Commit 1e49a538 authored by Martin K. Petersen's avatar Martin K. Petersen

Merge patch series "scsi: libsas: Some coding style fixes and cleanups"

Jason Yan <yanaijie@huawei.com> says:

A few coding style fixes and cleanups. There should be no functional
changes in this series besides the debug log prints.

Link: https://lore.kernel.org/r/20221214133808.1649122-1-yanaijie@huawei.comSigned-off-by: default avatarMartin K. Petersen <martin.petersen@oracle.com>
parents 1b929c02 5d39b77c
...@@ -239,7 +239,17 @@ static struct sas_internal *dev_to_sas_internal(struct domain_device *dev) ...@@ -239,7 +239,17 @@ static struct sas_internal *dev_to_sas_internal(struct domain_device *dev)
return to_sas_internal(dev->port->ha->core.shost->transportt); return to_sas_internal(dev->port->ha->core.shost->transportt);
} }
static int sas_get_ata_command_set(struct domain_device *dev); static int sas_get_ata_command_set(struct domain_device *dev)
{
struct ata_taskfile tf;
if (dev->dev_type == SAS_SATA_PENDING)
return ATA_DEV_UNKNOWN;
ata_tf_from_fis(dev->frame_rcvd, &tf);
return ata_dev_classify(&tf);
}
int sas_get_ata_info(struct domain_device *dev, struct ex_phy *phy) int sas_get_ata_info(struct domain_device *dev, struct ex_phy *phy)
{ {
...@@ -637,20 +647,6 @@ void sas_ata_task_abort(struct sas_task *task) ...@@ -637,20 +647,6 @@ void sas_ata_task_abort(struct sas_task *task)
complete(waiting); complete(waiting);
} }
static int sas_get_ata_command_set(struct domain_device *dev)
{
struct dev_to_host_fis *fis =
(struct dev_to_host_fis *) dev->frame_rcvd;
struct ata_taskfile tf;
if (dev->dev_type == SAS_SATA_PENDING)
return ATA_DEV_UNKNOWN;
ata_tf_from_fis((const u8 *)fis, &tf);
return ata_dev_classify(&tf);
}
void sas_probe_sata(struct asd_sas_port *port) void sas_probe_sata(struct asd_sas_port *port)
{ {
struct domain_device *dev, *n; struct domain_device *dev, *n;
...@@ -679,6 +675,68 @@ void sas_probe_sata(struct asd_sas_port *port) ...@@ -679,6 +675,68 @@ void sas_probe_sata(struct asd_sas_port *port)
} }
int sas_ata_add_dev(struct domain_device *parent, struct ex_phy *phy,
struct domain_device *child, int phy_id)
{
struct sas_rphy *rphy;
int ret;
if (child->linkrate > parent->min_linkrate) {
struct sas_phy *cphy = child->phy;
enum sas_linkrate min_prate = cphy->minimum_linkrate,
parent_min_lrate = parent->min_linkrate,
min_linkrate = (min_prate > parent_min_lrate) ?
parent_min_lrate : 0;
struct sas_phy_linkrates rates = {
.maximum_linkrate = parent->min_linkrate,
.minimum_linkrate = min_linkrate,
};
pr_notice("ex %016llx phy%02d SATA device linkrate > min pathway connection rate, attempting to lower device linkrate\n",
SAS_ADDR(child->sas_addr), phy_id);
ret = sas_smp_phy_control(parent, phy_id,
PHY_FUNC_LINK_RESET, &rates);
if (ret) {
pr_err("ex %016llx phy%02d SATA device could not set linkrate (%d)\n",
SAS_ADDR(child->sas_addr), phy_id, ret);
return ret;
}
pr_notice("ex %016llx phy%02d SATA device set linkrate successfully\n",
SAS_ADDR(child->sas_addr), phy_id);
child->linkrate = child->min_linkrate;
}
ret = sas_get_ata_info(child, phy);
if (ret)
return ret;
sas_init_dev(child);
ret = sas_ata_init(child);
if (ret)
return ret;
rphy = sas_end_device_alloc(phy->port);
if (!rphy)
return ret;
rphy->identify.phy_identifier = phy_id;
child->rphy = rphy;
get_device(&rphy->dev);
list_add_tail(&child->disco_list_node, &parent->port->disco_list);
ret = sas_discover_sata(child);
if (ret) {
pr_notice("sas_discover_sata() for device %16llx at %016llx:%02d returned 0x%x\n",
SAS_ADDR(child->sas_addr),
SAS_ADDR(parent->sas_addr), phy_id, ret);
sas_rphy_free(child->rphy);
list_del(&child->disco_list_node);
return ret;
}
return 0;
}
static void sas_ata_flush_pm_eh(struct asd_sas_port *port, const char *func) static void sas_ata_flush_pm_eh(struct asd_sas_port *port, const char *func)
{ {
struct domain_device *dev, *n; struct domain_device *dev, *n;
......
...@@ -455,14 +455,8 @@ static void sas_discover_domain(struct work_struct *work) ...@@ -455,14 +455,8 @@ static void sas_discover_domain(struct work_struct *work)
break; break;
case SAS_SATA_DEV: case SAS_SATA_DEV:
case SAS_SATA_PM: case SAS_SATA_PM:
#ifdef CONFIG_SCSI_SAS_ATA
error = sas_discover_sata(dev); error = sas_discover_sata(dev);
break; break;
#else
pr_notice("ATA device seen but CONFIG_SCSI_SAS_ATA=N so cannot attach\n");
fallthrough;
#endif
/* Fall through - only for the #else condition above. */
default: default:
error = -ENXIO; error = -ENXIO;
pr_err("unhandled device %d\n", dev->dev_type); pr_err("unhandled device %d\n", dev->dev_type);
......
...@@ -751,13 +751,46 @@ static void sas_ex_get_linkrate(struct domain_device *parent, ...@@ -751,13 +751,46 @@ static void sas_ex_get_linkrate(struct domain_device *parent,
child->pathways = min(child->pathways, parent->pathways); child->pathways = min(child->pathways, parent->pathways);
} }
static int sas_ex_add_dev(struct domain_device *parent, struct ex_phy *phy,
struct domain_device *child, int phy_id)
{
struct sas_rphy *rphy;
int res;
child->dev_type = SAS_END_DEVICE;
rphy = sas_end_device_alloc(phy->port);
if (!rphy)
return -ENOMEM;
child->tproto = phy->attached_tproto;
sas_init_dev(child);
child->rphy = rphy;
get_device(&rphy->dev);
rphy->identify.phy_identifier = phy_id;
sas_fill_in_rphy(child, rphy);
list_add_tail(&child->disco_list_node, &parent->port->disco_list);
res = sas_notify_lldd_dev_found(child);
if (res) {
pr_notice("notify lldd for device %016llx at %016llx:%02d returned 0x%x\n",
SAS_ADDR(child->sas_addr),
SAS_ADDR(parent->sas_addr), phy_id, res);
sas_rphy_free(child->rphy);
list_del(&child->disco_list_node);
return res;
}
return 0;
}
static struct domain_device *sas_ex_discover_end_dev( static struct domain_device *sas_ex_discover_end_dev(
struct domain_device *parent, int phy_id) struct domain_device *parent, int phy_id)
{ {
struct expander_device *parent_ex = &parent->ex_dev; struct expander_device *parent_ex = &parent->ex_dev;
struct ex_phy *phy = &parent_ex->ex_phy[phy_id]; struct ex_phy *phy = &parent_ex->ex_phy[phy_id];
struct domain_device *child = NULL; struct domain_device *child = NULL;
struct sas_rphy *rphy;
int res; int res;
if (phy->attached_sata_host || phy->attached_sata_ps) if (phy->attached_sata_host || phy->attached_sata_ps)
...@@ -785,99 +818,23 @@ static struct domain_device *sas_ex_discover_end_dev( ...@@ -785,99 +818,23 @@ static struct domain_device *sas_ex_discover_end_dev(
sas_ex_get_linkrate(parent, child, phy); sas_ex_get_linkrate(parent, child, phy);
sas_device_set_phy(child, phy->port); sas_device_set_phy(child, phy->port);
#ifdef CONFIG_SCSI_SAS_ATA
if ((phy->attached_tproto & SAS_PROTOCOL_STP) || phy->attached_sata_dev) { if ((phy->attached_tproto & SAS_PROTOCOL_STP) || phy->attached_sata_dev) {
if (child->linkrate > parent->min_linkrate) { res = sas_ata_add_dev(parent, phy, child, phy_id);
struct sas_phy *cphy = child->phy; } else if (phy->attached_tproto & SAS_PROTOCOL_SSP) {
enum sas_linkrate min_prate = cphy->minimum_linkrate, res = sas_ex_add_dev(parent, phy, child, phy_id);
parent_min_lrate = parent->min_linkrate,
min_linkrate = (min_prate > parent_min_lrate) ?
parent_min_lrate : 0;
struct sas_phy_linkrates rates = {
.maximum_linkrate = parent->min_linkrate,
.minimum_linkrate = min_linkrate,
};
int ret;
pr_notice("ex %016llx phy%02d SATA device linkrate > min pathway connection rate, attempting to lower device linkrate\n",
SAS_ADDR(child->sas_addr), phy_id);
ret = sas_smp_phy_control(parent, phy_id,
PHY_FUNC_LINK_RESET, &rates);
if (ret) {
pr_err("ex %016llx phy%02d SATA device could not set linkrate (%d)\n",
SAS_ADDR(child->sas_addr), phy_id, ret);
goto out_free;
}
pr_notice("ex %016llx phy%02d SATA device set linkrate successfully\n",
SAS_ADDR(child->sas_addr), phy_id);
child->linkrate = child->min_linkrate;
}
res = sas_get_ata_info(child, phy);
if (res)
goto out_free;
sas_init_dev(child);
res = sas_ata_init(child);
if (res)
goto out_free;
rphy = sas_end_device_alloc(phy->port);
if (!rphy)
goto out_free;
rphy->identify.phy_identifier = phy_id;
child->rphy = rphy;
get_device(&rphy->dev);
list_add_tail(&child->disco_list_node, &parent->port->disco_list);
res = sas_discover_sata(child);
if (res) {
pr_notice("sas_discover_sata() for device %16llx at %016llx:%02d returned 0x%x\n",
SAS_ADDR(child->sas_addr),
SAS_ADDR(parent->sas_addr), phy_id, res);
goto out_list_del;
}
} else
#endif
if (phy->attached_tproto & SAS_PROTOCOL_SSP) {
child->dev_type = SAS_END_DEVICE;
rphy = sas_end_device_alloc(phy->port);
/* FIXME: error handling */
if (unlikely(!rphy))
goto out_free;
child->tproto = phy->attached_tproto;
sas_init_dev(child);
child->rphy = rphy;
get_device(&rphy->dev);
rphy->identify.phy_identifier = phy_id;
sas_fill_in_rphy(child, rphy);
list_add_tail(&child->disco_list_node, &parent->port->disco_list);
res = sas_discover_end_dev(child);
if (res) {
pr_notice("sas_discover_end_dev() for device %016llx at %016llx:%02d returned 0x%x\n",
SAS_ADDR(child->sas_addr),
SAS_ADDR(parent->sas_addr), phy_id, res);
goto out_list_del;
}
} else { } else {
pr_notice("target proto 0x%x at %016llx:0x%x not handled\n", pr_notice("target proto 0x%x at %016llx:0x%x not handled\n",
phy->attached_tproto, SAS_ADDR(parent->sas_addr), phy->attached_tproto, SAS_ADDR(parent->sas_addr),
phy_id); phy_id);
goto out_free; res = -ENODEV;
} }
if (res)
goto out_free;
list_add_tail(&child->siblings, &parent_ex->children); list_add_tail(&child->siblings, &parent_ex->children);
return child; return child;
out_list_del:
sas_rphy_free(child->rphy);
list_del(&child->disco_list_node);
spin_lock_irq(&parent->port->dev_list_lock);
list_del(&child->dev_list_node);
spin_unlock_irq(&parent->port->dev_list_lock);
out_free: out_free:
sas_port_delete(phy->port); sas_port_delete(phy->port);
out_err: out_err:
......
...@@ -735,7 +735,6 @@ void sas_unregister_domain_devices(struct asd_sas_port *port, int gone); ...@@ -735,7 +735,6 @@ void sas_unregister_domain_devices(struct asd_sas_port *port, int gone);
void sas_init_disc(struct sas_discovery *disc, struct asd_sas_port *); void sas_init_disc(struct sas_discovery *disc, struct asd_sas_port *);
void sas_discover_event(struct asd_sas_port *, enum discover_event ev); void sas_discover_event(struct asd_sas_port *, enum discover_event ev);
int sas_discover_sata(struct domain_device *);
int sas_discover_end_dev(struct domain_device *); int sas_discover_end_dev(struct domain_device *);
void sas_unregister_dev(struct asd_sas_port *port, struct domain_device *); void sas_unregister_dev(struct asd_sas_port *port, struct domain_device *);
......
...@@ -36,8 +36,15 @@ void sas_ata_device_link_abort(struct domain_device *dev, bool force_reset); ...@@ -36,8 +36,15 @@ void sas_ata_device_link_abort(struct domain_device *dev, bool force_reset);
int sas_execute_ata_cmd(struct domain_device *device, u8 *fis, int sas_execute_ata_cmd(struct domain_device *device, u8 *fis,
int force_phy_id); int force_phy_id);
int smp_ata_check_ready_type(struct ata_link *link); int smp_ata_check_ready_type(struct ata_link *link);
int sas_discover_sata(struct domain_device *dev);
int sas_ata_add_dev(struct domain_device *parent, struct ex_phy *phy,
struct domain_device *child, int phy_id);
#else #else
static inline void sas_ata_disabled_notice(void)
{
pr_notice_once("ATA device seen but CONFIG_SCSI_SAS_ATA=N\n");
}
static inline int dev_is_sata(struct domain_device *dev) static inline int dev_is_sata(struct domain_device *dev)
{ {
...@@ -103,6 +110,19 @@ static inline int smp_ata_check_ready_type(struct ata_link *link) ...@@ -103,6 +110,19 @@ static inline int smp_ata_check_ready_type(struct ata_link *link)
{ {
return 0; return 0;
} }
static inline int sas_discover_sata(struct domain_device *dev)
{
sas_ata_disabled_notice();
return -ENXIO;
}
static inline int sas_ata_add_dev(struct domain_device *parent, struct ex_phy *phy,
struct domain_device *child, int phy_id)
{
sas_ata_disabled_notice();
return -ENODEV;
}
#endif #endif
#endif /* _SAS_ATA_H_ */ #endif /* _SAS_ATA_H_ */
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment