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