rt73usb.c 74 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473
  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: rt73usb
  19. Abstract: rt73usb device specific routines.
  20. Supported chipsets: rt2571W & rt2671.
  21. */
  22. #include <linux/crc-itu-t.h>
  23. #include <linux/delay.h>
  24. #include <linux/etherdevice.h>
  25. #include <linux/init.h>
  26. #include <linux/kernel.h>
  27. #include <linux/module.h>
  28. #include <linux/usb.h>
  29. #include "rt2x00.h"
  30. #include "rt2x00usb.h"
  31. #include "rt73usb.h"
  32. /*
  33. * Allow hardware encryption to be disabled.
  34. */
  35. static int modparam_nohwcrypt = 0;
  36. module_param_named(nohwcrypt, modparam_nohwcrypt, bool, S_IRUGO);
  37. MODULE_PARM_DESC(nohwcrypt, "Disable hardware encryption.");
  38. /*
  39. * Register access.
  40. * All access to the CSR registers will go through the methods
  41. * rt73usb_register_read and rt73usb_register_write.
  42. * BBP and RF register require indirect register access,
  43. * and use the CSR registers BBPCSR and RFCSR to achieve this.
  44. * These indirect registers work with busy bits,
  45. * and we will try maximal REGISTER_BUSY_COUNT times to access
  46. * the register while taking a REGISTER_BUSY_DELAY us delay
  47. * between each attampt. When the busy bit is still set at that time,
  48. * the access attempt is considered to have failed,
  49. * and we will print an error.
  50. * The _lock versions must be used if you already hold the csr_mutex
  51. */
  52. static inline void rt73usb_register_read(struct rt2x00_dev *rt2x00dev,
  53. const unsigned int offset, u32 *value)
  54. {
  55. __le32 reg;
  56. rt2x00usb_vendor_request_buff(rt2x00dev, USB_MULTI_READ,
  57. USB_VENDOR_REQUEST_IN, offset,
  58. &reg, sizeof(u32), REGISTER_TIMEOUT);
  59. *value = le32_to_cpu(reg);
  60. }
  61. static inline void rt73usb_register_read_lock(struct rt2x00_dev *rt2x00dev,
  62. const unsigned int offset, u32 *value)
  63. {
  64. __le32 reg;
  65. rt2x00usb_vendor_req_buff_lock(rt2x00dev, USB_MULTI_READ,
  66. USB_VENDOR_REQUEST_IN, offset,
  67. &reg, sizeof(u32), REGISTER_TIMEOUT);
  68. *value = le32_to_cpu(reg);
  69. }
  70. static inline void rt73usb_register_multiread(struct rt2x00_dev *rt2x00dev,
  71. const unsigned int offset,
  72. void *value, const u32 length)
  73. {
  74. rt2x00usb_vendor_request_buff(rt2x00dev, USB_MULTI_READ,
  75. USB_VENDOR_REQUEST_IN, offset,
  76. value, length,
  77. REGISTER_TIMEOUT32(length));
  78. }
  79. static inline void rt73usb_register_write(struct rt2x00_dev *rt2x00dev,
  80. const unsigned int offset, u32 value)
  81. {
  82. __le32 reg = cpu_to_le32(value);
  83. rt2x00usb_vendor_request_buff(rt2x00dev, USB_MULTI_WRITE,
  84. USB_VENDOR_REQUEST_OUT, offset,
  85. &reg, sizeof(u32), REGISTER_TIMEOUT);
  86. }
  87. static inline void rt73usb_register_write_lock(struct rt2x00_dev *rt2x00dev,
  88. const unsigned int offset, u32 value)
  89. {
  90. __le32 reg = cpu_to_le32(value);
  91. rt2x00usb_vendor_req_buff_lock(rt2x00dev, USB_MULTI_WRITE,
  92. USB_VENDOR_REQUEST_OUT, offset,
  93. &reg, sizeof(u32), REGISTER_TIMEOUT);
  94. }
  95. static inline void rt73usb_register_multiwrite(struct rt2x00_dev *rt2x00dev,
  96. const unsigned int offset,
  97. void *value, const u32 length)
  98. {
  99. rt2x00usb_vendor_request_buff(rt2x00dev, USB_MULTI_WRITE,
  100. USB_VENDOR_REQUEST_OUT, offset,
  101. value, length,
  102. REGISTER_TIMEOUT32(length));
  103. }
  104. static u32 rt73usb_bbp_check(struct rt2x00_dev *rt2x00dev)
  105. {
  106. u32 reg;
  107. unsigned int i;
  108. for (i = 0; i < REGISTER_BUSY_COUNT; i++) {
  109. rt73usb_register_read_lock(rt2x00dev, PHY_CSR3, &reg);
  110. if (!rt2x00_get_field32(reg, PHY_CSR3_BUSY))
  111. break;
  112. udelay(REGISTER_BUSY_DELAY);
  113. }
  114. return reg;
  115. }
  116. static void rt73usb_bbp_write(struct rt2x00_dev *rt2x00dev,
  117. const unsigned int word, const u8 value)
  118. {
  119. u32 reg;
  120. mutex_lock(&rt2x00dev->csr_mutex);
  121. /*
  122. * Wait until the BBP becomes ready.
  123. */
  124. reg = rt73usb_bbp_check(rt2x00dev);
  125. if (rt2x00_get_field32(reg, PHY_CSR3_BUSY))
  126. goto exit_fail;
  127. /*
  128. * Write the data into the BBP.
  129. */
  130. reg = 0;
  131. rt2x00_set_field32(&reg, PHY_CSR3_VALUE, value);
  132. rt2x00_set_field32(&reg, PHY_CSR3_REGNUM, word);
  133. rt2x00_set_field32(&reg, PHY_CSR3_BUSY, 1);
  134. rt2x00_set_field32(&reg, PHY_CSR3_READ_CONTROL, 0);
  135. rt73usb_register_write_lock(rt2x00dev, PHY_CSR3, reg);
  136. mutex_unlock(&rt2x00dev->csr_mutex);
  137. return;
  138. exit_fail:
  139. mutex_unlock(&rt2x00dev->csr_mutex);
  140. ERROR(rt2x00dev, "PHY_CSR3 register busy. Write failed.\n");
  141. }
  142. static void rt73usb_bbp_read(struct rt2x00_dev *rt2x00dev,
  143. const unsigned int word, u8 *value)
  144. {
  145. u32 reg;
  146. mutex_lock(&rt2x00dev->csr_mutex);
  147. /*
  148. * Wait until the BBP becomes ready.
  149. */
  150. reg = rt73usb_bbp_check(rt2x00dev);
  151. if (rt2x00_get_field32(reg, PHY_CSR3_BUSY))
  152. goto exit_fail;
  153. /*
  154. * Write the request into the BBP.
  155. */
  156. reg = 0;
  157. rt2x00_set_field32(&reg, PHY_CSR3_REGNUM, word);
  158. rt2x00_set_field32(&reg, PHY_CSR3_BUSY, 1);
  159. rt2x00_set_field32(&reg, PHY_CSR3_READ_CONTROL, 1);
  160. rt73usb_register_write_lock(rt2x00dev, PHY_CSR3, reg);
  161. /*
  162. * Wait until the BBP becomes ready.
  163. */
  164. reg = rt73usb_bbp_check(rt2x00dev);
  165. if (rt2x00_get_field32(reg, PHY_CSR3_BUSY))
  166. goto exit_fail;
  167. *value = rt2x00_get_field32(reg, PHY_CSR3_VALUE);
  168. mutex_unlock(&rt2x00dev->csr_mutex);
  169. return;
  170. exit_fail:
  171. mutex_unlock(&rt2x00dev->csr_mutex);
  172. ERROR(rt2x00dev, "PHY_CSR3 register busy. Read failed.\n");
  173. *value = 0xff;
  174. }
  175. static void rt73usb_rf_write(struct rt2x00_dev *rt2x00dev,
  176. const unsigned int word, const u32 value)
  177. {
  178. u32 reg;
  179. unsigned int i;
  180. if (!word)
  181. return;
  182. mutex_lock(&rt2x00dev->csr_mutex);
  183. for (i = 0; i < REGISTER_BUSY_COUNT; i++) {
  184. rt73usb_register_read_lock(rt2x00dev, PHY_CSR4, &reg);
  185. if (!rt2x00_get_field32(reg, PHY_CSR4_BUSY))
  186. goto rf_write;
  187. udelay(REGISTER_BUSY_DELAY);
  188. }
  189. mutex_unlock(&rt2x00dev->csr_mutex);
  190. ERROR(rt2x00dev, "PHY_CSR4 register busy. Write failed.\n");
  191. return;
  192. rf_write:
  193. reg = 0;
  194. rt2x00_set_field32(&reg, PHY_CSR4_VALUE, value);
  195. /*
  196. * RF5225 and RF2527 contain 21 bits per RF register value,
  197. * all others contain 20 bits.
  198. */
  199. rt2x00_set_field32(&reg, PHY_CSR4_NUMBER_OF_BITS,
  200. 20 + (rt2x00_rf(&rt2x00dev->chip, RF5225) ||
  201. rt2x00_rf(&rt2x00dev->chip, RF2527)));
  202. rt2x00_set_field32(&reg, PHY_CSR4_IF_SELECT, 0);
  203. rt2x00_set_field32(&reg, PHY_CSR4_BUSY, 1);
  204. rt73usb_register_write_lock(rt2x00dev, PHY_CSR4, reg);
  205. rt2x00_rf_write(rt2x00dev, word, value);
  206. mutex_unlock(&rt2x00dev->csr_mutex);
  207. }
  208. #ifdef CONFIG_RT2X00_LIB_DEBUGFS
  209. static const struct rt2x00debug rt73usb_rt2x00debug = {
  210. .owner = THIS_MODULE,
  211. .csr = {
  212. .read = rt73usb_register_read,
  213. .write = rt73usb_register_write,
  214. .flags = RT2X00DEBUGFS_OFFSET,
  215. .word_base = CSR_REG_BASE,
  216. .word_size = sizeof(u32),
  217. .word_count = CSR_REG_SIZE / sizeof(u32),
  218. },
  219. .eeprom = {
  220. .read = rt2x00_eeprom_read,
  221. .write = rt2x00_eeprom_write,
  222. .word_base = EEPROM_BASE,
  223. .word_size = sizeof(u16),
  224. .word_count = EEPROM_SIZE / sizeof(u16),
  225. },
  226. .bbp = {
  227. .read = rt73usb_bbp_read,
  228. .write = rt73usb_bbp_write,
  229. .word_base = BBP_BASE,
  230. .word_size = sizeof(u8),
  231. .word_count = BBP_SIZE / sizeof(u8),
  232. },
  233. .rf = {
  234. .read = rt2x00_rf_read,
  235. .write = rt73usb_rf_write,
  236. .word_base = RF_BASE,
  237. .word_size = sizeof(u32),
  238. .word_count = RF_SIZE / sizeof(u32),
  239. },
  240. };
  241. #endif /* CONFIG_RT2X00_LIB_DEBUGFS */
  242. #ifdef CONFIG_RT2X00_LIB_LEDS
  243. static void rt73usb_brightness_set(struct led_classdev *led_cdev,
  244. enum led_brightness brightness)
  245. {
  246. struct rt2x00_led *led =
  247. container_of(led_cdev, struct rt2x00_led, led_dev);
  248. unsigned int enabled = brightness != LED_OFF;
  249. unsigned int a_mode =
  250. (enabled && led->rt2x00dev->curr_band == IEEE80211_BAND_5GHZ);
  251. unsigned int bg_mode =
  252. (enabled && led->rt2x00dev->curr_band == IEEE80211_BAND_2GHZ);
  253. if (led->type == LED_TYPE_RADIO) {
  254. rt2x00_set_field16(&led->rt2x00dev->led_mcu_reg,
  255. MCU_LEDCS_RADIO_STATUS, enabled);
  256. rt2x00usb_vendor_request_sw(led->rt2x00dev, USB_LED_CONTROL,
  257. 0, led->rt2x00dev->led_mcu_reg,
  258. REGISTER_TIMEOUT);
  259. } else if (led->type == LED_TYPE_ASSOC) {
  260. rt2x00_set_field16(&led->rt2x00dev->led_mcu_reg,
  261. MCU_LEDCS_LINK_BG_STATUS, bg_mode);
  262. rt2x00_set_field16(&led->rt2x00dev->led_mcu_reg,
  263. MCU_LEDCS_LINK_A_STATUS, a_mode);
  264. rt2x00usb_vendor_request_sw(led->rt2x00dev, USB_LED_CONTROL,
  265. 0, led->rt2x00dev->led_mcu_reg,
  266. REGISTER_TIMEOUT);
  267. } else if (led->type == LED_TYPE_QUALITY) {
  268. /*
  269. * The brightness is divided into 6 levels (0 - 5),
  270. * this means we need to convert the brightness
  271. * argument into the matching level within that range.
  272. */
  273. rt2x00usb_vendor_request_sw(led->rt2x00dev, USB_LED_CONTROL,
  274. brightness / (LED_FULL / 6),
  275. led->rt2x00dev->led_mcu_reg,
  276. REGISTER_TIMEOUT);
  277. }
  278. }
  279. static int rt73usb_blink_set(struct led_classdev *led_cdev,
  280. unsigned long *delay_on,
  281. unsigned long *delay_off)
  282. {
  283. struct rt2x00_led *led =
  284. container_of(led_cdev, struct rt2x00_led, led_dev);
  285. u32 reg;
  286. rt73usb_register_read(led->rt2x00dev, MAC_CSR14, &reg);
  287. rt2x00_set_field32(&reg, MAC_CSR14_ON_PERIOD, *delay_on);
  288. rt2x00_set_field32(&reg, MAC_CSR14_OFF_PERIOD, *delay_off);
  289. rt73usb_register_write(led->rt2x00dev, MAC_CSR14, reg);
  290. return 0;
  291. }
  292. static void rt73usb_init_led(struct rt2x00_dev *rt2x00dev,
  293. struct rt2x00_led *led,
  294. enum led_type type)
  295. {
  296. led->rt2x00dev = rt2x00dev;
  297. led->type = type;
  298. led->led_dev.brightness_set = rt73usb_brightness_set;
  299. led->led_dev.blink_set = rt73usb_blink_set;
  300. led->flags = LED_INITIALIZED;
  301. }
  302. #endif /* CONFIG_RT2X00_LIB_LEDS */
  303. /*
  304. * Configuration handlers.
  305. */
  306. static int rt73usb_config_shared_key(struct rt2x00_dev *rt2x00dev,
  307. struct rt2x00lib_crypto *crypto,
  308. struct ieee80211_key_conf *key)
  309. {
  310. struct hw_key_entry key_entry;
  311. struct rt2x00_field32 field;
  312. int timeout;
  313. u32 mask;
  314. u32 reg;
  315. if (crypto->cmd == SET_KEY) {
  316. /*
  317. * rt2x00lib can't determine the correct free
  318. * key_idx for shared keys. We have 1 register
  319. * with key valid bits. The goal is simple, read
  320. * the register, if that is full we have no slots
  321. * left.
  322. * Note that each BSS is allowed to have up to 4
  323. * shared keys, so put a mask over the allowed
  324. * entries.
  325. */
  326. mask = (0xf << crypto->bssidx);
  327. rt73usb_register_read(rt2x00dev, SEC_CSR0, &reg);
  328. reg &= mask;
  329. if (reg && reg == mask)
  330. return -ENOSPC;
  331. key->hw_key_idx += reg ? ffz(reg) : 0;
  332. /*
  333. * Upload key to hardware
  334. */
  335. memcpy(key_entry.key, crypto->key,
  336. sizeof(key_entry.key));
  337. memcpy(key_entry.tx_mic, crypto->tx_mic,
  338. sizeof(key_entry.tx_mic));
  339. memcpy(key_entry.rx_mic, crypto->rx_mic,
  340. sizeof(key_entry.rx_mic));
  341. reg = SHARED_KEY_ENTRY(key->hw_key_idx);
  342. timeout = REGISTER_TIMEOUT32(sizeof(key_entry));
  343. rt2x00usb_vendor_request_large_buff(rt2x00dev, USB_MULTI_WRITE,
  344. USB_VENDOR_REQUEST_OUT, reg,
  345. &key_entry,
  346. sizeof(key_entry),
  347. timeout);
  348. /*
  349. * The cipher types are stored over 2 registers.
  350. * bssidx 0 and 1 keys are stored in SEC_CSR1 and
  351. * bssidx 1 and 2 keys are stored in SEC_CSR5.
  352. * Using the correct defines correctly will cause overhead,
  353. * so just calculate the correct offset.
  354. */
  355. if (key->hw_key_idx < 8) {
  356. field.bit_offset = (3 * key->hw_key_idx);
  357. field.bit_mask = 0x7 << field.bit_offset;
  358. rt73usb_register_read(rt2x00dev, SEC_CSR1, &reg);
  359. rt2x00_set_field32(&reg, field, crypto->cipher);
  360. rt73usb_register_write(rt2x00dev, SEC_CSR1, reg);
  361. } else {
  362. field.bit_offset = (3 * (key->hw_key_idx - 8));
  363. field.bit_mask = 0x7 << field.bit_offset;
  364. rt73usb_register_read(rt2x00dev, SEC_CSR5, &reg);
  365. rt2x00_set_field32(&reg, field, crypto->cipher);
  366. rt73usb_register_write(rt2x00dev, SEC_CSR5, reg);
  367. }
  368. /*
  369. * The driver does not support the IV/EIV generation
  370. * in hardware. However it doesn't support the IV/EIV
  371. * inside the ieee80211 frame either, but requires it
  372. * to be provided seperately for the descriptor.
  373. * rt2x00lib will cut the IV/EIV data out of all frames
  374. * given to us by mac80211, but we must tell mac80211
  375. * to generate the IV/EIV data.
  376. */
  377. key->flags |= IEEE80211_KEY_FLAG_GENERATE_IV;
  378. }
  379. /*
  380. * SEC_CSR0 contains only single-bit fields to indicate
  381. * a particular key is valid. Because using the FIELD32()
  382. * defines directly will cause a lot of overhead we use
  383. * a calculation to determine the correct bit directly.
  384. */
  385. mask = 1 << key->hw_key_idx;
  386. rt73usb_register_read(rt2x00dev, SEC_CSR0, &reg);
  387. if (crypto->cmd == SET_KEY)
  388. reg |= mask;
  389. else if (crypto->cmd == DISABLE_KEY)
  390. reg &= ~mask;
  391. rt73usb_register_write(rt2x00dev, SEC_CSR0, reg);
  392. return 0;
  393. }
  394. static int rt73usb_config_pairwise_key(struct rt2x00_dev *rt2x00dev,
  395. struct rt2x00lib_crypto *crypto,
  396. struct ieee80211_key_conf *key)
  397. {
  398. struct hw_pairwise_ta_entry addr_entry;
  399. struct hw_key_entry key_entry;
  400. int timeout;
  401. u32 mask;
  402. u32 reg;
  403. if (crypto->cmd == SET_KEY) {
  404. /*
  405. * rt2x00lib can't determine the correct free
  406. * key_idx for pairwise keys. We have 2 registers
  407. * with key valid bits. The goal is simple, read
  408. * the first register, if that is full move to
  409. * the next register.
  410. * When both registers are full, we drop the key,
  411. * otherwise we use the first invalid entry.
  412. */
  413. rt73usb_register_read(rt2x00dev, SEC_CSR2, &reg);
  414. if (reg && reg == ~0) {
  415. key->hw_key_idx = 32;
  416. rt73usb_register_read(rt2x00dev, SEC_CSR3, &reg);
  417. if (reg && reg == ~0)
  418. return -ENOSPC;
  419. }
  420. key->hw_key_idx += reg ? ffz(reg) : 0;
  421. /*
  422. * Upload key to hardware
  423. */
  424. memcpy(key_entry.key, crypto->key,
  425. sizeof(key_entry.key));
  426. memcpy(key_entry.tx_mic, crypto->tx_mic,
  427. sizeof(key_entry.tx_mic));
  428. memcpy(key_entry.rx_mic, crypto->rx_mic,
  429. sizeof(key_entry.rx_mic));
  430. reg = PAIRWISE_KEY_ENTRY(key->hw_key_idx);
  431. timeout = REGISTER_TIMEOUT32(sizeof(key_entry));
  432. rt2x00usb_vendor_request_large_buff(rt2x00dev, USB_MULTI_WRITE,
  433. USB_VENDOR_REQUEST_OUT, reg,
  434. &key_entry,
  435. sizeof(key_entry),
  436. timeout);
  437. /*
  438. * Send the address and cipher type to the hardware register.
  439. * This data fits within the CSR cache size, so we can use
  440. * rt73usb_register_multiwrite() directly.
  441. */
  442. memset(&addr_entry, 0, sizeof(addr_entry));
  443. memcpy(&addr_entry, crypto->address, ETH_ALEN);
  444. addr_entry.cipher = crypto->cipher;
  445. reg = PAIRWISE_TA_ENTRY(key->hw_key_idx);
  446. rt73usb_register_multiwrite(rt2x00dev, reg,
  447. &addr_entry, sizeof(addr_entry));
  448. /*
  449. * Enable pairwise lookup table for given BSS idx,
  450. * without this received frames will not be decrypted
  451. * by the hardware.
  452. */
  453. rt73usb_register_read(rt2x00dev, SEC_CSR4, &reg);
  454. reg |= (1 << crypto->bssidx);
  455. rt73usb_register_write(rt2x00dev, SEC_CSR4, reg);
  456. /*
  457. * The driver does not support the IV/EIV generation
  458. * in hardware. However it doesn't support the IV/EIV
  459. * inside the ieee80211 frame either, but requires it
  460. * to be provided seperately for the descriptor.
  461. * rt2x00lib will cut the IV/EIV data out of all frames
  462. * given to us by mac80211, but we must tell mac80211
  463. * to generate the IV/EIV data.
  464. */
  465. key->flags |= IEEE80211_KEY_FLAG_GENERATE_IV;
  466. }
  467. /*
  468. * SEC_CSR2 and SEC_CSR3 contain only single-bit fields to indicate
  469. * a particular key is valid. Because using the FIELD32()
  470. * defines directly will cause a lot of overhead we use
  471. * a calculation to determine the correct bit directly.
  472. */
  473. if (key->hw_key_idx < 32) {
  474. mask = 1 << key->hw_key_idx;
  475. rt73usb_register_read(rt2x00dev, SEC_CSR2, &reg);
  476. if (crypto->cmd == SET_KEY)
  477. reg |= mask;
  478. else if (crypto->cmd == DISABLE_KEY)
  479. reg &= ~mask;
  480. rt73usb_register_write(rt2x00dev, SEC_CSR2, reg);
  481. } else {
  482. mask = 1 << (key->hw_key_idx - 32);
  483. rt73usb_register_read(rt2x00dev, SEC_CSR3, &reg);
  484. if (crypto->cmd == SET_KEY)
  485. reg |= mask;
  486. else if (crypto->cmd == DISABLE_KEY)
  487. reg &= ~mask;
  488. rt73usb_register_write(rt2x00dev, SEC_CSR3, reg);
  489. }
  490. return 0;
  491. }
  492. static void rt73usb_config_filter(struct rt2x00_dev *rt2x00dev,
  493. const unsigned int filter_flags)
  494. {
  495. u32 reg;
  496. /*
  497. * Start configuration steps.
  498. * Note that the version error will always be dropped
  499. * and broadcast frames will always be accepted since
  500. * there is no filter for it at this time.
  501. */
  502. rt73usb_register_read(rt2x00dev, TXRX_CSR0, &reg);
  503. rt2x00_set_field32(&reg, TXRX_CSR0_DROP_CRC,
  504. !(filter_flags & FIF_FCSFAIL));
  505. rt2x00_set_field32(&reg, TXRX_CSR0_DROP_PHYSICAL,
  506. !(filter_flags & FIF_PLCPFAIL));
  507. rt2x00_set_field32(&reg, TXRX_CSR0_DROP_CONTROL,
  508. !(filter_flags & FIF_CONTROL));
  509. rt2x00_set_field32(&reg, TXRX_CSR0_DROP_NOT_TO_ME,
  510. !(filter_flags & FIF_PROMISC_IN_BSS));
  511. rt2x00_set_field32(&reg, TXRX_CSR0_DROP_TO_DS,
  512. !(filter_flags & FIF_PROMISC_IN_BSS) &&
  513. !rt2x00dev->intf_ap_count);
  514. rt2x00_set_field32(&reg, TXRX_CSR0_DROP_VERSION_ERROR, 1);
  515. rt2x00_set_field32(&reg, TXRX_CSR0_DROP_MULTICAST,
  516. !(filter_flags & FIF_ALLMULTI));
  517. rt2x00_set_field32(&reg, TXRX_CSR0_DROP_BROADCAST, 0);
  518. rt2x00_set_field32(&reg, TXRX_CSR0_DROP_ACK_CTS,
  519. !(filter_flags & FIF_CONTROL));
  520. rt73usb_register_write(rt2x00dev, TXRX_CSR0, reg);
  521. }
  522. static void rt73usb_config_intf(struct rt2x00_dev *rt2x00dev,
  523. struct rt2x00_intf *intf,
  524. struct rt2x00intf_conf *conf,
  525. const unsigned int flags)
  526. {
  527. unsigned int beacon_base;
  528. u32 reg;
  529. if (flags & CONFIG_UPDATE_TYPE) {
  530. /*
  531. * Clear current synchronisation setup.
  532. * For the Beacon base registers we only need to clear
  533. * the first byte since that byte contains the VALID and OWNER
  534. * bits which (when set to 0) will invalidate the entire beacon.
  535. */
  536. beacon_base = HW_BEACON_OFFSET(intf->beacon->entry_idx);
  537. rt73usb_register_write(rt2x00dev, beacon_base, 0);
  538. /*
  539. * Enable synchronisation.
  540. */
  541. rt73usb_register_read(rt2x00dev, TXRX_CSR9, &reg);
  542. rt2x00_set_field32(&reg, TXRX_CSR9_TSF_TICKING, 1);
  543. rt2x00_set_field32(&reg, TXRX_CSR9_TSF_SYNC, conf->sync);
  544. rt2x00_set_field32(&reg, TXRX_CSR9_TBTT_ENABLE, 1);
  545. rt73usb_register_write(rt2x00dev, TXRX_CSR9, reg);
  546. }
  547. if (flags & CONFIG_UPDATE_MAC) {
  548. reg = le32_to_cpu(conf->mac[1]);
  549. rt2x00_set_field32(&reg, MAC_CSR3_UNICAST_TO_ME_MASK, 0xff);
  550. conf->mac[1] = cpu_to_le32(reg);
  551. rt73usb_register_multiwrite(rt2x00dev, MAC_CSR2,
  552. conf->mac, sizeof(conf->mac));
  553. }
  554. if (flags & CONFIG_UPDATE_BSSID) {
  555. reg = le32_to_cpu(conf->bssid[1]);
  556. rt2x00_set_field32(&reg, MAC_CSR5_BSS_ID_MASK, 3);
  557. conf->bssid[1] = cpu_to_le32(reg);
  558. rt73usb_register_multiwrite(rt2x00dev, MAC_CSR4,
  559. conf->bssid, sizeof(conf->bssid));
  560. }
  561. }
  562. static void rt73usb_config_erp(struct rt2x00_dev *rt2x00dev,
  563. struct rt2x00lib_erp *erp)
  564. {
  565. u32 reg;
  566. rt73usb_register_read(rt2x00dev, TXRX_CSR0, &reg);
  567. rt2x00_set_field32(&reg, TXRX_CSR0_RX_ACK_TIMEOUT, erp->ack_timeout);
  568. rt73usb_register_write(rt2x00dev, TXRX_CSR0, reg);
  569. rt73usb_register_read(rt2x00dev, TXRX_CSR4, &reg);
  570. rt2x00_set_field32(&reg, TXRX_CSR4_AUTORESPOND_PREAMBLE,
  571. !!erp->short_preamble);
  572. rt73usb_register_write(rt2x00dev, TXRX_CSR4, reg);
  573. rt73usb_register_write(rt2x00dev, TXRX_CSR5, erp->basic_rates);
  574. rt73usb_register_read(rt2x00dev, MAC_CSR9, &reg);
  575. rt2x00_set_field32(&reg, MAC_CSR9_SLOT_TIME, erp->slot_time);
  576. rt73usb_register_write(rt2x00dev, MAC_CSR9, reg);
  577. rt73usb_register_read(rt2x00dev, MAC_CSR8, &reg);
  578. rt2x00_set_field32(&reg, MAC_CSR8_SIFS, erp->sifs);
  579. rt2x00_set_field32(&reg, MAC_CSR8_SIFS_AFTER_RX_OFDM, 3);
  580. rt2x00_set_field32(&reg, MAC_CSR8_EIFS, erp->eifs);
  581. rt73usb_register_write(rt2x00dev, MAC_CSR8, reg);
  582. }
  583. static void rt73usb_config_antenna_5x(struct rt2x00_dev *rt2x00dev,
  584. struct antenna_setup *ant)
  585. {
  586. u8 r3;
  587. u8 r4;
  588. u8 r77;
  589. u8 temp;
  590. rt73usb_bbp_read(rt2x00dev, 3, &r3);
  591. rt73usb_bbp_read(rt2x00dev, 4, &r4);
  592. rt73usb_bbp_read(rt2x00dev, 77, &r77);
  593. rt2x00_set_field8(&r3, BBP_R3_SMART_MODE, 0);
  594. /*
  595. * Configure the RX antenna.
  596. */
  597. switch (ant->rx) {
  598. case ANTENNA_HW_DIVERSITY:
  599. rt2x00_set_field8(&r4, BBP_R4_RX_ANTENNA_CONTROL, 2);
  600. temp = !test_bit(CONFIG_FRAME_TYPE, &rt2x00dev->flags)
  601. && (rt2x00dev->curr_band != IEEE80211_BAND_5GHZ);
  602. rt2x00_set_field8(&r4, BBP_R4_RX_FRAME_END, temp);
  603. break;
  604. case ANTENNA_A:
  605. rt2x00_set_field8(&r4, BBP_R4_RX_ANTENNA_CONTROL, 1);
  606. rt2x00_set_field8(&r4, BBP_R4_RX_FRAME_END, 0);
  607. if (rt2x00dev->curr_band == IEEE80211_BAND_5GHZ)
  608. rt2x00_set_field8(&r77, BBP_R77_RX_ANTENNA, 0);
  609. else
  610. rt2x00_set_field8(&r77, BBP_R77_RX_ANTENNA, 3);
  611. break;
  612. case ANTENNA_B:
  613. default:
  614. rt2x00_set_field8(&r4, BBP_R4_RX_ANTENNA_CONTROL, 1);
  615. rt2x00_set_field8(&r4, BBP_R4_RX_FRAME_END, 0);
  616. if (rt2x00dev->curr_band == IEEE80211_BAND_5GHZ)
  617. rt2x00_set_field8(&r77, BBP_R77_RX_ANTENNA, 3);
  618. else
  619. rt2x00_set_field8(&r77, BBP_R77_RX_ANTENNA, 0);
  620. break;
  621. }
  622. rt73usb_bbp_write(rt2x00dev, 77, r77);
  623. rt73usb_bbp_write(rt2x00dev, 3, r3);
  624. rt73usb_bbp_write(rt2x00dev, 4, r4);
  625. }
  626. static void rt73usb_config_antenna_2x(struct rt2x00_dev *rt2x00dev,
  627. struct antenna_setup *ant)
  628. {
  629. u8 r3;
  630. u8 r4;
  631. u8 r77;
  632. rt73usb_bbp_read(rt2x00dev, 3, &r3);
  633. rt73usb_bbp_read(rt2x00dev, 4, &r4);
  634. rt73usb_bbp_read(rt2x00dev, 77, &r77);
  635. rt2x00_set_field8(&r3, BBP_R3_SMART_MODE, 0);
  636. rt2x00_set_field8(&r4, BBP_R4_RX_FRAME_END,
  637. !test_bit(CONFIG_FRAME_TYPE, &rt2x00dev->flags));
  638. /*
  639. * Configure the RX antenna.
  640. */
  641. switch (ant->rx) {
  642. case ANTENNA_HW_DIVERSITY:
  643. rt2x00_set_field8(&r4, BBP_R4_RX_ANTENNA_CONTROL, 2);
  644. break;
  645. case ANTENNA_A:
  646. rt2x00_set_field8(&r77, BBP_R77_RX_ANTENNA, 3);
  647. rt2x00_set_field8(&r4, BBP_R4_RX_ANTENNA_CONTROL, 1);
  648. break;
  649. case ANTENNA_B:
  650. default:
  651. rt2x00_set_field8(&r77, BBP_R77_RX_ANTENNA, 0);
  652. rt2x00_set_field8(&r4, BBP_R4_RX_ANTENNA_CONTROL, 1);
  653. break;
  654. }
  655. rt73usb_bbp_write(rt2x00dev, 77, r77);
  656. rt73usb_bbp_write(rt2x00dev, 3, r3);
  657. rt73usb_bbp_write(rt2x00dev, 4, r4);
  658. }
  659. struct antenna_sel {
  660. u8 word;
  661. /*
  662. * value[0] -> non-LNA
  663. * value[1] -> LNA
  664. */
  665. u8 value[2];
  666. };
  667. static const struct antenna_sel antenna_sel_a[] = {
  668. { 96, { 0x58, 0x78 } },
  669. { 104, { 0x38, 0x48 } },
  670. { 75, { 0xfe, 0x80 } },
  671. { 86, { 0xfe, 0x80 } },
  672. { 88, { 0xfe, 0x80 } },
  673. { 35, { 0x60, 0x60 } },
  674. { 97, { 0x58, 0x58 } },
  675. { 98, { 0x58, 0x58 } },
  676. };
  677. static const struct antenna_sel antenna_sel_bg[] = {
  678. { 96, { 0x48, 0x68 } },
  679. { 104, { 0x2c, 0x3c } },
  680. { 75, { 0xfe, 0x80 } },
  681. { 86, { 0xfe, 0x80 } },
  682. { 88, { 0xfe, 0x80 } },
  683. { 35, { 0x50, 0x50 } },
  684. { 97, { 0x48, 0x48 } },
  685. { 98, { 0x48, 0x48 } },
  686. };
  687. static void rt73usb_config_ant(struct rt2x00_dev *rt2x00dev,
  688. struct antenna_setup *ant)
  689. {
  690. const struct antenna_sel *sel;
  691. unsigned int lna;
  692. unsigned int i;
  693. u32 reg;
  694. /*
  695. * We should never come here because rt2x00lib is supposed
  696. * to catch this and send us the correct antenna explicitely.
  697. */
  698. BUG_ON(ant->rx == ANTENNA_SW_DIVERSITY ||
  699. ant->tx == ANTENNA_SW_DIVERSITY);
  700. if (rt2x00dev->curr_band == IEEE80211_BAND_5GHZ) {
  701. sel = antenna_sel_a;
  702. lna = test_bit(CONFIG_EXTERNAL_LNA_A, &rt2x00dev->flags);
  703. } else {
  704. sel = antenna_sel_bg;
  705. lna = test_bit(CONFIG_EXTERNAL_LNA_BG, &rt2x00dev->flags);
  706. }
  707. for (i = 0; i < ARRAY_SIZE(antenna_sel_a); i++)
  708. rt73usb_bbp_write(rt2x00dev, sel[i].word, sel[i].value[lna]);
  709. rt73usb_register_read(rt2x00dev, PHY_CSR0, &reg);
  710. rt2x00_set_field32(&reg, PHY_CSR0_PA_PE_BG,
  711. (rt2x00dev->curr_band == IEEE80211_BAND_2GHZ));
  712. rt2x00_set_field32(&reg, PHY_CSR0_PA_PE_A,
  713. (rt2x00dev->curr_band == IEEE80211_BAND_5GHZ));
  714. rt73usb_register_write(rt2x00dev, PHY_CSR0, reg);
  715. if (rt2x00_rf(&rt2x00dev->chip, RF5226) ||
  716. rt2x00_rf(&rt2x00dev->chip, RF5225))
  717. rt73usb_config_antenna_5x(rt2x00dev, ant);
  718. else if (rt2x00_rf(&rt2x00dev->chip, RF2528) ||
  719. rt2x00_rf(&rt2x00dev->chip, RF2527))
  720. rt73usb_config_antenna_2x(rt2x00dev, ant);
  721. }
  722. static void rt73usb_config_lna_gain(struct rt2x00_dev *rt2x00dev,
  723. struct rt2x00lib_conf *libconf)
  724. {
  725. u16 eeprom;
  726. short lna_gain = 0;
  727. if (libconf->conf->channel->band == IEEE80211_BAND_2GHZ) {
  728. if (test_bit(CONFIG_EXTERNAL_LNA_BG, &rt2x00dev->flags))
  729. lna_gain += 14;
  730. rt2x00_eeprom_read(rt2x00dev, EEPROM_RSSI_OFFSET_BG, &eeprom);
  731. lna_gain -= rt2x00_get_field16(eeprom, EEPROM_RSSI_OFFSET_BG_1);
  732. } else {
  733. rt2x00_eeprom_read(rt2x00dev, EEPROM_RSSI_OFFSET_A, &eeprom);
  734. lna_gain -= rt2x00_get_field16(eeprom, EEPROM_RSSI_OFFSET_A_1);
  735. }
  736. rt2x00dev->lna_gain = lna_gain;
  737. }
  738. static void rt73usb_config_channel(struct rt2x00_dev *rt2x00dev,
  739. struct rf_channel *rf, const int txpower)
  740. {
  741. u8 r3;
  742. u8 r94;
  743. u8 smart;
  744. rt2x00_set_field32(&rf->rf3, RF3_TXPOWER, TXPOWER_TO_DEV(txpower));
  745. rt2x00_set_field32(&rf->rf4, RF4_FREQ_OFFSET, rt2x00dev->freq_offset);
  746. smart = !(rt2x00_rf(&rt2x00dev->chip, RF5225) ||
  747. rt2x00_rf(&rt2x00dev->chip, RF2527));
  748. rt73usb_bbp_read(rt2x00dev, 3, &r3);
  749. rt2x00_set_field8(&r3, BBP_R3_SMART_MODE, smart);
  750. rt73usb_bbp_write(rt2x00dev, 3, r3);
  751. r94 = 6;
  752. if (txpower > MAX_TXPOWER && txpower <= (MAX_TXPOWER + r94))
  753. r94 += txpower - MAX_TXPOWER;
  754. else if (txpower < MIN_TXPOWER && txpower >= (MIN_TXPOWER - r94))
  755. r94 += txpower;
  756. rt73usb_bbp_write(rt2x00dev, 94, r94);
  757. rt73usb_rf_write(rt2x00dev, 1, rf->rf1);
  758. rt73usb_rf_write(rt2x00dev, 2, rf->rf2);
  759. rt73usb_rf_write(rt2x00dev, 3, rf->rf3 & ~0x00000004);
  760. rt73usb_rf_write(rt2x00dev, 4, rf->rf4);
  761. rt73usb_rf_write(rt2x00dev, 1, rf->rf1);
  762. rt73usb_rf_write(rt2x00dev, 2, rf->rf2);
  763. rt73usb_rf_write(rt2x00dev, 3, rf->rf3 | 0x00000004);
  764. rt73usb_rf_write(rt2x00dev, 4, rf->rf4);
  765. rt73usb_rf_write(rt2x00dev, 1, rf->rf1);
  766. rt73usb_rf_write(rt2x00dev, 2, rf->rf2);
  767. rt73usb_rf_write(rt2x00dev, 3, rf->rf3 & ~0x00000004);
  768. rt73usb_rf_write(rt2x00dev, 4, rf->rf4);
  769. udelay(10);
  770. }
  771. static void rt73usb_config_txpower(struct rt2x00_dev *rt2x00dev,
  772. const int txpower)
  773. {
  774. struct rf_channel rf;
  775. rt2x00_rf_read(rt2x00dev, 1, &rf.rf1);
  776. rt2x00_rf_read(rt2x00dev, 2, &rf.rf2);
  777. rt2x00_rf_read(rt2x00dev, 3, &rf.rf3);
  778. rt2x00_rf_read(rt2x00dev, 4, &rf.rf4);
  779. rt73usb_config_channel(rt2x00dev, &rf, txpower);
  780. }
  781. static void rt73usb_config_retry_limit(struct rt2x00_dev *rt2x00dev,
  782. struct rt2x00lib_conf *libconf)
  783. {
  784. u32 reg;
  785. rt73usb_register_read(rt2x00dev, TXRX_CSR4, &reg);
  786. rt2x00_set_field32(&reg, TXRX_CSR4_LONG_RETRY_LIMIT,
  787. libconf->conf->long_frame_max_tx_count);
  788. rt2x00_set_field32(&reg, TXRX_CSR4_SHORT_RETRY_LIMIT,
  789. libconf->conf->short_frame_max_tx_count);
  790. rt73usb_register_write(rt2x00dev, TXRX_CSR4, reg);
  791. }
  792. static void rt73usb_config_duration(struct rt2x00_dev *rt2x00dev,
  793. struct rt2x00lib_conf *libconf)
  794. {
  795. u32 reg;
  796. rt73usb_register_read(rt2x00dev, TXRX_CSR0, &reg);
  797. rt2x00_set_field32(&reg, TXRX_CSR0_TSF_OFFSET, IEEE80211_HEADER);
  798. rt73usb_register_write(rt2x00dev, TXRX_CSR0, reg);
  799. rt73usb_register_read(rt2x00dev, TXRX_CSR4, &reg);
  800. rt2x00_set_field32(&reg, TXRX_CSR4_AUTORESPOND_ENABLE, 1);
  801. rt73usb_register_write(rt2x00dev, TXRX_CSR4, reg);
  802. rt73usb_register_read(rt2x00dev, TXRX_CSR9, &reg);
  803. rt2x00_set_field32(&reg, TXRX_CSR9_BEACON_INTERVAL,
  804. libconf->conf->beacon_int * 16);
  805. rt73usb_register_write(rt2x00dev, TXRX_CSR9, reg);
  806. }
  807. static void rt73usb_config(struct rt2x00_dev *rt2x00dev,
  808. struct rt2x00lib_conf *libconf,
  809. const unsigned int flags)
  810. {
  811. /* Always recalculate LNA gain before changing configuration */
  812. rt73usb_config_lna_gain(rt2x00dev, libconf);
  813. if (flags & IEEE80211_CONF_CHANGE_CHANNEL)
  814. rt73usb_config_channel(rt2x00dev, &libconf->rf,
  815. libconf->conf->power_level);
  816. if ((flags & IEEE80211_CONF_CHANGE_POWER) &&
  817. !(flags & IEEE80211_CONF_CHANGE_CHANNEL))
  818. rt73usb_config_txpower(rt2x00dev, libconf->conf->power_level);
  819. if (flags & IEEE80211_CONF_CHANGE_RETRY_LIMITS)
  820. rt73usb_config_retry_limit(rt2x00dev, libconf);
  821. if (flags & IEEE80211_CONF_CHANGE_BEACON_INTERVAL)
  822. rt73usb_config_duration(rt2x00dev, libconf);
  823. }
  824. /*
  825. * Link tuning
  826. */
  827. static void rt73usb_link_stats(struct rt2x00_dev *rt2x00dev,
  828. struct link_qual *qual)
  829. {
  830. u32 reg;
  831. /*
  832. * Update FCS error count from register.
  833. */
  834. rt73usb_register_read(rt2x00dev, STA_CSR0, &reg);
  835. qual->rx_failed = rt2x00_get_field32(reg, STA_CSR0_FCS_ERROR);
  836. /*
  837. * Update False CCA count from register.
  838. */
  839. rt73usb_register_read(rt2x00dev, STA_CSR1, &reg);
  840. qual->false_cca = rt2x00_get_field32(reg, STA_CSR1_FALSE_CCA_ERROR);
  841. }
  842. static void rt73usb_reset_tuner(struct rt2x00_dev *rt2x00dev)
  843. {
  844. rt73usb_bbp_write(rt2x00dev, 17, 0x20);
  845. rt2x00dev->link.vgc_level = 0x20;
  846. }
  847. static void rt73usb_link_tuner(struct rt2x00_dev *rt2x00dev)
  848. {
  849. int rssi = rt2x00_get_link_rssi(&rt2x00dev->link);
  850. u8 r17;
  851. u8 up_bound;
  852. u8 low_bound;
  853. rt73usb_bbp_read(rt2x00dev, 17, &r17);
  854. /*
  855. * Determine r17 bounds.
  856. */
  857. if (rt2x00dev->rx_status.band == IEEE80211_BAND_5GHZ) {
  858. low_bound = 0x28;
  859. up_bound = 0x48;
  860. if (test_bit(CONFIG_EXTERNAL_LNA_A, &rt2x00dev->flags)) {
  861. low_bound += 0x10;
  862. up_bound += 0x10;
  863. }
  864. } else {
  865. if (rssi > -82) {
  866. low_bound = 0x1c;
  867. up_bound = 0x40;
  868. } else if (rssi > -84) {
  869. low_bound = 0x1c;
  870. up_bound = 0x20;
  871. } else {
  872. low_bound = 0x1c;
  873. up_bound = 0x1c;
  874. }
  875. if (test_bit(CONFIG_EXTERNAL_LNA_BG, &rt2x00dev->flags)) {
  876. low_bound += 0x14;
  877. up_bound += 0x10;
  878. }
  879. }
  880. /*
  881. * If we are not associated, we should go straight to the
  882. * dynamic CCA tuning.
  883. */
  884. if (!rt2x00dev->intf_associated)
  885. goto dynamic_cca_tune;
  886. /*
  887. * Special big-R17 for very short distance
  888. */
  889. if (rssi > -35) {
  890. if (r17 != 0x60)
  891. rt73usb_bbp_write(rt2x00dev, 17, 0x60);
  892. return;
  893. }
  894. /*
  895. * Special big-R17 for short distance
  896. */
  897. if (rssi >= -58) {
  898. if (r17 != up_bound)
  899. rt73usb_bbp_write(rt2x00dev, 17, up_bound);
  900. return;
  901. }
  902. /*
  903. * Special big-R17 for middle-short distance
  904. */
  905. if (rssi >= -66) {
  906. low_bound += 0x10;
  907. if (r17 != low_bound)
  908. rt73usb_bbp_write(rt2x00dev, 17, low_bound);
  909. return;
  910. }
  911. /*
  912. * Special mid-R17 for middle distance
  913. */
  914. if (rssi >= -74) {
  915. if (r17 != (low_bound + 0x10))
  916. rt73usb_bbp_write(rt2x00dev, 17, low_bound + 0x08);
  917. return;
  918. }
  919. /*
  920. * Special case: Change up_bound based on the rssi.
  921. * Lower up_bound when rssi is weaker then -74 dBm.
  922. */
  923. up_bound -= 2 * (-74 - rssi);
  924. if (low_bound > up_bound)
  925. up_bound = low_bound;
  926. if (r17 > up_bound) {
  927. rt73usb_bbp_write(rt2x00dev, 17, up_bound);
  928. return;
  929. }
  930. dynamic_cca_tune:
  931. /*
  932. * r17 does not yet exceed upper limit, continue and base
  933. * the r17 tuning on the false CCA count.
  934. */
  935. if (rt2x00dev->link.qual.false_cca > 512 && r17 < up_bound) {
  936. r17 += 4;
  937. if (r17 > up_bound)
  938. r17 = up_bound;
  939. rt73usb_bbp_write(rt2x00dev, 17, r17);
  940. } else if (rt2x00dev->link.qual.false_cca < 100 && r17 > low_bound) {
  941. r17 -= 4;
  942. if (r17 < low_bound)
  943. r17 = low_bound;
  944. rt73usb_bbp_write(rt2x00dev, 17, r17);
  945. }
  946. }
  947. /*
  948. * Firmware functions
  949. */
  950. static char *rt73usb_get_firmware_name(struct rt2x00_dev *rt2x00dev)
  951. {
  952. return FIRMWARE_RT2571;
  953. }
  954. static u16 rt73usb_get_firmware_crc(const void *data, const size_t len)
  955. {
  956. u16 crc;
  957. /*
  958. * Use the crc itu-t algorithm.
  959. * The last 2 bytes in the firmware array are the crc checksum itself,
  960. * this means that we should never pass those 2 bytes to the crc
  961. * algorithm.
  962. */
  963. crc = crc_itu_t(0, data, len - 2);
  964. crc = crc_itu_t_byte(crc, 0);
  965. crc = crc_itu_t_byte(crc, 0);
  966. return crc;
  967. }
  968. static int rt73usb_load_firmware(struct rt2x00_dev *rt2x00dev, const void *data,
  969. const size_t len)
  970. {
  971. unsigned int i;
  972. int status;
  973. u32 reg;
  974. /*
  975. * Wait for stable hardware.
  976. */
  977. for (i = 0; i < 100; i++) {
  978. rt73usb_register_read(rt2x00dev, MAC_CSR0, &reg);
  979. if (reg)
  980. break;
  981. msleep(1);
  982. }
  983. if (!reg) {
  984. ERROR(rt2x00dev, "Unstable hardware.\n");
  985. return -EBUSY;
  986. }
  987. /*
  988. * Write firmware to device.
  989. */
  990. rt2x00usb_vendor_request_large_buff(rt2x00dev, USB_MULTI_WRITE,
  991. USB_VENDOR_REQUEST_OUT,
  992. FIRMWARE_IMAGE_BASE,
  993. data, len,
  994. REGISTER_TIMEOUT32(len));
  995. /*
  996. * Send firmware request to device to load firmware,
  997. * we need to specify a long timeout time.
  998. */
  999. status = rt2x00usb_vendor_request_sw(rt2x00dev, USB_DEVICE_MODE,
  1000. 0, USB_MODE_FIRMWARE,
  1001. REGISTER_TIMEOUT_FIRMWARE);
  1002. if (status < 0) {
  1003. ERROR(rt2x00dev, "Failed to write Firmware to device.\n");
  1004. return status;
  1005. }
  1006. return 0;
  1007. }
  1008. /*
  1009. * Initialization functions.
  1010. */
  1011. static int rt73usb_init_registers(struct rt2x00_dev *rt2x00dev)
  1012. {
  1013. u32 reg;
  1014. rt73usb_register_read(rt2x00dev, TXRX_CSR0, &reg);
  1015. rt2x00_set_field32(&reg, TXRX_CSR0_AUTO_TX_SEQ, 1);
  1016. rt2x00_set_field32(&reg, TXRX_CSR0_DISABLE_RX, 0);
  1017. rt2x00_set_field32(&reg, TXRX_CSR0_TX_WITHOUT_WAITING, 0);
  1018. rt73usb_register_write(rt2x00dev, TXRX_CSR0, reg);
  1019. rt73usb_register_read(rt2x00dev, TXRX_CSR1, &reg);
  1020. rt2x00_set_field32(&reg, TXRX_CSR1_BBP_ID0, 47); /* CCK Signal */
  1021. rt2x00_set_field32(&reg, TXRX_CSR1_BBP_ID0_VALID, 1);
  1022. rt2x00_set_field32(&reg, TXRX_CSR1_BBP_ID1, 30); /* Rssi */
  1023. rt2x00_set_field32(&reg, TXRX_CSR1_BBP_ID1_VALID, 1);
  1024. rt2x00_set_field32(&reg, TXRX_CSR1_BBP_ID2, 42); /* OFDM Rate */
  1025. rt2x00_set_field32(&reg, TXRX_CSR1_BBP_ID2_VALID, 1);
  1026. rt2x00_set_field32(&reg, TXRX_CSR1_BBP_ID3, 30); /* Rssi */
  1027. rt2x00_set_field32(&reg, TXRX_CSR1_BBP_ID3_VALID, 1);
  1028. rt73usb_register_write(rt2x00dev, TXRX_CSR1, reg);
  1029. /*
  1030. * CCK TXD BBP registers
  1031. */
  1032. rt73usb_register_read(rt2x00dev, TXRX_CSR2, &reg);
  1033. rt2x00_set_field32(&reg, TXRX_CSR2_BBP_ID0, 13);
  1034. rt2x00_set_field32(&reg, TXRX_CSR2_BBP_ID0_VALID, 1);
  1035. rt2x00_set_field32(&reg, TXRX_CSR2_BBP_ID1, 12);
  1036. rt2x00_set_field32(&reg, TXRX_CSR2_BBP_ID1_VALID, 1);
  1037. rt2x00_set_field32(&reg, TXRX_CSR2_BBP_ID2, 11);
  1038. rt2x00_set_field32(&reg, TXRX_CSR2_BBP_ID2_VALID, 1);
  1039. rt2x00_set_field32(&reg, TXRX_CSR2_BBP_ID3, 10);
  1040. rt2x00_set_field32(&reg, TXRX_CSR2_BBP_ID3_VALID, 1);
  1041. rt73usb_register_write(rt2x00dev, TXRX_CSR2, reg);
  1042. /*
  1043. * OFDM TXD BBP registers
  1044. */
  1045. rt73usb_register_read(rt2x00dev, TXRX_CSR3, &reg);
  1046. rt2x00_set_field32(&reg, TXRX_CSR3_BBP_ID0, 7);
  1047. rt2x00_set_field32(&reg, TXRX_CSR3_BBP_ID0_VALID, 1);
  1048. rt2x00_set_field32(&reg, TXRX_CSR3_BBP_ID1, 6);
  1049. rt2x00_set_field32(&reg, TXRX_CSR3_BBP_ID1_VALID, 1);
  1050. rt2x00_set_field32(&reg, TXRX_CSR3_BBP_ID2, 5);
  1051. rt2x00_set_field32(&reg, TXRX_CSR3_BBP_ID2_VALID, 1);
  1052. rt73usb_register_write(rt2x00dev, TXRX_CSR3, reg);
  1053. rt73usb_register_read(rt2x00dev, TXRX_CSR7, &reg);
  1054. rt2x00_set_field32(&reg, TXRX_CSR7_ACK_CTS_6MBS, 59);
  1055. rt2x00_set_field32(&reg, TXRX_CSR7_ACK_CTS_9MBS, 53);
  1056. rt2x00_set_field32(&reg, TXRX_CSR7_ACK_CTS_12MBS, 49);
  1057. rt2x00_set_field32(&reg, TXRX_CSR7_ACK_CTS_18MBS, 46);
  1058. rt73usb_register_write(rt2x00dev, TXRX_CSR7, reg);
  1059. rt73usb_register_read(rt2x00dev, TXRX_CSR8, &reg);
  1060. rt2x00_set_field32(&reg, TXRX_CSR8_ACK_CTS_24MBS, 44);
  1061. rt2x00_set_field32(&reg, TXRX_CSR8_ACK_CTS_36MBS, 42);
  1062. rt2x00_set_field32(&reg, TXRX_CSR8_ACK_CTS_48MBS, 42);
  1063. rt2x00_set_field32(&reg, TXRX_CSR8_ACK_CTS_54MBS, 42);
  1064. rt73usb_register_write(rt2x00dev, TXRX_CSR8, reg);
  1065. rt73usb_register_read(rt2x00dev, TXRX_CSR9, &reg);
  1066. rt2x00_set_field32(&reg, TXRX_CSR9_BEACON_INTERVAL, 0);
  1067. rt2x00_set_field32(&reg, TXRX_CSR9_TSF_TICKING, 0);
  1068. rt2x00_set_field32(&reg, TXRX_CSR9_TSF_SYNC, 0);
  1069. rt2x00_set_field32(&reg, TXRX_CSR9_TBTT_ENABLE, 0);
  1070. rt2x00_set_field32(&reg, TXRX_CSR9_BEACON_GEN, 0);
  1071. rt2x00_set_field32(&reg, TXRX_CSR9_TIMESTAMP_COMPENSATE, 0);
  1072. rt73usb_register_write(rt2x00dev, TXRX_CSR9, reg);
  1073. rt73usb_register_write(rt2x00dev, TXRX_CSR15, 0x0000000f);
  1074. rt73usb_register_read(rt2x00dev, MAC_CSR6, &reg);
  1075. rt2x00_set_field32(&reg, MAC_CSR6_MAX_FRAME_UNIT, 0xfff);
  1076. rt73usb_register_write(rt2x00dev, MAC_CSR6, reg);
  1077. rt73usb_register_write(rt2x00dev, MAC_CSR10, 0x00000718);
  1078. if (rt2x00dev->ops->lib->set_device_state(rt2x00dev, STATE_AWAKE))
  1079. return -EBUSY;
  1080. rt73usb_register_write(rt2x00dev, MAC_CSR13, 0x00007f00);
  1081. /*
  1082. * Invalidate all Shared Keys (SEC_CSR0),
  1083. * and clear the Shared key Cipher algorithms (SEC_CSR1 & SEC_CSR5)
  1084. */
  1085. rt73usb_register_write(rt2x00dev, SEC_CSR0, 0x00000000);
  1086. rt73usb_register_write(rt2x00dev, SEC_CSR1, 0x00000000);
  1087. rt73usb_register_write(rt2x00dev, SEC_CSR5, 0x00000000);
  1088. reg = 0x000023b0;
  1089. if (rt2x00_rf(&rt2x00dev->chip, RF5225) ||
  1090. rt2x00_rf(&rt2x00dev->chip, RF2527))
  1091. rt2x00_set_field32(&reg, PHY_CSR1_RF_RPI, 1);
  1092. rt73usb_register_write(rt2x00dev, PHY_CSR1, reg);
  1093. rt73usb_register_write(rt2x00dev, PHY_CSR5, 0x00040a06);
  1094. rt73usb_register_write(rt2x00dev, PHY_CSR6, 0x00080606);
  1095. rt73usb_register_write(rt2x00dev, PHY_CSR7, 0x00000408);
  1096. rt73usb_register_read(rt2x00dev, MAC_CSR9, &reg);
  1097. rt2x00_set_field32(&reg, MAC_CSR9_CW_SELECT, 0);
  1098. rt73usb_register_write(rt2x00dev, MAC_CSR9, reg);
  1099. /*
  1100. * Clear all beacons
  1101. * For the Beacon base registers we only need to clear
  1102. * the first byte since that byte contains the VALID and OWNER
  1103. * bits which (when set to 0) will invalidate the entire beacon.
  1104. */
  1105. rt73usb_register_write(rt2x00dev, HW_BEACON_BASE0, 0);
  1106. rt73usb_register_write(rt2x00dev, HW_BEACON_BASE1, 0);
  1107. rt73usb_register_write(rt2x00dev, HW_BEACON_BASE2, 0);
  1108. rt73usb_register_write(rt2x00dev, HW_BEACON_BASE3, 0);
  1109. /*
  1110. * We must clear the error counters.
  1111. * These registers are cleared on read,
  1112. * so we may pass a useless variable to store the value.
  1113. */
  1114. rt73usb_register_read(rt2x00dev, STA_CSR0, &reg);
  1115. rt73usb_register_read(rt2x00dev, STA_CSR1, &reg);
  1116. rt73usb_register_read(rt2x00dev, STA_CSR2, &reg);
  1117. /*
  1118. * Reset MAC and BBP registers.
  1119. */
  1120. rt73usb_register_read(rt2x00dev, MAC_CSR1, &reg);
  1121. rt2x00_set_field32(&reg, MAC_CSR1_SOFT_RESET, 1);
  1122. rt2x00_set_field32(&reg, MAC_CSR1_BBP_RESET, 1);
  1123. rt73usb_register_write(rt2x00dev, MAC_CSR1, reg);
  1124. rt73usb_register_read(rt2x00dev, MAC_CSR1, &reg);
  1125. rt2x00_set_field32(&reg, MAC_CSR1_SOFT_RESET, 0);
  1126. rt2x00_set_field32(&reg, MAC_CSR1_BBP_RESET, 0);
  1127. rt73usb_register_write(rt2x00dev, MAC_CSR1, reg);
  1128. rt73usb_register_read(rt2x00dev, MAC_CSR1, &reg);
  1129. rt2x00_set_field32(&reg, MAC_CSR1_HOST_READY, 1);
  1130. rt73usb_register_write(rt2x00dev, MAC_CSR1, reg);
  1131. return 0;
  1132. }
  1133. static int rt73usb_wait_bbp_ready(struct rt2x00_dev *rt2x00dev)
  1134. {
  1135. unsigned int i;
  1136. u8 value;
  1137. for (i = 0; i < REGISTER_BUSY_COUNT; i++) {
  1138. rt73usb_bbp_read(rt2x00dev, 0, &value);
  1139. if ((value != 0xff) && (value != 0x00))
  1140. return 0;
  1141. udelay(REGISTER_BUSY_DELAY);
  1142. }
  1143. ERROR(rt2x00dev, "BBP register access failed, aborting.\n");
  1144. return -EACCES;
  1145. }
  1146. static int rt73usb_init_bbp(struct rt2x00_dev *rt2x00dev)
  1147. {
  1148. unsigned int i;
  1149. u16 eeprom;
  1150. u8 reg_id;
  1151. u8 value;
  1152. if (unlikely(rt73usb_wait_bbp_ready(rt2x00dev)))
  1153. return -EACCES;
  1154. rt73usb_bbp_write(rt2x00dev, 3, 0x80);
  1155. rt73usb_bbp_write(rt2x00dev, 15, 0x30);
  1156. rt73usb_bbp_write(rt2x00dev, 21, 0xc8);
  1157. rt73usb_bbp_write(rt2x00dev, 22, 0x38);
  1158. rt73usb_bbp_write(rt2x00dev, 23, 0x06);
  1159. rt73usb_bbp_write(rt2x00dev, 24, 0xfe);
  1160. rt73usb_bbp_write(rt2x00dev, 25, 0x0a);
  1161. rt73usb_bbp_write(rt2x00dev, 26, 0x0d);
  1162. rt73usb_bbp_write(rt2x00dev, 32, 0x0b);
  1163. rt73usb_bbp_write(rt2x00dev, 34, 0x12);
  1164. rt73usb_bbp_write(rt2x00dev, 37, 0x07);
  1165. rt73usb_bbp_write(rt2x00dev, 39, 0xf8);
  1166. rt73usb_bbp_write(rt2x00dev, 41, 0x60);
  1167. rt73usb_bbp_write(rt2x00dev, 53, 0x10);
  1168. rt73usb_bbp_write(rt2x00dev, 54, 0x18);
  1169. rt73usb_bbp_write(rt2x00dev, 60, 0x10);
  1170. rt73usb_bbp_write(rt2x00dev, 61, 0x04);
  1171. rt73usb_bbp_write(rt2x00dev, 62, 0x04);
  1172. rt73usb_bbp_write(rt2x00dev, 75, 0xfe);
  1173. rt73usb_bbp_write(rt2x00dev, 86, 0xfe);
  1174. rt73usb_bbp_write(rt2x00dev, 88, 0xfe);
  1175. rt73usb_bbp_write(rt2x00dev, 90, 0x0f);
  1176. rt73usb_bbp_write(rt2x00dev, 99, 0x00);
  1177. rt73usb_bbp_write(rt2x00dev, 102, 0x16);
  1178. rt73usb_bbp_write(rt2x00dev, 107, 0x04);
  1179. for (i = 0; i < EEPROM_BBP_SIZE; i++) {
  1180. rt2x00_eeprom_read(rt2x00dev, EEPROM_BBP_START + i, &eeprom);
  1181. if (eeprom != 0xffff && eeprom != 0x0000) {
  1182. reg_id = rt2x00_get_field16(eeprom, EEPROM_BBP_REG_ID);
  1183. value = rt2x00_get_field16(eeprom, EEPROM_BBP_VALUE);
  1184. rt73usb_bbp_write(rt2x00dev, reg_id, value);
  1185. }
  1186. }
  1187. return 0;
  1188. }
  1189. /*
  1190. * Device state switch handlers.
  1191. */
  1192. static void rt73usb_toggle_rx(struct rt2x00_dev *rt2x00dev,
  1193. enum dev_state state)
  1194. {
  1195. u32 reg;
  1196. rt73usb_register_read(rt2x00dev, TXRX_CSR0, &reg);
  1197. rt2x00_set_field32(&reg, TXRX_CSR0_DISABLE_RX,
  1198. (state == STATE_RADIO_RX_OFF) ||
  1199. (state == STATE_RADIO_RX_OFF_LINK));
  1200. rt73usb_register_write(rt2x00dev, TXRX_CSR0, reg);
  1201. }
  1202. static int rt73usb_enable_radio(struct rt2x00_dev *rt2x00dev)
  1203. {
  1204. /*
  1205. * Initialize all registers.
  1206. */
  1207. if (unlikely(rt73usb_init_registers(rt2x00dev) ||
  1208. rt73usb_init_bbp(rt2x00dev)))
  1209. return -EIO;
  1210. return 0;
  1211. }
  1212. static void rt73usb_disable_radio(struct rt2x00_dev *rt2x00dev)
  1213. {
  1214. rt73usb_register_write(rt2x00dev, MAC_CSR10, 0x00001818);
  1215. /*
  1216. * Disable synchronisation.
  1217. */
  1218. rt73usb_register_write(rt2x00dev, TXRX_CSR9, 0);
  1219. rt2x00usb_disable_radio(rt2x00dev);
  1220. }
  1221. static int rt73usb_set_state(struct rt2x00_dev *rt2x00dev, enum dev_state state)
  1222. {
  1223. u32 reg;
  1224. unsigned int i;
  1225. char put_to_sleep;
  1226. put_to_sleep = (state != STATE_AWAKE);
  1227. rt73usb_register_read(rt2x00dev, MAC_CSR12, &reg);
  1228. rt2x00_set_field32(&reg, MAC_CSR12_FORCE_WAKEUP, !put_to_sleep);
  1229. rt2x00_set_field32(&reg, MAC_CSR12_PUT_TO_SLEEP, put_to_sleep);
  1230. rt73usb_register_write(rt2x00dev, MAC_CSR12, reg);
  1231. /*
  1232. * Device is not guaranteed to be in the requested state yet.
  1233. * We must wait until the register indicates that the
  1234. * device has entered the correct state.
  1235. */
  1236. for (i = 0; i < REGISTER_BUSY_COUNT; i++) {
  1237. rt73usb_register_read(rt2x00dev, MAC_CSR12, &reg);
  1238. state = rt2x00_get_field32(reg, MAC_CSR12_BBP_CURRENT_STATE);
  1239. if (state == !put_to_sleep)
  1240. return 0;
  1241. msleep(10);
  1242. }
  1243. return -EBUSY;
  1244. }
  1245. static int rt73usb_set_device_state(struct rt2x00_dev *rt2x00dev,
  1246. enum dev_state state)
  1247. {
  1248. int retval = 0;
  1249. switch (state) {
  1250. case STATE_RADIO_ON:
  1251. retval = rt73usb_enable_radio(rt2x00dev);
  1252. break;
  1253. case STATE_RADIO_OFF:
  1254. rt73usb_disable_radio(rt2x00dev);
  1255. break;
  1256. case STATE_RADIO_RX_ON:
  1257. case STATE_RADIO_RX_ON_LINK:
  1258. case STATE_RADIO_RX_OFF:
  1259. case STATE_RADIO_RX_OFF_LINK:
  1260. rt73usb_toggle_rx(rt2x00dev, state);
  1261. break;
  1262. case STATE_RADIO_IRQ_ON:
  1263. case STATE_RADIO_IRQ_OFF:
  1264. /* No support, but no error either */
  1265. break;
  1266. case STATE_DEEP_SLEEP:
  1267. case STATE_SLEEP:
  1268. case STATE_STANDBY:
  1269. case STATE_AWAKE:
  1270. retval = rt73usb_set_state(rt2x00dev, state);
  1271. break;
  1272. default:
  1273. retval = -ENOTSUPP;
  1274. break;
  1275. }
  1276. if (unlikely(retval))
  1277. ERROR(rt2x00dev, "Device failed to enter state %d (%d).\n",
  1278. state, retval);
  1279. return retval;
  1280. }
  1281. /*
  1282. * TX descriptor initialization
  1283. */
  1284. static void rt73usb_write_tx_desc(struct rt2x00_dev *rt2x00dev,
  1285. struct sk_buff *skb,
  1286. struct txentry_desc *txdesc)
  1287. {
  1288. struct skb_frame_desc *skbdesc = get_skb_frame_desc(skb);
  1289. __le32 *txd = skbdesc->desc;
  1290. u32 word;
  1291. /*
  1292. * Start writing the descriptor words.
  1293. */
  1294. rt2x00_desc_read(txd, 1, &word);
  1295. rt2x00_set_field32(&word, TXD_W1_HOST_Q_ID, txdesc->queue);
  1296. rt2x00_set_field32(&word, TXD_W1_AIFSN, txdesc->aifs);
  1297. rt2x00_set_field32(&word, TXD_W1_CWMIN, txdesc->cw_min);
  1298. rt2x00_set_field32(&word, TXD_W1_CWMAX, txdesc->cw_max);
  1299. rt2x00_set_field32(&word, TXD_W1_IV_OFFSET, txdesc->iv_offset);
  1300. rt2x00_set_field32(&word, TXD_W1_HW_SEQUENCE,
  1301. test_bit(ENTRY_TXD_GENERATE_SEQ, &txdesc->flags));
  1302. rt2x00_desc_write(txd, 1, word);
  1303. rt2x00_desc_read(txd, 2, &word);
  1304. rt2x00_set_field32(&word, TXD_W2_PLCP_SIGNAL, txdesc->signal);
  1305. rt2x00_set_field32(&word, TXD_W2_PLCP_SERVICE, txdesc->service);
  1306. rt2x00_set_field32(&word, TXD_W2_PLCP_LENGTH_LOW, txdesc->length_low);
  1307. rt2x00_set_field32(&word, TXD_W2_PLCP_LENGTH_HIGH, txdesc->length_high);
  1308. rt2x00_desc_write(txd, 2, word);
  1309. if (test_bit(ENTRY_TXD_ENCRYPT, &txdesc->flags)) {
  1310. _rt2x00_desc_write(txd, 3, skbdesc->iv);
  1311. _rt2x00_desc_write(txd, 4, skbdesc->eiv);
  1312. }
  1313. rt2x00_desc_read(txd, 5, &word);
  1314. rt2x00_set_field32(&word, TXD_W5_TX_POWER,
  1315. TXPOWER_TO_DEV(rt2x00dev->tx_power));
  1316. rt2x00_set_field32(&word, TXD_W5_WAITING_DMA_DONE_INT, 1);
  1317. rt2x00_desc_write(txd, 5, word);
  1318. rt2x00_desc_read(txd, 0, &word);
  1319. rt2x00_set_field32(&word, TXD_W0_BURST,
  1320. test_bit(ENTRY_TXD_BURST, &txdesc->flags));
  1321. rt2x00_set_field32(&word, TXD_W0_VALID, 1);
  1322. rt2x00_set_field32(&word, TXD_W0_MORE_FRAG,
  1323. test_bit(ENTRY_TXD_MORE_FRAG, &txdesc->flags));
  1324. rt2x00_set_field32(&word, TXD_W0_ACK,
  1325. test_bit(ENTRY_TXD_ACK, &txdesc->flags));
  1326. rt2x00_set_field32(&word, TXD_W0_TIMESTAMP,
  1327. test_bit(ENTRY_TXD_REQ_TIMESTAMP, &txdesc->flags));
  1328. rt2x00_set_field32(&word, TXD_W0_OFDM,
  1329. test_bit(ENTRY_TXD_OFDM_RATE, &txdesc->flags));
  1330. rt2x00_set_field32(&word, TXD_W0_IFS, txdesc->ifs);
  1331. rt2x00_set_field32(&word, TXD_W0_RETRY_MODE,
  1332. test_bit(ENTRY_TXD_RETRY_MODE, &txdesc->flags));
  1333. rt2x00_set_field32(&word, TXD_W0_TKIP_MIC,
  1334. test_bit(ENTRY_TXD_ENCRYPT_MMIC, &txdesc->flags));
  1335. rt2x00_set_field32(&word, TXD_W0_KEY_TABLE,
  1336. test_bit(ENTRY_TXD_ENCRYPT_PAIRWISE, &txdesc->flags));
  1337. rt2x00_set_field32(&word, TXD_W0_KEY_INDEX, txdesc->key_idx);
  1338. rt2x00_set_field32(&word, TXD_W0_DATABYTE_COUNT, skb->len);
  1339. rt2x00_set_field32(&word, TXD_W0_BURST2,
  1340. test_bit(ENTRY_TXD_BURST, &txdesc->flags));
  1341. rt2x00_set_field32(&word, TXD_W0_CIPHER_ALG, txdesc->cipher);
  1342. rt2x00_desc_write(txd, 0, word);
  1343. }
  1344. /*
  1345. * TX data initialization
  1346. */
  1347. static void rt73usb_write_beacon(struct queue_entry *entry)
  1348. {
  1349. struct rt2x00_dev *rt2x00dev = entry->queue->rt2x00dev;
  1350. struct skb_frame_desc *skbdesc = get_skb_frame_desc(entry->skb);
  1351. unsigned int beacon_base;
  1352. u32 reg;
  1353. /*
  1354. * Add the descriptor in front of the skb.
  1355. */
  1356. skb_push(entry->skb, entry->queue->desc_size);
  1357. memcpy(entry->skb->data, skbdesc->desc, skbdesc->desc_len);
  1358. skbdesc->desc = entry->skb->data;
  1359. /*
  1360. * Disable beaconing while we are reloading the beacon data,
  1361. * otherwise we might be sending out invalid data.
  1362. */
  1363. rt73usb_register_read(rt2x00dev, TXRX_CSR9, &reg);
  1364. rt2x00_set_field32(&reg, TXRX_CSR9_TSF_TICKING, 0);
  1365. rt2x00_set_field32(&reg, TXRX_CSR9_TBTT_ENABLE, 0);
  1366. rt2x00_set_field32(&reg, TXRX_CSR9_BEACON_GEN, 0);
  1367. rt73usb_register_write(rt2x00dev, TXRX_CSR9, reg);
  1368. /*
  1369. * Write entire beacon with descriptor to register.
  1370. */
  1371. beacon_base = HW_BEACON_OFFSET(entry->entry_idx);
  1372. rt2x00usb_vendor_request_large_buff(rt2x00dev, USB_MULTI_WRITE,
  1373. USB_VENDOR_REQUEST_OUT, beacon_base,
  1374. entry->skb->data, entry->skb->len,
  1375. REGISTER_TIMEOUT32(entry->skb->len));
  1376. /*
  1377. * Clean up the beacon skb.
  1378. */
  1379. dev_kfree_skb(entry->skb);
  1380. entry->skb = NULL;
  1381. }
  1382. static int rt73usb_get_tx_data_len(struct rt2x00_dev *rt2x00dev,
  1383. struct sk_buff *skb)
  1384. {
  1385. int length;
  1386. /*
  1387. * The length _must_ be a multiple of 4,
  1388. * but it must _not_ be a multiple of the USB packet size.
  1389. */
  1390. length = roundup(skb->len, 4);
  1391. length += (4 * !(length % rt2x00dev->usb_maxpacket));
  1392. return length;
  1393. }
  1394. static void rt73usb_kick_tx_queue(struct rt2x00_dev *rt2x00dev,
  1395. const enum data_queue_qid queue)
  1396. {
  1397. u32 reg;
  1398. if (queue != QID_BEACON) {
  1399. rt2x00usb_kick_tx_queue(rt2x00dev, queue);
  1400. return;
  1401. }
  1402. /*
  1403. * For Wi-Fi faily generated beacons between participating stations.
  1404. * Set TBTT phase adaptive adjustment step to 8us (default 16us)
  1405. */
  1406. rt73usb_register_write(rt2x00dev, TXRX_CSR10, 0x00001008);
  1407. rt73usb_register_read(rt2x00dev, TXRX_CSR9, &reg);
  1408. if (!rt2x00_get_field32(reg, TXRX_CSR9_BEACON_GEN)) {
  1409. rt2x00_set_field32(&reg, TXRX_CSR9_TSF_TICKING, 1);
  1410. rt2x00_set_field32(&reg, TXRX_CSR9_TBTT_ENABLE, 1);
  1411. rt2x00_set_field32(&reg, TXRX_CSR9_BEACON_GEN, 1);
  1412. rt73usb_register_write(rt2x00dev, TXRX_CSR9, reg);
  1413. }
  1414. }
  1415. /*
  1416. * RX control handlers
  1417. */
  1418. static int rt73usb_agc_to_rssi(struct rt2x00_dev *rt2x00dev, int rxd_w1)
  1419. {
  1420. u8 offset = rt2x00dev->lna_gain;
  1421. u8 lna;
  1422. lna = rt2x00_get_field32(rxd_w1, RXD_W1_RSSI_LNA);
  1423. switch (lna) {
  1424. case 3:
  1425. offset += 90;
  1426. break;
  1427. case 2:
  1428. offset += 74;
  1429. break;
  1430. case 1:
  1431. offset += 64;
  1432. break;
  1433. default:
  1434. return 0;
  1435. }
  1436. if (rt2x00dev->rx_status.band == IEEE80211_BAND_5GHZ) {
  1437. if (test_bit(CONFIG_EXTERNAL_LNA_A, &rt2x00dev->flags)) {
  1438. if (lna == 3 || lna == 2)
  1439. offset += 10;
  1440. } else {
  1441. if (lna == 3)
  1442. offset += 6;
  1443. else if (lna == 2)
  1444. offset += 8;
  1445. }
  1446. }
  1447. return rt2x00_get_field32(rxd_w1, RXD_W1_RSSI_AGC) * 2 - offset;
  1448. }
  1449. static void rt73usb_fill_rxdone(struct queue_entry *entry,
  1450. struct rxdone_entry_desc *rxdesc)
  1451. {
  1452. struct rt2x00_dev *rt2x00dev = entry->queue->rt2x00dev;
  1453. struct skb_frame_desc *skbdesc = get_skb_frame_desc(entry->skb);
  1454. __le32 *rxd = (__le32 *)entry->skb->data;
  1455. u32 word0;
  1456. u32 word1;
  1457. /*
  1458. * Copy descriptor to the skbdesc->desc buffer, making it safe from moving of
  1459. * frame data in rt2x00usb.
  1460. */
  1461. memcpy(skbdesc->desc, rxd, skbdesc->desc_len);
  1462. rxd = (__le32 *)skbdesc->desc;
  1463. /*
  1464. * It is now safe to read the descriptor on all architectures.
  1465. */
  1466. rt2x00_desc_read(rxd, 0, &word0);
  1467. rt2x00_desc_read(rxd, 1, &word1);
  1468. if (rt2x00_get_field32(word0, RXD_W0_CRC_ERROR))
  1469. rxdesc->flags |= RX_FLAG_FAILED_FCS_CRC;
  1470. if (test_bit(CONFIG_SUPPORT_HW_CRYPTO, &rt2x00dev->flags)) {
  1471. rxdesc->cipher =
  1472. rt2x00_get_field32(word0, RXD_W0_CIPHER_ALG);
  1473. rxdesc->cipher_status =
  1474. rt2x00_get_field32(word0, RXD_W0_CIPHER_ERROR);
  1475. }
  1476. if (rxdesc->cipher != CIPHER_NONE) {
  1477. _rt2x00_desc_read(rxd, 2, &rxdesc->iv);
  1478. _rt2x00_desc_read(rxd, 3, &rxdesc->eiv);
  1479. _rt2x00_desc_read(rxd, 4, &rxdesc->icv);
  1480. /*
  1481. * Hardware has stripped IV/EIV data from 802.11 frame during
  1482. * decryption. It has provided the data seperately but rt2x00lib
  1483. * should decide if it should be reinserted.
  1484. */
  1485. rxdesc->flags |= RX_FLAG_IV_STRIPPED;
  1486. /*
  1487. * FIXME: Legacy driver indicates that the frame does
  1488. * contain the Michael Mic. Unfortunately, in rt2x00
  1489. * the MIC seems to be missing completely...
  1490. */
  1491. rxdesc->flags |= RX_FLAG_MMIC_STRIPPED;
  1492. if (rxdesc->cipher_status == RX_CRYPTO_SUCCESS)
  1493. rxdesc->flags |= RX_FLAG_DECRYPTED;
  1494. else if (rxdesc->cipher_status == RX_CRYPTO_FAIL_MIC)
  1495. rxdesc->flags |= RX_FLAG_MMIC_ERROR;
  1496. }
  1497. /*
  1498. * Obtain the status about this packet.
  1499. * When frame was received with an OFDM bitrate,
  1500. * the signal is the PLCP value. If it was received with
  1501. * a CCK bitrate the signal is the rate in 100kbit/s.
  1502. */
  1503. rxdesc->signal = rt2x00_get_field32(word1, RXD_W1_SIGNAL);
  1504. rxdesc->rssi = rt73usb_agc_to_rssi(rt2x00dev, word1);
  1505. rxdesc->size = rt2x00_get_field32(word0, RXD_W0_DATABYTE_COUNT);
  1506. if (rt2x00_get_field32(word0, RXD_W0_OFDM))
  1507. rxdesc->dev_flags |= RXDONE_SIGNAL_PLCP;
  1508. else
  1509. rxdesc->dev_flags |= RXDONE_SIGNAL_BITRATE;
  1510. if (rt2x00_get_field32(word0, RXD_W0_MY_BSS))
  1511. rxdesc->dev_flags |= RXDONE_MY_BSS;
  1512. /*
  1513. * Set skb pointers, and update frame information.
  1514. */
  1515. skb_pull(entry->skb, entry->queue->desc_size);
  1516. skb_trim(entry->skb, rxdesc->size);
  1517. }
  1518. /*
  1519. * Device probe functions.
  1520. */
  1521. static int rt73usb_validate_eeprom(struct rt2x00_dev *rt2x00dev)
  1522. {
  1523. u16 word;
  1524. u8 *mac;
  1525. s8 value;
  1526. rt2x00usb_eeprom_read(rt2x00dev, rt2x00dev->eeprom, EEPROM_SIZE);
  1527. /*
  1528. * Start validation of the data that has been read.
  1529. */
  1530. mac = rt2x00_eeprom_addr(rt2x00dev, EEPROM_MAC_ADDR_0);
  1531. if (!is_valid_ether_addr(mac)) {
  1532. random_ether_addr(mac);
  1533. EEPROM(rt2x00dev, "MAC: %pM\n", mac);
  1534. }
  1535. rt2x00_eeprom_read(rt2x00dev, EEPROM_ANTENNA, &word);
  1536. if (word == 0xffff) {
  1537. rt2x00_set_field16(&word, EEPROM_ANTENNA_NUM, 2);
  1538. rt2x00_set_field16(&word, EEPROM_ANTENNA_TX_DEFAULT,
  1539. ANTENNA_B);
  1540. rt2x00_set_field16(&word, EEPROM_ANTENNA_RX_DEFAULT,
  1541. ANTENNA_B);
  1542. rt2x00_set_field16(&word, EEPROM_ANTENNA_FRAME_TYPE, 0);
  1543. rt2x00_set_field16(&word, EEPROM_ANTENNA_DYN_TXAGC, 0);
  1544. rt2x00_set_field16(&word, EEPROM_ANTENNA_HARDWARE_RADIO, 0);
  1545. rt2x00_set_field16(&word, EEPROM_ANTENNA_RF_TYPE, RF5226);
  1546. rt2x00_eeprom_write(rt2x00dev, EEPROM_ANTENNA, word);
  1547. EEPROM(rt2x00dev, "Antenna: 0x%04x\n", word);
  1548. }
  1549. rt2x00_eeprom_read(rt2x00dev, EEPROM_NIC, &word);
  1550. if (word == 0xffff) {
  1551. rt2x00_set_field16(&word, EEPROM_NIC_EXTERNAL_LNA, 0);
  1552. rt2x00_eeprom_write(rt2x00dev, EEPROM_NIC, word);
  1553. EEPROM(rt2x00dev, "NIC: 0x%04x\n", word);
  1554. }
  1555. rt2x00_eeprom_read(rt2x00dev, EEPROM_LED, &word);
  1556. if (word == 0xffff) {
  1557. rt2x00_set_field16(&word, EEPROM_LED_POLARITY_RDY_G, 0);
  1558. rt2x00_set_field16(&word, EEPROM_LED_POLARITY_RDY_A, 0);
  1559. rt2x00_set_field16(&word, EEPROM_LED_POLARITY_ACT, 0);
  1560. rt2x00_set_field16(&word, EEPROM_LED_POLARITY_GPIO_0, 0);
  1561. rt2x00_set_field16(&word, EEPROM_LED_POLARITY_GPIO_1, 0);
  1562. rt2x00_set_field16(&word, EEPROM_LED_POLARITY_GPIO_2, 0);
  1563. rt2x00_set_field16(&word, EEPROM_LED_POLARITY_GPIO_3, 0);
  1564. rt2x00_set_field16(&word, EEPROM_LED_POLARITY_GPIO_4, 0);
  1565. rt2x00_set_field16(&word, EEPROM_LED_LED_MODE,
  1566. LED_MODE_DEFAULT);
  1567. rt2x00_eeprom_write(rt2x00dev, EEPROM_LED, word);
  1568. EEPROM(rt2x00dev, "Led: 0x%04x\n", word);
  1569. }
  1570. rt2x00_eeprom_read(rt2x00dev, EEPROM_FREQ, &word);
  1571. if (word == 0xffff) {
  1572. rt2x00_set_field16(&word, EEPROM_FREQ_OFFSET, 0);
  1573. rt2x00_set_field16(&word, EEPROM_FREQ_SEQ, 0);
  1574. rt2x00_eeprom_write(rt2x00dev, EEPROM_FREQ, word);
  1575. EEPROM(rt2x00dev, "Freq: 0x%04x\n", word);
  1576. }
  1577. rt2x00_eeprom_read(rt2x00dev, EEPROM_RSSI_OFFSET_BG, &word);
  1578. if (word == 0xffff) {
  1579. rt2x00_set_field16(&word, EEPROM_RSSI_OFFSET_BG_1, 0);
  1580. rt2x00_set_field16(&word, EEPROM_RSSI_OFFSET_BG_2, 0);
  1581. rt2x00_eeprom_write(rt2x00dev, EEPROM_RSSI_OFFSET_BG, word);
  1582. EEPROM(rt2x00dev, "RSSI OFFSET BG: 0x%04x\n", word);
  1583. } else {
  1584. value = rt2x00_get_field16(word, EEPROM_RSSI_OFFSET_BG_1);
  1585. if (value < -10 || value > 10)
  1586. rt2x00_set_field16(&word, EEPROM_RSSI_OFFSET_BG_1, 0);
  1587. value = rt2x00_get_field16(word, EEPROM_RSSI_OFFSET_BG_2);
  1588. if (value < -10 || value > 10)
  1589. rt2x00_set_field16(&word, EEPROM_RSSI_OFFSET_BG_2, 0);
  1590. rt2x00_eeprom_write(rt2x00dev, EEPROM_RSSI_OFFSET_BG, word);
  1591. }
  1592. rt2x00_eeprom_read(rt2x00dev, EEPROM_RSSI_OFFSET_A, &word);
  1593. if (word == 0xffff) {
  1594. rt2x00_set_field16(&word, EEPROM_RSSI_OFFSET_A_1, 0);
  1595. rt2x00_set_field16(&word, EEPROM_RSSI_OFFSET_A_2, 0);
  1596. rt2x00_eeprom_write(rt2x00dev, EEPROM_RSSI_OFFSET_A, word);
  1597. EEPROM(rt2x00dev, "RSSI OFFSET A: 0x%04x\n", word);
  1598. } else {
  1599. value = rt2x00_get_field16(word, EEPROM_RSSI_OFFSET_A_1);
  1600. if (value < -10 || value > 10)
  1601. rt2x00_set_field16(&word, EEPROM_RSSI_OFFSET_A_1, 0);
  1602. value = rt2x00_get_field16(word, EEPROM_RSSI_OFFSET_A_2);
  1603. if (value < -10 || value > 10)
  1604. rt2x00_set_field16(&word, EEPROM_RSSI_OFFSET_A_2, 0);
  1605. rt2x00_eeprom_write(rt2x00dev, EEPROM_RSSI_OFFSET_A, word);
  1606. }
  1607. return 0;
  1608. }
  1609. static int rt73usb_init_eeprom(struct rt2x00_dev *rt2x00dev)
  1610. {
  1611. u32 reg;
  1612. u16 value;
  1613. u16 eeprom;
  1614. /*
  1615. * Read EEPROM word for configuration.
  1616. */
  1617. rt2x00_eeprom_read(rt2x00dev, EEPROM_ANTENNA, &eeprom);
  1618. /*
  1619. * Identify RF chipset.
  1620. */
  1621. value = rt2x00_get_field16(eeprom, EEPROM_ANTENNA_RF_TYPE);
  1622. rt73usb_register_read(rt2x00dev, MAC_CSR0, &reg);
  1623. rt2x00_set_chip(rt2x00dev, RT2571, value, reg);
  1624. if (!rt2x00_check_rev(&rt2x00dev->chip, 0x25730)) {
  1625. ERROR(rt2x00dev, "Invalid RT chipset detected.\n");
  1626. return -ENODEV;
  1627. }
  1628. if (!rt2x00_rf(&rt2x00dev->chip, RF5226) &&
  1629. !rt2x00_rf(&rt2x00dev->chip, RF2528) &&
  1630. !rt2x00_rf(&rt2x00dev->chip, RF5225) &&
  1631. !rt2x00_rf(&rt2x00dev->chip, RF2527)) {
  1632. ERROR(rt2x00dev, "Invalid RF chipset detected.\n");
  1633. return -ENODEV;
  1634. }
  1635. /*
  1636. * Identify default antenna configuration.
  1637. */
  1638. rt2x00dev->default_ant.tx =
  1639. rt2x00_get_field16(eeprom, EEPROM_ANTENNA_TX_DEFAULT);
  1640. rt2x00dev->default_ant.rx =
  1641. rt2x00_get_field16(eeprom, EEPROM_ANTENNA_RX_DEFAULT);
  1642. /*
  1643. * Read the Frame type.
  1644. */
  1645. if (rt2x00_get_field16(eeprom, EEPROM_ANTENNA_FRAME_TYPE))
  1646. __set_bit(CONFIG_FRAME_TYPE, &rt2x00dev->flags);
  1647. /*
  1648. * Read frequency offset.
  1649. */
  1650. rt2x00_eeprom_read(rt2x00dev, EEPROM_FREQ, &eeprom);
  1651. rt2x00dev->freq_offset = rt2x00_get_field16(eeprom, EEPROM_FREQ_OFFSET);
  1652. /*
  1653. * Read external LNA informations.
  1654. */
  1655. rt2x00_eeprom_read(rt2x00dev, EEPROM_NIC, &eeprom);
  1656. if (rt2x00_get_field16(eeprom, EEPROM_NIC_EXTERNAL_LNA)) {
  1657. __set_bit(CONFIG_EXTERNAL_LNA_A, &rt2x00dev->flags);
  1658. __set_bit(CONFIG_EXTERNAL_LNA_BG, &rt2x00dev->flags);
  1659. }
  1660. /*
  1661. * Store led settings, for correct led behaviour.
  1662. */
  1663. #ifdef CONFIG_RT2X00_LIB_LEDS
  1664. rt2x00_eeprom_read(rt2x00dev, EEPROM_LED, &eeprom);
  1665. rt73usb_init_led(rt2x00dev, &rt2x00dev->led_radio, LED_TYPE_RADIO);
  1666. rt73usb_init_led(rt2x00dev, &rt2x00dev->led_assoc, LED_TYPE_ASSOC);
  1667. if (value == LED_MODE_SIGNAL_STRENGTH)
  1668. rt73usb_init_led(rt2x00dev, &rt2x00dev->led_qual,
  1669. LED_TYPE_QUALITY);
  1670. rt2x00_set_field16(&rt2x00dev->led_mcu_reg, MCU_LEDCS_LED_MODE, value);
  1671. rt2x00_set_field16(&rt2x00dev->led_mcu_reg, MCU_LEDCS_POLARITY_GPIO_0,
  1672. rt2x00_get_field16(eeprom,
  1673. EEPROM_LED_POLARITY_GPIO_0));
  1674. rt2x00_set_field16(&rt2x00dev->led_mcu_reg, MCU_LEDCS_POLARITY_GPIO_1,
  1675. rt2x00_get_field16(eeprom,
  1676. EEPROM_LED_POLARITY_GPIO_1));
  1677. rt2x00_set_field16(&rt2x00dev->led_mcu_reg, MCU_LEDCS_POLARITY_GPIO_2,
  1678. rt2x00_get_field16(eeprom,
  1679. EEPROM_LED_POLARITY_GPIO_2));
  1680. rt2x00_set_field16(&rt2x00dev->led_mcu_reg, MCU_LEDCS_POLARITY_GPIO_3,
  1681. rt2x00_get_field16(eeprom,
  1682. EEPROM_LED_POLARITY_GPIO_3));
  1683. rt2x00_set_field16(&rt2x00dev->led_mcu_reg, MCU_LEDCS_POLARITY_GPIO_4,
  1684. rt2x00_get_field16(eeprom,
  1685. EEPROM_LED_POLARITY_GPIO_4));
  1686. rt2x00_set_field16(&rt2x00dev->led_mcu_reg, MCU_LEDCS_POLARITY_ACT,
  1687. rt2x00_get_field16(eeprom, EEPROM_LED_POLARITY_ACT));
  1688. rt2x00_set_field16(&rt2x00dev->led_mcu_reg, MCU_LEDCS_POLARITY_READY_BG,
  1689. rt2x00_get_field16(eeprom,
  1690. EEPROM_LED_POLARITY_RDY_G));
  1691. rt2x00_set_field16(&rt2x00dev->led_mcu_reg, MCU_LEDCS_POLARITY_READY_A,
  1692. rt2x00_get_field16(eeprom,
  1693. EEPROM_LED_POLARITY_RDY_A));
  1694. #endif /* CONFIG_RT2X00_LIB_LEDS */
  1695. return 0;
  1696. }
  1697. /*
  1698. * RF value list for RF2528
  1699. * Supports: 2.4 GHz
  1700. */
  1701. static const struct rf_channel rf_vals_bg_2528[] = {
  1702. { 1, 0x00002c0c, 0x00000786, 0x00068255, 0x000fea0b },
  1703. { 2, 0x00002c0c, 0x00000786, 0x00068255, 0x000fea1f },
  1704. { 3, 0x00002c0c, 0x0000078a, 0x00068255, 0x000fea0b },
  1705. { 4, 0x00002c0c, 0x0000078a, 0x00068255, 0x000fea1f },
  1706. { 5, 0x00002c0c, 0x0000078e, 0x00068255, 0x000fea0b },
  1707. { 6, 0x00002c0c, 0x0000078e, 0x00068255, 0x000fea1f },
  1708. { 7, 0x00002c0c, 0x00000792, 0x00068255, 0x000fea0b },
  1709. { 8, 0x00002c0c, 0x00000792, 0x00068255, 0x000fea1f },
  1710. { 9, 0x00002c0c, 0x00000796, 0x00068255, 0x000fea0b },
  1711. { 10, 0x00002c0c, 0x00000796, 0x00068255, 0x000fea1f },
  1712. { 11, 0x00002c0c, 0x0000079a, 0x00068255, 0x000fea0b },
  1713. { 12, 0x00002c0c, 0x0000079a, 0x00068255, 0x000fea1f },
  1714. { 13, 0x00002c0c, 0x0000079e, 0x00068255, 0x000fea0b },
  1715. { 14, 0x00002c0c, 0x000007a2, 0x00068255, 0x000fea13 },
  1716. };
  1717. /*
  1718. * RF value list for RF5226
  1719. * Supports: 2.4 GHz & 5.2 GHz
  1720. */
  1721. static const struct rf_channel rf_vals_5226[] = {
  1722. { 1, 0x00002c0c, 0x00000786, 0x00068255, 0x000fea0b },
  1723. { 2, 0x00002c0c, 0x00000786, 0x00068255, 0x000fea1f },
  1724. { 3, 0x00002c0c, 0x0000078a, 0x00068255, 0x000fea0b },
  1725. { 4, 0x00002c0c, 0x0000078a, 0x00068255, 0x000fea1f },
  1726. { 5, 0x00002c0c, 0x0000078e, 0x00068255, 0x000fea0b },
  1727. { 6, 0x00002c0c, 0x0000078e, 0x00068255, 0x000fea1f },
  1728. { 7, 0x00002c0c, 0x00000792, 0x00068255, 0x000fea0b },
  1729. { 8, 0x00002c0c, 0x00000792, 0x00068255, 0x000fea1f },
  1730. { 9, 0x00002c0c, 0x00000796, 0x00068255, 0x000fea0b },
  1731. { 10, 0x00002c0c, 0x00000796, 0x00068255, 0x000fea1f },
  1732. { 11, 0x00002c0c, 0x0000079a, 0x00068255, 0x000fea0b },
  1733. { 12, 0x00002c0c, 0x0000079a, 0x00068255, 0x000fea1f },
  1734. { 13, 0x00002c0c, 0x0000079e, 0x00068255, 0x000fea0b },
  1735. { 14, 0x00002c0c, 0x000007a2, 0x00068255, 0x000fea13 },
  1736. /* 802.11 UNI / HyperLan 2 */
  1737. { 36, 0x00002c0c, 0x0000099a, 0x00098255, 0x000fea23 },
  1738. { 40, 0x00002c0c, 0x000009a2, 0x00098255, 0x000fea03 },
  1739. { 44, 0x00002c0c, 0x000009a6, 0x00098255, 0x000fea0b },
  1740. { 48, 0x00002c0c, 0x000009aa, 0x00098255, 0x000fea13 },
  1741. { 52, 0x00002c0c, 0x000009ae, 0x00098255, 0x000fea1b },
  1742. { 56, 0x00002c0c, 0x000009b2, 0x00098255, 0x000fea23 },
  1743. { 60, 0x00002c0c, 0x000009ba, 0x00098255, 0x000fea03 },
  1744. { 64, 0x00002c0c, 0x000009be, 0x00098255, 0x000fea0b },
  1745. /* 802.11 HyperLan 2 */
  1746. { 100, 0x00002c0c, 0x00000a2a, 0x000b8255, 0x000fea03 },
  1747. { 104, 0x00002c0c, 0x00000a2e, 0x000b8255, 0x000fea0b },
  1748. { 108, 0x00002c0c, 0x00000a32, 0x000b8255, 0x000fea13 },
  1749. { 112, 0x00002c0c, 0x00000a36, 0x000b8255, 0x000fea1b },
  1750. { 116, 0x00002c0c, 0x00000a3a, 0x000b8255, 0x000fea23 },
  1751. { 120, 0x00002c0c, 0x00000a82, 0x000b8255, 0x000fea03 },
  1752. { 124, 0x00002c0c, 0x00000a86, 0x000b8255, 0x000fea0b },
  1753. { 128, 0x00002c0c, 0x00000a8a, 0x000b8255, 0x000fea13 },
  1754. { 132, 0x00002c0c, 0x00000a8e, 0x000b8255, 0x000fea1b },
  1755. { 136, 0x00002c0c, 0x00000a92, 0x000b8255, 0x000fea23 },
  1756. /* 802.11 UNII */
  1757. { 140, 0x00002c0c, 0x00000a9a, 0x000b8255, 0x000fea03 },
  1758. { 149, 0x00002c0c, 0x00000aa2, 0x000b8255, 0x000fea1f },
  1759. { 153, 0x00002c0c, 0x00000aa6, 0x000b8255, 0x000fea27 },
  1760. { 157, 0x00002c0c, 0x00000aae, 0x000b8255, 0x000fea07 },
  1761. { 161, 0x00002c0c, 0x00000ab2, 0x000b8255, 0x000fea0f },
  1762. { 165, 0x00002c0c, 0x00000ab6, 0x000b8255, 0x000fea17 },
  1763. /* MMAC(Japan)J52 ch 34,38,42,46 */
  1764. { 34, 0x00002c0c, 0x0008099a, 0x000da255, 0x000d3a0b },
  1765. { 38, 0x00002c0c, 0x0008099e, 0x000da255, 0x000d3a13 },
  1766. { 42, 0x00002c0c, 0x000809a2, 0x000da255, 0x000d3a1b },
  1767. { 46, 0x00002c0c, 0x000809a6, 0x000da255, 0x000d3a23 },
  1768. };
  1769. /*
  1770. * RF value list for RF5225 & RF2527
  1771. * Supports: 2.4 GHz & 5.2 GHz
  1772. */
  1773. static const struct rf_channel rf_vals_5225_2527[] = {
  1774. { 1, 0x00002ccc, 0x00004786, 0x00068455, 0x000ffa0b },
  1775. { 2, 0x00002ccc, 0x00004786, 0x00068455, 0x000ffa1f },
  1776. { 3, 0x00002ccc, 0x0000478a, 0x00068455, 0x000ffa0b },
  1777. { 4, 0x00002ccc, 0x0000478a, 0x00068455, 0x000ffa1f },
  1778. { 5, 0x00002ccc, 0x0000478e, 0x00068455, 0x000ffa0b },
  1779. { 6, 0x00002ccc, 0x0000478e, 0x00068455, 0x000ffa1f },
  1780. { 7, 0x00002ccc, 0x00004792, 0x00068455, 0x000ffa0b },
  1781. { 8, 0x00002ccc, 0x00004792, 0x00068455, 0x000ffa1f },
  1782. { 9, 0x00002ccc, 0x00004796, 0x00068455, 0x000ffa0b },
  1783. { 10, 0x00002ccc, 0x00004796, 0x00068455, 0x000ffa1f },
  1784. { 11, 0x00002ccc, 0x0000479a, 0x00068455, 0x000ffa0b },
  1785. { 12, 0x00002ccc, 0x0000479a, 0x00068455, 0x000ffa1f },
  1786. { 13, 0x00002ccc, 0x0000479e, 0x00068455, 0x000ffa0b },
  1787. { 14, 0x00002ccc, 0x000047a2, 0x00068455, 0x000ffa13 },
  1788. /* 802.11 UNI / HyperLan 2 */
  1789. { 36, 0x00002ccc, 0x0000499a, 0x0009be55, 0x000ffa23 },
  1790. { 40, 0x00002ccc, 0x000049a2, 0x0009be55, 0x000ffa03 },
  1791. { 44, 0x00002ccc, 0x000049a6, 0x0009be55, 0x000ffa0b },
  1792. { 48, 0x00002ccc, 0x000049aa, 0x0009be55, 0x000ffa13 },
  1793. { 52, 0x00002ccc, 0x000049ae, 0x0009ae55, 0x000ffa1b },
  1794. { 56, 0x00002ccc, 0x000049b2, 0x0009ae55, 0x000ffa23 },
  1795. { 60, 0x00002ccc, 0x000049ba, 0x0009ae55, 0x000ffa03 },
  1796. { 64, 0x00002ccc, 0x000049be, 0x0009ae55, 0x000ffa0b },
  1797. /* 802.11 HyperLan 2 */
  1798. { 100, 0x00002ccc, 0x00004a2a, 0x000bae55, 0x000ffa03 },
  1799. { 104, 0x00002ccc, 0x00004a2e, 0x000bae55, 0x000ffa0b },
  1800. { 108, 0x00002ccc, 0x00004a32, 0x000bae55, 0x000ffa13 },
  1801. { 112, 0x00002ccc, 0x00004a36, 0x000bae55, 0x000ffa1b },
  1802. { 116, 0x00002ccc, 0x00004a3a, 0x000bbe55, 0x000ffa23 },
  1803. { 120, 0x00002ccc, 0x00004a82, 0x000bbe55, 0x000ffa03 },
  1804. { 124, 0x00002ccc, 0x00004a86, 0x000bbe55, 0x000ffa0b },
  1805. { 128, 0x00002ccc, 0x00004a8a, 0x000bbe55, 0x000ffa13 },
  1806. { 132, 0x00002ccc, 0x00004a8e, 0x000bbe55, 0x000ffa1b },
  1807. { 136, 0x00002ccc, 0x00004a92, 0x000bbe55, 0x000ffa23 },
  1808. /* 802.11 UNII */
  1809. { 140, 0x00002ccc, 0x00004a9a, 0x000bbe55, 0x000ffa03 },
  1810. { 149, 0x00002ccc, 0x00004aa2, 0x000bbe55, 0x000ffa1f },
  1811. { 153, 0x00002ccc, 0x00004aa6, 0x000bbe55, 0x000ffa27 },
  1812. { 157, 0x00002ccc, 0x00004aae, 0x000bbe55, 0x000ffa07 },
  1813. { 161, 0x00002ccc, 0x00004ab2, 0x000bbe55, 0x000ffa0f },
  1814. { 165, 0x00002ccc, 0x00004ab6, 0x000bbe55, 0x000ffa17 },
  1815. /* MMAC(Japan)J52 ch 34,38,42,46 */
  1816. { 34, 0x00002ccc, 0x0000499a, 0x0009be55, 0x000ffa0b },
  1817. { 38, 0x00002ccc, 0x0000499e, 0x0009be55, 0x000ffa13 },
  1818. { 42, 0x00002ccc, 0x000049a2, 0x0009be55, 0x000ffa1b },
  1819. { 46, 0x00002ccc, 0x000049a6, 0x0009be55, 0x000ffa23 },
  1820. };
  1821. static int rt73usb_probe_hw_mode(struct rt2x00_dev *rt2x00dev)
  1822. {
  1823. struct hw_mode_spec *spec = &rt2x00dev->spec;
  1824. struct channel_info *info;
  1825. char *tx_power;
  1826. unsigned int i;
  1827. /*
  1828. * Initialize all hw fields.
  1829. */
  1830. rt2x00dev->hw->flags =
  1831. IEEE80211_HW_HOST_BROADCAST_PS_BUFFERING |
  1832. IEEE80211_HW_SIGNAL_DBM;
  1833. rt2x00dev->hw->extra_tx_headroom = TXD_DESC_SIZE;
  1834. SET_IEEE80211_DEV(rt2x00dev->hw, rt2x00dev->dev);
  1835. SET_IEEE80211_PERM_ADDR(rt2x00dev->hw,
  1836. rt2x00_eeprom_addr(rt2x00dev,
  1837. EEPROM_MAC_ADDR_0));
  1838. /*
  1839. * Initialize hw_mode information.
  1840. */
  1841. spec->supported_bands = SUPPORT_BAND_2GHZ;
  1842. spec->supported_rates = SUPPORT_RATE_CCK | SUPPORT_RATE_OFDM;
  1843. if (rt2x00_rf(&rt2x00dev->chip, RF2528)) {
  1844. spec->num_channels = ARRAY_SIZE(rf_vals_bg_2528);
  1845. spec->channels = rf_vals_bg_2528;
  1846. } else if (rt2x00_rf(&rt2x00dev->chip, RF5226)) {
  1847. spec->supported_bands |= SUPPORT_BAND_5GHZ;
  1848. spec->num_channels = ARRAY_SIZE(rf_vals_5226);
  1849. spec->channels = rf_vals_5226;
  1850. } else if (rt2x00_rf(&rt2x00dev->chip, RF2527)) {
  1851. spec->num_channels = 14;
  1852. spec->channels = rf_vals_5225_2527;
  1853. } else if (rt2x00_rf(&rt2x00dev->chip, RF5225)) {
  1854. spec->supported_bands |= SUPPORT_BAND_5GHZ;
  1855. spec->num_channels = ARRAY_SIZE(rf_vals_5225_2527);
  1856. spec->channels = rf_vals_5225_2527;
  1857. }
  1858. /*
  1859. * Create channel information array
  1860. */
  1861. info = kzalloc(spec->num_channels * sizeof(*info), GFP_KERNEL);
  1862. if (!info)
  1863. return -ENOMEM;
  1864. spec->channels_info = info;
  1865. tx_power = rt2x00_eeprom_addr(rt2x00dev, EEPROM_TXPOWER_G_START);
  1866. for (i = 0; i < 14; i++)
  1867. info[i].tx_power1 = TXPOWER_FROM_DEV(tx_power[i]);
  1868. if (spec->num_channels > 14) {
  1869. tx_power = rt2x00_eeprom_addr(rt2x00dev, EEPROM_TXPOWER_A_START);
  1870. for (i = 14; i < spec->num_channels; i++)
  1871. info[i].tx_power1 = TXPOWER_FROM_DEV(tx_power[i]);
  1872. }
  1873. return 0;
  1874. }
  1875. static int rt73usb_probe_hw(struct rt2x00_dev *rt2x00dev)
  1876. {
  1877. int retval;
  1878. /*
  1879. * Allocate eeprom data.
  1880. */
  1881. retval = rt73usb_validate_eeprom(rt2x00dev);
  1882. if (retval)
  1883. return retval;
  1884. retval = rt73usb_init_eeprom(rt2x00dev);
  1885. if (retval)
  1886. return retval;
  1887. /*
  1888. * Initialize hw specifications.
  1889. */
  1890. retval = rt73usb_probe_hw_mode(rt2x00dev);
  1891. if (retval)
  1892. return retval;
  1893. /*
  1894. * This device requires firmware.
  1895. */
  1896. __set_bit(DRIVER_REQUIRE_FIRMWARE, &rt2x00dev->flags);
  1897. __set_bit(DRIVER_REQUIRE_SCHEDULED, &rt2x00dev->flags);
  1898. if (!modparam_nohwcrypt)
  1899. __set_bit(CONFIG_SUPPORT_HW_CRYPTO, &rt2x00dev->flags);
  1900. /*
  1901. * Set the rssi offset.
  1902. */
  1903. rt2x00dev->rssi_offset = DEFAULT_RSSI_OFFSET;
  1904. return 0;
  1905. }
  1906. /*
  1907. * IEEE80211 stack callback functions.
  1908. */
  1909. static int rt73usb_conf_tx(struct ieee80211_hw *hw, u16 queue_idx,
  1910. const struct ieee80211_tx_queue_params *params)
  1911. {
  1912. struct rt2x00_dev *rt2x00dev = hw->priv;
  1913. struct data_queue *queue;
  1914. struct rt2x00_field32 field;
  1915. int retval;
  1916. u32 reg;
  1917. /*
  1918. * First pass the configuration through rt2x00lib, that will
  1919. * update the queue settings and validate the input. After that
  1920. * we are free to update the registers based on the value
  1921. * in the queue parameter.
  1922. */
  1923. retval = rt2x00mac_conf_tx(hw, queue_idx, params);
  1924. if (retval)
  1925. return retval;
  1926. queue = rt2x00queue_get_queue(rt2x00dev, queue_idx);
  1927. /* Update WMM TXOP register */
  1928. if (queue_idx < 2) {
  1929. field.bit_offset = queue_idx * 16;
  1930. field.bit_mask = 0xffff << field.bit_offset;
  1931. rt73usb_register_read(rt2x00dev, AC_TXOP_CSR0, &reg);
  1932. rt2x00_set_field32(&reg, field, queue->txop);
  1933. rt73usb_register_write(rt2x00dev, AC_TXOP_CSR0, reg);
  1934. } else if (queue_idx < 4) {
  1935. field.bit_offset = (queue_idx - 2) * 16;
  1936. field.bit_mask = 0xffff << field.bit_offset;
  1937. rt73usb_register_read(rt2x00dev, AC_TXOP_CSR1, &reg);
  1938. rt2x00_set_field32(&reg, field, queue->txop);
  1939. rt73usb_register_write(rt2x00dev, AC_TXOP_CSR1, reg);
  1940. }
  1941. /* Update WMM registers */
  1942. field.bit_offset = queue_idx * 4;
  1943. field.bit_mask = 0xf << field.bit_offset;
  1944. rt73usb_register_read(rt2x00dev, AIFSN_CSR, &reg);
  1945. rt2x00_set_field32(&reg, field, queue->aifs);
  1946. rt73usb_register_write(rt2x00dev, AIFSN_CSR, reg);
  1947. rt73usb_register_read(rt2x00dev, CWMIN_CSR, &reg);
  1948. rt2x00_set_field32(&reg, field, queue->cw_min);
  1949. rt73usb_register_write(rt2x00dev, CWMIN_CSR, reg);
  1950. rt73usb_register_read(rt2x00dev, CWMAX_CSR, &reg);
  1951. rt2x00_set_field32(&reg, field, queue->cw_max);
  1952. rt73usb_register_write(rt2x00dev, CWMAX_CSR, reg);
  1953. return 0;
  1954. }
  1955. #if 0
  1956. /*
  1957. * Mac80211 demands get_tsf must be atomic.
  1958. * This is not possible for rt73usb since all register access
  1959. * functions require sleeping. Untill mac80211 no longer needs
  1960. * get_tsf to be atomic, this function should be disabled.
  1961. */
  1962. static u64 rt73usb_get_tsf(struct ieee80211_hw *hw)
  1963. {
  1964. struct rt2x00_dev *rt2x00dev = hw->priv;
  1965. u64 tsf;
  1966. u32 reg;
  1967. rt73usb_register_read(rt2x00dev, TXRX_CSR13, &reg);
  1968. tsf = (u64) rt2x00_get_field32(reg, TXRX_CSR13_HIGH_TSFTIMER) << 32;
  1969. rt73usb_register_read(rt2x00dev, TXRX_CSR12, &reg);
  1970. tsf |= rt2x00_get_field32(reg, TXRX_CSR12_LOW_TSFTIMER);
  1971. return tsf;
  1972. }
  1973. #else
  1974. #define rt73usb_get_tsf NULL
  1975. #endif
  1976. static const struct ieee80211_ops rt73usb_mac80211_ops = {
  1977. .tx = rt2x00mac_tx,
  1978. .start = rt2x00mac_start,
  1979. .stop = rt2x00mac_stop,
  1980. .add_interface = rt2x00mac_add_interface,
  1981. .remove_interface = rt2x00mac_remove_interface,
  1982. .config = rt2x00mac_config,
  1983. .config_interface = rt2x00mac_config_interface,
  1984. .configure_filter = rt2x00mac_configure_filter,
  1985. .set_key = rt2x00mac_set_key,
  1986. .get_stats = rt2x00mac_get_stats,
  1987. .bss_info_changed = rt2x00mac_bss_info_changed,
  1988. .conf_tx = rt73usb_conf_tx,
  1989. .get_tx_stats = rt2x00mac_get_tx_stats,
  1990. .get_tsf = rt73usb_get_tsf,
  1991. };
  1992. static const struct rt2x00lib_ops rt73usb_rt2x00_ops = {
  1993. .probe_hw = rt73usb_probe_hw,
  1994. .get_firmware_name = rt73usb_get_firmware_name,
  1995. .get_firmware_crc = rt73usb_get_firmware_crc,
  1996. .load_firmware = rt73usb_load_firmware,
  1997. .initialize = rt2x00usb_initialize,
  1998. .uninitialize = rt2x00usb_uninitialize,
  1999. .clear_entry = rt2x00usb_clear_entry,
  2000. .set_device_state = rt73usb_set_device_state,
  2001. .link_stats = rt73usb_link_stats,
  2002. .reset_tuner = rt73usb_reset_tuner,
  2003. .link_tuner = rt73usb_link_tuner,
  2004. .write_tx_desc = rt73usb_write_tx_desc,
  2005. .write_tx_data = rt2x00usb_write_tx_data,
  2006. .write_beacon = rt73usb_write_beacon,
  2007. .get_tx_data_len = rt73usb_get_tx_data_len,
  2008. .kick_tx_queue = rt73usb_kick_tx_queue,
  2009. .fill_rxdone = rt73usb_fill_rxdone,
  2010. .config_shared_key = rt73usb_config_shared_key,
  2011. .config_pairwise_key = rt73usb_config_pairwise_key,
  2012. .config_filter = rt73usb_config_filter,
  2013. .config_intf = rt73usb_config_intf,
  2014. .config_erp = rt73usb_config_erp,
  2015. .config_ant = rt73usb_config_ant,
  2016. .config = rt73usb_config,
  2017. };
  2018. static const struct data_queue_desc rt73usb_queue_rx = {
  2019. .entry_num = RX_ENTRIES,
  2020. .data_size = DATA_FRAME_SIZE,
  2021. .desc_size = RXD_DESC_SIZE,
  2022. .priv_size = sizeof(struct queue_entry_priv_usb),
  2023. };
  2024. static const struct data_queue_desc rt73usb_queue_tx = {
  2025. .entry_num = TX_ENTRIES,
  2026. .data_size = DATA_FRAME_SIZE,
  2027. .desc_size = TXD_DESC_SIZE,
  2028. .priv_size = sizeof(struct queue_entry_priv_usb),
  2029. };
  2030. static const struct data_queue_desc rt73usb_queue_bcn = {
  2031. .entry_num = 4 * BEACON_ENTRIES,
  2032. .data_size = MGMT_FRAME_SIZE,
  2033. .desc_size = TXINFO_SIZE,
  2034. .priv_size = sizeof(struct queue_entry_priv_usb),
  2035. };
  2036. static const struct rt2x00_ops rt73usb_ops = {
  2037. .name = KBUILD_MODNAME,
  2038. .max_sta_intf = 1,
  2039. .max_ap_intf = 4,
  2040. .eeprom_size = EEPROM_SIZE,
  2041. .rf_size = RF_SIZE,
  2042. .tx_queues = NUM_TX_QUEUES,
  2043. .rx = &rt73usb_queue_rx,
  2044. .tx = &rt73usb_queue_tx,
  2045. .bcn = &rt73usb_queue_bcn,
  2046. .lib = &rt73usb_rt2x00_ops,
  2047. .hw = &rt73usb_mac80211_ops,
  2048. #ifdef CONFIG_RT2X00_LIB_DEBUGFS
  2049. .debugfs = &rt73usb_rt2x00debug,
  2050. #endif /* CONFIG_RT2X00_LIB_DEBUGFS */
  2051. };
  2052. /*
  2053. * rt73usb module information.
  2054. */
  2055. static struct usb_device_id rt73usb_device_table[] = {
  2056. /* AboCom */
  2057. { USB_DEVICE(0x07b8, 0xb21d), USB_DEVICE_DATA(&rt73usb_ops) },
  2058. /* Askey */
  2059. { USB_DEVICE(0x1690, 0x0722), USB_DEVICE_DATA(&rt73usb_ops) },
  2060. /* ASUS */
  2061. { USB_DEVICE(0x0b05, 0x1723), USB_DEVICE_DATA(&rt73usb_ops) },
  2062. { USB_DEVICE(0x0b05, 0x1724), USB_DEVICE_DATA(&rt73usb_ops) },
  2063. /* Belkin */
  2064. { USB_DEVICE(0x050d, 0x7050), USB_DEVICE_DATA(&rt73usb_ops) },
  2065. { USB_DEVICE(0x050d, 0x705a), USB_DEVICE_DATA(&rt73usb_ops) },
  2066. { USB_DEVICE(0x050d, 0x905b), USB_DEVICE_DATA(&rt73usb_ops) },
  2067. { USB_DEVICE(0x050d, 0x905c), USB_DEVICE_DATA(&rt73usb_ops) },
  2068. /* Billionton */
  2069. { USB_DEVICE(0x1631, 0xc019), USB_DEVICE_DATA(&rt73usb_ops) },
  2070. /* Buffalo */
  2071. { USB_DEVICE(0x0411, 0x00f4), USB_DEVICE_DATA(&rt73usb_ops) },
  2072. /* CNet */
  2073. { USB_DEVICE(0x1371, 0x9022), USB_DEVICE_DATA(&rt73usb_ops) },
  2074. { USB_DEVICE(0x1371, 0x9032), USB_DEVICE_DATA(&rt73usb_ops) },
  2075. /* Conceptronic */
  2076. { USB_DEVICE(0x14b2, 0x3c22), USB_DEVICE_DATA(&rt73usb_ops) },
  2077. /* Corega */
  2078. { USB_DEVICE(0x07aa, 0x002e), USB_DEVICE_DATA(&rt73usb_ops) },
  2079. /* D-Link */
  2080. { USB_DEVICE(0x07d1, 0x3c03), USB_DEVICE_DATA(&rt73usb_ops) },
  2081. { USB_DEVICE(0x07d1, 0x3c04), USB_DEVICE_DATA(&rt73usb_ops) },
  2082. { USB_DEVICE(0x07d1, 0x3c06), USB_DEVICE_DATA(&rt73usb_ops) },
  2083. { USB_DEVICE(0x07d1, 0x3c07), USB_DEVICE_DATA(&rt73usb_ops) },
  2084. /* Gemtek */
  2085. { USB_DEVICE(0x15a9, 0x0004), USB_DEVICE_DATA(&rt73usb_ops) },
  2086. /* Gigabyte */
  2087. { USB_DEVICE(0x1044, 0x8008), USB_DEVICE_DATA(&rt73usb_ops) },
  2088. { USB_DEVICE(0x1044, 0x800a), USB_DEVICE_DATA(&rt73usb_ops) },
  2089. /* Huawei-3Com */
  2090. { USB_DEVICE(0x1472, 0x0009), USB_DEVICE_DATA(&rt73usb_ops) },
  2091. /* Hercules */
  2092. { USB_DEVICE(0x06f8, 0xe010), USB_DEVICE_DATA(&rt73usb_ops) },
  2093. { USB_DEVICE(0x06f8, 0xe020), USB_DEVICE_DATA(&rt73usb_ops) },
  2094. /* Linksys */
  2095. { USB_DEVICE(0x13b1, 0x0020), USB_DEVICE_DATA(&rt73usb_ops) },
  2096. { USB_DEVICE(0x13b1, 0x0023), USB_DEVICE_DATA(&rt73usb_ops) },
  2097. /* MSI */
  2098. { USB_DEVICE(0x0db0, 0x6877), USB_DEVICE_DATA(&rt73usb_ops) },
  2099. { USB_DEVICE(0x0db0, 0x6874), USB_DEVICE_DATA(&rt73usb_ops) },
  2100. { USB_DEVICE(0x0db0, 0xa861), USB_DEVICE_DATA(&rt73usb_ops) },
  2101. { USB_DEVICE(0x0db0, 0xa874), USB_DEVICE_DATA(&rt73usb_ops) },
  2102. /* Ralink */
  2103. { USB_DEVICE(0x148f, 0x2573), USB_DEVICE_DATA(&rt73usb_ops) },
  2104. { USB_DEVICE(0x148f, 0x2671), USB_DEVICE_DATA(&rt73usb_ops) },
  2105. /* Qcom */
  2106. { USB_DEVICE(0x18e8, 0x6196), USB_DEVICE_DATA(&rt73usb_ops) },
  2107. { USB_DEVICE(0x18e8, 0x6229), USB_DEVICE_DATA(&rt73usb_ops) },
  2108. { USB_DEVICE(0x18e8, 0x6238), USB_DEVICE_DATA(&rt73usb_ops) },
  2109. /* Senao */
  2110. { USB_DEVICE(0x1740, 0x7100), USB_DEVICE_DATA(&rt73usb_ops) },
  2111. /* Sitecom */
  2112. { USB_DEVICE(0x0df6, 0x9712), USB_DEVICE_DATA(&rt73usb_ops) },
  2113. { USB_DEVICE(0x0df6, 0x90ac), USB_DEVICE_DATA(&rt73usb_ops) },
  2114. /* Surecom */
  2115. { USB_DEVICE(0x0769, 0x31f3), USB_DEVICE_DATA(&rt73usb_ops) },
  2116. /* Planex */
  2117. { USB_DEVICE(0x2019, 0xab01), USB_DEVICE_DATA(&rt73usb_ops) },
  2118. { USB_DEVICE(0x2019, 0xab50), USB_DEVICE_DATA(&rt73usb_ops) },
  2119. { 0, }
  2120. };
  2121. MODULE_AUTHOR(DRV_PROJECT);
  2122. MODULE_VERSION(DRV_VERSION);
  2123. MODULE_DESCRIPTION("Ralink RT73 USB Wireless LAN driver.");
  2124. MODULE_SUPPORTED_DEVICE("Ralink RT2571W & RT2671 USB chipset based cards");
  2125. MODULE_DEVICE_TABLE(usb, rt73usb_device_table);
  2126. MODULE_FIRMWARE(FIRMWARE_RT2571);
  2127. MODULE_LICENSE("GPL");
  2128. static struct usb_driver rt73usb_driver = {
  2129. .name = KBUILD_MODNAME,
  2130. .id_table = rt73usb_device_table,
  2131. .probe = rt2x00usb_probe,
  2132. .disconnect = rt2x00usb_disconnect,
  2133. .suspend = rt2x00usb_suspend,
  2134. .resume = rt2x00usb_resume,
  2135. };
  2136. static int __init rt73usb_init(void)
  2137. {
  2138. return usb_register(&rt73usb_driver);
  2139. }
  2140. static void __exit rt73usb_exit(void)
  2141. {
  2142. usb_deregister(&rt73usb_driver);
  2143. }
  2144. module_init(rt73usb_init);
  2145. module_exit(rt73usb_exit);