36246129864ca8176203f68421dbf721d6a078fb
[linux-drm-fsl-dcu.git] / drivers / net / ethernet / broadcom / bnx2x / bnx2x_vfpf.c
1 /* bnx2x_vfpf.c: Broadcom Everest network driver.
2  *
3  * Copyright 2009-2013 Broadcom Corporation
4  *
5  * Unless you and Broadcom execute a separate written software license
6  * agreement governing use of this software, this software is licensed to you
7  * under the terms of the GNU General Public License version 2, available
8  * at http://www.gnu.org/licenses/old-licenses/gpl-2.0.html (the "GPL").
9  *
10  * Notwithstanding the above, under no circumstances may you combine this
11  * software in any way with any other Broadcom software provided under a
12  * license other than the GPL, without Broadcom's express prior written
13  * consent.
14  *
15  * Maintained by: Eilon Greenstein <eilong@broadcom.com>
16  * Written by: Shmulik Ravid <shmulikr@broadcom.com>
17  *             Ariel Elior <ariele@broadcom.com>
18  */
19
20 #include "bnx2x.h"
21 #include "bnx2x_cmn.h"
22 #include <linux/crc32.h>
23
24 /* place a given tlv on the tlv buffer at a given offset */
25 void bnx2x_add_tlv(struct bnx2x *bp, void *tlvs_list, u16 offset, u16 type,
26                    u16 length)
27 {
28         struct channel_tlv *tl =
29                 (struct channel_tlv *)(tlvs_list + offset);
30
31         tl->type = type;
32         tl->length = length;
33 }
34
35 /* Clear the mailbox and init the header of the first tlv */
36 void bnx2x_vfpf_prep(struct bnx2x *bp, struct vfpf_first_tlv *first_tlv,
37                      u16 type, u16 length)
38 {
39         DP(BNX2X_MSG_IOV, "preparing to send %d tlv over vf pf channel\n",
40            type);
41
42         /* Clear mailbox */
43         memset(bp->vf2pf_mbox, 0, sizeof(struct bnx2x_vf_mbx_msg));
44
45         /* init type and length */
46         bnx2x_add_tlv(bp, &first_tlv->tl, 0, type, length);
47
48         /* init first tlv header */
49         first_tlv->resp_msg_offset = sizeof(bp->vf2pf_mbox->req);
50 }
51
52 /* list the types and lengths of the tlvs on the buffer */
53 void bnx2x_dp_tlv_list(struct bnx2x *bp, void *tlvs_list)
54 {
55         int i = 1;
56         struct channel_tlv *tlv = (struct channel_tlv *)tlvs_list;
57
58         while (tlv->type != CHANNEL_TLV_LIST_END) {
59                 /* output tlv */
60                 DP(BNX2X_MSG_IOV, "TLV number %d: type %d, length %d\n", i,
61                    tlv->type, tlv->length);
62
63                 /* advance to next tlv */
64                 tlvs_list += tlv->length;
65
66                 /* cast general tlv list pointer to channel tlv header*/
67                 tlv = (struct channel_tlv *)tlvs_list;
68
69                 i++;
70
71                 /* break condition for this loop */
72                 if (i > MAX_TLVS_IN_LIST) {
73                         WARN(true, "corrupt tlvs");
74                         return;
75                 }
76         }
77
78         /* output last tlv */
79         DP(BNX2X_MSG_IOV, "TLV number %d: type %d, length %d\n", i,
80            tlv->type, tlv->length);
81 }
82
83 /* test whether we support a tlv type */
84 bool bnx2x_tlv_supported(u16 tlvtype)
85 {
86         return CHANNEL_TLV_NONE < tlvtype && tlvtype < CHANNEL_TLV_MAX;
87 }
88
89 static inline int bnx2x_pfvf_status_codes(int rc)
90 {
91         switch (rc) {
92         case 0:
93                 return PFVF_STATUS_SUCCESS;
94         case -ENOMEM:
95                 return PFVF_STATUS_NO_RESOURCE;
96         default:
97                 return PFVF_STATUS_FAILURE;
98         }
99 }
100
101 int bnx2x_send_msg2pf(struct bnx2x *bp, u8 *done, dma_addr_t msg_mapping)
102 {
103         struct cstorm_vf_zone_data __iomem *zone_data =
104                 REG_ADDR(bp, PXP_VF_ADDR_CSDM_GLOBAL_START);
105         int tout = 600, interval = 100; /* wait for 60 seconds */
106
107         if (*done) {
108                 BNX2X_ERR("done was non zero before message to pf was sent\n");
109                 WARN_ON(true);
110                 return -EINVAL;
111         }
112
113         /* Write message address */
114         writel(U64_LO(msg_mapping),
115                &zone_data->non_trigger.vf_pf_channel.msg_addr_lo);
116         writel(U64_HI(msg_mapping),
117                &zone_data->non_trigger.vf_pf_channel.msg_addr_hi);
118
119         /* make sure the address is written before FW accesses it */
120         wmb();
121
122         /* Trigger the PF FW */
123         writeb(1, &zone_data->trigger.vf_pf_channel.addr_valid);
124
125         /* Wait for PF to complete */
126         while ((tout >= 0) && (!*done)) {
127                 msleep(interval);
128                 tout -= 1;
129
130                 /* progress indicator - HV can take its own sweet time in
131                  * answering VFs...
132                  */
133                 DP_CONT(BNX2X_MSG_IOV, ".");
134         }
135
136         if (!*done) {
137                 BNX2X_ERR("PF response has timed out\n");
138                 return -EAGAIN;
139         }
140         DP(BNX2X_MSG_SP, "Got a response from PF\n");
141         return 0;
142 }
143
144 int bnx2x_get_vf_id(struct bnx2x *bp, u32 *vf_id)
145 {
146         u32 me_reg;
147         int tout = 10, interval = 100; /* Wait for 1 sec */
148
149         do {
150                 /* pxp traps vf read of doorbells and returns me reg value */
151                 me_reg = readl(bp->doorbells);
152                 if (GOOD_ME_REG(me_reg))
153                         break;
154
155                 msleep(interval);
156
157                 BNX2X_ERR("Invalid ME register value: 0x%08x\n. Is pf driver up?",
158                           me_reg);
159         } while (tout-- > 0);
160
161         if (!GOOD_ME_REG(me_reg)) {
162                 BNX2X_ERR("Invalid ME register value: 0x%08x\n", me_reg);
163                 return -EINVAL;
164         }
165
166         BNX2X_ERR("valid ME register value: 0x%08x\n", me_reg);
167
168         *vf_id = (me_reg & ME_REG_VF_NUM_MASK) >> ME_REG_VF_NUM_SHIFT;
169
170         return 0;
171 }
172
173 int bnx2x_vfpf_acquire(struct bnx2x *bp, u8 tx_count, u8 rx_count)
174 {
175         int rc = 0, attempts = 0;
176         struct vfpf_acquire_tlv *req = &bp->vf2pf_mbox->req.acquire;
177         struct pfvf_acquire_resp_tlv *resp = &bp->vf2pf_mbox->resp.acquire_resp;
178         u32 vf_id;
179         bool resources_acquired = false;
180
181         /* clear mailbox and prep first tlv */
182         bnx2x_vfpf_prep(bp, &req->first_tlv, CHANNEL_TLV_ACQUIRE, sizeof(*req));
183
184         if (bnx2x_get_vf_id(bp, &vf_id))
185                 return -EAGAIN;
186
187         req->vfdev_info.vf_id = vf_id;
188         req->vfdev_info.vf_os = 0;
189
190         req->resc_request.num_rxqs = rx_count;
191         req->resc_request.num_txqs = tx_count;
192         req->resc_request.num_sbs = bp->igu_sb_cnt;
193         req->resc_request.num_mac_filters = VF_ACQUIRE_MAC_FILTERS;
194         req->resc_request.num_mc_filters = VF_ACQUIRE_MC_FILTERS;
195
196         /* pf 2 vf bulletin board address */
197         req->bulletin_addr = bp->pf2vf_bulletin_mapping;
198
199         /* add list termination tlv */
200         bnx2x_add_tlv(bp, req, req->first_tlv.tl.length, CHANNEL_TLV_LIST_END,
201                       sizeof(struct channel_list_end_tlv));
202
203         /* output tlvs list */
204         bnx2x_dp_tlv_list(bp, req);
205
206         while (!resources_acquired) {
207                 DP(BNX2X_MSG_SP, "attempting to acquire resources\n");
208
209                 /* send acquire request */
210                 rc = bnx2x_send_msg2pf(bp,
211                                        &resp->hdr.status,
212                                        bp->vf2pf_mbox_mapping);
213
214                 /* PF timeout */
215                 if (rc)
216                         return rc;
217
218                 /* copy acquire response from buffer to bp */
219                 memcpy(&bp->acquire_resp, resp, sizeof(bp->acquire_resp));
220
221                 attempts++;
222
223                 /* test whether the PF accepted our request. If not, humble the
224                  * the request and try again.
225                  */
226                 if (bp->acquire_resp.hdr.status == PFVF_STATUS_SUCCESS) {
227                         DP(BNX2X_MSG_SP, "resources acquired\n");
228                         resources_acquired = true;
229                 } else if (bp->acquire_resp.hdr.status ==
230                            PFVF_STATUS_NO_RESOURCE &&
231                            attempts < VF_ACQUIRE_THRESH) {
232                         DP(BNX2X_MSG_SP,
233                            "PF unwilling to fulfill resource request. Try PF recommended amount\n");
234
235                         /* humble our request */
236                         req->resc_request.num_txqs =
237                                 bp->acquire_resp.resc.num_txqs;
238                         req->resc_request.num_rxqs =
239                                 bp->acquire_resp.resc.num_rxqs;
240                         req->resc_request.num_sbs =
241                                 bp->acquire_resp.resc.num_sbs;
242                         req->resc_request.num_mac_filters =
243                                 bp->acquire_resp.resc.num_mac_filters;
244                         req->resc_request.num_vlan_filters =
245                                 bp->acquire_resp.resc.num_vlan_filters;
246                         req->resc_request.num_mc_filters =
247                                 bp->acquire_resp.resc.num_mc_filters;
248
249                         /* Clear response buffer */
250                         memset(&bp->vf2pf_mbox->resp, 0,
251                                sizeof(union pfvf_tlvs));
252                 } else {
253                         /* PF reports error */
254                         BNX2X_ERR("Failed to get the requested amount of resources: %d. Breaking...\n",
255                                   bp->acquire_resp.hdr.status);
256                         return -EAGAIN;
257                 }
258         }
259
260         /* get HW info */
261         bp->common.chip_id |= (bp->acquire_resp.pfdev_info.chip_num & 0xffff);
262         bp->link_params.chip_id = bp->common.chip_id;
263         bp->db_size = bp->acquire_resp.pfdev_info.db_size;
264         bp->common.int_block = INT_BLOCK_IGU;
265         bp->common.chip_port_mode = CHIP_2_PORT_MODE;
266         bp->igu_dsb_id = -1;
267         bp->mf_ov = 0;
268         bp->mf_mode = 0;
269         bp->common.flash_size = 0;
270         bp->flags |=
271                 NO_WOL_FLAG | NO_ISCSI_OOO_FLAG | NO_ISCSI_FLAG | NO_FCOE_FLAG;
272         bp->igu_sb_cnt = 1;
273         bp->igu_base_sb = bp->acquire_resp.resc.hw_sbs[0].hw_sb_id;
274         strlcpy(bp->fw_ver, bp->acquire_resp.pfdev_info.fw_ver,
275                 sizeof(bp->fw_ver));
276
277         if (is_valid_ether_addr(bp->acquire_resp.resc.current_mac_addr))
278                 memcpy(bp->dev->dev_addr,
279                        bp->acquire_resp.resc.current_mac_addr,
280                        ETH_ALEN);
281
282         return 0;
283 }
284
285 int bnx2x_vfpf_release(struct bnx2x *bp)
286 {
287         struct vfpf_release_tlv *req = &bp->vf2pf_mbox->req.release;
288         struct pfvf_general_resp_tlv *resp = &bp->vf2pf_mbox->resp.general_resp;
289         u32 rc = 0, vf_id;
290
291         /* clear mailbox and prep first tlv */
292         bnx2x_vfpf_prep(bp, &req->first_tlv, CHANNEL_TLV_RELEASE, sizeof(*req));
293
294         if (bnx2x_get_vf_id(bp, &vf_id))
295                 return -EAGAIN;
296
297         req->vf_id = vf_id;
298
299         /* add list termination tlv */
300         bnx2x_add_tlv(bp, req, req->first_tlv.tl.length, CHANNEL_TLV_LIST_END,
301                       sizeof(struct channel_list_end_tlv));
302
303         /* output tlvs list */
304         bnx2x_dp_tlv_list(bp, req);
305
306         /* send release request */
307         rc = bnx2x_send_msg2pf(bp, &resp->hdr.status, bp->vf2pf_mbox_mapping);
308
309         if (rc)
310                 /* PF timeout */
311                 return rc;
312         if (resp->hdr.status == PFVF_STATUS_SUCCESS) {
313                 /* PF released us */
314                 DP(BNX2X_MSG_SP, "vf released\n");
315         } else {
316                 /* PF reports error */
317                 BNX2X_ERR("PF failed our release request - are we out of sync? response status: %d\n",
318                           resp->hdr.status);
319                 return -EAGAIN;
320         }
321
322         return 0;
323 }
324
325 /* Tell PF about SB addresses */
326 int bnx2x_vfpf_init(struct bnx2x *bp)
327 {
328         struct vfpf_init_tlv *req = &bp->vf2pf_mbox->req.init;
329         struct pfvf_general_resp_tlv *resp = &bp->vf2pf_mbox->resp.general_resp;
330         int rc, i;
331
332         /* clear mailbox and prep first tlv */
333         bnx2x_vfpf_prep(bp, &req->first_tlv, CHANNEL_TLV_INIT, sizeof(*req));
334
335         /* status blocks */
336         for_each_eth_queue(bp, i)
337                 req->sb_addr[i] = (dma_addr_t)bnx2x_fp(bp, i,
338                                                        status_blk_mapping);
339
340         /* statistics - requests only supports single queue for now */
341         req->stats_addr = bp->fw_stats_data_mapping +
342                           offsetof(struct bnx2x_fw_stats_data, queue_stats);
343
344         /* add list termination tlv */
345         bnx2x_add_tlv(bp, req, req->first_tlv.tl.length, CHANNEL_TLV_LIST_END,
346                       sizeof(struct channel_list_end_tlv));
347
348         /* output tlvs list */
349         bnx2x_dp_tlv_list(bp, req);
350
351         rc = bnx2x_send_msg2pf(bp, &resp->hdr.status, bp->vf2pf_mbox_mapping);
352         if (rc)
353                 return rc;
354
355         if (resp->hdr.status != PFVF_STATUS_SUCCESS) {
356                 BNX2X_ERR("INIT VF failed: %d. Breaking...\n",
357                           resp->hdr.status);
358                 return -EAGAIN;
359         }
360
361         DP(BNX2X_MSG_SP, "INIT VF Succeeded\n");
362         return 0;
363 }
364
365 /* CLOSE VF - opposite to INIT_VF */
366 void bnx2x_vfpf_close_vf(struct bnx2x *bp)
367 {
368         struct vfpf_close_tlv *req = &bp->vf2pf_mbox->req.close;
369         struct pfvf_general_resp_tlv *resp = &bp->vf2pf_mbox->resp.general_resp;
370         int i, rc;
371         u32 vf_id;
372
373         /* If we haven't got a valid VF id, there is no sense to
374          * continue with sending messages
375          */
376         if (bnx2x_get_vf_id(bp, &vf_id))
377                 goto free_irq;
378
379         /* Close the queues */
380         for_each_queue(bp, i)
381                 bnx2x_vfpf_teardown_queue(bp, i);
382
383         /* clear mailbox and prep first tlv */
384         bnx2x_vfpf_prep(bp, &req->first_tlv, CHANNEL_TLV_CLOSE, sizeof(*req));
385
386         req->vf_id = vf_id;
387
388         /* add list termination tlv */
389         bnx2x_add_tlv(bp, req, req->first_tlv.tl.length, CHANNEL_TLV_LIST_END,
390                       sizeof(struct channel_list_end_tlv));
391
392         /* output tlvs list */
393         bnx2x_dp_tlv_list(bp, req);
394
395         rc = bnx2x_send_msg2pf(bp, &resp->hdr.status, bp->vf2pf_mbox_mapping);
396
397         if (rc)
398                 BNX2X_ERR("Sending CLOSE failed. rc was: %d\n", rc);
399
400         else if (resp->hdr.status != PFVF_STATUS_SUCCESS)
401                 BNX2X_ERR("Sending CLOSE failed: pf response was %d\n",
402                           resp->hdr.status);
403
404 free_irq:
405         /* Disable HW interrupts, NAPI */
406         bnx2x_netif_stop(bp, 0);
407         /* Delete all NAPI objects */
408         bnx2x_del_all_napi(bp);
409
410         /* Release IRQs */
411         bnx2x_free_irq(bp);
412 }
413
414 /* ask the pf to open a queue for the vf */
415 int bnx2x_vfpf_setup_q(struct bnx2x *bp, int fp_idx)
416 {
417         struct vfpf_setup_q_tlv *req = &bp->vf2pf_mbox->req.setup_q;
418         struct pfvf_general_resp_tlv *resp = &bp->vf2pf_mbox->resp.general_resp;
419         struct bnx2x_fastpath *fp = &bp->fp[fp_idx];
420         u16 tpa_agg_size = 0, flags = 0;
421         int rc;
422
423         /* clear mailbox and prep first tlv */
424         bnx2x_vfpf_prep(bp, &req->first_tlv, CHANNEL_TLV_SETUP_Q, sizeof(*req));
425
426         /* select tpa mode to request */
427         if (!fp->disable_tpa) {
428                 flags |= VFPF_QUEUE_FLG_TPA;
429                 flags |= VFPF_QUEUE_FLG_TPA_IPV6;
430                 if (fp->mode == TPA_MODE_GRO)
431                         flags |= VFPF_QUEUE_FLG_TPA_GRO;
432                 tpa_agg_size = TPA_AGG_SIZE;
433         }
434
435         /* calculate queue flags */
436         flags |= VFPF_QUEUE_FLG_STATS;
437         flags |= VFPF_QUEUE_FLG_CACHE_ALIGN;
438         flags |= IS_MF_SD(bp) ? VFPF_QUEUE_FLG_OV : 0;
439         flags |= VFPF_QUEUE_FLG_VLAN;
440         DP(NETIF_MSG_IFUP, "vlan removal enabled\n");
441
442         /* Common */
443         req->vf_qid = fp_idx;
444         req->param_valid = VFPF_RXQ_VALID | VFPF_TXQ_VALID;
445
446         /* Rx */
447         req->rxq.rcq_addr = fp->rx_comp_mapping;
448         req->rxq.rcq_np_addr = fp->rx_comp_mapping + BCM_PAGE_SIZE;
449         req->rxq.rxq_addr = fp->rx_desc_mapping;
450         req->rxq.sge_addr = fp->rx_sge_mapping;
451         req->rxq.vf_sb = fp_idx;
452         req->rxq.sb_index = HC_INDEX_ETH_RX_CQ_CONS;
453         req->rxq.hc_rate = bp->rx_ticks ? 1000000/bp->rx_ticks : 0;
454         req->rxq.mtu = bp->dev->mtu;
455         req->rxq.buf_sz = fp->rx_buf_size;
456         req->rxq.sge_buf_sz = BCM_PAGE_SIZE * PAGES_PER_SGE;
457         req->rxq.tpa_agg_sz = tpa_agg_size;
458         req->rxq.max_sge_pkt = SGE_PAGE_ALIGN(bp->dev->mtu) >> SGE_PAGE_SHIFT;
459         req->rxq.max_sge_pkt = ((req->rxq.max_sge_pkt + PAGES_PER_SGE - 1) &
460                           (~(PAGES_PER_SGE-1))) >> PAGES_PER_SGE_SHIFT;
461         req->rxq.flags = flags;
462         req->rxq.drop_flags = 0;
463         req->rxq.cache_line_log = BNX2X_RX_ALIGN_SHIFT;
464         req->rxq.stat_id = -1; /* No stats at the moment */
465
466         /* Tx */
467         req->txq.txq_addr = fp->txdata_ptr[FIRST_TX_COS_INDEX]->tx_desc_mapping;
468         req->txq.vf_sb = fp_idx;
469         req->txq.sb_index = HC_INDEX_ETH_TX_CQ_CONS_COS0;
470         req->txq.hc_rate = bp->tx_ticks ? 1000000/bp->tx_ticks : 0;
471         req->txq.flags = flags;
472         req->txq.traffic_type = LLFC_TRAFFIC_TYPE_NW;
473
474         /* add list termination tlv */
475         bnx2x_add_tlv(bp, req, req->first_tlv.tl.length, CHANNEL_TLV_LIST_END,
476                       sizeof(struct channel_list_end_tlv));
477
478         /* output tlvs list */
479         bnx2x_dp_tlv_list(bp, req);
480
481         rc = bnx2x_send_msg2pf(bp, &resp->hdr.status, bp->vf2pf_mbox_mapping);
482         if (rc)
483                 BNX2X_ERR("Sending SETUP_Q message for queue[%d] failed!\n",
484                           fp_idx);
485
486         if (resp->hdr.status != PFVF_STATUS_SUCCESS) {
487                 BNX2X_ERR("Status of SETUP_Q for queue[%d] is %d\n",
488                           fp_idx, resp->hdr.status);
489                 return -EINVAL;
490         }
491         return rc;
492 }
493
494 int bnx2x_vfpf_teardown_queue(struct bnx2x *bp, int qidx)
495 {
496         struct vfpf_q_op_tlv *req = &bp->vf2pf_mbox->req.q_op;
497         struct pfvf_general_resp_tlv *resp = &bp->vf2pf_mbox->resp.general_resp;
498         int rc;
499
500         /* clear mailbox and prep first tlv */
501         bnx2x_vfpf_prep(bp, &req->first_tlv, CHANNEL_TLV_TEARDOWN_Q,
502                         sizeof(*req));
503
504         req->vf_qid = qidx;
505
506         /* add list termination tlv */
507         bnx2x_add_tlv(bp, req, req->first_tlv.tl.length, CHANNEL_TLV_LIST_END,
508                       sizeof(struct channel_list_end_tlv));
509
510         /* output tlvs list */
511         bnx2x_dp_tlv_list(bp, req);
512
513         rc = bnx2x_send_msg2pf(bp, &resp->hdr.status, bp->vf2pf_mbox_mapping);
514
515         if (rc) {
516                 BNX2X_ERR("Sending TEARDOWN for queue %d failed: %d\n", qidx,
517                           rc);
518                 return rc;
519         }
520
521         /* PF failed the transaction */
522         if (resp->hdr.status != PFVF_STATUS_SUCCESS) {
523                 BNX2X_ERR("TEARDOWN for queue %d failed: %d\n", qidx,
524                           resp->hdr.status);
525                 return -EINVAL;
526         }
527
528         return 0;
529 }
530
531 /* request pf to add a mac for the vf */
532 int bnx2x_vfpf_set_mac(struct bnx2x *bp)
533 {
534         struct vfpf_set_q_filters_tlv *req = &bp->vf2pf_mbox->req.set_q_filters;
535         struct pfvf_general_resp_tlv *resp = &bp->vf2pf_mbox->resp.general_resp;
536         int rc;
537
538         /* clear mailbox and prep first tlv */
539         bnx2x_vfpf_prep(bp, &req->first_tlv, CHANNEL_TLV_SET_Q_FILTERS,
540                         sizeof(*req));
541
542         req->flags = VFPF_SET_Q_FILTERS_MAC_VLAN_CHANGED;
543         req->vf_qid = 0;
544         req->n_mac_vlan_filters = 1;
545         req->filters[0].flags =
546                 VFPF_Q_FILTER_DEST_MAC_VALID | VFPF_Q_FILTER_SET_MAC;
547
548         /* sample bulletin board for new mac */
549         bnx2x_sample_bulletin(bp);
550
551         /* copy mac from device to request */
552         memcpy(req->filters[0].mac, bp->dev->dev_addr, ETH_ALEN);
553
554         /* add list termination tlv */
555         bnx2x_add_tlv(bp, req, req->first_tlv.tl.length, CHANNEL_TLV_LIST_END,
556                       sizeof(struct channel_list_end_tlv));
557
558         /* output tlvs list */
559         bnx2x_dp_tlv_list(bp, req);
560
561         /* send message to pf */
562         rc = bnx2x_send_msg2pf(bp, &resp->hdr.status, bp->vf2pf_mbox_mapping);
563         if (rc) {
564                 BNX2X_ERR("failed to send message to pf. rc was %d\n", rc);
565                 return rc;
566         }
567
568         /* failure may mean PF was configured with a new mac for us */
569         while (resp->hdr.status == PFVF_STATUS_FAILURE) {
570                 DP(BNX2X_MSG_IOV,
571                    "vfpf SET MAC failed. Check bulletin board for new posts\n");
572
573                 /* check if bulletin board was updated */
574                 if (bnx2x_sample_bulletin(bp) == PFVF_BULLETIN_UPDATED) {
575                         /* copy mac from device to request */
576                         memcpy(req->filters[0].mac, bp->dev->dev_addr,
577                                ETH_ALEN);
578
579                         /* send message to pf */
580                         rc = bnx2x_send_msg2pf(bp, &resp->hdr.status,
581                                                bp->vf2pf_mbox_mapping);
582                 } else {
583                         /* no new info in bulletin */
584                         break;
585                 }
586         }
587
588         if (resp->hdr.status != PFVF_STATUS_SUCCESS) {
589                 BNX2X_ERR("vfpf SET MAC failed: %d\n", resp->hdr.status);
590                 return -EINVAL;
591         }
592
593         return 0;
594 }
595
596 int bnx2x_vfpf_set_mcast(struct net_device *dev)
597 {
598         struct bnx2x *bp = netdev_priv(dev);
599         struct vfpf_set_q_filters_tlv *req = &bp->vf2pf_mbox->req.set_q_filters;
600         struct pfvf_general_resp_tlv *resp = &bp->vf2pf_mbox->resp.general_resp;
601         int rc, i = 0;
602         struct netdev_hw_addr *ha;
603
604         if (bp->state != BNX2X_STATE_OPEN) {
605                 DP(NETIF_MSG_IFUP, "state is %x, returning\n", bp->state);
606                 return -EINVAL;
607         }
608
609         /* clear mailbox and prep first tlv */
610         bnx2x_vfpf_prep(bp, &req->first_tlv, CHANNEL_TLV_SET_Q_FILTERS,
611                         sizeof(*req));
612
613         /* Get Rx mode requested */
614         DP(NETIF_MSG_IFUP, "dev->flags = %x\n", dev->flags);
615
616         netdev_for_each_mc_addr(ha, dev) {
617                 DP(NETIF_MSG_IFUP, "Adding mcast MAC: %pM\n",
618                    bnx2x_mc_addr(ha));
619                 memcpy(req->multicast[i], bnx2x_mc_addr(ha), ETH_ALEN);
620                 i++;
621         }
622
623         /* We support four PFVF_MAX_MULTICAST_PER_VF mcast
624           * addresses tops
625           */
626         if (i >= PFVF_MAX_MULTICAST_PER_VF) {
627                 DP(NETIF_MSG_IFUP,
628                    "VF supports not more than %d multicast MAC addresses\n",
629                    PFVF_MAX_MULTICAST_PER_VF);
630                 return -EINVAL;
631         }
632
633         req->n_multicast = i;
634         req->flags |= VFPF_SET_Q_FILTERS_MULTICAST_CHANGED;
635         req->vf_qid = 0;
636
637         /* add list termination tlv */
638         bnx2x_add_tlv(bp, req, req->first_tlv.tl.length, CHANNEL_TLV_LIST_END,
639                       sizeof(struct channel_list_end_tlv));
640
641         /* output tlvs list */
642         bnx2x_dp_tlv_list(bp, req);
643         rc = bnx2x_send_msg2pf(bp, &resp->hdr.status, bp->vf2pf_mbox_mapping);
644         if (rc) {
645                 BNX2X_ERR("Sending a message failed: %d\n", rc);
646                 return rc;
647         }
648
649         if (resp->hdr.status != PFVF_STATUS_SUCCESS) {
650                 BNX2X_ERR("Set Rx mode/multicast failed: %d\n",
651                           resp->hdr.status);
652                 return -EINVAL;
653         }
654
655         return 0;
656 }
657
658 int bnx2x_vfpf_storm_rx_mode(struct bnx2x *bp)
659 {
660         int mode = bp->rx_mode;
661         struct vfpf_set_q_filters_tlv *req = &bp->vf2pf_mbox->req.set_q_filters;
662         struct pfvf_general_resp_tlv *resp = &bp->vf2pf_mbox->resp.general_resp;
663         int rc;
664
665         /* clear mailbox and prep first tlv */
666         bnx2x_vfpf_prep(bp, &req->first_tlv, CHANNEL_TLV_SET_Q_FILTERS,
667                         sizeof(*req));
668
669         DP(NETIF_MSG_IFUP, "Rx mode is %d\n", mode);
670
671         switch (mode) {
672         case BNX2X_RX_MODE_NONE: /* no Rx */
673                 req->rx_mask = VFPF_RX_MASK_ACCEPT_NONE;
674                 break;
675         case BNX2X_RX_MODE_NORMAL:
676                 req->rx_mask = VFPF_RX_MASK_ACCEPT_MATCHED_MULTICAST;
677                 req->rx_mask |= VFPF_RX_MASK_ACCEPT_MATCHED_UNICAST;
678                 req->rx_mask |= VFPF_RX_MASK_ACCEPT_BROADCAST;
679                 break;
680         case BNX2X_RX_MODE_ALLMULTI:
681                 req->rx_mask = VFPF_RX_MASK_ACCEPT_ALL_MULTICAST;
682                 req->rx_mask |= VFPF_RX_MASK_ACCEPT_MATCHED_UNICAST;
683                 req->rx_mask |= VFPF_RX_MASK_ACCEPT_BROADCAST;
684                 break;
685         case BNX2X_RX_MODE_PROMISC:
686                 req->rx_mask = VFPF_RX_MASK_ACCEPT_ALL_UNICAST;
687                 req->rx_mask |= VFPF_RX_MASK_ACCEPT_ALL_MULTICAST;
688                 req->rx_mask |= VFPF_RX_MASK_ACCEPT_BROADCAST;
689                 break;
690         default:
691                 BNX2X_ERR("BAD rx mode (%d)\n", mode);
692                 return -EINVAL;
693         }
694
695         req->flags |= VFPF_SET_Q_FILTERS_RX_MASK_CHANGED;
696         req->vf_qid = 0;
697
698         /* add list termination tlv */
699         bnx2x_add_tlv(bp, req, req->first_tlv.tl.length, CHANNEL_TLV_LIST_END,
700                       sizeof(struct channel_list_end_tlv));
701
702         /* output tlvs list */
703         bnx2x_dp_tlv_list(bp, req);
704
705         rc = bnx2x_send_msg2pf(bp, &resp->hdr.status, bp->vf2pf_mbox_mapping);
706         if (rc)
707                 BNX2X_ERR("Sending a message failed: %d\n", rc);
708
709         if (resp->hdr.status != PFVF_STATUS_SUCCESS) {
710                 BNX2X_ERR("Set Rx mode failed: %d\n", resp->hdr.status);
711                 return -EINVAL;
712         }
713
714         return rc;
715 }
716
717 /* General service functions */
718 static void storm_memset_vf_mbx_ack(struct bnx2x *bp, u16 abs_fid)
719 {
720         u32 addr = BAR_CSTRORM_INTMEM +
721                    CSTORM_VF_PF_CHANNEL_STATE_OFFSET(abs_fid);
722
723         REG_WR8(bp, addr, VF_PF_CHANNEL_STATE_READY);
724 }
725
726 static void storm_memset_vf_mbx_valid(struct bnx2x *bp, u16 abs_fid)
727 {
728         u32 addr = BAR_CSTRORM_INTMEM +
729                    CSTORM_VF_PF_CHANNEL_VALID_OFFSET(abs_fid);
730
731         REG_WR8(bp, addr, 1);
732 }
733
734 static inline void bnx2x_set_vf_mbxs_valid(struct bnx2x *bp)
735 {
736         int i;
737
738         for_each_vf(bp, i)
739                 storm_memset_vf_mbx_valid(bp, bnx2x_vf(bp, i, abs_vfid));
740 }
741
742 /* enable vf_pf mailbox (aka vf-pf-chanell) */
743 void bnx2x_vf_enable_mbx(struct bnx2x *bp, u8 abs_vfid)
744 {
745         bnx2x_vf_flr_clnup_epilog(bp, abs_vfid);
746
747         /* enable the mailbox in the FW */
748         storm_memset_vf_mbx_ack(bp, abs_vfid);
749         storm_memset_vf_mbx_valid(bp, abs_vfid);
750
751         /* enable the VF access to the mailbox */
752         bnx2x_vf_enable_access(bp, abs_vfid);
753 }
754
755 /* this works only on !E1h */
756 static int bnx2x_copy32_vf_dmae(struct bnx2x *bp, u8 from_vf,
757                                 dma_addr_t pf_addr, u8 vfid, u32 vf_addr_hi,
758                                 u32 vf_addr_lo, u32 len32)
759 {
760         struct dmae_command dmae;
761
762         if (CHIP_IS_E1x(bp)) {
763                 BNX2X_ERR("Chip revision does not support VFs\n");
764                 return DMAE_NOT_RDY;
765         }
766
767         if (!bp->dmae_ready) {
768                 BNX2X_ERR("DMAE is not ready, can not copy\n");
769                 return DMAE_NOT_RDY;
770         }
771
772         /* set opcode and fixed command fields */
773         bnx2x_prep_dmae_with_comp(bp, &dmae, DMAE_SRC_PCI, DMAE_DST_PCI);
774
775         if (from_vf) {
776                 dmae.opcode_iov = (vfid << DMAE_COMMAND_SRC_VFID_SHIFT) |
777                         (DMAE_SRC_VF << DMAE_COMMAND_SRC_VFPF_SHIFT) |
778                         (DMAE_DST_PF << DMAE_COMMAND_DST_VFPF_SHIFT);
779
780                 dmae.opcode |= (DMAE_C_DST << DMAE_COMMAND_C_FUNC_SHIFT);
781
782                 dmae.src_addr_lo = vf_addr_lo;
783                 dmae.src_addr_hi = vf_addr_hi;
784                 dmae.dst_addr_lo = U64_LO(pf_addr);
785                 dmae.dst_addr_hi = U64_HI(pf_addr);
786         } else {
787                 dmae.opcode_iov = (vfid << DMAE_COMMAND_DST_VFID_SHIFT) |
788                         (DMAE_DST_VF << DMAE_COMMAND_DST_VFPF_SHIFT) |
789                         (DMAE_SRC_PF << DMAE_COMMAND_SRC_VFPF_SHIFT);
790
791                 dmae.opcode |= (DMAE_C_SRC << DMAE_COMMAND_C_FUNC_SHIFT);
792
793                 dmae.src_addr_lo = U64_LO(pf_addr);
794                 dmae.src_addr_hi = U64_HI(pf_addr);
795                 dmae.dst_addr_lo = vf_addr_lo;
796                 dmae.dst_addr_hi = vf_addr_hi;
797         }
798         dmae.len = len32;
799         bnx2x_dp_dmae(bp, &dmae, BNX2X_MSG_DMAE);
800
801         /* issue the command and wait for completion */
802         return bnx2x_issue_dmae_with_comp(bp, &dmae);
803 }
804
805 static void bnx2x_vf_mbx_resp(struct bnx2x *bp, struct bnx2x_virtf *vf)
806 {
807         struct bnx2x_vf_mbx *mbx = BP_VF_MBX(bp, vf->index);
808         u64 vf_addr;
809         dma_addr_t pf_addr;
810         u16 length, type;
811         int rc;
812         struct pfvf_general_resp_tlv *resp = &mbx->msg->resp.general_resp;
813
814         /* prepare response */
815         type = mbx->first_tlv.tl.type;
816         length = type == CHANNEL_TLV_ACQUIRE ?
817                 sizeof(struct pfvf_acquire_resp_tlv) :
818                 sizeof(struct pfvf_general_resp_tlv);
819         bnx2x_add_tlv(bp, resp, 0, type, length);
820         resp->hdr.status = bnx2x_pfvf_status_codes(vf->op_rc);
821         bnx2x_add_tlv(bp, resp, length, CHANNEL_TLV_LIST_END,
822                       sizeof(struct channel_list_end_tlv));
823         bnx2x_dp_tlv_list(bp, resp);
824         DP(BNX2X_MSG_IOV, "mailbox vf address hi 0x%x, lo 0x%x, offset 0x%x\n",
825            mbx->vf_addr_hi, mbx->vf_addr_lo, mbx->first_tlv.resp_msg_offset);
826
827         /* send response */
828         vf_addr = HILO_U64(mbx->vf_addr_hi, mbx->vf_addr_lo) +
829                   mbx->first_tlv.resp_msg_offset;
830         pf_addr = mbx->msg_mapping +
831                   offsetof(struct bnx2x_vf_mbx_msg, resp);
832
833         /* copy the response body, if there is one, before the header, as the vf
834          * is sensitive to the header being written
835          */
836         if (resp->hdr.tl.length > sizeof(u64)) {
837                 length = resp->hdr.tl.length - sizeof(u64);
838                 vf_addr += sizeof(u64);
839                 pf_addr += sizeof(u64);
840                 rc = bnx2x_copy32_vf_dmae(bp, false, pf_addr, vf->abs_vfid,
841                                           U64_HI(vf_addr),
842                                           U64_LO(vf_addr),
843                                           length/4);
844                 if (rc) {
845                         BNX2X_ERR("Failed to copy response body to VF %d\n",
846                                   vf->abs_vfid);
847                         goto mbx_error;
848                 }
849                 vf_addr -= sizeof(u64);
850                 pf_addr -= sizeof(u64);
851         }
852
853         /* ack the FW */
854         storm_memset_vf_mbx_ack(bp, vf->abs_vfid);
855         mmiowb();
856
857         /* initiate dmae to send the response */
858         mbx->flags &= ~VF_MSG_INPROCESS;
859
860         /* copy the response header including status-done field,
861          * must be last dmae, must be after FW is acked
862          */
863         rc = bnx2x_copy32_vf_dmae(bp, false, pf_addr, vf->abs_vfid,
864                                   U64_HI(vf_addr),
865                                   U64_LO(vf_addr),
866                                   sizeof(u64)/4);
867
868         /* unlock channel mutex */
869         bnx2x_unlock_vf_pf_channel(bp, vf, mbx->first_tlv.tl.type);
870
871         if (rc) {
872                 BNX2X_ERR("Failed to copy response status to VF %d\n",
873                           vf->abs_vfid);
874                 goto mbx_error;
875         }
876         return;
877
878 mbx_error:
879         bnx2x_vf_release(bp, vf, false); /* non blocking */
880 }
881
882 static void bnx2x_vf_mbx_acquire_resp(struct bnx2x *bp, struct bnx2x_virtf *vf,
883                                       struct bnx2x_vf_mbx *mbx, int vfop_status)
884 {
885         int i;
886         struct pfvf_acquire_resp_tlv *resp = &mbx->msg->resp.acquire_resp;
887         struct pf_vf_resc *resc = &resp->resc;
888         u8 status = bnx2x_pfvf_status_codes(vfop_status);
889
890         memset(resp, 0, sizeof(*resp));
891
892         /* fill in pfdev info */
893         resp->pfdev_info.chip_num = bp->common.chip_id;
894         resp->pfdev_info.db_size = (1 << BNX2X_DB_SHIFT);
895         resp->pfdev_info.indices_per_sb = HC_SB_MAX_INDICES_E2;
896         resp->pfdev_info.pf_cap = (PFVF_CAP_RSS |
897                                    /* PFVF_CAP_DHC |*/ PFVF_CAP_TPA);
898         bnx2x_fill_fw_str(bp, resp->pfdev_info.fw_ver,
899                           sizeof(resp->pfdev_info.fw_ver));
900
901         if (status == PFVF_STATUS_NO_RESOURCE ||
902             status == PFVF_STATUS_SUCCESS) {
903                 /* set resources numbers, if status equals NO_RESOURCE these
904                  * are max possible numbers
905                  */
906                 resc->num_rxqs = vf_rxq_count(vf) ? :
907                         bnx2x_vf_max_queue_cnt(bp, vf);
908                 resc->num_txqs = vf_txq_count(vf) ? :
909                         bnx2x_vf_max_queue_cnt(bp, vf);
910                 resc->num_sbs = vf_sb_count(vf);
911                 resc->num_mac_filters = vf_mac_rules_cnt(vf);
912                 resc->num_vlan_filters = vf_vlan_rules_cnt(vf);
913                 resc->num_mc_filters = 0;
914
915                 if (status == PFVF_STATUS_SUCCESS) {
916                         /* fill in the allocated resources */
917                         struct pf_vf_bulletin_content *bulletin =
918                                 BP_VF_BULLETIN(bp, vf->index);
919
920                         for_each_vfq(vf, i)
921                                 resc->hw_qid[i] =
922                                         vfq_qzone_id(vf, vfq_get(vf, i));
923
924                         for_each_vf_sb(vf, i) {
925                                 resc->hw_sbs[i].hw_sb_id = vf_igu_sb(vf, i);
926                                 resc->hw_sbs[i].sb_qid = vf_hc_qzone(vf, i);
927                         }
928
929                         /* if a mac has been set for this vf, supply it */
930                         if (bulletin->valid_bitmap & 1 << MAC_ADDR_VALID) {
931                                 memcpy(resc->current_mac_addr, bulletin->mac,
932                                        ETH_ALEN);
933                         }
934                 }
935         }
936
937         DP(BNX2X_MSG_IOV, "VF[%d] ACQUIRE_RESPONSE: pfdev_info- chip_num=0x%x, db_size=%d, idx_per_sb=%d, pf_cap=0x%x\n"
938            "resources- n_rxq-%d, n_txq-%d, n_sbs-%d, n_macs-%d, n_vlans-%d, n_mcs-%d, fw_ver: '%s'\n",
939            vf->abs_vfid,
940            resp->pfdev_info.chip_num,
941            resp->pfdev_info.db_size,
942            resp->pfdev_info.indices_per_sb,
943            resp->pfdev_info.pf_cap,
944            resc->num_rxqs,
945            resc->num_txqs,
946            resc->num_sbs,
947            resc->num_mac_filters,
948            resc->num_vlan_filters,
949            resc->num_mc_filters,
950            resp->pfdev_info.fw_ver);
951
952         DP_CONT(BNX2X_MSG_IOV, "hw_qids- [ ");
953         for (i = 0; i < vf_rxq_count(vf); i++)
954                 DP_CONT(BNX2X_MSG_IOV, "%d ", resc->hw_qid[i]);
955         DP_CONT(BNX2X_MSG_IOV, "], sb_info- [ ");
956         for (i = 0; i < vf_sb_count(vf); i++)
957                 DP_CONT(BNX2X_MSG_IOV, "%d:%d ",
958                         resc->hw_sbs[i].hw_sb_id,
959                         resc->hw_sbs[i].sb_qid);
960         DP_CONT(BNX2X_MSG_IOV, "]\n");
961
962         /* send the response */
963         vf->op_rc = vfop_status;
964         bnx2x_vf_mbx_resp(bp, vf);
965 }
966
967 static void bnx2x_vf_mbx_acquire(struct bnx2x *bp, struct bnx2x_virtf *vf,
968                                  struct bnx2x_vf_mbx *mbx)
969 {
970         int rc;
971         struct vfpf_acquire_tlv *acquire = &mbx->msg->req.acquire;
972
973         /* log vfdef info */
974         DP(BNX2X_MSG_IOV,
975            "VF[%d] ACQUIRE: vfdev_info- vf_id %d, vf_os %d resources- n_rxq-%d, n_txq-%d, n_sbs-%d, n_macs-%d, n_vlans-%d, n_mcs-%d\n",
976            vf->abs_vfid, acquire->vfdev_info.vf_id, acquire->vfdev_info.vf_os,
977            acquire->resc_request.num_rxqs, acquire->resc_request.num_txqs,
978            acquire->resc_request.num_sbs, acquire->resc_request.num_mac_filters,
979            acquire->resc_request.num_vlan_filters,
980            acquire->resc_request.num_mc_filters);
981
982         /* acquire the resources */
983         rc = bnx2x_vf_acquire(bp, vf, &acquire->resc_request);
984
985         /* store address of vf's bulletin board */
986         vf->bulletin_map = acquire->bulletin_addr;
987
988         /* response */
989         bnx2x_vf_mbx_acquire_resp(bp, vf, mbx, rc);
990 }
991
992 static void bnx2x_vf_mbx_init_vf(struct bnx2x *bp, struct bnx2x_virtf *vf,
993                               struct bnx2x_vf_mbx *mbx)
994 {
995         struct vfpf_init_tlv *init = &mbx->msg->req.init;
996
997         /* record ghost addresses from vf message */
998         vf->spq_map = init->spq_addr;
999         vf->fw_stat_map = init->stats_addr;
1000         vf->op_rc = bnx2x_vf_init(bp, vf, (dma_addr_t *)init->sb_addr);
1001
1002         /* response */
1003         bnx2x_vf_mbx_resp(bp, vf);
1004 }
1005
1006 /* convert MBX queue-flags to standard SP queue-flags */
1007 static void bnx2x_vf_mbx_set_q_flags(u32 mbx_q_flags,
1008                                      unsigned long *sp_q_flags)
1009 {
1010         if (mbx_q_flags & VFPF_QUEUE_FLG_TPA)
1011                 __set_bit(BNX2X_Q_FLG_TPA, sp_q_flags);
1012         if (mbx_q_flags & VFPF_QUEUE_FLG_TPA_IPV6)
1013                 __set_bit(BNX2X_Q_FLG_TPA_IPV6, sp_q_flags);
1014         if (mbx_q_flags & VFPF_QUEUE_FLG_TPA_GRO)
1015                 __set_bit(BNX2X_Q_FLG_TPA_GRO, sp_q_flags);
1016         if (mbx_q_flags & VFPF_QUEUE_FLG_STATS)
1017                 __set_bit(BNX2X_Q_FLG_STATS, sp_q_flags);
1018         if (mbx_q_flags & VFPF_QUEUE_FLG_OV)
1019                 __set_bit(BNX2X_Q_FLG_OV, sp_q_flags);
1020         if (mbx_q_flags & VFPF_QUEUE_FLG_VLAN)
1021                 __set_bit(BNX2X_Q_FLG_VLAN, sp_q_flags);
1022         if (mbx_q_flags & VFPF_QUEUE_FLG_COS)
1023                 __set_bit(BNX2X_Q_FLG_COS, sp_q_flags);
1024         if (mbx_q_flags & VFPF_QUEUE_FLG_HC)
1025                 __set_bit(BNX2X_Q_FLG_HC, sp_q_flags);
1026         if (mbx_q_flags & VFPF_QUEUE_FLG_DHC)
1027                 __set_bit(BNX2X_Q_FLG_DHC, sp_q_flags);
1028 }
1029
1030 static void bnx2x_vf_mbx_setup_q(struct bnx2x *bp, struct bnx2x_virtf *vf,
1031                                  struct bnx2x_vf_mbx *mbx)
1032 {
1033         struct vfpf_setup_q_tlv *setup_q = &mbx->msg->req.setup_q;
1034         struct bnx2x_vfop_cmd cmd = {
1035                 .done = bnx2x_vf_mbx_resp,
1036                 .block = false,
1037         };
1038
1039         /* verify vf_qid */
1040         if (setup_q->vf_qid >= vf_rxq_count(vf)) {
1041                 BNX2X_ERR("vf_qid %d invalid, max queue count is %d\n",
1042                           setup_q->vf_qid, vf_rxq_count(vf));
1043                 vf->op_rc = -EINVAL;
1044                 goto response;
1045         }
1046
1047         /* tx queues must be setup alongside rx queues thus if the rx queue
1048          * is not marked as valid there's nothing to do.
1049          */
1050         if (setup_q->param_valid & (VFPF_RXQ_VALID|VFPF_TXQ_VALID)) {
1051                 struct bnx2x_vf_queue *q = vfq_get(vf, setup_q->vf_qid);
1052                 unsigned long q_type = 0;
1053
1054                 struct bnx2x_queue_init_params *init_p;
1055                 struct bnx2x_queue_setup_params *setup_p;
1056
1057                 /* reinit the VF operation context */
1058                 memset(&vf->op_params.qctor, 0 , sizeof(vf->op_params.qctor));
1059                 setup_p = &vf->op_params.qctor.prep_qsetup;
1060                 init_p =  &vf->op_params.qctor.qstate.params.init;
1061
1062                 /* activate immediately */
1063                 __set_bit(BNX2X_Q_FLG_ACTIVE, &setup_p->flags);
1064
1065                 if (setup_q->param_valid & VFPF_TXQ_VALID) {
1066                         struct bnx2x_txq_setup_params *txq_params =
1067                                 &setup_p->txq_params;
1068
1069                         __set_bit(BNX2X_Q_TYPE_HAS_TX, &q_type);
1070
1071                         /* save sb resource index */
1072                         q->sb_idx = setup_q->txq.vf_sb;
1073
1074                         /* tx init */
1075                         init_p->tx.hc_rate = setup_q->txq.hc_rate;
1076                         init_p->tx.sb_cq_index = setup_q->txq.sb_index;
1077
1078                         bnx2x_vf_mbx_set_q_flags(setup_q->txq.flags,
1079                                                  &init_p->tx.flags);
1080
1081                         /* tx setup - flags */
1082                         bnx2x_vf_mbx_set_q_flags(setup_q->txq.flags,
1083                                                  &setup_p->flags);
1084
1085                         /* tx setup - general, nothing */
1086
1087                         /* tx setup - tx */
1088                         txq_params->dscr_map = setup_q->txq.txq_addr;
1089                         txq_params->sb_cq_index = setup_q->txq.sb_index;
1090                         txq_params->traffic_type = setup_q->txq.traffic_type;
1091
1092                         bnx2x_vfop_qctor_dump_tx(bp, vf, init_p, setup_p,
1093                                                  q->index, q->sb_idx);
1094                 }
1095
1096                 if (setup_q->param_valid & VFPF_RXQ_VALID) {
1097                         struct bnx2x_rxq_setup_params *rxq_params =
1098                                                         &setup_p->rxq_params;
1099
1100                         __set_bit(BNX2X_Q_TYPE_HAS_RX, &q_type);
1101
1102                         /* Note: there is no support for different SBs
1103                          * for TX and RX
1104                          */
1105                         q->sb_idx = setup_q->rxq.vf_sb;
1106
1107                         /* rx init */
1108                         init_p->rx.hc_rate = setup_q->rxq.hc_rate;
1109                         init_p->rx.sb_cq_index = setup_q->rxq.sb_index;
1110                         bnx2x_vf_mbx_set_q_flags(setup_q->rxq.flags,
1111                                                  &init_p->rx.flags);
1112
1113                         /* rx setup - flags */
1114                         bnx2x_vf_mbx_set_q_flags(setup_q->rxq.flags,
1115                                                  &setup_p->flags);
1116
1117                         /* rx setup - general */
1118                         setup_p->gen_params.mtu = setup_q->rxq.mtu;
1119
1120                         /* rx setup - rx */
1121                         rxq_params->drop_flags = setup_q->rxq.drop_flags;
1122                         rxq_params->dscr_map = setup_q->rxq.rxq_addr;
1123                         rxq_params->sge_map = setup_q->rxq.sge_addr;
1124                         rxq_params->rcq_map = setup_q->rxq.rcq_addr;
1125                         rxq_params->rcq_np_map = setup_q->rxq.rcq_np_addr;
1126                         rxq_params->buf_sz = setup_q->rxq.buf_sz;
1127                         rxq_params->tpa_agg_sz = setup_q->rxq.tpa_agg_sz;
1128                         rxq_params->max_sges_pkt = setup_q->rxq.max_sge_pkt;
1129                         rxq_params->sge_buf_sz = setup_q->rxq.sge_buf_sz;
1130                         rxq_params->cache_line_log =
1131                                 setup_q->rxq.cache_line_log;
1132                         rxq_params->sb_cq_index = setup_q->rxq.sb_index;
1133
1134                         bnx2x_vfop_qctor_dump_rx(bp, vf, init_p, setup_p,
1135                                                  q->index, q->sb_idx);
1136                 }
1137                 /* complete the preparations */
1138                 bnx2x_vfop_qctor_prep(bp, vf, q, &vf->op_params.qctor, q_type);
1139
1140                 vf->op_rc = bnx2x_vfop_qsetup_cmd(bp, vf, &cmd, q->index);
1141                 if (vf->op_rc)
1142                         goto response;
1143                 return;
1144         }
1145 response:
1146         bnx2x_vf_mbx_resp(bp, vf);
1147 }
1148
1149 enum bnx2x_vfop_filters_state {
1150            BNX2X_VFOP_MBX_Q_FILTERS_MACS,
1151            BNX2X_VFOP_MBX_Q_FILTERS_VLANS,
1152            BNX2X_VFOP_MBX_Q_FILTERS_RXMODE,
1153            BNX2X_VFOP_MBX_Q_FILTERS_MCAST,
1154            BNX2X_VFOP_MBX_Q_FILTERS_DONE
1155 };
1156
1157 static int bnx2x_vf_mbx_macvlan_list(struct bnx2x *bp,
1158                                      struct bnx2x_virtf *vf,
1159                                      struct vfpf_set_q_filters_tlv *tlv,
1160                                      struct bnx2x_vfop_filters **pfl,
1161                                      u32 type_flag)
1162 {
1163         int i, j;
1164         struct bnx2x_vfop_filters *fl = NULL;
1165         size_t fsz;
1166
1167         fsz = tlv->n_mac_vlan_filters * sizeof(struct bnx2x_vfop_filter) +
1168                 sizeof(struct bnx2x_vfop_filters);
1169
1170         fl = kzalloc(fsz, GFP_KERNEL);
1171         if (!fl)
1172                 return -ENOMEM;
1173
1174         INIT_LIST_HEAD(&fl->head);
1175
1176         for (i = 0, j = 0; i < tlv->n_mac_vlan_filters; i++) {
1177                 struct vfpf_q_mac_vlan_filter *msg_filter = &tlv->filters[i];
1178
1179                 if ((msg_filter->flags & type_flag) != type_flag)
1180                         continue;
1181                 if (type_flag == VFPF_Q_FILTER_DEST_MAC_VALID) {
1182                         fl->filters[j].mac = msg_filter->mac;
1183                         fl->filters[j].type = BNX2X_VFOP_FILTER_MAC;
1184                 } else {
1185                         fl->filters[j].vid = msg_filter->vlan_tag;
1186                         fl->filters[j].type = BNX2X_VFOP_FILTER_VLAN;
1187                 }
1188                 fl->filters[j].add =
1189                         (msg_filter->flags & VFPF_Q_FILTER_SET_MAC) ?
1190                         true : false;
1191                 list_add_tail(&fl->filters[j++].link, &fl->head);
1192         }
1193         if (list_empty(&fl->head))
1194                 kfree(fl);
1195         else
1196                 *pfl = fl;
1197
1198         return 0;
1199 }
1200
1201 static void bnx2x_vf_mbx_dp_q_filter(struct bnx2x *bp, int msglvl, int idx,
1202                                        struct vfpf_q_mac_vlan_filter *filter)
1203 {
1204         DP(msglvl, "MAC-VLAN[%d] -- flags=0x%x\n", idx, filter->flags);
1205         if (filter->flags & VFPF_Q_FILTER_VLAN_TAG_VALID)
1206                 DP_CONT(msglvl, ", vlan=%d", filter->vlan_tag);
1207         if (filter->flags & VFPF_Q_FILTER_DEST_MAC_VALID)
1208                 DP_CONT(msglvl, ", MAC=%pM", filter->mac);
1209         DP_CONT(msglvl, "\n");
1210 }
1211
1212 static void bnx2x_vf_mbx_dp_q_filters(struct bnx2x *bp, int msglvl,
1213                                        struct vfpf_set_q_filters_tlv *filters)
1214 {
1215         int i;
1216
1217         if (filters->flags & VFPF_SET_Q_FILTERS_MAC_VLAN_CHANGED)
1218                 for (i = 0; i < filters->n_mac_vlan_filters; i++)
1219                         bnx2x_vf_mbx_dp_q_filter(bp, msglvl, i,
1220                                                  &filters->filters[i]);
1221
1222         if (filters->flags & VFPF_SET_Q_FILTERS_RX_MASK_CHANGED)
1223                 DP(msglvl, "RX-MASK=0x%x\n", filters->rx_mask);
1224
1225         if (filters->flags & VFPF_SET_Q_FILTERS_MULTICAST_CHANGED)
1226                 for (i = 0; i < filters->n_multicast; i++)
1227                         DP(msglvl, "MULTICAST=%pM\n", filters->multicast[i]);
1228 }
1229
1230 #define VFPF_MAC_FILTER         VFPF_Q_FILTER_DEST_MAC_VALID
1231 #define VFPF_VLAN_FILTER        VFPF_Q_FILTER_VLAN_TAG_VALID
1232
1233 static void bnx2x_vfop_mbx_qfilters(struct bnx2x *bp, struct bnx2x_virtf *vf)
1234 {
1235         int rc;
1236
1237         struct vfpf_set_q_filters_tlv *msg =
1238                 &BP_VF_MBX(bp, vf->index)->msg->req.set_q_filters;
1239
1240         struct bnx2x_vfop *vfop = bnx2x_vfop_cur(bp, vf);
1241         enum bnx2x_vfop_filters_state state = vfop->state;
1242
1243         struct bnx2x_vfop_cmd cmd = {
1244                 .done = bnx2x_vfop_mbx_qfilters,
1245                 .block = false,
1246         };
1247
1248         DP(BNX2X_MSG_IOV, "STATE: %d\n", state);
1249
1250         if (vfop->rc < 0)
1251                 goto op_err;
1252
1253         switch (state) {
1254         case BNX2X_VFOP_MBX_Q_FILTERS_MACS:
1255                 /* next state */
1256                 vfop->state = BNX2X_VFOP_MBX_Q_FILTERS_VLANS;
1257
1258                 /* check for any vlan/mac changes */
1259                 if (msg->flags & VFPF_SET_Q_FILTERS_MAC_VLAN_CHANGED) {
1260                         /* build mac list */
1261                         struct bnx2x_vfop_filters *fl = NULL;
1262
1263                         vfop->rc = bnx2x_vf_mbx_macvlan_list(bp, vf, msg, &fl,
1264                                                              VFPF_MAC_FILTER);
1265                         if (vfop->rc)
1266                                 goto op_err;
1267
1268                         if (fl) {
1269                                 /* set mac list */
1270                                 rc = bnx2x_vfop_mac_list_cmd(bp, vf, &cmd, fl,
1271                                                              msg->vf_qid,
1272                                                              false);
1273                                 if (rc) {
1274                                         vfop->rc = rc;
1275                                         goto op_err;
1276                                 }
1277                                 return;
1278                         }
1279                 }
1280                 /* fall through */
1281
1282         case BNX2X_VFOP_MBX_Q_FILTERS_VLANS:
1283                 /* next state */
1284                 vfop->state = BNX2X_VFOP_MBX_Q_FILTERS_RXMODE;
1285
1286                 /* check for any vlan/mac changes */
1287                 if (msg->flags & VFPF_SET_Q_FILTERS_MAC_VLAN_CHANGED) {
1288                         /* build vlan list */
1289                         struct bnx2x_vfop_filters *fl = NULL;
1290
1291                         vfop->rc = bnx2x_vf_mbx_macvlan_list(bp, vf, msg, &fl,
1292                                                              VFPF_VLAN_FILTER);
1293                         if (vfop->rc)
1294                                 goto op_err;
1295
1296                         if (fl) {
1297                                 /* set vlan list */
1298                                 rc = bnx2x_vfop_vlan_list_cmd(bp, vf, &cmd, fl,
1299                                                               msg->vf_qid,
1300                                                               false);
1301                                 if (rc) {
1302                                         vfop->rc = rc;
1303                                         goto op_err;
1304                                 }
1305                                 return;
1306                         }
1307                 }
1308                 /* fall through */
1309
1310         case BNX2X_VFOP_MBX_Q_FILTERS_RXMODE:
1311                 /* next state */
1312                 vfop->state = BNX2X_VFOP_MBX_Q_FILTERS_MCAST;
1313
1314                 if (msg->flags & VFPF_SET_Q_FILTERS_RX_MASK_CHANGED) {
1315                         unsigned long accept = 0;
1316
1317                         /* covert VF-PF if mask to bnx2x accept flags */
1318                         if (msg->rx_mask & VFPF_RX_MASK_ACCEPT_MATCHED_UNICAST)
1319                                 __set_bit(BNX2X_ACCEPT_UNICAST, &accept);
1320
1321                         if (msg->rx_mask &
1322                                         VFPF_RX_MASK_ACCEPT_MATCHED_MULTICAST)
1323                                 __set_bit(BNX2X_ACCEPT_MULTICAST, &accept);
1324
1325                         if (msg->rx_mask & VFPF_RX_MASK_ACCEPT_ALL_UNICAST)
1326                                 __set_bit(BNX2X_ACCEPT_ALL_UNICAST, &accept);
1327
1328                         if (msg->rx_mask & VFPF_RX_MASK_ACCEPT_ALL_MULTICAST)
1329                                 __set_bit(BNX2X_ACCEPT_ALL_MULTICAST, &accept);
1330
1331                         if (msg->rx_mask & VFPF_RX_MASK_ACCEPT_BROADCAST)
1332                                 __set_bit(BNX2X_ACCEPT_BROADCAST, &accept);
1333
1334                         /* A packet arriving the vf's mac should be accepted
1335                          * with any vlan
1336                          */
1337                         __set_bit(BNX2X_ACCEPT_ANY_VLAN, &accept);
1338
1339                         /* set rx-mode */
1340                         rc = bnx2x_vfop_rxmode_cmd(bp, vf, &cmd,
1341                                                    msg->vf_qid, accept);
1342                         if (rc) {
1343                                 vfop->rc = rc;
1344                                 goto op_err;
1345                         }
1346                         return;
1347                 }
1348                 /* fall through */
1349
1350         case BNX2X_VFOP_MBX_Q_FILTERS_MCAST:
1351                 /* next state */
1352                 vfop->state = BNX2X_VFOP_MBX_Q_FILTERS_DONE;
1353
1354                 if (msg->flags & VFPF_SET_Q_FILTERS_MULTICAST_CHANGED) {
1355                         /* set mcasts */
1356                         rc = bnx2x_vfop_mcast_cmd(bp, vf, &cmd, msg->multicast,
1357                                                   msg->n_multicast, false);
1358                         if (rc) {
1359                                 vfop->rc = rc;
1360                                 goto op_err;
1361                         }
1362                         return;
1363                 }
1364                 /* fall through */
1365 op_done:
1366         case BNX2X_VFOP_MBX_Q_FILTERS_DONE:
1367                 bnx2x_vfop_end(bp, vf, vfop);
1368                 return;
1369 op_err:
1370         BNX2X_ERR("QFILTERS[%d:%d] error: rc %d\n",
1371                   vf->abs_vfid, msg->vf_qid, vfop->rc);
1372         goto op_done;
1373
1374         default:
1375                 bnx2x_vfop_default(state);
1376         }
1377 }
1378
1379 static int bnx2x_vfop_mbx_qfilters_cmd(struct bnx2x *bp,
1380                                         struct bnx2x_virtf *vf,
1381                                         struct bnx2x_vfop_cmd *cmd)
1382 {
1383         struct bnx2x_vfop *vfop = bnx2x_vfop_add(bp, vf);
1384         if (vfop) {
1385                 bnx2x_vfop_opset(BNX2X_VFOP_MBX_Q_FILTERS_MACS,
1386                                  bnx2x_vfop_mbx_qfilters, cmd->done);
1387                 return bnx2x_vfop_transition(bp, vf, bnx2x_vfop_mbx_qfilters,
1388                                              cmd->block);
1389         }
1390         return -ENOMEM;
1391 }
1392
1393 static void bnx2x_vf_mbx_set_q_filters(struct bnx2x *bp,
1394                                        struct bnx2x_virtf *vf,
1395                                        struct bnx2x_vf_mbx *mbx)
1396 {
1397         struct vfpf_set_q_filters_tlv *filters = &mbx->msg->req.set_q_filters;
1398         struct pf_vf_bulletin_content *bulletin = BP_VF_BULLETIN(bp, vf->index);
1399         struct bnx2x_vfop_cmd cmd = {
1400                 .done = bnx2x_vf_mbx_resp,
1401                 .block = false,
1402         };
1403
1404         /* if a mac was already set for this VF via the set vf mac ndo, we only
1405          * accept mac configurations of that mac. Why accept them at all?
1406          * because PF may have been unable to configure the mac at the time
1407          * since queue was not set up.
1408          */
1409         if (bulletin->valid_bitmap & 1 << MAC_ADDR_VALID) {
1410                 /* once a mac was set by ndo can only accept a single mac... */
1411                 if (filters->n_mac_vlan_filters > 1) {
1412                         BNX2X_ERR("VF[%d] requested the addition of multiple macs after set_vf_mac ndo was called\n",
1413                                   vf->abs_vfid);
1414                         vf->op_rc = -EPERM;
1415                         goto response;
1416                 }
1417
1418                 /* ...and only the mac set by the ndo */
1419                 if (filters->n_mac_vlan_filters == 1 &&
1420                     memcmp(filters->filters->mac, bulletin->mac, ETH_ALEN)) {
1421                         BNX2X_ERR("VF[%d] requested the addition of a mac address not matching the one configured by set_vf_mac ndo\n",
1422                                   vf->abs_vfid);
1423
1424                         vf->op_rc = -EPERM;
1425                         goto response;
1426                 }
1427         }
1428
1429         /* verify vf_qid */
1430         if (filters->vf_qid > vf_rxq_count(vf))
1431                 goto response;
1432
1433         DP(BNX2X_MSG_IOV, "VF[%d] Q_FILTERS: queue[%d]\n",
1434            vf->abs_vfid,
1435            filters->vf_qid);
1436
1437         /* print q_filter message */
1438         bnx2x_vf_mbx_dp_q_filters(bp, BNX2X_MSG_IOV, filters);
1439
1440         vf->op_rc = bnx2x_vfop_mbx_qfilters_cmd(bp, vf, &cmd);
1441         if (vf->op_rc)
1442                 goto response;
1443         return;
1444
1445 response:
1446         bnx2x_vf_mbx_resp(bp, vf);
1447 }
1448
1449 static void bnx2x_vf_mbx_teardown_q(struct bnx2x *bp, struct bnx2x_virtf *vf,
1450                                     struct bnx2x_vf_mbx *mbx)
1451 {
1452         int qid = mbx->msg->req.q_op.vf_qid;
1453         struct bnx2x_vfop_cmd cmd = {
1454                 .done = bnx2x_vf_mbx_resp,
1455                 .block = false,
1456         };
1457
1458         DP(BNX2X_MSG_IOV, "VF[%d] Q_TEARDOWN: vf_qid=%d\n",
1459            vf->abs_vfid, qid);
1460
1461         vf->op_rc = bnx2x_vfop_qdown_cmd(bp, vf, &cmd, qid);
1462         if (vf->op_rc)
1463                 bnx2x_vf_mbx_resp(bp, vf);
1464 }
1465
1466 static void bnx2x_vf_mbx_close_vf(struct bnx2x *bp, struct bnx2x_virtf *vf,
1467                                   struct bnx2x_vf_mbx *mbx)
1468 {
1469         struct bnx2x_vfop_cmd cmd = {
1470                 .done = bnx2x_vf_mbx_resp,
1471                 .block = false,
1472         };
1473
1474         DP(BNX2X_MSG_IOV, "VF[%d] VF_CLOSE\n", vf->abs_vfid);
1475
1476         vf->op_rc = bnx2x_vfop_close_cmd(bp, vf, &cmd);
1477         if (vf->op_rc)
1478                 bnx2x_vf_mbx_resp(bp, vf);
1479 }
1480
1481 static void bnx2x_vf_mbx_release_vf(struct bnx2x *bp, struct bnx2x_virtf *vf,
1482                                     struct bnx2x_vf_mbx *mbx)
1483 {
1484         struct bnx2x_vfop_cmd cmd = {
1485                 .done = bnx2x_vf_mbx_resp,
1486                 .block = false,
1487         };
1488
1489         DP(BNX2X_MSG_IOV, "VF[%d] VF_RELEASE\n", vf->abs_vfid);
1490
1491         vf->op_rc = bnx2x_vfop_release_cmd(bp, vf, &cmd);
1492         if (vf->op_rc)
1493                 bnx2x_vf_mbx_resp(bp, vf);
1494 }
1495
1496 /* dispatch request */
1497 static void bnx2x_vf_mbx_request(struct bnx2x *bp, struct bnx2x_virtf *vf,
1498                                   struct bnx2x_vf_mbx *mbx)
1499 {
1500         int i;
1501
1502         /* check if tlv type is known */
1503         if (bnx2x_tlv_supported(mbx->first_tlv.tl.type)) {
1504                 /* Lock the per vf op mutex and note the locker's identity.
1505                  * The unlock will take place in mbx response.
1506                  */
1507                 bnx2x_lock_vf_pf_channel(bp, vf, mbx->first_tlv.tl.type);
1508
1509                 /* switch on the opcode */
1510                 switch (mbx->first_tlv.tl.type) {
1511                 case CHANNEL_TLV_ACQUIRE:
1512                         bnx2x_vf_mbx_acquire(bp, vf, mbx);
1513                         break;
1514                 case CHANNEL_TLV_INIT:
1515                         bnx2x_vf_mbx_init_vf(bp, vf, mbx);
1516                         break;
1517                 case CHANNEL_TLV_SETUP_Q:
1518                         bnx2x_vf_mbx_setup_q(bp, vf, mbx);
1519                         break;
1520                 case CHANNEL_TLV_SET_Q_FILTERS:
1521                         bnx2x_vf_mbx_set_q_filters(bp, vf, mbx);
1522                         break;
1523                 case CHANNEL_TLV_TEARDOWN_Q:
1524                         bnx2x_vf_mbx_teardown_q(bp, vf, mbx);
1525                         break;
1526                 case CHANNEL_TLV_CLOSE:
1527                         bnx2x_vf_mbx_close_vf(bp, vf, mbx);
1528                         break;
1529                 case CHANNEL_TLV_RELEASE:
1530                         bnx2x_vf_mbx_release_vf(bp, vf, mbx);
1531                         break;
1532                 }
1533
1534         } else {
1535                 /* unknown TLV - this may belong to a VF driver from the future
1536                  * - a version written after this PF driver was written, which
1537                  * supports features unknown as of yet. Too bad since we don't
1538                  * support them. Or this may be because someone wrote a crappy
1539                  * VF driver and is sending garbage over the channel.
1540                  */
1541                 BNX2X_ERR("unknown TLV. type %d length %d. first 20 bytes of mailbox buffer:\n",
1542                           mbx->first_tlv.tl.type, mbx->first_tlv.tl.length);
1543                 for (i = 0; i < 20; i++)
1544                         DP_CONT(BNX2X_MSG_IOV, "%x ",
1545                                 mbx->msg->req.tlv_buf_size.tlv_buffer[i]);
1546
1547                 /* test whether we can respond to the VF (do we have an address
1548                  * for it?)
1549                  */
1550                 if (vf->state == VF_ACQUIRED) {
1551                         /* mbx_resp uses the op_rc of the VF */
1552                         vf->op_rc = PFVF_STATUS_NOT_SUPPORTED;
1553
1554                         /* notify the VF that we do not support this request */
1555                         bnx2x_vf_mbx_resp(bp, vf);
1556                 } else {
1557                         /* can't send a response since this VF is unknown to us
1558                          * just unlock the channel and be done with.
1559                          */
1560                         bnx2x_unlock_vf_pf_channel(bp, vf,
1561                                                    mbx->first_tlv.tl.type);
1562                 }
1563         }
1564 }
1565
1566 /* handle new vf-pf message */
1567 void bnx2x_vf_mbx(struct bnx2x *bp, struct vf_pf_event_data *vfpf_event)
1568 {
1569         struct bnx2x_virtf *vf;
1570         struct bnx2x_vf_mbx *mbx;
1571         u8 vf_idx;
1572         int rc;
1573
1574         DP(BNX2X_MSG_IOV,
1575            "vf pf event received: vfid %d, address_hi %x, address lo %x",
1576            vfpf_event->vf_id, vfpf_event->msg_addr_hi, vfpf_event->msg_addr_lo);
1577         /* Sanity checks consider removing later */
1578
1579         /* check if the vf_id is valid */
1580         if (vfpf_event->vf_id - BP_VFDB(bp)->sriov.first_vf_in_pf >
1581             BNX2X_NR_VIRTFN(bp)) {
1582                 BNX2X_ERR("Illegal vf_id %d max allowed: %d\n",
1583                           vfpf_event->vf_id, BNX2X_NR_VIRTFN(bp));
1584                 goto mbx_done;
1585         }
1586         vf_idx = bnx2x_vf_idx_by_abs_fid(bp, vfpf_event->vf_id);
1587         mbx = BP_VF_MBX(bp, vf_idx);
1588
1589         /* verify an event is not currently being processed -
1590          * debug failsafe only
1591          */
1592         if (mbx->flags & VF_MSG_INPROCESS) {
1593                 BNX2X_ERR("Previous message is still being processed, vf_id %d\n",
1594                           vfpf_event->vf_id);
1595                 goto mbx_done;
1596         }
1597         vf = BP_VF(bp, vf_idx);
1598
1599         /* save the VF message address */
1600         mbx->vf_addr_hi = vfpf_event->msg_addr_hi;
1601         mbx->vf_addr_lo = vfpf_event->msg_addr_lo;
1602         DP(BNX2X_MSG_IOV, "mailbox vf address hi 0x%x, lo 0x%x, offset 0x%x\n",
1603            mbx->vf_addr_hi, mbx->vf_addr_lo, mbx->first_tlv.resp_msg_offset);
1604
1605         /* dmae to get the VF request */
1606         rc = bnx2x_copy32_vf_dmae(bp, true, mbx->msg_mapping, vf->abs_vfid,
1607                                   mbx->vf_addr_hi, mbx->vf_addr_lo,
1608                                   sizeof(union vfpf_tlvs)/4);
1609         if (rc) {
1610                 BNX2X_ERR("Failed to copy request VF %d\n", vf->abs_vfid);
1611                 goto mbx_error;
1612         }
1613
1614         /* process the VF message header */
1615         mbx->first_tlv = mbx->msg->req.first_tlv;
1616
1617         /* dispatch the request (will prepare the response) */
1618         bnx2x_vf_mbx_request(bp, vf, mbx);
1619         goto mbx_done;
1620
1621 mbx_error:
1622         bnx2x_vf_release(bp, vf, false); /* non blocking */
1623 mbx_done:
1624         return;
1625 }
1626
1627 /* propagate local bulletin board to vf */
1628 int bnx2x_post_vf_bulletin(struct bnx2x *bp, int vf)
1629 {
1630         struct pf_vf_bulletin_content *bulletin = BP_VF_BULLETIN(bp, vf);
1631         dma_addr_t pf_addr = BP_VF_BULLETIN_DMA(bp)->mapping +
1632                 vf * BULLETIN_CONTENT_SIZE;
1633         dma_addr_t vf_addr = bnx2x_vf(bp, vf, bulletin_map);
1634         int rc;
1635
1636         /* can only update vf after init took place */
1637         if (bnx2x_vf(bp, vf, state) != VF_ENABLED &&
1638             bnx2x_vf(bp, vf, state) != VF_ACQUIRED)
1639                 return 0;
1640
1641         /* increment bulletin board version and compute crc */
1642         bulletin->version++;
1643         bulletin->length = BULLETIN_CONTENT_SIZE;
1644         bulletin->crc = bnx2x_crc_vf_bulletin(bp, bulletin);
1645
1646         /* propagate bulletin board via dmae to vm memory */
1647         rc = bnx2x_copy32_vf_dmae(bp, false, pf_addr,
1648                                   bnx2x_vf(bp, vf, abs_vfid), U64_HI(vf_addr),
1649                                   U64_LO(vf_addr), bulletin->length / 4);
1650         return rc;
1651 }