blob: 7370edb4e0cee1ab5f642a8d1da05a17f8b67d9b [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*=============================================================================
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
John Daiker141fa612009-03-10 06:59:54 -070011 * it under the terms of version 2 only of the GNU General Public License as
Linus Torvalds1da177e2005-04-16 15:20:36 -070012 * 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)
John Daiker141fa612009-03-10 06:59:54 -070030 *
Linus Torvalds1da177e2005-04-16 15:20:36 -070031=============================================================================*/
32
Linus Torvalds1da177e2005-04-16 15:20:36 -070033#include <linux/module.h>
34#include <linux/kernel.h>
35#include <linux/proc_fs.h>
36#include <linux/ptrace.h>
Alexey Dobriyan6b914c52008-04-10 14:34:35 -070037#include <linux/seq_file.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070038#include <linux/slab.h>
39#include <linux/string.h>
40#include <linux/timer.h>
41#include <linux/init.h>
42#include <linux/netdevice.h>
43#include <linux/etherdevice.h>
44#include <linux/if_arp.h>
45#include <linux/ioport.h>
46#include <linux/skbuff.h>
47#include <linux/ethtool.h>
Al Viro7698d692007-12-29 04:55:50 -050048#include <linux/ieee80211.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070049
Linus Torvalds1da177e2005-04-16 15:20:36 -070050#include <pcmcia/cs_types.h>
51#include <pcmcia/cs.h>
52#include <pcmcia/cistpl.h>
53#include <pcmcia/cisreg.h>
54#include <pcmcia/ds.h>
55#include <pcmcia/mem_op.h>
56
57#include <linux/wireless.h>
Michael Wu113b8982006-08-13 23:27:17 -070058#include <net/iw_handler.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070059
60#include <asm/io.h>
61#include <asm/system.h>
62#include <asm/byteorder.h>
63#include <asm/uaccess.h>
64
65/* Warning : these stuff will slow down the driver... */
66#define WIRELESS_SPY /* Enable spying addresses */
67/* Definitions we need for spy */
John Daiker141fa612009-03-10 06:59:54 -070068typedef struct iw_statistics iw_stats;
69typedef u_char mac_addr[ETH_ALEN]; /* Hardware address */
Linus Torvalds1da177e2005-04-16 15:20:36 -070070
71#include "rayctl.h"
72#include "ray_cs.h"
73
74/* All the PCMCIA modules use PCMCIA_DEBUG to control debugging. If
75 you do not define PCMCIA_DEBUG at all, all the debug code will be
76 left out. If you compile with PCMCIA_DEBUG=0, the debug code will
77 be present but disabled -- but it can then be enabled for specific
78 modules at load time with a 'pc_debug=#' option to insmod.
79*/
80
81#ifdef RAYLINK_DEBUG
82#define PCMCIA_DEBUG RAYLINK_DEBUG
83#endif
84#ifdef PCMCIA_DEBUG
85static int ray_debug;
86static int pc_debug = PCMCIA_DEBUG;
87module_param(pc_debug, int, 0);
88/* #define DEBUG(n, args...) if (pc_debug>(n)) printk(KERN_DEBUG args); */
John Daiker141fa612009-03-10 06:59:54 -070089#define DEBUG(n, args...) if (pc_debug > (n)) printk(args);
Linus Torvalds1da177e2005-04-16 15:20:36 -070090#else
91#define DEBUG(n, args...)
92#endif
93/** Prototypes based on PCMCIA skeleton driver *******************************/
Dominik Brodowski15b99ac2006-03-31 17:26:06 +020094static int ray_config(struct pcmcia_device *link);
Dominik Brodowskifba395e2006-03-31 17:21:06 +020095static void ray_release(struct pcmcia_device *link);
Dominik Brodowskicc3b4862005-11-14 21:23:14 +010096static void ray_detach(struct pcmcia_device *p_dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -070097
98/***** Prototypes indicated by device structure ******************************/
99static int ray_dev_close(struct net_device *dev);
100static int ray_dev_config(struct net_device *dev, struct ifmap *map);
101static struct net_device_stats *ray_get_stats(struct net_device *dev);
102static int ray_dev_init(struct net_device *dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700103
Jeff Garzik7282d492006-09-13 14:30:00 -0400104static const struct ethtool_ops netdev_ethtool_ops;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700105
106static int ray_open(struct net_device *dev);
107static int ray_dev_start_xmit(struct sk_buff *skb, struct net_device *dev);
108static void set_multicast_list(struct net_device *dev);
109static void ray_update_multi_list(struct net_device *dev, int all);
110static int translate_frame(ray_dev_t *local, struct tx_msg __iomem *ptx,
John Daiker141fa612009-03-10 06:59:54 -0700111 unsigned char *data, int len);
112static void ray_build_header(ray_dev_t *local, struct tx_msg __iomem *ptx,
113 UCHAR msg_type, unsigned char *data);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700114static void untranslate(ray_dev_t *local, struct sk_buff *skb, int len);
John Daiker141fa612009-03-10 06:59:54 -0700115static iw_stats *ray_get_wireless_stats(struct net_device *dev);
116static const struct iw_handler_def ray_handler_def;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700117
118/***** Prototypes for raylink functions **************************************/
119static int asc_to_int(char a);
120static void authenticate(ray_dev_t *local);
121static int build_auth_frame(ray_dev_t *local, UCHAR *dest, int auth_type);
122static void authenticate_timeout(u_long);
123static int get_free_ccs(ray_dev_t *local);
124static int get_free_tx_ccs(ray_dev_t *local);
125static void init_startup_params(ray_dev_t *local);
126static int parse_addr(char *in_str, UCHAR *out);
John Daiker141fa612009-03-10 06:59:54 -0700127static int ray_hw_xmit(unsigned char *data, int len, struct net_device *dev, UCHAR type);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700128static int ray_init(struct net_device *dev);
129static int interrupt_ecf(ray_dev_t *local, int ccs);
130static void ray_reset(struct net_device *dev);
131static void ray_update_parm(struct net_device *dev, UCHAR objid, UCHAR *value, int len);
132static void verify_dl_startup(u_long);
133
134/* Prototypes for interrpt time functions **********************************/
John Daiker141fa612009-03-10 06:59:54 -0700135static irqreturn_t ray_interrupt(int reg, void *dev_id);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700136static void clear_interrupt(ray_dev_t *local);
John Daiker141fa612009-03-10 06:59:54 -0700137static void rx_deauthenticate(ray_dev_t *local, struct rcs __iomem *prcs,
138 unsigned int pkt_addr, int rx_len);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700139static int copy_from_rx_buff(ray_dev_t *local, UCHAR *dest, int pkt_addr, int len);
140static void ray_rx(struct net_device *dev, ray_dev_t *local, struct rcs __iomem *prcs);
141static void release_frag_chain(ray_dev_t *local, struct rcs __iomem *prcs);
142static void rx_authenticate(ray_dev_t *local, struct rcs __iomem *prcs,
John Daiker141fa612009-03-10 06:59:54 -0700143 unsigned int pkt_addr, int rx_len);
144static void rx_data(struct net_device *dev, struct rcs __iomem *prcs,
145 unsigned int pkt_addr, int rx_len);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700146static void associate(ray_dev_t *local);
147
148/* Card command functions */
149static int dl_startup_params(struct net_device *dev);
150static void join_net(u_long local);
151static void start_net(u_long local);
152/* void start_net(ray_dev_t *local); */
153
154/*===========================================================================*/
155/* Parameters that can be set with 'insmod' */
156
157/* ADHOC=0, Infrastructure=1 */
158static int net_type = ADHOC;
159
160/* Hop dwell time in Kus (1024 us units defined by 802.11) */
161static int hop_dwell = 128;
162
163/* Beacon period in Kus */
164static int beacon_period = 256;
165
166/* power save mode (0 = off, 1 = save power) */
167static int psm;
168
169/* String for network's Extended Service Set ID. 32 Characters max */
170static char *essid;
171
172/* Default to encapsulation unless translation requested */
173static int translate = 1;
174
175static int country = USA;
176
177static int sniffer;
178
179static int bc;
180
181/* 48 bit physical card address if overriding card's real physical
182 * address is required. Since IEEE 802.11 addresses are 48 bits
183 * like ethernet, an int can't be used, so a string is used. To
184 * allow use of addresses starting with a decimal digit, the first
185 * character must be a letter and will be ignored. This letter is
186 * followed by up to 12 hex digits which are the address. If less
187 * than 12 digits are used, the address will be left filled with 0's.
188 * Note that bit 0 of the first byte is the broadcast bit, and evil
189 * things will happen if it is not 0 in a card address.
190 */
191static char *phy_addr = NULL;
192
193
Dominik Brodowskifba395e2006-03-31 17:21:06 +0200194/* A struct pcmcia_device structure has fields for most things that are needed
Linus Torvalds1da177e2005-04-16 15:20:36 -0700195 to keep track of a socket, but there will usually be some device
196 specific information that also needs to be kept track of. The
Dominik Brodowskifba395e2006-03-31 17:21:06 +0200197 'priv' pointer in a struct pcmcia_device structure can be used to point to
Linus Torvalds1da177e2005-04-16 15:20:36 -0700198 a device-specific private data structure, like this.
199*/
200static unsigned int ray_mem_speed = 500;
201
Dominik Brodowskifd238232006-03-05 10:45:09 +0100202/* WARNING: THIS DRIVER IS NOT CAPABLE OF HANDLING MULTIPLE DEVICES! */
203static struct pcmcia_device *this_device = NULL;
204
Linus Torvalds1da177e2005-04-16 15:20:36 -0700205MODULE_AUTHOR("Corey Thomas <corey@world.std.com>");
206MODULE_DESCRIPTION("Raylink/WebGear wireless LAN driver");
207MODULE_LICENSE("GPL");
208
209module_param(net_type, int, 0);
210module_param(hop_dwell, int, 0);
211module_param(beacon_period, int, 0);
212module_param(psm, int, 0);
213module_param(essid, charp, 0);
214module_param(translate, int, 0);
215module_param(country, int, 0);
216module_param(sniffer, int, 0);
217module_param(bc, int, 0);
218module_param(phy_addr, charp, 0);
219module_param(ray_mem_speed, int, 0);
220
221static UCHAR b5_default_startup_parms[] = {
John Daiker141fa612009-03-10 06:59:54 -0700222 0, 0, /* Adhoc station */
223 'L', 'I', 'N', 'U', 'X', 0, 0, 0, /* 32 char ESSID */
224 0, 0, 0, 0, 0, 0, 0, 0,
225 0, 0, 0, 0, 0, 0, 0, 0,
226 0, 0, 0, 0, 0, 0, 0, 0,
227 1, 0, /* Active scan, CA Mode */
228 0, 0, 0, 0, 0, 0, /* No default MAC addr */
229 0x7f, 0xff, /* Frag threshold */
230 0x00, 0x80, /* Hop time 128 Kus */
231 0x01, 0x00, /* Beacon period 256 Kus */
232 0x01, 0x07, 0xa3, /* DTIM, retries, ack timeout */
233 0x1d, 0x82, 0x4e, /* SIFS, DIFS, PIFS */
234 0x7f, 0xff, /* RTS threshold */
235 0x04, 0xe2, 0x38, 0xA4, /* scan_dwell, max_scan_dwell */
236 0x05, /* assoc resp timeout thresh */
237 0x08, 0x02, 0x08, /* adhoc, infra, super cycle max */
238 0, /* Promiscuous mode */
239 0x0c, 0x0bd, /* Unique word */
240 0x32, /* Slot time */
241 0xff, 0xff, /* roam-low snr, low snr count */
242 0x05, 0xff, /* Infra, adhoc missed bcn thresh */
243 0x01, 0x0b, 0x4f, /* USA, hop pattern, hop pat length */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700244/* b4 - b5 differences start here */
John Daiker141fa612009-03-10 06:59:54 -0700245 0x00, 0x3f, /* CW max */
246 0x00, 0x0f, /* CW min */
247 0x04, 0x08, /* Noise gain, limit offset */
248 0x28, 0x28, /* det rssi, med busy offsets */
249 7, /* det sync thresh */
250 0, 2, 2, /* test mode, min, max */
251 0, /* allow broadcast SSID probe resp */
252 0, 0, /* privacy must start, can join */
253 2, 0, 0, 0, 0, 0, 0, 0 /* basic rate set */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700254};
255
256static UCHAR b4_default_startup_parms[] = {
John Daiker141fa612009-03-10 06:59:54 -0700257 0, 0, /* Adhoc station */
258 'L', 'I', 'N', 'U', 'X', 0, 0, 0, /* 32 char ESSID */
259 0, 0, 0, 0, 0, 0, 0, 0,
260 0, 0, 0, 0, 0, 0, 0, 0,
261 0, 0, 0, 0, 0, 0, 0, 0,
262 1, 0, /* Active scan, CA Mode */
263 0, 0, 0, 0, 0, 0, /* No default MAC addr */
264 0x7f, 0xff, /* Frag threshold */
265 0x02, 0x00, /* Hop time */
266 0x00, 0x01, /* Beacon period */
267 0x01, 0x07, 0xa3, /* DTIM, retries, ack timeout */
268 0x1d, 0x82, 0xce, /* SIFS, DIFS, PIFS */
269 0x7f, 0xff, /* RTS threshold */
270 0xfb, 0x1e, 0xc7, 0x5c, /* scan_dwell, max_scan_dwell */
271 0x05, /* assoc resp timeout thresh */
272 0x04, 0x02, 0x4, /* adhoc, infra, super cycle max */
273 0, /* Promiscuous mode */
274 0x0c, 0x0bd, /* Unique word */
275 0x4e, /* Slot time (TBD seems wrong) */
276 0xff, 0xff, /* roam-low snr, low snr count */
277 0x05, 0xff, /* Infra, adhoc missed bcn thresh */
278 0x01, 0x0b, 0x4e, /* USA, hop pattern, hop pat length */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700279/* b4 - b5 differences start here */
John Daiker141fa612009-03-10 06:59:54 -0700280 0x3f, 0x0f, /* CW max, min */
281 0x04, 0x08, /* Noise gain, limit offset */
282 0x28, 0x28, /* det rssi, med busy offsets */
283 7, /* det sync thresh */
284 0, 2, 2 /* test mode, min, max */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700285};
John Daiker141fa612009-03-10 06:59:54 -0700286
Linus Torvalds1da177e2005-04-16 15:20:36 -0700287/*===========================================================================*/
John Daiker141fa612009-03-10 06:59:54 -0700288static unsigned char eth2_llc[] = { 0xaa, 0xaa, 3, 0, 0, 0 };
Linus Torvalds1da177e2005-04-16 15:20:36 -0700289
290static char hop_pattern_length[] = { 1,
John Daiker141fa612009-03-10 06:59:54 -0700291 USA_HOP_MOD, EUROPE_HOP_MOD,
292 JAPAN_HOP_MOD, KOREA_HOP_MOD,
293 SPAIN_HOP_MOD, FRANCE_HOP_MOD,
294 ISRAEL_HOP_MOD, AUSTRALIA_HOP_MOD,
295 JAPAN_TEST_HOP_MOD
Linus Torvalds1da177e2005-04-16 15:20:36 -0700296};
297
John Daiker141fa612009-03-10 06:59:54 -0700298static char rcsid[] =
299 "Raylink/WebGear wireless LAN - Corey <Thomas corey@world.std.com>";
Linus Torvalds1da177e2005-04-16 15:20:36 -0700300
301/*=============================================================================
302 ray_attach() creates an "instance" of the driver, allocating
303 local data structures for one device. The device is registered
304 with Card Services.
305 The dev_link structure is initialized, but we don't actually
306 configure the card at this point -- we wait until we receive a
307 card insertion event.
308=============================================================================*/
Dominik Brodowski15b99ac2006-03-31 17:26:06 +0200309static int ray_probe(struct pcmcia_device *p_dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700310{
John Daiker141fa612009-03-10 06:59:54 -0700311 ray_dev_t *local;
312 struct net_device *dev;
Dominik Brodowskifd238232006-03-05 10:45:09 +0100313
John Daiker141fa612009-03-10 06:59:54 -0700314 DEBUG(1, "ray_attach()\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700315
John Daiker141fa612009-03-10 06:59:54 -0700316 /* Allocate space for private device-specific data */
317 dev = alloc_etherdev(sizeof(ray_dev_t));
318 if (!dev)
319 goto fail_alloc_dev;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700320
John Daiker141fa612009-03-10 06:59:54 -0700321 local = netdev_priv(dev);
322 local->finder = p_dev;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700323
John Daiker141fa612009-03-10 06:59:54 -0700324 /* The io structure describes IO port mapping. None used here */
325 p_dev->io.NumPorts1 = 0;
326 p_dev->io.Attributes1 = IO_DATA_PATH_WIDTH_8;
327 p_dev->io.IOAddrLines = 5;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700328
John Daiker141fa612009-03-10 06:59:54 -0700329 /* Interrupt setup. For PCMCIA, driver takes what's given */
330 p_dev->irq.Attributes = IRQ_TYPE_DYNAMIC_SHARING | IRQ_HANDLE_PRESENT;
331 p_dev->irq.IRQInfo1 = IRQ_LEVEL_ID;
332 p_dev->irq.Handler = &ray_interrupt;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700333
John Daiker141fa612009-03-10 06:59:54 -0700334 /* General socket configuration */
335 p_dev->conf.Attributes = CONF_ENABLE_IRQ;
336 p_dev->conf.IntType = INT_MEMORY_AND_IO;
337 p_dev->conf.ConfigIndex = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700338
John Daiker141fa612009-03-10 06:59:54 -0700339 p_dev->priv = dev;
340 p_dev->irq.Instance = dev;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700341
John Daiker141fa612009-03-10 06:59:54 -0700342 local->finder = p_dev;
343 local->card_status = CARD_INSERTED;
344 local->authentication_state = UNAUTHENTICATED;
345 local->num_multi = 0;
346 DEBUG(2, "ray_attach p_dev = %p, dev = %p, local = %p, intr = %p\n",
347 p_dev, dev, local, &ray_interrupt);
348
349 /* Raylink entries in the device structure */
350 dev->hard_start_xmit = &ray_dev_start_xmit;
351 dev->set_config = &ray_dev_config;
352 dev->get_stats = &ray_get_stats;
353 SET_ETHTOOL_OPS(dev, &netdev_ethtool_ops);
354 dev->wireless_handlers = &ray_handler_def;
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -0700355#ifdef WIRELESS_SPY
John Daiker141fa612009-03-10 06:59:54 -0700356 local->wireless_data.spy_data = &local->spy_data;
357 dev->wireless_data = &local->wireless_data;
358#endif /* WIRELESS_SPY */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700359
John Daiker141fa612009-03-10 06:59:54 -0700360 dev->set_multicast_list = &set_multicast_list;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700361
John Daiker141fa612009-03-10 06:59:54 -0700362 DEBUG(2, "ray_cs ray_attach calling ether_setup.)\n");
363 dev->init = &ray_dev_init;
364 dev->open = &ray_open;
365 dev->stop = &ray_dev_close;
366 netif_stop_queue(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700367
John Daiker141fa612009-03-10 06:59:54 -0700368 init_timer(&local->timer);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700369
John Daiker141fa612009-03-10 06:59:54 -0700370 this_device = p_dev;
371 return ray_config(p_dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700372
373fail_alloc_dev:
John Daiker141fa612009-03-10 06:59:54 -0700374 return -ENOMEM;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700375} /* ray_attach */
John Daiker141fa612009-03-10 06:59:54 -0700376
Linus Torvalds1da177e2005-04-16 15:20:36 -0700377/*=============================================================================
378 This deletes a driver "instance". The device is de-registered
379 with Card Services. If it has been released, all local data
380 structures are freed. Otherwise, the structures will be freed
381 when the device is released.
382=============================================================================*/
Dominik Brodowskifba395e2006-03-31 17:21:06 +0200383static void ray_detach(struct pcmcia_device *link)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700384{
John Daiker141fa612009-03-10 06:59:54 -0700385 struct net_device *dev;
386 ray_dev_t *local;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700387
John Daiker141fa612009-03-10 06:59:54 -0700388 DEBUG(1, "ray_detach(0x%p)\n", link);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700389
John Daiker141fa612009-03-10 06:59:54 -0700390 this_device = NULL;
391 dev = link->priv;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700392
John Daiker141fa612009-03-10 06:59:54 -0700393 ray_release(link);
Dominik Brodowskicc3b4862005-11-14 21:23:14 +0100394
John Daiker141fa612009-03-10 06:59:54 -0700395 local = netdev_priv(dev);
396 del_timer(&local->timer);
Dominik Brodowskicc3b4862005-11-14 21:23:14 +0100397
John Daiker141fa612009-03-10 06:59:54 -0700398 if (link->priv) {
399 if (link->dev_node)
400 unregister_netdev(dev);
401 free_netdev(dev);
402 }
403 DEBUG(2, "ray_cs ray_detach ending\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700404} /* ray_detach */
John Daiker141fa612009-03-10 06:59:54 -0700405
Linus Torvalds1da177e2005-04-16 15:20:36 -0700406/*=============================================================================
407 ray_config() is run after a CARD_INSERTION event
408 is received, to configure the PCMCIA socket, and to make the
409 ethernet device available to the system.
410=============================================================================*/
411#define CS_CHECK(fn, ret) \
412do { last_fn = (fn); if ((last_ret = (ret)) != 0) goto cs_failed; } while (0)
413#define MAX_TUPLE_SIZE 128
Dominik Brodowski15b99ac2006-03-31 17:26:06 +0200414static int ray_config(struct pcmcia_device *link)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700415{
John Daiker141fa612009-03-10 06:59:54 -0700416 int last_fn = 0, last_ret = 0;
417 int i;
418 win_req_t req;
419 memreq_t mem;
420 struct net_device *dev = (struct net_device *)link->priv;
421 ray_dev_t *local = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700422
John Daiker141fa612009-03-10 06:59:54 -0700423 DEBUG(1, "ray_config(0x%p)\n", link);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700424
John Daiker141fa612009-03-10 06:59:54 -0700425 /* Determine card type and firmware version */
426 printk(KERN_INFO "ray_cs Detected: %s%s%s%s\n",
427 link->prod_id[0] ? link->prod_id[0] : " ",
428 link->prod_id[1] ? link->prod_id[1] : " ",
429 link->prod_id[2] ? link->prod_id[2] : " ",
430 link->prod_id[3] ? link->prod_id[3] : " ");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700431
John Daiker141fa612009-03-10 06:59:54 -0700432 /* Now allocate an interrupt line. Note that this does not
433 actually assign a handler to the interrupt.
434 */
435 CS_CHECK(RequestIRQ, pcmcia_request_irq(link, &link->irq));
436 dev->irq = link->irq.AssignedIRQ;
437
438 /* This actually configures the PCMCIA socket -- setting up
439 the I/O windows and the interrupt mapping.
440 */
441 CS_CHECK(RequestConfiguration,
442 pcmcia_request_configuration(link, &link->conf));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700443
444/*** Set up 32k window for shared memory (transmit and control) ************/
John Daiker141fa612009-03-10 06:59:54 -0700445 req.Attributes =
446 WIN_DATA_WIDTH_8 | WIN_MEMORY_TYPE_CM | WIN_ENABLE | WIN_USE_WAIT;
447 req.Base = 0;
448 req.Size = 0x8000;
449 req.AccessSpeed = ray_mem_speed;
450 CS_CHECK(RequestWindow, pcmcia_request_window(&link, &req, &link->win));
451 mem.CardOffset = 0x0000;
452 mem.Page = 0;
453 CS_CHECK(MapMemPage, pcmcia_map_mem_page(link->win, &mem));
454 local->sram = ioremap(req.Base, req.Size);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700455
456/*** Set up 16k window for shared memory (receive buffer) ***************/
John Daiker141fa612009-03-10 06:59:54 -0700457 req.Attributes =
458 WIN_DATA_WIDTH_8 | WIN_MEMORY_TYPE_CM | WIN_ENABLE | WIN_USE_WAIT;
459 req.Base = 0;
460 req.Size = 0x4000;
461 req.AccessSpeed = ray_mem_speed;
462 CS_CHECK(RequestWindow,
463 pcmcia_request_window(&link, &req, &local->rmem_handle));
464 mem.CardOffset = 0x8000;
465 mem.Page = 0;
466 CS_CHECK(MapMemPage, pcmcia_map_mem_page(local->rmem_handle, &mem));
467 local->rmem = ioremap(req.Base, req.Size);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700468
469/*** Set up window for attribute memory ***********************************/
John Daiker141fa612009-03-10 06:59:54 -0700470 req.Attributes =
471 WIN_DATA_WIDTH_8 | WIN_MEMORY_TYPE_AM | WIN_ENABLE | WIN_USE_WAIT;
472 req.Base = 0;
473 req.Size = 0x1000;
474 req.AccessSpeed = ray_mem_speed;
475 CS_CHECK(RequestWindow,
476 pcmcia_request_window(&link, &req, &local->amem_handle));
477 mem.CardOffset = 0x0000;
478 mem.Page = 0;
479 CS_CHECK(MapMemPage, pcmcia_map_mem_page(local->amem_handle, &mem));
480 local->amem = ioremap(req.Base, req.Size);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700481
John Daiker141fa612009-03-10 06:59:54 -0700482 DEBUG(3, "ray_config sram=%p\n", local->sram);
483 DEBUG(3, "ray_config rmem=%p\n", local->rmem);
484 DEBUG(3, "ray_config amem=%p\n", local->amem);
485 if (ray_init(dev) < 0) {
486 ray_release(link);
487 return -ENODEV;
488 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700489
John Daiker141fa612009-03-10 06:59:54 -0700490 SET_NETDEV_DEV(dev, &handle_to_dev(link));
491 i = register_netdev(dev);
492 if (i != 0) {
493 printk("ray_config register_netdev() failed\n");
494 ray_release(link);
495 return i;
496 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700497
John Daiker141fa612009-03-10 06:59:54 -0700498 strcpy(local->node.dev_name, dev->name);
499 link->dev_node = &local->node;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700500
John Daiker141fa612009-03-10 06:59:54 -0700501 printk(KERN_INFO "%s: RayLink, irq %d, hw_addr %pM\n",
502 dev->name, dev->irq, dev->dev_addr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700503
John Daiker141fa612009-03-10 06:59:54 -0700504 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700505
506cs_failed:
John Daiker141fa612009-03-10 06:59:54 -0700507 cs_error(link, last_fn, last_ret);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700508
John Daiker141fa612009-03-10 06:59:54 -0700509 ray_release(link);
510 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700511} /* ray_config */
512
513static inline struct ccs __iomem *ccs_base(ray_dev_t *dev)
514{
515 return dev->sram + CCS_BASE;
516}
517
518static inline struct rcs __iomem *rcs_base(ray_dev_t *dev)
519{
520 /*
521 * This looks nonsensical, since there is a separate
522 * RCS_BASE. But the difference between a "struct rcs"
523 * and a "struct ccs" ends up being in the _index_ off
524 * the base, so the base pointer is the same for both
525 * ccs/rcs.
526 */
527 return dev->sram + CCS_BASE;
528}
529
530/*===========================================================================*/
531static int ray_init(struct net_device *dev)
532{
John Daiker141fa612009-03-10 06:59:54 -0700533 int i;
534 UCHAR *p;
535 struct ccs __iomem *pccs;
536 ray_dev_t *local = netdev_priv(dev);
537 struct pcmcia_device *link = local->finder;
538 DEBUG(1, "ray_init(0x%p)\n", dev);
539 if (!(pcmcia_dev_present(link))) {
540 DEBUG(0, "ray_init - device not present\n");
541 return -1;
542 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700543
John Daiker141fa612009-03-10 06:59:54 -0700544 local->net_type = net_type;
545 local->sta_type = TYPE_STA;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700546
John Daiker141fa612009-03-10 06:59:54 -0700547 /* Copy the startup results to local memory */
548 memcpy_fromio(&local->startup_res, local->sram + ECF_TO_HOST_BASE,
549 sizeof(struct startup_res_6));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700550
John Daiker141fa612009-03-10 06:59:54 -0700551 /* Check Power up test status and get mac address from card */
552 if (local->startup_res.startup_word != 0x80) {
553 printk(KERN_INFO "ray_init ERROR card status = %2x\n",
554 local->startup_res.startup_word);
555 local->card_status = CARD_INIT_ERROR;
556 return -1;
557 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700558
John Daiker141fa612009-03-10 06:59:54 -0700559 local->fw_ver = local->startup_res.firmware_version[0];
560 local->fw_bld = local->startup_res.firmware_version[1];
561 local->fw_var = local->startup_res.firmware_version[2];
562 DEBUG(1, "ray_init firmware version %d.%d \n", local->fw_ver,
563 local->fw_bld);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700564
John Daiker141fa612009-03-10 06:59:54 -0700565 local->tib_length = 0x20;
566 if ((local->fw_ver == 5) && (local->fw_bld >= 30))
567 local->tib_length = local->startup_res.tib_length;
568 DEBUG(2, "ray_init tib_length = 0x%02x\n", local->tib_length);
569 /* Initialize CCS's to buffer free state */
570 pccs = ccs_base(local);
571 for (i = 0; i < NUMBER_OF_CCS; i++) {
572 writeb(CCS_BUFFER_FREE, &(pccs++)->buffer_status);
573 }
574 init_startup_params(local);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700575
John Daiker141fa612009-03-10 06:59:54 -0700576 /* copy mac address to startup parameters */
577 if (parse_addr(phy_addr, local->sparm.b4.a_mac_addr)) {
578 p = local->sparm.b4.a_mac_addr;
579 } else {
580 memcpy(&local->sparm.b4.a_mac_addr,
581 &local->startup_res.station_addr, ADDRLEN);
582 p = local->sparm.b4.a_mac_addr;
583 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700584
John Daiker141fa612009-03-10 06:59:54 -0700585 clear_interrupt(local); /* Clear any interrupt from the card */
586 local->card_status = CARD_AWAITING_PARAM;
587 DEBUG(2, "ray_init ending\n");
588 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700589} /* ray_init */
John Daiker141fa612009-03-10 06:59:54 -0700590
Linus Torvalds1da177e2005-04-16 15:20:36 -0700591/*===========================================================================*/
592/* Download startup parameters to the card and command it to read them */
593static int dl_startup_params(struct net_device *dev)
594{
John Daiker141fa612009-03-10 06:59:54 -0700595 int ccsindex;
596 ray_dev_t *local = netdev_priv(dev);
597 struct ccs __iomem *pccs;
598 struct pcmcia_device *link = local->finder;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700599
John Daiker141fa612009-03-10 06:59:54 -0700600 DEBUG(1, "dl_startup_params entered\n");
601 if (!(pcmcia_dev_present(link))) {
602 DEBUG(2, "ray_cs dl_startup_params - device not present\n");
603 return -1;
604 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700605
John Daiker141fa612009-03-10 06:59:54 -0700606 /* Copy parameters to host to ECF area */
607 if (local->fw_ver == 0x55)
608 memcpy_toio(local->sram + HOST_TO_ECF_BASE, &local->sparm.b4,
609 sizeof(struct b4_startup_params));
610 else
611 memcpy_toio(local->sram + HOST_TO_ECF_BASE, &local->sparm.b5,
612 sizeof(struct b5_startup_params));
613
614 /* Fill in the CCS fields for the ECF */
615 if ((ccsindex = get_free_ccs(local)) < 0)
616 return -1;
617 local->dl_param_ccs = ccsindex;
618 pccs = ccs_base(local) + ccsindex;
619 writeb(CCS_DOWNLOAD_STARTUP_PARAMS, &pccs->cmd);
620 DEBUG(2, "dl_startup_params start ccsindex = %d\n",
621 local->dl_param_ccs);
622 /* Interrupt the firmware to process the command */
623 if (interrupt_ecf(local, ccsindex)) {
624 printk(KERN_INFO "ray dl_startup_params failed - "
625 "ECF not ready for intr\n");
626 local->card_status = CARD_DL_PARAM_ERROR;
627 writeb(CCS_BUFFER_FREE, &(pccs++)->buffer_status);
628 return -2;
629 }
630 local->card_status = CARD_DL_PARAM;
631 /* Start kernel timer to wait for dl startup to complete. */
632 local->timer.expires = jiffies + HZ / 2;
633 local->timer.data = (long)local;
634 local->timer.function = &verify_dl_startup;
635 add_timer(&local->timer);
636 DEBUG(2,
637 "ray_cs dl_startup_params started timer for verify_dl_startup\n");
638 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700639} /* dl_startup_params */
John Daiker141fa612009-03-10 06:59:54 -0700640
Linus Torvalds1da177e2005-04-16 15:20:36 -0700641/*===========================================================================*/
642static void init_startup_params(ray_dev_t *local)
643{
John Daiker141fa612009-03-10 06:59:54 -0700644 int i;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700645
John Daiker141fa612009-03-10 06:59:54 -0700646 if (country > JAPAN_TEST)
647 country = USA;
648 else if (country < USA)
649 country = USA;
650 /* structure for hop time and beacon period is defined here using
651 * New 802.11D6.1 format. Card firmware is still using old format
652 * until version 6.
653 * Before After
654 * a_hop_time ms byte a_hop_time ms byte
655 * a_hop_time 2s byte a_hop_time ls byte
656 * a_hop_time ls byte a_beacon_period ms byte
657 * a_beacon_period a_beacon_period ls byte
658 *
659 * a_hop_time = uS a_hop_time = KuS
660 * a_beacon_period = hops a_beacon_period = KuS
661 *//* 64ms = 010000 */
662 if (local->fw_ver == 0x55) {
663 memcpy((UCHAR *) &local->sparm.b4, b4_default_startup_parms,
664 sizeof(struct b4_startup_params));
665 /* Translate sane kus input values to old build 4/5 format */
666 /* i = hop time in uS truncated to 3 bytes */
667 i = (hop_dwell * 1024) & 0xffffff;
668 local->sparm.b4.a_hop_time[0] = (i >> 16) & 0xff;
669 local->sparm.b4.a_hop_time[1] = (i >> 8) & 0xff;
670 local->sparm.b4.a_beacon_period[0] = 0;
671 local->sparm.b4.a_beacon_period[1] =
672 ((beacon_period / hop_dwell) - 1) & 0xff;
673 local->sparm.b4.a_curr_country_code = country;
674 local->sparm.b4.a_hop_pattern_length =
675 hop_pattern_length[(int)country] - 1;
676 if (bc) {
677 local->sparm.b4.a_ack_timeout = 0x50;
678 local->sparm.b4.a_sifs = 0x3f;
679 }
680 } else { /* Version 5 uses real kus values */
681 memcpy((UCHAR *) &local->sparm.b5, b5_default_startup_parms,
682 sizeof(struct b5_startup_params));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700683
John Daiker141fa612009-03-10 06:59:54 -0700684 local->sparm.b5.a_hop_time[0] = (hop_dwell >> 8) & 0xff;
685 local->sparm.b5.a_hop_time[1] = hop_dwell & 0xff;
686 local->sparm.b5.a_beacon_period[0] =
687 (beacon_period >> 8) & 0xff;
688 local->sparm.b5.a_beacon_period[1] = beacon_period & 0xff;
689 if (psm)
690 local->sparm.b5.a_power_mgt_state = 1;
691 local->sparm.b5.a_curr_country_code = country;
692 local->sparm.b5.a_hop_pattern_length =
693 hop_pattern_length[(int)country];
694 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700695
John Daiker141fa612009-03-10 06:59:54 -0700696 local->sparm.b4.a_network_type = net_type & 0x01;
697 local->sparm.b4.a_acting_as_ap_status = TYPE_STA;
698
699 if (essid != NULL)
700 strncpy(local->sparm.b4.a_current_ess_id, essid, ESSID_SIZE);
701} /* init_startup_params */
702
Linus Torvalds1da177e2005-04-16 15:20:36 -0700703/*===========================================================================*/
704static void verify_dl_startup(u_long data)
705{
John Daiker141fa612009-03-10 06:59:54 -0700706 ray_dev_t *local = (ray_dev_t *) data;
707 struct ccs __iomem *pccs = ccs_base(local) + local->dl_param_ccs;
708 UCHAR status;
709 struct pcmcia_device *link = local->finder;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700710
John Daiker141fa612009-03-10 06:59:54 -0700711 if (!(pcmcia_dev_present(link))) {
712 DEBUG(2, "ray_cs verify_dl_startup - device not present\n");
713 return;
714 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700715#ifdef PCMCIA_DEBUG
John Daiker141fa612009-03-10 06:59:54 -0700716 if (pc_debug > 2) {
717 int i;
718 printk(KERN_DEBUG
719 "verify_dl_startup parameters sent via ccs %d:\n",
720 local->dl_param_ccs);
721 for (i = 0; i < sizeof(struct b5_startup_params); i++) {
722 printk(" %2x",
723 (unsigned int)readb(local->sram +
724 HOST_TO_ECF_BASE + i));
725 }
726 printk("\n");
727 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700728#endif
729
John Daiker141fa612009-03-10 06:59:54 -0700730 status = readb(&pccs->buffer_status);
731 if (status != CCS_BUFFER_FREE) {
732 printk(KERN_INFO
733 "Download startup params failed. Status = %d\n",
734 status);
735 local->card_status = CARD_DL_PARAM_ERROR;
736 return;
737 }
738 if (local->sparm.b4.a_network_type == ADHOC)
739 start_net((u_long) local);
740 else
741 join_net((u_long) local);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700742
John Daiker141fa612009-03-10 06:59:54 -0700743 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700744} /* end verify_dl_startup */
John Daiker141fa612009-03-10 06:59:54 -0700745
Linus Torvalds1da177e2005-04-16 15:20:36 -0700746/*===========================================================================*/
747/* Command card to start a network */
748static void start_net(u_long data)
749{
John Daiker141fa612009-03-10 06:59:54 -0700750 ray_dev_t *local = (ray_dev_t *) data;
751 struct ccs __iomem *pccs;
752 int ccsindex;
753 struct pcmcia_device *link = local->finder;
754 if (!(pcmcia_dev_present(link))) {
755 DEBUG(2, "ray_cs start_net - device not present\n");
756 return;
757 }
758 /* Fill in the CCS fields for the ECF */
759 if ((ccsindex = get_free_ccs(local)) < 0)
760 return;
761 pccs = ccs_base(local) + ccsindex;
762 writeb(CCS_START_NETWORK, &pccs->cmd);
763 writeb(0, &pccs->var.start_network.update_param);
764 /* Interrupt the firmware to process the command */
765 if (interrupt_ecf(local, ccsindex)) {
766 DEBUG(1, "ray start net failed - card not ready for intr\n");
767 writeb(CCS_BUFFER_FREE, &(pccs++)->buffer_status);
768 return;
769 }
770 local->card_status = CARD_DOING_ACQ;
771 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700772} /* end start_net */
John Daiker141fa612009-03-10 06:59:54 -0700773
Linus Torvalds1da177e2005-04-16 15:20:36 -0700774/*===========================================================================*/
775/* Command card to join a network */
776static void join_net(u_long data)
777{
John Daiker141fa612009-03-10 06:59:54 -0700778 ray_dev_t *local = (ray_dev_t *) data;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700779
John Daiker141fa612009-03-10 06:59:54 -0700780 struct ccs __iomem *pccs;
781 int ccsindex;
782 struct pcmcia_device *link = local->finder;
783
784 if (!(pcmcia_dev_present(link))) {
785 DEBUG(2, "ray_cs join_net - device not present\n");
786 return;
787 }
788 /* Fill in the CCS fields for the ECF */
789 if ((ccsindex = get_free_ccs(local)) < 0)
790 return;
791 pccs = ccs_base(local) + ccsindex;
792 writeb(CCS_JOIN_NETWORK, &pccs->cmd);
793 writeb(0, &pccs->var.join_network.update_param);
794 writeb(0, &pccs->var.join_network.net_initiated);
795 /* Interrupt the firmware to process the command */
796 if (interrupt_ecf(local, ccsindex)) {
797 DEBUG(1, "ray join net failed - card not ready for intr\n");
798 writeb(CCS_BUFFER_FREE, &(pccs++)->buffer_status);
799 return;
800 }
801 local->card_status = CARD_DOING_ACQ;
802 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700803}
John Daiker141fa612009-03-10 06:59:54 -0700804
Linus Torvalds1da177e2005-04-16 15:20:36 -0700805/*============================================================================
806 After a card is removed, ray_release() will unregister the net
807 device, and release the PCMCIA configuration. If the device is
808 still open, this will be postponed until it is closed.
809=============================================================================*/
Dominik Brodowskifba395e2006-03-31 17:21:06 +0200810static void ray_release(struct pcmcia_device *link)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700811{
John Daiker141fa612009-03-10 06:59:54 -0700812 struct net_device *dev = link->priv;
813 ray_dev_t *local = netdev_priv(dev);
814 int i;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700815
John Daiker141fa612009-03-10 06:59:54 -0700816 DEBUG(1, "ray_release(0x%p)\n", link);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700817
John Daiker141fa612009-03-10 06:59:54 -0700818 del_timer(&local->timer);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700819
John Daiker141fa612009-03-10 06:59:54 -0700820 iounmap(local->sram);
821 iounmap(local->rmem);
822 iounmap(local->amem);
823 /* Do bother checking to see if these succeed or not */
824 i = pcmcia_release_window(local->amem_handle);
825 if (i != 0)
826 DEBUG(0, "ReleaseWindow(local->amem) ret = %x\n", i);
827 i = pcmcia_release_window(local->rmem_handle);
828 if (i != 0)
829 DEBUG(0, "ReleaseWindow(local->rmem) ret = %x\n", i);
830 pcmcia_disable_device(link);
831
832 DEBUG(2, "ray_release ending\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700833}
834
Dominik Brodowskifba395e2006-03-31 17:21:06 +0200835static int ray_suspend(struct pcmcia_device *link)
Dominik Brodowski98e4c282005-11-14 21:21:18 +0100836{
Dominik Brodowski98e4c282005-11-14 21:21:18 +0100837 struct net_device *dev = link->priv;
838
Dominik Brodowskie2d40962006-03-02 00:09:29 +0100839 if (link->open)
Dominik Brodowski8661bb52006-03-02 00:02:33 +0100840 netif_device_detach(dev);
Dominik Brodowski98e4c282005-11-14 21:21:18 +0100841
842 return 0;
843}
844
Dominik Brodowskifba395e2006-03-31 17:21:06 +0200845static int ray_resume(struct pcmcia_device *link)
Dominik Brodowski98e4c282005-11-14 21:21:18 +0100846{
Dominik Brodowski98e4c282005-11-14 21:21:18 +0100847 struct net_device *dev = link->priv;
848
Dominik Brodowskie2d40962006-03-02 00:09:29 +0100849 if (link->open) {
Dominik Brodowski8661bb52006-03-02 00:02:33 +0100850 ray_reset(dev);
851 netif_device_attach(dev);
852 }
Dominik Brodowski98e4c282005-11-14 21:21:18 +0100853
854 return 0;
855}
856
Linus Torvalds1da177e2005-04-16 15:20:36 -0700857/*===========================================================================*/
Hannes Eder2ed5ba82008-12-26 00:12:59 -0800858static int ray_dev_init(struct net_device *dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700859{
860#ifdef RAY_IMMEDIATE_INIT
John Daiker141fa612009-03-10 06:59:54 -0700861 int i;
862#endif /* RAY_IMMEDIATE_INIT */
863 ray_dev_t *local = netdev_priv(dev);
864 struct pcmcia_device *link = local->finder;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700865
John Daiker141fa612009-03-10 06:59:54 -0700866 DEBUG(1, "ray_dev_init(dev=%p)\n", dev);
867 if (!(pcmcia_dev_present(link))) {
868 DEBUG(2, "ray_dev_init - device not present\n");
869 return -1;
870 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700871#ifdef RAY_IMMEDIATE_INIT
John Daiker141fa612009-03-10 06:59:54 -0700872 /* Download startup parameters */
873 if ((i = dl_startup_params(dev)) < 0) {
874 printk(KERN_INFO "ray_dev_init dl_startup_params failed - "
875 "returns 0x%x\n", i);
876 return -1;
877 }
878#else /* RAY_IMMEDIATE_INIT */
879 /* Postpone the card init so that we can still configure the card,
880 * for example using the Wireless Extensions. The init will happen
881 * in ray_open() - Jean II */
882 DEBUG(1,
883 "ray_dev_init: postponing card init to ray_open() ; Status = %d\n",
884 local->card_status);
885#endif /* RAY_IMMEDIATE_INIT */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700886
John Daiker141fa612009-03-10 06:59:54 -0700887 /* copy mac and broadcast addresses to linux device */
888 memcpy(&dev->dev_addr, &local->sparm.b4.a_mac_addr, ADDRLEN);
889 memset(dev->broadcast, 0xff, ETH_ALEN);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700890
John Daiker141fa612009-03-10 06:59:54 -0700891 DEBUG(2, "ray_dev_init ending\n");
892 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700893}
John Daiker141fa612009-03-10 06:59:54 -0700894
Linus Torvalds1da177e2005-04-16 15:20:36 -0700895/*===========================================================================*/
896static int ray_dev_config(struct net_device *dev, struct ifmap *map)
897{
John Daiker141fa612009-03-10 06:59:54 -0700898 ray_dev_t *local = netdev_priv(dev);
899 struct pcmcia_device *link = local->finder;
900 /* Dummy routine to satisfy device structure */
901 DEBUG(1, "ray_dev_config(dev=%p,ifmap=%p)\n", dev, map);
902 if (!(pcmcia_dev_present(link))) {
903 DEBUG(2, "ray_dev_config - device not present\n");
904 return -1;
905 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700906
John Daiker141fa612009-03-10 06:59:54 -0700907 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700908}
John Daiker141fa612009-03-10 06:59:54 -0700909
Linus Torvalds1da177e2005-04-16 15:20:36 -0700910/*===========================================================================*/
911static int ray_dev_start_xmit(struct sk_buff *skb, struct net_device *dev)
912{
John Daiker141fa612009-03-10 06:59:54 -0700913 ray_dev_t *local = netdev_priv(dev);
914 struct pcmcia_device *link = local->finder;
915 short length = skb->len;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700916
John Daiker141fa612009-03-10 06:59:54 -0700917 if (!(pcmcia_dev_present(link))) {
918 DEBUG(2, "ray_dev_start_xmit - device not present\n");
919 return -1;
920 }
921 DEBUG(3, "ray_dev_start_xmit(skb=%p, dev=%p)\n", skb, dev);
922 if (local->authentication_state == NEED_TO_AUTH) {
923 DEBUG(0, "ray_cs Sending authentication request.\n");
924 if (!build_auth_frame(local, local->auth_id, OPEN_AUTH_REQUEST)) {
925 local->authentication_state = AUTHENTICATED;
926 netif_stop_queue(dev);
927 return 1;
928 }
929 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700930
John Daiker141fa612009-03-10 06:59:54 -0700931 if (length < ETH_ZLEN) {
932 if (skb_padto(skb, ETH_ZLEN))
933 return 0;
934 length = ETH_ZLEN;
935 }
936 switch (ray_hw_xmit(skb->data, length, dev, DATA_TYPE)) {
937 case XMIT_NO_CCS:
938 case XMIT_NEED_AUTH:
939 netif_stop_queue(dev);
940 return 1;
941 case XMIT_NO_INTR:
942 case XMIT_MSG_BAD:
943 case XMIT_OK:
944 default:
945 dev->trans_start = jiffies;
946 dev_kfree_skb(skb);
947 return 0;
948 }
949 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700950} /* ray_dev_start_xmit */
John Daiker141fa612009-03-10 06:59:54 -0700951
Linus Torvalds1da177e2005-04-16 15:20:36 -0700952/*===========================================================================*/
John Daiker141fa612009-03-10 06:59:54 -0700953static int ray_hw_xmit(unsigned char *data, int len, struct net_device *dev,
954 UCHAR msg_type)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700955{
John Daiker141fa612009-03-10 06:59:54 -0700956 ray_dev_t *local = netdev_priv(dev);
957 struct ccs __iomem *pccs;
958 int ccsindex;
959 int offset;
960 struct tx_msg __iomem *ptx; /* Address of xmit buffer in PC space */
961 short int addr; /* Address of xmit buffer in card space */
962
963 DEBUG(3, "ray_hw_xmit(data=%p, len=%d, dev=%p)\n", data, len, dev);
964 if (len + TX_HEADER_LENGTH > TX_BUF_SIZE) {
965 printk(KERN_INFO "ray_hw_xmit packet too large: %d bytes\n",
966 len);
967 return XMIT_MSG_BAD;
968 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700969 switch (ccsindex = get_free_tx_ccs(local)) {
970 case ECCSBUSY:
John Daiker141fa612009-03-10 06:59:54 -0700971 DEBUG(2, "ray_hw_xmit tx_ccs table busy\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700972 case ECCSFULL:
John Daiker141fa612009-03-10 06:59:54 -0700973 DEBUG(2, "ray_hw_xmit No free tx ccs\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700974 case ECARDGONE:
John Daiker141fa612009-03-10 06:59:54 -0700975 netif_stop_queue(dev);
976 return XMIT_NO_CCS;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700977 default:
978 break;
979 }
John Daiker141fa612009-03-10 06:59:54 -0700980 addr = TX_BUF_BASE + (ccsindex << 11);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700981
John Daiker141fa612009-03-10 06:59:54 -0700982 if (msg_type == DATA_TYPE) {
983 local->stats.tx_bytes += len;
984 local->stats.tx_packets++;
985 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700986
John Daiker141fa612009-03-10 06:59:54 -0700987 ptx = local->sram + addr;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700988
John Daiker141fa612009-03-10 06:59:54 -0700989 ray_build_header(local, ptx, msg_type, data);
990 if (translate) {
991 offset = translate_frame(local, ptx, data, len);
992 } else { /* Encapsulate frame */
993 /* TBD TIB length will move address of ptx->var */
994 memcpy_toio(&ptx->var, data, len);
995 offset = 0;
996 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700997
John Daiker141fa612009-03-10 06:59:54 -0700998 /* fill in the CCS */
999 pccs = ccs_base(local) + ccsindex;
1000 len += TX_HEADER_LENGTH + offset;
1001 writeb(CCS_TX_REQUEST, &pccs->cmd);
1002 writeb(addr >> 8, &pccs->var.tx_request.tx_data_ptr[0]);
1003 writeb(local->tib_length, &pccs->var.tx_request.tx_data_ptr[1]);
1004 writeb(len >> 8, &pccs->var.tx_request.tx_data_length[0]);
1005 writeb(len & 0xff, &pccs->var.tx_request.tx_data_length[1]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001006/* TBD still need psm_cam? */
John Daiker141fa612009-03-10 06:59:54 -07001007 writeb(PSM_CAM, &pccs->var.tx_request.pow_sav_mode);
1008 writeb(local->net_default_tx_rate, &pccs->var.tx_request.tx_rate);
1009 writeb(0, &pccs->var.tx_request.antenna);
1010 DEBUG(3, "ray_hw_xmit default_tx_rate = 0x%x\n",
1011 local->net_default_tx_rate);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001012
John Daiker141fa612009-03-10 06:59:54 -07001013 /* Interrupt the firmware to process the command */
1014 if (interrupt_ecf(local, ccsindex)) {
1015 DEBUG(2, "ray_hw_xmit failed - ECF not ready for intr\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001016/* TBD very inefficient to copy packet to buffer, and then not
1017 send it, but the alternative is to queue the messages and that
1018 won't be done for a while. Maybe set tbusy until a CCS is free?
1019*/
John Daiker141fa612009-03-10 06:59:54 -07001020 writeb(CCS_BUFFER_FREE, &pccs->buffer_status);
1021 return XMIT_NO_INTR;
1022 }
1023 return XMIT_OK;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001024} /* end ray_hw_xmit */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001025
John Daiker141fa612009-03-10 06:59:54 -07001026/*===========================================================================*/
1027static int translate_frame(ray_dev_t *local, struct tx_msg __iomem *ptx,
1028 unsigned char *data, int len)
1029{
1030 __be16 proto = ((struct ethhdr *)data)->h_proto;
1031 if (ntohs(proto) >= 1536) { /* DIX II ethernet frame */
1032 DEBUG(3, "ray_cs translate_frame DIX II\n");
1033 /* Copy LLC header to card buffer */
1034 memcpy_toio(&ptx->var, eth2_llc, sizeof(eth2_llc));
1035 memcpy_toio(((void __iomem *)&ptx->var) + sizeof(eth2_llc),
1036 (UCHAR *) &proto, 2);
1037 if (proto == htons(ETH_P_AARP) || proto == htons(ETH_P_IPX)) {
1038 /* This is the selective translation table, only 2 entries */
1039 writeb(0xf8,
1040 &((struct snaphdr_t __iomem *)ptx->var)->org[3]);
1041 }
1042 /* Copy body of ethernet packet without ethernet header */
1043 memcpy_toio((void __iomem *)&ptx->var +
1044 sizeof(struct snaphdr_t), data + ETH_HLEN,
1045 len - ETH_HLEN);
1046 return (int)sizeof(struct snaphdr_t) - ETH_HLEN;
1047 } else { /* already 802 type, and proto is length */
1048 DEBUG(3, "ray_cs translate_frame 802\n");
1049 if (proto == htons(0xffff)) { /* evil netware IPX 802.3 without LLC */
1050 DEBUG(3, "ray_cs translate_frame evil IPX\n");
1051 memcpy_toio(&ptx->var, data + ETH_HLEN, len - ETH_HLEN);
1052 return 0 - ETH_HLEN;
1053 }
1054 memcpy_toio(&ptx->var, data + ETH_HLEN, len - ETH_HLEN);
1055 return 0 - ETH_HLEN;
1056 }
1057 /* TBD do other frame types */
1058} /* end translate_frame */
1059
1060/*===========================================================================*/
1061static void ray_build_header(ray_dev_t *local, struct tx_msg __iomem *ptx,
1062 UCHAR msg_type, unsigned char *data)
1063{
1064 writeb(PROTOCOL_VER | msg_type, &ptx->mac.frame_ctl_1);
1065/*** IEEE 802.11 Address field assignments *************
1066 TODS FROMDS addr_1 addr_2 addr_3 addr_4
1067Adhoc 0 0 dest src (terminal) BSSID N/A
1068AP to Terminal 0 1 dest AP(BSSID) source N/A
1069Terminal to AP 1 0 AP(BSSID) src (terminal) dest N/A
1070AP to AP 1 1 dest AP src AP dest source
1071*******************************************************/
1072 if (local->net_type == ADHOC) {
1073 writeb(0, &ptx->mac.frame_ctl_2);
1074 memcpy_toio(ptx->mac.addr_1, ((struct ethhdr *)data)->h_dest,
1075 2 * ADDRLEN);
1076 memcpy_toio(ptx->mac.addr_3, local->bss_id, ADDRLEN);
1077 } else { /* infrastructure */
1078
1079 if (local->sparm.b4.a_acting_as_ap_status) {
1080 writeb(FC2_FROM_DS, &ptx->mac.frame_ctl_2);
1081 memcpy_toio(ptx->mac.addr_1,
1082 ((struct ethhdr *)data)->h_dest, ADDRLEN);
1083 memcpy_toio(ptx->mac.addr_2, local->bss_id, 6);
1084 memcpy_toio(ptx->mac.addr_3,
1085 ((struct ethhdr *)data)->h_source, ADDRLEN);
1086 } else { /* Terminal */
1087
1088 writeb(FC2_TO_DS, &ptx->mac.frame_ctl_2);
1089 memcpy_toio(ptx->mac.addr_1, local->bss_id, ADDRLEN);
1090 memcpy_toio(ptx->mac.addr_2,
1091 ((struct ethhdr *)data)->h_source, ADDRLEN);
1092 memcpy_toio(ptx->mac.addr_3,
1093 ((struct ethhdr *)data)->h_dest, ADDRLEN);
1094 }
1095 }
1096} /* end encapsulate_frame */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001097
1098/*===========================================================================*/
1099
1100static void netdev_get_drvinfo(struct net_device *dev,
1101 struct ethtool_drvinfo *info)
1102{
1103 strcpy(info->driver, "ray_cs");
1104}
1105
Jeff Garzik7282d492006-09-13 14:30:00 -04001106static const struct ethtool_ops netdev_ethtool_ops = {
John Daiker141fa612009-03-10 06:59:54 -07001107 .get_drvinfo = netdev_get_drvinfo,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001108};
1109
1110/*====================================================================*/
1111
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001112/*------------------------------------------------------------------*/
1113/*
1114 * Wireless Handler : get protocol name
1115 */
1116static int ray_get_name(struct net_device *dev,
John Daiker141fa612009-03-10 06:59:54 -07001117 struct iw_request_info *info, char *cwrq, char *extra)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001118{
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001119 strcpy(cwrq, "IEEE 802.11-FH");
1120 return 0;
1121}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001122
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001123/*------------------------------------------------------------------*/
1124/*
1125 * Wireless Handler : set frequency
1126 */
1127static int ray_set_freq(struct net_device *dev,
1128 struct iw_request_info *info,
John Daiker141fa612009-03-10 06:59:54 -07001129 struct iw_freq *fwrq, char *extra)
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001130{
Yoann Padioleau6dbc9c82007-08-03 19:37:16 +02001131 ray_dev_t *local = netdev_priv(dev);
John Daiker141fa612009-03-10 06:59:54 -07001132 int err = -EINPROGRESS; /* Call commit handler */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001133
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001134 /* Reject if card is already initialised */
John Daiker141fa612009-03-10 06:59:54 -07001135 if (local->card_status != CARD_AWAITING_PARAM)
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001136 return -EBUSY;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001137
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001138 /* Setting by channel number */
1139 if ((fwrq->m > USA_HOP_MOD) || (fwrq->e > 0))
Linus Torvalds1da177e2005-04-16 15:20:36 -07001140 err = -EOPNOTSUPP;
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001141 else
1142 local->sparm.b5.a_hop_pattern = fwrq->m;
1143
1144 return err;
1145}
John Daiker141fa612009-03-10 06:59:54 -07001146
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001147/*------------------------------------------------------------------*/
1148/*
1149 * Wireless Handler : get frequency
1150 */
1151static int ray_get_freq(struct net_device *dev,
1152 struct iw_request_info *info,
John Daiker141fa612009-03-10 06:59:54 -07001153 struct iw_freq *fwrq, char *extra)
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001154{
Yoann Padioleau6dbc9c82007-08-03 19:37:16 +02001155 ray_dev_t *local = netdev_priv(dev);
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001156
1157 fwrq->m = local->sparm.b5.a_hop_pattern;
1158 fwrq->e = 0;
1159 return 0;
1160}
1161
1162/*------------------------------------------------------------------*/
1163/*
1164 * Wireless Handler : set ESSID
1165 */
1166static int ray_set_essid(struct net_device *dev,
1167 struct iw_request_info *info,
John Daiker141fa612009-03-10 06:59:54 -07001168 struct iw_point *dwrq, char *extra)
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001169{
Yoann Padioleau6dbc9c82007-08-03 19:37:16 +02001170 ray_dev_t *local = netdev_priv(dev);
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001171
1172 /* Reject if card is already initialised */
John Daiker141fa612009-03-10 06:59:54 -07001173 if (local->card_status != CARD_AWAITING_PARAM)
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001174 return -EBUSY;
1175
1176 /* Check if we asked for `any' */
John Daiker141fa612009-03-10 06:59:54 -07001177 if (dwrq->flags == 0) {
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001178 /* Corey : can you do that ? */
1179 return -EOPNOTSUPP;
1180 } else {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001181 /* Check the size of the string */
John Daiker141fa612009-03-10 06:59:54 -07001182 if (dwrq->length > IW_ESSID_MAX_SIZE) {
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001183 return -E2BIG;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001184 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001185
1186 /* Set the ESSID in the card */
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001187 memset(local->sparm.b5.a_current_ess_id, 0, IW_ESSID_MAX_SIZE);
1188 memcpy(local->sparm.b5.a_current_ess_id, extra, dwrq->length);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001189 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001190
John Daiker141fa612009-03-10 06:59:54 -07001191 return -EINPROGRESS; /* Call commit handler */
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001192}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001193
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001194/*------------------------------------------------------------------*/
1195/*
1196 * Wireless Handler : get ESSID
1197 */
1198static int ray_get_essid(struct net_device *dev,
1199 struct iw_request_info *info,
John Daiker141fa612009-03-10 06:59:54 -07001200 struct iw_point *dwrq, char *extra)
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001201{
Yoann Padioleau6dbc9c82007-08-03 19:37:16 +02001202 ray_dev_t *local = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001203
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001204 /* Get the essid that was set */
1205 memcpy(extra, local->sparm.b5.a_current_ess_id, IW_ESSID_MAX_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001206
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001207 /* Push it out ! */
Dan Williamsd6a13a22006-01-12 15:00:58 -05001208 dwrq->length = strlen(extra);
John Daiker141fa612009-03-10 06:59:54 -07001209 dwrq->flags = 1; /* active */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001210
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001211 return 0;
1212}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001213
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001214/*------------------------------------------------------------------*/
1215/*
1216 * Wireless Handler : get AP address
1217 */
1218static int ray_get_wap(struct net_device *dev,
John Daiker141fa612009-03-10 06:59:54 -07001219 struct iw_request_info *info,
1220 struct sockaddr *awrq, char *extra)
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001221{
Yoann Padioleau6dbc9c82007-08-03 19:37:16 +02001222 ray_dev_t *local = netdev_priv(dev);
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001223
1224 memcpy(awrq->sa_data, local->bss_id, ETH_ALEN);
1225 awrq->sa_family = ARPHRD_ETHER;
1226
1227 return 0;
1228}
1229
1230/*------------------------------------------------------------------*/
1231/*
1232 * Wireless Handler : set Bit-Rate
1233 */
1234static int ray_set_rate(struct net_device *dev,
1235 struct iw_request_info *info,
John Daiker141fa612009-03-10 06:59:54 -07001236 struct iw_param *vwrq, char *extra)
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001237{
Yoann Padioleau6dbc9c82007-08-03 19:37:16 +02001238 ray_dev_t *local = netdev_priv(dev);
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001239
1240 /* Reject if card is already initialised */
John Daiker141fa612009-03-10 06:59:54 -07001241 if (local->card_status != CARD_AWAITING_PARAM)
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001242 return -EBUSY;
1243
1244 /* Check if rate is in range */
John Daiker141fa612009-03-10 06:59:54 -07001245 if ((vwrq->value != 1000000) && (vwrq->value != 2000000))
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001246 return -EINVAL;
1247
1248 /* Hack for 1.5 Mb/s instead of 2 Mb/s */
John Daiker141fa612009-03-10 06:59:54 -07001249 if ((local->fw_ver == 0x55) && /* Please check */
1250 (vwrq->value == 2000000))
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001251 local->net_default_tx_rate = 3;
1252 else
John Daiker141fa612009-03-10 06:59:54 -07001253 local->net_default_tx_rate = vwrq->value / 500000;
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001254
1255 return 0;
1256}
1257
1258/*------------------------------------------------------------------*/
1259/*
1260 * Wireless Handler : get Bit-Rate
1261 */
1262static int ray_get_rate(struct net_device *dev,
1263 struct iw_request_info *info,
John Daiker141fa612009-03-10 06:59:54 -07001264 struct iw_param *vwrq, char *extra)
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001265{
Yoann Padioleau6dbc9c82007-08-03 19:37:16 +02001266 ray_dev_t *local = netdev_priv(dev);
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001267
John Daiker141fa612009-03-10 06:59:54 -07001268 if (local->net_default_tx_rate == 3)
1269 vwrq->value = 2000000; /* Hum... */
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001270 else
1271 vwrq->value = local->net_default_tx_rate * 500000;
John Daiker141fa612009-03-10 06:59:54 -07001272 vwrq->fixed = 0; /* We are in auto mode */
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001273
1274 return 0;
1275}
1276
1277/*------------------------------------------------------------------*/
1278/*
1279 * Wireless Handler : set RTS threshold
1280 */
1281static int ray_set_rts(struct net_device *dev,
1282 struct iw_request_info *info,
John Daiker141fa612009-03-10 06:59:54 -07001283 struct iw_param *vwrq, char *extra)
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001284{
Yoann Padioleau6dbc9c82007-08-03 19:37:16 +02001285 ray_dev_t *local = netdev_priv(dev);
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001286 int rthr = vwrq->value;
1287
1288 /* Reject if card is already initialised */
John Daiker141fa612009-03-10 06:59:54 -07001289 if (local->card_status != CARD_AWAITING_PARAM)
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001290 return -EBUSY;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001291
1292 /* if(wrq->u.rts.fixed == 0) we should complain */
John Daiker141fa612009-03-10 06:59:54 -07001293 if (vwrq->disabled)
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001294 rthr = 32767;
1295 else {
John Daiker141fa612009-03-10 06:59:54 -07001296 if ((rthr < 0) || (rthr > 2347)) /* What's the max packet size ??? */
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001297 return -EINVAL;
1298 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001299 local->sparm.b5.a_rts_threshold[0] = (rthr >> 8) & 0xFF;
1300 local->sparm.b5.a_rts_threshold[1] = rthr & 0xFF;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001301
John Daiker141fa612009-03-10 06:59:54 -07001302 return -EINPROGRESS; /* Call commit handler */
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001303}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001304
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001305/*------------------------------------------------------------------*/
1306/*
1307 * Wireless Handler : get RTS threshold
1308 */
1309static int ray_get_rts(struct net_device *dev,
1310 struct iw_request_info *info,
John Daiker141fa612009-03-10 06:59:54 -07001311 struct iw_param *vwrq, char *extra)
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001312{
Yoann Padioleau6dbc9c82007-08-03 19:37:16 +02001313 ray_dev_t *local = netdev_priv(dev);
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001314
1315 vwrq->value = (local->sparm.b5.a_rts_threshold[0] << 8)
John Daiker141fa612009-03-10 06:59:54 -07001316 + local->sparm.b5.a_rts_threshold[1];
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001317 vwrq->disabled = (vwrq->value == 32767);
1318 vwrq->fixed = 1;
1319
1320 return 0;
1321}
1322
1323/*------------------------------------------------------------------*/
1324/*
1325 * Wireless Handler : set Fragmentation threshold
1326 */
1327static int ray_set_frag(struct net_device *dev,
1328 struct iw_request_info *info,
John Daiker141fa612009-03-10 06:59:54 -07001329 struct iw_param *vwrq, char *extra)
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001330{
Yoann Padioleau6dbc9c82007-08-03 19:37:16 +02001331 ray_dev_t *local = netdev_priv(dev);
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001332 int fthr = vwrq->value;
1333
1334 /* Reject if card is already initialised */
John Daiker141fa612009-03-10 06:59:54 -07001335 if (local->card_status != CARD_AWAITING_PARAM)
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001336 return -EBUSY;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001337
1338 /* if(wrq->u.frag.fixed == 0) should complain */
John Daiker141fa612009-03-10 06:59:54 -07001339 if (vwrq->disabled)
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001340 fthr = 32767;
1341 else {
John Daiker141fa612009-03-10 06:59:54 -07001342 if ((fthr < 256) || (fthr > 2347)) /* To check out ! */
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001343 return -EINVAL;
1344 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001345 local->sparm.b5.a_frag_threshold[0] = (fthr >> 8) & 0xFF;
1346 local->sparm.b5.a_frag_threshold[1] = fthr & 0xFF;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001347
John Daiker141fa612009-03-10 06:59:54 -07001348 return -EINPROGRESS; /* Call commit handler */
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001349}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001350
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001351/*------------------------------------------------------------------*/
1352/*
1353 * Wireless Handler : get Fragmentation threshold
1354 */
1355static int ray_get_frag(struct net_device *dev,
1356 struct iw_request_info *info,
John Daiker141fa612009-03-10 06:59:54 -07001357 struct iw_param *vwrq, char *extra)
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001358{
Yoann Padioleau6dbc9c82007-08-03 19:37:16 +02001359 ray_dev_t *local = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001360
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001361 vwrq->value = (local->sparm.b5.a_frag_threshold[0] << 8)
John Daiker141fa612009-03-10 06:59:54 -07001362 + local->sparm.b5.a_frag_threshold[1];
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001363 vwrq->disabled = (vwrq->value == 32767);
1364 vwrq->fixed = 1;
1365
1366 return 0;
1367}
1368
1369/*------------------------------------------------------------------*/
1370/*
1371 * Wireless Handler : set Mode of Operation
1372 */
1373static int ray_set_mode(struct net_device *dev,
John Daiker141fa612009-03-10 06:59:54 -07001374 struct iw_request_info *info, __u32 *uwrq, char *extra)
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001375{
Yoann Padioleau6dbc9c82007-08-03 19:37:16 +02001376 ray_dev_t *local = netdev_priv(dev);
John Daiker141fa612009-03-10 06:59:54 -07001377 int err = -EINPROGRESS; /* Call commit handler */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001378 char card_mode = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001379
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001380 /* Reject if card is already initialised */
John Daiker141fa612009-03-10 06:59:54 -07001381 if (local->card_status != CARD_AWAITING_PARAM)
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001382 return -EBUSY;
1383
John Daiker141fa612009-03-10 06:59:54 -07001384 switch (*uwrq) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001385 case IW_MODE_ADHOC:
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001386 card_mode = 0;
John Daiker141fa612009-03-10 06:59:54 -07001387 /* Fall through */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001388 case IW_MODE_INFRA:
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001389 local->sparm.b5.a_network_type = card_mode;
1390 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001391 default:
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001392 err = -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001393 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001394
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001395 return err;
1396}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001397
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001398/*------------------------------------------------------------------*/
1399/*
1400 * Wireless Handler : get Mode of Operation
1401 */
1402static int ray_get_mode(struct net_device *dev,
John Daiker141fa612009-03-10 06:59:54 -07001403 struct iw_request_info *info, __u32 *uwrq, char *extra)
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001404{
Yoann Padioleau6dbc9c82007-08-03 19:37:16 +02001405 ray_dev_t *local = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001406
John Daiker141fa612009-03-10 06:59:54 -07001407 if (local->sparm.b5.a_network_type)
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001408 *uwrq = IW_MODE_INFRA;
1409 else
1410 *uwrq = IW_MODE_ADHOC;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001411
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001412 return 0;
1413}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001414
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001415/*------------------------------------------------------------------*/
1416/*
1417 * Wireless Handler : get range info
1418 */
1419static int ray_get_range(struct net_device *dev,
1420 struct iw_request_info *info,
John Daiker141fa612009-03-10 06:59:54 -07001421 struct iw_point *dwrq, char *extra)
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001422{
John Daiker141fa612009-03-10 06:59:54 -07001423 struct iw_range *range = (struct iw_range *)extra;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001424
John Daiker141fa612009-03-10 06:59:54 -07001425 memset((char *)range, 0, sizeof(struct iw_range));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001426
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001427 /* Set the length (very important for backward compatibility) */
1428 dwrq->length = sizeof(struct iw_range);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001429
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001430 /* Set the Wireless Extension versions */
1431 range->we_version_compiled = WIRELESS_EXT;
1432 range->we_version_source = 9;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001433
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001434 /* Set information in the range struct */
1435 range->throughput = 1.1 * 1000 * 1000; /* Put the right number here */
John Daiker141fa612009-03-10 06:59:54 -07001436 range->num_channels = hop_pattern_length[(int)country];
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001437 range->num_frequency = 0;
1438 range->max_qual.qual = 0;
1439 range->max_qual.level = 255; /* What's the correct value ? */
1440 range->max_qual.noise = 255; /* Idem */
1441 range->num_bitrates = 2;
1442 range->bitrate[0] = 1000000; /* 1 Mb/s */
1443 range->bitrate[1] = 2000000; /* 2 Mb/s */
1444 return 0;
1445}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001446
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001447/*------------------------------------------------------------------*/
1448/*
1449 * Wireless Private Handler : set framing mode
1450 */
1451static int ray_set_framing(struct net_device *dev,
1452 struct iw_request_info *info,
John Daiker141fa612009-03-10 06:59:54 -07001453 union iwreq_data *wrqu, char *extra)
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001454{
1455 translate = *(extra); /* Set framing mode */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001456
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001457 return 0;
1458}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001459
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001460/*------------------------------------------------------------------*/
1461/*
1462 * Wireless Private Handler : get framing mode
1463 */
1464static int ray_get_framing(struct net_device *dev,
1465 struct iw_request_info *info,
John Daiker141fa612009-03-10 06:59:54 -07001466 union iwreq_data *wrqu, char *extra)
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001467{
1468 *(extra) = translate;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001469
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001470 return 0;
1471}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001472
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001473/*------------------------------------------------------------------*/
1474/*
1475 * Wireless Private Handler : get country
1476 */
1477static int ray_get_country(struct net_device *dev,
1478 struct iw_request_info *info,
John Daiker141fa612009-03-10 06:59:54 -07001479 union iwreq_data *wrqu, char *extra)
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001480{
1481 *(extra) = country;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001482
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001483 return 0;
1484}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001485
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001486/*------------------------------------------------------------------*/
1487/*
1488 * Commit handler : called after a bunch of SET operations
1489 */
John Daiker141fa612009-03-10 06:59:54 -07001490static int ray_commit(struct net_device *dev, struct iw_request_info *info, /* NULL */
1491 void *zwrq, /* NULL */
1492 char *extra)
1493{ /* NULL */
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001494 return 0;
1495}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001496
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001497/*------------------------------------------------------------------*/
1498/*
1499 * Stats handler : return Wireless Stats
1500 */
John Daiker141fa612009-03-10 06:59:54 -07001501static iw_stats *ray_get_wireless_stats(struct net_device *dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001502{
John Daiker141fa612009-03-10 06:59:54 -07001503 ray_dev_t *local = netdev_priv(dev);
1504 struct pcmcia_device *link = local->finder;
1505 struct status __iomem *p = local->sram + STATUS_BASE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001506
John Daiker141fa612009-03-10 06:59:54 -07001507 if (local == (ray_dev_t *) NULL)
1508 return (iw_stats *) NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001509
John Daiker141fa612009-03-10 06:59:54 -07001510 local->wstats.status = local->card_status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001511#ifdef WIRELESS_SPY
John Daiker141fa612009-03-10 06:59:54 -07001512 if ((local->spy_data.spy_number > 0)
1513 && (local->sparm.b5.a_network_type == 0)) {
1514 /* Get it from the first node in spy list */
1515 local->wstats.qual.qual = local->spy_data.spy_stat[0].qual;
1516 local->wstats.qual.level = local->spy_data.spy_stat[0].level;
1517 local->wstats.qual.noise = local->spy_data.spy_stat[0].noise;
1518 local->wstats.qual.updated =
1519 local->spy_data.spy_stat[0].updated;
1520 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001521#endif /* WIRELESS_SPY */
1522
John Daiker141fa612009-03-10 06:59:54 -07001523 if (pcmcia_dev_present(link)) {
1524 local->wstats.qual.noise = readb(&p->rxnoise);
1525 local->wstats.qual.updated |= 4;
1526 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001527
John Daiker141fa612009-03-10 06:59:54 -07001528 return &local->wstats;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001529} /* end ray_get_wireless_stats */
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001530
1531/*------------------------------------------------------------------*/
1532/*
1533 * Structures to export the Wireless Handlers
1534 */
1535
John Daiker141fa612009-03-10 06:59:54 -07001536static const iw_handler ray_handler[] = {
1537 [SIOCSIWCOMMIT - SIOCIWFIRST] = (iw_handler) ray_commit,
1538 [SIOCGIWNAME - SIOCIWFIRST] = (iw_handler) ray_get_name,
1539 [SIOCSIWFREQ - SIOCIWFIRST] = (iw_handler) ray_set_freq,
1540 [SIOCGIWFREQ - SIOCIWFIRST] = (iw_handler) ray_get_freq,
1541 [SIOCSIWMODE - SIOCIWFIRST] = (iw_handler) ray_set_mode,
1542 [SIOCGIWMODE - SIOCIWFIRST] = (iw_handler) ray_get_mode,
1543 [SIOCGIWRANGE - SIOCIWFIRST] = (iw_handler) ray_get_range,
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001544#ifdef WIRELESS_SPY
John Daiker141fa612009-03-10 06:59:54 -07001545 [SIOCSIWSPY - SIOCIWFIRST] = (iw_handler) iw_handler_set_spy,
1546 [SIOCGIWSPY - SIOCIWFIRST] = (iw_handler) iw_handler_get_spy,
1547 [SIOCSIWTHRSPY - SIOCIWFIRST] = (iw_handler) iw_handler_set_thrspy,
1548 [SIOCGIWTHRSPY - SIOCIWFIRST] = (iw_handler) iw_handler_get_thrspy,
1549#endif /* WIRELESS_SPY */
1550 [SIOCGIWAP - SIOCIWFIRST] = (iw_handler) ray_get_wap,
1551 [SIOCSIWESSID - SIOCIWFIRST] = (iw_handler) ray_set_essid,
1552 [SIOCGIWESSID - SIOCIWFIRST] = (iw_handler) ray_get_essid,
1553 [SIOCSIWRATE - SIOCIWFIRST] = (iw_handler) ray_set_rate,
1554 [SIOCGIWRATE - SIOCIWFIRST] = (iw_handler) ray_get_rate,
1555 [SIOCSIWRTS - SIOCIWFIRST] = (iw_handler) ray_set_rts,
1556 [SIOCGIWRTS - SIOCIWFIRST] = (iw_handler) ray_get_rts,
1557 [SIOCSIWFRAG - SIOCIWFIRST] = (iw_handler) ray_set_frag,
1558 [SIOCGIWFRAG - SIOCIWFIRST] = (iw_handler) ray_get_frag,
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001559};
1560
John Daiker141fa612009-03-10 06:59:54 -07001561#define SIOCSIPFRAMING SIOCIWFIRSTPRIV /* Set framing mode */
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001562#define SIOCGIPFRAMING SIOCIWFIRSTPRIV + 1 /* Get framing mode */
1563#define SIOCGIPCOUNTRY SIOCIWFIRSTPRIV + 3 /* Get country code */
1564
John Daiker141fa612009-03-10 06:59:54 -07001565static const iw_handler ray_private_handler[] = {
viro@ZenIV.linux.org.uk7a700fa2005-09-09 20:40:23 +01001566 [0] = (iw_handler) ray_set_framing,
1567 [1] = (iw_handler) ray_get_framing,
1568 [3] = (iw_handler) ray_get_country,
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001569};
1570
John Daiker141fa612009-03-10 06:59:54 -07001571static const struct iw_priv_args ray_private_args[] = {
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001572/* cmd, set_args, get_args, name */
John Daiker141fa612009-03-10 06:59:54 -07001573 {SIOCSIPFRAMING, IW_PRIV_TYPE_BYTE | IW_PRIV_SIZE_FIXED | 1, 0,
1574 "set_framing"},
1575 {SIOCGIPFRAMING, 0, IW_PRIV_TYPE_BYTE | IW_PRIV_SIZE_FIXED | 1,
1576 "get_framing"},
1577 {SIOCGIPCOUNTRY, 0, IW_PRIV_TYPE_BYTE | IW_PRIV_SIZE_FIXED | 1,
1578 "get_country"},
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001579};
1580
John Daiker141fa612009-03-10 06:59:54 -07001581static const struct iw_handler_def ray_handler_def = {
1582 .num_standard = ARRAY_SIZE(ray_handler),
1583 .num_private = ARRAY_SIZE(ray_private_handler),
Denis Chengff8ac602007-09-02 18:30:18 +08001584 .num_private_args = ARRAY_SIZE(ray_private_args),
John Daiker141fa612009-03-10 06:59:54 -07001585 .standard = ray_handler,
1586 .private = ray_private_handler,
1587 .private_args = ray_private_args,
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001588 .get_wireless_stats = ray_get_wireless_stats,
1589};
1590
Linus Torvalds1da177e2005-04-16 15:20:36 -07001591/*===========================================================================*/
1592static int ray_open(struct net_device *dev)
1593{
John Daiker141fa612009-03-10 06:59:54 -07001594 ray_dev_t *local = netdev_priv(dev);
1595 struct pcmcia_device *link;
1596 link = local->finder;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001597
John Daiker141fa612009-03-10 06:59:54 -07001598 DEBUG(1, "ray_open('%s')\n", dev->name);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001599
John Daiker141fa612009-03-10 06:59:54 -07001600 if (link->open == 0)
1601 local->num_multi = 0;
1602 link->open++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001603
John Daiker141fa612009-03-10 06:59:54 -07001604 /* If the card is not started, time to start it ! - Jean II */
1605 if (local->card_status == CARD_AWAITING_PARAM) {
1606 int i;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001607
John Daiker141fa612009-03-10 06:59:54 -07001608 DEBUG(1, "ray_open: doing init now !\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001609
John Daiker141fa612009-03-10 06:59:54 -07001610 /* Download startup parameters */
1611 if ((i = dl_startup_params(dev)) < 0) {
1612 printk(KERN_INFO
1613 "ray_dev_init dl_startup_params failed - "
1614 "returns 0x%x\n", i);
1615 return -1;
1616 }
1617 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001618
John Daiker141fa612009-03-10 06:59:54 -07001619 if (sniffer)
1620 netif_stop_queue(dev);
1621 else
1622 netif_start_queue(dev);
1623
1624 DEBUG(2, "ray_open ending\n");
1625 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001626} /* end ray_open */
John Daiker141fa612009-03-10 06:59:54 -07001627
Linus Torvalds1da177e2005-04-16 15:20:36 -07001628/*===========================================================================*/
1629static int ray_dev_close(struct net_device *dev)
1630{
John Daiker141fa612009-03-10 06:59:54 -07001631 ray_dev_t *local = netdev_priv(dev);
1632 struct pcmcia_device *link;
1633 link = local->finder;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001634
John Daiker141fa612009-03-10 06:59:54 -07001635 DEBUG(1, "ray_dev_close('%s')\n", dev->name);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001636
John Daiker141fa612009-03-10 06:59:54 -07001637 link->open--;
1638 netif_stop_queue(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001639
John Daiker141fa612009-03-10 06:59:54 -07001640 /* In here, we should stop the hardware (stop card from beeing active)
1641 * and set local->card_status to CARD_AWAITING_PARAM, so that while the
1642 * card is closed we can chage its configuration.
1643 * Probably also need a COR reset to get sane state - Jean II */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001644
John Daiker141fa612009-03-10 06:59:54 -07001645 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001646} /* end ray_dev_close */
John Daiker141fa612009-03-10 06:59:54 -07001647
Linus Torvalds1da177e2005-04-16 15:20:36 -07001648/*===========================================================================*/
John Daiker141fa612009-03-10 06:59:54 -07001649static void ray_reset(struct net_device *dev)
1650{
1651 DEBUG(1, "ray_reset entered\n");
1652 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001653}
John Daiker141fa612009-03-10 06:59:54 -07001654
Linus Torvalds1da177e2005-04-16 15:20:36 -07001655/*===========================================================================*/
1656/* Cause a firmware interrupt if it is ready for one */
1657/* Return nonzero if not ready */
1658static int interrupt_ecf(ray_dev_t *local, int ccs)
1659{
John Daiker141fa612009-03-10 06:59:54 -07001660 int i = 50;
1661 struct pcmcia_device *link = local->finder;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001662
John Daiker141fa612009-03-10 06:59:54 -07001663 if (!(pcmcia_dev_present(link))) {
1664 DEBUG(2, "ray_cs interrupt_ecf - device not present\n");
1665 return -1;
1666 }
1667 DEBUG(2, "interrupt_ecf(local=%p, ccs = 0x%x\n", local, ccs);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001668
John Daiker141fa612009-03-10 06:59:54 -07001669 while (i &&
1670 (readb(local->amem + CIS_OFFSET + ECF_INTR_OFFSET) &
1671 ECF_INTR_SET))
1672 i--;
1673 if (i == 0) {
1674 DEBUG(2, "ray_cs interrupt_ecf card not ready for interrupt\n");
1675 return -1;
1676 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001677 /* Fill the mailbox, then kick the card */
John Daiker141fa612009-03-10 06:59:54 -07001678 writeb(ccs, local->sram + SCB_BASE);
1679 writeb(ECF_INTR_SET, local->amem + CIS_OFFSET + ECF_INTR_OFFSET);
1680 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001681} /* interrupt_ecf */
John Daiker141fa612009-03-10 06:59:54 -07001682
Linus Torvalds1da177e2005-04-16 15:20:36 -07001683/*===========================================================================*/
1684/* Get next free transmit CCS */
1685/* Return - index of current tx ccs */
1686static int get_free_tx_ccs(ray_dev_t *local)
1687{
John Daiker141fa612009-03-10 06:59:54 -07001688 int i;
1689 struct ccs __iomem *pccs = ccs_base(local);
1690 struct pcmcia_device *link = local->finder;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001691
John Daiker141fa612009-03-10 06:59:54 -07001692 if (!(pcmcia_dev_present(link))) {
1693 DEBUG(2, "ray_cs get_free_tx_ccs - device not present\n");
1694 return ECARDGONE;
1695 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001696
John Daiker141fa612009-03-10 06:59:54 -07001697 if (test_and_set_bit(0, &local->tx_ccs_lock)) {
1698 DEBUG(1, "ray_cs tx_ccs_lock busy\n");
1699 return ECCSBUSY;
1700 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001701
John Daiker141fa612009-03-10 06:59:54 -07001702 for (i = 0; i < NUMBER_OF_TX_CCS; i++) {
1703 if (readb(&(pccs + i)->buffer_status) == CCS_BUFFER_FREE) {
1704 writeb(CCS_BUFFER_BUSY, &(pccs + i)->buffer_status);
1705 writeb(CCS_END_LIST, &(pccs + i)->link);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001706 local->tx_ccs_lock = 0;
John Daiker141fa612009-03-10 06:59:54 -07001707 return i;
1708 }
1709 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001710 local->tx_ccs_lock = 0;
John Daiker141fa612009-03-10 06:59:54 -07001711 DEBUG(2, "ray_cs ERROR no free tx CCS for raylink card\n");
1712 return ECCSFULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001713} /* get_free_tx_ccs */
John Daiker141fa612009-03-10 06:59:54 -07001714
Linus Torvalds1da177e2005-04-16 15:20:36 -07001715/*===========================================================================*/
1716/* Get next free CCS */
1717/* Return - index of current ccs */
1718static int get_free_ccs(ray_dev_t *local)
1719{
John Daiker141fa612009-03-10 06:59:54 -07001720 int i;
1721 struct ccs __iomem *pccs = ccs_base(local);
1722 struct pcmcia_device *link = local->finder;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001723
John Daiker141fa612009-03-10 06:59:54 -07001724 if (!(pcmcia_dev_present(link))) {
1725 DEBUG(2, "ray_cs get_free_ccs - device not present\n");
1726 return ECARDGONE;
1727 }
1728 if (test_and_set_bit(0, &local->ccs_lock)) {
1729 DEBUG(1, "ray_cs ccs_lock busy\n");
1730 return ECCSBUSY;
1731 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001732
John Daiker141fa612009-03-10 06:59:54 -07001733 for (i = NUMBER_OF_TX_CCS; i < NUMBER_OF_CCS; i++) {
1734 if (readb(&(pccs + i)->buffer_status) == CCS_BUFFER_FREE) {
1735 writeb(CCS_BUFFER_BUSY, &(pccs + i)->buffer_status);
1736 writeb(CCS_END_LIST, &(pccs + i)->link);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001737 local->ccs_lock = 0;
John Daiker141fa612009-03-10 06:59:54 -07001738 return i;
1739 }
1740 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001741 local->ccs_lock = 0;
John Daiker141fa612009-03-10 06:59:54 -07001742 DEBUG(1, "ray_cs ERROR no free CCS for raylink card\n");
1743 return ECCSFULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001744} /* get_free_ccs */
John Daiker141fa612009-03-10 06:59:54 -07001745
Linus Torvalds1da177e2005-04-16 15:20:36 -07001746/*===========================================================================*/
1747static void authenticate_timeout(u_long data)
1748{
John Daiker141fa612009-03-10 06:59:54 -07001749 ray_dev_t *local = (ray_dev_t *) data;
1750 del_timer(&local->timer);
1751 printk(KERN_INFO "ray_cs Authentication with access point failed"
1752 " - timeout\n");
1753 join_net((u_long) local);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001754}
John Daiker141fa612009-03-10 06:59:54 -07001755
Linus Torvalds1da177e2005-04-16 15:20:36 -07001756/*===========================================================================*/
1757static int asc_to_int(char a)
1758{
John Daiker141fa612009-03-10 06:59:54 -07001759 if (a < '0')
1760 return -1;
1761 if (a <= '9')
1762 return (a - '0');
1763 if (a < 'A')
1764 return -1;
1765 if (a <= 'F')
1766 return (10 + a - 'A');
1767 if (a < 'a')
1768 return -1;
1769 if (a <= 'f')
1770 return (10 + a - 'a');
1771 return -1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001772}
John Daiker141fa612009-03-10 06:59:54 -07001773
Linus Torvalds1da177e2005-04-16 15:20:36 -07001774/*===========================================================================*/
1775static int parse_addr(char *in_str, UCHAR *out)
1776{
John Daiker141fa612009-03-10 06:59:54 -07001777 int len;
1778 int i, j, k;
1779 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001780
John Daiker141fa612009-03-10 06:59:54 -07001781 if (in_str == NULL)
1782 return 0;
1783 if ((len = strlen(in_str)) < 2)
1784 return 0;
1785 memset(out, 0, ADDRLEN);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001786
John Daiker141fa612009-03-10 06:59:54 -07001787 status = 1;
1788 j = len - 1;
1789 if (j > 12)
1790 j = 12;
1791 i = 5;
1792
1793 while (j > 0) {
1794 if ((k = asc_to_int(in_str[j--])) != -1)
1795 out[i] = k;
1796 else
1797 return 0;
1798
1799 if (j == 0)
1800 break;
1801 if ((k = asc_to_int(in_str[j--])) != -1)
1802 out[i] += k << 4;
1803 else
1804 return 0;
1805 if (!i--)
1806 break;
1807 }
1808 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001809}
John Daiker141fa612009-03-10 06:59:54 -07001810
Linus Torvalds1da177e2005-04-16 15:20:36 -07001811/*===========================================================================*/
1812static struct net_device_stats *ray_get_stats(struct net_device *dev)
1813{
John Daiker141fa612009-03-10 06:59:54 -07001814 ray_dev_t *local = netdev_priv(dev);
1815 struct pcmcia_device *link = local->finder;
1816 struct status __iomem *p = local->sram + STATUS_BASE;
1817 if (!(pcmcia_dev_present(link))) {
1818 DEBUG(2, "ray_cs net_device_stats - device not present\n");
1819 return &local->stats;
1820 }
1821 if (readb(&p->mrx_overflow_for_host)) {
1822 local->stats.rx_over_errors += swab16(readw(&p->mrx_overflow));
1823 writeb(0, &p->mrx_overflow);
1824 writeb(0, &p->mrx_overflow_for_host);
1825 }
1826 if (readb(&p->mrx_checksum_error_for_host)) {
1827 local->stats.rx_crc_errors +=
1828 swab16(readw(&p->mrx_checksum_error));
1829 writeb(0, &p->mrx_checksum_error);
1830 writeb(0, &p->mrx_checksum_error_for_host);
1831 }
1832 if (readb(&p->rx_hec_error_for_host)) {
1833 local->stats.rx_frame_errors += swab16(readw(&p->rx_hec_error));
1834 writeb(0, &p->rx_hec_error);
1835 writeb(0, &p->rx_hec_error_for_host);
1836 }
1837 return &local->stats;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001838}
John Daiker141fa612009-03-10 06:59:54 -07001839
Linus Torvalds1da177e2005-04-16 15:20:36 -07001840/*===========================================================================*/
John Daiker141fa612009-03-10 06:59:54 -07001841static void ray_update_parm(struct net_device *dev, UCHAR objid, UCHAR *value,
1842 int len)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001843{
John Daiker141fa612009-03-10 06:59:54 -07001844 ray_dev_t *local = netdev_priv(dev);
1845 struct pcmcia_device *link = local->finder;
1846 int ccsindex;
1847 int i;
1848 struct ccs __iomem *pccs;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001849
John Daiker141fa612009-03-10 06:59:54 -07001850 if (!(pcmcia_dev_present(link))) {
1851 DEBUG(2, "ray_update_parm - device not present\n");
1852 return;
1853 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001854
John Daiker141fa612009-03-10 06:59:54 -07001855 if ((ccsindex = get_free_ccs(local)) < 0) {
1856 DEBUG(0, "ray_update_parm - No free ccs\n");
1857 return;
1858 }
1859 pccs = ccs_base(local) + ccsindex;
1860 writeb(CCS_UPDATE_PARAMS, &pccs->cmd);
1861 writeb(objid, &pccs->var.update_param.object_id);
1862 writeb(1, &pccs->var.update_param.number_objects);
1863 writeb(0, &pccs->var.update_param.failure_cause);
1864 for (i = 0; i < len; i++) {
1865 writeb(value[i], local->sram + HOST_TO_ECF_BASE);
1866 }
1867 /* Interrupt the firmware to process the command */
1868 if (interrupt_ecf(local, ccsindex)) {
1869 DEBUG(0, "ray_cs associate failed - ECF not ready for intr\n");
1870 writeb(CCS_BUFFER_FREE, &(pccs++)->buffer_status);
1871 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001872}
John Daiker141fa612009-03-10 06:59:54 -07001873
Linus Torvalds1da177e2005-04-16 15:20:36 -07001874/*===========================================================================*/
1875static void ray_update_multi_list(struct net_device *dev, int all)
1876{
John Daiker141fa612009-03-10 06:59:54 -07001877 struct dev_mc_list *dmi, **dmip;
1878 int ccsindex;
1879 struct ccs __iomem *pccs;
1880 int i = 0;
1881 ray_dev_t *local = netdev_priv(dev);
1882 struct pcmcia_device *link = local->finder;
1883 void __iomem *p = local->sram + HOST_TO_ECF_BASE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001884
John Daiker141fa612009-03-10 06:59:54 -07001885 if (!(pcmcia_dev_present(link))) {
1886 DEBUG(2, "ray_update_multi_list - device not present\n");
1887 return;
1888 } else
1889 DEBUG(2, "ray_update_multi_list(%p)\n", dev);
1890 if ((ccsindex = get_free_ccs(local)) < 0) {
1891 DEBUG(1, "ray_update_multi - No free ccs\n");
1892 return;
1893 }
1894 pccs = ccs_base(local) + ccsindex;
1895 writeb(CCS_UPDATE_MULTICAST_LIST, &pccs->cmd);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001896
John Daiker141fa612009-03-10 06:59:54 -07001897 if (all) {
1898 writeb(0xff, &pccs->var);
1899 local->num_multi = 0xff;
1900 } else {
1901 /* Copy the kernel's list of MC addresses to card */
1902 for (dmip = &dev->mc_list; (dmi = *dmip) != NULL;
1903 dmip = &dmi->next) {
1904 memcpy_toio(p, dmi->dmi_addr, ETH_ALEN);
1905 DEBUG(1,
1906 "ray_update_multi add addr %02x%02x%02x%02x%02x%02x\n",
1907 dmi->dmi_addr[0], dmi->dmi_addr[1],
1908 dmi->dmi_addr[2], dmi->dmi_addr[3],
1909 dmi->dmi_addr[4], dmi->dmi_addr[5]);
1910 p += ETH_ALEN;
1911 i++;
1912 }
1913 if (i > 256 / ADDRLEN)
1914 i = 256 / ADDRLEN;
1915 writeb((UCHAR) i, &pccs->var);
1916 DEBUG(1, "ray_cs update_multi %d addresses in list\n", i);
1917 /* Interrupt the firmware to process the command */
1918 local->num_multi = i;
1919 }
1920 if (interrupt_ecf(local, ccsindex)) {
1921 DEBUG(1,
1922 "ray_cs update_multi failed - ECF not ready for intr\n");
1923 writeb(CCS_BUFFER_FREE, &(pccs++)->buffer_status);
1924 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001925} /* end ray_update_multi_list */
John Daiker141fa612009-03-10 06:59:54 -07001926
Linus Torvalds1da177e2005-04-16 15:20:36 -07001927/*===========================================================================*/
1928static void set_multicast_list(struct net_device *dev)
1929{
John Daiker141fa612009-03-10 06:59:54 -07001930 ray_dev_t *local = netdev_priv(dev);
1931 UCHAR promisc;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001932
John Daiker141fa612009-03-10 06:59:54 -07001933 DEBUG(2, "ray_cs set_multicast_list(%p)\n", dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001934
John Daiker141fa612009-03-10 06:59:54 -07001935 if (dev->flags & IFF_PROMISC) {
1936 if (local->sparm.b5.a_promiscuous_mode == 0) {
1937 DEBUG(1, "ray_cs set_multicast_list promisc on\n");
1938 local->sparm.b5.a_promiscuous_mode = 1;
1939 promisc = 1;
1940 ray_update_parm(dev, OBJID_promiscuous_mode,
1941 &promisc, sizeof(promisc));
1942 }
1943 } else {
1944 if (local->sparm.b5.a_promiscuous_mode == 1) {
1945 DEBUG(1, "ray_cs set_multicast_list promisc off\n");
1946 local->sparm.b5.a_promiscuous_mode = 0;
1947 promisc = 0;
1948 ray_update_parm(dev, OBJID_promiscuous_mode,
1949 &promisc, sizeof(promisc));
1950 }
1951 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001952
John Daiker141fa612009-03-10 06:59:54 -07001953 if (dev->flags & IFF_ALLMULTI)
1954 ray_update_multi_list(dev, 1);
1955 else {
1956 if (local->num_multi != dev->mc_count)
1957 ray_update_multi_list(dev, 0);
1958 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001959} /* end set_multicast_list */
John Daiker141fa612009-03-10 06:59:54 -07001960
Linus Torvalds1da177e2005-04-16 15:20:36 -07001961/*=============================================================================
1962 * All routines below here are run at interrupt time.
1963=============================================================================*/
David Howells7d12e782006-10-05 14:55:46 +01001964static irqreturn_t ray_interrupt(int irq, void *dev_id)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001965{
John Daiker141fa612009-03-10 06:59:54 -07001966 struct net_device *dev = (struct net_device *)dev_id;
1967 struct pcmcia_device *link;
1968 ray_dev_t *local;
1969 struct ccs __iomem *pccs;
1970 struct rcs __iomem *prcs;
1971 UCHAR rcsindex;
1972 UCHAR tmp;
1973 UCHAR cmd;
1974 UCHAR status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001975
John Daiker141fa612009-03-10 06:59:54 -07001976 if (dev == NULL) /* Note that we want interrupts with dev->start == 0 */
1977 return IRQ_NONE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001978
John Daiker141fa612009-03-10 06:59:54 -07001979 DEBUG(4, "ray_cs: interrupt for *dev=%p\n", dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001980
John Daiker141fa612009-03-10 06:59:54 -07001981 local = netdev_priv(dev);
1982 link = (struct pcmcia_device *)local->finder;
1983 if (!pcmcia_dev_present(link)) {
1984 DEBUG(2,
1985 "ray_cs interrupt from device not present or suspended.\n");
1986 return IRQ_NONE;
1987 }
1988 rcsindex = readb(&((struct scb __iomem *)(local->sram))->rcs_index);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001989
John Daiker141fa612009-03-10 06:59:54 -07001990 if (rcsindex >= (NUMBER_OF_CCS + NUMBER_OF_RCS)) {
1991 DEBUG(1, "ray_cs interrupt bad rcsindex = 0x%x\n", rcsindex);
1992 clear_interrupt(local);
1993 return IRQ_HANDLED;
1994 }
1995 if (rcsindex < NUMBER_OF_CCS) { /* If it's a returned CCS */
1996 pccs = ccs_base(local) + rcsindex;
1997 cmd = readb(&pccs->cmd);
1998 status = readb(&pccs->buffer_status);
1999 switch (cmd) {
2000 case CCS_DOWNLOAD_STARTUP_PARAMS: /* Happens in firmware someday */
2001 del_timer(&local->timer);
2002 if (status == CCS_COMMAND_COMPLETE) {
2003 DEBUG(1,
2004 "ray_cs interrupt download_startup_parameters OK\n");
2005 } else {
2006 DEBUG(1,
2007 "ray_cs interrupt download_startup_parameters fail\n");
2008 }
2009 break;
2010 case CCS_UPDATE_PARAMS:
2011 DEBUG(1, "ray_cs interrupt update params done\n");
2012 if (status != CCS_COMMAND_COMPLETE) {
2013 tmp =
2014 readb(&pccs->var.update_param.
2015 failure_cause);
2016 DEBUG(0,
2017 "ray_cs interrupt update params failed - reason %d\n",
2018 tmp);
2019 }
2020 break;
2021 case CCS_REPORT_PARAMS:
2022 DEBUG(1, "ray_cs interrupt report params done\n");
2023 break;
2024 case CCS_UPDATE_MULTICAST_LIST: /* Note that this CCS isn't returned */
2025 DEBUG(1,
2026 "ray_cs interrupt CCS Update Multicast List done\n");
2027 break;
2028 case CCS_UPDATE_POWER_SAVINGS_MODE:
2029 DEBUG(1,
2030 "ray_cs interrupt update power save mode done\n");
2031 break;
2032 case CCS_START_NETWORK:
2033 case CCS_JOIN_NETWORK:
2034 if (status == CCS_COMMAND_COMPLETE) {
2035 if (readb
2036 (&pccs->var.start_network.net_initiated) ==
2037 1) {
2038 DEBUG(0,
2039 "ray_cs interrupt network \"%s\" started\n",
2040 local->sparm.b4.a_current_ess_id);
2041 } else {
2042 DEBUG(0,
2043 "ray_cs interrupt network \"%s\" joined\n",
2044 local->sparm.b4.a_current_ess_id);
2045 }
2046 memcpy_fromio(&local->bss_id,
2047 pccs->var.start_network.bssid,
2048 ADDRLEN);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002049
John Daiker141fa612009-03-10 06:59:54 -07002050 if (local->fw_ver == 0x55)
2051 local->net_default_tx_rate = 3;
2052 else
2053 local->net_default_tx_rate =
2054 readb(&pccs->var.start_network.
2055 net_default_tx_rate);
2056 local->encryption =
2057 readb(&pccs->var.start_network.encryption);
2058 if (!sniffer && (local->net_type == INFRA)
2059 && !(local->sparm.b4.a_acting_as_ap_status)) {
2060 authenticate(local);
2061 }
2062 local->card_status = CARD_ACQ_COMPLETE;
2063 } else {
2064 local->card_status = CARD_ACQ_FAILED;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002065
John Daiker141fa612009-03-10 06:59:54 -07002066 del_timer(&local->timer);
2067 local->timer.expires = jiffies + HZ * 5;
2068 local->timer.data = (long)local;
2069 if (status == CCS_START_NETWORK) {
2070 DEBUG(0,
2071 "ray_cs interrupt network \"%s\" start failed\n",
2072 local->sparm.b4.a_current_ess_id);
2073 local->timer.function = &start_net;
2074 } else {
2075 DEBUG(0,
2076 "ray_cs interrupt network \"%s\" join failed\n",
2077 local->sparm.b4.a_current_ess_id);
2078 local->timer.function = &join_net;
2079 }
2080 add_timer(&local->timer);
2081 }
2082 break;
2083 case CCS_START_ASSOCIATION:
2084 if (status == CCS_COMMAND_COMPLETE) {
2085 local->card_status = CARD_ASSOC_COMPLETE;
2086 DEBUG(0, "ray_cs association successful\n");
2087 } else {
2088 DEBUG(0, "ray_cs association failed,\n");
2089 local->card_status = CARD_ASSOC_FAILED;
2090 join_net((u_long) local);
2091 }
2092 break;
2093 case CCS_TX_REQUEST:
2094 if (status == CCS_COMMAND_COMPLETE) {
2095 DEBUG(3,
2096 "ray_cs interrupt tx request complete\n");
2097 } else {
2098 DEBUG(1,
2099 "ray_cs interrupt tx request failed\n");
2100 }
2101 if (!sniffer)
2102 netif_start_queue(dev);
2103 netif_wake_queue(dev);
2104 break;
2105 case CCS_TEST_MEMORY:
2106 DEBUG(1, "ray_cs interrupt mem test done\n");
2107 break;
2108 case CCS_SHUTDOWN:
2109 DEBUG(1,
2110 "ray_cs interrupt Unexpected CCS returned - Shutdown\n");
2111 break;
2112 case CCS_DUMP_MEMORY:
2113 DEBUG(1, "ray_cs interrupt dump memory done\n");
2114 break;
2115 case CCS_START_TIMER:
2116 DEBUG(2,
2117 "ray_cs interrupt DING - raylink timer expired\n");
2118 break;
2119 default:
2120 DEBUG(1,
2121 "ray_cs interrupt Unexpected CCS 0x%x returned 0x%x\n",
2122 rcsindex, cmd);
2123 }
2124 writeb(CCS_BUFFER_FREE, &pccs->buffer_status);
2125 } else { /* It's an RCS */
2126
2127 prcs = rcs_base(local) + rcsindex;
2128
2129 switch (readb(&prcs->interrupt_id)) {
2130 case PROCESS_RX_PACKET:
2131 ray_rx(dev, local, prcs);
2132 break;
2133 case REJOIN_NET_COMPLETE:
2134 DEBUG(1, "ray_cs interrupt rejoin net complete\n");
2135 local->card_status = CARD_ACQ_COMPLETE;
2136 /* do we need to clear tx buffers CCS's? */
2137 if (local->sparm.b4.a_network_type == ADHOC) {
2138 if (!sniffer)
2139 netif_start_queue(dev);
2140 } else {
2141 memcpy_fromio(&local->bss_id,
2142 prcs->var.rejoin_net_complete.
2143 bssid, ADDRLEN);
2144 DEBUG(1,
2145 "ray_cs new BSSID = %02x%02x%02x%02x%02x%02x\n",
2146 local->bss_id[0], local->bss_id[1],
2147 local->bss_id[2], local->bss_id[3],
2148 local->bss_id[4], local->bss_id[5]);
2149 if (!sniffer)
2150 authenticate(local);
2151 }
2152 break;
2153 case ROAMING_INITIATED:
2154 DEBUG(1, "ray_cs interrupt roaming initiated\n");
2155 netif_stop_queue(dev);
2156 local->card_status = CARD_DOING_ACQ;
2157 break;
2158 case JAPAN_CALL_SIGN_RXD:
2159 DEBUG(1, "ray_cs interrupt japan call sign rx\n");
2160 break;
2161 default:
2162 DEBUG(1,
2163 "ray_cs Unexpected interrupt for RCS 0x%x cmd = 0x%x\n",
2164 rcsindex,
2165 (unsigned int)readb(&prcs->interrupt_id));
2166 break;
2167 }
2168 writeb(CCS_BUFFER_FREE, &prcs->buffer_status);
2169 }
2170 clear_interrupt(local);
2171 return IRQ_HANDLED;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002172} /* ray_interrupt */
John Daiker141fa612009-03-10 06:59:54 -07002173
Linus Torvalds1da177e2005-04-16 15:20:36 -07002174/*===========================================================================*/
John Daiker141fa612009-03-10 06:59:54 -07002175static void ray_rx(struct net_device *dev, ray_dev_t *local,
2176 struct rcs __iomem *prcs)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002177{
John Daiker141fa612009-03-10 06:59:54 -07002178 int rx_len;
2179 unsigned int pkt_addr;
2180 void __iomem *pmsg;
2181 DEBUG(4, "ray_rx process rx packet\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002182
John Daiker141fa612009-03-10 06:59:54 -07002183 /* Calculate address of packet within Rx buffer */
2184 pkt_addr = ((readb(&prcs->var.rx_packet.rx_data_ptr[0]) << 8)
2185 + readb(&prcs->var.rx_packet.rx_data_ptr[1])) & RX_BUFF_END;
2186 /* Length of first packet fragment */
2187 rx_len = (readb(&prcs->var.rx_packet.rx_data_length[0]) << 8)
2188 + readb(&prcs->var.rx_packet.rx_data_length[1]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002189
John Daiker141fa612009-03-10 06:59:54 -07002190 local->last_rsl = readb(&prcs->var.rx_packet.rx_sig_lev);
2191 pmsg = local->rmem + pkt_addr;
2192 switch (readb(pmsg)) {
2193 case DATA_TYPE:
2194 DEBUG(4, "ray_rx data type\n");
2195 rx_data(dev, prcs, pkt_addr, rx_len);
2196 break;
2197 case AUTHENTIC_TYPE:
2198 DEBUG(4, "ray_rx authentic type\n");
2199 if (sniffer)
2200 rx_data(dev, prcs, pkt_addr, rx_len);
2201 else
2202 rx_authenticate(local, prcs, pkt_addr, rx_len);
2203 break;
2204 case DEAUTHENTIC_TYPE:
2205 DEBUG(4, "ray_rx deauth type\n");
2206 if (sniffer)
2207 rx_data(dev, prcs, pkt_addr, rx_len);
2208 else
2209 rx_deauthenticate(local, prcs, pkt_addr, rx_len);
2210 break;
2211 case NULL_MSG_TYPE:
2212 DEBUG(3, "ray_cs rx NULL msg\n");
2213 break;
2214 case BEACON_TYPE:
2215 DEBUG(4, "ray_rx beacon type\n");
2216 if (sniffer)
2217 rx_data(dev, prcs, pkt_addr, rx_len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002218
John Daiker141fa612009-03-10 06:59:54 -07002219 copy_from_rx_buff(local, (UCHAR *) &local->last_bcn, pkt_addr,
2220 rx_len < sizeof(struct beacon_rx) ?
2221 rx_len : sizeof(struct beacon_rx));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002222
John Daiker141fa612009-03-10 06:59:54 -07002223 local->beacon_rxed = 1;
2224 /* Get the statistics so the card counters never overflow */
2225 ray_get_stats(dev);
2226 break;
2227 default:
2228 DEBUG(0, "ray_cs unknown pkt type %2x\n",
2229 (unsigned int)readb(pmsg));
2230 break;
2231 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002232
2233} /* end ray_rx */
John Daiker141fa612009-03-10 06:59:54 -07002234
Linus Torvalds1da177e2005-04-16 15:20:36 -07002235/*===========================================================================*/
John Daiker141fa612009-03-10 06:59:54 -07002236static void rx_data(struct net_device *dev, struct rcs __iomem *prcs,
2237 unsigned int pkt_addr, int rx_len)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002238{
John Daiker141fa612009-03-10 06:59:54 -07002239 struct sk_buff *skb = NULL;
2240 struct rcs __iomem *prcslink = prcs;
2241 ray_dev_t *local = netdev_priv(dev);
2242 UCHAR *rx_ptr;
2243 int total_len;
2244 int tmp;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002245#ifdef WIRELESS_SPY
John Daiker141fa612009-03-10 06:59:54 -07002246 int siglev = local->last_rsl;
2247 u_char linksrcaddr[ETH_ALEN]; /* Other end of the wireless link */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002248#endif
2249
John Daiker141fa612009-03-10 06:59:54 -07002250 if (!sniffer) {
2251 if (translate) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002252/* TBD length needs fixing for translated header */
John Daiker141fa612009-03-10 06:59:54 -07002253 if (rx_len < (ETH_HLEN + RX_MAC_HEADER_LENGTH) ||
2254 rx_len >
2255 (dev->mtu + RX_MAC_HEADER_LENGTH + ETH_HLEN +
2256 FCS_LEN)) {
2257 DEBUG(0,
2258 "ray_cs invalid packet length %d received \n",
2259 rx_len);
2260 return;
2261 }
2262 } else { /* encapsulated ethernet */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002263
John Daiker141fa612009-03-10 06:59:54 -07002264 if (rx_len < (ETH_HLEN + RX_MAC_HEADER_LENGTH) ||
2265 rx_len >
2266 (dev->mtu + RX_MAC_HEADER_LENGTH + ETH_HLEN +
2267 FCS_LEN)) {
2268 DEBUG(0,
2269 "ray_cs invalid packet length %d received \n",
2270 rx_len);
2271 return;
2272 }
2273 }
2274 }
2275 DEBUG(4, "ray_cs rx_data packet\n");
2276 /* If fragmented packet, verify sizes of fragments add up */
2277 if (readb(&prcs->var.rx_packet.next_frag_rcs_index) != 0xFF) {
2278 DEBUG(1, "ray_cs rx'ed fragment\n");
2279 tmp = (readb(&prcs->var.rx_packet.totalpacketlength[0]) << 8)
2280 + readb(&prcs->var.rx_packet.totalpacketlength[1]);
2281 total_len = tmp;
2282 prcslink = prcs;
2283 do {
2284 tmp -=
2285 (readb(&prcslink->var.rx_packet.rx_data_length[0])
2286 << 8)
2287 + readb(&prcslink->var.rx_packet.rx_data_length[1]);
2288 if (readb(&prcslink->var.rx_packet.next_frag_rcs_index)
2289 == 0xFF || tmp < 0)
2290 break;
2291 prcslink = rcs_base(local)
2292 + readb(&prcslink->link_field);
2293 } while (1);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002294
John Daiker141fa612009-03-10 06:59:54 -07002295 if (tmp < 0) {
2296 DEBUG(0,
2297 "ray_cs rx_data fragment lengths don't add up\n");
2298 local->stats.rx_dropped++;
2299 release_frag_chain(local, prcs);
2300 return;
2301 }
2302 } else { /* Single unfragmented packet */
2303 total_len = rx_len;
2304 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002305
John Daiker141fa612009-03-10 06:59:54 -07002306 skb = dev_alloc_skb(total_len + 5);
2307 if (skb == NULL) {
2308 DEBUG(0, "ray_cs rx_data could not allocate skb\n");
2309 local->stats.rx_dropped++;
2310 if (readb(&prcs->var.rx_packet.next_frag_rcs_index) != 0xFF)
2311 release_frag_chain(local, prcs);
2312 return;
2313 }
2314 skb_reserve(skb, 2); /* Align IP on 16 byte (TBD check this) */
2315
2316 DEBUG(4, "ray_cs rx_data total_len = %x, rx_len = %x\n", total_len,
2317 rx_len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002318
2319/************************/
John Daiker141fa612009-03-10 06:59:54 -07002320 /* Reserve enough room for the whole damn packet. */
2321 rx_ptr = skb_put(skb, total_len);
2322 /* Copy the whole packet to sk_buff */
2323 rx_ptr +=
2324 copy_from_rx_buff(local, rx_ptr, pkt_addr & RX_BUFF_END, rx_len);
2325 /* Get source address */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002326#ifdef WIRELESS_SPY
John Daiker141fa612009-03-10 06:59:54 -07002327 skb_copy_from_linear_data_offset(skb,
2328 offsetof(struct mac_header, addr_2),
2329 linksrcaddr, ETH_ALEN);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002330#endif
John Daiker141fa612009-03-10 06:59:54 -07002331 /* Now, deal with encapsulation/translation/sniffer */
2332 if (!sniffer) {
2333 if (!translate) {
2334 /* Encapsulated ethernet, so just lop off 802.11 MAC header */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002335/* TBD reserve skb_reserve( skb, RX_MAC_HEADER_LENGTH); */
John Daiker141fa612009-03-10 06:59:54 -07002336 skb_pull(skb, RX_MAC_HEADER_LENGTH);
2337 } else {
2338 /* Do translation */
2339 untranslate(local, skb, total_len);
2340 }
2341 } else { /* sniffer mode, so just pass whole packet */
2342 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002343
2344/************************/
John Daiker141fa612009-03-10 06:59:54 -07002345 /* Now pick up the rest of the fragments if any */
2346 tmp = 17;
2347 if (readb(&prcs->var.rx_packet.next_frag_rcs_index) != 0xFF) {
2348 prcslink = prcs;
2349 DEBUG(1, "ray_cs rx_data in fragment loop\n");
2350 do {
2351 prcslink = rcs_base(local)
2352 +
2353 readb(&prcslink->var.rx_packet.next_frag_rcs_index);
2354 rx_len =
2355 ((readb(&prcslink->var.rx_packet.rx_data_length[0])
2356 << 8)
2357 +
2358 readb(&prcslink->var.rx_packet.rx_data_length[1]))
2359 & RX_BUFF_END;
2360 pkt_addr =
2361 ((readb(&prcslink->var.rx_packet.rx_data_ptr[0]) <<
2362 8)
2363 + readb(&prcslink->var.rx_packet.rx_data_ptr[1]))
2364 & RX_BUFF_END;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002365
John Daiker141fa612009-03-10 06:59:54 -07002366 rx_ptr +=
2367 copy_from_rx_buff(local, rx_ptr, pkt_addr, rx_len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002368
John Daiker141fa612009-03-10 06:59:54 -07002369 } while (tmp-- &&
2370 readb(&prcslink->var.rx_packet.next_frag_rcs_index) !=
2371 0xFF);
2372 release_frag_chain(local, prcs);
2373 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002374
John Daiker141fa612009-03-10 06:59:54 -07002375 skb->protocol = eth_type_trans(skb, dev);
2376 netif_rx(skb);
2377 local->stats.rx_packets++;
2378 local->stats.rx_bytes += total_len;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002379
John Daiker141fa612009-03-10 06:59:54 -07002380 /* Gather signal strength per address */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002381#ifdef WIRELESS_SPY
John Daiker141fa612009-03-10 06:59:54 -07002382 /* For the Access Point or the node having started the ad-hoc net
2383 * note : ad-hoc work only in some specific configurations, but we
2384 * kludge in ray_get_wireless_stats... */
2385 if (!memcmp(linksrcaddr, local->bss_id, ETH_ALEN)) {
2386 /* Update statistics */
2387 /*local->wstats.qual.qual = none ? */
2388 local->wstats.qual.level = siglev;
2389 /*local->wstats.qual.noise = none ? */
2390 local->wstats.qual.updated = 0x2;
2391 }
2392 /* Now, update the spy stuff */
2393 {
2394 struct iw_quality wstats;
2395 wstats.level = siglev;
2396 /* wstats.noise = none ? */
2397 /* wstats.qual = none ? */
2398 wstats.updated = 0x2;
2399 /* Update spy records */
2400 wireless_spy_update(dev, linksrcaddr, &wstats);
2401 }
2402#endif /* WIRELESS_SPY */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002403} /* end rx_data */
John Daiker141fa612009-03-10 06:59:54 -07002404
Linus Torvalds1da177e2005-04-16 15:20:36 -07002405/*===========================================================================*/
2406static void untranslate(ray_dev_t *local, struct sk_buff *skb, int len)
2407{
John Daiker141fa612009-03-10 06:59:54 -07002408 snaphdr_t *psnap = (snaphdr_t *) (skb->data + RX_MAC_HEADER_LENGTH);
2409 struct ieee80211_hdr *pmac = (struct ieee80211_hdr *)skb->data;
2410 __be16 type = *(__be16 *) psnap->ethertype;
2411 int delta;
2412 struct ethhdr *peth;
2413 UCHAR srcaddr[ADDRLEN];
2414 UCHAR destaddr[ADDRLEN];
2415 static UCHAR org_bridge[3] = { 0, 0, 0xf8 };
2416 static UCHAR org_1042[3] = { 0, 0, 0 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002417
John Daiker141fa612009-03-10 06:59:54 -07002418 memcpy(destaddr, ieee80211_get_DA(pmac), ADDRLEN);
2419 memcpy(srcaddr, ieee80211_get_SA(pmac), ADDRLEN);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002420
2421#ifdef PCMCIA_DEBUG
John Daiker141fa612009-03-10 06:59:54 -07002422 if (pc_debug > 3) {
2423 int i;
2424 printk(KERN_DEBUG "skb->data before untranslate");
2425 for (i = 0; i < 64; i++)
2426 printk("%02x ", skb->data[i]);
2427 printk("\n" KERN_DEBUG
2428 "type = %08x, xsap = %02x%02x%02x, org = %02x02x02x\n",
2429 ntohs(type), psnap->dsap, psnap->ssap, psnap->ctrl,
2430 psnap->org[0], psnap->org[1], psnap->org[2]);
2431 printk(KERN_DEBUG "untranslate skb->data = %p\n", skb->data);
2432 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002433#endif
2434
John Daiker141fa612009-03-10 06:59:54 -07002435 if (psnap->dsap != 0xaa || psnap->ssap != 0xaa || psnap->ctrl != 3) {
2436 /* not a snap type so leave it alone */
2437 DEBUG(3, "ray_cs untranslate NOT SNAP %02x %02x %02x\n",
2438 psnap->dsap, psnap->ssap, psnap->ctrl);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002439
John Daiker141fa612009-03-10 06:59:54 -07002440 delta = RX_MAC_HEADER_LENGTH - ETH_HLEN;
2441 peth = (struct ethhdr *)(skb->data + delta);
2442 peth->h_proto = htons(len - RX_MAC_HEADER_LENGTH);
2443 } else { /* Its a SNAP */
2444 if (memcmp(psnap->org, org_bridge, 3) == 0) {
2445 /* EtherII and nuke the LLC */
2446 DEBUG(3, "ray_cs untranslate Bridge encap\n");
2447 delta = RX_MAC_HEADER_LENGTH
2448 + sizeof(struct snaphdr_t) - ETH_HLEN;
2449 peth = (struct ethhdr *)(skb->data + delta);
2450 peth->h_proto = type;
2451 } else if (memcmp(psnap->org, org_1042, 3) == 0) {
2452 switch (ntohs(type)) {
2453 case ETH_P_IPX:
2454 case ETH_P_AARP:
2455 DEBUG(3, "ray_cs untranslate RFC IPX/AARP\n");
2456 delta = RX_MAC_HEADER_LENGTH - ETH_HLEN;
2457 peth = (struct ethhdr *)(skb->data + delta);
2458 peth->h_proto =
2459 htons(len - RX_MAC_HEADER_LENGTH);
2460 break;
2461 default:
2462 DEBUG(3, "ray_cs untranslate RFC default\n");
2463 delta = RX_MAC_HEADER_LENGTH +
2464 sizeof(struct snaphdr_t) - ETH_HLEN;
2465 peth = (struct ethhdr *)(skb->data + delta);
2466 peth->h_proto = type;
2467 break;
2468 }
2469 } else {
2470 printk("ray_cs untranslate very confused by packet\n");
2471 delta = RX_MAC_HEADER_LENGTH - ETH_HLEN;
2472 peth = (struct ethhdr *)(skb->data + delta);
2473 peth->h_proto = type;
2474 }
Al Viro7698d692007-12-29 04:55:50 -05002475 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002476/* TBD reserve skb_reserve(skb, delta); */
John Daiker141fa612009-03-10 06:59:54 -07002477 skb_pull(skb, delta);
2478 DEBUG(3, "untranslate after skb_pull(%d), skb->data = %p\n", delta,
2479 skb->data);
2480 memcpy(peth->h_dest, destaddr, ADDRLEN);
2481 memcpy(peth->h_source, srcaddr, ADDRLEN);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002482#ifdef PCMCIA_DEBUG
John Daiker141fa612009-03-10 06:59:54 -07002483 if (pc_debug > 3) {
2484 int i;
2485 printk(KERN_DEBUG "skb->data after untranslate:");
2486 for (i = 0; i < 64; i++)
2487 printk("%02x ", skb->data[i]);
2488 printk("\n");
2489 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002490#endif
2491} /* end untranslate */
John Daiker141fa612009-03-10 06:59:54 -07002492
Linus Torvalds1da177e2005-04-16 15:20:36 -07002493/*===========================================================================*/
2494/* Copy data from circular receive buffer to PC memory.
2495 * dest = destination address in PC memory
2496 * pkt_addr = source address in receive buffer
2497 * len = length of packet to copy
2498 */
John Daiker141fa612009-03-10 06:59:54 -07002499static int copy_from_rx_buff(ray_dev_t *local, UCHAR *dest, int pkt_addr,
2500 int length)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002501{
John Daiker141fa612009-03-10 06:59:54 -07002502 int wrap_bytes = (pkt_addr + length) - (RX_BUFF_END + 1);
2503 if (wrap_bytes <= 0) {
2504 memcpy_fromio(dest, local->rmem + pkt_addr, length);
2505 } else { /* Packet wrapped in circular buffer */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002506
John Daiker141fa612009-03-10 06:59:54 -07002507 memcpy_fromio(dest, local->rmem + pkt_addr,
2508 length - wrap_bytes);
2509 memcpy_fromio(dest + length - wrap_bytes, local->rmem,
2510 wrap_bytes);
2511 }
2512 return length;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002513}
John Daiker141fa612009-03-10 06:59:54 -07002514
2515/*===========================================================================*/
2516static void release_frag_chain(ray_dev_t *local, struct rcs __iomem *prcs)
2517{
2518 struct rcs __iomem *prcslink = prcs;
2519 int tmp = 17;
2520 unsigned rcsindex = readb(&prcs->var.rx_packet.next_frag_rcs_index);
2521
2522 while (tmp--) {
2523 writeb(CCS_BUFFER_FREE, &prcslink->buffer_status);
2524 if (rcsindex >= (NUMBER_OF_CCS + NUMBER_OF_RCS)) {
2525 DEBUG(1, "ray_cs interrupt bad rcsindex = 0x%x\n",
2526 rcsindex);
2527 break;
2528 }
2529 prcslink = rcs_base(local) + rcsindex;
2530 rcsindex = readb(&prcslink->var.rx_packet.next_frag_rcs_index);
2531 }
2532 writeb(CCS_BUFFER_FREE, &prcslink->buffer_status);
2533}
2534
Linus Torvalds1da177e2005-04-16 15:20:36 -07002535/*===========================================================================*/
2536static void authenticate(ray_dev_t *local)
2537{
John Daiker141fa612009-03-10 06:59:54 -07002538 struct pcmcia_device *link = local->finder;
2539 DEBUG(0, "ray_cs Starting authentication.\n");
2540 if (!(pcmcia_dev_present(link))) {
2541 DEBUG(2, "ray_cs authenticate - device not present\n");
2542 return;
2543 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002544
John Daiker141fa612009-03-10 06:59:54 -07002545 del_timer(&local->timer);
2546 if (build_auth_frame(local, local->bss_id, OPEN_AUTH_REQUEST)) {
2547 local->timer.function = &join_net;
2548 } else {
2549 local->timer.function = &authenticate_timeout;
2550 }
2551 local->timer.expires = jiffies + HZ * 2;
2552 local->timer.data = (long)local;
2553 add_timer(&local->timer);
2554 local->authentication_state = AWAITING_RESPONSE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002555} /* end authenticate */
John Daiker141fa612009-03-10 06:59:54 -07002556
Linus Torvalds1da177e2005-04-16 15:20:36 -07002557/*===========================================================================*/
2558static void rx_authenticate(ray_dev_t *local, struct rcs __iomem *prcs,
John Daiker141fa612009-03-10 06:59:54 -07002559 unsigned int pkt_addr, int rx_len)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002560{
John Daiker141fa612009-03-10 06:59:54 -07002561 UCHAR buff[256];
2562 struct rx_msg *msg = (struct rx_msg *)buff;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002563
John Daiker141fa612009-03-10 06:59:54 -07002564 del_timer(&local->timer);
2565
2566 copy_from_rx_buff(local, buff, pkt_addr, rx_len & 0xff);
2567 /* if we are trying to get authenticated */
2568 if (local->sparm.b4.a_network_type == ADHOC) {
2569 DEBUG(1, "ray_cs rx_auth var= %02x %02x %02x %02x %02x %02x\n",
2570 msg->var[0], msg->var[1], msg->var[2], msg->var[3],
2571 msg->var[4], msg->var[5]);
2572 if (msg->var[2] == 1) {
2573 DEBUG(0, "ray_cs Sending authentication response.\n");
2574 if (!build_auth_frame
2575 (local, msg->mac.addr_2, OPEN_AUTH_RESPONSE)) {
2576 local->authentication_state = NEED_TO_AUTH;
2577 memcpy(local->auth_id, msg->mac.addr_2,
2578 ADDRLEN);
2579 }
2580 }
2581 } else { /* Infrastructure network */
2582
2583 if (local->authentication_state == AWAITING_RESPONSE) {
2584 /* Verify authentication sequence #2 and success */
2585 if (msg->var[2] == 2) {
2586 if ((msg->var[3] | msg->var[4]) == 0) {
2587 DEBUG(1, "Authentication successful\n");
2588 local->card_status = CARD_AUTH_COMPLETE;
2589 associate(local);
2590 local->authentication_state =
2591 AUTHENTICATED;
2592 } else {
2593 DEBUG(0, "Authentication refused\n");
2594 local->card_status = CARD_AUTH_REFUSED;
2595 join_net((u_long) local);
2596 local->authentication_state =
2597 UNAUTHENTICATED;
2598 }
2599 }
2600 }
2601 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002602
2603} /* end rx_authenticate */
John Daiker141fa612009-03-10 06:59:54 -07002604
Linus Torvalds1da177e2005-04-16 15:20:36 -07002605/*===========================================================================*/
2606static void associate(ray_dev_t *local)
2607{
John Daiker141fa612009-03-10 06:59:54 -07002608 struct ccs __iomem *pccs;
2609 struct pcmcia_device *link = local->finder;
2610 struct net_device *dev = link->priv;
2611 int ccsindex;
2612 if (!(pcmcia_dev_present(link))) {
2613 DEBUG(2, "ray_cs associate - device not present\n");
2614 return;
2615 }
2616 /* If no tx buffers available, return */
2617 if ((ccsindex = get_free_ccs(local)) < 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002618/* TBD should never be here but... what if we are? */
John Daiker141fa612009-03-10 06:59:54 -07002619 DEBUG(1, "ray_cs associate - No free ccs\n");
2620 return;
2621 }
2622 DEBUG(1, "ray_cs Starting association with access point\n");
2623 pccs = ccs_base(local) + ccsindex;
2624 /* fill in the CCS */
2625 writeb(CCS_START_ASSOCIATION, &pccs->cmd);
2626 /* Interrupt the firmware to process the command */
2627 if (interrupt_ecf(local, ccsindex)) {
2628 DEBUG(1, "ray_cs associate failed - ECF not ready for intr\n");
2629 writeb(CCS_BUFFER_FREE, &(pccs++)->buffer_status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002630
John Daiker141fa612009-03-10 06:59:54 -07002631 del_timer(&local->timer);
2632 local->timer.expires = jiffies + HZ * 2;
2633 local->timer.data = (long)local;
2634 local->timer.function = &join_net;
2635 add_timer(&local->timer);
2636 local->card_status = CARD_ASSOC_FAILED;
2637 return;
2638 }
2639 if (!sniffer)
2640 netif_start_queue(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002641
2642} /* end associate */
John Daiker141fa612009-03-10 06:59:54 -07002643
Linus Torvalds1da177e2005-04-16 15:20:36 -07002644/*===========================================================================*/
John Daiker141fa612009-03-10 06:59:54 -07002645static void rx_deauthenticate(ray_dev_t *local, struct rcs __iomem *prcs,
2646 unsigned int pkt_addr, int rx_len)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002647{
2648/* UCHAR buff[256];
2649 struct rx_msg *msg = (struct rx_msg *)buff;
2650*/
John Daiker141fa612009-03-10 06:59:54 -07002651 DEBUG(0, "Deauthentication frame received\n");
2652 local->authentication_state = UNAUTHENTICATED;
2653 /* Need to reauthenticate or rejoin depending on reason code */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002654/* copy_from_rx_buff(local, buff, pkt_addr, rx_len & 0xff);
2655 */
2656}
John Daiker141fa612009-03-10 06:59:54 -07002657
Linus Torvalds1da177e2005-04-16 15:20:36 -07002658/*===========================================================================*/
2659static void clear_interrupt(ray_dev_t *local)
2660{
John Daiker141fa612009-03-10 06:59:54 -07002661 writeb(0, local->amem + CIS_OFFSET + HCS_INTR_OFFSET);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002662}
John Daiker141fa612009-03-10 06:59:54 -07002663
Linus Torvalds1da177e2005-04-16 15:20:36 -07002664/*===========================================================================*/
2665#ifdef CONFIG_PROC_FS
2666#define MAXDATA (PAGE_SIZE - 80)
2667
2668static char *card_status[] = {
John Daiker141fa612009-03-10 06:59:54 -07002669 "Card inserted - uninitialized", /* 0 */
2670 "Card not downloaded", /* 1 */
2671 "Waiting for download parameters", /* 2 */
2672 "Card doing acquisition", /* 3 */
2673 "Acquisition complete", /* 4 */
2674 "Authentication complete", /* 5 */
2675 "Association complete", /* 6 */
2676 "???", "???", "???", "???", /* 7 8 9 10 undefined */
2677 "Card init error", /* 11 */
2678 "Download parameters error", /* 12 */
2679 "???", /* 13 */
2680 "Acquisition failed", /* 14 */
2681 "Authentication refused", /* 15 */
2682 "Association failed" /* 16 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002683};
2684
John Daiker141fa612009-03-10 06:59:54 -07002685static char *nettype[] = { "Adhoc", "Infra " };
2686static char *framing[] = { "Encapsulation", "Translation" }
2687
Linus Torvalds1da177e2005-04-16 15:20:36 -07002688;
2689/*===========================================================================*/
Alexey Dobriyan6b914c52008-04-10 14:34:35 -07002690static int ray_cs_proc_show(struct seq_file *m, void *v)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002691{
2692/* Print current values which are not available via other means
John Daiker141fa612009-03-10 06:59:54 -07002693 * eg ifconfig
Linus Torvalds1da177e2005-04-16 15:20:36 -07002694 */
John Daiker141fa612009-03-10 06:59:54 -07002695 int i;
2696 struct pcmcia_device *link;
2697 struct net_device *dev;
2698 ray_dev_t *local;
2699 UCHAR *p;
2700 struct freq_hop_element *pfh;
2701 UCHAR c[33];
Linus Torvalds1da177e2005-04-16 15:20:36 -07002702
John Daiker141fa612009-03-10 06:59:54 -07002703 link = this_device;
2704 if (!link)
2705 return 0;
2706 dev = (struct net_device *)link->priv;
2707 if (!dev)
2708 return 0;
2709 local = netdev_priv(dev);
2710 if (!local)
2711 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002712
John Daiker141fa612009-03-10 06:59:54 -07002713 seq_puts(m, "Raylink Wireless LAN driver status\n");
2714 seq_printf(m, "%s\n", rcsid);
2715 /* build 4 does not report version, and field is 0x55 after memtest */
2716 seq_puts(m, "Firmware version = ");
2717 if (local->fw_ver == 0x55)
2718 seq_puts(m, "4 - Use dump_cis for more details\n");
2719 else
2720 seq_printf(m, "%2d.%02d.%02d\n",
2721 local->fw_ver, local->fw_bld, local->fw_var);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002722
John Daiker141fa612009-03-10 06:59:54 -07002723 for (i = 0; i < 32; i++)
2724 c[i] = local->sparm.b5.a_current_ess_id[i];
2725 c[32] = 0;
2726 seq_printf(m, "%s network ESSID = \"%s\"\n",
2727 nettype[local->sparm.b5.a_network_type], c);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002728
John Daiker141fa612009-03-10 06:59:54 -07002729 p = local->bss_id;
2730 seq_printf(m, "BSSID = %pM\n", p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002731
John Daiker141fa612009-03-10 06:59:54 -07002732 seq_printf(m, "Country code = %d\n",
2733 local->sparm.b5.a_curr_country_code);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002734
John Daiker141fa612009-03-10 06:59:54 -07002735 i = local->card_status;
2736 if (i < 0)
2737 i = 10;
2738 if (i > 16)
2739 i = 10;
2740 seq_printf(m, "Card status = %s\n", card_status[i]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002741
John Daiker141fa612009-03-10 06:59:54 -07002742 seq_printf(m, "Framing mode = %s\n", framing[translate]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002743
John Daiker141fa612009-03-10 06:59:54 -07002744 seq_printf(m, "Last pkt signal lvl = %d\n", local->last_rsl);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002745
John Daiker141fa612009-03-10 06:59:54 -07002746 if (local->beacon_rxed) {
2747 /* Pull some fields out of last beacon received */
2748 seq_printf(m, "Beacon Interval = %d Kus\n",
2749 local->last_bcn.beacon_intvl[0]
2750 + 256 * local->last_bcn.beacon_intvl[1]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002751
John Daiker141fa612009-03-10 06:59:54 -07002752 p = local->last_bcn.elements;
2753 if (p[0] == C_ESSID_ELEMENT_ID)
2754 p += p[1] + 2;
2755 else {
2756 seq_printf(m,
2757 "Parse beacon failed at essid element id = %d\n",
2758 p[0]);
2759 return 0;
2760 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002761
John Daiker141fa612009-03-10 06:59:54 -07002762 if (p[0] == C_SUPPORTED_RATES_ELEMENT_ID) {
2763 seq_puts(m, "Supported rate codes = ");
2764 for (i = 2; i < p[1] + 2; i++)
2765 seq_printf(m, "0x%02x ", p[i]);
2766 seq_putc(m, '\n');
2767 p += p[1] + 2;
2768 } else {
2769 seq_puts(m, "Parse beacon failed at rates element\n");
2770 return 0;
2771 }
2772
2773 if (p[0] == C_FH_PARAM_SET_ELEMENT_ID) {
2774 pfh = (struct freq_hop_element *)p;
2775 seq_printf(m, "Hop dwell = %d Kus\n",
2776 pfh->dwell_time[0] +
2777 256 * pfh->dwell_time[1]);
2778 seq_printf(m, "Hop set = %d \n",
2779 pfh->hop_set);
2780 seq_printf(m, "Hop pattern = %d \n",
2781 pfh->hop_pattern);
2782 seq_printf(m, "Hop index = %d \n",
2783 pfh->hop_index);
2784 p += p[1] + 2;
2785 } else {
2786 seq_puts(m,
2787 "Parse beacon failed at FH param element\n");
2788 return 0;
2789 }
2790 } else {
2791 seq_puts(m, "No beacons received\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002792 }
John Daiker141fa612009-03-10 06:59:54 -07002793 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002794}
2795
Alexey Dobriyan6b914c52008-04-10 14:34:35 -07002796static int ray_cs_proc_open(struct inode *inode, struct file *file)
2797{
2798 return single_open(file, ray_cs_proc_show, NULL);
2799}
2800
2801static const struct file_operations ray_cs_proc_fops = {
John Daiker141fa612009-03-10 06:59:54 -07002802 .owner = THIS_MODULE,
2803 .open = ray_cs_proc_open,
2804 .read = seq_read,
2805 .llseek = seq_lseek,
2806 .release = single_release,
Alexey Dobriyan6b914c52008-04-10 14:34:35 -07002807};
Linus Torvalds1da177e2005-04-16 15:20:36 -07002808#endif
2809/*===========================================================================*/
2810static int build_auth_frame(ray_dev_t *local, UCHAR *dest, int auth_type)
2811{
John Daiker141fa612009-03-10 06:59:54 -07002812 int addr;
2813 struct ccs __iomem *pccs;
2814 struct tx_msg __iomem *ptx;
2815 int ccsindex;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002816
John Daiker141fa612009-03-10 06:59:54 -07002817 /* If no tx buffers available, return */
2818 if ((ccsindex = get_free_tx_ccs(local)) < 0) {
2819 DEBUG(1, "ray_cs send authenticate - No free tx ccs\n");
2820 return -1;
2821 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002822
John Daiker141fa612009-03-10 06:59:54 -07002823 pccs = ccs_base(local) + ccsindex;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002824
John Daiker141fa612009-03-10 06:59:54 -07002825 /* Address in card space */
2826 addr = TX_BUF_BASE + (ccsindex << 11);
2827 /* fill in the CCS */
2828 writeb(CCS_TX_REQUEST, &pccs->cmd);
2829 writeb(addr >> 8, pccs->var.tx_request.tx_data_ptr);
2830 writeb(0x20, pccs->var.tx_request.tx_data_ptr + 1);
2831 writeb(TX_AUTHENTICATE_LENGTH_MSB, pccs->var.tx_request.tx_data_length);
2832 writeb(TX_AUTHENTICATE_LENGTH_LSB,
2833 pccs->var.tx_request.tx_data_length + 1);
2834 writeb(0, &pccs->var.tx_request.pow_sav_mode);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002835
John Daiker141fa612009-03-10 06:59:54 -07002836 ptx = local->sram + addr;
2837 /* fill in the mac header */
2838 writeb(PROTOCOL_VER | AUTHENTIC_TYPE, &ptx->mac.frame_ctl_1);
2839 writeb(0, &ptx->mac.frame_ctl_2);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002840
John Daiker141fa612009-03-10 06:59:54 -07002841 memcpy_toio(ptx->mac.addr_1, dest, ADDRLEN);
2842 memcpy_toio(ptx->mac.addr_2, local->sparm.b4.a_mac_addr, ADDRLEN);
2843 memcpy_toio(ptx->mac.addr_3, local->bss_id, ADDRLEN);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002844
John Daiker141fa612009-03-10 06:59:54 -07002845 /* Fill in msg body with protocol 00 00, sequence 01 00 ,status 00 00 */
2846 memset_io(ptx->var, 0, 6);
2847 writeb(auth_type & 0xff, ptx->var + 2);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002848
John Daiker141fa612009-03-10 06:59:54 -07002849 /* Interrupt the firmware to process the command */
2850 if (interrupt_ecf(local, ccsindex)) {
2851 DEBUG(1,
2852 "ray_cs send authentication request failed - ECF not ready for intr\n");
2853 writeb(CCS_BUFFER_FREE, &(pccs++)->buffer_status);
2854 return -1;
2855 }
2856 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002857} /* End build_auth_frame */
2858
2859/*===========================================================================*/
2860#ifdef CONFIG_PROC_FS
2861static void raycs_write(const char *name, write_proc_t *w, void *data)
2862{
John Daiker141fa612009-03-10 06:59:54 -07002863 struct proc_dir_entry *entry =
2864 create_proc_entry(name, S_IFREG | S_IWUSR, NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002865 if (entry) {
2866 entry->write_proc = w;
2867 entry->data = data;
2868 }
2869}
2870
John Daiker141fa612009-03-10 06:59:54 -07002871static int write_essid(struct file *file, const char __user *buffer,
2872 unsigned long count, void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002873{
2874 static char proc_essid[33];
2875 int len = count;
2876
2877 if (len > 32)
2878 len = 32;
2879 memset(proc_essid, 0, 33);
2880 if (copy_from_user(proc_essid, buffer, len))
2881 return -EFAULT;
2882 essid = proc_essid;
2883 return count;
2884}
2885
John Daiker141fa612009-03-10 06:59:54 -07002886static int write_int(struct file *file, const char __user *buffer,
2887 unsigned long count, void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002888{
2889 static char proc_number[10];
2890 char *p;
2891 int nr, len;
2892
2893 if (!count)
2894 return 0;
2895
2896 if (count > 9)
2897 return -EINVAL;
2898 if (copy_from_user(proc_number, buffer, count))
2899 return -EFAULT;
2900 p = proc_number;
2901 nr = 0;
2902 len = count;
2903 do {
2904 unsigned int c = *p - '0';
2905 if (c > 9)
2906 return -EINVAL;
John Daiker141fa612009-03-10 06:59:54 -07002907 nr = nr * 10 + c;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002908 p++;
2909 } while (--len);
2910 *(int *)data = nr;
2911 return count;
2912}
2913#endif
2914
Dominik Brodowskif57ea2a2005-06-27 16:28:24 -07002915static struct pcmcia_device_id ray_ids[] = {
2916 PCMCIA_DEVICE_MANF_CARD(0x01a6, 0x0000),
2917 PCMCIA_DEVICE_NULL,
2918};
John Daiker141fa612009-03-10 06:59:54 -07002919
Dominik Brodowskif57ea2a2005-06-27 16:28:24 -07002920MODULE_DEVICE_TABLE(pcmcia, ray_ids);
2921
Linus Torvalds1da177e2005-04-16 15:20:36 -07002922static struct pcmcia_driver ray_driver = {
John Daiker141fa612009-03-10 06:59:54 -07002923 .owner = THIS_MODULE,
2924 .drv = {
2925 .name = "ray_cs",
2926 },
2927 .probe = ray_probe,
2928 .remove = ray_detach,
2929 .id_table = ray_ids,
2930 .suspend = ray_suspend,
2931 .resume = ray_resume,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002932};
2933
2934static int __init init_ray_cs(void)
2935{
John Daiker141fa612009-03-10 06:59:54 -07002936 int rc;
2937
2938 DEBUG(1, "%s\n", rcsid);
2939 rc = pcmcia_register_driver(&ray_driver);
2940 DEBUG(1, "raylink init_module register_pcmcia_driver returns 0x%x\n",
2941 rc);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002942
2943#ifdef CONFIG_PROC_FS
John Daiker141fa612009-03-10 06:59:54 -07002944 proc_mkdir("driver/ray_cs", NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002945
John Daiker141fa612009-03-10 06:59:54 -07002946 proc_create("driver/ray_cs/ray_cs", 0, NULL, &ray_cs_proc_fops);
2947 raycs_write("driver/ray_cs/essid", write_essid, NULL);
2948 raycs_write("driver/ray_cs/net_type", write_int, &net_type);
2949 raycs_write("driver/ray_cs/translate", write_int, &translate);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002950#endif
John Daiker141fa612009-03-10 06:59:54 -07002951 if (translate != 0)
2952 translate = 1;
2953 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002954} /* init_ray_cs */
2955
2956/*===========================================================================*/
2957
2958static void __exit exit_ray_cs(void)
2959{
John Daiker141fa612009-03-10 06:59:54 -07002960 DEBUG(0, "ray_cs: cleanup_module\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002961
2962#ifdef CONFIG_PROC_FS
John Daiker141fa612009-03-10 06:59:54 -07002963 remove_proc_entry("driver/ray_cs/ray_cs", NULL);
2964 remove_proc_entry("driver/ray_cs/essid", NULL);
2965 remove_proc_entry("driver/ray_cs/net_type", NULL);
2966 remove_proc_entry("driver/ray_cs/translate", NULL);
2967 remove_proc_entry("driver/ray_cs", NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002968#endif
2969
John Daiker141fa612009-03-10 06:59:54 -07002970 pcmcia_unregister_driver(&ray_driver);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002971} /* exit_ray_cs */
2972
2973module_init(init_ray_cs);
2974module_exit(exit_ray_cs);
2975
2976/*===========================================================================*/