aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/net/wireless
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/net/wireless')
-rw-r--r--drivers/net/wireless/Kconfig6
-rw-r--r--drivers/net/wireless/airo.c15
-rw-r--r--drivers/net/wireless/airo_cs.c161
-rw-r--r--drivers/net/wireless/atmel.c1490
-rw-r--r--drivers/net/wireless/atmel_cs.c156
-rw-r--r--drivers/net/wireless/hostap/Makefile1
-rw-r--r--drivers/net/wireless/hostap/hostap_cs.c156
-rw-r--r--drivers/net/wireless/hostap/hostap_main.c (renamed from drivers/net/wireless/hostap/hostap.c)0
-rw-r--r--drivers/net/wireless/ipw2100.c40
-rw-r--r--drivers/net/wireless/ipw2100.h2
-rw-r--r--drivers/net/wireless/ipw2200.c36
-rw-r--r--drivers/net/wireless/ipw2200.h6
-rw-r--r--drivers/net/wireless/netwave_cs.c184
-rw-r--r--drivers/net/wireless/orinoco_cs.c208
-rw-r--r--drivers/net/wireless/ray_cs.c154
-rw-r--r--drivers/net/wireless/spectrum_cs.c175
-rw-r--r--drivers/net/wireless/wavelan_cs.c183
-rw-r--r--drivers/net/wireless/wavelan_cs.p.h11
-rw-r--r--drivers/net/wireless/wl3501_cs.c133
19 files changed, 1286 insertions, 1831 deletions
diff --git a/drivers/net/wireless/Kconfig b/drivers/net/wireless/Kconfig
index 00e55165b760..24f7967aab67 100644
--- a/drivers/net/wireless/Kconfig
+++ b/drivers/net/wireless/Kconfig
@@ -173,7 +173,7 @@ config IPW2100_MONITOR
173 promiscuous mode via the Wireless Tool's Monitor mode. While in this 173 promiscuous mode via the Wireless Tool's Monitor mode. While in this
174 mode, no packets can be sent. 174 mode, no packets can be sent.
175 175
176config IPW_DEBUG 176config IPW2100_DEBUG
177 bool "Enable full debugging output in IPW2100 module." 177 bool "Enable full debugging output in IPW2100 module."
178 depends on IPW2100 178 depends on IPW2100
179 ---help--- 179 ---help---
@@ -192,7 +192,7 @@ config IPW_DEBUG
192 192
193config IPW2200 193config IPW2200
194 tristate "Intel PRO/Wireless 2200BG and 2915ABG Network Connection" 194 tristate "Intel PRO/Wireless 2200BG and 2915ABG Network Connection"
195 depends on IEEE80211 && PCI 195 depends on NET_RADIO && IEEE80211 && PCI
196 select FW_LOADER 196 select FW_LOADER
197 ---help--- 197 ---help---
198 A driver for the Intel PRO/Wireless 2200BG and 2915ABG Network 198 A driver for the Intel PRO/Wireless 2200BG and 2915ABG Network
@@ -217,7 +217,7 @@ config IPW2200
217 say M here and read <file:Documentation/modules.txt>. The module 217 say M here and read <file:Documentation/modules.txt>. The module
218 will be called ipw2200.ko. 218 will be called ipw2200.ko.
219 219
220config IPW_DEBUG 220config IPW2200_DEBUG
221 bool "Enable full debugging output in IPW2200 module." 221 bool "Enable full debugging output in IPW2200 module."
222 depends on IPW2200 222 depends on IPW2200
223 ---help--- 223 ---help---
diff --git a/drivers/net/wireless/airo.c b/drivers/net/wireless/airo.c
index 7a92b1cbd6aa..ee866fd6957d 100644
--- a/drivers/net/wireless/airo.c
+++ b/drivers/net/wireless/airo.c
@@ -4037,7 +4037,7 @@ static int PC4500_writerid(struct airo_info *ai, u16 rid,
4037 Cmd cmd; 4037 Cmd cmd;
4038 Resp rsp; 4038 Resp rsp;
4039 4039
4040 if (test_bit(FLAG_ENABLED, &ai->flags)) 4040 if (test_bit(FLAG_ENABLED, &ai->flags) && (RID_WEP_TEMP != rid))
4041 printk(KERN_ERR 4041 printk(KERN_ERR
4042 "%s: MAC should be disabled (rid=%04x)\n", 4042 "%s: MAC should be disabled (rid=%04x)\n",
4043 __FUNCTION__, rid); 4043 __FUNCTION__, rid);
@@ -5093,9 +5093,9 @@ static int set_wep_key(struct airo_info *ai, u16 index,
5093 printk(KERN_INFO "Setting key %d\n", index); 5093 printk(KERN_INFO "Setting key %d\n", index);
5094 } 5094 }
5095 5095
5096 disable_MAC(ai, lock); 5096 if (perm) disable_MAC(ai, lock);
5097 writeWepKeyRid(ai, &wkr, perm, lock); 5097 writeWepKeyRid(ai, &wkr, perm, lock);
5098 enable_MAC(ai, &rsp, lock); 5098 if (perm) enable_MAC(ai, &rsp, lock);
5099 return 0; 5099 return 0;
5100} 5100}
5101 5101
@@ -6170,6 +6170,8 @@ static int airo_set_encode(struct net_device *dev,
6170{ 6170{
6171 struct airo_info *local = dev->priv; 6171 struct airo_info *local = dev->priv;
6172 CapabilityRid cap_rid; /* Card capability info */ 6172 CapabilityRid cap_rid; /* Card capability info */
6173 int perm = ( dwrq->flags & IW_ENCODE_TEMP ? 0 : 1 );
6174 u16 currentAuthType = local->config.authType;
6173 6175
6174 /* Is WEP supported ? */ 6176 /* Is WEP supported ? */
6175 readCapabilityRid(local, &cap_rid, 1); 6177 readCapabilityRid(local, &cap_rid, 1);
@@ -6212,7 +6214,7 @@ static int airo_set_encode(struct net_device *dev,
6212 /* Copy the key in the driver */ 6214 /* Copy the key in the driver */
6213 memcpy(key.key, extra, dwrq->length); 6215 memcpy(key.key, extra, dwrq->length);
6214 /* Send the key to the card */ 6216 /* Send the key to the card */
6215 set_wep_key(local, index, key.key, key.len, 1, 1); 6217 set_wep_key(local, index, key.key, key.len, perm, 1);
6216 } 6218 }
6217 /* WE specify that if a valid key is set, encryption 6219 /* WE specify that if a valid key is set, encryption
6218 * should be enabled (user may turn it off later) 6220 * should be enabled (user may turn it off later)
@@ -6220,13 +6222,12 @@ static int airo_set_encode(struct net_device *dev,
6220 if((index == current_index) && (key.len > 0) && 6222 if((index == current_index) && (key.len > 0) &&
6221 (local->config.authType == AUTH_OPEN)) { 6223 (local->config.authType == AUTH_OPEN)) {
6222 local->config.authType = AUTH_ENCRYPT; 6224 local->config.authType = AUTH_ENCRYPT;
6223 set_bit (FLAG_COMMIT, &local->flags);
6224 } 6225 }
6225 } else { 6226 } else {
6226 /* Do we want to just set the transmit key index ? */ 6227 /* Do we want to just set the transmit key index ? */
6227 int index = (dwrq->flags & IW_ENCODE_INDEX) - 1; 6228 int index = (dwrq->flags & IW_ENCODE_INDEX) - 1;
6228 if ((index >= 0) && (index < ((cap_rid.softCap & 0x80)?4:1))) { 6229 if ((index >= 0) && (index < ((cap_rid.softCap & 0x80)?4:1))) {
6229 set_wep_key(local, index, NULL, 0, 1, 1); 6230 set_wep_key(local, index, NULL, 0, perm, 1);
6230 } else 6231 } else
6231 /* Don't complain if only change the mode */ 6232 /* Don't complain if only change the mode */
6232 if(!dwrq->flags & IW_ENCODE_MODE) { 6233 if(!dwrq->flags & IW_ENCODE_MODE) {
@@ -6241,7 +6242,7 @@ static int airo_set_encode(struct net_device *dev,
6241 if(dwrq->flags & IW_ENCODE_OPEN) 6242 if(dwrq->flags & IW_ENCODE_OPEN)
6242 local->config.authType = AUTH_ENCRYPT; // Only Wep 6243 local->config.authType = AUTH_ENCRYPT; // Only Wep
6243 /* Commit the changes to flags if needed */ 6244 /* Commit the changes to flags if needed */
6244 if(dwrq->flags & IW_ENCODE_MODE) 6245 if (local->config.authType != currentAuthType)
6245 set_bit (FLAG_COMMIT, &local->flags); 6246 set_bit (FLAG_COMMIT, &local->flags);
6246 return -EINPROGRESS; /* Call commit handler */ 6247 return -EINPROGRESS; /* Call commit handler */
6247} 6248}
diff --git a/drivers/net/wireless/airo_cs.c b/drivers/net/wireless/airo_cs.c
index e328547599dc..a496460ce224 100644
--- a/drivers/net/wireless/airo_cs.c
+++ b/drivers/net/wireless/airo_cs.c
@@ -82,8 +82,6 @@ MODULE_SUPPORTED_DEVICE("Aironet 4500, 4800 and Cisco 340 PCMCIA cards");
82 82
83static void airo_config(dev_link_t *link); 83static void airo_config(dev_link_t *link);
84static void airo_release(dev_link_t *link); 84static void airo_release(dev_link_t *link);
85static int airo_event(event_t event, int priority,
86 event_callback_args_t *args);
87 85
88/* 86/*
89 The attach() and detach() entry points are used to create and destroy 87 The attach() and detach() entry points are used to create and destroy
@@ -91,8 +89,7 @@ static int airo_event(event_t event, int priority,
91 needed to manage one actual PCMCIA card. 89 needed to manage one actual PCMCIA card.
92*/ 90*/
93 91
94static dev_link_t *airo_attach(void); 92static void airo_detach(struct pcmcia_device *p_dev);
95static void airo_detach(dev_link_t *);
96 93
97/* 94/*
98 You'll also need to prototype all the functions that will actually 95 You'll also need to prototype all the functions that will actually
@@ -102,14 +99,6 @@ static void airo_detach(dev_link_t *);
102*/ 99*/
103 100
104/* 101/*
105 The dev_info variable is the "key" that is used to match up this
106 device driver with appropriate cards, through the card configuration
107 database.
108*/
109
110static dev_info_t dev_info = "airo_cs";
111
112/*
113 A linked list of "instances" of the aironet device. Each actual 102 A linked list of "instances" of the aironet device. Each actual
114 PCMCIA card corresponds to one device instance, and is described 103 PCMCIA card corresponds to one device instance, and is described
115 by one dev_link_t structure (defined in ds.h). 104 by one dev_link_t structure (defined in ds.h).
@@ -119,15 +108,7 @@ static dev_info_t dev_info = "airo_cs";
119 device numbers are used to derive the corresponding array index. 108 device numbers are used to derive the corresponding array index.
120*/ 109*/
121 110
122static dev_link_t *dev_list = NULL;
123
124/* 111/*
125 A dev_link_t structure has fields for most things that are needed
126 to keep track of a socket, but there will usually be some device
127 specific information that also needs to be kept track of. The
128 'priv' pointer in a dev_link_t structure can be used to point to
129 a device-specific private data structure, like this.
130
131 A driver needs to provide a dev_node_t structure for each device 112 A driver needs to provide a dev_node_t structure for each device
132 on a card. In some cases, there is only one device per card (for 113 on a card. In some cases, there is only one device per card (for
133 example, ethernet cards, modems). In other cases, there may be 114 example, ethernet cards, modems). In other cases, there may be
@@ -160,20 +141,18 @@ typedef struct local_info_t {
160 141
161 ======================================================================*/ 142 ======================================================================*/
162 143
163static dev_link_t *airo_attach(void) 144static int airo_attach(struct pcmcia_device *p_dev)
164{ 145{
165 client_reg_t client_reg;
166 dev_link_t *link; 146 dev_link_t *link;
167 local_info_t *local; 147 local_info_t *local;
168 int ret; 148
169
170 DEBUG(0, "airo_attach()\n"); 149 DEBUG(0, "airo_attach()\n");
171 150
172 /* Initialize the dev_link_t structure */ 151 /* Initialize the dev_link_t structure */
173 link = kzalloc(sizeof(struct dev_link_t), GFP_KERNEL); 152 link = kzalloc(sizeof(struct dev_link_t), GFP_KERNEL);
174 if (!link) { 153 if (!link) {
175 printk(KERN_ERR "airo_cs: no memory for new device\n"); 154 printk(KERN_ERR "airo_cs: no memory for new device\n");
176 return NULL; 155 return -ENOMEM;
177 } 156 }
178 157
179 /* Interrupt setup */ 158 /* Interrupt setup */
@@ -197,24 +176,17 @@ static dev_link_t *airo_attach(void)
197 if (!local) { 176 if (!local) {
198 printk(KERN_ERR "airo_cs: no memory for new device\n"); 177 printk(KERN_ERR "airo_cs: no memory for new device\n");
199 kfree (link); 178 kfree (link);
200 return NULL; 179 return -ENOMEM;
201 } 180 }
202 link->priv = local; 181 link->priv = local;
203 182
204 /* Register with Card Services */ 183 link->handle = p_dev;
205 link->next = dev_list; 184 p_dev->instance = link;
206 dev_list = link; 185
207 client_reg.dev_info = &dev_info; 186 link->state |= DEV_PRESENT | DEV_CONFIG_PENDING;
208 client_reg.Version = 0x0210; 187 airo_config(link);
209 client_reg.event_callback_args.client_data = link; 188
210 ret = pcmcia_register_client(&link->handle, &client_reg); 189 return 0;
211 if (ret != 0) {
212 cs_error(link->handle, RegisterClient, ret);
213 airo_detach(link);
214 return NULL;
215 }
216
217 return link;
218} /* airo_attach */ 190} /* airo_attach */
219 191
220/*====================================================================== 192/*======================================================================
@@ -226,37 +198,22 @@ static dev_link_t *airo_attach(void)
226 198
227 ======================================================================*/ 199 ======================================================================*/
228 200
229static void airo_detach(dev_link_t *link) 201static void airo_detach(struct pcmcia_device *p_dev)
230{ 202{
231 dev_link_t **linkp; 203 dev_link_t *link = dev_to_instance(p_dev);
232 204
233 DEBUG(0, "airo_detach(0x%p)\n", link); 205 DEBUG(0, "airo_detach(0x%p)\n", link);
234 206
235 /* Locate device structure */
236 for (linkp = &dev_list; *linkp; linkp = &(*linkp)->next)
237 if (*linkp == link) break;
238 if (*linkp == NULL)
239 return;
240
241 if (link->state & DEV_CONFIG) 207 if (link->state & DEV_CONFIG)
242 airo_release(link); 208 airo_release(link);
243 209
244 if ( ((local_info_t*)link->priv)->eth_dev ) { 210 if ( ((local_info_t*)link->priv)->eth_dev ) {
245 stop_airo_card( ((local_info_t*)link->priv)->eth_dev, 0 ); 211 stop_airo_card( ((local_info_t*)link->priv)->eth_dev, 0 );
246 } 212 }
247 ((local_info_t*)link->priv)->eth_dev = NULL; 213 ((local_info_t*)link->priv)->eth_dev = NULL;
248 214
249 /* Break the link with Card Services */
250 if (link->handle)
251 pcmcia_deregister_client(link->handle);
252
253
254
255 /* Unlink device structure, free pieces */
256 *linkp = link->next;
257 kfree(link->priv); 215 kfree(link->priv);
258 kfree(link); 216 kfree(link);
259
260} /* airo_detach */ 217} /* airo_detach */
261 218
262/*====================================================================== 219/*======================================================================
@@ -492,60 +449,34 @@ static void airo_release(dev_link_t *link)
492 link->state &= ~DEV_CONFIG; 449 link->state &= ~DEV_CONFIG;
493} 450}
494 451
495/*====================================================================== 452static int airo_suspend(struct pcmcia_device *p_dev)
496 453{
497 The card status event handler. Mostly, this schedules other 454 dev_link_t *link = dev_to_instance(p_dev);
498 stuff to run after an event is received. 455 local_info_t *local = link->priv;
499 456
500 When a CARD_REMOVAL event is received, we immediately set a 457 link->state |= DEV_SUSPEND;
501 private flag to block future accesses to this device. All the 458 if (link->state & DEV_CONFIG) {
502 functions that actually access the device should check this flag 459 netif_device_detach(local->eth_dev);
503 to make sure the card is still present. 460 pcmcia_release_configuration(link->handle);
504 461 }
505 ======================================================================*/ 462
463 return 0;
464}
506 465
507static int airo_event(event_t event, int priority, 466static int airo_resume(struct pcmcia_device *p_dev)
508 event_callback_args_t *args)
509{ 467{
510 dev_link_t *link = args->client_data; 468 dev_link_t *link = dev_to_instance(p_dev);
511 local_info_t *local = link->priv; 469 local_info_t *local = link->priv;
512 470
513 DEBUG(1, "airo_event(0x%06x)\n", event); 471 link->state &= ~DEV_SUSPEND;
514 472 if (link->state & DEV_CONFIG) {
515 switch (event) { 473 pcmcia_request_configuration(link->handle, &link->conf);
516 case CS_EVENT_CARD_REMOVAL: 474 reset_airo_card(local->eth_dev);
517 link->state &= ~DEV_PRESENT; 475 netif_device_attach(local->eth_dev);
518 if (link->state & DEV_CONFIG) {
519 netif_device_detach(local->eth_dev);
520 airo_release(link);
521 }
522 break;
523 case CS_EVENT_CARD_INSERTION:
524 link->state |= DEV_PRESENT | DEV_CONFIG_PENDING;
525 airo_config(link);
526 break;
527 case CS_EVENT_PM_SUSPEND:
528 link->state |= DEV_SUSPEND;
529 /* Fall through... */
530 case CS_EVENT_RESET_PHYSICAL:
531 if (link->state & DEV_CONFIG) {
532 netif_device_detach(local->eth_dev);
533 pcmcia_release_configuration(link->handle);
534 }
535 break;
536 case CS_EVENT_PM_RESUME:
537 link->state &= ~DEV_SUSPEND;
538 /* Fall through... */
539 case CS_EVENT_CARD_RESET:
540 if (link->state & DEV_CONFIG) {
541 pcmcia_request_configuration(link->handle, &link->conf);
542 reset_airo_card(local->eth_dev);
543 netif_device_attach(local->eth_dev);
544 }
545 break;
546 } 476 }
477
547 return 0; 478 return 0;
548} /* airo_event */ 479}
549 480
550static struct pcmcia_device_id airo_ids[] = { 481static struct pcmcia_device_id airo_ids[] = {
551 PCMCIA_DEVICE_MANF_CARD(0x015f, 0x000a), 482 PCMCIA_DEVICE_MANF_CARD(0x015f, 0x000a),
@@ -561,10 +492,11 @@ static struct pcmcia_driver airo_driver = {
561 .drv = { 492 .drv = {
562 .name = "airo_cs", 493 .name = "airo_cs",
563 }, 494 },
564 .attach = airo_attach, 495 .probe = airo_attach,
565 .event = airo_event, 496 .remove = airo_detach,
566 .detach = airo_detach,
567 .id_table = airo_ids, 497 .id_table = airo_ids,
498 .suspend = airo_suspend,
499 .resume = airo_resume,
568}; 500};
569 501
570static int airo_cs_init(void) 502static int airo_cs_init(void)
@@ -575,7 +507,6 @@ static int airo_cs_init(void)
575static void airo_cs_cleanup(void) 507static void airo_cs_cleanup(void)
576{ 508{
577 pcmcia_unregister_driver(&airo_driver); 509 pcmcia_unregister_driver(&airo_driver);
578 BUG_ON(dev_list != NULL);
579} 510}
580 511
581/* 512/*
diff --git a/drivers/net/wireless/atmel.c b/drivers/net/wireless/atmel.c
index 5e53c5258a33..e4729ddf29fd 100644
--- a/drivers/net/wireless/atmel.c
+++ b/drivers/net/wireless/atmel.c
@@ -5,9 +5,9 @@
5 Copyright 2000-2001 ATMEL Corporation. 5 Copyright 2000-2001 ATMEL Corporation.
6 Copyright 2003-2004 Simon Kelley. 6 Copyright 2003-2004 Simon Kelley.
7 7
8 This code was developed from version 2.1.1 of the Atmel drivers, 8 This code was developed from version 2.1.1 of the Atmel drivers,
9 released by Atmel corp. under the GPL in December 2002. It also 9 released by Atmel corp. under the GPL in December 2002. It also
10 includes code from the Linux aironet drivers (C) Benjamin Reed, 10 includes code from the Linux aironet drivers (C) Benjamin Reed,
11 and the Linux PCMCIA package, (C) David Hinds and the Linux wireless 11 and the Linux PCMCIA package, (C) David Hinds and the Linux wireless
12 extensions, (C) Jean Tourrilhes. 12 extensions, (C) Jean Tourrilhes.
13 13
@@ -31,7 +31,7 @@
31 along with Atmel wireless lan drivers; if not, write to the Free Software 31 along with Atmel wireless lan drivers; if not, write to the Free Software
32 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 32 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
33 33
34 For all queries about this code, please contact the current author, 34 For all queries about this code, please contact the current author,
35 Simon Kelley <simon@thekelleys.org.uk> and not Atmel Corporation. 35 Simon Kelley <simon@thekelleys.org.uk> and not Atmel Corporation.
36 36
37 Credit is due to HP UK and Cambridge Online Systems Ltd for supplying 37 Credit is due to HP UK and Cambridge Online Systems Ltd for supplying
@@ -79,13 +79,13 @@ MODULE_DESCRIPTION("Support for Atmel at76c50x 802.11 wireless ethernet cards.")
79MODULE_LICENSE("GPL"); 79MODULE_LICENSE("GPL");
80MODULE_SUPPORTED_DEVICE("Atmel at76c50x wireless cards"); 80MODULE_SUPPORTED_DEVICE("Atmel at76c50x wireless cards");
81 81
82/* The name of the firmware file to be loaded 82/* The name of the firmware file to be loaded
83 over-rides any automatic selection */ 83 over-rides any automatic selection */
84static char *firmware = NULL; 84static char *firmware = NULL;
85module_param(firmware, charp, 0); 85module_param(firmware, charp, 0);
86 86
87/* table of firmware file names */ 87/* table of firmware file names */
88static struct { 88static struct {
89 AtmelFWType fw_type; 89 AtmelFWType fw_type;
90 const char *fw_file; 90 const char *fw_file;
91 const char *fw_file_ext; 91 const char *fw_file_ext;
@@ -104,17 +104,17 @@ static struct {
104#define MAX_SSID_LENGTH 32 104#define MAX_SSID_LENGTH 32
105#define MGMT_JIFFIES (256 * HZ / 100) 105#define MGMT_JIFFIES (256 * HZ / 100)
106 106
107#define MAX_BSS_ENTRIES 64 107#define MAX_BSS_ENTRIES 64
108 108
109/* registers */ 109/* registers */
110#define GCR 0x00 // (SIR0) General Configuration Register 110#define GCR 0x00 // (SIR0) General Configuration Register
111#define BSR 0x02 // (SIR1) Bank Switching Select Register 111#define BSR 0x02 // (SIR1) Bank Switching Select Register
112#define AR 0x04 112#define AR 0x04
113#define DR 0x08 113#define DR 0x08
114#define MR1 0x12 // Mirror Register 1 114#define MR1 0x12 // Mirror Register 1
115#define MR2 0x14 // Mirror Register 2 115#define MR2 0x14 // Mirror Register 2
116#define MR3 0x16 // Mirror Register 3 116#define MR3 0x16 // Mirror Register 3
117#define MR4 0x18 // Mirror Register 4 117#define MR4 0x18 // Mirror Register 4
118 118
119#define GPR1 0x0c 119#define GPR1 0x0c
120#define GPR2 0x0e 120#define GPR2 0x0e
@@ -123,9 +123,9 @@ static struct {
123// Constants for the GCR register. 123// Constants for the GCR register.
124// 124//
125#define GCR_REMAP 0x0400 // Remap internal SRAM to 0 125#define GCR_REMAP 0x0400 // Remap internal SRAM to 0
126#define GCR_SWRES 0x0080 // BIU reset (ARM and PAI are NOT reset) 126#define GCR_SWRES 0x0080 // BIU reset (ARM and PAI are NOT reset)
127#define GCR_CORES 0x0060 // Core Reset (ARM and PAI are reset) 127#define GCR_CORES 0x0060 // Core Reset (ARM and PAI are reset)
128#define GCR_ENINT 0x0002 // Enable Interrupts 128#define GCR_ENINT 0x0002 // Enable Interrupts
129#define GCR_ACKINT 0x0008 // Acknowledge Interrupts 129#define GCR_ACKINT 0x0008 // Acknowledge Interrupts
130 130
131#define BSS_SRAM 0x0200 // AMBA module selection --> SRAM 131#define BSS_SRAM 0x0200 // AMBA module selection --> SRAM
@@ -190,7 +190,7 @@ struct rx_desc {
190 u32 Next; 190 u32 Next;
191 u16 MsduPos; 191 u16 MsduPos;
192 u16 MsduSize; 192 u16 MsduSize;
193 193
194 u8 State; 194 u8 State;
195 u8 Status; 195 u8 Status;
196 u8 Rate; 196 u8 Rate;
@@ -199,7 +199,6 @@ struct rx_desc {
199 u8 PreambleType; 199 u8 PreambleType;
200 u16 Duration; 200 u16 Duration;
201 u32 RxTime; 201 u32 RxTime;
202
203}; 202};
204 203
205#define RX_DESC_FLAG_VALID 0x80 204#define RX_DESC_FLAG_VALID 0x80
@@ -218,16 +217,15 @@ struct rx_desc {
218#define RX_DESC_DURATION_OFFSET 14 217#define RX_DESC_DURATION_OFFSET 14
219#define RX_DESC_RX_TIME_OFFSET 16 218#define RX_DESC_RX_TIME_OFFSET 16
220 219
221
222struct tx_desc { 220struct tx_desc {
223 u32 NextDescriptor; 221 u32 NextDescriptor;
224 u16 TxStartOfFrame; 222 u16 TxStartOfFrame;
225 u16 TxLength; 223 u16 TxLength;
226 224
227 u8 TxState; 225 u8 TxState;
228 u8 TxStatus; 226 u8 TxStatus;
229 u8 RetryCount; 227 u8 RetryCount;
230 228
231 u8 TxRate; 229 u8 TxRate;
232 230
233 u8 KeyIndex; 231 u8 KeyIndex;
@@ -238,10 +236,8 @@ struct tx_desc {
238 u8 Reserved; 236 u8 Reserved;
239 u8 PacketType; 237 u8 PacketType;
240 u16 HostTxLength; 238 u16 HostTxLength;
241
242}; 239};
243 240
244
245#define TX_DESC_NEXT_OFFSET 0 241#define TX_DESC_NEXT_OFFSET 0
246#define TX_DESC_POS_OFFSET 4 242#define TX_DESC_POS_OFFSET 4
247#define TX_DESC_SIZE_OFFSET 6 243#define TX_DESC_SIZE_OFFSET 6
@@ -255,8 +251,6 @@ struct tx_desc {
255#define TX_DESC_PACKET_TYPE_OFFSET 17 251#define TX_DESC_PACKET_TYPE_OFFSET 17
256#define TX_DESC_HOST_LENGTH_OFFSET 18 252#define TX_DESC_HOST_LENGTH_OFFSET 18
257 253
258
259
260/////////////////////////////////////////////////////// 254///////////////////////////////////////////////////////
261// Host-MAC interface 255// Host-MAC interface
262/////////////////////////////////////////////////////// 256///////////////////////////////////////////////////////
@@ -266,7 +260,6 @@ struct tx_desc {
266#define TX_FIRM_OWN 0x80 260#define TX_FIRM_OWN 0x80
267#define TX_DONE 0x40 261#define TX_DONE 0x40
268 262
269
270#define TX_ERROR 0x01 263#define TX_ERROR 0x01
271 264
272#define TX_PACKET_TYPE_DATA 0x01 265#define TX_PACKET_TYPE_DATA 0x01
@@ -280,8 +273,7 @@ struct tx_desc {
280#define ISR_COMMAND_COMPLETE 0x10 // command completed 273#define ISR_COMMAND_COMPLETE 0x10 // command completed
281#define ISR_OUT_OF_RANGE 0x20 // command completed 274#define ISR_OUT_OF_RANGE 0x20 // command completed
282#define ISR_IBSS_MERGE 0x40 // (4.1.2.30): IBSS merge 275#define ISR_IBSS_MERGE 0x40 // (4.1.2.30): IBSS merge
283#define ISR_GENERIC_IRQ 0x80 276#define ISR_GENERIC_IRQ 0x80
284
285 277
286#define Local_Mib_Type 0x01 278#define Local_Mib_Type 0x01
287#define Mac_Address_Mib_Type 0x02 279#define Mac_Address_Mib_Type 0x02
@@ -317,7 +309,6 @@ struct tx_desc {
317#define LOCAL_MIB_PREAMBLE_TYPE 9 309#define LOCAL_MIB_PREAMBLE_TYPE 9
318#define MAC_ADDR_MIB_MAC_ADDR_POS 0 310#define MAC_ADDR_MIB_MAC_ADDR_POS 0
319 311
320
321#define CMD_Set_MIB_Vars 0x01 312#define CMD_Set_MIB_Vars 0x01
322#define CMD_Get_MIB_Vars 0x02 313#define CMD_Get_MIB_Vars 0x02
323#define CMD_Scan 0x03 314#define CMD_Scan 0x03
@@ -338,7 +329,6 @@ struct tx_desc {
338#define CMD_STATUS_HOST_ERROR 0xFF 329#define CMD_STATUS_HOST_ERROR 0xFF
339#define CMD_STATUS_BUSY 0xFE 330#define CMD_STATUS_BUSY 0xFE
340 331
341
342#define CMD_BLOCK_COMMAND_OFFSET 0 332#define CMD_BLOCK_COMMAND_OFFSET 0
343#define CMD_BLOCK_STATUS_OFFSET 1 333#define CMD_BLOCK_STATUS_OFFSET 1
344#define CMD_BLOCK_PARAMETERS_OFFSET 4 334#define CMD_BLOCK_PARAMETERS_OFFSET 4
@@ -347,15 +337,15 @@ struct tx_desc {
347 337
348#define MGMT_FRAME_BODY_OFFSET 24 338#define MGMT_FRAME_BODY_OFFSET 24
349#define MAX_AUTHENTICATION_RETRIES 3 339#define MAX_AUTHENTICATION_RETRIES 3
350#define MAX_ASSOCIATION_RETRIES 3 340#define MAX_ASSOCIATION_RETRIES 3
351 341
352#define AUTHENTICATION_RESPONSE_TIME_OUT 1000 342#define AUTHENTICATION_RESPONSE_TIME_OUT 1000
353 343
354#define MAX_WIRELESS_BODY 2316 /* mtu is 2312, CRC is 4 */ 344#define MAX_WIRELESS_BODY 2316 /* mtu is 2312, CRC is 4 */
355#define LOOP_RETRY_LIMIT 500000 345#define LOOP_RETRY_LIMIT 500000
356 346
357#define ACTIVE_MODE 1 347#define ACTIVE_MODE 1
358#define PS_MODE 2 348#define PS_MODE 2
359 349
360#define MAX_ENCRYPTION_KEYS 4 350#define MAX_ENCRYPTION_KEYS 4
361#define MAX_ENCRYPTION_KEY_SIZE 40 351#define MAX_ENCRYPTION_KEY_SIZE 40
@@ -377,7 +367,7 @@ struct tx_desc {
377#define REG_DOMAIN_MKK1 0x41 //Channel 1-14 Japan(MKK1) 367#define REG_DOMAIN_MKK1 0x41 //Channel 1-14 Japan(MKK1)
378#define REG_DOMAIN_ISRAEL 0x50 //Channel 3-9 ISRAEL 368#define REG_DOMAIN_ISRAEL 0x50 //Channel 3-9 ISRAEL
379 369
380#define BSS_TYPE_AD_HOC 1 370#define BSS_TYPE_AD_HOC 1
381#define BSS_TYPE_INFRASTRUCTURE 2 371#define BSS_TYPE_INFRASTRUCTURE 2
382 372
383#define SCAN_TYPE_ACTIVE 0 373#define SCAN_TYPE_ACTIVE 0
@@ -389,7 +379,7 @@ struct tx_desc {
389 379
390#define DATA_FRAME_WS_HEADER_SIZE 30 380#define DATA_FRAME_WS_HEADER_SIZE 30
391 381
392/* promiscuous mode control */ 382/* promiscuous mode control */
393#define PROM_MODE_OFF 0x0 383#define PROM_MODE_OFF 0x0
394#define PROM_MODE_UNKNOWN 0x1 384#define PROM_MODE_UNKNOWN 0x1
395#define PROM_MODE_CRC_FAILED 0x2 385#define PROM_MODE_CRC_FAILED 0x2
@@ -398,8 +388,7 @@ struct tx_desc {
398#define PROM_MODE_CTRL 0x10 388#define PROM_MODE_CTRL 0x10
399#define PROM_MODE_BAD_PROTOCOL 0x20 389#define PROM_MODE_BAD_PROTOCOL 0x20
400 390
401 391#define IFACE_INT_STATUS_OFFSET 0
402#define IFACE_INT_STATUS_OFFSET 0
403#define IFACE_INT_MASK_OFFSET 1 392#define IFACE_INT_MASK_OFFSET 1
404#define IFACE_LOCKOUT_HOST_OFFSET 2 393#define IFACE_LOCKOUT_HOST_OFFSET 2
405#define IFACE_LOCKOUT_MAC_OFFSET 3 394#define IFACE_LOCKOUT_MAC_OFFSET 3
@@ -407,7 +396,7 @@ struct tx_desc {
407#define IFACE_MAC_STAT_OFFSET 30 396#define IFACE_MAC_STAT_OFFSET 30
408#define IFACE_GENERIC_INT_TYPE_OFFSET 32 397#define IFACE_GENERIC_INT_TYPE_OFFSET 32
409 398
410#define CIPHER_SUITE_NONE 0 399#define CIPHER_SUITE_NONE 0
411#define CIPHER_SUITE_WEP_64 1 400#define CIPHER_SUITE_WEP_64 1
412#define CIPHER_SUITE_TKIP 2 401#define CIPHER_SUITE_TKIP 2
413#define CIPHER_SUITE_AES 3 402#define CIPHER_SUITE_AES 3
@@ -419,11 +408,11 @@ struct tx_desc {
419// 408//
420// 409//
421 410
422// FuncCtrl field: 411// FuncCtrl field:
423// 412//
424#define FUNC_CTRL_TxENABLE 0x10 413#define FUNC_CTRL_TxENABLE 0x10
425#define FUNC_CTRL_RxENABLE 0x20 414#define FUNC_CTRL_RxENABLE 0x20
426#define FUNC_CTRL_INIT_COMPLETE 0x01 415#define FUNC_CTRL_INIT_COMPLETE 0x01
427 416
428/* A stub firmware image which reads the MAC address from NVRAM on the card. 417/* A stub firmware image which reads the MAC address from NVRAM on the card.
429 For copyright information and source see the end of this file. */ 418 For copyright information and source see the end of this file. */
@@ -486,10 +475,10 @@ struct atmel_private {
486 struct net_device_stats stats; // device stats 475 struct net_device_stats stats; // device stats
487 spinlock_t irqlock, timerlock; // spinlocks 476 spinlock_t irqlock, timerlock; // spinlocks
488 enum { BUS_TYPE_PCCARD, BUS_TYPE_PCI } bus_type; 477 enum { BUS_TYPE_PCCARD, BUS_TYPE_PCI } bus_type;
489 enum { 478 enum {
490 CARD_TYPE_PARALLEL_FLASH, 479 CARD_TYPE_PARALLEL_FLASH,
491 CARD_TYPE_SPI_FLASH, 480 CARD_TYPE_SPI_FLASH,
492 CARD_TYPE_EEPROM 481 CARD_TYPE_EEPROM
493 } card_type; 482 } card_type;
494 int do_rx_crc; /* If we need to CRC incoming packets */ 483 int do_rx_crc; /* If we need to CRC incoming packets */
495 int probe_crc; /* set if we don't yet know */ 484 int probe_crc; /* set if we don't yet know */
@@ -497,18 +486,18 @@ struct atmel_private {
497 u16 rx_desc_head; 486 u16 rx_desc_head;
498 u16 tx_desc_free, tx_desc_head, tx_desc_tail, tx_desc_previous; 487 u16 tx_desc_free, tx_desc_head, tx_desc_tail, tx_desc_previous;
499 u16 tx_free_mem, tx_buff_head, tx_buff_tail; 488 u16 tx_free_mem, tx_buff_head, tx_buff_tail;
500 489
501 u16 frag_seq, frag_len, frag_no; 490 u16 frag_seq, frag_len, frag_no;
502 u8 frag_source[6]; 491 u8 frag_source[6];
503 492
504 u8 wep_is_on, default_key, exclude_unencrypted, encryption_level; 493 u8 wep_is_on, default_key, exclude_unencrypted, encryption_level;
505 u8 group_cipher_suite, pairwise_cipher_suite; 494 u8 group_cipher_suite, pairwise_cipher_suite;
506 u8 wep_keys[MAX_ENCRYPTION_KEYS][MAX_ENCRYPTION_KEY_SIZE]; 495 u8 wep_keys[MAX_ENCRYPTION_KEYS][MAX_ENCRYPTION_KEY_SIZE];
507 int wep_key_len[MAX_ENCRYPTION_KEYS]; 496 int wep_key_len[MAX_ENCRYPTION_KEYS];
508 int use_wpa, radio_on_broken; /* firmware dependent stuff. */ 497 int use_wpa, radio_on_broken; /* firmware dependent stuff. */
509 498
510 u16 host_info_base; 499 u16 host_info_base;
511 struct host_info_struct { 500 struct host_info_struct {
512 /* NB this is matched to the hardware, don't change. */ 501 /* NB this is matched to the hardware, don't change. */
513 u8 volatile int_status; 502 u8 volatile int_status;
514 u8 volatile int_mask; 503 u8 volatile int_mask;
@@ -524,20 +513,20 @@ struct atmel_private {
524 u16 rx_buff_size; 513 u16 rx_buff_size;
525 u16 rx_desc_pos; 514 u16 rx_desc_pos;
526 u16 rx_desc_count; 515 u16 rx_desc_count;
527 516
528 u16 build_version; 517 u16 build_version;
529 u16 command_pos; 518 u16 command_pos;
530 519
531 u16 major_version; 520 u16 major_version;
532 u16 minor_version; 521 u16 minor_version;
533 522
534 u16 func_ctrl; 523 u16 func_ctrl;
535 u16 mac_status; 524 u16 mac_status;
536 u16 generic_IRQ_type; 525 u16 generic_IRQ_type;
537 u8 reserved[2]; 526 u8 reserved[2];
538 } host_info; 527 } host_info;
539 528
540 enum { 529 enum {
541 STATION_STATE_SCANNING, 530 STATION_STATE_SCANNING,
542 STATION_STATE_JOINNING, 531 STATION_STATE_JOINNING,
543 STATION_STATE_AUTHENTICATING, 532 STATION_STATE_AUTHENTICATING,
@@ -547,7 +536,7 @@ struct atmel_private {
547 STATION_STATE_DOWN, 536 STATION_STATE_DOWN,
548 STATION_STATE_MGMT_ERROR 537 STATION_STATE_MGMT_ERROR
549 } station_state; 538 } station_state;
550 539
551 int operating_mode, power_mode; 540 int operating_mode, power_mode;
552 time_t last_qual; 541 time_t last_qual;
553 int beacons_this_sec; 542 int beacons_this_sec;
@@ -560,18 +549,18 @@ struct atmel_private {
560 int long_retry, short_retry; 549 int long_retry, short_retry;
561 int preamble; 550 int preamble;
562 int default_beacon_period, beacon_period, listen_interval; 551 int default_beacon_period, beacon_period, listen_interval;
563 int CurrentAuthentTransactionSeqNum, ExpectedAuthentTransactionSeqNum; 552 int CurrentAuthentTransactionSeqNum, ExpectedAuthentTransactionSeqNum;
564 int AuthenticationRequestRetryCnt, AssociationRequestRetryCnt, ReAssociationRequestRetryCnt; 553 int AuthenticationRequestRetryCnt, AssociationRequestRetryCnt, ReAssociationRequestRetryCnt;
565 enum { 554 enum {
566 SITE_SURVEY_IDLE, 555 SITE_SURVEY_IDLE,
567 SITE_SURVEY_IN_PROGRESS, 556 SITE_SURVEY_IN_PROGRESS,
568 SITE_SURVEY_COMPLETED 557 SITE_SURVEY_COMPLETED
569 } site_survey_state; 558 } site_survey_state;
570 time_t last_survey; 559 time_t last_survey;
571 560
572 int station_was_associated, station_is_associated; 561 int station_was_associated, station_is_associated;
573 int fast_scan; 562 int fast_scan;
574 563
575 struct bss_info { 564 struct bss_info {
576 int channel; 565 int channel;
577 int SSIDsize; 566 int SSIDsize;
@@ -584,13 +573,12 @@ struct atmel_private {
584 u8 SSID[MAX_SSID_LENGTH]; 573 u8 SSID[MAX_SSID_LENGTH];
585 } BSSinfo[MAX_BSS_ENTRIES]; 574 } BSSinfo[MAX_BSS_ENTRIES];
586 int BSS_list_entries, current_BSS; 575 int BSS_list_entries, current_BSS;
587 int connect_to_any_BSS; 576 int connect_to_any_BSS;
588 int SSID_size, new_SSID_size; 577 int SSID_size, new_SSID_size;
589 u8 CurrentBSSID[6], BSSID[6]; 578 u8 CurrentBSSID[6], BSSID[6];
590 u8 SSID[MAX_SSID_LENGTH], new_SSID[MAX_SSID_LENGTH]; 579 u8 SSID[MAX_SSID_LENGTH], new_SSID[MAX_SSID_LENGTH];
591 u64 last_beacon_timestamp; 580 u64 last_beacon_timestamp;
592 u8 rx_buf[MAX_WIRELESS_BODY]; 581 u8 rx_buf[MAX_WIRELESS_BODY];
593
594}; 582};
595 583
596static u8 atmel_basic_rates[4] = {0x82,0x84,0x0b,0x16}; 584static u8 atmel_basic_rates[4] = {0x82,0x84,0x0b,0x16};
@@ -598,39 +586,49 @@ static u8 atmel_basic_rates[4] = {0x82,0x84,0x0b,0x16};
598static const struct { 586static const struct {
599 int reg_domain; 587 int reg_domain;
600 int min, max; 588 int min, max;
601 char *name; 589 char *name;
602} channel_table[] = { { REG_DOMAIN_FCC, 1, 11, "USA" }, 590} channel_table[] = { { REG_DOMAIN_FCC, 1, 11, "USA" },
603 { REG_DOMAIN_DOC, 1, 11, "Canada" }, 591 { REG_DOMAIN_DOC, 1, 11, "Canada" },
604 { REG_DOMAIN_ETSI, 1, 13, "Europe" }, 592 { REG_DOMAIN_ETSI, 1, 13, "Europe" },
605 { REG_DOMAIN_SPAIN, 10, 11, "Spain" }, 593 { REG_DOMAIN_SPAIN, 10, 11, "Spain" },
606 { REG_DOMAIN_FRANCE, 10, 13, "France" }, 594 { REG_DOMAIN_FRANCE, 10, 13, "France" },
607 { REG_DOMAIN_MKK, 14, 14, "MKK" }, 595 { REG_DOMAIN_MKK, 14, 14, "MKK" },
608 { REG_DOMAIN_MKK1, 1, 14, "MKK1" }, 596 { REG_DOMAIN_MKK1, 1, 14, "MKK1" },
609 { REG_DOMAIN_ISRAEL, 3, 9, "Israel"} }; 597 { REG_DOMAIN_ISRAEL, 3, 9, "Israel"} };
610 598
611static void build_wpa_mib(struct atmel_private *priv); 599static void build_wpa_mib(struct atmel_private *priv);
612static int atmel_ioctl(struct net_device *dev, struct ifreq *rq, int cmd); 600static int atmel_ioctl(struct net_device *dev, struct ifreq *rq, int cmd);
613static void atmel_copy_to_card(struct net_device *dev, u16 dest, unsigned char *src, u16 len); 601static void atmel_copy_to_card(struct net_device *dev, u16 dest,
614static void atmel_copy_to_host(struct net_device *dev, unsigned char *dest, u16 src, u16 len); 602 unsigned char *src, u16 len);
603static void atmel_copy_to_host(struct net_device *dev, unsigned char *dest,
604 u16 src, u16 len);
615static void atmel_set_gcr(struct net_device *dev, u16 mask); 605static void atmel_set_gcr(struct net_device *dev, u16 mask);
616static void atmel_clear_gcr(struct net_device *dev, u16 mask); 606static void atmel_clear_gcr(struct net_device *dev, u16 mask);
617static int atmel_lock_mac(struct atmel_private *priv); 607static int atmel_lock_mac(struct atmel_private *priv);
618static void atmel_wmem32(struct atmel_private *priv, u16 pos, u32 data); 608static void atmel_wmem32(struct atmel_private *priv, u16 pos, u32 data);
619static void atmel_command_irq(struct atmel_private *priv); 609static void atmel_command_irq(struct atmel_private *priv);
620static int atmel_validate_channel(struct atmel_private *priv, int channel); 610static int atmel_validate_channel(struct atmel_private *priv, int channel);
621static void atmel_management_frame(struct atmel_private *priv, struct ieee80211_hdr_4addr *header, 611static void atmel_management_frame(struct atmel_private *priv,
612 struct ieee80211_hdr_4addr *header,
622 u16 frame_len, u8 rssi); 613 u16 frame_len, u8 rssi);
623static void atmel_management_timer(u_long a); 614static void atmel_management_timer(u_long a);
624static void atmel_send_command(struct atmel_private *priv, int command, void *cmd, int cmd_size); 615static void atmel_send_command(struct atmel_private *priv, int command,
625static int atmel_send_command_wait(struct atmel_private *priv, int command, void *cmd, int cmd_size); 616 void *cmd, int cmd_size);
626static void atmel_transmit_management_frame(struct atmel_private *priv, struct ieee80211_hdr_4addr *header, 617static int atmel_send_command_wait(struct atmel_private *priv, int command,
618 void *cmd, int cmd_size);
619static void atmel_transmit_management_frame(struct atmel_private *priv,
620 struct ieee80211_hdr_4addr *header,
627 u8 *body, int body_len); 621 u8 *body, int body_len);
628 622
629static u8 atmel_get_mib8(struct atmel_private *priv, u8 type, u8 index); 623static u8 atmel_get_mib8(struct atmel_private *priv, u8 type, u8 index);
630static void atmel_set_mib8(struct atmel_private *priv, u8 type, u8 index, u8 data); 624static void atmel_set_mib8(struct atmel_private *priv, u8 type, u8 index,
631static void atmel_set_mib16(struct atmel_private *priv, u8 type, u8 index, u16 data); 625 u8 data);
632static void atmel_set_mib(struct atmel_private *priv, u8 type, u8 index, u8 *data, int data_len); 626static void atmel_set_mib16(struct atmel_private *priv, u8 type, u8 index,
633static void atmel_get_mib(struct atmel_private *priv, u8 type, u8 index, u8 *data, int data_len); 627 u16 data);
628static void atmel_set_mib(struct atmel_private *priv, u8 type, u8 index,
629 u8 *data, int data_len);
630static void atmel_get_mib(struct atmel_private *priv, u8 type, u8 index,
631 u8 *data, int data_len);
634static void atmel_scan(struct atmel_private *priv, int specific_ssid); 632static void atmel_scan(struct atmel_private *priv, int specific_ssid);
635static void atmel_join_bss(struct atmel_private *priv, int bss_index); 633static void atmel_join_bss(struct atmel_private *priv, int bss_index);
636static void atmel_smooth_qual(struct atmel_private *priv); 634static void atmel_smooth_qual(struct atmel_private *priv);
@@ -650,12 +648,12 @@ static inline u16 atmel_co(struct atmel_private *priv, u16 offset)
650 return priv->host_info.command_pos + offset; 648 return priv->host_info.command_pos + offset;
651} 649}
652 650
653static inline u16 atmel_rx(struct atmel_private *priv, u16 offset, u16 desc) 651static inline u16 atmel_rx(struct atmel_private *priv, u16 offset, u16 desc)
654{ 652{
655 return priv->host_info.rx_desc_pos + (sizeof(struct rx_desc) * desc) + offset; 653 return priv->host_info.rx_desc_pos + (sizeof(struct rx_desc) * desc) + offset;
656} 654}
657 655
658static inline u16 atmel_tx(struct atmel_private *priv, u16 offset, u16 desc) 656static inline u16 atmel_tx(struct atmel_private *priv, u16 offset, u16 desc)
659{ 657{
660 return priv->host_info.tx_desc_pos + (sizeof(struct tx_desc) * desc) + offset; 658 return priv->host_info.tx_desc_pos + (sizeof(struct tx_desc) * desc) + offset;
661} 659}
@@ -682,25 +680,25 @@ static inline void atmel_write16(struct net_device *dev, u16 offset, u16 data)
682 680
683static inline u8 atmel_rmem8(struct atmel_private *priv, u16 pos) 681static inline u8 atmel_rmem8(struct atmel_private *priv, u16 pos)
684{ 682{
685 atmel_writeAR(priv->dev, pos); 683 atmel_writeAR(priv->dev, pos);
686 return atmel_read8(priv->dev, DR); 684 return atmel_read8(priv->dev, DR);
687} 685}
688 686
689static inline void atmel_wmem8(struct atmel_private *priv, u16 pos, u16 data) 687static inline void atmel_wmem8(struct atmel_private *priv, u16 pos, u16 data)
690{ 688{
691 atmel_writeAR(priv->dev, pos); 689 atmel_writeAR(priv->dev, pos);
692 atmel_write8(priv->dev, DR, data); 690 atmel_write8(priv->dev, DR, data);
693} 691}
694 692
695static inline u16 atmel_rmem16(struct atmel_private *priv, u16 pos) 693static inline u16 atmel_rmem16(struct atmel_private *priv, u16 pos)
696{ 694{
697 atmel_writeAR(priv->dev, pos); 695 atmel_writeAR(priv->dev, pos);
698 return atmel_read16(priv->dev, DR); 696 return atmel_read16(priv->dev, DR);
699} 697}
700 698
701static inline void atmel_wmem16(struct atmel_private *priv, u16 pos, u16 data) 699static inline void atmel_wmem16(struct atmel_private *priv, u16 pos, u16 data)
702{ 700{
703 atmel_writeAR(priv->dev, pos); 701 atmel_writeAR(priv->dev, pos);
704 atmel_write16(priv->dev, DR, data); 702 atmel_write16(priv->dev, DR, data);
705} 703}
706 704
@@ -710,11 +708,10 @@ static void tx_done_irq(struct atmel_private *priv)
710{ 708{
711 int i; 709 int i;
712 710
713 for (i = 0; 711 for (i = 0;
714 atmel_rmem8(priv, atmel_tx(priv, TX_DESC_FLAGS_OFFSET, priv->tx_desc_head)) == TX_DONE && 712 atmel_rmem8(priv, atmel_tx(priv, TX_DESC_FLAGS_OFFSET, priv->tx_desc_head)) == TX_DONE &&
715 i < priv->host_info.tx_desc_count; 713 i < priv->host_info.tx_desc_count;
716 i++) { 714 i++) {
717
718 u8 status = atmel_rmem8(priv, atmel_tx(priv, TX_DESC_STATUS_OFFSET, priv->tx_desc_head)); 715 u8 status = atmel_rmem8(priv, atmel_tx(priv, TX_DESC_STATUS_OFFSET, priv->tx_desc_head));
719 u16 msdu_size = atmel_rmem16(priv, atmel_tx(priv, TX_DESC_SIZE_OFFSET, priv->tx_desc_head)); 716 u16 msdu_size = atmel_rmem16(priv, atmel_tx(priv, TX_DESC_SIZE_OFFSET, priv->tx_desc_head));
720 u8 type = atmel_rmem8(priv, atmel_tx(priv, TX_DESC_PACKET_TYPE_OFFSET, priv->tx_desc_head)); 717 u8 type = atmel_rmem8(priv, atmel_tx(priv, TX_DESC_PACKET_TYPE_OFFSET, priv->tx_desc_head));
@@ -728,16 +725,16 @@ static void tx_done_irq(struct atmel_private *priv)
728 priv->tx_buff_head = 0; 725 priv->tx_buff_head = 0;
729 else 726 else
730 priv->tx_buff_head += msdu_size; 727 priv->tx_buff_head += msdu_size;
731 728
732 if (priv->tx_desc_head < (priv->host_info.tx_desc_count - 1)) 729 if (priv->tx_desc_head < (priv->host_info.tx_desc_count - 1))
733 priv->tx_desc_head++ ; 730 priv->tx_desc_head++ ;
734 else 731 else
735 priv->tx_desc_head = 0; 732 priv->tx_desc_head = 0;
736 733
737 if (type == TX_PACKET_TYPE_DATA) { 734 if (type == TX_PACKET_TYPE_DATA) {
738 if (status == TX_STATUS_SUCCESS) 735 if (status == TX_STATUS_SUCCESS)
739 priv->stats.tx_packets++; 736 priv->stats.tx_packets++;
740 else 737 else
741 priv->stats.tx_errors++; 738 priv->stats.tx_errors++;
742 netif_wake_queue(priv->dev); 739 netif_wake_queue(priv->dev);
743 } 740 }
@@ -748,21 +745,22 @@ static u16 find_tx_buff(struct atmel_private *priv, u16 len)
748{ 745{
749 u16 bottom_free = priv->host_info.tx_buff_size - priv->tx_buff_tail; 746 u16 bottom_free = priv->host_info.tx_buff_size - priv->tx_buff_tail;
750 747
751 if (priv->tx_desc_free == 3 || priv->tx_free_mem < len) 748 if (priv->tx_desc_free == 3 || priv->tx_free_mem < len)
752 return 0; 749 return 0;
753 750
754 if (bottom_free >= len) 751 if (bottom_free >= len)
755 return priv->host_info.tx_buff_pos + priv->tx_buff_tail; 752 return priv->host_info.tx_buff_pos + priv->tx_buff_tail;
756 753
757 if (priv->tx_free_mem - bottom_free >= len) { 754 if (priv->tx_free_mem - bottom_free >= len) {
758 priv->tx_buff_tail = 0; 755 priv->tx_buff_tail = 0;
759 return priv->host_info.tx_buff_pos; 756 return priv->host_info.tx_buff_pos;
760 } 757 }
761 758
762 return 0; 759 return 0;
763} 760}
764 761
765static void tx_update_descriptor(struct atmel_private *priv, int is_bcast, u16 len, u16 buff, u8 type) 762static void tx_update_descriptor(struct atmel_private *priv, int is_bcast,
763 u16 len, u16 buff, u8 type)
766{ 764{
767 atmel_wmem16(priv, atmel_tx(priv, TX_DESC_POS_OFFSET, priv->tx_desc_tail), buff); 765 atmel_wmem16(priv, atmel_tx(priv, TX_DESC_POS_OFFSET, priv->tx_desc_tail), buff);
768 atmel_wmem16(priv, atmel_tx(priv, TX_DESC_SIZE_OFFSET, priv->tx_desc_tail), len); 766 atmel_wmem16(priv, atmel_tx(priv, TX_DESC_SIZE_OFFSET, priv->tx_desc_tail), len);
@@ -775,8 +773,8 @@ static void tx_update_descriptor(struct atmel_private *priv, int is_bcast, u16 l
775 int cipher_type, cipher_length; 773 int cipher_type, cipher_length;
776 if (is_bcast) { 774 if (is_bcast) {
777 cipher_type = priv->group_cipher_suite; 775 cipher_type = priv->group_cipher_suite;
778 if (cipher_type == CIPHER_SUITE_WEP_64 || 776 if (cipher_type == CIPHER_SUITE_WEP_64 ||
779 cipher_type == CIPHER_SUITE_WEP_128 ) 777 cipher_type == CIPHER_SUITE_WEP_128)
780 cipher_length = 8; 778 cipher_length = 8;
781 else if (cipher_type == CIPHER_SUITE_TKIP) 779 else if (cipher_type == CIPHER_SUITE_TKIP)
782 cipher_length = 12; 780 cipher_length = 12;
@@ -790,8 +788,8 @@ static void tx_update_descriptor(struct atmel_private *priv, int is_bcast, u16 l
790 } 788 }
791 } else { 789 } else {
792 cipher_type = priv->pairwise_cipher_suite; 790 cipher_type = priv->pairwise_cipher_suite;
793 if (cipher_type == CIPHER_SUITE_WEP_64 || 791 if (cipher_type == CIPHER_SUITE_WEP_64 ||
794 cipher_type == CIPHER_SUITE_WEP_128 ) 792 cipher_type == CIPHER_SUITE_WEP_128)
795 cipher_length = 8; 793 cipher_length = 8;
796 else if (cipher_type == CIPHER_SUITE_TKIP) 794 else if (cipher_type == CIPHER_SUITE_TKIP)
797 cipher_length = 12; 795 cipher_length = 12;
@@ -804,9 +802,9 @@ static void tx_update_descriptor(struct atmel_private *priv, int is_bcast, u16 l
804 cipher_length = 0; 802 cipher_length = 0;
805 } 803 }
806 } 804 }
807 805
808 atmel_wmem8(priv, atmel_tx(priv, TX_DESC_CIPHER_TYPE_OFFSET, priv->tx_desc_tail), 806 atmel_wmem8(priv, atmel_tx(priv, TX_DESC_CIPHER_TYPE_OFFSET, priv->tx_desc_tail),
809 cipher_type); 807 cipher_type);
810 atmel_wmem8(priv, atmel_tx(priv, TX_DESC_CIPHER_LENGTH_OFFSET, priv->tx_desc_tail), 808 atmel_wmem8(priv, atmel_tx(priv, TX_DESC_CIPHER_LENGTH_OFFSET, priv->tx_desc_tail),
811 cipher_length); 809 cipher_length);
812 } 810 }
@@ -815,46 +813,46 @@ static void tx_update_descriptor(struct atmel_private *priv, int is_bcast, u16 l
815 if (priv->tx_desc_previous != priv->tx_desc_tail) 813 if (priv->tx_desc_previous != priv->tx_desc_tail)
816 atmel_wmem32(priv, atmel_tx(priv, TX_DESC_NEXT_OFFSET, priv->tx_desc_previous), 0); 814 atmel_wmem32(priv, atmel_tx(priv, TX_DESC_NEXT_OFFSET, priv->tx_desc_previous), 0);
817 priv->tx_desc_previous = priv->tx_desc_tail; 815 priv->tx_desc_previous = priv->tx_desc_tail;
818 if (priv->tx_desc_tail < (priv->host_info.tx_desc_count -1 )) 816 if (priv->tx_desc_tail < (priv->host_info.tx_desc_count - 1))
819 priv->tx_desc_tail++; 817 priv->tx_desc_tail++;
820 else 818 else
821 priv->tx_desc_tail = 0; 819 priv->tx_desc_tail = 0;
822 priv->tx_desc_free--; 820 priv->tx_desc_free--;
823 priv->tx_free_mem -= len; 821 priv->tx_free_mem -= len;
824
825} 822}
826 823
827static int start_tx (struct sk_buff *skb, struct net_device *dev) 824static int start_tx(struct sk_buff *skb, struct net_device *dev)
828{ 825{
829 struct atmel_private *priv = netdev_priv(dev); 826 struct atmel_private *priv = netdev_priv(dev);
830 struct ieee80211_hdr_4addr header; 827 struct ieee80211_hdr_4addr header;
831 unsigned long flags; 828 unsigned long flags;
832 u16 buff, frame_ctl, len = (ETH_ZLEN < skb->len) ? skb->len : ETH_ZLEN; 829 u16 buff, frame_ctl, len = (ETH_ZLEN < skb->len) ? skb->len : ETH_ZLEN;
833 u8 SNAP_RFC1024[6] = {0xaa, 0xaa, 0x03, 0x00, 0x00, 0x00}; 830 u8 SNAP_RFC1024[6] = {0xaa, 0xaa, 0x03, 0x00, 0x00, 0x00};
834 831
835 if (priv->card && priv->present_callback && 832 if (priv->card && priv->present_callback &&
836 !(*priv->present_callback)(priv->card)) { 833 !(*priv->present_callback)(priv->card)) {
837 priv->stats.tx_errors++; 834 priv->stats.tx_errors++;
838 dev_kfree_skb(skb); 835 dev_kfree_skb(skb);
839 return 0; 836 return 0;
840 } 837 }
841 838
842 if (priv->station_state != STATION_STATE_READY) { 839 if (priv->station_state != STATION_STATE_READY) {
843 priv->stats.tx_errors++; 840 priv->stats.tx_errors++;
844 dev_kfree_skb(skb); 841 dev_kfree_skb(skb);
845 return 0; 842 return 0;
846 } 843 }
847 844
848 /* first ensure the timer func cannot run */ 845 /* first ensure the timer func cannot run */
849 spin_lock_bh(&priv->timerlock); 846 spin_lock_bh(&priv->timerlock);
850 /* then stop the hardware ISR */ 847 /* then stop the hardware ISR */
851 spin_lock_irqsave(&priv->irqlock, flags); 848 spin_lock_irqsave(&priv->irqlock, flags);
852 /* nb doing the above in the opposite order will deadlock */ 849 /* nb doing the above in the opposite order will deadlock */
853 850
854 /* The Wireless Header is 30 bytes. In the Ethernet packet we "cut" the 851 /* The Wireless Header is 30 bytes. In the Ethernet packet we "cut" the
855 12 first bytes (containing DA/SA) and put them in the appropriate fields of 852 12 first bytes (containing DA/SA) and put them in the appropriate
856 the Wireless Header. Thus the packet length is then the initial + 18 (+30-12) */ 853 fields of the Wireless Header. Thus the packet length is then the
857 854 initial + 18 (+30-12) */
855
858 if (!(buff = find_tx_buff(priv, len + 18))) { 856 if (!(buff = find_tx_buff(priv, len + 18))) {
859 priv->stats.tx_dropped++; 857 priv->stats.tx_dropped++;
860 spin_unlock_irqrestore(&priv->irqlock, flags); 858 spin_unlock_irqrestore(&priv->irqlock, flags);
@@ -862,7 +860,7 @@ static int start_tx (struct sk_buff *skb, struct net_device *dev)
862 netif_stop_queue(dev); 860 netif_stop_queue(dev);
863 return 1; 861 return 1;
864 } 862 }
865 863
866 frame_ctl = IEEE80211_FTYPE_DATA; 864 frame_ctl = IEEE80211_FTYPE_DATA;
867 header.duration_id = 0; 865 header.duration_id = 0;
868 header.seq_ctl = 0; 866 header.seq_ctl = 0;
@@ -878,7 +876,7 @@ static int start_tx (struct sk_buff *skb, struct net_device *dev)
878 memcpy(&header.addr2, dev->dev_addr, 6); 876 memcpy(&header.addr2, dev->dev_addr, 6);
879 memcpy(&header.addr3, skb->data, 6); 877 memcpy(&header.addr3, skb->data, 6);
880 } 878 }
881 879
882 if (priv->use_wpa) 880 if (priv->use_wpa)
883 memcpy(&header.addr4, SNAP_RFC1024, 6); 881 memcpy(&header.addr4, SNAP_RFC1024, 6);
884 882
@@ -888,27 +886,27 @@ static int start_tx (struct sk_buff *skb, struct net_device *dev)
888 /* Copy the packet sans its 802.3 header addresses which have been replaced */ 886 /* Copy the packet sans its 802.3 header addresses which have been replaced */
889 atmel_copy_to_card(dev, buff + DATA_FRAME_WS_HEADER_SIZE, skb->data + 12, len - 12); 887 atmel_copy_to_card(dev, buff + DATA_FRAME_WS_HEADER_SIZE, skb->data + 12, len - 12);
890 priv->tx_buff_tail += len - 12 + DATA_FRAME_WS_HEADER_SIZE; 888 priv->tx_buff_tail += len - 12 + DATA_FRAME_WS_HEADER_SIZE;
891 889
892 /* low bit of first byte of destination tells us if broadcast */ 890 /* low bit of first byte of destination tells us if broadcast */
893 tx_update_descriptor(priv, *(skb->data) & 0x01, len + 18, buff, TX_PACKET_TYPE_DATA); 891 tx_update_descriptor(priv, *(skb->data) & 0x01, len + 18, buff, TX_PACKET_TYPE_DATA);
894 dev->trans_start = jiffies; 892 dev->trans_start = jiffies;
895 priv->stats.tx_bytes += len; 893 priv->stats.tx_bytes += len;
896 894
897 spin_unlock_irqrestore(&priv->irqlock, flags); 895 spin_unlock_irqrestore(&priv->irqlock, flags);
898 spin_unlock_bh(&priv->timerlock); 896 spin_unlock_bh(&priv->timerlock);
899 dev_kfree_skb(skb); 897 dev_kfree_skb(skb);
900 898
901 return 0; 899 return 0;
902} 900}
903 901
904static void atmel_transmit_management_frame(struct atmel_private *priv, 902static void atmel_transmit_management_frame(struct atmel_private *priv,
905 struct ieee80211_hdr_4addr *header, 903 struct ieee80211_hdr_4addr *header,
906 u8 *body, int body_len) 904 u8 *body, int body_len)
907{ 905{
908 u16 buff; 906 u16 buff;
909 int len = MGMT_FRAME_BODY_OFFSET + body_len; 907 int len = MGMT_FRAME_BODY_OFFSET + body_len;
910 908
911 if (!(buff = find_tx_buff(priv, len))) 909 if (!(buff = find_tx_buff(priv, len)))
912 return; 910 return;
913 911
914 atmel_copy_to_card(priv->dev, buff, (u8 *)header, MGMT_FRAME_BODY_OFFSET); 912 atmel_copy_to_card(priv->dev, buff, (u8 *)header, MGMT_FRAME_BODY_OFFSET);
@@ -916,24 +914,25 @@ static void atmel_transmit_management_frame(struct atmel_private *priv,
916 priv->tx_buff_tail += len; 914 priv->tx_buff_tail += len;
917 tx_update_descriptor(priv, header->addr1[0] & 0x01, len, buff, TX_PACKET_TYPE_MGMT); 915 tx_update_descriptor(priv, header->addr1[0] & 0x01, len, buff, TX_PACKET_TYPE_MGMT);
918} 916}
919 917
920static void fast_rx_path(struct atmel_private *priv, struct ieee80211_hdr_4addr *header, 918static void fast_rx_path(struct atmel_private *priv,
919 struct ieee80211_hdr_4addr *header,
921 u16 msdu_size, u16 rx_packet_loc, u32 crc) 920 u16 msdu_size, u16 rx_packet_loc, u32 crc)
922{ 921{
923 /* fast path: unfragmented packet copy directly into skbuf */ 922 /* fast path: unfragmented packet copy directly into skbuf */
924 u8 mac4[6]; 923 u8 mac4[6];
925 struct sk_buff *skb; 924 struct sk_buff *skb;
926 unsigned char *skbp; 925 unsigned char *skbp;
927 926
928 /* get the final, mac 4 header field, this tells us encapsulation */ 927 /* get the final, mac 4 header field, this tells us encapsulation */
929 atmel_copy_to_host(priv->dev, mac4, rx_packet_loc + 24, 6); 928 atmel_copy_to_host(priv->dev, mac4, rx_packet_loc + 24, 6);
930 msdu_size -= 6; 929 msdu_size -= 6;
931 930
932 if (priv->do_rx_crc) { 931 if (priv->do_rx_crc) {
933 crc = crc32_le(crc, mac4, 6); 932 crc = crc32_le(crc, mac4, 6);
934 msdu_size -= 4; 933 msdu_size -= 4;
935 } 934 }
936 935
937 if (!(skb = dev_alloc_skb(msdu_size + 14))) { 936 if (!(skb = dev_alloc_skb(msdu_size + 14))) {
938 priv->stats.rx_dropped++; 937 priv->stats.rx_dropped++;
939 return; 938 return;
@@ -942,7 +941,7 @@ static void fast_rx_path(struct atmel_private *priv, struct ieee80211_hdr_4addr
942 skb_reserve(skb, 2); 941 skb_reserve(skb, 2);
943 skbp = skb_put(skb, msdu_size + 12); 942 skbp = skb_put(skb, msdu_size + 12);
944 atmel_copy_to_host(priv->dev, skbp + 12, rx_packet_loc + 30, msdu_size); 943 atmel_copy_to_host(priv->dev, skbp + 12, rx_packet_loc + 30, msdu_size);
945 944
946 if (priv->do_rx_crc) { 945 if (priv->do_rx_crc) {
947 u32 netcrc; 946 u32 netcrc;
948 crc = crc32_le(crc, skbp + 12, msdu_size); 947 crc = crc32_le(crc, skbp + 12, msdu_size);
@@ -953,24 +952,25 @@ static void fast_rx_path(struct atmel_private *priv, struct ieee80211_hdr_4addr
953 return; 952 return;
954 } 953 }
955 } 954 }
956 955
957 memcpy(skbp, header->addr1, 6); /* destination address */ 956 memcpy(skbp, header->addr1, 6); /* destination address */
958 if (le16_to_cpu(header->frame_ctl) & IEEE80211_FCTL_FROMDS) 957 if (le16_to_cpu(header->frame_ctl) & IEEE80211_FCTL_FROMDS)
959 memcpy(&skbp[6], header->addr3, 6); 958 memcpy(&skbp[6], header->addr3, 6);
960 else 959 else
961 memcpy(&skbp[6], header->addr2, 6); /* source address */ 960 memcpy(&skbp[6], header->addr2, 6); /* source address */
962 961
963 priv->dev->last_rx=jiffies; 962 priv->dev->last_rx = jiffies;
964 skb->dev = priv->dev; 963 skb->dev = priv->dev;
965 skb->protocol = eth_type_trans(skb, priv->dev); 964 skb->protocol = eth_type_trans(skb, priv->dev);
966 skb->ip_summed = CHECKSUM_NONE; 965 skb->ip_summed = CHECKSUM_NONE;
967 netif_rx(skb); 966 netif_rx(skb);
968 priv->stats.rx_bytes += 12 + msdu_size; 967 priv->stats.rx_bytes += 12 + msdu_size;
969 priv->stats.rx_packets++; 968 priv->stats.rx_packets++;
970} 969}
971 970
972/* Test to see if the packet in card memory at packet_loc has a valid CRC 971/* Test to see if the packet in card memory at packet_loc has a valid CRC
973 It doesn't matter that this is slow: it is only used to proble the first few packets. */ 972 It doesn't matter that this is slow: it is only used to proble the first few
973 packets. */
974static int probe_crc(struct atmel_private *priv, u16 packet_loc, u16 msdu_size) 974static int probe_crc(struct atmel_private *priv, u16 packet_loc, u16 msdu_size)
975{ 975{
976 int i = msdu_size - 4; 976 int i = msdu_size - 4;
@@ -980,7 +980,7 @@ static int probe_crc(struct atmel_private *priv, u16 packet_loc, u16 msdu_size)
980 return 0; 980 return 0;
981 981
982 atmel_copy_to_host(priv->dev, (void *)&netcrc, packet_loc + i, 4); 982 atmel_copy_to_host(priv->dev, (void *)&netcrc, packet_loc + i, 4);
983 983
984 atmel_writeAR(priv->dev, packet_loc); 984 atmel_writeAR(priv->dev, packet_loc);
985 while (i--) { 985 while (i--) {
986 u8 octet = atmel_read8(priv->dev, DR); 986 u8 octet = atmel_read8(priv->dev, DR);
@@ -990,20 +990,22 @@ static int probe_crc(struct atmel_private *priv, u16 packet_loc, u16 msdu_size)
990 return (crc ^ 0xffffffff) == netcrc; 990 return (crc ^ 0xffffffff) == netcrc;
991} 991}
992 992
993static void frag_rx_path(struct atmel_private *priv, struct ieee80211_hdr_4addr *header, 993static void frag_rx_path(struct atmel_private *priv,
994 u16 msdu_size, u16 rx_packet_loc, u32 crc, u16 seq_no, u8 frag_no, int more_frags) 994 struct ieee80211_hdr_4addr *header,
995 u16 msdu_size, u16 rx_packet_loc, u32 crc, u16 seq_no,
996 u8 frag_no, int more_frags)
995{ 997{
996 u8 mac4[6]; 998 u8 mac4[6];
997 u8 source[6]; 999 u8 source[6];
998 struct sk_buff *skb; 1000 struct sk_buff *skb;
999 1001
1000 if (le16_to_cpu(header->frame_ctl) & IEEE80211_FCTL_FROMDS) 1002 if (le16_to_cpu(header->frame_ctl) & IEEE80211_FCTL_FROMDS)
1001 memcpy(source, header->addr3, 6); 1003 memcpy(source, header->addr3, 6);
1002 else 1004 else
1003 memcpy(source, header->addr2, 6); 1005 memcpy(source, header->addr2, 6);
1004 1006
1005 rx_packet_loc += 24; /* skip header */ 1007 rx_packet_loc += 24; /* skip header */
1006 1008
1007 if (priv->do_rx_crc) 1009 if (priv->do_rx_crc)
1008 msdu_size -= 4; 1010 msdu_size -= 4;
1009 1011
@@ -1012,16 +1014,16 @@ static void frag_rx_path(struct atmel_private *priv, struct ieee80211_hdr_4addr
1012 msdu_size -= 6; 1014 msdu_size -= 6;
1013 rx_packet_loc += 6; 1015 rx_packet_loc += 6;
1014 1016
1015 if (priv->do_rx_crc) 1017 if (priv->do_rx_crc)
1016 crc = crc32_le(crc, mac4, 6); 1018 crc = crc32_le(crc, mac4, 6);
1017 1019
1018 priv->frag_seq = seq_no; 1020 priv->frag_seq = seq_no;
1019 priv->frag_no = 1; 1021 priv->frag_no = 1;
1020 priv->frag_len = msdu_size; 1022 priv->frag_len = msdu_size;
1021 memcpy(priv->frag_source, source, 6); 1023 memcpy(priv->frag_source, source, 6);
1022 memcpy(&priv->rx_buf[6], source, 6); 1024 memcpy(&priv->rx_buf[6], source, 6);
1023 memcpy(priv->rx_buf, header->addr1, 6); 1025 memcpy(priv->rx_buf, header->addr1, 6);
1024 1026
1025 atmel_copy_to_host(priv->dev, &priv->rx_buf[12], rx_packet_loc, msdu_size); 1027 atmel_copy_to_host(priv->dev, &priv->rx_buf[12], rx_packet_loc, msdu_size);
1026 1028
1027 if (priv->do_rx_crc) { 1029 if (priv->do_rx_crc) {
@@ -1033,17 +1035,17 @@ static void frag_rx_path(struct atmel_private *priv, struct ieee80211_hdr_4addr
1033 memset(priv->frag_source, 0xff, 6); 1035 memset(priv->frag_source, 0xff, 6);
1034 } 1036 }
1035 } 1037 }
1036 1038
1037 } else if (priv->frag_no == frag_no && 1039 } else if (priv->frag_no == frag_no &&
1038 priv->frag_seq == seq_no && 1040 priv->frag_seq == seq_no &&
1039 memcmp(priv->frag_source, source, 6) == 0) { 1041 memcmp(priv->frag_source, source, 6) == 0) {
1040 1042
1041 atmel_copy_to_host(priv->dev, &priv->rx_buf[12 + priv->frag_len], 1043 atmel_copy_to_host(priv->dev, &priv->rx_buf[12 + priv->frag_len],
1042 rx_packet_loc, msdu_size); 1044 rx_packet_loc, msdu_size);
1043 if (priv->do_rx_crc) { 1045 if (priv->do_rx_crc) {
1044 u32 netcrc; 1046 u32 netcrc;
1045 crc = crc32_le(crc, 1047 crc = crc32_le(crc,
1046 &priv->rx_buf[12 + priv->frag_len], 1048 &priv->rx_buf[12 + priv->frag_len],
1047 msdu_size); 1049 msdu_size);
1048 atmel_copy_to_host(priv->dev, (void *)&netcrc, rx_packet_loc + msdu_size, 4); 1050 atmel_copy_to_host(priv->dev, (void *)&netcrc, rx_packet_loc + msdu_size, 4);
1049 if ((crc ^ 0xffffffff) != netcrc) { 1051 if ((crc ^ 0xffffffff) != netcrc) {
@@ -1052,7 +1054,7 @@ static void frag_rx_path(struct atmel_private *priv, struct ieee80211_hdr_4addr
1052 more_frags = 1; /* don't send broken assembly */ 1054 more_frags = 1; /* don't send broken assembly */
1053 } 1055 }
1054 } 1056 }
1055 1057
1056 priv->frag_len += msdu_size; 1058 priv->frag_len += msdu_size;
1057 priv->frag_no++; 1059 priv->frag_no++;
1058 1060
@@ -1062,60 +1064,60 @@ static void frag_rx_path(struct atmel_private *priv, struct ieee80211_hdr_4addr
1062 priv->stats.rx_dropped++; 1064 priv->stats.rx_dropped++;
1063 } else { 1065 } else {
1064 skb_reserve(skb, 2); 1066 skb_reserve(skb, 2);
1065 memcpy(skb_put(skb, priv->frag_len + 12), 1067 memcpy(skb_put(skb, priv->frag_len + 12),
1066 priv->rx_buf, 1068 priv->rx_buf,
1067 priv->frag_len + 12); 1069 priv->frag_len + 12);
1068 priv->dev->last_rx = jiffies; 1070 priv->dev->last_rx = jiffies;
1069 skb->dev = priv->dev; 1071 skb->dev = priv->dev;
1070 skb->protocol = eth_type_trans(skb, priv->dev); 1072 skb->protocol = eth_type_trans(skb, priv->dev);
1071 skb->ip_summed = CHECKSUM_NONE; 1073 skb->ip_summed = CHECKSUM_NONE;
1072 netif_rx(skb); 1074 netif_rx(skb);
1073 priv->stats.rx_bytes += priv->frag_len + 12; 1075 priv->stats.rx_bytes += priv->frag_len + 12;
1074 priv->stats.rx_packets++; 1076 priv->stats.rx_packets++;
1075 } 1077 }
1076 } 1078 }
1077
1078 } else 1079 } else
1079 priv->wstats.discard.fragment++; 1080 priv->wstats.discard.fragment++;
1080} 1081}
1081 1082
1082static void rx_done_irq(struct atmel_private *priv) 1083static void rx_done_irq(struct atmel_private *priv)
1083{ 1084{
1084 int i; 1085 int i;
1085 struct ieee80211_hdr_4addr header; 1086 struct ieee80211_hdr_4addr header;
1086 1087
1087 for (i = 0; 1088 for (i = 0;
1088 atmel_rmem8(priv, atmel_rx(priv, RX_DESC_FLAGS_OFFSET, priv->rx_desc_head)) == RX_DESC_FLAG_VALID && 1089 atmel_rmem8(priv, atmel_rx(priv, RX_DESC_FLAGS_OFFSET, priv->rx_desc_head)) == RX_DESC_FLAG_VALID &&
1089 i < priv->host_info.rx_desc_count; 1090 i < priv->host_info.rx_desc_count;
1090 i++) { 1091 i++) {
1091 1092
1092 u16 msdu_size, rx_packet_loc, frame_ctl, seq_control; 1093 u16 msdu_size, rx_packet_loc, frame_ctl, seq_control;
1093 u8 status = atmel_rmem8(priv, atmel_rx(priv, RX_DESC_STATUS_OFFSET, priv->rx_desc_head)); 1094 u8 status = atmel_rmem8(priv, atmel_rx(priv, RX_DESC_STATUS_OFFSET, priv->rx_desc_head));
1094 u32 crc = 0xffffffff; 1095 u32 crc = 0xffffffff;
1095 1096
1096 if (status != RX_STATUS_SUCCESS) { 1097 if (status != RX_STATUS_SUCCESS) {
1097 if (status == 0xc1) /* determined by experiment */ 1098 if (status == 0xc1) /* determined by experiment */
1098 priv->wstats.discard.nwid++; 1099 priv->wstats.discard.nwid++;
1099 else 1100 else
1100 priv->stats.rx_errors++; 1101 priv->stats.rx_errors++;
1101 goto next; 1102 goto next;
1102 } 1103 }
1103 1104
1104 msdu_size = atmel_rmem16(priv, atmel_rx(priv, RX_DESC_MSDU_SIZE_OFFSET, priv->rx_desc_head)); 1105 msdu_size = atmel_rmem16(priv, atmel_rx(priv, RX_DESC_MSDU_SIZE_OFFSET, priv->rx_desc_head));
1105 rx_packet_loc = atmel_rmem16(priv, atmel_rx(priv, RX_DESC_MSDU_POS_OFFSET, priv->rx_desc_head)); 1106 rx_packet_loc = atmel_rmem16(priv, atmel_rx(priv, RX_DESC_MSDU_POS_OFFSET, priv->rx_desc_head));
1106 1107
1107 if (msdu_size < 30) { 1108 if (msdu_size < 30) {
1108 priv->stats.rx_errors++; 1109 priv->stats.rx_errors++;
1109 goto next; 1110 goto next;
1110 } 1111 }
1111 1112
1112 /* Get header as far as end of seq_ctl */ 1113 /* Get header as far as end of seq_ctl */
1113 atmel_copy_to_host(priv->dev, (char *)&header, rx_packet_loc, 24); 1114 atmel_copy_to_host(priv->dev, (char *)&header, rx_packet_loc, 24);
1114 frame_ctl = le16_to_cpu(header.frame_ctl); 1115 frame_ctl = le16_to_cpu(header.frame_ctl);
1115 seq_control = le16_to_cpu(header.seq_ctl); 1116 seq_control = le16_to_cpu(header.seq_ctl);
1116 1117
1117 /* probe for CRC use here if needed once five packets have arrived with 1118 /* probe for CRC use here if needed once five packets have
1118 the same crc status, we assume we know what's happening and stop probing */ 1119 arrived with the same crc status, we assume we know what's
1120 happening and stop probing */
1119 if (priv->probe_crc) { 1121 if (priv->probe_crc) {
1120 if (!priv->wep_is_on || !(frame_ctl & IEEE80211_FCTL_PROTECTED)) { 1122 if (!priv->wep_is_on || !(frame_ctl & IEEE80211_FCTL_PROTECTED)) {
1121 priv->do_rx_crc = probe_crc(priv, rx_packet_loc, msdu_size); 1123 priv->do_rx_crc = probe_crc(priv, rx_packet_loc, msdu_size);
@@ -1130,34 +1132,33 @@ static void rx_done_irq(struct atmel_private *priv)
1130 priv->probe_crc = 0; 1132 priv->probe_crc = 0;
1131 } 1133 }
1132 } 1134 }
1133 1135
1134 /* don't CRC header when WEP in use */ 1136 /* don't CRC header when WEP in use */
1135 if (priv->do_rx_crc && (!priv->wep_is_on || !(frame_ctl & IEEE80211_FCTL_PROTECTED))) { 1137 if (priv->do_rx_crc && (!priv->wep_is_on || !(frame_ctl & IEEE80211_FCTL_PROTECTED))) {
1136 crc = crc32_le(0xffffffff, (unsigned char *)&header, 24); 1138 crc = crc32_le(0xffffffff, (unsigned char *)&header, 24);
1137 } 1139 }
1138 msdu_size -= 24; /* header */ 1140 msdu_size -= 24; /* header */
1139 1141
1140 if ((frame_ctl & IEEE80211_FCTL_FTYPE) == IEEE80211_FTYPE_DATA) { 1142 if ((frame_ctl & IEEE80211_FCTL_FTYPE) == IEEE80211_FTYPE_DATA) {
1141
1142 int more_fragments = frame_ctl & IEEE80211_FCTL_MOREFRAGS; 1143 int more_fragments = frame_ctl & IEEE80211_FCTL_MOREFRAGS;
1143 u8 packet_fragment_no = seq_control & IEEE80211_SCTL_FRAG; 1144 u8 packet_fragment_no = seq_control & IEEE80211_SCTL_FRAG;
1144 u16 packet_sequence_no = (seq_control & IEEE80211_SCTL_SEQ) >> 4; 1145 u16 packet_sequence_no = (seq_control & IEEE80211_SCTL_SEQ) >> 4;
1145 1146
1146 if (!more_fragments && packet_fragment_no == 0 ) { 1147 if (!more_fragments && packet_fragment_no == 0) {
1147 fast_rx_path(priv, &header, msdu_size, rx_packet_loc, crc); 1148 fast_rx_path(priv, &header, msdu_size, rx_packet_loc, crc);
1148 } else { 1149 } else {
1149 frag_rx_path(priv, &header, msdu_size, rx_packet_loc, crc, 1150 frag_rx_path(priv, &header, msdu_size, rx_packet_loc, crc,
1150 packet_sequence_no, packet_fragment_no, more_fragments); 1151 packet_sequence_no, packet_fragment_no, more_fragments);
1151 } 1152 }
1152 } 1153 }
1153 1154
1154 if ((frame_ctl & IEEE80211_FCTL_FTYPE) == IEEE80211_FTYPE_MGMT) { 1155 if ((frame_ctl & IEEE80211_FCTL_FTYPE) == IEEE80211_FTYPE_MGMT) {
1155 /* copy rest of packet into buffer */ 1156 /* copy rest of packet into buffer */
1156 atmel_copy_to_host(priv->dev, (unsigned char *)&priv->rx_buf, rx_packet_loc + 24, msdu_size); 1157 atmel_copy_to_host(priv->dev, (unsigned char *)&priv->rx_buf, rx_packet_loc + 24, msdu_size);
1157 1158
1158 /* we use the same buffer for frag reassembly and control packets */ 1159 /* we use the same buffer for frag reassembly and control packets */
1159 memset(priv->frag_source, 0xff, 6); 1160 memset(priv->frag_source, 0xff, 6);
1160 1161
1161 if (priv->do_rx_crc) { 1162 if (priv->do_rx_crc) {
1162 /* last 4 octets is crc */ 1163 /* last 4 octets is crc */
1163 msdu_size -= 4; 1164 msdu_size -= 4;
@@ -1170,18 +1171,18 @@ static void rx_done_irq(struct atmel_private *priv)
1170 1171
1171 atmel_management_frame(priv, &header, msdu_size, 1172 atmel_management_frame(priv, &header, msdu_size,
1172 atmel_rmem8(priv, atmel_rx(priv, RX_DESC_RSSI_OFFSET, priv->rx_desc_head))); 1173 atmel_rmem8(priv, atmel_rx(priv, RX_DESC_RSSI_OFFSET, priv->rx_desc_head)));
1173 } 1174 }
1174 1175
1175 next: 1176next:
1176 /* release descriptor */ 1177 /* release descriptor */
1177 atmel_wmem8(priv, atmel_rx(priv, RX_DESC_FLAGS_OFFSET, priv->rx_desc_head), RX_DESC_FLAG_CONSUMED); 1178 atmel_wmem8(priv, atmel_rx(priv, RX_DESC_FLAGS_OFFSET, priv->rx_desc_head), RX_DESC_FLAG_CONSUMED);
1178 1179
1179 if (priv->rx_desc_head < (priv->host_info.rx_desc_count - 1)) 1180 if (priv->rx_desc_head < (priv->host_info.rx_desc_count - 1))
1180 priv->rx_desc_head++; 1181 priv->rx_desc_head++;
1181 else 1182 else
1182 priv->rx_desc_head = 0; 1183 priv->rx_desc_head = 0;
1183 } 1184 }
1184} 1185}
1185 1186
1186static irqreturn_t service_interrupt(int irq, void *dev_id, struct pt_regs *regs) 1187static irqreturn_t service_interrupt(int irq, void *dev_id, struct pt_regs *regs)
1187{ 1188{
@@ -1189,7 +1190,7 @@ static irqreturn_t service_interrupt(int irq, void *dev_id, struct pt_regs *regs
1189 struct atmel_private *priv = netdev_priv(dev); 1190 struct atmel_private *priv = netdev_priv(dev);
1190 u8 isr; 1191 u8 isr;
1191 int i = -1; 1192 int i = -1;
1192 static u8 irq_order[] = { 1193 static u8 irq_order[] = {
1193 ISR_OUT_OF_RANGE, 1194 ISR_OUT_OF_RANGE,
1194 ISR_RxCOMPLETE, 1195 ISR_RxCOMPLETE,
1195 ISR_TxCOMPLETE, 1196 ISR_TxCOMPLETE,
@@ -1199,20 +1200,19 @@ static irqreturn_t service_interrupt(int irq, void *dev_id, struct pt_regs *regs
1199 ISR_IBSS_MERGE, 1200 ISR_IBSS_MERGE,
1200 ISR_GENERIC_IRQ 1201 ISR_GENERIC_IRQ
1201 }; 1202 };
1202
1203 1203
1204 if (priv->card && priv->present_callback && 1204 if (priv->card && priv->present_callback &&
1205 !(*priv->present_callback)(priv->card)) 1205 !(*priv->present_callback)(priv->card))
1206 return IRQ_HANDLED; 1206 return IRQ_HANDLED;
1207 1207
1208 /* In this state upper-level code assumes it can mess with 1208 /* In this state upper-level code assumes it can mess with
1209 the card unhampered by interrupts which may change register state. 1209 the card unhampered by interrupts which may change register state.
1210 Note that even though the card shouldn't generate interrupts 1210 Note that even though the card shouldn't generate interrupts
1211 the inturrupt line may be shared. This allows card setup 1211 the inturrupt line may be shared. This allows card setup
1212 to go on without disabling interrupts for a long time. */ 1212 to go on without disabling interrupts for a long time. */
1213 if (priv->station_state == STATION_STATE_DOWN) 1213 if (priv->station_state == STATION_STATE_DOWN)
1214 return IRQ_NONE; 1214 return IRQ_NONE;
1215 1215
1216 atmel_clear_gcr(dev, GCR_ENINT); /* disable interrupts */ 1216 atmel_clear_gcr(dev, GCR_ENINT); /* disable interrupts */
1217 1217
1218 while (1) { 1218 while (1) {
@@ -1221,36 +1221,36 @@ static irqreturn_t service_interrupt(int irq, void *dev_id, struct pt_regs *regs
1221 printk(KERN_ALERT "%s: failed to contact MAC.\n", dev->name); 1221 printk(KERN_ALERT "%s: failed to contact MAC.\n", dev->name);
1222 return IRQ_HANDLED; 1222 return IRQ_HANDLED;
1223 } 1223 }
1224 1224
1225 isr = atmel_rmem8(priv, atmel_hi(priv, IFACE_INT_STATUS_OFFSET)); 1225 isr = atmel_rmem8(priv, atmel_hi(priv, IFACE_INT_STATUS_OFFSET));
1226 atmel_wmem8(priv, atmel_hi(priv, IFACE_LOCKOUT_MAC_OFFSET), 0); 1226 atmel_wmem8(priv, atmel_hi(priv, IFACE_LOCKOUT_MAC_OFFSET), 0);
1227 1227
1228 if (!isr) { 1228 if (!isr) {
1229 atmel_set_gcr(dev, GCR_ENINT); /* enable interrupts */ 1229 atmel_set_gcr(dev, GCR_ENINT); /* enable interrupts */
1230 return i == -1 ? IRQ_NONE : IRQ_HANDLED; 1230 return i == -1 ? IRQ_NONE : IRQ_HANDLED;
1231 } 1231 }
1232 1232
1233 atmel_set_gcr(dev, GCR_ACKINT); /* acknowledge interrupt */ 1233 atmel_set_gcr(dev, GCR_ACKINT); /* acknowledge interrupt */
1234 1234
1235 for (i = 0; i < sizeof(irq_order)/sizeof(u8); i++) 1235 for (i = 0; i < sizeof(irq_order)/sizeof(u8); i++)
1236 if (isr & irq_order[i]) 1236 if (isr & irq_order[i])
1237 break; 1237 break;
1238 1238
1239 if (!atmel_lock_mac(priv)) { 1239 if (!atmel_lock_mac(priv)) {
1240 /* failed to contact card */ 1240 /* failed to contact card */
1241 printk(KERN_ALERT "%s: failed to contact MAC.\n", dev->name); 1241 printk(KERN_ALERT "%s: failed to contact MAC.\n", dev->name);
1242 return IRQ_HANDLED; 1242 return IRQ_HANDLED;
1243 } 1243 }
1244 1244
1245 isr = atmel_rmem8(priv, atmel_hi(priv, IFACE_INT_STATUS_OFFSET)); 1245 isr = atmel_rmem8(priv, atmel_hi(priv, IFACE_INT_STATUS_OFFSET));
1246 isr ^= irq_order[i]; 1246 isr ^= irq_order[i];
1247 atmel_wmem8(priv, atmel_hi(priv, IFACE_INT_STATUS_OFFSET), isr); 1247 atmel_wmem8(priv, atmel_hi(priv, IFACE_INT_STATUS_OFFSET), isr);
1248 atmel_wmem8(priv, atmel_hi(priv, IFACE_LOCKOUT_MAC_OFFSET), 0); 1248 atmel_wmem8(priv, atmel_hi(priv, IFACE_LOCKOUT_MAC_OFFSET), 0);
1249 1249
1250 switch (irq_order[i]) { 1250 switch (irq_order[i]) {
1251 1251
1252 case ISR_OUT_OF_RANGE: 1252 case ISR_OUT_OF_RANGE:
1253 if (priv->operating_mode == IW_MODE_INFRA && 1253 if (priv->operating_mode == IW_MODE_INFRA &&
1254 priv->station_state == STATION_STATE_READY) { 1254 priv->station_state == STATION_STATE_READY) {
1255 priv->station_is_associated = 0; 1255 priv->station_is_associated = 0;
1256 atmel_scan(priv, 1); 1256 atmel_scan(priv, 1);
@@ -1261,24 +1261,24 @@ static irqreturn_t service_interrupt(int irq, void *dev_id, struct pt_regs *regs
1261 priv->wstats.discard.misc++; 1261 priv->wstats.discard.misc++;
1262 /* fall through */ 1262 /* fall through */
1263 case ISR_RxCOMPLETE: 1263 case ISR_RxCOMPLETE:
1264 rx_done_irq(priv); 1264 rx_done_irq(priv);
1265 break; 1265 break;
1266 1266
1267 case ISR_TxCOMPLETE: 1267 case ISR_TxCOMPLETE:
1268 tx_done_irq(priv); 1268 tx_done_irq(priv);
1269 break; 1269 break;
1270 1270
1271 case ISR_FATAL_ERROR: 1271 case ISR_FATAL_ERROR:
1272 printk(KERN_ALERT "%s: *** FATAL error interrupt ***\n", dev->name); 1272 printk(KERN_ALERT "%s: *** FATAL error interrupt ***\n", dev->name);
1273 atmel_enter_state(priv, STATION_STATE_MGMT_ERROR); 1273 atmel_enter_state(priv, STATION_STATE_MGMT_ERROR);
1274 break; 1274 break;
1275 1275
1276 case ISR_COMMAND_COMPLETE: 1276 case ISR_COMMAND_COMPLETE:
1277 atmel_command_irq(priv); 1277 atmel_command_irq(priv);
1278 break; 1278 break;
1279 1279
1280 case ISR_IBSS_MERGE: 1280 case ISR_IBSS_MERGE:
1281 atmel_get_mib(priv, Mac_Mgmt_Mib_Type, MAC_MGMT_MIB_CUR_BSSID_POS, 1281 atmel_get_mib(priv, Mac_Mgmt_Mib_Type, MAC_MGMT_MIB_CUR_BSSID_POS,
1282 priv->CurrentBSSID, 6); 1282 priv->CurrentBSSID, 6);
1283 /* The WPA stuff cares about the current AP address */ 1283 /* The WPA stuff cares about the current AP address */
1284 if (priv->use_wpa) 1284 if (priv->use_wpa)
@@ -1288,24 +1288,23 @@ static irqreturn_t service_interrupt(int irq, void *dev_id, struct pt_regs *regs
1288 printk(KERN_INFO "%s: Generic_irq received.\n", dev->name); 1288 printk(KERN_INFO "%s: Generic_irq received.\n", dev->name);
1289 break; 1289 break;
1290 } 1290 }
1291 } 1291 }
1292} 1292}
1293 1293
1294 1294static struct net_device_stats *atmel_get_stats(struct net_device *dev)
1295static struct net_device_stats *atmel_get_stats (struct net_device *dev)
1296{ 1295{
1297 struct atmel_private *priv = netdev_priv(dev); 1296 struct atmel_private *priv = netdev_priv(dev);
1298 return &priv->stats; 1297 return &priv->stats;
1299} 1298}
1300 1299
1301static struct iw_statistics *atmel_get_wireless_stats (struct net_device *dev) 1300static struct iw_statistics *atmel_get_wireless_stats(struct net_device *dev)
1302{ 1301{
1303 struct atmel_private *priv = netdev_priv(dev); 1302 struct atmel_private *priv = netdev_priv(dev);
1304 1303
1305 /* update the link quality here in case we are seeing no beacons 1304 /* update the link quality here in case we are seeing no beacons
1306 at all to drive the process */ 1305 at all to drive the process */
1307 atmel_smooth_qual(priv); 1306 atmel_smooth_qual(priv);
1308 1307
1309 priv->wstats.status = priv->station_state; 1308 priv->wstats.status = priv->station_state;
1310 1309
1311 if (priv->operating_mode == IW_MODE_INFRA) { 1310 if (priv->operating_mode == IW_MODE_INFRA) {
@@ -1328,8 +1327,8 @@ static struct iw_statistics *atmel_get_wireless_stats (struct net_device *dev)
1328 | IW_QUAL_NOISE_INVALID; 1327 | IW_QUAL_NOISE_INVALID;
1329 priv->wstats.miss.beacon = 0; 1328 priv->wstats.miss.beacon = 0;
1330 } 1329 }
1331 1330
1332 return (&priv->wstats); 1331 return &priv->wstats;
1333} 1332}
1334 1333
1335static int atmel_change_mtu(struct net_device *dev, int new_mtu) 1334static int atmel_change_mtu(struct net_device *dev, int new_mtu)
@@ -1343,21 +1342,21 @@ static int atmel_change_mtu(struct net_device *dev, int new_mtu)
1343static int atmel_set_mac_address(struct net_device *dev, void *p) 1342static int atmel_set_mac_address(struct net_device *dev, void *p)
1344{ 1343{
1345 struct sockaddr *addr = p; 1344 struct sockaddr *addr = p;
1346 1345
1347 memcpy (dev->dev_addr, addr->sa_data, dev->addr_len); 1346 memcpy (dev->dev_addr, addr->sa_data, dev->addr_len);
1348 return atmel_open(dev); 1347 return atmel_open(dev);
1349} 1348}
1350 1349
1351EXPORT_SYMBOL(atmel_open); 1350EXPORT_SYMBOL(atmel_open);
1352 1351
1353int atmel_open (struct net_device *dev) 1352int atmel_open(struct net_device *dev)
1354{ 1353{
1355 struct atmel_private *priv = netdev_priv(dev); 1354 struct atmel_private *priv = netdev_priv(dev);
1356 int i, channel; 1355 int i, channel;
1357 1356
1358 /* any scheduled timer is no longer needed and might screw things up.. */ 1357 /* any scheduled timer is no longer needed and might screw things up.. */
1359 del_timer_sync(&priv->management_timer); 1358 del_timer_sync(&priv->management_timer);
1360 1359
1361 /* Interrupts will not touch the card once in this state... */ 1360 /* Interrupts will not touch the card once in this state... */
1362 priv->station_state = STATION_STATE_DOWN; 1361 priv->station_state = STATION_STATE_DOWN;
1363 1362
@@ -1377,7 +1376,7 @@ int atmel_open (struct net_device *dev)
1377 priv->site_survey_state = SITE_SURVEY_IDLE; 1376 priv->site_survey_state = SITE_SURVEY_IDLE;
1378 priv->station_is_associated = 0; 1377 priv->station_is_associated = 0;
1379 1378
1380 if (!reset_atmel_card(dev)) 1379 if (!reset_atmel_card(dev))
1381 return -EAGAIN; 1380 return -EAGAIN;
1382 1381
1383 if (priv->config_reg_domain) { 1382 if (priv->config_reg_domain) {
@@ -1391,26 +1390,26 @@ int atmel_open (struct net_device *dev)
1391 if (i == sizeof(channel_table)/sizeof(channel_table[0])) { 1390 if (i == sizeof(channel_table)/sizeof(channel_table[0])) {
1392 priv->reg_domain = REG_DOMAIN_MKK1; 1391 priv->reg_domain = REG_DOMAIN_MKK1;
1393 printk(KERN_ALERT "%s: failed to get regulatory domain: assuming MKK1.\n", dev->name); 1392 printk(KERN_ALERT "%s: failed to get regulatory domain: assuming MKK1.\n", dev->name);
1394 } 1393 }
1395 } 1394 }
1396 1395
1397 if ((channel = atmel_validate_channel(priv, priv->channel))) 1396 if ((channel = atmel_validate_channel(priv, priv->channel)))
1398 priv->channel = channel; 1397 priv->channel = channel;
1399 1398
1400 /* this moves station_state on.... */ 1399 /* this moves station_state on.... */
1401 atmel_scan(priv, 1); 1400 atmel_scan(priv, 1);
1402 1401
1403 atmel_set_gcr(priv->dev, GCR_ENINT); /* enable interrupts */ 1402 atmel_set_gcr(priv->dev, GCR_ENINT); /* enable interrupts */
1404 return 0; 1403 return 0;
1405} 1404}
1406 1405
1407static int atmel_close (struct net_device *dev) 1406static int atmel_close(struct net_device *dev)
1408{ 1407{
1409 struct atmel_private *priv = netdev_priv(dev); 1408 struct atmel_private *priv = netdev_priv(dev);
1410 1409
1411 atmel_enter_state(priv, STATION_STATE_DOWN); 1410 atmel_enter_state(priv, STATION_STATE_DOWN);
1412 1411
1413 if (priv->bus_type == BUS_TYPE_PCCARD) 1412 if (priv->bus_type == BUS_TYPE_PCCARD)
1414 atmel_write16(dev, GCR, 0x0060); 1413 atmel_write16(dev, GCR, 0x0060);
1415 atmel_write16(dev, GCR, 0x0040); 1414 atmel_write16(dev, GCR, 0x0040);
1416 return 0; 1415 return 0;
@@ -1438,43 +1437,46 @@ static int atmel_proc_output (char *buf, struct atmel_private *priv)
1438 int i; 1437 int i;
1439 char *p = buf; 1438 char *p = buf;
1440 char *s, *r, *c; 1439 char *s, *r, *c;
1441 1440
1442 p += sprintf(p, "Driver version:\t\t%d.%d\n", DRIVER_MAJOR, DRIVER_MINOR); 1441 p += sprintf(p, "Driver version:\t\t%d.%d\n",
1443 1442 DRIVER_MAJOR, DRIVER_MINOR);
1443
1444 if (priv->station_state != STATION_STATE_DOWN) { 1444 if (priv->station_state != STATION_STATE_DOWN) {
1445 p += sprintf(p, "Firmware version:\t%d.%d build %d\nFirmware location:\t", 1445 p += sprintf(p, "Firmware version:\t%d.%d build %d\n"
1446 "Firmware location:\t",
1446 priv->host_info.major_version, 1447 priv->host_info.major_version,
1447 priv->host_info.minor_version, 1448 priv->host_info.minor_version,
1448 priv->host_info.build_version); 1449 priv->host_info.build_version);
1449 1450
1450 if (priv->card_type != CARD_TYPE_EEPROM) 1451 if (priv->card_type != CARD_TYPE_EEPROM)
1451 p += sprintf(p, "on card\n"); 1452 p += sprintf(p, "on card\n");
1452 else if (priv->firmware) 1453 else if (priv->firmware)
1453 p += sprintf(p, "%s loaded by host\n", priv->firmware_id); 1454 p += sprintf(p, "%s loaded by host\n",
1455 priv->firmware_id);
1454 else 1456 else
1455 p += sprintf(p, "%s loaded by hotplug\n", priv->firmware_id); 1457 p += sprintf(p, "%s loaded by hotplug\n",
1456 1458 priv->firmware_id);
1457 switch(priv->card_type) { 1459
1460 switch (priv->card_type) {
1458 case CARD_TYPE_PARALLEL_FLASH: c = "Parallel flash"; break; 1461 case CARD_TYPE_PARALLEL_FLASH: c = "Parallel flash"; break;
1459 case CARD_TYPE_SPI_FLASH: c = "SPI flash\n"; break; 1462 case CARD_TYPE_SPI_FLASH: c = "SPI flash\n"; break;
1460 case CARD_TYPE_EEPROM: c = "EEPROM"; break; 1463 case CARD_TYPE_EEPROM: c = "EEPROM"; break;
1461 default: c = "<unknown>"; 1464 default: c = "<unknown>";
1462 } 1465 }
1463 1466
1464
1465 r = "<unknown>"; 1467 r = "<unknown>";
1466 for (i = 0; i < sizeof(channel_table)/sizeof(channel_table[0]); i++) 1468 for (i = 0; i < sizeof(channel_table)/sizeof(channel_table[0]); i++)
1467 if (priv->reg_domain == channel_table[i].reg_domain) 1469 if (priv->reg_domain == channel_table[i].reg_domain)
1468 r = channel_table[i].name; 1470 r = channel_table[i].name;
1469 1471
1470 p += sprintf(p, "MAC memory type:\t%s\n", c); 1472 p += sprintf(p, "MAC memory type:\t%s\n", c);
1471 p += sprintf(p, "Regulatory domain:\t%s\n", r); 1473 p += sprintf(p, "Regulatory domain:\t%s\n", r);
1472 p += sprintf(p, "Host CRC checking:\t%s\n", 1474 p += sprintf(p, "Host CRC checking:\t%s\n",
1473 priv->do_rx_crc ? "On" : "Off"); 1475 priv->do_rx_crc ? "On" : "Off");
1474 p += sprintf(p, "WPA-capable firmware:\t%s\n", 1476 p += sprintf(p, "WPA-capable firmware:\t%s\n",
1475 priv->use_wpa ? "Yes" : "No"); 1477 priv->use_wpa ? "Yes" : "No");
1476 } 1478 }
1477 1479
1478 switch(priv->station_state) { 1480 switch(priv->station_state) {
1479 case STATION_STATE_SCANNING: s = "Scanning"; break; 1481 case STATION_STATE_SCANNING: s = "Scanning"; break;
1480 case STATION_STATE_JOINNING: s = "Joining"; break; 1482 case STATION_STATE_JOINNING: s = "Joining"; break;
@@ -1486,9 +1488,9 @@ static int atmel_proc_output (char *buf, struct atmel_private *priv)
1486 case STATION_STATE_DOWN: s = "Down"; break; 1488 case STATION_STATE_DOWN: s = "Down"; break;
1487 default: s = "<unknown>"; 1489 default: s = "<unknown>";
1488 } 1490 }
1489 1491
1490 p += sprintf(p, "Current state:\t\t%s\n", s); 1492 p += sprintf(p, "Current state:\t\t%s\n", s);
1491 return p - buf; 1493 return p - buf;
1492} 1494}
1493 1495
1494static int atmel_read_proc(char *page, char **start, off_t off, 1496static int atmel_read_proc(char *page, char **start, off_t off,
@@ -1504,9 +1506,12 @@ static int atmel_read_proc(char *page, char **start, off_t off,
1504 return len; 1506 return len;
1505} 1507}
1506 1508
1507struct net_device *init_atmel_card( unsigned short irq, unsigned long port, const AtmelFWType fw_type, 1509struct net_device *init_atmel_card(unsigned short irq, unsigned long port,
1508 struct device *sys_dev, int (*card_present)(void *), void *card) 1510 const AtmelFWType fw_type,
1511 struct device *sys_dev,
1512 int (*card_present)(void *), void *card)
1509{ 1513{
1514 struct proc_dir_entry *ent;
1510 struct net_device *dev; 1515 struct net_device *dev;
1511 struct atmel_private *priv; 1516 struct atmel_private *priv;
1512 int rc; 1517 int rc;
@@ -1514,11 +1519,11 @@ struct net_device *init_atmel_card( unsigned short irq, unsigned long port, cons
1514 /* Create the network device object. */ 1519 /* Create the network device object. */
1515 dev = alloc_etherdev(sizeof(*priv)); 1520 dev = alloc_etherdev(sizeof(*priv));
1516 if (!dev) { 1521 if (!dev) {
1517 printk(KERN_ERR "atmel: Couldn't alloc_etherdev\n"); 1522 printk(KERN_ERR "atmel: Couldn't alloc_etherdev\n");
1518 return NULL; 1523 return NULL;
1519 } 1524 }
1520 if (dev_alloc_name(dev, dev->name) < 0) { 1525 if (dev_alloc_name(dev, dev->name) < 0) {
1521 printk(KERN_ERR "atmel: Couldn't get name!\n"); 1526 printk(KERN_ERR "atmel: Couldn't get name!\n");
1522 goto err_out_free; 1527 goto err_out_free;
1523 } 1528 }
1524 1529
@@ -1550,7 +1555,7 @@ struct net_device *init_atmel_card( unsigned short irq, unsigned long port, cons
1550 memset(priv->BSSID, 0, 6); 1555 memset(priv->BSSID, 0, 6);
1551 priv->CurrentBSSID[0] = 0xFF; /* Initialize to something invalid.... */ 1556 priv->CurrentBSSID[0] = 0xFF; /* Initialize to something invalid.... */
1552 priv->station_was_associated = 0; 1557 priv->station_was_associated = 0;
1553 1558
1554 priv->last_survey = jiffies; 1559 priv->last_survey = jiffies;
1555 priv->preamble = LONG_PREAMBLE; 1560 priv->preamble = LONG_PREAMBLE;
1556 priv->operating_mode = IW_MODE_INFRA; 1561 priv->operating_mode = IW_MODE_INFRA;
@@ -1586,7 +1591,7 @@ struct net_device *init_atmel_card( unsigned short irq, unsigned long port, cons
1586 spin_lock_init(&priv->timerlock); 1591 spin_lock_init(&priv->timerlock);
1587 priv->management_timer.function = atmel_management_timer; 1592 priv->management_timer.function = atmel_management_timer;
1588 priv->management_timer.data = (unsigned long) dev; 1593 priv->management_timer.data = (unsigned long) dev;
1589 1594
1590 dev->open = atmel_open; 1595 dev->open = atmel_open;
1591 dev->stop = atmel_close; 1596 dev->stop = atmel_close;
1592 dev->change_mtu = atmel_change_mtu; 1597 dev->change_mtu = atmel_change_mtu;
@@ -1597,44 +1602,46 @@ struct net_device *init_atmel_card( unsigned short irq, unsigned long port, cons
1597 dev->do_ioctl = atmel_ioctl; 1602 dev->do_ioctl = atmel_ioctl;
1598 dev->irq = irq; 1603 dev->irq = irq;
1599 dev->base_addr = port; 1604 dev->base_addr = port;
1600 1605
1601 SET_NETDEV_DEV(dev, sys_dev); 1606 SET_NETDEV_DEV(dev, sys_dev);
1602 1607
1603 if ((rc = request_irq(dev->irq, service_interrupt, SA_SHIRQ, dev->name, dev))) { 1608 if ((rc = request_irq(dev->irq, service_interrupt, SA_SHIRQ, dev->name, dev))) {
1604 printk(KERN_ERR "%s: register interrupt %d failed, rc %d\n", dev->name, irq, rc ); 1609 printk(KERN_ERR "%s: register interrupt %d failed, rc %d\n", dev->name, irq, rc);
1605 goto err_out_free; 1610 goto err_out_free;
1606 } 1611 }
1607 1612
1608 if (!request_region(dev->base_addr, 32, 1613 if (!request_region(dev->base_addr, 32,
1609 priv->bus_type == BUS_TYPE_PCCARD ? "atmel_cs" : "atmel_pci")) { 1614 priv->bus_type == BUS_TYPE_PCCARD ? "atmel_cs" : "atmel_pci")) {
1610 goto err_out_irq; 1615 goto err_out_irq;
1611 } 1616 }
1612 1617
1613 if (register_netdev(dev)) 1618 if (register_netdev(dev))
1614 goto err_out_res; 1619 goto err_out_res;
1615 1620
1616 if (!probe_atmel_card(dev)){ 1621 if (!probe_atmel_card(dev)){
1617 unregister_netdev(dev); 1622 unregister_netdev(dev);
1618 goto err_out_res; 1623 goto err_out_res;
1619 } 1624 }
1620 1625
1621 netif_carrier_off(dev); 1626 netif_carrier_off(dev);
1622 1627
1623 create_proc_read_entry ("driver/atmel", 0, NULL, atmel_read_proc, priv); 1628 ent = create_proc_read_entry ("driver/atmel", 0, NULL, atmel_read_proc, priv);
1624 1629 if (!ent)
1630 printk(KERN_WARNING "atmel: unable to create /proc entry.\n");
1631
1625 printk(KERN_INFO "%s: Atmel at76c50x. Version %d.%d. MAC %.2x:%.2x:%.2x:%.2x:%.2x:%.2x\n", 1632 printk(KERN_INFO "%s: Atmel at76c50x. Version %d.%d. MAC %.2x:%.2x:%.2x:%.2x:%.2x:%.2x\n",
1626 dev->name, DRIVER_MAJOR, DRIVER_MINOR, 1633 dev->name, DRIVER_MAJOR, DRIVER_MINOR,
1627 dev->dev_addr[0], dev->dev_addr[1], dev->dev_addr[2], 1634 dev->dev_addr[0], dev->dev_addr[1], dev->dev_addr[2],
1628 dev->dev_addr[3], dev->dev_addr[4], dev->dev_addr[5] ); 1635 dev->dev_addr[3], dev->dev_addr[4], dev->dev_addr[5] );
1629 1636
1630 SET_MODULE_OWNER(dev); 1637 SET_MODULE_OWNER(dev);
1631 return dev; 1638 return dev;
1632 1639
1633 err_out_res: 1640err_out_res:
1634 release_region( dev->base_addr, 32); 1641 release_region( dev->base_addr, 32);
1635 err_out_irq: 1642err_out_irq:
1636 free_irq(dev->irq, dev); 1643 free_irq(dev->irq, dev);
1637 err_out_free: 1644err_out_free:
1638 free_netdev(dev); 1645 free_netdev(dev);
1639 return NULL; 1646 return NULL;
1640} 1647}
@@ -1644,12 +1651,12 @@ EXPORT_SYMBOL(init_atmel_card);
1644void stop_atmel_card(struct net_device *dev) 1651void stop_atmel_card(struct net_device *dev)
1645{ 1652{
1646 struct atmel_private *priv = netdev_priv(dev); 1653 struct atmel_private *priv = netdev_priv(dev);
1647 1654
1648 /* put a brick on it... */ 1655 /* put a brick on it... */
1649 if (priv->bus_type == BUS_TYPE_PCCARD) 1656 if (priv->bus_type == BUS_TYPE_PCCARD)
1650 atmel_write16(dev, GCR, 0x0060); 1657 atmel_write16(dev, GCR, 0x0060);
1651 atmel_write16(dev, GCR, 0x0040); 1658 atmel_write16(dev, GCR, 0x0040);
1652 1659
1653 del_timer_sync(&priv->management_timer); 1660 del_timer_sync(&priv->management_timer);
1654 unregister_netdev(dev); 1661 unregister_netdev(dev);
1655 remove_proc_entry("driver/atmel", NULL); 1662 remove_proc_entry("driver/atmel", NULL);
@@ -1675,13 +1682,13 @@ static int atmel_set_essid(struct net_device *dev,
1675 int index = (dwrq->flags & IW_ENCODE_INDEX) - 1; 1682 int index = (dwrq->flags & IW_ENCODE_INDEX) - 1;
1676 1683
1677 priv->connect_to_any_BSS = 0; 1684 priv->connect_to_any_BSS = 0;
1678 1685
1679 /* Check the size of the string */ 1686 /* Check the size of the string */
1680 if (dwrq->length > MAX_SSID_LENGTH + 1) 1687 if (dwrq->length > MAX_SSID_LENGTH + 1)
1681 return -E2BIG ; 1688 return -E2BIG;
1682 if (index != 0) 1689 if (index != 0)
1683 return -EINVAL; 1690 return -EINVAL;
1684 1691
1685 memcpy(priv->new_SSID, extra, dwrq->length - 1); 1692 memcpy(priv->new_SSID, extra, dwrq->length - 1);
1686 priv->new_SSID_size = dwrq->length - 1; 1693 priv->new_SSID_size = dwrq->length - 1;
1687 } 1694 }
@@ -1706,7 +1713,7 @@ static int atmel_get_essid(struct net_device *dev,
1706 extra[priv->SSID_size] = '\0'; 1713 extra[priv->SSID_size] = '\0';
1707 dwrq->length = priv->SSID_size + 1; 1714 dwrq->length = priv->SSID_size + 1;
1708 } 1715 }
1709 1716
1710 dwrq->flags = !priv->connect_to_any_BSS; /* active */ 1717 dwrq->flags = !priv->connect_to_any_BSS; /* active */
1711 1718
1712 return 0; 1719 return 0;
@@ -1768,7 +1775,7 @@ static int atmel_set_encode(struct net_device *dev,
1768 /* WE specify that if a valid key is set, encryption 1775 /* WE specify that if a valid key is set, encryption
1769 * should be enabled (user may turn it off later) 1776 * should be enabled (user may turn it off later)
1770 * This is also how "iwconfig ethX key on" works */ 1777 * This is also how "iwconfig ethX key on" works */
1771 if (index == current_index && 1778 if (index == current_index &&
1772 priv->wep_key_len[index] > 0) { 1779 priv->wep_key_len[index] > 0) {
1773 priv->wep_is_on = 1; 1780 priv->wep_is_on = 1;
1774 priv->exclude_unencrypted = 1; 1781 priv->exclude_unencrypted = 1;
@@ -1783,18 +1790,18 @@ static int atmel_set_encode(struct net_device *dev,
1783 } else { 1790 } else {
1784 /* Do we want to just set the transmit key index ? */ 1791 /* Do we want to just set the transmit key index ? */
1785 int index = (dwrq->flags & IW_ENCODE_INDEX) - 1; 1792 int index = (dwrq->flags & IW_ENCODE_INDEX) - 1;
1786 if ( index>=0 && index < 4 ) { 1793 if (index >= 0 && index < 4) {
1787 priv->default_key = index; 1794 priv->default_key = index;
1788 } else 1795 } else
1789 /* Don't complain if only change the mode */ 1796 /* Don't complain if only change the mode */
1790 if(!dwrq->flags & IW_ENCODE_MODE) { 1797 if (!dwrq->flags & IW_ENCODE_MODE) {
1791 return -EINVAL; 1798 return -EINVAL;
1792 } 1799 }
1793 } 1800 }
1794 /* Read the flags */ 1801 /* Read the flags */
1795 if(dwrq->flags & IW_ENCODE_DISABLED) { 1802 if (dwrq->flags & IW_ENCODE_DISABLED) {
1796 priv->wep_is_on = 0; 1803 priv->wep_is_on = 0;
1797 priv->encryption_level = 0; 1804 priv->encryption_level = 0;
1798 priv->pairwise_cipher_suite = CIPHER_SUITE_NONE; 1805 priv->pairwise_cipher_suite = CIPHER_SUITE_NONE;
1799 } else { 1806 } else {
1800 priv->wep_is_on = 1; 1807 priv->wep_is_on = 1;
@@ -1806,15 +1813,14 @@ static int atmel_set_encode(struct net_device *dev,
1806 priv->encryption_level = 1; 1813 priv->encryption_level = 1;
1807 } 1814 }
1808 } 1815 }
1809 if(dwrq->flags & IW_ENCODE_RESTRICTED) 1816 if (dwrq->flags & IW_ENCODE_RESTRICTED)
1810 priv->exclude_unencrypted = 1; 1817 priv->exclude_unencrypted = 1;
1811 if(dwrq->flags & IW_ENCODE_OPEN) 1818 if(dwrq->flags & IW_ENCODE_OPEN)
1812 priv->exclude_unencrypted = 0; 1819 priv->exclude_unencrypted = 0;
1813 1820
1814 return -EINPROGRESS; /* Call commit handler */ 1821 return -EINPROGRESS; /* Call commit handler */
1815} 1822}
1816 1823
1817
1818static int atmel_get_encode(struct net_device *dev, 1824static int atmel_get_encode(struct net_device *dev,
1819 struct iw_request_info *info, 1825 struct iw_request_info *info,
1820 struct iw_point *dwrq, 1826 struct iw_point *dwrq,
@@ -1822,7 +1828,7 @@ static int atmel_get_encode(struct net_device *dev,
1822{ 1828{
1823 struct atmel_private *priv = netdev_priv(dev); 1829 struct atmel_private *priv = netdev_priv(dev);
1824 int index = (dwrq->flags & IW_ENCODE_INDEX) - 1; 1830 int index = (dwrq->flags & IW_ENCODE_INDEX) - 1;
1825 1831
1826 if (!priv->wep_is_on) 1832 if (!priv->wep_is_on)
1827 dwrq->flags = IW_ENCODE_DISABLED; 1833 dwrq->flags = IW_ENCODE_DISABLED;
1828 else { 1834 else {
@@ -1843,7 +1849,7 @@ static int atmel_get_encode(struct net_device *dev,
1843 memset(extra, 0, 16); 1849 memset(extra, 0, 16);
1844 memcpy(extra, priv->wep_keys[index], dwrq->length); 1850 memcpy(extra, priv->wep_keys[index], dwrq->length);
1845 } 1851 }
1846 1852
1847 return 0; 1853 return 0;
1848} 1854}
1849 1855
@@ -1862,17 +1868,17 @@ static int atmel_set_rate(struct net_device *dev,
1862 char *extra) 1868 char *extra)
1863{ 1869{
1864 struct atmel_private *priv = netdev_priv(dev); 1870 struct atmel_private *priv = netdev_priv(dev);
1865 1871
1866 if (vwrq->fixed == 0) { 1872 if (vwrq->fixed == 0) {
1867 priv->tx_rate = 3; 1873 priv->tx_rate = 3;
1868 priv->auto_tx_rate = 1; 1874 priv->auto_tx_rate = 1;
1869 } else { 1875 } else {
1870 priv->auto_tx_rate = 0; 1876 priv->auto_tx_rate = 0;
1871 1877
1872 /* Which type of value ? */ 1878 /* Which type of value ? */
1873 if((vwrq->value < 4) && (vwrq->value >= 0)) { 1879 if ((vwrq->value < 4) && (vwrq->value >= 0)) {
1874 /* Setting by rate index */ 1880 /* Setting by rate index */
1875 priv->tx_rate = vwrq->value; 1881 priv->tx_rate = vwrq->value;
1876 } else { 1882 } else {
1877 /* Setting by frequency value */ 1883 /* Setting by frequency value */
1878 switch (vwrq->value) { 1884 switch (vwrq->value) {
@@ -1899,7 +1905,7 @@ static int atmel_set_mode(struct net_device *dev,
1899 return -EINVAL; 1905 return -EINVAL;
1900 1906
1901 priv->operating_mode = *uwrq; 1907 priv->operating_mode = *uwrq;
1902 return -EINPROGRESS; 1908 return -EINPROGRESS;
1903} 1909}
1904 1910
1905static int atmel_get_mode(struct net_device *dev, 1911static int atmel_get_mode(struct net_device *dev,
@@ -1908,7 +1914,7 @@ static int atmel_get_mode(struct net_device *dev,
1908 char *extra) 1914 char *extra)
1909{ 1915{
1910 struct atmel_private *priv = netdev_priv(dev); 1916 struct atmel_private *priv = netdev_priv(dev);
1911 1917
1912 *uwrq = priv->operating_mode; 1918 *uwrq = priv->operating_mode;
1913 return 0; 1919 return 0;
1914} 1920}
@@ -1962,9 +1968,9 @@ static int atmel_set_retry(struct net_device *dev,
1962 char *extra) 1968 char *extra)
1963{ 1969{
1964 struct atmel_private *priv = netdev_priv(dev); 1970 struct atmel_private *priv = netdev_priv(dev);
1965 1971
1966 if(!vwrq->disabled && (vwrq->flags & IW_RETRY_LIMIT)) { 1972 if (!vwrq->disabled && (vwrq->flags & IW_RETRY_LIMIT)) {
1967 if(vwrq->flags & IW_RETRY_MAX) 1973 if (vwrq->flags & IW_RETRY_MAX)
1968 priv->long_retry = vwrq->value; 1974 priv->long_retry = vwrq->value;
1969 else if (vwrq->flags & IW_RETRY_MIN) 1975 else if (vwrq->flags & IW_RETRY_MIN)
1970 priv->short_retry = vwrq->value; 1976 priv->short_retry = vwrq->value;
@@ -1973,9 +1979,9 @@ static int atmel_set_retry(struct net_device *dev,
1973 priv->long_retry = vwrq->value; 1979 priv->long_retry = vwrq->value;
1974 priv->short_retry = vwrq->value; 1980 priv->short_retry = vwrq->value;
1975 } 1981 }
1976 return -EINPROGRESS; 1982 return -EINPROGRESS;
1977 } 1983 }
1978 1984
1979 return -EINVAL; 1985 return -EINVAL;
1980} 1986}
1981 1987
@@ -1989,13 +1995,13 @@ static int atmel_get_retry(struct net_device *dev,
1989 vwrq->disabled = 0; /* Can't be disabled */ 1995 vwrq->disabled = 0; /* Can't be disabled */
1990 1996
1991 /* Note : by default, display the min retry number */ 1997 /* Note : by default, display the min retry number */
1992 if((vwrq->flags & IW_RETRY_MAX)) { 1998 if (vwrq->flags & IW_RETRY_MAX) {
1993 vwrq->flags = IW_RETRY_LIMIT | IW_RETRY_MAX; 1999 vwrq->flags = IW_RETRY_LIMIT | IW_RETRY_MAX;
1994 vwrq->value = priv->long_retry; 2000 vwrq->value = priv->long_retry;
1995 } else { 2001 } else {
1996 vwrq->flags = IW_RETRY_LIMIT; 2002 vwrq->flags = IW_RETRY_LIMIT;
1997 vwrq->value = priv->short_retry; 2003 vwrq->value = priv->short_retry;
1998 if(priv->long_retry != priv->short_retry) 2004 if (priv->long_retry != priv->short_retry)
1999 vwrq->flags |= IW_RETRY_MIN; 2005 vwrq->flags |= IW_RETRY_MIN;
2000 } 2006 }
2001 2007
@@ -2010,13 +2016,13 @@ static int atmel_set_rts(struct net_device *dev,
2010 struct atmel_private *priv = netdev_priv(dev); 2016 struct atmel_private *priv = netdev_priv(dev);
2011 int rthr = vwrq->value; 2017 int rthr = vwrq->value;
2012 2018
2013 if(vwrq->disabled) 2019 if (vwrq->disabled)
2014 rthr = 2347; 2020 rthr = 2347;
2015 if((rthr < 0) || (rthr > 2347)) { 2021 if ((rthr < 0) || (rthr > 2347)) {
2016 return -EINVAL; 2022 return -EINVAL;
2017 } 2023 }
2018 priv->rts_threshold = rthr; 2024 priv->rts_threshold = rthr;
2019 2025
2020 return -EINPROGRESS; /* Call commit handler */ 2026 return -EINPROGRESS; /* Call commit handler */
2021} 2027}
2022 2028
@@ -2026,7 +2032,7 @@ static int atmel_get_rts(struct net_device *dev,
2026 char *extra) 2032 char *extra)
2027{ 2033{
2028 struct atmel_private *priv = netdev_priv(dev); 2034 struct atmel_private *priv = netdev_priv(dev);
2029 2035
2030 vwrq->value = priv->rts_threshold; 2036 vwrq->value = priv->rts_threshold;
2031 vwrq->disabled = (vwrq->value >= 2347); 2037 vwrq->disabled = (vwrq->value >= 2347);
2032 vwrq->fixed = 1; 2038 vwrq->fixed = 1;
@@ -2042,14 +2048,14 @@ static int atmel_set_frag(struct net_device *dev,
2042 struct atmel_private *priv = netdev_priv(dev); 2048 struct atmel_private *priv = netdev_priv(dev);
2043 int fthr = vwrq->value; 2049 int fthr = vwrq->value;
2044 2050
2045 if(vwrq->disabled) 2051 if (vwrq->disabled)
2046 fthr = 2346; 2052 fthr = 2346;
2047 if((fthr < 256) || (fthr > 2346)) { 2053 if ((fthr < 256) || (fthr > 2346)) {
2048 return -EINVAL; 2054 return -EINVAL;
2049 } 2055 }
2050 fthr &= ~0x1; /* Get an even value - is it really needed ??? */ 2056 fthr &= ~0x1; /* Get an even value - is it really needed ??? */
2051 priv->frag_threshold = fthr; 2057 priv->frag_threshold = fthr;
2052 2058
2053 return -EINPROGRESS; /* Call commit handler */ 2059 return -EINPROGRESS; /* Call commit handler */
2054} 2060}
2055 2061
@@ -2077,21 +2083,21 @@ static int atmel_set_freq(struct net_device *dev,
2077{ 2083{
2078 struct atmel_private *priv = netdev_priv(dev); 2084 struct atmel_private *priv = netdev_priv(dev);
2079 int rc = -EINPROGRESS; /* Call commit handler */ 2085 int rc = -EINPROGRESS; /* Call commit handler */
2080 2086
2081 /* If setting by frequency, convert to a channel */ 2087 /* If setting by frequency, convert to a channel */
2082 if((fwrq->e == 1) && 2088 if ((fwrq->e == 1) &&
2083 (fwrq->m >= (int) 241200000) && 2089 (fwrq->m >= (int) 241200000) &&
2084 (fwrq->m <= (int) 248700000)) { 2090 (fwrq->m <= (int) 248700000)) {
2085 int f = fwrq->m / 100000; 2091 int f = fwrq->m / 100000;
2086 int c = 0; 2092 int c = 0;
2087 while((c < 14) && (f != frequency_list[c])) 2093 while ((c < 14) && (f != frequency_list[c]))
2088 c++; 2094 c++;
2089 /* Hack to fall through... */ 2095 /* Hack to fall through... */
2090 fwrq->e = 0; 2096 fwrq->e = 0;
2091 fwrq->m = c + 1; 2097 fwrq->m = c + 1;
2092 } 2098 }
2093 /* Setting by channel number */ 2099 /* Setting by channel number */
2094 if((fwrq->m > 1000) || (fwrq->e > 0)) 2100 if ((fwrq->m > 1000) || (fwrq->e > 0))
2095 rc = -EOPNOTSUPP; 2101 rc = -EOPNOTSUPP;
2096 else { 2102 else {
2097 int channel = fwrq->m; 2103 int channel = fwrq->m;
@@ -2099,7 +2105,7 @@ static int atmel_set_freq(struct net_device *dev,
2099 priv->channel = channel; 2105 priv->channel = channel;
2100 } else { 2106 } else {
2101 rc = -EINVAL; 2107 rc = -EINVAL;
2102 } 2108 }
2103 } 2109 }
2104 return rc; 2110 return rc;
2105} 2111}
@@ -2130,7 +2136,7 @@ static int atmel_set_scan(struct net_device *dev,
2130 * This is not an error, while the device perform scanning, 2136 * This is not an error, while the device perform scanning,
2131 * traffic doesn't flow, so it's a perfect DoS... 2137 * traffic doesn't flow, so it's a perfect DoS...
2132 * Jean II */ 2138 * Jean II */
2133 2139
2134 if (priv->station_state == STATION_STATE_DOWN) 2140 if (priv->station_state == STATION_STATE_DOWN)
2135 return -EAGAIN; 2141 return -EAGAIN;
2136 2142
@@ -2142,15 +2148,15 @@ static int atmel_set_scan(struct net_device *dev,
2142 /* Initiate a scan command */ 2148 /* Initiate a scan command */
2143 if (priv->site_survey_state == SITE_SURVEY_IN_PROGRESS) 2149 if (priv->site_survey_state == SITE_SURVEY_IN_PROGRESS)
2144 return -EBUSY; 2150 return -EBUSY;
2145 2151
2146 del_timer_sync(&priv->management_timer); 2152 del_timer_sync(&priv->management_timer);
2147 spin_lock_irqsave(&priv->irqlock, flags); 2153 spin_lock_irqsave(&priv->irqlock, flags);
2148 2154
2149 priv->site_survey_state = SITE_SURVEY_IN_PROGRESS; 2155 priv->site_survey_state = SITE_SURVEY_IN_PROGRESS;
2150 priv->fast_scan = 0; 2156 priv->fast_scan = 0;
2151 atmel_scan(priv, 0); 2157 atmel_scan(priv, 0);
2152 spin_unlock_irqrestore(&priv->irqlock, flags); 2158 spin_unlock_irqrestore(&priv->irqlock, flags);
2153 2159
2154 return 0; 2160 return 0;
2155} 2161}
2156 2162
@@ -2163,11 +2169,11 @@ static int atmel_get_scan(struct net_device *dev,
2163 int i; 2169 int i;
2164 char *current_ev = extra; 2170 char *current_ev = extra;
2165 struct iw_event iwe; 2171 struct iw_event iwe;
2166 2172
2167 if (priv->site_survey_state != SITE_SURVEY_COMPLETED) 2173 if (priv->site_survey_state != SITE_SURVEY_COMPLETED)
2168 return -EAGAIN; 2174 return -EAGAIN;
2169 2175
2170 for(i=0; i<priv->BSS_list_entries; i++) { 2176 for (i = 0; i < priv->BSS_list_entries; i++) {
2171 iwe.cmd = SIOCGIWAP; 2177 iwe.cmd = SIOCGIWAP;
2172 iwe.u.ap_addr.sa_family = ARPHRD_ETHER; 2178 iwe.u.ap_addr.sa_family = ARPHRD_ETHER;
2173 memcpy(iwe.u.ap_addr.sa_data, priv->BSSinfo[i].BSSID, 6); 2179 memcpy(iwe.u.ap_addr.sa_data, priv->BSSinfo[i].BSSID, 6);
@@ -2179,16 +2185,16 @@ static int atmel_get_scan(struct net_device *dev,
2179 iwe.cmd = SIOCGIWESSID; 2185 iwe.cmd = SIOCGIWESSID;
2180 iwe.u.data.flags = 1; 2186 iwe.u.data.flags = 1;
2181 current_ev = iwe_stream_add_point(current_ev, extra + IW_SCAN_MAX_DATA, &iwe, priv->BSSinfo[i].SSID); 2187 current_ev = iwe_stream_add_point(current_ev, extra + IW_SCAN_MAX_DATA, &iwe, priv->BSSinfo[i].SSID);
2182 2188
2183 iwe.cmd = SIOCGIWMODE; 2189 iwe.cmd = SIOCGIWMODE;
2184 iwe.u.mode = priv->BSSinfo[i].BSStype; 2190 iwe.u.mode = priv->BSSinfo[i].BSStype;
2185 current_ev = iwe_stream_add_event(current_ev, extra + IW_SCAN_MAX_DATA, &iwe, IW_EV_UINT_LEN); 2191 current_ev = iwe_stream_add_event(current_ev, extra + IW_SCAN_MAX_DATA, &iwe, IW_EV_UINT_LEN);
2186 2192
2187 iwe.cmd = SIOCGIWFREQ; 2193 iwe.cmd = SIOCGIWFREQ;
2188 iwe.u.freq.m = priv->BSSinfo[i].channel; 2194 iwe.u.freq.m = priv->BSSinfo[i].channel;
2189 iwe.u.freq.e = 0; 2195 iwe.u.freq.e = 0;
2190 current_ev = iwe_stream_add_event(current_ev, extra + IW_SCAN_MAX_DATA, &iwe, IW_EV_FREQ_LEN); 2196 current_ev = iwe_stream_add_event(current_ev, extra + IW_SCAN_MAX_DATA, &iwe, IW_EV_FREQ_LEN);
2191 2197
2192 iwe.cmd = SIOCGIWENCODE; 2198 iwe.cmd = SIOCGIWENCODE;
2193 if (priv->BSSinfo[i].UsingWEP) 2199 if (priv->BSSinfo[i].UsingWEP)
2194 iwe.u.data.flags = IW_ENCODE_ENABLED | IW_ENCODE_NOKEY; 2200 iwe.u.data.flags = IW_ENCODE_ENABLED | IW_ENCODE_NOKEY;
@@ -2196,13 +2202,12 @@ static int atmel_get_scan(struct net_device *dev,
2196 iwe.u.data.flags = IW_ENCODE_DISABLED; 2202 iwe.u.data.flags = IW_ENCODE_DISABLED;
2197 iwe.u.data.length = 0; 2203 iwe.u.data.length = 0;
2198 current_ev = iwe_stream_add_point(current_ev, extra + IW_SCAN_MAX_DATA, &iwe, NULL); 2204 current_ev = iwe_stream_add_point(current_ev, extra + IW_SCAN_MAX_DATA, &iwe, NULL);
2199
2200 } 2205 }
2201 2206
2202 /* Length of data */ 2207 /* Length of data */
2203 dwrq->length = (current_ev - extra); 2208 dwrq->length = (current_ev - extra);
2204 dwrq->flags = 0; 2209 dwrq->flags = 0;
2205 2210
2206 return 0; 2211 return 0;
2207} 2212}
2208 2213
@@ -2213,7 +2218,7 @@ static int atmel_get_range(struct net_device *dev,
2213{ 2218{
2214 struct atmel_private *priv = netdev_priv(dev); 2219 struct atmel_private *priv = netdev_priv(dev);
2215 struct iw_range *range = (struct iw_range *) extra; 2220 struct iw_range *range = (struct iw_range *) extra;
2216 int k,i,j; 2221 int k, i, j;
2217 2222
2218 dwrq->length = sizeof(struct iw_range); 2223 dwrq->length = sizeof(struct iw_range);
2219 memset(range, 0, sizeof(struct iw_range)); 2224 memset(range, 0, sizeof(struct iw_range));
@@ -2226,14 +2231,14 @@ static int atmel_get_range(struct net_device *dev,
2226 break; 2231 break;
2227 } 2232 }
2228 if (range->num_channels != 0) { 2233 if (range->num_channels != 0) {
2229 for(k = 0, i = channel_table[j].min; i <= channel_table[j].max; i++) { 2234 for (k = 0, i = channel_table[j].min; i <= channel_table[j].max; i++) {
2230 range->freq[k].i = i; /* List index */ 2235 range->freq[k].i = i; /* List index */
2231 range->freq[k].m = frequency_list[i-1] * 100000; 2236 range->freq[k].m = frequency_list[i - 1] * 100000;
2232 range->freq[k++].e = 1; /* Values in table in MHz -> * 10^5 * 10 */ 2237 range->freq[k++].e = 1; /* Values in table in MHz -> * 10^5 * 10 */
2233 } 2238 }
2234 range->num_frequency = k; 2239 range->num_frequency = k;
2235 } 2240 }
2236 2241
2237 range->max_qual.qual = 100; 2242 range->max_qual.qual = 100;
2238 range->max_qual.level = 100; 2243 range->max_qual.level = 100;
2239 range->max_qual.noise = 0; 2244 range->max_qual.noise = 0;
@@ -2261,11 +2266,11 @@ static int atmel_get_range(struct net_device *dev,
2261 range->encoding_size[1] = 13; 2266 range->encoding_size[1] = 13;
2262 range->num_encoding_sizes = 2; 2267 range->num_encoding_sizes = 2;
2263 range->max_encoding_tokens = 4; 2268 range->max_encoding_tokens = 4;
2264 2269
2265 range->pmp_flags = IW_POWER_ON; 2270 range->pmp_flags = IW_POWER_ON;
2266 range->pmt_flags = IW_POWER_ON; 2271 range->pmt_flags = IW_POWER_ON;
2267 range->pm_capa = 0; 2272 range->pm_capa = 0;
2268 2273
2269 range->we_version_source = WIRELESS_EXT; 2274 range->we_version_source = WIRELESS_EXT;
2270 range->we_version_compiled = WIRELESS_EXT; 2275 range->we_version_compiled = WIRELESS_EXT;
2271 range->retry_capa = IW_RETRY_LIMIT ; 2276 range->retry_capa = IW_RETRY_LIMIT ;
@@ -2289,7 +2294,7 @@ static int atmel_set_wap(struct net_device *dev,
2289 2294
2290 if (awrq->sa_family != ARPHRD_ETHER) 2295 if (awrq->sa_family != ARPHRD_ETHER)
2291 return -EINVAL; 2296 return -EINVAL;
2292 2297
2293 if (memcmp(bcast, awrq->sa_data, 6) == 0) { 2298 if (memcmp(bcast, awrq->sa_data, 6) == 0) {
2294 del_timer_sync(&priv->management_timer); 2299 del_timer_sync(&priv->management_timer);
2295 spin_lock_irqsave(&priv->irqlock, flags); 2300 spin_lock_irqsave(&priv->irqlock, flags);
@@ -2297,8 +2302,8 @@ static int atmel_set_wap(struct net_device *dev,
2297 spin_unlock_irqrestore(&priv->irqlock, flags); 2302 spin_unlock_irqrestore(&priv->irqlock, flags);
2298 return 0; 2303 return 0;
2299 } 2304 }
2300 2305
2301 for(i=0; i<priv->BSS_list_entries; i++) { 2306 for (i = 0; i < priv->BSS_list_entries; i++) {
2302 if (memcmp(priv->BSSinfo[i].BSSID, awrq->sa_data, 6) == 0) { 2307 if (memcmp(priv->BSSinfo[i].BSSID, awrq->sa_data, 6) == 0) {
2303 if (!priv->wep_is_on && priv->BSSinfo[i].UsingWEP) { 2308 if (!priv->wep_is_on && priv->BSSinfo[i].UsingWEP) {
2304 return -EINVAL; 2309 return -EINVAL;
@@ -2313,10 +2318,10 @@ static int atmel_set_wap(struct net_device *dev,
2313 } 2318 }
2314 } 2319 }
2315 } 2320 }
2316 2321
2317 return -EINVAL; 2322 return -EINVAL;
2318} 2323}
2319 2324
2320static int atmel_config_commit(struct net_device *dev, 2325static int atmel_config_commit(struct net_device *dev,
2321 struct iw_request_info *info, /* NULL */ 2326 struct iw_request_info *info, /* NULL */
2322 void *zwrq, /* NULL */ 2327 void *zwrq, /* NULL */
@@ -2325,18 +2330,18 @@ static int atmel_config_commit(struct net_device *dev,
2325 return atmel_open(dev); 2330 return atmel_open(dev);
2326} 2331}
2327 2332
2328static const iw_handler atmel_handler[] = 2333static const iw_handler atmel_handler[] =
2329{ 2334{
2330 (iw_handler) atmel_config_commit, /* SIOCSIWCOMMIT */ 2335 (iw_handler) atmel_config_commit, /* SIOCSIWCOMMIT */
2331 (iw_handler) atmel_get_name, /* SIOCGIWNAME */ 2336 (iw_handler) atmel_get_name, /* SIOCGIWNAME */
2332 (iw_handler) NULL, /* SIOCSIWNWID */ 2337 (iw_handler) NULL, /* SIOCSIWNWID */
2333 (iw_handler) NULL, /* SIOCGIWNWID */ 2338 (iw_handler) NULL, /* SIOCGIWNWID */
2334 (iw_handler) atmel_set_freq, /* SIOCSIWFREQ */ 2339 (iw_handler) atmel_set_freq, /* SIOCSIWFREQ */
2335 (iw_handler) atmel_get_freq, /* SIOCGIWFREQ */ 2340 (iw_handler) atmel_get_freq, /* SIOCGIWFREQ */
2336 (iw_handler) atmel_set_mode, /* SIOCSIWMODE */ 2341 (iw_handler) atmel_set_mode, /* SIOCSIWMODE */
2337 (iw_handler) atmel_get_mode, /* SIOCGIWMODE */ 2342 (iw_handler) atmel_get_mode, /* SIOCGIWMODE */
2338 (iw_handler) NULL, /* SIOCSIWSENS */ 2343 (iw_handler) NULL, /* SIOCSIWSENS */
2339 (iw_handler) NULL, /* SIOCGIWSENS */ 2344 (iw_handler) NULL, /* SIOCGIWSENS */
2340 (iw_handler) NULL, /* SIOCSIWRANGE */ 2345 (iw_handler) NULL, /* SIOCSIWRANGE */
2341 (iw_handler) atmel_get_range, /* SIOCGIWRANGE */ 2346 (iw_handler) atmel_get_range, /* SIOCGIWRANGE */
2342 (iw_handler) NULL, /* SIOCSIWPRIV */ 2347 (iw_handler) NULL, /* SIOCSIWPRIV */
@@ -2350,13 +2355,13 @@ static const iw_handler atmel_handler[] =
2350 (iw_handler) atmel_set_wap, /* SIOCSIWAP */ 2355 (iw_handler) atmel_set_wap, /* SIOCSIWAP */
2351 (iw_handler) atmel_get_wap, /* SIOCGIWAP */ 2356 (iw_handler) atmel_get_wap, /* SIOCGIWAP */
2352 (iw_handler) NULL, /* -- hole -- */ 2357 (iw_handler) NULL, /* -- hole -- */
2353 (iw_handler) NULL, /* SIOCGIWAPLIST */ 2358 (iw_handler) NULL, /* SIOCGIWAPLIST */
2354 (iw_handler) atmel_set_scan, /* SIOCSIWSCAN */ 2359 (iw_handler) atmel_set_scan, /* SIOCSIWSCAN */
2355 (iw_handler) atmel_get_scan, /* SIOCGIWSCAN */ 2360 (iw_handler) atmel_get_scan, /* SIOCGIWSCAN */
2356 (iw_handler) atmel_set_essid, /* SIOCSIWESSID */ 2361 (iw_handler) atmel_set_essid, /* SIOCSIWESSID */
2357 (iw_handler) atmel_get_essid, /* SIOCGIWESSID */ 2362 (iw_handler) atmel_get_essid, /* SIOCGIWESSID */
2358 (iw_handler) NULL, /* SIOCSIWNICKN */ 2363 (iw_handler) NULL, /* SIOCSIWNICKN */
2359 (iw_handler) NULL, /* SIOCGIWNICKN */ 2364 (iw_handler) NULL, /* SIOCGIWNICKN */
2360 (iw_handler) NULL, /* -- hole -- */ 2365 (iw_handler) NULL, /* -- hole -- */
2361 (iw_handler) NULL, /* -- hole -- */ 2366 (iw_handler) NULL, /* -- hole -- */
2362 (iw_handler) atmel_set_rate, /* SIOCSIWRATE */ 2367 (iw_handler) atmel_set_rate, /* SIOCSIWRATE */
@@ -2365,8 +2370,8 @@ static const iw_handler atmel_handler[] =
2365 (iw_handler) atmel_get_rts, /* SIOCGIWRTS */ 2370 (iw_handler) atmel_get_rts, /* SIOCGIWRTS */
2366 (iw_handler) atmel_set_frag, /* SIOCSIWFRAG */ 2371 (iw_handler) atmel_set_frag, /* SIOCSIWFRAG */
2367 (iw_handler) atmel_get_frag, /* SIOCGIWFRAG */ 2372 (iw_handler) atmel_get_frag, /* SIOCGIWFRAG */
2368 (iw_handler) NULL, /* SIOCSIWTXPOW */ 2373 (iw_handler) NULL, /* SIOCSIWTXPOW */
2369 (iw_handler) NULL, /* SIOCGIWTXPOW */ 2374 (iw_handler) NULL, /* SIOCGIWTXPOW */
2370 (iw_handler) atmel_set_retry, /* SIOCSIWRETRY */ 2375 (iw_handler) atmel_set_retry, /* SIOCSIWRETRY */
2371 (iw_handler) atmel_get_retry, /* SIOCGIWRETRY */ 2376 (iw_handler) atmel_get_retry, /* SIOCGIWRETRY */
2372 (iw_handler) atmel_set_encode, /* SIOCSIWENCODE */ 2377 (iw_handler) atmel_set_encode, /* SIOCSIWENCODE */
@@ -2375,39 +2380,51 @@ static const iw_handler atmel_handler[] =
2375 (iw_handler) atmel_get_power, /* SIOCGIWPOWER */ 2380 (iw_handler) atmel_get_power, /* SIOCGIWPOWER */
2376}; 2381};
2377 2382
2378 2383static const iw_handler atmel_private_handler[] =
2379static const iw_handler atmel_private_handler[] =
2380{ 2384{
2381 NULL, /* SIOCIWFIRSTPRIV */ 2385 NULL, /* SIOCIWFIRSTPRIV */
2382}; 2386};
2383 2387
2384typedef struct atmel_priv_ioctl { 2388typedef struct atmel_priv_ioctl {
2385 char id[32]; 2389 char id[32];
2386 unsigned char __user *data; 2390 unsigned char __user *data;
2387 unsigned short len; 2391 unsigned short len;
2388} atmel_priv_ioctl; 2392} atmel_priv_ioctl;
2389 2393
2390 2394#define ATMELFWL SIOCIWFIRSTPRIV
2391#define ATMELFWL SIOCIWFIRSTPRIV 2395#define ATMELIDIFC ATMELFWL + 1
2392#define ATMELIDIFC ATMELFWL + 1 2396#define ATMELRD ATMELFWL + 2
2393#define ATMELRD ATMELFWL + 2 2397#define ATMELMAGIC 0x51807
2394#define ATMELMAGIC 0x51807
2395#define REGDOMAINSZ 20 2398#define REGDOMAINSZ 20
2396 2399
2397static const struct iw_priv_args atmel_private_args[] = { 2400static const struct iw_priv_args atmel_private_args[] = {
2398/*{ cmd, set_args, get_args, name } */ 2401 {
2399 { ATMELFWL, IW_PRIV_TYPE_BYTE | IW_PRIV_SIZE_FIXED | sizeof (atmel_priv_ioctl), IW_PRIV_TYPE_NONE, "atmelfwl" }, 2402 .cmd = ATMELFWL,
2400 { ATMELIDIFC, IW_PRIV_TYPE_NONE, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "atmelidifc" }, 2403 .set_args = IW_PRIV_TYPE_BYTE
2401 { ATMELRD, IW_PRIV_TYPE_CHAR | REGDOMAINSZ, IW_PRIV_TYPE_NONE, "regdomain" }, 2404 | IW_PRIV_SIZE_FIXED
2405 | sizeof (atmel_priv_ioctl),
2406 .get_args = IW_PRIV_TYPE_NONE,
2407 .name = "atmelfwl"
2408 }, {
2409 .cmd = ATMELIDIFC,
2410 .set_args = IW_PRIV_TYPE_NONE,
2411 .get_args = IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
2412 .name = "atmelidifc"
2413 }, {
2414 .cmd = ATMELRD,
2415 .set_args = IW_PRIV_TYPE_CHAR | REGDOMAINSZ,
2416 .get_args = IW_PRIV_TYPE_NONE,
2417 .name = "regdomain"
2418 },
2402}; 2419};
2403 2420
2404static const struct iw_handler_def atmel_handler_def = 2421static const struct iw_handler_def atmel_handler_def =
2405{ 2422{
2406 .num_standard = sizeof(atmel_handler)/sizeof(iw_handler), 2423 .num_standard = sizeof(atmel_handler)/sizeof(iw_handler),
2407 .num_private = sizeof(atmel_private_handler)/sizeof(iw_handler), 2424 .num_private = sizeof(atmel_private_handler)/sizeof(iw_handler),
2408 .num_private_args = sizeof(atmel_private_args)/sizeof(struct iw_priv_args), 2425 .num_private_args = sizeof(atmel_private_args)/sizeof(struct iw_priv_args),
2409 .standard = (iw_handler *) atmel_handler, 2426 .standard = (iw_handler *) atmel_handler,
2410 .private = (iw_handler *) atmel_private_handler, 2427 .private = (iw_handler *) atmel_private_handler,
2411 .private_args = (struct iw_priv_args *) atmel_private_args, 2428 .private_args = (struct iw_priv_args *) atmel_private_args,
2412 .get_wireless_stats = atmel_get_wireless_stats 2429 .get_wireless_stats = atmel_get_wireless_stats
2413}; 2430};
@@ -2419,13 +2436,13 @@ static int atmel_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
2419 atmel_priv_ioctl com; 2436 atmel_priv_ioctl com;
2420 struct iwreq *wrq = (struct iwreq *) rq; 2437 struct iwreq *wrq = (struct iwreq *) rq;
2421 unsigned char *new_firmware; 2438 unsigned char *new_firmware;
2422 char domain[REGDOMAINSZ+1]; 2439 char domain[REGDOMAINSZ + 1];
2423 2440
2424 switch (cmd) { 2441 switch (cmd) {
2425 case ATMELIDIFC: 2442 case ATMELIDIFC:
2426 wrq->u.param.value = ATMELMAGIC; 2443 wrq->u.param.value = ATMELMAGIC;
2427 break; 2444 break;
2428 2445
2429 case ATMELFWL: 2446 case ATMELFWL:
2430 if (copy_from_user(&com, rq->ifr_data, sizeof(com))) { 2447 if (copy_from_user(&com, rq->ifr_data, sizeof(com))) {
2431 rc = -EFAULT; 2448 rc = -EFAULT;
@@ -2449,7 +2466,7 @@ static int atmel_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
2449 } 2466 }
2450 2467
2451 kfree(priv->firmware); 2468 kfree(priv->firmware);
2452 2469
2453 priv->firmware = new_firmware; 2470 priv->firmware = new_firmware;
2454 priv->firmware_length = com.len; 2471 priv->firmware_length = com.len;
2455 strncpy(priv->firmware_id, com.id, 31); 2472 strncpy(priv->firmware_id, com.id, 31);
@@ -2461,7 +2478,7 @@ static int atmel_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
2461 rc = -EFAULT; 2478 rc = -EFAULT;
2462 break; 2479 break;
2463 } 2480 }
2464 2481
2465 if (!capable(CAP_NET_ADMIN)) { 2482 if (!capable(CAP_NET_ADMIN)) {
2466 rc = -EPERM; 2483 rc = -EPERM;
2467 break; 2484 break;
@@ -2484,15 +2501,15 @@ static int atmel_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
2484 rc = 0; 2501 rc = 0;
2485 } 2502 }
2486 } 2503 }
2487 2504
2488 if (rc == 0 && priv->station_state != STATION_STATE_DOWN) 2505 if (rc == 0 && priv->station_state != STATION_STATE_DOWN)
2489 rc = atmel_open(dev); 2506 rc = atmel_open(dev);
2490 break; 2507 break;
2491 2508
2492 default: 2509 default:
2493 rc = -EOPNOTSUPP; 2510 rc = -EOPNOTSUPP;
2494 } 2511 }
2495 2512
2496 return rc; 2513 return rc;
2497} 2514}
2498 2515
@@ -2503,17 +2520,17 @@ struct auth_body {
2503 u8 el_id; 2520 u8 el_id;
2504 u8 chall_text_len; 2521 u8 chall_text_len;
2505 u8 chall_text[253]; 2522 u8 chall_text[253];
2506}; 2523};
2507 2524
2508static void atmel_enter_state(struct atmel_private *priv, int new_state) 2525static void atmel_enter_state(struct atmel_private *priv, int new_state)
2509{ 2526{
2510 int old_state = priv->station_state; 2527 int old_state = priv->station_state;
2511 2528
2512 if (new_state == old_state) 2529 if (new_state == old_state)
2513 return; 2530 return;
2514 2531
2515 priv->station_state = new_state; 2532 priv->station_state = new_state;
2516 2533
2517 if (new_state == STATION_STATE_READY) { 2534 if (new_state == STATION_STATE_READY) {
2518 netif_start_queue(priv->dev); 2535 netif_start_queue(priv->dev);
2519 netif_carrier_on(priv->dev); 2536 netif_carrier_on(priv->dev);
@@ -2540,7 +2557,7 @@ static void atmel_scan(struct atmel_private *priv, int specific_ssid)
2540 u8 options; 2557 u8 options;
2541 u8 SSID_size; 2558 u8 SSID_size;
2542 } cmd; 2559 } cmd;
2543 2560
2544 memset(cmd.BSSID, 0xff, 6); 2561 memset(cmd.BSSID, 0xff, 6);
2545 2562
2546 if (priv->fast_scan) { 2563 if (priv->fast_scan) {
@@ -2554,17 +2571,17 @@ static void atmel_scan(struct atmel_private *priv, int specific_ssid)
2554 cmd.min_channel_time = cpu_to_le16(10); 2571 cmd.min_channel_time = cpu_to_le16(10);
2555 cmd.max_channel_time = cpu_to_le16(120); 2572 cmd.max_channel_time = cpu_to_le16(120);
2556 } 2573 }
2557 2574
2558 cmd.options = 0; 2575 cmd.options = 0;
2559 2576
2560 if (!specific_ssid) 2577 if (!specific_ssid)
2561 cmd.options |= SCAN_OPTIONS_SITE_SURVEY; 2578 cmd.options |= SCAN_OPTIONS_SITE_SURVEY;
2562 2579
2563 cmd.channel = (priv->channel & 0x7f); 2580 cmd.channel = (priv->channel & 0x7f);
2564 cmd.scan_type = SCAN_TYPE_ACTIVE; 2581 cmd.scan_type = SCAN_TYPE_ACTIVE;
2565 cmd.BSS_type = cpu_to_le16(priv->operating_mode == IW_MODE_ADHOC ? 2582 cmd.BSS_type = cpu_to_le16(priv->operating_mode == IW_MODE_ADHOC ?
2566 BSS_TYPE_AD_HOC : BSS_TYPE_INFRASTRUCTURE); 2583 BSS_TYPE_AD_HOC : BSS_TYPE_INFRASTRUCTURE);
2567 2584
2568 atmel_send_command(priv, CMD_Scan, &cmd, sizeof(cmd)); 2585 atmel_send_command(priv, CMD_Scan, &cmd, sizeof(cmd));
2569 2586
2570 /* This must come after all hardware access to avoid being messed up 2587 /* This must come after all hardware access to avoid being messed up
@@ -2591,16 +2608,15 @@ static void join(struct atmel_private *priv, int type)
2591 cmd.BSS_type = type; 2608 cmd.BSS_type = type;
2592 cmd.timeout = cpu_to_le16(2000); 2609 cmd.timeout = cpu_to_le16(2000);
2593 2610
2594 atmel_send_command(priv, CMD_Join, &cmd, sizeof(cmd)); 2611 atmel_send_command(priv, CMD_Join, &cmd, sizeof(cmd));
2595} 2612}
2596 2613
2597
2598static void start(struct atmel_private *priv, int type) 2614static void start(struct atmel_private *priv, int type)
2599{ 2615{
2600 struct { 2616 struct {
2601 u8 BSSID[6]; 2617 u8 BSSID[6];
2602 u8 SSID[MAX_SSID_LENGTH]; 2618 u8 SSID[MAX_SSID_LENGTH];
2603 u8 BSS_type; 2619 u8 BSS_type;
2604 u8 channel; 2620 u8 channel;
2605 u8 SSID_size; 2621 u8 SSID_size;
2606 u8 reserved[3]; 2622 u8 reserved[3];
@@ -2612,13 +2628,14 @@ static void start(struct atmel_private *priv, int type)
2612 cmd.BSS_type = type; 2628 cmd.BSS_type = type;
2613 cmd.channel = (priv->channel & 0x7f); 2629 cmd.channel = (priv->channel & 0x7f);
2614 2630
2615 atmel_send_command(priv, CMD_Start, &cmd, sizeof(cmd)); 2631 atmel_send_command(priv, CMD_Start, &cmd, sizeof(cmd));
2616} 2632}
2617 2633
2618static void handle_beacon_probe(struct atmel_private *priv, u16 capability, u8 channel) 2634static void handle_beacon_probe(struct atmel_private *priv, u16 capability,
2635 u8 channel)
2619{ 2636{
2620 int rejoin = 0; 2637 int rejoin = 0;
2621 int new = capability & C80211_MGMT_CAPABILITY_ShortPreamble ? 2638 int new = capability & C80211_MGMT_CAPABILITY_ShortPreamble ?
2622 SHORT_PREAMBLE : LONG_PREAMBLE; 2639 SHORT_PREAMBLE : LONG_PREAMBLE;
2623 2640
2624 if (priv->preamble != new) { 2641 if (priv->preamble != new) {
@@ -2626,48 +2643,48 @@ static void handle_beacon_probe(struct atmel_private *priv, u16 capability, u8 c
2626 rejoin = 1; 2643 rejoin = 1;
2627 atmel_set_mib8(priv, Local_Mib_Type, LOCAL_MIB_PREAMBLE_TYPE, new); 2644 atmel_set_mib8(priv, Local_Mib_Type, LOCAL_MIB_PREAMBLE_TYPE, new);
2628 } 2645 }
2629 2646
2630 if (priv->channel != channel) { 2647 if (priv->channel != channel) {
2631 priv->channel = channel; 2648 priv->channel = channel;
2632 rejoin = 1; 2649 rejoin = 1;
2633 atmel_set_mib8(priv, Phy_Mib_Type, PHY_MIB_CHANNEL_POS, channel); 2650 atmel_set_mib8(priv, Phy_Mib_Type, PHY_MIB_CHANNEL_POS, channel);
2634 } 2651 }
2635 2652
2636 if (rejoin) { 2653 if (rejoin) {
2637 priv->station_is_associated = 0; 2654 priv->station_is_associated = 0;
2638 atmel_enter_state(priv, STATION_STATE_JOINNING); 2655 atmel_enter_state(priv, STATION_STATE_JOINNING);
2639 2656
2640 if (priv->operating_mode == IW_MODE_INFRA) 2657 if (priv->operating_mode == IW_MODE_INFRA)
2641 join(priv, BSS_TYPE_INFRASTRUCTURE); 2658 join(priv, BSS_TYPE_INFRASTRUCTURE);
2642 else 2659 else
2643 join(priv, BSS_TYPE_AD_HOC); 2660 join(priv, BSS_TYPE_AD_HOC);
2644 } 2661 }
2645} 2662}
2646 2663
2647 2664static void send_authentication_request(struct atmel_private *priv, u16 system,
2648static void send_authentication_request(struct atmel_private *priv, u16 system, u8 *challenge, int challenge_len) 2665 u8 *challenge, int challenge_len)
2649{ 2666{
2650 struct ieee80211_hdr_4addr header; 2667 struct ieee80211_hdr_4addr header;
2651 struct auth_body auth; 2668 struct auth_body auth;
2652 2669
2653 header.frame_ctl = cpu_to_le16(IEEE80211_FTYPE_MGMT | IEEE80211_STYPE_AUTH); 2670 header.frame_ctl = cpu_to_le16(IEEE80211_FTYPE_MGMT | IEEE80211_STYPE_AUTH);
2654 header.duration_id = cpu_to_le16(0x8000); 2671 header.duration_id = cpu_to_le16(0x8000);
2655 header.seq_ctl = 0; 2672 header.seq_ctl = 0;
2656 memcpy(header.addr1, priv->CurrentBSSID, 6); 2673 memcpy(header.addr1, priv->CurrentBSSID, 6);
2657 memcpy(header.addr2, priv->dev->dev_addr, 6); 2674 memcpy(header.addr2, priv->dev->dev_addr, 6);
2658 memcpy(header.addr3, priv->CurrentBSSID, 6); 2675 memcpy(header.addr3, priv->CurrentBSSID, 6);
2659 2676
2660 if (priv->wep_is_on && priv->CurrentAuthentTransactionSeqNum != 1) 2677 if (priv->wep_is_on && priv->CurrentAuthentTransactionSeqNum != 1)
2661 /* no WEP for authentication frames with TrSeqNo 1 */ 2678 /* no WEP for authentication frames with TrSeqNo 1 */
2662 header.frame_ctl |= cpu_to_le16(IEEE80211_FCTL_PROTECTED); 2679 header.frame_ctl |= cpu_to_le16(IEEE80211_FCTL_PROTECTED);
2663 2680
2664 auth.alg = cpu_to_le16(system); 2681 auth.alg = cpu_to_le16(system);
2665 2682
2666 auth.status = 0; 2683 auth.status = 0;
2667 auth.trans_seq = cpu_to_le16(priv->CurrentAuthentTransactionSeqNum); 2684 auth.trans_seq = cpu_to_le16(priv->CurrentAuthentTransactionSeqNum);
2668 priv->ExpectedAuthentTransactionSeqNum = priv->CurrentAuthentTransactionSeqNum+1; 2685 priv->ExpectedAuthentTransactionSeqNum = priv->CurrentAuthentTransactionSeqNum+1;
2669 priv->CurrentAuthentTransactionSeqNum += 2; 2686 priv->CurrentAuthentTransactionSeqNum += 2;
2670 2687
2671 if (challenge_len != 0) { 2688 if (challenge_len != 0) {
2672 auth.el_id = 16; /* challenge_text */ 2689 auth.el_id = 16; /* challenge_text */
2673 auth.chall_text_len = challenge_len; 2690 auth.chall_text_len = challenge_len;
@@ -2685,7 +2702,7 @@ static void send_association_request(struct atmel_private *priv, int is_reassoc)
2685 struct ieee80211_hdr_4addr header; 2702 struct ieee80211_hdr_4addr header;
2686 struct ass_req_format { 2703 struct ass_req_format {
2687 u16 capability; 2704 u16 capability;
2688 u16 listen_interval; 2705 u16 listen_interval;
2689 u8 ap[6]; /* nothing after here directly accessible */ 2706 u8 ap[6]; /* nothing after here directly accessible */
2690 u8 ssid_el_id; 2707 u8 ssid_el_id;
2691 u8 ssid_len; 2708 u8 ssid_len;
@@ -2694,15 +2711,15 @@ static void send_association_request(struct atmel_private *priv, int is_reassoc)
2694 u8 sup_rates_len; 2711 u8 sup_rates_len;
2695 u8 rates[4]; 2712 u8 rates[4];
2696 } body; 2713 } body;
2697 2714
2698 header.frame_ctl = cpu_to_le16(IEEE80211_FTYPE_MGMT | 2715 header.frame_ctl = cpu_to_le16(IEEE80211_FTYPE_MGMT |
2699 (is_reassoc ? IEEE80211_STYPE_REASSOC_REQ : IEEE80211_STYPE_ASSOC_REQ)); 2716 (is_reassoc ? IEEE80211_STYPE_REASSOC_REQ : IEEE80211_STYPE_ASSOC_REQ));
2700 header.duration_id = cpu_to_le16(0x8000); 2717 header.duration_id = cpu_to_le16(0x8000);
2701 header.seq_ctl = 0; 2718 header.seq_ctl = 0;
2702 2719
2703 memcpy(header.addr1, priv->CurrentBSSID, 6); 2720 memcpy(header.addr1, priv->CurrentBSSID, 6);
2704 memcpy(header.addr2, priv->dev->dev_addr, 6); 2721 memcpy(header.addr2, priv->dev->dev_addr, 6);
2705 memcpy(header.addr3, priv->CurrentBSSID, 6); 2722 memcpy(header.addr3, priv->CurrentBSSID, 6);
2706 2723
2707 body.capability = cpu_to_le16(C80211_MGMT_CAPABILITY_ESS); 2724 body.capability = cpu_to_le16(C80211_MGMT_CAPABILITY_ESS);
2708 if (priv->wep_is_on) 2725 if (priv->wep_is_on)
@@ -2711,18 +2728,18 @@ static void send_association_request(struct atmel_private *priv, int is_reassoc)
2711 body.capability |= cpu_to_le16(C80211_MGMT_CAPABILITY_ShortPreamble); 2728 body.capability |= cpu_to_le16(C80211_MGMT_CAPABILITY_ShortPreamble);
2712 2729
2713 body.listen_interval = cpu_to_le16(priv->listen_interval * priv->beacon_period); 2730 body.listen_interval = cpu_to_le16(priv->listen_interval * priv->beacon_period);
2714 2731
2715 /* current AP address - only in reassoc frame */ 2732 /* current AP address - only in reassoc frame */
2716 if (is_reassoc) { 2733 if (is_reassoc) {
2717 memcpy(body.ap, priv->CurrentBSSID, 6); 2734 memcpy(body.ap, priv->CurrentBSSID, 6);
2718 ssid_el_p = (u8 *)&body.ssid_el_id; 2735 ssid_el_p = (u8 *)&body.ssid_el_id;
2719 bodysize = 18 + priv->SSID_size; 2736 bodysize = 18 + priv->SSID_size;
2720 } else { 2737 } else {
2721 ssid_el_p = (u8 *)&body.ap[0]; 2738 ssid_el_p = (u8 *)&body.ap[0];
2722 bodysize = 12 + priv->SSID_size; 2739 bodysize = 12 + priv->SSID_size;
2723 } 2740 }
2724 2741
2725 ssid_el_p[0]= C80211_MGMT_ElementID_SSID; 2742 ssid_el_p[0] = C80211_MGMT_ElementID_SSID;
2726 ssid_el_p[1] = priv->SSID_size; 2743 ssid_el_p[1] = priv->SSID_size;
2727 memcpy(ssid_el_p + 2, priv->SSID, priv->SSID_size); 2744 memcpy(ssid_el_p + 2, priv->SSID, priv->SSID_size);
2728 ssid_el_p[2 + priv->SSID_size] = C80211_MGMT_ElementID_SupportedRates; 2745 ssid_el_p[2 + priv->SSID_size] = C80211_MGMT_ElementID_SupportedRates;
@@ -2732,7 +2749,8 @@ static void send_association_request(struct atmel_private *priv, int is_reassoc)
2732 atmel_transmit_management_frame(priv, &header, (void *)&body, bodysize); 2749 atmel_transmit_management_frame(priv, &header, (void *)&body, bodysize);
2733} 2750}
2734 2751
2735static int is_frame_from_current_bss(struct atmel_private *priv, struct ieee80211_hdr_4addr *header) 2752static int is_frame_from_current_bss(struct atmel_private *priv,
2753 struct ieee80211_hdr_4addr *header)
2736{ 2754{
2737 if (le16_to_cpu(header->frame_ctl) & IEEE80211_FCTL_FROMDS) 2755 if (le16_to_cpu(header->frame_ctl) & IEEE80211_FCTL_FROMDS)
2738 return memcmp(header->addr3, priv->CurrentBSSID, 6) == 0; 2756 return memcmp(header->addr3, priv->CurrentBSSID, 6) == 0;
@@ -2745,29 +2763,29 @@ static int retrieve_bss(struct atmel_private *priv)
2745 int i; 2763 int i;
2746 int max_rssi = -128; 2764 int max_rssi = -128;
2747 int max_index = -1; 2765 int max_index = -1;
2748 2766
2749 if (priv->BSS_list_entries == 0) 2767 if (priv->BSS_list_entries == 0)
2750 return -1; 2768 return -1;
2751 2769
2752 if (priv->connect_to_any_BSS) { 2770 if (priv->connect_to_any_BSS) {
2753 /* Select a BSS with the max-RSSI but of the same type and of the same WEP mode 2771 /* Select a BSS with the max-RSSI but of the same type and of
2754 and that it is not marked as 'bad' (i.e. we had previously failed to connect to 2772 the same WEP mode and that it is not marked as 'bad' (i.e.
2755 this BSS with the settings that we currently use) */ 2773 we had previously failed to connect to this BSS with the
2774 settings that we currently use) */
2756 priv->current_BSS = 0; 2775 priv->current_BSS = 0;
2757 for(i=0; i<priv->BSS_list_entries; i++) { 2776 for (i = 0; i < priv->BSS_list_entries; i++) {
2758 if (priv->operating_mode == priv->BSSinfo[i].BSStype && 2777 if (priv->operating_mode == priv->BSSinfo[i].BSStype &&
2759 ((!priv->wep_is_on && !priv->BSSinfo[i].UsingWEP) || 2778 ((!priv->wep_is_on && !priv->BSSinfo[i].UsingWEP) ||
2760 (priv->wep_is_on && priv->BSSinfo[i].UsingWEP)) && 2779 (priv->wep_is_on && priv->BSSinfo[i].UsingWEP)) &&
2761 !(priv->BSSinfo[i].channel & 0x80)) { 2780 !(priv->BSSinfo[i].channel & 0x80)) {
2762 max_rssi = priv->BSSinfo[i].RSSI; 2781 max_rssi = priv->BSSinfo[i].RSSI;
2763 priv->current_BSS = max_index = i; 2782 priv->current_BSS = max_index = i;
2764 } 2783 }
2765
2766 } 2784 }
2767 return max_index; 2785 return max_index;
2768 } 2786 }
2769 2787
2770 for(i=0; i<priv->BSS_list_entries; i++) { 2788 for (i = 0; i < priv->BSS_list_entries; i++) {
2771 if (priv->SSID_size == priv->BSSinfo[i].SSIDsize && 2789 if (priv->SSID_size == priv->BSSinfo[i].SSIDsize &&
2772 memcmp(priv->SSID, priv->BSSinfo[i].SSID, priv->SSID_size) == 0 && 2790 memcmp(priv->SSID, priv->BSSinfo[i].SSID, priv->SSID_size) == 0 &&
2773 priv->operating_mode == priv->BSSinfo[i].BSStype && 2791 priv->operating_mode == priv->BSSinfo[i].BSStype &&
@@ -2781,19 +2799,19 @@ static int retrieve_bss(struct atmel_private *priv)
2781 return max_index; 2799 return max_index;
2782} 2800}
2783 2801
2784 2802static void store_bss_info(struct atmel_private *priv,
2785static void store_bss_info(struct atmel_private *priv, struct ieee80211_hdr_4addr *header, 2803 struct ieee80211_hdr_4addr *header, u16 capability,
2786 u16 capability, u16 beacon_period, u8 channel, u8 rssi, 2804 u16 beacon_period, u8 channel, u8 rssi, u8 ssid_len,
2787 u8 ssid_len, u8 *ssid, int is_beacon) 2805 u8 *ssid, int is_beacon)
2788{ 2806{
2789 u8 *bss = capability & C80211_MGMT_CAPABILITY_ESS ? header->addr2 : header->addr3; 2807 u8 *bss = capability & C80211_MGMT_CAPABILITY_ESS ? header->addr2 : header->addr3;
2790 int i, index; 2808 int i, index;
2791 2809
2792 for (index = -1, i = 0; i < priv->BSS_list_entries; i++) 2810 for (index = -1, i = 0; i < priv->BSS_list_entries; i++)
2793 if (memcmp(bss, priv->BSSinfo[i].BSSID, 6) == 0) 2811 if (memcmp(bss, priv->BSSinfo[i].BSSID, 6) == 0)
2794 index = i; 2812 index = i;
2795 2813
2796 /* If we process a probe and an entry from this BSS exists 2814 /* If we process a probe and an entry from this BSS exists
2797 we will update the BSS entry with the info from this BSS. 2815 we will update the BSS entry with the info from this BSS.
2798 If we process a beacon we will only update RSSI */ 2816 If we process a beacon we will only update RSSI */
2799 2817
@@ -2820,8 +2838,8 @@ static void store_bss_info(struct atmel_private *priv, struct ieee80211_hdr_4add
2820 priv->BSSinfo[index].BSStype = IW_MODE_ADHOC; 2838 priv->BSSinfo[index].BSStype = IW_MODE_ADHOC;
2821 else if (capability & C80211_MGMT_CAPABILITY_ESS) 2839 else if (capability & C80211_MGMT_CAPABILITY_ESS)
2822 priv->BSSinfo[index].BSStype =IW_MODE_INFRA; 2840 priv->BSSinfo[index].BSStype =IW_MODE_INFRA;
2823 2841
2824 priv->BSSinfo[index].preamble = capability & C80211_MGMT_CAPABILITY_ShortPreamble ? 2842 priv->BSSinfo[index].preamble = capability & C80211_MGMT_CAPABILITY_ShortPreamble ?
2825 SHORT_PREAMBLE : LONG_PREAMBLE; 2843 SHORT_PREAMBLE : LONG_PREAMBLE;
2826} 2844}
2827 2845
@@ -2831,8 +2849,8 @@ static void authenticate(struct atmel_private *priv, u16 frame_len)
2831 u16 status = le16_to_cpu(auth->status); 2849 u16 status = le16_to_cpu(auth->status);
2832 u16 trans_seq_no = le16_to_cpu(auth->trans_seq); 2850 u16 trans_seq_no = le16_to_cpu(auth->trans_seq);
2833 u16 system = le16_to_cpu(auth->alg); 2851 u16 system = le16_to_cpu(auth->alg);
2834 2852
2835 if (status == C80211_MGMT_SC_Success && !priv->wep_is_on) { 2853 if (status == C80211_MGMT_SC_Success && !priv->wep_is_on) {
2836 /* no WEP */ 2854 /* no WEP */
2837 if (priv->station_was_associated) { 2855 if (priv->station_was_associated) {
2838 atmel_enter_state(priv, STATION_STATE_REASSOCIATING); 2856 atmel_enter_state(priv, STATION_STATE_REASSOCIATING);
@@ -2842,20 +2860,20 @@ static void authenticate(struct atmel_private *priv, u16 frame_len)
2842 atmel_enter_state(priv, STATION_STATE_ASSOCIATING); 2860 atmel_enter_state(priv, STATION_STATE_ASSOCIATING);
2843 send_association_request(priv, 0); 2861 send_association_request(priv, 0);
2844 return; 2862 return;
2845 } 2863 }
2846 } 2864 }
2847 2865
2848 if (status == C80211_MGMT_SC_Success && priv->wep_is_on) { 2866 if (status == C80211_MGMT_SC_Success && priv->wep_is_on) {
2849 /* WEP */ 2867 /* WEP */
2850 if (trans_seq_no != priv->ExpectedAuthentTransactionSeqNum) 2868 if (trans_seq_no != priv->ExpectedAuthentTransactionSeqNum)
2851 return; 2869 return;
2852 2870
2853 if (trans_seq_no == 0x0002 && 2871 if (trans_seq_no == 0x0002 &&
2854 auth->el_id == C80211_MGMT_ElementID_ChallengeText) { 2872 auth->el_id == C80211_MGMT_ElementID_ChallengeText) {
2855 send_authentication_request(priv, system, auth->chall_text, auth->chall_text_len); 2873 send_authentication_request(priv, system, auth->chall_text, auth->chall_text_len);
2856 return; 2874 return;
2857 } 2875 }
2858 2876
2859 if (trans_seq_no == 0x0004) { 2877 if (trans_seq_no == 0x0004) {
2860 if(priv->station_was_associated) { 2878 if(priv->station_was_associated) {
2861 atmel_enter_state(priv, STATION_STATE_REASSOCIATING); 2879 atmel_enter_state(priv, STATION_STATE_REASSOCIATING);
@@ -2865,10 +2883,10 @@ static void authenticate(struct atmel_private *priv, u16 frame_len)
2865 atmel_enter_state(priv, STATION_STATE_ASSOCIATING); 2883 atmel_enter_state(priv, STATION_STATE_ASSOCIATING);
2866 send_association_request(priv, 0); 2884 send_association_request(priv, 0);
2867 return; 2885 return;
2868 } 2886 }
2869 } 2887 }
2870 } 2888 }
2871 2889
2872 if (status == C80211_MGMT_SC_AuthAlgNotSupported) { 2890 if (status == C80211_MGMT_SC_AuthAlgNotSupported) {
2873 /* Do opensystem first, then try sharedkey */ 2891 /* Do opensystem first, then try sharedkey */
2874 if (system == C80211_MGMT_AAN_OPENSYSTEM) { 2892 if (system == C80211_MGMT_AAN_OPENSYSTEM) {
@@ -2876,17 +2894,16 @@ static void authenticate(struct atmel_private *priv, u16 frame_len)
2876 send_authentication_request(priv, C80211_MGMT_AAN_SHAREDKEY, NULL, 0); 2894 send_authentication_request(priv, C80211_MGMT_AAN_SHAREDKEY, NULL, 0);
2877 } else if (priv->connect_to_any_BSS) { 2895 } else if (priv->connect_to_any_BSS) {
2878 int bss_index; 2896 int bss_index;
2879 2897
2880 priv->BSSinfo[(int)(priv->current_BSS)].channel |= 0x80; 2898 priv->BSSinfo[(int)(priv->current_BSS)].channel |= 0x80;
2881 2899
2882 if ((bss_index = retrieve_bss(priv)) != -1) { 2900 if ((bss_index = retrieve_bss(priv)) != -1) {
2883 atmel_join_bss(priv, bss_index); 2901 atmel_join_bss(priv, bss_index);
2884 return; 2902 return;
2885 } 2903 }
2886 } 2904 }
2887 } 2905 }
2888 2906
2889
2890 priv->AuthenticationRequestRetryCnt = 0; 2907 priv->AuthenticationRequestRetryCnt = 0;
2891 atmel_enter_state(priv, STATION_STATE_MGMT_ERROR); 2908 atmel_enter_state(priv, STATION_STATE_MGMT_ERROR);
2892 priv->station_is_associated = 0; 2909 priv->station_is_associated = 0;
@@ -2902,38 +2919,44 @@ static void associate(struct atmel_private *priv, u16 frame_len, u16 subtype)
2902 u8 length; 2919 u8 length;
2903 u8 rates[4]; 2920 u8 rates[4];
2904 } *ass_resp = (struct ass_resp_format *)priv->rx_buf; 2921 } *ass_resp = (struct ass_resp_format *)priv->rx_buf;
2905 2922
2906 u16 status = le16_to_cpu(ass_resp->status); 2923 u16 status = le16_to_cpu(ass_resp->status);
2907 u16 ass_id = le16_to_cpu(ass_resp->ass_id); 2924 u16 ass_id = le16_to_cpu(ass_resp->ass_id);
2908 u16 rates_len = ass_resp->length > 4 ? 4 : ass_resp->length; 2925 u16 rates_len = ass_resp->length > 4 ? 4 : ass_resp->length;
2909 2926
2910 if (frame_len < 8 + rates_len) 2927 if (frame_len < 8 + rates_len)
2911 return; 2928 return;
2912 2929
2913 if (status == C80211_MGMT_SC_Success) { 2930 if (status == C80211_MGMT_SC_Success) {
2914 if (subtype == C80211_SUBTYPE_MGMT_ASS_RESPONSE) 2931 if (subtype == C80211_SUBTYPE_MGMT_ASS_RESPONSE)
2915 priv->AssociationRequestRetryCnt = 0; 2932 priv->AssociationRequestRetryCnt = 0;
2916 else 2933 else
2917 priv->ReAssociationRequestRetryCnt = 0; 2934 priv->ReAssociationRequestRetryCnt = 0;
2918 2935
2919 atmel_set_mib16(priv, Mac_Mgmt_Mib_Type, MAC_MGMT_MIB_STATION_ID_POS, ass_id & 0x3fff); 2936 atmel_set_mib16(priv, Mac_Mgmt_Mib_Type,
2920 atmel_set_mib(priv, Phy_Mib_Type, PHY_MIB_RATE_SET_POS, ass_resp->rates, rates_len); 2937 MAC_MGMT_MIB_STATION_ID_POS, ass_id & 0x3fff);
2938 atmel_set_mib(priv, Phy_Mib_Type,
2939 PHY_MIB_RATE_SET_POS, ass_resp->rates, rates_len);
2921 if (priv->power_mode == 0) { 2940 if (priv->power_mode == 0) {
2922 priv->listen_interval = 1; 2941 priv->listen_interval = 1;
2923 atmel_set_mib8(priv, Mac_Mgmt_Mib_Type, MAC_MGMT_MIB_PS_MODE_POS, ACTIVE_MODE); 2942 atmel_set_mib8(priv, Mac_Mgmt_Mib_Type,
2924 atmel_set_mib16(priv, Mac_Mgmt_Mib_Type, MAC_MGMT_MIB_LISTEN_INTERVAL_POS, 1); 2943 MAC_MGMT_MIB_PS_MODE_POS, ACTIVE_MODE);
2944 atmel_set_mib16(priv, Mac_Mgmt_Mib_Type,
2945 MAC_MGMT_MIB_LISTEN_INTERVAL_POS, 1);
2925 } else { 2946 } else {
2926 priv->listen_interval = 2; 2947 priv->listen_interval = 2;
2927 atmel_set_mib8(priv, Mac_Mgmt_Mib_Type, MAC_MGMT_MIB_PS_MODE_POS, PS_MODE); 2948 atmel_set_mib8(priv, Mac_Mgmt_Mib_Type,
2928 atmel_set_mib16(priv, Mac_Mgmt_Mib_Type, MAC_MGMT_MIB_LISTEN_INTERVAL_POS, 2); 2949 MAC_MGMT_MIB_PS_MODE_POS, PS_MODE);
2950 atmel_set_mib16(priv, Mac_Mgmt_Mib_Type,
2951 MAC_MGMT_MIB_LISTEN_INTERVAL_POS, 2);
2929 } 2952 }
2930 2953
2931 priv->station_is_associated = 1; 2954 priv->station_is_associated = 1;
2932 priv->station_was_associated = 1; 2955 priv->station_was_associated = 1;
2933 atmel_enter_state(priv, STATION_STATE_READY); 2956 atmel_enter_state(priv, STATION_STATE_READY);
2934 return; 2957 return;
2935 } 2958 }
2936 2959
2937 if (subtype == C80211_SUBTYPE_MGMT_ASS_RESPONSE && 2960 if (subtype == C80211_SUBTYPE_MGMT_ASS_RESPONSE &&
2938 status != C80211_MGMT_SC_AssDeniedBSSRate && 2961 status != C80211_MGMT_SC_AssDeniedBSSRate &&
2939 status != C80211_MGMT_SC_SupportCapabilities && 2962 status != C80211_MGMT_SC_SupportCapabilities &&
@@ -2943,7 +2966,7 @@ static void associate(struct atmel_private *priv, u16 frame_len, u16 subtype)
2943 send_association_request(priv, 0); 2966 send_association_request(priv, 0);
2944 return; 2967 return;
2945 } 2968 }
2946 2969
2947 if (subtype == C80211_SUBTYPE_MGMT_REASS_RESPONSE && 2970 if (subtype == C80211_SUBTYPE_MGMT_REASS_RESPONSE &&
2948 status != C80211_MGMT_SC_AssDeniedBSSRate && 2971 status != C80211_MGMT_SC_AssDeniedBSSRate &&
2949 status != C80211_MGMT_SC_SupportCapabilities && 2972 status != C80211_MGMT_SC_SupportCapabilities &&
@@ -2953,17 +2976,16 @@ static void associate(struct atmel_private *priv, u16 frame_len, u16 subtype)
2953 send_association_request(priv, 1); 2976 send_association_request(priv, 1);
2954 return; 2977 return;
2955 } 2978 }
2956 2979
2957 atmel_enter_state(priv, STATION_STATE_MGMT_ERROR); 2980 atmel_enter_state(priv, STATION_STATE_MGMT_ERROR);
2958 priv->station_is_associated = 0; 2981 priv->station_is_associated = 0;
2959 2982
2960 if(priv->connect_to_any_BSS) { 2983 if (priv->connect_to_any_BSS) {
2961 int bss_index; 2984 int bss_index;
2962 priv->BSSinfo[(int)(priv->current_BSS)].channel |= 0x80; 2985 priv->BSSinfo[(int)(priv->current_BSS)].channel |= 0x80;
2963 2986
2964 if ((bss_index = retrieve_bss(priv)) != -1) 2987 if ((bss_index = retrieve_bss(priv)) != -1)
2965 atmel_join_bss(priv, bss_index); 2988 atmel_join_bss(priv, bss_index);
2966
2967 } 2989 }
2968} 2990}
2969 2991
@@ -2977,7 +2999,7 @@ void atmel_join_bss(struct atmel_private *priv, int bss_index)
2977 /* The WPA stuff cares about the current AP address */ 2999 /* The WPA stuff cares about the current AP address */
2978 if (priv->use_wpa) 3000 if (priv->use_wpa)
2979 build_wpa_mib(priv); 3001 build_wpa_mib(priv);
2980 3002
2981 /* When switching to AdHoc turn OFF Power Save if needed */ 3003 /* When switching to AdHoc turn OFF Power Save if needed */
2982 3004
2983 if (bss->BSStype == IW_MODE_ADHOC && 3005 if (bss->BSStype == IW_MODE_ADHOC &&
@@ -2985,25 +3007,28 @@ void atmel_join_bss(struct atmel_private *priv, int bss_index)
2985 priv->power_mode) { 3007 priv->power_mode) {
2986 priv->power_mode = 0; 3008 priv->power_mode = 0;
2987 priv->listen_interval = 1; 3009 priv->listen_interval = 1;
2988 atmel_set_mib8(priv, Mac_Mgmt_Mib_Type, MAC_MGMT_MIB_PS_MODE_POS, ACTIVE_MODE); 3010 atmel_set_mib8(priv, Mac_Mgmt_Mib_Type,
2989 atmel_set_mib16(priv, Mac_Mgmt_Mib_Type, MAC_MGMT_MIB_LISTEN_INTERVAL_POS, 1); 3011 MAC_MGMT_MIB_PS_MODE_POS, ACTIVE_MODE);
3012 atmel_set_mib16(priv, Mac_Mgmt_Mib_Type,
3013 MAC_MGMT_MIB_LISTEN_INTERVAL_POS, 1);
2990 } 3014 }
2991 3015
2992 priv->operating_mode = bss->BSStype; 3016 priv->operating_mode = bss->BSStype;
2993 priv->channel = bss->channel & 0x7f; 3017 priv->channel = bss->channel & 0x7f;
2994 priv->beacon_period = bss->beacon_period; 3018 priv->beacon_period = bss->beacon_period;
2995 3019
2996 if (priv->preamble != bss->preamble) { 3020 if (priv->preamble != bss->preamble) {
2997 priv->preamble = bss->preamble; 3021 priv->preamble = bss->preamble;
2998 atmel_set_mib8(priv, Local_Mib_Type, LOCAL_MIB_PREAMBLE_TYPE, bss->preamble); 3022 atmel_set_mib8(priv, Local_Mib_Type,
3023 LOCAL_MIB_PREAMBLE_TYPE, bss->preamble);
2999 } 3024 }
3000 3025
3001 if (!priv->wep_is_on && bss->UsingWEP) { 3026 if (!priv->wep_is_on && bss->UsingWEP) {
3002 atmel_enter_state(priv, STATION_STATE_MGMT_ERROR); 3027 atmel_enter_state(priv, STATION_STATE_MGMT_ERROR);
3003 priv->station_is_associated = 0; 3028 priv->station_is_associated = 0;
3004 return; 3029 return;
3005 } 3030 }
3006 3031
3007 if (priv->wep_is_on && !bss->UsingWEP) { 3032 if (priv->wep_is_on && !bss->UsingWEP) {
3008 atmel_enter_state(priv, STATION_STATE_MGMT_ERROR); 3033 atmel_enter_state(priv, STATION_STATE_MGMT_ERROR);
3009 priv->station_is_associated = 0; 3034 priv->station_is_associated = 0;
@@ -3011,30 +3036,28 @@ void atmel_join_bss(struct atmel_private *priv, int bss_index)
3011 } 3036 }
3012 3037
3013 atmel_enter_state(priv, STATION_STATE_JOINNING); 3038 atmel_enter_state(priv, STATION_STATE_JOINNING);
3014 3039
3015 if (priv->operating_mode == IW_MODE_INFRA) 3040 if (priv->operating_mode == IW_MODE_INFRA)
3016 join(priv, BSS_TYPE_INFRASTRUCTURE); 3041 join(priv, BSS_TYPE_INFRASTRUCTURE);
3017 else 3042 else
3018 join(priv, BSS_TYPE_AD_HOC); 3043 join(priv, BSS_TYPE_AD_HOC);
3019} 3044}
3020 3045
3021
3022static void restart_search(struct atmel_private *priv) 3046static void restart_search(struct atmel_private *priv)
3023{ 3047{
3024 int bss_index; 3048 int bss_index;
3025 3049
3026 if (!priv->connect_to_any_BSS) { 3050 if (!priv->connect_to_any_BSS) {
3027 atmel_scan(priv, 1); 3051 atmel_scan(priv, 1);
3028 } else { 3052 } else {
3029 priv->BSSinfo[(int)(priv->current_BSS)].channel |= 0x80; 3053 priv->BSSinfo[(int)(priv->current_BSS)].channel |= 0x80;
3030 3054
3031 if ((bss_index = retrieve_bss(priv)) != -1) 3055 if ((bss_index = retrieve_bss(priv)) != -1)
3032 atmel_join_bss(priv, bss_index); 3056 atmel_join_bss(priv, bss_index);
3033 else 3057 else
3034 atmel_scan(priv, 0); 3058 atmel_scan(priv, 0);
3035 3059 }
3036 } 3060}
3037}
3038 3061
3039static void smooth_rssi(struct atmel_private *priv, u8 rssi) 3062static void smooth_rssi(struct atmel_private *priv, u8 rssi)
3040{ 3063{
@@ -3050,21 +3073,21 @@ static void smooth_rssi(struct atmel_private *priv, u8 rssi)
3050 } 3073 }
3051 3074
3052 rssi = rssi * 100 / max_rssi; 3075 rssi = rssi * 100 / max_rssi;
3053 if((rssi + old) % 2) 3076 if ((rssi + old) % 2)
3054 priv->wstats.qual.level = ((rssi + old)/2) + 1; 3077 priv->wstats.qual.level = (rssi + old) / 2 + 1;
3055 else 3078 else
3056 priv->wstats.qual.level = ((rssi + old)/2); 3079 priv->wstats.qual.level = (rssi + old) / 2;
3057 priv->wstats.qual.updated |= IW_QUAL_LEVEL_UPDATED; 3080 priv->wstats.qual.updated |= IW_QUAL_LEVEL_UPDATED;
3058 priv->wstats.qual.updated &= ~IW_QUAL_LEVEL_INVALID; 3081 priv->wstats.qual.updated &= ~IW_QUAL_LEVEL_INVALID;
3059} 3082}
3060 3083
3061static void atmel_smooth_qual(struct atmel_private *priv) 3084static void atmel_smooth_qual(struct atmel_private *priv)
3062{ 3085{
3063 unsigned long time_diff = (jiffies - priv->last_qual)/HZ; 3086 unsigned long time_diff = (jiffies - priv->last_qual) / HZ;
3064 while (time_diff--) { 3087 while (time_diff--) {
3065 priv->last_qual += HZ; 3088 priv->last_qual += HZ;
3066 priv->wstats.qual.qual = priv->wstats.qual.qual/2; 3089 priv->wstats.qual.qual = priv->wstats.qual.qual / 2;
3067 priv->wstats.qual.qual += 3090 priv->wstats.qual.qual +=
3068 priv->beacons_this_sec * priv->beacon_period * (priv->wstats.qual.level + 100) / 4000; 3091 priv->beacons_this_sec * priv->beacon_period * (priv->wstats.qual.level + 100) / 4000;
3069 priv->beacons_this_sec = 0; 3092 priv->beacons_this_sec = 0;
3070 } 3093 }
@@ -3073,15 +3096,17 @@ static void atmel_smooth_qual(struct atmel_private *priv)
3073} 3096}
3074 3097
3075/* deals with incoming managment frames. */ 3098/* deals with incoming managment frames. */
3076static void atmel_management_frame(struct atmel_private *priv, struct ieee80211_hdr_4addr *header, 3099static void atmel_management_frame(struct atmel_private *priv,
3077 u16 frame_len, u8 rssi) 3100 struct ieee80211_hdr_4addr *header,
3101 u16 frame_len, u8 rssi)
3078{ 3102{
3079 u16 subtype; 3103 u16 subtype;
3080 3104
3081 switch (subtype = le16_to_cpu(header->frame_ctl) & IEEE80211_FCTL_STYPE) { 3105 subtype = le16_to_cpu(header->frame_ctl) & IEEE80211_FCTL_STYPE;
3082 case C80211_SUBTYPE_MGMT_BEACON : 3106 switch (subtype) {
3107 case C80211_SUBTYPE_MGMT_BEACON:
3083 case C80211_SUBTYPE_MGMT_ProbeResponse: 3108 case C80211_SUBTYPE_MGMT_ProbeResponse:
3084 3109
3085 /* beacon frame has multiple variable-length fields - 3110 /* beacon frame has multiple variable-length fields -
3086 never let an engineer loose with a data structure design. */ 3111 never let an engineer loose with a data structure design. */
3087 { 3112 {
@@ -3099,7 +3124,7 @@ static void atmel_management_frame(struct atmel_private *priv, struct ieee80211_
3099 u8 ds_length; 3124 u8 ds_length;
3100 /* ds here */ 3125 /* ds here */
3101 } *beacon = (struct beacon_format *)priv->rx_buf; 3126 } *beacon = (struct beacon_format *)priv->rx_buf;
3102 3127
3103 u8 channel, rates_length, ssid_length; 3128 u8 channel, rates_length, ssid_length;
3104 u64 timestamp = le64_to_cpu(beacon->timestamp); 3129 u64 timestamp = le64_to_cpu(beacon->timestamp);
3105 u16 beacon_interval = le16_to_cpu(beacon->interval); 3130 u16 beacon_interval = le16_to_cpu(beacon->interval);
@@ -3107,7 +3132,7 @@ static void atmel_management_frame(struct atmel_private *priv, struct ieee80211_
3107 u8 *beaconp = priv->rx_buf; 3132 u8 *beaconp = priv->rx_buf;
3108 ssid_length = beacon->ssid_length; 3133 ssid_length = beacon->ssid_length;
3109 /* this blows chunks. */ 3134 /* this blows chunks. */
3110 if (frame_len < 14 || frame_len < ssid_length + 15) 3135 if (frame_len < 14 || frame_len < ssid_length + 15)
3111 return; 3136 return;
3112 rates_length = beaconp[beacon->ssid_length + 15]; 3137 rates_length = beaconp[beacon->ssid_length + 15];
3113 if (frame_len < ssid_length + rates_length + 18) 3138 if (frame_len < ssid_length + rates_length + 18)
@@ -3115,10 +3140,10 @@ static void atmel_management_frame(struct atmel_private *priv, struct ieee80211_
3115 if (ssid_length > MAX_SSID_LENGTH) 3140 if (ssid_length > MAX_SSID_LENGTH)
3116 return; 3141 return;
3117 channel = beaconp[ssid_length + rates_length + 18]; 3142 channel = beaconp[ssid_length + rates_length + 18];
3118 3143
3119 if (priv->station_state == STATION_STATE_READY) { 3144 if (priv->station_state == STATION_STATE_READY) {
3120 smooth_rssi(priv, rssi); 3145 smooth_rssi(priv, rssi);
3121 if (is_frame_from_current_bss(priv, header)) { 3146 if (is_frame_from_current_bss(priv, header)) {
3122 priv->beacons_this_sec++; 3147 priv->beacons_this_sec++;
3123 atmel_smooth_qual(priv); 3148 atmel_smooth_qual(priv);
3124 if (priv->last_beacon_timestamp) { 3149 if (priv->last_beacon_timestamp) {
@@ -3132,41 +3157,43 @@ static void atmel_management_frame(struct atmel_private *priv, struct ieee80211_
3132 handle_beacon_probe(priv, capability, channel); 3157 handle_beacon_probe(priv, capability, channel);
3133 } 3158 }
3134 } 3159 }
3135 3160
3136 if (priv->station_state == STATION_STATE_SCANNING ) 3161 if (priv->station_state == STATION_STATE_SCANNING)
3137 store_bss_info(priv, header, capability, beacon_interval, channel, 3162 store_bss_info(priv, header, capability,
3138 rssi, ssid_length, &beacon->rates_el_id, 3163 beacon_interval, channel, rssi,
3139 subtype == C80211_SUBTYPE_MGMT_BEACON) ; 3164 ssid_length,
3165 &beacon->rates_el_id,
3166 subtype == C80211_SUBTYPE_MGMT_BEACON);
3140 } 3167 }
3141 break; 3168 break;
3142 3169
3143 case C80211_SUBTYPE_MGMT_Authentication: 3170 case C80211_SUBTYPE_MGMT_Authentication:
3144 3171
3145 if (priv->station_state == STATION_STATE_AUTHENTICATING) 3172 if (priv->station_state == STATION_STATE_AUTHENTICATING)
3146 authenticate(priv, frame_len); 3173 authenticate(priv, frame_len);
3147 3174
3148 break; 3175 break;
3149 3176
3150 case C80211_SUBTYPE_MGMT_ASS_RESPONSE: 3177 case C80211_SUBTYPE_MGMT_ASS_RESPONSE:
3151 case C80211_SUBTYPE_MGMT_REASS_RESPONSE: 3178 case C80211_SUBTYPE_MGMT_REASS_RESPONSE:
3152 3179
3153 if (priv->station_state == STATION_STATE_ASSOCIATING || 3180 if (priv->station_state == STATION_STATE_ASSOCIATING ||
3154 priv->station_state == STATION_STATE_REASSOCIATING) 3181 priv->station_state == STATION_STATE_REASSOCIATING)
3155 associate(priv, frame_len, subtype); 3182 associate(priv, frame_len, subtype);
3156 3183
3157 break; 3184 break;
3158 3185
3159 case C80211_SUBTYPE_MGMT_DISASSOSIATION: 3186 case C80211_SUBTYPE_MGMT_DISASSOSIATION:
3160 if (priv->station_is_associated && 3187 if (priv->station_is_associated &&
3161 priv->operating_mode == IW_MODE_INFRA && 3188 priv->operating_mode == IW_MODE_INFRA &&
3162 is_frame_from_current_bss(priv, header)) { 3189 is_frame_from_current_bss(priv, header)) {
3163 priv->station_was_associated = 0; 3190 priv->station_was_associated = 0;
3164 priv->station_is_associated = 0; 3191 priv->station_is_associated = 0;
3165 3192
3166 atmel_enter_state(priv, STATION_STATE_JOINNING); 3193 atmel_enter_state(priv, STATION_STATE_JOINNING);
3167 join(priv, BSS_TYPE_INFRASTRUCTURE); 3194 join(priv, BSS_TYPE_INFRASTRUCTURE);
3168 } 3195 }
3169 3196
3170 break; 3197 break;
3171 3198
3172 case C80211_SUBTYPE_MGMT_Deauthentication: 3199 case C80211_SUBTYPE_MGMT_Deauthentication:
@@ -3177,7 +3204,7 @@ static void atmel_management_frame(struct atmel_private *priv, struct ieee80211_
3177 atmel_enter_state(priv, STATION_STATE_JOINNING); 3204 atmel_enter_state(priv, STATION_STATE_JOINNING);
3178 join(priv, BSS_TYPE_INFRASTRUCTURE); 3205 join(priv, BSS_TYPE_INFRASTRUCTURE);
3179 } 3206 }
3180 3207
3181 break; 3208 break;
3182 } 3209 }
3183} 3210}
@@ -3185,76 +3212,73 @@ static void atmel_management_frame(struct atmel_private *priv, struct ieee80211_
3185/* run when timer expires */ 3212/* run when timer expires */
3186static void atmel_management_timer(u_long a) 3213static void atmel_management_timer(u_long a)
3187{ 3214{
3188 struct net_device *dev = (struct net_device *) a; 3215 struct net_device *dev = (struct net_device *) a;
3189 struct atmel_private *priv = netdev_priv(dev); 3216 struct atmel_private *priv = netdev_priv(dev);
3190 unsigned long flags; 3217 unsigned long flags;
3191
3192 /* Check if the card has been yanked. */
3193 if (priv->card && priv->present_callback &&
3194 !(*priv->present_callback)(priv->card))
3195 return;
3196
3197 spin_lock_irqsave(&priv->irqlock, flags);
3198
3199 switch (priv->station_state) {
3200
3201 case STATION_STATE_AUTHENTICATING:
3202 if (priv->AuthenticationRequestRetryCnt >= MAX_AUTHENTICATION_RETRIES) {
3203 atmel_enter_state(priv, STATION_STATE_MGMT_ERROR);
3204 priv->station_is_associated = 0;
3205 priv->AuthenticationRequestRetryCnt = 0;
3206 restart_search(priv);
3207 } else {
3208 priv->AuthenticationRequestRetryCnt++;
3209 priv->CurrentAuthentTransactionSeqNum = 0x0001;
3210 mod_timer(&priv->management_timer, jiffies + MGMT_JIFFIES);
3211 send_authentication_request(priv, C80211_MGMT_AAN_OPENSYSTEM, NULL, 0);
3212 }
3213
3214 break;
3215 3218
3216 case STATION_STATE_ASSOCIATING: 3219 /* Check if the card has been yanked. */
3217 if (priv->AssociationRequestRetryCnt == MAX_ASSOCIATION_RETRIES) { 3220 if (priv->card && priv->present_callback &&
3218 atmel_enter_state(priv, STATION_STATE_MGMT_ERROR); 3221 !(*priv->present_callback)(priv->card))
3219 priv->station_is_associated = 0; 3222 return;
3220 priv->AssociationRequestRetryCnt = 0;
3221 restart_search(priv);
3222 } else {
3223 priv->AssociationRequestRetryCnt++;
3224 mod_timer(&priv->management_timer, jiffies + MGMT_JIFFIES);
3225 send_association_request(priv, 0);
3226 }
3227 3223
3228 break; 3224 spin_lock_irqsave(&priv->irqlock, flags);
3229 3225
3230 case STATION_STATE_REASSOCIATING: 3226 switch (priv->station_state) {
3231 if (priv->ReAssociationRequestRetryCnt == MAX_ASSOCIATION_RETRIES) {
3232 atmel_enter_state(priv, STATION_STATE_MGMT_ERROR);
3233 priv->station_is_associated = 0;
3234 priv->ReAssociationRequestRetryCnt = 0;
3235 restart_search(priv);
3236 } else {
3237 priv->ReAssociationRequestRetryCnt++;
3238 mod_timer(&priv->management_timer, jiffies + MGMT_JIFFIES);
3239 send_association_request(priv, 1);
3240 }
3241 3227
3228 case STATION_STATE_AUTHENTICATING:
3229 if (priv->AuthenticationRequestRetryCnt >= MAX_AUTHENTICATION_RETRIES) {
3230 atmel_enter_state(priv, STATION_STATE_MGMT_ERROR);
3231 priv->station_is_associated = 0;
3232 priv->AuthenticationRequestRetryCnt = 0;
3233 restart_search(priv);
3234 } else {
3235 priv->AuthenticationRequestRetryCnt++;
3236 priv->CurrentAuthentTransactionSeqNum = 0x0001;
3237 mod_timer(&priv->management_timer, jiffies + MGMT_JIFFIES);
3238 send_authentication_request(priv, C80211_MGMT_AAN_OPENSYSTEM, NULL, 0);
3239 }
3242 break; 3240 break;
3243 3241
3244 default: 3242 case STATION_STATE_ASSOCIATING:
3243 if (priv->AssociationRequestRetryCnt == MAX_ASSOCIATION_RETRIES) {
3244 atmel_enter_state(priv, STATION_STATE_MGMT_ERROR);
3245 priv->station_is_associated = 0;
3246 priv->AssociationRequestRetryCnt = 0;
3247 restart_search(priv);
3248 } else {
3249 priv->AssociationRequestRetryCnt++;
3250 mod_timer(&priv->management_timer, jiffies + MGMT_JIFFIES);
3251 send_association_request(priv, 0);
3252 }
3245 break; 3253 break;
3246 } 3254
3247 3255 case STATION_STATE_REASSOCIATING:
3248 spin_unlock_irqrestore(&priv->irqlock, flags); 3256 if (priv->ReAssociationRequestRetryCnt == MAX_ASSOCIATION_RETRIES) {
3257 atmel_enter_state(priv, STATION_STATE_MGMT_ERROR);
3258 priv->station_is_associated = 0;
3259 priv->ReAssociationRequestRetryCnt = 0;
3260 restart_search(priv);
3261 } else {
3262 priv->ReAssociationRequestRetryCnt++;
3263 mod_timer(&priv->management_timer, jiffies + MGMT_JIFFIES);
3264 send_association_request(priv, 1);
3265 }
3266 break;
3267
3268 default:
3269 break;
3270 }
3271
3272 spin_unlock_irqrestore(&priv->irqlock, flags);
3249} 3273}
3250 3274
3251static void atmel_command_irq(struct atmel_private *priv) 3275static void atmel_command_irq(struct atmel_private *priv)
3252{ 3276{
3253 u8 status = atmel_rmem8(priv, atmel_co(priv, CMD_BLOCK_STATUS_OFFSET)); 3277 u8 status = atmel_rmem8(priv, atmel_co(priv, CMD_BLOCK_STATUS_OFFSET));
3254 u8 command = atmel_rmem8(priv, atmel_co(priv, CMD_BLOCK_COMMAND_OFFSET)); 3278 u8 command = atmel_rmem8(priv, atmel_co(priv, CMD_BLOCK_COMMAND_OFFSET));
3255 int fast_scan; 3279 int fast_scan;
3256 3280
3257 if (status == CMD_STATUS_IDLE || 3281 if (status == CMD_STATUS_IDLE ||
3258 status == CMD_STATUS_IN_PROGRESS) 3282 status == CMD_STATUS_IN_PROGRESS)
3259 return; 3283 return;
3260 3284
@@ -3266,20 +3290,20 @@ static void atmel_command_irq(struct atmel_private *priv)
3266 atmel_get_mib(priv, Mac_Mgmt_Mib_Type, MAC_MGMT_MIB_CUR_BSSID_POS, 3290 atmel_get_mib(priv, Mac_Mgmt_Mib_Type, MAC_MGMT_MIB_CUR_BSSID_POS,
3267 (u8 *)priv->CurrentBSSID, 6); 3291 (u8 *)priv->CurrentBSSID, 6);
3268 atmel_enter_state(priv, STATION_STATE_READY); 3292 atmel_enter_state(priv, STATION_STATE_READY);
3269 } 3293 }
3270 break; 3294 break;
3271 3295
3272 case CMD_Scan: 3296 case CMD_Scan:
3273 fast_scan = priv->fast_scan; 3297 fast_scan = priv->fast_scan;
3274 priv->fast_scan = 0; 3298 priv->fast_scan = 0;
3275 3299
3276 if (status != CMD_STATUS_COMPLETE) { 3300 if (status != CMD_STATUS_COMPLETE) {
3277 atmel_scan(priv, 1); 3301 atmel_scan(priv, 1);
3278 } else { 3302 } else {
3279 int bss_index = retrieve_bss(priv); 3303 int bss_index = retrieve_bss(priv);
3280 if (bss_index != -1) { 3304 if (bss_index != -1) {
3281 atmel_join_bss(priv, bss_index); 3305 atmel_join_bss(priv, bss_index);
3282 } else if (priv->operating_mode == IW_MODE_ADHOC && 3306 } else if (priv->operating_mode == IW_MODE_ADHOC &&
3283 priv->SSID_size != 0) { 3307 priv->SSID_size != 0) {
3284 start(priv, BSS_TYPE_AD_HOC); 3308 start(priv, BSS_TYPE_AD_HOC);
3285 } else { 3309 } else {
@@ -3289,16 +3313,16 @@ static void atmel_command_irq(struct atmel_private *priv)
3289 priv->site_survey_state = SITE_SURVEY_COMPLETED; 3313 priv->site_survey_state = SITE_SURVEY_COMPLETED;
3290 } 3314 }
3291 break; 3315 break;
3292 3316
3293 case CMD_SiteSurvey: 3317 case CMD_SiteSurvey:
3294 priv->fast_scan = 0; 3318 priv->fast_scan = 0;
3295 3319
3296 if (status != CMD_STATUS_COMPLETE) 3320 if (status != CMD_STATUS_COMPLETE)
3297 return; 3321 return;
3298 3322
3299 priv->site_survey_state = SITE_SURVEY_COMPLETED; 3323 priv->site_survey_state = SITE_SURVEY_COMPLETED;
3300 if (priv->station_is_associated) { 3324 if (priv->station_is_associated) {
3301 atmel_enter_state(priv, STATION_STATE_READY); 3325 atmel_enter_state(priv, STATION_STATE_READY);
3302 } else { 3326 } else {
3303 atmel_scan(priv, 1); 3327 atmel_scan(priv, 1);
3304 } 3328 }
@@ -3312,16 +3336,15 @@ static void atmel_command_irq(struct atmel_private *priv)
3312 } else { 3336 } else {
3313 priv->AuthenticationRequestRetryCnt = 0; 3337 priv->AuthenticationRequestRetryCnt = 0;
3314 atmel_enter_state(priv, STATION_STATE_AUTHENTICATING); 3338 atmel_enter_state(priv, STATION_STATE_AUTHENTICATING);
3315 3339
3316 mod_timer(&priv->management_timer, jiffies + MGMT_JIFFIES); 3340 mod_timer(&priv->management_timer, jiffies + MGMT_JIFFIES);
3317 priv->CurrentAuthentTransactionSeqNum = 0x0001; 3341 priv->CurrentAuthentTransactionSeqNum = 0x0001;
3318 send_authentication_request(priv, C80211_MGMT_AAN_SHAREDKEY, NULL, 0); 3342 send_authentication_request(priv, C80211_MGMT_AAN_SHAREDKEY, NULL, 0);
3319 } 3343 }
3320 return; 3344 return;
3321 } 3345 }
3322 3346
3323 atmel_scan(priv, 1); 3347 atmel_scan(priv, 1);
3324
3325 } 3348 }
3326} 3349}
3327 3350
@@ -3333,20 +3356,20 @@ static int atmel_wakeup_firmware(struct atmel_private *priv)
3333 3356
3334 if (priv->card_type == CARD_TYPE_SPI_FLASH) 3357 if (priv->card_type == CARD_TYPE_SPI_FLASH)
3335 atmel_set_gcr(priv->dev, GCR_REMAP); 3358 atmel_set_gcr(priv->dev, GCR_REMAP);
3336 3359
3337 /* wake up on-board processor */ 3360 /* wake up on-board processor */
3338 atmel_clear_gcr(priv->dev, 0x0040); 3361 atmel_clear_gcr(priv->dev, 0x0040);
3339 atmel_write16(priv->dev, BSR, BSS_SRAM); 3362 atmel_write16(priv->dev, BSR, BSS_SRAM);
3340 3363
3341 if (priv->card_type == CARD_TYPE_SPI_FLASH) 3364 if (priv->card_type == CARD_TYPE_SPI_FLASH)
3342 mdelay(100); 3365 mdelay(100);
3343 3366
3344 /* and wait for it */ 3367 /* and wait for it */
3345 for (i = LOOP_RETRY_LIMIT; i; i--) { 3368 for (i = LOOP_RETRY_LIMIT; i; i--) {
3346 mr1 = atmel_read16(priv->dev, MR1); 3369 mr1 = atmel_read16(priv->dev, MR1);
3347 mr3 = atmel_read16(priv->dev, MR3); 3370 mr3 = atmel_read16(priv->dev, MR3);
3348 3371
3349 if (mr3 & MAC_BOOT_COMPLETE) 3372 if (mr3 & MAC_BOOT_COMPLETE)
3350 break; 3373 break;
3351 if (mr1 & MAC_BOOT_COMPLETE && 3374 if (mr1 & MAC_BOOT_COMPLETE &&
3352 priv->bus_type == BUS_TYPE_PCCARD) 3375 priv->bus_type == BUS_TYPE_PCCARD)
@@ -3357,35 +3380,36 @@ static int atmel_wakeup_firmware(struct atmel_private *priv)
3357 printk(KERN_ALERT "%s: MAC failed to boot.\n", priv->dev->name); 3380 printk(KERN_ALERT "%s: MAC failed to boot.\n", priv->dev->name);
3358 return 0; 3381 return 0;
3359 } 3382 }
3360 3383
3361 if ((priv->host_info_base = atmel_read16(priv->dev, MR2)) == 0xffff) { 3384 if ((priv->host_info_base = atmel_read16(priv->dev, MR2)) == 0xffff) {
3362 printk(KERN_ALERT "%s: card missing.\n", priv->dev->name); 3385 printk(KERN_ALERT "%s: card missing.\n", priv->dev->name);
3363 return 0; 3386 return 0;
3364 } 3387 }
3365 3388
3366 /* now check for completion of MAC initialization through 3389 /* now check for completion of MAC initialization through
3367 the FunCtrl field of the IFACE, poll MR1 to detect completion of 3390 the FunCtrl field of the IFACE, poll MR1 to detect completion of
3368 MAC initialization, check completion status, set interrupt mask, 3391 MAC initialization, check completion status, set interrupt mask,
3369 enables interrupts and calls Tx and Rx initialization functions */ 3392 enables interrupts and calls Tx and Rx initialization functions */
3370 3393
3371 atmel_wmem8(priv, atmel_hi(priv, IFACE_FUNC_CTRL_OFFSET), FUNC_CTRL_INIT_COMPLETE); 3394 atmel_wmem8(priv, atmel_hi(priv, IFACE_FUNC_CTRL_OFFSET), FUNC_CTRL_INIT_COMPLETE);
3372 3395
3373 for (i = LOOP_RETRY_LIMIT; i; i--) { 3396 for (i = LOOP_RETRY_LIMIT; i; i--) {
3374 mr1 = atmel_read16(priv->dev, MR1); 3397 mr1 = atmel_read16(priv->dev, MR1);
3375 mr3 = atmel_read16(priv->dev, MR3); 3398 mr3 = atmel_read16(priv->dev, MR3);
3376 3399
3377 if (mr3 & MAC_INIT_COMPLETE) 3400 if (mr3 & MAC_INIT_COMPLETE)
3378 break; 3401 break;
3379 if (mr1 & MAC_INIT_COMPLETE && 3402 if (mr1 & MAC_INIT_COMPLETE &&
3380 priv->bus_type == BUS_TYPE_PCCARD) 3403 priv->bus_type == BUS_TYPE_PCCARD)
3381 break; 3404 break;
3382 } 3405 }
3383 3406
3384 if (i == 0) { 3407 if (i == 0) {
3385 printk(KERN_ALERT "%s: MAC failed to initialise.\n", priv->dev->name); 3408 printk(KERN_ALERT "%s: MAC failed to initialise.\n",
3409 priv->dev->name);
3386 return 0; 3410 return 0;
3387 } 3411 }
3388 3412
3389 /* Check for MAC_INIT_OK only on the register that the MAC_INIT_OK was set */ 3413 /* Check for MAC_INIT_OK only on the register that the MAC_INIT_OK was set */
3390 if ((mr3 & MAC_INIT_COMPLETE) && 3414 if ((mr3 & MAC_INIT_COMPLETE) &&
3391 !(atmel_read16(priv->dev, MR3) & MAC_INIT_OK)) { 3415 !(atmel_read16(priv->dev, MR3) & MAC_INIT_OK)) {
@@ -3398,9 +3422,9 @@ static int atmel_wakeup_firmware(struct atmel_private *priv)
3398 return 0; 3422 return 0;
3399 } 3423 }
3400 3424
3401 atmel_copy_to_host(priv->dev, (unsigned char *)iface, 3425 atmel_copy_to_host(priv->dev, (unsigned char *)iface,
3402 priv->host_info_base, sizeof(*iface)); 3426 priv->host_info_base, sizeof(*iface));
3403 3427
3404 iface->tx_buff_pos = le16_to_cpu(iface->tx_buff_pos); 3428 iface->tx_buff_pos = le16_to_cpu(iface->tx_buff_pos);
3405 iface->tx_buff_size = le16_to_cpu(iface->tx_buff_size); 3429 iface->tx_buff_size = le16_to_cpu(iface->tx_buff_size);
3406 iface->tx_desc_pos = le16_to_cpu(iface->tx_desc_pos); 3430 iface->tx_desc_pos = le16_to_cpu(iface->tx_desc_pos);
@@ -3424,16 +3448,16 @@ static int probe_atmel_card(struct net_device *dev)
3424{ 3448{
3425 int rc = 0; 3449 int rc = 0;
3426 struct atmel_private *priv = netdev_priv(dev); 3450 struct atmel_private *priv = netdev_priv(dev);
3427 3451
3428 /* reset pccard */ 3452 /* reset pccard */
3429 if (priv->bus_type == BUS_TYPE_PCCARD) 3453 if (priv->bus_type == BUS_TYPE_PCCARD)
3430 atmel_write16(dev, GCR, 0x0060); 3454 atmel_write16(dev, GCR, 0x0060);
3431 3455
3432 atmel_write16(dev, GCR, 0x0040); 3456 atmel_write16(dev, GCR, 0x0040);
3433 mdelay(500); 3457 mdelay(500);
3434 3458
3435 if (atmel_read16(dev, MR2) == 0) { 3459 if (atmel_read16(dev, MR2) == 0) {
3436 /* No stored firmware so load a small stub which just 3460 /* No stored firmware so load a small stub which just
3437 tells us the MAC address */ 3461 tells us the MAC address */
3438 int i; 3462 int i;
3439 priv->card_type = CARD_TYPE_EEPROM; 3463 priv->card_type = CARD_TYPE_EEPROM;
@@ -3442,7 +3466,7 @@ static int probe_atmel_card(struct net_device *dev)
3442 atmel_set_gcr(dev, GCR_REMAP); 3466 atmel_set_gcr(dev, GCR_REMAP);
3443 atmel_clear_gcr(priv->dev, 0x0040); 3467 atmel_clear_gcr(priv->dev, 0x0040);
3444 atmel_write16(dev, BSR, BSS_SRAM); 3468 atmel_write16(dev, BSR, BSS_SRAM);
3445 for (i = LOOP_RETRY_LIMIT; i; i--) 3469 for (i = LOOP_RETRY_LIMIT; i; i--)
3446 if (atmel_read16(dev, MR3) & MAC_BOOT_COMPLETE) 3470 if (atmel_read16(dev, MR3) & MAC_BOOT_COMPLETE)
3447 break; 3471 break;
3448 if (i == 0) { 3472 if (i == 0) {
@@ -3451,7 +3475,7 @@ static int probe_atmel_card(struct net_device *dev)
3451 atmel_copy_to_host(dev, dev->dev_addr, atmel_read16(dev, MR2), 6); 3475 atmel_copy_to_host(dev, dev->dev_addr, atmel_read16(dev, MR2), 6);
3452 /* got address, now squash it again until the network 3476 /* got address, now squash it again until the network
3453 interface is opened */ 3477 interface is opened */
3454 if (priv->bus_type == BUS_TYPE_PCCARD) 3478 if (priv->bus_type == BUS_TYPE_PCCARD)
3455 atmel_write16(dev, GCR, 0x0060); 3479 atmel_write16(dev, GCR, 0x0060);
3456 atmel_write16(dev, GCR, 0x0040); 3480 atmel_write16(dev, GCR, 0x0040);
3457 rc = 1; 3481 rc = 1;
@@ -3459,7 +3483,7 @@ static int probe_atmel_card(struct net_device *dev)
3459 } else if (atmel_read16(dev, MR4) == 0) { 3483 } else if (atmel_read16(dev, MR4) == 0) {
3460 /* Mac address easy in this case. */ 3484 /* Mac address easy in this case. */
3461 priv->card_type = CARD_TYPE_PARALLEL_FLASH; 3485 priv->card_type = CARD_TYPE_PARALLEL_FLASH;
3462 atmel_write16(dev, BSR, 1); 3486 atmel_write16(dev, BSR, 1);
3463 atmel_copy_to_host(dev, dev->dev_addr, 0xc000, 6); 3487 atmel_copy_to_host(dev, dev->dev_addr, 0xc000, 6);
3464 atmel_write16(dev, BSR, 0x200); 3488 atmel_write16(dev, BSR, 0x200);
3465 rc = 1; 3489 rc = 1;
@@ -3469,16 +3493,16 @@ static int probe_atmel_card(struct net_device *dev)
3469 priv->card_type = CARD_TYPE_SPI_FLASH; 3493 priv->card_type = CARD_TYPE_SPI_FLASH;
3470 if (atmel_wakeup_firmware(priv)) { 3494 if (atmel_wakeup_firmware(priv)) {
3471 atmel_get_mib(priv, Mac_Address_Mib_Type, 0, dev->dev_addr, 6); 3495 atmel_get_mib(priv, Mac_Address_Mib_Type, 0, dev->dev_addr, 6);
3472 3496
3473 /* got address, now squash it again until the network 3497 /* got address, now squash it again until the network
3474 interface is opened */ 3498 interface is opened */
3475 if (priv->bus_type == BUS_TYPE_PCCARD) 3499 if (priv->bus_type == BUS_TYPE_PCCARD)
3476 atmel_write16(dev, GCR, 0x0060); 3500 atmel_write16(dev, GCR, 0x0060);
3477 atmel_write16(dev, GCR, 0x0040); 3501 atmel_write16(dev, GCR, 0x0040);
3478 rc = 1; 3502 rc = 1;
3479 } 3503 }
3480 } 3504 }
3481 3505
3482 if (rc) { 3506 if (rc) {
3483 if (dev->dev_addr[0] == 0xFF) { 3507 if (dev->dev_addr[0] == 0xFF) {
3484 u8 default_mac[] = {0x00,0x04, 0x25, 0x00, 0x00, 0x00}; 3508 u8 default_mac[] = {0x00,0x04, 0x25, 0x00, 0x00, 0x00};
@@ -3486,27 +3510,27 @@ static int probe_atmel_card(struct net_device *dev)
3486 memcpy(dev->dev_addr, default_mac, 6); 3510 memcpy(dev->dev_addr, default_mac, 6);
3487 } 3511 }
3488 } 3512 }
3489 3513
3490 return rc; 3514 return rc;
3491} 3515}
3492 3516
3493static void build_wep_mib(struct atmel_private *priv)
3494/* Move the encyption information on the MIB structure. 3517/* Move the encyption information on the MIB structure.
3495 This routine is for the pre-WPA firmware: later firmware has 3518 This routine is for the pre-WPA firmware: later firmware has
3496 a different format MIB and a different routine. */ 3519 a different format MIB and a different routine. */
3520static void build_wep_mib(struct atmel_private *priv)
3497{ 3521{
3498 struct { /* NB this is matched to the hardware, don't change. */ 3522 struct { /* NB this is matched to the hardware, don't change. */
3499 u8 wep_is_on; 3523 u8 wep_is_on;
3500 u8 default_key; /* 0..3 */ 3524 u8 default_key; /* 0..3 */
3501 u8 reserved; 3525 u8 reserved;
3502 u8 exclude_unencrypted; 3526 u8 exclude_unencrypted;
3503 3527
3504 u32 WEPICV_error_count; 3528 u32 WEPICV_error_count;
3505 u32 WEP_excluded_count; 3529 u32 WEP_excluded_count;
3506 3530
3507 u8 wep_keys[MAX_ENCRYPTION_KEYS][13]; 3531 u8 wep_keys[MAX_ENCRYPTION_KEYS][13];
3508 u8 encryption_level; /* 0, 1, 2 */ 3532 u8 encryption_level; /* 0, 1, 2 */
3509 u8 reserved2[3]; 3533 u8 reserved2[3];
3510 } mib; 3534 } mib;
3511 int i; 3535 int i;
3512 3536
@@ -3515,54 +3539,55 @@ static void build_wep_mib(struct atmel_private *priv)
3515 if (priv->wep_key_len[priv->default_key] > 5) 3539 if (priv->wep_key_len[priv->default_key] > 5)
3516 mib.encryption_level = 2; 3540 mib.encryption_level = 2;
3517 else 3541 else
3518 mib.encryption_level = 1; 3542 mib.encryption_level = 1;
3519 } else { 3543 } else {
3520 mib.encryption_level = 0; 3544 mib.encryption_level = 0;
3521 } 3545 }
3522 3546
3523 mib.default_key = priv->default_key; 3547 mib.default_key = priv->default_key;
3524 mib.exclude_unencrypted = priv->exclude_unencrypted; 3548 mib.exclude_unencrypted = priv->exclude_unencrypted;
3525 3549
3526 for(i = 0; i < MAX_ENCRYPTION_KEYS; i++) 3550 for (i = 0; i < MAX_ENCRYPTION_KEYS; i++)
3527 memcpy(mib.wep_keys[i], priv->wep_keys[i], 13); 3551 memcpy(mib.wep_keys[i], priv->wep_keys[i], 13);
3528 3552
3529 atmel_set_mib(priv, Mac_Wep_Mib_Type, 0, (u8 *)&mib, sizeof(mib)); 3553 atmel_set_mib(priv, Mac_Wep_Mib_Type, 0, (u8 *)&mib, sizeof(mib));
3530} 3554}
3531 3555
3532static void build_wpa_mib(struct atmel_private *priv) 3556static void build_wpa_mib(struct atmel_private *priv)
3533{ 3557{
3534 /* This is for the later (WPA enabled) firmware. */ 3558 /* This is for the later (WPA enabled) firmware. */
3535 3559
3536 struct { /* NB this is matched to the hardware, don't change. */ 3560 struct { /* NB this is matched to the hardware, don't change. */
3537 u8 cipher_default_key_value[MAX_ENCRYPTION_KEYS][MAX_ENCRYPTION_KEY_SIZE]; 3561 u8 cipher_default_key_value[MAX_ENCRYPTION_KEYS][MAX_ENCRYPTION_KEY_SIZE];
3538 u8 receiver_address[6]; 3562 u8 receiver_address[6];
3539 u8 wep_is_on; 3563 u8 wep_is_on;
3540 u8 default_key; /* 0..3 */ 3564 u8 default_key; /* 0..3 */
3541 u8 group_key; 3565 u8 group_key;
3542 u8 exclude_unencrypted; 3566 u8 exclude_unencrypted;
3543 u8 encryption_type; 3567 u8 encryption_type;
3544 u8 reserved; 3568 u8 reserved;
3545 3569
3546 u32 WEPICV_error_count; 3570 u32 WEPICV_error_count;
3547 u32 WEP_excluded_count; 3571 u32 WEP_excluded_count;
3548 3572
3549 u8 key_RSC[4][8]; 3573 u8 key_RSC[4][8];
3550 } mib; 3574 } mib;
3551 3575
3552 int i; 3576 int i;
3553 3577
3554 mib.wep_is_on = priv->wep_is_on; 3578 mib.wep_is_on = priv->wep_is_on;
3555 mib.exclude_unencrypted = priv->exclude_unencrypted; 3579 mib.exclude_unencrypted = priv->exclude_unencrypted;
3556 memcpy(mib.receiver_address, priv->CurrentBSSID, 6); 3580 memcpy(mib.receiver_address, priv->CurrentBSSID, 6);
3557 3581
3558 /* zero all the keys before adding in valid ones. */ 3582 /* zero all the keys before adding in valid ones. */
3559 memset(mib.cipher_default_key_value, 0, sizeof(mib.cipher_default_key_value)); 3583 memset(mib.cipher_default_key_value, 0, sizeof(mib.cipher_default_key_value));
3560 3584
3561 if (priv->wep_is_on) { 3585 if (priv->wep_is_on) {
3562 /* There's a comment in the Atmel code to the effect that this is only valid 3586 /* There's a comment in the Atmel code to the effect that this
3563 when still using WEP, it may need to be set to something to use WPA */ 3587 is only valid when still using WEP, it may need to be set to
3588 something to use WPA */
3564 memset(mib.key_RSC, 0, sizeof(mib.key_RSC)); 3589 memset(mib.key_RSC, 0, sizeof(mib.key_RSC));
3565 3590
3566 mib.default_key = mib.group_key = 255; 3591 mib.default_key = mib.group_key = 255;
3567 for (i = 0; i < MAX_ENCRYPTION_KEYS; i++) { 3592 for (i = 0; i < MAX_ENCRYPTION_KEYS; i++) {
3568 if (priv->wep_key_len[i] > 0) { 3593 if (priv->wep_key_len[i] > 0) {
@@ -3570,12 +3595,12 @@ static void build_wpa_mib(struct atmel_private *priv)
3570 if (i == priv->default_key) { 3595 if (i == priv->default_key) {
3571 mib.default_key = i; 3596 mib.default_key = i;
3572 mib.cipher_default_key_value[i][MAX_ENCRYPTION_KEY_SIZE-1] = 7; 3597 mib.cipher_default_key_value[i][MAX_ENCRYPTION_KEY_SIZE-1] = 7;
3573 mib.cipher_default_key_value[i][MAX_ENCRYPTION_KEY_SIZE-2] = priv->pairwise_cipher_suite; 3598 mib.cipher_default_key_value[i][MAX_ENCRYPTION_KEY_SIZE-2] = priv->pairwise_cipher_suite;
3574 } else { 3599 } else {
3575 mib.group_key = i; 3600 mib.group_key = i;
3576 priv->group_cipher_suite = priv->pairwise_cipher_suite; 3601 priv->group_cipher_suite = priv->pairwise_cipher_suite;
3577 mib.cipher_default_key_value[i][MAX_ENCRYPTION_KEY_SIZE-1] = 1; 3602 mib.cipher_default_key_value[i][MAX_ENCRYPTION_KEY_SIZE-1] = 1;
3578 mib.cipher_default_key_value[i][MAX_ENCRYPTION_KEY_SIZE-2] = priv->group_cipher_suite; 3603 mib.cipher_default_key_value[i][MAX_ENCRYPTION_KEY_SIZE-2] = priv->group_cipher_suite;
3579 } 3604 }
3580 } 3605 }
3581 } 3606 }
@@ -3583,47 +3608,47 @@ static void build_wpa_mib(struct atmel_private *priv)
3583 mib.default_key = mib.group_key != 255 ? mib.group_key : 0; 3608 mib.default_key = mib.group_key != 255 ? mib.group_key : 0;
3584 if (mib.group_key == 255) 3609 if (mib.group_key == 255)
3585 mib.group_key = mib.default_key; 3610 mib.group_key = mib.default_key;
3586 3611
3587 } 3612 }
3588 3613
3589 atmel_set_mib(priv, Mac_Wep_Mib_Type, 0, (u8 *)&mib, sizeof(mib)); 3614 atmel_set_mib(priv, Mac_Wep_Mib_Type, 0, (u8 *)&mib, sizeof(mib));
3590} 3615}
3591 3616
3592static int reset_atmel_card(struct net_device *dev) 3617static int reset_atmel_card(struct net_device *dev)
3593{ 3618{
3594 /* do everything necessary to wake up the hardware, including 3619 /* do everything necessary to wake up the hardware, including
3595 waiting for the lightning strike and throwing the knife switch.... 3620 waiting for the lightning strike and throwing the knife switch....
3596 3621
3597 set all the Mib values which matter in the card to match 3622 set all the Mib values which matter in the card to match
3598 their settings in the atmel_private structure. Some of these 3623 their settings in the atmel_private structure. Some of these
3599 can be altered on the fly, but many (WEP, infrastucture or ad-hoc) 3624 can be altered on the fly, but many (WEP, infrastucture or ad-hoc)
3600 can only be changed by tearing down the world and coming back through 3625 can only be changed by tearing down the world and coming back through
3601 here. 3626 here.
3602 3627
3603 This routine is also responsible for initialising some 3628 This routine is also responsible for initialising some
3604 hardware-specific fields in the atmel_private structure, 3629 hardware-specific fields in the atmel_private structure,
3605 including a copy of the firmware's hostinfo stucture 3630 including a copy of the firmware's hostinfo stucture
3606 which is the route into the rest of the firmare datastructures. */ 3631 which is the route into the rest of the firmare datastructures. */
3607 3632
3608 struct atmel_private *priv = netdev_priv(dev); 3633 struct atmel_private *priv = netdev_priv(dev);
3609 u8 configuration; 3634 u8 configuration;
3610 3635
3611 /* data to add to the firmware names, in priority order 3636 /* data to add to the firmware names, in priority order
3612 this implemenents firmware versioning */ 3637 this implemenents firmware versioning */
3613 3638
3614 static char *firmware_modifier[] = { 3639 static char *firmware_modifier[] = {
3615 "-wpa", 3640 "-wpa",
3616 "", 3641 "",
3617 NULL 3642 NULL
3618 }; 3643 };
3619 3644
3620 /* reset pccard */ 3645 /* reset pccard */
3621 if (priv->bus_type == BUS_TYPE_PCCARD) 3646 if (priv->bus_type == BUS_TYPE_PCCARD)
3622 atmel_write16(priv->dev, GCR, 0x0060); 3647 atmel_write16(priv->dev, GCR, 0x0060);
3623 3648
3624 /* stop card , disable interrupts */ 3649 /* stop card , disable interrupts */
3625 atmel_write16(priv->dev, GCR, 0x0040); 3650 atmel_write16(priv->dev, GCR, 0x0040);
3626 3651
3627 if (priv->card_type == CARD_TYPE_EEPROM) { 3652 if (priv->card_type == CARD_TYPE_EEPROM) {
3628 /* copy in firmware if needed */ 3653 /* copy in firmware if needed */
3629 const struct firmware *fw_entry = NULL; 3654 const struct firmware *fw_entry = NULL;
@@ -3636,13 +3661,13 @@ static int reset_atmel_card(struct net_device *dev)
3636 "%s: card type is unknown: assuming at76c502 firmware is OK.\n", 3661 "%s: card type is unknown: assuming at76c502 firmware is OK.\n",
3637 dev->name); 3662 dev->name);
3638 printk(KERN_INFO 3663 printk(KERN_INFO
3639 "%s: if not, use the firmware= module parameter.\n", 3664 "%s: if not, use the firmware= module parameter.\n",
3640 dev->name); 3665 dev->name);
3641 strcpy(priv->firmware_id, "atmel_at76c502.bin"); 3666 strcpy(priv->firmware_id, "atmel_at76c502.bin");
3642 } 3667 }
3643 if (request_firmware(&fw_entry, priv->firmware_id, priv->sys_dev) != 0) { 3668 if (request_firmware(&fw_entry, priv->firmware_id, priv->sys_dev) != 0) {
3644 printk(KERN_ALERT 3669 printk(KERN_ALERT
3645 "%s: firmware %s is missing, cannot continue.\n", 3670 "%s: firmware %s is missing, cannot continue.\n",
3646 dev->name, priv->firmware_id); 3671 dev->name, priv->firmware_id);
3647 return 0; 3672 return 0;
3648 } 3673 }
@@ -3654,7 +3679,7 @@ static int reset_atmel_card(struct net_device *dev)
3654 while (fw_table[fw_index].fw_type != priv->firmware_type 3679 while (fw_table[fw_index].fw_type != priv->firmware_type
3655 && fw_table[fw_index].fw_type != ATMEL_FW_TYPE_NONE) 3680 && fw_table[fw_index].fw_type != ATMEL_FW_TYPE_NONE)
3656 fw_index++; 3681 fw_index++;
3657 3682
3658 /* construct the actual firmware file name */ 3683 /* construct the actual firmware file name */
3659 if (fw_table[fw_index].fw_type != ATMEL_FW_TYPE_NONE) { 3684 if (fw_table[fw_index].fw_type != ATMEL_FW_TYPE_NONE) {
3660 int i; 3685 int i;
@@ -3669,24 +3694,24 @@ static int reset_atmel_card(struct net_device *dev)
3669 } 3694 }
3670 } 3695 }
3671 if (!success) { 3696 if (!success) {
3672 printk(KERN_ALERT 3697 printk(KERN_ALERT
3673 "%s: firmware %s is missing, cannot start.\n", 3698 "%s: firmware %s is missing, cannot start.\n",
3674 dev->name, priv->firmware_id); 3699 dev->name, priv->firmware_id);
3675 priv->firmware_id[0] = '\0'; 3700 priv->firmware_id[0] = '\0';
3676 return 0; 3701 return 0;
3677 } 3702 }
3678 } 3703 }
3679 3704
3680 fw = fw_entry->data; 3705 fw = fw_entry->data;
3681 len = fw_entry->size; 3706 len = fw_entry->size;
3682 } 3707 }
3683 3708
3684 if (len <= 0x6000) { 3709 if (len <= 0x6000) {
3685 atmel_write16(priv->dev, BSR, BSS_IRAM); 3710 atmel_write16(priv->dev, BSR, BSS_IRAM);
3686 atmel_copy_to_card(priv->dev, 0, fw, len); 3711 atmel_copy_to_card(priv->dev, 0, fw, len);
3687 atmel_set_gcr(priv->dev, GCR_REMAP); 3712 atmel_set_gcr(priv->dev, GCR_REMAP);
3688 } else { 3713 } else {
3689 /* Remap */ 3714 /* Remap */
3690 atmel_set_gcr(priv->dev, GCR_REMAP); 3715 atmel_set_gcr(priv->dev, GCR_REMAP);
3691 atmel_write16(priv->dev, BSR, BSS_IRAM); 3716 atmel_write16(priv->dev, BSR, BSS_IRAM);
3692 atmel_copy_to_card(priv->dev, 0, fw, 0x6000); 3717 atmel_copy_to_card(priv->dev, 0, fw, 0x6000);
@@ -3708,45 +3733,45 @@ static int reset_atmel_card(struct net_device *dev)
3708 the 3com broken-ness filter. */ 3733 the 3com broken-ness filter. */
3709 priv->use_wpa = (priv->host_info.major_version == 4); 3734 priv->use_wpa = (priv->host_info.major_version == 4);
3710 priv->radio_on_broken = (priv->host_info.major_version == 5); 3735 priv->radio_on_broken = (priv->host_info.major_version == 5);
3711 3736
3712 /* unmask all irq sources */ 3737 /* unmask all irq sources */
3713 atmel_wmem8(priv, atmel_hi(priv, IFACE_INT_MASK_OFFSET), 0xff); 3738 atmel_wmem8(priv, atmel_hi(priv, IFACE_INT_MASK_OFFSET), 0xff);
3714 3739
3715 /* int Tx system and enable Tx */ 3740 /* int Tx system and enable Tx */
3716 atmel_wmem8(priv, atmel_tx(priv, TX_DESC_FLAGS_OFFSET, 0), 0); 3741 atmel_wmem8(priv, atmel_tx(priv, TX_DESC_FLAGS_OFFSET, 0), 0);
3717 atmel_wmem32(priv, atmel_tx(priv, TX_DESC_NEXT_OFFSET, 0), 0x80000000L); 3742 atmel_wmem32(priv, atmel_tx(priv, TX_DESC_NEXT_OFFSET, 0), 0x80000000L);
3718 atmel_wmem16(priv, atmel_tx(priv, TX_DESC_POS_OFFSET, 0), 0); 3743 atmel_wmem16(priv, atmel_tx(priv, TX_DESC_POS_OFFSET, 0), 0);
3719 atmel_wmem16(priv, atmel_tx(priv, TX_DESC_SIZE_OFFSET, 0), 0); 3744 atmel_wmem16(priv, atmel_tx(priv, TX_DESC_SIZE_OFFSET, 0), 0);
3720 3745
3721 priv->tx_desc_free = priv->host_info.tx_desc_count; 3746 priv->tx_desc_free = priv->host_info.tx_desc_count;
3722 priv->tx_desc_head = 0; 3747 priv->tx_desc_head = 0;
3723 priv->tx_desc_tail = 0; 3748 priv->tx_desc_tail = 0;
3724 priv->tx_desc_previous = 0; 3749 priv->tx_desc_previous = 0;
3725 priv->tx_free_mem = priv->host_info.tx_buff_size; 3750 priv->tx_free_mem = priv->host_info.tx_buff_size;
3726 priv->tx_buff_head = 0; 3751 priv->tx_buff_head = 0;
3727 priv->tx_buff_tail = 0; 3752 priv->tx_buff_tail = 0;
3728 3753
3729 configuration = atmel_rmem8(priv, atmel_hi(priv, IFACE_FUNC_CTRL_OFFSET)); 3754 configuration = atmel_rmem8(priv, atmel_hi(priv, IFACE_FUNC_CTRL_OFFSET));
3730 atmel_wmem8(priv, atmel_hi(priv, IFACE_FUNC_CTRL_OFFSET), 3755 atmel_wmem8(priv, atmel_hi(priv, IFACE_FUNC_CTRL_OFFSET),
3731 configuration | FUNC_CTRL_TxENABLE); 3756 configuration | FUNC_CTRL_TxENABLE);
3732 3757
3733 /* init Rx system and enable */ 3758 /* init Rx system and enable */
3734 priv->rx_desc_head = 0; 3759 priv->rx_desc_head = 0;
3735 3760
3736 configuration = atmel_rmem8(priv, atmel_hi(priv, IFACE_FUNC_CTRL_OFFSET)); 3761 configuration = atmel_rmem8(priv, atmel_hi(priv, IFACE_FUNC_CTRL_OFFSET));
3737 atmel_wmem8(priv, atmel_hi(priv, IFACE_FUNC_CTRL_OFFSET), 3762 atmel_wmem8(priv, atmel_hi(priv, IFACE_FUNC_CTRL_OFFSET),
3738 configuration | FUNC_CTRL_RxENABLE); 3763 configuration | FUNC_CTRL_RxENABLE);
3739 3764
3740 if (!priv->radio_on_broken) { 3765 if (!priv->radio_on_broken) {
3741 if (atmel_send_command_wait(priv, CMD_EnableRadio, NULL, 0) == 3766 if (atmel_send_command_wait(priv, CMD_EnableRadio, NULL, 0) ==
3742 CMD_STATUS_REJECTED_RADIO_OFF) { 3767 CMD_STATUS_REJECTED_RADIO_OFF) {
3743 printk(KERN_INFO 3768 printk(KERN_INFO
3744 "%s: cannot turn the radio on. (Hey radio, you're beautiful!)\n", 3769 "%s: cannot turn the radio on. (Hey radio, you're beautiful!)\n",
3745 dev->name); 3770 dev->name);
3746 return 0; 3771 return 0;
3747 } 3772 }
3748 } 3773 }
3749 3774
3750 /* set up enough MIB values to run. */ 3775 /* set up enough MIB values to run. */
3751 atmel_set_mib8(priv, Local_Mib_Type, LOCAL_MIB_AUTO_TX_RATE_POS, priv->auto_tx_rate); 3776 atmel_set_mib8(priv, Local_Mib_Type, LOCAL_MIB_AUTO_TX_RATE_POS, priv->auto_tx_rate);
3752 atmel_set_mib8(priv, Local_Mib_Type, LOCAL_MIB_TX_PROMISCUOUS_POS, PROM_MODE_OFF); 3777 atmel_set_mib8(priv, Local_Mib_Type, LOCAL_MIB_TX_PROMISCUOUS_POS, PROM_MODE_OFF);
@@ -3755,7 +3780,7 @@ static int reset_atmel_card(struct net_device *dev)
3755 atmel_set_mib8(priv, Mac_Mib_Type, MAC_MIB_SHORT_RETRY_POS, priv->short_retry); 3780 atmel_set_mib8(priv, Mac_Mib_Type, MAC_MIB_SHORT_RETRY_POS, priv->short_retry);
3756 atmel_set_mib8(priv, Mac_Mib_Type, MAC_MIB_LONG_RETRY_POS, priv->long_retry); 3781 atmel_set_mib8(priv, Mac_Mib_Type, MAC_MIB_LONG_RETRY_POS, priv->long_retry);
3757 atmel_set_mib8(priv, Local_Mib_Type, LOCAL_MIB_PREAMBLE_TYPE, priv->preamble); 3782 atmel_set_mib8(priv, Local_Mib_Type, LOCAL_MIB_PREAMBLE_TYPE, priv->preamble);
3758 atmel_set_mib(priv, Mac_Address_Mib_Type, MAC_ADDR_MIB_MAC_ADDR_POS, 3783 atmel_set_mib(priv, Mac_Address_Mib_Type, MAC_ADDR_MIB_MAC_ADDR_POS,
3759 priv->dev->dev_addr, 6); 3784 priv->dev->dev_addr, 6);
3760 atmel_set_mib8(priv, Mac_Mgmt_Mib_Type, MAC_MGMT_MIB_PS_MODE_POS, ACTIVE_MODE); 3785 atmel_set_mib8(priv, Mac_Mgmt_Mib_Type, MAC_MGMT_MIB_PS_MODE_POS, ACTIVE_MODE);
3761 atmel_set_mib16(priv, Mac_Mgmt_Mib_Type, MAC_MGMT_MIB_LISTEN_INTERVAL_POS, 1); 3786 atmel_set_mib16(priv, Mac_Mgmt_Mib_Type, MAC_MGMT_MIB_LISTEN_INTERVAL_POS, 1);
@@ -3766,42 +3791,44 @@ static int reset_atmel_card(struct net_device *dev)
3766 build_wpa_mib(priv); 3791 build_wpa_mib(priv);
3767 else 3792 else
3768 build_wep_mib(priv); 3793 build_wep_mib(priv);
3769 3794
3770 return 1; 3795 return 1;
3771} 3796}
3772 3797
3773static void atmel_send_command(struct atmel_private *priv, int command, void *cmd, int cmd_size) 3798static void atmel_send_command(struct atmel_private *priv, int command,
3799 void *cmd, int cmd_size)
3774{ 3800{
3775 if (cmd) 3801 if (cmd)
3776 atmel_copy_to_card(priv->dev, atmel_co(priv, CMD_BLOCK_PARAMETERS_OFFSET), 3802 atmel_copy_to_card(priv->dev, atmel_co(priv, CMD_BLOCK_PARAMETERS_OFFSET),
3777 cmd, cmd_size); 3803 cmd, cmd_size);
3778 3804
3779 atmel_wmem8(priv, atmel_co(priv, CMD_BLOCK_COMMAND_OFFSET), command); 3805 atmel_wmem8(priv, atmel_co(priv, CMD_BLOCK_COMMAND_OFFSET), command);
3780 atmel_wmem8(priv, atmel_co(priv, CMD_BLOCK_STATUS_OFFSET), 0); 3806 atmel_wmem8(priv, atmel_co(priv, CMD_BLOCK_STATUS_OFFSET), 0);
3781} 3807}
3782 3808
3783static int atmel_send_command_wait(struct atmel_private *priv, int command, void *cmd, int cmd_size) 3809static int atmel_send_command_wait(struct atmel_private *priv, int command,
3810 void *cmd, int cmd_size)
3784{ 3811{
3785 int i, status; 3812 int i, status;
3786 3813
3787 atmel_send_command(priv, command, cmd, cmd_size); 3814 atmel_send_command(priv, command, cmd, cmd_size);
3788 3815
3789 for (i = 5000; i; i--) { 3816 for (i = 5000; i; i--) {
3790 status = atmel_rmem8(priv, atmel_co(priv, CMD_BLOCK_STATUS_OFFSET)); 3817 status = atmel_rmem8(priv, atmel_co(priv, CMD_BLOCK_STATUS_OFFSET));
3791 if (status != CMD_STATUS_IDLE && 3818 if (status != CMD_STATUS_IDLE &&
3792 status != CMD_STATUS_IN_PROGRESS) 3819 status != CMD_STATUS_IN_PROGRESS)
3793 break; 3820 break;
3794 udelay(20); 3821 udelay(20);
3795 } 3822 }
3796 3823
3797 if (i == 0) { 3824 if (i == 0) {
3798 printk(KERN_ALERT "%s: failed to contact MAC.\n", priv->dev->name); 3825 printk(KERN_ALERT "%s: failed to contact MAC.\n", priv->dev->name);
3799 status = CMD_STATUS_HOST_ERROR; 3826 status = CMD_STATUS_HOST_ERROR;
3800 } else { 3827 } else {
3801 if (command != CMD_EnableRadio) 3828 if (command != CMD_EnableRadio)
3802 status = CMD_STATUS_COMPLETE; 3829 status = CMD_STATUS_COMPLETE;
3803 } 3830 }
3804 3831
3805 return status; 3832 return status;
3806} 3833}
3807 3834
@@ -3827,7 +3854,8 @@ static void atmel_set_mib8(struct atmel_private *priv, u8 type, u8 index, u8 dat
3827 atmel_send_command_wait(priv, CMD_Set_MIB_Vars, &m, MIB_HEADER_SIZE + 1); 3854 atmel_send_command_wait(priv, CMD_Set_MIB_Vars, &m, MIB_HEADER_SIZE + 1);
3828} 3855}
3829 3856
3830static void atmel_set_mib16(struct atmel_private *priv, u8 type, u8 index, u16 data) 3857static void atmel_set_mib16(struct atmel_private *priv, u8 type, u8 index,
3858 u16 data)
3831{ 3859{
3832 struct get_set_mib m; 3860 struct get_set_mib m;
3833 m.type = type; 3861 m.type = type;
@@ -3839,7 +3867,8 @@ static void atmel_set_mib16(struct atmel_private *priv, u8 type, u8 index, u16 d
3839 atmel_send_command_wait(priv, CMD_Set_MIB_Vars, &m, MIB_HEADER_SIZE + 2); 3867 atmel_send_command_wait(priv, CMD_Set_MIB_Vars, &m, MIB_HEADER_SIZE + 2);
3840} 3868}
3841 3869
3842static void atmel_set_mib(struct atmel_private *priv, u8 type, u8 index, u8 *data, int data_len) 3870static void atmel_set_mib(struct atmel_private *priv, u8 type, u8 index,
3871 u8 *data, int data_len)
3843{ 3872{
3844 struct get_set_mib m; 3873 struct get_set_mib m;
3845 m.type = type; 3874 m.type = type;
@@ -3848,23 +3877,24 @@ static void atmel_set_mib(struct atmel_private *priv, u8 type, u8 index, u8 *dat
3848 3877
3849 if (data_len > MIB_MAX_DATA_BYTES) 3878 if (data_len > MIB_MAX_DATA_BYTES)
3850 printk(KERN_ALERT "%s: MIB buffer too small.\n", priv->dev->name); 3879 printk(KERN_ALERT "%s: MIB buffer too small.\n", priv->dev->name);
3851 3880
3852 memcpy(m.data, data, data_len); 3881 memcpy(m.data, data, data_len);
3853 atmel_send_command_wait(priv, CMD_Set_MIB_Vars, &m, MIB_HEADER_SIZE + data_len); 3882 atmel_send_command_wait(priv, CMD_Set_MIB_Vars, &m, MIB_HEADER_SIZE + data_len);
3854} 3883}
3855 3884
3856static void atmel_get_mib(struct atmel_private *priv, u8 type, u8 index, u8 *data, int data_len) 3885static void atmel_get_mib(struct atmel_private *priv, u8 type, u8 index,
3886 u8 *data, int data_len)
3857{ 3887{
3858 struct get_set_mib m; 3888 struct get_set_mib m;
3859 m.type = type; 3889 m.type = type;
3860 m.size = data_len; 3890 m.size = data_len;
3861 m.index = index; 3891 m.index = index;
3862 3892
3863 if (data_len > MIB_MAX_DATA_BYTES) 3893 if (data_len > MIB_MAX_DATA_BYTES)
3864 printk(KERN_ALERT "%s: MIB buffer too small.\n", priv->dev->name); 3894 printk(KERN_ALERT "%s: MIB buffer too small.\n", priv->dev->name);
3865 3895
3866 atmel_send_command_wait(priv, CMD_Get_MIB_Vars, &m, MIB_HEADER_SIZE + data_len); 3896 atmel_send_command_wait(priv, CMD_Get_MIB_Vars, &m, MIB_HEADER_SIZE + data_len);
3867 atmel_copy_to_host(priv->dev, data, 3897 atmel_copy_to_host(priv->dev, data,
3868 atmel_co(priv, CMD_BLOCK_PARAMETERS_OFFSET + MIB_HEADER_SIZE), data_len); 3898 atmel_co(priv, CMD_BLOCK_PARAMETERS_OFFSET + MIB_HEADER_SIZE), data_len);
3869} 3899}
3870 3900
@@ -3873,11 +3903,12 @@ static void atmel_writeAR(struct net_device *dev, u16 data)
3873 int i; 3903 int i;
3874 outw(data, dev->base_addr + AR); 3904 outw(data, dev->base_addr + AR);
3875 /* Address register appears to need some convincing..... */ 3905 /* Address register appears to need some convincing..... */
3876 for (i = 0; data != inw(dev->base_addr + AR) && i<10; i++) 3906 for (i = 0; data != inw(dev->base_addr + AR) && i < 10; i++)
3877 outw(data, dev->base_addr + AR); 3907 outw(data, dev->base_addr + AR);
3878} 3908}
3879 3909
3880static void atmel_copy_to_card(struct net_device *dev, u16 dest, unsigned char *src, u16 len) 3910static void atmel_copy_to_card(struct net_device *dev, u16 dest,
3911 unsigned char *src, u16 len)
3881{ 3912{
3882 int i; 3913 int i;
3883 atmel_writeAR(dev, dest); 3914 atmel_writeAR(dev, dest);
@@ -3894,7 +3925,8 @@ static void atmel_copy_to_card(struct net_device *dev, u16 dest, unsigned char *
3894 atmel_write8(dev, DR, *src); 3925 atmel_write8(dev, DR, *src);
3895} 3926}
3896 3927
3897static void atmel_copy_to_host(struct net_device *dev, unsigned char *dest, u16 src, u16 len) 3928static void atmel_copy_to_host(struct net_device *dev, unsigned char *dest,
3929 u16 src, u16 len)
3898{ 3930{
3899 int i; 3931 int i;
3900 atmel_writeAR(dev, src); 3932 atmel_writeAR(dev, src);
@@ -3930,22 +3962,24 @@ static int atmel_lock_mac(struct atmel_private *priv)
3930 break; 3962 break;
3931 udelay(20); 3963 udelay(20);
3932 } 3964 }
3933 3965
3934 if (!i) return 0; /* timed out */ 3966 if (!i)
3935 3967 return 0; /* timed out */
3968
3936 atmel_wmem8(priv, atmel_hi(priv, IFACE_LOCKOUT_MAC_OFFSET), 1); 3969 atmel_wmem8(priv, atmel_hi(priv, IFACE_LOCKOUT_MAC_OFFSET), 1);
3937 if (atmel_rmem8(priv, atmel_hi(priv, IFACE_LOCKOUT_HOST_OFFSET))) { 3970 if (atmel_rmem8(priv, atmel_hi(priv, IFACE_LOCKOUT_HOST_OFFSET))) {
3938 atmel_wmem8(priv, atmel_hi(priv, IFACE_LOCKOUT_MAC_OFFSET), 0); 3971 atmel_wmem8(priv, atmel_hi(priv, IFACE_LOCKOUT_MAC_OFFSET), 0);
3939 if (!j--) return 0; /* timed out */ 3972 if (!j--)
3973 return 0; /* timed out */
3940 goto retry; 3974 goto retry;
3941 } 3975 }
3942 3976
3943 return 1; 3977 return 1;
3944} 3978}
3945 3979
3946static void atmel_wmem32(struct atmel_private *priv, u16 pos, u32 data) 3980static void atmel_wmem32(struct atmel_private *priv, u16 pos, u32 data)
3947{ 3981{
3948 atmel_writeAR(priv->dev, pos); 3982 atmel_writeAR(priv->dev, pos);
3949 atmel_write16(priv->dev, DR, data); /* card is little-endian */ 3983 atmel_write16(priv->dev, DR, data); /* card is little-endian */
3950 atmel_write16(priv->dev, DR, data >> 16); 3984 atmel_write16(priv->dev, DR, data >> 16);
3951} 3985}
@@ -4017,9 +4051,9 @@ static void atmel_wmem32(struct atmel_private *priv, u16 pos, u32 data)
4017 serial output, since SO is normally high. But it 4051 serial output, since SO is normally high. But it
4018 does cause 8 clock cycles and thus 8 bits to be 4052 does cause 8 clock cycles and thus 8 bits to be
4019 clocked in to the chip. See Atmel's SPI 4053 clocked in to the chip. See Atmel's SPI
4020 controller (e.g. AT91M55800) timing and 4K 4054 controller (e.g. AT91M55800) timing and 4K
4021 SPI EEPROM manuals */ 4055 SPI EEPROM manuals */
4022 4056
4023 .set NVRAM_SCRATCH, 0x02000100 /* arbitrary area for scratchpad memory */ 4057 .set NVRAM_SCRATCH, 0x02000100 /* arbitrary area for scratchpad memory */
4024 .set NVRAM_IMAGE, 0x02000200 4058 .set NVRAM_IMAGE, 0x02000200
4025 .set NVRAM_LENGTH, 0x0200 4059 .set NVRAM_LENGTH, 0x0200
@@ -4032,24 +4066,24 @@ static void atmel_wmem32(struct atmel_private *priv, u16 pos, u32 data)
4032 .set MR4, 0xC 4066 .set MR4, 0xC
4033RESET_VECTOR: 4067RESET_VECTOR:
4034 b RESET_HANDLER 4068 b RESET_HANDLER
4035UNDEF_VECTOR: 4069UNDEF_VECTOR:
4036 b HALT1 4070 b HALT1
4037SWI_VECTOR: 4071SWI_VECTOR:
4038 b HALT1 4072 b HALT1
4039IABORT_VECTOR: 4073IABORT_VECTOR:
4040 b HALT1 4074 b HALT1
4041DABORT_VECTOR: 4075DABORT_VECTOR:
4042RESERVED_VECTOR: 4076RESERVED_VECTOR:
4043 b HALT1 4077 b HALT1
4044IRQ_VECTOR: 4078IRQ_VECTOR:
4045 b HALT1 4079 b HALT1
4046FIQ_VECTOR: 4080FIQ_VECTOR:
4047 b HALT1 4081 b HALT1
4048HALT1: b HALT1 4082HALT1: b HALT1
4049RESET_HANDLER: 4083RESET_HANDLER:
4050 mov r0, #CPSR_INITIAL 4084 mov r0, #CPSR_INITIAL
4051 msr CPSR_c, r0 /* This is probably unnecessary */ 4085 msr CPSR_c, r0 /* This is probably unnecessary */
4052 4086
4053/* I'm guessing this is initializing clock generator electronics for SPI */ 4087/* I'm guessing this is initializing clock generator electronics for SPI */
4054 ldr r0, =SPI_CGEN_BASE 4088 ldr r0, =SPI_CGEN_BASE
4055 mov r1, #0 4089 mov r1, #0
@@ -4061,7 +4095,7 @@ RESET_HANDLER:
4061 str r1, [r0, #28] 4095 str r1, [r0, #28]
4062 mov r1, #1 4096 mov r1, #1
4063 str r1, [r0, #8] 4097 str r1, [r0, #8]
4064 4098
4065 ldr r0, =MRBASE 4099 ldr r0, =MRBASE
4066 mov r1, #0 4100 mov r1, #0
4067 strh r1, [r0, #MR1] 4101 strh r1, [r0, #MR1]
@@ -4094,7 +4128,7 @@ GET_WHOLE_NVRAM:
4094 ldmia sp!, {lr} 4128 ldmia sp!, {lr}
4095 bx lr 4129 bx lr
4096.endfunc 4130.endfunc
4097 4131
4098.func Get_MAC_Addr, GET_MAC_ADDR 4132.func Get_MAC_Addr, GET_MAC_ADDR
4099GET_MAC_ADDR: 4133GET_MAC_ADDR:
4100 stmdb sp!, {lr} 4134 stmdb sp!, {lr}
@@ -4110,13 +4144,13 @@ GET_MAC_ADDR:
4110.func Delay9, DELAY9 4144.func Delay9, DELAY9
4111DELAY9: 4145DELAY9:
4112 adds r0, r0, r0, LSL #3 /* r0 = r0 * 9 */ 4146 adds r0, r0, r0, LSL #3 /* r0 = r0 * 9 */
4113DELAYLOOP: 4147DELAYLOOP:
4114 beq DELAY9_done 4148 beq DELAY9_done
4115 subs r0, r0, #1 4149 subs r0, r0, #1
4116 b DELAYLOOP 4150 b DELAYLOOP
4117DELAY9_done: 4151DELAY9_done:
4118 bx lr 4152 bx lr
4119.endfunc 4153.endfunc
4120 4154
4121.func SP_Init, SP_INIT 4155.func SP_Init, SP_INIT
4122SP_INIT: 4156SP_INIT:
@@ -4145,26 +4179,26 @@ SP_INIT:
4145 ldr r0, [r0, #SP_RDR] 4179 ldr r0, [r0, #SP_RDR]
4146 bx lr 4180 bx lr
4147.endfunc 4181.endfunc
4148.func NVRAM_Init, NVRAM_INIT 4182.func NVRAM_Init, NVRAM_INIT
4149NVRAM_INIT: 4183NVRAM_INIT:
4150 ldr r1, =SP_BASE 4184 ldr r1, =SP_BASE
4151 ldr r0, [r1, #SP_RDR] 4185 ldr r0, [r1, #SP_RDR]
4152 mov r0, #NVRAM_CMD_RDSR 4186 mov r0, #NVRAM_CMD_RDSR
4153 str r0, [r1, #SP_TDR] 4187 str r0, [r1, #SP_TDR]
4154SP_loop1: 4188SP_loop1:
4155 ldr r0, [r1, #SP_SR] 4189 ldr r0, [r1, #SP_SR]
4156 tst r0, #SP_TDRE 4190 tst r0, #SP_TDRE
4157 beq SP_loop1 4191 beq SP_loop1
4158 4192
4159 mov r0, #SPI_8CLOCKS 4193 mov r0, #SPI_8CLOCKS
4160 str r0, [r1, #SP_TDR] 4194 str r0, [r1, #SP_TDR]
4161SP_loop2: 4195SP_loop2:
4162 ldr r0, [r1, #SP_SR] 4196 ldr r0, [r1, #SP_SR]
4163 tst r0, #SP_TDRE 4197 tst r0, #SP_TDRE
4164 beq SP_loop2 4198 beq SP_loop2
4165 4199
4166 ldr r0, [r1, #SP_RDR] 4200 ldr r0, [r1, #SP_RDR]
4167SP_loop3: 4201SP_loop3:
4168 ldr r0, [r1, #SP_SR] 4202 ldr r0, [r1, #SP_SR]
4169 tst r0, #SP_RDRF 4203 tst r0, #SP_RDRF
4170 beq SP_loop3 4204 beq SP_loop3
@@ -4173,7 +4207,7 @@ SP_loop3:
4173 and r0, r0, #255 4207 and r0, r0, #255
4174 bx lr 4208 bx lr
4175.endfunc 4209.endfunc
4176 4210
4177.func NVRAM_Xfer, NVRAM_XFER 4211.func NVRAM_Xfer, NVRAM_XFER
4178 /* r0 = dest address */ 4212 /* r0 = dest address */
4179 /* r1 = not used */ 4213 /* r1 = not used */
@@ -4185,11 +4219,11 @@ NVRAM_XFER:
4185 mov r4, r3 /* save r3 (length) */ 4219 mov r4, r3 /* save r3 (length) */
4186 mov r0, r2, LSR #5 /* SPI memories put A8 in the command field */ 4220 mov r0, r2, LSR #5 /* SPI memories put A8 in the command field */
4187 and r0, r0, #8 4221 and r0, r0, #8
4188 add r0, r0, #NVRAM_CMD_READ 4222 add r0, r0, #NVRAM_CMD_READ
4189 ldr r1, =NVRAM_SCRATCH 4223 ldr r1, =NVRAM_SCRATCH
4190 strb r0, [r1, #0] /* save command in NVRAM_SCRATCH[0] */ 4224 strb r0, [r1, #0] /* save command in NVRAM_SCRATCH[0] */
4191 strb r2, [r1, #1] /* save low byte of source address in NVRAM_SCRATCH[1] */ 4225 strb r2, [r1, #1] /* save low byte of source address in NVRAM_SCRATCH[1] */
4192_local1: 4226_local1:
4193 bl NVRAM_INIT 4227 bl NVRAM_INIT
4194 tst r0, #NVRAM_SR_RDY 4228 tst r0, #NVRAM_SR_RDY
4195 bne _local1 4229 bne _local1
@@ -4211,7 +4245,7 @@ NVRAM_XFER2:
4211 cmp r0, #0 4245 cmp r0, #0
4212 bls _local2 4246 bls _local2
4213 ldr r5, =NVRAM_SCRATCH 4247 ldr r5, =NVRAM_SCRATCH
4214_local4: 4248_local4:
4215 ldrb r6, [r5, r3] 4249 ldrb r6, [r5, r3]
4216 str r6, [r4, #SP_TDR] 4250 str r6, [r4, #SP_TDR]
4217_local3: 4251_local3:
@@ -4225,7 +4259,7 @@ _local2:
4225 mov r3, #SPI_8CLOCKS 4259 mov r3, #SPI_8CLOCKS
4226 str r3, [r4, #SP_TDR] 4260 str r3, [r4, #SP_TDR]
4227 ldr r0, [r4, #SP_RDR] 4261 ldr r0, [r4, #SP_RDR]
4228_local5: 4262_local5:
4229 ldr r0, [r4, #SP_SR] 4263 ldr r0, [r4, #SP_SR]
4230 tst r0, #SP_RDRF 4264 tst r0, #SP_RDRF
4231 beq _local5 4265 beq _local5
@@ -4233,12 +4267,12 @@ _local5:
4233 mov r0, #0 4267 mov r0, #0
4234 cmp r2, #0 /* r2 is # of bytes to copy in */ 4268 cmp r2, #0 /* r2 is # of bytes to copy in */
4235 bls _local6 4269 bls _local6
4236_local7: 4270_local7:
4237 ldr r5, [r4, #SP_SR] 4271 ldr r5, [r4, #SP_SR]
4238 tst r5, #SP_TDRE 4272 tst r5, #SP_TDRE
4239 beq _local7 4273 beq _local7
4240 str r3, [r4, #SP_TDR] /* r3 has SPI_8CLOCKS */ 4274 str r3, [r4, #SP_TDR] /* r3 has SPI_8CLOCKS */
4241_local8: 4275_local8:
4242 ldr r5, [r4, #SP_SR] 4276 ldr r5, [r4, #SP_SR]
4243 tst r5, #SP_RDRF 4277 tst r5, #SP_RDRF
4244 beq _local8 4278 beq _local8
diff --git a/drivers/net/wireless/atmel_cs.c b/drivers/net/wireless/atmel_cs.c
index 17d1fd90f832..d6f4a5a3e55a 100644
--- a/drivers/net/wireless/atmel_cs.c
+++ b/drivers/net/wireless/atmel_cs.c
@@ -93,8 +93,6 @@ MODULE_SUPPORTED_DEVICE("Atmel at76c50x PCMCIA cards");
93 93
94static void atmel_config(dev_link_t *link); 94static void atmel_config(dev_link_t *link);
95static void atmel_release(dev_link_t *link); 95static void atmel_release(dev_link_t *link);
96static int atmel_event(event_t event, int priority,
97 event_callback_args_t *args);
98 96
99/* 97/*
100 The attach() and detach() entry points are used to create and destroy 98 The attach() and detach() entry points are used to create and destroy
@@ -102,8 +100,7 @@ static int atmel_event(event_t event, int priority,
102 needed to manage one actual PCMCIA card. 100 needed to manage one actual PCMCIA card.
103*/ 101*/
104 102
105static dev_link_t *atmel_attach(void); 103static void atmel_detach(struct pcmcia_device *p_dev);
106static void atmel_detach(dev_link_t *);
107 104
108/* 105/*
109 You'll also need to prototype all the functions that will actually 106 You'll also need to prototype all the functions that will actually
@@ -113,14 +110,6 @@ static void atmel_detach(dev_link_t *);
113*/ 110*/
114 111
115/* 112/*
116 The dev_info variable is the "key" that is used to match up this
117 device driver with appropriate cards, through the card configuration
118 database.
119*/
120
121static dev_info_t dev_info = "atmel_cs";
122
123/*
124 A linked list of "instances" of the atmelnet device. Each actual 113 A linked list of "instances" of the atmelnet device. Each actual
125 PCMCIA card corresponds to one device instance, and is described 114 PCMCIA card corresponds to one device instance, and is described
126 by one dev_link_t structure (defined in ds.h). 115 by one dev_link_t structure (defined in ds.h).
@@ -130,15 +119,7 @@ static dev_info_t dev_info = "atmel_cs";
130 device numbers are used to derive the corresponding array index. 119 device numbers are used to derive the corresponding array index.
131*/ 120*/
132 121
133static dev_link_t *dev_list = NULL;
134
135/* 122/*
136 A dev_link_t structure has fields for most things that are needed
137 to keep track of a socket, but there will usually be some device
138 specific information that also needs to be kept track of. The
139 'priv' pointer in a dev_link_t structure can be used to point to
140 a device-specific private data structure, like this.
141
142 A driver needs to provide a dev_node_t structure for each device 123 A driver needs to provide a dev_node_t structure for each device
143 on a card. In some cases, there is only one device per card (for 124 on a card. In some cases, there is only one device per card (for
144 example, ethernet cards, modems). In other cases, there may be 125 example, ethernet cards, modems). In other cases, there may be
@@ -171,27 +152,25 @@ typedef struct local_info_t {
171 152
172 ======================================================================*/ 153 ======================================================================*/
173 154
174static dev_link_t *atmel_attach(void) 155static int atmel_attach(struct pcmcia_device *p_dev)
175{ 156{
176 client_reg_t client_reg;
177 dev_link_t *link; 157 dev_link_t *link;
178 local_info_t *local; 158 local_info_t *local;
179 int ret; 159
180
181 DEBUG(0, "atmel_attach()\n"); 160 DEBUG(0, "atmel_attach()\n");
182 161
183 /* Initialize the dev_link_t structure */ 162 /* Initialize the dev_link_t structure */
184 link = kzalloc(sizeof(struct dev_link_t), GFP_KERNEL); 163 link = kzalloc(sizeof(struct dev_link_t), GFP_KERNEL);
185 if (!link) { 164 if (!link) {
186 printk(KERN_ERR "atmel_cs: no memory for new device\n"); 165 printk(KERN_ERR "atmel_cs: no memory for new device\n");
187 return NULL; 166 return -ENOMEM;
188 } 167 }
189 168
190 /* Interrupt setup */ 169 /* Interrupt setup */
191 link->irq.Attributes = IRQ_TYPE_EXCLUSIVE; 170 link->irq.Attributes = IRQ_TYPE_EXCLUSIVE;
192 link->irq.IRQInfo1 = IRQ_LEVEL_ID; 171 link->irq.IRQInfo1 = IRQ_LEVEL_ID;
193 link->irq.Handler = NULL; 172 link->irq.Handler = NULL;
194 173
195 /* 174 /*
196 General socket configuration defaults can go here. In this 175 General socket configuration defaults can go here. In this
197 client, we assume very little, and rely on the CIS for almost 176 client, we assume very little, and rely on the CIS for almost
@@ -202,30 +181,23 @@ static dev_link_t *atmel_attach(void)
202 link->conf.Attributes = 0; 181 link->conf.Attributes = 0;
203 link->conf.Vcc = 50; 182 link->conf.Vcc = 50;
204 link->conf.IntType = INT_MEMORY_AND_IO; 183 link->conf.IntType = INT_MEMORY_AND_IO;
205 184
206 /* Allocate space for private device-specific data */ 185 /* Allocate space for private device-specific data */
207 local = kzalloc(sizeof(local_info_t), GFP_KERNEL); 186 local = kzalloc(sizeof(local_info_t), GFP_KERNEL);
208 if (!local) { 187 if (!local) {
209 printk(KERN_ERR "atmel_cs: no memory for new device\n"); 188 printk(KERN_ERR "atmel_cs: no memory for new device\n");
210 kfree (link); 189 kfree (link);
211 return NULL; 190 return -ENOMEM;
212 } 191 }
213 link->priv = local; 192 link->priv = local;
214 193
215 /* Register with Card Services */ 194 link->handle = p_dev;
216 link->next = dev_list; 195 p_dev->instance = link;
217 dev_list = link; 196
218 client_reg.dev_info = &dev_info; 197 link->state |= DEV_PRESENT | DEV_CONFIG_PENDING;
219 client_reg.Version = 0x0210; 198 atmel_config(link);
220 client_reg.event_callback_args.client_data = link; 199
221 ret = pcmcia_register_client(&link->handle, &client_reg); 200 return 0;
222 if (ret != 0) {
223 cs_error(link->handle, RegisterClient, ret);
224 atmel_detach(link);
225 return NULL;
226 }
227
228 return link;
229} /* atmel_attach */ 201} /* atmel_attach */
230 202
231/*====================================================================== 203/*======================================================================
@@ -237,27 +209,15 @@ static dev_link_t *atmel_attach(void)
237 209
238 ======================================================================*/ 210 ======================================================================*/
239 211
240static void atmel_detach(dev_link_t *link) 212static void atmel_detach(struct pcmcia_device *p_dev)
241{ 213{
242 dev_link_t **linkp; 214 dev_link_t *link = dev_to_instance(p_dev);
243 215
244 DEBUG(0, "atmel_detach(0x%p)\n", link); 216 DEBUG(0, "atmel_detach(0x%p)\n", link);
245
246 /* Locate device structure */
247 for (linkp = &dev_list; *linkp; linkp = &(*linkp)->next)
248 if (*linkp == link) break;
249 if (*linkp == NULL)
250 return;
251 217
252 if (link->state & DEV_CONFIG) 218 if (link->state & DEV_CONFIG)
253 atmel_release(link); 219 atmel_release(link);
254
255 /* Break the link with Card Services */
256 if (link->handle)
257 pcmcia_deregister_client(link->handle);
258 220
259 /* Unlink device structure, free pieces */
260 *linkp = link->next;
261 kfree(link->priv); 221 kfree(link->priv);
262 kfree(link); 222 kfree(link);
263} 223}
@@ -477,60 +437,34 @@ static void atmel_release(dev_link_t *link)
477 link->state &= ~DEV_CONFIG; 437 link->state &= ~DEV_CONFIG;
478} 438}
479 439
480/*====================================================================== 440static int atmel_suspend(struct pcmcia_device *dev)
481 441{
482 The card status event handler. Mostly, this schedules other 442 dev_link_t *link = dev_to_instance(dev);
483 stuff to run after an event is received. 443 local_info_t *local = link->priv;
484 444
485 When a CARD_REMOVAL event is received, we immediately set a 445 link->state |= DEV_SUSPEND;
486 private flag to block future accesses to this device. All the 446 if (link->state & DEV_CONFIG) {
487 functions that actually access the device should check this flag 447 netif_device_detach(local->eth_dev);
488 to make sure the card is still present. 448 pcmcia_release_configuration(link->handle);
489 449 }
490 ======================================================================*/ 450
451 return 0;
452}
491 453
492static int atmel_event(event_t event, int priority, 454static int atmel_resume(struct pcmcia_device *dev)
493 event_callback_args_t *args)
494{ 455{
495 dev_link_t *link = args->client_data; 456 dev_link_t *link = dev_to_instance(dev);
496 local_info_t *local = link->priv; 457 local_info_t *local = link->priv;
497 458
498 DEBUG(1, "atmel_event(0x%06x)\n", event); 459 link->state &= ~DEV_SUSPEND;
499 460 if (link->state & DEV_CONFIG) {
500 switch (event) { 461 pcmcia_request_configuration(link->handle, &link->conf);
501 case CS_EVENT_CARD_REMOVAL: 462 atmel_open(local->eth_dev);
502 link->state &= ~DEV_PRESENT; 463 netif_device_attach(local->eth_dev);
503 if (link->state & DEV_CONFIG) {
504 netif_device_detach(local->eth_dev);
505 atmel_release(link);
506 }
507 break;
508 case CS_EVENT_CARD_INSERTION:
509 link->state |= DEV_PRESENT | DEV_CONFIG_PENDING;
510 atmel_config(link);
511 break;
512 case CS_EVENT_PM_SUSPEND:
513 link->state |= DEV_SUSPEND;
514 /* Fall through... */
515 case CS_EVENT_RESET_PHYSICAL:
516 if (link->state & DEV_CONFIG) {
517 netif_device_detach(local->eth_dev);
518 pcmcia_release_configuration(link->handle);
519 }
520 break;
521 case CS_EVENT_PM_RESUME:
522 link->state &= ~DEV_SUSPEND;
523 /* Fall through... */
524 case CS_EVENT_CARD_RESET:
525 if (link->state & DEV_CONFIG) {
526 pcmcia_request_configuration(link->handle, &link->conf);
527 atmel_open(local->eth_dev);
528 netif_device_attach(local->eth_dev);
529 }
530 break;
531 } 464 }
465
532 return 0; 466 return 0;
533} /* atmel_event */ 467}
534 468
535/*====================================================================*/ 469/*====================================================================*/
536/* We use the driver_info field to store the correct firmware type for a card. */ 470/* We use the driver_info field to store the correct firmware type for a card. */
@@ -581,10 +515,11 @@ static struct pcmcia_driver atmel_driver = {
581 .drv = { 515 .drv = {
582 .name = "atmel_cs", 516 .name = "atmel_cs",
583 }, 517 },
584 .attach = atmel_attach, 518 .probe = atmel_attach,
585 .event = atmel_event, 519 .remove = atmel_detach,
586 .detach = atmel_detach,
587 .id_table = atmel_ids, 520 .id_table = atmel_ids,
521 .suspend = atmel_suspend,
522 .resume = atmel_resume,
588}; 523};
589 524
590static int atmel_cs_init(void) 525static int atmel_cs_init(void)
@@ -595,7 +530,6 @@ static int atmel_cs_init(void)
595static void atmel_cs_cleanup(void) 530static void atmel_cs_cleanup(void)
596{ 531{
597 pcmcia_unregister_driver(&atmel_driver); 532 pcmcia_unregister_driver(&atmel_driver);
598 BUG_ON(dev_list != NULL);
599} 533}
600 534
601/* 535/*
diff --git a/drivers/net/wireless/hostap/Makefile b/drivers/net/wireless/hostap/Makefile
index fc62235bfc24..353ccb93134b 100644
--- a/drivers/net/wireless/hostap/Makefile
+++ b/drivers/net/wireless/hostap/Makefile
@@ -1,3 +1,4 @@
1hostap-y := hostap_main.o
1obj-$(CONFIG_HOSTAP) += hostap.o 2obj-$(CONFIG_HOSTAP) += hostap.o
2 3
3obj-$(CONFIG_HOSTAP_CS) += hostap_cs.o 4obj-$(CONFIG_HOSTAP_CS) += hostap_cs.o
diff --git a/drivers/net/wireless/hostap/hostap_cs.c b/drivers/net/wireless/hostap/hostap_cs.c
index 2643976a6677..8bc0b528548f 100644
--- a/drivers/net/wireless/hostap/hostap_cs.c
+++ b/drivers/net/wireless/hostap/hostap_cs.c
@@ -25,7 +25,6 @@
25 25
26static char *version = PRISM2_VERSION " (Jouni Malinen <jkmaline@cc.hut.fi>)"; 26static char *version = PRISM2_VERSION " (Jouni Malinen <jkmaline@cc.hut.fi>)";
27static dev_info_t dev_info = "hostap_cs"; 27static dev_info_t dev_info = "hostap_cs";
28static dev_link_t *dev_list = NULL;
29 28
30MODULE_AUTHOR("Jouni Malinen"); 29MODULE_AUTHOR("Jouni Malinen");
31MODULE_DESCRIPTION("Support for Intersil Prism2-based 802.11 wireless LAN " 30MODULE_DESCRIPTION("Support for Intersil Prism2-based 802.11 wireless LAN "
@@ -203,10 +202,9 @@ static int hfa384x_to_bap(struct net_device *dev, u16 bap, void *buf, int len)
203 202
204 203
205 204
206static void prism2_detach(dev_link_t *link); 205static void prism2_detach(struct pcmcia_device *p_dev);
207static void prism2_release(u_long arg); 206static void prism2_release(u_long arg);
208static int prism2_event(event_t event, int priority, 207static int prism2_config(dev_link_t *link);
209 event_callback_args_t *args);
210 208
211 209
212static int prism2_pccard_card_present(local_info_t *local) 210static int prism2_pccard_card_present(local_info_t *local)
@@ -503,15 +501,13 @@ static struct prism2_helper_functions prism2_pccard_funcs =
503 501
504/* allocate local data and register with CardServices 502/* allocate local data and register with CardServices
505 * initialize dev_link structure, but do not configure the card yet */ 503 * initialize dev_link structure, but do not configure the card yet */
506static dev_link_t *prism2_attach(void) 504static int prism2_attach(struct pcmcia_device *p_dev)
507{ 505{
508 dev_link_t *link; 506 dev_link_t *link;
509 client_reg_t client_reg;
510 int ret;
511 507
512 link = kmalloc(sizeof(dev_link_t), GFP_KERNEL); 508 link = kmalloc(sizeof(dev_link_t), GFP_KERNEL);
513 if (link == NULL) 509 if (link == NULL)
514 return NULL; 510 return -ENOMEM;
515 511
516 memset(link, 0, sizeof(dev_link_t)); 512 memset(link, 0, sizeof(dev_link_t));
517 513
@@ -519,50 +515,27 @@ static dev_link_t *prism2_attach(void)
519 link->conf.Vcc = 33; 515 link->conf.Vcc = 33;
520 link->conf.IntType = INT_MEMORY_AND_IO; 516 link->conf.IntType = INT_MEMORY_AND_IO;
521 517
522 /* register with CardServices */ 518 link->handle = p_dev;
523 link->next = dev_list; 519 p_dev->instance = link;
524 dev_list = link; 520
525 client_reg.dev_info = &dev_info; 521 link->state |= DEV_PRESENT | DEV_CONFIG_PENDING;
526 client_reg.Version = 0x0210; 522 if (prism2_config(link))
527 client_reg.event_callback_args.client_data = link; 523 PDEBUG(DEBUG_EXTRA, "prism2_config() failed\n");
528 ret = pcmcia_register_client(&link->handle, &client_reg); 524
529 if (ret != CS_SUCCESS) { 525 return 0;
530 cs_error(link->handle, RegisterClient, ret);
531 prism2_detach(link);
532 return NULL;
533 }
534 return link;
535} 526}
536 527
537 528
538static void prism2_detach(dev_link_t *link) 529static void prism2_detach(struct pcmcia_device *p_dev)
539{ 530{
540 dev_link_t **linkp; 531 dev_link_t *link = dev_to_instance(p_dev);
541 532
542 PDEBUG(DEBUG_FLOW, "prism2_detach\n"); 533 PDEBUG(DEBUG_FLOW, "prism2_detach\n");
543 534
544 for (linkp = &dev_list; *linkp; linkp = &(*linkp)->next)
545 if (*linkp == link)
546 break;
547 if (*linkp == NULL) {
548 printk(KERN_WARNING "%s: Attempt to detach non-existing "
549 "PCMCIA client\n", dev_info);
550 return;
551 }
552
553 if (link->state & DEV_CONFIG) { 535 if (link->state & DEV_CONFIG) {
554 prism2_release((u_long)link); 536 prism2_release((u_long)link);
555 } 537 }
556 538
557 if (link->handle) {
558 int res = pcmcia_deregister_client(link->handle);
559 if (res) {
560 printk("CardService(DeregisterClient) => %d\n", res);
561 cs_error(link->handle, DeregisterClient, res);
562 }
563 }
564
565 *linkp = link->next;
566 /* release net devices */ 539 /* release net devices */
567 if (link->priv) { 540 if (link->priv) {
568 struct hostap_cs_priv *hw_priv; 541 struct hostap_cs_priv *hw_priv;
@@ -846,84 +819,58 @@ static void prism2_release(u_long arg)
846 PDEBUG(DEBUG_FLOW, "release - done\n"); 819 PDEBUG(DEBUG_FLOW, "release - done\n");
847} 820}
848 821
849 822static int hostap_cs_suspend(struct pcmcia_device *p_dev)
850static int prism2_event(event_t event, int priority,
851 event_callback_args_t *args)
852{ 823{
853 dev_link_t *link = args->client_data; 824 dev_link_t *link = dev_to_instance(p_dev);
854 struct net_device *dev = (struct net_device *) link->priv; 825 struct net_device *dev = (struct net_device *) link->priv;
855 int dev_open = 0; 826 int dev_open = 0;
856 827
828 PDEBUG(DEBUG_EXTRA, "%s: CS_EVENT_PM_SUSPEND\n", dev_info);
829
830 link->state |= DEV_SUSPEND;
831
857 if (link->state & DEV_CONFIG) { 832 if (link->state & DEV_CONFIG) {
858 struct hostap_interface *iface = netdev_priv(dev); 833 struct hostap_interface *iface = netdev_priv(dev);
859 if (iface && iface->local) 834 if (iface && iface->local)
860 dev_open = iface->local->num_dev_open > 0; 835 dev_open = iface->local->num_dev_open > 0;
861 } 836 if (dev_open) {
862
863 switch (event) {
864 case CS_EVENT_CARD_INSERTION:
865 PDEBUG(DEBUG_EXTRA, "%s: CS_EVENT_CARD_INSERTION\n", dev_info);
866 link->state |= DEV_PRESENT | DEV_CONFIG_PENDING;
867 if (prism2_config(link)) {
868 PDEBUG(DEBUG_EXTRA, "prism2_config() failed\n");
869 }
870 break;
871
872 case CS_EVENT_CARD_REMOVAL:
873 PDEBUG(DEBUG_EXTRA, "%s: CS_EVENT_CARD_REMOVAL\n", dev_info);
874 link->state &= ~DEV_PRESENT;
875 if (link->state & DEV_CONFIG) {
876 netif_stop_queue(dev); 837 netif_stop_queue(dev);
877 netif_device_detach(dev); 838 netif_device_detach(dev);
878 prism2_release((u_long) link);
879 } 839 }
880 break; 840 prism2_suspend(dev);
841 pcmcia_release_configuration(link->handle);
842 }
881 843
882 case CS_EVENT_PM_SUSPEND: 844 return 0;
883 PDEBUG(DEBUG_EXTRA, "%s: CS_EVENT_PM_SUSPEND\n", dev_info); 845}
884 link->state |= DEV_SUSPEND;
885 /* fall through */
886
887 case CS_EVENT_RESET_PHYSICAL:
888 PDEBUG(DEBUG_EXTRA, "%s: CS_EVENT_RESET_PHYSICAL\n", dev_info);
889 if (link->state & DEV_CONFIG) {
890 if (dev_open) {
891 netif_stop_queue(dev);
892 netif_device_detach(dev);
893 }
894 prism2_suspend(dev);
895 pcmcia_release_configuration(link->handle);
896 }
897 break;
898 846
899 case CS_EVENT_PM_RESUME: 847static int hostap_cs_resume(struct pcmcia_device *p_dev)
900 PDEBUG(DEBUG_EXTRA, "%s: CS_EVENT_PM_RESUME\n", dev_info); 848{
901 link->state &= ~DEV_SUSPEND; 849 dev_link_t *link = dev_to_instance(p_dev);
902 /* fall through */ 850 struct net_device *dev = (struct net_device *) link->priv;
903 851 int dev_open = 0;
904 case CS_EVENT_CARD_RESET:
905 PDEBUG(DEBUG_EXTRA, "%s: CS_EVENT_CARD_RESET\n", dev_info);
906 if (link->state & DEV_CONFIG) {
907 pcmcia_request_configuration(link->handle,
908 &link->conf);
909 prism2_hw_shutdown(dev, 1);
910 prism2_hw_config(dev, dev_open ? 0 : 1);
911 if (dev_open) {
912 netif_device_attach(dev);
913 netif_start_queue(dev);
914 }
915 }
916 break;
917 852
918 default: 853 PDEBUG(DEBUG_EXTRA, "%s: CS_EVENT_PM_RESUME\n", dev_info);
919 PDEBUG(DEBUG_EXTRA, "%s: prism2_event() - unknown event %d\n", 854
920 dev_info, event); 855 link->state &= ~DEV_SUSPEND;
921 break; 856 if (link->state & DEV_CONFIG) {
857 struct hostap_interface *iface = netdev_priv(dev);
858 if (iface && iface->local)
859 dev_open = iface->local->num_dev_open > 0;
860
861 pcmcia_request_configuration(link->handle, &link->conf);
862
863 prism2_hw_shutdown(dev, 1);
864 prism2_hw_config(dev, dev_open ? 0 : 1);
865 if (dev_open) {
866 netif_device_attach(dev);
867 netif_start_queue(dev);
868 }
922 } 869 }
870
923 return 0; 871 return 0;
924} 872}
925 873
926
927static struct pcmcia_device_id hostap_cs_ids[] = { 874static struct pcmcia_device_id hostap_cs_ids[] = {
928 PCMCIA_DEVICE_MANF_CARD(0x000b, 0x7100), 875 PCMCIA_DEVICE_MANF_CARD(0x000b, 0x7100),
929 PCMCIA_DEVICE_MANF_CARD(0x000b, 0x7300), 876 PCMCIA_DEVICE_MANF_CARD(0x000b, 0x7300),
@@ -982,11 +929,12 @@ static struct pcmcia_driver hostap_driver = {
982 .drv = { 929 .drv = {
983 .name = "hostap_cs", 930 .name = "hostap_cs",
984 }, 931 },
985 .attach = prism2_attach, 932 .probe = prism2_attach,
986 .detach = prism2_detach, 933 .remove = prism2_detach,
987 .owner = THIS_MODULE, 934 .owner = THIS_MODULE,
988 .event = prism2_event,
989 .id_table = hostap_cs_ids, 935 .id_table = hostap_cs_ids,
936 .suspend = hostap_cs_suspend,
937 .resume = hostap_cs_resume,
990}; 938};
991 939
992static int __init init_prism2_pccard(void) 940static int __init init_prism2_pccard(void)
diff --git a/drivers/net/wireless/hostap/hostap.c b/drivers/net/wireless/hostap/hostap_main.c
index 3d2ea61033be..3d2ea61033be 100644
--- a/drivers/net/wireless/hostap/hostap.c
+++ b/drivers/net/wireless/hostap/hostap_main.c
diff --git a/drivers/net/wireless/ipw2100.c b/drivers/net/wireless/ipw2100.c
index 77d2a21d4cd0..44cd3fcd1572 100644
--- a/drivers/net/wireless/ipw2100.c
+++ b/drivers/net/wireless/ipw2100.c
@@ -175,7 +175,7 @@ that only one external action is invoked at a time.
175#define DRV_COPYRIGHT "Copyright(c) 2003-2005 Intel Corporation" 175#define DRV_COPYRIGHT "Copyright(c) 2003-2005 Intel Corporation"
176 176
177/* Debugging stuff */ 177/* Debugging stuff */
178#ifdef CONFIG_IPW_DEBUG 178#ifdef CONFIG_IPW2100_DEBUG
179#define CONFIG_IPW2100_RX_DEBUG /* Reception debugging */ 179#define CONFIG_IPW2100_RX_DEBUG /* Reception debugging */
180#endif 180#endif
181 181
@@ -208,7 +208,7 @@ MODULE_PARM_DESC(disable, "manually disable the radio (default 0 [radio on])");
208 208
209static u32 ipw2100_debug_level = IPW_DL_NONE; 209static u32 ipw2100_debug_level = IPW_DL_NONE;
210 210
211#ifdef CONFIG_IPW_DEBUG 211#ifdef CONFIG_IPW2100_DEBUG
212#define IPW_DEBUG(level, message...) \ 212#define IPW_DEBUG(level, message...) \
213do { \ 213do { \
214 if (ipw2100_debug_level & (level)) { \ 214 if (ipw2100_debug_level & (level)) { \
@@ -219,9 +219,9 @@ do { \
219} while (0) 219} while (0)
220#else 220#else
221#define IPW_DEBUG(level, message...) do {} while (0) 221#define IPW_DEBUG(level, message...) do {} while (0)
222#endif /* CONFIG_IPW_DEBUG */ 222#endif /* CONFIG_IPW2100_DEBUG */
223 223
224#ifdef CONFIG_IPW_DEBUG 224#ifdef CONFIG_IPW2100_DEBUG
225static const char *command_types[] = { 225static const char *command_types[] = {
226 "undefined", 226 "undefined",
227 "unused", /* HOST_ATTENTION */ 227 "unused", /* HOST_ATTENTION */
@@ -2081,7 +2081,7 @@ static void isr_scan_complete(struct ipw2100_priv *priv, u32 status)
2081 priv->status &= ~STATUS_SCANNING; 2081 priv->status &= ~STATUS_SCANNING;
2082} 2082}
2083 2083
2084#ifdef CONFIG_IPW_DEBUG 2084#ifdef CONFIG_IPW2100_DEBUG
2085#define IPW2100_HANDLER(v, f) { v, f, # v } 2085#define IPW2100_HANDLER(v, f) { v, f, # v }
2086struct ipw2100_status_indicator { 2086struct ipw2100_status_indicator {
2087 int status; 2087 int status;
@@ -2094,7 +2094,7 @@ struct ipw2100_status_indicator {
2094 int status; 2094 int status;
2095 void (*cb) (struct ipw2100_priv * priv, u32 status); 2095 void (*cb) (struct ipw2100_priv * priv, u32 status);
2096}; 2096};
2097#endif /* CONFIG_IPW_DEBUG */ 2097#endif /* CONFIG_IPW2100_DEBUG */
2098 2098
2099static void isr_indicate_scanning(struct ipw2100_priv *priv, u32 status) 2099static void isr_indicate_scanning(struct ipw2100_priv *priv, u32 status)
2100{ 2100{
@@ -2149,7 +2149,7 @@ static void isr_status_change(struct ipw2100_priv *priv, int status)
2149static void isr_rx_complete_command(struct ipw2100_priv *priv, 2149static void isr_rx_complete_command(struct ipw2100_priv *priv,
2150 struct ipw2100_cmd_header *cmd) 2150 struct ipw2100_cmd_header *cmd)
2151{ 2151{
2152#ifdef CONFIG_IPW_DEBUG 2152#ifdef CONFIG_IPW2100_DEBUG
2153 if (cmd->host_command_reg < ARRAY_SIZE(command_types)) { 2153 if (cmd->host_command_reg < ARRAY_SIZE(command_types)) {
2154 IPW_DEBUG_HC("Command completed '%s (%d)'\n", 2154 IPW_DEBUG_HC("Command completed '%s (%d)'\n",
2155 command_types[cmd->host_command_reg], 2155 command_types[cmd->host_command_reg],
@@ -2167,7 +2167,7 @@ static void isr_rx_complete_command(struct ipw2100_priv *priv,
2167 wake_up_interruptible(&priv->wait_command_queue); 2167 wake_up_interruptible(&priv->wait_command_queue);
2168} 2168}
2169 2169
2170#ifdef CONFIG_IPW_DEBUG 2170#ifdef CONFIG_IPW2100_DEBUG
2171static const char *frame_types[] = { 2171static const char *frame_types[] = {
2172 "COMMAND_STATUS_VAL", 2172 "COMMAND_STATUS_VAL",
2173 "STATUS_CHANGE_VAL", 2173 "STATUS_CHANGE_VAL",
@@ -2290,7 +2290,7 @@ static u8 packet_data[IPW_RX_NIC_BUFFER_LENGTH];
2290 2290
2291static inline void ipw2100_corruption_detected(struct ipw2100_priv *priv, int i) 2291static inline void ipw2100_corruption_detected(struct ipw2100_priv *priv, int i)
2292{ 2292{
2293#ifdef CONFIG_IPW_DEBUG_C3 2293#ifdef CONFIG_IPW2100_DEBUG_C3
2294 struct ipw2100_status *status = &priv->status_queue.drv[i]; 2294 struct ipw2100_status *status = &priv->status_queue.drv[i];
2295 u32 match, reg; 2295 u32 match, reg;
2296 int j; 2296 int j;
@@ -2312,7 +2312,7 @@ static inline void ipw2100_corruption_detected(struct ipw2100_priv *priv, int i)
2312 } 2312 }
2313#endif 2313#endif
2314 2314
2315#ifdef CONFIG_IPW_DEBUG_C3 2315#ifdef CONFIG_IPW2100_DEBUG_C3
2316 /* Halt the fimrware so we can get a good image */ 2316 /* Halt the fimrware so we can get a good image */
2317 write_register(priv->net_dev, IPW_REG_RESET_REG, 2317 write_register(priv->net_dev, IPW_REG_RESET_REG,
2318 IPW_AUX_HOST_RESET_REG_STOP_MASTER); 2318 IPW_AUX_HOST_RESET_REG_STOP_MASTER);
@@ -2716,7 +2716,7 @@ static inline int __ipw2100_tx_process(struct ipw2100_priv *priv)
2716 list_del(element); 2716 list_del(element);
2717 DEC_STAT(&priv->fw_pend_stat); 2717 DEC_STAT(&priv->fw_pend_stat);
2718 2718
2719#ifdef CONFIG_IPW_DEBUG 2719#ifdef CONFIG_IPW2100_DEBUG
2720 { 2720 {
2721 int i = txq->oldest; 2721 int i = txq->oldest;
2722 IPW_DEBUG_TX("TX%d V=%p P=%04X T=%04X L=%d\n", i, 2722 IPW_DEBUG_TX("TX%d V=%p P=%04X T=%04X L=%d\n", i,
@@ -2782,7 +2782,7 @@ static inline int __ipw2100_tx_process(struct ipw2100_priv *priv)
2782 "something else: ids %d=%d.\n", 2782 "something else: ids %d=%d.\n",
2783 priv->net_dev->name, txq->oldest, packet->index); 2783 priv->net_dev->name, txq->oldest, packet->index);
2784 2784
2785#ifdef CONFIG_IPW_DEBUG 2785#ifdef CONFIG_IPW2100_DEBUG
2786 if (packet->info.c_struct.cmd->host_command_reg < 2786 if (packet->info.c_struct.cmd->host_command_reg <
2787 sizeof(command_types) / sizeof(*command_types)) 2787 sizeof(command_types) / sizeof(*command_types))
2788 IPW_DEBUG_TX("Command '%s (%d)' processed: %d.\n", 2788 IPW_DEBUG_TX("Command '%s (%d)' processed: %d.\n",
@@ -2975,7 +2975,7 @@ static void ipw2100_tx_send_data(struct ipw2100_priv *priv)
2975 2975
2976 IPW_DEBUG_TX("data header tbd TX%d P=%08x L=%d\n", 2976 IPW_DEBUG_TX("data header tbd TX%d P=%08x L=%d\n",
2977 packet->index, tbd->host_addr, tbd->buf_length); 2977 packet->index, tbd->host_addr, tbd->buf_length);
2978#ifdef CONFIG_IPW_DEBUG 2978#ifdef CONFIG_IPW2100_DEBUG
2979 if (packet->info.d_struct.txb->nr_frags > 1) 2979 if (packet->info.d_struct.txb->nr_frags > 1)
2980 IPW_DEBUG_FRAG("fragment Tx: %d frames\n", 2980 IPW_DEBUG_FRAG("fragment Tx: %d frames\n",
2981 packet->info.d_struct.txb->nr_frags); 2981 packet->info.d_struct.txb->nr_frags);
@@ -3827,7 +3827,7 @@ static ssize_t show_stats(struct device *d, struct device_attribute *attr,
3827 priv->rx_interrupts, priv->inta_other); 3827 priv->rx_interrupts, priv->inta_other);
3828 out += sprintf(out, "firmware resets: %d\n", priv->resets); 3828 out += sprintf(out, "firmware resets: %d\n", priv->resets);
3829 out += sprintf(out, "firmware hangs: %d\n", priv->hangs); 3829 out += sprintf(out, "firmware hangs: %d\n", priv->hangs);
3830#ifdef CONFIG_IPW_DEBUG 3830#ifdef CONFIG_IPW2100_DEBUG
3831 out += sprintf(out, "packet mismatch image: %s\n", 3831 out += sprintf(out, "packet mismatch image: %s\n",
3832 priv->snapshot[0] ? "YES" : "NO"); 3832 priv->snapshot[0] ? "YES" : "NO");
3833#endif 3833#endif
@@ -3982,7 +3982,7 @@ static ssize_t show_bssinfo(struct device *d, struct device_attribute *attr,
3982 3982
3983static DEVICE_ATTR(bssinfo, S_IRUGO, show_bssinfo, NULL); 3983static DEVICE_ATTR(bssinfo, S_IRUGO, show_bssinfo, NULL);
3984 3984
3985#ifdef CONFIG_IPW_DEBUG 3985#ifdef CONFIG_IPW2100_DEBUG
3986static ssize_t show_debug_level(struct device_driver *d, char *buf) 3986static ssize_t show_debug_level(struct device_driver *d, char *buf)
3987{ 3987{
3988 return sprintf(buf, "0x%08X\n", ipw2100_debug_level); 3988 return sprintf(buf, "0x%08X\n", ipw2100_debug_level);
@@ -4011,7 +4011,7 @@ static ssize_t store_debug_level(struct device_driver *d,
4011 4011
4012static DRIVER_ATTR(debug_level, S_IWUSR | S_IRUGO, show_debug_level, 4012static DRIVER_ATTR(debug_level, S_IWUSR | S_IRUGO, show_debug_level,
4013 store_debug_level); 4013 store_debug_level);
4014#endif /* CONFIG_IPW_DEBUG */ 4014#endif /* CONFIG_IPW2100_DEBUG */
4015 4015
4016static ssize_t show_fatal_error(struct device *d, 4016static ssize_t show_fatal_error(struct device *d,
4017 struct device_attribute *attr, char *buf) 4017 struct device_attribute *attr, char *buf)
@@ -4937,7 +4937,7 @@ static int ipw2100_set_mandatory_bssid(struct ipw2100_priv *priv, u8 * bssid,
4937 }; 4937 };
4938 int err; 4938 int err;
4939 4939
4940#ifdef CONFIG_IPW_DEBUG 4940#ifdef CONFIG_IPW2100_DEBUG
4941 if (bssid != NULL) 4941 if (bssid != NULL)
4942 IPW_DEBUG_HC("MANDATORY_BSSID: %02X:%02X:%02X:%02X:%02X:%02X\n", 4942 IPW_DEBUG_HC("MANDATORY_BSSID: %02X:%02X:%02X:%02X:%02X:%02X\n",
4943 bssid[0], bssid[1], bssid[2], bssid[3], bssid[4], 4943 bssid[0], bssid[1], bssid[2], bssid[3], bssid[4],
@@ -6858,7 +6858,7 @@ static int __init ipw2100_init(void)
6858 6858
6859 ret = pci_module_init(&ipw2100_pci_driver); 6859 ret = pci_module_init(&ipw2100_pci_driver);
6860 6860
6861#ifdef CONFIG_IPW_DEBUG 6861#ifdef CONFIG_IPW2100_DEBUG
6862 ipw2100_debug_level = debug; 6862 ipw2100_debug_level = debug;
6863 driver_create_file(&ipw2100_pci_driver.driver, 6863 driver_create_file(&ipw2100_pci_driver.driver,
6864 &driver_attr_debug_level); 6864 &driver_attr_debug_level);
@@ -6873,7 +6873,7 @@ static int __init ipw2100_init(void)
6873static void __exit ipw2100_exit(void) 6873static void __exit ipw2100_exit(void)
6874{ 6874{
6875 /* FIXME: IPG: check that we have no instances of the devices open */ 6875 /* FIXME: IPG: check that we have no instances of the devices open */
6876#ifdef CONFIG_IPW_DEBUG 6876#ifdef CONFIG_IPW2100_DEBUG
6877 driver_remove_file(&ipw2100_pci_driver.driver, 6877 driver_remove_file(&ipw2100_pci_driver.driver,
6878 &driver_attr_debug_level); 6878 &driver_attr_debug_level);
6879#endif 6879#endif
@@ -8558,7 +8558,7 @@ static struct iw_statistics *ipw2100_wx_wireless_stats(struct net_device *dev)
8558 8558
8559 quality = min(beacon_qual, min(tx_qual, rssi_qual)); 8559 quality = min(beacon_qual, min(tx_qual, rssi_qual));
8560 8560
8561#ifdef CONFIG_IPW_DEBUG 8561#ifdef CONFIG_IPW2100_DEBUG
8562 if (beacon_qual == quality) 8562 if (beacon_qual == quality)
8563 IPW_DEBUG_WX("Quality clamped by Missed Beacons\n"); 8563 IPW_DEBUG_WX("Quality clamped by Missed Beacons\n");
8564 else if (tx_qual == quality) 8564 else if (tx_qual == quality)
diff --git a/drivers/net/wireless/ipw2100.h b/drivers/net/wireless/ipw2100.h
index 7c65b10bb164..f6c51441fa87 100644
--- a/drivers/net/wireless/ipw2100.h
+++ b/drivers/net/wireless/ipw2100.h
@@ -73,7 +73,7 @@ struct ipw2100_rx_packet;
73 * you simply need to add your entry to the ipw2100_debug_levels array. 73 * you simply need to add your entry to the ipw2100_debug_levels array.
74 * 74 *
75 * If you do not see debug_level in /proc/net/ipw2100 then you do not have 75 * If you do not see debug_level in /proc/net/ipw2100 then you do not have
76 * CONFIG_IPW_DEBUG defined in your kernel configuration 76 * CONFIG_IPW2100_DEBUG defined in your kernel configuration
77 * 77 *
78 */ 78 */
79 79
diff --git a/drivers/net/wireless/ipw2200.c b/drivers/net/wireless/ipw2200.c
index 5e7c7e944c9d..cdfe50207757 100644
--- a/drivers/net/wireless/ipw2200.c
+++ b/drivers/net/wireless/ipw2200.c
@@ -462,7 +462,7 @@ static inline void ipw_disable_interrupts(struct ipw_priv *priv)
462 ipw_write32(priv, IPW_INTA_MASK_R, ~IPW_INTA_MASK_ALL); 462 ipw_write32(priv, IPW_INTA_MASK_R, ~IPW_INTA_MASK_ALL);
463} 463}
464 464
465#ifdef CONFIG_IPW_DEBUG 465#ifdef CONFIG_IPW2200_DEBUG
466static char *ipw_error_desc(u32 val) 466static char *ipw_error_desc(u32 val)
467{ 467{
468 switch (val) { 468 switch (val) {
@@ -1235,7 +1235,7 @@ static ssize_t store_scan_age(struct device *d, struct device_attribute *attr,
1235 const char *buf, size_t count) 1235 const char *buf, size_t count)
1236{ 1236{
1237 struct ipw_priv *priv = dev_get_drvdata(d); 1237 struct ipw_priv *priv = dev_get_drvdata(d);
1238#ifdef CONFIG_IPW_DEBUG 1238#ifdef CONFIG_IPW2200_DEBUG
1239 struct net_device *dev = priv->net_dev; 1239 struct net_device *dev = priv->net_dev;
1240#endif 1240#endif
1241 char buffer[] = "00000000"; 1241 char buffer[] = "00000000";
@@ -1754,7 +1754,7 @@ static void ipw_irq_tasklet(struct ipw_priv *priv)
1754 IPW_ERROR("Firmware error detected. Restarting.\n"); 1754 IPW_ERROR("Firmware error detected. Restarting.\n");
1755 if (priv->error) { 1755 if (priv->error) {
1756 IPW_ERROR("Sysfs 'error' log already exists.\n"); 1756 IPW_ERROR("Sysfs 'error' log already exists.\n");
1757#ifdef CONFIG_IPW_DEBUG 1757#ifdef CONFIG_IPW2200_DEBUG
1758 if (ipw_debug_level & IPW_DL_FW_ERRORS) { 1758 if (ipw_debug_level & IPW_DL_FW_ERRORS) {
1759 struct ipw_fw_error *error = 1759 struct ipw_fw_error *error =
1760 ipw_alloc_error_log(priv); 1760 ipw_alloc_error_log(priv);
@@ -1770,7 +1770,7 @@ static void ipw_irq_tasklet(struct ipw_priv *priv)
1770 else 1770 else
1771 IPW_ERROR("Error allocating sysfs 'error' " 1771 IPW_ERROR("Error allocating sysfs 'error' "
1772 "log.\n"); 1772 "log.\n");
1773#ifdef CONFIG_IPW_DEBUG 1773#ifdef CONFIG_IPW2200_DEBUG
1774 if (ipw_debug_level & IPW_DL_FW_ERRORS) 1774 if (ipw_debug_level & IPW_DL_FW_ERRORS)
1775 ipw_dump_error_log(priv, priv->error); 1775 ipw_dump_error_log(priv, priv->error);
1776#endif 1776#endif
@@ -3778,7 +3778,7 @@ static const struct ipw_status_code ipw_status_codes[] = {
3778 {0x2E, "Cipher suite is rejected per security policy"}, 3778 {0x2E, "Cipher suite is rejected per security policy"},
3779}; 3779};
3780 3780
3781#ifdef CONFIG_IPW_DEBUG 3781#ifdef CONFIG_IPW2200_DEBUG
3782static const char *ipw_get_status_code(u16 status) 3782static const char *ipw_get_status_code(u16 status)
3783{ 3783{
3784 int i; 3784 int i;
@@ -4250,7 +4250,7 @@ static inline void ipw_rx_notification(struct ipw_priv *priv,
4250 if (priv-> 4250 if (priv->
4251 status & (STATUS_ASSOCIATED | 4251 status & (STATUS_ASSOCIATED |
4252 STATUS_AUTH)) { 4252 STATUS_AUTH)) {
4253#ifdef CONFIG_IPW_DEBUG 4253#ifdef CONFIG_IPW2200_DEBUG
4254 struct notif_authenticate *auth 4254 struct notif_authenticate *auth
4255 = &notif->u.auth; 4255 = &notif->u.auth;
4256 IPW_DEBUG(IPW_DL_NOTIF | 4256 IPW_DEBUG(IPW_DL_NOTIF |
@@ -4944,12 +4944,11 @@ static struct ipw_rx_queue *ipw_rx_queue_alloc(struct ipw_priv *priv)
4944 struct ipw_rx_queue *rxq; 4944 struct ipw_rx_queue *rxq;
4945 int i; 4945 int i;
4946 4946
4947 rxq = (struct ipw_rx_queue *)kmalloc(sizeof(*rxq), GFP_KERNEL); 4947 rxq = kzalloc(sizeof(*rxq), GFP_KERNEL);
4948 if (unlikely(!rxq)) { 4948 if (unlikely(!rxq)) {
4949 IPW_ERROR("memory allocation failed\n"); 4949 IPW_ERROR("memory allocation failed\n");
4950 return NULL; 4950 return NULL;
4951 } 4951 }
4952 memset(rxq, 0, sizeof(*rxq));
4953 spin_lock_init(&rxq->lock); 4952 spin_lock_init(&rxq->lock);
4954 INIT_LIST_HEAD(&rxq->rx_free); 4953 INIT_LIST_HEAD(&rxq->rx_free);
4955 INIT_LIST_HEAD(&rxq->rx_used); 4954 INIT_LIST_HEAD(&rxq->rx_used);
@@ -5828,7 +5827,7 @@ static void ipw_bg_adhoc_check(void *data)
5828 up(&priv->sem); 5827 up(&priv->sem);
5829} 5828}
5830 5829
5831#ifdef CONFIG_IPW_DEBUG 5830#ifdef CONFIG_IPW2200_DEBUG
5832static void ipw_debug_config(struct ipw_priv *priv) 5831static void ipw_debug_config(struct ipw_priv *priv)
5833{ 5832{
5834 IPW_DEBUG_INFO("Scan completed, no valid APs matched " 5833 IPW_DEBUG_INFO("Scan completed, no valid APs matched "
@@ -7456,8 +7455,7 @@ static void ipw_handle_data_packet(struct ipw_priv *priv,
7456 /* HW decrypt will not clear the WEP bit, MIC, PN, etc. */ 7455 /* HW decrypt will not clear the WEP bit, MIC, PN, etc. */
7457 hdr = (struct ieee80211_hdr_4addr *)rxb->skb->data; 7456 hdr = (struct ieee80211_hdr_4addr *)rxb->skb->data;
7458 if (priv->ieee->iw_mode != IW_MODE_MONITOR && 7457 if (priv->ieee->iw_mode != IW_MODE_MONITOR &&
7459 ((is_multicast_ether_addr(hdr->addr1) || 7458 (is_multicast_ether_addr(hdr->addr1) ?
7460 is_broadcast_ether_addr(hdr->addr1)) ?
7461 !priv->ieee->host_mc_decrypt : !priv->ieee->host_decrypt)) 7459 !priv->ieee->host_mc_decrypt : !priv->ieee->host_decrypt))
7462 ipw_rebuild_decrypted_skb(priv, rxb->skb); 7460 ipw_rebuild_decrypted_skb(priv, rxb->skb);
7463 7461
@@ -7648,8 +7646,7 @@ static inline int is_network_packet(struct ipw_priv *priv,
7648 return 0; 7646 return 0;
7649 7647
7650 /* {broad,multi}cast packets to our BSSID go through */ 7648 /* {broad,multi}cast packets to our BSSID go through */
7651 if (is_multicast_ether_addr(header->addr1) || 7649 if (is_multicast_ether_addr(header->addr1))
7652 is_broadcast_ether_addr(header->addr1))
7653 return !memcmp(header->addr3, priv->bssid, ETH_ALEN); 7650 return !memcmp(header->addr3, priv->bssid, ETH_ALEN);
7654 7651
7655 /* packets to our adapter go through */ 7652 /* packets to our adapter go through */
@@ -7662,8 +7659,7 @@ static inline int is_network_packet(struct ipw_priv *priv,
7662 return 0; 7659 return 0;
7663 7660
7664 /* {broad,multi}cast packets to our BSS go through */ 7661 /* {broad,multi}cast packets to our BSS go through */
7665 if (is_multicast_ether_addr(header->addr1) || 7662 if (is_multicast_ether_addr(header->addr1))
7666 is_broadcast_ether_addr(header->addr1))
7667 return !memcmp(header->addr2, priv->bssid, ETH_ALEN); 7663 return !memcmp(header->addr2, priv->bssid, ETH_ALEN);
7668 7664
7669 /* packets to our adapter go through */ 7665 /* packets to our adapter go through */
@@ -7815,7 +7811,7 @@ static void ipw_rx(struct ipw_priv *priv)
7815 7811
7816 while (i != r) { 7812 while (i != r) {
7817 rxb = priv->rxq->queue[i]; 7813 rxb = priv->rxq->queue[i];
7818#ifdef CONFIG_IPW_DEBUG 7814#ifdef CONFIG_IPW2200_DEBUG
7819 if (unlikely(rxb == NULL)) { 7815 if (unlikely(rxb == NULL)) {
7820 printk(KERN_CRIT "Queue not allocated!\n"); 7816 printk(KERN_CRIT "Queue not allocated!\n");
7821 break; 7817 break;
@@ -9657,8 +9653,7 @@ static inline int ipw_tx_skb(struct ipw_priv *priv, struct ieee80211_txb *txb,
9657 switch (priv->ieee->iw_mode) { 9653 switch (priv->ieee->iw_mode) {
9658 case IW_MODE_ADHOC: 9654 case IW_MODE_ADHOC:
9659 hdr_len = IEEE80211_3ADDR_LEN; 9655 hdr_len = IEEE80211_3ADDR_LEN;
9660 unicast = !(is_multicast_ether_addr(hdr->addr1) || 9656 unicast = !is_multicast_ether_addr(hdr->addr1);
9661 is_broadcast_ether_addr(hdr->addr1));
9662 id = ipw_find_station(priv, hdr->addr1); 9657 id = ipw_find_station(priv, hdr->addr1);
9663 if (id == IPW_INVALID_STATION) { 9658 if (id == IPW_INVALID_STATION) {
9664 id = ipw_add_station(priv, hdr->addr1); 9659 id = ipw_add_station(priv, hdr->addr1);
@@ -9673,8 +9668,7 @@ static inline int ipw_tx_skb(struct ipw_priv *priv, struct ieee80211_txb *txb,
9673 9668
9674 case IW_MODE_INFRA: 9669 case IW_MODE_INFRA:
9675 default: 9670 default:
9676 unicast = !(is_multicast_ether_addr(hdr->addr3) || 9671 unicast = !is_multicast_ether_addr(hdr->addr3);
9677 is_broadcast_ether_addr(hdr->addr3));
9678 hdr_len = IEEE80211_3ADDR_LEN; 9672 hdr_len = IEEE80211_3ADDR_LEN;
9679 id = 0; 9673 id = 0;
9680 break; 9674 break;
@@ -10956,7 +10950,7 @@ static int ipw_pci_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
10956 10950
10957 priv->net_dev = net_dev; 10951 priv->net_dev = net_dev;
10958 priv->pci_dev = pdev; 10952 priv->pci_dev = pdev;
10959#ifdef CONFIG_IPW_DEBUG 10953#ifdef CONFIG_IPW2200_DEBUG
10960 ipw_debug_level = debug; 10954 ipw_debug_level = debug;
10961#endif 10955#endif
10962 spin_lock_init(&priv->lock); 10956 spin_lock_init(&priv->lock);
diff --git a/drivers/net/wireless/ipw2200.h b/drivers/net/wireless/ipw2200.h
index 1c98db0652c9..e65620a4d79e 100644
--- a/drivers/net/wireless/ipw2200.h
+++ b/drivers/net/wireless/ipw2200.h
@@ -1301,14 +1301,14 @@ struct ipw_priv {
1301 1301
1302/* debug macros */ 1302/* debug macros */
1303 1303
1304#ifdef CONFIG_IPW_DEBUG 1304#ifdef CONFIG_IPW2200_DEBUG
1305#define IPW_DEBUG(level, fmt, args...) \ 1305#define IPW_DEBUG(level, fmt, args...) \
1306do { if (ipw_debug_level & (level)) \ 1306do { if (ipw_debug_level & (level)) \
1307 printk(KERN_DEBUG DRV_NAME": %c %s " fmt, \ 1307 printk(KERN_DEBUG DRV_NAME": %c %s " fmt, \
1308 in_interrupt() ? 'I' : 'U', __FUNCTION__ , ## args); } while (0) 1308 in_interrupt() ? 'I' : 'U', __FUNCTION__ , ## args); } while (0)
1309#else 1309#else
1310#define IPW_DEBUG(level, fmt, args...) do {} while (0) 1310#define IPW_DEBUG(level, fmt, args...) do {} while (0)
1311#endif /* CONFIG_IPW_DEBUG */ 1311#endif /* CONFIG_IPW2200_DEBUG */
1312 1312
1313/* 1313/*
1314 * To use the debug system; 1314 * To use the debug system;
@@ -1332,7 +1332,7 @@ do { if (ipw_debug_level & (level)) \
1332 * you simply need to add your entry to the ipw_debug_levels array. 1332 * you simply need to add your entry to the ipw_debug_levels array.
1333 * 1333 *
1334 * If you do not see debug_level in /proc/net/ipw then you do not have 1334 * If you do not see debug_level in /proc/net/ipw then you do not have
1335 * CONFIG_IPW_DEBUG defined in your kernel configuration 1335 * CONFIG_IPW2200_DEBUG defined in your kernel configuration
1336 * 1336 *
1337 */ 1337 */
1338 1338
diff --git a/drivers/net/wireless/netwave_cs.c b/drivers/net/wireless/netwave_cs.c
index 92793b958e32..bf6271ee387a 100644
--- a/drivers/net/wireless/netwave_cs.c
+++ b/drivers/net/wireless/netwave_cs.c
@@ -166,8 +166,6 @@ static char *version =
166#define DEBUG(n, args...) 166#define DEBUG(n, args...)
167#endif 167#endif
168 168
169static dev_info_t dev_info = "netwave_cs";
170
171/*====================================================================*/ 169/*====================================================================*/
172 170
173/* Parameters that can be set with 'insmod' */ 171/* Parameters that can be set with 'insmod' */
@@ -195,12 +193,9 @@ module_param(mem_speed, int, 0);
195 193
196/* PCMCIA (Card Services) related functions */ 194/* PCMCIA (Card Services) related functions */
197static void netwave_release(dev_link_t *link); /* Card removal */ 195static void netwave_release(dev_link_t *link); /* Card removal */
198static int netwave_event(event_t event, int priority,
199 event_callback_args_t *args);
200static void netwave_pcmcia_config(dev_link_t *arg); /* Runs after card 196static void netwave_pcmcia_config(dev_link_t *arg); /* Runs after card
201 insertion */ 197 insertion */
202static dev_link_t *netwave_attach(void); /* Create instance */ 198static void netwave_detach(struct pcmcia_device *p_dev); /* Destroy instance */
203static void netwave_detach(dev_link_t *); /* Destroy instance */
204 199
205/* Hardware configuration */ 200/* Hardware configuration */
206static void netwave_doreset(kio_addr_t iobase, u_char __iomem *ramBase); 201static void netwave_doreset(kio_addr_t iobase, u_char __iomem *ramBase);
@@ -228,17 +223,6 @@ static struct iw_statistics* netwave_get_wireless_stats(struct net_device *dev);
228static void set_multicast_list(struct net_device *dev); 223static void set_multicast_list(struct net_device *dev);
229 224
230/* 225/*
231 A linked list of "instances" of the skeleton device. Each actual
232 PCMCIA card corresponds to one device instance, and is described
233 by one dev_link_t structure (defined in ds.h).
234
235 You may not want to use a linked list for this -- for example, the
236 memory card driver uses an array of dev_link_t pointers, where minor
237 device numbers are used to derive the corresponding array index.
238*/
239static dev_link_t *dev_list;
240
241/*
242 A dev_link_t structure has fields for most things that are needed 226 A dev_link_t structure has fields for most things that are needed
243 to keep track of a socket, but there will usually be some device 227 to keep track of a socket, but there will usually be some device
244 specific information that also needs to be kept track of. The 228 specific information that also needs to be kept track of. The
@@ -394,20 +378,18 @@ static struct iw_statistics *netwave_get_wireless_stats(struct net_device *dev)
394 * configure the card at this point -- we wait until we receive a 378 * configure the card at this point -- we wait until we receive a
395 * card insertion event. 379 * card insertion event.
396 */ 380 */
397static dev_link_t *netwave_attach(void) 381static int netwave_attach(struct pcmcia_device *p_dev)
398{ 382{
399 client_reg_t client_reg;
400 dev_link_t *link; 383 dev_link_t *link;
401 struct net_device *dev; 384 struct net_device *dev;
402 netwave_private *priv; 385 netwave_private *priv;
403 int ret; 386
404
405 DEBUG(0, "netwave_attach()\n"); 387 DEBUG(0, "netwave_attach()\n");
406 388
407 /* Initialize the dev_link_t structure */ 389 /* Initialize the dev_link_t structure */
408 dev = alloc_etherdev(sizeof(netwave_private)); 390 dev = alloc_etherdev(sizeof(netwave_private));
409 if (!dev) 391 if (!dev)
410 return NULL; 392 return -ENOMEM;
411 priv = netdev_priv(dev); 393 priv = netdev_priv(dev);
412 link = &priv->link; 394 link = &priv->link;
413 link->priv = dev; 395 link->priv = dev;
@@ -449,21 +431,14 @@ static dev_link_t *netwave_attach(void)
449 dev->open = &netwave_open; 431 dev->open = &netwave_open;
450 dev->stop = &netwave_close; 432 dev->stop = &netwave_close;
451 link->irq.Instance = dev; 433 link->irq.Instance = dev;
452
453 /* Register with Card Services */
454 link->next = dev_list;
455 dev_list = link;
456 client_reg.dev_info = &dev_info;
457 client_reg.Version = 0x0210;
458 client_reg.event_callback_args.client_data = link;
459 ret = pcmcia_register_client(&link->handle, &client_reg);
460 if (ret != 0) {
461 cs_error(link->handle, RegisterClient, ret);
462 netwave_detach(link);
463 return NULL;
464 }
465 434
466 return link; 435 link->handle = p_dev;
436 p_dev->instance = link;
437
438 link->state |= DEV_PRESENT | DEV_CONFIG_PENDING;
439 netwave_pcmcia_config( link);
440
441 return 0;
467} /* netwave_attach */ 442} /* netwave_attach */
468 443
469/* 444/*
@@ -474,42 +449,20 @@ static dev_link_t *netwave_attach(void)
474 * structures are freed. Otherwise, the structures will be freed 449 * structures are freed. Otherwise, the structures will be freed
475 * when the device is released. 450 * when the device is released.
476 */ 451 */
477static void netwave_detach(dev_link_t *link) 452static void netwave_detach(struct pcmcia_device *p_dev)
478{ 453{
479 struct net_device *dev = link->priv; 454 dev_link_t *link = dev_to_instance(p_dev);
480 dev_link_t **linkp; 455 struct net_device *dev = link->priv;
481 456
482 DEBUG(0, "netwave_detach(0x%p)\n", link); 457 DEBUG(0, "netwave_detach(0x%p)\n", link);
483 458
484 /* 459 if (link->state & DEV_CONFIG)
485 If the device is currently configured and active, we won't 460 netwave_release(link);
486 actually delete it yet. Instead, it is marked so that when 461
487 the release() function is called, that will trigger a proper 462 if (link->dev)
488 detach(). 463 unregister_netdev(dev);
489 */ 464
490 if (link->state & DEV_CONFIG) 465 free_netdev(dev);
491 netwave_release(link);
492
493 /* Break the link with Card Services */
494 if (link->handle)
495 pcmcia_deregister_client(link->handle);
496
497 /* Locate device structure */
498 for (linkp = &dev_list; *linkp; linkp = &(*linkp)->next)
499 if (*linkp == link) break;
500 if (*linkp == NULL)
501 {
502 DEBUG(1, "netwave_cs: detach fail, '%s' not in list\n",
503 link->dev->dev_name);
504 return;
505 }
506
507 /* Unlink device structure, free pieces */
508 *linkp = link->next;
509 if (link->dev)
510 unregister_netdev(dev);
511 free_netdev(dev);
512
513} /* netwave_detach */ 466} /* netwave_detach */
514 467
515/* 468/*
@@ -935,69 +888,38 @@ static void netwave_release(dev_link_t *link)
935 link->state &= ~DEV_CONFIG; 888 link->state &= ~DEV_CONFIG;
936} 889}
937 890
938/* 891static int netwave_suspend(struct pcmcia_device *p_dev)
939 * Function netwave_event (event, priority, args)
940 *
941 * The card status event handler. Mostly, this schedules other
942 * stuff to run after an event is received. A CARD_REMOVAL event
943 * also sets some flags to discourage the net drivers from trying
944 * to talk to the card any more.
945 *
946 * When a CARD_REMOVAL event is received, we immediately set a flag
947 * to block future accesses to this device. All the functions that
948 * actually access the device should check this flag to make sure
949 * the card is still present.
950 *
951 */
952static int netwave_event(event_t event, int priority,
953 event_callback_args_t *args)
954{ 892{
955 dev_link_t *link = args->client_data; 893 dev_link_t *link = dev_to_instance(p_dev);
956 struct net_device *dev = link->priv; 894 struct net_device *dev = link->priv;
957 895
958 DEBUG(1, "netwave_event(0x%06x)\n", event);
959
960 switch (event) {
961 case CS_EVENT_REGISTRATION_COMPLETE:
962 DEBUG(0, "netwave_cs: registration complete\n");
963 break;
964
965 case CS_EVENT_CARD_REMOVAL:
966 link->state &= ~DEV_PRESENT;
967 if (link->state & DEV_CONFIG) {
968 netif_device_detach(dev);
969 netwave_release(link);
970 }
971 break;
972 case CS_EVENT_CARD_INSERTION:
973 link->state |= DEV_PRESENT | DEV_CONFIG_PENDING;
974 netwave_pcmcia_config( link);
975 break;
976 case CS_EVENT_PM_SUSPEND:
977 link->state |= DEV_SUSPEND; 896 link->state |= DEV_SUSPEND;
978 /* Fall through... */
979 case CS_EVENT_RESET_PHYSICAL:
980 if (link->state & DEV_CONFIG) { 897 if (link->state & DEV_CONFIG) {
981 if (link->open) 898 if (link->open)
982 netif_device_detach(dev); 899 netif_device_detach(dev);
983 pcmcia_release_configuration(link->handle); 900 pcmcia_release_configuration(link->handle);
984 } 901 }
985 break; 902
986 case CS_EVENT_PM_RESUME: 903 return 0;
904}
905
906static int netwave_resume(struct pcmcia_device *p_dev)
907{
908 dev_link_t *link = dev_to_instance(p_dev);
909 struct net_device *dev = link->priv;
910
987 link->state &= ~DEV_SUSPEND; 911 link->state &= ~DEV_SUSPEND;
988 /* Fall through... */
989 case CS_EVENT_CARD_RESET:
990 if (link->state & DEV_CONFIG) { 912 if (link->state & DEV_CONFIG) {
991 pcmcia_request_configuration(link->handle, &link->conf); 913 pcmcia_request_configuration(link->handle, &link->conf);
992 if (link->open) { 914 if (link->open) {
993 netwave_reset(dev); 915 netwave_reset(dev);
994 netif_device_attach(dev); 916 netif_device_attach(dev);
995 } 917 }
996 } 918 }
997 break; 919
998 } 920 return 0;
999 return 0; 921}
1000} /* netwave_event */ 922
1001 923
1002/* 924/*
1003 * Function netwave_doreset (ioBase, ramBase) 925 * Function netwave_doreset (ioBase, ramBase)
@@ -1491,10 +1413,11 @@ static struct pcmcia_driver netwave_driver = {
1491 .drv = { 1413 .drv = {
1492 .name = "netwave_cs", 1414 .name = "netwave_cs",
1493 }, 1415 },
1494 .attach = netwave_attach, 1416 .probe = netwave_attach,
1495 .event = netwave_event, 1417 .remove = netwave_detach,
1496 .detach = netwave_detach,
1497 .id_table = netwave_ids, 1418 .id_table = netwave_ids,
1419 .suspend = netwave_suspend,
1420 .resume = netwave_resume,
1498}; 1421};
1499 1422
1500static int __init init_netwave_cs(void) 1423static int __init init_netwave_cs(void)
@@ -1505,7 +1428,6 @@ static int __init init_netwave_cs(void)
1505static void __exit exit_netwave_cs(void) 1428static void __exit exit_netwave_cs(void)
1506{ 1429{
1507 pcmcia_unregister_driver(&netwave_driver); 1430 pcmcia_unregister_driver(&netwave_driver);
1508 BUG_ON(dev_list != NULL);
1509} 1431}
1510 1432
1511module_init(init_netwave_cs); 1433module_init(init_netwave_cs);
diff --git a/drivers/net/wireless/orinoco_cs.c b/drivers/net/wireless/orinoco_cs.c
index dc1128a00971..b664708481cc 100644
--- a/drivers/net/wireless/orinoco_cs.c
+++ b/drivers/net/wireless/orinoco_cs.c
@@ -43,17 +43,6 @@ module_param(ignore_cis_vcc, int, 0);
43MODULE_PARM_DESC(ignore_cis_vcc, "Allow voltage mismatch between card and socket"); 43MODULE_PARM_DESC(ignore_cis_vcc, "Allow voltage mismatch between card and socket");
44 44
45/********************************************************************/ 45/********************************************************************/
46/* Magic constants */
47/********************************************************************/
48
49/*
50 * The dev_info variable is the "key" that is used to match up this
51 * device driver with appropriate cards, through the card
52 * configuration database.
53 */
54static dev_info_t dev_info = DRIVER_NAME;
55
56/********************************************************************/
57/* Data structures */ 46/* Data structures */
58/********************************************************************/ 47/********************************************************************/
59 48
@@ -69,19 +58,14 @@ struct orinoco_pccard {
69 unsigned long hard_reset_in_progress; 58 unsigned long hard_reset_in_progress;
70}; 59};
71 60
72/*
73 * A linked list of "instances" of the device. Each actual PCMCIA
74 * card corresponds to one device instance, and is described by one
75 * dev_link_t structure (defined in ds.h).
76 */
77static dev_link_t *dev_list; /* = NULL */
78 61
79/********************************************************************/ 62/********************************************************************/
80/* Function prototypes */ 63/* Function prototypes */
81/********************************************************************/ 64/********************************************************************/
82 65
66static void orinoco_cs_config(dev_link_t *link);
83static void orinoco_cs_release(dev_link_t *link); 67static void orinoco_cs_release(dev_link_t *link);
84static void orinoco_cs_detach(dev_link_t *link); 68static void orinoco_cs_detach(struct pcmcia_device *p_dev);
85 69
86/********************************************************************/ 70/********************************************************************/
87/* Device methods */ 71/* Device methods */
@@ -119,19 +103,17 @@ orinoco_cs_hard_reset(struct orinoco_private *priv)
119 * The dev_link structure is initialized, but we don't actually 103 * The dev_link structure is initialized, but we don't actually
120 * configure the card at this point -- we wait until we receive a card 104 * configure the card at this point -- we wait until we receive a card
121 * insertion event. */ 105 * insertion event. */
122static dev_link_t * 106static int
123orinoco_cs_attach(void) 107orinoco_cs_attach(struct pcmcia_device *p_dev)
124{ 108{
125 struct net_device *dev; 109 struct net_device *dev;
126 struct orinoco_private *priv; 110 struct orinoco_private *priv;
127 struct orinoco_pccard *card; 111 struct orinoco_pccard *card;
128 dev_link_t *link; 112 dev_link_t *link;
129 client_reg_t client_reg;
130 int ret;
131 113
132 dev = alloc_orinocodev(sizeof(*card), orinoco_cs_hard_reset); 114 dev = alloc_orinocodev(sizeof(*card), orinoco_cs_hard_reset);
133 if (! dev) 115 if (! dev)
134 return NULL; 116 return -ENOMEM;
135 priv = netdev_priv(dev); 117 priv = netdev_priv(dev);
136 card = priv->card; 118 card = priv->card;
137 119
@@ -154,22 +136,15 @@ orinoco_cs_attach(void)
154 link->conf.IntType = INT_MEMORY_AND_IO; 136 link->conf.IntType = INT_MEMORY_AND_IO;
155 137
156 /* Register with Card Services */ 138 /* Register with Card Services */
157 /* FIXME: need a lock? */ 139 link->next = NULL;
158 link->next = dev_list; 140
159 dev_list = link; 141 link->handle = p_dev;
160 142 p_dev->instance = link;
161 client_reg.dev_info = &dev_info; 143
162 client_reg.Version = 0x0210; /* FIXME: what does this mean? */ 144 link->state |= DEV_PRESENT | DEV_CONFIG_PENDING;
163 client_reg.event_callback_args.client_data = link; 145 orinoco_cs_config(link);
164
165 ret = pcmcia_register_client(&link->handle, &client_reg);
166 if (ret != CS_SUCCESS) {
167 cs_error(link->handle, RegisterClient, ret);
168 orinoco_cs_detach(link);
169 return NULL;
170 }
171 146
172 return link; 147 return 0;
173} /* orinoco_cs_attach */ 148} /* orinoco_cs_attach */
174 149
175/* 150/*
@@ -178,27 +153,14 @@ orinoco_cs_attach(void)
178 * are freed. Otherwise, the structures will be freed when the device 153 * are freed. Otherwise, the structures will be freed when the device
179 * is released. 154 * is released.
180 */ 155 */
181static void orinoco_cs_detach(dev_link_t *link) 156static void orinoco_cs_detach(struct pcmcia_device *p_dev)
182{ 157{
183 dev_link_t **linkp; 158 dev_link_t *link = dev_to_instance(p_dev);
184 struct net_device *dev = link->priv; 159 struct net_device *dev = link->priv;
185 160
186 /* Locate device structure */
187 for (linkp = &dev_list; *linkp; linkp = &(*linkp)->next)
188 if (*linkp == link)
189 break;
190
191 BUG_ON(*linkp == NULL);
192
193 if (link->state & DEV_CONFIG) 161 if (link->state & DEV_CONFIG)
194 orinoco_cs_release(link); 162 orinoco_cs_release(link);
195 163
196 /* Break the link with Card Services */
197 if (link->handle)
198 pcmcia_deregister_client(link->handle);
199
200 /* Unlink device structure, and free it */
201 *linkp = link->next;
202 DEBUG(0, PFX "detach: link=%p link->dev=%p\n", link, link->dev); 164 DEBUG(0, PFX "detach: link=%p link->dev=%p\n", link, link->dev);
203 if (link->dev) { 165 if (link->dev) {
204 DEBUG(0, PFX "About to unregister net device %p\n", 166 DEBUG(0, PFX "About to unregister net device %p\n",
@@ -465,106 +427,82 @@ orinoco_cs_release(dev_link_t *link)
465 ioport_unmap(priv->hw.iobase); 427 ioport_unmap(priv->hw.iobase);
466} /* orinoco_cs_release */ 428} /* orinoco_cs_release */
467 429
468/* 430static int orinoco_cs_suspend(struct pcmcia_device *p_dev)
469 * The card status event handler. Mostly, this schedules other stuff
470 * to run after an event is received.
471 */
472static int
473orinoco_cs_event(event_t event, int priority,
474 event_callback_args_t * args)
475{ 431{
476 dev_link_t *link = args->client_data; 432 dev_link_t *link = dev_to_instance(p_dev);
477 struct net_device *dev = link->priv; 433 struct net_device *dev = link->priv;
478 struct orinoco_private *priv = netdev_priv(dev); 434 struct orinoco_private *priv = netdev_priv(dev);
479 struct orinoco_pccard *card = priv->card; 435 struct orinoco_pccard *card = priv->card;
480 int err = 0; 436 int err = 0;
481 unsigned long flags; 437 unsigned long flags;
482 438
483 switch (event) { 439 link->state |= DEV_SUSPEND;
484 case CS_EVENT_CARD_REMOVAL: 440 if (link->state & DEV_CONFIG) {
485 link->state &= ~DEV_PRESENT; 441 /* This is probably racy, but I can't think of
486 if (link->state & DEV_CONFIG) { 442 a better way, short of rewriting the PCMCIA
487 unsigned long flags; 443 layer to not suck :-( */
488 444 if (! test_bit(0, &card->hard_reset_in_progress)) {
489 spin_lock_irqsave(&priv->lock, flags); 445 spin_lock_irqsave(&priv->lock, flags);
446
447 err = __orinoco_down(dev);
448 if (err)
449 printk(KERN_WARNING "%s: Error %d downing interface\n",
450 dev->name, err);
451
490 netif_device_detach(dev); 452 netif_device_detach(dev);
491 priv->hw_unavailable++; 453 priv->hw_unavailable++;
454
492 spin_unlock_irqrestore(&priv->lock, flags); 455 spin_unlock_irqrestore(&priv->lock, flags);
493 } 456 }
494 break;
495 457
496 case CS_EVENT_CARD_INSERTION: 458 pcmcia_release_configuration(link->handle);
497 link->state |= DEV_PRESENT | DEV_CONFIG_PENDING; 459 }
498 orinoco_cs_config(link);
499 break;
500 460
501 case CS_EVENT_PM_SUSPEND: 461 return 0;
502 link->state |= DEV_SUSPEND; 462}
503 /* Fall through... */ 463
504 case CS_EVENT_RESET_PHYSICAL: 464static int orinoco_cs_resume(struct pcmcia_device *p_dev)
505 /* Mark the device as stopped, to block IO until later */ 465{
506 if (link->state & DEV_CONFIG) { 466 dev_link_t *link = dev_to_instance(p_dev);
507 /* This is probably racy, but I can't think of 467 struct net_device *dev = link->priv;
508 a better way, short of rewriting the PCMCIA 468 struct orinoco_private *priv = netdev_priv(dev);
509 layer to not suck :-( */ 469 struct orinoco_pccard *card = priv->card;
510 if (! test_bit(0, &card->hard_reset_in_progress)) { 470 int err = 0;
511 spin_lock_irqsave(&priv->lock, flags); 471 unsigned long flags;
512 472
513 err = __orinoco_down(dev); 473 link->state &= ~DEV_SUSPEND;
514 if (err) 474 if (link->state & DEV_CONFIG) {
515 printk(KERN_WARNING "%s: %s: Error %d downing interface\n", 475 /* FIXME: should we double check that this is
516 dev->name, 476 * the same card as we had before */
517 event == CS_EVENT_PM_SUSPEND ? "SUSPEND" : "RESET_PHYSICAL", 477 pcmcia_request_configuration(link->handle, &link->conf);
518 err); 478
519 479 if (! test_bit(0, &card->hard_reset_in_progress)) {
520 netif_device_detach(dev); 480 err = orinoco_reinit_firmware(dev);
521 priv->hw_unavailable++; 481 if (err) {
522 482 printk(KERN_ERR "%s: Error %d re-initializing firmware\n",
523 spin_unlock_irqrestore(&priv->lock, flags); 483 dev->name, err);
484 return -EIO;
524 } 485 }
525 486
526 pcmcia_release_configuration(link->handle); 487 spin_lock_irqsave(&priv->lock, flags);
527 } 488
528 break; 489 netif_device_attach(dev);
490 priv->hw_unavailable--;
529 491
530 case CS_EVENT_PM_RESUME: 492 if (priv->open && ! priv->hw_unavailable) {
531 link->state &= ~DEV_SUSPEND; 493 err = __orinoco_up(dev);
532 /* Fall through... */ 494 if (err)
533 case CS_EVENT_CARD_RESET: 495 printk(KERN_ERR "%s: Error %d restarting card\n",
534 if (link->state & DEV_CONFIG) {
535 /* FIXME: should we double check that this is
536 * the same card as we had before */
537 pcmcia_request_configuration(link->handle, &link->conf);
538
539 if (! test_bit(0, &card->hard_reset_in_progress)) {
540 err = orinoco_reinit_firmware(dev);
541 if (err) {
542 printk(KERN_ERR "%s: Error %d re-initializing firmware\n",
543 dev->name, err); 496 dev->name, err);
544 break;
545 }
546
547 spin_lock_irqsave(&priv->lock, flags);
548
549 netif_device_attach(dev);
550 priv->hw_unavailable--;
551
552 if (priv->open && ! priv->hw_unavailable) {
553 err = __orinoco_up(dev);
554 if (err)
555 printk(KERN_ERR "%s: Error %d restarting card\n",
556 dev->name, err);
557
558 }
559
560 spin_unlock_irqrestore(&priv->lock, flags);
561 } 497 }
498
499 spin_unlock_irqrestore(&priv->lock, flags);
562 } 500 }
563 break;
564 } 501 }
565 502
566 return err; 503 return 0;
567} /* orinoco_cs_event */ 504}
505
568 506
569/********************************************************************/ 507/********************************************************************/
570/* Module initialization */ 508/* Module initialization */
@@ -665,10 +603,11 @@ static struct pcmcia_driver orinoco_driver = {
665 .drv = { 603 .drv = {
666 .name = DRIVER_NAME, 604 .name = DRIVER_NAME,
667 }, 605 },
668 .attach = orinoco_cs_attach, 606 .probe = orinoco_cs_attach,
669 .detach = orinoco_cs_detach, 607 .remove = orinoco_cs_detach,
670 .event = orinoco_cs_event,
671 .id_table = orinoco_cs_ids, 608 .id_table = orinoco_cs_ids,
609 .suspend = orinoco_cs_suspend,
610 .resume = orinoco_cs_resume,
672}; 611};
673 612
674static int __init 613static int __init
@@ -683,7 +622,6 @@ static void __exit
683exit_orinoco_cs(void) 622exit_orinoco_cs(void)
684{ 623{
685 pcmcia_unregister_driver(&orinoco_driver); 624 pcmcia_unregister_driver(&orinoco_driver);
686 BUG_ON(dev_list != NULL);
687} 625}
688 626
689module_init(init_orinoco_cs); 627module_init(init_orinoco_cs);
diff --git a/drivers/net/wireless/ray_cs.c b/drivers/net/wireless/ray_cs.c
index 70fd6fd8feb9..319180ca7e71 100644
--- a/drivers/net/wireless/ray_cs.c
+++ b/drivers/net/wireless/ray_cs.c
@@ -92,9 +92,7 @@ module_param(pc_debug, int, 0);
92/** Prototypes based on PCMCIA skeleton driver *******************************/ 92/** Prototypes based on PCMCIA skeleton driver *******************************/
93static void ray_config(dev_link_t *link); 93static void ray_config(dev_link_t *link);
94static void ray_release(dev_link_t *link); 94static void ray_release(dev_link_t *link);
95static int ray_event(event_t event, int priority, event_callback_args_t *args); 95static void ray_detach(struct pcmcia_device *p_dev);
96static dev_link_t *ray_attach(void);
97static void ray_detach(dev_link_t *);
98 96
99/***** Prototypes indicated by device structure ******************************/ 97/***** Prototypes indicated by device structure ******************************/
100static int ray_dev_close(struct net_device *dev); 98static int ray_dev_close(struct net_device *dev);
@@ -192,12 +190,6 @@ static int bc;
192static char *phy_addr = NULL; 190static char *phy_addr = NULL;
193 191
194 192
195/* The dev_info variable is the "key" that is used to match up this
196 device driver with appropriate cards, through the card configuration
197 database.
198*/
199static dev_info_t dev_info = "ray_cs";
200
201/* A linked list of "instances" of the ray device. Each actual 193/* A linked list of "instances" of the ray device. Each actual
202 PCMCIA card corresponds to one device instance, and is described 194 PCMCIA card corresponds to one device instance, and is described
203 by one dev_link_t structure (defined in ds.h). 195 by one dev_link_t structure (defined in ds.h).
@@ -314,12 +306,10 @@ static char rcsid[] = "Raylink/WebGear wireless LAN - Corey <Thomas corey@world.
314 configure the card at this point -- we wait until we receive a 306 configure the card at this point -- we wait until we receive a
315 card insertion event. 307 card insertion event.
316=============================================================================*/ 308=============================================================================*/
317static dev_link_t *ray_attach(void) 309static int ray_attach(struct pcmcia_device *p_dev)
318{ 310{
319 client_reg_t client_reg;
320 dev_link_t *link; 311 dev_link_t *link;
321 ray_dev_t *local; 312 ray_dev_t *local;
322 int ret;
323 struct net_device *dev; 313 struct net_device *dev;
324 314
325 DEBUG(1, "ray_attach()\n"); 315 DEBUG(1, "ray_attach()\n");
@@ -328,7 +318,7 @@ static dev_link_t *ray_attach(void)
328 link = kmalloc(sizeof(struct dev_link_t), GFP_KERNEL); 318 link = kmalloc(sizeof(struct dev_link_t), GFP_KERNEL);
329 319
330 if (!link) 320 if (!link)
331 return NULL; 321 return -ENOMEM;
332 322
333 /* Allocate space for private device-specific data */ 323 /* Allocate space for private device-specific data */
334 dev = alloc_etherdev(sizeof(ray_dev_t)); 324 dev = alloc_etherdev(sizeof(ray_dev_t));
@@ -387,30 +377,19 @@ static dev_link_t *ray_attach(void)
387 dev->stop = &ray_dev_close; 377 dev->stop = &ray_dev_close;
388 netif_stop_queue(dev); 378 netif_stop_queue(dev);
389 379
390 /* Register with Card Services */ 380 init_timer(&local->timer);
391 link->next = dev_list;
392 dev_list = link;
393 client_reg.dev_info = &dev_info;
394 client_reg.Version = 0x0210;
395 client_reg.event_callback_args.client_data = link;
396 381
397 DEBUG(2,"ray_cs ray_attach calling pcmcia_register_client(...)\n"); 382 link->handle = p_dev;
383 p_dev->instance = link;
398 384
399 init_timer(&local->timer); 385 link->state |= DEV_PRESENT | DEV_CONFIG_PENDING;
386 ray_config(link);
400 387
401 ret = pcmcia_register_client(&link->handle, &client_reg); 388 return 0;
402 if (ret != 0) {
403 printk("ray_cs ray_attach RegisterClient unhappy - detaching\n");
404 cs_error(link->handle, RegisterClient, ret);
405 ray_detach(link);
406 return NULL;
407 }
408 DEBUG(2,"ray_cs ray_attach ending\n");
409 return link;
410 389
411fail_alloc_dev: 390fail_alloc_dev:
412 kfree(link); 391 kfree(link);
413 return NULL; 392 return -ENOMEM;
414} /* ray_attach */ 393} /* ray_attach */
415/*============================================================================= 394/*=============================================================================
416 This deletes a driver "instance". The device is de-registered 395 This deletes a driver "instance". The device is de-registered
@@ -418,9 +397,12 @@ fail_alloc_dev:
418 structures are freed. Otherwise, the structures will be freed 397 structures are freed. Otherwise, the structures will be freed
419 when the device is released. 398 when the device is released.
420=============================================================================*/ 399=============================================================================*/
421static void ray_detach(dev_link_t *link) 400static void ray_detach(struct pcmcia_device *p_dev)
422{ 401{
402 dev_link_t *link = dev_to_instance(p_dev);
423 dev_link_t **linkp; 403 dev_link_t **linkp;
404 struct net_device *dev;
405 ray_dev_t *local;
424 406
425 DEBUG(1, "ray_detach(0x%p)\n", link); 407 DEBUG(1, "ray_detach(0x%p)\n", link);
426 408
@@ -430,22 +412,18 @@ static void ray_detach(dev_link_t *link)
430 if (*linkp == NULL) 412 if (*linkp == NULL)
431 return; 413 return;
432 414
433 /* If the device is currently configured and active, we won't 415 dev = link->priv;
434 actually delete it yet. Instead, it is marked so that when 416
435 the release() function is called, that will trigger a proper 417 if (link->state & DEV_CONFIG) {
436 detach(). 418 ray_release(link);
437 */ 419
438 if (link->state & DEV_CONFIG) 420 local = (ray_dev_t *)dev->priv;
439 ray_release(link); 421 del_timer(&local->timer);
422 }
440 423
441 /* Break the link with Card Services */
442 if (link->handle)
443 pcmcia_deregister_client(link->handle);
444
445 /* Unlink device structure, free pieces */ 424 /* Unlink device structure, free pieces */
446 *linkp = link->next; 425 *linkp = link->next;
447 if (link->priv) { 426 if (link->priv) {
448 struct net_device *dev = link->priv;
449 if (link->dev) unregister_netdev(dev); 427 if (link->dev) unregister_netdev(dev);
450 free_netdev(dev); 428 free_netdev(dev);
451 } 429 }
@@ -891,65 +869,40 @@ static void ray_release(dev_link_t *link)
891 DEBUG(2,"ray_release ending\n"); 869 DEBUG(2,"ray_release ending\n");
892} 870}
893 871
894/*============================================================================= 872static int ray_suspend(struct pcmcia_device *p_dev)
895 The card status event handler. Mostly, this schedules other
896 stuff to run after an event is received. A CARD_REMOVAL event
897 also sets some flags to discourage the net drivers from trying
898 to talk to the card any more.
899
900 When a CARD_REMOVAL event is received, we immediately set a flag
901 to block future accesses to this device. All the functions that
902 actually access the device should check this flag to make sure
903 the card is still present.
904=============================================================================*/
905static int ray_event(event_t event, int priority,
906 event_callback_args_t *args)
907{ 873{
908 dev_link_t *link = args->client_data; 874 dev_link_t *link = dev_to_instance(p_dev);
909 struct net_device *dev = link->priv; 875 struct net_device *dev = link->priv;
910 ray_dev_t *local = (ray_dev_t *)dev->priv; 876
911 DEBUG(1, "ray_event(0x%06x)\n", event); 877 link->state |= DEV_SUSPEND;
912
913 switch (event) {
914 case CS_EVENT_CARD_REMOVAL:
915 link->state &= ~DEV_PRESENT;
916 netif_device_detach(dev);
917 if (link->state & DEV_CONFIG) {
918 ray_release(link);
919 del_timer(&local->timer);
920 }
921 break;
922 case CS_EVENT_CARD_INSERTION:
923 link->state |= DEV_PRESENT | DEV_CONFIG_PENDING;
924 ray_config(link);
925 break;
926 case CS_EVENT_PM_SUSPEND:
927 link->state |= DEV_SUSPEND;
928 /* Fall through... */
929 case CS_EVENT_RESET_PHYSICAL:
930 if (link->state & DEV_CONFIG) { 878 if (link->state & DEV_CONFIG) {
931 if (link->open) 879 if (link->open)
932 netif_device_detach(dev); 880 netif_device_detach(dev);
933 881
934 pcmcia_release_configuration(link->handle); 882 pcmcia_release_configuration(link->handle);
935 } 883 }
936 break; 884
937 case CS_EVENT_PM_RESUME: 885
938 link->state &= ~DEV_SUSPEND; 886 return 0;
939 /* Fall through... */ 887}
940 case CS_EVENT_CARD_RESET: 888
889static int ray_resume(struct pcmcia_device *p_dev)
890{
891 dev_link_t *link = dev_to_instance(p_dev);
892 struct net_device *dev = link->priv;
893
894 link->state &= ~DEV_SUSPEND;
941 if (link->state & DEV_CONFIG) { 895 if (link->state & DEV_CONFIG) {
942 pcmcia_request_configuration(link->handle, &link->conf); 896 pcmcia_request_configuration(link->handle, &link->conf);
943 if (link->open) { 897 if (link->open) {
944 ray_reset(dev); 898 ray_reset(dev);
945 netif_device_attach(dev); 899 netif_device_attach(dev);
946 } 900 }
947 } 901 }
948 break; 902
949 } 903 return 0;
950 return 0; 904}
951 DEBUG(2,"ray_event ending\n"); 905
952} /* ray_event */
953/*===========================================================================*/ 906/*===========================================================================*/
954int ray_dev_init(struct net_device *dev) 907int ray_dev_init(struct net_device *dev)
955{ 908{
@@ -2945,10 +2898,11 @@ static struct pcmcia_driver ray_driver = {
2945 .drv = { 2898 .drv = {
2946 .name = "ray_cs", 2899 .name = "ray_cs",
2947 }, 2900 },
2948 .attach = ray_attach, 2901 .probe = ray_attach,
2949 .event = ray_event, 2902 .remove = ray_detach,
2950 .detach = ray_detach,
2951 .id_table = ray_ids, 2903 .id_table = ray_ids,
2904 .suspend = ray_suspend,
2905 .resume = ray_resume,
2952}; 2906};
2953 2907
2954static int __init init_ray_cs(void) 2908static int __init init_ray_cs(void)
diff --git a/drivers/net/wireless/spectrum_cs.c b/drivers/net/wireless/spectrum_cs.c
index b1bbc8e8e91f..fee4be1ce810 100644
--- a/drivers/net/wireless/spectrum_cs.c
+++ b/drivers/net/wireless/spectrum_cs.c
@@ -57,17 +57,6 @@ module_param(ignore_cis_vcc, int, 0);
57MODULE_PARM_DESC(ignore_cis_vcc, "Allow voltage mismatch between card and socket"); 57MODULE_PARM_DESC(ignore_cis_vcc, "Allow voltage mismatch between card and socket");
58 58
59/********************************************************************/ 59/********************************************************************/
60/* Magic constants */
61/********************************************************************/
62
63/*
64 * The dev_info variable is the "key" that is used to match up this
65 * device driver with appropriate cards, through the card
66 * configuration database.
67 */
68static dev_info_t dev_info = DRIVER_NAME;
69
70/********************************************************************/
71/* Data structures */ 60/* Data structures */
72/********************************************************************/ 61/********************************************************************/
73 62
@@ -78,19 +67,12 @@ struct orinoco_pccard {
78 dev_node_t node; 67 dev_node_t node;
79}; 68};
80 69
81/*
82 * A linked list of "instances" of the device. Each actual PCMCIA
83 * card corresponds to one device instance, and is described by one
84 * dev_link_t structure (defined in ds.h).
85 */
86static dev_link_t *dev_list; /* = NULL */
87
88/********************************************************************/ 70/********************************************************************/
89/* Function prototypes */ 71/* Function prototypes */
90/********************************************************************/ 72/********************************************************************/
91 73
74static void spectrum_cs_config(dev_link_t *link);
92static void spectrum_cs_release(dev_link_t *link); 75static void spectrum_cs_release(dev_link_t *link);
93static void spectrum_cs_detach(dev_link_t *link);
94 76
95/********************************************************************/ 77/********************************************************************/
96/* Firmware downloader */ 78/* Firmware downloader */
@@ -601,19 +583,17 @@ spectrum_cs_hard_reset(struct orinoco_private *priv)
601 * The dev_link structure is initialized, but we don't actually 583 * The dev_link structure is initialized, but we don't actually
602 * configure the card at this point -- we wait until we receive a card 584 * configure the card at this point -- we wait until we receive a card
603 * insertion event. */ 585 * insertion event. */
604static dev_link_t * 586static int
605spectrum_cs_attach(void) 587spectrum_cs_attach(struct pcmcia_device *p_dev)
606{ 588{
607 struct net_device *dev; 589 struct net_device *dev;
608 struct orinoco_private *priv; 590 struct orinoco_private *priv;
609 struct orinoco_pccard *card; 591 struct orinoco_pccard *card;
610 dev_link_t *link; 592 dev_link_t *link;
611 client_reg_t client_reg;
612 int ret;
613 593
614 dev = alloc_orinocodev(sizeof(*card), spectrum_cs_hard_reset); 594 dev = alloc_orinocodev(sizeof(*card), spectrum_cs_hard_reset);
615 if (! dev) 595 if (! dev)
616 return NULL; 596 return -ENOMEM;
617 priv = netdev_priv(dev); 597 priv = netdev_priv(dev);
618 card = priv->card; 598 card = priv->card;
619 599
@@ -635,23 +615,13 @@ spectrum_cs_attach(void)
635 link->conf.Attributes = 0; 615 link->conf.Attributes = 0;
636 link->conf.IntType = INT_MEMORY_AND_IO; 616 link->conf.IntType = INT_MEMORY_AND_IO;
637 617
638 /* Register with Card Services */ 618 link->handle = p_dev;
639 /* FIXME: need a lock? */ 619 p_dev->instance = link;
640 link->next = dev_list;
641 dev_list = link;
642 620
643 client_reg.dev_info = &dev_info; 621 link->state |= DEV_PRESENT | DEV_CONFIG_PENDING;
644 client_reg.Version = 0x0210; /* FIXME: what does this mean? */ 622 spectrum_cs_config(link);
645 client_reg.event_callback_args.client_data = link;
646 623
647 ret = pcmcia_register_client(&link->handle, &client_reg); 624 return 0;
648 if (ret != CS_SUCCESS) {
649 cs_error(link->handle, RegisterClient, ret);
650 spectrum_cs_detach(link);
651 return NULL;
652 }
653
654 return link;
655} /* spectrum_cs_attach */ 625} /* spectrum_cs_attach */
656 626
657/* 627/*
@@ -660,27 +630,14 @@ spectrum_cs_attach(void)
660 * are freed. Otherwise, the structures will be freed when the device 630 * are freed. Otherwise, the structures will be freed when the device
661 * is released. 631 * is released.
662 */ 632 */
663static void spectrum_cs_detach(dev_link_t *link) 633static void spectrum_cs_detach(struct pcmcia_device *p_dev)
664{ 634{
665 dev_link_t **linkp; 635 dev_link_t *link = dev_to_instance(p_dev);
666 struct net_device *dev = link->priv; 636 struct net_device *dev = link->priv;
667 637
668 /* Locate device structure */
669 for (linkp = &dev_list; *linkp; linkp = &(*linkp)->next)
670 if (*linkp == link)
671 break;
672
673 BUG_ON(*linkp == NULL);
674
675 if (link->state & DEV_CONFIG) 638 if (link->state & DEV_CONFIG)
676 spectrum_cs_release(link); 639 spectrum_cs_release(link);
677 640
678 /* Break the link with Card Services */
679 if (link->handle)
680 pcmcia_deregister_client(link->handle);
681
682 /* Unlink device structure, and free it */
683 *linkp = link->next;
684 DEBUG(0, PFX "detach: link=%p link->dev=%p\n", link, link->dev); 641 DEBUG(0, PFX "detach: link=%p link->dev=%p\n", link, link->dev);
685 if (link->dev) { 642 if (link->dev) {
686 DEBUG(0, PFX "About to unregister net device %p\n", 643 DEBUG(0, PFX "About to unregister net device %p\n",
@@ -948,82 +905,56 @@ spectrum_cs_release(dev_link_t *link)
948 ioport_unmap(priv->hw.iobase); 905 ioport_unmap(priv->hw.iobase);
949} /* spectrum_cs_release */ 906} /* spectrum_cs_release */
950 907
951/* 908
952 * The card status event handler. Mostly, this schedules other stuff
953 * to run after an event is received.
954 */
955static int 909static int
956spectrum_cs_event(event_t event, int priority, 910spectrum_cs_suspend(struct pcmcia_device *p_dev)
957 event_callback_args_t * args)
958{ 911{
959 dev_link_t *link = args->client_data; 912 dev_link_t *link = dev_to_instance(p_dev);
960 struct net_device *dev = link->priv; 913 struct net_device *dev = link->priv;
961 struct orinoco_private *priv = netdev_priv(dev); 914 struct orinoco_private *priv = netdev_priv(dev);
962 int err = 0;
963 unsigned long flags; 915 unsigned long flags;
916 int err = 0;
964 917
965 switch (event) { 918 link->state |= DEV_SUSPEND;
966 case CS_EVENT_CARD_REMOVAL: 919 /* Mark the device as stopped, to block IO until later */
967 link->state &= ~DEV_PRESENT; 920 if (link->state & DEV_CONFIG) {
968 if (link->state & DEV_CONFIG) { 921 spin_lock_irqsave(&priv->lock, flags);
969 unsigned long flags;
970 922
971 spin_lock_irqsave(&priv->lock, flags); 923 err = __orinoco_down(dev);
972 netif_device_detach(dev); 924 if (err)
973 priv->hw_unavailable++; 925 printk(KERN_WARNING "%s: Error %d downing interface\n",
974 spin_unlock_irqrestore(&priv->lock, flags); 926 dev->name, err);
975 }
976 break;
977 927
978 case CS_EVENT_CARD_INSERTION: 928 netif_device_detach(dev);
979 link->state |= DEV_PRESENT | DEV_CONFIG_PENDING; 929 priv->hw_unavailable++;
980 spectrum_cs_config(link);
981 break;
982 930
983 case CS_EVENT_PM_SUSPEND: 931 spin_unlock_irqrestore(&priv->lock, flags);
984 link->state |= DEV_SUSPEND;
985 /* Fall through... */
986 case CS_EVENT_RESET_PHYSICAL:
987 /* Mark the device as stopped, to block IO until later */
988 if (link->state & DEV_CONFIG) {
989 /* This is probably racy, but I can't think of
990 a better way, short of rewriting the PCMCIA
991 layer to not suck :-( */
992 spin_lock_irqsave(&priv->lock, flags);
993
994 err = __orinoco_down(dev);
995 if (err)
996 printk(KERN_WARNING "%s: %s: Error %d downing interface\n",
997 dev->name,
998 event == CS_EVENT_PM_SUSPEND ? "SUSPEND" : "RESET_PHYSICAL",
999 err);
1000
1001 netif_device_detach(dev);
1002 priv->hw_unavailable++;
1003
1004 spin_unlock_irqrestore(&priv->lock, flags);
1005
1006 pcmcia_release_configuration(link->handle);
1007 }
1008 break;
1009 932
1010 case CS_EVENT_PM_RESUME: 933 pcmcia_release_configuration(link->handle);
1011 link->state &= ~DEV_SUSPEND; 934 }
1012 /* Fall through... */ 935
1013 case CS_EVENT_CARD_RESET: 936 return 0;
1014 if (link->state & DEV_CONFIG) { 937}
1015 /* FIXME: should we double check that this is 938
1016 * the same card as we had before */ 939static int
1017 pcmcia_request_configuration(link->handle, &link->conf); 940spectrum_cs_resume(struct pcmcia_device *p_dev)
1018 netif_device_attach(dev); 941{
1019 priv->hw_unavailable--; 942 dev_link_t *link = dev_to_instance(p_dev);
1020 schedule_work(&priv->reset_work); 943 struct net_device *dev = link->priv;
1021 } 944 struct orinoco_private *priv = netdev_priv(dev);
1022 break; 945
946 link->state &= ~DEV_SUSPEND;
947 if (link->state & DEV_CONFIG) {
948 /* FIXME: should we double check that this is
949 * the same card as we had before */
950 pcmcia_request_configuration(link->handle, &link->conf);
951 netif_device_attach(dev);
952 priv->hw_unavailable--;
953 schedule_work(&priv->reset_work);
1023 } 954 }
955 return 0;
956}
1024 957
1025 return err;
1026} /* spectrum_cs_event */
1027 958
1028/********************************************************************/ 959/********************************************************************/
1029/* Module initialization */ 960/* Module initialization */
@@ -1048,9 +979,10 @@ static struct pcmcia_driver orinoco_driver = {
1048 .drv = { 979 .drv = {
1049 .name = DRIVER_NAME, 980 .name = DRIVER_NAME,
1050 }, 981 },
1051 .attach = spectrum_cs_attach, 982 .probe = spectrum_cs_attach,
1052 .detach = spectrum_cs_detach, 983 .remove = spectrum_cs_detach,
1053 .event = spectrum_cs_event, 984 .suspend = spectrum_cs_suspend,
985 .resume = spectrum_cs_resume,
1054 .id_table = spectrum_cs_ids, 986 .id_table = spectrum_cs_ids,
1055}; 987};
1056 988
@@ -1066,7 +998,6 @@ static void __exit
1066exit_spectrum_cs(void) 998exit_spectrum_cs(void)
1067{ 999{
1068 pcmcia_unregister_driver(&orinoco_driver); 1000 pcmcia_unregister_driver(&orinoco_driver);
1069 BUG_ON(dev_list != NULL);
1070} 1001}
1071 1002
1072module_init(init_spectrum_cs); 1003module_init(init_spectrum_cs);
diff --git a/drivers/net/wireless/wavelan_cs.c b/drivers/net/wireless/wavelan_cs.c
index c822cad3333f..7e2039f52c49 100644
--- a/drivers/net/wireless/wavelan_cs.c
+++ b/drivers/net/wireless/wavelan_cs.c
@@ -4594,14 +4594,12 @@ wavelan_close(struct net_device * dev)
4594 * configure the card at this point -- we wait until we receive a 4594 * configure the card at this point -- we wait until we receive a
4595 * card insertion event. 4595 * card insertion event.
4596 */ 4596 */
4597static dev_link_t * 4597static int
4598wavelan_attach(void) 4598wavelan_attach(struct pcmcia_device *p_dev)
4599{ 4599{
4600 client_reg_t client_reg; /* Register with cardmgr */
4601 dev_link_t * link; /* Info for cardmgr */ 4600 dev_link_t * link; /* Info for cardmgr */
4602 struct net_device * dev; /* Interface generic data */ 4601 struct net_device * dev; /* Interface generic data */
4603 net_local * lp; /* Interface specific data */ 4602 net_local * lp; /* Interface specific data */
4604 int ret;
4605 4603
4606#ifdef DEBUG_CALLBACK_TRACE 4604#ifdef DEBUG_CALLBACK_TRACE
4607 printk(KERN_DEBUG "-> wavelan_attach()\n"); 4605 printk(KERN_DEBUG "-> wavelan_attach()\n");
@@ -4609,7 +4607,7 @@ wavelan_attach(void)
4609 4607
4610 /* Initialize the dev_link_t structure */ 4608 /* Initialize the dev_link_t structure */
4611 link = kzalloc(sizeof(struct dev_link_t), GFP_KERNEL); 4609 link = kzalloc(sizeof(struct dev_link_t), GFP_KERNEL);
4612 if (!link) return NULL; 4610 if (!link) return -ENOMEM;
4613 4611
4614 /* The io structure describes IO port mapping */ 4612 /* The io structure describes IO port mapping */
4615 link->io.NumPorts1 = 8; 4613 link->io.NumPorts1 = 8;
@@ -4627,14 +4625,13 @@ wavelan_attach(void)
4627 link->conf.IntType = INT_MEMORY_AND_IO; 4625 link->conf.IntType = INT_MEMORY_AND_IO;
4628 4626
4629 /* Chain drivers */ 4627 /* Chain drivers */
4630 link->next = dev_list; 4628 link->next = NULL;
4631 dev_list = link;
4632 4629
4633 /* Allocate the generic data structure */ 4630 /* Allocate the generic data structure */
4634 dev = alloc_etherdev(sizeof(net_local)); 4631 dev = alloc_etherdev(sizeof(net_local));
4635 if (!dev) { 4632 if (!dev) {
4636 kfree(link); 4633 kfree(link);
4637 return NULL; 4634 return -ENOMEM;
4638 } 4635 }
4639 link->priv = link->irq.Instance = dev; 4636 link->priv = link->irq.Instance = dev;
4640 4637
@@ -4679,28 +4676,21 @@ wavelan_attach(void)
4679 /* Other specific data */ 4676 /* Other specific data */
4680 dev->mtu = WAVELAN_MTU; 4677 dev->mtu = WAVELAN_MTU;
4681 4678
4682 /* Register with Card Services */ 4679 link->handle = p_dev;
4683 client_reg.dev_info = &dev_info; 4680 p_dev->instance = link;
4684 client_reg.Version = 0x0210;
4685 client_reg.event_callback_args.client_data = link;
4686 4681
4687#ifdef DEBUG_CONFIG_INFO 4682 link->state |= DEV_PRESENT | DEV_CONFIG_PENDING;
4688 printk(KERN_DEBUG "wavelan_attach(): almost done, calling pcmcia_register_client\n"); 4683 if(wv_pcmcia_config(link) &&
4689#endif 4684 wv_hw_config(dev))
4690 4685 wv_init_info(dev);
4691 ret = pcmcia_register_client(&link->handle, &client_reg); 4686 else
4692 if(ret != 0) 4687 dev->irq = 0;
4693 {
4694 cs_error(link->handle, RegisterClient, ret);
4695 wavelan_detach(link);
4696 return NULL;
4697 }
4698 4688
4699#ifdef DEBUG_CALLBACK_TRACE 4689#ifdef DEBUG_CALLBACK_TRACE
4700 printk(KERN_DEBUG "<- wavelan_attach()\n"); 4690 printk(KERN_DEBUG "<- wavelan_attach()\n");
4701#endif 4691#endif
4702 4692
4703 return link; 4693 return 0;
4704} 4694}
4705 4695
4706/*------------------------------------------------------------------*/ 4696/*------------------------------------------------------------------*/
@@ -4711,8 +4701,10 @@ wavelan_attach(void)
4711 * is released. 4701 * is released.
4712 */ 4702 */
4713static void 4703static void
4714wavelan_detach(dev_link_t * link) 4704wavelan_detach(struct pcmcia_device *p_dev)
4715{ 4705{
4706 dev_link_t *link = dev_to_instance(p_dev);
4707
4716#ifdef DEBUG_CALLBACK_TRACE 4708#ifdef DEBUG_CALLBACK_TRACE
4717 printk(KERN_DEBUG "-> wavelan_detach(0x%p)\n", link); 4709 printk(KERN_DEBUG "-> wavelan_detach(0x%p)\n", link);
4718#endif 4710#endif
@@ -4729,31 +4721,6 @@ wavelan_detach(dev_link_t * link)
4729 wv_pcmcia_release(link); 4721 wv_pcmcia_release(link);
4730 } 4722 }
4731 4723
4732 /* Break the link with Card Services */
4733 if(link->handle)
4734 pcmcia_deregister_client(link->handle);
4735
4736 /* Remove the interface data from the linked list */
4737 if(dev_list == link)
4738 dev_list = link->next;
4739 else
4740 {
4741 dev_link_t * prev = dev_list;
4742
4743 while((prev != (dev_link_t *) NULL) && (prev->next != link))
4744 prev = prev->next;
4745
4746 if(prev == (dev_link_t *) NULL)
4747 {
4748#ifdef DEBUG_CONFIG_ERRORS
4749 printk(KERN_WARNING "wavelan_detach : Attempting to remove a nonexistent device.\n");
4750#endif
4751 return;
4752 }
4753
4754 prev->next = link->next;
4755 }
4756
4757 /* Free pieces */ 4724 /* Free pieces */
4758 if(link->priv) 4725 if(link->priv)
4759 { 4726 {
@@ -4775,65 +4742,11 @@ wavelan_detach(dev_link_t * link)
4775#endif 4742#endif
4776} 4743}
4777 4744
4778/*------------------------------------------------------------------*/ 4745static int wavelan_suspend(struct pcmcia_device *p_dev)
4779/*
4780 * The card status event handler. Mostly, this schedules other stuff
4781 * to run after an event is received. A CARD_REMOVAL event also sets
4782 * some flags to discourage the net drivers from trying to talk to the
4783 * card any more.
4784 */
4785static int
4786wavelan_event(event_t event, /* The event received */
4787 int priority,
4788 event_callback_args_t * args)
4789{ 4746{
4790 dev_link_t * link = (dev_link_t *) args->client_data; 4747 dev_link_t *link = dev_to_instance(p_dev);
4791 struct net_device * dev = (struct net_device *) link->priv; 4748 struct net_device * dev = (struct net_device *) link->priv;
4792
4793#ifdef DEBUG_CALLBACK_TRACE
4794 printk(KERN_DEBUG "->wavelan_event(): %s\n",
4795 ((event == CS_EVENT_REGISTRATION_COMPLETE)?"registration complete" :
4796 ((event == CS_EVENT_CARD_REMOVAL) ? "card removal" :
4797 ((event == CS_EVENT_CARD_INSERTION) ? "card insertion" :
4798 ((event == CS_EVENT_PM_SUSPEND) ? "pm suspend" :
4799 ((event == CS_EVENT_RESET_PHYSICAL) ? "physical reset" :
4800 ((event == CS_EVENT_PM_RESUME) ? "pm resume" :
4801 ((event == CS_EVENT_CARD_RESET) ? "card reset" :
4802 "unknown"))))))));
4803#endif
4804
4805 switch(event)
4806 {
4807 case CS_EVENT_REGISTRATION_COMPLETE:
4808#ifdef DEBUG_CONFIG_INFO
4809 printk(KERN_DEBUG "wavelan_cs: registration complete\n");
4810#endif
4811 break;
4812 4749
4813 case CS_EVENT_CARD_REMOVAL:
4814 /* Oups ! The card is no more there */
4815 link->state &= ~DEV_PRESENT;
4816 if(link->state & DEV_CONFIG)
4817 {
4818 /* Accept no more transmissions */
4819 netif_device_detach(dev);
4820
4821 /* Release the card */
4822 wv_pcmcia_release(link);
4823 }
4824 break;
4825
4826 case CS_EVENT_CARD_INSERTION:
4827 /* Reset and configure the card */
4828 link->state |= DEV_PRESENT | DEV_CONFIG_PENDING;
4829 if(wv_pcmcia_config(link) &&
4830 wv_hw_config(dev))
4831 wv_init_info(dev);
4832 else
4833 dev->irq = 0;
4834 break;
4835
4836 case CS_EVENT_PM_SUSPEND:
4837 /* NB: wavelan_close will be called, but too late, so we are 4750 /* NB: wavelan_close will be called, but too late, so we are
4838 * obliged to close nicely the wavelan here. David, could you 4751 * obliged to close nicely the wavelan here. David, could you
4839 * close the device before suspending them ? And, by the way, 4752 * close the device before suspending them ? And, by the way,
@@ -4848,38 +4761,37 @@ wavelan_event(event_t event, /* The event received */
4848 4761
4849 /* The card is now suspended */ 4762 /* The card is now suspended */
4850 link->state |= DEV_SUSPEND; 4763 link->state |= DEV_SUSPEND;
4851 /* Fall through... */ 4764
4852 case CS_EVENT_RESET_PHYSICAL:
4853 if(link->state & DEV_CONFIG) 4765 if(link->state & DEV_CONFIG)
4854 { 4766 {
4855 if(link->open) 4767 if(link->open)
4856 netif_device_detach(dev); 4768 netif_device_detach(dev);
4857 pcmcia_release_configuration(link->handle); 4769 pcmcia_release_configuration(link->handle);
4858 } 4770 }
4859 break; 4771
4772 return 0;
4773}
4774
4775static int wavelan_resume(struct pcmcia_device *p_dev)
4776{
4777 dev_link_t *link = dev_to_instance(p_dev);
4778 struct net_device * dev = (struct net_device *) link->priv;
4860 4779
4861 case CS_EVENT_PM_RESUME:
4862 link->state &= ~DEV_SUSPEND; 4780 link->state &= ~DEV_SUSPEND;
4863 /* Fall through... */
4864 case CS_EVENT_CARD_RESET:
4865 if(link->state & DEV_CONFIG) 4781 if(link->state & DEV_CONFIG)
4866 { 4782 {
4867 pcmcia_request_configuration(link->handle, &link->conf); 4783 pcmcia_request_configuration(link->handle, &link->conf);
4868 if(link->open) /* If RESET -> True, If RESUME -> False ? */ 4784 if(link->open) /* If RESET -> True, If RESUME -> False ? */
4869 { 4785 {
4870 wv_hw_reset(dev); 4786 wv_hw_reset(dev);
4871 netif_device_attach(dev); 4787 netif_device_attach(dev);
4872 } 4788 }
4873 } 4789 }
4874 break;
4875 }
4876 4790
4877#ifdef DEBUG_CALLBACK_TRACE 4791 return 0;
4878 printk(KERN_DEBUG "<-wavelan_event()\n");
4879#endif
4880 return 0;
4881} 4792}
4882 4793
4794
4883static struct pcmcia_device_id wavelan_ids[] = { 4795static struct pcmcia_device_id wavelan_ids[] = {
4884 PCMCIA_DEVICE_PROD_ID12("AT&T","WaveLAN/PCMCIA", 0xe7c5affd, 0x1bc50975), 4796 PCMCIA_DEVICE_PROD_ID12("AT&T","WaveLAN/PCMCIA", 0xe7c5affd, 0x1bc50975),
4885 PCMCIA_DEVICE_PROD_ID12("Digital", "RoamAbout/DS", 0x9999ab35, 0x00d05e06), 4797 PCMCIA_DEVICE_PROD_ID12("Digital", "RoamAbout/DS", 0x9999ab35, 0x00d05e06),
@@ -4894,10 +4806,11 @@ static struct pcmcia_driver wavelan_driver = {
4894 .drv = { 4806 .drv = {
4895 .name = "wavelan_cs", 4807 .name = "wavelan_cs",
4896 }, 4808 },
4897 .attach = wavelan_attach, 4809 .probe = wavelan_attach,
4898 .event = wavelan_event, 4810 .remove = wavelan_detach,
4899 .detach = wavelan_detach,
4900 .id_table = wavelan_ids, 4811 .id_table = wavelan_ids,
4812 .suspend = wavelan_suspend,
4813 .resume = wavelan_resume,
4901}; 4814};
4902 4815
4903static int __init 4816static int __init
diff --git a/drivers/net/wireless/wavelan_cs.p.h b/drivers/net/wireless/wavelan_cs.p.h
index 724a715089c9..f2d597568151 100644
--- a/drivers/net/wireless/wavelan_cs.p.h
+++ b/drivers/net/wireless/wavelan_cs.p.h
@@ -754,20 +754,11 @@ static void
754static int 754static int
755 wavelan_open(struct net_device *), /* Open the device */ 755 wavelan_open(struct net_device *), /* Open the device */
756 wavelan_close(struct net_device *); /* Close the device */ 756 wavelan_close(struct net_device *); /* Close the device */
757static dev_link_t *
758 wavelan_attach(void); /* Create a new device */
759static void 757static void
760 wavelan_detach(dev_link_t *); /* Destroy a removed device */ 758 wavelan_detach(struct pcmcia_device *p_dev); /* Destroy a removed device */
761static int
762 wavelan_event(event_t, /* Manage pcmcia events */
763 int,
764 event_callback_args_t *);
765 759
766/**************************** VARIABLES ****************************/ 760/**************************** VARIABLES ****************************/
767 761
768static dev_info_t dev_info = "wavelan_cs";
769static dev_link_t *dev_list = NULL; /* Linked list of devices */
770
771/* 762/*
772 * Parameters that can be set with 'insmod' 763 * Parameters that can be set with 'insmod'
773 * The exact syntax is 'insmod wavelan_cs.o <var>=<value>' 764 * The exact syntax is 'insmod wavelan_cs.o <var>=<value>'
diff --git a/drivers/net/wireless/wl3501_cs.c b/drivers/net/wireless/wl3501_cs.c
index 978fdc606781..48e10b0c7e74 100644
--- a/drivers/net/wireless/wl3501_cs.c
+++ b/drivers/net/wireless/wl3501_cs.c
@@ -105,7 +105,6 @@ module_param(pc_debug, int, 0);
105 */ 105 */
106static void wl3501_config(dev_link_t *link); 106static void wl3501_config(dev_link_t *link);
107static void wl3501_release(dev_link_t *link); 107static void wl3501_release(dev_link_t *link);
108static int wl3501_event(event_t event, int pri, event_callback_args_t *args);
109 108
110/* 109/*
111 * The dev_info variable is the "key" that is used to match up this 110 * The dev_info variable is the "key" that is used to match up this
@@ -1498,9 +1497,11 @@ static struct ethtool_ops ops = {
1498 * Services. If it has been released, all local data structures are freed. 1497 * Services. If it has been released, all local data structures are freed.
1499 * Otherwise, the structures will be freed when the device is released. 1498 * Otherwise, the structures will be freed when the device is released.
1500 */ 1499 */
1501static void wl3501_detach(dev_link_t *link) 1500static void wl3501_detach(struct pcmcia_device *p_dev)
1502{ 1501{
1502 dev_link_t *link = dev_to_instance(p_dev);
1503 dev_link_t **linkp; 1503 dev_link_t **linkp;
1504 struct net_device *dev = link->priv;
1504 1505
1505 /* Locate device structure */ 1506 /* Locate device structure */
1506 for (linkp = &wl3501_dev_list; *linkp; linkp = &(*linkp)->next) 1507 for (linkp = &wl3501_dev_list; *linkp; linkp = &(*linkp)->next)
@@ -1514,16 +1515,12 @@ static void wl3501_detach(dev_link_t *link)
1514 * function is called, that will trigger a proper detach(). */ 1515 * function is called, that will trigger a proper detach(). */
1515 1516
1516 if (link->state & DEV_CONFIG) { 1517 if (link->state & DEV_CONFIG) {
1517#ifdef PCMCIA_DEBUG 1518 while (link->open > 0)
1518 printk(KERN_DEBUG "wl3501_cs: detach postponed, '%s' " 1519 wl3501_close(dev);
1519 "still locked\n", link->dev->dev_name);
1520#endif
1521 goto out;
1522 }
1523 1520
1524 /* Break the link with Card Services */ 1521 netif_device_detach(dev);
1525 if (link->handle) 1522 wl3501_release(link);
1526 pcmcia_deregister_client(link->handle); 1523 }
1527 1524
1528 /* Unlink device structure, free pieces */ 1525 /* Unlink device structure, free pieces */
1529 *linkp = link->next; 1526 *linkp = link->next;
@@ -1956,18 +1953,16 @@ static const struct iw_handler_def wl3501_handler_def = {
1956 * The dev_link structure is initialized, but we don't actually configure the 1953 * The dev_link structure is initialized, but we don't actually configure the
1957 * card at this point -- we wait until we receive a card insertion event. 1954 * card at this point -- we wait until we receive a card insertion event.
1958 */ 1955 */
1959static dev_link_t *wl3501_attach(void) 1956static int wl3501_attach(struct pcmcia_device *p_dev)
1960{ 1957{
1961 client_reg_t client_reg;
1962 dev_link_t *link; 1958 dev_link_t *link;
1963 struct net_device *dev; 1959 struct net_device *dev;
1964 struct wl3501_card *this; 1960 struct wl3501_card *this;
1965 int ret;
1966 1961
1967 /* Initialize the dev_link_t structure */ 1962 /* Initialize the dev_link_t structure */
1968 link = kzalloc(sizeof(*link), GFP_KERNEL); 1963 link = kzalloc(sizeof(*link), GFP_KERNEL);
1969 if (!link) 1964 if (!link)
1970 goto out; 1965 return -ENOMEM;
1971 1966
1972 /* The io structure describes IO port mapping */ 1967 /* The io structure describes IO port mapping */
1973 link->io.NumPorts1 = 16; 1968 link->io.NumPorts1 = 16;
@@ -2003,24 +1998,17 @@ static dev_link_t *wl3501_attach(void)
2003 netif_stop_queue(dev); 1998 netif_stop_queue(dev);
2004 link->priv = link->irq.Instance = dev; 1999 link->priv = link->irq.Instance = dev;
2005 2000
2006 /* Register with Card Services */ 2001 link->handle = p_dev;
2007 link->next = wl3501_dev_list; 2002 p_dev->instance = link;
2008 wl3501_dev_list = link; 2003
2009 client_reg.dev_info = &wl3501_dev_info; 2004 link->state |= DEV_PRESENT | DEV_CONFIG_PENDING;
2010 client_reg.Version = 0x0210; 2005 wl3501_config(link);
2011 client_reg.event_callback_args.client_data = link; 2006
2012 ret = pcmcia_register_client(&link->handle, &client_reg); 2007 return 0;
2013 if (ret) {
2014 cs_error(link->handle, RegisterClient, ret);
2015 wl3501_detach(link);
2016 link = NULL;
2017 }
2018out:
2019 return link;
2020out_link: 2008out_link:
2021 kfree(link); 2009 kfree(link);
2022 link = NULL; 2010 link = NULL;
2023 goto out; 2011 return -ENOMEM;
2024} 2012}
2025 2013
2026#define CS_CHECK(fn, ret) \ 2014#define CS_CHECK(fn, ret) \
@@ -2173,67 +2161,41 @@ static void wl3501_release(dev_link_t *link)
2173 link->state &= ~DEV_CONFIG; 2161 link->state &= ~DEV_CONFIG;
2174} 2162}
2175 2163
2176/** 2164static int wl3501_suspend(struct pcmcia_device *p_dev)
2177 * wl3501_event - The card status event handler
2178 * @event - event
2179 * @pri - priority
2180 * @args - arguments for this event
2181 *
2182 * The card status event handler. Mostly, this schedules other stuff to run
2183 * after an event is received. A CARD_REMOVAL event also sets some flags to
2184 * discourage the net drivers from trying to talk to the card any more.
2185 *
2186 * When a CARD_REMOVAL event is received, we immediately set a flag to block
2187 * future accesses to this device. All the functions that actually access the
2188 * device should check this flag to make sure the card is still present.
2189 */
2190static int wl3501_event(event_t event, int pri, event_callback_args_t *args)
2191{ 2165{
2192 dev_link_t *link = args->client_data; 2166 dev_link_t *link = dev_to_instance(p_dev);
2193 struct net_device *dev = link->priv; 2167 struct net_device *dev = link->priv;
2194 2168
2195 switch (event) { 2169 link->state |= DEV_SUSPEND;
2196 case CS_EVENT_CARD_REMOVAL: 2170
2197 link->state &= ~DEV_PRESENT; 2171 wl3501_pwr_mgmt(dev->priv, WL3501_SUSPEND);
2198 if (link->state & DEV_CONFIG) { 2172 if (link->state & DEV_CONFIG) {
2199 while (link->open > 0) 2173 if (link->open)
2200 wl3501_close(dev);
2201 netif_device_detach(dev); 2174 netif_device_detach(dev);
2202 wl3501_release(link); 2175 pcmcia_release_configuration(link->handle);
2203 } 2176 }
2204 break; 2177
2205 case CS_EVENT_CARD_INSERTION: 2178 return 0;
2206 link->state |= DEV_PRESENT | DEV_CONFIG_PENDING; 2179}
2207 wl3501_config(link); 2180
2208 break; 2181static int wl3501_resume(struct pcmcia_device *p_dev)
2209 case CS_EVENT_PM_SUSPEND: 2182{
2210 link->state |= DEV_SUSPEND; 2183 dev_link_t *link = dev_to_instance(p_dev);
2211 wl3501_pwr_mgmt(dev->priv, WL3501_SUSPEND); 2184 struct net_device *dev = link->priv;
2212 /* Fall through... */ 2185
2213 case CS_EVENT_RESET_PHYSICAL: 2186 wl3501_pwr_mgmt(dev->priv, WL3501_RESUME);
2214 if (link->state & DEV_CONFIG) { 2187 if (link->state & DEV_CONFIG) {
2215 if (link->open) 2188 pcmcia_request_configuration(link->handle, &link->conf);
2216 netif_device_detach(dev); 2189 if (link->open) {
2217 pcmcia_release_configuration(link->handle); 2190 wl3501_reset(dev);
2218 } 2191 netif_device_attach(dev);
2219 break;
2220 case CS_EVENT_PM_RESUME:
2221 link->state &= ~DEV_SUSPEND;
2222 wl3501_pwr_mgmt(dev->priv, WL3501_RESUME);
2223 /* Fall through... */
2224 case CS_EVENT_CARD_RESET:
2225 if (link->state & DEV_CONFIG) {
2226 pcmcia_request_configuration(link->handle, &link->conf);
2227 if (link->open) {
2228 wl3501_reset(dev);
2229 netif_device_attach(dev);
2230 }
2231 } 2192 }
2232 break;
2233 } 2193 }
2194
2234 return 0; 2195 return 0;
2235} 2196}
2236 2197
2198
2237static struct pcmcia_device_id wl3501_ids[] = { 2199static struct pcmcia_device_id wl3501_ids[] = {
2238 PCMCIA_DEVICE_MANF_CARD(0xd601, 0x0001), 2200 PCMCIA_DEVICE_MANF_CARD(0xd601, 0x0001),
2239 PCMCIA_DEVICE_NULL 2201 PCMCIA_DEVICE_NULL
@@ -2245,10 +2207,11 @@ static struct pcmcia_driver wl3501_driver = {
2245 .drv = { 2207 .drv = {
2246 .name = "wl3501_cs", 2208 .name = "wl3501_cs",
2247 }, 2209 },
2248 .attach = wl3501_attach, 2210 .probe = wl3501_attach,
2249 .event = wl3501_event, 2211 .remove = wl3501_detach,
2250 .detach = wl3501_detach,
2251 .id_table = wl3501_ids, 2212 .id_table = wl3501_ids,
2213 .suspend = wl3501_suspend,
2214 .resume = wl3501_resume,
2252}; 2215};
2253 2216
2254static int __init wl3501_init_module(void) 2217static int __init wl3501_init_module(void)