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/stddef.h>
34 #include <linux/pci.h>
35 #include <linux/kernel.h>
36 #include <linux/slab.h>
37 #include <linux/delay.h>
38 #include <asm/byteorder.h>
39 #include <linux/dma-mapping.h>
40 #include <linux/string.h>
41 #include <linux/module.h>
42 #include <linux/interrupt.h>
43 #include <linux/workqueue.h>
44 #include <linux/ethtool.h>
45 #include <linux/etherdevice.h>
46 #include <linux/vmalloc.h>
47 #include <linux/crash_dump.h>
48 #include <linux/crc32.h>
49 #include <linux/qed/qed_if.h>
50 #include <linux/qed/qed_ll2_if.h>
53 #include "qed_sriov.h"
55 #include "qed_dev_api.h"
58 #include "qed_iscsi.h"
62 #include "qed_selftest.h"
63 #include "qed_debug.h"
65 #define QED_ROCE_QPS (8192)
66 #define QED_ROCE_DPIS (8)
68 static char version[] =
69 "QLogic FastLinQ 4xxxx Core Module qed " DRV_MODULE_VERSION "\n";
71 MODULE_DESCRIPTION("QLogic FastLinQ 4xxxx Core Module");
72 MODULE_LICENSE("GPL");
73 MODULE_VERSION(DRV_MODULE_VERSION);
75 #define FW_FILE_VERSION \
76 __stringify(FW_MAJOR_VERSION) "." \
77 __stringify(FW_MINOR_VERSION) "." \
78 __stringify(FW_REVISION_VERSION) "." \
79 __stringify(FW_ENGINEERING_VERSION)
81 #define QED_FW_FILE_NAME \
82 "qed/qed_init_values_zipped-" FW_FILE_VERSION ".bin"
84 MODULE_FIRMWARE(QED_FW_FILE_NAME);
86 static int __init qed_init(void)
88 pr_info("%s", version);
93 static void __exit qed_cleanup(void)
95 pr_notice("qed_cleanup called\n");
98 module_init(qed_init);
99 module_exit(qed_cleanup);
101 /* Check if the DMA controller on the machine can properly handle the DMA
102 * addressing required by the device.
104 static int qed_set_coherency_mask(struct qed_dev *cdev)
106 struct device *dev = &cdev->pdev->dev;
108 if (dma_set_mask(dev, DMA_BIT_MASK(64)) == 0) {
109 if (dma_set_coherent_mask(dev, DMA_BIT_MASK(64)) != 0) {
111 "Can't request 64-bit consistent allocations\n");
114 } else if (dma_set_mask(dev, DMA_BIT_MASK(32)) != 0) {
115 DP_NOTICE(cdev, "Can't request 64b/32b DMA addresses\n");
122 static void qed_free_pci(struct qed_dev *cdev)
124 struct pci_dev *pdev = cdev->pdev;
126 if (cdev->doorbells && cdev->db_size)
127 iounmap(cdev->doorbells);
129 iounmap(cdev->regview);
130 if (atomic_read(&pdev->enable_cnt) == 1)
131 pci_release_regions(pdev);
133 pci_disable_device(pdev);
136 #define PCI_REVISION_ID_ERROR_VAL 0xff
138 /* Performs PCI initializations as well as initializing PCI-related parameters
139 * in the device structrue. Returns 0 in case of success.
141 static int qed_init_pci(struct qed_dev *cdev, struct pci_dev *pdev)
148 rc = pci_enable_device(pdev);
150 DP_NOTICE(cdev, "Cannot enable PCI device\n");
154 if (!(pci_resource_flags(pdev, 0) & IORESOURCE_MEM)) {
155 DP_NOTICE(cdev, "No memory region found in bar #0\n");
160 if (IS_PF(cdev) && !(pci_resource_flags(pdev, 2) & IORESOURCE_MEM)) {
161 DP_NOTICE(cdev, "No memory region found in bar #2\n");
166 if (atomic_read(&pdev->enable_cnt) == 1) {
167 rc = pci_request_regions(pdev, "qed");
170 "Failed to request PCI memory resources\n");
173 pci_set_master(pdev);
174 pci_save_state(pdev);
177 pci_read_config_byte(pdev, PCI_REVISION_ID, &rev_id);
178 if (rev_id == PCI_REVISION_ID_ERROR_VAL) {
180 "Detected PCI device error [rev_id 0x%x]. Probably due to prior indication. Aborting.\n",
185 if (!pci_is_pcie(pdev)) {
186 DP_NOTICE(cdev, "The bus is not PCI Express\n");
191 cdev->pci_params.pm_cap = pci_find_capability(pdev, PCI_CAP_ID_PM);
192 if (IS_PF(cdev) && !cdev->pci_params.pm_cap)
193 DP_NOTICE(cdev, "Cannot find power management capability\n");
195 rc = qed_set_coherency_mask(cdev);
199 cdev->pci_params.mem_start = pci_resource_start(pdev, 0);
200 cdev->pci_params.mem_end = pci_resource_end(pdev, 0);
201 cdev->pci_params.irq = pdev->irq;
203 cdev->regview = pci_ioremap_bar(pdev, 0);
204 if (!cdev->regview) {
205 DP_NOTICE(cdev, "Cannot map register space, aborting\n");
210 cdev->db_phys_addr = pci_resource_start(cdev->pdev, 2);
211 cdev->db_size = pci_resource_len(cdev->pdev, 2);
212 if (!cdev->db_size) {
214 DP_NOTICE(cdev, "No Doorbell bar available\n");
221 cdev->doorbells = ioremap_wc(cdev->db_phys_addr, cdev->db_size);
223 if (!cdev->doorbells) {
224 DP_NOTICE(cdev, "Cannot map doorbell space\n");
231 pci_release_regions(pdev);
233 pci_disable_device(pdev);
238 int qed_fill_dev_info(struct qed_dev *cdev,
239 struct qed_dev_info *dev_info)
241 struct qed_hwfn *p_hwfn = QED_LEADING_HWFN(cdev);
242 struct qed_hw_info *hw_info = &p_hwfn->hw_info;
243 struct qed_tunnel_info *tun = &cdev->tunnel;
246 memset(dev_info, 0, sizeof(struct qed_dev_info));
248 if (tun->vxlan.tun_cls == QED_TUNN_CLSS_MAC_VLAN &&
249 tun->vxlan.b_mode_enabled)
250 dev_info->vxlan_enable = true;
252 if (tun->l2_gre.b_mode_enabled && tun->ip_gre.b_mode_enabled &&
253 tun->l2_gre.tun_cls == QED_TUNN_CLSS_MAC_VLAN &&
254 tun->ip_gre.tun_cls == QED_TUNN_CLSS_MAC_VLAN)
255 dev_info->gre_enable = true;
257 if (tun->l2_geneve.b_mode_enabled && tun->ip_geneve.b_mode_enabled &&
258 tun->l2_geneve.tun_cls == QED_TUNN_CLSS_MAC_VLAN &&
259 tun->ip_geneve.tun_cls == QED_TUNN_CLSS_MAC_VLAN)
260 dev_info->geneve_enable = true;
262 dev_info->num_hwfns = cdev->num_hwfns;
263 dev_info->pci_mem_start = cdev->pci_params.mem_start;
264 dev_info->pci_mem_end = cdev->pci_params.mem_end;
265 dev_info->pci_irq = cdev->pci_params.irq;
266 dev_info->rdma_supported = QED_IS_RDMA_PERSONALITY(p_hwfn);
267 dev_info->is_mf_default = IS_MF_DEFAULT(&cdev->hwfns[0]);
268 dev_info->dev_type = cdev->type;
269 ether_addr_copy(dev_info->hw_mac, hw_info->hw_mac_addr);
272 dev_info->fw_major = FW_MAJOR_VERSION;
273 dev_info->fw_minor = FW_MINOR_VERSION;
274 dev_info->fw_rev = FW_REVISION_VERSION;
275 dev_info->fw_eng = FW_ENGINEERING_VERSION;
276 dev_info->mf_mode = cdev->mf_mode;
277 dev_info->tx_switching = true;
279 if (hw_info->b_wol_support == QED_WOL_SUPPORT_PME)
280 dev_info->wol_support = true;
282 dev_info->abs_pf_id = QED_LEADING_HWFN(cdev)->abs_pf_id;
284 qed_vf_get_fw_version(&cdev->hwfns[0], &dev_info->fw_major,
285 &dev_info->fw_minor, &dev_info->fw_rev,
290 ptt = qed_ptt_acquire(QED_LEADING_HWFN(cdev));
292 qed_mcp_get_mfw_ver(QED_LEADING_HWFN(cdev), ptt,
293 &dev_info->mfw_rev, NULL);
295 qed_mcp_get_mbi_ver(QED_LEADING_HWFN(cdev), ptt,
296 &dev_info->mbi_version);
298 qed_mcp_get_flash_size(QED_LEADING_HWFN(cdev), ptt,
299 &dev_info->flash_size);
301 qed_ptt_release(QED_LEADING_HWFN(cdev), ptt);
304 qed_mcp_get_mfw_ver(QED_LEADING_HWFN(cdev), NULL,
305 &dev_info->mfw_rev, NULL);
308 dev_info->mtu = hw_info->mtu;
313 static void qed_free_cdev(struct qed_dev *cdev)
318 static struct qed_dev *qed_alloc_cdev(struct pci_dev *pdev)
320 struct qed_dev *cdev;
322 cdev = kzalloc(sizeof(*cdev), GFP_KERNEL);
326 qed_init_struct(cdev);
331 /* Sets the requested power state */
332 static int qed_set_power_state(struct qed_dev *cdev, pci_power_t state)
337 DP_VERBOSE(cdev, NETIF_MSG_DRV, "Omitting Power state change\n");
342 static struct qed_dev *qed_probe(struct pci_dev *pdev,
343 struct qed_probe_params *params)
345 struct qed_dev *cdev;
348 cdev = qed_alloc_cdev(pdev);
352 cdev->drv_type = DRV_ID_DRV_TYPE_LINUX;
353 cdev->protocol = params->protocol;
356 cdev->b_is_vf = true;
358 qed_init_dp(cdev, params->dp_module, params->dp_level);
360 rc = qed_init_pci(cdev, pdev);
362 DP_ERR(cdev, "init pci failed\n");
365 DP_INFO(cdev, "PCI init completed successfully\n");
367 rc = qed_hw_prepare(cdev, QED_PCI_DEFAULT);
369 DP_ERR(cdev, "hw prepare failed\n");
373 DP_INFO(cdev, "qed_probe completed successffuly\n");
385 static void qed_remove(struct qed_dev *cdev)
394 qed_set_power_state(cdev, PCI_D3hot);
399 static void qed_disable_msix(struct qed_dev *cdev)
401 if (cdev->int_params.out.int_mode == QED_INT_MODE_MSIX) {
402 pci_disable_msix(cdev->pdev);
403 kfree(cdev->int_params.msix_table);
404 } else if (cdev->int_params.out.int_mode == QED_INT_MODE_MSI) {
405 pci_disable_msi(cdev->pdev);
408 memset(&cdev->int_params.out, 0, sizeof(struct qed_int_param));
411 static int qed_enable_msix(struct qed_dev *cdev,
412 struct qed_int_params *int_params)
416 cnt = int_params->in.num_vectors;
418 for (i = 0; i < cnt; i++)
419 int_params->msix_table[i].entry = i;
421 rc = pci_enable_msix_range(cdev->pdev, int_params->msix_table,
422 int_params->in.min_msix_cnt, cnt);
423 if (rc < cnt && rc >= int_params->in.min_msix_cnt &&
424 (rc % cdev->num_hwfns)) {
425 pci_disable_msix(cdev->pdev);
427 /* If fastpath is initialized, we need at least one interrupt
428 * per hwfn [and the slow path interrupts]. New requested number
429 * should be a multiple of the number of hwfns.
431 cnt = (rc / cdev->num_hwfns) * cdev->num_hwfns;
433 "Trying to enable MSI-X with less vectors (%d out of %d)\n",
434 cnt, int_params->in.num_vectors);
435 rc = pci_enable_msix_exact(cdev->pdev, int_params->msix_table,
442 /* MSI-x configuration was achieved */
443 int_params->out.int_mode = QED_INT_MODE_MSIX;
444 int_params->out.num_vectors = rc;
448 "Failed to enable MSI-X [Requested %d vectors][rc %d]\n",
455 /* This function outputs the int mode and the number of enabled msix vector */
456 static int qed_set_int_mode(struct qed_dev *cdev, bool force_mode)
458 struct qed_int_params *int_params = &cdev->int_params;
459 struct msix_entry *tbl;
462 switch (int_params->in.int_mode) {
463 case QED_INT_MODE_MSIX:
464 /* Allocate MSIX table */
465 cnt = int_params->in.num_vectors;
466 int_params->msix_table = kcalloc(cnt, sizeof(*tbl), GFP_KERNEL);
467 if (!int_params->msix_table) {
473 rc = qed_enable_msix(cdev, int_params);
477 DP_NOTICE(cdev, "Failed to enable MSI-X\n");
478 kfree(int_params->msix_table);
483 case QED_INT_MODE_MSI:
484 if (cdev->num_hwfns == 1) {
485 rc = pci_enable_msi(cdev->pdev);
487 int_params->out.int_mode = QED_INT_MODE_MSI;
491 DP_NOTICE(cdev, "Failed to enable MSI\n");
497 case QED_INT_MODE_INTA:
498 int_params->out.int_mode = QED_INT_MODE_INTA;
502 DP_NOTICE(cdev, "Unknown int_mode value %d\n",
503 int_params->in.int_mode);
509 DP_INFO(cdev, "Using %s interrupts\n",
510 int_params->out.int_mode == QED_INT_MODE_INTA ?
511 "INTa" : int_params->out.int_mode == QED_INT_MODE_MSI ?
513 cdev->int_coalescing_mode = QED_COAL_MODE_ENABLE;
518 static void qed_simd_handler_config(struct qed_dev *cdev, void *token,
519 int index, void(*handler)(void *))
521 struct qed_hwfn *hwfn = &cdev->hwfns[index % cdev->num_hwfns];
522 int relative_idx = index / cdev->num_hwfns;
524 hwfn->simd_proto_handler[relative_idx].func = handler;
525 hwfn->simd_proto_handler[relative_idx].token = token;
528 static void qed_simd_handler_clean(struct qed_dev *cdev, int index)
530 struct qed_hwfn *hwfn = &cdev->hwfns[index % cdev->num_hwfns];
531 int relative_idx = index / cdev->num_hwfns;
533 memset(&hwfn->simd_proto_handler[relative_idx], 0,
534 sizeof(struct qed_simd_fp_handler));
537 static irqreturn_t qed_msix_sp_int(int irq, void *tasklet)
539 tasklet_schedule((struct tasklet_struct *)tasklet);
543 static irqreturn_t qed_single_int(int irq, void *dev_instance)
545 struct qed_dev *cdev = (struct qed_dev *)dev_instance;
546 struct qed_hwfn *hwfn;
547 irqreturn_t rc = IRQ_NONE;
551 for (i = 0; i < cdev->num_hwfns; i++) {
552 status = qed_int_igu_read_sisr_reg(&cdev->hwfns[i]);
557 hwfn = &cdev->hwfns[i];
559 /* Slowpath interrupt */
560 if (unlikely(status & 0x1)) {
561 tasklet_schedule(hwfn->sp_dpc);
566 /* Fastpath interrupts */
567 for (j = 0; j < 64; j++) {
568 if ((0x2ULL << j) & status) {
569 hwfn->simd_proto_handler[j].func(
570 hwfn->simd_proto_handler[j].token);
571 status &= ~(0x2ULL << j);
576 if (unlikely(status))
577 DP_VERBOSE(hwfn, NETIF_MSG_INTR,
578 "got an unknown interrupt status 0x%llx\n",
585 int qed_slowpath_irq_req(struct qed_hwfn *hwfn)
587 struct qed_dev *cdev = hwfn->cdev;
592 int_mode = cdev->int_params.out.int_mode;
593 if (int_mode == QED_INT_MODE_MSIX) {
595 snprintf(hwfn->name, NAME_SIZE, "sp-%d-%02x:%02x.%02x",
596 id, cdev->pdev->bus->number,
597 PCI_SLOT(cdev->pdev->devfn), hwfn->abs_pf_id);
598 rc = request_irq(cdev->int_params.msix_table[id].vector,
599 qed_msix_sp_int, 0, hwfn->name, hwfn->sp_dpc);
601 unsigned long flags = 0;
603 snprintf(cdev->name, NAME_SIZE, "%02x:%02x.%02x",
604 cdev->pdev->bus->number, PCI_SLOT(cdev->pdev->devfn),
605 PCI_FUNC(cdev->pdev->devfn));
607 if (cdev->int_params.out.int_mode == QED_INT_MODE_INTA)
608 flags |= IRQF_SHARED;
610 rc = request_irq(cdev->pdev->irq, qed_single_int,
611 flags, cdev->name, cdev);
615 DP_NOTICE(cdev, "request_irq failed, rc = %d\n", rc);
617 DP_VERBOSE(hwfn, (NETIF_MSG_INTR | QED_MSG_SP),
618 "Requested slowpath %s\n",
619 (int_mode == QED_INT_MODE_MSIX) ? "MSI-X" : "IRQ");
624 static void qed_slowpath_tasklet_flush(struct qed_hwfn *p_hwfn)
626 /* Calling the disable function will make sure that any
627 * currently-running function is completed. The following call to the
628 * enable function makes this sequence a flush-like operation.
630 if (p_hwfn->b_sp_dpc_enabled) {
631 tasklet_disable(p_hwfn->sp_dpc);
632 tasklet_enable(p_hwfn->sp_dpc);
636 void qed_slowpath_irq_sync(struct qed_hwfn *p_hwfn)
638 struct qed_dev *cdev = p_hwfn->cdev;
639 u8 id = p_hwfn->my_id;
642 int_mode = cdev->int_params.out.int_mode;
643 if (int_mode == QED_INT_MODE_MSIX)
644 synchronize_irq(cdev->int_params.msix_table[id].vector);
646 synchronize_irq(cdev->pdev->irq);
648 qed_slowpath_tasklet_flush(p_hwfn);
651 static void qed_slowpath_irq_free(struct qed_dev *cdev)
655 if (cdev->int_params.out.int_mode == QED_INT_MODE_MSIX) {
656 for_each_hwfn(cdev, i) {
657 if (!cdev->hwfns[i].b_int_requested)
659 synchronize_irq(cdev->int_params.msix_table[i].vector);
660 free_irq(cdev->int_params.msix_table[i].vector,
661 cdev->hwfns[i].sp_dpc);
664 if (QED_LEADING_HWFN(cdev)->b_int_requested)
665 free_irq(cdev->pdev->irq, cdev);
667 qed_int_disable_post_isr_release(cdev);
670 static int qed_nic_stop(struct qed_dev *cdev)
674 rc = qed_hw_stop(cdev);
676 for (i = 0; i < cdev->num_hwfns; i++) {
677 struct qed_hwfn *p_hwfn = &cdev->hwfns[i];
679 if (p_hwfn->b_sp_dpc_enabled) {
680 tasklet_disable(p_hwfn->sp_dpc);
681 p_hwfn->b_sp_dpc_enabled = false;
682 DP_VERBOSE(cdev, NETIF_MSG_IFDOWN,
683 "Disabled sp tasklet [hwfn %d] at %p\n",
688 qed_dbg_pf_exit(cdev);
693 static int qed_nic_setup(struct qed_dev *cdev)
697 /* Determine if interface is going to require LL2 */
698 if (QED_LEADING_HWFN(cdev)->hw_info.personality != QED_PCI_ETH) {
699 for (i = 0; i < cdev->num_hwfns; i++) {
700 struct qed_hwfn *p_hwfn = &cdev->hwfns[i];
702 p_hwfn->using_ll2 = true;
706 rc = qed_resc_alloc(cdev);
710 DP_INFO(cdev, "Allocated qed resources\n");
712 qed_resc_setup(cdev);
717 static int qed_set_int_fp(struct qed_dev *cdev, u16 cnt)
721 /* Mark the fastpath as free/used */
722 cdev->int_params.fp_initialized = cnt ? true : false;
724 if (cdev->int_params.out.int_mode != QED_INT_MODE_MSIX)
725 limit = cdev->num_hwfns * 63;
726 else if (cdev->int_params.fp_msix_cnt)
727 limit = cdev->int_params.fp_msix_cnt;
732 return min_t(int, cnt, limit);
735 static int qed_get_int_fp(struct qed_dev *cdev, struct qed_int_info *info)
737 memset(info, 0, sizeof(struct qed_int_info));
739 if (!cdev->int_params.fp_initialized) {
741 "Protocol driver requested interrupt information, but its support is not yet configured\n");
745 /* Need to expose only MSI-X information; Single IRQ is handled solely
748 if (cdev->int_params.out.int_mode == QED_INT_MODE_MSIX) {
749 int msix_base = cdev->int_params.fp_msix_base;
751 info->msix_cnt = cdev->int_params.fp_msix_cnt;
752 info->msix = &cdev->int_params.msix_table[msix_base];
758 static int qed_slowpath_setup_int(struct qed_dev *cdev,
759 enum qed_int_mode int_mode)
761 struct qed_sb_cnt_info sb_cnt_info;
762 int num_l2_queues = 0;
766 if ((int_mode == QED_INT_MODE_MSI) && (cdev->num_hwfns > 1)) {
767 DP_NOTICE(cdev, "MSI mode is not supported for CMT devices\n");
771 memset(&cdev->int_params, 0, sizeof(struct qed_int_params));
772 cdev->int_params.in.int_mode = int_mode;
773 for_each_hwfn(cdev, i) {
774 memset(&sb_cnt_info, 0, sizeof(sb_cnt_info));
775 qed_int_get_num_sbs(&cdev->hwfns[i], &sb_cnt_info);
776 cdev->int_params.in.num_vectors += sb_cnt_info.cnt;
777 cdev->int_params.in.num_vectors++; /* slowpath */
780 /* We want a minimum of one slowpath and one fastpath vector per hwfn */
781 cdev->int_params.in.min_msix_cnt = cdev->num_hwfns * 2;
783 rc = qed_set_int_mode(cdev, false);
785 DP_ERR(cdev, "qed_slowpath_setup_int ERR\n");
789 cdev->int_params.fp_msix_base = cdev->num_hwfns;
790 cdev->int_params.fp_msix_cnt = cdev->int_params.out.num_vectors -
793 if (!IS_ENABLED(CONFIG_QED_RDMA) ||
794 !QED_IS_RDMA_PERSONALITY(QED_LEADING_HWFN(cdev)))
797 for_each_hwfn(cdev, i)
798 num_l2_queues += FEAT_NUM(&cdev->hwfns[i], QED_PF_L2_QUE);
800 DP_VERBOSE(cdev, QED_MSG_RDMA,
801 "cdev->int_params.fp_msix_cnt=%d num_l2_queues=%d\n",
802 cdev->int_params.fp_msix_cnt, num_l2_queues);
804 if (cdev->int_params.fp_msix_cnt > num_l2_queues) {
805 cdev->int_params.rdma_msix_cnt =
806 (cdev->int_params.fp_msix_cnt - num_l2_queues)
808 cdev->int_params.rdma_msix_base =
809 cdev->int_params.fp_msix_base + num_l2_queues;
810 cdev->int_params.fp_msix_cnt = num_l2_queues;
812 cdev->int_params.rdma_msix_cnt = 0;
815 DP_VERBOSE(cdev, QED_MSG_RDMA, "roce_msix_cnt=%d roce_msix_base=%d\n",
816 cdev->int_params.rdma_msix_cnt,
817 cdev->int_params.rdma_msix_base);
822 static int qed_slowpath_vf_setup_int(struct qed_dev *cdev)
826 memset(&cdev->int_params, 0, sizeof(struct qed_int_params));
827 cdev->int_params.in.int_mode = QED_INT_MODE_MSIX;
829 qed_vf_get_num_rxqs(QED_LEADING_HWFN(cdev),
830 &cdev->int_params.in.num_vectors);
831 if (cdev->num_hwfns > 1) {
834 qed_vf_get_num_rxqs(&cdev->hwfns[1], &vectors);
835 cdev->int_params.in.num_vectors += vectors;
838 /* We want a minimum of one fastpath vector per vf hwfn */
839 cdev->int_params.in.min_msix_cnt = cdev->num_hwfns;
841 rc = qed_set_int_mode(cdev, true);
845 cdev->int_params.fp_msix_base = 0;
846 cdev->int_params.fp_msix_cnt = cdev->int_params.out.num_vectors;
851 u32 qed_unzip_data(struct qed_hwfn *p_hwfn, u32 input_len,
852 u8 *input_buf, u32 max_size, u8 *unzip_buf)
856 p_hwfn->stream->next_in = input_buf;
857 p_hwfn->stream->avail_in = input_len;
858 p_hwfn->stream->next_out = unzip_buf;
859 p_hwfn->stream->avail_out = max_size;
861 rc = zlib_inflateInit2(p_hwfn->stream, MAX_WBITS);
864 DP_VERBOSE(p_hwfn, NETIF_MSG_DRV, "zlib init failed, rc = %d\n",
869 rc = zlib_inflate(p_hwfn->stream, Z_FINISH);
870 zlib_inflateEnd(p_hwfn->stream);
872 if (rc != Z_OK && rc != Z_STREAM_END) {
873 DP_VERBOSE(p_hwfn, NETIF_MSG_DRV, "FW unzip error: %s, rc=%d\n",
874 p_hwfn->stream->msg, rc);
878 return p_hwfn->stream->total_out / 4;
881 static int qed_alloc_stream_mem(struct qed_dev *cdev)
886 for_each_hwfn(cdev, i) {
887 struct qed_hwfn *p_hwfn = &cdev->hwfns[i];
889 p_hwfn->stream = kzalloc(sizeof(*p_hwfn->stream), GFP_KERNEL);
893 workspace = vzalloc(zlib_inflate_workspacesize());
896 p_hwfn->stream->workspace = workspace;
902 static void qed_free_stream_mem(struct qed_dev *cdev)
906 for_each_hwfn(cdev, i) {
907 struct qed_hwfn *p_hwfn = &cdev->hwfns[i];
912 vfree(p_hwfn->stream->workspace);
913 kfree(p_hwfn->stream);
917 static void qed_update_pf_params(struct qed_dev *cdev,
918 struct qed_pf_params *params)
922 if (IS_ENABLED(CONFIG_QED_RDMA)) {
923 params->rdma_pf_params.num_qps = QED_ROCE_QPS;
924 params->rdma_pf_params.min_dpis = QED_ROCE_DPIS;
925 /* divide by 3 the MRs to avoid MF ILT overflow */
926 params->rdma_pf_params.gl_pi = QED_ROCE_PROTOCOL_INDEX;
929 if (cdev->num_hwfns > 1 || IS_VF(cdev))
930 params->eth_pf_params.num_arfs_filters = 0;
932 /* In case we might support RDMA, don't allow qede to be greedy
933 * with the L2 contexts. Allow for 64 queues [rx, tx, xdp] per hwfn.
935 if (QED_IS_RDMA_PERSONALITY(QED_LEADING_HWFN(cdev))) {
938 num_cons = ¶ms->eth_pf_params.num_cons;
939 *num_cons = min_t(u16, *num_cons, 192);
942 for (i = 0; i < cdev->num_hwfns; i++) {
943 struct qed_hwfn *p_hwfn = &cdev->hwfns[i];
945 p_hwfn->pf_params = *params;
949 static int qed_slowpath_start(struct qed_dev *cdev,
950 struct qed_slowpath_params *params)
952 struct qed_drv_load_params drv_load_params;
953 struct qed_hw_init_params hw_init_params;
954 struct qed_mcp_drv_version drv_version;
955 struct qed_tunnel_info tunn_info;
956 const u8 *data = NULL;
957 struct qed_hwfn *hwfn;
958 struct qed_ptt *p_ptt;
961 if (qed_iov_wq_start(cdev))
965 rc = request_firmware(&cdev->firmware, QED_FW_FILE_NAME,
969 "Failed to find fw file - /lib/firmware/%s\n",
974 if (cdev->num_hwfns == 1) {
975 p_ptt = qed_ptt_acquire(QED_LEADING_HWFN(cdev));
977 QED_LEADING_HWFN(cdev)->p_arfs_ptt = p_ptt;
980 "Failed to acquire PTT for aRFS\n");
986 cdev->rx_coalesce_usecs = QED_DEFAULT_RX_USECS;
987 rc = qed_nic_setup(cdev);
992 rc = qed_slowpath_setup_int(cdev, params->int_mode);
994 rc = qed_slowpath_vf_setup_int(cdev);
999 /* Allocate stream for unzipping */
1000 rc = qed_alloc_stream_mem(cdev);
1004 /* First Dword used to differentiate between various sources */
1005 data = cdev->firmware->data + sizeof(u32);
1007 qed_dbg_pf_init(cdev);
1010 /* Start the slowpath */
1011 memset(&hw_init_params, 0, sizeof(hw_init_params));
1012 memset(&tunn_info, 0, sizeof(tunn_info));
1013 tunn_info.vxlan.b_mode_enabled = true;
1014 tunn_info.l2_gre.b_mode_enabled = true;
1015 tunn_info.ip_gre.b_mode_enabled = true;
1016 tunn_info.l2_geneve.b_mode_enabled = true;
1017 tunn_info.ip_geneve.b_mode_enabled = true;
1018 tunn_info.vxlan.tun_cls = QED_TUNN_CLSS_MAC_VLAN;
1019 tunn_info.l2_gre.tun_cls = QED_TUNN_CLSS_MAC_VLAN;
1020 tunn_info.ip_gre.tun_cls = QED_TUNN_CLSS_MAC_VLAN;
1021 tunn_info.l2_geneve.tun_cls = QED_TUNN_CLSS_MAC_VLAN;
1022 tunn_info.ip_geneve.tun_cls = QED_TUNN_CLSS_MAC_VLAN;
1023 hw_init_params.p_tunn = &tunn_info;
1024 hw_init_params.b_hw_start = true;
1025 hw_init_params.int_mode = cdev->int_params.out.int_mode;
1026 hw_init_params.allow_npar_tx_switch = true;
1027 hw_init_params.bin_fw_data = data;
1029 memset(&drv_load_params, 0, sizeof(drv_load_params));
1030 drv_load_params.is_crash_kernel = is_kdump_kernel();
1031 drv_load_params.mfw_timeout_val = QED_LOAD_REQ_LOCK_TO_DEFAULT;
1032 drv_load_params.avoid_eng_reset = false;
1033 drv_load_params.override_force_load = QED_OVERRIDE_FORCE_LOAD_NONE;
1034 hw_init_params.p_drv_load_params = &drv_load_params;
1036 rc = qed_hw_init(cdev, &hw_init_params);
1041 "HW initialization and function start completed successfully\n");
1044 cdev->tunn_feature_mask = (BIT(QED_MODE_VXLAN_TUNN) |
1045 BIT(QED_MODE_L2GENEVE_TUNN) |
1046 BIT(QED_MODE_IPGENEVE_TUNN) |
1047 BIT(QED_MODE_L2GRE_TUNN) |
1048 BIT(QED_MODE_IPGRE_TUNN));
1051 /* Allocate LL2 interface if needed */
1052 if (QED_LEADING_HWFN(cdev)->using_ll2) {
1053 rc = qed_ll2_alloc_if(cdev);
1058 hwfn = QED_LEADING_HWFN(cdev);
1059 drv_version.version = (params->drv_major << 24) |
1060 (params->drv_minor << 16) |
1061 (params->drv_rev << 8) |
1063 strlcpy(drv_version.name, params->name,
1064 MCP_DRV_VER_STR_SIZE - 4);
1065 rc = qed_mcp_send_drv_version(hwfn, hwfn->p_main_ptt,
1068 DP_NOTICE(cdev, "Failed sending drv version command\n");
1073 qed_reset_vport_stats(cdev);
1080 qed_hw_timers_stop_all(cdev);
1082 qed_slowpath_irq_free(cdev);
1083 qed_free_stream_mem(cdev);
1084 qed_disable_msix(cdev);
1086 qed_resc_free(cdev);
1089 release_firmware(cdev->firmware);
1091 if (IS_PF(cdev) && (cdev->num_hwfns == 1) &&
1092 QED_LEADING_HWFN(cdev)->p_arfs_ptt)
1093 qed_ptt_release(QED_LEADING_HWFN(cdev),
1094 QED_LEADING_HWFN(cdev)->p_arfs_ptt);
1096 qed_iov_wq_stop(cdev, false);
1101 static int qed_slowpath_stop(struct qed_dev *cdev)
1106 qed_ll2_dealloc_if(cdev);
1109 if (cdev->num_hwfns == 1)
1110 qed_ptt_release(QED_LEADING_HWFN(cdev),
1111 QED_LEADING_HWFN(cdev)->p_arfs_ptt);
1112 qed_free_stream_mem(cdev);
1113 if (IS_QED_ETH_IF(cdev))
1114 qed_sriov_disable(cdev, true);
1120 qed_slowpath_irq_free(cdev);
1122 qed_disable_msix(cdev);
1124 qed_resc_free(cdev);
1126 qed_iov_wq_stop(cdev, true);
1129 release_firmware(cdev->firmware);
1134 static void qed_set_name(struct qed_dev *cdev, char name[NAME_SIZE])
1138 memcpy(cdev->name, name, NAME_SIZE);
1139 for_each_hwfn(cdev, i)
1140 snprintf(cdev->hwfns[i].name, NAME_SIZE, "%s-%d", name, i);
1143 static u32 qed_sb_init(struct qed_dev *cdev,
1144 struct qed_sb_info *sb_info,
1146 dma_addr_t sb_phy_addr, u16 sb_id,
1147 enum qed_sb_type type)
1149 struct qed_hwfn *p_hwfn;
1150 struct qed_ptt *p_ptt;
1156 /* RoCE uses single engine and CMT uses two engines. When using both
1157 * we force only a single engine. Storage uses only engine 0 too.
1159 if (type == QED_SB_TYPE_L2_QUEUE)
1160 n_hwfns = cdev->num_hwfns;
1164 hwfn_index = sb_id % n_hwfns;
1165 p_hwfn = &cdev->hwfns[hwfn_index];
1166 rel_sb_id = sb_id / n_hwfns;
1168 DP_VERBOSE(cdev, NETIF_MSG_INTR,
1169 "hwfn [%d] <--[init]-- SB %04x [0x%04x upper]\n",
1170 hwfn_index, rel_sb_id, sb_id);
1172 if (IS_PF(p_hwfn->cdev)) {
1173 p_ptt = qed_ptt_acquire(p_hwfn);
1177 rc = qed_int_sb_init(p_hwfn, p_ptt, sb_info, sb_virt_addr,
1178 sb_phy_addr, rel_sb_id);
1179 qed_ptt_release(p_hwfn, p_ptt);
1181 rc = qed_int_sb_init(p_hwfn, NULL, sb_info, sb_virt_addr,
1182 sb_phy_addr, rel_sb_id);
1188 static u32 qed_sb_release(struct qed_dev *cdev,
1189 struct qed_sb_info *sb_info, u16 sb_id)
1191 struct qed_hwfn *p_hwfn;
1196 hwfn_index = sb_id % cdev->num_hwfns;
1197 p_hwfn = &cdev->hwfns[hwfn_index];
1198 rel_sb_id = sb_id / cdev->num_hwfns;
1200 DP_VERBOSE(cdev, NETIF_MSG_INTR,
1201 "hwfn [%d] <--[init]-- SB %04x [0x%04x upper]\n",
1202 hwfn_index, rel_sb_id, sb_id);
1204 rc = qed_int_sb_release(p_hwfn, sb_info, rel_sb_id);
1209 static bool qed_can_link_change(struct qed_dev *cdev)
1214 static int qed_set_link(struct qed_dev *cdev, struct qed_link_params *params)
1216 struct qed_hwfn *hwfn;
1217 struct qed_mcp_link_params *link_params;
1218 struct qed_ptt *ptt;
1224 /* The link should be set only once per PF */
1225 hwfn = &cdev->hwfns[0];
1227 /* When VF wants to set link, force it to read the bulletin instead.
1228 * This mimics the PF behavior, where a noitification [both immediate
1229 * and possible later] would be generated when changing properties.
1232 qed_schedule_iov(hwfn, QED_IOV_WQ_VF_FORCE_LINK_QUERY_FLAG);
1236 ptt = qed_ptt_acquire(hwfn);
1240 link_params = qed_mcp_get_link_params(hwfn);
1241 if (params->override_flags & QED_LINK_OVERRIDE_SPEED_AUTONEG)
1242 link_params->speed.autoneg = params->autoneg;
1243 if (params->override_flags & QED_LINK_OVERRIDE_SPEED_ADV_SPEEDS) {
1244 link_params->speed.advertised_speeds = 0;
1245 if ((params->adv_speeds & QED_LM_1000baseT_Half_BIT) ||
1246 (params->adv_speeds & QED_LM_1000baseT_Full_BIT))
1247 link_params->speed.advertised_speeds |=
1248 NVM_CFG1_PORT_DRV_SPEED_CAPABILITY_MASK_1G;
1249 if (params->adv_speeds & QED_LM_10000baseKR_Full_BIT)
1250 link_params->speed.advertised_speeds |=
1251 NVM_CFG1_PORT_DRV_SPEED_CAPABILITY_MASK_10G;
1252 if (params->adv_speeds & QED_LM_25000baseKR_Full_BIT)
1253 link_params->speed.advertised_speeds |=
1254 NVM_CFG1_PORT_DRV_SPEED_CAPABILITY_MASK_25G;
1255 if (params->adv_speeds & QED_LM_40000baseLR4_Full_BIT)
1256 link_params->speed.advertised_speeds |=
1257 NVM_CFG1_PORT_DRV_SPEED_CAPABILITY_MASK_40G;
1258 if (params->adv_speeds & QED_LM_50000baseKR2_Full_BIT)
1259 link_params->speed.advertised_speeds |=
1260 NVM_CFG1_PORT_DRV_SPEED_CAPABILITY_MASK_50G;
1261 if (params->adv_speeds & QED_LM_100000baseKR4_Full_BIT)
1262 link_params->speed.advertised_speeds |=
1263 NVM_CFG1_PORT_DRV_SPEED_CAPABILITY_MASK_BB_100G;
1265 if (params->override_flags & QED_LINK_OVERRIDE_SPEED_FORCED_SPEED)
1266 link_params->speed.forced_speed = params->forced_speed;
1267 if (params->override_flags & QED_LINK_OVERRIDE_PAUSE_CONFIG) {
1268 if (params->pause_config & QED_LINK_PAUSE_AUTONEG_ENABLE)
1269 link_params->pause.autoneg = true;
1271 link_params->pause.autoneg = false;
1272 if (params->pause_config & QED_LINK_PAUSE_RX_ENABLE)
1273 link_params->pause.forced_rx = true;
1275 link_params->pause.forced_rx = false;
1276 if (params->pause_config & QED_LINK_PAUSE_TX_ENABLE)
1277 link_params->pause.forced_tx = true;
1279 link_params->pause.forced_tx = false;
1281 if (params->override_flags & QED_LINK_OVERRIDE_LOOPBACK_MODE) {
1282 switch (params->loopback_mode) {
1283 case QED_LINK_LOOPBACK_INT_PHY:
1284 link_params->loopback_mode = ETH_LOOPBACK_INT_PHY;
1286 case QED_LINK_LOOPBACK_EXT_PHY:
1287 link_params->loopback_mode = ETH_LOOPBACK_EXT_PHY;
1289 case QED_LINK_LOOPBACK_EXT:
1290 link_params->loopback_mode = ETH_LOOPBACK_EXT;
1292 case QED_LINK_LOOPBACK_MAC:
1293 link_params->loopback_mode = ETH_LOOPBACK_MAC;
1296 link_params->loopback_mode = ETH_LOOPBACK_NONE;
1301 if (params->override_flags & QED_LINK_OVERRIDE_EEE_CONFIG)
1302 memcpy(&link_params->eee, ¶ms->eee,
1303 sizeof(link_params->eee));
1305 rc = qed_mcp_set_link(hwfn, ptt, params->link_up);
1307 qed_ptt_release(hwfn, ptt);
1312 static int qed_get_port_type(u32 media_type)
1316 switch (media_type) {
1317 case MEDIA_SFPP_10G_FIBER:
1318 case MEDIA_SFP_1G_FIBER:
1319 case MEDIA_XFP_FIBER:
1320 case MEDIA_MODULE_FIBER:
1322 port_type = PORT_FIBRE;
1324 case MEDIA_DA_TWINAX:
1325 port_type = PORT_DA;
1328 port_type = PORT_TP;
1330 case MEDIA_NOT_PRESENT:
1331 port_type = PORT_NONE;
1333 case MEDIA_UNSPECIFIED:
1335 port_type = PORT_OTHER;
1341 static int qed_get_link_data(struct qed_hwfn *hwfn,
1342 struct qed_mcp_link_params *params,
1343 struct qed_mcp_link_state *link,
1344 struct qed_mcp_link_capabilities *link_caps)
1348 if (!IS_PF(hwfn->cdev)) {
1349 qed_vf_get_link_params(hwfn, params);
1350 qed_vf_get_link_state(hwfn, link);
1351 qed_vf_get_link_caps(hwfn, link_caps);
1356 p = qed_mcp_get_link_params(hwfn);
1359 memcpy(params, p, sizeof(*params));
1361 p = qed_mcp_get_link_state(hwfn);
1364 memcpy(link, p, sizeof(*link));
1366 p = qed_mcp_get_link_capabilities(hwfn);
1369 memcpy(link_caps, p, sizeof(*link_caps));
1374 static void qed_fill_link(struct qed_hwfn *hwfn,
1375 struct qed_link_output *if_link)
1377 struct qed_mcp_link_params params;
1378 struct qed_mcp_link_state link;
1379 struct qed_mcp_link_capabilities link_caps;
1382 memset(if_link, 0, sizeof(*if_link));
1384 /* Prepare source inputs */
1385 if (qed_get_link_data(hwfn, ¶ms, &link, &link_caps)) {
1386 dev_warn(&hwfn->cdev->pdev->dev, "no link data available\n");
1390 /* Set the link parameters to pass to protocol driver */
1392 if_link->link_up = true;
1394 /* TODO - at the moment assume supported and advertised speed equal */
1395 if_link->supported_caps = QED_LM_FIBRE_BIT;
1396 if (link_caps.default_speed_autoneg)
1397 if_link->supported_caps |= QED_LM_Autoneg_BIT;
1398 if (params.pause.autoneg ||
1399 (params.pause.forced_rx && params.pause.forced_tx))
1400 if_link->supported_caps |= QED_LM_Asym_Pause_BIT;
1401 if (params.pause.autoneg || params.pause.forced_rx ||
1402 params.pause.forced_tx)
1403 if_link->supported_caps |= QED_LM_Pause_BIT;
1405 if_link->advertised_caps = if_link->supported_caps;
1406 if (params.speed.autoneg)
1407 if_link->advertised_caps |= QED_LM_Autoneg_BIT;
1409 if_link->advertised_caps &= ~QED_LM_Autoneg_BIT;
1410 if (params.speed.advertised_speeds &
1411 NVM_CFG1_PORT_DRV_SPEED_CAPABILITY_MASK_1G)
1412 if_link->advertised_caps |= QED_LM_1000baseT_Half_BIT |
1413 QED_LM_1000baseT_Full_BIT;
1414 if (params.speed.advertised_speeds &
1415 NVM_CFG1_PORT_DRV_SPEED_CAPABILITY_MASK_10G)
1416 if_link->advertised_caps |= QED_LM_10000baseKR_Full_BIT;
1417 if (params.speed.advertised_speeds &
1418 NVM_CFG1_PORT_DRV_SPEED_CAPABILITY_MASK_25G)
1419 if_link->advertised_caps |= QED_LM_25000baseKR_Full_BIT;
1420 if (params.speed.advertised_speeds &
1421 NVM_CFG1_PORT_DRV_SPEED_CAPABILITY_MASK_40G)
1422 if_link->advertised_caps |= QED_LM_40000baseLR4_Full_BIT;
1423 if (params.speed.advertised_speeds &
1424 NVM_CFG1_PORT_DRV_SPEED_CAPABILITY_MASK_50G)
1425 if_link->advertised_caps |= QED_LM_50000baseKR2_Full_BIT;
1426 if (params.speed.advertised_speeds &
1427 NVM_CFG1_PORT_DRV_SPEED_CAPABILITY_MASK_BB_100G)
1428 if_link->advertised_caps |= QED_LM_100000baseKR4_Full_BIT;
1430 if (link_caps.speed_capabilities &
1431 NVM_CFG1_PORT_DRV_SPEED_CAPABILITY_MASK_1G)
1432 if_link->supported_caps |= QED_LM_1000baseT_Half_BIT |
1433 QED_LM_1000baseT_Full_BIT;
1434 if (link_caps.speed_capabilities &
1435 NVM_CFG1_PORT_DRV_SPEED_CAPABILITY_MASK_10G)
1436 if_link->supported_caps |= QED_LM_10000baseKR_Full_BIT;
1437 if (link_caps.speed_capabilities &
1438 NVM_CFG1_PORT_DRV_SPEED_CAPABILITY_MASK_25G)
1439 if_link->supported_caps |= QED_LM_25000baseKR_Full_BIT;
1440 if (link_caps.speed_capabilities &
1441 NVM_CFG1_PORT_DRV_SPEED_CAPABILITY_MASK_40G)
1442 if_link->supported_caps |= QED_LM_40000baseLR4_Full_BIT;
1443 if (link_caps.speed_capabilities &
1444 NVM_CFG1_PORT_DRV_SPEED_CAPABILITY_MASK_50G)
1445 if_link->supported_caps |= QED_LM_50000baseKR2_Full_BIT;
1446 if (link_caps.speed_capabilities &
1447 NVM_CFG1_PORT_DRV_SPEED_CAPABILITY_MASK_BB_100G)
1448 if_link->supported_caps |= QED_LM_100000baseKR4_Full_BIT;
1451 if_link->speed = link.speed;
1453 /* TODO - fill duplex properly */
1454 if_link->duplex = DUPLEX_FULL;
1455 qed_mcp_get_media_type(hwfn->cdev, &media_type);
1456 if_link->port = qed_get_port_type(media_type);
1458 if_link->autoneg = params.speed.autoneg;
1460 if (params.pause.autoneg)
1461 if_link->pause_config |= QED_LINK_PAUSE_AUTONEG_ENABLE;
1462 if (params.pause.forced_rx)
1463 if_link->pause_config |= QED_LINK_PAUSE_RX_ENABLE;
1464 if (params.pause.forced_tx)
1465 if_link->pause_config |= QED_LINK_PAUSE_TX_ENABLE;
1467 /* Link partner capabilities */
1468 if (link.partner_adv_speed & QED_LINK_PARTNER_SPEED_1G_HD)
1469 if_link->lp_caps |= QED_LM_1000baseT_Half_BIT;
1470 if (link.partner_adv_speed & QED_LINK_PARTNER_SPEED_1G_FD)
1471 if_link->lp_caps |= QED_LM_1000baseT_Full_BIT;
1472 if (link.partner_adv_speed & QED_LINK_PARTNER_SPEED_10G)
1473 if_link->lp_caps |= QED_LM_10000baseKR_Full_BIT;
1474 if (link.partner_adv_speed & QED_LINK_PARTNER_SPEED_25G)
1475 if_link->lp_caps |= QED_LM_25000baseKR_Full_BIT;
1476 if (link.partner_adv_speed & QED_LINK_PARTNER_SPEED_40G)
1477 if_link->lp_caps |= QED_LM_40000baseLR4_Full_BIT;
1478 if (link.partner_adv_speed & QED_LINK_PARTNER_SPEED_50G)
1479 if_link->lp_caps |= QED_LM_50000baseKR2_Full_BIT;
1480 if (link.partner_adv_speed & QED_LINK_PARTNER_SPEED_100G)
1481 if_link->lp_caps |= QED_LM_100000baseKR4_Full_BIT;
1483 if (link.an_complete)
1484 if_link->lp_caps |= QED_LM_Autoneg_BIT;
1486 if (link.partner_adv_pause)
1487 if_link->lp_caps |= QED_LM_Pause_BIT;
1488 if (link.partner_adv_pause == QED_LINK_PARTNER_ASYMMETRIC_PAUSE ||
1489 link.partner_adv_pause == QED_LINK_PARTNER_BOTH_PAUSE)
1490 if_link->lp_caps |= QED_LM_Asym_Pause_BIT;
1492 if (link_caps.default_eee == QED_MCP_EEE_UNSUPPORTED) {
1493 if_link->eee_supported = false;
1495 if_link->eee_supported = true;
1496 if_link->eee_active = link.eee_active;
1497 if_link->sup_caps = link_caps.eee_speed_caps;
1498 /* MFW clears adv_caps on eee disable; use configured value */
1499 if_link->eee.adv_caps = link.eee_adv_caps ? link.eee_adv_caps :
1500 params.eee.adv_caps;
1501 if_link->eee.lp_adv_caps = link.eee_lp_adv_caps;
1502 if_link->eee.enable = params.eee.enable;
1503 if_link->eee.tx_lpi_enable = params.eee.tx_lpi_enable;
1504 if_link->eee.tx_lpi_timer = params.eee.tx_lpi_timer;
1508 static void qed_get_current_link(struct qed_dev *cdev,
1509 struct qed_link_output *if_link)
1513 qed_fill_link(&cdev->hwfns[0], if_link);
1515 for_each_hwfn(cdev, i)
1516 qed_inform_vf_link_state(&cdev->hwfns[i]);
1519 void qed_link_update(struct qed_hwfn *hwfn)
1521 void *cookie = hwfn->cdev->ops_cookie;
1522 struct qed_common_cb_ops *op = hwfn->cdev->protocol_ops.common;
1523 struct qed_link_output if_link;
1525 qed_fill_link(hwfn, &if_link);
1526 qed_inform_vf_link_state(hwfn);
1528 if (IS_LEAD_HWFN(hwfn) && cookie)
1529 op->link_update(cookie, &if_link);
1532 static int qed_drain(struct qed_dev *cdev)
1534 struct qed_hwfn *hwfn;
1535 struct qed_ptt *ptt;
1541 for_each_hwfn(cdev, i) {
1542 hwfn = &cdev->hwfns[i];
1543 ptt = qed_ptt_acquire(hwfn);
1545 DP_NOTICE(hwfn, "Failed to drain NIG; No PTT\n");
1548 rc = qed_mcp_drain(hwfn, ptt);
1551 qed_ptt_release(hwfn, ptt);
1557 static u32 qed_nvm_flash_image_access_crc(struct qed_dev *cdev,
1558 struct qed_nvm_image_att *nvm_image,
1565 /* Allocate a buffer for holding the nvram image */
1566 buf = kzalloc(nvm_image->length, GFP_KERNEL);
1570 /* Read image into buffer */
1571 rc = qed_mcp_nvm_read(cdev, nvm_image->start_addr,
1572 buf, nvm_image->length);
1574 DP_ERR(cdev, "Failed reading image from nvm\n");
1578 /* Convert the buffer into big-endian format (excluding the
1579 * closing 4 bytes of CRC).
1581 for (j = 0; j < nvm_image->length - 4; j += 4) {
1582 val = cpu_to_be32(*(u32 *)&buf[j]);
1583 *(u32 *)&buf[j] = val;
1586 /* Calc CRC for the "actual" image buffer, i.e. not including
1587 * the last 4 CRC bytes.
1589 *crc = (~cpu_to_be32(crc32(0xffffffff, buf, nvm_image->length - 4)));
1597 /* Binary file format -
1598 * /----------------------------------------------------------------------\
1599 * 0B | 0x4 [command index] |
1600 * 4B | image_type | Options | Number of register settings |
1604 * \----------------------------------------------------------------------/
1605 * There can be several Value-Mask-Offset sets as specified by 'Number of...'.
1606 * Options - 0'b - Calculate & Update CRC for image
1608 static int qed_nvm_flash_image_access(struct qed_dev *cdev, const u8 **data,
1611 struct qed_nvm_image_att nvm_image;
1612 struct qed_hwfn *p_hwfn;
1613 bool is_crc = false;
1619 image_type = **data;
1620 p_hwfn = QED_LEADING_HWFN(cdev);
1621 for (i = 0; i < p_hwfn->nvm_info.num_images; i++)
1622 if (image_type == p_hwfn->nvm_info.image_att[i].image_type)
1624 if (i == p_hwfn->nvm_info.num_images) {
1625 DP_ERR(cdev, "Failed to find nvram image of type %08x\n",
1630 nvm_image.start_addr = p_hwfn->nvm_info.image_att[i].nvm_start_addr;
1631 nvm_image.length = p_hwfn->nvm_info.image_att[i].len;
1633 DP_VERBOSE(cdev, NETIF_MSG_DRV,
1634 "Read image %02x; type = %08x; NVM [%08x,...,%08x]\n",
1635 **data, image_type, nvm_image.start_addr,
1636 nvm_image.start_addr + nvm_image.length - 1);
1638 is_crc = !!(**data & BIT(0));
1640 len = *((u16 *)*data);
1645 rc = qed_nvm_flash_image_access_crc(cdev, &nvm_image, &crc);
1647 DP_ERR(cdev, "Failed calculating CRC, rc = %d\n", rc);
1651 rc = qed_mcp_nvm_write(cdev, QED_NVM_WRITE_NVRAM,
1652 (nvm_image.start_addr +
1653 nvm_image.length - 4), (u8 *)&crc, 4);
1655 DP_ERR(cdev, "Failed writing to %08x, rc = %d\n",
1656 nvm_image.start_addr + nvm_image.length - 4, rc);
1660 /* Iterate over the values for setting */
1662 u32 offset, mask, value, cur_value;
1665 value = *((u32 *)*data);
1667 mask = *((u32 *)*data);
1669 offset = *((u32 *)*data);
1672 rc = qed_mcp_nvm_read(cdev, nvm_image.start_addr + offset, buf,
1675 DP_ERR(cdev, "Failed reading from %08x\n",
1676 nvm_image.start_addr + offset);
1680 cur_value = le32_to_cpu(*((__le32 *)buf));
1681 DP_VERBOSE(cdev, NETIF_MSG_DRV,
1682 "NVM %08x: %08x -> %08x [Value %08x Mask %08x]\n",
1683 nvm_image.start_addr + offset, cur_value,
1684 (cur_value & ~mask) | (value & mask), value, mask);
1685 value = (value & mask) | (cur_value & ~mask);
1686 rc = qed_mcp_nvm_write(cdev, QED_NVM_WRITE_NVRAM,
1687 nvm_image.start_addr + offset,
1690 DP_ERR(cdev, "Failed writing to %08x\n",
1691 nvm_image.start_addr + offset);
1701 /* Binary file format -
1702 * /----------------------------------------------------------------------\
1703 * 0B | 0x3 [command index] |
1704 * 4B | b'0: check_response? | b'1-31 reserved |
1705 * 8B | File-type | reserved |
1706 * \----------------------------------------------------------------------/
1707 * Start a new file of the provided type
1709 static int qed_nvm_flash_image_file_start(struct qed_dev *cdev,
1710 const u8 **data, bool *check_resp)
1715 *check_resp = !!(**data & BIT(0));
1718 DP_VERBOSE(cdev, NETIF_MSG_DRV,
1719 "About to start a new file of type %02x\n", **data);
1720 rc = qed_mcp_nvm_put_file_begin(cdev, **data);
1726 /* Binary file format -
1727 * /----------------------------------------------------------------------\
1728 * 0B | 0x2 [command index] |
1729 * 4B | Length in bytes |
1730 * 8B | b'0: check_response? | b'1-31 reserved |
1731 * 12B | Offset in bytes |
1733 * \----------------------------------------------------------------------/
1734 * Write data as part of a file that was previously started. Data should be
1735 * of length equal to that provided in the message
1737 static int qed_nvm_flash_image_file_data(struct qed_dev *cdev,
1738 const u8 **data, bool *check_resp)
1744 len = *((u32 *)(*data));
1746 *check_resp = !!(**data & BIT(0));
1748 offset = *((u32 *)(*data));
1751 DP_VERBOSE(cdev, NETIF_MSG_DRV,
1752 "About to write File-data: %08x bytes to offset %08x\n",
1755 rc = qed_mcp_nvm_write(cdev, QED_PUT_FILE_DATA, offset,
1756 (char *)(*data), len);
1762 /* Binary file format [General header] -
1763 * /----------------------------------------------------------------------\
1764 * 0B | QED_NVM_SIGNATURE |
1765 * 4B | Length in bytes |
1766 * 8B | Highest command in this batchfile | Reserved |
1767 * \----------------------------------------------------------------------/
1769 static int qed_nvm_flash_image_validate(struct qed_dev *cdev,
1770 const struct firmware *image,
1775 /* Check minimum size */
1776 if (image->size < 12) {
1777 DP_ERR(cdev, "Image is too short [%08x]\n", (u32)image->size);
1781 /* Check signature */
1782 signature = *((u32 *)(*data));
1783 if (signature != QED_NVM_SIGNATURE) {
1784 DP_ERR(cdev, "Wrong signature '%08x'\n", signature);
1789 /* Validate internal size equals the image-size */
1790 len = *((u32 *)(*data));
1791 if (len != image->size) {
1792 DP_ERR(cdev, "Size mismatch: internal = %08x image = %08x\n",
1793 len, (u32)image->size);
1798 /* Make sure driver familiar with all commands necessary for this */
1799 if (*((u16 *)(*data)) >= QED_NVM_FLASH_CMD_NVM_MAX) {
1800 DP_ERR(cdev, "File contains unsupported commands [Need %04x]\n",
1810 static int qed_nvm_flash(struct qed_dev *cdev, const char *name)
1812 const struct firmware *image;
1813 const u8 *data, *data_end;
1817 rc = request_firmware(&image, name, &cdev->pdev->dev);
1819 DP_ERR(cdev, "Failed to find '%s'\n", name);
1823 DP_VERBOSE(cdev, NETIF_MSG_DRV,
1824 "Flashing '%s' - firmware's data at %p, size is %08x\n",
1825 name, image->data, (u32)image->size);
1827 data_end = data + image->size;
1829 rc = qed_nvm_flash_image_validate(cdev, image, &data);
1833 while (data < data_end) {
1834 bool check_resp = false;
1836 /* Parse the actual command */
1837 cmd_type = *((u32 *)data);
1839 case QED_NVM_FLASH_CMD_FILE_DATA:
1840 rc = qed_nvm_flash_image_file_data(cdev, &data,
1843 case QED_NVM_FLASH_CMD_FILE_START:
1844 rc = qed_nvm_flash_image_file_start(cdev, &data,
1847 case QED_NVM_FLASH_CMD_NVM_CHANGE:
1848 rc = qed_nvm_flash_image_access(cdev, &data,
1852 DP_ERR(cdev, "Unknown command %08x\n", cmd_type);
1858 DP_ERR(cdev, "Command %08x failed\n", cmd_type);
1862 /* Check response if needed */
1864 u32 mcp_response = 0;
1866 if (qed_mcp_nvm_resp(cdev, (u8 *)&mcp_response)) {
1867 DP_ERR(cdev, "Failed getting MCP response\n");
1872 switch (mcp_response & FW_MSG_CODE_MASK) {
1873 case FW_MSG_CODE_OK:
1874 case FW_MSG_CODE_NVM_OK:
1875 case FW_MSG_CODE_NVM_PUT_FILE_FINISH_OK:
1876 case FW_MSG_CODE_PHY_OK:
1879 DP_ERR(cdev, "MFW returns error: %08x\n",
1888 release_firmware(image);
1893 static int qed_nvm_get_image(struct qed_dev *cdev, enum qed_nvm_images type,
1896 struct qed_hwfn *hwfn = QED_LEADING_HWFN(cdev);
1897 struct qed_ptt *ptt = qed_ptt_acquire(hwfn);
1903 rc = qed_mcp_get_nvm_image(hwfn, ptt, type, buf, len);
1904 qed_ptt_release(hwfn, ptt);
1908 static int qed_set_coalesce(struct qed_dev *cdev, u16 rx_coal, u16 tx_coal,
1911 return qed_set_queue_coalesce(rx_coal, tx_coal, handle);
1914 static int qed_set_led(struct qed_dev *cdev, enum qed_led_mode mode)
1916 struct qed_hwfn *hwfn = QED_LEADING_HWFN(cdev);
1917 struct qed_ptt *ptt;
1920 ptt = qed_ptt_acquire(hwfn);
1924 status = qed_mcp_set_led(hwfn, ptt, mode);
1926 qed_ptt_release(hwfn, ptt);
1931 static int qed_update_wol(struct qed_dev *cdev, bool enabled)
1933 struct qed_hwfn *hwfn = QED_LEADING_HWFN(cdev);
1934 struct qed_ptt *ptt;
1940 ptt = qed_ptt_acquire(hwfn);
1944 rc = qed_mcp_ov_update_wol(hwfn, ptt, enabled ? QED_OV_WOL_ENABLED
1945 : QED_OV_WOL_DISABLED);
1948 rc = qed_mcp_ov_update_current_config(hwfn, ptt, QED_OV_CLIENT_DRV);
1951 qed_ptt_release(hwfn, ptt);
1955 static int qed_update_drv_state(struct qed_dev *cdev, bool active)
1957 struct qed_hwfn *hwfn = QED_LEADING_HWFN(cdev);
1958 struct qed_ptt *ptt;
1964 ptt = qed_ptt_acquire(hwfn);
1968 status = qed_mcp_ov_update_driver_state(hwfn, ptt, active ?
1969 QED_OV_DRIVER_STATE_ACTIVE :
1970 QED_OV_DRIVER_STATE_DISABLED);
1972 qed_ptt_release(hwfn, ptt);
1977 static int qed_update_mac(struct qed_dev *cdev, u8 *mac)
1979 struct qed_hwfn *hwfn = QED_LEADING_HWFN(cdev);
1980 struct qed_ptt *ptt;
1986 ptt = qed_ptt_acquire(hwfn);
1990 status = qed_mcp_ov_update_mac(hwfn, ptt, mac);
1994 status = qed_mcp_ov_update_current_config(hwfn, ptt, QED_OV_CLIENT_DRV);
1997 qed_ptt_release(hwfn, ptt);
2001 static int qed_update_mtu(struct qed_dev *cdev, u16 mtu)
2003 struct qed_hwfn *hwfn = QED_LEADING_HWFN(cdev);
2004 struct qed_ptt *ptt;
2010 ptt = qed_ptt_acquire(hwfn);
2014 status = qed_mcp_ov_update_mtu(hwfn, ptt, mtu);
2018 status = qed_mcp_ov_update_current_config(hwfn, ptt, QED_OV_CLIENT_DRV);
2021 qed_ptt_release(hwfn, ptt);
2025 static struct qed_selftest_ops qed_selftest_ops_pass = {
2026 .selftest_memory = &qed_selftest_memory,
2027 .selftest_interrupt = &qed_selftest_interrupt,
2028 .selftest_register = &qed_selftest_register,
2029 .selftest_clock = &qed_selftest_clock,
2030 .selftest_nvram = &qed_selftest_nvram,
2033 const struct qed_common_ops qed_common_ops_pass = {
2034 .selftest = &qed_selftest_ops_pass,
2035 .probe = &qed_probe,
2036 .remove = &qed_remove,
2037 .set_power_state = &qed_set_power_state,
2038 .set_name = &qed_set_name,
2039 .update_pf_params = &qed_update_pf_params,
2040 .slowpath_start = &qed_slowpath_start,
2041 .slowpath_stop = &qed_slowpath_stop,
2042 .set_fp_int = &qed_set_int_fp,
2043 .get_fp_int = &qed_get_int_fp,
2044 .sb_init = &qed_sb_init,
2045 .sb_release = &qed_sb_release,
2046 .simd_handler_config = &qed_simd_handler_config,
2047 .simd_handler_clean = &qed_simd_handler_clean,
2048 .dbg_grc = &qed_dbg_grc,
2049 .dbg_grc_size = &qed_dbg_grc_size,
2050 .can_link_change = &qed_can_link_change,
2051 .set_link = &qed_set_link,
2052 .get_link = &qed_get_current_link,
2053 .drain = &qed_drain,
2054 .update_msglvl = &qed_init_dp,
2055 .dbg_all_data = &qed_dbg_all_data,
2056 .dbg_all_data_size = &qed_dbg_all_data_size,
2057 .chain_alloc = &qed_chain_alloc,
2058 .chain_free = &qed_chain_free,
2059 .nvm_flash = &qed_nvm_flash,
2060 .nvm_get_image = &qed_nvm_get_image,
2061 .set_coalesce = &qed_set_coalesce,
2062 .set_led = &qed_set_led,
2063 .update_drv_state = &qed_update_drv_state,
2064 .update_mac = &qed_update_mac,
2065 .update_mtu = &qed_update_mtu,
2066 .update_wol = &qed_update_wol,
2069 void qed_get_protocol_stats(struct qed_dev *cdev,
2070 enum qed_mcp_protocol_type type,
2071 union qed_mcp_protocol_stats *stats)
2073 struct qed_eth_stats eth_stats;
2075 memset(stats, 0, sizeof(*stats));
2078 case QED_MCP_LAN_STATS:
2079 qed_get_vport_stats(cdev, ð_stats);
2080 stats->lan_stats.ucast_rx_pkts =
2081 eth_stats.common.rx_ucast_pkts;
2082 stats->lan_stats.ucast_tx_pkts =
2083 eth_stats.common.tx_ucast_pkts;
2084 stats->lan_stats.fcs_err = -1;
2086 case QED_MCP_FCOE_STATS:
2087 qed_get_protocol_stats_fcoe(cdev, &stats->fcoe_stats);
2089 case QED_MCP_ISCSI_STATS:
2090 qed_get_protocol_stats_iscsi(cdev, &stats->iscsi_stats);
2093 DP_VERBOSE(cdev, QED_MSG_SP,
2094 "Invalid protocol type = %d\n", type);