blob: cb1af0fb405145e60c60f7f3c9b1f91f273dfdf2 [file] [log] [blame]
Devesh Sharma71ee6732015-07-24 05:03:59 +05301/* This file is part of the Emulex RoCE Device Driver for
2 * RoCE (RDMA over Converged Ethernet) adapters.
3 * Copyright (C) 2012-2015 Emulex. All rights reserved.
4 * EMULEX and SLI are trademarks of Emulex.
5 * www.emulex.com
6 *
7 * This software is available to you under a choice of one of two licenses.
8 * You may choose to be licensed under the terms of the GNU General Public
9 * License (GPL) Version 2, available from the file COPYING in the main
10 * directory of this source tree, or the BSD license below:
11 *
12 * Redistribution and use in source and binary forms, with or without
13 * modification, are permitted provided that the following conditions
14 * are met:
15 *
16 * - Redistributions of source code must retain the above copyright notice,
17 * this list of conditions and the following disclaimer.
18 *
19 * - Redistributions in binary form must reproduce the above copyright
20 * notice, this list of conditions and the following disclaimer in
21 * the documentation and/or other materials provided with the distribution.
22 *
23 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
24 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,THE
25 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
26 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
27 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
28 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
29 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
30 * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
31 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
32 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
33 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
Parav Panditfe2caef2012-03-21 04:09:06 +053034 *
35 * Contact Information:
36 * linux-drivers@emulex.com
37 *
38 * Emulex
39 * 3333 Susan Street
40 * Costa Mesa, CA 92626
Devesh Sharma71ee6732015-07-24 05:03:59 +053041 */
Parav Panditfe2caef2012-03-21 04:09:06 +053042
43#include <linux/module.h>
Parav Panditfe2caef2012-03-21 04:09:06 +053044#include <linux/idr.h>
45#include <rdma/ib_verbs.h>
46#include <rdma/ib_user_verbs.h>
47#include <rdma/ib_addr.h>
Ira Weiny337877a2015-06-06 14:38:29 -040048#include <rdma/ib_mad.h>
Parav Panditfe2caef2012-03-21 04:09:06 +053049
50#include <linux/netdevice.h>
51#include <net/addrconf.h>
52
53#include "ocrdma.h"
54#include "ocrdma_verbs.h"
55#include "ocrdma_ah.h"
56#include "be_roce.h"
57#include "ocrdma_hw.h"
Selvin Xaviera51f06e2014-02-04 11:57:07 +053058#include "ocrdma_stats.h"
Naresh Gottumukkala38754392013-08-26 15:27:49 +053059#include "ocrdma_abi.h"
Parav Panditfe2caef2012-03-21 04:09:06 +053060
Devesh Sharma01544102014-02-04 11:57:00 +053061MODULE_VERSION(OCRDMA_ROCE_DRV_VERSION);
62MODULE_DESCRIPTION(OCRDMA_ROCE_DRV_DESC " " OCRDMA_ROCE_DRV_VERSION);
Parav Panditfe2caef2012-03-21 04:09:06 +053063MODULE_AUTHOR("Emulex Corporation");
Devesh Sharmab8f55952015-07-24 05:04:00 +053064MODULE_LICENSE("Dual BSD/GPL");
Parav Panditfe2caef2012-03-21 04:09:06 +053065
Parav Panditfe2caef2012-03-21 04:09:06 +053066static DEFINE_IDR(ocrdma_dev_id);
67
Parav Panditfe2caef2012-03-21 04:09:06 +053068void ocrdma_get_guid(struct ocrdma_dev *dev, u8 *guid)
69{
70 u8 mac_addr[6];
71
72 memcpy(&mac_addr[0], &dev->nic_info.mac_addr[0], ETH_ALEN);
73 guid[0] = mac_addr[0] ^ 2;
74 guid[1] = mac_addr[1];
75 guid[2] = mac_addr[2];
76 guid[3] = 0xff;
77 guid[4] = 0xfe;
78 guid[5] = mac_addr[3];
79 guid[6] = mac_addr[4];
80 guid[7] = mac_addr[5];
81}
Parav Panditfe2caef2012-03-21 04:09:06 +053082static enum rdma_link_layer ocrdma_link_layer(struct ib_device *device,
83 u8 port_num)
84{
85 return IB_LINK_LAYER_ETHERNET;
86}
87
Ira Weiny77386132015-05-13 20:02:58 -040088static int ocrdma_port_immutable(struct ib_device *ibdev, u8 port_num,
89 struct ib_port_immutable *immutable)
90{
91 struct ib_port_attr attr;
92 int err;
93
94 err = ocrdma_query_port(ibdev, port_num, &attr);
95 if (err)
96 return err;
97
98 immutable->pkey_tbl_len = attr.pkey_tbl_len;
99 immutable->gid_tbl_len = attr.gid_tbl_len;
Ira Weinyf9b22e32015-05-13 20:02:59 -0400100 immutable->core_cap_flags = RDMA_CORE_PORT_IBA_ROCE;
Ira Weiny337877a2015-06-06 14:38:29 -0400101 immutable->max_mad_size = IB_MGMT_MAD_SIZE;
Ira Weiny77386132015-05-13 20:02:58 -0400102
103 return 0;
104}
105
Roland Dreierabe3afa2012-04-16 11:36:29 -0700106static int ocrdma_register_device(struct ocrdma_dev *dev)
Parav Panditfe2caef2012-03-21 04:09:06 +0530107{
108 strlcpy(dev->ibdev.name, "ocrdma%d", IB_DEVICE_NAME_MAX);
109 ocrdma_get_guid(dev, (u8 *)&dev->ibdev.node_guid);
110 memcpy(dev->ibdev.node_desc, OCRDMA_NODE_DESC,
111 sizeof(OCRDMA_NODE_DESC));
112 dev->ibdev.owner = THIS_MODULE;
Naresh Gottumukkala38754392013-08-26 15:27:49 +0530113 dev->ibdev.uverbs_abi_ver = OCRDMA_ABI_VERSION;
Parav Panditfe2caef2012-03-21 04:09:06 +0530114 dev->ibdev.uverbs_cmd_mask =
115 OCRDMA_UVERBS(GET_CONTEXT) |
116 OCRDMA_UVERBS(QUERY_DEVICE) |
117 OCRDMA_UVERBS(QUERY_PORT) |
118 OCRDMA_UVERBS(ALLOC_PD) |
119 OCRDMA_UVERBS(DEALLOC_PD) |
120 OCRDMA_UVERBS(REG_MR) |
121 OCRDMA_UVERBS(DEREG_MR) |
122 OCRDMA_UVERBS(CREATE_COMP_CHANNEL) |
123 OCRDMA_UVERBS(CREATE_CQ) |
124 OCRDMA_UVERBS(RESIZE_CQ) |
125 OCRDMA_UVERBS(DESTROY_CQ) |
126 OCRDMA_UVERBS(REQ_NOTIFY_CQ) |
127 OCRDMA_UVERBS(CREATE_QP) |
128 OCRDMA_UVERBS(MODIFY_QP) |
129 OCRDMA_UVERBS(QUERY_QP) |
130 OCRDMA_UVERBS(DESTROY_QP) |
131 OCRDMA_UVERBS(POLL_CQ) |
132 OCRDMA_UVERBS(POST_SEND) |
133 OCRDMA_UVERBS(POST_RECV);
134
135 dev->ibdev.uverbs_cmd_mask |=
136 OCRDMA_UVERBS(CREATE_AH) |
137 OCRDMA_UVERBS(MODIFY_AH) |
138 OCRDMA_UVERBS(QUERY_AH) |
139 OCRDMA_UVERBS(DESTROY_AH);
140
141 dev->ibdev.node_type = RDMA_NODE_IB_CA;
142 dev->ibdev.phys_port_cnt = 1;
Devesh Sharma0c0eacd2014-12-18 14:12:58 +0530143 dev->ibdev.num_comp_vectors = dev->eq_cnt;
Parav Panditfe2caef2012-03-21 04:09:06 +0530144
145 /* mandatory verbs. */
146 dev->ibdev.query_device = ocrdma_query_device;
147 dev->ibdev.query_port = ocrdma_query_port;
148 dev->ibdev.modify_port = ocrdma_modify_port;
149 dev->ibdev.query_gid = ocrdma_query_gid;
Somnath Koturcc369292015-07-30 18:33:31 +0300150 dev->ibdev.get_netdev = ocrdma_get_netdev;
151 dev->ibdev.add_gid = ocrdma_add_gid;
152 dev->ibdev.del_gid = ocrdma_del_gid;
Parav Panditfe2caef2012-03-21 04:09:06 +0530153 dev->ibdev.get_link_layer = ocrdma_link_layer;
154 dev->ibdev.alloc_pd = ocrdma_alloc_pd;
155 dev->ibdev.dealloc_pd = ocrdma_dealloc_pd;
156
157 dev->ibdev.create_cq = ocrdma_create_cq;
158 dev->ibdev.destroy_cq = ocrdma_destroy_cq;
159 dev->ibdev.resize_cq = ocrdma_resize_cq;
160
161 dev->ibdev.create_qp = ocrdma_create_qp;
162 dev->ibdev.modify_qp = ocrdma_modify_qp;
163 dev->ibdev.query_qp = ocrdma_query_qp;
164 dev->ibdev.destroy_qp = ocrdma_destroy_qp;
165
166 dev->ibdev.query_pkey = ocrdma_query_pkey;
167 dev->ibdev.create_ah = ocrdma_create_ah;
168 dev->ibdev.destroy_ah = ocrdma_destroy_ah;
169 dev->ibdev.query_ah = ocrdma_query_ah;
170 dev->ibdev.modify_ah = ocrdma_modify_ah;
171
172 dev->ibdev.poll_cq = ocrdma_poll_cq;
173 dev->ibdev.post_send = ocrdma_post_send;
174 dev->ibdev.post_recv = ocrdma_post_recv;
175 dev->ibdev.req_notify_cq = ocrdma_arm_cq;
176
177 dev->ibdev.get_dma_mr = ocrdma_get_dma_mr;
Naresh Gottumukkalacffce992013-08-26 15:27:44 +0530178 dev->ibdev.reg_phys_mr = ocrdma_reg_kernel_mr;
Parav Panditfe2caef2012-03-21 04:09:06 +0530179 dev->ibdev.dereg_mr = ocrdma_dereg_mr;
180 dev->ibdev.reg_user_mr = ocrdma_reg_user_mr;
181
Sagi Grimbergcacb7d52015-07-30 10:32:43 +0300182 dev->ibdev.alloc_mr = ocrdma_alloc_mr;
Naresh Gottumukkala7c338802013-08-26 15:27:39 +0530183 dev->ibdev.alloc_fast_reg_page_list = ocrdma_alloc_frmr_page_list;
184 dev->ibdev.free_fast_reg_page_list = ocrdma_free_frmr_page_list;
185
Parav Panditfe2caef2012-03-21 04:09:06 +0530186 /* mandatory to support user space verbs consumer. */
187 dev->ibdev.alloc_ucontext = ocrdma_alloc_ucontext;
188 dev->ibdev.dealloc_ucontext = ocrdma_dealloc_ucontext;
189 dev->ibdev.mmap = ocrdma_mmap;
190 dev->ibdev.dma_device = &dev->nic_info.pdev->dev;
191
192 dev->ibdev.process_mad = ocrdma_process_mad;
Ira Weiny77386132015-05-13 20:02:58 -0400193 dev->ibdev.get_port_immutable = ocrdma_port_immutable;
Parav Panditfe2caef2012-03-21 04:09:06 +0530194
Devesh Sharma21c33912014-02-04 11:56:56 +0530195 if (ocrdma_get_asic_type(dev) == OCRDMA_ASIC_GEN_SKH_R) {
Parav Panditfe2caef2012-03-21 04:09:06 +0530196 dev->ibdev.uverbs_cmd_mask |=
197 OCRDMA_UVERBS(CREATE_SRQ) |
198 OCRDMA_UVERBS(MODIFY_SRQ) |
199 OCRDMA_UVERBS(QUERY_SRQ) |
200 OCRDMA_UVERBS(DESTROY_SRQ) |
201 OCRDMA_UVERBS(POST_SRQ_RECV);
202
203 dev->ibdev.create_srq = ocrdma_create_srq;
204 dev->ibdev.modify_srq = ocrdma_modify_srq;
205 dev->ibdev.query_srq = ocrdma_query_srq;
206 dev->ibdev.destroy_srq = ocrdma_destroy_srq;
207 dev->ibdev.post_srq_recv = ocrdma_post_srq_recv;
208 }
209 return ib_register_device(&dev->ibdev, NULL);
210}
211
212static int ocrdma_alloc_resources(struct ocrdma_dev *dev)
213{
214 mutex_init(&dev->dev_lock);
Parav Panditfe2caef2012-03-21 04:09:06 +0530215 dev->cq_tbl = kzalloc(sizeof(struct ocrdma_cq *) *
216 OCRDMA_MAX_CQ, GFP_KERNEL);
217 if (!dev->cq_tbl)
218 goto alloc_err;
219
220 if (dev->attr.max_qp) {
221 dev->qp_tbl = kzalloc(sizeof(struct ocrdma_qp *) *
222 OCRDMA_MAX_QP, GFP_KERNEL);
223 if (!dev->qp_tbl)
224 goto alloc_err;
225 }
Selvin Xavier4f1df842014-06-10 19:32:24 +0530226
227 dev->stag_arr = kzalloc(sizeof(u64) * OCRDMA_MAX_STAG, GFP_KERNEL);
228 if (dev->stag_arr == NULL)
229 goto alloc_err;
230
Mitesh Ahuja9ba13772014-12-18 14:12:57 +0530231 ocrdma_alloc_pd_pool(dev);
232
Parav Panditfe2caef2012-03-21 04:09:06 +0530233 spin_lock_init(&dev->av_tbl.lock);
234 spin_lock_init(&dev->flush_q_lock);
235 return 0;
236alloc_err:
Naresh Gottumukkalaef99c4c2013-06-10 04:42:39 +0000237 pr_err("%s(%d) error.\n", __func__, dev->id);
Parav Panditfe2caef2012-03-21 04:09:06 +0530238 return -ENOMEM;
239}
240
241static void ocrdma_free_resources(struct ocrdma_dev *dev)
242{
Selvin Xavier4f1df842014-06-10 19:32:24 +0530243 kfree(dev->stag_arr);
Parav Panditfe2caef2012-03-21 04:09:06 +0530244 kfree(dev->qp_tbl);
245 kfree(dev->cq_tbl);
Parav Panditfe2caef2012-03-21 04:09:06 +0530246}
247
Selvin Xavier334b8db2014-02-04 11:57:09 +0530248/* OCRDMA sysfs interface */
249static ssize_t show_rev(struct device *device, struct device_attribute *attr,
250 char *buf)
251{
252 struct ocrdma_dev *dev = dev_get_drvdata(device);
253
254 return scnprintf(buf, PAGE_SIZE, "0x%x\n", dev->nic_info.pdev->vendor);
255}
256
257static ssize_t show_fw_ver(struct device *device, struct device_attribute *attr,
258 char *buf)
259{
260 struct ocrdma_dev *dev = dev_get_drvdata(device);
261
Selvin Xavier4808b182014-06-10 19:32:14 +0530262 return scnprintf(buf, PAGE_SIZE, "%s\n", &dev->attr.fw_ver[0]);
263}
264
265static ssize_t show_hca_type(struct device *device,
266 struct device_attribute *attr, char *buf)
267{
268 struct ocrdma_dev *dev = dev_get_drvdata(device);
269
270 return scnprintf(buf, PAGE_SIZE, "%s\n", &dev->model_number[0]);
Selvin Xavier334b8db2014-02-04 11:57:09 +0530271}
272
273static DEVICE_ATTR(hw_rev, S_IRUGO, show_rev, NULL);
274static DEVICE_ATTR(fw_ver, S_IRUGO, show_fw_ver, NULL);
Selvin Xavier4808b182014-06-10 19:32:14 +0530275static DEVICE_ATTR(hca_type, S_IRUGO, show_hca_type, NULL);
Selvin Xavier334b8db2014-02-04 11:57:09 +0530276
277static struct device_attribute *ocrdma_attributes[] = {
278 &dev_attr_hw_rev,
Selvin Xavier4808b182014-06-10 19:32:14 +0530279 &dev_attr_fw_ver,
280 &dev_attr_hca_type
Selvin Xavier334b8db2014-02-04 11:57:09 +0530281};
282
283static void ocrdma_remove_sysfiles(struct ocrdma_dev *dev)
284{
285 int i;
286
287 for (i = 0; i < ARRAY_SIZE(ocrdma_attributes); i++)
288 device_remove_file(&dev->ibdev.dev, ocrdma_attributes[i]);
289}
290
Parav Panditfe2caef2012-03-21 04:09:06 +0530291static struct ocrdma_dev *ocrdma_add(struct be_dev_info *dev_info)
292{
Selvin Xavier334b8db2014-02-04 11:57:09 +0530293 int status = 0, i;
Parav Panditfe2caef2012-03-21 04:09:06 +0530294 struct ocrdma_dev *dev;
295
296 dev = (struct ocrdma_dev *)ib_alloc_device(sizeof(struct ocrdma_dev));
297 if (!dev) {
Naresh Gottumukkalaef99c4c2013-06-10 04:42:39 +0000298 pr_err("Unable to allocate ib device\n");
Parav Panditfe2caef2012-03-21 04:09:06 +0530299 return NULL;
300 }
301 dev->mbx_cmd = kzalloc(sizeof(struct ocrdma_mqe_emb_cmd), GFP_KERNEL);
302 if (!dev->mbx_cmd)
303 goto idr_err;
304
305 memcpy(&dev->nic_info, dev_info, sizeof(*dev_info));
Tejun Heocffcd592013-02-27 17:04:24 -0800306 dev->id = idr_alloc(&ocrdma_dev_id, NULL, 0, 0, GFP_KERNEL);
Parav Panditfe2caef2012-03-21 04:09:06 +0530307 if (dev->id < 0)
308 goto idr_err;
309
310 status = ocrdma_init_hw(dev);
311 if (status)
312 goto init_err;
313
314 status = ocrdma_alloc_resources(dev);
315 if (status)
316 goto alloc_err;
317
Selvin Xavier31dbdd92014-06-10 19:32:13 +0530318 ocrdma_init_service_level(dev);
Parav Panditfe2caef2012-03-21 04:09:06 +0530319 status = ocrdma_register_device(dev);
320 if (status)
321 goto alloc_err;
322
Selvin Xavier334b8db2014-02-04 11:57:09 +0530323 for (i = 0; i < ARRAY_SIZE(ocrdma_attributes); i++)
324 if (device_create_file(&dev->ibdev.dev, ocrdma_attributes[i]))
325 goto sysfs_err;
Selvin Xaviera51f06e2014-02-04 11:57:07 +0530326 /* Init stats */
327 ocrdma_add_port_stats(dev);
Mitesh Ahujab4dbe8d2014-12-18 14:13:05 +0530328 /* Interrupt Moderation */
329 INIT_DELAYED_WORK(&dev->eqd_work, ocrdma_eqd_set_task);
330 schedule_delayed_work(&dev->eqd_work, msecs_to_jiffies(1000));
Selvin Xaviera51f06e2014-02-04 11:57:07 +0530331
332 pr_info("%s %s: %s \"%s\" port %d\n",
333 dev_name(&dev->nic_info.pdev->dev), hca_name(dev),
334 port_speed_string(dev), dev->model_number,
335 dev->hba_port_num);
336 pr_info("%s ocrdma%d driver loaded successfully\n",
337 dev_name(&dev->nic_info.pdev->dev), dev->id);
Parav Panditfe2caef2012-03-21 04:09:06 +0530338 return dev;
339
Selvin Xavier334b8db2014-02-04 11:57:09 +0530340sysfs_err:
341 ocrdma_remove_sysfiles(dev);
Parav Panditfe2caef2012-03-21 04:09:06 +0530342alloc_err:
343 ocrdma_free_resources(dev);
344 ocrdma_cleanup_hw(dev);
345init_err:
346 idr_remove(&ocrdma_dev_id, dev->id);
347idr_err:
348 kfree(dev->mbx_cmd);
349 ib_dealloc_device(&dev->ibdev);
Naresh Gottumukkalaef99c4c2013-06-10 04:42:39 +0000350 pr_err("%s() leaving. ret=%d\n", __func__, status);
Parav Panditfe2caef2012-03-21 04:09:06 +0530351 return NULL;
352}
353
Selvin Xavier5a85f5e2015-10-20 14:17:56 +0530354static void ocrdma_remove_free(struct ocrdma_dev *dev)
Parav Panditfe2caef2012-03-21 04:09:06 +0530355{
Parav Panditfe2caef2012-03-21 04:09:06 +0530356
Parav Panditfe2caef2012-03-21 04:09:06 +0530357 idr_remove(&ocrdma_dev_id, dev->id);
358 kfree(dev->mbx_cmd);
359 ib_dealloc_device(&dev->ibdev);
360}
361
Sasha Levin3e4d60a2012-04-28 07:40:01 +0200362static void ocrdma_remove(struct ocrdma_dev *dev)
363{
364 /* first unregister with stack to stop all the active traffic
365 * of the registered clients.
366 */
Mitesh Ahujab4dbe8d2014-12-18 14:13:05 +0530367 cancel_delayed_work_sync(&dev->eqd_work);
Selvin Xavier334b8db2014-02-04 11:57:09 +0530368 ocrdma_remove_sysfiles(dev);
Sasha Levin3e4d60a2012-04-28 07:40:01 +0200369 ib_unregister_device(&dev->ibdev);
370
Mitesh Ahuja4b8180a2014-12-18 14:13:01 +0530371 ocrdma_rem_port_stats(dev);
Naresh Gottumukkala1852d1d2013-09-06 15:02:47 +0530372 ocrdma_free_resources(dev);
373 ocrdma_cleanup_hw(dev);
Selvin Xavier5a85f5e2015-10-20 14:17:56 +0530374 ocrdma_remove_free(dev);
Sasha Levin3e4d60a2012-04-28 07:40:01 +0200375}
376
Parav Panditfe2caef2012-03-21 04:09:06 +0530377static int ocrdma_open(struct ocrdma_dev *dev)
378{
379 struct ib_event port_event;
380
381 port_event.event = IB_EVENT_PORT_ACTIVE;
382 port_event.element.port_num = 1;
383 port_event.device = &dev->ibdev;
384 ib_dispatch_event(&port_event);
385 return 0;
386}
387
388static int ocrdma_close(struct ocrdma_dev *dev)
389{
390 int i;
391 struct ocrdma_qp *qp, **cur_qp;
392 struct ib_event err_event;
393 struct ib_qp_attr attrs;
394 int attr_mask = IB_QP_STATE;
395
396 attrs.qp_state = IB_QPS_ERR;
397 mutex_lock(&dev->dev_lock);
398 if (dev->qp_tbl) {
399 cur_qp = dev->qp_tbl;
400 for (i = 0; i < OCRDMA_MAX_QP; i++) {
401 qp = cur_qp[i];
Devesh Sharmafad51b72014-02-04 11:57:10 +0530402 if (qp && qp->ibqp.qp_type != IB_QPT_GSI) {
Parav Panditfe2caef2012-03-21 04:09:06 +0530403 /* change the QP state to ERROR */
404 _ocrdma_modify_qp(&qp->ibqp, &attrs, attr_mask);
405
406 err_event.event = IB_EVENT_QP_FATAL;
407 err_event.element.qp = &qp->ibqp;
408 err_event.device = &dev->ibdev;
409 ib_dispatch_event(&err_event);
410 }
411 }
412 }
413 mutex_unlock(&dev->dev_lock);
414
415 err_event.event = IB_EVENT_PORT_ERR;
416 err_event.element.port_num = 1;
417 err_event.device = &dev->ibdev;
418 ib_dispatch_event(&err_event);
419 return 0;
420}
421
Devesh Sharmaefe45932014-06-10 19:32:16 +0530422static void ocrdma_shutdown(struct ocrdma_dev *dev)
423{
424 ocrdma_close(dev);
425 ocrdma_remove(dev);
426}
427
Parav Panditfe2caef2012-03-21 04:09:06 +0530428/* event handling via NIC driver ensures that all the NIC specific
429 * initialization done before RoCE driver notifies
430 * event to stack.
431 */
432static void ocrdma_event_handler(struct ocrdma_dev *dev, u32 event)
433{
434 switch (event) {
435 case BE_DEV_UP:
436 ocrdma_open(dev);
437 break;
438 case BE_DEV_DOWN:
439 ocrdma_close(dev);
440 break;
Devesh Sharmaefe45932014-06-10 19:32:16 +0530441 case BE_DEV_SHUTDOWN:
442 ocrdma_shutdown(dev);
443 break;
Joe Perches2b50176d2013-10-08 16:07:22 -0700444 }
Parav Panditfe2caef2012-03-21 04:09:06 +0530445}
446
Roland Dreierabe3afa2012-04-16 11:36:29 -0700447static struct ocrdma_driver ocrdma_drv = {
Parav Panditfe2caef2012-03-21 04:09:06 +0530448 .name = "ocrdma_driver",
449 .add = ocrdma_add,
450 .remove = ocrdma_remove,
451 .state_change_handler = ocrdma_event_handler,
Devesh Sharmab6b87d22014-02-04 11:56:58 +0530452 .be_abi_version = OCRDMA_BE_ROCE_ABI_VERSION,
Parav Panditfe2caef2012-03-21 04:09:06 +0530453};
454
455static int __init ocrdma_init_module(void)
456{
457 int status;
458
Selvin Xaviera51f06e2014-02-04 11:57:07 +0530459 ocrdma_init_debugfs();
460
Parav Panditfe2caef2012-03-21 04:09:06 +0530461 status = be_roce_register_driver(&ocrdma_drv);
462 if (status)
Selvin Xavier2d8f57d2014-03-18 14:54:56 +0530463 goto err_be_reg;
Roland Dreier34955662012-05-02 15:42:33 -0700464
Selvin Xavier2d8f57d2014-03-18 14:54:56 +0530465 return 0;
466
467err_be_reg:
Somnath Koturcc369292015-07-30 18:33:31 +0300468
Parav Panditfe2caef2012-03-21 04:09:06 +0530469 return status;
470}
471
472static void __exit ocrdma_exit_module(void)
473{
474 be_roce_unregister_driver(&ocrdma_drv);
Selvin Xaviera51f06e2014-02-04 11:57:07 +0530475 ocrdma_rem_debugfs();
Johannes Thumshirnd8b2ba72015-07-08 17:23:00 +0200476 idr_destroy(&ocrdma_dev_id);
Parav Panditfe2caef2012-03-21 04:09:06 +0530477}
478
479module_init(ocrdma_init_module);
480module_exit(ocrdma_exit_module);