blob: 84c530aa52f9d42f11f3f62f816c8fdd95767b43 [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
Linus Torvalds1da177e2005-04-16 15:20:36 -070074
Linus Torvalds1da177e2005-04-16 15:20:36 -070075/** Prototypes based on PCMCIA skeleton driver *******************************/
Dominik Brodowski15b99ac2006-03-31 17:26:06 +020076static int ray_config(struct pcmcia_device *link);
Dominik Brodowskifba395e2006-03-31 17:21:06 +020077static void ray_release(struct pcmcia_device *link);
Dominik Brodowskicc3b4862005-11-14 21:23:14 +010078static void ray_detach(struct pcmcia_device *p_dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -070079
80/***** Prototypes indicated by device structure ******************************/
81static int ray_dev_close(struct net_device *dev);
82static int ray_dev_config(struct net_device *dev, struct ifmap *map);
83static struct net_device_stats *ray_get_stats(struct net_device *dev);
84static int ray_dev_init(struct net_device *dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -070085
Jeff Garzik7282d492006-09-13 14:30:00 -040086static const struct ethtool_ops netdev_ethtool_ops;
Linus Torvalds1da177e2005-04-16 15:20:36 -070087
88static int ray_open(struct net_device *dev);
Stephen Hemmingerd0cf9c02009-08-31 19:50:57 +000089static netdev_tx_t ray_dev_start_xmit(struct sk_buff *skb,
90 struct net_device *dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -070091static void set_multicast_list(struct net_device *dev);
92static void ray_update_multi_list(struct net_device *dev, int all);
93static int translate_frame(ray_dev_t *local, struct tx_msg __iomem *ptx,
John Daiker141fa612009-03-10 06:59:54 -070094 unsigned char *data, int len);
95static void ray_build_header(ray_dev_t *local, struct tx_msg __iomem *ptx,
96 UCHAR msg_type, unsigned char *data);
Linus Torvalds1da177e2005-04-16 15:20:36 -070097static void untranslate(ray_dev_t *local, struct sk_buff *skb, int len);
John Daiker141fa612009-03-10 06:59:54 -070098static iw_stats *ray_get_wireless_stats(struct net_device *dev);
99static const struct iw_handler_def ray_handler_def;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700100
101/***** Prototypes for raylink functions **************************************/
102static int asc_to_int(char a);
103static void authenticate(ray_dev_t *local);
104static int build_auth_frame(ray_dev_t *local, UCHAR *dest, int auth_type);
105static void authenticate_timeout(u_long);
106static int get_free_ccs(ray_dev_t *local);
107static int get_free_tx_ccs(ray_dev_t *local);
108static void init_startup_params(ray_dev_t *local);
109static int parse_addr(char *in_str, UCHAR *out);
John Daiker141fa612009-03-10 06:59:54 -0700110static int ray_hw_xmit(unsigned char *data, int len, struct net_device *dev, UCHAR type);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700111static int ray_init(struct net_device *dev);
112static int interrupt_ecf(ray_dev_t *local, int ccs);
113static void ray_reset(struct net_device *dev);
114static void ray_update_parm(struct net_device *dev, UCHAR objid, UCHAR *value, int len);
115static void verify_dl_startup(u_long);
116
117/* Prototypes for interrpt time functions **********************************/
John Daiker141fa612009-03-10 06:59:54 -0700118static irqreturn_t ray_interrupt(int reg, void *dev_id);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700119static void clear_interrupt(ray_dev_t *local);
John Daiker141fa612009-03-10 06:59:54 -0700120static void rx_deauthenticate(ray_dev_t *local, struct rcs __iomem *prcs,
121 unsigned int pkt_addr, int rx_len);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700122static int copy_from_rx_buff(ray_dev_t *local, UCHAR *dest, int pkt_addr, int len);
123static void ray_rx(struct net_device *dev, ray_dev_t *local, struct rcs __iomem *prcs);
124static void release_frag_chain(ray_dev_t *local, struct rcs __iomem *prcs);
125static void rx_authenticate(ray_dev_t *local, struct rcs __iomem *prcs,
John Daiker141fa612009-03-10 06:59:54 -0700126 unsigned int pkt_addr, int rx_len);
127static void rx_data(struct net_device *dev, struct rcs __iomem *prcs,
128 unsigned int pkt_addr, int rx_len);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700129static void associate(ray_dev_t *local);
130
131/* Card command functions */
132static int dl_startup_params(struct net_device *dev);
133static void join_net(u_long local);
134static void start_net(u_long local);
135/* void start_net(ray_dev_t *local); */
136
137/*===========================================================================*/
138/* Parameters that can be set with 'insmod' */
139
140/* ADHOC=0, Infrastructure=1 */
141static int net_type = ADHOC;
142
143/* Hop dwell time in Kus (1024 us units defined by 802.11) */
144static int hop_dwell = 128;
145
146/* Beacon period in Kus */
147static int beacon_period = 256;
148
149/* power save mode (0 = off, 1 = save power) */
150static int psm;
151
152/* String for network's Extended Service Set ID. 32 Characters max */
153static char *essid;
154
155/* Default to encapsulation unless translation requested */
156static int translate = 1;
157
158static int country = USA;
159
160static int sniffer;
161
162static int bc;
163
164/* 48 bit physical card address if overriding card's real physical
165 * address is required. Since IEEE 802.11 addresses are 48 bits
166 * like ethernet, an int can't be used, so a string is used. To
167 * allow use of addresses starting with a decimal digit, the first
168 * character must be a letter and will be ignored. This letter is
169 * followed by up to 12 hex digits which are the address. If less
170 * than 12 digits are used, the address will be left filled with 0's.
171 * Note that bit 0 of the first byte is the broadcast bit, and evil
172 * things will happen if it is not 0 in a card address.
173 */
174static char *phy_addr = NULL;
175
176
Dominik Brodowskifba395e2006-03-31 17:21:06 +0200177/* A struct pcmcia_device structure has fields for most things that are needed
Linus Torvalds1da177e2005-04-16 15:20:36 -0700178 to keep track of a socket, but there will usually be some device
179 specific information that also needs to be kept track of. The
Dominik Brodowskifba395e2006-03-31 17:21:06 +0200180 'priv' pointer in a struct pcmcia_device structure can be used to point to
Linus Torvalds1da177e2005-04-16 15:20:36 -0700181 a device-specific private data structure, like this.
182*/
183static unsigned int ray_mem_speed = 500;
184
Dominik Brodowskifd238232006-03-05 10:45:09 +0100185/* WARNING: THIS DRIVER IS NOT CAPABLE OF HANDLING MULTIPLE DEVICES! */
186static struct pcmcia_device *this_device = NULL;
187
Linus Torvalds1da177e2005-04-16 15:20:36 -0700188MODULE_AUTHOR("Corey Thomas <corey@world.std.com>");
189MODULE_DESCRIPTION("Raylink/WebGear wireless LAN driver");
190MODULE_LICENSE("GPL");
191
192module_param(net_type, int, 0);
193module_param(hop_dwell, int, 0);
194module_param(beacon_period, int, 0);
195module_param(psm, int, 0);
196module_param(essid, charp, 0);
197module_param(translate, int, 0);
198module_param(country, int, 0);
199module_param(sniffer, int, 0);
200module_param(bc, int, 0);
201module_param(phy_addr, charp, 0);
202module_param(ray_mem_speed, int, 0);
203
204static UCHAR b5_default_startup_parms[] = {
John Daiker141fa612009-03-10 06:59:54 -0700205 0, 0, /* Adhoc station */
206 'L', 'I', 'N', 'U', 'X', 0, 0, 0, /* 32 char ESSID */
207 0, 0, 0, 0, 0, 0, 0, 0,
208 0, 0, 0, 0, 0, 0, 0, 0,
209 0, 0, 0, 0, 0, 0, 0, 0,
210 1, 0, /* Active scan, CA Mode */
211 0, 0, 0, 0, 0, 0, /* No default MAC addr */
212 0x7f, 0xff, /* Frag threshold */
213 0x00, 0x80, /* Hop time 128 Kus */
214 0x01, 0x00, /* Beacon period 256 Kus */
215 0x01, 0x07, 0xa3, /* DTIM, retries, ack timeout */
216 0x1d, 0x82, 0x4e, /* SIFS, DIFS, PIFS */
217 0x7f, 0xff, /* RTS threshold */
218 0x04, 0xe2, 0x38, 0xA4, /* scan_dwell, max_scan_dwell */
219 0x05, /* assoc resp timeout thresh */
220 0x08, 0x02, 0x08, /* adhoc, infra, super cycle max */
221 0, /* Promiscuous mode */
222 0x0c, 0x0bd, /* Unique word */
223 0x32, /* Slot time */
224 0xff, 0xff, /* roam-low snr, low snr count */
225 0x05, 0xff, /* Infra, adhoc missed bcn thresh */
226 0x01, 0x0b, 0x4f, /* USA, hop pattern, hop pat length */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700227/* b4 - b5 differences start here */
John Daiker141fa612009-03-10 06:59:54 -0700228 0x00, 0x3f, /* CW max */
229 0x00, 0x0f, /* CW min */
230 0x04, 0x08, /* Noise gain, limit offset */
231 0x28, 0x28, /* det rssi, med busy offsets */
232 7, /* det sync thresh */
233 0, 2, 2, /* test mode, min, max */
234 0, /* allow broadcast SSID probe resp */
235 0, 0, /* privacy must start, can join */
236 2, 0, 0, 0, 0, 0, 0, 0 /* basic rate set */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700237};
238
239static UCHAR b4_default_startup_parms[] = {
John Daiker141fa612009-03-10 06:59:54 -0700240 0, 0, /* Adhoc station */
241 'L', 'I', 'N', 'U', 'X', 0, 0, 0, /* 32 char ESSID */
242 0, 0, 0, 0, 0, 0, 0, 0,
243 0, 0, 0, 0, 0, 0, 0, 0,
244 0, 0, 0, 0, 0, 0, 0, 0,
245 1, 0, /* Active scan, CA Mode */
246 0, 0, 0, 0, 0, 0, /* No default MAC addr */
247 0x7f, 0xff, /* Frag threshold */
248 0x02, 0x00, /* Hop time */
249 0x00, 0x01, /* Beacon period */
250 0x01, 0x07, 0xa3, /* DTIM, retries, ack timeout */
251 0x1d, 0x82, 0xce, /* SIFS, DIFS, PIFS */
252 0x7f, 0xff, /* RTS threshold */
253 0xfb, 0x1e, 0xc7, 0x5c, /* scan_dwell, max_scan_dwell */
254 0x05, /* assoc resp timeout thresh */
255 0x04, 0x02, 0x4, /* adhoc, infra, super cycle max */
256 0, /* Promiscuous mode */
257 0x0c, 0x0bd, /* Unique word */
258 0x4e, /* Slot time (TBD seems wrong) */
259 0xff, 0xff, /* roam-low snr, low snr count */
260 0x05, 0xff, /* Infra, adhoc missed bcn thresh */
261 0x01, 0x0b, 0x4e, /* USA, hop pattern, hop pat length */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700262/* b4 - b5 differences start here */
John Daiker141fa612009-03-10 06:59:54 -0700263 0x3f, 0x0f, /* CW max, min */
264 0x04, 0x08, /* Noise gain, limit offset */
265 0x28, 0x28, /* det rssi, med busy offsets */
266 7, /* det sync thresh */
267 0, 2, 2 /* test mode, min, max */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700268};
John Daiker141fa612009-03-10 06:59:54 -0700269
Linus Torvalds1da177e2005-04-16 15:20:36 -0700270/*===========================================================================*/
John Daiker141fa612009-03-10 06:59:54 -0700271static unsigned char eth2_llc[] = { 0xaa, 0xaa, 3, 0, 0, 0 };
Linus Torvalds1da177e2005-04-16 15:20:36 -0700272
273static char hop_pattern_length[] = { 1,
John Daiker141fa612009-03-10 06:59:54 -0700274 USA_HOP_MOD, EUROPE_HOP_MOD,
275 JAPAN_HOP_MOD, KOREA_HOP_MOD,
276 SPAIN_HOP_MOD, FRANCE_HOP_MOD,
277 ISRAEL_HOP_MOD, AUSTRALIA_HOP_MOD,
278 JAPAN_TEST_HOP_MOD
Linus Torvalds1da177e2005-04-16 15:20:36 -0700279};
280
John Daiker141fa612009-03-10 06:59:54 -0700281static char rcsid[] =
282 "Raylink/WebGear wireless LAN - Corey <Thomas corey@world.std.com>";
Linus Torvalds1da177e2005-04-16 15:20:36 -0700283
Stephen Hemminger32f5a332009-03-20 19:36:28 +0000284static const struct net_device_ops ray_netdev_ops = {
285 .ndo_init = ray_dev_init,
286 .ndo_open = ray_open,
287 .ndo_stop = ray_dev_close,
288 .ndo_start_xmit = ray_dev_start_xmit,
289 .ndo_set_config = ray_dev_config,
290 .ndo_get_stats = ray_get_stats,
291 .ndo_set_multicast_list = set_multicast_list,
292 .ndo_change_mtu = eth_change_mtu,
293 .ndo_set_mac_address = eth_mac_addr,
294 .ndo_validate_addr = eth_validate_addr,
295};
296
Linus Torvalds1da177e2005-04-16 15:20:36 -0700297/*=============================================================================
298 ray_attach() creates an "instance" of the driver, allocating
299 local data structures for one device. The device is registered
300 with Card Services.
301 The dev_link structure is initialized, but we don't actually
302 configure the card at this point -- we wait until we receive a
303 card insertion event.
304=============================================================================*/
Dominik Brodowski15b99ac2006-03-31 17:26:06 +0200305static int ray_probe(struct pcmcia_device *p_dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700306{
John Daiker141fa612009-03-10 06:59:54 -0700307 ray_dev_t *local;
308 struct net_device *dev;
Dominik Brodowskifd238232006-03-05 10:45:09 +0100309
Dominik Brodowski624dd662009-10-24 15:52:44 +0200310 dev_dbg(&p_dev->dev, "ray_attach()\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700311
John Daiker141fa612009-03-10 06:59:54 -0700312 /* Allocate space for private device-specific data */
313 dev = alloc_etherdev(sizeof(ray_dev_t));
314 if (!dev)
315 goto fail_alloc_dev;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700316
John Daiker141fa612009-03-10 06:59:54 -0700317 local = netdev_priv(dev);
318 local->finder = p_dev;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700319
John Daiker141fa612009-03-10 06:59:54 -0700320 /* The io structure describes IO port mapping. None used here */
321 p_dev->io.NumPorts1 = 0;
322 p_dev->io.Attributes1 = IO_DATA_PATH_WIDTH_8;
323 p_dev->io.IOAddrLines = 5;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700324
John Daiker141fa612009-03-10 06:59:54 -0700325 /* Interrupt setup. For PCMCIA, driver takes what's given */
Dominik Brodowski5fa91672009-11-08 17:24:46 +0100326 p_dev->irq.Attributes = IRQ_TYPE_DYNAMIC_SHARING;
John Daiker141fa612009-03-10 06:59:54 -0700327 p_dev->irq.Handler = &ray_interrupt;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700328
John Daiker141fa612009-03-10 06:59:54 -0700329 /* General socket configuration */
330 p_dev->conf.Attributes = CONF_ENABLE_IRQ;
331 p_dev->conf.IntType = INT_MEMORY_AND_IO;
332 p_dev->conf.ConfigIndex = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700333
John Daiker141fa612009-03-10 06:59:54 -0700334 p_dev->priv = dev;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700335
John Daiker141fa612009-03-10 06:59:54 -0700336 local->finder = p_dev;
337 local->card_status = CARD_INSERTED;
338 local->authentication_state = UNAUTHENTICATED;
339 local->num_multi = 0;
Dominik Brodowski624dd662009-10-24 15:52:44 +0200340 dev_dbg(&p_dev->dev, "ray_attach p_dev = %p, dev = %p, local = %p, intr = %p\n",
John Daiker141fa612009-03-10 06:59:54 -0700341 p_dev, dev, local, &ray_interrupt);
342
343 /* Raylink entries in the device structure */
Stephen Hemminger32f5a332009-03-20 19:36:28 +0000344 dev->netdev_ops = &ray_netdev_ops;
John Daiker141fa612009-03-10 06:59:54 -0700345 SET_ETHTOOL_OPS(dev, &netdev_ethtool_ops);
346 dev->wireless_handlers = &ray_handler_def;
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -0700347#ifdef WIRELESS_SPY
John Daiker141fa612009-03-10 06:59:54 -0700348 local->wireless_data.spy_data = &local->spy_data;
349 dev->wireless_data = &local->wireless_data;
350#endif /* WIRELESS_SPY */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700351
Linus Torvalds1da177e2005-04-16 15:20:36 -0700352
Dominik Brodowski624dd662009-10-24 15:52:44 +0200353 dev_dbg(&p_dev->dev, "ray_cs ray_attach calling ether_setup.)\n");
John Daiker141fa612009-03-10 06:59:54 -0700354 netif_stop_queue(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700355
John Daiker141fa612009-03-10 06:59:54 -0700356 init_timer(&local->timer);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700357
John Daiker141fa612009-03-10 06:59:54 -0700358 this_device = p_dev;
359 return ray_config(p_dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700360
361fail_alloc_dev:
John Daiker141fa612009-03-10 06:59:54 -0700362 return -ENOMEM;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700363} /* ray_attach */
John Daiker141fa612009-03-10 06:59:54 -0700364
Linus Torvalds1da177e2005-04-16 15:20:36 -0700365/*=============================================================================
366 This deletes a driver "instance". The device is de-registered
367 with Card Services. If it has been released, all local data
368 structures are freed. Otherwise, the structures will be freed
369 when the device is released.
370=============================================================================*/
Dominik Brodowskifba395e2006-03-31 17:21:06 +0200371static void ray_detach(struct pcmcia_device *link)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700372{
John Daiker141fa612009-03-10 06:59:54 -0700373 struct net_device *dev;
374 ray_dev_t *local;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700375
Dominik Brodowski624dd662009-10-24 15:52:44 +0200376 dev_dbg(&link->dev, "ray_detach\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700377
John Daiker141fa612009-03-10 06:59:54 -0700378 this_device = NULL;
379 dev = link->priv;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700380
John Daiker141fa612009-03-10 06:59:54 -0700381 ray_release(link);
Dominik Brodowskicc3b4862005-11-14 21:23:14 +0100382
John Daiker141fa612009-03-10 06:59:54 -0700383 local = netdev_priv(dev);
384 del_timer(&local->timer);
Dominik Brodowskicc3b4862005-11-14 21:23:14 +0100385
John Daiker141fa612009-03-10 06:59:54 -0700386 if (link->priv) {
387 if (link->dev_node)
388 unregister_netdev(dev);
389 free_netdev(dev);
390 }
Dominik Brodowski624dd662009-10-24 15:52:44 +0200391 dev_dbg(&link->dev, "ray_cs ray_detach ending\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700392} /* ray_detach */
John Daiker141fa612009-03-10 06:59:54 -0700393
Linus Torvalds1da177e2005-04-16 15:20:36 -0700394/*=============================================================================
395 ray_config() is run after a CARD_INSERTION event
396 is received, to configure the PCMCIA socket, and to make the
397 ethernet device available to the system.
398=============================================================================*/
Linus Torvalds1da177e2005-04-16 15:20:36 -0700399#define MAX_TUPLE_SIZE 128
Dominik Brodowski15b99ac2006-03-31 17:26:06 +0200400static int ray_config(struct pcmcia_device *link)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700401{
Dominik Brodowski624dd662009-10-24 15:52:44 +0200402 int ret = 0;
John Daiker141fa612009-03-10 06:59:54 -0700403 int i;
404 win_req_t req;
405 memreq_t mem;
406 struct net_device *dev = (struct net_device *)link->priv;
407 ray_dev_t *local = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700408
Dominik Brodowski624dd662009-10-24 15:52:44 +0200409 dev_dbg(&link->dev, "ray_config\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700410
John Daiker141fa612009-03-10 06:59:54 -0700411 /* Determine card type and firmware version */
412 printk(KERN_INFO "ray_cs Detected: %s%s%s%s\n",
413 link->prod_id[0] ? link->prod_id[0] : " ",
414 link->prod_id[1] ? link->prod_id[1] : " ",
415 link->prod_id[2] ? link->prod_id[2] : " ",
416 link->prod_id[3] ? link->prod_id[3] : " ");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700417
John Daiker141fa612009-03-10 06:59:54 -0700418 /* Now allocate an interrupt line. Note that this does not
419 actually assign a handler to the interrupt.
420 */
Dominik Brodowski624dd662009-10-24 15:52:44 +0200421 ret = pcmcia_request_irq(link, &link->irq);
422 if (ret)
423 goto failed;
John Daiker141fa612009-03-10 06:59:54 -0700424 dev->irq = link->irq.AssignedIRQ;
425
426 /* This actually configures the PCMCIA socket -- setting up
427 the I/O windows and the interrupt mapping.
428 */
Dominik Brodowski624dd662009-10-24 15:52:44 +0200429 ret = pcmcia_request_configuration(link, &link->conf);
430 if (ret)
431 goto failed;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700432
433/*** Set up 32k window for shared memory (transmit and control) ************/
John Daiker141fa612009-03-10 06:59:54 -0700434 req.Attributes =
435 WIN_DATA_WIDTH_8 | WIN_MEMORY_TYPE_CM | WIN_ENABLE | WIN_USE_WAIT;
436 req.Base = 0;
437 req.Size = 0x8000;
438 req.AccessSpeed = ray_mem_speed;
Dominik Brodowski6838b032009-11-03 01:31:52 +0100439 ret = pcmcia_request_window(link, &req, &link->win);
Dominik Brodowski624dd662009-10-24 15:52:44 +0200440 if (ret)
441 goto failed;
John Daiker141fa612009-03-10 06:59:54 -0700442 mem.CardOffset = 0x0000;
443 mem.Page = 0;
Magnus Damm868575d2006-12-13 19:46:43 +0900444 ret = pcmcia_map_mem_page(link, link->win, &mem);
Dominik Brodowski624dd662009-10-24 15:52:44 +0200445 if (ret)
446 goto failed;
John Daiker141fa612009-03-10 06:59:54 -0700447 local->sram = ioremap(req.Base, req.Size);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700448
449/*** Set up 16k window for shared memory (receive buffer) ***************/
John Daiker141fa612009-03-10 06:59:54 -0700450 req.Attributes =
451 WIN_DATA_WIDTH_8 | WIN_MEMORY_TYPE_CM | WIN_ENABLE | WIN_USE_WAIT;
452 req.Base = 0;
453 req.Size = 0x4000;
454 req.AccessSpeed = ray_mem_speed;
Dominik Brodowski6838b032009-11-03 01:31:52 +0100455 ret = pcmcia_request_window(link, &req, &local->rmem_handle);
Dominik Brodowski624dd662009-10-24 15:52:44 +0200456 if (ret)
457 goto failed;
John Daiker141fa612009-03-10 06:59:54 -0700458 mem.CardOffset = 0x8000;
459 mem.Page = 0;
Magnus Damm868575d2006-12-13 19:46:43 +0900460 ret = pcmcia_map_mem_page(link, local->rmem_handle, &mem);
Dominik Brodowski624dd662009-10-24 15:52:44 +0200461 if (ret)
462 goto failed;
John Daiker141fa612009-03-10 06:59:54 -0700463 local->rmem = ioremap(req.Base, req.Size);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700464
465/*** Set up window for attribute memory ***********************************/
John Daiker141fa612009-03-10 06:59:54 -0700466 req.Attributes =
467 WIN_DATA_WIDTH_8 | WIN_MEMORY_TYPE_AM | WIN_ENABLE | WIN_USE_WAIT;
468 req.Base = 0;
469 req.Size = 0x1000;
470 req.AccessSpeed = ray_mem_speed;
Dominik Brodowski6838b032009-11-03 01:31:52 +0100471 ret = pcmcia_request_window(link, &req, &local->amem_handle);
Dominik Brodowski624dd662009-10-24 15:52:44 +0200472 if (ret)
473 goto failed;
John Daiker141fa612009-03-10 06:59:54 -0700474 mem.CardOffset = 0x0000;
475 mem.Page = 0;
Magnus Damm868575d2006-12-13 19:46:43 +0900476 ret = pcmcia_map_mem_page(link, local->amem_handle, &mem);
Dominik Brodowski624dd662009-10-24 15:52:44 +0200477 if (ret)
478 goto failed;
John Daiker141fa612009-03-10 06:59:54 -0700479 local->amem = ioremap(req.Base, req.Size);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700480
Dominik Brodowski624dd662009-10-24 15:52:44 +0200481 dev_dbg(&link->dev, "ray_config sram=%p\n", local->sram);
482 dev_dbg(&link->dev, "ray_config rmem=%p\n", local->rmem);
483 dev_dbg(&link->dev, "ray_config amem=%p\n", local->amem);
John Daiker141fa612009-03-10 06:59:54 -0700484 if (ray_init(dev) < 0) {
485 ray_release(link);
486 return -ENODEV;
487 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700488
Dominik Brodowskidd2e5a12009-11-03 10:27:34 +0100489 SET_NETDEV_DEV(dev, &link->dev);
John Daiker141fa612009-03-10 06:59:54 -0700490 i = register_netdev(dev);
491 if (i != 0) {
492 printk("ray_config register_netdev() failed\n");
493 ray_release(link);
494 return i;
495 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700496
John Daiker141fa612009-03-10 06:59:54 -0700497 strcpy(local->node.dev_name, dev->name);
498 link->dev_node = &local->node;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700499
John Daiker141fa612009-03-10 06:59:54 -0700500 printk(KERN_INFO "%s: RayLink, irq %d, hw_addr %pM\n",
501 dev->name, dev->irq, dev->dev_addr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700502
John Daiker141fa612009-03-10 06:59:54 -0700503 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700504
Dominik Brodowski624dd662009-10-24 15:52:44 +0200505failed:
John Daiker141fa612009-03-10 06:59:54 -0700506 ray_release(link);
507 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700508} /* ray_config */
509
510static inline struct ccs __iomem *ccs_base(ray_dev_t *dev)
511{
512 return dev->sram + CCS_BASE;
513}
514
515static inline struct rcs __iomem *rcs_base(ray_dev_t *dev)
516{
517 /*
518 * This looks nonsensical, since there is a separate
519 * RCS_BASE. But the difference between a "struct rcs"
520 * and a "struct ccs" ends up being in the _index_ off
521 * the base, so the base pointer is the same for both
522 * ccs/rcs.
523 */
524 return dev->sram + CCS_BASE;
525}
526
527/*===========================================================================*/
528static int ray_init(struct net_device *dev)
529{
John Daiker141fa612009-03-10 06:59:54 -0700530 int i;
531 UCHAR *p;
532 struct ccs __iomem *pccs;
533 ray_dev_t *local = netdev_priv(dev);
534 struct pcmcia_device *link = local->finder;
Dominik Brodowski624dd662009-10-24 15:52:44 +0200535 dev_dbg(&link->dev, "ray_init(0x%p)\n", dev);
John Daiker141fa612009-03-10 06:59:54 -0700536 if (!(pcmcia_dev_present(link))) {
Dominik Brodowski624dd662009-10-24 15:52:44 +0200537 dev_dbg(&link->dev, "ray_init - device not present\n");
John Daiker141fa612009-03-10 06:59:54 -0700538 return -1;
539 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700540
John Daiker141fa612009-03-10 06:59:54 -0700541 local->net_type = net_type;
542 local->sta_type = TYPE_STA;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700543
John Daiker141fa612009-03-10 06:59:54 -0700544 /* Copy the startup results to local memory */
545 memcpy_fromio(&local->startup_res, local->sram + ECF_TO_HOST_BASE,
546 sizeof(struct startup_res_6));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700547
John Daiker141fa612009-03-10 06:59:54 -0700548 /* Check Power up test status and get mac address from card */
549 if (local->startup_res.startup_word != 0x80) {
550 printk(KERN_INFO "ray_init ERROR card status = %2x\n",
551 local->startup_res.startup_word);
552 local->card_status = CARD_INIT_ERROR;
553 return -1;
554 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700555
John Daiker141fa612009-03-10 06:59:54 -0700556 local->fw_ver = local->startup_res.firmware_version[0];
557 local->fw_bld = local->startup_res.firmware_version[1];
558 local->fw_var = local->startup_res.firmware_version[2];
Dominik Brodowski624dd662009-10-24 15:52:44 +0200559 dev_dbg(&link->dev, "ray_init firmware version %d.%d \n", local->fw_ver,
John Daiker141fa612009-03-10 06:59:54 -0700560 local->fw_bld);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700561
John Daiker141fa612009-03-10 06:59:54 -0700562 local->tib_length = 0x20;
563 if ((local->fw_ver == 5) && (local->fw_bld >= 30))
564 local->tib_length = local->startup_res.tib_length;
Dominik Brodowski624dd662009-10-24 15:52:44 +0200565 dev_dbg(&link->dev, "ray_init tib_length = 0x%02x\n", local->tib_length);
John Daiker141fa612009-03-10 06:59:54 -0700566 /* Initialize CCS's to buffer free state */
567 pccs = ccs_base(local);
568 for (i = 0; i < NUMBER_OF_CCS; i++) {
569 writeb(CCS_BUFFER_FREE, &(pccs++)->buffer_status);
570 }
571 init_startup_params(local);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700572
John Daiker141fa612009-03-10 06:59:54 -0700573 /* copy mac address to startup parameters */
574 if (parse_addr(phy_addr, local->sparm.b4.a_mac_addr)) {
575 p = local->sparm.b4.a_mac_addr;
576 } else {
577 memcpy(&local->sparm.b4.a_mac_addr,
578 &local->startup_res.station_addr, ADDRLEN);
579 p = local->sparm.b4.a_mac_addr;
580 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700581
John Daiker141fa612009-03-10 06:59:54 -0700582 clear_interrupt(local); /* Clear any interrupt from the card */
583 local->card_status = CARD_AWAITING_PARAM;
Dominik Brodowski624dd662009-10-24 15:52:44 +0200584 dev_dbg(&link->dev, "ray_init ending\n");
John Daiker141fa612009-03-10 06:59:54 -0700585 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700586} /* ray_init */
John Daiker141fa612009-03-10 06:59:54 -0700587
Linus Torvalds1da177e2005-04-16 15:20:36 -0700588/*===========================================================================*/
589/* Download startup parameters to the card and command it to read them */
590static int dl_startup_params(struct net_device *dev)
591{
John Daiker141fa612009-03-10 06:59:54 -0700592 int ccsindex;
593 ray_dev_t *local = netdev_priv(dev);
594 struct ccs __iomem *pccs;
595 struct pcmcia_device *link = local->finder;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700596
Dominik Brodowski624dd662009-10-24 15:52:44 +0200597 dev_dbg(&link->dev, "dl_startup_params entered\n");
John Daiker141fa612009-03-10 06:59:54 -0700598 if (!(pcmcia_dev_present(link))) {
Dominik Brodowski624dd662009-10-24 15:52:44 +0200599 dev_dbg(&link->dev, "ray_cs dl_startup_params - device not present\n");
John Daiker141fa612009-03-10 06:59:54 -0700600 return -1;
601 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700602
John Daiker141fa612009-03-10 06:59:54 -0700603 /* Copy parameters to host to ECF area */
604 if (local->fw_ver == 0x55)
605 memcpy_toio(local->sram + HOST_TO_ECF_BASE, &local->sparm.b4,
606 sizeof(struct b4_startup_params));
607 else
608 memcpy_toio(local->sram + HOST_TO_ECF_BASE, &local->sparm.b5,
609 sizeof(struct b5_startup_params));
610
611 /* Fill in the CCS fields for the ECF */
612 if ((ccsindex = get_free_ccs(local)) < 0)
613 return -1;
614 local->dl_param_ccs = ccsindex;
615 pccs = ccs_base(local) + ccsindex;
616 writeb(CCS_DOWNLOAD_STARTUP_PARAMS, &pccs->cmd);
Dominik Brodowski624dd662009-10-24 15:52:44 +0200617 dev_dbg(&link->dev, "dl_startup_params start ccsindex = %d\n",
John Daiker141fa612009-03-10 06:59:54 -0700618 local->dl_param_ccs);
619 /* Interrupt the firmware to process the command */
620 if (interrupt_ecf(local, ccsindex)) {
621 printk(KERN_INFO "ray dl_startup_params failed - "
622 "ECF not ready for intr\n");
623 local->card_status = CARD_DL_PARAM_ERROR;
624 writeb(CCS_BUFFER_FREE, &(pccs++)->buffer_status);
625 return -2;
626 }
627 local->card_status = CARD_DL_PARAM;
628 /* Start kernel timer to wait for dl startup to complete. */
629 local->timer.expires = jiffies + HZ / 2;
630 local->timer.data = (long)local;
631 local->timer.function = &verify_dl_startup;
632 add_timer(&local->timer);
Dominik Brodowski624dd662009-10-24 15:52:44 +0200633 dev_dbg(&link->dev,
John Daiker141fa612009-03-10 06:59:54 -0700634 "ray_cs dl_startup_params started timer for verify_dl_startup\n");
635 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700636} /* dl_startup_params */
John Daiker141fa612009-03-10 06:59:54 -0700637
Linus Torvalds1da177e2005-04-16 15:20:36 -0700638/*===========================================================================*/
639static void init_startup_params(ray_dev_t *local)
640{
John Daiker141fa612009-03-10 06:59:54 -0700641 int i;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700642
John Daiker141fa612009-03-10 06:59:54 -0700643 if (country > JAPAN_TEST)
644 country = USA;
645 else if (country < USA)
646 country = USA;
647 /* structure for hop time and beacon period is defined here using
648 * New 802.11D6.1 format. Card firmware is still using old format
649 * until version 6.
650 * Before After
651 * a_hop_time ms byte a_hop_time ms byte
652 * a_hop_time 2s byte a_hop_time ls byte
653 * a_hop_time ls byte a_beacon_period ms byte
654 * a_beacon_period a_beacon_period ls byte
655 *
656 * a_hop_time = uS a_hop_time = KuS
657 * a_beacon_period = hops a_beacon_period = KuS
658 *//* 64ms = 010000 */
659 if (local->fw_ver == 0x55) {
660 memcpy((UCHAR *) &local->sparm.b4, b4_default_startup_parms,
661 sizeof(struct b4_startup_params));
662 /* Translate sane kus input values to old build 4/5 format */
663 /* i = hop time in uS truncated to 3 bytes */
664 i = (hop_dwell * 1024) & 0xffffff;
665 local->sparm.b4.a_hop_time[0] = (i >> 16) & 0xff;
666 local->sparm.b4.a_hop_time[1] = (i >> 8) & 0xff;
667 local->sparm.b4.a_beacon_period[0] = 0;
668 local->sparm.b4.a_beacon_period[1] =
669 ((beacon_period / hop_dwell) - 1) & 0xff;
670 local->sparm.b4.a_curr_country_code = country;
671 local->sparm.b4.a_hop_pattern_length =
672 hop_pattern_length[(int)country] - 1;
673 if (bc) {
674 local->sparm.b4.a_ack_timeout = 0x50;
675 local->sparm.b4.a_sifs = 0x3f;
676 }
677 } else { /* Version 5 uses real kus values */
678 memcpy((UCHAR *) &local->sparm.b5, b5_default_startup_parms,
679 sizeof(struct b5_startup_params));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700680
John Daiker141fa612009-03-10 06:59:54 -0700681 local->sparm.b5.a_hop_time[0] = (hop_dwell >> 8) & 0xff;
682 local->sparm.b5.a_hop_time[1] = hop_dwell & 0xff;
683 local->sparm.b5.a_beacon_period[0] =
684 (beacon_period >> 8) & 0xff;
685 local->sparm.b5.a_beacon_period[1] = beacon_period & 0xff;
686 if (psm)
687 local->sparm.b5.a_power_mgt_state = 1;
688 local->sparm.b5.a_curr_country_code = country;
689 local->sparm.b5.a_hop_pattern_length =
690 hop_pattern_length[(int)country];
691 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700692
John Daiker141fa612009-03-10 06:59:54 -0700693 local->sparm.b4.a_network_type = net_type & 0x01;
694 local->sparm.b4.a_acting_as_ap_status = TYPE_STA;
695
696 if (essid != NULL)
697 strncpy(local->sparm.b4.a_current_ess_id, essid, ESSID_SIZE);
698} /* init_startup_params */
699
Linus Torvalds1da177e2005-04-16 15:20:36 -0700700/*===========================================================================*/
701static void verify_dl_startup(u_long data)
702{
John Daiker141fa612009-03-10 06:59:54 -0700703 ray_dev_t *local = (ray_dev_t *) data;
704 struct ccs __iomem *pccs = ccs_base(local) + local->dl_param_ccs;
705 UCHAR status;
706 struct pcmcia_device *link = local->finder;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700707
John Daiker141fa612009-03-10 06:59:54 -0700708 if (!(pcmcia_dev_present(link))) {
Dominik Brodowski624dd662009-10-24 15:52:44 +0200709 dev_dbg(&link->dev, "ray_cs verify_dl_startup - device not present\n");
John Daiker141fa612009-03-10 06:59:54 -0700710 return;
711 }
Dominik Brodowski624dd662009-10-24 15:52:44 +0200712#if 0
713 {
John Daiker141fa612009-03-10 06:59:54 -0700714 int i;
715 printk(KERN_DEBUG
716 "verify_dl_startup parameters sent via ccs %d:\n",
717 local->dl_param_ccs);
718 for (i = 0; i < sizeof(struct b5_startup_params); i++) {
719 printk(" %2x",
720 (unsigned int)readb(local->sram +
721 HOST_TO_ECF_BASE + i));
722 }
723 printk("\n");
724 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700725#endif
726
John Daiker141fa612009-03-10 06:59:54 -0700727 status = readb(&pccs->buffer_status);
728 if (status != CCS_BUFFER_FREE) {
729 printk(KERN_INFO
730 "Download startup params failed. Status = %d\n",
731 status);
732 local->card_status = CARD_DL_PARAM_ERROR;
733 return;
734 }
735 if (local->sparm.b4.a_network_type == ADHOC)
736 start_net((u_long) local);
737 else
738 join_net((u_long) local);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700739
John Daiker141fa612009-03-10 06:59:54 -0700740 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700741} /* end verify_dl_startup */
John Daiker141fa612009-03-10 06:59:54 -0700742
Linus Torvalds1da177e2005-04-16 15:20:36 -0700743/*===========================================================================*/
744/* Command card to start a network */
745static void start_net(u_long data)
746{
John Daiker141fa612009-03-10 06:59:54 -0700747 ray_dev_t *local = (ray_dev_t *) data;
748 struct ccs __iomem *pccs;
749 int ccsindex;
750 struct pcmcia_device *link = local->finder;
751 if (!(pcmcia_dev_present(link))) {
Dominik Brodowski624dd662009-10-24 15:52:44 +0200752 dev_dbg(&link->dev, "ray_cs start_net - device not present\n");
John Daiker141fa612009-03-10 06:59:54 -0700753 return;
754 }
755 /* Fill in the CCS fields for the ECF */
756 if ((ccsindex = get_free_ccs(local)) < 0)
757 return;
758 pccs = ccs_base(local) + ccsindex;
759 writeb(CCS_START_NETWORK, &pccs->cmd);
760 writeb(0, &pccs->var.start_network.update_param);
761 /* Interrupt the firmware to process the command */
762 if (interrupt_ecf(local, ccsindex)) {
Dominik Brodowski624dd662009-10-24 15:52:44 +0200763 dev_dbg(&link->dev, "ray start net failed - card not ready for intr\n");
John Daiker141fa612009-03-10 06:59:54 -0700764 writeb(CCS_BUFFER_FREE, &(pccs++)->buffer_status);
765 return;
766 }
767 local->card_status = CARD_DOING_ACQ;
768 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700769} /* end start_net */
John Daiker141fa612009-03-10 06:59:54 -0700770
Linus Torvalds1da177e2005-04-16 15:20:36 -0700771/*===========================================================================*/
772/* Command card to join a network */
773static void join_net(u_long data)
774{
John Daiker141fa612009-03-10 06:59:54 -0700775 ray_dev_t *local = (ray_dev_t *) data;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700776
John Daiker141fa612009-03-10 06:59:54 -0700777 struct ccs __iomem *pccs;
778 int ccsindex;
779 struct pcmcia_device *link = local->finder;
780
781 if (!(pcmcia_dev_present(link))) {
Dominik Brodowski624dd662009-10-24 15:52:44 +0200782 dev_dbg(&link->dev, "ray_cs join_net - device not present\n");
John Daiker141fa612009-03-10 06:59:54 -0700783 return;
784 }
785 /* Fill in the CCS fields for the ECF */
786 if ((ccsindex = get_free_ccs(local)) < 0)
787 return;
788 pccs = ccs_base(local) + ccsindex;
789 writeb(CCS_JOIN_NETWORK, &pccs->cmd);
790 writeb(0, &pccs->var.join_network.update_param);
791 writeb(0, &pccs->var.join_network.net_initiated);
792 /* Interrupt the firmware to process the command */
793 if (interrupt_ecf(local, ccsindex)) {
Dominik Brodowski624dd662009-10-24 15:52:44 +0200794 dev_dbg(&link->dev, "ray join net failed - card not ready for intr\n");
John Daiker141fa612009-03-10 06:59:54 -0700795 writeb(CCS_BUFFER_FREE, &(pccs++)->buffer_status);
796 return;
797 }
798 local->card_status = CARD_DOING_ACQ;
799 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700800}
John Daiker141fa612009-03-10 06:59:54 -0700801
Linus Torvalds1da177e2005-04-16 15:20:36 -0700802/*============================================================================
803 After a card is removed, ray_release() will unregister the net
804 device, and release the PCMCIA configuration. If the device is
805 still open, this will be postponed until it is closed.
806=============================================================================*/
Dominik Brodowskifba395e2006-03-31 17:21:06 +0200807static void ray_release(struct pcmcia_device *link)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700808{
John Daiker141fa612009-03-10 06:59:54 -0700809 struct net_device *dev = link->priv;
810 ray_dev_t *local = netdev_priv(dev);
811 int i;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700812
Dominik Brodowski624dd662009-10-24 15:52:44 +0200813 dev_dbg(&link->dev, "ray_release\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700814
John Daiker141fa612009-03-10 06:59:54 -0700815 del_timer(&local->timer);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700816
John Daiker141fa612009-03-10 06:59:54 -0700817 iounmap(local->sram);
818 iounmap(local->rmem);
819 iounmap(local->amem);
820 /* Do bother checking to see if these succeed or not */
Magnus Dammf5560da2006-12-13 19:46:38 +0900821 i = pcmcia_release_window(link, local->amem_handle);
John Daiker141fa612009-03-10 06:59:54 -0700822 if (i != 0)
Dominik Brodowski624dd662009-10-24 15:52:44 +0200823 dev_dbg(&link->dev, "ReleaseWindow(local->amem) ret = %x\n", i);
Magnus Dammf5560da2006-12-13 19:46:38 +0900824 i = pcmcia_release_window(link, local->rmem_handle);
John Daiker141fa612009-03-10 06:59:54 -0700825 if (i != 0)
Dominik Brodowski624dd662009-10-24 15:52:44 +0200826 dev_dbg(&link->dev, "ReleaseWindow(local->rmem) ret = %x\n", i);
John Daiker141fa612009-03-10 06:59:54 -0700827 pcmcia_disable_device(link);
828
Dominik Brodowski624dd662009-10-24 15:52:44 +0200829 dev_dbg(&link->dev, "ray_release ending\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700830}
831
Dominik Brodowskifba395e2006-03-31 17:21:06 +0200832static int ray_suspend(struct pcmcia_device *link)
Dominik Brodowski98e4c282005-11-14 21:21:18 +0100833{
Dominik Brodowski98e4c282005-11-14 21:21:18 +0100834 struct net_device *dev = link->priv;
835
Dominik Brodowskie2d40962006-03-02 00:09:29 +0100836 if (link->open)
Dominik Brodowski8661bb52006-03-02 00:02:33 +0100837 netif_device_detach(dev);
Dominik Brodowski98e4c282005-11-14 21:21:18 +0100838
839 return 0;
840}
841
Dominik Brodowskifba395e2006-03-31 17:21:06 +0200842static int ray_resume(struct pcmcia_device *link)
Dominik Brodowski98e4c282005-11-14 21:21:18 +0100843{
Dominik Brodowski98e4c282005-11-14 21:21:18 +0100844 struct net_device *dev = link->priv;
845
Dominik Brodowskie2d40962006-03-02 00:09:29 +0100846 if (link->open) {
Dominik Brodowski8661bb52006-03-02 00:02:33 +0100847 ray_reset(dev);
848 netif_device_attach(dev);
849 }
Dominik Brodowski98e4c282005-11-14 21:21:18 +0100850
851 return 0;
852}
853
Linus Torvalds1da177e2005-04-16 15:20:36 -0700854/*===========================================================================*/
Hannes Eder2ed5ba82008-12-26 00:12:59 -0800855static int ray_dev_init(struct net_device *dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700856{
857#ifdef RAY_IMMEDIATE_INIT
John Daiker141fa612009-03-10 06:59:54 -0700858 int i;
859#endif /* RAY_IMMEDIATE_INIT */
860 ray_dev_t *local = netdev_priv(dev);
861 struct pcmcia_device *link = local->finder;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700862
Dominik Brodowski624dd662009-10-24 15:52:44 +0200863 dev_dbg(&link->dev, "ray_dev_init(dev=%p)\n", dev);
John Daiker141fa612009-03-10 06:59:54 -0700864 if (!(pcmcia_dev_present(link))) {
Dominik Brodowski624dd662009-10-24 15:52:44 +0200865 dev_dbg(&link->dev, "ray_dev_init - device not present\n");
John Daiker141fa612009-03-10 06:59:54 -0700866 return -1;
867 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700868#ifdef RAY_IMMEDIATE_INIT
John Daiker141fa612009-03-10 06:59:54 -0700869 /* Download startup parameters */
870 if ((i = dl_startup_params(dev)) < 0) {
871 printk(KERN_INFO "ray_dev_init dl_startup_params failed - "
872 "returns 0x%x\n", i);
873 return -1;
874 }
875#else /* RAY_IMMEDIATE_INIT */
876 /* Postpone the card init so that we can still configure the card,
877 * for example using the Wireless Extensions. The init will happen
878 * in ray_open() - Jean II */
Dominik Brodowski624dd662009-10-24 15:52:44 +0200879 dev_dbg(&link->dev,
John Daiker141fa612009-03-10 06:59:54 -0700880 "ray_dev_init: postponing card init to ray_open() ; Status = %d\n",
881 local->card_status);
882#endif /* RAY_IMMEDIATE_INIT */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700883
John Daiker141fa612009-03-10 06:59:54 -0700884 /* copy mac and broadcast addresses to linux device */
Jiri Pirko3a6d54c2009-05-11 23:37:15 +0000885 memcpy(dev->dev_addr, &local->sparm.b4.a_mac_addr, ADDRLEN);
John Daiker141fa612009-03-10 06:59:54 -0700886 memset(dev->broadcast, 0xff, ETH_ALEN);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700887
Dominik Brodowski624dd662009-10-24 15:52:44 +0200888 dev_dbg(&link->dev, "ray_dev_init ending\n");
John Daiker141fa612009-03-10 06:59:54 -0700889 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700890}
John Daiker141fa612009-03-10 06:59:54 -0700891
Linus Torvalds1da177e2005-04-16 15:20:36 -0700892/*===========================================================================*/
893static int ray_dev_config(struct net_device *dev, struct ifmap *map)
894{
John Daiker141fa612009-03-10 06:59:54 -0700895 ray_dev_t *local = netdev_priv(dev);
896 struct pcmcia_device *link = local->finder;
897 /* Dummy routine to satisfy device structure */
Dominik Brodowski624dd662009-10-24 15:52:44 +0200898 dev_dbg(&link->dev, "ray_dev_config(dev=%p,ifmap=%p)\n", dev, map);
John Daiker141fa612009-03-10 06:59:54 -0700899 if (!(pcmcia_dev_present(link))) {
Dominik Brodowski624dd662009-10-24 15:52:44 +0200900 dev_dbg(&link->dev, "ray_dev_config - device not present\n");
John Daiker141fa612009-03-10 06:59:54 -0700901 return -1;
902 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700903
John Daiker141fa612009-03-10 06:59:54 -0700904 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700905}
John Daiker141fa612009-03-10 06:59:54 -0700906
Linus Torvalds1da177e2005-04-16 15:20:36 -0700907/*===========================================================================*/
Stephen Hemmingerd0cf9c02009-08-31 19:50:57 +0000908static netdev_tx_t ray_dev_start_xmit(struct sk_buff *skb,
909 struct net_device *dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700910{
John Daiker141fa612009-03-10 06:59:54 -0700911 ray_dev_t *local = netdev_priv(dev);
912 struct pcmcia_device *link = local->finder;
913 short length = skb->len;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700914
Stephen Hemmingerd0cf9c02009-08-31 19:50:57 +0000915 if (!pcmcia_dev_present(link)) {
Dominik Brodowski624dd662009-10-24 15:52:44 +0200916 dev_dbg(&link->dev, "ray_dev_start_xmit - device not present\n");
Stephen Hemmingerd0cf9c02009-08-31 19:50:57 +0000917 dev_kfree_skb(skb);
918 return NETDEV_TX_OK;
John Daiker141fa612009-03-10 06:59:54 -0700919 }
Stephen Hemmingerd0cf9c02009-08-31 19:50:57 +0000920
Dominik Brodowski624dd662009-10-24 15:52:44 +0200921 dev_dbg(&link->dev, "ray_dev_start_xmit(skb=%p, dev=%p)\n", skb, dev);
John Daiker141fa612009-03-10 06:59:54 -0700922 if (local->authentication_state == NEED_TO_AUTH) {
Dominik Brodowski624dd662009-10-24 15:52:44 +0200923 dev_dbg(&link->dev, "ray_cs Sending authentication request.\n");
John Daiker141fa612009-03-10 06:59:54 -0700924 if (!build_auth_frame(local, local->auth_id, OPEN_AUTH_REQUEST)) {
925 local->authentication_state = AUTHENTICATED;
926 netif_stop_queue(dev);
Patrick McHardy5b548142009-06-12 06:22:29 +0000927 return NETDEV_TX_BUSY;
John Daiker141fa612009-03-10 06:59:54 -0700928 }
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))
Patrick McHardy6ed10652009-06-23 06:03:08 +0000933 return NETDEV_TX_OK;
John Daiker141fa612009-03-10 06:59:54 -0700934 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);
Patrick McHardy5b548142009-06-12 06:22:29 +0000940 return NETDEV_TX_BUSY;
John Daiker141fa612009-03-10 06:59:54 -0700941 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);
John Daiker141fa612009-03-10 06:59:54 -0700947 }
Stephen Hemmingerd0cf9c02009-08-31 19:50:57 +0000948
Patrick McHardy6ed10652009-06-23 06:03:08 +0000949 return NETDEV_TX_OK;
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
Dominik Brodowski624dd662009-10-24 15:52:44 +0200963 pr_debug("ray_hw_xmit(data=%p, len=%d, dev=%p)\n", data, len, dev);
John Daiker141fa612009-03-10 06:59:54 -0700964 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:
Dominik Brodowski624dd662009-10-24 15:52:44 +0200971 pr_debug("ray_hw_xmit tx_ccs table busy\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700972 case ECCSFULL:
Dominik Brodowski624dd662009-10-24 15:52:44 +0200973 pr_debug("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);
Dominik Brodowski624dd662009-10-24 15:52:44 +02001010 pr_debug("ray_hw_xmit default_tx_rate = 0x%x\n",
John Daiker141fa612009-03-10 06:59:54 -07001011 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)) {
Dominik Brodowski624dd662009-10-24 15:52:44 +02001015 pr_debug("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 */
Dominik Brodowski624dd662009-10-24 15:52:44 +02001032 pr_debug("ray_cs translate_frame DIX II\n");
John Daiker141fa612009-03-10 06:59:54 -07001033 /* 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 */
Dominik Brodowski624dd662009-10-24 15:52:44 +02001048 pr_debug("ray_cs translate_frame 802\n");
John Daiker141fa612009-03-10 06:59:54 -07001049 if (proto == htons(0xffff)) { /* evil netware IPX 802.3 without LLC */
Dominik Brodowski624dd662009-10-24 15:52:44 +02001050 pr_debug("ray_cs translate_frame evil IPX\n");
John Daiker141fa612009-03-10 06:59:54 -07001051 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 local->wstats.status = local->card_status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001508#ifdef WIRELESS_SPY
John Daiker141fa612009-03-10 06:59:54 -07001509 if ((local->spy_data.spy_number > 0)
1510 && (local->sparm.b5.a_network_type == 0)) {
1511 /* Get it from the first node in spy list */
1512 local->wstats.qual.qual = local->spy_data.spy_stat[0].qual;
1513 local->wstats.qual.level = local->spy_data.spy_stat[0].level;
1514 local->wstats.qual.noise = local->spy_data.spy_stat[0].noise;
1515 local->wstats.qual.updated =
1516 local->spy_data.spy_stat[0].updated;
1517 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001518#endif /* WIRELESS_SPY */
1519
John Daiker141fa612009-03-10 06:59:54 -07001520 if (pcmcia_dev_present(link)) {
1521 local->wstats.qual.noise = readb(&p->rxnoise);
1522 local->wstats.qual.updated |= 4;
1523 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001524
John Daiker141fa612009-03-10 06:59:54 -07001525 return &local->wstats;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001526} /* end ray_get_wireless_stats */
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001527
1528/*------------------------------------------------------------------*/
1529/*
1530 * Structures to export the Wireless Handlers
1531 */
1532
John Daiker141fa612009-03-10 06:59:54 -07001533static const iw_handler ray_handler[] = {
1534 [SIOCSIWCOMMIT - SIOCIWFIRST] = (iw_handler) ray_commit,
1535 [SIOCGIWNAME - SIOCIWFIRST] = (iw_handler) ray_get_name,
1536 [SIOCSIWFREQ - SIOCIWFIRST] = (iw_handler) ray_set_freq,
1537 [SIOCGIWFREQ - SIOCIWFIRST] = (iw_handler) ray_get_freq,
1538 [SIOCSIWMODE - SIOCIWFIRST] = (iw_handler) ray_set_mode,
1539 [SIOCGIWMODE - SIOCIWFIRST] = (iw_handler) ray_get_mode,
1540 [SIOCGIWRANGE - SIOCIWFIRST] = (iw_handler) ray_get_range,
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001541#ifdef WIRELESS_SPY
John Daiker141fa612009-03-10 06:59:54 -07001542 [SIOCSIWSPY - SIOCIWFIRST] = (iw_handler) iw_handler_set_spy,
1543 [SIOCGIWSPY - SIOCIWFIRST] = (iw_handler) iw_handler_get_spy,
1544 [SIOCSIWTHRSPY - SIOCIWFIRST] = (iw_handler) iw_handler_set_thrspy,
1545 [SIOCGIWTHRSPY - SIOCIWFIRST] = (iw_handler) iw_handler_get_thrspy,
1546#endif /* WIRELESS_SPY */
1547 [SIOCGIWAP - SIOCIWFIRST] = (iw_handler) ray_get_wap,
1548 [SIOCSIWESSID - SIOCIWFIRST] = (iw_handler) ray_set_essid,
1549 [SIOCGIWESSID - SIOCIWFIRST] = (iw_handler) ray_get_essid,
1550 [SIOCSIWRATE - SIOCIWFIRST] = (iw_handler) ray_set_rate,
1551 [SIOCGIWRATE - SIOCIWFIRST] = (iw_handler) ray_get_rate,
1552 [SIOCSIWRTS - SIOCIWFIRST] = (iw_handler) ray_set_rts,
1553 [SIOCGIWRTS - SIOCIWFIRST] = (iw_handler) ray_get_rts,
1554 [SIOCSIWFRAG - SIOCIWFIRST] = (iw_handler) ray_set_frag,
1555 [SIOCGIWFRAG - SIOCIWFIRST] = (iw_handler) ray_get_frag,
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001556};
1557
John Daiker141fa612009-03-10 06:59:54 -07001558#define SIOCSIPFRAMING SIOCIWFIRSTPRIV /* Set framing mode */
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001559#define SIOCGIPFRAMING SIOCIWFIRSTPRIV + 1 /* Get framing mode */
1560#define SIOCGIPCOUNTRY SIOCIWFIRSTPRIV + 3 /* Get country code */
1561
John Daiker141fa612009-03-10 06:59:54 -07001562static const iw_handler ray_private_handler[] = {
viro@ZenIV.linux.org.uk7a700fa2005-09-09 20:40:23 +01001563 [0] = (iw_handler) ray_set_framing,
1564 [1] = (iw_handler) ray_get_framing,
1565 [3] = (iw_handler) ray_get_country,
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001566};
1567
John Daiker141fa612009-03-10 06:59:54 -07001568static const struct iw_priv_args ray_private_args[] = {
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001569/* cmd, set_args, get_args, name */
John Daiker141fa612009-03-10 06:59:54 -07001570 {SIOCSIPFRAMING, IW_PRIV_TYPE_BYTE | IW_PRIV_SIZE_FIXED | 1, 0,
1571 "set_framing"},
1572 {SIOCGIPFRAMING, 0, IW_PRIV_TYPE_BYTE | IW_PRIV_SIZE_FIXED | 1,
1573 "get_framing"},
1574 {SIOCGIPCOUNTRY, 0, IW_PRIV_TYPE_BYTE | IW_PRIV_SIZE_FIXED | 1,
1575 "get_country"},
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001576};
1577
John Daiker141fa612009-03-10 06:59:54 -07001578static const struct iw_handler_def ray_handler_def = {
1579 .num_standard = ARRAY_SIZE(ray_handler),
1580 .num_private = ARRAY_SIZE(ray_private_handler),
Denis Chengff8ac602007-09-02 18:30:18 +08001581 .num_private_args = ARRAY_SIZE(ray_private_args),
John Daiker141fa612009-03-10 06:59:54 -07001582 .standard = ray_handler,
1583 .private = ray_private_handler,
1584 .private_args = ray_private_args,
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001585 .get_wireless_stats = ray_get_wireless_stats,
1586};
1587
Linus Torvalds1da177e2005-04-16 15:20:36 -07001588/*===========================================================================*/
1589static int ray_open(struct net_device *dev)
1590{
John Daiker141fa612009-03-10 06:59:54 -07001591 ray_dev_t *local = netdev_priv(dev);
1592 struct pcmcia_device *link;
1593 link = local->finder;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001594
Dominik Brodowski624dd662009-10-24 15:52:44 +02001595 dev_dbg(&link->dev, "ray_open('%s')\n", dev->name);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001596
John Daiker141fa612009-03-10 06:59:54 -07001597 if (link->open == 0)
1598 local->num_multi = 0;
1599 link->open++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001600
John Daiker141fa612009-03-10 06:59:54 -07001601 /* If the card is not started, time to start it ! - Jean II */
1602 if (local->card_status == CARD_AWAITING_PARAM) {
1603 int i;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001604
Dominik Brodowski624dd662009-10-24 15:52:44 +02001605 dev_dbg(&link->dev, "ray_open: doing init now !\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001606
John Daiker141fa612009-03-10 06:59:54 -07001607 /* Download startup parameters */
1608 if ((i = dl_startup_params(dev)) < 0) {
1609 printk(KERN_INFO
1610 "ray_dev_init dl_startup_params failed - "
1611 "returns 0x%x\n", i);
1612 return -1;
1613 }
1614 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001615
John Daiker141fa612009-03-10 06:59:54 -07001616 if (sniffer)
1617 netif_stop_queue(dev);
1618 else
1619 netif_start_queue(dev);
1620
Dominik Brodowski624dd662009-10-24 15:52:44 +02001621 dev_dbg(&link->dev, "ray_open ending\n");
John Daiker141fa612009-03-10 06:59:54 -07001622 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001623} /* end ray_open */
John Daiker141fa612009-03-10 06:59:54 -07001624
Linus Torvalds1da177e2005-04-16 15:20:36 -07001625/*===========================================================================*/
1626static int ray_dev_close(struct net_device *dev)
1627{
John Daiker141fa612009-03-10 06:59:54 -07001628 ray_dev_t *local = netdev_priv(dev);
1629 struct pcmcia_device *link;
1630 link = local->finder;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001631
Dominik Brodowski624dd662009-10-24 15:52:44 +02001632 dev_dbg(&link->dev, "ray_dev_close('%s')\n", dev->name);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001633
John Daiker141fa612009-03-10 06:59:54 -07001634 link->open--;
1635 netif_stop_queue(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001636
John Daiker141fa612009-03-10 06:59:54 -07001637 /* In here, we should stop the hardware (stop card from beeing active)
1638 * and set local->card_status to CARD_AWAITING_PARAM, so that while the
1639 * card is closed we can chage its configuration.
1640 * Probably also need a COR reset to get sane state - Jean II */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001641
John Daiker141fa612009-03-10 06:59:54 -07001642 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001643} /* end ray_dev_close */
John Daiker141fa612009-03-10 06:59:54 -07001644
Linus Torvalds1da177e2005-04-16 15:20:36 -07001645/*===========================================================================*/
John Daiker141fa612009-03-10 06:59:54 -07001646static void ray_reset(struct net_device *dev)
1647{
Dominik Brodowski624dd662009-10-24 15:52:44 +02001648 pr_debug("ray_reset entered\n");
John Daiker141fa612009-03-10 06:59:54 -07001649 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001650}
John Daiker141fa612009-03-10 06:59:54 -07001651
Linus Torvalds1da177e2005-04-16 15:20:36 -07001652/*===========================================================================*/
1653/* Cause a firmware interrupt if it is ready for one */
1654/* Return nonzero if not ready */
1655static int interrupt_ecf(ray_dev_t *local, int ccs)
1656{
John Daiker141fa612009-03-10 06:59:54 -07001657 int i = 50;
1658 struct pcmcia_device *link = local->finder;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001659
John Daiker141fa612009-03-10 06:59:54 -07001660 if (!(pcmcia_dev_present(link))) {
Dominik Brodowski624dd662009-10-24 15:52:44 +02001661 dev_dbg(&link->dev, "ray_cs interrupt_ecf - device not present\n");
John Daiker141fa612009-03-10 06:59:54 -07001662 return -1;
1663 }
Dominik Brodowski624dd662009-10-24 15:52:44 +02001664 dev_dbg(&link->dev, "interrupt_ecf(local=%p, ccs = 0x%x\n", local, ccs);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001665
John Daiker141fa612009-03-10 06:59:54 -07001666 while (i &&
1667 (readb(local->amem + CIS_OFFSET + ECF_INTR_OFFSET) &
1668 ECF_INTR_SET))
1669 i--;
1670 if (i == 0) {
Dominik Brodowski624dd662009-10-24 15:52:44 +02001671 dev_dbg(&link->dev, "ray_cs interrupt_ecf card not ready for interrupt\n");
John Daiker141fa612009-03-10 06:59:54 -07001672 return -1;
1673 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001674 /* Fill the mailbox, then kick the card */
John Daiker141fa612009-03-10 06:59:54 -07001675 writeb(ccs, local->sram + SCB_BASE);
1676 writeb(ECF_INTR_SET, local->amem + CIS_OFFSET + ECF_INTR_OFFSET);
1677 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001678} /* interrupt_ecf */
John Daiker141fa612009-03-10 06:59:54 -07001679
Linus Torvalds1da177e2005-04-16 15:20:36 -07001680/*===========================================================================*/
1681/* Get next free transmit CCS */
1682/* Return - index of current tx ccs */
1683static int get_free_tx_ccs(ray_dev_t *local)
1684{
John Daiker141fa612009-03-10 06:59:54 -07001685 int i;
1686 struct ccs __iomem *pccs = ccs_base(local);
1687 struct pcmcia_device *link = local->finder;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001688
John Daiker141fa612009-03-10 06:59:54 -07001689 if (!(pcmcia_dev_present(link))) {
Dominik Brodowski624dd662009-10-24 15:52:44 +02001690 dev_dbg(&link->dev, "ray_cs get_free_tx_ccs - device not present\n");
John Daiker141fa612009-03-10 06:59:54 -07001691 return ECARDGONE;
1692 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001693
John Daiker141fa612009-03-10 06:59:54 -07001694 if (test_and_set_bit(0, &local->tx_ccs_lock)) {
Dominik Brodowski624dd662009-10-24 15:52:44 +02001695 dev_dbg(&link->dev, "ray_cs tx_ccs_lock busy\n");
John Daiker141fa612009-03-10 06:59:54 -07001696 return ECCSBUSY;
1697 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001698
John Daiker141fa612009-03-10 06:59:54 -07001699 for (i = 0; i < NUMBER_OF_TX_CCS; i++) {
1700 if (readb(&(pccs + i)->buffer_status) == CCS_BUFFER_FREE) {
1701 writeb(CCS_BUFFER_BUSY, &(pccs + i)->buffer_status);
1702 writeb(CCS_END_LIST, &(pccs + i)->link);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001703 local->tx_ccs_lock = 0;
John Daiker141fa612009-03-10 06:59:54 -07001704 return i;
1705 }
1706 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001707 local->tx_ccs_lock = 0;
Dominik Brodowski624dd662009-10-24 15:52:44 +02001708 dev_dbg(&link->dev, "ray_cs ERROR no free tx CCS for raylink card\n");
John Daiker141fa612009-03-10 06:59:54 -07001709 return ECCSFULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001710} /* get_free_tx_ccs */
John Daiker141fa612009-03-10 06:59:54 -07001711
Linus Torvalds1da177e2005-04-16 15:20:36 -07001712/*===========================================================================*/
1713/* Get next free CCS */
1714/* Return - index of current ccs */
1715static int get_free_ccs(ray_dev_t *local)
1716{
John Daiker141fa612009-03-10 06:59:54 -07001717 int i;
1718 struct ccs __iomem *pccs = ccs_base(local);
1719 struct pcmcia_device *link = local->finder;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001720
John Daiker141fa612009-03-10 06:59:54 -07001721 if (!(pcmcia_dev_present(link))) {
Dominik Brodowski624dd662009-10-24 15:52:44 +02001722 dev_dbg(&link->dev, "ray_cs get_free_ccs - device not present\n");
John Daiker141fa612009-03-10 06:59:54 -07001723 return ECARDGONE;
1724 }
1725 if (test_and_set_bit(0, &local->ccs_lock)) {
Dominik Brodowski624dd662009-10-24 15:52:44 +02001726 dev_dbg(&link->dev, "ray_cs ccs_lock busy\n");
John Daiker141fa612009-03-10 06:59:54 -07001727 return ECCSBUSY;
1728 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001729
John Daiker141fa612009-03-10 06:59:54 -07001730 for (i = NUMBER_OF_TX_CCS; i < NUMBER_OF_CCS; i++) {
1731 if (readb(&(pccs + i)->buffer_status) == CCS_BUFFER_FREE) {
1732 writeb(CCS_BUFFER_BUSY, &(pccs + i)->buffer_status);
1733 writeb(CCS_END_LIST, &(pccs + i)->link);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001734 local->ccs_lock = 0;
John Daiker141fa612009-03-10 06:59:54 -07001735 return i;
1736 }
1737 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001738 local->ccs_lock = 0;
Dominik Brodowski624dd662009-10-24 15:52:44 +02001739 dev_dbg(&link->dev, "ray_cs ERROR no free CCS for raylink card\n");
John Daiker141fa612009-03-10 06:59:54 -07001740 return ECCSFULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001741} /* get_free_ccs */
John Daiker141fa612009-03-10 06:59:54 -07001742
Linus Torvalds1da177e2005-04-16 15:20:36 -07001743/*===========================================================================*/
1744static void authenticate_timeout(u_long data)
1745{
John Daiker141fa612009-03-10 06:59:54 -07001746 ray_dev_t *local = (ray_dev_t *) data;
1747 del_timer(&local->timer);
1748 printk(KERN_INFO "ray_cs Authentication with access point failed"
1749 " - timeout\n");
1750 join_net((u_long) local);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001751}
John Daiker141fa612009-03-10 06:59:54 -07001752
Linus Torvalds1da177e2005-04-16 15:20:36 -07001753/*===========================================================================*/
1754static int asc_to_int(char a)
1755{
John Daiker141fa612009-03-10 06:59:54 -07001756 if (a < '0')
1757 return -1;
1758 if (a <= '9')
1759 return (a - '0');
1760 if (a < 'A')
1761 return -1;
1762 if (a <= 'F')
1763 return (10 + a - 'A');
1764 if (a < 'a')
1765 return -1;
1766 if (a <= 'f')
1767 return (10 + a - 'a');
1768 return -1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001769}
John Daiker141fa612009-03-10 06:59:54 -07001770
Linus Torvalds1da177e2005-04-16 15:20:36 -07001771/*===========================================================================*/
1772static int parse_addr(char *in_str, UCHAR *out)
1773{
John Daiker141fa612009-03-10 06:59:54 -07001774 int len;
1775 int i, j, k;
1776 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001777
John Daiker141fa612009-03-10 06:59:54 -07001778 if (in_str == NULL)
1779 return 0;
1780 if ((len = strlen(in_str)) < 2)
1781 return 0;
1782 memset(out, 0, ADDRLEN);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001783
John Daiker141fa612009-03-10 06:59:54 -07001784 status = 1;
1785 j = len - 1;
1786 if (j > 12)
1787 j = 12;
1788 i = 5;
1789
1790 while (j > 0) {
1791 if ((k = asc_to_int(in_str[j--])) != -1)
1792 out[i] = k;
1793 else
1794 return 0;
1795
1796 if (j == 0)
1797 break;
1798 if ((k = asc_to_int(in_str[j--])) != -1)
1799 out[i] += k << 4;
1800 else
1801 return 0;
1802 if (!i--)
1803 break;
1804 }
1805 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001806}
John Daiker141fa612009-03-10 06:59:54 -07001807
Linus Torvalds1da177e2005-04-16 15:20:36 -07001808/*===========================================================================*/
1809static struct net_device_stats *ray_get_stats(struct net_device *dev)
1810{
John Daiker141fa612009-03-10 06:59:54 -07001811 ray_dev_t *local = netdev_priv(dev);
1812 struct pcmcia_device *link = local->finder;
1813 struct status __iomem *p = local->sram + STATUS_BASE;
1814 if (!(pcmcia_dev_present(link))) {
Dominik Brodowski624dd662009-10-24 15:52:44 +02001815 dev_dbg(&link->dev, "ray_cs net_device_stats - device not present\n");
John Daiker141fa612009-03-10 06:59:54 -07001816 return &local->stats;
1817 }
1818 if (readb(&p->mrx_overflow_for_host)) {
1819 local->stats.rx_over_errors += swab16(readw(&p->mrx_overflow));
1820 writeb(0, &p->mrx_overflow);
1821 writeb(0, &p->mrx_overflow_for_host);
1822 }
1823 if (readb(&p->mrx_checksum_error_for_host)) {
1824 local->stats.rx_crc_errors +=
1825 swab16(readw(&p->mrx_checksum_error));
1826 writeb(0, &p->mrx_checksum_error);
1827 writeb(0, &p->mrx_checksum_error_for_host);
1828 }
1829 if (readb(&p->rx_hec_error_for_host)) {
1830 local->stats.rx_frame_errors += swab16(readw(&p->rx_hec_error));
1831 writeb(0, &p->rx_hec_error);
1832 writeb(0, &p->rx_hec_error_for_host);
1833 }
1834 return &local->stats;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001835}
John Daiker141fa612009-03-10 06:59:54 -07001836
Linus Torvalds1da177e2005-04-16 15:20:36 -07001837/*===========================================================================*/
John Daiker141fa612009-03-10 06:59:54 -07001838static void ray_update_parm(struct net_device *dev, UCHAR objid, UCHAR *value,
1839 int len)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001840{
John Daiker141fa612009-03-10 06:59:54 -07001841 ray_dev_t *local = netdev_priv(dev);
1842 struct pcmcia_device *link = local->finder;
1843 int ccsindex;
1844 int i;
1845 struct ccs __iomem *pccs;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001846
John Daiker141fa612009-03-10 06:59:54 -07001847 if (!(pcmcia_dev_present(link))) {
Dominik Brodowski624dd662009-10-24 15:52:44 +02001848 dev_dbg(&link->dev, "ray_update_parm - device not present\n");
John Daiker141fa612009-03-10 06:59:54 -07001849 return;
1850 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001851
John Daiker141fa612009-03-10 06:59:54 -07001852 if ((ccsindex = get_free_ccs(local)) < 0) {
Dominik Brodowski624dd662009-10-24 15:52:44 +02001853 dev_dbg(&link->dev, "ray_update_parm - No free ccs\n");
John Daiker141fa612009-03-10 06:59:54 -07001854 return;
1855 }
1856 pccs = ccs_base(local) + ccsindex;
1857 writeb(CCS_UPDATE_PARAMS, &pccs->cmd);
1858 writeb(objid, &pccs->var.update_param.object_id);
1859 writeb(1, &pccs->var.update_param.number_objects);
1860 writeb(0, &pccs->var.update_param.failure_cause);
1861 for (i = 0; i < len; i++) {
1862 writeb(value[i], local->sram + HOST_TO_ECF_BASE);
1863 }
1864 /* Interrupt the firmware to process the command */
1865 if (interrupt_ecf(local, ccsindex)) {
Dominik Brodowski624dd662009-10-24 15:52:44 +02001866 dev_dbg(&link->dev, "ray_cs associate failed - ECF not ready for intr\n");
John Daiker141fa612009-03-10 06:59:54 -07001867 writeb(CCS_BUFFER_FREE, &(pccs++)->buffer_status);
1868 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001869}
John Daiker141fa612009-03-10 06:59:54 -07001870
Linus Torvalds1da177e2005-04-16 15:20:36 -07001871/*===========================================================================*/
1872static void ray_update_multi_list(struct net_device *dev, int all)
1873{
John Daiker141fa612009-03-10 06:59:54 -07001874 int ccsindex;
1875 struct ccs __iomem *pccs;
John Daiker141fa612009-03-10 06:59:54 -07001876 ray_dev_t *local = netdev_priv(dev);
1877 struct pcmcia_device *link = local->finder;
1878 void __iomem *p = local->sram + HOST_TO_ECF_BASE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001879
John Daiker141fa612009-03-10 06:59:54 -07001880 if (!(pcmcia_dev_present(link))) {
Dominik Brodowski624dd662009-10-24 15:52:44 +02001881 dev_dbg(&link->dev, "ray_update_multi_list - device not present\n");
John Daiker141fa612009-03-10 06:59:54 -07001882 return;
1883 } else
Dominik Brodowski624dd662009-10-24 15:52:44 +02001884 dev_dbg(&link->dev, "ray_update_multi_list(%p)\n", dev);
John Daiker141fa612009-03-10 06:59:54 -07001885 if ((ccsindex = get_free_ccs(local)) < 0) {
Dominik Brodowski624dd662009-10-24 15:52:44 +02001886 dev_dbg(&link->dev, "ray_update_multi - No free ccs\n");
John Daiker141fa612009-03-10 06:59:54 -07001887 return;
1888 }
1889 pccs = ccs_base(local) + ccsindex;
1890 writeb(CCS_UPDATE_MULTICAST_LIST, &pccs->cmd);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001891
John Daiker141fa612009-03-10 06:59:54 -07001892 if (all) {
1893 writeb(0xff, &pccs->var);
1894 local->num_multi = 0xff;
1895 } else {
Jiri Pirko655ffee2010-02-27 07:35:45 +00001896 struct dev_mc_list *dmi;
1897 int i = 0;
1898
John Daiker141fa612009-03-10 06:59:54 -07001899 /* Copy the kernel's list of MC addresses to card */
Jiri Pirko655ffee2010-02-27 07:35:45 +00001900 netdev_for_each_mc_addr(dmi, dev) {
John Daiker141fa612009-03-10 06:59:54 -07001901 memcpy_toio(p, dmi->dmi_addr, ETH_ALEN);
Dominik Brodowski624dd662009-10-24 15:52:44 +02001902 dev_dbg(&link->dev,
John Daiker141fa612009-03-10 06:59:54 -07001903 "ray_update_multi add addr %02x%02x%02x%02x%02x%02x\n",
1904 dmi->dmi_addr[0], dmi->dmi_addr[1],
1905 dmi->dmi_addr[2], dmi->dmi_addr[3],
1906 dmi->dmi_addr[4], dmi->dmi_addr[5]);
1907 p += ETH_ALEN;
1908 i++;
1909 }
1910 if (i > 256 / ADDRLEN)
1911 i = 256 / ADDRLEN;
1912 writeb((UCHAR) i, &pccs->var);
Dominik Brodowski624dd662009-10-24 15:52:44 +02001913 dev_dbg(&link->dev, "ray_cs update_multi %d addresses in list\n", i);
John Daiker141fa612009-03-10 06:59:54 -07001914 /* Interrupt the firmware to process the command */
1915 local->num_multi = i;
1916 }
1917 if (interrupt_ecf(local, ccsindex)) {
Dominik Brodowski624dd662009-10-24 15:52:44 +02001918 dev_dbg(&link->dev,
John Daiker141fa612009-03-10 06:59:54 -07001919 "ray_cs update_multi failed - ECF not ready for intr\n");
1920 writeb(CCS_BUFFER_FREE, &(pccs++)->buffer_status);
1921 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001922} /* end ray_update_multi_list */
John Daiker141fa612009-03-10 06:59:54 -07001923
Linus Torvalds1da177e2005-04-16 15:20:36 -07001924/*===========================================================================*/
1925static void set_multicast_list(struct net_device *dev)
1926{
John Daiker141fa612009-03-10 06:59:54 -07001927 ray_dev_t *local = netdev_priv(dev);
1928 UCHAR promisc;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001929
Dominik Brodowski624dd662009-10-24 15:52:44 +02001930 pr_debug("ray_cs set_multicast_list(%p)\n", dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001931
John Daiker141fa612009-03-10 06:59:54 -07001932 if (dev->flags & IFF_PROMISC) {
1933 if (local->sparm.b5.a_promiscuous_mode == 0) {
Dominik Brodowski624dd662009-10-24 15:52:44 +02001934 pr_debug("ray_cs set_multicast_list promisc on\n");
John Daiker141fa612009-03-10 06:59:54 -07001935 local->sparm.b5.a_promiscuous_mode = 1;
1936 promisc = 1;
1937 ray_update_parm(dev, OBJID_promiscuous_mode,
1938 &promisc, sizeof(promisc));
1939 }
1940 } else {
1941 if (local->sparm.b5.a_promiscuous_mode == 1) {
Dominik Brodowski624dd662009-10-24 15:52:44 +02001942 pr_debug("ray_cs set_multicast_list promisc off\n");
John Daiker141fa612009-03-10 06:59:54 -07001943 local->sparm.b5.a_promiscuous_mode = 0;
1944 promisc = 0;
1945 ray_update_parm(dev, OBJID_promiscuous_mode,
1946 &promisc, sizeof(promisc));
1947 }
1948 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001949
John Daiker141fa612009-03-10 06:59:54 -07001950 if (dev->flags & IFF_ALLMULTI)
1951 ray_update_multi_list(dev, 1);
1952 else {
Jiri Pirko4cd24ea2010-02-08 04:30:35 +00001953 if (local->num_multi != netdev_mc_count(dev))
John Daiker141fa612009-03-10 06:59:54 -07001954 ray_update_multi_list(dev, 0);
1955 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001956} /* end set_multicast_list */
John Daiker141fa612009-03-10 06:59:54 -07001957
Linus Torvalds1da177e2005-04-16 15:20:36 -07001958/*=============================================================================
1959 * All routines below here are run at interrupt time.
1960=============================================================================*/
David Howells7d12e782006-10-05 14:55:46 +01001961static irqreturn_t ray_interrupt(int irq, void *dev_id)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001962{
John Daiker141fa612009-03-10 06:59:54 -07001963 struct net_device *dev = (struct net_device *)dev_id;
1964 struct pcmcia_device *link;
1965 ray_dev_t *local;
1966 struct ccs __iomem *pccs;
1967 struct rcs __iomem *prcs;
1968 UCHAR rcsindex;
1969 UCHAR tmp;
1970 UCHAR cmd;
1971 UCHAR status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001972
John Daiker141fa612009-03-10 06:59:54 -07001973 if (dev == NULL) /* Note that we want interrupts with dev->start == 0 */
1974 return IRQ_NONE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001975
Dominik Brodowski624dd662009-10-24 15:52:44 +02001976 pr_debug("ray_cs: interrupt for *dev=%p\n", dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001977
John Daiker141fa612009-03-10 06:59:54 -07001978 local = netdev_priv(dev);
1979 link = (struct pcmcia_device *)local->finder;
1980 if (!pcmcia_dev_present(link)) {
Dominik Brodowski624dd662009-10-24 15:52:44 +02001981 pr_debug(
1982 "ray_cs interrupt from device not present or suspended.\n");
John Daiker141fa612009-03-10 06:59:54 -07001983 return IRQ_NONE;
1984 }
1985 rcsindex = readb(&((struct scb __iomem *)(local->sram))->rcs_index);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001986
John Daiker141fa612009-03-10 06:59:54 -07001987 if (rcsindex >= (NUMBER_OF_CCS + NUMBER_OF_RCS)) {
Dominik Brodowski624dd662009-10-24 15:52:44 +02001988 dev_dbg(&link->dev, "ray_cs interrupt bad rcsindex = 0x%x\n", rcsindex);
John Daiker141fa612009-03-10 06:59:54 -07001989 clear_interrupt(local);
1990 return IRQ_HANDLED;
1991 }
1992 if (rcsindex < NUMBER_OF_CCS) { /* If it's a returned CCS */
1993 pccs = ccs_base(local) + rcsindex;
1994 cmd = readb(&pccs->cmd);
1995 status = readb(&pccs->buffer_status);
1996 switch (cmd) {
1997 case CCS_DOWNLOAD_STARTUP_PARAMS: /* Happens in firmware someday */
1998 del_timer(&local->timer);
1999 if (status == CCS_COMMAND_COMPLETE) {
Dominik Brodowski624dd662009-10-24 15:52:44 +02002000 dev_dbg(&link->dev,
John Daiker141fa612009-03-10 06:59:54 -07002001 "ray_cs interrupt download_startup_parameters OK\n");
2002 } else {
Dominik Brodowski624dd662009-10-24 15:52:44 +02002003 dev_dbg(&link->dev,
John Daiker141fa612009-03-10 06:59:54 -07002004 "ray_cs interrupt download_startup_parameters fail\n");
2005 }
2006 break;
2007 case CCS_UPDATE_PARAMS:
Dominik Brodowski624dd662009-10-24 15:52:44 +02002008 dev_dbg(&link->dev, "ray_cs interrupt update params done\n");
John Daiker141fa612009-03-10 06:59:54 -07002009 if (status != CCS_COMMAND_COMPLETE) {
2010 tmp =
2011 readb(&pccs->var.update_param.
2012 failure_cause);
Dominik Brodowski624dd662009-10-24 15:52:44 +02002013 dev_dbg(&link->dev,
John Daiker141fa612009-03-10 06:59:54 -07002014 "ray_cs interrupt update params failed - reason %d\n",
2015 tmp);
2016 }
2017 break;
2018 case CCS_REPORT_PARAMS:
Dominik Brodowski624dd662009-10-24 15:52:44 +02002019 dev_dbg(&link->dev, "ray_cs interrupt report params done\n");
John Daiker141fa612009-03-10 06:59:54 -07002020 break;
2021 case CCS_UPDATE_MULTICAST_LIST: /* Note that this CCS isn't returned */
Dominik Brodowski624dd662009-10-24 15:52:44 +02002022 dev_dbg(&link->dev,
John Daiker141fa612009-03-10 06:59:54 -07002023 "ray_cs interrupt CCS Update Multicast List done\n");
2024 break;
2025 case CCS_UPDATE_POWER_SAVINGS_MODE:
Dominik Brodowski624dd662009-10-24 15:52:44 +02002026 dev_dbg(&link->dev,
John Daiker141fa612009-03-10 06:59:54 -07002027 "ray_cs interrupt update power save mode done\n");
2028 break;
2029 case CCS_START_NETWORK:
2030 case CCS_JOIN_NETWORK:
2031 if (status == CCS_COMMAND_COMPLETE) {
2032 if (readb
2033 (&pccs->var.start_network.net_initiated) ==
2034 1) {
Dominik Brodowski624dd662009-10-24 15:52:44 +02002035 dev_dbg(&link->dev,
John Daiker141fa612009-03-10 06:59:54 -07002036 "ray_cs interrupt network \"%s\" started\n",
2037 local->sparm.b4.a_current_ess_id);
2038 } else {
Dominik Brodowski624dd662009-10-24 15:52:44 +02002039 dev_dbg(&link->dev,
John Daiker141fa612009-03-10 06:59:54 -07002040 "ray_cs interrupt network \"%s\" joined\n",
2041 local->sparm.b4.a_current_ess_id);
2042 }
2043 memcpy_fromio(&local->bss_id,
2044 pccs->var.start_network.bssid,
2045 ADDRLEN);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002046
John Daiker141fa612009-03-10 06:59:54 -07002047 if (local->fw_ver == 0x55)
2048 local->net_default_tx_rate = 3;
2049 else
2050 local->net_default_tx_rate =
2051 readb(&pccs->var.start_network.
2052 net_default_tx_rate);
2053 local->encryption =
2054 readb(&pccs->var.start_network.encryption);
2055 if (!sniffer && (local->net_type == INFRA)
2056 && !(local->sparm.b4.a_acting_as_ap_status)) {
2057 authenticate(local);
2058 }
2059 local->card_status = CARD_ACQ_COMPLETE;
2060 } else {
2061 local->card_status = CARD_ACQ_FAILED;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002062
John Daiker141fa612009-03-10 06:59:54 -07002063 del_timer(&local->timer);
2064 local->timer.expires = jiffies + HZ * 5;
2065 local->timer.data = (long)local;
2066 if (status == CCS_START_NETWORK) {
Dominik Brodowski624dd662009-10-24 15:52:44 +02002067 dev_dbg(&link->dev,
John Daiker141fa612009-03-10 06:59:54 -07002068 "ray_cs interrupt network \"%s\" start failed\n",
2069 local->sparm.b4.a_current_ess_id);
2070 local->timer.function = &start_net;
2071 } else {
Dominik Brodowski624dd662009-10-24 15:52:44 +02002072 dev_dbg(&link->dev,
John Daiker141fa612009-03-10 06:59:54 -07002073 "ray_cs interrupt network \"%s\" join failed\n",
2074 local->sparm.b4.a_current_ess_id);
2075 local->timer.function = &join_net;
2076 }
2077 add_timer(&local->timer);
2078 }
2079 break;
2080 case CCS_START_ASSOCIATION:
2081 if (status == CCS_COMMAND_COMPLETE) {
2082 local->card_status = CARD_ASSOC_COMPLETE;
Dominik Brodowski624dd662009-10-24 15:52:44 +02002083 dev_dbg(&link->dev, "ray_cs association successful\n");
John Daiker141fa612009-03-10 06:59:54 -07002084 } else {
Dominik Brodowski624dd662009-10-24 15:52:44 +02002085 dev_dbg(&link->dev, "ray_cs association failed,\n");
John Daiker141fa612009-03-10 06:59:54 -07002086 local->card_status = CARD_ASSOC_FAILED;
2087 join_net((u_long) local);
2088 }
2089 break;
2090 case CCS_TX_REQUEST:
2091 if (status == CCS_COMMAND_COMPLETE) {
Dominik Brodowski624dd662009-10-24 15:52:44 +02002092 dev_dbg(&link->dev,
John Daiker141fa612009-03-10 06:59:54 -07002093 "ray_cs interrupt tx request complete\n");
2094 } else {
Dominik Brodowski624dd662009-10-24 15:52:44 +02002095 dev_dbg(&link->dev,
John Daiker141fa612009-03-10 06:59:54 -07002096 "ray_cs interrupt tx request failed\n");
2097 }
2098 if (!sniffer)
2099 netif_start_queue(dev);
2100 netif_wake_queue(dev);
2101 break;
2102 case CCS_TEST_MEMORY:
Dominik Brodowski624dd662009-10-24 15:52:44 +02002103 dev_dbg(&link->dev, "ray_cs interrupt mem test done\n");
John Daiker141fa612009-03-10 06:59:54 -07002104 break;
2105 case CCS_SHUTDOWN:
Dominik Brodowski624dd662009-10-24 15:52:44 +02002106 dev_dbg(&link->dev,
John Daiker141fa612009-03-10 06:59:54 -07002107 "ray_cs interrupt Unexpected CCS returned - Shutdown\n");
2108 break;
2109 case CCS_DUMP_MEMORY:
Dominik Brodowski624dd662009-10-24 15:52:44 +02002110 dev_dbg(&link->dev, "ray_cs interrupt dump memory done\n");
John Daiker141fa612009-03-10 06:59:54 -07002111 break;
2112 case CCS_START_TIMER:
Dominik Brodowski624dd662009-10-24 15:52:44 +02002113 dev_dbg(&link->dev,
John Daiker141fa612009-03-10 06:59:54 -07002114 "ray_cs interrupt DING - raylink timer expired\n");
2115 break;
2116 default:
Dominik Brodowski624dd662009-10-24 15:52:44 +02002117 dev_dbg(&link->dev,
John Daiker141fa612009-03-10 06:59:54 -07002118 "ray_cs interrupt Unexpected CCS 0x%x returned 0x%x\n",
2119 rcsindex, cmd);
2120 }
2121 writeb(CCS_BUFFER_FREE, &pccs->buffer_status);
2122 } else { /* It's an RCS */
2123
2124 prcs = rcs_base(local) + rcsindex;
2125
2126 switch (readb(&prcs->interrupt_id)) {
2127 case PROCESS_RX_PACKET:
2128 ray_rx(dev, local, prcs);
2129 break;
2130 case REJOIN_NET_COMPLETE:
Dominik Brodowski624dd662009-10-24 15:52:44 +02002131 dev_dbg(&link->dev, "ray_cs interrupt rejoin net complete\n");
John Daiker141fa612009-03-10 06:59:54 -07002132 local->card_status = CARD_ACQ_COMPLETE;
2133 /* do we need to clear tx buffers CCS's? */
2134 if (local->sparm.b4.a_network_type == ADHOC) {
2135 if (!sniffer)
2136 netif_start_queue(dev);
2137 } else {
2138 memcpy_fromio(&local->bss_id,
2139 prcs->var.rejoin_net_complete.
2140 bssid, ADDRLEN);
Dominik Brodowski624dd662009-10-24 15:52:44 +02002141 dev_dbg(&link->dev,
John Daiker141fa612009-03-10 06:59:54 -07002142 "ray_cs new BSSID = %02x%02x%02x%02x%02x%02x\n",
2143 local->bss_id[0], local->bss_id[1],
2144 local->bss_id[2], local->bss_id[3],
2145 local->bss_id[4], local->bss_id[5]);
2146 if (!sniffer)
2147 authenticate(local);
2148 }
2149 break;
2150 case ROAMING_INITIATED:
Dominik Brodowski624dd662009-10-24 15:52:44 +02002151 dev_dbg(&link->dev, "ray_cs interrupt roaming initiated\n");
John Daiker141fa612009-03-10 06:59:54 -07002152 netif_stop_queue(dev);
2153 local->card_status = CARD_DOING_ACQ;
2154 break;
2155 case JAPAN_CALL_SIGN_RXD:
Dominik Brodowski624dd662009-10-24 15:52:44 +02002156 dev_dbg(&link->dev, "ray_cs interrupt japan call sign rx\n");
John Daiker141fa612009-03-10 06:59:54 -07002157 break;
2158 default:
Dominik Brodowski624dd662009-10-24 15:52:44 +02002159 dev_dbg(&link->dev,
John Daiker141fa612009-03-10 06:59:54 -07002160 "ray_cs Unexpected interrupt for RCS 0x%x cmd = 0x%x\n",
2161 rcsindex,
2162 (unsigned int)readb(&prcs->interrupt_id));
2163 break;
2164 }
2165 writeb(CCS_BUFFER_FREE, &prcs->buffer_status);
2166 }
2167 clear_interrupt(local);
2168 return IRQ_HANDLED;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002169} /* ray_interrupt */
John Daiker141fa612009-03-10 06:59:54 -07002170
Linus Torvalds1da177e2005-04-16 15:20:36 -07002171/*===========================================================================*/
John Daiker141fa612009-03-10 06:59:54 -07002172static void ray_rx(struct net_device *dev, ray_dev_t *local,
2173 struct rcs __iomem *prcs)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002174{
John Daiker141fa612009-03-10 06:59:54 -07002175 int rx_len;
2176 unsigned int pkt_addr;
2177 void __iomem *pmsg;
Dominik Brodowski624dd662009-10-24 15:52:44 +02002178 pr_debug("ray_rx process rx packet\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002179
John Daiker141fa612009-03-10 06:59:54 -07002180 /* Calculate address of packet within Rx buffer */
2181 pkt_addr = ((readb(&prcs->var.rx_packet.rx_data_ptr[0]) << 8)
2182 + readb(&prcs->var.rx_packet.rx_data_ptr[1])) & RX_BUFF_END;
2183 /* Length of first packet fragment */
2184 rx_len = (readb(&prcs->var.rx_packet.rx_data_length[0]) << 8)
2185 + readb(&prcs->var.rx_packet.rx_data_length[1]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002186
John Daiker141fa612009-03-10 06:59:54 -07002187 local->last_rsl = readb(&prcs->var.rx_packet.rx_sig_lev);
2188 pmsg = local->rmem + pkt_addr;
2189 switch (readb(pmsg)) {
2190 case DATA_TYPE:
Dominik Brodowski624dd662009-10-24 15:52:44 +02002191 pr_debug("ray_rx data type\n");
John Daiker141fa612009-03-10 06:59:54 -07002192 rx_data(dev, prcs, pkt_addr, rx_len);
2193 break;
2194 case AUTHENTIC_TYPE:
Dominik Brodowski624dd662009-10-24 15:52:44 +02002195 pr_debug("ray_rx authentic type\n");
John Daiker141fa612009-03-10 06:59:54 -07002196 if (sniffer)
2197 rx_data(dev, prcs, pkt_addr, rx_len);
2198 else
2199 rx_authenticate(local, prcs, pkt_addr, rx_len);
2200 break;
2201 case DEAUTHENTIC_TYPE:
Dominik Brodowski624dd662009-10-24 15:52:44 +02002202 pr_debug("ray_rx deauth type\n");
John Daiker141fa612009-03-10 06:59:54 -07002203 if (sniffer)
2204 rx_data(dev, prcs, pkt_addr, rx_len);
2205 else
2206 rx_deauthenticate(local, prcs, pkt_addr, rx_len);
2207 break;
2208 case NULL_MSG_TYPE:
Dominik Brodowski624dd662009-10-24 15:52:44 +02002209 pr_debug("ray_cs rx NULL msg\n");
John Daiker141fa612009-03-10 06:59:54 -07002210 break;
2211 case BEACON_TYPE:
Dominik Brodowski624dd662009-10-24 15:52:44 +02002212 pr_debug("ray_rx beacon type\n");
John Daiker141fa612009-03-10 06:59:54 -07002213 if (sniffer)
2214 rx_data(dev, prcs, pkt_addr, rx_len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002215
John Daiker141fa612009-03-10 06:59:54 -07002216 copy_from_rx_buff(local, (UCHAR *) &local->last_bcn, pkt_addr,
2217 rx_len < sizeof(struct beacon_rx) ?
2218 rx_len : sizeof(struct beacon_rx));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002219
John Daiker141fa612009-03-10 06:59:54 -07002220 local->beacon_rxed = 1;
2221 /* Get the statistics so the card counters never overflow */
2222 ray_get_stats(dev);
2223 break;
2224 default:
Dominik Brodowski624dd662009-10-24 15:52:44 +02002225 pr_debug("ray_cs unknown pkt type %2x\n",
John Daiker141fa612009-03-10 06:59:54 -07002226 (unsigned int)readb(pmsg));
2227 break;
2228 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002229
2230} /* end ray_rx */
John Daiker141fa612009-03-10 06:59:54 -07002231
Linus Torvalds1da177e2005-04-16 15:20:36 -07002232/*===========================================================================*/
John Daiker141fa612009-03-10 06:59:54 -07002233static void rx_data(struct net_device *dev, struct rcs __iomem *prcs,
2234 unsigned int pkt_addr, int rx_len)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002235{
John Daiker141fa612009-03-10 06:59:54 -07002236 struct sk_buff *skb = NULL;
2237 struct rcs __iomem *prcslink = prcs;
2238 ray_dev_t *local = netdev_priv(dev);
2239 UCHAR *rx_ptr;
2240 int total_len;
2241 int tmp;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002242#ifdef WIRELESS_SPY
John Daiker141fa612009-03-10 06:59:54 -07002243 int siglev = local->last_rsl;
2244 u_char linksrcaddr[ETH_ALEN]; /* Other end of the wireless link */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002245#endif
2246
John Daiker141fa612009-03-10 06:59:54 -07002247 if (!sniffer) {
2248 if (translate) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002249/* TBD length needs fixing for translated header */
John Daiker141fa612009-03-10 06:59:54 -07002250 if (rx_len < (ETH_HLEN + RX_MAC_HEADER_LENGTH) ||
2251 rx_len >
2252 (dev->mtu + RX_MAC_HEADER_LENGTH + ETH_HLEN +
2253 FCS_LEN)) {
Dominik Brodowski624dd662009-10-24 15:52:44 +02002254 pr_debug(
John Daiker141fa612009-03-10 06:59:54 -07002255 "ray_cs invalid packet length %d received \n",
2256 rx_len);
2257 return;
2258 }
2259 } else { /* encapsulated ethernet */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002260
John Daiker141fa612009-03-10 06:59:54 -07002261 if (rx_len < (ETH_HLEN + RX_MAC_HEADER_LENGTH) ||
2262 rx_len >
2263 (dev->mtu + RX_MAC_HEADER_LENGTH + ETH_HLEN +
2264 FCS_LEN)) {
Dominik Brodowski624dd662009-10-24 15:52:44 +02002265 pr_debug(
John Daiker141fa612009-03-10 06:59:54 -07002266 "ray_cs invalid packet length %d received \n",
2267 rx_len);
2268 return;
2269 }
2270 }
2271 }
Dominik Brodowski624dd662009-10-24 15:52:44 +02002272 pr_debug("ray_cs rx_data packet\n");
John Daiker141fa612009-03-10 06:59:54 -07002273 /* If fragmented packet, verify sizes of fragments add up */
2274 if (readb(&prcs->var.rx_packet.next_frag_rcs_index) != 0xFF) {
Dominik Brodowski624dd662009-10-24 15:52:44 +02002275 pr_debug("ray_cs rx'ed fragment\n");
John Daiker141fa612009-03-10 06:59:54 -07002276 tmp = (readb(&prcs->var.rx_packet.totalpacketlength[0]) << 8)
2277 + readb(&prcs->var.rx_packet.totalpacketlength[1]);
2278 total_len = tmp;
2279 prcslink = prcs;
2280 do {
2281 tmp -=
2282 (readb(&prcslink->var.rx_packet.rx_data_length[0])
2283 << 8)
2284 + readb(&prcslink->var.rx_packet.rx_data_length[1]);
2285 if (readb(&prcslink->var.rx_packet.next_frag_rcs_index)
2286 == 0xFF || tmp < 0)
2287 break;
2288 prcslink = rcs_base(local)
2289 + readb(&prcslink->link_field);
2290 } while (1);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002291
John Daiker141fa612009-03-10 06:59:54 -07002292 if (tmp < 0) {
Dominik Brodowski624dd662009-10-24 15:52:44 +02002293 pr_debug(
John Daiker141fa612009-03-10 06:59:54 -07002294 "ray_cs rx_data fragment lengths don't add up\n");
2295 local->stats.rx_dropped++;
2296 release_frag_chain(local, prcs);
2297 return;
2298 }
2299 } else { /* Single unfragmented packet */
2300 total_len = rx_len;
2301 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002302
John Daiker141fa612009-03-10 06:59:54 -07002303 skb = dev_alloc_skb(total_len + 5);
2304 if (skb == NULL) {
Dominik Brodowski624dd662009-10-24 15:52:44 +02002305 pr_debug("ray_cs rx_data could not allocate skb\n");
John Daiker141fa612009-03-10 06:59:54 -07002306 local->stats.rx_dropped++;
2307 if (readb(&prcs->var.rx_packet.next_frag_rcs_index) != 0xFF)
2308 release_frag_chain(local, prcs);
2309 return;
2310 }
2311 skb_reserve(skb, 2); /* Align IP on 16 byte (TBD check this) */
2312
Dominik Brodowski624dd662009-10-24 15:52:44 +02002313 pr_debug("ray_cs rx_data total_len = %x, rx_len = %x\n", total_len,
John Daiker141fa612009-03-10 06:59:54 -07002314 rx_len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002315
2316/************************/
John Daiker141fa612009-03-10 06:59:54 -07002317 /* Reserve enough room for the whole damn packet. */
2318 rx_ptr = skb_put(skb, total_len);
2319 /* Copy the whole packet to sk_buff */
2320 rx_ptr +=
2321 copy_from_rx_buff(local, rx_ptr, pkt_addr & RX_BUFF_END, rx_len);
2322 /* Get source address */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002323#ifdef WIRELESS_SPY
John Daiker141fa612009-03-10 06:59:54 -07002324 skb_copy_from_linear_data_offset(skb,
2325 offsetof(struct mac_header, addr_2),
2326 linksrcaddr, ETH_ALEN);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002327#endif
John Daiker141fa612009-03-10 06:59:54 -07002328 /* Now, deal with encapsulation/translation/sniffer */
2329 if (!sniffer) {
2330 if (!translate) {
2331 /* Encapsulated ethernet, so just lop off 802.11 MAC header */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002332/* TBD reserve skb_reserve( skb, RX_MAC_HEADER_LENGTH); */
John Daiker141fa612009-03-10 06:59:54 -07002333 skb_pull(skb, RX_MAC_HEADER_LENGTH);
2334 } else {
2335 /* Do translation */
2336 untranslate(local, skb, total_len);
2337 }
2338 } else { /* sniffer mode, so just pass whole packet */
2339 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002340
2341/************************/
John Daiker141fa612009-03-10 06:59:54 -07002342 /* Now pick up the rest of the fragments if any */
2343 tmp = 17;
2344 if (readb(&prcs->var.rx_packet.next_frag_rcs_index) != 0xFF) {
2345 prcslink = prcs;
Dominik Brodowski624dd662009-10-24 15:52:44 +02002346 pr_debug("ray_cs rx_data in fragment loop\n");
John Daiker141fa612009-03-10 06:59:54 -07002347 do {
2348 prcslink = rcs_base(local)
2349 +
2350 readb(&prcslink->var.rx_packet.next_frag_rcs_index);
2351 rx_len =
2352 ((readb(&prcslink->var.rx_packet.rx_data_length[0])
2353 << 8)
2354 +
2355 readb(&prcslink->var.rx_packet.rx_data_length[1]))
2356 & RX_BUFF_END;
2357 pkt_addr =
2358 ((readb(&prcslink->var.rx_packet.rx_data_ptr[0]) <<
2359 8)
2360 + readb(&prcslink->var.rx_packet.rx_data_ptr[1]))
2361 & RX_BUFF_END;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002362
John Daiker141fa612009-03-10 06:59:54 -07002363 rx_ptr +=
2364 copy_from_rx_buff(local, rx_ptr, pkt_addr, rx_len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002365
John Daiker141fa612009-03-10 06:59:54 -07002366 } while (tmp-- &&
2367 readb(&prcslink->var.rx_packet.next_frag_rcs_index) !=
2368 0xFF);
2369 release_frag_chain(local, prcs);
2370 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002371
John Daiker141fa612009-03-10 06:59:54 -07002372 skb->protocol = eth_type_trans(skb, dev);
2373 netif_rx(skb);
2374 local->stats.rx_packets++;
2375 local->stats.rx_bytes += total_len;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002376
John Daiker141fa612009-03-10 06:59:54 -07002377 /* Gather signal strength per address */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002378#ifdef WIRELESS_SPY
John Daiker141fa612009-03-10 06:59:54 -07002379 /* For the Access Point or the node having started the ad-hoc net
2380 * note : ad-hoc work only in some specific configurations, but we
2381 * kludge in ray_get_wireless_stats... */
2382 if (!memcmp(linksrcaddr, local->bss_id, ETH_ALEN)) {
2383 /* Update statistics */
2384 /*local->wstats.qual.qual = none ? */
2385 local->wstats.qual.level = siglev;
2386 /*local->wstats.qual.noise = none ? */
2387 local->wstats.qual.updated = 0x2;
2388 }
2389 /* Now, update the spy stuff */
2390 {
2391 struct iw_quality wstats;
2392 wstats.level = siglev;
2393 /* wstats.noise = none ? */
2394 /* wstats.qual = none ? */
2395 wstats.updated = 0x2;
2396 /* Update spy records */
2397 wireless_spy_update(dev, linksrcaddr, &wstats);
2398 }
2399#endif /* WIRELESS_SPY */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002400} /* end rx_data */
John Daiker141fa612009-03-10 06:59:54 -07002401
Linus Torvalds1da177e2005-04-16 15:20:36 -07002402/*===========================================================================*/
2403static void untranslate(ray_dev_t *local, struct sk_buff *skb, int len)
2404{
John Daiker141fa612009-03-10 06:59:54 -07002405 snaphdr_t *psnap = (snaphdr_t *) (skb->data + RX_MAC_HEADER_LENGTH);
2406 struct ieee80211_hdr *pmac = (struct ieee80211_hdr *)skb->data;
2407 __be16 type = *(__be16 *) psnap->ethertype;
2408 int delta;
2409 struct ethhdr *peth;
2410 UCHAR srcaddr[ADDRLEN];
2411 UCHAR destaddr[ADDRLEN];
2412 static UCHAR org_bridge[3] = { 0, 0, 0xf8 };
2413 static UCHAR org_1042[3] = { 0, 0, 0 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002414
John Daiker141fa612009-03-10 06:59:54 -07002415 memcpy(destaddr, ieee80211_get_DA(pmac), ADDRLEN);
2416 memcpy(srcaddr, ieee80211_get_SA(pmac), ADDRLEN);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002417
Dominik Brodowski624dd662009-10-24 15:52:44 +02002418#if 0
2419 if {
Joe Perchesad361c92009-07-06 13:05:40 -07002420 print_hex_dump(KERN_DEBUG, "skb->data before untranslate: ",
2421 DUMP_PREFIX_NONE, 16, 1,
2422 skb->data, 64, true);
2423 printk(KERN_DEBUG
John Daiker141fa612009-03-10 06:59:54 -07002424 "type = %08x, xsap = %02x%02x%02x, org = %02x02x02x\n",
2425 ntohs(type), psnap->dsap, psnap->ssap, psnap->ctrl,
2426 psnap->org[0], psnap->org[1], psnap->org[2]);
2427 printk(KERN_DEBUG "untranslate skb->data = %p\n", skb->data);
2428 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002429#endif
2430
John Daiker141fa612009-03-10 06:59:54 -07002431 if (psnap->dsap != 0xaa || psnap->ssap != 0xaa || psnap->ctrl != 3) {
2432 /* not a snap type so leave it alone */
Dominik Brodowski624dd662009-10-24 15:52:44 +02002433 pr_debug("ray_cs untranslate NOT SNAP %02x %02x %02x\n",
John Daiker141fa612009-03-10 06:59:54 -07002434 psnap->dsap, psnap->ssap, psnap->ctrl);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002435
John Daiker141fa612009-03-10 06:59:54 -07002436 delta = RX_MAC_HEADER_LENGTH - ETH_HLEN;
2437 peth = (struct ethhdr *)(skb->data + delta);
2438 peth->h_proto = htons(len - RX_MAC_HEADER_LENGTH);
2439 } else { /* Its a SNAP */
2440 if (memcmp(psnap->org, org_bridge, 3) == 0) {
2441 /* EtherII and nuke the LLC */
Dominik Brodowski624dd662009-10-24 15:52:44 +02002442 pr_debug("ray_cs untranslate Bridge encap\n");
John Daiker141fa612009-03-10 06:59:54 -07002443 delta = RX_MAC_HEADER_LENGTH
2444 + sizeof(struct snaphdr_t) - ETH_HLEN;
2445 peth = (struct ethhdr *)(skb->data + delta);
2446 peth->h_proto = type;
2447 } else if (memcmp(psnap->org, org_1042, 3) == 0) {
2448 switch (ntohs(type)) {
2449 case ETH_P_IPX:
2450 case ETH_P_AARP:
Dominik Brodowski624dd662009-10-24 15:52:44 +02002451 pr_debug("ray_cs untranslate RFC IPX/AARP\n");
John Daiker141fa612009-03-10 06:59:54 -07002452 delta = RX_MAC_HEADER_LENGTH - ETH_HLEN;
2453 peth = (struct ethhdr *)(skb->data + delta);
2454 peth->h_proto =
2455 htons(len - RX_MAC_HEADER_LENGTH);
2456 break;
2457 default:
Dominik Brodowski624dd662009-10-24 15:52:44 +02002458 pr_debug("ray_cs untranslate RFC default\n");
John Daiker141fa612009-03-10 06:59:54 -07002459 delta = RX_MAC_HEADER_LENGTH +
2460 sizeof(struct snaphdr_t) - ETH_HLEN;
2461 peth = (struct ethhdr *)(skb->data + delta);
2462 peth->h_proto = type;
2463 break;
2464 }
2465 } else {
2466 printk("ray_cs untranslate very confused by packet\n");
2467 delta = RX_MAC_HEADER_LENGTH - ETH_HLEN;
2468 peth = (struct ethhdr *)(skb->data + delta);
2469 peth->h_proto = type;
2470 }
Al Viro7698d692007-12-29 04:55:50 -05002471 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002472/* TBD reserve skb_reserve(skb, delta); */
John Daiker141fa612009-03-10 06:59:54 -07002473 skb_pull(skb, delta);
Dominik Brodowski624dd662009-10-24 15:52:44 +02002474 pr_debug("untranslate after skb_pull(%d), skb->data = %p\n", delta,
John Daiker141fa612009-03-10 06:59:54 -07002475 skb->data);
2476 memcpy(peth->h_dest, destaddr, ADDRLEN);
2477 memcpy(peth->h_source, srcaddr, ADDRLEN);
Dominik Brodowski624dd662009-10-24 15:52:44 +02002478#if 0
2479 {
John Daiker141fa612009-03-10 06:59:54 -07002480 int i;
2481 printk(KERN_DEBUG "skb->data after untranslate:");
2482 for (i = 0; i < 64; i++)
2483 printk("%02x ", skb->data[i]);
2484 printk("\n");
2485 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002486#endif
2487} /* end untranslate */
John Daiker141fa612009-03-10 06:59:54 -07002488
Linus Torvalds1da177e2005-04-16 15:20:36 -07002489/*===========================================================================*/
2490/* Copy data from circular receive buffer to PC memory.
2491 * dest = destination address in PC memory
2492 * pkt_addr = source address in receive buffer
2493 * len = length of packet to copy
2494 */
John Daiker141fa612009-03-10 06:59:54 -07002495static int copy_from_rx_buff(ray_dev_t *local, UCHAR *dest, int pkt_addr,
2496 int length)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002497{
John Daiker141fa612009-03-10 06:59:54 -07002498 int wrap_bytes = (pkt_addr + length) - (RX_BUFF_END + 1);
2499 if (wrap_bytes <= 0) {
2500 memcpy_fromio(dest, local->rmem + pkt_addr, length);
2501 } else { /* Packet wrapped in circular buffer */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002502
John Daiker141fa612009-03-10 06:59:54 -07002503 memcpy_fromio(dest, local->rmem + pkt_addr,
2504 length - wrap_bytes);
2505 memcpy_fromio(dest + length - wrap_bytes, local->rmem,
2506 wrap_bytes);
2507 }
2508 return length;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002509}
John Daiker141fa612009-03-10 06:59:54 -07002510
2511/*===========================================================================*/
2512static void release_frag_chain(ray_dev_t *local, struct rcs __iomem *prcs)
2513{
2514 struct rcs __iomem *prcslink = prcs;
2515 int tmp = 17;
2516 unsigned rcsindex = readb(&prcs->var.rx_packet.next_frag_rcs_index);
2517
2518 while (tmp--) {
2519 writeb(CCS_BUFFER_FREE, &prcslink->buffer_status);
2520 if (rcsindex >= (NUMBER_OF_CCS + NUMBER_OF_RCS)) {
Dominik Brodowski624dd662009-10-24 15:52:44 +02002521 pr_debug("ray_cs interrupt bad rcsindex = 0x%x\n",
John Daiker141fa612009-03-10 06:59:54 -07002522 rcsindex);
2523 break;
2524 }
2525 prcslink = rcs_base(local) + rcsindex;
2526 rcsindex = readb(&prcslink->var.rx_packet.next_frag_rcs_index);
2527 }
2528 writeb(CCS_BUFFER_FREE, &prcslink->buffer_status);
2529}
2530
Linus Torvalds1da177e2005-04-16 15:20:36 -07002531/*===========================================================================*/
2532static void authenticate(ray_dev_t *local)
2533{
John Daiker141fa612009-03-10 06:59:54 -07002534 struct pcmcia_device *link = local->finder;
Dominik Brodowski624dd662009-10-24 15:52:44 +02002535 dev_dbg(&link->dev, "ray_cs Starting authentication.\n");
John Daiker141fa612009-03-10 06:59:54 -07002536 if (!(pcmcia_dev_present(link))) {
Dominik Brodowski624dd662009-10-24 15:52:44 +02002537 dev_dbg(&link->dev, "ray_cs authenticate - device not present\n");
John Daiker141fa612009-03-10 06:59:54 -07002538 return;
2539 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002540
John Daiker141fa612009-03-10 06:59:54 -07002541 del_timer(&local->timer);
2542 if (build_auth_frame(local, local->bss_id, OPEN_AUTH_REQUEST)) {
2543 local->timer.function = &join_net;
2544 } else {
2545 local->timer.function = &authenticate_timeout;
2546 }
2547 local->timer.expires = jiffies + HZ * 2;
2548 local->timer.data = (long)local;
2549 add_timer(&local->timer);
2550 local->authentication_state = AWAITING_RESPONSE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002551} /* end authenticate */
John Daiker141fa612009-03-10 06:59:54 -07002552
Linus Torvalds1da177e2005-04-16 15:20:36 -07002553/*===========================================================================*/
2554static void rx_authenticate(ray_dev_t *local, struct rcs __iomem *prcs,
John Daiker141fa612009-03-10 06:59:54 -07002555 unsigned int pkt_addr, int rx_len)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002556{
John Daiker141fa612009-03-10 06:59:54 -07002557 UCHAR buff[256];
2558 struct rx_msg *msg = (struct rx_msg *)buff;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002559
John Daiker141fa612009-03-10 06:59:54 -07002560 del_timer(&local->timer);
2561
2562 copy_from_rx_buff(local, buff, pkt_addr, rx_len & 0xff);
2563 /* if we are trying to get authenticated */
2564 if (local->sparm.b4.a_network_type == ADHOC) {
Dominik Brodowski624dd662009-10-24 15:52:44 +02002565 pr_debug("ray_cs rx_auth var= %02x %02x %02x %02x %02x %02x\n",
John Daiker141fa612009-03-10 06:59:54 -07002566 msg->var[0], msg->var[1], msg->var[2], msg->var[3],
2567 msg->var[4], msg->var[5]);
2568 if (msg->var[2] == 1) {
Dominik Brodowski624dd662009-10-24 15:52:44 +02002569 pr_debug("ray_cs Sending authentication response.\n");
John Daiker141fa612009-03-10 06:59:54 -07002570 if (!build_auth_frame
2571 (local, msg->mac.addr_2, OPEN_AUTH_RESPONSE)) {
2572 local->authentication_state = NEED_TO_AUTH;
2573 memcpy(local->auth_id, msg->mac.addr_2,
2574 ADDRLEN);
2575 }
2576 }
2577 } else { /* Infrastructure network */
2578
2579 if (local->authentication_state == AWAITING_RESPONSE) {
2580 /* Verify authentication sequence #2 and success */
2581 if (msg->var[2] == 2) {
2582 if ((msg->var[3] | msg->var[4]) == 0) {
Dominik Brodowski624dd662009-10-24 15:52:44 +02002583 pr_debug("Authentication successful\n");
John Daiker141fa612009-03-10 06:59:54 -07002584 local->card_status = CARD_AUTH_COMPLETE;
2585 associate(local);
2586 local->authentication_state =
2587 AUTHENTICATED;
2588 } else {
Dominik Brodowski624dd662009-10-24 15:52:44 +02002589 pr_debug("Authentication refused\n");
John Daiker141fa612009-03-10 06:59:54 -07002590 local->card_status = CARD_AUTH_REFUSED;
2591 join_net((u_long) local);
2592 local->authentication_state =
2593 UNAUTHENTICATED;
2594 }
2595 }
2596 }
2597 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002598
2599} /* end rx_authenticate */
John Daiker141fa612009-03-10 06:59:54 -07002600
Linus Torvalds1da177e2005-04-16 15:20:36 -07002601/*===========================================================================*/
2602static void associate(ray_dev_t *local)
2603{
John Daiker141fa612009-03-10 06:59:54 -07002604 struct ccs __iomem *pccs;
2605 struct pcmcia_device *link = local->finder;
2606 struct net_device *dev = link->priv;
2607 int ccsindex;
2608 if (!(pcmcia_dev_present(link))) {
Dominik Brodowski624dd662009-10-24 15:52:44 +02002609 dev_dbg(&link->dev, "ray_cs associate - device not present\n");
John Daiker141fa612009-03-10 06:59:54 -07002610 return;
2611 }
2612 /* If no tx buffers available, return */
2613 if ((ccsindex = get_free_ccs(local)) < 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002614/* TBD should never be here but... what if we are? */
Dominik Brodowski624dd662009-10-24 15:52:44 +02002615 dev_dbg(&link->dev, "ray_cs associate - No free ccs\n");
John Daiker141fa612009-03-10 06:59:54 -07002616 return;
2617 }
Dominik Brodowski624dd662009-10-24 15:52:44 +02002618 dev_dbg(&link->dev, "ray_cs Starting association with access point\n");
John Daiker141fa612009-03-10 06:59:54 -07002619 pccs = ccs_base(local) + ccsindex;
2620 /* fill in the CCS */
2621 writeb(CCS_START_ASSOCIATION, &pccs->cmd);
2622 /* Interrupt the firmware to process the command */
2623 if (interrupt_ecf(local, ccsindex)) {
Dominik Brodowski624dd662009-10-24 15:52:44 +02002624 dev_dbg(&link->dev, "ray_cs associate failed - ECF not ready for intr\n");
John Daiker141fa612009-03-10 06:59:54 -07002625 writeb(CCS_BUFFER_FREE, &(pccs++)->buffer_status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002626
John Daiker141fa612009-03-10 06:59:54 -07002627 del_timer(&local->timer);
2628 local->timer.expires = jiffies + HZ * 2;
2629 local->timer.data = (long)local;
2630 local->timer.function = &join_net;
2631 add_timer(&local->timer);
2632 local->card_status = CARD_ASSOC_FAILED;
2633 return;
2634 }
2635 if (!sniffer)
2636 netif_start_queue(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002637
2638} /* end associate */
John Daiker141fa612009-03-10 06:59:54 -07002639
Linus Torvalds1da177e2005-04-16 15:20:36 -07002640/*===========================================================================*/
John Daiker141fa612009-03-10 06:59:54 -07002641static void rx_deauthenticate(ray_dev_t *local, struct rcs __iomem *prcs,
2642 unsigned int pkt_addr, int rx_len)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002643{
2644/* UCHAR buff[256];
2645 struct rx_msg *msg = (struct rx_msg *)buff;
2646*/
Dominik Brodowski624dd662009-10-24 15:52:44 +02002647 pr_debug("Deauthentication frame received\n");
John Daiker141fa612009-03-10 06:59:54 -07002648 local->authentication_state = UNAUTHENTICATED;
2649 /* Need to reauthenticate or rejoin depending on reason code */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002650/* copy_from_rx_buff(local, buff, pkt_addr, rx_len & 0xff);
2651 */
2652}
John Daiker141fa612009-03-10 06:59:54 -07002653
Linus Torvalds1da177e2005-04-16 15:20:36 -07002654/*===========================================================================*/
2655static void clear_interrupt(ray_dev_t *local)
2656{
John Daiker141fa612009-03-10 06:59:54 -07002657 writeb(0, local->amem + CIS_OFFSET + HCS_INTR_OFFSET);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002658}
John Daiker141fa612009-03-10 06:59:54 -07002659
Linus Torvalds1da177e2005-04-16 15:20:36 -07002660/*===========================================================================*/
2661#ifdef CONFIG_PROC_FS
2662#define MAXDATA (PAGE_SIZE - 80)
2663
2664static char *card_status[] = {
John Daiker141fa612009-03-10 06:59:54 -07002665 "Card inserted - uninitialized", /* 0 */
2666 "Card not downloaded", /* 1 */
2667 "Waiting for download parameters", /* 2 */
2668 "Card doing acquisition", /* 3 */
2669 "Acquisition complete", /* 4 */
2670 "Authentication complete", /* 5 */
2671 "Association complete", /* 6 */
2672 "???", "???", "???", "???", /* 7 8 9 10 undefined */
2673 "Card init error", /* 11 */
2674 "Download parameters error", /* 12 */
2675 "???", /* 13 */
2676 "Acquisition failed", /* 14 */
2677 "Authentication refused", /* 15 */
2678 "Association failed" /* 16 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002679};
2680
John Daiker141fa612009-03-10 06:59:54 -07002681static char *nettype[] = { "Adhoc", "Infra " };
2682static char *framing[] = { "Encapsulation", "Translation" }
2683
Linus Torvalds1da177e2005-04-16 15:20:36 -07002684;
2685/*===========================================================================*/
Alexey Dobriyan6b914c52008-04-10 14:34:35 -07002686static int ray_cs_proc_show(struct seq_file *m, void *v)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002687{
2688/* Print current values which are not available via other means
John Daiker141fa612009-03-10 06:59:54 -07002689 * eg ifconfig
Linus Torvalds1da177e2005-04-16 15:20:36 -07002690 */
John Daiker141fa612009-03-10 06:59:54 -07002691 int i;
2692 struct pcmcia_device *link;
2693 struct net_device *dev;
2694 ray_dev_t *local;
2695 UCHAR *p;
2696 struct freq_hop_element *pfh;
2697 UCHAR c[33];
Linus Torvalds1da177e2005-04-16 15:20:36 -07002698
John Daiker141fa612009-03-10 06:59:54 -07002699 link = this_device;
2700 if (!link)
2701 return 0;
2702 dev = (struct net_device *)link->priv;
2703 if (!dev)
2704 return 0;
2705 local = netdev_priv(dev);
2706 if (!local)
2707 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002708
John Daiker141fa612009-03-10 06:59:54 -07002709 seq_puts(m, "Raylink Wireless LAN driver status\n");
2710 seq_printf(m, "%s\n", rcsid);
2711 /* build 4 does not report version, and field is 0x55 after memtest */
2712 seq_puts(m, "Firmware version = ");
2713 if (local->fw_ver == 0x55)
2714 seq_puts(m, "4 - Use dump_cis for more details\n");
2715 else
2716 seq_printf(m, "%2d.%02d.%02d\n",
2717 local->fw_ver, local->fw_bld, local->fw_var);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002718
John Daiker141fa612009-03-10 06:59:54 -07002719 for (i = 0; i < 32; i++)
2720 c[i] = local->sparm.b5.a_current_ess_id[i];
2721 c[32] = 0;
2722 seq_printf(m, "%s network ESSID = \"%s\"\n",
2723 nettype[local->sparm.b5.a_network_type], c);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002724
John Daiker141fa612009-03-10 06:59:54 -07002725 p = local->bss_id;
2726 seq_printf(m, "BSSID = %pM\n", p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002727
John Daiker141fa612009-03-10 06:59:54 -07002728 seq_printf(m, "Country code = %d\n",
2729 local->sparm.b5.a_curr_country_code);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002730
John Daiker141fa612009-03-10 06:59:54 -07002731 i = local->card_status;
2732 if (i < 0)
2733 i = 10;
2734 if (i > 16)
2735 i = 10;
2736 seq_printf(m, "Card status = %s\n", card_status[i]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002737
John Daiker141fa612009-03-10 06:59:54 -07002738 seq_printf(m, "Framing mode = %s\n", framing[translate]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002739
John Daiker141fa612009-03-10 06:59:54 -07002740 seq_printf(m, "Last pkt signal lvl = %d\n", local->last_rsl);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002741
John Daiker141fa612009-03-10 06:59:54 -07002742 if (local->beacon_rxed) {
2743 /* Pull some fields out of last beacon received */
2744 seq_printf(m, "Beacon Interval = %d Kus\n",
2745 local->last_bcn.beacon_intvl[0]
2746 + 256 * local->last_bcn.beacon_intvl[1]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002747
John Daiker141fa612009-03-10 06:59:54 -07002748 p = local->last_bcn.elements;
2749 if (p[0] == C_ESSID_ELEMENT_ID)
2750 p += p[1] + 2;
2751 else {
2752 seq_printf(m,
2753 "Parse beacon failed at essid element id = %d\n",
2754 p[0]);
2755 return 0;
2756 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002757
John Daiker141fa612009-03-10 06:59:54 -07002758 if (p[0] == C_SUPPORTED_RATES_ELEMENT_ID) {
2759 seq_puts(m, "Supported rate codes = ");
2760 for (i = 2; i < p[1] + 2; i++)
2761 seq_printf(m, "0x%02x ", p[i]);
2762 seq_putc(m, '\n');
2763 p += p[1] + 2;
2764 } else {
2765 seq_puts(m, "Parse beacon failed at rates element\n");
2766 return 0;
2767 }
2768
2769 if (p[0] == C_FH_PARAM_SET_ELEMENT_ID) {
2770 pfh = (struct freq_hop_element *)p;
2771 seq_printf(m, "Hop dwell = %d Kus\n",
2772 pfh->dwell_time[0] +
2773 256 * pfh->dwell_time[1]);
2774 seq_printf(m, "Hop set = %d \n",
2775 pfh->hop_set);
2776 seq_printf(m, "Hop pattern = %d \n",
2777 pfh->hop_pattern);
2778 seq_printf(m, "Hop index = %d \n",
2779 pfh->hop_index);
2780 p += p[1] + 2;
2781 } else {
2782 seq_puts(m,
2783 "Parse beacon failed at FH param element\n");
2784 return 0;
2785 }
2786 } else {
2787 seq_puts(m, "No beacons received\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002788 }
John Daiker141fa612009-03-10 06:59:54 -07002789 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002790}
2791
Alexey Dobriyan6b914c52008-04-10 14:34:35 -07002792static int ray_cs_proc_open(struct inode *inode, struct file *file)
2793{
2794 return single_open(file, ray_cs_proc_show, NULL);
2795}
2796
2797static const struct file_operations ray_cs_proc_fops = {
John Daiker141fa612009-03-10 06:59:54 -07002798 .owner = THIS_MODULE,
2799 .open = ray_cs_proc_open,
2800 .read = seq_read,
2801 .llseek = seq_lseek,
2802 .release = single_release,
Alexey Dobriyan6b914c52008-04-10 14:34:35 -07002803};
Linus Torvalds1da177e2005-04-16 15:20:36 -07002804#endif
2805/*===========================================================================*/
2806static int build_auth_frame(ray_dev_t *local, UCHAR *dest, int auth_type)
2807{
John Daiker141fa612009-03-10 06:59:54 -07002808 int addr;
2809 struct ccs __iomem *pccs;
2810 struct tx_msg __iomem *ptx;
2811 int ccsindex;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002812
John Daiker141fa612009-03-10 06:59:54 -07002813 /* If no tx buffers available, return */
2814 if ((ccsindex = get_free_tx_ccs(local)) < 0) {
Dominik Brodowski624dd662009-10-24 15:52:44 +02002815 pr_debug("ray_cs send authenticate - No free tx ccs\n");
John Daiker141fa612009-03-10 06:59:54 -07002816 return -1;
2817 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002818
John Daiker141fa612009-03-10 06:59:54 -07002819 pccs = ccs_base(local) + ccsindex;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002820
John Daiker141fa612009-03-10 06:59:54 -07002821 /* Address in card space */
2822 addr = TX_BUF_BASE + (ccsindex << 11);
2823 /* fill in the CCS */
2824 writeb(CCS_TX_REQUEST, &pccs->cmd);
2825 writeb(addr >> 8, pccs->var.tx_request.tx_data_ptr);
2826 writeb(0x20, pccs->var.tx_request.tx_data_ptr + 1);
2827 writeb(TX_AUTHENTICATE_LENGTH_MSB, pccs->var.tx_request.tx_data_length);
2828 writeb(TX_AUTHENTICATE_LENGTH_LSB,
2829 pccs->var.tx_request.tx_data_length + 1);
2830 writeb(0, &pccs->var.tx_request.pow_sav_mode);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002831
John Daiker141fa612009-03-10 06:59:54 -07002832 ptx = local->sram + addr;
2833 /* fill in the mac header */
2834 writeb(PROTOCOL_VER | AUTHENTIC_TYPE, &ptx->mac.frame_ctl_1);
2835 writeb(0, &ptx->mac.frame_ctl_2);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002836
John Daiker141fa612009-03-10 06:59:54 -07002837 memcpy_toio(ptx->mac.addr_1, dest, ADDRLEN);
2838 memcpy_toio(ptx->mac.addr_2, local->sparm.b4.a_mac_addr, ADDRLEN);
2839 memcpy_toio(ptx->mac.addr_3, local->bss_id, ADDRLEN);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002840
John Daiker141fa612009-03-10 06:59:54 -07002841 /* Fill in msg body with protocol 00 00, sequence 01 00 ,status 00 00 */
2842 memset_io(ptx->var, 0, 6);
2843 writeb(auth_type & 0xff, ptx->var + 2);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002844
John Daiker141fa612009-03-10 06:59:54 -07002845 /* Interrupt the firmware to process the command */
2846 if (interrupt_ecf(local, ccsindex)) {
Dominik Brodowski624dd662009-10-24 15:52:44 +02002847 pr_debug(
John Daiker141fa612009-03-10 06:59:54 -07002848 "ray_cs send authentication request failed - ECF not ready for intr\n");
2849 writeb(CCS_BUFFER_FREE, &(pccs++)->buffer_status);
2850 return -1;
2851 }
2852 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002853} /* End build_auth_frame */
2854
2855/*===========================================================================*/
2856#ifdef CONFIG_PROC_FS
Alexey Dobriyan83daee02009-11-25 10:12:20 +03002857static ssize_t ray_cs_essid_proc_write(struct file *file,
2858 const char __user *buffer, size_t count, loff_t *pos)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002859{
2860 static char proc_essid[33];
Alan Cox575c9ed2009-10-27 15:35:55 +00002861 unsigned int len = count;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002862
2863 if (len > 32)
2864 len = 32;
2865 memset(proc_essid, 0, 33);
2866 if (copy_from_user(proc_essid, buffer, len))
2867 return -EFAULT;
2868 essid = proc_essid;
2869 return count;
2870}
2871
Alexey Dobriyan83daee02009-11-25 10:12:20 +03002872static const struct file_operations ray_cs_essid_proc_fops = {
2873 .owner = THIS_MODULE,
2874 .write = ray_cs_essid_proc_write,
2875};
2876
2877static ssize_t int_proc_write(struct file *file, const char __user *buffer,
2878 size_t count, loff_t *pos)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002879{
2880 static char proc_number[10];
2881 char *p;
2882 int nr, len;
2883
2884 if (!count)
2885 return 0;
2886
2887 if (count > 9)
2888 return -EINVAL;
2889 if (copy_from_user(proc_number, buffer, count))
2890 return -EFAULT;
2891 p = proc_number;
2892 nr = 0;
2893 len = count;
2894 do {
2895 unsigned int c = *p - '0';
2896 if (c > 9)
2897 return -EINVAL;
John Daiker141fa612009-03-10 06:59:54 -07002898 nr = nr * 10 + c;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002899 p++;
2900 } while (--len);
Alexey Dobriyan83daee02009-11-25 10:12:20 +03002901 *(int *)PDE(file->f_path.dentry->d_inode)->data = nr;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002902 return count;
2903}
Alexey Dobriyan83daee02009-11-25 10:12:20 +03002904
2905static const struct file_operations int_proc_fops = {
2906 .owner = THIS_MODULE,
2907 .write = int_proc_write,
2908};
Linus Torvalds1da177e2005-04-16 15:20:36 -07002909#endif
2910
Dominik Brodowskif57ea2a2005-06-27 16:28:24 -07002911static struct pcmcia_device_id ray_ids[] = {
2912 PCMCIA_DEVICE_MANF_CARD(0x01a6, 0x0000),
2913 PCMCIA_DEVICE_NULL,
2914};
John Daiker141fa612009-03-10 06:59:54 -07002915
Dominik Brodowskif57ea2a2005-06-27 16:28:24 -07002916MODULE_DEVICE_TABLE(pcmcia, ray_ids);
2917
Linus Torvalds1da177e2005-04-16 15:20:36 -07002918static struct pcmcia_driver ray_driver = {
John Daiker141fa612009-03-10 06:59:54 -07002919 .owner = THIS_MODULE,
2920 .drv = {
2921 .name = "ray_cs",
2922 },
2923 .probe = ray_probe,
2924 .remove = ray_detach,
2925 .id_table = ray_ids,
2926 .suspend = ray_suspend,
2927 .resume = ray_resume,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002928};
2929
2930static int __init init_ray_cs(void)
2931{
John Daiker141fa612009-03-10 06:59:54 -07002932 int rc;
2933
Dominik Brodowski624dd662009-10-24 15:52:44 +02002934 pr_debug("%s\n", rcsid);
John Daiker141fa612009-03-10 06:59:54 -07002935 rc = pcmcia_register_driver(&ray_driver);
Dominik Brodowski624dd662009-10-24 15:52:44 +02002936 pr_debug("raylink init_module register_pcmcia_driver returns 0x%x\n",
John Daiker141fa612009-03-10 06:59:54 -07002937 rc);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002938
2939#ifdef CONFIG_PROC_FS
John Daiker141fa612009-03-10 06:59:54 -07002940 proc_mkdir("driver/ray_cs", NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002941
John Daiker141fa612009-03-10 06:59:54 -07002942 proc_create("driver/ray_cs/ray_cs", 0, NULL, &ray_cs_proc_fops);
Alexey Dobriyan83daee02009-11-25 10:12:20 +03002943 proc_create("driver/ray_cs/essid", S_IWUSR, NULL, &ray_cs_essid_proc_fops);
2944 proc_create_data("driver/ray_cs/net_type", S_IWUSR, NULL, &int_proc_fops, &net_type);
2945 proc_create_data("driver/ray_cs/translate", S_IWUSR, NULL, &int_proc_fops, &translate);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002946#endif
John Daiker141fa612009-03-10 06:59:54 -07002947 if (translate != 0)
2948 translate = 1;
2949 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002950} /* init_ray_cs */
2951
2952/*===========================================================================*/
2953
2954static void __exit exit_ray_cs(void)
2955{
Dominik Brodowski624dd662009-10-24 15:52:44 +02002956 pr_debug("ray_cs: cleanup_module\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002957
2958#ifdef CONFIG_PROC_FS
John Daiker141fa612009-03-10 06:59:54 -07002959 remove_proc_entry("driver/ray_cs/ray_cs", NULL);
2960 remove_proc_entry("driver/ray_cs/essid", NULL);
2961 remove_proc_entry("driver/ray_cs/net_type", NULL);
2962 remove_proc_entry("driver/ray_cs/translate", NULL);
2963 remove_proc_entry("driver/ray_cs", NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002964#endif
2965
John Daiker141fa612009-03-10 06:59:54 -07002966 pcmcia_unregister_driver(&ray_driver);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002967} /* exit_ray_cs */
2968
2969module_init(init_ray_cs);
2970module_exit(exit_ray_cs);
2971
2972/*===========================================================================*/