1 /* QLogic qed NIC Driver
2 * Copyright (c) 2015-2017 QLogic Corporation
4 * This software is available to you under a choice of one of two
5 * licenses. You may choose to be licensed under the terms of the GNU
6 * General Public License (GPL) Version 2, available from the file
7 * COPYING in the main directory of this source tree, or the
8 * OpenIB.org BSD license below:
10 * Redistribution and use in source and binary forms, with or
11 * without modification, are permitted provided that the following
14 * - Redistributions of source code must retain the above
15 * copyright notice, this list of conditions and the following
18 * - Redistributions in binary form must reproduce the above
19 * copyright notice, this list of conditions and the following
20 * disclaimer in the documentation and /or other materials
21 * provided with the distribution.
23 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
24 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
25 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
26 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
27 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
28 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
29 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
33 #include <linux/crc32.h>
34 #include <linux/etherdevice.h>
36 #include "qed_sriov.h"
39 static void *qed_vf_pf_prep(struct qed_hwfn *p_hwfn, u16 type, u16 length)
41 struct qed_vf_iov *p_iov = p_hwfn->vf_iov_info;
44 /* This lock is released when we receive PF's response
45 * in qed_send_msg2pf().
46 * So, qed_vf_pf_prep() and qed_send_msg2pf()
47 * must come in sequence.
49 mutex_lock(&(p_iov->mutex));
53 "preparing to send 0x%04x tlv over vf pf channel\n",
56 /* Reset Requst offset */
57 p_iov->offset = (u8 *)p_iov->vf2pf_request;
59 /* Clear mailbox - both request and reply */
60 memset(p_iov->vf2pf_request, 0, sizeof(union vfpf_tlvs));
61 memset(p_iov->pf2vf_reply, 0, sizeof(union pfvf_tlvs));
63 /* Init type and length */
64 p_tlv = qed_add_tlv(p_hwfn, &p_iov->offset, type, length);
66 /* Init first tlv header */
67 ((struct vfpf_first_tlv *)p_tlv)->reply_address =
68 (u64)p_iov->pf2vf_reply_phys;
73 static void qed_vf_pf_req_end(struct qed_hwfn *p_hwfn, int req_status)
75 union pfvf_tlvs *resp = p_hwfn->vf_iov_info->pf2vf_reply;
77 DP_VERBOSE(p_hwfn, QED_MSG_IOV,
78 "VF request status = 0x%x, PF reply status = 0x%x\n",
79 req_status, resp->default_resp.hdr.status);
81 mutex_unlock(&(p_hwfn->vf_iov_info->mutex));
84 static int qed_send_msg2pf(struct qed_hwfn *p_hwfn, u8 *done, u32 resp_size)
86 union vfpf_tlvs *p_req = p_hwfn->vf_iov_info->vf2pf_request;
87 struct ustorm_trigger_vf_zone trigger;
88 struct ustorm_vf_zone *zone_data;
89 int rc = 0, time = 100;
91 zone_data = (struct ustorm_vf_zone *)PXP_VF_BAR0_START_USDM_ZONE_B;
93 /* output tlvs list */
94 qed_dp_tlv_list(p_hwfn, p_req);
96 /* need to add the END TLV to the message size */
97 resp_size += sizeof(struct channel_list_end_tlv);
99 /* Send TLVs over HW channel */
100 memset(&trigger, 0, sizeof(struct ustorm_trigger_vf_zone));
101 trigger.vf_pf_msg_valid = 1;
105 "VF -> PF [%02x] message: [%08x, %08x] --> %p, %08x --> %p\n",
106 GET_FIELD(p_hwfn->hw_info.concrete_fid,
107 PXP_CONCRETE_FID_PFID),
108 upper_32_bits(p_hwfn->vf_iov_info->vf2pf_request_phys),
109 lower_32_bits(p_hwfn->vf_iov_info->vf2pf_request_phys),
110 &zone_data->non_trigger.vf_pf_msg_addr,
111 *((u32 *)&trigger), &zone_data->trigger);
114 (uintptr_t)&zone_data->non_trigger.vf_pf_msg_addr.lo,
115 lower_32_bits(p_hwfn->vf_iov_info->vf2pf_request_phys));
118 (uintptr_t)&zone_data->non_trigger.vf_pf_msg_addr.hi,
119 upper_32_bits(p_hwfn->vf_iov_info->vf2pf_request_phys));
121 /* The message data must be written first, to prevent trigger before
126 REG_WR(p_hwfn, (uintptr_t)&zone_data->trigger, *((u32 *)&trigger));
128 /* When PF would be done with the response, it would write back to the
129 * `done' address. Poll until then.
131 while ((!*done) && time) {
138 "VF <-- PF Timeout [Type %d]\n",
139 p_req->first_tlv.tl.type);
142 if ((*done != PFVF_STATUS_SUCCESS) &&
143 (*done != PFVF_STATUS_NO_RESOURCE))
145 "PF response: %d [Type %d]\n",
146 *done, p_req->first_tlv.tl.type);
148 DP_VERBOSE(p_hwfn, QED_MSG_IOV,
149 "PF response: %d [Type %d]\n",
150 *done, p_req->first_tlv.tl.type);
156 #define VF_ACQUIRE_THRESH 3
157 static void qed_vf_pf_acquire_reduce_resc(struct qed_hwfn *p_hwfn,
158 struct vf_pf_resc_request *p_req,
159 struct pf_vf_resc *p_resp)
163 "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",
170 p_req->num_mac_filters,
171 p_resp->num_mac_filters,
172 p_req->num_vlan_filters,
173 p_resp->num_vlan_filters,
174 p_req->num_mc_filters, p_resp->num_mc_filters);
176 /* humble our request */
177 p_req->num_txqs = p_resp->num_txqs;
178 p_req->num_rxqs = p_resp->num_rxqs;
179 p_req->num_sbs = p_resp->num_sbs;
180 p_req->num_mac_filters = p_resp->num_mac_filters;
181 p_req->num_vlan_filters = p_resp->num_vlan_filters;
182 p_req->num_mc_filters = p_resp->num_mc_filters;
185 static int qed_vf_pf_acquire(struct qed_hwfn *p_hwfn)
187 struct qed_vf_iov *p_iov = p_hwfn->vf_iov_info;
188 struct pfvf_acquire_resp_tlv *resp = &p_iov->pf2vf_reply->acquire_resp;
189 struct pf_vf_pfdev_info *pfdev_info = &resp->pfdev_info;
190 struct vf_pf_resc_request *p_resc;
191 bool resources_acquired = false;
192 struct vfpf_acquire_tlv *req;
193 int rc = 0, attempts = 0;
195 /* clear mailbox and prep first tlv */
196 req = qed_vf_pf_prep(p_hwfn, CHANNEL_TLV_ACQUIRE, sizeof(*req));
197 p_resc = &req->resc_request;
199 /* starting filling the request */
200 req->vfdev_info.opaque_fid = p_hwfn->hw_info.opaque_fid;
202 p_resc->num_rxqs = QED_MAX_VF_CHAINS_PER_PF;
203 p_resc->num_txqs = QED_MAX_VF_CHAINS_PER_PF;
204 p_resc->num_sbs = QED_MAX_VF_CHAINS_PER_PF;
205 p_resc->num_mac_filters = QED_ETH_VF_NUM_MAC_FILTERS;
206 p_resc->num_vlan_filters = QED_ETH_VF_NUM_VLAN_FILTERS;
208 req->vfdev_info.os_type = VFPF_ACQUIRE_OS_LINUX;
209 req->vfdev_info.fw_major = FW_MAJOR_VERSION;
210 req->vfdev_info.fw_minor = FW_MINOR_VERSION;
211 req->vfdev_info.fw_revision = FW_REVISION_VERSION;
212 req->vfdev_info.fw_engineering = FW_ENGINEERING_VERSION;
213 req->vfdev_info.eth_fp_hsi_major = ETH_HSI_VER_MAJOR;
214 req->vfdev_info.eth_fp_hsi_minor = ETH_HSI_VER_MINOR;
216 /* Fill capability field with any non-deprecated config we support */
217 req->vfdev_info.capabilities |= VFPF_ACQUIRE_CAP_100G;
219 /* pf 2 vf bulletin board address */
220 req->bulletin_addr = p_iov->bulletin.phys;
221 req->bulletin_size = p_iov->bulletin.size;
223 /* add list termination tlv */
224 qed_add_tlv(p_hwfn, &p_iov->offset,
225 CHANNEL_TLV_LIST_END, sizeof(struct channel_list_end_tlv));
227 while (!resources_acquired) {
229 QED_MSG_IOV, "attempting to acquire resources\n");
231 /* Clear response buffer, as this might be a re-send */
232 memset(p_iov->pf2vf_reply, 0, sizeof(union pfvf_tlvs));
234 /* send acquire request */
235 rc = qed_send_msg2pf(p_hwfn, &resp->hdr.status, sizeof(*resp));
239 /* copy acquire response from buffer to p_hwfn */
240 memcpy(&p_iov->acquire_resp, resp, sizeof(p_iov->acquire_resp));
244 if (resp->hdr.status == PFVF_STATUS_SUCCESS) {
245 /* PF agrees to allocate our resources */
246 if (!(resp->pfdev_info.capabilities &
247 PFVF_ACQUIRE_CAP_POST_FW_OVERRIDE)) {
248 /* It's possible legacy PF mistakenly accepted;
249 * but we don't care - simply mark it as
250 * legacy and continue.
252 req->vfdev_info.capabilities |=
253 VFPF_ACQUIRE_CAP_PRE_FP_HSI;
255 DP_VERBOSE(p_hwfn, QED_MSG_IOV, "resources acquired\n");
256 resources_acquired = true;
257 } else if (resp->hdr.status == PFVF_STATUS_NO_RESOURCE &&
258 attempts < VF_ACQUIRE_THRESH) {
259 qed_vf_pf_acquire_reduce_resc(p_hwfn, p_resc,
261 } else if (resp->hdr.status == PFVF_STATUS_NOT_SUPPORTED) {
262 if (pfdev_info->major_fp_hsi &&
263 (pfdev_info->major_fp_hsi != ETH_HSI_VER_MAJOR)) {
265 "PF uses an incompatible fastpath HSI %02x.%02x [VF requires %02x.%02x]. Please change to a VF driver using %02x.xx.\n",
266 pfdev_info->major_fp_hsi,
267 pfdev_info->minor_fp_hsi,
270 pfdev_info->major_fp_hsi);
275 if (!pfdev_info->major_fp_hsi) {
276 if (req->vfdev_info.capabilities &
277 VFPF_ACQUIRE_CAP_PRE_FP_HSI) {
279 "PF uses very old drivers. Please change to a VF driver using no later than 8.8.x.x.\n");
284 "PF is old - try re-acquire to see if it supports FW-version override\n");
285 req->vfdev_info.capabilities |=
286 VFPF_ACQUIRE_CAP_PRE_FP_HSI;
291 /* If PF/VF are using same Major, PF must have had
292 * it's reasons. Simply fail.
294 DP_NOTICE(p_hwfn, "PF rejected acquisition by VF\n");
299 "PF returned error %d to VF acquisition request\n",
306 /* Mark the PF as legacy, if needed */
307 if (req->vfdev_info.capabilities & VFPF_ACQUIRE_CAP_PRE_FP_HSI)
308 p_iov->b_pre_fp_hsi = true;
310 /* Update bulletin board size with response from PF */
311 p_iov->bulletin.size = resp->bulletin_size;
314 p_hwfn->cdev->type = resp->pfdev_info.dev_type;
315 p_hwfn->cdev->chip_rev = resp->pfdev_info.chip_rev;
317 p_hwfn->cdev->chip_num = pfdev_info->chip_num & 0xffff;
319 /* Learn of the possibility of CMT */
320 if (IS_LEAD_HWFN(p_hwfn)) {
321 if (resp->pfdev_info.capabilities & PFVF_ACQUIRE_CAP_100G) {
322 DP_NOTICE(p_hwfn, "100g VF\n");
323 p_hwfn->cdev->num_hwfns = 2;
327 if (!p_iov->b_pre_fp_hsi &&
329 (resp->pfdev_info.minor_fp_hsi < ETH_HSI_VER_MINOR)) {
331 "PF is using older fastpath HSI; %02x.%02x is configured\n",
332 ETH_HSI_VER_MAJOR, resp->pfdev_info.minor_fp_hsi);
336 qed_vf_pf_req_end(p_hwfn, rc);
341 int qed_vf_hw_prepare(struct qed_hwfn *p_hwfn)
343 struct qed_vf_iov *p_iov;
346 /* Set number of hwfns - might be overriden once leading hwfn learns
347 * actual configuration from PF.
349 if (IS_LEAD_HWFN(p_hwfn))
350 p_hwfn->cdev->num_hwfns = 1;
352 /* Set the doorbell bar. Assumption: regview is set */
353 p_hwfn->doorbells = (u8 __iomem *)p_hwfn->regview +
354 PXP_VF_BAR0_START_DQ;
356 reg = PXP_VF_BAR0_ME_OPAQUE_ADDRESS;
357 p_hwfn->hw_info.opaque_fid = (u16)REG_RD(p_hwfn, reg);
359 reg = PXP_VF_BAR0_ME_CONCRETE_ADDRESS;
360 p_hwfn->hw_info.concrete_fid = REG_RD(p_hwfn, reg);
362 /* Allocate vf sriov info */
363 p_iov = kzalloc(sizeof(*p_iov), GFP_KERNEL);
367 /* Allocate vf2pf msg */
368 p_iov->vf2pf_request = dma_alloc_coherent(&p_hwfn->cdev->pdev->dev,
369 sizeof(union vfpf_tlvs),
370 &p_iov->vf2pf_request_phys,
372 if (!p_iov->vf2pf_request)
375 p_iov->pf2vf_reply = dma_alloc_coherent(&p_hwfn->cdev->pdev->dev,
376 sizeof(union pfvf_tlvs),
377 &p_iov->pf2vf_reply_phys,
379 if (!p_iov->pf2vf_reply)
380 goto free_vf2pf_request;
384 "VF's Request mailbox [%p virt 0x%llx phys], Response mailbox [%p virt 0x%llx phys]\n",
385 p_iov->vf2pf_request,
386 (u64) p_iov->vf2pf_request_phys,
387 p_iov->pf2vf_reply, (u64)p_iov->pf2vf_reply_phys);
389 /* Allocate Bulletin board */
390 p_iov->bulletin.size = sizeof(struct qed_bulletin_content);
391 p_iov->bulletin.p_virt = dma_alloc_coherent(&p_hwfn->cdev->pdev->dev,
392 p_iov->bulletin.size,
393 &p_iov->bulletin.phys,
395 DP_VERBOSE(p_hwfn, QED_MSG_IOV,
396 "VF's bulletin Board [%p virt 0x%llx phys 0x%08x bytes]\n",
397 p_iov->bulletin.p_virt,
398 (u64)p_iov->bulletin.phys, p_iov->bulletin.size);
400 mutex_init(&p_iov->mutex);
402 p_hwfn->vf_iov_info = p_iov;
404 p_hwfn->hw_info.personality = QED_PCI_ETH;
406 return qed_vf_pf_acquire(p_hwfn);
409 dma_free_coherent(&p_hwfn->cdev->pdev->dev,
410 sizeof(union vfpf_tlvs),
411 p_iov->vf2pf_request, p_iov->vf2pf_request_phys);
417 #define TSTORM_QZONE_START PXP_VF_BAR0_START_SDM_ZONE_A
418 #define MSTORM_QZONE_START(dev) (TSTORM_QZONE_START + \
419 (TSTORM_QZONE_SIZE * NUM_OF_L2_QUEUES(dev)))
422 __qed_vf_prep_tunn_req_tlv(struct vfpf_update_tunn_param_tlv *p_req,
423 struct qed_tunn_update_type *p_src,
424 enum qed_tunn_clss mask, u8 *p_cls)
426 if (p_src->b_update_mode) {
427 p_req->tun_mode_update_mask |= BIT(mask);
429 if (p_src->b_mode_enabled)
430 p_req->tunn_mode |= BIT(mask);
433 *p_cls = p_src->tun_cls;
437 qed_vf_prep_tunn_req_tlv(struct vfpf_update_tunn_param_tlv *p_req,
438 struct qed_tunn_update_type *p_src,
439 enum qed_tunn_clss mask,
440 u8 *p_cls, struct qed_tunn_update_udp_port *p_port,
441 u8 *p_update_port, u16 *p_udp_port)
443 if (p_port->b_update_port) {
445 *p_udp_port = p_port->port;
448 __qed_vf_prep_tunn_req_tlv(p_req, p_src, mask, p_cls);
451 void qed_vf_set_vf_start_tunn_update_param(struct qed_tunnel_info *p_tun)
453 if (p_tun->vxlan.b_mode_enabled)
454 p_tun->vxlan.b_update_mode = true;
455 if (p_tun->l2_geneve.b_mode_enabled)
456 p_tun->l2_geneve.b_update_mode = true;
457 if (p_tun->ip_geneve.b_mode_enabled)
458 p_tun->ip_geneve.b_update_mode = true;
459 if (p_tun->l2_gre.b_mode_enabled)
460 p_tun->l2_gre.b_update_mode = true;
461 if (p_tun->ip_gre.b_mode_enabled)
462 p_tun->ip_gre.b_update_mode = true;
464 p_tun->b_update_rx_cls = true;
465 p_tun->b_update_tx_cls = true;
469 __qed_vf_update_tunn_param(struct qed_tunn_update_type *p_tun,
470 u16 feature_mask, u8 tunn_mode,
471 u8 tunn_cls, enum qed_tunn_mode val)
473 if (feature_mask & BIT(val)) {
474 p_tun->b_mode_enabled = tunn_mode;
475 p_tun->tun_cls = tunn_cls;
477 p_tun->b_mode_enabled = false;
481 static void qed_vf_update_tunn_param(struct qed_hwfn *p_hwfn,
482 struct qed_tunnel_info *p_tun,
483 struct pfvf_update_tunn_param_tlv *p_resp)
485 /* Update mode and classes provided by PF */
486 u16 feat_mask = p_resp->tunn_feature_mask;
488 __qed_vf_update_tunn_param(&p_tun->vxlan, feat_mask,
489 p_resp->vxlan_mode, p_resp->vxlan_clss,
490 QED_MODE_VXLAN_TUNN);
491 __qed_vf_update_tunn_param(&p_tun->l2_geneve, feat_mask,
492 p_resp->l2geneve_mode,
493 p_resp->l2geneve_clss,
494 QED_MODE_L2GENEVE_TUNN);
495 __qed_vf_update_tunn_param(&p_tun->ip_geneve, feat_mask,
496 p_resp->ipgeneve_mode,
497 p_resp->ipgeneve_clss,
498 QED_MODE_IPGENEVE_TUNN);
499 __qed_vf_update_tunn_param(&p_tun->l2_gre, feat_mask,
500 p_resp->l2gre_mode, p_resp->l2gre_clss,
501 QED_MODE_L2GRE_TUNN);
502 __qed_vf_update_tunn_param(&p_tun->ip_gre, feat_mask,
503 p_resp->ipgre_mode, p_resp->ipgre_clss,
504 QED_MODE_IPGRE_TUNN);
505 p_tun->geneve_port.port = p_resp->geneve_udp_port;
506 p_tun->vxlan_port.port = p_resp->vxlan_udp_port;
508 DP_VERBOSE(p_hwfn, QED_MSG_IOV,
509 "tunn mode: vxlan=0x%x, l2geneve=0x%x, ipgeneve=0x%x, l2gre=0x%x, ipgre=0x%x",
510 p_tun->vxlan.b_mode_enabled, p_tun->l2_geneve.b_mode_enabled,
511 p_tun->ip_geneve.b_mode_enabled,
512 p_tun->l2_gre.b_mode_enabled, p_tun->ip_gre.b_mode_enabled);
515 int qed_vf_pf_tunnel_param_update(struct qed_hwfn *p_hwfn,
516 struct qed_tunnel_info *p_src)
518 struct qed_tunnel_info *p_tun = &p_hwfn->cdev->tunnel;
519 struct qed_vf_iov *p_iov = p_hwfn->vf_iov_info;
520 struct pfvf_update_tunn_param_tlv *p_resp;
521 struct vfpf_update_tunn_param_tlv *p_req;
524 p_req = qed_vf_pf_prep(p_hwfn, CHANNEL_TLV_UPDATE_TUNN_PARAM,
527 if (p_src->b_update_rx_cls && p_src->b_update_tx_cls)
528 p_req->update_tun_cls = 1;
530 qed_vf_prep_tunn_req_tlv(p_req, &p_src->vxlan, QED_MODE_VXLAN_TUNN,
531 &p_req->vxlan_clss, &p_src->vxlan_port,
532 &p_req->update_vxlan_port,
534 qed_vf_prep_tunn_req_tlv(p_req, &p_src->l2_geneve,
535 QED_MODE_L2GENEVE_TUNN,
536 &p_req->l2geneve_clss, &p_src->geneve_port,
537 &p_req->update_geneve_port,
538 &p_req->geneve_port);
539 __qed_vf_prep_tunn_req_tlv(p_req, &p_src->ip_geneve,
540 QED_MODE_IPGENEVE_TUNN,
541 &p_req->ipgeneve_clss);
542 __qed_vf_prep_tunn_req_tlv(p_req, &p_src->l2_gre,
543 QED_MODE_L2GRE_TUNN, &p_req->l2gre_clss);
544 __qed_vf_prep_tunn_req_tlv(p_req, &p_src->ip_gre,
545 QED_MODE_IPGRE_TUNN, &p_req->ipgre_clss);
547 /* add list termination tlv */
548 qed_add_tlv(p_hwfn, &p_iov->offset,
549 CHANNEL_TLV_LIST_END,
550 sizeof(struct channel_list_end_tlv));
552 p_resp = &p_iov->pf2vf_reply->tunn_param_resp;
553 rc = qed_send_msg2pf(p_hwfn, &p_resp->hdr.status, sizeof(*p_resp));
558 if (p_resp->hdr.status != PFVF_STATUS_SUCCESS) {
559 DP_VERBOSE(p_hwfn, QED_MSG_IOV,
560 "Failed to update tunnel parameters\n");
564 qed_vf_update_tunn_param(p_hwfn, p_tun, p_resp);
566 qed_vf_pf_req_end(p_hwfn, rc);
571 qed_vf_pf_rxq_start(struct qed_hwfn *p_hwfn,
572 struct qed_queue_cid *p_cid,
574 dma_addr_t bd_chain_phys_addr,
575 dma_addr_t cqe_pbl_addr,
576 u16 cqe_pbl_size, void __iomem **pp_prod)
578 struct qed_vf_iov *p_iov = p_hwfn->vf_iov_info;
579 struct pfvf_start_queue_resp_tlv *resp;
580 struct vfpf_start_rxq_tlv *req;
581 u8 rx_qid = p_cid->rel.queue_id;
584 /* clear mailbox and prep first tlv */
585 req = qed_vf_pf_prep(p_hwfn, CHANNEL_TLV_START_RXQ, sizeof(*req));
587 req->rx_qid = rx_qid;
588 req->cqe_pbl_addr = cqe_pbl_addr;
589 req->cqe_pbl_size = cqe_pbl_size;
590 req->rxq_addr = bd_chain_phys_addr;
591 req->hw_sb = p_cid->rel.sb;
592 req->sb_index = p_cid->rel.sb_idx;
593 req->bd_max_bytes = bd_max_bytes;
596 /* If PF is legacy, we'll need to calculate producers ourselves
597 * as well as clean them.
599 if (p_iov->b_pre_fp_hsi) {
600 u8 hw_qid = p_iov->acquire_resp.resc.hw_qid[rx_qid];
601 u32 init_prod_val = 0;
603 *pp_prod = (u8 __iomem *)
605 MSTORM_QZONE_START(p_hwfn->cdev) +
606 hw_qid * MSTORM_QZONE_SIZE;
608 /* Init the rcq, rx bd and rx sge (if valid) producers to 0 */
609 __internal_ram_wr(p_hwfn, *pp_prod, sizeof(u32),
610 (u32 *)(&init_prod_val));
612 /* add list termination tlv */
613 qed_add_tlv(p_hwfn, &p_iov->offset,
614 CHANNEL_TLV_LIST_END, sizeof(struct channel_list_end_tlv));
616 resp = &p_iov->pf2vf_reply->queue_start;
617 rc = qed_send_msg2pf(p_hwfn, &resp->hdr.status, sizeof(*resp));
621 if (resp->hdr.status != PFVF_STATUS_SUCCESS) {
626 /* Learn the address of the producer from the response */
627 if (!p_iov->b_pre_fp_hsi) {
628 u32 init_prod_val = 0;
630 *pp_prod = (u8 __iomem *)p_hwfn->regview + resp->offset;
631 DP_VERBOSE(p_hwfn, QED_MSG_IOV,
632 "Rxq[0x%02x]: producer at %p [offset 0x%08x]\n",
633 rx_qid, *pp_prod, resp->offset);
635 /* Init the rcq, rx bd and rx sge (if valid) producers to 0 */
636 __internal_ram_wr(p_hwfn, *pp_prod, sizeof(u32),
637 (u32 *)&init_prod_val);
640 qed_vf_pf_req_end(p_hwfn, rc);
645 int qed_vf_pf_rxq_stop(struct qed_hwfn *p_hwfn,
646 struct qed_queue_cid *p_cid, bool cqe_completion)
648 struct qed_vf_iov *p_iov = p_hwfn->vf_iov_info;
649 struct vfpf_stop_rxqs_tlv *req;
650 struct pfvf_def_resp_tlv *resp;
653 /* clear mailbox and prep first tlv */
654 req = qed_vf_pf_prep(p_hwfn, CHANNEL_TLV_STOP_RXQS, sizeof(*req));
656 req->rx_qid = p_cid->rel.queue_id;
658 req->cqe_completion = cqe_completion;
660 /* add list termination tlv */
661 qed_add_tlv(p_hwfn, &p_iov->offset,
662 CHANNEL_TLV_LIST_END, sizeof(struct channel_list_end_tlv));
664 resp = &p_iov->pf2vf_reply->default_resp;
665 rc = qed_send_msg2pf(p_hwfn, &resp->hdr.status, sizeof(*resp));
669 if (resp->hdr.status != PFVF_STATUS_SUCCESS) {
675 qed_vf_pf_req_end(p_hwfn, rc);
681 qed_vf_pf_txq_start(struct qed_hwfn *p_hwfn,
682 struct qed_queue_cid *p_cid,
684 u16 pbl_size, void __iomem **pp_doorbell)
686 struct qed_vf_iov *p_iov = p_hwfn->vf_iov_info;
687 struct pfvf_start_queue_resp_tlv *resp;
688 struct vfpf_start_txq_tlv *req;
689 u16 qid = p_cid->rel.queue_id;
692 /* clear mailbox and prep first tlv */
693 req = qed_vf_pf_prep(p_hwfn, CHANNEL_TLV_START_TXQ, sizeof(*req));
698 req->pbl_addr = pbl_addr;
699 req->pbl_size = pbl_size;
700 req->hw_sb = p_cid->rel.sb;
701 req->sb_index = p_cid->rel.sb_idx;
703 /* add list termination tlv */
704 qed_add_tlv(p_hwfn, &p_iov->offset,
705 CHANNEL_TLV_LIST_END, sizeof(struct channel_list_end_tlv));
707 resp = &p_iov->pf2vf_reply->queue_start;
708 rc = qed_send_msg2pf(p_hwfn, &resp->hdr.status, sizeof(*resp));
712 if (resp->hdr.status != PFVF_STATUS_SUCCESS) {
717 /* Modern PFs provide the actual offsets, while legacy
718 * provided only the queue id.
720 if (!p_iov->b_pre_fp_hsi) {
721 *pp_doorbell = (u8 __iomem *)p_hwfn->doorbells + resp->offset;
723 u8 cid = p_iov->acquire_resp.resc.cid[qid];
725 *pp_doorbell = (u8 __iomem *)p_hwfn->doorbells +
730 DP_VERBOSE(p_hwfn, QED_MSG_IOV,
731 "Txq[0x%02x]: doorbell at %p [offset 0x%08x]\n",
732 qid, *pp_doorbell, resp->offset);
734 qed_vf_pf_req_end(p_hwfn, rc);
739 int qed_vf_pf_txq_stop(struct qed_hwfn *p_hwfn, struct qed_queue_cid *p_cid)
741 struct qed_vf_iov *p_iov = p_hwfn->vf_iov_info;
742 struct vfpf_stop_txqs_tlv *req;
743 struct pfvf_def_resp_tlv *resp;
746 /* clear mailbox and prep first tlv */
747 req = qed_vf_pf_prep(p_hwfn, CHANNEL_TLV_STOP_TXQS, sizeof(*req));
749 req->tx_qid = p_cid->rel.queue_id;
752 /* add list termination tlv */
753 qed_add_tlv(p_hwfn, &p_iov->offset,
754 CHANNEL_TLV_LIST_END, sizeof(struct channel_list_end_tlv));
756 resp = &p_iov->pf2vf_reply->default_resp;
757 rc = qed_send_msg2pf(p_hwfn, &resp->hdr.status, sizeof(*resp));
761 if (resp->hdr.status != PFVF_STATUS_SUCCESS) {
767 qed_vf_pf_req_end(p_hwfn, rc);
772 int qed_vf_pf_vport_start(struct qed_hwfn *p_hwfn,
775 u8 inner_vlan_removal,
776 enum qed_tpa_mode tpa_mode,
777 u8 max_buffers_per_cqe, u8 only_untagged)
779 struct qed_vf_iov *p_iov = p_hwfn->vf_iov_info;
780 struct vfpf_vport_start_tlv *req;
781 struct pfvf_def_resp_tlv *resp;
784 /* clear mailbox and prep first tlv */
785 req = qed_vf_pf_prep(p_hwfn, CHANNEL_TLV_VPORT_START, sizeof(*req));
788 req->vport_id = vport_id;
789 req->inner_vlan_removal = inner_vlan_removal;
790 req->tpa_mode = tpa_mode;
791 req->max_buffers_per_cqe = max_buffers_per_cqe;
792 req->only_untagged = only_untagged;
795 for (i = 0; i < p_hwfn->vf_iov_info->acquire_resp.resc.num_sbs; i++) {
796 struct qed_sb_info *p_sb = p_hwfn->vf_iov_info->sbs_info[i];
799 req->sb_addr[i] = p_sb->sb_phys;
802 /* add list termination tlv */
803 qed_add_tlv(p_hwfn, &p_iov->offset,
804 CHANNEL_TLV_LIST_END, sizeof(struct channel_list_end_tlv));
806 resp = &p_iov->pf2vf_reply->default_resp;
807 rc = qed_send_msg2pf(p_hwfn, &resp->hdr.status, sizeof(*resp));
811 if (resp->hdr.status != PFVF_STATUS_SUCCESS) {
817 qed_vf_pf_req_end(p_hwfn, rc);
822 int qed_vf_pf_vport_stop(struct qed_hwfn *p_hwfn)
824 struct qed_vf_iov *p_iov = p_hwfn->vf_iov_info;
825 struct pfvf_def_resp_tlv *resp = &p_iov->pf2vf_reply->default_resp;
828 /* clear mailbox and prep first tlv */
829 qed_vf_pf_prep(p_hwfn, CHANNEL_TLV_VPORT_TEARDOWN,
830 sizeof(struct vfpf_first_tlv));
832 /* add list termination tlv */
833 qed_add_tlv(p_hwfn, &p_iov->offset,
834 CHANNEL_TLV_LIST_END, sizeof(struct channel_list_end_tlv));
836 rc = qed_send_msg2pf(p_hwfn, &resp->hdr.status, sizeof(*resp));
840 if (resp->hdr.status != PFVF_STATUS_SUCCESS) {
846 qed_vf_pf_req_end(p_hwfn, rc);
852 qed_vf_handle_vp_update_is_needed(struct qed_hwfn *p_hwfn,
853 struct qed_sp_vport_update_params *p_data,
857 case CHANNEL_TLV_VPORT_UPDATE_ACTIVATE:
858 return !!(p_data->update_vport_active_rx_flg ||
859 p_data->update_vport_active_tx_flg);
860 case CHANNEL_TLV_VPORT_UPDATE_TX_SWITCH:
861 return !!p_data->update_tx_switching_flg;
862 case CHANNEL_TLV_VPORT_UPDATE_VLAN_STRIP:
863 return !!p_data->update_inner_vlan_removal_flg;
864 case CHANNEL_TLV_VPORT_UPDATE_ACCEPT_ANY_VLAN:
865 return !!p_data->update_accept_any_vlan_flg;
866 case CHANNEL_TLV_VPORT_UPDATE_MCAST:
867 return !!p_data->update_approx_mcast_flg;
868 case CHANNEL_TLV_VPORT_UPDATE_ACCEPT_PARAM:
869 return !!(p_data->accept_flags.update_rx_mode_config ||
870 p_data->accept_flags.update_tx_mode_config);
871 case CHANNEL_TLV_VPORT_UPDATE_RSS:
872 return !!p_data->rss_params;
873 case CHANNEL_TLV_VPORT_UPDATE_SGE_TPA:
874 return !!p_data->sge_tpa_params;
876 DP_INFO(p_hwfn, "Unexpected vport-update TLV[%d]\n",
883 qed_vf_handle_vp_update_tlvs_resp(struct qed_hwfn *p_hwfn,
884 struct qed_sp_vport_update_params *p_data)
886 struct qed_vf_iov *p_iov = p_hwfn->vf_iov_info;
887 struct pfvf_def_resp_tlv *p_resp;
890 for (tlv = CHANNEL_TLV_VPORT_UPDATE_ACTIVATE;
891 tlv < CHANNEL_TLV_VPORT_UPDATE_MAX; tlv++) {
892 if (!qed_vf_handle_vp_update_is_needed(p_hwfn, p_data, tlv))
895 p_resp = (struct pfvf_def_resp_tlv *)
896 qed_iov_search_list_tlvs(p_hwfn, p_iov->pf2vf_reply,
898 if (p_resp && p_resp->hdr.status)
899 DP_VERBOSE(p_hwfn, QED_MSG_IOV,
900 "TLV[%d] Configuration %s\n",
902 (p_resp && p_resp->hdr.status) ? "succeeded"
907 int qed_vf_pf_vport_update(struct qed_hwfn *p_hwfn,
908 struct qed_sp_vport_update_params *p_params)
910 struct qed_vf_iov *p_iov = p_hwfn->vf_iov_info;
911 struct vfpf_vport_update_tlv *req;
912 struct pfvf_def_resp_tlv *resp;
913 u8 update_rx, update_tx;
918 resp = &p_iov->pf2vf_reply->default_resp;
919 resp_size = sizeof(*resp);
921 update_rx = p_params->update_vport_active_rx_flg;
922 update_tx = p_params->update_vport_active_tx_flg;
924 /* clear mailbox and prep header tlv */
925 qed_vf_pf_prep(p_hwfn, CHANNEL_TLV_VPORT_UPDATE, sizeof(*req));
927 /* Prepare extended tlvs */
928 if (update_rx || update_tx) {
929 struct vfpf_vport_update_activate_tlv *p_act_tlv;
931 size = sizeof(struct vfpf_vport_update_activate_tlv);
932 p_act_tlv = qed_add_tlv(p_hwfn, &p_iov->offset,
933 CHANNEL_TLV_VPORT_UPDATE_ACTIVATE,
935 resp_size += sizeof(struct pfvf_def_resp_tlv);
938 p_act_tlv->update_rx = update_rx;
939 p_act_tlv->active_rx = p_params->vport_active_rx_flg;
943 p_act_tlv->update_tx = update_tx;
944 p_act_tlv->active_tx = p_params->vport_active_tx_flg;
948 if (p_params->update_tx_switching_flg) {
949 struct vfpf_vport_update_tx_switch_tlv *p_tx_switch_tlv;
951 size = sizeof(struct vfpf_vport_update_tx_switch_tlv);
952 tlv = CHANNEL_TLV_VPORT_UPDATE_TX_SWITCH;
953 p_tx_switch_tlv = qed_add_tlv(p_hwfn, &p_iov->offset,
955 resp_size += sizeof(struct pfvf_def_resp_tlv);
957 p_tx_switch_tlv->tx_switching = p_params->tx_switching_flg;
960 if (p_params->update_approx_mcast_flg) {
961 struct vfpf_vport_update_mcast_bin_tlv *p_mcast_tlv;
963 size = sizeof(struct vfpf_vport_update_mcast_bin_tlv);
964 p_mcast_tlv = qed_add_tlv(p_hwfn, &p_iov->offset,
965 CHANNEL_TLV_VPORT_UPDATE_MCAST, size);
966 resp_size += sizeof(struct pfvf_def_resp_tlv);
968 memcpy(p_mcast_tlv->bins, p_params->bins,
969 sizeof(unsigned long) * ETH_MULTICAST_MAC_BINS_IN_REGS);
972 update_rx = p_params->accept_flags.update_rx_mode_config;
973 update_tx = p_params->accept_flags.update_tx_mode_config;
975 if (update_rx || update_tx) {
976 struct vfpf_vport_update_accept_param_tlv *p_accept_tlv;
978 tlv = CHANNEL_TLV_VPORT_UPDATE_ACCEPT_PARAM;
979 size = sizeof(struct vfpf_vport_update_accept_param_tlv);
980 p_accept_tlv = qed_add_tlv(p_hwfn, &p_iov->offset, tlv, size);
981 resp_size += sizeof(struct pfvf_def_resp_tlv);
984 p_accept_tlv->update_rx_mode = update_rx;
985 p_accept_tlv->rx_accept_filter =
986 p_params->accept_flags.rx_accept_filter;
990 p_accept_tlv->update_tx_mode = update_tx;
991 p_accept_tlv->tx_accept_filter =
992 p_params->accept_flags.tx_accept_filter;
996 if (p_params->rss_params) {
997 struct qed_rss_params *rss_params = p_params->rss_params;
998 struct vfpf_vport_update_rss_tlv *p_rss_tlv;
1001 size = sizeof(struct vfpf_vport_update_rss_tlv);
1002 p_rss_tlv = qed_add_tlv(p_hwfn,
1004 CHANNEL_TLV_VPORT_UPDATE_RSS, size);
1005 resp_size += sizeof(struct pfvf_def_resp_tlv);
1007 if (rss_params->update_rss_config)
1008 p_rss_tlv->update_rss_flags |=
1009 VFPF_UPDATE_RSS_CONFIG_FLAG;
1010 if (rss_params->update_rss_capabilities)
1011 p_rss_tlv->update_rss_flags |=
1012 VFPF_UPDATE_RSS_CAPS_FLAG;
1013 if (rss_params->update_rss_ind_table)
1014 p_rss_tlv->update_rss_flags |=
1015 VFPF_UPDATE_RSS_IND_TABLE_FLAG;
1016 if (rss_params->update_rss_key)
1017 p_rss_tlv->update_rss_flags |= VFPF_UPDATE_RSS_KEY_FLAG;
1019 p_rss_tlv->rss_enable = rss_params->rss_enable;
1020 p_rss_tlv->rss_caps = rss_params->rss_caps;
1021 p_rss_tlv->rss_table_size_log = rss_params->rss_table_size_log;
1023 table_size = min_t(int, T_ETH_INDIRECTION_TABLE_SIZE,
1024 1 << p_rss_tlv->rss_table_size_log);
1025 for (i = 0; i < table_size; i++) {
1026 struct qed_queue_cid *p_queue;
1028 p_queue = rss_params->rss_ind_table[i];
1029 p_rss_tlv->rss_ind_table[i] = p_queue->rel.queue_id;
1031 memcpy(p_rss_tlv->rss_key, rss_params->rss_key,
1032 sizeof(rss_params->rss_key));
1035 if (p_params->update_accept_any_vlan_flg) {
1036 struct vfpf_vport_update_accept_any_vlan_tlv *p_any_vlan_tlv;
1038 size = sizeof(struct vfpf_vport_update_accept_any_vlan_tlv);
1039 tlv = CHANNEL_TLV_VPORT_UPDATE_ACCEPT_ANY_VLAN;
1040 p_any_vlan_tlv = qed_add_tlv(p_hwfn, &p_iov->offset, tlv, size);
1042 resp_size += sizeof(struct pfvf_def_resp_tlv);
1043 p_any_vlan_tlv->accept_any_vlan = p_params->accept_any_vlan;
1044 p_any_vlan_tlv->update_accept_any_vlan_flg =
1045 p_params->update_accept_any_vlan_flg;
1048 /* add list termination tlv */
1049 qed_add_tlv(p_hwfn, &p_iov->offset,
1050 CHANNEL_TLV_LIST_END, sizeof(struct channel_list_end_tlv));
1052 rc = qed_send_msg2pf(p_hwfn, &resp->hdr.status, resp_size);
1056 if (resp->hdr.status != PFVF_STATUS_SUCCESS) {
1061 qed_vf_handle_vp_update_tlvs_resp(p_hwfn, p_params);
1064 qed_vf_pf_req_end(p_hwfn, rc);
1069 int qed_vf_pf_reset(struct qed_hwfn *p_hwfn)
1071 struct qed_vf_iov *p_iov = p_hwfn->vf_iov_info;
1072 struct pfvf_def_resp_tlv *resp;
1073 struct vfpf_first_tlv *req;
1076 /* clear mailbox and prep first tlv */
1077 req = qed_vf_pf_prep(p_hwfn, CHANNEL_TLV_CLOSE, sizeof(*req));
1079 /* add list termination tlv */
1080 qed_add_tlv(p_hwfn, &p_iov->offset,
1081 CHANNEL_TLV_LIST_END, sizeof(struct channel_list_end_tlv));
1083 resp = &p_iov->pf2vf_reply->default_resp;
1084 rc = qed_send_msg2pf(p_hwfn, &resp->hdr.status, sizeof(*resp));
1088 if (resp->hdr.status != PFVF_STATUS_SUCCESS) {
1093 p_hwfn->b_int_enabled = 0;
1096 qed_vf_pf_req_end(p_hwfn, rc);
1101 int qed_vf_pf_release(struct qed_hwfn *p_hwfn)
1103 struct qed_vf_iov *p_iov = p_hwfn->vf_iov_info;
1104 struct pfvf_def_resp_tlv *resp;
1105 struct vfpf_first_tlv *req;
1109 /* clear mailbox and prep first tlv */
1110 req = qed_vf_pf_prep(p_hwfn, CHANNEL_TLV_RELEASE, sizeof(*req));
1112 /* add list termination tlv */
1113 qed_add_tlv(p_hwfn, &p_iov->offset,
1114 CHANNEL_TLV_LIST_END, sizeof(struct channel_list_end_tlv));
1116 resp = &p_iov->pf2vf_reply->default_resp;
1117 rc = qed_send_msg2pf(p_hwfn, &resp->hdr.status, sizeof(*resp));
1119 if (!rc && resp->hdr.status != PFVF_STATUS_SUCCESS)
1122 qed_vf_pf_req_end(p_hwfn, rc);
1124 p_hwfn->b_int_enabled = 0;
1126 if (p_iov->vf2pf_request)
1127 dma_free_coherent(&p_hwfn->cdev->pdev->dev,
1128 sizeof(union vfpf_tlvs),
1129 p_iov->vf2pf_request,
1130 p_iov->vf2pf_request_phys);
1131 if (p_iov->pf2vf_reply)
1132 dma_free_coherent(&p_hwfn->cdev->pdev->dev,
1133 sizeof(union pfvf_tlvs),
1134 p_iov->pf2vf_reply, p_iov->pf2vf_reply_phys);
1136 if (p_iov->bulletin.p_virt) {
1137 size = sizeof(struct qed_bulletin_content);
1138 dma_free_coherent(&p_hwfn->cdev->pdev->dev,
1140 p_iov->bulletin.p_virt, p_iov->bulletin.phys);
1143 kfree(p_hwfn->vf_iov_info);
1144 p_hwfn->vf_iov_info = NULL;
1149 void qed_vf_pf_filter_mcast(struct qed_hwfn *p_hwfn,
1150 struct qed_filter_mcast *p_filter_cmd)
1152 struct qed_sp_vport_update_params sp_params;
1155 memset(&sp_params, 0, sizeof(sp_params));
1156 sp_params.update_approx_mcast_flg = 1;
1158 if (p_filter_cmd->opcode == QED_FILTER_ADD) {
1159 for (i = 0; i < p_filter_cmd->num_mc_addrs; i++) {
1162 bit = qed_mcast_bin_from_mac(p_filter_cmd->mac[i]);
1163 __set_bit(bit, sp_params.bins);
1167 qed_vf_pf_vport_update(p_hwfn, &sp_params);
1170 int qed_vf_pf_filter_ucast(struct qed_hwfn *p_hwfn,
1171 struct qed_filter_ucast *p_ucast)
1173 struct qed_vf_iov *p_iov = p_hwfn->vf_iov_info;
1174 struct vfpf_ucast_filter_tlv *req;
1175 struct pfvf_def_resp_tlv *resp;
1178 /* clear mailbox and prep first tlv */
1179 req = qed_vf_pf_prep(p_hwfn, CHANNEL_TLV_UCAST_FILTER, sizeof(*req));
1180 req->opcode = (u8) p_ucast->opcode;
1181 req->type = (u8) p_ucast->type;
1182 memcpy(req->mac, p_ucast->mac, ETH_ALEN);
1183 req->vlan = p_ucast->vlan;
1185 /* add list termination tlv */
1186 qed_add_tlv(p_hwfn, &p_iov->offset,
1187 CHANNEL_TLV_LIST_END, sizeof(struct channel_list_end_tlv));
1189 resp = &p_iov->pf2vf_reply->default_resp;
1190 rc = qed_send_msg2pf(p_hwfn, &resp->hdr.status, sizeof(*resp));
1194 if (resp->hdr.status != PFVF_STATUS_SUCCESS) {
1200 qed_vf_pf_req_end(p_hwfn, rc);
1205 int qed_vf_pf_int_cleanup(struct qed_hwfn *p_hwfn)
1207 struct qed_vf_iov *p_iov = p_hwfn->vf_iov_info;
1208 struct pfvf_def_resp_tlv *resp = &p_iov->pf2vf_reply->default_resp;
1211 /* clear mailbox and prep first tlv */
1212 qed_vf_pf_prep(p_hwfn, CHANNEL_TLV_INT_CLEANUP,
1213 sizeof(struct vfpf_first_tlv));
1215 /* add list termination tlv */
1216 qed_add_tlv(p_hwfn, &p_iov->offset,
1217 CHANNEL_TLV_LIST_END, sizeof(struct channel_list_end_tlv));
1219 rc = qed_send_msg2pf(p_hwfn, &resp->hdr.status, sizeof(*resp));
1223 if (resp->hdr.status != PFVF_STATUS_SUCCESS) {
1229 qed_vf_pf_req_end(p_hwfn, rc);
1234 u16 qed_vf_get_igu_sb_id(struct qed_hwfn *p_hwfn, u16 sb_id)
1236 struct qed_vf_iov *p_iov = p_hwfn->vf_iov_info;
1239 DP_NOTICE(p_hwfn, "vf_sriov_info isn't initialized\n");
1243 return p_iov->acquire_resp.resc.hw_sbs[sb_id].hw_sb_id;
1246 void qed_vf_set_sb_info(struct qed_hwfn *p_hwfn,
1247 u16 sb_id, struct qed_sb_info *p_sb)
1249 struct qed_vf_iov *p_iov = p_hwfn->vf_iov_info;
1252 DP_NOTICE(p_hwfn, "vf_sriov_info isn't initialized\n");
1256 if (sb_id >= PFVF_MAX_SBS_PER_VF) {
1257 DP_NOTICE(p_hwfn, "Can't configure SB %04x\n", sb_id);
1261 p_iov->sbs_info[sb_id] = p_sb;
1264 int qed_vf_read_bulletin(struct qed_hwfn *p_hwfn, u8 *p_change)
1266 struct qed_vf_iov *p_iov = p_hwfn->vf_iov_info;
1267 struct qed_bulletin_content shadow;
1270 crc_size = sizeof(p_iov->bulletin.p_virt->crc);
1273 /* Need to guarantee PF is not in the middle of writing it */
1274 memcpy(&shadow, p_iov->bulletin.p_virt, p_iov->bulletin.size);
1276 /* If version did not update, no need to do anything */
1277 if (shadow.version == p_iov->bulletin_shadow.version)
1280 /* Verify the bulletin we see is valid */
1281 crc = crc32(0, (u8 *)&shadow + crc_size,
1282 p_iov->bulletin.size - crc_size);
1283 if (crc != shadow.crc)
1286 /* Set the shadow bulletin and process it */
1287 memcpy(&p_iov->bulletin_shadow, &shadow, p_iov->bulletin.size);
1289 DP_VERBOSE(p_hwfn, QED_MSG_IOV,
1290 "Read a bulletin update %08x\n", shadow.version);
1297 void __qed_vf_get_link_params(struct qed_hwfn *p_hwfn,
1298 struct qed_mcp_link_params *p_params,
1299 struct qed_bulletin_content *p_bulletin)
1301 memset(p_params, 0, sizeof(*p_params));
1303 p_params->speed.autoneg = p_bulletin->req_autoneg;
1304 p_params->speed.advertised_speeds = p_bulletin->req_adv_speed;
1305 p_params->speed.forced_speed = p_bulletin->req_forced_speed;
1306 p_params->pause.autoneg = p_bulletin->req_autoneg_pause;
1307 p_params->pause.forced_rx = p_bulletin->req_forced_rx;
1308 p_params->pause.forced_tx = p_bulletin->req_forced_tx;
1309 p_params->loopback_mode = p_bulletin->req_loopback;
1312 void qed_vf_get_link_params(struct qed_hwfn *p_hwfn,
1313 struct qed_mcp_link_params *params)
1315 __qed_vf_get_link_params(p_hwfn, params,
1316 &(p_hwfn->vf_iov_info->bulletin_shadow));
1319 void __qed_vf_get_link_state(struct qed_hwfn *p_hwfn,
1320 struct qed_mcp_link_state *p_link,
1321 struct qed_bulletin_content *p_bulletin)
1323 memset(p_link, 0, sizeof(*p_link));
1325 p_link->link_up = p_bulletin->link_up;
1326 p_link->speed = p_bulletin->speed;
1327 p_link->full_duplex = p_bulletin->full_duplex;
1328 p_link->an = p_bulletin->autoneg;
1329 p_link->an_complete = p_bulletin->autoneg_complete;
1330 p_link->parallel_detection = p_bulletin->parallel_detection;
1331 p_link->pfc_enabled = p_bulletin->pfc_enabled;
1332 p_link->partner_adv_speed = p_bulletin->partner_adv_speed;
1333 p_link->partner_tx_flow_ctrl_en = p_bulletin->partner_tx_flow_ctrl_en;
1334 p_link->partner_rx_flow_ctrl_en = p_bulletin->partner_rx_flow_ctrl_en;
1335 p_link->partner_adv_pause = p_bulletin->partner_adv_pause;
1336 p_link->sfp_tx_fault = p_bulletin->sfp_tx_fault;
1339 void qed_vf_get_link_state(struct qed_hwfn *p_hwfn,
1340 struct qed_mcp_link_state *link)
1342 __qed_vf_get_link_state(p_hwfn, link,
1343 &(p_hwfn->vf_iov_info->bulletin_shadow));
1346 void __qed_vf_get_link_caps(struct qed_hwfn *p_hwfn,
1347 struct qed_mcp_link_capabilities *p_link_caps,
1348 struct qed_bulletin_content *p_bulletin)
1350 memset(p_link_caps, 0, sizeof(*p_link_caps));
1351 p_link_caps->speed_capabilities = p_bulletin->capability_speed;
1354 void qed_vf_get_link_caps(struct qed_hwfn *p_hwfn,
1355 struct qed_mcp_link_capabilities *p_link_caps)
1357 __qed_vf_get_link_caps(p_hwfn, p_link_caps,
1358 &(p_hwfn->vf_iov_info->bulletin_shadow));
1361 void qed_vf_get_num_rxqs(struct qed_hwfn *p_hwfn, u8 *num_rxqs)
1363 *num_rxqs = p_hwfn->vf_iov_info->acquire_resp.resc.num_rxqs;
1366 void qed_vf_get_port_mac(struct qed_hwfn *p_hwfn, u8 *port_mac)
1369 p_hwfn->vf_iov_info->acquire_resp.pfdev_info.port_mac, ETH_ALEN);
1372 void qed_vf_get_num_vlan_filters(struct qed_hwfn *p_hwfn, u8 *num_vlan_filters)
1374 struct qed_vf_iov *p_vf;
1376 p_vf = p_hwfn->vf_iov_info;
1377 *num_vlan_filters = p_vf->acquire_resp.resc.num_vlan_filters;
1380 void qed_vf_get_num_mac_filters(struct qed_hwfn *p_hwfn, u8 *num_mac_filters)
1382 struct qed_vf_iov *p_vf = p_hwfn->vf_iov_info;
1384 *num_mac_filters = p_vf->acquire_resp.resc.num_mac_filters;
1387 bool qed_vf_check_mac(struct qed_hwfn *p_hwfn, u8 *mac)
1389 struct qed_bulletin_content *bulletin;
1391 bulletin = &p_hwfn->vf_iov_info->bulletin_shadow;
1392 if (!(bulletin->valid_bitmap & (1 << MAC_ADDR_FORCED)))
1395 /* Forbid VF from changing a MAC enforced by PF */
1396 if (ether_addr_equal(bulletin->mac, mac))
1402 static bool qed_vf_bulletin_get_forced_mac(struct qed_hwfn *hwfn,
1403 u8 *dst_mac, u8 *p_is_forced)
1405 struct qed_bulletin_content *bulletin;
1407 bulletin = &hwfn->vf_iov_info->bulletin_shadow;
1409 if (bulletin->valid_bitmap & (1 << MAC_ADDR_FORCED)) {
1412 } else if (bulletin->valid_bitmap & (1 << VFPF_BULLETIN_MAC_ADDR)) {
1419 ether_addr_copy(dst_mac, bulletin->mac);
1425 qed_vf_bulletin_get_udp_ports(struct qed_hwfn *p_hwfn,
1426 u16 *p_vxlan_port, u16 *p_geneve_port)
1428 struct qed_bulletin_content *p_bulletin;
1430 p_bulletin = &p_hwfn->vf_iov_info->bulletin_shadow;
1432 *p_vxlan_port = p_bulletin->vxlan_udp_port;
1433 *p_geneve_port = p_bulletin->geneve_udp_port;
1436 void qed_vf_get_fw_version(struct qed_hwfn *p_hwfn,
1437 u16 *fw_major, u16 *fw_minor,
1438 u16 *fw_rev, u16 *fw_eng)
1440 struct pf_vf_pfdev_info *info;
1442 info = &p_hwfn->vf_iov_info->acquire_resp.pfdev_info;
1444 *fw_major = info->fw_major;
1445 *fw_minor = info->fw_minor;
1446 *fw_rev = info->fw_rev;
1447 *fw_eng = info->fw_eng;
1450 static void qed_handle_bulletin_change(struct qed_hwfn *hwfn)
1452 struct qed_eth_cb_ops *ops = hwfn->cdev->protocol_ops.eth;
1453 u8 mac[ETH_ALEN], is_mac_exist, is_mac_forced;
1454 void *cookie = hwfn->cdev->ops_cookie;
1455 u16 vxlan_port, geneve_port;
1457 qed_vf_bulletin_get_udp_ports(hwfn, &vxlan_port, &geneve_port);
1458 is_mac_exist = qed_vf_bulletin_get_forced_mac(hwfn, mac,
1460 if (is_mac_exist && cookie)
1461 ops->force_mac(cookie, mac, !!is_mac_forced);
1463 ops->ports_update(cookie, vxlan_port, geneve_port);
1465 /* Always update link configuration according to bulletin */
1466 qed_link_update(hwfn);
1469 void qed_iov_vf_task(struct work_struct *work)
1471 struct qed_hwfn *hwfn = container_of(work, struct qed_hwfn,
1475 if (test_and_clear_bit(QED_IOV_WQ_STOP_WQ_FLAG, &hwfn->iov_task_flags))
1478 /* Handle bulletin board changes */
1479 qed_vf_read_bulletin(hwfn, &change);
1480 if (test_and_clear_bit(QED_IOV_WQ_VF_FORCE_LINK_QUERY_FLAG,
1481 &hwfn->iov_task_flags))
1484 qed_handle_bulletin_change(hwfn);
1486 /* As VF is polling bulletin board, need to constantly re-schedule */
1487 queue_delayed_work(hwfn->iov_wq, &hwfn->iov_task, HZ);