dhd_linux.c 30 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235
  1. /*
  2. * Copyright (c) 2010 Broadcom Corporation
  3. *
  4. * Permission to use, copy, modify, and/or distribute this software for any
  5. * purpose with or without fee is hereby granted, provided that the above
  6. * copyright notice and this permission notice appear in all copies.
  7. *
  8. * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
  9. * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
  10. * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
  11. * SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
  12. * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
  13. * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
  14. * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  15. */
  16. #include <linux/init.h>
  17. #include <linux/kernel.h>
  18. #include <linux/kthread.h>
  19. #include <linux/slab.h>
  20. #include <linux/skbuff.h>
  21. #include <linux/netdevice.h>
  22. #include <linux/etherdevice.h>
  23. #include <linux/mmc/sdio_func.h>
  24. #include <linux/random.h>
  25. #include <linux/spinlock.h>
  26. #include <linux/ethtool.h>
  27. #include <linux/fcntl.h>
  28. #include <linux/fs.h>
  29. #include <linux/uaccess.h>
  30. #include <linux/hardirq.h>
  31. #include <linux/mutex.h>
  32. #include <linux/wait.h>
  33. #include <linux/module.h>
  34. #include <net/cfg80211.h>
  35. #include <net/rtnetlink.h>
  36. #include <defs.h>
  37. #include <brcmu_utils.h>
  38. #include <brcmu_wifi.h>
  39. #include "dhd.h"
  40. #include "dhd_bus.h"
  41. #include "dhd_proto.h"
  42. #include "dhd_dbg.h"
  43. #include "wl_cfg80211.h"
  44. MODULE_AUTHOR("Broadcom Corporation");
  45. MODULE_DESCRIPTION("Broadcom 802.11n wireless LAN fullmac driver.");
  46. MODULE_SUPPORTED_DEVICE("Broadcom 802.11n WLAN fullmac cards");
  47. MODULE_LICENSE("Dual BSD/GPL");
  48. /* Interface control information */
  49. struct brcmf_if {
  50. struct brcmf_info *info; /* back pointer to brcmf_info */
  51. /* OS/stack specifics */
  52. struct net_device *ndev;
  53. struct net_device_stats stats;
  54. int idx; /* iface idx in dongle */
  55. u8 mac_addr[ETH_ALEN]; /* assigned MAC address */
  56. };
  57. /* Local private structure (extension of pub) */
  58. struct brcmf_info {
  59. struct brcmf_pub pub;
  60. /* OS/stack specifics */
  61. struct brcmf_if *iflist[BRCMF_MAX_IFS];
  62. struct mutex proto_block;
  63. struct work_struct setmacaddr_work;
  64. struct work_struct multicast_work;
  65. u8 macvalue[ETH_ALEN];
  66. atomic_t pend_8021x_cnt;
  67. };
  68. /* Error bits */
  69. int brcmf_msg_level = BRCMF_ERROR_VAL;
  70. module_param(brcmf_msg_level, int, 0);
  71. int brcmf_ifname2idx(struct brcmf_info *drvr_priv, char *name)
  72. {
  73. int i = BRCMF_MAX_IFS;
  74. struct brcmf_if *ifp;
  75. if (name == NULL || *name == '\0')
  76. return 0;
  77. while (--i > 0) {
  78. ifp = drvr_priv->iflist[i];
  79. if (ifp && !strncmp(ifp->ndev->name, name, IFNAMSIZ))
  80. break;
  81. }
  82. brcmf_dbg(TRACE, "return idx %d for \"%s\"\n", i, name);
  83. return i; /* default - the primary interface */
  84. }
  85. char *brcmf_ifname(struct brcmf_pub *drvr, int ifidx)
  86. {
  87. struct brcmf_info *drvr_priv = drvr->info;
  88. if (ifidx < 0 || ifidx >= BRCMF_MAX_IFS) {
  89. brcmf_dbg(ERROR, "ifidx %d out of range\n", ifidx);
  90. return "<if_bad>";
  91. }
  92. if (drvr_priv->iflist[ifidx] == NULL) {
  93. brcmf_dbg(ERROR, "null i/f %d\n", ifidx);
  94. return "<if_null>";
  95. }
  96. if (drvr_priv->iflist[ifidx]->ndev)
  97. return drvr_priv->iflist[ifidx]->ndev->name;
  98. return "<if_none>";
  99. }
  100. static void _brcmf_set_multicast_list(struct work_struct *work)
  101. {
  102. struct net_device *ndev;
  103. struct netdev_hw_addr *ha;
  104. u32 dcmd_value, cnt;
  105. __le32 cnt_le;
  106. __le32 dcmd_le_value;
  107. struct brcmf_dcmd dcmd;
  108. char *buf, *bufp;
  109. uint buflen;
  110. int ret;
  111. struct brcmf_info *drvr_priv = container_of(work, struct brcmf_info,
  112. multicast_work);
  113. ndev = drvr_priv->iflist[0]->ndev;
  114. cnt = netdev_mc_count(ndev);
  115. /* Determine initial value of allmulti flag */
  116. dcmd_value = (ndev->flags & IFF_ALLMULTI) ? true : false;
  117. /* Send down the multicast list first. */
  118. buflen = sizeof("mcast_list") + sizeof(cnt) + (cnt * ETH_ALEN);
  119. bufp = buf = kmalloc(buflen, GFP_ATOMIC);
  120. if (!bufp)
  121. return;
  122. strcpy(bufp, "mcast_list");
  123. bufp += strlen("mcast_list") + 1;
  124. cnt_le = cpu_to_le32(cnt);
  125. memcpy(bufp, &cnt_le, sizeof(cnt));
  126. bufp += sizeof(cnt_le);
  127. netdev_for_each_mc_addr(ha, ndev) {
  128. if (!cnt)
  129. break;
  130. memcpy(bufp, ha->addr, ETH_ALEN);
  131. bufp += ETH_ALEN;
  132. cnt--;
  133. }
  134. memset(&dcmd, 0, sizeof(dcmd));
  135. dcmd.cmd = BRCMF_C_SET_VAR;
  136. dcmd.buf = buf;
  137. dcmd.len = buflen;
  138. dcmd.set = true;
  139. ret = brcmf_proto_dcmd(&drvr_priv->pub, 0, &dcmd, dcmd.len);
  140. if (ret < 0) {
  141. brcmf_dbg(ERROR, "%s: set mcast_list failed, cnt %d\n",
  142. brcmf_ifname(&drvr_priv->pub, 0), cnt);
  143. dcmd_value = cnt ? true : dcmd_value;
  144. }
  145. kfree(buf);
  146. /* Now send the allmulti setting. This is based on the setting in the
  147. * net_device flags, but might be modified above to be turned on if we
  148. * were trying to set some addresses and dongle rejected it...
  149. */
  150. buflen = sizeof("allmulti") + sizeof(dcmd_value);
  151. buf = kmalloc(buflen, GFP_ATOMIC);
  152. if (!buf)
  153. return;
  154. dcmd_le_value = cpu_to_le32(dcmd_value);
  155. if (!brcmf_c_mkiovar
  156. ("allmulti", (void *)&dcmd_le_value,
  157. sizeof(dcmd_le_value), buf, buflen)) {
  158. brcmf_dbg(ERROR, "%s: mkiovar failed for allmulti, datalen %d buflen %u\n",
  159. brcmf_ifname(&drvr_priv->pub, 0),
  160. (int)sizeof(dcmd_value), buflen);
  161. kfree(buf);
  162. return;
  163. }
  164. memset(&dcmd, 0, sizeof(dcmd));
  165. dcmd.cmd = BRCMF_C_SET_VAR;
  166. dcmd.buf = buf;
  167. dcmd.len = buflen;
  168. dcmd.set = true;
  169. ret = brcmf_proto_dcmd(&drvr_priv->pub, 0, &dcmd, dcmd.len);
  170. if (ret < 0) {
  171. brcmf_dbg(ERROR, "%s: set allmulti %d failed\n",
  172. brcmf_ifname(&drvr_priv->pub, 0),
  173. le32_to_cpu(dcmd_le_value));
  174. }
  175. kfree(buf);
  176. /* Finally, pick up the PROMISC flag as well, like the NIC
  177. driver does */
  178. dcmd_value = (ndev->flags & IFF_PROMISC) ? true : false;
  179. dcmd_le_value = cpu_to_le32(dcmd_value);
  180. memset(&dcmd, 0, sizeof(dcmd));
  181. dcmd.cmd = BRCMF_C_SET_PROMISC;
  182. dcmd.buf = &dcmd_le_value;
  183. dcmd.len = sizeof(dcmd_le_value);
  184. dcmd.set = true;
  185. ret = brcmf_proto_dcmd(&drvr_priv->pub, 0, &dcmd, dcmd.len);
  186. if (ret < 0) {
  187. brcmf_dbg(ERROR, "%s: set promisc %d failed\n",
  188. brcmf_ifname(&drvr_priv->pub, 0),
  189. le32_to_cpu(dcmd_le_value));
  190. }
  191. }
  192. static void
  193. _brcmf_set_mac_address(struct work_struct *work)
  194. {
  195. char buf[32];
  196. struct brcmf_dcmd dcmd;
  197. int ret;
  198. struct brcmf_info *drvr_priv = container_of(work, struct brcmf_info,
  199. setmacaddr_work);
  200. brcmf_dbg(TRACE, "enter\n");
  201. if (!brcmf_c_mkiovar("cur_etheraddr", (char *)drvr_priv->macvalue,
  202. ETH_ALEN, buf, 32)) {
  203. brcmf_dbg(ERROR, "%s: mkiovar failed for cur_etheraddr\n",
  204. brcmf_ifname(&drvr_priv->pub, 0));
  205. return;
  206. }
  207. memset(&dcmd, 0, sizeof(dcmd));
  208. dcmd.cmd = BRCMF_C_SET_VAR;
  209. dcmd.buf = buf;
  210. dcmd.len = 32;
  211. dcmd.set = true;
  212. ret = brcmf_proto_dcmd(&drvr_priv->pub, 0, &dcmd, dcmd.len);
  213. if (ret < 0)
  214. brcmf_dbg(ERROR, "%s: set cur_etheraddr failed\n",
  215. brcmf_ifname(&drvr_priv->pub, 0));
  216. else
  217. memcpy(drvr_priv->iflist[0]->ndev->dev_addr,
  218. drvr_priv->macvalue, ETH_ALEN);
  219. return;
  220. }
  221. static int brcmf_netdev_set_mac_address(struct net_device *ndev, void *addr)
  222. {
  223. struct brcmf_if *ifp = netdev_priv(ndev);
  224. struct brcmf_info *drvr_priv = ifp->info;
  225. struct sockaddr *sa = (struct sockaddr *)addr;
  226. memcpy(&drvr_priv->macvalue, sa->sa_data, ETH_ALEN);
  227. schedule_work(&drvr_priv->setmacaddr_work);
  228. return 0;
  229. }
  230. static void brcmf_netdev_set_multicast_list(struct net_device *ndev)
  231. {
  232. struct brcmf_if *ifp = netdev_priv(ndev);
  233. struct brcmf_info *drvr_priv = ifp->info;
  234. schedule_work(&drvr_priv->multicast_work);
  235. }
  236. int brcmf_sendpkt(struct brcmf_pub *drvr, int ifidx, struct sk_buff *pktbuf)
  237. {
  238. struct brcmf_info *drvr_priv = drvr->info;
  239. /* Reject if down */
  240. if (!drvr->up || (drvr->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. if (!ifp || !ifp->ndev ||
  355. ifp->ndev->reg_state != NETREG_REGISTERED) {
  356. brcmu_pkt_buf_free_skb(skb);
  357. continue;
  358. }
  359. skb->dev = ifp->ndev;
  360. skb->protocol = eth_type_trans(skb, skb->dev);
  361. if (skb->pkt_type == PACKET_MULTICAST)
  362. drvr_priv->pub.rx_multicast++;
  363. skb->data = eth;
  364. skb->len = len;
  365. /* Strip header, count, deliver upward */
  366. skb_pull(skb, ETH_HLEN);
  367. /* Process special event packets and then discard them */
  368. if (ntohs(skb->protocol) == ETH_P_LINK_CTL)
  369. brcmf_host_event(drvr_priv, &ifidx,
  370. skb_mac_header(skb),
  371. &event, &data);
  372. if (drvr_priv->iflist[ifidx]) {
  373. ifp = drvr_priv->iflist[ifidx];
  374. ifp->ndev->last_rx = jiffies;
  375. }
  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->bus_info, "%s",
  494. dev_name(brcmf_bus_get_device(drvr_priv->pub.bus)));
  495. }
  496. static struct ethtool_ops brcmf_ethtool_ops = {
  497. .get_drvinfo = brcmf_ethtool_get_drvinfo
  498. };
  499. static int brcmf_ethtool(struct brcmf_info *drvr_priv, void __user *uaddr)
  500. {
  501. struct ethtool_drvinfo info;
  502. char drvname[sizeof(info.driver)];
  503. u32 cmd;
  504. struct ethtool_value edata;
  505. u32 toe_cmpnt, csum_dir;
  506. int ret;
  507. brcmf_dbg(TRACE, "Enter\n");
  508. /* all ethtool calls start with a cmd word */
  509. if (copy_from_user(&cmd, uaddr, sizeof(u32)))
  510. return -EFAULT;
  511. switch (cmd) {
  512. case ETHTOOL_GDRVINFO:
  513. /* Copy out any request driver name */
  514. if (copy_from_user(&info, uaddr, sizeof(info)))
  515. return -EFAULT;
  516. strncpy(drvname, info.driver, sizeof(info.driver));
  517. drvname[sizeof(info.driver) - 1] = '\0';
  518. /* clear struct for return */
  519. memset(&info, 0, sizeof(info));
  520. info.cmd = cmd;
  521. /* if requested, identify ourselves */
  522. if (strcmp(drvname, "?dhd") == 0) {
  523. sprintf(info.driver, "dhd");
  524. strcpy(info.version, BRCMF_VERSION_STR);
  525. }
  526. /* otherwise, require dongle to be up */
  527. else if (!drvr_priv->pub.up) {
  528. brcmf_dbg(ERROR, "dongle is not up\n");
  529. return -ENODEV;
  530. }
  531. /* finally, report dongle driver type */
  532. else if (drvr_priv->pub.iswl)
  533. sprintf(info.driver, "wl");
  534. else
  535. sprintf(info.driver, "xx");
  536. sprintf(info.version, "%lu", drvr_priv->pub.drv_version);
  537. if (copy_to_user(uaddr, &info, sizeof(info)))
  538. return -EFAULT;
  539. brcmf_dbg(CTL, "given %*s, returning %s\n",
  540. (int)sizeof(drvname), drvname, info.driver);
  541. break;
  542. /* Get toe offload components from dongle */
  543. case ETHTOOL_GRXCSUM:
  544. case ETHTOOL_GTXCSUM:
  545. ret = brcmf_toe_get(drvr_priv, 0, &toe_cmpnt);
  546. if (ret < 0)
  547. return ret;
  548. csum_dir =
  549. (cmd == ETHTOOL_GTXCSUM) ? TOE_TX_CSUM_OL : TOE_RX_CSUM_OL;
  550. edata.cmd = cmd;
  551. edata.data = (toe_cmpnt & csum_dir) ? 1 : 0;
  552. if (copy_to_user(uaddr, &edata, sizeof(edata)))
  553. return -EFAULT;
  554. break;
  555. /* Set toe offload components in dongle */
  556. case ETHTOOL_SRXCSUM:
  557. case ETHTOOL_STXCSUM:
  558. if (copy_from_user(&edata, uaddr, sizeof(edata)))
  559. return -EFAULT;
  560. /* Read the current settings, update and write back */
  561. ret = brcmf_toe_get(drvr_priv, 0, &toe_cmpnt);
  562. if (ret < 0)
  563. return ret;
  564. csum_dir =
  565. (cmd == ETHTOOL_STXCSUM) ? TOE_TX_CSUM_OL : TOE_RX_CSUM_OL;
  566. if (edata.data != 0)
  567. toe_cmpnt |= csum_dir;
  568. else
  569. toe_cmpnt &= ~csum_dir;
  570. ret = brcmf_toe_set(drvr_priv, 0, toe_cmpnt);
  571. if (ret < 0)
  572. return ret;
  573. /* If setting TX checksum mode, tell Linux the new mode */
  574. if (cmd == ETHTOOL_STXCSUM) {
  575. if (edata.data)
  576. drvr_priv->iflist[0]->ndev->features |=
  577. NETIF_F_IP_CSUM;
  578. else
  579. drvr_priv->iflist[0]->ndev->features &=
  580. ~NETIF_F_IP_CSUM;
  581. }
  582. break;
  583. default:
  584. return -EOPNOTSUPP;
  585. }
  586. return 0;
  587. }
  588. static int brcmf_netdev_ioctl_entry(struct net_device *ndev, struct ifreq *ifr,
  589. int cmd)
  590. {
  591. struct brcmf_if *ifp = netdev_priv(ndev);
  592. struct brcmf_info *drvr_priv = ifp->info;
  593. brcmf_dbg(TRACE, "ifidx %d, cmd 0x%04x\n", ifp->idx, cmd);
  594. if (!drvr_priv->iflist[ifp->idx])
  595. return -1;
  596. if (cmd == SIOCETHTOOL)
  597. return brcmf_ethtool(drvr_priv, ifr->ifr_data);
  598. return -EOPNOTSUPP;
  599. }
  600. /* called only from within this driver. Sends a command to the dongle. */
  601. s32 brcmf_exec_dcmd(struct net_device *ndev, u32 cmd, void *arg, u32 len)
  602. {
  603. struct brcmf_dcmd dcmd;
  604. s32 err = 0;
  605. int buflen = 0;
  606. bool is_set_key_cmd;
  607. struct brcmf_if *ifp = netdev_priv(ndev);
  608. struct brcmf_info *drvr_priv = ifp->info;
  609. memset(&dcmd, 0, sizeof(dcmd));
  610. dcmd.cmd = cmd;
  611. dcmd.buf = arg;
  612. dcmd.len = len;
  613. if (dcmd.buf != NULL)
  614. buflen = min_t(uint, dcmd.len, BRCMF_DCMD_MAXLEN);
  615. /* send to dongle (must be up, and wl) */
  616. if ((drvr_priv->pub.busstate != BRCMF_BUS_DATA)) {
  617. brcmf_dbg(ERROR, "DONGLE_DOWN\n");
  618. err = -EIO;
  619. goto done;
  620. }
  621. if (!drvr_priv->pub.iswl) {
  622. err = -EIO;
  623. goto done;
  624. }
  625. /*
  626. * Intercept BRCMF_C_SET_KEY CMD - serialize M4 send and
  627. * set key CMD to prevent M4 encryption.
  628. */
  629. is_set_key_cmd = ((dcmd.cmd == BRCMF_C_SET_KEY) ||
  630. ((dcmd.cmd == BRCMF_C_SET_VAR) &&
  631. !(strncmp("wsec_key", dcmd.buf, 9))) ||
  632. ((dcmd.cmd == BRCMF_C_SET_VAR) &&
  633. !(strncmp("bsscfg:wsec_key", dcmd.buf, 15))));
  634. if (is_set_key_cmd)
  635. brcmf_netdev_wait_pend8021x(ndev);
  636. err = brcmf_proto_dcmd(&drvr_priv->pub, ifp->idx, &dcmd, buflen);
  637. done:
  638. if (err > 0)
  639. err = 0;
  640. return err;
  641. }
  642. static int brcmf_netdev_stop(struct net_device *ndev)
  643. {
  644. struct brcmf_if *ifp = netdev_priv(ndev);
  645. struct brcmf_pub *drvr = &ifp->info->pub;
  646. brcmf_dbg(TRACE, "Enter\n");
  647. brcmf_cfg80211_down(drvr->config);
  648. if (drvr->up == 0)
  649. return 0;
  650. /* Set state and stop OS transmissions */
  651. drvr->up = 0;
  652. netif_stop_queue(ndev);
  653. return 0;
  654. }
  655. static int brcmf_netdev_open(struct net_device *ndev)
  656. {
  657. struct brcmf_if *ifp = netdev_priv(ndev);
  658. struct brcmf_info *drvr_priv = ifp->info;
  659. u32 toe_ol;
  660. s32 ret = 0;
  661. brcmf_dbg(TRACE, "ifidx %d\n", ifp->idx);
  662. if (ifp->idx == 0) { /* do it only for primary eth0 */
  663. /* try to bring up bus */
  664. ret = brcmf_bus_start(&drvr_priv->pub);
  665. if (ret != 0) {
  666. brcmf_dbg(ERROR, "failed with code %d\n", ret);
  667. return -1;
  668. }
  669. atomic_set(&drvr_priv->pend_8021x_cnt, 0);
  670. memcpy(ndev->dev_addr, drvr_priv->pub.mac, ETH_ALEN);
  671. /* Get current TOE mode from dongle */
  672. if (brcmf_toe_get(drvr_priv, ifp->idx, &toe_ol) >= 0
  673. && (toe_ol & TOE_TX_CSUM_OL) != 0)
  674. drvr_priv->iflist[ifp->idx]->ndev->features |=
  675. NETIF_F_IP_CSUM;
  676. else
  677. drvr_priv->iflist[ifp->idx]->ndev->features &=
  678. ~NETIF_F_IP_CSUM;
  679. }
  680. /* Allow transmit calls */
  681. netif_start_queue(ndev);
  682. drvr_priv->pub.up = 1;
  683. if (brcmf_cfg80211_up(drvr_priv->pub.config)) {
  684. brcmf_dbg(ERROR, "failed to bring up cfg80211\n");
  685. return -1;
  686. }
  687. return ret;
  688. }
  689. static const struct net_device_ops brcmf_netdev_ops_pri = {
  690. .ndo_open = brcmf_netdev_open,
  691. .ndo_stop = brcmf_netdev_stop,
  692. .ndo_get_stats = brcmf_netdev_get_stats,
  693. .ndo_do_ioctl = brcmf_netdev_ioctl_entry,
  694. .ndo_start_xmit = brcmf_netdev_start_xmit,
  695. .ndo_set_mac_address = brcmf_netdev_set_mac_address,
  696. .ndo_set_rx_mode = brcmf_netdev_set_multicast_list
  697. };
  698. int
  699. brcmf_add_if(struct brcmf_info *drvr_priv, int ifidx, char *name, u8 *mac_addr)
  700. {
  701. struct brcmf_if *ifp;
  702. struct net_device *ndev;
  703. brcmf_dbg(TRACE, "idx %d\n", ifidx);
  704. ifp = drvr_priv->iflist[ifidx];
  705. /*
  706. * Delete the existing interface before overwriting it
  707. * in case we missed the BRCMF_E_IF_DEL event.
  708. */
  709. if (ifp) {
  710. brcmf_dbg(ERROR, "ERROR: netdev:%s already exists, try free & unregister\n",
  711. ifp->ndev->name);
  712. netif_stop_queue(ifp->ndev);
  713. unregister_netdev(ifp->ndev);
  714. free_netdev(ifp->ndev);
  715. drvr_priv->iflist[ifidx] = NULL;
  716. }
  717. /* Allocate netdev, including space for private structure */
  718. ndev = alloc_netdev(sizeof(struct brcmf_if), name, ether_setup);
  719. if (!ndev) {
  720. brcmf_dbg(ERROR, "OOM - alloc_netdev\n");
  721. return -ENOMEM;
  722. }
  723. ifp = netdev_priv(ndev);
  724. ifp->ndev = ndev;
  725. ifp->info = drvr_priv;
  726. drvr_priv->iflist[ifidx] = ifp;
  727. ifp->idx = ifidx;
  728. if (mac_addr != NULL)
  729. memcpy(&ifp->mac_addr, mac_addr, ETH_ALEN);
  730. if (brcmf_net_attach(&drvr_priv->pub, ifp->idx)) {
  731. brcmf_dbg(ERROR, "brcmf_net_attach failed");
  732. free_netdev(ifp->ndev);
  733. drvr_priv->iflist[ifidx] = NULL;
  734. return -EOPNOTSUPP;
  735. }
  736. brcmf_dbg(TRACE, " ==== pid:%x, net_device for if:%s created ===\n",
  737. current->pid, ifp->ndev->name);
  738. return 0;
  739. }
  740. void brcmf_del_if(struct brcmf_info *drvr_priv, int ifidx)
  741. {
  742. struct brcmf_if *ifp;
  743. brcmf_dbg(TRACE, "idx %d\n", ifidx);
  744. ifp = drvr_priv->iflist[ifidx];
  745. if (!ifp) {
  746. brcmf_dbg(ERROR, "Null interface\n");
  747. return;
  748. }
  749. if (ifp->ndev) {
  750. if (ifidx == 0) {
  751. if (ifp->ndev->netdev_ops == &brcmf_netdev_ops_pri) {
  752. rtnl_lock();
  753. brcmf_netdev_stop(ifp->ndev);
  754. rtnl_unlock();
  755. }
  756. } else {
  757. netif_stop_queue(ifp->ndev);
  758. }
  759. unregister_netdev(ifp->ndev);
  760. drvr_priv->iflist[ifidx] = NULL;
  761. if (ifidx == 0)
  762. brcmf_cfg80211_detach(drvr_priv->pub.config);
  763. free_netdev(ifp->ndev);
  764. }
  765. }
  766. struct brcmf_pub *brcmf_attach(struct brcmf_sdio *bus, uint bus_hdrlen)
  767. {
  768. struct brcmf_info *drvr_priv = NULL;
  769. brcmf_dbg(TRACE, "Enter\n");
  770. /* Allocate primary brcmf_info */
  771. drvr_priv = kzalloc(sizeof(struct brcmf_info), GFP_ATOMIC);
  772. if (!drvr_priv)
  773. goto fail;
  774. mutex_init(&drvr_priv->proto_block);
  775. /* Link to info module */
  776. drvr_priv->pub.info = drvr_priv;
  777. /* Link to bus module */
  778. drvr_priv->pub.bus = bus;
  779. drvr_priv->pub.hdrlen = bus_hdrlen;
  780. /* Attach and link in the protocol */
  781. if (brcmf_proto_attach(&drvr_priv->pub) != 0) {
  782. brcmf_dbg(ERROR, "brcmf_prot_attach failed\n");
  783. goto fail;
  784. }
  785. INIT_WORK(&drvr_priv->setmacaddr_work, _brcmf_set_mac_address);
  786. INIT_WORK(&drvr_priv->multicast_work, _brcmf_set_multicast_list);
  787. return &drvr_priv->pub;
  788. fail:
  789. if (drvr_priv)
  790. brcmf_detach(&drvr_priv->pub);
  791. return NULL;
  792. }
  793. int brcmf_bus_start(struct brcmf_pub *drvr)
  794. {
  795. int ret = -1;
  796. struct brcmf_info *drvr_priv = drvr->info;
  797. /* Room for "event_msgs" + '\0' + bitvec */
  798. char iovbuf[BRCMF_EVENTING_MASK_LEN + 12];
  799. brcmf_dbg(TRACE, "\n");
  800. /* Bring up the bus */
  801. ret = brcmf_sdbrcm_bus_init(&drvr_priv->pub);
  802. if (ret != 0) {
  803. brcmf_dbg(ERROR, "brcmf_sdbrcm_bus_init failed %d\n", ret);
  804. return ret;
  805. }
  806. /* If bus is not ready, can't come up */
  807. if (drvr_priv->pub.busstate != BRCMF_BUS_DATA) {
  808. brcmf_dbg(ERROR, "failed bus is not ready\n");
  809. return -ENODEV;
  810. }
  811. brcmf_c_mkiovar("event_msgs", drvr->eventmask, BRCMF_EVENTING_MASK_LEN,
  812. iovbuf, sizeof(iovbuf));
  813. brcmf_proto_cdc_query_dcmd(drvr, 0, BRCMF_C_GET_VAR, iovbuf,
  814. sizeof(iovbuf));
  815. memcpy(drvr->eventmask, iovbuf, BRCMF_EVENTING_MASK_LEN);
  816. setbit(drvr->eventmask, BRCMF_E_SET_SSID);
  817. setbit(drvr->eventmask, BRCMF_E_PRUNE);
  818. setbit(drvr->eventmask, BRCMF_E_AUTH);
  819. setbit(drvr->eventmask, BRCMF_E_REASSOC);
  820. setbit(drvr->eventmask, BRCMF_E_REASSOC_IND);
  821. setbit(drvr->eventmask, BRCMF_E_DEAUTH_IND);
  822. setbit(drvr->eventmask, BRCMF_E_DISASSOC_IND);
  823. setbit(drvr->eventmask, BRCMF_E_DISASSOC);
  824. setbit(drvr->eventmask, BRCMF_E_JOIN);
  825. setbit(drvr->eventmask, BRCMF_E_ASSOC_IND);
  826. setbit(drvr->eventmask, BRCMF_E_PSK_SUP);
  827. setbit(drvr->eventmask, BRCMF_E_LINK);
  828. setbit(drvr->eventmask, BRCMF_E_NDIS_LINK);
  829. setbit(drvr->eventmask, BRCMF_E_MIC_ERROR);
  830. setbit(drvr->eventmask, BRCMF_E_PMKID_CACHE);
  831. setbit(drvr->eventmask, BRCMF_E_TXFAIL);
  832. setbit(drvr->eventmask, BRCMF_E_JOIN_START);
  833. setbit(drvr->eventmask, BRCMF_E_SCAN_COMPLETE);
  834. /* enable dongle roaming event */
  835. drvr->pktfilter_count = 1;
  836. /* Setup filter to allow only unicast */
  837. drvr->pktfilter[0] = "100 0 0 0 0x01 0x00";
  838. /* Bus is ready, do any protocol initialization */
  839. ret = brcmf_proto_init(&drvr_priv->pub);
  840. if (ret < 0)
  841. return ret;
  842. return 0;
  843. }
  844. int brcmf_net_attach(struct brcmf_pub *drvr, int ifidx)
  845. {
  846. struct brcmf_info *drvr_priv = drvr->info;
  847. struct net_device *ndev;
  848. u8 temp_addr[ETH_ALEN] = {
  849. 0x00, 0x90, 0x4c, 0x11, 0x22, 0x33};
  850. brcmf_dbg(TRACE, "ifidx %d\n", ifidx);
  851. ndev = drvr_priv->iflist[ifidx]->ndev;
  852. ndev->netdev_ops = &brcmf_netdev_ops_pri;
  853. /*
  854. * We have to use the primary MAC for virtual interfaces
  855. */
  856. if (ifidx != 0) {
  857. /* for virtual interfaces use the primary MAC */
  858. memcpy(temp_addr, drvr_priv->pub.mac, ETH_ALEN);
  859. }
  860. if (ifidx == 1) {
  861. brcmf_dbg(TRACE, "ACCESS POINT MAC:\n");
  862. /* ACCESSPOINT INTERFACE CASE */
  863. temp_addr[0] |= 0X02; /* set bit 2 ,
  864. - Locally Administered address */
  865. }
  866. ndev->hard_header_len = ETH_HLEN + drvr_priv->pub.hdrlen;
  867. ndev->ethtool_ops = &brcmf_ethtool_ops;
  868. drvr_priv->pub.rxsz = ndev->mtu + ndev->hard_header_len +
  869. drvr_priv->pub.hdrlen;
  870. memcpy(ndev->dev_addr, temp_addr, ETH_ALEN);
  871. /* attach to cfg80211 for primary interface */
  872. if (!ifidx) {
  873. drvr->config =
  874. brcmf_cfg80211_attach(ndev,
  875. brcmf_bus_get_device(drvr->bus),
  876. drvr);
  877. if (drvr->config == NULL) {
  878. brcmf_dbg(ERROR, "wl_cfg80211_attach failed\n");
  879. goto fail;
  880. }
  881. }
  882. if (register_netdev(ndev) != 0) {
  883. brcmf_dbg(ERROR, "couldn't register the net device\n");
  884. goto fail;
  885. }
  886. brcmf_dbg(INFO, "%s: Broadcom Dongle Host Driver\n", ndev->name);
  887. return 0;
  888. fail:
  889. ndev->netdev_ops = NULL;
  890. return -EBADE;
  891. }
  892. static void brcmf_bus_detach(struct brcmf_pub *drvr)
  893. {
  894. struct brcmf_info *drvr_priv;
  895. brcmf_dbg(TRACE, "Enter\n");
  896. if (drvr) {
  897. drvr_priv = drvr->info;
  898. if (drvr_priv) {
  899. /* Stop the protocol module */
  900. brcmf_proto_stop(&drvr_priv->pub);
  901. /* Stop the bus module */
  902. brcmf_sdbrcm_bus_stop(drvr_priv->pub.bus);
  903. }
  904. }
  905. }
  906. void brcmf_detach(struct brcmf_pub *drvr)
  907. {
  908. struct brcmf_info *drvr_priv;
  909. brcmf_dbg(TRACE, "Enter\n");
  910. if (drvr) {
  911. drvr_priv = drvr->info;
  912. if (drvr_priv) {
  913. int i;
  914. /* make sure primary interface removed last */
  915. for (i = BRCMF_MAX_IFS-1; i > -1; i--)
  916. if (drvr_priv->iflist[i])
  917. brcmf_del_if(drvr_priv, i);
  918. cancel_work_sync(&drvr_priv->setmacaddr_work);
  919. cancel_work_sync(&drvr_priv->multicast_work);
  920. brcmf_bus_detach(drvr);
  921. if (drvr->prot)
  922. brcmf_proto_detach(drvr);
  923. kfree(drvr_priv);
  924. }
  925. }
  926. }
  927. int brcmf_os_proto_block(struct brcmf_pub *drvr)
  928. {
  929. struct brcmf_info *drvr_priv = drvr->info;
  930. if (drvr_priv) {
  931. mutex_lock(&drvr_priv->proto_block);
  932. return 1;
  933. }
  934. return 0;
  935. }
  936. int brcmf_os_proto_unblock(struct brcmf_pub *drvr)
  937. {
  938. struct brcmf_info *drvr_priv = drvr->info;
  939. if (drvr_priv) {
  940. mutex_unlock(&drvr_priv->proto_block);
  941. return 1;
  942. }
  943. return 0;
  944. }
  945. static int brcmf_get_pend_8021x_cnt(struct brcmf_info *drvr_priv)
  946. {
  947. return atomic_read(&drvr_priv->pend_8021x_cnt);
  948. }
  949. #define MAX_WAIT_FOR_8021X_TX 10
  950. int brcmf_netdev_wait_pend8021x(struct net_device *ndev)
  951. {
  952. struct brcmf_if *ifp = netdev_priv(ndev);
  953. struct brcmf_info *drvr_priv = ifp->info;
  954. int timeout = 10 * HZ / 1000;
  955. int ntimes = MAX_WAIT_FOR_8021X_TX;
  956. int pend = brcmf_get_pend_8021x_cnt(drvr_priv);
  957. while (ntimes && pend) {
  958. if (pend) {
  959. set_current_state(TASK_INTERRUPTIBLE);
  960. schedule_timeout(timeout);
  961. set_current_state(TASK_RUNNING);
  962. ntimes--;
  963. }
  964. pend = brcmf_get_pend_8021x_cnt(drvr_priv);
  965. }
  966. return pend;
  967. }
  968. #ifdef BCMDBG
  969. int brcmf_write_to_file(struct brcmf_pub *drvr, const u8 *buf, int size)
  970. {
  971. int ret = 0;
  972. struct file *fp;
  973. mm_segment_t old_fs;
  974. loff_t pos = 0;
  975. /* change to KERNEL_DS address limit */
  976. old_fs = get_fs();
  977. set_fs(KERNEL_DS);
  978. /* open file to write */
  979. fp = filp_open("/tmp/mem_dump", O_WRONLY | O_CREAT, 0640);
  980. if (!fp) {
  981. brcmf_dbg(ERROR, "open file error\n");
  982. ret = -1;
  983. goto exit;
  984. }
  985. /* Write buf to file */
  986. fp->f_op->write(fp, (char __user *)buf, size, &pos);
  987. exit:
  988. /* free buf before return */
  989. kfree(buf);
  990. /* close file before return */
  991. if (fp)
  992. filp_close(fp, current->files);
  993. /* restore previous address limit */
  994. set_fs(old_fs);
  995. return ret;
  996. }
  997. #endif /* BCMDBG */