1 /* QLogic qedr NIC Driver
2 * Copyright (c) 2015-2016 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
32 #include <linux/module.h>
33 #include <rdma/ib_verbs.h>
34 #include <rdma/ib_addr.h>
35 #include <linux/netdevice.h>
36 #include <linux/iommu.h>
37 #include <net/addrconf.h>
38 #include <linux/qed/qede_roce.h>
41 MODULE_DESCRIPTION("QLogic 40G/100G ROCE Driver");
42 MODULE_AUTHOR("QLogic Corporation");
43 MODULE_LICENSE("Dual BSD/GPL");
44 MODULE_VERSION(QEDR_MODULE_VERSION);
46 void qedr_ib_dispatch_event(struct qedr_dev *dev, u8 port_num,
47 enum ib_event_type type)
51 ibev.device = &dev->ibdev;
52 ibev.element.port_num = port_num;
55 ib_dispatch_event(&ibev);
58 static enum rdma_link_layer qedr_link_layer(struct ib_device *device,
61 return IB_LINK_LAYER_ETHERNET;
64 static int qedr_register_device(struct qedr_dev *dev)
66 strlcpy(dev->ibdev.name, "qedr%d", IB_DEVICE_NAME_MAX);
68 memcpy(dev->ibdev.node_desc, QEDR_NODE_DESC, sizeof(QEDR_NODE_DESC));
69 dev->ibdev.owner = THIS_MODULE;
71 dev->ibdev.get_link_layer = qedr_link_layer;
76 /* QEDR sysfs interface */
77 static ssize_t show_rev(struct device *device, struct device_attribute *attr,
80 struct qedr_dev *dev = dev_get_drvdata(device);
82 return scnprintf(buf, PAGE_SIZE, "0x%x\n", dev->pdev->vendor);
85 static ssize_t show_hca_type(struct device *device,
86 struct device_attribute *attr, char *buf)
88 return scnprintf(buf, PAGE_SIZE, "%s\n", "HCA_TYPE_TO_SET");
91 static DEVICE_ATTR(hw_rev, S_IRUGO, show_rev, NULL);
92 static DEVICE_ATTR(hca_type, S_IRUGO, show_hca_type, NULL);
94 static struct device_attribute *qedr_attributes[] = {
99 static void qedr_remove_sysfiles(struct qedr_dev *dev)
103 for (i = 0; i < ARRAY_SIZE(qedr_attributes); i++)
104 device_remove_file(&dev->ibdev.dev, qedr_attributes[i]);
107 static void qedr_pci_set_atomic(struct qedr_dev *dev, struct pci_dev *pdev)
109 struct pci_dev *bridge;
112 dev->atomic_cap = IB_ATOMIC_NONE;
114 bridge = pdev->bus->self;
118 /* Check whether we are connected directly or via a switch */
119 while (bridge && bridge->bus->parent) {
120 DP_DEBUG(dev, QEDR_MSG_INIT,
121 "Device is not connected directly to root. bridge->bus->number=%d primary=%d\n",
122 bridge->bus->number, bridge->bus->primary);
123 /* Need to check Atomic Op Routing Supported all the way to
126 pcie_capability_read_dword(bridge, PCI_EXP_DEVCAP2, &val);
127 if (!(val & PCI_EXP_DEVCAP2_ATOMIC_ROUTE)) {
128 pcie_capability_clear_word(pdev,
130 PCI_EXP_DEVCTL2_ATOMIC_REQ);
133 bridge = bridge->bus->parent->self;
135 bridge = pdev->bus->self;
137 /* according to bridge capability */
138 pcie_capability_read_dword(bridge, PCI_EXP_DEVCAP2, &val);
139 if (val & PCI_EXP_DEVCAP2_ATOMIC_COMP64) {
140 pcie_capability_set_word(pdev, PCI_EXP_DEVCTL2,
141 PCI_EXP_DEVCTL2_ATOMIC_REQ);
142 dev->atomic_cap = IB_ATOMIC_GLOB;
144 pcie_capability_clear_word(pdev, PCI_EXP_DEVCTL2,
145 PCI_EXP_DEVCTL2_ATOMIC_REQ);
149 static struct qedr_dev *qedr_add(struct qed_dev *cdev, struct pci_dev *pdev,
150 struct net_device *ndev)
152 struct qedr_dev *dev;
155 dev = (struct qedr_dev *)ib_alloc_device(sizeof(*dev));
157 pr_err("Unable to allocate ib device\n");
161 DP_DEBUG(dev, QEDR_MSG_INIT, "qedr add device called\n");
167 qedr_pci_set_atomic(dev, pdev);
169 rc = qedr_register_device(dev);
171 DP_ERR(dev, "Unable to allocate register device\n");
175 for (i = 0; i < ARRAY_SIZE(qedr_attributes); i++)
176 if (device_create_file(&dev->ibdev.dev, qedr_attributes[i]))
179 DP_DEBUG(dev, QEDR_MSG_INIT, "qedr driver loaded successfully\n");
183 ib_dealloc_device(&dev->ibdev);
184 DP_ERR(dev, "qedr driver load failed rc=%d\n", rc);
189 static void qedr_remove(struct qedr_dev *dev)
191 /* First unregister with stack to stop all the active traffic
192 * of the registered clients.
194 qedr_remove_sysfiles(dev);
196 ib_dealloc_device(&dev->ibdev);
199 static int qedr_close(struct qedr_dev *dev)
201 qedr_ib_dispatch_event(dev, 1, IB_EVENT_PORT_ERR);
206 static void qedr_shutdown(struct qedr_dev *dev)
212 /* event handling via NIC driver ensures that all the NIC specific
213 * initialization done before RoCE driver notifies
216 static void qedr_notify(struct qedr_dev *dev, enum qede_roce_event event)
220 qedr_ib_dispatch_event(dev, 1, IB_EVENT_PORT_ACTIVE);
228 case QEDE_CHANGE_ADDR:
229 qedr_ib_dispatch_event(dev, 1, IB_EVENT_GID_CHANGE);
232 pr_err("Event not supported\n");
236 static struct qedr_driver qedr_drv = {
237 .name = "qedr_driver",
239 .remove = qedr_remove,
240 .notify = qedr_notify,
243 static int __init qedr_init_module(void)
245 return qede_roce_register_driver(&qedr_drv);
248 static void __exit qedr_exit_module(void)
250 qede_roce_unregister_driver(&qedr_drv);
253 module_init(qedr_init_module);
254 module_exit(qedr_exit_module);