"Deepspeed/BingBertSquad/run_squad_baseline.sh" did not exist on "aebde649e30016aa33b2e1345cb22210a2e49b04"
i40e_adminq.cc 14.8 KB
Newer Older
Antoine Kaufmann's avatar
Antoine Kaufmann committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
/*
 * Copyright 2021 Max Planck Institute for Software Systems, and
 * National University of Singapore
 *
 * Permission is hereby granted, free of charge, to any person obtaining
 * a copy of this software and associated documentation files (the
 * "Software"), to deal in the Software without restriction, including
 * without limitation the rights to use, copy, modify, merge, publish,
 * distribute, sublicense, and/or sell copies of the Software, and to
 * permit persons to whom the Software is furnished to do so, subject to
 * the following conditions:
 *
 * The above copyright notice and this permission notice shall be
 * included in all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
 * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
 * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 */

25
26
#include <stdlib.h>
#include <string.h>
27

28
29
30
#include <cassert>
#include <iostream>

Antoine Kaufmann's avatar
Antoine Kaufmann committed
31
#include "sims/nic/i40e_bm/i40e_base_wrapper.h"
32
#include "sims/nic/i40e_bm/i40e_bm.h"
33

34
namespace i40e {
35
36

queue_admin_tx::queue_admin_tx(i40e_bm &dev_, uint64_t &reg_base_,
37
38
                               uint32_t &reg_len_, uint32_t &reg_head_,
                               uint32_t &reg_tail_)
39
    : queue_base("atx", reg_head_, reg_tail_, dev_),
40
41
42
43
      reg_base(reg_base_),
      reg_len(reg_len_) {
  desc_len = 32;
  ctxs_init();
44
45
}

46
47
queue_base::desc_ctx &queue_admin_tx::desc_ctx_create() {
  return *new admin_desc_ctx(*this, dev);
48
49
}

50
51
52
void queue_admin_tx::reg_updated() {
  base = reg_base;
  len = (reg_len & I40E_GL_ATQLEN_ATQLEN_MASK) >> I40E_GL_ATQLEN_ATQLEN_SHIFT;
53

54
  if (!enabled && (reg_len & I40E_GL_ATQLEN_ATQENABLE_MASK)) {
55
#ifdef DEBUG_ADMINQ
56
    log << " enable base=" << base << " len=" << len << logger::endl;
57
#endif
58
59
    enabled = true;
  } else if (enabled && !(reg_len & I40E_GL_ATQLEN_ATQENABLE_MASK)) {
60
#ifdef DEBUG_ADMINQ
61
    log << " disable" << logger::endl;
62
#endif
63
64
    enabled = false;
  }
65

66
  queue_base::reg_updated();
67
68
69
}

queue_admin_tx::admin_desc_ctx::admin_desc_ctx(queue_admin_tx &queue_,
70
71
72
                                               i40e_bm &dev_)
    : i40e::queue_base::desc_ctx(queue_), aq(queue_), dev(dev_) {
  d = reinterpret_cast<struct i40e_aq_desc *>(desc);
73
74
}

75
76
void queue_admin_tx::admin_desc_ctx::data_written(uint64_t addr, size_t len) {
  processed();
77
78
79
}

void queue_admin_tx::admin_desc_ctx::desc_compl_prepare(uint16_t retval,
80
81
82
83
84
85
                                                        uint16_t extra_flags) {
  d->flags &= ~0x1ff;
  d->flags |= I40E_AQ_FLAG_DD | I40E_AQ_FLAG_CMP | extra_flags;
  if (retval)
    d->flags |= I40E_AQ_FLAG_ERR;
  d->retval = retval;
Antoine Kaufmann's avatar
Antoine Kaufmann committed
86
87

#ifdef DEBUG_ADMINQ
88
89
  queue.log << " desc_compl_prepare index=" << index << " retval=" << retval
            << logger::endl;
Antoine Kaufmann's avatar
Antoine Kaufmann committed
90
#endif
91
92
}

93
void queue_admin_tx::admin_desc_ctx::desc_complete(uint16_t retval,
94
95
96
                                                   uint16_t extra_flags) {
  desc_compl_prepare(retval, extra_flags);
  processed();
97
98
}

99
void queue_admin_tx::admin_desc_ctx::desc_complete_indir(uint16_t retval,
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
                                                         const void *data,
                                                         size_t len,
                                                         uint16_t extra_flags,
                                                         bool ignore_datalen) {
  if (!ignore_datalen && len > d->datalen) {
    queue.log << "queue_admin_tx::desc_complete_indir: data too long (" << len
              << ") got buffer for (" << d->datalen << ")" << logger::endl;
    abort();
  }
  d->datalen = len;

  desc_compl_prepare(retval, extra_flags);

  uint64_t addr = d->params.external.addr_low |
                  (((uint64_t)d->params.external.addr_high) << 32);
  data_write(addr, len, data);
116
117
}

118
119
120
121
void queue_admin_tx::admin_desc_ctx::prepare() {
  if ((d->flags & I40E_AQ_FLAG_RD)) {
    uint64_t addr = d->params.external.addr_low |
                    (((uint64_t)d->params.external.addr_high) << 32);
122
#ifdef DEBUG_ADMINQ
123
124
    queue.log << " desc with buffer opc=" << d->opcode << " addr=" << addr
              << logger::endl;
125
#endif
126
127
128
129
    data_fetch(addr, d->datalen);
  } else {
    prepared();
  }
130
}
131

132
void queue_admin_tx::admin_desc_ctx::process() {
133
#ifdef DEBUG_ADMINQ
134
  queue.log << " descriptor " << index << " fetched" << logger::endl;
135
#endif
136

137
  if (d->opcode == i40e_aqc_opc_get_version) {
138
#ifdef DEBUG_ADMINQ
139
    queue.log << "  get version" << logger::endl;
140
#endif
141
142
143
144
    struct i40e_aqc_get_version *gv =
        reinterpret_cast<struct i40e_aqc_get_version *>(d->params.raw);
    gv->rom_ver = 0;
    gv->fw_build = 0;
145
    gv->fw_major = 6;
146
147
148
149
150
151
    gv->fw_minor = 0;
    gv->api_major = I40E_FW_API_VERSION_MAJOR;
    gv->api_minor = I40E_FW_API_VERSION_MINOR_X710;

    desc_complete(0);
  } else if (d->opcode == i40e_aqc_opc_request_resource) {
152
#ifdef DEBUG_ADMINQ
153
    queue.log << "  request resource" << logger::endl;
154
#endif
155
156
157
    struct i40e_aqc_request_resource *rr =
        reinterpret_cast<struct i40e_aqc_request_resource *>(d->params.raw);
    rr->timeout = 180000;
158
#ifdef DEBUG_ADMINQ
159
160
    queue.log << "    res_id=" << rr->resource_id << logger::endl;
    queue.log << "    res_nu=" << rr->resource_number << logger::endl;
161
#endif
162
163
    desc_complete(0);
  } else if (d->opcode == i40e_aqc_opc_release_resource) {
164
#ifdef DEBUG_ADMINQ
165
    queue.log << "  release resource" << logger::endl;
166
167
#endif
#ifdef DEBUG_ADMINQ
168
169
170
171
    struct i40e_aqc_request_resource *rr =
        reinterpret_cast<struct i40e_aqc_request_resource *>(d->params.raw);
    queue.log << "    res_id=" << rr->resource_id << logger::endl;
    queue.log << "    res_nu=" << rr->resource_number << logger::endl;
172
#endif
173
174
    desc_complete(0);
  } else if (d->opcode == i40e_aqc_opc_clear_pxe_mode) {
175
#ifdef DEBUG_ADMINQ
176
    queue.log << "  clear PXE mode" << logger::endl;
177
#endif
178
179
180
181
    dev.regs.gllan_rctl_0 &= ~I40E_GLLAN_RCTL_0_PXE_MODE_MASK;
    desc_complete(0);
  } else if (d->opcode == i40e_aqc_opc_list_func_capabilities ||
             d->opcode == i40e_aqc_opc_list_dev_capabilities) {
182
#ifdef DEBUG_ADMINQ
183
    queue.log << "  get dev/fun caps" << logger::endl;
184
#endif
185
186
187
188
189
190
191
192
193
194
195
196
197
198
    struct i40e_aqc_list_capabilites *lc =
        reinterpret_cast<struct i40e_aqc_list_capabilites *>(d->params.raw);

    struct i40e_aqc_list_capabilities_element_resp caps[] = {
        {I40E_AQ_CAP_ID_RSS, 1, 0, 512, 6, 0, {}},
        {I40E_AQ_CAP_ID_RXQ, 1, 0, dev.NUM_QUEUES, 0, 0, {}},
        {I40E_AQ_CAP_ID_TXQ, 1, 0, dev.NUM_QUEUES, 0, 0, {}},
        {I40E_AQ_CAP_ID_MSIX, 1, 0, dev.NUM_PFINTS, 0, 0, {}},
        {I40E_AQ_CAP_ID_VSI, 1, 0, dev.NUM_VSIS, 0, 0, {}},
        {I40E_AQ_CAP_ID_DCB, 1, 0, 1, 1, 1, {}},
    };
    size_t num_caps = sizeof(caps) / sizeof(caps[0]);

    if (sizeof(caps) <= d->datalen) {
199
#ifdef DEBUG_ADMINQ
200
      queue.log << "    data fits" << logger::endl;
201
#endif
202
203
204
205
      // data fits within the buffer
      lc->count = num_caps;
      desc_complete_indir(0, caps, sizeof(caps));
    } else {
206
#ifdef DEBUG_ADMINQ
207
      queue.log << "    data doesn't fit" << logger::endl;
208
#endif
209
210
211
212
213
      // data does not fit
      d->datalen = sizeof(caps);
      desc_complete(I40E_AQ_RC_ENOMEM);
    }
  } else if (d->opcode == i40e_aqc_opc_lldp_stop) {
214
#ifdef DEBUG_ADMINQ
215
    queue.log << "  lldp stop" << logger::endl;
216
#endif
217
218
    desc_complete(0);
  } else if (d->opcode == i40e_aqc_opc_mac_address_read) {
219
#ifdef DEBUG_ADMINQ
220
    queue.log << "  read mac" << logger::endl;
221
#endif
222
223
    struct i40e_aqc_mac_address_read *ar =
        reinterpret_cast<struct i40e_aqc_mac_address_read *>(d->params.raw);
224

225
    struct i40e_aqc_mac_address_read_data ard;
226
    uint64_t mac = dev.runner_->GetMacAddr();
227
#ifdef DEBUG_ADMINQ
228
    queue.log << "    mac = " << mac << logger::endl;
229
#endif
230
231
    memcpy(ard.pf_lan_mac, &mac, 6);
    memcpy(ard.port_mac, &mac, 6);
232

233
234
235
    ar->command_flags = I40E_AQC_LAN_ADDR_VALID | I40E_AQC_PORT_ADDR_VALID;
    desc_complete_indir(0, &ard, sizeof(ard));
  } else if (d->opcode == i40e_aqc_opc_get_phy_abilities) {
236
#ifdef DEBUG_ADMINQ
237
    queue.log << "  get phy abilities" << logger::endl;
238
#endif
239
240
    struct i40e_aq_get_phy_abilities_resp par;
    memset(&par, 0, sizeof(par));
241

242
243
244
245
    par.phy_type = (1ULL << I40E_PHY_TYPE_40GBASE_CR4_CU);
    par.link_speed = I40E_LINK_SPEED_40GB;
    par.abilities = I40E_AQ_PHY_LINK_ENABLED | I40E_AQ_PHY_AN_ENABLED;
    par.eee_capability = 0;
246

247
248
    d->params.external.param0 = 0;
    d->params.external.param1 = 0;
249

250
251
    desc_complete_indir(0, &par, sizeof(par), 0, true);
  } else if (d->opcode == i40e_aqc_opc_get_link_status) {
252
#ifdef DEBUG_ADMINQ
253
    queue.log << "  link status" << logger::endl;
254
#endif
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
    struct i40e_aqc_get_link_status *gls =
        reinterpret_cast<struct i40e_aqc_get_link_status *>(d->params.raw);

    gls->command_flags &= I40E_AQ_LSE_IS_ENABLED;  // should actually return
                                                   // status of link status
                                                   // notification
    gls->phy_type = I40E_PHY_TYPE_40GBASE_CR4_CU;
    gls->link_speed = I40E_LINK_SPEED_40GB;
    gls->link_info = I40E_AQ_LINK_UP_FUNCTION | I40E_AQ_LINK_UP_PORT |
                     I40E_AQ_MEDIA_AVAILABLE | I40E_AQ_SIGNAL_DETECT;
    // might need qualified module
    gls->an_info = I40E_AQ_AN_COMPLETED | I40E_AQ_LP_AN_ABILITY;
    gls->ext_info = 0;
    gls->loopback = I40E_AQ_LINK_POWER_CLASS_4 << I40E_AQ_PWR_CLASS_SHIFT_LB;
    gls->max_frame_size = dev.MAX_MTU;
    gls->config = I40E_AQ_CONFIG_CRC_ENA;

    desc_complete(0);
  } else if (d->opcode == i40e_aqc_opc_get_switch_config) {
274
#ifdef DEBUG_ADMINQ
275
    queue.log << "  get switch config" << logger::endl;
276
#endif
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
    struct i40e_aqc_switch_seid *sw =
        reinterpret_cast<struct i40e_aqc_switch_seid *>(d->params.raw);
    struct i40e_aqc_get_switch_config_header_resp hr;
    /* Not sure why dpdk doesn't like this?
    struct i40e_aqc_switch_config_element_resp els[] = {
        // EMC
        { I40E_AQ_SW_ELEM_TYPE_EMP, I40E_AQ_SW_ELEM_REV_1, 1, 513, 0, {},
            I40E_AQ_CONN_TYPE_REGULAR, 0, 0},
        // MAC
        { I40E_AQ_SW_ELEM_TYPE_MAC, I40E_AQ_SW_ELEM_REV_1, 2, 0, 0, {},
            I40E_AQ_CONN_TYPE_REGULAR, 0, 0},
        // PF
        { I40E_AQ_SW_ELEM_TYPE_PF, I40E_AQ_SW_ELEM_REV_1, 16, 512, 0, {},
            I40E_AQ_CONN_TYPE_REGULAR, 0, 0},
        // VSI PF
        { I40E_AQ_SW_ELEM_TYPE_VSI, I40E_AQ_SW_ELEM_REV_1, 512, 2, 16, {},
            I40E_AQ_CONN_TYPE_REGULAR, 0, 0},
        // VSI PF
        { I40E_AQ_SW_ELEM_TYPE_VSI, I40E_AQ_SW_ELEM_REV_1, 513, 2, 1, {},
            I40E_AQ_CONN_TYPE_REGULAR, 0, 0},
    };*/
    struct i40e_aqc_switch_config_element_resp els[] = {
        // VSI PF
        {I40E_AQ_SW_ELEM_TYPE_VSI,
         I40E_AQ_SW_ELEM_REV_1,
         512,
         2,
         16,
         {},
         I40E_AQ_CONN_TYPE_REGULAR,
         0,
         0},
    };

    // find start idx
    size_t cnt = sizeof(els) / sizeof(els[0]);
    size_t first = 0;
    for (first = 0; first < cnt && els[first].seid < sw->seid; first++) {
    }

    // figure out how many fit in the buffer
    size_t max = (d->datalen - sizeof(hr)) / sizeof(els[0]);
    size_t report = cnt - first;
    if (report > max) {
      report = max;
      sw->seid = els[first + report].seid;
    } else {
      sw->seid = 0;
    }

    // prepare header
    memset(&hr, 0, sizeof(hr));
    hr.num_reported = report;
    hr.num_total = cnt;
331
#ifdef DEBUG_ADMINQ
332
333
    queue.log << "    report=" << report << " cnt=" << cnt
              << "  seid=" << sw->seid << logger::endl;
334
#endif
335

336
337
338
339
340
    // create temporary contiguous buffer
    size_t buflen = sizeof(hr) + sizeof(els[0]) * report;
    uint8_t buf[buflen];
    memcpy(buf, &hr, sizeof(hr));
    memcpy(buf + sizeof(hr), els + first, sizeof(els[0]) * report);
341

342
343
    desc_complete_indir(0, buf, buflen);
  } else if (d->opcode == i40e_aqc_opc_set_switch_config) {
344
#ifdef DEBUG_ADMINQ
345
    queue.log << "  set switch config" << logger::endl;
346
#endif
347
348
349
350
351
352
353
354
    /* TODO: lots of interesting things here like l2 filtering etc. that are
     * relevant.
    struct i40e_aqc_set_switch_config *sc =
        reinterpret_cast<struct i40e_aqc_set_switch_config *>(
                d->params.raw);
    */
    desc_complete(0);
  } else if (d->opcode == i40e_aqc_opc_get_vsi_parameters) {
355
#ifdef DEBUG_ADMINQ
356
    queue.log << "  get vsi parameters" << logger::endl;
357
#endif
358
359
360
361
362
363
364
365
366
367
368
    /*struct i40e_aqc_add_get_update_vsi *v =
        reinterpret_cast<struct i40e_aqc_add_get_update_vsi *>(
                d->params.raw);*/

    struct i40e_aqc_vsi_properties_data pd;
    memset(&pd, 0, sizeof(pd));
    pd.valid_sections |=
        I40E_AQ_VSI_PROP_SWITCH_VALID | I40E_AQ_VSI_PROP_QUEUE_MAP_VALID |
        I40E_AQ_VSI_PROP_QUEUE_OPT_VALID | I40E_AQ_VSI_PROP_SCHED_VALID;
    desc_complete_indir(0, &pd, sizeof(pd));
  } else if (d->opcode == i40e_aqc_opc_update_vsi_parameters) {
369
#ifdef DEBUG_ADMINQ
370
    queue.log << "  update vsi parameters" << logger::endl;
371
#endif
372
373
374
    /* TODO */
    desc_complete(0);
  } else if (d->opcode == i40e_aqc_opc_set_dcb_parameters) {
375
#ifdef DEBUG_ADMINQ
376
    queue.log << "  set dcb parameters" << logger::endl;
377
#endif
378
379
380
    /* TODO */
    desc_complete(0);
  } else if (d->opcode == i40e_aqc_opc_configure_vsi_bw_limit) {
381
#ifdef DEBUG_ADMINQ
382
    queue.log << "  configure vsi bw limit" << logger::endl;
383
#endif
384
385
    desc_complete(0);
  } else if (d->opcode == i40e_aqc_opc_query_vsi_bw_config) {
386
#ifdef DEBUG_ADMINQ
387
    queue.log << "  query vsi bw config" << logger::endl;
388
#endif
389
390
    struct i40e_aqc_query_vsi_bw_config_resp bwc;
    memset(&bwc, 0, sizeof(bwc));
391
392
    for (size_t i = 0; i < 8; i++)
      bwc.qs_handles[i] = 0xffff;
393
394
    desc_complete_indir(0, &bwc, sizeof(bwc));
  } else if (d->opcode == i40e_aqc_opc_query_vsi_ets_sla_config) {
395
#ifdef DEBUG_ADMINQ
396
    queue.log << "  query vsi ets sla config" << logger::endl;
397
#endif
398
399
    struct i40e_aqc_query_vsi_ets_sla_config_resp sla;
    memset(&sla, 0, sizeof(sla));
400
401
    for (size_t i = 0; i < 8; i++)
      sla.share_credits[i] = 127;
402
403
    desc_complete_indir(0, &sla, sizeof(sla));
  } else if (d->opcode == i40e_aqc_opc_remove_macvlan) {
404
#ifdef DEBUG_ADMINQ
405
    queue.log << "  remove macvlan" << logger::endl;
406
#endif
407
408
409
410
411
412
413
414
415
    struct i40e_aqc_macvlan *m =
        reinterpret_cast<struct i40e_aqc_macvlan *>(d->params.raw);
    struct i40e_aqc_remove_macvlan_element_data *rve =
        reinterpret_cast<struct i40e_aqc_remove_macvlan_element_data *>(data);
    for (uint16_t i = 0; i < m->num_addresses; i++)
      rve[i].error_code = I40E_AQC_REMOVE_MACVLAN_SUCCESS;

    desc_complete_indir(0, data, d->datalen);
  } else {
416
#ifdef DEBUG_ADMINQ
417
    queue.log << "  uknown opcode=" << d->opcode << logger::endl;
418
#endif
419
420
421
    // desc_complete(I40E_AQ_RC_ESRCH);
    desc_complete(0);
  }
422
}
423
}  // namespace i40e