Skip to content

Commit 89c36a8

Browse files
committed
Introduce sysfs attributes for requester ID ops
Introduce sysfs attributes add_requester_id, del_requester_id and requester_ids for to adding, deleting and showing requester IDs dynamically at run time.
1 parent 0350588 commit 89c36a8

File tree

1 file changed

+104
-2
lines changed

1 file changed

+104
-2
lines changed

ntb_hw_switchtec.c

Lines changed: 104 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1058,8 +1058,8 @@ static int add_req_id(struct switchtec_ntb *sndev,
10581058
return 0;
10591059
}
10601060

1061-
int del_req_id(struct switchtec_ntb *sndev,
1062-
struct ntb_ctrl_regs __iomem *mmio_ctrl, int req_id)
1061+
static int del_req_id(struct switchtec_ntb *sndev,
1062+
struct ntb_ctrl_regs __iomem *mmio_ctrl, int req_id)
10631063
{
10641064
int i, rc = 0;
10651065
u32 error;
@@ -1636,6 +1636,102 @@ static int switchtec_ntb_reinit_peer(struct switchtec_ntb *sndev)
16361636
return rc;
16371637
}
16381638

1639+
static ssize_t add_requester_id_store(struct device *dev,
1640+
struct device_attribute *attr,
1641+
const char *buf, size_t count)
1642+
{
1643+
struct ntb_dev *ntb = container_of(dev, struct ntb_dev, dev);
1644+
struct switchtec_ntb *sndev = ntb_sndev(ntb);
1645+
int req_id;
1646+
int bus, device, func;
1647+
int rc;
1648+
1649+
if (sscanf(buf, "%x:%x.%x", &bus, &device, &func) != 3)
1650+
return -EINVAL;
1651+
1652+
req_id = PCI_DEVID(bus, PCI_DEVFN(device, func));
1653+
rc = add_req_id(sndev, sndev->mmio_self_ctrl, req_id);
1654+
if (rc)
1655+
return rc;
1656+
1657+
if (crosslink_is_enabled(sndev)) {
1658+
rc = crosslink_setup_req_ids(sndev, sndev->mmio_peer_ctrl);
1659+
if (rc)
1660+
return rc;
1661+
}
1662+
1663+
return count;
1664+
}
1665+
static DEVICE_ATTR_WO(add_requester_id);
1666+
1667+
static ssize_t del_requester_id_store(struct device *dev,
1668+
struct device_attribute *attr,
1669+
const char *buf, size_t count)
1670+
{
1671+
struct ntb_dev *ntb = container_of(dev, struct ntb_dev, dev);
1672+
struct switchtec_ntb *sndev = ntb_sndev(ntb);
1673+
int req_id;
1674+
int bus, device, func;
1675+
int rc;
1676+
1677+
if (sscanf(buf, "%x:%x.%x", &bus, &device, &func) != 3)
1678+
return -EINVAL;
1679+
1680+
req_id = PCI_DEVID(bus, PCI_DEVFN(device, func));
1681+
rc = del_req_id(sndev, sndev->mmio_self_ctrl, req_id);
1682+
if (rc)
1683+
return rc;
1684+
1685+
if (crosslink_is_enabled(sndev)) {
1686+
rc = crosslink_setup_req_ids(sndev, sndev->mmio_peer_ctrl);
1687+
if (rc)
1688+
return rc;
1689+
}
1690+
1691+
return count;
1692+
}
1693+
static DEVICE_ATTR_WO(del_requester_id);
1694+
1695+
static ssize_t requester_ids_show(struct device *dev,
1696+
struct device_attribute *attr, char *buf)
1697+
{
1698+
struct ntb_dev *ntb = container_of(dev, struct ntb_dev, dev);
1699+
struct switchtec_ntb *sndev = ntb_sndev(ntb);
1700+
int i;
1701+
int table_size;
1702+
char req_id_str[32];
1703+
u32 req_id;
1704+
ssize_t n = 0;
1705+
1706+
table_size = ioread16(&sndev->mmio_self_ctrl->req_id_table_size);
1707+
1708+
for (i = 0; i < table_size; i++) {
1709+
req_id = ioread32(&sndev->mmio_self_ctrl->req_id_table[i]);
1710+
1711+
if (req_id & NTB_CTRL_REQ_ID_EN) {
1712+
req_id >>= 16;
1713+
n += sprintf(req_id_str, "%d\t%02X:%02X.%X\n", i,
1714+
PCI_BUS_NUM(req_id), PCI_SLOT(req_id),
1715+
PCI_FUNC(req_id));
1716+
strcat(buf, req_id_str);
1717+
}
1718+
}
1719+
1720+
return n;
1721+
}
1722+
static DEVICE_ATTR_RO(requester_ids);
1723+
1724+
static struct attribute *switchtec_ntb_device_attrs[] = {
1725+
&dev_attr_add_requester_id.attr,
1726+
&dev_attr_del_requester_id.attr,
1727+
&dev_attr_requester_ids.attr,
1728+
NULL,
1729+
};
1730+
1731+
static const struct attribute_group switchtec_ntb_device_group = {
1732+
.attrs = switchtec_ntb_device_attrs,
1733+
};
1734+
16391735
static int switchtec_ntb_add(struct device *dev,
16401736
struct class_interface *class_intf)
16411737
{
@@ -1689,6 +1785,11 @@ static int switchtec_ntb_add(struct device *dev,
16891785
if (rc)
16901786
goto deinit_and_exit;
16911787

1788+
rc = sysfs_create_group(&sndev->ntb.dev.kobj,
1789+
&switchtec_ntb_device_group);
1790+
if (rc)
1791+
goto deinit_and_exit;
1792+
16921793
stdev->sndev = sndev;
16931794
stdev->link_notifier = switchtec_ntb_link_notification;
16941795
dev_info(dev, "NTB device registered\n");
@@ -1718,6 +1819,7 @@ static void switchtec_ntb_remove(struct device *dev,
17181819

17191820
stdev->link_notifier = NULL;
17201821
stdev->sndev = NULL;
1822+
sysfs_remove_group(&sndev->ntb.dev.kobj, &switchtec_ntb_device_group);
17211823
ntb_unregister_device(&sndev->ntb);
17221824
switchtec_ntb_deinit_db_msg_irq(sndev);
17231825
switchtec_ntb_deinit_shared_mw(sndev);

0 commit comments

Comments
 (0)