Skip to contentSkip to conversation

rt2800usb: Add support for eeprom writing

PATCH New Solomon Peachy 2 participants 6 messages Feb 14, 2013 – Mar 2, 2013 Networking drivers (wireless)

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 rt2800usb: Add support for eeprom writing

Due to a vendor sending us a batch of boards with bad eeprom data, we needed a way of rewriting the eeproms. This hooks the device's eeprom write support up to a debugfs file, since there's no existing command path to trigger eeprom writes in the generic rt2x00 driver.

If there's a better way to accomplish this (ethtool?) I'm all ears, but this solves my immediate problem.

#1 lore raw

PATCH 1/1 rt2800usb: Add support for eeprom writes.

From: Solomon Peachy <[email protected]>

This adds another file under debugfs:

/debug/ieee80211/phyX/rt2800usb/register/eeprom_commit

reading from that file will re-read the eeprom data from device flash writing to that file will store the current eeprom data to device flash.

---
 .../drivers/net/wireless/rt2x00/rt2800lib.h        | 10 ++++++
 .../drivers/net/wireless/rt2x00/rt2800usb.c        |  8 ++++-
 .../drivers/net/wireless/rt2x00/rt2x00debug.c      | 40 ++++++++++++++++++++++
 .../drivers/net/wireless/rt2x00/rt2x00usb.h        | 19 ++++++++++
 4 files changed, 76 insertions(+), 1 deletion(-)
drivers/net/wireless/rt2x00/rt2800lib.h +10 -0
index a128cea..d653c09 100644
@@ -44,6 +44,7 @@ struct rt2800_ops {
 			    const struct rt2x00_field32 field, u32 *reg);
 
 	void (*read_eeprom)(struct rt2x00_dev *rt2x00dev);
+	void (*write_eeprom)(struct rt2x00_dev *rt2x00dev);
 	bool (*hwcrypt_disabled)(struct rt2x00_dev *rt2x00dev);
 
 	int (*drv_write_firmware)(struct rt2x00_dev *rt2x00dev,
@@ -124,6 +125,15 @@ static inline void rt2800_read_eeprom(struct rt2x00_dev *rt2x00dev)
 	rt2800ops->read_eeprom(rt2x00dev);
 }
 
+static inline void rt2800_write_eeprom(struct rt2x00_dev *rt2x00dev)
+{
+	const struct rt2800_ops *rt2800ops = rt2x00dev->ops->drv;
+
+	if (rt2800ops->write_eeprom)
+		rt2800ops->write_eeprom(rt2x00dev);
+}
+
+
 static inline bool rt2800_hwcrypt_disabled(struct rt2x00_dev *rt2x00dev)
 {
 	const struct rt2800_ops *rt2800ops = rt2x00dev->ops->drv;
drivers/net/wireless/rt2x00/rt2800usb.c +7 -1
index 85a4b62..22d14d2 100644
@@ -743,7 +743,12 @@ static void rt2800usb_read_eeprom(struct rt2x00_dev *rt2x00dev)
 		rt2x00usb_eeprom_read(rt2x00dev, rt2x00dev->eeprom,
 				      EEPROM_SIZE);
 }
