dhd_linux.c 30 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258
  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. #include "bcmchip.h"
  45. MODULE_AUTHOR("Broadcom Corporation");
  46. MODULE_DESCRIPTION("Broadcom 802.11n wireless LAN fullmac driver.");
  47. MODULE_SUPPORTED_DEVICE("Broadcom 802.11n WLAN fullmac cards");
  48. MODULE_LICENSE("Dual BSD/GPL");
  49. /* Interface control information */
  50. struct brcmf_if {
  51. struct brcmf_info *info; /* back pointer to brcmf_info */
  52. /* OS/stack specifics */
  53. struct net_device *ndev;
  54. struct net_device_stats stats;
  55. int idx; /* iface idx in dongle */
  56. u8 mac_addr[ETH_ALEN]; /* assigned MAC address */
  57. };
  58. /* Local private structure (extension of pub) */
  59. struct brcmf_info {
  60. struct brcmf_pub pub;
  61. /* OS/stack specifics */
  62. struct brcmf_if *iflist[BRCMF_MAX_IFS];
  63. struct mutex proto_block;
  64. struct work_struct setmacaddr_work;
  65. struct work_struct multicast_work;
  66. u8 macvalue[ETH_ALEN];
  67. atomic_t pend_8021x_cnt;
  68. };
  69. /* Error bits */
  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->busstate == 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 || (drvr_priv->pub.busstate == BRCMF_BUS_DOWN)) {
  264. brcmf_dbg(ERROR, "xmit rejected pub.up=%d busstate=%d\n",
  265. drvr_priv->pub.up, drvr_priv->pub.busstate);
  266. netif_stop_queue(ndev);
  267. return -ENODEV;
  268. }
  269. if (!drvr_priv->iflist[ifp->idx]) {
  270. brcmf_dbg(ERROR, "bad ifidx %d\n", ifp->idx);
  271. netif_stop_queue(ndev);
  272. return -ENODEV;
  273. }
  274. /* Make sure there's enough room for any header */
  275. if (skb_headroom(skb) < drvr_priv->pub.hdrlen) {
  276. struct sk_buff *skb2;
  277. brcmf_dbg(INFO, "%s: insufficient headroom\n",
  278. brcmf_ifname(&drvr_priv->pub, ifp->idx));
  279. drvr_priv->pub.tx_realloc++;
  280. skb2 = skb_realloc_headroom(skb, drvr_priv->pub.hdrlen);
  281. dev_kfree_skb(skb);
  282. skb = skb2;
  283. if (skb == NULL) {
  284. brcmf_dbg(ERROR, "%s: skb_realloc_headroom failed\n",
  285. brcmf_ifname(&drvr_priv->pub, ifp->idx));
  286. ret = -ENOMEM;
  287. goto done;
  288. }
  289. }
  290. ret = brcmf_sendpkt(&drvr_priv->pub, ifp->idx, skb);
  291. done:
  292. if (ret)
  293. drvr_priv->pub.dstats.tx_dropped++;
  294. else
  295. drvr_priv->pub.tx_packets++;
  296. /* Return ok: we always eat the packet */
  297. return 0;
  298. }
  299. void brcmf_txflowcontrol(struct brcmf_pub *drvr, int ifidx, bool state)
  300. {
  301. struct net_device *ndev;
  302. struct brcmf_info *drvr_priv = drvr->info;
  303. brcmf_dbg(TRACE, "Enter\n");
  304. drvr->txoff = state;
  305. ndev = drvr_priv->iflist[ifidx]->ndev;
  306. if (state == ON)
  307. netif_stop_queue(ndev);
  308. else
  309. netif_wake_queue(ndev);
  310. }
  311. static int brcmf_host_event(struct brcmf_info *drvr_priv, int *ifidx,
  312. void *pktdata, struct brcmf_event_msg *event,
  313. void **data)
  314. {
  315. int bcmerror = 0;
  316. bcmerror = brcmf_c_host_event(drvr_priv, ifidx, pktdata, event, data);
  317. if (bcmerror != 0)
  318. return bcmerror;
  319. if (drvr_priv->iflist[*ifidx]->ndev)
  320. brcmf_cfg80211_event(drvr_priv->iflist[*ifidx]->ndev,
  321. event, *data);
  322. return bcmerror;
  323. }
  324. void brcmf_rx_frame(struct brcmf_pub *drvr, int ifidx,
  325. struct sk_buff_head *skb_list)
  326. {
  327. struct brcmf_info *drvr_priv = drvr->info;
  328. unsigned char *eth;
  329. uint len;
  330. void *data;
  331. struct sk_buff *skb, *pnext;
  332. struct brcmf_if *ifp;
  333. struct brcmf_event_msg event;
  334. brcmf_dbg(TRACE, "Enter\n");
  335. skb_queue_walk_safe(skb_list, skb, pnext) {
  336. skb_unlink(skb, skb_list);
  337. /* Get the protocol, maintain skb around eth_type_trans()
  338. * The main reason for this hack is for the limitation of
  339. * Linux 2.4 where 'eth_type_trans' uses the
  340. * 'net->hard_header_len'
  341. * to perform skb_pull inside vs ETH_HLEN. Since to avoid
  342. * coping of the packet coming from the network stack to add
  343. * BDC, Hardware header etc, during network interface
  344. * registration
  345. * we set the 'net->hard_header_len' to ETH_HLEN + extra space
  346. * required
  347. * for BDC, Hardware header etc. and not just the ETH_HLEN
  348. */
  349. eth = skb->data;
  350. len = skb->len;
  351. ifp = drvr_priv->iflist[ifidx];
  352. if (ifp == NULL)
  353. ifp = drvr_priv->iflist[0];
  354. skb->dev = ifp->ndev;
  355. skb->protocol = eth_type_trans(skb, skb->dev);
  356. if (skb->pkt_type == PACKET_MULTICAST)
  357. drvr_priv->pub.rx_multicast++;
  358. skb->data = eth;
  359. skb->len = len;
  360. /* Strip header, count, deliver upward */
  361. skb_pull(skb, ETH_HLEN);
  362. /* Process special event packets and then discard them */
  363. if (ntohs(skb->protocol) == ETH_P_LINK_CTL)
  364. brcmf_host_event(drvr_priv, &ifidx,
  365. skb_mac_header(skb),
  366. &event, &data);
  367. if (drvr_priv->iflist[ifidx]) {
  368. ifp = drvr_priv->iflist[ifidx];
  369. ifp->ndev->last_rx = jiffies;
  370. }
  371. drvr->dstats.rx_bytes += skb->len;
  372. drvr->rx_packets++; /* Local count */
  373. if (in_interrupt())
  374. netif_rx(skb);
  375. else
  376. /* If the receive is not processed inside an ISR,
  377. * the softirqd must be woken explicitly to service
  378. * the NET_RX_SOFTIRQ. In 2.6 kernels, this is handled
  379. * by netif_rx_ni(), but in earlier kernels, we need
  380. * to do it manually.
  381. */
  382. netif_rx_ni(skb);
  383. }
  384. }
  385. void brcmf_txcomplete(struct brcmf_pub *drvr, struct sk_buff *txp, bool success)
  386. {
  387. uint ifidx;
  388. struct brcmf_info *drvr_priv = drvr->info;
  389. struct ethhdr *eh;
  390. u16 type;
  391. brcmf_proto_hdrpull(drvr, &ifidx, txp);
  392. eh = (struct ethhdr *)(txp->data);
  393. type = ntohs(eh->h_proto);
  394. if (type == ETH_P_PAE)
  395. atomic_dec(&drvr_priv->pend_8021x_cnt);
  396. }
  397. static struct net_device_stats *brcmf_netdev_get_stats(struct net_device *ndev)
  398. {
  399. struct brcmf_if *ifp = netdev_priv(ndev);
  400. struct brcmf_info *drvr_priv = ifp->info;
  401. brcmf_dbg(TRACE, "Enter\n");
  402. if (drvr_priv->pub.up)
  403. /* Use the protocol to get dongle stats */
  404. brcmf_proto_dstats(&drvr_priv->pub);
  405. /* Copy dongle stats to net device stats */
  406. ifp->stats.rx_packets = drvr_priv->pub.dstats.rx_packets;
  407. ifp->stats.tx_packets = drvr_priv->pub.dstats.tx_packets;
  408. ifp->stats.rx_bytes = drvr_priv->pub.dstats.rx_bytes;
  409. ifp->stats.tx_bytes = drvr_priv->pub.dstats.tx_bytes;
  410. ifp->stats.rx_errors = drvr_priv->pub.dstats.rx_errors;
  411. ifp->stats.tx_errors = drvr_priv->pub.dstats.tx_errors;
  412. ifp->stats.rx_dropped = drvr_priv->pub.dstats.rx_dropped;
  413. ifp->stats.tx_dropped = drvr_priv->pub.dstats.tx_dropped;
  414. ifp->stats.multicast = drvr_priv->pub.dstats.multicast;
  415. return &ifp->stats;
  416. }
  417. /* Retrieve current toe component enables, which are kept
  418. as a bitmap in toe_ol iovar */
  419. static int brcmf_toe_get(struct brcmf_info *drvr_priv, int ifidx, u32 *toe_ol)
  420. {
  421. struct brcmf_dcmd dcmd;
  422. __le32 toe_le;
  423. char buf[32];
  424. int ret;
  425. memset(&dcmd, 0, sizeof(dcmd));
  426. dcmd.cmd = BRCMF_C_GET_VAR;
  427. dcmd.buf = buf;
  428. dcmd.len = (uint) sizeof(buf);
  429. dcmd.set = false;
  430. strcpy(buf, "toe_ol");
  431. ret = brcmf_proto_dcmd(&drvr_priv->pub, ifidx, &dcmd, dcmd.len);
  432. if (ret < 0) {
  433. /* Check for older dongle image that doesn't support toe_ol */
  434. if (ret == -EIO) {
  435. brcmf_dbg(ERROR, "%s: toe not supported by device\n",
  436. brcmf_ifname(&drvr_priv->pub, ifidx));
  437. return -EOPNOTSUPP;
  438. }
  439. brcmf_dbg(INFO, "%s: could not get toe_ol: ret=%d\n",
  440. brcmf_ifname(&drvr_priv->pub, ifidx), ret);
  441. return ret;
  442. }
  443. memcpy(&toe_le, buf, sizeof(u32));
  444. *toe_ol = le32_to_cpu(toe_le);
  445. return 0;
  446. }
  447. /* Set current toe component enables in toe_ol iovar,
  448. and set toe global enable iovar */
  449. static int brcmf_toe_set(struct brcmf_info *drvr_priv, int ifidx, u32 toe_ol)
  450. {
  451. struct brcmf_dcmd dcmd;
  452. char buf[32];
  453. int ret;
  454. __le32 toe_le = cpu_to_le32(toe_ol);
  455. memset(&dcmd, 0, sizeof(dcmd));
  456. dcmd.cmd = BRCMF_C_SET_VAR;
  457. dcmd.buf = buf;
  458. dcmd.len = (uint) sizeof(buf);
  459. dcmd.set = true;
  460. /* Set toe_ol as requested */
  461. strcpy(buf, "toe_ol");
  462. memcpy(&buf[sizeof("toe_ol")], &toe_le, sizeof(u32));
  463. ret = brcmf_proto_dcmd(&drvr_priv->pub, ifidx, &dcmd, dcmd.len);
  464. if (ret < 0) {
  465. brcmf_dbg(ERROR, "%s: could not set toe_ol: ret=%d\n",
  466. brcmf_ifname(&drvr_priv->pub, ifidx), ret);
  467. return ret;
  468. }
  469. /* Enable toe globally only if any components are enabled. */
  470. toe_le = cpu_to_le32(toe_ol != 0);
  471. strcpy(buf, "toe");
  472. memcpy(&buf[sizeof("toe")], &toe_le, sizeof(u32));
  473. ret = brcmf_proto_dcmd(&drvr_priv->pub, ifidx, &dcmd, dcmd.len);
  474. if (ret < 0) {
  475. brcmf_dbg(ERROR, "%s: could not set toe: ret=%d\n",
  476. brcmf_ifname(&drvr_priv->pub, ifidx), ret);
  477. return ret;
  478. }
  479. return 0;
  480. }
  481. static void brcmf_ethtool_get_drvinfo(struct net_device *ndev,
  482. struct ethtool_drvinfo *info)
  483. {
  484. struct brcmf_if *ifp = netdev_priv(ndev);
  485. struct brcmf_info *drvr_priv = ifp->info;
  486. sprintf(info->driver, KBUILD_MODNAME);
  487. sprintf(info->version, "%lu", drvr_priv->pub.drv_version);
  488. sprintf(info->fw_version, "%s", BCM4329_FW_NAME);
  489. sprintf(info->bus_info, "%s",
  490. dev_name(brcmf_bus_get_device(drvr_priv->pub.bus)));
  491. }
  492. static struct ethtool_ops brcmf_ethtool_ops = {
  493. .get_drvinfo = brcmf_ethtool_get_drvinfo
  494. };
  495. static int brcmf_ethtool(struct brcmf_info *drvr_priv, void __user *uaddr)
  496. {
  497. struct ethtool_drvinfo info;
  498. char drvname[sizeof(info.driver)];
  499. u32 cmd;
  500. struct ethtool_value edata;
  501. u32 toe_cmpnt, csum_dir;
  502. int ret;
  503. brcmf_dbg(TRACE, "Enter\n");
  504. /* all ethtool calls start with a cmd word */
  505. if (copy_from_user(&cmd, uaddr, sizeof(u32)))
  506. return -EFAULT;
  507. switch (cmd) {
  508. case ETHTOOL_GDRVINFO:
  509. /* Copy out any request driver name */
  510. if (copy_from_user(&info, uaddr, sizeof(info)))
  511. return -EFAULT;
  512. strncpy(drvname, info.driver, sizeof(info.driver));
  513. drvname[sizeof(info.driver) - 1] = '\0';
  514. /* clear struct for return */
  515. memset(&info, 0, sizeof(info));
  516. info.cmd = cmd;
  517. /* if requested, identify ourselves */
  518. if (strcmp(drvname, "?dhd") == 0) {
  519. sprintf(info.driver, "dhd");
  520. strcpy(info.version, BRCMF_VERSION_STR);
  521. }
  522. /* otherwise, require dongle to be up */
  523. else if (!drvr_priv->pub.up) {
  524. brcmf_dbg(ERROR, "dongle is not up\n");
  525. return -ENODEV;
  526. }
  527. /* finally, report dongle driver type */
  528. else if (drvr_priv->pub.iswl)
  529. sprintf(info.driver, "wl");
  530. else
  531. sprintf(info.driver, "xx");
  532. sprintf(info.version, "%lu", drvr_priv->pub.drv_version);
  533. if (copy_to_user(uaddr, &info, sizeof(info)))
  534. return -EFAULT;
  535. brcmf_dbg(CTL, "given %*s, returning %s\n",
  536. (int)sizeof(drvname), drvname, info.driver);
  537. break;
  538. /* Get toe offload components from dongle */
  539. case ETHTOOL_GRXCSUM:
  540. case ETHTOOL_GTXCSUM:
  541. ret = brcmf_toe_get(drvr_priv, 0, &toe_cmpnt);
  542. if (ret < 0)
  543. return ret;
  544. csum_dir =
  545. (cmd == ETHTOOL_GTXCSUM) ? TOE_TX_CSUM_OL : TOE_RX_CSUM_OL;
  546. edata.cmd = cmd;
  547. edata.data = (toe_cmpnt & csum_dir) ? 1 : 0;
  548. if (copy_to_user(uaddr, &edata, sizeof(edata)))
  549. return -EFAULT;
  550. break;
  551. /* Set toe offload components in dongle */
  552. case ETHTOOL_SRXCSUM:
  553. case ETHTOOL_STXCSUM:
  554. if (copy_from_user(&edata, uaddr, sizeof(edata)))
  555. return -EFAULT;
  556. /* Read the current settings, update and write back */
  557. ret = brcmf_toe_get(drvr_priv, 0, &toe_cmpnt);
  558. if (ret < 0)
  559. return ret;
  560. csum_dir =
  561. (cmd == ETHTOOL_STXCSUM) ? TOE_TX_CSUM_OL : TOE_RX_CSUM_OL;
  562. if (edata.data != 0)
  563. toe_cmpnt |= csum_dir;
  564. else
  565. toe_cmpnt &= ~csum_dir;
  566. ret = brcmf_toe_set(drvr_priv, 0, toe_cmpnt);
  567. if (ret < 0)
  568. return ret;
  569. /* If setting TX checksum mode, tell Linux the new mode */
  570. if (cmd == ETHTOOL_STXCSUM) {
  571. if (edata.data)
  572. drvr_priv->iflist[0]->ndev->features |=
  573. NETIF_F_IP_CSUM;
  574. else
  575. drvr_priv->iflist[0]->ndev->features &=
  576. ~NETIF_F_IP_CSUM;
  577. }
  578. break;
  579. default:
  580. return -EOPNOTSUPP;
  581. }
  582. return 0;
  583. }
  584. static int brcmf_netdev_ioctl_entry(struct net_device *ndev, struct ifreq *ifr,
  585. int cmd)
  586. {
  587. struct brcmf_if *ifp = netdev_priv(ndev);
  588. struct brcmf_info *drvr_priv = ifp->info;
  589. brcmf_dbg(TRACE, "ifidx %d, cmd 0x%04x\n", ifp->idx, cmd);
  590. if (!drvr_priv->iflist[ifp->idx])
  591. return -1;
  592. if (cmd == SIOCETHTOOL)
  593. return brcmf_ethtool(drvr_priv, ifr->ifr_data);
  594. return -EOPNOTSUPP;
  595. }
  596. /* called only from within this driver. Sends a command to the dongle. */
  597. s32 brcmf_exec_dcmd(struct net_device *ndev, u32 cmd, void *arg, u32 len)
  598. {
  599. struct brcmf_dcmd dcmd;
  600. s32 err = 0;
  601. int buflen = 0;
  602. bool is_set_key_cmd;
  603. struct brcmf_if *ifp = netdev_priv(ndev);
  604. struct brcmf_info *drvr_priv = ifp->info;
  605. memset(&dcmd, 0, sizeof(dcmd));
  606. dcmd.cmd = cmd;
  607. dcmd.buf = arg;
  608. dcmd.len = len;
  609. if (dcmd.buf != NULL)
  610. buflen = min_t(uint, dcmd.len, BRCMF_DCMD_MAXLEN);
  611. /* send to dongle (must be up, and wl) */
  612. if ((drvr_priv->pub.busstate != BRCMF_BUS_DATA)) {
  613. brcmf_dbg(ERROR, "DONGLE_DOWN\n");
  614. err = -EIO;
  615. goto done;
  616. }
  617. if (!drvr_priv->pub.iswl) {
  618. err = -EIO;
  619. goto done;
  620. }
  621. /*
  622. * Intercept BRCMF_C_SET_KEY CMD - serialize M4 send and
  623. * set key CMD to prevent M4 encryption.
  624. */
  625. is_set_key_cmd = ((dcmd.cmd == BRCMF_C_SET_KEY) ||
  626. ((dcmd.cmd == BRCMF_C_SET_VAR) &&
  627. !(strncmp("wsec_key", dcmd.buf, 9))) ||
  628. ((dcmd.cmd == BRCMF_C_SET_VAR) &&
  629. !(strncmp("bsscfg:wsec_key", dcmd.buf, 15))));
  630. if (is_set_key_cmd)
  631. brcmf_netdev_wait_pend8021x(ndev);
  632. err = brcmf_proto_dcmd(&drvr_priv->pub, ifp->idx, &dcmd, buflen);
  633. done:
  634. if (err > 0)
  635. err = 0;
  636. return err;
  637. }
  638. static int brcmf_netdev_stop(struct net_device *ndev)
  639. {
  640. struct brcmf_if *ifp = netdev_priv(ndev);
  641. struct brcmf_pub *drvr = &ifp->info->pub;
  642. brcmf_dbg(TRACE, "Enter\n");
  643. brcmf_cfg80211_down(drvr->config);
  644. if (drvr->up == 0)
  645. return 0;
  646. /* Set state and stop OS transmissions */
  647. drvr->up = 0;
  648. netif_stop_queue(ndev);
  649. return 0;
  650. }
  651. static int brcmf_netdev_open(struct net_device *ndev)
  652. {
  653. struct brcmf_if *ifp = netdev_priv(ndev);
  654. struct brcmf_info *drvr_priv = ifp->info;
  655. u32 toe_ol;
  656. s32 ret = 0;
  657. brcmf_dbg(TRACE, "ifidx %d\n", ifp->idx);
  658. if (ifp->idx == 0) { /* do it only for primary eth0 */
  659. /* try to bring up bus */
  660. ret = brcmf_bus_start(&drvr_priv->pub);
  661. if (ret != 0) {
  662. brcmf_dbg(ERROR, "failed with code %d\n", ret);
  663. return -1;
  664. }
  665. atomic_set(&drvr_priv->pend_8021x_cnt, 0);
  666. memcpy(ndev->dev_addr, drvr_priv->pub.mac, ETH_ALEN);
  667. /* Get current TOE mode from dongle */
  668. if (brcmf_toe_get(drvr_priv, ifp->idx, &toe_ol) >= 0
  669. && (toe_ol & TOE_TX_CSUM_OL) != 0)
  670. drvr_priv->iflist[ifp->idx]->ndev->features |=
  671. NETIF_F_IP_CSUM;
  672. else
  673. drvr_priv->iflist[ifp->idx]->ndev->features &=
  674. ~NETIF_F_IP_CSUM;
  675. }
  676. /* Allow transmit calls */
  677. netif_start_queue(ndev);
  678. drvr_priv->pub.up = 1;
  679. if (brcmf_cfg80211_up(drvr_priv->pub.config)) {
  680. brcmf_dbg(ERROR, "failed to bring up cfg80211\n");
  681. return -1;
  682. }
  683. return ret;
  684. }
  685. static const struct net_device_ops brcmf_netdev_ops_pri = {
  686. .ndo_open = brcmf_netdev_open,
  687. .ndo_stop = brcmf_netdev_stop,
  688. .ndo_get_stats = brcmf_netdev_get_stats,
  689. .ndo_do_ioctl = brcmf_netdev_ioctl_entry,
  690. .ndo_start_xmit = brcmf_netdev_start_xmit,
  691. .ndo_set_mac_address = brcmf_netdev_set_mac_address,
  692. .ndo_set_rx_mode = brcmf_netdev_set_multicast_list
  693. };
  694. int
  695. brcmf_add_if(struct brcmf_info *drvr_priv, int ifidx, char *name, u8 *mac_addr)
  696. {
  697. struct brcmf_if *ifp;
  698. struct net_device *ndev;
  699. brcmf_dbg(TRACE, "idx %d\n", ifidx);
  700. ifp = drvr_priv->iflist[ifidx];
  701. /*
  702. * Delete the existing interface before overwriting it
  703. * in case we missed the BRCMF_E_IF_DEL event.
  704. */
  705. if (ifp) {
  706. brcmf_dbg(ERROR, "ERROR: netdev:%s already exists, try free & unregister\n",
  707. ifp->ndev->name);
  708. netif_stop_queue(ifp->ndev);
  709. unregister_netdev(ifp->ndev);
  710. free_netdev(ifp->ndev);
  711. drvr_priv->iflist[ifidx] = NULL;
  712. }
  713. /* Allocate netdev, including space for private structure */
  714. ndev = alloc_netdev(sizeof(struct brcmf_if), name, ether_setup);
  715. if (!ndev) {
  716. brcmf_dbg(ERROR, "OOM - alloc_netdev\n");
  717. return -ENOMEM;
  718. }
  719. ifp = netdev_priv(ndev);
  720. ifp->ndev = ndev;
  721. ifp->info = drvr_priv;
  722. drvr_priv->iflist[ifidx] = ifp;
  723. ifp->idx = ifidx;
  724. if (mac_addr != NULL)
  725. memcpy(&ifp->mac_addr, mac_addr, ETH_ALEN);
  726. if (brcmf_net_attach(&drvr_priv->pub, ifp->idx)) {
  727. brcmf_dbg(ERROR, "brcmf_net_attach failed");
  728. free_netdev(ifp->ndev);
  729. drvr_priv->iflist[ifidx] = NULL;
  730. return -EOPNOTSUPP;
  731. }
  732. brcmf_dbg(TRACE, " ==== pid:%x, net_device for if:%s created ===\n",
  733. current->pid, ifp->ndev->name);
  734. return 0;
  735. }
  736. void brcmf_del_if(struct brcmf_info *drvr_priv, int ifidx)
  737. {
  738. struct brcmf_if *ifp;
  739. brcmf_dbg(TRACE, "idx %d\n", ifidx);
  740. ifp = drvr_priv->iflist[ifidx];
  741. if (!ifp) {
  742. brcmf_dbg(ERROR, "Null interface\n");
  743. return;
  744. }
  745. if (ifp->ndev) {
  746. if (ifidx == 0) {
  747. if (ifp->ndev->netdev_ops == &brcmf_netdev_ops_pri) {
  748. rtnl_lock();
  749. brcmf_netdev_stop(ifp->ndev);
  750. rtnl_unlock();
  751. }
  752. } else {
  753. netif_stop_queue(ifp->ndev);
  754. }
  755. unregister_netdev(ifp->ndev);
  756. drvr_priv->iflist[ifidx] = NULL;
  757. if (ifidx == 0)
  758. brcmf_cfg80211_detach(drvr_priv->pub.config);
  759. free_netdev(ifp->ndev);
  760. }
  761. }
  762. struct brcmf_pub *brcmf_attach(struct brcmf_bus *bus, uint bus_hdrlen)
  763. {
  764. struct brcmf_info *drvr_priv = NULL;
  765. brcmf_dbg(TRACE, "Enter\n");
  766. /* Allocate primary brcmf_info */
  767. drvr_priv = kzalloc(sizeof(struct brcmf_info), GFP_ATOMIC);
  768. if (!drvr_priv)
  769. goto fail;
  770. mutex_init(&drvr_priv->proto_block);
  771. /* Link to info module */
  772. drvr_priv->pub.info = drvr_priv;
  773. /* Link to bus module */
  774. drvr_priv->pub.bus = bus;
  775. drvr_priv->pub.hdrlen = bus_hdrlen;
  776. /* Attach and link in the protocol */
  777. if (brcmf_proto_attach(&drvr_priv->pub) != 0) {
  778. brcmf_dbg(ERROR, "brcmf_prot_attach failed\n");
  779. goto fail;
  780. }
  781. INIT_WORK(&drvr_priv->setmacaddr_work, _brcmf_set_mac_address);
  782. INIT_WORK(&drvr_priv->multicast_work, _brcmf_set_multicast_list);
  783. return &drvr_priv->pub;
  784. fail:
  785. if (drvr_priv)
  786. brcmf_detach(&drvr_priv->pub);
  787. return NULL;
  788. }
  789. int brcmf_bus_start(struct brcmf_pub *drvr)
  790. {
  791. int ret = -1;
  792. struct brcmf_info *drvr_priv = drvr->info;
  793. /* Room for "event_msgs" + '\0' + bitvec */
  794. char iovbuf[BRCMF_EVENTING_MASK_LEN + 12];
  795. brcmf_dbg(TRACE, "\n");
  796. /* Bring up the bus */
  797. ret = brcmf_sdbrcm_bus_init(&drvr_priv->pub);
  798. if (ret != 0) {
  799. brcmf_dbg(ERROR, "brcmf_sdbrcm_bus_init failed %d\n", ret);
  800. return ret;
  801. }
  802. /* If bus is not ready, can't come up */
  803. if (drvr_priv->pub.busstate != BRCMF_BUS_DATA) {
  804. brcmf_dbg(ERROR, "failed bus is not ready\n");
  805. return -ENODEV;
  806. }
  807. brcmf_c_mkiovar("event_msgs", drvr->eventmask, BRCMF_EVENTING_MASK_LEN,
  808. iovbuf, sizeof(iovbuf));
  809. brcmf_proto_cdc_query_dcmd(drvr, 0, BRCMF_C_GET_VAR, iovbuf,
  810. sizeof(iovbuf));
  811. memcpy(drvr->eventmask, iovbuf, BRCMF_EVENTING_MASK_LEN);
  812. setbit(drvr->eventmask, BRCMF_E_SET_SSID);
  813. setbit(drvr->eventmask, BRCMF_E_PRUNE);
  814. setbit(drvr->eventmask, BRCMF_E_AUTH);
  815. setbit(drvr->eventmask, BRCMF_E_REASSOC);
  816. setbit(drvr->eventmask, BRCMF_E_REASSOC_IND);
  817. setbit(drvr->eventmask, BRCMF_E_DEAUTH_IND);
  818. setbit(drvr->eventmask, BRCMF_E_DISASSOC_IND);
  819. setbit(drvr->eventmask, BRCMF_E_DISASSOC);
  820. setbit(drvr->eventmask, BRCMF_E_JOIN);
  821. setbit(drvr->eventmask, BRCMF_E_ASSOC_IND);
  822. setbit(drvr->eventmask, BRCMF_E_PSK_SUP);
  823. setbit(drvr->eventmask, BRCMF_E_LINK);
  824. setbit(drvr->eventmask, BRCMF_E_NDIS_LINK);
  825. setbit(drvr->eventmask, BRCMF_E_MIC_ERROR);
  826. setbit(drvr->eventmask, BRCMF_E_PMKID_CACHE);
  827. setbit(drvr->eventmask, BRCMF_E_TXFAIL);
  828. setbit(drvr->eventmask, BRCMF_E_JOIN_START);
  829. setbit(drvr->eventmask, BRCMF_E_SCAN_COMPLETE);
  830. /* enable dongle roaming event */
  831. drvr->pktfilter_count = 1;
  832. /* Setup filter to allow only unicast */
  833. drvr->pktfilter[0] = "100 0 0 0 0x01 0x00";
  834. /* Bus is ready, do any protocol initialization */
  835. ret = brcmf_proto_init(&drvr_priv->pub);
  836. if (ret < 0)
  837. return ret;
  838. return 0;
  839. }
  840. int brcmf_net_attach(struct brcmf_pub *drvr, int ifidx)
  841. {
  842. struct brcmf_info *drvr_priv = drvr->info;
  843. struct net_device *ndev;
  844. u8 temp_addr[ETH_ALEN] = {
  845. 0x00, 0x90, 0x4c, 0x11, 0x22, 0x33};
  846. brcmf_dbg(TRACE, "ifidx %d\n", ifidx);
  847. ndev = drvr_priv->iflist[ifidx]->ndev;
  848. ndev->netdev_ops = &brcmf_netdev_ops_pri;
  849. /*
  850. * We have to use the primary MAC for virtual interfaces
  851. */
  852. if (ifidx != 0) {
  853. /* for virtual interfaces use the primary MAC */
  854. memcpy(temp_addr, drvr_priv->pub.mac, ETH_ALEN);
  855. }
  856. if (ifidx == 1) {
  857. brcmf_dbg(TRACE, "ACCESS POINT MAC:\n");
  858. /* ACCESSPOINT INTERFACE CASE */
  859. temp_addr[0] |= 0X02; /* set bit 2 ,
  860. - Locally Administered address */
  861. }
  862. ndev->hard_header_len = ETH_HLEN + drvr_priv->pub.hdrlen;
  863. ndev->ethtool_ops = &brcmf_ethtool_ops;
  864. drvr_priv->pub.rxsz = ndev->mtu + ndev->hard_header_len +
  865. drvr_priv->pub.hdrlen;
  866. memcpy(ndev->dev_addr, temp_addr, ETH_ALEN);
  867. /* attach to cfg80211 for primary interface */
  868. if (!ifidx) {
  869. drvr->config =
  870. brcmf_cfg80211_attach(ndev,
  871. brcmf_bus_get_device(drvr->bus),
  872. drvr);
  873. if (drvr->config == NULL) {
  874. brcmf_dbg(ERROR, "wl_cfg80211_attach failed\n");
  875. goto fail;
  876. }
  877. }
  878. if (register_netdev(ndev) != 0) {
  879. brcmf_dbg(ERROR, "couldn't register the net device\n");
  880. goto fail;
  881. }
  882. brcmf_dbg(INFO, "%s: Broadcom Dongle Host Driver\n", ndev->name);
  883. return 0;
  884. fail:
  885. ndev->netdev_ops = NULL;
  886. return -EBADE;
  887. }
  888. static void brcmf_bus_detach(struct brcmf_pub *drvr)
  889. {
  890. struct brcmf_info *drvr_priv;
  891. brcmf_dbg(TRACE, "Enter\n");
  892. if (drvr) {
  893. drvr_priv = drvr->info;
  894. if (drvr_priv) {
  895. /* Stop the protocol module */
  896. brcmf_proto_stop(&drvr_priv->pub);
  897. /* Stop the bus module */
  898. brcmf_sdbrcm_bus_stop(drvr_priv->pub.bus);
  899. }
  900. }
  901. }
  902. void brcmf_detach(struct brcmf_pub *drvr)
  903. {
  904. struct brcmf_info *drvr_priv;
  905. brcmf_dbg(TRACE, "Enter\n");
  906. if (drvr) {
  907. drvr_priv = drvr->info;
  908. if (drvr_priv) {
  909. int i;
  910. /* make sure primary interface removed last */
  911. for (i = BRCMF_MAX_IFS-1; i > -1; i--)
  912. if (drvr_priv->iflist[i])
  913. brcmf_del_if(drvr_priv, i);
  914. cancel_work_sync(&drvr_priv->setmacaddr_work);
  915. cancel_work_sync(&drvr_priv->multicast_work);
  916. brcmf_bus_detach(drvr);
  917. if (drvr->prot)
  918. brcmf_proto_detach(drvr);
  919. kfree(drvr_priv);
  920. }
  921. }
  922. }
  923. static void __exit brcmf_module_cleanup(void)
  924. {
  925. brcmf_dbg(TRACE, "Enter\n");
  926. brcmf_bus_unregister();
  927. }
  928. static int __init brcmf_module_init(void)
  929. {
  930. int error;
  931. brcmf_dbg(TRACE, "Enter\n");
  932. error = brcmf_bus_register();
  933. if (error) {
  934. brcmf_dbg(ERROR, "brcmf_bus_register failed\n");
  935. goto failed;
  936. }
  937. return 0;
  938. failed:
  939. return -EINVAL;
  940. }
  941. module_init(brcmf_module_init);
  942. module_exit(brcmf_module_cleanup);
  943. int brcmf_os_proto_block(struct brcmf_pub *drvr)
  944. {
  945. struct brcmf_info *drvr_priv = drvr->info;
  946. if (drvr_priv) {
  947. mutex_lock(&drvr_priv->proto_block);
  948. return 1;
  949. }
  950. return 0;
  951. }
  952. int brcmf_os_proto_unblock(struct brcmf_pub *drvr)
  953. {
  954. struct brcmf_info *drvr_priv = drvr->info;
  955. if (drvr_priv) {
  956. mutex_unlock(&drvr_priv->proto_block);
  957. return 1;
  958. }
  959. return 0;
  960. }
  961. static int brcmf_get_pend_8021x_cnt(struct brcmf_info *drvr_priv)
  962. {
  963. return atomic_read(&drvr_priv->pend_8021x_cnt);
  964. }
  965. #define MAX_WAIT_FOR_8021X_TX 10
  966. int brcmf_netdev_wait_pend8021x(struct net_device *ndev)
  967. {
  968. struct brcmf_if *ifp = netdev_priv(ndev);
  969. struct brcmf_info *drvr_priv = ifp->info;
  970. int timeout = 10 * HZ / 1000;
  971. int ntimes = MAX_WAIT_FOR_8021X_TX;
  972. int pend = brcmf_get_pend_8021x_cnt(drvr_priv);
  973. while (ntimes && pend) {
  974. if (pend) {
  975. set_current_state(TASK_INTERRUPTIBLE);
  976. schedule_timeout(timeout);
  977. set_current_state(TASK_RUNNING);
  978. ntimes--;
  979. }
  980. pend = brcmf_get_pend_8021x_cnt(drvr_priv);
  981. }
  982. return pend;
  983. }
  984. #ifdef BCMDBG
  985. int brcmf_write_to_file(struct brcmf_pub *drvr, const u8 *buf, int size)
  986. {
  987. int ret = 0;
  988. struct file *fp;
  989. mm_segment_t old_fs;
  990. loff_t pos = 0;
  991. /* change to KERNEL_DS address limit */
  992. old_fs = get_fs();
  993. set_fs(KERNEL_DS);
  994. /* open file to write */
  995. fp = filp_open("/tmp/mem_dump", O_WRONLY | O_CREAT, 0640);
  996. if (!fp) {
  997. brcmf_dbg(ERROR, "open file error\n");
  998. ret = -1;
  999. goto exit;
  1000. }
  1001. /* Write buf to file */
  1002. fp->f_op->write(fp, (char __user *)buf, size, &pos);
  1003. exit:
  1004. /* free buf before return */
  1005. kfree(buf);
  1006. /* close file before return */
  1007. if (fp)
  1008. filp_close(fp, current->files);
  1009. /* restore previous address limit */
  1010. set_fs(old_fs);
  1011. return ret;
  1012. }
  1013. #endif /* BCMDBG */