2023-10-15 14:07:22 +00:00
|
|
|
From 1046fc9e98936991aeb0b0656c84833d96a63c0f Mon Sep 17 00:00:00 2001
|
|
|
|
From: Christian Marangi <ansuelsmth@gmail.com>
|
|
|
|
Date: Sun, 15 Oct 2023 14:22:49 +0200
|
|
|
|
Subject: [PATCH 1/5] wifi: rt2x00: Add support for loading EEPROM from
|
|
|
|
userspace
|
|
|
|
|
|
|
|
Add support for loading EEPROM from userspace.
|
|
|
|
|
|
|
|
Signed-off-by: Christian Marangi <ansuelsmth@gmail.com>
|
|
|
|
---
|
|
|
|
drivers/net/wireless/ralink/rt2x00/Kconfig | 5 ++
|
|
|
|
drivers/net/wireless/ralink/rt2x00/Makefile | 1 +
|
|
|
|
.../net/wireless/ralink/rt2x00/rt2800soc.c | 15 +---
|
|
|
|
drivers/net/wireless/ralink/rt2x00/rt2x00.h | 1 +
|
|
|
|
.../net/wireless/ralink/rt2x00/rt2x00dev.c | 9 +++
|
|
|
|
.../net/wireless/ralink/rt2x00/rt2x00eeprom.c | 75 +++++++++++++++++++
|
|
|
|
.../net/wireless/ralink/rt2x00/rt2x00soc.c | 1 +
|
|
|
|
.../net/wireless/ralink/rt2x00/rt2x00soc.h | 9 +++
|
|
|
|
8 files changed, 102 insertions(+), 14 deletions(-)
|
|
|
|
create mode 100644 drivers/net/wireless/ralink/rt2x00/rt2x00eeprom.c
|
|
|
|
|
2017-08-22 21:59:48 +00:00
|
|
|
--- a/local-symbols
|
|
|
|
+++ b/local-symbols
|
2024-09-24 13:06:20 +00:00
|
|
|
@@ -339,6 +339,7 @@ RT2X00_LIB_FIRMWARE=
|
2013-11-12 22:11:33 +00:00
|
|
|
RT2X00_LIB_CRYPTO=
|
|
|
|
RT2X00_LIB_LEDS=
|
|
|
|
RT2X00_LIB_DEBUGFS=
|
|
|
|
+RT2X00_LIB_EEPROM=
|
|
|
|
RT2X00_DEBUG=
|
2015-12-04 22:39:37 +00:00
|
|
|
WLAN_VENDOR_REALTEK=
|
|
|
|
RTL8180=
|
|
|
|
--- a/drivers/net/wireless/ralink/rt2x00/Kconfig
|
|
|
|
+++ b/drivers/net/wireless/ralink/rt2x00/Kconfig
|
2019-07-06 22:08:20 +00:00
|
|
|
@@ -70,6 +70,7 @@ config RT2800PCI
|
2013-11-12 22:11:33 +00:00
|
|
|
select RT2X00_LIB_MMIO
|
|
|
|
select RT2X00_LIB_PCI
|
|
|
|
select RT2X00_LIB_FIRMWARE
|
|
|
|
+ select RT2X00_LIB_EEPROM
|
|
|
|
select RT2X00_LIB_CRYPTO
|
|
|
|
depends on CRC_CCITT
|
|
|
|
depends on EEPROM_93CX6
|
2019-07-06 22:08:20 +00:00
|
|
|
@@ -216,6 +217,7 @@ config RT2800SOC
|
2013-11-12 22:11:33 +00:00
|
|
|
select RT2X00_LIB_MMIO
|
|
|
|
select RT2X00_LIB_CRYPTO
|
|
|
|
select RT2X00_LIB_FIRMWARE
|
|
|
|
+ select RT2X00_LIB_EEPROM
|
|
|
|
select RT2800_LIB
|
|
|
|
select RT2800_LIB_MMIO
|
2020-06-20 21:11:17 +00:00
|
|
|
help
|
2019-07-06 22:08:20 +00:00
|
|
|
@@ -266,6 +268,9 @@ config RT2X00_LIB_FIRMWARE
|
2013-11-12 22:11:33 +00:00
|
|
|
config RT2X00_LIB_CRYPTO
|
2015-03-11 15:02:47 +00:00
|
|
|
bool
|
2013-11-12 22:11:33 +00:00
|
|
|
|
|
|
|
+config RT2X00_LIB_EEPROM
|
2019-08-03 10:30:38 +00:00
|
|
|
+ bool
|
2013-11-12 22:11:33 +00:00
|
|
|
+
|
|
|
|
config RT2X00_LIB_LEDS
|
2015-03-11 15:02:47 +00:00
|
|
|
bool
|
2013-11-12 22:11:33 +00:00
|
|
|
default y if (RT2X00_LIB=y && LEDS_CLASS=y) || (RT2X00_LIB=m && LEDS_CLASS!=n)
|
2015-12-04 22:39:37 +00:00
|
|
|
--- a/drivers/net/wireless/ralink/rt2x00/Makefile
|
|
|
|
+++ b/drivers/net/wireless/ralink/rt2x00/Makefile
|
2018-09-23 16:02:35 +00:00
|
|
|
@@ -8,6 +8,7 @@ rt2x00lib-$(CPTCFG_RT2X00_LIB_DEBUGFS) +
|
2013-11-12 22:11:33 +00:00
|
|
|
rt2x00lib-$(CPTCFG_RT2X00_LIB_CRYPTO) += rt2x00crypto.o
|
|
|
|
rt2x00lib-$(CPTCFG_RT2X00_LIB_FIRMWARE) += rt2x00firmware.o
|
|
|
|
rt2x00lib-$(CPTCFG_RT2X00_LIB_LEDS) += rt2x00leds.o
|
|
|
|
+rt2x00lib-$(CPTCFG_RT2X00_LIB_EEPROM) += rt2x00eeprom.o
|
|
|
|
|
|
|
|
obj-$(CPTCFG_RT2X00_LIB) += rt2x00lib.o
|
|
|
|
obj-$(CPTCFG_RT2X00_LIB_MMIO) += rt2x00mmio.o
|
2015-12-04 22:39:37 +00:00
|
|
|
--- a/drivers/net/wireless/ralink/rt2x00/rt2800soc.c
|
|
|
|
+++ b/drivers/net/wireless/ralink/rt2x00/rt2800soc.c
|
2019-07-06 22:08:20 +00:00
|
|
|
@@ -90,19 +90,6 @@ static int rt2800soc_set_device_state(st
|
2013-11-12 22:11:33 +00:00
|
|
|
return retval;
|
|
|
|
}
|
|
|
|
|
|
|
|
-static int rt2800soc_read_eeprom(struct rt2x00_dev *rt2x00dev)
|
|
|
|
-{
|
|
|
|
- void __iomem *base_addr = ioremap(0x1F040000, EEPROM_SIZE);
|
|
|
|
-
|
|
|
|
- if (!base_addr)
|
|
|
|
- return -ENOMEM;
|
|
|
|
-
|
|
|
|
- memcpy_fromio(rt2x00dev->eeprom, base_addr, EEPROM_SIZE);
|
|
|
|
-
|
|
|
|
- iounmap(base_addr);
|
|
|
|
- return 0;
|
|
|
|
-}
|
|
|
|
-
|
|
|
|
/* Firmware functions */
|
|
|
|
static char *rt2800soc_get_firmware_name(struct rt2x00_dev *rt2x00dev)
|
|
|
|
{
|
2024-06-19 11:51:47 +00:00
|
|
|
@@ -172,7 +159,7 @@ static const struct rt2800_ops rt2800soc
|
2013-11-12 22:11:33 +00:00
|
|
|
.register_multiread = rt2x00mmio_register_multiread,
|
|
|
|
.register_multiwrite = rt2x00mmio_register_multiwrite,
|
|
|
|
.regbusy_read = rt2x00mmio_regbusy_read,
|
|
|
|
- .read_eeprom = rt2800soc_read_eeprom,
|
2023-10-15 14:07:22 +00:00
|
|
|
+ .read_eeprom = rt2x00lib_read_eeprom,
|
2013-11-12 22:11:33 +00:00
|
|
|
.hwcrypt_disabled = rt2800soc_hwcrypt_disabled,
|
|
|
|
.drv_write_firmware = rt2800soc_write_firmware,
|
|
|
|
.drv_init_registers = rt2800mmio_init_registers,
|
2015-12-04 22:39:37 +00:00
|
|
|
--- a/drivers/net/wireless/ralink/rt2x00/rt2x00.h
|
|
|
|
+++ b/drivers/net/wireless/ralink/rt2x00/rt2x00.h
|
2024-09-24 13:06:20 +00:00
|
|
|
@@ -693,6 +693,7 @@ enum rt2x00_capability_flags {
|
2013-11-12 22:11:33 +00:00
|
|
|
REQUIRE_HT_TX_DESC,
|
|
|
|
REQUIRE_PS_AUTOWAKE,
|
2014-09-27 20:51:43 +00:00
|
|
|
REQUIRE_DELAYED_RFKILL,
|
2013-11-12 22:11:33 +00:00
|
|
|
+ REQUIRE_EEPROM_FILE,
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Capabilities
|
2011-07-03 15:02:04 +00:00
|
|
|
--- /dev/null
|
2015-12-04 22:39:37 +00:00
|
|
|
+++ b/drivers/net/wireless/ralink/rt2x00/rt2x00eeprom.c
|
2023-10-15 14:07:22 +00:00
|
|
|
@@ -0,0 +1,77 @@
|
|
|
|
+// SPDX-License-Identifier: GPL-2.0-or-later
|
|
|
|
+/* Copyright (C) 2004 - 2009 Ivo van Doorn <IvDoorn@gmail.com>
|
|
|
|
+ * Copyright (C) 2004 - 2009 Gertjan van Wingerde <gwingerde@gmail.com>
|
|
|
|
+ * <http://rt2x00.serialmonkey.com>
|
2011-07-03 15:02:04 +00:00
|
|
|
+ */
|
|
|
|
+
|
2023-10-15 14:07:22 +00:00
|
|
|
+/* Module: rt2x00lib
|
|
|
|
+ * Abstract: rt2x00 eeprom file loading routines.
|
2011-07-03 15:02:04 +00:00
|
|
|
+ */
|
|
|
|
+
|
|
|
|
+#include <linux/kernel.h>
|
|
|
|
+#include <linux/module.h>
|
|
|
|
+
|
|
|
|
+#include "rt2x00.h"
|
2023-10-15 14:07:22 +00:00
|
|
|
+#include "rt2x00soc.h"
|
2011-07-03 15:02:04 +00:00
|
|
|
+
|
2013-11-12 22:11:33 +00:00
|
|
|
+static const char *
|
|
|
|
+rt2x00lib_get_eeprom_file_name(struct rt2x00_dev *rt2x00dev)
|
|
|
|
+{
|
|
|
|
+ struct rt2x00_platform_data *pdata = rt2x00dev->dev->platform_data;
|
|
|
|
+
|
|
|
|
+ if (pdata && pdata->eeprom_file_name)
|
|
|
|
+ return pdata->eeprom_file_name;
|
|
|
|
+
|
2022-01-31 17:53:59 +00:00
|
|
|
+ return NULL;
|
2013-11-12 22:11:33 +00:00
|
|
|
+}
|
|
|
|
+
|
2023-10-15 14:07:22 +00:00
|
|
|
+static int rt2x00lib_read_eeprom_file(struct rt2x00_dev *rt2x00dev)
|
2011-07-03 15:02:04 +00:00
|
|
|
+{
|
|
|
|
+ const struct firmware *ee;
|
2014-01-30 13:21:36 +00:00
|
|
|
+ const char *ee_name;
|
2011-07-03 15:02:04 +00:00
|
|
|
+ int retval;
|
|
|
|
+
|
2013-11-12 22:11:33 +00:00
|
|
|
+ ee_name = rt2x00lib_get_eeprom_file_name(rt2x00dev);
|
2016-11-04 06:43:38 +00:00
|
|
|
+ if (!ee_name && test_bit(REQUIRE_EEPROM_FILE, &rt2x00dev->cap_flags)) {
|
|
|
|
+ rt2x00_err(rt2x00dev, "Required EEPROM name is missing.");
|
2011-07-03 15:02:04 +00:00
|
|
|
+ return -EINVAL;
|
|
|
|
+ }
|
|
|
|
+
|
2016-11-04 06:43:38 +00:00
|
|
|
+ if (!ee_name)
|
|
|
|
+ return 0;
|
|
|
|
+
|
2013-06-15 20:14:06 +00:00
|
|
|
+ rt2x00_info(rt2x00dev, "Loading EEPROM data from '%s'.\n", ee_name);
|
2011-07-03 15:02:04 +00:00
|
|
|
+
|
|
|
|
+ retval = request_firmware(&ee, ee_name, rt2x00dev->dev);
|
|
|
|
+ if (retval) {
|
2013-06-15 20:14:06 +00:00
|
|
|
+ rt2x00_err(rt2x00dev, "Failed to request EEPROM.\n");
|
2011-07-03 15:02:04 +00:00
|
|
|
+ return retval;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ if (!ee || !ee->size || !ee->data) {
|
2013-06-15 20:14:06 +00:00
|
|
|
+ rt2x00_err(rt2x00dev, "Failed to read EEPROM file.\n");
|
2011-07-03 15:02:04 +00:00
|
|
|
+ retval = -ENOENT;
|
|
|
|
+ goto err_exit;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ if (ee->size != rt2x00dev->ops->eeprom_size) {
|
2013-06-15 20:14:06 +00:00
|
|
|
+ rt2x00_err(rt2x00dev,
|
|
|
|
+ "EEPROM file size is invalid, it should be %d bytes\n",
|
|
|
|
+ rt2x00dev->ops->eeprom_size);
|
2011-07-03 15:02:04 +00:00
|
|
|
+ retval = -EINVAL;
|
|
|
|
+ goto err_release_ee;
|
|
|
|
+ }
|
|
|
|
+
|
2023-10-15 14:07:22 +00:00
|
|
|
+ memcpy(rt2x00dev->eeprom, ee->data, rt2x00dev->ops->eeprom_size);
|
2011-07-03 15:02:04 +00:00
|
|
|
+
|
|
|
|
+err_release_ee:
|
|
|
|
+ release_firmware(ee);
|
|
|
|
+err_exit:
|
|
|
|
+ return retval;
|
|
|
|
+}
|
|
|
|
+
|
2023-10-15 14:07:22 +00:00
|
|
|
+int rt2x00lib_read_eeprom(struct rt2x00_dev *rt2x00dev)
|
2011-07-03 15:02:04 +00:00
|
|
|
+{
|
2023-10-15 14:07:22 +00:00
|
|
|
+ return rt2x00lib_read_eeprom_file(rt2x00dev);
|
2011-07-03 15:02:04 +00:00
|
|
|
+}
|
2023-10-15 14:07:22 +00:00
|
|
|
+EXPORT_SYMBOL_GPL(rt2x00lib_read_eeprom);
|
2015-12-04 22:39:37 +00:00
|
|
|
--- a/drivers/net/wireless/ralink/rt2x00/rt2x00soc.c
|
|
|
|
+++ b/drivers/net/wireless/ralink/rt2x00/rt2x00soc.c
|
2019-07-06 22:08:20 +00:00
|
|
|
@@ -86,6 +86,7 @@ int rt2x00soc_probe(struct platform_devi
|
2017-02-02 11:02:22 +00:00
|
|
|
if (IS_ERR(rt2x00dev->clk))
|
|
|
|
rt2x00dev->clk = NULL;
|
2011-07-03 15:02:04 +00:00
|
|
|
|
2017-02-02 11:02:22 +00:00
|
|
|
+ set_bit(REQUIRE_EEPROM_FILE, &rt2x00dev->cap_flags);
|
2011-07-03 15:02:04 +00:00
|
|
|
rt2x00_set_chip_intf(rt2x00dev, RT2X00_CHIP_INTF_SOC);
|
|
|
|
|
2017-02-02 11:02:22 +00:00
|
|
|
retval = rt2x00soc_alloc_reg(rt2x00dev);
|
2024-08-17 04:04:43 +00:00
|
|
|
--- a/drivers/net/wireless/ralink/rt2x00/rt2800pci.c
|
|
|
|
+++ b/drivers/net/wireless/ralink/rt2x00/rt2800pci.c
|
|
|
|
@@ -278,6 +278,9 @@ static int rt2800pci_read_eeprom(struct
|
|
|
|
{
|
|
|
|
int retval;
|
|
|
|
|
|
|
|
+ if (!rt2x00lib_read_eeprom(rt2x00dev))
|
|
|
|
+ return 0;
|
|
|
|
+
|
|
|
|
if (rt2800pci_efuse_detect(rt2x00dev))
|
|
|
|
retval = rt2800pci_read_eeprom_efuse(rt2x00dev);
|
|
|
|
else
|
|
|
|
--- a/drivers/net/wireless/ralink/rt2x00/rt2800lib.h
|
|
|
|
+++ b/drivers/net/wireless/ralink/rt2x00/rt2800lib.h
|
|
|
|
@@ -270,4 +270,13 @@ void rt2800_get_txwi_rxwi_size(struct rt
|
|
|
|
unsigned short *rxwi_size);
|
|
|
|
void rt2800_pre_reset_hw(struct rt2x00_dev *rt2x00dev);
|
2023-10-15 14:07:22 +00:00
|
|
|
|
|
|
|
+/*
|
|
|
|
+ * EEPROM file handlers.
|
|
|
|
+ */
|
|
|
|
+#ifdef CPTCFG_RT2X00_LIB_EEPROM
|
|
|
|
+int rt2x00lib_read_eeprom(struct rt2x00_dev *rt2x00dev);
|
|
|
|
+#else
|
|
|
|
+#define rt2x00lib_read_eeprom NULL
|
|
|
|
+#endif /* CPTCFG_RT2X00_LIB_EEPROM */
|
|
|
|
+
|
2024-08-17 04:04:43 +00:00
|
|
|
#endif /* RT2800LIB_H */
|