summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJohn Garry <john.garry@huawei.com>2019-04-12 04:57:52 -0400
committerMartin K. Petersen <martin.petersen@oracle.com>2019-04-15 18:55:00 -0400
commit7b27c5fe247b4288f41551ced5bf458f58dc77b8 (patch)
tree8690506f9060347020a7eff518d654f646e6591c
parent01d4e3a2fc07b269eedeefa1f7c5c7090c442900 (diff)
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()). Signed-off-by: John Garry <john.garry@huawei.com> Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
-rw-r--r--drivers/scsi/libsas/sas_expander.c15
-rw-r--r--drivers/scsi/libsas/sas_init.c40
-rw-r--r--include/scsi/libsas.h6
3 files changed, 32 insertions, 29 deletions
diff --git a/drivers/scsi/libsas/sas_expander.c b/drivers/scsi/libsas/sas_expander.c
index 17b45a0c7bc3..93f297199d4c 100644
--- a/drivers/scsi/libsas/sas_expander.c
+++ b/drivers/scsi/libsas/sas_expander.c
@@ -1151,7 +1151,7 @@ static int sas_find_sub_addr(struct domain_device *dev, u8 *sub_addr)
1151 phy->attached_dev_type == SAS_FANOUT_EXPANDER_DEVICE) && 1151 phy->attached_dev_type == SAS_FANOUT_EXPANDER_DEVICE) &&
1152 phy->routing_attr == SUBTRACTIVE_ROUTING) { 1152 phy->routing_attr == SUBTRACTIVE_ROUTING) {
1153 1153
1154 memcpy(sub_addr, phy->attached_sas_addr,SAS_ADDR_SIZE); 1154 memcpy(sub_addr, phy->attached_sas_addr, SAS_ADDR_SIZE);
1155 1155
1156 return 1; 1156 return 1;
1157 } 1157 }
@@ -1163,7 +1163,7 @@ static int sas_check_level_subtractive_boundary(struct domain_device *dev)
1163{ 1163{
1164 struct expander_device *ex = &dev->ex_dev; 1164 struct expander_device *ex = &dev->ex_dev;
1165 struct domain_device *child; 1165 struct domain_device *child;
1166 u8 sub_addr[8] = {0, }; 1166 u8 sub_addr[SAS_ADDR_SIZE] = {0, };
1167 1167
1168 list_for_each_entry(child, &ex->children, siblings) { 1168 list_for_each_entry(child, &ex->children, siblings) {
1169 if (child->dev_type != SAS_EDGE_EXPANDER_DEVICE && 1169 if (child->dev_type != SAS_EDGE_EXPANDER_DEVICE &&
@@ -1173,7 +1173,7 @@ static int sas_check_level_subtractive_boundary(struct domain_device *dev)
1173 sas_find_sub_addr(child, sub_addr); 1173 sas_find_sub_addr(child, sub_addr);
1174 continue; 1174 continue;
1175 } else { 1175 } else {
1176 u8 s2[8]; 1176 u8 s2[SAS_ADDR_SIZE];
1177 1177
1178 if (sas_find_sub_addr(child, s2) && 1178 if (sas_find_sub_addr(child, s2) &&
1179 (SAS_ADDR(sub_addr) != SAS_ADDR(s2))) { 1179 (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,
1760 1760
1761 res = sas_get_phy_discover(dev, phy_id, disc_resp); 1761 res = sas_get_phy_discover(dev, phy_id, disc_resp);
1762 if (res == 0) { 1762 if (res == 0) {
1763 memcpy(sas_addr, disc_resp->disc.attached_sas_addr, 8); 1763 memcpy(sas_addr, disc_resp->disc.attached_sas_addr,
1764 SAS_ADDR_SIZE);
1764 *type = to_dev_type(dr); 1765 *type = to_dev_type(dr);
1765 if (*type == 0) 1766 if (*type == 0)
1766 memset(sas_addr, 0, 8); 1767 memset(sas_addr, 0, SAS_ADDR_SIZE);
1767 } 1768 }
1768 kfree(disc_resp); 1769 kfree(disc_resp);
1769 return res; 1770 return res;
@@ -2027,10 +2028,10 @@ static int sas_rediscover_dev(struct domain_device *dev, int phy_id, bool last)
2027 struct expander_device *ex = &dev->ex_dev; 2028 struct expander_device *ex = &dev->ex_dev;
2028 struct ex_phy *phy = &ex->ex_phy[phy_id]; 2029 struct ex_phy *phy = &ex->ex_phy[phy_id];
2029 enum sas_device_type type = SAS_PHY_UNUSED; 2030 enum sas_device_type type = SAS_PHY_UNUSED;
2030 u8 sas_addr[8]; 2031 u8 sas_addr[SAS_ADDR_SIZE];
2031 int res; 2032 int res;
2032 2033
2033 memset(sas_addr, 0, 8); 2034 memset(sas_addr, 0, SAS_ADDR_SIZE);
2034 res = sas_get_phy_attached_dev(dev, phy_id, sas_addr, &type); 2035 res = sas_get_phy_attached_dev(dev, phy_id, sas_addr, &type);
2035 switch (res) { 2036 switch (res) {
2036 case SMP_RESP_NO_PHY: 2037 case SMP_RESP_NO_PHY:
diff --git a/drivers/scsi/libsas/sas_init.c b/drivers/scsi/libsas/sas_init.c
index 221340ee8651..213c85557bf9 100644
--- a/drivers/scsi/libsas/sas_init.c
+++ b/drivers/scsi/libsas/sas_init.c
@@ -87,25 +87,27 @@ EXPORT_SYMBOL_GPL(sas_free_task);
87/*------------ SAS addr hash -----------*/ 87/*------------ SAS addr hash -----------*/
88void sas_hash_addr(u8 *hashed, const u8 *sas_addr) 88void sas_hash_addr(u8 *hashed, const u8 *sas_addr)
89{ 89{
90 const u32 poly = 0x00DB2777; 90 const u32 poly = 0x00DB2777;
91 u32 r = 0; 91 u32 r = 0;
92 int i; 92 int i;
93 93
94 for (i = 0; i < 8; i++) { 94 for (i = 0; i < SAS_ADDR_SIZE; i++) {
95 int b; 95 int b;
96 for (b = 7; b >= 0; b--) { 96
97 r <<= 1; 97 for (b = (SAS_ADDR_SIZE - 1); b >= 0; b--) {
98 if ((1 << b) & sas_addr[i]) { 98 r <<= 1;
99 if (!(r & 0x01000000)) 99 if ((1 << b) & sas_addr[i]) {
100 r ^= poly; 100 if (!(r & 0x01000000))
101 } else if (r & 0x01000000) 101 r ^= poly;
102 r ^= poly; 102 } else if (r & 0x01000000) {
103 } 103 r ^= poly;
104 } 104 }
105 105 }
106 hashed[0] = (r >> 16) & 0xFF; 106 }
107 hashed[1] = (r >> 8) & 0xFF ; 107
108 hashed[2] = r & 0xFF; 108 hashed[0] = (r >> 16) & 0xFF;
109 hashed[1] = (r >> 8) & 0xFF;
110 hashed[2] = r & 0xFF;
109} 111}
110 112
111int sas_register_ha(struct sas_ha_struct *sas_ha) 113int sas_register_ha(struct sas_ha_struct *sas_ha)
diff --git a/include/scsi/libsas.h b/include/scsi/libsas.h
index 56b2dba7d911..cfaaf1254211 100644
--- a/include/scsi/libsas.h
+++ b/include/scsi/libsas.h
@@ -245,9 +245,9 @@ static inline struct sas_discovery_event *to_sas_discovery_event(struct work_str
245struct sas_discovery { 245struct sas_discovery {
246 struct sas_discovery_event disc_work[DISC_NUM_EVENTS]; 246 struct sas_discovery_event disc_work[DISC_NUM_EVENTS];
247 unsigned long pending; 247 unsigned long pending;
248 u8 fanout_sas_addr[8]; 248 u8 fanout_sas_addr[SAS_ADDR_SIZE];
249 u8 eeds_a[8]; 249 u8 eeds_a[SAS_ADDR_SIZE];
250 u8 eeds_b[8]; 250 u8 eeds_b[SAS_ADDR_SIZE];
251 int max_level; 251 int max_level;
252}; 252};
253 253