rt2x00: Push beacon TX descriptor writing to drivers.
[linux-2.6/linux-acpi-2.6/ibm-acpi-2.6.git] / drivers / net / wireless / iwmc3200wifi / netdev.c
blob13a69ebf2a94cbe67834f5dd9dec9c752e6deaf2
1 /*
2 * Intel Wireless Multicomm 3200 WiFi driver
4 * Copyright (C) 2009 Intel Corporation <ilw@linux.intel.com>
5 * Samuel Ortiz <samuel.ortiz@intel.com>
6 * Zhu Yi <yi.zhu@intel.com>
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.
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.
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.
25 * This is the netdev related hooks for iwm.
27 * Some interesting code paths:
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()
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()
48 #include <linux/netdevice.h>
49 #include <linux/slab.h>
51 #include "iwm.h"
52 #include "commands.h"
53 #include "cfg80211.h"
54 #include "debug.h"
56 static int iwm_open(struct net_device *ndev)
58 struct iwm_priv *iwm = ndev_to_iwm(ndev);
60 return iwm_up(iwm);
63 static int iwm_stop(struct net_device *ndev)
65 struct iwm_priv *iwm = ndev_to_iwm(ndev);
67 return iwm_down(iwm);
71 * iwm AC to queue mapping
73 * AC_VO -> queue 3
74 * AC_VI -> queue 2
75 * AC_BE -> queue 1
76 * AC_BK -> queue 0
78 static const u16 iwm_1d_to_queue[8] = { 1, 0, 0, 1, 2, 2, 3, 3 };
80 int iwm_tid_to_queue(u16 tid)
82 if (tid > IWM_UMAC_TID_NR - 2)
83 return -EINVAL;
85 return iwm_1d_to_queue[tid];
88 static u16 iwm_select_queue(struct net_device *dev, struct sk_buff *skb)
90 skb->priority = cfg80211_classify8021d(skb);
92 return iwm_1d_to_queue[skb->priority];
95 static const struct net_device_ops iwm_netdev_ops = {
96 .ndo_open = iwm_open,
97 .ndo_stop = iwm_stop,
98 .ndo_start_xmit = iwm_xmit_frame,
99 .ndo_select_queue = iwm_select_queue,
102 void *iwm_if_alloc(int sizeof_bus, struct device *dev,
103 struct iwm_if_ops *if_ops)
105 struct net_device *ndev;
106 struct wireless_dev *wdev;
107 struct iwm_priv *iwm;
108 int ret = 0;
110 wdev = iwm_wdev_alloc(sizeof_bus, dev);
111 if (IS_ERR(wdev))
112 return wdev;
114 iwm = wdev_to_iwm(wdev);
115 iwm->bus_ops = if_ops;
116 iwm->wdev = wdev;
118 ret = iwm_priv_init(iwm);
119 if (ret) {
120 dev_err(dev, "failed to init iwm_priv\n");
121 goto out_wdev;
124 wdev->iftype = iwm_mode_to_nl80211_iftype(iwm->conf.mode);
126 ndev = alloc_netdev_mq(0, "wlan%d", ether_setup, IWM_TX_QUEUES);
127 if (!ndev) {
128 dev_err(dev, "no memory for network device instance\n");
129 goto out_priv;
132 ndev->netdev_ops = &iwm_netdev_ops;
133 ndev->ieee80211_ptr = wdev;
134 SET_NETDEV_DEV(ndev, wiphy_dev(wdev->wiphy));
135 wdev->netdev = ndev;
137 iwm->umac_profile = kmalloc(sizeof(struct iwm_umac_profile),
138 GFP_KERNEL);
139 if (!iwm->umac_profile) {
140 dev_err(dev, "Couldn't alloc memory for profile\n");
141 goto out_profile;
144 iwm_init_default_profile(iwm, iwm->umac_profile);
146 return iwm;
148 out_profile:
149 free_netdev(ndev);
151 out_priv:
152 iwm_priv_deinit(iwm);
154 out_wdev:
155 iwm_wdev_free(iwm);
156 return ERR_PTR(ret);
159 void iwm_if_free(struct iwm_priv *iwm)
161 if (!iwm_to_ndev(iwm))
162 return;
164 cancel_delayed_work_sync(&iwm->ct_kill_delay);
165 free_netdev(iwm_to_ndev(iwm));
166 iwm_priv_deinit(iwm);
167 kfree(iwm->umac_profile);
168 iwm->umac_profile = NULL;
169 iwm_wdev_free(iwm);
172 int iwm_if_add(struct iwm_priv *iwm)
174 struct net_device *ndev = iwm_to_ndev(iwm);
175 int ret;
177 ret = register_netdev(ndev);
178 if (ret < 0) {
179 dev_err(&ndev->dev, "Failed to register netdev: %d\n", ret);
180 return ret;
183 return 0;
186 void iwm_if_remove(struct iwm_priv *iwm)
188 unregister_netdev(iwm_to_ndev(iwm));