p54common.c 60 KB

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