dhd_linux.c 31 KB

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