-
+static void rt2800usb_write_eeprom(struct rt2x00_dev *rt2x00dev)
+{
+	if (!rt2800_efuse_detect(rt2x00dev))
+		rt2x00usb_eeprom_write(rt2x00dev, rt2x00dev->eeprom,
+				       EEPROM_SIZE);
+}
 static int rt2800usb_probe_hw(struct rt2x00_dev *rt2x00dev)
 {
 	int retval;
@@ -802,6 +807,7 @@ static const struct rt2800_ops rt2800usb_rt2800_ops = {
 	.register_multiwrite	= rt2x00usb_register_multiwrite,
 	.regbusy_read		= rt2x00usb_regbusy_read,
 	.read_eeprom		= rt2800usb_read_eeprom,
+	.write_eeprom		= rt2800usb_write_eeprom,
 	.hwcrypt_disabled	= rt2800usb_hwcrypt_disabled,
 	.drv_write_firmware	= rt2800usb_write_firmware,
 	.drv_init_registers	= rt2800usb_init_registers,
drivers/net/wireless/rt2x00/rt2x00debug.c +40 -0
index 3bb8caf..f6776b1 100644
@@ -86,6 +86,7 @@ struct rt2x00debug_intf {
 	struct dentry *csr_val_entry;
 	struct dentry *eeprom_off_entry;
 	struct dentry *eeprom_val_entry;
+	struct dentry *eeprom_commit_entry;
 	struct dentry *bbp_off_entry;
 	struct dentry *bbp_val_entry;
 	struct dentry *rf_off_entry;
@@ -650,6 +651,37 @@ static struct dentry *rt2x00debug_create_file_chipset(const char *name,
 	return debugfs_create_blob(name, S_IRUSR, intf->driver_folder, blob);
 }
 
+#include "rt2800lib.h"
+static ssize_t rt2x00debug_eeprom_commit_write(struct file *file,
+					       const char __user *buf,
+					       size_t length,
+					       loff_t *offset)
+{
+	struct rt2x00debug_intf *intf = file->private_data;
+
+	rt2800_write_eeprom(intf->rt2x00dev);
+	return length;
+}
+static ssize_t rt2x00debug_eeprom_commit_read(struct file *file,
+					      char __user *buf,
+					      size_t length,
+					      loff_t *offset)
+{
+	struct rt2x00debug_intf *intf = file->private_data;
+
+	rt2800_read_eeprom(intf->rt2x00dev);
+	return 0;
+}
+
+static const struct file_operations rt2x00debug_fop_eeprom_commit = {
+	.owner		= THIS_MODULE,
+	.write		= rt2x00debug_eeprom_commit_write,
+	.read		= rt2x00debug_eeprom_commit_read,
+	.open		= rt2x00debug_file_open,
+	.release	= rt2x00debug_file_release,
+	.llseek		= default_llseek,
+};
+
 void rt2x00debug_register(struct rt2x00_dev *rt2x00dev)
 {
 	const struct rt2x00debug *debug = rt2x00dev->ops->debugfs;
@@ -730,6 +762,13 @@ void rt2x00debug_register(struct rt2x00_dev *rt2x00dev)
 
 #undef RT2X00DEBUGFS_CREATE_REGISTER_ENTRY
 
+	intf->eeprom_commit_entry =
+		debugfs_create_file("eeprom_commit", S_IRUSR | S_IWUSR,
+				    intf->register_folder,
+				    intf, &rt2x00debug_fop_eeprom_commit);
+	if (IS_ERR(intf->eeprom_commit_entry) || !intf->eeprom_commit_entry)
+		goto exit;
+
 	intf->queue_folder =
 	    debugfs_create_dir("queue", intf->driver_folder);
 	if (IS_ERR(intf->queue_folder) || !intf->queue_folder)
@@ -786,6 +825,7 @@ void rt2x00debug_deregister(struct rt2x00_dev *rt2x00dev)
 	debugfs_remove(intf->bbp_off_entry);
 	debugfs_remove(intf->eeprom_val_entry);
 	debugfs_remove(intf->eeprom_off_entry);
+	debugfs_remove(intf->eeprom_commit_entry);
 	debugfs_remove(intf->csr_val_entry);
 	debugfs_remove(intf->csr_off_entry);
 	debugfs_remove(intf->register_folder);
drivers/net/wireless/rt2x00/rt2x00usb.h +19 -0
index 323ca7b..f8ed3de 100644
@@ -203,6 +203,25 @@ static inline int rt2x00usb_eeprom_read(struct rt2x00_dev *rt2x00dev,
 }
 
 /**
+ * rt2x00usb_eeprom_write - Write eeprom to device
+ * @rt2x00dev: Pointer to &struct rt2x00_dev
+ * @eeprom: Pointer to eeprom array to copy the information from
+ * @length: Number of bytes to write to the eeprom
+ *
+ * Simple wrapper around rt2x00usb_vendor_request to write the eeprom
+ * to the device. Note that the eeprom argument _must_ be allocated using
+ * kmalloc for correct handling inside the kernel USB layer.
+ */
+static inline int rt2x00usb_eeprom_write(struct rt2x00_dev *rt2x00dev,
+					 __le16 *eeprom, const u16 length)
+{
+	return rt2x00usb_vendor_request(rt2x00dev, USB_EEPROM_WRITE,
+					USB_VENDOR_REQUEST_OUT, 0, 0,
+					eeprom, length,
+					REGISTER_TIMEOUT16(length));
+}
+
+/**
  * rt2x00usb_register_read - Read 32bit register word
  * @rt2x00dev: Device pointer, see &struct rt2x00_dev.
  * @offset: Register offset
Signature · 1 line
1.7.11.7
#2 lore raw

Re: [PATCH] rt2800usb: Add support for eeprom writes.

Hi,

drivers/net/wireless/rt2x00/rt2x00debug.c struct rt2x00debug_intf { · line 89

Quoted 9 lines
drivers/net/wireless/rt2x00/rt2x00debug.c +1 -0
index 3bb8caf..f6776b1 100644
@@ -86,6 +86,7 @@ struct rt2x00debug_intf {
        struct dentry *csr_val_entry;
        struct dentry *eeprom_off_entry;
        struct dentry *eeprom_val_entry;
+       struct dentry *eeprom_commit_entry;

This is incorrect, all other debugfs files are read/write, so there is no point in a extra commit file.

drivers/net/wireless/rt2x00/rt2x00debug.c static struct dentry *rt2x00debug_create_file_chipset(const char *name, · line 654

Quoted 5 lines
drivers/net/wireless/rt2x00/rt2x00debug.c +1 -0
@@ -650,6 +651,37 @@ static struct dentry *rt2x00debug_create_file_chipset(const char *name,
        return debugfs_create_blob(name, S_IRUSR, intf->driver_folder, blob);
 }
 
+#include "rt2800lib.h"

So here we make the _generic_ rt2x00lib module be specific for rt2800 only. That is a terrible idea.

Quoted 10 lines
drivers/net/wireless/rt2x00/rt2x00debug.c +10 -0
+static ssize_t rt2x00debug_eeprom_commit_write(struct file *file,
+                                              const char __user *buf,
+                                              size_t length,
+                                              loff_t *offset)
+{
+       struct rt2x00debug_intf *intf = file->private_data;
+
+       rt2800_write_eeprom(intf->rt2x00dev);
+       return length;
+}

drivers/net/wireless/rt2x00/rt2x00debug.c static struct dentry *rt2x00debug_create_file_chipset(const char *name, · line 674

Quoted 10 lines
drivers/net/wireless/rt2x00/rt2x00debug.c +10 -0
+static ssize_t rt2x00debug_eeprom_commit_read(struct file *file,
+                                             char __user *buf,
+                                             size_t length,
+                                             loff_t *offset)
+{
+       struct rt2x00debug_intf *intf = file->private_data;
+
+       rt2800_read_eeprom(intf->rt2x00dev);
+       return 0;
+}

rt2800 specific code doesn't belong in the generic code. You should make your solution
completely driver independent.

Quoted 8 lines
drivers/net/wireless/rt2x00/rt2x00debug.c +7 -0
 /**
+ * rt2x00usb_eeprom_write - Write eeprom to device
+ * @rt2x00dev: Pointer to &struct rt2x00_dev
+ * @eeprom: Pointer to eeprom array to copy the information from
+ * @length: Number of bytes to write to the eeprom
+ *
+ * Simple wrapper around rt2x00usb_vendor_request to write the eeprom
+ * to the device. Note that the eeprom argument _must_ be allocated using

drivers/net/wireless/rt2x00/rt2x00debug.c static struct dentry *rt2x00debug_create_file_chipset(const char *name,

Quoted 10 lines
drivers/net/wireless/rt2x00/rt2x00debug.c +10 -0
+ * kmalloc for correct handling inside the kernel USB layer.
+ */
+static inline int rt2x00usb_eeprom_write(struct rt2x00_dev *rt2x00dev,
+                                        __le16 *eeprom, const u16 length)
+{
+       return rt2x00usb_vendor_request(rt2x00dev, USB_EEPROM_WRITE,
+                                       USB_VENDOR_REQUEST_OUT, 0, 0,
+                                       eeprom, length,
+                                       REGISTER_TIMEOUT16(length));
+}

Have you checked if this is specific to rt2800 or would other Ralink USB devices be able to work with this as well?

Ivo

#3 lore raw

Re: [PATCH] rt2800usb: Add support for eeprom writes.

Quoted 2 lines · Ivo Van Doorn

This is incorrect, all other debugfs files are read/write, so there is no point in a extra commit file.

The other eeprom debugfs files only modify the in-memory copy of the eeprom data; they do not actually write it back out to the eeprom.

Furthermore, the rt2800usb driver often "validates" (ie modifies) the in-memory copy of the eeprom data, so I needed to have a way to re-read the raw data so I would only modify what was absolutely necessary.

(IIRC the PCI-based modules expose a standard I2C eeprom which can be
accessed/updated independently)

Quoted 2 lines

rt2800 specific code doesn't belong in the generic code. You should make your solution completely driver independent.

I see your point.

This should come via bolting on generic eeprom read/write functions to rt2x00lib_ops, and calling those from the debugfs hooks, correct?

Alternatively this could be bolted up to ethtool's eeprom manipulation hooks instead of the debugfs hook I hacked in there.

Let me know what you'd prefer.

Quoted 2 lines

Have you checked if this is specific to rt2800 or would other Ralink USB devices be able to work with this as well?

I only have access to RT2870 modules at the moment, so I don't have any way of verifying this applies to non-RT2800 modules. I suppose I could wade through ralink's posted source code, but the comments in rt2x00usb.h seem to indicate eeprom write support is generic.

- Solomon

Signature · 3 lines
Solomon Peachy        		       pizza at shaftnet dot org	 
Melbourne, FL                          ^^ (mail/jabber/gtalk) ^^
Quidquid latine dictum sit, altum viditur.
#4 lore raw

PATCH v2 1/1 Add eeprom write supprot to rt2800usb

In reply to Ivo Van Doorn
Quoted 2 lines · Ivo Van Doorn

rt2800 specific code doesn't belong in the generic code. You should make your solution completely driver independent.

Okay, I've attached my current WIP code. I want to make sure I'm on an acceptible track before I proceed further.

This patch is more invasive than the first, but functionally it's identical to my first patch.

Comments?

- Solomon

Signature · 3 lines
Solomon Peachy        		       pizza at shaftnet dot org	 
Melbourne, FL                          ^^ (mail/jabber/gtalk) ^^
Quidquid latine dictum sit, altum viditur.
drivers/net/wireless/rt2x00/rt2800lib.c +10 -8
index 197b446..82221e0 100644
@@ -4574,7 +4574,8 @@ int rt2800_efuse_detect(struct rt2x00_dev *rt2x00dev)
 }
 EXPORT_SYMBOL_GPL(rt2800_efuse_detect);
 
-static void rt2800_efuse_read(struct rt2x00_dev *rt2x00dev, unsigned int i)
+static void rt2800_efuse_read(struct rt2x00_dev *rt2x00dev,
+			      u16 *eeprom, unsigned int i)
 {
 	u32 reg;
 	u16 efuse_ctrl_reg;
@@ -4609,23 +4610,24 @@ static void rt2800_efuse_read(struct rt2x00_dev *rt2x00dev, unsigned int i)
 	/* Apparently the data is read from end to start */
 	rt2800_register_read_lock(rt2x00dev, efuse_data3_reg, &reg);
 	/* The returned value is in CPU order, but eeprom is le */
-	*(u32 *)&rt2x00dev->eeprom[i] = cpu_to_le32(reg);
+	*(u32 *)&eeprom[i] = cpu_to_le32(reg);
 	rt2800_register_read_lock(rt2x00dev, efuse_data2_reg, &reg);
-	*(u32 *)&rt2x00dev->eeprom[i + 2] = cpu_to_le32(reg);
+	*(u32 *)&eeprom[i + 2] = cpu_to_le32(reg);
 	rt2800_register_read_lock(rt2x00dev, efuse_data1_reg, &reg);
-	*(u32 *)&rt2x00dev->eeprom[i + 4] = cpu_to_le32(reg);
+	*(u32 *)&eeprom[i + 4] = cpu_to_le32(reg);
 	rt2800_register_read_lock(rt2x00dev, efuse_data0_reg, &reg);
-	*(u32 *)&rt2x00dev->eeprom[i + 6] = cpu_to_le32(reg);
+	*(u32 *)&eeprom[i + 6] = cpu_to_le32(reg);
 
 	mutex_unlock(&rt2x00dev->csr_mutex);
 }
 
-void rt2800_read_eeprom_efuse(struct rt2x00_dev *rt2x00dev)
+void rt2800_read_eeprom_efuse(struct rt2x00_dev *rt2x00dev,
+			      u16 *eeprom, const u16 length)
 {
 	unsigned int i;
 
-	for (i = 0; i < EEPROM_SIZE / sizeof(u16); i += 8)
-		rt2800_efuse_read(rt2x00dev, i);
+	for (i = 0; i < length / sizeof(u16); i += 8)
+		rt2800_efuse_read(rt2x00dev, eeprom, i);
 }
 EXPORT_SYMBOL_GPL(rt2800_read_eeprom_efuse);
 
drivers/net/wireless/rt2x00/rt2800lib.h +2 -1
index a128cea..3c5452d 100644
@@ -207,7 +207,8 @@ int rt2800_enable_radio(struct rt2x00_dev *rt2x00dev);
 void rt2800_disable_radio(struct rt2x00_dev *rt2x00dev);
 
 int rt2800_efuse_detect(struct rt2x00_dev *rt2x00dev);
-void rt2800_read_eeprom_efuse(struct rt2x00_dev *rt2x00dev);
+void rt2800_read_eeprom_efuse(struct rt2x00_dev *rt2x00dev,
+			      u16 *eeprom, const u16 length);
 
 int rt2800_probe_hw(struct rt2x00_dev *rt2x00dev);
 
drivers/net/wireless/rt2x00/rt2800pci.c +1 -1
index 9224d87..7782002 100644
@@ -173,7 +173,7 @@ static int rt2800pci_efuse_detect(struct rt2x00_dev *rt2x00dev)
 
 static inline void rt2800pci_read_eeprom_efuse(struct rt2x00_dev *rt2x00dev)
 {
-	rt2800_read_eeprom_efuse(rt2x00dev);
+	rt2800_read_eeprom_efuse(rt2x00dev, rt2x00dev->eeprom, EEPROM_SIZE);
 }
 #else
 static inline void rt2800pci_read_eeprom_pci(struct rt2x00_dev *rt2x00dev)
drivers/net/wireless/rt2x00/rt2800usb.c +35 -1
index 85a4b62..9a90fa1 100644
@@ -733,12 +733,43 @@ static void rt2800usb_fill_rxdone(struct queue_entry *entry,
 }
 
 /*
+ *  EEPROM manipulation functions,
+ */
+static int rt2800usb_load_eeprom(struct rt2x00_dev *rt2x00dev,
+				 u16 *eeprom, const u16 length)
+{
+	u16 len = min_t(u16, length, EEPROM_SIZE);
+
+	if (rt2800_efuse_detect(rt2x00dev))
+		rt2800_read_eeprom_efuse(rt2x00dev, eeprom,
+					 len);
+	else
+		rt2x00usb_eeprom_read(rt2x00dev, eeprom, len);
+
+	return len;
+}
+
+static int rt2800usb_store_eeprom(struct rt2x00_dev *rt2x00dev,
+				  u16 *eeprom, const u16 length)
+{
+	u16 len = min_t(u16, length, EEPROM_SIZE);
+
+	if (rt2800_efuse_detect(rt2x00dev))
+		return -EINVAL;
+
+	rt2x00usb_eeprom_write(rt2x00dev, eeprom, len);
+
+	return length;
+}
+
+/*
  * Device probe functions.
  */
 static void rt2800usb_read_eeprom(struct rt2x00_dev *rt2x00dev)
 {
 	if (rt2800_efuse_detect(rt2x00dev))
-		rt2800_read_eeprom_efuse(rt2x00dev);
+		rt2800_read_eeprom_efuse(rt2x00dev, rt2x00dev->eeprom,
+					 EEPROM_SIZE);
 	else
 		rt2x00usb_eeprom_read(rt2x00dev, rt2x00dev->eeprom,
 				      EEPROM_SIZE);
@@ -844,6 +875,9 @@ static const struct rt2x00lib_ops rt2800usb_rt2x00_ops = {
 	.config			= rt2800_config,
 	.sta_add		= rt2800_sta_add,
 	.sta_remove		= rt2800_sta_remove,
+
+	.eeprom_load            = rt2800usb_load_eeprom,
+	.eeprom_store           = rt2800usb_store_eeprom,
 };
 
 static const struct data_queue_desc rt2800usb_queue_rx = {
drivers/net/wireless/rt2x00/rt2x00.h +6 -0
index 0751b35..8fd81f5 100644
@@ -648,6 +648,12 @@ struct rt2x00lib_ops {
 			struct ieee80211_sta *sta);
 	int (*sta_remove) (struct rt2x00_dev *rt2x00dev,
 			   int wcid);
+
+	/* EEPROM manipulation */
+	int (*eeprom_load) (struct rt2x00_dev *rt2x00dev,
+			    u16 *eeprom, const u16 max_length);
+	int (*eeprom_store) (struct rt2x00_dev *rt2x00dev,
+			     u16 *eeprom, const u16 max_length);
 };
 
 /*
drivers/net/wireless/rt2x00/rt2x00debug.c +47 -0

71 lines not on this page · raw message

drivers/net/wireless/rt2x00/rt2x00usb.h +19 -0
index 323ca7b..f8ed3de 100644
@@ -203,6 +203,25 @@ static inline int rt2x00usb_eeprom_read(struct rt2x00_dev *rt2x00dev,
 }
 
 /**
+ * rt2x00usb_eeprom_write - Write eeprom to device
+ * @rt2x00dev: Pointer to &struct rt2x00_dev
+ * @eeprom: Pointer to eeprom array to copy the information from
+ * @length: Number of bytes to write to the eeprom
+ *
+ * Simple wrapper around rt2x00usb_vendor_request to write the eeprom
+ * to the device. Note that the eeprom argument _must_ be allocated using
+ * kmalloc for correct handling inside the kernel USB layer.
+ */
+static inline int rt2x00usb_eeprom_write(struct rt2x00_dev *rt2x00dev,
+					 __le16 *eeprom, const u16 length)
+{
+	return rt2x00usb_vendor_request(rt2x00dev, USB_EEPROM_WRITE,
+					USB_VENDOR_REQUEST_OUT, 0, 0,
+					eeprom, length,
+					REGISTER_TIMEOUT16(length));
+}
+
+/**
  * rt2x00usb_register_read - Read 32bit register word
  * @rt2x00dev: Device pointer, see &struct rt2x00_dev.
  * @offset: Register offset
#5 lore raw

PATCH v3 1/1 Add eeprom/efuse write supprot to rt2800usb

The major addition from the last patch is the addition of eFuse write support. I used the the Ralink vendor drivers (gack!) as a reference.

There are several things that need to be addressed before this can be committed (indepdently of any comments y'all may have):

* some printk debug output is still present
* Probably won't pass checkpatch scrutiny
* debugfs interface to trigger load/store of eeprom data is unchanged
* Only rt2800usb (rt2870+eeprom, rt3070+eeprom, rt3070+efuse) is tested
* uses hardcoded efuse offsets/sizes for rt3070 (see '//' comments)

The latter point is the critical one, and I'd like suggestions on how to handle this -- The vendor drivers use hardcoded values based on the identified chip. So far I've itentified four distinct types by perusing the vendor USB drivers. (PCI/SoC chips mayhave more variants too)

Is it worth setting globally at module init time, or just hardcoded/handled in this function based on chip detection? Due to how the efuse block mapping is handled, if the wrong offsets (or lengths) are used, it's possible to brick the module.

If there's a reasonable shot at getting this patch (or a reworked version) committed, I'll iterate this until it's acceptible.

Let me know,

- Solomon

Signature · 3 lines
Solomon Peachy        		       pizza at shaftnet dot org	 
Melbourne, FL                          ^^ (mail/jabber/gtalk) ^^
Quidquid latine dictum sit, altum viditur.
drivers/net/wireless/rt2x00/rt2800.h +8 -0
index 4db1088..1cdfe0c 100644
@@ -641,10 +641,18 @@
 #define EFUSE_CTRL			0x0580
 #define EFUSE_CTRL_ADDRESS_IN		FIELD32(0x03fe0000)
 #define EFUSE_CTRL_MODE			FIELD32(0x000000c0)
+#define EFUSE_CTRL_ADDRESS_OUT		FIELD32(0x0000003f)
 #define EFUSE_CTRL_KICK			FIELD32(0x40000000)
 #define EFUSE_CTRL_PRESENT		FIELD32(0x80000000)
 
 /*
+ * EFUSE MODE selection
+ */
+#define EFUSE_CTRL_MODE_READ_VIRTUAL    0
+#define EFUSE_CTRL_MODE_READ_PHYSICAL   1
+#define EFUSE_CTRL_MODE_WRITE_PHYSICAL  3
+
+/*
  * EFUSE_DATA0
  */
 #define EFUSE_DATA0			0x0590
drivers/net/wireless/rt2x00/rt2800lib.c +169 -10

218 lines not on this page · raw message

drivers/net/wireless/rt2x00/rt2800lib.h +4 -1
index a128cea..c266c79 100644
@@ -207,7 +207,10 @@ int rt2800_enable_radio(struct rt2x00_dev *rt2x00dev);
 void rt2800_disable_radio(struct rt2x00_dev *rt2x00dev);
 
 int rt2800_efuse_detect(struct rt2x00_dev *rt2x00dev);
-void rt2800_read_eeprom_efuse(struct rt2x00_dev *rt2x00dev);
+void rt2800_read_eeprom_efuse(struct rt2x00_dev *rt2x00dev, u16 *eeprom,
+			      const u16 length);
+void rt2800_write_eeprom_efuse(struct rt2x00_dev *rt2x00dev, u16 *eeprom,
+			       const u16 length);
 
 int rt2800_probe_hw(struct rt2x00_dev *rt2x00dev);
 
drivers/net/wireless/rt2x00/rt2800pci.c +1 -1
index 9224d87..7782002 100644
@@ -173,7 +173,7 @@ static int rt2800pci_efuse_detect(struct rt2x00_dev *rt2x00dev)
 
 static inline void rt2800pci_read_eeprom_efuse(struct rt2x00_dev *rt2x00dev)
 {
-	rt2800_read_eeprom_efuse(rt2x00dev);
+	rt2800_read_eeprom_efuse(rt2x00dev, rt2x00dev->eeprom, EEPROM_SIZE);
 }
 #else
 static inline void rt2800pci_read_eeprom_pci(struct rt2x00_dev *rt2x00dev)
drivers/net/wireless/rt2x00/rt2800usb.c +34 -1
index 85a4b62..069be20 100644
@@ -733,12 +733,42 @@ static void rt2800usb_fill_rxdone(struct queue_entry *entry,
 }
 
 /*
+ *  EEPROM manipulation functions,
+ */
+static int rt2800usb_load_eeprom(struct rt2x00_dev *rt2x00dev,
+				 u16 *eeprom, const u16 length)
+{
+	u16 len = min_t(u16, length, EEPROM_SIZE);
+
+	if (rt2800_efuse_detect(rt2x00dev))
+		rt2800_read_eeprom_efuse(rt2x00dev, eeprom, len);
+	else
+		rt2x00usb_eeprom_read(rt2x00dev, eeprom, len);
+
+	return len;
+}
+
+static int rt2800usb_store_eeprom(struct rt2x00_dev *rt2x00dev,
+				  u16 *eeprom, const u16 length)
+{
+	u16 len = min_t(u16, length, EEPROM_SIZE);
+
+	if (rt2800_efuse_detect(rt2x00dev))
+		rt2800_write_eeprom_efuse(rt2x00dev, eeprom, len);
+	else
+		rt2x00usb_eeprom_write(rt2x00dev, eeprom, len);
+
+	return length;
+}
+
+/*
  * Device probe functions.
  */
 static void rt2800usb_read_eeprom(struct rt2x00_dev *rt2x00dev)
 {
 	if (rt2800_efuse_detect(rt2x00dev))
-		rt2800_read_eeprom_efuse(rt2x00dev);
+		rt2800_read_eeprom_efuse(rt2x00dev, rt2x00dev->eeprom,
+					 EEPROM_SIZE);
 	else
 		rt2x00usb_eeprom_read(rt2x00dev, rt2x00dev->eeprom,
 				      EEPROM_SIZE);
@@ -844,6 +874,9 @@ static const struct rt2x00lib_ops rt2800usb_rt2x00_ops = {
 	.config			= rt2800_config,
 	.sta_add		= rt2800_sta_add,
 	.sta_remove		= rt2800_sta_remove,
+
+	.eeprom_load            = rt2800usb_load_eeprom,
+	.eeprom_store           = rt2800usb_store_eeprom,
 };
 
 static const struct data_queue_desc rt2800usb_queue_rx = {
drivers/net/wireless/rt2x00/rt2x00.h +6 -0
index 0751b35..8fd81f5 100644
@@ -648,6 +648,12 @@ struct rt2x00lib_ops {
 			struct ieee80211_sta *sta);
 	int (*sta_remove) (struct rt2x00_dev *rt2x00dev,
 			   int wcid);
+
+	/* EEPROM manipulation */
+	int (*eeprom_load) (struct rt2x00_dev *rt2x00dev,
+			    u16 *eeprom, const u16 max_length);
+	int (*eeprom_store) (struct rt2x00_dev *rt2x00dev,
+			     u16 *eeprom, const u16 max_length);
 };
 
 /*
drivers/net/wireless/rt2x00/rt2x00debug.c +47 -0

71 lines not on this page · raw message

drivers/net/wireless/rt2x00/rt2x00usb.h +19 -0
index 323ca7b..f8ed3de 100644
@@ -203,6 +203,25 @@ static inline int rt2x00usb_eeprom_read(struct rt2x00_dev *rt2x00dev,
 }
 
 /**
+ * rt2x00usb_eeprom_write - Write eeprom to device
+ * @rt2x00dev: Pointer to &struct rt2x00_dev
+ * @eeprom: Pointer to eeprom array to copy the information from
+ * @length: Number of bytes to write to the eeprom
+ *
+ * Simple wrapper around rt2x00usb_vendor_request to write the eeprom
+ * to the device. Note that the eeprom argument _must_ be allocated using
+ * kmalloc for correct handling inside the kernel USB layer.
+ */
+static inline int rt2x00usb_eeprom_write(struct rt2x00_dev *rt2x00dev,
+					 __le16 *eeprom, const u16 length)
+{
+	return rt2x00usb_vendor_request(rt2x00dev, USB_EEPROM_WRITE,
+					USB_VENDOR_REQUEST_OUT, 0, 0,
+					eeprom, length,
+					REGISTER_TIMEOUT16(length));
+}
+
+/**
  * rt2x00usb_register_read - Read 32bit register word
  * @rt2x00dev: Device pointer, see &struct rt2x00_dev.
  * @offset: Register offset