Sas address conversion and comparation is widely used in libsas and
drivers. However they are all opencoded and to avoid the line spill over
80 columns, are mostly split into multi-lines.
To make the code easier to read, introduce some helpers with clearer
semantics and replace the opencoded segments with them.
v2->v3:
Rename sas_phy_addr_same() to sas_phy_addr_match().
Rearrange patches, move patch #6 to #1 and directly use the helper
sas_phy_match_dev_addr() in sas_find_attached_phy().
Add some review tags from Jack Wang.
v1->v2:
First factor out sas_find_attached_phy() and replace LLDDs's code
with it.
Remove three too simple helpers.
Rename the helpers with 'sas_' prefix.
Jason Yan (8):
scsi: libsas: introduce sas address comparation helpers
scsi: libsas: introduce sas_find_attached_phy() helper
scsi: pm8001: use sas_find_attached_phy() instead of open coded
scsi: mvsas: use sas_find_attached_phy() instead of open coded
scsi: hisi_sas: use sas_find_attathed_phy() instead of open coded
scsi: libsas: use sas_phy_match_dev_addr() instead of open coded
scsi: libsas: use sas_phy_addr_match() instead of open coded
scsi: libsas: use sas_phy_match_port_addr() instead of open coded
drivers/scsi/hisi_sas/hisi_sas_main.c | 12 ++------
drivers/scsi/libsas/sas_expander.c | 40 ++++++++++++++++-----------
drivers/scsi/libsas/sas_internal.h | 17 ++++++++++++
drivers/scsi/mvsas/mv_sas.c | 15 +++-------
drivers/scsi/pm8001/pm8001_sas.c | 16 ++++-------
include/scsi/libsas.h | 2 ++
6 files changed, 54 insertions(+), 48 deletions(-)
--
2.31.1
LLDDs are implementing their own attached phy finding code repeatedly.
Factor it out to libsas.
Signed-off-by: Jason Yan <[email protected]>
Reviewed-by: Jack Wang <[email protected]>
---
drivers/scsi/libsas/sas_expander.c | 16 ++++++++++++++++
include/scsi/libsas.h | 2 ++
2 files changed, 18 insertions(+)
diff --git a/drivers/scsi/libsas/sas_expander.c b/drivers/scsi/libsas/sas_expander.c
index fa2209080cc2..df5a64ad902f 100644
--- a/drivers/scsi/libsas/sas_expander.c
+++ b/drivers/scsi/libsas/sas_expander.c
@@ -2107,6 +2107,22 @@ int sas_ex_revalidate_domain(struct domain_device *port_dev)
return res;
}
+int sas_find_attached_phy(struct expander_device *ex_dev,
+ struct domain_device *dev)
+{
+ struct ex_phy *phy;
+ int phy_id;
+
+ for (phy_id = 0; phy_id < ex_dev->num_phys; phy_id++) {
+ phy = &ex_dev->ex_phy[phy_id];
+ if (sas_phy_match_dev_addr(dev, phy))
+ return phy_id;
+ }
+
+ return -ENODEV;
+}
+EXPORT_SYMBOL_GPL(sas_find_attached_phy);
+
void sas_smp_handler(struct bsg_job *job, struct Scsi_Host *shost,
struct sas_rphy *rphy)
{
diff --git a/include/scsi/libsas.h b/include/scsi/libsas.h
index 2dbead74a2af..75faf2308eae 100644
--- a/include/scsi/libsas.h
+++ b/include/scsi/libsas.h
@@ -750,6 +750,8 @@ int sas_clear_task_set(struct domain_device *dev, u8 *lun);
int sas_lu_reset(struct domain_device *dev, u8 *lun);
int sas_query_task(struct sas_task *task, u16 tag);
int sas_abort_task(struct sas_task *task, u16 tag);
+int sas_find_attached_phy(struct expander_device *ex_dev,
+ struct domain_device *dev);
void sas_notify_port_event(struct asd_sas_phy *phy, enum port_event event,
gfp_t gfp_flags);
--
2.31.1