2 * This file contains the major functions in WLAN
3 * driver. It includes init, exit, open, close and main
7 #include <linux/moduleparam.h>
8 #include <linux/delay.h>
9 #include <linux/etherdevice.h>
10 #include <linux/netdevice.h>
11 #include <linux/if_arp.h>
12 #include <linux/kthread.h>
13 #include <linux/kfifo.h>
14 #include <linux/stddef.h>
15 #include <linux/ieee80211.h>
16 #include <net/iw_handler.h>
17 #include <net/cfg80211.h>
29 #define DRIVER_RELEASE_VERSION "323.p0"
30 const char lbs_driver_version
[] = "COMM-USB8388-" DRIVER_RELEASE_VERSION
37 /* Module parameters */
38 unsigned int lbs_debug
;
39 EXPORT_SYMBOL_GPL(lbs_debug
);
40 module_param_named(libertas_debug
, lbs_debug
, int, 0644);
43 /* This global structure is used to send the confirm_sleep command as
44 * fast as possible down to the firmware. */
45 struct cmd_confirm_sleep confirm_sleep
;
48 #define LBS_TX_PWR_DEFAULT 20 /*100mW */
49 #define LBS_TX_PWR_US_DEFAULT 20 /*100mW */
50 #define LBS_TX_PWR_JP_DEFAULT 16 /*50mW */
51 #define LBS_TX_PWR_FR_DEFAULT 20 /*100mW */
52 #define LBS_TX_PWR_EMEA_DEFAULT 20 /*100mW */
54 /* Format { channel, frequency (MHz), maxtxpower } */
55 /* band: 'B/G', region: USA FCC/Canada IC */
56 static struct chan_freq_power channel_freq_power_US_BG
[] = {
57 {1, 2412, LBS_TX_PWR_US_DEFAULT
},
58 {2, 2417, LBS_TX_PWR_US_DEFAULT
},
59 {3, 2422, LBS_TX_PWR_US_DEFAULT
},
60 {4, 2427, LBS_TX_PWR_US_DEFAULT
},
61 {5, 2432, LBS_TX_PWR_US_DEFAULT
},
62 {6, 2437, LBS_TX_PWR_US_DEFAULT
},
63 {7, 2442, LBS_TX_PWR_US_DEFAULT
},
64 {8, 2447, LBS_TX_PWR_US_DEFAULT
},
65 {9, 2452, LBS_TX_PWR_US_DEFAULT
},
66 {10, 2457, LBS_TX_PWR_US_DEFAULT
},
67 {11, 2462, LBS_TX_PWR_US_DEFAULT
}
70 /* band: 'B/G', region: Europe ETSI */
71 static struct chan_freq_power channel_freq_power_EU_BG
[] = {
72 {1, 2412, LBS_TX_PWR_EMEA_DEFAULT
},
73 {2, 2417, LBS_TX_PWR_EMEA_DEFAULT
},
74 {3, 2422, LBS_TX_PWR_EMEA_DEFAULT
},
75 {4, 2427, LBS_TX_PWR_EMEA_DEFAULT
},
76 {5, 2432, LBS_TX_PWR_EMEA_DEFAULT
},
77 {6, 2437, LBS_TX_PWR_EMEA_DEFAULT
},
78 {7, 2442, LBS_TX_PWR_EMEA_DEFAULT
},
79 {8, 2447, LBS_TX_PWR_EMEA_DEFAULT
},
80 {9, 2452, LBS_TX_PWR_EMEA_DEFAULT
},
81 {10, 2457, LBS_TX_PWR_EMEA_DEFAULT
},
82 {11, 2462, LBS_TX_PWR_EMEA_DEFAULT
},
83 {12, 2467, LBS_TX_PWR_EMEA_DEFAULT
},
84 {13, 2472, LBS_TX_PWR_EMEA_DEFAULT
}
87 /* band: 'B/G', region: Spain */
88 static struct chan_freq_power channel_freq_power_SPN_BG
[] = {
89 {10, 2457, LBS_TX_PWR_DEFAULT
},
90 {11, 2462, LBS_TX_PWR_DEFAULT
}
93 /* band: 'B/G', region: France */
94 static struct chan_freq_power channel_freq_power_FR_BG
[] = {
95 {10, 2457, LBS_TX_PWR_FR_DEFAULT
},
96 {11, 2462, LBS_TX_PWR_FR_DEFAULT
},
97 {12, 2467, LBS_TX_PWR_FR_DEFAULT
},
98 {13, 2472, LBS_TX_PWR_FR_DEFAULT
}
101 /* band: 'B/G', region: Japan */
102 static struct chan_freq_power channel_freq_power_JPN_BG
[] = {
103 {1, 2412, LBS_TX_PWR_JP_DEFAULT
},
104 {2, 2417, LBS_TX_PWR_JP_DEFAULT
},
105 {3, 2422, LBS_TX_PWR_JP_DEFAULT
},
106 {4, 2427, LBS_TX_PWR_JP_DEFAULT
},
107 {5, 2432, LBS_TX_PWR_JP_DEFAULT
},
108 {6, 2437, LBS_TX_PWR_JP_DEFAULT
},
109 {7, 2442, LBS_TX_PWR_JP_DEFAULT
},
110 {8, 2447, LBS_TX_PWR_JP_DEFAULT
},
111 {9, 2452, LBS_TX_PWR_JP_DEFAULT
},
112 {10, 2457, LBS_TX_PWR_JP_DEFAULT
},
113 {11, 2462, LBS_TX_PWR_JP_DEFAULT
},
114 {12, 2467, LBS_TX_PWR_JP_DEFAULT
},
115 {13, 2472, LBS_TX_PWR_JP_DEFAULT
},
116 {14, 2484, LBS_TX_PWR_JP_DEFAULT
}
120 * the structure for channel, frequency and power
122 struct region_cfp_table
{
124 struct chan_freq_power
*cfp_BG
;
129 * the structure for the mapping between region and CFP
131 static struct region_cfp_table region_cfp_table
[] = {
133 channel_freq_power_US_BG
,
134 ARRAY_SIZE(channel_freq_power_US_BG
),
137 {0x20, /*CANADA IC */
138 channel_freq_power_US_BG
,
139 ARRAY_SIZE(channel_freq_power_US_BG
),
142 {0x30, /*EU*/ channel_freq_power_EU_BG
,
143 ARRAY_SIZE(channel_freq_power_EU_BG
),
146 {0x31, /*SPAIN*/ channel_freq_power_SPN_BG
,
147 ARRAY_SIZE(channel_freq_power_SPN_BG
),
150 {0x32, /*FRANCE*/ channel_freq_power_FR_BG
,
151 ARRAY_SIZE(channel_freq_power_FR_BG
),
154 {0x40, /*JAPAN*/ channel_freq_power_JPN_BG
,
155 ARRAY_SIZE(channel_freq_power_JPN_BG
),
158 /*Add new region here */
162 * the table to keep region code
164 u16 lbs_region_code_to_index
[MRVDRV_MAX_REGION_CODE
] =
165 { 0x10, 0x20, 0x30, 0x31, 0x32, 0x40 };
168 * 802.11b/g supported bitrates (in 500Kb/s units)
170 u8 lbs_bg_rates
[MAX_RATES
] =
171 { 0x02, 0x04, 0x0b, 0x16, 0x0c, 0x12, 0x18, 0x24, 0x30, 0x48, 0x60, 0x6c,
175 * FW rate table. FW refers to rates by their index in this table, not by the
176 * rate value itself. Values of 0x00 are
177 * reserved positions.
179 static u8 fw_data_rates
[MAX_RATES
] =
180 { 0x02, 0x04, 0x0B, 0x16, 0x00, 0x0C, 0x12,
181 0x18, 0x24, 0x30, 0x48, 0x60, 0x6C, 0x00
185 * @brief use index to get the data rate
187 * @param idx The index of data rate
188 * @return data rate or 0
190 u32
lbs_fw_index_to_data_rate(u8 idx
)
192 if (idx
>= sizeof(fw_data_rates
))
194 return fw_data_rates
[idx
];
198 * @brief use rate to get the index
200 * @param rate data rate
203 u8
lbs_data_rate_to_fw_index(u32 rate
)
210 for (i
= 0; i
< sizeof(fw_data_rates
); i
++) {
211 if (rate
== fw_data_rates
[i
])
218 * Attributes exported through sysfs
222 * @brief Get function for sysfs attribute anycast_mask
224 static ssize_t
lbs_anycast_get(struct device
*dev
,
225 struct device_attribute
*attr
, char * buf
)
227 struct lbs_private
*priv
= to_net_dev(dev
)->ml_priv
;
228 struct cmd_ds_mesh_access mesh_access
;
231 memset(&mesh_access
, 0, sizeof(mesh_access
));
233 ret
= lbs_mesh_access(priv
, CMD_ACT_MESH_GET_ANYCAST
, &mesh_access
);
237 return snprintf(buf
, 12, "0x%X\n", le32_to_cpu(mesh_access
.data
[0]));
241 * @brief Set function for sysfs attribute anycast_mask
243 static ssize_t
lbs_anycast_set(struct device
*dev
,
244 struct device_attribute
*attr
, const char * buf
, size_t count
)
246 struct lbs_private
*priv
= to_net_dev(dev
)->ml_priv
;
247 struct cmd_ds_mesh_access mesh_access
;
251 memset(&mesh_access
, 0, sizeof(mesh_access
));
252 sscanf(buf
, "%x", &datum
);
253 mesh_access
.data
[0] = cpu_to_le32(datum
);
255 ret
= lbs_mesh_access(priv
, CMD_ACT_MESH_SET_ANYCAST
, &mesh_access
);
263 * @brief Get function for sysfs attribute prb_rsp_limit
265 static ssize_t
lbs_prb_rsp_limit_get(struct device
*dev
,
266 struct device_attribute
*attr
, char *buf
)
268 struct lbs_private
*priv
= to_net_dev(dev
)->ml_priv
;
269 struct cmd_ds_mesh_access mesh_access
;
273 memset(&mesh_access
, 0, sizeof(mesh_access
));
274 mesh_access
.data
[0] = cpu_to_le32(CMD_ACT_GET
);
276 ret
= lbs_mesh_access(priv
, CMD_ACT_MESH_SET_GET_PRB_RSP_LIMIT
,
281 retry_limit
= le32_to_cpu(mesh_access
.data
[1]);
282 return snprintf(buf
, 10, "%d\n", retry_limit
);
286 * @brief Set function for sysfs attribute prb_rsp_limit
288 static ssize_t
lbs_prb_rsp_limit_set(struct device
*dev
,
289 struct device_attribute
*attr
, const char *buf
, size_t count
)
291 struct lbs_private
*priv
= to_net_dev(dev
)->ml_priv
;
292 struct cmd_ds_mesh_access mesh_access
;
294 unsigned long retry_limit
;
296 memset(&mesh_access
, 0, sizeof(mesh_access
));
297 mesh_access
.data
[0] = cpu_to_le32(CMD_ACT_SET
);
299 if (!strict_strtoul(buf
, 10, &retry_limit
))
301 if (retry_limit
> 15)
304 mesh_access
.data
[1] = cpu_to_le32(retry_limit
);
306 ret
= lbs_mesh_access(priv
, CMD_ACT_MESH_SET_GET_PRB_RSP_LIMIT
,
314 static int lbs_add_rtap(struct lbs_private
*priv
);
315 static void lbs_remove_rtap(struct lbs_private
*priv
);
316 static int lbs_add_mesh(struct lbs_private
*priv
);
317 static void lbs_remove_mesh(struct lbs_private
*priv
);
321 * Get function for sysfs attribute rtap
323 static ssize_t
lbs_rtap_get(struct device
*dev
,
324 struct device_attribute
*attr
, char * buf
)
326 struct lbs_private
*priv
= to_net_dev(dev
)->ml_priv
;
327 return snprintf(buf
, 5, "0x%X\n", priv
->monitormode
);
331 * Set function for sysfs attribute rtap
333 static ssize_t
lbs_rtap_set(struct device
*dev
,
334 struct device_attribute
*attr
, const char * buf
, size_t count
)
337 struct lbs_private
*priv
= to_net_dev(dev
)->ml_priv
;
339 sscanf(buf
, "%x", &monitor_mode
);
341 if (priv
->monitormode
== monitor_mode
)
343 if (!priv
->monitormode
) {
344 if (priv
->infra_open
|| priv
->mesh_open
)
346 if (priv
->mode
== IW_MODE_INFRA
)
347 lbs_cmd_80211_deauthenticate(priv
,
348 priv
->curbssparams
.bssid
,
349 WLAN_REASON_DEAUTH_LEAVING
);
350 else if (priv
->mode
== IW_MODE_ADHOC
)
351 lbs_adhoc_stop(priv
);
354 priv
->monitormode
= monitor_mode
;
356 if (!priv
->monitormode
)
358 priv
->monitormode
= 0;
359 lbs_remove_rtap(priv
);
361 if (priv
->currenttxskb
) {
362 dev_kfree_skb_any(priv
->currenttxskb
);
363 priv
->currenttxskb
= NULL
;
366 /* Wake queues, command thread, etc. */
367 lbs_host_to_card_done(priv
);
370 lbs_prepare_and_send_command(priv
,
371 CMD_802_11_MONITOR_MODE
, CMD_ACT_SET
,
372 CMD_OPTION_WAITFORRSP
, 0, &priv
->monitormode
);
377 * lbs_rtap attribute to be exported per ethX interface
378 * through sysfs (/sys/class/net/ethX/lbs_rtap)
380 static DEVICE_ATTR(lbs_rtap
, 0644, lbs_rtap_get
, lbs_rtap_set
);
383 * Get function for sysfs attribute mesh
385 static ssize_t
lbs_mesh_get(struct device
*dev
,
386 struct device_attribute
*attr
, char * buf
)
388 struct lbs_private
*priv
= to_net_dev(dev
)->ml_priv
;
389 return snprintf(buf
, 5, "0x%X\n", !!priv
->mesh_dev
);
393 * Set function for sysfs attribute mesh
395 static ssize_t
lbs_mesh_set(struct device
*dev
,
396 struct device_attribute
*attr
, const char * buf
, size_t count
)
398 struct lbs_private
*priv
= to_net_dev(dev
)->ml_priv
;
400 int ret
, action
= CMD_ACT_MESH_CONFIG_STOP
;
402 sscanf(buf
, "%x", &enable
);
404 if (enable
== !!priv
->mesh_dev
)
407 action
= CMD_ACT_MESH_CONFIG_START
;
408 ret
= lbs_mesh_config(priv
, action
, priv
->curbssparams
.channel
);
415 lbs_remove_mesh(priv
);
421 * lbs_mesh attribute to be exported per ethX interface
422 * through sysfs (/sys/class/net/ethX/lbs_mesh)
424 static DEVICE_ATTR(lbs_mesh
, 0644, lbs_mesh_get
, lbs_mesh_set
);
427 * anycast_mask attribute to be exported per mshX interface
428 * through sysfs (/sys/class/net/mshX/anycast_mask)
430 static DEVICE_ATTR(anycast_mask
, 0644, lbs_anycast_get
, lbs_anycast_set
);
433 * prb_rsp_limit attribute to be exported per mshX interface
434 * through sysfs (/sys/class/net/mshX/prb_rsp_limit)
436 static DEVICE_ATTR(prb_rsp_limit
, 0644, lbs_prb_rsp_limit_get
,
437 lbs_prb_rsp_limit_set
);
439 static struct attribute
*lbs_mesh_sysfs_entries
[] = {
440 &dev_attr_anycast_mask
.attr
,
441 &dev_attr_prb_rsp_limit
.attr
,
445 static struct attribute_group lbs_mesh_attr_group
= {
446 .attrs
= lbs_mesh_sysfs_entries
,
450 * @brief This function opens the ethX or mshX interface
452 * @param dev A pointer to net_device structure
453 * @return 0 or -EBUSY if monitor mode active
455 static int lbs_dev_open(struct net_device
*dev
)
457 struct lbs_private
*priv
= dev
->ml_priv
;
460 lbs_deb_enter(LBS_DEB_NET
);
462 spin_lock_irq(&priv
->driver_lock
);
464 if (priv
->monitormode
) {
469 if (dev
== priv
->mesh_dev
) {
471 priv
->mesh_connect_status
= LBS_CONNECTED
;
472 netif_carrier_on(dev
);
474 priv
->infra_open
= 1;
476 if (priv
->connect_status
== LBS_CONNECTED
)
477 netif_carrier_on(dev
);
479 netif_carrier_off(dev
);
482 if (!priv
->tx_pending_len
)
483 netif_wake_queue(dev
);
486 spin_unlock_irq(&priv
->driver_lock
);
487 lbs_deb_leave_args(LBS_DEB_NET
, "ret %d", ret
);
492 * @brief This function closes the mshX interface
494 * @param dev A pointer to net_device structure
497 static int lbs_mesh_stop(struct net_device
*dev
)
499 struct lbs_private
*priv
= dev
->ml_priv
;
501 lbs_deb_enter(LBS_DEB_MESH
);
502 spin_lock_irq(&priv
->driver_lock
);
505 priv
->mesh_connect_status
= LBS_DISCONNECTED
;
507 netif_stop_queue(dev
);
508 netif_carrier_off(dev
);
510 spin_unlock_irq(&priv
->driver_lock
);
512 schedule_work(&priv
->mcast_work
);
514 lbs_deb_leave(LBS_DEB_MESH
);
519 * @brief This function closes the ethX interface
521 * @param dev A pointer to net_device structure
524 static int lbs_eth_stop(struct net_device
*dev
)
526 struct lbs_private
*priv
= dev
->ml_priv
;
528 lbs_deb_enter(LBS_DEB_NET
);
530 spin_lock_irq(&priv
->driver_lock
);
531 priv
->infra_open
= 0;
532 netif_stop_queue(dev
);
533 spin_unlock_irq(&priv
->driver_lock
);
535 schedule_work(&priv
->mcast_work
);
537 lbs_deb_leave(LBS_DEB_NET
);
541 static void lbs_tx_timeout(struct net_device
*dev
)
543 struct lbs_private
*priv
= dev
->ml_priv
;
545 lbs_deb_enter(LBS_DEB_TX
);
547 lbs_pr_err("tx watch dog timeout\n");
549 dev
->trans_start
= jiffies
;
551 if (priv
->currenttxskb
)
552 lbs_send_tx_feedback(priv
, 0);
554 /* XX: Shouldn't we also call into the hw-specific driver
555 to kick it somehow? */
556 lbs_host_to_card_done(priv
);
558 /* More often than not, this actually happens because the
559 firmware has crapped itself -- rather than just a very
560 busy medium. So send a harmless command, and if/when
561 _that_ times out, we'll kick it in the head. */
562 lbs_prepare_and_send_command(priv
, CMD_802_11_RSSI
, 0,
565 lbs_deb_leave(LBS_DEB_TX
);
568 void lbs_host_to_card_done(struct lbs_private
*priv
)
572 lbs_deb_enter(LBS_DEB_THREAD
);
574 spin_lock_irqsave(&priv
->driver_lock
, flags
);
576 priv
->dnld_sent
= DNLD_RES_RECEIVED
;
578 /* Wake main thread if commands are pending */
579 if (!priv
->cur_cmd
|| priv
->tx_pending_len
> 0) {
580 if (!priv
->wakeup_dev_required
)
581 wake_up_interruptible(&priv
->waitq
);
584 spin_unlock_irqrestore(&priv
->driver_lock
, flags
);
585 lbs_deb_leave(LBS_DEB_THREAD
);
587 EXPORT_SYMBOL_GPL(lbs_host_to_card_done
);
589 static int lbs_set_mac_address(struct net_device
*dev
, void *addr
)
592 struct lbs_private
*priv
= dev
->ml_priv
;
593 struct sockaddr
*phwaddr
= addr
;
594 struct cmd_ds_802_11_mac_address cmd
;
596 lbs_deb_enter(LBS_DEB_NET
);
598 /* In case it was called from the mesh device */
601 cmd
.hdr
.size
= cpu_to_le16(sizeof(cmd
));
602 cmd
.action
= cpu_to_le16(CMD_ACT_SET
);
603 memcpy(cmd
.macadd
, phwaddr
->sa_data
, ETH_ALEN
);
605 ret
= lbs_cmd_with_response(priv
, CMD_802_11_MAC_ADDRESS
, &cmd
);
607 lbs_deb_net("set MAC address failed\n");
611 memcpy(priv
->current_addr
, phwaddr
->sa_data
, ETH_ALEN
);
612 memcpy(dev
->dev_addr
, phwaddr
->sa_data
, ETH_ALEN
);
614 memcpy(priv
->mesh_dev
->dev_addr
, phwaddr
->sa_data
, ETH_ALEN
);
617 lbs_deb_leave_args(LBS_DEB_NET
, "ret %d", ret
);
622 static inline int mac_in_list(unsigned char *list
, int list_len
,
626 if (!memcmp(list
, mac
, ETH_ALEN
))
635 static int lbs_add_mcast_addrs(struct cmd_ds_mac_multicast_adr
*cmd
,
636 struct net_device
*dev
, int nr_addrs
)
639 struct dev_mc_list
*mc_list
;
641 if ((dev
->flags
& (IFF_UP
|IFF_MULTICAST
)) != (IFF_UP
|IFF_MULTICAST
))
644 netif_addr_lock_bh(dev
);
645 for (mc_list
= dev
->mc_list
; mc_list
; mc_list
= mc_list
->next
) {
646 if (mac_in_list(cmd
->maclist
, nr_addrs
, mc_list
->dmi_addr
)) {
647 lbs_deb_net("mcast address %s:%pM skipped\n", dev
->name
,
652 if (i
== MRVDRV_MAX_MULTICAST_LIST_SIZE
)
654 memcpy(&cmd
->maclist
[6*i
], mc_list
->dmi_addr
, ETH_ALEN
);
655 lbs_deb_net("mcast address %s:%pM added to filter\n", dev
->name
,
659 netif_addr_unlock_bh(dev
);
666 static void lbs_set_mcast_worker(struct work_struct
*work
)
668 struct lbs_private
*priv
= container_of(work
, struct lbs_private
, mcast_work
);
669 struct cmd_ds_mac_multicast_adr mcast_cmd
;
672 int old_mac_control
= priv
->mac_control
;
674 lbs_deb_enter(LBS_DEB_NET
);
676 dev_flags
= priv
->dev
->flags
;
678 dev_flags
|= priv
->mesh_dev
->flags
;
680 if (dev_flags
& IFF_PROMISC
) {
681 priv
->mac_control
|= CMD_ACT_MAC_PROMISCUOUS_ENABLE
;
682 priv
->mac_control
&= ~(CMD_ACT_MAC_ALL_MULTICAST_ENABLE
|
683 CMD_ACT_MAC_MULTICAST_ENABLE
);
684 goto out_set_mac_control
;
685 } else if (dev_flags
& IFF_ALLMULTI
) {
687 priv
->mac_control
|= CMD_ACT_MAC_ALL_MULTICAST_ENABLE
;
688 priv
->mac_control
&= ~(CMD_ACT_MAC_PROMISCUOUS_ENABLE
|
689 CMD_ACT_MAC_MULTICAST_ENABLE
);
690 goto out_set_mac_control
;
693 /* Once for priv->dev, again for priv->mesh_dev if it exists */
694 nr_addrs
= lbs_add_mcast_addrs(&mcast_cmd
, priv
->dev
, 0);
695 if (nr_addrs
>= 0 && priv
->mesh_dev
)
696 nr_addrs
= lbs_add_mcast_addrs(&mcast_cmd
, priv
->mesh_dev
, nr_addrs
);
701 int size
= offsetof(struct cmd_ds_mac_multicast_adr
,
702 maclist
[6*nr_addrs
]);
704 mcast_cmd
.action
= cpu_to_le16(CMD_ACT_SET
);
705 mcast_cmd
.hdr
.size
= cpu_to_le16(size
);
706 mcast_cmd
.nr_of_adrs
= cpu_to_le16(nr_addrs
);
708 lbs_cmd_async(priv
, CMD_MAC_MULTICAST_ADR
, &mcast_cmd
.hdr
, size
);
710 priv
->mac_control
|= CMD_ACT_MAC_MULTICAST_ENABLE
;
712 priv
->mac_control
&= ~CMD_ACT_MAC_MULTICAST_ENABLE
;
714 priv
->mac_control
&= ~(CMD_ACT_MAC_PROMISCUOUS_ENABLE
|
715 CMD_ACT_MAC_ALL_MULTICAST_ENABLE
);
717 if (priv
->mac_control
!= old_mac_control
)
718 lbs_set_mac_control(priv
);
720 lbs_deb_leave(LBS_DEB_NET
);
723 static void lbs_set_multicast_list(struct net_device
*dev
)
725 struct lbs_private
*priv
= dev
->ml_priv
;
727 schedule_work(&priv
->mcast_work
);
731 * @brief This function handles the major jobs in the LBS driver.
732 * It handles all events generated by firmware, RX data received
733 * from firmware and TX data sent from kernel.
735 * @param data A pointer to lbs_thread structure
738 static int lbs_thread(void *data
)
740 struct net_device
*dev
= data
;
741 struct lbs_private
*priv
= dev
->ml_priv
;
744 lbs_deb_enter(LBS_DEB_THREAD
);
746 init_waitqueue_entry(&wait
, current
);
752 lbs_deb_thread("1: currenttxskb %p, dnld_sent %d\n",
753 priv
->currenttxskb
, priv
->dnld_sent
);
755 add_wait_queue(&priv
->waitq
, &wait
);
756 set_current_state(TASK_INTERRUPTIBLE
);
757 spin_lock_irq(&priv
->driver_lock
);
759 if (kthread_should_stop())
760 shouldsleep
= 0; /* Bye */
761 else if (priv
->surpriseremoved
)
762 shouldsleep
= 1; /* We need to wait until we're _told_ to die */
763 else if (priv
->psstate
== PS_STATE_SLEEP
)
764 shouldsleep
= 1; /* Sleep mode. Nothing we can do till it wakes */
765 else if (priv
->cmd_timed_out
)
766 shouldsleep
= 0; /* Command timed out. Recover */
767 else if (!priv
->fw_ready
)
768 shouldsleep
= 1; /* Firmware not ready. We're waiting for it */
769 else if (priv
->dnld_sent
)
770 shouldsleep
= 1; /* Something is en route to the device already */
771 else if (priv
->tx_pending_len
> 0)
772 shouldsleep
= 0; /* We've a packet to send */
773 else if (priv
->resp_len
[priv
->resp_idx
])
774 shouldsleep
= 0; /* We have a command response */
775 else if (priv
->cur_cmd
)
776 shouldsleep
= 1; /* Can't send a command; one already running */
777 else if (!list_empty(&priv
->cmdpendingq
) &&
778 !(priv
->wakeup_dev_required
))
779 shouldsleep
= 0; /* We have a command to send */
780 else if (__kfifo_len(priv
->event_fifo
))
781 shouldsleep
= 0; /* We have an event to process */
783 shouldsleep
= 1; /* No command */
786 lbs_deb_thread("sleeping, connect_status %d, "
787 "psmode %d, psstate %d\n",
788 priv
->connect_status
,
789 priv
->psmode
, priv
->psstate
);
790 spin_unlock_irq(&priv
->driver_lock
);
793 spin_unlock_irq(&priv
->driver_lock
);
795 lbs_deb_thread("2: currenttxskb %p, dnld_send %d\n",
796 priv
->currenttxskb
, priv
->dnld_sent
);
798 set_current_state(TASK_RUNNING
);
799 remove_wait_queue(&priv
->waitq
, &wait
);
801 lbs_deb_thread("3: currenttxskb %p, dnld_sent %d\n",
802 priv
->currenttxskb
, priv
->dnld_sent
);
804 if (kthread_should_stop()) {
805 lbs_deb_thread("break from main thread\n");
809 if (priv
->surpriseremoved
) {
810 lbs_deb_thread("adapter removed; waiting to die...\n");
814 lbs_deb_thread("4: currenttxskb %p, dnld_sent %d\n",
815 priv
->currenttxskb
, priv
->dnld_sent
);
817 /* Process any pending command response */
818 spin_lock_irq(&priv
->driver_lock
);
819 resp_idx
= priv
->resp_idx
;
820 if (priv
->resp_len
[resp_idx
]) {
821 spin_unlock_irq(&priv
->driver_lock
);
822 lbs_process_command_response(priv
,
823 priv
->resp_buf
[resp_idx
],
824 priv
->resp_len
[resp_idx
]);
825 spin_lock_irq(&priv
->driver_lock
);
826 priv
->resp_len
[resp_idx
] = 0;
828 spin_unlock_irq(&priv
->driver_lock
);
830 /* Process hardware events, e.g. card removed, link lost */
831 spin_lock_irq(&priv
->driver_lock
);
832 while (__kfifo_len(priv
->event_fifo
)) {
834 __kfifo_get(priv
->event_fifo
, (unsigned char *) &event
,
836 spin_unlock_irq(&priv
->driver_lock
);
837 lbs_process_event(priv
, event
);
838 spin_lock_irq(&priv
->driver_lock
);
840 spin_unlock_irq(&priv
->driver_lock
);
842 if (priv
->wakeup_dev_required
) {
843 lbs_deb_thread("Waking up device...\n");
845 if (priv
->exit_deep_sleep(priv
))
846 lbs_deb_thread("Wakeup device failed\n");
850 /* command timeout stuff */
851 if (priv
->cmd_timed_out
&& priv
->cur_cmd
) {
852 struct cmd_ctrl_node
*cmdnode
= priv
->cur_cmd
;
854 if (++priv
->nr_retries
> 3) {
855 lbs_pr_info("Excessive timeouts submitting "
857 le16_to_cpu(cmdnode
->cmdbuf
->command
));
858 lbs_complete_command(priv
, cmdnode
, -ETIMEDOUT
);
859 priv
->nr_retries
= 0;
860 if (priv
->reset_card
)
861 priv
->reset_card(priv
);
863 priv
->cur_cmd
= NULL
;
864 priv
->dnld_sent
= DNLD_RES_RECEIVED
;
865 lbs_pr_info("requeueing command 0x%04x due "
866 "to timeout (#%d)\n",
867 le16_to_cpu(cmdnode
->cmdbuf
->command
),
870 /* Stick it back at the _top_ of the pending queue
871 for immediate resubmission */
872 list_add(&cmdnode
->list
, &priv
->cmdpendingq
);
875 priv
->cmd_timed_out
= 0;
882 /* Check if we need to confirm Sleep Request received previously */
883 if (priv
->psstate
== PS_STATE_PRE_SLEEP
&&
884 !priv
->dnld_sent
&& !priv
->cur_cmd
) {
885 if (priv
->connect_status
== LBS_CONNECTED
) {
886 lbs_deb_thread("pre-sleep, currenttxskb %p, "
887 "dnld_sent %d, cur_cmd %p\n",
888 priv
->currenttxskb
, priv
->dnld_sent
,
891 lbs_ps_confirm_sleep(priv
);
893 /* workaround for firmware sending
894 * deauth/linkloss event immediately
895 * after sleep request; remove this
896 * after firmware fixes it
898 priv
->psstate
= PS_STATE_AWAKE
;
899 lbs_pr_alert("ignore PS_SleepConfirm in "
900 "non-connected state\n");
904 /* The PS state is changed during processing of Sleep Request
907 if ((priv
->psstate
== PS_STATE_SLEEP
) ||
908 (priv
->psstate
== PS_STATE_PRE_SLEEP
))
911 if (priv
->is_deep_sleep
)
914 /* Execute the next command */
915 if (!priv
->dnld_sent
&& !priv
->cur_cmd
)
916 lbs_execute_next_command(priv
);
918 /* Wake-up command waiters which can't sleep in
919 * lbs_prepare_and_send_command
921 if (!list_empty(&priv
->cmdpendingq
))
922 wake_up_all(&priv
->cmd_pending
);
924 spin_lock_irq(&priv
->driver_lock
);
925 if (!priv
->dnld_sent
&& priv
->tx_pending_len
> 0) {
926 int ret
= priv
->hw_host_to_card(priv
, MVMS_DAT
,
927 priv
->tx_pending_buf
,
928 priv
->tx_pending_len
);
930 lbs_deb_tx("host_to_card failed %d\n", ret
);
931 priv
->dnld_sent
= DNLD_RES_RECEIVED
;
933 priv
->tx_pending_len
= 0;
934 if (!priv
->currenttxskb
) {
935 /* We can wake the queues immediately if we aren't
936 waiting for TX feedback */
937 if (priv
->connect_status
== LBS_CONNECTED
)
938 netif_wake_queue(priv
->dev
);
939 if (priv
->mesh_dev
&&
940 priv
->mesh_connect_status
== LBS_CONNECTED
)
941 netif_wake_queue(priv
->mesh_dev
);
944 spin_unlock_irq(&priv
->driver_lock
);
947 del_timer(&priv
->command_timer
);
948 del_timer(&priv
->auto_deepsleep_timer
);
949 wake_up_all(&priv
->cmd_pending
);
951 lbs_deb_leave(LBS_DEB_THREAD
);
955 static int lbs_suspend_callback(struct lbs_private
*priv
, unsigned long dummy
,
956 struct cmd_header
*cmd
)
958 lbs_deb_enter(LBS_DEB_FW
);
960 netif_device_detach(priv
->dev
);
962 netif_device_detach(priv
->mesh_dev
);
965 lbs_deb_leave(LBS_DEB_FW
);
969 int lbs_suspend(struct lbs_private
*priv
)
971 struct cmd_header cmd
;
974 lbs_deb_enter(LBS_DEB_FW
);
976 if (priv
->wol_criteria
== 0xffffffff) {
977 lbs_pr_info("Suspend attempt without configuring wake params!\n");
981 memset(&cmd
, 0, sizeof(cmd
));
983 ret
= __lbs_cmd(priv
, CMD_802_11_HOST_SLEEP_ACTIVATE
, &cmd
,
984 sizeof(cmd
), lbs_suspend_callback
, 0);
986 lbs_pr_info("HOST_SLEEP_ACTIVATE failed: %d\n", ret
);
988 lbs_deb_leave_args(LBS_DEB_FW
, "ret %d", ret
);
991 EXPORT_SYMBOL_GPL(lbs_suspend
);
993 void lbs_resume(struct lbs_private
*priv
)
995 lbs_deb_enter(LBS_DEB_FW
);
999 /* Firmware doesn't seem to give us RX packets any more
1000 until we send it some command. Might as well update */
1001 lbs_prepare_and_send_command(priv
, CMD_802_11_RSSI
, 0,
1004 netif_device_attach(priv
->dev
);
1006 netif_device_attach(priv
->mesh_dev
);
1008 lbs_deb_leave(LBS_DEB_FW
);
1010 EXPORT_SYMBOL_GPL(lbs_resume
);
1013 * @brief This function gets the HW spec from the firmware and sets
1014 * some basic parameters.
1016 * @param priv A pointer to struct lbs_private structure
1019 static int lbs_setup_firmware(struct lbs_private
*priv
)
1022 s16 curlevel
= 0, minlevel
= 0, maxlevel
= 0;
1024 lbs_deb_enter(LBS_DEB_FW
);
1026 /* Read MAC address from firmware */
1027 memset(priv
->current_addr
, 0xff, ETH_ALEN
);
1028 ret
= lbs_update_hw_spec(priv
);
1032 /* Read power levels if available */
1033 ret
= lbs_get_tx_power(priv
, &curlevel
, &minlevel
, &maxlevel
);
1035 priv
->txpower_cur
= curlevel
;
1036 priv
->txpower_min
= minlevel
;
1037 priv
->txpower_max
= maxlevel
;
1040 lbs_set_mac_control(priv
);
1042 lbs_deb_leave_args(LBS_DEB_FW
, "ret %d", ret
);
1047 * This function handles the timeout of command sending.
1048 * It will re-send the same command again.
1050 static void command_timer_fn(unsigned long data
)
1052 struct lbs_private
*priv
= (struct lbs_private
*)data
;
1053 unsigned long flags
;
1055 lbs_deb_enter(LBS_DEB_CMD
);
1056 spin_lock_irqsave(&priv
->driver_lock
, flags
);
1061 lbs_pr_info("command 0x%04x timed out\n",
1062 le16_to_cpu(priv
->cur_cmd
->cmdbuf
->command
));
1064 priv
->cmd_timed_out
= 1;
1065 wake_up_interruptible(&priv
->waitq
);
1067 spin_unlock_irqrestore(&priv
->driver_lock
, flags
);
1068 lbs_deb_leave(LBS_DEB_CMD
);
1072 * This function put the device back to deep sleep mode when timer expires
1073 * and no activity (command, event, data etc.) is detected.
1075 static void auto_deepsleep_timer_fn(unsigned long data
)
1077 struct lbs_private
*priv
= (struct lbs_private
*)data
;
1080 lbs_deb_enter(LBS_DEB_CMD
);
1082 if (priv
->is_activity_detected
) {
1083 priv
->is_activity_detected
= 0;
1085 if (priv
->is_auto_deep_sleep_enabled
&&
1086 (!priv
->wakeup_dev_required
) &&
1087 (priv
->connect_status
!= LBS_CONNECTED
)) {
1088 lbs_deb_main("Entering auto deep sleep mode...\n");
1089 ret
= lbs_prepare_and_send_command(priv
,
1090 CMD_802_11_DEEP_SLEEP
, 0,
1093 lbs_pr_err("Enter Deep Sleep command failed\n");
1096 mod_timer(&priv
->auto_deepsleep_timer
, jiffies
+
1097 (priv
->auto_deep_sleep_timeout
* HZ
)/1000);
1098 lbs_deb_leave(LBS_DEB_CMD
);
1101 int lbs_enter_auto_deep_sleep(struct lbs_private
*priv
)
1103 lbs_deb_enter(LBS_DEB_SDIO
);
1105 priv
->is_auto_deep_sleep_enabled
= 1;
1106 if (priv
->is_deep_sleep
)
1107 priv
->wakeup_dev_required
= 1;
1108 mod_timer(&priv
->auto_deepsleep_timer
,
1109 jiffies
+ (priv
->auto_deep_sleep_timeout
* HZ
)/1000);
1111 lbs_deb_leave(LBS_DEB_SDIO
);
1115 int lbs_exit_auto_deep_sleep(struct lbs_private
*priv
)
1117 lbs_deb_enter(LBS_DEB_SDIO
);
1119 priv
->is_auto_deep_sleep_enabled
= 0;
1120 priv
->auto_deep_sleep_timeout
= 0;
1121 del_timer(&priv
->auto_deepsleep_timer
);
1123 lbs_deb_leave(LBS_DEB_SDIO
);
1127 static void lbs_sync_channel_worker(struct work_struct
*work
)
1129 struct lbs_private
*priv
= container_of(work
, struct lbs_private
,
1132 lbs_deb_enter(LBS_DEB_MAIN
);
1133 if (lbs_update_channel(priv
))
1134 lbs_pr_info("Channel synchronization failed.");
1135 lbs_deb_leave(LBS_DEB_MAIN
);
1139 static int lbs_init_adapter(struct lbs_private
*priv
)
1144 lbs_deb_enter(LBS_DEB_MAIN
);
1146 /* Allocate buffer to store the BSSID list */
1147 bufsize
= MAX_NETWORK_COUNT
* sizeof(struct bss_descriptor
);
1148 priv
->networks
= kzalloc(bufsize
, GFP_KERNEL
);
1149 if (!priv
->networks
) {
1150 lbs_pr_err("Out of memory allocating beacons\n");
1155 /* Initialize scan result lists */
1156 INIT_LIST_HEAD(&priv
->network_free_list
);
1157 INIT_LIST_HEAD(&priv
->network_list
);
1158 for (i
= 0; i
< MAX_NETWORK_COUNT
; i
++) {
1159 list_add_tail(&priv
->networks
[i
].list
,
1160 &priv
->network_free_list
);
1163 memset(priv
->current_addr
, 0xff, ETH_ALEN
);
1165 priv
->connect_status
= LBS_DISCONNECTED
;
1166 priv
->mesh_connect_status
= LBS_DISCONNECTED
;
1167 priv
->secinfo
.auth_mode
= IW_AUTH_ALG_OPEN_SYSTEM
;
1168 priv
->mode
= IW_MODE_INFRA
;
1169 priv
->curbssparams
.channel
= DEFAULT_AD_HOC_CHANNEL
;
1170 priv
->mac_control
= CMD_ACT_MAC_RX_ON
| CMD_ACT_MAC_TX_ON
;
1172 priv
->enablehwauto
= 1;
1173 priv
->capability
= WLAN_CAPABILITY_SHORT_PREAMBLE
;
1174 priv
->psmode
= LBS802_11POWERMODECAM
;
1175 priv
->psstate
= PS_STATE_FULL_POWER
;
1176 priv
->is_deep_sleep
= 0;
1177 priv
->is_auto_deep_sleep_enabled
= 0;
1178 priv
->wakeup_dev_required
= 0;
1179 init_waitqueue_head(&priv
->ds_awake_q
);
1181 mutex_init(&priv
->lock
);
1183 setup_timer(&priv
->command_timer
, command_timer_fn
,
1184 (unsigned long)priv
);
1185 setup_timer(&priv
->auto_deepsleep_timer
, auto_deepsleep_timer_fn
,
1186 (unsigned long)priv
);
1188 INIT_LIST_HEAD(&priv
->cmdfreeq
);
1189 INIT_LIST_HEAD(&priv
->cmdpendingq
);
1191 spin_lock_init(&priv
->driver_lock
);
1192 init_waitqueue_head(&priv
->cmd_pending
);
1194 /* Allocate the command buffers */
1195 if (lbs_allocate_cmd_buffer(priv
)) {
1196 lbs_pr_err("Out of memory allocating command buffers\n");
1201 priv
->resp_len
[0] = priv
->resp_len
[1] = 0;
1203 /* Create the event FIFO */
1204 priv
->event_fifo
= kfifo_alloc(sizeof(u32
) * 16, GFP_KERNEL
, NULL
);
1205 if (IS_ERR(priv
->event_fifo
)) {
1206 lbs_pr_err("Out of memory allocating event FIFO buffer\n");
1212 lbs_deb_leave_args(LBS_DEB_MAIN
, "ret %d", ret
);
1217 static void lbs_free_adapter(struct lbs_private
*priv
)
1219 lbs_deb_enter(LBS_DEB_MAIN
);
1221 lbs_free_cmd_buffer(priv
);
1222 if (priv
->event_fifo
)
1223 kfifo_free(priv
->event_fifo
);
1224 del_timer(&priv
->command_timer
);
1225 del_timer(&priv
->auto_deepsleep_timer
);
1226 kfree(priv
->networks
);
1227 priv
->networks
= NULL
;
1229 lbs_deb_leave(LBS_DEB_MAIN
);
1232 static const struct net_device_ops lbs_netdev_ops
= {
1233 .ndo_open
= lbs_dev_open
,
1234 .ndo_stop
= lbs_eth_stop
,
1235 .ndo_start_xmit
= lbs_hard_start_xmit
,
1236 .ndo_set_mac_address
= lbs_set_mac_address
,
1237 .ndo_tx_timeout
= lbs_tx_timeout
,
1238 .ndo_set_multicast_list
= lbs_set_multicast_list
,
1239 .ndo_change_mtu
= eth_change_mtu
,
1240 .ndo_validate_addr
= eth_validate_addr
,
1244 * @brief This function adds the card. it will probe the
1245 * card, allocate the lbs_priv and initialize the device.
1247 * @param card A pointer to card
1248 * @return A pointer to struct lbs_private structure
1250 struct lbs_private
*lbs_add_card(void *card
, struct device
*dmdev
)
1252 struct net_device
*dev
;
1253 struct wireless_dev
*wdev
;
1254 struct lbs_private
*priv
= NULL
;
1256 lbs_deb_enter(LBS_DEB_MAIN
);
1258 /* Allocate an Ethernet device and register it */
1259 wdev
= lbs_cfg_alloc(dmdev
);
1261 lbs_pr_err("cfg80211 init failed\n");
1265 wdev
->iftype
= NL80211_IFTYPE_STATION
;
1266 priv
= wdev_priv(wdev
);
1269 if (lbs_init_adapter(priv
)) {
1270 lbs_pr_err("failed to initialize adapter structure.\n");
1274 //TODO? dev = alloc_netdev_mq(0, "wlan%d", ether_setup, IWM_TX_QUEUES);
1275 dev
= alloc_netdev(0, "wlan%d", ether_setup
);
1277 dev_err(dmdev
, "no memory for network device instance\n");
1281 dev
->ieee80211_ptr
= wdev
;
1282 dev
->ml_priv
= priv
;
1283 SET_NETDEV_DEV(dev
, dmdev
);
1287 dev
->netdev_ops
= &lbs_netdev_ops
;
1288 dev
->watchdog_timeo
= 5 * HZ
;
1289 dev
->ethtool_ops
= &lbs_ethtool_ops
;
1291 dev
->wireless_handlers
= &lbs_handler_def
;
1293 dev
->flags
|= IFF_BROADCAST
| IFF_MULTICAST
;
1296 // TODO: kzalloc + iwm_init_default_profile(iwm, iwm->umac_profile); ??
1300 priv
->mesh_open
= 0;
1301 priv
->infra_open
= 0;
1304 priv
->rtap_net_dev
= NULL
;
1305 strcpy(dev
->name
, "wlan%d");
1307 lbs_deb_thread("Starting main thread...\n");
1308 init_waitqueue_head(&priv
->waitq
);
1309 priv
->main_thread
= kthread_run(lbs_thread
, dev
, "lbs_main");
1310 if (IS_ERR(priv
->main_thread
)) {
1311 lbs_deb_thread("Error creating main thread.\n");
1315 priv
->work_thread
= create_singlethread_workqueue("lbs_worker");
1316 INIT_DELAYED_WORK(&priv
->assoc_work
, lbs_association_worker
);
1317 INIT_DELAYED_WORK(&priv
->scan_work
, lbs_scan_worker
);
1318 INIT_WORK(&priv
->mcast_work
, lbs_set_mcast_worker
);
1319 INIT_WORK(&priv
->sync_channel
, lbs_sync_channel_worker
);
1321 sprintf(priv
->mesh_ssid
, "mesh");
1322 priv
->mesh_ssid_len
= 4;
1324 priv
->wol_criteria
= 0xffffffff;
1325 priv
->wol_gpio
= 0xff;
1333 lbs_free_adapter(priv
);
1341 lbs_deb_leave_args(LBS_DEB_MAIN
, "priv %p", priv
);
1344 EXPORT_SYMBOL_GPL(lbs_add_card
);
1347 void lbs_remove_card(struct lbs_private
*priv
)
1349 struct net_device
*dev
= priv
->dev
;
1350 union iwreq_data wrqu
;
1352 lbs_deb_enter(LBS_DEB_MAIN
);
1354 lbs_remove_mesh(priv
);
1355 lbs_remove_rtap(priv
);
1359 cancel_delayed_work_sync(&priv
->scan_work
);
1360 cancel_delayed_work_sync(&priv
->assoc_work
);
1361 cancel_work_sync(&priv
->mcast_work
);
1363 /* worker thread destruction blocks on the in-flight command which
1364 * should have been cleared already in lbs_stop_card().
1366 lbs_deb_main("destroying worker thread\n");
1367 destroy_workqueue(priv
->work_thread
);
1368 lbs_deb_main("done destroying worker thread\n");
1370 if (priv
->psmode
== LBS802_11POWERMODEMAX_PSP
) {
1371 priv
->psmode
= LBS802_11POWERMODECAM
;
1372 lbs_ps_wakeup(priv
, CMD_OPTION_WAITFORRSP
);
1375 memset(wrqu
.ap_addr
.sa_data
, 0xaa, ETH_ALEN
);
1376 wrqu
.ap_addr
.sa_family
= ARPHRD_ETHER
;
1377 wireless_send_event(priv
->dev
, SIOCGIWAP
, &wrqu
, NULL
);
1379 if (priv
->is_deep_sleep
) {
1380 priv
->is_deep_sleep
= 0;
1381 wake_up_interruptible(&priv
->ds_awake_q
);
1384 /* Stop the thread servicing the interrupts */
1385 priv
->surpriseremoved
= 1;
1386 kthread_stop(priv
->main_thread
);
1388 lbs_free_adapter(priv
);
1394 lbs_deb_leave(LBS_DEB_MAIN
);
1396 EXPORT_SYMBOL_GPL(lbs_remove_card
);
1399 int lbs_start_card(struct lbs_private
*priv
)
1401 struct net_device
*dev
= priv
->dev
;
1404 lbs_deb_enter(LBS_DEB_MAIN
);
1406 /* poke the firmware */
1407 ret
= lbs_setup_firmware(priv
);
1414 if (lbs_cfg_register(priv
)) {
1415 lbs_pr_err("cannot register device\n");
1419 lbs_update_channel(priv
);
1421 /* Check mesh FW version and appropriately send the mesh start
1424 if (priv
->mesh_fw_ver
== MESH_FW_OLD
) {
1425 /* Enable mesh, if supported, and work out which TLV it uses.
1426 0x100 + 291 is an unofficial value used in 5.110.20.pXX
1427 0x100 + 37 is the official value used in 5.110.21.pXX
1428 but we check them in that order because 20.pXX doesn't
1429 give an error -- it just silently fails. */
1431 /* 5.110.20.pXX firmware will fail the command if the channel
1432 doesn't match the existing channel. But only if the TLV
1433 is correct. If the channel is wrong, _BOTH_ versions will
1434 give an error to 0x100+291, and allow 0x100+37 to succeed.
1435 It's just that 5.110.20.pXX will not have done anything
1438 priv
->mesh_tlv
= TLV_TYPE_OLD_MESH_ID
;
1439 if (lbs_mesh_config(priv
, CMD_ACT_MESH_CONFIG_START
,
1440 priv
->curbssparams
.channel
)) {
1441 priv
->mesh_tlv
= TLV_TYPE_MESH_ID
;
1442 if (lbs_mesh_config(priv
, CMD_ACT_MESH_CONFIG_START
,
1443 priv
->curbssparams
.channel
))
1446 } else if (priv
->mesh_fw_ver
== MESH_FW_NEW
) {
1447 /* 10.0.0.pXX new firmwares should succeed with TLV
1448 * 0x100+37; Do not invoke command with old TLV.
1450 priv
->mesh_tlv
= TLV_TYPE_MESH_ID
;
1451 if (lbs_mesh_config(priv
, CMD_ACT_MESH_CONFIG_START
,
1452 priv
->curbssparams
.channel
))
1455 if (priv
->mesh_tlv
) {
1458 if (device_create_file(&dev
->dev
, &dev_attr_lbs_mesh
))
1459 lbs_pr_err("cannot register lbs_mesh attribute\n");
1461 /* While rtap isn't related to mesh, only mesh-enabled
1462 * firmware implements the rtap functionality via
1463 * CMD_802_11_MONITOR_MODE.
1465 if (device_create_file(&dev
->dev
, &dev_attr_lbs_rtap
))
1466 lbs_pr_err("cannot register lbs_rtap attribute\n");
1469 lbs_debugfs_init_one(priv
, dev
);
1471 lbs_pr_info("%s: Marvell WLAN 802.11 adapter\n", dev
->name
);
1476 lbs_deb_leave_args(LBS_DEB_MAIN
, "ret %d", ret
);
1479 EXPORT_SYMBOL_GPL(lbs_start_card
);
1482 void lbs_stop_card(struct lbs_private
*priv
)
1484 struct net_device
*dev
;
1485 struct cmd_ctrl_node
*cmdnode
;
1486 unsigned long flags
;
1488 lbs_deb_enter(LBS_DEB_MAIN
);
1494 netif_stop_queue(dev
);
1495 netif_carrier_off(dev
);
1497 lbs_debugfs_remove_one(priv
);
1498 if (priv
->mesh_tlv
) {
1499 device_remove_file(&dev
->dev
, &dev_attr_lbs_mesh
);
1500 device_remove_file(&dev
->dev
, &dev_attr_lbs_rtap
);
1503 /* Delete the timeout of the currently processing command */
1504 del_timer_sync(&priv
->command_timer
);
1505 del_timer_sync(&priv
->auto_deepsleep_timer
);
1507 /* Flush pending command nodes */
1508 spin_lock_irqsave(&priv
->driver_lock
, flags
);
1509 lbs_deb_main("clearing pending commands\n");
1510 list_for_each_entry(cmdnode
, &priv
->cmdpendingq
, list
) {
1511 cmdnode
->result
= -ENOENT
;
1512 cmdnode
->cmdwaitqwoken
= 1;
1513 wake_up_interruptible(&cmdnode
->cmdwait_q
);
1516 /* Flush the command the card is currently processing */
1517 if (priv
->cur_cmd
) {
1518 lbs_deb_main("clearing current command\n");
1519 priv
->cur_cmd
->result
= -ENOENT
;
1520 priv
->cur_cmd
->cmdwaitqwoken
= 1;
1521 wake_up_interruptible(&priv
->cur_cmd
->cmdwait_q
);
1523 lbs_deb_main("done clearing commands\n");
1524 spin_unlock_irqrestore(&priv
->driver_lock
, flags
);
1526 unregister_netdev(dev
);
1529 lbs_deb_leave(LBS_DEB_MAIN
);
1531 EXPORT_SYMBOL_GPL(lbs_stop_card
);
1534 static const struct net_device_ops mesh_netdev_ops
= {
1535 .ndo_open
= lbs_dev_open
,
1536 .ndo_stop
= lbs_mesh_stop
,
1537 .ndo_start_xmit
= lbs_hard_start_xmit
,
1538 .ndo_set_mac_address
= lbs_set_mac_address
,
1539 .ndo_set_multicast_list
= lbs_set_multicast_list
,
1543 * @brief This function adds mshX interface
1545 * @param priv A pointer to the struct lbs_private structure
1546 * @return 0 if successful, -X otherwise
1548 static int lbs_add_mesh(struct lbs_private
*priv
)
1550 struct net_device
*mesh_dev
= NULL
;
1553 lbs_deb_enter(LBS_DEB_MESH
);
1555 /* Allocate a virtual mesh device */
1556 if (!(mesh_dev
= alloc_netdev(0, "msh%d", ether_setup
))) {
1557 lbs_deb_mesh("init mshX device failed\n");
1561 mesh_dev
->ml_priv
= priv
;
1562 priv
->mesh_dev
= mesh_dev
;
1564 mesh_dev
->netdev_ops
= &mesh_netdev_ops
;
1565 mesh_dev
->ethtool_ops
= &lbs_ethtool_ops
;
1566 memcpy(mesh_dev
->dev_addr
, priv
->dev
->dev_addr
,
1567 sizeof(priv
->dev
->dev_addr
));
1569 SET_NETDEV_DEV(priv
->mesh_dev
, priv
->dev
->dev
.parent
);
1572 mesh_dev
->wireless_handlers
= (struct iw_handler_def
*)&mesh_handler_def
;
1574 mesh_dev
->flags
|= IFF_BROADCAST
| IFF_MULTICAST
;
1575 /* Register virtual mesh interface */
1576 ret
= register_netdev(mesh_dev
);
1578 lbs_pr_err("cannot register mshX virtual interface\n");
1582 ret
= sysfs_create_group(&(mesh_dev
->dev
.kobj
), &lbs_mesh_attr_group
);
1584 goto err_unregister
;
1586 lbs_persist_config_init(mesh_dev
);
1588 /* Everything successful */
1593 unregister_netdev(mesh_dev
);
1596 free_netdev(mesh_dev
);
1599 lbs_deb_leave_args(LBS_DEB_MESH
, "ret %d", ret
);
1603 static void lbs_remove_mesh(struct lbs_private
*priv
)
1605 struct net_device
*mesh_dev
;
1608 mesh_dev
= priv
->mesh_dev
;
1612 lbs_deb_enter(LBS_DEB_MESH
);
1613 netif_stop_queue(mesh_dev
);
1614 netif_carrier_off(mesh_dev
);
1615 sysfs_remove_group(&(mesh_dev
->dev
.kobj
), &lbs_mesh_attr_group
);
1616 lbs_persist_config_remove(mesh_dev
);
1617 unregister_netdev(mesh_dev
);
1618 priv
->mesh_dev
= NULL
;
1619 free_netdev(mesh_dev
);
1620 lbs_deb_leave(LBS_DEB_MESH
);
1624 * @brief This function finds the CFP in
1625 * region_cfp_table based on region and band parameter.
1627 * @param region The region code
1628 * @param band The band
1629 * @param cfp_no A pointer to CFP number
1630 * @return A pointer to CFP
1632 struct chan_freq_power
*lbs_get_region_cfp_table(u8 region
, int *cfp_no
)
1636 lbs_deb_enter(LBS_DEB_MAIN
);
1638 end
= ARRAY_SIZE(region_cfp_table
);
1640 for (i
= 0; i
< end
; i
++) {
1641 lbs_deb_main("region_cfp_table[i].region=%d\n",
1642 region_cfp_table
[i
].region
);
1643 if (region_cfp_table
[i
].region
== region
) {
1644 *cfp_no
= region_cfp_table
[i
].cfp_no_BG
;
1645 lbs_deb_leave(LBS_DEB_MAIN
);
1646 return region_cfp_table
[i
].cfp_BG
;
1650 lbs_deb_leave_args(LBS_DEB_MAIN
, "ret NULL");
1654 int lbs_set_regiontable(struct lbs_private
*priv
, u8 region
, u8 band
)
1659 struct chan_freq_power
*cfp
;
1662 lbs_deb_enter(LBS_DEB_MAIN
);
1664 memset(priv
->region_channel
, 0, sizeof(priv
->region_channel
));
1666 cfp
= lbs_get_region_cfp_table(region
, &cfp_no
);
1668 priv
->region_channel
[i
].nrcfp
= cfp_no
;
1669 priv
->region_channel
[i
].CFP
= cfp
;
1671 lbs_deb_main("wrong region code %#x in band B/G\n",
1676 priv
->region_channel
[i
].valid
= 1;
1677 priv
->region_channel
[i
].region
= region
;
1678 priv
->region_channel
[i
].band
= band
;
1681 lbs_deb_leave_args(LBS_DEB_MAIN
, "ret %d", ret
);
1685 void lbs_queue_event(struct lbs_private
*priv
, u32 event
)
1687 unsigned long flags
;
1689 lbs_deb_enter(LBS_DEB_THREAD
);
1690 spin_lock_irqsave(&priv
->driver_lock
, flags
);
1692 if (priv
->psstate
== PS_STATE_SLEEP
)
1693 priv
->psstate
= PS_STATE_AWAKE
;
1695 __kfifo_put(priv
->event_fifo
, (unsigned char *) &event
, sizeof(u32
));
1697 wake_up_interruptible(&priv
->waitq
);
1699 spin_unlock_irqrestore(&priv
->driver_lock
, flags
);
1700 lbs_deb_leave(LBS_DEB_THREAD
);
1702 EXPORT_SYMBOL_GPL(lbs_queue_event
);
1704 void lbs_notify_command_response(struct lbs_private
*priv
, u8 resp_idx
)
1706 lbs_deb_enter(LBS_DEB_THREAD
);
1708 if (priv
->psstate
== PS_STATE_SLEEP
)
1709 priv
->psstate
= PS_STATE_AWAKE
;
1711 /* Swap buffers by flipping the response index */
1712 BUG_ON(resp_idx
> 1);
1713 priv
->resp_idx
= resp_idx
;
1715 wake_up_interruptible(&priv
->waitq
);
1717 lbs_deb_leave(LBS_DEB_THREAD
);
1719 EXPORT_SYMBOL_GPL(lbs_notify_command_response
);
1721 static int __init
lbs_init_module(void)
1723 lbs_deb_enter(LBS_DEB_MAIN
);
1724 memset(&confirm_sleep
, 0, sizeof(confirm_sleep
));
1725 confirm_sleep
.hdr
.command
= cpu_to_le16(CMD_802_11_PS_MODE
);
1726 confirm_sleep
.hdr
.size
= cpu_to_le16(sizeof(confirm_sleep
));
1727 confirm_sleep
.action
= cpu_to_le16(CMD_SUBCMD_SLEEP_CONFIRMED
);
1729 lbs_deb_leave(LBS_DEB_MAIN
);
1733 static void __exit
lbs_exit_module(void)
1735 lbs_deb_enter(LBS_DEB_MAIN
);
1736 lbs_debugfs_remove();
1737 lbs_deb_leave(LBS_DEB_MAIN
);
1741 * rtap interface support fuctions
1744 static int lbs_rtap_open(struct net_device
*dev
)
1746 /* Yes, _stop_ the queue. Because we don't support injection */
1747 lbs_deb_enter(LBS_DEB_MAIN
);
1748 netif_carrier_off(dev
);
1749 netif_stop_queue(dev
);
1750 lbs_deb_leave(LBS_DEB_LEAVE
);
1754 static int lbs_rtap_stop(struct net_device
*dev
)
1756 lbs_deb_enter(LBS_DEB_MAIN
);
1757 lbs_deb_leave(LBS_DEB_MAIN
);
1761 static netdev_tx_t
lbs_rtap_hard_start_xmit(struct sk_buff
*skb
,
1762 struct net_device
*dev
)
1764 netif_stop_queue(dev
);
1765 return NETDEV_TX_BUSY
;
1768 static void lbs_remove_rtap(struct lbs_private
*priv
)
1770 lbs_deb_enter(LBS_DEB_MAIN
);
1771 if (priv
->rtap_net_dev
== NULL
)
1773 unregister_netdev(priv
->rtap_net_dev
);
1774 free_netdev(priv
->rtap_net_dev
);
1775 priv
->rtap_net_dev
= NULL
;
1777 lbs_deb_leave(LBS_DEB_MAIN
);
1780 static const struct net_device_ops rtap_netdev_ops
= {
1781 .ndo_open
= lbs_rtap_open
,
1782 .ndo_stop
= lbs_rtap_stop
,
1783 .ndo_start_xmit
= lbs_rtap_hard_start_xmit
,
1786 static int lbs_add_rtap(struct lbs_private
*priv
)
1789 struct net_device
*rtap_dev
;
1791 lbs_deb_enter(LBS_DEB_MAIN
);
1792 if (priv
->rtap_net_dev
) {
1797 rtap_dev
= alloc_netdev(0, "rtap%d", ether_setup
);
1798 if (rtap_dev
== NULL
) {
1803 memcpy(rtap_dev
->dev_addr
, priv
->current_addr
, ETH_ALEN
);
1804 rtap_dev
->type
= ARPHRD_IEEE80211_RADIOTAP
;
1805 rtap_dev
->netdev_ops
= &rtap_netdev_ops
;
1806 rtap_dev
->ml_priv
= priv
;
1807 SET_NETDEV_DEV(rtap_dev
, priv
->dev
->dev
.parent
);
1809 ret
= register_netdev(rtap_dev
);
1811 free_netdev(rtap_dev
);
1814 priv
->rtap_net_dev
= rtap_dev
;
1817 lbs_deb_leave_args(LBS_DEB_MAIN
, "ret %d", ret
);
1821 module_init(lbs_init_module
);
1822 module_exit(lbs_exit_module
);
1824 MODULE_DESCRIPTION("Libertas WLAN Driver Library");
1825 MODULE_AUTHOR("Marvell International Ltd.");
1826 MODULE_LICENSE("GPL");