linux-wireless.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v2] iwlwifi: pnvm: implement reading PNVM from UEFI
@ 2021-02-10 23:50 Luca Coelho
  2021-02-10 23:58 ` Luca Coelho
  2021-02-11 16:21 ` Kalle Valo
  0 siblings, 2 replies; 4+ messages in thread
From: Luca Coelho @ 2021-02-10 23:50 UTC (permalink / raw)
  To: kvalo; +Cc: linux-wireless

From: Luca Coelho <luciano.coelho@intel.com>

We now support fetching the PNVM data from a UEFI variable.  Add the
code to read this variable first and use it.  If it's not available,
we fall back to reading the data from the filesystem, as before.

Signed-off-by: Luca Coelho <luciano.coelho@intel.com>
---
 drivers/net/wireless/intel/iwlwifi/fw/pnvm.c | 91 +++++++++++++++++++-
 1 file changed, 90 insertions(+), 1 deletion(-)

diff --git a/drivers/net/wireless/intel/iwlwifi/fw/pnvm.c b/drivers/net/wireless/intel/iwlwifi/fw/pnvm.c
index d515af8c1686..2cd07d2690e0 100644
--- a/drivers/net/wireless/intel/iwlwifi/fw/pnvm.c
+++ b/drivers/net/wireless/intel/iwlwifi/fw/pnvm.c
@@ -10,6 +10,7 @@
 #include "fw/api/commands.h"
 #include "fw/api/nvm-reg.h"
 #include "fw/api/alive.h"
