rt61pci.c 86 KB

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