1 /* QLogic qed NIC Driver
2 * Copyright (c) 2015 QLogic Corporation
4 * This software is available under the terms of the GNU General Public License
5 * (GPL) Version 2, available from the file COPYING in the main directory of
9 #include <linux/crc32.h>
10 #include <linux/etherdevice.h>
12 #include "qed_sriov.h"
15 static void *qed_vf_pf_prep(struct qed_hwfn *p_hwfn, u16 type, u16 length)
17 struct qed_vf_iov *p_iov = p_hwfn->vf_iov_info;
20 /* This lock is released when we receive PF's response
21 * in qed_send_msg2pf().
22 * So, qed_vf_pf_prep() and qed_send_msg2pf()
23 * must come in sequence.
25 mutex_lock(&(p_iov->mutex));
29 "preparing to send 0x%04x tlv over vf pf channel\n",
32 /* Reset Requst offset */
33 p_iov->offset = (u8 *)p_iov->vf2pf_request;
35 /* Clear mailbox - both request and reply */
36 memset(p_iov->vf2pf_request, 0, sizeof(union vfpf_tlvs));
37 memset(p_iov->pf2vf_reply, 0, sizeof(union pfvf_tlvs));
39 /* Init type and length */
40 p_tlv = qed_add_tlv(p_hwfn, &p_iov->offset, type, length);
42 /* Init first tlv header */
43 ((struct vfpf_first_tlv *)p_tlv)->reply_address =
44 (u64)p_iov->pf2vf_reply_phys;
49 static void qed_vf_pf_req_end(struct qed_hwfn *p_hwfn, int req_status)
51 union pfvf_tlvs *resp = p_hwfn->vf_iov_info->pf2vf_reply;
53 DP_VERBOSE(p_hwfn, QED_MSG_IOV,
54 "VF request status = 0x%x, PF reply status = 0x%x\n",
55 req_status, resp->default_resp.hdr.status);
57 mutex_unlock(&(p_hwfn->vf_iov_info->mutex));
60 #define QED_VF_CHANNEL_USLEEP_ITERATIONS 90
61 #define QED_VF_CHANNEL_USLEEP_DELAY 100
62 #define QED_VF_CHANNEL_MSLEEP_ITERATIONS 10
63 #define QED_VF_CHANNEL_MSLEEP_DELAY 25
65 static int qed_send_msg2pf(struct qed_hwfn *p_hwfn, u8 *done, u32 resp_size)
67 union vfpf_tlvs *p_req = p_hwfn->vf_iov_info->vf2pf_request;
68 struct ustorm_trigger_vf_zone trigger;
69 struct ustorm_vf_zone *zone_data;
72 zone_data = (struct ustorm_vf_zone *)PXP_VF_BAR0_START_USDM_ZONE_B;
74 /* output tlvs list */
75 qed_dp_tlv_list(p_hwfn, p_req);
77 /* need to add the END TLV to the message size */
78 resp_size += sizeof(struct channel_list_end_tlv);
80 /* Send TLVs over HW channel */
81 memset(&trigger, 0, sizeof(struct ustorm_trigger_vf_zone));
82 trigger.vf_pf_msg_valid = 1;
86 "VF -> PF [%02x] message: [%08x, %08x] --> %p, %08x --> %p\n",
87 GET_FIELD(p_hwfn->hw_info.concrete_fid,
88 PXP_CONCRETE_FID_PFID),
89 upper_32_bits(p_hwfn->vf_iov_info->vf2pf_request_phys),
90 lower_32_bits(p_hwfn->vf_iov_info->vf2pf_request_phys),
91 &zone_data->non_trigger.vf_pf_msg_addr,
92 *((u32 *)&trigger), &zone_data->trigger);
95 (uintptr_t)&zone_data->non_trigger.vf_pf_msg_addr.lo,
96 lower_32_bits(p_hwfn->vf_iov_info->vf2pf_request_phys));
99 (uintptr_t)&zone_data->non_trigger.vf_pf_msg_addr.hi,
100 upper_32_bits(p_hwfn->vf_iov_info->vf2pf_request_phys));
102 /* The message data must be written first, to prevent trigger before
107 REG_WR(p_hwfn, (uintptr_t)&zone_data->trigger, *((u32 *)&trigger));
109 /* When PF would be done with the response, it would write back to the
110 * `done' address from a coherent DMA zone. Poll until then.
113 iter = QED_VF_CHANNEL_USLEEP_ITERATIONS;
114 while (!*done && iter--) {
115 udelay(QED_VF_CHANNEL_USLEEP_DELAY);
119 iter = QED_VF_CHANNEL_MSLEEP_ITERATIONS;
120 while (!*done && iter--) {
121 msleep(QED_VF_CHANNEL_MSLEEP_DELAY);
126 DP_VERBOSE(p_hwfn, QED_MSG_IOV,
127 "VF <-- PF Timeout [Type %d]\n",
128 p_req->first_tlv.tl.type);
131 DP_VERBOSE(p_hwfn, QED_MSG_IOV,
132 "PF response: %d [Type %d]\n",
133 *done, p_req->first_tlv.tl.type);
139 #define VF_ACQUIRE_THRESH 3
140 static void qed_vf_pf_acquire_reduce_resc(struct qed_hwfn *p_hwfn,
141 struct vf_pf_resc_request *p_req,
142 struct pf_vf_resc *p_resp)
146 "PF unwilling to fullill resource request: rxq [%02x/%02x] txq [%02x/%02x] sbs [%02x/%02x] mac [%02x/%02x] vlan [%02x/%02x] mc [%02x/%02x]. Try PF recommended amount\n",
153 p_req->num_mac_filters,
154 p_resp->num_mac_filters,
155 p_req->num_vlan_filters,
156 p_resp->num_vlan_filters,
157 p_req->num_mc_filters, p_resp->num_mc_filters);
159 /* humble our request */
160 p_req->num_txqs = p_resp->num_txqs;
161 p_req->num_rxqs = p_resp->num_rxqs;
162 p_req->num_sbs = p_resp->num_sbs;
163 p_req->num_mac_filters = p_resp->num_mac_filters;
164 p_req->num_vlan_filters = p_resp->num_vlan_filters;
165 p_req->num_mc_filters = p_resp->num_mc_filters;
168 static int qed_vf_pf_acquire(struct qed_hwfn *p_hwfn)
170 struct qed_vf_iov *p_iov = p_hwfn->vf_iov_info;
171 struct pfvf_acquire_resp_tlv *resp = &p_iov->pf2vf_reply->acquire_resp;
172 struct pf_vf_pfdev_info *pfdev_info = &resp->pfdev_info;
173 struct vf_pf_resc_request *p_resc;
174 u8 retry_cnt = VF_ACQUIRE_THRESH;
175 bool resources_acquired = false;
176 struct vfpf_acquire_tlv *req;
177 int rc = 0, attempts = 0;
179 /* clear mailbox and prep first tlv */
180 req = qed_vf_pf_prep(p_hwfn, CHANNEL_TLV_ACQUIRE, sizeof(*req));
181 p_resc = &req->resc_request;
183 /* starting filling the request */
184 req->vfdev_info.opaque_fid = p_hwfn->hw_info.opaque_fid;
186 p_resc->num_rxqs = QED_MAX_VF_CHAINS_PER_PF;
187 p_resc->num_txqs = QED_MAX_VF_CHAINS_PER_PF;
188 p_resc->num_sbs = QED_MAX_VF_CHAINS_PER_PF;
189 p_resc->num_mac_filters = QED_ETH_VF_NUM_MAC_FILTERS;
190 p_resc->num_vlan_filters = QED_ETH_VF_NUM_VLAN_FILTERS;
192 req->vfdev_info.os_type = VFPF_ACQUIRE_OS_LINUX;
193 req->vfdev_info.fw_major = FW_MAJOR_VERSION;
194 req->vfdev_info.fw_minor = FW_MINOR_VERSION;
195 req->vfdev_info.fw_revision = FW_REVISION_VERSION;
196 req->vfdev_info.fw_engineering = FW_ENGINEERING_VERSION;
197 req->vfdev_info.eth_fp_hsi_major = ETH_HSI_VER_MAJOR;
198 req->vfdev_info.eth_fp_hsi_minor = ETH_HSI_VER_MINOR;
200 /* Fill capability field with any non-deprecated config we support */
201 req->vfdev_info.capabilities |= VFPF_ACQUIRE_CAP_100G;
203 /* pf 2 vf bulletin board address */
204 req->bulletin_addr = p_iov->bulletin.phys;
205 req->bulletin_size = p_iov->bulletin.size;
207 /* add list termination tlv */
208 qed_add_tlv(p_hwfn, &p_iov->offset,
209 CHANNEL_TLV_LIST_END, sizeof(struct channel_list_end_tlv));
211 while (!resources_acquired) {
213 QED_MSG_IOV, "attempting to acquire resources\n");
215 /* Clear response buffer, as this might be a re-send */
216 memset(p_iov->pf2vf_reply, 0, sizeof(union pfvf_tlvs));
218 /* send acquire request */
219 rc = qed_send_msg2pf(p_hwfn, &resp->hdr.status, sizeof(*resp));
221 /* Re-try acquire in case of vf-pf hw channel timeout */
222 if (retry_cnt && rc == -EBUSY) {
223 DP_VERBOSE(p_hwfn, QED_MSG_IOV,
224 "VF retrying to acquire due to VPC timeout\n");
232 /* copy acquire response from buffer to p_hwfn */
233 memcpy(&p_iov->acquire_resp, resp, sizeof(p_iov->acquire_resp));
237 if (resp->hdr.status == PFVF_STATUS_SUCCESS) {
238 /* PF agrees to allocate our resources */
239 if (!(resp->pfdev_info.capabilities &
240 PFVF_ACQUIRE_CAP_POST_FW_OVERRIDE)) {
241 /* It's possible legacy PF mistakenly accepted;
242 * but we don't care - simply mark it as
243 * legacy and continue.
245 req->vfdev_info.capabilities |=
246 VFPF_ACQUIRE_CAP_PRE_FP_HSI;
248 DP_VERBOSE(p_hwfn, QED_MSG_IOV, "resources acquired\n");
249 resources_acquired = true;
250 } else if (resp->hdr.status == PFVF_STATUS_NO_RESOURCE &&
251 attempts < VF_ACQUIRE_THRESH) {
252 qed_vf_pf_acquire_reduce_resc(p_hwfn, p_resc,
254 } else if (resp->hdr.status == PFVF_STATUS_NOT_SUPPORTED) {
255 if (pfdev_info->major_fp_hsi &&
256 (pfdev_info->major_fp_hsi != ETH_HSI_VER_MAJOR)) {
258 "PF uses an incompatible fastpath HSI %02x.%02x [VF requires %02x.%02x]. Please change to a VF driver using %02x.xx.\n",
259 pfdev_info->major_fp_hsi,
260 pfdev_info->minor_fp_hsi,
263 pfdev_info->major_fp_hsi);
268 if (!pfdev_info->major_fp_hsi) {
269 if (req->vfdev_info.capabilities &
270 VFPF_ACQUIRE_CAP_PRE_FP_HSI) {
272 "PF uses very old drivers. Please change to a VF driver using no later than 8.8.x.x.\n");
277 "PF is old - try re-acquire to see if it supports FW-version override\n");
278 req->vfdev_info.capabilities |=
279 VFPF_ACQUIRE_CAP_PRE_FP_HSI;
284 /* If PF/VF are using same Major, PF must have had
285 * it's reasons. Simply fail.
287 DP_NOTICE(p_hwfn, "PF rejected acquisition by VF\n");
292 "PF returned error %d to VF acquisition request\n",
299 /* Mark the PF as legacy, if needed */
300 if (req->vfdev_info.capabilities & VFPF_ACQUIRE_CAP_PRE_FP_HSI)
301 p_iov->b_pre_fp_hsi = true;
303 /* Update bulletin board size with response from PF */
304 p_iov->bulletin.size = resp->bulletin_size;
307 p_hwfn->cdev->type = resp->pfdev_info.dev_type;
308 p_hwfn->cdev->chip_rev = resp->pfdev_info.chip_rev;
310 p_hwfn->cdev->chip_num = pfdev_info->chip_num & 0xffff;
312 /* Learn of the possibility of CMT */
313 if (IS_LEAD_HWFN(p_hwfn)) {
314 if (resp->pfdev_info.capabilities & PFVF_ACQUIRE_CAP_100G) {
315 DP_NOTICE(p_hwfn, "100g VF\n");
316 p_hwfn->cdev->num_hwfns = 2;
320 if (!p_iov->b_pre_fp_hsi &&
321 (resp->pfdev_info.minor_fp_hsi < ETH_HSI_VER_MINOR)) {
323 "PF is using older fastpath HSI; %02x.%02x is configured\n",
324 ETH_HSI_VER_MAJOR, resp->pfdev_info.minor_fp_hsi);
328 qed_vf_pf_req_end(p_hwfn, rc);
333 int qed_vf_hw_prepare(struct qed_hwfn *p_hwfn)
335 struct qed_vf_iov *p_iov;
338 /* Set number of hwfns - might be overriden once leading hwfn learns
339 * actual configuration from PF.
341 if (IS_LEAD_HWFN(p_hwfn))
342 p_hwfn->cdev->num_hwfns = 1;
344 /* Set the doorbell bar. Assumption: regview is set */
345 p_hwfn->doorbells = (u8 __iomem *)p_hwfn->regview +
346 PXP_VF_BAR0_START_DQ;
348 reg = PXP_VF_BAR0_ME_OPAQUE_ADDRESS;
349 p_hwfn->hw_info.opaque_fid = (u16)REG_RD(p_hwfn, reg);
351 reg = PXP_VF_BAR0_ME_CONCRETE_ADDRESS;
352 p_hwfn->hw_info.concrete_fid = REG_RD(p_hwfn, reg);
354 /* Allocate vf sriov info */
355 p_iov = kzalloc(sizeof(*p_iov), GFP_KERNEL);
359 /* Allocate vf2pf msg */
360 p_iov->vf2pf_request = dma_alloc_coherent(&p_hwfn->cdev->pdev->dev,
361 sizeof(union vfpf_tlvs),
362 &p_iov->vf2pf_request_phys,
364 if (!p_iov->vf2pf_request)
367 p_iov->pf2vf_reply = dma_alloc_coherent(&p_hwfn->cdev->pdev->dev,
368 sizeof(union pfvf_tlvs),
369 &p_iov->pf2vf_reply_phys,
371 if (!p_iov->pf2vf_reply)
372 goto free_vf2pf_request;
376 "VF's Request mailbox [%p virt 0x%llx phys], Response mailbox [%p virt 0x%llx phys]\n",
377 p_iov->vf2pf_request,
378 (u64) p_iov->vf2pf_request_phys,
379 p_iov->pf2vf_reply, (u64)p_iov->pf2vf_reply_phys);
381 /* Allocate Bulletin board */
382 p_iov->bulletin.size = sizeof(struct qed_bulletin_content);
383 p_iov->bulletin.p_virt = dma_alloc_coherent(&p_hwfn->cdev->pdev->dev,
384 p_iov->bulletin.size,
385 &p_iov->bulletin.phys,
387 if (!p_iov->bulletin.p_virt)
388 goto free_pf2vf_reply;
390 DP_VERBOSE(p_hwfn, QED_MSG_IOV,
391 "VF's bulletin Board [%p virt 0x%llx phys 0x%08x bytes]\n",
392 p_iov->bulletin.p_virt,
393 (u64)p_iov->bulletin.phys, p_iov->bulletin.size);
395 mutex_init(&p_iov->mutex);
397 p_hwfn->vf_iov_info = p_iov;
399 p_hwfn->hw_info.personality = QED_PCI_ETH;
401 return qed_vf_pf_acquire(p_hwfn);
404 dma_free_coherent(&p_hwfn->cdev->pdev->dev,
405 sizeof(union pfvf_tlvs),
406 p_iov->pf2vf_reply, p_iov->pf2vf_reply_phys);
408 dma_free_coherent(&p_hwfn->cdev->pdev->dev,
409 sizeof(union vfpf_tlvs),
410 p_iov->vf2pf_request, p_iov->vf2pf_request_phys);
416 #define TSTORM_QZONE_START PXP_VF_BAR0_START_SDM_ZONE_A
417 #define MSTORM_QZONE_START(dev) (TSTORM_QZONE_START + \
418 (TSTORM_QZONE_SIZE * NUM_OF_L2_QUEUES(dev)))
420 int qed_vf_pf_rxq_start(struct qed_hwfn *p_hwfn,
425 dma_addr_t bd_chain_phys_addr,
426 dma_addr_t cqe_pbl_addr,
427 u16 cqe_pbl_size, void __iomem **pp_prod)
429 struct qed_vf_iov *p_iov = p_hwfn->vf_iov_info;
430 struct pfvf_start_queue_resp_tlv *resp;
431 struct vfpf_start_rxq_tlv *req;
434 /* clear mailbox and prep first tlv */
435 req = qed_vf_pf_prep(p_hwfn, CHANNEL_TLV_START_RXQ, sizeof(*req));
437 req->rx_qid = rx_qid;
438 req->cqe_pbl_addr = cqe_pbl_addr;
439 req->cqe_pbl_size = cqe_pbl_size;
440 req->rxq_addr = bd_chain_phys_addr;
442 req->sb_index = sb_index;
443 req->bd_max_bytes = bd_max_bytes;
446 /* If PF is legacy, we'll need to calculate producers ourselves
447 * as well as clean them.
449 if (pp_prod && p_iov->b_pre_fp_hsi) {
450 u8 hw_qid = p_iov->acquire_resp.resc.hw_qid[rx_qid];
451 u32 init_prod_val = 0;
453 *pp_prod = (u8 __iomem *)p_hwfn->regview +
454 MSTORM_QZONE_START(p_hwfn->cdev) +
455 hw_qid * MSTORM_QZONE_SIZE;
457 /* Init the rcq, rx bd and rx sge (if valid) producers to 0 */
458 __internal_ram_wr(p_hwfn, *pp_prod, sizeof(u32),
459 (u32 *)(&init_prod_val));
461 /* add list termination tlv */
462 qed_add_tlv(p_hwfn, &p_iov->offset,
463 CHANNEL_TLV_LIST_END, sizeof(struct channel_list_end_tlv));
465 resp = &p_iov->pf2vf_reply->queue_start;
466 rc = qed_send_msg2pf(p_hwfn, &resp->hdr.status, sizeof(*resp));
470 if (resp->hdr.status != PFVF_STATUS_SUCCESS) {
475 /* Learn the address of the producer from the response */
476 if (pp_prod && !p_iov->b_pre_fp_hsi) {
477 u32 init_prod_val = 0;
479 *pp_prod = (u8 __iomem *)p_hwfn->regview + resp->offset;
480 DP_VERBOSE(p_hwfn, QED_MSG_IOV,
481 "Rxq[0x%02x]: producer at %p [offset 0x%08x]\n",
482 rx_qid, *pp_prod, resp->offset);
484 /* Init the rcq, rx bd and rx sge (if valid) producers to 0 */
485 __internal_ram_wr(p_hwfn, *pp_prod, sizeof(u32),
486 (u32 *)&init_prod_val);
489 qed_vf_pf_req_end(p_hwfn, rc);
494 int qed_vf_pf_rxq_stop(struct qed_hwfn *p_hwfn, u16 rx_qid, bool cqe_completion)
496 struct qed_vf_iov *p_iov = p_hwfn->vf_iov_info;
497 struct vfpf_stop_rxqs_tlv *req;
498 struct pfvf_def_resp_tlv *resp;
501 /* clear mailbox and prep first tlv */
502 req = qed_vf_pf_prep(p_hwfn, CHANNEL_TLV_STOP_RXQS, sizeof(*req));
504 req->rx_qid = rx_qid;
506 req->cqe_completion = cqe_completion;
508 /* add list termination tlv */
509 qed_add_tlv(p_hwfn, &p_iov->offset,
510 CHANNEL_TLV_LIST_END, sizeof(struct channel_list_end_tlv));
512 resp = &p_iov->pf2vf_reply->default_resp;
513 rc = qed_send_msg2pf(p_hwfn, &resp->hdr.status, sizeof(*resp));
517 if (resp->hdr.status != PFVF_STATUS_SUCCESS) {
523 qed_vf_pf_req_end(p_hwfn, rc);
528 int qed_vf_pf_txq_start(struct qed_hwfn *p_hwfn,
533 u16 pbl_size, void __iomem **pp_doorbell)
535 struct qed_vf_iov *p_iov = p_hwfn->vf_iov_info;
536 struct pfvf_start_queue_resp_tlv *resp;
537 struct vfpf_start_txq_tlv *req;
540 /* clear mailbox and prep first tlv */
541 req = qed_vf_pf_prep(p_hwfn, CHANNEL_TLV_START_TXQ, sizeof(*req));
543 req->tx_qid = tx_queue_id;
546 req->pbl_addr = pbl_addr;
547 req->pbl_size = pbl_size;
549 req->sb_index = sb_index;
551 /* add list termination tlv */
552 qed_add_tlv(p_hwfn, &p_iov->offset,
553 CHANNEL_TLV_LIST_END, sizeof(struct channel_list_end_tlv));
555 resp = &p_iov->pf2vf_reply->queue_start;
556 rc = qed_send_msg2pf(p_hwfn, &resp->hdr.status, sizeof(*resp));
560 if (resp->hdr.status != PFVF_STATUS_SUCCESS) {
566 /* Modern PFs provide the actual offsets, while legacy
567 * provided only the queue id.
569 if (!p_iov->b_pre_fp_hsi) {
570 *pp_doorbell = (u8 __iomem *)p_hwfn->doorbells +
573 u8 cid = p_iov->acquire_resp.resc.cid[tx_queue_id];
576 db_addr = qed_db_addr_vf(cid, DQ_DEMS_LEGACY);
577 *pp_doorbell = (u8 __iomem *)p_hwfn->doorbells +
581 DP_VERBOSE(p_hwfn, QED_MSG_IOV,
582 "Txq[0x%02x]: doorbell at %p [offset 0x%08x]\n",
583 tx_queue_id, *pp_doorbell, resp->offset);
586 qed_vf_pf_req_end(p_hwfn, rc);
591 int qed_vf_pf_txq_stop(struct qed_hwfn *p_hwfn, u16 tx_qid)
593 struct qed_vf_iov *p_iov = p_hwfn->vf_iov_info;
594 struct vfpf_stop_txqs_tlv *req;
595 struct pfvf_def_resp_tlv *resp;
598 /* clear mailbox and prep first tlv */
599 req = qed_vf_pf_prep(p_hwfn, CHANNEL_TLV_STOP_TXQS, sizeof(*req));
601 req->tx_qid = tx_qid;
604 /* add list termination tlv */
605 qed_add_tlv(p_hwfn, &p_iov->offset,
606 CHANNEL_TLV_LIST_END, sizeof(struct channel_list_end_tlv));
608 resp = &p_iov->pf2vf_reply->default_resp;
609 rc = qed_send_msg2pf(p_hwfn, &resp->hdr.status, sizeof(*resp));
613 if (resp->hdr.status != PFVF_STATUS_SUCCESS) {
619 qed_vf_pf_req_end(p_hwfn, rc);
624 int qed_vf_pf_vport_start(struct qed_hwfn *p_hwfn,
627 u8 inner_vlan_removal,
628 enum qed_tpa_mode tpa_mode,
629 u8 max_buffers_per_cqe, u8 only_untagged)
631 struct qed_vf_iov *p_iov = p_hwfn->vf_iov_info;
632 struct vfpf_vport_start_tlv *req;
633 struct pfvf_def_resp_tlv *resp;
636 /* clear mailbox and prep first tlv */
637 req = qed_vf_pf_prep(p_hwfn, CHANNEL_TLV_VPORT_START, sizeof(*req));
640 req->vport_id = vport_id;
641 req->inner_vlan_removal = inner_vlan_removal;
642 req->tpa_mode = tpa_mode;
643 req->max_buffers_per_cqe = max_buffers_per_cqe;
644 req->only_untagged = only_untagged;
647 for (i = 0; i < p_hwfn->vf_iov_info->acquire_resp.resc.num_sbs; i++)
648 if (p_hwfn->sbs_info[i])
649 req->sb_addr[i] = p_hwfn->sbs_info[i]->sb_phys;
651 /* add list termination tlv */
652 qed_add_tlv(p_hwfn, &p_iov->offset,
653 CHANNEL_TLV_LIST_END, sizeof(struct channel_list_end_tlv));
655 resp = &p_iov->pf2vf_reply->default_resp;
656 rc = qed_send_msg2pf(p_hwfn, &resp->hdr.status, sizeof(*resp));
660 if (resp->hdr.status != PFVF_STATUS_SUCCESS) {
666 qed_vf_pf_req_end(p_hwfn, rc);
671 int qed_vf_pf_vport_stop(struct qed_hwfn *p_hwfn)
673 struct qed_vf_iov *p_iov = p_hwfn->vf_iov_info;
674 struct pfvf_def_resp_tlv *resp = &p_iov->pf2vf_reply->default_resp;
677 /* clear mailbox and prep first tlv */
678 qed_vf_pf_prep(p_hwfn, CHANNEL_TLV_VPORT_TEARDOWN,
679 sizeof(struct vfpf_first_tlv));
681 /* add list termination tlv */
682 qed_add_tlv(p_hwfn, &p_iov->offset,
683 CHANNEL_TLV_LIST_END, sizeof(struct channel_list_end_tlv));
685 rc = qed_send_msg2pf(p_hwfn, &resp->hdr.status, sizeof(*resp));
689 if (resp->hdr.status != PFVF_STATUS_SUCCESS) {
695 qed_vf_pf_req_end(p_hwfn, rc);
701 qed_vf_handle_vp_update_is_needed(struct qed_hwfn *p_hwfn,
702 struct qed_sp_vport_update_params *p_data,
706 case CHANNEL_TLV_VPORT_UPDATE_ACTIVATE:
707 return !!(p_data->update_vport_active_rx_flg ||
708 p_data->update_vport_active_tx_flg);
709 case CHANNEL_TLV_VPORT_UPDATE_TX_SWITCH:
710 return !!p_data->update_tx_switching_flg;
711 case CHANNEL_TLV_VPORT_UPDATE_VLAN_STRIP:
712 return !!p_data->update_inner_vlan_removal_flg;
713 case CHANNEL_TLV_VPORT_UPDATE_ACCEPT_ANY_VLAN:
714 return !!p_data->update_accept_any_vlan_flg;
715 case CHANNEL_TLV_VPORT_UPDATE_MCAST:
716 return !!p_data->update_approx_mcast_flg;
717 case CHANNEL_TLV_VPORT_UPDATE_ACCEPT_PARAM:
718 return !!(p_data->accept_flags.update_rx_mode_config ||
719 p_data->accept_flags.update_tx_mode_config);
720 case CHANNEL_TLV_VPORT_UPDATE_RSS:
721 return !!p_data->rss_params;
722 case CHANNEL_TLV_VPORT_UPDATE_SGE_TPA:
723 return !!p_data->sge_tpa_params;
725 DP_INFO(p_hwfn, "Unexpected vport-update TLV[%d]\n",
732 qed_vf_handle_vp_update_tlvs_resp(struct qed_hwfn *p_hwfn,
733 struct qed_sp_vport_update_params *p_data)
735 struct qed_vf_iov *p_iov = p_hwfn->vf_iov_info;
736 struct pfvf_def_resp_tlv *p_resp;
739 for (tlv = CHANNEL_TLV_VPORT_UPDATE_ACTIVATE;
740 tlv < CHANNEL_TLV_VPORT_UPDATE_MAX; tlv++) {
741 if (!qed_vf_handle_vp_update_is_needed(p_hwfn, p_data, tlv))
744 p_resp = (struct pfvf_def_resp_tlv *)
745 qed_iov_search_list_tlvs(p_hwfn, p_iov->pf2vf_reply,
747 if (p_resp && p_resp->hdr.status)
748 DP_VERBOSE(p_hwfn, QED_MSG_IOV,
749 "TLV[%d] Configuration %s\n",
751 (p_resp && p_resp->hdr.status) ? "succeeded"
756 int qed_vf_pf_vport_update(struct qed_hwfn *p_hwfn,
757 struct qed_sp_vport_update_params *p_params)
759 struct qed_vf_iov *p_iov = p_hwfn->vf_iov_info;
760 struct vfpf_vport_update_tlv *req;
761 struct pfvf_def_resp_tlv *resp;
762 u8 update_rx, update_tx;
767 resp = &p_iov->pf2vf_reply->default_resp;
768 resp_size = sizeof(*resp);
770 update_rx = p_params->update_vport_active_rx_flg;
771 update_tx = p_params->update_vport_active_tx_flg;
773 /* clear mailbox and prep header tlv */
774 qed_vf_pf_prep(p_hwfn, CHANNEL_TLV_VPORT_UPDATE, sizeof(*req));
776 /* Prepare extended tlvs */
777 if (update_rx || update_tx) {
778 struct vfpf_vport_update_activate_tlv *p_act_tlv;
780 size = sizeof(struct vfpf_vport_update_activate_tlv);
781 p_act_tlv = qed_add_tlv(p_hwfn, &p_iov->offset,
782 CHANNEL_TLV_VPORT_UPDATE_ACTIVATE,
784 resp_size += sizeof(struct pfvf_def_resp_tlv);
787 p_act_tlv->update_rx = update_rx;
788 p_act_tlv->active_rx = p_params->vport_active_rx_flg;
792 p_act_tlv->update_tx = update_tx;
793 p_act_tlv->active_tx = p_params->vport_active_tx_flg;
797 if (p_params->update_tx_switching_flg) {
798 struct vfpf_vport_update_tx_switch_tlv *p_tx_switch_tlv;
800 size = sizeof(struct vfpf_vport_update_tx_switch_tlv);
801 tlv = CHANNEL_TLV_VPORT_UPDATE_TX_SWITCH;
802 p_tx_switch_tlv = qed_add_tlv(p_hwfn, &p_iov->offset,
804 resp_size += sizeof(struct pfvf_def_resp_tlv);
806 p_tx_switch_tlv->tx_switching = p_params->tx_switching_flg;
809 if (p_params->update_approx_mcast_flg) {
810 struct vfpf_vport_update_mcast_bin_tlv *p_mcast_tlv;
812 size = sizeof(struct vfpf_vport_update_mcast_bin_tlv);
813 p_mcast_tlv = qed_add_tlv(p_hwfn, &p_iov->offset,
814 CHANNEL_TLV_VPORT_UPDATE_MCAST, size);
815 resp_size += sizeof(struct pfvf_def_resp_tlv);
817 memcpy(p_mcast_tlv->bins, p_params->bins,
818 sizeof(u32) * ETH_MULTICAST_MAC_BINS_IN_REGS);
821 update_rx = p_params->accept_flags.update_rx_mode_config;
822 update_tx = p_params->accept_flags.update_tx_mode_config;
824 if (update_rx || update_tx) {
825 struct vfpf_vport_update_accept_param_tlv *p_accept_tlv;
827 tlv = CHANNEL_TLV_VPORT_UPDATE_ACCEPT_PARAM;
828 size = sizeof(struct vfpf_vport_update_accept_param_tlv);
829 p_accept_tlv = qed_add_tlv(p_hwfn, &p_iov->offset, tlv, size);
830 resp_size += sizeof(struct pfvf_def_resp_tlv);
833 p_accept_tlv->update_rx_mode = update_rx;
834 p_accept_tlv->rx_accept_filter =
835 p_params->accept_flags.rx_accept_filter;
839 p_accept_tlv->update_tx_mode = update_tx;
840 p_accept_tlv->tx_accept_filter =
841 p_params->accept_flags.tx_accept_filter;
845 if (p_params->rss_params) {
846 struct qed_rss_params *rss_params = p_params->rss_params;
847 struct vfpf_vport_update_rss_tlv *p_rss_tlv;
849 size = sizeof(struct vfpf_vport_update_rss_tlv);
850 p_rss_tlv = qed_add_tlv(p_hwfn,
852 CHANNEL_TLV_VPORT_UPDATE_RSS, size);
853 resp_size += sizeof(struct pfvf_def_resp_tlv);
855 if (rss_params->update_rss_config)
856 p_rss_tlv->update_rss_flags |=
857 VFPF_UPDATE_RSS_CONFIG_FLAG;
858 if (rss_params->update_rss_capabilities)
859 p_rss_tlv->update_rss_flags |=
860 VFPF_UPDATE_RSS_CAPS_FLAG;
861 if (rss_params->update_rss_ind_table)
862 p_rss_tlv->update_rss_flags |=
863 VFPF_UPDATE_RSS_IND_TABLE_FLAG;
864 if (rss_params->update_rss_key)
865 p_rss_tlv->update_rss_flags |= VFPF_UPDATE_RSS_KEY_FLAG;
867 p_rss_tlv->rss_enable = rss_params->rss_enable;
868 p_rss_tlv->rss_caps = rss_params->rss_caps;
869 p_rss_tlv->rss_table_size_log = rss_params->rss_table_size_log;
870 memcpy(p_rss_tlv->rss_ind_table, rss_params->rss_ind_table,
871 sizeof(rss_params->rss_ind_table));
872 memcpy(p_rss_tlv->rss_key, rss_params->rss_key,
873 sizeof(rss_params->rss_key));
876 if (p_params->update_accept_any_vlan_flg) {
877 struct vfpf_vport_update_accept_any_vlan_tlv *p_any_vlan_tlv;
879 size = sizeof(struct vfpf_vport_update_accept_any_vlan_tlv);
880 tlv = CHANNEL_TLV_VPORT_UPDATE_ACCEPT_ANY_VLAN;
881 p_any_vlan_tlv = qed_add_tlv(p_hwfn, &p_iov->offset, tlv, size);
883 resp_size += sizeof(struct pfvf_def_resp_tlv);
884 p_any_vlan_tlv->accept_any_vlan = p_params->accept_any_vlan;
885 p_any_vlan_tlv->update_accept_any_vlan_flg =
886 p_params->update_accept_any_vlan_flg;
889 /* add list termination tlv */
890 qed_add_tlv(p_hwfn, &p_iov->offset,
891 CHANNEL_TLV_LIST_END, sizeof(struct channel_list_end_tlv));
893 rc = qed_send_msg2pf(p_hwfn, &resp->hdr.status, resp_size);
897 if (resp->hdr.status != PFVF_STATUS_SUCCESS) {
902 qed_vf_handle_vp_update_tlvs_resp(p_hwfn, p_params);
905 qed_vf_pf_req_end(p_hwfn, rc);
910 int qed_vf_pf_reset(struct qed_hwfn *p_hwfn)
912 struct qed_vf_iov *p_iov = p_hwfn->vf_iov_info;
913 struct pfvf_def_resp_tlv *resp;
914 struct vfpf_first_tlv *req;
917 /* clear mailbox and prep first tlv */
918 req = qed_vf_pf_prep(p_hwfn, CHANNEL_TLV_CLOSE, sizeof(*req));
920 /* add list termination tlv */
921 qed_add_tlv(p_hwfn, &p_iov->offset,
922 CHANNEL_TLV_LIST_END, sizeof(struct channel_list_end_tlv));
924 resp = &p_iov->pf2vf_reply->default_resp;
925 rc = qed_send_msg2pf(p_hwfn, &resp->hdr.status, sizeof(*resp));
929 if (resp->hdr.status != PFVF_STATUS_SUCCESS) {
934 p_hwfn->b_int_enabled = 0;
937 qed_vf_pf_req_end(p_hwfn, rc);
942 int qed_vf_pf_release(struct qed_hwfn *p_hwfn)
944 struct qed_vf_iov *p_iov = p_hwfn->vf_iov_info;
945 struct pfvf_def_resp_tlv *resp;
946 struct vfpf_first_tlv *req;
950 /* clear mailbox and prep first tlv */
951 req = qed_vf_pf_prep(p_hwfn, CHANNEL_TLV_RELEASE, sizeof(*req));
953 /* add list termination tlv */
954 qed_add_tlv(p_hwfn, &p_iov->offset,
955 CHANNEL_TLV_LIST_END, sizeof(struct channel_list_end_tlv));
957 resp = &p_iov->pf2vf_reply->default_resp;
958 rc = qed_send_msg2pf(p_hwfn, &resp->hdr.status, sizeof(*resp));
960 if (!rc && resp->hdr.status != PFVF_STATUS_SUCCESS)
963 qed_vf_pf_req_end(p_hwfn, rc);
965 p_hwfn->b_int_enabled = 0;
967 if (p_iov->vf2pf_request)
968 dma_free_coherent(&p_hwfn->cdev->pdev->dev,
969 sizeof(union vfpf_tlvs),
970 p_iov->vf2pf_request,
971 p_iov->vf2pf_request_phys);
972 if (p_iov->pf2vf_reply)
973 dma_free_coherent(&p_hwfn->cdev->pdev->dev,
974 sizeof(union pfvf_tlvs),
975 p_iov->pf2vf_reply, p_iov->pf2vf_reply_phys);
977 if (p_iov->bulletin.p_virt) {
978 size = sizeof(struct qed_bulletin_content);
979 dma_free_coherent(&p_hwfn->cdev->pdev->dev,
981 p_iov->bulletin.p_virt, p_iov->bulletin.phys);
984 kfree(p_hwfn->vf_iov_info);
985 p_hwfn->vf_iov_info = NULL;
990 void qed_vf_pf_filter_mcast(struct qed_hwfn *p_hwfn,
991 struct qed_filter_mcast *p_filter_cmd)
993 struct qed_sp_vport_update_params sp_params;
996 memset(&sp_params, 0, sizeof(sp_params));
997 sp_params.update_approx_mcast_flg = 1;
999 if (p_filter_cmd->opcode == QED_FILTER_ADD) {
1000 for (i = 0; i < p_filter_cmd->num_mc_addrs; i++) {
1003 bit = qed_mcast_bin_from_mac(p_filter_cmd->mac[i]);
1004 sp_params.bins[bit / 32] |= 1 << (bit % 32);
1008 qed_vf_pf_vport_update(p_hwfn, &sp_params);
1011 int qed_vf_pf_filter_ucast(struct qed_hwfn *p_hwfn,
1012 struct qed_filter_ucast *p_ucast)
1014 struct qed_vf_iov *p_iov = p_hwfn->vf_iov_info;
1015 struct vfpf_ucast_filter_tlv *req;
1016 struct pfvf_def_resp_tlv *resp;
1019 /* clear mailbox and prep first tlv */
1020 req = qed_vf_pf_prep(p_hwfn, CHANNEL_TLV_UCAST_FILTER, sizeof(*req));
1021 req->opcode = (u8) p_ucast->opcode;
1022 req->type = (u8) p_ucast->type;
1023 memcpy(req->mac, p_ucast->mac, ETH_ALEN);
1024 req->vlan = p_ucast->vlan;
1026 /* add list termination tlv */
1027 qed_add_tlv(p_hwfn, &p_iov->offset,
1028 CHANNEL_TLV_LIST_END, sizeof(struct channel_list_end_tlv));
1030 resp = &p_iov->pf2vf_reply->default_resp;
1031 rc = qed_send_msg2pf(p_hwfn, &resp->hdr.status, sizeof(*resp));
1035 if (resp->hdr.status != PFVF_STATUS_SUCCESS) {
1041 qed_vf_pf_req_end(p_hwfn, rc);
1046 int qed_vf_pf_int_cleanup(struct qed_hwfn *p_hwfn)
1048 struct qed_vf_iov *p_iov = p_hwfn->vf_iov_info;
1049 struct pfvf_def_resp_tlv *resp = &p_iov->pf2vf_reply->default_resp;
1052 /* clear mailbox and prep first tlv */
1053 qed_vf_pf_prep(p_hwfn, CHANNEL_TLV_INT_CLEANUP,
1054 sizeof(struct vfpf_first_tlv));
1056 /* add list termination tlv */
1057 qed_add_tlv(p_hwfn, &p_iov->offset,
1058 CHANNEL_TLV_LIST_END, sizeof(struct channel_list_end_tlv));
1060 rc = qed_send_msg2pf(p_hwfn, &resp->hdr.status, sizeof(*resp));
1064 if (resp->hdr.status != PFVF_STATUS_SUCCESS) {
1070 qed_vf_pf_req_end(p_hwfn, rc);
1075 u16 qed_vf_get_igu_sb_id(struct qed_hwfn *p_hwfn, u16 sb_id)
1077 struct qed_vf_iov *p_iov = p_hwfn->vf_iov_info;
1080 DP_NOTICE(p_hwfn, "vf_sriov_info isn't initialized\n");
1084 return p_iov->acquire_resp.resc.hw_sbs[sb_id].hw_sb_id;
1087 int qed_vf_read_bulletin(struct qed_hwfn *p_hwfn, u8 *p_change)
1089 struct qed_vf_iov *p_iov = p_hwfn->vf_iov_info;
1090 struct qed_bulletin_content shadow;
1093 crc_size = sizeof(p_iov->bulletin.p_virt->crc);
1096 /* Need to guarantee PF is not in the middle of writing it */
1097 memcpy(&shadow, p_iov->bulletin.p_virt, p_iov->bulletin.size);
1099 /* If version did not update, no need to do anything */
1100 if (shadow.version == p_iov->bulletin_shadow.version)
1103 /* Verify the bulletin we see is valid */
1104 crc = crc32(0, (u8 *)&shadow + crc_size,
1105 p_iov->bulletin.size - crc_size);
1106 if (crc != shadow.crc)
1109 /* Set the shadow bulletin and process it */
1110 memcpy(&p_iov->bulletin_shadow, &shadow, p_iov->bulletin.size);
1112 DP_VERBOSE(p_hwfn, QED_MSG_IOV,
1113 "Read a bulletin update %08x\n", shadow.version);
1120 void __qed_vf_get_link_params(struct qed_hwfn *p_hwfn,
1121 struct qed_mcp_link_params *p_params,
1122 struct qed_bulletin_content *p_bulletin)
1124 memset(p_params, 0, sizeof(*p_params));
1126 p_params->speed.autoneg = p_bulletin->req_autoneg;
1127 p_params->speed.advertised_speeds = p_bulletin->req_adv_speed;
1128 p_params->speed.forced_speed = p_bulletin->req_forced_speed;
1129 p_params->pause.autoneg = p_bulletin->req_autoneg_pause;
1130 p_params->pause.forced_rx = p_bulletin->req_forced_rx;
1131 p_params->pause.forced_tx = p_bulletin->req_forced_tx;
1132 p_params->loopback_mode = p_bulletin->req_loopback;
1135 void qed_vf_get_link_params(struct qed_hwfn *p_hwfn,
1136 struct qed_mcp_link_params *params)
1138 __qed_vf_get_link_params(p_hwfn, params,
1139 &(p_hwfn->vf_iov_info->bulletin_shadow));
1142 void __qed_vf_get_link_state(struct qed_hwfn *p_hwfn,
1143 struct qed_mcp_link_state *p_link,
1144 struct qed_bulletin_content *p_bulletin)
1146 memset(p_link, 0, sizeof(*p_link));
1148 p_link->link_up = p_bulletin->link_up;
1149 p_link->speed = p_bulletin->speed;
1150 p_link->full_duplex = p_bulletin->full_duplex;
1151 p_link->an = p_bulletin->autoneg;
1152 p_link->an_complete = p_bulletin->autoneg_complete;
1153 p_link->parallel_detection = p_bulletin->parallel_detection;
1154 p_link->pfc_enabled = p_bulletin->pfc_enabled;
1155 p_link->partner_adv_speed = p_bulletin->partner_adv_speed;
1156 p_link->partner_tx_flow_ctrl_en = p_bulletin->partner_tx_flow_ctrl_en;
1157 p_link->partner_rx_flow_ctrl_en = p_bulletin->partner_rx_flow_ctrl_en;
1158 p_link->partner_adv_pause = p_bulletin->partner_adv_pause;
1159 p_link->sfp_tx_fault = p_bulletin->sfp_tx_fault;
1162 void qed_vf_get_link_state(struct qed_hwfn *p_hwfn,
1163 struct qed_mcp_link_state *link)
1165 __qed_vf_get_link_state(p_hwfn, link,
1166 &(p_hwfn->vf_iov_info->bulletin_shadow));
1169 void __qed_vf_get_link_caps(struct qed_hwfn *p_hwfn,
1170 struct qed_mcp_link_capabilities *p_link_caps,
1171 struct qed_bulletin_content *p_bulletin)
1173 memset(p_link_caps, 0, sizeof(*p_link_caps));
1174 p_link_caps->speed_capabilities = p_bulletin->capability_speed;
1177 void qed_vf_get_link_caps(struct qed_hwfn *p_hwfn,
1178 struct qed_mcp_link_capabilities *p_link_caps)
1180 __qed_vf_get_link_caps(p_hwfn, p_link_caps,
1181 &(p_hwfn->vf_iov_info->bulletin_shadow));
1184 void qed_vf_get_num_rxqs(struct qed_hwfn *p_hwfn, u8 *num_rxqs)
1186 *num_rxqs = p_hwfn->vf_iov_info->acquire_resp.resc.num_rxqs;
1189 void qed_vf_get_port_mac(struct qed_hwfn *p_hwfn, u8 *port_mac)
1192 p_hwfn->vf_iov_info->acquire_resp.pfdev_info.port_mac, ETH_ALEN);
1195 void qed_vf_get_num_vlan_filters(struct qed_hwfn *p_hwfn, u8 *num_vlan_filters)
1197 struct qed_vf_iov *p_vf;
1199 p_vf = p_hwfn->vf_iov_info;
1200 *num_vlan_filters = p_vf->acquire_resp.resc.num_vlan_filters;
1203 bool qed_vf_check_mac(struct qed_hwfn *p_hwfn, u8 *mac)
1205 struct qed_bulletin_content *bulletin;
1207 bulletin = &p_hwfn->vf_iov_info->bulletin_shadow;
1208 if (!(bulletin->valid_bitmap & (1 << MAC_ADDR_FORCED)))
1211 /* Forbid VF from changing a MAC enforced by PF */
1212 if (ether_addr_equal(bulletin->mac, mac))
1218 static bool qed_vf_bulletin_get_forced_mac(struct qed_hwfn *hwfn,
1219 u8 *dst_mac, u8 *p_is_forced)
1221 struct qed_bulletin_content *bulletin;
1223 bulletin = &hwfn->vf_iov_info->bulletin_shadow;
1225 if (bulletin->valid_bitmap & (1 << MAC_ADDR_FORCED)) {
1228 } else if (bulletin->valid_bitmap & (1 << VFPF_BULLETIN_MAC_ADDR)) {
1235 ether_addr_copy(dst_mac, bulletin->mac);
1240 void qed_vf_get_fw_version(struct qed_hwfn *p_hwfn,
1241 u16 *fw_major, u16 *fw_minor,
1242 u16 *fw_rev, u16 *fw_eng)
1244 struct pf_vf_pfdev_info *info;
1246 info = &p_hwfn->vf_iov_info->acquire_resp.pfdev_info;
1248 *fw_major = info->fw_major;
1249 *fw_minor = info->fw_minor;
1250 *fw_rev = info->fw_rev;
1251 *fw_eng = info->fw_eng;
1254 static void qed_handle_bulletin_change(struct qed_hwfn *hwfn)
1256 struct qed_eth_cb_ops *ops = hwfn->cdev->protocol_ops.eth;
1257 u8 mac[ETH_ALEN], is_mac_exist, is_mac_forced;
1258 void *cookie = hwfn->cdev->ops_cookie;
1260 is_mac_exist = qed_vf_bulletin_get_forced_mac(hwfn, mac,
1262 if (is_mac_exist && is_mac_forced && cookie)
1263 ops->force_mac(cookie, mac);
1265 /* Always update link configuration according to bulletin */
1266 qed_link_update(hwfn);
1269 void qed_iov_vf_task(struct work_struct *work)
1271 struct qed_hwfn *hwfn = container_of(work, struct qed_hwfn,
1275 if (test_and_clear_bit(QED_IOV_WQ_STOP_WQ_FLAG, &hwfn->iov_task_flags))
1278 /* Handle bulletin board changes */
1279 qed_vf_read_bulletin(hwfn, &change);
1281 qed_handle_bulletin_change(hwfn);
1283 /* As VF is polling bulletin board, need to constantly re-schedule */
1284 queue_delayed_work(hwfn->iov_wq, &hwfn->iov_task, HZ);