rt61pci.c 85 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837
  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: rt61pci
  19. Abstract: rt61pci device specific routines.
  20. Supported chipsets: RT2561, RT2561s, RT2661.
  21. */
  22. #include <linux/crc-itu-t.h>
  23. #include <linux/delay.h>
  24. #include <linux/etherdevice.h>
  25. #include <linux/init.h>
  26. #include <linux/kernel.h>
  27. #include <linux/module.h>
  28. #include <linux/pci.h>
  29. #include <linux/eeprom_93cx6.h>
  30. #include "rt2x00.h"
  31. #include "rt2x00pci.h"
  32. #include "rt61pci.h"
  33. /*
  34. * Allow hardware encryption to be disabled.
  35. */
  36. static int modparam_nohwcrypt = 0;
  37. module_param_named(nohwcrypt, modparam_nohwcrypt, bool, S_IRUGO);
  38. MODULE_PARM_DESC(nohwcrypt, "Disable hardware encryption.");
  39. /*
  40. * Register access.
  41. * BBP and RF register require indirect register access,
  42. * and use the CSR registers PHY_CSR3 and PHY_CSR4 to achieve this.
  43. * These indirect registers work with busy bits,
  44. * and we will try maximal REGISTER_BUSY_COUNT times to access
  45. * the register while taking a REGISTER_BUSY_DELAY us delay
  46. * between each attampt. When the busy bit is still set at that time,
  47. * the access attempt is considered to have failed,
  48. * and we will print an error.
  49. */
  50. static u32 rt61pci_bbp_check(struct rt2x00_dev *rt2x00dev)
  51. {
  52. u32 reg;
  53. unsigned int i;
  54. for (i = 0; i < REGISTER_BUSY_COUNT; i++) {
  55. rt2x00pci_register_read(rt2x00dev, PHY_CSR3, &reg);
  56. if (!rt2x00_get_field32(reg, PHY_CSR3_BUSY))
  57. break;
  58. udelay(REGISTER_BUSY_DELAY);
  59. }
  60. return reg;
  61. }
  62. static void rt61pci_bbp_write(struct rt2x00_dev *rt2x00dev,
  63. const unsigned int word, const u8 value)
  64. {
  65. u32 reg;
  66. /*
  67. * Wait until the BBP becomes ready.
  68. */
  69. reg = rt61pci_bbp_check(rt2x00dev);
  70. if (rt2x00_get_field32(reg, PHY_CSR3_BUSY)) {
  71. ERROR(rt2x00dev, "PHY_CSR3 register busy. Write failed.\n");
  72. return;
  73. }
  74. /*
  75. * Write the data into the BBP.
  76. */
  77. reg = 0;
  78. rt2x00_set_field32(&reg, PHY_CSR3_VALUE, value);
  79. rt2x00_set_field32(&reg, PHY_CSR3_REGNUM, word);
  80. rt2x00_set_field32(&reg, PHY_CSR3_BUSY, 1);
  81. rt2x00_set_field32(&reg, PHY_CSR3_READ_CONTROL, 0);
  82. rt2x00pci_register_write(rt2x00dev, PHY_CSR3, reg);
  83. }
  84. static void rt61pci_bbp_read(struct rt2x00_dev *rt2x00dev,
  85. const unsigned int word, u8 *value)
  86. {
  87. u32 reg;
  88. /*
  89. * Wait until the BBP becomes ready.
  90. */
  91. reg = rt61pci_bbp_check(rt2x00dev);
  92. if (rt2x00_get_field32(reg, PHY_CSR3_BUSY)) {
  93. ERROR(rt2x00dev, "PHY_CSR3 register busy. Read failed.\n");
  94. return;
  95. }
  96. /*
  97. * Write the request into the BBP.
  98. */
  99. reg = 0;
  100. rt2x00_set_field32(&reg, PHY_CSR3_REGNUM, word);
  101. rt2x00_set_field32(&reg, PHY_CSR3_BUSY, 1);
  102. rt2x00_set_field32(&reg, PHY_CSR3_READ_CONTROL, 1);
  103. rt2x00pci_register_write(rt2x00dev, PHY_CSR3, reg);
  104. /*
  105. * Wait until the BBP becomes ready.
  106. */
  107. reg = rt61pci_bbp_check(rt2x00dev);
  108. if (rt2x00_get_field32(reg, PHY_CSR3_BUSY)) {
  109. ERROR(rt2x00dev, "PHY_CSR3 register busy. Read failed.\n");
  110. *value = 0xff;
  111. return;
  112. }
  113. *value = rt2x00_get_field32(reg, PHY_CSR3_VALUE);
  114. }
  115. static void rt61pci_rf_write(struct rt2x00_dev *rt2x00dev,
  116. const unsigned int word, const u32 value)
  117. {
  118. u32 reg;
  119. unsigned int i;
  120. if (!word)
  121. return;
  122. for (i = 0; i < REGISTER_BUSY_COUNT; i++) {
  123. rt2x00pci_register_read(rt2x00dev, PHY_CSR4, &reg);
  124. if (!rt2x00_get_field32(reg, PHY_CSR4_BUSY))
  125. goto rf_write;
  126. udelay(REGISTER_BUSY_DELAY);
  127. }
  128. ERROR(rt2x00dev, "PHY_CSR4 register busy. Write failed.\n");
  129. return;
  130. rf_write:
  131. reg = 0;
  132. rt2x00_set_field32(&reg, PHY_CSR4_VALUE, value);
  133. rt2x00_set_field32(&reg, PHY_CSR4_NUMBER_OF_BITS, 21);
  134. rt2x00_set_field32(&reg, PHY_CSR4_IF_SELECT, 0);
  135. rt2x00_set_field32(&reg, PHY_CSR4_BUSY, 1);
  136. rt2x00pci_register_write(rt2x00dev, PHY_CSR4, reg);
  137. rt2x00_rf_write(rt2x00dev, word, value);
  138. }
  139. #ifdef CONFIG_RT2X00_LIB_LEDS
  140. /*
  141. * This function is only called from rt61pci_led_brightness()
  142. * make gcc happy by placing this function inside the
  143. * same ifdef statement as the caller.
  144. */
  145. static void rt61pci_mcu_request(struct rt2x00_dev *rt2x00dev,
  146. const u8 command, const u8 token,
  147. const u8 arg0, const u8 arg1)
  148. {
  149. u32 reg;
  150. rt2x00pci_register_read(rt2x00dev, H2M_MAILBOX_CSR, &reg);
  151. if (rt2x00_get_field32(reg, H2M_MAILBOX_CSR_OWNER)) {
  152. ERROR(rt2x00dev, "mcu request error. "
  153. "Request 0x%02x failed for token 0x%02x.\n",
  154. command, token);
  155. return;
  156. }
  157. rt2x00_set_field32(&reg, H2M_MAILBOX_CSR_OWNER, 1);
  158. rt2x00_set_field32(&reg, H2M_MAILBOX_CSR_CMD_TOKEN, token);
  159. rt2x00_set_field32(&reg, H2M_MAILBOX_CSR_ARG0, arg0);
  160. rt2x00_set_field32(&reg, H2M_MAILBOX_CSR_ARG1, arg1);
  161. rt2x00pci_register_write(rt2x00dev, H2M_MAILBOX_CSR, reg);
  162. rt2x00pci_register_read(rt2x00dev, HOST_CMD_CSR, &reg);
  163. rt2x00_set_field32(&reg, HOST_CMD_CSR_HOST_COMMAND, command);
  164. rt2x00_set_field32(&reg, HOST_CMD_CSR_INTERRUPT_MCU, 1);
  165. rt2x00pci_register_write(rt2x00dev, HOST_CMD_CSR, reg);
  166. }
  167. #endif /* CONFIG_RT2X00_LIB_LEDS */
  168. static void rt61pci_eepromregister_read(struct eeprom_93cx6 *eeprom)
  169. {
  170. struct rt2x00_dev *rt2x00dev = eeprom->data;
  171. u32 reg;
  172. rt2x00pci_register_read(rt2x00dev, E2PROM_CSR, &reg);
  173. eeprom->reg_data_in = !!rt2x00_get_field32(reg, E2PROM_CSR_DATA_IN);
  174. eeprom->reg_data_out = !!rt2x00_get_field32(reg, E2PROM_CSR_DATA_OUT);
  175. eeprom->reg_data_clock =
  176. !!rt2x00_get_field32(reg, E2PROM_CSR_DATA_CLOCK);
  177. eeprom->reg_chip_select =
  178. !!rt2x00_get_field32(reg, E2PROM_CSR_CHIP_SELECT);
  179. }
  180. static void rt61pci_eepromregister_write(struct eeprom_93cx6 *eeprom)
  181. {
  182. struct rt2x00_dev *rt2x00dev = eeprom->data;
  183. u32 reg = 0;
  184. rt2x00_set_field32(&reg, E2PROM_CSR_DATA_IN, !!eeprom->reg_data_in);
  185. rt2x00_set_field32(&reg, E2PROM_CSR_DATA_OUT, !!eeprom->reg_data_out);
  186. rt2x00_set_field32(&reg, E2PROM_CSR_DATA_CLOCK,
  187. !!eeprom->reg_data_clock);
  188. rt2x00_set_field32(&reg, E2PROM_CSR_CHIP_SELECT,
  189. !!eeprom->reg_chip_select);
  190. rt2x00pci_register_write(rt2x00dev, E2PROM_CSR, reg);
  191. }
  192. #ifdef CONFIG_RT2X00_LIB_DEBUGFS
  193. #define CSR_OFFSET(__word) ( CSR_REG_BASE + ((__word) * sizeof(u32)) )
  194. static void rt61pci_read_csr(struct rt2x00_dev *rt2x00dev,
  195. const unsigned int word, u32 *data)
  196. {
  197. rt2x00pci_register_read(rt2x00dev, CSR_OFFSET(word), data);
  198. }
  199. static void rt61pci_write_csr(struct rt2x00_dev *rt2x00dev,
  200. const unsigned int word, u32 data)
  201. {
  202. rt2x00pci_register_write(rt2x00dev, CSR_OFFSET(word), data);
  203. }
  204. static const struct rt2x00debug rt61pci_rt2x00debug = {
  205. .owner = THIS_MODULE,
  206. .csr = {
  207. .read = rt61pci_read_csr,
  208. .write = rt61pci_write_csr,
  209. .word_size = sizeof(u32),
  210. .word_count = CSR_REG_SIZE / sizeof(u32),
  211. },
  212. .eeprom = {
  213. .read = rt2x00_eeprom_read,
  214. .write = rt2x00_eeprom_write,
  215. .word_size = sizeof(u16),
  216. .word_count = EEPROM_SIZE / sizeof(u16),
  217. },
  218. .bbp = {
  219. .read = rt61pci_bbp_read,
  220. .write = rt61pci_bbp_write,
  221. .word_size = sizeof(u8),
  222. .word_count = BBP_SIZE / sizeof(u8),
  223. },
  224. .rf = {
  225. .read = rt2x00_rf_read,
  226. .write = rt61pci_rf_write,
  227. .word_size = sizeof(u32),
  228. .word_count = RF_SIZE / sizeof(u32),
  229. },
  230. };
  231. #endif /* CONFIG_RT2X00_LIB_DEBUGFS */
  232. #ifdef CONFIG_RT2X00_LIB_RFKILL
  233. static int rt61pci_rfkill_poll(struct rt2x00_dev *rt2x00dev)
  234. {
  235. u32 reg;
  236. rt2x00pci_register_read(rt2x00dev, MAC_CSR13, &reg);
  237. return rt2x00_get_field32(reg, MAC_CSR13_BIT5);
  238. }
  239. #else
  240. #define rt61pci_rfkill_poll NULL
  241. #endif /* CONFIG_RT2X00_LIB_RFKILL */
  242. #ifdef CONFIG_RT2X00_LIB_LEDS
  243. static void rt61pci_brightness_set(struct led_classdev *led_cdev,
  244. enum led_brightness brightness)
  245. {
  246. struct rt2x00_led *led =
  247. container_of(led_cdev, struct rt2x00_led, led_dev);
  248. unsigned int enabled = brightness != LED_OFF;
  249. unsigned int a_mode =
  250. (enabled && led->rt2x00dev->curr_band == IEEE80211_BAND_5GHZ);
  251. unsigned int bg_mode =
  252. (enabled && led->rt2x00dev->curr_band == IEEE80211_BAND_2GHZ);
  253. if (led->type == LED_TYPE_RADIO) {
  254. rt2x00_set_field16(&led->rt2x00dev->led_mcu_reg,
  255. MCU_LEDCS_RADIO_STATUS, enabled);
  256. rt61pci_mcu_request(led->rt2x00dev, MCU_LED, 0xff,
  257. (led->rt2x00dev->led_mcu_reg & 0xff),
  258. ((led->rt2x00dev->led_mcu_reg >> 8)));
  259. } else if (led->type == LED_TYPE_ASSOC) {
  260. rt2x00_set_field16(&led->rt2x00dev->led_mcu_reg,
  261. MCU_LEDCS_LINK_BG_STATUS, bg_mode);
  262. rt2x00_set_field16(&led->rt2x00dev->led_mcu_reg,
  263. MCU_LEDCS_LINK_A_STATUS, a_mode);
  264. rt61pci_mcu_request(led->rt2x00dev, MCU_LED, 0xff,
  265. (led->rt2x00dev->led_mcu_reg & 0xff),
  266. ((led->rt2x00dev->led_mcu_reg >> 8)));
  267. } else if (led->type == LED_TYPE_QUALITY) {
  268. /*
  269. * The brightness is divided into 6 levels (0 - 5),
  270. * this means we need to convert the brightness
  271. * argument into the matching level within that range.
  272. */
  273. rt61pci_mcu_request(led->rt2x00dev, MCU_LED_STRENGTH, 0xff,
  274. brightness / (LED_FULL / 6), 0);
  275. }
  276. }
  277. static int rt61pci_blink_set(struct led_classdev *led_cdev,
  278. unsigned long *delay_on,
  279. unsigned long *delay_off)
  280. {
  281. struct rt2x00_led *led =
  282. container_of(led_cdev, struct rt2x00_led, led_dev);
  283. u32 reg;
  284. rt2x00pci_register_read(led->rt2x00dev, MAC_CSR14, &reg);
  285. rt2x00_set_field32(&reg, MAC_CSR14_ON_PERIOD, *delay_on);
  286. rt2x00_set_field32(&reg, MAC_CSR14_OFF_PERIOD, *delay_off);
  287. rt2x00pci_register_write(led->rt2x00dev, MAC_CSR14, reg);
  288. return 0;
  289. }
  290. static void rt61pci_init_led(struct rt2x00_dev *rt2x00dev,
  291. struct rt2x00_led *led,
  292. enum led_type type)
  293. {
  294. led->rt2x00dev = rt2x00dev;
  295. led->type = type;
  296. led->led_dev.brightness_set = rt61pci_brightness_set;
  297. led->led_dev.blink_set = rt61pci_blink_set;
  298. led->flags = LED_INITIALIZED;
  299. }
  300. #endif /* CONFIG_RT2X00_LIB_LEDS */
  301. /*
  302. * Configuration handlers.
  303. */
  304. static int rt61pci_config_shared_key(struct rt2x00_dev *rt2x00dev,
  305. struct rt2x00lib_crypto *crypto,
  306. struct ieee80211_key_conf *key)
  307. {
  308. struct hw_key_entry key_entry;
  309. struct rt2x00_field32 field;
  310. u32 mask;
  311. u32 reg;
  312. if (crypto->cmd == SET_KEY) {
  313. /*
  314. * rt2x00lib can't determine the correct free
  315. * key_idx for shared keys. We have 1 register
  316. * with key valid bits. The goal is simple, read
  317. * the register, if that is full we have no slots
  318. * left.
  319. * Note that each BSS is allowed to have up to 4
  320. * shared keys, so put a mask over the allowed
  321. * entries.
  322. */
  323. mask = (0xf << crypto->bssidx);
  324. rt2x00pci_register_read(rt2x00dev, SEC_CSR0, &reg);
  325. reg &= mask;
  326. if (reg && reg == mask)
  327. return -ENOSPC;
  328. key->hw_key_idx += reg ? ffz(reg) : 0;
  329. /*
  330. * Upload key to hardware
  331. */
  332. memcpy(key_entry.key, crypto->key,
  333. sizeof(key_entry.key));
  334. memcpy(key_entry.tx_mic, crypto->tx_mic,
  335. sizeof(key_entry.tx_mic));
  336. memcpy(key_entry.rx_mic, crypto->rx_mic,
  337. sizeof(key_entry.rx_mic));
  338. reg = SHARED_KEY_ENTRY(key->hw_key_idx);
  339. rt2x00pci_register_multiwrite(rt2x00dev, reg,
  340. &key_entry, sizeof(key_entry));
  341. /*
  342. * The cipher types are stored over 2 registers.
  343. * bssidx 0 and 1 keys are stored in SEC_CSR1 and
  344. * bssidx 1 and 2 keys are stored in SEC_CSR5.
  345. * Using the correct defines correctly will cause overhead,
  346. * so just calculate the correct offset.
  347. */
  348. if (key->hw_key_idx < 8) {
  349. field.bit_offset = (3 * key->hw_key_idx);
  350. field.bit_mask = 0x7 << field.bit_offset;
  351. rt2x00pci_register_read(rt2x00dev, SEC_CSR1, &reg);
  352. rt2x00_set_field32(&reg, field, crypto->cipher);
  353. rt2x00pci_register_write(rt2x00dev, SEC_CSR1, reg);
  354. } else {
  355. field.bit_offset = (3 * (key->hw_key_idx - 8));
  356. field.bit_mask = 0x7 << field.bit_offset;
  357. rt2x00pci_register_read(rt2x00dev, SEC_CSR5, &reg);
  358. rt2x00_set_field32(&reg, field, crypto->cipher);
  359. rt2x00pci_register_write(rt2x00dev, SEC_CSR5, reg);
  360. }
  361. /*
  362. * The driver does not support the IV/EIV generation
  363. * in hardware. However it doesn't support the IV/EIV
  364. * inside the ieee80211 frame either, but requires it
  365. * to be provided seperately for the descriptor.
  366. * rt2x00lib will cut the IV/EIV data out of all frames
  367. * given to us by mac80211, but we must tell mac80211
  368. * to generate the IV/EIV data.
  369. */
  370. key->flags |= IEEE80211_KEY_FLAG_GENERATE_IV;
  371. }
  372. /*
  373. * SEC_CSR0 contains only single-bit fields to indicate
  374. * a particular key is valid. Because using the FIELD32()
  375. * defines directly will cause a lot of overhead we use
  376. * a calculation to determine the correct bit directly.
  377. */
  378. mask = 1 << key->hw_key_idx;
  379. rt2x00pci_register_read(rt2x00dev, SEC_CSR0, &reg);
  380. if (crypto->cmd == SET_KEY)
  381. reg |= mask;
  382. else if (crypto->cmd == DISABLE_KEY)
  383. reg &= ~mask;
  384. rt2x00pci_register_write(rt2x00dev, SEC_CSR0, reg);
  385. return 0;
  386. }
  387. static int rt61pci_config_pairwise_key(struct rt2x00_dev *rt2x00dev,
  388. struct rt2x00lib_crypto *crypto,
  389. struct ieee80211_key_conf *key)
  390. {
  391. struct hw_pairwise_ta_entry addr_entry;
  392. struct hw_key_entry key_entry;
  393. u32 mask;
  394. u32 reg;
  395. if (crypto->cmd == SET_KEY) {
  396. /*
  397. * rt2x00lib can't determine the correct free
  398. * key_idx for pairwise keys. We have 2 registers
  399. * with key valid bits. The goal is simple, read
  400. * the first register, if that is full move to
  401. * the next register.
  402. * When both registers are full, we drop the key,
  403. * otherwise we use the first invalid entry.
  404. */
  405. rt2x00pci_register_read(rt2x00dev, SEC_CSR2, &reg);
  406. if (reg && reg == ~0) {
  407. key->hw_key_idx = 32;
  408. rt2x00pci_register_read(rt2x00dev, SEC_CSR3, &reg);
  409. if (reg && reg == ~0)
  410. return -ENOSPC;
  411. }
  412. key->hw_key_idx += reg ? ffz(reg) : 0;
  413. /*
  414. * Upload key to hardware
  415. */
  416. memcpy(key_entry.key, crypto->key,
  417. sizeof(key_entry.key));
  418. memcpy(key_entry.tx_mic, crypto->tx_mic,
  419. sizeof(key_entry.tx_mic));
  420. memcpy(key_entry.rx_mic, crypto->rx_mic,
  421. sizeof(key_entry.rx_mic));
  422. memset(&addr_entry, 0, sizeof(addr_entry));
  423. memcpy(&addr_entry, crypto->address, ETH_ALEN);
  424. addr_entry.cipher = crypto->cipher;
  425. reg = PAIRWISE_KEY_ENTRY(key->hw_key_idx);
  426. rt2x00pci_register_multiwrite(rt2x00dev, reg,
  427. &key_entry, sizeof(key_entry));
  428. reg = PAIRWISE_TA_ENTRY(key->hw_key_idx);
  429. rt2x00pci_register_multiwrite(rt2x00dev, reg,
  430. &addr_entry, sizeof(addr_entry));
  431. /*
  432. * Enable pairwise lookup table for given BSS idx,
  433. * without this received frames will not be decrypted
  434. * by the hardware.
  435. */
  436. rt2x00pci_register_read(rt2x00dev, SEC_CSR4, &reg);
  437. reg |= (1 << crypto->bssidx);
  438. rt2x00pci_register_write(rt2x00dev, SEC_CSR4, reg);
  439. /*
  440. * The driver does not support the IV/EIV generation
  441. * in hardware. However it doesn't support the IV/EIV
  442. * inside the ieee80211 frame either, but requires it
  443. * to be provided seperately for the descriptor.
  444. * rt2x00lib will cut the IV/EIV data out of all frames
  445. * given to us by mac80211, but we must tell mac80211
  446. * to generate the IV/EIV data.
  447. */
  448. key->flags |= IEEE80211_KEY_FLAG_GENERATE_IV;
  449. }
  450. /*
  451. * SEC_CSR2 and SEC_CSR3 contain only single-bit fields to indicate
  452. * a particular key is valid. Because using the FIELD32()
  453. * defines directly will cause a lot of overhead we use
  454. * a calculation to determine the correct bit directly.
  455. */
  456. if (key->hw_key_idx < 32) {
  457. mask = 1 << key->hw_key_idx;
  458. rt2x00pci_register_read(rt2x00dev, SEC_CSR2, &reg);
  459. if (crypto->cmd == SET_KEY)
  460. reg |= mask;
  461. else if (crypto->cmd == DISABLE_KEY)
  462. reg &= ~mask;
  463. rt2x00pci_register_write(rt2x00dev, SEC_CSR2, reg);
  464. } else {
  465. mask = 1 << (key->hw_key_idx - 32);
  466. rt2x00pci_register_read(rt2x00dev, SEC_CSR3, &reg);
  467. if (crypto->cmd == SET_KEY)
  468. reg |= mask;
  469. else if (crypto->cmd == DISABLE_KEY)
  470. reg &= ~mask;
  471. rt2x00pci_register_write(rt2x00dev, SEC_CSR3, reg);
  472. }
  473. return 0;
  474. }
  475. static void rt61pci_config_filter(struct rt2x00_dev *rt2x00dev,
  476. const unsigned int filter_flags)
  477. {
  478. u32 reg;
  479. /*
  480. * Start configuration steps.
  481. * Note that the version error will always be dropped
  482. * and broadcast frames will always be accepted since
  483. * there is no filter for it at this time.
  484. */
  485. rt2x00pci_register_read(rt2x00dev, TXRX_CSR0, &reg);
  486. rt2x00_set_field32(&reg, TXRX_CSR0_DROP_CRC,
  487. !(filter_flags & FIF_FCSFAIL));
  488. rt2x00_set_field32(&reg, TXRX_CSR0_DROP_PHYSICAL,
  489. !(filter_flags & FIF_PLCPFAIL));
  490. rt2x00_set_field32(&reg, TXRX_CSR0_DROP_CONTROL,
  491. !(filter_flags & FIF_CONTROL));
  492. rt2x00_set_field32(&reg, TXRX_CSR0_DROP_NOT_TO_ME,
  493. !(filter_flags & FIF_PROMISC_IN_BSS));
  494. rt2x00_set_field32(&reg, TXRX_CSR0_DROP_TO_DS,
  495. !(filter_flags & FIF_PROMISC_IN_BSS) &&
  496. !rt2x00dev->intf_ap_count);
  497. rt2x00_set_field32(&reg, TXRX_CSR0_DROP_VERSION_ERROR, 1);
  498. rt2x00_set_field32(&reg, TXRX_CSR0_DROP_MULTICAST,
  499. !(filter_flags & FIF_ALLMULTI));
  500. rt2x00_set_field32(&reg, TXRX_CSR0_DROP_BROADCAST, 0);
  501. rt2x00_set_field32(&reg, TXRX_CSR0_DROP_ACK_CTS,
  502. !(filter_flags & FIF_CONTROL));
  503. rt2x00pci_register_write(rt2x00dev, TXRX_CSR0, reg);
  504. }
  505. static void rt61pci_config_intf(struct rt2x00_dev *rt2x00dev,
  506. struct rt2x00_intf *intf,
  507. struct rt2x00intf_conf *conf,
  508. const unsigned int flags)
  509. {
  510. unsigned int beacon_base;
  511. u32 reg;
  512. if (flags & CONFIG_UPDATE_TYPE) {
  513. /*
  514. * Clear current synchronisation setup.
  515. * For the Beacon base registers we only need to clear
  516. * the first byte since that byte contains the VALID and OWNER
  517. * bits which (when set to 0) will invalidate the entire beacon.
  518. */
  519. beacon_base = HW_BEACON_OFFSET(intf->beacon->entry_idx);
  520. rt2x00pci_register_write(rt2x00dev, beacon_base, 0);
  521. /*
  522. * Enable synchronisation.
  523. */
  524. rt2x00pci_register_read(rt2x00dev, TXRX_CSR9, &reg);
  525. rt2x00_set_field32(&reg, TXRX_CSR9_TSF_TICKING, 1);
  526. rt2x00_set_field32(&reg, TXRX_CSR9_TSF_SYNC, conf->sync);
  527. rt2x00_set_field32(&reg, TXRX_CSR9_TBTT_ENABLE, 1);
  528. rt2x00pci_register_write(rt2x00dev, TXRX_CSR9, reg);
  529. }
  530. if (flags & CONFIG_UPDATE_MAC) {
  531. reg = le32_to_cpu(conf->mac[1]);
  532. rt2x00_set_field32(&reg, MAC_CSR3_UNICAST_TO_ME_MASK, 0xff);
  533. conf->mac[1] = cpu_to_le32(reg);
  534. rt2x00pci_register_multiwrite(rt2x00dev, MAC_CSR2,
  535. conf->mac, sizeof(conf->mac));
  536. }
  537. if (flags & CONFIG_UPDATE_BSSID) {
  538. reg = le32_to_cpu(conf->bssid[1]);
  539. rt2x00_set_field32(&reg, MAC_CSR5_BSS_ID_MASK, 3);
  540. conf->bssid[1] = cpu_to_le32(reg);
  541. rt2x00pci_register_multiwrite(rt2x00dev, MAC_CSR4,
  542. conf->bssid, sizeof(conf->bssid));
  543. }
  544. }
  545. static void rt61pci_config_erp(struct rt2x00_dev *rt2x00dev,
  546. struct rt2x00lib_erp *erp)
  547. {
  548. u32 reg;
  549. rt2x00pci_register_read(rt2x00dev, TXRX_CSR0, &reg);
  550. rt2x00_set_field32(&reg, TXRX_CSR0_RX_ACK_TIMEOUT, erp->ack_timeout);
  551. rt2x00pci_register_write(rt2x00dev, TXRX_CSR0, reg);
  552. rt2x00pci_register_read(rt2x00dev, TXRX_CSR4, &reg);
  553. rt2x00_set_field32(&reg, TXRX_CSR4_AUTORESPOND_PREAMBLE,
  554. !!erp->short_preamble);
  555. rt2x00pci_register_write(rt2x00dev, TXRX_CSR4, reg);
  556. rt2x00pci_register_write(rt2x00dev, TXRX_CSR5, erp->basic_rates);
  557. rt2x00pci_register_read(rt2x00dev, MAC_CSR9, &reg);
  558. rt2x00_set_field32(&reg, MAC_CSR9_SLOT_TIME, erp->slot_time);
  559. rt2x00pci_register_write(rt2x00dev, MAC_CSR9, reg);
  560. rt2x00pci_register_read(rt2x00dev, MAC_CSR8, &reg);
  561. rt2x00_set_field32(&reg, MAC_CSR8_SIFS, erp->sifs);
  562. rt2x00_set_field32(&reg, MAC_CSR8_SIFS_AFTER_RX_OFDM, 3);
  563. rt2x00_set_field32(&reg, MAC_CSR8_EIFS, erp->eifs);
  564. rt2x00pci_register_write(rt2x00dev, MAC_CSR8, reg);
  565. }
  566. static void rt61pci_config_antenna_5x(struct rt2x00_dev *rt2x00dev,
  567. struct antenna_setup *ant)
  568. {
  569. u8 r3;
  570. u8 r4;
  571. u8 r77;
  572. rt61pci_bbp_read(rt2x00dev, 3, &r3);
  573. rt61pci_bbp_read(rt2x00dev, 4, &r4);
  574. rt61pci_bbp_read(rt2x00dev, 77, &r77);
  575. rt2x00_set_field8(&r3, BBP_R3_SMART_MODE,
  576. rt2x00_rf(&rt2x00dev->chip, RF5325));
  577. /*
  578. * Configure the RX antenna.
  579. */
  580. switch (ant->rx) {
  581. case ANTENNA_HW_DIVERSITY:
  582. rt2x00_set_field8(&r4, BBP_R4_RX_ANTENNA_CONTROL, 2);
  583. rt2x00_set_field8(&r4, BBP_R4_RX_FRAME_END,
  584. (rt2x00dev->curr_band != IEEE80211_BAND_5GHZ));
  585. break;
  586. case ANTENNA_A:
  587. rt2x00_set_field8(&r4, BBP_R4_RX_ANTENNA_CONTROL, 1);
  588. rt2x00_set_field8(&r4, BBP_R4_RX_FRAME_END, 0);
  589. if (rt2x00dev->curr_band == IEEE80211_BAND_5GHZ)
  590. rt2x00_set_field8(&r77, BBP_R77_RX_ANTENNA, 0);
  591. else
  592. rt2x00_set_field8(&r77, BBP_R77_RX_ANTENNA, 3);
  593. break;
  594. case ANTENNA_B:
  595. default:
  596. rt2x00_set_field8(&r4, BBP_R4_RX_ANTENNA_CONTROL, 1);
  597. rt2x00_set_field8(&r4, BBP_R4_RX_FRAME_END, 0);
  598. if (rt2x00dev->curr_band == IEEE80211_BAND_5GHZ)
  599. rt2x00_set_field8(&r77, BBP_R77_RX_ANTENNA, 3);
  600. else
  601. rt2x00_set_field8(&r77, BBP_R77_RX_ANTENNA, 0);
  602. break;
  603. }
  604. rt61pci_bbp_write(rt2x00dev, 77, r77);
  605. rt61pci_bbp_write(rt2x00dev, 3, r3);
  606. rt61pci_bbp_write(rt2x00dev, 4, r4);
  607. }
  608. static void rt61pci_config_antenna_2x(struct rt2x00_dev *rt2x00dev,
  609. struct antenna_setup *ant)
  610. {
  611. u8 r3;
  612. u8 r4;
  613. u8 r77;
  614. rt61pci_bbp_read(rt2x00dev, 3, &r3);
  615. rt61pci_bbp_read(rt2x00dev, 4, &r4);
  616. rt61pci_bbp_read(rt2x00dev, 77, &r77);
  617. rt2x00_set_field8(&r3, BBP_R3_SMART_MODE,
  618. rt2x00_rf(&rt2x00dev->chip, RF2529));
  619. rt2x00_set_field8(&r4, BBP_R4_RX_FRAME_END,
  620. !test_bit(CONFIG_FRAME_TYPE, &rt2x00dev->flags));
  621. /*
  622. * Configure the RX antenna.
  623. */
  624. switch (ant->rx) {
  625. case ANTENNA_HW_DIVERSITY:
  626. rt2x00_set_field8(&r4, BBP_R4_RX_ANTENNA_CONTROL, 2);
  627. break;
  628. case ANTENNA_A:
  629. rt2x00_set_field8(&r4, BBP_R4_RX_ANTENNA_CONTROL, 1);
  630. rt2x00_set_field8(&r77, BBP_R77_RX_ANTENNA, 3);
  631. break;
  632. case ANTENNA_B:
  633. default:
  634. rt2x00_set_field8(&r4, BBP_R4_RX_ANTENNA_CONTROL, 1);
  635. rt2x00_set_field8(&r77, BBP_R77_RX_ANTENNA, 0);
  636. break;
  637. }
  638. rt61pci_bbp_write(rt2x00dev, 77, r77);
  639. rt61pci_bbp_write(rt2x00dev, 3, r3);
  640. rt61pci_bbp_write(rt2x00dev, 4, r4);
  641. }
  642. static void rt61pci_config_antenna_2529_rx(struct rt2x00_dev *rt2x00dev,
  643. const int p1, const int p2)
  644. {
  645. u32 reg;
  646. rt2x00pci_register_read(rt2x00dev, MAC_CSR13, &reg);
  647. rt2x00_set_field32(&reg, MAC_CSR13_BIT4, p1);
  648. rt2x00_set_field32(&reg, MAC_CSR13_BIT12, 0);
  649. rt2x00_set_field32(&reg, MAC_CSR13_BIT3, !p2);
  650. rt2x00_set_field32(&reg, MAC_CSR13_BIT11, 0);
  651. rt2x00pci_register_write(rt2x00dev, MAC_CSR13, reg);
  652. }
  653. static void rt61pci_config_antenna_2529(struct rt2x00_dev *rt2x00dev,
  654. struct antenna_setup *ant)
  655. {
  656. u8 r3;
  657. u8 r4;
  658. u8 r77;
  659. rt61pci_bbp_read(rt2x00dev, 3, &r3);
  660. rt61pci_bbp_read(rt2x00dev, 4, &r4);
  661. rt61pci_bbp_read(rt2x00dev, 77, &r77);
  662. /*
  663. * Configure the RX antenna.
  664. */
  665. switch (ant->rx) {
  666. case ANTENNA_A:
  667. rt2x00_set_field8(&r4, BBP_R4_RX_ANTENNA_CONTROL, 1);
  668. rt2x00_set_field8(&r77, BBP_R77_RX_ANTENNA, 0);
  669. rt61pci_config_antenna_2529_rx(rt2x00dev, 0, 0);
  670. break;
  671. case ANTENNA_HW_DIVERSITY:
  672. /*
  673. * FIXME: Antenna selection for the rf 2529 is very confusing
  674. * in the legacy driver. Just default to antenna B until the
  675. * legacy code can be properly translated into rt2x00 code.
  676. */
  677. case ANTENNA_B:
  678. default:
  679. rt2x00_set_field8(&r4, BBP_R4_RX_ANTENNA_CONTROL, 1);
  680. rt2x00_set_field8(&r77, BBP_R77_RX_ANTENNA, 3);
  681. rt61pci_config_antenna_2529_rx(rt2x00dev, 1, 1);
  682. break;
  683. }
  684. rt61pci_bbp_write(rt2x00dev, 77, r77);
  685. rt61pci_bbp_write(rt2x00dev, 3, r3);
  686. rt61pci_bbp_write(rt2x00dev, 4, r4);
  687. }
  688. struct antenna_sel {
  689. u8 word;
  690. /*
  691. * value[0] -> non-LNA
  692. * value[1] -> LNA
  693. */
  694. u8 value[2];
  695. };
  696. static const struct antenna_sel antenna_sel_a[] = {
  697. { 96, { 0x58, 0x78 } },
  698. { 104, { 0x38, 0x48 } },
  699. { 75, { 0xfe, 0x80 } },
  700. { 86, { 0xfe, 0x80 } },
  701. { 88, { 0xfe, 0x80 } },
  702. { 35, { 0x60, 0x60 } },
  703. { 97, { 0x58, 0x58 } },
  704. { 98, { 0x58, 0x58 } },
  705. };
  706. static const struct antenna_sel antenna_sel_bg[] = {
  707. { 96, { 0x48, 0x68 } },
  708. { 104, { 0x2c, 0x3c } },
  709. { 75, { 0xfe, 0x80 } },
  710. { 86, { 0xfe, 0x80 } },
  711. { 88, { 0xfe, 0x80 } },
  712. { 35, { 0x50, 0x50 } },
  713. { 97, { 0x48, 0x48 } },
  714. { 98, { 0x48, 0x48 } },
  715. };
  716. static void rt61pci_config_ant(struct rt2x00_dev *rt2x00dev,
  717. struct antenna_setup *ant)
  718. {
  719. const struct antenna_sel *sel;
  720. unsigned int lna;
  721. unsigned int i;
  722. u32 reg;
  723. /*
  724. * We should never come here because rt2x00lib is supposed
  725. * to catch this and send us the correct antenna explicitely.
  726. */
  727. BUG_ON(ant->rx == ANTENNA_SW_DIVERSITY ||
  728. ant->tx == ANTENNA_SW_DIVERSITY);
  729. if (rt2x00dev->curr_band == IEEE80211_BAND_5GHZ) {
  730. sel = antenna_sel_a;
  731. lna = test_bit(CONFIG_EXTERNAL_LNA_A, &rt2x00dev->flags);
  732. } else {
  733. sel = antenna_sel_bg;
  734. lna = test_bit(CONFIG_EXTERNAL_LNA_BG, &rt2x00dev->flags);
  735. }
  736. for (i = 0; i < ARRAY_SIZE(antenna_sel_a); i++)
  737. rt61pci_bbp_write(rt2x00dev, sel[i].word, sel[i].value[lna]);
  738. rt2x00pci_register_read(rt2x00dev, PHY_CSR0, &reg);
  739. rt2x00_set_field32(&reg, PHY_CSR0_PA_PE_BG,
  740. rt2x00dev->curr_band == IEEE80211_BAND_2GHZ);
  741. rt2x00_set_field32(&reg, PHY_CSR0_PA_PE_A,
  742. rt2x00dev->curr_band == IEEE80211_BAND_5GHZ);
  743. rt2x00pci_register_write(rt2x00dev, PHY_CSR0, reg);
  744. if (rt2x00_rf(&rt2x00dev->chip, RF5225) ||
  745. rt2x00_rf(&rt2x00dev->chip, RF5325))
  746. rt61pci_config_antenna_5x(rt2x00dev, ant);
  747. else if (rt2x00_rf(&rt2x00dev->chip, RF2527))
  748. rt61pci_config_antenna_2x(rt2x00dev, ant);
  749. else if (rt2x00_rf(&rt2x00dev->chip, RF2529)) {
  750. if (test_bit(CONFIG_DOUBLE_ANTENNA, &rt2x00dev->flags))
  751. rt61pci_config_antenna_2x(rt2x00dev, ant);
  752. else
  753. rt61pci_config_antenna_2529(rt2x00dev, ant);
  754. }
  755. }
  756. static void rt61pci_config_lna_gain(struct rt2x00_dev *rt2x00dev,
  757. struct rt2x00lib_conf *libconf)
  758. {
  759. u16 eeprom;
  760. short lna_gain = 0;
  761. if (libconf->conf->channel->band == IEEE80211_BAND_2GHZ) {
  762. if (test_bit(CONFIG_EXTERNAL_LNA_BG, &rt2x00dev->flags))
  763. lna_gain += 14;
  764. rt2x00_eeprom_read(rt2x00dev, EEPROM_RSSI_OFFSET_BG, &eeprom);
  765. lna_gain -= rt2x00_get_field16(eeprom, EEPROM_RSSI_OFFSET_BG_1);
  766. } else {
  767. if (test_bit(CONFIG_EXTERNAL_LNA_A, &rt2x00dev->flags))
  768. lna_gain += 14;
  769. rt2x00_eeprom_read(rt2x00dev, EEPROM_RSSI_OFFSET_A, &eeprom);
  770. lna_gain -= rt2x00_get_field16(eeprom, EEPROM_RSSI_OFFSET_A_1);
  771. }
  772. rt2x00dev->lna_gain = lna_gain;
  773. }
  774. static void rt61pci_config_channel(struct rt2x00_dev *rt2x00dev,
  775. struct rf_channel *rf, const int txpower)
  776. {
  777. u8 r3;
  778. u8 r94;
  779. u8 smart;
  780. rt2x00_set_field32(&rf->rf3, RF3_TXPOWER, TXPOWER_TO_DEV(txpower));
  781. rt2x00_set_field32(&rf->rf4, RF4_FREQ_OFFSET, rt2x00dev->freq_offset);
  782. smart = !(rt2x00_rf(&rt2x00dev->chip, RF5225) ||
  783. rt2x00_rf(&rt2x00dev->chip, RF2527));
  784. rt61pci_bbp_read(rt2x00dev, 3, &r3);
  785. rt2x00_set_field8(&r3, BBP_R3_SMART_MODE, smart);
  786. rt61pci_bbp_write(rt2x00dev, 3, r3);
  787. r94 = 6;
  788. if (txpower > MAX_TXPOWER && txpower <= (MAX_TXPOWER + r94))
  789. r94 += txpower - MAX_TXPOWER;
  790. else if (txpower < MIN_TXPOWER && txpower >= (MIN_TXPOWER - r94))
  791. r94 += txpower;
  792. rt61pci_bbp_write(rt2x00dev, 94, r94);
  793. rt61pci_rf_write(rt2x00dev, 1, rf->rf1);
  794. rt61pci_rf_write(rt2x00dev, 2, rf->rf2);
  795. rt61pci_rf_write(rt2x00dev, 3, rf->rf3 & ~0x00000004);
  796. rt61pci_rf_write(rt2x00dev, 4, rf->rf4);
  797. udelay(200);
  798. rt61pci_rf_write(rt2x00dev, 1, rf->rf1);
  799. rt61pci_rf_write(rt2x00dev, 2, rf->rf2);
  800. rt61pci_rf_write(rt2x00dev, 3, rf->rf3 | 0x00000004);
  801. rt61pci_rf_write(rt2x00dev, 4, rf->rf4);
  802. udelay(200);
  803. rt61pci_rf_write(rt2x00dev, 1, rf->rf1);
  804. rt61pci_rf_write(rt2x00dev, 2, rf->rf2);
  805. rt61pci_rf_write(rt2x00dev, 3, rf->rf3 & ~0x00000004);
  806. rt61pci_rf_write(rt2x00dev, 4, rf->rf4);
  807. msleep(1);
  808. }
  809. static void rt61pci_config_txpower(struct rt2x00_dev *rt2x00dev,
  810. const int txpower)
  811. {
  812. struct rf_channel rf;
  813. rt2x00_rf_read(rt2x00dev, 1, &rf.rf1);
  814. rt2x00_rf_read(rt2x00dev, 2, &rf.rf2);
  815. rt2x00_rf_read(rt2x00dev, 3, &rf.rf3);
  816. rt2x00_rf_read(rt2x00dev, 4, &rf.rf4);
  817. rt61pci_config_channel(rt2x00dev, &rf, txpower);
  818. }
  819. static void rt61pci_config_retry_limit(struct rt2x00_dev *rt2x00dev,
  820. struct rt2x00lib_conf *libconf)
  821. {
  822. u32 reg;
  823. rt2x00pci_register_read(rt2x00dev, TXRX_CSR4, &reg);
  824. rt2x00_set_field32(&reg, TXRX_CSR4_LONG_RETRY_LIMIT,
  825. libconf->conf->long_frame_max_tx_count);
  826. rt2x00_set_field32(&reg, TXRX_CSR4_SHORT_RETRY_LIMIT,
  827. libconf->conf->short_frame_max_tx_count);
  828. rt2x00pci_register_write(rt2x00dev, TXRX_CSR4, reg);
  829. }
  830. static void rt61pci_config_duration(struct rt2x00_dev *rt2x00dev,
  831. struct rt2x00lib_conf *libconf)
  832. {
  833. u32 reg;
  834. rt2x00pci_register_read(rt2x00dev, TXRX_CSR0, &reg);
  835. rt2x00_set_field32(&reg, TXRX_CSR0_TSF_OFFSET, IEEE80211_HEADER);
  836. rt2x00pci_register_write(rt2x00dev, TXRX_CSR0, reg);
  837. rt2x00pci_register_read(rt2x00dev, TXRX_CSR4, &reg);
  838. rt2x00_set_field32(&reg, TXRX_CSR4_AUTORESPOND_ENABLE, 1);
  839. rt2x00pci_register_write(rt2x00dev, TXRX_CSR4, reg);
  840. rt2x00pci_register_read(rt2x00dev, TXRX_CSR9, &reg);
  841. rt2x00_set_field32(&reg, TXRX_CSR9_BEACON_INTERVAL,
  842. libconf->conf->beacon_int * 16);
  843. rt2x00pci_register_write(rt2x00dev, TXRX_CSR9, reg);
  844. }
  845. static void rt61pci_config(struct rt2x00_dev *rt2x00dev,
  846. struct rt2x00lib_conf *libconf,
  847. const unsigned int flags)
  848. {
  849. /* Always recalculate LNA gain before changing configuration */
  850. rt61pci_config_lna_gain(rt2x00dev, libconf);
  851. if (flags & IEEE80211_CONF_CHANGE_CHANNEL)
  852. rt61pci_config_channel(rt2x00dev, &libconf->rf,
  853. libconf->conf->power_level);
  854. if ((flags & IEEE80211_CONF_CHANGE_POWER) &&
  855. !(flags & IEEE80211_CONF_CHANGE_CHANNEL))
  856. rt61pci_config_txpower(rt2x00dev, libconf->conf->power_level);
  857. if (flags & IEEE80211_CONF_CHANGE_RETRY_LIMITS)
  858. rt61pci_config_retry_limit(rt2x00dev, libconf);
  859. if (flags & IEEE80211_CONF_CHANGE_BEACON_INTERVAL)
  860. rt61pci_config_duration(rt2x00dev, libconf);
  861. }
  862. /*
  863. * Link tuning
  864. */
  865. static void rt61pci_link_stats(struct rt2x00_dev *rt2x00dev,
  866. struct link_qual *qual)
  867. {
  868. u32 reg;
  869. /*
  870. * Update FCS error count from register.
  871. */
  872. rt2x00pci_register_read(rt2x00dev, STA_CSR0, &reg);
  873. qual->rx_failed = rt2x00_get_field32(reg, STA_CSR0_FCS_ERROR);
  874. /*
  875. * Update False CCA count from register.
  876. */
  877. rt2x00pci_register_read(rt2x00dev, STA_CSR1, &reg);
  878. qual->false_cca = rt2x00_get_field32(reg, STA_CSR1_FALSE_CCA_ERROR);
  879. }
  880. static void rt61pci_reset_tuner(struct rt2x00_dev *rt2x00dev)
  881. {
  882. rt61pci_bbp_write(rt2x00dev, 17, 0x20);
  883. rt2x00dev->link.vgc_level = 0x20;
  884. }
  885. static void rt61pci_link_tuner(struct rt2x00_dev *rt2x00dev)
  886. {
  887. int rssi = rt2x00_get_link_rssi(&rt2x00dev->link);
  888. u8 r17;
  889. u8 up_bound;
  890. u8 low_bound;
  891. rt61pci_bbp_read(rt2x00dev, 17, &r17);
  892. /*
  893. * Determine r17 bounds.
  894. */
  895. if (rt2x00dev->rx_status.band == IEEE80211_BAND_5GHZ) {
  896. low_bound = 0x28;
  897. up_bound = 0x48;
  898. if (test_bit(CONFIG_EXTERNAL_LNA_A, &rt2x00dev->flags)) {
  899. low_bound += 0x10;
  900. up_bound += 0x10;
  901. }
  902. } else {
  903. low_bound = 0x20;
  904. up_bound = 0x40;
  905. if (test_bit(CONFIG_EXTERNAL_LNA_BG, &rt2x00dev->flags)) {
  906. low_bound += 0x10;
  907. up_bound += 0x10;
  908. }
  909. }
  910. /*
  911. * If we are not associated, we should go straight to the
  912. * dynamic CCA tuning.
  913. */
  914. if (!rt2x00dev->intf_associated)
  915. goto dynamic_cca_tune;
  916. /*
  917. * Special big-R17 for very short distance
  918. */
  919. if (rssi >= -35) {
  920. if (r17 != 0x60)
  921. rt61pci_bbp_write(rt2x00dev, 17, 0x60);
  922. return;
  923. }
  924. /*
  925. * Special big-R17 for short distance
  926. */
  927. if (rssi >= -58) {
  928. if (r17 != up_bound)
  929. rt61pci_bbp_write(rt2x00dev, 17, up_bound);
  930. return;
  931. }
  932. /*
  933. * Special big-R17 for middle-short distance
  934. */
  935. if (rssi >= -66) {
  936. low_bound += 0x10;
  937. if (r17 != low_bound)
  938. rt61pci_bbp_write(rt2x00dev, 17, low_bound);
  939. return;
  940. }
  941. /*
  942. * Special mid-R17 for middle distance
  943. */
  944. if (rssi >= -74) {
  945. low_bound += 0x08;
  946. if (r17 != low_bound)
  947. rt61pci_bbp_write(rt2x00dev, 17, low_bound);
  948. return;
  949. }
  950. /*
  951. * Special case: Change up_bound based on the rssi.
  952. * Lower up_bound when rssi is weaker then -74 dBm.
  953. */
  954. up_bound -= 2 * (-74 - rssi);
  955. if (low_bound > up_bound)
  956. up_bound = low_bound;
  957. if (r17 > up_bound) {
  958. rt61pci_bbp_write(rt2x00dev, 17, up_bound);
  959. return;
  960. }
  961. dynamic_cca_tune:
  962. /*
  963. * r17 does not yet exceed upper limit, continue and base
  964. * the r17 tuning on the false CCA count.
  965. */
  966. if (rt2x00dev->link.qual.false_cca > 512 && r17 < up_bound) {
  967. if (++r17 > up_bound)
  968. r17 = up_bound;
  969. rt61pci_bbp_write(rt2x00dev, 17, r17);
  970. } else if (rt2x00dev->link.qual.false_cca < 100 && r17 > low_bound) {
  971. if (--r17 < low_bound)
  972. r17 = low_bound;
  973. rt61pci_bbp_write(rt2x00dev, 17, r17);
  974. }
  975. }
  976. /*
  977. * Firmware functions
  978. */
  979. static char *rt61pci_get_firmware_name(struct rt2x00_dev *rt2x00dev)
  980. {
  981. char *fw_name;
  982. switch (rt2x00dev->chip.rt) {
  983. case RT2561:
  984. fw_name = FIRMWARE_RT2561;
  985. break;
  986. case RT2561s:
  987. fw_name = FIRMWARE_RT2561s;
  988. break;
  989. case RT2661:
  990. fw_name = FIRMWARE_RT2661;
  991. break;
  992. default:
  993. fw_name = NULL;
  994. break;
  995. }
  996. return fw_name;
  997. }
  998. static u16 rt61pci_get_firmware_crc(const void *data, const size_t len)
  999. {
  1000. u16 crc;
  1001. /*
  1002. * Use the crc itu-t algorithm.
  1003. * The last 2 bytes in the firmware array are the crc checksum itself,
  1004. * this means that we should never pass those 2 bytes to the crc
  1005. * algorithm.
  1006. */
  1007. crc = crc_itu_t(0, data, len - 2);
  1008. crc = crc_itu_t_byte(crc, 0);
  1009. crc = crc_itu_t_byte(crc, 0);
  1010. return crc;
  1011. }
  1012. static int rt61pci_load_firmware(struct rt2x00_dev *rt2x00dev, const void *data,
  1013. const size_t len)
  1014. {
  1015. int i;
  1016. u32 reg;
  1017. /*
  1018. * Wait for stable hardware.
  1019. */
  1020. for (i = 0; i < 100; i++) {
  1021. rt2x00pci_register_read(rt2x00dev, MAC_CSR0, &reg);
  1022. if (reg)
  1023. break;
  1024. msleep(1);
  1025. }
  1026. if (!reg) {
  1027. ERROR(rt2x00dev, "Unstable hardware.\n");
  1028. return -EBUSY;
  1029. }
  1030. /*
  1031. * Prepare MCU and mailbox for firmware loading.
  1032. */
  1033. reg = 0;
  1034. rt2x00_set_field32(&reg, MCU_CNTL_CSR_RESET, 1);
  1035. rt2x00pci_register_write(rt2x00dev, MCU_CNTL_CSR, reg);
  1036. rt2x00pci_register_write(rt2x00dev, M2H_CMD_DONE_CSR, 0xffffffff);
  1037. rt2x00pci_register_write(rt2x00dev, H2M_MAILBOX_CSR, 0);
  1038. rt2x00pci_register_write(rt2x00dev, HOST_CMD_CSR, 0);
  1039. /*
  1040. * Write firmware to device.
  1041. */
  1042. reg = 0;
  1043. rt2x00_set_field32(&reg, MCU_CNTL_CSR_RESET, 1);
  1044. rt2x00_set_field32(&reg, MCU_CNTL_CSR_SELECT_BANK, 1);
  1045. rt2x00pci_register_write(rt2x00dev, MCU_CNTL_CSR, reg);
  1046. rt2x00pci_register_multiwrite(rt2x00dev, FIRMWARE_IMAGE_BASE,
  1047. data, len);
  1048. rt2x00_set_field32(&reg, MCU_CNTL_CSR_SELECT_BANK, 0);
  1049. rt2x00pci_register_write(rt2x00dev, MCU_CNTL_CSR, reg);
  1050. rt2x00_set_field32(&reg, MCU_CNTL_CSR_RESET, 0);
  1051. rt2x00pci_register_write(rt2x00dev, MCU_CNTL_CSR, reg);
  1052. for (i = 0; i < 100; i++) {
  1053. rt2x00pci_register_read(rt2x00dev, MCU_CNTL_CSR, &reg);
  1054. if (rt2x00_get_field32(reg, MCU_CNTL_CSR_READY))
  1055. break;
  1056. msleep(1);
  1057. }
  1058. if (i == 100) {
  1059. ERROR(rt2x00dev, "MCU Control register not ready.\n");
  1060. return -EBUSY;
  1061. }
  1062. /*
  1063. * Hardware needs another millisecond before it is ready.
  1064. */
  1065. msleep(1);
  1066. /*
  1067. * Reset MAC and BBP registers.
  1068. */
  1069. reg = 0;
  1070. rt2x00_set_field32(&reg, MAC_CSR1_SOFT_RESET, 1);
  1071. rt2x00_set_field32(&reg, MAC_CSR1_BBP_RESET, 1);
  1072. rt2x00pci_register_write(rt2x00dev, MAC_CSR1, reg);
  1073. rt2x00pci_register_read(rt2x00dev, MAC_CSR1, &reg);
  1074. rt2x00_set_field32(&reg, MAC_CSR1_SOFT_RESET, 0);
  1075. rt2x00_set_field32(&reg, MAC_CSR1_BBP_RESET, 0);
  1076. rt2x00pci_register_write(rt2x00dev, MAC_CSR1, reg);
  1077. rt2x00pci_register_read(rt2x00dev, MAC_CSR1, &reg);
  1078. rt2x00_set_field32(&reg, MAC_CSR1_HOST_READY, 1);
  1079. rt2x00pci_register_write(rt2x00dev, MAC_CSR1, reg);
  1080. return 0;
  1081. }
  1082. /*
  1083. * Initialization functions.
  1084. */
  1085. static void rt61pci_init_rxentry(struct rt2x00_dev *rt2x00dev,
  1086. struct queue_entry *entry)
  1087. {
  1088. struct queue_entry_priv_pci *entry_priv = entry->priv_data;
  1089. struct skb_frame_desc *skbdesc = get_skb_frame_desc(entry->skb);
  1090. u32 word;
  1091. rt2x00_desc_read(entry_priv->desc, 5, &word);
  1092. rt2x00_set_field32(&word, RXD_W5_BUFFER_PHYSICAL_ADDRESS,
  1093. skbdesc->skb_dma);
  1094. rt2x00_desc_write(entry_priv->desc, 5, word);
  1095. rt2x00_desc_read(entry_priv->desc, 0, &word);
  1096. rt2x00_set_field32(&word, RXD_W0_OWNER_NIC, 1);
  1097. rt2x00_desc_write(entry_priv->desc, 0, word);
  1098. }
  1099. static void rt61pci_init_txentry(struct rt2x00_dev *rt2x00dev,
  1100. struct queue_entry *entry)
  1101. {
  1102. struct queue_entry_priv_pci *entry_priv = entry->priv_data;
  1103. u32 word;
  1104. rt2x00_desc_read(entry_priv->desc, 0, &word);
  1105. rt2x00_set_field32(&word, TXD_W0_VALID, 0);
  1106. rt2x00_set_field32(&word, TXD_W0_OWNER_NIC, 0);
  1107. rt2x00_desc_write(entry_priv->desc, 0, word);
  1108. }
  1109. static int rt61pci_init_queues(struct rt2x00_dev *rt2x00dev)
  1110. {
  1111. struct queue_entry_priv_pci *entry_priv;
  1112. u32 reg;
  1113. /*
  1114. * Initialize registers.
  1115. */
  1116. rt2x00pci_register_read(rt2x00dev, TX_RING_CSR0, &reg);
  1117. rt2x00_set_field32(&reg, TX_RING_CSR0_AC0_RING_SIZE,
  1118. rt2x00dev->tx[0].limit);
  1119. rt2x00_set_field32(&reg, TX_RING_CSR0_AC1_RING_SIZE,
  1120. rt2x00dev->tx[1].limit);
  1121. rt2x00_set_field32(&reg, TX_RING_CSR0_AC2_RING_SIZE,
  1122. rt2x00dev->tx[2].limit);
  1123. rt2x00_set_field32(&reg, TX_RING_CSR0_AC3_RING_SIZE,
  1124. rt2x00dev->tx[3].limit);
  1125. rt2x00pci_register_write(rt2x00dev, TX_RING_CSR0, reg);
  1126. rt2x00pci_register_read(rt2x00dev, TX_RING_CSR1, &reg);
  1127. rt2x00_set_field32(&reg, TX_RING_CSR1_TXD_SIZE,
  1128. rt2x00dev->tx[0].desc_size / 4);
  1129. rt2x00pci_register_write(rt2x00dev, TX_RING_CSR1, reg);
  1130. entry_priv = rt2x00dev->tx[0].entries[0].priv_data;
  1131. rt2x00pci_register_read(rt2x00dev, AC0_BASE_CSR, &reg);
  1132. rt2x00_set_field32(&reg, AC0_BASE_CSR_RING_REGISTER,
  1133. entry_priv->desc_dma);
  1134. rt2x00pci_register_write(rt2x00dev, AC0_BASE_CSR, reg);
  1135. entry_priv = rt2x00dev->tx[1].entries[0].priv_data;
  1136. rt2x00pci_register_read(rt2x00dev, AC1_BASE_CSR, &reg);
  1137. rt2x00_set_field32(&reg, AC1_BASE_CSR_RING_REGISTER,
  1138. entry_priv->desc_dma);
  1139. rt2x00pci_register_write(rt2x00dev, AC1_BASE_CSR, reg);
  1140. entry_priv = rt2x00dev->tx[2].entries[0].priv_data;
  1141. rt2x00pci_register_read(rt2x00dev, AC2_BASE_CSR, &reg);
  1142. rt2x00_set_field32(&reg, AC2_BASE_CSR_RING_REGISTER,
  1143. entry_priv->desc_dma);
  1144. rt2x00pci_register_write(rt2x00dev, AC2_BASE_CSR, reg);
  1145. entry_priv = rt2x00dev->tx[3].entries[0].priv_data;
  1146. rt2x00pci_register_read(rt2x00dev, AC3_BASE_CSR, &reg);
  1147. rt2x00_set_field32(&reg, AC3_BASE_CSR_RING_REGISTER,
  1148. entry_priv->desc_dma);
  1149. rt2x00pci_register_write(rt2x00dev, AC3_BASE_CSR, reg);
  1150. rt2x00pci_register_read(rt2x00dev, RX_RING_CSR, &reg);
  1151. rt2x00_set_field32(&reg, RX_RING_CSR_RING_SIZE, rt2x00dev->rx->limit);
  1152. rt2x00_set_field32(&reg, RX_RING_CSR_RXD_SIZE,
  1153. rt2x00dev->rx->desc_size / 4);
  1154. rt2x00_set_field32(&reg, RX_RING_CSR_RXD_WRITEBACK_SIZE, 4);
  1155. rt2x00pci_register_write(rt2x00dev, RX_RING_CSR, reg);
  1156. entry_priv = rt2x00dev->rx->entries[0].priv_data;
  1157. rt2x00pci_register_read(rt2x00dev, RX_BASE_CSR, &reg);
  1158. rt2x00_set_field32(&reg, RX_BASE_CSR_RING_REGISTER,
  1159. entry_priv->desc_dma);
  1160. rt2x00pci_register_write(rt2x00dev, RX_BASE_CSR, reg);
  1161. rt2x00pci_register_read(rt2x00dev, TX_DMA_DST_CSR, &reg);
  1162. rt2x00_set_field32(&reg, TX_DMA_DST_CSR_DEST_AC0, 2);
  1163. rt2x00_set_field32(&reg, TX_DMA_DST_CSR_DEST_AC1, 2);
  1164. rt2x00_set_field32(&reg, TX_DMA_DST_CSR_DEST_AC2, 2);
  1165. rt2x00_set_field32(&reg, TX_DMA_DST_CSR_DEST_AC3, 2);
  1166. rt2x00pci_register_write(rt2x00dev, TX_DMA_DST_CSR, reg);
  1167. rt2x00pci_register_read(rt2x00dev, LOAD_TX_RING_CSR, &reg);
  1168. rt2x00_set_field32(&reg, LOAD_TX_RING_CSR_LOAD_TXD_AC0, 1);
  1169. rt2x00_set_field32(&reg, LOAD_TX_RING_CSR_LOAD_TXD_AC1, 1);
  1170. rt2x00_set_field32(&reg, LOAD_TX_RING_CSR_LOAD_TXD_AC2, 1);
  1171. rt2x00_set_field32(&reg, LOAD_TX_RING_CSR_LOAD_TXD_AC3, 1);
  1172. rt2x00pci_register_write(rt2x00dev, LOAD_TX_RING_CSR, reg);
  1173. rt2x00pci_register_read(rt2x00dev, RX_CNTL_CSR, &reg);
  1174. rt2x00_set_field32(&reg, RX_CNTL_CSR_LOAD_RXD, 1);
  1175. rt2x00pci_register_write(rt2x00dev, RX_CNTL_CSR, reg);
  1176. return 0;
  1177. }
  1178. static int rt61pci_init_registers(struct rt2x00_dev *rt2x00dev)
  1179. {
  1180. u32 reg;
  1181. rt2x00pci_register_read(rt2x00dev, TXRX_CSR0, &reg);
  1182. rt2x00_set_field32(&reg, TXRX_CSR0_AUTO_TX_SEQ, 1);
  1183. rt2x00_set_field32(&reg, TXRX_CSR0_DISABLE_RX, 0);
  1184. rt2x00_set_field32(&reg, TXRX_CSR0_TX_WITHOUT_WAITING, 0);
  1185. rt2x00pci_register_write(rt2x00dev, TXRX_CSR0, reg);
  1186. rt2x00pci_register_read(rt2x00dev, TXRX_CSR1, &reg);
  1187. rt2x00_set_field32(&reg, TXRX_CSR1_BBP_ID0, 47); /* CCK Signal */
  1188. rt2x00_set_field32(&reg, TXRX_CSR1_BBP_ID0_VALID, 1);
  1189. rt2x00_set_field32(&reg, TXRX_CSR1_BBP_ID1, 30); /* Rssi */
  1190. rt2x00_set_field32(&reg, TXRX_CSR1_BBP_ID1_VALID, 1);
  1191. rt2x00_set_field32(&reg, TXRX_CSR1_BBP_ID2, 42); /* OFDM Rate */
  1192. rt2x00_set_field32(&reg, TXRX_CSR1_BBP_ID2_VALID, 1);
  1193. rt2x00_set_field32(&reg, TXRX_CSR1_BBP_ID3, 30); /* Rssi */
  1194. rt2x00_set_field32(&reg, TXRX_CSR1_BBP_ID3_VALID, 1);
  1195. rt2x00pci_register_write(rt2x00dev, TXRX_CSR1, reg);
  1196. /*
  1197. * CCK TXD BBP registers
  1198. */
  1199. rt2x00pci_register_read(rt2x00dev, TXRX_CSR2, &reg);
  1200. rt2x00_set_field32(&reg, TXRX_CSR2_BBP_ID0, 13);
  1201. rt2x00_set_field32(&reg, TXRX_CSR2_BBP_ID0_VALID, 1);
  1202. rt2x00_set_field32(&reg, TXRX_CSR2_BBP_ID1, 12);
  1203. rt2x00_set_field32(&reg, TXRX_CSR2_BBP_ID1_VALID, 1);
  1204. rt2x00_set_field32(&reg, TXRX_CSR2_BBP_ID2, 11);
  1205. rt2x00_set_field32(&reg, TXRX_CSR2_BBP_ID2_VALID, 1);
  1206. rt2x00_set_field32(&reg, TXRX_CSR2_BBP_ID3, 10);
  1207. rt2x00_set_field32(&reg, TXRX_CSR2_BBP_ID3_VALID, 1);
  1208. rt2x00pci_register_write(rt2x00dev, TXRX_CSR2, reg);
  1209. /*
  1210. * OFDM TXD BBP registers
  1211. */
  1212. rt2x00pci_register_read(rt2x00dev, TXRX_CSR3, &reg);
  1213. rt2x00_set_field32(&reg, TXRX_CSR3_BBP_ID0, 7);
  1214. rt2x00_set_field32(&reg, TXRX_CSR3_BBP_ID0_VALID, 1);
  1215. rt2x00_set_field32(&reg, TXRX_CSR3_BBP_ID1, 6);
  1216. rt2x00_set_field32(&reg, TXRX_CSR3_BBP_ID1_VALID, 1);
  1217. rt2x00_set_field32(&reg, TXRX_CSR3_BBP_ID2, 5);
  1218. rt2x00_set_field32(&reg, TXRX_CSR3_BBP_ID2_VALID, 1);
  1219. rt2x00pci_register_write(rt2x00dev, TXRX_CSR3, reg);
  1220. rt2x00pci_register_read(rt2x00dev, TXRX_CSR7, &reg);
  1221. rt2x00_set_field32(&reg, TXRX_CSR7_ACK_CTS_6MBS, 59);
  1222. rt2x00_set_field32(&reg, TXRX_CSR7_ACK_CTS_9MBS, 53);
  1223. rt2x00_set_field32(&reg, TXRX_CSR7_ACK_CTS_12MBS, 49);
  1224. rt2x00_set_field32(&reg, TXRX_CSR7_ACK_CTS_18MBS, 46);
  1225. rt2x00pci_register_write(rt2x00dev, TXRX_CSR7, reg);
  1226. rt2x00pci_register_read(rt2x00dev, TXRX_CSR8, &reg);
  1227. rt2x00_set_field32(&reg, TXRX_CSR8_ACK_CTS_24MBS, 44);
  1228. rt2x00_set_field32(&reg, TXRX_CSR8_ACK_CTS_36MBS, 42);
  1229. rt2x00_set_field32(&reg, TXRX_CSR8_ACK_CTS_48MBS, 42);
  1230. rt2x00_set_field32(&reg, TXRX_CSR8_ACK_CTS_54MBS, 42);
  1231. rt2x00pci_register_write(rt2x00dev, TXRX_CSR8, reg);
  1232. rt2x00pci_register_read(rt2x00dev, TXRX_CSR9, &reg);
  1233. rt2x00_set_field32(&reg, TXRX_CSR9_BEACON_INTERVAL, 0);
  1234. rt2x00_set_field32(&reg, TXRX_CSR9_TSF_TICKING, 0);
  1235. rt2x00_set_field32(&reg, TXRX_CSR9_TSF_SYNC, 0);
  1236. rt2x00_set_field32(&reg, TXRX_CSR9_TBTT_ENABLE, 0);
  1237. rt2x00_set_field32(&reg, TXRX_CSR9_BEACON_GEN, 0);
  1238. rt2x00_set_field32(&reg, TXRX_CSR9_TIMESTAMP_COMPENSATE, 0);
  1239. rt2x00pci_register_write(rt2x00dev, TXRX_CSR9, reg);
  1240. rt2x00pci_register_write(rt2x00dev, TXRX_CSR15, 0x0000000f);
  1241. rt2x00pci_register_write(rt2x00dev, MAC_CSR6, 0x00000fff);
  1242. rt2x00pci_register_read(rt2x00dev, MAC_CSR9, &reg);
  1243. rt2x00_set_field32(&reg, MAC_CSR9_CW_SELECT, 0);
  1244. rt2x00pci_register_write(rt2x00dev, MAC_CSR9, reg);
  1245. rt2x00pci_register_write(rt2x00dev, MAC_CSR10, 0x0000071c);
  1246. if (rt2x00dev->ops->lib->set_device_state(rt2x00dev, STATE_AWAKE))
  1247. return -EBUSY;
  1248. rt2x00pci_register_write(rt2x00dev, MAC_CSR13, 0x0000e000);
  1249. /*
  1250. * Invalidate all Shared Keys (SEC_CSR0),
  1251. * and clear the Shared key Cipher algorithms (SEC_CSR1 & SEC_CSR5)
  1252. */
  1253. rt2x00pci_register_write(rt2x00dev, SEC_CSR0, 0x00000000);
  1254. rt2x00pci_register_write(rt2x00dev, SEC_CSR1, 0x00000000);
  1255. rt2x00pci_register_write(rt2x00dev, SEC_CSR5, 0x00000000);
  1256. rt2x00pci_register_write(rt2x00dev, PHY_CSR1, 0x000023b0);
  1257. rt2x00pci_register_write(rt2x00dev, PHY_CSR5, 0x060a100c);
  1258. rt2x00pci_register_write(rt2x00dev, PHY_CSR6, 0x00080606);
  1259. rt2x00pci_register_write(rt2x00dev, PHY_CSR7, 0x00000a08);
  1260. rt2x00pci_register_write(rt2x00dev, PCI_CFG_CSR, 0x28ca4404);
  1261. rt2x00pci_register_write(rt2x00dev, TEST_MODE_CSR, 0x00000200);
  1262. rt2x00pci_register_write(rt2x00dev, M2H_CMD_DONE_CSR, 0xffffffff);
  1263. /*
  1264. * Clear all beacons
  1265. * For the Beacon base registers we only need to clear
  1266. * the first byte since that byte contains the VALID and OWNER
  1267. * bits which (when set to 0) will invalidate the entire beacon.
  1268. */
  1269. rt2x00pci_register_write(rt2x00dev, HW_BEACON_BASE0, 0);
  1270. rt2x00pci_register_write(rt2x00dev, HW_BEACON_BASE1, 0);
  1271. rt2x00pci_register_write(rt2x00dev, HW_BEACON_BASE2, 0);
  1272. rt2x00pci_register_write(rt2x00dev, HW_BEACON_BASE3, 0);
  1273. /*
  1274. * We must clear the error counters.
  1275. * These registers are cleared on read,
  1276. * so we may pass a useless variable to store the value.
  1277. */
  1278. rt2x00pci_register_read(rt2x00dev, STA_CSR0, &reg);
  1279. rt2x00pci_register_read(rt2x00dev, STA_CSR1, &reg);
  1280. rt2x00pci_register_read(rt2x00dev, STA_CSR2, &reg);
  1281. /*
  1282. * Reset MAC and BBP registers.
  1283. */
  1284. rt2x00pci_register_read(rt2x00dev, MAC_CSR1, &reg);
  1285. rt2x00_set_field32(&reg, MAC_CSR1_SOFT_RESET, 1);
  1286. rt2x00_set_field32(&reg, MAC_CSR1_BBP_RESET, 1);
  1287. rt2x00pci_register_write(rt2x00dev, MAC_CSR1, reg);
  1288. rt2x00pci_register_read(rt2x00dev, MAC_CSR1, &reg);
  1289. rt2x00_set_field32(&reg, MAC_CSR1_SOFT_RESET, 0);
  1290. rt2x00_set_field32(&reg, MAC_CSR1_BBP_RESET, 0);
  1291. rt2x00pci_register_write(rt2x00dev, MAC_CSR1, reg);
  1292. rt2x00pci_register_read(rt2x00dev, MAC_CSR1, &reg);
  1293. rt2x00_set_field32(&reg, MAC_CSR1_HOST_READY, 1);
  1294. rt2x00pci_register_write(rt2x00dev, MAC_CSR1, reg);
  1295. return 0;
  1296. }
  1297. static int rt61pci_wait_bbp_ready(struct rt2x00_dev *rt2x00dev)
  1298. {
  1299. unsigned int i;
  1300. u8 value;
  1301. for (i = 0; i < REGISTER_BUSY_COUNT; i++) {
  1302. rt61pci_bbp_read(rt2x00dev, 0, &value);
  1303. if ((value != 0xff) && (value != 0x00))
  1304. return 0;
  1305. udelay(REGISTER_BUSY_DELAY);
  1306. }
  1307. ERROR(rt2x00dev, "BBP register access failed, aborting.\n");
  1308. return -EACCES;
  1309. }
  1310. static int rt61pci_init_bbp(struct rt2x00_dev *rt2x00dev)
  1311. {
  1312. unsigned int i;
  1313. u16 eeprom;
  1314. u8 reg_id;
  1315. u8 value;
  1316. if (unlikely(rt61pci_wait_bbp_ready(rt2x00dev)))
  1317. return -EACCES;
  1318. rt61pci_bbp_write(rt2x00dev, 3, 0x00);
  1319. rt61pci_bbp_write(rt2x00dev, 15, 0x30);
  1320. rt61pci_bbp_write(rt2x00dev, 21, 0xc8);
  1321. rt61pci_bbp_write(rt2x00dev, 22, 0x38);
  1322. rt61pci_bbp_write(rt2x00dev, 23, 0x06);
  1323. rt61pci_bbp_write(rt2x00dev, 24, 0xfe);
  1324. rt61pci_bbp_write(rt2x00dev, 25, 0x0a);
  1325. rt61pci_bbp_write(rt2x00dev, 26, 0x0d);
  1326. rt61pci_bbp_write(rt2x00dev, 34, 0x12);
  1327. rt61pci_bbp_write(rt2x00dev, 37, 0x07);
  1328. rt61pci_bbp_write(rt2x00dev, 39, 0xf8);
  1329. rt61pci_bbp_write(rt2x00dev, 41, 0x60);
  1330. rt61pci_bbp_write(rt2x00dev, 53, 0x10);
  1331. rt61pci_bbp_write(rt2x00dev, 54, 0x18);
  1332. rt61pci_bbp_write(rt2x00dev, 60, 0x10);
  1333. rt61pci_bbp_write(rt2x00dev, 61, 0x04);
  1334. rt61pci_bbp_write(rt2x00dev, 62, 0x04);
  1335. rt61pci_bbp_write(rt2x00dev, 75, 0xfe);
  1336. rt61pci_bbp_write(rt2x00dev, 86, 0xfe);
  1337. rt61pci_bbp_write(rt2x00dev, 88, 0xfe);
  1338. rt61pci_bbp_write(rt2x00dev, 90, 0x0f);
  1339. rt61pci_bbp_write(rt2x00dev, 99, 0x00);
  1340. rt61pci_bbp_write(rt2x00dev, 102, 0x16);
  1341. rt61pci_bbp_write(rt2x00dev, 107, 0x04);
  1342. for (i = 0; i < EEPROM_BBP_SIZE; i++) {
  1343. rt2x00_eeprom_read(rt2x00dev, EEPROM_BBP_START + i, &eeprom);
  1344. if (eeprom != 0xffff && eeprom != 0x0000) {
  1345. reg_id = rt2x00_get_field16(eeprom, EEPROM_BBP_REG_ID);
  1346. value = rt2x00_get_field16(eeprom, EEPROM_BBP_VALUE);
  1347. rt61pci_bbp_write(rt2x00dev, reg_id, value);
  1348. }
  1349. }
  1350. return 0;
  1351. }
  1352. /*
  1353. * Device state switch handlers.
  1354. */
  1355. static void rt61pci_toggle_rx(struct rt2x00_dev *rt2x00dev,
  1356. enum dev_state state)
  1357. {
  1358. u32 reg;
  1359. rt2x00pci_register_read(rt2x00dev, TXRX_CSR0, &reg);
  1360. rt2x00_set_field32(&reg, TXRX_CSR0_DISABLE_RX,
  1361. (state == STATE_RADIO_RX_OFF) ||
  1362. (state == STATE_RADIO_RX_OFF_LINK));
  1363. rt2x00pci_register_write(rt2x00dev, TXRX_CSR0, reg);
  1364. }
  1365. static void rt61pci_toggle_irq(struct rt2x00_dev *rt2x00dev,
  1366. enum dev_state state)
  1367. {
  1368. int mask = (state == STATE_RADIO_IRQ_OFF);
  1369. u32 reg;
  1370. /*
  1371. * When interrupts are being enabled, the interrupt registers
  1372. * should clear the register to assure a clean state.
  1373. */
  1374. if (state == STATE_RADIO_IRQ_ON) {
  1375. rt2x00pci_register_read(rt2x00dev, INT_SOURCE_CSR, &reg);
  1376. rt2x00pci_register_write(rt2x00dev, INT_SOURCE_CSR, reg);
  1377. rt2x00pci_register_read(rt2x00dev, MCU_INT_SOURCE_CSR, &reg);
  1378. rt2x00pci_register_write(rt2x00dev, MCU_INT_SOURCE_CSR, reg);
  1379. }
  1380. /*
  1381. * Only toggle the interrupts bits we are going to use.
  1382. * Non-checked interrupt bits are disabled by default.
  1383. */
  1384. rt2x00pci_register_read(rt2x00dev, INT_MASK_CSR, &reg);
  1385. rt2x00_set_field32(&reg, INT_MASK_CSR_TXDONE, mask);
  1386. rt2x00_set_field32(&reg, INT_MASK_CSR_RXDONE, mask);
  1387. rt2x00_set_field32(&reg, INT_MASK_CSR_ENABLE_MITIGATION, mask);
  1388. rt2x00_set_field32(&reg, INT_MASK_CSR_MITIGATION_PERIOD, 0xff);
  1389. rt2x00pci_register_write(rt2x00dev, INT_MASK_CSR, reg);
  1390. rt2x00pci_register_read(rt2x00dev, MCU_INT_MASK_CSR, &reg);
  1391. rt2x00_set_field32(&reg, MCU_INT_MASK_CSR_0, mask);
  1392. rt2x00_set_field32(&reg, MCU_INT_MASK_CSR_1, mask);
  1393. rt2x00_set_field32(&reg, MCU_INT_MASK_CSR_2, mask);
  1394. rt2x00_set_field32(&reg, MCU_INT_MASK_CSR_3, mask);
  1395. rt2x00_set_field32(&reg, MCU_INT_MASK_CSR_4, mask);
  1396. rt2x00_set_field32(&reg, MCU_INT_MASK_CSR_5, mask);
  1397. rt2x00_set_field32(&reg, MCU_INT_MASK_CSR_6, mask);
  1398. rt2x00_set_field32(&reg, MCU_INT_MASK_CSR_7, mask);
  1399. rt2x00pci_register_write(rt2x00dev, MCU_INT_MASK_CSR, reg);
  1400. }
  1401. static int rt61pci_enable_radio(struct rt2x00_dev *rt2x00dev)
  1402. {
  1403. u32 reg;
  1404. /*
  1405. * Initialize all registers.
  1406. */
  1407. if (unlikely(rt61pci_init_queues(rt2x00dev) ||
  1408. rt61pci_init_registers(rt2x00dev) ||
  1409. rt61pci_init_bbp(rt2x00dev)))
  1410. return -EIO;
  1411. /*
  1412. * Enable RX.
  1413. */
  1414. rt2x00pci_register_read(rt2x00dev, RX_CNTL_CSR, &reg);
  1415. rt2x00_set_field32(&reg, RX_CNTL_CSR_ENABLE_RX_DMA, 1);
  1416. rt2x00pci_register_write(rt2x00dev, RX_CNTL_CSR, reg);
  1417. return 0;
  1418. }
  1419. static void rt61pci_disable_radio(struct rt2x00_dev *rt2x00dev)
  1420. {
  1421. u32 reg;
  1422. rt2x00pci_register_write(rt2x00dev, MAC_CSR10, 0x00001818);
  1423. /*
  1424. * Disable synchronisation.
  1425. */
  1426. rt2x00pci_register_write(rt2x00dev, TXRX_CSR9, 0);
  1427. /*
  1428. * Cancel RX and TX.
  1429. */
  1430. rt2x00pci_register_read(rt2x00dev, TX_CNTL_CSR, &reg);
  1431. rt2x00_set_field32(&reg, TX_CNTL_CSR_ABORT_TX_AC0, 1);
  1432. rt2x00_set_field32(&reg, TX_CNTL_CSR_ABORT_TX_AC1, 1);
  1433. rt2x00_set_field32(&reg, TX_CNTL_CSR_ABORT_TX_AC2, 1);
  1434. rt2x00_set_field32(&reg, TX_CNTL_CSR_ABORT_TX_AC3, 1);
  1435. rt2x00pci_register_write(rt2x00dev, TX_CNTL_CSR, reg);
  1436. }
  1437. static int rt61pci_set_state(struct rt2x00_dev *rt2x00dev, enum dev_state state)
  1438. {
  1439. u32 reg;
  1440. unsigned int i;
  1441. char put_to_sleep;
  1442. put_to_sleep = (state != STATE_AWAKE);
  1443. rt2x00pci_register_read(rt2x00dev, MAC_CSR12, &reg);
  1444. rt2x00_set_field32(&reg, MAC_CSR12_FORCE_WAKEUP, !put_to_sleep);
  1445. rt2x00_set_field32(&reg, MAC_CSR12_PUT_TO_SLEEP, put_to_sleep);
  1446. rt2x00pci_register_write(rt2x00dev, MAC_CSR12, reg);
  1447. /*
  1448. * Device is not guaranteed to be in the requested state yet.
  1449. * We must wait until the register indicates that the
  1450. * device has entered the correct state.
  1451. */
  1452. for (i = 0; i < REGISTER_BUSY_COUNT; i++) {
  1453. rt2x00pci_register_read(rt2x00dev, MAC_CSR12, &reg);
  1454. state = rt2x00_get_field32(reg, MAC_CSR12_BBP_CURRENT_STATE);
  1455. if (state == !put_to_sleep)
  1456. return 0;
  1457. msleep(10);
  1458. }
  1459. return -EBUSY;
  1460. }
  1461. static int rt61pci_set_device_state(struct rt2x00_dev *rt2x00dev,
  1462. enum dev_state state)
  1463. {
  1464. int retval = 0;
  1465. switch (state) {
  1466. case STATE_RADIO_ON:
  1467. retval = rt61pci_enable_radio(rt2x00dev);
  1468. break;
  1469. case STATE_RADIO_OFF:
  1470. rt61pci_disable_radio(rt2x00dev);
  1471. break;
  1472. case STATE_RADIO_RX_ON:
  1473. case STATE_RADIO_RX_ON_LINK:
  1474. case STATE_RADIO_RX_OFF:
  1475. case STATE_RADIO_RX_OFF_LINK:
  1476. rt61pci_toggle_rx(rt2x00dev, state);
  1477. break;
  1478. case STATE_RADIO_IRQ_ON:
  1479. case STATE_RADIO_IRQ_OFF:
  1480. rt61pci_toggle_irq(rt2x00dev, state);
  1481. break;
  1482. case STATE_DEEP_SLEEP:
  1483. case STATE_SLEEP:
  1484. case STATE_STANDBY:
  1485. case STATE_AWAKE:
  1486. retval = rt61pci_set_state(rt2x00dev, state);
  1487. break;
  1488. default:
  1489. retval = -ENOTSUPP;
  1490. break;
  1491. }
  1492. if (unlikely(retval))
  1493. ERROR(rt2x00dev, "Device failed to enter state %d (%d).\n",
  1494. state, retval);
  1495. return retval;
  1496. }
  1497. /*
  1498. * TX descriptor initialization
  1499. */
  1500. static void rt61pci_write_tx_desc(struct rt2x00_dev *rt2x00dev,
  1501. struct sk_buff *skb,
  1502. struct txentry_desc *txdesc)
  1503. {
  1504. struct skb_frame_desc *skbdesc = get_skb_frame_desc(skb);
  1505. __le32 *txd = skbdesc->desc;
  1506. u32 word;
  1507. /*
  1508. * Start writing the descriptor words.
  1509. */
  1510. rt2x00_desc_read(txd, 1, &word);
  1511. rt2x00_set_field32(&word, TXD_W1_HOST_Q_ID, txdesc->queue);
  1512. rt2x00_set_field32(&word, TXD_W1_AIFSN, txdesc->aifs);
  1513. rt2x00_set_field32(&word, TXD_W1_CWMIN, txdesc->cw_min);
  1514. rt2x00_set_field32(&word, TXD_W1_CWMAX, txdesc->cw_max);
  1515. rt2x00_set_field32(&word, TXD_W1_IV_OFFSET, txdesc->iv_offset);
  1516. rt2x00_set_field32(&word, TXD_W1_HW_SEQUENCE,
  1517. test_bit(ENTRY_TXD_GENERATE_SEQ, &txdesc->flags));
  1518. rt2x00_set_field32(&word, TXD_W1_BUFFER_COUNT, 1);
  1519. rt2x00_desc_write(txd, 1, word);
  1520. rt2x00_desc_read(txd, 2, &word);
  1521. rt2x00_set_field32(&word, TXD_W2_PLCP_SIGNAL, txdesc->signal);
  1522. rt2x00_set_field32(&word, TXD_W2_PLCP_SERVICE, txdesc->service);
  1523. rt2x00_set_field32(&word, TXD_W2_PLCP_LENGTH_LOW, txdesc->length_low);
  1524. rt2x00_set_field32(&word, TXD_W2_PLCP_LENGTH_HIGH, txdesc->length_high);
  1525. rt2x00_desc_write(txd, 2, word);
  1526. if (test_bit(ENTRY_TXD_ENCRYPT, &txdesc->flags)) {
  1527. _rt2x00_desc_write(txd, 3, skbdesc->iv);
  1528. _rt2x00_desc_write(txd, 4, skbdesc->eiv);
  1529. }
  1530. rt2x00_desc_read(txd, 5, &word);
  1531. rt2x00_set_field32(&word, TXD_W5_PID_TYPE, skbdesc->entry->queue->qid);
  1532. rt2x00_set_field32(&word, TXD_W5_PID_SUBTYPE,
  1533. skbdesc->entry->entry_idx);
  1534. rt2x00_set_field32(&word, TXD_W5_TX_POWER,
  1535. TXPOWER_TO_DEV(rt2x00dev->tx_power));
  1536. rt2x00_set_field32(&word, TXD_W5_WAITING_DMA_DONE_INT, 1);
  1537. rt2x00_desc_write(txd, 5, word);
  1538. rt2x00_desc_read(txd, 6, &word);
  1539. rt2x00_set_field32(&word, TXD_W6_BUFFER_PHYSICAL_ADDRESS,
  1540. skbdesc->skb_dma);
  1541. rt2x00_desc_write(txd, 6, word);
  1542. if (skbdesc->desc_len > TXINFO_SIZE) {
  1543. rt2x00_desc_read(txd, 11, &word);
  1544. rt2x00_set_field32(&word, TXD_W11_BUFFER_LENGTH0, skb->len);
  1545. rt2x00_desc_write(txd, 11, word);
  1546. }
  1547. rt2x00_desc_read(txd, 0, &word);
  1548. rt2x00_set_field32(&word, TXD_W0_OWNER_NIC, 1);
  1549. rt2x00_set_field32(&word, TXD_W0_VALID, 1);
  1550. rt2x00_set_field32(&word, TXD_W0_MORE_FRAG,
  1551. test_bit(ENTRY_TXD_MORE_FRAG, &txdesc->flags));
  1552. rt2x00_set_field32(&word, TXD_W0_ACK,
  1553. test_bit(ENTRY_TXD_ACK, &txdesc->flags));
  1554. rt2x00_set_field32(&word, TXD_W0_TIMESTAMP,
  1555. test_bit(ENTRY_TXD_REQ_TIMESTAMP, &txdesc->flags));
  1556. rt2x00_set_field32(&word, TXD_W0_OFDM,
  1557. test_bit(ENTRY_TXD_OFDM_RATE, &txdesc->flags));
  1558. rt2x00_set_field32(&word, TXD_W0_IFS, txdesc->ifs);
  1559. rt2x00_set_field32(&word, TXD_W0_RETRY_MODE,
  1560. test_bit(ENTRY_TXD_RETRY_MODE, &txdesc->flags));
  1561. rt2x00_set_field32(&word, TXD_W0_TKIP_MIC,
  1562. test_bit(ENTRY_TXD_ENCRYPT_MMIC, &txdesc->flags));
  1563. rt2x00_set_field32(&word, TXD_W0_KEY_TABLE,
  1564. test_bit(ENTRY_TXD_ENCRYPT_PAIRWISE, &txdesc->flags));
  1565. rt2x00_set_field32(&word, TXD_W0_KEY_INDEX, txdesc->key_idx);
  1566. rt2x00_set_field32(&word, TXD_W0_DATABYTE_COUNT, skb->len);
  1567. rt2x00_set_field32(&word, TXD_W0_BURST,
  1568. test_bit(ENTRY_TXD_BURST, &txdesc->flags));
  1569. rt2x00_set_field32(&word, TXD_W0_CIPHER_ALG, txdesc->cipher);
  1570. rt2x00_desc_write(txd, 0, word);
  1571. }
  1572. /*
  1573. * TX data initialization
  1574. */
  1575. static void rt61pci_write_beacon(struct queue_entry *entry)
  1576. {
  1577. struct rt2x00_dev *rt2x00dev = entry->queue->rt2x00dev;
  1578. struct skb_frame_desc *skbdesc = get_skb_frame_desc(entry->skb);
  1579. unsigned int beacon_base;
  1580. u32 reg;
  1581. /*
  1582. * Disable beaconing while we are reloading the beacon data,
  1583. * otherwise we might be sending out invalid data.
  1584. */
  1585. rt2x00pci_register_read(rt2x00dev, TXRX_CSR9, &reg);
  1586. rt2x00_set_field32(&reg, TXRX_CSR9_TSF_TICKING, 0);
  1587. rt2x00_set_field32(&reg, TXRX_CSR9_TBTT_ENABLE, 0);
  1588. rt2x00_set_field32(&reg, TXRX_CSR9_BEACON_GEN, 0);
  1589. rt2x00pci_register_write(rt2x00dev, TXRX_CSR9, reg);
  1590. /*
  1591. * Write entire beacon with descriptor to register.
  1592. */
  1593. beacon_base = HW_BEACON_OFFSET(entry->entry_idx);
  1594. rt2x00pci_register_multiwrite(rt2x00dev,
  1595. beacon_base,
  1596. skbdesc->desc, skbdesc->desc_len);
  1597. rt2x00pci_register_multiwrite(rt2x00dev,
  1598. beacon_base + skbdesc->desc_len,
  1599. entry->skb->data, entry->skb->len);
  1600. /*
  1601. * Clean up beacon skb.
  1602. */
  1603. dev_kfree_skb_any(entry->skb);
  1604. entry->skb = NULL;
  1605. }
  1606. static void rt61pci_kick_tx_queue(struct rt2x00_dev *rt2x00dev,
  1607. const enum data_queue_qid queue)
  1608. {
  1609. u32 reg;
  1610. if (queue == QID_BEACON) {
  1611. /*
  1612. * For Wi-Fi faily generated beacons between participating
  1613. * stations. Set TBTT phase adaptive adjustment step to 8us.
  1614. */
  1615. rt2x00pci_register_write(rt2x00dev, TXRX_CSR10, 0x00001008);
  1616. rt2x00pci_register_read(rt2x00dev, TXRX_CSR9, &reg);
  1617. if (!rt2x00_get_field32(reg, TXRX_CSR9_BEACON_GEN)) {
  1618. rt2x00_set_field32(&reg, TXRX_CSR9_TSF_TICKING, 1);
  1619. rt2x00_set_field32(&reg, TXRX_CSR9_TBTT_ENABLE, 1);
  1620. rt2x00_set_field32(&reg, TXRX_CSR9_BEACON_GEN, 1);
  1621. rt2x00pci_register_write(rt2x00dev, TXRX_CSR9, reg);
  1622. }
  1623. return;
  1624. }
  1625. rt2x00pci_register_read(rt2x00dev, TX_CNTL_CSR, &reg);
  1626. rt2x00_set_field32(&reg, TX_CNTL_CSR_KICK_TX_AC0, (queue == QID_AC_BE));
  1627. rt2x00_set_field32(&reg, TX_CNTL_CSR_KICK_TX_AC1, (queue == QID_AC_BK));
  1628. rt2x00_set_field32(&reg, TX_CNTL_CSR_KICK_TX_AC2, (queue == QID_AC_VI));
  1629. rt2x00_set_field32(&reg, TX_CNTL_CSR_KICK_TX_AC3, (queue == QID_AC_VO));
  1630. rt2x00pci_register_write(rt2x00dev, TX_CNTL_CSR, reg);
  1631. }
  1632. /*
  1633. * RX control handlers
  1634. */
  1635. static int rt61pci_agc_to_rssi(struct rt2x00_dev *rt2x00dev, int rxd_w1)
  1636. {
  1637. u8 offset = rt2x00dev->lna_gain;
  1638. u8 lna;
  1639. lna = rt2x00_get_field32(rxd_w1, RXD_W1_RSSI_LNA);
  1640. switch (lna) {
  1641. case 3:
  1642. offset += 90;
  1643. break;
  1644. case 2:
  1645. offset += 74;
  1646. break;
  1647. case 1:
  1648. offset += 64;
  1649. break;
  1650. default:
  1651. return 0;
  1652. }
  1653. if (rt2x00dev->rx_status.band == IEEE80211_BAND_5GHZ) {
  1654. if (lna == 3 || lna == 2)
  1655. offset += 10;
  1656. }
  1657. return rt2x00_get_field32(rxd_w1, RXD_W1_RSSI_AGC) * 2 - offset;
  1658. }
  1659. static void rt61pci_fill_rxdone(struct queue_entry *entry,
  1660. struct rxdone_entry_desc *rxdesc)
  1661. {
  1662. struct rt2x00_dev *rt2x00dev = entry->queue->rt2x00dev;
  1663. struct queue_entry_priv_pci *entry_priv = entry->priv_data;
  1664. u32 word0;
  1665. u32 word1;
  1666. rt2x00_desc_read(entry_priv->desc, 0, &word0);
  1667. rt2x00_desc_read(entry_priv->desc, 1, &word1);
  1668. if (rt2x00_get_field32(word0, RXD_W0_CRC_ERROR))
  1669. rxdesc->flags |= RX_FLAG_FAILED_FCS_CRC;
  1670. if (test_bit(CONFIG_SUPPORT_HW_CRYPTO, &rt2x00dev->flags)) {
  1671. rxdesc->cipher =
  1672. rt2x00_get_field32(word0, RXD_W0_CIPHER_ALG);
  1673. rxdesc->cipher_status =
  1674. rt2x00_get_field32(word0, RXD_W0_CIPHER_ERROR);
  1675. }
  1676. if (rxdesc->cipher != CIPHER_NONE) {
  1677. _rt2x00_desc_read(entry_priv->desc, 2, &rxdesc->iv);
  1678. _rt2x00_desc_read(entry_priv->desc, 3, &rxdesc->eiv);
  1679. _rt2x00_desc_read(entry_priv->desc, 4, &rxdesc->icv);
  1680. /*
  1681. * Hardware has stripped IV/EIV data from 802.11 frame during
  1682. * decryption. It has provided the data seperately but rt2x00lib
  1683. * should decide if it should be reinserted.
  1684. */
  1685. rxdesc->flags |= RX_FLAG_IV_STRIPPED;
  1686. /*
  1687. * FIXME: Legacy driver indicates that the frame does
  1688. * contain the Michael Mic. Unfortunately, in rt2x00
  1689. * the MIC seems to be missing completely...
  1690. */
  1691. rxdesc->flags |= RX_FLAG_MMIC_STRIPPED;
  1692. if (rxdesc->cipher_status == RX_CRYPTO_SUCCESS)
  1693. rxdesc->flags |= RX_FLAG_DECRYPTED;
  1694. else if (rxdesc->cipher_status == RX_CRYPTO_FAIL_MIC)
  1695. rxdesc->flags |= RX_FLAG_MMIC_ERROR;
  1696. }
  1697. /*
  1698. * Obtain the status about this packet.
  1699. * When frame was received with an OFDM bitrate,
  1700. * the signal is the PLCP value. If it was received with
  1701. * a CCK bitrate the signal is the rate in 100kbit/s.
  1702. */
  1703. rxdesc->signal = rt2x00_get_field32(word1, RXD_W1_SIGNAL);
  1704. rxdesc->rssi = rt61pci_agc_to_rssi(rt2x00dev, word1);
  1705. rxdesc->size = rt2x00_get_field32(word0, RXD_W0_DATABYTE_COUNT);
  1706. if (rt2x00_get_field32(word0, RXD_W0_OFDM))
  1707. rxdesc->dev_flags |= RXDONE_SIGNAL_PLCP;
  1708. else
  1709. rxdesc->dev_flags |= RXDONE_SIGNAL_BITRATE;
  1710. if (rt2x00_get_field32(word0, RXD_W0_MY_BSS))
  1711. rxdesc->dev_flags |= RXDONE_MY_BSS;
  1712. }
  1713. /*
  1714. * Interrupt functions.
  1715. */
  1716. static void rt61pci_txdone(struct rt2x00_dev *rt2x00dev)
  1717. {
  1718. struct data_queue *queue;
  1719. struct queue_entry *entry;
  1720. struct queue_entry *entry_done;
  1721. struct queue_entry_priv_pci *entry_priv;
  1722. struct txdone_entry_desc txdesc;
  1723. u32 word;
  1724. u32 reg;
  1725. u32 old_reg;
  1726. int type;
  1727. int index;
  1728. /*
  1729. * During each loop we will compare the freshly read
  1730. * STA_CSR4 register value with the value read from
  1731. * the previous loop. If the 2 values are equal then
  1732. * we should stop processing because the chance it
  1733. * quite big that the device has been unplugged and
  1734. * we risk going into an endless loop.
  1735. */
  1736. old_reg = 0;
  1737. while (1) {
  1738. rt2x00pci_register_read(rt2x00dev, STA_CSR4, &reg);
  1739. if (!rt2x00_get_field32(reg, STA_CSR4_VALID))
  1740. break;
  1741. if (old_reg == reg)
  1742. break;
  1743. old_reg = reg;
  1744. /*
  1745. * Skip this entry when it contains an invalid
  1746. * queue identication number.
  1747. */
  1748. type = rt2x00_get_field32(reg, STA_CSR4_PID_TYPE);
  1749. queue = rt2x00queue_get_queue(rt2x00dev, type);
  1750. if (unlikely(!queue))
  1751. continue;
  1752. /*
  1753. * Skip this entry when it contains an invalid
  1754. * index number.
  1755. */
  1756. index = rt2x00_get_field32(reg, STA_CSR4_PID_SUBTYPE);
  1757. if (unlikely(index >= queue->limit))
  1758. continue;
  1759. entry = &queue->entries[index];
  1760. entry_priv = entry->priv_data;
  1761. rt2x00_desc_read(entry_priv->desc, 0, &word);
  1762. if (rt2x00_get_field32(word, TXD_W0_OWNER_NIC) ||
  1763. !rt2x00_get_field32(word, TXD_W0_VALID))
  1764. return;
  1765. entry_done = rt2x00queue_get_entry(queue, Q_INDEX_DONE);
  1766. while (entry != entry_done) {
  1767. /* Catch up.
  1768. * Just report any entries we missed as failed.
  1769. */
  1770. WARNING(rt2x00dev,
  1771. "TX status report missed for entry %d\n",
  1772. entry_done->entry_idx);
  1773. txdesc.flags = 0;
  1774. __set_bit(TXDONE_UNKNOWN, &txdesc.flags);
  1775. txdesc.retry = 0;
  1776. rt2x00lib_txdone(entry_done, &txdesc);
  1777. entry_done = rt2x00queue_get_entry(queue, Q_INDEX_DONE);
  1778. }
  1779. /*
  1780. * Obtain the status about this packet.
  1781. */
  1782. txdesc.flags = 0;
  1783. switch (rt2x00_get_field32(reg, STA_CSR4_TX_RESULT)) {
  1784. case 0: /* Success, maybe with retry */
  1785. __set_bit(TXDONE_SUCCESS, &txdesc.flags);
  1786. break;
  1787. case 6: /* Failure, excessive retries */
  1788. __set_bit(TXDONE_EXCESSIVE_RETRY, &txdesc.flags);
  1789. /* Don't break, this is a failed frame! */
  1790. default: /* Failure */
  1791. __set_bit(TXDONE_FAILURE, &txdesc.flags);
  1792. }
  1793. txdesc.retry = rt2x00_get_field32(reg, STA_CSR4_RETRY_COUNT);
  1794. rt2x00lib_txdone(entry, &txdesc);
  1795. }
  1796. }
  1797. static irqreturn_t rt61pci_interrupt(int irq, void *dev_instance)
  1798. {
  1799. struct rt2x00_dev *rt2x00dev = dev_instance;
  1800. u32 reg_mcu;
  1801. u32 reg;
  1802. /*
  1803. * Get the interrupt sources & saved to local variable.
  1804. * Write register value back to clear pending interrupts.
  1805. */
  1806. rt2x00pci_register_read(rt2x00dev, MCU_INT_SOURCE_CSR, &reg_mcu);
  1807. rt2x00pci_register_write(rt2x00dev, MCU_INT_SOURCE_CSR, reg_mcu);
  1808. rt2x00pci_register_read(rt2x00dev, INT_SOURCE_CSR, &reg);
  1809. rt2x00pci_register_write(rt2x00dev, INT_SOURCE_CSR, reg);
  1810. if (!reg && !reg_mcu)
  1811. return IRQ_NONE;
  1812. if (!test_bit(DEVICE_STATE_ENABLED_RADIO, &rt2x00dev->flags))
  1813. return IRQ_HANDLED;
  1814. /*
  1815. * Handle interrupts, walk through all bits
  1816. * and run the tasks, the bits are checked in order of
  1817. * priority.
  1818. */
  1819. /*
  1820. * 1 - Rx ring done interrupt.
  1821. */
  1822. if (rt2x00_get_field32(reg, INT_SOURCE_CSR_RXDONE))
  1823. rt2x00pci_rxdone(rt2x00dev);
  1824. /*
  1825. * 2 - Tx ring done interrupt.
  1826. */
  1827. if (rt2x00_get_field32(reg, INT_SOURCE_CSR_TXDONE))
  1828. rt61pci_txdone(rt2x00dev);
  1829. /*
  1830. * 3 - Handle MCU command done.
  1831. */
  1832. if (reg_mcu)
  1833. rt2x00pci_register_write(rt2x00dev,
  1834. M2H_CMD_DONE_CSR, 0xffffffff);
  1835. return IRQ_HANDLED;
  1836. }
  1837. /*
  1838. * Device probe functions.
  1839. */
  1840. static int rt61pci_validate_eeprom(struct rt2x00_dev *rt2x00dev)
  1841. {
  1842. struct eeprom_93cx6 eeprom;
  1843. u32 reg;
  1844. u16 word;
  1845. u8 *mac;
  1846. s8 value;
  1847. rt2x00pci_register_read(rt2x00dev, E2PROM_CSR, &reg);
  1848. eeprom.data = rt2x00dev;
  1849. eeprom.register_read = rt61pci_eepromregister_read;
  1850. eeprom.register_write = rt61pci_eepromregister_write;
  1851. eeprom.width = rt2x00_get_field32(reg, E2PROM_CSR_TYPE_93C46) ?
  1852. PCI_EEPROM_WIDTH_93C46 : PCI_EEPROM_WIDTH_93C66;
  1853. eeprom.reg_data_in = 0;
  1854. eeprom.reg_data_out = 0;
  1855. eeprom.reg_data_clock = 0;
  1856. eeprom.reg_chip_select = 0;
  1857. eeprom_93cx6_multiread(&eeprom, EEPROM_BASE, rt2x00dev->eeprom,
  1858. EEPROM_SIZE / sizeof(u16));
  1859. /*
  1860. * Start validation of the data that has been read.
  1861. */
  1862. mac = rt2x00_eeprom_addr(rt2x00dev, EEPROM_MAC_ADDR_0);
  1863. if (!is_valid_ether_addr(mac)) {
  1864. random_ether_addr(mac);
  1865. EEPROM(rt2x00dev, "MAC: %pM\n", mac);
  1866. }
  1867. rt2x00_eeprom_read(rt2x00dev, EEPROM_ANTENNA, &word);
  1868. if (word == 0xffff) {
  1869. rt2x00_set_field16(&word, EEPROM_ANTENNA_NUM, 2);
  1870. rt2x00_set_field16(&word, EEPROM_ANTENNA_TX_DEFAULT,
  1871. ANTENNA_B);
  1872. rt2x00_set_field16(&word, EEPROM_ANTENNA_RX_DEFAULT,
  1873. ANTENNA_B);
  1874. rt2x00_set_field16(&word, EEPROM_ANTENNA_FRAME_TYPE, 0);
  1875. rt2x00_set_field16(&word, EEPROM_ANTENNA_DYN_TXAGC, 0);
  1876. rt2x00_set_field16(&word, EEPROM_ANTENNA_HARDWARE_RADIO, 0);
  1877. rt2x00_set_field16(&word, EEPROM_ANTENNA_RF_TYPE, RF5225);
  1878. rt2x00_eeprom_write(rt2x00dev, EEPROM_ANTENNA, word);
  1879. EEPROM(rt2x00dev, "Antenna: 0x%04x\n", word);
  1880. }
  1881. rt2x00_eeprom_read(rt2x00dev, EEPROM_NIC, &word);
  1882. if (word == 0xffff) {
  1883. rt2x00_set_field16(&word, EEPROM_NIC_ENABLE_DIVERSITY, 0);
  1884. rt2x00_set_field16(&word, EEPROM_NIC_TX_DIVERSITY, 0);
  1885. rt2x00_set_field16(&word, EEPROM_NIC_TX_RX_FIXED, 0);
  1886. rt2x00_set_field16(&word, EEPROM_NIC_EXTERNAL_LNA_BG, 0);
  1887. rt2x00_set_field16(&word, EEPROM_NIC_CARDBUS_ACCEL, 0);
  1888. rt2x00_set_field16(&word, EEPROM_NIC_EXTERNAL_LNA_A, 0);
  1889. rt2x00_eeprom_write(rt2x00dev, EEPROM_NIC, word);
  1890. EEPROM(rt2x00dev, "NIC: 0x%04x\n", word);
  1891. }
  1892. rt2x00_eeprom_read(rt2x00dev, EEPROM_LED, &word);
  1893. if (word == 0xffff) {
  1894. rt2x00_set_field16(&word, EEPROM_LED_LED_MODE,
  1895. LED_MODE_DEFAULT);
  1896. rt2x00_eeprom_write(rt2x00dev, EEPROM_LED, word);
  1897. EEPROM(rt2x00dev, "Led: 0x%04x\n", word);
  1898. }
  1899. rt2x00_eeprom_read(rt2x00dev, EEPROM_FREQ, &word);
  1900. if (word == 0xffff) {
  1901. rt2x00_set_field16(&word, EEPROM_FREQ_OFFSET, 0);
  1902. rt2x00_set_field16(&word, EEPROM_FREQ_SEQ, 0);
  1903. rt2x00_eeprom_write(rt2x00dev, EEPROM_FREQ, word);
  1904. EEPROM(rt2x00dev, "Freq: 0x%04x\n", word);
  1905. }
  1906. rt2x00_eeprom_read(rt2x00dev, EEPROM_RSSI_OFFSET_BG, &word);
  1907. if (word == 0xffff) {
  1908. rt2x00_set_field16(&word, EEPROM_RSSI_OFFSET_BG_1, 0);
  1909. rt2x00_set_field16(&word, EEPROM_RSSI_OFFSET_BG_2, 0);
  1910. rt2x00_eeprom_write(rt2x00dev, EEPROM_RSSI_OFFSET_BG, word);
  1911. EEPROM(rt2x00dev, "RSSI OFFSET BG: 0x%04x\n", word);
  1912. } else {
  1913. value = rt2x00_get_field16(word, EEPROM_RSSI_OFFSET_BG_1);
  1914. if (value < -10 || value > 10)
  1915. rt2x00_set_field16(&word, EEPROM_RSSI_OFFSET_BG_1, 0);
  1916. value = rt2x00_get_field16(word, EEPROM_RSSI_OFFSET_BG_2);
  1917. if (value < -10 || value > 10)
  1918. rt2x00_set_field16(&word, EEPROM_RSSI_OFFSET_BG_2, 0);
  1919. rt2x00_eeprom_write(rt2x00dev, EEPROM_RSSI_OFFSET_BG, word);
  1920. }
  1921. rt2x00_eeprom_read(rt2x00dev, EEPROM_RSSI_OFFSET_A, &word);
  1922. if (word == 0xffff) {
  1923. rt2x00_set_field16(&word, EEPROM_RSSI_OFFSET_A_1, 0);
  1924. rt2x00_set_field16(&word, EEPROM_RSSI_OFFSET_A_2, 0);
  1925. rt2x00_eeprom_write(rt2x00dev, EEPROM_RSSI_OFFSET_A, word);
  1926. EEPROM(rt2x00dev, "RSSI OFFSET A: 0x%04x\n", word);
  1927. } else {
  1928. value = rt2x00_get_field16(word, EEPROM_RSSI_OFFSET_A_1);
  1929. if (value < -10 || value > 10)
  1930. rt2x00_set_field16(&word, EEPROM_RSSI_OFFSET_A_1, 0);
  1931. value = rt2x00_get_field16(word, EEPROM_RSSI_OFFSET_A_2);
  1932. if (value < -10 || value > 10)
  1933. rt2x00_set_field16(&word, EEPROM_RSSI_OFFSET_A_2, 0);
  1934. rt2x00_eeprom_write(rt2x00dev, EEPROM_RSSI_OFFSET_A, word);
  1935. }
  1936. return 0;
  1937. }
  1938. static int rt61pci_init_eeprom(struct rt2x00_dev *rt2x00dev)
  1939. {
  1940. u32 reg;
  1941. u16 value;
  1942. u16 eeprom;
  1943. u16 device;
  1944. /*
  1945. * Read EEPROM word for configuration.
  1946. */
  1947. rt2x00_eeprom_read(rt2x00dev, EEPROM_ANTENNA, &eeprom);
  1948. /*
  1949. * Identify RF chipset.
  1950. * To determine the RT chip we have to read the
  1951. * PCI header of the device.
  1952. */
  1953. pci_read_config_word(to_pci_dev(rt2x00dev->dev),
  1954. PCI_CONFIG_HEADER_DEVICE, &device);
  1955. value = rt2x00_get_field16(eeprom, EEPROM_ANTENNA_RF_TYPE);
  1956. rt2x00pci_register_read(rt2x00dev, MAC_CSR0, &reg);
  1957. rt2x00_set_chip(rt2x00dev, device, value, reg);
  1958. if (!rt2x00_rf(&rt2x00dev->chip, RF5225) &&
  1959. !rt2x00_rf(&rt2x00dev->chip, RF5325) &&
  1960. !rt2x00_rf(&rt2x00dev->chip, RF2527) &&
  1961. !rt2x00_rf(&rt2x00dev->chip, RF2529)) {
  1962. ERROR(rt2x00dev, "Invalid RF chipset detected.\n");
  1963. return -ENODEV;
  1964. }
  1965. /*
  1966. * Determine number of antenna's.
  1967. */
  1968. if (rt2x00_get_field16(eeprom, EEPROM_ANTENNA_NUM) == 2)
  1969. __set_bit(CONFIG_DOUBLE_ANTENNA, &rt2x00dev->flags);
  1970. /*
  1971. * Identify default antenna configuration.
  1972. */
  1973. rt2x00dev->default_ant.tx =
  1974. rt2x00_get_field16(eeprom, EEPROM_ANTENNA_TX_DEFAULT);
  1975. rt2x00dev->default_ant.rx =
  1976. rt2x00_get_field16(eeprom, EEPROM_ANTENNA_RX_DEFAULT);
  1977. /*
  1978. * Read the Frame type.
  1979. */
  1980. if (rt2x00_get_field16(eeprom, EEPROM_ANTENNA_FRAME_TYPE))
  1981. __set_bit(CONFIG_FRAME_TYPE, &rt2x00dev->flags);
  1982. /*
  1983. * Detect if this device has an hardware controlled radio.
  1984. */
  1985. #ifdef CONFIG_RT2X00_LIB_RFKILL
  1986. if (rt2x00_get_field16(eeprom, EEPROM_ANTENNA_HARDWARE_RADIO))
  1987. __set_bit(CONFIG_SUPPORT_HW_BUTTON, &rt2x00dev->flags);
  1988. #endif /* CONFIG_RT2X00_LIB_RFKILL */
  1989. /*
  1990. * Read frequency offset and RF programming sequence.
  1991. */
  1992. rt2x00_eeprom_read(rt2x00dev, EEPROM_FREQ, &eeprom);
  1993. if (rt2x00_get_field16(eeprom, EEPROM_FREQ_SEQ))
  1994. __set_bit(CONFIG_RF_SEQUENCE, &rt2x00dev->flags);
  1995. rt2x00dev->freq_offset = rt2x00_get_field16(eeprom, EEPROM_FREQ_OFFSET);
  1996. /*
  1997. * Read external LNA informations.
  1998. */
  1999. rt2x00_eeprom_read(rt2x00dev, EEPROM_NIC, &eeprom);
  2000. if (rt2x00_get_field16(eeprom, EEPROM_NIC_EXTERNAL_LNA_A))
  2001. __set_bit(CONFIG_EXTERNAL_LNA_A, &rt2x00dev->flags);
  2002. if (rt2x00_get_field16(eeprom, EEPROM_NIC_EXTERNAL_LNA_BG))
  2003. __set_bit(CONFIG_EXTERNAL_LNA_BG, &rt2x00dev->flags);
  2004. /*
  2005. * When working with a RF2529 chip without double antenna
  2006. * the antenna settings should be gathered from the NIC
  2007. * eeprom word.
  2008. */
  2009. if (rt2x00_rf(&rt2x00dev->chip, RF2529) &&
  2010. !test_bit(CONFIG_DOUBLE_ANTENNA, &rt2x00dev->flags)) {
  2011. switch (rt2x00_get_field16(eeprom, EEPROM_NIC_TX_RX_FIXED)) {
  2012. case 0:
  2013. rt2x00dev->default_ant.tx = ANTENNA_B;
  2014. rt2x00dev->default_ant.rx = ANTENNA_A;
  2015. break;
  2016. case 1:
  2017. rt2x00dev->default_ant.tx = ANTENNA_B;
  2018. rt2x00dev->default_ant.rx = ANTENNA_B;
  2019. break;
  2020. case 2:
  2021. rt2x00dev->default_ant.tx = ANTENNA_A;
  2022. rt2x00dev->default_ant.rx = ANTENNA_A;
  2023. break;
  2024. case 3:
  2025. rt2x00dev->default_ant.tx = ANTENNA_A;
  2026. rt2x00dev->default_ant.rx = ANTENNA_B;
  2027. break;
  2028. }
  2029. if (rt2x00_get_field16(eeprom, EEPROM_NIC_TX_DIVERSITY))
  2030. rt2x00dev->default_ant.tx = ANTENNA_SW_DIVERSITY;
  2031. if (rt2x00_get_field16(eeprom, EEPROM_NIC_ENABLE_DIVERSITY))
  2032. rt2x00dev->default_ant.rx = ANTENNA_SW_DIVERSITY;
  2033. }
  2034. /*
  2035. * Store led settings, for correct led behaviour.
  2036. * If the eeprom value is invalid,
  2037. * switch to default led mode.
  2038. */
  2039. #ifdef CONFIG_RT2X00_LIB_LEDS
  2040. rt2x00_eeprom_read(rt2x00dev, EEPROM_LED, &eeprom);
  2041. value = rt2x00_get_field16(eeprom, EEPROM_LED_LED_MODE);
  2042. rt61pci_init_led(rt2x00dev, &rt2x00dev->led_radio, LED_TYPE_RADIO);
  2043. rt61pci_init_led(rt2x00dev, &rt2x00dev->led_assoc, LED_TYPE_ASSOC);
  2044. if (value == LED_MODE_SIGNAL_STRENGTH)
  2045. rt61pci_init_led(rt2x00dev, &rt2x00dev->led_qual,
  2046. LED_TYPE_QUALITY);
  2047. rt2x00_set_field16(&rt2x00dev->led_mcu_reg, MCU_LEDCS_LED_MODE, value);
  2048. rt2x00_set_field16(&rt2x00dev->led_mcu_reg, MCU_LEDCS_POLARITY_GPIO_0,
  2049. rt2x00_get_field16(eeprom,
  2050. EEPROM_LED_POLARITY_GPIO_0));
  2051. rt2x00_set_field16(&rt2x00dev->led_mcu_reg, MCU_LEDCS_POLARITY_GPIO_1,
  2052. rt2x00_get_field16(eeprom,
  2053. EEPROM_LED_POLARITY_GPIO_1));
  2054. rt2x00_set_field16(&rt2x00dev->led_mcu_reg, MCU_LEDCS_POLARITY_GPIO_2,
  2055. rt2x00_get_field16(eeprom,
  2056. EEPROM_LED_POLARITY_GPIO_2));
  2057. rt2x00_set_field16(&rt2x00dev->led_mcu_reg, MCU_LEDCS_POLARITY_GPIO_3,
  2058. rt2x00_get_field16(eeprom,
  2059. EEPROM_LED_POLARITY_GPIO_3));
  2060. rt2x00_set_field16(&rt2x00dev->led_mcu_reg, MCU_LEDCS_POLARITY_GPIO_4,
  2061. rt2x00_get_field16(eeprom,
  2062. EEPROM_LED_POLARITY_GPIO_4));
  2063. rt2x00_set_field16(&rt2x00dev->led_mcu_reg, MCU_LEDCS_POLARITY_ACT,
  2064. rt2x00_get_field16(eeprom, EEPROM_LED_POLARITY_ACT));
  2065. rt2x00_set_field16(&rt2x00dev->led_mcu_reg, MCU_LEDCS_POLARITY_READY_BG,
  2066. rt2x00_get_field16(eeprom,
  2067. EEPROM_LED_POLARITY_RDY_G));
  2068. rt2x00_set_field16(&rt2x00dev->led_mcu_reg, MCU_LEDCS_POLARITY_READY_A,
  2069. rt2x00_get_field16(eeprom,
  2070. EEPROM_LED_POLARITY_RDY_A));
  2071. #endif /* CONFIG_RT2X00_LIB_LEDS */
  2072. return 0;
  2073. }
  2074. /*
  2075. * RF value list for RF5225 & RF5325
  2076. * Supports: 2.4 GHz & 5.2 GHz, rf_sequence disabled
  2077. */
  2078. static const struct rf_channel rf_vals_noseq[] = {
  2079. { 1, 0x00002ccc, 0x00004786, 0x00068455, 0x000ffa0b },
  2080. { 2, 0x00002ccc, 0x00004786, 0x00068455, 0x000ffa1f },
  2081. { 3, 0x00002ccc, 0x0000478a, 0x00068455, 0x000ffa0b },
  2082. { 4, 0x00002ccc, 0x0000478a, 0x00068455, 0x000ffa1f },
  2083. { 5, 0x00002ccc, 0x0000478e, 0x00068455, 0x000ffa0b },
  2084. { 6, 0x00002ccc, 0x0000478e, 0x00068455, 0x000ffa1f },
  2085. { 7, 0x00002ccc, 0x00004792, 0x00068455, 0x000ffa0b },
  2086. { 8, 0x00002ccc, 0x00004792, 0x00068455, 0x000ffa1f },
  2087. { 9, 0x00002ccc, 0x00004796, 0x00068455, 0x000ffa0b },
  2088. { 10, 0x00002ccc, 0x00004796, 0x00068455, 0x000ffa1f },
  2089. { 11, 0x00002ccc, 0x0000479a, 0x00068455, 0x000ffa0b },
  2090. { 12, 0x00002ccc, 0x0000479a, 0x00068455, 0x000ffa1f },
  2091. { 13, 0x00002ccc, 0x0000479e, 0x00068455, 0x000ffa0b },
  2092. { 14, 0x00002ccc, 0x000047a2, 0x00068455, 0x000ffa13 },
  2093. /* 802.11 UNI / HyperLan 2 */
  2094. { 36, 0x00002ccc, 0x0000499a, 0x0009be55, 0x000ffa23 },
  2095. { 40, 0x00002ccc, 0x000049a2, 0x0009be55, 0x000ffa03 },
  2096. { 44, 0x00002ccc, 0x000049a6, 0x0009be55, 0x000ffa0b },
  2097. { 48, 0x00002ccc, 0x000049aa, 0x0009be55, 0x000ffa13 },
  2098. { 52, 0x00002ccc, 0x000049ae, 0x0009ae55, 0x000ffa1b },
  2099. { 56, 0x00002ccc, 0x000049b2, 0x0009ae55, 0x000ffa23 },
  2100. { 60, 0x00002ccc, 0x000049ba, 0x0009ae55, 0x000ffa03 },
  2101. { 64, 0x00002ccc, 0x000049be, 0x0009ae55, 0x000ffa0b },
  2102. /* 802.11 HyperLan 2 */
  2103. { 100, 0x00002ccc, 0x00004a2a, 0x000bae55, 0x000ffa03 },
  2104. { 104, 0x00002ccc, 0x00004a2e, 0x000bae55, 0x000ffa0b },
  2105. { 108, 0x00002ccc, 0x00004a32, 0x000bae55, 0x000ffa13 },
  2106. { 112, 0x00002ccc, 0x00004a36, 0x000bae55, 0x000ffa1b },
  2107. { 116, 0x00002ccc, 0x00004a3a, 0x000bbe55, 0x000ffa23 },
  2108. { 120, 0x00002ccc, 0x00004a82, 0x000bbe55, 0x000ffa03 },
  2109. { 124, 0x00002ccc, 0x00004a86, 0x000bbe55, 0x000ffa0b },
  2110. { 128, 0x00002ccc, 0x00004a8a, 0x000bbe55, 0x000ffa13 },
  2111. { 132, 0x00002ccc, 0x00004a8e, 0x000bbe55, 0x000ffa1b },
  2112. { 136, 0x00002ccc, 0x00004a92, 0x000bbe55, 0x000ffa23 },
  2113. /* 802.11 UNII */
  2114. { 140, 0x00002ccc, 0x00004a9a, 0x000bbe55, 0x000ffa03 },
  2115. { 149, 0x00002ccc, 0x00004aa2, 0x000bbe55, 0x000ffa1f },
  2116. { 153, 0x00002ccc, 0x00004aa6, 0x000bbe55, 0x000ffa27 },
  2117. { 157, 0x00002ccc, 0x00004aae, 0x000bbe55, 0x000ffa07 },
  2118. { 161, 0x00002ccc, 0x00004ab2, 0x000bbe55, 0x000ffa0f },
  2119. { 165, 0x00002ccc, 0x00004ab6, 0x000bbe55, 0x000ffa17 },
  2120. /* MMAC(Japan)J52 ch 34,38,42,46 */
  2121. { 34, 0x00002ccc, 0x0000499a, 0x0009be55, 0x000ffa0b },
  2122. { 38, 0x00002ccc, 0x0000499e, 0x0009be55, 0x000ffa13 },
  2123. { 42, 0x00002ccc, 0x000049a2, 0x0009be55, 0x000ffa1b },
  2124. { 46, 0x00002ccc, 0x000049a6, 0x0009be55, 0x000ffa23 },
  2125. };
  2126. /*
  2127. * RF value list for RF5225 & RF5325
  2128. * Supports: 2.4 GHz & 5.2 GHz, rf_sequence enabled
  2129. */
  2130. static const struct rf_channel rf_vals_seq[] = {
  2131. { 1, 0x00002ccc, 0x00004786, 0x00068455, 0x000ffa0b },
  2132. { 2, 0x00002ccc, 0x00004786, 0x00068455, 0x000ffa1f },
  2133. { 3, 0x00002ccc, 0x0000478a, 0x00068455, 0x000ffa0b },
  2134. { 4, 0x00002ccc, 0x0000478a, 0x00068455, 0x000ffa1f },
  2135. { 5, 0x00002ccc, 0x0000478e, 0x00068455, 0x000ffa0b },
  2136. { 6, 0x00002ccc, 0x0000478e, 0x00068455, 0x000ffa1f },
  2137. { 7, 0x00002ccc, 0x00004792, 0x00068455, 0x000ffa0b },
  2138. { 8, 0x00002ccc, 0x00004792, 0x00068455, 0x000ffa1f },
  2139. { 9, 0x00002ccc, 0x00004796, 0x00068455, 0x000ffa0b },
  2140. { 10, 0x00002ccc, 0x00004796, 0x00068455, 0x000ffa1f },
  2141. { 11, 0x00002ccc, 0x0000479a, 0x00068455, 0x000ffa0b },
  2142. { 12, 0x00002ccc, 0x0000479a, 0x00068455, 0x000ffa1f },
  2143. { 13, 0x00002ccc, 0x0000479e, 0x00068455, 0x000ffa0b },
  2144. { 14, 0x00002ccc, 0x000047a2, 0x00068455, 0x000ffa13 },
  2145. /* 802.11 UNI / HyperLan 2 */
  2146. { 36, 0x00002cd4, 0x0004481a, 0x00098455, 0x000c0a03 },
  2147. { 40, 0x00002cd0, 0x00044682, 0x00098455, 0x000c0a03 },
  2148. { 44, 0x00002cd0, 0x00044686, 0x00098455, 0x000c0a1b },
  2149. { 48, 0x00002cd0, 0x0004468e, 0x00098655, 0x000c0a0b },
  2150. { 52, 0x00002cd0, 0x00044692, 0x00098855, 0x000c0a23 },
  2151. { 56, 0x00002cd0, 0x0004469a, 0x00098c55, 0x000c0a13 },
  2152. { 60, 0x00002cd0, 0x000446a2, 0x00098e55, 0x000c0a03 },
  2153. { 64, 0x00002cd0, 0x000446a6, 0x00099255, 0x000c0a1b },
  2154. /* 802.11 HyperLan 2 */
  2155. { 100, 0x00002cd4, 0x0004489a, 0x000b9855, 0x000c0a03 },
  2156. { 104, 0x00002cd4, 0x000448a2, 0x000b9855, 0x000c0a03 },
  2157. { 108, 0x00002cd4, 0x000448aa, 0x000b9855, 0x000c0a03 },
  2158. { 112, 0x00002cd4, 0x000448b2, 0x000b9a55, 0x000c0a03 },
  2159. { 116, 0x00002cd4, 0x000448ba, 0x000b9a55, 0x000c0a03 },
  2160. { 120, 0x00002cd0, 0x00044702, 0x000b9a55, 0x000c0a03 },
  2161. { 124, 0x00002cd0, 0x00044706, 0x000b9a55, 0x000c0a1b },
  2162. { 128, 0x00002cd0, 0x0004470e, 0x000b9c55, 0x000c0a0b },
  2163. { 132, 0x00002cd0, 0x00044712, 0x000b9c55, 0x000c0a23 },
  2164. { 136, 0x00002cd0, 0x0004471a, 0x000b9e55, 0x000c0a13 },
  2165. /* 802.11 UNII */
  2166. { 140, 0x00002cd0, 0x00044722, 0x000b9e55, 0x000c0a03 },
  2167. { 149, 0x00002cd0, 0x0004472e, 0x000ba255, 0x000c0a1b },
  2168. { 153, 0x00002cd0, 0x00044736, 0x000ba255, 0x000c0a0b },
  2169. { 157, 0x00002cd4, 0x0004490a, 0x000ba255, 0x000c0a17 },
  2170. { 161, 0x00002cd4, 0x00044912, 0x000ba255, 0x000c0a17 },
  2171. { 165, 0x00002cd4, 0x0004491a, 0x000ba255, 0x000c0a17 },
  2172. /* MMAC(Japan)J52 ch 34,38,42,46 */
  2173. { 34, 0x00002ccc, 0x0000499a, 0x0009be55, 0x000c0a0b },
  2174. { 38, 0x00002ccc, 0x0000499e, 0x0009be55, 0x000c0a13 },
  2175. { 42, 0x00002ccc, 0x000049a2, 0x0009be55, 0x000c0a1b },
  2176. { 46, 0x00002ccc, 0x000049a6, 0x0009be55, 0x000c0a23 },
  2177. };
  2178. static int rt61pci_probe_hw_mode(struct rt2x00_dev *rt2x00dev)
  2179. {
  2180. struct hw_mode_spec *spec = &rt2x00dev->spec;
  2181. struct channel_info *info;
  2182. char *tx_power;
  2183. unsigned int i;
  2184. /*
  2185. * Initialize all hw fields.
  2186. */
  2187. rt2x00dev->hw->flags =
  2188. IEEE80211_HW_HOST_BROADCAST_PS_BUFFERING |
  2189. IEEE80211_HW_SIGNAL_DBM;
  2190. rt2x00dev->hw->extra_tx_headroom = 0;
  2191. SET_IEEE80211_DEV(rt2x00dev->hw, rt2x00dev->dev);
  2192. SET_IEEE80211_PERM_ADDR(rt2x00dev->hw,
  2193. rt2x00_eeprom_addr(rt2x00dev,
  2194. EEPROM_MAC_ADDR_0));
  2195. /*
  2196. * Initialize hw_mode information.
  2197. */
  2198. spec->supported_bands = SUPPORT_BAND_2GHZ;
  2199. spec->supported_rates = SUPPORT_RATE_CCK | SUPPORT_RATE_OFDM;
  2200. if (!test_bit(CONFIG_RF_SEQUENCE, &rt2x00dev->flags)) {
  2201. spec->num_channels = 14;
  2202. spec->channels = rf_vals_noseq;
  2203. } else {
  2204. spec->num_channels = 14;
  2205. spec->channels = rf_vals_seq;
  2206. }
  2207. if (rt2x00_rf(&rt2x00dev->chip, RF5225) ||
  2208. rt2x00_rf(&rt2x00dev->chip, RF5325)) {
  2209. spec->supported_bands |= SUPPORT_BAND_5GHZ;
  2210. spec->num_channels = ARRAY_SIZE(rf_vals_seq);
  2211. }
  2212. /*
  2213. * Create channel information array
  2214. */
  2215. info = kzalloc(spec->num_channels * sizeof(*info), GFP_KERNEL);
  2216. if (!info)
  2217. return -ENOMEM;
  2218. spec->channels_info = info;
  2219. tx_power = rt2x00_eeprom_addr(rt2x00dev, EEPROM_TXPOWER_G_START);
  2220. for (i = 0; i < 14; i++)
  2221. info[i].tx_power1 = TXPOWER_FROM_DEV(tx_power[i]);
  2222. if (spec->num_channels > 14) {
  2223. tx_power = rt2x00_eeprom_addr(rt2x00dev, EEPROM_TXPOWER_A_START);
  2224. for (i = 14; i < spec->num_channels; i++)
  2225. info[i].tx_power1 = TXPOWER_FROM_DEV(tx_power[i]);
  2226. }
  2227. return 0;
  2228. }
  2229. static int rt61pci_probe_hw(struct rt2x00_dev *rt2x00dev)
  2230. {
  2231. int retval;
  2232. /*
  2233. * Allocate eeprom data.
  2234. */
  2235. retval = rt61pci_validate_eeprom(rt2x00dev);
  2236. if (retval)
  2237. return retval;
  2238. retval = rt61pci_init_eeprom(rt2x00dev);
  2239. if (retval)
  2240. return retval;
  2241. /*
  2242. * Initialize hw specifications.
  2243. */
  2244. retval = rt61pci_probe_hw_mode(rt2x00dev);
  2245. if (retval)
  2246. return retval;
  2247. /*
  2248. * This device requires firmware and DMA mapped skbs.
  2249. */
  2250. __set_bit(DRIVER_REQUIRE_FIRMWARE, &rt2x00dev->flags);
  2251. __set_bit(DRIVER_REQUIRE_DMA, &rt2x00dev->flags);
  2252. if (!modparam_nohwcrypt)
  2253. __set_bit(CONFIG_SUPPORT_HW_CRYPTO, &rt2x00dev->flags);
  2254. /*
  2255. * Set the rssi offset.
  2256. */
  2257. rt2x00dev->rssi_offset = DEFAULT_RSSI_OFFSET;
  2258. return 0;
  2259. }
  2260. /*
  2261. * IEEE80211 stack callback functions.
  2262. */
  2263. static int rt61pci_conf_tx(struct ieee80211_hw *hw, u16 queue_idx,
  2264. const struct ieee80211_tx_queue_params *params)
  2265. {
  2266. struct rt2x00_dev *rt2x00dev = hw->priv;
  2267. struct data_queue *queue;
  2268. struct rt2x00_field32 field;
  2269. int retval;
  2270. u32 reg;
  2271. /*
  2272. * First pass the configuration through rt2x00lib, that will
  2273. * update the queue settings and validate the input. After that
  2274. * we are free to update the registers based on the value
  2275. * in the queue parameter.
  2276. */
  2277. retval = rt2x00mac_conf_tx(hw, queue_idx, params);
  2278. if (retval)
  2279. return retval;
  2280. queue = rt2x00queue_get_queue(rt2x00dev, queue_idx);
  2281. /* Update WMM TXOP register */
  2282. if (queue_idx < 2) {
  2283. field.bit_offset = queue_idx * 16;
  2284. field.bit_mask = 0xffff << field.bit_offset;
  2285. rt2x00pci_register_read(rt2x00dev, AC_TXOP_CSR0, &reg);
  2286. rt2x00_set_field32(&reg, field, queue->txop);
  2287. rt2x00pci_register_write(rt2x00dev, AC_TXOP_CSR0, reg);
  2288. } else if (queue_idx < 4) {
  2289. field.bit_offset = (queue_idx - 2) * 16;
  2290. field.bit_mask = 0xffff << field.bit_offset;
  2291. rt2x00pci_register_read(rt2x00dev, AC_TXOP_CSR1, &reg);
  2292. rt2x00_set_field32(&reg, field, queue->txop);
  2293. rt2x00pci_register_write(rt2x00dev, AC_TXOP_CSR1, reg);
  2294. }
  2295. /* Update WMM registers */
  2296. field.bit_offset = queue_idx * 4;
  2297. field.bit_mask = 0xf << field.bit_offset;
  2298. rt2x00pci_register_read(rt2x00dev, AIFSN_CSR, &reg);
  2299. rt2x00_set_field32(&reg, field, queue->aifs);
  2300. rt2x00pci_register_write(rt2x00dev, AIFSN_CSR, reg);
  2301. rt2x00pci_register_read(rt2x00dev, CWMIN_CSR, &reg);
  2302. rt2x00_set_field32(&reg, field, queue->cw_min);
  2303. rt2x00pci_register_write(rt2x00dev, CWMIN_CSR, reg);
  2304. rt2x00pci_register_read(rt2x00dev, CWMAX_CSR, &reg);
  2305. rt2x00_set_field32(&reg, field, queue->cw_max);
  2306. rt2x00pci_register_write(rt2x00dev, CWMAX_CSR, reg);
  2307. return 0;
  2308. }
  2309. static u64 rt61pci_get_tsf(struct ieee80211_hw *hw)
  2310. {
  2311. struct rt2x00_dev *rt2x00dev = hw->priv;
  2312. u64 tsf;
  2313. u32 reg;
  2314. rt2x00pci_register_read(rt2x00dev, TXRX_CSR13, &reg);
  2315. tsf = (u64) rt2x00_get_field32(reg, TXRX_CSR13_HIGH_TSFTIMER) << 32;
  2316. rt2x00pci_register_read(rt2x00dev, TXRX_CSR12, &reg);
  2317. tsf |= rt2x00_get_field32(reg, TXRX_CSR12_LOW_TSFTIMER);
  2318. return tsf;
  2319. }
  2320. static const struct ieee80211_ops rt61pci_mac80211_ops = {
  2321. .tx = rt2x00mac_tx,
  2322. .start = rt2x00mac_start,
  2323. .stop = rt2x00mac_stop,
  2324. .add_interface = rt2x00mac_add_interface,
  2325. .remove_interface = rt2x00mac_remove_interface,
  2326. .config = rt2x00mac_config,
  2327. .config_interface = rt2x00mac_config_interface,
  2328. .configure_filter = rt2x00mac_configure_filter,
  2329. .set_key = rt2x00mac_set_key,
  2330. .get_stats = rt2x00mac_get_stats,
  2331. .bss_info_changed = rt2x00mac_bss_info_changed,
  2332. .conf_tx = rt61pci_conf_tx,
  2333. .get_tx_stats = rt2x00mac_get_tx_stats,
  2334. .get_tsf = rt61pci_get_tsf,
  2335. };
  2336. static const struct rt2x00lib_ops rt61pci_rt2x00_ops = {
  2337. .irq_handler = rt61pci_interrupt,
  2338. .probe_hw = rt61pci_probe_hw,
  2339. .get_firmware_name = rt61pci_get_firmware_name,
  2340. .get_firmware_crc = rt61pci_get_firmware_crc,
  2341. .load_firmware = rt61pci_load_firmware,
  2342. .initialize = rt2x00pci_initialize,
  2343. .uninitialize = rt2x00pci_uninitialize,
  2344. .init_rxentry = rt61pci_init_rxentry,
  2345. .init_txentry = rt61pci_init_txentry,
  2346. .set_device_state = rt61pci_set_device_state,
  2347. .rfkill_poll = rt61pci_rfkill_poll,
  2348. .link_stats = rt61pci_link_stats,
  2349. .reset_tuner = rt61pci_reset_tuner,
  2350. .link_tuner = rt61pci_link_tuner,
  2351. .write_tx_desc = rt61pci_write_tx_desc,
  2352. .write_tx_data = rt2x00pci_write_tx_data,
  2353. .write_beacon = rt61pci_write_beacon,
  2354. .kick_tx_queue = rt61pci_kick_tx_queue,
  2355. .fill_rxdone = rt61pci_fill_rxdone,
  2356. .config_shared_key = rt61pci_config_shared_key,
  2357. .config_pairwise_key = rt61pci_config_pairwise_key,
  2358. .config_filter = rt61pci_config_filter,
  2359. .config_intf = rt61pci_config_intf,
  2360. .config_erp = rt61pci_config_erp,
  2361. .config_ant = rt61pci_config_ant,
  2362. .config = rt61pci_config,
  2363. };
  2364. static const struct data_queue_desc rt61pci_queue_rx = {
  2365. .entry_num = RX_ENTRIES,
  2366. .data_size = DATA_FRAME_SIZE,
  2367. .desc_size = RXD_DESC_SIZE,
  2368. .priv_size = sizeof(struct queue_entry_priv_pci),
  2369. };
  2370. static const struct data_queue_desc rt61pci_queue_tx = {
  2371. .entry_num = TX_ENTRIES,
  2372. .data_size = DATA_FRAME_SIZE,
  2373. .desc_size = TXD_DESC_SIZE,
  2374. .priv_size = sizeof(struct queue_entry_priv_pci),
  2375. };
  2376. static const struct data_queue_desc rt61pci_queue_bcn = {
  2377. .entry_num = 4 * BEACON_ENTRIES,
  2378. .data_size = 0, /* No DMA required for beacons */
  2379. .desc_size = TXINFO_SIZE,
  2380. .priv_size = sizeof(struct queue_entry_priv_pci),
  2381. };
  2382. static const struct rt2x00_ops rt61pci_ops = {
  2383. .name = KBUILD_MODNAME,
  2384. .max_sta_intf = 1,
  2385. .max_ap_intf = 4,
  2386. .eeprom_size = EEPROM_SIZE,
  2387. .rf_size = RF_SIZE,
  2388. .tx_queues = NUM_TX_QUEUES,
  2389. .rx = &rt61pci_queue_rx,
  2390. .tx = &rt61pci_queue_tx,
  2391. .bcn = &rt61pci_queue_bcn,
  2392. .lib = &rt61pci_rt2x00_ops,
  2393. .hw = &rt61pci_mac80211_ops,
  2394. #ifdef CONFIG_RT2X00_LIB_DEBUGFS
  2395. .debugfs = &rt61pci_rt2x00debug,
  2396. #endif /* CONFIG_RT2X00_LIB_DEBUGFS */
  2397. };
  2398. /*
  2399. * RT61pci module information.
  2400. */
  2401. static struct pci_device_id rt61pci_device_table[] = {
  2402. /* RT2561s */
  2403. { PCI_DEVICE(0x1814, 0x0301), PCI_DEVICE_DATA(&rt61pci_ops) },
  2404. /* RT2561 v2 */
  2405. { PCI_DEVICE(0x1814, 0x0302), PCI_DEVICE_DATA(&rt61pci_ops) },
  2406. /* RT2661 */
  2407. { PCI_DEVICE(0x1814, 0x0401), PCI_DEVICE_DATA(&rt61pci_ops) },
  2408. { 0, }
  2409. };
  2410. MODULE_AUTHOR(DRV_PROJECT);
  2411. MODULE_VERSION(DRV_VERSION);
  2412. MODULE_DESCRIPTION("Ralink RT61 PCI & PCMCIA Wireless LAN driver.");
  2413. MODULE_SUPPORTED_DEVICE("Ralink RT2561, RT2561s & RT2661 "
  2414. "PCI & PCMCIA chipset based cards");
  2415. MODULE_DEVICE_TABLE(pci, rt61pci_device_table);
  2416. MODULE_FIRMWARE(FIRMWARE_RT2561);
  2417. MODULE_FIRMWARE(FIRMWARE_RT2561s);
  2418. MODULE_FIRMWARE(FIRMWARE_RT2661);
  2419. MODULE_LICENSE("GPL");
  2420. static struct pci_driver rt61pci_driver = {
  2421. .name = KBUILD_MODNAME,
  2422. .id_table = rt61pci_device_table,
  2423. .probe = rt2x00pci_probe,
  2424. .remove = __devexit_p(rt2x00pci_remove),
  2425. .suspend = rt2x00pci_suspend,
  2426. .resume = rt2x00pci_resume,
  2427. };
  2428. static int __init rt61pci_init(void)
  2429. {
  2430. return pci_register_driver(&rt61pci_driver);
  2431. }
  2432. static void __exit rt61pci_exit(void)
  2433. {
  2434. pci_unregister_driver(&rt61pci_driver);
  2435. }
  2436. module_init(rt61pci_init);
  2437. module_exit(rt61pci_exit);