1// SPDX-License-Identifier: (GPL-2.0-only OR BSD-3-Clause)
2/* QLogic qed NIC Driver
3 * Copyright (c) 2015-2017  QLogic Corporation
4 * Copyright (c) 2019-2020 Marvell International Ltd.
5 */
6
7#include <linux/crc32.h>
8#include <linux/etherdevice.h>
9#include "qed.h"
10#include "qed_sriov.h"
11#include "qed_vf.h"
12
13static void *qed_vf_pf_prep(struct qed_hwfn *p_hwfn, u16 type, u16 length)
14{
15	struct qed_vf_iov *p_iov = p_hwfn->vf_iov_info;
16	void *p_tlv;
17
18	/* This lock is released when we receive PF's response
19	 * in qed_send_msg2pf().
20	 * So, qed_vf_pf_prep() and qed_send_msg2pf()
21	 * must come in sequence.
22	 */
23	mutex_lock(&(p_iov->mutex));
24
25	DP_VERBOSE(p_hwfn,
26		   QED_MSG_IOV,
27		   "preparing to send 0x%04x tlv over vf pf channel\n",
28		   type);
29
30	/* Reset Requst offset */
31	p_iov->offset = (u8 *)p_iov->vf2pf_request;
32
33	/* Clear mailbox - both request and reply */
34	memset(p_iov->vf2pf_request, 0, sizeof(union vfpf_tlvs));
35	memset(p_iov->pf2vf_reply, 0, sizeof(union pfvf_tlvs));
36
37	/* Init type and length */
38	p_tlv = qed_add_tlv(p_hwfn, &p_iov->offset, type, length);
39
40	/* Init first tlv header */
41	((struct vfpf_first_tlv *)p_tlv)->reply_address =
42	    (u64)p_iov->pf2vf_reply_phys;
43
44	return p_tlv;
45}
46
47static void qed_vf_pf_req_end(struct qed_hwfn *p_hwfn, int req_status)
48{
49	union pfvf_tlvs *resp = p_hwfn->vf_iov_info->pf2vf_reply;
50
51	DP_VERBOSE(p_hwfn, QED_MSG_IOV,
52		   "VF request status = 0x%x, PF reply status = 0x%x\n",
53		   req_status, resp->default_resp.hdr.status);
54
55	mutex_unlock(&(p_hwfn->vf_iov_info->mutex));
56}
57
58#define QED_VF_CHANNEL_USLEEP_ITERATIONS	90
59#define QED_VF_CHANNEL_USLEEP_DELAY		100
60#define QED_VF_CHANNEL_MSLEEP_ITERATIONS	10
61#define QED_VF_CHANNEL_MSLEEP_DELAY		25
62
63static int qed_send_msg2pf(struct qed_hwfn *p_hwfn, u8 *done, u32 resp_size)
64{
65	union vfpf_tlvs *p_req = p_hwfn->vf_iov_info->vf2pf_request;
66	struct ustorm_trigger_vf_zone trigger;
67	struct ustorm_vf_zone *zone_data;
68	int iter, rc = 0;
69
70	zone_data = (struct ustorm_vf_zone *)PXP_VF_BAR0_START_USDM_ZONE_B;
71
72	/* output tlvs list */
73	qed_dp_tlv_list(p_hwfn, p_req);
74
75	/* need to add the END TLV to the message size */
76	resp_size += sizeof(struct channel_list_end_tlv);
77
78	/* Send TLVs over HW channel */
79	memset(&trigger, 0, sizeof(struct ustorm_trigger_vf_zone));
80	trigger.vf_pf_msg_valid = 1;
81
82	DP_VERBOSE(p_hwfn,
83		   QED_MSG_IOV,
84		   "VF -> PF [%02x] message: [%08x, %08x] --> %p, %08x --> %p\n",
85		   GET_FIELD(p_hwfn->hw_info.concrete_fid,
86			     PXP_CONCRETE_FID_PFID),
87		   upper_32_bits(p_hwfn->vf_iov_info->vf2pf_request_phys),
88		   lower_32_bits(p_hwfn->vf_iov_info->vf2pf_request_phys),
89		   &zone_data->non_trigger.vf_pf_msg_addr,
90		   *((u32 *)&trigger), &zone_data->trigger);
91
92	REG_WR(p_hwfn,
93	       (uintptr_t)&zone_data->non_trigger.vf_pf_msg_addr.lo,
94	       lower_32_bits(p_hwfn->vf_iov_info->vf2pf_request_phys));
95
96	REG_WR(p_hwfn,
97	       (uintptr_t)&zone_data->non_trigger.vf_pf_msg_addr.hi,
98	       upper_32_bits(p_hwfn->vf_iov_info->vf2pf_request_phys));
99
100	/* The message data must be written first, to prevent trigger before
101	 * data is written.
102	 */
103	wmb();
104
105	REG_WR(p_hwfn, (uintptr_t)&zone_data->trigger, *((u32 *)&trigger));
106
107	/* When PF would be done with the response, it would write back to the
108	 * `done' address from a coherent DMA zone. Poll until then.
109	 */
110
111	iter = QED_VF_CHANNEL_USLEEP_ITERATIONS;
112	while (!*done && iter--) {
113		udelay(QED_VF_CHANNEL_USLEEP_DELAY);
114		dma_rmb();
115	}
116
117	iter = QED_VF_CHANNEL_MSLEEP_ITERATIONS;
118	while (!*done && iter--) {
119		msleep(QED_VF_CHANNEL_MSLEEP_DELAY);
120		dma_rmb();
121	}
122
123	if (!*done) {
124		DP_NOTICE(p_hwfn,
125			  "VF <-- PF Timeout [Type %d]\n",
126			  p_req->first_tlv.tl.type);
127		rc = -EBUSY;
128	} else {
129		if ((*done != PFVF_STATUS_SUCCESS) &&
130		    (*done != PFVF_STATUS_NO_RESOURCE))
131			DP_NOTICE(p_hwfn,
132				  "PF response: %d [Type %d]\n",
133				  *done, p_req->first_tlv.tl.type);
134		else
135			DP_VERBOSE(p_hwfn, QED_MSG_IOV,
136				   "PF response: %d [Type %d]\n",
137				   *done, p_req->first_tlv.tl.type);
138	}
139
140	return rc;
141}
142
143static void qed_vf_pf_add_qid(struct qed_hwfn *p_hwfn,
144			      struct qed_queue_cid *p_cid)
145{
146	struct qed_vf_iov *p_iov = p_hwfn->vf_iov_info;
147	struct vfpf_qid_tlv *p_qid_tlv;
148
149	/* Only add QIDs for the queue if it was negotiated with PF */
150	if (!(p_iov->acquire_resp.pfdev_info.capabilities &
151	      PFVF_ACQUIRE_CAP_QUEUE_QIDS))
152		return;
153
154	p_qid_tlv = qed_add_tlv(p_hwfn, &p_iov->offset,
155				CHANNEL_TLV_QID, sizeof(*p_qid_tlv));
156	p_qid_tlv->qid = p_cid->qid_usage_idx;
157}
158
159static int _qed_vf_pf_release(struct qed_hwfn *p_hwfn, bool b_final)
160{
161	struct qed_vf_iov *p_iov = p_hwfn->vf_iov_info;
162	struct pfvf_def_resp_tlv *resp;
163	struct vfpf_first_tlv *req;
164	u32 size;
165	int rc;
166
167	/* clear mailbox and prep first tlv */
168	req = qed_vf_pf_prep(p_hwfn, CHANNEL_TLV_RELEASE, sizeof(*req));
169
170	/* add list termination tlv */
171	qed_add_tlv(p_hwfn, &p_iov->offset,
172		    CHANNEL_TLV_LIST_END, sizeof(struct channel_list_end_tlv));
173
174	resp = &p_iov->pf2vf_reply->default_resp;
175	rc = qed_send_msg2pf(p_hwfn, &resp->hdr.status, sizeof(*resp));
176
177	if (!rc && resp->hdr.status != PFVF_STATUS_SUCCESS)
178		rc = -EAGAIN;
179
180	qed_vf_pf_req_end(p_hwfn, rc);
181	if (!b_final)
182		return rc;
183
184	p_hwfn->b_int_enabled = 0;
185
186	if (p_iov->vf2pf_request)
187		dma_free_coherent(&p_hwfn->cdev->pdev->dev,
188				  sizeof(union vfpf_tlvs),
189				  p_iov->vf2pf_request,
190				  p_iov->vf2pf_request_phys);
191	if (p_iov->pf2vf_reply)
192		dma_free_coherent(&p_hwfn->cdev->pdev->dev,
193				  sizeof(union pfvf_tlvs),
194				  p_iov->pf2vf_reply, p_iov->pf2vf_reply_phys);
195
196	if (p_iov->bulletin.p_virt) {
197		size = sizeof(struct qed_bulletin_content);
198		dma_free_coherent(&p_hwfn->cdev->pdev->dev,
199				  size,
200				  p_iov->bulletin.p_virt, p_iov->bulletin.phys);
201	}
202
203	kfree(p_hwfn->vf_iov_info);
204	p_hwfn->vf_iov_info = NULL;
205
206	return rc;
207}
208
209int qed_vf_pf_release(struct qed_hwfn *p_hwfn)
210{
211	return _qed_vf_pf_release(p_hwfn, true);
212}
213
214#define VF_ACQUIRE_THRESH 3
215static void qed_vf_pf_acquire_reduce_resc(struct qed_hwfn *p_hwfn,
216					  struct vf_pf_resc_request *p_req,
217					  struct pf_vf_resc *p_resp)
218{
219	DP_VERBOSE(p_hwfn,
220		   QED_MSG_IOV,
221		   "PF unwilling to fulfill resource request: rxq [%02x/%02x] txq [%02x/%02x] sbs [%02x/%02x] mac [%02x/%02x] vlan [%02x/%02x] mc [%02x/%02x] cids [%02x/%02x]. Try PF recommended amount\n",
222		   p_req->num_rxqs,
223		   p_resp->num_rxqs,
224		   p_req->num_rxqs,
225		   p_resp->num_txqs,
226		   p_req->num_sbs,
227		   p_resp->num_sbs,
228		   p_req->num_mac_filters,
229		   p_resp->num_mac_filters,
230		   p_req->num_vlan_filters,
231		   p_resp->num_vlan_filters,
232		   p_req->num_mc_filters,
233		   p_resp->num_mc_filters, p_req->num_cids, p_resp->num_cids);
234
235	/* humble our request */
236	p_req->num_txqs = p_resp->num_txqs;
237	p_req->num_rxqs = p_resp->num_rxqs;
238	p_req->num_sbs = p_resp->num_sbs;
239	p_req->num_mac_filters = p_resp->num_mac_filters;
240	p_req->num_vlan_filters = p_resp->num_vlan_filters;
241	p_req->num_mc_filters = p_resp->num_mc_filters;
242	p_req->num_cids = p_resp->num_cids;
243}
244
245static int qed_vf_pf_acquire(struct qed_hwfn *p_hwfn)
246{
247	struct qed_vf_iov *p_iov = p_hwfn->vf_iov_info;
248	struct pfvf_acquire_resp_tlv *resp = &p_iov->pf2vf_reply->acquire_resp;
249	struct pf_vf_pfdev_info *pfdev_info = &resp->pfdev_info;
250	struct vf_pf_resc_request *p_resc;
251	u8 retry_cnt = VF_ACQUIRE_THRESH;
252	bool resources_acquired = false;
253	struct vfpf_acquire_tlv *req;
254	int rc = 0, attempts = 0;
255
256	/* clear mailbox and prep first tlv */
257	req = qed_vf_pf_prep(p_hwfn, CHANNEL_TLV_ACQUIRE, sizeof(*req));
258	p_resc = &req->resc_request;
259
260	/* starting filling the request */
261	req->vfdev_info.opaque_fid = p_hwfn->hw_info.opaque_fid;
262
263	p_resc->num_rxqs = QED_MAX_VF_CHAINS_PER_PF;
264	p_resc->num_txqs = QED_MAX_VF_CHAINS_PER_PF;
265	p_resc->num_sbs = QED_MAX_VF_CHAINS_PER_PF;
266	p_resc->num_mac_filters = QED_ETH_VF_NUM_MAC_FILTERS;
267	p_resc->num_vlan_filters = QED_ETH_VF_NUM_VLAN_FILTERS;
268	p_resc->num_cids = QED_ETH_VF_DEFAULT_NUM_CIDS;
269
270	req->vfdev_info.os_type = VFPF_ACQUIRE_OS_LINUX;
271	req->vfdev_info.fw_major = FW_MAJOR_VERSION;
272	req->vfdev_info.fw_minor = FW_MINOR_VERSION;
273	req->vfdev_info.fw_revision = FW_REVISION_VERSION;
274	req->vfdev_info.fw_engineering = FW_ENGINEERING_VERSION;
275	req->vfdev_info.eth_fp_hsi_major = ETH_HSI_VER_MAJOR;
276	req->vfdev_info.eth_fp_hsi_minor = ETH_HSI_VER_MINOR;
277
278	/* Fill capability field with any non-deprecated config we support */
279	req->vfdev_info.capabilities |= VFPF_ACQUIRE_CAP_100G;
280
281	/* If we've mapped the doorbell bar, try using queue qids */
282	if (p_iov->b_doorbell_bar) {
283		req->vfdev_info.capabilities |= VFPF_ACQUIRE_CAP_PHYSICAL_BAR |
284						VFPF_ACQUIRE_CAP_QUEUE_QIDS;
285		p_resc->num_cids = QED_ETH_VF_MAX_NUM_CIDS;
286	}
287
288	/* pf 2 vf bulletin board address */
289	req->bulletin_addr = p_iov->bulletin.phys;
290	req->bulletin_size = p_iov->bulletin.size;
291
292	/* add list termination tlv */
293	qed_add_tlv(p_hwfn, &p_iov->offset,
294		    CHANNEL_TLV_LIST_END, sizeof(struct channel_list_end_tlv));
295
296	while (!resources_acquired) {
297		DP_VERBOSE(p_hwfn,
298			   QED_MSG_IOV, "attempting to acquire resources\n");
299
300		/* Clear response buffer, as this might be a re-send */
301		memset(p_iov->pf2vf_reply, 0, sizeof(union pfvf_tlvs));
302
303		/* send acquire request */
304		rc = qed_send_msg2pf(p_hwfn, &resp->hdr.status, sizeof(*resp));
305
306		/* Re-try acquire in case of vf-pf hw channel timeout */
307		if (retry_cnt && rc == -EBUSY) {
308			DP_VERBOSE(p_hwfn, QED_MSG_IOV,
309				   "VF retrying to acquire due to VPC timeout\n");
310			retry_cnt--;
311			continue;
312		}
313
314		if (rc)
315			goto exit;
316
317		/* copy acquire response from buffer to p_hwfn */
318		memcpy(&p_iov->acquire_resp, resp, sizeof(p_iov->acquire_resp));
319
320		attempts++;
321
322		if (resp->hdr.status == PFVF_STATUS_SUCCESS) {
323			/* PF agrees to allocate our resources */
324			if (!(resp->pfdev_info.capabilities &
325			      PFVF_ACQUIRE_CAP_POST_FW_OVERRIDE)) {
326				/* It's possible legacy PF mistakenly accepted;
327				 * but we don't care - simply mark it as
328				 * legacy and continue.
329				 */
330				req->vfdev_info.capabilities |=
331				    VFPF_ACQUIRE_CAP_PRE_FP_HSI;
332			}
333			DP_VERBOSE(p_hwfn, QED_MSG_IOV, "resources acquired\n");
334			resources_acquired = true;
335		} else if (resp->hdr.status == PFVF_STATUS_NO_RESOURCE &&
336			   attempts < VF_ACQUIRE_THRESH) {
337			qed_vf_pf_acquire_reduce_resc(p_hwfn, p_resc,
338						      &resp->resc);
339		} else if (resp->hdr.status == PFVF_STATUS_NOT_SUPPORTED) {
340			if (pfdev_info->major_fp_hsi &&
341			    (pfdev_info->major_fp_hsi != ETH_HSI_VER_MAJOR)) {
342				DP_NOTICE(p_hwfn,
343					  "PF uses an incompatible fastpath HSI %02x.%02x [VF requires %02x.%02x]. Please change to a VF driver using %02x.xx.\n",
344					  pfdev_info->major_fp_hsi,
345					  pfdev_info->minor_fp_hsi,
346					  ETH_HSI_VER_MAJOR,
347					  ETH_HSI_VER_MINOR,
348					  pfdev_info->major_fp_hsi);
349				rc = -EINVAL;
350				goto exit;
351			}
352
353			if (!pfdev_info->major_fp_hsi) {
354				if (req->vfdev_info.capabilities &
355				    VFPF_ACQUIRE_CAP_PRE_FP_HSI) {
356					DP_NOTICE(p_hwfn,
357						  "PF uses very old drivers. Please change to a VF driver using no later than 8.8.x.x.\n");
358					rc = -EINVAL;
359					goto exit;
360				} else {
361					DP_INFO(p_hwfn,
362						"PF is old - try re-acquire to see if it supports FW-version override\n");
363					req->vfdev_info.capabilities |=
364					    VFPF_ACQUIRE_CAP_PRE_FP_HSI;
365					continue;
366				}
367			}
368
369			/* If PF/VF are using same Major, PF must have had
370			 * it's reasons. Simply fail.
371			 */
372			DP_NOTICE(p_hwfn, "PF rejected acquisition by VF\n");
373			rc = -EINVAL;
374			goto exit;
375		} else {
376			DP_ERR(p_hwfn,
377			       "PF returned error %d to VF acquisition request\n",
378			       resp->hdr.status);
379			rc = -EAGAIN;
380			goto exit;
381		}
382	}
383
384	/* Mark the PF as legacy, if needed */
385	if (req->vfdev_info.capabilities & VFPF_ACQUIRE_CAP_PRE_FP_HSI)
386		p_iov->b_pre_fp_hsi = true;
387
388	/* In case PF doesn't support multi-queue Tx, update the number of
389	 * CIDs to reflect the number of queues [older PFs didn't fill that
390	 * field].
391	 */
392	if (!(resp->pfdev_info.capabilities & PFVF_ACQUIRE_CAP_QUEUE_QIDS))
393		resp->resc.num_cids = resp->resc.num_rxqs + resp->resc.num_txqs;
394
395	/* Update bulletin board size with response from PF */
396	p_iov->bulletin.size = resp->bulletin_size;
397
398	/* get HW info */
399	p_hwfn->cdev->type = resp->pfdev_info.dev_type;
400	p_hwfn->cdev->chip_rev = resp->pfdev_info.chip_rev;
401
402	p_hwfn->cdev->chip_num = pfdev_info->chip_num & 0xffff;
403
404	/* Learn of the possibility of CMT */
405	if (IS_LEAD_HWFN(p_hwfn)) {
406		if (resp->pfdev_info.capabilities & PFVF_ACQUIRE_CAP_100G) {
407			DP_NOTICE(p_hwfn, "100g VF\n");
408			p_hwfn->cdev->num_hwfns = 2;
409		}
410	}
411
412	if (!p_iov->b_pre_fp_hsi &&
413	    (resp->pfdev_info.minor_fp_hsi < ETH_HSI_VER_MINOR)) {
414		DP_INFO(p_hwfn,
415			"PF is using older fastpath HSI; %02x.%02x is configured\n",
416			ETH_HSI_VER_MAJOR, resp->pfdev_info.minor_fp_hsi);
417	}
418
419exit:
420	qed_vf_pf_req_end(p_hwfn, rc);
421
422	return rc;
423}
424
425u32 qed_vf_hw_bar_size(struct qed_hwfn *p_hwfn, enum BAR_ID bar_id)
426{
427	u32 bar_size;
428
429	/* Regview size is fixed */
430	if (bar_id == BAR_ID_0)
431		return 1 << 17;
432
433	/* Doorbell is received from PF */
434	bar_size = p_hwfn->vf_iov_info->acquire_resp.pfdev_info.bar_size;
435	if (bar_size)
436		return 1 << bar_size;
437	return 0;
438}
439
440int qed_vf_hw_prepare(struct qed_hwfn *p_hwfn)
441{
442	struct qed_hwfn *p_lead = QED_LEADING_HWFN(p_hwfn->cdev);
443	struct qed_vf_iov *p_iov;
444	u32 reg;
445	int rc;
446
447	/* Set number of hwfns - might be overriden once leading hwfn learns
448	 * actual configuration from PF.
449	 */
450	if (IS_LEAD_HWFN(p_hwfn))
451		p_hwfn->cdev->num_hwfns = 1;
452
453	reg = PXP_VF_BAR0_ME_OPAQUE_ADDRESS;
454	p_hwfn->hw_info.opaque_fid = (u16)REG_RD(p_hwfn, reg);
455
456	reg = PXP_VF_BAR0_ME_CONCRETE_ADDRESS;
457	p_hwfn->hw_info.concrete_fid = REG_RD(p_hwfn, reg);
458
459	/* Allocate vf sriov info */
460	p_iov = kzalloc(sizeof(*p_iov), GFP_KERNEL);
461	if (!p_iov)
462		return -ENOMEM;
463
464	/* Doorbells are tricky; Upper-layer has alreday set the hwfn doorbell
465	 * value, but there are several incompatibily scenarios where that
466	 * would be incorrect and we'd need to override it.
467	 */
468	if (!p_hwfn->doorbells) {
469		p_hwfn->doorbells = (u8 __iomem *)p_hwfn->regview +
470						  PXP_VF_BAR0_START_DQ;
471	} else if (p_hwfn == p_lead) {
472		/* For leading hw-function, value is always correct, but need
473		 * to handle scenario where legacy PF would not support 100g
474		 * mapped bars later.
475		 */
476		p_iov->b_doorbell_bar = true;
477	} else {
478		/* here, value would be correct ONLY if the leading hwfn
479		 * received indication that mapped-bars are supported.
480		 */
481		if (p_lead->vf_iov_info->b_doorbell_bar)
482			p_iov->b_doorbell_bar = true;
483		else
484			p_hwfn->doorbells = (u8 __iomem *)
485			    p_hwfn->regview + PXP_VF_BAR0_START_DQ;
486	}
487
488	/* Allocate vf2pf msg */
489	p_iov->vf2pf_request = dma_alloc_coherent(&p_hwfn->cdev->pdev->dev,
490						  sizeof(union vfpf_tlvs),
491						  &p_iov->vf2pf_request_phys,
492						  GFP_KERNEL);
493	if (!p_iov->vf2pf_request)
494		goto free_p_iov;
495
496	p_iov->pf2vf_reply = dma_alloc_coherent(&p_hwfn->cdev->pdev->dev,
497						sizeof(union pfvf_tlvs),
498						&p_iov->pf2vf_reply_phys,
499						GFP_KERNEL);
500	if (!p_iov->pf2vf_reply)
501		goto free_vf2pf_request;
502
503	DP_VERBOSE(p_hwfn,
504		   QED_MSG_IOV,
505		   "VF's Request mailbox [%p virt 0x%llx phys], Response mailbox [%p virt 0x%llx phys]\n",
506		   p_iov->vf2pf_request,
507		   (u64) p_iov->vf2pf_request_phys,
508		   p_iov->pf2vf_reply, (u64)p_iov->pf2vf_reply_phys);
509
510	/* Allocate Bulletin board */
511	p_iov->bulletin.size = sizeof(struct qed_bulletin_content);
512	p_iov->bulletin.p_virt = dma_alloc_coherent(&p_hwfn->cdev->pdev->dev,
513						    p_iov->bulletin.size,
514						    &p_iov->bulletin.phys,
515						    GFP_KERNEL);
516	if (!p_iov->bulletin.p_virt)
517		goto free_pf2vf_reply;
518
519	DP_VERBOSE(p_hwfn, QED_MSG_IOV,
520		   "VF's bulletin Board [%p virt 0x%llx phys 0x%08x bytes]\n",
521		   p_iov->bulletin.p_virt,
522		   (u64)p_iov->bulletin.phys, p_iov->bulletin.size);
523
524	mutex_init(&p_iov->mutex);
525
526	p_hwfn->vf_iov_info = p_iov;
527
528	p_hwfn->hw_info.personality = QED_PCI_ETH;
529
530	rc = qed_vf_pf_acquire(p_hwfn);
531
532	/* If VF is 100g using a mapped bar and PF is too old to support that,
533	 * acquisition would succeed - but the VF would have no way knowing
534	 * the size of the doorbell bar configured in HW and thus will not
535	 * know how to split it for 2nd hw-function.
536	 * In this case we re-try without the indication of the mapped
537	 * doorbell.
538	 */
539	if (!rc && p_iov->b_doorbell_bar &&
540	    !qed_vf_hw_bar_size(p_hwfn, BAR_ID_1) &&
541	    (p_hwfn->cdev->num_hwfns > 1)) {
542		rc = _qed_vf_pf_release(p_hwfn, false);
543		if (rc)
544			return rc;
545
546		p_iov->b_doorbell_bar = false;
547		p_hwfn->doorbells = (u8 __iomem *)p_hwfn->regview +
548						  PXP_VF_BAR0_START_DQ;
549		rc = qed_vf_pf_acquire(p_hwfn);
550	}
551
552	DP_VERBOSE(p_hwfn, QED_MSG_IOV,
553		   "Regview [%p], Doorbell [%p], Device-doorbell [%p]\n",
554		   p_hwfn->regview, p_hwfn->doorbells, p_hwfn->cdev->doorbells);
555
556	return rc;
557
558free_pf2vf_reply:
559	dma_free_coherent(&p_hwfn->cdev->pdev->dev,
560			  sizeof(union pfvf_tlvs),
561			  p_iov->pf2vf_reply, p_iov->pf2vf_reply_phys);
562free_vf2pf_request:
563	dma_free_coherent(&p_hwfn->cdev->pdev->dev,
564			  sizeof(union vfpf_tlvs),
565			  p_iov->vf2pf_request, p_iov->vf2pf_request_phys);
566free_p_iov:
567	kfree(p_iov);
568
569	return -ENOMEM;
570}
571#define TSTORM_QZONE_START   PXP_VF_BAR0_START_SDM_ZONE_A
572#define MSTORM_QZONE_START(dev)   (TSTORM_QZONE_START +	\
573				   (TSTORM_QZONE_SIZE * NUM_OF_L2_QUEUES(dev)))
574
575static void
576__qed_vf_prep_tunn_req_tlv(struct vfpf_update_tunn_param_tlv *p_req,
577			   struct qed_tunn_update_type *p_src,
578			   enum qed_tunn_mode mask, u8 *p_cls)
579{
580	if (p_src->b_update_mode) {
581		p_req->tun_mode_update_mask |= BIT(mask);
582
583		if (p_src->b_mode_enabled)
584			p_req->tunn_mode |= BIT(mask);
585	}
586
587	*p_cls = p_src->tun_cls;
588}
589
590static void
591qed_vf_prep_tunn_req_tlv(struct vfpf_update_tunn_param_tlv *p_req,
592			 struct qed_tunn_update_type *p_src,
593			 enum qed_tunn_mode mask,
594			 u8 *p_cls, struct qed_tunn_update_udp_port *p_port,
595			 u8 *p_update_port, u16 *p_udp_port)
596{
597	if (p_port->b_update_port) {
598		*p_update_port = 1;
599		*p_udp_port = p_port->port;
600	}
601
602	__qed_vf_prep_tunn_req_tlv(p_req, p_src, mask, p_cls);
603}
604
605void qed_vf_set_vf_start_tunn_update_param(struct qed_tunnel_info *p_tun)
606{
607	if (p_tun->vxlan.b_mode_enabled)
608		p_tun->vxlan.b_update_mode = true;
609	if (p_tun->l2_geneve.b_mode_enabled)
610		p_tun->l2_geneve.b_update_mode = true;
611	if (p_tun->ip_geneve.b_mode_enabled)
612		p_tun->ip_geneve.b_update_mode = true;
613	if (p_tun->l2_gre.b_mode_enabled)
614		p_tun->l2_gre.b_update_mode = true;
615	if (p_tun->ip_gre.b_mode_enabled)
616		p_tun->ip_gre.b_update_mode = true;
617
618	p_tun->b_update_rx_cls = true;
619	p_tun->b_update_tx_cls = true;
620}
621
622static void
623__qed_vf_update_tunn_param(struct qed_tunn_update_type *p_tun,
624			   u16 feature_mask, u8 tunn_mode,
625			   u8 tunn_cls, enum qed_tunn_mode val)
626{
627	if (feature_mask & BIT(val)) {
628		p_tun->b_mode_enabled = tunn_mode;
629		p_tun->tun_cls = tunn_cls;
630	} else {
631		p_tun->b_mode_enabled = false;
632	}
633}
634
635static void qed_vf_update_tunn_param(struct qed_hwfn *p_hwfn,
636				     struct qed_tunnel_info *p_tun,
637				     struct pfvf_update_tunn_param_tlv *p_resp)
638{
639	/* Update mode and classes provided by PF */
640	u16 feat_mask = p_resp->tunn_feature_mask;
641
642	__qed_vf_update_tunn_param(&p_tun->vxlan, feat_mask,
643				   p_resp->vxlan_mode, p_resp->vxlan_clss,
644				   QED_MODE_VXLAN_TUNN);
645	__qed_vf_update_tunn_param(&p_tun->l2_geneve, feat_mask,
646				   p_resp->l2geneve_mode,
647				   p_resp->l2geneve_clss,
648				   QED_MODE_L2GENEVE_TUNN);
649	__qed_vf_update_tunn_param(&p_tun->ip_geneve, feat_mask,
650				   p_resp->ipgeneve_mode,
651				   p_resp->ipgeneve_clss,
652				   QED_MODE_IPGENEVE_TUNN);
653	__qed_vf_update_tunn_param(&p_tun->l2_gre, feat_mask,
654				   p_resp->l2gre_mode, p_resp->l2gre_clss,
655				   QED_MODE_L2GRE_TUNN);
656	__qed_vf_update_tunn_param(&p_tun->ip_gre, feat_mask,
657				   p_resp->ipgre_mode, p_resp->ipgre_clss,
658				   QED_MODE_IPGRE_TUNN);
659	p_tun->geneve_port.port = p_resp->geneve_udp_port;
660	p_tun->vxlan_port.port = p_resp->vxlan_udp_port;
661
662	DP_VERBOSE(p_hwfn, QED_MSG_IOV,
663		   "tunn mode: vxlan=0x%x, l2geneve=0x%x, ipgeneve=0x%x, l2gre=0x%x, ipgre=0x%x",
664		   p_tun->vxlan.b_mode_enabled, p_tun->l2_geneve.b_mode_enabled,
665		   p_tun->ip_geneve.b_mode_enabled,
666		   p_tun->l2_gre.b_mode_enabled, p_tun->ip_gre.b_mode_enabled);
667}
668
669int qed_vf_pf_tunnel_param_update(struct qed_hwfn *p_hwfn,
670				  struct qed_tunnel_info *p_src)
671{
672	struct qed_tunnel_info *p_tun = &p_hwfn->cdev->tunnel;
673	struct qed_vf_iov *p_iov = p_hwfn->vf_iov_info;
674	struct pfvf_update_tunn_param_tlv *p_resp;
675	struct vfpf_update_tunn_param_tlv *p_req;
676	int rc;
677
678	p_req = qed_vf_pf_prep(p_hwfn, CHANNEL_TLV_UPDATE_TUNN_PARAM,
679			       sizeof(*p_req));
680
681	if (p_src->b_update_rx_cls && p_src->b_update_tx_cls)
682		p_req->update_tun_cls = 1;
683
684	qed_vf_prep_tunn_req_tlv(p_req, &p_src->vxlan, QED_MODE_VXLAN_TUNN,
685				 &p_req->vxlan_clss, &p_src->vxlan_port,
686				 &p_req->update_vxlan_port,
687				 &p_req->vxlan_port);
688	qed_vf_prep_tunn_req_tlv(p_req, &p_src->l2_geneve,
689				 QED_MODE_L2GENEVE_TUNN,
690				 &p_req->l2geneve_clss, &p_src->geneve_port,
691				 &p_req->update_geneve_port,
692				 &p_req->geneve_port);
693	__qed_vf_prep_tunn_req_tlv(p_req, &p_src->ip_geneve,
694				   QED_MODE_IPGENEVE_TUNN,
695				   &p_req->ipgeneve_clss);
696	__qed_vf_prep_tunn_req_tlv(p_req, &p_src->l2_gre,
697				   QED_MODE_L2GRE_TUNN, &p_req->l2gre_clss);
698	__qed_vf_prep_tunn_req_tlv(p_req, &p_src->ip_gre,
699				   QED_MODE_IPGRE_TUNN, &p_req->ipgre_clss);
700
701	/* add list termination tlv */
702	qed_add_tlv(p_hwfn, &p_iov->offset,
703		    CHANNEL_TLV_LIST_END,
704		    sizeof(struct channel_list_end_tlv));
705
706	p_resp = &p_iov->pf2vf_reply->tunn_param_resp;
707	rc = qed_send_msg2pf(p_hwfn, &p_resp->hdr.status, sizeof(*p_resp));
708
709	if (rc)
710		goto exit;
711
712	if (p_resp->hdr.status != PFVF_STATUS_SUCCESS) {
713		DP_VERBOSE(p_hwfn, QED_MSG_IOV,
714			   "Failed to update tunnel parameters\n");
715		rc = -EINVAL;
716	}
717
718	qed_vf_update_tunn_param(p_hwfn, p_tun, p_resp);
719exit:
720	qed_vf_pf_req_end(p_hwfn, rc);
721	return rc;
722}
723
724int
725qed_vf_pf_rxq_start(struct qed_hwfn *p_hwfn,
726		    struct qed_queue_cid *p_cid,
727		    u16 bd_max_bytes,
728		    dma_addr_t bd_chain_phys_addr,
729		    dma_addr_t cqe_pbl_addr,
730		    u16 cqe_pbl_size, void __iomem **pp_prod)
731{
732	struct qed_vf_iov *p_iov = p_hwfn->vf_iov_info;
733	struct pfvf_start_queue_resp_tlv *resp;
734	struct vfpf_start_rxq_tlv *req;
735	u8 rx_qid = p_cid->rel.queue_id;
736	int rc;
737
738	/* clear mailbox and prep first tlv */
739	req = qed_vf_pf_prep(p_hwfn, CHANNEL_TLV_START_RXQ, sizeof(*req));
740
741	req->rx_qid = rx_qid;
742	req->cqe_pbl_addr = cqe_pbl_addr;
743	req->cqe_pbl_size = cqe_pbl_size;
744	req->rxq_addr = bd_chain_phys_addr;
745	req->hw_sb = p_cid->sb_igu_id;
746	req->sb_index = p_cid->sb_idx;
747	req->bd_max_bytes = bd_max_bytes;
748	req->stat_id = -1;
749
750	/* If PF is legacy, we'll need to calculate producers ourselves
751	 * as well as clean them.
752	 */
753	if (p_iov->b_pre_fp_hsi) {
754		u8 hw_qid = p_iov->acquire_resp.resc.hw_qid[rx_qid];
755		u32 init_prod_val = 0;
756
757		*pp_prod = (u8 __iomem *)
758		    p_hwfn->regview +
759		    MSTORM_QZONE_START(p_hwfn->cdev) +
760		    hw_qid * MSTORM_QZONE_SIZE;
761
762		/* Init the rcq, rx bd and rx sge (if valid) producers to 0 */
763		__internal_ram_wr(p_hwfn, *pp_prod, sizeof(u32),
764				  (u32 *)(&init_prod_val));
765	}
766
767	qed_vf_pf_add_qid(p_hwfn, p_cid);
768
769	/* add list termination tlv */
770	qed_add_tlv(p_hwfn, &p_iov->offset,
771		    CHANNEL_TLV_LIST_END, sizeof(struct channel_list_end_tlv));
772
773	resp = &p_iov->pf2vf_reply->queue_start;
774	rc = qed_send_msg2pf(p_hwfn, &resp->hdr.status, sizeof(*resp));
775	if (rc)
776		goto exit;
777
778	if (resp->hdr.status != PFVF_STATUS_SUCCESS) {
779		rc = -EINVAL;
780		goto exit;
781	}
782
783	/* Learn the address of the producer from the response */
784	if (!p_iov->b_pre_fp_hsi) {
785		u32 init_prod_val = 0;
786
787		*pp_prod = (u8 __iomem *)p_hwfn->regview + resp->offset;
788		DP_VERBOSE(p_hwfn, QED_MSG_IOV,
789			   "Rxq[0x%02x]: producer at %p [offset 0x%08x]\n",
790			   rx_qid, *pp_prod, resp->offset);
791
792		/* Init the rcq, rx bd and rx sge (if valid) producers to 0 */
793		__internal_ram_wr(p_hwfn, *pp_prod, sizeof(u32),
794				  (u32 *)&init_prod_val);
795	}
796exit:
797	qed_vf_pf_req_end(p_hwfn, rc);
798
799	return rc;
800}
801
802int qed_vf_pf_rxq_stop(struct qed_hwfn *p_hwfn,
803		       struct qed_queue_cid *p_cid, bool cqe_completion)
804{
805	struct qed_vf_iov *p_iov = p_hwfn->vf_iov_info;
806	struct vfpf_stop_rxqs_tlv *req;
807	struct pfvf_def_resp_tlv *resp;
808	int rc;
809
810	/* clear mailbox and prep first tlv */
811	req = qed_vf_pf_prep(p_hwfn, CHANNEL_TLV_STOP_RXQS, sizeof(*req));
812
813	req->rx_qid = p_cid->rel.queue_id;
814	req->num_rxqs = 1;
815	req->cqe_completion = cqe_completion;
816
817	qed_vf_pf_add_qid(p_hwfn, p_cid);
818
819	/* add list termination tlv */
820	qed_add_tlv(p_hwfn, &p_iov->offset,
821		    CHANNEL_TLV_LIST_END, sizeof(struct channel_list_end_tlv));
822
823	resp = &p_iov->pf2vf_reply->default_resp;
824	rc = qed_send_msg2pf(p_hwfn, &resp->hdr.status, sizeof(*resp));
825	if (rc)
826		goto exit;
827
828	if (resp->hdr.status != PFVF_STATUS_SUCCESS) {
829		rc = -EINVAL;
830		goto exit;
831	}
832
833exit:
834	qed_vf_pf_req_end(p_hwfn, rc);
835
836	return rc;
837}
838
839int
840qed_vf_pf_txq_start(struct qed_hwfn *p_hwfn,
841		    struct qed_queue_cid *p_cid,
842		    dma_addr_t pbl_addr,
843		    u16 pbl_size, void __iomem **pp_doorbell)
844{
845	struct qed_vf_iov *p_iov = p_hwfn->vf_iov_info;
846	struct pfvf_start_queue_resp_tlv *resp;
847	struct vfpf_start_txq_tlv *req;
848	u16 qid = p_cid->rel.queue_id;
849	int rc;
850
851	/* clear mailbox and prep first tlv */
852	req = qed_vf_pf_prep(p_hwfn, CHANNEL_TLV_START_TXQ, sizeof(*req));
853
854	req->tx_qid = qid;
855
856	/* Tx */
857	req->pbl_addr = pbl_addr;
858	req->pbl_size = pbl_size;
859	req->hw_sb = p_cid->sb_igu_id;
860	req->sb_index = p_cid->sb_idx;
861
862	qed_vf_pf_add_qid(p_hwfn, p_cid);
863
864	/* add list termination tlv */
865	qed_add_tlv(p_hwfn, &p_iov->offset,
866		    CHANNEL_TLV_LIST_END, sizeof(struct channel_list_end_tlv));
867
868	resp = &p_iov->pf2vf_reply->queue_start;
869	rc = qed_send_msg2pf(p_hwfn, &resp->hdr.status, sizeof(*resp));
870	if (rc)
871		goto exit;
872
873	if (resp->hdr.status != PFVF_STATUS_SUCCESS) {
874		rc = -EINVAL;
875		goto exit;
876	}
877
878	/* Modern PFs provide the actual offsets, while legacy
879	 * provided only the queue id.
880	 */
881	if (!p_iov->b_pre_fp_hsi) {
882		*pp_doorbell = (u8 __iomem *)p_hwfn->doorbells + resp->offset;
883	} else {
884		u8 cid = p_iov->acquire_resp.resc.cid[qid];
885
886		*pp_doorbell = (u8 __iomem *)p_hwfn->doorbells +
887					     qed_db_addr_vf(cid,
888							    DQ_DEMS_LEGACY);
889	}
890
891	DP_VERBOSE(p_hwfn, QED_MSG_IOV,
892		   "Txq[0x%02x.%02x]: doorbell at %p [offset 0x%08x]\n",
893		   qid, p_cid->qid_usage_idx, *pp_doorbell, resp->offset);
894exit:
895	qed_vf_pf_req_end(p_hwfn, rc);
896
897	return rc;
898}
899
900int qed_vf_pf_txq_stop(struct qed_hwfn *p_hwfn, struct qed_queue_cid *p_cid)
901{
902	struct qed_vf_iov *p_iov = p_hwfn->vf_iov_info;
903	struct vfpf_stop_txqs_tlv *req;
904	struct pfvf_def_resp_tlv *resp;
905	int rc;
906
907	/* clear mailbox and prep first tlv */
908	req = qed_vf_pf_prep(p_hwfn, CHANNEL_TLV_STOP_TXQS, sizeof(*req));
909
910	req->tx_qid = p_cid->rel.queue_id;
911	req->num_txqs = 1;
912
913	qed_vf_pf_add_qid(p_hwfn, p_cid);
914
915	/* add list termination tlv */
916	qed_add_tlv(p_hwfn, &p_iov->offset,
917		    CHANNEL_TLV_LIST_END, sizeof(struct channel_list_end_tlv));
918
919	resp = &p_iov->pf2vf_reply->default_resp;
920	rc = qed_send_msg2pf(p_hwfn, &resp->hdr.status, sizeof(*resp));
921	if (rc)
922		goto exit;
923
924	if (resp->hdr.status != PFVF_STATUS_SUCCESS) {
925		rc = -EINVAL;
926		goto exit;
927	}
928
929exit:
930	qed_vf_pf_req_end(p_hwfn, rc);
931
932	return rc;
933}
934
935int qed_vf_pf_vport_start(struct qed_hwfn *p_hwfn,
936			  u8 vport_id,
937			  u16 mtu,
938			  u8 inner_vlan_removal,
939			  enum qed_tpa_mode tpa_mode,
940			  u8 max_buffers_per_cqe, u8 only_untagged)
941{
942	struct qed_vf_iov *p_iov = p_hwfn->vf_iov_info;
943	struct vfpf_vport_start_tlv *req;
944	struct pfvf_def_resp_tlv *resp;
945	int rc, i;
946
947	/* clear mailbox and prep first tlv */
948	req = qed_vf_pf_prep(p_hwfn, CHANNEL_TLV_VPORT_START, sizeof(*req));
949
950	req->mtu = mtu;
951	req->vport_id = vport_id;
952	req->inner_vlan_removal = inner_vlan_removal;
953	req->tpa_mode = tpa_mode;
954	req->max_buffers_per_cqe = max_buffers_per_cqe;
955	req->only_untagged = only_untagged;
956
957	/* status blocks */
958	for (i = 0; i < p_hwfn->vf_iov_info->acquire_resp.resc.num_sbs; i++) {
959		struct qed_sb_info *p_sb = p_hwfn->vf_iov_info->sbs_info[i];
960
961		if (p_sb)
962			req->sb_addr[i] = p_sb->sb_phys;
963	}
964
965	/* add list termination tlv */
966	qed_add_tlv(p_hwfn, &p_iov->offset,
967		    CHANNEL_TLV_LIST_END, sizeof(struct channel_list_end_tlv));
968
969	resp = &p_iov->pf2vf_reply->default_resp;
970	rc = qed_send_msg2pf(p_hwfn, &resp->hdr.status, sizeof(*resp));
971	if (rc)
972		goto exit;
973
974	if (resp->hdr.status != PFVF_STATUS_SUCCESS) {
975		rc = -EINVAL;
976		goto exit;
977	}
978
979exit:
980	qed_vf_pf_req_end(p_hwfn, rc);
981
982	return rc;
983}
984
985int qed_vf_pf_vport_stop(struct qed_hwfn *p_hwfn)
986{
987	struct qed_vf_iov *p_iov = p_hwfn->vf_iov_info;
988	struct pfvf_def_resp_tlv *resp = &p_iov->pf2vf_reply->default_resp;
989	int rc;
990
991	/* clear mailbox and prep first tlv */
992	qed_vf_pf_prep(p_hwfn, CHANNEL_TLV_VPORT_TEARDOWN,
993		       sizeof(struct vfpf_first_tlv));
994
995	/* add list termination tlv */
996	qed_add_tlv(p_hwfn, &p_iov->offset,
997		    CHANNEL_TLV_LIST_END, sizeof(struct channel_list_end_tlv));
998
999	rc = qed_send_msg2pf(p_hwfn, &resp->hdr.status, sizeof(*resp));
1000	if (rc)
1001		goto exit;
1002
1003	if (resp->hdr.status != PFVF_STATUS_SUCCESS) {
1004		rc = -EINVAL;
1005		goto exit;
1006	}
1007
1008exit:
1009	qed_vf_pf_req_end(p_hwfn, rc);
1010
1011	return rc;
1012}
1013
1014static bool
1015qed_vf_handle_vp_update_is_needed(struct qed_hwfn *p_hwfn,
1016				  struct qed_sp_vport_update_params *p_data,
1017				  u16 tlv)
1018{
1019	switch (tlv) {
1020	case CHANNEL_TLV_VPORT_UPDATE_ACTIVATE:
1021		return !!(p_data->update_vport_active_rx_flg ||
1022			  p_data->update_vport_active_tx_flg);
1023	case CHANNEL_TLV_VPORT_UPDATE_TX_SWITCH:
1024		return !!p_data->update_tx_switching_flg;
1025	case CHANNEL_TLV_VPORT_UPDATE_VLAN_STRIP:
1026		return !!p_data->update_inner_vlan_removal_flg;
1027	case CHANNEL_TLV_VPORT_UPDATE_ACCEPT_ANY_VLAN:
1028		return !!p_data->update_accept_any_vlan_flg;
1029	case CHANNEL_TLV_VPORT_UPDATE_MCAST:
1030		return !!p_data->update_approx_mcast_flg;
1031	case CHANNEL_TLV_VPORT_UPDATE_ACCEPT_PARAM:
1032		return !!(p_data->accept_flags.update_rx_mode_config ||
1033			  p_data->accept_flags.update_tx_mode_config);
1034	case CHANNEL_TLV_VPORT_UPDATE_RSS:
1035		return !!p_data->rss_params;
1036	case CHANNEL_TLV_VPORT_UPDATE_SGE_TPA:
1037		return !!p_data->sge_tpa_params;
1038	default:
1039		DP_INFO(p_hwfn, "Unexpected vport-update TLV[%d]\n",
1040			tlv);
1041		return false;
1042	}
1043}
1044
1045static void
1046qed_vf_handle_vp_update_tlvs_resp(struct qed_hwfn *p_hwfn,
1047				  struct qed_sp_vport_update_params *p_data)
1048{
1049	struct qed_vf_iov *p_iov = p_hwfn->vf_iov_info;
1050	struct pfvf_def_resp_tlv *p_resp;
1051	u16 tlv;
1052
1053	for (tlv = CHANNEL_TLV_VPORT_UPDATE_ACTIVATE;
1054	     tlv < CHANNEL_TLV_VPORT_UPDATE_MAX; tlv++) {
1055		if (!qed_vf_handle_vp_update_is_needed(p_hwfn, p_data, tlv))
1056			continue;
1057
1058		p_resp = (struct pfvf_def_resp_tlv *)
1059			 qed_iov_search_list_tlvs(p_hwfn, p_iov->pf2vf_reply,
1060						  tlv);
1061		if (p_resp && p_resp->hdr.status)
1062			DP_VERBOSE(p_hwfn, QED_MSG_IOV,
1063				   "TLV[%d] Configuration %s\n",
1064				   tlv,
1065				   (p_resp && p_resp->hdr.status) ? "succeeded"
1066								  : "failed");
1067	}
1068}
1069
1070int qed_vf_pf_vport_update(struct qed_hwfn *p_hwfn,
1071			   struct qed_sp_vport_update_params *p_params)
1072{
1073	struct qed_vf_iov *p_iov = p_hwfn->vf_iov_info;
1074	struct vfpf_vport_update_tlv *req;
1075	struct pfvf_def_resp_tlv *resp;
1076	u8 update_rx, update_tx;
1077	u32 resp_size = 0;
1078	u16 size, tlv;
1079	int rc;
1080
1081	resp = &p_iov->pf2vf_reply->default_resp;
1082	resp_size = sizeof(*resp);
1083
1084	update_rx = p_params->update_vport_active_rx_flg;
1085	update_tx = p_params->update_vport_active_tx_flg;
1086
1087	/* clear mailbox and prep header tlv */
1088	qed_vf_pf_prep(p_hwfn, CHANNEL_TLV_VPORT_UPDATE, sizeof(*req));
1089
1090	/* Prepare extended tlvs */
1091	if (update_rx || update_tx) {
1092		struct vfpf_vport_update_activate_tlv *p_act_tlv;
1093
1094		size = sizeof(struct vfpf_vport_update_activate_tlv);
1095		p_act_tlv = qed_add_tlv(p_hwfn, &p_iov->offset,
1096					CHANNEL_TLV_VPORT_UPDATE_ACTIVATE,
1097					size);
1098		resp_size += sizeof(struct pfvf_def_resp_tlv);
1099
1100		if (update_rx) {
1101			p_act_tlv->update_rx = update_rx;
1102			p_act_tlv->active_rx = p_params->vport_active_rx_flg;
1103		}
1104
1105		if (update_tx) {
1106			p_act_tlv->update_tx = update_tx;
1107			p_act_tlv->active_tx = p_params->vport_active_tx_flg;
1108		}
1109	}
1110
1111	if (p_params->update_tx_switching_flg) {
1112		struct vfpf_vport_update_tx_switch_tlv *p_tx_switch_tlv;
1113
1114		size = sizeof(struct vfpf_vport_update_tx_switch_tlv);
1115		tlv = CHANNEL_TLV_VPORT_UPDATE_TX_SWITCH;
1116		p_tx_switch_tlv = qed_add_tlv(p_hwfn, &p_iov->offset,
1117					      tlv, size);
1118		resp_size += sizeof(struct pfvf_def_resp_tlv);
1119
1120		p_tx_switch_tlv->tx_switching = p_params->tx_switching_flg;
1121	}
1122
1123	if (p_params->update_approx_mcast_flg) {
1124		struct vfpf_vport_update_mcast_bin_tlv *p_mcast_tlv;
1125
1126		size = sizeof(struct vfpf_vport_update_mcast_bin_tlv);
1127		p_mcast_tlv = qed_add_tlv(p_hwfn, &p_iov->offset,
1128					  CHANNEL_TLV_VPORT_UPDATE_MCAST, size);
1129		resp_size += sizeof(struct pfvf_def_resp_tlv);
1130
1131		memcpy(p_mcast_tlv->bins, p_params->bins,
1132		       sizeof(u32) * ETH_MULTICAST_MAC_BINS_IN_REGS);
1133	}
1134
1135	update_rx = p_params->accept_flags.update_rx_mode_config;
1136	update_tx = p_params->accept_flags.update_tx_mode_config;
1137
1138	if (update_rx || update_tx) {
1139		struct vfpf_vport_update_accept_param_tlv *p_accept_tlv;
1140
1141		tlv = CHANNEL_TLV_VPORT_UPDATE_ACCEPT_PARAM;
1142		size = sizeof(struct vfpf_vport_update_accept_param_tlv);
1143		p_accept_tlv = qed_add_tlv(p_hwfn, &p_iov->offset, tlv, size);
1144		resp_size += sizeof(struct pfvf_def_resp_tlv);
1145
1146		if (update_rx) {
1147			p_accept_tlv->update_rx_mode = update_rx;
1148			p_accept_tlv->rx_accept_filter =
1149			    p_params->accept_flags.rx_accept_filter;
1150		}
1151
1152		if (update_tx) {
1153			p_accept_tlv->update_tx_mode = update_tx;
1154			p_accept_tlv->tx_accept_filter =
1155			    p_params->accept_flags.tx_accept_filter;
1156		}
1157	}
1158
1159	if (p_params->rss_params) {
1160		struct qed_rss_params *rss_params = p_params->rss_params;
1161		struct vfpf_vport_update_rss_tlv *p_rss_tlv;
1162		int i, table_size;
1163
1164		size = sizeof(struct vfpf_vport_update_rss_tlv);
1165		p_rss_tlv = qed_add_tlv(p_hwfn,
1166					&p_iov->offset,
1167					CHANNEL_TLV_VPORT_UPDATE_RSS, size);
1168		resp_size += sizeof(struct pfvf_def_resp_tlv);
1169
1170		if (rss_params->update_rss_config)
1171			p_rss_tlv->update_rss_flags |=
1172			    VFPF_UPDATE_RSS_CONFIG_FLAG;
1173		if (rss_params->update_rss_capabilities)
1174			p_rss_tlv->update_rss_flags |=
1175			    VFPF_UPDATE_RSS_CAPS_FLAG;
1176		if (rss_params->update_rss_ind_table)
1177			p_rss_tlv->update_rss_flags |=
1178			    VFPF_UPDATE_RSS_IND_TABLE_FLAG;
1179		if (rss_params->update_rss_key)
1180			p_rss_tlv->update_rss_flags |= VFPF_UPDATE_RSS_KEY_FLAG;
1181
1182		p_rss_tlv->rss_enable = rss_params->rss_enable;
1183		p_rss_tlv->rss_caps = rss_params->rss_caps;
1184		p_rss_tlv->rss_table_size_log = rss_params->rss_table_size_log;
1185
1186		table_size = min_t(int, T_ETH_INDIRECTION_TABLE_SIZE,
1187				   1 << p_rss_tlv->rss_table_size_log);
1188		for (i = 0; i < table_size; i++) {
1189			struct qed_queue_cid *p_queue;
1190
1191			p_queue = rss_params->rss_ind_table[i];
1192			p_rss_tlv->rss_ind_table[i] = p_queue->rel.queue_id;
1193		}
1194		memcpy(p_rss_tlv->rss_key, rss_params->rss_key,
1195		       sizeof(rss_params->rss_key));
1196	}
1197
1198	if (p_params->update_accept_any_vlan_flg) {
1199		struct vfpf_vport_update_accept_any_vlan_tlv *p_any_vlan_tlv;
1200
1201		size = sizeof(struct vfpf_vport_update_accept_any_vlan_tlv);
1202		tlv = CHANNEL_TLV_VPORT_UPDATE_ACCEPT_ANY_VLAN;
1203		p_any_vlan_tlv = qed_add_tlv(p_hwfn, &p_iov->offset, tlv, size);
1204
1205		resp_size += sizeof(struct pfvf_def_resp_tlv);
1206		p_any_vlan_tlv->accept_any_vlan = p_params->accept_any_vlan;
1207		p_any_vlan_tlv->update_accept_any_vlan_flg =
1208		    p_params->update_accept_any_vlan_flg;
1209	}
1210
1211	/* add list termination tlv */
1212	qed_add_tlv(p_hwfn, &p_iov->offset,
1213		    CHANNEL_TLV_LIST_END, sizeof(struct channel_list_end_tlv));
1214
1215	rc = qed_send_msg2pf(p_hwfn, &resp->hdr.status, resp_size);
1216	if (rc)
1217		goto exit;
1218
1219	if (resp->hdr.status != PFVF_STATUS_SUCCESS) {
1220		rc = -EINVAL;
1221		goto exit;
1222	}
1223
1224	qed_vf_handle_vp_update_tlvs_resp(p_hwfn, p_params);
1225
1226exit:
1227	qed_vf_pf_req_end(p_hwfn, rc);
1228
1229	return rc;
1230}
1231
1232int qed_vf_pf_reset(struct qed_hwfn *p_hwfn)
1233{
1234	struct qed_vf_iov *p_iov = p_hwfn->vf_iov_info;
1235	struct pfvf_def_resp_tlv *resp;
1236	struct vfpf_first_tlv *req;
1237	int rc;
1238
1239	/* clear mailbox and prep first tlv */
1240	req = qed_vf_pf_prep(p_hwfn, CHANNEL_TLV_CLOSE, sizeof(*req));
1241
1242	/* add list termination tlv */
1243	qed_add_tlv(p_hwfn, &p_iov->offset,
1244		    CHANNEL_TLV_LIST_END, sizeof(struct channel_list_end_tlv));
1245
1246	resp = &p_iov->pf2vf_reply->default_resp;
1247	rc = qed_send_msg2pf(p_hwfn, &resp->hdr.status, sizeof(*resp));
1248	if (rc)
1249		goto exit;
1250
1251	if (resp->hdr.status != PFVF_STATUS_SUCCESS) {
1252		rc = -EAGAIN;
1253		goto exit;
1254	}
1255
1256	p_hwfn->b_int_enabled = 0;
1257
1258exit:
1259	qed_vf_pf_req_end(p_hwfn, rc);
1260
1261	return rc;
1262}
1263
1264void qed_vf_pf_filter_mcast(struct qed_hwfn *p_hwfn,
1265			    struct qed_filter_mcast *p_filter_cmd)
1266{
1267	struct qed_sp_vport_update_params sp_params;
1268	int i;
1269
1270	memset(&sp_params, 0, sizeof(sp_params));
1271	sp_params.update_approx_mcast_flg = 1;
1272
1273	if (p_filter_cmd->opcode == QED_FILTER_ADD) {
1274		for (i = 0; i < p_filter_cmd->num_mc_addrs; i++) {
1275			u32 bit;
1276
1277			bit = qed_mcast_bin_from_mac(p_filter_cmd->mac[i]);
1278			sp_params.bins[bit / 32] |= 1 << (bit % 32);
1279		}
1280	}
1281
1282	qed_vf_pf_vport_update(p_hwfn, &sp_params);
1283}
1284
1285int qed_vf_pf_filter_ucast(struct qed_hwfn *p_hwfn,
1286			   struct qed_filter_ucast *p_ucast)
1287{
1288	struct qed_vf_iov *p_iov = p_hwfn->vf_iov_info;
1289	struct vfpf_ucast_filter_tlv *req;
1290	struct pfvf_def_resp_tlv *resp;
1291	int rc;
1292
1293	/* clear mailbox and prep first tlv */
1294	req = qed_vf_pf_prep(p_hwfn, CHANNEL_TLV_UCAST_FILTER, sizeof(*req));
1295	req->opcode = (u8) p_ucast->opcode;
1296	req->type = (u8) p_ucast->type;
1297	memcpy(req->mac, p_ucast->mac, ETH_ALEN);
1298	req->vlan = p_ucast->vlan;
1299
1300	/* add list termination tlv */
1301	qed_add_tlv(p_hwfn, &p_iov->offset,
1302		    CHANNEL_TLV_LIST_END, sizeof(struct channel_list_end_tlv));
1303
1304	resp = &p_iov->pf2vf_reply->default_resp;
1305	rc = qed_send_msg2pf(p_hwfn, &resp->hdr.status, sizeof(*resp));
1306	if (rc)
1307		goto exit;
1308
1309	if (resp->hdr.status != PFVF_STATUS_SUCCESS) {
1310		rc = -EAGAIN;
1311		goto exit;
1312	}
1313
1314exit:
1315	qed_vf_pf_req_end(p_hwfn, rc);
1316
1317	return rc;
1318}
1319
1320int qed_vf_pf_int_cleanup(struct qed_hwfn *p_hwfn)
1321{
1322	struct qed_vf_iov *p_iov = p_hwfn->vf_iov_info;
1323	struct pfvf_def_resp_tlv *resp = &p_iov->pf2vf_reply->default_resp;
1324	int rc;
1325
1326	/* clear mailbox and prep first tlv */
1327	qed_vf_pf_prep(p_hwfn, CHANNEL_TLV_INT_CLEANUP,
1328		       sizeof(struct vfpf_first_tlv));
1329
1330	/* add list termination tlv */
1331	qed_add_tlv(p_hwfn, &p_iov->offset,
1332		    CHANNEL_TLV_LIST_END, sizeof(struct channel_list_end_tlv));
1333
1334	rc = qed_send_msg2pf(p_hwfn, &resp->hdr.status, sizeof(*resp));
1335	if (rc)
1336		goto exit;
1337
1338	if (resp->hdr.status != PFVF_STATUS_SUCCESS) {
1339		rc = -EINVAL;
1340		goto exit;
1341	}
1342
1343exit:
1344	qed_vf_pf_req_end(p_hwfn, rc);
1345
1346	return rc;
1347}
1348
1349int qed_vf_pf_get_coalesce(struct qed_hwfn *p_hwfn,
1350			   u16 *p_coal, struct qed_queue_cid *p_cid)
1351{
1352	struct qed_vf_iov *p_iov = p_hwfn->vf_iov_info;
1353	struct pfvf_read_coal_resp_tlv *resp;
1354	struct vfpf_read_coal_req_tlv *req;
1355	int rc;
1356
1357	/* clear mailbox and prep header tlv */
1358	req = qed_vf_pf_prep(p_hwfn, CHANNEL_TLV_COALESCE_READ, sizeof(*req));
1359	req->qid = p_cid->rel.queue_id;
1360	req->is_rx = p_cid->b_is_rx ? 1 : 0;
1361
1362	qed_add_tlv(p_hwfn, &p_iov->offset, CHANNEL_TLV_LIST_END,
1363		    sizeof(struct channel_list_end_tlv));
1364	resp = &p_iov->pf2vf_reply->read_coal_resp;
1365
1366	rc = qed_send_msg2pf(p_hwfn, &resp->hdr.status, sizeof(*resp));
1367	if (rc)
1368		goto exit;
1369
1370	if (resp->hdr.status != PFVF_STATUS_SUCCESS)
1371		goto exit;
1372
1373	*p_coal = resp->coal;
1374exit:
1375	qed_vf_pf_req_end(p_hwfn, rc);
1376
1377	return rc;
1378}
1379
1380int
1381qed_vf_pf_bulletin_update_mac(struct qed_hwfn *p_hwfn,
1382			      u8 *p_mac)
1383{
1384	struct qed_vf_iov *p_iov = p_hwfn->vf_iov_info;
1385	struct vfpf_bulletin_update_mac_tlv *p_req;
1386	struct pfvf_def_resp_tlv *p_resp;
1387	int rc;
1388
1389	if (!p_mac)
1390		return -EINVAL;
1391
1392	/* clear mailbox and prep header tlv */
1393	p_req = qed_vf_pf_prep(p_hwfn, CHANNEL_TLV_BULLETIN_UPDATE_MAC,
1394			       sizeof(*p_req));
1395	ether_addr_copy(p_req->mac, p_mac);
1396	DP_VERBOSE(p_hwfn, QED_MSG_IOV,
1397		   "Requesting bulletin update for MAC[%pM]\n", p_mac);
1398
1399	/* add list termination tlv */
1400	qed_add_tlv(p_hwfn, &p_iov->offset, CHANNEL_TLV_LIST_END,
1401		    sizeof(struct channel_list_end_tlv));
1402
1403	p_resp = &p_iov->pf2vf_reply->default_resp;
1404	rc = qed_send_msg2pf(p_hwfn, &p_resp->hdr.status, sizeof(*p_resp));
1405	qed_vf_pf_req_end(p_hwfn, rc);
1406	return rc;
1407}
1408
1409int
1410qed_vf_pf_set_coalesce(struct qed_hwfn *p_hwfn,
1411		       u16 rx_coal, u16 tx_coal, struct qed_queue_cid *p_cid)
1412{
1413	struct qed_vf_iov *p_iov = p_hwfn->vf_iov_info;
1414	struct vfpf_update_coalesce *req;
1415	struct pfvf_def_resp_tlv *resp;
1416	int rc;
1417
1418	/* clear mailbox and prep header tlv */
1419	req = qed_vf_pf_prep(p_hwfn, CHANNEL_TLV_COALESCE_UPDATE, sizeof(*req));
1420
1421	req->rx_coal = rx_coal;
1422	req->tx_coal = tx_coal;
1423	req->qid = p_cid->rel.queue_id;
1424
1425	DP_VERBOSE(p_hwfn,
1426		   QED_MSG_IOV,
1427		   "Setting coalesce rx_coal = %d, tx_coal = %d at queue = %d\n",
1428		   rx_coal, tx_coal, req->qid);
1429
1430	/* add list termination tlv */
1431	qed_add_tlv(p_hwfn, &p_iov->offset, CHANNEL_TLV_LIST_END,
1432		    sizeof(struct channel_list_end_tlv));
1433
1434	resp = &p_iov->pf2vf_reply->default_resp;
1435	rc = qed_send_msg2pf(p_hwfn, &resp->hdr.status, sizeof(*resp));
1436	if (rc)
1437		goto exit;
1438
1439	if (resp->hdr.status != PFVF_STATUS_SUCCESS)
1440		goto exit;
1441
1442	if (rx_coal)
1443		p_hwfn->cdev->rx_coalesce_usecs = rx_coal;
1444
1445	if (tx_coal)
1446		p_hwfn->cdev->tx_coalesce_usecs = tx_coal;
1447
1448exit:
1449	qed_vf_pf_req_end(p_hwfn, rc);
1450	return rc;
1451}
1452
1453u16 qed_vf_get_igu_sb_id(struct qed_hwfn *p_hwfn, u16 sb_id)
1454{
1455	struct qed_vf_iov *p_iov = p_hwfn->vf_iov_info;
1456
1457	if (!p_iov) {
1458		DP_NOTICE(p_hwfn, "vf_sriov_info isn't initialized\n");
1459		return 0;
1460	}
1461
1462	return p_iov->acquire_resp.resc.hw_sbs[sb_id].hw_sb_id;
1463}
1464
1465void qed_vf_set_sb_info(struct qed_hwfn *p_hwfn,
1466			u16 sb_id, struct qed_sb_info *p_sb)
1467{
1468	struct qed_vf_iov *p_iov = p_hwfn->vf_iov_info;
1469
1470	if (!p_iov) {
1471		DP_NOTICE(p_hwfn, "vf_sriov_info isn't initialized\n");
1472		return;
1473	}
1474
1475	if (sb_id >= PFVF_MAX_SBS_PER_VF) {
1476		DP_NOTICE(p_hwfn, "Can't configure SB %04x\n", sb_id);
1477		return;
1478	}
1479
1480	p_iov->sbs_info[sb_id] = p_sb;
1481}
1482
1483int qed_vf_read_bulletin(struct qed_hwfn *p_hwfn, u8 *p_change)
1484{
1485	struct qed_vf_iov *p_iov = p_hwfn->vf_iov_info;
1486	struct qed_bulletin_content shadow;
1487	u32 crc, crc_size;
1488
1489	crc_size = sizeof(p_iov->bulletin.p_virt->crc);
1490	*p_change = 0;
1491
1492	/* Need to guarantee PF is not in the middle of writing it */
1493	memcpy(&shadow, p_iov->bulletin.p_virt, p_iov->bulletin.size);
1494
1495	/* If version did not update, no need to do anything */
1496	if (shadow.version == p_iov->bulletin_shadow.version)
1497		return 0;
1498
1499	/* Verify the bulletin we see is valid */
1500	crc = crc32(0, (u8 *)&shadow + crc_size,
1501		    p_iov->bulletin.size - crc_size);
1502	if (crc != shadow.crc)
1503		return -EAGAIN;
1504
1505	/* Set the shadow bulletin and process it */
1506	memcpy(&p_iov->bulletin_shadow, &shadow, p_iov->bulletin.size);
1507
1508	DP_VERBOSE(p_hwfn, QED_MSG_IOV,
1509		   "Read a bulletin update %08x\n", shadow.version);
1510
1511	*p_change = 1;
1512
1513	return 0;
1514}
1515
1516void __qed_vf_get_link_params(struct qed_hwfn *p_hwfn,
1517			      struct qed_mcp_link_params *p_params,
1518			      struct qed_bulletin_content *p_bulletin)
1519{
1520	memset(p_params, 0, sizeof(*p_params));
1521
1522	p_params->speed.autoneg = p_bulletin->req_autoneg;
1523	p_params->speed.advertised_speeds = p_bulletin->req_adv_speed;
1524	p_params->speed.forced_speed = p_bulletin->req_forced_speed;
1525	p_params->pause.autoneg = p_bulletin->req_autoneg_pause;
1526	p_params->pause.forced_rx = p_bulletin->req_forced_rx;
1527	p_params->pause.forced_tx = p_bulletin->req_forced_tx;
1528	p_params->loopback_mode = p_bulletin->req_loopback;
1529}
1530
1531void qed_vf_get_link_params(struct qed_hwfn *p_hwfn,
1532			    struct qed_mcp_link_params *params)
1533{
1534	__qed_vf_get_link_params(p_hwfn, params,
1535				 &(p_hwfn->vf_iov_info->bulletin_shadow));
1536}
1537
1538void __qed_vf_get_link_state(struct qed_hwfn *p_hwfn,
1539			     struct qed_mcp_link_state *p_link,
1540			     struct qed_bulletin_content *p_bulletin)
1541{
1542	memset(p_link, 0, sizeof(*p_link));
1543
1544	p_link->link_up = p_bulletin->link_up;
1545	p_link->speed = p_bulletin->speed;
1546	p_link->full_duplex = p_bulletin->full_duplex;
1547	p_link->an = p_bulletin->autoneg;
1548	p_link->an_complete = p_bulletin->autoneg_complete;
1549	p_link->parallel_detection = p_bulletin->parallel_detection;
1550	p_link->pfc_enabled = p_bulletin->pfc_enabled;
1551	p_link->partner_adv_speed = p_bulletin->partner_adv_speed;
1552	p_link->partner_tx_flow_ctrl_en = p_bulletin->partner_tx_flow_ctrl_en;
1553	p_link->partner_rx_flow_ctrl_en = p_bulletin->partner_rx_flow_ctrl_en;
1554	p_link->partner_adv_pause = p_bulletin->partner_adv_pause;
1555	p_link->sfp_tx_fault = p_bulletin->sfp_tx_fault;
1556}
1557
1558void qed_vf_get_link_state(struct qed_hwfn *p_hwfn,
1559			   struct qed_mcp_link_state *link)
1560{
1561	__qed_vf_get_link_state(p_hwfn, link,
1562				&(p_hwfn->vf_iov_info->bulletin_shadow));
1563}
1564
1565void __qed_vf_get_link_caps(struct qed_hwfn *p_hwfn,
1566			    struct qed_mcp_link_capabilities *p_link_caps,
1567			    struct qed_bulletin_content *p_bulletin)
1568{
1569	memset(p_link_caps, 0, sizeof(*p_link_caps));
1570	p_link_caps->speed_capabilities = p_bulletin->capability_speed;
1571}
1572
1573void qed_vf_get_link_caps(struct qed_hwfn *p_hwfn,
1574			  struct qed_mcp_link_capabilities *p_link_caps)
1575{
1576	__qed_vf_get_link_caps(p_hwfn, p_link_caps,
1577			       &(p_hwfn->vf_iov_info->bulletin_shadow));
1578}
1579
1580void qed_vf_get_num_rxqs(struct qed_hwfn *p_hwfn, u8 *num_rxqs)
1581{
1582	*num_rxqs = p_hwfn->vf_iov_info->acquire_resp.resc.num_rxqs;
1583}
1584
1585void qed_vf_get_num_txqs(struct qed_hwfn *p_hwfn, u8 *num_txqs)
1586{
1587	*num_txqs = p_hwfn->vf_iov_info->acquire_resp.resc.num_txqs;
1588}
1589
1590void qed_vf_get_num_cids(struct qed_hwfn *p_hwfn, u8 *num_cids)
1591{
1592	*num_cids = p_hwfn->vf_iov_info->acquire_resp.resc.num_cids;
1593}
1594
1595void qed_vf_get_port_mac(struct qed_hwfn *p_hwfn, u8 *port_mac)
1596{
1597	memcpy(port_mac,
1598	       p_hwfn->vf_iov_info->acquire_resp.pfdev_info.port_mac, ETH_ALEN);
1599}
1600
1601void qed_vf_get_num_vlan_filters(struct qed_hwfn *p_hwfn, u8 *num_vlan_filters)
1602{
1603	struct qed_vf_iov *p_vf;
1604
1605	p_vf = p_hwfn->vf_iov_info;
1606	*num_vlan_filters = p_vf->acquire_resp.resc.num_vlan_filters;
1607}
1608
1609void qed_vf_get_num_mac_filters(struct qed_hwfn *p_hwfn, u8 *num_mac_filters)
1610{
1611	struct qed_vf_iov *p_vf = p_hwfn->vf_iov_info;
1612
1613	*num_mac_filters = p_vf->acquire_resp.resc.num_mac_filters;
1614}
1615
1616bool qed_vf_check_mac(struct qed_hwfn *p_hwfn, u8 *mac)
1617{
1618	struct qed_bulletin_content *bulletin;
1619
1620	bulletin = &p_hwfn->vf_iov_info->bulletin_shadow;
1621	if (!(bulletin->valid_bitmap & (1 << MAC_ADDR_FORCED)))
1622		return true;
1623
1624	/* Forbid VF from changing a MAC enforced by PF */
1625	if (ether_addr_equal(bulletin->mac, mac))
1626		return false;
1627
1628	return false;
1629}
1630
1631static bool qed_vf_bulletin_get_forced_mac(struct qed_hwfn *hwfn,
1632					   u8 *dst_mac, u8 *p_is_forced)
1633{
1634	struct qed_bulletin_content *bulletin;
1635
1636	bulletin = &hwfn->vf_iov_info->bulletin_shadow;
1637
1638	if (bulletin->valid_bitmap & (1 << MAC_ADDR_FORCED)) {
1639		if (p_is_forced)
1640			*p_is_forced = 1;
1641	} else if (bulletin->valid_bitmap & (1 << VFPF_BULLETIN_MAC_ADDR)) {
1642		if (p_is_forced)
1643			*p_is_forced = 0;
1644	} else {
1645		return false;
1646	}
1647
1648	ether_addr_copy(dst_mac, bulletin->mac);
1649
1650	return true;
1651}
1652
1653static void
1654qed_vf_bulletin_get_udp_ports(struct qed_hwfn *p_hwfn,
1655			      u16 *p_vxlan_port, u16 *p_geneve_port)
1656{
1657	struct qed_bulletin_content *p_bulletin;
1658
1659	p_bulletin = &p_hwfn->vf_iov_info->bulletin_shadow;
1660
1661	*p_vxlan_port = p_bulletin->vxlan_udp_port;
1662	*p_geneve_port = p_bulletin->geneve_udp_port;
1663}
1664
1665void qed_vf_get_fw_version(struct qed_hwfn *p_hwfn,
1666			   u16 *fw_major, u16 *fw_minor,
1667			   u16 *fw_rev, u16 *fw_eng)
1668{
1669	struct pf_vf_pfdev_info *info;
1670
1671	info = &p_hwfn->vf_iov_info->acquire_resp.pfdev_info;
1672
1673	*fw_major = info->fw_major;
1674	*fw_minor = info->fw_minor;
1675	*fw_rev = info->fw_rev;
1676	*fw_eng = info->fw_eng;
1677}
1678
1679static void qed_handle_bulletin_change(struct qed_hwfn *hwfn)
1680{
1681	struct qed_eth_cb_ops *ops = hwfn->cdev->protocol_ops.eth;
1682	u8 mac[ETH_ALEN], is_mac_exist, is_mac_forced;
1683	void *cookie = hwfn->cdev->ops_cookie;
1684	u16 vxlan_port, geneve_port;
1685
1686	qed_vf_bulletin_get_udp_ports(hwfn, &vxlan_port, &geneve_port);
1687	is_mac_exist = qed_vf_bulletin_get_forced_mac(hwfn, mac,
1688						      &is_mac_forced);
1689	if (is_mac_exist && cookie)
1690		ops->force_mac(cookie, mac, !!is_mac_forced);
1691
1692	ops->ports_update(cookie, vxlan_port, geneve_port);
1693
1694	/* Always update link configuration according to bulletin */
1695	qed_link_update(hwfn, NULL);
1696}
1697
1698void qed_iov_vf_task(struct work_struct *work)
1699{
1700	struct qed_hwfn *hwfn = container_of(work, struct qed_hwfn,
1701					     iov_task.work);
1702	u8 change = 0;
1703
1704	if (test_and_clear_bit(QED_IOV_WQ_STOP_WQ_FLAG, &hwfn->iov_task_flags))
1705		return;
1706
1707	/* Handle bulletin board changes */
1708	qed_vf_read_bulletin(hwfn, &change);
1709	if (test_and_clear_bit(QED_IOV_WQ_VF_FORCE_LINK_QUERY_FLAG,
1710			       &hwfn->iov_task_flags))
1711		change = 1;
1712	if (change)
1713		qed_handle_bulletin_change(hwfn);
1714
1715	/* As VF is polling bulletin board, need to constantly re-schedule */
1716	queue_delayed_work(hwfn->iov_wq, &hwfn->iov_task, HZ);
1717}
1718