bnx2x: Rebrand from 'broadcom' into 'qlogic'
[linux-2.6-microblaze.git] / drivers / net / ethernet / broadcom / bnx2x / bnx2x_vfpf.c
1 /* bnx2x_vfpf.c: QLogic Everest network driver.
2  *
3  * Copyright 2009-2013 Broadcom Corporation
4  * Copyright 2014 QLogic Corporation
5  * All rights reserved
6  *
7  * Unless you and QLogic execute a separate written software license
8  * agreement governing use of this software, this software is licensed to you
9  * under the terms of the GNU General Public License version 2, available
10  * at http://www.gnu.org/licenses/old-licenses/gpl-2.0.html (the "GPL").
11  *
12  * Notwithstanding the above, under no circumstances may you combine this
13  * software in any way with any other QLogic software provided under a
14  * license other than the GPL, without QLogic's express prior written
15  * consent.
16  *
17  * Maintained by: Ariel Elior <ariel.elior@qlogic.com>
18  * Written by: Shmulik Ravid
19  *             Ariel Elior <ariel.elior@qlogic.com>
20  */
21
22 #include "bnx2x.h"
23 #include "bnx2x_cmn.h"
24 #include <linux/crc32.h>
25
26 static int bnx2x_vfpf_teardown_queue(struct bnx2x *bp, int qidx);
27
28 /* place a given tlv on the tlv buffer at a given offset */
29 static void bnx2x_add_tlv(struct bnx2x *bp, void *tlvs_list,
30                           u16 offset, u16 type, u16 length)
31 {
32         struct channel_tlv *tl =
33                 (struct channel_tlv *)(tlvs_list + offset);
34
35         tl->type = type;
36         tl->length = length;
37 }
38
39 /* Clear the mailbox and init the header of the first tlv */
40 static void bnx2x_vfpf_prep(struct bnx2x *bp, struct vfpf_first_tlv *first_tlv,
41                             u16 type, u16 length)
42 {
43         mutex_lock(&bp->vf2pf_mutex);
44
45         DP(BNX2X_MSG_IOV, "preparing to send %d tlv over vf pf channel\n",
46            type);
47
48         /* Clear mailbox */
49         memset(bp->vf2pf_mbox, 0, sizeof(struct bnx2x_vf_mbx_msg));
50
51         /* init type and length */
52         bnx2x_add_tlv(bp, &first_tlv->tl, 0, type, length);
53
54         /* init first tlv header */
55         first_tlv->resp_msg_offset = sizeof(bp->vf2pf_mbox->req);
56 }
57
58 /* releases the mailbox */
59 static void bnx2x_vfpf_finalize(struct bnx2x *bp,
60                                 struct vfpf_first_tlv *first_tlv)
61 {
62         DP(BNX2X_MSG_IOV, "done sending [%d] tlv over vf pf channel\n",
63            first_tlv->tl.type);
64
65         mutex_unlock(&bp->vf2pf_mutex);
66 }
67
68 /* Finds a TLV by type in a TLV buffer; If found, returns pointer to the TLV */
69 static void *bnx2x_search_tlv_list(struct bnx2x *bp, void *tlvs_list,
70                                    enum channel_tlvs req_tlv)
71 {
72         struct channel_tlv *tlv = (struct channel_tlv *)tlvs_list;
73
74         do {
75                 if (tlv->type == req_tlv)
76                         return tlv;
77
78                 if (!tlv->length) {
79                         BNX2X_ERR("Found TLV with length 0\n");
80                         return NULL;
81                 }
82
83                 tlvs_list += tlv->length;
84                 tlv = (struct channel_tlv *)tlvs_list;
85         } while (tlv->type != CHANNEL_TLV_LIST_END);
86
87         DP(BNX2X_MSG_IOV, "TLV list does not contain %d TLV\n", req_tlv);
88
89         return NULL;
90 }
91
92 /* list the types and lengths of the tlvs on the buffer */
93 static void bnx2x_dp_tlv_list(struct bnx2x *bp, void *tlvs_list)
94 {
95         int i = 1;
96         struct channel_tlv *tlv = (struct channel_tlv *)tlvs_list;
97
98         while (tlv->type != CHANNEL_TLV_LIST_END) {
99                 /* output tlv */
100                 DP(BNX2X_MSG_IOV, "TLV number %d: type %d, length %d\n", i,
101                    tlv->type, tlv->length);
102
103                 /* advance to next tlv */
104                 tlvs_list += tlv->length;
105
106                 /* cast general tlv list pointer to channel tlv header*/
107                 tlv = (struct channel_tlv *)tlvs_list;
108
109                 i++;
110
111                 /* break condition for this loop */
112                 if (i > MAX_TLVS_IN_LIST) {
113                         WARN(true, "corrupt tlvs");
114                         return;
115                 }
116         }
117
118         /* output last tlv */
119         DP(BNX2X_MSG_IOV, "TLV number %d: type %d, length %d\n", i,
120            tlv->type, tlv->length);
121 }
122
123 /* test whether we support a tlv type */
124 bool bnx2x_tlv_supported(u16 tlvtype)
125 {
126         return CHANNEL_TLV_NONE < tlvtype && tlvtype < CHANNEL_TLV_MAX;
127 }
128
129 static inline int bnx2x_pfvf_status_codes(int rc)
130 {
131         switch (rc) {
132         case 0:
133                 return PFVF_STATUS_SUCCESS;
134         case -ENOMEM:
135                 return PFVF_STATUS_NO_RESOURCE;
136         default:
137                 return PFVF_STATUS_FAILURE;
138         }
139 }
140
141 static int bnx2x_send_msg2pf(struct bnx2x *bp, u8 *done, dma_addr_t msg_mapping)
142 {
143         struct cstorm_vf_zone_data __iomem *zone_data =
144                 REG_ADDR(bp, PXP_VF_ADDR_CSDM_GLOBAL_START);
145         int tout = 100, interval = 100; /* wait for 10 seconds */
146
147         if (*done) {
148                 BNX2X_ERR("done was non zero before message to pf was sent\n");
149                 WARN_ON(true);
150                 return -EINVAL;
151         }
152
153         /* if PF indicated channel is down avoid sending message. Return success
154          * so calling flow can continue
155          */
156         bnx2x_sample_bulletin(bp);
157         if (bp->old_bulletin.valid_bitmap & 1 << CHANNEL_DOWN) {
158                 DP(BNX2X_MSG_IOV, "detecting channel down. Aborting message\n");
159                 *done = PFVF_STATUS_SUCCESS;
160                 return -EINVAL;
161         }
162
163         /* Write message address */
164         writel(U64_LO(msg_mapping),
165                &zone_data->non_trigger.vf_pf_channel.msg_addr_lo);
166         writel(U64_HI(msg_mapping),
167                &zone_data->non_trigger.vf_pf_channel.msg_addr_hi);
168
169         /* make sure the address is written before FW accesses it */
170         wmb();
171
172         /* Trigger the PF FW */
173         writeb(1, &zone_data->trigger.vf_pf_channel.addr_valid);
174
175         /* Wait for PF to complete */
176         while ((tout >= 0) && (!*done)) {
177                 msleep(interval);
178                 tout -= 1;
179
180                 /* progress indicator - HV can take its own sweet time in
181                  * answering VFs...
182                  */
183                 DP_CONT(BNX2X_MSG_IOV, ".");
184         }
185
186         if (!*done) {
187                 BNX2X_ERR("PF response has timed out\n");
188                 return -EAGAIN;
189         }
190         DP(BNX2X_MSG_SP, "Got a response from PF\n");
191         return 0;
192 }
193
194 static int bnx2x_get_vf_id(struct bnx2x *bp, u32 *vf_id)
195 {
196         u32 me_reg;
197         int tout = 10, interval = 100; /* Wait for 1 sec */
198
199         do {
200                 /* pxp traps vf read of doorbells and returns me reg value */
201                 me_reg = readl(bp->doorbells);
202                 if (GOOD_ME_REG(me_reg))
203                         break;
204
205                 msleep(interval);
206
207                 BNX2X_ERR("Invalid ME register value: 0x%08x\n. Is pf driver up?",
208                           me_reg);
209         } while (tout-- > 0);
210
211         if (!GOOD_ME_REG(me_reg)) {
212                 BNX2X_ERR("Invalid ME register value: 0x%08x\n", me_reg);
213                 return -EINVAL;
214         }
215
216         DP(BNX2X_MSG_IOV, "valid ME register value: 0x%08x\n", me_reg);
217
218         *vf_id = (me_reg & ME_REG_VF_NUM_MASK) >> ME_REG_VF_NUM_SHIFT;
219
220         return 0;
221 }
222
223 int bnx2x_vfpf_acquire(struct bnx2x *bp, u8 tx_count, u8 rx_count)
224 {
225         int rc = 0, attempts = 0;
226         struct vfpf_acquire_tlv *req = &bp->vf2pf_mbox->req.acquire;
227         struct pfvf_acquire_resp_tlv *resp = &bp->vf2pf_mbox->resp.acquire_resp;
228         struct vfpf_port_phys_id_resp_tlv *phys_port_resp;
229         struct vfpf_fp_hsi_resp_tlv *fp_hsi_resp;
230         u32 vf_id;
231         bool resources_acquired = false;
232
233         /* clear mailbox and prep first tlv */
234         bnx2x_vfpf_prep(bp, &req->first_tlv, CHANNEL_TLV_ACQUIRE, sizeof(*req));
235
236         if (bnx2x_get_vf_id(bp, &vf_id)) {
237                 rc = -EAGAIN;
238                 goto out;
239         }
240
241         req->vfdev_info.vf_id = vf_id;
242         req->vfdev_info.vf_os = 0;
243         req->vfdev_info.fp_hsi_ver = ETH_FP_HSI_VERSION;
244
245         req->resc_request.num_rxqs = rx_count;
246         req->resc_request.num_txqs = tx_count;
247         req->resc_request.num_sbs = bp->igu_sb_cnt;
248         req->resc_request.num_mac_filters = VF_ACQUIRE_MAC_FILTERS;
249         req->resc_request.num_mc_filters = VF_ACQUIRE_MC_FILTERS;
250
251         /* pf 2 vf bulletin board address */
252         req->bulletin_addr = bp->pf2vf_bulletin_mapping;
253
254         /* Request physical port identifier */
255         bnx2x_add_tlv(bp, req, req->first_tlv.tl.length,
256                       CHANNEL_TLV_PHYS_PORT_ID, sizeof(struct channel_tlv));
257
258         /* Bulletin support for bulletin board with length > legacy length */
259         req->vfdev_info.caps |= VF_CAP_SUPPORT_EXT_BULLETIN;
260
261         /* add list termination tlv */
262         bnx2x_add_tlv(bp, req,
263                       req->first_tlv.tl.length + sizeof(struct channel_tlv),
264                       CHANNEL_TLV_LIST_END,
265                       sizeof(struct channel_list_end_tlv));
266
267         /* output tlvs list */
268         bnx2x_dp_tlv_list(bp, req);
269
270         while (!resources_acquired) {
271                 DP(BNX2X_MSG_SP, "attempting to acquire resources\n");
272
273                 /* send acquire request */
274                 rc = bnx2x_send_msg2pf(bp,
275                                        &resp->hdr.status,
276                                        bp->vf2pf_mbox_mapping);
277
278                 /* PF timeout */
279                 if (rc)
280                         goto out;
281
282                 /* copy acquire response from buffer to bp */
283                 memcpy(&bp->acquire_resp, resp, sizeof(bp->acquire_resp));
284
285                 attempts++;
286
287                 /* test whether the PF accepted our request. If not, humble
288                  * the request and try again.
289                  */
290                 if (bp->acquire_resp.hdr.status == PFVF_STATUS_SUCCESS) {
291                         DP(BNX2X_MSG_SP, "resources acquired\n");
292                         resources_acquired = true;
293                 } else if (bp->acquire_resp.hdr.status ==
294                            PFVF_STATUS_NO_RESOURCE &&
295                            attempts < VF_ACQUIRE_THRESH) {
296                         DP(BNX2X_MSG_SP,
297                            "PF unwilling to fulfill resource request. Try PF recommended amount\n");
298
299                         /* humble our request */
300                         req->resc_request.num_txqs =
301                                 min(req->resc_request.num_txqs,
302                                     bp->acquire_resp.resc.num_txqs);
303                         req->resc_request.num_rxqs =
304                                 min(req->resc_request.num_rxqs,
305                                     bp->acquire_resp.resc.num_rxqs);
306                         req->resc_request.num_sbs =
307                                 min(req->resc_request.num_sbs,
308                                     bp->acquire_resp.resc.num_sbs);
309                         req->resc_request.num_mac_filters =
310                                 min(req->resc_request.num_mac_filters,
311                                     bp->acquire_resp.resc.num_mac_filters);
312                         req->resc_request.num_vlan_filters =
313                                 min(req->resc_request.num_vlan_filters,
314                                     bp->acquire_resp.resc.num_vlan_filters);
315                         req->resc_request.num_mc_filters =
316                                 min(req->resc_request.num_mc_filters,
317                                     bp->acquire_resp.resc.num_mc_filters);
318
319                         /* Clear response buffer */
320                         memset(&bp->vf2pf_mbox->resp, 0,
321                                sizeof(union pfvf_tlvs));
322                 } else {
323                         /* Determine reason of PF failure of acquire process */
324                         fp_hsi_resp = bnx2x_search_tlv_list(bp, resp,
325                                                             CHANNEL_TLV_FP_HSI_SUPPORT);
326                         if (fp_hsi_resp && !fp_hsi_resp->is_supported)
327                                 BNX2X_ERR("Old hypervisor - doesn't support current fastpath HSI version; Need to downgrade VF driver [or upgrade hypervisor]\n");
328                         else
329                                 BNX2X_ERR("Failed to get the requested amount of resources: %d. Breaking...\n",
330                                           bp->acquire_resp.hdr.status);
331                         rc = -EAGAIN;
332                         goto out;
333                 }
334         }
335
336         /* Retrieve physical port id (if possible) */
337         phys_port_resp = (struct vfpf_port_phys_id_resp_tlv *)
338                          bnx2x_search_tlv_list(bp, resp,
339                                                CHANNEL_TLV_PHYS_PORT_ID);
340         if (phys_port_resp) {
341                 memcpy(bp->phys_port_id, phys_port_resp->id, ETH_ALEN);
342                 bp->flags |= HAS_PHYS_PORT_ID;
343         }
344
345         /* Old Hypevisors might not even support the FP_HSI_SUPPORT TLV.
346          * If that's the case, we need to make certain required FW was
347          * supported by such a hypervisor [i.e., v0-v2].
348          */
349         fp_hsi_resp = bnx2x_search_tlv_list(bp, resp,
350                                             CHANNEL_TLV_FP_HSI_SUPPORT);
351         if (!fp_hsi_resp && (ETH_FP_HSI_VERSION > ETH_FP_HSI_VER_2)) {
352                 BNX2X_ERR("Old hypervisor - need to downgrade VF's driver\n");
353
354                 /* Since acquire succeeded on the PF side, we need to send a
355                  * release message in order to allow future probes.
356                  */
357                 bnx2x_vfpf_finalize(bp, &req->first_tlv);
358                 bnx2x_vfpf_release(bp);
359
360                 rc = -EINVAL;
361                 goto out;
362         }
363
364         /* get HW info */
365         bp->common.chip_id |= (bp->acquire_resp.pfdev_info.chip_num & 0xffff);
366         bp->link_params.chip_id = bp->common.chip_id;
367         bp->db_size = bp->acquire_resp.pfdev_info.db_size;
368         bp->common.int_block = INT_BLOCK_IGU;
369         bp->common.chip_port_mode = CHIP_2_PORT_MODE;
370         bp->igu_dsb_id = -1;
371         bp->mf_ov = 0;
372         bp->mf_mode = 0;
373         bp->common.flash_size = 0;
374         bp->flags |=
375                 NO_WOL_FLAG | NO_ISCSI_OOO_FLAG | NO_ISCSI_FLAG | NO_FCOE_FLAG;
376         bp->igu_sb_cnt = bp->acquire_resp.resc.num_sbs;
377         bp->igu_base_sb = bp->acquire_resp.resc.hw_sbs[0].hw_sb_id;
378         strlcpy(bp->fw_ver, bp->acquire_resp.pfdev_info.fw_ver,
379                 sizeof(bp->fw_ver));
380
381         if (is_valid_ether_addr(bp->acquire_resp.resc.current_mac_addr))
382                 memcpy(bp->dev->dev_addr,
383                        bp->acquire_resp.resc.current_mac_addr,
384                        ETH_ALEN);
385
386 out:
387         bnx2x_vfpf_finalize(bp, &req->first_tlv);
388         return rc;
389 }
390
391 int bnx2x_vfpf_release(struct bnx2x *bp)
392 {
393         struct vfpf_release_tlv *req = &bp->vf2pf_mbox->req.release;
394         struct pfvf_general_resp_tlv *resp = &bp->vf2pf_mbox->resp.general_resp;
395         u32 rc, vf_id;
396
397         /* clear mailbox and prep first tlv */
398         bnx2x_vfpf_prep(bp, &req->first_tlv, CHANNEL_TLV_RELEASE, sizeof(*req));
399
400         if (bnx2x_get_vf_id(bp, &vf_id)) {
401                 rc = -EAGAIN;
402                 goto out;
403         }
404
405         req->vf_id = vf_id;
406
407         /* add list termination tlv */
408         bnx2x_add_tlv(bp, req, req->first_tlv.tl.length, CHANNEL_TLV_LIST_END,
409                       sizeof(struct channel_list_end_tlv));
410
411         /* output tlvs list */
412         bnx2x_dp_tlv_list(bp, req);
413
414         /* send release request */
415         rc = bnx2x_send_msg2pf(bp, &resp->hdr.status, bp->vf2pf_mbox_mapping);
416
417         if (rc)
418                 /* PF timeout */
419                 goto out;
420
421         if (resp->hdr.status == PFVF_STATUS_SUCCESS) {
422                 /* PF released us */
423                 DP(BNX2X_MSG_SP, "vf released\n");
424         } else {
425                 /* PF reports error */
426                 BNX2X_ERR("PF failed our release request - are we out of sync? Response status: %d\n",
427                           resp->hdr.status);
428                 rc = -EAGAIN;
429                 goto out;
430         }
431 out:
432         bnx2x_vfpf_finalize(bp, &req->first_tlv);
433
434         return rc;
435 }
436
437 /* Tell PF about SB addresses */
438 int bnx2x_vfpf_init(struct bnx2x *bp)
439 {
440         struct vfpf_init_tlv *req = &bp->vf2pf_mbox->req.init;
441         struct pfvf_general_resp_tlv *resp = &bp->vf2pf_mbox->resp.general_resp;
442         int rc, i;
443
444         /* clear mailbox and prep first tlv */
445         bnx2x_vfpf_prep(bp, &req->first_tlv, CHANNEL_TLV_INIT, sizeof(*req));
446
447         /* status blocks */
448         for_each_eth_queue(bp, i)
449                 req->sb_addr[i] = (dma_addr_t)bnx2x_fp(bp, i,
450                                                        status_blk_mapping);
451
452         /* statistics - requests only supports single queue for now */
453         req->stats_addr = bp->fw_stats_data_mapping +
454                           offsetof(struct bnx2x_fw_stats_data, queue_stats);
455
456         req->stats_stride = sizeof(struct per_queue_stats);
457
458         /* add list termination tlv */
459         bnx2x_add_tlv(bp, req, req->first_tlv.tl.length, CHANNEL_TLV_LIST_END,
460                       sizeof(struct channel_list_end_tlv));
461
462         /* output tlvs list */
463         bnx2x_dp_tlv_list(bp, req);
464
465         rc = bnx2x_send_msg2pf(bp, &resp->hdr.status, bp->vf2pf_mbox_mapping);
466         if (rc)
467                 goto out;
468
469         if (resp->hdr.status != PFVF_STATUS_SUCCESS) {
470                 BNX2X_ERR("INIT VF failed: %d. Breaking...\n",
471                           resp->hdr.status);
472                 rc = -EAGAIN;
473                 goto out;
474         }
475
476         DP(BNX2X_MSG_SP, "INIT VF Succeeded\n");
477 out:
478         bnx2x_vfpf_finalize(bp, &req->first_tlv);
479
480         return rc;
481 }
482
483 /* CLOSE VF - opposite to INIT_VF */
484 void bnx2x_vfpf_close_vf(struct bnx2x *bp)
485 {
486         struct vfpf_close_tlv *req = &bp->vf2pf_mbox->req.close;
487         struct pfvf_general_resp_tlv *resp = &bp->vf2pf_mbox->resp.general_resp;
488         int i, rc;
489         u32 vf_id;
490
491         /* If we haven't got a valid VF id, there is no sense to
492          * continue with sending messages
493          */
494         if (bnx2x_get_vf_id(bp, &vf_id))
495                 goto free_irq;
496
497         /* Close the queues */
498         for_each_queue(bp, i)
499                 bnx2x_vfpf_teardown_queue(bp, i);
500
501         /* remove mac */
502         bnx2x_vfpf_config_mac(bp, bp->dev->dev_addr, bp->fp->index, false);
503
504         /* clear mailbox and prep first tlv */
505         bnx2x_vfpf_prep(bp, &req->first_tlv, CHANNEL_TLV_CLOSE, sizeof(*req));
506
507         req->vf_id = vf_id;
508
509         /* add list termination tlv */
510         bnx2x_add_tlv(bp, req, req->first_tlv.tl.length, CHANNEL_TLV_LIST_END,
511                       sizeof(struct channel_list_end_tlv));
512
513         /* output tlvs list */
514         bnx2x_dp_tlv_list(bp, req);
515
516         rc = bnx2x_send_msg2pf(bp, &resp->hdr.status, bp->vf2pf_mbox_mapping);
517
518         if (rc)
519                 BNX2X_ERR("Sending CLOSE failed. rc was: %d\n", rc);
520
521         else if (resp->hdr.status != PFVF_STATUS_SUCCESS)
522                 BNX2X_ERR("Sending CLOSE failed: pf response was %d\n",
523                           resp->hdr.status);
524
525         bnx2x_vfpf_finalize(bp, &req->first_tlv);
526
527 free_irq:
528         /* Disable HW interrupts, NAPI */
529         bnx2x_netif_stop(bp, 0);
530         /* Delete all NAPI objects */
531         bnx2x_del_all_napi(bp);
532
533         /* Release IRQs */
534         bnx2x_free_irq(bp);
535 }
536
537 static void bnx2x_leading_vfq_init(struct bnx2x *bp, struct bnx2x_virtf *vf,
538                                    struct bnx2x_vf_queue *q)
539 {
540         u8 cl_id = vfq_cl_id(vf, q);
541         u8 func_id = FW_VF_HANDLE(vf->abs_vfid);
542
543         /* mac */
544         bnx2x_init_mac_obj(bp, &q->mac_obj,
545                            cl_id, q->cid, func_id,
546                            bnx2x_vf_sp(bp, vf, mac_rdata),
547                            bnx2x_vf_sp_map(bp, vf, mac_rdata),
548                            BNX2X_FILTER_MAC_PENDING,
549                            &vf->filter_state,
550                            BNX2X_OBJ_TYPE_RX_TX,
551                            &bp->macs_pool);
552         /* vlan */
553         bnx2x_init_vlan_obj(bp, &q->vlan_obj,
554                             cl_id, q->cid, func_id,
555                             bnx2x_vf_sp(bp, vf, vlan_rdata),
556                             bnx2x_vf_sp_map(bp, vf, vlan_rdata),
557                             BNX2X_FILTER_VLAN_PENDING,
558                             &vf->filter_state,
559                             BNX2X_OBJ_TYPE_RX_TX,
560                             &bp->vlans_pool);
561
562         /* mcast */
563         bnx2x_init_mcast_obj(bp, &vf->mcast_obj, cl_id,
564                              q->cid, func_id, func_id,
565                              bnx2x_vf_sp(bp, vf, mcast_rdata),
566                              bnx2x_vf_sp_map(bp, vf, mcast_rdata),
567                              BNX2X_FILTER_MCAST_PENDING,
568                              &vf->filter_state,
569                              BNX2X_OBJ_TYPE_RX_TX);
570
571         /* rss */
572         bnx2x_init_rss_config_obj(bp, &vf->rss_conf_obj, cl_id, q->cid,
573                                   func_id, func_id,
574                                   bnx2x_vf_sp(bp, vf, rss_rdata),
575                                   bnx2x_vf_sp_map(bp, vf, rss_rdata),
576                                   BNX2X_FILTER_RSS_CONF_PENDING,
577                                   &vf->filter_state,
578                                   BNX2X_OBJ_TYPE_RX_TX);
579
580         vf->leading_rss = cl_id;
581         q->is_leading = true;
582         q->sp_initialized = true;
583 }
584
585 /* ask the pf to open a queue for the vf */
586 int bnx2x_vfpf_setup_q(struct bnx2x *bp, struct bnx2x_fastpath *fp,
587                        bool is_leading)
588 {
589         struct vfpf_setup_q_tlv *req = &bp->vf2pf_mbox->req.setup_q;
590         struct pfvf_general_resp_tlv *resp = &bp->vf2pf_mbox->resp.general_resp;
591         u8 fp_idx = fp->index;
592         u16 tpa_agg_size = 0, flags = 0;
593         int rc;
594
595         /* clear mailbox and prep first tlv */
596         bnx2x_vfpf_prep(bp, &req->first_tlv, CHANNEL_TLV_SETUP_Q, sizeof(*req));
597
598         /* select tpa mode to request */
599         if (fp->mode != TPA_MODE_DISABLED) {
600                 flags |= VFPF_QUEUE_FLG_TPA;
601                 flags |= VFPF_QUEUE_FLG_TPA_IPV6;
602                 if (fp->mode == TPA_MODE_GRO)
603                         flags |= VFPF_QUEUE_FLG_TPA_GRO;
604                 tpa_agg_size = TPA_AGG_SIZE;
605         }
606
607         if (is_leading)
608                 flags |= VFPF_QUEUE_FLG_LEADING_RSS;
609
610         /* calculate queue flags */
611         flags |= VFPF_QUEUE_FLG_STATS;
612         flags |= VFPF_QUEUE_FLG_CACHE_ALIGN;
613         flags |= VFPF_QUEUE_FLG_VLAN;
614
615         /* Common */
616         req->vf_qid = fp_idx;
617         req->param_valid = VFPF_RXQ_VALID | VFPF_TXQ_VALID;
618
619         /* Rx */
620         req->rxq.rcq_addr = fp->rx_comp_mapping;
621         req->rxq.rcq_np_addr = fp->rx_comp_mapping + BCM_PAGE_SIZE;
622         req->rxq.rxq_addr = fp->rx_desc_mapping;
623         req->rxq.sge_addr = fp->rx_sge_mapping;
624         req->rxq.vf_sb = fp_idx;
625         req->rxq.sb_index = HC_INDEX_ETH_RX_CQ_CONS;
626         req->rxq.hc_rate = bp->rx_ticks ? 1000000/bp->rx_ticks : 0;
627         req->rxq.mtu = bp->dev->mtu;
628         req->rxq.buf_sz = fp->rx_buf_size;
629         req->rxq.sge_buf_sz = BCM_PAGE_SIZE * PAGES_PER_SGE;
630         req->rxq.tpa_agg_sz = tpa_agg_size;
631         req->rxq.max_sge_pkt = SGE_PAGE_ALIGN(bp->dev->mtu) >> SGE_PAGE_SHIFT;
632         req->rxq.max_sge_pkt = ((req->rxq.max_sge_pkt + PAGES_PER_SGE - 1) &
633                           (~(PAGES_PER_SGE-1))) >> PAGES_PER_SGE_SHIFT;
634         req->rxq.flags = flags;
635         req->rxq.drop_flags = 0;
636         req->rxq.cache_line_log = BNX2X_RX_ALIGN_SHIFT;
637         req->rxq.stat_id = -1; /* No stats at the moment */
638
639         /* Tx */
640         req->txq.txq_addr = fp->txdata_ptr[FIRST_TX_COS_INDEX]->tx_desc_mapping;
641         req->txq.vf_sb = fp_idx;
642         req->txq.sb_index = HC_INDEX_ETH_TX_CQ_CONS_COS0;
643         req->txq.hc_rate = bp->tx_ticks ? 1000000/bp->tx_ticks : 0;
644         req->txq.flags = flags;
645         req->txq.traffic_type = LLFC_TRAFFIC_TYPE_NW;
646
647         /* add list termination tlv */
648         bnx2x_add_tlv(bp, req, req->first_tlv.tl.length, CHANNEL_TLV_LIST_END,
649                       sizeof(struct channel_list_end_tlv));
650
651         /* output tlvs list */
652         bnx2x_dp_tlv_list(bp, req);
653
654         rc = bnx2x_send_msg2pf(bp, &resp->hdr.status, bp->vf2pf_mbox_mapping);
655         if (rc)
656                 BNX2X_ERR("Sending SETUP_Q message for queue[%d] failed!\n",
657                           fp_idx);
658
659         if (resp->hdr.status != PFVF_STATUS_SUCCESS) {
660                 BNX2X_ERR("Status of SETUP_Q for queue[%d] is %d\n",
661                           fp_idx, resp->hdr.status);
662                 rc = -EINVAL;
663         }
664
665         bnx2x_vfpf_finalize(bp, &req->first_tlv);
666
667         return rc;
668 }
669
670 static int bnx2x_vfpf_teardown_queue(struct bnx2x *bp, int qidx)
671 {
672         struct vfpf_q_op_tlv *req = &bp->vf2pf_mbox->req.q_op;
673         struct pfvf_general_resp_tlv *resp = &bp->vf2pf_mbox->resp.general_resp;
674         int rc;
675
676         /* clear mailbox and prep first tlv */
677         bnx2x_vfpf_prep(bp, &req->first_tlv, CHANNEL_TLV_TEARDOWN_Q,
678                         sizeof(*req));
679
680         req->vf_qid = qidx;
681
682         /* add list termination tlv */
683         bnx2x_add_tlv(bp, req, req->first_tlv.tl.length, CHANNEL_TLV_LIST_END,
684                       sizeof(struct channel_list_end_tlv));
685
686         /* output tlvs list */
687         bnx2x_dp_tlv_list(bp, req);
688
689         rc = bnx2x_send_msg2pf(bp, &resp->hdr.status, bp->vf2pf_mbox_mapping);
690
691         if (rc) {
692                 BNX2X_ERR("Sending TEARDOWN for queue %d failed: %d\n", qidx,
693                           rc);
694                 goto out;
695         }
696
697         /* PF failed the transaction */
698         if (resp->hdr.status != PFVF_STATUS_SUCCESS) {
699                 BNX2X_ERR("TEARDOWN for queue %d failed: %d\n", qidx,
700                           resp->hdr.status);
701                 rc = -EINVAL;
702         }
703
704 out:
705         bnx2x_vfpf_finalize(bp, &req->first_tlv);
706
707         return rc;
708 }
709
710 /* request pf to add a mac for the vf */
711 int bnx2x_vfpf_config_mac(struct bnx2x *bp, u8 *addr, u8 vf_qid, bool set)
712 {
713         struct vfpf_set_q_filters_tlv *req = &bp->vf2pf_mbox->req.set_q_filters;
714         struct pfvf_general_resp_tlv *resp = &bp->vf2pf_mbox->resp.general_resp;
715         struct pf_vf_bulletin_content bulletin = bp->pf2vf_bulletin->content;
716         int rc = 0;
717
718         /* clear mailbox and prep first tlv */
719         bnx2x_vfpf_prep(bp, &req->first_tlv, CHANNEL_TLV_SET_Q_FILTERS,
720                         sizeof(*req));
721
722         req->flags = VFPF_SET_Q_FILTERS_MAC_VLAN_CHANGED;
723         req->vf_qid = vf_qid;
724         req->n_mac_vlan_filters = 1;
725
726         req->filters[0].flags = VFPF_Q_FILTER_DEST_MAC_VALID;
727         if (set)
728                 req->filters[0].flags |= VFPF_Q_FILTER_SET_MAC;
729
730         /* sample bulletin board for new mac */
731         bnx2x_sample_bulletin(bp);
732
733         /* copy mac from device to request */
734         memcpy(req->filters[0].mac, addr, ETH_ALEN);
735
736         /* add list termination tlv */
737         bnx2x_add_tlv(bp, req, req->first_tlv.tl.length, CHANNEL_TLV_LIST_END,
738                       sizeof(struct channel_list_end_tlv));
739
740         /* output tlvs list */
741         bnx2x_dp_tlv_list(bp, req);
742
743         /* send message to pf */
744         rc = bnx2x_send_msg2pf(bp, &resp->hdr.status, bp->vf2pf_mbox_mapping);
745         if (rc) {
746                 BNX2X_ERR("failed to send message to pf. rc was %d\n", rc);
747                 goto out;
748         }
749
750         /* failure may mean PF was configured with a new mac for us */
751         while (resp->hdr.status == PFVF_STATUS_FAILURE) {
752                 DP(BNX2X_MSG_IOV,
753                    "vfpf SET MAC failed. Check bulletin board for new posts\n");
754
755                 /* copy mac from bulletin to device */
756                 memcpy(bp->dev->dev_addr, bulletin.mac, ETH_ALEN);
757
758                 /* check if bulletin board was updated */
759                 if (bnx2x_sample_bulletin(bp) == PFVF_BULLETIN_UPDATED) {
760                         /* copy mac from device to request */
761                         memcpy(req->filters[0].mac, bp->dev->dev_addr,
762                                ETH_ALEN);
763
764                         /* send message to pf */
765                         rc = bnx2x_send_msg2pf(bp, &resp->hdr.status,
766                                                bp->vf2pf_mbox_mapping);
767                 } else {
768                         /* no new info in bulletin */
769                         break;
770                 }
771         }
772
773         if (resp->hdr.status != PFVF_STATUS_SUCCESS) {
774                 BNX2X_ERR("vfpf SET MAC failed: %d\n", resp->hdr.status);
775                 rc = -EINVAL;
776         }
777 out:
778         bnx2x_vfpf_finalize(bp, &req->first_tlv);
779
780         return rc;
781 }
782
783 /* request pf to config rss table for vf queues*/
784 int bnx2x_vfpf_config_rss(struct bnx2x *bp,
785                           struct bnx2x_config_rss_params *params)
786 {
787         struct pfvf_general_resp_tlv *resp = &bp->vf2pf_mbox->resp.general_resp;
788         struct vfpf_rss_tlv *req = &bp->vf2pf_mbox->req.update_rss;
789         int rc = 0;
790
791         /* clear mailbox and prep first tlv */
792         bnx2x_vfpf_prep(bp, &req->first_tlv, CHANNEL_TLV_UPDATE_RSS,
793                         sizeof(*req));
794
795         /* add list termination tlv */
796         bnx2x_add_tlv(bp, req, req->first_tlv.tl.length, CHANNEL_TLV_LIST_END,
797                       sizeof(struct channel_list_end_tlv));
798
799         memcpy(req->ind_table, params->ind_table, T_ETH_INDIRECTION_TABLE_SIZE);
800         memcpy(req->rss_key, params->rss_key, sizeof(params->rss_key));
801         req->ind_table_size = T_ETH_INDIRECTION_TABLE_SIZE;
802         req->rss_key_size = T_ETH_RSS_KEY;
803         req->rss_result_mask = params->rss_result_mask;
804
805         /* flags handled individually for backward/forward compatibility */
806         if (params->rss_flags & (1 << BNX2X_RSS_MODE_DISABLED))
807                 req->rss_flags |= VFPF_RSS_MODE_DISABLED;
808         if (params->rss_flags & (1 << BNX2X_RSS_MODE_REGULAR))
809                 req->rss_flags |= VFPF_RSS_MODE_REGULAR;
810         if (params->rss_flags & (1 << BNX2X_RSS_SET_SRCH))
811                 req->rss_flags |= VFPF_RSS_SET_SRCH;
812         if (params->rss_flags & (1 << BNX2X_RSS_IPV4))
813                 req->rss_flags |= VFPF_RSS_IPV4;
814         if (params->rss_flags & (1 << BNX2X_RSS_IPV4_TCP))
815                 req->rss_flags |= VFPF_RSS_IPV4_TCP;
816         if (params->rss_flags & (1 << BNX2X_RSS_IPV4_UDP))
817                 req->rss_flags |= VFPF_RSS_IPV4_UDP;
818         if (params->rss_flags & (1 << BNX2X_RSS_IPV6))
819                 req->rss_flags |= VFPF_RSS_IPV6;
820         if (params->rss_flags & (1 << BNX2X_RSS_IPV6_TCP))
821                 req->rss_flags |= VFPF_RSS_IPV6_TCP;
822         if (params->rss_flags & (1 << BNX2X_RSS_IPV6_UDP))
823                 req->rss_flags |= VFPF_RSS_IPV6_UDP;
824
825         DP(BNX2X_MSG_IOV, "rss flags %x\n", req->rss_flags);
826
827         /* output tlvs list */
828         bnx2x_dp_tlv_list(bp, req);
829
830         /* send message to pf */
831         rc = bnx2x_send_msg2pf(bp, &resp->hdr.status, bp->vf2pf_mbox_mapping);
832         if (rc) {
833                 BNX2X_ERR("failed to send message to pf. rc was %d\n", rc);
834                 goto out;
835         }
836
837         if (resp->hdr.status != PFVF_STATUS_SUCCESS) {
838                 /* Since older drivers don't support this feature (and VF has
839                  * no way of knowing other than failing this), don't propagate
840                  * an error in this case.
841                  */
842                 DP(BNX2X_MSG_IOV,
843                    "Failed to send rss message to PF over VF-PF channel [%d]\n",
844                    resp->hdr.status);
845         }
846 out:
847         bnx2x_vfpf_finalize(bp, &req->first_tlv);
848
849         return rc;
850 }
851
852 int bnx2x_vfpf_set_mcast(struct net_device *dev)
853 {
854         struct bnx2x *bp = netdev_priv(dev);
855         struct vfpf_set_q_filters_tlv *req = &bp->vf2pf_mbox->req.set_q_filters;
856         struct pfvf_general_resp_tlv *resp = &bp->vf2pf_mbox->resp.general_resp;
857         int rc, i = 0;
858         struct netdev_hw_addr *ha;
859
860         if (bp->state != BNX2X_STATE_OPEN) {
861                 DP(NETIF_MSG_IFUP, "state is %x, returning\n", bp->state);
862                 return -EINVAL;
863         }
864
865         /* clear mailbox and prep first tlv */
866         bnx2x_vfpf_prep(bp, &req->first_tlv, CHANNEL_TLV_SET_Q_FILTERS,
867                         sizeof(*req));
868
869         /* Get Rx mode requested */
870         DP(NETIF_MSG_IFUP, "dev->flags = %x\n", dev->flags);
871
872         netdev_for_each_mc_addr(ha, dev) {
873                 DP(NETIF_MSG_IFUP, "Adding mcast MAC: %pM\n",
874                    bnx2x_mc_addr(ha));
875                 memcpy(req->multicast[i], bnx2x_mc_addr(ha), ETH_ALEN);
876                 i++;
877         }
878
879         /* We support four PFVF_MAX_MULTICAST_PER_VF mcast
880           * addresses tops
881           */
882         if (i >= PFVF_MAX_MULTICAST_PER_VF) {
883                 DP(NETIF_MSG_IFUP,
884                    "VF supports not more than %d multicast MAC addresses\n",
885                    PFVF_MAX_MULTICAST_PER_VF);
886                 return -EINVAL;
887         }
888
889         req->n_multicast = i;
890         req->flags |= VFPF_SET_Q_FILTERS_MULTICAST_CHANGED;
891         req->vf_qid = 0;
892
893         /* add list termination tlv */
894         bnx2x_add_tlv(bp, req, req->first_tlv.tl.length, CHANNEL_TLV_LIST_END,
895                       sizeof(struct channel_list_end_tlv));
896
897         /* output tlvs list */
898         bnx2x_dp_tlv_list(bp, req);
899         rc = bnx2x_send_msg2pf(bp, &resp->hdr.status, bp->vf2pf_mbox_mapping);
900         if (rc) {
901                 BNX2X_ERR("Sending a message failed: %d\n", rc);
902                 goto out;
903         }
904
905         if (resp->hdr.status != PFVF_STATUS_SUCCESS) {
906                 BNX2X_ERR("Set Rx mode/multicast failed: %d\n",
907                           resp->hdr.status);
908                 rc = -EINVAL;
909         }
910 out:
911         bnx2x_vfpf_finalize(bp, &req->first_tlv);
912
913         return 0;
914 }
915
916 int bnx2x_vfpf_storm_rx_mode(struct bnx2x *bp)
917 {
918         int mode = bp->rx_mode;
919         struct vfpf_set_q_filters_tlv *req = &bp->vf2pf_mbox->req.set_q_filters;
920         struct pfvf_general_resp_tlv *resp = &bp->vf2pf_mbox->resp.general_resp;
921         int rc;
922
923         /* clear mailbox and prep first tlv */
924         bnx2x_vfpf_prep(bp, &req->first_tlv, CHANNEL_TLV_SET_Q_FILTERS,
925                         sizeof(*req));
926
927         DP(NETIF_MSG_IFUP, "Rx mode is %d\n", mode);
928
929         /* Ignore everything accept MODE_NONE */
930         if (mode  == BNX2X_RX_MODE_NONE) {
931                 req->rx_mask = VFPF_RX_MASK_ACCEPT_NONE;
932         } else {
933                 /* Current PF driver will not look at the specific flags,
934                  * but they are required when working with older drivers on hv.
935                  */
936                 req->rx_mask = VFPF_RX_MASK_ACCEPT_MATCHED_MULTICAST;
937                 req->rx_mask |= VFPF_RX_MASK_ACCEPT_MATCHED_UNICAST;
938                 req->rx_mask |= VFPF_RX_MASK_ACCEPT_BROADCAST;
939         }
940
941         req->flags |= VFPF_SET_Q_FILTERS_RX_MASK_CHANGED;
942         req->vf_qid = 0;
943
944         /* add list termination tlv */
945         bnx2x_add_tlv(bp, req, req->first_tlv.tl.length, CHANNEL_TLV_LIST_END,
946                       sizeof(struct channel_list_end_tlv));
947
948         /* output tlvs list */
949         bnx2x_dp_tlv_list(bp, req);
950
951         rc = bnx2x_send_msg2pf(bp, &resp->hdr.status, bp->vf2pf_mbox_mapping);
952         if (rc)
953                 BNX2X_ERR("Sending a message failed: %d\n", rc);
954
955         if (resp->hdr.status != PFVF_STATUS_SUCCESS) {
956                 BNX2X_ERR("Set Rx mode failed: %d\n", resp->hdr.status);
957                 rc = -EINVAL;
958         }
959
960         bnx2x_vfpf_finalize(bp, &req->first_tlv);
961
962         return rc;
963 }
964
965 /* General service functions */
966 static void storm_memset_vf_mbx_ack(struct bnx2x *bp, u16 abs_fid)
967 {
968         u32 addr = BAR_CSTRORM_INTMEM +
969                    CSTORM_VF_PF_CHANNEL_STATE_OFFSET(abs_fid);
970
971         REG_WR8(bp, addr, VF_PF_CHANNEL_STATE_READY);
972 }
973
974 static void storm_memset_vf_mbx_valid(struct bnx2x *bp, u16 abs_fid)
975 {
976         u32 addr = BAR_CSTRORM_INTMEM +
977                    CSTORM_VF_PF_CHANNEL_VALID_OFFSET(abs_fid);
978
979         REG_WR8(bp, addr, 1);
980 }
981
982 /* enable vf_pf mailbox (aka vf-pf-channel) */
983 void bnx2x_vf_enable_mbx(struct bnx2x *bp, u8 abs_vfid)
984 {
985         bnx2x_vf_flr_clnup_epilog(bp, abs_vfid);
986
987         /* enable the mailbox in the FW */
988         storm_memset_vf_mbx_ack(bp, abs_vfid);
989         storm_memset_vf_mbx_valid(bp, abs_vfid);
990
991         /* enable the VF access to the mailbox */
992         bnx2x_vf_enable_access(bp, abs_vfid);
993 }
994
995 /* this works only on !E1h */
996 static int bnx2x_copy32_vf_dmae(struct bnx2x *bp, u8 from_vf,
997                                 dma_addr_t pf_addr, u8 vfid, u32 vf_addr_hi,
998                                 u32 vf_addr_lo, u32 len32)
999 {
1000         struct dmae_command dmae;
1001
1002         if (CHIP_IS_E1x(bp)) {
1003                 BNX2X_ERR("Chip revision does not support VFs\n");
1004                 return DMAE_NOT_RDY;
1005         }
1006
1007         if (!bp->dmae_ready) {
1008                 BNX2X_ERR("DMAE is not ready, can not copy\n");
1009                 return DMAE_NOT_RDY;
1010         }
1011
1012         /* set opcode and fixed command fields */
1013         bnx2x_prep_dmae_with_comp(bp, &dmae, DMAE_SRC_PCI, DMAE_DST_PCI);
1014
1015         if (from_vf) {
1016                 dmae.opcode_iov = (vfid << DMAE_COMMAND_SRC_VFID_SHIFT) |
1017                         (DMAE_SRC_VF << DMAE_COMMAND_SRC_VFPF_SHIFT) |
1018                         (DMAE_DST_PF << DMAE_COMMAND_DST_VFPF_SHIFT);
1019
1020                 dmae.opcode |= (DMAE_C_DST << DMAE_COMMAND_C_FUNC_SHIFT);
1021
1022                 dmae.src_addr_lo = vf_addr_lo;
1023                 dmae.src_addr_hi = vf_addr_hi;
1024                 dmae.dst_addr_lo = U64_LO(pf_addr);
1025                 dmae.dst_addr_hi = U64_HI(pf_addr);
1026         } else {
1027                 dmae.opcode_iov = (vfid << DMAE_COMMAND_DST_VFID_SHIFT) |
1028                         (DMAE_DST_VF << DMAE_COMMAND_DST_VFPF_SHIFT) |
1029                         (DMAE_SRC_PF << DMAE_COMMAND_SRC_VFPF_SHIFT);
1030
1031                 dmae.opcode |= (DMAE_C_SRC << DMAE_COMMAND_C_FUNC_SHIFT);
1032
1033                 dmae.src_addr_lo = U64_LO(pf_addr);
1034                 dmae.src_addr_hi = U64_HI(pf_addr);
1035                 dmae.dst_addr_lo = vf_addr_lo;
1036                 dmae.dst_addr_hi = vf_addr_hi;
1037         }
1038         dmae.len = len32;
1039
1040         /* issue the command and wait for completion */
1041         return bnx2x_issue_dmae_with_comp(bp, &dmae, bnx2x_sp(bp, wb_comp));
1042 }
1043
1044 static void bnx2x_vf_mbx_resp_single_tlv(struct bnx2x *bp,
1045                                          struct bnx2x_virtf *vf)
1046 {
1047         struct bnx2x_vf_mbx *mbx = BP_VF_MBX(bp, vf->index);
1048         u16 length, type;
1049
1050         /* prepare response */
1051         type = mbx->first_tlv.tl.type;
1052         length = type == CHANNEL_TLV_ACQUIRE ?
1053                 sizeof(struct pfvf_acquire_resp_tlv) :
1054                 sizeof(struct pfvf_general_resp_tlv);
1055         bnx2x_add_tlv(bp, &mbx->msg->resp, 0, type, length);
1056         bnx2x_add_tlv(bp, &mbx->msg->resp, length, CHANNEL_TLV_LIST_END,
1057                       sizeof(struct channel_list_end_tlv));
1058 }
1059
1060 static void bnx2x_vf_mbx_resp_send_msg(struct bnx2x *bp,
1061                                        struct bnx2x_virtf *vf,
1062                                        int vf_rc)
1063 {
1064         struct bnx2x_vf_mbx *mbx = BP_VF_MBX(bp, vf->index);
1065         struct pfvf_general_resp_tlv *resp = &mbx->msg->resp.general_resp;
1066         dma_addr_t pf_addr;
1067         u64 vf_addr;
1068         int rc;
1069
1070         bnx2x_dp_tlv_list(bp, resp);
1071         DP(BNX2X_MSG_IOV, "mailbox vf address hi 0x%x, lo 0x%x, offset 0x%x\n",
1072            mbx->vf_addr_hi, mbx->vf_addr_lo, mbx->first_tlv.resp_msg_offset);
1073
1074         resp->hdr.status = bnx2x_pfvf_status_codes(vf_rc);
1075
1076         /* send response */
1077         vf_addr = HILO_U64(mbx->vf_addr_hi, mbx->vf_addr_lo) +
1078                   mbx->first_tlv.resp_msg_offset;
1079         pf_addr = mbx->msg_mapping +
1080                   offsetof(struct bnx2x_vf_mbx_msg, resp);
1081
1082         /* Copy the response buffer. The first u64 is written afterwards, as
1083          * the vf is sensitive to the header being written
1084          */
1085         vf_addr += sizeof(u64);
1086         pf_addr += sizeof(u64);
1087         rc = bnx2x_copy32_vf_dmae(bp, false, pf_addr, vf->abs_vfid,
1088                                   U64_HI(vf_addr),
1089                                   U64_LO(vf_addr),
1090                                   (sizeof(union pfvf_tlvs) - sizeof(u64))/4);
1091         if (rc) {
1092                 BNX2X_ERR("Failed to copy response body to VF %d\n",
1093                           vf->abs_vfid);
1094                 goto mbx_error;
1095         }
1096         vf_addr -= sizeof(u64);
1097         pf_addr -= sizeof(u64);
1098
1099         /* ack the FW */
1100         storm_memset_vf_mbx_ack(bp, vf->abs_vfid);
1101         mmiowb();
1102
1103         /* copy the response header including status-done field,
1104          * must be last dmae, must be after FW is acked
1105          */
1106         rc = bnx2x_copy32_vf_dmae(bp, false, pf_addr, vf->abs_vfid,
1107                                   U64_HI(vf_addr),
1108                                   U64_LO(vf_addr),
1109                                   sizeof(u64)/4);
1110
1111         /* unlock channel mutex */
1112         bnx2x_unlock_vf_pf_channel(bp, vf, mbx->first_tlv.tl.type);
1113
1114         if (rc) {
1115                 BNX2X_ERR("Failed to copy response status to VF %d\n",
1116                           vf->abs_vfid);
1117                 goto mbx_error;
1118         }
1119         return;
1120
1121 mbx_error:
1122         bnx2x_vf_release(bp, vf);
1123 }
1124
1125 static void bnx2x_vf_mbx_resp(struct bnx2x *bp,
1126                               struct bnx2x_virtf *vf,
1127                               int rc)
1128 {
1129         bnx2x_vf_mbx_resp_single_tlv(bp, vf);
1130         bnx2x_vf_mbx_resp_send_msg(bp, vf, rc);
1131 }
1132
1133 static void bnx2x_vf_mbx_resp_phys_port(struct bnx2x *bp,
1134                                         struct bnx2x_virtf *vf,
1135                                         void *buffer,
1136                                         u16 *offset)
1137 {
1138         struct vfpf_port_phys_id_resp_tlv *port_id;
1139
1140         if (!(bp->flags & HAS_PHYS_PORT_ID))
1141                 return;
1142
1143         bnx2x_add_tlv(bp, buffer, *offset, CHANNEL_TLV_PHYS_PORT_ID,
1144                       sizeof(struct vfpf_port_phys_id_resp_tlv));
1145
1146         port_id = (struct vfpf_port_phys_id_resp_tlv *)
1147                   (((u8 *)buffer) + *offset);
1148         memcpy(port_id->id, bp->phys_port_id, ETH_ALEN);
1149
1150         /* Offset should continue representing the offset to the tail
1151          * of TLV data (outside this function scope)
1152          */
1153         *offset += sizeof(struct vfpf_port_phys_id_resp_tlv);
1154 }
1155
1156 static void bnx2x_vf_mbx_resp_fp_hsi_ver(struct bnx2x *bp,
1157                                          struct bnx2x_virtf *vf,
1158                                          void *buffer,
1159                                          u16 *offset)
1160 {
1161         struct vfpf_fp_hsi_resp_tlv *fp_hsi;
1162
1163         bnx2x_add_tlv(bp, buffer, *offset, CHANNEL_TLV_FP_HSI_SUPPORT,
1164                       sizeof(struct vfpf_fp_hsi_resp_tlv));
1165
1166         fp_hsi = (struct vfpf_fp_hsi_resp_tlv *)
1167                  (((u8 *)buffer) + *offset);
1168         fp_hsi->is_supported = (vf->fp_hsi > ETH_FP_HSI_VERSION) ? 0 : 1;
1169
1170         /* Offset should continue representing the offset to the tail
1171          * of TLV data (outside this function scope)
1172          */
1173         *offset += sizeof(struct vfpf_fp_hsi_resp_tlv);
1174 }
1175
1176 static void bnx2x_vf_mbx_acquire_resp(struct bnx2x *bp, struct bnx2x_virtf *vf,
1177                                       struct bnx2x_vf_mbx *mbx, int vfop_status)
1178 {
1179         int i;
1180         struct pfvf_acquire_resp_tlv *resp = &mbx->msg->resp.acquire_resp;
1181         struct pf_vf_resc *resc = &resp->resc;
1182         u8 status = bnx2x_pfvf_status_codes(vfop_status);
1183         u16 length;
1184
1185         memset(resp, 0, sizeof(*resp));
1186
1187         /* fill in pfdev info */
1188         resp->pfdev_info.chip_num = bp->common.chip_id;
1189         resp->pfdev_info.db_size = bp->db_size;
1190         resp->pfdev_info.indices_per_sb = HC_SB_MAX_INDICES_E2;
1191         resp->pfdev_info.pf_cap = (PFVF_CAP_RSS |
1192                                    PFVF_CAP_TPA |
1193                                    PFVF_CAP_TPA_UPDATE);
1194         bnx2x_fill_fw_str(bp, resp->pfdev_info.fw_ver,
1195                           sizeof(resp->pfdev_info.fw_ver));
1196
1197         if (status == PFVF_STATUS_NO_RESOURCE ||
1198             status == PFVF_STATUS_SUCCESS) {
1199                 /* set resources numbers, if status equals NO_RESOURCE these
1200                  * are max possible numbers
1201                  */
1202                 resc->num_rxqs = vf_rxq_count(vf) ? :
1203                         bnx2x_vf_max_queue_cnt(bp, vf);
1204                 resc->num_txqs = vf_txq_count(vf) ? :
1205                         bnx2x_vf_max_queue_cnt(bp, vf);
1206                 resc->num_sbs = vf_sb_count(vf);
1207                 resc->num_mac_filters = vf_mac_rules_cnt(vf);
1208                 resc->num_vlan_filters = vf_vlan_rules_visible_cnt(vf);
1209                 resc->num_mc_filters = 0;
1210
1211                 if (status == PFVF_STATUS_SUCCESS) {
1212                         /* fill in the allocated resources */
1213                         struct pf_vf_bulletin_content *bulletin =
1214                                 BP_VF_BULLETIN(bp, vf->index);
1215
1216                         for_each_vfq(vf, i)
1217                                 resc->hw_qid[i] =
1218                                         vfq_qzone_id(vf, vfq_get(vf, i));
1219
1220                         for_each_vf_sb(vf, i) {
1221                                 resc->hw_sbs[i].hw_sb_id = vf_igu_sb(vf, i);
1222                                 resc->hw_sbs[i].sb_qid = vf_hc_qzone(vf, i);
1223                         }
1224
1225                         /* if a mac has been set for this vf, supply it */
1226                         if (bulletin->valid_bitmap & 1 << MAC_ADDR_VALID) {
1227                                 memcpy(resc->current_mac_addr, bulletin->mac,
1228                                        ETH_ALEN);
1229                         }
1230                 }
1231         }
1232
1233         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"
1234            "resources- n_rxq-%d, n_txq-%d, n_sbs-%d, n_macs-%d, n_vlans-%d, n_mcs-%d, fw_ver: '%s'\n",
1235            vf->abs_vfid,
1236            resp->pfdev_info.chip_num,
1237            resp->pfdev_info.db_size,
1238            resp->pfdev_info.indices_per_sb,
1239            resp->pfdev_info.pf_cap,
1240            resc->num_rxqs,
1241            resc->num_txqs,
1242            resc->num_sbs,
1243            resc->num_mac_filters,
1244            resc->num_vlan_filters,
1245            resc->num_mc_filters,
1246            resp->pfdev_info.fw_ver);
1247
1248         DP_CONT(BNX2X_MSG_IOV, "hw_qids- [ ");
1249         for (i = 0; i < vf_rxq_count(vf); i++)
1250                 DP_CONT(BNX2X_MSG_IOV, "%d ", resc->hw_qid[i]);
1251         DP_CONT(BNX2X_MSG_IOV, "], sb_info- [ ");
1252         for (i = 0; i < vf_sb_count(vf); i++)
1253                 DP_CONT(BNX2X_MSG_IOV, "%d:%d ",
1254                         resc->hw_sbs[i].hw_sb_id,
1255                         resc->hw_sbs[i].sb_qid);
1256         DP_CONT(BNX2X_MSG_IOV, "]\n");
1257
1258         /* prepare response */
1259         length = sizeof(struct pfvf_acquire_resp_tlv);
1260         bnx2x_add_tlv(bp, &mbx->msg->resp, 0, CHANNEL_TLV_ACQUIRE, length);
1261
1262         /* Handle possible VF requests for physical port identifiers.
1263          * 'length' should continue to indicate the offset of the first empty
1264          * place in the buffer (i.e., where next TLV should be inserted)
1265          */
1266         if (bnx2x_search_tlv_list(bp, &mbx->msg->req,
1267                                   CHANNEL_TLV_PHYS_PORT_ID))
1268                 bnx2x_vf_mbx_resp_phys_port(bp, vf, &mbx->msg->resp, &length);
1269
1270         /* `New' vfs will want to know if fastpath HSI is supported, since
1271          * if that's not the case they could print into system log the fact
1272          * the driver version must be updated.
1273          */
1274         bnx2x_vf_mbx_resp_fp_hsi_ver(bp, vf, &mbx->msg->resp, &length);
1275
1276         bnx2x_add_tlv(bp, &mbx->msg->resp, length, CHANNEL_TLV_LIST_END,
1277                       sizeof(struct channel_list_end_tlv));
1278
1279         /* send the response */
1280         bnx2x_vf_mbx_resp_send_msg(bp, vf, vfop_status);
1281 }
1282
1283 static bool bnx2x_vf_mbx_is_windows_vm(struct bnx2x *bp,
1284                                        struct vfpf_acquire_tlv *acquire)
1285 {
1286         /* Windows driver does one of three things:
1287          * 1. Old driver doesn't have bulletin board address set.
1288          * 2. 'Middle' driver sends mc_num == 32.
1289          * 3. New driver sets the OS field.
1290          */
1291         if (!acquire->bulletin_addr ||
1292             acquire->resc_request.num_mc_filters == 32 ||
1293             ((acquire->vfdev_info.vf_os & VF_OS_MASK) ==
1294              VF_OS_WINDOWS))
1295                 return true;
1296
1297         return false;
1298 }
1299
1300 static int bnx2x_vf_mbx_acquire_chk_dorq(struct bnx2x *bp,
1301                                          struct bnx2x_virtf *vf,
1302                                          struct bnx2x_vf_mbx *mbx)
1303 {
1304         /* Linux drivers which correctly set the doorbell size also
1305          * send a physical port request
1306          */
1307         if (bnx2x_search_tlv_list(bp, &mbx->msg->req,
1308                                   CHANNEL_TLV_PHYS_PORT_ID))
1309                 return 0;
1310
1311         /* Issue does not exist in windows VMs */
1312         if (bnx2x_vf_mbx_is_windows_vm(bp, &mbx->msg->req.acquire))
1313                 return 0;
1314
1315         return -EOPNOTSUPP;
1316 }
1317
1318 static void bnx2x_vf_mbx_acquire(struct bnx2x *bp, struct bnx2x_virtf *vf,
1319                                  struct bnx2x_vf_mbx *mbx)
1320 {
1321         int rc;
1322         struct vfpf_acquire_tlv *acquire = &mbx->msg->req.acquire;
1323
1324         /* log vfdef info */
1325         DP(BNX2X_MSG_IOV,
1326            "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",
1327            vf->abs_vfid, acquire->vfdev_info.vf_id, acquire->vfdev_info.vf_os,
1328            acquire->resc_request.num_rxqs, acquire->resc_request.num_txqs,
1329            acquire->resc_request.num_sbs, acquire->resc_request.num_mac_filters,
1330            acquire->resc_request.num_vlan_filters,
1331            acquire->resc_request.num_mc_filters);
1332
1333         /* Prevent VFs with old drivers from loading, since they calculate
1334          * CIDs incorrectly requiring a VF-flr [VM reboot] in order to recover
1335          * while being upgraded.
1336          */
1337         rc = bnx2x_vf_mbx_acquire_chk_dorq(bp, vf, mbx);
1338         if (rc) {
1339                 DP(BNX2X_MSG_IOV,
1340                    "VF [%d] - Can't support acquire request due to doorbell mismatch. Please update VM driver\n",
1341                    vf->abs_vfid);
1342                 goto out;
1343         }
1344
1345         /* Verify the VF fastpath HSI can be supported by the loaded FW.
1346          * Linux vfs should be oblivious to changes between v0 and v2.
1347          */
1348         if (bnx2x_vf_mbx_is_windows_vm(bp, &mbx->msg->req.acquire))
1349                 vf->fp_hsi = acquire->vfdev_info.fp_hsi_ver;
1350         else
1351                 vf->fp_hsi = max_t(u8, acquire->vfdev_info.fp_hsi_ver,
1352                                    ETH_FP_HSI_VER_2);
1353         if (vf->fp_hsi > ETH_FP_HSI_VERSION) {
1354                 DP(BNX2X_MSG_IOV,
1355                    "VF [%d] - Can't support acquire request since VF requests a FW version which is too new [%02x > %02x]\n",
1356                    vf->abs_vfid, acquire->vfdev_info.fp_hsi_ver,
1357                    ETH_FP_HSI_VERSION);
1358                 rc = -EINVAL;
1359                 goto out;
1360         }
1361
1362         /* acquire the resources */
1363         rc = bnx2x_vf_acquire(bp, vf, &acquire->resc_request);
1364
1365         /* store address of vf's bulletin board */
1366         vf->bulletin_map = acquire->bulletin_addr;
1367         if (acquire->vfdev_info.caps & VF_CAP_SUPPORT_EXT_BULLETIN) {
1368                 DP(BNX2X_MSG_IOV, "VF[%d] supports long bulletin boards\n",
1369                    vf->abs_vfid);
1370                 vf->cfg_flags |= VF_CFG_EXT_BULLETIN;
1371         } else {
1372                 vf->cfg_flags &= ~VF_CFG_EXT_BULLETIN;
1373         }
1374
1375 out:
1376         /* response */
1377         bnx2x_vf_mbx_acquire_resp(bp, vf, mbx, rc);
1378 }
1379
1380 static void bnx2x_vf_mbx_init_vf(struct bnx2x *bp, struct bnx2x_virtf *vf,
1381                               struct bnx2x_vf_mbx *mbx)
1382 {
1383         struct vfpf_init_tlv *init = &mbx->msg->req.init;
1384         int rc;
1385
1386         /* record ghost addresses from vf message */
1387         vf->spq_map = init->spq_addr;
1388         vf->fw_stat_map = init->stats_addr;
1389         vf->stats_stride = init->stats_stride;
1390         rc = bnx2x_vf_init(bp, vf, (dma_addr_t *)init->sb_addr);
1391
1392         /* set VF multiqueue statistics collection mode */
1393         if (init->flags & VFPF_INIT_FLG_STATS_COALESCE)
1394                 vf->cfg_flags |= VF_CFG_STATS_COALESCE;
1395
1396         /* Update VF's view of link state */
1397         if (vf->cfg_flags & VF_CFG_EXT_BULLETIN)
1398                 bnx2x_iov_link_update_vf(bp, vf->index);
1399
1400         /* response */
1401         bnx2x_vf_mbx_resp(bp, vf, rc);
1402 }
1403
1404 /* convert MBX queue-flags to standard SP queue-flags */
1405 static void bnx2x_vf_mbx_set_q_flags(struct bnx2x *bp, u32 mbx_q_flags,
1406                                      unsigned long *sp_q_flags)
1407 {
1408         if (mbx_q_flags & VFPF_QUEUE_FLG_TPA)
1409                 __set_bit(BNX2X_Q_FLG_TPA, sp_q_flags);
1410         if (mbx_q_flags & VFPF_QUEUE_FLG_TPA_IPV6)
1411                 __set_bit(BNX2X_Q_FLG_TPA_IPV6, sp_q_flags);
1412         if (mbx_q_flags & VFPF_QUEUE_FLG_TPA_GRO)
1413                 __set_bit(BNX2X_Q_FLG_TPA_GRO, sp_q_flags);
1414         if (mbx_q_flags & VFPF_QUEUE_FLG_STATS)
1415                 __set_bit(BNX2X_Q_FLG_STATS, sp_q_flags);
1416         if (mbx_q_flags & VFPF_QUEUE_FLG_VLAN)
1417                 __set_bit(BNX2X_Q_FLG_VLAN, sp_q_flags);
1418         if (mbx_q_flags & VFPF_QUEUE_FLG_COS)
1419                 __set_bit(BNX2X_Q_FLG_COS, sp_q_flags);
1420         if (mbx_q_flags & VFPF_QUEUE_FLG_HC)
1421                 __set_bit(BNX2X_Q_FLG_HC, sp_q_flags);
1422         if (mbx_q_flags & VFPF_QUEUE_FLG_DHC)
1423                 __set_bit(BNX2X_Q_FLG_DHC, sp_q_flags);
1424         if (mbx_q_flags & VFPF_QUEUE_FLG_LEADING_RSS)
1425                 __set_bit(BNX2X_Q_FLG_LEADING_RSS, sp_q_flags);
1426
1427         /* outer vlan removal is set according to PF's multi function mode */
1428         if (IS_MF_SD(bp))
1429                 __set_bit(BNX2X_Q_FLG_OV, sp_q_flags);
1430 }
1431
1432 static void bnx2x_vf_mbx_setup_q(struct bnx2x *bp, struct bnx2x_virtf *vf,
1433                                  struct bnx2x_vf_mbx *mbx)
1434 {
1435         struct vfpf_setup_q_tlv *setup_q = &mbx->msg->req.setup_q;
1436         struct bnx2x_vf_queue_construct_params qctor;
1437         int rc = 0;
1438
1439         /* verify vf_qid */
1440         if (setup_q->vf_qid >= vf_rxq_count(vf)) {
1441                 BNX2X_ERR("vf_qid %d invalid, max queue count is %d\n",
1442                           setup_q->vf_qid, vf_rxq_count(vf));
1443                 rc = -EINVAL;
1444                 goto response;
1445         }
1446
1447         /* tx queues must be setup alongside rx queues thus if the rx queue
1448          * is not marked as valid there's nothing to do.
1449          */
1450         if (setup_q->param_valid & (VFPF_RXQ_VALID|VFPF_TXQ_VALID)) {
1451                 struct bnx2x_vf_queue *q = vfq_get(vf, setup_q->vf_qid);
1452                 unsigned long q_type = 0;
1453
1454                 struct bnx2x_queue_init_params *init_p;
1455                 struct bnx2x_queue_setup_params *setup_p;
1456
1457                 if (bnx2x_vfq_is_leading(q))
1458                         bnx2x_leading_vfq_init(bp, vf, q);
1459
1460                 /* re-init the VF operation context */
1461                 memset(&qctor, 0 ,
1462                        sizeof(struct bnx2x_vf_queue_construct_params));
1463                 setup_p = &qctor.prep_qsetup;
1464                 init_p =  &qctor.qstate.params.init;
1465
1466                 /* activate immediately */
1467                 __set_bit(BNX2X_Q_FLG_ACTIVE, &setup_p->flags);
1468
1469                 if (setup_q->param_valid & VFPF_TXQ_VALID) {
1470                         struct bnx2x_txq_setup_params *txq_params =
1471                                 &setup_p->txq_params;
1472
1473                         __set_bit(BNX2X_Q_TYPE_HAS_TX, &q_type);
1474
1475                         /* save sb resource index */
1476                         q->sb_idx = setup_q->txq.vf_sb;
1477
1478                         /* tx init */
1479                         init_p->tx.hc_rate = setup_q->txq.hc_rate;
1480                         init_p->tx.sb_cq_index = setup_q->txq.sb_index;
1481
1482                         bnx2x_vf_mbx_set_q_flags(bp, setup_q->txq.flags,
1483                                                  &init_p->tx.flags);
1484
1485                         /* tx setup - flags */
1486                         bnx2x_vf_mbx_set_q_flags(bp, setup_q->txq.flags,
1487                                                  &setup_p->flags);
1488
1489                         /* tx setup - general, nothing */
1490
1491                         /* tx setup - tx */
1492                         txq_params->dscr_map = setup_q->txq.txq_addr;
1493                         txq_params->sb_cq_index = setup_q->txq.sb_index;
1494                         txq_params->traffic_type = setup_q->txq.traffic_type;
1495
1496                         bnx2x_vfop_qctor_dump_tx(bp, vf, init_p, setup_p,
1497                                                  q->index, q->sb_idx);
1498                 }
1499
1500                 if (setup_q->param_valid & VFPF_RXQ_VALID) {
1501                         struct bnx2x_rxq_setup_params *rxq_params =
1502                                                         &setup_p->rxq_params;
1503
1504                         __set_bit(BNX2X_Q_TYPE_HAS_RX, &q_type);
1505
1506                         /* Note: there is no support for different SBs
1507                          * for TX and RX
1508                          */
1509                         q->sb_idx = setup_q->rxq.vf_sb;
1510
1511                         /* rx init */
1512                         init_p->rx.hc_rate = setup_q->rxq.hc_rate;
1513                         init_p->rx.sb_cq_index = setup_q->rxq.sb_index;
1514                         bnx2x_vf_mbx_set_q_flags(bp, setup_q->rxq.flags,
1515                                                  &init_p->rx.flags);
1516
1517                         /* rx setup - flags */
1518                         bnx2x_vf_mbx_set_q_flags(bp, setup_q->rxq.flags,
1519                                                  &setup_p->flags);
1520
1521                         /* rx setup - general */
1522                         setup_p->gen_params.mtu = setup_q->rxq.mtu;
1523
1524                         /* rx setup - rx */
1525                         rxq_params->drop_flags = setup_q->rxq.drop_flags;
1526                         rxq_params->dscr_map = setup_q->rxq.rxq_addr;
1527                         rxq_params->sge_map = setup_q->rxq.sge_addr;
1528                         rxq_params->rcq_map = setup_q->rxq.rcq_addr;
1529                         rxq_params->rcq_np_map = setup_q->rxq.rcq_np_addr;
1530                         rxq_params->buf_sz = setup_q->rxq.buf_sz;
1531                         rxq_params->tpa_agg_sz = setup_q->rxq.tpa_agg_sz;
1532                         rxq_params->max_sges_pkt = setup_q->rxq.max_sge_pkt;
1533                         rxq_params->sge_buf_sz = setup_q->rxq.sge_buf_sz;
1534                         rxq_params->cache_line_log =
1535                                 setup_q->rxq.cache_line_log;
1536                         rxq_params->sb_cq_index = setup_q->rxq.sb_index;
1537
1538                         /* rx setup - multicast engine */
1539                         if (bnx2x_vfq_is_leading(q)) {
1540                                 u8 mcast_id = FW_VF_HANDLE(vf->abs_vfid);
1541
1542                                 rxq_params->mcast_engine_id = mcast_id;
1543                                 __set_bit(BNX2X_Q_FLG_MCAST, &setup_p->flags);
1544                         }
1545
1546                         bnx2x_vfop_qctor_dump_rx(bp, vf, init_p, setup_p,
1547                                                  q->index, q->sb_idx);
1548                 }
1549                 /* complete the preparations */
1550                 bnx2x_vfop_qctor_prep(bp, vf, q, &qctor, q_type);
1551
1552                 rc = bnx2x_vf_queue_setup(bp, vf, q->index, &qctor);
1553                 if (rc)
1554                         goto response;
1555         }
1556 response:
1557         bnx2x_vf_mbx_resp(bp, vf, rc);
1558 }
1559
1560 static int bnx2x_vf_mbx_macvlan_list(struct bnx2x *bp,
1561                                      struct bnx2x_virtf *vf,
1562                                      struct vfpf_set_q_filters_tlv *tlv,
1563                                      struct bnx2x_vf_mac_vlan_filters **pfl,
1564                                      u32 type_flag)
1565 {
1566         int i, j;
1567         struct bnx2x_vf_mac_vlan_filters *fl = NULL;
1568         size_t fsz;
1569
1570         fsz = tlv->n_mac_vlan_filters *
1571               sizeof(struct bnx2x_vf_mac_vlan_filter) +
1572               sizeof(struct bnx2x_vf_mac_vlan_filters);
1573
1574         fl = kzalloc(fsz, GFP_KERNEL);
1575         if (!fl)
1576                 return -ENOMEM;
1577
1578         for (i = 0, j = 0; i < tlv->n_mac_vlan_filters; i++) {
1579                 struct vfpf_q_mac_vlan_filter *msg_filter = &tlv->filters[i];
1580
1581                 if ((msg_filter->flags & type_flag) != type_flag)
1582                         continue;
1583                 if (type_flag == VFPF_Q_FILTER_DEST_MAC_VALID) {
1584                         fl->filters[j].mac = msg_filter->mac;
1585                         fl->filters[j].type = BNX2X_VF_FILTER_MAC;
1586                 } else {
1587                         fl->filters[j].vid = msg_filter->vlan_tag;
1588                         fl->filters[j].type = BNX2X_VF_FILTER_VLAN;
1589                 }
1590                 fl->filters[j].add =
1591                         (msg_filter->flags & VFPF_Q_FILTER_SET_MAC) ?
1592                         true : false;
1593                 fl->count++;
1594         }
1595         if (!fl->count)
1596                 kfree(fl);
1597         else
1598                 *pfl = fl;
1599
1600         return 0;
1601 }
1602
1603 static void bnx2x_vf_mbx_dp_q_filter(struct bnx2x *bp, int msglvl, int idx,
1604                                        struct vfpf_q_mac_vlan_filter *filter)
1605 {
1606         DP(msglvl, "MAC-VLAN[%d] -- flags=0x%x\n", idx, filter->flags);
1607         if (filter->flags & VFPF_Q_FILTER_VLAN_TAG_VALID)
1608                 DP_CONT(msglvl, ", vlan=%d", filter->vlan_tag);
1609         if (filter->flags & VFPF_Q_FILTER_DEST_MAC_VALID)
1610                 DP_CONT(msglvl, ", MAC=%pM", filter->mac);
1611         DP_CONT(msglvl, "\n");
1612 }
1613
1614 static void bnx2x_vf_mbx_dp_q_filters(struct bnx2x *bp, int msglvl,
1615                                        struct vfpf_set_q_filters_tlv *filters)
1616 {
1617         int i;
1618
1619         if (filters->flags & VFPF_SET_Q_FILTERS_MAC_VLAN_CHANGED)
1620                 for (i = 0; i < filters->n_mac_vlan_filters; i++)
1621                         bnx2x_vf_mbx_dp_q_filter(bp, msglvl, i,
1622                                                  &filters->filters[i]);
1623
1624         if (filters->flags & VFPF_SET_Q_FILTERS_RX_MASK_CHANGED)
1625                 DP(msglvl, "RX-MASK=0x%x\n", filters->rx_mask);
1626
1627         if (filters->flags & VFPF_SET_Q_FILTERS_MULTICAST_CHANGED)
1628                 for (i = 0; i < filters->n_multicast; i++)
1629                         DP(msglvl, "MULTICAST=%pM\n", filters->multicast[i]);
1630 }
1631
1632 #define VFPF_MAC_FILTER         VFPF_Q_FILTER_DEST_MAC_VALID
1633 #define VFPF_VLAN_FILTER        VFPF_Q_FILTER_VLAN_TAG_VALID
1634
1635 static int bnx2x_vf_mbx_qfilters(struct bnx2x *bp, struct bnx2x_virtf *vf)
1636 {
1637         int rc = 0;
1638
1639         struct vfpf_set_q_filters_tlv *msg =
1640                 &BP_VF_MBX(bp, vf->index)->msg->req.set_q_filters;
1641
1642         /* check for any mac/vlan changes */
1643         if (msg->flags & VFPF_SET_Q_FILTERS_MAC_VLAN_CHANGED) {
1644                 /* build mac list */
1645                 struct bnx2x_vf_mac_vlan_filters *fl = NULL;
1646
1647                 rc = bnx2x_vf_mbx_macvlan_list(bp, vf, msg, &fl,
1648                                                VFPF_MAC_FILTER);
1649                 if (rc)
1650                         goto op_err;
1651
1652                 if (fl) {
1653
1654                         /* set mac list */
1655                         rc = bnx2x_vf_mac_vlan_config_list(bp, vf, fl,
1656                                                            msg->vf_qid,
1657                                                            false);
1658                         if (rc)
1659                                 goto op_err;
1660                 }
1661
1662                 /* build vlan list */
1663                 fl = NULL;
1664
1665                 rc = bnx2x_vf_mbx_macvlan_list(bp, vf, msg, &fl,
1666                                                VFPF_VLAN_FILTER);
1667                 if (rc)
1668                         goto op_err;
1669
1670                 if (fl) {
1671                         /* set vlan list */
1672                         rc = bnx2x_vf_mac_vlan_config_list(bp, vf, fl,
1673                                                            msg->vf_qid,
1674                                                            false);
1675                         if (rc)
1676                                 goto op_err;
1677                 }
1678         }
1679
1680         if (msg->flags & VFPF_SET_Q_FILTERS_RX_MASK_CHANGED) {
1681                 unsigned long accept = 0;
1682                 struct pf_vf_bulletin_content *bulletin =
1683                                         BP_VF_BULLETIN(bp, vf->index);
1684
1685                 /* Ignore VF requested mode; instead set a regular mode */
1686                 if (msg->rx_mask !=  VFPF_RX_MASK_ACCEPT_NONE) {
1687                         __set_bit(BNX2X_ACCEPT_UNICAST, &accept);
1688                         __set_bit(BNX2X_ACCEPT_MULTICAST, &accept);
1689                         __set_bit(BNX2X_ACCEPT_BROADCAST, &accept);
1690                 }
1691
1692                 /* A packet arriving the vf's mac should be accepted
1693                  * with any vlan, unless a vlan has already been
1694                  * configured.
1695                  */
1696                 if (!(bulletin->valid_bitmap & (1 << VLAN_VALID)))
1697                         __set_bit(BNX2X_ACCEPT_ANY_VLAN, &accept);
1698
1699                 /* set rx-mode */
1700                 rc = bnx2x_vf_rxmode(bp, vf, msg->vf_qid, accept);
1701                 if (rc)
1702                         goto op_err;
1703         }
1704
1705         if (msg->flags & VFPF_SET_Q_FILTERS_MULTICAST_CHANGED) {
1706                 /* set mcasts */
1707                 rc = bnx2x_vf_mcast(bp, vf, msg->multicast,
1708                                     msg->n_multicast, false);
1709                 if (rc)
1710                         goto op_err;
1711         }
1712 op_err:
1713         if (rc)
1714                 BNX2X_ERR("QFILTERS[%d:%d] error: rc %d\n",
1715                           vf->abs_vfid, msg->vf_qid, rc);
1716         return rc;
1717 }
1718
1719 static int bnx2x_filters_validate_mac(struct bnx2x *bp,
1720                                       struct bnx2x_virtf *vf,
1721                                       struct vfpf_set_q_filters_tlv *filters)
1722 {
1723         struct pf_vf_bulletin_content *bulletin = BP_VF_BULLETIN(bp, vf->index);
1724         int rc = 0;
1725
1726         /* if a mac was already set for this VF via the set vf mac ndo, we only
1727          * accept mac configurations of that mac. Why accept them at all?
1728          * because PF may have been unable to configure the mac at the time
1729          * since queue was not set up.
1730          */
1731         if (bulletin->valid_bitmap & 1 << MAC_ADDR_VALID) {
1732                 /* once a mac was set by ndo can only accept a single mac... */
1733                 if (filters->n_mac_vlan_filters > 1) {
1734                         BNX2X_ERR("VF[%d] requested the addition of multiple macs after set_vf_mac ndo was called\n",
1735                                   vf->abs_vfid);
1736                         rc = -EPERM;
1737                         goto response;
1738                 }
1739
1740                 /* ...and only the mac set by the ndo */
1741                 if (filters->n_mac_vlan_filters == 1 &&
1742                     !ether_addr_equal(filters->filters->mac, bulletin->mac)) {
1743                         BNX2X_ERR("VF[%d] requested the addition of a mac address not matching the one configured by set_vf_mac ndo\n",
1744                                   vf->abs_vfid);
1745
1746                         rc = -EPERM;
1747                         goto response;
1748                 }
1749         }
1750
1751 response:
1752         return rc;
1753 }
1754
1755 static int bnx2x_filters_validate_vlan(struct bnx2x *bp,
1756                                        struct bnx2x_virtf *vf,
1757                                        struct vfpf_set_q_filters_tlv *filters)
1758 {
1759         struct pf_vf_bulletin_content *bulletin = BP_VF_BULLETIN(bp, vf->index);
1760         int rc = 0;
1761
1762         /* if vlan was set by hypervisor we don't allow guest to config vlan */
1763         if (bulletin->valid_bitmap & 1 << VLAN_VALID) {
1764                 int i;
1765
1766                 /* search for vlan filters */
1767                 for (i = 0; i < filters->n_mac_vlan_filters; i++) {
1768                         if (filters->filters[i].flags &
1769                             VFPF_Q_FILTER_VLAN_TAG_VALID) {
1770                                 BNX2X_ERR("VF[%d] attempted to configure vlan but one was already set by Hypervisor. Aborting request\n",
1771                                           vf->abs_vfid);
1772                                 rc = -EPERM;
1773                                 goto response;
1774                         }
1775                 }
1776         }
1777
1778         /* verify vf_qid */
1779         if (filters->vf_qid > vf_rxq_count(vf)) {
1780                 rc = -EPERM;
1781                 goto response;
1782         }
1783
1784 response:
1785         return rc;
1786 }
1787
1788 static void bnx2x_vf_mbx_set_q_filters(struct bnx2x *bp,
1789                                        struct bnx2x_virtf *vf,
1790                                        struct bnx2x_vf_mbx *mbx)
1791 {
1792         struct vfpf_set_q_filters_tlv *filters = &mbx->msg->req.set_q_filters;
1793         int rc;
1794
1795         rc = bnx2x_filters_validate_mac(bp, vf, filters);
1796         if (rc)
1797                 goto response;
1798
1799         rc = bnx2x_filters_validate_vlan(bp, vf, filters);
1800         if (rc)
1801                 goto response;
1802
1803         DP(BNX2X_MSG_IOV, "VF[%d] Q_FILTERS: queue[%d]\n",
1804            vf->abs_vfid,
1805            filters->vf_qid);
1806
1807         /* print q_filter message */
1808         bnx2x_vf_mbx_dp_q_filters(bp, BNX2X_MSG_IOV, filters);
1809
1810         rc = bnx2x_vf_mbx_qfilters(bp, vf);
1811 response:
1812         bnx2x_vf_mbx_resp(bp, vf, rc);
1813 }
1814
1815 static void bnx2x_vf_mbx_teardown_q(struct bnx2x *bp, struct bnx2x_virtf *vf,
1816                                     struct bnx2x_vf_mbx *mbx)
1817 {
1818         int qid = mbx->msg->req.q_op.vf_qid;
1819         int rc;
1820
1821         DP(BNX2X_MSG_IOV, "VF[%d] Q_TEARDOWN: vf_qid=%d\n",
1822            vf->abs_vfid, qid);
1823
1824         rc = bnx2x_vf_queue_teardown(bp, vf, qid);
1825         bnx2x_vf_mbx_resp(bp, vf, rc);
1826 }
1827
1828 static void bnx2x_vf_mbx_close_vf(struct bnx2x *bp, struct bnx2x_virtf *vf,
1829                                   struct bnx2x_vf_mbx *mbx)
1830 {
1831         int rc;
1832
1833         DP(BNX2X_MSG_IOV, "VF[%d] VF_CLOSE\n", vf->abs_vfid);
1834
1835         rc = bnx2x_vf_close(bp, vf);
1836         bnx2x_vf_mbx_resp(bp, vf, rc);
1837 }
1838
1839 static void bnx2x_vf_mbx_release_vf(struct bnx2x *bp, struct bnx2x_virtf *vf,
1840                                     struct bnx2x_vf_mbx *mbx)
1841 {
1842         int rc;
1843
1844         DP(BNX2X_MSG_IOV, "VF[%d] VF_RELEASE\n", vf->abs_vfid);
1845
1846         rc = bnx2x_vf_free(bp, vf);
1847         bnx2x_vf_mbx_resp(bp, vf, rc);
1848 }
1849
1850 static void bnx2x_vf_mbx_update_rss(struct bnx2x *bp, struct bnx2x_virtf *vf,
1851                                     struct bnx2x_vf_mbx *mbx)
1852 {
1853         struct bnx2x_config_rss_params rss;
1854         struct vfpf_rss_tlv *rss_tlv = &mbx->msg->req.update_rss;
1855         int rc = 0;
1856
1857         if (rss_tlv->ind_table_size != T_ETH_INDIRECTION_TABLE_SIZE ||
1858             rss_tlv->rss_key_size != T_ETH_RSS_KEY) {
1859                 BNX2X_ERR("failing rss configuration of vf %d due to size mismatch\n",
1860                           vf->index);
1861                 rc = -EINVAL;
1862                 goto mbx_resp;
1863         }
1864
1865         memset(&rss, 0, sizeof(struct bnx2x_config_rss_params));
1866
1867         /* set vfop params according to rss tlv */
1868         memcpy(rss.ind_table, rss_tlv->ind_table,
1869                T_ETH_INDIRECTION_TABLE_SIZE);
1870         memcpy(rss.rss_key, rss_tlv->rss_key, sizeof(rss_tlv->rss_key));
1871         rss.rss_obj = &vf->rss_conf_obj;
1872         rss.rss_result_mask = rss_tlv->rss_result_mask;
1873
1874         /* flags handled individually for backward/forward compatibility */
1875         rss.rss_flags = 0;
1876         rss.ramrod_flags = 0;
1877
1878         if (rss_tlv->rss_flags & VFPF_RSS_MODE_DISABLED)
1879                 __set_bit(BNX2X_RSS_MODE_DISABLED, &rss.rss_flags);
1880         if (rss_tlv->rss_flags & VFPF_RSS_MODE_REGULAR)
1881                 __set_bit(BNX2X_RSS_MODE_REGULAR, &rss.rss_flags);
1882         if (rss_tlv->rss_flags & VFPF_RSS_SET_SRCH)
1883                 __set_bit(BNX2X_RSS_SET_SRCH, &rss.rss_flags);
1884         if (rss_tlv->rss_flags & VFPF_RSS_IPV4)
1885                 __set_bit(BNX2X_RSS_IPV4, &rss.rss_flags);
1886         if (rss_tlv->rss_flags & VFPF_RSS_IPV4_TCP)
1887                 __set_bit(BNX2X_RSS_IPV4_TCP, &rss.rss_flags);
1888         if (rss_tlv->rss_flags & VFPF_RSS_IPV4_UDP)
1889                 __set_bit(BNX2X_RSS_IPV4_UDP, &rss.rss_flags);
1890         if (rss_tlv->rss_flags & VFPF_RSS_IPV6)
1891                 __set_bit(BNX2X_RSS_IPV6, &rss.rss_flags);
1892         if (rss_tlv->rss_flags & VFPF_RSS_IPV6_TCP)
1893                 __set_bit(BNX2X_RSS_IPV6_TCP, &rss.rss_flags);
1894         if (rss_tlv->rss_flags & VFPF_RSS_IPV6_UDP)
1895                 __set_bit(BNX2X_RSS_IPV6_UDP, &rss.rss_flags);
1896
1897         if ((!(rss_tlv->rss_flags & VFPF_RSS_IPV4_TCP) &&
1898              rss_tlv->rss_flags & VFPF_RSS_IPV4_UDP) ||
1899             (!(rss_tlv->rss_flags & VFPF_RSS_IPV6_TCP) &&
1900              rss_tlv->rss_flags & VFPF_RSS_IPV6_UDP)) {
1901                 BNX2X_ERR("about to hit a FW assert. aborting...\n");
1902                 rc = -EINVAL;
1903                 goto mbx_resp;
1904         }
1905
1906         rc = bnx2x_vf_rss_update(bp, vf, &rss);
1907 mbx_resp:
1908         bnx2x_vf_mbx_resp(bp, vf, rc);
1909 }
1910
1911 static int bnx2x_validate_tpa_params(struct bnx2x *bp,
1912                                        struct vfpf_tpa_tlv *tpa_tlv)
1913 {
1914         int rc = 0;
1915
1916         if (tpa_tlv->tpa_client_info.max_sges_for_packet >
1917             U_ETH_MAX_SGES_FOR_PACKET) {
1918                 rc = -EINVAL;
1919                 BNX2X_ERR("TPA update: max_sges received %d, max is %d\n",
1920                           tpa_tlv->tpa_client_info.max_sges_for_packet,
1921                           U_ETH_MAX_SGES_FOR_PACKET);
1922         }
1923
1924         if (tpa_tlv->tpa_client_info.max_tpa_queues > MAX_AGG_QS(bp)) {
1925                 rc = -EINVAL;
1926                 BNX2X_ERR("TPA update: max_tpa_queues received %d, max is %d\n",
1927                           tpa_tlv->tpa_client_info.max_tpa_queues,
1928                           MAX_AGG_QS(bp));
1929         }
1930
1931         return rc;
1932 }
1933
1934 static void bnx2x_vf_mbx_update_tpa(struct bnx2x *bp, struct bnx2x_virtf *vf,
1935                                     struct bnx2x_vf_mbx *mbx)
1936 {
1937         struct bnx2x_queue_update_tpa_params vf_op_params;
1938         struct vfpf_tpa_tlv *tpa_tlv = &mbx->msg->req.update_tpa;
1939         int rc = 0;
1940
1941         memset(&vf_op_params, 0, sizeof(vf_op_params));
1942
1943         if (bnx2x_validate_tpa_params(bp, tpa_tlv))
1944                 goto mbx_resp;
1945
1946         vf_op_params.complete_on_both_clients =
1947                 tpa_tlv->tpa_client_info.complete_on_both_clients;
1948         vf_op_params.dont_verify_thr =
1949                 tpa_tlv->tpa_client_info.dont_verify_thr;
1950         vf_op_params.max_agg_sz =
1951                 tpa_tlv->tpa_client_info.max_agg_size;
1952         vf_op_params.max_sges_pkt =
1953                 tpa_tlv->tpa_client_info.max_sges_for_packet;
1954         vf_op_params.max_tpa_queues =
1955                 tpa_tlv->tpa_client_info.max_tpa_queues;
1956         vf_op_params.sge_buff_sz =
1957                 tpa_tlv->tpa_client_info.sge_buff_size;
1958         vf_op_params.sge_pause_thr_high =
1959                 tpa_tlv->tpa_client_info.sge_pause_thr_high;
1960         vf_op_params.sge_pause_thr_low =
1961                 tpa_tlv->tpa_client_info.sge_pause_thr_low;
1962         vf_op_params.tpa_mode =
1963                 tpa_tlv->tpa_client_info.tpa_mode;
1964         vf_op_params.update_ipv4 =
1965                 tpa_tlv->tpa_client_info.update_ipv4;
1966         vf_op_params.update_ipv6 =
1967                 tpa_tlv->tpa_client_info.update_ipv6;
1968
1969         rc = bnx2x_vf_tpa_update(bp, vf, tpa_tlv, &vf_op_params);
1970
1971 mbx_resp:
1972         bnx2x_vf_mbx_resp(bp, vf, rc);
1973 }
1974
1975 /* dispatch request */
1976 static void bnx2x_vf_mbx_request(struct bnx2x *bp, struct bnx2x_virtf *vf,
1977                                   struct bnx2x_vf_mbx *mbx)
1978 {
1979         int i;
1980
1981         /* check if tlv type is known */
1982         if (bnx2x_tlv_supported(mbx->first_tlv.tl.type)) {
1983                 /* Lock the per vf op mutex and note the locker's identity.
1984                  * The unlock will take place in mbx response.
1985                  */
1986                 bnx2x_lock_vf_pf_channel(bp, vf, mbx->first_tlv.tl.type);
1987
1988                 /* switch on the opcode */
1989                 switch (mbx->first_tlv.tl.type) {
1990                 case CHANNEL_TLV_ACQUIRE:
1991                         bnx2x_vf_mbx_acquire(bp, vf, mbx);
1992                         return;
1993                 case CHANNEL_TLV_INIT:
1994                         bnx2x_vf_mbx_init_vf(bp, vf, mbx);
1995                         return;
1996                 case CHANNEL_TLV_SETUP_Q:
1997                         bnx2x_vf_mbx_setup_q(bp, vf, mbx);
1998                         return;
1999                 case CHANNEL_TLV_SET_Q_FILTERS:
2000                         bnx2x_vf_mbx_set_q_filters(bp, vf, mbx);
2001                         return;
2002                 case CHANNEL_TLV_TEARDOWN_Q:
2003                         bnx2x_vf_mbx_teardown_q(bp, vf, mbx);
2004                         return;
2005                 case CHANNEL_TLV_CLOSE:
2006                         bnx2x_vf_mbx_close_vf(bp, vf, mbx);
2007                         return;
2008                 case CHANNEL_TLV_RELEASE:
2009                         bnx2x_vf_mbx_release_vf(bp, vf, mbx);
2010                         return;
2011                 case CHANNEL_TLV_UPDATE_RSS:
2012                         bnx2x_vf_mbx_update_rss(bp, vf, mbx);
2013                         return;
2014                 case CHANNEL_TLV_UPDATE_TPA:
2015                         bnx2x_vf_mbx_update_tpa(bp, vf, mbx);
2016                         return;
2017                 }
2018
2019         } else {
2020                 /* unknown TLV - this may belong to a VF driver from the future
2021                  * - a version written after this PF driver was written, which
2022                  * supports features unknown as of yet. Too bad since we don't
2023                  * support them. Or this may be because someone wrote a crappy
2024                  * VF driver and is sending garbage over the channel.
2025                  */
2026                 BNX2X_ERR("unknown TLV. type %d length %d vf->state was %d. first 20 bytes of mailbox buffer:\n",
2027                           mbx->first_tlv.tl.type, mbx->first_tlv.tl.length,
2028                           vf->state);
2029                 for (i = 0; i < 20; i++)
2030                         DP_CONT(BNX2X_MSG_IOV, "%x ",
2031                                 mbx->msg->req.tlv_buf_size.tlv_buffer[i]);
2032         }
2033
2034         /* can we respond to VF (do we have an address for it?) */
2035         if (vf->state == VF_ACQUIRED || vf->state == VF_ENABLED) {
2036                 /* notify the VF that we do not support this request */
2037                 bnx2x_vf_mbx_resp(bp, vf, PFVF_STATUS_NOT_SUPPORTED);
2038         } else {
2039                 /* can't send a response since this VF is unknown to us
2040                  * just ack the FW to release the mailbox and unlock
2041                  * the channel.
2042                  */
2043                 storm_memset_vf_mbx_ack(bp, vf->abs_vfid);
2044                 /* Firmware ack should be written before unlocking channel */
2045                 mmiowb();
2046                 bnx2x_unlock_vf_pf_channel(bp, vf, mbx->first_tlv.tl.type);
2047         }
2048 }
2049
2050 void bnx2x_vf_mbx_schedule(struct bnx2x *bp,
2051                            struct vf_pf_event_data *vfpf_event)
2052 {
2053         u8 vf_idx;
2054
2055         DP(BNX2X_MSG_IOV,
2056            "vf pf event received: vfid %d, address_hi %x, address lo %x",
2057            vfpf_event->vf_id, vfpf_event->msg_addr_hi, vfpf_event->msg_addr_lo);
2058         /* Sanity checks consider removing later */
2059
2060         /* check if the vf_id is valid */
2061         if (vfpf_event->vf_id - BP_VFDB(bp)->sriov.first_vf_in_pf >
2062             BNX2X_NR_VIRTFN(bp)) {
2063                 BNX2X_ERR("Illegal vf_id %d max allowed: %d\n",
2064                           vfpf_event->vf_id, BNX2X_NR_VIRTFN(bp));
2065                 return;
2066         }
2067
2068         vf_idx = bnx2x_vf_idx_by_abs_fid(bp, vfpf_event->vf_id);
2069
2070         /* Update VFDB with current message and schedule its handling */
2071         mutex_lock(&BP_VFDB(bp)->event_mutex);
2072         BP_VF_MBX(bp, vf_idx)->vf_addr_hi = vfpf_event->msg_addr_hi;
2073         BP_VF_MBX(bp, vf_idx)->vf_addr_lo = vfpf_event->msg_addr_lo;
2074         BP_VFDB(bp)->event_occur |= (1ULL << vf_idx);
2075         mutex_unlock(&BP_VFDB(bp)->event_mutex);
2076
2077         bnx2x_schedule_iov_task(bp, BNX2X_IOV_HANDLE_VF_MSG);
2078 }
2079
2080 /* handle new vf-pf messages */
2081 void bnx2x_vf_mbx(struct bnx2x *bp)
2082 {
2083         struct bnx2x_vfdb *vfdb = BP_VFDB(bp);
2084         u64 events;
2085         u8 vf_idx;
2086         int rc;
2087
2088         if (!vfdb)
2089                 return;
2090
2091         mutex_lock(&vfdb->event_mutex);
2092         events = vfdb->event_occur;
2093         vfdb->event_occur = 0;
2094         mutex_unlock(&vfdb->event_mutex);
2095
2096         for_each_vf(bp, vf_idx) {
2097                 struct bnx2x_vf_mbx *mbx = BP_VF_MBX(bp, vf_idx);
2098                 struct bnx2x_virtf *vf = BP_VF(bp, vf_idx);
2099
2100                 /* Handle VFs which have pending events */
2101                 if (!(events & (1ULL << vf_idx)))
2102                         continue;
2103
2104                 DP(BNX2X_MSG_IOV,
2105                    "Handling vf pf event vfid %d, address: [%x:%x], resp_offset 0x%x\n",
2106                    vf_idx, mbx->vf_addr_hi, mbx->vf_addr_lo,
2107                    mbx->first_tlv.resp_msg_offset);
2108
2109                 /* dmae to get the VF request */
2110                 rc = bnx2x_copy32_vf_dmae(bp, true, mbx->msg_mapping,
2111                                           vf->abs_vfid, mbx->vf_addr_hi,
2112                                           mbx->vf_addr_lo,
2113                                           sizeof(union vfpf_tlvs)/4);
2114                 if (rc) {
2115                         BNX2X_ERR("Failed to copy request VF %d\n",
2116                                   vf->abs_vfid);
2117                         bnx2x_vf_release(bp, vf);
2118                         return;
2119                 }
2120
2121                 /* process the VF message header */
2122                 mbx->first_tlv = mbx->msg->req.first_tlv;
2123
2124                 /* Clean response buffer to refrain from falsely
2125                  * seeing chains.
2126                  */
2127                 memset(&mbx->msg->resp, 0, sizeof(union pfvf_tlvs));
2128
2129                 /* dispatch the request (will prepare the response) */
2130                 bnx2x_vf_mbx_request(bp, vf, mbx);
2131         }
2132 }
2133
2134 void bnx2x_vf_bulletin_finalize(struct pf_vf_bulletin_content *bulletin,
2135                                 bool support_long)
2136 {
2137         /* Older VFs contain a bug where they can't check CRC for bulletin
2138          * boards of length greater than legacy size.
2139          */
2140         bulletin->length = support_long ? BULLETIN_CONTENT_SIZE :
2141                                           BULLETIN_CONTENT_LEGACY_SIZE;
2142         bulletin->crc = bnx2x_crc_vf_bulletin(bulletin);
2143 }
2144
2145 /* propagate local bulletin board to vf */
2146 int bnx2x_post_vf_bulletin(struct bnx2x *bp, int vf)
2147 {
2148         struct pf_vf_bulletin_content *bulletin = BP_VF_BULLETIN(bp, vf);
2149         dma_addr_t pf_addr = BP_VF_BULLETIN_DMA(bp)->mapping +
2150                 vf * BULLETIN_CONTENT_SIZE;
2151         dma_addr_t vf_addr = bnx2x_vf(bp, vf, bulletin_map);
2152         int rc;
2153
2154         /* can only update vf after init took place */
2155         if (bnx2x_vf(bp, vf, state) != VF_ENABLED &&
2156             bnx2x_vf(bp, vf, state) != VF_ACQUIRED)
2157                 return 0;
2158
2159         /* increment bulletin board version and compute crc */
2160         bulletin->version++;
2161         bnx2x_vf_bulletin_finalize(bulletin,
2162                                    (bnx2x_vf(bp, vf, cfg_flags) &
2163                                     VF_CFG_EXT_BULLETIN) ? true : false);
2164
2165         /* propagate bulletin board via dmae to vm memory */
2166         rc = bnx2x_copy32_vf_dmae(bp, false, pf_addr,
2167                                   bnx2x_vf(bp, vf, abs_vfid), U64_HI(vf_addr),
2168                                   U64_LO(vf_addr), bulletin->length / 4);
2169         return rc;
2170 }