rt61pci.c 83 KB

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