p54common.c 59 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217
  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[4].limit = 3; /* AC_VO */
  224. priv->tx_stats[5].limit = 4; /* AC_VI */
  225. priv->tx_stats[6].limit = 3; /* AC_BE */
  226. priv->tx_stats[7].limit = 2; /* AC_BK */
  227. dev->queues = 4;
  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 int p54_parse_eeprom(struct ieee80211_hw *dev, void *eeprom, int len)
  342. {
  343. struct p54_common *priv = dev->priv;
  344. struct eeprom_pda_wrap *wrap = NULL;
  345. struct pda_entry *entry;
  346. unsigned int data_len, entry_len;
  347. void *tmp;
  348. int err;
  349. u8 *end = (u8 *)eeprom + len;
  350. u16 synth = 0;
  351. wrap = (struct eeprom_pda_wrap *) eeprom;
  352. entry = (void *)wrap->data + le16_to_cpu(wrap->len);
  353. /* verify that at least the entry length/code fits */
  354. while ((u8 *)entry <= end - sizeof(*entry)) {
  355. entry_len = le16_to_cpu(entry->len);
  356. data_len = ((entry_len - 1) << 1);
  357. /* abort if entry exceeds whole structure */
  358. if ((u8 *)entry + sizeof(*entry) + data_len > end)
  359. break;
  360. switch (le16_to_cpu(entry->code)) {
  361. case PDR_MAC_ADDRESS:
  362. SET_IEEE80211_PERM_ADDR(dev, entry->data);
  363. break;
  364. case PDR_PRISM_PA_CAL_OUTPUT_POWER_LIMITS:
  365. if (data_len < 2) {
  366. err = -EINVAL;
  367. goto err;
  368. }
  369. if (2 + entry->data[1]*sizeof(*priv->output_limit) > data_len) {
  370. err = -EINVAL;
  371. goto err;
  372. }
  373. priv->output_limit = kmalloc(entry->data[1] *
  374. sizeof(*priv->output_limit), GFP_KERNEL);
  375. if (!priv->output_limit) {
  376. err = -ENOMEM;
  377. goto err;
  378. }
  379. memcpy(priv->output_limit, &entry->data[2],
  380. entry->data[1]*sizeof(*priv->output_limit));
  381. priv->output_limit_len = entry->data[1];
  382. break;
  383. case PDR_PRISM_PA_CAL_CURVE_DATA: {
  384. struct pda_pa_curve_data *curve_data =
  385. (struct pda_pa_curve_data *)entry->data;
  386. if (data_len < sizeof(*curve_data)) {
  387. err = -EINVAL;
  388. goto err;
  389. }
  390. switch (curve_data->cal_method_rev) {
  391. case 0:
  392. err = p54_convert_rev0(dev, curve_data);
  393. break;
  394. case 1:
  395. err = p54_convert_rev1(dev, curve_data);
  396. break;
  397. default:
  398. printk(KERN_ERR "%s: unknown curve data "
  399. "revision %d\n",
  400. wiphy_name(dev->wiphy),
  401. curve_data->cal_method_rev);
  402. err = -ENODEV;
  403. break;
  404. }
  405. if (err)
  406. goto err;
  407. }
  408. case PDR_PRISM_ZIF_TX_IQ_CALIBRATION:
  409. priv->iq_autocal = kmalloc(data_len, GFP_KERNEL);
  410. if (!priv->iq_autocal) {
  411. err = -ENOMEM;
  412. goto err;
  413. }
  414. memcpy(priv->iq_autocal, entry->data, data_len);
  415. priv->iq_autocal_len = data_len / sizeof(struct pda_iq_autocal_entry);
  416. break;
  417. case PDR_INTERFACE_LIST:
  418. tmp = entry->data;
  419. while ((u8 *)tmp < entry->data + data_len) {
  420. struct bootrec_exp_if *exp_if = tmp;
  421. if (le16_to_cpu(exp_if->if_id) == 0xf)
  422. synth = le16_to_cpu(exp_if->variant);
  423. tmp += sizeof(struct bootrec_exp_if);
  424. }
  425. break;
  426. case PDR_HARDWARE_PLATFORM_COMPONENT_ID:
  427. priv->version = *(u8 *)(entry->data + 1);
  428. break;
  429. case PDR_RSSI_LINEAR_APPROXIMATION:
  430. case PDR_RSSI_LINEAR_APPROXIMATION_DUAL_BAND:
  431. case PDR_RSSI_LINEAR_APPROXIMATION_EXTENDED:
  432. p54_parse_rssical(dev, entry->data, data_len,
  433. le16_to_cpu(entry->code));
  434. break;
  435. case PDR_END:
  436. /* make it overrun */
  437. entry_len = len;
  438. break;
  439. case PDR_MANUFACTURING_PART_NUMBER:
  440. case PDR_PDA_VERSION:
  441. case PDR_NIC_SERIAL_NUMBER:
  442. case PDR_REGULATORY_DOMAIN_LIST:
  443. case PDR_TEMPERATURE_TYPE:
  444. case PDR_PRISM_PCI_IDENTIFIER:
  445. case PDR_COUNTRY_INFORMATION:
  446. case PDR_OEM_NAME:
  447. case PDR_PRODUCT_NAME:
  448. case PDR_UTF8_OEM_NAME:
  449. case PDR_UTF8_PRODUCT_NAME:
  450. case PDR_COUNTRY_LIST:
  451. case PDR_DEFAULT_COUNTRY:
  452. case PDR_ANTENNA_GAIN:
  453. case PDR_PRISM_INDIGO_PA_CALIBRATION_DATA:
  454. case PDR_REGULATORY_POWER_LIMITS:
  455. case PDR_RADIATED_TRANSMISSION_CORRECTION:
  456. case PDR_PRISM_TX_IQ_CALIBRATION:
  457. case PDR_BASEBAND_REGISTERS:
  458. case PDR_PER_CHANNEL_BASEBAND_REGISTERS:
  459. break;
  460. default:
  461. printk(KERN_INFO "%s: unknown eeprom code : 0x%x\n",
  462. wiphy_name(dev->wiphy),
  463. le16_to_cpu(entry->code));
  464. break;
  465. }
  466. entry = (void *)entry + (entry_len + 1)*2;
  467. }
  468. if (!synth || !priv->iq_autocal || !priv->output_limit ||
  469. !priv->curve_data) {
  470. printk(KERN_ERR "%s: not all required entries found in eeprom!\n",
  471. wiphy_name(dev->wiphy));
  472. err = -EINVAL;
  473. goto err;
  474. }
  475. priv->rxhw = synth & PDR_SYNTH_FRONTEND_MASK;
  476. if (priv->rxhw == 4)
  477. p54_init_xbow_synth(dev);
  478. if (!(synth & PDR_SYNTH_24_GHZ_DISABLED))
  479. dev->wiphy->bands[IEEE80211_BAND_2GHZ] = &band_2GHz;
  480. if (!(synth & PDR_SYNTH_5_GHZ_DISABLED))
  481. dev->wiphy->bands[IEEE80211_BAND_5GHZ] = &band_5GHz;
  482. if (!is_valid_ether_addr(dev->wiphy->perm_addr)) {
  483. u8 perm_addr[ETH_ALEN];
  484. printk(KERN_WARNING "%s: Invalid hwaddr! Using randomly generated MAC addr\n",
  485. wiphy_name(dev->wiphy));
  486. random_ether_addr(perm_addr);
  487. SET_IEEE80211_PERM_ADDR(dev, perm_addr);
  488. }
  489. printk(KERN_INFO "%s: hwaddr %pM, MAC:isl38%02x RF:%s\n",
  490. wiphy_name(dev->wiphy),
  491. dev->wiphy->perm_addr,
  492. priv->version, p54_rf_chips[priv->rxhw]);
  493. return 0;
  494. err:
  495. if (priv->iq_autocal) {
  496. kfree(priv->iq_autocal);
  497. priv->iq_autocal = NULL;
  498. }
  499. if (priv->output_limit) {
  500. kfree(priv->output_limit);
  501. priv->output_limit = NULL;
  502. }
  503. if (priv->curve_data) {
  504. kfree(priv->curve_data);
  505. priv->curve_data = NULL;
  506. }
  507. printk(KERN_ERR "%s: eeprom parse failed!\n",
  508. wiphy_name(dev->wiphy));
  509. return err;
  510. }
  511. static int p54_rssi_to_dbm(struct ieee80211_hw *dev, int rssi)
  512. {
  513. struct p54_common *priv = dev->priv;
  514. int band = dev->conf.channel->band;
  515. return ((rssi * priv->rssical_db[band].mul) / 64 +
  516. priv->rssical_db[band].add) / 4;
  517. }
  518. static int p54_rx_data(struct ieee80211_hw *dev, struct sk_buff *skb)
  519. {
  520. struct p54_common *priv = dev->priv;
  521. struct p54_rx_data *hdr = (struct p54_rx_data *) skb->data;
  522. struct ieee80211_rx_status rx_status = {0};
  523. u16 freq = le16_to_cpu(hdr->freq);
  524. size_t header_len = sizeof(*hdr);
  525. u32 tsf32;
  526. u8 rate = hdr->rate & 0xf;
  527. /*
  528. * If the device is in a unspecified state we have to
  529. * ignore all data frames. Else we could end up with a
  530. * nasty crash.
  531. */
  532. if (unlikely(priv->mode == NL80211_IFTYPE_UNSPECIFIED))
  533. return 0;
  534. if (!(hdr->flags & cpu_to_le16(P54_HDR_FLAG_DATA_IN_FCS_GOOD))) {
  535. if (priv->filter_flags & FIF_FCSFAIL)
  536. rx_status.flag |= RX_FLAG_FAILED_FCS_CRC;
  537. else
  538. return 0;
  539. }
  540. if (hdr->decrypt_status == P54_DECRYPT_OK)
  541. rx_status.flag |= RX_FLAG_DECRYPTED;
  542. if ((hdr->decrypt_status == P54_DECRYPT_FAIL_MICHAEL) ||
  543. (hdr->decrypt_status == P54_DECRYPT_FAIL_TKIP))
  544. rx_status.flag |= RX_FLAG_MMIC_ERROR;
  545. rx_status.signal = p54_rssi_to_dbm(dev, hdr->rssi);
  546. rx_status.noise = priv->noise;
  547. /* XX correct? */
  548. rx_status.qual = (100 * hdr->rssi) / 127;
  549. if (hdr->rate & 0x10)
  550. rx_status.flag |= RX_FLAG_SHORTPRE;
  551. if (dev->conf.channel->band == IEEE80211_BAND_5GHZ)
  552. rx_status.rate_idx = (rate < 4) ? 0 : rate - 4;
  553. else
  554. rx_status.rate_idx = rate;
  555. rx_status.freq = freq;
  556. rx_status.band = dev->conf.channel->band;
  557. rx_status.antenna = hdr->antenna;
  558. tsf32 = le32_to_cpu(hdr->tsf32);
  559. if (tsf32 < priv->tsf_low32)
  560. priv->tsf_high32++;
  561. rx_status.mactime = ((u64)priv->tsf_high32) << 32 | tsf32;
  562. priv->tsf_low32 = tsf32;
  563. rx_status.flag |= RX_FLAG_TSFT;
  564. if (hdr->flags & cpu_to_le16(P54_HDR_FLAG_DATA_ALIGN))
  565. header_len += hdr->align[0];
  566. skb_pull(skb, header_len);
  567. skb_trim(skb, le16_to_cpu(hdr->len));
  568. ieee80211_rx_irqsafe(dev, skb, &rx_status);
  569. queue_delayed_work(dev->workqueue, &priv->work,
  570. msecs_to_jiffies(P54_STATISTICS_UPDATE));
  571. return -1;
  572. }
  573. static void inline p54_wake_free_queues(struct ieee80211_hw *dev)
  574. {
  575. struct p54_common *priv = dev->priv;
  576. int i;
  577. if (priv->mode == NL80211_IFTYPE_UNSPECIFIED)
  578. return ;
  579. for (i = 0; i < dev->queues; i++)
  580. if (priv->tx_stats[i + 4].len < priv->tx_stats[i + 4].limit)
  581. ieee80211_wake_queue(dev, i);
  582. }
  583. void p54_free_skb(struct ieee80211_hw *dev, struct sk_buff *skb)
  584. {
  585. struct p54_common *priv = dev->priv;
  586. struct ieee80211_tx_info *info;
  587. struct memrecord *range;
  588. unsigned long flags;
  589. u32 freed = 0, last_addr = priv->rx_start;
  590. if (unlikely(!skb || !dev || !skb_queue_len(&priv->tx_queue)))
  591. return;
  592. /*
  593. * don't try to free an already unlinked skb
  594. */
  595. if (unlikely((!skb->next) || (!skb->prev)))
  596. return;
  597. spin_lock_irqsave(&priv->tx_queue.lock, flags);
  598. info = IEEE80211_SKB_CB(skb);
  599. range = (void *)info->rate_driver_data;
  600. if (skb->prev != (struct sk_buff *)&priv->tx_queue) {
  601. struct ieee80211_tx_info *ni;
  602. struct memrecord *mr;
  603. ni = IEEE80211_SKB_CB(skb->prev);
  604. mr = (struct memrecord *)ni->rate_driver_data;
  605. last_addr = mr->end_addr;
  606. }
  607. if (skb->next != (struct sk_buff *)&priv->tx_queue) {
  608. struct ieee80211_tx_info *ni;
  609. struct memrecord *mr;
  610. ni = IEEE80211_SKB_CB(skb->next);
  611. mr = (struct memrecord *)ni->rate_driver_data;
  612. freed = mr->start_addr - last_addr;
  613. } else
  614. freed = priv->rx_end - last_addr;
  615. __skb_unlink(skb, &priv->tx_queue);
  616. spin_unlock_irqrestore(&priv->tx_queue.lock, flags);
  617. dev_kfree_skb_any(skb);
  618. if (freed >= priv->headroom + sizeof(struct p54_hdr) + 48 +
  619. IEEE80211_MAX_RTS_THRESHOLD + priv->tailroom)
  620. p54_wake_free_queues(dev);
  621. }
  622. EXPORT_SYMBOL_GPL(p54_free_skb);
  623. static struct sk_buff *p54_find_tx_entry(struct ieee80211_hw *dev,
  624. __le32 req_id)
  625. {
  626. struct p54_common *priv = dev->priv;
  627. struct sk_buff *entry = priv->tx_queue.next;
  628. unsigned long flags;
  629. spin_lock_irqsave(&priv->tx_queue.lock, flags);
  630. while (entry != (struct sk_buff *)&priv->tx_queue) {
  631. struct p54_hdr *hdr = (struct p54_hdr *) entry->data;
  632. if (hdr->req_id == req_id) {
  633. spin_unlock_irqrestore(&priv->tx_queue.lock, flags);
  634. return entry;
  635. }
  636. entry = entry->next;
  637. }
  638. spin_unlock_irqrestore(&priv->tx_queue.lock, flags);
  639. return NULL;
  640. }
  641. static void p54_rx_frame_sent(struct ieee80211_hw *dev, struct sk_buff *skb)
  642. {
  643. struct p54_common *priv = dev->priv;
  644. struct p54_hdr *hdr = (struct p54_hdr *) skb->data;
  645. struct p54_frame_sent *payload = (struct p54_frame_sent *) hdr->data;
  646. struct sk_buff *entry = (struct sk_buff *) priv->tx_queue.next;
  647. u32 addr = le32_to_cpu(hdr->req_id) - priv->headroom;
  648. struct memrecord *range = NULL;
  649. u32 freed = 0;
  650. u32 last_addr = priv->rx_start;
  651. unsigned long flags;
  652. int count, idx;
  653. spin_lock_irqsave(&priv->tx_queue.lock, flags);
  654. while (entry != (struct sk_buff *)&priv->tx_queue) {
  655. struct ieee80211_tx_info *info = IEEE80211_SKB_CB(entry);
  656. struct p54_hdr *entry_hdr;
  657. struct p54_tx_data *entry_data;
  658. int pad = 0;
  659. range = (void *)info->rate_driver_data;
  660. if (range->start_addr != addr) {
  661. last_addr = range->end_addr;
  662. entry = entry->next;
  663. continue;
  664. }
  665. if (entry->next != (struct sk_buff *)&priv->tx_queue) {
  666. struct ieee80211_tx_info *ni;
  667. struct memrecord *mr;
  668. ni = IEEE80211_SKB_CB(entry->next);
  669. mr = (struct memrecord *)ni->rate_driver_data;
  670. freed = mr->start_addr - last_addr;
  671. } else
  672. freed = priv->rx_end - last_addr;
  673. last_addr = range->end_addr;
  674. __skb_unlink(entry, &priv->tx_queue);
  675. spin_unlock_irqrestore(&priv->tx_queue.lock, flags);
  676. entry_hdr = (struct p54_hdr *) entry->data;
  677. entry_data = (struct p54_tx_data *) entry_hdr->data;
  678. priv->tx_stats[entry_data->hw_queue].len--;
  679. priv->stats.dot11ACKFailureCount += payload->tries - 1;
  680. if (unlikely(entry == priv->cached_beacon)) {
  681. kfree_skb(entry);
  682. priv->cached_beacon = NULL;
  683. goto out;
  684. }
  685. /*
  686. * Clear manually, ieee80211_tx_info_clear_status would
  687. * clear the counts too and we need them.
  688. */
  689. memset(&info->status.ampdu_ack_len, 0,
  690. sizeof(struct ieee80211_tx_info) -
  691. offsetof(struct ieee80211_tx_info, status.ampdu_ack_len));
  692. BUILD_BUG_ON(offsetof(struct ieee80211_tx_info,
  693. status.ampdu_ack_len) != 23);
  694. if (entry_hdr->flags & cpu_to_le16(P54_HDR_FLAG_DATA_ALIGN))
  695. pad = entry_data->align[0];
  696. /* walk through the rates array and adjust the counts */
  697. count = payload->tries;
  698. for (idx = 0; idx < 4; idx++) {
  699. if (count >= info->status.rates[idx].count) {
  700. count -= info->status.rates[idx].count;
  701. } else if (count > 0) {
  702. info->status.rates[idx].count = count;
  703. count = 0;
  704. } else {
  705. info->status.rates[idx].idx = -1;
  706. info->status.rates[idx].count = 0;
  707. }
  708. }
  709. if (!(info->flags & IEEE80211_TX_CTL_NO_ACK) &&
  710. (!payload->status))
  711. info->flags |= IEEE80211_TX_STAT_ACK;
  712. if (payload->status & P54_TX_PSM_CANCELLED)
  713. info->flags |= IEEE80211_TX_STAT_TX_FILTERED;
  714. info->status.ack_signal = p54_rssi_to_dbm(dev,
  715. (int)payload->ack_rssi);
  716. if (entry_data->key_type == P54_CRYPTO_TKIPMICHAEL) {
  717. u8 *iv = (u8 *)(entry_data->align + pad +
  718. entry_data->crypt_offset);
  719. /* Restore the original TKIP IV. */
  720. iv[2] = iv[0];
  721. iv[0] = iv[1];
  722. iv[1] = (iv[0] | 0x20) & 0x7f; /* WEPSeed - 8.3.2.2 */
  723. }
  724. skb_pull(entry, sizeof(*hdr) + pad + sizeof(*entry_data));
  725. ieee80211_tx_status_irqsafe(dev, entry);
  726. goto out;
  727. }
  728. spin_unlock_irqrestore(&priv->tx_queue.lock, flags);
  729. out:
  730. if (freed >= priv->headroom + sizeof(struct p54_hdr) + 48 +
  731. IEEE80211_MAX_RTS_THRESHOLD + priv->tailroom)
  732. p54_wake_free_queues(dev);
  733. }
  734. static void p54_rx_eeprom_readback(struct ieee80211_hw *dev,
  735. struct sk_buff *skb)
  736. {
  737. struct p54_hdr *hdr = (struct p54_hdr *) skb->data;
  738. struct p54_eeprom_lm86 *eeprom = (struct p54_eeprom_lm86 *) hdr->data;
  739. struct p54_common *priv = dev->priv;
  740. if (!priv->eeprom)
  741. return ;
  742. if (priv->fw_var >= 0x509) {
  743. memcpy(priv->eeprom, eeprom->v2.data,
  744. le16_to_cpu(eeprom->v2.len));
  745. } else {
  746. memcpy(priv->eeprom, eeprom->v1.data,
  747. le16_to_cpu(eeprom->v1.len));
  748. }
  749. complete(&priv->eeprom_comp);
  750. }
  751. static void p54_rx_stats(struct ieee80211_hw *dev, struct sk_buff *skb)
  752. {
  753. struct p54_common *priv = dev->priv;
  754. struct p54_hdr *hdr = (struct p54_hdr *) skb->data;
  755. struct p54_statistics *stats = (struct p54_statistics *) hdr->data;
  756. u32 tsf32;
  757. if (unlikely(priv->mode == NL80211_IFTYPE_UNSPECIFIED))
  758. return ;
  759. tsf32 = le32_to_cpu(stats->tsf32);
  760. if (tsf32 < priv->tsf_low32)
  761. priv->tsf_high32++;
  762. priv->tsf_low32 = tsf32;
  763. priv->stats.dot11RTSFailureCount = le32_to_cpu(stats->rts_fail);
  764. priv->stats.dot11RTSSuccessCount = le32_to_cpu(stats->rts_success);
  765. priv->stats.dot11FCSErrorCount = le32_to_cpu(stats->rx_bad_fcs);
  766. priv->noise = p54_rssi_to_dbm(dev, le32_to_cpu(stats->noise));
  767. p54_free_skb(dev, p54_find_tx_entry(dev, hdr->req_id));
  768. }
  769. static void p54_rx_trap(struct ieee80211_hw *dev, struct sk_buff *skb)
  770. {
  771. struct p54_hdr *hdr = (struct p54_hdr *) skb->data;
  772. struct p54_trap *trap = (struct p54_trap *) hdr->data;
  773. u16 event = le16_to_cpu(trap->event);
  774. u16 freq = le16_to_cpu(trap->frequency);
  775. switch (event) {
  776. case P54_TRAP_BEACON_TX:
  777. break;
  778. case P54_TRAP_RADAR:
  779. printk(KERN_INFO "%s: radar (freq:%d MHz)\n",
  780. wiphy_name(dev->wiphy), freq);
  781. break;
  782. case P54_TRAP_NO_BEACON:
  783. break;
  784. case P54_TRAP_SCAN:
  785. break;
  786. case P54_TRAP_TBTT:
  787. break;
  788. case P54_TRAP_TIMER:
  789. break;
  790. default:
  791. printk(KERN_INFO "%s: received event:%x freq:%d\n",
  792. wiphy_name(dev->wiphy), event, freq);
  793. break;
  794. }
  795. }
  796. static int p54_rx_control(struct ieee80211_hw *dev, struct sk_buff *skb)
  797. {
  798. struct p54_hdr *hdr = (struct p54_hdr *) skb->data;
  799. switch (le16_to_cpu(hdr->type)) {
  800. case P54_CONTROL_TYPE_TXDONE:
  801. p54_rx_frame_sent(dev, skb);
  802. break;
  803. case P54_CONTROL_TYPE_TRAP:
  804. p54_rx_trap(dev, skb);
  805. break;
  806. case P54_CONTROL_TYPE_BBP:
  807. break;
  808. case P54_CONTROL_TYPE_STAT_READBACK:
  809. p54_rx_stats(dev, skb);
  810. break;
  811. case P54_CONTROL_TYPE_EEPROM_READBACK:
  812. p54_rx_eeprom_readback(dev, skb);
  813. break;
  814. default:
  815. printk(KERN_DEBUG "%s: not handling 0x%02x type control frame\n",
  816. wiphy_name(dev->wiphy), le16_to_cpu(hdr->type));
  817. break;
  818. }
  819. return 0;
  820. }
  821. /* returns zero if skb can be reused */
  822. int p54_rx(struct ieee80211_hw *dev, struct sk_buff *skb)
  823. {
  824. u16 type = le16_to_cpu(*((__le16 *)skb->data));
  825. if (type & P54_HDR_FLAG_CONTROL)
  826. return p54_rx_control(dev, skb);
  827. else
  828. return p54_rx_data(dev, skb);
  829. }
  830. EXPORT_SYMBOL_GPL(p54_rx);
  831. /*
  832. * So, the firmware is somewhat stupid and doesn't know what places in its
  833. * memory incoming data should go to. By poking around in the firmware, we
  834. * can find some unused memory to upload our packets to. However, data that we
  835. * want the card to TX needs to stay intact until the card has told us that
  836. * it is done with it. This function finds empty places we can upload to and
  837. * marks allocated areas as reserved if necessary. p54_rx_frame_sent frees
  838. * allocated areas.
  839. */
  840. static int p54_assign_address(struct ieee80211_hw *dev, struct sk_buff *skb,
  841. struct p54_hdr *data, u32 len)
  842. {
  843. struct p54_common *priv = dev->priv;
  844. struct sk_buff *entry = priv->tx_queue.next;
  845. struct sk_buff *target_skb = NULL;
  846. struct ieee80211_tx_info *info;
  847. struct memrecord *range;
  848. u32 last_addr = priv->rx_start;
  849. u32 largest_hole = 0;
  850. u32 target_addr = priv->rx_start;
  851. unsigned long flags;
  852. unsigned int left;
  853. len = (len + priv->headroom + priv->tailroom + 3) & ~0x3;
  854. if (!skb)
  855. return -EINVAL;
  856. spin_lock_irqsave(&priv->tx_queue.lock, flags);
  857. left = skb_queue_len(&priv->tx_queue);
  858. if (unlikely(left >= 28)) {
  859. /*
  860. * The tx_queue is nearly full!
  861. * We have throttle normal data traffic, because we must
  862. * have a few spare slots for control frames left.
  863. */
  864. ieee80211_stop_queues(dev);
  865. queue_delayed_work(dev->workqueue, &priv->work,
  866. msecs_to_jiffies(P54_TX_TIMEOUT));
  867. if (unlikely(left == 32)) {
  868. /*
  869. * The tx_queue is now really full.
  870. *
  871. * TODO: check if the device has crashed and reset it.
  872. */
  873. spin_unlock_irqrestore(&priv->tx_queue.lock, flags);
  874. return -ENOSPC;
  875. }
  876. }
  877. while (left--) {
  878. u32 hole_size;
  879. info = IEEE80211_SKB_CB(entry);
  880. range = (void *)info->rate_driver_data;
  881. hole_size = range->start_addr - last_addr;
  882. if (!target_skb && hole_size >= len) {
  883. target_skb = entry->prev;
  884. hole_size -= len;
  885. target_addr = last_addr;
  886. }
  887. largest_hole = max(largest_hole, hole_size);
  888. last_addr = range->end_addr;
  889. entry = entry->next;
  890. }
  891. if (!target_skb && priv->rx_end - last_addr >= len) {
  892. target_skb = priv->tx_queue.prev;
  893. largest_hole = max(largest_hole, priv->rx_end - last_addr - len);
  894. if (!skb_queue_empty(&priv->tx_queue)) {
  895. info = IEEE80211_SKB_CB(target_skb);
  896. range = (void *)info->rate_driver_data;
  897. target_addr = range->end_addr;
  898. }
  899. } else
  900. largest_hole = max(largest_hole, priv->rx_end - last_addr);
  901. if (!target_skb) {
  902. spin_unlock_irqrestore(&priv->tx_queue.lock, flags);
  903. ieee80211_stop_queues(dev);
  904. return -ENOSPC;
  905. }
  906. info = IEEE80211_SKB_CB(skb);
  907. range = (void *)info->rate_driver_data;
  908. range->start_addr = target_addr;
  909. range->end_addr = target_addr + len;
  910. __skb_queue_after(&priv->tx_queue, target_skb, skb);
  911. spin_unlock_irqrestore(&priv->tx_queue.lock, flags);
  912. if (largest_hole < priv->headroom + sizeof(struct p54_hdr) +
  913. 48 + IEEE80211_MAX_RTS_THRESHOLD + priv->tailroom)
  914. ieee80211_stop_queues(dev);
  915. data->req_id = cpu_to_le32(target_addr + priv->headroom);
  916. return 0;
  917. }
  918. static struct sk_buff *p54_alloc_skb(struct ieee80211_hw *dev,
  919. u16 hdr_flags, u16 len, u16 type, gfp_t memflags)
  920. {
  921. struct p54_common *priv = dev->priv;
  922. struct p54_hdr *hdr;
  923. struct sk_buff *skb;
  924. skb = __dev_alloc_skb(len + priv->tx_hdr_len, memflags);
  925. if (!skb)
  926. return NULL;
  927. skb_reserve(skb, priv->tx_hdr_len);
  928. hdr = (struct p54_hdr *) skb_put(skb, sizeof(*hdr));
  929. hdr->flags = cpu_to_le16(hdr_flags);
  930. hdr->len = cpu_to_le16(len - sizeof(*hdr));
  931. hdr->type = cpu_to_le16(type);
  932. hdr->tries = hdr->rts_tries = 0;
  933. if (unlikely(p54_assign_address(dev, skb, hdr, len))) {
  934. kfree_skb(skb);
  935. return NULL;
  936. }
  937. return skb;
  938. }
  939. int p54_read_eeprom(struct ieee80211_hw *dev)
  940. {
  941. struct p54_common *priv = dev->priv;
  942. struct p54_hdr *hdr = NULL;
  943. struct p54_eeprom_lm86 *eeprom_hdr;
  944. struct sk_buff *skb;
  945. size_t eeprom_size = 0x2020, offset = 0, blocksize, maxblocksize;
  946. int ret = -ENOMEM;
  947. void *eeprom = NULL;
  948. maxblocksize = EEPROM_READBACK_LEN;
  949. if (priv->fw_var >= 0x509)
  950. maxblocksize -= 0xc;
  951. else
  952. maxblocksize -= 0x4;
  953. skb = p54_alloc_skb(dev, P54_HDR_FLAG_CONTROL, sizeof(*hdr) +
  954. sizeof(*eeprom_hdr) + maxblocksize,
  955. P54_CONTROL_TYPE_EEPROM_READBACK, GFP_KERNEL);
  956. if (!skb)
  957. goto free;
  958. priv->eeprom = kzalloc(EEPROM_READBACK_LEN, GFP_KERNEL);
  959. if (!priv->eeprom)
  960. goto free;
  961. eeprom = kzalloc(eeprom_size, GFP_KERNEL);
  962. if (!eeprom)
  963. goto free;
  964. eeprom_hdr = (struct p54_eeprom_lm86 *) skb_put(skb,
  965. sizeof(*eeprom_hdr) + maxblocksize);
  966. while (eeprom_size) {
  967. blocksize = min(eeprom_size, maxblocksize);
  968. if (priv->fw_var < 0x509) {
  969. eeprom_hdr->v1.offset = cpu_to_le16(offset);
  970. eeprom_hdr->v1.len = cpu_to_le16(blocksize);
  971. } else {
  972. eeprom_hdr->v2.offset = cpu_to_le32(offset);
  973. eeprom_hdr->v2.len = cpu_to_le16(blocksize);
  974. eeprom_hdr->v2.magic2 = 0xf;
  975. memcpy(eeprom_hdr->v2.magic, (const char *)"LOCK", 4);
  976. }
  977. priv->tx(dev, skb);
  978. if (!wait_for_completion_interruptible_timeout(&priv->eeprom_comp, HZ)) {
  979. printk(KERN_ERR "%s: device does not respond!\n",
  980. wiphy_name(dev->wiphy));
  981. ret = -EBUSY;
  982. goto free;
  983. }
  984. memcpy(eeprom + offset, priv->eeprom, blocksize);
  985. offset += blocksize;
  986. eeprom_size -= blocksize;
  987. }
  988. ret = p54_parse_eeprom(dev, eeprom, offset);
  989. free:
  990. kfree(priv->eeprom);
  991. priv->eeprom = NULL;
  992. p54_free_skb(dev, skb);
  993. kfree(eeprom);
  994. return ret;
  995. }
  996. EXPORT_SYMBOL_GPL(p54_read_eeprom);
  997. static int p54_set_tim(struct ieee80211_hw *dev, struct ieee80211_sta *sta,
  998. bool set)
  999. {
  1000. struct p54_common *priv = dev->priv;
  1001. struct sk_buff *skb;
  1002. struct p54_tim *tim;
  1003. skb = p54_alloc_skb(dev, P54_HDR_FLAG_CONTROL_OPSET,
  1004. sizeof(struct p54_hdr) + sizeof(*tim),
  1005. P54_CONTROL_TYPE_TIM, GFP_KERNEL);
  1006. if (!skb)
  1007. return -ENOMEM;
  1008. tim = (struct p54_tim *) skb_put(skb, sizeof(*tim));
  1009. tim->count = 1;
  1010. tim->entry[0] = cpu_to_le16(set ? (sta->aid | 0x8000) : sta->aid);
  1011. priv->tx(dev, skb);
  1012. return 0;
  1013. }
  1014. static int p54_sta_unlock(struct ieee80211_hw *dev, u8 *addr)
  1015. {
  1016. struct p54_common *priv = dev->priv;
  1017. struct sk_buff *skb;
  1018. struct p54_sta_unlock *sta;
  1019. skb = p54_alloc_skb(dev, P54_HDR_FLAG_CONTROL_OPSET,
  1020. sizeof(struct p54_hdr) + sizeof(*sta),
  1021. P54_CONTROL_TYPE_PSM_STA_UNLOCK, GFP_ATOMIC);
  1022. if (!skb)
  1023. return -ENOMEM;
  1024. sta = (struct p54_sta_unlock *)skb_put(skb, sizeof(*sta));
  1025. memcpy(sta->addr, addr, ETH_ALEN);
  1026. priv->tx(dev, skb);
  1027. return 0;
  1028. }
  1029. static void p54_sta_notify(struct ieee80211_hw *dev, struct ieee80211_vif *vif,
  1030. enum sta_notify_cmd notify_cmd,
  1031. struct ieee80211_sta *sta)
  1032. {
  1033. switch (notify_cmd) {
  1034. case STA_NOTIFY_ADD:
  1035. case STA_NOTIFY_REMOVE:
  1036. /*
  1037. * Notify the firmware that we don't want or we don't
  1038. * need to buffer frames for this station anymore.
  1039. */
  1040. p54_sta_unlock(dev, sta->addr);
  1041. break;
  1042. case STA_NOTIFY_AWAKE:
  1043. /* update the firmware's filter table */
  1044. p54_sta_unlock(dev, sta->addr);
  1045. break;
  1046. default:
  1047. break;
  1048. }
  1049. }
  1050. static int p54_tx_cancel(struct ieee80211_hw *dev, struct sk_buff *entry)
  1051. {
  1052. struct p54_common *priv = dev->priv;
  1053. struct sk_buff *skb;
  1054. struct p54_hdr *hdr;
  1055. struct p54_txcancel *cancel;
  1056. skb = p54_alloc_skb(dev, P54_HDR_FLAG_CONTROL_OPSET,
  1057. sizeof(struct p54_hdr) + sizeof(*cancel),
  1058. P54_CONTROL_TYPE_TXCANCEL, GFP_ATOMIC);
  1059. if (!skb)
  1060. return -ENOMEM;
  1061. hdr = (void *)entry->data;
  1062. cancel = (struct p54_txcancel *)skb_put(skb, sizeof(*cancel));
  1063. cancel->req_id = hdr->req_id;
  1064. priv->tx(dev, skb);
  1065. return 0;
  1066. }
  1067. static int p54_tx_fill(struct ieee80211_hw *dev, struct sk_buff *skb,
  1068. struct ieee80211_tx_info *info, u8 *queue, size_t *extra_len,
  1069. u16 *flags, u16 *aid)
  1070. {
  1071. struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
  1072. struct p54_common *priv = dev->priv;
  1073. int ret = 0;
  1074. if (unlikely(ieee80211_is_mgmt(hdr->frame_control))) {
  1075. if (ieee80211_is_beacon(hdr->frame_control)) {
  1076. *aid = 0;
  1077. *queue = 0;
  1078. *extra_len = IEEE80211_MAX_TIM_LEN;
  1079. *flags = P54_HDR_FLAG_DATA_OUT_TIMESTAMP;
  1080. return 0;
  1081. } else if (ieee80211_is_probe_resp(hdr->frame_control)) {
  1082. *aid = 0;
  1083. *queue = 2;
  1084. *flags = P54_HDR_FLAG_DATA_OUT_TIMESTAMP |
  1085. P54_HDR_FLAG_DATA_OUT_NOCANCEL;
  1086. return 0;
  1087. } else {
  1088. *queue = 2;
  1089. ret = 0;
  1090. }
  1091. } else {
  1092. *queue += 4;
  1093. ret = 1;
  1094. }
  1095. switch (priv->mode) {
  1096. case NL80211_IFTYPE_STATION:
  1097. *aid = 1;
  1098. break;
  1099. case NL80211_IFTYPE_AP:
  1100. case NL80211_IFTYPE_ADHOC:
  1101. case NL80211_IFTYPE_MESH_POINT:
  1102. if (info->flags & IEEE80211_TX_CTL_SEND_AFTER_DTIM) {
  1103. *aid = 0;
  1104. *queue = 3;
  1105. return 0;
  1106. }
  1107. if (info->control.sta)
  1108. *aid = info->control.sta->aid;
  1109. else
  1110. *flags |= P54_HDR_FLAG_DATA_OUT_NOCANCEL;
  1111. }
  1112. return ret;
  1113. }
  1114. static u8 p54_convert_algo(enum ieee80211_key_alg alg)
  1115. {
  1116. switch (alg) {
  1117. case ALG_WEP:
  1118. return P54_CRYPTO_WEP;
  1119. case ALG_TKIP:
  1120. return P54_CRYPTO_TKIPMICHAEL;
  1121. case ALG_CCMP:
  1122. return P54_CRYPTO_AESCCMP;
  1123. default:
  1124. return 0;
  1125. }
  1126. }
  1127. static int p54_tx(struct ieee80211_hw *dev, struct sk_buff *skb)
  1128. {
  1129. struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
  1130. struct ieee80211_tx_queue_stats *current_queue = NULL;
  1131. struct p54_common *priv = dev->priv;
  1132. struct p54_hdr *hdr;
  1133. struct p54_tx_data *txhdr;
  1134. size_t padding, len, tim_len = 0;
  1135. int i, j, ridx, ret;
  1136. u16 hdr_flags = 0, aid = 0;
  1137. u8 rate, queue, crypt_offset = 0;
  1138. u8 cts_rate = 0x20;
  1139. u8 rc_flags;
  1140. u8 calculated_tries[4];
  1141. u8 nrates = 0, nremaining = 8;
  1142. queue = skb_get_queue_mapping(skb);
  1143. ret = p54_tx_fill(dev, skb, info, &queue, &tim_len, &hdr_flags, &aid);
  1144. current_queue = &priv->tx_stats[queue];
  1145. if (unlikely((current_queue->len > current_queue->limit) && ret))
  1146. return NETDEV_TX_BUSY;
  1147. current_queue->len++;
  1148. current_queue->count++;
  1149. if ((current_queue->len == current_queue->limit) && ret)
  1150. ieee80211_stop_queue(dev, skb_get_queue_mapping(skb));
  1151. padding = (unsigned long)(skb->data - (sizeof(*hdr) + sizeof(*txhdr))) & 3;
  1152. len = skb->len;
  1153. if (info->control.hw_key) {
  1154. crypt_offset = ieee80211_get_hdrlen_from_skb(skb);
  1155. if (info->control.hw_key->alg == ALG_TKIP) {
  1156. u8 *iv = (u8 *)(skb->data + crypt_offset);
  1157. /*
  1158. * The firmware excepts that the IV has to have
  1159. * this special format
  1160. */
  1161. iv[1] = iv[0];
  1162. iv[0] = iv[2];
  1163. iv[2] = 0;
  1164. }
  1165. }
  1166. txhdr = (struct p54_tx_data *) skb_push(skb, sizeof(*txhdr) + padding);
  1167. hdr = (struct p54_hdr *) skb_push(skb, sizeof(*hdr));
  1168. if (padding)
  1169. hdr_flags |= P54_HDR_FLAG_DATA_ALIGN;
  1170. hdr->type = cpu_to_le16(aid);
  1171. hdr->rts_tries = info->control.rates[0].count;
  1172. /*
  1173. * we register the rates in perfect order, and
  1174. * RTS/CTS won't happen on 5 GHz
  1175. */
  1176. cts_rate = info->control.rts_cts_rate_idx;
  1177. memset(&txhdr->rateset, 0, sizeof(txhdr->rateset));
  1178. /* see how many rates got used */
  1179. for (i = 0; i < 4; i++) {
  1180. if (info->control.rates[i].idx < 0)
  1181. break;
  1182. nrates++;
  1183. }
  1184. /* limit tries to 8/nrates per rate */
  1185. for (i = 0; i < nrates; i++) {
  1186. /*
  1187. * The magic expression here is equivalent to 8/nrates for
  1188. * all values that matter, but avoids division and jumps.
  1189. * Note that nrates can only take the values 1 through 4.
  1190. */
  1191. calculated_tries[i] = min_t(int, ((15 >> nrates) | 1) + 1,
  1192. info->control.rates[i].count);
  1193. nremaining -= calculated_tries[i];
  1194. }
  1195. /* if there are tries left, distribute from back to front */
  1196. for (i = nrates - 1; nremaining > 0 && i >= 0; i--) {
  1197. int tmp = info->control.rates[i].count - calculated_tries[i];
  1198. if (tmp <= 0)
  1199. continue;
  1200. /* RC requested more tries at this rate */
  1201. tmp = min_t(int, tmp, nremaining);
  1202. calculated_tries[i] += tmp;
  1203. nremaining -= tmp;
  1204. }
  1205. ridx = 0;
  1206. for (i = 0; i < nrates && ridx < 8; i++) {
  1207. /* we register the rates in perfect order */
  1208. rate = info->control.rates[i].idx;
  1209. if (info->band == IEEE80211_BAND_5GHZ)
  1210. rate += 4;
  1211. /* store the count we actually calculated for TX status */
  1212. info->control.rates[i].count = calculated_tries[i];
  1213. rc_flags = info->control.rates[i].flags;
  1214. if (rc_flags & IEEE80211_TX_RC_USE_SHORT_PREAMBLE) {
  1215. rate |= 0x10;
  1216. cts_rate |= 0x10;
  1217. }
  1218. if (rc_flags & IEEE80211_TX_RC_USE_RTS_CTS)
  1219. rate |= 0x40;
  1220. else if (rc_flags & IEEE80211_TX_RC_USE_CTS_PROTECT)
  1221. rate |= 0x20;
  1222. for (j = 0; j < calculated_tries[i] && ridx < 8; j++) {
  1223. txhdr->rateset[ridx] = rate;
  1224. ridx++;
  1225. }
  1226. }
  1227. if (info->flags & IEEE80211_TX_CTL_ASSIGN_SEQ)
  1228. hdr_flags |= P54_HDR_FLAG_DATA_OUT_SEQNR;
  1229. /* TODO: enable bursting */
  1230. hdr->flags = cpu_to_le16(hdr_flags);
  1231. hdr->tries = ridx;
  1232. txhdr->rts_rate_idx = 0;
  1233. if (info->control.hw_key) {
  1234. txhdr->key_type = p54_convert_algo(info->control.hw_key->alg);
  1235. txhdr->key_len = min((u8)16, info->control.hw_key->keylen);
  1236. memcpy(txhdr->key, info->control.hw_key->key, txhdr->key_len);
  1237. if (info->control.hw_key->alg == ALG_TKIP) {
  1238. if (unlikely(skb_tailroom(skb) < 12))
  1239. goto err;
  1240. /* reserve space for the MIC key */
  1241. len += 8;
  1242. memcpy(skb_put(skb, 8), &(info->control.hw_key->key
  1243. [NL80211_TKIP_DATA_OFFSET_TX_MIC_KEY]), 8);
  1244. }
  1245. /* reserve some space for ICV */
  1246. len += info->control.hw_key->icv_len;
  1247. memset(skb_put(skb, info->control.hw_key->icv_len), 0,
  1248. info->control.hw_key->icv_len);
  1249. } else {
  1250. txhdr->key_type = 0;
  1251. txhdr->key_len = 0;
  1252. }
  1253. txhdr->crypt_offset = crypt_offset;
  1254. txhdr->hw_queue = queue;
  1255. if (current_queue)
  1256. txhdr->backlog = current_queue->len;
  1257. else
  1258. txhdr->backlog = 0;
  1259. memset(txhdr->durations, 0, sizeof(txhdr->durations));
  1260. txhdr->tx_antenna = (info->antenna_sel_tx == 0) ?
  1261. 2 : info->antenna_sel_tx - 1;
  1262. txhdr->output_power = priv->output_power;
  1263. txhdr->cts_rate = cts_rate;
  1264. if (padding)
  1265. txhdr->align[0] = padding;
  1266. hdr->len = cpu_to_le16(len);
  1267. /* modifies skb->cb and with it info, so must be last! */
  1268. if (unlikely(p54_assign_address(dev, skb, hdr, skb->len + tim_len)))
  1269. goto err;
  1270. priv->tx(dev, skb);
  1271. queue_delayed_work(dev->workqueue, &priv->work,
  1272. msecs_to_jiffies(P54_TX_FRAME_LIFETIME));
  1273. return 0;
  1274. err:
  1275. skb_pull(skb, sizeof(*hdr) + sizeof(*txhdr) + padding);
  1276. if (current_queue) {
  1277. current_queue->len--;
  1278. current_queue->count--;
  1279. }
  1280. return NETDEV_TX_BUSY;
  1281. }
  1282. static int p54_setup_mac(struct ieee80211_hw *dev)
  1283. {
  1284. struct p54_common *priv = dev->priv;
  1285. struct sk_buff *skb;
  1286. struct p54_setup_mac *setup;
  1287. u16 mode;
  1288. skb = p54_alloc_skb(dev, P54_HDR_FLAG_CONTROL_OPSET, sizeof(*setup) +
  1289. sizeof(struct p54_hdr), P54_CONTROL_TYPE_SETUP,
  1290. GFP_ATOMIC);
  1291. if (!skb)
  1292. return -ENOMEM;
  1293. setup = (struct p54_setup_mac *) skb_put(skb, sizeof(*setup));
  1294. if (dev->conf.radio_enabled) {
  1295. switch (priv->mode) {
  1296. case NL80211_IFTYPE_STATION:
  1297. mode = P54_FILTER_TYPE_STATION;
  1298. break;
  1299. case NL80211_IFTYPE_AP:
  1300. mode = P54_FILTER_TYPE_AP;
  1301. break;
  1302. case NL80211_IFTYPE_ADHOC:
  1303. case NL80211_IFTYPE_MESH_POINT:
  1304. mode = P54_FILTER_TYPE_IBSS;
  1305. break;
  1306. default:
  1307. mode = P54_FILTER_TYPE_NONE;
  1308. break;
  1309. }
  1310. if (priv->filter_flags & FIF_PROMISC_IN_BSS)
  1311. mode |= P54_FILTER_TYPE_TRANSPARENT;
  1312. } else
  1313. mode = P54_FILTER_TYPE_RX_DISABLED;
  1314. setup->mac_mode = cpu_to_le16(mode);
  1315. memcpy(setup->mac_addr, priv->mac_addr, ETH_ALEN);
  1316. memcpy(setup->bssid, priv->bssid, ETH_ALEN);
  1317. setup->rx_antenna = 2; /* automatic */
  1318. setup->rx_align = 0;
  1319. if (priv->fw_var < 0x500) {
  1320. setup->v1.basic_rate_mask = cpu_to_le32(priv->basic_rate_mask);
  1321. memset(setup->v1.rts_rates, 0, 8);
  1322. setup->v1.rx_addr = cpu_to_le32(priv->rx_end);
  1323. setup->v1.max_rx = cpu_to_le16(priv->rx_mtu);
  1324. setup->v1.rxhw = cpu_to_le16(priv->rxhw);
  1325. setup->v1.wakeup_timer = cpu_to_le16(priv->wakeup_timer);
  1326. setup->v1.unalloc0 = cpu_to_le16(0);
  1327. } else {
  1328. setup->v2.rx_addr = cpu_to_le32(priv->rx_end);
  1329. setup->v2.max_rx = cpu_to_le16(priv->rx_mtu);
  1330. setup->v2.rxhw = cpu_to_le16(priv->rxhw);
  1331. setup->v2.timer = cpu_to_le16(priv->wakeup_timer);
  1332. setup->v2.truncate = cpu_to_le16(48896);
  1333. setup->v2.basic_rate_mask = cpu_to_le32(priv->basic_rate_mask);
  1334. setup->v2.sbss_offset = 0;
  1335. setup->v2.mcast_window = 0;
  1336. setup->v2.rx_rssi_threshold = 0;
  1337. setup->v2.rx_ed_threshold = 0;
  1338. setup->v2.ref_clock = cpu_to_le32(644245094);
  1339. setup->v2.lpf_bandwidth = cpu_to_le16(65535);
  1340. setup->v2.osc_start_delay = cpu_to_le16(65535);
  1341. }
  1342. priv->tx(dev, skb);
  1343. return 0;
  1344. }
  1345. static int p54_scan(struct ieee80211_hw *dev, u16 mode, u16 dwell)
  1346. {
  1347. struct p54_common *priv = dev->priv;
  1348. struct sk_buff *skb;
  1349. struct p54_scan *chan;
  1350. unsigned int i;
  1351. void *entry;
  1352. __le16 freq = cpu_to_le16(dev->conf.channel->center_freq);
  1353. int band = dev->conf.channel->band;
  1354. skb = p54_alloc_skb(dev, P54_HDR_FLAG_CONTROL_OPSET, sizeof(*chan) +
  1355. sizeof(struct p54_hdr), P54_CONTROL_TYPE_SCAN,
  1356. GFP_ATOMIC);
  1357. if (!skb)
  1358. return -ENOMEM;
  1359. chan = (struct p54_scan *) skb_put(skb, sizeof(*chan));
  1360. memset(chan->padding1, 0, sizeof(chan->padding1));
  1361. chan->mode = cpu_to_le16(mode);
  1362. chan->dwell = cpu_to_le16(dwell);
  1363. for (i = 0; i < priv->iq_autocal_len; i++) {
  1364. if (priv->iq_autocal[i].freq != freq)
  1365. continue;
  1366. memcpy(&chan->iq_autocal, &priv->iq_autocal[i],
  1367. sizeof(*priv->iq_autocal));
  1368. break;
  1369. }
  1370. if (i == priv->iq_autocal_len)
  1371. goto err;
  1372. for (i = 0; i < priv->output_limit_len; i++) {
  1373. if (priv->output_limit[i].freq != freq)
  1374. continue;
  1375. chan->val_barker = 0x38;
  1376. chan->val_bpsk = chan->dup_bpsk =
  1377. priv->output_limit[i].val_bpsk;
  1378. chan->val_qpsk = chan->dup_qpsk =
  1379. priv->output_limit[i].val_qpsk;
  1380. chan->val_16qam = chan->dup_16qam =
  1381. priv->output_limit[i].val_16qam;
  1382. chan->val_64qam = chan->dup_64qam =
  1383. priv->output_limit[i].val_64qam;
  1384. break;
  1385. }
  1386. if (i == priv->output_limit_len)
  1387. goto err;
  1388. entry = priv->curve_data->data;
  1389. for (i = 0; i < priv->curve_data->channels; i++) {
  1390. if (*((__le16 *)entry) != freq) {
  1391. entry += sizeof(__le16);
  1392. entry += sizeof(struct p54_pa_curve_data_sample) *
  1393. priv->curve_data->points_per_channel;
  1394. continue;
  1395. }
  1396. entry += sizeof(__le16);
  1397. chan->pa_points_per_curve = 8;
  1398. memset(chan->curve_data, 0, sizeof(*chan->curve_data));
  1399. memcpy(chan->curve_data, entry,
  1400. sizeof(struct p54_pa_curve_data_sample) *
  1401. min((u8)8, priv->curve_data->points_per_channel));
  1402. break;
  1403. }
  1404. if (priv->fw_var < 0x500) {
  1405. chan->v1_rssi.mul = cpu_to_le16(priv->rssical_db[band].mul);
  1406. chan->v1_rssi.add = cpu_to_le16(priv->rssical_db[band].add);
  1407. } else {
  1408. chan->v2.rssi.mul = cpu_to_le16(priv->rssical_db[band].mul);
  1409. chan->v2.rssi.add = cpu_to_le16(priv->rssical_db[band].add);
  1410. chan->v2.basic_rate_mask = cpu_to_le32(priv->basic_rate_mask);
  1411. memset(chan->v2.rts_rates, 0, 8);
  1412. }
  1413. priv->tx(dev, skb);
  1414. return 0;
  1415. err:
  1416. printk(KERN_ERR "%s: frequency change failed\n", wiphy_name(dev->wiphy));
  1417. kfree_skb(skb);
  1418. return -EINVAL;
  1419. }
  1420. static int p54_set_leds(struct ieee80211_hw *dev, int mode, int link, int act)
  1421. {
  1422. struct p54_common *priv = dev->priv;
  1423. struct sk_buff *skb;
  1424. struct p54_led *led;
  1425. skb = p54_alloc_skb(dev, P54_HDR_FLAG_CONTROL_OPSET, sizeof(*led) +
  1426. sizeof(struct p54_hdr), P54_CONTROL_TYPE_LED,
  1427. GFP_ATOMIC);
  1428. if (!skb)
  1429. return -ENOMEM;
  1430. led = (struct p54_led *)skb_put(skb, sizeof(*led));
  1431. led->mode = cpu_to_le16(mode);
  1432. led->led_permanent = cpu_to_le16(link);
  1433. led->led_temporary = cpu_to_le16(act);
  1434. led->duration = cpu_to_le16(1000);
  1435. priv->tx(dev, skb);
  1436. return 0;
  1437. }
  1438. #define P54_SET_QUEUE(queue, ai_fs, cw_min, cw_max, _txop) \
  1439. do { \
  1440. queue.aifs = cpu_to_le16(ai_fs); \
  1441. queue.cwmin = cpu_to_le16(cw_min); \
  1442. queue.cwmax = cpu_to_le16(cw_max); \
  1443. queue.txop = cpu_to_le16(_txop); \
  1444. } while(0)
  1445. static int p54_set_edcf(struct ieee80211_hw *dev)
  1446. {
  1447. struct p54_common *priv = dev->priv;
  1448. struct sk_buff *skb;
  1449. struct p54_edcf *edcf;
  1450. skb = p54_alloc_skb(dev, P54_HDR_FLAG_CONTROL_OPSET, sizeof(*edcf) +
  1451. sizeof(struct p54_hdr), P54_CONTROL_TYPE_DCFINIT,
  1452. GFP_ATOMIC);
  1453. if (!skb)
  1454. return -ENOMEM;
  1455. edcf = (struct p54_edcf *)skb_put(skb, sizeof(*edcf));
  1456. if (priv->use_short_slot) {
  1457. edcf->slottime = 9;
  1458. edcf->sifs = 0x10;
  1459. edcf->eofpad = 0x00;
  1460. } else {
  1461. edcf->slottime = 20;
  1462. edcf->sifs = 0x0a;
  1463. edcf->eofpad = 0x06;
  1464. }
  1465. /* (see prism54/isl_oid.h for further details) */
  1466. edcf->frameburst = cpu_to_le16(0);
  1467. edcf->round_trip_delay = cpu_to_le16(0);
  1468. edcf->flags = 0;
  1469. memset(edcf->mapping, 0, sizeof(edcf->mapping));
  1470. memcpy(edcf->queue, priv->qos_params, sizeof(edcf->queue));
  1471. priv->tx(dev, skb);
  1472. return 0;
  1473. }
  1474. static int p54_beacon_tim(struct sk_buff *skb)
  1475. {
  1476. /*
  1477. * the good excuse for this mess is ... the firmware.
  1478. * The dummy TIM MUST be at the end of the beacon frame,
  1479. * because it'll be overwritten!
  1480. */
  1481. struct ieee80211_mgmt *mgmt = (void *)skb->data;
  1482. u8 *pos, *end;
  1483. if (skb->len <= sizeof(mgmt))
  1484. return -EINVAL;
  1485. pos = (u8 *)mgmt->u.beacon.variable;
  1486. end = skb->data + skb->len;
  1487. while (pos < end) {
  1488. if (pos + 2 + pos[1] > end)
  1489. return -EINVAL;
  1490. if (pos[0] == WLAN_EID_TIM) {
  1491. u8 dtim_len = pos[1];
  1492. u8 dtim_period = pos[3];
  1493. u8 *next = pos + 2 + dtim_len;
  1494. if (dtim_len < 3)
  1495. return -EINVAL;
  1496. memmove(pos, next, end - next);
  1497. if (dtim_len > 3)
  1498. skb_trim(skb, skb->len - (dtim_len - 3));
  1499. pos = end - (dtim_len + 2);
  1500. /* add the dummy at the end */
  1501. pos[0] = WLAN_EID_TIM;
  1502. pos[1] = 3;
  1503. pos[2] = 0;
  1504. pos[3] = dtim_period;
  1505. pos[4] = 0;
  1506. return 0;
  1507. }
  1508. pos += 2 + pos[1];
  1509. }
  1510. return 0;
  1511. }
  1512. static int p54_beacon_update(struct ieee80211_hw *dev,
  1513. struct ieee80211_vif *vif)
  1514. {
  1515. struct p54_common *priv = dev->priv;
  1516. struct sk_buff *beacon;
  1517. int ret;
  1518. if (priv->cached_beacon) {
  1519. p54_tx_cancel(dev, priv->cached_beacon);
  1520. /* wait for the last beacon the be freed */
  1521. msleep(10);
  1522. }
  1523. beacon = ieee80211_beacon_get(dev, vif);
  1524. if (!beacon)
  1525. return -ENOMEM;
  1526. ret = p54_beacon_tim(beacon);
  1527. if (ret)
  1528. return ret;
  1529. ret = p54_tx(dev, beacon);
  1530. if (ret)
  1531. return ret;
  1532. priv->cached_beacon = beacon;
  1533. priv->tsf_high32 = 0;
  1534. priv->tsf_low32 = 0;
  1535. return 0;
  1536. }
  1537. static int p54_start(struct ieee80211_hw *dev)
  1538. {
  1539. struct p54_common *priv = dev->priv;
  1540. int err;
  1541. mutex_lock(&priv->conf_mutex);
  1542. err = priv->open(dev);
  1543. if (err)
  1544. goto out;
  1545. P54_SET_QUEUE(priv->qos_params[0], 0x0002, 0x0003, 0x0007, 47);
  1546. P54_SET_QUEUE(priv->qos_params[1], 0x0002, 0x0007, 0x000f, 94);
  1547. P54_SET_QUEUE(priv->qos_params[2], 0x0003, 0x000f, 0x03ff, 0);
  1548. P54_SET_QUEUE(priv->qos_params[3], 0x0007, 0x000f, 0x03ff, 0);
  1549. err = p54_set_edcf(dev);
  1550. if (err)
  1551. goto out;
  1552. memset(priv->bssid, ~0, ETH_ALEN);
  1553. priv->mode = NL80211_IFTYPE_MONITOR;
  1554. err = p54_setup_mac(dev);
  1555. if (err) {
  1556. priv->mode = NL80211_IFTYPE_UNSPECIFIED;
  1557. goto out;
  1558. }
  1559. queue_delayed_work(dev->workqueue, &priv->work, 0);
  1560. out:
  1561. mutex_unlock(&priv->conf_mutex);
  1562. return err;
  1563. }
  1564. static void p54_stop(struct ieee80211_hw *dev)
  1565. {
  1566. struct p54_common *priv = dev->priv;
  1567. struct sk_buff *skb;
  1568. mutex_lock(&priv->conf_mutex);
  1569. priv->mode = NL80211_IFTYPE_UNSPECIFIED;
  1570. cancel_delayed_work_sync(&priv->work);
  1571. if (priv->cached_beacon)
  1572. p54_tx_cancel(dev, priv->cached_beacon);
  1573. priv->stop(dev);
  1574. while ((skb = skb_dequeue(&priv->tx_queue)))
  1575. kfree_skb(skb);
  1576. priv->cached_beacon = NULL;
  1577. priv->tsf_high32 = priv->tsf_low32 = 0;
  1578. mutex_unlock(&priv->conf_mutex);
  1579. }
  1580. static int p54_add_interface(struct ieee80211_hw *dev,
  1581. struct ieee80211_if_init_conf *conf)
  1582. {
  1583. struct p54_common *priv = dev->priv;
  1584. mutex_lock(&priv->conf_mutex);
  1585. if (priv->mode != NL80211_IFTYPE_MONITOR) {
  1586. mutex_unlock(&priv->conf_mutex);
  1587. return -EOPNOTSUPP;
  1588. }
  1589. switch (conf->type) {
  1590. case NL80211_IFTYPE_STATION:
  1591. case NL80211_IFTYPE_ADHOC:
  1592. case NL80211_IFTYPE_AP:
  1593. case NL80211_IFTYPE_MESH_POINT:
  1594. priv->mode = conf->type;
  1595. break;
  1596. default:
  1597. mutex_unlock(&priv->conf_mutex);
  1598. return -EOPNOTSUPP;
  1599. }
  1600. memcpy(priv->mac_addr, conf->mac_addr, ETH_ALEN);
  1601. p54_setup_mac(dev);
  1602. p54_set_leds(dev, 1, 0, 0);
  1603. mutex_unlock(&priv->conf_mutex);
  1604. return 0;
  1605. }
  1606. static void p54_remove_interface(struct ieee80211_hw *dev,
  1607. struct ieee80211_if_init_conf *conf)
  1608. {
  1609. struct p54_common *priv = dev->priv;
  1610. mutex_lock(&priv->conf_mutex);
  1611. if (priv->cached_beacon)
  1612. p54_tx_cancel(dev, priv->cached_beacon);
  1613. priv->mode = NL80211_IFTYPE_MONITOR;
  1614. memset(priv->mac_addr, 0, ETH_ALEN);
  1615. memset(priv->bssid, 0, ETH_ALEN);
  1616. p54_setup_mac(dev);
  1617. mutex_unlock(&priv->conf_mutex);
  1618. }
  1619. static int p54_config(struct ieee80211_hw *dev, u32 changed)
  1620. {
  1621. int ret = 0;
  1622. struct p54_common *priv = dev->priv;
  1623. struct ieee80211_conf *conf = &dev->conf;
  1624. mutex_lock(&priv->conf_mutex);
  1625. if (changed & IEEE80211_CONF_CHANGE_POWER)
  1626. priv->output_power = conf->power_level << 2;
  1627. if (changed & IEEE80211_CONF_CHANGE_RADIO_ENABLED) {
  1628. ret = p54_setup_mac(dev);
  1629. if (ret)
  1630. goto out;
  1631. }
  1632. if (changed & IEEE80211_CONF_CHANGE_CHANNEL) {
  1633. ret = p54_scan(dev, P54_SCAN_EXIT, 0);
  1634. if (ret)
  1635. goto out;
  1636. }
  1637. out:
  1638. mutex_unlock(&priv->conf_mutex);
  1639. return ret;
  1640. }
  1641. static int p54_config_interface(struct ieee80211_hw *dev,
  1642. struct ieee80211_vif *vif,
  1643. struct ieee80211_if_conf *conf)
  1644. {
  1645. struct p54_common *priv = dev->priv;
  1646. int ret = 0;
  1647. mutex_lock(&priv->conf_mutex);
  1648. if (conf->changed & IEEE80211_IFCC_BSSID) {
  1649. memcpy(priv->bssid, conf->bssid, ETH_ALEN);
  1650. ret = p54_setup_mac(dev);
  1651. if (ret)
  1652. goto out;
  1653. }
  1654. if (conf->changed & IEEE80211_IFCC_BEACON) {
  1655. ret = p54_scan(dev, P54_SCAN_EXIT, 0);
  1656. if (ret)
  1657. goto out;
  1658. ret = p54_setup_mac(dev);
  1659. if (ret)
  1660. goto out;
  1661. ret = p54_beacon_update(dev, vif);
  1662. if (ret)
  1663. goto out;
  1664. ret = p54_set_edcf(dev);
  1665. if (ret)
  1666. goto out;
  1667. }
  1668. ret = p54_set_leds(dev, 1, !is_multicast_ether_addr(priv->bssid), 0);
  1669. out:
  1670. mutex_unlock(&priv->conf_mutex);
  1671. return ret;
  1672. }
  1673. static void p54_configure_filter(struct ieee80211_hw *dev,
  1674. unsigned int changed_flags,
  1675. unsigned int *total_flags,
  1676. int mc_count, struct dev_mc_list *mclist)
  1677. {
  1678. struct p54_common *priv = dev->priv;
  1679. *total_flags &= FIF_PROMISC_IN_BSS |
  1680. (*total_flags & FIF_PROMISC_IN_BSS) ?
  1681. FIF_FCSFAIL : 0;
  1682. priv->filter_flags = *total_flags;
  1683. if (changed_flags & FIF_PROMISC_IN_BSS)
  1684. p54_setup_mac(dev);
  1685. }
  1686. static int p54_conf_tx(struct ieee80211_hw *dev, u16 queue,
  1687. const struct ieee80211_tx_queue_params *params)
  1688. {
  1689. struct p54_common *priv = dev->priv;
  1690. int ret;
  1691. mutex_lock(&priv->conf_mutex);
  1692. if ((params) && !(queue > 4)) {
  1693. P54_SET_QUEUE(priv->qos_params[queue], params->aifs,
  1694. params->cw_min, params->cw_max, params->txop);
  1695. ret = p54_set_edcf(dev);
  1696. } else
  1697. ret = -EINVAL;
  1698. mutex_unlock(&priv->conf_mutex);
  1699. return ret;
  1700. }
  1701. static int p54_init_xbow_synth(struct ieee80211_hw *dev)
  1702. {
  1703. struct p54_common *priv = dev->priv;
  1704. struct sk_buff *skb;
  1705. struct p54_xbow_synth *xbow;
  1706. skb = p54_alloc_skb(dev, P54_HDR_FLAG_CONTROL_OPSET, sizeof(*xbow) +
  1707. sizeof(struct p54_hdr),
  1708. P54_CONTROL_TYPE_XBOW_SYNTH_CFG,
  1709. GFP_KERNEL);
  1710. if (!skb)
  1711. return -ENOMEM;
  1712. xbow = (struct p54_xbow_synth *)skb_put(skb, sizeof(*xbow));
  1713. xbow->magic1 = cpu_to_le16(0x1);
  1714. xbow->magic2 = cpu_to_le16(0x2);
  1715. xbow->freq = cpu_to_le16(5390);
  1716. memset(xbow->padding, 0, sizeof(xbow->padding));
  1717. priv->tx(dev, skb);
  1718. return 0;
  1719. }
  1720. static void p54_work(struct work_struct *work)
  1721. {
  1722. struct p54_common *priv = container_of(work, struct p54_common,
  1723. work.work);
  1724. struct ieee80211_hw *dev = priv->hw;
  1725. struct sk_buff *skb;
  1726. if (unlikely(priv->mode == NL80211_IFTYPE_UNSPECIFIED))
  1727. return ;
  1728. /*
  1729. * TODO: walk through tx_queue and do the following tasks
  1730. * 1. initiate bursts.
  1731. * 2. cancel stuck frames / reset the device if necessary.
  1732. */
  1733. skb = p54_alloc_skb(dev, P54_HDR_FLAG_CONTROL, sizeof(struct p54_hdr) +
  1734. sizeof(struct p54_statistics),
  1735. P54_CONTROL_TYPE_STAT_READBACK, GFP_KERNEL);
  1736. if (!skb)
  1737. return ;
  1738. priv->tx(dev, skb);
  1739. }
  1740. static int p54_get_stats(struct ieee80211_hw *dev,
  1741. struct ieee80211_low_level_stats *stats)
  1742. {
  1743. struct p54_common *priv = dev->priv;
  1744. memcpy(stats, &priv->stats, sizeof(*stats));
  1745. return 0;
  1746. }
  1747. static int p54_get_tx_stats(struct ieee80211_hw *dev,
  1748. struct ieee80211_tx_queue_stats *stats)
  1749. {
  1750. struct p54_common *priv = dev->priv;
  1751. memcpy(stats, &priv->tx_stats[4], sizeof(stats[0]) * dev->queues);
  1752. return 0;
  1753. }
  1754. static void p54_bss_info_changed(struct ieee80211_hw *dev,
  1755. struct ieee80211_vif *vif,
  1756. struct ieee80211_bss_conf *info,
  1757. u32 changed)
  1758. {
  1759. struct p54_common *priv = dev->priv;
  1760. if (changed & BSS_CHANGED_ERP_SLOT) {
  1761. priv->use_short_slot = info->use_short_slot;
  1762. p54_set_edcf(dev);
  1763. }
  1764. if (changed & BSS_CHANGED_BASIC_RATES) {
  1765. if (dev->conf.channel->band == IEEE80211_BAND_5GHZ)
  1766. priv->basic_rate_mask = (info->basic_rates << 4);
  1767. else
  1768. priv->basic_rate_mask = info->basic_rates;
  1769. p54_setup_mac(dev);
  1770. if (priv->fw_var >= 0x500)
  1771. p54_scan(dev, P54_SCAN_EXIT, 0);
  1772. }
  1773. if (changed & BSS_CHANGED_ASSOC) {
  1774. if (info->assoc) {
  1775. priv->aid = info->aid;
  1776. priv->wakeup_timer = info->beacon_int *
  1777. info->dtim_period * 5;
  1778. p54_setup_mac(dev);
  1779. }
  1780. }
  1781. }
  1782. static int p54_set_key(struct ieee80211_hw *dev, enum set_key_cmd cmd,
  1783. const u8 *local_address, const u8 *address,
  1784. struct ieee80211_key_conf *key)
  1785. {
  1786. struct p54_common *priv = dev->priv;
  1787. struct sk_buff *skb;
  1788. struct p54_keycache *rxkey;
  1789. u8 algo = 0;
  1790. if (modparam_nohwcrypt)
  1791. return -EOPNOTSUPP;
  1792. if (cmd == DISABLE_KEY)
  1793. algo = 0;
  1794. else {
  1795. switch (key->alg) {
  1796. case ALG_TKIP:
  1797. if (!(priv->privacy_caps & (BR_DESC_PRIV_CAP_MICHAEL |
  1798. BR_DESC_PRIV_CAP_TKIP)))
  1799. return -EOPNOTSUPP;
  1800. key->flags |= IEEE80211_KEY_FLAG_GENERATE_IV;
  1801. algo = P54_CRYPTO_TKIPMICHAEL;
  1802. break;
  1803. case ALG_WEP:
  1804. if (!(priv->privacy_caps & BR_DESC_PRIV_CAP_WEP))
  1805. return -EOPNOTSUPP;
  1806. key->flags |= IEEE80211_KEY_FLAG_GENERATE_IV;
  1807. algo = P54_CRYPTO_WEP;
  1808. break;
  1809. case ALG_CCMP:
  1810. if (!(priv->privacy_caps & BR_DESC_PRIV_CAP_AESCCMP))
  1811. return -EOPNOTSUPP;
  1812. key->flags |= IEEE80211_KEY_FLAG_GENERATE_IV;
  1813. algo = P54_CRYPTO_AESCCMP;
  1814. break;
  1815. default:
  1816. return -EINVAL;
  1817. }
  1818. }
  1819. if (key->keyidx > priv->rx_keycache_size) {
  1820. /*
  1821. * The device supports the choosen algorithm, but the firmware
  1822. * does not provide enough key slots to store all of them.
  1823. * So, incoming frames have to be decoded by the mac80211 stack,
  1824. * but we can still offload encryption for outgoing frames.
  1825. */
  1826. return 0;
  1827. }
  1828. mutex_lock(&priv->conf_mutex);
  1829. skb = p54_alloc_skb(dev, P54_HDR_FLAG_CONTROL_OPSET, sizeof(*rxkey) +
  1830. sizeof(struct p54_hdr), P54_CONTROL_TYPE_RX_KEYCACHE,
  1831. GFP_ATOMIC);
  1832. if (!skb) {
  1833. mutex_unlock(&priv->conf_mutex);
  1834. return -ENOMEM;
  1835. }
  1836. /* TODO: some devices have 4 more free slots for rx keys */
  1837. rxkey = (struct p54_keycache *)skb_put(skb, sizeof(*rxkey));
  1838. rxkey->entry = key->keyidx;
  1839. rxkey->key_id = key->keyidx;
  1840. rxkey->key_type = algo;
  1841. if (address)
  1842. memcpy(rxkey->mac, address, ETH_ALEN);
  1843. else
  1844. memset(rxkey->mac, ~0, ETH_ALEN);
  1845. if (key->alg != ALG_TKIP) {
  1846. rxkey->key_len = min((u8)16, key->keylen);
  1847. memcpy(rxkey->key, key->key, rxkey->key_len);
  1848. } else {
  1849. rxkey->key_len = 24;
  1850. memcpy(rxkey->key, key->key, 16);
  1851. memcpy(&(rxkey->key[16]), &(key->key
  1852. [NL80211_TKIP_DATA_OFFSET_RX_MIC_KEY]), 8);
  1853. }
  1854. priv->tx(dev, skb);
  1855. mutex_unlock(&priv->conf_mutex);
  1856. return 0;
  1857. }
  1858. static const struct ieee80211_ops p54_ops = {
  1859. .tx = p54_tx,
  1860. .start = p54_start,
  1861. .stop = p54_stop,
  1862. .add_interface = p54_add_interface,
  1863. .remove_interface = p54_remove_interface,
  1864. .set_tim = p54_set_tim,
  1865. .sta_notify = p54_sta_notify,
  1866. .set_key = p54_set_key,
  1867. .config = p54_config,
  1868. .config_interface = p54_config_interface,
  1869. .bss_info_changed = p54_bss_info_changed,
  1870. .configure_filter = p54_configure_filter,
  1871. .conf_tx = p54_conf_tx,
  1872. .get_stats = p54_get_stats,
  1873. .get_tx_stats = p54_get_tx_stats
  1874. };
  1875. struct ieee80211_hw *p54_init_common(size_t priv_data_len)
  1876. {
  1877. struct ieee80211_hw *dev;
  1878. struct p54_common *priv;
  1879. dev = ieee80211_alloc_hw(priv_data_len, &p54_ops);
  1880. if (!dev)
  1881. return NULL;
  1882. priv = dev->priv;
  1883. priv->hw = dev;
  1884. priv->mode = NL80211_IFTYPE_UNSPECIFIED;
  1885. priv->basic_rate_mask = 0x15f;
  1886. skb_queue_head_init(&priv->tx_queue);
  1887. dev->flags = IEEE80211_HW_RX_INCLUDES_FCS |
  1888. IEEE80211_HW_SIGNAL_DBM |
  1889. IEEE80211_HW_NOISE_DBM;
  1890. dev->wiphy->interface_modes = BIT(NL80211_IFTYPE_STATION) |
  1891. BIT(NL80211_IFTYPE_ADHOC) |
  1892. BIT(NL80211_IFTYPE_AP) |
  1893. BIT(NL80211_IFTYPE_MESH_POINT);
  1894. dev->channel_change_time = 1000; /* TODO: find actual value */
  1895. priv->tx_stats[0].limit = 1; /* Beacon queue */
  1896. priv->tx_stats[1].limit = 1; /* Probe queue for HW scan */
  1897. priv->tx_stats[2].limit = 3; /* queue for MLMEs */
  1898. priv->tx_stats[3].limit = 3; /* Broadcast / MC queue */
  1899. priv->tx_stats[4].limit = 5; /* Data */
  1900. dev->queues = 1;
  1901. priv->noise = -94;
  1902. /*
  1903. * We support at most 8 tries no matter which rate they're at,
  1904. * we cannot support max_rates * max_rate_tries as we set it
  1905. * here, but setting it correctly to 4/2 or so would limit us
  1906. * artificially if the RC algorithm wants just two rates, so
  1907. * let's say 4/7, we'll redistribute it at TX time, see the
  1908. * comments there.
  1909. */
  1910. dev->max_rates = 4;
  1911. dev->max_rate_tries = 7;
  1912. dev->extra_tx_headroom = sizeof(struct p54_hdr) + 4 +
  1913. sizeof(struct p54_tx_data);
  1914. mutex_init(&priv->conf_mutex);
  1915. init_completion(&priv->eeprom_comp);
  1916. INIT_DELAYED_WORK(&priv->work, p54_work);
  1917. return dev;
  1918. }
  1919. EXPORT_SYMBOL_GPL(p54_init_common);
  1920. void p54_free_common(struct ieee80211_hw *dev)
  1921. {
  1922. struct p54_common *priv = dev->priv;
  1923. kfree(priv->iq_autocal);
  1924. kfree(priv->output_limit);
  1925. kfree(priv->curve_data);
  1926. }
  1927. EXPORT_SYMBOL_GPL(p54_free_common);
  1928. static int __init p54_init(void)
  1929. {
  1930. return 0;
  1931. }
  1932. static void __exit p54_exit(void)
  1933. {
  1934. }
  1935. module_init(p54_init);
  1936. module_exit(p54_exit);