aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/net/wireless/rt2x00/rt73usb.c
diff options
context:
space:
mode:
authorAdam Baker <linux@baker-net.org.uk>2007-10-27 07:43:29 -0400
committerDavid S. Miller <davem@davemloft.net>2008-01-28 18:03:03 -0500
commit3d82346c5d0ff0a413c387c6edaadc0ca29a0971 (patch)
tree790b3fcc6ccee693d9ac343626d1296c736a7851 /drivers/net/wireless/rt2x00/rt73usb.c
parent4bd7c452a468af30bb3c4d9c3adcdaf3f3c6048c (diff)
rt2x00: Place mutex around USB register access
There is a buffer, csr_cache which is used to hold copies of data being passed to the USB stack which can get corrupted if multiple threads attempt to access CSR registers simultaneously. There is also the possibility if multiple threads try to access BBP or RF registers for the multiple USB operations needed to get interleaved leading to incorrect results. This patch introduces a mutex to prevent such simultaneous access. The interleaved access problem may also affect the PCI devices but if so that will be handled in a follow-up patch. Signed-off-by: Adam Baker <linux@baker-net.org.uk> Signed-off-by: Ivo van Doorn <IvDoorn@gmail.com> Signed-off-by: John W. Linville <linville@tuxdriver.com> Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'drivers/net/wireless/rt2x00/rt73usb.c')
-rw-r--r--drivers/net/wireless/rt2x00/rt73usb.c42
1 files changed, 37 insertions, 5 deletions
diff --git a/drivers/net/wireless/rt2x00/rt73usb.c b/drivers/net/wireless/rt2x00/rt73usb.c
index d89db266757c..7caa3639dadf 100644
--- a/drivers/net/wireless/rt2x00/rt73usb.c
+++ b/drivers/net/wireless/rt2x00/rt73usb.c
@@ -52,6 +52,7 @@
52 * between each attampt. When the busy bit is still set at that time, 52 * between each attampt. When the busy bit is still set at that time,
53 * the access attempt is considered to have failed, 53 * the access attempt is considered to have failed,
54 * and we will print an error. 54 * and we will print an error.
55 * The _lock versions must be used if you already hold the usb_cache_mutex
55 */ 56 */
56static inline void rt73usb_register_read(struct rt2x00_dev *rt2x00dev, 57static inline void rt73usb_register_read(struct rt2x00_dev *rt2x00dev,
57 const unsigned int offset, u32 *value) 58 const unsigned int offset, u32 *value)
@@ -63,6 +64,16 @@ static inline void rt73usb_register_read(struct rt2x00_dev *rt2x00dev,
63 *value = le32_to_cpu(reg); 64 *value = le32_to_cpu(reg);
64} 65}
65 66
67static inline void rt73usb_register_read_lock(struct rt2x00_dev *rt2x00dev,
68 const unsigned int offset, u32 *value)
69{
70 __le32 reg;
71 rt2x00usb_vendor_req_buff_lock(rt2x00dev, USB_MULTI_READ,
72 USB_VENDOR_REQUEST_IN, offset,
73 &reg, sizeof(u32), REGISTER_TIMEOUT);
74 *value = le32_to_cpu(reg);
75}
76
66static inline void rt73usb_register_multiread(struct rt2x00_dev *rt2x00dev, 77static inline void rt73usb_register_multiread(struct rt2x00_dev *rt2x00dev,
67 const unsigned int offset, 78 const unsigned int offset,
68 void *value, const u32 length) 79 void *value, const u32 length)
@@ -82,6 +93,15 @@ static inline void rt73usb_register_write(struct rt2x00_dev *rt2x00dev,
82 &reg, sizeof(u32), REGISTER_TIMEOUT); 93 &reg, sizeof(u32), REGISTER_TIMEOUT);
83} 94}
84 95
96static inline void rt73usb_register_write_lock(struct rt2x00_dev *rt2x00dev,
97 const unsigned int offset, u32 value)
98{
99 __le32 reg = cpu_to_le32(value);
100 rt2x00usb_vendor_req_buff_lock(rt2x00dev, USB_MULTI_WRITE,
101 USB_VENDOR_REQUEST_OUT, offset,
102 &reg, sizeof(u32), REGISTER_TIMEOUT);
103}
104
85static inline void rt73usb_register_multiwrite(struct rt2x00_dev *rt2x00dev, 105static inline void rt73usb_register_multiwrite(struct rt2x00_dev *rt2x00dev,
86 const unsigned int offset, 106 const unsigned int offset,
87 void *value, const u32 length) 107 void *value, const u32 length)
@@ -98,7 +118,7 @@ static u32 rt73usb_bbp_check(struct rt2x00_dev *rt2x00dev)
98 unsigned int i; 118 unsigned int i;
99 119
100 for (i = 0; i < REGISTER_BUSY_COUNT; i++) { 120 for (i = 0; i < REGISTER_BUSY_COUNT; i++) {
101 rt73usb_register_read(rt2x00dev, PHY_CSR3, &reg); 121 rt73usb_register_read_lock(rt2x00dev, PHY_CSR3, &reg);
102 if (!rt2x00_get_field32(reg, PHY_CSR3_BUSY)) 122 if (!rt2x00_get_field32(reg, PHY_CSR3_BUSY))
103 break; 123 break;
104 udelay(REGISTER_BUSY_DELAY); 124 udelay(REGISTER_BUSY_DELAY);
@@ -112,12 +132,15 @@ static void rt73usb_bbp_write(struct rt2x00_dev *rt2x00dev,
112{ 132{
113 u32 reg; 133 u32 reg;
114 134
135 mutex_lock(&rt2x00dev->usb_cache_mutex);
136
115 /* 137 /*
116 * Wait until the BBP becomes ready. 138 * Wait until the BBP becomes ready.
117 */ 139 */
118 reg = rt73usb_bbp_check(rt2x00dev); 140 reg = rt73usb_bbp_check(rt2x00dev);
119 if (rt2x00_get_field32(reg, PHY_CSR3_BUSY)) { 141 if (rt2x00_get_field32(reg, PHY_CSR3_BUSY)) {
120 ERROR(rt2x00dev, "PHY_CSR3 register busy. Write failed.\n"); 142 ERROR(rt2x00dev, "PHY_CSR3 register busy. Write failed.\n");
143 mutex_unlock(&rt2x00dev->usb_cache_mutex);
121 return; 144 return;
122 } 145 }
123 146
@@ -130,7 +153,8 @@ static void rt73usb_bbp_write(struct rt2x00_dev *rt2x00dev,
130 rt2x00_set_field32(&reg, PHY_CSR3_BUSY, 1); 153 rt2x00_set_field32(&reg, PHY_CSR3_BUSY, 1);
131 rt2x00_set_field32(&reg, PHY_CSR3_READ_CONTROL, 0); 154 rt2x00_set_field32(&reg, PHY_CSR3_READ_CONTROL, 0);
132 155
133 rt73usb_register_write(rt2x00dev, PHY_CSR3, reg); 156 rt73usb_register_write_lock(rt2x00dev, PHY_CSR3, reg);
157 mutex_unlock(&rt2x00dev->usb_cache_mutex);
134} 158}
135 159
136static void rt73usb_bbp_read(struct rt2x00_dev *rt2x00dev, 160static void rt73usb_bbp_read(struct rt2x00_dev *rt2x00dev,
@@ -138,12 +162,15 @@ static void rt73usb_bbp_read(struct rt2x00_dev *rt2x00dev,
138{ 162{
139 u32 reg; 163 u32 reg;
140 164
165 mutex_lock(&rt2x00dev->usb_cache_mutex);
166
141 /* 167 /*
142 * Wait until the BBP becomes ready. 168 * Wait until the BBP becomes ready.
143 */ 169 */
144 reg = rt73usb_bbp_check(rt2x00dev); 170 reg = rt73usb_bbp_check(rt2x00dev);
145 if (rt2x00_get_field32(reg, PHY_CSR3_BUSY)) { 171 if (rt2x00_get_field32(reg, PHY_CSR3_BUSY)) {
146 ERROR(rt2x00dev, "PHY_CSR3 register busy. Read failed.\n"); 172 ERROR(rt2x00dev, "PHY_CSR3 register busy. Read failed.\n");
173 mutex_unlock(&rt2x00dev->usb_cache_mutex);
147 return; 174 return;
148 } 175 }
149 176
@@ -155,7 +182,7 @@ static void rt73usb_bbp_read(struct rt2x00_dev *rt2x00dev,
155 rt2x00_set_field32(&reg, PHY_CSR3_BUSY, 1); 182 rt2x00_set_field32(&reg, PHY_CSR3_BUSY, 1);
156 rt2x00_set_field32(&reg, PHY_CSR3_READ_CONTROL, 1); 183 rt2x00_set_field32(&reg, PHY_CSR3_READ_CONTROL, 1);
157 184
158 rt73usb_register_write(rt2x00dev, PHY_CSR3, reg); 185 rt73usb_register_write_lock(rt2x00dev, PHY_CSR3, reg);
159 186
160 /* 187 /*
161 * Wait until the BBP becomes ready. 188 * Wait until the BBP becomes ready.
@@ -168,6 +195,7 @@ static void rt73usb_bbp_read(struct rt2x00_dev *rt2x00dev,
168 } 195 }
169 196
170 *value = rt2x00_get_field32(reg, PHY_CSR3_VALUE); 197 *value = rt2x00_get_field32(reg, PHY_CSR3_VALUE);
198 mutex_unlock(&rt2x00dev->usb_cache_mutex);
171} 199}
172 200
173static void rt73usb_rf_write(struct rt2x00_dev *rt2x00dev, 201static void rt73usb_rf_write(struct rt2x00_dev *rt2x00dev,
@@ -179,13 +207,16 @@ static void rt73usb_rf_write(struct rt2x00_dev *rt2x00dev,
179 if (!word) 207 if (!word)
180 return; 208 return;
181 209
210 mutex_lock(&rt2x00dev->usb_cache_mutex);
211
182 for (i = 0; i < REGISTER_BUSY_COUNT; i++) { 212 for (i = 0; i < REGISTER_BUSY_COUNT; i++) {
183 rt73usb_register_read(rt2x00dev, PHY_CSR4, &reg); 213 rt73usb_register_read_lock(rt2x00dev, PHY_CSR4, &reg);
184 if (!rt2x00_get_field32(reg, PHY_CSR4_BUSY)) 214 if (!rt2x00_get_field32(reg, PHY_CSR4_BUSY))
185 goto rf_write; 215 goto rf_write;
186 udelay(REGISTER_BUSY_DELAY); 216 udelay(REGISTER_BUSY_DELAY);
187 } 217 }
188 218
219 mutex_unlock(&rt2x00dev->usb_cache_mutex);
189 ERROR(rt2x00dev, "PHY_CSR4 register busy. Write failed.\n"); 220 ERROR(rt2x00dev, "PHY_CSR4 register busy. Write failed.\n");
190 return; 221 return;
191 222
@@ -203,8 +234,9 @@ rf_write:
203 rt2x00_set_field32(&reg, PHY_CSR4_IF_SELECT, 0); 234 rt2x00_set_field32(&reg, PHY_CSR4_IF_SELECT, 0);
204 rt2x00_set_field32(&reg, PHY_CSR4_BUSY, 1); 235 rt2x00_set_field32(&reg, PHY_CSR4_BUSY, 1);
205 236
206 rt73usb_register_write(rt2x00dev, PHY_CSR4, reg); 237 rt73usb_register_write_lock(rt2x00dev, PHY_CSR4, reg);
207 rt2x00_rf_write(rt2x00dev, word, value); 238 rt2x00_rf_write(rt2x00dev, word, value);
239 mutex_unlock(&rt2x00dev->usb_cache_mutex);
208} 240}
209 241
210#ifdef CONFIG_RT2X00_LIB_DEBUGFS 242#ifdef CONFIG_RT2X00_LIB_DEBUGFS