rt2400pci.c 47 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694
  1. /*
  2. Copyright (C) 2004 - 2007 rt2x00 SourceForge Project
  3. <http://rt2x00.serialmonkey.com>
  4. This program is free software; you can redistribute it and/or modify
  5. it under the terms of the GNU General Public License as published by
  6. the Free Software Foundation; either version 2 of the License, or
  7. (at your option) any later version.
  8. This program is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. GNU General Public License for more details.
  12. You should have received a copy of the GNU General Public License
  13. along with this program; if not, write to the
  14. Free Software Foundation, Inc.,
  15. 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  16. */
  17. /*
  18. Module: rt2400pci
  19. Abstract: rt2400pci device specific routines.
  20. Supported chipsets: RT2460.
  21. */
  22. /*
  23. * Set enviroment defines for rt2x00.h
  24. */
  25. #define DRV_NAME "rt2400pci"
  26. #include <linux/delay.h>
  27. #include <linux/etherdevice.h>
  28. #include <linux/init.h>
  29. #include <linux/kernel.h>
  30. #include <linux/module.h>
  31. #include <linux/pci.h>
  32. #include <linux/eeprom_93cx6.h>
  33. #include "rt2x00.h"
  34. #include "rt2x00pci.h"
  35. #include "rt2400pci.h"
  36. /*
  37. * Register access.
  38. * All access to the CSR registers will go through the methods
  39. * rt2x00pci_register_read and rt2x00pci_register_write.
  40. * BBP and RF register require indirect register access,
  41. * and use the CSR registers BBPCSR and RFCSR to achieve this.
  42. * These indirect registers work with busy bits,
  43. * and we will try maximal REGISTER_BUSY_COUNT times to access
  44. * the register while taking a REGISTER_BUSY_DELAY us delay
  45. * between each attampt. When the busy bit is still set at that time,
  46. * the access attempt is considered to have failed,
  47. * and we will print an error.
  48. */
  49. static u32 rt2400pci_bbp_check(const struct rt2x00_dev *rt2x00dev)
  50. {
  51. u32 reg;
  52. unsigned int i;
  53. for (i = 0; i < REGISTER_BUSY_COUNT; i++) {
  54. rt2x00pci_register_read(rt2x00dev, BBPCSR, &reg);
  55. if (!rt2x00_get_field32(reg, BBPCSR_BUSY))
  56. break;
  57. udelay(REGISTER_BUSY_DELAY);
  58. }
  59. return reg;
  60. }
  61. static void rt2400pci_bbp_write(const struct rt2x00_dev *rt2x00dev,
  62. const unsigned int word, const u8 value)
  63. {
  64. u32 reg;
  65. /*
  66. * Wait until the BBP becomes ready.
  67. */
  68. reg = rt2400pci_bbp_check(rt2x00dev);
  69. if (rt2x00_get_field32(reg, BBPCSR_BUSY)) {
  70. ERROR(rt2x00dev, "BBPCSR register busy. Write failed.\n");
  71. return;
  72. }
  73. /*
  74. * Write the data into the BBP.
  75. */
  76. reg = 0;
  77. rt2x00_set_field32(&reg, BBPCSR_VALUE, value);
  78. rt2x00_set_field32(&reg, BBPCSR_REGNUM, word);
  79. rt2x00_set_field32(&reg, BBPCSR_BUSY, 1);
  80. rt2x00_set_field32(&reg, BBPCSR_WRITE_CONTROL, 1);
  81. rt2x00pci_register_write(rt2x00dev, BBPCSR, reg);
  82. }
  83. static void rt2400pci_bbp_read(const struct rt2x00_dev *rt2x00dev,
  84. const unsigned int word, u8 *value)
  85. {
  86. u32 reg;
  87. /*
  88. * Wait until the BBP becomes ready.
  89. */
  90. reg = rt2400pci_bbp_check(rt2x00dev);
  91. if (rt2x00_get_field32(reg, BBPCSR_BUSY)) {
  92. ERROR(rt2x00dev, "BBPCSR register busy. Read failed.\n");
  93. return;
  94. }
  95. /*
  96. * Write the request into the BBP.
  97. */
  98. reg = 0;
  99. rt2x00_set_field32(&reg, BBPCSR_REGNUM, word);
  100. rt2x00_set_field32(&reg, BBPCSR_BUSY, 1);
  101. rt2x00_set_field32(&reg, BBPCSR_WRITE_CONTROL, 0);
  102. rt2x00pci_register_write(rt2x00dev, BBPCSR, reg);
  103. /*
  104. * Wait until the BBP becomes ready.
  105. */
  106. reg = rt2400pci_bbp_check(rt2x00dev);
  107. if (rt2x00_get_field32(reg, BBPCSR_BUSY)) {
  108. ERROR(rt2x00dev, "BBPCSR register busy. Read failed.\n");
  109. *value = 0xff;
  110. return;
  111. }
  112. *value = rt2x00_get_field32(reg, BBPCSR_VALUE);
  113. }
  114. static void rt2400pci_rf_write(const struct rt2x00_dev *rt2x00dev,
  115. const unsigned int word, const u32 value)
  116. {
  117. u32 reg;
  118. unsigned int i;
  119. if (!word)
  120. return;
  121. for (i = 0; i < REGISTER_BUSY_COUNT; i++) {
  122. rt2x00pci_register_read(rt2x00dev, RFCSR, &reg);
  123. if (!rt2x00_get_field32(reg, RFCSR_BUSY))
  124. goto rf_write;
  125. udelay(REGISTER_BUSY_DELAY);
  126. }
  127. ERROR(rt2x00dev, "RFCSR register busy. Write failed.\n");
  128. return;
  129. rf_write:
  130. reg = 0;
  131. rt2x00_set_field32(&reg, RFCSR_VALUE, value);
  132. rt2x00_set_field32(&reg, RFCSR_NUMBER_OF_BITS, 20);
  133. rt2x00_set_field32(&reg, RFCSR_IF_SELECT, 0);
  134. rt2x00_set_field32(&reg, RFCSR_BUSY, 1);
  135. rt2x00pci_register_write(rt2x00dev, RFCSR, reg);
  136. rt2x00_rf_write(rt2x00dev, word, value);
  137. }
  138. static void rt2400pci_eepromregister_read(struct eeprom_93cx6 *eeprom)
  139. {
  140. struct rt2x00_dev *rt2x00dev = eeprom->data;
  141. u32 reg;
  142. rt2x00pci_register_read(rt2x00dev, CSR21, &reg);
  143. eeprom->reg_data_in = !!rt2x00_get_field32(reg, CSR21_EEPROM_DATA_IN);
  144. eeprom->reg_data_out = !!rt2x00_get_field32(reg, CSR21_EEPROM_DATA_OUT);
  145. eeprom->reg_data_clock =
  146. !!rt2x00_get_field32(reg, CSR21_EEPROM_DATA_CLOCK);
  147. eeprom->reg_chip_select =
  148. !!rt2x00_get_field32(reg, CSR21_EEPROM_CHIP_SELECT);
  149. }
  150. static void rt2400pci_eepromregister_write(struct eeprom_93cx6 *eeprom)
  151. {
  152. struct rt2x00_dev *rt2x00dev = eeprom->data;
  153. u32 reg = 0;
  154. rt2x00_set_field32(&reg, CSR21_EEPROM_DATA_IN, !!eeprom->reg_data_in);
  155. rt2x00_set_field32(&reg, CSR21_EEPROM_DATA_OUT, !!eeprom->reg_data_out);
  156. rt2x00_set_field32(&reg, CSR21_EEPROM_DATA_CLOCK,
  157. !!eeprom->reg_data_clock);
  158. rt2x00_set_field32(&reg, CSR21_EEPROM_CHIP_SELECT,
  159. !!eeprom->reg_chip_select);
  160. rt2x00pci_register_write(rt2x00dev, CSR21, reg);
  161. }
  162. #ifdef CONFIG_RT2X00_LIB_DEBUGFS
  163. #define CSR_OFFSET(__word) ( CSR_REG_BASE + ((__word) * sizeof(u32)) )
  164. static void rt2400pci_read_csr(const struct rt2x00_dev *rt2x00dev,
  165. const unsigned int word, u32 *data)
  166. {
  167. rt2x00pci_register_read(rt2x00dev, CSR_OFFSET(word), data);
  168. }
  169. static void rt2400pci_write_csr(const struct rt2x00_dev *rt2x00dev,
  170. const unsigned int word, u32 data)
  171. {
  172. rt2x00pci_register_write(rt2x00dev, CSR_OFFSET(word), data);
  173. }
  174. static const struct rt2x00debug rt2400pci_rt2x00debug = {
  175. .owner = THIS_MODULE,
  176. .csr = {
  177. .read = rt2400pci_read_csr,
  178. .write = rt2400pci_write_csr,
  179. .word_size = sizeof(u32),
  180. .word_count = CSR_REG_SIZE / sizeof(u32),
  181. },
  182. .eeprom = {
  183. .read = rt2x00_eeprom_read,
  184. .write = rt2x00_eeprom_write,
  185. .word_size = sizeof(u16),
  186. .word_count = EEPROM_SIZE / sizeof(u16),
  187. },
  188. .bbp = {
  189. .read = rt2400pci_bbp_read,
  190. .write = rt2400pci_bbp_write,
  191. .word_size = sizeof(u8),
  192. .word_count = BBP_SIZE / sizeof(u8),
  193. },
  194. .rf = {
  195. .read = rt2x00_rf_read,
  196. .write = rt2400pci_rf_write,
  197. .word_size = sizeof(u32),
  198. .word_count = RF_SIZE / sizeof(u32),
  199. },
  200. };
  201. #endif /* CONFIG_RT2X00_LIB_DEBUGFS */
  202. #ifdef CONFIG_RT2400PCI_RFKILL
  203. static int rt2400pci_rfkill_poll(struct rt2x00_dev *rt2x00dev)
  204. {
  205. u32 reg;
  206. rt2x00pci_register_read(rt2x00dev, GPIOCSR, &reg);
  207. return rt2x00_get_field32(reg, GPIOCSR_BIT0);
  208. }
  209. #else
  210. #define rt2400pci_rfkill_poll NULL
  211. #endif /* CONFIG_RT2400PCI_RFKILL */
  212. /*
  213. * Configuration handlers.
  214. */
  215. static void rt2400pci_config_mac_addr(struct rt2x00_dev *rt2x00dev,
  216. __le32 *mac)
  217. {
  218. rt2x00pci_register_multiwrite(rt2x00dev, CSR3, mac,
  219. (2 * sizeof(__le32)));
  220. }
  221. static void rt2400pci_config_bssid(struct rt2x00_dev *rt2x00dev,
  222. __le32 *bssid)
  223. {
  224. rt2x00pci_register_multiwrite(rt2x00dev, CSR5, bssid,
  225. (2 * sizeof(__le32)));
  226. }
  227. static void rt2400pci_config_type(struct rt2x00_dev *rt2x00dev, int type)
  228. {
  229. struct interface *intf = &rt2x00dev->interface;
  230. u32 reg;
  231. rt2x00pci_register_write(rt2x00dev, CSR14, 0);
  232. /*
  233. * Enable beacon config
  234. */
  235. rt2x00pci_register_read(rt2x00dev, BCNCSR1, &reg);
  236. rt2x00_set_field32(&reg, BCNCSR1_PRELOAD,
  237. PREAMBLE + get_duration(IEEE80211_HEADER, 2));
  238. rt2x00pci_register_write(rt2x00dev, BCNCSR1, reg);
  239. /*
  240. * Enable synchronisation.
  241. */
  242. rt2x00pci_register_read(rt2x00dev, CSR14, &reg);
  243. rt2x00_set_field32(&reg, CSR14_TSF_COUNT, 1);
  244. rt2x00_set_field32(&reg, CSR14_TBCN, 1);
  245. rt2x00_set_field32(&reg, CSR14_BEACON_GEN, 0);
  246. if (is_interface_type(intf, IEEE80211_IF_TYPE_IBSS) ||
  247. is_interface_type(intf, IEEE80211_IF_TYPE_AP))
  248. rt2x00_set_field32(&reg, CSR14_TSF_SYNC, 2);
  249. else if (is_interface_type(intf, IEEE80211_IF_TYPE_STA))
  250. rt2x00_set_field32(&reg, CSR14_TSF_SYNC, 1);
  251. else
  252. rt2x00_set_field32(&reg, CSR14_TSF_SYNC, 0);
  253. rt2x00pci_register_write(rt2x00dev, CSR14, reg);
  254. }
  255. static void rt2400pci_config_rate(struct rt2x00_dev *rt2x00dev, const int rate)
  256. {
  257. struct ieee80211_conf *conf = &rt2x00dev->hw->conf;
  258. u32 reg;
  259. u32 preamble;
  260. u16 value;
  261. if (DEVICE_GET_RATE_FIELD(rate, PREAMBLE))
  262. preamble = SHORT_PREAMBLE;
  263. else
  264. preamble = PREAMBLE;
  265. reg = DEVICE_GET_RATE_FIELD(rate, RATEMASK) & DEV_BASIC_RATEMASK;
  266. rt2x00pci_register_write(rt2x00dev, ARCSR1, reg);
  267. rt2x00pci_register_read(rt2x00dev, TXCSR1, &reg);
  268. value = ((conf->flags & IEEE80211_CONF_SHORT_SLOT_TIME) ?
  269. SHORT_DIFS : DIFS) +
  270. PLCP + preamble + get_duration(ACK_SIZE, 10);
  271. rt2x00_set_field32(&reg, TXCSR1_ACK_TIMEOUT, value);
  272. value = SIFS + PLCP + preamble + get_duration(ACK_SIZE, 10);
  273. rt2x00_set_field32(&reg, TXCSR1_ACK_CONSUME_TIME, value);
  274. rt2x00pci_register_write(rt2x00dev, TXCSR1, reg);
  275. preamble = DEVICE_GET_RATE_FIELD(rate, PREAMBLE) ? 0x08 : 0x00;
  276. rt2x00pci_register_read(rt2x00dev, ARCSR2, &reg);
  277. rt2x00_set_field32(&reg, ARCSR2_SIGNAL, 0x00 | preamble);
  278. rt2x00_set_field32(&reg, ARCSR2_SERVICE, 0x04);
  279. rt2x00_set_field32(&reg, ARCSR2_LENGTH, get_duration(ACK_SIZE, 10));
  280. rt2x00pci_register_write(rt2x00dev, ARCSR2, reg);
  281. rt2x00pci_register_read(rt2x00dev, ARCSR3, &reg);
  282. rt2x00_set_field32(&reg, ARCSR3_SIGNAL, 0x01 | preamble);
  283. rt2x00_set_field32(&reg, ARCSR3_SERVICE, 0x04);
  284. rt2x00_set_field32(&reg, ARCSR2_LENGTH, get_duration(ACK_SIZE, 20));
  285. rt2x00pci_register_write(rt2x00dev, ARCSR3, reg);
  286. rt2x00pci_register_read(rt2x00dev, ARCSR4, &reg);
  287. rt2x00_set_field32(&reg, ARCSR4_SIGNAL, 0x02 | preamble);
  288. rt2x00_set_field32(&reg, ARCSR4_SERVICE, 0x04);
  289. rt2x00_set_field32(&reg, ARCSR2_LENGTH, get_duration(ACK_SIZE, 55));
  290. rt2x00pci_register_write(rt2x00dev, ARCSR4, reg);
  291. rt2x00pci_register_read(rt2x00dev, ARCSR5, &reg);
  292. rt2x00_set_field32(&reg, ARCSR5_SIGNAL, 0x03 | preamble);
  293. rt2x00_set_field32(&reg, ARCSR5_SERVICE, 0x84);
  294. rt2x00_set_field32(&reg, ARCSR2_LENGTH, get_duration(ACK_SIZE, 110));
  295. rt2x00pci_register_write(rt2x00dev, ARCSR5, reg);
  296. }
  297. static void rt2400pci_config_phymode(struct rt2x00_dev *rt2x00dev,
  298. const int phymode)
  299. {
  300. struct ieee80211_hw_mode *mode;
  301. struct ieee80211_rate *rate;
  302. rt2x00dev->curr_hwmode = HWMODE_B;
  303. mode = &rt2x00dev->hwmodes[rt2x00dev->curr_hwmode];
  304. rate = &mode->rates[mode->num_rates - 1];
  305. rt2400pci_config_rate(rt2x00dev, rate->val2);
  306. }
  307. static void rt2400pci_config_channel(struct rt2x00_dev *rt2x00dev,
  308. const int index, const int channel)
  309. {
  310. struct rf_channel reg;
  311. /*
  312. * Fill rf_reg structure.
  313. */
  314. memcpy(&reg, &rt2x00dev->spec.channels[index], sizeof(reg));
  315. /*
  316. * Switch on tuning bits.
  317. */
  318. rt2x00_set_field32(&reg.rf1, RF1_TUNER, 1);
  319. rt2x00_set_field32(&reg.rf3, RF3_TUNER, 1);
  320. rt2400pci_rf_write(rt2x00dev, 1, reg.rf1);
  321. rt2400pci_rf_write(rt2x00dev, 2, reg.rf2);
  322. rt2400pci_rf_write(rt2x00dev, 3, reg.rf3);
  323. /*
  324. * RF2420 chipset don't need any additional actions.
  325. */
  326. if (rt2x00_rf(&rt2x00dev->chip, RF2420))
  327. return;
  328. /*
  329. * For the RT2421 chipsets we need to write an invalid
  330. * reference clock rate to activate auto_tune.
  331. * After that we set the value back to the correct channel.
  332. */
  333. rt2400pci_rf_write(rt2x00dev, 1, reg.rf1);
  334. rt2400pci_rf_write(rt2x00dev, 2, 0x000c2a32);
  335. rt2400pci_rf_write(rt2x00dev, 3, reg.rf3);
  336. msleep(1);
  337. rt2400pci_rf_write(rt2x00dev, 1, reg.rf1);
  338. rt2400pci_rf_write(rt2x00dev, 2, reg.rf2);
  339. rt2400pci_rf_write(rt2x00dev, 3, reg.rf3);
  340. msleep(1);
  341. /*
  342. * Switch off tuning bits.
  343. */
  344. rt2x00_set_field32(&reg.rf1, RF1_TUNER, 0);
  345. rt2x00_set_field32(&reg.rf3, RF3_TUNER, 0);
  346. rt2400pci_rf_write(rt2x00dev, 1, reg.rf1);
  347. rt2400pci_rf_write(rt2x00dev, 3, reg.rf3);
  348. /*
  349. * Clear false CRC during channel switch.
  350. */
  351. rt2x00pci_register_read(rt2x00dev, CNT0, &reg.rf1);
  352. }
  353. static void rt2400pci_config_txpower(struct rt2x00_dev *rt2x00dev, int txpower)
  354. {
  355. rt2400pci_bbp_write(rt2x00dev, 3, TXPOWER_TO_DEV(txpower));
  356. }
  357. static void rt2400pci_config_antenna(struct rt2x00_dev *rt2x00dev,
  358. int antenna_tx, int antenna_rx)
  359. {
  360. u8 r1;
  361. u8 r4;
  362. rt2400pci_bbp_read(rt2x00dev, 4, &r4);
  363. rt2400pci_bbp_read(rt2x00dev, 1, &r1);
  364. /*
  365. * Configure the TX antenna.
  366. */
  367. switch (antenna_tx) {
  368. case ANTENNA_SW_DIVERSITY:
  369. case ANTENNA_HW_DIVERSITY:
  370. rt2x00_set_field8(&r1, BBP_R1_TX_ANTENNA, 1);
  371. break;
  372. case ANTENNA_A:
  373. rt2x00_set_field8(&r1, BBP_R1_TX_ANTENNA, 0);
  374. break;
  375. case ANTENNA_B:
  376. rt2x00_set_field8(&r1, BBP_R1_TX_ANTENNA, 2);
  377. break;
  378. }
  379. /*
  380. * Configure the RX antenna.
  381. */
  382. switch (antenna_rx) {
  383. case ANTENNA_SW_DIVERSITY:
  384. case ANTENNA_HW_DIVERSITY:
  385. rt2x00_set_field8(&r4, BBP_R4_RX_ANTENNA, 1);
  386. break;
  387. case ANTENNA_A:
  388. rt2x00_set_field8(&r4, BBP_R4_RX_ANTENNA, 0);
  389. break;
  390. case ANTENNA_B:
  391. rt2x00_set_field8(&r4, BBP_R4_RX_ANTENNA, 2);
  392. break;
  393. }
  394. rt2400pci_bbp_write(rt2x00dev, 4, r4);
  395. rt2400pci_bbp_write(rt2x00dev, 1, r1);
  396. }
  397. static void rt2400pci_config_duration(struct rt2x00_dev *rt2x00dev,
  398. int short_slot_time, int beacon_int)
  399. {
  400. u32 reg;
  401. rt2x00pci_register_read(rt2x00dev, CSR11, &reg);
  402. rt2x00_set_field32(&reg, CSR11_SLOT_TIME,
  403. short_slot_time ? SHORT_SLOT_TIME : SLOT_TIME);
  404. rt2x00pci_register_write(rt2x00dev, CSR11, reg);
  405. rt2x00pci_register_read(rt2x00dev, CSR18, &reg);
  406. rt2x00_set_field32(&reg, CSR18_SIFS, SIFS);
  407. rt2x00_set_field32(&reg, CSR18_PIFS,
  408. short_slot_time ? SHORT_PIFS : PIFS);
  409. rt2x00pci_register_write(rt2x00dev, CSR18, reg);
  410. rt2x00pci_register_read(rt2x00dev, CSR19, &reg);
  411. rt2x00_set_field32(&reg, CSR19_DIFS,
  412. short_slot_time ? SHORT_DIFS : DIFS);
  413. rt2x00_set_field32(&reg, CSR19_EIFS, EIFS);
  414. rt2x00pci_register_write(rt2x00dev, CSR19, reg);
  415. rt2x00pci_register_read(rt2x00dev, TXCSR1, &reg);
  416. rt2x00_set_field32(&reg, TXCSR1_TSF_OFFSET, IEEE80211_HEADER);
  417. rt2x00_set_field32(&reg, TXCSR1_AUTORESPONDER, 1);
  418. rt2x00pci_register_write(rt2x00dev, TXCSR1, reg);
  419. rt2x00pci_register_read(rt2x00dev, CSR12, &reg);
  420. rt2x00_set_field32(&reg, CSR12_BEACON_INTERVAL, beacon_int * 16);
  421. rt2x00_set_field32(&reg, CSR12_CFP_MAX_DURATION, beacon_int * 16);
  422. rt2x00pci_register_write(rt2x00dev, CSR12, reg);
  423. }
  424. static void rt2400pci_config(struct rt2x00_dev *rt2x00dev,
  425. const unsigned int flags,
  426. struct ieee80211_conf *conf)
  427. {
  428. int short_slot_time = conf->flags & IEEE80211_CONF_SHORT_SLOT_TIME;
  429. if (flags & CONFIG_UPDATE_PHYMODE)
  430. rt2400pci_config_phymode(rt2x00dev, conf->phymode);
  431. if (flags & CONFIG_UPDATE_CHANNEL)
  432. rt2400pci_config_channel(rt2x00dev, conf->channel_val,
  433. conf->channel);
  434. if (flags & CONFIG_UPDATE_TXPOWER)
  435. rt2400pci_config_txpower(rt2x00dev, conf->power_level);
  436. if (flags & CONFIG_UPDATE_ANTENNA)
  437. rt2400pci_config_antenna(rt2x00dev, conf->antenna_sel_tx,
  438. conf->antenna_sel_rx);
  439. if (flags & (CONFIG_UPDATE_SLOT_TIME | CONFIG_UPDATE_BEACON_INT))
  440. rt2400pci_config_duration(rt2x00dev, short_slot_time,
  441. conf->beacon_int);
  442. }
  443. static void rt2400pci_config_cw(struct rt2x00_dev *rt2x00dev,
  444. struct ieee80211_tx_queue_params *params)
  445. {
  446. u32 reg;
  447. rt2x00pci_register_read(rt2x00dev, CSR11, &reg);
  448. rt2x00_set_field32(&reg, CSR11_CWMIN, params->cw_min);
  449. rt2x00_set_field32(&reg, CSR11_CWMAX, params->cw_max);
  450. rt2x00pci_register_write(rt2x00dev, CSR11, reg);
  451. }
  452. /*
  453. * LED functions.
  454. */
  455. static void rt2400pci_enable_led(struct rt2x00_dev *rt2x00dev)
  456. {
  457. u32 reg;
  458. rt2x00pci_register_read(rt2x00dev, LEDCSR, &reg);
  459. rt2x00_set_field32(&reg, LEDCSR_ON_PERIOD, 70);
  460. rt2x00_set_field32(&reg, LEDCSR_OFF_PERIOD, 30);
  461. if (rt2x00dev->led_mode == LED_MODE_TXRX_ACTIVITY) {
  462. rt2x00_set_field32(&reg, LEDCSR_LINK, 1);
  463. rt2x00_set_field32(&reg, LEDCSR_ACTIVITY, 0);
  464. } else if (rt2x00dev->led_mode == LED_MODE_ASUS) {
  465. rt2x00_set_field32(&reg, LEDCSR_LINK, 0);
  466. rt2x00_set_field32(&reg, LEDCSR_ACTIVITY, 1);
  467. } else {
  468. rt2x00_set_field32(&reg, LEDCSR_LINK, 1);
  469. rt2x00_set_field32(&reg, LEDCSR_ACTIVITY, 1);
  470. }
  471. rt2x00pci_register_write(rt2x00dev, LEDCSR, reg);
  472. }
  473. static void rt2400pci_disable_led(struct rt2x00_dev *rt2x00dev)
  474. {
  475. u32 reg;
  476. rt2x00pci_register_read(rt2x00dev, LEDCSR, &reg);
  477. rt2x00_set_field32(&reg, LEDCSR_LINK, 0);
  478. rt2x00_set_field32(&reg, LEDCSR_ACTIVITY, 0);
  479. rt2x00pci_register_write(rt2x00dev, LEDCSR, reg);
  480. }
  481. /*
  482. * Link tuning
  483. */
  484. static void rt2400pci_link_stats(struct rt2x00_dev *rt2x00dev)
  485. {
  486. u32 reg;
  487. u8 bbp;
  488. /*
  489. * Update FCS error count from register.
  490. */
  491. rt2x00pci_register_read(rt2x00dev, CNT0, &reg);
  492. rt2x00dev->link.rx_failed = rt2x00_get_field32(reg, CNT0_FCS_ERROR);
  493. /*
  494. * Update False CCA count from register.
  495. */
  496. rt2400pci_bbp_read(rt2x00dev, 39, &bbp);
  497. rt2x00dev->link.false_cca = bbp;
  498. }
  499. static void rt2400pci_reset_tuner(struct rt2x00_dev *rt2x00dev)
  500. {
  501. rt2400pci_bbp_write(rt2x00dev, 13, 0x08);
  502. rt2x00dev->link.vgc_level = 0x08;
  503. }
  504. static void rt2400pci_link_tuner(struct rt2x00_dev *rt2x00dev)
  505. {
  506. u8 reg;
  507. /*
  508. * The link tuner should not run longer then 60 seconds,
  509. * and should run once every 2 seconds.
  510. */
  511. if (rt2x00dev->link.count > 60 || !(rt2x00dev->link.count & 1))
  512. return;
  513. /*
  514. * Base r13 link tuning on the false cca count.
  515. */
  516. rt2400pci_bbp_read(rt2x00dev, 13, &reg);
  517. if (rt2x00dev->link.false_cca > 512 && reg < 0x20) {
  518. rt2400pci_bbp_write(rt2x00dev, 13, ++reg);
  519. rt2x00dev->link.vgc_level = reg;
  520. } else if (rt2x00dev->link.false_cca < 100 && reg > 0x08) {
  521. rt2400pci_bbp_write(rt2x00dev, 13, --reg);
  522. rt2x00dev->link.vgc_level = reg;
  523. }
  524. }
  525. /*
  526. * Initialization functions.
  527. */
  528. static void rt2400pci_init_rxring(struct rt2x00_dev *rt2x00dev)
  529. {
  530. struct data_ring *ring = rt2x00dev->rx;
  531. struct data_desc *rxd;
  532. unsigned int i;
  533. u32 word;
  534. memset(ring->data_addr, 0x00, rt2x00_get_ring_size(ring));
  535. for (i = 0; i < ring->stats.limit; i++) {
  536. rxd = ring->entry[i].priv;
  537. rt2x00_desc_read(rxd, 2, &word);
  538. rt2x00_set_field32(&word, RXD_W2_BUFFER_LENGTH,
  539. ring->data_size);
  540. rt2x00_desc_write(rxd, 2, word);
  541. rt2x00_desc_read(rxd, 1, &word);
  542. rt2x00_set_field32(&word, RXD_W1_BUFFER_ADDRESS,
  543. ring->entry[i].data_dma);
  544. rt2x00_desc_write(rxd, 1, word);
  545. rt2x00_desc_read(rxd, 0, &word);
  546. rt2x00_set_field32(&word, RXD_W0_OWNER_NIC, 1);
  547. rt2x00_desc_write(rxd, 0, word);
  548. }
  549. rt2x00_ring_index_clear(rt2x00dev->rx);
  550. }
  551. static void rt2400pci_init_txring(struct rt2x00_dev *rt2x00dev, const int queue)
  552. {
  553. struct data_ring *ring = rt2x00lib_get_ring(rt2x00dev, queue);
  554. struct data_desc *txd;
  555. unsigned int i;
  556. u32 word;
  557. memset(ring->data_addr, 0x00, rt2x00_get_ring_size(ring));
  558. for (i = 0; i < ring->stats.limit; i++) {
  559. txd = ring->entry[i].priv;
  560. rt2x00_desc_read(txd, 1, &word);
  561. rt2x00_set_field32(&word, TXD_W1_BUFFER_ADDRESS,
  562. ring->entry[i].data_dma);
  563. rt2x00_desc_write(txd, 1, word);
  564. rt2x00_desc_read(txd, 2, &word);
  565. rt2x00_set_field32(&word, TXD_W2_BUFFER_LENGTH,
  566. ring->data_size);
  567. rt2x00_desc_write(txd, 2, word);
  568. rt2x00_desc_read(txd, 0, &word);
  569. rt2x00_set_field32(&word, TXD_W0_VALID, 0);
  570. rt2x00_set_field32(&word, TXD_W0_OWNER_NIC, 0);
  571. rt2x00_desc_write(txd, 0, word);
  572. }
  573. rt2x00_ring_index_clear(ring);
  574. }
  575. static int rt2400pci_init_rings(struct rt2x00_dev *rt2x00dev)
  576. {
  577. u32 reg;
  578. /*
  579. * Initialize rings.
  580. */
  581. rt2400pci_init_rxring(rt2x00dev);
  582. rt2400pci_init_txring(rt2x00dev, IEEE80211_TX_QUEUE_DATA0);
  583. rt2400pci_init_txring(rt2x00dev, IEEE80211_TX_QUEUE_DATA1);
  584. rt2400pci_init_txring(rt2x00dev, IEEE80211_TX_QUEUE_AFTER_BEACON);
  585. rt2400pci_init_txring(rt2x00dev, IEEE80211_TX_QUEUE_BEACON);
  586. /*
  587. * Initialize registers.
  588. */
  589. rt2x00pci_register_read(rt2x00dev, TXCSR2, &reg);
  590. rt2x00_set_field32(&reg, TXCSR2_TXD_SIZE,
  591. rt2x00dev->tx[IEEE80211_TX_QUEUE_DATA0].desc_size);
  592. rt2x00_set_field32(&reg, TXCSR2_NUM_TXD,
  593. rt2x00dev->tx[IEEE80211_TX_QUEUE_DATA1].stats.limit);
  594. rt2x00_set_field32(&reg, TXCSR2_NUM_ATIM,
  595. rt2x00dev->bcn[1].stats.limit);
  596. rt2x00_set_field32(&reg, TXCSR2_NUM_PRIO,
  597. rt2x00dev->tx[IEEE80211_TX_QUEUE_DATA0].stats.limit);
  598. rt2x00pci_register_write(rt2x00dev, TXCSR2, reg);
  599. rt2x00pci_register_read(rt2x00dev, TXCSR3, &reg);
  600. rt2x00_set_field32(&reg, TXCSR3_TX_RING_REGISTER,
  601. rt2x00dev->tx[IEEE80211_TX_QUEUE_DATA1].data_dma);
  602. rt2x00pci_register_write(rt2x00dev, TXCSR3, reg);
  603. rt2x00pci_register_read(rt2x00dev, TXCSR5, &reg);
  604. rt2x00_set_field32(&reg, TXCSR5_PRIO_RING_REGISTER,
  605. rt2x00dev->tx[IEEE80211_TX_QUEUE_DATA0].data_dma);
  606. rt2x00pci_register_write(rt2x00dev, TXCSR5, reg);
  607. rt2x00pci_register_read(rt2x00dev, TXCSR4, &reg);
  608. rt2x00_set_field32(&reg, TXCSR4_ATIM_RING_REGISTER,
  609. rt2x00dev->bcn[1].data_dma);
  610. rt2x00pci_register_write(rt2x00dev, TXCSR4, reg);
  611. rt2x00pci_register_read(rt2x00dev, TXCSR6, &reg);
  612. rt2x00_set_field32(&reg, TXCSR6_BEACON_RING_REGISTER,
  613. rt2x00dev->bcn[0].data_dma);
  614. rt2x00pci_register_write(rt2x00dev, TXCSR6, reg);
  615. rt2x00pci_register_read(rt2x00dev, RXCSR1, &reg);
  616. rt2x00_set_field32(&reg, RXCSR1_RXD_SIZE, rt2x00dev->rx->desc_size);
  617. rt2x00_set_field32(&reg, RXCSR1_NUM_RXD, rt2x00dev->rx->stats.limit);
  618. rt2x00pci_register_write(rt2x00dev, RXCSR1, reg);
  619. rt2x00pci_register_read(rt2x00dev, RXCSR2, &reg);
  620. rt2x00_set_field32(&reg, RXCSR2_RX_RING_REGISTER,
  621. rt2x00dev->rx->data_dma);
  622. rt2x00pci_register_write(rt2x00dev, RXCSR2, reg);
  623. return 0;
  624. }
  625. static int rt2400pci_init_registers(struct rt2x00_dev *rt2x00dev)
  626. {
  627. u32 reg;
  628. rt2x00pci_register_write(rt2x00dev, PSCSR0, 0x00020002);
  629. rt2x00pci_register_write(rt2x00dev, PSCSR1, 0x00000002);
  630. rt2x00pci_register_write(rt2x00dev, PSCSR2, 0x00023f20);
  631. rt2x00pci_register_write(rt2x00dev, PSCSR3, 0x00000002);
  632. rt2x00pci_register_read(rt2x00dev, TIMECSR, &reg);
  633. rt2x00_set_field32(&reg, TIMECSR_US_COUNT, 33);
  634. rt2x00_set_field32(&reg, TIMECSR_US_64_COUNT, 63);
  635. rt2x00_set_field32(&reg, TIMECSR_BEACON_EXPECT, 0);
  636. rt2x00pci_register_write(rt2x00dev, TIMECSR, reg);
  637. rt2x00pci_register_read(rt2x00dev, CSR9, &reg);
  638. rt2x00_set_field32(&reg, CSR9_MAX_FRAME_UNIT,
  639. (rt2x00dev->rx->data_size / 128));
  640. rt2x00pci_register_write(rt2x00dev, CSR9, reg);
  641. rt2x00pci_register_write(rt2x00dev, CNT3, 0x3f080000);
  642. rt2x00pci_register_read(rt2x00dev, ARCSR0, &reg);
  643. rt2x00_set_field32(&reg, ARCSR0_AR_BBP_DATA0, 133);
  644. rt2x00_set_field32(&reg, ARCSR0_AR_BBP_ID0, 134);
  645. rt2x00_set_field32(&reg, ARCSR0_AR_BBP_DATA1, 136);
  646. rt2x00_set_field32(&reg, ARCSR0_AR_BBP_ID1, 135);
  647. rt2x00pci_register_write(rt2x00dev, ARCSR0, reg);
  648. rt2x00pci_register_read(rt2x00dev, RXCSR3, &reg);
  649. rt2x00_set_field32(&reg, RXCSR3_BBP_ID0, 3); /* Tx power.*/
  650. rt2x00_set_field32(&reg, RXCSR3_BBP_ID0_VALID, 1);
  651. rt2x00_set_field32(&reg, RXCSR3_BBP_ID1, 32); /* Signal */
  652. rt2x00_set_field32(&reg, RXCSR3_BBP_ID1_VALID, 1);
  653. rt2x00_set_field32(&reg, RXCSR3_BBP_ID2, 36); /* Rssi */
  654. rt2x00_set_field32(&reg, RXCSR3_BBP_ID2_VALID, 1);
  655. rt2x00pci_register_write(rt2x00dev, RXCSR3, reg);
  656. rt2x00pci_register_write(rt2x00dev, PWRCSR0, 0x3f3b3100);
  657. if (rt2x00dev->ops->lib->set_device_state(rt2x00dev, STATE_AWAKE))
  658. return -EBUSY;
  659. rt2x00pci_register_write(rt2x00dev, MACCSR0, 0x00217223);
  660. rt2x00pci_register_write(rt2x00dev, MACCSR1, 0x00235518);
  661. rt2x00pci_register_read(rt2x00dev, MACCSR2, &reg);
  662. rt2x00_set_field32(&reg, MACCSR2_DELAY, 64);
  663. rt2x00pci_register_write(rt2x00dev, MACCSR2, reg);
  664. rt2x00pci_register_read(rt2x00dev, RALINKCSR, &reg);
  665. rt2x00_set_field32(&reg, RALINKCSR_AR_BBP_DATA0, 17);
  666. rt2x00_set_field32(&reg, RALINKCSR_AR_BBP_ID0, 154);
  667. rt2x00_set_field32(&reg, RALINKCSR_AR_BBP_DATA1, 0);
  668. rt2x00_set_field32(&reg, RALINKCSR_AR_BBP_ID1, 154);
  669. rt2x00pci_register_write(rt2x00dev, RALINKCSR, reg);
  670. rt2x00pci_register_read(rt2x00dev, CSR1, &reg);
  671. rt2x00_set_field32(&reg, CSR1_SOFT_RESET, 1);
  672. rt2x00_set_field32(&reg, CSR1_BBP_RESET, 0);
  673. rt2x00_set_field32(&reg, CSR1_HOST_READY, 0);
  674. rt2x00pci_register_write(rt2x00dev, CSR1, reg);
  675. rt2x00pci_register_read(rt2x00dev, CSR1, &reg);
  676. rt2x00_set_field32(&reg, CSR1_SOFT_RESET, 0);
  677. rt2x00_set_field32(&reg, CSR1_HOST_READY, 1);
  678. rt2x00pci_register_write(rt2x00dev, CSR1, reg);
  679. /*
  680. * We must clear the FCS and FIFO error count.
  681. * These registers are cleared on read,
  682. * so we may pass a useless variable to store the value.
  683. */
  684. rt2x00pci_register_read(rt2x00dev, CNT0, &reg);
  685. rt2x00pci_register_read(rt2x00dev, CNT4, &reg);
  686. return 0;
  687. }
  688. static int rt2400pci_init_bbp(struct rt2x00_dev *rt2x00dev)
  689. {
  690. unsigned int i;
  691. u16 eeprom;
  692. u8 reg_id;
  693. u8 value;
  694. for (i = 0; i < REGISTER_BUSY_COUNT; i++) {
  695. rt2400pci_bbp_read(rt2x00dev, 0, &value);
  696. if ((value != 0xff) && (value != 0x00))
  697. goto continue_csr_init;
  698. NOTICE(rt2x00dev, "Waiting for BBP register.\n");
  699. udelay(REGISTER_BUSY_DELAY);
  700. }
  701. ERROR(rt2x00dev, "BBP register access failed, aborting.\n");
  702. return -EACCES;
  703. continue_csr_init:
  704. rt2400pci_bbp_write(rt2x00dev, 1, 0x00);
  705. rt2400pci_bbp_write(rt2x00dev, 3, 0x27);
  706. rt2400pci_bbp_write(rt2x00dev, 4, 0x08);
  707. rt2400pci_bbp_write(rt2x00dev, 10, 0x0f);
  708. rt2400pci_bbp_write(rt2x00dev, 15, 0x72);
  709. rt2400pci_bbp_write(rt2x00dev, 16, 0x74);
  710. rt2400pci_bbp_write(rt2x00dev, 17, 0x20);
  711. rt2400pci_bbp_write(rt2x00dev, 18, 0x72);
  712. rt2400pci_bbp_write(rt2x00dev, 19, 0x0b);
  713. rt2400pci_bbp_write(rt2x00dev, 20, 0x00);
  714. rt2400pci_bbp_write(rt2x00dev, 28, 0x11);
  715. rt2400pci_bbp_write(rt2x00dev, 29, 0x04);
  716. rt2400pci_bbp_write(rt2x00dev, 30, 0x21);
  717. rt2400pci_bbp_write(rt2x00dev, 31, 0x00);
  718. DEBUG(rt2x00dev, "Start initialization from EEPROM...\n");
  719. for (i = 0; i < EEPROM_BBP_SIZE; i++) {
  720. rt2x00_eeprom_read(rt2x00dev, EEPROM_BBP_START + i, &eeprom);
  721. if (eeprom != 0xffff && eeprom != 0x0000) {
  722. reg_id = rt2x00_get_field16(eeprom, EEPROM_BBP_REG_ID);
  723. value = rt2x00_get_field16(eeprom, EEPROM_BBP_VALUE);
  724. DEBUG(rt2x00dev, "BBP: 0x%02x, value: 0x%02x.\n",
  725. reg_id, value);
  726. rt2400pci_bbp_write(rt2x00dev, reg_id, value);
  727. }
  728. }
  729. DEBUG(rt2x00dev, "...End initialization from EEPROM.\n");
  730. return 0;
  731. }
  732. /*
  733. * Device state switch handlers.
  734. */
  735. static void rt2400pci_toggle_rx(struct rt2x00_dev *rt2x00dev,
  736. enum dev_state state)
  737. {
  738. u32 reg;
  739. rt2x00pci_register_read(rt2x00dev, RXCSR0, &reg);
  740. rt2x00_set_field32(&reg, RXCSR0_DISABLE_RX,
  741. state == STATE_RADIO_RX_OFF);
  742. rt2x00pci_register_write(rt2x00dev, RXCSR0, reg);
  743. }
  744. static void rt2400pci_toggle_irq(struct rt2x00_dev *rt2x00dev,
  745. enum dev_state state)
  746. {
  747. int mask = (state == STATE_RADIO_IRQ_OFF);
  748. u32 reg;
  749. /*
  750. * When interrupts are being enabled, the interrupt registers
  751. * should clear the register to assure a clean state.
  752. */
  753. if (state == STATE_RADIO_IRQ_ON) {
  754. rt2x00pci_register_read(rt2x00dev, CSR7, &reg);
  755. rt2x00pci_register_write(rt2x00dev, CSR7, reg);
  756. }
  757. /*
  758. * Only toggle the interrupts bits we are going to use.
  759. * Non-checked interrupt bits are disabled by default.
  760. */
  761. rt2x00pci_register_read(rt2x00dev, CSR8, &reg);
  762. rt2x00_set_field32(&reg, CSR8_TBCN_EXPIRE, mask);
  763. rt2x00_set_field32(&reg, CSR8_TXDONE_TXRING, mask);
  764. rt2x00_set_field32(&reg, CSR8_TXDONE_ATIMRING, mask);
  765. rt2x00_set_field32(&reg, CSR8_TXDONE_PRIORING, mask);
  766. rt2x00_set_field32(&reg, CSR8_RXDONE, mask);
  767. rt2x00pci_register_write(rt2x00dev, CSR8, reg);
  768. }
  769. static int rt2400pci_enable_radio(struct rt2x00_dev *rt2x00dev)
  770. {
  771. /*
  772. * Initialize all registers.
  773. */
  774. if (rt2400pci_init_rings(rt2x00dev) ||
  775. rt2400pci_init_registers(rt2x00dev) ||
  776. rt2400pci_init_bbp(rt2x00dev)) {
  777. ERROR(rt2x00dev, "Register initialization failed.\n");
  778. return -EIO;
  779. }
  780. /*
  781. * Enable interrupts.
  782. */
  783. rt2400pci_toggle_irq(rt2x00dev, STATE_RADIO_IRQ_ON);
  784. /*
  785. * Enable LED
  786. */
  787. rt2400pci_enable_led(rt2x00dev);
  788. return 0;
  789. }
  790. static void rt2400pci_disable_radio(struct rt2x00_dev *rt2x00dev)
  791. {
  792. u32 reg;
  793. /*
  794. * Disable LED
  795. */
  796. rt2400pci_disable_led(rt2x00dev);
  797. rt2x00pci_register_write(rt2x00dev, PWRCSR0, 0);
  798. /*
  799. * Disable synchronisation.
  800. */
  801. rt2x00pci_register_write(rt2x00dev, CSR14, 0);
  802. /*
  803. * Cancel RX and TX.
  804. */
  805. rt2x00pci_register_read(rt2x00dev, TXCSR0, &reg);
  806. rt2x00_set_field32(&reg, TXCSR0_ABORT, 1);
  807. rt2x00pci_register_write(rt2x00dev, TXCSR0, reg);
  808. /*
  809. * Disable interrupts.
  810. */
  811. rt2400pci_toggle_irq(rt2x00dev, STATE_RADIO_IRQ_OFF);
  812. }
  813. static int rt2400pci_set_state(struct rt2x00_dev *rt2x00dev,
  814. enum dev_state state)
  815. {
  816. u32 reg;
  817. unsigned int i;
  818. char put_to_sleep;
  819. char bbp_state;
  820. char rf_state;
  821. put_to_sleep = (state != STATE_AWAKE);
  822. rt2x00pci_register_read(rt2x00dev, PWRCSR1, &reg);
  823. rt2x00_set_field32(&reg, PWRCSR1_SET_STATE, 1);
  824. rt2x00_set_field32(&reg, PWRCSR1_BBP_DESIRE_STATE, state);
  825. rt2x00_set_field32(&reg, PWRCSR1_RF_DESIRE_STATE, state);
  826. rt2x00_set_field32(&reg, PWRCSR1_PUT_TO_SLEEP, put_to_sleep);
  827. rt2x00pci_register_write(rt2x00dev, PWRCSR1, reg);
  828. /*
  829. * Device is not guaranteed to be in the requested state yet.
  830. * We must wait until the register indicates that the
  831. * device has entered the correct state.
  832. */
  833. for (i = 0; i < REGISTER_BUSY_COUNT; i++) {
  834. rt2x00pci_register_read(rt2x00dev, PWRCSR1, &reg);
  835. bbp_state = rt2x00_get_field32(reg, PWRCSR1_BBP_CURR_STATE);
  836. rf_state = rt2x00_get_field32(reg, PWRCSR1_RF_CURR_STATE);
  837. if (bbp_state == state && rf_state == state)
  838. return 0;
  839. msleep(10);
  840. }
  841. NOTICE(rt2x00dev, "Device failed to enter state %d, "
  842. "current device state: bbp %d and rf %d.\n",
  843. state, bbp_state, rf_state);
  844. return -EBUSY;
  845. }
  846. static int rt2400pci_set_device_state(struct rt2x00_dev *rt2x00dev,
  847. enum dev_state state)
  848. {
  849. int retval = 0;
  850. switch (state) {
  851. case STATE_RADIO_ON:
  852. retval = rt2400pci_enable_radio(rt2x00dev);
  853. break;
  854. case STATE_RADIO_OFF:
  855. rt2400pci_disable_radio(rt2x00dev);
  856. break;
  857. case STATE_RADIO_RX_ON:
  858. case STATE_RADIO_RX_OFF:
  859. rt2400pci_toggle_rx(rt2x00dev, state);
  860. break;
  861. case STATE_DEEP_SLEEP:
  862. case STATE_SLEEP:
  863. case STATE_STANDBY:
  864. case STATE_AWAKE:
  865. retval = rt2400pci_set_state(rt2x00dev, state);
  866. break;
  867. default:
  868. retval = -ENOTSUPP;
  869. break;
  870. }
  871. return retval;
  872. }
  873. /*
  874. * TX descriptor initialization
  875. */
  876. static void rt2400pci_write_tx_desc(struct rt2x00_dev *rt2x00dev,
  877. struct data_desc *txd,
  878. struct txdata_entry_desc *desc,
  879. struct ieee80211_hdr *ieee80211hdr,
  880. unsigned int length,
  881. struct ieee80211_tx_control *control)
  882. {
  883. u32 word;
  884. u32 signal = 0;
  885. u32 service = 0;
  886. u32 length_high = 0;
  887. u32 length_low = 0;
  888. /*
  889. * The PLCP values should be treated as if they
  890. * were BBP values.
  891. */
  892. rt2x00_set_field32(&signal, BBPCSR_VALUE, desc->signal);
  893. rt2x00_set_field32(&signal, BBPCSR_REGNUM, 5);
  894. rt2x00_set_field32(&signal, BBPCSR_BUSY, 1);
  895. rt2x00_set_field32(&service, BBPCSR_VALUE, desc->service);
  896. rt2x00_set_field32(&service, BBPCSR_REGNUM, 6);
  897. rt2x00_set_field32(&service, BBPCSR_BUSY, 1);
  898. rt2x00_set_field32(&length_high, BBPCSR_VALUE, desc->length_high);
  899. rt2x00_set_field32(&length_high, BBPCSR_REGNUM, 7);
  900. rt2x00_set_field32(&length_high, BBPCSR_BUSY, 1);
  901. rt2x00_set_field32(&length_low, BBPCSR_VALUE, desc->length_low);
  902. rt2x00_set_field32(&length_low, BBPCSR_REGNUM, 8);
  903. rt2x00_set_field32(&length_low, BBPCSR_BUSY, 1);
  904. /*
  905. * Start writing the descriptor words.
  906. */
  907. rt2x00_desc_read(txd, 2, &word);
  908. rt2x00_set_field32(&word, TXD_W2_DATABYTE_COUNT, length);
  909. rt2x00_desc_write(txd, 2, word);
  910. rt2x00_desc_read(txd, 3, &word);
  911. rt2x00_set_field32(&word, TXD_W3_PLCP_SIGNAL, signal);
  912. rt2x00_set_field32(&word, TXD_W3_PLCP_SERVICE, service);
  913. rt2x00_desc_write(txd, 3, word);
  914. rt2x00_desc_read(txd, 4, &word);
  915. rt2x00_set_field32(&word, TXD_W4_PLCP_LENGTH_LOW, length_low);
  916. rt2x00_set_field32(&word, TXD_W4_PLCP_LENGTH_HIGH, length_high);
  917. rt2x00_desc_write(txd, 4, word);
  918. rt2x00_desc_read(txd, 0, &word);
  919. rt2x00_set_field32(&word, TXD_W0_OWNER_NIC, 1);
  920. rt2x00_set_field32(&word, TXD_W0_VALID, 1);
  921. rt2x00_set_field32(&word, TXD_W0_MORE_FRAG,
  922. test_bit(ENTRY_TXD_MORE_FRAG, &desc->flags));
  923. rt2x00_set_field32(&word, TXD_W0_ACK,
  924. !(control->flags & IEEE80211_TXCTL_NO_ACK));
  925. rt2x00_set_field32(&word, TXD_W0_TIMESTAMP,
  926. test_bit(ENTRY_TXD_REQ_TIMESTAMP, &desc->flags));
  927. rt2x00_set_field32(&word, TXD_W0_RTS,
  928. test_bit(ENTRY_TXD_RTS_FRAME, &desc->flags));
  929. rt2x00_set_field32(&word, TXD_W0_IFS, desc->ifs);
  930. rt2x00_set_field32(&word, TXD_W0_RETRY_MODE,
  931. !!(control->flags &
  932. IEEE80211_TXCTL_LONG_RETRY_LIMIT));
  933. rt2x00_desc_write(txd, 0, word);
  934. }
  935. /*
  936. * TX data initialization
  937. */
  938. static void rt2400pci_kick_tx_queue(struct rt2x00_dev *rt2x00dev,
  939. unsigned int queue)
  940. {
  941. u32 reg;
  942. if (queue == IEEE80211_TX_QUEUE_BEACON) {
  943. rt2x00pci_register_read(rt2x00dev, CSR14, &reg);
  944. if (!rt2x00_get_field32(reg, CSR14_BEACON_GEN)) {
  945. rt2x00_set_field32(&reg, CSR14_BEACON_GEN, 1);
  946. rt2x00pci_register_write(rt2x00dev, CSR14, reg);
  947. }
  948. return;
  949. }
  950. rt2x00pci_register_read(rt2x00dev, TXCSR0, &reg);
  951. if (queue == IEEE80211_TX_QUEUE_DATA0)
  952. rt2x00_set_field32(&reg, TXCSR0_KICK_PRIO, 1);
  953. else if (queue == IEEE80211_TX_QUEUE_DATA1)
  954. rt2x00_set_field32(&reg, TXCSR0_KICK_TX, 1);
  955. else if (queue == IEEE80211_TX_QUEUE_AFTER_BEACON)
  956. rt2x00_set_field32(&reg, TXCSR0_KICK_ATIM, 1);
  957. rt2x00pci_register_write(rt2x00dev, TXCSR0, reg);
  958. }
  959. /*
  960. * RX control handlers
  961. */
  962. static void rt2400pci_fill_rxdone(struct data_entry *entry,
  963. struct rxdata_entry_desc *desc)
  964. {
  965. struct data_desc *rxd = entry->priv;
  966. u32 word0;
  967. u32 word2;
  968. rt2x00_desc_read(rxd, 0, &word0);
  969. rt2x00_desc_read(rxd, 2, &word2);
  970. desc->flags = 0;
  971. if (rt2x00_get_field32(word0, RXD_W0_CRC_ERROR))
  972. desc->flags |= RX_FLAG_FAILED_FCS_CRC;
  973. if (rt2x00_get_field32(word0, RXD_W0_PHYSICAL_ERROR))
  974. desc->flags |= RX_FLAG_FAILED_PLCP_CRC;
  975. /*
  976. * Obtain the status about this packet.
  977. */
  978. desc->signal = rt2x00_get_field32(word2, RXD_W2_SIGNAL);
  979. desc->rssi = rt2x00_get_field32(word2, RXD_W2_RSSI) -
  980. entry->ring->rt2x00dev->rssi_offset;
  981. desc->ofdm = 0;
  982. desc->size = rt2x00_get_field32(word0, RXD_W0_DATABYTE_COUNT);
  983. }
  984. /*
  985. * Interrupt functions.
  986. */
  987. static void rt2400pci_txdone(struct rt2x00_dev *rt2x00dev, const int queue)
  988. {
  989. struct data_ring *ring = rt2x00lib_get_ring(rt2x00dev, queue);
  990. struct data_entry *entry;
  991. struct data_desc *txd;
  992. u32 word;
  993. int tx_status;
  994. int retry;
  995. while (!rt2x00_ring_empty(ring)) {
  996. entry = rt2x00_get_data_entry_done(ring);
  997. txd = entry->priv;
  998. rt2x00_desc_read(txd, 0, &word);
  999. if (rt2x00_get_field32(word, TXD_W0_OWNER_NIC) ||
  1000. !rt2x00_get_field32(word, TXD_W0_VALID))
  1001. break;
  1002. /*
  1003. * Obtain the status about this packet.
  1004. */
  1005. tx_status = rt2x00_get_field32(word, TXD_W0_RESULT);
  1006. retry = rt2x00_get_field32(word, TXD_W0_RETRY_COUNT);
  1007. rt2x00lib_txdone(entry, tx_status, retry);
  1008. /*
  1009. * Make this entry available for reuse.
  1010. */
  1011. entry->flags = 0;
  1012. rt2x00_set_field32(&word, TXD_W0_VALID, 0);
  1013. rt2x00_desc_write(txd, 0, word);
  1014. rt2x00_ring_index_done_inc(ring);
  1015. }
  1016. /*
  1017. * If the data ring was full before the txdone handler
  1018. * we must make sure the packet queue in the mac80211 stack
  1019. * is reenabled when the txdone handler has finished.
  1020. */
  1021. entry = ring->entry;
  1022. if (!rt2x00_ring_full(ring))
  1023. ieee80211_wake_queue(rt2x00dev->hw,
  1024. entry->tx_status.control.queue);
  1025. }
  1026. static irqreturn_t rt2400pci_interrupt(int irq, void *dev_instance)
  1027. {
  1028. struct rt2x00_dev *rt2x00dev = dev_instance;
  1029. u32 reg;
  1030. /*
  1031. * Get the interrupt sources & saved to local variable.
  1032. * Write register value back to clear pending interrupts.
  1033. */
  1034. rt2x00pci_register_read(rt2x00dev, CSR7, &reg);
  1035. rt2x00pci_register_write(rt2x00dev, CSR7, reg);
  1036. if (!reg)
  1037. return IRQ_NONE;
  1038. if (!test_bit(DEVICE_ENABLED_RADIO, &rt2x00dev->flags))
  1039. return IRQ_HANDLED;
  1040. /*
  1041. * Handle interrupts, walk through all bits
  1042. * and run the tasks, the bits are checked in order of
  1043. * priority.
  1044. */
  1045. /*
  1046. * 1 - Beacon timer expired interrupt.
  1047. */
  1048. if (rt2x00_get_field32(reg, CSR7_TBCN_EXPIRE))
  1049. rt2x00lib_beacondone(rt2x00dev);
  1050. /*
  1051. * 2 - Rx ring done interrupt.
  1052. */
  1053. if (rt2x00_get_field32(reg, CSR7_RXDONE))
  1054. rt2x00pci_rxdone(rt2x00dev);
  1055. /*
  1056. * 3 - Atim ring transmit done interrupt.
  1057. */
  1058. if (rt2x00_get_field32(reg, CSR7_TXDONE_ATIMRING))
  1059. rt2400pci_txdone(rt2x00dev, IEEE80211_TX_QUEUE_AFTER_BEACON);
  1060. /*
  1061. * 4 - Priority ring transmit done interrupt.
  1062. */
  1063. if (rt2x00_get_field32(reg, CSR7_TXDONE_PRIORING))
  1064. rt2400pci_txdone(rt2x00dev, IEEE80211_TX_QUEUE_DATA0);
  1065. /*
  1066. * 5 - Tx ring transmit done interrupt.
  1067. */
  1068. if (rt2x00_get_field32(reg, CSR7_TXDONE_TXRING))
  1069. rt2400pci_txdone(rt2x00dev, IEEE80211_TX_QUEUE_DATA1);
  1070. return IRQ_HANDLED;
  1071. }
  1072. /*
  1073. * Device probe functions.
  1074. */
  1075. static int rt2400pci_validate_eeprom(struct rt2x00_dev *rt2x00dev)
  1076. {
  1077. struct eeprom_93cx6 eeprom;
  1078. u32 reg;
  1079. u16 word;
  1080. u8 *mac;
  1081. rt2x00pci_register_read(rt2x00dev, CSR21, &reg);
  1082. eeprom.data = rt2x00dev;
  1083. eeprom.register_read = rt2400pci_eepromregister_read;
  1084. eeprom.register_write = rt2400pci_eepromregister_write;
  1085. eeprom.width = rt2x00_get_field32(reg, CSR21_TYPE_93C46) ?
  1086. PCI_EEPROM_WIDTH_93C46 : PCI_EEPROM_WIDTH_93C66;
  1087. eeprom.reg_data_in = 0;
  1088. eeprom.reg_data_out = 0;
  1089. eeprom.reg_data_clock = 0;
  1090. eeprom.reg_chip_select = 0;
  1091. eeprom_93cx6_multiread(&eeprom, EEPROM_BASE, rt2x00dev->eeprom,
  1092. EEPROM_SIZE / sizeof(u16));
  1093. /*
  1094. * Start validation of the data that has been read.
  1095. */
  1096. mac = rt2x00_eeprom_addr(rt2x00dev, EEPROM_MAC_ADDR_0);
  1097. if (!is_valid_ether_addr(mac)) {
  1098. DECLARE_MAC_BUF(macbuf);
  1099. random_ether_addr(mac);
  1100. EEPROM(rt2x00dev, "MAC: %s\n", print_mac(macbuf, mac));
  1101. }
  1102. rt2x00_eeprom_read(rt2x00dev, EEPROM_ANTENNA, &word);
  1103. if (word == 0xffff) {
  1104. ERROR(rt2x00dev, "Invalid EEPROM data detected.\n");
  1105. return -EINVAL;
  1106. }
  1107. return 0;
  1108. }
  1109. static int rt2400pci_init_eeprom(struct rt2x00_dev *rt2x00dev)
  1110. {
  1111. u32 reg;
  1112. u16 value;
  1113. u16 eeprom;
  1114. /*
  1115. * Read EEPROM word for configuration.
  1116. */
  1117. rt2x00_eeprom_read(rt2x00dev, EEPROM_ANTENNA, &eeprom);
  1118. /*
  1119. * Identify RF chipset.
  1120. */
  1121. value = rt2x00_get_field16(eeprom, EEPROM_ANTENNA_RF_TYPE);
  1122. rt2x00pci_register_read(rt2x00dev, CSR0, &reg);
  1123. rt2x00_set_chip(rt2x00dev, RT2460, value, reg);
  1124. if (!rt2x00_rf(&rt2x00dev->chip, RF2420) &&
  1125. !rt2x00_rf(&rt2x00dev->chip, RF2421)) {
  1126. ERROR(rt2x00dev, "Invalid RF chipset detected.\n");
  1127. return -ENODEV;
  1128. }
  1129. /*
  1130. * Identify default antenna configuration.
  1131. */
  1132. rt2x00dev->hw->conf.antenna_sel_tx =
  1133. rt2x00_get_field16(eeprom, EEPROM_ANTENNA_TX_DEFAULT);
  1134. rt2x00dev->hw->conf.antenna_sel_rx =
  1135. rt2x00_get_field16(eeprom, EEPROM_ANTENNA_RX_DEFAULT);
  1136. /*
  1137. * Store led mode, for correct led behaviour.
  1138. */
  1139. rt2x00dev->led_mode =
  1140. rt2x00_get_field16(eeprom, EEPROM_ANTENNA_LED_MODE);
  1141. /*
  1142. * Detect if this device has an hardware controlled radio.
  1143. */
  1144. #ifdef CONFIG_RT2400PCI_RFKILL
  1145. if (rt2x00_get_field16(eeprom, EEPROM_ANTENNA_HARDWARE_RADIO))
  1146. __set_bit(CONFIG_SUPPORT_HW_BUTTON, &rt2x00dev->flags);
  1147. #endif /* CONFIG_RT2400PCI_RFKILL */
  1148. /*
  1149. * Check if the BBP tuning should be enabled.
  1150. */
  1151. if (!rt2x00_get_field16(eeprom, EEPROM_ANTENNA_RX_AGCVGC_TUNING))
  1152. __set_bit(CONFIG_DISABLE_LINK_TUNING, &rt2x00dev->flags);
  1153. return 0;
  1154. }
  1155. /*
  1156. * RF value list for RF2420 & RF2421
  1157. * Supports: 2.4 GHz
  1158. */
  1159. static const struct rf_channel rf_vals_bg[] = {
  1160. { 1, 0x00022058, 0x000c1fda, 0x00000101, 0 },
  1161. { 2, 0x00022058, 0x000c1fee, 0x00000101, 0 },
  1162. { 3, 0x00022058, 0x000c2002, 0x00000101, 0 },
  1163. { 4, 0x00022058, 0x000c2016, 0x00000101, 0 },
  1164. { 5, 0x00022058, 0x000c202a, 0x00000101, 0 },
  1165. { 6, 0x00022058, 0x000c203e, 0x00000101, 0 },
  1166. { 7, 0x00022058, 0x000c2052, 0x00000101, 0 },
  1167. { 8, 0x00022058, 0x000c2066, 0x00000101, 0 },
  1168. { 9, 0x00022058, 0x000c207a, 0x00000101, 0 },
  1169. { 10, 0x00022058, 0x000c208e, 0x00000101, 0 },
  1170. { 11, 0x00022058, 0x000c20a2, 0x00000101, 0 },
  1171. { 12, 0x00022058, 0x000c20b6, 0x00000101, 0 },
  1172. { 13, 0x00022058, 0x000c20ca, 0x00000101, 0 },
  1173. { 14, 0x00022058, 0x000c20fa, 0x00000101, 0 },
  1174. };
  1175. static void rt2400pci_probe_hw_mode(struct rt2x00_dev *rt2x00dev)
  1176. {
  1177. struct hw_mode_spec *spec = &rt2x00dev->spec;
  1178. u8 *txpower;
  1179. unsigned int i;
  1180. /*
  1181. * Initialize all hw fields.
  1182. */
  1183. rt2x00dev->hw->flags = IEEE80211_HW_HOST_BROADCAST_PS_BUFFERING;
  1184. rt2x00dev->hw->extra_tx_headroom = 0;
  1185. rt2x00dev->hw->max_signal = MAX_SIGNAL;
  1186. rt2x00dev->hw->max_rssi = MAX_RX_SSI;
  1187. rt2x00dev->hw->queues = 2;
  1188. SET_IEEE80211_DEV(rt2x00dev->hw, &rt2x00dev_pci(rt2x00dev)->dev);
  1189. SET_IEEE80211_PERM_ADDR(rt2x00dev->hw,
  1190. rt2x00_eeprom_addr(rt2x00dev,
  1191. EEPROM_MAC_ADDR_0));
  1192. /*
  1193. * Convert tx_power array in eeprom.
  1194. */
  1195. txpower = rt2x00_eeprom_addr(rt2x00dev, EEPROM_TXPOWER_START);
  1196. for (i = 0; i < 14; i++)
  1197. txpower[i] = TXPOWER_FROM_DEV(txpower[i]);
  1198. /*
  1199. * Initialize hw_mode information.
  1200. */
  1201. spec->num_modes = 1;
  1202. spec->num_rates = 4;
  1203. spec->tx_power_a = NULL;
  1204. spec->tx_power_bg = txpower;
  1205. spec->tx_power_default = DEFAULT_TXPOWER;
  1206. spec->num_channels = ARRAY_SIZE(rf_vals_bg);
  1207. spec->channels = rf_vals_bg;
  1208. }
  1209. static int rt2400pci_probe_hw(struct rt2x00_dev *rt2x00dev)
  1210. {
  1211. int retval;
  1212. /*
  1213. * Allocate eeprom data.
  1214. */
  1215. retval = rt2400pci_validate_eeprom(rt2x00dev);
  1216. if (retval)
  1217. return retval;
  1218. retval = rt2400pci_init_eeprom(rt2x00dev);
  1219. if (retval)
  1220. return retval;
  1221. /*
  1222. * Initialize hw specifications.
  1223. */
  1224. rt2400pci_probe_hw_mode(rt2x00dev);
  1225. /*
  1226. * This device requires the beacon ring
  1227. */
  1228. __set_bit(DRIVER_REQUIRE_BEACON_RING, &rt2x00dev->flags);
  1229. /*
  1230. * Set the rssi offset.
  1231. */
  1232. rt2x00dev->rssi_offset = DEFAULT_RSSI_OFFSET;
  1233. return 0;
  1234. }
  1235. /*
  1236. * IEEE80211 stack callback functions.
  1237. */
  1238. static void rt2400pci_configure_filter(struct ieee80211_hw *hw,
  1239. unsigned int changed_flags,
  1240. unsigned int *total_flags,
  1241. int mc_count,
  1242. struct dev_addr_list *mc_list)
  1243. {
  1244. struct rt2x00_dev *rt2x00dev = hw->priv;
  1245. struct interface *intf = &rt2x00dev->interface;
  1246. u32 reg;
  1247. /*
  1248. * Mask off any flags we are going to ignore from
  1249. * the total_flags field.
  1250. */
  1251. *total_flags &=
  1252. FIF_ALLMULTI |
  1253. FIF_FCSFAIL |
  1254. FIF_PLCPFAIL |
  1255. FIF_CONTROL |
  1256. FIF_OTHER_BSS |
  1257. FIF_PROMISC_IN_BSS;
  1258. /*
  1259. * Apply some rules to the filters:
  1260. * - Some filters imply different filters to be set.
  1261. * - Some things we can't filter out at all.
  1262. * - Some filters are set based on interface type.
  1263. */
  1264. *total_flags |= FIF_ALLMULTI;
  1265. if (*total_flags & FIF_OTHER_BSS ||
  1266. *total_flags & FIF_PROMISC_IN_BSS)
  1267. *total_flags |= FIF_PROMISC_IN_BSS | FIF_OTHER_BSS;
  1268. if (is_interface_type(intf, IEEE80211_IF_TYPE_AP))
  1269. *total_flags |= FIF_PROMISC_IN_BSS;
  1270. /*
  1271. * Check if there is any work left for us.
  1272. */
  1273. if (intf->filter == *total_flags)
  1274. return;
  1275. intf->filter = *total_flags;
  1276. /*
  1277. * Start configuration steps.
  1278. * Note that the version error will always be dropped
  1279. * since there is no filter for it at this time.
  1280. */
  1281. rt2x00pci_register_read(rt2x00dev, RXCSR0, &reg);
  1282. rt2x00_set_field32(&reg, RXCSR0_DROP_CRC,
  1283. !(*total_flags & FIF_FCSFAIL));
  1284. rt2x00_set_field32(&reg, RXCSR0_DROP_PHYSICAL,
  1285. !(*total_flags & FIF_PLCPFAIL));
  1286. rt2x00_set_field32(&reg, RXCSR0_DROP_CONTROL,
  1287. !(*total_flags & FIF_CONTROL));
  1288. rt2x00_set_field32(&reg, RXCSR0_DROP_NOT_TO_ME,
  1289. !(*total_flags & FIF_PROMISC_IN_BSS));
  1290. rt2x00_set_field32(&reg, RXCSR0_DROP_TODS,
  1291. !(*total_flags & FIF_PROMISC_IN_BSS));
  1292. rt2x00_set_field32(&reg, RXCSR0_DROP_VERSION_ERROR, 1);
  1293. rt2x00pci_register_write(rt2x00dev, RXCSR0, reg);
  1294. }
  1295. static int rt2400pci_set_retry_limit(struct ieee80211_hw *hw,
  1296. u32 short_retry, u32 long_retry)
  1297. {
  1298. struct rt2x00_dev *rt2x00dev = hw->priv;
  1299. u32 reg;
  1300. rt2x00pci_register_read(rt2x00dev, CSR11, &reg);
  1301. rt2x00_set_field32(&reg, CSR11_LONG_RETRY, long_retry);
  1302. rt2x00_set_field32(&reg, CSR11_SHORT_RETRY, short_retry);
  1303. rt2x00pci_register_write(rt2x00dev, CSR11, reg);
  1304. return 0;
  1305. }
  1306. static int rt2400pci_conf_tx(struct ieee80211_hw *hw,
  1307. int queue,
  1308. const struct ieee80211_tx_queue_params *params)
  1309. {
  1310. struct rt2x00_dev *rt2x00dev = hw->priv;
  1311. /*
  1312. * We don't support variating cw_min and cw_max variables
  1313. * per queue. So by default we only configure the TX queue,
  1314. * and ignore all other configurations.
  1315. */
  1316. if (queue != IEEE80211_TX_QUEUE_DATA0)
  1317. return -EINVAL;
  1318. if (rt2x00mac_conf_tx(hw, queue, params))
  1319. return -EINVAL;
  1320. /*
  1321. * Write configuration to register.
  1322. */
  1323. rt2400pci_config_cw(rt2x00dev, &rt2x00dev->tx->tx_params);
  1324. return 0;
  1325. }
  1326. static u64 rt2400pci_get_tsf(struct ieee80211_hw *hw)
  1327. {
  1328. struct rt2x00_dev *rt2x00dev = hw->priv;
  1329. u64 tsf;
  1330. u32 reg;
  1331. rt2x00pci_register_read(rt2x00dev, CSR17, &reg);
  1332. tsf = (u64) rt2x00_get_field32(reg, CSR17_HIGH_TSFTIMER) << 32;
  1333. rt2x00pci_register_read(rt2x00dev, CSR16, &reg);
  1334. tsf |= rt2x00_get_field32(reg, CSR16_LOW_TSFTIMER);
  1335. return tsf;
  1336. }
  1337. static void rt2400pci_reset_tsf(struct ieee80211_hw *hw)
  1338. {
  1339. struct rt2x00_dev *rt2x00dev = hw->priv;
  1340. rt2x00pci_register_write(rt2x00dev, CSR16, 0);
  1341. rt2x00pci_register_write(rt2x00dev, CSR17, 0);
  1342. }
  1343. static int rt2400pci_tx_last_beacon(struct ieee80211_hw *hw)
  1344. {
  1345. struct rt2x00_dev *rt2x00dev = hw->priv;
  1346. u32 reg;
  1347. rt2x00pci_register_read(rt2x00dev, CSR15, &reg);
  1348. return rt2x00_get_field32(reg, CSR15_BEACON_SENT);
  1349. }
  1350. static const struct ieee80211_ops rt2400pci_mac80211_ops = {
  1351. .tx = rt2x00mac_tx,
  1352. .start = rt2x00mac_start,
  1353. .stop = rt2x00mac_stop,
  1354. .add_interface = rt2x00mac_add_interface,
  1355. .remove_interface = rt2x00mac_remove_interface,
  1356. .config = rt2x00mac_config,
  1357. .config_interface = rt2x00mac_config_interface,
  1358. .configure_filter = rt2400pci_configure_filter,
  1359. .get_stats = rt2x00mac_get_stats,
  1360. .set_retry_limit = rt2400pci_set_retry_limit,
  1361. .conf_tx = rt2400pci_conf_tx,
  1362. .get_tx_stats = rt2x00mac_get_tx_stats,
  1363. .get_tsf = rt2400pci_get_tsf,
  1364. .reset_tsf = rt2400pci_reset_tsf,
  1365. .beacon_update = rt2x00pci_beacon_update,
  1366. .tx_last_beacon = rt2400pci_tx_last_beacon,
  1367. };
  1368. static const struct rt2x00lib_ops rt2400pci_rt2x00_ops = {
  1369. .irq_handler = rt2400pci_interrupt,
  1370. .probe_hw = rt2400pci_probe_hw,
  1371. .initialize = rt2x00pci_initialize,
  1372. .uninitialize = rt2x00pci_uninitialize,
  1373. .set_device_state = rt2400pci_set_device_state,
  1374. .rfkill_poll = rt2400pci_rfkill_poll,
  1375. .link_stats = rt2400pci_link_stats,
  1376. .reset_tuner = rt2400pci_reset_tuner,
  1377. .link_tuner = rt2400pci_link_tuner,
  1378. .write_tx_desc = rt2400pci_write_tx_desc,
  1379. .write_tx_data = rt2x00pci_write_tx_data,
  1380. .kick_tx_queue = rt2400pci_kick_tx_queue,
  1381. .fill_rxdone = rt2400pci_fill_rxdone,
  1382. .config_mac_addr = rt2400pci_config_mac_addr,
  1383. .config_bssid = rt2400pci_config_bssid,
  1384. .config_type = rt2400pci_config_type,
  1385. .config = rt2400pci_config,
  1386. };
  1387. static const struct rt2x00_ops rt2400pci_ops = {
  1388. .name = DRV_NAME,
  1389. .rxd_size = RXD_DESC_SIZE,
  1390. .txd_size = TXD_DESC_SIZE,
  1391. .eeprom_size = EEPROM_SIZE,
  1392. .rf_size = RF_SIZE,
  1393. .lib = &rt2400pci_rt2x00_ops,
  1394. .hw = &rt2400pci_mac80211_ops,
  1395. #ifdef CONFIG_RT2X00_LIB_DEBUGFS
  1396. .debugfs = &rt2400pci_rt2x00debug,
  1397. #endif /* CONFIG_RT2X00_LIB_DEBUGFS */
  1398. };
  1399. /*
  1400. * RT2400pci module information.
  1401. */
  1402. static struct pci_device_id rt2400pci_device_table[] = {
  1403. { PCI_DEVICE(0x1814, 0x0101), PCI_DEVICE_DATA(&rt2400pci_ops) },
  1404. { 0, }
  1405. };
  1406. MODULE_AUTHOR(DRV_PROJECT);
  1407. MODULE_VERSION(DRV_VERSION);
  1408. MODULE_DESCRIPTION("Ralink RT2400 PCI & PCMCIA Wireless LAN driver.");
  1409. MODULE_SUPPORTED_DEVICE("Ralink RT2460 PCI & PCMCIA chipset based cards");
  1410. MODULE_DEVICE_TABLE(pci, rt2400pci_device_table);
  1411. MODULE_LICENSE("GPL");
  1412. static struct pci_driver rt2400pci_driver = {
  1413. .name = DRV_NAME,
  1414. .id_table = rt2400pci_device_table,
  1415. .probe = rt2x00pci_probe,
  1416. .remove = __devexit_p(rt2x00pci_remove),
  1417. .suspend = rt2x00pci_suspend,
  1418. .resume = rt2x00pci_resume,
  1419. };
  1420. static int __init rt2400pci_init(void)
  1421. {
  1422. return pci_register_driver(&rt2400pci_driver);
  1423. }
  1424. static void __exit rt2400pci_exit(void)
  1425. {
  1426. pci_unregister_driver(&rt2400pci_driver);
  1427. }
  1428. module_init(rt2400pci_init);
  1429. module_exit(rt2400pci_exit);