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