diff options
Diffstat (limited to 'drivers/net/wireless/iwmc3200wifi/netdev.c')
-rw-r--r-- | drivers/net/wireless/iwmc3200wifi/netdev.c | 172 |
1 files changed, 172 insertions, 0 deletions
diff --git a/drivers/net/wireless/iwmc3200wifi/netdev.c b/drivers/net/wireless/iwmc3200wifi/netdev.c new file mode 100644 index 000000000000..eec7201e91a8 --- /dev/null +++ b/drivers/net/wireless/iwmc3200wifi/netdev.c | |||
@@ -0,0 +1,172 @@ | |||
1 | /* | ||
2 | * Intel Wireless Multicomm 3200 WiFi driver | ||
3 | * | ||
4 | * Copyright (C) 2009 Intel Corporation <ilw@linux.intel.com> | ||
5 | * Samuel Ortiz <samuel.ortiz@intel.com> | ||
6 | * Zhu Yi <yi.zhu@intel.com> | ||
7 | * | ||
8 | * This program is free software; you can redistribute it and/or | ||
9 | * modify it under the terms of the GNU General Public License version | ||
10 | * 2 as published by the Free Software Foundation. | ||
11 | * | ||
12 | * This program is distributed in the hope that it will be useful, | ||
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
15 | * GNU General Public License for more details. | ||
16 | * | ||
17 | * You should have received a copy of the GNU General Public License | ||
18 | * along with this program; if not, write to the Free Software | ||
19 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA | ||
20 | * 02110-1301, USA. | ||
21 | * | ||
22 | */ | ||
23 | |||
24 | /* | ||
25 | * This is the netdev related hooks for iwm. | ||
26 | * | ||
27 | * Some interesting code paths: | ||
28 | * | ||
29 | * iwm_open() (Called at netdev interface bringup time) | ||
30 | * -> iwm_up() (main.c) | ||
31 | * -> iwm_bus_enable() | ||
32 | * -> if_sdio_enable() (In case of an SDIO bus) | ||
33 | * -> sdio_enable_func() | ||
34 | * -> iwm_notif_wait(BARKER_REBOOT) (wait for reboot barker) | ||
35 | * -> iwm_notif_wait(ACK_BARKER) (wait for ACK barker) | ||
36 | * -> iwm_load_fw() (fw.c) | ||
37 | * -> iwm_load_umac() | ||
38 | * -> iwm_load_lmac() (Calibration LMAC) | ||
39 | * -> iwm_load_lmac() (Operational LMAC) | ||
40 | * -> iwm_send_umac_config() | ||
41 | * | ||
42 | * iwm_stop() (Called at netdev interface bringdown time) | ||
43 | * -> iwm_down() | ||
44 | * -> iwm_bus_disable() | ||
45 | * -> if_sdio_disable() (In case of an SDIO bus) | ||
46 | * -> sdio_disable_func() | ||
47 | */ | ||
48 | #include <linux/netdevice.h> | ||
49 | |||
50 | #include "iwm.h" | ||
51 | #include "cfg80211.h" | ||
52 | #include "debug.h" | ||
53 | |||
54 | static int iwm_open(struct net_device *ndev) | ||
55 | { | ||
56 | struct iwm_priv *iwm = ndev_to_iwm(ndev); | ||
57 | int ret = 0; | ||
58 | |||
59 | if (!test_bit(IWM_RADIO_RFKILL_SW, &iwm->radio)) | ||
60 | ret = iwm_up(iwm); | ||
61 | |||
62 | return ret; | ||
63 | } | ||
64 | |||
65 | static int iwm_stop(struct net_device *ndev) | ||
66 | { | ||
67 | struct iwm_priv *iwm = ndev_to_iwm(ndev); | ||
68 | int ret = 0; | ||
69 | |||
70 | if (!test_bit(IWM_RADIO_RFKILL_SW, &iwm->radio)) | ||
71 | ret = iwm_down(iwm); | ||
72 | |||
73 | return ret; | ||
74 | } | ||
75 | |||
76 | /* | ||
77 | * iwm AC to queue mapping | ||
78 | * | ||
79 | * AC_VO -> queue 3 | ||
80 | * AC_VI -> queue 2 | ||
81 | * AC_BE -> queue 1 | ||
82 | * AC_BK -> queue 0 | ||
83 | */ | ||
84 | static const u16 iwm_1d_to_queue[8] = { 1, 0, 0, 1, 2, 2, 3, 3 }; | ||
85 | |||
86 | static u16 iwm_select_queue(struct net_device *dev, struct sk_buff *skb) | ||
87 | { | ||
88 | skb->priority = cfg80211_classify8021d(skb); | ||
89 | |||
90 | return iwm_1d_to_queue[skb->priority]; | ||
91 | } | ||
92 | |||
93 | static const struct net_device_ops iwm_netdev_ops = { | ||
94 | .ndo_open = iwm_open, | ||
95 | .ndo_stop = iwm_stop, | ||
96 | .ndo_start_xmit = iwm_xmit_frame, | ||
97 | .ndo_select_queue = iwm_select_queue, | ||
98 | }; | ||
99 | |||
100 | void *iwm_if_alloc(int sizeof_bus, struct device *dev, | ||
101 | struct iwm_if_ops *if_ops) | ||
102 | { | ||
103 | struct net_device *ndev; | ||
104 | struct wireless_dev *wdev; | ||
105 | struct iwm_priv *iwm; | ||
106 | int ret = 0; | ||
107 | |||
108 | wdev = iwm_wdev_alloc(sizeof_bus, dev); | ||
109 | if (!wdev) { | ||
110 | dev_err(dev, "no memory for wireless device instance\n"); | ||
111 | return ERR_PTR(-ENOMEM); | ||
112 | } | ||
113 | |||
114 | iwm = wdev_to_iwm(wdev); | ||
115 | iwm->bus_ops = if_ops; | ||
116 | iwm->wdev = wdev; | ||
117 | iwm_priv_init(iwm); | ||
118 | wdev->iftype = iwm_mode_to_nl80211_iftype(iwm->conf.mode); | ||
119 | |||
120 | ndev = alloc_netdev_mq(0, "wlan%d", ether_setup, | ||
121 | IWM_TX_QUEUES); | ||
122 | if (!ndev) { | ||
123 | dev_err(dev, "no memory for network device instance\n"); | ||
124 | goto out_wdev; | ||
125 | } | ||
126 | |||
127 | ndev->netdev_ops = &iwm_netdev_ops; | ||
128 | ndev->wireless_handlers = &iwm_iw_handler_def; | ||
129 | ndev->ieee80211_ptr = wdev; | ||
130 | SET_NETDEV_DEV(ndev, wiphy_dev(wdev->wiphy)); | ||
131 | ret = register_netdev(ndev); | ||
132 | if (ret < 0) { | ||
133 | dev_err(dev, "Failed to register netdev: %d\n", ret); | ||
134 | goto out_ndev; | ||
135 | } | ||
136 | |||
137 | wdev->netdev = ndev; | ||
138 | |||
139 | ret = iwm_rfkill_init(iwm); | ||
140 | if (ret) { | ||
141 | dev_err(dev, "Failed to init rfkill\n"); | ||
142 | goto out_rfkill; | ||
143 | } | ||
144 | |||
145 | return iwm; | ||
146 | |||
147 | out_rfkill: | ||
148 | unregister_netdev(ndev); | ||
149 | |||
150 | out_ndev: | ||
151 | free_netdev(ndev); | ||
152 | |||
153 | out_wdev: | ||
154 | iwm_wdev_free(iwm); | ||
155 | return ERR_PTR(ret); | ||
156 | } | ||
157 | |||
158 | void iwm_if_free(struct iwm_priv *iwm) | ||
159 | { | ||
160 | int i; | ||
161 | |||
162 | if (!iwm_to_ndev(iwm)) | ||
163 | return; | ||
164 | |||
165 | iwm_rfkill_exit(iwm); | ||
166 | unregister_netdev(iwm_to_ndev(iwm)); | ||
167 | free_netdev(iwm_to_ndev(iwm)); | ||
168 | iwm_wdev_free(iwm); | ||
169 | destroy_workqueue(iwm->rx_wq); | ||
170 | for (i = 0; i < IWM_TX_QUEUES; i++) | ||
171 | destroy_workqueue(iwm->txq[i].wq); | ||
172 | } | ||