sky2: Refactor down/up code out of sky2_restart()
[safe/jmp/linux-2.6] / drivers / net / wireless / ray_cs.c
1 /*=============================================================================
2  *
3  * A  PCMCIA client driver for the Raylink wireless LAN card.
4  * The starting point for this module was the skeleton.c in the
5  * PCMCIA 2.9.12 package written by David Hinds, dahinds@users.sourceforge.net
6  *
7  *
8  * Copyright (c) 1998  Corey Thomas (corey@world.std.com)
9  *
10  * This driver is free software; you can redistribute it and/or modify
11  * it under the terms of version 2 only of the GNU General Public License as
12  * published by the Free Software Foundation.
13  *
14  * It is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17  * GNU General Public License for more details.
18  *
19  * You should have received a copy of the GNU General Public License
20  * along with this program; if not, write to the Free Software
21  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
22  *
23  * Changes:
24  * Arnaldo Carvalho de Melo <acme@conectiva.com.br> - 08/08/2000
25  * - reorganize kmallocs in ray_attach, checking all for failure
26  *   and releasing the previous allocations if one fails
27  *
28  * Daniele Bellucci <bellucda@tiscali.it> - 07/10/2003
29  * - Audit copy_to_user in ioctl(SIOCGIWESSID)
30  *
31 =============================================================================*/
32
33 #include <linux/module.h>
34 #include <linux/kernel.h>
35 #include <linux/proc_fs.h>
36 #include <linux/ptrace.h>
37 #include <linux/seq_file.h>
38 #include <linux/string.h>
39 #include <linux/timer.h>
40 #include <linux/init.h>
41 #include <linux/netdevice.h>
42 #include <linux/etherdevice.h>
43 #include <linux/if_arp.h>
44 #include <linux/ioport.h>
45 #include <linux/skbuff.h>
46 #include <linux/ethtool.h>
47 #include <linux/ieee80211.h>
48
49 #include <pcmcia/cs_types.h>
50 #include <pcmcia/cs.h>
51 #include <pcmcia/cistpl.h>
52 #include <pcmcia/cisreg.h>
53 #include <pcmcia/ds.h>
54 #include <pcmcia/mem_op.h>
55
56 #include <linux/wireless.h>
57 #include <net/iw_handler.h>
58
59 #include <asm/io.h>
60 #include <asm/system.h>
61 #include <asm/byteorder.h>
62 #include <asm/uaccess.h>
63
64 /* Warning : these stuff will slow down the driver... */
65 #define WIRELESS_SPY            /* Enable spying addresses */
66 /* Definitions we need for spy */
67 typedef struct iw_statistics iw_stats;
68 typedef u_char mac_addr[ETH_ALEN];      /* Hardware address */
69
70 #include "rayctl.h"
71 #include "ray_cs.h"
72
73
74 /** Prototypes based on PCMCIA skeleton driver *******************************/
75 static int ray_config(struct pcmcia_device *link);
76 static void ray_release(struct pcmcia_device *link);
77 static void ray_detach(struct pcmcia_device *p_dev);
78
79 /***** Prototypes indicated by device structure ******************************/
80 static int ray_dev_close(struct net_device *dev);
81 static int ray_dev_config(struct net_device *dev, struct ifmap *map);
82 static struct net_device_stats *ray_get_stats(struct net_device *dev);
83 static int ray_dev_init(struct net_device *dev);
84
85 static const struct ethtool_ops netdev_ethtool_ops;
86
87 static int ray_open(struct net_device *dev);
88 static netdev_tx_t ray_dev_start_xmit(struct sk_buff *skb,
89                                             struct net_device *dev);
90 static void set_multicast_list(struct net_device *dev);
91 static void ray_update_multi_list(struct net_device *dev, int all);
92 static int translate_frame(ray_dev_t *local, struct tx_msg __iomem *ptx,
93                            unsigned char *data, int len);
94 static void ray_build_header(ray_dev_t *local, struct tx_msg __iomem *ptx,
95                              UCHAR msg_type, unsigned char *data);
96 static void untranslate(ray_dev_t *local, struct sk_buff *skb, int len);
97 static iw_stats *ray_get_wireless_stats(struct net_device *dev);
98 static const struct iw_handler_def ray_handler_def;
99
100 /***** Prototypes for raylink functions **************************************/
101 static int asc_to_int(char a);
102 static void authenticate(ray_dev_t *local);
103 static int build_auth_frame(ray_dev_t *local, UCHAR *dest, int auth_type);
104 static void authenticate_timeout(u_long);
105 static int get_free_ccs(ray_dev_t *local);
106 static int get_free_tx_ccs(ray_dev_t *local);
107 static void init_startup_params(ray_dev_t *local);
108 static int parse_addr(char *in_str, UCHAR *out);
109 static int ray_hw_xmit(unsigned char *data, int len, struct net_device *dev, UCHAR type);
110 static int ray_init(struct net_device *dev);
111 static int interrupt_ecf(ray_dev_t *local, int ccs);
112 static void ray_reset(struct net_device *dev);
113 static void ray_update_parm(struct net_device *dev, UCHAR objid, UCHAR *value, int len);
114 static void verify_dl_startup(u_long);
115
116 /* Prototypes for interrpt time functions **********************************/
117 static irqreturn_t ray_interrupt(int reg, void *dev_id);
118 static void clear_interrupt(ray_dev_t *local);
119 static void rx_deauthenticate(ray_dev_t *local, struct rcs __iomem *prcs,
120                               unsigned int pkt_addr, int rx_len);
121 static int copy_from_rx_buff(ray_dev_t *local, UCHAR *dest, int pkt_addr, int len);
122 static void ray_rx(struct net_device *dev, ray_dev_t *local, struct rcs __iomem *prcs);
123 static void release_frag_chain(ray_dev_t *local, struct rcs __iomem *prcs);
124 static void rx_authenticate(ray_dev_t *local, struct rcs __iomem *prcs,
125                             unsigned int pkt_addr, int rx_len);
126 static void rx_data(struct net_device *dev, struct rcs __iomem *prcs,
127                     unsigned int pkt_addr, int rx_len);
128 static void associate(ray_dev_t *local);
129
130 /* Card command functions */
131 static int dl_startup_params(struct net_device *dev);
132 static void join_net(u_long local);
133 static void start_net(u_long local);
134 /* void start_net(ray_dev_t *local); */
135
136 /*===========================================================================*/
137 /* Parameters that can be set with 'insmod' */
138
139 /* ADHOC=0, Infrastructure=1 */
140 static int net_type = ADHOC;
141
142 /* Hop dwell time in Kus (1024 us units defined by 802.11) */
143 static int hop_dwell = 128;
144
145 /* Beacon period in Kus */
146 static int beacon_period = 256;
147
148 /* power save mode (0 = off, 1 = save power) */
149 static int psm;
150
151 /* String for network's Extended Service Set ID. 32 Characters max */
152 static char *essid;
153
154 /* Default to encapsulation unless translation requested */
155 static int translate = 1;
156
157 static int country = USA;
158
159 static int sniffer;
160
161 static int bc;
162
163 /* 48 bit physical card address if overriding card's real physical
164  * address is required.  Since IEEE 802.11 addresses are 48 bits
165  * like ethernet, an int can't be used, so a string is used. To
166  * allow use of addresses starting with a decimal digit, the first
167  * character must be a letter and will be ignored. This letter is
168  * followed by up to 12 hex digits which are the address.  If less
169  * than 12 digits are used, the address will be left filled with 0's.
170  * Note that bit 0 of the first byte is the broadcast bit, and evil
171  * things will happen if it is not 0 in a card address.
172  */
173 static char *phy_addr = NULL;
174
175
176 /* A struct pcmcia_device structure has fields for most things that are needed
177    to keep track of a socket, but there will usually be some device
178    specific information that also needs to be kept track of.  The
179    'priv' pointer in a struct pcmcia_device structure can be used to point to
180    a device-specific private data structure, like this.
181 */
182 static unsigned int ray_mem_speed = 500;
183
184 /* WARNING: THIS DRIVER IS NOT CAPABLE OF HANDLING MULTIPLE DEVICES! */
185 static struct pcmcia_device *this_device = NULL;
186
187 MODULE_AUTHOR("Corey Thomas <corey@world.std.com>");
188 MODULE_DESCRIPTION("Raylink/WebGear wireless LAN driver");
189 MODULE_LICENSE("GPL");
190
191 module_param(net_type, int, 0);
192 module_param(hop_dwell, int, 0);
193 module_param(beacon_period, int, 0);
194 module_param(psm, int, 0);
195 module_param(essid, charp, 0);
196 module_param(translate, int, 0);
197 module_param(country, int, 0);
198 module_param(sniffer, int, 0);
199 module_param(bc, int, 0);
200 module_param(phy_addr, charp, 0);
201 module_param(ray_mem_speed, int, 0);
202
203 static UCHAR b5_default_startup_parms[] = {
204         0, 0,                   /* Adhoc station */
205         'L', 'I', 'N', 'U', 'X', 0, 0, 0,       /* 32 char ESSID */
206         0, 0, 0, 0, 0, 0, 0, 0,
207         0, 0, 0, 0, 0, 0, 0, 0,
208         0, 0, 0, 0, 0, 0, 0, 0,
209         1, 0,                   /* Active scan, CA Mode */
210         0, 0, 0, 0, 0, 0,       /* No default MAC addr  */
211         0x7f, 0xff,             /* Frag threshold */
212         0x00, 0x80,             /* Hop time 128 Kus */
213         0x01, 0x00,             /* Beacon period 256 Kus */
214         0x01, 0x07, 0xa3,       /* DTIM, retries, ack timeout */
215         0x1d, 0x82, 0x4e,       /* SIFS, DIFS, PIFS */
216         0x7f, 0xff,             /* RTS threshold */
217         0x04, 0xe2, 0x38, 0xA4, /* scan_dwell, max_scan_dwell */
218         0x05,                   /* assoc resp timeout thresh */
219         0x08, 0x02, 0x08,       /* adhoc, infra, super cycle max */
220         0,                      /* Promiscuous mode */
221         0x0c, 0x0bd,            /* Unique word */
222         0x32,                   /* Slot time */
223         0xff, 0xff,             /* roam-low snr, low snr count */
224         0x05, 0xff,             /* Infra, adhoc missed bcn thresh */
225         0x01, 0x0b, 0x4f,       /* USA, hop pattern, hop pat length */
226 /* b4 - b5 differences start here */
227         0x00, 0x3f,             /* CW max */
228         0x00, 0x0f,             /* CW min */
229         0x04, 0x08,             /* Noise gain, limit offset */
230         0x28, 0x28,             /* det rssi, med busy offsets */
231         7,                      /* det sync thresh */
232         0, 2, 2,                /* test mode, min, max */
233         0,                      /* allow broadcast SSID probe resp */
234         0, 0,                   /* privacy must start, can join */
235         2, 0, 0, 0, 0, 0, 0, 0  /* basic rate set */
236 };
237
238 static UCHAR b4_default_startup_parms[] = {
239         0, 0,                   /* Adhoc station */
240         'L', 'I', 'N', 'U', 'X', 0, 0, 0,       /* 32 char ESSID */
241         0, 0, 0, 0, 0, 0, 0, 0,
242         0, 0, 0, 0, 0, 0, 0, 0,
243         0, 0, 0, 0, 0, 0, 0, 0,
244         1, 0,                   /* Active scan, CA Mode */
245         0, 0, 0, 0, 0, 0,       /* No default MAC addr  */
246         0x7f, 0xff,             /* Frag threshold */
247         0x02, 0x00,             /* Hop time */
248         0x00, 0x01,             /* Beacon period */
249         0x01, 0x07, 0xa3,       /* DTIM, retries, ack timeout */
250         0x1d, 0x82, 0xce,       /* SIFS, DIFS, PIFS */
251         0x7f, 0xff,             /* RTS threshold */
252         0xfb, 0x1e, 0xc7, 0x5c, /* scan_dwell, max_scan_dwell */
253         0x05,                   /* assoc resp timeout thresh */
254         0x04, 0x02, 0x4,        /* adhoc, infra, super cycle max */
255         0,                      /* Promiscuous mode */
256         0x0c, 0x0bd,            /* Unique word */
257         0x4e,                   /* Slot time (TBD seems wrong) */
258         0xff, 0xff,             /* roam-low snr, low snr count */
259         0x05, 0xff,             /* Infra, adhoc missed bcn thresh */
260         0x01, 0x0b, 0x4e,       /* USA, hop pattern, hop pat length */
261 /* b4 - b5 differences start here */
262         0x3f, 0x0f,             /* CW max, min */
263         0x04, 0x08,             /* Noise gain, limit offset */
264         0x28, 0x28,             /* det rssi, med busy offsets */
265         7,                      /* det sync thresh */
266         0, 2, 2                 /* test mode, min, max */
267 };
268
269 /*===========================================================================*/
270 static unsigned char eth2_llc[] = { 0xaa, 0xaa, 3, 0, 0, 0 };
271
272 static char hop_pattern_length[] = { 1,
273         USA_HOP_MOD, EUROPE_HOP_MOD,
274         JAPAN_HOP_MOD, KOREA_HOP_MOD,
275         SPAIN_HOP_MOD, FRANCE_HOP_MOD,
276         ISRAEL_HOP_MOD, AUSTRALIA_HOP_MOD,
277         JAPAN_TEST_HOP_MOD
278 };
279
280 static char rcsid[] =
281     "Raylink/WebGear wireless LAN - Corey <Thomas corey@world.std.com>";
282
283 static const struct net_device_ops ray_netdev_ops = {
284         .ndo_init               = ray_dev_init,
285         .ndo_open               = ray_open,
286         .ndo_stop               = ray_dev_close,
287         .ndo_start_xmit         = ray_dev_start_xmit,
288         .ndo_set_config         = ray_dev_config,
289         .ndo_get_stats          = ray_get_stats,
290         .ndo_set_multicast_list = set_multicast_list,
291         .ndo_change_mtu         = eth_change_mtu,
292         .ndo_set_mac_address    = eth_mac_addr,
293         .ndo_validate_addr      = eth_validate_addr,
294 };
295
296 /*=============================================================================
297     ray_attach() creates an "instance" of the driver, allocating
298     local data structures for one device.  The device is registered
299     with Card Services.
300     The dev_link structure is initialized, but we don't actually
301     configure the card at this point -- we wait until we receive a
302     card insertion event.
303 =============================================================================*/
304 static int ray_probe(struct pcmcia_device *p_dev)
305 {
306         ray_dev_t *local;
307         struct net_device *dev;
308
309         dev_dbg(&p_dev->dev, "ray_attach()\n");
310
311         /* Allocate space for private device-specific data */
312         dev = alloc_etherdev(sizeof(ray_dev_t));
313         if (!dev)
314                 goto fail_alloc_dev;
315
316         local = netdev_priv(dev);
317         local->finder = p_dev;
318
319         /* The io structure describes IO port mapping. None used here */
320         p_dev->io.NumPorts1 = 0;
321         p_dev->io.Attributes1 = IO_DATA_PATH_WIDTH_8;
322         p_dev->io.IOAddrLines = 5;
323
324         /* Interrupt setup. For PCMCIA, driver takes what's given */
325         p_dev->irq.Attributes = IRQ_TYPE_DYNAMIC_SHARING;
326         p_dev->irq.Handler = &ray_interrupt;
327
328         /* General socket configuration */
329         p_dev->conf.Attributes = CONF_ENABLE_IRQ;
330         p_dev->conf.IntType = INT_MEMORY_AND_IO;
331         p_dev->conf.ConfigIndex = 1;
332
333         p_dev->priv = dev;
334
335         local->finder = p_dev;
336         local->card_status = CARD_INSERTED;
337         local->authentication_state = UNAUTHENTICATED;
338         local->num_multi = 0;
339         dev_dbg(&p_dev->dev, "ray_attach p_dev = %p,  dev = %p,  local = %p, intr = %p\n",
340               p_dev, dev, local, &ray_interrupt);
341
342         /* Raylink entries in the device structure */
343         dev->netdev_ops = &ray_netdev_ops;
344         SET_ETHTOOL_OPS(dev, &netdev_ethtool_ops);
345         dev->wireless_handlers = &ray_handler_def;
346 #ifdef WIRELESS_SPY
347         local->wireless_data.spy_data = &local->spy_data;
348         dev->wireless_data = &local->wireless_data;
349 #endif /* WIRELESS_SPY */
350
351
352         dev_dbg(&p_dev->dev, "ray_cs ray_attach calling ether_setup.)\n");
353         netif_stop_queue(dev);
354
355         init_timer(&local->timer);
356
357         this_device = p_dev;
358         return ray_config(p_dev);
359
360 fail_alloc_dev:
361         return -ENOMEM;
362 } /* ray_attach */
363
364 /*=============================================================================
365     This deletes a driver "instance".  The device is de-registered
366     with Card Services.  If it has been released, all local data
367     structures are freed.  Otherwise, the structures will be freed
368     when the device is released.
369 =============================================================================*/
370 static void ray_detach(struct pcmcia_device *link)
371 {
372         struct net_device *dev;
373         ray_dev_t *local;
374
375         dev_dbg(&link->dev, "ray_detach\n");
376
377         this_device = NULL;
378         dev = link->priv;
379
380         ray_release(link);
381
382         local = netdev_priv(dev);
383         del_timer(&local->timer);
384
385         if (link->priv) {
386                 if (link->dev_node)
387                         unregister_netdev(dev);
388                 free_netdev(dev);
389         }
390         dev_dbg(&link->dev, "ray_cs ray_detach ending\n");
391 } /* ray_detach */
392
393 /*=============================================================================
394     ray_config() is run after a CARD_INSERTION event
395     is received, to configure the PCMCIA socket, and to make the
396     ethernet device available to the system.
397 =============================================================================*/
398 #define MAX_TUPLE_SIZE 128
399 static int ray_config(struct pcmcia_device *link)
400 {
401         int ret = 0;
402         int i;
403         win_req_t req;
404         memreq_t mem;
405         struct net_device *dev = (struct net_device *)link->priv;
406         ray_dev_t *local = netdev_priv(dev);
407
408         dev_dbg(&link->dev, "ray_config\n");
409
410         /* Determine card type and firmware version */
411         printk(KERN_INFO "ray_cs Detected: %s%s%s%s\n",
412                link->prod_id[0] ? link->prod_id[0] : " ",
413                link->prod_id[1] ? link->prod_id[1] : " ",
414                link->prod_id[2] ? link->prod_id[2] : " ",
415                link->prod_id[3] ? link->prod_id[3] : " ");
416
417         /* Now allocate an interrupt line.  Note that this does not
418            actually assign a handler to the interrupt.
419          */
420         ret = pcmcia_request_irq(link, &link->irq);
421         if (ret)
422                 goto failed;
423         dev->irq = link->irq.AssignedIRQ;
424
425         /* This actually configures the PCMCIA socket -- setting up
426            the I/O windows and the interrupt mapping.
427          */
428         ret = pcmcia_request_configuration(link, &link->conf);
429         if (ret)
430                 goto failed;
431
432 /*** Set up 32k window for shared memory (transmit and control) ************/
433         req.Attributes =
434             WIN_DATA_WIDTH_8 | WIN_MEMORY_TYPE_CM | WIN_ENABLE | WIN_USE_WAIT;
435         req.Base = 0;
436         req.Size = 0x8000;
437         req.AccessSpeed = ray_mem_speed;
438         ret = pcmcia_request_window(link, &req, &link->win);
439         if (ret)
440                 goto failed;
441         mem.CardOffset = 0x0000;
442         mem.Page = 0;
443         ret = pcmcia_map_mem_page(link, link->win, &mem);
444         if (ret)
445                 goto failed;
446         local->sram = ioremap(req.Base, req.Size);
447
448 /*** Set up 16k window for shared memory (receive buffer) ***************/
449         req.Attributes =
450             WIN_DATA_WIDTH_8 | WIN_MEMORY_TYPE_CM | WIN_ENABLE | WIN_USE_WAIT;
451         req.Base = 0;
452         req.Size = 0x4000;
453         req.AccessSpeed = ray_mem_speed;
454         ret = pcmcia_request_window(link, &req, &local->rmem_handle);
455         if (ret)
456                 goto failed;
457         mem.CardOffset = 0x8000;
458         mem.Page = 0;
459         ret = pcmcia_map_mem_page(link, local->rmem_handle, &mem);
460         if (ret)
461                 goto failed;
462         local->rmem = ioremap(req.Base, req.Size);
463
464 /*** Set up window for attribute memory ***********************************/
465         req.Attributes =
466             WIN_DATA_WIDTH_8 | WIN_MEMORY_TYPE_AM | WIN_ENABLE | WIN_USE_WAIT;
467         req.Base = 0;
468         req.Size = 0x1000;
469         req.AccessSpeed = ray_mem_speed;
470         ret = pcmcia_request_window(link, &req, &local->amem_handle);
471         if (ret)
472                 goto failed;
473         mem.CardOffset = 0x0000;
474         mem.Page = 0;
475         ret = pcmcia_map_mem_page(link, local->amem_handle, &mem);
476         if (ret)
477                 goto failed;
478         local->amem = ioremap(req.Base, req.Size);
479
480         dev_dbg(&link->dev, "ray_config sram=%p\n", local->sram);
481         dev_dbg(&link->dev, "ray_config rmem=%p\n", local->rmem);
482         dev_dbg(&link->dev, "ray_config amem=%p\n", local->amem);
483         if (ray_init(dev) < 0) {
484                 ray_release(link);
485                 return -ENODEV;
486         }
487
488         SET_NETDEV_DEV(dev, &link->dev);
489         i = register_netdev(dev);
490         if (i != 0) {
491                 printk("ray_config register_netdev() failed\n");
492                 ray_release(link);
493                 return i;
494         }
495
496         strcpy(local->node.dev_name, dev->name);
497         link->dev_node = &local->node;
498
499         printk(KERN_INFO "%s: RayLink, irq %d, hw_addr %pM\n",
500                dev->name, dev->irq, dev->dev_addr);
501
502         return 0;
503
504 failed:
505         ray_release(link);
506         return -ENODEV;
507 } /* ray_config */
508
509 static inline struct ccs __iomem *ccs_base(ray_dev_t *dev)
510 {
511         return dev->sram + CCS_BASE;
512 }
513
514 static inline struct rcs __iomem *rcs_base(ray_dev_t *dev)
515 {
516         /*
517          * This looks nonsensical, since there is a separate
518          * RCS_BASE. But the difference between a "struct rcs"
519          * and a "struct ccs" ends up being in the _index_ off
520          * the base, so the base pointer is the same for both
521          * ccs/rcs.
522          */
523         return dev->sram + CCS_BASE;
524 }
525
526 /*===========================================================================*/
527 static int ray_init(struct net_device *dev)
528 {
529         int i;
530         UCHAR *p;
531         struct ccs __iomem *pccs;
532         ray_dev_t *local = netdev_priv(dev);
533         struct pcmcia_device *link = local->finder;
534         dev_dbg(&link->dev, "ray_init(0x%p)\n", dev);
535         if (!(pcmcia_dev_present(link))) {
536                 dev_dbg(&link->dev, "ray_init - device not present\n");
537                 return -1;
538         }
539
540         local->net_type = net_type;
541         local->sta_type = TYPE_STA;
542
543         /* Copy the startup results to local memory */
544         memcpy_fromio(&local->startup_res, local->sram + ECF_TO_HOST_BASE,
545                       sizeof(struct startup_res_6));
546
547         /* Check Power up test status and get mac address from card */
548         if (local->startup_res.startup_word != 0x80) {
549                 printk(KERN_INFO "ray_init ERROR card status = %2x\n",
550                        local->startup_res.startup_word);
551                 local->card_status = CARD_INIT_ERROR;
552                 return -1;
553         }
554
555         local->fw_ver = local->startup_res.firmware_version[0];
556         local->fw_bld = local->startup_res.firmware_version[1];
557         local->fw_var = local->startup_res.firmware_version[2];
558         dev_dbg(&link->dev, "ray_init firmware version %d.%d\n", local->fw_ver,
559               local->fw_bld);
560
561         local->tib_length = 0x20;
562         if ((local->fw_ver == 5) && (local->fw_bld >= 30))
563                 local->tib_length = local->startup_res.tib_length;
564         dev_dbg(&link->dev, "ray_init tib_length = 0x%02x\n", local->tib_length);
565         /* Initialize CCS's to buffer free state */
566         pccs = ccs_base(local);
567         for (i = 0; i < NUMBER_OF_CCS; i++) {
568                 writeb(CCS_BUFFER_FREE, &(pccs++)->buffer_status);
569         }
570         init_startup_params(local);
571
572         /* copy mac address to startup parameters */
573         if (parse_addr(phy_addr, local->sparm.b4.a_mac_addr)) {
574                 p = local->sparm.b4.a_mac_addr;
575         } else {
576                 memcpy(&local->sparm.b4.a_mac_addr,
577                        &local->startup_res.station_addr, ADDRLEN);
578                 p = local->sparm.b4.a_mac_addr;
579         }
580
581         clear_interrupt(local); /* Clear any interrupt from the card */
582         local->card_status = CARD_AWAITING_PARAM;
583         dev_dbg(&link->dev, "ray_init ending\n");
584         return 0;
585 } /* ray_init */
586
587 /*===========================================================================*/
588 /* Download startup parameters to the card and command it to read them       */
589 static int dl_startup_params(struct net_device *dev)
590 {
591         int ccsindex;
592         ray_dev_t *local = netdev_priv(dev);
593         struct ccs __iomem *pccs;
594         struct pcmcia_device *link = local->finder;
595
596         dev_dbg(&link->dev, "dl_startup_params entered\n");
597         if (!(pcmcia_dev_present(link))) {
598                 dev_dbg(&link->dev, "ray_cs dl_startup_params - device not present\n");
599                 return -1;
600         }
601
602         /* Copy parameters to host to ECF area */
603         if (local->fw_ver == 0x55)
604                 memcpy_toio(local->sram + HOST_TO_ECF_BASE, &local->sparm.b4,
605                             sizeof(struct b4_startup_params));
606         else
607                 memcpy_toio(local->sram + HOST_TO_ECF_BASE, &local->sparm.b5,
608                             sizeof(struct b5_startup_params));
609
610         /* Fill in the CCS fields for the ECF */
611         if ((ccsindex = get_free_ccs(local)) < 0)
612                 return -1;
613         local->dl_param_ccs = ccsindex;
614         pccs = ccs_base(local) + ccsindex;
615         writeb(CCS_DOWNLOAD_STARTUP_PARAMS, &pccs->cmd);
616         dev_dbg(&link->dev, "dl_startup_params start ccsindex = %d\n",
617               local->dl_param_ccs);
618         /* Interrupt the firmware to process the command */
619         if (interrupt_ecf(local, ccsindex)) {
620                 printk(KERN_INFO "ray dl_startup_params failed - "
621                        "ECF not ready for intr\n");
622                 local->card_status = CARD_DL_PARAM_ERROR;
623                 writeb(CCS_BUFFER_FREE, &(pccs++)->buffer_status);
624                 return -2;
625         }
626         local->card_status = CARD_DL_PARAM;
627         /* Start kernel timer to wait for dl startup to complete. */
628         local->timer.expires = jiffies + HZ / 2;
629         local->timer.data = (long)local;
630         local->timer.function = &verify_dl_startup;
631         add_timer(&local->timer);
632         dev_dbg(&link->dev,
633               "ray_cs dl_startup_params started timer for verify_dl_startup\n");
634         return 0;
635 } /* dl_startup_params */
636
637 /*===========================================================================*/
638 static void init_startup_params(ray_dev_t *local)
639 {
640         int i;
641
642         if (country > JAPAN_TEST)
643                 country = USA;
644         else if (country < USA)
645                 country = USA;
646         /* structure for hop time and beacon period is defined here using
647          * New 802.11D6.1 format.  Card firmware is still using old format
648          * until version 6.
649          *    Before                    After
650          *    a_hop_time ms byte        a_hop_time ms byte
651          *    a_hop_time 2s byte        a_hop_time ls byte
652          *    a_hop_time ls byte        a_beacon_period ms byte
653          *    a_beacon_period           a_beacon_period ls byte
654          *
655          *    a_hop_time = uS           a_hop_time = KuS
656          *    a_beacon_period = hops    a_beacon_period = KuS
657          *//* 64ms = 010000 */
658         if (local->fw_ver == 0x55) {
659                 memcpy((UCHAR *) &local->sparm.b4, b4_default_startup_parms,
660                        sizeof(struct b4_startup_params));
661                 /* Translate sane kus input values to old build 4/5 format */
662                 /* i = hop time in uS truncated to 3 bytes */
663                 i = (hop_dwell * 1024) & 0xffffff;
664                 local->sparm.b4.a_hop_time[0] = (i >> 16) & 0xff;
665                 local->sparm.b4.a_hop_time[1] = (i >> 8) & 0xff;
666                 local->sparm.b4.a_beacon_period[0] = 0;
667                 local->sparm.b4.a_beacon_period[1] =
668                     ((beacon_period / hop_dwell) - 1) & 0xff;
669                 local->sparm.b4.a_curr_country_code = country;
670                 local->sparm.b4.a_hop_pattern_length =
671                     hop_pattern_length[(int)country] - 1;
672                 if (bc) {
673                         local->sparm.b4.a_ack_timeout = 0x50;
674                         local->sparm.b4.a_sifs = 0x3f;
675                 }
676         } else { /* Version 5 uses real kus values */
677                 memcpy((UCHAR *) &local->sparm.b5, b5_default_startup_parms,
678                        sizeof(struct b5_startup_params));
679
680                 local->sparm.b5.a_hop_time[0] = (hop_dwell >> 8) & 0xff;
681                 local->sparm.b5.a_hop_time[1] = hop_dwell & 0xff;
682                 local->sparm.b5.a_beacon_period[0] =
683                     (beacon_period >> 8) & 0xff;
684                 local->sparm.b5.a_beacon_period[1] = beacon_period & 0xff;
685                 if (psm)
686                         local->sparm.b5.a_power_mgt_state = 1;
687                 local->sparm.b5.a_curr_country_code = country;
688                 local->sparm.b5.a_hop_pattern_length =
689                     hop_pattern_length[(int)country];
690         }
691
692         local->sparm.b4.a_network_type = net_type & 0x01;
693         local->sparm.b4.a_acting_as_ap_status = TYPE_STA;
694
695         if (essid != NULL)
696                 strncpy(local->sparm.b4.a_current_ess_id, essid, ESSID_SIZE);
697 } /* init_startup_params */
698
699 /*===========================================================================*/
700 static void verify_dl_startup(u_long data)
701 {
702         ray_dev_t *local = (ray_dev_t *) data;
703         struct ccs __iomem *pccs = ccs_base(local) + local->dl_param_ccs;
704         UCHAR status;
705         struct pcmcia_device *link = local->finder;
706
707         if (!(pcmcia_dev_present(link))) {
708                 dev_dbg(&link->dev, "ray_cs verify_dl_startup - device not present\n");
709                 return;
710         }
711 #if 0
712         {
713                 int i;
714                 printk(KERN_DEBUG
715                        "verify_dl_startup parameters sent via ccs %d:\n",
716                        local->dl_param_ccs);
717                 for (i = 0; i < sizeof(struct b5_startup_params); i++) {
718                         printk(" %2x",
719                                (unsigned int)readb(local->sram +
720                                                    HOST_TO_ECF_BASE + i));
721                 }
722                 printk("\n");
723         }
724 #endif
725
726         status = readb(&pccs->buffer_status);
727         if (status != CCS_BUFFER_FREE) {
728                 printk(KERN_INFO
729                        "Download startup params failed.  Status = %d\n",
730                        status);
731                 local->card_status = CARD_DL_PARAM_ERROR;
732                 return;
733         }
734         if (local->sparm.b4.a_network_type == ADHOC)
735                 start_net((u_long) local);
736         else
737                 join_net((u_long) local);
738 } /* end verify_dl_startup */
739
740 /*===========================================================================*/
741 /* Command card to start a network */
742 static void start_net(u_long data)
743 {
744         ray_dev_t *local = (ray_dev_t *) data;
745         struct ccs __iomem *pccs;
746         int ccsindex;
747         struct pcmcia_device *link = local->finder;
748         if (!(pcmcia_dev_present(link))) {
749                 dev_dbg(&link->dev, "ray_cs start_net - device not present\n");
750                 return;
751         }
752         /* Fill in the CCS fields for the ECF */
753         if ((ccsindex = get_free_ccs(local)) < 0)
754                 return;
755         pccs = ccs_base(local) + ccsindex;
756         writeb(CCS_START_NETWORK, &pccs->cmd);
757         writeb(0, &pccs->var.start_network.update_param);
758         /* Interrupt the firmware to process the command */
759         if (interrupt_ecf(local, ccsindex)) {
760                 dev_dbg(&link->dev, "ray start net failed - card not ready for intr\n");
761                 writeb(CCS_BUFFER_FREE, &(pccs++)->buffer_status);
762                 return;
763         }
764         local->card_status = CARD_DOING_ACQ;
765 } /* end start_net */
766
767 /*===========================================================================*/
768 /* Command card to join a network */
769 static void join_net(u_long data)
770 {
771         ray_dev_t *local = (ray_dev_t *) data;
772
773         struct ccs __iomem *pccs;
774         int ccsindex;
775         struct pcmcia_device *link = local->finder;
776
777         if (!(pcmcia_dev_present(link))) {
778                 dev_dbg(&link->dev, "ray_cs join_net - device not present\n");
779                 return;
780         }
781         /* Fill in the CCS fields for the ECF */
782         if ((ccsindex = get_free_ccs(local)) < 0)
783                 return;
784         pccs = ccs_base(local) + ccsindex;
785         writeb(CCS_JOIN_NETWORK, &pccs->cmd);
786         writeb(0, &pccs->var.join_network.update_param);
787         writeb(0, &pccs->var.join_network.net_initiated);
788         /* Interrupt the firmware to process the command */
789         if (interrupt_ecf(local, ccsindex)) {
790                 dev_dbg(&link->dev, "ray join net failed - card not ready for intr\n");
791                 writeb(CCS_BUFFER_FREE, &(pccs++)->buffer_status);
792                 return;
793         }
794         local->card_status = CARD_DOING_ACQ;
795 }
796
797 /*============================================================================
798     After a card is removed, ray_release() will unregister the net
799     device, and release the PCMCIA configuration.  If the device is
800     still open, this will be postponed until it is closed.
801 =============================================================================*/
802 static void ray_release(struct pcmcia_device *link)
803 {
804         struct net_device *dev = link->priv;
805         ray_dev_t *local = netdev_priv(dev);
806         int i;
807
808         dev_dbg(&link->dev, "ray_release\n");
809
810         del_timer(&local->timer);
811
812         iounmap(local->sram);
813         iounmap(local->rmem);
814         iounmap(local->amem);
815         /* Do bother checking to see if these succeed or not */
816         i = pcmcia_release_window(link, local->amem_handle);
817         if (i != 0)
818                 dev_dbg(&link->dev, "ReleaseWindow(local->amem) ret = %x\n", i);
819         i = pcmcia_release_window(link, local->rmem_handle);
820         if (i != 0)
821                 dev_dbg(&link->dev, "ReleaseWindow(local->rmem) ret = %x\n", i);
822         pcmcia_disable_device(link);
823
824         dev_dbg(&link->dev, "ray_release ending\n");
825 }
826
827 static int ray_suspend(struct pcmcia_device *link)
828 {
829         struct net_device *dev = link->priv;
830
831         if (link->open)
832                 netif_device_detach(dev);
833
834         return 0;
835 }
836
837 static int ray_resume(struct pcmcia_device *link)
838 {
839         struct net_device *dev = link->priv;
840
841         if (link->open) {
842                 ray_reset(dev);
843                 netif_device_attach(dev);
844         }
845
846         return 0;
847 }
848
849 /*===========================================================================*/
850 static int ray_dev_init(struct net_device *dev)
851 {
852 #ifdef RAY_IMMEDIATE_INIT
853         int i;
854 #endif /* RAY_IMMEDIATE_INIT */
855         ray_dev_t *local = netdev_priv(dev);
856         struct pcmcia_device *link = local->finder;
857
858         dev_dbg(&link->dev, "ray_dev_init(dev=%p)\n", dev);
859         if (!(pcmcia_dev_present(link))) {
860                 dev_dbg(&link->dev, "ray_dev_init - device not present\n");
861                 return -1;
862         }
863 #ifdef RAY_IMMEDIATE_INIT
864         /* Download startup parameters */
865         if ((i = dl_startup_params(dev)) < 0) {
866                 printk(KERN_INFO "ray_dev_init dl_startup_params failed - "
867                        "returns 0x%x\n", i);
868                 return -1;
869         }
870 #else /* RAY_IMMEDIATE_INIT */
871         /* Postpone the card init so that we can still configure the card,
872          * for example using the Wireless Extensions. The init will happen
873          * in ray_open() - Jean II */
874         dev_dbg(&link->dev,
875               "ray_dev_init: postponing card init to ray_open() ; Status = %d\n",
876               local->card_status);
877 #endif /* RAY_IMMEDIATE_INIT */
878
879         /* copy mac and broadcast addresses to linux device */
880         memcpy(dev->dev_addr, &local->sparm.b4.a_mac_addr, ADDRLEN);
881         memset(dev->broadcast, 0xff, ETH_ALEN);
882
883         dev_dbg(&link->dev, "ray_dev_init ending\n");
884         return 0;
885 }
886
887 /*===========================================================================*/
888 static int ray_dev_config(struct net_device *dev, struct ifmap *map)
889 {
890         ray_dev_t *local = netdev_priv(dev);
891         struct pcmcia_device *link = local->finder;
892         /* Dummy routine to satisfy device structure */
893         dev_dbg(&link->dev, "ray_dev_config(dev=%p,ifmap=%p)\n", dev, map);
894         if (!(pcmcia_dev_present(link))) {
895                 dev_dbg(&link->dev, "ray_dev_config - device not present\n");
896                 return -1;
897         }
898
899         return 0;
900 }
901
902 /*===========================================================================*/
903 static netdev_tx_t ray_dev_start_xmit(struct sk_buff *skb,
904                                             struct net_device *dev)
905 {
906         ray_dev_t *local = netdev_priv(dev);
907         struct pcmcia_device *link = local->finder;
908         short length = skb->len;
909
910         if (!pcmcia_dev_present(link)) {
911                 dev_dbg(&link->dev, "ray_dev_start_xmit - device not present\n");
912                 dev_kfree_skb(skb);
913                 return NETDEV_TX_OK;
914         }
915
916         dev_dbg(&link->dev, "ray_dev_start_xmit(skb=%p, dev=%p)\n", skb, dev);
917         if (local->authentication_state == NEED_TO_AUTH) {
918                 dev_dbg(&link->dev, "ray_cs Sending authentication request.\n");
919                 if (!build_auth_frame(local, local->auth_id, OPEN_AUTH_REQUEST)) {
920                         local->authentication_state = AUTHENTICATED;
921                         netif_stop_queue(dev);
922                         return NETDEV_TX_BUSY;
923                 }
924         }
925
926         if (length < ETH_ZLEN) {
927                 if (skb_padto(skb, ETH_ZLEN))
928                         return NETDEV_TX_OK;
929                 length = ETH_ZLEN;
930         }
931         switch (ray_hw_xmit(skb->data, length, dev, DATA_TYPE)) {
932         case XMIT_NO_CCS:
933         case XMIT_NEED_AUTH:
934                 netif_stop_queue(dev);
935                 return NETDEV_TX_BUSY;
936         case XMIT_NO_INTR:
937         case XMIT_MSG_BAD:
938         case XMIT_OK:
939         default:
940                 dev_kfree_skb(skb);
941         }
942
943         return NETDEV_TX_OK;
944 } /* ray_dev_start_xmit */
945
946 /*===========================================================================*/
947 static int ray_hw_xmit(unsigned char *data, int len, struct net_device *dev,
948                        UCHAR msg_type)
949 {
950         ray_dev_t *local = netdev_priv(dev);
951         struct ccs __iomem *pccs;
952         int ccsindex;
953         int offset;
954         struct tx_msg __iomem *ptx;     /* Address of xmit buffer in PC space */
955         short int addr;         /* Address of xmit buffer in card space */
956
957         pr_debug("ray_hw_xmit(data=%p, len=%d, dev=%p)\n", data, len, dev);
958         if (len + TX_HEADER_LENGTH > TX_BUF_SIZE) {
959                 printk(KERN_INFO "ray_hw_xmit packet too large: %d bytes\n",
960                        len);
961                 return XMIT_MSG_BAD;
962         }
963         switch (ccsindex = get_free_tx_ccs(local)) {
964         case ECCSBUSY:
965                 pr_debug("ray_hw_xmit tx_ccs table busy\n");
966         case ECCSFULL:
967                 pr_debug("ray_hw_xmit No free tx ccs\n");
968         case ECARDGONE:
969                 netif_stop_queue(dev);
970                 return XMIT_NO_CCS;
971         default:
972                 break;
973         }
974         addr = TX_BUF_BASE + (ccsindex << 11);
975
976         if (msg_type == DATA_TYPE) {
977                 local->stats.tx_bytes += len;
978                 local->stats.tx_packets++;
979         }
980
981         ptx = local->sram + addr;
982
983         ray_build_header(local, ptx, msg_type, data);
984         if (translate) {
985                 offset = translate_frame(local, ptx, data, len);
986         } else { /* Encapsulate frame */
987                 /* TBD TIB length will move address of ptx->var */
988                 memcpy_toio(&ptx->var, data, len);
989                 offset = 0;
990         }
991
992         /* fill in the CCS */
993         pccs = ccs_base(local) + ccsindex;
994         len += TX_HEADER_LENGTH + offset;
995         writeb(CCS_TX_REQUEST, &pccs->cmd);
996         writeb(addr >> 8, &pccs->var.tx_request.tx_data_ptr[0]);
997         writeb(local->tib_length, &pccs->var.tx_request.tx_data_ptr[1]);
998         writeb(len >> 8, &pccs->var.tx_request.tx_data_length[0]);
999         writeb(len & 0xff, &pccs->var.tx_request.tx_data_length[1]);
1000 /* TBD still need psm_cam? */
1001         writeb(PSM_CAM, &pccs->var.tx_request.pow_sav_mode);
1002         writeb(local->net_default_tx_rate, &pccs->var.tx_request.tx_rate);
1003         writeb(0, &pccs->var.tx_request.antenna);
1004         pr_debug("ray_hw_xmit default_tx_rate = 0x%x\n",
1005               local->net_default_tx_rate);
1006
1007         /* Interrupt the firmware to process the command */
1008         if (interrupt_ecf(local, ccsindex)) {
1009                 pr_debug("ray_hw_xmit failed - ECF not ready for intr\n");
1010 /* TBD very inefficient to copy packet to buffer, and then not
1011    send it, but the alternative is to queue the messages and that
1012    won't be done for a while.  Maybe set tbusy until a CCS is free?
1013 */
1014                 writeb(CCS_BUFFER_FREE, &pccs->buffer_status);
1015                 return XMIT_NO_INTR;
1016         }
1017         return XMIT_OK;
1018 } /* end ray_hw_xmit */
1019
1020 /*===========================================================================*/
1021 static int translate_frame(ray_dev_t *local, struct tx_msg __iomem *ptx,
1022                            unsigned char *data, int len)
1023 {
1024         __be16 proto = ((struct ethhdr *)data)->h_proto;
1025         if (ntohs(proto) >= 1536) { /* DIX II ethernet frame */
1026                 pr_debug("ray_cs translate_frame DIX II\n");
1027                 /* Copy LLC header to card buffer */
1028                 memcpy_toio(&ptx->var, eth2_llc, sizeof(eth2_llc));
1029                 memcpy_toio(((void __iomem *)&ptx->var) + sizeof(eth2_llc),
1030                             (UCHAR *) &proto, 2);
1031                 if (proto == htons(ETH_P_AARP) || proto == htons(ETH_P_IPX)) {
1032                         /* This is the selective translation table, only 2 entries */
1033                         writeb(0xf8,
1034                                &((struct snaphdr_t __iomem *)ptx->var)->org[3]);
1035                 }
1036                 /* Copy body of ethernet packet without ethernet header */
1037                 memcpy_toio((void __iomem *)&ptx->var +
1038                             sizeof(struct snaphdr_t), data + ETH_HLEN,
1039                             len - ETH_HLEN);
1040                 return (int)sizeof(struct snaphdr_t) - ETH_HLEN;
1041         } else { /* already  802 type, and proto is length */
1042                 pr_debug("ray_cs translate_frame 802\n");
1043                 if (proto == htons(0xffff)) { /* evil netware IPX 802.3 without LLC */
1044                         pr_debug("ray_cs translate_frame evil IPX\n");
1045                         memcpy_toio(&ptx->var, data + ETH_HLEN, len - ETH_HLEN);
1046                         return 0 - ETH_HLEN;
1047                 }
1048                 memcpy_toio(&ptx->var, data + ETH_HLEN, len - ETH_HLEN);
1049                 return 0 - ETH_HLEN;
1050         }
1051         /* TBD do other frame types */
1052 } /* end translate_frame */
1053
1054 /*===========================================================================*/
1055 static void ray_build_header(ray_dev_t *local, struct tx_msg __iomem *ptx,
1056                              UCHAR msg_type, unsigned char *data)
1057 {
1058         writeb(PROTOCOL_VER | msg_type, &ptx->mac.frame_ctl_1);
1059 /*** IEEE 802.11 Address field assignments *************
1060                 TODS    FROMDS  addr_1          addr_2          addr_3  addr_4
1061 Adhoc           0       0       dest            src (terminal)  BSSID   N/A
1062 AP to Terminal  0       1       dest            AP(BSSID)       source  N/A
1063 Terminal to AP  1       0       AP(BSSID)       src (terminal)  dest    N/A
1064 AP to AP        1       1       dest AP         src AP          dest    source
1065 *******************************************************/
1066         if (local->net_type == ADHOC) {
1067                 writeb(0, &ptx->mac.frame_ctl_2);
1068                 memcpy_toio(ptx->mac.addr_1, ((struct ethhdr *)data)->h_dest,
1069                             2 * ADDRLEN);
1070                 memcpy_toio(ptx->mac.addr_3, local->bss_id, ADDRLEN);
1071         } else { /* infrastructure */
1072
1073                 if (local->sparm.b4.a_acting_as_ap_status) {
1074                         writeb(FC2_FROM_DS, &ptx->mac.frame_ctl_2);
1075                         memcpy_toio(ptx->mac.addr_1,
1076                                     ((struct ethhdr *)data)->h_dest, ADDRLEN);
1077                         memcpy_toio(ptx->mac.addr_2, local->bss_id, 6);
1078                         memcpy_toio(ptx->mac.addr_3,
1079                                     ((struct ethhdr *)data)->h_source, ADDRLEN);
1080                 } else { /* Terminal */
1081
1082                         writeb(FC2_TO_DS, &ptx->mac.frame_ctl_2);
1083                         memcpy_toio(ptx->mac.addr_1, local->bss_id, ADDRLEN);
1084                         memcpy_toio(ptx->mac.addr_2,
1085                                     ((struct ethhdr *)data)->h_source, ADDRLEN);
1086                         memcpy_toio(ptx->mac.addr_3,
1087                                     ((struct ethhdr *)data)->h_dest, ADDRLEN);
1088                 }
1089         }
1090 } /* end encapsulate_frame */
1091
1092 /*===========================================================================*/
1093
1094 static void netdev_get_drvinfo(struct net_device *dev,
1095                                struct ethtool_drvinfo *info)
1096 {
1097         strcpy(info->driver, "ray_cs");
1098 }
1099
1100 static const struct ethtool_ops netdev_ethtool_ops = {
1101         .get_drvinfo = netdev_get_drvinfo,
1102 };
1103
1104 /*====================================================================*/
1105
1106 /*------------------------------------------------------------------*/
1107 /*
1108  * Wireless Handler : get protocol name
1109  */
1110 static int ray_get_name(struct net_device *dev, struct iw_request_info *info,
1111                         union iwreq_data *wrqu, char *extra)
1112 {
1113         strcpy(wrqu->name, "IEEE 802.11-FH");
1114         return 0;
1115 }
1116
1117 /*------------------------------------------------------------------*/
1118 /*
1119  * Wireless Handler : set frequency
1120  */
1121 static int ray_set_freq(struct net_device *dev, struct iw_request_info *info,
1122                         union iwreq_data *wrqu, char *extra)
1123 {
1124         ray_dev_t *local = netdev_priv(dev);
1125         int err = -EINPROGRESS; /* Call commit handler */
1126
1127         /* Reject if card is already initialised */
1128         if (local->card_status != CARD_AWAITING_PARAM)
1129                 return -EBUSY;
1130
1131         /* Setting by channel number */
1132         if ((wrqu->freq.m > USA_HOP_MOD) || (wrqu->freq.e > 0))
1133                 err = -EOPNOTSUPP;
1134         else
1135                 local->sparm.b5.a_hop_pattern = wrqu->freq.m;
1136
1137         return err;
1138 }
1139
1140 /*------------------------------------------------------------------*/
1141 /*
1142  * Wireless Handler : get frequency
1143  */
1144 static int ray_get_freq(struct net_device *dev, struct iw_request_info *info,
1145                         union iwreq_data *wrqu, char *extra)
1146 {
1147         ray_dev_t *local = netdev_priv(dev);
1148
1149         wrqu->freq.m = local->sparm.b5.a_hop_pattern;
1150         wrqu->freq.e = 0;
1151         return 0;
1152 }
1153
1154 /*------------------------------------------------------------------*/
1155 /*
1156  * Wireless Handler : set ESSID
1157  */
1158 static int ray_set_essid(struct net_device *dev, struct iw_request_info *info,
1159                          union iwreq_data *wrqu, char *extra)
1160 {
1161         ray_dev_t *local = netdev_priv(dev);
1162
1163         /* Reject if card is already initialised */
1164         if (local->card_status != CARD_AWAITING_PARAM)
1165                 return -EBUSY;
1166
1167         /* Check if we asked for `any' */
1168         if (wrqu->essid.flags == 0)
1169                 /* Corey : can you do that ? */
1170                 return -EOPNOTSUPP;
1171
1172         /* Check the size of the string */
1173         if (wrqu->essid.length > IW_ESSID_MAX_SIZE)
1174                 return -E2BIG;
1175
1176         /* Set the ESSID in the card */
1177         memset(local->sparm.b5.a_current_ess_id, 0, IW_ESSID_MAX_SIZE);
1178         memcpy(local->sparm.b5.a_current_ess_id, extra, wrqu->essid.length);
1179
1180         return -EINPROGRESS;    /* Call commit handler */
1181 }
1182
1183 /*------------------------------------------------------------------*/
1184 /*
1185  * Wireless Handler : get ESSID
1186  */
1187 static int ray_get_essid(struct net_device *dev, struct iw_request_info *info,
1188                          union iwreq_data *wrqu, char *extra)
1189 {
1190         ray_dev_t *local = netdev_priv(dev);
1191
1192         /* Get the essid that was set */
1193         memcpy(extra, local->sparm.b5.a_current_ess_id, IW_ESSID_MAX_SIZE);
1194
1195         /* Push it out ! */
1196         wrqu->essid.length = strlen(extra);
1197         wrqu->essid.flags = 1;  /* active */
1198
1199         return 0;
1200 }
1201
1202 /*------------------------------------------------------------------*/
1203 /*
1204  * Wireless Handler : get AP address
1205  */
1206 static int ray_get_wap(struct net_device *dev, struct iw_request_info *info,
1207                        union iwreq_data *wrqu, char *extra)
1208 {
1209         ray_dev_t *local = netdev_priv(dev);
1210
1211         memcpy(wrqu->ap_addr.sa_data, local->bss_id, ETH_ALEN);
1212         wrqu->ap_addr.sa_family = ARPHRD_ETHER;
1213
1214         return 0;
1215 }
1216
1217 /*------------------------------------------------------------------*/
1218 /*
1219  * Wireless Handler : set Bit-Rate
1220  */
1221 static int ray_set_rate(struct net_device *dev, struct iw_request_info *info,
1222                         union iwreq_data *wrqu, char *extra)
1223 {
1224         ray_dev_t *local = netdev_priv(dev);
1225
1226         /* Reject if card is already initialised */
1227         if (local->card_status != CARD_AWAITING_PARAM)
1228                 return -EBUSY;
1229
1230         /* Check if rate is in range */
1231         if ((wrqu->bitrate.value != 1000000) && (wrqu->bitrate.value != 2000000))
1232                 return -EINVAL;
1233
1234         /* Hack for 1.5 Mb/s instead of 2 Mb/s */
1235         if ((local->fw_ver == 0x55) &&  /* Please check */
1236             (wrqu->bitrate.value == 2000000))
1237                 local->net_default_tx_rate = 3;
1238         else
1239                 local->net_default_tx_rate = wrqu->bitrate.value / 500000;
1240
1241         return 0;
1242 }
1243
1244 /*------------------------------------------------------------------*/
1245 /*
1246  * Wireless Handler : get Bit-Rate
1247  */
1248 static int ray_get_rate(struct net_device *dev, struct iw_request_info *info,
1249                         union iwreq_data *wrqu, char *extra)
1250 {
1251         ray_dev_t *local = netdev_priv(dev);
1252
1253         if (local->net_default_tx_rate == 3)
1254                 wrqu->bitrate.value = 2000000;  /* Hum... */
1255         else
1256                 wrqu->bitrate.value = local->net_default_tx_rate * 500000;
1257         wrqu->bitrate.fixed = 0;        /* We are in auto mode */
1258
1259         return 0;
1260 }
1261
1262 /*------------------------------------------------------------------*/
1263 /*
1264  * Wireless Handler : set RTS threshold
1265  */
1266 static int ray_set_rts(struct net_device *dev, struct iw_request_info *info,
1267                        union iwreq_data *wrqu, char *extra)
1268 {
1269         ray_dev_t *local = netdev_priv(dev);
1270         int rthr = wrqu->rts.value;
1271
1272         /* Reject if card is already initialised */
1273         if (local->card_status != CARD_AWAITING_PARAM)
1274                 return -EBUSY;
1275
1276         /* if(wrq->u.rts.fixed == 0) we should complain */
1277         if (wrqu->rts.disabled)
1278                 rthr = 32767;
1279         else {
1280                 if ((rthr < 0) || (rthr > 2347))   /* What's the max packet size ??? */
1281                         return -EINVAL;
1282         }
1283         local->sparm.b5.a_rts_threshold[0] = (rthr >> 8) & 0xFF;
1284         local->sparm.b5.a_rts_threshold[1] = rthr & 0xFF;
1285
1286         return -EINPROGRESS;    /* Call commit handler */
1287 }
1288
1289 /*------------------------------------------------------------------*/
1290 /*
1291  * Wireless Handler : get RTS threshold
1292  */
1293 static int ray_get_rts(struct net_device *dev, struct iw_request_info *info,
1294                        union iwreq_data *wrqu, char *extra)
1295 {
1296         ray_dev_t *local = netdev_priv(dev);
1297
1298         wrqu->rts.value = (local->sparm.b5.a_rts_threshold[0] << 8)
1299             + local->sparm.b5.a_rts_threshold[1];
1300         wrqu->rts.disabled = (wrqu->rts.value == 32767);
1301         wrqu->rts.fixed = 1;
1302
1303         return 0;
1304 }
1305
1306 /*------------------------------------------------------------------*/
1307 /*
1308  * Wireless Handler : set Fragmentation threshold
1309  */
1310 static int ray_set_frag(struct net_device *dev, struct iw_request_info *info,
1311                         union iwreq_data *wrqu, char *extra)
1312 {
1313         ray_dev_t *local = netdev_priv(dev);
1314         int fthr = wrqu->frag.value;
1315
1316         /* Reject if card is already initialised */
1317         if (local->card_status != CARD_AWAITING_PARAM)
1318                 return -EBUSY;
1319
1320         /* if(wrq->u.frag.fixed == 0) should complain */
1321         if (wrqu->frag.disabled)
1322                 fthr = 32767;
1323         else {
1324                 if ((fthr < 256) || (fthr > 2347))      /* To check out ! */
1325                         return -EINVAL;
1326         }
1327         local->sparm.b5.a_frag_threshold[0] = (fthr >> 8) & 0xFF;
1328         local->sparm.b5.a_frag_threshold[1] = fthr & 0xFF;
1329
1330         return -EINPROGRESS;    /* Call commit handler */
1331 }
1332
1333 /*------------------------------------------------------------------*/
1334 /*
1335  * Wireless Handler : get Fragmentation threshold
1336  */
1337 static int ray_get_frag(struct net_device *dev, struct iw_request_info *info,
1338                         union iwreq_data *wrqu, char *extra)
1339 {
1340         ray_dev_t *local = netdev_priv(dev);
1341
1342         wrqu->frag.value = (local->sparm.b5.a_frag_threshold[0] << 8)
1343             + local->sparm.b5.a_frag_threshold[1];
1344         wrqu->frag.disabled = (wrqu->frag.value == 32767);
1345         wrqu->frag.fixed = 1;
1346
1347         return 0;
1348 }
1349
1350 /*------------------------------------------------------------------*/
1351 /*
1352  * Wireless Handler : set Mode of Operation
1353  */
1354 static int ray_set_mode(struct net_device *dev, struct iw_request_info *info,
1355                         union iwreq_data *wrqu, char *extra)
1356 {
1357         ray_dev_t *local = netdev_priv(dev);
1358         int err = -EINPROGRESS; /* Call commit handler */
1359         char card_mode = 1;
1360
1361         /* Reject if card is already initialised */
1362         if (local->card_status != CARD_AWAITING_PARAM)
1363                 return -EBUSY;
1364
1365         switch (wrqu->mode) {
1366         case IW_MODE_ADHOC:
1367                 card_mode = 0;
1368                 /* Fall through */
1369         case IW_MODE_INFRA:
1370                 local->sparm.b5.a_network_type = card_mode;
1371                 break;
1372         default:
1373                 err = -EINVAL;
1374         }
1375
1376         return err;
1377 }
1378
1379 /*------------------------------------------------------------------*/
1380 /*
1381  * Wireless Handler : get Mode of Operation
1382  */
1383 static int ray_get_mode(struct net_device *dev, struct iw_request_info *info,
1384                         union iwreq_data *wrqu, char *extra)
1385 {
1386         ray_dev_t *local = netdev_priv(dev);
1387
1388         if (local->sparm.b5.a_network_type)
1389                 wrqu->mode = IW_MODE_INFRA;
1390         else
1391                 wrqu->mode = IW_MODE_ADHOC;
1392
1393         return 0;
1394 }
1395
1396 /*------------------------------------------------------------------*/
1397 /*
1398  * Wireless Handler : get range info
1399  */
1400 static int ray_get_range(struct net_device *dev, struct iw_request_info *info,
1401                          union iwreq_data *wrqu, char *extra)
1402 {
1403         struct iw_range *range = (struct iw_range *)extra;
1404
1405         memset(range, 0, sizeof(struct iw_range));
1406
1407         /* Set the length (very important for backward compatibility) */
1408         wrqu->data.length = sizeof(struct iw_range);
1409
1410         /* Set the Wireless Extension versions */
1411         range->we_version_compiled = WIRELESS_EXT;
1412         range->we_version_source = 9;
1413
1414         /* Set information in the range struct */
1415         range->throughput = 1.1 * 1000 * 1000;  /* Put the right number here */
1416         range->num_channels = hop_pattern_length[(int)country];
1417         range->num_frequency = 0;
1418         range->max_qual.qual = 0;
1419         range->max_qual.level = 255;    /* What's the correct value ? */
1420         range->max_qual.noise = 255;    /* Idem */
1421         range->num_bitrates = 2;
1422         range->bitrate[0] = 1000000;    /* 1 Mb/s */
1423         range->bitrate[1] = 2000000;    /* 2 Mb/s */
1424         return 0;
1425 }
1426
1427 /*------------------------------------------------------------------*/
1428 /*
1429  * Wireless Private Handler : set framing mode
1430  */
1431 static int ray_set_framing(struct net_device *dev, struct iw_request_info *info,
1432                            union iwreq_data *wrqu, char *extra)
1433 {
1434         translate = *(extra);   /* Set framing mode */
1435
1436         return 0;
1437 }
1438
1439 /*------------------------------------------------------------------*/
1440 /*
1441  * Wireless Private Handler : get framing mode
1442  */
1443 static int ray_get_framing(struct net_device *dev, struct iw_request_info *info,
1444                            union iwreq_data *wrqu, char *extra)
1445 {
1446         *(extra) = translate;
1447
1448         return 0;
1449 }
1450
1451 /*------------------------------------------------------------------*/
1452 /*
1453  * Wireless Private Handler : get country
1454  */
1455 static int ray_get_country(struct net_device *dev, struct iw_request_info *info,
1456                            union iwreq_data *wrqu, char *extra)
1457 {
1458         *(extra) = country;
1459
1460         return 0;
1461 }
1462
1463 /*------------------------------------------------------------------*/
1464 /*
1465  * Commit handler : called after a bunch of SET operations
1466  */
1467 static int ray_commit(struct net_device *dev, struct iw_request_info *info,
1468                       union iwreq_data *wrqu, char *extra)
1469 {
1470         return 0;
1471 }
1472
1473 /*------------------------------------------------------------------*/
1474 /*
1475  * Stats handler : return Wireless Stats
1476  */
1477 static iw_stats *ray_get_wireless_stats(struct net_device *dev)
1478 {
1479         ray_dev_t *local = netdev_priv(dev);
1480         struct pcmcia_device *link = local->finder;
1481         struct status __iomem *p = local->sram + STATUS_BASE;
1482
1483         local->wstats.status = local->card_status;
1484 #ifdef WIRELESS_SPY
1485         if ((local->spy_data.spy_number > 0)
1486             && (local->sparm.b5.a_network_type == 0)) {
1487                 /* Get it from the first node in spy list */
1488                 local->wstats.qual.qual = local->spy_data.spy_stat[0].qual;
1489                 local->wstats.qual.level = local->spy_data.spy_stat[0].level;
1490                 local->wstats.qual.noise = local->spy_data.spy_stat[0].noise;
1491                 local->wstats.qual.updated =
1492                     local->spy_data.spy_stat[0].updated;
1493         }
1494 #endif /* WIRELESS_SPY */
1495
1496         if (pcmcia_dev_present(link)) {
1497                 local->wstats.qual.noise = readb(&p->rxnoise);
1498                 local->wstats.qual.updated |= 4;
1499         }
1500
1501         return &local->wstats;
1502 } /* end ray_get_wireless_stats */
1503
1504 /*------------------------------------------------------------------*/
1505 /*
1506  * Structures to export the Wireless Handlers
1507  */
1508
1509 static const iw_handler ray_handler[] = {
1510         IW_HANDLER(SIOCSIWCOMMIT, ray_commit),
1511         IW_HANDLER(SIOCGIWNAME, ray_get_name),
1512         IW_HANDLER(SIOCSIWFREQ, ray_set_freq),
1513         IW_HANDLER(SIOCGIWFREQ, ray_get_freq),
1514         IW_HANDLER(SIOCSIWMODE, ray_set_mode),
1515         IW_HANDLER(SIOCGIWMODE, ray_get_mode),
1516         IW_HANDLER(SIOCGIWRANGE, ray_get_range),
1517 #ifdef WIRELESS_SPY
1518         IW_HANDLER(SIOCSIWSPY, iw_handler_set_spy),
1519         IW_HANDLER(SIOCGIWSPY, iw_handler_get_spy),
1520         IW_HANDLER(SIOCSIWTHRSPY, iw_handler_set_thrspy),
1521         IW_HANDLER(SIOCGIWTHRSPY, iw_handler_get_thrspy),
1522 #endif /* WIRELESS_SPY */
1523         IW_HANDLER(SIOCGIWAP, ray_get_wap),
1524         IW_HANDLER(SIOCSIWESSID, ray_set_essid),
1525         IW_HANDLER(SIOCGIWESSID, ray_get_essid),
1526         IW_HANDLER(SIOCSIWRATE, ray_set_rate),
1527         IW_HANDLER(SIOCGIWRATE, ray_get_rate),
1528         IW_HANDLER(SIOCSIWRTS, ray_set_rts),
1529         IW_HANDLER(SIOCGIWRTS, ray_get_rts),
1530         IW_HANDLER(SIOCSIWFRAG, ray_set_frag),
1531         IW_HANDLER(SIOCGIWFRAG, ray_get_frag),
1532 };
1533
1534 #define SIOCSIPFRAMING  SIOCIWFIRSTPRIV /* Set framing mode */
1535 #define SIOCGIPFRAMING  SIOCIWFIRSTPRIV + 1     /* Get framing mode */
1536 #define SIOCGIPCOUNTRY  SIOCIWFIRSTPRIV + 3     /* Get country code */
1537
1538 static const iw_handler ray_private_handler[] = {
1539         [0] = ray_set_framing,
1540         [1] = ray_get_framing,
1541         [3] = ray_get_country,
1542 };
1543
1544 static const struct iw_priv_args ray_private_args[] = {
1545 /* cmd,         set_args,       get_args,       name */
1546         {SIOCSIPFRAMING, IW_PRIV_TYPE_BYTE | IW_PRIV_SIZE_FIXED | 1, 0,
1547          "set_framing"},
1548         {SIOCGIPFRAMING, 0, IW_PRIV_TYPE_BYTE | IW_PRIV_SIZE_FIXED | 1,
1549          "get_framing"},
1550         {SIOCGIPCOUNTRY, 0, IW_PRIV_TYPE_BYTE | IW_PRIV_SIZE_FIXED | 1,
1551          "get_country"},
1552 };
1553
1554 static const struct iw_handler_def ray_handler_def = {
1555         .num_standard = ARRAY_SIZE(ray_handler),
1556         .num_private = ARRAY_SIZE(ray_private_handler),
1557         .num_private_args = ARRAY_SIZE(ray_private_args),
1558         .standard = ray_handler,
1559         .private = ray_private_handler,
1560         .private_args = ray_private_args,
1561         .get_wireless_stats = ray_get_wireless_stats,
1562 };
1563
1564 /*===========================================================================*/
1565 static int ray_open(struct net_device *dev)
1566 {
1567         ray_dev_t *local = netdev_priv(dev);
1568         struct pcmcia_device *link;
1569         link = local->finder;
1570
1571         dev_dbg(&link->dev, "ray_open('%s')\n", dev->name);
1572
1573         if (link->open == 0)
1574                 local->num_multi = 0;
1575         link->open++;
1576
1577         /* If the card is not started, time to start it ! - Jean II */
1578         if (local->card_status == CARD_AWAITING_PARAM) {
1579                 int i;
1580
1581                 dev_dbg(&link->dev, "ray_open: doing init now !\n");
1582
1583                 /* Download startup parameters */
1584                 if ((i = dl_startup_params(dev)) < 0) {
1585                         printk(KERN_INFO
1586                                "ray_dev_init dl_startup_params failed - "
1587                                "returns 0x%x\n", i);
1588                         return -1;
1589                 }
1590         }
1591
1592         if (sniffer)
1593                 netif_stop_queue(dev);
1594         else
1595                 netif_start_queue(dev);
1596
1597         dev_dbg(&link->dev, "ray_open ending\n");
1598         return 0;
1599 } /* end ray_open */
1600
1601 /*===========================================================================*/
1602 static int ray_dev_close(struct net_device *dev)
1603 {
1604         ray_dev_t *local = netdev_priv(dev);
1605         struct pcmcia_device *link;
1606         link = local->finder;
1607
1608         dev_dbg(&link->dev, "ray_dev_close('%s')\n", dev->name);
1609
1610         link->open--;
1611         netif_stop_queue(dev);
1612
1613         /* In here, we should stop the hardware (stop card from beeing active)
1614          * and set local->card_status to CARD_AWAITING_PARAM, so that while the
1615          * card is closed we can chage its configuration.
1616          * Probably also need a COR reset to get sane state - Jean II */
1617
1618         return 0;
1619 } /* end ray_dev_close */
1620
1621 /*===========================================================================*/
1622 static void ray_reset(struct net_device *dev)
1623 {
1624         pr_debug("ray_reset entered\n");
1625 }
1626
1627 /*===========================================================================*/
1628 /* Cause a firmware interrupt if it is ready for one                         */
1629 /* Return nonzero if not ready                                               */
1630 static int interrupt_ecf(ray_dev_t *local, int ccs)
1631 {
1632         int i = 50;
1633         struct pcmcia_device *link = local->finder;
1634
1635         if (!(pcmcia_dev_present(link))) {
1636                 dev_dbg(&link->dev, "ray_cs interrupt_ecf - device not present\n");
1637                 return -1;
1638         }
1639         dev_dbg(&link->dev, "interrupt_ecf(local=%p, ccs = 0x%x\n", local, ccs);
1640
1641         while (i &&
1642                (readb(local->amem + CIS_OFFSET + ECF_INTR_OFFSET) &
1643                 ECF_INTR_SET))
1644                 i--;
1645         if (i == 0) {
1646                 dev_dbg(&link->dev, "ray_cs interrupt_ecf card not ready for interrupt\n");
1647                 return -1;
1648         }
1649         /* Fill the mailbox, then kick the card */
1650         writeb(ccs, local->sram + SCB_BASE);
1651         writeb(ECF_INTR_SET, local->amem + CIS_OFFSET + ECF_INTR_OFFSET);
1652         return 0;
1653 } /* interrupt_ecf */
1654
1655 /*===========================================================================*/
1656 /* Get next free transmit CCS                                                */
1657 /* Return - index of current tx ccs                                          */
1658 static int get_free_tx_ccs(ray_dev_t *local)
1659 {
1660         int i;
1661         struct ccs __iomem *pccs = ccs_base(local);
1662         struct pcmcia_device *link = local->finder;
1663
1664         if (!(pcmcia_dev_present(link))) {
1665                 dev_dbg(&link->dev, "ray_cs get_free_tx_ccs - device not present\n");
1666                 return ECARDGONE;
1667         }
1668
1669         if (test_and_set_bit(0, &local->tx_ccs_lock)) {
1670                 dev_dbg(&link->dev, "ray_cs tx_ccs_lock busy\n");
1671                 return ECCSBUSY;
1672         }
1673
1674         for (i = 0; i < NUMBER_OF_TX_CCS; i++) {
1675                 if (readb(&(pccs + i)->buffer_status) == CCS_BUFFER_FREE) {
1676                         writeb(CCS_BUFFER_BUSY, &(pccs + i)->buffer_status);
1677                         writeb(CCS_END_LIST, &(pccs + i)->link);
1678                         local->tx_ccs_lock = 0;
1679                         return i;
1680                 }
1681         }
1682         local->tx_ccs_lock = 0;
1683         dev_dbg(&link->dev, "ray_cs ERROR no free tx CCS for raylink card\n");
1684         return ECCSFULL;
1685 } /* get_free_tx_ccs */
1686
1687 /*===========================================================================*/
1688 /* Get next free CCS                                                         */
1689 /* Return - index of current ccs                                             */
1690 static int get_free_ccs(ray_dev_t *local)
1691 {
1692         int i;
1693         struct ccs __iomem *pccs = ccs_base(local);
1694         struct pcmcia_device *link = local->finder;
1695
1696         if (!(pcmcia_dev_present(link))) {
1697                 dev_dbg(&link->dev, "ray_cs get_free_ccs - device not present\n");
1698                 return ECARDGONE;
1699         }
1700         if (test_and_set_bit(0, &local->ccs_lock)) {
1701                 dev_dbg(&link->dev, "ray_cs ccs_lock busy\n");
1702                 return ECCSBUSY;
1703         }
1704
1705         for (i = NUMBER_OF_TX_CCS; i < NUMBER_OF_CCS; i++) {
1706                 if (readb(&(pccs + i)->buffer_status) == CCS_BUFFER_FREE) {
1707                         writeb(CCS_BUFFER_BUSY, &(pccs + i)->buffer_status);
1708                         writeb(CCS_END_LIST, &(pccs + i)->link);
1709                         local->ccs_lock = 0;
1710                         return i;
1711                 }
1712         }
1713         local->ccs_lock = 0;
1714         dev_dbg(&link->dev, "ray_cs ERROR no free CCS for raylink card\n");
1715         return ECCSFULL;
1716 } /* get_free_ccs */
1717
1718 /*===========================================================================*/
1719 static void authenticate_timeout(u_long data)
1720 {
1721         ray_dev_t *local = (ray_dev_t *) data;
1722         del_timer(&local->timer);
1723         printk(KERN_INFO "ray_cs Authentication with access point failed"
1724                " - timeout\n");
1725         join_net((u_long) local);
1726 }
1727
1728 /*===========================================================================*/
1729 static int asc_to_int(char a)
1730 {
1731         if (a < '0')
1732                 return -1;
1733         if (a <= '9')
1734                 return (a - '0');
1735         if (a < 'A')
1736                 return -1;
1737         if (a <= 'F')
1738                 return (10 + a - 'A');
1739         if (a < 'a')
1740                 return -1;
1741         if (a <= 'f')
1742                 return (10 + a - 'a');
1743         return -1;
1744 }
1745
1746 /*===========================================================================*/
1747 static int parse_addr(char *in_str, UCHAR *out)
1748 {
1749         int len;
1750         int i, j, k;
1751         int status;
1752
1753         if (in_str == NULL)
1754                 return 0;
1755         if ((len = strlen(in_str)) < 2)
1756                 return 0;
1757         memset(out, 0, ADDRLEN);
1758
1759         status = 1;
1760         j = len - 1;
1761         if (j > 12)
1762                 j = 12;
1763         i = 5;
1764
1765         while (j > 0) {
1766                 if ((k = asc_to_int(in_str[j--])) != -1)
1767                         out[i] = k;
1768                 else
1769                         return 0;
1770
1771                 if (j == 0)
1772                         break;
1773                 if ((k = asc_to_int(in_str[j--])) != -1)
1774                         out[i] += k << 4;
1775                 else
1776                         return 0;
1777                 if (!i--)
1778                         break;
1779         }
1780         return status;
1781 }
1782
1783 /*===========================================================================*/
1784 static struct net_device_stats *ray_get_stats(struct net_device *dev)
1785 {
1786         ray_dev_t *local = netdev_priv(dev);
1787         struct pcmcia_device *link = local->finder;
1788         struct status __iomem *p = local->sram + STATUS_BASE;
1789         if (!(pcmcia_dev_present(link))) {
1790                 dev_dbg(&link->dev, "ray_cs net_device_stats - device not present\n");
1791                 return &local->stats;
1792         }
1793         if (readb(&p->mrx_overflow_for_host)) {
1794                 local->stats.rx_over_errors += swab16(readw(&p->mrx_overflow));
1795                 writeb(0, &p->mrx_overflow);
1796                 writeb(0, &p->mrx_overflow_for_host);
1797         }
1798         if (readb(&p->mrx_checksum_error_for_host)) {
1799                 local->stats.rx_crc_errors +=
1800                     swab16(readw(&p->mrx_checksum_error));
1801                 writeb(0, &p->mrx_checksum_error);
1802                 writeb(0, &p->mrx_checksum_error_for_host);
1803         }
1804         if (readb(&p->rx_hec_error_for_host)) {
1805                 local->stats.rx_frame_errors += swab16(readw(&p->rx_hec_error));
1806                 writeb(0, &p->rx_hec_error);
1807                 writeb(0, &p->rx_hec_error_for_host);
1808         }
1809         return &local->stats;
1810 }
1811
1812 /*===========================================================================*/
1813 static void ray_update_parm(struct net_device *dev, UCHAR objid, UCHAR *value,
1814                             int len)
1815 {
1816         ray_dev_t *local = netdev_priv(dev);
1817         struct pcmcia_device *link = local->finder;
1818         int ccsindex;
1819         int i;
1820         struct ccs __iomem *pccs;
1821
1822         if (!(pcmcia_dev_present(link))) {
1823                 dev_dbg(&link->dev, "ray_update_parm - device not present\n");
1824                 return;
1825         }
1826
1827         if ((ccsindex = get_free_ccs(local)) < 0) {
1828                 dev_dbg(&link->dev, "ray_update_parm - No free ccs\n");
1829                 return;
1830         }
1831         pccs = ccs_base(local) + ccsindex;
1832         writeb(CCS_UPDATE_PARAMS, &pccs->cmd);
1833         writeb(objid, &pccs->var.update_param.object_id);
1834         writeb(1, &pccs->var.update_param.number_objects);
1835         writeb(0, &pccs->var.update_param.failure_cause);
1836         for (i = 0; i < len; i++) {
1837                 writeb(value[i], local->sram + HOST_TO_ECF_BASE);
1838         }
1839         /* Interrupt the firmware to process the command */
1840         if (interrupt_ecf(local, ccsindex)) {
1841                 dev_dbg(&link->dev, "ray_cs associate failed - ECF not ready for intr\n");
1842                 writeb(CCS_BUFFER_FREE, &(pccs++)->buffer_status);
1843         }
1844 }
1845
1846 /*===========================================================================*/
1847 static void ray_update_multi_list(struct net_device *dev, int all)
1848 {
1849         int ccsindex;
1850         struct ccs __iomem *pccs;
1851         ray_dev_t *local = netdev_priv(dev);
1852         struct pcmcia_device *link = local->finder;
1853         void __iomem *p = local->sram + HOST_TO_ECF_BASE;
1854
1855         if (!(pcmcia_dev_present(link))) {
1856                 dev_dbg(&link->dev, "ray_update_multi_list - device not present\n");
1857                 return;
1858         } else
1859                 dev_dbg(&link->dev, "ray_update_multi_list(%p)\n", dev);
1860         if ((ccsindex = get_free_ccs(local)) < 0) {
1861                 dev_dbg(&link->dev, "ray_update_multi - No free ccs\n");
1862                 return;
1863         }
1864         pccs = ccs_base(local) + ccsindex;
1865         writeb(CCS_UPDATE_MULTICAST_LIST, &pccs->cmd);
1866
1867         if (all) {
1868                 writeb(0xff, &pccs->var);
1869                 local->num_multi = 0xff;
1870         } else {
1871                 struct netdev_hw_addr *ha;
1872                 int i = 0;
1873
1874                 /* Copy the kernel's list of MC addresses to card */
1875                 netdev_for_each_mc_addr(ha, dev) {
1876                         memcpy_toio(p, ha->addr, ETH_ALEN);
1877                         dev_dbg(&link->dev,
1878                               "ray_update_multi add addr %02x%02x%02x%02x%02x%02x\n",
1879                               ha->addr[0], ha->addr[1],
1880                               ha->addr[2], ha->addr[3],
1881                               ha->addr[4], ha->addr[5]);
1882                         p += ETH_ALEN;
1883                         i++;
1884                 }
1885                 if (i > 256 / ADDRLEN)
1886                         i = 256 / ADDRLEN;
1887                 writeb((UCHAR) i, &pccs->var);
1888                 dev_dbg(&link->dev, "ray_cs update_multi %d addresses in list\n", i);
1889                 /* Interrupt the firmware to process the command */
1890                 local->num_multi = i;
1891         }
1892         if (interrupt_ecf(local, ccsindex)) {
1893                 dev_dbg(&link->dev,
1894                       "ray_cs update_multi failed - ECF not ready for intr\n");
1895                 writeb(CCS_BUFFER_FREE, &(pccs++)->buffer_status);
1896         }
1897 } /* end ray_update_multi_list */
1898
1899 /*===========================================================================*/
1900 static void set_multicast_list(struct net_device *dev)
1901 {
1902         ray_dev_t *local = netdev_priv(dev);
1903         UCHAR promisc;
1904
1905         pr_debug("ray_cs set_multicast_list(%p)\n", dev);
1906
1907         if (dev->flags & IFF_PROMISC) {
1908                 if (local->sparm.b5.a_promiscuous_mode == 0) {
1909                         pr_debug("ray_cs set_multicast_list promisc on\n");
1910                         local->sparm.b5.a_promiscuous_mode = 1;
1911                         promisc = 1;
1912                         ray_update_parm(dev, OBJID_promiscuous_mode,
1913                                         &promisc, sizeof(promisc));
1914                 }
1915         } else {
1916                 if (local->sparm.b5.a_promiscuous_mode == 1) {
1917                         pr_debug("ray_cs set_multicast_list promisc off\n");
1918                         local->sparm.b5.a_promiscuous_mode = 0;
1919                         promisc = 0;
1920                         ray_update_parm(dev, OBJID_promiscuous_mode,
1921                                         &promisc, sizeof(promisc));
1922                 }
1923         }
1924
1925         if (dev->flags & IFF_ALLMULTI)
1926                 ray_update_multi_list(dev, 1);
1927         else {
1928                 if (local->num_multi != netdev_mc_count(dev))
1929                         ray_update_multi_list(dev, 0);
1930         }
1931 } /* end set_multicast_list */
1932
1933 /*=============================================================================
1934  * All routines below here are run at interrupt time.
1935 =============================================================================*/
1936 static irqreturn_t ray_interrupt(int irq, void *dev_id)
1937 {
1938         struct net_device *dev = (struct net_device *)dev_id;
1939         struct pcmcia_device *link;
1940         ray_dev_t *local;
1941         struct ccs __iomem *pccs;
1942         struct rcs __iomem *prcs;
1943         UCHAR rcsindex;
1944         UCHAR tmp;
1945         UCHAR cmd;
1946         UCHAR status;
1947
1948         if (dev == NULL)        /* Note that we want interrupts with dev->start == 0 */
1949                 return IRQ_NONE;
1950
1951         pr_debug("ray_cs: interrupt for *dev=%p\n", dev);
1952
1953         local = netdev_priv(dev);
1954         link = (struct pcmcia_device *)local->finder;
1955         if (!pcmcia_dev_present(link)) {
1956                 pr_debug(
1957                         "ray_cs interrupt from device not present or suspended.\n");
1958                 return IRQ_NONE;
1959         }
1960         rcsindex = readb(&((struct scb __iomem *)(local->sram))->rcs_index);
1961
1962         if (rcsindex >= (NUMBER_OF_CCS + NUMBER_OF_RCS)) {
1963                 dev_dbg(&link->dev, "ray_cs interrupt bad rcsindex = 0x%x\n", rcsindex);
1964                 clear_interrupt(local);
1965                 return IRQ_HANDLED;
1966         }
1967         if (rcsindex < NUMBER_OF_CCS) { /* If it's a returned CCS */
1968                 pccs = ccs_base(local) + rcsindex;
1969                 cmd = readb(&pccs->cmd);
1970                 status = readb(&pccs->buffer_status);
1971                 switch (cmd) {
1972                 case CCS_DOWNLOAD_STARTUP_PARAMS:       /* Happens in firmware someday */
1973                         del_timer(&local->timer);
1974                         if (status == CCS_COMMAND_COMPLETE) {
1975                                 dev_dbg(&link->dev,
1976                                       "ray_cs interrupt download_startup_parameters OK\n");
1977                         } else {
1978                                 dev_dbg(&link->dev,
1979                                       "ray_cs interrupt download_startup_parameters fail\n");
1980                         }
1981                         break;
1982                 case CCS_UPDATE_PARAMS:
1983                         dev_dbg(&link->dev, "ray_cs interrupt update params done\n");
1984                         if (status != CCS_COMMAND_COMPLETE) {
1985                                 tmp =
1986                                     readb(&pccs->var.update_param.
1987                                           failure_cause);
1988                                 dev_dbg(&link->dev,
1989                                       "ray_cs interrupt update params failed - reason %d\n",
1990                                       tmp);
1991                         }
1992                         break;
1993                 case CCS_REPORT_PARAMS:
1994                         dev_dbg(&link->dev, "ray_cs interrupt report params done\n");
1995                         break;
1996                 case CCS_UPDATE_MULTICAST_LIST: /* Note that this CCS isn't returned */
1997                         dev_dbg(&link->dev,
1998                               "ray_cs interrupt CCS Update Multicast List done\n");
1999                         break;
2000                 case CCS_UPDATE_POWER_SAVINGS_MODE:
2001                         dev_dbg(&link->dev,
2002                               "ray_cs interrupt update power save mode done\n");
2003                         break;
2004                 case CCS_START_NETWORK:
2005                 case CCS_JOIN_NETWORK:
2006                         if (status == CCS_COMMAND_COMPLETE) {
2007                                 if (readb
2008                                     (&pccs->var.start_network.net_initiated) ==
2009                                     1) {
2010                                         dev_dbg(&link->dev,
2011                                               "ray_cs interrupt network \"%s\" started\n",
2012                                               local->sparm.b4.a_current_ess_id);
2013                                 } else {
2014                                         dev_dbg(&link->dev,
2015                                               "ray_cs interrupt network \"%s\" joined\n",
2016                                               local->sparm.b4.a_current_ess_id);
2017                                 }
2018                                 memcpy_fromio(&local->bss_id,
2019                                               pccs->var.start_network.bssid,
2020                                               ADDRLEN);
2021
2022                                 if (local->fw_ver == 0x55)
2023                                         local->net_default_tx_rate = 3;
2024                                 else
2025                                         local->net_default_tx_rate =
2026                                             readb(&pccs->var.start_network.
2027                                                   net_default_tx_rate);
2028                                 local->encryption =
2029                                     readb(&pccs->var.start_network.encryption);
2030                                 if (!sniffer && (local->net_type == INFRA)
2031                                     && !(local->sparm.b4.a_acting_as_ap_status)) {
2032                                         authenticate(local);
2033                                 }
2034                                 local->card_status = CARD_ACQ_COMPLETE;
2035                         } else {
2036                                 local->card_status = CARD_ACQ_FAILED;
2037
2038                                 del_timer(&local->timer);
2039                                 local->timer.expires = jiffies + HZ * 5;
2040                                 local->timer.data = (long)local;
2041                                 if (status == CCS_START_NETWORK) {
2042                                         dev_dbg(&link->dev,
2043                                               "ray_cs interrupt network \"%s\" start failed\n",
2044                                               local->sparm.b4.a_current_ess_id);
2045                                         local->timer.function = &start_net;
2046                                 } else {
2047                                         dev_dbg(&link->dev,
2048                                               "ray_cs interrupt network \"%s\" join failed\n",
2049                                               local->sparm.b4.a_current_ess_id);
2050                                         local->timer.function = &join_net;
2051                                 }
2052                                 add_timer(&local->timer);
2053                         }
2054                         break;
2055                 case CCS_START_ASSOCIATION:
2056                         if (status == CCS_COMMAND_COMPLETE) {
2057                                 local->card_status = CARD_ASSOC_COMPLETE;
2058                                 dev_dbg(&link->dev, "ray_cs association successful\n");
2059                         } else {
2060                                 dev_dbg(&link->dev, "ray_cs association failed,\n");
2061                                 local->card_status = CARD_ASSOC_FAILED;
2062                                 join_net((u_long) local);
2063                         }
2064                         break;
2065                 case CCS_TX_REQUEST:
2066                         if (status == CCS_COMMAND_COMPLETE) {
2067                                 dev_dbg(&link->dev,
2068                                       "ray_cs interrupt tx request complete\n");
2069                         } else {
2070                                 dev_dbg(&link->dev,
2071                                       "ray_cs interrupt tx request failed\n");
2072                         }
2073                         if (!sniffer)
2074                                 netif_start_queue(dev);
2075                         netif_wake_queue(dev);
2076                         break;
2077                 case CCS_TEST_MEMORY:
2078                         dev_dbg(&link->dev, "ray_cs interrupt mem test done\n");
2079                         break;
2080                 case CCS_SHUTDOWN:
2081                         dev_dbg(&link->dev,
2082                               "ray_cs interrupt Unexpected CCS returned - Shutdown\n");
2083                         break;
2084                 case CCS_DUMP_MEMORY:
2085                         dev_dbg(&link->dev, "ray_cs interrupt dump memory done\n");
2086                         break;
2087                 case CCS_START_TIMER:
2088                         dev_dbg(&link->dev,
2089                               "ray_cs interrupt DING - raylink timer expired\n");
2090                         break;
2091                 default:
2092                         dev_dbg(&link->dev,
2093                               "ray_cs interrupt Unexpected CCS 0x%x returned 0x%x\n",
2094                               rcsindex, cmd);
2095                 }
2096                 writeb(CCS_BUFFER_FREE, &pccs->buffer_status);
2097         } else { /* It's an RCS */
2098
2099                 prcs = rcs_base(local) + rcsindex;
2100
2101                 switch (readb(&prcs->interrupt_id)) {
2102                 case PROCESS_RX_PACKET:
2103                         ray_rx(dev, local, prcs);
2104                         break;
2105                 case REJOIN_NET_COMPLETE:
2106                         dev_dbg(&link->dev, "ray_cs interrupt rejoin net complete\n");
2107                         local->card_status = CARD_ACQ_COMPLETE;
2108                         /* do we need to clear tx buffers CCS's? */
2109                         if (local->sparm.b4.a_network_type == ADHOC) {
2110                                 if (!sniffer)
2111                                         netif_start_queue(dev);
2112                         } else {
2113                                 memcpy_fromio(&local->bss_id,
2114                                               prcs->var.rejoin_net_complete.
2115                                               bssid, ADDRLEN);
2116                                 dev_dbg(&link->dev,
2117                                       "ray_cs new BSSID = %02x%02x%02x%02x%02x%02x\n",
2118                                       local->bss_id[0], local->bss_id[1],
2119                                       local->bss_id[2], local->bss_id[3],
2120                                       local->bss_id[4], local->bss_id[5]);
2121                                 if (!sniffer)
2122                                         authenticate(local);
2123                         }
2124                         break;
2125                 case ROAMING_INITIATED:
2126                         dev_dbg(&link->dev, "ray_cs interrupt roaming initiated\n");
2127                         netif_stop_queue(dev);
2128                         local->card_status = CARD_DOING_ACQ;
2129                         break;
2130                 case JAPAN_CALL_SIGN_RXD:
2131                         dev_dbg(&link->dev, "ray_cs interrupt japan call sign rx\n");
2132                         break;
2133                 default:
2134                         dev_dbg(&link->dev,
2135                               "ray_cs Unexpected interrupt for RCS 0x%x cmd = 0x%x\n",
2136                               rcsindex,
2137                               (unsigned int)readb(&prcs->interrupt_id));
2138                         break;
2139                 }
2140                 writeb(CCS_BUFFER_FREE, &prcs->buffer_status);
2141         }
2142         clear_interrupt(local);
2143         return IRQ_HANDLED;
2144 } /* ray_interrupt */
2145
2146 /*===========================================================================*/
2147 static void ray_rx(struct net_device *dev, ray_dev_t *local,
2148                    struct rcs __iomem *prcs)
2149 {
2150         int rx_len;
2151         unsigned int pkt_addr;
2152         void __iomem *pmsg;
2153         pr_debug("ray_rx process rx packet\n");
2154
2155         /* Calculate address of packet within Rx buffer */
2156         pkt_addr = ((readb(&prcs->var.rx_packet.rx_data_ptr[0]) << 8)
2157                     + readb(&prcs->var.rx_packet.rx_data_ptr[1])) & RX_BUFF_END;
2158         /* Length of first packet fragment */
2159         rx_len = (readb(&prcs->var.rx_packet.rx_data_length[0]) << 8)
2160             + readb(&prcs->var.rx_packet.rx_data_length[1]);
2161
2162         local->last_rsl = readb(&prcs->var.rx_packet.rx_sig_lev);
2163         pmsg = local->rmem + pkt_addr;
2164         switch (readb(pmsg)) {
2165         case DATA_TYPE:
2166                 pr_debug("ray_rx data type\n");
2167                 rx_data(dev, prcs, pkt_addr, rx_len);
2168                 break;
2169         case AUTHENTIC_TYPE:
2170                 pr_debug("ray_rx authentic type\n");
2171                 if (sniffer)
2172                         rx_data(dev, prcs, pkt_addr, rx_len);
2173                 else
2174                         rx_authenticate(local, prcs, pkt_addr, rx_len);
2175                 break;
2176         case DEAUTHENTIC_TYPE:
2177                 pr_debug("ray_rx deauth type\n");
2178                 if (sniffer)
2179                         rx_data(dev, prcs, pkt_addr, rx_len);
2180                 else
2181                         rx_deauthenticate(local, prcs, pkt_addr, rx_len);
2182                 break;
2183         case NULL_MSG_TYPE:
2184                 pr_debug("ray_cs rx NULL msg\n");
2185                 break;
2186         case BEACON_TYPE:
2187                 pr_debug("ray_rx beacon type\n");
2188                 if (sniffer)
2189                         rx_data(dev, prcs, pkt_addr, rx_len);
2190
2191                 copy_from_rx_buff(local, (UCHAR *) &local->last_bcn, pkt_addr,
2192                                   rx_len < sizeof(struct beacon_rx) ?
2193                                   rx_len : sizeof(struct beacon_rx));
2194
2195                 local->beacon_rxed = 1;
2196                 /* Get the statistics so the card counters never overflow */
2197                 ray_get_stats(dev);
2198                 break;
2199         default:
2200                 pr_debug("ray_cs unknown pkt type %2x\n",
2201                       (unsigned int)readb(pmsg));
2202                 break;
2203         }
2204
2205 } /* end ray_rx */
2206
2207 /*===========================================================================*/
2208 static void rx_data(struct net_device *dev, struct rcs __iomem *prcs,
2209                     unsigned int pkt_addr, int rx_len)
2210 {
2211         struct sk_buff *skb = NULL;
2212         struct rcs __iomem *prcslink = prcs;
2213         ray_dev_t *local = netdev_priv(dev);
2214         UCHAR *rx_ptr;
2215         int total_len;
2216         int tmp;
2217 #ifdef WIRELESS_SPY
2218         int siglev = local->last_rsl;
2219         u_char linksrcaddr[ETH_ALEN];   /* Other end of the wireless link */
2220 #endif
2221
2222         if (!sniffer) {
2223                 if (translate) {
2224 /* TBD length needs fixing for translated header */
2225                         if (rx_len < (ETH_HLEN + RX_MAC_HEADER_LENGTH) ||
2226                             rx_len >
2227                             (dev->mtu + RX_MAC_HEADER_LENGTH + ETH_HLEN +
2228                              FCS_LEN)) {
2229                                 pr_debug(
2230                                       "ray_cs invalid packet length %d received\n",
2231                                       rx_len);
2232                                 return;
2233                         }
2234                 } else { /* encapsulated ethernet */
2235
2236                         if (rx_len < (ETH_HLEN + RX_MAC_HEADER_LENGTH) ||
2237                             rx_len >
2238                             (dev->mtu + RX_MAC_HEADER_LENGTH + ETH_HLEN +
2239                              FCS_LEN)) {
2240                                 pr_debug(
2241                                       "ray_cs invalid packet length %d received\n",
2242                                       rx_len);
2243                                 return;
2244                         }
2245                 }
2246         }
2247         pr_debug("ray_cs rx_data packet\n");
2248         /* If fragmented packet, verify sizes of fragments add up */
2249         if (readb(&prcs->var.rx_packet.next_frag_rcs_index) != 0xFF) {
2250                 pr_debug("ray_cs rx'ed fragment\n");
2251                 tmp = (readb(&prcs->var.rx_packet.totalpacketlength[0]) << 8)
2252                     + readb(&prcs->var.rx_packet.totalpacketlength[1]);
2253                 total_len = tmp;
2254                 prcslink = prcs;
2255                 do {
2256                         tmp -=
2257                             (readb(&prcslink->var.rx_packet.rx_data_length[0])
2258                              << 8)
2259                             + readb(&prcslink->var.rx_packet.rx_data_length[1]);
2260                         if (readb(&prcslink->var.rx_packet.next_frag_rcs_index)
2261                             == 0xFF || tmp < 0)
2262                                 break;
2263                         prcslink = rcs_base(local)
2264                             + readb(&prcslink->link_field);
2265                 } while (1);
2266
2267                 if (tmp < 0) {
2268                         pr_debug(
2269                               "ray_cs rx_data fragment lengths don't add up\n");
2270                         local->stats.rx_dropped++;
2271                         release_frag_chain(local, prcs);
2272                         return;
2273                 }
2274         } else { /* Single unfragmented packet */
2275                 total_len = rx_len;
2276         }
2277
2278         skb = dev_alloc_skb(total_len + 5);
2279         if (skb == NULL) {
2280                 pr_debug("ray_cs rx_data could not allocate skb\n");
2281                 local->stats.rx_dropped++;
2282                 if (readb(&prcs->var.rx_packet.next_frag_rcs_index) != 0xFF)
2283                         release_frag_chain(local, prcs);
2284                 return;
2285         }
2286         skb_reserve(skb, 2);    /* Align IP on 16 byte (TBD check this) */
2287
2288         pr_debug("ray_cs rx_data total_len = %x, rx_len = %x\n", total_len,
2289               rx_len);
2290
2291 /************************/
2292         /* Reserve enough room for the whole damn packet. */
2293         rx_ptr = skb_put(skb, total_len);
2294         /* Copy the whole packet to sk_buff */
2295         rx_ptr +=
2296             copy_from_rx_buff(local, rx_ptr, pkt_addr & RX_BUFF_END, rx_len);
2297         /* Get source address */
2298 #ifdef WIRELESS_SPY
2299         skb_copy_from_linear_data_offset(skb,
2300                                          offsetof(struct mac_header, addr_2),
2301                                          linksrcaddr, ETH_ALEN);
2302 #endif
2303         /* Now, deal with encapsulation/translation/sniffer */
2304         if (!sniffer) {
2305                 if (!translate) {
2306                         /* Encapsulated ethernet, so just lop off 802.11 MAC header */
2307 /* TBD reserve            skb_reserve( skb, RX_MAC_HEADER_LENGTH); */
2308                         skb_pull(skb, RX_MAC_HEADER_LENGTH);
2309                 } else {
2310                         /* Do translation */
2311                         untranslate(local, skb, total_len);
2312                 }
2313         } else { /* sniffer mode, so just pass whole packet */
2314         };
2315
2316 /************************/
2317         /* Now pick up the rest of the fragments if any */
2318         tmp = 17;
2319         if (readb(&prcs->var.rx_packet.next_frag_rcs_index) != 0xFF) {
2320                 prcslink = prcs;
2321                 pr_debug("ray_cs rx_data in fragment loop\n");
2322                 do {
2323                         prcslink = rcs_base(local)
2324                             +
2325                             readb(&prcslink->var.rx_packet.next_frag_rcs_index);
2326                         rx_len =
2327                             ((readb(&prcslink->var.rx_packet.rx_data_length[0])
2328                               << 8)
2329                              +
2330                              readb(&prcslink->var.rx_packet.rx_data_length[1]))
2331                             & RX_BUFF_END;
2332                         pkt_addr =
2333                             ((readb(&prcslink->var.rx_packet.rx_data_ptr[0]) <<
2334                               8)
2335                              + readb(&prcslink->var.rx_packet.rx_data_ptr[1]))
2336                             & RX_BUFF_END;
2337
2338                         rx_ptr +=
2339                             copy_from_rx_buff(local, rx_ptr, pkt_addr, rx_len);
2340
2341                 } while (tmp-- &&
2342                          readb(&prcslink->var.rx_packet.next_frag_rcs_index) !=
2343                          0xFF);
2344                 release_frag_chain(local, prcs);
2345         }
2346
2347         skb->protocol = eth_type_trans(skb, dev);
2348         netif_rx(skb);
2349         local->stats.rx_packets++;
2350         local->stats.rx_bytes += total_len;
2351
2352         /* Gather signal strength per address */
2353 #ifdef WIRELESS_SPY
2354         /* For the Access Point or the node having started the ad-hoc net
2355          * note : ad-hoc work only in some specific configurations, but we
2356          * kludge in ray_get_wireless_stats... */
2357         if (!memcmp(linksrcaddr, local->bss_id, ETH_ALEN)) {
2358                 /* Update statistics */
2359                 /*local->wstats.qual.qual = none ? */
2360                 local->wstats.qual.level = siglev;
2361                 /*local->wstats.qual.noise = none ? */
2362                 local->wstats.qual.updated = 0x2;
2363         }
2364         /* Now, update the spy stuff */
2365         {
2366                 struct iw_quality wstats;
2367                 wstats.level = siglev;
2368                 /* wstats.noise = none ? */
2369                 /* wstats.qual = none ? */
2370                 wstats.updated = 0x2;
2371                 /* Update spy records */
2372                 wireless_spy_update(dev, linksrcaddr, &wstats);
2373         }
2374 #endif /* WIRELESS_SPY */
2375 } /* end rx_data */
2376
2377 /*===========================================================================*/
2378 static void untranslate(ray_dev_t *local, struct sk_buff *skb, int len)
2379 {
2380         snaphdr_t *psnap = (snaphdr_t *) (skb->data + RX_MAC_HEADER_LENGTH);
2381         struct ieee80211_hdr *pmac = (struct ieee80211_hdr *)skb->data;
2382         __be16 type = *(__be16 *) psnap->ethertype;
2383         int delta;
2384         struct ethhdr *peth;
2385         UCHAR srcaddr[ADDRLEN];
2386         UCHAR destaddr[ADDRLEN];
2387         static UCHAR org_bridge[3] = { 0, 0, 0xf8 };
2388         static UCHAR org_1042[3] = { 0, 0, 0 };
2389
2390         memcpy(destaddr, ieee80211_get_DA(pmac), ADDRLEN);
2391         memcpy(srcaddr, ieee80211_get_SA(pmac), ADDRLEN);
2392
2393 #if 0
2394         if {
2395                 print_hex_dump(KERN_DEBUG, "skb->data before untranslate: ",
2396                                DUMP_PREFIX_NONE, 16, 1,
2397                                skb->data, 64, true);
2398                 printk(KERN_DEBUG
2399                        "type = %08x, xsap = %02x%02x%02x, org = %02x02x02x\n",
2400                        ntohs(type), psnap->dsap, psnap->ssap, psnap->ctrl,
2401                        psnap->org[0], psnap->org[1], psnap->org[2]);
2402                 printk(KERN_DEBUG "untranslate skb->data = %p\n", skb->data);
2403         }
2404 #endif
2405
2406         if (psnap->dsap != 0xaa || psnap->ssap != 0xaa || psnap->ctrl != 3) {
2407                 /* not a snap type so leave it alone */
2408                 pr_debug("ray_cs untranslate NOT SNAP %02x %02x %02x\n",
2409                       psnap->dsap, psnap->ssap, psnap->ctrl);
2410
2411                 delta = RX_MAC_HEADER_LENGTH - ETH_HLEN;
2412                 peth = (struct ethhdr *)(skb->data + delta);
2413                 peth->h_proto = htons(len - RX_MAC_HEADER_LENGTH);
2414         } else { /* Its a SNAP */
2415                 if (memcmp(psnap->org, org_bridge, 3) == 0) {
2416                 /* EtherII and nuke the LLC */
2417                         pr_debug("ray_cs untranslate Bridge encap\n");
2418                         delta = RX_MAC_HEADER_LENGTH
2419                             + sizeof(struct snaphdr_t) - ETH_HLEN;
2420                         peth = (struct ethhdr *)(skb->data + delta);
2421                         peth->h_proto = type;
2422                 } else if (memcmp(psnap->org, org_1042, 3) == 0) {
2423                         switch (ntohs(type)) {
2424                         case ETH_P_IPX:
2425                         case ETH_P_AARP:
2426                                 pr_debug("ray_cs untranslate RFC IPX/AARP\n");
2427                                 delta = RX_MAC_HEADER_LENGTH - ETH_HLEN;
2428                                 peth = (struct ethhdr *)(skb->data + delta);
2429                                 peth->h_proto =
2430                                     htons(len - RX_MAC_HEADER_LENGTH);
2431                                 break;
2432                         default:
2433                                 pr_debug("ray_cs untranslate RFC default\n");
2434                                 delta = RX_MAC_HEADER_LENGTH +
2435                                     sizeof(struct snaphdr_t) - ETH_HLEN;
2436                                 peth = (struct ethhdr *)(skb->data + delta);
2437                                 peth->h_proto = type;
2438                                 break;
2439                         }
2440                 } else {
2441                         printk("ray_cs untranslate very confused by packet\n");
2442                         delta = RX_MAC_HEADER_LENGTH - ETH_HLEN;
2443                         peth = (struct ethhdr *)(skb->data + delta);
2444                         peth->h_proto = type;
2445                 }
2446         }
2447 /* TBD reserve  skb_reserve(skb, delta); */
2448         skb_pull(skb, delta);
2449         pr_debug("untranslate after skb_pull(%d), skb->data = %p\n", delta,
2450               skb->data);
2451         memcpy(peth->h_dest, destaddr, ADDRLEN);
2452         memcpy(peth->h_source, srcaddr, ADDRLEN);
2453 #if 0
2454         {
2455                 int i;
2456                 printk(KERN_DEBUG "skb->data after untranslate:");
2457                 for (i = 0; i < 64; i++)
2458                         printk("%02x ", skb->data[i]);
2459                 printk("\n");
2460         }
2461 #endif
2462 } /* end untranslate */
2463
2464 /*===========================================================================*/
2465 /* Copy data from circular receive buffer to PC memory.
2466  * dest     = destination address in PC memory
2467  * pkt_addr = source address in receive buffer
2468  * len      = length of packet to copy
2469  */
2470 static int copy_from_rx_buff(ray_dev_t *local, UCHAR *dest, int pkt_addr,
2471                              int length)
2472 {
2473         int wrap_bytes = (pkt_addr + length) - (RX_BUFF_END + 1);
2474         if (wrap_bytes <= 0) {
2475                 memcpy_fromio(dest, local->rmem + pkt_addr, length);
2476         } else { /* Packet wrapped in circular buffer */
2477
2478                 memcpy_fromio(dest, local->rmem + pkt_addr,
2479                               length - wrap_bytes);
2480                 memcpy_fromio(dest + length - wrap_bytes, local->rmem,
2481                               wrap_bytes);
2482         }
2483         return length;
2484 }
2485
2486 /*===========================================================================*/
2487 static void release_frag_chain(ray_dev_t *local, struct rcs __iomem *prcs)
2488 {
2489         struct rcs __iomem *prcslink = prcs;
2490         int tmp = 17;
2491         unsigned rcsindex = readb(&prcs->var.rx_packet.next_frag_rcs_index);
2492
2493         while (tmp--) {
2494                 writeb(CCS_BUFFER_FREE, &prcslink->buffer_status);
2495                 if (rcsindex >= (NUMBER_OF_CCS + NUMBER_OF_RCS)) {
2496                         pr_debug("ray_cs interrupt bad rcsindex = 0x%x\n",
2497                               rcsindex);
2498                         break;
2499                 }
2500                 prcslink = rcs_base(local) + rcsindex;
2501                 rcsindex = readb(&prcslink->var.rx_packet.next_frag_rcs_index);
2502         }
2503         writeb(CCS_BUFFER_FREE, &prcslink->buffer_status);
2504 }
2505
2506 /*===========================================================================*/
2507 static void authenticate(ray_dev_t *local)
2508 {
2509         struct pcmcia_device *link = local->finder;
2510         dev_dbg(&link->dev, "ray_cs Starting authentication.\n");
2511         if (!(pcmcia_dev_present(link))) {
2512                 dev_dbg(&link->dev, "ray_cs authenticate - device not present\n");
2513                 return;
2514         }
2515
2516         del_timer(&local->timer);
2517         if (build_auth_frame(local, local->bss_id, OPEN_AUTH_REQUEST)) {
2518                 local->timer.function = &join_net;
2519         } else {
2520                 local->timer.function = &authenticate_timeout;
2521         }
2522         local->timer.expires = jiffies + HZ * 2;
2523         local->timer.data = (long)local;
2524         add_timer(&local->timer);
2525         local->authentication_state = AWAITING_RESPONSE;
2526 } /* end authenticate */
2527
2528 /*===========================================================================*/
2529 static void rx_authenticate(ray_dev_t *local, struct rcs __iomem *prcs,
2530                             unsigned int pkt_addr, int rx_len)
2531 {
2532         UCHAR buff[256];
2533         struct rx_msg *msg = (struct rx_msg *)buff;
2534
2535         del_timer(&local->timer);
2536
2537         copy_from_rx_buff(local, buff, pkt_addr, rx_len & 0xff);
2538         /* if we are trying to get authenticated */
2539         if (local->sparm.b4.a_network_type == ADHOC) {
2540                 pr_debug("ray_cs rx_auth var= %02x %02x %02x %02x %02x %02x\n",
2541                       msg->var[0], msg->var[1], msg->var[2], msg->var[3],
2542                       msg->var[4], msg->var[5]);
2543                 if (msg->var[2] == 1) {
2544                         pr_debug("ray_cs Sending authentication response.\n");
2545                         if (!build_auth_frame
2546                             (local, msg->mac.addr_2, OPEN_AUTH_RESPONSE)) {
2547                                 local->authentication_state = NEED_TO_AUTH;
2548                                 memcpy(local->auth_id, msg->mac.addr_2,
2549                                        ADDRLEN);
2550                         }
2551                 }
2552         } else { /* Infrastructure network */
2553
2554                 if (local->authentication_state == AWAITING_RESPONSE) {
2555                         /* Verify authentication sequence #2 and success */
2556                         if (msg->var[2] == 2) {
2557                                 if ((msg->var[3] | msg->var[4]) == 0) {
2558                                         pr_debug("Authentication successful\n");
2559                                         local->card_status = CARD_AUTH_COMPLETE;
2560                                         associate(local);
2561                                         local->authentication_state =
2562                                             AUTHENTICATED;
2563                                 } else {
2564                                         pr_debug("Authentication refused\n");
2565                                         local->card_status = CARD_AUTH_REFUSED;
2566                                         join_net((u_long) local);
2567                                         local->authentication_state =
2568                                             UNAUTHENTICATED;
2569                                 }
2570                         }
2571                 }
2572         }
2573
2574 } /* end rx_authenticate */
2575
2576 /*===========================================================================*/
2577 static void associate(ray_dev_t *local)
2578 {
2579         struct ccs __iomem *pccs;
2580         struct pcmcia_device *link = local->finder;
2581         struct net_device *dev = link->priv;
2582         int ccsindex;
2583         if (!(pcmcia_dev_present(link))) {
2584                 dev_dbg(&link->dev, "ray_cs associate - device not present\n");
2585                 return;
2586         }
2587         /* If no tx buffers available, return */
2588         if ((ccsindex = get_free_ccs(local)) < 0) {
2589 /* TBD should never be here but... what if we are? */
2590                 dev_dbg(&link->dev, "ray_cs associate - No free ccs\n");
2591                 return;
2592         }
2593         dev_dbg(&link->dev, "ray_cs Starting association with access point\n");
2594         pccs = ccs_base(local) + ccsindex;
2595         /* fill in the CCS */
2596         writeb(CCS_START_ASSOCIATION, &pccs->cmd);
2597         /* Interrupt the firmware to process the command */
2598         if (interrupt_ecf(local, ccsindex)) {
2599                 dev_dbg(&link->dev, "ray_cs associate failed - ECF not ready for intr\n");
2600                 writeb(CCS_BUFFER_FREE, &(pccs++)->buffer_status);
2601
2602                 del_timer(&local->timer);
2603                 local->timer.expires = jiffies + HZ * 2;
2604                 local->timer.data = (long)local;
2605                 local->timer.function = &join_net;
2606                 add_timer(&local->timer);
2607                 local->card_status = CARD_ASSOC_FAILED;
2608                 return;
2609         }
2610         if (!sniffer)
2611                 netif_start_queue(dev);
2612
2613 } /* end associate */
2614
2615 /*===========================================================================*/
2616 static void rx_deauthenticate(ray_dev_t *local, struct rcs __iomem *prcs,
2617                               unsigned int pkt_addr, int rx_len)
2618 {
2619 /*  UCHAR buff[256];
2620     struct rx_msg *msg = (struct rx_msg *)buff;
2621 */
2622         pr_debug("Deauthentication frame received\n");
2623         local->authentication_state = UNAUTHENTICATED;
2624         /* Need to reauthenticate or rejoin depending on reason code */
2625 /*  copy_from_rx_buff(local, buff, pkt_addr, rx_len & 0xff);
2626  */
2627 }
2628
2629 /*===========================================================================*/
2630 static void clear_interrupt(ray_dev_t *local)
2631 {
2632         writeb(0, local->amem + CIS_OFFSET + HCS_INTR_OFFSET);
2633 }
2634
2635 /*===========================================================================*/
2636 #ifdef CONFIG_PROC_FS
2637 #define MAXDATA (PAGE_SIZE - 80)
2638
2639 static char *card_status[] = {
2640         "Card inserted - uninitialized",        /* 0 */
2641         "Card not downloaded",                  /* 1 */
2642         "Waiting for download parameters",      /* 2 */
2643         "Card doing acquisition",               /* 3 */
2644         "Acquisition complete",                 /* 4 */
2645         "Authentication complete",              /* 5 */
2646         "Association complete",                 /* 6 */
2647         "???", "???", "???", "???",             /* 7 8 9 10 undefined */
2648         "Card init error",                      /* 11 */
2649         "Download parameters error",            /* 12 */
2650         "???",                                  /* 13 */
2651         "Acquisition failed",                   /* 14 */
2652         "Authentication refused",               /* 15 */
2653         "Association failed"                    /* 16 */
2654 };
2655
2656 static char *nettype[] = { "Adhoc", "Infra " };
2657 static char *framing[] = { "Encapsulation", "Translation" }
2658
2659 ;
2660 /*===========================================================================*/
2661 static int ray_cs_proc_show(struct seq_file *m, void *v)
2662 {
2663 /* Print current values which are not available via other means
2664  * eg ifconfig
2665  */
2666         int i;
2667         struct pcmcia_device *link;
2668         struct net_device *dev;
2669         ray_dev_t *local;
2670         UCHAR *p;
2671         struct freq_hop_element *pfh;
2672         UCHAR c[33];
2673
2674         link = this_device;
2675         if (!link)
2676                 return 0;
2677         dev = (struct net_device *)link->priv;
2678         if (!dev)
2679                 return 0;
2680         local = netdev_priv(dev);
2681         if (!local)
2682                 return 0;
2683
2684         seq_puts(m, "Raylink Wireless LAN driver status\n");
2685         seq_printf(m, "%s\n", rcsid);
2686         /* build 4 does not report version, and field is 0x55 after memtest */
2687         seq_puts(m, "Firmware version     = ");
2688         if (local->fw_ver == 0x55)
2689                 seq_puts(m, "4 - Use dump_cis for more details\n");
2690         else
2691                 seq_printf(m, "%2d.%02d.%02d\n",
2692                            local->fw_ver, local->fw_bld, local->fw_var);
2693
2694         for (i = 0; i < 32; i++)
2695                 c[i] = local->sparm.b5.a_current_ess_id[i];
2696         c[32] = 0;
2697         seq_printf(m, "%s network ESSID = \"%s\"\n",
2698                    nettype[local->sparm.b5.a_network_type], c);
2699
2700         p = local->bss_id;
2701         seq_printf(m, "BSSID                = %pM\n", p);
2702
2703         seq_printf(m, "Country code         = %d\n",
2704                    local->sparm.b5.a_curr_country_code);
2705
2706         i = local->card_status;
2707         if (i < 0)
2708                 i = 10;
2709         if (i > 16)
2710                 i = 10;
2711         seq_printf(m, "Card status          = %s\n", card_status[i]);
2712
2713         seq_printf(m, "Framing mode         = %s\n", framing[translate]);
2714
2715         seq_printf(m, "Last pkt signal lvl  = %d\n", local->last_rsl);
2716
2717         if (local->beacon_rxed) {
2718                 /* Pull some fields out of last beacon received */
2719                 seq_printf(m, "Beacon Interval      = %d Kus\n",
2720                            local->last_bcn.beacon_intvl[0]
2721                            + 256 * local->last_bcn.beacon_intvl[1]);
2722
2723                 p = local->last_bcn.elements;
2724                 if (p[0] == C_ESSID_ELEMENT_ID)
2725                         p += p[1] + 2;
2726                 else {
2727                         seq_printf(m,
2728                                    "Parse beacon failed at essid element id = %d\n",
2729                                    p[0]);
2730                         return 0;
2731                 }
2732
2733                 if (p[0] == C_SUPPORTED_RATES_ELEMENT_ID) {
2734                         seq_puts(m, "Supported rate codes = ");
2735                         for (i = 2; i < p[1] + 2; i++)
2736                                 seq_printf(m, "0x%02x ", p[i]);
2737                         seq_putc(m, '\n');
2738                         p += p[1] + 2;
2739                 } else {
2740                         seq_puts(m, "Parse beacon failed at rates element\n");
2741                         return 0;
2742                 }
2743
2744                 if (p[0] == C_FH_PARAM_SET_ELEMENT_ID) {
2745                         pfh = (struct freq_hop_element *)p;
2746                         seq_printf(m, "Hop dwell            = %d Kus\n",
2747                                    pfh->dwell_time[0] +
2748                                    256 * pfh->dwell_time[1]);
2749                         seq_printf(m, "Hop set              = %d\n",
2750                                    pfh->hop_set);
2751                         seq_printf(m, "Hop pattern          = %d\n",
2752                                    pfh->hop_pattern);
2753                         seq_printf(m, "Hop index            = %d\n",
2754                                    pfh->hop_index);
2755                         p += p[1] + 2;
2756                 } else {
2757                         seq_puts(m,
2758                                  "Parse beacon failed at FH param element\n");
2759                         return 0;
2760                 }
2761         } else {
2762                 seq_puts(m, "No beacons received\n");
2763         }
2764         return 0;
2765 }
2766
2767 static int ray_cs_proc_open(struct inode *inode, struct file *file)
2768 {
2769         return single_open(file, ray_cs_proc_show, NULL);
2770 }
2771
2772 static const struct file_operations ray_cs_proc_fops = {
2773         .owner = THIS_MODULE,
2774         .open = ray_cs_proc_open,
2775         .read = seq_read,
2776         .llseek = seq_lseek,
2777         .release = single_release,
2778 };
2779 #endif
2780 /*===========================================================================*/
2781 static int build_auth_frame(ray_dev_t *local, UCHAR *dest, int auth_type)
2782 {
2783         int addr;
2784         struct ccs __iomem *pccs;
2785         struct tx_msg __iomem *ptx;
2786         int ccsindex;
2787
2788         /* If no tx buffers available, return */
2789         if ((ccsindex = get_free_tx_ccs(local)) < 0) {
2790                 pr_debug("ray_cs send authenticate - No free tx ccs\n");
2791                 return -1;
2792         }
2793
2794         pccs = ccs_base(local) + ccsindex;
2795
2796         /* Address in card space */
2797         addr = TX_BUF_BASE + (ccsindex << 11);
2798         /* fill in the CCS */
2799         writeb(CCS_TX_REQUEST, &pccs->cmd);
2800         writeb(addr >> 8, pccs->var.tx_request.tx_data_ptr);
2801         writeb(0x20, pccs->var.tx_request.tx_data_ptr + 1);
2802         writeb(TX_AUTHENTICATE_LENGTH_MSB, pccs->var.tx_request.tx_data_length);
2803         writeb(TX_AUTHENTICATE_LENGTH_LSB,
2804                pccs->var.tx_request.tx_data_length + 1);
2805         writeb(0, &pccs->var.tx_request.pow_sav_mode);
2806
2807         ptx = local->sram + addr;
2808         /* fill in the mac header */
2809         writeb(PROTOCOL_VER | AUTHENTIC_TYPE, &ptx->mac.frame_ctl_1);
2810         writeb(0, &ptx->mac.frame_ctl_2);
2811
2812         memcpy_toio(ptx->mac.addr_1, dest, ADDRLEN);
2813         memcpy_toio(ptx->mac.addr_2, local->sparm.b4.a_mac_addr, ADDRLEN);
2814         memcpy_toio(ptx->mac.addr_3, local->bss_id, ADDRLEN);
2815
2816         /* Fill in msg body with protocol 00 00, sequence 01 00 ,status 00 00 */
2817         memset_io(ptx->var, 0, 6);
2818         writeb(auth_type & 0xff, ptx->var + 2);
2819
2820         /* Interrupt the firmware to process the command */
2821         if (interrupt_ecf(local, ccsindex)) {
2822                 pr_debug(
2823                       "ray_cs send authentication request failed - ECF not ready for intr\n");
2824                 writeb(CCS_BUFFER_FREE, &(pccs++)->buffer_status);
2825                 return -1;
2826         }
2827         return 0;
2828 } /* End build_auth_frame */
2829
2830 /*===========================================================================*/
2831 #ifdef CONFIG_PROC_FS
2832 static ssize_t ray_cs_essid_proc_write(struct file *file,
2833                 const char __user *buffer, size_t count, loff_t *pos)
2834 {
2835         static char proc_essid[33];
2836         unsigned int len = count;
2837
2838         if (len > 32)
2839                 len = 32;
2840         memset(proc_essid, 0, 33);
2841         if (copy_from_user(proc_essid, buffer, len))
2842                 return -EFAULT;
2843         essid = proc_essid;
2844         return count;
2845 }
2846
2847 static const struct file_operations ray_cs_essid_proc_fops = {
2848         .owner          = THIS_MODULE,
2849         .write          = ray_cs_essid_proc_write,
2850 };
2851
2852 static ssize_t int_proc_write(struct file *file, const char __user *buffer,
2853                               size_t count, loff_t *pos)
2854 {
2855         static char proc_number[10];
2856         char *p;
2857         int nr, len;
2858
2859         if (!count)
2860                 return 0;
2861
2862         if (count > 9)
2863                 return -EINVAL;
2864         if (copy_from_user(proc_number, buffer, count))
2865                 return -EFAULT;
2866         p = proc_number;
2867         nr = 0;
2868         len = count;
2869         do {
2870                 unsigned int c = *p - '0';
2871                 if (c > 9)
2872                         return -EINVAL;
2873                 nr = nr * 10 + c;
2874                 p++;
2875         } while (--len);
2876         *(int *)PDE(file->f_path.dentry->d_inode)->data = nr;
2877         return count;
2878 }
2879
2880 static const struct file_operations int_proc_fops = {
2881         .owner          = THIS_MODULE,
2882         .write          = int_proc_write,
2883 };
2884 #endif
2885
2886 static struct pcmcia_device_id ray_ids[] = {
2887         PCMCIA_DEVICE_MANF_CARD(0x01a6, 0x0000),
2888         PCMCIA_DEVICE_NULL,
2889 };
2890
2891 MODULE_DEVICE_TABLE(pcmcia, ray_ids);
2892
2893 static struct pcmcia_driver ray_driver = {
2894         .owner = THIS_MODULE,
2895         .drv = {
2896                 .name = "ray_cs",
2897                 },
2898         .probe = ray_probe,
2899         .remove = ray_detach,
2900         .id_table = ray_ids,
2901         .suspend = ray_suspend,
2902         .resume = ray_resume,
2903 };
2904
2905 static int __init init_ray_cs(void)
2906 {
2907         int rc;
2908
2909         pr_debug("%s\n", rcsid);
2910         rc = pcmcia_register_driver(&ray_driver);
2911         pr_debug("raylink init_module register_pcmcia_driver returns 0x%x\n",
2912               rc);
2913
2914 #ifdef CONFIG_PROC_FS
2915         proc_mkdir("driver/ray_cs", NULL);
2916
2917         proc_create("driver/ray_cs/ray_cs", 0, NULL, &ray_cs_proc_fops);
2918         proc_create("driver/ray_cs/essid", S_IWUSR, NULL, &ray_cs_essid_proc_fops);
2919         proc_create_data("driver/ray_cs/net_type", S_IWUSR, NULL, &int_proc_fops, &net_type);
2920         proc_create_data("driver/ray_cs/translate", S_IWUSR, NULL, &int_proc_fops, &translate);
2921 #endif
2922         if (translate != 0)
2923                 translate = 1;
2924         return 0;
2925 } /* init_ray_cs */
2926
2927 /*===========================================================================*/
2928
2929 static void __exit exit_ray_cs(void)
2930 {
2931         pr_debug("ray_cs: cleanup_module\n");
2932
2933 #ifdef CONFIG_PROC_FS
2934         remove_proc_entry("driver/ray_cs/ray_cs", NULL);
2935         remove_proc_entry("driver/ray_cs/essid", NULL);
2936         remove_proc_entry("driver/ray_cs/net_type", NULL);
2937         remove_proc_entry("driver/ray_cs/translate", NULL);
2938         remove_proc_entry("driver/ray_cs", NULL);
2939 #endif
2940
2941         pcmcia_unregister_driver(&ray_driver);
2942 } /* exit_ray_cs */
2943
2944 module_init(init_ray_cs);
2945 module_exit(exit_ray_cs);
2946
2947 /*===========================================================================*/