libsas: Some minor improvements and tidy-up
Subsystems (2)
cover libsas: Some minor improvements and tidy-up
This patchset introduces some minor improvements and tidy-up, including:
- fix PHY info in sysfs for PHY events
- min pathway rate programming improvement
- some other tidy-up and neatening
John Garry (6):
scsi: libsas: Stop hardcoding SAS address length
scsi: libsas: Try to retain programmed min linkrate for SATA min
pathway unmatch fixing
scsi: libsas: Improve vague log in SAS rediscovery
scsi: libsas: Inject revalidate event for root port event
scsi: libsas: Do discovery on empty PHY to update PHY info
scsi: libsas: Print expander PHY indexes in decimal
drivers/scsi/libsas/sas_ata.c | 2 +- drivers/scsi/libsas/sas_expander.c | 83 ++++++++++++++++++------------ drivers/scsi/libsas/sas_init.c | 42 ++++++++------- drivers/scsi/libsas/sas_phy.c | 7 ++- drivers/scsi/libsas/sas_port.c | 24 +++++++-- include/scsi/libsas.h | 13 +++-- 6 files changed, 108 insertions(+), 63 deletions(-)
Signature · 1 line
2.17.1
PATCH 1/6 scsi: libsas: Stop hardcoding SAS address length
Many times we use 8 for SAS address length, while we already have a macro for this - SAS_ADDR_SIZE.
Replace instances of this with the macro. However, don't touch the SAS address array sizes sas.h, as these are defined according to the SAS spec.
Some missing whitespaces are also added, and whitespace indentation in sas_hash_addr() is also fixed (see sas_hash_addr()).
--- drivers/scsi/libsas/sas_expander.c | 15 +++++------ drivers/scsi/libsas/sas_init.c | 40 ++++++++++++++++-------------- include/scsi/libsas.h | 6 ++--- 3 files changed, 32 insertions(+), 29 deletions(-)
drivers/scsi/libsas/sas_expander.c +8 -7
@@ -1151,7 +1151,7 @@ static int sas_find_sub_addr(struct domain_device *dev, u8 *sub_addr) phy->attached_dev_type == SAS_FANOUT_EXPANDER_DEVICE) && phy->routing_attr == SUBTRACTIVE_ROUTING) { -memcpy (sub_addr, phy->attached_sas_addr,SAS_ADDR_SIZE ); +memcpy (sub_addr, phy->attached_sas_addr,SAS_ADDR_SIZE );return 1 ; }
@@ -1163,7 +1163,7 @@ static int sas_check_level_subtractive_boundary(struct domain_device *dev) {struct expander_device *ex = &dev->ex_dev;struct domain_device *child; -u8 sub_addr[8 ] = {0 , }; +u8 sub_addr[SAS_ADDR_SIZE ] = {0 , };list_for_each_entry (child, &ex->children, siblings) { if (child->dev_type != SAS_EDGE_EXPANDER_DEVICE &&
@@ -1173,7 +1173,7 @@ static int sas_check_level_subtractive_boundary(struct domain_device *dev)sas_find_sub_addr (child, sub_addr);continue ; }else { -u8 s2[8 ]; +u8 s2[SAS_ADDR_SIZE ];if (sas_find_sub_addr (child, s2) && (SAS_ADDR (sub_addr) !=SAS_ADDR (s2))) {
@@ -1760,10 +1760,11 @@ static int sas_get_phy_attached_dev(struct domain_device *dev, int phy_id, res =sas_get_phy_discover (dev, phy_id, disc_resp);if (res ==0 ) { -memcpy (sas_addr, disc_resp->disc.attached_sas_addr,8 ); +memcpy (sas_addr, disc_resp->disc.attached_sas_addr, +SAS_ADDR_SIZE ); *type =to_dev_type (dr);if (*type ==0 ) -memset (sas_addr,0 ,8 ); +memset (sas_addr,0 ,SAS_ADDR_SIZE ); }kfree (disc_resp);return res;
@@ -2027,10 +2028,10 @@ static int sas_rediscover_dev(struct domain_device *dev, int phy_id, bool last)struct expander_device *ex = &dev->ex_dev;struct ex_phy *phy = &ex->ex_phy[phy_id];enum sas_device_type type =SAS_PHY_UNUSED ; -u8 sas_addr[8 ]; +u8 sas_addr[SAS_ADDR_SIZE ];int res; -memset (sas_addr,0 ,8 ); +memset (sas_addr,0 ,SAS_ADDR_SIZE ); res =sas_get_phy_attached_dev (dev, phy_id, sas_addr, &type);switch (res) {case SMP_RESP_NO_PHY :
drivers/scsi/libsas/sas_init.c +21 -19
@@ -87,25 +87,27 @@ EXPORT_SYMBOL_GPL(sas_free_task);/*------------ SAS addr hash -----------*/ void sas_hash_addr (u8 *hashed,const u8 *sas_addr) { -const u32 poly =0x00DB2777 ; -u32 r =0 ; -int i; - -for (i =0 ; i <8 ; i++) { -int b; -for (b =7 ; b >=0 ; b--) { - r <<=1 ; -if ((1 << b) & sas_addr[i]) { -if (!(r &0x01000000 )) - r ^= poly; - }else if (r &0x01000000 ) - r ^= poly; - } - } - - hashed[0 ] = (r >>16 ) &0xFF ; - hashed[1 ] = (r >>8 ) &0xFF ; - hashed[2 ] = r &0xFF ; +const u32 poly =0x00DB2777 ; +u32 r =0 ; +int i; + +for (i =0 ; i <SAS_ADDR_SIZE ; i++) { +int b; + +for (b = (SAS_ADDR_SIZE -1 ); b >=0 ; b--) { + r <<=1 ; +if ((1 << b) & sas_addr[i]) { +if (!(r &0x01000000 )) + r ^= poly; + }else if (r &0x01000000 ) { + r ^= poly; + } + } + } + + hashed[0 ] = (r >>16 ) &0xFF ; + hashed[1 ] = (r >>8 ) &0xFF ; + hashed[2 ] = r &0xFF ; }int sas_register_ha (struct sas_ha_struct *sas_ha)
include/scsi/libsas.h +3 -3
@@ -245,9 +245,9 @@ static inline struct sas_discovery_event *to_sas_discovery_event(struct work_strstruct sas_discovery {struct sas_discovery_event disc_work[DISC_NUM_EVENTS ];unsigned long pending; -u8 fanout_sas_addr[8 ]; -u8 eeds_a[8 ]; -u8 eeds_b[8 ]; +u8 fanout_sas_addr[SAS_ADDR_SIZE ]; +u8 eeds_a[SAS_ADDR_SIZE ]; +u8 eeds_b[SAS_ADDR_SIZE ];int max_level; };
Signature · 1 line
2.17.1
PATCH 2/6 scsi: libsas: Try to retain programmed min linkrate for SATA min pathway unmatch fixing
In reply to John GarryCurrently for fixing the linkrate matching during discovery such that the linkrate of a SATA PHY does not exceed min pathway to initiator, we set the SATA PHY programmed min linkrate to the same value as the programmed max linkrate.
This is unnecessary, and we should be able to keep the same programmed min linkrate if it is already lower than this new max programmed linkrate.
This patch makes that change.
In effect, this will not make much difference since we generally will negotiate a linkrate at the programmed max linkrate, and the programmed min linkrate will have no impact.
--- drivers/scsi/libsas/sas_expander.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-)
drivers/scsi/libsas/sas_expander.c +6 -1
@@ -826,9 +826,14 @@ static struct domain_device *sas_ex_discover_end_dev(#ifdef CONFIG_SCSI_SAS_ATA if ((phy->attached_tproto &SAS_PROTOCOL_STP ) || phy->attached_sata_dev) {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 = parent->min_linkrate, + .minimum_linkrate = min_linkrate, };int ret;
Signature · 1 line
2.17.1
PATCH 3/6 scsi: libsas: Improve vague log in SAS rediscovery
In reply to John GarryWhen an expander PHY which was part of a wideport disconnects, we would see a log like this from sas_rediscover():
[ 39.695554] sas: phy20 part of wide port with phy16
Here, phy20 is the PHY that disconnected, and phy16 is the lowest indexed member PHY of the wideport.
The log implies the phy20 is still part of the wideport with phy16, so is misleading or, at least, vague.
Improve the logs in SAS rediscovery by removing this log and adding a log in sas_rediscover_dev() to tell what's really going on.
While we're at it, also make the logs in sas_find_bcast_dev() more informative (and more consistent with the reset of the expander logs).
--- drivers/scsi/libsas/sas_expander.c | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-)
drivers/scsi/libsas/sas_expander.c +14 -6
@@ -1876,10 +1876,12 @@ static int sas_find_bcast_dev(struct domain_device *dev,if (phy_id !=-1 ) { *src_dev = dev; ex->ex_change_count = ex_change_count; -pr_info ("Expander phy change count has changed\n" ); +pr_info ("ex %016llx phy%d change count has changed\n" , +SAS_ADDR (dev->sas_addr), phy_id);return res; }else -pr_info ("Expander phys DID NOT change\n" ); +pr_info ("ex %016llx phys DID NOT change\n" , +SAS_ADDR (dev->sas_addr)); }list_for_each_entry (ch, &ex->children, siblings) {if (ch->dev_type ==SAS_EDGE_EXPANDER_DEVICE || ch->dev_type ==SAS_FANOUT_EXPANDER_DEVICE ) {
@@ -2028,14 +2030,22 @@ static bool dev_type_flutter(enum sas_device_type new, enum sas_device_type old)return false; } -static int sas_rediscover_dev (struct domain_device *dev,int phy_id,bool last) +static int sas_rediscover_dev (struct domain_device *dev,int phy_id, +bool last,int sibling) {struct expander_device *ex = &dev->ex_dev;struct ex_phy *phy = &ex->ex_phy[phy_id];enum sas_device_type type =SAS_PHY_UNUSED ;u8 sas_addr[SAS_ADDR_SIZE ]; +char msg[80 ] ="" ;int res; +if (!last) +sprintf (msg,", part of a wide port with phy%d" , sibling); + +pr_debug ("ex %016llx rediscovering phy%d%s\n" ,SAS_ADDR (dev->sas_addr), + phy_id, msg); +memset (sas_addr,0 ,SAS_ADDR_SIZE ); res =sas_get_phy_attached_dev (dev, phy_id, sas_addr, &type);switch (res) {
@@ -2115,13 +2125,11 @@ static int sas_rediscover(struct domain_device *dev, const int phy_id)continue ;if (SAS_ADDR (phy->attached_sas_addr) ==SAS_ADDR (changed_phy->attached_sas_addr)) { -pr_debug ("phy%d part of wide port with phy%d\n" , - phy_id, i); last = false;break ; } } - res =sas_rediscover_dev (dev, phy_id, last); + res =sas_rediscover_dev (dev, phy_id, last, i); }else res =sas_discover_new (dev, phy_id);return res;
Signature · 1 line
2.17.1
PATCH 4/6 scsi: libsas: Inject revalidate event for root port event
In reply to John GarryAccording to the SAS spec, an expander device shall transmit BROADCAST (CHANGE) from at least one phy in each expander port other than the expander port that is the cause for transmitting BROADCAST (CHANGE).
As such, for when the link is lost for a root PHY attached to an expander PHY, we get no broadcast event.
This causes an issue for libsas, in that we will not revalidate the domain for these events.
As a solution, for when a root PHY is formed or deformed from a root port, insert a broadcast event to trigger a domain revalidation.
--- drivers/scsi/libsas/sas_port.c | 24 +++++++++++++++++++++--- include/scsi/libsas.h | 7 +++++++ 2 files changed, 28 insertions(+), 3 deletions(-)
drivers/scsi/libsas/sas_port.c +21 -3
@@ -95,6 +95,7 @@ static void sas_form_port(struct asd_sas_phy *phy)int i;struct sas_ha_struct *sas_ha = phy->ha;struct asd_sas_port *port = phy->port; +struct domain_device *port_dev;struct sas_internal *si =to_sas_internal (sas_ha->core.shost->transportt);unsigned long flags;
@@ -153,8 +154,9 @@ static void sas_form_port(struct asd_sas_phy *phy) }/* add the phy to the port */ + port_dev = port->port_dev;list_add_tail (&phy->port_phy_el, &port->phy_list); -sas_phy_set_target (phy, port->port_dev); +sas_phy_set_target (phy, port_dev); phy->port = port; port->num_phys++; port->phy_mask |= (1U << phy->id);
@@ -184,14 +186,21 @@ static void sas_form_port(struct asd_sas_phy *phy) port->phy_mask, SAS_ADDR(port->attached_sas_addr)); -if (port->port_dev) - port->port_dev->pathways = port->num_phys; +if (port_dev) + port_dev->pathways = port->num_phys;/* Tell the LLDD about this port formation. */ if (si->dft->lldd_port_formed) si->dft->lldd_port_formed (phy);sas_discover_event (phy->port,DISCE_DISCOVER_DOMAIN ); +/* Only insert a revalidate event after initial discovery */ +if (port_dev &&sas_dev_type_is_expander (port_dev->dev_type)) { +struct expander_device *ex_dev = &port_dev->ex_dev; + + ex_dev->ex_change_count =-1 ; +sas_discover_event (port,DISCE_REVALIDATE_DOMAIN ); + }flush_workqueue (sas_ha->disco_q); }
@@ -254,6 +263,15 @@ void sas_deform_port(struct asd_sas_phy *phy, int gone)spin_unlock (&port->phy_list_lock);spin_unlock_irqrestore (&sas_ha->phy_port_lock, flags); +/* Only insert revalidate event if the port still has members */ +if (port->port && dev &&sas_dev_type_is_expander (dev->dev_type)) { +struct expander_device *ex_dev = &dev->ex_dev; + + ex_dev->ex_change_count =-1 ; +sas_discover_event (port,DISCE_REVALIDATE_DOMAIN ); + } +flush_workqueue (sas_ha->disco_q); +return ; }
include/scsi/libsas.h +7 -0
@@ -224,6 +224,13 @@ struct sas_work {struct work_struct work; }; +/* Lots of code duplicates this in the SCSI tree, which can be factored out */ +static inline bool sas_dev_type_is_expander (enum sas_device_type type) +{ +return type ==SAS_EDGE_EXPANDER_DEVICE || + type ==SAS_FANOUT_EXPANDER_DEVICE ; +} +static inline void INIT_SAS_WORK (struct sas_work *sw,void (*fn)(struct work_struct *)) {INIT_WORK (&sw->work, fn);
Signature · 1 line
2.17.1
PATCH 5/6 scsi: libsas: Do discovery on empty PHY to update PHY info
In reply to John GarryWhen we discover the PHY is empty in sas_rediscover_dev(), the PHY information (like negotiated linkrate) is not updated.
As such, for a user examining sysfs for that PHY, they would see incorrect values:
root@(none)$ cd /sys/class/sas_phy/phy-0:0:20 root@(none)$ more negotiated_linkrate 3.0 Gbit root@(none)$ echo 0 > enable root@(none)$ more negotiated_linkrate 3.0 Gbit
So fix this, simply discover the PHY again, even though we know it's empty; in the above example, this gives us:
root@(none)$ more negotiated_linkrate Phy disabled
We must do this after unregistering the device associated with the PHY (in sas_unregister_devs_sas_addr()).
--- drivers/scsi/libsas/sas_expander.c | 5 +++++ 1 file changed, 5 insertions(+)
drivers/scsi/libsas/sas_expander.c +5 -0
@@ -2068,6 +2068,11 @@ static int sas_rediscover_dev(struct domain_device *dev, int phy_id,if ((SAS_ADDR (sas_addr) ==0 ) || (res == -ECOMM )) { phy->phy_state =PHY_EMPTY ;sas_unregister_devs_sas_addr (dev, phy_id, last); +/* +* Even though the PHY is empty, for convenience we discover +* the PHY to update the PHY info, like negotiated linkrate. +*/ +sas_ex_phy_discover (dev, phy_id);return res; }else if (SAS_ADDR (sas_addr) ==SAS_ADDR (phy->attached_sas_addr) &&dev_type_flutter (type, phy->attached_dev_type)) {
Signature · 1 line
2.17.1
PATCH 6/6 scsi: libsas: Print expander PHY indexes in decimal
In reply to John GarryCurrently we print expander PHY indexes in a mix of decimal and hex.
It is more consistent and also more convenient to read decimal, so make this change.
We use width of 2 for expander and 1 for root PHYs prints.
Some lines which were needlessly spilling multiple lines are unified.
--- drivers/scsi/libsas/sas_ata.c | 2 +- drivers/scsi/libsas/sas_expander.c | 44 +++++++++++++++--------------- drivers/scsi/libsas/sas_init.c | 2 +- drivers/scsi/libsas/sas_phy.c | 7 ++--- 4 files changed, 27 insertions(+), 28 deletions(-)
drivers/scsi/libsas/sas_ata.c +1 -1
@@ -281,7 +281,7 @@ int sas_get_ata_info(struct domain_device *dev, struct ex_phy *phy) res =sas_get_report_phy_sata (dev->parent, phy->phy_id, &dev->sata_dev.rps_resp);if (res) { -pr_debug ("report phy sata to %016llx:0x%x returned 0x%x\n" , +pr_debug ("report phy sata to %016llx:%02d returned 0x%x\n" ,SAS_ADDR (dev->parent->sas_addr), phy->phy_id, res);return res;
drivers/scsi/libsas/sas_expander.c +22 -22
161 lines not on this page · raw message
drivers/scsi/libsas/sas_init.c +1 -1
@@ -625,7 +625,7 @@ struct asd_sas_event *sas_alloc_event(struct asd_sas_phy *phy)if (atomic_read (&phy->event_nr) > phy->ha->event_thres) {if (i->dft->lldd_control_phy) {if (cmpxchg (&phy->in_shutdown,0 ,1 ) ==0 ) { -pr_notice ("The phy%02d bursting events, shut it down.\n" , +pr_notice ("The phy%d bursting events, shut it down.\n" , phy->id);sas_notify_phy_event (phy,PHYE_SHUTDOWN ); }
drivers/scsi/libsas/sas_phy.c +3 -4
@@ -122,11 +122,10 @@ static void sas_phye_shutdown(struct work_struct *work) phy->enabled =0 ; ret = i->dft->lldd_control_phy (phy,PHY_FUNC_DISABLE ,NULL );if (ret) -pr_notice ("lldd disable phy%02d returned %d\n" , - phy->id, ret); +pr_notice ("lldd disable phy%d returned %d\n" , phy->id, + ret); }else -pr_notice ("phy%02d is not enabled, cannot shutdown\n" , - phy->id); +pr_notice ("phy%d is not enabled, cannot shutdown\n" , phy->id); }/* ---------- Phy class registration ---------- */
Signature · 1 line
2.17.1
Martin K. Petersen
AppliedJohn,
Quoted 4 lines
This patchset introduces some minor improvements and tidy-up, including:
- fix PHY info in sysfs for PHY events
- min pathway rate programming improvement
- some other tidy-up and neatening
Applied to 5.2/scsi-queue, thanks!
One thing that always bugged me is the ambiguous "ex" prefix for many libsas log messages. And in a way, your patch #3 makes things worse by replacing the more descriptive "Expander" with "ex". It does make things more consistent, though.
I'd really like to see all the libsas messages be cleaned up with a sensible prefix and a consistent format where possible.
Signature · 1 line
Martin K. Petersen Oracle Linux Engineering
Quoted 10 lines · Martin K. Petersen
John,
Quoted 4 lines
This patchset introduces some minor improvements and tidy-up, including:
- fix PHY info in sysfs for PHY events
- min pathway rate programming improvement
- some other tidy-up and neateningApplied to 5.2/scsi-queue, thanks!
Hi Martin,
Sorry for the slow response.
Quoted 4 lines
One thing that always bugged me is the ambiguous "ex" prefix for many libsas log messages.And in a way, your patch #3 makes things worse by replacing the more descriptive "Expander" with "ex". It does make things more consistent, though.
OK, understood. Personally I prefer the brevity of "ex". However, apart from this, adding the SAS address to the log does add value.
Quoted 3 lines
I'd really like to see all the libsas messages be cleaned up with a sensible prefix and a consistent format where possible.
So all libsas messages do have the "sas: " prefix, but they still can be vague/inconsistent at times.
Anyway, I'll check what can be done here.
Thanks,