aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/net/wireless/rt2x00/rt2400pci.c
diff options
context:
space:
mode:
authorIvo van Doorn <ivdoorn@gmail.com>2008-11-09 17:40:46 -0500
committerJohn W. Linville <linville@tuxdriver.com>2008-11-21 11:08:16 -0500
commit8ff48a8bbe4a1ba29dea2836dfce74660f97c1be (patch)
tree611c0e996813c59c229694b52d329c24829b80e8 /drivers/net/wireless/rt2x00/rt2400pci.c
parentbad13639a30e1557fbe9d440adc1906673c9de4e (diff)
rt2x00: Fix race condition when using inderect registers
Indirect registers require multiple calls to the CSR register in order to access the indirect registers. This must be protected under a lock to prevent race conditions which could cause invalid data to be returned when reading from the indirect register or silent failures when writing data to the indirect register. USB drivers where already protected under a mutex, so rename the mutex and make PCI drivers use the mutex as well. This now means that BBP and RF registers are no longer accessible in interrupt context. That is not a bad situation since the slow behavior of accessing those registers means we don't _want_ to access them in interrupt context either. Signed-off-by: Ivo van Doorn <IvDoorn@gmail.com> Signed-off-by: John W. Linville <linville@tuxdriver.com>
Diffstat (limited to 'drivers/net/wireless/rt2x00/rt2400pci.c')
-rw-r--r--drivers/net/wireless/rt2x00/rt2400pci.c47
1 files changed, 34 insertions, 13 deletions
diff --git a/drivers/net/wireless/rt2x00/rt2400pci.c b/drivers/net/wireless/rt2x00/rt2400pci.c
index 9bda3889539c..78fca1bcc544 100644
--- a/drivers/net/wireless/rt2x00/rt2400pci.c
+++ b/drivers/net/wireless/rt2x00/rt2400pci.c
@@ -69,14 +69,14 @@ static void rt2400pci_bbp_write(struct rt2x00_dev *rt2x00dev,
69{ 69{
70 u32 reg; 70 u32 reg;
71 71
72 mutex_lock(&rt2x00dev->csr_mutex);
73
72 /* 74 /*
73 * Wait until the BBP becomes ready. 75 * Wait until the BBP becomes ready.
74 */ 76 */
75 reg = rt2400pci_bbp_check(rt2x00dev); 77 reg = rt2400pci_bbp_check(rt2x00dev);
76 if (rt2x00_get_field32(reg, BBPCSR_BUSY)) { 78 if (rt2x00_get_field32(reg, BBPCSR_BUSY))
77 ERROR(rt2x00dev, "BBPCSR register busy. Write failed.\n"); 79 goto exit_fail;
78 return;
79 }
80 80
81 /* 81 /*
82 * Write the data into the BBP. 82 * Write the data into the BBP.
@@ -88,6 +88,15 @@ static void rt2400pci_bbp_write(struct rt2x00_dev *rt2x00dev,
88 rt2x00_set_field32(&reg, BBPCSR_WRITE_CONTROL, 1); 88 rt2x00_set_field32(&reg, BBPCSR_WRITE_CONTROL, 1);
89 89
90 rt2x00pci_register_write(rt2x00dev, BBPCSR, reg); 90 rt2x00pci_register_write(rt2x00dev, BBPCSR, reg);
91
92 mutex_unlock(&rt2x00dev->csr_mutex);
93
94 return;
95
96exit_fail:
97 mutex_unlock(&rt2x00dev->csr_mutex);
98
99 ERROR(rt2x00dev, "BBPCSR register busy. Write failed.\n");
91} 100}
92 101
93static void rt2400pci_bbp_read(struct rt2x00_dev *rt2x00dev, 102static void rt2400pci_bbp_read(struct rt2x00_dev *rt2x00dev,
@@ -95,14 +104,14 @@ static void rt2400pci_bbp_read(struct rt2x00_dev *rt2x00dev,
95{ 104{
96 u32 reg; 105 u32 reg;
97 106
107 mutex_lock(&rt2x00dev->csr_mutex);
108
98 /* 109 /*
99 * Wait until the BBP becomes ready. 110 * Wait until the BBP becomes ready.
100 */ 111 */
101 reg = rt2400pci_bbp_check(rt2x00dev); 112 reg = rt2400pci_bbp_check(rt2x00dev);
102 if (rt2x00_get_field32(reg, BBPCSR_BUSY)) { 113 if (rt2x00_get_field32(reg, BBPCSR_BUSY))
103 ERROR(rt2x00dev, "BBPCSR register busy. Read failed.\n"); 114 goto exit_fail;
104 return;
105 }
106 115
107 /* 116 /*
108 * Write the request into the BBP. 117 * Write the request into the BBP.
@@ -118,13 +127,20 @@ static void rt2400pci_bbp_read(struct rt2x00_dev *rt2x00dev,
118 * Wait until the BBP becomes ready. 127 * Wait until the BBP becomes ready.
119 */ 128 */
120 reg = rt2400pci_bbp_check(rt2x00dev); 129 reg = rt2400pci_bbp_check(rt2x00dev);
121 if (rt2x00_get_field32(reg, BBPCSR_BUSY)) { 130 if (rt2x00_get_field32(reg, BBPCSR_BUSY))
122 ERROR(rt2x00dev, "BBPCSR register busy. Read failed.\n"); 131 goto exit_fail;
123 *value = 0xff;
124 return;
125 }
126 132
127 *value = rt2x00_get_field32(reg, BBPCSR_VALUE); 133 *value = rt2x00_get_field32(reg, BBPCSR_VALUE);
134
135 mutex_unlock(&rt2x00dev->csr_mutex);
136
137 return;
138
139exit_fail:
140 mutex_unlock(&rt2x00dev->csr_mutex);
141
142 ERROR(rt2x00dev, "BBPCSR register busy. Read failed.\n");
143 *value = 0xff;
128} 144}
129 145
130static void rt2400pci_rf_write(struct rt2x00_dev *rt2x00dev, 146static void rt2400pci_rf_write(struct rt2x00_dev *rt2x00dev,
@@ -136,6 +152,8 @@ static void rt2400pci_rf_write(struct rt2x00_dev *rt2x00dev,
136 if (!word) 152 if (!word)
137 return; 153 return;
138 154
155 mutex_lock(&rt2x00dev->csr_mutex);
156
139 for (i = 0; i < REGISTER_BUSY_COUNT; i++) { 157 for (i = 0; i < REGISTER_BUSY_COUNT; i++) {
140 rt2x00pci_register_read(rt2x00dev, RFCSR, &reg); 158 rt2x00pci_register_read(rt2x00dev, RFCSR, &reg);
141 if (!rt2x00_get_field32(reg, RFCSR_BUSY)) 159 if (!rt2x00_get_field32(reg, RFCSR_BUSY))
@@ -143,6 +161,7 @@ static void rt2400pci_rf_write(struct rt2x00_dev *rt2x00dev,
143 udelay(REGISTER_BUSY_DELAY); 161 udelay(REGISTER_BUSY_DELAY);
144 } 162 }
145 163
164 mutex_unlock(&rt2x00dev->csr_mutex);
146 ERROR(rt2x00dev, "RFCSR register busy. Write failed.\n"); 165 ERROR(rt2x00dev, "RFCSR register busy. Write failed.\n");
147 return; 166 return;
148 167
@@ -155,6 +174,8 @@ rf_write:
155 174
156 rt2x00pci_register_write(rt2x00dev, RFCSR, reg); 175 rt2x00pci_register_write(rt2x00dev, RFCSR, reg);
157 rt2x00_rf_write(rt2x00dev, word, value); 176 rt2x00_rf_write(rt2x00dev, word, value);
177
178 mutex_unlock(&rt2x00dev->csr_mutex);
158} 179}
159 180
160static void rt2400pci_eepromregister_read(struct eeprom_93cx6 *eeprom) 181static void rt2400pci_eepromregister_read(struct eeprom_93cx6 *eeprom)