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