1 From 1046fc9e98936991aeb0b0656c84833d96a63c0f Mon Sep 17 00:00:00 2001
2 From: Christian Marangi <ansuelsmth@gmail.com>
3 Date: Sun, 15 Oct 2023 14:22:49 +0200
4 Subject: [PATCH 1/5] wifi: rt2x00: Add support for loading EEPROM from
7 Add support for loading EEPROM from userspace.
9 Signed-off-by: Christian Marangi <ansuelsmth@gmail.com>
11 drivers/net/wireless/ralink/rt2x00/Kconfig | 5 ++
12 drivers/net/wireless/ralink/rt2x00/Makefile | 1 +
13 .../net/wireless/ralink/rt2x00/rt2800soc.c | 15 +---
14 drivers/net/wireless/ralink/rt2x00/rt2x00.h | 1 +
15 .../net/wireless/ralink/rt2x00/rt2x00dev.c | 9 +++
16 .../net/wireless/ralink/rt2x00/rt2x00eeprom.c | 75 +++++++++++++++++++
17 .../net/wireless/ralink/rt2x00/rt2x00soc.c | 1 +
18 .../net/wireless/ralink/rt2x00/rt2x00soc.h | 9 +++
19 8 files changed, 102 insertions(+), 14 deletions(-)
20 create mode 100644 drivers/net/wireless/ralink/rt2x00/rt2x00eeprom.c
24 @@ -352,6 +352,7 @@ RT2X00_LIB_FIRMWARE=
32 --- a/drivers/net/wireless/ralink/rt2x00/Kconfig
33 +++ b/drivers/net/wireless/ralink/rt2x00/Kconfig
34 @@ -70,6 +70,7 @@ config RT2800PCI
35 select RT2X00_LIB_MMIO
37 select RT2X00_LIB_FIRMWARE
38 + select RT2X00_LIB_EEPROM
39 select RT2X00_LIB_CRYPTO
41 depends on EEPROM_93CX6
42 @@ -216,6 +217,7 @@ config RT2800SOC
43 select RT2X00_LIB_MMIO
44 select RT2X00_LIB_CRYPTO
45 select RT2X00_LIB_FIRMWARE
46 + select RT2X00_LIB_EEPROM
48 select RT2800_LIB_MMIO
50 @@ -266,6 +268,9 @@ config RT2X00_LIB_FIRMWARE
51 config RT2X00_LIB_CRYPTO
54 +config RT2X00_LIB_EEPROM
57 config RT2X00_LIB_LEDS
59 default y if (RT2X00_LIB=y && LEDS_CLASS=y) || (RT2X00_LIB=m && LEDS_CLASS!=n)
60 --- a/drivers/net/wireless/ralink/rt2x00/Makefile
61 +++ b/drivers/net/wireless/ralink/rt2x00/Makefile
62 @@ -8,6 +8,7 @@ rt2x00lib-$(CPTCFG_RT2X00_LIB_DEBUGFS) +
63 rt2x00lib-$(CPTCFG_RT2X00_LIB_CRYPTO) += rt2x00crypto.o
64 rt2x00lib-$(CPTCFG_RT2X00_LIB_FIRMWARE) += rt2x00firmware.o
65 rt2x00lib-$(CPTCFG_RT2X00_LIB_LEDS) += rt2x00leds.o
66 +rt2x00lib-$(CPTCFG_RT2X00_LIB_EEPROM) += rt2x00eeprom.o
68 obj-$(CPTCFG_RT2X00_LIB) += rt2x00lib.o
69 obj-$(CPTCFG_RT2X00_LIB_MMIO) += rt2x00mmio.o
70 --- a/drivers/net/wireless/ralink/rt2x00/rt2800soc.c
71 +++ b/drivers/net/wireless/ralink/rt2x00/rt2800soc.c
72 @@ -90,19 +90,6 @@ static int rt2800soc_set_device_state(st
76 -static int rt2800soc_read_eeprom(struct rt2x00_dev *rt2x00dev)
78 - void __iomem *base_addr = ioremap(0x1F040000, EEPROM_SIZE);
83 - memcpy_fromio(rt2x00dev->eeprom, base_addr, EEPROM_SIZE);
89 /* Firmware functions */
90 static char *rt2800soc_get_firmware_name(struct rt2x00_dev *rt2x00dev)
92 @@ -168,7 +155,7 @@ static const struct rt2800_ops rt2800soc
93 .register_multiread = rt2x00mmio_register_multiread,
94 .register_multiwrite = rt2x00mmio_register_multiwrite,
95 .regbusy_read = rt2x00mmio_regbusy_read,
96 - .read_eeprom = rt2800soc_read_eeprom,
97 + .read_eeprom = rt2x00lib_read_eeprom,
98 .hwcrypt_disabled = rt2800soc_hwcrypt_disabled,
99 .drv_write_firmware = rt2800soc_write_firmware,
100 .drv_init_registers = rt2800mmio_init_registers,
101 --- a/drivers/net/wireless/ralink/rt2x00/rt2x00.h
102 +++ b/drivers/net/wireless/ralink/rt2x00/rt2x00.h
103 @@ -703,6 +703,7 @@ enum rt2x00_capability_flags {
106 REQUIRE_DELAYED_RFKILL,
107 + REQUIRE_EEPROM_FILE,
112 +++ b/drivers/net/wireless/ralink/rt2x00/rt2x00eeprom.c
114 +// SPDX-License-Identifier: GPL-2.0-or-later
115 +/* Copyright (C) 2004 - 2009 Ivo van Doorn <IvDoorn@gmail.com>
116 + * Copyright (C) 2004 - 2009 Gertjan van Wingerde <gwingerde@gmail.com>
117 + * <http://rt2x00.serialmonkey.com>
120 +/* Module: rt2x00lib
121 + * Abstract: rt2x00 eeprom file loading routines.
124 +#include <linux/kernel.h>
125 +#include <linux/module.h>
128 +#include "rt2x00soc.h"
131 +rt2x00lib_get_eeprom_file_name(struct rt2x00_dev *rt2x00dev)
133 + struct rt2x00_platform_data *pdata = rt2x00dev->dev->platform_data;
135 + if (pdata && pdata->eeprom_file_name)
136 + return pdata->eeprom_file_name;
141 +static int rt2x00lib_read_eeprom_file(struct rt2x00_dev *rt2x00dev)
143 + const struct firmware *ee;
144 + const char *ee_name;
147 + ee_name = rt2x00lib_get_eeprom_file_name(rt2x00dev);
148 + if (!ee_name && test_bit(REQUIRE_EEPROM_FILE, &rt2x00dev->cap_flags)) {
149 + rt2x00_err(rt2x00dev, "Required EEPROM name is missing.");
156 + rt2x00_info(rt2x00dev, "Loading EEPROM data from '%s'.\n", ee_name);
158 + retval = request_firmware(&ee, ee_name, rt2x00dev->dev);
160 + rt2x00_err(rt2x00dev, "Failed to request EEPROM.\n");
164 + if (!ee || !ee->size || !ee->data) {
165 + rt2x00_err(rt2x00dev, "Failed to read EEPROM file.\n");
170 + if (ee->size != rt2x00dev->ops->eeprom_size) {
171 + rt2x00_err(rt2x00dev,
172 + "EEPROM file size is invalid, it should be %d bytes\n",
173 + rt2x00dev->ops->eeprom_size);
175 + goto err_release_ee;
178 + memcpy(rt2x00dev->eeprom, ee->data, rt2x00dev->ops->eeprom_size);
181 + release_firmware(ee);
186 +int rt2x00lib_read_eeprom(struct rt2x00_dev *rt2x00dev)
188 + return rt2x00lib_read_eeprom_file(rt2x00dev);
190 +EXPORT_SYMBOL_GPL(rt2x00lib_read_eeprom);
191 --- a/drivers/net/wireless/ralink/rt2x00/rt2x00soc.c
192 +++ b/drivers/net/wireless/ralink/rt2x00/rt2x00soc.c
193 @@ -86,6 +86,7 @@ int rt2x00soc_probe(struct platform_devi
194 if (IS_ERR(rt2x00dev->clk))
195 rt2x00dev->clk = NULL;
197 + set_bit(REQUIRE_EEPROM_FILE, &rt2x00dev->cap_flags);
198 rt2x00_set_chip_intf(rt2x00dev, RT2X00_CHIP_INTF_SOC);
200 retval = rt2x00soc_alloc_reg(rt2x00dev);
201 --- a/drivers/net/wireless/ralink/rt2x00/rt2x00soc.h
202 +++ b/drivers/net/wireless/ralink/rt2x00/rt2x00soc.h
203 @@ -26,4 +26,13 @@ int rt2x00soc_resume(struct platform_dev
204 #define rt2x00soc_resume NULL
205 #endif /* CONFIG_PM */
208 + * EEPROM file handlers.
210 +#ifdef CPTCFG_RT2X00_LIB_EEPROM
211 +int rt2x00lib_read_eeprom(struct rt2x00_dev *rt2x00dev);
213 +#define rt2x00lib_read_eeprom NULL
214 +#endif /* CPTCFG_RT2X00_LIB_EEPROM */
216 #endif /* RT2X00SOC_H */