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>
28 #include "qed_dev_api.h"
32 static const char version[] =
33 "QLogic QL4xxx 40G/100G Ethernet Driver qed " DRV_MODULE_VERSION "\n";
35 MODULE_DESCRIPTION("QLogic 25G/40G/50G/100G Core Module");
36 MODULE_LICENSE("GPL");
37 MODULE_VERSION(DRV_MODULE_VERSION);
39 #define FW_FILE_VERSION \
40 __stringify(FW_MAJOR_VERSION) "." \
41 __stringify(FW_MINOR_VERSION) "." \
42 __stringify(FW_REVISION_VERSION) "." \
43 __stringify(FW_ENGINEERING_VERSION)
45 #define QED_FW_FILE_NAME \
46 "qed/qed_init_values_zipped-" FW_FILE_VERSION ".bin"
48 static int __init qed_init(void)
50 pr_notice("qed_init called\n");
52 pr_info("%s", version);
57 static void __exit qed_cleanup(void)
59 pr_notice("qed_cleanup called\n");
62 module_init(qed_init);
63 module_exit(qed_cleanup);
65 /* Check if the DMA controller on the machine can properly handle the DMA
66 * addressing required by the device.
68 static int qed_set_coherency_mask(struct qed_dev *cdev)
70 struct device *dev = &cdev->pdev->dev;
72 if (dma_set_mask(dev, DMA_BIT_MASK(64)) == 0) {
73 if (dma_set_coherent_mask(dev, DMA_BIT_MASK(64)) != 0) {
75 "Can't request 64-bit consistent allocations\n");
78 } else if (dma_set_mask(dev, DMA_BIT_MASK(32)) != 0) {
79 DP_NOTICE(cdev, "Can't request 64b/32b DMA addresses\n");
86 static void qed_free_pci(struct qed_dev *cdev)
88 struct pci_dev *pdev = cdev->pdev;
91 iounmap(cdev->doorbells);
93 iounmap(cdev->regview);
94 if (atomic_read(&pdev->enable_cnt) == 1)
95 pci_release_regions(pdev);
97 pci_disable_device(pdev);
100 /* Performs PCI initializations as well as initializing PCI-related parameters
101 * in the device structrue. Returns 0 in case of success.
103 static int qed_init_pci(struct qed_dev *cdev,
104 struct pci_dev *pdev)
110 rc = pci_enable_device(pdev);
112 DP_NOTICE(cdev, "Cannot enable PCI device\n");
116 if (!(pci_resource_flags(pdev, 0) & IORESOURCE_MEM)) {
117 DP_NOTICE(cdev, "No memory region found in bar #0\n");
122 if (!(pci_resource_flags(pdev, 2) & IORESOURCE_MEM)) {
123 DP_NOTICE(cdev, "No memory region found in bar #2\n");
128 if (atomic_read(&pdev->enable_cnt) == 1) {
129 rc = pci_request_regions(pdev, "qed");
132 "Failed to request PCI memory resources\n");
135 pci_set_master(pdev);
136 pci_save_state(pdev);
139 if (!pci_is_pcie(pdev)) {
140 DP_NOTICE(cdev, "The bus is not PCI Express\n");
145 cdev->pci_params.pm_cap = pci_find_capability(pdev, PCI_CAP_ID_PM);
146 if (cdev->pci_params.pm_cap == 0)
147 DP_NOTICE(cdev, "Cannot find power management capability\n");
149 rc = qed_set_coherency_mask(cdev);
153 cdev->pci_params.mem_start = pci_resource_start(pdev, 0);
154 cdev->pci_params.mem_end = pci_resource_end(pdev, 0);
155 cdev->pci_params.irq = pdev->irq;
157 cdev->regview = pci_ioremap_bar(pdev, 0);
158 if (!cdev->regview) {
159 DP_NOTICE(cdev, "Cannot map register space, aborting\n");
164 cdev->db_phys_addr = pci_resource_start(cdev->pdev, 2);
165 cdev->db_size = pci_resource_len(cdev->pdev, 2);
166 cdev->doorbells = ioremap_wc(cdev->db_phys_addr, cdev->db_size);
167 if (!cdev->doorbells) {
168 DP_NOTICE(cdev, "Cannot map doorbell space\n");
175 pci_release_regions(pdev);
177 pci_disable_device(pdev);
182 int qed_fill_dev_info(struct qed_dev *cdev,
183 struct qed_dev_info *dev_info)
187 memset(dev_info, 0, sizeof(struct qed_dev_info));
189 dev_info->num_hwfns = cdev->num_hwfns;
190 dev_info->pci_mem_start = cdev->pci_params.mem_start;
191 dev_info->pci_mem_end = cdev->pci_params.mem_end;
192 dev_info->pci_irq = cdev->pci_params.irq;
193 dev_info->is_mf = IS_MF(&cdev->hwfns[0]);
194 ether_addr_copy(dev_info->hw_mac, cdev->hwfns[0].hw_info.hw_mac_addr);
196 dev_info->fw_major = FW_MAJOR_VERSION;
197 dev_info->fw_minor = FW_MINOR_VERSION;
198 dev_info->fw_rev = FW_REVISION_VERSION;
199 dev_info->fw_eng = FW_ENGINEERING_VERSION;
200 dev_info->mf_mode = cdev->mf_mode;
202 qed_mcp_get_mfw_ver(cdev, &dev_info->mfw_rev);
204 ptt = qed_ptt_acquire(QED_LEADING_HWFN(cdev));
206 qed_mcp_get_flash_size(QED_LEADING_HWFN(cdev), ptt,
207 &dev_info->flash_size);
209 qed_ptt_release(QED_LEADING_HWFN(cdev), ptt);
215 static void qed_free_cdev(struct qed_dev *cdev)
220 static struct qed_dev *qed_alloc_cdev(struct pci_dev *pdev)
222 struct qed_dev *cdev;
224 cdev = kzalloc(sizeof(*cdev), GFP_KERNEL);
228 qed_init_struct(cdev);
233 /* Sets the requested power state */
234 static int qed_set_power_state(struct qed_dev *cdev,
240 DP_VERBOSE(cdev, NETIF_MSG_DRV, "Omitting Power state change\n");
245 static struct qed_dev *qed_probe(struct pci_dev *pdev,
246 enum qed_protocol protocol,
250 struct qed_dev *cdev;
253 cdev = qed_alloc_cdev(pdev);
257 cdev->protocol = protocol;
259 qed_init_dp(cdev, dp_module, dp_level);
261 rc = qed_init_pci(cdev, pdev);
263 DP_ERR(cdev, "init pci failed\n");
266 DP_INFO(cdev, "PCI init completed successfully\n");
268 rc = qed_hw_prepare(cdev, QED_PCI_DEFAULT);
270 DP_ERR(cdev, "hw prepare failed\n");
274 DP_INFO(cdev, "qed_probe completed successffuly\n");
286 static void qed_remove(struct qed_dev *cdev)
295 qed_set_power_state(cdev, PCI_D3hot);
300 static void qed_disable_msix(struct qed_dev *cdev)
302 if (cdev->int_params.out.int_mode == QED_INT_MODE_MSIX) {
303 pci_disable_msix(cdev->pdev);
304 kfree(cdev->int_params.msix_table);
305 } else if (cdev->int_params.out.int_mode == QED_INT_MODE_MSI) {
306 pci_disable_msi(cdev->pdev);
309 memset(&cdev->int_params.out, 0, sizeof(struct qed_int_param));
312 static int qed_enable_msix(struct qed_dev *cdev,
313 struct qed_int_params *int_params)
317 cnt = int_params->in.num_vectors;
319 for (i = 0; i < cnt; i++)
320 int_params->msix_table[i].entry = i;
322 rc = pci_enable_msix_range(cdev->pdev, int_params->msix_table,
323 int_params->in.min_msix_cnt, cnt);
324 if (rc < cnt && rc >= int_params->in.min_msix_cnt &&
325 (rc % cdev->num_hwfns)) {
326 pci_disable_msix(cdev->pdev);
328 /* If fastpath is initialized, we need at least one interrupt
329 * per hwfn [and the slow path interrupts]. New requested number
330 * should be a multiple of the number of hwfns.
332 cnt = (rc / cdev->num_hwfns) * cdev->num_hwfns;
334 "Trying to enable MSI-X with less vectors (%d out of %d)\n",
335 cnt, int_params->in.num_vectors);
336 rc = pci_enable_msix_exact(cdev->pdev,
337 int_params->msix_table, cnt);
343 /* MSI-x configuration was achieved */
344 int_params->out.int_mode = QED_INT_MODE_MSIX;
345 int_params->out.num_vectors = rc;
349 "Failed to enable MSI-X [Requested %d vectors][rc %d]\n",
356 /* This function outputs the int mode and the number of enabled msix vector */
357 static int qed_set_int_mode(struct qed_dev *cdev, bool force_mode)
359 struct qed_int_params *int_params = &cdev->int_params;
360 struct msix_entry *tbl;
363 switch (int_params->in.int_mode) {
364 case QED_INT_MODE_MSIX:
365 /* Allocate MSIX table */
366 cnt = int_params->in.num_vectors;
367 int_params->msix_table = kcalloc(cnt, sizeof(*tbl), GFP_KERNEL);
368 if (!int_params->msix_table) {
374 rc = qed_enable_msix(cdev, int_params);
378 DP_NOTICE(cdev, "Failed to enable MSI-X\n");
379 kfree(int_params->msix_table);
384 case QED_INT_MODE_MSI:
385 rc = pci_enable_msi(cdev->pdev);
387 int_params->out.int_mode = QED_INT_MODE_MSI;
391 DP_NOTICE(cdev, "Failed to enable MSI\n");
396 case QED_INT_MODE_INTA:
397 int_params->out.int_mode = QED_INT_MODE_INTA;
401 DP_NOTICE(cdev, "Unknown int_mode value %d\n",
402 int_params->in.int_mode);
407 cdev->int_coalescing_mode = QED_COAL_MODE_ENABLE;
412 static void qed_simd_handler_config(struct qed_dev *cdev, void *token,
413 int index, void(*handler)(void *))
415 struct qed_hwfn *hwfn = &cdev->hwfns[index % cdev->num_hwfns];
416 int relative_idx = index / cdev->num_hwfns;
418 hwfn->simd_proto_handler[relative_idx].func = handler;
419 hwfn->simd_proto_handler[relative_idx].token = token;
422 static void qed_simd_handler_clean(struct qed_dev *cdev, int index)
424 struct qed_hwfn *hwfn = &cdev->hwfns[index % cdev->num_hwfns];
425 int relative_idx = index / cdev->num_hwfns;
427 memset(&hwfn->simd_proto_handler[relative_idx], 0,
428 sizeof(struct qed_simd_fp_handler));
431 static irqreturn_t qed_msix_sp_int(int irq, void *tasklet)
433 tasklet_schedule((struct tasklet_struct *)tasklet);
437 static irqreturn_t qed_single_int(int irq, void *dev_instance)
439 struct qed_dev *cdev = (struct qed_dev *)dev_instance;
440 struct qed_hwfn *hwfn;
441 irqreturn_t rc = IRQ_NONE;
445 for (i = 0; i < cdev->num_hwfns; i++) {
446 status = qed_int_igu_read_sisr_reg(&cdev->hwfns[i]);
451 hwfn = &cdev->hwfns[i];
453 /* Slowpath interrupt */
454 if (unlikely(status & 0x1)) {
455 tasklet_schedule(hwfn->sp_dpc);
460 /* Fastpath interrupts */
461 for (j = 0; j < 64; j++) {
462 if ((0x2ULL << j) & status) {
463 hwfn->simd_proto_handler[j].func(
464 hwfn->simd_proto_handler[j].token);
465 status &= ~(0x2ULL << j);
470 if (unlikely(status))
471 DP_VERBOSE(hwfn, NETIF_MSG_INTR,
472 "got an unknown interrupt status 0x%llx\n",
479 static int qed_slowpath_irq_req(struct qed_dev *cdev)
483 if (cdev->int_params.out.int_mode == QED_INT_MODE_MSIX) {
484 /* Request all the slowpath MSI-X vectors */
485 for (i = 0; i < cdev->num_hwfns; i++) {
486 snprintf(cdev->hwfns[i].name, NAME_SIZE,
487 "sp-%d-%02x:%02x.%02x",
488 i, cdev->pdev->bus->number,
489 PCI_SLOT(cdev->pdev->devfn),
490 cdev->hwfns[i].abs_pf_id);
492 rc = request_irq(cdev->int_params.msix_table[i].vector,
495 cdev->hwfns[i].sp_dpc);
499 DP_VERBOSE(&cdev->hwfns[i],
500 (NETIF_MSG_INTR | QED_MSG_SP),
501 "Requested slowpath MSI-X\n");
504 if (i != cdev->num_hwfns) {
505 /* Free already request MSI-X vectors */
506 for (i--; i >= 0; i--) {
508 cdev->int_params.msix_table[i].vector;
509 synchronize_irq(vec);
510 free_irq(cdev->int_params.msix_table[i].vector,
511 cdev->hwfns[i].sp_dpc);
515 unsigned long flags = 0;
517 snprintf(cdev->name, NAME_SIZE, "%02x:%02x.%02x",
518 cdev->pdev->bus->number, PCI_SLOT(cdev->pdev->devfn),
519 PCI_FUNC(cdev->pdev->devfn));
521 if (cdev->int_params.out.int_mode == QED_INT_MODE_INTA)
522 flags |= IRQF_SHARED;
524 rc = request_irq(cdev->pdev->irq, qed_single_int,
525 flags, cdev->name, cdev);
531 static void qed_slowpath_irq_free(struct qed_dev *cdev)
535 if (cdev->int_params.out.int_mode == QED_INT_MODE_MSIX) {
536 for_each_hwfn(cdev, i) {
537 synchronize_irq(cdev->int_params.msix_table[i].vector);
538 free_irq(cdev->int_params.msix_table[i].vector,
539 cdev->hwfns[i].sp_dpc);
542 free_irq(cdev->pdev->irq, cdev);
546 static int qed_nic_stop(struct qed_dev *cdev)
550 rc = qed_hw_stop(cdev);
552 for (i = 0; i < cdev->num_hwfns; i++) {
553 struct qed_hwfn *p_hwfn = &cdev->hwfns[i];
555 if (p_hwfn->b_sp_dpc_enabled) {
556 tasklet_disable(p_hwfn->sp_dpc);
557 p_hwfn->b_sp_dpc_enabled = false;
558 DP_VERBOSE(cdev, NETIF_MSG_IFDOWN,
559 "Disabled sp taskelt [hwfn %d] at %p\n",
567 static int qed_nic_reset(struct qed_dev *cdev)
571 rc = qed_hw_reset(cdev);
580 static int qed_nic_setup(struct qed_dev *cdev)
584 rc = qed_resc_alloc(cdev);
588 DP_INFO(cdev, "Allocated qed resources\n");
590 qed_resc_setup(cdev);
595 static int qed_set_int_fp(struct qed_dev *cdev, u16 cnt)
599 /* Mark the fastpath as free/used */
600 cdev->int_params.fp_initialized = cnt ? true : false;
602 if (cdev->int_params.out.int_mode != QED_INT_MODE_MSIX)
603 limit = cdev->num_hwfns * 63;
604 else if (cdev->int_params.fp_msix_cnt)
605 limit = cdev->int_params.fp_msix_cnt;
610 return min_t(int, cnt, limit);
613 static int qed_get_int_fp(struct qed_dev *cdev, struct qed_int_info *info)
615 memset(info, 0, sizeof(struct qed_int_info));
617 if (!cdev->int_params.fp_initialized) {
619 "Protocol driver requested interrupt information, but its support is not yet configured\n");
623 /* Need to expose only MSI-X information; Single IRQ is handled solely
626 if (cdev->int_params.out.int_mode == QED_INT_MODE_MSIX) {
627 int msix_base = cdev->int_params.fp_msix_base;
629 info->msix_cnt = cdev->int_params.fp_msix_cnt;
630 info->msix = &cdev->int_params.msix_table[msix_base];
636 static int qed_slowpath_setup_int(struct qed_dev *cdev,
637 enum qed_int_mode int_mode)
642 memset(&cdev->int_params, 0, sizeof(struct qed_int_params));
644 cdev->int_params.in.int_mode = int_mode;
645 for_each_hwfn(cdev, i)
646 num_vectors += qed_int_get_num_sbs(&cdev->hwfns[i], NULL) + 1;
647 cdev->int_params.in.num_vectors = num_vectors;
649 /* We want a minimum of one slowpath and one fastpath vector per hwfn */
650 cdev->int_params.in.min_msix_cnt = cdev->num_hwfns * 2;
652 rc = qed_set_int_mode(cdev, false);
654 DP_ERR(cdev, "qed_slowpath_setup_int ERR\n");
658 cdev->int_params.fp_msix_base = cdev->num_hwfns;
659 cdev->int_params.fp_msix_cnt = cdev->int_params.out.num_vectors -
665 u32 qed_unzip_data(struct qed_hwfn *p_hwfn, u32 input_len,
666 u8 *input_buf, u32 max_size, u8 *unzip_buf)
670 p_hwfn->stream->next_in = input_buf;
671 p_hwfn->stream->avail_in = input_len;
672 p_hwfn->stream->next_out = unzip_buf;
673 p_hwfn->stream->avail_out = max_size;
675 rc = zlib_inflateInit2(p_hwfn->stream, MAX_WBITS);
678 DP_VERBOSE(p_hwfn, NETIF_MSG_DRV, "zlib init failed, rc = %d\n",
683 rc = zlib_inflate(p_hwfn->stream, Z_FINISH);
684 zlib_inflateEnd(p_hwfn->stream);
686 if (rc != Z_OK && rc != Z_STREAM_END) {
687 DP_VERBOSE(p_hwfn, NETIF_MSG_DRV, "FW unzip error: %s, rc=%d\n",
688 p_hwfn->stream->msg, rc);
692 return p_hwfn->stream->total_out / 4;
695 static int qed_alloc_stream_mem(struct qed_dev *cdev)
700 for_each_hwfn(cdev, i) {
701 struct qed_hwfn *p_hwfn = &cdev->hwfns[i];
703 p_hwfn->stream = kzalloc(sizeof(*p_hwfn->stream), GFP_KERNEL);
707 workspace = vzalloc(zlib_inflate_workspacesize());
710 p_hwfn->stream->workspace = workspace;
716 static void qed_free_stream_mem(struct qed_dev *cdev)
720 for_each_hwfn(cdev, i) {
721 struct qed_hwfn *p_hwfn = &cdev->hwfns[i];
726 vfree(p_hwfn->stream->workspace);
727 kfree(p_hwfn->stream);
731 static void qed_update_pf_params(struct qed_dev *cdev,
732 struct qed_pf_params *params)
736 for (i = 0; i < cdev->num_hwfns; i++) {
737 struct qed_hwfn *p_hwfn = &cdev->hwfns[i];
739 p_hwfn->pf_params = *params;
743 static int qed_slowpath_start(struct qed_dev *cdev,
744 struct qed_slowpath_params *params)
746 struct qed_mcp_drv_version drv_version;
747 const u8 *data = NULL;
748 struct qed_hwfn *hwfn;
751 rc = request_firmware(&cdev->firmware, QED_FW_FILE_NAME,
755 "Failed to find fw file - /lib/firmware/%s\n",
760 rc = qed_nic_setup(cdev);
764 rc = qed_slowpath_setup_int(cdev, params->int_mode);
768 /* Request the slowpath IRQ */
769 rc = qed_slowpath_irq_req(cdev);
773 /* Allocate stream for unzipping */
774 rc = qed_alloc_stream_mem(cdev);
776 DP_NOTICE(cdev, "Failed to allocate stream memory\n");
780 /* Start the slowpath */
781 data = cdev->firmware->data;
783 rc = qed_hw_init(cdev, true, cdev->int_params.out.int_mode,
789 "HW initialization and function start completed successfully\n");
791 hwfn = QED_LEADING_HWFN(cdev);
792 drv_version.version = (params->drv_major << 24) |
793 (params->drv_minor << 16) |
794 (params->drv_rev << 8) |
796 strlcpy(drv_version.name, params->name,
797 MCP_DRV_VER_STR_SIZE - 4);
798 rc = qed_mcp_send_drv_version(hwfn, hwfn->p_main_ptt,
801 DP_NOTICE(cdev, "Failed sending drv version command\n");
808 qed_free_stream_mem(cdev);
809 qed_slowpath_irq_free(cdev);
811 qed_disable_msix(cdev);
815 release_firmware(cdev->firmware);
820 static int qed_slowpath_stop(struct qed_dev *cdev)
825 qed_free_stream_mem(cdev);
828 qed_slowpath_irq_free(cdev);
830 qed_disable_msix(cdev);
833 release_firmware(cdev->firmware);
838 static void qed_set_id(struct qed_dev *cdev, char name[NAME_SIZE],
839 char ver_str[VER_SIZE])
843 memcpy(cdev->name, name, NAME_SIZE);
844 for_each_hwfn(cdev, i)
845 snprintf(cdev->hwfns[i].name, NAME_SIZE, "%s-%d", name, i);
847 memcpy(cdev->ver_str, ver_str, VER_SIZE);
848 cdev->drv_type = DRV_ID_DRV_TYPE_LINUX;
851 static u32 qed_sb_init(struct qed_dev *cdev,
852 struct qed_sb_info *sb_info,
854 dma_addr_t sb_phy_addr, u16 sb_id,
855 enum qed_sb_type type)
857 struct qed_hwfn *p_hwfn;
863 /* RoCE uses single engine and CMT uses two engines. When using both
864 * we force only a single engine. Storage uses only engine 0 too.
866 if (type == QED_SB_TYPE_L2_QUEUE)
867 n_hwfns = cdev->num_hwfns;
871 hwfn_index = sb_id % n_hwfns;
872 p_hwfn = &cdev->hwfns[hwfn_index];
873 rel_sb_id = sb_id / n_hwfns;
875 DP_VERBOSE(cdev, NETIF_MSG_INTR,
876 "hwfn [%d] <--[init]-- SB %04x [0x%04x upper]\n",
877 hwfn_index, rel_sb_id, sb_id);
879 rc = qed_int_sb_init(p_hwfn, p_hwfn->p_main_ptt, sb_info,
880 sb_virt_addr, sb_phy_addr, rel_sb_id);
885 static u32 qed_sb_release(struct qed_dev *cdev,
886 struct qed_sb_info *sb_info,
889 struct qed_hwfn *p_hwfn;
894 hwfn_index = sb_id % cdev->num_hwfns;
895 p_hwfn = &cdev->hwfns[hwfn_index];
896 rel_sb_id = sb_id / cdev->num_hwfns;
898 DP_VERBOSE(cdev, NETIF_MSG_INTR,
899 "hwfn [%d] <--[init]-- SB %04x [0x%04x upper]\n",
900 hwfn_index, rel_sb_id, sb_id);
902 rc = qed_int_sb_release(p_hwfn, sb_info, rel_sb_id);
907 static int qed_set_link(struct qed_dev *cdev,
908 struct qed_link_params *params)
910 struct qed_hwfn *hwfn;
911 struct qed_mcp_link_params *link_params;
918 /* The link should be set only once per PF */
919 hwfn = &cdev->hwfns[0];
921 ptt = qed_ptt_acquire(hwfn);
925 link_params = qed_mcp_get_link_params(hwfn);
926 if (params->override_flags & QED_LINK_OVERRIDE_SPEED_AUTONEG)
927 link_params->speed.autoneg = params->autoneg;
928 if (params->override_flags & QED_LINK_OVERRIDE_SPEED_ADV_SPEEDS) {
929 link_params->speed.advertised_speeds = 0;
930 if ((params->adv_speeds & SUPPORTED_1000baseT_Half) ||
931 (params->adv_speeds & SUPPORTED_1000baseT_Full))
932 link_params->speed.advertised_speeds |=
933 NVM_CFG1_PORT_DRV_SPEED_CAPABILITY_MASK_1G;
934 if (params->adv_speeds & SUPPORTED_10000baseKR_Full)
935 link_params->speed.advertised_speeds |=
936 NVM_CFG1_PORT_DRV_SPEED_CAPABILITY_MASK_10G;
937 if (params->adv_speeds & SUPPORTED_40000baseLR4_Full)
938 link_params->speed.advertised_speeds |=
939 NVM_CFG1_PORT_DRV_SPEED_CAPABILITY_MASK_40G;
940 if (params->adv_speeds & 0)
941 link_params->speed.advertised_speeds |=
942 NVM_CFG1_PORT_DRV_SPEED_CAPABILITY_MASK_50G;
943 if (params->adv_speeds & 0)
944 link_params->speed.advertised_speeds |=
945 NVM_CFG1_PORT_DRV_SPEED_CAPABILITY_MASK_100G;
947 if (params->override_flags & QED_LINK_OVERRIDE_SPEED_FORCED_SPEED)
948 link_params->speed.forced_speed = params->forced_speed;
950 rc = qed_mcp_set_link(hwfn, ptt, params->link_up);
952 qed_ptt_release(hwfn, ptt);
957 static int qed_get_port_type(u32 media_type)
961 switch (media_type) {
962 case MEDIA_SFPP_10G_FIBER:
963 case MEDIA_SFP_1G_FIBER:
964 case MEDIA_XFP_FIBER:
966 port_type = PORT_FIBRE;
968 case MEDIA_DA_TWINAX:
974 case MEDIA_NOT_PRESENT:
975 port_type = PORT_NONE;
977 case MEDIA_UNSPECIFIED:
979 port_type = PORT_OTHER;
985 static void qed_fill_link(struct qed_hwfn *hwfn,
986 struct qed_link_output *if_link)
988 struct qed_mcp_link_params params;
989 struct qed_mcp_link_state link;
990 struct qed_mcp_link_capabilities link_caps;
993 memset(if_link, 0, sizeof(*if_link));
995 /* Prepare source inputs */
996 memcpy(¶ms, qed_mcp_get_link_params(hwfn), sizeof(params));
997 memcpy(&link, qed_mcp_get_link_state(hwfn), sizeof(link));
998 memcpy(&link_caps, qed_mcp_get_link_capabilities(hwfn),
1001 /* Set the link parameters to pass to protocol driver */
1003 if_link->link_up = true;
1005 /* TODO - at the moment assume supported and advertised speed equal */
1006 if_link->supported_caps = SUPPORTED_FIBRE;
1007 if (params.speed.autoneg)
1008 if_link->supported_caps |= SUPPORTED_Autoneg;
1009 if (params.pause.autoneg ||
1010 (params.pause.forced_rx && params.pause.forced_tx))
1011 if_link->supported_caps |= SUPPORTED_Asym_Pause;
1012 if (params.pause.autoneg || params.pause.forced_rx ||
1013 params.pause.forced_tx)
1014 if_link->supported_caps |= SUPPORTED_Pause;
1016 if_link->advertised_caps = if_link->supported_caps;
1017 if (params.speed.advertised_speeds &
1018 NVM_CFG1_PORT_DRV_SPEED_CAPABILITY_MASK_1G)
1019 if_link->advertised_caps |= SUPPORTED_1000baseT_Half |
1020 SUPPORTED_1000baseT_Full;
1021 if (params.speed.advertised_speeds &
1022 NVM_CFG1_PORT_DRV_SPEED_CAPABILITY_MASK_10G)
1023 if_link->advertised_caps |= SUPPORTED_10000baseKR_Full;
1024 if (params.speed.advertised_speeds &
1025 NVM_CFG1_PORT_DRV_SPEED_CAPABILITY_MASK_40G)
1026 if_link->advertised_caps |= SUPPORTED_40000baseLR4_Full;
1027 if (params.speed.advertised_speeds &
1028 NVM_CFG1_PORT_DRV_SPEED_CAPABILITY_MASK_50G)
1029 if_link->advertised_caps |= 0;
1030 if (params.speed.advertised_speeds &
1031 NVM_CFG1_PORT_DRV_SPEED_CAPABILITY_MASK_100G)
1032 if_link->advertised_caps |= 0;
1034 if (link_caps.speed_capabilities &
1035 NVM_CFG1_PORT_DRV_SPEED_CAPABILITY_MASK_1G)
1036 if_link->supported_caps |= SUPPORTED_1000baseT_Half |
1037 SUPPORTED_1000baseT_Full;
1038 if (link_caps.speed_capabilities &
1039 NVM_CFG1_PORT_DRV_SPEED_CAPABILITY_MASK_10G)
1040 if_link->supported_caps |= SUPPORTED_10000baseKR_Full;
1041 if (link_caps.speed_capabilities &
1042 NVM_CFG1_PORT_DRV_SPEED_CAPABILITY_MASK_40G)
1043 if_link->supported_caps |= SUPPORTED_40000baseLR4_Full;
1044 if (link_caps.speed_capabilities &
1045 NVM_CFG1_PORT_DRV_SPEED_CAPABILITY_MASK_50G)
1046 if_link->supported_caps |= 0;
1047 if (link_caps.speed_capabilities &
1048 NVM_CFG1_PORT_DRV_SPEED_CAPABILITY_MASK_100G)
1049 if_link->supported_caps |= 0;
1052 if_link->speed = link.speed;
1054 /* TODO - fill duplex properly */
1055 if_link->duplex = DUPLEX_FULL;
1056 qed_mcp_get_media_type(hwfn->cdev, &media_type);
1057 if_link->port = qed_get_port_type(media_type);
1059 if_link->autoneg = params.speed.autoneg;
1061 if (params.pause.autoneg)
1062 if_link->pause_config |= QED_LINK_PAUSE_AUTONEG_ENABLE;
1063 if (params.pause.forced_rx)
1064 if_link->pause_config |= QED_LINK_PAUSE_RX_ENABLE;
1065 if (params.pause.forced_tx)
1066 if_link->pause_config |= QED_LINK_PAUSE_TX_ENABLE;
1068 /* Link partner capabilities */
1069 if (link.partner_adv_speed &
1070 QED_LINK_PARTNER_SPEED_1G_HD)
1071 if_link->lp_caps |= SUPPORTED_1000baseT_Half;
1072 if (link.partner_adv_speed &
1073 QED_LINK_PARTNER_SPEED_1G_FD)
1074 if_link->lp_caps |= SUPPORTED_1000baseT_Full;
1075 if (link.partner_adv_speed &
1076 QED_LINK_PARTNER_SPEED_10G)
1077 if_link->lp_caps |= SUPPORTED_10000baseKR_Full;
1078 if (link.partner_adv_speed &
1079 QED_LINK_PARTNER_SPEED_40G)
1080 if_link->lp_caps |= SUPPORTED_40000baseLR4_Full;
1081 if (link.partner_adv_speed &
1082 QED_LINK_PARTNER_SPEED_50G)
1083 if_link->lp_caps |= 0;
1084 if (link.partner_adv_speed &
1085 QED_LINK_PARTNER_SPEED_100G)
1086 if_link->lp_caps |= 0;
1088 if (link.an_complete)
1089 if_link->lp_caps |= SUPPORTED_Autoneg;
1091 if (link.partner_adv_pause)
1092 if_link->lp_caps |= SUPPORTED_Pause;
1093 if (link.partner_adv_pause == QED_LINK_PARTNER_ASYMMETRIC_PAUSE ||
1094 link.partner_adv_pause == QED_LINK_PARTNER_BOTH_PAUSE)
1095 if_link->lp_caps |= SUPPORTED_Asym_Pause;
1098 static void qed_get_current_link(struct qed_dev *cdev,
1099 struct qed_link_output *if_link)
1101 qed_fill_link(&cdev->hwfns[0], if_link);
1104 void qed_link_update(struct qed_hwfn *hwfn)
1106 void *cookie = hwfn->cdev->ops_cookie;
1107 struct qed_common_cb_ops *op = hwfn->cdev->protocol_ops.common;
1108 struct qed_link_output if_link;
1110 qed_fill_link(hwfn, &if_link);
1112 if (IS_LEAD_HWFN(hwfn) && cookie)
1113 op->link_update(cookie, &if_link);
1116 static int qed_drain(struct qed_dev *cdev)
1118 struct qed_hwfn *hwfn;
1119 struct qed_ptt *ptt;
1122 for_each_hwfn(cdev, i) {
1123 hwfn = &cdev->hwfns[i];
1124 ptt = qed_ptt_acquire(hwfn);
1126 DP_NOTICE(hwfn, "Failed to drain NIG; No PTT\n");
1129 rc = qed_mcp_drain(hwfn, ptt);
1132 qed_ptt_release(hwfn, ptt);
1138 const struct qed_common_ops qed_common_ops_pass = {
1139 .probe = &qed_probe,
1140 .remove = &qed_remove,
1141 .set_power_state = &qed_set_power_state,
1142 .set_id = &qed_set_id,
1143 .update_pf_params = &qed_update_pf_params,
1144 .slowpath_start = &qed_slowpath_start,
1145 .slowpath_stop = &qed_slowpath_stop,
1146 .set_fp_int = &qed_set_int_fp,
1147 .get_fp_int = &qed_get_int_fp,
1148 .sb_init = &qed_sb_init,
1149 .sb_release = &qed_sb_release,
1150 .simd_handler_config = &qed_simd_handler_config,
1151 .simd_handler_clean = &qed_simd_handler_clean,
1152 .set_link = &qed_set_link,
1153 .get_link = &qed_get_current_link,
1154 .drain = &qed_drain,
1155 .update_msglvl = &qed_init_dp,
1156 .chain_alloc = &qed_chain_alloc,
1157 .chain_free = &qed_chain_free,
1160 u32 qed_get_protocol_version(enum qed_protocol protocol)
1163 case QED_PROTOCOL_ETH:
1164 return QED_ETH_INTERFACE_VERSION;
1169 EXPORT_SYMBOL(qed_get_protocol_version);