rt61pci.c 85 KB

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