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>
11 #include "qed_sriov.h"
14 static void *qed_vf_pf_prep(struct qed_hwfn *p_hwfn, u16 type, u16 length)
16 struct qed_vf_iov *p_iov = p_hwfn->vf_iov_info;
19 /* This lock is released when we receive PF's response
20 * in qed_send_msg2pf().
21 * So, qed_vf_pf_prep() and qed_send_msg2pf()
22 * must come in sequence.
24 mutex_lock(&(p_iov->mutex));
28 "preparing to send 0x%04x tlv over vf pf channel\n",
31 /* Reset Requst offset */
32 p_iov->offset = (u8 *)p_iov->vf2pf_request;
34 /* Clear mailbox - both request and reply */
35 memset(p_iov->vf2pf_request, 0, sizeof(union vfpf_tlvs));
36 memset(p_iov->pf2vf_reply, 0, sizeof(union pfvf_tlvs));
38 /* Init type and length */
39 p_tlv = qed_add_tlv(p_hwfn, &p_iov->offset, type, length);
41 /* Init first tlv header */
42 ((struct vfpf_first_tlv *)p_tlv)->reply_address =
43 (u64)p_iov->pf2vf_reply_phys;
48 static int qed_send_msg2pf(struct qed_hwfn *p_hwfn, u8 *done, u32 resp_size)
50 union vfpf_tlvs *p_req = p_hwfn->vf_iov_info->vf2pf_request;
51 struct ustorm_trigger_vf_zone trigger;
52 struct ustorm_vf_zone *zone_data;
53 int rc = 0, time = 100;
55 zone_data = (struct ustorm_vf_zone *)PXP_VF_BAR0_START_USDM_ZONE_B;
57 /* output tlvs list */
58 qed_dp_tlv_list(p_hwfn, p_req);
60 /* need to add the END TLV to the message size */
61 resp_size += sizeof(struct channel_list_end_tlv);
63 /* Send TLVs over HW channel */
64 memset(&trigger, 0, sizeof(struct ustorm_trigger_vf_zone));
65 trigger.vf_pf_msg_valid = 1;
69 "VF -> PF [%02x] message: [%08x, %08x] --> %p, %08x --> %p\n",
70 GET_FIELD(p_hwfn->hw_info.concrete_fid,
71 PXP_CONCRETE_FID_PFID),
72 upper_32_bits(p_hwfn->vf_iov_info->vf2pf_request_phys),
73 lower_32_bits(p_hwfn->vf_iov_info->vf2pf_request_phys),
74 &zone_data->non_trigger.vf_pf_msg_addr,
75 *((u32 *)&trigger), &zone_data->trigger);
78 (uintptr_t)&zone_data->non_trigger.vf_pf_msg_addr.lo,
79 lower_32_bits(p_hwfn->vf_iov_info->vf2pf_request_phys));
82 (uintptr_t)&zone_data->non_trigger.vf_pf_msg_addr.hi,
83 upper_32_bits(p_hwfn->vf_iov_info->vf2pf_request_phys));
85 /* The message data must be written first, to prevent trigger before
90 REG_WR(p_hwfn, (uintptr_t)&zone_data->trigger, *((u32 *)&trigger));
92 /* When PF would be done with the response, it would write back to the
93 * `done' address. Poll until then.
95 while ((!*done) && time) {
101 DP_VERBOSE(p_hwfn, QED_MSG_IOV,
102 "VF <-- PF Timeout [Type %d]\n",
103 p_req->first_tlv.tl.type);
107 DP_VERBOSE(p_hwfn, QED_MSG_IOV,
108 "PF response: %d [Type %d]\n",
109 *done, p_req->first_tlv.tl.type);
113 mutex_unlock(&(p_hwfn->vf_iov_info->mutex));
118 #define VF_ACQUIRE_THRESH 3
119 #define VF_ACQUIRE_MAC_FILTERS 1
121 static int qed_vf_pf_acquire(struct qed_hwfn *p_hwfn)
123 struct qed_vf_iov *p_iov = p_hwfn->vf_iov_info;
124 struct pfvf_acquire_resp_tlv *resp = &p_iov->pf2vf_reply->acquire_resp;
125 struct pf_vf_pfdev_info *pfdev_info = &resp->pfdev_info;
126 u8 rx_count = 1, tx_count = 1, num_sbs = 1;
127 u8 num_mac = VF_ACQUIRE_MAC_FILTERS;
128 bool resources_acquired = false;
129 struct vfpf_acquire_tlv *req;
130 int rc = 0, attempts = 0;
132 /* clear mailbox and prep first tlv */
133 req = qed_vf_pf_prep(p_hwfn, CHANNEL_TLV_ACQUIRE, sizeof(*req));
135 /* starting filling the request */
136 req->vfdev_info.opaque_fid = p_hwfn->hw_info.opaque_fid;
138 req->resc_request.num_rxqs = rx_count;
139 req->resc_request.num_txqs = tx_count;
140 req->resc_request.num_sbs = num_sbs;
141 req->resc_request.num_mac_filters = num_mac;
142 req->resc_request.num_vlan_filters = QED_ETH_VF_NUM_VLAN_FILTERS;
144 req->vfdev_info.os_type = VFPF_ACQUIRE_OS_LINUX;
145 req->vfdev_info.fw_major = FW_MAJOR_VERSION;
146 req->vfdev_info.fw_minor = FW_MINOR_VERSION;
147 req->vfdev_info.fw_revision = FW_REVISION_VERSION;
148 req->vfdev_info.fw_engineering = FW_ENGINEERING_VERSION;
150 /* Fill capability field with any non-deprecated config we support */
151 req->vfdev_info.capabilities |= VFPF_ACQUIRE_CAP_100G;
153 /* pf 2 vf bulletin board address */
154 req->bulletin_addr = p_iov->bulletin.phys;
155 req->bulletin_size = p_iov->bulletin.size;
157 /* add list termination tlv */
158 qed_add_tlv(p_hwfn, &p_iov->offset,
159 CHANNEL_TLV_LIST_END, sizeof(struct channel_list_end_tlv));
161 while (!resources_acquired) {
163 QED_MSG_IOV, "attempting to acquire resources\n");
165 /* send acquire request */
166 rc = qed_send_msg2pf(p_hwfn, &resp->hdr.status, sizeof(*resp));
170 /* copy acquire response from buffer to p_hwfn */
171 memcpy(&p_iov->acquire_resp, resp, sizeof(p_iov->acquire_resp));
175 if (resp->hdr.status == PFVF_STATUS_SUCCESS) {
176 /* PF agrees to allocate our resources */
177 if (!(resp->pfdev_info.capabilities &
178 PFVF_ACQUIRE_CAP_POST_FW_OVERRIDE)) {
180 "PF is using old incompatible driver; Either downgrade driver or request provider to update hypervisor version\n");
183 DP_VERBOSE(p_hwfn, QED_MSG_IOV, "resources acquired\n");
184 resources_acquired = true;
185 } else if (resp->hdr.status == PFVF_STATUS_NO_RESOURCE &&
186 attempts < VF_ACQUIRE_THRESH) {
189 "PF unwilling to fullfill resource request. Try PF recommended amount\n");
191 /* humble our request */
192 req->resc_request.num_txqs = resp->resc.num_txqs;
193 req->resc_request.num_rxqs = resp->resc.num_rxqs;
194 req->resc_request.num_sbs = resp->resc.num_sbs;
195 req->resc_request.num_mac_filters =
196 resp->resc.num_mac_filters;
197 req->resc_request.num_vlan_filters =
198 resp->resc.num_vlan_filters;
200 /* Clear response buffer */
201 memset(p_iov->pf2vf_reply, 0, sizeof(union pfvf_tlvs));
204 "PF returned error %d to VF acquisition request\n",
210 /* Update bulletin board size with response from PF */
211 p_iov->bulletin.size = resp->bulletin_size;
214 p_hwfn->cdev->type = resp->pfdev_info.dev_type;
215 p_hwfn->cdev->chip_rev = resp->pfdev_info.chip_rev;
217 p_hwfn->cdev->chip_num = pfdev_info->chip_num & 0xffff;
219 /* Learn of the possibility of CMT */
220 if (IS_LEAD_HWFN(p_hwfn)) {
221 if (resp->pfdev_info.capabilities & PFVF_ACQUIRE_CAP_100G) {
222 DP_NOTICE(p_hwfn, "100g VF\n");
223 p_hwfn->cdev->num_hwfns = 2;
230 int qed_vf_hw_prepare(struct qed_hwfn *p_hwfn)
232 struct qed_vf_iov *p_iov;
235 /* Set number of hwfns - might be overriden once leading hwfn learns
236 * actual configuration from PF.
238 if (IS_LEAD_HWFN(p_hwfn))
239 p_hwfn->cdev->num_hwfns = 1;
241 /* Set the doorbell bar. Assumption: regview is set */
242 p_hwfn->doorbells = (u8 __iomem *)p_hwfn->regview +
243 PXP_VF_BAR0_START_DQ;
245 reg = PXP_VF_BAR0_ME_OPAQUE_ADDRESS;
246 p_hwfn->hw_info.opaque_fid = (u16)REG_RD(p_hwfn, reg);
248 reg = PXP_VF_BAR0_ME_CONCRETE_ADDRESS;
249 p_hwfn->hw_info.concrete_fid = REG_RD(p_hwfn, reg);
251 /* Allocate vf sriov info */
252 p_iov = kzalloc(sizeof(*p_iov), GFP_KERNEL);
254 DP_NOTICE(p_hwfn, "Failed to allocate `struct qed_sriov'\n");
258 /* Allocate vf2pf msg */
259 p_iov->vf2pf_request = dma_alloc_coherent(&p_hwfn->cdev->pdev->dev,
260 sizeof(union vfpf_tlvs),
261 &p_iov->vf2pf_request_phys,
263 if (!p_iov->vf2pf_request) {
265 "Failed to allocate `vf2pf_request' DMA memory\n");
269 p_iov->pf2vf_reply = dma_alloc_coherent(&p_hwfn->cdev->pdev->dev,
270 sizeof(union pfvf_tlvs),
271 &p_iov->pf2vf_reply_phys,
273 if (!p_iov->pf2vf_reply) {
275 "Failed to allocate `pf2vf_reply' DMA memory\n");
276 goto free_vf2pf_request;
281 "VF's Request mailbox [%p virt 0x%llx phys], Response mailbox [%p virt 0x%llx phys]\n",
282 p_iov->vf2pf_request,
283 (u64) p_iov->vf2pf_request_phys,
284 p_iov->pf2vf_reply, (u64)p_iov->pf2vf_reply_phys);
286 /* Allocate Bulletin board */
287 p_iov->bulletin.size = sizeof(struct qed_bulletin_content);
288 p_iov->bulletin.p_virt = dma_alloc_coherent(&p_hwfn->cdev->pdev->dev,
289 p_iov->bulletin.size,
290 &p_iov->bulletin.phys,
292 DP_VERBOSE(p_hwfn, QED_MSG_IOV,
293 "VF's bulletin Board [%p virt 0x%llx phys 0x%08x bytes]\n",
294 p_iov->bulletin.p_virt,
295 (u64)p_iov->bulletin.phys, p_iov->bulletin.size);
297 mutex_init(&p_iov->mutex);
299 p_hwfn->vf_iov_info = p_iov;
301 p_hwfn->hw_info.personality = QED_PCI_ETH;
303 return qed_vf_pf_acquire(p_hwfn);
306 dma_free_coherent(&p_hwfn->cdev->pdev->dev,
307 sizeof(union vfpf_tlvs),
308 p_iov->vf2pf_request, p_iov->vf2pf_request_phys);
315 int qed_vf_pf_rxq_start(struct qed_hwfn *p_hwfn,
320 dma_addr_t bd_chain_phys_addr,
321 dma_addr_t cqe_pbl_addr,
322 u16 cqe_pbl_size, void __iomem **pp_prod)
324 struct qed_vf_iov *p_iov = p_hwfn->vf_iov_info;
325 struct pfvf_start_queue_resp_tlv *resp;
326 struct vfpf_start_rxq_tlv *req;
329 /* clear mailbox and prep first tlv */
330 req = qed_vf_pf_prep(p_hwfn, CHANNEL_TLV_START_RXQ, sizeof(*req));
332 req->rx_qid = rx_qid;
333 req->cqe_pbl_addr = cqe_pbl_addr;
334 req->cqe_pbl_size = cqe_pbl_size;
335 req->rxq_addr = bd_chain_phys_addr;
337 req->sb_index = sb_index;
338 req->bd_max_bytes = bd_max_bytes;
341 /* add list termination tlv */
342 qed_add_tlv(p_hwfn, &p_iov->offset,
343 CHANNEL_TLV_LIST_END, sizeof(struct channel_list_end_tlv));
345 resp = &p_iov->pf2vf_reply->queue_start;
346 rc = qed_send_msg2pf(p_hwfn, &resp->hdr.status, sizeof(*resp));
350 if (resp->hdr.status != PFVF_STATUS_SUCCESS)
353 /* Learn the address of the producer from the response */
355 u64 init_prod_val = 0;
357 *pp_prod = (u8 __iomem *)p_hwfn->regview + resp->offset;
358 DP_VERBOSE(p_hwfn, QED_MSG_IOV,
359 "Rxq[0x%02x]: producer at %p [offset 0x%08x]\n",
360 rx_qid, *pp_prod, resp->offset);
362 /* Init the rcq, rx bd and rx sge (if valid) producers to 0 */
363 __internal_ram_wr(p_hwfn, *pp_prod, sizeof(u64),
364 (u32 *)&init_prod_val);
370 int qed_vf_pf_rxq_stop(struct qed_hwfn *p_hwfn, u16 rx_qid, bool cqe_completion)
372 struct qed_vf_iov *p_iov = p_hwfn->vf_iov_info;
373 struct vfpf_stop_rxqs_tlv *req;
374 struct pfvf_def_resp_tlv *resp;
377 /* clear mailbox and prep first tlv */
378 req = qed_vf_pf_prep(p_hwfn, CHANNEL_TLV_STOP_RXQS, sizeof(*req));
380 req->rx_qid = rx_qid;
382 req->cqe_completion = cqe_completion;
384 /* add list termination tlv */
385 qed_add_tlv(p_hwfn, &p_iov->offset,
386 CHANNEL_TLV_LIST_END, sizeof(struct channel_list_end_tlv));
388 resp = &p_iov->pf2vf_reply->default_resp;
389 rc = qed_send_msg2pf(p_hwfn, &resp->hdr.status, sizeof(*resp));
393 if (resp->hdr.status != PFVF_STATUS_SUCCESS)
399 int qed_vf_pf_txq_start(struct qed_hwfn *p_hwfn,
404 u16 pbl_size, void __iomem **pp_doorbell)
406 struct qed_vf_iov *p_iov = p_hwfn->vf_iov_info;
407 struct vfpf_start_txq_tlv *req;
408 struct pfvf_def_resp_tlv *resp;
411 /* clear mailbox and prep first tlv */
412 req = qed_vf_pf_prep(p_hwfn, CHANNEL_TLV_START_TXQ, sizeof(*req));
414 req->tx_qid = tx_queue_id;
417 req->pbl_addr = pbl_addr;
418 req->pbl_size = pbl_size;
420 req->sb_index = sb_index;
422 /* add list termination tlv */
423 qed_add_tlv(p_hwfn, &p_iov->offset,
424 CHANNEL_TLV_LIST_END, sizeof(struct channel_list_end_tlv));
426 resp = &p_iov->pf2vf_reply->default_resp;
427 rc = qed_send_msg2pf(p_hwfn, &resp->hdr.status, sizeof(*resp));
431 if (resp->hdr.status != PFVF_STATUS_SUCCESS)
435 u8 cid = p_iov->acquire_resp.resc.cid[tx_queue_id];
437 *pp_doorbell = (u8 __iomem *)p_hwfn->doorbells +
438 qed_db_addr(cid, DQ_DEMS_LEGACY);
444 int qed_vf_pf_txq_stop(struct qed_hwfn *p_hwfn, u16 tx_qid)
446 struct qed_vf_iov *p_iov = p_hwfn->vf_iov_info;
447 struct vfpf_stop_txqs_tlv *req;
448 struct pfvf_def_resp_tlv *resp;
451 /* clear mailbox and prep first tlv */
452 req = qed_vf_pf_prep(p_hwfn, CHANNEL_TLV_STOP_TXQS, sizeof(*req));
454 req->tx_qid = tx_qid;
457 /* add list termination tlv */
458 qed_add_tlv(p_hwfn, &p_iov->offset,
459 CHANNEL_TLV_LIST_END, sizeof(struct channel_list_end_tlv));
461 resp = &p_iov->pf2vf_reply->default_resp;
462 rc = qed_send_msg2pf(p_hwfn, &resp->hdr.status, sizeof(*resp));
466 if (resp->hdr.status != PFVF_STATUS_SUCCESS)
472 int qed_vf_pf_vport_start(struct qed_hwfn *p_hwfn,
475 u8 inner_vlan_removal,
476 enum qed_tpa_mode tpa_mode,
477 u8 max_buffers_per_cqe, u8 only_untagged)
479 struct qed_vf_iov *p_iov = p_hwfn->vf_iov_info;
480 struct vfpf_vport_start_tlv *req;
481 struct pfvf_def_resp_tlv *resp;
484 /* clear mailbox and prep first tlv */
485 req = qed_vf_pf_prep(p_hwfn, CHANNEL_TLV_VPORT_START, sizeof(*req));
488 req->vport_id = vport_id;
489 req->inner_vlan_removal = inner_vlan_removal;
490 req->tpa_mode = tpa_mode;
491 req->max_buffers_per_cqe = max_buffers_per_cqe;
492 req->only_untagged = only_untagged;
495 for (i = 0; i < p_hwfn->vf_iov_info->acquire_resp.resc.num_sbs; i++)
496 if (p_hwfn->sbs_info[i])
497 req->sb_addr[i] = p_hwfn->sbs_info[i]->sb_phys;
499 /* add list termination tlv */
500 qed_add_tlv(p_hwfn, &p_iov->offset,
501 CHANNEL_TLV_LIST_END, sizeof(struct channel_list_end_tlv));
503 resp = &p_iov->pf2vf_reply->default_resp;
504 rc = qed_send_msg2pf(p_hwfn, &resp->hdr.status, sizeof(*resp));
508 if (resp->hdr.status != PFVF_STATUS_SUCCESS)
514 int qed_vf_pf_vport_stop(struct qed_hwfn *p_hwfn)
516 struct qed_vf_iov *p_iov = p_hwfn->vf_iov_info;
517 struct pfvf_def_resp_tlv *resp = &p_iov->pf2vf_reply->default_resp;
520 /* clear mailbox and prep first tlv */
521 qed_vf_pf_prep(p_hwfn, CHANNEL_TLV_VPORT_TEARDOWN,
522 sizeof(struct vfpf_first_tlv));
524 /* add list termination tlv */
525 qed_add_tlv(p_hwfn, &p_iov->offset,
526 CHANNEL_TLV_LIST_END, sizeof(struct channel_list_end_tlv));
528 rc = qed_send_msg2pf(p_hwfn, &resp->hdr.status, sizeof(*resp));
532 if (resp->hdr.status != PFVF_STATUS_SUCCESS)
539 qed_vf_handle_vp_update_is_needed(struct qed_hwfn *p_hwfn,
540 struct qed_sp_vport_update_params *p_data,
544 case CHANNEL_TLV_VPORT_UPDATE_ACTIVATE:
545 return !!(p_data->update_vport_active_rx_flg ||
546 p_data->update_vport_active_tx_flg);
547 case CHANNEL_TLV_VPORT_UPDATE_TX_SWITCH:
548 return !!p_data->update_tx_switching_flg;
549 case CHANNEL_TLV_VPORT_UPDATE_VLAN_STRIP:
550 return !!p_data->update_inner_vlan_removal_flg;
551 case CHANNEL_TLV_VPORT_UPDATE_ACCEPT_ANY_VLAN:
552 return !!p_data->update_accept_any_vlan_flg;
553 case CHANNEL_TLV_VPORT_UPDATE_MCAST:
554 return !!p_data->update_approx_mcast_flg;
555 case CHANNEL_TLV_VPORT_UPDATE_ACCEPT_PARAM:
556 return !!(p_data->accept_flags.update_rx_mode_config ||
557 p_data->accept_flags.update_tx_mode_config);
558 case CHANNEL_TLV_VPORT_UPDATE_RSS:
559 return !!p_data->rss_params;
560 case CHANNEL_TLV_VPORT_UPDATE_SGE_TPA:
561 return !!p_data->sge_tpa_params;
563 DP_INFO(p_hwfn, "Unexpected vport-update TLV[%d]\n",
570 qed_vf_handle_vp_update_tlvs_resp(struct qed_hwfn *p_hwfn,
571 struct qed_sp_vport_update_params *p_data)
573 struct qed_vf_iov *p_iov = p_hwfn->vf_iov_info;
574 struct pfvf_def_resp_tlv *p_resp;
577 for (tlv = CHANNEL_TLV_VPORT_UPDATE_ACTIVATE;
578 tlv < CHANNEL_TLV_VPORT_UPDATE_MAX; tlv++) {
579 if (!qed_vf_handle_vp_update_is_needed(p_hwfn, p_data, tlv))
582 p_resp = (struct pfvf_def_resp_tlv *)
583 qed_iov_search_list_tlvs(p_hwfn, p_iov->pf2vf_reply,
585 if (p_resp && p_resp->hdr.status)
586 DP_VERBOSE(p_hwfn, QED_MSG_IOV,
587 "TLV[%d] Configuration %s\n",
589 (p_resp && p_resp->hdr.status) ? "succeeded"
594 int qed_vf_pf_vport_update(struct qed_hwfn *p_hwfn,
595 struct qed_sp_vport_update_params *p_params)
597 struct qed_vf_iov *p_iov = p_hwfn->vf_iov_info;
598 struct vfpf_vport_update_tlv *req;
599 struct pfvf_def_resp_tlv *resp;
600 u8 update_rx, update_tx;
605 resp = &p_iov->pf2vf_reply->default_resp;
606 resp_size = sizeof(*resp);
608 update_rx = p_params->update_vport_active_rx_flg;
609 update_tx = p_params->update_vport_active_tx_flg;
611 /* clear mailbox and prep header tlv */
612 qed_vf_pf_prep(p_hwfn, CHANNEL_TLV_VPORT_UPDATE, sizeof(*req));
614 /* Prepare extended tlvs */
615 if (update_rx || update_tx) {
616 struct vfpf_vport_update_activate_tlv *p_act_tlv;
618 size = sizeof(struct vfpf_vport_update_activate_tlv);
619 p_act_tlv = qed_add_tlv(p_hwfn, &p_iov->offset,
620 CHANNEL_TLV_VPORT_UPDATE_ACTIVATE,
622 resp_size += sizeof(struct pfvf_def_resp_tlv);
625 p_act_tlv->update_rx = update_rx;
626 p_act_tlv->active_rx = p_params->vport_active_rx_flg;
630 p_act_tlv->update_tx = update_tx;
631 p_act_tlv->active_tx = p_params->vport_active_tx_flg;
635 if (p_params->update_approx_mcast_flg) {
636 struct vfpf_vport_update_mcast_bin_tlv *p_mcast_tlv;
638 size = sizeof(struct vfpf_vport_update_mcast_bin_tlv);
639 p_mcast_tlv = qed_add_tlv(p_hwfn, &p_iov->offset,
640 CHANNEL_TLV_VPORT_UPDATE_MCAST, size);
641 resp_size += sizeof(struct pfvf_def_resp_tlv);
643 memcpy(p_mcast_tlv->bins, p_params->bins,
644 sizeof(unsigned long) * ETH_MULTICAST_MAC_BINS_IN_REGS);
647 update_rx = p_params->accept_flags.update_rx_mode_config;
648 update_tx = p_params->accept_flags.update_tx_mode_config;
650 if (update_rx || update_tx) {
651 struct vfpf_vport_update_accept_param_tlv *p_accept_tlv;
653 tlv = CHANNEL_TLV_VPORT_UPDATE_ACCEPT_PARAM;
654 size = sizeof(struct vfpf_vport_update_accept_param_tlv);
655 p_accept_tlv = qed_add_tlv(p_hwfn, &p_iov->offset, tlv, size);
656 resp_size += sizeof(struct pfvf_def_resp_tlv);
659 p_accept_tlv->update_rx_mode = update_rx;
660 p_accept_tlv->rx_accept_filter =
661 p_params->accept_flags.rx_accept_filter;
665 p_accept_tlv->update_tx_mode = update_tx;
666 p_accept_tlv->tx_accept_filter =
667 p_params->accept_flags.tx_accept_filter;
671 if (p_params->rss_params) {
672 struct qed_rss_params *rss_params = p_params->rss_params;
673 struct vfpf_vport_update_rss_tlv *p_rss_tlv;
675 size = sizeof(struct vfpf_vport_update_rss_tlv);
676 p_rss_tlv = qed_add_tlv(p_hwfn,
678 CHANNEL_TLV_VPORT_UPDATE_RSS, size);
679 resp_size += sizeof(struct pfvf_def_resp_tlv);
681 if (rss_params->update_rss_config)
682 p_rss_tlv->update_rss_flags |=
683 VFPF_UPDATE_RSS_CONFIG_FLAG;
684 if (rss_params->update_rss_capabilities)
685 p_rss_tlv->update_rss_flags |=
686 VFPF_UPDATE_RSS_CAPS_FLAG;
687 if (rss_params->update_rss_ind_table)
688 p_rss_tlv->update_rss_flags |=
689 VFPF_UPDATE_RSS_IND_TABLE_FLAG;
690 if (rss_params->update_rss_key)
691 p_rss_tlv->update_rss_flags |= VFPF_UPDATE_RSS_KEY_FLAG;
693 p_rss_tlv->rss_enable = rss_params->rss_enable;
694 p_rss_tlv->rss_caps = rss_params->rss_caps;
695 p_rss_tlv->rss_table_size_log = rss_params->rss_table_size_log;
696 memcpy(p_rss_tlv->rss_ind_table, rss_params->rss_ind_table,
697 sizeof(rss_params->rss_ind_table));
698 memcpy(p_rss_tlv->rss_key, rss_params->rss_key,
699 sizeof(rss_params->rss_key));
702 if (p_params->update_accept_any_vlan_flg) {
703 struct vfpf_vport_update_accept_any_vlan_tlv *p_any_vlan_tlv;
705 size = sizeof(struct vfpf_vport_update_accept_any_vlan_tlv);
706 tlv = CHANNEL_TLV_VPORT_UPDATE_ACCEPT_ANY_VLAN;
707 p_any_vlan_tlv = qed_add_tlv(p_hwfn, &p_iov->offset, tlv, size);
709 resp_size += sizeof(struct pfvf_def_resp_tlv);
710 p_any_vlan_tlv->accept_any_vlan = p_params->accept_any_vlan;
711 p_any_vlan_tlv->update_accept_any_vlan_flg =
712 p_params->update_accept_any_vlan_flg;
715 /* add list termination tlv */
716 qed_add_tlv(p_hwfn, &p_iov->offset,
717 CHANNEL_TLV_LIST_END, sizeof(struct channel_list_end_tlv));
719 rc = qed_send_msg2pf(p_hwfn, &resp->hdr.status, resp_size);
723 if (resp->hdr.status != PFVF_STATUS_SUCCESS)
726 qed_vf_handle_vp_update_tlvs_resp(p_hwfn, p_params);
731 int qed_vf_pf_reset(struct qed_hwfn *p_hwfn)
733 struct qed_vf_iov *p_iov = p_hwfn->vf_iov_info;
734 struct pfvf_def_resp_tlv *resp;
735 struct vfpf_first_tlv *req;
738 /* clear mailbox and prep first tlv */
739 req = qed_vf_pf_prep(p_hwfn, CHANNEL_TLV_CLOSE, sizeof(*req));
741 /* add list termination tlv */
742 qed_add_tlv(p_hwfn, &p_iov->offset,
743 CHANNEL_TLV_LIST_END, sizeof(struct channel_list_end_tlv));
745 resp = &p_iov->pf2vf_reply->default_resp;
746 rc = qed_send_msg2pf(p_hwfn, &resp->hdr.status, sizeof(*resp));
750 if (resp->hdr.status != PFVF_STATUS_SUCCESS)
753 p_hwfn->b_int_enabled = 0;
758 int qed_vf_pf_release(struct qed_hwfn *p_hwfn)
760 struct qed_vf_iov *p_iov = p_hwfn->vf_iov_info;
761 struct pfvf_def_resp_tlv *resp;
762 struct vfpf_first_tlv *req;
766 /* clear mailbox and prep first tlv */
767 req = qed_vf_pf_prep(p_hwfn, CHANNEL_TLV_RELEASE, sizeof(*req));
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));
773 resp = &p_iov->pf2vf_reply->default_resp;
774 rc = qed_send_msg2pf(p_hwfn, &resp->hdr.status, sizeof(*resp));
776 if (!rc && resp->hdr.status != PFVF_STATUS_SUCCESS)
779 p_hwfn->b_int_enabled = 0;
781 if (p_iov->vf2pf_request)
782 dma_free_coherent(&p_hwfn->cdev->pdev->dev,
783 sizeof(union vfpf_tlvs),
784 p_iov->vf2pf_request,
785 p_iov->vf2pf_request_phys);
786 if (p_iov->pf2vf_reply)
787 dma_free_coherent(&p_hwfn->cdev->pdev->dev,
788 sizeof(union pfvf_tlvs),
789 p_iov->pf2vf_reply, p_iov->pf2vf_reply_phys);
791 if (p_iov->bulletin.p_virt) {
792 size = sizeof(struct qed_bulletin_content);
793 dma_free_coherent(&p_hwfn->cdev->pdev->dev,
795 p_iov->bulletin.p_virt, p_iov->bulletin.phys);
798 kfree(p_hwfn->vf_iov_info);
799 p_hwfn->vf_iov_info = NULL;
804 void qed_vf_pf_filter_mcast(struct qed_hwfn *p_hwfn,
805 struct qed_filter_mcast *p_filter_cmd)
807 struct qed_sp_vport_update_params sp_params;
810 memset(&sp_params, 0, sizeof(sp_params));
811 sp_params.update_approx_mcast_flg = 1;
813 if (p_filter_cmd->opcode == QED_FILTER_ADD) {
814 for (i = 0; i < p_filter_cmd->num_mc_addrs; i++) {
817 bit = qed_mcast_bin_from_mac(p_filter_cmd->mac[i]);
818 __set_bit(bit, sp_params.bins);
822 qed_vf_pf_vport_update(p_hwfn, &sp_params);
825 int qed_vf_pf_filter_ucast(struct qed_hwfn *p_hwfn,
826 struct qed_filter_ucast *p_ucast)
828 struct qed_vf_iov *p_iov = p_hwfn->vf_iov_info;
829 struct vfpf_ucast_filter_tlv *req;
830 struct pfvf_def_resp_tlv *resp;
833 /* clear mailbox and prep first tlv */
834 req = qed_vf_pf_prep(p_hwfn, CHANNEL_TLV_UCAST_FILTER, sizeof(*req));
835 req->opcode = (u8) p_ucast->opcode;
836 req->type = (u8) p_ucast->type;
837 memcpy(req->mac, p_ucast->mac, ETH_ALEN);
838 req->vlan = p_ucast->vlan;
840 /* add list termination tlv */
841 qed_add_tlv(p_hwfn, &p_iov->offset,
842 CHANNEL_TLV_LIST_END, sizeof(struct channel_list_end_tlv));
844 resp = &p_iov->pf2vf_reply->default_resp;
845 rc = qed_send_msg2pf(p_hwfn, &resp->hdr.status, sizeof(*resp));
849 if (resp->hdr.status != PFVF_STATUS_SUCCESS)
855 int qed_vf_pf_int_cleanup(struct qed_hwfn *p_hwfn)
857 struct qed_vf_iov *p_iov = p_hwfn->vf_iov_info;
858 struct pfvf_def_resp_tlv *resp = &p_iov->pf2vf_reply->default_resp;
861 /* clear mailbox and prep first tlv */
862 qed_vf_pf_prep(p_hwfn, CHANNEL_TLV_INT_CLEANUP,
863 sizeof(struct vfpf_first_tlv));
865 /* add list termination tlv */
866 qed_add_tlv(p_hwfn, &p_iov->offset,
867 CHANNEL_TLV_LIST_END, sizeof(struct channel_list_end_tlv));
869 rc = qed_send_msg2pf(p_hwfn, &resp->hdr.status, sizeof(*resp));
873 if (resp->hdr.status != PFVF_STATUS_SUCCESS)
879 u16 qed_vf_get_igu_sb_id(struct qed_hwfn *p_hwfn, u16 sb_id)
881 struct qed_vf_iov *p_iov = p_hwfn->vf_iov_info;
884 DP_NOTICE(p_hwfn, "vf_sriov_info isn't initialized\n");
888 return p_iov->acquire_resp.resc.hw_sbs[sb_id].hw_sb_id;
891 int qed_vf_read_bulletin(struct qed_hwfn *p_hwfn, u8 *p_change)
893 struct qed_vf_iov *p_iov = p_hwfn->vf_iov_info;
894 struct qed_bulletin_content shadow;
897 crc_size = sizeof(p_iov->bulletin.p_virt->crc);
900 /* Need to guarantee PF is not in the middle of writing it */
901 memcpy(&shadow, p_iov->bulletin.p_virt, p_iov->bulletin.size);
903 /* If version did not update, no need to do anything */
904 if (shadow.version == p_iov->bulletin_shadow.version)
907 /* Verify the bulletin we see is valid */
908 crc = crc32(0, (u8 *)&shadow + crc_size,
909 p_iov->bulletin.size - crc_size);
910 if (crc != shadow.crc)
913 /* Set the shadow bulletin and process it */
914 memcpy(&p_iov->bulletin_shadow, &shadow, p_iov->bulletin.size);
916 DP_VERBOSE(p_hwfn, QED_MSG_IOV,
917 "Read a bulletin update %08x\n", shadow.version);
924 void __qed_vf_get_link_params(struct qed_hwfn *p_hwfn,
925 struct qed_mcp_link_params *p_params,
926 struct qed_bulletin_content *p_bulletin)
928 memset(p_params, 0, sizeof(*p_params));
930 p_params->speed.autoneg = p_bulletin->req_autoneg;
931 p_params->speed.advertised_speeds = p_bulletin->req_adv_speed;
932 p_params->speed.forced_speed = p_bulletin->req_forced_speed;
933 p_params->pause.autoneg = p_bulletin->req_autoneg_pause;
934 p_params->pause.forced_rx = p_bulletin->req_forced_rx;
935 p_params->pause.forced_tx = p_bulletin->req_forced_tx;
936 p_params->loopback_mode = p_bulletin->req_loopback;
939 void qed_vf_get_link_params(struct qed_hwfn *p_hwfn,
940 struct qed_mcp_link_params *params)
942 __qed_vf_get_link_params(p_hwfn, params,
943 &(p_hwfn->vf_iov_info->bulletin_shadow));
946 void __qed_vf_get_link_state(struct qed_hwfn *p_hwfn,
947 struct qed_mcp_link_state *p_link,
948 struct qed_bulletin_content *p_bulletin)
950 memset(p_link, 0, sizeof(*p_link));
952 p_link->link_up = p_bulletin->link_up;
953 p_link->speed = p_bulletin->speed;
954 p_link->full_duplex = p_bulletin->full_duplex;
955 p_link->an = p_bulletin->autoneg;
956 p_link->an_complete = p_bulletin->autoneg_complete;
957 p_link->parallel_detection = p_bulletin->parallel_detection;
958 p_link->pfc_enabled = p_bulletin->pfc_enabled;
959 p_link->partner_adv_speed = p_bulletin->partner_adv_speed;
960 p_link->partner_tx_flow_ctrl_en = p_bulletin->partner_tx_flow_ctrl_en;
961 p_link->partner_rx_flow_ctrl_en = p_bulletin->partner_rx_flow_ctrl_en;
962 p_link->partner_adv_pause = p_bulletin->partner_adv_pause;
963 p_link->sfp_tx_fault = p_bulletin->sfp_tx_fault;
966 void qed_vf_get_link_state(struct qed_hwfn *p_hwfn,
967 struct qed_mcp_link_state *link)
969 __qed_vf_get_link_state(p_hwfn, link,
970 &(p_hwfn->vf_iov_info->bulletin_shadow));
973 void __qed_vf_get_link_caps(struct qed_hwfn *p_hwfn,
974 struct qed_mcp_link_capabilities *p_link_caps,
975 struct qed_bulletin_content *p_bulletin)
977 memset(p_link_caps, 0, sizeof(*p_link_caps));
978 p_link_caps->speed_capabilities = p_bulletin->capability_speed;
981 void qed_vf_get_link_caps(struct qed_hwfn *p_hwfn,
982 struct qed_mcp_link_capabilities *p_link_caps)
984 __qed_vf_get_link_caps(p_hwfn, p_link_caps,
985 &(p_hwfn->vf_iov_info->bulletin_shadow));
988 void qed_vf_get_num_rxqs(struct qed_hwfn *p_hwfn, u8 *num_rxqs)
990 *num_rxqs = p_hwfn->vf_iov_info->acquire_resp.resc.num_rxqs;
993 void qed_vf_get_port_mac(struct qed_hwfn *p_hwfn, u8 *port_mac)
996 p_hwfn->vf_iov_info->acquire_resp.pfdev_info.port_mac, ETH_ALEN);
999 void qed_vf_get_num_vlan_filters(struct qed_hwfn *p_hwfn, u8 *num_vlan_filters)
1001 struct qed_vf_iov *p_vf;
1003 p_vf = p_hwfn->vf_iov_info;
1004 *num_vlan_filters = p_vf->acquire_resp.resc.num_vlan_filters;
1007 void qed_vf_get_fw_version(struct qed_hwfn *p_hwfn,
1008 u16 *fw_major, u16 *fw_minor,
1009 u16 *fw_rev, u16 *fw_eng)
1011 struct pf_vf_pfdev_info *info;
1013 info = &p_hwfn->vf_iov_info->acquire_resp.pfdev_info;
1015 *fw_major = info->fw_major;
1016 *fw_minor = info->fw_minor;
1017 *fw_rev = info->fw_rev;
1018 *fw_eng = info->fw_eng;
1021 static void qed_handle_bulletin_change(struct qed_hwfn *hwfn)
1023 /* Always update link configuration according to bulletin */
1024 qed_link_update(hwfn);
1027 void qed_iov_vf_task(struct work_struct *work)
1029 struct qed_hwfn *hwfn = container_of(work, struct qed_hwfn,
1033 if (test_and_clear_bit(QED_IOV_WQ_STOP_WQ_FLAG, &hwfn->iov_task_flags))
1036 /* Handle bulletin board changes */
1037 qed_vf_read_bulletin(hwfn, &change);
1039 qed_handle_bulletin_change(hwfn);
1041 /* As VF is polling bulletin board, need to constantly re-schedule */
1042 queue_delayed_work(hwfn->iov_wq, &hwfn->iov_task, HZ);