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 static void qed_vf_pf_add_qid(struct qed_hwfn *p_hwfn,
157 struct qed_queue_cid *p_cid)
159 struct qed_vf_iov *p_iov = p_hwfn->vf_iov_info;
160 struct vfpf_qid_tlv *p_qid_tlv;
162 /* Only add QIDs for the queue if it was negotiated with PF */
163 if (!(p_iov->acquire_resp.pfdev_info.capabilities &
164 PFVF_ACQUIRE_CAP_QUEUE_QIDS))
167 p_qid_tlv = qed_add_tlv(p_hwfn, &p_iov->offset,
168 CHANNEL_TLV_QID, sizeof(*p_qid_tlv));
169 p_qid_tlv->qid = p_cid->qid_usage_idx;
172 static int _qed_vf_pf_release(struct qed_hwfn *p_hwfn, bool b_final)
174 struct qed_vf_iov *p_iov = p_hwfn->vf_iov_info;
175 struct pfvf_def_resp_tlv *resp;
176 struct vfpf_first_tlv *req;
180 /* clear mailbox and prep first tlv */
181 req = qed_vf_pf_prep(p_hwfn, CHANNEL_TLV_RELEASE, sizeof(*req));
183 /* add list termination tlv */
184 qed_add_tlv(p_hwfn, &p_iov->offset,
185 CHANNEL_TLV_LIST_END, sizeof(struct channel_list_end_tlv));
187 resp = &p_iov->pf2vf_reply->default_resp;
188 rc = qed_send_msg2pf(p_hwfn, &resp->hdr.status, sizeof(*resp));
190 if (!rc && resp->hdr.status != PFVF_STATUS_SUCCESS)
193 qed_vf_pf_req_end(p_hwfn, rc);
197 p_hwfn->b_int_enabled = 0;
199 if (p_iov->vf2pf_request)
200 dma_free_coherent(&p_hwfn->cdev->pdev->dev,
201 sizeof(union vfpf_tlvs),
202 p_iov->vf2pf_request,
203 p_iov->vf2pf_request_phys);
204 if (p_iov->pf2vf_reply)
205 dma_free_coherent(&p_hwfn->cdev->pdev->dev,
206 sizeof(union pfvf_tlvs),
207 p_iov->pf2vf_reply, p_iov->pf2vf_reply_phys);
209 if (p_iov->bulletin.p_virt) {
210 size = sizeof(struct qed_bulletin_content);
211 dma_free_coherent(&p_hwfn->cdev->pdev->dev,
213 p_iov->bulletin.p_virt, p_iov->bulletin.phys);
216 kfree(p_hwfn->vf_iov_info);
217 p_hwfn->vf_iov_info = NULL;
222 int qed_vf_pf_release(struct qed_hwfn *p_hwfn)
224 return _qed_vf_pf_release(p_hwfn, true);
227 #define VF_ACQUIRE_THRESH 3
228 static void qed_vf_pf_acquire_reduce_resc(struct qed_hwfn *p_hwfn,
229 struct vf_pf_resc_request *p_req,
230 struct pf_vf_resc *p_resp)
234 "PF unwilling to fullill resource request: rxq [%02x/%02x] txq [%02x/%02x] sbs [%02x/%02x] mac [%02x/%02x] vlan [%02x/%02x] mc [%02x/%02x] cids [%02x/%02x]. Try PF recommended amount\n",
241 p_req->num_mac_filters,
242 p_resp->num_mac_filters,
243 p_req->num_vlan_filters,
244 p_resp->num_vlan_filters,
245 p_req->num_mc_filters,
246 p_resp->num_mc_filters, p_req->num_cids, p_resp->num_cids);
248 /* humble our request */
249 p_req->num_txqs = p_resp->num_txqs;
250 p_req->num_rxqs = p_resp->num_rxqs;
251 p_req->num_sbs = p_resp->num_sbs;
252 p_req->num_mac_filters = p_resp->num_mac_filters;
253 p_req->num_vlan_filters = p_resp->num_vlan_filters;
254 p_req->num_mc_filters = p_resp->num_mc_filters;
255 p_req->num_cids = p_resp->num_cids;
258 static int qed_vf_pf_acquire(struct qed_hwfn *p_hwfn)
260 struct qed_vf_iov *p_iov = p_hwfn->vf_iov_info;
261 struct pfvf_acquire_resp_tlv *resp = &p_iov->pf2vf_reply->acquire_resp;
262 struct pf_vf_pfdev_info *pfdev_info = &resp->pfdev_info;
263 struct vf_pf_resc_request *p_resc;
264 bool resources_acquired = false;
265 struct vfpf_acquire_tlv *req;
266 int rc = 0, attempts = 0;
268 /* clear mailbox and prep first tlv */
269 req = qed_vf_pf_prep(p_hwfn, CHANNEL_TLV_ACQUIRE, sizeof(*req));
270 p_resc = &req->resc_request;
272 /* starting filling the request */
273 req->vfdev_info.opaque_fid = p_hwfn->hw_info.opaque_fid;
275 p_resc->num_rxqs = QED_MAX_VF_CHAINS_PER_PF;
276 p_resc->num_txqs = QED_MAX_VF_CHAINS_PER_PF;
277 p_resc->num_sbs = QED_MAX_VF_CHAINS_PER_PF;
278 p_resc->num_mac_filters = QED_ETH_VF_NUM_MAC_FILTERS;
279 p_resc->num_vlan_filters = QED_ETH_VF_NUM_VLAN_FILTERS;
280 p_resc->num_cids = QED_ETH_VF_DEFAULT_NUM_CIDS;
282 req->vfdev_info.os_type = VFPF_ACQUIRE_OS_LINUX;
283 req->vfdev_info.fw_major = FW_MAJOR_VERSION;
284 req->vfdev_info.fw_minor = FW_MINOR_VERSION;
285 req->vfdev_info.fw_revision = FW_REVISION_VERSION;
286 req->vfdev_info.fw_engineering = FW_ENGINEERING_VERSION;
287 req->vfdev_info.eth_fp_hsi_major = ETH_HSI_VER_MAJOR;
288 req->vfdev_info.eth_fp_hsi_minor = ETH_HSI_VER_MINOR;
290 /* Fill capability field with any non-deprecated config we support */
291 req->vfdev_info.capabilities |= VFPF_ACQUIRE_CAP_100G;
293 /* If we've mapped the doorbell bar, try using queue qids */
294 if (p_iov->b_doorbell_bar) {
295 req->vfdev_info.capabilities |= VFPF_ACQUIRE_CAP_PHYSICAL_BAR |
296 VFPF_ACQUIRE_CAP_QUEUE_QIDS;
297 p_resc->num_cids = QED_ETH_VF_MAX_NUM_CIDS;
300 /* pf 2 vf bulletin board address */
301 req->bulletin_addr = p_iov->bulletin.phys;
302 req->bulletin_size = p_iov->bulletin.size;
304 /* add list termination tlv */
305 qed_add_tlv(p_hwfn, &p_iov->offset,
306 CHANNEL_TLV_LIST_END, sizeof(struct channel_list_end_tlv));
308 while (!resources_acquired) {
310 QED_MSG_IOV, "attempting to acquire resources\n");
312 /* Clear response buffer, as this might be a re-send */
313 memset(p_iov->pf2vf_reply, 0, sizeof(union pfvf_tlvs));
315 /* send acquire request */
316 rc = qed_send_msg2pf(p_hwfn, &resp->hdr.status, sizeof(*resp));
320 /* copy acquire response from buffer to p_hwfn */
321 memcpy(&p_iov->acquire_resp, resp, sizeof(p_iov->acquire_resp));
325 if (resp->hdr.status == PFVF_STATUS_SUCCESS) {
326 /* PF agrees to allocate our resources */
327 if (!(resp->pfdev_info.capabilities &
328 PFVF_ACQUIRE_CAP_POST_FW_OVERRIDE)) {
329 /* It's possible legacy PF mistakenly accepted;
330 * but we don't care - simply mark it as
331 * legacy and continue.
333 req->vfdev_info.capabilities |=
334 VFPF_ACQUIRE_CAP_PRE_FP_HSI;
336 DP_VERBOSE(p_hwfn, QED_MSG_IOV, "resources acquired\n");
337 resources_acquired = true;
338 } else if (resp->hdr.status == PFVF_STATUS_NO_RESOURCE &&
339 attempts < VF_ACQUIRE_THRESH) {
340 qed_vf_pf_acquire_reduce_resc(p_hwfn, p_resc,
342 } else if (resp->hdr.status == PFVF_STATUS_NOT_SUPPORTED) {
343 if (pfdev_info->major_fp_hsi &&
344 (pfdev_info->major_fp_hsi != ETH_HSI_VER_MAJOR)) {
346 "PF uses an incompatible fastpath HSI %02x.%02x [VF requires %02x.%02x]. Please change to a VF driver using %02x.xx.\n",
347 pfdev_info->major_fp_hsi,
348 pfdev_info->minor_fp_hsi,
351 pfdev_info->major_fp_hsi);
356 if (!pfdev_info->major_fp_hsi) {
357 if (req->vfdev_info.capabilities &
358 VFPF_ACQUIRE_CAP_PRE_FP_HSI) {
360 "PF uses very old drivers. Please change to a VF driver using no later than 8.8.x.x.\n");
365 "PF is old - try re-acquire to see if it supports FW-version override\n");
366 req->vfdev_info.capabilities |=
367 VFPF_ACQUIRE_CAP_PRE_FP_HSI;
372 /* If PF/VF are using same Major, PF must have had
373 * it's reasons. Simply fail.
375 DP_NOTICE(p_hwfn, "PF rejected acquisition by VF\n");
380 "PF returned error %d to VF acquisition request\n",
387 /* Mark the PF as legacy, if needed */
388 if (req->vfdev_info.capabilities & VFPF_ACQUIRE_CAP_PRE_FP_HSI)
389 p_iov->b_pre_fp_hsi = true;
391 /* In case PF doesn't support multi-queue Tx, update the number of
392 * CIDs to reflect the number of queues [older PFs didn't fill that
395 if (!(resp->pfdev_info.capabilities & PFVF_ACQUIRE_CAP_QUEUE_QIDS))
396 resp->resc.num_cids = resp->resc.num_rxqs + resp->resc.num_txqs;
398 /* Update bulletin board size with response from PF */
399 p_iov->bulletin.size = resp->bulletin_size;
402 p_hwfn->cdev->type = resp->pfdev_info.dev_type;
403 p_hwfn->cdev->chip_rev = resp->pfdev_info.chip_rev;
405 p_hwfn->cdev->chip_num = pfdev_info->chip_num & 0xffff;
407 /* Learn of the possibility of CMT */
408 if (IS_LEAD_HWFN(p_hwfn)) {
409 if (resp->pfdev_info.capabilities & PFVF_ACQUIRE_CAP_100G) {
410 DP_NOTICE(p_hwfn, "100g VF\n");
411 p_hwfn->cdev->num_hwfns = 2;
415 if (!p_iov->b_pre_fp_hsi &&
417 (resp->pfdev_info.minor_fp_hsi < ETH_HSI_VER_MINOR)) {
419 "PF is using older fastpath HSI; %02x.%02x is configured\n",
420 ETH_HSI_VER_MAJOR, resp->pfdev_info.minor_fp_hsi);
424 qed_vf_pf_req_end(p_hwfn, rc);
429 u32 qed_vf_hw_bar_size(struct qed_hwfn *p_hwfn, enum BAR_ID bar_id)
433 /* Regview size is fixed */
434 if (bar_id == BAR_ID_0)
437 /* Doorbell is received from PF */
438 bar_size = p_hwfn->vf_iov_info->acquire_resp.pfdev_info.bar_size;
440 return 1 << bar_size;
444 int qed_vf_hw_prepare(struct qed_hwfn *p_hwfn)
446 struct qed_hwfn *p_lead = QED_LEADING_HWFN(p_hwfn->cdev);
447 struct qed_vf_iov *p_iov;
451 /* Set number of hwfns - might be overriden once leading hwfn learns
452 * actual configuration from PF.
454 if (IS_LEAD_HWFN(p_hwfn))
455 p_hwfn->cdev->num_hwfns = 1;
457 reg = PXP_VF_BAR0_ME_OPAQUE_ADDRESS;
458 p_hwfn->hw_info.opaque_fid = (u16)REG_RD(p_hwfn, reg);
460 reg = PXP_VF_BAR0_ME_CONCRETE_ADDRESS;
461 p_hwfn->hw_info.concrete_fid = REG_RD(p_hwfn, reg);
463 /* Allocate vf sriov info */
464 p_iov = kzalloc(sizeof(*p_iov), GFP_KERNEL);
468 /* Doorbells are tricky; Upper-layer has alreday set the hwfn doorbell
469 * value, but there are several incompatibily scenarios where that
470 * would be incorrect and we'd need to override it.
472 if (!p_hwfn->doorbells) {
473 p_hwfn->doorbells = (u8 __iomem *)p_hwfn->regview +
474 PXP_VF_BAR0_START_DQ;
475 } else if (p_hwfn == p_lead) {
476 /* For leading hw-function, value is always correct, but need
477 * to handle scenario where legacy PF would not support 100g
480 p_iov->b_doorbell_bar = true;
482 /* here, value would be correct ONLY if the leading hwfn
483 * received indication that mapped-bars are supported.
485 if (p_lead->vf_iov_info->b_doorbell_bar)
486 p_iov->b_doorbell_bar = true;
488 p_hwfn->doorbells = (u8 __iomem *)
489 p_hwfn->regview + PXP_VF_BAR0_START_DQ;
492 /* Allocate vf2pf msg */
493 p_iov->vf2pf_request = dma_alloc_coherent(&p_hwfn->cdev->pdev->dev,
494 sizeof(union vfpf_tlvs),
495 &p_iov->vf2pf_request_phys,
497 if (!p_iov->vf2pf_request)
500 p_iov->pf2vf_reply = dma_alloc_coherent(&p_hwfn->cdev->pdev->dev,
501 sizeof(union pfvf_tlvs),
502 &p_iov->pf2vf_reply_phys,
504 if (!p_iov->pf2vf_reply)
505 goto free_vf2pf_request;
509 "VF's Request mailbox [%p virt 0x%llx phys], Response mailbox [%p virt 0x%llx phys]\n",
510 p_iov->vf2pf_request,
511 (u64) p_iov->vf2pf_request_phys,
512 p_iov->pf2vf_reply, (u64)p_iov->pf2vf_reply_phys);
514 /* Allocate Bulletin board */
515 p_iov->bulletin.size = sizeof(struct qed_bulletin_content);
516 p_iov->bulletin.p_virt = dma_alloc_coherent(&p_hwfn->cdev->pdev->dev,
517 p_iov->bulletin.size,
518 &p_iov->bulletin.phys,
520 DP_VERBOSE(p_hwfn, QED_MSG_IOV,
521 "VF's bulletin Board [%p virt 0x%llx phys 0x%08x bytes]\n",
522 p_iov->bulletin.p_virt,
523 (u64)p_iov->bulletin.phys, p_iov->bulletin.size);
525 mutex_init(&p_iov->mutex);
527 p_hwfn->vf_iov_info = p_iov;
529 p_hwfn->hw_info.personality = QED_PCI_ETH;
531 rc = qed_vf_pf_acquire(p_hwfn);
533 /* If VF is 100g using a mapped bar and PF is too old to support that,
534 * acquisition would succeed - but the VF would have no way knowing
535 * the size of the doorbell bar configured in HW and thus will not
536 * know how to split it for 2nd hw-function.
537 * In this case we re-try without the indication of the mapped
540 if (!rc && p_iov->b_doorbell_bar &&
541 !qed_vf_hw_bar_size(p_hwfn, BAR_ID_1) &&
542 (p_hwfn->cdev->num_hwfns > 1)) {
543 rc = _qed_vf_pf_release(p_hwfn, false);
547 p_iov->b_doorbell_bar = false;
548 p_hwfn->doorbells = (u8 __iomem *)p_hwfn->regview +
549 PXP_VF_BAR0_START_DQ;
550 rc = qed_vf_pf_acquire(p_hwfn);
553 DP_VERBOSE(p_hwfn, QED_MSG_IOV,
554 "Regview [%p], Doorbell [%p], Device-doorbell [%p]\n",
555 p_hwfn->regview, p_hwfn->doorbells, p_hwfn->cdev->doorbells);
560 dma_free_coherent(&p_hwfn->cdev->pdev->dev,
561 sizeof(union vfpf_tlvs),
562 p_iov->vf2pf_request, p_iov->vf2pf_request_phys);
568 #define TSTORM_QZONE_START PXP_VF_BAR0_START_SDM_ZONE_A
569 #define MSTORM_QZONE_START(dev) (TSTORM_QZONE_START + \
570 (TSTORM_QZONE_SIZE * NUM_OF_L2_QUEUES(dev)))
573 __qed_vf_prep_tunn_req_tlv(struct vfpf_update_tunn_param_tlv *p_req,
574 struct qed_tunn_update_type *p_src,
575 enum qed_tunn_clss mask, u8 *p_cls)
577 if (p_src->b_update_mode) {
578 p_req->tun_mode_update_mask |= BIT(mask);
580 if (p_src->b_mode_enabled)
581 p_req->tunn_mode |= BIT(mask);
584 *p_cls = p_src->tun_cls;
588 qed_vf_prep_tunn_req_tlv(struct vfpf_update_tunn_param_tlv *p_req,
589 struct qed_tunn_update_type *p_src,
590 enum qed_tunn_clss mask,
591 u8 *p_cls, struct qed_tunn_update_udp_port *p_port,
592 u8 *p_update_port, u16 *p_udp_port)
594 if (p_port->b_update_port) {
596 *p_udp_port = p_port->port;
599 __qed_vf_prep_tunn_req_tlv(p_req, p_src, mask, p_cls);
602 void qed_vf_set_vf_start_tunn_update_param(struct qed_tunnel_info *p_tun)
604 if (p_tun->vxlan.b_mode_enabled)
605 p_tun->vxlan.b_update_mode = true;
606 if (p_tun->l2_geneve.b_mode_enabled)
607 p_tun->l2_geneve.b_update_mode = true;
608 if (p_tun->ip_geneve.b_mode_enabled)
609 p_tun->ip_geneve.b_update_mode = true;
610 if (p_tun->l2_gre.b_mode_enabled)
611 p_tun->l2_gre.b_update_mode = true;
612 if (p_tun->ip_gre.b_mode_enabled)
613 p_tun->ip_gre.b_update_mode = true;
615 p_tun->b_update_rx_cls = true;
616 p_tun->b_update_tx_cls = true;
620 __qed_vf_update_tunn_param(struct qed_tunn_update_type *p_tun,
621 u16 feature_mask, u8 tunn_mode,
622 u8 tunn_cls, enum qed_tunn_mode val)
624 if (feature_mask & BIT(val)) {
625 p_tun->b_mode_enabled = tunn_mode;
626 p_tun->tun_cls = tunn_cls;
628 p_tun->b_mode_enabled = false;
632 static void qed_vf_update_tunn_param(struct qed_hwfn *p_hwfn,
633 struct qed_tunnel_info *p_tun,
634 struct pfvf_update_tunn_param_tlv *p_resp)
636 /* Update mode and classes provided by PF */
637 u16 feat_mask = p_resp->tunn_feature_mask;
639 __qed_vf_update_tunn_param(&p_tun->vxlan, feat_mask,
640 p_resp->vxlan_mode, p_resp->vxlan_clss,
641 QED_MODE_VXLAN_TUNN);
642 __qed_vf_update_tunn_param(&p_tun->l2_geneve, feat_mask,
643 p_resp->l2geneve_mode,
644 p_resp->l2geneve_clss,
645 QED_MODE_L2GENEVE_TUNN);
646 __qed_vf_update_tunn_param(&p_tun->ip_geneve, feat_mask,
647 p_resp->ipgeneve_mode,
648 p_resp->ipgeneve_clss,
649 QED_MODE_IPGENEVE_TUNN);
650 __qed_vf_update_tunn_param(&p_tun->l2_gre, feat_mask,
651 p_resp->l2gre_mode, p_resp->l2gre_clss,
652 QED_MODE_L2GRE_TUNN);
653 __qed_vf_update_tunn_param(&p_tun->ip_gre, feat_mask,
654 p_resp->ipgre_mode, p_resp->ipgre_clss,
655 QED_MODE_IPGRE_TUNN);
656 p_tun->geneve_port.port = p_resp->geneve_udp_port;
657 p_tun->vxlan_port.port = p_resp->vxlan_udp_port;
659 DP_VERBOSE(p_hwfn, QED_MSG_IOV,
660 "tunn mode: vxlan=0x%x, l2geneve=0x%x, ipgeneve=0x%x, l2gre=0x%x, ipgre=0x%x",
661 p_tun->vxlan.b_mode_enabled, p_tun->l2_geneve.b_mode_enabled,
662 p_tun->ip_geneve.b_mode_enabled,
663 p_tun->l2_gre.b_mode_enabled, p_tun->ip_gre.b_mode_enabled);
666 int qed_vf_pf_tunnel_param_update(struct qed_hwfn *p_hwfn,
667 struct qed_tunnel_info *p_src)
669 struct qed_tunnel_info *p_tun = &p_hwfn->cdev->tunnel;
670 struct qed_vf_iov *p_iov = p_hwfn->vf_iov_info;
671 struct pfvf_update_tunn_param_tlv *p_resp;
672 struct vfpf_update_tunn_param_tlv *p_req;
675 p_req = qed_vf_pf_prep(p_hwfn, CHANNEL_TLV_UPDATE_TUNN_PARAM,
678 if (p_src->b_update_rx_cls && p_src->b_update_tx_cls)
679 p_req->update_tun_cls = 1;
681 qed_vf_prep_tunn_req_tlv(p_req, &p_src->vxlan, QED_MODE_VXLAN_TUNN,
682 &p_req->vxlan_clss, &p_src->vxlan_port,
683 &p_req->update_vxlan_port,
685 qed_vf_prep_tunn_req_tlv(p_req, &p_src->l2_geneve,
686 QED_MODE_L2GENEVE_TUNN,
687 &p_req->l2geneve_clss, &p_src->geneve_port,
688 &p_req->update_geneve_port,
689 &p_req->geneve_port);
690 __qed_vf_prep_tunn_req_tlv(p_req, &p_src->ip_geneve,
691 QED_MODE_IPGENEVE_TUNN,
692 &p_req->ipgeneve_clss);
693 __qed_vf_prep_tunn_req_tlv(p_req, &p_src->l2_gre,
694 QED_MODE_L2GRE_TUNN, &p_req->l2gre_clss);
695 __qed_vf_prep_tunn_req_tlv(p_req, &p_src->ip_gre,
696 QED_MODE_IPGRE_TUNN, &p_req->ipgre_clss);
698 /* add list termination tlv */
699 qed_add_tlv(p_hwfn, &p_iov->offset,
700 CHANNEL_TLV_LIST_END,
701 sizeof(struct channel_list_end_tlv));
703 p_resp = &p_iov->pf2vf_reply->tunn_param_resp;
704 rc = qed_send_msg2pf(p_hwfn, &p_resp->hdr.status, sizeof(*p_resp));
709 if (p_resp->hdr.status != PFVF_STATUS_SUCCESS) {
710 DP_VERBOSE(p_hwfn, QED_MSG_IOV,
711 "Failed to update tunnel parameters\n");
715 qed_vf_update_tunn_param(p_hwfn, p_tun, p_resp);
717 qed_vf_pf_req_end(p_hwfn, rc);
722 qed_vf_pf_rxq_start(struct qed_hwfn *p_hwfn,
723 struct qed_queue_cid *p_cid,
725 dma_addr_t bd_chain_phys_addr,
726 dma_addr_t cqe_pbl_addr,
727 u16 cqe_pbl_size, void __iomem **pp_prod)
729 struct qed_vf_iov *p_iov = p_hwfn->vf_iov_info;
730 struct pfvf_start_queue_resp_tlv *resp;
731 struct vfpf_start_rxq_tlv *req;
732 u8 rx_qid = p_cid->rel.queue_id;
735 /* clear mailbox and prep first tlv */
736 req = qed_vf_pf_prep(p_hwfn, CHANNEL_TLV_START_RXQ, sizeof(*req));
738 req->rx_qid = rx_qid;
739 req->cqe_pbl_addr = cqe_pbl_addr;
740 req->cqe_pbl_size = cqe_pbl_size;
741 req->rxq_addr = bd_chain_phys_addr;
742 req->hw_sb = p_cid->sb_igu_id;
743 req->sb_index = p_cid->sb_idx;
744 req->bd_max_bytes = bd_max_bytes;
747 /* If PF is legacy, we'll need to calculate producers ourselves
748 * as well as clean them.
750 if (p_iov->b_pre_fp_hsi) {
751 u8 hw_qid = p_iov->acquire_resp.resc.hw_qid[rx_qid];
752 u32 init_prod_val = 0;
754 *pp_prod = (u8 __iomem *)
756 MSTORM_QZONE_START(p_hwfn->cdev) +
757 hw_qid * MSTORM_QZONE_SIZE;
759 /* Init the rcq, rx bd and rx sge (if valid) producers to 0 */
760 __internal_ram_wr(p_hwfn, *pp_prod, sizeof(u32),
761 (u32 *)(&init_prod_val));
764 qed_vf_pf_add_qid(p_hwfn, p_cid);
766 /* add list termination tlv */
767 qed_add_tlv(p_hwfn, &p_iov->offset,
768 CHANNEL_TLV_LIST_END, sizeof(struct channel_list_end_tlv));
770 resp = &p_iov->pf2vf_reply->queue_start;
771 rc = qed_send_msg2pf(p_hwfn, &resp->hdr.status, sizeof(*resp));
775 if (resp->hdr.status != PFVF_STATUS_SUCCESS) {
780 /* Learn the address of the producer from the response */
781 if (!p_iov->b_pre_fp_hsi) {
782 u32 init_prod_val = 0;
784 *pp_prod = (u8 __iomem *)p_hwfn->regview + resp->offset;
785 DP_VERBOSE(p_hwfn, QED_MSG_IOV,
786 "Rxq[0x%02x]: producer at %p [offset 0x%08x]\n",
787 rx_qid, *pp_prod, resp->offset);
789 /* Init the rcq, rx bd and rx sge (if valid) producers to 0 */
790 __internal_ram_wr(p_hwfn, *pp_prod, sizeof(u32),
791 (u32 *)&init_prod_val);
794 qed_vf_pf_req_end(p_hwfn, rc);
799 int qed_vf_pf_rxq_stop(struct qed_hwfn *p_hwfn,
800 struct qed_queue_cid *p_cid, bool cqe_completion)
802 struct qed_vf_iov *p_iov = p_hwfn->vf_iov_info;
803 struct vfpf_stop_rxqs_tlv *req;
804 struct pfvf_def_resp_tlv *resp;
807 /* clear mailbox and prep first tlv */
808 req = qed_vf_pf_prep(p_hwfn, CHANNEL_TLV_STOP_RXQS, sizeof(*req));
810 req->rx_qid = p_cid->rel.queue_id;
812 req->cqe_completion = cqe_completion;
814 qed_vf_pf_add_qid(p_hwfn, p_cid);
816 /* add list termination tlv */
817 qed_add_tlv(p_hwfn, &p_iov->offset,
818 CHANNEL_TLV_LIST_END, sizeof(struct channel_list_end_tlv));
820 resp = &p_iov->pf2vf_reply->default_resp;
821 rc = qed_send_msg2pf(p_hwfn, &resp->hdr.status, sizeof(*resp));
825 if (resp->hdr.status != PFVF_STATUS_SUCCESS) {
831 qed_vf_pf_req_end(p_hwfn, rc);
837 qed_vf_pf_txq_start(struct qed_hwfn *p_hwfn,
838 struct qed_queue_cid *p_cid,
840 u16 pbl_size, void __iomem **pp_doorbell)
842 struct qed_vf_iov *p_iov = p_hwfn->vf_iov_info;
843 struct pfvf_start_queue_resp_tlv *resp;
844 struct vfpf_start_txq_tlv *req;
845 u16 qid = p_cid->rel.queue_id;
848 /* clear mailbox and prep first tlv */
849 req = qed_vf_pf_prep(p_hwfn, CHANNEL_TLV_START_TXQ, sizeof(*req));
854 req->pbl_addr = pbl_addr;
855 req->pbl_size = pbl_size;
856 req->hw_sb = p_cid->sb_igu_id;
857 req->sb_index = p_cid->sb_idx;
859 qed_vf_pf_add_qid(p_hwfn, p_cid);
861 /* add list termination tlv */
862 qed_add_tlv(p_hwfn, &p_iov->offset,
863 CHANNEL_TLV_LIST_END, sizeof(struct channel_list_end_tlv));
865 resp = &p_iov->pf2vf_reply->queue_start;
866 rc = qed_send_msg2pf(p_hwfn, &resp->hdr.status, sizeof(*resp));
870 if (resp->hdr.status != PFVF_STATUS_SUCCESS) {
875 /* Modern PFs provide the actual offsets, while legacy
876 * provided only the queue id.
878 if (!p_iov->b_pre_fp_hsi) {
879 *pp_doorbell = (u8 __iomem *)p_hwfn->doorbells + resp->offset;
881 u8 cid = p_iov->acquire_resp.resc.cid[qid];
883 *pp_doorbell = (u8 __iomem *)p_hwfn->doorbells +
888 DP_VERBOSE(p_hwfn, QED_MSG_IOV,
889 "Txq[0x%02x.%02x]: doorbell at %p [offset 0x%08x]\n",
890 qid, p_cid->qid_usage_idx, *pp_doorbell, resp->offset);
892 qed_vf_pf_req_end(p_hwfn, rc);
897 int qed_vf_pf_txq_stop(struct qed_hwfn *p_hwfn, struct qed_queue_cid *p_cid)
899 struct qed_vf_iov *p_iov = p_hwfn->vf_iov_info;
900 struct vfpf_stop_txqs_tlv *req;
901 struct pfvf_def_resp_tlv *resp;
904 /* clear mailbox and prep first tlv */
905 req = qed_vf_pf_prep(p_hwfn, CHANNEL_TLV_STOP_TXQS, sizeof(*req));
907 req->tx_qid = p_cid->rel.queue_id;
910 qed_vf_pf_add_qid(p_hwfn, p_cid);
912 /* add list termination tlv */
913 qed_add_tlv(p_hwfn, &p_iov->offset,
914 CHANNEL_TLV_LIST_END, sizeof(struct channel_list_end_tlv));
916 resp = &p_iov->pf2vf_reply->default_resp;
917 rc = qed_send_msg2pf(p_hwfn, &resp->hdr.status, sizeof(*resp));
921 if (resp->hdr.status != PFVF_STATUS_SUCCESS) {
927 qed_vf_pf_req_end(p_hwfn, rc);
932 int qed_vf_pf_vport_start(struct qed_hwfn *p_hwfn,
935 u8 inner_vlan_removal,
936 enum qed_tpa_mode tpa_mode,
937 u8 max_buffers_per_cqe, u8 only_untagged)
939 struct qed_vf_iov *p_iov = p_hwfn->vf_iov_info;
940 struct vfpf_vport_start_tlv *req;
941 struct pfvf_def_resp_tlv *resp;
944 /* clear mailbox and prep first tlv */
945 req = qed_vf_pf_prep(p_hwfn, CHANNEL_TLV_VPORT_START, sizeof(*req));
948 req->vport_id = vport_id;
949 req->inner_vlan_removal = inner_vlan_removal;
950 req->tpa_mode = tpa_mode;
951 req->max_buffers_per_cqe = max_buffers_per_cqe;
952 req->only_untagged = only_untagged;
955 for (i = 0; i < p_hwfn->vf_iov_info->acquire_resp.resc.num_sbs; i++) {
956 struct qed_sb_info *p_sb = p_hwfn->vf_iov_info->sbs_info[i];
959 req->sb_addr[i] = p_sb->sb_phys;
962 /* add list termination tlv */
963 qed_add_tlv(p_hwfn, &p_iov->offset,
964 CHANNEL_TLV_LIST_END, sizeof(struct channel_list_end_tlv));
966 resp = &p_iov->pf2vf_reply->default_resp;
967 rc = qed_send_msg2pf(p_hwfn, &resp->hdr.status, sizeof(*resp));
971 if (resp->hdr.status != PFVF_STATUS_SUCCESS) {
977 qed_vf_pf_req_end(p_hwfn, rc);
982 int qed_vf_pf_vport_stop(struct qed_hwfn *p_hwfn)
984 struct qed_vf_iov *p_iov = p_hwfn->vf_iov_info;
985 struct pfvf_def_resp_tlv *resp = &p_iov->pf2vf_reply->default_resp;
988 /* clear mailbox and prep first tlv */
989 qed_vf_pf_prep(p_hwfn, CHANNEL_TLV_VPORT_TEARDOWN,
990 sizeof(struct vfpf_first_tlv));
992 /* add list termination tlv */
993 qed_add_tlv(p_hwfn, &p_iov->offset,
994 CHANNEL_TLV_LIST_END, sizeof(struct channel_list_end_tlv));
996 rc = qed_send_msg2pf(p_hwfn, &resp->hdr.status, sizeof(*resp));
1000 if (resp->hdr.status != PFVF_STATUS_SUCCESS) {
1006 qed_vf_pf_req_end(p_hwfn, rc);
1012 qed_vf_handle_vp_update_is_needed(struct qed_hwfn *p_hwfn,
1013 struct qed_sp_vport_update_params *p_data,
1017 case CHANNEL_TLV_VPORT_UPDATE_ACTIVATE:
1018 return !!(p_data->update_vport_active_rx_flg ||
1019 p_data->update_vport_active_tx_flg);
1020 case CHANNEL_TLV_VPORT_UPDATE_TX_SWITCH:
1021 return !!p_data->update_tx_switching_flg;
1022 case CHANNEL_TLV_VPORT_UPDATE_VLAN_STRIP:
1023 return !!p_data->update_inner_vlan_removal_flg;
1024 case CHANNEL_TLV_VPORT_UPDATE_ACCEPT_ANY_VLAN:
1025 return !!p_data->update_accept_any_vlan_flg;
1026 case CHANNEL_TLV_VPORT_UPDATE_MCAST:
1027 return !!p_data->update_approx_mcast_flg;
1028 case CHANNEL_TLV_VPORT_UPDATE_ACCEPT_PARAM:
1029 return !!(p_data->accept_flags.update_rx_mode_config ||
1030 p_data->accept_flags.update_tx_mode_config);
1031 case CHANNEL_TLV_VPORT_UPDATE_RSS:
1032 return !!p_data->rss_params;
1033 case CHANNEL_TLV_VPORT_UPDATE_SGE_TPA:
1034 return !!p_data->sge_tpa_params;
1036 DP_INFO(p_hwfn, "Unexpected vport-update TLV[%d]\n",
1043 qed_vf_handle_vp_update_tlvs_resp(struct qed_hwfn *p_hwfn,
1044 struct qed_sp_vport_update_params *p_data)
1046 struct qed_vf_iov *p_iov = p_hwfn->vf_iov_info;
1047 struct pfvf_def_resp_tlv *p_resp;
1050 for (tlv = CHANNEL_TLV_VPORT_UPDATE_ACTIVATE;
1051 tlv < CHANNEL_TLV_VPORT_UPDATE_MAX; tlv++) {
1052 if (!qed_vf_handle_vp_update_is_needed(p_hwfn, p_data, tlv))
1055 p_resp = (struct pfvf_def_resp_tlv *)
1056 qed_iov_search_list_tlvs(p_hwfn, p_iov->pf2vf_reply,
1058 if (p_resp && p_resp->hdr.status)
1059 DP_VERBOSE(p_hwfn, QED_MSG_IOV,
1060 "TLV[%d] Configuration %s\n",
1062 (p_resp && p_resp->hdr.status) ? "succeeded"
1067 int qed_vf_pf_vport_update(struct qed_hwfn *p_hwfn,
1068 struct qed_sp_vport_update_params *p_params)
1070 struct qed_vf_iov *p_iov = p_hwfn->vf_iov_info;
1071 struct vfpf_vport_update_tlv *req;
1072 struct pfvf_def_resp_tlv *resp;
1073 u8 update_rx, update_tx;
1078 resp = &p_iov->pf2vf_reply->default_resp;
1079 resp_size = sizeof(*resp);
1081 update_rx = p_params->update_vport_active_rx_flg;
1082 update_tx = p_params->update_vport_active_tx_flg;
1084 /* clear mailbox and prep header tlv */
1085 qed_vf_pf_prep(p_hwfn, CHANNEL_TLV_VPORT_UPDATE, sizeof(*req));
1087 /* Prepare extended tlvs */
1088 if (update_rx || update_tx) {
1089 struct vfpf_vport_update_activate_tlv *p_act_tlv;
1091 size = sizeof(struct vfpf_vport_update_activate_tlv);
1092 p_act_tlv = qed_add_tlv(p_hwfn, &p_iov->offset,
1093 CHANNEL_TLV_VPORT_UPDATE_ACTIVATE,
1095 resp_size += sizeof(struct pfvf_def_resp_tlv);
1098 p_act_tlv->update_rx = update_rx;
1099 p_act_tlv->active_rx = p_params->vport_active_rx_flg;
1103 p_act_tlv->update_tx = update_tx;
1104 p_act_tlv->active_tx = p_params->vport_active_tx_flg;
1108 if (p_params->update_tx_switching_flg) {
1109 struct vfpf_vport_update_tx_switch_tlv *p_tx_switch_tlv;
1111 size = sizeof(struct vfpf_vport_update_tx_switch_tlv);
1112 tlv = CHANNEL_TLV_VPORT_UPDATE_TX_SWITCH;
1113 p_tx_switch_tlv = qed_add_tlv(p_hwfn, &p_iov->offset,
1115 resp_size += sizeof(struct pfvf_def_resp_tlv);
1117 p_tx_switch_tlv->tx_switching = p_params->tx_switching_flg;
1120 if (p_params->update_approx_mcast_flg) {
1121 struct vfpf_vport_update_mcast_bin_tlv *p_mcast_tlv;
1123 size = sizeof(struct vfpf_vport_update_mcast_bin_tlv);
1124 p_mcast_tlv = qed_add_tlv(p_hwfn, &p_iov->offset,
1125 CHANNEL_TLV_VPORT_UPDATE_MCAST, size);
1126 resp_size += sizeof(struct pfvf_def_resp_tlv);
1128 memcpy(p_mcast_tlv->bins, p_params->bins,
1129 sizeof(u32) * ETH_MULTICAST_MAC_BINS_IN_REGS);
1132 update_rx = p_params->accept_flags.update_rx_mode_config;
1133 update_tx = p_params->accept_flags.update_tx_mode_config;
1135 if (update_rx || update_tx) {
1136 struct vfpf_vport_update_accept_param_tlv *p_accept_tlv;
1138 tlv = CHANNEL_TLV_VPORT_UPDATE_ACCEPT_PARAM;
1139 size = sizeof(struct vfpf_vport_update_accept_param_tlv);
1140 p_accept_tlv = qed_add_tlv(p_hwfn, &p_iov->offset, tlv, size);
1141 resp_size += sizeof(struct pfvf_def_resp_tlv);
1144 p_accept_tlv->update_rx_mode = update_rx;
1145 p_accept_tlv->rx_accept_filter =
1146 p_params->accept_flags.rx_accept_filter;
1150 p_accept_tlv->update_tx_mode = update_tx;
1151 p_accept_tlv->tx_accept_filter =
1152 p_params->accept_flags.tx_accept_filter;
1156 if (p_params->rss_params) {
1157 struct qed_rss_params *rss_params = p_params->rss_params;
1158 struct vfpf_vport_update_rss_tlv *p_rss_tlv;
1161 size = sizeof(struct vfpf_vport_update_rss_tlv);
1162 p_rss_tlv = qed_add_tlv(p_hwfn,
1164 CHANNEL_TLV_VPORT_UPDATE_RSS, size);
1165 resp_size += sizeof(struct pfvf_def_resp_tlv);
1167 if (rss_params->update_rss_config)
1168 p_rss_tlv->update_rss_flags |=
1169 VFPF_UPDATE_RSS_CONFIG_FLAG;
1170 if (rss_params->update_rss_capabilities)
1171 p_rss_tlv->update_rss_flags |=
1172 VFPF_UPDATE_RSS_CAPS_FLAG;
1173 if (rss_params->update_rss_ind_table)
1174 p_rss_tlv->update_rss_flags |=
1175 VFPF_UPDATE_RSS_IND_TABLE_FLAG;
1176 if (rss_params->update_rss_key)
1177 p_rss_tlv->update_rss_flags |= VFPF_UPDATE_RSS_KEY_FLAG;
1179 p_rss_tlv->rss_enable = rss_params->rss_enable;
1180 p_rss_tlv->rss_caps = rss_params->rss_caps;
1181 p_rss_tlv->rss_table_size_log = rss_params->rss_table_size_log;
1183 table_size = min_t(int, T_ETH_INDIRECTION_TABLE_SIZE,
1184 1 << p_rss_tlv->rss_table_size_log);
1185 for (i = 0; i < table_size; i++) {
1186 struct qed_queue_cid *p_queue;
1188 p_queue = rss_params->rss_ind_table[i];
1189 p_rss_tlv->rss_ind_table[i] = p_queue->rel.queue_id;
1191 memcpy(p_rss_tlv->rss_key, rss_params->rss_key,
1192 sizeof(rss_params->rss_key));
1195 if (p_params->update_accept_any_vlan_flg) {
1196 struct vfpf_vport_update_accept_any_vlan_tlv *p_any_vlan_tlv;
1198 size = sizeof(struct vfpf_vport_update_accept_any_vlan_tlv);
1199 tlv = CHANNEL_TLV_VPORT_UPDATE_ACCEPT_ANY_VLAN;
1200 p_any_vlan_tlv = qed_add_tlv(p_hwfn, &p_iov->offset, tlv, size);
1202 resp_size += sizeof(struct pfvf_def_resp_tlv);
1203 p_any_vlan_tlv->accept_any_vlan = p_params->accept_any_vlan;
1204 p_any_vlan_tlv->update_accept_any_vlan_flg =
1205 p_params->update_accept_any_vlan_flg;
1208 /* add list termination tlv */
1209 qed_add_tlv(p_hwfn, &p_iov->offset,
1210 CHANNEL_TLV_LIST_END, sizeof(struct channel_list_end_tlv));
1212 rc = qed_send_msg2pf(p_hwfn, &resp->hdr.status, resp_size);
1216 if (resp->hdr.status != PFVF_STATUS_SUCCESS) {
1221 qed_vf_handle_vp_update_tlvs_resp(p_hwfn, p_params);
1224 qed_vf_pf_req_end(p_hwfn, rc);
1229 int qed_vf_pf_reset(struct qed_hwfn *p_hwfn)
1231 struct qed_vf_iov *p_iov = p_hwfn->vf_iov_info;
1232 struct pfvf_def_resp_tlv *resp;
1233 struct vfpf_first_tlv *req;
1236 /* clear mailbox and prep first tlv */
1237 req = qed_vf_pf_prep(p_hwfn, CHANNEL_TLV_CLOSE, sizeof(*req));
1239 /* add list termination tlv */
1240 qed_add_tlv(p_hwfn, &p_iov->offset,
1241 CHANNEL_TLV_LIST_END, sizeof(struct channel_list_end_tlv));
1243 resp = &p_iov->pf2vf_reply->default_resp;
1244 rc = qed_send_msg2pf(p_hwfn, &resp->hdr.status, sizeof(*resp));
1248 if (resp->hdr.status != PFVF_STATUS_SUCCESS) {
1253 p_hwfn->b_int_enabled = 0;
1256 qed_vf_pf_req_end(p_hwfn, rc);
1261 void qed_vf_pf_filter_mcast(struct qed_hwfn *p_hwfn,
1262 struct qed_filter_mcast *p_filter_cmd)
1264 struct qed_sp_vport_update_params sp_params;
1267 memset(&sp_params, 0, sizeof(sp_params));
1268 sp_params.update_approx_mcast_flg = 1;
1270 if (p_filter_cmd->opcode == QED_FILTER_ADD) {
1271 for (i = 0; i < p_filter_cmd->num_mc_addrs; i++) {
1274 bit = qed_mcast_bin_from_mac(p_filter_cmd->mac[i]);
1275 sp_params.bins[bit / 32] |= 1 << (bit % 32);
1279 qed_vf_pf_vport_update(p_hwfn, &sp_params);
1282 int qed_vf_pf_filter_ucast(struct qed_hwfn *p_hwfn,
1283 struct qed_filter_ucast *p_ucast)
1285 struct qed_vf_iov *p_iov = p_hwfn->vf_iov_info;
1286 struct vfpf_ucast_filter_tlv *req;
1287 struct pfvf_def_resp_tlv *resp;
1290 /* clear mailbox and prep first tlv */
1291 req = qed_vf_pf_prep(p_hwfn, CHANNEL_TLV_UCAST_FILTER, sizeof(*req));
1292 req->opcode = (u8) p_ucast->opcode;
1293 req->type = (u8) p_ucast->type;
1294 memcpy(req->mac, p_ucast->mac, ETH_ALEN);
1295 req->vlan = p_ucast->vlan;
1297 /* add list termination tlv */
1298 qed_add_tlv(p_hwfn, &p_iov->offset,
1299 CHANNEL_TLV_LIST_END, sizeof(struct channel_list_end_tlv));
1301 resp = &p_iov->pf2vf_reply->default_resp;
1302 rc = qed_send_msg2pf(p_hwfn, &resp->hdr.status, sizeof(*resp));
1306 if (resp->hdr.status != PFVF_STATUS_SUCCESS) {
1312 qed_vf_pf_req_end(p_hwfn, rc);
1317 int qed_vf_pf_int_cleanup(struct qed_hwfn *p_hwfn)
1319 struct qed_vf_iov *p_iov = p_hwfn->vf_iov_info;
1320 struct pfvf_def_resp_tlv *resp = &p_iov->pf2vf_reply->default_resp;
1323 /* clear mailbox and prep first tlv */
1324 qed_vf_pf_prep(p_hwfn, CHANNEL_TLV_INT_CLEANUP,
1325 sizeof(struct vfpf_first_tlv));
1327 /* add list termination tlv */
1328 qed_add_tlv(p_hwfn, &p_iov->offset,
1329 CHANNEL_TLV_LIST_END, sizeof(struct channel_list_end_tlv));
1331 rc = qed_send_msg2pf(p_hwfn, &resp->hdr.status, sizeof(*resp));
1335 if (resp->hdr.status != PFVF_STATUS_SUCCESS) {
1341 qed_vf_pf_req_end(p_hwfn, rc);
1346 int qed_vf_pf_get_coalesce(struct qed_hwfn *p_hwfn,
1347 u16 *p_coal, struct qed_queue_cid *p_cid)
1349 struct qed_vf_iov *p_iov = p_hwfn->vf_iov_info;
1350 struct pfvf_read_coal_resp_tlv *resp;
1351 struct vfpf_read_coal_req_tlv *req;
1354 /* clear mailbox and prep header tlv */
1355 req = qed_vf_pf_prep(p_hwfn, CHANNEL_TLV_COALESCE_READ, sizeof(*req));
1356 req->qid = p_cid->rel.queue_id;
1357 req->is_rx = p_cid->b_is_rx ? 1 : 0;
1359 qed_add_tlv(p_hwfn, &p_iov->offset, CHANNEL_TLV_LIST_END,
1360 sizeof(struct channel_list_end_tlv));
1361 resp = &p_iov->pf2vf_reply->read_coal_resp;
1363 rc = qed_send_msg2pf(p_hwfn, &resp->hdr.status, sizeof(*resp));
1367 if (resp->hdr.status != PFVF_STATUS_SUCCESS)
1370 *p_coal = resp->coal;
1372 qed_vf_pf_req_end(p_hwfn, rc);
1378 qed_vf_pf_bulletin_update_mac(struct qed_hwfn *p_hwfn,
1381 struct qed_vf_iov *p_iov = p_hwfn->vf_iov_info;
1382 struct vfpf_bulletin_update_mac_tlv *p_req;
1383 struct pfvf_def_resp_tlv *p_resp;
1389 /* clear mailbox and prep header tlv */
1390 p_req = qed_vf_pf_prep(p_hwfn, CHANNEL_TLV_BULLETIN_UPDATE_MAC,
1392 ether_addr_copy(p_req->mac, p_mac);
1393 DP_VERBOSE(p_hwfn, QED_MSG_IOV,
1394 "Requesting bulletin update for MAC[%pM]\n", p_mac);
1396 /* add list termination tlv */
1397 qed_add_tlv(p_hwfn, &p_iov->offset, CHANNEL_TLV_LIST_END,
1398 sizeof(struct channel_list_end_tlv));
1400 p_resp = &p_iov->pf2vf_reply->default_resp;
1401 rc = qed_send_msg2pf(p_hwfn, &p_resp->hdr.status, sizeof(*p_resp));
1402 qed_vf_pf_req_end(p_hwfn, rc);
1407 qed_vf_pf_set_coalesce(struct qed_hwfn *p_hwfn,
1408 u16 rx_coal, u16 tx_coal, struct qed_queue_cid *p_cid)
1410 struct qed_vf_iov *p_iov = p_hwfn->vf_iov_info;
1411 struct vfpf_update_coalesce *req;
1412 struct pfvf_def_resp_tlv *resp;
1415 /* clear mailbox and prep header tlv */
1416 req = qed_vf_pf_prep(p_hwfn, CHANNEL_TLV_COALESCE_UPDATE, sizeof(*req));
1418 req->rx_coal = rx_coal;
1419 req->tx_coal = tx_coal;
1420 req->qid = p_cid->rel.queue_id;
1424 "Setting coalesce rx_coal = %d, tx_coal = %d at queue = %d\n",
1425 rx_coal, tx_coal, req->qid);
1427 /* add list termination tlv */
1428 qed_add_tlv(p_hwfn, &p_iov->offset, CHANNEL_TLV_LIST_END,
1429 sizeof(struct channel_list_end_tlv));
1431 resp = &p_iov->pf2vf_reply->default_resp;
1432 rc = qed_send_msg2pf(p_hwfn, &resp->hdr.status, sizeof(*resp));
1436 if (resp->hdr.status != PFVF_STATUS_SUCCESS)
1440 p_hwfn->cdev->rx_coalesce_usecs = rx_coal;
1443 p_hwfn->cdev->tx_coalesce_usecs = tx_coal;
1446 qed_vf_pf_req_end(p_hwfn, rc);
1450 u16 qed_vf_get_igu_sb_id(struct qed_hwfn *p_hwfn, u16 sb_id)
1452 struct qed_vf_iov *p_iov = p_hwfn->vf_iov_info;
1455 DP_NOTICE(p_hwfn, "vf_sriov_info isn't initialized\n");
1459 return p_iov->acquire_resp.resc.hw_sbs[sb_id].hw_sb_id;
1462 void qed_vf_set_sb_info(struct qed_hwfn *p_hwfn,
1463 u16 sb_id, struct qed_sb_info *p_sb)
1465 struct qed_vf_iov *p_iov = p_hwfn->vf_iov_info;
1468 DP_NOTICE(p_hwfn, "vf_sriov_info isn't initialized\n");
1472 if (sb_id >= PFVF_MAX_SBS_PER_VF) {
1473 DP_NOTICE(p_hwfn, "Can't configure SB %04x\n", sb_id);
1477 p_iov->sbs_info[sb_id] = p_sb;
1480 int qed_vf_read_bulletin(struct qed_hwfn *p_hwfn, u8 *p_change)
1482 struct qed_vf_iov *p_iov = p_hwfn->vf_iov_info;
1483 struct qed_bulletin_content shadow;
1486 crc_size = sizeof(p_iov->bulletin.p_virt->crc);
1489 /* Need to guarantee PF is not in the middle of writing it */
1490 memcpy(&shadow, p_iov->bulletin.p_virt, p_iov->bulletin.size);
1492 /* If version did not update, no need to do anything */
1493 if (shadow.version == p_iov->bulletin_shadow.version)
1496 /* Verify the bulletin we see is valid */
1497 crc = crc32(0, (u8 *)&shadow + crc_size,
1498 p_iov->bulletin.size - crc_size);
1499 if (crc != shadow.crc)
1502 /* Set the shadow bulletin and process it */
1503 memcpy(&p_iov->bulletin_shadow, &shadow, p_iov->bulletin.size);
1505 DP_VERBOSE(p_hwfn, QED_MSG_IOV,
1506 "Read a bulletin update %08x\n", shadow.version);
1513 void __qed_vf_get_link_params(struct qed_hwfn *p_hwfn,
1514 struct qed_mcp_link_params *p_params,
1515 struct qed_bulletin_content *p_bulletin)
1517 memset(p_params, 0, sizeof(*p_params));
1519 p_params->speed.autoneg = p_bulletin->req_autoneg;
1520 p_params->speed.advertised_speeds = p_bulletin->req_adv_speed;
1521 p_params->speed.forced_speed = p_bulletin->req_forced_speed;
1522 p_params->pause.autoneg = p_bulletin->req_autoneg_pause;
1523 p_params->pause.forced_rx = p_bulletin->req_forced_rx;
1524 p_params->pause.forced_tx = p_bulletin->req_forced_tx;
1525 p_params->loopback_mode = p_bulletin->req_loopback;
1528 void qed_vf_get_link_params(struct qed_hwfn *p_hwfn,
1529 struct qed_mcp_link_params *params)
1531 __qed_vf_get_link_params(p_hwfn, params,
1532 &(p_hwfn->vf_iov_info->bulletin_shadow));
1535 void __qed_vf_get_link_state(struct qed_hwfn *p_hwfn,
1536 struct qed_mcp_link_state *p_link,
1537 struct qed_bulletin_content *p_bulletin)
1539 memset(p_link, 0, sizeof(*p_link));
1541 p_link->link_up = p_bulletin->link_up;
1542 p_link->speed = p_bulletin->speed;
1543 p_link->full_duplex = p_bulletin->full_duplex;
1544 p_link->an = p_bulletin->autoneg;
1545 p_link->an_complete = p_bulletin->autoneg_complete;
1546 p_link->parallel_detection = p_bulletin->parallel_detection;
1547 p_link->pfc_enabled = p_bulletin->pfc_enabled;
1548 p_link->partner_adv_speed = p_bulletin->partner_adv_speed;
1549 p_link->partner_tx_flow_ctrl_en = p_bulletin->partner_tx_flow_ctrl_en;
1550 p_link->partner_rx_flow_ctrl_en = p_bulletin->partner_rx_flow_ctrl_en;
1551 p_link->partner_adv_pause = p_bulletin->partner_adv_pause;
1552 p_link->sfp_tx_fault = p_bulletin->sfp_tx_fault;
1555 void qed_vf_get_link_state(struct qed_hwfn *p_hwfn,
1556 struct qed_mcp_link_state *link)
1558 __qed_vf_get_link_state(p_hwfn, link,
1559 &(p_hwfn->vf_iov_info->bulletin_shadow));
1562 void __qed_vf_get_link_caps(struct qed_hwfn *p_hwfn,
1563 struct qed_mcp_link_capabilities *p_link_caps,
1564 struct qed_bulletin_content *p_bulletin)
1566 memset(p_link_caps, 0, sizeof(*p_link_caps));
1567 p_link_caps->speed_capabilities = p_bulletin->capability_speed;
1570 void qed_vf_get_link_caps(struct qed_hwfn *p_hwfn,
1571 struct qed_mcp_link_capabilities *p_link_caps)
1573 __qed_vf_get_link_caps(p_hwfn, p_link_caps,
1574 &(p_hwfn->vf_iov_info->bulletin_shadow));
1577 void qed_vf_get_num_rxqs(struct qed_hwfn *p_hwfn, u8 *num_rxqs)
1579 *num_rxqs = p_hwfn->vf_iov_info->acquire_resp.resc.num_rxqs;
1582 void qed_vf_get_num_txqs(struct qed_hwfn *p_hwfn, u8 *num_txqs)
1584 *num_txqs = p_hwfn->vf_iov_info->acquire_resp.resc.num_txqs;
1587 void qed_vf_get_num_cids(struct qed_hwfn *p_hwfn, u8 *num_cids)
1589 *num_cids = p_hwfn->vf_iov_info->acquire_resp.resc.num_cids;
1592 void qed_vf_get_port_mac(struct qed_hwfn *p_hwfn, u8 *port_mac)
1595 p_hwfn->vf_iov_info->acquire_resp.pfdev_info.port_mac, ETH_ALEN);
1598 void qed_vf_get_num_vlan_filters(struct qed_hwfn *p_hwfn, u8 *num_vlan_filters)
1600 struct qed_vf_iov *p_vf;
1602 p_vf = p_hwfn->vf_iov_info;
1603 *num_vlan_filters = p_vf->acquire_resp.resc.num_vlan_filters;
1606 void qed_vf_get_num_mac_filters(struct qed_hwfn *p_hwfn, u8 *num_mac_filters)
1608 struct qed_vf_iov *p_vf = p_hwfn->vf_iov_info;
1610 *num_mac_filters = p_vf->acquire_resp.resc.num_mac_filters;
1613 bool qed_vf_check_mac(struct qed_hwfn *p_hwfn, u8 *mac)
1615 struct qed_bulletin_content *bulletin;
1617 bulletin = &p_hwfn->vf_iov_info->bulletin_shadow;
1618 if (!(bulletin->valid_bitmap & (1 << MAC_ADDR_FORCED)))
1621 /* Forbid VF from changing a MAC enforced by PF */
1622 if (ether_addr_equal(bulletin->mac, mac))
1628 static bool qed_vf_bulletin_get_forced_mac(struct qed_hwfn *hwfn,
1629 u8 *dst_mac, u8 *p_is_forced)
1631 struct qed_bulletin_content *bulletin;
1633 bulletin = &hwfn->vf_iov_info->bulletin_shadow;
1635 if (bulletin->valid_bitmap & (1 << MAC_ADDR_FORCED)) {
1638 } else if (bulletin->valid_bitmap & (1 << VFPF_BULLETIN_MAC_ADDR)) {
1645 ether_addr_copy(dst_mac, bulletin->mac);
1651 qed_vf_bulletin_get_udp_ports(struct qed_hwfn *p_hwfn,
1652 u16 *p_vxlan_port, u16 *p_geneve_port)
1654 struct qed_bulletin_content *p_bulletin;
1656 p_bulletin = &p_hwfn->vf_iov_info->bulletin_shadow;
1658 *p_vxlan_port = p_bulletin->vxlan_udp_port;
1659 *p_geneve_port = p_bulletin->geneve_udp_port;
1662 void qed_vf_get_fw_version(struct qed_hwfn *p_hwfn,
1663 u16 *fw_major, u16 *fw_minor,
1664 u16 *fw_rev, u16 *fw_eng)
1666 struct pf_vf_pfdev_info *info;
1668 info = &p_hwfn->vf_iov_info->acquire_resp.pfdev_info;
1670 *fw_major = info->fw_major;
1671 *fw_minor = info->fw_minor;
1672 *fw_rev = info->fw_rev;
1673 *fw_eng = info->fw_eng;
1676 static void qed_handle_bulletin_change(struct qed_hwfn *hwfn)
1678 struct qed_eth_cb_ops *ops = hwfn->cdev->protocol_ops.eth;
1679 u8 mac[ETH_ALEN], is_mac_exist, is_mac_forced;
1680 void *cookie = hwfn->cdev->ops_cookie;
1681 u16 vxlan_port, geneve_port;
1683 qed_vf_bulletin_get_udp_ports(hwfn, &vxlan_port, &geneve_port);
1684 is_mac_exist = qed_vf_bulletin_get_forced_mac(hwfn, mac,
1686 if (is_mac_exist && cookie)
1687 ops->force_mac(cookie, mac, !!is_mac_forced);
1689 ops->ports_update(cookie, vxlan_port, geneve_port);
1691 /* Always update link configuration according to bulletin */
1692 qed_link_update(hwfn);
1695 void qed_iov_vf_task(struct work_struct *work)
1697 struct qed_hwfn *hwfn = container_of(work, struct qed_hwfn,
1701 if (test_and_clear_bit(QED_IOV_WQ_STOP_WQ_FLAG, &hwfn->iov_task_flags))
1704 /* Handle bulletin board changes */
1705 qed_vf_read_bulletin(hwfn, &change);
1706 if (test_and_clear_bit(QED_IOV_WQ_VF_FORCE_LINK_QUERY_FLAG,
1707 &hwfn->iov_task_flags))
1710 qed_handle_bulletin_change(hwfn);
1712 /* As VF is polling bulletin board, need to constantly re-schedule */
1713 queue_delayed_work(hwfn->iov_wq, &hwfn->iov_task, HZ);