2 * Copyright (c) 2012-2017 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/moduleparam.h>
18 #include <linux/etherdevice.h>
22 static bool alt_ifname; /* = false; */
23 module_param(alt_ifname, bool, S_IRUGO);
24 MODULE_PARM_DESC(alt_ifname, " use an alternate interface name wigigN instead of wlanN");
26 static int wil_open(struct net_device *ndev)
28 struct wil6210_priv *wil = ndev_to_wil(ndev);
30 wil_dbg_misc(wil, "open\n");
33 test_bit(WMI_FW_CAPABILITY_WMI_ONLY, wil->fw_capabilities)) {
34 wil_err(wil, "while in debug_fw or wmi_only mode\n");
41 static int wil_stop(struct net_device *ndev)
43 struct wil6210_priv *wil = ndev_to_wil(ndev);
45 wil_dbg_misc(wil, "stop\n");
50 static int wil_change_mtu(struct net_device *ndev, int new_mtu)
52 struct wil6210_priv *wil = ndev_to_wil(ndev);
54 if (new_mtu < 68 || new_mtu > mtu_max) {
55 wil_err(wil, "invalid MTU %d\n", new_mtu);
59 wil_dbg_misc(wil, "change MTU %d -> %d\n", ndev->mtu, new_mtu);
65 static int wil_do_ioctl(struct net_device *ndev, struct ifreq *ifr, int cmd)
67 struct wil6210_priv *wil = ndev_to_wil(ndev);
69 return wil_ioctl(wil, ifr->ifr_data, cmd);
72 static const struct net_device_ops wil_netdev_ops = {
75 .ndo_start_xmit = wil_start_xmit,
76 .ndo_set_mac_address = eth_mac_addr,
77 .ndo_validate_addr = eth_validate_addr,
78 .ndo_change_mtu = wil_change_mtu,
79 .ndo_do_ioctl = wil_do_ioctl,
82 static int wil6210_netdev_poll_rx(struct napi_struct *napi, int budget)
84 struct wil6210_priv *wil = container_of(napi, struct wil6210_priv,
89 wil_rx_handle(wil, "a);
90 done = budget - quota;
93 napi_complete_done(napi, done);
94 wil6210_unmask_irq_rx(wil);
95 wil_dbg_txrx(wil, "NAPI RX complete\n");
98 wil_dbg_txrx(wil, "NAPI RX poll(%d) done %d\n", budget, done);
103 static int wil6210_netdev_poll_tx(struct napi_struct *napi, int budget)
105 struct wil6210_priv *wil = container_of(napi, struct wil6210_priv,
110 /* always process ALL Tx complete, regardless budget - it is fast */
111 for (i = 0; i < WIL6210_MAX_TX_RINGS; i++) {
112 struct vring *vring = &wil->vring_tx[i];
113 struct vring_tx_data *txdata = &wil->vring_tx_data[i];
115 if (!vring->va || !txdata->enabled)
118 tx_done += wil_tx_complete(wil, i);
121 if (tx_done < budget) {
123 wil6210_unmask_irq_tx(wil);
124 wil_dbg_txrx(wil, "NAPI TX complete\n");
127 wil_dbg_txrx(wil, "NAPI TX poll(%d) done %d\n", budget, tx_done);
129 return min(tx_done, budget);
132 static void wil_dev_setup(struct net_device *dev)
135 dev->tx_queue_len = WIL_TX_Q_LEN_DEFAULT;
138 void *wil_if_alloc(struct device *dev)
140 struct net_device *ndev;
141 struct wireless_dev *wdev;
142 struct wil6210_priv *wil;
143 struct ieee80211_channel *ch;
145 const char *ifname = alt_ifname ? "wigig%d" : "wlan%d";
147 wdev = wil_cfg80211_init(dev);
149 dev_err(dev, "wil_cfg80211_init failed\n");
153 wil = wdev_to_wil(wdev);
155 wil->radio_wdev = wdev;
157 wil_dbg_misc(wil, "if_alloc\n");
159 rc = wil_priv_init(wil);
161 dev_err(dev, "wil_priv_init failed\n");
165 wdev->iftype = NL80211_IFTYPE_STATION; /* TODO */
166 /* default monitor channel */
167 ch = wdev->wiphy->bands[NL80211_BAND_60GHZ]->channels;
168 cfg80211_chandef_create(&wdev->preset_chandef, ch, NL80211_CHAN_NO_HT);
170 ndev = alloc_netdev(0, ifname, NET_NAME_UNKNOWN, wil_dev_setup);
172 dev_err(dev, "alloc_netdev_mqs failed\n");
177 ndev->netdev_ops = &wil_netdev_ops;
178 wil_set_ethtoolops(ndev);
179 ndev->ieee80211_ptr = wdev;
180 ndev->hw_features = NETIF_F_HW_CSUM | NETIF_F_RXCSUM |
181 NETIF_F_SG | NETIF_F_GRO |
182 NETIF_F_TSO | NETIF_F_TSO6 |
185 ndev->features |= ndev->hw_features;
186 SET_NETDEV_DEV(ndev, wiphy_dev(wdev->wiphy));
192 wil_priv_deinit(wil);
200 void wil_if_free(struct wil6210_priv *wil)
202 struct net_device *ndev = wil_to_ndev(wil);
204 wil_dbg_misc(wil, "if_free\n");
209 wil_priv_deinit(wil);
211 wil_to_ndev(wil) = NULL;
217 int wil_if_add(struct wil6210_priv *wil)
219 struct wireless_dev *wdev = wil_to_wdev(wil);
220 struct wiphy *wiphy = wdev->wiphy;
221 struct net_device *ndev = wil_to_ndev(wil);
224 wil_dbg_misc(wil, "entered");
226 strlcpy(wiphy->fw_version, wil->fw_version, sizeof(wiphy->fw_version));
228 rc = wiphy_register(wiphy);
230 wil_err(wil, "failed to register wiphy, err %d\n", rc);
234 netif_napi_add(ndev, &wil->napi_rx, wil6210_netdev_poll_rx,
235 WIL6210_NAPI_BUDGET);
236 netif_napi_add(ndev, &wil->napi_tx, wil6210_netdev_poll_tx,
237 WIL6210_NAPI_BUDGET);
239 wil_update_net_queues_bh(wil, NULL, true);
241 rc = register_netdev(ndev);
243 dev_err(&ndev->dev, "Failed to register netdev: %d\n", rc);
250 wiphy_unregister(wdev->wiphy);
254 void wil_if_remove(struct wil6210_priv *wil)
256 struct net_device *ndev = wil_to_ndev(wil);
257 struct wireless_dev *wdev = wil_to_wdev(wil);
259 wil_dbg_misc(wil, "if_remove\n");
261 unregister_netdev(ndev);
262 wiphy_unregister(wdev->wiphy);