Skip to content

Commit

Permalink
Merge branch 'devel'
Browse files Browse the repository at this point in the history
  • Loading branch information
kelvin-cao committed Sep 17, 2021
2 parents 958e6f6 + ad8f1c8 commit e459e54
Show file tree
Hide file tree
Showing 2 changed files with 75 additions and 26 deletions.
83 changes: 66 additions & 17 deletions ntb_hw_switchtec.c
Original file line number Diff line number Diff line change
Expand Up @@ -134,9 +134,9 @@ static struct switchtec_ntb *ntb_sndev(struct ntb_dev *ntb)
return container_of(ntb, struct switchtec_ntb, ntb);
}

static int switchtec_ntb_part_op(struct switchtec_ntb *sndev,
struct ntb_ctrl_regs __iomem *ctl,
u32 op, int wait_status)
static int switchtec_ntb_part_op_no_retry(struct switchtec_ntb *sndev,
struct ntb_ctrl_regs __iomem *ctl,
u32 op, int wait_status)
{
static const char * const op_text[] = {
[NTB_CTRL_PART_OP_LOCK] = "lock",
Expand All @@ -147,6 +147,24 @@ static int switchtec_ntb_part_op(struct switchtec_ntb *sndev,
int i;
u32 ps;
int status;
int part_id, locked_part_id;
int xlink_peer = ctl == sndev->mmio_xlink_peer_ctrl ? 1 : 0;

ps = ioread32(&ctl->partition_status);

locked_part_id = (ps & 0xFF0000) >> 16;
part_id = (ps & 0xFF000000) >> 24;

ps &= 0xFFFF;

if (ps != NTB_CTRL_PART_STATUS_NORMAL &&
ps != NTB_CTRL_PART_STATUS_LOCKED)
return -EAGAIN;

if (ps == NTB_CTRL_PART_STATUS_LOCKED)
if ((xlink_peer && (locked_part_id != part_id)) ||
(!xlink_peer && (locked_part_id != sndev->self_partition)))
return -EAGAIN;

switch (op) {
case NTB_CTRL_PART_OP_LOCK:
Expand All @@ -170,12 +188,24 @@ static int switchtec_ntb_part_op(struct switchtec_ntb *sndev,
return -EINTR;
}

ps = ioread32(&ctl->partition_status) & 0xFFFF;
ps = ioread32(&ctl->partition_status);

locked_part_id = (ps & 0xFF0000) >> 16;
part_id = (ps & 0xFF000000) >> 24;

ps &= 0xFFFF;

if (ps != status)
break;
}

if (ps == NTB_CTRL_PART_STATUS_LOCKED) {
if ((xlink_peer && (locked_part_id != part_id)) ||
(!xlink_peer &&
(locked_part_id != sndev->self_partition)))
return -EAGAIN;
}

if (ps == wait_status)
return 0;

Expand All @@ -191,6 +221,28 @@ static int switchtec_ntb_part_op(struct switchtec_ntb *sndev,
return -EIO;
}

static int switchtec_ntb_part_op(struct switchtec_ntb *sndev,
struct ntb_ctrl_regs __iomem *ctl,
u32 op, int wait_status)
{
int rc;
int i = 0;

while (i++ < 10) {
rc = switchtec_ntb_part_op_no_retry(sndev, ctl, op,
wait_status);
if (rc == -EAGAIN) {
if (msleep_interruptible(30) != 0)
return -EINTR;
continue;
}

break;
}

return rc;
}

static int switchtec_ntb_send_msg(struct switchtec_ntb *sndev, int idx,
u32 val)
{
Expand Down Expand Up @@ -536,14 +588,21 @@ enum switchtec_msg {

static int switchtec_ntb_reinit_peer(struct switchtec_ntb *sndev);

static int crosslink_setup_req_ids(struct switchtec_ntb *sndev,
struct ntb_ctrl_regs __iomem *mmio_ctrl);

static void switchtec_ntb_link_status_update(struct switchtec_ntb *sndev)
{
int link_sta;
int old = sndev->link_is_up;
u64 peer;

link_sta = sndev->self_shared->link_sta;
if (link_sta) {
u64 peer = ioread64(&sndev->peer_shared->magic);
if (!sndev->link_is_up && crosslink_is_enabled(sndev))
crosslink_setup_req_ids(sndev, sndev->mmio_xlink_peer_ctrl);

peer = ioread64(&sndev->peer_shared->magic);

if ((peer & 0xFFFFFFFF) == SWITCHTEC_NTB_MAGIC)
link_sta = peer >> 32;
Expand Down Expand Up @@ -618,9 +677,6 @@ static u64 switchtec_ntb_link_is_up(struct ntb_dev *ntb,
return sndev->link_is_up;
}

static int crosslink_setup_req_ids(struct switchtec_ntb *sndev,
struct ntb_ctrl_regs __iomem *mmio_ctrl);

static int switchtec_ntb_link_enable(struct ntb_dev *ntb,
enum ntb_speed max_speed,
enum ntb_width max_width)
Expand All @@ -632,11 +688,6 @@ static int switchtec_ntb_link_enable(struct ntb_dev *ntb,
sndev->self_shared->link_sta = 1;
switchtec_ntb_send_msg(sndev, LINK_MESSAGE, MSG_LINK_UP);

if (crosslink_is_enabled(sndev))
crosslink_setup_req_ids(sndev, sndev->mmio_xlink_peer_ctrl);

switchtec_ntb_link_status_update(sndev);

return 0;
}

Expand Down Expand Up @@ -1364,10 +1415,6 @@ static int switchtec_ntb_init_crosslink(struct switchtec_ntb *sndev)
if (rc)
return rc;

crosslink_init_dbmsgs(sndev);

crosslink_setup_req_ids(sndev, sndev->mmio_xlink_peer_ctrl);

return 0;
}

Expand Down Expand Up @@ -1853,6 +1900,8 @@ static void switchtec_ntb_remove(struct device *dev,
if (!sndev)
return;

flush_scheduled_work();

stdev->link_notifier = NULL;
stdev->sndev = NULL;
sysfs_remove_group(&sndev->ntb.dev.kobj, &switchtec_ntb_device_group);
Expand Down
18 changes: 9 additions & 9 deletions switchtec.c
Original file line number Diff line number Diff line change
Expand Up @@ -328,7 +328,7 @@ static ssize_t device_version_show(struct device *dev,

ver = ioread32(&stdev->mmio_sys_info->device_version);

return sprintf(buf, "%x\n", ver);
return sysfs_emit(buf, "%x\n", ver);
}
static DEVICE_ATTR_RO(device_version);

Expand All @@ -340,7 +340,7 @@ static ssize_t fw_version_show(struct device *dev,

ver = ioread32(&stdev->mmio_sys_info->firmware_version);

return sprintf(buf, "%08x\n", ver);
return sysfs_emit(buf, "%08x\n", ver);
}
static DEVICE_ATTR_RO(fw_version);

Expand Down Expand Up @@ -392,7 +392,7 @@ static ssize_t component_vendor_show(struct device *dev,

/* component_vendor field not supported after gen3 */
if (stdev->gen != SWITCHTEC_GEN3)
return sprintf(buf, "none\n");
return sysfs_emit(buf, "none\n");

return io_string_show(buf, &si->gen3.component_vendor,
sizeof(si->gen3.component_vendor));
Expand All @@ -407,9 +407,9 @@ static ssize_t component_id_show(struct device *dev,

/* component_id field not supported after gen3 */
if (stdev->gen != SWITCHTEC_GEN3)
return sprintf(buf, "none\n");
return sysfs_emit(buf, "none\n");

return sprintf(buf, "PM%04X\n", id);
return sysfs_emit(buf, "PM%04X\n", id);
}
static DEVICE_ATTR_RO(component_id);

Expand All @@ -421,9 +421,9 @@ static ssize_t component_revision_show(struct device *dev,

/* component_revision field not supported after gen3 */
if (stdev->gen != SWITCHTEC_GEN3)
return sprintf(buf, "255\n");
return sysfs_emit(buf, "255\n");

return sprintf(buf, "%d\n", rev);
return sysfs_emit(buf, "%d\n", rev);
}
static DEVICE_ATTR_RO(component_revision);

Expand All @@ -432,7 +432,7 @@ static ssize_t partition_show(struct device *dev,
{
struct switchtec_dev *stdev = to_stdev(dev);

return sprintf(buf, "%d\n", stdev->partition);
return sysfs_emit(buf, "%d\n", stdev->partition);
}
static DEVICE_ATTR_RO(partition);

Expand All @@ -441,7 +441,7 @@ static ssize_t partition_count_show(struct device *dev,
{
struct switchtec_dev *stdev = to_stdev(dev);

return sprintf(buf, "%d\n", stdev->partition_count);
return sysfs_emit(buf, "%d\n", stdev->partition_count);
}
static DEVICE_ATTR_RO(partition_count);

Expand Down

0 comments on commit e459e54

Please sign in to comment.