blob: d4deb4b471e529f208f64b21904de47c0a5cf549 [file] [log] [blame]
Zhu Yibb9f8692009-05-21 21:20:45 +08001/*
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"
Samuel Ortiz35497162009-06-15 21:59:54 +020051#include "commands.h"
Zhu Yibb9f8692009-05-21 21:20:45 +080052#include "cfg80211.h"
53#include "debug.h"
54
55static int iwm_open(struct net_device *ndev)
56{
57 struct iwm_priv *iwm = ndev_to_iwm(ndev);
58 int ret = 0;
59
60 if (!test_bit(IWM_RADIO_RFKILL_SW, &iwm->radio))
61 ret = iwm_up(iwm);
62
63 return ret;
64}
65
66static int iwm_stop(struct net_device *ndev)
67{
68 struct iwm_priv *iwm = ndev_to_iwm(ndev);
69 int ret = 0;
70
71 if (!test_bit(IWM_RADIO_RFKILL_SW, &iwm->radio))
72 ret = iwm_down(iwm);
73
74 return ret;
75}
76
77/*
78 * iwm AC to queue mapping
79 *
80 * AC_VO -> queue 3
81 * AC_VI -> queue 2
82 * AC_BE -> queue 1
83 * AC_BK -> queue 0
84 */
85static const u16 iwm_1d_to_queue[8] = { 1, 0, 0, 1, 2, 2, 3, 3 };
86
87static u16 iwm_select_queue(struct net_device *dev, struct sk_buff *skb)
88{
89 skb->priority = cfg80211_classify8021d(skb);
90
91 return iwm_1d_to_queue[skb->priority];
92}
93
94static const struct net_device_ops iwm_netdev_ops = {
95 .ndo_open = iwm_open,
96 .ndo_stop = iwm_stop,
97 .ndo_start_xmit = iwm_xmit_frame,
98 .ndo_select_queue = iwm_select_queue,
99};
100
101void *iwm_if_alloc(int sizeof_bus, struct device *dev,
102 struct iwm_if_ops *if_ops)
103{
104 struct net_device *ndev;
105 struct wireless_dev *wdev;
106 struct iwm_priv *iwm;
107 int ret = 0;
108
109 wdev = iwm_wdev_alloc(sizeof_bus, dev);
110 if (!wdev) {
111 dev_err(dev, "no memory for wireless device instance\n");
112 return ERR_PTR(-ENOMEM);
113 }
114
115 iwm = wdev_to_iwm(wdev);
116 iwm->bus_ops = if_ops;
117 iwm->wdev = wdev;
Zhu Yi8d96e792009-06-15 21:36:13 +0200118
119 ret = iwm_priv_init(iwm);
120 if (ret) {
121 dev_err(dev, "failed to init iwm_priv\n");
122 goto out_wdev;
123 }
124
Zhu Yibb9f8692009-05-21 21:20:45 +0800125 wdev->iftype = iwm_mode_to_nl80211_iftype(iwm->conf.mode);
126
Zhu Yid7e057d2009-06-15 21:36:14 +0200127 ndev = alloc_netdev_mq(0, "wlan%d", ether_setup, IWM_TX_QUEUES);
Zhu Yibb9f8692009-05-21 21:20:45 +0800128 if (!ndev) {
129 dev_err(dev, "no memory for network device instance\n");
Zhu Yi8d96e792009-06-15 21:36:13 +0200130 goto out_priv;
Zhu Yibb9f8692009-05-21 21:20:45 +0800131 }
132
133 ndev->netdev_ops = &iwm_netdev_ops;
134 ndev->wireless_handlers = &iwm_iw_handler_def;
135 ndev->ieee80211_ptr = wdev;
136 SET_NETDEV_DEV(ndev, wiphy_dev(wdev->wiphy));
Zhu Yibb9f8692009-05-21 21:20:45 +0800137 wdev->netdev = ndev;
138
Samuel Ortiz35497162009-06-15 21:59:54 +0200139 iwm->umac_profile = kmalloc(sizeof(struct iwm_umac_profile),
140 GFP_KERNEL);
141 if (!iwm->umac_profile) {
142 dev_err(dev, "Couldn't alloc memory for profile\n");
143 goto out_profile;
144 }
145
146 iwm_init_default_profile(iwm, iwm->umac_profile);
147
Zhu Yibb9f8692009-05-21 21:20:45 +0800148 return iwm;
149
Samuel Ortiz35497162009-06-15 21:59:54 +0200150 out_profile:
151 free_netdev(ndev);
152
Zhu Yi8d96e792009-06-15 21:36:13 +0200153 out_priv:
154 iwm_priv_deinit(iwm);
155
Zhu Yibb9f8692009-05-21 21:20:45 +0800156 out_wdev:
157 iwm_wdev_free(iwm);
158 return ERR_PTR(ret);
159}
160
161void iwm_if_free(struct iwm_priv *iwm)
162{
Zhu Yibb9f8692009-05-21 21:20:45 +0800163 if (!iwm_to_ndev(iwm))
164 return;
165
Zhu Yibb9f8692009-05-21 21:20:45 +0800166 free_netdev(iwm_to_ndev(iwm));
167 iwm_wdev_free(iwm);
Zhu Yi8d96e792009-06-15 21:36:13 +0200168 iwm_priv_deinit(iwm);
Samuel Ortiz35497162009-06-15 21:59:54 +0200169 kfree(iwm->umac_profile);
170 iwm->umac_profile = NULL;
Zhu Yibb9f8692009-05-21 21:20:45 +0800171}
Zhu Yid7e057d2009-06-15 21:36:14 +0200172
173int iwm_if_add(struct iwm_priv *iwm)
174{
175 struct net_device *ndev = iwm_to_ndev(iwm);
176 int ret;
177
178 ret = register_netdev(ndev);
179 if (ret < 0) {
180 dev_err(&ndev->dev, "Failed to register netdev: %d\n", ret);
181 return ret;
182 }
183
184 return 0;
185}
186
187void iwm_if_remove(struct iwm_priv *iwm)
188{
189 unregister_netdev(iwm_to_ndev(iwm));
190}