2 * Copyright (c) 2012 Qualcomm Atheros, Inc.
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.
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
11 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
13 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
14 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17 #include <linux/etherdevice.h>
21 static int wil_open(struct net_device *ndev)
23 struct wil6210_priv *wil = ndev_to_wil(ndev);
28 static int wil_stop(struct net_device *ndev)
30 struct wil6210_priv *wil = ndev_to_wil(ndev);
35 static int wil_change_mtu(struct net_device *ndev, int new_mtu)
37 struct wil6210_priv *wil = ndev_to_wil(ndev);
39 if (new_mtu < 68 || new_mtu > IEEE80211_MAX_DATA_LEN_DMG)
42 wil_dbg_misc(wil, "change MTU %d -> %d\n", ndev->mtu, new_mtu);
48 static const struct net_device_ops wil_netdev_ops = {
51 .ndo_start_xmit = wil_start_xmit,
52 .ndo_set_mac_address = eth_mac_addr,
53 .ndo_validate_addr = eth_validate_addr,
54 .ndo_change_mtu = wil_change_mtu,
57 static int wil6210_netdev_poll_rx(struct napi_struct *napi, int budget)
59 struct wil6210_priv *wil = container_of(napi, struct wil6210_priv,
64 wil_rx_handle(wil, "a);
65 done = budget - quota;
67 if (done <= 1) { /* burst ends - only one packet processed */
69 wil6210_unmask_irq_rx(wil);
70 wil_dbg_txrx(wil, "NAPI RX complete\n");
73 wil_dbg_txrx(wil, "NAPI RX poll(%d) done %d\n", budget, done);
78 static int wil6210_netdev_poll_tx(struct napi_struct *napi, int budget)
80 struct wil6210_priv *wil = container_of(napi, struct wil6210_priv,
85 /* always process ALL Tx complete, regardless budget - it is fast */
86 for (i = 0; i < WIL6210_MAX_TX_RINGS; i++) {
87 struct vring *vring = &wil->vring_tx[i];
92 tx_done += wil_tx_complete(wil, i);
95 if (tx_done <= 1) { /* burst ends - only one packet processed */
97 wil6210_unmask_irq_tx(wil);
98 wil_dbg_txrx(wil, "NAPI TX complete\n");
101 wil_dbg_txrx(wil, "NAPI TX poll(%d) done %d\n", budget, tx_done);
103 return min(tx_done, budget);
106 void *wil_if_alloc(struct device *dev, void __iomem *csr)
108 struct net_device *ndev;
109 struct wireless_dev *wdev;
110 struct wil6210_priv *wil;
111 struct ieee80211_channel *ch;
114 wdev = wil_cfg80211_init(dev);
116 dev_err(dev, "wil_cfg80211_init failed\n");
120 wil = wdev_to_wil(wdev);
124 rc = wil_priv_init(wil);
126 dev_err(dev, "wil_priv_init failed\n");
130 wdev->iftype = NL80211_IFTYPE_STATION; /* TODO */
131 /* default monitor channel */
132 ch = wdev->wiphy->bands[IEEE80211_BAND_60GHZ]->channels;
133 cfg80211_chandef_create(&wdev->preset_chandef, ch, NL80211_CHAN_NO_HT);
135 ndev = alloc_netdev(0, "wlan%d", ether_setup);
137 dev_err(dev, "alloc_netdev_mqs failed\n");
142 ndev->netdev_ops = &wil_netdev_ops;
143 ndev->ieee80211_ptr = wdev;
144 ndev->hw_features = NETIF_F_HW_CSUM | NETIF_F_RXCSUM |
145 NETIF_F_SG | NETIF_F_GRO;
146 ndev->features |= ndev->hw_features;
147 SET_NETDEV_DEV(ndev, wiphy_dev(wdev->wiphy));
150 netif_napi_add(ndev, &wil->napi_rx, wil6210_netdev_poll_rx,
151 WIL6210_NAPI_BUDGET);
152 netif_napi_add(ndev, &wil->napi_tx, wil6210_netdev_poll_tx,
153 WIL6210_NAPI_BUDGET);
160 wil_priv_deinit(wil);
168 void wil_if_free(struct wil6210_priv *wil)
170 struct net_device *ndev = wil_to_ndev(wil);
175 wil_priv_deinit(wil);
179 int wil_if_add(struct wil6210_priv *wil)
181 struct net_device *ndev = wil_to_ndev(wil);
184 rc = register_netdev(ndev);
186 dev_err(&ndev->dev, "Failed to register netdev: %d\n", rc);
195 void wil_if_remove(struct wil6210_priv *wil)
197 struct net_device *ndev = wil_to_ndev(wil);
199 unregister_netdev(ndev);