[PATCH 0/2] [SRU] [SAUCE] [B/master] arm64: snapdragon: wcn36xx MAC

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

[PATCH 0/2] [SRU] [SAUCE] [B/master] arm64: snapdragon: wcn36xx MAC

Paolo Pisati-5
BugLink: http://bugs.launchpad.net/bugs/1776491

Impact:

The wcn36xx driver in Xenial/linux-snapdragon had an ability to autogenerate its
MAC address upon boot, or read it from a file (/lib/firmware/wlan/macaddr0). The
linux-snapdragon kernel in Bionic doesn't have this feature.

While by itself not a bug (Xenial used a QCOM provided custom driver, while
Bionic uses the upstream wcn36xx driver), it can be easily work-arounded by
specifying the hw address in /etc/network/interfaces, or set using ifconfig on the
command line, but it turned out to be a real problem on ubuntu core:

1) upon boot, with no MAC address assigned, the wcn36xx assigns itself the
dummy address "00:00:00:00:00" and that prevents the network interface from
working at all, until a valid address is set

2) the ubuntu core installer doesn't have any knowledge about this behaviour,
it simply tries to bring up the interface and on failure, it marks it as
'not working'

On top of that, ubuntu core ships a small script in initramfs, that generates the
/lib/firmware/wlan/macaddr0 file starting from the android boot serial,
effectively generating a unique MAC address per board: clearly, without driver
support, this ubuntu core feature doesn't work.

Fix:

Import back the MAC generation mechanism from Xenial: the pseudo random
generation and the parsing of /lib/firmware/wlan/macaddr0 - see the attached patch.

How to test:

Unpon boot, if no /lib/firmware/wlan/macaddr0 is present, the kernel will print:

[ 10.612701] wcn36xx a204000.wcnss:smd-edge:wcnss:wifi: Direct firmware load for
wlan/macaddr0 failed with error -2
[ 10.612713] wcn36xx a204000.wcnss:smd-edge:wcnss:wifi: Failed (-2) to read
macaddressfile wlan/macaddr0, using a random address instead

ubuntu@dragon410c:~$ ifconfig wlan0
wlan0: flags=4098<BROADCAST,MULTICAST> mtu 1500
        ether 00:0a:f5:d5:54:d7 txqueuelen 1000 (Ethernet)
        RX packets 0 bytes 0 (0.0 B)
        RX errors 0 dropped 0 overruns 0 frame 0
        TX packets 0 bytes 0 (0.0 B)
        TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0

else, if /lib/firmware/wlan/macaddr0 is present, its content will be used to
generate wlan0 MAC address:

ubuntu@dragon410c:~$ cat /lib/firmware/wlan/macaddr0
fe:1a:19:77:d9:88

ubuntu@dragon410c:~$ ifconfig wlan0
wlan0: flags=4098<BROADCAST,MULTICAST> mtu 1500
        ether fe:1a:19:77:d9:88 txqueuelen 1000 (Ethernet)
        RX packets 0 bytes 0 (0.0 B)
        RX errors 0 dropped 0 overruns 0 frame 0
        TX packets 0 bytes 0 (0.0 B)
        TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0

Regression potential:

Low - the patch is small and the code is wrapped in a Kconfig option
(WCN36XX_SNAPDRAGON_HACKS) that only affects the linux-snapdragon flavour,
leaving the generic kernel untouched.

Paolo Pisati (2):
  SAUCE: wcn36xx: read MAC from file or randomly generate one
  UBUNTU: [Config] arm64: snapdragon: WCN36XX_SNAPDRAGON_HACKS=y

 .../config/amd64/config.common.amd64          |  1 +
 .../config/arm64/config.flavour.generic       |  1 +
 .../config/arm64/config.flavour.snapdragon    |  1 +
 .../config/armhf/config.common.armhf          |  1 +
 debian.master/config/i386/config.common.i386  |  1 +
 .../config/ppc64el/config.common.ppc64el      |  1 +
 drivers/net/wireless/ath/wcn36xx/Kconfig      |  9 +++++
 drivers/net/wireless/ath/wcn36xx/main.c       | 38 ++++++++++++++++++-
 8 files changed, 52 insertions(+), 1 deletion(-)

--
2.17.1


--
kernel-team mailing list
[hidden email]
https://lists.ubuntu.com/mailman/listinfo/kernel-team
Reply | Threaded
Open this post in threaded view
|

[PATCH 1/2] SAUCE: wcn36xx: read MAC from file or randomly generate one

Paolo Pisati-5
BugLink: http://bugs.launchpad.net/bugs/1776491

