dhd_linux.c 30 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240
  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. drvr_priv->pub.dev = dev;
  785. /* Attach and link in the protocol */
  786. if (brcmf_proto_attach(&drvr_priv->pub) != 0) {
  787. brcmf_dbg(ERROR, "brcmf_prot_attach failed\n");
  788. goto fail;
  789. }
  790. INIT_WORK(&drvr_priv->setmacaddr_work, _brcmf_set_mac_address);
  791. INIT_WORK(&drvr_priv->multicast_work, _brcmf_set_multicast_list);
  792. return &drvr_priv->pub;
  793. fail:
  794. if (drvr_priv)
  795. brcmf_detach(&drvr_priv->pub);
  796. return NULL;
  797. }
  798. int brcmf_bus_start(struct brcmf_pub *drvr)
  799. {
  800. int ret = -1;
  801. struct brcmf_info *drvr_priv = drvr->info;
  802. /* Room for "event_msgs" + '\0' + bitvec */
  803. char iovbuf[BRCMF_EVENTING_MASK_LEN + 12];
  804. brcmf_dbg(TRACE, "\n");
  805. /* Bring up the bus */
  806. ret = brcmf_sdbrcm_bus_init(&drvr_priv->pub);
  807. if (ret != 0) {
  808. brcmf_dbg(ERROR, "brcmf_sdbrcm_bus_init failed %d\n", ret);
  809. return ret;
  810. }
  811. /* If bus is not ready, can't come up */
  812. if (drvr_priv->pub.bus_if->state != BRCMF_BUS_DATA) {
  813. brcmf_dbg(ERROR, "failed bus is not ready\n");
  814. return -ENODEV;
  815. }
  816. brcmf_c_mkiovar("event_msgs", drvr->eventmask, BRCMF_EVENTING_MASK_LEN,
  817. iovbuf, sizeof(iovbuf));
  818. brcmf_proto_cdc_query_dcmd(drvr, 0, BRCMF_C_GET_VAR, iovbuf,
  819. sizeof(iovbuf));
  820. memcpy(drvr->eventmask, iovbuf, BRCMF_EVENTING_MASK_LEN);
  821. setbit(drvr->eventmask, BRCMF_E_SET_SSID);
  822. setbit(drvr->eventmask, BRCMF_E_PRUNE);
  823. setbit(drvr->eventmask, BRCMF_E_AUTH);
  824. setbit(drvr->eventmask, BRCMF_E_REASSOC);
  825. setbit(drvr->eventmask, BRCMF_E_REASSOC_IND);
  826. setbit(drvr->eventmask, BRCMF_E_DEAUTH_IND);
  827. setbit(drvr->eventmask, BRCMF_E_DISASSOC_IND);
  828. setbit(drvr->eventmask, BRCMF_E_DISASSOC);
  829. setbit(drvr->eventmask, BRCMF_E_JOIN);
  830. setbit(drvr->eventmask, BRCMF_E_ASSOC_IND);
  831. setbit(drvr->eventmask, BRCMF_E_PSK_SUP);
  832. setbit(drvr->eventmask, BRCMF_E_LINK);
  833. setbit(drvr->eventmask, BRCMF_E_NDIS_LINK);
  834. setbit(drvr->eventmask, BRCMF_E_MIC_ERROR);
  835. setbit(drvr->eventmask, BRCMF_E_PMKID_CACHE);
  836. setbit(drvr->eventmask, BRCMF_E_TXFAIL);
  837. setbit(drvr->eventmask, BRCMF_E_JOIN_START);
  838. setbit(drvr->eventmask, BRCMF_E_SCAN_COMPLETE);
  839. /* enable dongle roaming event */
  840. drvr->pktfilter_count = 1;
  841. /* Setup filter to allow only unicast */
  842. drvr->pktfilter[0] = "100 0 0 0 0x01 0x00";
  843. /* Bus is ready, do any protocol initialization */
  844. ret = brcmf_proto_init(&drvr_priv->pub);
  845. if (ret < 0)
  846. return ret;
  847. return 0;
  848. }
  849. int brcmf_net_attach(struct brcmf_pub *drvr, int ifidx)
  850. {
  851. struct brcmf_info *drvr_priv = drvr->info;
  852. struct net_device *ndev;
  853. u8 temp_addr[ETH_ALEN] = {
  854. 0x00, 0x90, 0x4c, 0x11, 0x22, 0x33};
  855. brcmf_dbg(TRACE, "ifidx %d\n", ifidx);
  856. ndev = drvr_priv->iflist[ifidx]->ndev;
  857. ndev->netdev_ops = &brcmf_netdev_ops_pri;
  858. /*
  859. * We have to use the primary MAC for virtual interfaces
  860. */
  861. if (ifidx != 0) {
  862. /* for virtual interfaces use the primary MAC */
  863. memcpy(temp_addr, drvr_priv->pub.mac, ETH_ALEN);
  864. }
  865. if (ifidx == 1) {
  866. brcmf_dbg(TRACE, "ACCESS POINT MAC:\n");
  867. /* ACCESSPOINT INTERFACE CASE */
  868. temp_addr[0] |= 0X02; /* set bit 2 ,
  869. - Locally Administered address */
  870. }
  871. ndev->hard_header_len = ETH_HLEN + drvr_priv->pub.hdrlen;
  872. ndev->ethtool_ops = &brcmf_ethtool_ops;
  873. drvr_priv->pub.rxsz = ndev->mtu + ndev->hard_header_len +
  874. drvr_priv->pub.hdrlen;
  875. memcpy(ndev->dev_addr, temp_addr, ETH_ALEN);
  876. /* attach to cfg80211 for primary interface */
  877. if (!ifidx) {
  878. drvr->config =
  879. brcmf_cfg80211_attach(ndev,
  880. brcmf_bus_get_device(drvr->bus),
  881. drvr);
  882. if (drvr->config == NULL) {
  883. brcmf_dbg(ERROR, "wl_cfg80211_attach failed\n");
  884. goto fail;
  885. }
  886. }
  887. if (register_netdev(ndev) != 0) {
  888. brcmf_dbg(ERROR, "couldn't register the net device\n");
  889. goto fail;
  890. }
  891. brcmf_dbg(INFO, "%s: Broadcom Dongle Host Driver\n", ndev->name);
  892. return 0;
  893. fail:
  894. ndev->netdev_ops = NULL;
  895. return -EBADE;
  896. }
  897. static void brcmf_bus_detach(struct brcmf_pub *drvr)
  898. {
  899. struct brcmf_info *drvr_priv;
  900. brcmf_dbg(TRACE, "Enter\n");
  901. if (drvr) {
  902. drvr_priv = drvr->info;
  903. if (drvr_priv) {
  904. /* Stop the protocol module */
  905. brcmf_proto_stop(&drvr_priv->pub);
  906. /* Stop the bus module */
  907. brcmf_sdbrcm_bus_stop(drvr_priv->pub.bus);
  908. }
  909. }
  910. }
  911. void brcmf_detach(struct brcmf_pub *drvr)
  912. {
  913. struct brcmf_info *drvr_priv;
  914. brcmf_dbg(TRACE, "Enter\n");
  915. if (drvr) {
  916. drvr_priv = drvr->info;
  917. if (drvr_priv) {
  918. int i;
  919. /* make sure primary interface removed last */
  920. for (i = BRCMF_MAX_IFS-1; i > -1; i--)
  921. if (drvr_priv->iflist[i])
  922. brcmf_del_if(drvr_priv, i);
  923. cancel_work_sync(&drvr_priv->setmacaddr_work);
  924. cancel_work_sync(&drvr_priv->multicast_work);
  925. brcmf_bus_detach(drvr);
  926. if (drvr->prot)
  927. brcmf_proto_detach(drvr);
  928. kfree(drvr_priv);
  929. }
  930. }
  931. }
  932. int brcmf_os_proto_block(struct brcmf_pub *drvr)
  933. {
  934. struct brcmf_info *drvr_priv = drvr->info;
  935. if (drvr_priv) {
  936. mutex_lock(&drvr_priv->proto_block);
  937. return 1;
  938. }
  939. return 0;
  940. }
  941. int brcmf_os_proto_unblock(struct brcmf_pub *drvr)
  942. {
  943. struct brcmf_info *drvr_priv = drvr->info;
  944. if (drvr_priv) {
  945. mutex_unlock(&drvr_priv->proto_block);
  946. return 1;
  947. }
  948. return 0;
  949. }
  950. static int brcmf_get_pend_8021x_cnt(struct brcmf_info *drvr_priv)
  951. {
  952. return atomic_read(&drvr_priv->pend_8021x_cnt);
  953. }
  954. #define MAX_WAIT_FOR_8021X_TX 10
  955. int brcmf_netdev_wait_pend8021x(struct net_device *ndev)
  956. {
  957. struct brcmf_if *ifp = netdev_priv(ndev);
  958. struct brcmf_info *drvr_priv = ifp->info;
  959. int timeout = 10 * HZ / 1000;
  960. int ntimes = MAX_WAIT_FOR_8021X_TX;
  961. int pend = brcmf_get_pend_8021x_cnt(drvr_priv);
  962. while (ntimes && pend) {
  963. if (pend) {
  964. set_current_state(TASK_INTERRUPTIBLE);
  965. schedule_timeout(timeout);
  966. set_current_state(TASK_RUNNING);
  967. ntimes--;
  968. }
  969. pend = brcmf_get_pend_8021x_cnt(drvr_priv);
  970. }
  971. return pend;
  972. }
  973. #ifdef BCMDBG
  974. int brcmf_write_to_file(struct brcmf_pub *drvr, const u8 *buf, int size)
  975. {
  976. int ret = 0;
  977. struct file *fp;
  978. mm_segment_t old_fs;
  979. loff_t pos = 0;
  980. /* change to KERNEL_DS address limit */
  981. old_fs = get_fs();
  982. set_fs(KERNEL_DS);
  983. /* open file to write */
  984. fp = filp_open("/tmp/mem_dump", O_WRONLY | O_CREAT, 0640);
  985. if (!fp) {
  986. brcmf_dbg(ERROR, "open file error\n");
  987. ret = -1;
  988. goto exit;
  989. }
  990. /* Write buf to file */
  991. fp->f_op->write(fp, (char __user *)buf, size, &pos);
  992. exit:
  993. /* free buf before return */
  994. kfree(buf);
  995. /* close file before return */
  996. if (fp)
  997. filp_close(fp, current->files);
  998. /* restore previous address limit */
  999. set_fs(old_fs);
  1000. return ret;
  1001. }
  1002. #endif /* BCMDBG */