net/bnx2x: replace macro with static function
[dpdk.git] / drivers / net / bnx2x / bnx2x_vfpf.c
1 /*
2  * Copyright (c) 2013-2015 Brocade Communications Systems, Inc.
3  *
4  * Copyright (c) 2015 QLogic Corporation.
5  * All rights reserved.
6  * www.qlogic.com
7  *
8  * See LICENSE.bnx2x_pmd for copyright and licensing details.
9  */
10
11 #include "bnx2x.h"
12
13 /* calculate the crc in the bulletin board */
14 static inline uint32_t
15 bnx2x_vf_crc(struct bnx2x_vf_bulletin *bull)
16 {
17         uint32_t crc_sz = sizeof(bull->crc), length = bull->length - crc_sz;
18
19         return ECORE_CRC32_LE(0, (uint8_t *)bull + crc_sz, length);
20 }
21
22 /* Checks are there mac/channel updates for VF
23  * returns TRUE if something was updated
24 */
25 int
26 bnx2x_check_bull(struct bnx2x_softc *sc)
27 {
28         struct bnx2x_vf_bulletin *bull;
29         uint8_t tries = 0;
30         uint16_t old_version = sc->old_bulletin.version;
31         uint64_t valid_bitmap;
32
33         bull = sc->pf2vf_bulletin;
34         if (old_version == bull->version) {
35                 return FALSE;
36         } else {
37                 /* Check the crc until we get the correct data */
38                 while (tries < BNX2X_VF_BULLETIN_TRIES) {
39                         bull = sc->pf2vf_bulletin;
40                         if (bull->crc == bnx2x_vf_crc(bull))
41                                 break;
42
43                         PMD_DRV_LOG(ERR, "bad crc on bulletin board. contained %x computed %x",
44                                         bull->crc, bnx2x_vf_crc(bull));
45                         ++tries;
46                 }
47                 if (tries == BNX2X_VF_BULLETIN_TRIES) {
48                         PMD_DRV_LOG(ERR, "pf to vf bulletin board crc was wrong %d consecutive times. Aborting",
49                                         tries);
50                         return FALSE;
51                 }
52         }
53
54         valid_bitmap = bull->valid_bitmap;
55
56         /* check the mac address and VLAN and allocate memory if valid */
57         if (valid_bitmap & (1 << MAC_ADDR_VALID) && memcmp(bull->mac, sc->old_bulletin.mac, ETH_ALEN))
58                 rte_memcpy(&sc->link_params.mac_addr, bull->mac, ETH_ALEN);
59         if (valid_bitmap & (1 << VLAN_VALID))
60                 rte_memcpy(&bull->vlan, &sc->old_bulletin.vlan, VLAN_HLEN);
61
62         sc->old_bulletin = *bull;
63
64         return TRUE;
65 }
66
67 /* place a given tlv on the tlv buffer at a given offset */
68 static void
69 bnx2x_add_tlv(__rte_unused struct bnx2x_softc *sc, void *tlvs_list,
70               uint16_t offset, uint16_t type, uint16_t length)
71 {
72         struct channel_tlv *tl = (struct channel_tlv *)
73                                         ((unsigned long)tlvs_list + offset);
74
75         tl->type = type;
76         tl->length = length;
77 }
78
79 /* Initiliaze header of the first tlv and clear mailbox*/
80 static void
81 bnx2x_init_first_tlv(struct bnx2x_softc *sc, struct vf_first_tlv *first_tlv,
82         uint16_t type, uint16_t length)
83 {
84         struct bnx2x_vf_mbx_msg *mbox = sc->vf2pf_mbox;
85         PMD_DRV_LOG(DEBUG, "Preparing %d tlv for sending", type);
86
87         memset(mbox, 0, sizeof(struct bnx2x_vf_mbx_msg));
88
89         bnx2x_add_tlv(sc, &first_tlv->tl, 0, type, length);
90
91         /* Initialize header of the first tlv */
92         first_tlv->reply_offset = sizeof(mbox->query);
93 }
94
95 #define BNX2X_VF_CMD_ADDR_LO PXP_VF_ADDR_CSDM_GLOBAL_START
96 #define BNX2X_VF_CMD_ADDR_HI BNX2X_VF_CMD_ADDR_LO + 4
97 #define BNX2X_VF_CMD_TRIGGER BNX2X_VF_CMD_ADDR_HI + 4
98 #define BNX2X_VF_CHANNEL_DELAY 100
99 #define BNX2X_VF_CHANNEL_TRIES 100
100
101 static int
102 bnx2x_do_req4pf(struct bnx2x_softc *sc, phys_addr_t phys_addr)
103 {
104         uint8_t *status = &sc->vf2pf_mbox->resp.common_reply.status;
105         uint8_t i;
106
107         if (!*status) {
108                 bnx2x_check_bull(sc);
109                 if (sc->old_bulletin.valid_bitmap & (1 << CHANNEL_DOWN)) {
110                         PMD_DRV_LOG(ERR, "channel is down. Aborting message sending");
111                         *status = BNX2X_VF_STATUS_SUCCESS;
112                         return 0;
113                 }
114
115                 REG_WR(sc, BNX2X_VF_CMD_ADDR_LO, U64_LO(phys_addr));
116                 REG_WR(sc, BNX2X_VF_CMD_ADDR_HI, U64_HI(phys_addr));
117
118                 /* memory barrier to ensure that FW can read phys_addr */
119                 wmb();
120
121                 REG_WR8(sc, BNX2X_VF_CMD_TRIGGER, 1);
122
123                 /* Do several attempts until PF completes
124                  * "." is used to show progress
125                  */
126                 for (i = 0; i < BNX2X_VF_CHANNEL_TRIES; i++) {
127                         DELAY_MS(BNX2X_VF_CHANNEL_DELAY);
128                         if (*status)
129                                 break;
130                 }
131
132                 if (!*status) {
133                         PMD_DRV_LOG(ERR, "Response from PF timed out");
134                         return -EAGAIN;
135                 }
136         } else {
137                 PMD_DRV_LOG(ERR, "status should be zero before message"
138                                 "to pf was sent");
139                 return -EINVAL;
140         }
141
142         PMD_DRV_LOG(DEBUG, "Response from PF was received");
143         return 0;
144 }
145
146 static inline uint16_t bnx2x_check_me_flags(uint32_t val)
147 {
148         if (((val) & ME_REG_VF_VALID) && (!((val) & ME_REG_VF_ERR)))
149                 return ME_REG_VF_VALID;
150         else
151                 return 0;
152 }
153
154 #define BNX2X_ME_ANSWER_DELAY 100
155 #define BNX2X_ME_ANSWER_TRIES 10
156
157 static inline int bnx2x_read_vf_id(struct bnx2x_softc *sc)
158 {
159         uint32_t val;
160         uint8_t i = 0;
161
162         while (i <= BNX2X_ME_ANSWER_TRIES) {
163                 val = BNX2X_DB_READ(DOORBELL_ADDR(sc, 0));
164                 if (bnx2x_check_me_flags(val))
165                         return VF_ID(val);
166
167                 DELAY_MS(BNX2X_ME_ANSWER_DELAY);
168                 i++;
169         }
170
171         return -EINVAL;
172 }
173
174 #define BNX2X_VF_OBTAIN_MAX_TRIES 3
175 #define BNX2X_VF_OBTAIN_MAC_FILTERS 1
176 #define BNX2X_VF_OBTAIN_MC_FILTERS 10
177
178 struct bnx2x_obtain_status {
179         int success;
180         int err_code;
181 };
182
183 static
184 struct bnx2x_obtain_status bnx2x_loop_obtain_resources(struct bnx2x_softc *sc)
185 {
186         int tries = 0;
187         struct vf_acquire_resp_tlv *resp = &sc->vf2pf_mbox->resp.acquire_resp,
188                                                                  *sc_resp = &sc->acquire_resp;
189         struct vf_resource_query    *res_query;
190         struct vf_resc            *resc;
191         struct bnx2x_obtain_status     status;
192         int res_obtained = false;
193
194         do {
195                 PMD_DRV_LOG(DEBUG, "trying to get resources");
196
197                 if (bnx2x_do_req4pf(sc, sc->vf2pf_mbox_mapping.paddr)) {
198                         /* timeout */
199                         status.success = 0;
200                         status.err_code = -EAGAIN;
201                         return status;
202                 }
203
204                 memcpy(sc_resp, resp, sizeof(sc->acquire_resp));
205
206                 tries++;
207
208                 /* check PF to request acceptance */
209                 if (sc_resp->status == BNX2X_VF_STATUS_SUCCESS) {
210                         PMD_DRV_LOG(DEBUG, "resources obtained successfully");
211                         res_obtained = true;
212                 } else if (sc_resp->status == BNX2X_VF_STATUS_NO_RESOURCES &&
213                         tries < BNX2X_VF_OBTAIN_MAX_TRIES) {
214                         PMD_DRV_LOG(DEBUG,
215                            "PF cannot allocate requested amount of resources");
216
217                         res_query = &sc->vf2pf_mbox->query[0].acquire.res_query;
218                         resc     = &sc_resp->resc;
219
220                         /* PF refused our request. Try to decrease request params */
221                         res_query->num_txqs         = min(res_query->num_txqs, resc->num_txqs);
222                         res_query->num_rxqs         = min(res_query->num_rxqs, resc->num_rxqs);
223                         res_query->num_sbs          = min(res_query->num_sbs, resc->num_sbs);
224                         res_query->num_mac_filters  = min(res_query->num_mac_filters, resc->num_mac_filters);
225                         res_query->num_vlan_filters = min(res_query->num_vlan_filters, resc->num_vlan_filters);
226                         res_query->num_mc_filters   = min(res_query->num_mc_filters, resc->num_mc_filters);
227
228                         memset(&sc->vf2pf_mbox->resp, 0, sizeof(union resp_tlvs));
229                 } else {
230                         PMD_DRV_LOG(ERR, "Resources cannot be obtained. Status of handling: %d. Aborting",
231                                         sc_resp->status);
232                         status.success = 0;
233                         status.err_code = -EAGAIN;
234                         return status;
235                 }
236         } while (!res_obtained);
237
238         status.success = 1;
239         return status;
240 }
241
242 int bnx2x_vf_get_resources(struct bnx2x_softc *sc, uint8_t tx_count, uint8_t rx_count)
243 {
244         struct vf_acquire_tlv *acq = &sc->vf2pf_mbox->query[0].acquire;
245         int vf_id;
246         struct bnx2x_obtain_status obtain_status;
247
248         bnx2x_vf_close(sc);
249         bnx2x_init_first_tlv(sc, &acq->first_tlv, BNX2X_VF_TLV_ACQUIRE, sizeof(*acq));
250
251         vf_id = bnx2x_read_vf_id(sc);
252         if (vf_id < 0)
253                 return -EAGAIN;
254
255         acq->vf_id = vf_id;
256
257         acq->res_query.num_rxqs = rx_count;
258         acq->res_query.num_txqs = tx_count;
259         acq->res_query.num_sbs = sc->igu_sb_cnt;
260         acq->res_query.num_mac_filters = BNX2X_VF_OBTAIN_MAC_FILTERS;
261         acq->res_query.num_mc_filters = BNX2X_VF_OBTAIN_MC_FILTERS;
262
263         acq->bulletin_addr = sc->pf2vf_bulletin_mapping.paddr;
264
265         /* Request physical port identifier */
266         bnx2x_add_tlv(sc, acq, acq->first_tlv.tl.length,
267                       BNX2X_VF_TLV_PHYS_PORT_ID,
268                       sizeof(struct channel_tlv));
269
270         bnx2x_add_tlv(sc, acq,
271                       (acq->first_tlv.tl.length + sizeof(struct channel_tlv)),
272                       BNX2X_VF_TLV_LIST_END,
273                       sizeof(struct channel_list_end_tlv));
274
275         /* requesting the resources in loop */
276         obtain_status = bnx2x_loop_obtain_resources(sc);
277         if (!obtain_status.success)
278                 return obtain_status.err_code;
279
280         struct vf_acquire_resp_tlv sc_resp = sc->acquire_resp;
281
282         sc->devinfo.chip_id        |= (sc_resp.chip_num & 0xFFFF);
283         sc->devinfo.int_block       = INT_BLOCK_IGU;
284         sc->devinfo.chip_port_mode  = CHIP_2_PORT_MODE;
285         sc->devinfo.mf_info.mf_ov   = 0;
286         sc->devinfo.mf_info.mf_mode = 0;
287         sc->devinfo.flash_size      = 0;
288
289         sc->igu_sb_cnt  = sc_resp.resc.num_sbs;
290         sc->igu_base_sb = sc_resp.resc.hw_sbs[0] & 0xFF;
291         sc->igu_dsb_id  = -1;
292         sc->max_tx_queues = sc_resp.resc.num_txqs;
293         sc->max_rx_queues = sc_resp.resc.num_rxqs;
294
295         sc->link_params.chip_id = sc->devinfo.chip_id;
296         sc->doorbell_size = sc_resp.db_size;
297         sc->flags |= BNX2X_NO_WOL_FLAG | BNX2X_NO_ISCSI_OOO_FLAG | BNX2X_NO_ISCSI_FLAG | BNX2X_NO_FCOE_FLAG;
298
299         PMD_DRV_LOG(DEBUG, "status block count = %d, base status block = %x",
300                 sc->igu_sb_cnt, sc->igu_base_sb);
301         strncpy(sc->fw_ver, sc_resp.fw_ver, sizeof(sc->fw_ver));
302
303         if (is_valid_assigned_ether_addr(&sc_resp.resc.current_mac_addr))
304                 ether_addr_copy(&sc_resp.resc.current_mac_addr,
305                                 (struct ether_addr *)sc->link_params.mac_addr);
306         else
307                 eth_random_addr(sc->link_params.mac_addr);
308
309         return 0;
310 }
311
312 /* Ask PF to release VF's resources */
313 void
314 bnx2x_vf_close(struct bnx2x_softc *sc)
315 {
316         struct vf_release_tlv *query;
317         struct vf_common_reply_tlv *reply = &sc->vf2pf_mbox->resp.common_reply;
318         int vf_id = bnx2x_read_vf_id(sc);
319
320         if (vf_id >= 0) {
321                 query = &sc->vf2pf_mbox->query[0].release;
322                 bnx2x_init_first_tlv(sc, &query->first_tlv, BNX2X_VF_TLV_RELEASE,
323                                 sizeof(*query));
324
325                 query->vf_id = vf_id;
326                 bnx2x_add_tlv(sc, query, query->first_tlv.tl.length,
327                               BNX2X_VF_TLV_LIST_END,
328                               sizeof(struct channel_list_end_tlv));
329
330                 bnx2x_do_req4pf(sc, sc->vf2pf_mbox_mapping.paddr);
331                 if (reply->status != BNX2X_VF_STATUS_SUCCESS)
332                         PMD_DRV_LOG(ERR, "Failed to release VF");
333         }
334 }
335
336 /* Let PF know the VF status blocks phys_addrs */
337 int
338 bnx2x_vf_init(struct bnx2x_softc *sc)
339 {
340         struct vf_init_tlv *query;
341         struct vf_common_reply_tlv *reply = &sc->vf2pf_mbox->resp.common_reply;
342         int i;
343
344         query = &sc->vf2pf_mbox->query[0].init;
345         bnx2x_init_first_tlv(sc, &query->first_tlv, BNX2X_VF_TLV_INIT,
346                         sizeof(*query));
347
348         FOR_EACH_QUEUE(sc, i) {
349                 query->sb_addr[i] = (unsigned long)(sc->fp[i].sb_dma.paddr);
350         }
351
352         query->stats_step = sizeof(struct per_queue_stats);
353         query->stats_addr = sc->fw_stats_data_mapping +
354                 offsetof(struct bnx2x_fw_stats_data, queue_stats);
355
356         bnx2x_add_tlv(sc, query, query->first_tlv.tl.length,
357                       BNX2X_VF_TLV_LIST_END,
358                       sizeof(struct channel_list_end_tlv));
359
360         bnx2x_do_req4pf(sc, sc->vf2pf_mbox_mapping.paddr);
361         if (reply->status != BNX2X_VF_STATUS_SUCCESS) {
362                 PMD_DRV_LOG(ERR, "Failed to init VF");
363                 return -EINVAL;
364         }
365
366         PMD_DRV_LOG(DEBUG, "VF was initialized");
367         return 0;
368 }
369
370 void
371 bnx2x_vf_unload(struct bnx2x_softc *sc)
372 {
373         struct vf_close_tlv *query;
374         struct vf_common_reply_tlv *reply = &sc->vf2pf_mbox->resp.common_reply;
375         struct vf_q_op_tlv *query_op;
376         int i, vf_id;
377
378         vf_id = bnx2x_read_vf_id(sc);
379         if (vf_id > 0) {
380                 FOR_EACH_QUEUE(sc, i) {
381                         query_op = &sc->vf2pf_mbox->query[0].q_op;
382                         bnx2x_init_first_tlv(sc, &query_op->first_tlv,
383                                         BNX2X_VF_TLV_TEARDOWN_Q,
384                                         sizeof(*query_op));
385
386                         query_op->vf_qid = i;
387
388                         bnx2x_add_tlv(sc, query_op,
389                                       query_op->first_tlv.tl.length,
390                                       BNX2X_VF_TLV_LIST_END,
391                                       sizeof(struct channel_list_end_tlv));
392
393                         bnx2x_do_req4pf(sc, sc->vf2pf_mbox_mapping.paddr);
394                         if (reply->status != BNX2X_VF_STATUS_SUCCESS)
395                                 PMD_DRV_LOG(ERR,
396                                             "Bad reply for vf_q %d teardown", i);
397                 }
398
399                 bnx2x_vf_set_mac(sc, false);
400
401                 query = &sc->vf2pf_mbox->query[0].close;
402                 bnx2x_init_first_tlv(sc, &query->first_tlv, BNX2X_VF_TLV_CLOSE,
403                                 sizeof(*query));
404
405                 query->vf_id = vf_id;
406
407                 bnx2x_add_tlv(sc, query, query->first_tlv.tl.length,
408                               BNX2X_VF_TLV_LIST_END,
409                               sizeof(struct channel_list_end_tlv));
410
411                 bnx2x_do_req4pf(sc, sc->vf2pf_mbox_mapping.paddr);
412                 if (reply->status != BNX2X_VF_STATUS_SUCCESS)
413                         PMD_DRV_LOG(ERR,
414                                     "Bad reply from PF for close message");
415         }
416 }
417
418 static inline uint16_t
419 bnx2x_vf_q_flags(uint8_t leading)
420 {
421         uint16_t flags = leading ? BNX2X_VF_Q_FLAG_LEADING_RSS : 0;
422
423         flags |= BNX2X_VF_Q_FLAG_CACHE_ALIGN;
424         flags |= BNX2X_VF_Q_FLAG_STATS;
425         flags |= BNX2X_VF_Q_FLAG_VLAN;
426
427         return flags;
428 }
429
430 static void
431 bnx2x_vf_rx_q_prep(struct bnx2x_softc *sc, struct bnx2x_fastpath *fp,
432                 struct vf_rxq_params *rxq_init, uint16_t flags)
433 {
434         struct bnx2x_rx_queue *rxq;
435
436         rxq = sc->rx_queues[fp->index];
437         if (!rxq) {
438                 PMD_DRV_LOG(ERR, "RX queue %d is NULL", fp->index);
439                 return;
440         }
441
442         rxq_init->rcq_addr = rxq->cq_ring_phys_addr;
443         rxq_init->rcq_np_addr = rxq->cq_ring_phys_addr + BNX2X_PAGE_SIZE;
444         rxq_init->rxq_addr = rxq->rx_ring_phys_addr;
445         rxq_init->vf_sb_id = fp->index;
446         rxq_init->sb_cq_index = HC_INDEX_ETH_RX_CQ_CONS;
447         rxq_init->mtu = sc->mtu;
448         rxq_init->buf_sz = fp->rx_buf_size;
449         rxq_init->flags = flags;
450         rxq_init->stat_id = -1;
451         rxq_init->cache_line_log = BNX2X_RX_ALIGN_SHIFT;
452 }
453
454 static void
455 bnx2x_vf_tx_q_prep(struct bnx2x_softc *sc, struct bnx2x_fastpath *fp,
456                 struct vf_txq_params *txq_init, uint16_t flags)
457 {
458         struct bnx2x_tx_queue *txq;
459
460         txq = sc->tx_queues[fp->index];
461         if (!txq) {
462                 PMD_DRV_LOG(ERR, "TX queue %d is NULL", fp->index);
463                 return;
464         }
465
466         txq_init->txq_addr = txq->tx_ring_phys_addr;
467         txq_init->sb_index = HC_INDEX_ETH_TX_CQ_CONS_COS0;
468         txq_init->flags = flags;
469         txq_init->traffic_type = LLFC_TRAFFIC_TYPE_NW;
470         txq_init->vf_sb_id = fp->index;
471 }
472
473 int
474 bnx2x_vf_setup_queue(struct bnx2x_softc *sc, struct bnx2x_fastpath *fp, int leading)
475 {
476         struct vf_setup_q_tlv *query;
477         struct vf_common_reply_tlv *reply = &sc->vf2pf_mbox->resp.common_reply;
478         uint16_t flags = bnx2x_vf_q_flags(leading);
479
480         query = &sc->vf2pf_mbox->query[0].setup_q;
481         bnx2x_init_first_tlv(sc, &query->first_tlv, BNX2X_VF_TLV_SETUP_Q,
482                         sizeof(*query));
483
484         query->vf_qid = fp->index;
485         query->param_valid = VF_RXQ_VALID | VF_TXQ_VALID;
486
487         bnx2x_vf_rx_q_prep(sc, fp, &query->rxq, flags);
488         bnx2x_vf_tx_q_prep(sc, fp, &query->txq, flags);
489
490         bnx2x_add_tlv(sc, query, query->first_tlv.tl.length,
491                       BNX2X_VF_TLV_LIST_END,
492                       sizeof(struct channel_list_end_tlv));
493
494         bnx2x_do_req4pf(sc, sc->vf2pf_mbox_mapping.paddr);
495         if (reply->status != BNX2X_VF_STATUS_SUCCESS) {
496                 PMD_DRV_LOG(ERR, "Failed to setup VF queue[%d]",
497                                  fp->index);
498                 return -EINVAL;
499         }
500
501         return 0;
502 }
503
504 int
505 bnx2x_vf_set_mac(struct bnx2x_softc *sc, int set)
506 {
507         struct vf_set_q_filters_tlv *query;
508         struct vf_common_reply_tlv *reply;
509
510         query = &sc->vf2pf_mbox->query[0].set_q_filters;
511         bnx2x_init_first_tlv(sc, &query->first_tlv, BNX2X_VF_TLV_SET_Q_FILTERS,
512                         sizeof(*query));
513
514         query->vf_qid = sc->fp->index;
515         query->mac_filters_cnt = 1;
516         query->flags = BNX2X_VF_MAC_VLAN_CHANGED;
517
518         query->filters[0].flags = (set ? BNX2X_VF_Q_FILTER_SET_MAC : 0) |
519                 BNX2X_VF_Q_FILTER_DEST_MAC_VALID;
520
521         bnx2x_check_bull(sc);
522
523         rte_memcpy(query->filters[0].mac, sc->link_params.mac_addr, ETH_ALEN);
524
525         bnx2x_add_tlv(sc, query, query->first_tlv.tl.length,
526                       BNX2X_VF_TLV_LIST_END,
527                       sizeof(struct channel_list_end_tlv));
528
529         bnx2x_do_req4pf(sc, sc->vf2pf_mbox_mapping.paddr);
530         reply = &sc->vf2pf_mbox->resp.common_reply;
531
532         while (BNX2X_VF_STATUS_FAILURE == reply->status &&
533                         bnx2x_check_bull(sc)) {
534                 /* A new mac was configured by PF for us */
535                 rte_memcpy(sc->link_params.mac_addr, sc->pf2vf_bulletin->mac,
536                                 ETH_ALEN);
537                 rte_memcpy(query->filters[0].mac, sc->pf2vf_bulletin->mac,
538                                 ETH_ALEN);
539
540                 bnx2x_do_req4pf(sc, sc->vf2pf_mbox_mapping.paddr);
541         }
542
543         if (BNX2X_VF_STATUS_SUCCESS != reply->status) {
544                 PMD_DRV_LOG(ERR, "Bad reply from PF for SET MAC message: %d",
545                                 reply->status);
546                 return -EINVAL;
547         }
548
549         return 0;
550 }
551
552 int
553 bnx2x_vf_config_rss(struct bnx2x_softc *sc,
554                           struct ecore_config_rss_params *params)
555 {
556         struct vf_rss_tlv *query;
557         struct vf_common_reply_tlv *reply = &sc->vf2pf_mbox->resp.common_reply;
558
559         query = &sc->vf2pf_mbox->query[0].update_rss;
560
561         bnx2x_init_first_tlv(sc, &query->first_tlv, BNX2X_VF_TLV_UPDATE_RSS,
562                         sizeof(*query));
563
564         /* add list termination tlv */
565         bnx2x_add_tlv(sc, query, query->first_tlv.tl.length,
566                       BNX2X_VF_TLV_LIST_END,
567                       sizeof(struct channel_list_end_tlv));
568
569         rte_memcpy(query->rss_key, params->rss_key, sizeof(params->rss_key));
570         query->rss_key_size = T_ETH_RSS_KEY;
571
572         rte_memcpy(query->ind_table, params->ind_table, T_ETH_INDIRECTION_TABLE_SIZE);
573         query->ind_table_size = T_ETH_INDIRECTION_TABLE_SIZE;
574
575         query->rss_result_mask = params->rss_result_mask;
576         query->rss_flags = params->rss_flags;
577
578         bnx2x_do_req4pf(sc, sc->vf2pf_mbox_mapping.paddr);
579         if (reply->status != BNX2X_VF_STATUS_SUCCESS) {
580                 PMD_DRV_LOG(ERR, "Failed to configure RSS");
581                 return -EINVAL;
582         }
583
584         return 0;
585 }
586
587 int
588 bnx2x_vf_set_rx_mode(struct bnx2x_softc *sc)
589 {
590         struct vf_set_q_filters_tlv *query;
591         struct vf_common_reply_tlv *reply = &sc->vf2pf_mbox->resp.common_reply;
592
593         query = &sc->vf2pf_mbox->query[0].set_q_filters;
594         bnx2x_init_first_tlv(sc, &query->first_tlv, BNX2X_VF_TLV_SET_Q_FILTERS,
595                         sizeof(*query));
596
597         query->vf_qid = 0;
598         query->flags = BNX2X_VF_RX_MASK_CHANGED;
599
600         switch (sc->rx_mode) {
601         case BNX2X_RX_MODE_NONE: /* no Rx */
602                 query->rx_mask = VFPF_RX_MASK_ACCEPT_NONE;
603                 break;
604         case BNX2X_RX_MODE_NORMAL:
605                 query->rx_mask = VFPF_RX_MASK_ACCEPT_MATCHED_MULTICAST;
606                 query->rx_mask |= VFPF_RX_MASK_ACCEPT_MATCHED_UNICAST;
607                 query->rx_mask |= VFPF_RX_MASK_ACCEPT_BROADCAST;
608                 break;
609         case BNX2X_RX_MODE_ALLMULTI:
610                 query->rx_mask = VFPF_RX_MASK_ACCEPT_ALL_MULTICAST;
611                 query->rx_mask |= VFPF_RX_MASK_ACCEPT_MATCHED_UNICAST;
612                 query->rx_mask |= VFPF_RX_MASK_ACCEPT_BROADCAST;
613                 break;
614         case BNX2X_RX_MODE_PROMISC:
615                 query->rx_mask = VFPF_RX_MASK_ACCEPT_ALL_UNICAST;
616                 query->rx_mask |= VFPF_RX_MASK_ACCEPT_ALL_MULTICAST;
617                 query->rx_mask |= VFPF_RX_MASK_ACCEPT_BROADCAST;
618                 break;
619         default:
620                 PMD_DRV_LOG(ERR, "BAD rx mode (%d)", sc->rx_mode);
621                 return -EINVAL;
622         }
623
624         bnx2x_add_tlv(sc, query, query->first_tlv.tl.length,
625                       BNX2X_VF_TLV_LIST_END,
626                       sizeof(struct channel_list_end_tlv));
627
628         bnx2x_do_req4pf(sc, sc->vf2pf_mbox_mapping.paddr);
629         if (reply->status != BNX2X_VF_STATUS_SUCCESS) {
630                 PMD_DRV_LOG(ERR, "Failed to set RX mode");
631                 return -EINVAL;
632         }
633
634         return 0;
635 }