Signed-off-by: Paolo Pisati <[hidden email]>
---
 drivers/net/wireless/ath/wcn36xx/Kconfig |  9 ++++++
 drivers/net/wireless/ath/wcn36xx/main.c  | 38 +++++++++++++++++++++++-
 2 files changed, 46 insertions(+), 1 deletion(-)

diff --git a/drivers/net/wireless/ath/wcn36xx/Kconfig b/drivers/net/wireless/ath/wcn36xx/Kconfig
index 20bf967a70b9..44d34a80fad4 100644
--- a/drivers/net/wireless/ath/wcn36xx/Kconfig
+++ b/drivers/net/wireless/ath/wcn36xx/Kconfig
@@ -16,3 +16,12 @@ config WCN36XX_DEBUGFS
   Enabled debugfs support
 
   If unsure, say Y to make it easier to debug problems.
+
+config WCN36XX_SNAPDRAGON_HACKS
+ bool "Dragonboard 410c WCN36XX MAC address generation hacks"
+ default n
+ depends on WCN36XX
+ ---help---
+  Upon probe, WCN36XX will try to read its MAC address from
+  a file located at /lib/firmware/wlan/macaddr0. If the file
+  is not present, it will randomly generate a new MAC address.
diff --git a/drivers/net/wireless/ath/wcn36xx/main.c b/drivers/net/wireless/ath/wcn36xx/main.c
index fcc98d4f9f9e..ed0b9736f9ae 100644
--- a/drivers/net/wireless/ath/wcn36xx/main.c
+++ b/drivers/net/wireless/ath/wcn36xx/main.c
@@ -1265,6 +1265,14 @@ static int wcn36xx_probe(struct platform_device *pdev)
  void *wcnss;
  int ret;
  const u8 *addr;
+#ifdef CONFIG_WCN36XX_SNAPDRAGON_HACKS
+ int status;
+ const struct firmware *addr_file = NULL;
+ u8 tmp[18], _addr[ETH_ALEN];
+ static const u8 qcom_oui[3] = {0x00, 0x0A, 0xF5};
+ static const char *files = {"wlan/macaddr0"};
+#endif
+
 
  wcn36xx_dbg(WCN36XX_DBG_MAC, "platform probe\n");
 
@@ -1298,7 +1306,35 @@ static int wcn36xx_probe(struct platform_device *pdev)
  wcn36xx_err("invalid local-mac-address\n");
  ret = -EINVAL;
  goto out_wq;
- } else if (addr) {
+ }
+#ifdef CONFIG_WCN36XX_SNAPDRAGON_HACKS
+ else if (addr == NULL) {
+ addr = _addr;
+ status = request_firmware(&addr_file, files, &pdev->dev);
+
+ if (status < 0) {
+ /* Assign a random mac with Qualcomm oui */
+ dev_err(&pdev->dev, "Failed (%d) to read macaddress"
+ "file %s, using a random address instead", status, files);
+ memcpy(addr, qcom_oui, 3);
+ get_random_bytes(addr + 3, 3);
+ } else {
+ memset(tmp, 0, sizeof(tmp));
+ memcpy(tmp, addr_file->data, sizeof(tmp) - 1);
+ sscanf(tmp, "%hhx:%hhx:%hhx:%hhx:%hhx:%hhx",
+ &addr[0],
+ &addr[1],
+ &addr[2],
+ &addr[3],
+ &addr[4],
+ &addr[5]);
+
+ release_firmware(addr_file);
+ }
+ }
+#endif
+
+ if (addr) {
  wcn36xx_info("mac address: %pM\n", addr);
  SET_IEEE80211_PERM_ADDR(wcn->hw, addr);
  }
--
2.17.1


--
kernel-team mailing list
[hidden email]
https://lists.ubuntu.com/mailman/listinfo/kernel-team
Reply | Threaded
Open this post in threaded view
|

[PATCH 2/2] UBUNTU: [Config] arm64: snapdragon: WCN36XX_SNAPDRAGON_HACKS=y

Paolo Pisati-5
In reply to this post by Paolo Pisati-5
BugLink: http://bugs.launchpad.net/bugs/1776491

Signed-off-by: Paolo Pisati <[hidden email]>
---
 debian.master/config/amd64/config.common.amd64       | 1 +
 debian.master/config/arm64/config.flavour.generic    | 1 +
 debian.master/config/arm64/config.flavour.snapdragon | 1 +
 debian.master/config/armhf/config.common.armhf       | 1 +
 debian.master/config/i386/config.common.i386         | 1 +
 debian.master/config/ppc64el/config.common.ppc64el   | 1 +
 6 files changed, 6 insertions(+)

