p54common.c 34 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227
  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. *
  7. * Based on the islsm (softmac prism54) driver, which is:
  8. * Copyright 2004-2006 Jean-Baptiste Note <jbnote@gmail.com>, et al.
  9. *
  10. * This program is free software; you can redistribute it and/or modify
  11. * it under the terms of the GNU General Public License version 2 as
  12. * published by the Free Software Foundation.
  13. */
  14. #include <linux/init.h>
  15. #include <linux/firmware.h>
  16. #include <linux/etherdevice.h>
  17. #include <net/mac80211.h>
  18. #include "p54.h"
  19. #include "p54common.h"
  20. MODULE_AUTHOR("Michael Wu <flamingice@sourmilk.net>");
  21. MODULE_DESCRIPTION("Softmac Prism54 common code");
  22. MODULE_LICENSE("GPL");
  23. MODULE_ALIAS("prism54common");
  24. static struct ieee80211_rate p54_rates[] = {
  25. { .bitrate = 10, .hw_value = 0, .flags = IEEE80211_RATE_SHORT_PREAMBLE },
  26. { .bitrate = 20, .hw_value = 1, .flags = IEEE80211_RATE_SHORT_PREAMBLE },
  27. { .bitrate = 55, .hw_value = 2, .flags = IEEE80211_RATE_SHORT_PREAMBLE },
  28. { .bitrate = 110, .hw_value = 3, .flags = IEEE80211_RATE_SHORT_PREAMBLE },
  29. { .bitrate = 60, .hw_value = 4, },
  30. { .bitrate = 90, .hw_value = 5, },
  31. { .bitrate = 120, .hw_value = 6, },
  32. { .bitrate = 180, .hw_value = 7, },
  33. { .bitrate = 240, .hw_value = 8, },
  34. { .bitrate = 360, .hw_value = 9, },
  35. { .bitrate = 480, .hw_value = 10, },
  36. { .bitrate = 540, .hw_value = 11, },
  37. };
  38. static struct ieee80211_channel p54_channels[] = {
  39. { .center_freq = 2412, .hw_value = 1, },
  40. { .center_freq = 2417, .hw_value = 2, },
  41. { .center_freq = 2422, .hw_value = 3, },
  42. { .center_freq = 2427, .hw_value = 4, },
  43. { .center_freq = 2432, .hw_value = 5, },
  44. { .center_freq = 2437, .hw_value = 6, },
  45. { .center_freq = 2442, .hw_value = 7, },
  46. { .center_freq = 2447, .hw_value = 8, },
  47. { .center_freq = 2452, .hw_value = 9, },
  48. { .center_freq = 2457, .hw_value = 10, },
  49. { .center_freq = 2462, .hw_value = 11, },
  50. { .center_freq = 2467, .hw_value = 12, },
  51. { .center_freq = 2472, .hw_value = 13, },
  52. { .center_freq = 2484, .hw_value = 14, },
  53. };
  54. static struct ieee80211_supported_band band_2GHz = {
  55. .channels = p54_channels,
  56. .n_channels = ARRAY_SIZE(p54_channels),
  57. .bitrates = p54_rates,
  58. .n_bitrates = ARRAY_SIZE(p54_rates),
  59. };
  60. int p54_parse_firmware(struct ieee80211_hw *dev, const struct firmware *fw)
  61. {
  62. struct p54_common *priv = dev->priv;
  63. struct bootrec_exp_if *exp_if;
  64. struct bootrec *bootrec;
  65. u32 *data = (u32 *)fw->data;
  66. u32 *end_data = (u32 *)fw->data + (fw->size >> 2);
  67. u8 *fw_version = NULL;
  68. size_t len;
  69. int i;
  70. if (priv->rx_start)
  71. return 0;
  72. while (data < end_data && *data)
  73. data++;
  74. while (data < end_data && !*data)
  75. data++;
  76. bootrec = (struct bootrec *) data;
  77. while (bootrec->data <= end_data &&
  78. (bootrec->data + (len = le32_to_cpu(bootrec->len))) <= end_data) {
  79. u32 code = le32_to_cpu(bootrec->code);
  80. switch (code) {
  81. case BR_CODE_COMPONENT_ID:
  82. priv->fw_interface = be32_to_cpup(bootrec->data);
  83. switch (priv->fw_interface) {
  84. case FW_FMAC:
  85. printk(KERN_INFO "p54: FreeMAC firmware\n");
  86. break;
  87. case FW_LM20:
  88. printk(KERN_INFO "p54: LM20 firmware\n");
  89. break;
  90. case FW_LM86:
  91. printk(KERN_INFO "p54: LM86 firmware\n");
  92. break;
  93. case FW_LM87:
  94. printk(KERN_INFO "p54: LM87 firmware\n");
  95. break;
  96. default:
  97. printk(KERN_INFO "p54: unknown firmware\n");
  98. break;
  99. }
  100. break;
  101. case BR_CODE_COMPONENT_VERSION:
  102. /* 24 bytes should be enough for all firmwares */
  103. if (strnlen((unsigned char*)bootrec->data, 24) < 24)
  104. fw_version = (unsigned char*)bootrec->data;
  105. break;
  106. case BR_CODE_DESCR: {
  107. struct bootrec_desc *desc =
  108. (struct bootrec_desc *)bootrec->data;
  109. priv->rx_start = le32_to_cpu(desc->rx_start);
  110. /* FIXME add sanity checking */
  111. priv->rx_end = le32_to_cpu(desc->rx_end) - 0x3500;
  112. priv->headroom = desc->headroom;
  113. priv->tailroom = desc->tailroom;
  114. if (bootrec->len == 11)
  115. priv->rx_mtu = (size_t) le16_to_cpu(
  116. (__le16)bootrec->data[10]);
  117. else
  118. priv->rx_mtu = (size_t)
  119. 0x620 - priv->tx_hdr_len;
  120. break;
  121. }
  122. case BR_CODE_EXPOSED_IF:
  123. exp_if = (struct bootrec_exp_if *) bootrec->data;
  124. for (i = 0; i < (len * sizeof(*exp_if) / 4); i++)
  125. if (exp_if[i].if_id == cpu_to_le16(0x1a))
  126. priv->fw_var = le16_to_cpu(exp_if[i].variant);
  127. break;
  128. case BR_CODE_DEPENDENT_IF:
  129. break;
  130. case BR_CODE_END_OF_BRA:
  131. case LEGACY_BR_CODE_END_OF_BRA:
  132. end_data = NULL;
  133. break;
  134. default:
  135. break;
  136. }
  137. bootrec = (struct bootrec *)&bootrec->data[len];
  138. }
  139. if (fw_version)
  140. printk(KERN_INFO "p54: FW rev %s - Softmac protocol %x.%x\n",
  141. fw_version, priv->fw_var >> 8, priv->fw_var & 0xff);
  142. if (priv->fw_var >= 0x300) {
  143. /* Firmware supports QoS, use it! */
  144. priv->tx_stats[4].limit = 3;
  145. priv->tx_stats[5].limit = 4;
  146. priv->tx_stats[6].limit = 3;
  147. priv->tx_stats[7].limit = 1;
  148. dev->queues = 4;
  149. }
  150. return 0;
  151. }
  152. EXPORT_SYMBOL_GPL(p54_parse_firmware);
  153. static int p54_convert_rev0(struct ieee80211_hw *dev,
  154. struct pda_pa_curve_data *curve_data)
  155. {
  156. struct p54_common *priv = dev->priv;
  157. struct p54_pa_curve_data_sample *dst;
  158. struct pda_pa_curve_data_sample_rev0 *src;
  159. size_t cd_len = sizeof(*curve_data) +
  160. (curve_data->points_per_channel*sizeof(*dst) + 2) *
  161. curve_data->channels;
  162. unsigned int i, j;
  163. void *source, *target;
  164. priv->curve_data = kmalloc(cd_len, GFP_KERNEL);
  165. if (!priv->curve_data)
  166. return -ENOMEM;
  167. memcpy(priv->curve_data, curve_data, sizeof(*curve_data));
  168. source = curve_data->data;
  169. target = priv->curve_data->data;
  170. for (i = 0; i < curve_data->channels; i++) {
  171. __le16 *freq = source;
  172. source += sizeof(__le16);
  173. *((__le16 *)target) = *freq;
  174. target += sizeof(__le16);
  175. for (j = 0; j < curve_data->points_per_channel; j++) {
  176. dst = target;
  177. src = source;
  178. dst->rf_power = src->rf_power;
  179. dst->pa_detector = src->pa_detector;
  180. dst->data_64qam = src->pcv;
  181. /* "invent" the points for the other modulations */
  182. #define SUB(x,y) (u8)((x) - (y)) > (x) ? 0 : (x) - (y)
  183. dst->data_16qam = SUB(src->pcv, 12);
  184. dst->data_qpsk = SUB(dst->data_16qam, 12);
  185. dst->data_bpsk = SUB(dst->data_qpsk, 12);
  186. dst->data_barker = SUB(dst->data_bpsk, 14);
  187. #undef SUB
  188. target += sizeof(*dst);
  189. source += sizeof(*src);
  190. }
  191. }
  192. return 0;
  193. }
  194. static int p54_convert_rev1(struct ieee80211_hw *dev,
  195. struct pda_pa_curve_data *curve_data)
  196. {
  197. struct p54_common *priv = dev->priv;
  198. struct p54_pa_curve_data_sample *dst;
  199. struct pda_pa_curve_data_sample_rev1 *src;
  200. size_t cd_len = sizeof(*curve_data) +
  201. (curve_data->points_per_channel*sizeof(*dst) + 2) *
  202. curve_data->channels;
  203. unsigned int i, j;
  204. void *source, *target;
  205. priv->curve_data = kmalloc(cd_len, GFP_KERNEL);
  206. if (!priv->curve_data)
  207. return -ENOMEM;
  208. memcpy(priv->curve_data, curve_data, sizeof(*curve_data));
  209. source = curve_data->data;
  210. target = priv->curve_data->data;
  211. for (i = 0; i < curve_data->channels; i++) {
  212. __le16 *freq = source;
  213. source += sizeof(__le16);
  214. *((__le16 *)target) = *freq;
  215. target += sizeof(__le16);
  216. for (j = 0; j < curve_data->points_per_channel; j++) {
  217. memcpy(target, source, sizeof(*src));
  218. target += sizeof(*dst);
  219. source += sizeof(*src);
  220. }
  221. source++;
  222. }
  223. return 0;
  224. }
  225. const char* p54_rf_chips[] = { "NULL", "Indigo?", "Duette",
  226. "Frisbee", "Xbow", "Longbow" };
  227. int p54_parse_eeprom(struct ieee80211_hw *dev, void *eeprom, int len)
  228. {
  229. struct p54_common *priv = dev->priv;
  230. struct eeprom_pda_wrap *wrap = NULL;
  231. struct pda_entry *entry;
  232. unsigned int data_len, entry_len;
  233. void *tmp;
  234. int err;
  235. u8 *end = (u8 *)eeprom + len;
  236. DECLARE_MAC_BUF(mac);
  237. wrap = (struct eeprom_pda_wrap *) eeprom;
  238. entry = (void *)wrap->data + le16_to_cpu(wrap->len);
  239. /* verify that at least the entry length/code fits */
  240. while ((u8 *)entry <= end - sizeof(*entry)) {
  241. entry_len = le16_to_cpu(entry->len);
  242. data_len = ((entry_len - 1) << 1);
  243. /* abort if entry exceeds whole structure */
  244. if ((u8 *)entry + sizeof(*entry) + data_len > end)
  245. break;
  246. switch (le16_to_cpu(entry->code)) {
  247. case PDR_MAC_ADDRESS:
  248. SET_IEEE80211_PERM_ADDR(dev, entry->data);
  249. break;
  250. case PDR_PRISM_PA_CAL_OUTPUT_POWER_LIMITS:
  251. if (data_len < 2) {
  252. err = -EINVAL;
  253. goto err;
  254. }
  255. if (2 + entry->data[1]*sizeof(*priv->output_limit) > data_len) {
  256. err = -EINVAL;
  257. goto err;
  258. }
  259. priv->output_limit = kmalloc(entry->data[1] *
  260. sizeof(*priv->output_limit), GFP_KERNEL);
  261. if (!priv->output_limit) {
  262. err = -ENOMEM;
  263. goto err;
  264. }
  265. memcpy(priv->output_limit, &entry->data[2],
  266. entry->data[1]*sizeof(*priv->output_limit));
  267. priv->output_limit_len = entry->data[1];
  268. break;
  269. case PDR_PRISM_PA_CAL_CURVE_DATA: {
  270. struct pda_pa_curve_data *curve_data =
  271. (struct pda_pa_curve_data *)entry->data;
  272. if (data_len < sizeof(*curve_data)) {
  273. err = -EINVAL;
  274. goto err;
  275. }
  276. switch (curve_data->cal_method_rev) {
  277. case 0:
  278. err = p54_convert_rev0(dev, curve_data);
  279. break;
  280. case 1:
  281. err = p54_convert_rev1(dev, curve_data);
  282. break;
  283. default:
  284. printk(KERN_ERR "p54: unknown curve data "
  285. "revision %d\n",
  286. curve_data->cal_method_rev);
  287. err = -ENODEV;
  288. break;
  289. }
  290. if (err)
  291. goto err;
  292. }
  293. case PDR_PRISM_ZIF_TX_IQ_CALIBRATION:
  294. priv->iq_autocal = kmalloc(data_len, GFP_KERNEL);
  295. if (!priv->iq_autocal) {
  296. err = -ENOMEM;
  297. goto err;
  298. }
  299. memcpy(priv->iq_autocal, entry->data, data_len);
  300. priv->iq_autocal_len = data_len / sizeof(struct pda_iq_autocal_entry);
  301. break;
  302. case PDR_INTERFACE_LIST:
  303. tmp = entry->data;
  304. while ((u8 *)tmp < entry->data + data_len) {
  305. struct bootrec_exp_if *exp_if = tmp;
  306. if (le16_to_cpu(exp_if->if_id) == 0xF)
  307. priv->rxhw = le16_to_cpu(exp_if->variant) & 0x07;
  308. tmp += sizeof(struct bootrec_exp_if);
  309. }
  310. break;
  311. case PDR_HARDWARE_PLATFORM_COMPONENT_ID:
  312. priv->version = *(u8 *)(entry->data + 1);
  313. break;
  314. case PDR_END:
  315. /* make it overrun */
  316. entry_len = len;
  317. break;
  318. default:
  319. printk(KERN_INFO "p54: unknown eeprom code : 0x%x\n",
  320. le16_to_cpu(entry->code));
  321. break;
  322. }
  323. entry = (void *)entry + (entry_len + 1)*2;
  324. }
  325. if (!priv->iq_autocal || !priv->output_limit || !priv->curve_data) {
  326. printk(KERN_ERR "p54: not all required entries found in eeprom!\n");
  327. err = -EINVAL;
  328. goto err;
  329. }
  330. switch (priv->rxhw) {
  331. case 4: /* XBow */
  332. case 1: /* Indigo? */
  333. case 2: /* Duette */
  334. /* TODO: 5GHz initialization goes here */
  335. case 3: /* Frisbee */
  336. case 5: /* Longbow */
  337. dev->wiphy->bands[IEEE80211_BAND_2GHZ] = &band_2GHz;
  338. break;
  339. default:
  340. printk(KERN_ERR "%s: unsupported RF-Chip\n",
  341. wiphy_name(dev->wiphy));
  342. err = -EINVAL;
  343. goto err;
  344. }
  345. if (!is_valid_ether_addr(dev->wiphy->perm_addr)) {
  346. u8 perm_addr[ETH_ALEN];
  347. printk(KERN_WARNING "%s: Invalid hwaddr! Using randomly generated MAC addr\n",
  348. wiphy_name(dev->wiphy));
  349. random_ether_addr(perm_addr);
  350. SET_IEEE80211_PERM_ADDR(dev, perm_addr);
  351. }
  352. printk(KERN_INFO "%s: hwaddr %s, MAC:isl38%02x RF:%s\n",
  353. wiphy_name(dev->wiphy),
  354. print_mac(mac, dev->wiphy->perm_addr),
  355. priv->version, p54_rf_chips[priv->rxhw]);
  356. return 0;
  357. err:
  358. if (priv->iq_autocal) {
  359. kfree(priv->iq_autocal);
  360. priv->iq_autocal = NULL;
  361. }
  362. if (priv->output_limit) {
  363. kfree(priv->output_limit);
  364. priv->output_limit = NULL;
  365. }
  366. if (priv->curve_data) {
  367. kfree(priv->curve_data);
  368. priv->curve_data = NULL;
  369. }
  370. printk(KERN_ERR "p54: eeprom parse failed!\n");
  371. return err;
  372. }
  373. EXPORT_SYMBOL_GPL(p54_parse_eeprom);
  374. static void p54_rx_data(struct ieee80211_hw *dev, struct sk_buff *skb)
  375. {
  376. struct p54_rx_hdr *hdr = (struct p54_rx_hdr *) skb->data;
  377. struct ieee80211_rx_status rx_status = {0};
  378. u16 freq = le16_to_cpu(hdr->freq);
  379. rx_status.signal = hdr->rssi;
  380. /* XX correct? */
  381. rx_status.qual = (100 * hdr->rssi) / 127;
  382. rx_status.rate_idx = hdr->rate & 0xf;
  383. rx_status.freq = freq;
  384. rx_status.band = IEEE80211_BAND_2GHZ;
  385. rx_status.antenna = hdr->antenna;
  386. rx_status.mactime = le64_to_cpu(hdr->timestamp);
  387. rx_status.flag |= RX_FLAG_TSFT;
  388. skb_pull(skb, sizeof(*hdr));
  389. skb_trim(skb, le16_to_cpu(hdr->len));
  390. ieee80211_rx_irqsafe(dev, skb, &rx_status);
  391. }
  392. static void inline p54_wake_free_queues(struct ieee80211_hw *dev)
  393. {
  394. struct p54_common *priv = dev->priv;
  395. int i;
  396. for (i = 0; i < dev->queues; i++)
  397. if (priv->tx_stats[i + 4].len < priv->tx_stats[i + 4].limit)
  398. ieee80211_wake_queue(dev, i);
  399. }
  400. static void p54_rx_frame_sent(struct ieee80211_hw *dev, struct sk_buff *skb)
  401. {
  402. struct p54_common *priv = dev->priv;
  403. struct p54_control_hdr *hdr = (struct p54_control_hdr *) skb->data;
  404. struct p54_frame_sent_hdr *payload = (struct p54_frame_sent_hdr *) hdr->data;
  405. struct sk_buff *entry = (struct sk_buff *) priv->tx_queue.next;
  406. u32 addr = le32_to_cpu(hdr->req_id) - priv->headroom;
  407. struct memrecord *range = NULL;
  408. u32 freed = 0;
  409. u32 last_addr = priv->rx_start;
  410. unsigned long flags;
  411. spin_lock_irqsave(&priv->tx_queue.lock, flags);
  412. while (entry != (struct sk_buff *)&priv->tx_queue) {
  413. struct ieee80211_tx_info *info = IEEE80211_SKB_CB(entry);
  414. range = (void *)info->driver_data;
  415. if (range->start_addr == addr) {
  416. struct p54_control_hdr *entry_hdr;
  417. struct p54_tx_control_allocdata *entry_data;
  418. int pad = 0;
  419. if (entry->next != (struct sk_buff *)&priv->tx_queue) {
  420. struct ieee80211_tx_info *ni;
  421. struct memrecord *mr;
  422. ni = IEEE80211_SKB_CB(entry->next);
  423. mr = (struct memrecord *)ni->driver_data;
  424. freed = mr->start_addr - last_addr;
  425. } else
  426. freed = priv->rx_end - last_addr;
  427. last_addr = range->end_addr;
  428. __skb_unlink(entry, &priv->tx_queue);
  429. spin_unlock_irqrestore(&priv->tx_queue.lock, flags);
  430. memset(&info->status, 0, sizeof(info->status));
  431. entry_hdr = (struct p54_control_hdr *) entry->data;
  432. entry_data = (struct p54_tx_control_allocdata *) entry_hdr->data;
  433. if ((entry_hdr->magic1 & cpu_to_le16(0x4000)) != 0)
  434. pad = entry_data->align[0];
  435. priv->tx_stats[entry_data->hw_queue].len--;
  436. if (!(info->flags & IEEE80211_TX_CTL_NO_ACK)) {
  437. if (!(payload->status & 0x01))
  438. info->flags |= IEEE80211_TX_STAT_ACK;
  439. else
  440. info->status.excessive_retries = 1;
  441. }
  442. info->status.retry_count = payload->retries - 1;
  443. info->status.ack_signal = le16_to_cpu(payload->ack_rssi);
  444. skb_pull(entry, sizeof(*hdr) + pad + sizeof(*entry_data));
  445. ieee80211_tx_status_irqsafe(dev, entry);
  446. goto out;
  447. } else
  448. last_addr = range->end_addr;
  449. entry = entry->next;
  450. }
  451. spin_unlock_irqrestore(&priv->tx_queue.lock, flags);
  452. out:
  453. if (freed >= IEEE80211_MAX_RTS_THRESHOLD + 0x170 +
  454. sizeof(struct p54_control_hdr))
  455. p54_wake_free_queues(dev);
  456. }
  457. static void p54_rx_eeprom_readback(struct ieee80211_hw *dev,
  458. struct sk_buff *skb)
  459. {
  460. struct p54_control_hdr *hdr = (struct p54_control_hdr *) skb->data;
  461. struct p54_eeprom_lm86 *eeprom = (struct p54_eeprom_lm86 *) hdr->data;
  462. struct p54_common *priv = dev->priv;
  463. if (!priv->eeprom)
  464. return ;
  465. memcpy(priv->eeprom, eeprom->data, eeprom->len);
  466. complete(&priv->eeprom_comp);
  467. }
  468. static void p54_rx_control(struct ieee80211_hw *dev, struct sk_buff *skb)
  469. {
  470. struct p54_control_hdr *hdr = (struct p54_control_hdr *) skb->data;
  471. switch (le16_to_cpu(hdr->type)) {
  472. case P54_CONTROL_TYPE_TXDONE:
  473. p54_rx_frame_sent(dev, skb);
  474. break;
  475. case P54_CONTROL_TYPE_BBP:
  476. break;
  477. case P54_CONTROL_TYPE_EEPROM_READBACK:
  478. p54_rx_eeprom_readback(dev, skb);
  479. break;
  480. default:
  481. printk(KERN_DEBUG "%s: not handling 0x%02x type control frame\n",
  482. wiphy_name(dev->wiphy), le16_to_cpu(hdr->type));
  483. break;
  484. }
  485. }
  486. /* returns zero if skb can be reused */
  487. int p54_rx(struct ieee80211_hw *dev, struct sk_buff *skb)
  488. {
  489. u8 type = le16_to_cpu(*((__le16 *)skb->data)) >> 8;
  490. switch (type) {
  491. case 0x00:
  492. case 0x01:
  493. p54_rx_data(dev, skb);
  494. return -1;
  495. case 0x4d:
  496. /* TODO: do something better... but then again, I've never seen this happen */
  497. printk(KERN_ERR "%s: Received fault. Probably need to restart hardware now..\n",
  498. wiphy_name(dev->wiphy));
  499. break;
  500. case 0x80:
  501. p54_rx_control(dev, skb);
  502. break;
  503. default:
  504. printk(KERN_ERR "%s: unknown frame RXed (0x%02x)\n",
  505. wiphy_name(dev->wiphy), type);
  506. break;
  507. }
  508. return 0;
  509. }
  510. EXPORT_SYMBOL_GPL(p54_rx);
  511. /*
  512. * So, the firmware is somewhat stupid and doesn't know what places in its
  513. * memory incoming data should go to. By poking around in the firmware, we
  514. * can find some unused memory to upload our packets to. However, data that we
  515. * want the card to TX needs to stay intact until the card has told us that
  516. * it is done with it. This function finds empty places we can upload to and
  517. * marks allocated areas as reserved if necessary. p54_rx_frame_sent frees
  518. * allocated areas.
  519. */
  520. static void p54_assign_address(struct ieee80211_hw *dev, struct sk_buff *skb,
  521. struct p54_control_hdr *data, u32 len)
  522. {
  523. struct p54_common *priv = dev->priv;
  524. struct sk_buff *entry = priv->tx_queue.next;
  525. struct sk_buff *target_skb = NULL;
  526. u32 last_addr = priv->rx_start;
  527. u32 largest_hole = 0;
  528. u32 target_addr = priv->rx_start;
  529. unsigned long flags;
  530. unsigned int left;
  531. len = (len + priv->headroom + priv->tailroom + 3) & ~0x3;
  532. spin_lock_irqsave(&priv->tx_queue.lock, flags);
  533. left = skb_queue_len(&priv->tx_queue);
  534. while (left--) {
  535. u32 hole_size;
  536. struct ieee80211_tx_info *info = IEEE80211_SKB_CB(entry);
  537. struct memrecord *range = (void *)info->driver_data;
  538. hole_size = range->start_addr - last_addr;
  539. if (!target_skb && hole_size >= len) {
  540. target_skb = entry->prev;
  541. hole_size -= len;
  542. target_addr = last_addr;
  543. }
  544. largest_hole = max(largest_hole, hole_size);
  545. last_addr = range->end_addr;
  546. entry = entry->next;
  547. }
  548. if (!target_skb && priv->rx_end - last_addr >= len) {
  549. target_skb = priv->tx_queue.prev;
  550. largest_hole = max(largest_hole, priv->rx_end - last_addr - len);
  551. if (!skb_queue_empty(&priv->tx_queue)) {
  552. struct ieee80211_tx_info *info = IEEE80211_SKB_CB(target_skb);
  553. struct memrecord *range = (void *)info->driver_data;
  554. target_addr = range->end_addr;
  555. }
  556. } else
  557. largest_hole = max(largest_hole, priv->rx_end - last_addr);
  558. if (skb) {
  559. struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
  560. struct memrecord *range = (void *)info->driver_data;
  561. range->start_addr = target_addr;
  562. range->end_addr = target_addr + len;
  563. __skb_queue_after(&priv->tx_queue, target_skb, skb);
  564. if (largest_hole < priv->rx_mtu + priv->headroom +
  565. priv->tailroom +
  566. sizeof(struct p54_control_hdr))
  567. ieee80211_stop_queues(dev);
  568. }
  569. spin_unlock_irqrestore(&priv->tx_queue.lock, flags);
  570. data->req_id = cpu_to_le32(target_addr + priv->headroom);
  571. }
  572. int p54_read_eeprom(struct ieee80211_hw *dev)
  573. {
  574. struct p54_common *priv = dev->priv;
  575. struct p54_control_hdr *hdr = NULL;
  576. struct p54_eeprom_lm86 *eeprom_hdr;
  577. size_t eeprom_size = 0x2020, offset = 0, blocksize;
  578. int ret = -ENOMEM;
  579. void *eeprom = NULL;
  580. hdr = (struct p54_control_hdr *)kzalloc(sizeof(*hdr) +
  581. sizeof(*eeprom_hdr) + EEPROM_READBACK_LEN, GFP_KERNEL);
  582. if (!hdr)
  583. goto free;
  584. priv->eeprom = kzalloc(EEPROM_READBACK_LEN, GFP_KERNEL);
  585. if (!priv->eeprom)
  586. goto free;
  587. eeprom = kzalloc(eeprom_size, GFP_KERNEL);
  588. if (!eeprom)
  589. goto free;
  590. hdr->magic1 = cpu_to_le16(0x8000);
  591. hdr->type = cpu_to_le16(P54_CONTROL_TYPE_EEPROM_READBACK);
  592. hdr->retry1 = hdr->retry2 = 0;
  593. eeprom_hdr = (struct p54_eeprom_lm86 *) hdr->data;
  594. while (eeprom_size) {
  595. blocksize = min(eeprom_size, (size_t)EEPROM_READBACK_LEN);
  596. hdr->len = cpu_to_le16(blocksize + sizeof(*eeprom_hdr));
  597. eeprom_hdr->offset = cpu_to_le16(offset);
  598. eeprom_hdr->len = cpu_to_le16(blocksize);
  599. p54_assign_address(dev, NULL, hdr, hdr->len + sizeof(*hdr));
  600. priv->tx(dev, hdr, hdr->len + sizeof(*hdr), 0);
  601. if (!wait_for_completion_interruptible_timeout(&priv->eeprom_comp, HZ)) {
  602. printk(KERN_ERR "%s: device does not respond!\n",
  603. wiphy_name(dev->wiphy));
  604. ret = -EBUSY;
  605. goto free;
  606. }
  607. memcpy(eeprom + offset, priv->eeprom, blocksize);
  608. offset += blocksize;
  609. eeprom_size -= blocksize;
  610. }
  611. ret = p54_parse_eeprom(dev, eeprom, offset);
  612. free:
  613. kfree(priv->eeprom);
  614. priv->eeprom = NULL;
  615. kfree(hdr);
  616. kfree(eeprom);
  617. return ret;
  618. }
  619. EXPORT_SYMBOL_GPL(p54_read_eeprom);
  620. static int p54_tx(struct ieee80211_hw *dev, struct sk_buff *skb)
  621. {
  622. struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
  623. struct ieee80211_tx_queue_stats *current_queue;
  624. struct p54_common *priv = dev->priv;
  625. struct p54_control_hdr *hdr;
  626. struct ieee80211_hdr *ieee80211hdr = (struct ieee80211_hdr *)skb->data;
  627. struct p54_tx_control_allocdata *txhdr;
  628. size_t padding, len;
  629. u8 rate;
  630. u8 cts_rate = 0x20;
  631. current_queue = &priv->tx_stats[skb_get_queue_mapping(skb) + 4];
  632. if (unlikely(current_queue->len > current_queue->limit))
  633. return NETDEV_TX_BUSY;
  634. current_queue->len++;
  635. current_queue->count++;
  636. if (current_queue->len == current_queue->limit)
  637. ieee80211_stop_queue(dev, skb_get_queue_mapping(skb));
  638. padding = (unsigned long)(skb->data - (sizeof(*hdr) + sizeof(*txhdr))) & 3;
  639. len = skb->len;
  640. txhdr = (struct p54_tx_control_allocdata *)
  641. skb_push(skb, sizeof(*txhdr) + padding);
  642. hdr = (struct p54_control_hdr *) skb_push(skb, sizeof(*hdr));
  643. if (padding)
  644. hdr->magic1 = cpu_to_le16(0x4010);
  645. else
  646. hdr->magic1 = cpu_to_le16(0x0010);
  647. hdr->len = cpu_to_le16(len);
  648. hdr->type = (info->flags & IEEE80211_TX_CTL_NO_ACK) ? 0 : cpu_to_le16(1);
  649. hdr->retry1 = hdr->retry2 = info->control.retry_limit;
  650. /* TODO: add support for alternate retry TX rates */
  651. rate = ieee80211_get_tx_rate(dev, info)->hw_value;
  652. if (info->flags & IEEE80211_TX_CTL_SHORT_PREAMBLE) {
  653. rate |= 0x10;
  654. cts_rate |= 0x10;
  655. }
  656. if (info->flags & IEEE80211_TX_CTL_USE_RTS_CTS) {
  657. rate |= 0x40;
  658. cts_rate |= ieee80211_get_rts_cts_rate(dev, info)->hw_value;
  659. } else if (info->flags & IEEE80211_TX_CTL_USE_CTS_PROTECT) {
  660. rate |= 0x20;
  661. cts_rate |= ieee80211_get_rts_cts_rate(dev, info)->hw_value;
  662. }
  663. memset(txhdr->rateset, rate, 8);
  664. txhdr->key_type = 0;
  665. txhdr->key_len = 0;
  666. txhdr->hw_queue = skb_get_queue_mapping(skb) + 4;
  667. txhdr->tx_antenna = (info->antenna_sel_tx == 0) ?
  668. 2 : info->antenna_sel_tx - 1;
  669. txhdr->output_power = 0x7f; // HW Maximum
  670. txhdr->cts_rate = (info->flags & IEEE80211_TX_CTL_NO_ACK) ?
  671. 0 : cts_rate;
  672. if (padding)
  673. txhdr->align[0] = padding;
  674. /* FIXME: The sequence that follows is needed for this driver to
  675. * work with mac80211 since "mac80211: fix TX sequence numbers".
  676. * As with the temporary code in rt2x00, changes will be needed
  677. * to get proper sequence numbers on beacons. In addition, this
  678. * patch places the sequence number in the hardware state, which
  679. * limits us to a single virtual state.
  680. */
  681. if (info->flags & IEEE80211_TX_CTL_ASSIGN_SEQ) {
  682. if (info->flags & IEEE80211_TX_CTL_FIRST_FRAGMENT)
  683. priv->seqno += 0x10;
  684. ieee80211hdr->seq_ctrl &= cpu_to_le16(IEEE80211_SCTL_FRAG);
  685. ieee80211hdr->seq_ctrl |= cpu_to_le16(priv->seqno);
  686. }
  687. /* modifies skb->cb and with it info, so must be last! */
  688. p54_assign_address(dev, skb, hdr, skb->len);
  689. priv->tx(dev, hdr, skb->len, 0);
  690. return 0;
  691. }
  692. static int p54_set_filter(struct ieee80211_hw *dev, u16 filter_type,
  693. const u8 *dst, const u8 *src, u8 antenna,
  694. u32 magic3, u32 magic8, u32 magic9)
  695. {
  696. struct p54_common *priv = dev->priv;
  697. struct p54_control_hdr *hdr;
  698. struct p54_tx_control_filter *filter;
  699. hdr = kzalloc(sizeof(*hdr) + sizeof(*filter) +
  700. priv->tx_hdr_len, GFP_ATOMIC);
  701. if (!hdr)
  702. return -ENOMEM;
  703. hdr = (void *)hdr + priv->tx_hdr_len;
  704. filter = (struct p54_tx_control_filter *) hdr->data;
  705. hdr->magic1 = cpu_to_le16(0x8001);
  706. hdr->len = cpu_to_le16(sizeof(*filter));
  707. p54_assign_address(dev, NULL, hdr, sizeof(*hdr) + sizeof(*filter));
  708. hdr->type = cpu_to_le16(P54_CONTROL_TYPE_FILTER_SET);
  709. filter->filter_type = cpu_to_le16(filter_type);
  710. memcpy(filter->dst, dst, ETH_ALEN);
  711. if (!src)
  712. memset(filter->src, ~0, ETH_ALEN);
  713. else
  714. memcpy(filter->src, src, ETH_ALEN);
  715. filter->antenna = antenna;
  716. filter->magic3 = cpu_to_le32(magic3);
  717. filter->rx_addr = cpu_to_le32(priv->rx_end);
  718. filter->max_rx = cpu_to_le16(priv->rx_mtu);
  719. filter->rxhw = cpu_to_le16(priv->rxhw);
  720. filter->magic8 = cpu_to_le16(magic8);
  721. filter->magic9 = cpu_to_le16(magic9);
  722. priv->tx(dev, hdr, sizeof(*hdr) + sizeof(*filter), 1);
  723. return 0;
  724. }
  725. static int p54_set_freq(struct ieee80211_hw *dev, __le16 freq)
  726. {
  727. struct p54_common *priv = dev->priv;
  728. struct p54_control_hdr *hdr;
  729. struct p54_tx_control_channel *chan;
  730. unsigned int i;
  731. void *entry;
  732. hdr = kzalloc(sizeof(*hdr) + sizeof(*chan) +
  733. priv->tx_hdr_len, GFP_KERNEL);
  734. if (!hdr)
  735. return -ENOMEM;
  736. hdr = (void *)hdr + priv->tx_hdr_len;
  737. chan = (struct p54_tx_control_channel *) hdr->data;
  738. hdr->magic1 = cpu_to_le16(0x8001);
  739. hdr->len = cpu_to_le16(sizeof(*chan));
  740. hdr->type = cpu_to_le16(P54_CONTROL_TYPE_CHANNEL_CHANGE);
  741. p54_assign_address(dev, NULL, hdr, sizeof(*hdr) + sizeof(*chan));
  742. chan->flags = cpu_to_le16(0x1);
  743. chan->dwell = cpu_to_le16(0x0);
  744. for (i = 0; i < priv->iq_autocal_len; i++) {
  745. if (priv->iq_autocal[i].freq != freq)
  746. continue;
  747. memcpy(&chan->iq_autocal, &priv->iq_autocal[i],
  748. sizeof(*priv->iq_autocal));
  749. break;
  750. }
  751. if (i == priv->iq_autocal_len)
  752. goto err;
  753. for (i = 0; i < priv->output_limit_len; i++) {
  754. if (priv->output_limit[i].freq != freq)
  755. continue;
  756. chan->val_barker = 0x38;
  757. chan->val_bpsk = chan->dup_bpsk =
  758. priv->output_limit[i].val_bpsk;
  759. chan->val_qpsk = chan->dup_qpsk =
  760. priv->output_limit[i].val_qpsk;
  761. chan->val_16qam = chan->dup_16qam =
  762. priv->output_limit[i].val_16qam;
  763. chan->val_64qam = chan->dup_64qam =
  764. priv->output_limit[i].val_64qam;
  765. break;
  766. }
  767. if (i == priv->output_limit_len)
  768. goto err;
  769. entry = priv->curve_data->data;
  770. for (i = 0; i < priv->curve_data->channels; i++) {
  771. if (*((__le16 *)entry) != freq) {
  772. entry += sizeof(__le16);
  773. entry += sizeof(struct p54_pa_curve_data_sample) *
  774. priv->curve_data->points_per_channel;
  775. continue;
  776. }
  777. entry += sizeof(__le16);
  778. chan->pa_points_per_curve =
  779. min(priv->curve_data->points_per_channel, (u8) 8);
  780. memcpy(chan->curve_data, entry, sizeof(*chan->curve_data) *
  781. chan->pa_points_per_curve);
  782. break;
  783. }
  784. chan->rssical_mul = cpu_to_le16(130);
  785. chan->rssical_add = cpu_to_le16(0xfe70); /* -400 */
  786. priv->tx(dev, hdr, sizeof(*hdr) + sizeof(*chan), 1);
  787. return 0;
  788. err:
  789. printk(KERN_ERR "%s: frequency change failed\n", wiphy_name(dev->wiphy));
  790. kfree(hdr);
  791. return -EINVAL;
  792. }
  793. static int p54_set_leds(struct ieee80211_hw *dev, int mode, int link, int act)
  794. {
  795. struct p54_common *priv = dev->priv;
  796. struct p54_control_hdr *hdr;
  797. struct p54_tx_control_led *led;
  798. hdr = kzalloc(sizeof(*hdr) + sizeof(*led) +
  799. priv->tx_hdr_len, GFP_KERNEL);
  800. if (!hdr)
  801. return -ENOMEM;
  802. hdr = (void *)hdr + priv->tx_hdr_len;
  803. hdr->magic1 = cpu_to_le16(0x8001);
  804. hdr->len = cpu_to_le16(sizeof(*led));
  805. hdr->type = cpu_to_le16(P54_CONTROL_TYPE_LED);
  806. p54_assign_address(dev, NULL, hdr, sizeof(*hdr) + sizeof(*led));
  807. led = (struct p54_tx_control_led *) hdr->data;
  808. led->mode = cpu_to_le16(mode);
  809. led->led_permanent = cpu_to_le16(link);
  810. led->led_temporary = cpu_to_le16(act);
  811. led->duration = cpu_to_le16(1000);
  812. priv->tx(dev, hdr, sizeof(*hdr) + sizeof(*led), 1);
  813. return 0;
  814. }
  815. #define P54_SET_QUEUE(queue, ai_fs, cw_min, cw_max, _txop) \
  816. do { \
  817. queue.aifs = cpu_to_le16(ai_fs); \
  818. queue.cwmin = cpu_to_le16(cw_min); \
  819. queue.cwmax = cpu_to_le16(cw_max); \
  820. queue.txop = cpu_to_le16(_txop); \
  821. } while(0)
  822. static void p54_init_vdcf(struct ieee80211_hw *dev)
  823. {
  824. struct p54_common *priv = dev->priv;
  825. struct p54_control_hdr *hdr;
  826. struct p54_tx_control_vdcf *vdcf;
  827. /* all USB V1 adapters need a extra headroom */
  828. hdr = (void *)priv->cached_vdcf + priv->tx_hdr_len;
  829. hdr->magic1 = cpu_to_le16(0x8001);
  830. hdr->len = cpu_to_le16(sizeof(*vdcf));
  831. hdr->type = cpu_to_le16(P54_CONTROL_TYPE_DCFINIT);
  832. hdr->req_id = cpu_to_le32(priv->rx_start);
  833. vdcf = (struct p54_tx_control_vdcf *) hdr->data;
  834. P54_SET_QUEUE(vdcf->queue[0], 0x0002, 0x0003, 0x0007, 47);
  835. P54_SET_QUEUE(vdcf->queue[1], 0x0002, 0x0007, 0x000f, 94);
  836. P54_SET_QUEUE(vdcf->queue[2], 0x0003, 0x000f, 0x03ff, 0);
  837. P54_SET_QUEUE(vdcf->queue[3], 0x0007, 0x000f, 0x03ff, 0);
  838. }
  839. static void p54_set_vdcf(struct ieee80211_hw *dev)
  840. {
  841. struct p54_common *priv = dev->priv;
  842. struct p54_control_hdr *hdr;
  843. struct p54_tx_control_vdcf *vdcf;
  844. hdr = (void *)priv->cached_vdcf + priv->tx_hdr_len;
  845. p54_assign_address(dev, NULL, hdr, sizeof(*hdr) + sizeof(*vdcf));
  846. vdcf = (struct p54_tx_control_vdcf *) hdr->data;
  847. if (dev->conf.flags & IEEE80211_CONF_SHORT_SLOT_TIME) {
  848. vdcf->slottime = 9;
  849. vdcf->magic1 = 0x10;
  850. vdcf->magic2 = 0x00;
  851. } else {
  852. vdcf->slottime = 20;
  853. vdcf->magic1 = 0x0a;
  854. vdcf->magic2 = 0x06;
  855. }
  856. /* (see prism54/isl_oid.h for further details) */
  857. vdcf->frameburst = cpu_to_le16(0);
  858. priv->tx(dev, hdr, sizeof(*hdr) + sizeof(*vdcf), 0);
  859. }
  860. static int p54_start(struct ieee80211_hw *dev)
  861. {
  862. struct p54_common *priv = dev->priv;
  863. int err;
  864. if (!priv->cached_vdcf) {
  865. priv->cached_vdcf = kzalloc(sizeof(struct p54_tx_control_vdcf)+
  866. priv->tx_hdr_len + sizeof(struct p54_control_hdr),
  867. GFP_KERNEL);
  868. if (!priv->cached_vdcf)
  869. return -ENOMEM;
  870. }
  871. err = priv->open(dev);
  872. if (!err)
  873. priv->mode = IEEE80211_IF_TYPE_MNTR;
  874. p54_init_vdcf(dev);
  875. return err;
  876. }
  877. static void p54_stop(struct ieee80211_hw *dev)
  878. {
  879. struct p54_common *priv = dev->priv;
  880. struct sk_buff *skb;
  881. while ((skb = skb_dequeue(&priv->tx_queue)))
  882. kfree_skb(skb);
  883. priv->stop(dev);
  884. priv->mode = IEEE80211_IF_TYPE_INVALID;
  885. }
  886. static int p54_add_interface(struct ieee80211_hw *dev,
  887. struct ieee80211_if_init_conf *conf)
  888. {
  889. struct p54_common *priv = dev->priv;
  890. if (priv->mode != IEEE80211_IF_TYPE_MNTR)
  891. return -EOPNOTSUPP;
  892. switch (conf->type) {
  893. case IEEE80211_IF_TYPE_STA:
  894. priv->mode = conf->type;
  895. break;
  896. default:
  897. return -EOPNOTSUPP;
  898. }
  899. memcpy(priv->mac_addr, conf->mac_addr, ETH_ALEN);
  900. p54_set_filter(dev, 0, priv->mac_addr, NULL, 0, 1, 0, 0xF642);
  901. p54_set_filter(dev, 0, priv->mac_addr, NULL, 1, 0, 0, 0xF642);
  902. switch (conf->type) {
  903. case IEEE80211_IF_TYPE_STA:
  904. p54_set_filter(dev, 1, priv->mac_addr, NULL, 0, 0x15F, 0x1F4, 0);
  905. break;
  906. default:
  907. BUG(); /* impossible */
  908. break;
  909. }
  910. p54_set_leds(dev, 1, 0, 0);
  911. return 0;
  912. }
  913. static void p54_remove_interface(struct ieee80211_hw *dev,
  914. struct ieee80211_if_init_conf *conf)
  915. {
  916. struct p54_common *priv = dev->priv;
  917. priv->mode = IEEE80211_IF_TYPE_MNTR;
  918. memset(priv->mac_addr, 0, ETH_ALEN);
  919. p54_set_filter(dev, 0, priv->mac_addr, NULL, 2, 0, 0, 0);
  920. }
  921. static int p54_config(struct ieee80211_hw *dev, struct ieee80211_conf *conf)
  922. {
  923. int ret;
  924. struct p54_common *priv = dev->priv;
  925. mutex_lock(&priv->conf_mutex);
  926. ret = p54_set_freq(dev, cpu_to_le16(conf->channel->center_freq));
  927. p54_set_vdcf(dev);
  928. mutex_unlock(&priv->conf_mutex);
  929. return ret;
  930. }
  931. static int p54_config_interface(struct ieee80211_hw *dev,
  932. struct ieee80211_vif *vif,
  933. struct ieee80211_if_conf *conf)
  934. {
  935. struct p54_common *priv = dev->priv;
  936. mutex_lock(&priv->conf_mutex);
  937. p54_set_filter(dev, 0, priv->mac_addr, conf->bssid, 0, 1, 0, 0xF642);
  938. p54_set_filter(dev, 0, priv->mac_addr, conf->bssid, 2, 0, 0, 0);
  939. p54_set_leds(dev, 1, !is_multicast_ether_addr(conf->bssid), 0);
  940. memcpy(priv->bssid, conf->bssid, ETH_ALEN);
  941. mutex_unlock(&priv->conf_mutex);
  942. return 0;
  943. }
  944. static void p54_configure_filter(struct ieee80211_hw *dev,
  945. unsigned int changed_flags,
  946. unsigned int *total_flags,
  947. int mc_count, struct dev_mc_list *mclist)
  948. {
  949. struct p54_common *priv = dev->priv;
  950. *total_flags &= FIF_BCN_PRBRESP_PROMISC;
  951. if (changed_flags & FIF_BCN_PRBRESP_PROMISC) {
  952. if (*total_flags & FIF_BCN_PRBRESP_PROMISC)
  953. p54_set_filter(dev, 0, priv->mac_addr,
  954. NULL, 2, 0, 0, 0);
  955. else
  956. p54_set_filter(dev, 0, priv->mac_addr,
  957. priv->bssid, 2, 0, 0, 0);
  958. }
  959. }
  960. static int p54_conf_tx(struct ieee80211_hw *dev, u16 queue,
  961. const struct ieee80211_tx_queue_params *params)
  962. {
  963. struct p54_common *priv = dev->priv;
  964. struct p54_tx_control_vdcf *vdcf;
  965. vdcf = (struct p54_tx_control_vdcf *)(((struct p54_control_hdr *)
  966. ((void *)priv->cached_vdcf + priv->tx_hdr_len))->data);
  967. if ((params) && !(queue > 4)) {
  968. P54_SET_QUEUE(vdcf->queue[queue], params->aifs,
  969. params->cw_min, params->cw_max, params->txop);
  970. } else
  971. return -EINVAL;
  972. p54_set_vdcf(dev);
  973. return 0;
  974. }
  975. static int p54_get_stats(struct ieee80211_hw *dev,
  976. struct ieee80211_low_level_stats *stats)
  977. {
  978. /* TODO */
  979. return 0;
  980. }
  981. static int p54_get_tx_stats(struct ieee80211_hw *dev,
  982. struct ieee80211_tx_queue_stats *stats)
  983. {
  984. struct p54_common *priv = dev->priv;
  985. memcpy(stats, &priv->tx_stats[4], sizeof(stats[0]) * dev->queues);
  986. return 0;
  987. }
  988. static const struct ieee80211_ops p54_ops = {
  989. .tx = p54_tx,
  990. .start = p54_start,
  991. .stop = p54_stop,
  992. .add_interface = p54_add_interface,
  993. .remove_interface = p54_remove_interface,
  994. .config = p54_config,
  995. .config_interface = p54_config_interface,
  996. .configure_filter = p54_configure_filter,
  997. .conf_tx = p54_conf_tx,
  998. .get_stats = p54_get_stats,
  999. .get_tx_stats = p54_get_tx_stats
  1000. };
  1001. struct ieee80211_hw *p54_init_common(size_t priv_data_len)
  1002. {
  1003. struct ieee80211_hw *dev;
  1004. struct p54_common *priv;
  1005. dev = ieee80211_alloc_hw(priv_data_len, &p54_ops);
  1006. if (!dev)
  1007. return NULL;
  1008. priv = dev->priv;
  1009. priv->mode = IEEE80211_IF_TYPE_INVALID;
  1010. skb_queue_head_init(&priv->tx_queue);
  1011. dev->flags = IEEE80211_HW_HOST_BROADCAST_PS_BUFFERING | /* not sure */
  1012. IEEE80211_HW_RX_INCLUDES_FCS |
  1013. IEEE80211_HW_SIGNAL_UNSPEC;
  1014. dev->wiphy->interface_modes = BIT(NL80211_IFTYPE_STATION);
  1015. dev->channel_change_time = 1000; /* TODO: find actual value */
  1016. dev->max_signal = 127;
  1017. priv->tx_stats[0].limit = 1;
  1018. priv->tx_stats[1].limit = 1;
  1019. priv->tx_stats[2].limit = 1;
  1020. priv->tx_stats[3].limit = 1;
  1021. priv->tx_stats[4].limit = 5;
  1022. dev->queues = 1;
  1023. dev->extra_tx_headroom = sizeof(struct p54_control_hdr) + 4 +
  1024. sizeof(struct p54_tx_control_allocdata);
  1025. mutex_init(&priv->conf_mutex);
  1026. init_completion(&priv->eeprom_comp);
  1027. return dev;
  1028. }
  1029. EXPORT_SYMBOL_GPL(p54_init_common);
  1030. void p54_free_common(struct ieee80211_hw *dev)
  1031. {
  1032. struct p54_common *priv = dev->priv;
  1033. kfree(priv->iq_autocal);
  1034. kfree(priv->output_limit);
  1035. kfree(priv->curve_data);
  1036. kfree(priv->cached_vdcf);
  1037. }
  1038. EXPORT_SYMBOL_GPL(p54_free_common);
  1039. static int __init p54_init(void)
  1040. {
  1041. return 0;
  1042. }
  1043. static void __exit p54_exit(void)
  1044. {
  1045. }
  1046. module_init(p54_init);
  1047. module_exit(p54_exit);