17 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
20 #include <linux/kernel.h>
22 #include <linux/slab.h>
24 #include <linux/netdevice.h>
27 #include <linux/random.h>
29 #include <linux/ethtool.h>
30 #include <linux/fcntl.h>
35 #include <linux/wait.h>
36 #include <linux/module.h>
74 if (name ==
NULL || *name ==
'\0')
100 if (drvr->
iflist[ifidx]->ndev)
101 return drvr->
iflist[ifidx]->ndev->name;
122 ndev = drvr->
iflist[0]->ndev;
130 buflen =
sizeof(
"mcast_list") +
sizeof(cnt) + (cnt *
ETH_ALEN);
135 strcpy(bufp,
"mcast_list");
136 bufp +=
strlen(
"mcast_list") + 1;
139 memcpy(bufp, &cnt_le,
sizeof(cnt));
140 bufp +=
sizeof(cnt_le);
160 dcmd_value = cnt ?
true : dcmd_value;
170 buflen =
sizeof(
"allmulti") +
sizeof(dcmd_value);
178 (
"allmulti", (
void *)&dcmd_le_value,
179 sizeof(dcmd_le_value), buf, buflen)) {
180 brcmf_dbg(
ERROR,
"%s: mkiovar failed for allmulti, datalen %d buflen %u\n",
182 (
int)
sizeof(dcmd_value), buflen);
210 dcmd.buf = &dcmd_le_value;
211 dcmd.len =
sizeof(dcmd_le_value);
256 static int brcmf_netdev_set_mac_address(
struct net_device *ndev,
void *
addr)
258 struct brcmf_if *ifp = netdev_priv(ndev);
267 static void brcmf_netdev_set_multicast_list(
struct net_device *ndev)
269 struct brcmf_if *ifp = netdev_priv(ndev);
278 struct brcmf_if *ifp = netdev_priv(ndev);
284 if (!drvr->
bus_if->drvr_up ||
289 netif_stop_queue(ndev);
295 netif_stop_queue(ndev);
300 if (skb_headroom(skb) < drvr->
hdrlen) {
305 drvr->
bus_if->tx_realloc++;
322 if (is_multicast_ether_addr(eh->
h_dest))
332 ret = drvr->
bus_if->brcmf_bus_txdata(drvr->
dev, skb);
336 drvr->
bus_if->dstats.tx_dropped++;
338 drvr->
bus_if->dstats.tx_packets++;
357 netif_stop_queue(ndev);
359 netif_wake_queue(ndev);
363 static int brcmf_host_event(
struct brcmf_pub *drvr,
int *ifidx,
373 if (drvr->
iflist[*ifidx]->ndev)
394 skb_queue_walk_safe(skb_list, skb, pnext) {
412 ifp = drvr->
iflist[ifidx];
416 if (!ifp || !ifp->
ndev ||
417 ifp->
ndev->reg_state != NETREG_REGISTERED) {
426 bus_if->
dstats.multicast++;
436 brcmf_host_event(drvr, &ifidx,
440 if (drvr->
iflist[ifidx]) {
441 ifp = drvr->
iflist[ifidx];
446 bus_if->
dstats.rx_packets++;
481 struct brcmf_if *ifp = netdev_priv(ndev);
502 static int brcmf_toe_get(
struct brcmf_pub *drvr,
int ifidx,
u32 *toe_ol)
538 static int brcmf_toe_set(
struct brcmf_pub *drvr,
int ifidx,
u32 toe_ol)
554 memcpy(&buf[
sizeof(
"toe_ol")], &toe_le,
sizeof(
u32));
567 memcpy(&buf[
sizeof(
"toe")], &toe_le,
sizeof(
u32));
579 static void brcmf_ethtool_get_drvinfo(
struct net_device *ndev,
582 struct brcmf_if *ifp = netdev_priv(ndev);
590 static const struct ethtool_ops brcmf_ethtool_ops = {
591 .get_drvinfo = brcmf_ethtool_get_drvinfo,
594 static int brcmf_ethtool(
struct brcmf_pub *drvr,
void __user *
uaddr)
597 char drvname[
sizeof(info.
driver)];
600 u32 toe_cmpnt, csum_dir;
615 drvname[
sizeof(info.
driver) - 1] =
'\0';
618 memset(&info, 0,
sizeof(info));
622 if (
strcmp(drvname,
"?dhd") == 0) {
628 else if (!drvr->
bus_if->drvr_up) {
643 (
int)
sizeof(drvname), drvname, info.
driver);
649 ret = brcmf_toe_get(drvr, 0, &toe_cmpnt);
657 edata.data = (toe_cmpnt & csum_dir) ? 1 : 0;
670 ret = brcmf_toe_get(drvr, 0, &toe_cmpnt);
678 toe_cmpnt |= csum_dir;
680 toe_cmpnt &= ~csum_dir;
682 ret = brcmf_toe_set(drvr, 0, toe_cmpnt);
689 drvr->
iflist[0]->ndev->features |=
692 drvr->
iflist[0]->ndev->features &=
705 static int brcmf_netdev_ioctl_entry(
struct net_device *ndev,
struct ifreq *ifr,
708 struct brcmf_if *ifp = netdev_priv(ndev);
717 return brcmf_ethtool(drvr, ifr->ifr_data);
729 struct brcmf_if *ifp = netdev_priv(ndev);
732 memset(&dcmd, 0,
sizeof(dcmd));
760 !(
strncmp(
"bsscfg:wsec_key", dcmd.
buf, 15))));
781 static int brcmf_netdev_stop(
struct net_device *ndev)
783 struct brcmf_if *ifp = netdev_priv(ndev);
788 if (drvr->
bus_if->drvr_up == 0)
792 drvr->
bus_if->drvr_up =
false;
793 netif_stop_queue(ndev);
798 static int brcmf_netdev_open(
struct net_device *ndev)
800 struct brcmf_if *ifp = netdev_priv(ndev);
821 if (brcmf_toe_get(drvr, ifp->
idx, &toe_ol) >= 0
823 drvr->
iflist[ifp->
idx]->ndev->features |=
826 drvr->
iflist[ifp->
idx]->ndev->features &=
834 netif_start_queue(ndev);
835 drvr->
bus_if->drvr_up =
true;
845 .ndo_open = brcmf_netdev_open,
846 .ndo_stop = brcmf_netdev_stop,
847 .ndo_get_stats = brcmf_netdev_get_stats,
848 .ndo_do_ioctl = brcmf_netdev_ioctl_entry,
849 .ndo_start_xmit = brcmf_netdev_start_xmit,
850 .ndo_set_mac_address = brcmf_netdev_set_mac_address,
851 .ndo_set_rx_mode = brcmf_netdev_set_multicast_list
854 static int brcmf_net_attach(
struct brcmf_if *ifp)
868 if (is_valid_ether_addr(ifp->
mac_addr))
876 temp_addr[0] |= 0X02;
921 ifp = drvr->
iflist[ifidx];
927 brcmf_dbg(
ERROR,
"ERROR: netdev:%s already exists, try free & unregister\n",
929 netif_stop_queue(ifp->
ndev);
942 ifp = netdev_priv(ndev);
945 drvr->
iflist[ifidx] = ifp;
947 if (mac_addr !=
NULL)
950 if (brcmf_net_attach(ifp)) {
957 brcmf_dbg(
TRACE,
" ==== pid:%x, net_device for if:%s created ===\n",
969 ifp = drvr->
iflist[ifidx];
976 if (ifp->
ndev->netdev_ops == &brcmf_netdev_ops_pri) {
978 brcmf_netdev_stop(ifp->
ndev);
982 netif_stop_queue(ifp->
ndev);
1008 drvr->
hdrlen = bus_hdrlen;
1010 drvr->
bus_if->drvr = drvr;
1026 INIT_LIST_HEAD(&drvr->
bus_if->dcmd_list);
1054 iovbuf,
sizeof(iovbuf));
1082 drvr->
pktfilter[0] =
"100 0 0 0 0x01 0x00";
1099 static void brcmf_bus_detach(
struct brcmf_pub *drvr)
1108 drvr->
bus_if->brcmf_bus_stop(drvr->
dev);
1126 brcmf_bus_detach(drvr);
1139 static int brcmf_get_pend_8021x_cnt(
struct brcmf_pub *drvr)
1144 #define MAX_WAIT_FOR_8021X_TX 10
1148 struct brcmf_if *ifp = netdev_priv(ndev);
1152 int pend = brcmf_get_pend_8021x_cnt(drvr);
1154 while (ntimes && pend) {
1161 pend = brcmf_get_pend_8021x_cnt(drvr);
1167 int brcmf_write_to_file(
struct brcmf_pub *drvr,
const u8 *buf,
int size)
1187 fp->
f_op->write(fp, (
char __user *)buf, size, &pos);
1202 static void brcmf_driver_init(
struct work_struct *work)
1206 #ifdef CONFIG_BRCMFMAC_SDIO
1209 #ifdef CONFIG_BRCMFMAC_USB
1213 static DECLARE_WORK(brcmf_driver_work, brcmf_driver_init);
1215 static int __init brcmfmac_module_init(
void)
1223 static void __exit brcmfmac_module_exit(
void)
1227 #ifdef CONFIG_BRCMFMAC_SDIO
1230 #ifdef CONFIG_BRCMFMAC_USB