diff --git a/debian.master/config/amd64/config.common.amd64 b/debian.master/config/amd64/config.common.amd64
index 74bdfcef30cc..c38099732a9d 100644
--- a/debian.master/config/amd64/config.common.amd64
+++ b/debian.master/config/amd64/config.common.amd64
@@ -524,6 +524,7 @@ CONFIG_VMXNET3=m
 CONFIG_VXFS_FS=m
 CONFIG_W1=m
 CONFIG_WAN=y
+# CONFIG_WCN36XX_SNAPDRAGON_HACKS is not set
 CONFIG_WDTPCI=m
 CONFIG_WIMAX=m
 CONFIG_X25=m
diff --git a/debian.master/config/arm64/config.flavour.generic b/debian.master/config/arm64/config.flavour.generic
index d57a37e00066..b22966aac36b 100644
--- a/debian.master/config/arm64/config.flavour.generic
+++ b/debian.master/config/arm64/config.flavour.generic
@@ -68,3 +68,4 @@ CONFIG_SPI_QUP=m
 CONFIG_SPMI=m
 CONFIG_SPMI_MSM_PMIC_ARB=m
 CONFIG_USB_ULPI_BUS=m
+# CONFIG_WCN36XX_SNAPDRAGON_HACKS is not set
diff --git a/debian.master/config/arm64/config.flavour.snapdragon b/debian.master/config/arm64/config.flavour.snapdragon
index cef01ad27861..28179ca69d94 100644
--- a/debian.master/config/arm64/config.flavour.snapdragon
+++ b/debian.master/config/arm64/config.flavour.snapdragon
@@ -68,3 +68,4 @@ CONFIG_SPI_QUP=y
 CONFIG_SPMI=y
 CONFIG_SPMI_MSM_PMIC_ARB=y
 CONFIG_USB_ULPI_BUS=y
+CONFIG_WCN36XX_SNAPDRAGON_HACKS=y
diff --git a/debian.master/config/armhf/config.common.armhf b/debian.master/config/armhf/config.common.armhf
index 6ae8ae5bf84d..b7530fab51c9 100644
--- a/debian.master/config/armhf/config.common.armhf
+++ b/debian.master/config/armhf/config.common.armhf
@@ -547,6 +547,7 @@ CONFIG_VMXNET3=m
 CONFIG_VXFS_FS=m
 CONFIG_W1=m
 CONFIG_WAN=y
+# CONFIG_WCN36XX_SNAPDRAGON_HACKS is not set
 CONFIG_WDTPCI=m
 CONFIG_WIMAX=m
 CONFIG_X25=m
diff --git a/debian.master/config/i386/config.common.i386 b/debian.master/config/i386/config.common.i386
index 3d4f6adf0b33..85d45bd791f8 100644
--- a/debian.master/config/i386/config.common.i386
+++ b/debian.master/config/i386/config.common.i386
@@ -516,6 +516,7 @@ CONFIG_VMXNET3=m
 CONFIG_VXFS_FS=m
 CONFIG_W1=m
 CONFIG_WAN=y
+# CONFIG_WCN36XX_SNAPDRAGON_HACKS is not set
 CONFIG_WDTPCI=m
 CONFIG_WIMAX=m
 CONFIG_X25=m
diff --git a/debian.master/config/ppc64el/config.common.ppc64el b/debian.master/config/ppc64el/config.common.ppc64el
index 02bb780f57a8..4719378b2630 100644
--- a/debian.master/config/ppc64el/config.common.ppc64el
+++ b/debian.master/config/ppc64el/config.common.ppc64el
@@ -521,6 +521,7 @@ CONFIG_VME_BUS=y
 CONFIG_VXFS_FS=m
 CONFIG_W1=m
 CONFIG_WAN=y
+# CONFIG_WCN36XX_SNAPDRAGON_HACKS is not set
 CONFIG_WDTPCI=m
 CONFIG_WIMAX=m
 CONFIG_X25=m
--
2.17.1


--
kernel-team mailing list
[hidden email]
https://lists.ubuntu.com/mailman/listinfo/kernel-team
Reply | Threaded
Open this post in threaded view
|

Re: [PATCH 1/2] SAUCE: wcn36xx: read MAC from file or randomly generate one

Stefan Bader-2
In reply to this post by Paolo Pisati-5
On 12.06.2018 16:28, Paolo Pisati wrote:

Subject should, iirc be "UBUNTU: SAUCE: ...". Also, please add more of the
description of the change into the commit message. Its a pain to always have to
follow some link or read code to know what a commit does and why. Does not have
to be the long story but a bit more than nothing would help.
The config change, ok, there is probably not much more to say about that one
beyond the one line.

