rt2400pci.c 48 KB

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