rt61pci.c 76 KB

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