+#include <linux/efi.h>
 
 struct iwl_pnvm_section {
 	__le32 offset;
@@ -219,6 +220,88 @@ static int iwl_pnvm_parse(struct iwl_trans *trans, const u8 *data,
 	return -ENOENT;
 }
 
+/*
+ * This is known to be broken on v4.19 and to work on v5.4.  Until we
+ * figure out why this is the case and how to make it work, simply
+ * disable the feature in old kernels.
+ */
+#if defined(CONFIG_EFI)
+
+#define IWL_EFI_VAR_GUID EFI_GUID(0x92daaf2f, 0xc02b, 0x455b,	\
+				  0xb2, 0xec, 0xf5, 0xa3,	\
+				  0x59, 0x4f, 0x4a, 0xea)
+
+#define IWL_UEFI_OEM_PNVM_NAME	L"UefiCnvWlanOemSignedPnvm"
+
+#define IWL_HARDCODED_PNVM_SIZE 4096
+
+struct pnvm_sku_package {
+	u8 rev;
+	u8 reserved1[3];
+	u32 total_size;
+	u8 n_skus;
+	u8 reserved2[11];
+	u8 data[];
+};
+
+static int iwl_pnvm_get_from_efi(struct iwl_trans *trans,
+				 u8 **data, size_t *len)
+{
+	struct efivar_entry *pnvm_efivar;
+	struct pnvm_sku_package *package;
+	unsigned long package_size;
+	int err;
+
+	pnvm_efivar = kzalloc(sizeof(*pnvm_efivar), GFP_KERNEL);
+	if (!pnvm_efivar)
+		return -ENOMEM;
+
+	memcpy(&pnvm_efivar->var.VariableName, IWL_UEFI_OEM_PNVM_NAME,
+	       sizeof(IWL_UEFI_OEM_PNVM_NAME));
+	pnvm_efivar->var.VendorGuid = IWL_EFI_VAR_GUID;
+
+	/*
+	 * TODO: we hardcode a maximum length here, because reading
+	 * from the UEFI is not working.  To implement this properly,
+	 * we have to call efivar_entry_size().
+	 */
+	package_size = IWL_HARDCODED_PNVM_SIZE;
+
+	package = kmalloc(package_size, GFP_KERNEL);
+	if (!package) {
+		err = -ENOMEM;
+		goto out;
+	}
+
+	err = efivar_entry_get(pnvm_efivar, NULL, &package_size, package);
+	if (err) {
+		IWL_DEBUG_FW(trans,
+			     "PNVM UEFI variable not found %d (len %zd)\n",
+			     err, package_size);
+		goto out;
+	}
+
+	IWL_DEBUG_FW(trans, "Read PNVM fro UEFI with size %zd\n", package_size);
+
+	*data = kmemdup(package->data, *len, GFP_KERNEL);
+	if (!*data)
+		err = -ENOMEM;
+	*len = package_size - sizeof(*package);
+
+out:
+	kfree(package);
+	kfree(pnvm_efivar);
+
+	return err;
+}
+#else /* CONFIG_EFI */
+static inline int iwl_pnvm_get_from_efi(struct iwl_trans *trans,
+					u8 **data, size_t *len)
+{
+	return -EOPNOTSUPP;
+}
+#endif /* CONFIG_EFI */
+
 static int iwl_pnvm_get_from_fs(struct iwl_trans *trans, u8 **data, size_t *len)
 {
 	const struct firmware *pnvm;
@@ -277,7 +360,12 @@ int iwl_pnvm_load(struct iwl_trans *trans,
 		goto skip_parse;
 	}
 
-	/* Try to load the PNVM from the filesystem */
+	/* First attempt to get the PNVM from BIOS */
+	ret = iwl_pnvm_get_from_efi(trans, &data, &len);
+	if (!ret)
+		goto parse;
+
+	/* If it's not available, try from the filesystem */
 	ret = iwl_pnvm_get_from_fs(trans, &data, &len);
 	if (ret) {
 		/*
@@ -290,6 +378,7 @@ int iwl_pnvm_load(struct iwl_trans *trans,
 		goto skip_parse;
 	}
 
+parse:
 	iwl_pnvm_parse(trans, data, len);
 
 	kfree(data);
-- 
2.30.0


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH v2] iwlwifi: pnvm: implement reading PNVM from UEFI
  2021-02-10 23:50 [PATCH v2] iwlwifi: pnvm: implement reading PNVM from UEFI Luca Coelho
@ 2021-02-10 23:58 ` Luca Coelho
  2021-02-11 16:21 ` Kalle Valo
  1 sibling, 0 replies; 4+ messages in thread
From: Luca Coelho @ 2021-02-10 23:58 UTC (permalink / raw)
  To: Luca Coelho; +Cc: kvalo, linux-wireless

Luca Coelho <luca@coelho.fi> wrote:

> From: Luca Coelho <luciano.coelho@intel.com>
> 
> We now support fetching the PNVM data from a UEFI variable.  Add the
> code to read this variable first and use it.  If it's not available,
> we fall back to reading the data from the filesystem, as before.
> 
> Signed-off-by: Luca Coelho <luciano.coelho@intel.com>

Patch applied to iwlwifi-next.git, thanks.

a1a6a4cf49ec iwlwifi: pnvm: implement reading PNVM from UEFI


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH v2] iwlwifi: pnvm: implement reading PNVM from UEFI
  2021-02-10 23:50 [PATCH v2] iwlwifi: pnvm: implement reading PNVM from UEFI Luca Coelho
  2021-02-10 23:58 ` Luca Coelho
@ 2021-02-11 16:21 ` Kalle Valo
  2021-02-11 20:25   ` Luca Coelho
  1 sibling, 1 reply; 4+ messages in thread
From: Kalle Valo @ 2021-02-11 16:21 UTC (permalink / raw)
  To: Luca Coelho; +Cc: linux-wireless

Luca Coelho <luca@coelho.fi> writes:

> From: Luca Coelho <luciano.coelho@intel.com>
>
> We now support fetching the PNVM data from a UEFI variable.  Add the
> code to read this variable first and use it.  If it's not available,
> we fall back to reading the data from the filesystem, as before.
>
> Signed-off-by: Luca Coelho <luciano.coelho@intel.com>

[...]

> --- a/drivers/net/wireless/intel/iwlwifi/fw/pnvm.c
> +++ b/drivers/net/wireless/intel/iwlwifi/fw/pnvm.c
> @@ -10,6 +10,7 @@
>  #include "fw/api/commands.h"
>  #include "fw/api/nvm-reg.h"
>  #include "fw/api/alive.h"
> +#include <linux/efi.h>
>  
>  struct iwl_pnvm_section {
>  	__le32 offset;
> @@ -219,6 +220,88 @@ static int iwl_pnvm_parse(struct iwl_trans *trans, const u8 *data,
>  	return -ENOENT;
>  }
>  
> +/*
> + * This is known to be broken on v4.19 and to work on v5.4.  Until we
> + * figure out why this is the case and how to make it work, simply
> + * disable the feature in old kernels.
> + */
> +#if defined(CONFIG_EFI)

The comment doesn't really make sense anymore, can you send a followupb
patch to remove it? No need to change the tag because of this.

-- 
https://patchwork.kernel.org/project/linux-wireless/list/

https://wireless.wiki.kernel.org/en/developers/documentation/submittingpatches

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH v2] iwlwifi: pnvm: implement reading PNVM from UEFI
  2021-02-11 16:21 ` Kalle Valo
@ 2021-02-11 20:25   ` Luca Coelho
  0 siblings, 0 replies; 4+ messages in thread
From: Luca Coelho @ 2021-02-11 20:25 UTC (permalink / raw)
  To: Kalle Valo; +Cc: linux-wireless

On Thu, 2021-02-11 at 18:21 +0200, Kalle Valo wrote:
> Luca Coelho <luca@coelho.fi> writes:
> 
> > From: Luca Coelho <luciano.coelho@intel.com>
> > 
> > We now support fetching the PNVM data from a UEFI variable.  Add the
> > code to read this variable first and use it.  If it's not available,
> > we fall back to reading the data from the filesystem, as before.
> > 
> > Signed-off-by: Luca Coelho <luciano.coelho@intel.com>
> 
> [...]
> 
> > --- a/drivers/net/wireless/intel/iwlwifi/fw/pnvm.c
> > +++ b/drivers/net/wireless/intel/iwlwifi/fw/pnvm.c
> > @@ -10,6 +10,7 @@
> >  #include "fw/api/commands.h"
> >  #include "fw/api/nvm-reg.h"
> >  #include "fw/api/alive.h"
> > +#include <linux/efi.h>
> >  
> > 
> > 
> > 
> >  struct iwl_pnvm_section {
> >  	__le32 offset;
> > @@ -219,6 +220,88 @@ static int iwl_pnvm_parse(struct iwl_trans *trans, const u8 *data,
> >  	return -ENOENT;
> >  }
> >  
> > 
> > 
> > 
> > +/*
> > + * This is known to be broken on v4.19 and to work on v5.4.  Until we
> > + * figure out why this is the case and how to make it work, simply
> > + * disable the feature in old kernels.
> > + */
> > +#if defined(CONFIG_EFI)
> 
> The comment doesn't really make sense anymore, can you send a followupb
> patch to remove it? No need to change the tag because of this.

Ugh, sorry about that.  I just saw that the version check had slipped
in and fixed it quickly at 2am, so I could still send you the pull-req
before going to sleep...

I'll send a patch removing this now.

--
Cheers,
Luca.


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2021-02-11 20:26 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-02-10 23:50 [PATCH v2] iwlwifi: pnvm: implement reading PNVM from UEFI Luca Coelho
2021-02-10 23:58 ` Luca Coelho
2021-02-11 16:21 ` Kalle Valo
2021-02-11 20:25   ` Luca Coelho

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).