p54common.c 57 KB

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