Devesh Sharma | 71ee673 | 2015-07-24 05:03:59 +0530 | [diff] [blame^] | 1 | /* 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 Pandit | fe2caef | 2012-03-21 04:09:06 +0530 | [diff] [blame] | 34 | * |
| 35 | * Contact Information: |
| 36 | * linux-drivers@emulex.com |
| 37 | * |
| 38 | * Emulex |
| 39 | * 3333 Susan Street |
| 40 | * Costa Mesa, CA 92626 |
Devesh Sharma | 71ee673 | 2015-07-24 05:03:59 +0530 | [diff] [blame^] | 41 | */ |
Parav Pandit | fe2caef | 2012-03-21 04:09:06 +0530 | [diff] [blame] | 42 | |
| 43 | #include <linux/module.h> |
Parav Pandit | fe2caef | 2012-03-21 04:09:06 +0530 | [diff] [blame] | 44 | #include <linux/idr.h> |
| 45 | #include <rdma/ib_verbs.h> |
| 46 | #include <rdma/ib_user_verbs.h> |
| 47 | #include <rdma/ib_addr.h> |
Ira Weiny | 337877a | 2015-06-06 14:38:29 -0400 | [diff] [blame] | 48 | #include <rdma/ib_mad.h> |
Parav Pandit | fe2caef | 2012-03-21 04:09:06 +0530 | [diff] [blame] | 49 | |
| 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 Xavier | a51f06e | 2014-02-04 11:57:07 +0530 | [diff] [blame] | 58 | #include "ocrdma_stats.h" |
Naresh Gottumukkala | 3875439 | 2013-08-26 15:27:49 +0530 | [diff] [blame] | 59 | #include "ocrdma_abi.h" |
Parav Pandit | fe2caef | 2012-03-21 04:09:06 +0530 | [diff] [blame] | 60 | |
Devesh Sharma | 0154410 | 2014-02-04 11:57:00 +0530 | [diff] [blame] | 61 | MODULE_VERSION(OCRDMA_ROCE_DRV_VERSION); |
| 62 | MODULE_DESCRIPTION(OCRDMA_ROCE_DRV_DESC " " OCRDMA_ROCE_DRV_VERSION); |
Parav Pandit | fe2caef | 2012-03-21 04:09:06 +0530 | [diff] [blame] | 63 | MODULE_AUTHOR("Emulex Corporation"); |
| 64 | MODULE_LICENSE("GPL"); |
| 65 | |
| 66 | static LIST_HEAD(ocrdma_dev_list); |
Sasha Levin | 3e4d60a | 2012-04-28 07:40:01 +0200 | [diff] [blame] | 67 | static DEFINE_SPINLOCK(ocrdma_devlist_lock); |
Parav Pandit | fe2caef | 2012-03-21 04:09:06 +0530 | [diff] [blame] | 68 | static DEFINE_IDR(ocrdma_dev_id); |
| 69 | |
| 70 | static union ib_gid ocrdma_zero_sgid; |
Parav Pandit | fe2caef | 2012-03-21 04:09:06 +0530 | [diff] [blame] | 71 | |
Parav Pandit | fe2caef | 2012-03-21 04:09:06 +0530 | [diff] [blame] | 72 | void ocrdma_get_guid(struct ocrdma_dev *dev, u8 *guid) |
| 73 | { |
| 74 | u8 mac_addr[6]; |
| 75 | |
| 76 | memcpy(&mac_addr[0], &dev->nic_info.mac_addr[0], ETH_ALEN); |
| 77 | guid[0] = mac_addr[0] ^ 2; |
| 78 | guid[1] = mac_addr[1]; |
| 79 | guid[2] = mac_addr[2]; |
| 80 | guid[3] = 0xff; |
| 81 | guid[4] = 0xfe; |
| 82 | guid[5] = mac_addr[3]; |
| 83 | guid[6] = mac_addr[4]; |
| 84 | guid[7] = mac_addr[5]; |
| 85 | } |
| 86 | |
Moni Shoua | 37721d8 | 2013-12-12 18:03:16 +0200 | [diff] [blame] | 87 | static bool ocrdma_add_sgid(struct ocrdma_dev *dev, union ib_gid *new_sgid) |
Parav Pandit | fe2caef | 2012-03-21 04:09:06 +0530 | [diff] [blame] | 88 | { |
| 89 | int i; |
Parav Pandit | fe2caef | 2012-03-21 04:09:06 +0530 | [diff] [blame] | 90 | unsigned long flags; |
| 91 | |
| 92 | memset(&ocrdma_zero_sgid, 0, sizeof(union ib_gid)); |
| 93 | |
Parav Pandit | fe2caef | 2012-03-21 04:09:06 +0530 | [diff] [blame] | 94 | |
| 95 | spin_lock_irqsave(&dev->sgid_lock, flags); |
| 96 | for (i = 0; i < OCRDMA_MAX_SGID; i++) { |
| 97 | if (!memcmp(&dev->sgid_tbl[i], &ocrdma_zero_sgid, |
| 98 | sizeof(union ib_gid))) { |
| 99 | /* found free entry */ |
Moni Shoua | 37721d8 | 2013-12-12 18:03:16 +0200 | [diff] [blame] | 100 | memcpy(&dev->sgid_tbl[i], new_sgid, |
Parav Pandit | 6ab6827 | 2012-06-08 21:25:25 +0530 | [diff] [blame] | 101 | sizeof(union ib_gid)); |
| 102 | spin_unlock_irqrestore(&dev->sgid_lock, flags); |
| 103 | return true; |
Moni Shoua | 37721d8 | 2013-12-12 18:03:16 +0200 | [diff] [blame] | 104 | } else if (!memcmp(&dev->sgid_tbl[i], new_sgid, |
Parav Pandit | fe2caef | 2012-03-21 04:09:06 +0530 | [diff] [blame] | 105 | sizeof(union ib_gid))) { |
| 106 | /* entry already present, no addition is required. */ |
| 107 | spin_unlock_irqrestore(&dev->sgid_lock, flags); |
Parav Pandit | 6ab6827 | 2012-06-08 21:25:25 +0530 | [diff] [blame] | 108 | return false; |
Parav Pandit | fe2caef | 2012-03-21 04:09:06 +0530 | [diff] [blame] | 109 | } |
| 110 | } |
Parav Pandit | fe2caef | 2012-03-21 04:09:06 +0530 | [diff] [blame] | 111 | spin_unlock_irqrestore(&dev->sgid_lock, flags); |
Parav Pandit | 6ab6827 | 2012-06-08 21:25:25 +0530 | [diff] [blame] | 112 | return false; |
Parav Pandit | fe2caef | 2012-03-21 04:09:06 +0530 | [diff] [blame] | 113 | } |
| 114 | |
Moni Shoua | 37721d8 | 2013-12-12 18:03:16 +0200 | [diff] [blame] | 115 | static bool ocrdma_del_sgid(struct ocrdma_dev *dev, union ib_gid *sgid) |
Parav Pandit | fe2caef | 2012-03-21 04:09:06 +0530 | [diff] [blame] | 116 | { |
| 117 | int found = false; |
| 118 | int i; |
Parav Pandit | fe2caef | 2012-03-21 04:09:06 +0530 | [diff] [blame] | 119 | unsigned long flags; |
| 120 | |
Parav Pandit | fe2caef | 2012-03-21 04:09:06 +0530 | [diff] [blame] | 121 | |
| 122 | spin_lock_irqsave(&dev->sgid_lock, flags); |
| 123 | /* first is default sgid, which cannot be deleted. */ |
| 124 | for (i = 1; i < OCRDMA_MAX_SGID; i++) { |
Moni Shoua | 37721d8 | 2013-12-12 18:03:16 +0200 | [diff] [blame] | 125 | if (!memcmp(&dev->sgid_tbl[i], sgid, sizeof(union ib_gid))) { |
Parav Pandit | fe2caef | 2012-03-21 04:09:06 +0530 | [diff] [blame] | 126 | /* found matching entry */ |
| 127 | memset(&dev->sgid_tbl[i], 0, sizeof(union ib_gid)); |
| 128 | found = true; |
| 129 | break; |
| 130 | } |
| 131 | } |
| 132 | spin_unlock_irqrestore(&dev->sgid_lock, flags); |
| 133 | return found; |
| 134 | } |
| 135 | |
Moni Shoua | 37721d8 | 2013-12-12 18:03:16 +0200 | [diff] [blame] | 136 | static int ocrdma_addr_event(unsigned long event, struct net_device *netdev, |
| 137 | union ib_gid *gid) |
Parav Pandit | fe2caef | 2012-03-21 04:09:06 +0530 | [diff] [blame] | 138 | { |
Parav Pandit | fe2caef | 2012-03-21 04:09:06 +0530 | [diff] [blame] | 139 | struct ib_event gid_event; |
| 140 | struct ocrdma_dev *dev; |
| 141 | bool found = false; |
Parav Pandit | 6ab6827 | 2012-06-08 21:25:25 +0530 | [diff] [blame] | 142 | bool updated = false; |
Parav Pandit | fe2caef | 2012-03-21 04:09:06 +0530 | [diff] [blame] | 143 | bool is_vlan = false; |
Parav Pandit | fe2caef | 2012-03-21 04:09:06 +0530 | [diff] [blame] | 144 | |
Roland Dreier | d549f55 | 2012-08-10 16:52:13 -0700 | [diff] [blame] | 145 | is_vlan = netdev->priv_flags & IFF_802_1Q_VLAN; |
Moni Shoua | 37721d8 | 2013-12-12 18:03:16 +0200 | [diff] [blame] | 146 | if (is_vlan) |
Devesh Sharma | 09de3f1 | 2014-02-04 12:10:48 +0530 | [diff] [blame] | 147 | netdev = rdma_vlan_dev_real_dev(netdev); |
Roland Dreier | d549f55 | 2012-08-10 16:52:13 -0700 | [diff] [blame] | 148 | |
Sasha Levin | 3e4d60a | 2012-04-28 07:40:01 +0200 | [diff] [blame] | 149 | rcu_read_lock(); |
| 150 | list_for_each_entry_rcu(dev, &ocrdma_dev_list, entry) { |
Parav Pandit | fe2caef | 2012-03-21 04:09:06 +0530 | [diff] [blame] | 151 | if (dev->nic_info.netdev == netdev) { |
| 152 | found = true; |
| 153 | break; |
| 154 | } |
| 155 | } |
Sasha Levin | 3e4d60a | 2012-04-28 07:40:01 +0200 | [diff] [blame] | 156 | rcu_read_unlock(); |
Parav Pandit | fe2caef | 2012-03-21 04:09:06 +0530 | [diff] [blame] | 157 | |
| 158 | if (!found) |
| 159 | return NOTIFY_DONE; |
Parav Pandit | fe2caef | 2012-03-21 04:09:06 +0530 | [diff] [blame] | 160 | |
| 161 | mutex_lock(&dev->dev_lock); |
| 162 | switch (event) { |
| 163 | case NETDEV_UP: |
Moni Shoua | 37721d8 | 2013-12-12 18:03:16 +0200 | [diff] [blame] | 164 | updated = ocrdma_add_sgid(dev, gid); |
Parav Pandit | fe2caef | 2012-03-21 04:09:06 +0530 | [diff] [blame] | 165 | break; |
| 166 | case NETDEV_DOWN: |
Moni Shoua | 37721d8 | 2013-12-12 18:03:16 +0200 | [diff] [blame] | 167 | updated = ocrdma_del_sgid(dev, gid); |
Parav Pandit | fe2caef | 2012-03-21 04:09:06 +0530 | [diff] [blame] | 168 | break; |
| 169 | default: |
| 170 | break; |
| 171 | } |
Parav Pandit | 6ab6827 | 2012-06-08 21:25:25 +0530 | [diff] [blame] | 172 | if (updated) { |
| 173 | /* GID table updated, notify the consumers about it */ |
| 174 | gid_event.device = &dev->ibdev; |
| 175 | gid_event.element.port_num = 1; |
| 176 | gid_event.event = IB_EVENT_GID_CHANGE; |
| 177 | ib_dispatch_event(&gid_event); |
| 178 | } |
Parav Pandit | fe2caef | 2012-03-21 04:09:06 +0530 | [diff] [blame] | 179 | mutex_unlock(&dev->dev_lock); |
| 180 | return NOTIFY_OK; |
| 181 | } |
| 182 | |
Moni Shoua | 37721d8 | 2013-12-12 18:03:16 +0200 | [diff] [blame] | 183 | static int ocrdma_inetaddr_event(struct notifier_block *notifier, |
| 184 | unsigned long event, void *ptr) |
| 185 | { |
| 186 | struct in_ifaddr *ifa = ptr; |
| 187 | union ib_gid gid; |
| 188 | struct net_device *netdev = ifa->ifa_dev->dev; |
| 189 | |
| 190 | ipv6_addr_set_v4mapped(ifa->ifa_address, (struct in6_addr *)&gid); |
| 191 | return ocrdma_addr_event(event, netdev, &gid); |
| 192 | } |
| 193 | |
Roland Dreier | 31ab8ac | 2014-01-19 15:13:44 -0800 | [diff] [blame] | 194 | static struct notifier_block ocrdma_inetaddr_notifier = { |
| 195 | .notifier_call = ocrdma_inetaddr_event |
| 196 | }; |
| 197 | |
Moni Shoua | 37721d8 | 2013-12-12 18:03:16 +0200 | [diff] [blame] | 198 | #if IS_ENABLED(CONFIG_IPV6) |
| 199 | |
| 200 | static int ocrdma_inet6addr_event(struct notifier_block *notifier, |
| 201 | unsigned long event, void *ptr) |
| 202 | { |
| 203 | struct inet6_ifaddr *ifa = (struct inet6_ifaddr *)ptr; |
| 204 | union ib_gid *gid = (union ib_gid *)&ifa->addr; |
| 205 | struct net_device *netdev = ifa->idev->dev; |
| 206 | return ocrdma_addr_event(event, netdev, gid); |
| 207 | } |
| 208 | |
Roland Dreier | 3495566 | 2012-05-02 15:42:33 -0700 | [diff] [blame] | 209 | static struct notifier_block ocrdma_inet6addr_notifier = { |
| 210 | .notifier_call = ocrdma_inet6addr_event |
| 211 | }; |
| 212 | |
Parav Pandit | 6ab6827 | 2012-06-08 21:25:25 +0530 | [diff] [blame] | 213 | #endif /* IPV6 and VLAN */ |
Roland Dreier | 3495566 | 2012-05-02 15:42:33 -0700 | [diff] [blame] | 214 | |
Parav Pandit | fe2caef | 2012-03-21 04:09:06 +0530 | [diff] [blame] | 215 | static enum rdma_link_layer ocrdma_link_layer(struct ib_device *device, |
| 216 | u8 port_num) |
| 217 | { |
| 218 | return IB_LINK_LAYER_ETHERNET; |
| 219 | } |
| 220 | |
Ira Weiny | 7738613 | 2015-05-13 20:02:58 -0400 | [diff] [blame] | 221 | static int ocrdma_port_immutable(struct ib_device *ibdev, u8 port_num, |
| 222 | struct ib_port_immutable *immutable) |
| 223 | { |
| 224 | struct ib_port_attr attr; |
| 225 | int err; |
| 226 | |
| 227 | err = ocrdma_query_port(ibdev, port_num, &attr); |
| 228 | if (err) |
| 229 | return err; |
| 230 | |
| 231 | immutable->pkey_tbl_len = attr.pkey_tbl_len; |
| 232 | immutable->gid_tbl_len = attr.gid_tbl_len; |
Ira Weiny | f9b22e3 | 2015-05-13 20:02:59 -0400 | [diff] [blame] | 233 | immutable->core_cap_flags = RDMA_CORE_PORT_IBA_ROCE; |
Ira Weiny | 337877a | 2015-06-06 14:38:29 -0400 | [diff] [blame] | 234 | immutable->max_mad_size = IB_MGMT_MAD_SIZE; |
Ira Weiny | 7738613 | 2015-05-13 20:02:58 -0400 | [diff] [blame] | 235 | |
| 236 | return 0; |
| 237 | } |
| 238 | |
Roland Dreier | abe3afa | 2012-04-16 11:36:29 -0700 | [diff] [blame] | 239 | static int ocrdma_register_device(struct ocrdma_dev *dev) |
Parav Pandit | fe2caef | 2012-03-21 04:09:06 +0530 | [diff] [blame] | 240 | { |
| 241 | strlcpy(dev->ibdev.name, "ocrdma%d", IB_DEVICE_NAME_MAX); |
| 242 | ocrdma_get_guid(dev, (u8 *)&dev->ibdev.node_guid); |
| 243 | memcpy(dev->ibdev.node_desc, OCRDMA_NODE_DESC, |
| 244 | sizeof(OCRDMA_NODE_DESC)); |
| 245 | dev->ibdev.owner = THIS_MODULE; |
Naresh Gottumukkala | 3875439 | 2013-08-26 15:27:49 +0530 | [diff] [blame] | 246 | dev->ibdev.uverbs_abi_ver = OCRDMA_ABI_VERSION; |
Parav Pandit | fe2caef | 2012-03-21 04:09:06 +0530 | [diff] [blame] | 247 | dev->ibdev.uverbs_cmd_mask = |
| 248 | OCRDMA_UVERBS(GET_CONTEXT) | |
| 249 | OCRDMA_UVERBS(QUERY_DEVICE) | |
| 250 | OCRDMA_UVERBS(QUERY_PORT) | |
| 251 | OCRDMA_UVERBS(ALLOC_PD) | |
| 252 | OCRDMA_UVERBS(DEALLOC_PD) | |
| 253 | OCRDMA_UVERBS(REG_MR) | |
| 254 | OCRDMA_UVERBS(DEREG_MR) | |
| 255 | OCRDMA_UVERBS(CREATE_COMP_CHANNEL) | |
| 256 | OCRDMA_UVERBS(CREATE_CQ) | |
| 257 | OCRDMA_UVERBS(RESIZE_CQ) | |
| 258 | OCRDMA_UVERBS(DESTROY_CQ) | |
| 259 | OCRDMA_UVERBS(REQ_NOTIFY_CQ) | |
| 260 | OCRDMA_UVERBS(CREATE_QP) | |
| 261 | OCRDMA_UVERBS(MODIFY_QP) | |
| 262 | OCRDMA_UVERBS(QUERY_QP) | |
| 263 | OCRDMA_UVERBS(DESTROY_QP) | |
| 264 | OCRDMA_UVERBS(POLL_CQ) | |
| 265 | OCRDMA_UVERBS(POST_SEND) | |
| 266 | OCRDMA_UVERBS(POST_RECV); |
| 267 | |
| 268 | dev->ibdev.uverbs_cmd_mask |= |
| 269 | OCRDMA_UVERBS(CREATE_AH) | |
| 270 | OCRDMA_UVERBS(MODIFY_AH) | |
| 271 | OCRDMA_UVERBS(QUERY_AH) | |
| 272 | OCRDMA_UVERBS(DESTROY_AH); |
| 273 | |
| 274 | dev->ibdev.node_type = RDMA_NODE_IB_CA; |
| 275 | dev->ibdev.phys_port_cnt = 1; |
Devesh Sharma | 0c0eacd | 2014-12-18 14:12:58 +0530 | [diff] [blame] | 276 | dev->ibdev.num_comp_vectors = dev->eq_cnt; |
Parav Pandit | fe2caef | 2012-03-21 04:09:06 +0530 | [diff] [blame] | 277 | |
| 278 | /* mandatory verbs. */ |
| 279 | dev->ibdev.query_device = ocrdma_query_device; |
| 280 | dev->ibdev.query_port = ocrdma_query_port; |
| 281 | dev->ibdev.modify_port = ocrdma_modify_port; |
| 282 | dev->ibdev.query_gid = ocrdma_query_gid; |
| 283 | dev->ibdev.get_link_layer = ocrdma_link_layer; |
| 284 | dev->ibdev.alloc_pd = ocrdma_alloc_pd; |
| 285 | dev->ibdev.dealloc_pd = ocrdma_dealloc_pd; |
| 286 | |
| 287 | dev->ibdev.create_cq = ocrdma_create_cq; |
| 288 | dev->ibdev.destroy_cq = ocrdma_destroy_cq; |
| 289 | dev->ibdev.resize_cq = ocrdma_resize_cq; |
| 290 | |
| 291 | dev->ibdev.create_qp = ocrdma_create_qp; |
| 292 | dev->ibdev.modify_qp = ocrdma_modify_qp; |
| 293 | dev->ibdev.query_qp = ocrdma_query_qp; |
| 294 | dev->ibdev.destroy_qp = ocrdma_destroy_qp; |
| 295 | |
| 296 | dev->ibdev.query_pkey = ocrdma_query_pkey; |
| 297 | dev->ibdev.create_ah = ocrdma_create_ah; |
| 298 | dev->ibdev.destroy_ah = ocrdma_destroy_ah; |
| 299 | dev->ibdev.query_ah = ocrdma_query_ah; |
| 300 | dev->ibdev.modify_ah = ocrdma_modify_ah; |
| 301 | |
| 302 | dev->ibdev.poll_cq = ocrdma_poll_cq; |
| 303 | dev->ibdev.post_send = ocrdma_post_send; |
| 304 | dev->ibdev.post_recv = ocrdma_post_recv; |
| 305 | dev->ibdev.req_notify_cq = ocrdma_arm_cq; |
| 306 | |
| 307 | dev->ibdev.get_dma_mr = ocrdma_get_dma_mr; |
Naresh Gottumukkala | cffce99 | 2013-08-26 15:27:44 +0530 | [diff] [blame] | 308 | dev->ibdev.reg_phys_mr = ocrdma_reg_kernel_mr; |
Parav Pandit | fe2caef | 2012-03-21 04:09:06 +0530 | [diff] [blame] | 309 | dev->ibdev.dereg_mr = ocrdma_dereg_mr; |
| 310 | dev->ibdev.reg_user_mr = ocrdma_reg_user_mr; |
| 311 | |
Naresh Gottumukkala | 7c33880 | 2013-08-26 15:27:39 +0530 | [diff] [blame] | 312 | dev->ibdev.alloc_fast_reg_mr = ocrdma_alloc_frmr; |
| 313 | dev->ibdev.alloc_fast_reg_page_list = ocrdma_alloc_frmr_page_list; |
| 314 | dev->ibdev.free_fast_reg_page_list = ocrdma_free_frmr_page_list; |
| 315 | |
Parav Pandit | fe2caef | 2012-03-21 04:09:06 +0530 | [diff] [blame] | 316 | /* mandatory to support user space verbs consumer. */ |
| 317 | dev->ibdev.alloc_ucontext = ocrdma_alloc_ucontext; |
| 318 | dev->ibdev.dealloc_ucontext = ocrdma_dealloc_ucontext; |
| 319 | dev->ibdev.mmap = ocrdma_mmap; |
| 320 | dev->ibdev.dma_device = &dev->nic_info.pdev->dev; |
| 321 | |
| 322 | dev->ibdev.process_mad = ocrdma_process_mad; |
Ira Weiny | 7738613 | 2015-05-13 20:02:58 -0400 | [diff] [blame] | 323 | dev->ibdev.get_port_immutable = ocrdma_port_immutable; |
Parav Pandit | fe2caef | 2012-03-21 04:09:06 +0530 | [diff] [blame] | 324 | |
Devesh Sharma | 21c3391 | 2014-02-04 11:56:56 +0530 | [diff] [blame] | 325 | if (ocrdma_get_asic_type(dev) == OCRDMA_ASIC_GEN_SKH_R) { |
Parav Pandit | fe2caef | 2012-03-21 04:09:06 +0530 | [diff] [blame] | 326 | dev->ibdev.uverbs_cmd_mask |= |
| 327 | OCRDMA_UVERBS(CREATE_SRQ) | |
| 328 | OCRDMA_UVERBS(MODIFY_SRQ) | |
| 329 | OCRDMA_UVERBS(QUERY_SRQ) | |
| 330 | OCRDMA_UVERBS(DESTROY_SRQ) | |
| 331 | OCRDMA_UVERBS(POST_SRQ_RECV); |
| 332 | |
| 333 | dev->ibdev.create_srq = ocrdma_create_srq; |
| 334 | dev->ibdev.modify_srq = ocrdma_modify_srq; |
| 335 | dev->ibdev.query_srq = ocrdma_query_srq; |
| 336 | dev->ibdev.destroy_srq = ocrdma_destroy_srq; |
| 337 | dev->ibdev.post_srq_recv = ocrdma_post_srq_recv; |
| 338 | } |
| 339 | return ib_register_device(&dev->ibdev, NULL); |
| 340 | } |
| 341 | |
| 342 | static int ocrdma_alloc_resources(struct ocrdma_dev *dev) |
| 343 | { |
| 344 | mutex_init(&dev->dev_lock); |
| 345 | dev->sgid_tbl = kzalloc(sizeof(union ib_gid) * |
| 346 | OCRDMA_MAX_SGID, GFP_KERNEL); |
| 347 | if (!dev->sgid_tbl) |
| 348 | goto alloc_err; |
| 349 | spin_lock_init(&dev->sgid_lock); |
| 350 | |
| 351 | dev->cq_tbl = kzalloc(sizeof(struct ocrdma_cq *) * |
| 352 | OCRDMA_MAX_CQ, GFP_KERNEL); |
| 353 | if (!dev->cq_tbl) |
| 354 | goto alloc_err; |
| 355 | |
| 356 | if (dev->attr.max_qp) { |
| 357 | dev->qp_tbl = kzalloc(sizeof(struct ocrdma_qp *) * |
| 358 | OCRDMA_MAX_QP, GFP_KERNEL); |
| 359 | if (!dev->qp_tbl) |
| 360 | goto alloc_err; |
| 361 | } |
Selvin Xavier | 4f1df84 | 2014-06-10 19:32:24 +0530 | [diff] [blame] | 362 | |
| 363 | dev->stag_arr = kzalloc(sizeof(u64) * OCRDMA_MAX_STAG, GFP_KERNEL); |
| 364 | if (dev->stag_arr == NULL) |
| 365 | goto alloc_err; |
| 366 | |
Mitesh Ahuja | 9ba1377 | 2014-12-18 14:12:57 +0530 | [diff] [blame] | 367 | ocrdma_alloc_pd_pool(dev); |
| 368 | |
Parav Pandit | fe2caef | 2012-03-21 04:09:06 +0530 | [diff] [blame] | 369 | spin_lock_init(&dev->av_tbl.lock); |
| 370 | spin_lock_init(&dev->flush_q_lock); |
| 371 | return 0; |
| 372 | alloc_err: |
Naresh Gottumukkala | ef99c4c | 2013-06-10 04:42:39 +0000 | [diff] [blame] | 373 | pr_err("%s(%d) error.\n", __func__, dev->id); |
Parav Pandit | fe2caef | 2012-03-21 04:09:06 +0530 | [diff] [blame] | 374 | return -ENOMEM; |
| 375 | } |
| 376 | |
| 377 | static void ocrdma_free_resources(struct ocrdma_dev *dev) |
| 378 | { |
Selvin Xavier | 4f1df84 | 2014-06-10 19:32:24 +0530 | [diff] [blame] | 379 | kfree(dev->stag_arr); |
Parav Pandit | fe2caef | 2012-03-21 04:09:06 +0530 | [diff] [blame] | 380 | kfree(dev->qp_tbl); |
| 381 | kfree(dev->cq_tbl); |
| 382 | kfree(dev->sgid_tbl); |
| 383 | } |
| 384 | |
Selvin Xavier | 334b8db | 2014-02-04 11:57:09 +0530 | [diff] [blame] | 385 | /* OCRDMA sysfs interface */ |
| 386 | static ssize_t show_rev(struct device *device, struct device_attribute *attr, |
| 387 | char *buf) |
| 388 | { |
| 389 | struct ocrdma_dev *dev = dev_get_drvdata(device); |
| 390 | |
| 391 | return scnprintf(buf, PAGE_SIZE, "0x%x\n", dev->nic_info.pdev->vendor); |
| 392 | } |
| 393 | |
| 394 | static ssize_t show_fw_ver(struct device *device, struct device_attribute *attr, |
| 395 | char *buf) |
| 396 | { |
| 397 | struct ocrdma_dev *dev = dev_get_drvdata(device); |
| 398 | |
Selvin Xavier | 4808b18 | 2014-06-10 19:32:14 +0530 | [diff] [blame] | 399 | return scnprintf(buf, PAGE_SIZE, "%s\n", &dev->attr.fw_ver[0]); |
| 400 | } |
| 401 | |
| 402 | static ssize_t show_hca_type(struct device *device, |
| 403 | struct device_attribute *attr, char *buf) |
| 404 | { |
| 405 | struct ocrdma_dev *dev = dev_get_drvdata(device); |
| 406 | |
| 407 | return scnprintf(buf, PAGE_SIZE, "%s\n", &dev->model_number[0]); |
Selvin Xavier | 334b8db | 2014-02-04 11:57:09 +0530 | [diff] [blame] | 408 | } |
| 409 | |
| 410 | static DEVICE_ATTR(hw_rev, S_IRUGO, show_rev, NULL); |
| 411 | static DEVICE_ATTR(fw_ver, S_IRUGO, show_fw_ver, NULL); |
Selvin Xavier | 4808b18 | 2014-06-10 19:32:14 +0530 | [diff] [blame] | 412 | static DEVICE_ATTR(hca_type, S_IRUGO, show_hca_type, NULL); |
Selvin Xavier | 334b8db | 2014-02-04 11:57:09 +0530 | [diff] [blame] | 413 | |
| 414 | static struct device_attribute *ocrdma_attributes[] = { |
| 415 | &dev_attr_hw_rev, |
Selvin Xavier | 4808b18 | 2014-06-10 19:32:14 +0530 | [diff] [blame] | 416 | &dev_attr_fw_ver, |
| 417 | &dev_attr_hca_type |
Selvin Xavier | 334b8db | 2014-02-04 11:57:09 +0530 | [diff] [blame] | 418 | }; |
| 419 | |
| 420 | static void ocrdma_remove_sysfiles(struct ocrdma_dev *dev) |
| 421 | { |
| 422 | int i; |
| 423 | |
| 424 | for (i = 0; i < ARRAY_SIZE(ocrdma_attributes); i++) |
| 425 | device_remove_file(&dev->ibdev.dev, ocrdma_attributes[i]); |
| 426 | } |
| 427 | |
Devesh Sharma | 7ec11e0 | 2014-08-22 16:57:19 +0530 | [diff] [blame] | 428 | static void ocrdma_add_default_sgid(struct ocrdma_dev *dev) |
| 429 | { |
| 430 | /* GID Index 0 - Invariant manufacturer-assigned EUI-64 */ |
| 431 | union ib_gid *sgid = &dev->sgid_tbl[0]; |
| 432 | |
| 433 | sgid->global.subnet_prefix = cpu_to_be64(0xfe80000000000000LL); |
| 434 | ocrdma_get_guid(dev, &sgid->raw[8]); |
| 435 | } |
| 436 | |
Selvin Xavier | b880632 | 2014-06-10 19:32:25 +0530 | [diff] [blame] | 437 | static void ocrdma_init_ipv4_gids(struct ocrdma_dev *dev, |
| 438 | struct net_device *net) |
| 439 | { |
| 440 | struct in_device *in_dev; |
| 441 | union ib_gid gid; |
| 442 | in_dev = in_dev_get(net); |
| 443 | if (in_dev) { |
| 444 | for_ifa(in_dev) { |
| 445 | ipv6_addr_set_v4mapped(ifa->ifa_address, |
| 446 | (struct in6_addr *)&gid); |
| 447 | ocrdma_add_sgid(dev, &gid); |
| 448 | } |
| 449 | endfor_ifa(in_dev); |
| 450 | in_dev_put(in_dev); |
| 451 | } |
| 452 | } |
| 453 | |
| 454 | static void ocrdma_init_ipv6_gids(struct ocrdma_dev *dev, |
| 455 | struct net_device *net) |
| 456 | { |
| 457 | #if IS_ENABLED(CONFIG_IPV6) |
| 458 | struct inet6_dev *in6_dev; |
| 459 | union ib_gid *pgid; |
| 460 | struct inet6_ifaddr *ifp; |
| 461 | in6_dev = in6_dev_get(net); |
| 462 | if (in6_dev) { |
| 463 | read_lock_bh(&in6_dev->lock); |
| 464 | list_for_each_entry(ifp, &in6_dev->addr_list, if_list) { |
| 465 | pgid = (union ib_gid *)&ifp->addr; |
| 466 | ocrdma_add_sgid(dev, pgid); |
| 467 | } |
| 468 | read_unlock_bh(&in6_dev->lock); |
| 469 | in6_dev_put(in6_dev); |
| 470 | } |
| 471 | #endif |
| 472 | } |
| 473 | |
| 474 | static void ocrdma_init_gid_table(struct ocrdma_dev *dev) |
| 475 | { |
| 476 | struct net_device *net_dev; |
| 477 | |
| 478 | for_each_netdev(&init_net, net_dev) { |
| 479 | struct net_device *real_dev = rdma_vlan_dev_real_dev(net_dev) ? |
| 480 | rdma_vlan_dev_real_dev(net_dev) : net_dev; |
| 481 | |
| 482 | if (real_dev == dev->nic_info.netdev) { |
Devesh Sharma | 7ec11e0 | 2014-08-22 16:57:19 +0530 | [diff] [blame] | 483 | ocrdma_add_default_sgid(dev); |
Selvin Xavier | b880632 | 2014-06-10 19:32:25 +0530 | [diff] [blame] | 484 | ocrdma_init_ipv4_gids(dev, net_dev); |
| 485 | ocrdma_init_ipv6_gids(dev, net_dev); |
| 486 | } |
| 487 | } |
| 488 | } |
| 489 | |
Parav Pandit | fe2caef | 2012-03-21 04:09:06 +0530 | [diff] [blame] | 490 | static struct ocrdma_dev *ocrdma_add(struct be_dev_info *dev_info) |
| 491 | { |
Selvin Xavier | 334b8db | 2014-02-04 11:57:09 +0530 | [diff] [blame] | 492 | int status = 0, i; |
Parav Pandit | fe2caef | 2012-03-21 04:09:06 +0530 | [diff] [blame] | 493 | struct ocrdma_dev *dev; |
| 494 | |
| 495 | dev = (struct ocrdma_dev *)ib_alloc_device(sizeof(struct ocrdma_dev)); |
| 496 | if (!dev) { |
Naresh Gottumukkala | ef99c4c | 2013-06-10 04:42:39 +0000 | [diff] [blame] | 497 | pr_err("Unable to allocate ib device\n"); |
Parav Pandit | fe2caef | 2012-03-21 04:09:06 +0530 | [diff] [blame] | 498 | return NULL; |
| 499 | } |
| 500 | dev->mbx_cmd = kzalloc(sizeof(struct ocrdma_mqe_emb_cmd), GFP_KERNEL); |
| 501 | if (!dev->mbx_cmd) |
| 502 | goto idr_err; |
| 503 | |
| 504 | memcpy(&dev->nic_info, dev_info, sizeof(*dev_info)); |
Tejun Heo | cffcd59 | 2013-02-27 17:04:24 -0800 | [diff] [blame] | 505 | dev->id = idr_alloc(&ocrdma_dev_id, NULL, 0, 0, GFP_KERNEL); |
Parav Pandit | fe2caef | 2012-03-21 04:09:06 +0530 | [diff] [blame] | 506 | if (dev->id < 0) |
| 507 | goto idr_err; |
| 508 | |
| 509 | status = ocrdma_init_hw(dev); |
| 510 | if (status) |
| 511 | goto init_err; |
| 512 | |
| 513 | status = ocrdma_alloc_resources(dev); |
| 514 | if (status) |
| 515 | goto alloc_err; |
| 516 | |
Selvin Xavier | 31dbdd9 | 2014-06-10 19:32:13 +0530 | [diff] [blame] | 517 | ocrdma_init_service_level(dev); |
Selvin Xavier | b880632 | 2014-06-10 19:32:25 +0530 | [diff] [blame] | 518 | ocrdma_init_gid_table(dev); |
Parav Pandit | fe2caef | 2012-03-21 04:09:06 +0530 | [diff] [blame] | 519 | status = ocrdma_register_device(dev); |
| 520 | if (status) |
| 521 | goto alloc_err; |
| 522 | |
Selvin Xavier | 334b8db | 2014-02-04 11:57:09 +0530 | [diff] [blame] | 523 | for (i = 0; i < ARRAY_SIZE(ocrdma_attributes); i++) |
| 524 | if (device_create_file(&dev->ibdev.dev, ocrdma_attributes[i])) |
| 525 | goto sysfs_err; |
Sasha Levin | 3e4d60a | 2012-04-28 07:40:01 +0200 | [diff] [blame] | 526 | spin_lock(&ocrdma_devlist_lock); |
| 527 | list_add_tail_rcu(&dev->entry, &ocrdma_dev_list); |
| 528 | spin_unlock(&ocrdma_devlist_lock); |
Selvin Xavier | a51f06e | 2014-02-04 11:57:07 +0530 | [diff] [blame] | 529 | /* Init stats */ |
| 530 | ocrdma_add_port_stats(dev); |
Mitesh Ahuja | b4dbe8d | 2014-12-18 14:13:05 +0530 | [diff] [blame] | 531 | /* Interrupt Moderation */ |
| 532 | INIT_DELAYED_WORK(&dev->eqd_work, ocrdma_eqd_set_task); |
| 533 | schedule_delayed_work(&dev->eqd_work, msecs_to_jiffies(1000)); |
Selvin Xavier | a51f06e | 2014-02-04 11:57:07 +0530 | [diff] [blame] | 534 | |
| 535 | pr_info("%s %s: %s \"%s\" port %d\n", |
| 536 | dev_name(&dev->nic_info.pdev->dev), hca_name(dev), |
| 537 | port_speed_string(dev), dev->model_number, |
| 538 | dev->hba_port_num); |
| 539 | pr_info("%s ocrdma%d driver loaded successfully\n", |
| 540 | dev_name(&dev->nic_info.pdev->dev), dev->id); |
Parav Pandit | fe2caef | 2012-03-21 04:09:06 +0530 | [diff] [blame] | 541 | return dev; |
| 542 | |
Selvin Xavier | 334b8db | 2014-02-04 11:57:09 +0530 | [diff] [blame] | 543 | sysfs_err: |
| 544 | ocrdma_remove_sysfiles(dev); |
Parav Pandit | fe2caef | 2012-03-21 04:09:06 +0530 | [diff] [blame] | 545 | alloc_err: |
| 546 | ocrdma_free_resources(dev); |
| 547 | ocrdma_cleanup_hw(dev); |
| 548 | init_err: |
| 549 | idr_remove(&ocrdma_dev_id, dev->id); |
| 550 | idr_err: |
| 551 | kfree(dev->mbx_cmd); |
| 552 | ib_dealloc_device(&dev->ibdev); |
Naresh Gottumukkala | ef99c4c | 2013-06-10 04:42:39 +0000 | [diff] [blame] | 553 | pr_err("%s() leaving. ret=%d\n", __func__, status); |
Parav Pandit | fe2caef | 2012-03-21 04:09:06 +0530 | [diff] [blame] | 554 | return NULL; |
| 555 | } |
| 556 | |
Sasha Levin | 3e4d60a | 2012-04-28 07:40:01 +0200 | [diff] [blame] | 557 | static void ocrdma_remove_free(struct rcu_head *rcu) |
Parav Pandit | fe2caef | 2012-03-21 04:09:06 +0530 | [diff] [blame] | 558 | { |
Sasha Levin | 3e4d60a | 2012-04-28 07:40:01 +0200 | [diff] [blame] | 559 | struct ocrdma_dev *dev = container_of(rcu, struct ocrdma_dev, rcu); |
Parav Pandit | fe2caef | 2012-03-21 04:09:06 +0530 | [diff] [blame] | 560 | |
Parav Pandit | fe2caef | 2012-03-21 04:09:06 +0530 | [diff] [blame] | 561 | idr_remove(&ocrdma_dev_id, dev->id); |
| 562 | kfree(dev->mbx_cmd); |
| 563 | ib_dealloc_device(&dev->ibdev); |
| 564 | } |
| 565 | |
Sasha Levin | 3e4d60a | 2012-04-28 07:40:01 +0200 | [diff] [blame] | 566 | static void ocrdma_remove(struct ocrdma_dev *dev) |
| 567 | { |
| 568 | /* first unregister with stack to stop all the active traffic |
| 569 | * of the registered clients. |
| 570 | */ |
Mitesh Ahuja | b4dbe8d | 2014-12-18 14:13:05 +0530 | [diff] [blame] | 571 | cancel_delayed_work_sync(&dev->eqd_work); |
Selvin Xavier | 334b8db | 2014-02-04 11:57:09 +0530 | [diff] [blame] | 572 | ocrdma_remove_sysfiles(dev); |
Sasha Levin | 3e4d60a | 2012-04-28 07:40:01 +0200 | [diff] [blame] | 573 | ib_unregister_device(&dev->ibdev); |
| 574 | |
Mitesh Ahuja | 4b8180a | 2014-12-18 14:13:01 +0530 | [diff] [blame] | 575 | ocrdma_rem_port_stats(dev); |
| 576 | |
Sasha Levin | 3e4d60a | 2012-04-28 07:40:01 +0200 | [diff] [blame] | 577 | spin_lock(&ocrdma_devlist_lock); |
| 578 | list_del_rcu(&dev->entry); |
| 579 | spin_unlock(&ocrdma_devlist_lock); |
Naresh Gottumukkala | 1852d1d | 2013-09-06 15:02:47 +0530 | [diff] [blame] | 580 | |
| 581 | ocrdma_free_resources(dev); |
| 582 | ocrdma_cleanup_hw(dev); |
| 583 | |
Sasha Levin | 3e4d60a | 2012-04-28 07:40:01 +0200 | [diff] [blame] | 584 | call_rcu(&dev->rcu, ocrdma_remove_free); |
| 585 | } |
| 586 | |
Parav Pandit | fe2caef | 2012-03-21 04:09:06 +0530 | [diff] [blame] | 587 | static int ocrdma_open(struct ocrdma_dev *dev) |
| 588 | { |
| 589 | struct ib_event port_event; |
| 590 | |
| 591 | port_event.event = IB_EVENT_PORT_ACTIVE; |
| 592 | port_event.element.port_num = 1; |
| 593 | port_event.device = &dev->ibdev; |
| 594 | ib_dispatch_event(&port_event); |
| 595 | return 0; |
| 596 | } |
| 597 | |
| 598 | static int ocrdma_close(struct ocrdma_dev *dev) |
| 599 | { |
| 600 | int i; |
| 601 | struct ocrdma_qp *qp, **cur_qp; |
| 602 | struct ib_event err_event; |
| 603 | struct ib_qp_attr attrs; |
| 604 | int attr_mask = IB_QP_STATE; |
| 605 | |
| 606 | attrs.qp_state = IB_QPS_ERR; |
| 607 | mutex_lock(&dev->dev_lock); |
| 608 | if (dev->qp_tbl) { |
| 609 | cur_qp = dev->qp_tbl; |
| 610 | for (i = 0; i < OCRDMA_MAX_QP; i++) { |
| 611 | qp = cur_qp[i]; |
Devesh Sharma | fad51b7 | 2014-02-04 11:57:10 +0530 | [diff] [blame] | 612 | if (qp && qp->ibqp.qp_type != IB_QPT_GSI) { |
Parav Pandit | fe2caef | 2012-03-21 04:09:06 +0530 | [diff] [blame] | 613 | /* change the QP state to ERROR */ |
| 614 | _ocrdma_modify_qp(&qp->ibqp, &attrs, attr_mask); |
| 615 | |
| 616 | err_event.event = IB_EVENT_QP_FATAL; |
| 617 | err_event.element.qp = &qp->ibqp; |
| 618 | err_event.device = &dev->ibdev; |
| 619 | ib_dispatch_event(&err_event); |
| 620 | } |
| 621 | } |
| 622 | } |
| 623 | mutex_unlock(&dev->dev_lock); |
| 624 | |
| 625 | err_event.event = IB_EVENT_PORT_ERR; |
| 626 | err_event.element.port_num = 1; |
| 627 | err_event.device = &dev->ibdev; |
| 628 | ib_dispatch_event(&err_event); |
| 629 | return 0; |
| 630 | } |
| 631 | |
Devesh Sharma | efe4593 | 2014-06-10 19:32:16 +0530 | [diff] [blame] | 632 | static void ocrdma_shutdown(struct ocrdma_dev *dev) |
| 633 | { |
| 634 | ocrdma_close(dev); |
| 635 | ocrdma_remove(dev); |
| 636 | } |
| 637 | |
Parav Pandit | fe2caef | 2012-03-21 04:09:06 +0530 | [diff] [blame] | 638 | /* event handling via NIC driver ensures that all the NIC specific |
| 639 | * initialization done before RoCE driver notifies |
| 640 | * event to stack. |
| 641 | */ |
| 642 | static void ocrdma_event_handler(struct ocrdma_dev *dev, u32 event) |
| 643 | { |
| 644 | switch (event) { |
| 645 | case BE_DEV_UP: |
| 646 | ocrdma_open(dev); |
| 647 | break; |
| 648 | case BE_DEV_DOWN: |
| 649 | ocrdma_close(dev); |
| 650 | break; |
Devesh Sharma | efe4593 | 2014-06-10 19:32:16 +0530 | [diff] [blame] | 651 | case BE_DEV_SHUTDOWN: |
| 652 | ocrdma_shutdown(dev); |
| 653 | break; |
Joe Perches | 2b50176d | 2013-10-08 16:07:22 -0700 | [diff] [blame] | 654 | } |
Parav Pandit | fe2caef | 2012-03-21 04:09:06 +0530 | [diff] [blame] | 655 | } |
| 656 | |
Roland Dreier | abe3afa | 2012-04-16 11:36:29 -0700 | [diff] [blame] | 657 | static struct ocrdma_driver ocrdma_drv = { |
Parav Pandit | fe2caef | 2012-03-21 04:09:06 +0530 | [diff] [blame] | 658 | .name = "ocrdma_driver", |
| 659 | .add = ocrdma_add, |
| 660 | .remove = ocrdma_remove, |
| 661 | .state_change_handler = ocrdma_event_handler, |
Devesh Sharma | b6b87d2 | 2014-02-04 11:56:58 +0530 | [diff] [blame] | 662 | .be_abi_version = OCRDMA_BE_ROCE_ABI_VERSION, |
Parav Pandit | fe2caef | 2012-03-21 04:09:06 +0530 | [diff] [blame] | 663 | }; |
| 664 | |
Roland Dreier | 3495566 | 2012-05-02 15:42:33 -0700 | [diff] [blame] | 665 | static void ocrdma_unregister_inet6addr_notifier(void) |
| 666 | { |
Roland Dreier | d90f9b3 | 2012-07-05 22:39:34 -0700 | [diff] [blame] | 667 | #if IS_ENABLED(CONFIG_IPV6) |
Roland Dreier | 3495566 | 2012-05-02 15:42:33 -0700 | [diff] [blame] | 668 | unregister_inet6addr_notifier(&ocrdma_inet6addr_notifier); |
| 669 | #endif |
| 670 | } |
| 671 | |
Selvin Xavier | 2d8f57d | 2014-03-18 14:54:56 +0530 | [diff] [blame] | 672 | static void ocrdma_unregister_inetaddr_notifier(void) |
| 673 | { |
| 674 | unregister_inetaddr_notifier(&ocrdma_inetaddr_notifier); |
| 675 | } |
| 676 | |
Parav Pandit | fe2caef | 2012-03-21 04:09:06 +0530 | [diff] [blame] | 677 | static int __init ocrdma_init_module(void) |
| 678 | { |
| 679 | int status; |
| 680 | |
Selvin Xavier | a51f06e | 2014-02-04 11:57:07 +0530 | [diff] [blame] | 681 | ocrdma_init_debugfs(); |
| 682 | |
Moni Shoua | 37721d8 | 2013-12-12 18:03:16 +0200 | [diff] [blame] | 683 | status = register_inetaddr_notifier(&ocrdma_inetaddr_notifier); |
| 684 | if (status) |
| 685 | return status; |
| 686 | |
Roland Dreier | d90f9b3 | 2012-07-05 22:39:34 -0700 | [diff] [blame] | 687 | #if IS_ENABLED(CONFIG_IPV6) |
Parav Pandit | fe2caef | 2012-03-21 04:09:06 +0530 | [diff] [blame] | 688 | status = register_inet6addr_notifier(&ocrdma_inet6addr_notifier); |
| 689 | if (status) |
Selvin Xavier | 2d8f57d | 2014-03-18 14:54:56 +0530 | [diff] [blame] | 690 | goto err_notifier6; |
Roland Dreier | 3495566 | 2012-05-02 15:42:33 -0700 | [diff] [blame] | 691 | #endif |
| 692 | |
Parav Pandit | fe2caef | 2012-03-21 04:09:06 +0530 | [diff] [blame] | 693 | status = be_roce_register_driver(&ocrdma_drv); |
| 694 | if (status) |
Selvin Xavier | 2d8f57d | 2014-03-18 14:54:56 +0530 | [diff] [blame] | 695 | goto err_be_reg; |
Roland Dreier | 3495566 | 2012-05-02 15:42:33 -0700 | [diff] [blame] | 696 | |
Selvin Xavier | 2d8f57d | 2014-03-18 14:54:56 +0530 | [diff] [blame] | 697 | return 0; |
| 698 | |
| 699 | err_be_reg: |
Li RongQing | e5dc940 | 2014-09-29 14:59:43 +0800 | [diff] [blame] | 700 | #if IS_ENABLED(CONFIG_IPV6) |
Selvin Xavier | 2d8f57d | 2014-03-18 14:54:56 +0530 | [diff] [blame] | 701 | ocrdma_unregister_inet6addr_notifier(); |
| 702 | err_notifier6: |
Li RongQing | e5dc940 | 2014-09-29 14:59:43 +0800 | [diff] [blame] | 703 | #endif |
Selvin Xavier | 2d8f57d | 2014-03-18 14:54:56 +0530 | [diff] [blame] | 704 | ocrdma_unregister_inetaddr_notifier(); |
Parav Pandit | fe2caef | 2012-03-21 04:09:06 +0530 | [diff] [blame] | 705 | return status; |
| 706 | } |
| 707 | |
| 708 | static void __exit ocrdma_exit_module(void) |
| 709 | { |
| 710 | be_roce_unregister_driver(&ocrdma_drv); |
Roland Dreier | 3495566 | 2012-05-02 15:42:33 -0700 | [diff] [blame] | 711 | ocrdma_unregister_inet6addr_notifier(); |
Selvin Xavier | 2d8f57d | 2014-03-18 14:54:56 +0530 | [diff] [blame] | 712 | ocrdma_unregister_inetaddr_notifier(); |
Selvin Xavier | a51f06e | 2014-02-04 11:57:07 +0530 | [diff] [blame] | 713 | ocrdma_rem_debugfs(); |
Johannes Thumshirn | d8b2ba7 | 2015-07-08 17:23:00 +0200 | [diff] [blame] | 714 | idr_destroy(&ocrdma_dev_id); |
Parav Pandit | fe2caef | 2012-03-21 04:09:06 +0530 | [diff] [blame] | 715 | } |
| 716 | |
| 717 | module_init(ocrdma_init_module); |
| 718 | module_exit(ocrdma_exit_module); |