From afdd1126940068ef06c2b4b08b85a47a3eafba5b Mon Sep 17 00:00:00 2001 From: Muneendra Kumar Date: Thu, 7 Jan 2021 03:19:07 +0530 Subject: scsi: scsi_transport_fc: Add store capability to rport port_state in sysfs Add store capability to the rport port_state using sysfs under fc_remote_ports/rport-*/port_state. With this the user can move the port_state from Marginal->Online and Online->Marginal. - Marginal: This interface will set SCMD_NORETRIES_ABORT bit in scmd->state for all the pending I/Os on the SCSI device associated with target port. - Online: This interface will clear SCMD_NORETRIES_ABORT bit in scmd->state for all the pending I/Os on the SCSI device associated with target port. The following interface is provided to set the port state to Marginal and Online respectively: echo "Marginal" >> /sys/class/fc_remote_ports/rport-X\:Y-Z/port_state echo "Online" >> /sys/class/fc_remote_ports/rport-X\:Y-Z/port_state Link: https://lore.kernel.org/r/1609969748-17684-5-git-send-email-muneendra.kumar@broadcom.com Reviewed-by: Himanshu Madhani Reviewed-by: Ewan D. Milne Reviewed-by: Hannes Reinecke Signed-off-by: Muneendra Kumar Signed-off-by: Martin K. Petersen --- drivers/scsi/scsi_transport_fc.c | 56 ++++++++++++++++++++++++++++++++++++++-- 1 file changed, 54 insertions(+), 2 deletions(-) (limited to 'drivers/scsi/scsi_transport_fc.c') diff --git a/drivers/scsi/scsi_transport_fc.c b/drivers/scsi/scsi_transport_fc.c index ffd25195ae62..da5b503dc7a1 100644 --- a/drivers/scsi/scsi_transport_fc.c +++ b/drivers/scsi/scsi_transport_fc.c @@ -1238,7 +1238,59 @@ show_fc_rport_roles (struct device *dev, struct device_attribute *attr, static FC_DEVICE_ATTR(rport, roles, S_IRUGO, show_fc_rport_roles, NULL); -fc_private_rport_rd_enum_attr(port_state, FC_PORTSTATE_MAX_NAMELEN); +static ssize_t fc_rport_set_marginal_state(struct device *dev, + struct device_attribute *attr, + const char *buf, size_t count) +{ + struct fc_rport *rport = transport_class_to_rport(dev); + enum fc_port_state port_state; + int ret = 0; + + ret = get_fc_port_state_match(buf, &port_state); + if (ret) + return -EINVAL; + if (port_state == FC_PORTSTATE_MARGINAL) { + /* + * Change the state to Marginal only if the + * current rport state is Online + * Allow only Online->Marginal + */ + if (rport->port_state == FC_PORTSTATE_ONLINE) + rport->port_state = port_state; + else + return -EINVAL; + } else if (port_state == FC_PORTSTATE_ONLINE) { + /* + * Change the state to Online only if the + * current rport state is Marginal + * Allow only Marginal->Online + */ + if (rport->port_state == FC_PORTSTATE_MARGINAL) + rport->port_state = port_state; + else + return -EINVAL; + } else + return -EINVAL; + return count; +} + +static ssize_t +show_fc_rport_port_state(struct device *dev, + struct device_attribute *attr, char *buf) +{ + const char *name; + struct fc_rport *rport = transport_class_to_rport(dev); + + name = get_fc_port_state_name(rport->port_state); + if (!name) + return -EINVAL; + + return snprintf(buf, 20, "%s\n", name); +} + +static FC_DEVICE_ATTR(rport, port_state, 0444 | 0200, + show_fc_rport_port_state, fc_rport_set_marginal_state); + fc_private_rport_rd_attr(scsi_target_id, "%d\n", 20); /* @@ -2681,7 +2733,7 @@ fc_attach_transport(struct fc_function_template *ft) SETUP_PRIVATE_RPORT_ATTRIBUTE_RD(port_name); SETUP_PRIVATE_RPORT_ATTRIBUTE_RD(port_id); SETUP_PRIVATE_RPORT_ATTRIBUTE_RD(roles); - SETUP_PRIVATE_RPORT_ATTRIBUTE_RD(port_state); + SETUP_PRIVATE_RPORT_ATTRIBUTE_RW(port_state); SETUP_PRIVATE_RPORT_ATTRIBUTE_RD(scsi_target_id); SETUP_PRIVATE_RPORT_ATTRIBUTE_RW(fast_io_fail_tmo); -- cgit v1.2.3