RDMA/drivers: Use core provided API for registering device attributes
Use rdma_set_device_sysfs_group() to register device attributes and simplify the driver. Signed-off-by: Parav Pandit <parav@mellanox.com> Signed-off-by: Leon Romanovsky <leonro@mellanox.com> Signed-off-by: Jason Gunthorpe <jgg@mellanox.com>
Esse commit está contido em:
@@ -1390,13 +1390,13 @@ static inline u32 qib_get_hdrqtail(const struct qib_ctxtdata *rcd)
|
||||
*/
|
||||
|
||||
extern const char ib_qib_version[];
|
||||
extern const struct attribute_group qib_attr_group;
|
||||
|
||||
int qib_device_create(struct qib_devdata *);
|
||||
void qib_device_remove(struct qib_devdata *);
|
||||
|
||||
int qib_create_port_files(struct ib_device *ibdev, u8 port_num,
|
||||
struct kobject *kobj);
|
||||
int qib_verbs_register_sysfs(struct qib_devdata *);
|
||||
void qib_verbs_unregister_sysfs(struct qib_devdata *);
|
||||
/* Hook for sysfs read of QSFP */
|
||||
extern int qib_qsfp_dump(struct qib_pportdata *ppd, char *buf, int len);
|
||||
|
@@ -551,17 +551,18 @@ static struct kobj_type qib_diagc_ktype = {
|
||||
* Start of per-unit (or driver, in some cases, but replicated
|
||||
* per unit) functions (these get a device *)
|
||||
*/
|
||||
static ssize_t show_rev(struct device *device, struct device_attribute *attr,
|
||||
char *buf)
|
||||
static ssize_t hw_rev_show(struct device *device, struct device_attribute *attr,
|
||||
char *buf)
|
||||
{
|
||||
struct qib_ibdev *dev =
|
||||
container_of(device, struct qib_ibdev, rdi.ibdev.dev);
|
||||
|
||||
return sprintf(buf, "%x\n", dd_from_dev(dev)->minrev);
|
||||
}
|
||||
static DEVICE_ATTR_RO(hw_rev);
|
||||
|
||||
static ssize_t show_hca(struct device *device, struct device_attribute *attr,
|
||||
char *buf)
|
||||
static ssize_t hca_type_show(struct device *device,
|
||||
struct device_attribute *attr, char *buf)
|
||||
{
|
||||
struct qib_ibdev *dev =
|
||||
container_of(device, struct qib_ibdev, rdi.ibdev.dev);
|
||||
@@ -574,15 +575,18 @@ static ssize_t show_hca(struct device *device, struct device_attribute *attr,
|
||||
ret = scnprintf(buf, PAGE_SIZE, "%s\n", dd->boardname);
|
||||
return ret;
|
||||
}
|
||||
static DEVICE_ATTR_RO(hca_type);
|
||||
static DEVICE_ATTR(board_id, 0444, hca_type_show, NULL);
|
||||
|
||||
static ssize_t show_version(struct device *device,
|
||||
static ssize_t version_show(struct device *device,
|
||||
struct device_attribute *attr, char *buf)
|
||||
{
|
||||
/* The string printed here is already newline-terminated. */
|
||||
return scnprintf(buf, PAGE_SIZE, "%s", (char *)ib_qib_version);
|
||||
}
|
||||
static DEVICE_ATTR_RO(version);
|
||||
|
||||
static ssize_t show_boardversion(struct device *device,
|
||||
static ssize_t boardversion_show(struct device *device,
|
||||
struct device_attribute *attr, char *buf)
|
||||
{
|
||||
struct qib_ibdev *dev =
|
||||
@@ -592,9 +596,9 @@ static ssize_t show_boardversion(struct device *device,
|
||||
/* The string printed here is already newline-terminated. */
|
||||
return scnprintf(buf, PAGE_SIZE, "%s", dd->boardversion);
|
||||
}
|
||||
static DEVICE_ATTR_RO(boardversion);
|
||||
|
||||
|
||||
static ssize_t show_localbus_info(struct device *device,
|
||||
static ssize_t localbus_info_show(struct device *device,
|
||||
struct device_attribute *attr, char *buf)
|
||||
{
|
||||
struct qib_ibdev *dev =
|
||||
@@ -604,9 +608,9 @@ static ssize_t show_localbus_info(struct device *device,
|
||||
/* The string printed here is already newline-terminated. */
|
||||
return scnprintf(buf, PAGE_SIZE, "%s", dd->lbus_info);
|
||||
}
|
||||
static DEVICE_ATTR_RO(localbus_info);
|
||||
|
||||
|
||||
static ssize_t show_nctxts(struct device *device,
|
||||
static ssize_t nctxts_show(struct device *device,
|
||||
struct device_attribute *attr, char *buf)
|
||||
{
|
||||
struct qib_ibdev *dev =
|
||||
@@ -620,9 +624,10 @@ static ssize_t show_nctxts(struct device *device,
|
||||
(dd->first_user_ctxt > dd->cfgctxts) ? 0 :
|
||||
(dd->cfgctxts - dd->first_user_ctxt));
|
||||
}
|
||||
static DEVICE_ATTR_RO(nctxts);
|
||||
|
||||
static ssize_t show_nfreectxts(struct device *device,
|
||||
struct device_attribute *attr, char *buf)
|
||||
static ssize_t nfreectxts_show(struct device *device,
|
||||
struct device_attribute *attr, char *buf)
|
||||
{
|
||||
struct qib_ibdev *dev =
|
||||
container_of(device, struct qib_ibdev, rdi.ibdev.dev);
|
||||
@@ -631,8 +636,9 @@ static ssize_t show_nfreectxts(struct device *device,
|
||||
/* Return the number of free user ports (contexts) available. */
|
||||
return scnprintf(buf, PAGE_SIZE, "%u\n", dd->freectxts);
|
||||
}
|
||||
static DEVICE_ATTR_RO(nfreectxts);
|
||||
|
||||
static ssize_t show_serial(struct device *device,
|
||||
static ssize_t serial_show(struct device *device,
|
||||
struct device_attribute *attr, char *buf)
|
||||
{
|
||||
struct qib_ibdev *dev =
|
||||
@@ -644,8 +650,9 @@ static ssize_t show_serial(struct device *device,
|
||||
strcat(buf, "\n");
|
||||
return strlen(buf);
|
||||
}
|
||||
static DEVICE_ATTR_RO(serial);
|
||||
|
||||
static ssize_t store_chip_reset(struct device *device,
|
||||
static ssize_t chip_reset_store(struct device *device,
|
||||
struct device_attribute *attr, const char *buf,
|
||||
size_t count)
|
||||
{
|
||||
@@ -663,11 +670,12 @@ static ssize_t store_chip_reset(struct device *device,
|
||||
bail:
|
||||
return ret < 0 ? ret : count;
|
||||
}
|
||||
static DEVICE_ATTR_WO(chip_reset);
|
||||
|
||||
/*
|
||||
* Dump tempsense regs. in decimal, to ease shell-scripts.
|
||||
*/
|
||||
static ssize_t show_tempsense(struct device *device,
|
||||
static ssize_t tempsense_show(struct device *device,
|
||||
struct device_attribute *attr, char *buf)
|
||||
{
|
||||
struct qib_ibdev *dev =
|
||||
@@ -695,6 +703,7 @@ static ssize_t show_tempsense(struct device *device,
|
||||
*(signed char *)(regvals + 7));
|
||||
return ret;
|
||||
}
|
||||
static DEVICE_ATTR_RO(tempsense);
|
||||
|
||||
/*
|
||||
* end of per-unit (or driver, in some cases, but replicated
|
||||
@@ -702,30 +711,23 @@ static ssize_t show_tempsense(struct device *device,
|
||||
*/
|
||||
|
||||
/* start of per-unit file structures and support code */
|
||||
static DEVICE_ATTR(hw_rev, S_IRUGO, show_rev, NULL);
|
||||
static DEVICE_ATTR(hca_type, S_IRUGO, show_hca, NULL);
|
||||
static DEVICE_ATTR(board_id, S_IRUGO, show_hca, NULL);
|
||||
static DEVICE_ATTR(version, S_IRUGO, show_version, NULL);
|
||||
static DEVICE_ATTR(nctxts, S_IRUGO, show_nctxts, NULL);
|
||||
static DEVICE_ATTR(nfreectxts, S_IRUGO, show_nfreectxts, NULL);
|
||||
static DEVICE_ATTR(serial, S_IRUGO, show_serial, NULL);
|
||||
static DEVICE_ATTR(boardversion, S_IRUGO, show_boardversion, NULL);
|
||||
static DEVICE_ATTR(tempsense, S_IRUGO, show_tempsense, NULL);
|
||||
static DEVICE_ATTR(localbus_info, S_IRUGO, show_localbus_info, NULL);
|
||||
static DEVICE_ATTR(chip_reset, S_IWUSR, NULL, store_chip_reset);
|
||||
static struct attribute *qib_attributes[] = {
|
||||
&dev_attr_hw_rev.attr,
|
||||
&dev_attr_hca_type.attr,
|
||||
&dev_attr_board_id.attr,
|
||||
&dev_attr_version.attr,
|
||||
&dev_attr_nctxts.attr,
|
||||
&dev_attr_nfreectxts.attr,
|
||||
&dev_attr_serial.attr,
|
||||
&dev_attr_boardversion.attr,
|
||||
&dev_attr_tempsense.attr,
|
||||
&dev_attr_localbus_info.attr,
|
||||
&dev_attr_chip_reset.attr,
|
||||
NULL,
|
||||
};
|
||||
|
||||
static struct device_attribute *qib_attributes[] = {
|
||||
&dev_attr_hw_rev,
|
||||
&dev_attr_hca_type,
|
||||
&dev_attr_board_id,
|
||||
&dev_attr_version,
|
||||
&dev_attr_nctxts,
|
||||
&dev_attr_nfreectxts,
|
||||
&dev_attr_serial,
|
||||
&dev_attr_boardversion,
|
||||
&dev_attr_tempsense,
|
||||
&dev_attr_localbus_info,
|
||||
&dev_attr_chip_reset,
|
||||
const struct attribute_group qib_attr_group = {
|
||||
.attrs = qib_attributes,
|
||||
};
|
||||
|
||||
int qib_create_port_files(struct ib_device *ibdev, u8 port_num,
|
||||
@@ -826,27 +828,6 @@ bail:
|
||||
return ret;
|
||||
}
|
||||
|
||||
/*
|
||||
* Register and create our files in /sys/class/infiniband.
|
||||
*/
|
||||
int qib_verbs_register_sysfs(struct qib_devdata *dd)
|
||||
{
|
||||
struct ib_device *dev = &dd->verbs_dev.rdi.ibdev;
|
||||
int i, ret;
|
||||
|
||||
for (i = 0; i < ARRAY_SIZE(qib_attributes); ++i) {
|
||||
ret = device_create_file(&dev->dev, qib_attributes[i]);
|
||||
if (ret)
|
||||
goto bail;
|
||||
}
|
||||
|
||||
return 0;
|
||||
bail:
|
||||
for (i = 0; i < ARRAY_SIZE(qib_attributes); ++i)
|
||||
device_remove_file(&dev->dev, qib_attributes[i]);
|
||||
return ret;
|
||||
}
|
||||
|
||||
/*
|
||||
* Unregister and remove our files in /sys/class/infiniband.
|
||||
*/
|
||||
|
@@ -1625,19 +1625,14 @@ int qib_register_ib_device(struct qib_devdata *dd)
|
||||
i,
|
||||
dd->rcd[ctxt]->pkeys);
|
||||
}
|
||||
rdma_set_device_sysfs_group(&dd->verbs_dev.rdi.ibdev, &qib_attr_group);
|
||||
|
||||
ret = rvt_register_device(&dd->verbs_dev.rdi, RDMA_DRIVER_QIB);
|
||||
if (ret)
|
||||
goto err_tx;
|
||||
|
||||
ret = qib_verbs_register_sysfs(dd);
|
||||
if (ret)
|
||||
goto err_class;
|
||||
|
||||
return ret;
|
||||
|
||||
err_class:
|
||||
rvt_unregister_device(&dd->verbs_dev.rdi);
|
||||
err_tx:
|
||||
while (!list_empty(&dev->txreq_free)) {
|
||||
struct list_head *l = dev->txreq_free.next;
|
||||
|
Referência em uma nova issue
Block a user