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/etherdevice.h>
21 static int wil_open(struct net_device *ndev)
23 struct wil6210_priv *wil = ndev_to_wil(ndev);
25 wil_dbg_misc(wil, "open\n");
28 test_bit(WMI_FW_CAPABILITY_WMI_ONLY, wil->fw_capabilities)) {
29 wil_err(wil, "while in debug_fw or wmi_only mode\n");
36 static int wil_stop(struct net_device *ndev)
38 struct wil6210_priv *wil = ndev_to_wil(ndev);
40 wil_dbg_misc(wil, "stop\n");
45 static int wil_do_ioctl(struct net_device *ndev, struct ifreq *ifr, int cmd)
47 struct wil6210_priv *wil = ndev_to_wil(ndev);
49 return wil_ioctl(wil, ifr->ifr_data, cmd);
52 static const struct net_device_ops wil_netdev_ops = {
55 .ndo_start_xmit = wil_start_xmit,
56 .ndo_set_mac_address = eth_mac_addr,
57 .ndo_validate_addr = eth_validate_addr,
58 .ndo_do_ioctl = wil_do_ioctl,
61 static int wil6210_netdev_poll_rx(struct napi_struct *napi, int budget)
63 struct wil6210_priv *wil = container_of(napi, struct wil6210_priv,
68 wil_rx_handle(wil, "a);
69 done = budget - quota;
72 napi_complete_done(napi, done);
73 wil6210_unmask_irq_rx(wil);
74 wil_dbg_txrx(wil, "NAPI RX complete\n");
77 wil_dbg_txrx(wil, "NAPI RX poll(%d) done %d\n", budget, done);
82 static int wil6210_netdev_poll_tx(struct napi_struct *napi, int budget)
84 struct wil6210_priv *wil = container_of(napi, struct wil6210_priv,
89 /* always process ALL Tx complete, regardless budget - it is fast */
90 for (i = 0; i < WIL6210_MAX_TX_RINGS; i++) {
91 struct vring *vring = &wil->vring_tx[i];
92 struct vring_tx_data *txdata = &wil->vring_tx_data[i];
94 if (!vring->va || !txdata->enabled)
97 tx_done += wil_tx_complete(wil, i);
100 if (tx_done < budget) {
102 wil6210_unmask_irq_tx(wil);
103 wil_dbg_txrx(wil, "NAPI TX complete\n");
106 wil_dbg_txrx(wil, "NAPI TX poll(%d) done %d\n", budget, tx_done);
108 return min(tx_done, budget);
111 static void wil_dev_setup(struct net_device *dev)
114 dev->max_mtu = mtu_max;
115 dev->tx_queue_len = WIL_TX_Q_LEN_DEFAULT;
118 void *wil_if_alloc(struct device *dev)
120 struct net_device *ndev;
121 struct wireless_dev *wdev;
122 struct wil6210_priv *wil;
123 struct ieee80211_channel *ch;
126 wdev = wil_cfg80211_init(dev);
128 dev_err(dev, "wil_cfg80211_init failed\n");
132 wil = wdev_to_wil(wdev);
134 wil->radio_wdev = wdev;
136 wil_dbg_misc(wil, "if_alloc\n");
138 rc = wil_priv_init(wil);
140 dev_err(dev, "wil_priv_init failed\n");
144 wdev->iftype = NL80211_IFTYPE_STATION; /* TODO */
145 /* default monitor channel */
146 ch = wdev->wiphy->bands[NL80211_BAND_60GHZ]->channels;
147 cfg80211_chandef_create(&wdev->preset_chandef, ch, NL80211_CHAN_NO_HT);
149 ndev = alloc_netdev(0, "wlan%d", NET_NAME_UNKNOWN, wil_dev_setup);
151 dev_err(dev, "alloc_netdev_mqs failed\n");
156 ndev->netdev_ops = &wil_netdev_ops;
157 wil_set_ethtoolops(ndev);
158 ndev->ieee80211_ptr = wdev;
159 ndev->hw_features = NETIF_F_HW_CSUM | NETIF_F_RXCSUM |
160 NETIF_F_SG | NETIF_F_GRO |
161 NETIF_F_TSO | NETIF_F_TSO6 |
164 ndev->features |= ndev->hw_features;
165 SET_NETDEV_DEV(ndev, wiphy_dev(wdev->wiphy));
171 wil_priv_deinit(wil);
179 void wil_if_free(struct wil6210_priv *wil)
181 struct net_device *ndev = wil_to_ndev(wil);
183 wil_dbg_misc(wil, "if_free\n");
188 wil_priv_deinit(wil);
190 wil_to_ndev(wil) = NULL;
196 int wil_if_add(struct wil6210_priv *wil)
198 struct wireless_dev *wdev = wil_to_wdev(wil);
199 struct wiphy *wiphy = wdev->wiphy;
200 struct net_device *ndev = wil_to_ndev(wil);
203 wil_dbg_misc(wil, "entered");
205 strlcpy(wiphy->fw_version, wil->fw_version, sizeof(wiphy->fw_version));
207 rc = wiphy_register(wiphy);
209 wil_err(wil, "failed to register wiphy, err %d\n", rc);
213 netif_napi_add(ndev, &wil->napi_rx, wil6210_netdev_poll_rx,
214 WIL6210_NAPI_BUDGET);
215 netif_tx_napi_add(ndev, &wil->napi_tx, wil6210_netdev_poll_tx,
216 WIL6210_NAPI_BUDGET);
218 wil_update_net_queues_bh(wil, NULL, true);
220 rc = register_netdev(ndev);
222 dev_err(&ndev->dev, "Failed to register netdev: %d\n", rc);
229 wiphy_unregister(wdev->wiphy);
233 void wil_if_remove(struct wil6210_priv *wil)
235 struct net_device *ndev = wil_to_ndev(wil);
236 struct wireless_dev *wdev = wil_to_wdev(wil);
238 wil_dbg_misc(wil, "if_remove\n");
240 unregister_netdev(ndev);
241 wiphy_unregister(wdev->wiphy);