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