p54common.c 62 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308
  1. /*
  2. * Common code for mac80211 Prism54 drivers
  3. *
  4. * Copyright (c) 2006, Michael Wu <flamingice@sourmilk.net>
  5. * Copyright (c) 2007, Christian Lamparter <chunkeey@web.de>
  6. * Copyright 2008, Johannes Berg <johannes@sipsolutions.net>
  7. *
  8. * Based on:
  9. * - the islsm (softmac prism54) driver, which is:
  10. * Copyright 2004-2006 Jean-Baptiste Note <jbnote@gmail.com>, et al.
  11. * - stlc45xx driver
  12. * Copyright (C) 2008 Nokia Corporation and/or its subsidiary(-ies).
  13. *
  14. * This program is free software; you can redistribute it and/or modify
  15. * it under the terms of the GNU General Public License version 2 as
  16. * published by the Free Software Foundation.
  17. */
  18. #include <linux/init.h>
  19. #include <linux/firmware.h>
  20. #include <linux/etherdevice.h>
  21. #include <net/mac80211.h>
  22. #include "p54.h"
  23. #include "p54common.h"
  24. static int modparam_nohwcrypt;
  25. module_param_named(nohwcrypt, modparam_nohwcrypt, bool, S_IRUGO);
  26. MODULE_PARM_DESC(nohwcrypt, "Disable hardware encryption.");
  27. MODULE_AUTHOR("Michael Wu <flamingice@sourmilk.net>");
  28. MODULE_DESCRIPTION("Softmac Prism54 common code");
  29. MODULE_LICENSE("GPL");
  30. MODULE_ALIAS("prism54common");
  31. static struct ieee80211_rate p54_bgrates[] = {
  32. { .bitrate = 10, .hw_value = 0, .flags = IEEE80211_RATE_SHORT_PREAMBLE },
  33. { .bitrate = 20, .hw_value = 1, .flags = IEEE80211_RATE_SHORT_PREAMBLE },
  34. { .bitrate = 55, .hw_value = 2, .flags = IEEE80211_RATE_SHORT_PREAMBLE },
  35. { .bitrate = 110, .hw_value = 3, .flags = IEEE80211_RATE_SHORT_PREAMBLE },
  36. { .bitrate = 60, .hw_value = 4, },
  37. { .bitrate = 90, .hw_value = 5, },
  38. { .bitrate = 120, .hw_value = 6, },
  39. { .bitrate = 180, .hw_value = 7, },
  40. { .bitrate = 240, .hw_value = 8, },
  41. { .bitrate = 360, .hw_value = 9, },
  42. { .bitrate = 480, .hw_value = 10, },
  43. { .bitrate = 540, .hw_value = 11, },
  44. };
  45. static struct ieee80211_channel p54_bgchannels[] = {
  46. { .center_freq = 2412, .hw_value = 1, },
  47. { .center_freq = 2417, .hw_value = 2, },
  48. { .center_freq = 2422, .hw_value = 3, },
  49. { .center_freq = 2427, .hw_value = 4, },
  50. { .center_freq = 2432, .hw_value = 5, },
  51. { .center_freq = 2437, .hw_value = 6, },
  52. { .center_freq = 2442, .hw_value = 7, },
  53. { .center_freq = 2447, .hw_value = 8, },
  54. { .center_freq = 2452, .hw_value = 9, },
  55. { .center_freq = 2457, .hw_value = 10, },
  56. { .center_freq = 2462, .hw_value = 11, },
  57. { .center_freq = 2467, .hw_value = 12, },
  58. { .center_freq = 2472, .hw_value = 13, },
  59. { .center_freq = 2484, .hw_value = 14, },
  60. };
  61. static struct ieee80211_supported_band band_2GHz = {
  62. .channels = p54_bgchannels,
  63. .n_channels = ARRAY_SIZE(p54_bgchannels),
  64. .bitrates = p54_bgrates,
  65. .n_bitrates = ARRAY_SIZE(p54_bgrates),
  66. };
  67. static struct ieee80211_rate p54_arates[] = {
  68. { .bitrate = 60, .hw_value = 4, },
  69. { .bitrate = 90, .hw_value = 5, },
  70. { .bitrate = 120, .hw_value = 6, },
  71. { .bitrate = 180, .hw_value = 7, },
  72. { .bitrate = 240, .hw_value = 8, },
  73. { .bitrate = 360, .hw_value = 9, },
  74. { .bitrate = 480, .hw_value = 10, },
  75. { .bitrate = 540, .hw_value = 11, },
  76. };
  77. static struct ieee80211_channel p54_achannels[] = {
  78. { .center_freq = 4920 },
  79. { .center_freq = 4940 },
  80. { .center_freq = 4960 },
  81. { .center_freq = 4980 },
  82. { .center_freq = 5040 },
  83. { .center_freq = 5060 },
  84. { .center_freq = 5080 },
  85. { .center_freq = 5170 },
  86. { .center_freq = 5180 },
  87. { .center_freq = 5190 },
  88. { .center_freq = 5200 },
  89. { .center_freq = 5210 },
  90. { .center_freq = 5220 },
  91. { .center_freq = 5230 },
  92. { .center_freq = 5240 },
  93. { .center_freq = 5260 },
  94. { .center_freq = 5280 },
  95. { .center_freq = 5300 },
  96. { .center_freq = 5320 },
  97. { .center_freq = 5500 },
  98. { .center_freq = 5520 },
  99. { .center_freq = 5540 },
  100. { .center_freq = 5560 },
  101. { .center_freq = 5580 },
  102. { .center_freq = 5600 },
  103. { .center_freq = 5620 },
  104. { .center_freq = 5640 },
  105. { .center_freq = 5660 },
  106. { .center_freq = 5680 },
  107. { .center_freq = 5700 },
  108. { .center_freq = 5745 },
  109. { .center_freq = 5765 },
  110. { .center_freq = 5785 },
  111. { .center_freq = 5805 },
  112. { .center_freq = 5825 },
  113. };
  114. static struct ieee80211_supported_band band_5GHz = {
  115. .channels = p54_achannels,
  116. .n_channels = ARRAY_SIZE(p54_achannels),
  117. .bitrates = p54_arates,
  118. .n_bitrates = ARRAY_SIZE(p54_arates),
  119. };
  120. int p54_parse_firmware(struct ieee80211_hw *dev, const struct firmware *fw)
  121. {
  122. struct p54_common *priv = dev->priv;
  123. struct bootrec_exp_if *exp_if;
  124. struct bootrec *bootrec;
  125. u32 *data = (u32 *)fw->data;
  126. u32 *end_data = (u32 *)fw->data + (fw->size >> 2);
  127. u8 *fw_version = NULL;
  128. size_t len;
  129. int i;
  130. int maxlen;
  131. if (priv->rx_start)
  132. return 0;
  133. while (data < end_data && *data)
  134. data++;
  135. while (data < end_data && !*data)
  136. data++;
  137. bootrec = (struct bootrec *) data;
  138. while (bootrec->data <= end_data &&
  139. (bootrec->data + (len = le32_to_cpu(bootrec->len))) <= end_data) {
  140. u32 code = le32_to_cpu(bootrec->code);
  141. switch (code) {
  142. case BR_CODE_COMPONENT_ID:
  143. priv->fw_interface = be32_to_cpup((__be32 *)
  144. bootrec->data);
  145. switch (priv->fw_interface) {
  146. case FW_LM86:
  147. case FW_LM20:
  148. case FW_LM87: {
  149. char *iftype = (char *)bootrec->data;
  150. printk(KERN_INFO "%s: p54 detected a LM%c%c "
  151. "firmware\n",
  152. wiphy_name(dev->wiphy),
  153. iftype[2], iftype[3]);
  154. break;
  155. }
  156. case FW_FMAC:
  157. default:
  158. printk(KERN_ERR "%s: unsupported firmware\n",
  159. wiphy_name(dev->wiphy));
  160. return -ENODEV;
  161. }
  162. break;
  163. case BR_CODE_COMPONENT_VERSION:
  164. /* 24 bytes should be enough for all firmwares */
  165. if (strnlen((unsigned char*)bootrec->data, 24) < 24)
  166. fw_version = (unsigned char*)bootrec->data;
  167. break;
  168. case BR_CODE_DESCR: {
  169. struct bootrec_desc *desc =
  170. (struct bootrec_desc *)bootrec->data;
  171. priv->rx_start = le32_to_cpu(desc->rx_start);
  172. /* FIXME add sanity checking */
  173. priv->rx_end = le32_to_cpu(desc->rx_end) - 0x3500;
  174. priv->headroom = desc->headroom;
  175. priv->tailroom = desc->tailroom;
  176. priv->privacy_caps = desc->privacy_caps;
  177. priv->rx_keycache_size = desc->rx_keycache_size;
  178. if (le32_to_cpu(bootrec->len) == 11)
  179. priv->rx_mtu = le16_to_cpu(desc->rx_mtu);
  180. else
  181. priv->rx_mtu = (size_t)
  182. 0x620 - priv->tx_hdr_len;
  183. maxlen = priv->tx_hdr_len + /* USB devices */
  184. sizeof(struct p54_rx_data) +
  185. 4 + /* rx alignment */
  186. IEEE80211_MAX_FRAG_THRESHOLD;
  187. if (priv->rx_mtu > maxlen && PAGE_SIZE == 4096) {
  188. printk(KERN_INFO "p54: rx_mtu reduced from %d "
  189. "to %d\n", priv->rx_mtu,
  190. maxlen);
  191. priv->rx_mtu = maxlen;
  192. }
  193. break;
  194. }
  195. case BR_CODE_EXPOSED_IF:
  196. exp_if = (struct bootrec_exp_if *) bootrec->data;
  197. for (i = 0; i < (len * sizeof(*exp_if) / 4); i++)
  198. if (exp_if[i].if_id == cpu_to_le16(0x1a))
  199. priv->fw_var = le16_to_cpu(exp_if[i].variant);
  200. break;
  201. case BR_CODE_DEPENDENT_IF:
  202. break;
  203. case BR_CODE_END_OF_BRA:
  204. case LEGACY_BR_CODE_END_OF_BRA:
  205. end_data = NULL;
  206. break;
  207. default:
  208. break;
  209. }
  210. bootrec = (struct bootrec *)&bootrec->data[len];
  211. }
  212. if (fw_version)
  213. printk(KERN_INFO "%s: FW rev %s - Softmac protocol %x.%x\n",
  214. wiphy_name(dev->wiphy), fw_version,
  215. priv->fw_var >> 8, priv->fw_var & 0xff);
  216. if (priv->fw_var < 0x500)
  217. printk(KERN_INFO "%s: you are using an obsolete firmware. "
  218. "visit http://wireless.kernel.org/en/users/Drivers/p54 "
  219. "and grab one for \"kernel >= 2.6.28\"!\n",
  220. wiphy_name(dev->wiphy));
  221. if (priv->fw_var >= 0x300) {
  222. /* Firmware supports QoS, use it! */
  223. priv->tx_stats[P54_QUEUE_AC_VO].limit = 3;
  224. priv->tx_stats[P54_QUEUE_AC_VI].limit = 4;
  225. priv->tx_stats[P54_QUEUE_AC_BE].limit = 3;
  226. priv->tx_stats[P54_QUEUE_AC_BK].limit = 2;
  227. dev->queues = P54_QUEUE_AC_NUM;
  228. }
  229. if (!modparam_nohwcrypt)
  230. printk(KERN_INFO "%s: cryptographic accelerator "
  231. "WEP:%s, TKIP:%s, CCMP:%s\n",
  232. wiphy_name(dev->wiphy),
  233. (priv->privacy_caps & BR_DESC_PRIV_CAP_WEP) ? "YES" :
  234. "no", (priv->privacy_caps & (BR_DESC_PRIV_CAP_TKIP |
  235. BR_DESC_PRIV_CAP_MICHAEL)) ? "YES" : "no",
  236. (priv->privacy_caps & BR_DESC_PRIV_CAP_AESCCMP) ?
  237. "YES" : "no");
  238. return 0;
  239. }
  240. EXPORT_SYMBOL_GPL(p54_parse_firmware);
  241. static int p54_convert_rev0(struct ieee80211_hw *dev,
  242. struct pda_pa_curve_data *curve_data)
  243. {
  244. struct p54_common *priv = dev->priv;
  245. struct p54_pa_curve_data_sample *dst;
  246. struct pda_pa_curve_data_sample_rev0 *src;
  247. size_t cd_len = sizeof(*curve_data) +
  248. (curve_data->points_per_channel*sizeof(*dst) + 2) *
  249. curve_data->channels;
  250. unsigned int i, j;
  251. void *source, *target;
  252. priv->curve_data = kmalloc(cd_len, GFP_KERNEL);
  253. if (!priv->curve_data)
  254. return -ENOMEM;
  255. memcpy(priv->curve_data, curve_data, sizeof(*curve_data));
  256. source = curve_data->data;
  257. target = priv->curve_data->data;
  258. for (i = 0; i < curve_data->channels; i++) {
  259. __le16 *freq = source;
  260. source += sizeof(__le16);
  261. *((__le16 *)target) = *freq;
  262. target += sizeof(__le16);
  263. for (j = 0; j < curve_data->points_per_channel; j++) {
  264. dst = target;
  265. src = source;
  266. dst->rf_power = src->rf_power;
  267. dst->pa_detector = src->pa_detector;
  268. dst->data_64qam = src->pcv;
  269. /* "invent" the points for the other modulations */
  270. #define SUB(x,y) (u8)((x) - (y)) > (x) ? 0 : (x) - (y)
  271. dst->data_16qam = SUB(src->pcv, 12);
  272. dst->data_qpsk = SUB(dst->data_16qam, 12);
  273. dst->data_bpsk = SUB(dst->data_qpsk, 12);
  274. dst->data_barker = SUB(dst->data_bpsk, 14);
  275. #undef SUB
  276. target += sizeof(*dst);
  277. source += sizeof(*src);
  278. }
  279. }
  280. return 0;
  281. }
  282. static int p54_convert_rev1(struct ieee80211_hw *dev,
  283. struct pda_pa_curve_data *curve_data)
  284. {
  285. struct p54_common *priv = dev->priv;
  286. struct p54_pa_curve_data_sample *dst;
  287. struct pda_pa_curve_data_sample_rev1 *src;
  288. size_t cd_len = sizeof(*curve_data) +
  289. (curve_data->points_per_channel*sizeof(*dst) + 2) *
  290. curve_data->channels;
  291. unsigned int i, j;
  292. void *source, *target;
  293. priv->curve_data = kmalloc(cd_len, GFP_KERNEL);
  294. if (!priv->curve_data)
  295. return -ENOMEM;
  296. memcpy(priv->curve_data, curve_data, sizeof(*curve_data));
  297. source = curve_data->data;
  298. target = priv->curve_data->data;
  299. for (i = 0; i < curve_data->channels; i++) {
  300. __le16 *freq = source;
  301. source += sizeof(__le16);
  302. *((__le16 *)target) = *freq;
  303. target += sizeof(__le16);
  304. for (j = 0; j < curve_data->points_per_channel; j++) {
  305. memcpy(target, source, sizeof(*src));
  306. target += sizeof(*dst);
  307. source += sizeof(*src);
  308. }
  309. source++;
  310. }
  311. return 0;
  312. }
  313. static const char *p54_rf_chips[] = { "NULL", "Duette3", "Duette2",
  314. "Frisbee", "Xbow", "Longbow", "NULL", "NULL" };
  315. static int p54_init_xbow_synth(struct ieee80211_hw *dev);
  316. static void p54_parse_rssical(struct ieee80211_hw *dev, void *data, int len,
  317. u16 type)
  318. {
  319. struct p54_common *priv = dev->priv;
  320. int offset = (type == PDR_RSSI_LINEAR_APPROXIMATION_EXTENDED) ? 2 : 0;
  321. int entry_size = sizeof(struct pda_rssi_cal_entry) + offset;
  322. int num_entries = (type == PDR_RSSI_LINEAR_APPROXIMATION) ? 1 : 2;
  323. int i;
  324. if (len != (entry_size * num_entries)) {
  325. printk(KERN_ERR "%s: unknown rssi calibration data packing "
  326. " type:(%x) len:%d.\n",
  327. wiphy_name(dev->wiphy), type, len);
  328. print_hex_dump_bytes("rssical:", DUMP_PREFIX_NONE,
  329. data, len);
  330. printk(KERN_ERR "%s: please report this issue.\n",
  331. wiphy_name(dev->wiphy));
  332. return;
  333. }
  334. for (i = 0; i < num_entries; i++) {
  335. struct pda_rssi_cal_entry *cal = data +
  336. (offset + i * entry_size);
  337. priv->rssical_db[i].mul = (s16) le16_to_cpu(cal->mul);
  338. priv->rssical_db[i].add = (s16) le16_to_cpu(cal->add);
  339. }
  340. }
  341. static void p54_parse_default_country(struct ieee80211_hw *dev,
  342. void *data, int len)
  343. {
  344. struct pda_country *country;
  345. if (len != sizeof(*country)) {
  346. printk(KERN_ERR "%s: found possible invalid default country "
  347. "eeprom entry. (entry size: %d)\n",
  348. wiphy_name(dev->wiphy), len);
  349. print_hex_dump_bytes("country:", DUMP_PREFIX_NONE,
  350. data, len);
  351. printk(KERN_ERR "%s: please report this issue.\n",
  352. wiphy_name(dev->wiphy));
  353. return;
  354. }
  355. country = (struct pda_country *) data;
  356. if (country->flags == PDR_COUNTRY_CERT_CODE_PSEUDO)
  357. regulatory_hint(dev->wiphy, country->alpha2);
  358. else {
  359. /* TODO:
  360. * write a shared/common function that converts
  361. * "Regulatory domain codes" (802.11-2007 14.8.2.2)
  362. * into ISO/IEC 3166-1 alpha2 for regulatory_hint.
  363. */
  364. }
  365. }
  366. static int p54_parse_eeprom(struct ieee80211_hw *dev, void *eeprom, int len)
  367. {
  368. struct p54_common *priv = dev->priv;
  369. struct eeprom_pda_wrap *wrap = NULL;
  370. struct pda_entry *entry;
  371. unsigned int data_len, entry_len;
  372. void *tmp;
  373. int err;
  374. u8 *end = (u8 *)eeprom + len;
  375. u16 synth = 0;
  376. wrap = (struct eeprom_pda_wrap *) eeprom;
  377. entry = (void *)wrap->data + le16_to_cpu(wrap->len);
  378. /* verify that at least the entry length/code fits */
  379. while ((u8 *)entry <= end - sizeof(*entry)) {
  380. entry_len = le16_to_cpu(entry->len);
  381. data_len = ((entry_len - 1) << 1);
  382. /* abort if entry exceeds whole structure */
  383. if ((u8 *)entry + sizeof(*entry) + data_len > end)
  384. break;
  385. switch (le16_to_cpu(entry->code)) {
  386. case PDR_MAC_ADDRESS:
  387. SET_IEEE80211_PERM_ADDR(dev, entry->data);
  388. break;
  389. case PDR_PRISM_PA_CAL_OUTPUT_POWER_LIMITS:
  390. if (data_len < 2) {
  391. err = -EINVAL;
  392. goto err;
  393. }
  394. if (2 + entry->data[1]*sizeof(*priv->output_limit) > data_len) {
  395. err = -EINVAL;
  396. goto err;
  397. }
  398. priv->output_limit = kmalloc(entry->data[1] *
  399. sizeof(*priv->output_limit), GFP_KERNEL);
  400. if (!priv->output_limit) {
  401. err = -ENOMEM;
  402. goto err;
  403. }
  404. memcpy(priv->output_limit, &entry->data[2],
  405. entry->data[1]*sizeof(*priv->output_limit));
  406. priv->output_limit_len = entry->data[1];
  407. break;
  408. case PDR_PRISM_PA_CAL_CURVE_DATA: {
  409. struct pda_pa_curve_data *curve_data =
  410. (struct pda_pa_curve_data *)entry->data;
  411. if (data_len < sizeof(*curve_data)) {
  412. err = -EINVAL;
  413. goto err;
  414. }
  415. switch (curve_data->cal_method_rev) {
  416. case 0:
  417. err = p54_convert_rev0(dev, curve_data);
  418. break;
  419. case 1:
  420. err = p54_convert_rev1(dev, curve_data);
  421. break;
  422. default:
  423. printk(KERN_ERR "%s: unknown curve data "
  424. "revision %d\n",
  425. wiphy_name(dev->wiphy),
  426. curve_data->cal_method_rev);
  427. err = -ENODEV;
  428. break;
  429. }
  430. if (err)
  431. goto err;
  432. }
  433. break;
  434. case PDR_PRISM_ZIF_TX_IQ_CALIBRATION:
  435. priv->iq_autocal = kmalloc(data_len, GFP_KERNEL);
  436. if (!priv->iq_autocal) {
  437. err = -ENOMEM;
  438. goto err;
  439. }
  440. memcpy(priv->iq_autocal, entry->data, data_len);
  441. priv->iq_autocal_len = data_len / sizeof(struct pda_iq_autocal_entry);
  442. break;
  443. case PDR_DEFAULT_COUNTRY:
  444. p54_parse_default_country(dev, entry->data, data_len);
  445. break;
  446. case PDR_INTERFACE_LIST:
  447. tmp = entry->data;
  448. while ((u8 *)tmp < entry->data + data_len) {
  449. struct bootrec_exp_if *exp_if = tmp;
  450. if (le16_to_cpu(exp_if->if_id) == 0xf)
  451. synth = le16_to_cpu(exp_if->variant);
  452. tmp += sizeof(struct bootrec_exp_if);
  453. }
  454. break;
  455. case PDR_HARDWARE_PLATFORM_COMPONENT_ID:
  456. priv->version = *(u8 *)(entry->data + 1);
  457. break;
  458. case PDR_RSSI_LINEAR_APPROXIMATION:
  459. case PDR_RSSI_LINEAR_APPROXIMATION_DUAL_BAND:
  460. case PDR_RSSI_LINEAR_APPROXIMATION_EXTENDED:
  461. p54_parse_rssical(dev, entry->data, data_len,
  462. le16_to_cpu(entry->code));
  463. break;
  464. case PDR_END:
  465. /* make it overrun */
  466. entry_len = len;
  467. break;
  468. case PDR_MANUFACTURING_PART_NUMBER:
  469. case PDR_PDA_VERSION:
  470. case PDR_NIC_SERIAL_NUMBER:
  471. case PDR_REGULATORY_DOMAIN_LIST:
  472. case PDR_TEMPERATURE_TYPE:
  473. case PDR_PRISM_PCI_IDENTIFIER:
  474. case PDR_COUNTRY_INFORMATION:
  475. case PDR_OEM_NAME:
  476. case PDR_PRODUCT_NAME:
  477. case PDR_UTF8_OEM_NAME:
  478. case PDR_UTF8_PRODUCT_NAME:
  479. case PDR_COUNTRY_LIST:
  480. case PDR_ANTENNA_GAIN:
  481. case PDR_PRISM_INDIGO_PA_CALIBRATION_DATA:
  482. case PDR_REGULATORY_POWER_LIMITS:
  483. case PDR_RADIATED_TRANSMISSION_CORRECTION:
  484. case PDR_PRISM_TX_IQ_CALIBRATION:
  485. case PDR_BASEBAND_REGISTERS:
  486. case PDR_PER_CHANNEL_BASEBAND_REGISTERS:
  487. break;
  488. default:
  489. printk(KERN_INFO "%s: unknown eeprom code : 0x%x\n",
  490. wiphy_name(dev->wiphy),
  491. le16_to_cpu(entry->code));
  492. break;
  493. }
  494. entry = (void *)entry + (entry_len + 1)*2;
  495. }
  496. if (!synth || !priv->iq_autocal || !priv->output_limit ||
  497. !priv->curve_data) {
  498. printk(KERN_ERR "%s: not all required entries found in eeprom!\n",
  499. wiphy_name(dev->wiphy));
  500. err = -EINVAL;
  501. goto err;
  502. }
  503. priv->rxhw = synth & PDR_SYNTH_FRONTEND_MASK;
  504. if (priv->rxhw == 4)
  505. p54_init_xbow_synth(dev);
  506. if (!(synth & PDR_SYNTH_24_GHZ_DISABLED))
  507. dev->wiphy->bands[IEEE80211_BAND_2GHZ] = &band_2GHz;
  508. if (!(synth & PDR_SYNTH_5_GHZ_DISABLED))
  509. dev->wiphy->bands[IEEE80211_BAND_5GHZ] = &band_5GHz;
  510. if ((synth & PDR_SYNTH_RX_DIV_MASK) == PDR_SYNTH_RX_DIV_SUPPORTED)
  511. priv->rx_diversity_mask = 3;
  512. if ((synth & PDR_SYNTH_TX_DIV_MASK) == PDR_SYNTH_TX_DIV_SUPPORTED)
  513. priv->tx_diversity_mask = 3;
  514. if (!is_valid_ether_addr(dev->wiphy->perm_addr)) {
  515. u8 perm_addr[ETH_ALEN];
  516. printk(KERN_WARNING "%s: Invalid hwaddr! Using randomly generated MAC addr\n",
  517. wiphy_name(dev->wiphy));
  518. random_ether_addr(perm_addr);
  519. SET_IEEE80211_PERM_ADDR(dev, perm_addr);
  520. }
  521. printk(KERN_INFO "%s: hwaddr %pM, MAC:isl38%02x RF:%s\n",
  522. wiphy_name(dev->wiphy),
  523. dev->wiphy->perm_addr,
  524. priv->version, p54_rf_chips[priv->rxhw]);
  525. return 0;
  526. err:
  527. if (priv->iq_autocal) {
  528. kfree(priv->iq_autocal);
  529. priv->iq_autocal = NULL;
  530. }
  531. if (priv->output_limit) {
  532. kfree(priv->output_limit);
  533. priv->output_limit = NULL;
  534. }
  535. if (priv->curve_data) {
  536. kfree(priv->curve_data);
  537. priv->curve_data = NULL;
  538. }
  539. printk(KERN_ERR "%s: eeprom parse failed!\n",
  540. wiphy_name(dev->wiphy));
  541. return err;
  542. }
  543. static int p54_rssi_to_dbm(struct ieee80211_hw *dev, int rssi)
  544. {
  545. struct p54_common *priv = dev->priv;
  546. int band = dev->conf.channel->band;
  547. return ((rssi * priv->rssical_db[band].mul) / 64 +
  548. priv->rssical_db[band].add) / 4;
  549. }
  550. static int p54_rx_data(struct ieee80211_hw *dev, struct sk_buff *skb)
  551. {
  552. struct p54_common *priv = dev->priv;
  553. struct p54_rx_data *hdr = (struct p54_rx_data *) skb->data;
  554. struct ieee80211_rx_status rx_status = {0};
  555. u16 freq = le16_to_cpu(hdr->freq);
  556. size_t header_len = sizeof(*hdr);
  557. u32 tsf32;
  558. u8 rate = hdr->rate & 0xf;
  559. /*
  560. * If the device is in a unspecified state we have to
  561. * ignore all data frames. Else we could end up with a
  562. * nasty crash.
  563. */
  564. if (unlikely(priv->mode == NL80211_IFTYPE_UNSPECIFIED))
  565. return 0;
  566. if (!(hdr->flags & cpu_to_le16(P54_HDR_FLAG_DATA_IN_FCS_GOOD))) {
  567. if (priv->filter_flags & FIF_FCSFAIL)
  568. rx_status.flag |= RX_FLAG_FAILED_FCS_CRC;
  569. else
  570. return 0;
  571. }
  572. if (hdr->decrypt_status == P54_DECRYPT_OK)
  573. rx_status.flag |= RX_FLAG_DECRYPTED;
  574. if ((hdr->decrypt_status == P54_DECRYPT_FAIL_MICHAEL) ||
  575. (hdr->decrypt_status == P54_DECRYPT_FAIL_TKIP))
  576. rx_status.flag |= RX_FLAG_MMIC_ERROR;
  577. rx_status.signal = p54_rssi_to_dbm(dev, hdr->rssi);
  578. rx_status.noise = priv->noise;
  579. /* XX correct? */
  580. rx_status.qual = (100 * hdr->rssi) / 127;
  581. if (hdr->rate & 0x10)
  582. rx_status.flag |= RX_FLAG_SHORTPRE;
  583. if (dev->conf.channel->band == IEEE80211_BAND_5GHZ)
  584. rx_status.rate_idx = (rate < 4) ? 0 : rate - 4;
  585. else
  586. rx_status.rate_idx = rate;
  587. rx_status.freq = freq;
  588. rx_status.band = dev->conf.channel->band;
  589. rx_status.antenna = hdr->antenna;
  590. tsf32 = le32_to_cpu(hdr->tsf32);
  591. if (tsf32 < priv->tsf_low32)
  592. priv->tsf_high32++;
  593. rx_status.mactime = ((u64)priv->tsf_high32) << 32 | tsf32;
  594. priv->tsf_low32 = tsf32;
  595. rx_status.flag |= RX_FLAG_TSFT;
  596. if (hdr->flags & cpu_to_le16(P54_HDR_FLAG_DATA_ALIGN))
  597. header_len += hdr->align[0];
  598. skb_pull(skb, header_len);
  599. skb_trim(skb, le16_to_cpu(hdr->len));
  600. ieee80211_rx_irqsafe(dev, skb, &rx_status);
  601. queue_delayed_work(dev->workqueue, &priv->work,
  602. msecs_to_jiffies(P54_STATISTICS_UPDATE));
  603. return -1;
  604. }
  605. static void inline p54_wake_free_queues(struct ieee80211_hw *dev)
  606. {
  607. struct p54_common *priv = dev->priv;
  608. int i;
  609. if (priv->mode == NL80211_IFTYPE_UNSPECIFIED)
  610. return ;
  611. for (i = 0; i < dev->queues; i++)
  612. if (priv->tx_stats[i + P54_QUEUE_DATA].len <
  613. priv->tx_stats[i + P54_QUEUE_DATA].limit)
  614. ieee80211_wake_queue(dev, i);
  615. }
  616. void p54_free_skb(struct ieee80211_hw *dev, struct sk_buff *skb)
  617. {
  618. struct p54_common *priv = dev->priv;
  619. struct ieee80211_tx_info *info;
  620. struct memrecord *range;
  621. unsigned long flags;
  622. u32 freed = 0, last_addr = priv->rx_start;
  623. if (unlikely(!skb || !dev || !skb_queue_len(&priv->tx_queue)))
  624. return;
  625. /*
  626. * don't try to free an already unlinked skb
  627. */
  628. if (unlikely((!skb->next) || (!skb->prev)))
  629. return;
  630. spin_lock_irqsave(&priv->tx_queue.lock, flags);
  631. info = IEEE80211_SKB_CB(skb);
  632. range = (void *)info->rate_driver_data;
  633. if (skb->prev != (struct sk_buff *)&priv->tx_queue) {
  634. struct ieee80211_tx_info *ni;
  635. struct memrecord *mr;
  636. ni = IEEE80211_SKB_CB(skb->prev);
  637. mr = (struct memrecord *)ni->rate_driver_data;
  638. last_addr = mr->end_addr;
  639. }
  640. if (skb->next != (struct sk_buff *)&priv->tx_queue) {
  641. struct ieee80211_tx_info *ni;
  642. struct memrecord *mr;
  643. ni = IEEE80211_SKB_CB(skb->next);
  644. mr = (struct memrecord *)ni->rate_driver_data;
  645. freed = mr->start_addr - last_addr;
  646. } else
  647. freed = priv->rx_end - last_addr;
  648. __skb_unlink(skb, &priv->tx_queue);
  649. spin_unlock_irqrestore(&priv->tx_queue.lock, flags);
  650. dev_kfree_skb_any(skb);
  651. if (freed >= priv->headroom + sizeof(struct p54_hdr) + 48 +
  652. IEEE80211_MAX_RTS_THRESHOLD + priv->tailroom)
  653. p54_wake_free_queues(dev);
  654. }
  655. EXPORT_SYMBOL_GPL(p54_free_skb);
  656. static struct sk_buff *p54_find_tx_entry(struct ieee80211_hw *dev,
  657. __le32 req_id)
  658. {
  659. struct p54_common *priv = dev->priv;
  660. struct sk_buff *entry = priv->tx_queue.next;
  661. unsigned long flags;
  662. spin_lock_irqsave(&priv->tx_queue.lock, flags);
  663. while (entry != (struct sk_buff *)&priv->tx_queue) {
  664. struct p54_hdr *hdr = (struct p54_hdr *) entry->data;
  665. if (hdr->req_id == req_id) {
  666. spin_unlock_irqrestore(&priv->tx_queue.lock, flags);
  667. return entry;
  668. }
  669. entry = entry->next;
  670. }
  671. spin_unlock_irqrestore(&priv->tx_queue.lock, flags);
  672. return NULL;
  673. }
  674. static void p54_rx_frame_sent(struct ieee80211_hw *dev, struct sk_buff *skb)
  675. {
  676. struct p54_common *priv = dev->priv;
  677. struct p54_hdr *hdr = (struct p54_hdr *) skb->data;
  678. struct p54_frame_sent *payload = (struct p54_frame_sent *) hdr->data;
  679. struct sk_buff *entry = (struct sk_buff *) priv->tx_queue.next;
  680. u32 addr = le32_to_cpu(hdr->req_id) - priv->headroom;
  681. struct memrecord *range = NULL;
  682. u32 freed = 0;
  683. u32 last_addr = priv->rx_start;
  684. unsigned long flags;
  685. int count, idx;
  686. spin_lock_irqsave(&priv->tx_queue.lock, flags);
  687. while (entry != (struct sk_buff *)&priv->tx_queue) {
  688. struct ieee80211_tx_info *info = IEEE80211_SKB_CB(entry);
  689. struct p54_hdr *entry_hdr;
  690. struct p54_tx_data *entry_data;
  691. unsigned int pad = 0, frame_len;
  692. range = (void *)info->rate_driver_data;
  693. if (range->start_addr != addr) {
  694. last_addr = range->end_addr;
  695. entry = entry->next;
  696. continue;
  697. }
  698. if (entry->next != (struct sk_buff *)&priv->tx_queue) {
  699. struct ieee80211_tx_info *ni;
  700. struct memrecord *mr;
  701. ni = IEEE80211_SKB_CB(entry->next);
  702. mr = (struct memrecord *)ni->rate_driver_data;
  703. freed = mr->start_addr - last_addr;
  704. } else
  705. freed = priv->rx_end - last_addr;
  706. last_addr = range->end_addr;
  707. __skb_unlink(entry, &priv->tx_queue);
  708. spin_unlock_irqrestore(&priv->tx_queue.lock, flags);
  709. frame_len = entry->len;
  710. entry_hdr = (struct p54_hdr *) entry->data;
  711. entry_data = (struct p54_tx_data *) entry_hdr->data;
  712. priv->tx_stats[entry_data->hw_queue].len--;
  713. priv->stats.dot11ACKFailureCount += payload->tries - 1;
  714. /*
  715. * Frames in P54_QUEUE_FWSCAN and P54_QUEUE_BEACON are
  716. * generated by the driver. Therefore tx_status is bogus
  717. * and we don't want to confuse the mac80211 stack.
  718. */
  719. if (unlikely(entry_data->hw_queue < P54_QUEUE_FWSCAN)) {
  720. if (entry_data->hw_queue == P54_QUEUE_BEACON)
  721. priv->cached_beacon = NULL;
  722. kfree_skb(entry);
  723. goto out;
  724. }
  725. /*
  726. * Clear manually, ieee80211_tx_info_clear_status would
  727. * clear the counts too and we need them.
  728. */
  729. memset(&info->status.ampdu_ack_len, 0,
  730. sizeof(struct ieee80211_tx_info) -
  731. offsetof(struct ieee80211_tx_info, status.ampdu_ack_len));
  732. BUILD_BUG_ON(offsetof(struct ieee80211_tx_info,
  733. status.ampdu_ack_len) != 23);
  734. if (entry_hdr->flags & cpu_to_le16(P54_HDR_FLAG_DATA_ALIGN))
  735. pad = entry_data->align[0];
  736. /* walk through the rates array and adjust the counts */
  737. count = payload->tries;
  738. for (idx = 0; idx < 4; idx++) {
  739. if (count >= info->status.rates[idx].count) {
  740. count -= info->status.rates[idx].count;
  741. } else if (count > 0) {
  742. info->status.rates[idx].count = count;
  743. count = 0;
  744. } else {
  745. info->status.rates[idx].idx = -1;
  746. info->status.rates[idx].count = 0;
  747. }
  748. }
  749. if (!(info->flags & IEEE80211_TX_CTL_NO_ACK) &&
  750. (!payload->status))
  751. info->flags |= IEEE80211_TX_STAT_ACK;
  752. if (payload->status & P54_TX_PSM_CANCELLED)
  753. info->flags |= IEEE80211_TX_STAT_TX_FILTERED;
  754. info->status.ack_signal = p54_rssi_to_dbm(dev,
  755. (int)payload->ack_rssi);
  756. /* Undo all changes to the frame. */
  757. switch (entry_data->key_type) {
  758. case P54_CRYPTO_TKIPMICHAEL: {
  759. u8 *iv = (u8 *)(entry_data->align + pad +
  760. entry_data->crypt_offset);
  761. /* Restore the original TKIP IV. */
  762. iv[2] = iv[0];
  763. iv[0] = iv[1];
  764. iv[1] = (iv[0] | 0x20) & 0x7f; /* WEPSeed - 8.3.2.2 */
  765. frame_len -= 12; /* remove TKIP_MMIC + TKIP_ICV */
  766. break;
  767. }
  768. case P54_CRYPTO_AESCCMP:
  769. frame_len -= 8; /* remove CCMP_MIC */
  770. break;
  771. case P54_CRYPTO_WEP:
  772. frame_len -= 4; /* remove WEP_ICV */
  773. break;
  774. }
  775. skb_trim(entry, frame_len);
  776. skb_pull(entry, sizeof(*hdr) + pad + sizeof(*entry_data));
  777. ieee80211_tx_status_irqsafe(dev, entry);
  778. goto out;
  779. }
  780. spin_unlock_irqrestore(&priv->tx_queue.lock, flags);
  781. out:
  782. if (freed >= priv->headroom + sizeof(struct p54_hdr) + 48 +
  783. IEEE80211_MAX_RTS_THRESHOLD + priv->tailroom)
  784. p54_wake_free_queues(dev);
  785. }
  786. static void p54_rx_eeprom_readback(struct ieee80211_hw *dev,
  787. struct sk_buff *skb)
  788. {
  789. struct p54_hdr *hdr = (struct p54_hdr *) skb->data;
  790. struct p54_eeprom_lm86 *eeprom = (struct p54_eeprom_lm86 *) hdr->data;
  791. struct p54_common *priv = dev->priv;
  792. if (!priv->eeprom)
  793. return ;
  794. if (priv->fw_var >= 0x509) {
  795. memcpy(priv->eeprom, eeprom->v2.data,
  796. le16_to_cpu(eeprom->v2.len));
  797. } else {
  798. memcpy(priv->eeprom, eeprom->v1.data,
  799. le16_to_cpu(eeprom->v1.len));
  800. }
  801. complete(&priv->eeprom_comp);
  802. }
  803. static void p54_rx_stats(struct ieee80211_hw *dev, struct sk_buff *skb)
  804. {
  805. struct p54_common *priv = dev->priv;
  806. struct p54_hdr *hdr = (struct p54_hdr *) skb->data;
  807. struct p54_statistics *stats = (struct p54_statistics *) hdr->data;
  808. u32 tsf32;
  809. if (unlikely(priv->mode == NL80211_IFTYPE_UNSPECIFIED))
  810. return ;
  811. tsf32 = le32_to_cpu(stats->tsf32);
  812. if (tsf32 < priv->tsf_low32)
  813. priv->tsf_high32++;
  814. priv->tsf_low32 = tsf32;
  815. priv->stats.dot11RTSFailureCount = le32_to_cpu(stats->rts_fail);
  816. priv->stats.dot11RTSSuccessCount = le32_to_cpu(stats->rts_success);
  817. priv->stats.dot11FCSErrorCount = le32_to_cpu(stats->rx_bad_fcs);
  818. priv->noise = p54_rssi_to_dbm(dev, le32_to_cpu(stats->noise));
  819. p54_free_skb(dev, p54_find_tx_entry(dev, hdr->req_id));
  820. }
  821. static void p54_rx_trap(struct ieee80211_hw *dev, struct sk_buff *skb)
  822. {
  823. struct p54_hdr *hdr = (struct p54_hdr *) skb->data;
  824. struct p54_trap *trap = (struct p54_trap *) hdr->data;
  825. u16 event = le16_to_cpu(trap->event);
  826. u16 freq = le16_to_cpu(trap->frequency);
  827. switch (event) {
  828. case P54_TRAP_BEACON_TX:
  829. break;
  830. case P54_TRAP_RADAR:
  831. printk(KERN_INFO "%s: radar (freq:%d MHz)\n",
  832. wiphy_name(dev->wiphy), freq);
  833. break;
  834. case P54_TRAP_NO_BEACON:
  835. break;
  836. case P54_TRAP_SCAN:
  837. break;
  838. case P54_TRAP_TBTT:
  839. break;
  840. case P54_TRAP_TIMER:
  841. break;
  842. default:
  843. printk(KERN_INFO "%s: received event:%x freq:%d\n",
  844. wiphy_name(dev->wiphy), event, freq);
  845. break;
  846. }
  847. }
  848. static int p54_rx_control(struct ieee80211_hw *dev, struct sk_buff *skb)
  849. {
  850. struct p54_hdr *hdr = (struct p54_hdr *) skb->data;
  851. switch (le16_to_cpu(hdr->type)) {
  852. case P54_CONTROL_TYPE_TXDONE:
  853. p54_rx_frame_sent(dev, skb);
  854. break;
  855. case P54_CONTROL_TYPE_TRAP:
  856. p54_rx_trap(dev, skb);
  857. break;
  858. case P54_CONTROL_TYPE_BBP:
  859. break;
  860. case P54_CONTROL_TYPE_STAT_READBACK:
  861. p54_rx_stats(dev, skb);
  862. break;
  863. case P54_CONTROL_TYPE_EEPROM_READBACK:
  864. p54_rx_eeprom_readback(dev, skb);
  865. break;
  866. default:
  867. printk(KERN_DEBUG "%s: not handling 0x%02x type control frame\n",
  868. wiphy_name(dev->wiphy), le16_to_cpu(hdr->type));
  869. break;
  870. }
  871. return 0;
  872. }
  873. /* returns zero if skb can be reused */
  874. int p54_rx(struct ieee80211_hw *dev, struct sk_buff *skb)
  875. {
  876. u16 type = le16_to_cpu(*((__le16 *)skb->data));
  877. if (type & P54_HDR_FLAG_CONTROL)
  878. return p54_rx_control(dev, skb);
  879. else
  880. return p54_rx_data(dev, skb);
  881. }
  882. EXPORT_SYMBOL_GPL(p54_rx);
  883. /*
  884. * So, the firmware is somewhat stupid and doesn't know what places in its
  885. * memory incoming data should go to. By poking around in the firmware, we
  886. * can find some unused memory to upload our packets to. However, data that we
  887. * want the card to TX needs to stay intact until the card has told us that
  888. * it is done with it. This function finds empty places we can upload to and
  889. * marks allocated areas as reserved if necessary. p54_rx_frame_sent frees
  890. * allocated areas.
  891. */
  892. static int p54_assign_address(struct ieee80211_hw *dev, struct sk_buff *skb,
  893. struct p54_hdr *data, u32 len)
  894. {
  895. struct p54_common *priv = dev->priv;
  896. struct sk_buff *entry = priv->tx_queue.next;
  897. struct sk_buff *target_skb = NULL;
  898. struct ieee80211_tx_info *info;
  899. struct memrecord *range;
  900. u32 last_addr = priv->rx_start;
  901. u32 largest_hole = 0;
  902. u32 target_addr = priv->rx_start;
  903. unsigned long flags;
  904. unsigned int left;
  905. len = (len + priv->headroom + priv->tailroom + 3) & ~0x3;
  906. if (!skb)
  907. return -EINVAL;
  908. spin_lock_irqsave(&priv->tx_queue.lock, flags);
  909. left = skb_queue_len(&priv->tx_queue);
  910. if (unlikely(left >= 28)) {
  911. /*
  912. * The tx_queue is nearly full!
  913. * We have throttle normal data traffic, because we must
  914. * have a few spare slots for control frames left.
  915. */
  916. ieee80211_stop_queues(dev);
  917. queue_delayed_work(dev->workqueue, &priv->work,
  918. msecs_to_jiffies(P54_TX_TIMEOUT));
  919. if (unlikely(left == 32)) {
  920. /*
  921. * The tx_queue is now really full.
  922. *
  923. * TODO: check if the device has crashed and reset it.
  924. */
  925. spin_unlock_irqrestore(&priv->tx_queue.lock, flags);
  926. return -ENOSPC;
  927. }
  928. }
  929. while (left--) {
  930. u32 hole_size;
  931. info = IEEE80211_SKB_CB(entry);
  932. range = (void *)info->rate_driver_data;
  933. hole_size = range->start_addr - last_addr;
  934. if (!target_skb && hole_size >= len) {
  935. target_skb = entry->prev;
  936. hole_size -= len;
  937. target_addr = last_addr;
  938. }
  939. largest_hole = max(largest_hole, hole_size);
  940. last_addr = range->end_addr;
  941. entry = entry->next;
  942. }
  943. if (!target_skb && priv->rx_end - last_addr >= len) {
  944. target_skb = priv->tx_queue.prev;
  945. largest_hole = max(largest_hole, priv->rx_end - last_addr - len);
  946. if (!skb_queue_empty(&priv->tx_queue)) {
  947. info = IEEE80211_SKB_CB(target_skb);
  948. range = (void *)info->rate_driver_data;
  949. target_addr = range->end_addr;
  950. }
  951. } else
  952. largest_hole = max(largest_hole, priv->rx_end - last_addr);
  953. if (!target_skb) {
  954. spin_unlock_irqrestore(&priv->tx_queue.lock, flags);
  955. ieee80211_stop_queues(dev);
  956. return -ENOSPC;
  957. }
  958. info = IEEE80211_SKB_CB(skb);
  959. range = (void *)info->rate_driver_data;
  960. range->start_addr = target_addr;
  961. range->end_addr = target_addr + len;
  962. __skb_queue_after(&priv->tx_queue, target_skb, skb);
  963. spin_unlock_irqrestore(&priv->tx_queue.lock, flags);
  964. if (largest_hole < priv->headroom + sizeof(struct p54_hdr) +
  965. 48 + IEEE80211_MAX_RTS_THRESHOLD + priv->tailroom)
  966. ieee80211_stop_queues(dev);
  967. data->req_id = cpu_to_le32(target_addr + priv->headroom);
  968. return 0;
  969. }
  970. static struct sk_buff *p54_alloc_skb(struct ieee80211_hw *dev,
  971. u16 hdr_flags, u16 len, u16 type, gfp_t memflags)
  972. {
  973. struct p54_common *priv = dev->priv;
  974. struct p54_hdr *hdr;
  975. struct sk_buff *skb;
  976. skb = __dev_alloc_skb(len + priv->tx_hdr_len, memflags);
  977. if (!skb)
  978. return NULL;
  979. skb_reserve(skb, priv->tx_hdr_len);
  980. hdr = (struct p54_hdr *) skb_put(skb, sizeof(*hdr));
  981. hdr->flags = cpu_to_le16(hdr_flags);
  982. hdr->len = cpu_to_le16(len - sizeof(*hdr));
  983. hdr->type = cpu_to_le16(type);
  984. hdr->tries = hdr->rts_tries = 0;
  985. if (unlikely(p54_assign_address(dev, skb, hdr, len))) {
  986. kfree_skb(skb);
  987. return NULL;
  988. }
  989. return skb;
  990. }
  991. int p54_read_eeprom(struct ieee80211_hw *dev)
  992. {
  993. struct p54_common *priv = dev->priv;
  994. struct p54_hdr *hdr = NULL;
  995. struct p54_eeprom_lm86 *eeprom_hdr;
  996. struct sk_buff *skb;
  997. size_t eeprom_size = 0x2020, offset = 0, blocksize, maxblocksize;
  998. int ret = -ENOMEM;
  999. void *eeprom = NULL;
  1000. maxblocksize = EEPROM_READBACK_LEN;
  1001. if (priv->fw_var >= 0x509)
  1002. maxblocksize -= 0xc;
  1003. else
  1004. maxblocksize -= 0x4;
  1005. skb = p54_alloc_skb(dev, P54_HDR_FLAG_CONTROL, sizeof(*hdr) +
  1006. sizeof(*eeprom_hdr) + maxblocksize,
  1007. P54_CONTROL_TYPE_EEPROM_READBACK, GFP_KERNEL);
  1008. if (!skb)
  1009. goto free;
  1010. priv->eeprom = kzalloc(EEPROM_READBACK_LEN, GFP_KERNEL);
  1011. if (!priv->eeprom)
  1012. goto free;
  1013. eeprom = kzalloc(eeprom_size, GFP_KERNEL);
  1014. if (!eeprom)
  1015. goto free;
  1016. eeprom_hdr = (struct p54_eeprom_lm86 *) skb_put(skb,
  1017. sizeof(*eeprom_hdr) + maxblocksize);
  1018. while (eeprom_size) {
  1019. blocksize = min(eeprom_size, maxblocksize);
  1020. if (priv->fw_var < 0x509) {
  1021. eeprom_hdr->v1.offset = cpu_to_le16(offset);
  1022. eeprom_hdr->v1.len = cpu_to_le16(blocksize);
  1023. } else {
  1024. eeprom_hdr->v2.offset = cpu_to_le32(offset);
  1025. eeprom_hdr->v2.len = cpu_to_le16(blocksize);
  1026. eeprom_hdr->v2.magic2 = 0xf;
  1027. memcpy(eeprom_hdr->v2.magic, (const char *)"LOCK", 4);
  1028. }
  1029. priv->tx(dev, skb);
  1030. if (!wait_for_completion_interruptible_timeout(&priv->eeprom_comp, HZ)) {
  1031. printk(KERN_ERR "%s: device does not respond!\n",
  1032. wiphy_name(dev->wiphy));
  1033. ret = -EBUSY;
  1034. goto free;
  1035. }
  1036. memcpy(eeprom + offset, priv->eeprom, blocksize);
  1037. offset += blocksize;
  1038. eeprom_size -= blocksize;
  1039. }
  1040. ret = p54_parse_eeprom(dev, eeprom, offset);
  1041. free:
  1042. kfree(priv->eeprom);
  1043. priv->eeprom = NULL;
  1044. p54_free_skb(dev, skb);
  1045. kfree(eeprom);
  1046. return ret;
  1047. }
  1048. EXPORT_SYMBOL_GPL(p54_read_eeprom);
  1049. static int p54_set_tim(struct ieee80211_hw *dev, struct ieee80211_sta *sta,
  1050. bool set)
  1051. {
  1052. struct p54_common *priv = dev->priv;
  1053. struct sk_buff *skb;
  1054. struct p54_tim *tim;
  1055. skb = p54_alloc_skb(dev, P54_HDR_FLAG_CONTROL_OPSET,
  1056. sizeof(struct p54_hdr) + sizeof(*tim),
  1057. P54_CONTROL_TYPE_TIM, GFP_ATOMIC);
  1058. if (!skb)
  1059. return -ENOMEM;
  1060. tim = (struct p54_tim *) skb_put(skb, sizeof(*tim));
  1061. tim->count = 1;
  1062. tim->entry[0] = cpu_to_le16(set ? (sta->aid | 0x8000) : sta->aid);
  1063. priv->tx(dev, skb);
  1064. return 0;
  1065. }
  1066. static int p54_sta_unlock(struct ieee80211_hw *dev, u8 *addr)
  1067. {
  1068. struct p54_common *priv = dev->priv;
  1069. struct sk_buff *skb;
  1070. struct p54_sta_unlock *sta;
  1071. skb = p54_alloc_skb(dev, P54_HDR_FLAG_CONTROL_OPSET,
  1072. sizeof(struct p54_hdr) + sizeof(*sta),
  1073. P54_CONTROL_TYPE_PSM_STA_UNLOCK, GFP_ATOMIC);
  1074. if (!skb)
  1075. return -ENOMEM;
  1076. sta = (struct p54_sta_unlock *)skb_put(skb, sizeof(*sta));
  1077. memcpy(sta->addr, addr, ETH_ALEN);
  1078. priv->tx(dev, skb);
  1079. return 0;
  1080. }
  1081. static void p54_sta_notify(struct ieee80211_hw *dev, struct ieee80211_vif *vif,
  1082. enum sta_notify_cmd notify_cmd,
  1083. struct ieee80211_sta *sta)
  1084. {
  1085. switch (notify_cmd) {
  1086. case STA_NOTIFY_ADD:
  1087. case STA_NOTIFY_REMOVE:
  1088. /*
  1089. * Notify the firmware that we don't want or we don't
  1090. * need to buffer frames for this station anymore.
  1091. */
  1092. p54_sta_unlock(dev, sta->addr);
  1093. break;
  1094. case STA_NOTIFY_AWAKE:
  1095. /* update the firmware's filter table */
  1096. p54_sta_unlock(dev, sta->addr);
  1097. break;
  1098. default:
  1099. break;
  1100. }
  1101. }
  1102. static int p54_tx_cancel(struct ieee80211_hw *dev, struct sk_buff *entry)
  1103. {
  1104. struct p54_common *priv = dev->priv;
  1105. struct sk_buff *skb;
  1106. struct p54_hdr *hdr;
  1107. struct p54_txcancel *cancel;
  1108. skb = p54_alloc_skb(dev, P54_HDR_FLAG_CONTROL_OPSET,
  1109. sizeof(struct p54_hdr) + sizeof(*cancel),
  1110. P54_CONTROL_TYPE_TXCANCEL, GFP_ATOMIC);
  1111. if (!skb)
  1112. return -ENOMEM;
  1113. hdr = (void *)entry->data;
  1114. cancel = (struct p54_txcancel *)skb_put(skb, sizeof(*cancel));
  1115. cancel->req_id = hdr->req_id;
  1116. priv->tx(dev, skb);
  1117. return 0;
  1118. }
  1119. static int p54_tx_fill(struct ieee80211_hw *dev, struct sk_buff *skb,
  1120. struct ieee80211_tx_info *info, u8 *queue, size_t *extra_len,
  1121. u16 *flags, u16 *aid)
  1122. {
  1123. struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
  1124. struct p54_common *priv = dev->priv;
  1125. int ret = 1;
  1126. switch (priv->mode) {
  1127. case NL80211_IFTYPE_MONITOR:
  1128. /*
  1129. * We have to set P54_HDR_FLAG_DATA_OUT_PROMISC for
  1130. * every frame in promiscuous/monitor mode.
  1131. * see STSW45x0C LMAC API - page 12.
  1132. */
  1133. *aid = 0;
  1134. *flags = P54_HDR_FLAG_DATA_OUT_PROMISC;
  1135. *queue += P54_QUEUE_DATA;
  1136. break;
  1137. case NL80211_IFTYPE_STATION:
  1138. *aid = 1;
  1139. if (unlikely(ieee80211_is_mgmt(hdr->frame_control))) {
  1140. *queue = P54_QUEUE_MGMT;
  1141. ret = 0;
  1142. } else
  1143. *queue += P54_QUEUE_DATA;
  1144. break;
  1145. case NL80211_IFTYPE_AP:
  1146. case NL80211_IFTYPE_ADHOC:
  1147. case NL80211_IFTYPE_MESH_POINT:
  1148. if (info->flags & IEEE80211_TX_CTL_SEND_AFTER_DTIM) {
  1149. *aid = 0;
  1150. *queue = P54_QUEUE_CAB;
  1151. return 0;
  1152. }
  1153. if (unlikely(ieee80211_is_mgmt(hdr->frame_control))) {
  1154. if (ieee80211_is_probe_resp(hdr->frame_control)) {
  1155. *aid = 0;
  1156. *queue = P54_QUEUE_MGMT;
  1157. *flags = P54_HDR_FLAG_DATA_OUT_TIMESTAMP |
  1158. P54_HDR_FLAG_DATA_OUT_NOCANCEL;
  1159. return 0;
  1160. } else if (ieee80211_is_beacon(hdr->frame_control)) {
  1161. *aid = 0;
  1162. if (info->flags & IEEE80211_TX_CTL_INJECTED) {
  1163. /*
  1164. * Injecting beacons on top of a AP is
  1165. * not a good idea... nevertheless,
  1166. * it should be doable.
  1167. */
  1168. *queue += P54_QUEUE_DATA;
  1169. return 1;
  1170. }
  1171. *flags = P54_HDR_FLAG_DATA_OUT_TIMESTAMP;
  1172. *queue = P54_QUEUE_BEACON;
  1173. *extra_len = IEEE80211_MAX_TIM_LEN;
  1174. return 0;
  1175. } else {
  1176. *queue = P54_QUEUE_MGMT;
  1177. ret = 0;
  1178. }
  1179. } else
  1180. *queue += P54_QUEUE_DATA;
  1181. if (info->control.sta)
  1182. *aid = info->control.sta->aid;
  1183. else
  1184. *flags |= P54_HDR_FLAG_DATA_OUT_NOCANCEL;
  1185. break;
  1186. }
  1187. return ret;
  1188. }
  1189. static u8 p54_convert_algo(enum ieee80211_key_alg alg)
  1190. {
  1191. switch (alg) {
  1192. case ALG_WEP:
  1193. return P54_CRYPTO_WEP;
  1194. case ALG_TKIP:
  1195. return P54_CRYPTO_TKIPMICHAEL;
  1196. case ALG_CCMP:
  1197. return P54_CRYPTO_AESCCMP;
  1198. default:
  1199. return 0;
  1200. }
  1201. }
  1202. static int p54_tx(struct ieee80211_hw *dev, struct sk_buff *skb)
  1203. {
  1204. struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
  1205. struct ieee80211_tx_queue_stats *current_queue;
  1206. struct p54_common *priv = dev->priv;
  1207. struct p54_hdr *hdr;
  1208. struct p54_tx_data *txhdr;
  1209. size_t padding, len, tim_len = 0;
  1210. int i, j, ridx, ret;
  1211. u16 hdr_flags = 0, aid = 0;
  1212. u8 rate, queue, crypt_offset = 0;
  1213. u8 cts_rate = 0x20;
  1214. u8 rc_flags;
  1215. u8 calculated_tries[4];
  1216. u8 nrates = 0, nremaining = 8;
  1217. queue = skb_get_queue_mapping(skb);
  1218. ret = p54_tx_fill(dev, skb, info, &queue, &tim_len, &hdr_flags, &aid);
  1219. current_queue = &priv->tx_stats[queue];
  1220. if (unlikely((current_queue->len > current_queue->limit) && ret))
  1221. return NETDEV_TX_BUSY;
  1222. current_queue->len++;
  1223. current_queue->count++;
  1224. if ((current_queue->len == current_queue->limit) && ret)
  1225. ieee80211_stop_queue(dev, skb_get_queue_mapping(skb));
  1226. padding = (unsigned long)(skb->data - (sizeof(*hdr) + sizeof(*txhdr))) & 3;
  1227. len = skb->len;
  1228. if (info->control.hw_key) {
  1229. crypt_offset = ieee80211_get_hdrlen_from_skb(skb);
  1230. if (info->control.hw_key->alg == ALG_TKIP) {
  1231. u8 *iv = (u8 *)(skb->data + crypt_offset);
  1232. /*
  1233. * The firmware excepts that the IV has to have
  1234. * this special format
  1235. */
  1236. iv[1] = iv[0];
  1237. iv[0] = iv[2];
  1238. iv[2] = 0;
  1239. }
  1240. }
  1241. txhdr = (struct p54_tx_data *) skb_push(skb, sizeof(*txhdr) + padding);
  1242. hdr = (struct p54_hdr *) skb_push(skb, sizeof(*hdr));
  1243. if (padding)
  1244. hdr_flags |= P54_HDR_FLAG_DATA_ALIGN;
  1245. hdr->type = cpu_to_le16(aid);
  1246. hdr->rts_tries = info->control.rates[0].count;
  1247. /*
  1248. * we register the rates in perfect order, and
  1249. * RTS/CTS won't happen on 5 GHz
  1250. */
  1251. cts_rate = info->control.rts_cts_rate_idx;
  1252. memset(&txhdr->rateset, 0, sizeof(txhdr->rateset));
  1253. /* see how many rates got used */
  1254. for (i = 0; i < 4; i++) {
  1255. if (info->control.rates[i].idx < 0)
  1256. break;
  1257. nrates++;
  1258. }
  1259. /* limit tries to 8/nrates per rate */
  1260. for (i = 0; i < nrates; i++) {
  1261. /*
  1262. * The magic expression here is equivalent to 8/nrates for
  1263. * all values that matter, but avoids division and jumps.
  1264. * Note that nrates can only take the values 1 through 4.
  1265. */
  1266. calculated_tries[i] = min_t(int, ((15 >> nrates) | 1) + 1,
  1267. info->control.rates[i].count);
  1268. nremaining -= calculated_tries[i];
  1269. }
  1270. /* if there are tries left, distribute from back to front */
  1271. for (i = nrates - 1; nremaining > 0 && i >= 0; i--) {
  1272. int tmp = info->control.rates[i].count - calculated_tries[i];
  1273. if (tmp <= 0)
  1274. continue;
  1275. /* RC requested more tries at this rate */
  1276. tmp = min_t(int, tmp, nremaining);
  1277. calculated_tries[i] += tmp;
  1278. nremaining -= tmp;
  1279. }
  1280. ridx = 0;
  1281. for (i = 0; i < nrates && ridx < 8; i++) {
  1282. /* we register the rates in perfect order */
  1283. rate = info->control.rates[i].idx;
  1284. if (info->band == IEEE80211_BAND_5GHZ)
  1285. rate += 4;
  1286. /* store the count we actually calculated for TX status */
  1287. info->control.rates[i].count = calculated_tries[i];
  1288. rc_flags = info->control.rates[i].flags;
  1289. if (rc_flags & IEEE80211_TX_RC_USE_SHORT_PREAMBLE) {
  1290. rate |= 0x10;
  1291. cts_rate |= 0x10;
  1292. }
  1293. if (rc_flags & IEEE80211_TX_RC_USE_RTS_CTS)
  1294. rate |= 0x40;
  1295. else if (rc_flags & IEEE80211_TX_RC_USE_CTS_PROTECT)
  1296. rate |= 0x20;
  1297. for (j = 0; j < calculated_tries[i] && ridx < 8; j++) {
  1298. txhdr->rateset[ridx] = rate;
  1299. ridx++;
  1300. }
  1301. }
  1302. if (info->flags & IEEE80211_TX_CTL_ASSIGN_SEQ)
  1303. hdr_flags |= P54_HDR_FLAG_DATA_OUT_SEQNR;
  1304. /* TODO: enable bursting */
  1305. hdr->flags = cpu_to_le16(hdr_flags);
  1306. hdr->tries = ridx;
  1307. txhdr->rts_rate_idx = 0;
  1308. if (info->control.hw_key) {
  1309. txhdr->key_type = p54_convert_algo(info->control.hw_key->alg);
  1310. txhdr->key_len = min((u8)16, info->control.hw_key->keylen);
  1311. memcpy(txhdr->key, info->control.hw_key->key, txhdr->key_len);
  1312. if (info->control.hw_key->alg == ALG_TKIP) {
  1313. if (unlikely(skb_tailroom(skb) < 12))
  1314. goto err;
  1315. /* reserve space for the MIC key */
  1316. len += 8;
  1317. memcpy(skb_put(skb, 8), &(info->control.hw_key->key
  1318. [NL80211_TKIP_DATA_OFFSET_TX_MIC_KEY]), 8);
  1319. }
  1320. /* reserve some space for ICV */
  1321. len += info->control.hw_key->icv_len;
  1322. memset(skb_put(skb, info->control.hw_key->icv_len), 0,
  1323. info->control.hw_key->icv_len);
  1324. } else {
  1325. txhdr->key_type = 0;
  1326. txhdr->key_len = 0;
  1327. }
  1328. txhdr->crypt_offset = crypt_offset;
  1329. txhdr->hw_queue = queue;
  1330. txhdr->backlog = current_queue->len;
  1331. memset(txhdr->durations, 0, sizeof(txhdr->durations));
  1332. txhdr->tx_antenna = ((info->antenna_sel_tx == 0) ?
  1333. 2 : info->antenna_sel_tx - 1) & priv->tx_diversity_mask;
  1334. txhdr->output_power = priv->output_power;
  1335. txhdr->cts_rate = cts_rate;
  1336. if (padding)
  1337. txhdr->align[0] = padding;
  1338. hdr->len = cpu_to_le16(len);
  1339. /* modifies skb->cb and with it info, so must be last! */
  1340. if (unlikely(p54_assign_address(dev, skb, hdr, skb->len + tim_len)))
  1341. goto err;
  1342. priv->tx(dev, skb);
  1343. queue_delayed_work(dev->workqueue, &priv->work,
  1344. msecs_to_jiffies(P54_TX_FRAME_LIFETIME));
  1345. return 0;
  1346. err:
  1347. skb_pull(skb, sizeof(*hdr) + sizeof(*txhdr) + padding);
  1348. current_queue->len--;
  1349. current_queue->count--;
  1350. return NETDEV_TX_BUSY;
  1351. }
  1352. static int p54_setup_mac(struct ieee80211_hw *dev)
  1353. {
  1354. struct p54_common *priv = dev->priv;
  1355. struct sk_buff *skb;
  1356. struct p54_setup_mac *setup;
  1357. u16 mode;
  1358. skb = p54_alloc_skb(dev, P54_HDR_FLAG_CONTROL_OPSET, sizeof(*setup) +
  1359. sizeof(struct p54_hdr), P54_CONTROL_TYPE_SETUP,
  1360. GFP_ATOMIC);
  1361. if (!skb)
  1362. return -ENOMEM;
  1363. setup = (struct p54_setup_mac *) skb_put(skb, sizeof(*setup));
  1364. if (dev->conf.radio_enabled) {
  1365. switch (priv->mode) {
  1366. case NL80211_IFTYPE_STATION:
  1367. mode = P54_FILTER_TYPE_STATION;
  1368. break;
  1369. case NL80211_IFTYPE_AP:
  1370. mode = P54_FILTER_TYPE_AP;
  1371. break;
  1372. case NL80211_IFTYPE_ADHOC:
  1373. case NL80211_IFTYPE_MESH_POINT:
  1374. mode = P54_FILTER_TYPE_IBSS;
  1375. break;
  1376. case NL80211_IFTYPE_MONITOR:
  1377. mode = P54_FILTER_TYPE_PROMISCUOUS;
  1378. break;
  1379. default:
  1380. mode = P54_FILTER_TYPE_NONE;
  1381. break;
  1382. }
  1383. /*
  1384. * "TRANSPARENT and PROMISCUOUS are mutually exclusive"
  1385. * STSW45X0C LMAC API - page 12
  1386. */
  1387. if (((priv->filter_flags & FIF_PROMISC_IN_BSS) ||
  1388. (priv->filter_flags & FIF_OTHER_BSS)) &&
  1389. (mode != P54_FILTER_TYPE_PROMISCUOUS))
  1390. mode |= P54_FILTER_TYPE_TRANSPARENT;
  1391. } else
  1392. mode = P54_FILTER_TYPE_RX_DISABLED;
  1393. setup->mac_mode = cpu_to_le16(mode);
  1394. memcpy(setup->mac_addr, priv->mac_addr, ETH_ALEN);
  1395. memcpy(setup->bssid, priv->bssid, ETH_ALEN);
  1396. setup->rx_antenna = 2 & priv->rx_diversity_mask; /* automatic */
  1397. setup->rx_align = 0;
  1398. if (priv->fw_var < 0x500) {
  1399. setup->v1.basic_rate_mask = cpu_to_le32(priv->basic_rate_mask);
  1400. memset(setup->v1.rts_rates, 0, 8);
  1401. setup->v1.rx_addr = cpu_to_le32(priv->rx_end);
  1402. setup->v1.max_rx = cpu_to_le16(priv->rx_mtu);
  1403. setup->v1.rxhw = cpu_to_le16(priv->rxhw);
  1404. setup->v1.wakeup_timer = cpu_to_le16(priv->wakeup_timer);
  1405. setup->v1.unalloc0 = cpu_to_le16(0);
  1406. } else {
  1407. setup->v2.rx_addr = cpu_to_le32(priv->rx_end);
  1408. setup->v2.max_rx = cpu_to_le16(priv->rx_mtu);
  1409. setup->v2.rxhw = cpu_to_le16(priv->rxhw);
  1410. setup->v2.timer = cpu_to_le16(priv->wakeup_timer);
  1411. setup->v2.truncate = cpu_to_le16(48896);
  1412. setup->v2.basic_rate_mask = cpu_to_le32(priv->basic_rate_mask);
  1413. setup->v2.sbss_offset = 0;
  1414. setup->v2.mcast_window = 0;
  1415. setup->v2.rx_rssi_threshold = 0;
  1416. setup->v2.rx_ed_threshold = 0;
  1417. setup->v2.ref_clock = cpu_to_le32(644245094);
  1418. setup->v2.lpf_bandwidth = cpu_to_le16(65535);
  1419. setup->v2.osc_start_delay = cpu_to_le16(65535);
  1420. }
  1421. priv->tx(dev, skb);
  1422. return 0;
  1423. }
  1424. static int p54_scan(struct ieee80211_hw *dev, u16 mode, u16 dwell)
  1425. {
  1426. struct p54_common *priv = dev->priv;
  1427. struct sk_buff *skb;
  1428. struct p54_scan *chan;
  1429. unsigned int i;
  1430. void *entry;
  1431. __le16 freq = cpu_to_le16(dev->conf.channel->center_freq);
  1432. int band = dev->conf.channel->band;
  1433. skb = p54_alloc_skb(dev, P54_HDR_FLAG_CONTROL_OPSET, sizeof(*chan) +
  1434. sizeof(struct p54_hdr), P54_CONTROL_TYPE_SCAN,
  1435. GFP_ATOMIC);
  1436. if (!skb)
  1437. return -ENOMEM;
  1438. chan = (struct p54_scan *) skb_put(skb, sizeof(*chan));
  1439. memset(chan->padding1, 0, sizeof(chan->padding1));
  1440. chan->mode = cpu_to_le16(mode);
  1441. chan->dwell = cpu_to_le16(dwell);
  1442. for (i = 0; i < priv->iq_autocal_len; i++) {
  1443. if (priv->iq_autocal[i].freq != freq)
  1444. continue;
  1445. memcpy(&chan->iq_autocal, &priv->iq_autocal[i],
  1446. sizeof(*priv->iq_autocal));
  1447. break;
  1448. }
  1449. if (i == priv->iq_autocal_len)
  1450. goto err;
  1451. for (i = 0; i < priv->output_limit_len; i++) {
  1452. if (priv->output_limit[i].freq != freq)
  1453. continue;
  1454. chan->val_barker = 0x38;
  1455. chan->val_bpsk = chan->dup_bpsk =
  1456. priv->output_limit[i].val_bpsk;
  1457. chan->val_qpsk = chan->dup_qpsk =
  1458. priv->output_limit[i].val_qpsk;
  1459. chan->val_16qam = chan->dup_16qam =
  1460. priv->output_limit[i].val_16qam;
  1461. chan->val_64qam = chan->dup_64qam =
  1462. priv->output_limit[i].val_64qam;
  1463. break;
  1464. }
  1465. if (i == priv->output_limit_len)
  1466. goto err;
  1467. entry = priv->curve_data->data;
  1468. for (i = 0; i < priv->curve_data->channels; i++) {
  1469. if (*((__le16 *)entry) != freq) {
  1470. entry += sizeof(__le16);
  1471. entry += sizeof(struct p54_pa_curve_data_sample) *
  1472. priv->curve_data->points_per_channel;
  1473. continue;
  1474. }
  1475. entry += sizeof(__le16);
  1476. chan->pa_points_per_curve = 8;
  1477. memset(chan->curve_data, 0, sizeof(*chan->curve_data));
  1478. memcpy(chan->curve_data, entry,
  1479. sizeof(struct p54_pa_curve_data_sample) *
  1480. min((u8)8, priv->curve_data->points_per_channel));
  1481. break;
  1482. }
  1483. if (priv->fw_var < 0x500) {
  1484. chan->v1_rssi.mul = cpu_to_le16(priv->rssical_db[band].mul);
  1485. chan->v1_rssi.add = cpu_to_le16(priv->rssical_db[band].add);
  1486. } else {
  1487. chan->v2.rssi.mul = cpu_to_le16(priv->rssical_db[band].mul);
  1488. chan->v2.rssi.add = cpu_to_le16(priv->rssical_db[band].add);
  1489. chan->v2.basic_rate_mask = cpu_to_le32(priv->basic_rate_mask);
  1490. memset(chan->v2.rts_rates, 0, 8);
  1491. }
  1492. priv->tx(dev, skb);
  1493. return 0;
  1494. err:
  1495. printk(KERN_ERR "%s: frequency change failed\n", wiphy_name(dev->wiphy));
  1496. p54_free_skb(dev, skb);
  1497. return -EINVAL;
  1498. }
  1499. static int p54_set_leds(struct ieee80211_hw *dev, int mode, int link, int act)
  1500. {
  1501. struct p54_common *priv = dev->priv;
  1502. struct sk_buff *skb;
  1503. struct p54_led *led;
  1504. skb = p54_alloc_skb(dev, P54_HDR_FLAG_CONTROL_OPSET, sizeof(*led) +
  1505. sizeof(struct p54_hdr), P54_CONTROL_TYPE_LED,
  1506. GFP_ATOMIC);
  1507. if (!skb)
  1508. return -ENOMEM;
  1509. led = (struct p54_led *)skb_put(skb, sizeof(*led));
  1510. led->mode = cpu_to_le16(mode);
  1511. led->led_permanent = cpu_to_le16(link);
  1512. led->led_temporary = cpu_to_le16(act);
  1513. led->duration = cpu_to_le16(1000);
  1514. priv->tx(dev, skb);
  1515. return 0;
  1516. }
  1517. #define P54_SET_QUEUE(queue, ai_fs, cw_min, cw_max, _txop) \
  1518. do { \
  1519. queue.aifs = cpu_to_le16(ai_fs); \
  1520. queue.cwmin = cpu_to_le16(cw_min); \
  1521. queue.cwmax = cpu_to_le16(cw_max); \
  1522. queue.txop = cpu_to_le16(_txop); \
  1523. } while(0)
  1524. static int p54_set_edcf(struct ieee80211_hw *dev)
  1525. {
  1526. struct p54_common *priv = dev->priv;
  1527. struct sk_buff *skb;
  1528. struct p54_edcf *edcf;
  1529. skb = p54_alloc_skb(dev, P54_HDR_FLAG_CONTROL_OPSET, sizeof(*edcf) +
  1530. sizeof(struct p54_hdr), P54_CONTROL_TYPE_DCFINIT,
  1531. GFP_ATOMIC);
  1532. if (!skb)
  1533. return -ENOMEM;
  1534. edcf = (struct p54_edcf *)skb_put(skb, sizeof(*edcf));
  1535. if (priv->use_short_slot) {
  1536. edcf->slottime = 9;
  1537. edcf->sifs = 0x10;
  1538. edcf->eofpad = 0x00;
  1539. } else {
  1540. edcf->slottime = 20;
  1541. edcf->sifs = 0x0a;
  1542. edcf->eofpad = 0x06;
  1543. }
  1544. /* (see prism54/isl_oid.h for further details) */
  1545. edcf->frameburst = cpu_to_le16(0);
  1546. edcf->round_trip_delay = cpu_to_le16(0);
  1547. edcf->flags = 0;
  1548. memset(edcf->mapping, 0, sizeof(edcf->mapping));
  1549. memcpy(edcf->queue, priv->qos_params, sizeof(edcf->queue));
  1550. priv->tx(dev, skb);
  1551. return 0;
  1552. }
  1553. static int p54_beacon_tim(struct sk_buff *skb)
  1554. {
  1555. /*
  1556. * the good excuse for this mess is ... the firmware.
  1557. * The dummy TIM MUST be at the end of the beacon frame,
  1558. * because it'll be overwritten!
  1559. */
  1560. struct ieee80211_mgmt *mgmt = (void *)skb->data;
  1561. u8 *pos, *end;
  1562. if (skb->len <= sizeof(mgmt))
  1563. return -EINVAL;
  1564. pos = (u8 *)mgmt->u.beacon.variable;
  1565. end = skb->data + skb->len;
  1566. while (pos < end) {
  1567. if (pos + 2 + pos[1] > end)
  1568. return -EINVAL;
  1569. if (pos[0] == WLAN_EID_TIM) {
  1570. u8 dtim_len = pos[1];
  1571. u8 dtim_period = pos[3];
  1572. u8 *next = pos + 2 + dtim_len;
  1573. if (dtim_len < 3)
  1574. return -EINVAL;
  1575. memmove(pos, next, end - next);
  1576. if (dtim_len > 3)
  1577. skb_trim(skb, skb->len - (dtim_len - 3));
  1578. pos = end - (dtim_len + 2);
  1579. /* add the dummy at the end */
  1580. pos[0] = WLAN_EID_TIM;
  1581. pos[1] = 3;
  1582. pos[2] = 0;
  1583. pos[3] = dtim_period;
  1584. pos[4] = 0;
  1585. return 0;
  1586. }
  1587. pos += 2 + pos[1];
  1588. }
  1589. return 0;
  1590. }
  1591. static int p54_beacon_update(struct ieee80211_hw *dev,
  1592. struct ieee80211_vif *vif)
  1593. {
  1594. struct p54_common *priv = dev->priv;
  1595. struct sk_buff *beacon;
  1596. int ret;
  1597. if (priv->cached_beacon) {
  1598. p54_tx_cancel(dev, priv->cached_beacon);
  1599. /* wait for the last beacon the be freed */
  1600. msleep(10);
  1601. }
  1602. beacon = ieee80211_beacon_get(dev, vif);
  1603. if (!beacon)
  1604. return -ENOMEM;
  1605. ret = p54_beacon_tim(beacon);
  1606. if (ret)
  1607. return ret;
  1608. ret = p54_tx(dev, beacon);
  1609. if (ret)
  1610. return ret;
  1611. priv->cached_beacon = beacon;
  1612. priv->tsf_high32 = 0;
  1613. priv->tsf_low32 = 0;
  1614. return 0;
  1615. }
  1616. static int p54_start(struct ieee80211_hw *dev)
  1617. {
  1618. struct p54_common *priv = dev->priv;
  1619. int err;
  1620. mutex_lock(&priv->conf_mutex);
  1621. err = priv->open(dev);
  1622. if (err)
  1623. goto out;
  1624. P54_SET_QUEUE(priv->qos_params[0], 0x0002, 0x0003, 0x0007, 47);
  1625. P54_SET_QUEUE(priv->qos_params[1], 0x0002, 0x0007, 0x000f, 94);
  1626. P54_SET_QUEUE(priv->qos_params[2], 0x0003, 0x000f, 0x03ff, 0);
  1627. P54_SET_QUEUE(priv->qos_params[3], 0x0007, 0x000f, 0x03ff, 0);
  1628. err = p54_set_edcf(dev);
  1629. if (err)
  1630. goto out;
  1631. memset(priv->bssid, ~0, ETH_ALEN);
  1632. priv->mode = NL80211_IFTYPE_MONITOR;
  1633. err = p54_setup_mac(dev);
  1634. if (err) {
  1635. priv->mode = NL80211_IFTYPE_UNSPECIFIED;
  1636. goto out;
  1637. }
  1638. queue_delayed_work(dev->workqueue, &priv->work, 0);
  1639. out:
  1640. mutex_unlock(&priv->conf_mutex);
  1641. return err;
  1642. }
  1643. static void p54_stop(struct ieee80211_hw *dev)
  1644. {
  1645. struct p54_common *priv = dev->priv;
  1646. struct sk_buff *skb;
  1647. mutex_lock(&priv->conf_mutex);
  1648. priv->mode = NL80211_IFTYPE_UNSPECIFIED;
  1649. cancel_delayed_work_sync(&priv->work);
  1650. if (priv->cached_beacon)
  1651. p54_tx_cancel(dev, priv->cached_beacon);
  1652. priv->stop(dev);
  1653. while ((skb = skb_dequeue(&priv->tx_queue)))
  1654. kfree_skb(skb);
  1655. priv->cached_beacon = NULL;
  1656. priv->tsf_high32 = priv->tsf_low32 = 0;
  1657. mutex_unlock(&priv->conf_mutex);
  1658. }
  1659. static int p54_add_interface(struct ieee80211_hw *dev,
  1660. struct ieee80211_if_init_conf *conf)
  1661. {
  1662. struct p54_common *priv = dev->priv;
  1663. mutex_lock(&priv->conf_mutex);
  1664. if (priv->mode != NL80211_IFTYPE_MONITOR) {
  1665. mutex_unlock(&priv->conf_mutex);
  1666. return -EOPNOTSUPP;
  1667. }
  1668. switch (conf->type) {
  1669. case NL80211_IFTYPE_STATION:
  1670. case NL80211_IFTYPE_ADHOC:
  1671. case NL80211_IFTYPE_AP:
  1672. case NL80211_IFTYPE_MESH_POINT:
  1673. priv->mode = conf->type;
  1674. break;
  1675. default:
  1676. mutex_unlock(&priv->conf_mutex);
  1677. return -EOPNOTSUPP;
  1678. }
  1679. memcpy(priv->mac_addr, conf->mac_addr, ETH_ALEN);
  1680. p54_setup_mac(dev);
  1681. p54_set_leds(dev, 1, 0, 0);
  1682. mutex_unlock(&priv->conf_mutex);
  1683. return 0;
  1684. }
  1685. static void p54_remove_interface(struct ieee80211_hw *dev,
  1686. struct ieee80211_if_init_conf *conf)
  1687. {
  1688. struct p54_common *priv = dev->priv;
  1689. mutex_lock(&priv->conf_mutex);
  1690. if (priv->cached_beacon)
  1691. p54_tx_cancel(dev, priv->cached_beacon);
  1692. priv->mode = NL80211_IFTYPE_MONITOR;
  1693. memset(priv->mac_addr, 0, ETH_ALEN);
  1694. memset(priv->bssid, 0, ETH_ALEN);
  1695. p54_setup_mac(dev);
  1696. mutex_unlock(&priv->conf_mutex);
  1697. }
  1698. static int p54_config(struct ieee80211_hw *dev, u32 changed)
  1699. {
  1700. int ret = 0;
  1701. struct p54_common *priv = dev->priv;
  1702. struct ieee80211_conf *conf = &dev->conf;
  1703. mutex_lock(&priv->conf_mutex);
  1704. if (changed & IEEE80211_CONF_CHANGE_POWER)
  1705. priv->output_power = conf->power_level << 2;
  1706. if (changed & IEEE80211_CONF_CHANGE_RADIO_ENABLED) {
  1707. ret = p54_setup_mac(dev);
  1708. if (ret)
  1709. goto out;
  1710. }
  1711. if (changed & IEEE80211_CONF_CHANGE_CHANNEL) {
  1712. ret = p54_scan(dev, P54_SCAN_EXIT, 0);
  1713. if (ret)
  1714. goto out;
  1715. }
  1716. out:
  1717. mutex_unlock(&priv->conf_mutex);
  1718. return ret;
  1719. }
  1720. static int p54_config_interface(struct ieee80211_hw *dev,
  1721. struct ieee80211_vif *vif,
  1722. struct ieee80211_if_conf *conf)
  1723. {
  1724. struct p54_common *priv = dev->priv;
  1725. int ret = 0;
  1726. mutex_lock(&priv->conf_mutex);
  1727. if (conf->changed & IEEE80211_IFCC_BSSID) {
  1728. memcpy(priv->bssid, conf->bssid, ETH_ALEN);
  1729. ret = p54_setup_mac(dev);
  1730. if (ret)
  1731. goto out;
  1732. }
  1733. if (conf->changed & IEEE80211_IFCC_BEACON) {
  1734. ret = p54_scan(dev, P54_SCAN_EXIT, 0);
  1735. if (ret)
  1736. goto out;
  1737. ret = p54_setup_mac(dev);
  1738. if (ret)
  1739. goto out;
  1740. ret = p54_beacon_update(dev, vif);
  1741. if (ret)
  1742. goto out;
  1743. ret = p54_set_edcf(dev);
  1744. if (ret)
  1745. goto out;
  1746. }
  1747. ret = p54_set_leds(dev, 1, !is_multicast_ether_addr(priv->bssid), 0);
  1748. out:
  1749. mutex_unlock(&priv->conf_mutex);
  1750. return ret;
  1751. }
  1752. static void p54_configure_filter(struct ieee80211_hw *dev,
  1753. unsigned int changed_flags,
  1754. unsigned int *total_flags,
  1755. int mc_count, struct dev_mc_list *mclist)
  1756. {
  1757. struct p54_common *priv = dev->priv;
  1758. *total_flags &= FIF_PROMISC_IN_BSS |
  1759. FIF_OTHER_BSS |
  1760. (*total_flags & FIF_PROMISC_IN_BSS) ?
  1761. FIF_FCSFAIL : 0;
  1762. priv->filter_flags = *total_flags;
  1763. if (changed_flags & (FIF_PROMISC_IN_BSS | FIF_OTHER_BSS))
  1764. p54_setup_mac(dev);
  1765. }
  1766. static int p54_conf_tx(struct ieee80211_hw *dev, u16 queue,
  1767. const struct ieee80211_tx_queue_params *params)
  1768. {
  1769. struct p54_common *priv = dev->priv;
  1770. int ret;
  1771. mutex_lock(&priv->conf_mutex);
  1772. if ((params) && !(queue > 4)) {
  1773. P54_SET_QUEUE(priv->qos_params[queue], params->aifs,
  1774. params->cw_min, params->cw_max, params->txop);
  1775. ret = p54_set_edcf(dev);
  1776. } else
  1777. ret = -EINVAL;
  1778. mutex_unlock(&priv->conf_mutex);
  1779. return ret;
  1780. }
  1781. static int p54_init_xbow_synth(struct ieee80211_hw *dev)
  1782. {
  1783. struct p54_common *priv = dev->priv;
  1784. struct sk_buff *skb;
  1785. struct p54_xbow_synth *xbow;
  1786. skb = p54_alloc_skb(dev, P54_HDR_FLAG_CONTROL_OPSET, sizeof(*xbow) +
  1787. sizeof(struct p54_hdr),
  1788. P54_CONTROL_TYPE_XBOW_SYNTH_CFG,
  1789. GFP_KERNEL);
  1790. if (!skb)
  1791. return -ENOMEM;
  1792. xbow = (struct p54_xbow_synth *)skb_put(skb, sizeof(*xbow));
  1793. xbow->magic1 = cpu_to_le16(0x1);
  1794. xbow->magic2 = cpu_to_le16(0x2);
  1795. xbow->freq = cpu_to_le16(5390);
  1796. memset(xbow->padding, 0, sizeof(xbow->padding));
  1797. priv->tx(dev, skb);
  1798. return 0;
  1799. }
  1800. static void p54_work(struct work_struct *work)
  1801. {
  1802. struct p54_common *priv = container_of(work, struct p54_common,
  1803. work.work);
  1804. struct ieee80211_hw *dev = priv->hw;
  1805. struct sk_buff *skb;
  1806. if (unlikely(priv->mode == NL80211_IFTYPE_UNSPECIFIED))
  1807. return ;
  1808. /*
  1809. * TODO: walk through tx_queue and do the following tasks
  1810. * 1. initiate bursts.
  1811. * 2. cancel stuck frames / reset the device if necessary.
  1812. */
  1813. skb = p54_alloc_skb(dev, P54_HDR_FLAG_CONTROL, sizeof(struct p54_hdr) +
  1814. sizeof(struct p54_statistics),
  1815. P54_CONTROL_TYPE_STAT_READBACK, GFP_KERNEL);
  1816. if (!skb)
  1817. return ;
  1818. priv->tx(dev, skb);
  1819. }
  1820. static int p54_get_stats(struct ieee80211_hw *dev,
  1821. struct ieee80211_low_level_stats *stats)
  1822. {
  1823. struct p54_common *priv = dev->priv;
  1824. memcpy(stats, &priv->stats, sizeof(*stats));
  1825. return 0;
  1826. }
  1827. static int p54_get_tx_stats(struct ieee80211_hw *dev,
  1828. struct ieee80211_tx_queue_stats *stats)
  1829. {
  1830. struct p54_common *priv = dev->priv;
  1831. memcpy(stats, &priv->tx_stats[P54_QUEUE_DATA],
  1832. sizeof(stats[0]) * dev->queues);
  1833. return 0;
  1834. }
  1835. static void p54_bss_info_changed(struct ieee80211_hw *dev,
  1836. struct ieee80211_vif *vif,
  1837. struct ieee80211_bss_conf *info,
  1838. u32 changed)
  1839. {
  1840. struct p54_common *priv = dev->priv;
  1841. if (changed & BSS_CHANGED_ERP_SLOT) {
  1842. priv->use_short_slot = info->use_short_slot;
  1843. p54_set_edcf(dev);
  1844. }
  1845. if (changed & BSS_CHANGED_BASIC_RATES) {
  1846. if (dev->conf.channel->band == IEEE80211_BAND_5GHZ)
  1847. priv->basic_rate_mask = (info->basic_rates << 4);
  1848. else
  1849. priv->basic_rate_mask = info->basic_rates;
  1850. p54_setup_mac(dev);
  1851. if (priv->fw_var >= 0x500)
  1852. p54_scan(dev, P54_SCAN_EXIT, 0);
  1853. }
  1854. if (changed & BSS_CHANGED_ASSOC) {
  1855. if (info->assoc) {
  1856. priv->aid = info->aid;
  1857. priv->wakeup_timer = info->beacon_int *
  1858. info->dtim_period * 5;
  1859. p54_setup_mac(dev);
  1860. }
  1861. }
  1862. }
  1863. static int p54_set_key(struct ieee80211_hw *dev, enum set_key_cmd cmd,
  1864. struct ieee80211_vif *vif, struct ieee80211_sta *sta,
  1865. struct ieee80211_key_conf *key)
  1866. {
  1867. struct p54_common *priv = dev->priv;
  1868. struct sk_buff *skb;
  1869. struct p54_keycache *rxkey;
  1870. u8 algo = 0;
  1871. if (modparam_nohwcrypt)
  1872. return -EOPNOTSUPP;
  1873. if (cmd == DISABLE_KEY)
  1874. algo = 0;
  1875. else {
  1876. switch (key->alg) {
  1877. case ALG_TKIP:
  1878. if (!(priv->privacy_caps & (BR_DESC_PRIV_CAP_MICHAEL |
  1879. BR_DESC_PRIV_CAP_TKIP)))
  1880. return -EOPNOTSUPP;
  1881. key->flags |= IEEE80211_KEY_FLAG_GENERATE_IV;
  1882. algo = P54_CRYPTO_TKIPMICHAEL;
  1883. break;
  1884. case ALG_WEP:
  1885. if (!(priv->privacy_caps & BR_DESC_PRIV_CAP_WEP))
  1886. return -EOPNOTSUPP;
  1887. key->flags |= IEEE80211_KEY_FLAG_GENERATE_IV;
  1888. algo = P54_CRYPTO_WEP;
  1889. break;
  1890. case ALG_CCMP:
  1891. if (!(priv->privacy_caps & BR_DESC_PRIV_CAP_AESCCMP))
  1892. return -EOPNOTSUPP;
  1893. key->flags |= IEEE80211_KEY_FLAG_GENERATE_IV;
  1894. algo = P54_CRYPTO_AESCCMP;
  1895. break;
  1896. default:
  1897. return -EOPNOTSUPP;
  1898. }
  1899. }
  1900. if (key->keyidx > priv->rx_keycache_size) {
  1901. /*
  1902. * The device supports the choosen algorithm, but the firmware
  1903. * does not provide enough key slots to store all of them.
  1904. * So, incoming frames have to be decoded by the mac80211 stack,
  1905. * but we can still offload encryption for outgoing frames.
  1906. */
  1907. return 0;
  1908. }
  1909. mutex_lock(&priv->conf_mutex);
  1910. skb = p54_alloc_skb(dev, P54_HDR_FLAG_CONTROL_OPSET, sizeof(*rxkey) +
  1911. sizeof(struct p54_hdr), P54_CONTROL_TYPE_RX_KEYCACHE,
  1912. GFP_ATOMIC);
  1913. if (!skb) {
  1914. mutex_unlock(&priv->conf_mutex);
  1915. return -ENOMEM;
  1916. }
  1917. /* TODO: some devices have 4 more free slots for rx keys */
  1918. rxkey = (struct p54_keycache *)skb_put(skb, sizeof(*rxkey));
  1919. rxkey->entry = key->keyidx;
  1920. rxkey->key_id = key->keyidx;
  1921. rxkey->key_type = algo;
  1922. if (sta)
  1923. memcpy(rxkey->mac, sta->addr, ETH_ALEN);
  1924. else
  1925. memset(rxkey->mac, ~0, ETH_ALEN);
  1926. if (key->alg != ALG_TKIP) {
  1927. rxkey->key_len = min((u8)16, key->keylen);
  1928. memcpy(rxkey->key, key->key, rxkey->key_len);
  1929. } else {
  1930. rxkey->key_len = 24;
  1931. memcpy(rxkey->key, key->key, 16);
  1932. memcpy(&(rxkey->key[16]), &(key->key
  1933. [NL80211_TKIP_DATA_OFFSET_RX_MIC_KEY]), 8);
  1934. }
  1935. priv->tx(dev, skb);
  1936. mutex_unlock(&priv->conf_mutex);
  1937. return 0;
  1938. }
  1939. static const struct ieee80211_ops p54_ops = {
  1940. .tx = p54_tx,
  1941. .start = p54_start,
  1942. .stop = p54_stop,
  1943. .add_interface = p54_add_interface,
  1944. .remove_interface = p54_remove_interface,
  1945. .set_tim = p54_set_tim,
  1946. .sta_notify = p54_sta_notify,
  1947. .set_key = p54_set_key,
  1948. .config = p54_config,
  1949. .config_interface = p54_config_interface,
  1950. .bss_info_changed = p54_bss_info_changed,
  1951. .configure_filter = p54_configure_filter,
  1952. .conf_tx = p54_conf_tx,
  1953. .get_stats = p54_get_stats,
  1954. .get_tx_stats = p54_get_tx_stats
  1955. };
  1956. struct ieee80211_hw *p54_init_common(size_t priv_data_len)
  1957. {
  1958. struct ieee80211_hw *dev;
  1959. struct p54_common *priv;
  1960. dev = ieee80211_alloc_hw(priv_data_len, &p54_ops);
  1961. if (!dev)
  1962. return NULL;
  1963. priv = dev->priv;
  1964. priv->hw = dev;
  1965. priv->mode = NL80211_IFTYPE_UNSPECIFIED;
  1966. priv->basic_rate_mask = 0x15f;
  1967. skb_queue_head_init(&priv->tx_queue);
  1968. dev->flags = IEEE80211_HW_RX_INCLUDES_FCS |
  1969. IEEE80211_HW_SIGNAL_DBM |
  1970. IEEE80211_HW_NOISE_DBM;
  1971. dev->wiphy->interface_modes = BIT(NL80211_IFTYPE_STATION) |
  1972. BIT(NL80211_IFTYPE_ADHOC) |
  1973. BIT(NL80211_IFTYPE_AP) |
  1974. BIT(NL80211_IFTYPE_MESH_POINT);
  1975. dev->channel_change_time = 1000; /* TODO: find actual value */
  1976. priv->tx_stats[P54_QUEUE_BEACON].limit = 1;
  1977. priv->tx_stats[P54_QUEUE_FWSCAN].limit = 1;
  1978. priv->tx_stats[P54_QUEUE_MGMT].limit = 3;
  1979. priv->tx_stats[P54_QUEUE_CAB].limit = 3;
  1980. priv->tx_stats[P54_QUEUE_DATA].limit = 5;
  1981. dev->queues = 1;
  1982. priv->noise = -94;
  1983. /*
  1984. * We support at most 8 tries no matter which rate they're at,
  1985. * we cannot support max_rates * max_rate_tries as we set it
  1986. * here, but setting it correctly to 4/2 or so would limit us
  1987. * artificially if the RC algorithm wants just two rates, so
  1988. * let's say 4/7, we'll redistribute it at TX time, see the
  1989. * comments there.
  1990. */
  1991. dev->max_rates = 4;
  1992. dev->max_rate_tries = 7;
  1993. dev->extra_tx_headroom = sizeof(struct p54_hdr) + 4 +
  1994. sizeof(struct p54_tx_data);
  1995. mutex_init(&priv->conf_mutex);
  1996. init_completion(&priv->eeprom_comp);
  1997. INIT_DELAYED_WORK(&priv->work, p54_work);
  1998. return dev;
  1999. }
  2000. EXPORT_SYMBOL_GPL(p54_init_common);
  2001. void p54_free_common(struct ieee80211_hw *dev)
  2002. {
  2003. struct p54_common *priv = dev->priv;
  2004. kfree(priv->iq_autocal);
  2005. kfree(priv->output_limit);
  2006. kfree(priv->curve_data);
  2007. }
  2008. EXPORT_SYMBOL_GPL(p54_free_common);
  2009. static int __init p54_init(void)
  2010. {
  2011. return 0;
  2012. }
  2013. static void __exit p54_exit(void)
  2014. {
  2015. }
  2016. module_init(p54_init);
  2017. module_exit(p54_exit);