2015-07-24 05:03:59 +05:30
|
|
|
/* 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 04:09:06 +05:30
|
|
|
*
|
|
|
|
* Contact Information:
|
|
|
|
* linux-drivers@emulex.com
|
|
|
|
*
|
|
|
|
* Emulex
|
|
|
|
* 3333 Susan Street
|
|
|
|
* Costa Mesa, CA 92626
|
2015-07-24 05:03:59 +05:30
|
|
|
*/
|
2012-03-21 04:09:06 +05:30
|
|
|
|
|
|
|
#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-06 14:38:29 -04:00
|
|
|
#include <rdma/ib_mad.h>
|
2012-03-21 04:09:06 +05:30
|
|
|
|
|
|
|
#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 11:57:07 +05:30
|
|
|
#include "ocrdma_stats.h"
|
2016-09-22 17:31:15 +03:00
|
|
|
#include <rdma/ocrdma-abi.h>
|
2012-03-21 04:09:06 +05:30
|
|
|
|
2014-02-04 11:57:00 +05:30
|
|
|
MODULE_DESCRIPTION(OCRDMA_ROCE_DRV_DESC " " OCRDMA_ROCE_DRV_VERSION);
|
2012-03-21 04:09:06 +05:30
|
|
|
MODULE_AUTHOR("Emulex Corporation");
|
2015-07-24 05:04:00 +05:30
|
|
|
MODULE_LICENSE("Dual BSD/GPL");
|
2012-03-21 04:09:06 +05:30
|
|
|
|
|
|
|
static enum rdma_link_layer ocrdma_link_layer(struct ib_device *device,
|
2021-03-01 09:04:20 +02:00
|
|
|
u32 port_num)
|
2012-03-21 04:09:06 +05:30
|
|
|
{
|
|
|
|
return IB_LINK_LAYER_ETHERNET;
|
|
|
|
}
|
|
|
|
|
2021-03-01 09:04:20 +02:00
|
|
|
static int ocrdma_port_immutable(struct ib_device *ibdev, u32 port_num,
|
2015-05-13 20:02:58 -04:00
|
|
|
struct ib_port_immutable *immutable)
|
|
|
|
{
|
|
|
|
struct ib_port_attr attr;
|
2016-01-28 08:59:56 -05:00
|
|
|
struct ocrdma_dev *dev;
|
2015-05-13 20:02:58 -04:00
|
|
|
int err;
|
|
|
|
|
2016-01-28 08:59:56 -05:00
|
|
|
dev = get_ocrdma_dev(ibdev);
|
2017-01-24 13:02:39 +02:00
|
|
|
immutable->core_cap_flags = RDMA_CORE_PORT_IBA_ROCE;
|
|
|
|
if (ocrdma_is_udp_encap_supported(dev))
|
|
|
|
immutable->core_cap_flags |= RDMA_CORE_CAP_PROT_ROCE_UDP_ENCAP;
|
|
|
|
|
|
|
|
err = ib_query_port(ibdev, port_num, &attr);
|
2015-05-13 20:02:58 -04:00
|
|
|
if (err)
|
|
|
|
return err;
|
|
|
|
|
|
|
|
immutable->pkey_tbl_len = attr.pkey_tbl_len;
|
|
|
|
immutable->gid_tbl_len = attr.gid_tbl_len;
|
2015-06-06 14:38:29 -04:00
|
|
|
immutable->max_mad_size = IB_MGMT_MAD_SIZE;
|
2015-05-13 20:02:58 -04:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2017-06-27 16:49:53 +03:00
|
|
|
static void get_dev_fw_str(struct ib_device *device, char *str)
|
2016-06-15 02:22:04 -04:00
|
|
|
{
|
|
|
|
struct ocrdma_dev *dev = get_ocrdma_dev(device);
|
|
|
|
|
2017-06-27 16:49:53 +03:00
|
|
|
snprintf(str, IB_FW_VERSION_NAME_MAX, "%s", &dev->attr.fw_ver[0]);
|
2016-06-15 02:22:04 -04:00
|
|
|
}
|
|
|
|
|
2018-10-11 22:31:54 +03:00
|
|
|
/* OCRDMA sysfs interface */
|
|
|
|
static ssize_t hw_rev_show(struct device *device,
|
|
|
|
struct device_attribute *attr, char *buf)
|
|
|
|
{
|
2018-12-18 14:15:56 +02:00
|
|
|
struct ocrdma_dev *dev =
|
|
|
|
rdma_device_to_drv_device(device, struct ocrdma_dev, ibdev);
|
2018-10-11 22:31:54 +03:00
|
|
|
|
RDMA: Convert sysfs device * show functions to use sysfs_emit()
Done with cocci script:
@@
identifier d_show;
identifier dev, attr, buf;
@@
ssize_t d_show(struct device *dev, struct device_attribute *attr, char *buf)
{
<...
return
- sprintf(buf,
+ sysfs_emit(buf,
...);
...>
}
@@
identifier d_show;
identifier dev, attr, buf;
@@
ssize_t d_show(struct device *dev, struct device_attribute *attr, char *buf)
{
<...
return
- snprintf(buf, PAGE_SIZE,
+ sysfs_emit(buf,
...);
...>
}
@@
identifier d_show;
identifier dev, attr, buf;
@@
ssize_t d_show(struct device *dev, struct device_attribute *attr, char *buf)
{
<...
return
- scnprintf(buf, PAGE_SIZE,
+ sysfs_emit(buf,
...);
...>
}
@@
identifier d_show;
identifier dev, attr, buf;
expression chr;
@@
ssize_t d_show(struct device *dev, struct device_attribute *attr, char *buf)
{
<...
return
- strcpy(buf, chr);
+ sysfs_emit(buf, chr);
...>
}
@@
identifier d_show;
identifier dev, attr, buf;
identifier len;
@@
ssize_t d_show(struct device *dev, struct device_attribute *attr, char *buf)
{
<...
len =
- sprintf(buf,
+ sysfs_emit(buf,
...);
...>
return len;
}
@@
identifier d_show;
identifier dev, attr, buf;
identifier len;
@@
ssize_t d_show(struct device *dev, struct device_attribute *attr, char *buf)
{
<...
len =
- snprintf(buf, PAGE_SIZE,
+ sysfs_emit(buf,
...);
...>
return len;
}
@@
identifier d_show;
identifier dev, attr, buf;
identifier len;
@@
ssize_t d_show(struct device *dev, struct device_attribute *attr, char *buf)
{
<...
len =
- scnprintf(buf, PAGE_SIZE,
+ sysfs_emit(buf,
...);
...>
return len;
}
@@
identifier d_show;
identifier dev, attr, buf;
identifier len;
@@
ssize_t d_show(struct device *dev, struct device_attribute *attr, char *buf)
{
<...
- len += scnprintf(buf + len, PAGE_SIZE - len,
+ len += sysfs_emit_at(buf, len,
...);
...>
return len;
}
@@
identifier d_show;
identifier dev, attr, buf;
expression chr;
@@
ssize_t d_show(struct device *dev, struct device_attribute *attr, char *buf)
{
...
- strcpy(buf, chr);
- return strlen(buf);
+ return sysfs_emit(buf, chr);
}
Link: https://lore.kernel.org/r/7f406fa8e3aa2552c022bec680f621e38d1fe414.1602122879.git.joe@perches.com
Signed-off-by: Joe Perches <joe@perches.com>
Reviewed-by: Jason Gunthorpe <jgg@nvidia.com>
Signed-off-by: Jason Gunthorpe <jgg@nvidia.com>
2020-10-07 19:36:24 -07:00
|
|
|
return sysfs_emit(buf, "0x%x\n", dev->nic_info.pdev->vendor);
|
2018-10-11 22:31:54 +03:00
|
|
|
}
|
|
|
|
static DEVICE_ATTR_RO(hw_rev);
|
|
|
|
|
|
|
|
static ssize_t hca_type_show(struct device *device,
|
|
|
|
struct device_attribute *attr, char *buf)
|
|
|
|
{
|
2018-12-18 14:15:56 +02:00
|
|
|
struct ocrdma_dev *dev =
|
|
|
|
rdma_device_to_drv_device(device, struct ocrdma_dev, ibdev);
|
2018-10-11 22:31:54 +03:00
|
|
|
|
RDMA: Convert sysfs device * show functions to use sysfs_emit()
Done with cocci script:
@@
identifier d_show;
identifier dev, attr, buf;
@@
ssize_t d_show(struct device *dev, struct device_attribute *attr, char *buf)
{
<...
return
- sprintf(buf,
+ sysfs_emit(buf,
...);
...>
}
@@
identifier d_show;
identifier dev, attr, buf;
@@
ssize_t d_show(struct device *dev, struct device_attribute *attr, char *buf)
{
<...
return
- snprintf(buf, PAGE_SIZE,
+ sysfs_emit(buf,
...);
...>
}
@@
identifier d_show;
identifier dev, attr, buf;
@@
ssize_t d_show(struct device *dev, struct device_attribute *attr, char *buf)
{
<...
return
- scnprintf(buf, PAGE_SIZE,
+ sysfs_emit(buf,
...);
...>
}
@@
identifier d_show;
identifier dev, attr, buf;
expression chr;
@@
ssize_t d_show(struct device *dev, struct device_attribute *attr, char *buf)
{
<...
return
- strcpy(buf, chr);
+ sysfs_emit(buf, chr);
...>
}
@@
identifier d_show;
identifier dev, attr, buf;
identifier len;
@@
ssize_t d_show(struct device *dev, struct device_attribute *attr, char *buf)
{
<...
len =
- sprintf(buf,
+ sysfs_emit(buf,
...);
...>
return len;
}
@@
identifier d_show;
identifier dev, attr, buf;
identifier len;
@@
ssize_t d_show(struct device *dev, struct device_attribute *attr, char *buf)
{
<...
len =
- snprintf(buf, PAGE_SIZE,
+ sysfs_emit(buf,
...);
...>
return len;
}
@@
identifier d_show;
identifier dev, attr, buf;
identifier len;
@@
ssize_t d_show(struct device *dev, struct device_attribute *attr, char *buf)
{
<...
len =
- scnprintf(buf, PAGE_SIZE,
+ sysfs_emit(buf,
...);
...>
return len;
}
@@
identifier d_show;
identifier dev, attr, buf;
identifier len;
@@
ssize_t d_show(struct device *dev, struct device_attribute *attr, char *buf)
{
<...
- len += scnprintf(buf + len, PAGE_SIZE - len,
+ len += sysfs_emit_at(buf, len,
...);
...>
return len;
}
@@
identifier d_show;
identifier dev, attr, buf;
expression chr;
@@
ssize_t d_show(struct device *dev, struct device_attribute *attr, char *buf)
{
...
- strcpy(buf, chr);
- return strlen(buf);
+ return sysfs_emit(buf, chr);
}
Link: https://lore.kernel.org/r/7f406fa8e3aa2552c022bec680f621e38d1fe414.1602122879.git.joe@perches.com
Signed-off-by: Joe Perches <joe@perches.com>
Reviewed-by: Jason Gunthorpe <jgg@nvidia.com>
Signed-off-by: Jason Gunthorpe <jgg@nvidia.com>
2020-10-07 19:36:24 -07:00
|
|
|
return sysfs_emit(buf, "%s\n", &dev->model_number[0]);
|
2018-10-11 22:31:54 +03:00
|
|
|
}
|
|
|
|
static DEVICE_ATTR_RO(hca_type);
|
|
|
|
|
|
|
|
static struct attribute *ocrdma_attributes[] = {
|
|
|
|
&dev_attr_hw_rev.attr,
|
|
|
|
&dev_attr_hca_type.attr,
|
|
|
|
NULL
|
|
|
|
};
|
|
|
|
|
|
|
|
static const struct attribute_group ocrdma_attr_group = {
|
|
|
|
.attrs = ocrdma_attributes,
|
|
|
|
};
|
|
|
|
|
2018-12-10 21:09:41 +02:00
|
|
|
static const struct ib_device_ops ocrdma_dev_ops = {
|
2019-06-05 14:39:26 -03:00
|
|
|
.owner = THIS_MODULE,
|
2019-06-05 14:39:24 -03:00
|
|
|
.driver_id = RDMA_DRIVER_OCRDMA,
|
2019-06-05 14:39:25 -03:00
|
|
|
.uverbs_abi_ver = OCRDMA_ABI_VERSION,
|
2019-06-05 14:39:24 -03:00
|
|
|
|
2018-12-10 21:09:41 +02:00
|
|
|
.alloc_mr = ocrdma_alloc_mr,
|
|
|
|
.alloc_pd = ocrdma_alloc_pd,
|
|
|
|
.alloc_ucontext = ocrdma_alloc_ucontext,
|
|
|
|
.create_ah = ocrdma_create_ah,
|
|
|
|
.create_cq = ocrdma_create_cq,
|
|
|
|
.create_qp = ocrdma_create_qp,
|
2020-10-03 20:20:11 -03:00
|
|
|
.create_user_ah = ocrdma_create_ah,
|
2018-12-10 21:09:41 +02:00
|
|
|
.dealloc_pd = ocrdma_dealloc_pd,
|
|
|
|
.dealloc_ucontext = ocrdma_dealloc_ucontext,
|
|
|
|
.dereg_mr = ocrdma_dereg_mr,
|
|
|
|
.destroy_ah = ocrdma_destroy_ah,
|
|
|
|
.destroy_cq = ocrdma_destroy_cq,
|
|
|
|
.destroy_qp = ocrdma_destroy_qp,
|
2021-06-11 19:00:34 +03:00
|
|
|
.device_group = &ocrdma_attr_group,
|
2018-12-10 21:09:41 +02:00
|
|
|
.get_dev_fw_str = get_dev_fw_str,
|
|
|
|
.get_dma_mr = ocrdma_get_dma_mr,
|
|
|
|
.get_link_layer = ocrdma_link_layer,
|
|
|
|
.get_port_immutable = ocrdma_port_immutable,
|
|
|
|
.map_mr_sg = ocrdma_map_mr_sg,
|
|
|
|
.mmap = ocrdma_mmap,
|
|
|
|
.modify_qp = ocrdma_modify_qp,
|
|
|
|
.poll_cq = ocrdma_poll_cq,
|
|
|
|
.post_recv = ocrdma_post_recv,
|
|
|
|
.post_send = ocrdma_post_send,
|
|
|
|
.process_mad = ocrdma_process_mad,
|
|
|
|
.query_ah = ocrdma_query_ah,
|
|
|
|
.query_device = ocrdma_query_device,
|
|
|
|
.query_pkey = ocrdma_query_pkey,
|
|
|
|
.query_port = ocrdma_query_port,
|
|
|
|
.query_qp = ocrdma_query_qp,
|
|
|
|
.reg_user_mr = ocrdma_reg_user_mr,
|
|
|
|
.req_notify_cq = ocrdma_arm_cq,
|
|
|
|
.resize_cq = ocrdma_resize_cq,
|
2019-04-03 16:42:42 +03:00
|
|
|
|
|
|
|
INIT_RDMA_OBJ_SIZE(ib_ah, ocrdma_ah, ibah),
|
2019-05-28 14:37:29 +03:00
|
|
|
INIT_RDMA_OBJ_SIZE(ib_cq, ocrdma_cq, ibcq),
|
2019-02-03 14:55:51 +02:00
|
|
|
INIT_RDMA_OBJ_SIZE(ib_pd, ocrdma_pd, ibpd),
|
2021-07-23 14:39:50 +03:00
|
|
|
INIT_RDMA_OBJ_SIZE(ib_qp, ocrdma_qp, ibqp),
|
2019-02-12 20:39:16 +02:00
|
|
|
INIT_RDMA_OBJ_SIZE(ib_ucontext, ocrdma_ucontext, ibucontext),
|
2018-12-10 21:09:41 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
static const struct ib_device_ops ocrdma_dev_srq_ops = {
|
|
|
|
.create_srq = ocrdma_create_srq,
|
|
|
|
.destroy_srq = ocrdma_destroy_srq,
|
|
|
|
.modify_srq = ocrdma_modify_srq,
|
|
|
|
.post_srq_recv = ocrdma_post_srq_recv,
|
|
|
|
.query_srq = ocrdma_query_srq,
|
2019-04-03 16:42:43 +03:00
|
|
|
|
|
|
|
INIT_RDMA_OBJ_SIZE(ib_srq, ocrdma_srq, ibsrq),
|
2018-12-10 21:09:41 +02:00
|
|
|
};
|
|
|
|
|
2012-04-16 11:36:29 -07:00
|
|
|
static int ocrdma_register_device(struct ocrdma_dev *dev)
|
2012-03-21 04:09:06 +05:30
|
|
|
{
|
2019-04-04 16:56:57 -03:00
|
|
|
int ret;
|
|
|
|
|
2021-11-17 11:02:05 +02:00
|
|
|
addrconf_addr_eui48((u8 *)&dev->ibdev.node_guid,
|
|
|
|
dev->nic_info.mac_addr);
|
2016-08-25 10:57:07 -07:00
|
|
|
BUILD_BUG_ON(sizeof(OCRDMA_NODE_DESC) > IB_DEVICE_NODE_DESC_MAX);
|
2012-03-21 04:09:06 +05:30
|
|
|
memcpy(dev->ibdev.node_desc, OCRDMA_NODE_DESC,
|
|
|
|
sizeof(OCRDMA_NODE_DESC));
|
|
|
|
|
|
|
|
dev->ibdev.node_type = RDMA_NODE_IB_CA;
|
|
|
|
dev->ibdev.phys_port_cnt = 1;
|
2014-12-18 14:12:58 +05:30
|
|
|
dev->ibdev.num_comp_vectors = dev->eq_cnt;
|
2012-03-21 04:09:06 +05:30
|
|
|
|
|
|
|
/* mandatory to support user space verbs consumer. */
|
2017-01-20 13:04:24 -08:00
|
|
|
dev->ibdev.dev.parent = &dev->nic_info.pdev->dev;
|
2012-03-21 04:09:06 +05:30
|
|
|
|
2018-12-10 21:09:41 +02:00
|
|
|
ib_set_device_ops(&dev->ibdev, &ocrdma_dev_ops);
|
2012-03-21 04:09:06 +05:30
|
|
|
|
RDMA: Remove uverbs cmds from drivers that don't use them
Allowing userspace to invoke these commands is probably going to crash
these drivers as they are not tested and not expecting to use them on a
user object.
For example pvrdma touches cq->ring_state which is not initialized for
user QPs.
These commands are effected:
- IB_USER_VERBS_CMD_REQ_NOTIFY_CQ is ibv_cmd_req_notify_cq() in
rdma-core, only hfi1, ipath and rxe calls it.
- IB_USER_VERBS_CMD_POLL_CQ is ibv_cmd_poll_cq() in rdma-core, only
ipath and hfi1 calls it.
- IB_USER_VERBS_CMD_POST_SEND/RECV is ibv_cmd_post_send/recv() in
rdma-core, only ipath and hfi1 call them.
- IB_USER_VERBS_CMD_POST_SRQ_RECV is ibv_cmd_post_srq_recv() in
rdma-core, only ipath and hfi1 calls it.
- IB_USER_VERBS_CMD_PEEK_CQ isn't even implemented anywhere
- IB_USER_VERBS_CMD_CREATE/DESTROY_AH is ibv_cmd_create/destroy_ah() in
rdma-core, only bnxt_re, efa, hfi1, ipath, mlx5, orcrdma, and rxe call
it.
Link: https://lore.kernel.org/r/10-v1-caa70ba3d1ab+1436e-ucmd_mask_jgg@nvidia.com
Signed-off-by: Jason Gunthorpe <jgg@nvidia.com>
2020-10-03 20:20:10 -03:00
|
|
|
if (ocrdma_get_asic_type(dev) == OCRDMA_ASIC_GEN_SKH_R)
|
2018-12-10 21:09:41 +02:00
|
|
|
ib_set_device_ops(&dev->ibdev, &ocrdma_dev_srq_ops);
|
RDMA: Remove uverbs cmds from drivers that don't use them
Allowing userspace to invoke these commands is probably going to crash
these drivers as they are not tested and not expecting to use them on a
user object.
For example pvrdma touches cq->ring_state which is not initialized for
user QPs.
These commands are effected:
- IB_USER_VERBS_CMD_REQ_NOTIFY_CQ is ibv_cmd_req_notify_cq() in
rdma-core, only hfi1, ipath and rxe calls it.
- IB_USER_VERBS_CMD_POLL_CQ is ibv_cmd_poll_cq() in rdma-core, only
ipath and hfi1 calls it.
- IB_USER_VERBS_CMD_POST_SEND/RECV is ibv_cmd_post_send/recv() in
rdma-core, only ipath and hfi1 call them.
- IB_USER_VERBS_CMD_POST_SRQ_RECV is ibv_cmd_post_srq_recv() in
rdma-core, only ipath and hfi1 calls it.
- IB_USER_VERBS_CMD_PEEK_CQ isn't even implemented anywhere
- IB_USER_VERBS_CMD_CREATE/DESTROY_AH is ibv_cmd_create/destroy_ah() in
rdma-core, only bnxt_re, efa, hfi1, ipath, mlx5, orcrdma, and rxe call
it.
Link: https://lore.kernel.org/r/10-v1-caa70ba3d1ab+1436e-ucmd_mask_jgg@nvidia.com
Signed-off-by: Jason Gunthorpe <jgg@nvidia.com>
2020-10-03 20:20:10 -03:00
|
|
|
|
2019-04-04 16:56:57 -03:00
|
|
|
ret = ib_device_set_netdev(&dev->ibdev, dev->nic_info.netdev, 1);
|
|
|
|
if (ret)
|
|
|
|
return ret;
|
|
|
|
|
2020-10-08 11:27:52 +03:00
|
|
|
dma_set_max_seg_size(&dev->nic_info.pdev->dev, UINT_MAX);
|
|
|
|
return ib_register_device(&dev->ibdev, "ocrdma%d",
|
|
|
|
&dev->nic_info.pdev->dev);
|
2012-03-21 04:09:06 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
static int ocrdma_alloc_resources(struct ocrdma_dev *dev)
|
|
|
|
{
|
|
|
|
mutex_init(&dev->dev_lock);
|
treewide: kzalloc() -> kcalloc()
The kzalloc() function has a 2-factor argument form, kcalloc(). This
patch replaces cases of:
kzalloc(a * b, gfp)
with:
kcalloc(a * b, gfp)
as well as handling cases of:
kzalloc(a * b * c, gfp)
with:
kzalloc(array3_size(a, b, c), gfp)
as it's slightly less ugly than:
kzalloc_array(array_size(a, b), c, gfp)
This does, however, attempt to ignore constant size factors like:
kzalloc(4 * 1024, gfp)
though any constants defined via macros get caught up in the conversion.
Any factors with a sizeof() of "unsigned char", "char", and "u8" were
dropped, since they're redundant.
The Coccinelle script used for this was:
// Fix redundant parens around sizeof().
@@
type TYPE;
expression THING, E;
@@
(
kzalloc(
- (sizeof(TYPE)) * E
+ sizeof(TYPE) * E
, ...)
|
kzalloc(
- (sizeof(THING)) * E
+ sizeof(THING) * E
, ...)
)
// Drop single-byte sizes and redundant parens.
@@
expression COUNT;
typedef u8;
typedef __u8;
@@
(
kzalloc(
- sizeof(u8) * (COUNT)
+ COUNT
, ...)
|
kzalloc(
- sizeof(__u8) * (COUNT)
+ COUNT
, ...)
|
kzalloc(
- sizeof(char) * (COUNT)
+ COUNT
, ...)
|
kzalloc(
- sizeof(unsigned char) * (COUNT)
+ COUNT
, ...)
|
kzalloc(
- sizeof(u8) * COUNT
+ COUNT
, ...)
|
kzalloc(
- sizeof(__u8) * COUNT
+ COUNT
, ...)
|
kzalloc(
- sizeof(char) * COUNT
+ COUNT
, ...)
|
kzalloc(
- sizeof(unsigned char) * COUNT
+ COUNT
, ...)
)
// 2-factor product with sizeof(type/expression) and identifier or constant.
@@
type TYPE;
expression THING;
identifier COUNT_ID;
constant COUNT_CONST;
@@
(
- kzalloc
+ kcalloc
(
- sizeof(TYPE) * (COUNT_ID)
+ COUNT_ID, sizeof(TYPE)
, ...)
|
- kzalloc
+ kcalloc
(
- sizeof(TYPE) * COUNT_ID
+ COUNT_ID, sizeof(TYPE)
, ...)
|
- kzalloc
+ kcalloc
(
- sizeof(TYPE) * (COUNT_CONST)
+ COUNT_CONST, sizeof(TYPE)
, ...)
|
- kzalloc
+ kcalloc
(
- sizeof(TYPE) * COUNT_CONST
+ COUNT_CONST, sizeof(TYPE)
, ...)
|
- kzalloc
+ kcalloc
(
- sizeof(THING) * (COUNT_ID)
+ COUNT_ID, sizeof(THING)
, ...)
|
- kzalloc
+ kcalloc
(
- sizeof(THING) * COUNT_ID
+ COUNT_ID, sizeof(THING)
, ...)
|
- kzalloc
+ kcalloc
(
- sizeof(THING) * (COUNT_CONST)
+ COUNT_CONST, sizeof(THING)
, ...)
|
- kzalloc
+ kcalloc
(
- sizeof(THING) * COUNT_CONST
+ COUNT_CONST, sizeof(THING)
, ...)
)
// 2-factor product, only identifiers.
@@
identifier SIZE, COUNT;
@@
- kzalloc
+ kcalloc
(
- SIZE * COUNT
+ COUNT, SIZE
, ...)
// 3-factor product with 1 sizeof(type) or sizeof(expression), with
// redundant parens removed.
@@
expression THING;
identifier STRIDE, COUNT;
type TYPE;
@@
(
kzalloc(
- sizeof(TYPE) * (COUNT) * (STRIDE)
+ array3_size(COUNT, STRIDE, sizeof(TYPE))
, ...)
|
kzalloc(
- sizeof(TYPE) * (COUNT) * STRIDE
+ array3_size(COUNT, STRIDE, sizeof(TYPE))
, ...)
|
kzalloc(
- sizeof(TYPE) * COUNT * (STRIDE)
+ array3_size(COUNT, STRIDE, sizeof(TYPE))
, ...)
|
kzalloc(
- sizeof(TYPE) * COUNT * STRIDE
+ array3_size(COUNT, STRIDE, sizeof(TYPE))
, ...)
|
kzalloc(
- sizeof(THING) * (COUNT) * (STRIDE)
+ array3_size(COUNT, STRIDE, sizeof(THING))
, ...)
|
kzalloc(
- sizeof(THING) * (COUNT) * STRIDE
+ array3_size(COUNT, STRIDE, sizeof(THING))
, ...)
|
kzalloc(
- sizeof(THING) * COUNT * (STRIDE)
+ array3_size(COUNT, STRIDE, sizeof(THING))
, ...)
|
kzalloc(
- sizeof(THING) * COUNT * STRIDE
+ array3_size(COUNT, STRIDE, sizeof(THING))
, ...)
)
// 3-factor product with 2 sizeof(variable), with redundant parens removed.
@@
expression THING1, THING2;
identifier COUNT;
type TYPE1, TYPE2;
@@
(
kzalloc(
- sizeof(TYPE1) * sizeof(TYPE2) * COUNT
+ array3_size(COUNT, sizeof(TYPE1), sizeof(TYPE2))
, ...)
|
kzalloc(
- sizeof(TYPE1) * sizeof(THING2) * (COUNT)
+ array3_size(COUNT, sizeof(TYPE1), sizeof(TYPE2))
, ...)
|
kzalloc(
- sizeof(THING1) * sizeof(THING2) * COUNT
+ array3_size(COUNT, sizeof(THING1), sizeof(THING2))
, ...)
|
kzalloc(
- sizeof(THING1) * sizeof(THING2) * (COUNT)
+ array3_size(COUNT, sizeof(THING1), sizeof(THING2))
, ...)
|
kzalloc(
- sizeof(TYPE1) * sizeof(THING2) * COUNT
+ array3_size(COUNT, sizeof(TYPE1), sizeof(THING2))
, ...)
|
kzalloc(
- sizeof(TYPE1) * sizeof(THING2) * (COUNT)
+ array3_size(COUNT, sizeof(TYPE1), sizeof(THING2))
, ...)
)
// 3-factor product, only identifiers, with redundant parens removed.
@@
identifier STRIDE, SIZE, COUNT;
@@
(
kzalloc(
- (COUNT) * STRIDE * SIZE
+ array3_size(COUNT, STRIDE, SIZE)
, ...)
|
kzalloc(
- COUNT * (STRIDE) * SIZE
+ array3_size(COUNT, STRIDE, SIZE)
, ...)
|
kzalloc(
- COUNT * STRIDE * (SIZE)
+ array3_size(COUNT, STRIDE, SIZE)
, ...)
|
kzalloc(
- (COUNT) * (STRIDE) * SIZE
+ array3_size(COUNT, STRIDE, SIZE)
, ...)
|
kzalloc(
- COUNT * (STRIDE) * (SIZE)
+ array3_size(COUNT, STRIDE, SIZE)
, ...)
|
kzalloc(
- (COUNT) * STRIDE * (SIZE)
+ array3_size(COUNT, STRIDE, SIZE)
, ...)
|
kzalloc(
- (COUNT) * (STRIDE) * (SIZE)
+ array3_size(COUNT, STRIDE, SIZE)
, ...)
|
kzalloc(
- COUNT * STRIDE * SIZE
+ array3_size(COUNT, STRIDE, SIZE)
, ...)
)
// Any remaining multi-factor products, first at least 3-factor products,
// when they're not all constants...
@@
expression E1, E2, E3;
constant C1, C2, C3;
@@
(
kzalloc(C1 * C2 * C3, ...)
|
kzalloc(
- (E1) * E2 * E3
+ array3_size(E1, E2, E3)
, ...)
|
kzalloc(
- (E1) * (E2) * E3
+ array3_size(E1, E2, E3)
, ...)
|
kzalloc(
- (E1) * (E2) * (E3)
+ array3_size(E1, E2, E3)
, ...)
|
kzalloc(
- E1 * E2 * E3
+ array3_size(E1, E2, E3)
, ...)
)
// And then all remaining 2 factors products when they're not all constants,
// keeping sizeof() as the second factor argument.
@@
expression THING, E1, E2;
type TYPE;
constant C1, C2, C3;
@@
(
kzalloc(sizeof(THING) * C2, ...)
|
kzalloc(sizeof(TYPE) * C2, ...)
|
kzalloc(C1 * C2 * C3, ...)
|
kzalloc(C1 * C2, ...)
|
- kzalloc
+ kcalloc
(
- sizeof(TYPE) * (E2)
+ E2, sizeof(TYPE)
, ...)
|
- kzalloc
+ kcalloc
(
- sizeof(TYPE) * E2
+ E2, sizeof(TYPE)
, ...)
|
- kzalloc
+ kcalloc
(
- sizeof(THING) * (E2)
+ E2, sizeof(THING)
, ...)
|
- kzalloc
+ kcalloc
(
- sizeof(THING) * E2
+ E2, sizeof(THING)
, ...)
|
- kzalloc
+ kcalloc
(
- (E1) * E2
+ E1, E2
, ...)
|
- kzalloc
+ kcalloc
(
- (E1) * (E2)
+ E1, E2
, ...)
|
- kzalloc
+ kcalloc
(
- E1 * E2
+ E1, E2
, ...)
)
Signed-off-by: Kees Cook <keescook@chromium.org>
2018-06-12 14:03:40 -07:00
|
|
|
dev->cq_tbl = kcalloc(OCRDMA_MAX_CQ, sizeof(struct ocrdma_cq *),
|
|
|
|
GFP_KERNEL);
|
2012-03-21 04:09:06 +05:30
|
|
|
if (!dev->cq_tbl)
|
|
|
|
goto alloc_err;
|
|
|
|
|
|
|
|
if (dev->attr.max_qp) {
|
treewide: kzalloc() -> kcalloc()
The kzalloc() function has a 2-factor argument form, kcalloc(). This
patch replaces cases of:
kzalloc(a * b, gfp)
with:
kcalloc(a * b, gfp)
as well as handling cases of:
kzalloc(a * b * c, gfp)
with:
kzalloc(array3_size(a, b, c), gfp)
as it's slightly less ugly than:
kzalloc_array(array_size(a, b), c, gfp)
This does, however, attempt to ignore constant size factors like:
kzalloc(4 * 1024, gfp)
though any constants defined via macros get caught up in the conversion.
Any factors with a sizeof() of "unsigned char", "char", and "u8" were
dropped, since they're redundant.
The Coccinelle script used for this was:
// Fix redundant parens around sizeof().
@@
type TYPE;
expression THING, E;
@@
(
kzalloc(
- (sizeof(TYPE)) * E
+ sizeof(TYPE) * E
, ...)
|
kzalloc(
- (sizeof(THING)) * E
+ sizeof(THING) * E
, ...)
)
// Drop single-byte sizes and redundant parens.
@@
expression COUNT;
typedef u8;
typedef __u8;
@@
(
kzalloc(
- sizeof(u8) * (COUNT)
+ COUNT
, ...)
|
kzalloc(
- sizeof(__u8) * (COUNT)
+ COUNT
, ...)
|
kzalloc(
- sizeof(char) * (COUNT)
+ COUNT
, ...)
|
kzalloc(
- sizeof(unsigned char) * (COUNT)
+ COUNT
, ...)
|
kzalloc(
- sizeof(u8) * COUNT
+ COUNT
, ...)
|
kzalloc(
- sizeof(__u8) * COUNT
+ COUNT
, ...)
|
kzalloc(
- sizeof(char) * COUNT
+ COUNT
, ...)
|
kzalloc(
- sizeof(unsigned char) * COUNT
+ COUNT
, ...)
)
// 2-factor product with sizeof(type/expression) and identifier or constant.
@@
type TYPE;
expression THING;
identifier COUNT_ID;
constant COUNT_CONST;
@@
(
- kzalloc
+ kcalloc
(
- sizeof(TYPE) * (COUNT_ID)
+ COUNT_ID, sizeof(TYPE)
, ...)
|
- kzalloc
+ kcalloc
(
- sizeof(TYPE) * COUNT_ID
+ COUNT_ID, sizeof(TYPE)
, ...)
|
- kzalloc
+ kcalloc
(
- sizeof(TYPE) * (COUNT_CONST)
+ COUNT_CONST, sizeof(TYPE)
, ...)
|
- kzalloc
+ kcalloc
(
- sizeof(TYPE) * COUNT_CONST
+ COUNT_CONST, sizeof(TYPE)
, ...)
|
- kzalloc
+ kcalloc
(
- sizeof(THING) * (COUNT_ID)
+ COUNT_ID, sizeof(THING)
, ...)
|
- kzalloc
+ kcalloc
(
- sizeof(THING) * COUNT_ID
+ COUNT_ID, sizeof(THING)
, ...)
|
- kzalloc
+ kcalloc
(
- sizeof(THING) * (COUNT_CONST)
+ COUNT_CONST, sizeof(THING)
, ...)
|
- kzalloc
+ kcalloc
(
- sizeof(THING) * COUNT_CONST
+ COUNT_CONST, sizeof(THING)
, ...)
)
// 2-factor product, only identifiers.
@@
identifier SIZE, COUNT;
@@
- kzalloc
+ kcalloc
(
- SIZE * COUNT
+ COUNT, SIZE
, ...)
// 3-factor product with 1 sizeof(type) or sizeof(expression), with
// redundant parens removed.
@@
expression THING;
identifier STRIDE, COUNT;
type TYPE;
@@
(
kzalloc(
- sizeof(TYPE) * (COUNT) * (STRIDE)
+ array3_size(COUNT, STRIDE, sizeof(TYPE))
, ...)
|
kzalloc(
- sizeof(TYPE) * (COUNT) * STRIDE
+ array3_size(COUNT, STRIDE, sizeof(TYPE))
, ...)
|
kzalloc(
- sizeof(TYPE) * COUNT * (STRIDE)
+ array3_size(COUNT, STRIDE, sizeof(TYPE))
, ...)
|
kzalloc(
- sizeof(TYPE) * COUNT * STRIDE
+ array3_size(COUNT, STRIDE, sizeof(TYPE))
, ...)
|
kzalloc(
- sizeof(THING) * (COUNT) * (STRIDE)
+ array3_size(COUNT, STRIDE, sizeof(THING))
, ...)
|
kzalloc(
- sizeof(THING) * (COUNT) * STRIDE
+ array3_size(COUNT, STRIDE, sizeof(THING))
, ...)
|
kzalloc(
- sizeof(THING) * COUNT * (STRIDE)
+ array3_size(COUNT, STRIDE, sizeof(THING))
, ...)
|
kzalloc(
- sizeof(THING) * COUNT * STRIDE
+ array3_size(COUNT, STRIDE, sizeof(THING))
, ...)
)
// 3-factor product with 2 sizeof(variable), with redundant parens removed.
@@
expression THING1, THING2;
identifier COUNT;
type TYPE1, TYPE2;
@@
(
kzalloc(
- sizeof(TYPE1) * sizeof(TYPE2) * COUNT
+ array3_size(COUNT, sizeof(TYPE1), sizeof(TYPE2))
, ...)
|
kzalloc(
- sizeof(TYPE1) * sizeof(THING2) * (COUNT)
+ array3_size(COUNT, sizeof(TYPE1), sizeof(TYPE2))
, ...)
|
kzalloc(
- sizeof(THING1) * sizeof(THING2) * COUNT
+ array3_size(COUNT, sizeof(THING1), sizeof(THING2))
, ...)
|
kzalloc(
- sizeof(THING1) * sizeof(THING2) * (COUNT)
+ array3_size(COUNT, sizeof(THING1), sizeof(THING2))
, ...)
|
kzalloc(
- sizeof(TYPE1) * sizeof(THING2) * COUNT
+ array3_size(COUNT, sizeof(TYPE1), sizeof(THING2))
, ...)
|
kzalloc(
- sizeof(TYPE1) * sizeof(THING2) * (COUNT)
+ array3_size(COUNT, sizeof(TYPE1), sizeof(THING2))
, ...)
)
// 3-factor product, only identifiers, with redundant parens removed.
@@
identifier STRIDE, SIZE, COUNT;
@@
(
kzalloc(
- (COUNT) * STRIDE * SIZE
+ array3_size(COUNT, STRIDE, SIZE)
, ...)
|
kzalloc(
- COUNT * (STRIDE) * SIZE
+ array3_size(COUNT, STRIDE, SIZE)
, ...)
|
kzalloc(
- COUNT * STRIDE * (SIZE)
+ array3_size(COUNT, STRIDE, SIZE)
, ...)
|
kzalloc(
- (COUNT) * (STRIDE) * SIZE
+ array3_size(COUNT, STRIDE, SIZE)
, ...)
|
kzalloc(
- COUNT * (STRIDE) * (SIZE)
+ array3_size(COUNT, STRIDE, SIZE)
, ...)
|
kzalloc(
- (COUNT) * STRIDE * (SIZE)
+ array3_size(COUNT, STRIDE, SIZE)
, ...)
|
kzalloc(
- (COUNT) * (STRIDE) * (SIZE)
+ array3_size(COUNT, STRIDE, SIZE)
, ...)
|
kzalloc(
- COUNT * STRIDE * SIZE
+ array3_size(COUNT, STRIDE, SIZE)
, ...)
)
// Any remaining multi-factor products, first at least 3-factor products,
// when they're not all constants...
@@
expression E1, E2, E3;
constant C1, C2, C3;
@@
(
kzalloc(C1 * C2 * C3, ...)
|
kzalloc(
- (E1) * E2 * E3
+ array3_size(E1, E2, E3)
, ...)
|
kzalloc(
- (E1) * (E2) * E3
+ array3_size(E1, E2, E3)
, ...)
|
kzalloc(
- (E1) * (E2) * (E3)
+ array3_size(E1, E2, E3)
, ...)
|
kzalloc(
- E1 * E2 * E3
+ array3_size(E1, E2, E3)
, ...)
)
// And then all remaining 2 factors products when they're not all constants,
// keeping sizeof() as the second factor argument.
@@
expression THING, E1, E2;
type TYPE;
constant C1, C2, C3;
@@
(
kzalloc(sizeof(THING) * C2, ...)
|
kzalloc(sizeof(TYPE) * C2, ...)
|
kzalloc(C1 * C2 * C3, ...)
|
kzalloc(C1 * C2, ...)
|
- kzalloc
+ kcalloc
(
- sizeof(TYPE) * (E2)
+ E2, sizeof(TYPE)
, ...)
|
- kzalloc
+ kcalloc
(
- sizeof(TYPE) * E2
+ E2, sizeof(TYPE)
, ...)
|
- kzalloc
+ kcalloc
(
- sizeof(THING) * (E2)
+ E2, sizeof(THING)
, ...)
|
- kzalloc
+ kcalloc
(
- sizeof(THING) * E2
+ E2, sizeof(THING)
, ...)
|
- kzalloc
+ kcalloc
(
- (E1) * E2
+ E1, E2
, ...)
|
- kzalloc
+ kcalloc
(
- (E1) * (E2)
+ E1, E2
, ...)
|
- kzalloc
+ kcalloc
(
- E1 * E2
+ E1, E2
, ...)
)
Signed-off-by: Kees Cook <keescook@chromium.org>
2018-06-12 14:03:40 -07:00
|
|
|
dev->qp_tbl = kcalloc(OCRDMA_MAX_QP,
|
|
|
|
sizeof(struct ocrdma_qp *),
|
|
|
|
GFP_KERNEL);
|
2012-03-21 04:09:06 +05:30
|
|
|
if (!dev->qp_tbl)
|
|
|
|
goto alloc_err;
|
|
|
|
}
|
2014-06-10 19:32:24 +05:30
|
|
|
|
treewide: kzalloc() -> kcalloc()
The kzalloc() function has a 2-factor argument form, kcalloc(). This
patch replaces cases of:
kzalloc(a * b, gfp)
with:
kcalloc(a * b, gfp)
as well as handling cases of:
kzalloc(a * b * c, gfp)
with:
kzalloc(array3_size(a, b, c), gfp)
as it's slightly less ugly than:
kzalloc_array(array_size(a, b), c, gfp)
This does, however, attempt to ignore constant size factors like:
kzalloc(4 * 1024, gfp)
though any constants defined via macros get caught up in the conversion.
Any factors with a sizeof() of "unsigned char", "char", and "u8" were
dropped, since they're redundant.
The Coccinelle script used for this was:
// Fix redundant parens around sizeof().
@@
type TYPE;
expression THING, E;
@@
(
kzalloc(
- (sizeof(TYPE)) * E
+ sizeof(TYPE) * E
, ...)
|
kzalloc(
- (sizeof(THING)) * E
+ sizeof(THING) * E
, ...)
)
// Drop single-byte sizes and redundant parens.
@@
expression COUNT;
typedef u8;
typedef __u8;
@@
(
kzalloc(
- sizeof(u8) * (COUNT)
+ COUNT
, ...)
|
kzalloc(
- sizeof(__u8) * (COUNT)
+ COUNT
, ...)
|
kzalloc(
- sizeof(char) * (COUNT)
+ COUNT
, ...)
|
kzalloc(
- sizeof(unsigned char) * (COUNT)
+ COUNT
, ...)
|
kzalloc(
- sizeof(u8) * COUNT
+ COUNT
, ...)
|
kzalloc(
- sizeof(__u8) * COUNT
+ COUNT
, ...)
|
kzalloc(
- sizeof(char) * COUNT
+ COUNT
, ...)
|
kzalloc(
- sizeof(unsigned char) * COUNT
+ COUNT
, ...)
)
// 2-factor product with sizeof(type/expression) and identifier or constant.
@@
type TYPE;
expression THING;
identifier COUNT_ID;
constant COUNT_CONST;
@@
(
- kzalloc
+ kcalloc
(
- sizeof(TYPE) * (COUNT_ID)
+ COUNT_ID, sizeof(TYPE)
, ...)
|
- kzalloc
+ kcalloc
(
- sizeof(TYPE) * COUNT_ID
+ COUNT_ID, sizeof(TYPE)
, ...)
|
- kzalloc
+ kcalloc
(
- sizeof(TYPE) * (COUNT_CONST)
+ COUNT_CONST, sizeof(TYPE)
, ...)
|
- kzalloc
+ kcalloc
(
- sizeof(TYPE) * COUNT_CONST
+ COUNT_CONST, sizeof(TYPE)
, ...)
|
- kzalloc
+ kcalloc
(
- sizeof(THING) * (COUNT_ID)
+ COUNT_ID, sizeof(THING)
, ...)
|
- kzalloc
+ kcalloc
(
- sizeof(THING) * COUNT_ID
+ COUNT_ID, sizeof(THING)
, ...)
|
- kzalloc
+ kcalloc
(
- sizeof(THING) * (COUNT_CONST)
+ COUNT_CONST, sizeof(THING)
, ...)
|
- kzalloc
+ kcalloc
(
- sizeof(THING) * COUNT_CONST
+ COUNT_CONST, sizeof(THING)
, ...)
)
// 2-factor product, only identifiers.
@@
identifier SIZE, COUNT;
@@
- kzalloc
+ kcalloc
(
- SIZE * COUNT
+ COUNT, SIZE
, ...)
// 3-factor product with 1 sizeof(type) or sizeof(expression), with
// redundant parens removed.
@@
expression THING;
identifier STRIDE, COUNT;
type TYPE;
@@
(
kzalloc(
- sizeof(TYPE) * (COUNT) * (STRIDE)
+ array3_size(COUNT, STRIDE, sizeof(TYPE))
, ...)
|
kzalloc(
- sizeof(TYPE) * (COUNT) * STRIDE
+ array3_size(COUNT, STRIDE, sizeof(TYPE))
, ...)
|
kzalloc(
- sizeof(TYPE) * COUNT * (STRIDE)
+ array3_size(COUNT, STRIDE, sizeof(TYPE))
, ...)
|
kzalloc(
- sizeof(TYPE) * COUNT * STRIDE
+ array3_size(COUNT, STRIDE, sizeof(TYPE))
, ...)
|
kzalloc(
- sizeof(THING) * (COUNT) * (STRIDE)
+ array3_size(COUNT, STRIDE, sizeof(THING))
, ...)
|
kzalloc(
- sizeof(THING) * (COUNT) * STRIDE
+ array3_size(COUNT, STRIDE, sizeof(THING))
, ...)
|
kzalloc(
- sizeof(THING) * COUNT * (STRIDE)
+ array3_size(COUNT, STRIDE, sizeof(THING))
, ...)
|
kzalloc(
- sizeof(THING) * COUNT * STRIDE
+ array3_size(COUNT, STRIDE, sizeof(THING))
, ...)
)
// 3-factor product with 2 sizeof(variable), with redundant parens removed.
@@
expression THING1, THING2;
identifier COUNT;
type TYPE1, TYPE2;
@@
(
kzalloc(
- sizeof(TYPE1) * sizeof(TYPE2) * COUNT
+ array3_size(COUNT, sizeof(TYPE1), sizeof(TYPE2))
, ...)
|
kzalloc(
- sizeof(TYPE1) * sizeof(THING2) * (COUNT)
+ array3_size(COUNT, sizeof(TYPE1), sizeof(TYPE2))
, ...)
|
kzalloc(
- sizeof(THING1) * sizeof(THING2) * COUNT
+ array3_size(COUNT, sizeof(THING1), sizeof(THING2))
, ...)
|
kzalloc(
- sizeof(THING1) * sizeof(THING2) * (COUNT)
+ array3_size(COUNT, sizeof(THING1), sizeof(THING2))
, ...)
|
kzalloc(
- sizeof(TYPE1) * sizeof(THING2) * COUNT
+ array3_size(COUNT, sizeof(TYPE1), sizeof(THING2))
, ...)
|
kzalloc(
- sizeof(TYPE1) * sizeof(THING2) * (COUNT)
+ array3_size(COUNT, sizeof(TYPE1), sizeof(THING2))
, ...)
)
// 3-factor product, only identifiers, with redundant parens removed.
@@
identifier STRIDE, SIZE, COUNT;
@@
(
kzalloc(
- (COUNT) * STRIDE * SIZE
+ array3_size(COUNT, STRIDE, SIZE)
, ...)
|
kzalloc(
- COUNT * (STRIDE) * SIZE
+ array3_size(COUNT, STRIDE, SIZE)
, ...)
|
kzalloc(
- COUNT * STRIDE * (SIZE)
+ array3_size(COUNT, STRIDE, SIZE)
, ...)
|
kzalloc(
- (COUNT) * (STRIDE) * SIZE
+ array3_size(COUNT, STRIDE, SIZE)
, ...)
|
kzalloc(
- COUNT * (STRIDE) * (SIZE)
+ array3_size(COUNT, STRIDE, SIZE)
, ...)
|
kzalloc(
- (COUNT) * STRIDE * (SIZE)
+ array3_size(COUNT, STRIDE, SIZE)
, ...)
|
kzalloc(
- (COUNT) * (STRIDE) * (SIZE)
+ array3_size(COUNT, STRIDE, SIZE)
, ...)
|
kzalloc(
- COUNT * STRIDE * SIZE
+ array3_size(COUNT, STRIDE, SIZE)
, ...)
)
// Any remaining multi-factor products, first at least 3-factor products,
// when they're not all constants...
@@
expression E1, E2, E3;
constant C1, C2, C3;
@@
(
kzalloc(C1 * C2 * C3, ...)
|
kzalloc(
- (E1) * E2 * E3
+ array3_size(E1, E2, E3)
, ...)
|
kzalloc(
- (E1) * (E2) * E3
+ array3_size(E1, E2, E3)
, ...)
|
kzalloc(
- (E1) * (E2) * (E3)
+ array3_size(E1, E2, E3)
, ...)
|
kzalloc(
- E1 * E2 * E3
+ array3_size(E1, E2, E3)
, ...)
)
// And then all remaining 2 factors products when they're not all constants,
// keeping sizeof() as the second factor argument.
@@
expression THING, E1, E2;
type TYPE;
constant C1, C2, C3;
@@
(
kzalloc(sizeof(THING) * C2, ...)
|
kzalloc(sizeof(TYPE) * C2, ...)
|
kzalloc(C1 * C2 * C3, ...)
|
kzalloc(C1 * C2, ...)
|
- kzalloc
+ kcalloc
(
- sizeof(TYPE) * (E2)
+ E2, sizeof(TYPE)
, ...)
|
- kzalloc
+ kcalloc
(
- sizeof(TYPE) * E2
+ E2, sizeof(TYPE)
, ...)
|
- kzalloc
+ kcalloc
(
- sizeof(THING) * (E2)
+ E2, sizeof(THING)
, ...)
|
- kzalloc
+ kcalloc
(
- sizeof(THING) * E2
+ E2, sizeof(THING)
, ...)
|
- kzalloc
+ kcalloc
(
- (E1) * E2
+ E1, E2
, ...)
|
- kzalloc
+ kcalloc
(
- (E1) * (E2)
+ E1, E2
, ...)
|
- kzalloc
+ kcalloc
(
- E1 * E2
+ E1, E2
, ...)
)
Signed-off-by: Kees Cook <keescook@chromium.org>
2018-06-12 14:03:40 -07:00
|
|
|
dev->stag_arr = kcalloc(OCRDMA_MAX_STAG, sizeof(u64), GFP_KERNEL);
|
2014-06-10 19:32:24 +05:30
|
|
|
if (dev->stag_arr == NULL)
|
|
|
|
goto alloc_err;
|
|
|
|
|
2014-12-18 14:12:57 +05:30
|
|
|
ocrdma_alloc_pd_pool(dev);
|
|
|
|
|
2016-02-05 20:06:37 +05:30
|
|
|
if (!ocrdma_alloc_stats_resources(dev)) {
|
|
|
|
pr_err("%s: stats resource allocation failed\n", __func__);
|
|
|
|
goto alloc_err;
|
|
|
|
}
|
|
|
|
|
2012-03-21 04:09:06 +05:30
|
|
|
spin_lock_init(&dev->av_tbl.lock);
|
|
|
|
spin_lock_init(&dev->flush_q_lock);
|
|
|
|
return 0;
|
|
|
|
alloc_err:
|
2013-06-10 04:42:39 +00:00
|
|
|
pr_err("%s(%d) error.\n", __func__, dev->id);
|
2012-03-21 04:09:06 +05:30
|
|
|
return -ENOMEM;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void ocrdma_free_resources(struct ocrdma_dev *dev)
|
|
|
|
{
|
2016-02-05 20:06:37 +05:30
|
|
|
ocrdma_release_stats_resources(dev);
|
2014-06-10 19:32:24 +05:30
|
|
|
kfree(dev->stag_arr);
|
2012-03-21 04:09:06 +05:30
|
|
|
kfree(dev->qp_tbl);
|
|
|
|
kfree(dev->cq_tbl);
|
|
|
|
}
|
|
|
|
|
|
|
|
static struct ocrdma_dev *ocrdma_add(struct be_dev_info *dev_info)
|
|
|
|
{
|
2018-10-11 22:31:54 +03:00
|
|
|
int status = 0;
|
2015-12-24 13:14:07 -05:00
|
|
|
u8 lstate = 0;
|
2012-03-21 04:09:06 +05:30
|
|
|
struct ocrdma_dev *dev;
|
|
|
|
|
2019-01-30 12:49:11 +02:00
|
|
|
dev = ib_alloc_device(ocrdma_dev, ibdev);
|
2012-03-21 04:09:06 +05:30
|
|
|
if (!dev) {
|
2013-06-10 04:42:39 +00:00
|
|
|
pr_err("Unable to allocate ib device\n");
|
2012-03-21 04:09:06 +05:30
|
|
|
return NULL;
|
|
|
|
}
|
2019-04-04 16:56:57 -03:00
|
|
|
|
2012-03-21 04:09:06 +05:30
|
|
|
dev->mbx_cmd = kzalloc(sizeof(struct ocrdma_mqe_emb_cmd), GFP_KERNEL);
|
|
|
|
if (!dev->mbx_cmd)
|
2019-04-10 05:10:07 -04:00
|
|
|
goto init_err;
|
2012-03-21 04:09:06 +05:30
|
|
|
|
|
|
|
memcpy(&dev->nic_info, dev_info, sizeof(*dev_info));
|
2019-04-10 05:10:07 -04:00
|
|
|
dev->id = PCI_FUNC(dev->nic_info.pdev->devfn);
|
2012-03-21 04:09:06 +05:30
|
|
|
status = ocrdma_init_hw(dev);
|
|
|
|
if (status)
|
|
|
|
goto init_err;
|
|
|
|
|
|
|
|
status = ocrdma_alloc_resources(dev);
|
|
|
|
if (status)
|
|
|
|
goto alloc_err;
|
|
|
|
|
2014-06-10 19:32:13 +05:30
|
|
|
ocrdma_init_service_level(dev);
|
2012-03-21 04:09:06 +05:30
|
|
|
status = ocrdma_register_device(dev);
|
|
|
|
if (status)
|
|
|
|
goto alloc_err;
|
|
|
|
|
2015-12-24 13:14:07 -05:00
|
|
|
/* Query Link state and update */
|
|
|
|
status = ocrdma_mbx_get_link_speed(dev, NULL, &lstate);
|
|
|
|
if (!status)
|
|
|
|
ocrdma_update_link_state(dev, lstate);
|
|
|
|
|
2014-02-04 11:57:07 +05:30
|
|
|
/* Init stats */
|
|
|
|
ocrdma_add_port_stats(dev);
|
2014-12-18 14:13:05 +05:30
|
|
|
/* 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 11:57:07 +05:30
|
|
|
|
|
|
|
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 04:09:06 +05:30
|
|
|
return dev;
|
|
|
|
|
|
|
|
alloc_err:
|
|
|
|
ocrdma_free_resources(dev);
|
|
|
|
ocrdma_cleanup_hw(dev);
|
|
|
|
init_err:
|
|
|
|
kfree(dev->mbx_cmd);
|
|
|
|
ib_dealloc_device(&dev->ibdev);
|
2013-06-10 04:42:39 +00:00
|
|
|
pr_err("%s() leaving. ret=%d\n", __func__, status);
|
2012-03-21 04:09:06 +05:30
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2015-10-20 14:17:56 +05:30
|
|
|
static void ocrdma_remove_free(struct ocrdma_dev *dev)
|
2012-03-21 04:09:06 +05:30
|
|
|
{
|
|
|
|
|
|
|
|
kfree(dev->mbx_cmd);
|
|
|
|
ib_dealloc_device(&dev->ibdev);
|
|
|
|
}
|
|
|
|
|
2012-04-28 07:40:01 +02: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 14:13:05 +05:30
|
|
|
cancel_delayed_work_sync(&dev->eqd_work);
|
2012-04-28 07:40:01 +02:00
|
|
|
ib_unregister_device(&dev->ibdev);
|
2014-12-18 14:13:01 +05:30
|
|
|
|
|
|
|
ocrdma_rem_port_stats(dev);
|
2013-09-06 15:02:47 +05:30
|
|
|
ocrdma_free_resources(dev);
|
|
|
|
ocrdma_cleanup_hw(dev);
|
2015-10-20 14:17:56 +05:30
|
|
|
ocrdma_remove_free(dev);
|
2012-04-28 07:40:01 +02:00
|
|
|
}
|
|
|
|
|
2015-12-24 13:14:07 -05:00
|
|
|
static int ocrdma_dispatch_port_active(struct ocrdma_dev *dev)
|
2012-03-21 04:09:06 +05:30
|
|
|
{
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2015-12-24 13:14:07 -05:00
|
|
|
static int ocrdma_dispatch_port_error(struct ocrdma_dev *dev)
|
2012-03-21 04:09:06 +05:30
|
|
|
{
|
|
|
|
struct ib_event err_event;
|
|
|
|
|
|
|
|
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 19:32:16 +05:30
|
|
|
static void ocrdma_shutdown(struct ocrdma_dev *dev)
|
|
|
|
{
|
2015-12-24 13:14:07 -05:00
|
|
|
ocrdma_dispatch_port_error(dev);
|
2014-06-10 19:32:16 +05:30
|
|
|
ocrdma_remove(dev);
|
|
|
|
}
|
|
|
|
|
2012-03-21 04:09:06 +05:30
|
|
|
/* 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) {
|
2014-06-10 19:32:16 +05:30
|
|
|
case BE_DEV_SHUTDOWN:
|
|
|
|
ocrdma_shutdown(dev);
|
|
|
|
break;
|
2015-12-24 13:14:07 -05:00
|
|
|
default:
|
|
|
|
break;
|
2013-10-08 16:07:22 -07:00
|
|
|
}
|
2012-03-21 04:09:06 +05:30
|
|
|
}
|
|
|
|
|
2015-12-24 13:14:07 -05:00
|
|
|
void ocrdma_update_link_state(struct ocrdma_dev *dev, u8 lstate)
|
|
|
|
{
|
|
|
|
if (!(dev->flags & OCRDMA_FLAGS_LINK_STATUS_INIT)) {
|
|
|
|
dev->flags |= OCRDMA_FLAGS_LINK_STATUS_INIT;
|
|
|
|
if (!lstate)
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!lstate)
|
|
|
|
ocrdma_dispatch_port_error(dev);
|
|
|
|
else
|
|
|
|
ocrdma_dispatch_port_active(dev);
|
|
|
|
}
|
|
|
|
|
2012-04-16 11:36:29 -07:00
|
|
|
static struct ocrdma_driver ocrdma_drv = {
|
2012-03-21 04:09:06 +05:30
|
|
|
.name = "ocrdma_driver",
|
|
|
|
.add = ocrdma_add,
|
|
|
|
.remove = ocrdma_remove,
|
|
|
|
.state_change_handler = ocrdma_event_handler,
|
2014-02-04 11:56:58 +05:30
|
|
|
.be_abi_version = OCRDMA_BE_ROCE_ABI_VERSION,
|
2012-03-21 04:09:06 +05:30
|
|
|
};
|
|
|
|
|
|
|
|
static int __init ocrdma_init_module(void)
|
|
|
|
{
|
|
|
|
int status;
|
|
|
|
|
2014-02-04 11:57:07 +05:30
|
|
|
ocrdma_init_debugfs();
|
|
|
|
|
2012-03-21 04:09:06 +05:30
|
|
|
status = be_roce_register_driver(&ocrdma_drv);
|
|
|
|
if (status)
|
2014-03-18 14:54:56 +05:30
|
|
|
goto err_be_reg;
|
2012-05-02 15:42:33 -07:00
|
|
|
|
2014-03-18 14:54:56 +05:30
|
|
|
return 0;
|
|
|
|
|
|
|
|
err_be_reg:
|
2015-07-30 18:33:31 +03:00
|
|
|
|
2012-03-21 04:09:06 +05:30
|
|
|
return status;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void __exit ocrdma_exit_module(void)
|
|
|
|
{
|
|
|
|
be_roce_unregister_driver(&ocrdma_drv);
|
2014-02-04 11:57:07 +05:30
|
|
|
ocrdma_rem_debugfs();
|
2012-03-21 04:09:06 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
module_init(ocrdma_init_module);
|
|
|
|
module_exit(ocrdma_exit_module);
|