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