i40e_adminq.cc 13.2 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
#include <stdlib.h>
#include <string.h>
#include <cassert>
#include <iostream>

#include "i40e_bm.h"

#include "i40e_base_wrapper.h"

using namespace i40e;

extern nicbm::Runner *runner;

queue_admin_tx::queue_admin_tx(i40e_bm &dev_, uint64_t &reg_base_,
        uint32_t &reg_len_, uint32_t &reg_head_, uint32_t &reg_tail_)
    : queue_base(reg_head_, reg_tail_), dev(dev_), reg_base(reg_base_),
    reg_len(reg_len_)
{
    desc_len = 32;
20
    ctxs_init();
21
22
}

23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
queue_base::desc_ctx &queue_admin_tx::desc_ctx_create()
{
    return *new admin_desc_ctx(*this, dev);
}

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

    if (!enabled  && (reg_len & I40E_GL_ATQLEN_ATQENABLE_MASK)) {
        std::cerr << "enable atq base=" << base << " len=" << len << std::endl;
        enabled = true;
    } else if (enabled && !(reg_len & I40E_GL_ATQLEN_ATQENABLE_MASK)) {
        std::cerr << "disable atq" << std::endl;
        enabled = false;
    }

    queue_base::reg_updated();
}

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

void queue_admin_tx::admin_desc_ctx::data_written(uint64_t addr, size_t len)
{
    processed();
}

void queue_admin_tx::admin_desc_ctx::desc_compl_prepare(uint16_t retval,
57
58
59
60
61
62
63
64
65
        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;
}

66
67
void queue_admin_tx::admin_desc_ctx::desc_complete(uint16_t retval,
        uint16_t extra_flags)
68
{
69
70
    desc_compl_prepare(retval, extra_flags);
    processed();
71
72
}

73
74
void queue_admin_tx::admin_desc_ctx::desc_complete_indir(uint16_t retval,
        const void *data, size_t len, uint16_t extra_flags, bool ignore_datalen)
