1 /* QLogic qed NIC Driver
2 * Copyright (c) 2015 QLogic Corporation
4 * This software is available under the terms of the GNU General Public License
5 * (GPL) Version 2, available from the file COPYING in the main directory of
9 #include <linux/stddef.h>
10 #include <linux/pci.h>
11 #include <linux/kernel.h>
12 #include <linux/slab.h>
13 #include <linux/version.h>
14 #include <linux/delay.h>
15 #include <asm/byteorder.h>
16 #include <linux/dma-mapping.h>
17 #include <linux/string.h>
18 #include <linux/module.h>
19 #include <linux/interrupt.h>
20 #include <linux/workqueue.h>
21 #include <linux/ethtool.h>
22 #include <linux/etherdevice.h>
23 #include <linux/vmalloc.h>
24 #include <linux/qed/qed_if.h>
25 #include <linux/crash_dump.h>
29 #include "qed_dev_api.h"
33 static const char version[] =
34 "QLogic QL4xxx 40G/100G Ethernet Driver qed " DRV_MODULE_VERSION "\n";
36 MODULE_DESCRIPTION("QLogic 25G/40G/50G/100G Core Module");
37 MODULE_LICENSE("GPL");
38 MODULE_VERSION(DRV_MODULE_VERSION);
40 #define FW_FILE_VERSION \
41 __stringify(FW_MAJOR_VERSION) "." \
42 __stringify(FW_MINOR_VERSION) "." \
43 __stringify(FW_REVISION_VERSION) "." \
44 __stringify(FW_ENGINEERING_VERSION)
46 #define QED_FW_FILE_NAME \
49 static int __init qed_init(void)
51 pr_notice("qed_init called\n");
53 pr_info("%s", version);
58 static void __exit qed_cleanup(void)
60 pr_notice("qed_cleanup called\n");
63 module_init(qed_init);
64 module_exit(qed_cleanup);
66 /* Check if the DMA controller on the machine can properly handle the DMA
67 * addressing required by the device.
69 static int qed_set_coherency_mask(struct qed_dev *cdev)
71 struct device *dev = &cdev->pdev->dev;
73 if (dma_set_mask(dev, DMA_BIT_MASK(64)) == 0) {
74 if (dma_set_coherent_mask(dev, DMA_BIT_MASK(64)) != 0) {
76 "Can't request 64-bit consistent allocations\n");
79 } else if (dma_set_mask(dev, DMA_BIT_MASK(32)) != 0) {
80 DP_NOTICE(cdev, "Can't request 64b/32b DMA addresses\n");
87 static void qed_free_pci(struct qed_dev *cdev)
89 struct pci_dev *pdev = cdev->pdev;
92 iounmap(cdev->doorbells);
94 iounmap(cdev->regview);
95 if (atomic_read(&pdev->enable_cnt) == 1)
96 pci_release_regions(pdev);
98 pci_disable_device(pdev);
101 /* Performs PCI initializations as well as initializing PCI-related parameters
102 * in the device structrue. Returns 0 in case of success.
104 static int qed_init_pci(struct qed_dev *cdev,
105 struct pci_dev *pdev)
111 rc = pci_enable_device(pdev);
113 DP_NOTICE(cdev, "Cannot enable PCI device\n");
117 if (!(pci_resource_flags(pdev, 0) & IORESOURCE_MEM)) {
118 DP_NOTICE(cdev, "No memory region found in bar #0\n");
123 if (!(pci_resource_flags(pdev, 2) & IORESOURCE_MEM)) {
124 DP_NOTICE(cdev, "No memory region found in bar #2\n");
129 if (atomic_read(&pdev->enable_cnt) == 1) {
130 rc = pci_request_regions(pdev, "qed");
133 "Failed to request PCI memory resources\n");
136 pci_set_master(pdev);
137 pci_save_state(pdev);
140 if (!pci_is_pcie(pdev)) {
141 DP_NOTICE(cdev, "The bus is not PCI Express\n");
146 cdev->pci_params.pm_cap = pci_find_capability(pdev, PCI_CAP_ID_PM);
147 if (cdev->pci_params.pm_cap == 0)
148 DP_NOTICE(cdev, "Cannot find power management capability\n");
150 rc = qed_set_coherency_mask(cdev);
154 cdev->pci_params.mem_start = pci_resource_start(pdev, 0);
155 cdev->pci_params.mem_end = pci_resource_end(pdev, 0);
156 cdev->pci_params.irq = pdev->irq;
158 cdev->regview = pci_ioremap_bar(pdev, 0);
159 if (!cdev->regview) {
160 DP_NOTICE(cdev, "Cannot map register space, aborting\n");
165 cdev->db_phys_addr = pci_resource_start(cdev->pdev, 2);
166 cdev->db_size = pci_resource_len(cdev->pdev, 2);
167 cdev->doorbells = ioremap_wc(cdev->db_phys_addr, cdev->db_size);
168 if (!cdev->doorbells) {
169 DP_NOTICE(cdev, "Cannot map doorbell space\n");
176 pci_release_regions(pdev);
178 pci_disable_device(pdev);
183 int qed_fill_dev_info(struct qed_dev *cdev,
184 struct qed_dev_info *dev_info)
188 memset(dev_info, 0, sizeof(struct qed_dev_info));
190 dev_info->num_hwfns = cdev->num_hwfns;
191 dev_info->pci_mem_start = cdev->pci_params.mem_start;
192 dev_info->pci_mem_end = cdev->pci_params.mem_end;
193 dev_info->pci_irq = cdev->pci_params.irq;
194 dev_info->is_mf = IS_MF(&cdev->hwfns[0]);
195 ether_addr_copy(dev_info->hw_mac, cdev->hwfns[0].hw_info.hw_mac_addr);
197 dev_info->fw_major = FW_MAJOR_VERSION;
198 dev_info->fw_minor = FW_MINOR_VERSION;
199 dev_info->fw_rev = FW_REVISION_VERSION;
200 dev_info->fw_eng = FW_ENGINEERING_VERSION;
201 dev_info->mf_mode = cdev->mf_mode;
203 qed_mcp_get_mfw_ver(cdev, &dev_info->mfw_rev);
205 ptt = qed_ptt_acquire(QED_LEADING_HWFN(cdev));
207 qed_mcp_get_flash_size(QED_LEADING_HWFN(cdev), ptt,
208 &dev_info->flash_size);
210 qed_ptt_release(QED_LEADING_HWFN(cdev), ptt);
216 static void qed_free_cdev(struct qed_dev *cdev)
221 static struct qed_dev *qed_alloc_cdev(struct pci_dev *pdev)
223 struct qed_dev *cdev;
225 cdev = kzalloc(sizeof(*cdev), GFP_KERNEL);
229 qed_init_struct(cdev);
234 /* Sets the requested power state */
235 static int qed_set_power_state(struct qed_dev *cdev,
241 DP_VERBOSE(cdev, NETIF_MSG_DRV, "Omitting Power state change\n");
246 static struct qed_dev *qed_probe(struct pci_dev *pdev,
247 enum qed_protocol protocol,
251 struct qed_dev *cdev;
254 cdev = qed_alloc_cdev(pdev);
258 cdev->protocol = protocol;
260 qed_init_dp(cdev, dp_module, dp_level);
262 rc = qed_init_pci(cdev, pdev);
264 DP_ERR(cdev, "init pci failed\n");
267 DP_INFO(cdev, "PCI init completed successfully\n");
269 rc = qed_hw_prepare(cdev, QED_PCI_DEFAULT);
271 DP_ERR(cdev, "hw prepare failed\n");
275 DP_INFO(cdev, "qed_probe completed successffuly\n");
287 static void qed_remove(struct qed_dev *cdev)
296 qed_set_power_state(cdev, PCI_D3hot);
301 static void qed_disable_msix(struct qed_dev *cdev)
303 if (cdev->int_params.out.int_mode == QED_INT_MODE_MSIX) {
304 pci_disable_msix(cdev->pdev);
305 kfree(cdev->int_params.msix_table);
306 } else if (cdev->int_params.out.int_mode == QED_INT_MODE_MSI) {
307 pci_disable_msi(cdev->pdev);
310 memset(&cdev->int_params.out, 0, sizeof(struct qed_int_param));
313 static int qed_enable_msix(struct qed_dev *cdev,
314 struct qed_int_params *int_params)
318 cnt = int_params->in.num_vectors;
320 for (i = 0; i < cnt; i++)
321 int_params->msix_table[i].entry = i;
323 rc = pci_enable_msix_range(cdev->pdev, int_params->msix_table,
324 int_params->in.min_msix_cnt, cnt);
325 if (rc < cnt && rc >= int_params->in.min_msix_cnt &&
326 (rc % cdev->num_hwfns)) {
327 pci_disable_msix(cdev->pdev);
329 /* If fastpath is initialized, we need at least one interrupt
330 * per hwfn [and the slow path interrupts]. New requested number
331 * should be a multiple of the number of hwfns.
333 cnt = (rc / cdev->num_hwfns) * cdev->num_hwfns;
335 "Trying to enable MSI-X with less vectors (%d out of %d)\n",
336 cnt, int_params->in.num_vectors);
337 rc = pci_enable_msix_exact(cdev->pdev,
338 int_params->msix_table, cnt);
344 /* MSI-x configuration was achieved */
345 int_params->out.int_mode = QED_INT_MODE_MSIX;
346 int_params->out.num_vectors = rc;
350 "Failed to enable MSI-X [Requested %d vectors][rc %d]\n",
357 /* This function outputs the int mode and the number of enabled msix vector */
358 static int qed_set_int_mode(struct qed_dev *cdev, bool force_mode)
360 struct qed_int_params *int_params = &cdev->int_params;
361 struct msix_entry *tbl;
364 switch (int_params->in.int_mode) {
365 case QED_INT_MODE_MSIX:
366 /* Allocate MSIX table */
367 cnt = int_params->in.num_vectors;
368 int_params->msix_table = kcalloc(cnt, sizeof(*tbl), GFP_KERNEL);
369 if (!int_params->msix_table) {
375 rc = qed_enable_msix(cdev, int_params);
379 DP_NOTICE(cdev, "Failed to enable MSI-X\n");
380 kfree(int_params->msix_table);
385 case QED_INT_MODE_MSI:
386 rc = pci_enable_msi(cdev->pdev);
388 int_params->out.int_mode = QED_INT_MODE_MSI;
392 DP_NOTICE(cdev, "Failed to enable MSI\n");
397 case QED_INT_MODE_INTA:
398 int_params->out.int_mode = QED_INT_MODE_INTA;
402 DP_NOTICE(cdev, "Unknown int_mode value %d\n",
403 int_params->in.int_mode);
408 cdev->int_coalescing_mode = QED_COAL_MODE_ENABLE;
413 static void qed_simd_handler_config(struct qed_dev *cdev, void *token,
414 int index, void(*handler)(void *))
416 struct qed_hwfn *hwfn = &cdev->hwfns[index % cdev->num_hwfns];
417 int relative_idx = index / cdev->num_hwfns;
419 hwfn->simd_proto_handler[relative_idx].func = handler;
420 hwfn->simd_proto_handler[relative_idx].token = token;
423 static void qed_simd_handler_clean(struct qed_dev *cdev, int index)
425 struct qed_hwfn *hwfn = &cdev->hwfns[index % cdev->num_hwfns];
426 int relative_idx = index / cdev->num_hwfns;
428 memset(&hwfn->simd_proto_handler[relative_idx], 0,
429 sizeof(struct qed_simd_fp_handler));
432 static irqreturn_t qed_msix_sp_int(int irq, void *tasklet)
434 tasklet_schedule((struct tasklet_struct *)tasklet);
438 static irqreturn_t qed_single_int(int irq, void *dev_instance)
440 struct qed_dev *cdev = (struct qed_dev *)dev_instance;
441 struct qed_hwfn *hwfn;
442 irqreturn_t rc = IRQ_NONE;
446 for (i = 0; i < cdev->num_hwfns; i++) {
447 status = qed_int_igu_read_sisr_reg(&cdev->hwfns[i]);
452 hwfn = &cdev->hwfns[i];
454 /* Slowpath interrupt */
455 if (unlikely(status & 0x1)) {
456 tasklet_schedule(hwfn->sp_dpc);
461 /* Fastpath interrupts */
462 for (j = 0; j < 64; j++) {
463 if ((0x2ULL << j) & status) {
464 struct qed_simd_fp_handler *p_handler =
465 &hwfn->simd_proto_handler[j];
468 p_handler->func(p_handler->token);
471 "Not calling fastpath handler as it is NULL [handler #%d, status 0x%llx]\n",
474 status &= ~(0x2ULL << j);
479 if (unlikely(status))
480 DP_VERBOSE(hwfn, NETIF_MSG_INTR,
481 "got an unknown interrupt status 0x%llx\n",
488 int qed_slowpath_irq_req(struct qed_hwfn *hwfn)
490 struct qed_dev *cdev = hwfn->cdev;
494 if (cdev->int_params.out.int_mode == QED_INT_MODE_MSIX) {
496 snprintf(hwfn->name, NAME_SIZE, "sp-%d-%02x:%02x.%02x",
497 id, cdev->pdev->bus->number,
498 PCI_SLOT(cdev->pdev->devfn), hwfn->abs_pf_id);
499 rc = request_irq(cdev->int_params.msix_table[id].vector,
500 qed_msix_sp_int, 0, hwfn->name, hwfn->sp_dpc);
502 DP_VERBOSE(hwfn, (NETIF_MSG_INTR | QED_MSG_SP),
503 "Requested slowpath MSI-X\n");
505 unsigned long flags = 0;
507 snprintf(cdev->name, NAME_SIZE, "%02x:%02x.%02x",
508 cdev->pdev->bus->number, PCI_SLOT(cdev->pdev->devfn),
509 PCI_FUNC(cdev->pdev->devfn));
511 if (cdev->int_params.out.int_mode == QED_INT_MODE_INTA)
512 flags |= IRQF_SHARED;
514 rc = request_irq(cdev->pdev->irq, qed_single_int,
515 flags, cdev->name, cdev);
521 static void qed_slowpath_irq_free(struct qed_dev *cdev)
525 if (cdev->int_params.out.int_mode == QED_INT_MODE_MSIX) {
526 for_each_hwfn(cdev, i) {
527 if (!cdev->hwfns[i].b_int_requested)
529 synchronize_irq(cdev->int_params.msix_table[i].vector);
530 free_irq(cdev->int_params.msix_table[i].vector,
531 cdev->hwfns[i].sp_dpc);
534 if (QED_LEADING_HWFN(cdev)->b_int_requested)
535 free_irq(cdev->pdev->irq, cdev);
537 qed_int_disable_post_isr_release(cdev);
540 static int qed_nic_stop(struct qed_dev *cdev)
544 rc = qed_hw_stop(cdev);
546 for (i = 0; i < cdev->num_hwfns; i++) {
547 struct qed_hwfn *p_hwfn = &cdev->hwfns[i];
549 if (p_hwfn->b_sp_dpc_enabled) {
550 tasklet_disable(p_hwfn->sp_dpc);
551 p_hwfn->b_sp_dpc_enabled = false;
552 DP_VERBOSE(cdev, NETIF_MSG_IFDOWN,
553 "Disabled sp taskelt [hwfn %d] at %p\n",
561 static int qed_nic_reset(struct qed_dev *cdev)
565 rc = qed_hw_reset(cdev);
574 static int qed_nic_setup(struct qed_dev *cdev)
578 rc = qed_resc_alloc(cdev);
582 DP_INFO(cdev, "Allocated qed resources\n");
584 qed_resc_setup(cdev);
589 static int qed_set_int_fp(struct qed_dev *cdev, u16 cnt)
593 /* Mark the fastpath as free/used */
594 cdev->int_params.fp_initialized = cnt ? true : false;
596 if (cdev->int_params.out.int_mode != QED_INT_MODE_MSIX)
597 limit = cdev->num_hwfns * 63;
598 else if (cdev->int_params.fp_msix_cnt)
599 limit = cdev->int_params.fp_msix_cnt;
604 return min_t(int, cnt, limit);
607 static int qed_get_int_fp(struct qed_dev *cdev, struct qed_int_info *info)
609 memset(info, 0, sizeof(struct qed_int_info));
611 if (!cdev->int_params.fp_initialized) {
613 "Protocol driver requested interrupt information, but its support is not yet configured\n");
617 /* Need to expose only MSI-X information; Single IRQ is handled solely
620 if (cdev->int_params.out.int_mode == QED_INT_MODE_MSIX) {
621 int msix_base = cdev->int_params.fp_msix_base;
623 info->msix_cnt = cdev->int_params.fp_msix_cnt;
624 info->msix = &cdev->int_params.msix_table[msix_base];
630 static int qed_slowpath_setup_int(struct qed_dev *cdev,
631 enum qed_int_mode int_mode)
636 memset(&cdev->int_params, 0, sizeof(struct qed_int_params));
638 cdev->int_params.in.int_mode = int_mode;
639 for_each_hwfn(cdev, i)
640 num_vectors += qed_int_get_num_sbs(&cdev->hwfns[i], NULL) + 1;
641 cdev->int_params.in.num_vectors = num_vectors;
643 /* We want a minimum of one slowpath and one fastpath vector per hwfn */
644 cdev->int_params.in.min_msix_cnt = cdev->num_hwfns * 2;
646 if (is_kdump_kernel()) {
648 "Kdump kernel: Limit the max number of requested MSI-X vectors to %hd\n",
649 cdev->int_params.in.min_msix_cnt);
650 cdev->int_params.in.num_vectors =
651 cdev->int_params.in.min_msix_cnt;
654 rc = qed_set_int_mode(cdev, false);
656 DP_ERR(cdev, "qed_slowpath_setup_int ERR\n");
660 cdev->int_params.fp_msix_base = cdev->num_hwfns;
661 cdev->int_params.fp_msix_cnt = cdev->int_params.out.num_vectors -
667 u32 qed_unzip_data(struct qed_hwfn *p_hwfn, u32 input_len,
668 u8 *input_buf, u32 max_size, u8 *unzip_buf)
672 p_hwfn->stream->next_in = input_buf;
673 p_hwfn->stream->avail_in = input_len;
674 p_hwfn->stream->next_out = unzip_buf;
675 p_hwfn->stream->avail_out = max_size;
677 rc = zlib_inflateInit2(p_hwfn->stream, MAX_WBITS);
680 DP_VERBOSE(p_hwfn, NETIF_MSG_DRV, "zlib init failed, rc = %d\n",
685 rc = zlib_inflate(p_hwfn->stream, Z_FINISH);
686 zlib_inflateEnd(p_hwfn->stream);
688 if (rc != Z_OK && rc != Z_STREAM_END) {
689 DP_VERBOSE(p_hwfn, NETIF_MSG_DRV, "FW unzip error: %s, rc=%d\n",
690 p_hwfn->stream->msg, rc);
694 return p_hwfn->stream->total_out / 4;
697 static int qed_alloc_stream_mem(struct qed_dev *cdev)
702 for_each_hwfn(cdev, i) {
703 struct qed_hwfn *p_hwfn = &cdev->hwfns[i];
705 p_hwfn->stream = kzalloc(sizeof(*p_hwfn->stream), GFP_KERNEL);
709 workspace = vzalloc(zlib_inflate_workspacesize());
712 p_hwfn->stream->workspace = workspace;
718 static void qed_free_stream_mem(struct qed_dev *cdev)
722 for_each_hwfn(cdev, i) {
723 struct qed_hwfn *p_hwfn = &cdev->hwfns[i];
728 vfree(p_hwfn->stream->workspace);
729 kfree(p_hwfn->stream);
733 static void qed_update_pf_params(struct qed_dev *cdev,
734 struct qed_pf_params *params)
738 for (i = 0; i < cdev->num_hwfns; i++) {
739 struct qed_hwfn *p_hwfn = &cdev->hwfns[i];
741 p_hwfn->pf_params = *params;
745 static int qed_slowpath_start(struct qed_dev *cdev,
746 struct qed_slowpath_params *params)
748 struct qed_mcp_drv_version drv_version;
749 const u8 *data = NULL;
750 struct qed_hwfn *hwfn;
753 rc = reject_firmware(&cdev->firmware, QED_FW_FILE_NAME,
757 "Failed to find fw file - /lib/firmware/%s\n",
762 rc = qed_nic_setup(cdev);
766 rc = qed_slowpath_setup_int(cdev, params->int_mode);
770 /* Allocate stream for unzipping */
771 rc = qed_alloc_stream_mem(cdev);
773 DP_NOTICE(cdev, "Failed to allocate stream memory\n");
777 /* Start the slowpath */
778 data = cdev->firmware->data;
780 rc = qed_hw_init(cdev, true, cdev->int_params.out.int_mode,
786 "HW initialization and function start completed successfully\n");
788 hwfn = QED_LEADING_HWFN(cdev);
789 drv_version.version = (params->drv_major << 24) |
790 (params->drv_minor << 16) |
791 (params->drv_rev << 8) |
793 strlcpy(drv_version.name, params->name,
794 MCP_DRV_VER_STR_SIZE - 4);
795 rc = qed_mcp_send_drv_version(hwfn, hwfn->p_main_ptt,
798 DP_NOTICE(cdev, "Failed sending drv version command\n");
805 qed_free_stream_mem(cdev);
806 qed_slowpath_irq_free(cdev);
808 qed_disable_msix(cdev);
812 release_firmware(cdev->firmware);
817 static int qed_slowpath_stop(struct qed_dev *cdev)
822 qed_free_stream_mem(cdev);
825 qed_slowpath_irq_free(cdev);
827 qed_disable_msix(cdev);
830 release_firmware(cdev->firmware);
835 static void qed_set_id(struct qed_dev *cdev, char name[NAME_SIZE],
836 char ver_str[VER_SIZE])
840 memcpy(cdev->name, name, NAME_SIZE);
841 for_each_hwfn(cdev, i)
842 snprintf(cdev->hwfns[i].name, NAME_SIZE, "%s-%d", name, i);
844 memcpy(cdev->ver_str, ver_str, VER_SIZE);
845 cdev->drv_type = DRV_ID_DRV_TYPE_LINUX;
848 static u32 qed_sb_init(struct qed_dev *cdev,
849 struct qed_sb_info *sb_info,
851 dma_addr_t sb_phy_addr, u16 sb_id,
852 enum qed_sb_type type)
854 struct qed_hwfn *p_hwfn;
860 /* RoCE uses single engine and CMT uses two engines. When using both
861 * we force only a single engine. Storage uses only engine 0 too.
863 if (type == QED_SB_TYPE_L2_QUEUE)
864 n_hwfns = cdev->num_hwfns;
868 hwfn_index = sb_id % n_hwfns;
869 p_hwfn = &cdev->hwfns[hwfn_index];
870 rel_sb_id = sb_id / n_hwfns;
872 DP_VERBOSE(cdev, NETIF_MSG_INTR,
873 "hwfn [%d] <--[init]-- SB %04x [0x%04x upper]\n",
874 hwfn_index, rel_sb_id, sb_id);
876 rc = qed_int_sb_init(p_hwfn, p_hwfn->p_main_ptt, sb_info,
877 sb_virt_addr, sb_phy_addr, rel_sb_id);
882 static u32 qed_sb_release(struct qed_dev *cdev,
883 struct qed_sb_info *sb_info,
886 struct qed_hwfn *p_hwfn;
891 hwfn_index = sb_id % cdev->num_hwfns;
892 p_hwfn = &cdev->hwfns[hwfn_index];
893 rel_sb_id = sb_id / cdev->num_hwfns;
895 DP_VERBOSE(cdev, NETIF_MSG_INTR,
896 "hwfn [%d] <--[init]-- SB %04x [0x%04x upper]\n",
897 hwfn_index, rel_sb_id, sb_id);
899 rc = qed_int_sb_release(p_hwfn, sb_info, rel_sb_id);
904 static int qed_set_link(struct qed_dev *cdev,
905 struct qed_link_params *params)
907 struct qed_hwfn *hwfn;
908 struct qed_mcp_link_params *link_params;
915 /* The link should be set only once per PF */
916 hwfn = &cdev->hwfns[0];
918 ptt = qed_ptt_acquire(hwfn);
922 link_params = qed_mcp_get_link_params(hwfn);
923 if (params->override_flags & QED_LINK_OVERRIDE_SPEED_AUTONEG)
924 link_params->speed.autoneg = params->autoneg;
925 if (params->override_flags & QED_LINK_OVERRIDE_SPEED_ADV_SPEEDS) {
926 link_params->speed.advertised_speeds = 0;
927 if ((params->adv_speeds & SUPPORTED_1000baseT_Half) ||
928 (params->adv_speeds & SUPPORTED_1000baseT_Full))
929 link_params->speed.advertised_speeds |=
930 NVM_CFG1_PORT_DRV_SPEED_CAPABILITY_MASK_1G;
931 if (params->adv_speeds & SUPPORTED_10000baseKR_Full)
932 link_params->speed.advertised_speeds |=
933 NVM_CFG1_PORT_DRV_SPEED_CAPABILITY_MASK_10G;
934 if (params->adv_speeds & SUPPORTED_40000baseLR4_Full)
935 link_params->speed.advertised_speeds |=
936 NVM_CFG1_PORT_DRV_SPEED_CAPABILITY_MASK_40G;
937 if (params->adv_speeds & 0)
938 link_params->speed.advertised_speeds |=
939 NVM_CFG1_PORT_DRV_SPEED_CAPABILITY_MASK_50G;
940 if (params->adv_speeds & 0)
941 link_params->speed.advertised_speeds |=
942 NVM_CFG1_PORT_DRV_SPEED_CAPABILITY_MASK_100G;
944 if (params->override_flags & QED_LINK_OVERRIDE_SPEED_FORCED_SPEED)
945 link_params->speed.forced_speed = params->forced_speed;
947 rc = qed_mcp_set_link(hwfn, ptt, params->link_up);
949 qed_ptt_release(hwfn, ptt);
954 static int qed_get_port_type(u32 media_type)
958 switch (media_type) {
959 case MEDIA_SFPP_10G_FIBER:
960 case MEDIA_SFP_1G_FIBER:
961 case MEDIA_XFP_FIBER:
963 port_type = PORT_FIBRE;
965 case MEDIA_DA_TWINAX:
971 case MEDIA_NOT_PRESENT:
972 port_type = PORT_NONE;
974 case MEDIA_UNSPECIFIED:
976 port_type = PORT_OTHER;
982 static void qed_fill_link(struct qed_hwfn *hwfn,
983 struct qed_link_output *if_link)
985 struct qed_mcp_link_params params;
986 struct qed_mcp_link_state link;
987 struct qed_mcp_link_capabilities link_caps;
990 memset(if_link, 0, sizeof(*if_link));
992 /* Prepare source inputs */
993 memcpy(¶ms, qed_mcp_get_link_params(hwfn), sizeof(params));
994 memcpy(&link, qed_mcp_get_link_state(hwfn), sizeof(link));
995 memcpy(&link_caps, qed_mcp_get_link_capabilities(hwfn),
998 /* Set the link parameters to pass to protocol driver */
1000 if_link->link_up = true;
1002 /* TODO - at the moment assume supported and advertised speed equal */
1003 if_link->supported_caps = SUPPORTED_FIBRE;
1004 if (params.speed.autoneg)
1005 if_link->supported_caps |= SUPPORTED_Autoneg;
1006 if (params.pause.autoneg ||
1007 (params.pause.forced_rx && params.pause.forced_tx))
1008 if_link->supported_caps |= SUPPORTED_Asym_Pause;
1009 if (params.pause.autoneg || params.pause.forced_rx ||
1010 params.pause.forced_tx)
1011 if_link->supported_caps |= SUPPORTED_Pause;
1013 if_link->advertised_caps = if_link->supported_caps;
1014 if (params.speed.advertised_speeds &
1015 NVM_CFG1_PORT_DRV_SPEED_CAPABILITY_MASK_1G)
1016 if_link->advertised_caps |= SUPPORTED_1000baseT_Half |
1017 SUPPORTED_1000baseT_Full;
1018 if (params.speed.advertised_speeds &
1019 NVM_CFG1_PORT_DRV_SPEED_CAPABILITY_MASK_10G)
1020 if_link->advertised_caps |= SUPPORTED_10000baseKR_Full;
1021 if (params.speed.advertised_speeds &
1022 NVM_CFG1_PORT_DRV_SPEED_CAPABILITY_MASK_40G)
1023 if_link->advertised_caps |= SUPPORTED_40000baseLR4_Full;
1024 if (params.speed.advertised_speeds &
1025 NVM_CFG1_PORT_DRV_SPEED_CAPABILITY_MASK_50G)
1026 if_link->advertised_caps |= 0;
1027 if (params.speed.advertised_speeds &
1028 NVM_CFG1_PORT_DRV_SPEED_CAPABILITY_MASK_100G)
1029 if_link->advertised_caps |= 0;
1031 if (link_caps.speed_capabilities &
1032 NVM_CFG1_PORT_DRV_SPEED_CAPABILITY_MASK_1G)
1033 if_link->supported_caps |= SUPPORTED_1000baseT_Half |
1034 SUPPORTED_1000baseT_Full;
1035 if (link_caps.speed_capabilities &
1036 NVM_CFG1_PORT_DRV_SPEED_CAPABILITY_MASK_10G)
1037 if_link->supported_caps |= SUPPORTED_10000baseKR_Full;
1038 if (link_caps.speed_capabilities &
1039 NVM_CFG1_PORT_DRV_SPEED_CAPABILITY_MASK_40G)
1040 if_link->supported_caps |= SUPPORTED_40000baseLR4_Full;
1041 if (link_caps.speed_capabilities &
1042 NVM_CFG1_PORT_DRV_SPEED_CAPABILITY_MASK_50G)
1043 if_link->supported_caps |= 0;
1044 if (link_caps.speed_capabilities &
1045 NVM_CFG1_PORT_DRV_SPEED_CAPABILITY_MASK_100G)
1046 if_link->supported_caps |= 0;
1049 if_link->speed = link.speed;
1051 /* TODO - fill duplex properly */
1052 if_link->duplex = DUPLEX_FULL;
1053 qed_mcp_get_media_type(hwfn->cdev, &media_type);
1054 if_link->port = qed_get_port_type(media_type);
1056 if_link->autoneg = params.speed.autoneg;
1058 if (params.pause.autoneg)
1059 if_link->pause_config |= QED_LINK_PAUSE_AUTONEG_ENABLE;
1060 if (params.pause.forced_rx)
1061 if_link->pause_config |= QED_LINK_PAUSE_RX_ENABLE;
1062 if (params.pause.forced_tx)
1063 if_link->pause_config |= QED_LINK_PAUSE_TX_ENABLE;
1065 /* Link partner capabilities */
1066 if (link.partner_adv_speed &
1067 QED_LINK_PARTNER_SPEED_1G_HD)
1068 if_link->lp_caps |= SUPPORTED_1000baseT_Half;
1069 if (link.partner_adv_speed &
1070 QED_LINK_PARTNER_SPEED_1G_FD)
1071 if_link->lp_caps |= SUPPORTED_1000baseT_Full;
1072 if (link.partner_adv_speed &
1073 QED_LINK_PARTNER_SPEED_10G)
1074 if_link->lp_caps |= SUPPORTED_10000baseKR_Full;
1075 if (link.partner_adv_speed &
1076 QED_LINK_PARTNER_SPEED_40G)
1077 if_link->lp_caps |= SUPPORTED_40000baseLR4_Full;
1078 if (link.partner_adv_speed &
1079 QED_LINK_PARTNER_SPEED_50G)
1080 if_link->lp_caps |= 0;
1081 if (link.partner_adv_speed &
1082 QED_LINK_PARTNER_SPEED_100G)
1083 if_link->lp_caps |= 0;
1085 if (link.an_complete)
1086 if_link->lp_caps |= SUPPORTED_Autoneg;
1088 if (link.partner_adv_pause)
1089 if_link->lp_caps |= SUPPORTED_Pause;
1090 if (link.partner_adv_pause == QED_LINK_PARTNER_ASYMMETRIC_PAUSE ||
1091 link.partner_adv_pause == QED_LINK_PARTNER_BOTH_PAUSE)
1092 if_link->lp_caps |= SUPPORTED_Asym_Pause;
1095 static void qed_get_current_link(struct qed_dev *cdev,
1096 struct qed_link_output *if_link)
1098 qed_fill_link(&cdev->hwfns[0], if_link);
1101 void qed_link_update(struct qed_hwfn *hwfn)
1103 void *cookie = hwfn->cdev->ops_cookie;
1104 struct qed_common_cb_ops *op = hwfn->cdev->protocol_ops.common;
1105 struct qed_link_output if_link;
1107 qed_fill_link(hwfn, &if_link);
1109 if (IS_LEAD_HWFN(hwfn) && cookie)
1110 op->link_update(cookie, &if_link);
1113 static int qed_drain(struct qed_dev *cdev)
1115 struct qed_hwfn *hwfn;
1116 struct qed_ptt *ptt;
1119 for_each_hwfn(cdev, i) {
1120 hwfn = &cdev->hwfns[i];
1121 ptt = qed_ptt_acquire(hwfn);
1123 DP_NOTICE(hwfn, "Failed to drain NIG; No PTT\n");
1126 rc = qed_mcp_drain(hwfn, ptt);
1127 qed_ptt_release(hwfn, ptt);
1135 const struct qed_common_ops qed_common_ops_pass = {
1136 .probe = &qed_probe,
1137 .remove = &qed_remove,
1138 .set_power_state = &qed_set_power_state,
1139 .set_id = &qed_set_id,
1140 .update_pf_params = &qed_update_pf_params,
1141 .slowpath_start = &qed_slowpath_start,
1142 .slowpath_stop = &qed_slowpath_stop,
1143 .set_fp_int = &qed_set_int_fp,
1144 .get_fp_int = &qed_get_int_fp,
1145 .sb_init = &qed_sb_init,
1146 .sb_release = &qed_sb_release,
1147 .simd_handler_config = &qed_simd_handler_config,
1148 .simd_handler_clean = &qed_simd_handler_clean,
1149 .set_link = &qed_set_link,
1150 .get_link = &qed_get_current_link,
1151 .drain = &qed_drain,
1152 .update_msglvl = &qed_init_dp,
1153 .chain_alloc = &qed_chain_alloc,
1154 .chain_free = &qed_chain_free,
1157 u32 qed_get_protocol_version(enum qed_protocol protocol)
1160 case QED_PROTOCOL_ETH:
1161 return QED_ETH_INTERFACE_VERSION;
1166 EXPORT_SYMBOL(qed_get_protocol_version);