dhd_linux.c 30 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239
  1. /*
  2. * Copyright (c) 2010 Broadcom Corporation
  3. *
  4. * Permission to use, copy, modify, and/or distribute this software for any
  5. * purpose with or without fee is hereby granted, provided that the above
  6. * copyright notice and this permission notice appear in all copies.
  7. *
  8. * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
  9. * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
  10. * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
  11. * SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
  12. * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
  13. * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
  14. * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  15. */
  16. #include <linux/init.h>
  17. #include <linux/kernel.h>
  18. #include <linux/kthread.h>
  19. #include <linux/slab.h>
  20. #include <linux/skbuff.h>
  21. #include <linux/netdevice.h>
  22. #include <linux/etherdevice.h>
  23. #include <linux/mmc/sdio_func.h>
  24. #include <linux/random.h>
  25. #include <linux/spinlock.h>
  26. #include <linux/ethtool.h>
  27. #include <linux/fcntl.h>
  28. #include <linux/fs.h>
  29. #include <linux/uaccess.h>
  30. #include <linux/hardirq.h>
  31. #include <linux/mutex.h>
  32. #include <linux/wait.h>
  33. #include <linux/module.h>
  34. #include <net/cfg80211.h>
  35. #include <net/rtnetlink.h>
  36. #include <defs.h>
  37. #include <brcmu_utils.h>
  38. #include <brcmu_wifi.h>
  39. #include "dhd.h"
  40. #include "dhd_bus.h"
  41. #include "dhd_proto.h"
  42. #include "dhd_dbg.h"
  43. #include "wl_cfg80211.h"
  44. MODULE_AUTHOR("Broadcom Corporation");
  45. MODULE_DESCRIPTION("Broadcom 802.11n wireless LAN fullmac driver.");
  46. MODULE_SUPPORTED_DEVICE("Broadcom 802.11n WLAN fullmac cards");
  47. MODULE_LICENSE("Dual BSD/GPL");
  48. /* Interface control information */
  49. struct brcmf_if {
  50. struct brcmf_info *info; /* back pointer to brcmf_info */
  51. /* OS/stack specifics */
  52. struct net_device *ndev;
  53. struct net_device_stats stats;
  54. int idx; /* iface idx in dongle */
  55. u8 mac_addr[ETH_ALEN]; /* assigned MAC address */
  56. };
  57. /* Local private structure (extension of pub) */
  58. struct brcmf_info {
  59. struct brcmf_pub pub;
  60. /* OS/stack specifics */
  61. struct brcmf_if *iflist[BRCMF_MAX_IFS];
  62. struct mutex proto_block;
  63. struct work_struct setmacaddr_work;
  64. struct work_struct multicast_work;
  65. u8 macvalue[ETH_ALEN];
  66. atomic_t pend_8021x_cnt;
  67. };
  68. /* Error bits */
  69. int brcmf_msg_level = BRCMF_ERROR_VAL;
  70. module_param(brcmf_msg_level, int, 0);
  71. int brcmf_ifname2idx(struct brcmf_info *drvr_priv, char *name)
  72. {
  73. int i = BRCMF_MAX_IFS;
  74. struct brcmf_if *ifp;
  75. if (name == NULL || *name == '\0')
  76. return 0;
  77. while (--i > 0) {
  78. ifp = drvr_priv->iflist[i];
  79. if (ifp && !strncmp(ifp->ndev->name, name, IFNAMSIZ))
  80. break;
  81. }
  82. brcmf_dbg(TRACE, "return idx %d for \"%s\"\n", i, name);
  83. return i; /* default - the primary interface */
  84. }
  85. char *brcmf_ifname(struct brcmf_pub *drvr, int ifidx)
  86. {
  87. struct brcmf_info *drvr_priv = drvr->info;
  88. if (ifidx < 0 || ifidx >= BRCMF_MAX_IFS) {
  89. brcmf_dbg(ERROR, "ifidx %d out of range\n", ifidx);
  90. return "<if_bad>";
  91. }
  92. if (drvr_priv->iflist[ifidx] == NULL) {
  93. brcmf_dbg(ERROR, "null i/f %d\n", ifidx);
  94. return "<if_null>";
  95. }
  96. if (drvr_priv->iflist[ifidx]->ndev)
  97. return drvr_priv->iflist[ifidx]->ndev->name;
  98. return "<if_none>";
  99. }
  100. static void _brcmf_set_multicast_list(struct work_struct *work)
  101. {
  102. struct net_device *ndev;
  103. struct netdev_hw_addr *ha;
  104. u32 dcmd_value, cnt;
  105. __le32 cnt_le;
  106. __le32 dcmd_le_value;
  107. struct brcmf_dcmd dcmd;
  108. char *buf, *bufp;
  109. uint buflen;
  110. int ret;
  111. struct brcmf_info *drvr_priv = container_of(work, struct brcmf_info,
  112. multicast_work);
  113. ndev = drvr_priv->iflist[0]->ndev;
  114. cnt = netdev_mc_count(ndev);
  115. /* Determine initial value of allmulti flag */
  116. dcmd_value = (ndev->flags & IFF_ALLMULTI) ? true : false;
  117. /* Send down the multicast list first. */
  118. buflen = sizeof("mcast_list") + sizeof(cnt) + (cnt * ETH_ALEN);
  119. bufp = buf = kmalloc(buflen, GFP_ATOMIC);
  120. if (!bufp)
  121. return;
  122. strcpy(bufp, "mcast_list");
  123. bufp += strlen("mcast_list") + 1;
  124. cnt_le = cpu_to_le32(cnt);
  125. memcpy(bufp, &cnt_le, sizeof(cnt));
  126. bufp += sizeof(cnt_le);
  127. netdev_for_each_mc_addr(ha, ndev) {
  128. if (!cnt)
  129. break;
  130. memcpy(bufp, ha->addr, ETH_ALEN);
  131. bufp += ETH_ALEN;
  132. cnt--;
  133. }
  134. memset(&dcmd, 0, sizeof(dcmd));
  135. dcmd.cmd = BRCMF_C_SET_VAR;
  136. dcmd.buf = buf;
  137. dcmd.len = buflen;
  138. dcmd.set = true;
  139. ret = brcmf_proto_dcmd(&drvr_priv->pub, 0, &dcmd, dcmd.len);
  140. if (ret < 0) {
  141. brcmf_dbg(ERROR, "%s: set mcast_list failed, cnt %d\n",
  142. brcmf_ifname(&drvr_priv->pub, 0), cnt);
  143. dcmd_value = cnt ? true : dcmd_value;
  144. }
  145. kfree(buf);
  146. /* Now send the allmulti setting. This is based on the setting in the
  147. * net_device flags, but might be modified above to be turned on if we
  148. * were trying to set some addresses and dongle rejected it...
  149. */
  150. buflen = sizeof("allmulti") + sizeof(dcmd_value);
  151. buf = kmalloc(buflen, GFP_ATOMIC);
  152. if (!buf)
  153. return;
  154. dcmd_le_value = cpu_to_le32(dcmd_value);
  155. if (!brcmf_c_mkiovar
  156. ("allmulti", (void *)&dcmd_le_value,
  157. sizeof(dcmd_le_value), buf, buflen)) {
  158. brcmf_dbg(ERROR, "%s: mkiovar failed for allmulti, datalen %d buflen %u\n",
  159. brcmf_ifname(&drvr_priv->pub, 0),
  160. (int)sizeof(dcmd_value), buflen);
  161. kfree(buf);
  162. return;
  163. }
  164. memset(&dcmd, 0, sizeof(dcmd));
  165. dcmd.cmd = BRCMF_C_SET_VAR;
  166. dcmd.buf = buf;
  167. dcmd.len = buflen;
  168. dcmd.set = true;
  169. ret = brcmf_proto_dcmd(&drvr_priv->pub, 0, &dcmd, dcmd.len);
  170. if (ret < 0) {
  171. brcmf_dbg(ERROR, "%s: set allmulti %d failed\n",
  172. brcmf_ifname(&drvr_priv->pub, 0),
  173. le32_to_cpu(dcmd_le_value));
  174. }
  175. kfree(buf);
  176. /* Finally, pick up the PROMISC flag as well, like the NIC
  177. driver does */
  178. dcmd_value = (ndev->flags & IFF_PROMISC) ? true : false;
  179. dcmd_le_value = cpu_to_le32(dcmd_value);
  180. memset(&dcmd, 0, sizeof(dcmd));
  181. dcmd.cmd = BRCMF_C_SET_PROMISC;
  182. dcmd.buf = &dcmd_le_value;
  183. dcmd.len = sizeof(dcmd_le_value);
  184. dcmd.set = true;
  185. ret = brcmf_proto_dcmd(&drvr_priv->pub, 0, &dcmd, dcmd.len);
  186. if (ret < 0) {
  187. brcmf_dbg(ERROR, "%s: set promisc %d failed\n",
  188. brcmf_ifname(&drvr_priv->pub, 0),
  189. le32_to_cpu(dcmd_le_value));
  190. }
  191. }
  192. static void
  193. _brcmf_set_mac_address(struct work_struct *work)
  194. {
  195. char buf[32];
  196. struct brcmf_dcmd dcmd;
  197. int ret;
  198. struct brcmf_info *drvr_priv = container_of(work, struct brcmf_info,
  199. setmacaddr_work);
  200. brcmf_dbg(TRACE, "enter\n");
  201. if (!brcmf_c_mkiovar("cur_etheraddr", (char *)drvr_priv->macvalue,
  202. ETH_ALEN, buf, 32)) {
  203. brcmf_dbg(ERROR, "%s: mkiovar failed for cur_etheraddr\n",
  204. brcmf_ifname(&drvr_priv->pub, 0));
  205. return;
  206. }
  207. memset(&dcmd, 0, sizeof(dcmd));
  208. dcmd.cmd = BRCMF_C_SET_VAR;
  209. dcmd.buf = buf;
  210. dcmd.len = 32;
  211. dcmd.set = true;
  212. ret = brcmf_proto_dcmd(&drvr_priv->pub, 0, &dcmd, dcmd.len);
  213. if (ret < 0)
  214. brcmf_dbg(ERROR, "%s: set cur_etheraddr failed\n",
  215. brcmf_ifname(&drvr_priv->pub, 0));
  216. else
  217. memcpy(drvr_priv->iflist[0]->ndev->dev_addr,
  218. drvr_priv->macvalue, ETH_ALEN);
  219. return;
  220. }
  221. static int brcmf_netdev_set_mac_address(struct net_device *ndev, void *addr)
  222. {
  223. struct brcmf_if *ifp = netdev_priv(ndev);
  224. struct brcmf_info *drvr_priv = ifp->info;
  225. struct sockaddr *sa = (struct sockaddr *)addr;
  226. memcpy(&drvr_priv->macvalue, sa->sa_data, ETH_ALEN);
  227. schedule_work(&drvr_priv->setmacaddr_work);
  228. return 0;
  229. }
  230. static void brcmf_netdev_set_multicast_list(struct net_device *ndev)
  231. {
  232. struct brcmf_if *ifp = netdev_priv(ndev);
  233. struct brcmf_info *drvr_priv = ifp->info;
  234. schedule_work(&drvr_priv->multicast_work);
  235. }
  236. int brcmf_sendpkt(struct brcmf_pub *drvr, int ifidx, struct sk_buff *pktbuf)
  237. {
  238. struct brcmf_info *drvr_priv = drvr->info;
  239. /* Reject if down */
  240. if (!drvr->up || (drvr->bus_if->state == BRCMF_BUS_DOWN))
  241. return -ENODEV;
  242. /* Update multicast statistic */
  243. if (pktbuf->len >= ETH_ALEN) {
  244. u8 *pktdata = (u8 *) (pktbuf->data);
  245. struct ethhdr *eh = (struct ethhdr *)pktdata;
  246. if (is_multicast_ether_addr(eh->h_dest))
  247. drvr->tx_multicast++;
  248. if (ntohs(eh->h_proto) == ETH_P_PAE)
  249. atomic_inc(&drvr_priv->pend_8021x_cnt);
  250. }
  251. /* If the protocol uses a data header, apply it */
  252. brcmf_proto_hdrpush(drvr, ifidx, pktbuf);
  253. /* Use bus module to send data frame */
  254. return brcmf_sdbrcm_bus_txdata(drvr->bus, pktbuf);
  255. }
  256. static int brcmf_netdev_start_xmit(struct sk_buff *skb, struct net_device *ndev)
  257. {
  258. int ret;
  259. struct brcmf_if *ifp = netdev_priv(ndev);
  260. struct brcmf_info *drvr_priv = ifp->info;
  261. brcmf_dbg(TRACE, "Enter\n");
  262. /* Reject if down */
  263. if (!drvr_priv->pub.up ||
  264. (drvr_priv->pub.bus_if->state == BRCMF_BUS_DOWN)) {
  265. brcmf_dbg(ERROR, "xmit rejected pub.up=%d state=%d\n",
  266. drvr_priv->pub.up,
  267. drvr_priv->pub.bus_if->state);
  268. netif_stop_queue(ndev);
  269. return -ENODEV;
  270. }
  271. if (!drvr_priv->iflist[ifp->idx]) {
  272. brcmf_dbg(ERROR, "bad ifidx %d\n", ifp->idx);
  273. netif_stop_queue(ndev);
  274. return -ENODEV;
  275. }
  276. /* Make sure there's enough room for any header */
  277. if (skb_headroom(skb) < drvr_priv->pub.hdrlen) {
  278. struct sk_buff *skb2;
  279. brcmf_dbg(INFO, "%s: insufficient headroom\n",
  280. brcmf_ifname(&drvr_priv->pub, ifp->idx));
  281. drvr_priv->pub.tx_realloc++;
  282. skb2 = skb_realloc_headroom(skb, drvr_priv->pub.hdrlen);
  283. dev_kfree_skb(skb);
  284. skb = skb2;
  285. if (skb == NULL) {
  286. brcmf_dbg(ERROR, "%s: skb_realloc_headroom failed\n",
  287. brcmf_ifname(&drvr_priv->pub, ifp->idx));
  288. ret = -ENOMEM;
  289. goto done;
  290. }
  291. }
  292. ret = brcmf_sendpkt(&drvr_priv->pub, ifp->idx, skb);
  293. done:
  294. if (ret)
  295. drvr_priv->pub.dstats.tx_dropped++;
  296. else
  297. drvr_priv->pub.tx_packets++;
  298. /* Return ok: we always eat the packet */
  299. return 0;
  300. }
  301. void brcmf_txflowcontrol(struct brcmf_pub *drvr, int ifidx, bool state)
  302. {
  303. struct net_device *ndev;
  304. struct brcmf_info *drvr_priv = drvr->info;
  305. brcmf_dbg(TRACE, "Enter\n");
  306. drvr->txoff = state;
  307. ndev = drvr_priv->iflist[ifidx]->ndev;
  308. if (state == ON)
  309. netif_stop_queue(ndev);
  310. else
  311. netif_wake_queue(ndev);
  312. }
  313. static int brcmf_host_event(struct brcmf_info *drvr_priv, int *ifidx,
  314. void *pktdata, struct brcmf_event_msg *event,
  315. void **data)
  316. {
  317. int bcmerror = 0;
  318. bcmerror = brcmf_c_host_event(drvr_priv, ifidx, pktdata, event, data);
  319. if (bcmerror != 0)
  320. return bcmerror;
  321. if (drvr_priv->iflist[*ifidx]->ndev)
  322. brcmf_cfg80211_event(drvr_priv->iflist[*ifidx]->ndev,
  323. event, *data);
  324. return bcmerror;
  325. }
  326. void brcmf_rx_frame(struct brcmf_pub *drvr, int ifidx,
  327. struct sk_buff_head *skb_list)
  328. {
  329. struct brcmf_info *drvr_priv = drvr->info;
  330. unsigned char *eth;
  331. uint len;
  332. void *data;
  333. struct sk_buff *skb, *pnext;
  334. struct brcmf_if *ifp;
  335. struct brcmf_event_msg event;
  336. brcmf_dbg(TRACE, "Enter\n");
  337. skb_queue_walk_safe(skb_list, skb, pnext) {
  338. skb_unlink(skb, skb_list);
  339. /* Get the protocol, maintain skb around eth_type_trans()
  340. * The main reason for this hack is for the limitation of
  341. * Linux 2.4 where 'eth_type_trans' uses the
  342. * 'net->hard_header_len'
  343. * to perform skb_pull inside vs ETH_HLEN. Since to avoid
  344. * coping of the packet coming from the network stack to add
  345. * BDC, Hardware header etc, during network interface
  346. * registration
  347. * we set the 'net->hard_header_len' to ETH_HLEN + extra space
  348. * required
  349. * for BDC, Hardware header etc. and not just the ETH_HLEN
  350. */
  351. eth = skb->data;
  352. len = skb->len;
  353. ifp = drvr_priv->iflist[ifidx];
  354. if (ifp == NULL)
  355. ifp = drvr_priv->iflist[0];
  356. if (!ifp || !ifp->ndev ||
  357. ifp->ndev->reg_state != NETREG_REGISTERED) {
  358. brcmu_pkt_buf_free_skb(skb);
  359. continue;
  360. }
  361. skb->dev = ifp->ndev;
  362. skb->protocol = eth_type_trans(skb, skb->dev);
  363. if (skb->pkt_type == PACKET_MULTICAST)
  364. drvr_priv->pub.rx_multicast++;
  365. skb->data = eth;
  366. skb->len = len;
  367. /* Strip header, count, deliver upward */
  368. skb_pull(skb, ETH_HLEN);
  369. /* Process special event packets and then discard them */
  370. if (ntohs(skb->protocol) == ETH_P_LINK_CTL)
  371. brcmf_host_event(drvr_priv, &ifidx,
  372. skb_mac_header(skb),
  373. &event, &data);
  374. if (drvr_priv->iflist[ifidx]) {
  375. ifp = drvr_priv->iflist[ifidx];
  376. ifp->ndev->last_rx = jiffies;
  377. }
  378. drvr->dstats.rx_bytes += skb->len;
  379. drvr->rx_packets++; /* Local count */
  380. if (in_interrupt())
  381. netif_rx(skb);
  382. else
  383. /* If the receive is not processed inside an ISR,
  384. * the softirqd must be woken explicitly to service
  385. * the NET_RX_SOFTIRQ. In 2.6 kernels, this is handled
  386. * by netif_rx_ni(), but in earlier kernels, we need
  387. * to do it manually.
  388. */
  389. netif_rx_ni(skb);
  390. }
  391. }
  392. void brcmf_txcomplete(struct brcmf_pub *drvr, struct sk_buff *txp, bool success)
  393. {
  394. uint ifidx;
  395. struct brcmf_info *drvr_priv = drvr->info;
  396. struct ethhdr *eh;
  397. u16 type;
  398. brcmf_proto_hdrpull(drvr, &ifidx, txp);
  399. eh = (struct ethhdr *)(txp->data);
  400. type = ntohs(eh->h_proto);
  401. if (type == ETH_P_PAE)
  402. atomic_dec(&drvr_priv->pend_8021x_cnt);
  403. }
  404. static struct net_device_stats *brcmf_netdev_get_stats(struct net_device *ndev)
  405. {
  406. struct brcmf_if *ifp = netdev_priv(ndev);
  407. struct brcmf_info *drvr_priv = ifp->info;
  408. brcmf_dbg(TRACE, "Enter\n");
  409. if (drvr_priv->pub.up)
  410. /* Use the protocol to get dongle stats */
  411. brcmf_proto_dstats(&drvr_priv->pub);
  412. /* Copy dongle stats to net device stats */
  413. ifp->stats.rx_packets = drvr_priv->pub.dstats.rx_packets;
  414. ifp->stats.tx_packets = drvr_priv->pub.dstats.tx_packets;
  415. ifp->stats.rx_bytes = drvr_priv->pub.dstats.rx_bytes;
  416. ifp->stats.tx_bytes = drvr_priv->pub.dstats.tx_bytes;
  417. ifp->stats.rx_errors = drvr_priv->pub.dstats.rx_errors;
  418. ifp->stats.tx_errors = drvr_priv->pub.dstats.tx_errors;
  419. ifp->stats.rx_dropped = drvr_priv->pub.dstats.rx_dropped;
  420. ifp->stats.tx_dropped = drvr_priv->pub.dstats.tx_dropped;
  421. ifp->stats.multicast = drvr_priv->pub.dstats.multicast;
  422. return &ifp->stats;
  423. }
  424. /* Retrieve current toe component enables, which are kept
  425. as a bitmap in toe_ol iovar */
  426. static int brcmf_toe_get(struct brcmf_info *drvr_priv, int ifidx, u32 *toe_ol)
  427. {
  428. struct brcmf_dcmd dcmd;
  429. __le32 toe_le;
  430. char buf[32];
  431. int ret;
  432. memset(&dcmd, 0, sizeof(dcmd));
  433. dcmd.cmd = BRCMF_C_GET_VAR;
  434. dcmd.buf = buf;
  435. dcmd.len = (uint) sizeof(buf);
  436. dcmd.set = false;
  437. strcpy(buf, "toe_ol");
  438. ret = brcmf_proto_dcmd(&drvr_priv->pub, ifidx, &dcmd, dcmd.len);
  439. if (ret < 0) {
  440. /* Check for older dongle image that doesn't support toe_ol */
  441. if (ret == -EIO) {
  442. brcmf_dbg(ERROR, "%s: toe not supported by device\n",
  443. brcmf_ifname(&drvr_priv->pub, ifidx));
  444. return -EOPNOTSUPP;
  445. }
  446. brcmf_dbg(INFO, "%s: could not get toe_ol: ret=%d\n",
  447. brcmf_ifname(&drvr_priv->pub, ifidx), ret);
  448. return ret;
  449. }
  450. memcpy(&toe_le, buf, sizeof(u32));
  451. *toe_ol = le32_to_cpu(toe_le);
  452. return 0;
  453. }
  454. /* Set current toe component enables in toe_ol iovar,
  455. and set toe global enable iovar */
  456. static int brcmf_toe_set(struct brcmf_info *drvr_priv, int ifidx, u32 toe_ol)
  457. {
  458. struct brcmf_dcmd dcmd;
  459. char buf[32];
  460. int ret;
  461. __le32 toe_le = cpu_to_le32(toe_ol);
  462. memset(&dcmd, 0, sizeof(dcmd));
  463. dcmd.cmd = BRCMF_C_SET_VAR;
  464. dcmd.buf = buf;
  465. dcmd.len = (uint) sizeof(buf);
  466. dcmd.set = true;
  467. /* Set toe_ol as requested */
  468. strcpy(buf, "toe_ol");
  469. memcpy(&buf[sizeof("toe_ol")], &toe_le, sizeof(u32));
  470. ret = brcmf_proto_dcmd(&drvr_priv->pub, ifidx, &dcmd, dcmd.len);
  471. if (ret < 0) {
  472. brcmf_dbg(ERROR, "%s: could not set toe_ol: ret=%d\n",
  473. brcmf_ifname(&drvr_priv->pub, ifidx), ret);
  474. return ret;
  475. }
  476. /* Enable toe globally only if any components are enabled. */
  477. toe_le = cpu_to_le32(toe_ol != 0);
  478. strcpy(buf, "toe");
  479. memcpy(&buf[sizeof("toe")], &toe_le, sizeof(u32));
  480. ret = brcmf_proto_dcmd(&drvr_priv->pub, ifidx, &dcmd, dcmd.len);
  481. if (ret < 0) {
  482. brcmf_dbg(ERROR, "%s: could not set toe: ret=%d\n",
  483. brcmf_ifname(&drvr_priv->pub, ifidx), ret);
  484. return ret;
  485. }
  486. return 0;
  487. }
  488. static void brcmf_ethtool_get_drvinfo(struct net_device *ndev,
  489. struct ethtool_drvinfo *info)
  490. {
  491. struct brcmf_if *ifp = netdev_priv(ndev);
  492. struct brcmf_info *drvr_priv = ifp->info;
  493. sprintf(info->driver, KBUILD_MODNAME);
  494. sprintf(info->version, "%lu", drvr_priv->pub.drv_version);
  495. sprintf(info->bus_info, "%s",
  496. dev_name(brcmf_bus_get_device(drvr_priv->pub.bus)));
  497. }
  498. static struct ethtool_ops brcmf_ethtool_ops = {
  499. .get_drvinfo = brcmf_ethtool_get_drvinfo
  500. };
  501. static int brcmf_ethtool(struct brcmf_info *drvr_priv, void __user *uaddr)
  502. {
  503. struct ethtool_drvinfo info;
  504. char drvname[sizeof(info.driver)];
  505. u32 cmd;
  506. struct ethtool_value edata;
  507. u32 toe_cmpnt, csum_dir;
  508. int ret;
  509. brcmf_dbg(TRACE, "Enter\n");
  510. /* all ethtool calls start with a cmd word */
  511. if (copy_from_user(&cmd, uaddr, sizeof(u32)))
  512. return -EFAULT;
  513. switch (cmd) {
  514. case ETHTOOL_GDRVINFO:
  515. /* Copy out any request driver name */
  516. if (copy_from_user(&info, uaddr, sizeof(info)))
  517. return -EFAULT;
  518. strncpy(drvname, info.driver, sizeof(info.driver));
  519. drvname[sizeof(info.driver) - 1] = '\0';
  520. /* clear struct for return */
  521. memset(&info, 0, sizeof(info));
  522. info.cmd = cmd;
  523. /* if requested, identify ourselves */
  524. if (strcmp(drvname, "?dhd") == 0) {
  525. sprintf(info.driver, "dhd");
  526. strcpy(info.version, BRCMF_VERSION_STR);
  527. }
  528. /* otherwise, require dongle to be up */
  529. else if (!drvr_priv->pub.up) {
  530. brcmf_dbg(ERROR, "dongle is not up\n");
  531. return -ENODEV;
  532. }
  533. /* finally, report dongle driver type */
  534. else if (drvr_priv->pub.iswl)
  535. sprintf(info.driver, "wl");
  536. else
  537. sprintf(info.driver, "xx");
  538. sprintf(info.version, "%lu", drvr_priv->pub.drv_version);
  539. if (copy_to_user(uaddr, &info, sizeof(info)))
  540. return -EFAULT;
  541. brcmf_dbg(CTL, "given %*s, returning %s\n",
  542. (int)sizeof(drvname), drvname, info.driver);
  543. break;
  544. /* Get toe offload components from dongle */
  545. case ETHTOOL_GRXCSUM:
  546. case ETHTOOL_GTXCSUM:
  547. ret = brcmf_toe_get(drvr_priv, 0, &toe_cmpnt);
  548. if (ret < 0)
  549. return ret;
  550. csum_dir =
  551. (cmd == ETHTOOL_GTXCSUM) ? TOE_TX_CSUM_OL : TOE_RX_CSUM_OL;
  552. edata.cmd = cmd;
  553. edata.data = (toe_cmpnt & csum_dir) ? 1 : 0;
  554. if (copy_to_user(uaddr, &edata, sizeof(edata)))
  555. return -EFAULT;
  556. break;
  557. /* Set toe offload components in dongle */
  558. case ETHTOOL_SRXCSUM:
  559. case ETHTOOL_STXCSUM:
  560. if (copy_from_user(&edata, uaddr, sizeof(edata)))
  561. return -EFAULT;
  562. /* Read the current settings, update and write back */
  563. ret = brcmf_toe_get(drvr_priv, 0, &toe_cmpnt);
  564. if (ret < 0)
  565. return ret;
  566. csum_dir =
  567. (cmd == ETHTOOL_STXCSUM) ? TOE_TX_CSUM_OL : TOE_RX_CSUM_OL;
  568. if (edata.data != 0)
  569. toe_cmpnt |= csum_dir;
  570. else
  571. toe_cmpnt &= ~csum_dir;
  572. ret = brcmf_toe_set(drvr_priv, 0, toe_cmpnt);
  573. if (ret < 0)
  574. return ret;
  575. /* If setting TX checksum mode, tell Linux the new mode */
  576. if (cmd == ETHTOOL_STXCSUM) {
  577. if (edata.data)
  578. drvr_priv->iflist[0]->ndev->features |=
  579. NETIF_F_IP_CSUM;
  580. else
  581. drvr_priv->iflist[0]->ndev->features &=
  582. ~NETIF_F_IP_CSUM;
  583. }
  584. break;
  585. default:
  586. return -EOPNOTSUPP;
  587. }
  588. return 0;
  589. }
  590. static int brcmf_netdev_ioctl_entry(struct net_device *ndev, struct ifreq *ifr,
  591. int cmd)
  592. {
  593. struct brcmf_if *ifp = netdev_priv(ndev);
  594. struct brcmf_info *drvr_priv = ifp->info;
  595. brcmf_dbg(TRACE, "ifidx %d, cmd 0x%04x\n", ifp->idx, cmd);
  596. if (!drvr_priv->iflist[ifp->idx])
  597. return -1;
  598. if (cmd == SIOCETHTOOL)
  599. return brcmf_ethtool(drvr_priv, ifr->ifr_data);
  600. return -EOPNOTSUPP;
  601. }
  602. /* called only from within this driver. Sends a command to the dongle. */
  603. s32 brcmf_exec_dcmd(struct net_device *ndev, u32 cmd, void *arg, u32 len)
  604. {
  605. struct brcmf_dcmd dcmd;
  606. s32 err = 0;
  607. int buflen = 0;
  608. bool is_set_key_cmd;
  609. struct brcmf_if *ifp = netdev_priv(ndev);
  610. struct brcmf_info *drvr_priv = ifp->info;
  611. memset(&dcmd, 0, sizeof(dcmd));
  612. dcmd.cmd = cmd;
  613. dcmd.buf = arg;
  614. dcmd.len = len;
  615. if (dcmd.buf != NULL)
  616. buflen = min_t(uint, dcmd.len, BRCMF_DCMD_MAXLEN);
  617. /* send to dongle (must be up, and wl) */
  618. if ((drvr_priv->pub.bus_if->state != BRCMF_BUS_DATA)) {
  619. brcmf_dbg(ERROR, "DONGLE_DOWN\n");
  620. err = -EIO;
  621. goto done;
  622. }
  623. if (!drvr_priv->pub.iswl) {
  624. err = -EIO;
  625. goto done;
  626. }
  627. /*
  628. * Intercept BRCMF_C_SET_KEY CMD - serialize M4 send and
  629. * set key CMD to prevent M4 encryption.
  630. */
  631. is_set_key_cmd = ((dcmd.cmd == BRCMF_C_SET_KEY) ||
  632. ((dcmd.cmd == BRCMF_C_SET_VAR) &&
  633. !(strncmp("wsec_key", dcmd.buf, 9))) ||
  634. ((dcmd.cmd == BRCMF_C_SET_VAR) &&
  635. !(strncmp("bsscfg:wsec_key", dcmd.buf, 15))));
  636. if (is_set_key_cmd)
  637. brcmf_netdev_wait_pend8021x(ndev);
  638. err = brcmf_proto_dcmd(&drvr_priv->pub, ifp->idx, &dcmd, buflen);
  639. done:
  640. if (err > 0)
  641. err = 0;
  642. return err;
  643. }
  644. static int brcmf_netdev_stop(struct net_device *ndev)
  645. {
  646. struct brcmf_if *ifp = netdev_priv(ndev);
  647. struct brcmf_pub *drvr = &ifp->info->pub;
  648. brcmf_dbg(TRACE, "Enter\n");
  649. brcmf_cfg80211_down(drvr->config);
  650. if (drvr->up == 0)
  651. return 0;
  652. /* Set state and stop OS transmissions */
  653. drvr->up = 0;
  654. netif_stop_queue(ndev);
  655. return 0;
  656. }
  657. static int brcmf_netdev_open(struct net_device *ndev)
  658. {
  659. struct brcmf_if *ifp = netdev_priv(ndev);
  660. struct brcmf_info *drvr_priv = ifp->info;
  661. u32 toe_ol;
  662. s32 ret = 0;
  663. brcmf_dbg(TRACE, "ifidx %d\n", ifp->idx);
  664. if (ifp->idx == 0) { /* do it only for primary eth0 */
  665. /* try to bring up bus */
  666. ret = brcmf_bus_start(&drvr_priv->pub);
  667. if (ret != 0) {
  668. brcmf_dbg(ERROR, "failed with code %d\n", ret);
  669. return -1;
  670. }
  671. atomic_set(&drvr_priv->pend_8021x_cnt, 0);
  672. memcpy(ndev->dev_addr, drvr_priv->pub.mac, ETH_ALEN);
  673. /* Get current TOE mode from dongle */
  674. if (brcmf_toe_get(drvr_priv, ifp->idx, &toe_ol) >= 0
  675. && (toe_ol & TOE_TX_CSUM_OL) != 0)
  676. drvr_priv->iflist[ifp->idx]->ndev->features |=
  677. NETIF_F_IP_CSUM;
  678. else
  679. drvr_priv->iflist[ifp->idx]->ndev->features &=
  680. ~NETIF_F_IP_CSUM;
  681. }
  682. /* Allow transmit calls */
  683. netif_start_queue(ndev);
  684. drvr_priv->pub.up = 1;
  685. if (brcmf_cfg80211_up(drvr_priv->pub.config)) {
  686. brcmf_dbg(ERROR, "failed to bring up cfg80211\n");
  687. return -1;
  688. }
  689. return ret;
  690. }
  691. static const struct net_device_ops brcmf_netdev_ops_pri = {
  692. .ndo_open = brcmf_netdev_open,
  693. .ndo_stop = brcmf_netdev_stop,
  694. .ndo_get_stats = brcmf_netdev_get_stats,
  695. .ndo_do_ioctl = brcmf_netdev_ioctl_entry,
  696. .ndo_start_xmit = brcmf_netdev_start_xmit,
  697. .ndo_set_mac_address = brcmf_netdev_set_mac_address,
  698. .ndo_set_rx_mode = brcmf_netdev_set_multicast_list
  699. };
  700. int
  701. brcmf_add_if(struct brcmf_info *drvr_priv, int ifidx, char *name, u8 *mac_addr)
  702. {
  703. struct brcmf_if *ifp;
  704. struct net_device *ndev;
  705. brcmf_dbg(TRACE, "idx %d\n", ifidx);
  706. ifp = drvr_priv->iflist[ifidx];
  707. /*
  708. * Delete the existing interface before overwriting it
  709. * in case we missed the BRCMF_E_IF_DEL event.
  710. */
  711. if (ifp) {
  712. brcmf_dbg(ERROR, "ERROR: netdev:%s already exists, try free & unregister\n",
  713. ifp->ndev->name);
  714. netif_stop_queue(ifp->ndev);
  715. unregister_netdev(ifp->ndev);
  716. free_netdev(ifp->ndev);
  717. drvr_priv->iflist[ifidx] = NULL;
  718. }
  719. /* Allocate netdev, including space for private structure */
  720. ndev = alloc_netdev(sizeof(struct brcmf_if), name, ether_setup);
  721. if (!ndev) {
  722. brcmf_dbg(ERROR, "OOM - alloc_netdev\n");
  723. return -ENOMEM;
  724. }
  725. ifp = netdev_priv(ndev);
  726. ifp->ndev = ndev;
  727. ifp->info = drvr_priv;
  728. drvr_priv->iflist[ifidx] = ifp;
  729. ifp->idx = ifidx;
  730. if (mac_addr != NULL)
  731. memcpy(&ifp->mac_addr, mac_addr, ETH_ALEN);
  732. if (brcmf_net_attach(&drvr_priv->pub, ifp->idx)) {
  733. brcmf_dbg(ERROR, "brcmf_net_attach failed");
  734. free_netdev(ifp->ndev);
  735. drvr_priv->iflist[ifidx] = NULL;
  736. return -EOPNOTSUPP;
  737. }
  738. brcmf_dbg(TRACE, " ==== pid:%x, net_device for if:%s created ===\n",
  739. current->pid, ifp->ndev->name);
  740. return 0;
  741. }
  742. void brcmf_del_if(struct brcmf_info *drvr_priv, int ifidx)
  743. {
  744. struct brcmf_if *ifp;
  745. brcmf_dbg(TRACE, "idx %d\n", ifidx);
  746. ifp = drvr_priv->iflist[ifidx];
  747. if (!ifp) {
  748. brcmf_dbg(ERROR, "Null interface\n");
  749. return;
  750. }
  751. if (ifp->ndev) {
  752. if (ifidx == 0) {
  753. if (ifp->ndev->netdev_ops == &brcmf_netdev_ops_pri) {
  754. rtnl_lock();
  755. brcmf_netdev_stop(ifp->ndev);
  756. rtnl_unlock();
  757. }
  758. } else {
  759. netif_stop_queue(ifp->ndev);
  760. }
  761. unregister_netdev(ifp->ndev);
  762. drvr_priv->iflist[ifidx] = NULL;
  763. if (ifidx == 0)
  764. brcmf_cfg80211_detach(drvr_priv->pub.config);
  765. free_netdev(ifp->ndev);
  766. }
  767. }
  768. struct brcmf_pub *brcmf_attach(struct brcmf_sdio *bus, uint bus_hdrlen,
  769. struct device *dev)
  770. {
  771. struct brcmf_info *drvr_priv = NULL;
  772. brcmf_dbg(TRACE, "Enter\n");
  773. /* Allocate primary brcmf_info */
  774. drvr_priv = kzalloc(sizeof(struct brcmf_info), GFP_ATOMIC);
  775. if (!drvr_priv)
  776. goto fail;
  777. mutex_init(&drvr_priv->proto_block);
  778. /* Link to info module */
  779. drvr_priv->pub.info = drvr_priv;
  780. /* Link to bus module */
  781. drvr_priv->pub.bus = bus;
  782. drvr_priv->pub.hdrlen = bus_hdrlen;
  783. drvr_priv->pub.bus_if = dev_get_drvdata(dev);
  784. /* Attach and link in the protocol */
  785. if (brcmf_proto_attach(&drvr_priv->pub) != 0) {
  786. brcmf_dbg(ERROR, "brcmf_prot_attach failed\n");
  787. goto fail;
  788. }
  789. INIT_WORK(&drvr_priv->setmacaddr_work, _brcmf_set_mac_address);
  790. INIT_WORK(&drvr_priv->multicast_work, _brcmf_set_multicast_list);
  791. return &drvr_priv->pub;
  792. fail:
  793. if (drvr_priv)
  794. brcmf_detach(&drvr_priv->pub);
  795. return NULL;
  796. }
  797. int brcmf_bus_start(struct brcmf_pub *drvr)
  798. {
  799. int ret = -1;
  800. struct brcmf_info *drvr_priv = drvr->info;
  801. /* Room for "event_msgs" + '\0' + bitvec */
  802. char iovbuf[BRCMF_EVENTING_MASK_LEN + 12];
  803. brcmf_dbg(TRACE, "\n");
  804. /* Bring up the bus */
  805. ret = brcmf_sdbrcm_bus_init(&drvr_priv->pub);
  806. if (ret != 0) {
  807. brcmf_dbg(ERROR, "brcmf_sdbrcm_bus_init failed %d\n", ret);
  808. return ret;
  809. }
  810. /* If bus is not ready, can't come up */
  811. if (drvr_priv->pub.bus_if->state != BRCMF_BUS_DATA) {
  812. brcmf_dbg(ERROR, "failed bus is not ready\n");
  813. return -ENODEV;
  814. }
  815. brcmf_c_mkiovar("event_msgs", drvr->eventmask, BRCMF_EVENTING_MASK_LEN,
  816. iovbuf, sizeof(iovbuf));
  817. brcmf_proto_cdc_query_dcmd(drvr, 0, BRCMF_C_GET_VAR, iovbuf,
  818. sizeof(iovbuf));
  819. memcpy(drvr->eventmask, iovbuf, BRCMF_EVENTING_MASK_LEN);
  820. setbit(drvr->eventmask, BRCMF_E_SET_SSID);
  821. setbit(drvr->eventmask, BRCMF_E_PRUNE);
  822. setbit(drvr->eventmask, BRCMF_E_AUTH);
  823. setbit(drvr->eventmask, BRCMF_E_REASSOC);
  824. setbit(drvr->eventmask, BRCMF_E_REASSOC_IND);
  825. setbit(drvr->eventmask, BRCMF_E_DEAUTH_IND);
  826. setbit(drvr->eventmask, BRCMF_E_DISASSOC_IND);
  827. setbit(drvr->eventmask, BRCMF_E_DISASSOC);
  828. setbit(drvr->eventmask, BRCMF_E_JOIN);
  829. setbit(drvr->eventmask, BRCMF_E_ASSOC_IND);
  830. setbit(drvr->eventmask, BRCMF_E_PSK_SUP);
  831. setbit(drvr->eventmask, BRCMF_E_LINK);
  832. setbit(drvr->eventmask, BRCMF_E_NDIS_LINK);
  833. setbit(drvr->eventmask, BRCMF_E_MIC_ERROR);
  834. setbit(drvr->eventmask, BRCMF_E_PMKID_CACHE);
  835. setbit(drvr->eventmask, BRCMF_E_TXFAIL);
  836. setbit(drvr->eventmask, BRCMF_E_JOIN_START);
  837. setbit(drvr->eventmask, BRCMF_E_SCAN_COMPLETE);
  838. /* enable dongle roaming event */
  839. drvr->pktfilter_count = 1;
  840. /* Setup filter to allow only unicast */
  841. drvr->pktfilter[0] = "100 0 0 0 0x01 0x00";
  842. /* Bus is ready, do any protocol initialization */
  843. ret = brcmf_proto_init(&drvr_priv->pub);
  844. if (ret < 0)
  845. return ret;
  846. return 0;
  847. }
  848. int brcmf_net_attach(struct brcmf_pub *drvr, int ifidx)
  849. {
  850. struct brcmf_info *drvr_priv = drvr->info;
  851. struct net_device *ndev;
  852. u8 temp_addr[ETH_ALEN] = {
  853. 0x00, 0x90, 0x4c, 0x11, 0x22, 0x33};
  854. brcmf_dbg(TRACE, "ifidx %d\n", ifidx);
  855. ndev = drvr_priv->iflist[ifidx]->ndev;
  856. ndev->netdev_ops = &brcmf_netdev_ops_pri;
  857. /*
  858. * We have to use the primary MAC for virtual interfaces
  859. */
  860. if (ifidx != 0) {
  861. /* for virtual interfaces use the primary MAC */
  862. memcpy(temp_addr, drvr_priv->pub.mac, ETH_ALEN);
  863. }
  864. if (ifidx == 1) {
  865. brcmf_dbg(TRACE, "ACCESS POINT MAC:\n");
  866. /* ACCESSPOINT INTERFACE CASE */
  867. temp_addr[0] |= 0X02; /* set bit 2 ,
  868. - Locally Administered address */
  869. }
  870. ndev->hard_header_len = ETH_HLEN + drvr_priv->pub.hdrlen;
  871. ndev->ethtool_ops = &brcmf_ethtool_ops;
  872. drvr_priv->pub.rxsz = ndev->mtu + ndev->hard_header_len +
  873. drvr_priv->pub.hdrlen;
  874. memcpy(ndev->dev_addr, temp_addr, ETH_ALEN);
  875. /* attach to cfg80211 for primary interface */
  876. if (!ifidx) {
  877. drvr->config =
  878. brcmf_cfg80211_attach(ndev,
  879. brcmf_bus_get_device(drvr->bus),
  880. drvr);
  881. if (drvr->config == NULL) {
  882. brcmf_dbg(ERROR, "wl_cfg80211_attach failed\n");
  883. goto fail;
  884. }
  885. }
  886. if (register_netdev(ndev) != 0) {
  887. brcmf_dbg(ERROR, "couldn't register the net device\n");
  888. goto fail;
  889. }
  890. brcmf_dbg(INFO, "%s: Broadcom Dongle Host Driver\n", ndev->name);
  891. return 0;
  892. fail:
  893. ndev->netdev_ops = NULL;
  894. return -EBADE;
  895. }
  896. static void brcmf_bus_detach(struct brcmf_pub *drvr)
  897. {
  898. struct brcmf_info *drvr_priv;
  899. brcmf_dbg(TRACE, "Enter\n");
  900. if (drvr) {
  901. drvr_priv = drvr->info;
  902. if (drvr_priv) {
  903. /* Stop the protocol module */
  904. brcmf_proto_stop(&drvr_priv->pub);
  905. /* Stop the bus module */
  906. brcmf_sdbrcm_bus_stop(drvr_priv->pub.bus);
  907. }
  908. }
  909. }
  910. void brcmf_detach(struct brcmf_pub *drvr)
  911. {
  912. struct brcmf_info *drvr_priv;
  913. brcmf_dbg(TRACE, "Enter\n");
  914. if (drvr) {
  915. drvr_priv = drvr->info;
  916. if (drvr_priv) {
  917. int i;
  918. /* make sure primary interface removed last */
  919. for (i = BRCMF_MAX_IFS-1; i > -1; i--)
  920. if (drvr_priv->iflist[i])
  921. brcmf_del_if(drvr_priv, i);
  922. cancel_work_sync(&drvr_priv->setmacaddr_work);
  923. cancel_work_sync(&drvr_priv->multicast_work);
  924. brcmf_bus_detach(drvr);
  925. if (drvr->prot)
  926. brcmf_proto_detach(drvr);
  927. kfree(drvr_priv);
  928. }
  929. }
  930. }
  931. int brcmf_os_proto_block(struct brcmf_pub *drvr)
  932. {
  933. struct brcmf_info *drvr_priv = drvr->info;
  934. if (drvr_priv) {
  935. mutex_lock(&drvr_priv->proto_block);
  936. return 1;
  937. }
  938. return 0;
  939. }
  940. int brcmf_os_proto_unblock(struct brcmf_pub *drvr)
  941. {
  942. struct brcmf_info *drvr_priv = drvr->info;
  943. if (drvr_priv) {
  944. mutex_unlock(&drvr_priv->proto_block);
  945. return 1;
  946. }
  947. return 0;
  948. }
  949. static int brcmf_get_pend_8021x_cnt(struct brcmf_info *drvr_priv)
  950. {
  951. return atomic_read(&drvr_priv->pend_8021x_cnt);
  952. }
  953. #define MAX_WAIT_FOR_8021X_TX 10
  954. int brcmf_netdev_wait_pend8021x(struct net_device *ndev)
  955. {
  956. struct brcmf_if *ifp = netdev_priv(ndev);
  957. struct brcmf_info *drvr_priv = ifp->info;
  958. int timeout = 10 * HZ / 1000;
  959. int ntimes = MAX_WAIT_FOR_8021X_TX;
  960. int pend = brcmf_get_pend_8021x_cnt(drvr_priv);
  961. while (ntimes && pend) {
  962. if (pend) {
  963. set_current_state(TASK_INTERRUPTIBLE);
  964. schedule_timeout(timeout);
  965. set_current_state(TASK_RUNNING);
  966. ntimes--;
  967. }
  968. pend = brcmf_get_pend_8021x_cnt(drvr_priv);
  969. }
  970. return pend;
  971. }
  972. #ifdef BCMDBG
  973. int brcmf_write_to_file(struct brcmf_pub *drvr, const u8 *buf, int size)
  974. {
  975. int ret = 0;
  976. struct file *fp;
  977. mm_segment_t old_fs;
  978. loff_t pos = 0;
  979. /* change to KERNEL_DS address limit */
  980. old_fs = get_fs();
  981. set_fs(KERNEL_DS);
  982. /* open file to write */
  983. fp = filp_open("/tmp/mem_dump", O_WRONLY | O_CREAT, 0640);
  984. if (!fp) {
  985. brcmf_dbg(ERROR, "open file error\n");
  986. ret = -1;
  987. goto exit;
  988. }
  989. /* Write buf to file */
  990. fp->f_op->write(fp, (char __user *)buf, size, &pos);
  991. exit:
  992. /* free buf before return */
  993. kfree(buf);
  994. /* close file before return */
  995. if (fp)
  996. filp_close(fp, current->files);
  997. /* restore previous address limit */
  998. set_fs(old_fs);
  999. return ret;
  1000. }
  1001. #endif /* BCMDBG */