rt61pci.c 86 KB

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