dhd_linux.c 30 KB

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