Skip to content

Commit ecacbcb

Browse files
committed
Merge branch 'master' into backport_ubuntu_16.04.2_4.4.0-62-generic
2 parents b9cd8ec + 5b836d6 commit ecacbcb

File tree

3 files changed

+258
-34
lines changed

3 files changed

+258
-34
lines changed

linux/switchtec.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -301,7 +301,8 @@ struct ntb_info_regs {
301301
u8 partition_count;
302302
u8 partition_id;
303303
u16 reserved1;
304-
u64 ep_map;
304+
u32 ep_map_low;
305+
u32 ep_map_high;
305306
u16 requester_id;
306307
u16 reserved2;
307308
u32 reserved3[4];

ntb_hw_switchtec.c

Lines changed: 253 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -438,7 +438,8 @@ static void switchtec_ntb_part_link_speed(struct switchtec_ntb *sndev,
438438
u32 linksta;
439439

440440
pff = ioread32(&stdev->mmio_part_cfg_all[partition].vep_pff_inst_id);
441-
if (pff == 0xFFFFFFFF) {
441+
pff &= 0xFF;
442+
if (pff == 0xFF) {
442443
dev_warn(&sndev->stdev->dev,
443444
"Invalid pff, setting speed/width to 0");
444445
*speed = 0;
@@ -862,7 +863,9 @@ static int switchtec_ntb_init_sndev(struct switchtec_ntb *sndev)
862863
tpart_vec <<= 32;
863864
tpart_vec |= ioread32(&sndev->mmio_ntb->ntp_info[self].target_part_low);
864865

865-
part_map = ioread64(&sndev->mmio_ntb->ep_map);
866+
part_map = ioread32(&sndev->mmio_ntb->ep_map_high);
867+
part_map <<= 32;
868+
part_map |= ioread32(&sndev->mmio_ntb->ep_map_low);
866869
tpart_vec &= part_map;
867870
part_map &= ~(1 << sndev->self_partition);
868871

@@ -950,20 +953,138 @@ static int config_rsvd_lut_win(struct switchtec_ntb *sndev,
950953
return 0;
951954
}
952955

953-
static int config_req_id_table(struct switchtec_ntb *sndev,
954-
struct ntb_ctrl_regs __iomem *mmio_ctrl,
955-
int *req_ids, int count)
956+
static int add_req_id(struct switchtec_ntb *sndev,
957+
struct ntb_ctrl_regs __iomem *mmio_ctrl, int req_id)
956958
{
957959
int i, rc = 0;
960+
int slot = -1;
958961
u32 error;
959-
u32 proxy_id;
962+
int table_size;
963+
u32 proxy_id = 0;
964+
bool added = true;
965+
966+
table_size = ioread16(&mmio_ctrl->req_id_table_size);
967+
968+
rc = switchtec_ntb_part_op(sndev, mmio_ctrl,
969+
NTB_CTRL_PART_OP_LOCK,
970+
NTB_CTRL_PART_STATUS_LOCKED);
971+
if (rc)
972+
return rc;
973+
974+
iowrite32(NTB_PART_CTRL_ID_PROT_DIS, &mmio_ctrl->partition_ctrl);
960975

961-
if (ioread32(&mmio_ctrl->req_id_table_size) < count) {
976+
for (i = 0; i < table_size; i++) {
977+
proxy_id = ioread32(&mmio_ctrl->req_id_table[i]);
978+
979+
if (!(proxy_id & NTB_CTRL_REQ_ID_EN) && slot == -1)
980+
slot = i;
981+
982+
if (proxy_id & NTB_CTRL_REQ_ID_EN &&
983+
proxy_id >> 16 == req_id) {
984+
goto unlock_exit;
985+
}
986+
}
987+
988+
if (slot == -1) {
962989
dev_err(&sndev->stdev->dev,
963990
"Not enough requester IDs available.\n");
991+
added = false;
992+
} else {
993+
iowrite32(req_id << 16 | NTB_CTRL_REQ_ID_EN,
994+
&mmio_ctrl->req_id_table[slot]);
995+
996+
dev_dbg(&sndev->stdev->dev,
997+
"Requester ID %02X:%02X.%X -> BB:%02X.%X\n",
998+
req_id >> 8, (req_id >> 3) & 0x1F,
999+
req_id & 0x7, (proxy_id >> 4) & 0x1F,
1000+
(proxy_id >> 1) & 0x7);
1001+
added = true;
1002+
}
1003+
1004+
unlock_exit:
1005+
rc = switchtec_ntb_part_op(sndev, mmio_ctrl,
1006+
NTB_CTRL_PART_OP_CFG,
1007+
NTB_CTRL_PART_STATUS_NORMAL);
1008+
1009+
if (rc == -EIO) {
1010+
error = ioread32(&mmio_ctrl->req_id_error);
1011+
dev_err(&sndev->stdev->dev,
1012+
"Error setting up the requester ID table: %08x\n",
1013+
error);
1014+
}
1015+
1016+
if (!added)
9641017
return -EFAULT;
1018+
1019+
return 0;
1020+
}
1021+
1022+
static int del_req_id(struct switchtec_ntb *sndev,
1023+
struct ntb_ctrl_regs __iomem *mmio_ctrl, int req_id)
1024+
{
1025+
int i, rc = 0;
1026+
u32 error;
1027+
int table_size;
1028+
u32 rid;
1029+
bool deleted = true;
1030+
1031+
table_size = ioread16(&mmio_ctrl->req_id_table_size);
1032+
1033+
rc = switchtec_ntb_part_op(sndev, mmio_ctrl,
1034+
NTB_CTRL_PART_OP_LOCK,
1035+
NTB_CTRL_PART_STATUS_LOCKED);
1036+
if (rc)
1037+
return rc;
1038+
1039+
iowrite32(NTB_PART_CTRL_ID_PROT_DIS, &mmio_ctrl->partition_ctrl);
1040+
1041+
for (i = 0; i < table_size; i++) {
1042+
rid = ioread32(&mmio_ctrl->req_id_table[i]);
1043+
1044+
if (!(rid & NTB_CTRL_REQ_ID_EN))
1045+
continue;
1046+
1047+
rid >>= 16;
1048+
if (rid == req_id) {
1049+
iowrite32(0, &mmio_ctrl->req_id_table[i]);
1050+
break;
1051+
}
1052+
}
1053+
1054+
if (i == table_size) {
1055+
dev_err(&sndev->stdev->dev,
1056+
"Requester ID %02X:%02X.%X not in the table.\n",
1057+
PCI_BUS_NUM(req_id), PCI_SLOT(req_id),
1058+
PCI_FUNC(req_id));
1059+
deleted = false;
1060+
}
1061+
1062+
rc = switchtec_ntb_part_op(sndev, mmio_ctrl,
1063+
NTB_CTRL_PART_OP_CFG,
1064+
NTB_CTRL_PART_STATUS_NORMAL);
1065+
1066+
if (rc == -EIO) {
1067+
error = ioread32(&mmio_ctrl->req_id_error);
1068+
dev_err(&sndev->stdev->dev,
1069+
"Error setting up the requester ID table: %08x\n",
1070+
error);
9651071
}
9661072

1073+
if (!deleted)
1074+
return -ENXIO;
1075+
1076+
return 0;
1077+
}
1078+
1079+
static int clr_req_ids(struct switchtec_ntb *sndev,
1080+
struct ntb_ctrl_regs __iomem *mmio_ctrl)
1081+
{
1082+
int i, rc = 0;
1083+
u32 error;
1084+
int table_size;
1085+
1086+
table_size = ioread16(&mmio_ctrl->req_id_table_size);
1087+
9671088
rc = switchtec_ntb_part_op(sndev, mmio_ctrl,
9681089
NTB_CTRL_PART_OP_LOCK,
9691090
NTB_CTRL_PART_STATUS_LOCKED);
@@ -973,17 +1094,8 @@ static int config_req_id_table(struct switchtec_ntb *sndev,
9731094
iowrite32(NTB_PART_CTRL_ID_PROT_DIS,
9741095
&mmio_ctrl->partition_ctrl);
9751096

976-
for (i = 0; i < count; i++) {
977-
iowrite32(req_ids[i] << 16 | NTB_CTRL_REQ_ID_EN,
978-
&mmio_ctrl->req_id_table[i]);
979-
980-
proxy_id = ioread32(&mmio_ctrl->req_id_table[i]);
981-
dev_dbg(&sndev->stdev->dev,
982-
"Requester ID %02X:%02X.%X -> BB:%02X.%X\n",
983-
req_ids[i] >> 8, (req_ids[i] >> 3) & 0x1F,
984-
req_ids[i] & 0x7, (proxy_id >> 4) & 0x1F,
985-
(proxy_id >> 1) & 0x7);
986-
}
1097+
for (i = 0; i < table_size; i++)
1098+
iowrite32(0, &mmio_ctrl->req_id_table[i]);
9871099

9881100
rc = switchtec_ntb_part_op(sndev, mmio_ctrl,
9891101
NTB_CTRL_PART_OP_CFG,
@@ -1068,20 +1180,28 @@ static int crosslink_setup_mws(struct switchtec_ntb *sndev, int ntb_lut_idx,
10681180
static int crosslink_setup_req_ids(struct switchtec_ntb *sndev,
10691181
struct ntb_ctrl_regs __iomem *mmio_ctrl)
10701182
{
1071-
int req_ids[16];
10721183
int i;
10731184
u32 proxy_id;
1185+
int table_size;
1186+
int rc;
10741187

1075-
for (i = 0; i < ARRAY_SIZE(req_ids); i++) {
1188+
table_size = ioread16(&mmio_ctrl->req_id_table_size);
1189+
1190+
clr_req_ids(sndev, mmio_ctrl);
1191+
1192+
for (i = 0; i < table_size; i++) {
10761193
proxy_id = ioread32(&sndev->mmio_self_ctrl->req_id_table[i]);
10771194

10781195
if (!(proxy_id & NTB_CTRL_REQ_ID_EN))
1079-
break;
1196+
continue;
10801197

1081-
req_ids[i] = ((proxy_id >> 1) & 0xFF);
1198+
proxy_id = ((proxy_id >> 1) & 0xFF);
1199+
rc = add_req_id(sndev, mmio_ctrl, proxy_id);
1200+
if (rc)
1201+
return rc;
10821202
}
10831203

1084-
return config_req_id_table(sndev, mmio_ctrl, req_ids, i);
1204+
return 0;
10851205
}
10861206

10871207
/*
@@ -1094,7 +1214,7 @@ static int crosslink_enum_partition(struct switchtec_ntb *sndev,
10941214
{
10951215
struct part_cfg_regs __iomem *part_cfg =
10961216
&sndev->stdev->mmio_part_cfg_all[sndev->peer_partition];
1097-
u32 pff = ioread32(&part_cfg->vep_pff_inst_id);
1217+
u32 pff = ioread32(&part_cfg->vep_pff_inst_id) & 0xFF;
10981218
struct pff_csr_regs __iomem *mmio_pff =
10991219
&sndev->stdev->mmio_pff_csr[pff];
11001220
const u64 bar_space = 0x1000000000LL;
@@ -1281,20 +1401,21 @@ static void switchtec_ntb_init_msgs(struct switchtec_ntb *sndev)
12811401
static int
12821402
switchtec_ntb_init_req_id_table(struct switchtec_ntb *sndev)
12831403
{
1284-
int req_ids[2];
1404+
int req_id;
1405+
int rc;
12851406

12861407
/*
12871408
* Root Complex Requester ID (which is 0:00.0)
12881409
*/
1289-
req_ids[0] = 0;
1410+
rc = add_req_id(sndev, sndev->mmio_self_ctrl, 0);
1411+
if (rc)
1412+
return rc;
12901413

12911414
/*
12921415
* Host Bridge Requester ID (as read from the mmap address)
12931416
*/
1294-
req_ids[1] = ioread16(&sndev->mmio_ntb->requester_id);
1295-
1296-
return config_req_id_table(sndev, sndev->mmio_self_ctrl, req_ids,
1297-
ARRAY_SIZE(req_ids));
1417+
req_id = ioread16(&sndev->mmio_ntb->requester_id);
1418+
return add_req_id(sndev, sndev->mmio_self_ctrl, req_id);
12981419
}
12991420

13001421
static void switchtec_ntb_init_shared(struct switchtec_ntb *sndev)
@@ -1475,6 +1596,102 @@ static int switchtec_ntb_reinit_peer(struct switchtec_ntb *sndev)
14751596
return rc;
14761597
}
14771598

1599+
static ssize_t add_requester_id_store(struct device *dev,
1600+
struct device_attribute *attr,
1601+
const char *buf, size_t count)
1602+
{
1603+
struct ntb_dev *ntb = container_of(dev, struct ntb_dev, dev);
1604+
struct switchtec_ntb *sndev = ntb_sndev(ntb);
1605+
int req_id;
1606+
int bus, device, func;
1607+
int rc;
1608+
1609+
if (sscanf(buf, "%x:%x.%x", &bus, &device, &func) != 3)
1610+
return -EINVAL;
1611+
1612+
req_id = PCI_DEVID(bus, PCI_DEVFN(device, func));
1613+
rc = add_req_id(sndev, sndev->mmio_self_ctrl, req_id);
1614+
if (rc)
1615+
return rc;
1616+
1617+
if (crosslink_is_enabled(sndev)) {
1618+
rc = crosslink_setup_req_ids(sndev, sndev->mmio_peer_ctrl);
1619+
if (rc)
1620+
return rc;
1621+
}
1622+
1623+
return count;
1624+
}
1625+
static DEVICE_ATTR_WO(add_requester_id);
1626+
1627+
static ssize_t del_requester_id_store(struct device *dev,
1628+
struct device_attribute *attr,
1629+
const char *buf, size_t count)
1630+
{
1631+
struct ntb_dev *ntb = container_of(dev, struct ntb_dev, dev);
1632+
struct switchtec_ntb *sndev = ntb_sndev(ntb);
1633+
int req_id;
1634+
int bus, device, func;
1635+
int rc;
1636+
1637+
if (sscanf(buf, "%x:%x.%x", &bus, &device, &func) != 3)
1638+
return -EINVAL;
1639+
1640+
req_id = PCI_DEVID(bus, PCI_DEVFN(device, func));
1641+
rc = del_req_id(sndev, sndev->mmio_self_ctrl, req_id);
1642+
if (rc)
1643+
return rc;
1644+
1645+
if (crosslink_is_enabled(sndev)) {
1646+
rc = crosslink_setup_req_ids(sndev, sndev->mmio_peer_ctrl);
1647+
if (rc)
1648+
return rc;
1649+
}
1650+
1651+
return count;
1652+
}
1653+
static DEVICE_ATTR_WO(del_requester_id);
1654+
1655+
static ssize_t requester_ids_show(struct device *dev,
1656+
struct device_attribute *attr, char *buf)
1657+
{
1658+
struct ntb_dev *ntb = container_of(dev, struct ntb_dev, dev);
1659+
struct switchtec_ntb *sndev = ntb_sndev(ntb);
1660+
int i;
1661+
int table_size;
1662+
char req_id_str[32];
1663+
u32 req_id;
1664+
ssize_t n = 0;
1665+
1666+
table_size = ioread16(&sndev->mmio_self_ctrl->req_id_table_size);
1667+
1668+
for (i = 0; i < table_size; i++) {
1669+
req_id = ioread32(&sndev->mmio_self_ctrl->req_id_table[i]);
1670+
1671+
if (req_id & NTB_CTRL_REQ_ID_EN) {
1672+
req_id >>= 16;
1673+
n += sprintf(req_id_str, "%d\t%02X:%02X.%X\n", i,
1674+
PCI_BUS_NUM(req_id), PCI_SLOT(req_id),
1675+
PCI_FUNC(req_id));
1676+
strcat(buf, req_id_str);
1677+
}
1678+
}
1679+
1680+
return n;
1681+
}
1682+
static DEVICE_ATTR_RO(requester_ids);
1683+
1684+
static struct attribute *switchtec_ntb_device_attrs[] = {
1685+
&dev_attr_add_requester_id.attr,
1686+
&dev_attr_del_requester_id.attr,
1687+
&dev_attr_requester_ids.attr,
1688+
NULL,
1689+
};
1690+
1691+
static const struct attribute_group switchtec_ntb_device_group = {
1692+
.attrs = switchtec_ntb_device_attrs,
1693+
};
1694+
14781695
static int switchtec_ntb_add(struct device *dev,
14791696
struct class_interface *class_intf)
14801697
{
@@ -1528,6 +1745,11 @@ static int switchtec_ntb_add(struct device *dev,
15281745
if (rc)
15291746
goto deinit_and_exit;
15301747

1748+
rc = sysfs_create_group(&sndev->ntb.dev.kobj,
1749+
&switchtec_ntb_device_group);
1750+
if (rc)
1751+
goto deinit_and_exit;
1752+
15311753
stdev->sndev = sndev;
15321754
stdev->link_notifier = switchtec_ntb_link_notification;
15331755
dev_info(dev, "NTB device registered\n");
@@ -1557,6 +1779,7 @@ static void switchtec_ntb_remove(struct device *dev,
15571779

15581780
stdev->link_notifier = NULL;
15591781
stdev->sndev = NULL;
1782+
sysfs_remove_group(&sndev->ntb.dev.kobj, &switchtec_ntb_device_group);
15601783
ntb_unregister_device(&sndev->ntb);
15611784
switchtec_ntb_deinit_db_msg_irq(sndev);
15621785
switchtec_ntb_deinit_shared_mw(sndev);

0 commit comments

Comments
 (0)