rt61pci.c 75 KB

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