2015-07-24 07:33:59 +08:00
|
|
|
/* This file is part of the Emulex RoCE Device Driver for
|
|
|
|
* RoCE (RDMA over Converged Ethernet) adapters.
|
|
|
|
* Copyright (C) 2012-2015 Emulex. All rights reserved.
|
|
|
|
* EMULEX and SLI are trademarks of Emulex.
|
|
|
|
* www.emulex.com
|
|
|
|
*
|
|
|
|
* This software is available to you under a choice of one of two licenses.
|
|
|
|
* You may choose to be licensed under the terms of the GNU General Public
|
|
|
|
* License (GPL) Version 2, available from the file COPYING in the main
|
|
|
|
* directory of this source tree, or the BSD license below:
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
*
|
|
|
|
* - Redistributions of source code must retain the above copyright notice,
|
|
|
|
* this list of conditions and the following disclaimer.
|
|
|
|
*
|
|
|
|
* - Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in
|
|
|
|
* the documentation and/or other materials provided with the distribution.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
|
|
|
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,THE
|
|
|
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
|
|
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
|
|
|
|
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
|
|
|
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
|
|
|
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
|
|
|
|
* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
|
|
|
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
|
|
|
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
|
|
|
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
2012-03-21 06:39:06 +08:00
|
|
|
*
|
|
|
|
* Contact Information:
|
|
|
|
* linux-drivers@emulex.com
|
|
|
|
*
|
|
|
|
* Emulex
|
|
|
|
* 3333 Susan Street
|
|
|
|
* Costa Mesa, CA 92626
|
2015-07-24 07:33:59 +08:00
|
|
|
*/
|
2012-03-21 06:39:06 +08:00
|
|
|
|
|
|
|
#include <linux/module.h>
|
|
|
|
#include <linux/idr.h>
|
|
|
|
#include <rdma/ib_verbs.h>
|
|
|
|
#include <rdma/ib_user_verbs.h>
|
|
|
|
#include <rdma/ib_addr.h>
|
2015-06-07 02:38:29 +08:00
|
|
|
#include <rdma/ib_mad.h>
|
2012-03-21 06:39:06 +08:00
|
|
|
|
|
|
|
#include <linux/netdevice.h>
|
|
|
|
#include <net/addrconf.h>
|
|
|
|
|
|
|
|
#include "ocrdma.h"
|
|
|
|
#include "ocrdma_verbs.h"
|
|
|
|
#include "ocrdma_ah.h"
|
|
|
|
#include "be_roce.h"
|
|
|
|
#include "ocrdma_hw.h"
|
2014-02-04 14:27:07 +08:00
|
|
|
#include "ocrdma_stats.h"
|
2013-08-26 17:57:49 +08:00
|
|
|
#include "ocrdma_abi.h"
|
2012-03-21 06:39:06 +08:00
|
|
|
|
2014-02-04 14:27:00 +08:00
|
|
|
MODULE_VERSION(OCRDMA_ROCE_DRV_VERSION);
|
|
|
|
MODULE_DESCRIPTION(OCRDMA_ROCE_DRV_DESC " " OCRDMA_ROCE_DRV_VERSION);
|
2012-03-21 06:39:06 +08:00
|
|
|
MODULE_AUTHOR("Emulex Corporation");
|
2015-07-24 07:34:00 +08:00
|
|
|
MODULE_LICENSE("Dual BSD/GPL");
|
2012-03-21 06:39:06 +08:00
|
|
|
|
|
|
|
static LIST_HEAD(ocrdma_dev_list);
|
2012-04-28 13:40:01 +08:00
|
|
|
static DEFINE_SPINLOCK(ocrdma_devlist_lock);
|
2012-03-21 06:39:06 +08:00
|
|
|
static DEFINE_IDR(ocrdma_dev_id);
|
|
|
|
|
|
|
|
static union ib_gid ocrdma_zero_sgid;
|
|
|
|
|
|
|
|
void ocrdma_get_guid(struct ocrdma_dev *dev, u8 *guid)
|
|
|
|
{
|
|
|
|
u8 mac_addr[6];
|
|
|
|
|
|
|
|
memcpy(&mac_addr[0], &dev->nic_info.mac_addr[0], ETH_ALEN);
|
|
|
|
guid[0] = mac_addr[0] ^ 2;
|
|
|
|
guid[1] = mac_addr[1];
|
|
|
|
guid[2] = mac_addr[2];
|
|
|
|
guid[3] = 0xff;
|
|
|
|
guid[4] = 0xfe;
|
|
|
|
guid[5] = mac_addr[3];
|
|
|
|
guid[6] = mac_addr[4];
|
|
|
|
guid[7] = mac_addr[5];
|
|
|
|
}
|
|
|
|
|
2013-12-13 00:03:16 +08:00
|
|
|
static bool ocrdma_add_sgid(struct ocrdma_dev *dev, union ib_gid *new_sgid)
|
2012-03-21 06:39:06 +08:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
unsigned long flags;
|
|
|
|
|
|
|
|
memset(&ocrdma_zero_sgid, 0, sizeof(union ib_gid));
|
|
|
|
|
|
|
|
|
|
|
|
spin_lock_irqsave(&dev->sgid_lock, flags);
|
|
|
|
for (i = 0; i < OCRDMA_MAX_SGID; i++) {
|
|
|
|
if (!memcmp(&dev->sgid_tbl[i], &ocrdma_zero_sgid,
|
|
|
|
sizeof(union ib_gid))) {
|
|
|
|
/* found free entry */
|
2013-12-13 00:03:16 +08:00
|
|
|
memcpy(&dev->sgid_tbl[i], new_sgid,
|
2012-06-08 23:55:25 +08:00
|
|
|
sizeof(union ib_gid));
|
|
|
|
spin_unlock_irqrestore(&dev->sgid_lock, flags);
|
|
|
|
return true;
|
2013-12-13 00:03:16 +08:00
|
|
|
} else if (!memcmp(&dev->sgid_tbl[i], new_sgid,
|
2012-03-21 06:39:06 +08:00
|
|
|
sizeof(union ib_gid))) {
|
|
|
|
/* entry already present, no addition is required. */
|
|
|
|
spin_unlock_irqrestore(&dev->sgid_lock, flags);
|
2012-06-08 23:55:25 +08:00
|
|
|
return false;
|
2012-03-21 06:39:06 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
spin_unlock_irqrestore(&dev->sgid_lock, flags);
|
2012-06-08 23:55:25 +08:00
|
|
|
return false;
|
2012-03-21 06:39:06 +08:00
|
|
|
}
|
|
|
|
|
2013-12-13 00:03:16 +08:00
|
|
|
static bool ocrdma_del_sgid(struct ocrdma_dev *dev, union ib_gid *sgid)
|
2012-03-21 06:39:06 +08:00
|
|
|
{
|
|
|
|
int found = false;
|
|
|
|
int i;
|
|
|
|
unsigned long flags;
|
|
|
|
|
|
|
|
|
|
|
|
spin_lock_irqsave(&dev->sgid_lock, flags);
|
|
|
|
/* first is default sgid, which cannot be deleted. */
|
|
|
|
for (i = 1; i < OCRDMA_MAX_SGID; i++) {
|
2013-12-13 00:03:16 +08:00
|
|
|
if (!memcmp(&dev->sgid_tbl[i], sgid, sizeof(union ib_gid))) {
|
2012-03-21 06:39:06 +08:00
|
|
|
/* found matching entry */
|
|
|
|
memset(&dev->sgid_tbl[i], 0, sizeof(union ib_gid));
|
|
|
|
found = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
spin_unlock_irqrestore(&dev->sgid_lock, flags);
|
|
|
|
return found;
|
|
|
|
}
|
|
|
|
|
2013-12-13 00:03:16 +08:00
|
|
|
static int ocrdma_addr_event(unsigned long event, struct net_device *netdev,
|
|
|
|
union ib_gid *gid)
|
2012-06-08 23:55:25 +08:00
|
|
|
{
|
2012-03-21 06:39:06 +08:00
|
|
|
struct ib_event gid_event;
|
|
|
|
struct ocrdma_dev *dev;
|
|
|
|
bool found = false;
|
2012-06-08 23:55:25 +08:00
|
|
|
bool updated = false;
|
2012-03-21 06:39:06 +08:00
|
|
|
bool is_vlan = false;
|
|
|
|
|
2012-08-11 07:52:13 +08:00
|
|
|
is_vlan = netdev->priv_flags & IFF_802_1Q_VLAN;
|
2013-12-13 00:03:16 +08:00
|
|
|
if (is_vlan)
|
2014-02-04 14:40:48 +08:00
|
|
|
netdev = rdma_vlan_dev_real_dev(netdev);
|
2012-08-11 07:52:13 +08:00
|
|
|
|
2012-04-28 13:40:01 +08:00
|
|
|
rcu_read_lock();
|
|
|
|
list_for_each_entry_rcu(dev, &ocrdma_dev_list, entry) {
|
2012-03-21 06:39:06 +08:00
|
|
|
if (dev->nic_info.netdev == netdev) {
|
|
|
|
found = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2012-04-28 13:40:01 +08:00
|
|
|
rcu_read_unlock();
|
2012-03-21 06:39:06 +08:00
|
|
|
|
|
|
|
if (!found)
|
|
|
|
return NOTIFY_DONE;
|
|
|
|
|
|
|
|
mutex_lock(&dev->dev_lock);
|
|
|
|
switch (event) {
|
|
|
|
case NETDEV_UP:
|
2013-12-13 00:03:16 +08:00
|
|
|
updated = ocrdma_add_sgid(dev, gid);
|
2012-03-21 06:39:06 +08:00
|
|
|
break;
|
|
|
|
case NETDEV_DOWN:
|
2013-12-13 00:03:16 +08:00
|
|
|
updated = ocrdma_del_sgid(dev, gid);
|
2012-03-21 06:39:06 +08:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
2012-06-08 23:55:25 +08:00
|
|
|
if (updated) {
|
|
|
|
/* GID table updated, notify the consumers about it */
|
|
|
|
gid_event.device = &dev->ibdev;
|
|
|
|
gid_event.element.port_num = 1;
|
|
|
|
gid_event.event = IB_EVENT_GID_CHANGE;
|
|
|
|
ib_dispatch_event(&gid_event);
|
|
|
|
}
|
2012-03-21 06:39:06 +08:00
|
|
|
mutex_unlock(&dev->dev_lock);
|
|
|
|
return NOTIFY_OK;
|
|
|
|
}
|
|
|
|
|
2013-12-13 00:03:16 +08:00
|
|
|
static int ocrdma_inetaddr_event(struct notifier_block *notifier,
|
|
|
|
unsigned long event, void *ptr)
|
|
|
|
{
|
|
|
|
struct in_ifaddr *ifa = ptr;
|
|
|
|
union ib_gid gid;
|
|
|
|
struct net_device *netdev = ifa->ifa_dev->dev;
|
|
|
|
|
|
|
|
ipv6_addr_set_v4mapped(ifa->ifa_address, (struct in6_addr *)&gid);
|
|
|
|
return ocrdma_addr_event(event, netdev, &gid);
|
|
|
|
}
|
|
|
|
|
2014-01-20 07:13:44 +08:00
|
|
|
static struct notifier_block ocrdma_inetaddr_notifier = {
|
|
|
|
.notifier_call = ocrdma_inetaddr_event
|
|
|
|
};
|
|
|
|
|
2013-12-13 00:03:16 +08:00
|
|
|
#if IS_ENABLED(CONFIG_IPV6)
|
|
|
|
|
|
|
|
static int ocrdma_inet6addr_event(struct notifier_block *notifier,
|
|
|
|
unsigned long event, void *ptr)
|
|
|
|
{
|
|
|
|
struct inet6_ifaddr *ifa = (struct inet6_ifaddr *)ptr;
|
|
|
|
union ib_gid *gid = (union ib_gid *)&ifa->addr;
|
|
|
|
struct net_device *netdev = ifa->idev->dev;
|
|
|
|
return ocrdma_addr_event(event, netdev, gid);
|
|
|
|
}
|
|
|
|
|
2012-05-03 06:42:33 +08:00
|
|
|
static struct notifier_block ocrdma_inet6addr_notifier = {
|
|
|
|
.notifier_call = ocrdma_inet6addr_event
|
|
|
|
};
|
|
|
|
|
2012-06-08 23:55:25 +08:00
|
|
|
#endif /* IPV6 and VLAN */
|
2012-05-03 06:42:33 +08:00
|
|
|
|
2012-03-21 06:39:06 +08:00
|
|
|
static enum rdma_link_layer ocrdma_link_layer(struct ib_device *device,
|
|
|
|
u8 port_num)
|
|
|
|
{
|
|
|
|
return IB_LINK_LAYER_ETHERNET;
|
|
|
|
}
|
|
|
|
|
2015-05-14 08:02:58 +08:00
|
|
|
static int ocrdma_port_immutable(struct ib_device *ibdev, u8 port_num,
|
|
|
|
struct ib_port_immutable *immutable)
|
|
|
|
{
|
|
|
|
struct ib_port_attr attr;
|
|
|
|
int err;
|
|
|
|
|
|
|
|
err = ocrdma_query_port(ibdev, port_num, &attr);
|
|
|
|
if (err)
|
|
|
|
return err;
|
|
|
|
|
|
|
|
immutable->pkey_tbl_len = attr.pkey_tbl_len;
|
|
|
|
immutable->gid_tbl_len = attr.gid_tbl_len;
|
2015-05-14 08:02:59 +08:00
|
|
|
immutable->core_cap_flags = RDMA_CORE_PORT_IBA_ROCE;
|
2015-06-07 02:38:29 +08:00
|
|
|
immutable->max_mad_size = IB_MGMT_MAD_SIZE;
|
2015-05-14 08:02:58 +08:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2012-04-17 02:36:29 +08:00
|
|
|
static int ocrdma_register_device(struct ocrdma_dev *dev)
|
2012-03-21 06:39:06 +08:00
|
|
|
{
|
|
|
|
strlcpy(dev->ibdev.name, "ocrdma%d", IB_DEVICE_NAME_MAX);
|
|
|
|
ocrdma_get_guid(dev, (u8 *)&dev->ibdev.node_guid);
|
|
|
|
memcpy(dev->ibdev.node_desc, OCRDMA_NODE_DESC,
|
|
|
|
sizeof(OCRDMA_NODE_DESC));
|
|
|
|
dev->ibdev.owner = THIS_MODULE;
|
2013-08-26 17:57:49 +08:00
|
|
|
dev->ibdev.uverbs_abi_ver = OCRDMA_ABI_VERSION;
|
2012-03-21 06:39:06 +08:00
|
|
|
dev->ibdev.uverbs_cmd_mask =
|
|
|
|
OCRDMA_UVERBS(GET_CONTEXT) |
|
|
|
|
OCRDMA_UVERBS(QUERY_DEVICE) |
|
|
|
|
OCRDMA_UVERBS(QUERY_PORT) |
|
|
|
|
OCRDMA_UVERBS(ALLOC_PD) |
|
|
|
|
OCRDMA_UVERBS(DEALLOC_PD) |
|
|
|
|
OCRDMA_UVERBS(REG_MR) |
|
|
|
|
OCRDMA_UVERBS(DEREG_MR) |
|
|
|
|
OCRDMA_UVERBS(CREATE_COMP_CHANNEL) |
|
|
|
|
OCRDMA_UVERBS(CREATE_CQ) |
|
|
|
|
OCRDMA_UVERBS(RESIZE_CQ) |
|
|
|
|
OCRDMA_UVERBS(DESTROY_CQ) |
|
|
|
|
OCRDMA_UVERBS(REQ_NOTIFY_CQ) |
|
|
|
|
OCRDMA_UVERBS(CREATE_QP) |
|
|
|
|
OCRDMA_UVERBS(MODIFY_QP) |
|
|
|
|
OCRDMA_UVERBS(QUERY_QP) |
|
|
|
|
OCRDMA_UVERBS(DESTROY_QP) |
|
|
|
|
OCRDMA_UVERBS(POLL_CQ) |
|
|
|
|
OCRDMA_UVERBS(POST_SEND) |
|
|
|
|
OCRDMA_UVERBS(POST_RECV);
|
|
|
|
|
|
|
|
dev->ibdev.uverbs_cmd_mask |=
|
|
|
|
OCRDMA_UVERBS(CREATE_AH) |
|
|
|
|
OCRDMA_UVERBS(MODIFY_AH) |
|
|
|
|
OCRDMA_UVERBS(QUERY_AH) |
|
|
|
|
OCRDMA_UVERBS(DESTROY_AH);
|
|
|
|
|
|
|
|
dev->ibdev.node_type = RDMA_NODE_IB_CA;
|
|
|
|
dev->ibdev.phys_port_cnt = 1;
|
2014-12-18 16:42:58 +08:00
|
|
|
dev->ibdev.num_comp_vectors = dev->eq_cnt;
|
2012-03-21 06:39:06 +08:00
|
|
|
|
|
|
|
/* mandatory verbs. */
|
|
|
|
dev->ibdev.query_device = ocrdma_query_device;
|
|
|
|
dev->ibdev.query_port = ocrdma_query_port;
|
|
|
|
dev->ibdev.modify_port = ocrdma_modify_port;
|
|
|
|
dev->ibdev.query_gid = ocrdma_query_gid;
|
|
|
|
dev->ibdev.get_link_layer = ocrdma_link_layer;
|
|
|
|
dev->ibdev.alloc_pd = ocrdma_alloc_pd;
|
|
|
|
dev->ibdev.dealloc_pd = ocrdma_dealloc_pd;
|
|
|
|
|
|
|
|
dev->ibdev.create_cq = ocrdma_create_cq;
|
|
|
|
dev->ibdev.destroy_cq = ocrdma_destroy_cq;
|
|
|
|
dev->ibdev.resize_cq = ocrdma_resize_cq;
|
|
|
|
|
|
|
|
dev->ibdev.create_qp = ocrdma_create_qp;
|
|
|
|
dev->ibdev.modify_qp = ocrdma_modify_qp;
|
|
|
|
dev->ibdev.query_qp = ocrdma_query_qp;
|
|
|
|
dev->ibdev.destroy_qp = ocrdma_destroy_qp;
|
|
|
|
|
|
|
|
dev->ibdev.query_pkey = ocrdma_query_pkey;
|
|
|
|
dev->ibdev.create_ah = ocrdma_create_ah;
|
|
|
|
dev->ibdev.destroy_ah = ocrdma_destroy_ah;
|
|
|
|
dev->ibdev.query_ah = ocrdma_query_ah;
|
|
|
|
dev->ibdev.modify_ah = ocrdma_modify_ah;
|
|
|
|
|
|
|
|
dev->ibdev.poll_cq = ocrdma_poll_cq;
|
|
|
|
dev->ibdev.post_send = ocrdma_post_send;
|
|
|
|
dev->ibdev.post_recv = ocrdma_post_recv;
|
|
|
|
dev->ibdev.req_notify_cq = ocrdma_arm_cq;
|
|
|
|
|
|
|
|
dev->ibdev.get_dma_mr = ocrdma_get_dma_mr;
|
2013-08-26 17:57:44 +08:00
|
|
|
dev->ibdev.reg_phys_mr = ocrdma_reg_kernel_mr;
|
2012-03-21 06:39:06 +08:00
|
|
|
dev->ibdev.dereg_mr = ocrdma_dereg_mr;
|
|
|
|
dev->ibdev.reg_user_mr = ocrdma_reg_user_mr;
|
|
|
|
|
2013-08-26 17:57:39 +08:00
|
|
|
dev->ibdev.alloc_fast_reg_mr = ocrdma_alloc_frmr;
|
|
|
|
dev->ibdev.alloc_fast_reg_page_list = ocrdma_alloc_frmr_page_list;
|
|
|
|
dev->ibdev.free_fast_reg_page_list = ocrdma_free_frmr_page_list;
|
|
|
|
|
2012-03-21 06:39:06 +08:00
|
|
|
/* mandatory to support user space verbs consumer. */
|
|
|
|
dev->ibdev.alloc_ucontext = ocrdma_alloc_ucontext;
|
|
|
|
dev->ibdev.dealloc_ucontext = ocrdma_dealloc_ucontext;
|
|
|
|
dev->ibdev.mmap = ocrdma_mmap;
|
|
|
|
dev->ibdev.dma_device = &dev->nic_info.pdev->dev;
|
|
|
|
|
|
|
|
dev->ibdev.process_mad = ocrdma_process_mad;
|
2015-05-14 08:02:58 +08:00
|
|
|
dev->ibdev.get_port_immutable = ocrdma_port_immutable;
|
2012-03-21 06:39:06 +08:00
|
|
|
|
2014-02-04 14:26:56 +08:00
|
|
|
if (ocrdma_get_asic_type(dev) == OCRDMA_ASIC_GEN_SKH_R) {
|
2012-03-21 06:39:06 +08:00
|
|
|
dev->ibdev.uverbs_cmd_mask |=
|
|
|
|
OCRDMA_UVERBS(CREATE_SRQ) |
|
|
|
|
OCRDMA_UVERBS(MODIFY_SRQ) |
|
|
|
|
OCRDMA_UVERBS(QUERY_SRQ) |
|
|
|
|
OCRDMA_UVERBS(DESTROY_SRQ) |
|
|
|
|
OCRDMA_UVERBS(POST_SRQ_RECV);
|
|
|
|
|
|
|
|
dev->ibdev.create_srq = ocrdma_create_srq;
|
|
|
|
dev->ibdev.modify_srq = ocrdma_modify_srq;
|
|
|
|
dev->ibdev.query_srq = ocrdma_query_srq;
|
|
|
|
dev->ibdev.destroy_srq = ocrdma_destroy_srq;
|
|
|
|
dev->ibdev.post_srq_recv = ocrdma_post_srq_recv;
|
|
|
|
}
|
|
|
|
return ib_register_device(&dev->ibdev, NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int ocrdma_alloc_resources(struct ocrdma_dev *dev)
|
|
|
|
{
|
|
|
|
mutex_init(&dev->dev_lock);
|
|
|
|
dev->sgid_tbl = kzalloc(sizeof(union ib_gid) *
|
|
|
|
OCRDMA_MAX_SGID, GFP_KERNEL);
|
|
|
|
if (!dev->sgid_tbl)
|
|
|
|
goto alloc_err;
|
|
|
|
spin_lock_init(&dev->sgid_lock);
|
|
|
|
|
|
|
|
dev->cq_tbl = kzalloc(sizeof(struct ocrdma_cq *) *
|
|
|
|
OCRDMA_MAX_CQ, GFP_KERNEL);
|
|
|
|
if (!dev->cq_tbl)
|
|
|
|
goto alloc_err;
|
|
|
|
|
|
|
|
if (dev->attr.max_qp) {
|
|
|
|
dev->qp_tbl = kzalloc(sizeof(struct ocrdma_qp *) *
|
|
|
|
OCRDMA_MAX_QP, GFP_KERNEL);
|
|
|
|
if (!dev->qp_tbl)
|
|
|
|
goto alloc_err;
|
|
|
|
}
|
2014-06-10 22:02:24 +08:00
|
|
|
|
|
|
|
dev->stag_arr = kzalloc(sizeof(u64) * OCRDMA_MAX_STAG, GFP_KERNEL);
|
|
|
|
if (dev->stag_arr == NULL)
|
|
|
|
goto alloc_err;
|
|
|
|
|
2014-12-18 16:42:57 +08:00
|
|
|
ocrdma_alloc_pd_pool(dev);
|
|
|
|
|
2012-03-21 06:39:06 +08:00
|
|
|
spin_lock_init(&dev->av_tbl.lock);
|
|
|
|
spin_lock_init(&dev->flush_q_lock);
|
|
|
|
return 0;
|
|
|
|
alloc_err:
|
2013-06-10 12:42:39 +08:00
|
|
|
pr_err("%s(%d) error.\n", __func__, dev->id);
|
2012-03-21 06:39:06 +08:00
|
|
|
return -ENOMEM;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void ocrdma_free_resources(struct ocrdma_dev *dev)
|
|
|
|
{
|
2014-06-10 22:02:24 +08:00
|
|
|
kfree(dev->stag_arr);
|
2012-03-21 06:39:06 +08:00
|
|
|
kfree(dev->qp_tbl);
|
|
|
|
kfree(dev->cq_tbl);
|
|
|
|
kfree(dev->sgid_tbl);
|
|
|
|
}
|
|
|
|
|
2014-02-04 14:27:09 +08:00
|
|
|
/* OCRDMA sysfs interface */
|
|
|
|
static ssize_t show_rev(struct device *device, struct device_attribute *attr,
|
|
|
|
char *buf)
|
|
|
|
{
|
|
|
|
struct ocrdma_dev *dev = dev_get_drvdata(device);
|
|
|
|
|
|
|
|
return scnprintf(buf, PAGE_SIZE, "0x%x\n", dev->nic_info.pdev->vendor);
|
|
|
|
}
|
|
|
|
|
|
|
|
static ssize_t show_fw_ver(struct device *device, struct device_attribute *attr,
|
|
|
|
char *buf)
|
|
|
|
{
|
|
|
|
struct ocrdma_dev *dev = dev_get_drvdata(device);
|
|
|
|
|
2014-06-10 22:02:14 +08:00
|
|
|
return scnprintf(buf, PAGE_SIZE, "%s\n", &dev->attr.fw_ver[0]);
|
|
|
|
}
|
|
|
|
|
|
|
|
static ssize_t show_hca_type(struct device *device,
|
|
|
|
struct device_attribute *attr, char *buf)
|
|
|
|
{
|
|
|
|
struct ocrdma_dev *dev = dev_get_drvdata(device);
|
|
|
|
|
|
|
|
return scnprintf(buf, PAGE_SIZE, "%s\n", &dev->model_number[0]);
|
2014-02-04 14:27:09 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static DEVICE_ATTR(hw_rev, S_IRUGO, show_rev, NULL);
|
|
|
|
static DEVICE_ATTR(fw_ver, S_IRUGO, show_fw_ver, NULL);
|
2014-06-10 22:02:14 +08:00
|
|
|
static DEVICE_ATTR(hca_type, S_IRUGO, show_hca_type, NULL);
|
2014-02-04 14:27:09 +08:00
|
|
|
|
|
|
|
static struct device_attribute *ocrdma_attributes[] = {
|
|
|
|
&dev_attr_hw_rev,
|
2014-06-10 22:02:14 +08:00
|
|
|
&dev_attr_fw_ver,
|
|
|
|
&dev_attr_hca_type
|
2014-02-04 14:27:09 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
static void ocrdma_remove_sysfiles(struct ocrdma_dev *dev)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i = 0; i < ARRAY_SIZE(ocrdma_attributes); i++)
|
|
|
|
device_remove_file(&dev->ibdev.dev, ocrdma_attributes[i]);
|
|
|
|
}
|
|
|
|
|
2014-08-22 19:27:19 +08:00
|
|
|
static void ocrdma_add_default_sgid(struct ocrdma_dev *dev)
|
|
|
|
{
|
|
|
|
/* GID Index 0 - Invariant manufacturer-assigned EUI-64 */
|
|
|
|
union ib_gid *sgid = &dev->sgid_tbl[0];
|
|
|
|
|
|
|
|
sgid->global.subnet_prefix = cpu_to_be64(0xfe80000000000000LL);
|
|
|
|
ocrdma_get_guid(dev, &sgid->raw[8]);
|
|
|
|
}
|
|
|
|
|
2014-06-10 22:02:25 +08:00
|
|
|
static void ocrdma_init_ipv4_gids(struct ocrdma_dev *dev,
|
|
|
|
struct net_device *net)
|
|
|
|
{
|
|
|
|
struct in_device *in_dev;
|
|
|
|
union ib_gid gid;
|
|
|
|
in_dev = in_dev_get(net);
|
|
|
|
if (in_dev) {
|
|
|
|
for_ifa(in_dev) {
|
|
|
|
ipv6_addr_set_v4mapped(ifa->ifa_address,
|
|
|
|
(struct in6_addr *)&gid);
|
|
|
|
ocrdma_add_sgid(dev, &gid);
|
|
|
|
}
|
|
|
|
endfor_ifa(in_dev);
|
|
|
|
in_dev_put(in_dev);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void ocrdma_init_ipv6_gids(struct ocrdma_dev *dev,
|
|
|
|
struct net_device *net)
|
|
|
|
{
|
|
|
|
#if IS_ENABLED(CONFIG_IPV6)
|
|
|
|
struct inet6_dev *in6_dev;
|
|
|
|
union ib_gid *pgid;
|
|
|
|
struct inet6_ifaddr *ifp;
|
|
|
|
in6_dev = in6_dev_get(net);
|
|
|
|
if (in6_dev) {
|
|
|
|
read_lock_bh(&in6_dev->lock);
|
|
|
|
list_for_each_entry(ifp, &in6_dev->addr_list, if_list) {
|
|
|
|
pgid = (union ib_gid *)&ifp->addr;
|
|
|
|
ocrdma_add_sgid(dev, pgid);
|
|
|
|
}
|
|
|
|
read_unlock_bh(&in6_dev->lock);
|
|
|
|
in6_dev_put(in6_dev);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
static void ocrdma_init_gid_table(struct ocrdma_dev *dev)
|
|
|
|
{
|
|
|
|
struct net_device *net_dev;
|
|
|
|
|
|
|
|
for_each_netdev(&init_net, net_dev) {
|
|
|
|
struct net_device *real_dev = rdma_vlan_dev_real_dev(net_dev) ?
|
|
|
|
rdma_vlan_dev_real_dev(net_dev) : net_dev;
|
|
|
|
|
|
|
|
if (real_dev == dev->nic_info.netdev) {
|
2014-08-22 19:27:19 +08:00
|
|
|
ocrdma_add_default_sgid(dev);
|
2014-06-10 22:02:25 +08:00
|
|
|
ocrdma_init_ipv4_gids(dev, net_dev);
|
|
|
|
ocrdma_init_ipv6_gids(dev, net_dev);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-03-21 06:39:06 +08:00
|
|
|
static struct ocrdma_dev *ocrdma_add(struct be_dev_info *dev_info)
|
|
|
|
{
|
2014-02-04 14:27:09 +08:00
|
|
|
int status = 0, i;
|
2012-03-21 06:39:06 +08:00
|
|
|
struct ocrdma_dev *dev;
|
|
|
|
|
|
|
|
dev = (struct ocrdma_dev *)ib_alloc_device(sizeof(struct ocrdma_dev));
|
|
|
|
if (!dev) {
|
2013-06-10 12:42:39 +08:00
|
|
|
pr_err("Unable to allocate ib device\n");
|
2012-03-21 06:39:06 +08:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
dev->mbx_cmd = kzalloc(sizeof(struct ocrdma_mqe_emb_cmd), GFP_KERNEL);
|
|
|
|
if (!dev->mbx_cmd)
|
|
|
|
goto idr_err;
|
|
|
|
|
|
|
|
memcpy(&dev->nic_info, dev_info, sizeof(*dev_info));
|
2013-02-28 09:04:24 +08:00
|
|
|
dev->id = idr_alloc(&ocrdma_dev_id, NULL, 0, 0, GFP_KERNEL);
|
2012-03-21 06:39:06 +08:00
|
|
|
if (dev->id < 0)
|
|
|
|
goto idr_err;
|
|
|
|
|
|
|
|
status = ocrdma_init_hw(dev);
|
|
|
|
if (status)
|
|
|
|
goto init_err;
|
|
|
|
|
|
|
|
status = ocrdma_alloc_resources(dev);
|
|
|
|
if (status)
|
|
|
|
goto alloc_err;
|
|
|
|
|
2014-06-10 22:02:13 +08:00
|
|
|
ocrdma_init_service_level(dev);
|
2014-06-10 22:02:25 +08:00
|
|
|
ocrdma_init_gid_table(dev);
|
2012-03-21 06:39:06 +08:00
|
|
|
status = ocrdma_register_device(dev);
|
|
|
|
if (status)
|
|
|
|
goto alloc_err;
|
|
|
|
|
2014-02-04 14:27:09 +08:00
|
|
|
for (i = 0; i < ARRAY_SIZE(ocrdma_attributes); i++)
|
|
|
|
if (device_create_file(&dev->ibdev.dev, ocrdma_attributes[i]))
|
|
|
|
goto sysfs_err;
|
2012-04-28 13:40:01 +08:00
|
|
|
spin_lock(&ocrdma_devlist_lock);
|
|
|
|
list_add_tail_rcu(&dev->entry, &ocrdma_dev_list);
|
|
|
|
spin_unlock(&ocrdma_devlist_lock);
|
2014-02-04 14:27:07 +08:00
|
|
|
/* Init stats */
|
|
|
|
ocrdma_add_port_stats(dev);
|
2014-12-18 16:43:05 +08:00
|
|
|
/* Interrupt Moderation */
|
|
|
|
INIT_DELAYED_WORK(&dev->eqd_work, ocrdma_eqd_set_task);
|
|
|
|
schedule_delayed_work(&dev->eqd_work, msecs_to_jiffies(1000));
|
2014-02-04 14:27:07 +08:00
|
|
|
|
|
|
|
pr_info("%s %s: %s \"%s\" port %d\n",
|
|
|
|
dev_name(&dev->nic_info.pdev->dev), hca_name(dev),
|
|
|
|
port_speed_string(dev), dev->model_number,
|
|
|
|
dev->hba_port_num);
|
|
|
|
pr_info("%s ocrdma%d driver loaded successfully\n",
|
|
|
|
dev_name(&dev->nic_info.pdev->dev), dev->id);
|
2012-03-21 06:39:06 +08:00
|
|
|
return dev;
|
|
|
|
|
2014-02-04 14:27:09 +08:00
|
|
|
sysfs_err:
|
|
|
|
ocrdma_remove_sysfiles(dev);
|
2012-03-21 06:39:06 +08:00
|
|
|
alloc_err:
|
|
|
|
ocrdma_free_resources(dev);
|
|
|
|
ocrdma_cleanup_hw(dev);
|
|
|
|
init_err:
|
|
|
|
idr_remove(&ocrdma_dev_id, dev->id);
|
|
|
|
idr_err:
|
|
|
|
kfree(dev->mbx_cmd);
|
|
|
|
ib_dealloc_device(&dev->ibdev);
|
2013-06-10 12:42:39 +08:00
|
|
|
pr_err("%s() leaving. ret=%d\n", __func__, status);
|
2012-03-21 06:39:06 +08:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2012-04-28 13:40:01 +08:00
|
|
|
static void ocrdma_remove_free(struct rcu_head *rcu)
|
2012-03-21 06:39:06 +08:00
|
|
|
{
|
2012-04-28 13:40:01 +08:00
|
|
|
struct ocrdma_dev *dev = container_of(rcu, struct ocrdma_dev, rcu);
|
2012-03-21 06:39:06 +08:00
|
|
|
|
|
|
|
idr_remove(&ocrdma_dev_id, dev->id);
|
|
|
|
kfree(dev->mbx_cmd);
|
|
|
|
ib_dealloc_device(&dev->ibdev);
|
|
|
|
}
|
|
|
|
|
2012-04-28 13:40:01 +08:00
|
|
|
static void ocrdma_remove(struct ocrdma_dev *dev)
|
|
|
|
{
|
|
|
|
/* first unregister with stack to stop all the active traffic
|
|
|
|
* of the registered clients.
|
|
|
|
*/
|
2014-12-18 16:43:05 +08:00
|
|
|
cancel_delayed_work_sync(&dev->eqd_work);
|
2014-02-04 14:27:09 +08:00
|
|
|
ocrdma_remove_sysfiles(dev);
|
2012-04-28 13:40:01 +08:00
|
|
|
ib_unregister_device(&dev->ibdev);
|
2014-12-18 16:43:01 +08:00
|
|
|
|
|
|
|
ocrdma_rem_port_stats(dev);
|
2012-04-28 13:40:01 +08:00
|
|
|
|
|
|
|
spin_lock(&ocrdma_devlist_lock);
|
|
|
|
list_del_rcu(&dev->entry);
|
|
|
|
spin_unlock(&ocrdma_devlist_lock);
|
2013-09-06 17:32:47 +08:00
|
|
|
|
|
|
|
ocrdma_free_resources(dev);
|
|
|
|
ocrdma_cleanup_hw(dev);
|
|
|
|
|
2012-04-28 13:40:01 +08:00
|
|
|
call_rcu(&dev->rcu, ocrdma_remove_free);
|
|
|
|
}
|
|
|
|
|
2012-03-21 06:39:06 +08:00
|
|
|
static int ocrdma_open(struct ocrdma_dev *dev)
|
|
|
|
{
|
|
|
|
struct ib_event port_event;
|
|
|
|
|
|
|
|
port_event.event = IB_EVENT_PORT_ACTIVE;
|
|
|
|
port_event.element.port_num = 1;
|
|
|
|
port_event.device = &dev->ibdev;
|
|
|
|
ib_dispatch_event(&port_event);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int ocrdma_close(struct ocrdma_dev *dev)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
struct ocrdma_qp *qp, **cur_qp;
|
|
|
|
struct ib_event err_event;
|
|
|
|
struct ib_qp_attr attrs;
|
|
|
|
int attr_mask = IB_QP_STATE;
|
|
|
|
|
|
|
|
attrs.qp_state = IB_QPS_ERR;
|
|
|
|
mutex_lock(&dev->dev_lock);
|
|
|
|
if (dev->qp_tbl) {
|
|
|
|
cur_qp = dev->qp_tbl;
|
|
|
|
for (i = 0; i < OCRDMA_MAX_QP; i++) {
|
|
|
|
qp = cur_qp[i];
|
2014-02-04 14:27:10 +08:00
|
|
|
if (qp && qp->ibqp.qp_type != IB_QPT_GSI) {
|
2012-03-21 06:39:06 +08:00
|
|
|
/* change the QP state to ERROR */
|
|
|
|
_ocrdma_modify_qp(&qp->ibqp, &attrs, attr_mask);
|
|
|
|
|
|
|
|
err_event.event = IB_EVENT_QP_FATAL;
|
|
|
|
err_event.element.qp = &qp->ibqp;
|
|
|
|
err_event.device = &dev->ibdev;
|
|
|
|
ib_dispatch_event(&err_event);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
mutex_unlock(&dev->dev_lock);
|
|
|
|
|
|
|
|
err_event.event = IB_EVENT_PORT_ERR;
|
|
|
|
err_event.element.port_num = 1;
|
|
|
|
err_event.device = &dev->ibdev;
|
|
|
|
ib_dispatch_event(&err_event);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2014-06-10 22:02:16 +08:00
|
|
|
static void ocrdma_shutdown(struct ocrdma_dev *dev)
|
|
|
|
{
|
|
|
|
ocrdma_close(dev);
|
|
|
|
ocrdma_remove(dev);
|
|
|
|
}
|
|
|
|
|
2012-03-21 06:39:06 +08:00
|
|
|
/* event handling via NIC driver ensures that all the NIC specific
|
|
|
|
* initialization done before RoCE driver notifies
|
|
|
|
* event to stack.
|
|
|
|
*/
|
|
|
|
static void ocrdma_event_handler(struct ocrdma_dev *dev, u32 event)
|
|
|
|
{
|
|
|
|
switch (event) {
|
|
|
|
case BE_DEV_UP:
|
|
|
|
ocrdma_open(dev);
|
|
|
|
break;
|
|
|
|
case BE_DEV_DOWN:
|
|
|
|
ocrdma_close(dev);
|
|
|
|
break;
|
2014-06-10 22:02:16 +08:00
|
|
|
case BE_DEV_SHUTDOWN:
|
|
|
|
ocrdma_shutdown(dev);
|
|
|
|
break;
|
2013-10-09 07:07:22 +08:00
|
|
|
}
|
2012-03-21 06:39:06 +08:00
|
|
|
}
|
|
|
|
|
2012-04-17 02:36:29 +08:00
|
|
|
static struct ocrdma_driver ocrdma_drv = {
|
2012-03-21 06:39:06 +08:00
|
|
|
.name = "ocrdma_driver",
|
|
|
|
.add = ocrdma_add,
|
|
|
|
.remove = ocrdma_remove,
|
|
|
|
.state_change_handler = ocrdma_event_handler,
|
2014-02-04 14:26:58 +08:00
|
|
|
.be_abi_version = OCRDMA_BE_ROCE_ABI_VERSION,
|
2012-03-21 06:39:06 +08:00
|
|
|
};
|
|
|
|
|
2012-05-03 06:42:33 +08:00
|
|
|
static void ocrdma_unregister_inet6addr_notifier(void)
|
|
|
|
{
|
2012-07-06 13:39:34 +08:00
|
|
|
#if IS_ENABLED(CONFIG_IPV6)
|
2012-05-03 06:42:33 +08:00
|
|
|
unregister_inet6addr_notifier(&ocrdma_inet6addr_notifier);
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2014-03-18 17:24:56 +08:00
|
|
|
static void ocrdma_unregister_inetaddr_notifier(void)
|
|
|
|
{
|
|
|
|
unregister_inetaddr_notifier(&ocrdma_inetaddr_notifier);
|
|
|
|
}
|
|
|
|
|
2012-03-21 06:39:06 +08:00
|
|
|
static int __init ocrdma_init_module(void)
|
|
|
|
{
|
|
|
|
int status;
|
|
|
|
|
2014-02-04 14:27:07 +08:00
|
|
|
ocrdma_init_debugfs();
|
|
|
|
|
2013-12-13 00:03:16 +08:00
|
|
|
status = register_inetaddr_notifier(&ocrdma_inetaddr_notifier);
|
|
|
|
if (status)
|
|
|
|
return status;
|
|
|
|
|
2012-07-06 13:39:34 +08:00
|
|
|
#if IS_ENABLED(CONFIG_IPV6)
|
2012-03-21 06:39:06 +08:00
|
|
|
status = register_inet6addr_notifier(&ocrdma_inet6addr_notifier);
|
|
|
|
if (status)
|
2014-03-18 17:24:56 +08:00
|
|
|
goto err_notifier6;
|
2012-05-03 06:42:33 +08:00
|
|
|
#endif
|
|
|
|
|
2012-03-21 06:39:06 +08:00
|
|
|
status = be_roce_register_driver(&ocrdma_drv);
|
|
|
|
if (status)
|
2014-03-18 17:24:56 +08:00
|
|
|
goto err_be_reg;
|
2012-05-03 06:42:33 +08:00
|
|
|
|
2014-03-18 17:24:56 +08:00
|
|
|
return 0;
|
|
|
|
|
|
|
|
err_be_reg:
|
2014-09-29 14:59:43 +08:00
|
|
|
#if IS_ENABLED(CONFIG_IPV6)
|
2014-03-18 17:24:56 +08:00
|
|
|
ocrdma_unregister_inet6addr_notifier();
|
|
|
|
err_notifier6:
|
2014-09-29 14:59:43 +08:00
|
|
|
#endif
|
2014-03-18 17:24:56 +08:00
|
|
|
ocrdma_unregister_inetaddr_notifier();
|
2012-03-21 06:39:06 +08:00
|
|
|
return status;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void __exit ocrdma_exit_module(void)
|
|
|
|
{
|
|
|
|
be_roce_unregister_driver(&ocrdma_drv);
|
2012-05-03 06:42:33 +08:00
|
|
|
ocrdma_unregister_inet6addr_notifier();
|
2014-03-18 17:24:56 +08:00
|
|
|
ocrdma_unregister_inetaddr_notifier();
|
2014-02-04 14:27:07 +08:00
|
|
|
ocrdma_rem_debugfs();
|
2015-07-08 23:23:00 +08:00
|
|
|
idr_destroy(&ocrdma_dev_id);
|
2012-03-21 06:39:06 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
module_init(ocrdma_init_module);
|
|
|
|
module_exit(ocrdma_exit_module);
|