2 * Copyright (c) 2013-2015, Mellanox Technologies. All rights reserved.
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/highmem.h>
34 #include <linux/module.h>
35 #include <linux/init.h>
36 #include <linux/errno.h>
37 #include <linux/pci.h>
38 #include <linux/dma-mapping.h>
39 #include <linux/slab.h>
40 #include <linux/io-mapping.h>
41 #include <linux/interrupt.h>
42 #include <linux/delay.h>
43 #include <linux/mlx5/driver.h>
44 #include <linux/mlx5/cq.h>
45 #include <linux/mlx5/qp.h>
46 #include <linux/debugfs.h>
47 #include <linux/kmod.h>
48 #include <linux/mlx5/mlx5_ifc.h>
49 #include <linux/mlx5/vport.h>
50 #ifdef CONFIG_RFS_ACCEL
51 #include <linux/cpu_rmap.h>
53 #include <net/devlink.h>
54 #include "mlx5_core.h"
61 #include "fpga/core.h"
62 #include "fpga/ipsec.h"
63 #include "accel/ipsec.h"
64 #include "accel/tls.h"
65 #include "lib/clock.h"
66 #include "lib/vxlan.h"
67 #include "lib/geneve.h"
68 #include "lib/devcom.h"
69 #include "lib/pci_vsc.h"
70 #include "diag/fw_tracer.h"
72 #include "lib/hv_vhca.h"
73 #include "diag/rsc_dump.h"
75 MODULE_AUTHOR("Eli Cohen <eli@mellanox.com>");
76 MODULE_DESCRIPTION("Mellanox 5th generation network adapters (ConnectX series) core driver");
77 MODULE_LICENSE("Dual BSD/GPL");
78 MODULE_VERSION(DRIVER_VERSION);
80 unsigned int mlx5_core_debug_mask;
81 module_param_named(debug_mask, mlx5_core_debug_mask, uint, 0644);
82 MODULE_PARM_DESC(debug_mask, "debug mask: 1 = dump cmd data, 2 = dump cmd exec time, 3 = both. Default=0");
84 #define MLX5_DEFAULT_PROF 2
85 static unsigned int prof_sel = MLX5_DEFAULT_PROF;
86 module_param_named(prof_sel, prof_sel, uint, 0444);
87 MODULE_PARM_DESC(prof_sel, "profile selector. Valid range 0 - 2");
89 static u32 sw_owner_id[4];
92 MLX5_ATOMIC_REQ_MODE_BE = 0x0,
93 MLX5_ATOMIC_REQ_MODE_HOST_ENDIANNESS = 0x1,
96 static struct mlx5_profile profile[] = {
101 .mask = MLX5_PROF_MASK_QP_SIZE,
105 .mask = MLX5_PROF_MASK_QP_SIZE |
106 MLX5_PROF_MASK_MR_CACHE,
175 #define FW_INIT_TIMEOUT_MILI 2000
176 #define FW_INIT_WAIT_MS 2
177 #define FW_PRE_INIT_TIMEOUT_MILI 120000
178 #define FW_INIT_WARN_MESSAGE_INTERVAL 20000
180 static int fw_initializing(struct mlx5_core_dev *dev)
182 return ioread32be(&dev->iseg->initializing) >> 31;
185 static int wait_fw_init(struct mlx5_core_dev *dev, u32 max_wait_mili,
188 unsigned long warn = jiffies + msecs_to_jiffies(warn_time_mili);
189 unsigned long end = jiffies + msecs_to_jiffies(max_wait_mili);
192 BUILD_BUG_ON(FW_PRE_INIT_TIMEOUT_MILI < FW_INIT_WARN_MESSAGE_INTERVAL);
194 while (fw_initializing(dev)) {
195 if (time_after(jiffies, end)) {
199 if (warn_time_mili && time_after(jiffies, warn)) {
200 mlx5_core_warn(dev, "Waiting for FW initialization, timeout abort in %ds\n",
201 jiffies_to_msecs(end - warn) / 1000);
202 warn = jiffies + msecs_to_jiffies(warn_time_mili);
204 msleep(FW_INIT_WAIT_MS);
210 static void mlx5_set_driver_version(struct mlx5_core_dev *dev)
212 int driver_ver_sz = MLX5_FLD_SZ_BYTES(set_driver_version_in,
214 u8 in[MLX5_ST_SZ_BYTES(set_driver_version_in)] = {};
215 int remaining_size = driver_ver_sz;
218 if (!MLX5_CAP_GEN(dev, driver_version))
221 string = MLX5_ADDR_OF(set_driver_version_in, in, driver_version);
223 strncpy(string, "Linux", remaining_size);
225 remaining_size = max_t(int, 0, driver_ver_sz - strlen(string));
226 strncat(string, ",", remaining_size);
228 remaining_size = max_t(int, 0, driver_ver_sz - strlen(string));
229 strncat(string, DRIVER_NAME, remaining_size);
231 remaining_size = max_t(int, 0, driver_ver_sz - strlen(string));
232 strncat(string, ",", remaining_size);
234 remaining_size = max_t(int, 0, driver_ver_sz - strlen(string));
235 strncat(string, DRIVER_VERSION, remaining_size);
238 MLX5_SET(set_driver_version_in, in, opcode,
239 MLX5_CMD_OP_SET_DRIVER_VERSION);
241 mlx5_cmd_exec_in(dev, set_driver_version, in);
244 static int set_dma_caps(struct pci_dev *pdev)
248 err = pci_set_dma_mask(pdev, DMA_BIT_MASK(64));
250 dev_warn(&pdev->dev, "Warning: couldn't set 64-bit PCI DMA mask\n");
251 err = pci_set_dma_mask(pdev, DMA_BIT_MASK(32));
253 dev_err(&pdev->dev, "Can't set PCI DMA mask, aborting\n");
258 err = pci_set_consistent_dma_mask(pdev, DMA_BIT_MASK(64));
261 "Warning: couldn't set 64-bit consistent PCI DMA mask\n");
262 err = pci_set_consistent_dma_mask(pdev, DMA_BIT_MASK(32));
265 "Can't set consistent PCI DMA mask, aborting\n");
270 dma_set_max_seg_size(&pdev->dev, 2u * 1024 * 1024 * 1024);
274 static int mlx5_pci_enable_device(struct mlx5_core_dev *dev)
276 struct pci_dev *pdev = dev->pdev;
279 mutex_lock(&dev->pci_status_mutex);
280 if (dev->pci_status == MLX5_PCI_STATUS_DISABLED) {
281 err = pci_enable_device(pdev);
283 dev->pci_status = MLX5_PCI_STATUS_ENABLED;
285 mutex_unlock(&dev->pci_status_mutex);
290 static void mlx5_pci_disable_device(struct mlx5_core_dev *dev)
292 struct pci_dev *pdev = dev->pdev;
294 mutex_lock(&dev->pci_status_mutex);
295 if (dev->pci_status == MLX5_PCI_STATUS_ENABLED) {
296 pci_disable_device(pdev);
297 dev->pci_status = MLX5_PCI_STATUS_DISABLED;
299 mutex_unlock(&dev->pci_status_mutex);
302 static int request_bar(struct pci_dev *pdev)
306 if (!(pci_resource_flags(pdev, 0) & IORESOURCE_MEM)) {
307 dev_err(&pdev->dev, "Missing registers BAR, aborting\n");
311 err = pci_request_regions(pdev, DRIVER_NAME);
313 dev_err(&pdev->dev, "Couldn't get PCI resources, aborting\n");
318 static void release_bar(struct pci_dev *pdev)
320 pci_release_regions(pdev);
323 struct mlx5_reg_host_endianness {
328 #define CAP_MASK(pos, size) ((u64)((1 << (size)) - 1) << (pos))
331 MLX5_CAP_BITS_RW_MASK = CAP_MASK(MLX5_CAP_OFF_CMDIF_CSUM, 2) |
332 MLX5_DEV_CAP_FLAG_DCT,
335 static u16 to_fw_pkey_sz(struct mlx5_core_dev *dev, u32 size)
351 mlx5_core_warn(dev, "invalid pkey table size %d\n", size);
356 static int mlx5_core_get_caps_mode(struct mlx5_core_dev *dev,
357 enum mlx5_cap_type cap_type,
358 enum mlx5_cap_mode cap_mode)
360 u8 in[MLX5_ST_SZ_BYTES(query_hca_cap_in)];
361 int out_sz = MLX5_ST_SZ_BYTES(query_hca_cap_out);
362 void *out, *hca_caps;
363 u16 opmod = (cap_type << 1) | (cap_mode & 0x01);
366 memset(in, 0, sizeof(in));
367 out = kzalloc(out_sz, GFP_KERNEL);
371 MLX5_SET(query_hca_cap_in, in, opcode, MLX5_CMD_OP_QUERY_HCA_CAP);
372 MLX5_SET(query_hca_cap_in, in, op_mod, opmod);
373 err = mlx5_cmd_exec_inout(dev, query_hca_cap, in, out);
376 "QUERY_HCA_CAP : type(%x) opmode(%x) Failed(%d)\n",
377 cap_type, cap_mode, err);
381 hca_caps = MLX5_ADDR_OF(query_hca_cap_out, out, capability);
384 case HCA_CAP_OPMOD_GET_MAX:
385 memcpy(dev->caps.hca_max[cap_type], hca_caps,
386 MLX5_UN_SZ_BYTES(hca_cap_union));
388 case HCA_CAP_OPMOD_GET_CUR:
389 memcpy(dev->caps.hca_cur[cap_type], hca_caps,
390 MLX5_UN_SZ_BYTES(hca_cap_union));
394 "Tried to query dev cap type(%x) with wrong opmode(%x)\n",
404 int mlx5_core_get_caps(struct mlx5_core_dev *dev, enum mlx5_cap_type cap_type)
408 ret = mlx5_core_get_caps_mode(dev, cap_type, HCA_CAP_OPMOD_GET_CUR);
411 return mlx5_core_get_caps_mode(dev, cap_type, HCA_CAP_OPMOD_GET_MAX);
414 static int set_caps(struct mlx5_core_dev *dev, void *in, int opmod)
416 MLX5_SET(set_hca_cap_in, in, opcode, MLX5_CMD_OP_SET_HCA_CAP);
417 MLX5_SET(set_hca_cap_in, in, op_mod, opmod << 1);
418 return mlx5_cmd_exec_in(dev, set_hca_cap, in);
421 static int handle_hca_cap_atomic(struct mlx5_core_dev *dev, void *set_ctx)
427 if (!MLX5_CAP_GEN(dev, atomic))
430 err = mlx5_core_get_caps(dev, MLX5_CAP_ATOMIC);
436 supported_atomic_req_8B_endianness_mode_1);
438 if (req_endianness != MLX5_ATOMIC_REQ_MODE_HOST_ENDIANNESS)
441 set_hca_cap = MLX5_ADDR_OF(set_hca_cap_in, set_ctx, capability);
443 /* Set requestor to host endianness */
444 MLX5_SET(atomic_caps, set_hca_cap, atomic_req_8B_endianness_mode,
445 MLX5_ATOMIC_REQ_MODE_HOST_ENDIANNESS);
447 return set_caps(dev, set_ctx, MLX5_SET_HCA_CAP_OP_MOD_ATOMIC);
450 static int handle_hca_cap_odp(struct mlx5_core_dev *dev, void *set_ctx)
456 if (!IS_ENABLED(CONFIG_INFINIBAND_ON_DEMAND_PAGING) ||
457 !MLX5_CAP_GEN(dev, pg))
460 err = mlx5_core_get_caps(dev, MLX5_CAP_ODP);
464 set_hca_cap = MLX5_ADDR_OF(set_hca_cap_in, set_ctx, capability);
465 memcpy(set_hca_cap, dev->caps.hca_cur[MLX5_CAP_ODP],
466 MLX5_ST_SZ_BYTES(odp_cap));
468 #define ODP_CAP_SET_MAX(dev, field) \
470 u32 _res = MLX5_CAP_ODP_MAX(dev, field); \
473 MLX5_SET(odp_cap, set_hca_cap, field, _res); \
477 ODP_CAP_SET_MAX(dev, ud_odp_caps.srq_receive);
478 ODP_CAP_SET_MAX(dev, rc_odp_caps.srq_receive);
479 ODP_CAP_SET_MAX(dev, xrc_odp_caps.srq_receive);
480 ODP_CAP_SET_MAX(dev, xrc_odp_caps.send);
481 ODP_CAP_SET_MAX(dev, xrc_odp_caps.receive);
482 ODP_CAP_SET_MAX(dev, xrc_odp_caps.write);
483 ODP_CAP_SET_MAX(dev, xrc_odp_caps.read);
484 ODP_CAP_SET_MAX(dev, xrc_odp_caps.atomic);
485 ODP_CAP_SET_MAX(dev, dc_odp_caps.srq_receive);
486 ODP_CAP_SET_MAX(dev, dc_odp_caps.send);
487 ODP_CAP_SET_MAX(dev, dc_odp_caps.receive);
488 ODP_CAP_SET_MAX(dev, dc_odp_caps.write);
489 ODP_CAP_SET_MAX(dev, dc_odp_caps.read);
490 ODP_CAP_SET_MAX(dev, dc_odp_caps.atomic);
495 return set_caps(dev, set_ctx, MLX5_SET_HCA_CAP_OP_MOD_ODP);
498 static int handle_hca_cap(struct mlx5_core_dev *dev, void *set_ctx)
500 struct mlx5_profile *prof = dev->profile;
504 err = mlx5_core_get_caps(dev, MLX5_CAP_GENERAL);
508 set_hca_cap = MLX5_ADDR_OF(set_hca_cap_in, set_ctx,
510 memcpy(set_hca_cap, dev->caps.hca_cur[MLX5_CAP_GENERAL],
511 MLX5_ST_SZ_BYTES(cmd_hca_cap));
513 mlx5_core_dbg(dev, "Current Pkey table size %d Setting new size %d\n",
514 mlx5_to_sw_pkey_sz(MLX5_CAP_GEN(dev, pkey_table_size)),
516 /* we limit the size of the pkey table to 128 entries for now */
517 MLX5_SET(cmd_hca_cap, set_hca_cap, pkey_table_size,
518 to_fw_pkey_sz(dev, 128));
520 /* Check log_max_qp from HCA caps to set in current profile */
521 if (MLX5_CAP_GEN_MAX(dev, log_max_qp) < profile[prof_sel].log_max_qp) {
522 mlx5_core_warn(dev, "log_max_qp value in current profile is %d, changing it to HCA capability limit (%d)\n",
523 profile[prof_sel].log_max_qp,
524 MLX5_CAP_GEN_MAX(dev, log_max_qp));
525 profile[prof_sel].log_max_qp = MLX5_CAP_GEN_MAX(dev, log_max_qp);
527 if (prof->mask & MLX5_PROF_MASK_QP_SIZE)
528 MLX5_SET(cmd_hca_cap, set_hca_cap, log_max_qp,
531 /* disable cmdif checksum */
532 MLX5_SET(cmd_hca_cap, set_hca_cap, cmdif_checksum, 0);
534 /* Enable 4K UAR only when HCA supports it and page size is bigger
537 if (MLX5_CAP_GEN_MAX(dev, uar_4k) && PAGE_SIZE > 4096)
538 MLX5_SET(cmd_hca_cap, set_hca_cap, uar_4k, 1);
540 MLX5_SET(cmd_hca_cap, set_hca_cap, log_uar_page_sz, PAGE_SHIFT - 12);
542 if (MLX5_CAP_GEN_MAX(dev, cache_line_128byte))
543 MLX5_SET(cmd_hca_cap,
546 cache_line_size() >= 128 ? 1 : 0);
548 if (MLX5_CAP_GEN_MAX(dev, dct))
549 MLX5_SET(cmd_hca_cap, set_hca_cap, dct, 1);
551 if (MLX5_CAP_GEN_MAX(dev, num_vhca_ports))
552 MLX5_SET(cmd_hca_cap,
555 MLX5_CAP_GEN_MAX(dev, num_vhca_ports));
557 if (MLX5_CAP_GEN_MAX(dev, release_all_pages))
558 MLX5_SET(cmd_hca_cap, set_hca_cap, release_all_pages, 1);
560 return set_caps(dev, set_ctx, MLX5_SET_HCA_CAP_OP_MOD_GENERAL_DEVICE);
563 static int handle_hca_cap_roce(struct mlx5_core_dev *dev, void *set_ctx)
568 if (!MLX5_CAP_GEN(dev, roce))
571 err = mlx5_core_get_caps(dev, MLX5_CAP_ROCE);
575 if (MLX5_CAP_ROCE(dev, sw_r_roce_src_udp_port) ||
576 !MLX5_CAP_ROCE_MAX(dev, sw_r_roce_src_udp_port))
579 set_hca_cap = MLX5_ADDR_OF(set_hca_cap_in, set_ctx, capability);
580 memcpy(set_hca_cap, dev->caps.hca_cur[MLX5_CAP_ROCE],
581 MLX5_ST_SZ_BYTES(roce_cap));
582 MLX5_SET(roce_cap, set_hca_cap, sw_r_roce_src_udp_port, 1);
584 err = set_caps(dev, set_ctx, MLX5_SET_HCA_CAP_OP_MOD_ROCE);
588 static int set_hca_cap(struct mlx5_core_dev *dev)
590 int set_sz = MLX5_ST_SZ_BYTES(set_hca_cap_in);
594 set_ctx = kzalloc(set_sz, GFP_KERNEL);
598 err = handle_hca_cap(dev, set_ctx);
600 mlx5_core_err(dev, "handle_hca_cap failed\n");
604 memset(set_ctx, 0, set_sz);
605 err = handle_hca_cap_atomic(dev, set_ctx);
607 mlx5_core_err(dev, "handle_hca_cap_atomic failed\n");
611 memset(set_ctx, 0, set_sz);
612 err = handle_hca_cap_odp(dev, set_ctx);
614 mlx5_core_err(dev, "handle_hca_cap_odp failed\n");
618 memset(set_ctx, 0, set_sz);
619 err = handle_hca_cap_roce(dev, set_ctx);
621 mlx5_core_err(dev, "handle_hca_cap_roce failed\n");
630 static int set_hca_ctrl(struct mlx5_core_dev *dev)
632 struct mlx5_reg_host_endianness he_in;
633 struct mlx5_reg_host_endianness he_out;
636 if (!mlx5_core_is_pf(dev))
639 memset(&he_in, 0, sizeof(he_in));
640 he_in.he = MLX5_SET_HOST_ENDIANNESS;
641 err = mlx5_core_access_reg(dev, &he_in, sizeof(he_in),
642 &he_out, sizeof(he_out),
643 MLX5_REG_HOST_ENDIANNESS, 0, 1);
647 static int mlx5_core_set_hca_defaults(struct mlx5_core_dev *dev)
651 /* Disable local_lb by default */
652 if (MLX5_CAP_GEN(dev, port_type) == MLX5_CAP_PORT_TYPE_ETH)
653 ret = mlx5_nic_vport_update_local_lb(dev, false);
658 int mlx5_core_enable_hca(struct mlx5_core_dev *dev, u16 func_id)
660 u32 in[MLX5_ST_SZ_DW(enable_hca_in)] = {};
662 MLX5_SET(enable_hca_in, in, opcode, MLX5_CMD_OP_ENABLE_HCA);
663 MLX5_SET(enable_hca_in, in, function_id, func_id);
664 MLX5_SET(enable_hca_in, in, embedded_cpu_function,
665 dev->caps.embedded_cpu);
666 return mlx5_cmd_exec_in(dev, enable_hca, in);
669 int mlx5_core_disable_hca(struct mlx5_core_dev *dev, u16 func_id)
671 u32 in[MLX5_ST_SZ_DW(disable_hca_in)] = {};
673 MLX5_SET(disable_hca_in, in, opcode, MLX5_CMD_OP_DISABLE_HCA);
674 MLX5_SET(disable_hca_in, in, function_id, func_id);
675 MLX5_SET(enable_hca_in, in, embedded_cpu_function,
676 dev->caps.embedded_cpu);
677 return mlx5_cmd_exec_in(dev, disable_hca, in);
680 static int mlx5_core_set_issi(struct mlx5_core_dev *dev)
682 u32 query_out[MLX5_ST_SZ_DW(query_issi_out)] = {};
683 u32 query_in[MLX5_ST_SZ_DW(query_issi_in)] = {};
687 MLX5_SET(query_issi_in, query_in, opcode, MLX5_CMD_OP_QUERY_ISSI);
688 err = mlx5_cmd_exec_inout(dev, query_issi, query_in, query_out);
693 mlx5_cmd_mbox_status(query_out, &status, &syndrome);
694 if (!status || syndrome == MLX5_DRIVER_SYND) {
695 mlx5_core_err(dev, "Failed to query ISSI err(%d) status(%d) synd(%d)\n",
696 err, status, syndrome);
700 mlx5_core_warn(dev, "Query ISSI is not supported by FW, ISSI is 0\n");
705 sup_issi = MLX5_GET(query_issi_out, query_out, supported_issi_dw0);
707 if (sup_issi & (1 << 1)) {
708 u32 set_in[MLX5_ST_SZ_DW(set_issi_in)] = {};
710 MLX5_SET(set_issi_in, set_in, opcode, MLX5_CMD_OP_SET_ISSI);
711 MLX5_SET(set_issi_in, set_in, current_issi, 1);
712 err = mlx5_cmd_exec_in(dev, set_issi, set_in);
714 mlx5_core_err(dev, "Failed to set ISSI to 1 err(%d)\n",
722 } else if (sup_issi & (1 << 0) || !sup_issi) {
729 static int mlx5_pci_init(struct mlx5_core_dev *dev, struct pci_dev *pdev,
730 const struct pci_device_id *id)
732 struct mlx5_priv *priv = &dev->priv;
735 mutex_init(&dev->pci_status_mutex);
736 pci_set_drvdata(dev->pdev, dev);
738 dev->bar_addr = pci_resource_start(pdev, 0);
739 priv->numa_node = dev_to_node(&dev->pdev->dev);
741 err = mlx5_pci_enable_device(dev);
743 mlx5_core_err(dev, "Cannot enable PCI device, aborting\n");
747 err = request_bar(pdev);
749 mlx5_core_err(dev, "error requesting BARs, aborting\n");
753 pci_set_master(pdev);
755 err = set_dma_caps(pdev);
757 mlx5_core_err(dev, "Failed setting DMA capabilities mask, aborting\n");
761 if (pci_enable_atomic_ops_to_root(pdev, PCI_EXP_DEVCAP2_ATOMIC_COMP32) &&
762 pci_enable_atomic_ops_to_root(pdev, PCI_EXP_DEVCAP2_ATOMIC_COMP64) &&
763 pci_enable_atomic_ops_to_root(pdev, PCI_EXP_DEVCAP2_ATOMIC_COMP128))
764 mlx5_core_dbg(dev, "Enabling pci atomics failed\n");
766 dev->iseg_base = dev->bar_addr;
767 dev->iseg = ioremap(dev->iseg_base, sizeof(*dev->iseg));
770 mlx5_core_err(dev, "Failed mapping initialization segment, aborting\n");
774 mlx5_pci_vsc_init(dev);
775 dev->caps.embedded_cpu = mlx5_read_embedded_cpu(dev);
779 pci_clear_master(dev->pdev);
780 release_bar(dev->pdev);
782 mlx5_pci_disable_device(dev);
786 static void mlx5_pci_close(struct mlx5_core_dev *dev)
788 /* health work might still be active, and it needs pci bar in
789 * order to know the NIC state. Therefore, drain the health WQ
790 * before removing the pci bars
792 mlx5_drain_health_wq(dev);
794 pci_clear_master(dev->pdev);
795 release_bar(dev->pdev);
796 mlx5_pci_disable_device(dev);
799 static int mlx5_init_once(struct mlx5_core_dev *dev)
803 dev->priv.devcom = mlx5_devcom_register_device(dev);
804 if (IS_ERR(dev->priv.devcom))
805 mlx5_core_err(dev, "failed to register with devcom (0x%p)\n",
808 err = mlx5_query_board_id(dev);
810 mlx5_core_err(dev, "query board id failed\n");
814 err = mlx5_irq_table_init(dev);
816 mlx5_core_err(dev, "failed to initialize irq table\n");
820 err = mlx5_eq_table_init(dev);
822 mlx5_core_err(dev, "failed to initialize eq\n");
823 goto err_irq_cleanup;
826 err = mlx5_events_init(dev);
828 mlx5_core_err(dev, "failed to initialize events\n");
832 mlx5_cq_debugfs_init(dev);
834 mlx5_init_reserved_gids(dev);
836 mlx5_init_clock(dev);
838 dev->vxlan = mlx5_vxlan_create(dev);
839 dev->geneve = mlx5_geneve_create(dev);
841 err = mlx5_init_rl_table(dev);
843 mlx5_core_err(dev, "Failed to init rate limiting\n");
844 goto err_tables_cleanup;
847 err = mlx5_mpfs_init(dev);
849 mlx5_core_err(dev, "Failed to init l2 table %d\n", err);
853 err = mlx5_sriov_init(dev);
855 mlx5_core_err(dev, "Failed to init sriov %d\n", err);
856 goto err_mpfs_cleanup;
859 err = mlx5_eswitch_init(dev);
861 mlx5_core_err(dev, "Failed to init eswitch %d\n", err);
862 goto err_sriov_cleanup;
865 err = mlx5_fpga_init(dev);
867 mlx5_core_err(dev, "Failed to init fpga device %d\n", err);
868 goto err_eswitch_cleanup;
871 dev->dm = mlx5_dm_create(dev);
873 mlx5_core_warn(dev, "Failed to init device memory%d\n", err);
875 dev->tracer = mlx5_fw_tracer_create(dev);
876 dev->hv_vhca = mlx5_hv_vhca_create(dev);
877 dev->rsc_dump = mlx5_rsc_dump_create(dev);
882 mlx5_eswitch_cleanup(dev->priv.eswitch);
884 mlx5_sriov_cleanup(dev);
886 mlx5_mpfs_cleanup(dev);
888 mlx5_cleanup_rl_table(dev);
890 mlx5_geneve_destroy(dev->geneve);
891 mlx5_vxlan_destroy(dev->vxlan);
892 mlx5_cq_debugfs_cleanup(dev);
893 mlx5_events_cleanup(dev);
895 mlx5_eq_table_cleanup(dev);
897 mlx5_irq_table_cleanup(dev);
899 mlx5_devcom_unregister_device(dev->priv.devcom);
904 static void mlx5_cleanup_once(struct mlx5_core_dev *dev)
906 mlx5_rsc_dump_destroy(dev);
907 mlx5_hv_vhca_destroy(dev->hv_vhca);
908 mlx5_fw_tracer_destroy(dev->tracer);
909 mlx5_dm_cleanup(dev);
910 mlx5_fpga_cleanup(dev);
911 mlx5_eswitch_cleanup(dev->priv.eswitch);
912 mlx5_sriov_cleanup(dev);
913 mlx5_mpfs_cleanup(dev);
914 mlx5_cleanup_rl_table(dev);
915 mlx5_geneve_destroy(dev->geneve);
916 mlx5_vxlan_destroy(dev->vxlan);
917 mlx5_cleanup_clock(dev);
918 mlx5_cleanup_reserved_gids(dev);
919 mlx5_cq_debugfs_cleanup(dev);
920 mlx5_events_cleanup(dev);
921 mlx5_eq_table_cleanup(dev);
922 mlx5_irq_table_cleanup(dev);
923 mlx5_devcom_unregister_device(dev->priv.devcom);
926 static int mlx5_function_setup(struct mlx5_core_dev *dev, bool boot)
930 mlx5_core_info(dev, "firmware version: %d.%d.%d\n", fw_rev_maj(dev),
931 fw_rev_min(dev), fw_rev_sub(dev));
933 /* Only PFs hold the relevant PCIe information for this query */
934 if (mlx5_core_is_pf(dev))
935 pcie_print_link_status(dev->pdev);
937 /* wait for firmware to accept initialization segments configurations
939 err = wait_fw_init(dev, FW_PRE_INIT_TIMEOUT_MILI, FW_INIT_WARN_MESSAGE_INTERVAL);
941 mlx5_core_err(dev, "Firmware over %d MS in pre-initializing state, aborting\n",
942 FW_PRE_INIT_TIMEOUT_MILI);
946 err = mlx5_cmd_init(dev);
948 mlx5_core_err(dev, "Failed initializing command interface, aborting\n");
952 err = wait_fw_init(dev, FW_INIT_TIMEOUT_MILI, 0);
954 mlx5_core_err(dev, "Firmware over %d MS in initializing state, aborting\n",
955 FW_INIT_TIMEOUT_MILI);
956 goto err_cmd_cleanup;
959 mlx5_cmd_set_state(dev, MLX5_CMDIF_STATE_UP);
961 err = mlx5_core_enable_hca(dev, 0);
963 mlx5_core_err(dev, "enable hca failed\n");
964 goto err_cmd_cleanup;
967 err = mlx5_core_set_issi(dev);
969 mlx5_core_err(dev, "failed to set issi\n");
970 goto err_disable_hca;
973 err = mlx5_satisfy_startup_pages(dev, 1);
975 mlx5_core_err(dev, "failed to allocate boot pages\n");
976 goto err_disable_hca;
979 err = set_hca_ctrl(dev);
981 mlx5_core_err(dev, "set_hca_ctrl failed\n");
982 goto reclaim_boot_pages;
985 err = set_hca_cap(dev);
987 mlx5_core_err(dev, "set_hca_cap failed\n");
988 goto reclaim_boot_pages;
991 err = mlx5_satisfy_startup_pages(dev, 0);
993 mlx5_core_err(dev, "failed to allocate init pages\n");
994 goto reclaim_boot_pages;
997 err = mlx5_cmd_init_hca(dev, sw_owner_id);
999 mlx5_core_err(dev, "init hca failed\n");
1000 goto reclaim_boot_pages;
1003 mlx5_set_driver_version(dev);
1005 mlx5_start_health_poll(dev);
1007 err = mlx5_query_hca_caps(dev);
1009 mlx5_core_err(dev, "query hca failed\n");
1016 mlx5_stop_health_poll(dev, boot);
1018 mlx5_reclaim_startup_pages(dev);
1020 mlx5_core_disable_hca(dev, 0);
1022 mlx5_cmd_set_state(dev, MLX5_CMDIF_STATE_DOWN);
1023 mlx5_cmd_cleanup(dev);
1028 static int mlx5_function_teardown(struct mlx5_core_dev *dev, bool boot)
1032 mlx5_stop_health_poll(dev, boot);
1033 err = mlx5_cmd_teardown_hca(dev);
1035 mlx5_core_err(dev, "tear_down_hca failed, skip cleanup\n");
1038 mlx5_reclaim_startup_pages(dev);
1039 mlx5_core_disable_hca(dev, 0);
1040 mlx5_cmd_set_state(dev, MLX5_CMDIF_STATE_DOWN);
1041 mlx5_cmd_cleanup(dev);
1046 static int mlx5_load(struct mlx5_core_dev *dev)
1050 dev->priv.uar = mlx5_get_uars_page(dev);
1051 if (IS_ERR(dev->priv.uar)) {
1052 mlx5_core_err(dev, "Failed allocating uar, aborting\n");
1053 err = PTR_ERR(dev->priv.uar);
1057 mlx5_events_start(dev);
1058 mlx5_pagealloc_start(dev);
1060 err = mlx5_irq_table_create(dev);
1062 mlx5_core_err(dev, "Failed to alloc IRQs\n");
1066 err = mlx5_eq_table_create(dev);
1068 mlx5_core_err(dev, "Failed to create EQs\n");
1072 err = mlx5_fw_tracer_init(dev->tracer);
1074 mlx5_core_err(dev, "Failed to init FW tracer\n");
1078 mlx5_hv_vhca_init(dev->hv_vhca);
1080 err = mlx5_rsc_dump_init(dev);
1082 mlx5_core_err(dev, "Failed to init Resource dump\n");
1086 err = mlx5_fpga_device_start(dev);
1088 mlx5_core_err(dev, "fpga device start failed %d\n", err);
1089 goto err_fpga_start;
1092 err = mlx5_accel_ipsec_init(dev);
1094 mlx5_core_err(dev, "IPSec device start failed %d\n", err);
1095 goto err_ipsec_start;
1098 err = mlx5_accel_tls_init(dev);
1100 mlx5_core_err(dev, "TLS device start failed %d\n", err);
1104 err = mlx5_init_fs(dev);
1106 mlx5_core_err(dev, "Failed to init flow steering\n");
1110 err = mlx5_core_set_hca_defaults(dev);
1112 mlx5_core_err(dev, "Failed to set hca defaults\n");
1116 err = mlx5_sriov_attach(dev);
1118 mlx5_core_err(dev, "sriov init failed %d\n", err);
1122 err = mlx5_ec_init(dev);
1124 mlx5_core_err(dev, "Failed to init embedded CPU\n");
1131 mlx5_sriov_detach(dev);
1133 mlx5_cleanup_fs(dev);
1135 mlx5_accel_tls_cleanup(dev);
1137 mlx5_accel_ipsec_cleanup(dev);
1139 mlx5_fpga_device_stop(dev);
1141 mlx5_rsc_dump_cleanup(dev);
1143 mlx5_hv_vhca_cleanup(dev->hv_vhca);
1144 mlx5_fw_tracer_cleanup(dev->tracer);
1146 mlx5_eq_table_destroy(dev);
1148 mlx5_irq_table_destroy(dev);
1150 mlx5_pagealloc_stop(dev);
1151 mlx5_events_stop(dev);
1152 mlx5_put_uars_page(dev, dev->priv.uar);
1156 static void mlx5_unload(struct mlx5_core_dev *dev)
1158 mlx5_ec_cleanup(dev);
1159 mlx5_sriov_detach(dev);
1160 mlx5_cleanup_fs(dev);
1161 mlx5_accel_ipsec_cleanup(dev);
1162 mlx5_accel_tls_cleanup(dev);
1163 mlx5_fpga_device_stop(dev);
1164 mlx5_rsc_dump_cleanup(dev);
1165 mlx5_hv_vhca_cleanup(dev->hv_vhca);
1166 mlx5_fw_tracer_cleanup(dev->tracer);
1167 mlx5_eq_table_destroy(dev);
1168 mlx5_irq_table_destroy(dev);
1169 mlx5_pagealloc_stop(dev);
1170 mlx5_events_stop(dev);
1171 mlx5_put_uars_page(dev, dev->priv.uar);
1174 int mlx5_load_one(struct mlx5_core_dev *dev, bool boot)
1178 mutex_lock(&dev->intf_state_mutex);
1179 if (test_bit(MLX5_INTERFACE_STATE_UP, &dev->intf_state)) {
1180 mlx5_core_warn(dev, "interface is up, NOP\n");
1183 /* remove any previous indication of internal error */
1184 dev->state = MLX5_DEVICE_STATE_UP;
1186 err = mlx5_function_setup(dev, boot);
1191 err = mlx5_init_once(dev);
1193 mlx5_core_err(dev, "sw objs init failed\n");
1194 goto function_teardown;
1198 err = mlx5_load(dev);
1203 err = mlx5_devlink_register(priv_to_devlink(dev), dev->device);
1205 goto err_devlink_reg;
1208 if (mlx5_device_registered(dev))
1209 mlx5_attach_device(dev);
1211 mlx5_register_device(dev);
1213 set_bit(MLX5_INTERFACE_STATE_UP, &dev->intf_state);
1215 mutex_unlock(&dev->intf_state_mutex);
1222 mlx5_cleanup_once(dev);
1224 mlx5_function_teardown(dev, boot);
1226 dev->state = MLX5_DEVICE_STATE_INTERNAL_ERROR;
1228 mutex_unlock(&dev->intf_state_mutex);
1232 void mlx5_unload_one(struct mlx5_core_dev *dev, bool cleanup)
1235 mlx5_unregister_device(dev);
1237 mutex_lock(&dev->intf_state_mutex);
1238 if (!test_bit(MLX5_INTERFACE_STATE_UP, &dev->intf_state)) {
1239 mlx5_core_warn(dev, "%s: interface is down, NOP\n",
1242 mlx5_cleanup_once(dev);
1246 clear_bit(MLX5_INTERFACE_STATE_UP, &dev->intf_state);
1248 if (mlx5_device_registered(dev))
1249 mlx5_detach_device(dev);
1254 mlx5_cleanup_once(dev);
1256 mlx5_function_teardown(dev, cleanup);
1258 mutex_unlock(&dev->intf_state_mutex);
1261 static int mlx5_mdev_init(struct mlx5_core_dev *dev, int profile_idx)
1263 struct mlx5_priv *priv = &dev->priv;
1266 dev->profile = &profile[profile_idx];
1268 INIT_LIST_HEAD(&priv->ctx_list);
1269 spin_lock_init(&priv->ctx_lock);
1270 mutex_init(&dev->intf_state_mutex);
1272 mutex_init(&priv->bfregs.reg_head.lock);
1273 mutex_init(&priv->bfregs.wc_head.lock);
1274 INIT_LIST_HEAD(&priv->bfregs.reg_head.list);
1275 INIT_LIST_HEAD(&priv->bfregs.wc_head.list);
1277 mutex_init(&priv->alloc_mutex);
1278 mutex_init(&priv->pgdir_mutex);
1279 INIT_LIST_HEAD(&priv->pgdir_list);
1281 priv->dbg_root = debugfs_create_dir(dev_name(dev->device),
1283 if (!priv->dbg_root) {
1284 dev_err(dev->device, "mlx5_core: error, Cannot create debugfs dir, aborting\n");
1288 err = mlx5_health_init(dev);
1290 goto err_health_init;
1292 err = mlx5_pagealloc_init(dev);
1294 goto err_pagealloc_init;
1299 mlx5_health_cleanup(dev);
1301 debugfs_remove(dev->priv.dbg_root);
1303 mutex_destroy(&priv->pgdir_mutex);
1304 mutex_destroy(&priv->alloc_mutex);
1305 mutex_destroy(&priv->bfregs.wc_head.lock);
1306 mutex_destroy(&priv->bfregs.reg_head.lock);
1307 mutex_destroy(&dev->intf_state_mutex);
1311 static void mlx5_mdev_uninit(struct mlx5_core_dev *dev)
1313 struct mlx5_priv *priv = &dev->priv;
1315 mlx5_pagealloc_cleanup(dev);
1316 mlx5_health_cleanup(dev);
1317 debugfs_remove_recursive(dev->priv.dbg_root);
1318 mutex_destroy(&priv->pgdir_mutex);
1319 mutex_destroy(&priv->alloc_mutex);
1320 mutex_destroy(&priv->bfregs.wc_head.lock);
1321 mutex_destroy(&priv->bfregs.reg_head.lock);
1322 mutex_destroy(&dev->intf_state_mutex);
1325 #define MLX5_IB_MOD "mlx5_ib"
1326 static int init_one(struct pci_dev *pdev, const struct pci_device_id *id)
1328 struct mlx5_core_dev *dev;
1329 struct devlink *devlink;
1332 devlink = mlx5_devlink_alloc();
1334 dev_err(&pdev->dev, "devlink alloc failed\n");
1338 dev = devlink_priv(devlink);
1339 dev->device = &pdev->dev;
1342 dev->coredev_type = id->driver_data & MLX5_PCI_DEV_IS_VF ?
1343 MLX5_COREDEV_VF : MLX5_COREDEV_PF;
1345 err = mlx5_mdev_init(dev, prof_sel);
1349 err = mlx5_pci_init(dev, pdev, id);
1351 mlx5_core_err(dev, "mlx5_pci_init failed with error code %d\n",
1356 err = mlx5_load_one(dev, true);
1358 mlx5_core_err(dev, "mlx5_load_one failed with error code %d\n",
1363 request_module_nowait(MLX5_IB_MOD);
1365 err = mlx5_crdump_enable(dev);
1367 dev_err(&pdev->dev, "mlx5_crdump_enable failed with error code %d\n", err);
1369 pci_save_state(pdev);
1370 devlink_reload_enable(devlink);
1374 mlx5_pci_close(dev);
1376 mlx5_mdev_uninit(dev);
1378 mlx5_devlink_free(devlink);
1383 static void remove_one(struct pci_dev *pdev)
1385 struct mlx5_core_dev *dev = pci_get_drvdata(pdev);
1386 struct devlink *devlink = priv_to_devlink(dev);
1388 devlink_reload_disable(devlink);
1389 mlx5_crdump_disable(dev);
1390 mlx5_devlink_unregister(devlink);
1392 mlx5_drain_health_wq(dev);
1393 mlx5_unload_one(dev, true);
1394 mlx5_pci_close(dev);
1395 mlx5_mdev_uninit(dev);
1396 mlx5_devlink_free(devlink);
1399 static pci_ers_result_t mlx5_pci_err_detected(struct pci_dev *pdev,
1400 pci_channel_state_t state)
1402 struct mlx5_core_dev *dev = pci_get_drvdata(pdev);
1404 mlx5_core_info(dev, "%s was called\n", __func__);
1406 mlx5_enter_error_state(dev, false);
1407 mlx5_error_sw_reset(dev);
1408 mlx5_unload_one(dev, false);
1409 mlx5_drain_health_wq(dev);
1410 mlx5_pci_disable_device(dev);
1412 return state == pci_channel_io_perm_failure ?
1413 PCI_ERS_RESULT_DISCONNECT : PCI_ERS_RESULT_NEED_RESET;
1416 /* wait for the device to show vital signs by waiting
1417 * for the health counter to start counting.
1419 static int wait_vital(struct pci_dev *pdev)
1421 struct mlx5_core_dev *dev = pci_get_drvdata(pdev);
1422 struct mlx5_core_health *health = &dev->priv.health;
1423 const int niter = 100;
1428 for (i = 0; i < niter; i++) {
1429 count = ioread32be(health->health_counter);
1430 if (count && count != 0xffffffff) {
1431 if (last_count && last_count != count) {
1433 "wait vital counter value 0x%x after %d iterations\n",
1445 static pci_ers_result_t mlx5_pci_slot_reset(struct pci_dev *pdev)
1447 struct mlx5_core_dev *dev = pci_get_drvdata(pdev);
1450 mlx5_core_info(dev, "%s was called\n", __func__);
1452 err = mlx5_pci_enable_device(dev);
1454 mlx5_core_err(dev, "%s: mlx5_pci_enable_device failed with error code: %d\n",
1456 return PCI_ERS_RESULT_DISCONNECT;
1459 pci_set_master(pdev);
1460 pci_restore_state(pdev);
1461 pci_save_state(pdev);
1463 if (wait_vital(pdev)) {
1464 mlx5_core_err(dev, "%s: wait_vital timed out\n", __func__);
1465 return PCI_ERS_RESULT_DISCONNECT;
1468 return PCI_ERS_RESULT_RECOVERED;
1471 static void mlx5_pci_resume(struct pci_dev *pdev)
1473 struct mlx5_core_dev *dev = pci_get_drvdata(pdev);
1476 mlx5_core_info(dev, "%s was called\n", __func__);
1478 err = mlx5_load_one(dev, false);
1480 mlx5_core_err(dev, "%s: mlx5_load_one failed with error code: %d\n",
1483 mlx5_core_info(dev, "%s: device recovered\n", __func__);
1486 static const struct pci_error_handlers mlx5_err_handler = {
1487 .error_detected = mlx5_pci_err_detected,
1488 .slot_reset = mlx5_pci_slot_reset,
1489 .resume = mlx5_pci_resume
1492 static int mlx5_try_fast_unload(struct mlx5_core_dev *dev)
1494 bool fast_teardown = false, force_teardown = false;
1497 fast_teardown = MLX5_CAP_GEN(dev, fast_teardown);
1498 force_teardown = MLX5_CAP_GEN(dev, force_teardown);
1500 mlx5_core_dbg(dev, "force teardown firmware support=%d\n", force_teardown);
1501 mlx5_core_dbg(dev, "fast teardown firmware support=%d\n", fast_teardown);
1503 if (!fast_teardown && !force_teardown)
1506 if (dev->state == MLX5_DEVICE_STATE_INTERNAL_ERROR) {
1507 mlx5_core_dbg(dev, "Device in internal error state, giving up\n");
1511 /* Panic tear down fw command will stop the PCI bus communication
1512 * with the HCA, so the health polll is no longer needed.
1514 mlx5_drain_health_wq(dev);
1515 mlx5_stop_health_poll(dev, false);
1517 ret = mlx5_cmd_fast_teardown_hca(dev);
1521 ret = mlx5_cmd_force_teardown_hca(dev);
1525 mlx5_core_dbg(dev, "Firmware couldn't do fast unload error: %d\n", ret);
1526 mlx5_start_health_poll(dev);
1530 mlx5_enter_error_state(dev, true);
1532 /* Some platforms requiring freeing the IRQ's in the shutdown
1533 * flow. If they aren't freed they can't be allocated after
1534 * kexec. There is no need to cleanup the mlx5_core software
1537 mlx5_core_eq_free_irqs(dev);
1542 static void shutdown(struct pci_dev *pdev)
1544 struct mlx5_core_dev *dev = pci_get_drvdata(pdev);
1547 mlx5_core_info(dev, "Shutdown was called\n");
1548 err = mlx5_try_fast_unload(dev);
1550 mlx5_unload_one(dev, false);
1551 mlx5_pci_disable_device(dev);
1554 static int mlx5_suspend(struct pci_dev *pdev, pm_message_t state)
1556 struct mlx5_core_dev *dev = pci_get_drvdata(pdev);
1558 mlx5_unload_one(dev, false);
1563 static int mlx5_resume(struct pci_dev *pdev)
1565 struct mlx5_core_dev *dev = pci_get_drvdata(pdev);
1567 return mlx5_load_one(dev, false);
1570 static const struct pci_device_id mlx5_core_pci_table[] = {
1571 { PCI_VDEVICE(MELLANOX, PCI_DEVICE_ID_MELLANOX_CONNECTIB) },
1572 { PCI_VDEVICE(MELLANOX, 0x1012), MLX5_PCI_DEV_IS_VF}, /* Connect-IB VF */
1573 { PCI_VDEVICE(MELLANOX, PCI_DEVICE_ID_MELLANOX_CONNECTX4) },
1574 { PCI_VDEVICE(MELLANOX, 0x1014), MLX5_PCI_DEV_IS_VF}, /* ConnectX-4 VF */
1575 { PCI_VDEVICE(MELLANOX, PCI_DEVICE_ID_MELLANOX_CONNECTX4_LX) },
1576 { PCI_VDEVICE(MELLANOX, 0x1016), MLX5_PCI_DEV_IS_VF}, /* ConnectX-4LX VF */
1577 { PCI_VDEVICE(MELLANOX, 0x1017) }, /* ConnectX-5, PCIe 3.0 */
1578 { PCI_VDEVICE(MELLANOX, 0x1018), MLX5_PCI_DEV_IS_VF}, /* ConnectX-5 VF */
1579 { PCI_VDEVICE(MELLANOX, 0x1019) }, /* ConnectX-5 Ex */
1580 { PCI_VDEVICE(MELLANOX, 0x101a), MLX5_PCI_DEV_IS_VF}, /* ConnectX-5 Ex VF */
1581 { PCI_VDEVICE(MELLANOX, 0x101b) }, /* ConnectX-6 */
1582 { PCI_VDEVICE(MELLANOX, 0x101c), MLX5_PCI_DEV_IS_VF}, /* ConnectX-6 VF */
1583 { PCI_VDEVICE(MELLANOX, 0x101d) }, /* ConnectX-6 Dx */
1584 { PCI_VDEVICE(MELLANOX, 0x101e), MLX5_PCI_DEV_IS_VF}, /* ConnectX Family mlx5Gen Virtual Function */
1585 { PCI_VDEVICE(MELLANOX, 0x101f) }, /* ConnectX-6 LX */
1586 { PCI_VDEVICE(MELLANOX, 0x1021) }, /* ConnectX-7 */
1587 { PCI_VDEVICE(MELLANOX, 0xa2d2) }, /* BlueField integrated ConnectX-5 network controller */
1588 { PCI_VDEVICE(MELLANOX, 0xa2d3), MLX5_PCI_DEV_IS_VF}, /* BlueField integrated ConnectX-5 network controller VF */
1589 { PCI_VDEVICE(MELLANOX, 0xa2d6) }, /* BlueField-2 integrated ConnectX-6 Dx network controller */
1593 MODULE_DEVICE_TABLE(pci, mlx5_core_pci_table);
1595 void mlx5_disable_device(struct mlx5_core_dev *dev)
1597 mlx5_error_sw_reset(dev);
1598 mlx5_unload_one(dev, false);
1601 void mlx5_recover_device(struct mlx5_core_dev *dev)
1603 mlx5_pci_disable_device(dev);
1604 if (mlx5_pci_slot_reset(dev->pdev) == PCI_ERS_RESULT_RECOVERED)
1605 mlx5_pci_resume(dev->pdev);
1608 static struct pci_driver mlx5_core_driver = {
1609 .name = DRIVER_NAME,
1610 .id_table = mlx5_core_pci_table,
1612 .remove = remove_one,
1613 .suspend = mlx5_suspend,
1614 .resume = mlx5_resume,
1615 .shutdown = shutdown,
1616 .err_handler = &mlx5_err_handler,
1617 .sriov_configure = mlx5_core_sriov_configure,
1620 static void mlx5_core_verify_params(void)
1622 if (prof_sel >= ARRAY_SIZE(profile)) {
1623 pr_warn("mlx5_core: WARNING: Invalid module parameter prof_sel %d, valid range 0-%zu, changing back to default(%d)\n",
1625 ARRAY_SIZE(profile) - 1,
1627 prof_sel = MLX5_DEFAULT_PROF;
1631 static int __init init(void)
1635 get_random_bytes(&sw_owner_id, sizeof(sw_owner_id));
1637 mlx5_core_verify_params();
1638 mlx5_accel_ipsec_build_fs_cmds();
1639 mlx5_register_debugfs();
1641 err = pci_register_driver(&mlx5_core_driver);
1645 #ifdef CONFIG_MLX5_CORE_EN
1652 mlx5_unregister_debugfs();
1656 static void __exit cleanup(void)
1658 #ifdef CONFIG_MLX5_CORE_EN
1661 pci_unregister_driver(&mlx5_core_driver);
1662 mlx5_unregister_debugfs();
1666 module_exit(cleanup);