> BugLink: http://bugs.launchpad.net/bugs/1776491
>
> Signed-off-by: Paolo Pisati <[hidden email]>
> ---
>  drivers/net/wireless/ath/wcn36xx/Kconfig |  9 ++++++
>  drivers/net/wireless/ath/wcn36xx/main.c  | 38 +++++++++++++++++++++++-
>  2 files changed, 46 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/net/wireless/ath/wcn36xx/Kconfig b/drivers/net/wireless/ath/wcn36xx/Kconfig
> index 20bf967a70b9..44d34a80fad4 100644
> --- a/drivers/net/wireless/ath/wcn36xx/Kconfig
> +++ b/drivers/net/wireless/ath/wcn36xx/Kconfig
> @@ -16,3 +16,12 @@ config WCN36XX_DEBUGFS
>    Enabled debugfs support
>  
>    If unsure, say Y to make it easier to debug problems.
> +
> +config WCN36XX_SNAPDRAGON_HACKS
> + bool "Dragonboard 410c WCN36XX MAC address generation hacks"
> + default n
> + depends on WCN36XX
> + ---help---
> +  Upon probe, WCN36XX will try to read its MAC address from
> +  a file located at /lib/firmware/wlan/macaddr0. If the file
> +  is not present, it will randomly generate a new MAC address.
> diff --git a/drivers/net/wireless/ath/wcn36xx/main.c b/drivers/net/wireless/ath/wcn36xx/main.c
> index fcc98d4f9f9e..ed0b9736f9ae 100644
> --- a/drivers/net/wireless/ath/wcn36xx/main.c
> +++ b/drivers/net/wireless/ath/wcn36xx/main.c
> @@ -1265,6 +1265,14 @@ static int wcn36xx_probe(struct platform_device *pdev)
>   void *wcnss;
>   int ret;
>   const u8 *addr;
> +#ifdef CONFIG_WCN36XX_SNAPDRAGON_HACKS
> + int status;
> + const struct firmware *addr_file = NULL;
> + u8 tmp[18], _addr[ETH_ALEN];
> + static const u8 qcom_oui[3] = {0x00, 0x0A, 0xF5};
> + static const char *files = {"wlan/macaddr0"};
> +#endif
> +
>  
>   wcn36xx_dbg(WCN36XX_DBG_MAC, "platform probe\n");
>  
> @@ -1298,7 +1306,35 @@ static int wcn36xx_probe(struct platform_device *pdev)
>   wcn36xx_err("invalid local-mac-address\n");
>   ret = -EINVAL;
>   goto out_wq;
> - } else if (addr) {
> + }
> +#ifdef CONFIG_WCN36XX_SNAPDRAGON_HACKS
> + else if (addr == NULL) {
> + addr = _addr;
> + status = request_firmware(&addr_file, files, &pdev->dev);
> +
> + if (status < 0) {
> + /* Assign a random mac with Qualcomm oui */
> + dev_err(&pdev->dev, "Failed (%d) to read macaddress"
> + "file %s, using a random address instead", status, files);
> + memcpy(addr, qcom_oui, 3);
> + get_random_bytes(addr + 3, 3);
> + } else {
> + memset(tmp, 0, sizeof(tmp));
> + memcpy(tmp, addr_file->data, sizeof(tmp) - 1);
> + sscanf(tmp, "%hhx:%hhx:%hhx:%hhx:%hhx:%hhx",
> + &addr[0],
> + &addr[1],
> + &addr[2],
> + &addr[3],
> + &addr[4],
> + &addr[5]);
> +
> + release_firmware(addr_file);
> + }
> + }
> +#endif
> +
> + if (addr) {
>   wcn36xx_info("mac address: %pM\n", addr);
>   SET_IEEE80211_PERM_ADDR(wcn->hw, addr);
>   }
>


--
kernel-team mailing list
[hidden email]
https://lists.ubuntu.com/mailman/listinfo/kernel-team

signature.asc (836 bytes) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: [PATCH 1/2] SAUCE: wcn36xx: read MAC from file or randomly generate one

Paolo Pisati-5
Ok, i'm sending a V2.

On Wed, Jun 13, 2018 at 4:48 PM, Stefan Bader
<[hidden email]> wrote:
> On 12.06.2018 16:28, Paolo Pisati wrote:
>
> Subject should, iirc be "UBUNTU: SAUCE: ...". Also, please add more of the
> description of the change into the commit message. Its a pain to always have to
> follow some link or read code to know what a commit does and why. Does not have
> to be the long story but a bit more than nothing would help.
> The config change, ok, there is probably not much more to say about that one
> beyond the one line.

--
bye,
p.

--
kernel-team mailing list
[hidden email]
https://lists.ubuntu.com/mailman/listinfo/kernel-team