75
{
76
    if (!ignore_datalen && len > d->datalen) {
77
78
79
80
81
82
        std::cerr << "queue_admin_tx::desc_complete_indir: data too long ("
            << len << ") got buffer for (" << d->datalen << ")" << std::endl;
        abort();
    }
    d->datalen = len;

83
    desc_compl_prepare(retval, extra_flags);
84
85
86

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

90
void queue_admin_tx::admin_desc_ctx::prepare()
91
{
92
93
94
95
96
97
98
99
100
101
    if ((d->flags & I40E_AQ_FLAG_RD)) {
        uint64_t addr = d->params.external.addr_low |
            (((uint64_t) d->params.external.addr_high) << 32);
        std::cerr << "  desc with buffer opc=" << d->opcode << " addr=" << addr
            << std::endl;
        data_fetch(addr, d->datalen);
    } else {
        prepared();
    }
}
102

103
104
105
void queue_admin_tx::admin_desc_ctx::process()
{
    std::cerr << "descriptor " << index << " fetched" << std::endl;
106
107
108
109
110
111
112
113
114
115
116
117

    if (d->opcode == i40e_aqc_opc_get_version) {
        std::cerr << "    get version" << std::endl;
        struct i40e_aqc_get_version *gv =
            reinterpret_cast<struct i40e_aqc_get_version *>(d->params.raw);
        gv->rom_ver = 0;
        gv->fw_build = 0;
        gv->fw_major = 0;
        gv->fw_minor = 0;
        gv->api_major = I40E_FW_API_VERSION_MAJOR;
        gv->api_minor = I40E_FW_API_VERSION_MINOR_X710;

118
        desc_complete(0);
119
120
121
122
123
124
125
126
    } else if (d->opcode == i40e_aqc_opc_request_resource) {
        std::cerr << "    request resource" << std::endl;
        struct i40e_aqc_request_resource *rr =
            reinterpret_cast<struct i40e_aqc_request_resource *>(
                    d->params.raw);
        rr->timeout = 180000;
        std::cerr << "      res_id=" << rr->resource_id << std::endl;
        std::cerr << "      res_nu=" << rr->resource_number << std::endl;
127
        desc_complete(0);
128
129
130
131
132
133
134
    } else if (d->opcode == i40e_aqc_opc_release_resource) {
        std::cerr << "    release resource" << std::endl;
        struct i40e_aqc_request_resource *rr =
            reinterpret_cast<struct i40e_aqc_request_resource *>(
                    d->params.raw);
        std::cerr << "      res_id=" << rr->resource_id << std::endl;
        std::cerr << "      res_nu=" << rr->resource_number << std::endl;
135
        desc_complete(0);
136
137
138
    } else if (d->opcode == i40e_aqc_opc_clear_pxe_mode)  {
        std::cerr << "    clear PXE mode" << std::endl;
        dev.regs.gllan_rctl_0 &= ~I40E_GLLAN_RCTL_0_PXE_MODE_MASK;
139
        desc_complete(0);
140
141
142
143
144
145
146
147
148
149
150
151
152
    } else if (d->opcode == i40e_aqc_opc_list_func_capabilities ||
            d->opcode == i40e_aqc_opc_list_dev_capabilities)
    {
        std::cerr << "    get dev/fun caps" << std::endl;
        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, {} },
153
154
            { I40E_AQ_CAP_ID_VSI, 1, 0, dev.NUM_VSIS, 0, 0, {} },
            { I40E_AQ_CAP_ID_DCB, 1, 0, 1, 1, 1, {} },
155
156
157
158
159
160
161
        };
        size_t num_caps = sizeof(caps) / sizeof(caps[0]);

        if (sizeof(caps) <= d->datalen) {
            std::cerr << "      data fits" << std::endl;
            // data fits within the buffer
            lc->count = num_caps;
162
            desc_complete_indir(0, caps, sizeof(caps));
163
164
165
166
        } else {
            std::cerr << "      data doesn't fit" << std::endl;
            // data does not fit
            d->datalen = sizeof(caps);
167
            desc_complete(I40E_AQ_RC_ENOMEM);
168
169
170
        }
    } else if (d->opcode == i40e_aqc_opc_lldp_stop) {
        std::cerr << "    lldp stop" << std::endl;
171
        desc_complete(0);
172
173
174
175
176
177
178
179
180
181
182
183
184
    } else if (d->opcode == i40e_aqc_opc_mac_address_read) {
        std::cerr << "    read mac" << std::endl;
        struct i40e_aqc_mac_address_read *ar =
            reinterpret_cast<struct i40e_aqc_mac_address_read *>(
                    d->params.raw);

        struct i40e_aqc_mac_address_read_data ard;
        uint64_t mac = runner->get_mac_addr();
        std::cerr << "      mac = " << mac << std::endl;
        memcpy(ard.pf_lan_mac, &mac, 6);
        memcpy(ard.port_mac, &mac, 6);

        ar->command_flags = I40E_AQC_LAN_ADDR_VALID | I40E_AQC_PORT_ADDR_VALID;
185
        desc_complete_indir(0, &ard, sizeof(ard));
186
187
188
189
190
191
192
193
194
195
196
197
198
199
    } else if (d->opcode == i40e_aqc_opc_get_phy_abilities) {
        std::cerr << "    get phy abilities" << std::endl;
        struct i40e_aq_get_phy_abilities_resp par;
        memset(&par, 0, sizeof(par));

        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;

        d->params.external.param0 = 0;
        d->params.external.param1 = 0;

200
        desc_complete_indir(0, &par, sizeof(par), 0, true);
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
    } else if (d->opcode == i40e_aqc_opc_get_link_status) {
        std::cerr << "    link status" << std::endl;
        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;
        gls->an_info = I40E_AQ_AN_COMPLETED | I40E_AQ_LP_AN_ABILITY; // might need qualified module
        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;

220
        desc_complete(0);
221
222
223
224
225
    } else if (d->opcode == i40e_aqc_opc_get_switch_config) {
        std::cerr << "    get switch config" << std::endl;
        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;
226
        /* Not sure why dpdk doesn't like this?
227
        struct i40e_aqc_switch_config_element_resp els[] = {
228
229
            // EMC
            { I40E_AQ_SW_ELEM_TYPE_EMP, I40E_AQ_SW_ELEM_REV_1, 1, 513, 0, {},
230
                I40E_AQ_CONN_TYPE_REGULAR, 0, 0},
231
232
            // MAC
            { I40E_AQ_SW_ELEM_TYPE_MAC, I40E_AQ_SW_ELEM_REV_1, 2, 0, 0, {},
233
234
                I40E_AQ_CONN_TYPE_REGULAR, 0, 0},
            // PF
235
236
237
238
239
240
241
242
243
244
245
246
            { 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, {},
247
248
249
                I40E_AQ_CONN_TYPE_REGULAR, 0, 0},
        };

250

251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
        // 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;
270
        std::cerr << "    report=" << report << " cnt=" << cnt << "  seid=" << sw->seid << std::endl;
271
272
273
274
275
276
277

        // 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);

278
        desc_complete_indir(0, buf, buflen);
279
280
281
282
283
284
285
286
    } else if (d->opcode == i40e_aqc_opc_set_switch_config) {
        std::cerr << "    set switch config" << std::endl;
        /* 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);
        */
287
        desc_complete(0);
288
289
    } else if (d->opcode == i40e_aqc_opc_get_vsi_parameters) {
        std::cerr << "    get vsi parameters" << std::endl;
Antoine Kaufmann's avatar
Antoine Kaufmann committed
290
        /*struct i40e_aqc_add_get_update_vsi *v =
291
            reinterpret_cast<struct i40e_aqc_add_get_update_vsi *>(
Antoine Kaufmann's avatar
Antoine Kaufmann committed
292
                    d->params.raw);*/
293
294
295
296
297
298
299

        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;
300
        desc_complete_indir(0, &pd, sizeof(pd));
301
302
303
    } else if (d->opcode == i40e_aqc_opc_update_vsi_parameters) {
        std::cerr << "    update vsi parameters" << std::endl;
        /* TODO */
304
        desc_complete(0);
305
306
307
    } else if (d->opcode == i40e_aqc_opc_set_dcb_parameters) {
        std::cerr << "    set dcb parameters" << std::endl;
        /* TODO */
308
        desc_complete(0);
309
310
    } else if (d->opcode == i40e_aqc_opc_configure_vsi_bw_limit) {
        std::cerr << "    configure vsi bw limit" << std::endl;
311
        desc_complete(0);
312
    } else if (d->opcode == i40e_aqc_opc_query_vsi_bw_config) {
313
        std::cerr << "    query vsi bw config" << std::endl;
314
315
316
317
        struct i40e_aqc_query_vsi_bw_config_resp bwc;
        memset(&bwc, 0, sizeof(bwc));
        for (size_t i = 0; i < 8; i++)
            bwc.qs_handles[i] = 0xffff;
318
        desc_complete_indir(0, &bwc, sizeof(bwc));
319
    } else if (d->opcode == i40e_aqc_opc_query_vsi_ets_sla_config) {
320
        std::cerr << "    query vsi ets sla config" << std::endl;
321
322
323
324
        struct i40e_aqc_query_vsi_ets_sla_config_resp sla;
        memset(&sla, 0, sizeof(sla));
        for (size_t i = 0; i < 8; i++)
            sla.share_credits[i] = 127;
325
        desc_complete_indir(0, &sla, sizeof(sla));
326
327
328
329
330
331
332
333
334
335
    } else if (d->opcode == i40e_aqc_opc_remove_macvlan) {
        std::cerr << "    remove macvlan" << std::endl;
        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;

336
        desc_complete_indir(0, data, d->datalen);
337
338
    } else {
        std::cerr << "    uknown opcode=" << d->opcode << std::endl;
339
340
        //desc_complete(I40E_AQ_RC_ESRCH);
        desc_complete(0);
341
342
    }
}