ssb: fix unaligned access to mac address
PATCH 1/1 ssb: fix unaligned access to mac address
The mac address should be aligned to u16 to prevent an unaligned access in drivers/ssb/pci.c where it is casted to __be16.
--- include/linux/ssb/ssb.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
include/linux/ssb/ssb.h +1 -1
@@ -26,6 +26,7 @@ struct ssb_sprom_core_pwr_info {struct ssb_sprom {u8 revision; +u8 country_code;/* Country Code */ u8 il0mac[6 ];/* MAC address for 802.11b/g */ u8 et0mac[6 ];/* MAC address for Ethernet */ u8 et1mac[6 ];/* MAC address for 802.11a */
@@ -36,7 +37,6 @@ struct ssb_sprom {u16 board_rev;/* Board revision number from SPROM. */ u16 board_num;/* Board number from SPROM. */ u16 board_type;/* Board type from SPROM. */ -u8 country_code;/* Country Code */ char alpha2[2 ];/* Country Code as two chars like EU or US */ u8 leddc_on_time;/* LED Powersave Duty Cycle On Count */ u8 leddc_off_time;/* LED Powersave Duty Cycle Off Count */
Signature · 1 line
1.7.10.4
Quoted 13 lines · Hauke Mehrtens
The mac address should be aligned to u16 to prevent an unaligned access in
drivers/ssb/pci.cwhere it is casted to__be16.Signed-off-by Hauke Mehrtens <[email protected]>--- include/linux/ssb/ssb.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)include/linux/ssb/ssb.h +0
-0
include/linux/ssb/ssb.h struct ssb_sprom_core_pwr_info { · line 30
Quoted 5 lines
include/linux/ssb/ssb.h +1
-0@@ -26,6 +26,7 @@ struct ssb_sprom_core_pwr_info {struct ssb_sprom {u8 revision; +u8 country_code;/* Country Code */ u8 il0mac[6 ];/* MAC address for 802.11b/g */
You should probably add __aligned(2) or so to them to avoid relying on the struct layout only.
johannes
2013/2/16 Hauke Mehrtens <[email protected]>:
Quoted 13 lines
The mac address should be aligned to u16 to prevent an unaligned access in
drivers/ssb/pci.cwhere it is casted to__be16.Signed-off-by Hauke Mehrtens <[email protected]>--- include/linux/ssb/ssb.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)include/linux/ssb/ssb.h +0
-0
include/linux/ssb/ssb.h struct ssb_sprom_core_pwr_info { · line 30
Quoted 5 lines
include/linux/ssb/ssb.h +1
-0@@ -26,6 +26,7 @@ struct ssb_sprom_core_pwr_info {struct ssb_sprom {u8 revision; +u8 country_code;/* Country Code */ u8 il0mac[6 ];/* MAC address for 802.11b/g */
It looks a little hacky to me too, it's easy to forget about that requirement and break that again in the future.
What about not casting il0mac to u16 at all? Maybe we should just fill it as u8 (which it is)?
Signature · 1 line
Rafał
Quoted 3 lines · Rafał Miłecki
2013/2/16 Hauke Mehrtens <[email protected]>:
Quoted 2 lines
The mac address should be aligned to u16 to prevent an unaligned access in
drivers/ssb/pci.cwhere it is casted to__be16.
[]
Quoted 1 line
include/linux/ssb/ssb.h
Quoted 1 line
include/linux/ssb/ssb.h +0
-0
[]
Quoted 10 lines
include/linux/ssb/ssb.h struct ssb_sprom_core_pwr_info { · line 30
Quoted 6 lines
include/linux/ssb/ssb.h +1
-0@@ -26,6 +26,7 @@ struct ssb_sprom_core_pwr_info {struct ssb_sprom {u8 revision; +u8 country_code;/* Country Code */ u8 il0mac[6 ];/* MAC address for 802.11b/g */ It looks a little hacky to me too, it's easy to forget about that requirement and break that again in the future.
Quoted 3 lines
What about not casting il0mac to u16 at all? Maybe we should just fill it as u8 (which it is)?
Perhaps this?
From: Joe Perches <[email protected]>
Subject: [PATCH] ssb: pci: Standardize a function to get mac address
Don't require alignment of mac addresses to u16.
--- drivers/ssb/pci.c | 44 ++++++++++++++++++-------------------------- 1 file changed, 18 insertions(+), 26 deletions(-)
drivers/ssb/pci.c +18 -26
@@ -231,6 +231,15 @@ static inline u8 ssb_crc8(u8 crc, u8 data)return t[crc ^ data]; } +static void sprom_get_mac (char *mac,const u16 *in) +{ +int i; +for (i =0 ; i <3 ; i++) { + *mac++ = in[i]; + *mac++ = in[i] >>8 ; + } +} +static u8 ssb_sprom_crc (const u16 *sprom,u16 size) {int word;
@@ -341,8 +350,6 @@ static s8 r123_extract_antgain(u8 sprom_revision, const u16 *in,static void sprom_extract_r123 (struct ssb_sprom *out,const u16 *in) { -int i; -u16 v;u16 loc[3 ];if (out->revision ==3 )/* rev 3 moved MAC */
@@ -352,19 +359,10 @@ static void sprom_extract_r123(struct ssb_sprom *out, const u16 *in) loc[1 ] =SSB_SPROM1_ET0MAC ; loc[2 ] =SSB_SPROM1_ET1MAC ; } -for (i =0 ; i <3 ; i++) { - v = in[SPOFF (loc[0 ]) + i]; - *(((__be16 *)out->il0mac) + i) =cpu_to_be16 (v); - } +sprom_get_mac (out->il0mac, &in[SPOFF (loc[0 ])]);if (out->revision <3 ) {/* only rev 1-2 have et0, et1 */ -for (i =0 ; i <3 ; i++) { - v = in[SPOFF (loc[1 ]) + i]; - *(((__be16 *)out->et0mac) + i) =cpu_to_be16 (v); - } -for (i =0 ; i <3 ; i++) { - v = in[SPOFF (loc[2 ]) + i]; - *(((__be16 *)out->et1mac) + i) =cpu_to_be16 (v); - } +sprom_get_mac (out->et0mac, &in[SPOFF (loc[1 ])]); +sprom_get_mac (out->et1mac, &in[SPOFF (loc[2 ])]); }SPEX (et0phyaddr,SSB_SPROM1_ETHPHY ,SSB_SPROM1_ETHPHY_ET0A ,0 ); SPEX(et1phyaddr, SSB_SPROM1_ETHPHY, SSB_SPROM1_ETHPHY_ET1A,
@@ -454,19 +452,15 @@ static void sprom_extract_r458(struct ssb_sprom *out, const u16 *in)static void sprom_extract_r45 (struct ssb_sprom *out,const u16 *in) { -int i; -u16 v;u16 il0mac_offset;if (out->revision ==4 ) il0mac_offset =SSB_SPROM4_IL0MAC ;else il0mac_offset =SSB_SPROM5_IL0MAC ; -/* extract the MAC address */ -for (i =0 ; i <3 ; i++) { - v = in[SPOFF (il0mac_offset) + i]; - *(((__be16 *)out->il0mac) + i) =cpu_to_be16 (v); - } + +sprom_get_mac (out->il0mac, &in[SPOFF (il0mac_offset)]); +SPEX (et0phyaddr,SSB_SPROM4_ETHPHY ,SSB_SPROM4_ETHPHY_ET0A ,0 );SPEX (et1phyaddr,SSB_SPROM4_ETHPHY ,SSB_SPROM4_ETHPHY_ET1A ,SSB_SPROM4_ETHPHY_ET1A_SHIFT );
@@ -530,7 +524,7 @@ static void sprom_extract_r45(struct ssb_sprom *out, const u16 *in)static void sprom_extract_r8 (struct ssb_sprom *out,const u16 *in) {int i; -u16 v, o; +u16 o;u16 pwr_info_offset[] = {SSB_SROM8_PWR_INFO_CORE0 ,SSB_SROM8_PWR_INFO_CORE1 ,SSB_SROM8_PWR_INFO_CORE2 ,SSB_SROM8_PWR_INFO_CORE3
@@ -539,10 +533,8 @@ static void sprom_extract_r8(struct ssb_sprom *out, const u16 *in) ARRAY_SIZE(out->core_pwr_info));/* extract the MAC address */ -for (i =0 ; i <3 ; i++) { - v = in[SPOFF (SSB_SPROM8_IL0MAC ) + i]; - *(((__be16 *)out->il0mac) + i) =cpu_to_be16 (v); - } +sprom_get_mac (out->il0mac, &in[SSB_SPROM8_IL0MAC ]); +SPEX (board_rev,SSB_SPROM8_BOARDREV ,0xFFFF ,0 );SPEX (alpha2[0 ],SSB_SPROM8_CCODE ,0xff00 ,8 );SPEX (alpha2[1 ],SSB_SPROM8_CCODE ,0x00ff ,0 );
Signature · 1 line
1.8.1.2.459.gbcd45b4.dirty
Quoted 121 lines · Joe Perches
Quoted 3 lines · Rafał Miłecki
2013/2/16 Hauke Mehrtens <[email protected]>:
Quoted 2 lines
The mac address should be aligned to u16 to prevent an unaligned access in
drivers/ssb/pci.cwhere it is casted to__be16.[]
Quoted 1 line
include/linux/ssb/ssb.h
Quoted 1 line
include/linux/ssb/ssb.h +0
-0[]
Quoted 10 lines
include/linux/ssb/ssb.h struct ssb_sprom_core_pwr_info { · line 30
Quoted 6 lines
include/linux/ssb/ssb.h +1
-0@@ -26,6 +26,7 @@ struct ssb_sprom_core_pwr_info {struct ssb_sprom {u8 revision; +u8 country_code;/* Country Code */ u8 il0mac[6 ];/* MAC address for 802.11b/g */ It looks a little hacky to me too, it's easy to forget about that requirement and break that again in the future.
Quoted 3 lines
What about not casting il0mac to u16 at all? Maybe we should just fill it as u8 (which it is)?
Perhaps this?
From: Joe Perches <[email protected]>
Subject: [PATCH] ssb: pci: Standardize a function to get mac addressDon't require alignment of mac addresses to u16.
Signed-off-by Joe Perches <[email protected]>--- drivers/ssb/pci.c | 44 ++++++++++++++++++-------------------------- 1 file changed, 18 insertions(+), 26 deletions(-)drivers/ssb/pci.c +16
-22@@ -231,6 +231,15 @@ static inline u8 ssb_crc8(u8 crc, u8 data)return t[crc ^ data]; } +static void sprom_get_mac (char *mac,const u16 *in) +{ +int i; +for (i =0 ; i <3 ; i++) { + *mac++ = in[i]; + *mac++ = in[i] >>8 ; + } +} +static u8 ssb_sprom_crc (const u16 *sprom,u16 size) {int word;@@ -341,8 +350,6 @@ static s8 r123_extract_antgain(u8 sprom_revision, const u16 *in,static void sprom_extract_r123 (struct ssb_sprom *out,const u16 *in) { -int i; -u16 v;u16 loc[3 ];if (out->revision ==3 )/* rev 3 moved MAC */ @@ -352,19 +359,10 @@ static void sprom_extract_r123(struct ssb_sprom *out, const u16 *in) loc[1 ] =SSB_SPROM1_ET0MAC ; loc[2 ] =SSB_SPROM1_ET1MAC ; } -for (i =0 ; i <3 ; i++) { - v = in[SPOFF (loc[0 ]) + i]; - *(((__be16 *)out->il0mac) + i) =cpu_to_be16 (v); - } +sprom_get_mac (out->il0mac, &in[SPOFF (loc[0 ])]);if (out->revision <3 ) {/* only rev 1-2 have et0, et1 */ -for (i =0 ; i <3 ; i++) { - v = in[SPOFF (loc[1 ]) + i]; - *(((__be16 *)out->et0mac) + i) =cpu_to_be16 (v); - } -for (i =0 ; i <3 ; i++) { - v = in[SPOFF (loc[2 ]) + i]; - *(((__be16 *)out->et1mac) + i) =cpu_to_be16 (v); - } +sprom_get_mac (out->et0mac, &in[SPOFF (loc[1 ])]); +sprom_get_mac (out->et1mac, &in[SPOFF (loc[2 ])]); }SPEX (et0phyaddr,SSB_SPROM1_ETHPHY ,SSB_SPROM1_ETHPHY_ET0A ,0 ); SPEX(et1phyaddr, SSB_SPROM1_ETHPHY, SSB_SPROM1_ETHPHY_ET1A,@@ -454,19 +452,15 @@ static void sprom_extract_r458(struct ssb_sprom *out, const u16 *in)static void sprom_extract_r45 (struct ssb_sprom *out,const u16 *in) { -int i; -u16 v;u16 il0mac_offset;if (out->revision ==4 ) il0mac_offset =SSB_SPROM4_IL0MAC ;else il0mac_offset =SSB_SPROM5_IL0MAC ; -/* extract the MAC address */ -for (i =0 ; i <3 ; i++) { - v = in[SPOFF (il0mac_offset) + i]; - *(((__be16 *)out->il0mac) + i) =cpu_to_be16 (v); - } + +sprom_get_mac (out->il0mac, &in[SPOFF (il0mac_offset)]); +SPEX (et0phyaddr,SSB_SPROM4_ETHPHY ,SSB_SPROM4_ETHPHY_ET0A ,0 );SPEX (et1phyaddr,SSB_SPROM4_ETHPHY ,SSB_SPROM4_ETHPHY_ET1A ,SSB_SPROM4_ETHPHY_ET1A_SHIFT );@@ -530,7 +524,7 @@ static void sprom_extract_r45(struct ssb_sprom *out, const u16 *in)static void sprom_extract_r8 (struct ssb_sprom *out,const u16 *in) {int i; -u16 v, o; +u16 o;u16 pwr_info_offset[] = {SSB_SROM8_PWR_INFO_CORE0 ,SSB_SROM8_PWR_INFO_CORE1 ,SSB_SROM8_PWR_INFO_CORE2 ,SSB_SROM8_PWR_INFO_CORE3 @@ -539,10 +533,8 @@ static void sprom_extract_r8(struct ssb_sprom *out, const u16 *in) ARRAY_SIZE(out->core_pwr_info));
drivers/ssb/pci.c static void sprom_extract_r8(struct ssb_sprom *out, const u16 *in) · line 540
Quoted 10 lines
drivers/ssb/pci.c +2
-4/* extract the MAC address */ -for (i =0 ; i <3 ; i++) { - v = in[SPOFF (SSB_SPROM8_IL0MAC ) + i]; - *(((__be16 *)out->il0mac) + i) =cpu_to_be16 (v); - } +sprom_get_mac (out->il0mac, &in[SSB_SPROM8_IL0MAC ]); +SPEX (board_rev,SSB_SPROM8_BOARDREV ,0xFFFF ,0 );SPEX (alpha2[0 ],SSB_SPROM8_CCODE ,0xff00 ,8 );SPEX (alpha2[1 ],SSB_SPROM8_CCODE ,0x00ff ,0 );
I like the looks of sprom_get_mac() over that ugly *(((__be16 *)out->il0mac) construct, but this patch breaks ssb. The resulting MAC address is all ones. I have not yet figured out the problem.
Larry
Quoted 22 lines · Larry Finger
Quoted 21 lines · Joe Perches
Quoted 3 lines · Rafał Miłecki
2013/2/16 Hauke Mehrtens <[email protected]>:
Quoted 2 lines
The mac address should be aligned to u16 to prevent an unaligned access in
drivers/ssb/pci.cwhere it is casted to__be16.[]
Quoted 1 line
include/linux/ssb/ssb.h
Quoted 1 line
include/linux/ssb/ssb.h +0
-0[]
Quoted 13 lines
include/linux/ssb/ssb.h struct ssb_sprom_core_pwr_info { · line 30
Quoted 6 lines
include/linux/ssb/ssb.h +1
-0@@ -26,6 +26,7 @@ struct ssb_sprom_core_pwr_info {struct ssb_sprom {u8 revision; +u8 country_code;/* Country Code */ u8 il0mac[6 ];/* MAC address for 802.11b/g */ It looks a little hacky to me too, it's easy to forget about that requirement and break that again in the future.
What about not casting il0mac to u16 at all? Maybe we should just fill it as u8 (which it is)?
Quoted 6 lines
Quoted 6 lines
Perhaps this?
From: Joe Perches <[email protected]>
Subject: [PATCH] ssb: pci: Standardize a function to get mac addressDon't require alignment of mac addresses to u16.
[]
Quoted 1 line
drivers/ssb/pci.c
Quoted 1 line
drivers/ssb/pci.c +0
-0
[]
Quoted 24 lines
Quoted 24 lines
drivers/ssb/pci.c +9
-2@@ -231,6 +231,15 @@ static inline u8 ssb_crc8(u8 crc, u8 data)return t[crc ^ data]; } +static void sprom_get_mac (char *mac,const u16 *in) +{ +int i; +for (i =0 ; i <3 ; i++) { + *mac++ = in[i]; + *mac++ = in[i] >>8 ; + } +} +static u8 ssb_sprom_crc (const u16 *sprom,u16 size) {int word;@@ -341,8 +350,6 @@ static s8 r123_extract_antgain(u8 sprom_revision, const u16 *in,static void sprom_extract_r123 (struct ssb_sprom *out,const u16 *in) { -int i; -u16 v;u16 loc[3 ];
Quoted 10 lines
drivers/ssb/pci.c static void sprom_extract_r123(struct ssb_sprom *out, const u16 *in) · line 362
Quoted 10 lines
drivers/ssb/pci.c +1
-4if (out->revision ==3 )/* rev 3 moved MAC */ @@ -352,19 +359,10 @@ static void sprom_extract_r123(struct ssb_sprom *out, const u16 *in) loc[1 ] =SSB_SPROM1_ET0MAC ; loc[2 ] =SSB_SPROM1_ET1MAC ; } -for (i =0 ; i <3 ; i++) { - v = in[SPOFF (loc[0 ]) + i]; - *(((__be16 *)out->il0mac) + i) =cpu_to_be16 (v); - } +sprom_get_mac (out->il0mac, &in[SPOFF (loc[0 ])]);
[]
Quoted 3 lines
I like the looks of
sprom_get_mac()over that ugly *(((__be16 *)out->il0mac) construct, but this patch breaks ssb. The resulting MAC address is all ones. I have not yet figured out the problem.
Dunno, I must have done something stupid.
I don't have one of these but the transform looked correct when I did it.
I'm not sure it's the best solution anyway because some of the other ether address functions like compare_ether_addr also require 2 byte alignment and cast to u16.
cheers, Joe
Quoted 29 lines · Joe Perches
Quoted 28 lines · Larry Finger
Quoted 27 lines · Joe Perches
Quoted 3 lines · Rafał Miłecki
2013/2/16 Hauke Mehrtens <[email protected]>:
Quoted 2 lines
The mac address should be aligned to u16 to prevent an unaligned access in
drivers/ssb/pci.cwhere it is casted to__be16.[]
Quoted 1 line
include/linux/ssb/ssb.h
Quoted 1 line
include/linux/ssb/ssb.h +0
-0[]
Quoted 10 lines
include/linux/ssb/ssb.h struct ssb_sprom_core_pwr_info { · line 30
Quoted 6 lines
include/linux/ssb/ssb.h +1
-0@@ -26,6 +26,7 @@ struct ssb_sprom_core_pwr_info {struct ssb_sprom {u8 revision; +u8 country_code;/* Country Code */ u8 il0mac[6 ];/* MAC address for 802.11b/g */ It looks a little hacky to me too, it's easy to forget about that requirement and break that again in the future.
Quoted 3 lines
What about not casting il0mac to u16 at all? Maybe we should just fill it as u8 (which it is)?
Perhaps this?
From: Joe Perches <[email protected]>
Subject: [PATCH] ssb: pci: Standardize a function to get mac addressDon't require alignment of mac addresses to u16.
...
Quoted 6 lines
Quoted 3 lines
I like the looks of
sprom_get_mac()over that ugly *(((__be16 *)out->il0mac) construct, but this patch breaks ssb. The resulting MAC address is all ones. I have not yet figured out the problem.Dunno, I must have done something stupid.
Quoted 7 lines
I don't have one of these but the transform looked correct when I did it.
I'm not sure it's the best solution anyway because some of the other ether address functions like
compare_ether_addralso require 2 byte alignment and cast to u16.
Your patch looks good (haven't tested it), but as you said we should still align the mac addresses to u16 so functions like compare_ether_addr work with them.
There is also a v2 of my patch:
http://www.spinics.net/lists/linux-wireless/msg103628.html
Hauke
Quoted 47 lines · Hauke Mehrtens
Quoted 29 lines · Joe Perches
Quoted 28 lines · Larry Finger
Quoted 27 lines · Joe Perches
Quoted 3 lines · Rafał Miłecki
2013/2/16 Hauke Mehrtens <[email protected]>:
Quoted 2 lines
The mac address should be aligned to u16 to prevent an unaligned access in
drivers/ssb/pci.cwhere it is casted to__be16.[]
Quoted 1 line
include/linux/ssb/ssb.h
Quoted 1 line
include/linux/ssb/ssb.h +0
-0[]
Quoted 10 lines
include/linux/ssb/ssb.h struct ssb_sprom_core_pwr_info { · line 30
Quoted 6 lines
include/linux/ssb/ssb.h +1
-0@@ -26,6 +26,7 @@ struct ssb_sprom_core_pwr_info {struct ssb_sprom {u8 revision; +u8 country_code;/* Country Code */ u8 il0mac[6 ];/* MAC address for 802.11b/g */ It looks a little hacky to me too, it's easy to forget about that requirement and break that again in the future.
Quoted 3 lines
What about not casting il0mac to u16 at all? Maybe we should just fill it as u8 (which it is)?
Perhaps this?
From: Joe Perches <[email protected]>
Subject: [PATCH] ssb: pci: Standardize a function to get mac addressDon't require alignment of mac addresses to u16.
...
Quoted 6 lines
Quoted 3 lines
I like the looks of
sprom_get_mac()over that ugly *(((__be16 *)out->il0mac) construct, but this patch breaks ssb. The resulting MAC address is all ones. I have not yet figured out the problem.Dunno, I must have done something stupid.
Quoted 7 lines
I don't have one of these but the transform looked correct when I did it.
I'm not sure it's the best solution anyway because some of the other ether address functions like
compare_ether_addralso require 2 byte alignment and cast to u16.
Quoted 6 lines
Your patch looks good (haven't tested it), but as you said we should still align the mac addresses to u16 so functions like
compare_ether_addrwork with them.There is also a v2 of my patch:
http://www.spinics.net/lists/linux-wireless/msg103628.html
Seems OK to me, though I suggest using ETH_ALEN
instead of 6.
Maybe using both patches would be better still.
And as long as I'm futzing with ssb, there's another logging cleanup to go with it.
Here's a V2 with the missing SPOFF fixed.
Subject: [PATCH 1/2] ssb: pci: Standardize a function to get mac address
From: Joe Perches <[email protected]>
Don't require alignment of mac addresses to u16.
---
V2: Add missing SPOFF
drivers/ssb/pci.c | 44 ++++++++++++++++++-------------------------- 1 file changed, 18 insertions(+), 26 deletions(-)
drivers/ssb/pci.c +18 -26
@@ -231,6 +231,15 @@ static inline u8 ssb_crc8(u8 crc, u8 data)return t[crc ^ data]; } +static void sprom_get_mac (char *mac,const u16 *in) +{ +int i; +for (i =0 ; i <3 ; i++) { + *mac++ = in[i]; + *mac++ = in[i] >>8 ; + } +} +static u8 ssb_sprom_crc (const u16 *sprom,u16 size) {int word;
@@ -341,8 +350,6 @@ static s8 r123_extract_antgain(u8 sprom_revision, const u16 *in,static void sprom_extract_r123 (struct ssb_sprom *out,const u16 *in) { -int i; -u16 v;u16 loc[3 ];if (out->revision ==3 )/* rev 3 moved MAC */
@@ -352,19 +359,10 @@ static void sprom_extract_r123(struct ssb_sprom *out, const u16 *in) loc[1 ] =SSB_SPROM1_ET0MAC ; loc[2 ] =SSB_SPROM1_ET1MAC ; } -for (i =0 ; i <3 ; i++) { - v = in[SPOFF (loc[0 ]) + i]; - *(((__be16 *)out->il0mac) + i) =cpu_to_be16 (v); - } +sprom_get_mac (out->il0mac, &in[SPOFF (loc[0 ])]);if (out->revision <3 ) {/* only rev 1-2 have et0, et1 */ -for (i =0 ; i <3 ; i++) { - v = in[SPOFF (loc[1 ]) + i]; - *(((__be16 *)out->et0mac) + i) =cpu_to_be16 (v); - } -for (i =0 ; i <3 ; i++) { - v = in[SPOFF (loc[2 ]) + i]; - *(((__be16 *)out->et1mac) + i) =cpu_to_be16 (v); - } +sprom_get_mac (out->et0mac, &in[SPOFF (loc[1 ])]); +sprom_get_mac (out->et1mac, &in[SPOFF (loc[2 ])]); }SPEX (et0phyaddr,SSB_SPROM1_ETHPHY ,SSB_SPROM1_ETHPHY_ET0A ,0 ); SPEX(et1phyaddr, SSB_SPROM1_ETHPHY, SSB_SPROM1_ETHPHY_ET1A,
@@ -454,19 +452,15 @@ static void sprom_extract_r458(struct ssb_sprom *out, const u16 *in)static void sprom_extract_r45 (struct ssb_sprom *out,const u16 *in) { -int i; -u16 v;u16 il0mac_offset;if (out->revision ==4 ) il0mac_offset =SSB_SPROM4_IL0MAC ;else il0mac_offset =SSB_SPROM5_IL0MAC ; -/* extract the MAC address */ -for (i =0 ; i <3 ; i++) { - v = in[SPOFF (il0mac_offset) + i]; - *(((__be16 *)out->il0mac) + i) =cpu_to_be16 (v); - } + +sprom_get_mac (out->il0mac, &in[SPOFF (il0mac_offset)]); +SPEX (et0phyaddr,SSB_SPROM4_ETHPHY ,SSB_SPROM4_ETHPHY_ET0A ,0 );SPEX (et1phyaddr,SSB_SPROM4_ETHPHY ,SSB_SPROM4_ETHPHY_ET1A ,SSB_SPROM4_ETHPHY_ET1A_SHIFT );
@@ -530,7 +524,7 @@ static void sprom_extract_r45(struct ssb_sprom *out, const u16 *in)static void sprom_extract_r8 (struct ssb_sprom *out,const u16 *in) {int i; -u16 v, o; +u16 o;u16 pwr_info_offset[] = {SSB_SROM8_PWR_INFO_CORE0 ,SSB_SROM8_PWR_INFO_CORE1 ,SSB_SROM8_PWR_INFO_CORE2 ,SSB_SROM8_PWR_INFO_CORE3
@@ -539,10 +533,8 @@ static void sprom_extract_r8(struct ssb_sprom *out, const u16 *in) ARRAY_SIZE(out->core_pwr_info));/* extract the MAC address */ -for (i =0 ; i <3 ; i++) { - v = in[SPOFF (SSB_SPROM8_IL0MAC ) + i]; - *(((__be16 *)out->il0mac) + i) =cpu_to_be16 (v); - } +sprom_get_mac (out->il0mac, &in[SPOFF (SSB_SPROM8_IL0MAC )]); +SPEX (board_rev,SSB_SPROM8_BOARDREV ,0xFFFF ,0 );SPEX (alpha2[0 ],SSB_SPROM8_CCODE ,0xff00 ,8 );SPEX (alpha2[1 ],SSB_SPROM8_CCODE ,0x00ff ,0 );
Signature · 1 line
1.8.1.2.459.gbcd45b4.dirty
Larry Finger
Tested-byQuoted 68 lines · Joe Perches
Quoted 47 lines · Hauke Mehrtens
Quoted 29 lines · Joe Perches
Quoted 28 lines · Larry Finger
Quoted 27 lines · Joe Perches
Quoted 3 lines · Rafał Miłecki
2013/2/16 Hauke Mehrtens <[email protected]>:
Quoted 2 lines
The mac address should be aligned to u16 to prevent an unaligned access in
drivers/ssb/pci.cwhere it is casted to__be16.[]
Quoted 1 line
include/linux/ssb/ssb.h
Quoted 1 line
include/linux/ssb/ssb.h +0
-0[]
Quoted 10 lines
include/linux/ssb/ssb.h struct ssb_sprom_core_pwr_info { · line 30
Quoted 6 lines
include/linux/ssb/ssb.h +1
-0@@ -26,6 +26,7 @@ struct ssb_sprom_core_pwr_info {struct ssb_sprom {u8 revision; +u8 country_code;/* Country Code */ u8 il0mac[6 ];/* MAC address for 802.11b/g */ It looks a little hacky to me too, it's easy to forget about that requirement and break that again in the future.
Quoted 3 lines
What about not casting il0mac to u16 at all? Maybe we should just fill it as u8 (which it is)?
Perhaps this?
From: Joe Perches <[email protected]>
Subject: [PATCH] ssb: pci: Standardize a function to get mac addressDon't require alignment of mac addresses to u16.
...
Quoted 6 lines
Quoted 3 lines
I like the looks of
sprom_get_mac()over that ugly *(((__be16 *)out->il0mac) construct, but this patch breaks ssb. The resulting MAC address is all ones. I have not yet figured out the problem.Dunno, I must have done something stupid.
Quoted 7 lines
I don't have one of these but the transform looked correct when I did it.
I'm not sure it's the best solution anyway because some of the other ether address functions like
compare_ether_addralso require 2 byte alignment and cast to u16.Quoted 6 lines
Your patch looks good (haven't tested it), but as you said we should still align the mac addresses to u16 so functions like
compare_ether_addrwork with them.There is also a v2 of my patch:
http://www.spinics.net/lists/linux-wireless/msg103628.htmlSeems OK to me, though I suggest using
ETH_ALEN
instead of 6.Maybe using both patches would be better still.
And as long as I'm futzing with ssb, there's another logging cleanup to go with it.
Here's a V2 with the missing SPOFF fixed.
Subject: [PATCH 1/2] ssb: pci: Standardize a function to get mac address
From: Joe Perches <[email protected]>
Quoted 6 lines
Don't require alignment of mac addresses to u16.
Signed-off-by Joe Perches <[email protected]>---
V2: Add missing SPOFF
Larry
Quoted 102 lines
drivers/ssb/pci.c | 44 ++++++++++++++++++-------------------------- 1 file changed, 18 insertions(+), 26 deletions(-)drivers/ssb/pci.c +18
-26@@ -231,6 +231,15 @@ static inline u8 ssb_crc8(u8 crc, u8 data)return t[crc ^ data]; } +static void sprom_get_mac (char *mac,const u16 *in) +{ +int i; +for (i =0 ; i <3 ; i++) { + *mac++ = in[i]; + *mac++ = in[i] >>8 ; + } +} +static u8 ssb_sprom_crc (const u16 *sprom,u16 size) {int word;@@ -341,8 +350,6 @@ static s8 r123_extract_antgain(u8 sprom_revision, const u16 *in,static void sprom_extract_r123 (struct ssb_sprom *out,const u16 *in) { -int i; -u16 v;u16 loc[3 ];if (out->revision ==3 )/* rev 3 moved MAC */ @@ -352,19 +359,10 @@ static void sprom_extract_r123(struct ssb_sprom *out, const u16 *in) loc[1 ] =SSB_SPROM1_ET0MAC ; loc[2 ] =SSB_SPROM1_ET1MAC ; } -for (i =0 ; i <3 ; i++) { - v = in[SPOFF (loc[0 ]) + i]; - *(((__be16 *)out->il0mac) + i) =cpu_to_be16 (v); - } +sprom_get_mac (out->il0mac, &in[SPOFF (loc[0 ])]);if (out->revision <3 ) {/* only rev 1-2 have et0, et1 */ -for (i =0 ; i <3 ; i++) { - v = in[SPOFF (loc[1 ]) + i]; - *(((__be16 *)out->et0mac) + i) =cpu_to_be16 (v); - } -for (i =0 ; i <3 ; i++) { - v = in[SPOFF (loc[2 ]) + i]; - *(((__be16 *)out->et1mac) + i) =cpu_to_be16 (v); - } +sprom_get_mac (out->et0mac, &in[SPOFF (loc[1 ])]); +sprom_get_mac (out->et1mac, &in[SPOFF (loc[2 ])]); }SPEX (et0phyaddr,SSB_SPROM1_ETHPHY ,SSB_SPROM1_ETHPHY_ET0A ,0 ); SPEX(et1phyaddr, SSB_SPROM1_ETHPHY, SSB_SPROM1_ETHPHY_ET1A,@@ -454,19 +452,15 @@ static void sprom_extract_r458(struct ssb_sprom *out, const u16 *in)static void sprom_extract_r45 (struct ssb_sprom *out,const u16 *in) { -int i; -u16 v;u16 il0mac_offset;if (out->revision ==4 ) il0mac_offset =SSB_SPROM4_IL0MAC ;else il0mac_offset =SSB_SPROM5_IL0MAC ; -/* extract the MAC address */ -for (i =0 ; i <3 ; i++) { - v = in[SPOFF (il0mac_offset) + i]; - *(((__be16 *)out->il0mac) + i) =cpu_to_be16 (v); - } + +sprom_get_mac (out->il0mac, &in[SPOFF (il0mac_offset)]); +SPEX (et0phyaddr,SSB_SPROM4_ETHPHY ,SSB_SPROM4_ETHPHY_ET0A ,0 );SPEX (et1phyaddr,SSB_SPROM4_ETHPHY ,SSB_SPROM4_ETHPHY_ET1A ,SSB_SPROM4_ETHPHY_ET1A_SHIFT );@@ -530,7 +524,7 @@ static void sprom_extract_r45(struct ssb_sprom *out, const u16 *in)static void sprom_extract_r8 (struct ssb_sprom *out,const u16 *in) {int i; -u16 v, o; +u16 o;u16 pwr_info_offset[] = {SSB_SROM8_PWR_INFO_CORE0 ,SSB_SROM8_PWR_INFO_CORE1 ,SSB_SROM8_PWR_INFO_CORE2 ,SSB_SROM8_PWR_INFO_CORE3 @@ -539,10 +533,8 @@ static void sprom_extract_r8(struct ssb_sprom *out, const u16 *in) ARRAY_SIZE(out->core_pwr_info));/* extract the MAC address */ -for (i =0 ; i <3 ; i++) { - v = in[SPOFF (SSB_SPROM8_IL0MAC ) + i]; - *(((__be16 *)out->il0mac) + i) =cpu_to_be16 (v); - } +sprom_get_mac (out->il0mac, &in[SPOFF (SSB_SPROM8_IL0MAC )]); +SPEX (board_rev,SSB_SPROM8_BOARDREV ,0xFFFF ,0 );SPEX (alpha2[0 ],SSB_SPROM8_CCODE ,0xff00 ,8 );SPEX (alpha2[1 ],SSB_SPROM8_CCODE ,0x00ff ,0 );
2013/2/21 Larry Finger <[email protected]>:
Quoted 91 lines · Joe Perches
Quoted 90 lines · Hauke Mehrtens
Quoted 65 lines · Joe Perches
Quoted 41 lines · Larry Finger
Quoted 39 lines · Joe Perches
Quoted 37 lines · Rafał Miłecki
Quoted 6 lines
2013/2/16 Hauke Mehrtens <[email protected]>:
Quoted 4 lines
The mac address should be aligned to u16 to prevent an unaligned access
indrivers/ssb/pci.cwhere it is casted to__be16.[]
Quoted 2 lines
include/linux/ssb/ssb.h
Quoted 2 lines
include/linux/ssb/ssb.h +0
-0[]
Quoted 12 lines
include/linux/ssb/ssb.h struct ssb_sprom_core_pwr_info { · line 30
Quoted 7 lines
include/linux/ssb/ssb.h +1
-0@@ -26,6 +26,7 @@ struct ssb_sprom_core_pwr_info {struct ssb_sprom {u8 revision; +u8 country_code;/* Country Code */ u8 il0mac[6 ];/* MAC address for 802.11b/g */ It looks a little hacky to me too, it's easy to forget about that requirement and break that again in the future.
Quoted 4 lines
What about not casting il0mac to u16 at all? Maybe we should just fill
it as u8 (which it is)?Perhaps this?
From: Joe Perches <[email protected]>
Subject: [PATCH] ssb: pci: Standardize a function to get mac addressDon't require alignment of mac addresses to u16.
...
Quoted 9 lines
Quoted 5 lines
I like the looks of
sprom_get_mac()over that ugly *(((__be16 *)out->il0mac)
construct, but this patch breaks ssb. The resulting MAC address is all ones. I
have not yet figured out the problem.Dunno, I must have done something stupid.
Quoted 7 lines
I don't have one of these but the transform looked correct when I did it.
I'm not sure it's the best solution anyway because some of the other ether address functions like
compare_ether_addralso require 2 byte alignment and cast to u16.Quoted 6 lines
Your patch looks good (haven't tested it), but as you said we should still align the mac addresses to u16 so functions like
compare_ether_addrwork with them.There is also a v2 of my patch:
http://www.spinics.net/lists/linux-wireless/msg103628.htmlSeems OK to me, though I suggest using
ETH_ALEN
instead of 6.Maybe using both patches would be better still.
And as long as I'm futzing with ssb, there's another logging cleanup to go with it.
Here's a V2 with the missing SPOFF fixed.
Subject: [PATCH 1/2] ssb: pci: Standardize a function to get mac address
From: Joe Perches <[email protected]>Don't require alignment of mac addresses to u16.
Quoted 7 lines
Quoted 4 lines
Signed-off-by Joe Perches <[email protected]>---
V2: Add missing SPOFF
Tested-by Larry Finger <[email protected]>
I didn't confirm my issue to be related to this patch, but with recent kernels my MAC has changed from
00:11:22:33:44:55
to
11:00:33:22:55:44
Larry: did you verify MAC didn't change for you?
Signature · 1 line
Rafał
Quoted 9 lines · Rafał Miłecki
2013/2/21 Larry Finger <[email protected]>:
Quoted 7 lines
Quoted 4 lines
Signed-off-by Joe Perches <[email protected]>---
V2: Add missing SPOFF
Tested-by Larry Finger <[email protected]>
Quoted 7 lines
I didn't confirm my issue to be related to this patch, but with recent kernels my MAC has changed from
00:11:22:33:44:55
to
11:00:33:22:55:44Larry: did you verify MAC didn't change for you?
I just checked it on PowerPC and it changed it the same way as yours did.
The problem is that the MAC is stored in the SPROM in big-endian order, thus the sequence
+ for (i = 0; i < 3; i++) {
+ *mac++ = in[i];
+ *mac++ = in[i] >> 8;
+ }
needs to be changed to
+ for (i = 0; i < 3; i++) {
+ *mac++ = in[i] >> 8;
+ *mac++ = in[i];
+ }
After that change, it is OK, at least on the PPC.
BTW, that patch is not yet in my copy of wireless-testing.
Larry
Quoted 100 lines · Rafał Miłecki
2013/2/21 Larry Finger <[email protected]>:
Quoted 91 lines · Joe Perches
Quoted 90 lines · Hauke Mehrtens
Quoted 65 lines · Joe Perches
Quoted 41 lines · Larry Finger
Quoted 39 lines · Joe Perches
Quoted 37 lines · Rafał Miłecki
Quoted 6 lines
2013/2/16 Hauke Mehrtens <[email protected]>:
Quoted 4 lines
The mac address should be aligned to u16 to prevent an unaligned access
indrivers/ssb/pci.cwhere it is casted to__be16.[]
Quoted 2 lines
include/linux/ssb/ssb.h
Quoted 2 lines
include/linux/ssb/ssb.h +0
-0[]
Quoted 12 lines
include/linux/ssb/ssb.h struct ssb_sprom_core_pwr_info { · line 30
Quoted 7 lines
include/linux/ssb/ssb.h +1
-0@@ -26,6 +26,7 @@ struct ssb_sprom_core_pwr_info {struct ssb_sprom {u8 revision; +u8 country_code;/* Country Code */ u8 il0mac[6 ];/* MAC address for 802.11b/g */ It looks a little hacky to me too, it's easy to forget about that requirement and break that again in the future.
Quoted 4 lines
What about not casting il0mac to u16 at all? Maybe we should just fill
it as u8 (which it is)?Perhaps this?
From: Joe Perches <[email protected]>
Subject: [PATCH] ssb: pci: Standardize a function to get mac addressDon't require alignment of mac addresses to u16.
...
Quoted 9 lines
Quoted 5 lines
I like the looks of
sprom_get_mac()over that ugly *(((__be16 *)out->il0mac)
construct, but this patch breaks ssb. The resulting MAC address is all ones. I
have not yet figured out the problem.Dunno, I must have done something stupid.
Quoted 7 lines
I don't have one of these but the transform looked correct when I did it.
I'm not sure it's the best solution anyway because some of the other ether address functions like
compare_ether_addralso require 2 byte alignment and cast to u16.Quoted 6 lines
Your patch looks good (haven't tested it), but as you said we should still align the mac addresses to u16 so functions like
compare_ether_addrwork with them.There is also a v2 of my patch:
http://www.spinics.net/lists/linux-wireless/msg103628.htmlSeems OK to me, though I suggest using
ETH_ALEN
instead of 6.Maybe using both patches would be better still.
And as long as I'm futzing with ssb, there's another logging cleanup to go with it.
Here's a V2 with the missing SPOFF fixed.
Subject: [PATCH 1/2] ssb: pci: Standardize a function to get mac address
From: Joe Perches <[email protected]>Don't require alignment of mac addresses to u16.
Quoted 7 lines
Quoted 4 lines
Signed-off-by Joe Perches <[email protected]>---
V2: Add missing SPOFF
Tested-by Larry Finger <[email protected]>
Quoted 7 lines
I didn't confirm my issue to be related to this patch, but with recent kernels my MAC has changed from
00:11:22:33:44:55
to
11:00:33:22:55:44Larry: did you verify MAC didn't change for you?
I just checked on x86_64, and the bytes are swapped here too. Do you want to push the patch, or should I do it?
Larry
2013/3/10 Larry Finger <[email protected]>:
Quoted 128 lines · Rafał Miłecki
Quoted 127 lines
2013/2/21 Larry Finger <[email protected]>:
Quoted 109 lines · Joe Perches
Quoted 107 lines · Hauke Mehrtens
Quoted 80 lines · Joe Perches
Quoted 51 lines · Larry Finger
Quoted 48 lines · Joe Perches
Quoted 45 lines · Rafał Miłecki
Quoted 8 lines
2013/2/16 Hauke Mehrtens <[email protected]>:
Quoted 5 lines
The mac address should be aligned to u16 to prevent an unaligned access
indrivers/ssb/pci.cwhere it is casted to__be16.[]
Quoted 3 lines
include/linux/ssb/ssb.h
Quoted 3 lines
include/linux/ssb/ssb.h +0
-0[]
Quoted 14 lines
include/linux/ssb/ssb.h struct ssb_sprom_core_pwr_info { · line 30
Quoted 8 lines
include/linux/ssb/ssb.h +1
-0@@ -26,6 +26,7 @@ struct ssb_sprom_core_pwr_info {struct ssb_sprom {u8 revision; +u8 country_code;/* Country Code */ u8 il0mac[6 ];/* MAC address for 802.11b/g */ It looks a little hacky to me too, it's easy to forget about that requirement and break that again in the future.
Quoted 4 lines
What about not casting il0mac to u16 at all? Maybe we should just fill
it as u8 (which it is)?Perhaps this?
From: Joe Perches <[email protected]>
Subject: [PATCH] ssb: pci: Standardize a function to get mac addressDon't require alignment of mac addresses to u16.
...
Quoted 11 lines
Quoted 6 lines
I like the looks of
sprom_get_mac()over that ugly *(((__be16 *)out->il0mac)
construct, but this patch breaks ssb. The resulting MAC address is all
ones. I
have not yet figured out the problem.Dunno, I must have done something stupid.
Quoted 7 lines
I don't have one of these but the transform looked correct when I did it.
I'm not sure it's the best solution anyway because some of the other ether address functions like
compare_ether_addralso require 2 byte alignment and cast to u16.Quoted 6 lines
Your patch looks good (haven't tested it), but as you said we should still align the mac addresses to u16 so functions like
compare_ether_addrwork with them.There is also a v2 of my patch:
http://www.spinics.net/lists/linux-wireless/msg103628.htmlSeems OK to me, though I suggest using
ETH_ALEN
instead of 6.Maybe using both patches would be better still.
And as long as I'm futzing with ssb, there's another logging cleanup to go with it.
Here's a V2 with the missing SPOFF fixed.
Subject: [PATCH 1/2] ssb: pci: Standardize a function to get mac address
From: Joe Perches <[email protected]>Don't require alignment of mac addresses to u16.
Quoted 8 lines
Quoted 4 lines
Signed-off-by Joe Perches <[email protected]>---
V2: Add missing SPOFF
Tested-by Larry Finger <[email protected]>I didn't confirm my issue to be related to this patch, but with recent kernels my MAC has changed from
00:11:22:33:44:55
to
11:00:33:22:55:44
Quoted 5 lines
Quoted 1 line
Larry: did you verify MAC didn't change for you?
I just checked on
x86_64, and the bytes are swapped here too. Do you want to push the patch, or should I do it?
Feel free to fix. I've another 3 regressions to track...
Signature · 1 line
Rafał
Quoted 2 lines · Rafał Miłecki
Feel free to fix. I've another 3 regressions to track...
Upon further investigation, the flipping of the MAC bytes was not due to "ssb: pci: Standardize a function to get mac address", or "ssb: fix unaligned access to mac address". For other reasons, I had to run 3.8 today and found the flipping, even though neither patch was installed. Joe and Hauke are blameless - they merely reproduced the existing bug. I have no real desire to find out when that error was introduced as I am not an archeologist. Note that b43legacy does not have the problem, thus it was introduced after the split of those two variants.
I will submit the fix.
Larry
2013/3/10 Larry Finger <[email protected]>:
Quoted 6 lines · Rafał Miłecki
Quoted 3 lines
Feel free to fix. I've another 3 regressions to track...
Quoted 8 lines
Upon further investigation, the flipping of the MAC bytes was not due to "ssb: pci: Standardize a function to get mac address", or "ssb: fix unaligned access to mac address". For other reasons, I had to run 3.8 today and found the flipping, even though neither patch was installed. Joe and Hauke are blameless - they merely reproduced the existing bug. I have no real desire to find out when that error was introduced as I am not an archeologist. Note that b43legacy does not have the problem, thus it was introduced after the split of those two variants.
It's not about blaming anyone, just finish the bug :)
Reverting e5652756ff36ed9e1283121f788e6a17117efcab which is "ssb: pci:
Standardize a function to get mac address" fixes the MAC address issue for me.
I'm reverting on top of c49141682cfa9713e67f515cc7faf6145720ec3d.
Signature · 1 line
Rafał
PATCH 2/2 ssb: Convert ssb_printk to ssb_<level>
In reply to Hauke MehrtensUse a more current logging style.
Convert ssb_dbprint to ssb_dbg too.
--- drivers/ssb/driver_chipcommon.c | 2 +- drivers/ssb/driver_chipcommon_pmu.c | 41 +++++++++++++--------------- drivers/ssb/driver_mipscore.c | 25 ++++++++--------- drivers/ssb/driver_pcicore.c | 15 +++++------ drivers/ssb/embedded.c | 5 ++-- drivers/ssb/main.c | 51 +++++++++++++++-------------------- drivers/ssb/pci.c | 53 +++++++++++++++++-------------------- drivers/ssb/pcmcia.c | 46 ++++++++++++++------------------ drivers/ssb/scan.c | 31 ++++++++-------------- drivers/ssb/sprom.c | 4 +-- drivers/ssb/ssb_private.h | 19 ++++++++++--- 11 files changed, 135 insertions(+), 157 deletions(-)
drivers/ssb/driver_chipcommon.c +1 -1
@@ -354,7 +354,7 @@ void ssb_chipcommon_init(struct ssb_chipcommon *cc)if (cc->dev->id.revision >=11 ) cc->status =chipco_read32 (cc,SSB_CHIPCO_CHIPSTAT ); - ssb_dprintk(KERN_INFO PFX "chipcommon status is 0x%x\n", cc->status); +ssb_dbg ("chipcommon status is 0x%x\n" , cc->status);if (cc->dev->id.revision >=20 ) {chipco_write32 (cc,SSB_CHIPCO_GPIOPULLUP ,0 );
drivers/ssb/driver_chipcommon_pmu.c +18 -23
101 lines not on this page · raw message
drivers/ssb/driver_mipscore.c +13 -12
@@ -167,21 +167,22 @@ static void set_irq(struct ssb_device *dev, unsigned int irq) irqflag |= (ipsflag & ~ipsflag_irq_mask[irq]);ssb_write32 (mdev,SSB_IPSFLAG , irqflag); } - ssb_dprintk(KERN_INFO PFX -"set_irq: core 0x%04x, irq %d => %d\n" , - dev->id.coreid, oldirq+2, irq+2); +ssb_dbg ("set_irq: core 0x%04x, irq %d => %d\n" , + dev->id.coreid, oldirq+2 , irq+2 ); }static void print_irq (struct ssb_device *dev,unsigned int irq) { -int i;static const char *irq_name[] = {"2(S)" ,"3" ,"4" ,"5" ,"6" ,"D" ,"I" }; - ssb_dprintk(KERN_INFO PFX - "core 0x%04x, irq :", dev->id.coreid); -for (i =0 ; i <=6 ; i++) { -ssb_dprintk (" %s%s" , irq_name[i], i==irq?"*" :" " ); - } -ssb_dprintk ("\n" ); +ssb_dbg ("core 0x%04x, irq : %s%s %s%s %s%s %s%s %s%s %s%s %s%s\n" , + dev->id.coreid, + irq_name[0 ], irq ==0 ?"*" :" " , + irq_name[1 ], irq ==1 ?"*" :" " , + irq_name[2 ], irq ==2 ?"*" :" " , + irq_name[3 ], irq ==3 ?"*" :" " , + irq_name[4 ], irq ==4 ?"*" :" " , + irq_name[5 ], irq ==5 ?"*" :" " , + irq_name[6 ], irq ==6 ?"*" :" " ); }static void dump_irq (struct ssb_bus *bus)
@@ -286,7 +287,7 @@ void ssb_mipscore_init(struct ssb_mipscore *mcore)if (!mcore->dev)return ;/* We don't have a MIPS core */ - ssb_dprintk(KERN_INFO PFX "Initializing MIPS core...\n"); +ssb_dbg ("Initializing MIPS core...\n" ); bus = mcore->dev->bus; hz =ssb_clockspeed (bus);
@@ -334,7 +335,7 @@ void ssb_mipscore_init(struct ssb_mipscore *mcore)break ; } } - ssb_dprintk(KERN_INFO PFX "after irq reconfiguration\n"); +ssb_dbg ("after irq reconfiguration\n" );dump_irq (bus);ssb_mips_serial_init (mcore);
drivers/ssb/driver_pcicore.c +7 -8
@@ -263,8 +263,7 @@ int ssb_pcicore_plat_dev_init(struct pci_dev *d)return -ENODEV ; } -ssb_printk (KERN_INFO "PCI: Fixing up device %s\n" , -pci_name (d)); +ssb_info ("PCI: Fixing up device %s\n" ,pci_name (d));/* Fix up interrupt lines */ d->irq =ssb_mips_irq (extpci_core->dev) +2 ;
@@ -285,12 +284,12 @@ static void ssb_pcicore_fixup_pcibridge(struct pci_dev *dev)if (dev->bus->number !=0 ||PCI_SLOT (dev->devfn) !=0 )return ; -ssb_printk (KERN_INFO "PCI: Fixing up bridge %s\n" ,pci_name (dev)); +ssb_info ("PCI: Fixing up bridge %s\n" ,pci_name (dev));/* Enable PCI bridge bus mastering and memory space */ pci_set_master (dev);if (pcibios_enable_device (dev, ~0 ) <0 ) { -ssb_printk (KERN_ERR "PCI: SSB bridge enable failed\n" ); +ssb_err ("PCI: SSB bridge enable failed\n" );return ; }
@@ -299,8 +298,8 @@ static void ssb_pcicore_fixup_pcibridge(struct pci_dev *dev)/* Make sure our latency is high enough to handle the devices behind us */ lat =168 ; -ssb_printk (KERN_INFO "PCI: Fixing latency timer of device %s to %u\n" , -pci_name (dev), lat); +ssb_info ("PCI: Fixing latency timer of device %s to %u\n" , +pci_name (dev), lat);pci_write_config_byte (dev,PCI_LATENCY_TIMER , lat); }DECLARE_PCI_FIXUP_EARLY (PCI_ANY_ID ,PCI_ANY_ID , ssb_pcicore_fixup_pcibridge);
@@ -323,7 +322,7 @@ static void ssb_pcicore_init_hostmode(struct ssb_pcicore *pc)return ; extpci_core = pc; - ssb_dprintk(KERN_INFO PFX "PCIcore in host mode found\n"); +ssb_dbg ("PCIcore in host mode found\n" );/* Reset devices on the external PCI bus */ val =SSB_PCICORE_CTL_RST_OE ; val |=SSB_PCICORE_CTL_CLK_OE ;
@@ -338,7 +337,7 @@ static void ssb_pcicore_init_hostmode(struct ssb_pcicore *pc)udelay (1 );/* Assertion time demanded by the PCI standard */ if (pc->dev->bus->has_cardbus_slot) { - ssb_dprintk(KERN_INFO PFX "CardBus slot detected\n"); +ssb_dbg ("CardBus slot detected\n" ); pc->cardbusmode =1 ;/* GPIO 1 resets the bridge */ ssb_gpio_out (pc->dev->bus,1 ,1 );
drivers/ssb/embedded.c +2 -3
@@ -57,9 +57,8 @@ int ssb_watchdog_register(struct ssb_bus *bus) bus->busnumber, &wdt, sizeof(wdt));if (IS_ERR (pdev)) { - ssb_dprintk(KERN_INFO PFX -"can not register watchdog device, err: %li\n" , - PTR_ERR(pdev)); +ssb_dbg ("can not register watchdog device, err: %li\n" , +PTR_ERR (pdev));return PTR_ERR (pdev); }
drivers/ssb/main.c +22 -29
131 lines not on this page · raw message
drivers/ssb/pci.c +24 -29
132 lines not on this page · raw message
drivers/ssb/pcmcia.c +20 -26
115 lines not on this page · raw message
drivers/ssb/scan.c +11 -20
@@ -125,8 +125,7 @@ static u16 pcidev_to_chipid(struct pci_dev *pci_dev) chipid_fallback =0x4401 ;break ;default : - ssb_printk(KERN_ERR PFX - "PCI-ID not in fallback list\n"); +ssb_err ("PCI-ID not in fallback list\n" ); }return chipid_fallback;
@@ -152,8 +151,7 @@ static u8 chipid_to_nrcores(u16 chipid)case 0x4704 :return 9 ;default : - ssb_printk(KERN_ERR PFX - "CHIPID not in nrcores fallback list\n"); +ssb_err ("CHIPID not in nrcores fallback list\n" ); }return 1 ;
@@ -320,15 +318,13 @@ int ssb_bus_scan(struct ssb_bus *bus, bus->chip_package =0 ; } } - ssb_printk(KERN_INFO PFX "Found chip with id 0x%04X, rev 0x%02X and " -"package 0x%02X\n" , bus->chip_id, bus->chip_rev, - bus->chip_package); +ssb_info ("Found chip with id 0x%04X, rev 0x%02X and package 0x%02X\n" , + bus->chip_id, bus->chip_rev, bus->chip_package);if (!bus->nr_devices) bus->nr_devices =chipid_to_nrcores (bus->chip_id);if (bus->nr_devices >ARRAY_SIZE (bus->devices)) { - ssb_printk(KERN_ERR PFX -"More than %d ssb cores found (%d)\n" , - SSB_MAX_NR_CORES, bus->nr_devices); +ssb_err ("More than %d ssb cores found (%d)\n" , +SSB_MAX_NR_CORES , bus->nr_devices); goto err_unmap; }if (bus->bustype ==SSB_BUSTYPE_SSB ) {
@@ -370,8 +366,7 @@ int ssb_bus_scan(struct ssb_bus *bus, nr_80211_cores++;if (nr_80211_cores >1 ) {if (!we_support_multiple_80211_cores (bus)) { - ssb_dprintk(KERN_INFO PFX "Ignoring additional " - "802.11 core\n"); +ssb_dbg ("Ignoring additional 802.11 core\n" );continue ; } }
@@ -379,8 +374,7 @@ int ssb_bus_scan(struct ssb_bus *bus,case SSB_DEV_EXTIF :#ifdef CONFIG_SSB_DRIVER_EXTIF if (bus->extif.dev) { - ssb_printk(KERN_WARNING PFX - "WARNING: Multiple EXTIFs found\n"); +ssb_warn ("WARNING: Multiple EXTIFs found\n" );break ; } bus->extif.dev = dev;
@@ -388,8 +382,7 @@ int ssb_bus_scan(struct ssb_bus *bus,break ;case SSB_DEV_CHIPCOMMON :if (bus->chipco.dev) { - ssb_printk(KERN_WARNING PFX - "WARNING: Multiple ChipCommon found\n"); +ssb_warn ("WARNING: Multiple ChipCommon found\n" );break ; } bus->chipco.dev = dev;
@@ -398,8 +391,7 @@ int ssb_bus_scan(struct ssb_bus *bus,case SSB_DEV_MIPS_3302 :#ifdef CONFIG_SSB_DRIVER_MIPS if (bus->mipscore.dev) { - ssb_printk(KERN_WARNING PFX - "WARNING: Multiple MIPS cores found\n"); +ssb_warn ("WARNING: Multiple MIPS cores found\n" );break ; } bus->mipscore.dev = dev;
@@ -420,8 +412,7 @@ int ssb_bus_scan(struct ssb_bus *bus, } }if (bus->pcicore.dev) { - ssb_printk(KERN_WARNING PFX - "WARNING: Multiple PCI(E) cores found\n"); +ssb_warn ("WARNING: Multiple PCI(E) cores found\n" );break ; } bus->pcicore.dev = dev;
drivers/ssb/sprom.c +2 -2
@@ -127,13 +127,13 @@ ssize_t ssb_attr_sprom_store(struct ssb_bus *bus, goto out_kfree; err =ssb_devices_freeze (bus, &freeze);if (err) { - ssb_printk(KERN_ERR PFX "SPROM write: Could not freeze all devices\n"); +ssb_err ("SPROM write: Could not freeze all devices\n" ); goto out_unlock; } res =sprom_write (bus, sprom); err =ssb_devices_thaw (&freeze);if (err) - ssb_printk(KERN_ERR PFX "SPROM write: Could not thaw all devices\n"); +ssb_err ("SPROM write: Could not thaw all devices\n" ); out_unlock:mutex_unlock (&bus->sprom_mutex); out_kfree:
drivers/ssb/ssb_private.h +15 -4
@@ -9,16 +9,27 @@#define PFX "ssb: "#ifdef CONFIG_SSB_SILENT -# define ssb_printk(fmt, x...) do { /* nothing */ } while (0) +# define ssb_printk (fmt, ...) \ + do { if (0) printk(fmt, ##__VA_ARGS__); } while (0)#else -# define ssb_printk printk +# define ssb_printk (fmt, ...) \ + printk(fmt, ##__VA_ARGS__)#endif /* CONFIG_SSB_SILENT */ +#define ssb_emerg (fmt, ...) ssb_printk(KERN_EMERG PFX fmt, ##__VA_ARGS__) +#define ssb_err (fmt, ...) ssb_printk(KERN_ERR PFX fmt, ##__VA_ARGS__) +#define ssb_warn (fmt, ...) ssb_printk(KERN_WARNING PFX fmt, ##__VA_ARGS__) +#define ssb_notice (fmt, ...) ssb_printk(KERN_NOTICE PFX fmt, ##__VA_ARGS__) +#define ssb_info (fmt, ...) ssb_printk(KERN_INFO PFX fmt, ##__VA_ARGS__) +#define ssb_cont (fmt, ...) ssb_printk(KERN_CONT fmt, ##__VA_ARGS__) +/* dprintk: Debugging printk; vanishes for non-debug compilation */ #ifdef CONFIG_SSB_DEBUG -# define ssb_dprintk(fmt, x...) ssb_printk(fmt , ##x) +# define ssb_dbg (fmt, ...) \ + ssb_printk(KERN_DEBUG PFX fmt, ##__VA_ARGS__)#else -# define ssb_dprintk(fmt, x...) do { /* nothing */ } while (0) +# define ssb_dbg (fmt, ...) \ + do { if (0) printk(KERN_DEBUG PFX fmt, ##__VA_ARGS__); } while (0)#endif #ifdef CONFIG_SSB_DEBUG
Signature · 1 line
1.8.1.2.459.gbcd45b4.dirty
Quoted 4 lines · Larry Finger
I like the looks of
sprom_get_mac()over that ugly *(((__be16 *)out->il0mac)
construct, but this patch breaks ssb.
The resulting MAC address is all ones.
[]
Quoted 9 lines
drivers/ssb/pci.c static void sprom_extract_r8(struct ssb_sprom *out, const u16 *in) · line 536
Quoted 9 lines
drivers/ssb/pci.c +1
-4@@ -539,10 +533,8 @@ static void sprom_extract_r8(struct ssb_sprom *out, const u16 *in) ARRAY_SIZE(out->core_pwr_info));/* extract the MAC address */ -for (i =0 ; i <3 ; i++) { - v = in[SPOFF (SSB_SPROM8_IL0MAC ) + i]; - *(((__be16 *)out->il0mac) + i) =cpu_to_be16 (v); - } +sprom_get_mac (out->il0mac, &in[SSB_SPROM8_IL0MAC ]);
Yup, I did a stupid.
This one should be:
sprom_get_mac(out->il0mac, &in[SPOFF(SSB_SPROM8_IL0MAC)]);