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