blob: d91a831a7700b0509f40e4ff1b445a7b9923abac [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/string.h>
39#include <linux/timer.h>
40#include <linux/init.h>
41#include <linux/netdevice.h>
42#include <linux/etherdevice.h>
43#include <linux/if_arp.h>
44#include <linux/ioport.h>
45#include <linux/skbuff.h>
Al Viro7698d692007-12-29 04:55:50 -050046#include <linux/ieee80211.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070047
Linus Torvalds1da177e2005-04-16 15:20:36 -070048#include <pcmcia/cs.h>
49#include <pcmcia/cistpl.h>
50#include <pcmcia/cisreg.h>
51#include <pcmcia/ds.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070052
53#include <linux/wireless.h>
Michael Wu113b8982006-08-13 23:27:17 -070054#include <net/iw_handler.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070055
56#include <asm/io.h>
57#include <asm/system.h>
58#include <asm/byteorder.h>
59#include <asm/uaccess.h>
60
61/* Warning : these stuff will slow down the driver... */
62#define WIRELESS_SPY /* Enable spying addresses */
63/* Definitions we need for spy */
John Daiker141fa612009-03-10 06:59:54 -070064typedef struct iw_statistics iw_stats;
65typedef u_char mac_addr[ETH_ALEN]; /* Hardware address */
Linus Torvalds1da177e2005-04-16 15:20:36 -070066
67#include "rayctl.h"
68#include "ray_cs.h"
69
Linus Torvalds1da177e2005-04-16 15:20:36 -070070
Linus Torvalds1da177e2005-04-16 15:20:36 -070071/** Prototypes based on PCMCIA skeleton driver *******************************/
Dominik Brodowski15b99ac2006-03-31 17:26:06 +020072static int ray_config(struct pcmcia_device *link);
Dominik Brodowskifba395e2006-03-31 17:21:06 +020073static void ray_release(struct pcmcia_device *link);
Dominik Brodowskicc3b4862005-11-14 21:23:14 +010074static void ray_detach(struct pcmcia_device *p_dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -070075
76/***** Prototypes indicated by device structure ******************************/
77static int ray_dev_close(struct net_device *dev);
78static int ray_dev_config(struct net_device *dev, struct ifmap *map);
79static struct net_device_stats *ray_get_stats(struct net_device *dev);
80static int ray_dev_init(struct net_device *dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -070081
Linus Torvalds1da177e2005-04-16 15:20:36 -070082static int ray_open(struct net_device *dev);
Stephen Hemmingerd0cf9c02009-08-31 19:50:57 +000083static netdev_tx_t ray_dev_start_xmit(struct sk_buff *skb,
84 struct net_device *dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -070085static void set_multicast_list(struct net_device *dev);
86static void ray_update_multi_list(struct net_device *dev, int all);
87static int translate_frame(ray_dev_t *local, struct tx_msg __iomem *ptx,
John Daiker141fa612009-03-10 06:59:54 -070088 unsigned char *data, int len);
89static void ray_build_header(ray_dev_t *local, struct tx_msg __iomem *ptx,
90 UCHAR msg_type, unsigned char *data);
Linus Torvalds1da177e2005-04-16 15:20:36 -070091static void untranslate(ray_dev_t *local, struct sk_buff *skb, int len);
John Daiker141fa612009-03-10 06:59:54 -070092static iw_stats *ray_get_wireless_stats(struct net_device *dev);
93static const struct iw_handler_def ray_handler_def;
Linus Torvalds1da177e2005-04-16 15:20:36 -070094
95/***** Prototypes for raylink functions **************************************/
Linus Torvalds1da177e2005-04-16 15:20:36 -070096static void authenticate(ray_dev_t *local);
97static int build_auth_frame(ray_dev_t *local, UCHAR *dest, int auth_type);
98static void authenticate_timeout(u_long);
99static int get_free_ccs(ray_dev_t *local);
100static int get_free_tx_ccs(ray_dev_t *local);
101static void init_startup_params(ray_dev_t *local);
102static int parse_addr(char *in_str, UCHAR *out);
John Daiker141fa612009-03-10 06:59:54 -0700103static int ray_hw_xmit(unsigned char *data, int len, struct net_device *dev, UCHAR type);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700104static int ray_init(struct net_device *dev);
105static int interrupt_ecf(ray_dev_t *local, int ccs);
106static void ray_reset(struct net_device *dev);
107static void ray_update_parm(struct net_device *dev, UCHAR objid, UCHAR *value, int len);
108static void verify_dl_startup(u_long);
109
110/* Prototypes for interrpt time functions **********************************/
John Daiker141fa612009-03-10 06:59:54 -0700111static irqreturn_t ray_interrupt(int reg, void *dev_id);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700112static void clear_interrupt(ray_dev_t *local);
John Daiker141fa612009-03-10 06:59:54 -0700113static void rx_deauthenticate(ray_dev_t *local, struct rcs __iomem *prcs,
114 unsigned int pkt_addr, int rx_len);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700115static int copy_from_rx_buff(ray_dev_t *local, UCHAR *dest, int pkt_addr, int len);
116static void ray_rx(struct net_device *dev, ray_dev_t *local, struct rcs __iomem *prcs);
117static void release_frag_chain(ray_dev_t *local, struct rcs __iomem *prcs);
118static void rx_authenticate(ray_dev_t *local, struct rcs __iomem *prcs,
John Daiker141fa612009-03-10 06:59:54 -0700119 unsigned int pkt_addr, int rx_len);
120static void rx_data(struct net_device *dev, struct rcs __iomem *prcs,
121 unsigned int pkt_addr, int rx_len);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700122static void associate(ray_dev_t *local);
123
124/* Card command functions */
125static int dl_startup_params(struct net_device *dev);
126static void join_net(u_long local);
127static void start_net(u_long local);
128/* void start_net(ray_dev_t *local); */
129
130/*===========================================================================*/
131/* Parameters that can be set with 'insmod' */
132
133/* ADHOC=0, Infrastructure=1 */
134static int net_type = ADHOC;
135
136/* Hop dwell time in Kus (1024 us units defined by 802.11) */
137static int hop_dwell = 128;
138
139/* Beacon period in Kus */
140static int beacon_period = 256;
141
142/* power save mode (0 = off, 1 = save power) */
143static int psm;
144
145/* String for network's Extended Service Set ID. 32 Characters max */
146static char *essid;
147
148/* Default to encapsulation unless translation requested */
149static int translate = 1;
150
151static int country = USA;
152
153static int sniffer;
154
155static int bc;
156
157/* 48 bit physical card address if overriding card's real physical
158 * address is required. Since IEEE 802.11 addresses are 48 bits
159 * like ethernet, an int can't be used, so a string is used. To
160 * allow use of addresses starting with a decimal digit, the first
161 * character must be a letter and will be ignored. This letter is
162 * followed by up to 12 hex digits which are the address. If less
163 * than 12 digits are used, the address will be left filled with 0's.
164 * Note that bit 0 of the first byte is the broadcast bit, and evil
165 * things will happen if it is not 0 in a card address.
166 */
167static char *phy_addr = NULL;
168
169
Dominik Brodowskifba395e2006-03-31 17:21:06 +0200170/* A struct pcmcia_device structure has fields for most things that are needed
Linus Torvalds1da177e2005-04-16 15:20:36 -0700171 to keep track of a socket, but there will usually be some device
172 specific information that also needs to be kept track of. The
Dominik Brodowskifba395e2006-03-31 17:21:06 +0200173 'priv' pointer in a struct pcmcia_device structure can be used to point to
Linus Torvalds1da177e2005-04-16 15:20:36 -0700174 a device-specific private data structure, like this.
175*/
176static unsigned int ray_mem_speed = 500;
177
Dominik Brodowskifd238232006-03-05 10:45:09 +0100178/* WARNING: THIS DRIVER IS NOT CAPABLE OF HANDLING MULTIPLE DEVICES! */
179static struct pcmcia_device *this_device = NULL;
180
Linus Torvalds1da177e2005-04-16 15:20:36 -0700181MODULE_AUTHOR("Corey Thomas <corey@world.std.com>");
182MODULE_DESCRIPTION("Raylink/WebGear wireless LAN driver");
183MODULE_LICENSE("GPL");
184
185module_param(net_type, int, 0);
186module_param(hop_dwell, int, 0);
187module_param(beacon_period, int, 0);
188module_param(psm, int, 0);
189module_param(essid, charp, 0);
190module_param(translate, int, 0);
191module_param(country, int, 0);
192module_param(sniffer, int, 0);
193module_param(bc, int, 0);
194module_param(phy_addr, charp, 0);
195module_param(ray_mem_speed, int, 0);
196
197static UCHAR b5_default_startup_parms[] = {
John Daiker141fa612009-03-10 06:59:54 -0700198 0, 0, /* Adhoc station */
199 'L', 'I', 'N', 'U', 'X', 0, 0, 0, /* 32 char ESSID */
200 0, 0, 0, 0, 0, 0, 0, 0,
201 0, 0, 0, 0, 0, 0, 0, 0,
202 0, 0, 0, 0, 0, 0, 0, 0,
203 1, 0, /* Active scan, CA Mode */
204 0, 0, 0, 0, 0, 0, /* No default MAC addr */
205 0x7f, 0xff, /* Frag threshold */
206 0x00, 0x80, /* Hop time 128 Kus */
207 0x01, 0x00, /* Beacon period 256 Kus */
208 0x01, 0x07, 0xa3, /* DTIM, retries, ack timeout */
209 0x1d, 0x82, 0x4e, /* SIFS, DIFS, PIFS */
210 0x7f, 0xff, /* RTS threshold */
211 0x04, 0xe2, 0x38, 0xA4, /* scan_dwell, max_scan_dwell */
212 0x05, /* assoc resp timeout thresh */
213 0x08, 0x02, 0x08, /* adhoc, infra, super cycle max */
214 0, /* Promiscuous mode */
215 0x0c, 0x0bd, /* Unique word */
216 0x32, /* Slot time */
217 0xff, 0xff, /* roam-low snr, low snr count */
218 0x05, 0xff, /* Infra, adhoc missed bcn thresh */
219 0x01, 0x0b, 0x4f, /* USA, hop pattern, hop pat length */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700220/* b4 - b5 differences start here */
John Daiker141fa612009-03-10 06:59:54 -0700221 0x00, 0x3f, /* CW max */
222 0x00, 0x0f, /* CW min */
223 0x04, 0x08, /* Noise gain, limit offset */
224 0x28, 0x28, /* det rssi, med busy offsets */
225 7, /* det sync thresh */
226 0, 2, 2, /* test mode, min, max */
227 0, /* allow broadcast SSID probe resp */
228 0, 0, /* privacy must start, can join */
229 2, 0, 0, 0, 0, 0, 0, 0 /* basic rate set */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700230};
231
232static UCHAR b4_default_startup_parms[] = {
John Daiker141fa612009-03-10 06:59:54 -0700233 0, 0, /* Adhoc station */
234 'L', 'I', 'N', 'U', 'X', 0, 0, 0, /* 32 char ESSID */
235 0, 0, 0, 0, 0, 0, 0, 0,
236 0, 0, 0, 0, 0, 0, 0, 0,
237 0, 0, 0, 0, 0, 0, 0, 0,
238 1, 0, /* Active scan, CA Mode */
239 0, 0, 0, 0, 0, 0, /* No default MAC addr */
240 0x7f, 0xff, /* Frag threshold */
241 0x02, 0x00, /* Hop time */
242 0x00, 0x01, /* Beacon period */
243 0x01, 0x07, 0xa3, /* DTIM, retries, ack timeout */
244 0x1d, 0x82, 0xce, /* SIFS, DIFS, PIFS */
245 0x7f, 0xff, /* RTS threshold */
246 0xfb, 0x1e, 0xc7, 0x5c, /* scan_dwell, max_scan_dwell */
247 0x05, /* assoc resp timeout thresh */
248 0x04, 0x02, 0x4, /* adhoc, infra, super cycle max */
249 0, /* Promiscuous mode */
250 0x0c, 0x0bd, /* Unique word */
251 0x4e, /* Slot time (TBD seems wrong) */
252 0xff, 0xff, /* roam-low snr, low snr count */
253 0x05, 0xff, /* Infra, adhoc missed bcn thresh */
254 0x01, 0x0b, 0x4e, /* USA, hop pattern, hop pat length */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700255/* b4 - b5 differences start here */
John Daiker141fa612009-03-10 06:59:54 -0700256 0x3f, 0x0f, /* CW max, min */
257 0x04, 0x08, /* Noise gain, limit offset */
258 0x28, 0x28, /* det rssi, med busy offsets */
259 7, /* det sync thresh */
260 0, 2, 2 /* test mode, min, max */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700261};
John Daiker141fa612009-03-10 06:59:54 -0700262
Linus Torvalds1da177e2005-04-16 15:20:36 -0700263/*===========================================================================*/
John Daiker141fa612009-03-10 06:59:54 -0700264static unsigned char eth2_llc[] = { 0xaa, 0xaa, 3, 0, 0, 0 };
Linus Torvalds1da177e2005-04-16 15:20:36 -0700265
266static char hop_pattern_length[] = { 1,
John Daiker141fa612009-03-10 06:59:54 -0700267 USA_HOP_MOD, EUROPE_HOP_MOD,
268 JAPAN_HOP_MOD, KOREA_HOP_MOD,
269 SPAIN_HOP_MOD, FRANCE_HOP_MOD,
270 ISRAEL_HOP_MOD, AUSTRALIA_HOP_MOD,
271 JAPAN_TEST_HOP_MOD
Linus Torvalds1da177e2005-04-16 15:20:36 -0700272};
273
John Daiker141fa612009-03-10 06:59:54 -0700274static char rcsid[] =
275 "Raylink/WebGear wireless LAN - Corey <Thomas corey@world.std.com>";
Linus Torvalds1da177e2005-04-16 15:20:36 -0700276
Stephen Hemminger32f5a332009-03-20 19:36:28 +0000277static const struct net_device_ops ray_netdev_ops = {
278 .ndo_init = ray_dev_init,
279 .ndo_open = ray_open,
280 .ndo_stop = ray_dev_close,
281 .ndo_start_xmit = ray_dev_start_xmit,
282 .ndo_set_config = ray_dev_config,
283 .ndo_get_stats = ray_get_stats,
284 .ndo_set_multicast_list = set_multicast_list,
285 .ndo_change_mtu = eth_change_mtu,
286 .ndo_set_mac_address = eth_mac_addr,
287 .ndo_validate_addr = eth_validate_addr,
288};
289
Linus Torvalds1da177e2005-04-16 15:20:36 -0700290/*=============================================================================
291 ray_attach() creates an "instance" of the driver, allocating
292 local data structures for one device. The device is registered
293 with Card Services.
294 The dev_link structure is initialized, but we don't actually
295 configure the card at this point -- we wait until we receive a
296 card insertion event.
297=============================================================================*/
Dominik Brodowski15b99ac2006-03-31 17:26:06 +0200298static int ray_probe(struct pcmcia_device *p_dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700299{
John Daiker141fa612009-03-10 06:59:54 -0700300 ray_dev_t *local;
301 struct net_device *dev;
Dominik Brodowskifd238232006-03-05 10:45:09 +0100302
Dominik Brodowski624dd662009-10-24 15:52:44 +0200303 dev_dbg(&p_dev->dev, "ray_attach()\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700304
John Daiker141fa612009-03-10 06:59:54 -0700305 /* Allocate space for private device-specific data */
306 dev = alloc_etherdev(sizeof(ray_dev_t));
307 if (!dev)
308 goto fail_alloc_dev;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700309
John Daiker141fa612009-03-10 06:59:54 -0700310 local = netdev_priv(dev);
311 local->finder = p_dev;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700312
John Daiker141fa612009-03-10 06:59:54 -0700313 /* The io structure describes IO port mapping. None used here */
Dominik Brodowski90abdc32010-07-24 17:23:51 +0200314 p_dev->resource[0]->end = 0;
315 p_dev->resource[0]->flags |= IO_DATA_PATH_WIDTH_8;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700316
John Daiker141fa612009-03-10 06:59:54 -0700317 /* General socket configuration */
318 p_dev->conf.Attributes = CONF_ENABLE_IRQ;
319 p_dev->conf.IntType = INT_MEMORY_AND_IO;
320 p_dev->conf.ConfigIndex = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700321
John Daiker141fa612009-03-10 06:59:54 -0700322 p_dev->priv = dev;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700323
John Daiker141fa612009-03-10 06:59:54 -0700324 local->finder = p_dev;
325 local->card_status = CARD_INSERTED;
326 local->authentication_state = UNAUTHENTICATED;
327 local->num_multi = 0;
Dominik Brodowski624dd662009-10-24 15:52:44 +0200328 dev_dbg(&p_dev->dev, "ray_attach p_dev = %p, dev = %p, local = %p, intr = %p\n",
John Daiker141fa612009-03-10 06:59:54 -0700329 p_dev, dev, local, &ray_interrupt);
330
331 /* Raylink entries in the device structure */
Stephen Hemminger32f5a332009-03-20 19:36:28 +0000332 dev->netdev_ops = &ray_netdev_ops;
John Daiker141fa612009-03-10 06:59:54 -0700333 dev->wireless_handlers = &ray_handler_def;
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -0700334#ifdef WIRELESS_SPY
John Daiker141fa612009-03-10 06:59:54 -0700335 local->wireless_data.spy_data = &local->spy_data;
336 dev->wireless_data = &local->wireless_data;
337#endif /* WIRELESS_SPY */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700338
Linus Torvalds1da177e2005-04-16 15:20:36 -0700339
Dominik Brodowski624dd662009-10-24 15:52:44 +0200340 dev_dbg(&p_dev->dev, "ray_cs ray_attach calling ether_setup.)\n");
John Daiker141fa612009-03-10 06:59:54 -0700341 netif_stop_queue(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700342
John Daiker141fa612009-03-10 06:59:54 -0700343 init_timer(&local->timer);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700344
John Daiker141fa612009-03-10 06:59:54 -0700345 this_device = p_dev;
346 return ray_config(p_dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700347
348fail_alloc_dev:
John Daiker141fa612009-03-10 06:59:54 -0700349 return -ENOMEM;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700350} /* ray_attach */
John Daiker141fa612009-03-10 06:59:54 -0700351
Linus Torvalds1da177e2005-04-16 15:20:36 -0700352/*=============================================================================
353 This deletes a driver "instance". The device is de-registered
354 with Card Services. If it has been released, all local data
355 structures are freed. Otherwise, the structures will be freed
356 when the device is released.
357=============================================================================*/
Dominik Brodowskifba395e2006-03-31 17:21:06 +0200358static void ray_detach(struct pcmcia_device *link)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700359{
John Daiker141fa612009-03-10 06:59:54 -0700360 struct net_device *dev;
361 ray_dev_t *local;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700362
Dominik Brodowski624dd662009-10-24 15:52:44 +0200363 dev_dbg(&link->dev, "ray_detach\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700364
John Daiker141fa612009-03-10 06:59:54 -0700365 this_device = NULL;
366 dev = link->priv;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700367
John Daiker141fa612009-03-10 06:59:54 -0700368 ray_release(link);
Dominik Brodowskicc3b4862005-11-14 21:23:14 +0100369
John Daiker141fa612009-03-10 06:59:54 -0700370 local = netdev_priv(dev);
371 del_timer(&local->timer);
Dominik Brodowskicc3b4862005-11-14 21:23:14 +0100372
John Daiker141fa612009-03-10 06:59:54 -0700373 if (link->priv) {
Dominik Brodowskic7c2fa02010-03-20 19:39:26 +0100374 unregister_netdev(dev);
John Daiker141fa612009-03-10 06:59:54 -0700375 free_netdev(dev);
376 }
Dominik Brodowski624dd662009-10-24 15:52:44 +0200377 dev_dbg(&link->dev, "ray_cs ray_detach ending\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700378} /* ray_detach */
John Daiker141fa612009-03-10 06:59:54 -0700379
Linus Torvalds1da177e2005-04-16 15:20:36 -0700380/*=============================================================================
381 ray_config() is run after a CARD_INSERTION event
382 is received, to configure the PCMCIA socket, and to make the
383 ethernet device available to the system.
384=============================================================================*/
Linus Torvalds1da177e2005-04-16 15:20:36 -0700385#define MAX_TUPLE_SIZE 128
Dominik Brodowski15b99ac2006-03-31 17:26:06 +0200386static int ray_config(struct pcmcia_device *link)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700387{
Dominik Brodowski624dd662009-10-24 15:52:44 +0200388 int ret = 0;
John Daiker141fa612009-03-10 06:59:54 -0700389 int i;
390 win_req_t req;
John Daiker141fa612009-03-10 06:59:54 -0700391 struct net_device *dev = (struct net_device *)link->priv;
392 ray_dev_t *local = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700393
Dominik Brodowski624dd662009-10-24 15:52:44 +0200394 dev_dbg(&link->dev, "ray_config\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700395
John Daiker141fa612009-03-10 06:59:54 -0700396 /* Determine card type and firmware version */
397 printk(KERN_INFO "ray_cs Detected: %s%s%s%s\n",
398 link->prod_id[0] ? link->prod_id[0] : " ",
399 link->prod_id[1] ? link->prod_id[1] : " ",
400 link->prod_id[2] ? link->prod_id[2] : " ",
401 link->prod_id[3] ? link->prod_id[3] : " ");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700402
John Daiker141fa612009-03-10 06:59:54 -0700403 /* Now allocate an interrupt line. Note that this does not
404 actually assign a handler to the interrupt.
405 */
Dominik Brodowskieb141202010-03-07 12:21:16 +0100406 ret = pcmcia_request_irq(link, ray_interrupt);
Dominik Brodowski624dd662009-10-24 15:52:44 +0200407 if (ret)
408 goto failed;
Dominik Brodowskieb141202010-03-07 12:21:16 +0100409 dev->irq = link->irq;
John Daiker141fa612009-03-10 06:59:54 -0700410
411 /* This actually configures the PCMCIA socket -- setting up
412 the I/O windows and the interrupt mapping.
413 */
Dominik Brodowski624dd662009-10-24 15:52:44 +0200414 ret = pcmcia_request_configuration(link, &link->conf);
415 if (ret)
416 goto failed;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700417
418/*** Set up 32k window for shared memory (transmit and control) ************/
John Daiker141fa612009-03-10 06:59:54 -0700419 req.Attributes =
420 WIN_DATA_WIDTH_8 | WIN_MEMORY_TYPE_CM | WIN_ENABLE | WIN_USE_WAIT;
421 req.Base = 0;
422 req.Size = 0x8000;
423 req.AccessSpeed = ray_mem_speed;
Dominik Brodowski6838b032009-11-03 01:31:52 +0100424 ret = pcmcia_request_window(link, &req, &link->win);
Dominik Brodowski624dd662009-10-24 15:52:44 +0200425 if (ret)
426 goto failed;
Dominik Brodowskib5cb2592010-07-24 18:46:42 +0200427 ret = pcmcia_map_mem_page(link, link->win, 0);
Dominik Brodowski624dd662009-10-24 15:52:44 +0200428 if (ret)
429 goto failed;
John Daiker141fa612009-03-10 06:59:54 -0700430 local->sram = ioremap(req.Base, req.Size);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700431
432/*** Set up 16k window for shared memory (receive buffer) ***************/
John Daiker141fa612009-03-10 06:59:54 -0700433 req.Attributes =
434 WIN_DATA_WIDTH_8 | WIN_MEMORY_TYPE_CM | WIN_ENABLE | WIN_USE_WAIT;
435 req.Base = 0;
436 req.Size = 0x4000;
437 req.AccessSpeed = ray_mem_speed;
Dominik Brodowski6838b032009-11-03 01:31:52 +0100438 ret = pcmcia_request_window(link, &req, &local->rmem_handle);
Dominik Brodowski624dd662009-10-24 15:52:44 +0200439 if (ret)
440 goto failed;
Dominik Brodowskib5cb2592010-07-24 18:46:42 +0200441 ret = pcmcia_map_mem_page(link, local->rmem_handle, 0x8000);
Dominik Brodowski624dd662009-10-24 15:52:44 +0200442 if (ret)
443 goto failed;
John Daiker141fa612009-03-10 06:59:54 -0700444 local->rmem = ioremap(req.Base, req.Size);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700445
446/*** Set up window for attribute memory ***********************************/
John Daiker141fa612009-03-10 06:59:54 -0700447 req.Attributes =
448 WIN_DATA_WIDTH_8 | WIN_MEMORY_TYPE_AM | WIN_ENABLE | WIN_USE_WAIT;
449 req.Base = 0;
450 req.Size = 0x1000;
451 req.AccessSpeed = ray_mem_speed;
Dominik Brodowski6838b032009-11-03 01:31:52 +0100452 ret = pcmcia_request_window(link, &req, &local->amem_handle);
Dominik Brodowski624dd662009-10-24 15:52:44 +0200453 if (ret)
454 goto failed;
Dominik Brodowskib5cb2592010-07-24 18:46:42 +0200455 ret = pcmcia_map_mem_page(link, local->amem_handle, 0);
Dominik Brodowski624dd662009-10-24 15:52:44 +0200456 if (ret)
457 goto failed;
John Daiker141fa612009-03-10 06:59:54 -0700458 local->amem = ioremap(req.Base, req.Size);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700459
Dominik Brodowski624dd662009-10-24 15:52:44 +0200460 dev_dbg(&link->dev, "ray_config sram=%p\n", local->sram);
461 dev_dbg(&link->dev, "ray_config rmem=%p\n", local->rmem);
462 dev_dbg(&link->dev, "ray_config amem=%p\n", local->amem);
John Daiker141fa612009-03-10 06:59:54 -0700463 if (ray_init(dev) < 0) {
464 ray_release(link);
465 return -ENODEV;
466 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700467
Dominik Brodowskidd2e5a12009-11-03 10:27:34 +0100468 SET_NETDEV_DEV(dev, &link->dev);
John Daiker141fa612009-03-10 06:59:54 -0700469 i = register_netdev(dev);
470 if (i != 0) {
471 printk("ray_config register_netdev() failed\n");
472 ray_release(link);
473 return i;
474 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700475
John Daiker141fa612009-03-10 06:59:54 -0700476 printk(KERN_INFO "%s: RayLink, irq %d, hw_addr %pM\n",
477 dev->name, dev->irq, dev->dev_addr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700478
John Daiker141fa612009-03-10 06:59:54 -0700479 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700480
Dominik Brodowski624dd662009-10-24 15:52:44 +0200481failed:
John Daiker141fa612009-03-10 06:59:54 -0700482 ray_release(link);
483 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700484} /* ray_config */
485
486static inline struct ccs __iomem *ccs_base(ray_dev_t *dev)
487{
488 return dev->sram + CCS_BASE;
489}
490
491static inline struct rcs __iomem *rcs_base(ray_dev_t *dev)
492{
493 /*
494 * This looks nonsensical, since there is a separate
495 * RCS_BASE. But the difference between a "struct rcs"
496 * and a "struct ccs" ends up being in the _index_ off
497 * the base, so the base pointer is the same for both
498 * ccs/rcs.
499 */
500 return dev->sram + CCS_BASE;
501}
502
503/*===========================================================================*/
504static int ray_init(struct net_device *dev)
505{
John Daiker141fa612009-03-10 06:59:54 -0700506 int i;
507 UCHAR *p;
508 struct ccs __iomem *pccs;
509 ray_dev_t *local = netdev_priv(dev);
510 struct pcmcia_device *link = local->finder;
Dominik Brodowski624dd662009-10-24 15:52:44 +0200511 dev_dbg(&link->dev, "ray_init(0x%p)\n", dev);
John Daiker141fa612009-03-10 06:59:54 -0700512 if (!(pcmcia_dev_present(link))) {
Dominik Brodowski624dd662009-10-24 15:52:44 +0200513 dev_dbg(&link->dev, "ray_init - device not present\n");
John Daiker141fa612009-03-10 06:59:54 -0700514 return -1;
515 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700516
John Daiker141fa612009-03-10 06:59:54 -0700517 local->net_type = net_type;
518 local->sta_type = TYPE_STA;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700519
John Daiker141fa612009-03-10 06:59:54 -0700520 /* Copy the startup results to local memory */
521 memcpy_fromio(&local->startup_res, local->sram + ECF_TO_HOST_BASE,
522 sizeof(struct startup_res_6));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700523
John Daiker141fa612009-03-10 06:59:54 -0700524 /* Check Power up test status and get mac address from card */
525 if (local->startup_res.startup_word != 0x80) {
526 printk(KERN_INFO "ray_init ERROR card status = %2x\n",
527 local->startup_res.startup_word);
528 local->card_status = CARD_INIT_ERROR;
529 return -1;
530 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700531
John Daiker141fa612009-03-10 06:59:54 -0700532 local->fw_ver = local->startup_res.firmware_version[0];
533 local->fw_bld = local->startup_res.firmware_version[1];
534 local->fw_var = local->startup_res.firmware_version[2];
Frans Popcb01b092010-03-24 19:46:34 +0100535 dev_dbg(&link->dev, "ray_init firmware version %d.%d\n", local->fw_ver,
John Daiker141fa612009-03-10 06:59:54 -0700536 local->fw_bld);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700537
John Daiker141fa612009-03-10 06:59:54 -0700538 local->tib_length = 0x20;
539 if ((local->fw_ver == 5) && (local->fw_bld >= 30))
540 local->tib_length = local->startup_res.tib_length;
Dominik Brodowski624dd662009-10-24 15:52:44 +0200541 dev_dbg(&link->dev, "ray_init tib_length = 0x%02x\n", local->tib_length);
John Daiker141fa612009-03-10 06:59:54 -0700542 /* Initialize CCS's to buffer free state */
543 pccs = ccs_base(local);
544 for (i = 0; i < NUMBER_OF_CCS; i++) {
545 writeb(CCS_BUFFER_FREE, &(pccs++)->buffer_status);
546 }
547 init_startup_params(local);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700548
John Daiker141fa612009-03-10 06:59:54 -0700549 /* copy mac address to startup parameters */
550 if (parse_addr(phy_addr, local->sparm.b4.a_mac_addr)) {
551 p = local->sparm.b4.a_mac_addr;
552 } else {
553 memcpy(&local->sparm.b4.a_mac_addr,
554 &local->startup_res.station_addr, ADDRLEN);
555 p = local->sparm.b4.a_mac_addr;
556 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700557
John Daiker141fa612009-03-10 06:59:54 -0700558 clear_interrupt(local); /* Clear any interrupt from the card */
559 local->card_status = CARD_AWAITING_PARAM;
Dominik Brodowski624dd662009-10-24 15:52:44 +0200560 dev_dbg(&link->dev, "ray_init ending\n");
John Daiker141fa612009-03-10 06:59:54 -0700561 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700562} /* ray_init */
John Daiker141fa612009-03-10 06:59:54 -0700563
Linus Torvalds1da177e2005-04-16 15:20:36 -0700564/*===========================================================================*/
565/* Download startup parameters to the card and command it to read them */
566static int dl_startup_params(struct net_device *dev)
567{
John Daiker141fa612009-03-10 06:59:54 -0700568 int ccsindex;
569 ray_dev_t *local = netdev_priv(dev);
570 struct ccs __iomem *pccs;
571 struct pcmcia_device *link = local->finder;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700572
Dominik Brodowski624dd662009-10-24 15:52:44 +0200573 dev_dbg(&link->dev, "dl_startup_params entered\n");
John Daiker141fa612009-03-10 06:59:54 -0700574 if (!(pcmcia_dev_present(link))) {
Dominik Brodowski624dd662009-10-24 15:52:44 +0200575 dev_dbg(&link->dev, "ray_cs dl_startup_params - device not present\n");
John Daiker141fa612009-03-10 06:59:54 -0700576 return -1;
577 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700578
John Daiker141fa612009-03-10 06:59:54 -0700579 /* Copy parameters to host to ECF area */
580 if (local->fw_ver == 0x55)
581 memcpy_toio(local->sram + HOST_TO_ECF_BASE, &local->sparm.b4,
582 sizeof(struct b4_startup_params));
583 else
584 memcpy_toio(local->sram + HOST_TO_ECF_BASE, &local->sparm.b5,
585 sizeof(struct b5_startup_params));
586
587 /* Fill in the CCS fields for the ECF */
588 if ((ccsindex = get_free_ccs(local)) < 0)
589 return -1;
590 local->dl_param_ccs = ccsindex;
591 pccs = ccs_base(local) + ccsindex;
592 writeb(CCS_DOWNLOAD_STARTUP_PARAMS, &pccs->cmd);
Dominik Brodowski624dd662009-10-24 15:52:44 +0200593 dev_dbg(&link->dev, "dl_startup_params start ccsindex = %d\n",
John Daiker141fa612009-03-10 06:59:54 -0700594 local->dl_param_ccs);
595 /* Interrupt the firmware to process the command */
596 if (interrupt_ecf(local, ccsindex)) {
597 printk(KERN_INFO "ray dl_startup_params failed - "
598 "ECF not ready for intr\n");
599 local->card_status = CARD_DL_PARAM_ERROR;
600 writeb(CCS_BUFFER_FREE, &(pccs++)->buffer_status);
601 return -2;
602 }
603 local->card_status = CARD_DL_PARAM;
604 /* Start kernel timer to wait for dl startup to complete. */
605 local->timer.expires = jiffies + HZ / 2;
606 local->timer.data = (long)local;
Joe Perchesc061b182010-08-23 18:20:03 +0000607 local->timer.function = verify_dl_startup;
John Daiker141fa612009-03-10 06:59:54 -0700608 add_timer(&local->timer);
Dominik Brodowski624dd662009-10-24 15:52:44 +0200609 dev_dbg(&link->dev,
John Daiker141fa612009-03-10 06:59:54 -0700610 "ray_cs dl_startup_params started timer for verify_dl_startup\n");
611 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700612} /* dl_startup_params */
John Daiker141fa612009-03-10 06:59:54 -0700613
Linus Torvalds1da177e2005-04-16 15:20:36 -0700614/*===========================================================================*/
615static void init_startup_params(ray_dev_t *local)
616{
John Daiker141fa612009-03-10 06:59:54 -0700617 int i;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700618
John Daiker141fa612009-03-10 06:59:54 -0700619 if (country > JAPAN_TEST)
620 country = USA;
621 else if (country < USA)
622 country = USA;
623 /* structure for hop time and beacon period is defined here using
624 * New 802.11D6.1 format. Card firmware is still using old format
625 * until version 6.
626 * Before After
627 * a_hop_time ms byte a_hop_time ms byte
628 * a_hop_time 2s byte a_hop_time ls byte
629 * a_hop_time ls byte a_beacon_period ms byte
630 * a_beacon_period a_beacon_period ls byte
631 *
632 * a_hop_time = uS a_hop_time = KuS
633 * a_beacon_period = hops a_beacon_period = KuS
634 *//* 64ms = 010000 */
635 if (local->fw_ver == 0x55) {
636 memcpy((UCHAR *) &local->sparm.b4, b4_default_startup_parms,
637 sizeof(struct b4_startup_params));
638 /* Translate sane kus input values to old build 4/5 format */
639 /* i = hop time in uS truncated to 3 bytes */
640 i = (hop_dwell * 1024) & 0xffffff;
641 local->sparm.b4.a_hop_time[0] = (i >> 16) & 0xff;
642 local->sparm.b4.a_hop_time[1] = (i >> 8) & 0xff;
643 local->sparm.b4.a_beacon_period[0] = 0;
644 local->sparm.b4.a_beacon_period[1] =
645 ((beacon_period / hop_dwell) - 1) & 0xff;
646 local->sparm.b4.a_curr_country_code = country;
647 local->sparm.b4.a_hop_pattern_length =
648 hop_pattern_length[(int)country] - 1;
649 if (bc) {
650 local->sparm.b4.a_ack_timeout = 0x50;
651 local->sparm.b4.a_sifs = 0x3f;
652 }
653 } else { /* Version 5 uses real kus values */
654 memcpy((UCHAR *) &local->sparm.b5, b5_default_startup_parms,
655 sizeof(struct b5_startup_params));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700656
John Daiker141fa612009-03-10 06:59:54 -0700657 local->sparm.b5.a_hop_time[0] = (hop_dwell >> 8) & 0xff;
658 local->sparm.b5.a_hop_time[1] = hop_dwell & 0xff;
659 local->sparm.b5.a_beacon_period[0] =
660 (beacon_period >> 8) & 0xff;
661 local->sparm.b5.a_beacon_period[1] = beacon_period & 0xff;
662 if (psm)
663 local->sparm.b5.a_power_mgt_state = 1;
664 local->sparm.b5.a_curr_country_code = country;
665 local->sparm.b5.a_hop_pattern_length =
666 hop_pattern_length[(int)country];
667 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700668
John Daiker141fa612009-03-10 06:59:54 -0700669 local->sparm.b4.a_network_type = net_type & 0x01;
670 local->sparm.b4.a_acting_as_ap_status = TYPE_STA;
671
672 if (essid != NULL)
673 strncpy(local->sparm.b4.a_current_ess_id, essid, ESSID_SIZE);
674} /* init_startup_params */
675
Linus Torvalds1da177e2005-04-16 15:20:36 -0700676/*===========================================================================*/
677static void verify_dl_startup(u_long data)
678{
John Daiker141fa612009-03-10 06:59:54 -0700679 ray_dev_t *local = (ray_dev_t *) data;
680 struct ccs __iomem *pccs = ccs_base(local) + local->dl_param_ccs;
681 UCHAR status;
682 struct pcmcia_device *link = local->finder;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700683
John Daiker141fa612009-03-10 06:59:54 -0700684 if (!(pcmcia_dev_present(link))) {
Dominik Brodowski624dd662009-10-24 15:52:44 +0200685 dev_dbg(&link->dev, "ray_cs verify_dl_startup - device not present\n");
John Daiker141fa612009-03-10 06:59:54 -0700686 return;
687 }
Dominik Brodowski624dd662009-10-24 15:52:44 +0200688#if 0
689 {
John Daiker141fa612009-03-10 06:59:54 -0700690 int i;
691 printk(KERN_DEBUG
692 "verify_dl_startup parameters sent via ccs %d:\n",
693 local->dl_param_ccs);
694 for (i = 0; i < sizeof(struct b5_startup_params); i++) {
695 printk(" %2x",
696 (unsigned int)readb(local->sram +
697 HOST_TO_ECF_BASE + i));
698 }
699 printk("\n");
700 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700701#endif
702
John Daiker141fa612009-03-10 06:59:54 -0700703 status = readb(&pccs->buffer_status);
704 if (status != CCS_BUFFER_FREE) {
705 printk(KERN_INFO
706 "Download startup params failed. Status = %d\n",
707 status);
708 local->card_status = CARD_DL_PARAM_ERROR;
709 return;
710 }
711 if (local->sparm.b4.a_network_type == ADHOC)
712 start_net((u_long) local);
713 else
714 join_net((u_long) local);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700715} /* end verify_dl_startup */
John Daiker141fa612009-03-10 06:59:54 -0700716
Linus Torvalds1da177e2005-04-16 15:20:36 -0700717/*===========================================================================*/
718/* Command card to start a network */
719static void start_net(u_long data)
720{
John Daiker141fa612009-03-10 06:59:54 -0700721 ray_dev_t *local = (ray_dev_t *) data;
722 struct ccs __iomem *pccs;
723 int ccsindex;
724 struct pcmcia_device *link = local->finder;
725 if (!(pcmcia_dev_present(link))) {
Dominik Brodowski624dd662009-10-24 15:52:44 +0200726 dev_dbg(&link->dev, "ray_cs start_net - device not present\n");
John Daiker141fa612009-03-10 06:59:54 -0700727 return;
728 }
729 /* Fill in the CCS fields for the ECF */
730 if ((ccsindex = get_free_ccs(local)) < 0)
731 return;
732 pccs = ccs_base(local) + ccsindex;
733 writeb(CCS_START_NETWORK, &pccs->cmd);
734 writeb(0, &pccs->var.start_network.update_param);
735 /* Interrupt the firmware to process the command */
736 if (interrupt_ecf(local, ccsindex)) {
Dominik Brodowski624dd662009-10-24 15:52:44 +0200737 dev_dbg(&link->dev, "ray start net failed - card not ready for intr\n");
John Daiker141fa612009-03-10 06:59:54 -0700738 writeb(CCS_BUFFER_FREE, &(pccs++)->buffer_status);
739 return;
740 }
741 local->card_status = CARD_DOING_ACQ;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700742} /* end start_net */
John Daiker141fa612009-03-10 06:59:54 -0700743
Linus Torvalds1da177e2005-04-16 15:20:36 -0700744/*===========================================================================*/
745/* Command card to join a network */
746static void join_net(u_long data)
747{
John Daiker141fa612009-03-10 06:59:54 -0700748 ray_dev_t *local = (ray_dev_t *) data;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700749
John Daiker141fa612009-03-10 06:59:54 -0700750 struct ccs __iomem *pccs;
751 int ccsindex;
752 struct pcmcia_device *link = local->finder;
753
754 if (!(pcmcia_dev_present(link))) {
Dominik Brodowski624dd662009-10-24 15:52:44 +0200755 dev_dbg(&link->dev, "ray_cs join_net - device not present\n");
John Daiker141fa612009-03-10 06:59:54 -0700756 return;
757 }
758 /* Fill in the CCS fields for the ECF */
759 if ((ccsindex = get_free_ccs(local)) < 0)
760 return;
761 pccs = ccs_base(local) + ccsindex;
762 writeb(CCS_JOIN_NETWORK, &pccs->cmd);
763 writeb(0, &pccs->var.join_network.update_param);
764 writeb(0, &pccs->var.join_network.net_initiated);
765 /* Interrupt the firmware to process the command */
766 if (interrupt_ecf(local, ccsindex)) {
Dominik Brodowski624dd662009-10-24 15:52:44 +0200767 dev_dbg(&link->dev, "ray join net failed - card not ready for intr\n");
John Daiker141fa612009-03-10 06:59:54 -0700768 writeb(CCS_BUFFER_FREE, &(pccs++)->buffer_status);
769 return;
770 }
771 local->card_status = CARD_DOING_ACQ;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700772}
John Daiker141fa612009-03-10 06:59:54 -0700773
Linus Torvalds1da177e2005-04-16 15:20:36 -0700774/*============================================================================
775 After a card is removed, ray_release() will unregister the net
776 device, and release the PCMCIA configuration. If the device is
777 still open, this will be postponed until it is closed.
778=============================================================================*/
Dominik Brodowskifba395e2006-03-31 17:21:06 +0200779static void ray_release(struct pcmcia_device *link)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700780{
John Daiker141fa612009-03-10 06:59:54 -0700781 struct net_device *dev = link->priv;
782 ray_dev_t *local = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700783
Dominik Brodowski624dd662009-10-24 15:52:44 +0200784 dev_dbg(&link->dev, "ray_release\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700785
John Daiker141fa612009-03-10 06:59:54 -0700786 del_timer(&local->timer);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700787
John Daiker141fa612009-03-10 06:59:54 -0700788 iounmap(local->sram);
789 iounmap(local->rmem);
790 iounmap(local->amem);
John Daiker141fa612009-03-10 06:59:54 -0700791 pcmcia_disable_device(link);
792
Dominik Brodowski624dd662009-10-24 15:52:44 +0200793 dev_dbg(&link->dev, "ray_release ending\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700794}
795
Dominik Brodowskifba395e2006-03-31 17:21:06 +0200796static int ray_suspend(struct pcmcia_device *link)
Dominik Brodowski98e4c282005-11-14 21:21:18 +0100797{
Dominik Brodowski98e4c282005-11-14 21:21:18 +0100798 struct net_device *dev = link->priv;
799
Dominik Brodowskie2d40962006-03-02 00:09:29 +0100800 if (link->open)
Dominik Brodowski8661bb52006-03-02 00:02:33 +0100801 netif_device_detach(dev);
Dominik Brodowski98e4c282005-11-14 21:21:18 +0100802
803 return 0;
804}
805
Dominik Brodowskifba395e2006-03-31 17:21:06 +0200806static int ray_resume(struct pcmcia_device *link)
Dominik Brodowski98e4c282005-11-14 21:21:18 +0100807{
Dominik Brodowski98e4c282005-11-14 21:21:18 +0100808 struct net_device *dev = link->priv;
809
Dominik Brodowskie2d40962006-03-02 00:09:29 +0100810 if (link->open) {
Dominik Brodowski8661bb52006-03-02 00:02:33 +0100811 ray_reset(dev);
812 netif_device_attach(dev);
813 }
Dominik Brodowski98e4c282005-11-14 21:21:18 +0100814
815 return 0;
816}
817
Linus Torvalds1da177e2005-04-16 15:20:36 -0700818/*===========================================================================*/
Hannes Eder2ed5ba82008-12-26 00:12:59 -0800819static int ray_dev_init(struct net_device *dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700820{
821#ifdef RAY_IMMEDIATE_INIT
John Daiker141fa612009-03-10 06:59:54 -0700822 int i;
823#endif /* RAY_IMMEDIATE_INIT */
824 ray_dev_t *local = netdev_priv(dev);
825 struct pcmcia_device *link = local->finder;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700826
Dominik Brodowski624dd662009-10-24 15:52:44 +0200827 dev_dbg(&link->dev, "ray_dev_init(dev=%p)\n", dev);
John Daiker141fa612009-03-10 06:59:54 -0700828 if (!(pcmcia_dev_present(link))) {
Dominik Brodowski624dd662009-10-24 15:52:44 +0200829 dev_dbg(&link->dev, "ray_dev_init - device not present\n");
John Daiker141fa612009-03-10 06:59:54 -0700830 return -1;
831 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700832#ifdef RAY_IMMEDIATE_INIT
John Daiker141fa612009-03-10 06:59:54 -0700833 /* Download startup parameters */
834 if ((i = dl_startup_params(dev)) < 0) {
835 printk(KERN_INFO "ray_dev_init dl_startup_params failed - "
836 "returns 0x%x\n", i);
837 return -1;
838 }
839#else /* RAY_IMMEDIATE_INIT */
840 /* Postpone the card init so that we can still configure the card,
841 * for example using the Wireless Extensions. The init will happen
842 * in ray_open() - Jean II */
Dominik Brodowski624dd662009-10-24 15:52:44 +0200843 dev_dbg(&link->dev,
John Daiker141fa612009-03-10 06:59:54 -0700844 "ray_dev_init: postponing card init to ray_open() ; Status = %d\n",
845 local->card_status);
846#endif /* RAY_IMMEDIATE_INIT */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700847
John Daiker141fa612009-03-10 06:59:54 -0700848 /* copy mac and broadcast addresses to linux device */
Jiri Pirko3a6d54c2009-05-11 23:37:15 +0000849 memcpy(dev->dev_addr, &local->sparm.b4.a_mac_addr, ADDRLEN);
John Daiker141fa612009-03-10 06:59:54 -0700850 memset(dev->broadcast, 0xff, ETH_ALEN);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700851
Dominik Brodowski624dd662009-10-24 15:52:44 +0200852 dev_dbg(&link->dev, "ray_dev_init ending\n");
John Daiker141fa612009-03-10 06:59:54 -0700853 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700854}
John Daiker141fa612009-03-10 06:59:54 -0700855
Linus Torvalds1da177e2005-04-16 15:20:36 -0700856/*===========================================================================*/
857static int ray_dev_config(struct net_device *dev, struct ifmap *map)
858{
John Daiker141fa612009-03-10 06:59:54 -0700859 ray_dev_t *local = netdev_priv(dev);
860 struct pcmcia_device *link = local->finder;
861 /* Dummy routine to satisfy device structure */
Dominik Brodowski624dd662009-10-24 15:52:44 +0200862 dev_dbg(&link->dev, "ray_dev_config(dev=%p,ifmap=%p)\n", dev, map);
John Daiker141fa612009-03-10 06:59:54 -0700863 if (!(pcmcia_dev_present(link))) {
Dominik Brodowski624dd662009-10-24 15:52:44 +0200864 dev_dbg(&link->dev, "ray_dev_config - device not present\n");
John Daiker141fa612009-03-10 06:59:54 -0700865 return -1;
866 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700867
John Daiker141fa612009-03-10 06:59:54 -0700868 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700869}
John Daiker141fa612009-03-10 06:59:54 -0700870
Linus Torvalds1da177e2005-04-16 15:20:36 -0700871/*===========================================================================*/
Stephen Hemmingerd0cf9c02009-08-31 19:50:57 +0000872static netdev_tx_t ray_dev_start_xmit(struct sk_buff *skb,
873 struct net_device *dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700874{
John Daiker141fa612009-03-10 06:59:54 -0700875 ray_dev_t *local = netdev_priv(dev);
876 struct pcmcia_device *link = local->finder;
877 short length = skb->len;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700878
Stephen Hemmingerd0cf9c02009-08-31 19:50:57 +0000879 if (!pcmcia_dev_present(link)) {
Dominik Brodowski624dd662009-10-24 15:52:44 +0200880 dev_dbg(&link->dev, "ray_dev_start_xmit - device not present\n");
Stephen Hemmingerd0cf9c02009-08-31 19:50:57 +0000881 dev_kfree_skb(skb);
882 return NETDEV_TX_OK;
John Daiker141fa612009-03-10 06:59:54 -0700883 }
Stephen Hemmingerd0cf9c02009-08-31 19:50:57 +0000884
Dominik Brodowski624dd662009-10-24 15:52:44 +0200885 dev_dbg(&link->dev, "ray_dev_start_xmit(skb=%p, dev=%p)\n", skb, dev);
John Daiker141fa612009-03-10 06:59:54 -0700886 if (local->authentication_state == NEED_TO_AUTH) {
Dominik Brodowski624dd662009-10-24 15:52:44 +0200887 dev_dbg(&link->dev, "ray_cs Sending authentication request.\n");
John Daiker141fa612009-03-10 06:59:54 -0700888 if (!build_auth_frame(local, local->auth_id, OPEN_AUTH_REQUEST)) {
889 local->authentication_state = AUTHENTICATED;
890 netif_stop_queue(dev);
Patrick McHardy5b548142009-06-12 06:22:29 +0000891 return NETDEV_TX_BUSY;
John Daiker141fa612009-03-10 06:59:54 -0700892 }
893 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700894
John Daiker141fa612009-03-10 06:59:54 -0700895 if (length < ETH_ZLEN) {
896 if (skb_padto(skb, ETH_ZLEN))
Patrick McHardy6ed10652009-06-23 06:03:08 +0000897 return NETDEV_TX_OK;
John Daiker141fa612009-03-10 06:59:54 -0700898 length = ETH_ZLEN;
899 }
900 switch (ray_hw_xmit(skb->data, length, dev, DATA_TYPE)) {
901 case XMIT_NO_CCS:
902 case XMIT_NEED_AUTH:
903 netif_stop_queue(dev);
Patrick McHardy5b548142009-06-12 06:22:29 +0000904 return NETDEV_TX_BUSY;
John Daiker141fa612009-03-10 06:59:54 -0700905 case XMIT_NO_INTR:
906 case XMIT_MSG_BAD:
907 case XMIT_OK:
908 default:
John Daiker141fa612009-03-10 06:59:54 -0700909 dev_kfree_skb(skb);
John Daiker141fa612009-03-10 06:59:54 -0700910 }
Stephen Hemmingerd0cf9c02009-08-31 19:50:57 +0000911
Patrick McHardy6ed10652009-06-23 06:03:08 +0000912 return NETDEV_TX_OK;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700913} /* ray_dev_start_xmit */
John Daiker141fa612009-03-10 06:59:54 -0700914
Linus Torvalds1da177e2005-04-16 15:20:36 -0700915/*===========================================================================*/
John Daiker141fa612009-03-10 06:59:54 -0700916static int ray_hw_xmit(unsigned char *data, int len, struct net_device *dev,
917 UCHAR msg_type)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700918{
John Daiker141fa612009-03-10 06:59:54 -0700919 ray_dev_t *local = netdev_priv(dev);
920 struct ccs __iomem *pccs;
921 int ccsindex;
922 int offset;
923 struct tx_msg __iomem *ptx; /* Address of xmit buffer in PC space */
924 short int addr; /* Address of xmit buffer in card space */
925
Dominik Brodowski624dd662009-10-24 15:52:44 +0200926 pr_debug("ray_hw_xmit(data=%p, len=%d, dev=%p)\n", data, len, dev);
John Daiker141fa612009-03-10 06:59:54 -0700927 if (len + TX_HEADER_LENGTH > TX_BUF_SIZE) {
928 printk(KERN_INFO "ray_hw_xmit packet too large: %d bytes\n",
929 len);
930 return XMIT_MSG_BAD;
931 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700932 switch (ccsindex = get_free_tx_ccs(local)) {
933 case ECCSBUSY:
Dominik Brodowski624dd662009-10-24 15:52:44 +0200934 pr_debug("ray_hw_xmit tx_ccs table busy\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700935 case ECCSFULL:
Dominik Brodowski624dd662009-10-24 15:52:44 +0200936 pr_debug("ray_hw_xmit No free tx ccs\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700937 case ECARDGONE:
John Daiker141fa612009-03-10 06:59:54 -0700938 netif_stop_queue(dev);
939 return XMIT_NO_CCS;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700940 default:
941 break;
942 }
John Daiker141fa612009-03-10 06:59:54 -0700943 addr = TX_BUF_BASE + (ccsindex << 11);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700944
John Daiker141fa612009-03-10 06:59:54 -0700945 if (msg_type == DATA_TYPE) {
946 local->stats.tx_bytes += len;
947 local->stats.tx_packets++;
948 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700949
John Daiker141fa612009-03-10 06:59:54 -0700950 ptx = local->sram + addr;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700951
John Daiker141fa612009-03-10 06:59:54 -0700952 ray_build_header(local, ptx, msg_type, data);
953 if (translate) {
954 offset = translate_frame(local, ptx, data, len);
955 } else { /* Encapsulate frame */
956 /* TBD TIB length will move address of ptx->var */
957 memcpy_toio(&ptx->var, data, len);
958 offset = 0;
959 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700960
John Daiker141fa612009-03-10 06:59:54 -0700961 /* fill in the CCS */
962 pccs = ccs_base(local) + ccsindex;
963 len += TX_HEADER_LENGTH + offset;
964 writeb(CCS_TX_REQUEST, &pccs->cmd);
965 writeb(addr >> 8, &pccs->var.tx_request.tx_data_ptr[0]);
966 writeb(local->tib_length, &pccs->var.tx_request.tx_data_ptr[1]);
967 writeb(len >> 8, &pccs->var.tx_request.tx_data_length[0]);
968 writeb(len & 0xff, &pccs->var.tx_request.tx_data_length[1]);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700969/* TBD still need psm_cam? */
John Daiker141fa612009-03-10 06:59:54 -0700970 writeb(PSM_CAM, &pccs->var.tx_request.pow_sav_mode);
971 writeb(local->net_default_tx_rate, &pccs->var.tx_request.tx_rate);
972 writeb(0, &pccs->var.tx_request.antenna);
Dominik Brodowski624dd662009-10-24 15:52:44 +0200973 pr_debug("ray_hw_xmit default_tx_rate = 0x%x\n",
John Daiker141fa612009-03-10 06:59:54 -0700974 local->net_default_tx_rate);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700975
John Daiker141fa612009-03-10 06:59:54 -0700976 /* Interrupt the firmware to process the command */
977 if (interrupt_ecf(local, ccsindex)) {
Dominik Brodowski624dd662009-10-24 15:52:44 +0200978 pr_debug("ray_hw_xmit failed - ECF not ready for intr\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700979/* TBD very inefficient to copy packet to buffer, and then not
980 send it, but the alternative is to queue the messages and that
981 won't be done for a while. Maybe set tbusy until a CCS is free?
982*/
John Daiker141fa612009-03-10 06:59:54 -0700983 writeb(CCS_BUFFER_FREE, &pccs->buffer_status);
984 return XMIT_NO_INTR;
985 }
986 return XMIT_OK;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700987} /* end ray_hw_xmit */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700988
John Daiker141fa612009-03-10 06:59:54 -0700989/*===========================================================================*/
990static int translate_frame(ray_dev_t *local, struct tx_msg __iomem *ptx,
991 unsigned char *data, int len)
992{
993 __be16 proto = ((struct ethhdr *)data)->h_proto;
994 if (ntohs(proto) >= 1536) { /* DIX II ethernet frame */
Dominik Brodowski624dd662009-10-24 15:52:44 +0200995 pr_debug("ray_cs translate_frame DIX II\n");
John Daiker141fa612009-03-10 06:59:54 -0700996 /* Copy LLC header to card buffer */
997 memcpy_toio(&ptx->var, eth2_llc, sizeof(eth2_llc));
998 memcpy_toio(((void __iomem *)&ptx->var) + sizeof(eth2_llc),
999 (UCHAR *) &proto, 2);
1000 if (proto == htons(ETH_P_AARP) || proto == htons(ETH_P_IPX)) {
1001 /* This is the selective translation table, only 2 entries */
1002 writeb(0xf8,
1003 &((struct snaphdr_t __iomem *)ptx->var)->org[3]);
1004 }
1005 /* Copy body of ethernet packet without ethernet header */
1006 memcpy_toio((void __iomem *)&ptx->var +
1007 sizeof(struct snaphdr_t), data + ETH_HLEN,
1008 len - ETH_HLEN);
1009 return (int)sizeof(struct snaphdr_t) - ETH_HLEN;
1010 } else { /* already 802 type, and proto is length */
Dominik Brodowski624dd662009-10-24 15:52:44 +02001011 pr_debug("ray_cs translate_frame 802\n");
John Daiker141fa612009-03-10 06:59:54 -07001012 if (proto == htons(0xffff)) { /* evil netware IPX 802.3 without LLC */
Dominik Brodowski624dd662009-10-24 15:52:44 +02001013 pr_debug("ray_cs translate_frame evil IPX\n");
John Daiker141fa612009-03-10 06:59:54 -07001014 memcpy_toio(&ptx->var, data + ETH_HLEN, len - ETH_HLEN);
1015 return 0 - ETH_HLEN;
1016 }
1017 memcpy_toio(&ptx->var, data + ETH_HLEN, len - ETH_HLEN);
1018 return 0 - ETH_HLEN;
1019 }
1020 /* TBD do other frame types */
1021} /* end translate_frame */
1022
1023/*===========================================================================*/
1024static void ray_build_header(ray_dev_t *local, struct tx_msg __iomem *ptx,
1025 UCHAR msg_type, unsigned char *data)
1026{
1027 writeb(PROTOCOL_VER | msg_type, &ptx->mac.frame_ctl_1);
1028/*** IEEE 802.11 Address field assignments *************
1029 TODS FROMDS addr_1 addr_2 addr_3 addr_4
1030Adhoc 0 0 dest src (terminal) BSSID N/A
1031AP to Terminal 0 1 dest AP(BSSID) source N/A
1032Terminal to AP 1 0 AP(BSSID) src (terminal) dest N/A
1033AP to AP 1 1 dest AP src AP dest source
1034*******************************************************/
1035 if (local->net_type == ADHOC) {
1036 writeb(0, &ptx->mac.frame_ctl_2);
1037 memcpy_toio(ptx->mac.addr_1, ((struct ethhdr *)data)->h_dest,
1038 2 * ADDRLEN);
1039 memcpy_toio(ptx->mac.addr_3, local->bss_id, ADDRLEN);
1040 } else { /* infrastructure */
1041
1042 if (local->sparm.b4.a_acting_as_ap_status) {
1043 writeb(FC2_FROM_DS, &ptx->mac.frame_ctl_2);
1044 memcpy_toio(ptx->mac.addr_1,
1045 ((struct ethhdr *)data)->h_dest, ADDRLEN);
1046 memcpy_toio(ptx->mac.addr_2, local->bss_id, 6);
1047 memcpy_toio(ptx->mac.addr_3,
1048 ((struct ethhdr *)data)->h_source, ADDRLEN);
1049 } else { /* Terminal */
1050
1051 writeb(FC2_TO_DS, &ptx->mac.frame_ctl_2);
1052 memcpy_toio(ptx->mac.addr_1, local->bss_id, ADDRLEN);
1053 memcpy_toio(ptx->mac.addr_2,
1054 ((struct ethhdr *)data)->h_source, ADDRLEN);
1055 memcpy_toio(ptx->mac.addr_3,
1056 ((struct ethhdr *)data)->h_dest, ADDRLEN);
1057 }
1058 }
1059} /* end encapsulate_frame */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001060
Linus Torvalds1da177e2005-04-16 15:20:36 -07001061/*====================================================================*/
1062
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001063/*------------------------------------------------------------------*/
1064/*
1065 * Wireless Handler : get protocol name
1066 */
Joe Perches43ead782010-03-18 18:29:40 -07001067static int ray_get_name(struct net_device *dev, struct iw_request_info *info,
1068 union iwreq_data *wrqu, char *extra)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001069{
Joe Perches43ead782010-03-18 18:29:40 -07001070 strcpy(wrqu->name, "IEEE 802.11-FH");
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001071 return 0;
1072}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001073
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001074/*------------------------------------------------------------------*/
1075/*
1076 * Wireless Handler : set frequency
1077 */
Joe Perches43ead782010-03-18 18:29:40 -07001078static int ray_set_freq(struct net_device *dev, struct iw_request_info *info,
1079 union iwreq_data *wrqu, char *extra)
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001080{
Yoann Padioleau6dbc9c82007-08-03 19:37:16 +02001081 ray_dev_t *local = netdev_priv(dev);
John Daiker141fa612009-03-10 06:59:54 -07001082 int err = -EINPROGRESS; /* Call commit handler */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001083
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001084 /* Reject if card is already initialised */
John Daiker141fa612009-03-10 06:59:54 -07001085 if (local->card_status != CARD_AWAITING_PARAM)
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001086 return -EBUSY;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001087
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001088 /* Setting by channel number */
Joe Perches43ead782010-03-18 18:29:40 -07001089 if ((wrqu->freq.m > USA_HOP_MOD) || (wrqu->freq.e > 0))
Linus Torvalds1da177e2005-04-16 15:20:36 -07001090 err = -EOPNOTSUPP;
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001091 else
Joe Perches43ead782010-03-18 18:29:40 -07001092 local->sparm.b5.a_hop_pattern = wrqu->freq.m;
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001093
1094 return err;
1095}
John Daiker141fa612009-03-10 06:59:54 -07001096
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001097/*------------------------------------------------------------------*/
1098/*
1099 * Wireless Handler : get frequency
1100 */
Joe Perches43ead782010-03-18 18:29:40 -07001101static int ray_get_freq(struct net_device *dev, struct iw_request_info *info,
1102 union iwreq_data *wrqu, char *extra)
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001103{
Yoann Padioleau6dbc9c82007-08-03 19:37:16 +02001104 ray_dev_t *local = netdev_priv(dev);
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001105
Joe Perches43ead782010-03-18 18:29:40 -07001106 wrqu->freq.m = local->sparm.b5.a_hop_pattern;
1107 wrqu->freq.e = 0;
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001108 return 0;
1109}
1110
1111/*------------------------------------------------------------------*/
1112/*
1113 * Wireless Handler : set ESSID
1114 */
Joe Perches43ead782010-03-18 18:29:40 -07001115static int ray_set_essid(struct net_device *dev, struct iw_request_info *info,
1116 union iwreq_data *wrqu, char *extra)
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001117{
Yoann Padioleau6dbc9c82007-08-03 19:37:16 +02001118 ray_dev_t *local = netdev_priv(dev);
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001119
1120 /* Reject if card is already initialised */
John Daiker141fa612009-03-10 06:59:54 -07001121 if (local->card_status != CARD_AWAITING_PARAM)
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001122 return -EBUSY;
1123
1124 /* Check if we asked for `any' */
Joe Perches43ead782010-03-18 18:29:40 -07001125 if (wrqu->essid.flags == 0)
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001126 /* Corey : can you do that ? */
1127 return -EOPNOTSUPP;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001128
Joe Perches43ead782010-03-18 18:29:40 -07001129 /* Check the size of the string */
1130 if (wrqu->essid.length > IW_ESSID_MAX_SIZE)
1131 return -E2BIG;
1132
1133 /* Set the ESSID in the card */
1134 memset(local->sparm.b5.a_current_ess_id, 0, IW_ESSID_MAX_SIZE);
1135 memcpy(local->sparm.b5.a_current_ess_id, extra, wrqu->essid.length);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001136
John Daiker141fa612009-03-10 06:59:54 -07001137 return -EINPROGRESS; /* Call commit handler */
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001138}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001139
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001140/*------------------------------------------------------------------*/
1141/*
1142 * Wireless Handler : get ESSID
1143 */
Joe Perches43ead782010-03-18 18:29:40 -07001144static int ray_get_essid(struct net_device *dev, struct iw_request_info *info,
1145 union iwreq_data *wrqu, char *extra)
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001146{
Yoann Padioleau6dbc9c82007-08-03 19:37:16 +02001147 ray_dev_t *local = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001148
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001149 /* Get the essid that was set */
1150 memcpy(extra, local->sparm.b5.a_current_ess_id, IW_ESSID_MAX_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001151
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001152 /* Push it out ! */
Joe Perches43ead782010-03-18 18:29:40 -07001153 wrqu->essid.length = strlen(extra);
1154 wrqu->essid.flags = 1; /* active */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001155
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001156 return 0;
1157}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001158
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001159/*------------------------------------------------------------------*/
1160/*
1161 * Wireless Handler : get AP address
1162 */
Joe Perches43ead782010-03-18 18:29:40 -07001163static int ray_get_wap(struct net_device *dev, struct iw_request_info *info,
1164 union iwreq_data *wrqu, char *extra)
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001165{
Yoann Padioleau6dbc9c82007-08-03 19:37:16 +02001166 ray_dev_t *local = netdev_priv(dev);
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001167
Joe Perches43ead782010-03-18 18:29:40 -07001168 memcpy(wrqu->ap_addr.sa_data, local->bss_id, ETH_ALEN);
1169 wrqu->ap_addr.sa_family = ARPHRD_ETHER;
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001170
1171 return 0;
1172}
1173
1174/*------------------------------------------------------------------*/
1175/*
1176 * Wireless Handler : set Bit-Rate
1177 */
Joe Perches43ead782010-03-18 18:29:40 -07001178static int ray_set_rate(struct net_device *dev, struct iw_request_info *info,
1179 union iwreq_data *wrqu, char *extra)
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001180{
Yoann Padioleau6dbc9c82007-08-03 19:37:16 +02001181 ray_dev_t *local = netdev_priv(dev);
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001182
1183 /* Reject if card is already initialised */
John Daiker141fa612009-03-10 06:59:54 -07001184 if (local->card_status != CARD_AWAITING_PARAM)
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001185 return -EBUSY;
1186
1187 /* Check if rate is in range */
Joe Perches43ead782010-03-18 18:29:40 -07001188 if ((wrqu->bitrate.value != 1000000) && (wrqu->bitrate.value != 2000000))
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001189 return -EINVAL;
1190
1191 /* Hack for 1.5 Mb/s instead of 2 Mb/s */
John Daiker141fa612009-03-10 06:59:54 -07001192 if ((local->fw_ver == 0x55) && /* Please check */
Joe Perches43ead782010-03-18 18:29:40 -07001193 (wrqu->bitrate.value == 2000000))
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001194 local->net_default_tx_rate = 3;
1195 else
Joe Perches43ead782010-03-18 18:29:40 -07001196 local->net_default_tx_rate = wrqu->bitrate.value / 500000;
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001197
1198 return 0;
1199}
1200
1201/*------------------------------------------------------------------*/
1202/*
1203 * Wireless Handler : get Bit-Rate
1204 */
Joe Perches43ead782010-03-18 18:29:40 -07001205static int ray_get_rate(struct net_device *dev, struct iw_request_info *info,
1206 union iwreq_data *wrqu, char *extra)
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001207{
Yoann Padioleau6dbc9c82007-08-03 19:37:16 +02001208 ray_dev_t *local = netdev_priv(dev);
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001209
John Daiker141fa612009-03-10 06:59:54 -07001210 if (local->net_default_tx_rate == 3)
Joe Perches43ead782010-03-18 18:29:40 -07001211 wrqu->bitrate.value = 2000000; /* Hum... */
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001212 else
Joe Perches43ead782010-03-18 18:29:40 -07001213 wrqu->bitrate.value = local->net_default_tx_rate * 500000;
1214 wrqu->bitrate.fixed = 0; /* We are in auto mode */
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001215
1216 return 0;
1217}
1218
1219/*------------------------------------------------------------------*/
1220/*
1221 * Wireless Handler : set RTS threshold
1222 */
Joe Perches43ead782010-03-18 18:29:40 -07001223static int ray_set_rts(struct net_device *dev, struct iw_request_info *info,
1224 union iwreq_data *wrqu, char *extra)
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001225{
Yoann Padioleau6dbc9c82007-08-03 19:37:16 +02001226 ray_dev_t *local = netdev_priv(dev);
Joe Perches43ead782010-03-18 18:29:40 -07001227 int rthr = wrqu->rts.value;
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001228
1229 /* Reject if card is already initialised */
John Daiker141fa612009-03-10 06:59:54 -07001230 if (local->card_status != CARD_AWAITING_PARAM)
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001231 return -EBUSY;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001232
1233 /* if(wrq->u.rts.fixed == 0) we should complain */
Joe Perches43ead782010-03-18 18:29:40 -07001234 if (wrqu->rts.disabled)
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001235 rthr = 32767;
1236 else {
John Daiker141fa612009-03-10 06:59:54 -07001237 if ((rthr < 0) || (rthr > 2347)) /* What's the max packet size ??? */
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001238 return -EINVAL;
1239 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001240 local->sparm.b5.a_rts_threshold[0] = (rthr >> 8) & 0xFF;
1241 local->sparm.b5.a_rts_threshold[1] = rthr & 0xFF;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001242
John Daiker141fa612009-03-10 06:59:54 -07001243 return -EINPROGRESS; /* Call commit handler */
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001244}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001245
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001246/*------------------------------------------------------------------*/
1247/*
1248 * Wireless Handler : get RTS threshold
1249 */
Joe Perches43ead782010-03-18 18:29:40 -07001250static int ray_get_rts(struct net_device *dev, struct iw_request_info *info,
1251 union iwreq_data *wrqu, char *extra)
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001252{
Yoann Padioleau6dbc9c82007-08-03 19:37:16 +02001253 ray_dev_t *local = netdev_priv(dev);
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001254
Joe Perches43ead782010-03-18 18:29:40 -07001255 wrqu->rts.value = (local->sparm.b5.a_rts_threshold[0] << 8)
John Daiker141fa612009-03-10 06:59:54 -07001256 + local->sparm.b5.a_rts_threshold[1];
Joe Perches43ead782010-03-18 18:29:40 -07001257 wrqu->rts.disabled = (wrqu->rts.value == 32767);
1258 wrqu->rts.fixed = 1;
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001259
1260 return 0;
1261}
1262
1263/*------------------------------------------------------------------*/
1264/*
1265 * Wireless Handler : set Fragmentation threshold
1266 */
Joe Perches43ead782010-03-18 18:29:40 -07001267static int ray_set_frag(struct net_device *dev, struct iw_request_info *info,
1268 union iwreq_data *wrqu, char *extra)
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001269{
Yoann Padioleau6dbc9c82007-08-03 19:37:16 +02001270 ray_dev_t *local = netdev_priv(dev);
Joe Perches43ead782010-03-18 18:29:40 -07001271 int fthr = wrqu->frag.value;
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001272
1273 /* Reject if card is already initialised */
John Daiker141fa612009-03-10 06:59:54 -07001274 if (local->card_status != CARD_AWAITING_PARAM)
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001275 return -EBUSY;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001276
1277 /* if(wrq->u.frag.fixed == 0) should complain */
Joe Perches43ead782010-03-18 18:29:40 -07001278 if (wrqu->frag.disabled)
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001279 fthr = 32767;
1280 else {
John Daiker141fa612009-03-10 06:59:54 -07001281 if ((fthr < 256) || (fthr > 2347)) /* To check out ! */
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001282 return -EINVAL;
1283 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001284 local->sparm.b5.a_frag_threshold[0] = (fthr >> 8) & 0xFF;
1285 local->sparm.b5.a_frag_threshold[1] = fthr & 0xFF;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001286
John Daiker141fa612009-03-10 06:59:54 -07001287 return -EINPROGRESS; /* Call commit handler */
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001288}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001289
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001290/*------------------------------------------------------------------*/
1291/*
1292 * Wireless Handler : get Fragmentation threshold
1293 */
Joe Perches43ead782010-03-18 18:29:40 -07001294static int ray_get_frag(struct net_device *dev, struct iw_request_info *info,
1295 union iwreq_data *wrqu, char *extra)
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001296{
Yoann Padioleau6dbc9c82007-08-03 19:37:16 +02001297 ray_dev_t *local = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001298
Joe Perches43ead782010-03-18 18:29:40 -07001299 wrqu->frag.value = (local->sparm.b5.a_frag_threshold[0] << 8)
John Daiker141fa612009-03-10 06:59:54 -07001300 + local->sparm.b5.a_frag_threshold[1];
Joe Perches43ead782010-03-18 18:29:40 -07001301 wrqu->frag.disabled = (wrqu->frag.value == 32767);
1302 wrqu->frag.fixed = 1;
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001303
1304 return 0;
1305}
1306
1307/*------------------------------------------------------------------*/
1308/*
1309 * Wireless Handler : set Mode of Operation
1310 */
Joe Perches43ead782010-03-18 18:29:40 -07001311static int ray_set_mode(struct net_device *dev, struct iw_request_info *info,
1312 union iwreq_data *wrqu, char *extra)
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001313{
Yoann Padioleau6dbc9c82007-08-03 19:37:16 +02001314 ray_dev_t *local = netdev_priv(dev);
John Daiker141fa612009-03-10 06:59:54 -07001315 int err = -EINPROGRESS; /* Call commit handler */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001316 char card_mode = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001317
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001318 /* Reject if card is already initialised */
John Daiker141fa612009-03-10 06:59:54 -07001319 if (local->card_status != CARD_AWAITING_PARAM)
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001320 return -EBUSY;
1321
Joe Perches43ead782010-03-18 18:29:40 -07001322 switch (wrqu->mode) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001323 case IW_MODE_ADHOC:
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001324 card_mode = 0;
John Daiker141fa612009-03-10 06:59:54 -07001325 /* Fall through */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001326 case IW_MODE_INFRA:
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001327 local->sparm.b5.a_network_type = card_mode;
1328 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001329 default:
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001330 err = -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001331 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001332
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001333 return err;
1334}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001335
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001336/*------------------------------------------------------------------*/
1337/*
1338 * Wireless Handler : get Mode of Operation
1339 */
Joe Perches43ead782010-03-18 18:29:40 -07001340static int ray_get_mode(struct net_device *dev, struct iw_request_info *info,
1341 union iwreq_data *wrqu, char *extra)
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001342{
Yoann Padioleau6dbc9c82007-08-03 19:37:16 +02001343 ray_dev_t *local = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001344
John Daiker141fa612009-03-10 06:59:54 -07001345 if (local->sparm.b5.a_network_type)
Joe Perches43ead782010-03-18 18:29:40 -07001346 wrqu->mode = IW_MODE_INFRA;
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001347 else
Joe Perches43ead782010-03-18 18:29:40 -07001348 wrqu->mode = IW_MODE_ADHOC;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001349
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001350 return 0;
1351}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001352
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001353/*------------------------------------------------------------------*/
1354/*
1355 * Wireless Handler : get range info
1356 */
Joe Perches43ead782010-03-18 18:29:40 -07001357static int ray_get_range(struct net_device *dev, struct iw_request_info *info,
1358 union iwreq_data *wrqu, char *extra)
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001359{
John Daiker141fa612009-03-10 06:59:54 -07001360 struct iw_range *range = (struct iw_range *)extra;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001361
Joe Perches43ead782010-03-18 18:29:40 -07001362 memset(range, 0, sizeof(struct iw_range));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001363
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001364 /* Set the length (very important for backward compatibility) */
Joe Perches43ead782010-03-18 18:29:40 -07001365 wrqu->data.length = sizeof(struct iw_range);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001366
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001367 /* Set the Wireless Extension versions */
1368 range->we_version_compiled = WIRELESS_EXT;
1369 range->we_version_source = 9;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001370
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001371 /* Set information in the range struct */
1372 range->throughput = 1.1 * 1000 * 1000; /* Put the right number here */
John Daiker141fa612009-03-10 06:59:54 -07001373 range->num_channels = hop_pattern_length[(int)country];
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001374 range->num_frequency = 0;
1375 range->max_qual.qual = 0;
1376 range->max_qual.level = 255; /* What's the correct value ? */
1377 range->max_qual.noise = 255; /* Idem */
1378 range->num_bitrates = 2;
1379 range->bitrate[0] = 1000000; /* 1 Mb/s */
1380 range->bitrate[1] = 2000000; /* 2 Mb/s */
1381 return 0;
1382}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001383
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001384/*------------------------------------------------------------------*/
1385/*
1386 * Wireless Private Handler : set framing mode
1387 */
Joe Perches43ead782010-03-18 18:29:40 -07001388static int ray_set_framing(struct net_device *dev, struct iw_request_info *info,
John Daiker141fa612009-03-10 06:59:54 -07001389 union iwreq_data *wrqu, char *extra)
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001390{
1391 translate = *(extra); /* Set framing mode */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001392
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001393 return 0;
1394}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001395
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001396/*------------------------------------------------------------------*/
1397/*
1398 * Wireless Private Handler : get framing mode
1399 */
Joe Perches43ead782010-03-18 18:29:40 -07001400static int ray_get_framing(struct net_device *dev, struct iw_request_info *info,
John Daiker141fa612009-03-10 06:59:54 -07001401 union iwreq_data *wrqu, char *extra)
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001402{
1403 *(extra) = translate;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001404
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001405 return 0;
1406}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001407
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001408/*------------------------------------------------------------------*/
1409/*
1410 * Wireless Private Handler : get country
1411 */
Joe Perches43ead782010-03-18 18:29:40 -07001412static int ray_get_country(struct net_device *dev, struct iw_request_info *info,
John Daiker141fa612009-03-10 06:59:54 -07001413 union iwreq_data *wrqu, char *extra)
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001414{
1415 *(extra) = country;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001416
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001417 return 0;
1418}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001419
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001420/*------------------------------------------------------------------*/
1421/*
1422 * Commit handler : called after a bunch of SET operations
1423 */
Joe Perches43ead782010-03-18 18:29:40 -07001424static int ray_commit(struct net_device *dev, struct iw_request_info *info,
1425 union iwreq_data *wrqu, char *extra)
1426{
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001427 return 0;
1428}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001429
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001430/*------------------------------------------------------------------*/
1431/*
1432 * Stats handler : return Wireless Stats
1433 */
John Daiker141fa612009-03-10 06:59:54 -07001434static iw_stats *ray_get_wireless_stats(struct net_device *dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001435{
John Daiker141fa612009-03-10 06:59:54 -07001436 ray_dev_t *local = netdev_priv(dev);
1437 struct pcmcia_device *link = local->finder;
1438 struct status __iomem *p = local->sram + STATUS_BASE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001439
John Daiker141fa612009-03-10 06:59:54 -07001440 local->wstats.status = local->card_status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001441#ifdef WIRELESS_SPY
John Daiker141fa612009-03-10 06:59:54 -07001442 if ((local->spy_data.spy_number > 0)
1443 && (local->sparm.b5.a_network_type == 0)) {
1444 /* Get it from the first node in spy list */
1445 local->wstats.qual.qual = local->spy_data.spy_stat[0].qual;
1446 local->wstats.qual.level = local->spy_data.spy_stat[0].level;
1447 local->wstats.qual.noise = local->spy_data.spy_stat[0].noise;
1448 local->wstats.qual.updated =
1449 local->spy_data.spy_stat[0].updated;
1450 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001451#endif /* WIRELESS_SPY */
1452
John Daiker141fa612009-03-10 06:59:54 -07001453 if (pcmcia_dev_present(link)) {
1454 local->wstats.qual.noise = readb(&p->rxnoise);
1455 local->wstats.qual.updated |= 4;
1456 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001457
John Daiker141fa612009-03-10 06:59:54 -07001458 return &local->wstats;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001459} /* end ray_get_wireless_stats */
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001460
1461/*------------------------------------------------------------------*/
1462/*
1463 * Structures to export the Wireless Handlers
1464 */
1465
John Daiker141fa612009-03-10 06:59:54 -07001466static const iw_handler ray_handler[] = {
Joe Perches43ead782010-03-18 18:29:40 -07001467 IW_HANDLER(SIOCSIWCOMMIT, ray_commit),
1468 IW_HANDLER(SIOCGIWNAME, ray_get_name),
1469 IW_HANDLER(SIOCSIWFREQ, ray_set_freq),
1470 IW_HANDLER(SIOCGIWFREQ, ray_get_freq),
1471 IW_HANDLER(SIOCSIWMODE, ray_set_mode),
1472 IW_HANDLER(SIOCGIWMODE, ray_get_mode),
1473 IW_HANDLER(SIOCGIWRANGE, ray_get_range),
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001474#ifdef WIRELESS_SPY
Joe Perches270020e2010-03-18 18:29:37 -07001475 IW_HANDLER(SIOCSIWSPY, iw_handler_set_spy),
1476 IW_HANDLER(SIOCGIWSPY, iw_handler_get_spy),
1477 IW_HANDLER(SIOCSIWTHRSPY, iw_handler_set_thrspy),
1478 IW_HANDLER(SIOCGIWTHRSPY, iw_handler_get_thrspy),
John Daiker141fa612009-03-10 06:59:54 -07001479#endif /* WIRELESS_SPY */
Joe Perches43ead782010-03-18 18:29:40 -07001480 IW_HANDLER(SIOCGIWAP, ray_get_wap),
1481 IW_HANDLER(SIOCSIWESSID, ray_set_essid),
1482 IW_HANDLER(SIOCGIWESSID, ray_get_essid),
1483 IW_HANDLER(SIOCSIWRATE, ray_set_rate),
1484 IW_HANDLER(SIOCGIWRATE, ray_get_rate),
1485 IW_HANDLER(SIOCSIWRTS, ray_set_rts),
1486 IW_HANDLER(SIOCGIWRTS, ray_get_rts),
1487 IW_HANDLER(SIOCSIWFRAG, ray_set_frag),
1488 IW_HANDLER(SIOCGIWFRAG, ray_get_frag),
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001489};
1490
John Daiker141fa612009-03-10 06:59:54 -07001491#define SIOCSIPFRAMING SIOCIWFIRSTPRIV /* Set framing mode */
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001492#define SIOCGIPFRAMING SIOCIWFIRSTPRIV + 1 /* Get framing mode */
1493#define SIOCGIPCOUNTRY SIOCIWFIRSTPRIV + 3 /* Get country code */
1494
John Daiker141fa612009-03-10 06:59:54 -07001495static const iw_handler ray_private_handler[] = {
Joe Perches43ead782010-03-18 18:29:40 -07001496 [0] = ray_set_framing,
1497 [1] = ray_get_framing,
1498 [3] = ray_get_country,
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001499};
1500
John Daiker141fa612009-03-10 06:59:54 -07001501static const struct iw_priv_args ray_private_args[] = {
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001502/* cmd, set_args, get_args, name */
John Daiker141fa612009-03-10 06:59:54 -07001503 {SIOCSIPFRAMING, IW_PRIV_TYPE_BYTE | IW_PRIV_SIZE_FIXED | 1, 0,
1504 "set_framing"},
1505 {SIOCGIPFRAMING, 0, IW_PRIV_TYPE_BYTE | IW_PRIV_SIZE_FIXED | 1,
1506 "get_framing"},
1507 {SIOCGIPCOUNTRY, 0, IW_PRIV_TYPE_BYTE | IW_PRIV_SIZE_FIXED | 1,
1508 "get_country"},
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001509};
1510
John Daiker141fa612009-03-10 06:59:54 -07001511static const struct iw_handler_def ray_handler_def = {
1512 .num_standard = ARRAY_SIZE(ray_handler),
1513 .num_private = ARRAY_SIZE(ray_private_handler),
Denis Chengff8ac602007-09-02 18:30:18 +08001514 .num_private_args = ARRAY_SIZE(ray_private_args),
John Daiker141fa612009-03-10 06:59:54 -07001515 .standard = ray_handler,
1516 .private = ray_private_handler,
1517 .private_args = ray_private_args,
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001518 .get_wireless_stats = ray_get_wireless_stats,
1519};
1520
Linus Torvalds1da177e2005-04-16 15:20:36 -07001521/*===========================================================================*/
1522static int ray_open(struct net_device *dev)
1523{
John Daiker141fa612009-03-10 06:59:54 -07001524 ray_dev_t *local = netdev_priv(dev);
1525 struct pcmcia_device *link;
1526 link = local->finder;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001527
Dominik Brodowski624dd662009-10-24 15:52:44 +02001528 dev_dbg(&link->dev, "ray_open('%s')\n", dev->name);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001529
John Daiker141fa612009-03-10 06:59:54 -07001530 if (link->open == 0)
1531 local->num_multi = 0;
1532 link->open++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001533
John Daiker141fa612009-03-10 06:59:54 -07001534 /* If the card is not started, time to start it ! - Jean II */
1535 if (local->card_status == CARD_AWAITING_PARAM) {
1536 int i;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001537
Dominik Brodowski624dd662009-10-24 15:52:44 +02001538 dev_dbg(&link->dev, "ray_open: doing init now !\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001539
John Daiker141fa612009-03-10 06:59:54 -07001540 /* Download startup parameters */
1541 if ((i = dl_startup_params(dev)) < 0) {
1542 printk(KERN_INFO
1543 "ray_dev_init dl_startup_params failed - "
1544 "returns 0x%x\n", i);
1545 return -1;
1546 }
1547 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001548
John Daiker141fa612009-03-10 06:59:54 -07001549 if (sniffer)
1550 netif_stop_queue(dev);
1551 else
1552 netif_start_queue(dev);
1553
Dominik Brodowski624dd662009-10-24 15:52:44 +02001554 dev_dbg(&link->dev, "ray_open ending\n");
John Daiker141fa612009-03-10 06:59:54 -07001555 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001556} /* end ray_open */
John Daiker141fa612009-03-10 06:59:54 -07001557
Linus Torvalds1da177e2005-04-16 15:20:36 -07001558/*===========================================================================*/
1559static int ray_dev_close(struct net_device *dev)
1560{
John Daiker141fa612009-03-10 06:59:54 -07001561 ray_dev_t *local = netdev_priv(dev);
1562 struct pcmcia_device *link;
1563 link = local->finder;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001564
Dominik Brodowski624dd662009-10-24 15:52:44 +02001565 dev_dbg(&link->dev, "ray_dev_close('%s')\n", dev->name);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001566
John Daiker141fa612009-03-10 06:59:54 -07001567 link->open--;
1568 netif_stop_queue(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001569
John Daiker141fa612009-03-10 06:59:54 -07001570 /* In here, we should stop the hardware (stop card from beeing active)
1571 * and set local->card_status to CARD_AWAITING_PARAM, so that while the
1572 * card is closed we can chage its configuration.
1573 * Probably also need a COR reset to get sane state - Jean II */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001574
John Daiker141fa612009-03-10 06:59:54 -07001575 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001576} /* end ray_dev_close */
John Daiker141fa612009-03-10 06:59:54 -07001577
Linus Torvalds1da177e2005-04-16 15:20:36 -07001578/*===========================================================================*/
John Daiker141fa612009-03-10 06:59:54 -07001579static void ray_reset(struct net_device *dev)
1580{
Dominik Brodowski624dd662009-10-24 15:52:44 +02001581 pr_debug("ray_reset entered\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001582}
John Daiker141fa612009-03-10 06:59:54 -07001583
Linus Torvalds1da177e2005-04-16 15:20:36 -07001584/*===========================================================================*/
1585/* Cause a firmware interrupt if it is ready for one */
1586/* Return nonzero if not ready */
1587static int interrupt_ecf(ray_dev_t *local, int ccs)
1588{
John Daiker141fa612009-03-10 06:59:54 -07001589 int i = 50;
1590 struct pcmcia_device *link = local->finder;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001591
John Daiker141fa612009-03-10 06:59:54 -07001592 if (!(pcmcia_dev_present(link))) {
Dominik Brodowski624dd662009-10-24 15:52:44 +02001593 dev_dbg(&link->dev, "ray_cs interrupt_ecf - device not present\n");
John Daiker141fa612009-03-10 06:59:54 -07001594 return -1;
1595 }
Dominik Brodowski624dd662009-10-24 15:52:44 +02001596 dev_dbg(&link->dev, "interrupt_ecf(local=%p, ccs = 0x%x\n", local, ccs);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001597
John Daiker141fa612009-03-10 06:59:54 -07001598 while (i &&
1599 (readb(local->amem + CIS_OFFSET + ECF_INTR_OFFSET) &
1600 ECF_INTR_SET))
1601 i--;
1602 if (i == 0) {
Dominik Brodowski624dd662009-10-24 15:52:44 +02001603 dev_dbg(&link->dev, "ray_cs interrupt_ecf card not ready for interrupt\n");
John Daiker141fa612009-03-10 06:59:54 -07001604 return -1;
1605 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001606 /* Fill the mailbox, then kick the card */
John Daiker141fa612009-03-10 06:59:54 -07001607 writeb(ccs, local->sram + SCB_BASE);
1608 writeb(ECF_INTR_SET, local->amem + CIS_OFFSET + ECF_INTR_OFFSET);
1609 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001610} /* interrupt_ecf */
John Daiker141fa612009-03-10 06:59:54 -07001611
Linus Torvalds1da177e2005-04-16 15:20:36 -07001612/*===========================================================================*/
1613/* Get next free transmit CCS */
1614/* Return - index of current tx ccs */
1615static int get_free_tx_ccs(ray_dev_t *local)
1616{
John Daiker141fa612009-03-10 06:59:54 -07001617 int i;
1618 struct ccs __iomem *pccs = ccs_base(local);
1619 struct pcmcia_device *link = local->finder;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001620
John Daiker141fa612009-03-10 06:59:54 -07001621 if (!(pcmcia_dev_present(link))) {
Dominik Brodowski624dd662009-10-24 15:52:44 +02001622 dev_dbg(&link->dev, "ray_cs get_free_tx_ccs - device not present\n");
John Daiker141fa612009-03-10 06:59:54 -07001623 return ECARDGONE;
1624 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001625
John Daiker141fa612009-03-10 06:59:54 -07001626 if (test_and_set_bit(0, &local->tx_ccs_lock)) {
Dominik Brodowski624dd662009-10-24 15:52:44 +02001627 dev_dbg(&link->dev, "ray_cs tx_ccs_lock busy\n");
John Daiker141fa612009-03-10 06:59:54 -07001628 return ECCSBUSY;
1629 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001630
John Daiker141fa612009-03-10 06:59:54 -07001631 for (i = 0; i < NUMBER_OF_TX_CCS; i++) {
1632 if (readb(&(pccs + i)->buffer_status) == CCS_BUFFER_FREE) {
1633 writeb(CCS_BUFFER_BUSY, &(pccs + i)->buffer_status);
1634 writeb(CCS_END_LIST, &(pccs + i)->link);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001635 local->tx_ccs_lock = 0;
John Daiker141fa612009-03-10 06:59:54 -07001636 return i;
1637 }
1638 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001639 local->tx_ccs_lock = 0;
Dominik Brodowski624dd662009-10-24 15:52:44 +02001640 dev_dbg(&link->dev, "ray_cs ERROR no free tx CCS for raylink card\n");
John Daiker141fa612009-03-10 06:59:54 -07001641 return ECCSFULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001642} /* get_free_tx_ccs */
John Daiker141fa612009-03-10 06:59:54 -07001643
Linus Torvalds1da177e2005-04-16 15:20:36 -07001644/*===========================================================================*/
1645/* Get next free CCS */
1646/* Return - index of current ccs */
1647static int get_free_ccs(ray_dev_t *local)
1648{
John Daiker141fa612009-03-10 06:59:54 -07001649 int i;
1650 struct ccs __iomem *pccs = ccs_base(local);
1651 struct pcmcia_device *link = local->finder;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001652
John Daiker141fa612009-03-10 06:59:54 -07001653 if (!(pcmcia_dev_present(link))) {
Dominik Brodowski624dd662009-10-24 15:52:44 +02001654 dev_dbg(&link->dev, "ray_cs get_free_ccs - device not present\n");
John Daiker141fa612009-03-10 06:59:54 -07001655 return ECARDGONE;
1656 }
1657 if (test_and_set_bit(0, &local->ccs_lock)) {
Dominik Brodowski624dd662009-10-24 15:52:44 +02001658 dev_dbg(&link->dev, "ray_cs ccs_lock busy\n");
John Daiker141fa612009-03-10 06:59:54 -07001659 return ECCSBUSY;
1660 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001661
John Daiker141fa612009-03-10 06:59:54 -07001662 for (i = NUMBER_OF_TX_CCS; i < NUMBER_OF_CCS; i++) {
1663 if (readb(&(pccs + i)->buffer_status) == CCS_BUFFER_FREE) {
1664 writeb(CCS_BUFFER_BUSY, &(pccs + i)->buffer_status);
1665 writeb(CCS_END_LIST, &(pccs + i)->link);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001666 local->ccs_lock = 0;
John Daiker141fa612009-03-10 06:59:54 -07001667 return i;
1668 }
1669 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001670 local->ccs_lock = 0;
Dominik Brodowski624dd662009-10-24 15:52:44 +02001671 dev_dbg(&link->dev, "ray_cs ERROR no free CCS for raylink card\n");
John Daiker141fa612009-03-10 06:59:54 -07001672 return ECCSFULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001673} /* get_free_ccs */
John Daiker141fa612009-03-10 06:59:54 -07001674
Linus Torvalds1da177e2005-04-16 15:20:36 -07001675/*===========================================================================*/
1676static void authenticate_timeout(u_long data)
1677{
John Daiker141fa612009-03-10 06:59:54 -07001678 ray_dev_t *local = (ray_dev_t *) data;
1679 del_timer(&local->timer);
1680 printk(KERN_INFO "ray_cs Authentication with access point failed"
1681 " - timeout\n");
1682 join_net((u_long) local);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001683}
John Daiker141fa612009-03-10 06:59:54 -07001684
Linus Torvalds1da177e2005-04-16 15:20:36 -07001685/*===========================================================================*/
Linus Torvalds1da177e2005-04-16 15:20:36 -07001686static int parse_addr(char *in_str, UCHAR *out)
1687{
John Daiker141fa612009-03-10 06:59:54 -07001688 int len;
1689 int i, j, k;
1690 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001691
John Daiker141fa612009-03-10 06:59:54 -07001692 if (in_str == NULL)
1693 return 0;
1694 if ((len = strlen(in_str)) < 2)
1695 return 0;
1696 memset(out, 0, ADDRLEN);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001697
John Daiker141fa612009-03-10 06:59:54 -07001698 status = 1;
1699 j = len - 1;
1700 if (j > 12)
1701 j = 12;
1702 i = 5;
1703
1704 while (j > 0) {
Andy Shevchenko882d8292010-07-23 03:18:09 +00001705 if ((k = hex_to_bin(in_str[j--])) != -1)
John Daiker141fa612009-03-10 06:59:54 -07001706 out[i] = k;
1707 else
1708 return 0;
1709
1710 if (j == 0)
1711 break;
Andy Shevchenko882d8292010-07-23 03:18:09 +00001712 if ((k = hex_to_bin(in_str[j--])) != -1)
John Daiker141fa612009-03-10 06:59:54 -07001713 out[i] += k << 4;
1714 else
1715 return 0;
1716 if (!i--)
1717 break;
1718 }
1719 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001720}
John Daiker141fa612009-03-10 06:59:54 -07001721
Linus Torvalds1da177e2005-04-16 15:20:36 -07001722/*===========================================================================*/
1723static struct net_device_stats *ray_get_stats(struct net_device *dev)
1724{
John Daiker141fa612009-03-10 06:59:54 -07001725 ray_dev_t *local = netdev_priv(dev);
1726 struct pcmcia_device *link = local->finder;
1727 struct status __iomem *p = local->sram + STATUS_BASE;
1728 if (!(pcmcia_dev_present(link))) {
Dominik Brodowski624dd662009-10-24 15:52:44 +02001729 dev_dbg(&link->dev, "ray_cs net_device_stats - device not present\n");
John Daiker141fa612009-03-10 06:59:54 -07001730 return &local->stats;
1731 }
1732 if (readb(&p->mrx_overflow_for_host)) {
1733 local->stats.rx_over_errors += swab16(readw(&p->mrx_overflow));
1734 writeb(0, &p->mrx_overflow);
1735 writeb(0, &p->mrx_overflow_for_host);
1736 }
1737 if (readb(&p->mrx_checksum_error_for_host)) {
1738 local->stats.rx_crc_errors +=
1739 swab16(readw(&p->mrx_checksum_error));
1740 writeb(0, &p->mrx_checksum_error);
1741 writeb(0, &p->mrx_checksum_error_for_host);
1742 }
1743 if (readb(&p->rx_hec_error_for_host)) {
1744 local->stats.rx_frame_errors += swab16(readw(&p->rx_hec_error));
1745 writeb(0, &p->rx_hec_error);
1746 writeb(0, &p->rx_hec_error_for_host);
1747 }
1748 return &local->stats;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001749}
John Daiker141fa612009-03-10 06:59:54 -07001750
Linus Torvalds1da177e2005-04-16 15:20:36 -07001751/*===========================================================================*/
John Daiker141fa612009-03-10 06:59:54 -07001752static void ray_update_parm(struct net_device *dev, UCHAR objid, UCHAR *value,
1753 int len)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001754{
John Daiker141fa612009-03-10 06:59:54 -07001755 ray_dev_t *local = netdev_priv(dev);
1756 struct pcmcia_device *link = local->finder;
1757 int ccsindex;
1758 int i;
1759 struct ccs __iomem *pccs;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001760
John Daiker141fa612009-03-10 06:59:54 -07001761 if (!(pcmcia_dev_present(link))) {
Dominik Brodowski624dd662009-10-24 15:52:44 +02001762 dev_dbg(&link->dev, "ray_update_parm - device not present\n");
John Daiker141fa612009-03-10 06:59:54 -07001763 return;
1764 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001765
John Daiker141fa612009-03-10 06:59:54 -07001766 if ((ccsindex = get_free_ccs(local)) < 0) {
Dominik Brodowski624dd662009-10-24 15:52:44 +02001767 dev_dbg(&link->dev, "ray_update_parm - No free ccs\n");
John Daiker141fa612009-03-10 06:59:54 -07001768 return;
1769 }
1770 pccs = ccs_base(local) + ccsindex;
1771 writeb(CCS_UPDATE_PARAMS, &pccs->cmd);
1772 writeb(objid, &pccs->var.update_param.object_id);
1773 writeb(1, &pccs->var.update_param.number_objects);
1774 writeb(0, &pccs->var.update_param.failure_cause);
1775 for (i = 0; i < len; i++) {
1776 writeb(value[i], local->sram + HOST_TO_ECF_BASE);
1777 }
1778 /* Interrupt the firmware to process the command */
1779 if (interrupt_ecf(local, ccsindex)) {
Dominik Brodowski624dd662009-10-24 15:52:44 +02001780 dev_dbg(&link->dev, "ray_cs associate failed - ECF not ready for intr\n");
John Daiker141fa612009-03-10 06:59:54 -07001781 writeb(CCS_BUFFER_FREE, &(pccs++)->buffer_status);
1782 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001783}
John Daiker141fa612009-03-10 06:59:54 -07001784
Linus Torvalds1da177e2005-04-16 15:20:36 -07001785/*===========================================================================*/
1786static void ray_update_multi_list(struct net_device *dev, int all)
1787{
John Daiker141fa612009-03-10 06:59:54 -07001788 int ccsindex;
1789 struct ccs __iomem *pccs;
John Daiker141fa612009-03-10 06:59:54 -07001790 ray_dev_t *local = netdev_priv(dev);
1791 struct pcmcia_device *link = local->finder;
1792 void __iomem *p = local->sram + HOST_TO_ECF_BASE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001793
John Daiker141fa612009-03-10 06:59:54 -07001794 if (!(pcmcia_dev_present(link))) {
Dominik Brodowski624dd662009-10-24 15:52:44 +02001795 dev_dbg(&link->dev, "ray_update_multi_list - device not present\n");
John Daiker141fa612009-03-10 06:59:54 -07001796 return;
1797 } else
Dominik Brodowski624dd662009-10-24 15:52:44 +02001798 dev_dbg(&link->dev, "ray_update_multi_list(%p)\n", dev);
John Daiker141fa612009-03-10 06:59:54 -07001799 if ((ccsindex = get_free_ccs(local)) < 0) {
Dominik Brodowski624dd662009-10-24 15:52:44 +02001800 dev_dbg(&link->dev, "ray_update_multi - No free ccs\n");
John Daiker141fa612009-03-10 06:59:54 -07001801 return;
1802 }
1803 pccs = ccs_base(local) + ccsindex;
1804 writeb(CCS_UPDATE_MULTICAST_LIST, &pccs->cmd);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001805
John Daiker141fa612009-03-10 06:59:54 -07001806 if (all) {
1807 writeb(0xff, &pccs->var);
1808 local->num_multi = 0xff;
1809 } else {
Jiri Pirko22bedad32010-04-01 21:22:57 +00001810 struct netdev_hw_addr *ha;
Jiri Pirko655ffee2010-02-27 07:35:45 +00001811 int i = 0;
1812
John Daiker141fa612009-03-10 06:59:54 -07001813 /* Copy the kernel's list of MC addresses to card */
Jiri Pirko22bedad32010-04-01 21:22:57 +00001814 netdev_for_each_mc_addr(ha, dev) {
1815 memcpy_toio(p, ha->addr, ETH_ALEN);
Dominik Brodowski624dd662009-10-24 15:52:44 +02001816 dev_dbg(&link->dev,
John Daiker141fa612009-03-10 06:59:54 -07001817 "ray_update_multi add addr %02x%02x%02x%02x%02x%02x\n",
Jiri Pirko22bedad32010-04-01 21:22:57 +00001818 ha->addr[0], ha->addr[1],
1819 ha->addr[2], ha->addr[3],
1820 ha->addr[4], ha->addr[5]);
John Daiker141fa612009-03-10 06:59:54 -07001821 p += ETH_ALEN;
1822 i++;
1823 }
1824 if (i > 256 / ADDRLEN)
1825 i = 256 / ADDRLEN;
1826 writeb((UCHAR) i, &pccs->var);
Dominik Brodowski624dd662009-10-24 15:52:44 +02001827 dev_dbg(&link->dev, "ray_cs update_multi %d addresses in list\n", i);
John Daiker141fa612009-03-10 06:59:54 -07001828 /* Interrupt the firmware to process the command */
1829 local->num_multi = i;
1830 }
1831 if (interrupt_ecf(local, ccsindex)) {
Dominik Brodowski624dd662009-10-24 15:52:44 +02001832 dev_dbg(&link->dev,
John Daiker141fa612009-03-10 06:59:54 -07001833 "ray_cs update_multi failed - ECF not ready for intr\n");
1834 writeb(CCS_BUFFER_FREE, &(pccs++)->buffer_status);
1835 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001836} /* end ray_update_multi_list */
John Daiker141fa612009-03-10 06:59:54 -07001837
Linus Torvalds1da177e2005-04-16 15:20:36 -07001838/*===========================================================================*/
1839static void set_multicast_list(struct net_device *dev)
1840{
John Daiker141fa612009-03-10 06:59:54 -07001841 ray_dev_t *local = netdev_priv(dev);
1842 UCHAR promisc;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001843
Dominik Brodowski624dd662009-10-24 15:52:44 +02001844 pr_debug("ray_cs set_multicast_list(%p)\n", dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001845
John Daiker141fa612009-03-10 06:59:54 -07001846 if (dev->flags & IFF_PROMISC) {
1847 if (local->sparm.b5.a_promiscuous_mode == 0) {
Dominik Brodowski624dd662009-10-24 15:52:44 +02001848 pr_debug("ray_cs set_multicast_list promisc on\n");
John Daiker141fa612009-03-10 06:59:54 -07001849 local->sparm.b5.a_promiscuous_mode = 1;
1850 promisc = 1;
1851 ray_update_parm(dev, OBJID_promiscuous_mode,
1852 &promisc, sizeof(promisc));
1853 }
1854 } else {
1855 if (local->sparm.b5.a_promiscuous_mode == 1) {
Dominik Brodowski624dd662009-10-24 15:52:44 +02001856 pr_debug("ray_cs set_multicast_list promisc off\n");
John Daiker141fa612009-03-10 06:59:54 -07001857 local->sparm.b5.a_promiscuous_mode = 0;
1858 promisc = 0;
1859 ray_update_parm(dev, OBJID_promiscuous_mode,
1860 &promisc, sizeof(promisc));
1861 }
1862 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001863
John Daiker141fa612009-03-10 06:59:54 -07001864 if (dev->flags & IFF_ALLMULTI)
1865 ray_update_multi_list(dev, 1);
1866 else {
Jiri Pirko4cd24ea2010-02-08 04:30:35 +00001867 if (local->num_multi != netdev_mc_count(dev))
John Daiker141fa612009-03-10 06:59:54 -07001868 ray_update_multi_list(dev, 0);
1869 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001870} /* end set_multicast_list */
John Daiker141fa612009-03-10 06:59:54 -07001871
Linus Torvalds1da177e2005-04-16 15:20:36 -07001872/*=============================================================================
1873 * All routines below here are run at interrupt time.
1874=============================================================================*/
David Howells7d12e782006-10-05 14:55:46 +01001875static irqreturn_t ray_interrupt(int irq, void *dev_id)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001876{
John Daiker141fa612009-03-10 06:59:54 -07001877 struct net_device *dev = (struct net_device *)dev_id;
1878 struct pcmcia_device *link;
1879 ray_dev_t *local;
1880 struct ccs __iomem *pccs;
1881 struct rcs __iomem *prcs;
1882 UCHAR rcsindex;
1883 UCHAR tmp;
1884 UCHAR cmd;
1885 UCHAR status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001886
John Daiker141fa612009-03-10 06:59:54 -07001887 if (dev == NULL) /* Note that we want interrupts with dev->start == 0 */
1888 return IRQ_NONE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001889
Dominik Brodowski624dd662009-10-24 15:52:44 +02001890 pr_debug("ray_cs: interrupt for *dev=%p\n", dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001891
John Daiker141fa612009-03-10 06:59:54 -07001892 local = netdev_priv(dev);
1893 link = (struct pcmcia_device *)local->finder;
1894 if (!pcmcia_dev_present(link)) {
Dominik Brodowski624dd662009-10-24 15:52:44 +02001895 pr_debug(
1896 "ray_cs interrupt from device not present or suspended.\n");
John Daiker141fa612009-03-10 06:59:54 -07001897 return IRQ_NONE;
1898 }
1899 rcsindex = readb(&((struct scb __iomem *)(local->sram))->rcs_index);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001900
John Daiker141fa612009-03-10 06:59:54 -07001901 if (rcsindex >= (NUMBER_OF_CCS + NUMBER_OF_RCS)) {
Dominik Brodowski624dd662009-10-24 15:52:44 +02001902 dev_dbg(&link->dev, "ray_cs interrupt bad rcsindex = 0x%x\n", rcsindex);
John Daiker141fa612009-03-10 06:59:54 -07001903 clear_interrupt(local);
1904 return IRQ_HANDLED;
1905 }
1906 if (rcsindex < NUMBER_OF_CCS) { /* If it's a returned CCS */
1907 pccs = ccs_base(local) + rcsindex;
1908 cmd = readb(&pccs->cmd);
1909 status = readb(&pccs->buffer_status);
1910 switch (cmd) {
1911 case CCS_DOWNLOAD_STARTUP_PARAMS: /* Happens in firmware someday */
1912 del_timer(&local->timer);
1913 if (status == CCS_COMMAND_COMPLETE) {
Dominik Brodowski624dd662009-10-24 15:52:44 +02001914 dev_dbg(&link->dev,
John Daiker141fa612009-03-10 06:59:54 -07001915 "ray_cs interrupt download_startup_parameters OK\n");
1916 } else {
Dominik Brodowski624dd662009-10-24 15:52:44 +02001917 dev_dbg(&link->dev,
John Daiker141fa612009-03-10 06:59:54 -07001918 "ray_cs interrupt download_startup_parameters fail\n");
1919 }
1920 break;
1921 case CCS_UPDATE_PARAMS:
Dominik Brodowski624dd662009-10-24 15:52:44 +02001922 dev_dbg(&link->dev, "ray_cs interrupt update params done\n");
John Daiker141fa612009-03-10 06:59:54 -07001923 if (status != CCS_COMMAND_COMPLETE) {
1924 tmp =
1925 readb(&pccs->var.update_param.
1926 failure_cause);
Dominik Brodowski624dd662009-10-24 15:52:44 +02001927 dev_dbg(&link->dev,
John Daiker141fa612009-03-10 06:59:54 -07001928 "ray_cs interrupt update params failed - reason %d\n",
1929 tmp);
1930 }
1931 break;
1932 case CCS_REPORT_PARAMS:
Dominik Brodowski624dd662009-10-24 15:52:44 +02001933 dev_dbg(&link->dev, "ray_cs interrupt report params done\n");
John Daiker141fa612009-03-10 06:59:54 -07001934 break;
1935 case CCS_UPDATE_MULTICAST_LIST: /* Note that this CCS isn't returned */
Dominik Brodowski624dd662009-10-24 15:52:44 +02001936 dev_dbg(&link->dev,
John Daiker141fa612009-03-10 06:59:54 -07001937 "ray_cs interrupt CCS Update Multicast List done\n");
1938 break;
1939 case CCS_UPDATE_POWER_SAVINGS_MODE:
Dominik Brodowski624dd662009-10-24 15:52:44 +02001940 dev_dbg(&link->dev,
John Daiker141fa612009-03-10 06:59:54 -07001941 "ray_cs interrupt update power save mode done\n");
1942 break;
1943 case CCS_START_NETWORK:
1944 case CCS_JOIN_NETWORK:
1945 if (status == CCS_COMMAND_COMPLETE) {
1946 if (readb
1947 (&pccs->var.start_network.net_initiated) ==
1948 1) {
Dominik Brodowski624dd662009-10-24 15:52:44 +02001949 dev_dbg(&link->dev,
John Daiker141fa612009-03-10 06:59:54 -07001950 "ray_cs interrupt network \"%s\" started\n",
1951 local->sparm.b4.a_current_ess_id);
1952 } else {
Dominik Brodowski624dd662009-10-24 15:52:44 +02001953 dev_dbg(&link->dev,
John Daiker141fa612009-03-10 06:59:54 -07001954 "ray_cs interrupt network \"%s\" joined\n",
1955 local->sparm.b4.a_current_ess_id);
1956 }
1957 memcpy_fromio(&local->bss_id,
1958 pccs->var.start_network.bssid,
1959 ADDRLEN);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001960
John Daiker141fa612009-03-10 06:59:54 -07001961 if (local->fw_ver == 0x55)
1962 local->net_default_tx_rate = 3;
1963 else
1964 local->net_default_tx_rate =
1965 readb(&pccs->var.start_network.
1966 net_default_tx_rate);
1967 local->encryption =
1968 readb(&pccs->var.start_network.encryption);
1969 if (!sniffer && (local->net_type == INFRA)
1970 && !(local->sparm.b4.a_acting_as_ap_status)) {
1971 authenticate(local);
1972 }
1973 local->card_status = CARD_ACQ_COMPLETE;
1974 } else {
1975 local->card_status = CARD_ACQ_FAILED;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001976
John Daiker141fa612009-03-10 06:59:54 -07001977 del_timer(&local->timer);
1978 local->timer.expires = jiffies + HZ * 5;
1979 local->timer.data = (long)local;
1980 if (status == CCS_START_NETWORK) {
Dominik Brodowski624dd662009-10-24 15:52:44 +02001981 dev_dbg(&link->dev,
John Daiker141fa612009-03-10 06:59:54 -07001982 "ray_cs interrupt network \"%s\" start failed\n",
1983 local->sparm.b4.a_current_ess_id);
Joe Perchesc061b182010-08-23 18:20:03 +00001984 local->timer.function = start_net;
John Daiker141fa612009-03-10 06:59:54 -07001985 } else {
Dominik Brodowski624dd662009-10-24 15:52:44 +02001986 dev_dbg(&link->dev,
John Daiker141fa612009-03-10 06:59:54 -07001987 "ray_cs interrupt network \"%s\" join failed\n",
1988 local->sparm.b4.a_current_ess_id);
Joe Perchesc061b182010-08-23 18:20:03 +00001989 local->timer.function = join_net;
John Daiker141fa612009-03-10 06:59:54 -07001990 }
1991 add_timer(&local->timer);
1992 }
1993 break;
1994 case CCS_START_ASSOCIATION:
1995 if (status == CCS_COMMAND_COMPLETE) {
1996 local->card_status = CARD_ASSOC_COMPLETE;
Dominik Brodowski624dd662009-10-24 15:52:44 +02001997 dev_dbg(&link->dev, "ray_cs association successful\n");
John Daiker141fa612009-03-10 06:59:54 -07001998 } else {
Dominik Brodowski624dd662009-10-24 15:52:44 +02001999 dev_dbg(&link->dev, "ray_cs association failed,\n");
John Daiker141fa612009-03-10 06:59:54 -07002000 local->card_status = CARD_ASSOC_FAILED;
2001 join_net((u_long) local);
2002 }
2003 break;
2004 case CCS_TX_REQUEST:
2005 if (status == CCS_COMMAND_COMPLETE) {
Dominik Brodowski624dd662009-10-24 15:52:44 +02002006 dev_dbg(&link->dev,
John Daiker141fa612009-03-10 06:59:54 -07002007 "ray_cs interrupt tx request complete\n");
2008 } else {
Dominik Brodowski624dd662009-10-24 15:52:44 +02002009 dev_dbg(&link->dev,
John Daiker141fa612009-03-10 06:59:54 -07002010 "ray_cs interrupt tx request failed\n");
2011 }
2012 if (!sniffer)
2013 netif_start_queue(dev);
2014 netif_wake_queue(dev);
2015 break;
2016 case CCS_TEST_MEMORY:
Dominik Brodowski624dd662009-10-24 15:52:44 +02002017 dev_dbg(&link->dev, "ray_cs interrupt mem test done\n");
John Daiker141fa612009-03-10 06:59:54 -07002018 break;
2019 case CCS_SHUTDOWN:
Dominik Brodowski624dd662009-10-24 15:52:44 +02002020 dev_dbg(&link->dev,
John Daiker141fa612009-03-10 06:59:54 -07002021 "ray_cs interrupt Unexpected CCS returned - Shutdown\n");
2022 break;
2023 case CCS_DUMP_MEMORY:
Dominik Brodowski624dd662009-10-24 15:52:44 +02002024 dev_dbg(&link->dev, "ray_cs interrupt dump memory done\n");
John Daiker141fa612009-03-10 06:59:54 -07002025 break;
2026 case CCS_START_TIMER:
Dominik Brodowski624dd662009-10-24 15:52:44 +02002027 dev_dbg(&link->dev,
John Daiker141fa612009-03-10 06:59:54 -07002028 "ray_cs interrupt DING - raylink timer expired\n");
2029 break;
2030 default:
Dominik Brodowski624dd662009-10-24 15:52:44 +02002031 dev_dbg(&link->dev,
John Daiker141fa612009-03-10 06:59:54 -07002032 "ray_cs interrupt Unexpected CCS 0x%x returned 0x%x\n",
2033 rcsindex, cmd);
2034 }
2035 writeb(CCS_BUFFER_FREE, &pccs->buffer_status);
2036 } else { /* It's an RCS */
2037
2038 prcs = rcs_base(local) + rcsindex;
2039
2040 switch (readb(&prcs->interrupt_id)) {
2041 case PROCESS_RX_PACKET:
2042 ray_rx(dev, local, prcs);
2043 break;
2044 case REJOIN_NET_COMPLETE:
Dominik Brodowski624dd662009-10-24 15:52:44 +02002045 dev_dbg(&link->dev, "ray_cs interrupt rejoin net complete\n");
John Daiker141fa612009-03-10 06:59:54 -07002046 local->card_status = CARD_ACQ_COMPLETE;
2047 /* do we need to clear tx buffers CCS's? */
2048 if (local->sparm.b4.a_network_type == ADHOC) {
2049 if (!sniffer)
2050 netif_start_queue(dev);
2051 } else {
2052 memcpy_fromio(&local->bss_id,
2053 prcs->var.rejoin_net_complete.
2054 bssid, ADDRLEN);
Dominik Brodowski624dd662009-10-24 15:52:44 +02002055 dev_dbg(&link->dev,
John Daiker141fa612009-03-10 06:59:54 -07002056 "ray_cs new BSSID = %02x%02x%02x%02x%02x%02x\n",
2057 local->bss_id[0], local->bss_id[1],
2058 local->bss_id[2], local->bss_id[3],
2059 local->bss_id[4], local->bss_id[5]);
2060 if (!sniffer)
2061 authenticate(local);
2062 }
2063 break;
2064 case ROAMING_INITIATED:
Dominik Brodowski624dd662009-10-24 15:52:44 +02002065 dev_dbg(&link->dev, "ray_cs interrupt roaming initiated\n");
John Daiker141fa612009-03-10 06:59:54 -07002066 netif_stop_queue(dev);
2067 local->card_status = CARD_DOING_ACQ;
2068 break;
2069 case JAPAN_CALL_SIGN_RXD:
Dominik Brodowski624dd662009-10-24 15:52:44 +02002070 dev_dbg(&link->dev, "ray_cs interrupt japan call sign rx\n");
John Daiker141fa612009-03-10 06:59:54 -07002071 break;
2072 default:
Dominik Brodowski624dd662009-10-24 15:52:44 +02002073 dev_dbg(&link->dev,
John Daiker141fa612009-03-10 06:59:54 -07002074 "ray_cs Unexpected interrupt for RCS 0x%x cmd = 0x%x\n",
2075 rcsindex,
2076 (unsigned int)readb(&prcs->interrupt_id));
2077 break;
2078 }
2079 writeb(CCS_BUFFER_FREE, &prcs->buffer_status);
2080 }
2081 clear_interrupt(local);
2082 return IRQ_HANDLED;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002083} /* ray_interrupt */
John Daiker141fa612009-03-10 06:59:54 -07002084
Linus Torvalds1da177e2005-04-16 15:20:36 -07002085/*===========================================================================*/
John Daiker141fa612009-03-10 06:59:54 -07002086static void ray_rx(struct net_device *dev, ray_dev_t *local,
2087 struct rcs __iomem *prcs)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002088{
John Daiker141fa612009-03-10 06:59:54 -07002089 int rx_len;
2090 unsigned int pkt_addr;
2091 void __iomem *pmsg;
Dominik Brodowski624dd662009-10-24 15:52:44 +02002092 pr_debug("ray_rx process rx packet\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002093
John Daiker141fa612009-03-10 06:59:54 -07002094 /* Calculate address of packet within Rx buffer */
2095 pkt_addr = ((readb(&prcs->var.rx_packet.rx_data_ptr[0]) << 8)
2096 + readb(&prcs->var.rx_packet.rx_data_ptr[1])) & RX_BUFF_END;
2097 /* Length of first packet fragment */
2098 rx_len = (readb(&prcs->var.rx_packet.rx_data_length[0]) << 8)
2099 + readb(&prcs->var.rx_packet.rx_data_length[1]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002100
John Daiker141fa612009-03-10 06:59:54 -07002101 local->last_rsl = readb(&prcs->var.rx_packet.rx_sig_lev);
2102 pmsg = local->rmem + pkt_addr;
2103 switch (readb(pmsg)) {
2104 case DATA_TYPE:
Dominik Brodowski624dd662009-10-24 15:52:44 +02002105 pr_debug("ray_rx data type\n");
John Daiker141fa612009-03-10 06:59:54 -07002106 rx_data(dev, prcs, pkt_addr, rx_len);
2107 break;
2108 case AUTHENTIC_TYPE:
Dominik Brodowski624dd662009-10-24 15:52:44 +02002109 pr_debug("ray_rx authentic type\n");
John Daiker141fa612009-03-10 06:59:54 -07002110 if (sniffer)
2111 rx_data(dev, prcs, pkt_addr, rx_len);
2112 else
2113 rx_authenticate(local, prcs, pkt_addr, rx_len);
2114 break;
2115 case DEAUTHENTIC_TYPE:
Dominik Brodowski624dd662009-10-24 15:52:44 +02002116 pr_debug("ray_rx deauth type\n");
John Daiker141fa612009-03-10 06:59:54 -07002117 if (sniffer)
2118 rx_data(dev, prcs, pkt_addr, rx_len);
2119 else
2120 rx_deauthenticate(local, prcs, pkt_addr, rx_len);
2121 break;
2122 case NULL_MSG_TYPE:
Dominik Brodowski624dd662009-10-24 15:52:44 +02002123 pr_debug("ray_cs rx NULL msg\n");
John Daiker141fa612009-03-10 06:59:54 -07002124 break;
2125 case BEACON_TYPE:
Dominik Brodowski624dd662009-10-24 15:52:44 +02002126 pr_debug("ray_rx beacon type\n");
John Daiker141fa612009-03-10 06:59:54 -07002127 if (sniffer)
2128 rx_data(dev, prcs, pkt_addr, rx_len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002129
John Daiker141fa612009-03-10 06:59:54 -07002130 copy_from_rx_buff(local, (UCHAR *) &local->last_bcn, pkt_addr,
2131 rx_len < sizeof(struct beacon_rx) ?
2132 rx_len : sizeof(struct beacon_rx));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002133
John Daiker141fa612009-03-10 06:59:54 -07002134 local->beacon_rxed = 1;
2135 /* Get the statistics so the card counters never overflow */
2136 ray_get_stats(dev);
2137 break;
2138 default:
Dominik Brodowski624dd662009-10-24 15:52:44 +02002139 pr_debug("ray_cs unknown pkt type %2x\n",
John Daiker141fa612009-03-10 06:59:54 -07002140 (unsigned int)readb(pmsg));
2141 break;
2142 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002143
2144} /* end ray_rx */
John Daiker141fa612009-03-10 06:59:54 -07002145
Linus Torvalds1da177e2005-04-16 15:20:36 -07002146/*===========================================================================*/
John Daiker141fa612009-03-10 06:59:54 -07002147static void rx_data(struct net_device *dev, struct rcs __iomem *prcs,
2148 unsigned int pkt_addr, int rx_len)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002149{
John Daiker141fa612009-03-10 06:59:54 -07002150 struct sk_buff *skb = NULL;
2151 struct rcs __iomem *prcslink = prcs;
2152 ray_dev_t *local = netdev_priv(dev);
2153 UCHAR *rx_ptr;
2154 int total_len;
2155 int tmp;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002156#ifdef WIRELESS_SPY
John Daiker141fa612009-03-10 06:59:54 -07002157 int siglev = local->last_rsl;
2158 u_char linksrcaddr[ETH_ALEN]; /* Other end of the wireless link */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002159#endif
2160
John Daiker141fa612009-03-10 06:59:54 -07002161 if (!sniffer) {
2162 if (translate) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002163/* TBD length needs fixing for translated header */
John Daiker141fa612009-03-10 06:59:54 -07002164 if (rx_len < (ETH_HLEN + RX_MAC_HEADER_LENGTH) ||
2165 rx_len >
2166 (dev->mtu + RX_MAC_HEADER_LENGTH + ETH_HLEN +
2167 FCS_LEN)) {
Dominik Brodowski624dd662009-10-24 15:52:44 +02002168 pr_debug(
Frans Popcb01b092010-03-24 19:46:34 +01002169 "ray_cs invalid packet length %d received\n",
John Daiker141fa612009-03-10 06:59:54 -07002170 rx_len);
2171 return;
2172 }
2173 } else { /* encapsulated ethernet */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002174
John Daiker141fa612009-03-10 06:59:54 -07002175 if (rx_len < (ETH_HLEN + RX_MAC_HEADER_LENGTH) ||
2176 rx_len >
2177 (dev->mtu + RX_MAC_HEADER_LENGTH + ETH_HLEN +
2178 FCS_LEN)) {
Dominik Brodowski624dd662009-10-24 15:52:44 +02002179 pr_debug(
Frans Popcb01b092010-03-24 19:46:34 +01002180 "ray_cs invalid packet length %d received\n",
John Daiker141fa612009-03-10 06:59:54 -07002181 rx_len);
2182 return;
2183 }
2184 }
2185 }
Dominik Brodowski624dd662009-10-24 15:52:44 +02002186 pr_debug("ray_cs rx_data packet\n");
John Daiker141fa612009-03-10 06:59:54 -07002187 /* If fragmented packet, verify sizes of fragments add up */
2188 if (readb(&prcs->var.rx_packet.next_frag_rcs_index) != 0xFF) {
Dominik Brodowski624dd662009-10-24 15:52:44 +02002189 pr_debug("ray_cs rx'ed fragment\n");
John Daiker141fa612009-03-10 06:59:54 -07002190 tmp = (readb(&prcs->var.rx_packet.totalpacketlength[0]) << 8)
2191 + readb(&prcs->var.rx_packet.totalpacketlength[1]);
2192 total_len = tmp;
2193 prcslink = prcs;
2194 do {
2195 tmp -=
2196 (readb(&prcslink->var.rx_packet.rx_data_length[0])
2197 << 8)
2198 + readb(&prcslink->var.rx_packet.rx_data_length[1]);
2199 if (readb(&prcslink->var.rx_packet.next_frag_rcs_index)
2200 == 0xFF || tmp < 0)
2201 break;
2202 prcslink = rcs_base(local)
2203 + readb(&prcslink->link_field);
2204 } while (1);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002205
John Daiker141fa612009-03-10 06:59:54 -07002206 if (tmp < 0) {
Dominik Brodowski624dd662009-10-24 15:52:44 +02002207 pr_debug(
John Daiker141fa612009-03-10 06:59:54 -07002208 "ray_cs rx_data fragment lengths don't add up\n");
2209 local->stats.rx_dropped++;
2210 release_frag_chain(local, prcs);
2211 return;
2212 }
2213 } else { /* Single unfragmented packet */
2214 total_len = rx_len;
2215 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002216
John Daiker141fa612009-03-10 06:59:54 -07002217 skb = dev_alloc_skb(total_len + 5);
2218 if (skb == NULL) {
Dominik Brodowski624dd662009-10-24 15:52:44 +02002219 pr_debug("ray_cs rx_data could not allocate skb\n");
John Daiker141fa612009-03-10 06:59:54 -07002220 local->stats.rx_dropped++;
2221 if (readb(&prcs->var.rx_packet.next_frag_rcs_index) != 0xFF)
2222 release_frag_chain(local, prcs);
2223 return;
2224 }
2225 skb_reserve(skb, 2); /* Align IP on 16 byte (TBD check this) */
2226
Dominik Brodowski624dd662009-10-24 15:52:44 +02002227 pr_debug("ray_cs rx_data total_len = %x, rx_len = %x\n", total_len,
John Daiker141fa612009-03-10 06:59:54 -07002228 rx_len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002229
2230/************************/
John Daiker141fa612009-03-10 06:59:54 -07002231 /* Reserve enough room for the whole damn packet. */
2232 rx_ptr = skb_put(skb, total_len);
2233 /* Copy the whole packet to sk_buff */
2234 rx_ptr +=
2235 copy_from_rx_buff(local, rx_ptr, pkt_addr & RX_BUFF_END, rx_len);
2236 /* Get source address */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002237#ifdef WIRELESS_SPY
John Daiker141fa612009-03-10 06:59:54 -07002238 skb_copy_from_linear_data_offset(skb,
2239 offsetof(struct mac_header, addr_2),
2240 linksrcaddr, ETH_ALEN);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002241#endif
John Daiker141fa612009-03-10 06:59:54 -07002242 /* Now, deal with encapsulation/translation/sniffer */
2243 if (!sniffer) {
2244 if (!translate) {
2245 /* Encapsulated ethernet, so just lop off 802.11 MAC header */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002246/* TBD reserve skb_reserve( skb, RX_MAC_HEADER_LENGTH); */
John Daiker141fa612009-03-10 06:59:54 -07002247 skb_pull(skb, RX_MAC_HEADER_LENGTH);
2248 } else {
2249 /* Do translation */
2250 untranslate(local, skb, total_len);
2251 }
2252 } else { /* sniffer mode, so just pass whole packet */
2253 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002254
2255/************************/
John Daiker141fa612009-03-10 06:59:54 -07002256 /* Now pick up the rest of the fragments if any */
2257 tmp = 17;
2258 if (readb(&prcs->var.rx_packet.next_frag_rcs_index) != 0xFF) {
2259 prcslink = prcs;
Dominik Brodowski624dd662009-10-24 15:52:44 +02002260 pr_debug("ray_cs rx_data in fragment loop\n");
John Daiker141fa612009-03-10 06:59:54 -07002261 do {
2262 prcslink = rcs_base(local)
2263 +
2264 readb(&prcslink->var.rx_packet.next_frag_rcs_index);
2265 rx_len =
2266 ((readb(&prcslink->var.rx_packet.rx_data_length[0])
2267 << 8)
2268 +
2269 readb(&prcslink->var.rx_packet.rx_data_length[1]))
2270 & RX_BUFF_END;
2271 pkt_addr =
2272 ((readb(&prcslink->var.rx_packet.rx_data_ptr[0]) <<
2273 8)
2274 + readb(&prcslink->var.rx_packet.rx_data_ptr[1]))
2275 & RX_BUFF_END;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002276
John Daiker141fa612009-03-10 06:59:54 -07002277 rx_ptr +=
2278 copy_from_rx_buff(local, rx_ptr, pkt_addr, rx_len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002279
John Daiker141fa612009-03-10 06:59:54 -07002280 } while (tmp-- &&
2281 readb(&prcslink->var.rx_packet.next_frag_rcs_index) !=
2282 0xFF);
2283 release_frag_chain(local, prcs);
2284 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002285
John Daiker141fa612009-03-10 06:59:54 -07002286 skb->protocol = eth_type_trans(skb, dev);
2287 netif_rx(skb);
2288 local->stats.rx_packets++;
2289 local->stats.rx_bytes += total_len;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002290
John Daiker141fa612009-03-10 06:59:54 -07002291 /* Gather signal strength per address */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002292#ifdef WIRELESS_SPY
John Daiker141fa612009-03-10 06:59:54 -07002293 /* For the Access Point or the node having started the ad-hoc net
2294 * note : ad-hoc work only in some specific configurations, but we
2295 * kludge in ray_get_wireless_stats... */
2296 if (!memcmp(linksrcaddr, local->bss_id, ETH_ALEN)) {
2297 /* Update statistics */
2298 /*local->wstats.qual.qual = none ? */
2299 local->wstats.qual.level = siglev;
2300 /*local->wstats.qual.noise = none ? */
2301 local->wstats.qual.updated = 0x2;
2302 }
2303 /* Now, update the spy stuff */
2304 {
2305 struct iw_quality wstats;
2306 wstats.level = siglev;
2307 /* wstats.noise = none ? */
2308 /* wstats.qual = none ? */
2309 wstats.updated = 0x2;
2310 /* Update spy records */
2311 wireless_spy_update(dev, linksrcaddr, &wstats);
2312 }
2313#endif /* WIRELESS_SPY */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002314} /* end rx_data */
John Daiker141fa612009-03-10 06:59:54 -07002315
Linus Torvalds1da177e2005-04-16 15:20:36 -07002316/*===========================================================================*/
2317static void untranslate(ray_dev_t *local, struct sk_buff *skb, int len)
2318{
John Daiker141fa612009-03-10 06:59:54 -07002319 snaphdr_t *psnap = (snaphdr_t *) (skb->data + RX_MAC_HEADER_LENGTH);
2320 struct ieee80211_hdr *pmac = (struct ieee80211_hdr *)skb->data;
2321 __be16 type = *(__be16 *) psnap->ethertype;
2322 int delta;
2323 struct ethhdr *peth;
2324 UCHAR srcaddr[ADDRLEN];
2325 UCHAR destaddr[ADDRLEN];
2326 static UCHAR org_bridge[3] = { 0, 0, 0xf8 };
2327 static UCHAR org_1042[3] = { 0, 0, 0 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002328
John Daiker141fa612009-03-10 06:59:54 -07002329 memcpy(destaddr, ieee80211_get_DA(pmac), ADDRLEN);
2330 memcpy(srcaddr, ieee80211_get_SA(pmac), ADDRLEN);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002331
Dominik Brodowski624dd662009-10-24 15:52:44 +02002332#if 0
2333 if {
Joe Perchesad361c92009-07-06 13:05:40 -07002334 print_hex_dump(KERN_DEBUG, "skb->data before untranslate: ",
2335 DUMP_PREFIX_NONE, 16, 1,
2336 skb->data, 64, true);
2337 printk(KERN_DEBUG
John Daiker141fa612009-03-10 06:59:54 -07002338 "type = %08x, xsap = %02x%02x%02x, org = %02x02x02x\n",
2339 ntohs(type), psnap->dsap, psnap->ssap, psnap->ctrl,
2340 psnap->org[0], psnap->org[1], psnap->org[2]);
2341 printk(KERN_DEBUG "untranslate skb->data = %p\n", skb->data);
2342 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002343#endif
2344
John Daiker141fa612009-03-10 06:59:54 -07002345 if (psnap->dsap != 0xaa || psnap->ssap != 0xaa || psnap->ctrl != 3) {
2346 /* not a snap type so leave it alone */
Dominik Brodowski624dd662009-10-24 15:52:44 +02002347 pr_debug("ray_cs untranslate NOT SNAP %02x %02x %02x\n",
John Daiker141fa612009-03-10 06:59:54 -07002348 psnap->dsap, psnap->ssap, psnap->ctrl);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002349
John Daiker141fa612009-03-10 06:59:54 -07002350 delta = RX_MAC_HEADER_LENGTH - ETH_HLEN;
2351 peth = (struct ethhdr *)(skb->data + delta);
2352 peth->h_proto = htons(len - RX_MAC_HEADER_LENGTH);
2353 } else { /* Its a SNAP */
2354 if (memcmp(psnap->org, org_bridge, 3) == 0) {
2355 /* EtherII and nuke the LLC */
Dominik Brodowski624dd662009-10-24 15:52:44 +02002356 pr_debug("ray_cs untranslate Bridge encap\n");
John Daiker141fa612009-03-10 06:59:54 -07002357 delta = RX_MAC_HEADER_LENGTH
2358 + sizeof(struct snaphdr_t) - ETH_HLEN;
2359 peth = (struct ethhdr *)(skb->data + delta);
2360 peth->h_proto = type;
2361 } else if (memcmp(psnap->org, org_1042, 3) == 0) {
2362 switch (ntohs(type)) {
2363 case ETH_P_IPX:
2364 case ETH_P_AARP:
Dominik Brodowski624dd662009-10-24 15:52:44 +02002365 pr_debug("ray_cs untranslate RFC IPX/AARP\n");
John Daiker141fa612009-03-10 06:59:54 -07002366 delta = RX_MAC_HEADER_LENGTH - ETH_HLEN;
2367 peth = (struct ethhdr *)(skb->data + delta);
2368 peth->h_proto =
2369 htons(len - RX_MAC_HEADER_LENGTH);
2370 break;
2371 default:
Dominik Brodowski624dd662009-10-24 15:52:44 +02002372 pr_debug("ray_cs untranslate RFC default\n");
John Daiker141fa612009-03-10 06:59:54 -07002373 delta = RX_MAC_HEADER_LENGTH +
2374 sizeof(struct snaphdr_t) - ETH_HLEN;
2375 peth = (struct ethhdr *)(skb->data + delta);
2376 peth->h_proto = type;
2377 break;
2378 }
2379 } else {
2380 printk("ray_cs untranslate very confused by packet\n");
2381 delta = RX_MAC_HEADER_LENGTH - ETH_HLEN;
2382 peth = (struct ethhdr *)(skb->data + delta);
2383 peth->h_proto = type;
2384 }
Al Viro7698d692007-12-29 04:55:50 -05002385 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002386/* TBD reserve skb_reserve(skb, delta); */
John Daiker141fa612009-03-10 06:59:54 -07002387 skb_pull(skb, delta);
Dominik Brodowski624dd662009-10-24 15:52:44 +02002388 pr_debug("untranslate after skb_pull(%d), skb->data = %p\n", delta,
John Daiker141fa612009-03-10 06:59:54 -07002389 skb->data);
2390 memcpy(peth->h_dest, destaddr, ADDRLEN);
2391 memcpy(peth->h_source, srcaddr, ADDRLEN);
Dominik Brodowski624dd662009-10-24 15:52:44 +02002392#if 0
2393 {
John Daiker141fa612009-03-10 06:59:54 -07002394 int i;
2395 printk(KERN_DEBUG "skb->data after untranslate:");
2396 for (i = 0; i < 64; i++)
2397 printk("%02x ", skb->data[i]);
2398 printk("\n");
2399 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002400#endif
2401} /* end untranslate */
John Daiker141fa612009-03-10 06:59:54 -07002402
Linus Torvalds1da177e2005-04-16 15:20:36 -07002403/*===========================================================================*/
2404/* Copy data from circular receive buffer to PC memory.
2405 * dest = destination address in PC memory
2406 * pkt_addr = source address in receive buffer
2407 * len = length of packet to copy
2408 */
John Daiker141fa612009-03-10 06:59:54 -07002409static int copy_from_rx_buff(ray_dev_t *local, UCHAR *dest, int pkt_addr,
2410 int length)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002411{
John Daiker141fa612009-03-10 06:59:54 -07002412 int wrap_bytes = (pkt_addr + length) - (RX_BUFF_END + 1);
2413 if (wrap_bytes <= 0) {
2414 memcpy_fromio(dest, local->rmem + pkt_addr, length);
2415 } else { /* Packet wrapped in circular buffer */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002416
John Daiker141fa612009-03-10 06:59:54 -07002417 memcpy_fromio(dest, local->rmem + pkt_addr,
2418 length - wrap_bytes);
2419 memcpy_fromio(dest + length - wrap_bytes, local->rmem,
2420 wrap_bytes);
2421 }
2422 return length;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002423}
John Daiker141fa612009-03-10 06:59:54 -07002424
2425/*===========================================================================*/
2426static void release_frag_chain(ray_dev_t *local, struct rcs __iomem *prcs)
2427{
2428 struct rcs __iomem *prcslink = prcs;
2429 int tmp = 17;
2430 unsigned rcsindex = readb(&prcs->var.rx_packet.next_frag_rcs_index);
2431
2432 while (tmp--) {
2433 writeb(CCS_BUFFER_FREE, &prcslink->buffer_status);
2434 if (rcsindex >= (NUMBER_OF_CCS + NUMBER_OF_RCS)) {
Dominik Brodowski624dd662009-10-24 15:52:44 +02002435 pr_debug("ray_cs interrupt bad rcsindex = 0x%x\n",
John Daiker141fa612009-03-10 06:59:54 -07002436 rcsindex);
2437 break;
2438 }
2439 prcslink = rcs_base(local) + rcsindex;
2440 rcsindex = readb(&prcslink->var.rx_packet.next_frag_rcs_index);
2441 }
2442 writeb(CCS_BUFFER_FREE, &prcslink->buffer_status);
2443}
2444
Linus Torvalds1da177e2005-04-16 15:20:36 -07002445/*===========================================================================*/
2446static void authenticate(ray_dev_t *local)
2447{
John Daiker141fa612009-03-10 06:59:54 -07002448 struct pcmcia_device *link = local->finder;
Dominik Brodowski624dd662009-10-24 15:52:44 +02002449 dev_dbg(&link->dev, "ray_cs Starting authentication.\n");
John Daiker141fa612009-03-10 06:59:54 -07002450 if (!(pcmcia_dev_present(link))) {
Dominik Brodowski624dd662009-10-24 15:52:44 +02002451 dev_dbg(&link->dev, "ray_cs authenticate - device not present\n");
John Daiker141fa612009-03-10 06:59:54 -07002452 return;
2453 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002454
John Daiker141fa612009-03-10 06:59:54 -07002455 del_timer(&local->timer);
2456 if (build_auth_frame(local, local->bss_id, OPEN_AUTH_REQUEST)) {
Joe Perchesc061b182010-08-23 18:20:03 +00002457 local->timer.function = join_net;
John Daiker141fa612009-03-10 06:59:54 -07002458 } else {
Joe Perchesc061b182010-08-23 18:20:03 +00002459 local->timer.function = authenticate_timeout;
John Daiker141fa612009-03-10 06:59:54 -07002460 }
2461 local->timer.expires = jiffies + HZ * 2;
2462 local->timer.data = (long)local;
2463 add_timer(&local->timer);
2464 local->authentication_state = AWAITING_RESPONSE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002465} /* end authenticate */
John Daiker141fa612009-03-10 06:59:54 -07002466
Linus Torvalds1da177e2005-04-16 15:20:36 -07002467/*===========================================================================*/
2468static void rx_authenticate(ray_dev_t *local, struct rcs __iomem *prcs,
John Daiker141fa612009-03-10 06:59:54 -07002469 unsigned int pkt_addr, int rx_len)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002470{
John Daiker141fa612009-03-10 06:59:54 -07002471 UCHAR buff[256];
2472 struct rx_msg *msg = (struct rx_msg *)buff;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002473
John Daiker141fa612009-03-10 06:59:54 -07002474 del_timer(&local->timer);
2475
2476 copy_from_rx_buff(local, buff, pkt_addr, rx_len & 0xff);
2477 /* if we are trying to get authenticated */
2478 if (local->sparm.b4.a_network_type == ADHOC) {
Dominik Brodowski624dd662009-10-24 15:52:44 +02002479 pr_debug("ray_cs rx_auth var= %02x %02x %02x %02x %02x %02x\n",
John Daiker141fa612009-03-10 06:59:54 -07002480 msg->var[0], msg->var[1], msg->var[2], msg->var[3],
2481 msg->var[4], msg->var[5]);
2482 if (msg->var[2] == 1) {
Dominik Brodowski624dd662009-10-24 15:52:44 +02002483 pr_debug("ray_cs Sending authentication response.\n");
John Daiker141fa612009-03-10 06:59:54 -07002484 if (!build_auth_frame
2485 (local, msg->mac.addr_2, OPEN_AUTH_RESPONSE)) {
2486 local->authentication_state = NEED_TO_AUTH;
2487 memcpy(local->auth_id, msg->mac.addr_2,
2488 ADDRLEN);
2489 }
2490 }
2491 } else { /* Infrastructure network */
2492
2493 if (local->authentication_state == AWAITING_RESPONSE) {
2494 /* Verify authentication sequence #2 and success */
2495 if (msg->var[2] == 2) {
2496 if ((msg->var[3] | msg->var[4]) == 0) {
Dominik Brodowski624dd662009-10-24 15:52:44 +02002497 pr_debug("Authentication successful\n");
John Daiker141fa612009-03-10 06:59:54 -07002498 local->card_status = CARD_AUTH_COMPLETE;
2499 associate(local);
2500 local->authentication_state =
2501 AUTHENTICATED;
2502 } else {
Dominik Brodowski624dd662009-10-24 15:52:44 +02002503 pr_debug("Authentication refused\n");
John Daiker141fa612009-03-10 06:59:54 -07002504 local->card_status = CARD_AUTH_REFUSED;
2505 join_net((u_long) local);
2506 local->authentication_state =
2507 UNAUTHENTICATED;
2508 }
2509 }
2510 }
2511 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002512
2513} /* end rx_authenticate */
John Daiker141fa612009-03-10 06:59:54 -07002514
Linus Torvalds1da177e2005-04-16 15:20:36 -07002515/*===========================================================================*/
2516static void associate(ray_dev_t *local)
2517{
John Daiker141fa612009-03-10 06:59:54 -07002518 struct ccs __iomem *pccs;
2519 struct pcmcia_device *link = local->finder;
2520 struct net_device *dev = link->priv;
2521 int ccsindex;
2522 if (!(pcmcia_dev_present(link))) {
Dominik Brodowski624dd662009-10-24 15:52:44 +02002523 dev_dbg(&link->dev, "ray_cs associate - device not present\n");
John Daiker141fa612009-03-10 06:59:54 -07002524 return;
2525 }
2526 /* If no tx buffers available, return */
2527 if ((ccsindex = get_free_ccs(local)) < 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002528/* TBD should never be here but... what if we are? */
Dominik Brodowski624dd662009-10-24 15:52:44 +02002529 dev_dbg(&link->dev, "ray_cs associate - No free ccs\n");
John Daiker141fa612009-03-10 06:59:54 -07002530 return;
2531 }
Dominik Brodowski624dd662009-10-24 15:52:44 +02002532 dev_dbg(&link->dev, "ray_cs Starting association with access point\n");
John Daiker141fa612009-03-10 06:59:54 -07002533 pccs = ccs_base(local) + ccsindex;
2534 /* fill in the CCS */
2535 writeb(CCS_START_ASSOCIATION, &pccs->cmd);
2536 /* Interrupt the firmware to process the command */
2537 if (interrupt_ecf(local, ccsindex)) {
Dominik Brodowski624dd662009-10-24 15:52:44 +02002538 dev_dbg(&link->dev, "ray_cs associate failed - ECF not ready for intr\n");
John Daiker141fa612009-03-10 06:59:54 -07002539 writeb(CCS_BUFFER_FREE, &(pccs++)->buffer_status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002540
John Daiker141fa612009-03-10 06:59:54 -07002541 del_timer(&local->timer);
2542 local->timer.expires = jiffies + HZ * 2;
2543 local->timer.data = (long)local;
Joe Perchesc061b182010-08-23 18:20:03 +00002544 local->timer.function = join_net;
John Daiker141fa612009-03-10 06:59:54 -07002545 add_timer(&local->timer);
2546 local->card_status = CARD_ASSOC_FAILED;
2547 return;
2548 }
2549 if (!sniffer)
2550 netif_start_queue(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002551
2552} /* end associate */
John Daiker141fa612009-03-10 06:59:54 -07002553
Linus Torvalds1da177e2005-04-16 15:20:36 -07002554/*===========================================================================*/
John Daiker141fa612009-03-10 06:59:54 -07002555static void rx_deauthenticate(ray_dev_t *local, struct rcs __iomem *prcs,
2556 unsigned int pkt_addr, int rx_len)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002557{
2558/* UCHAR buff[256];
2559 struct rx_msg *msg = (struct rx_msg *)buff;
2560*/
Dominik Brodowski624dd662009-10-24 15:52:44 +02002561 pr_debug("Deauthentication frame received\n");
John Daiker141fa612009-03-10 06:59:54 -07002562 local->authentication_state = UNAUTHENTICATED;
2563 /* Need to reauthenticate or rejoin depending on reason code */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002564/* copy_from_rx_buff(local, buff, pkt_addr, rx_len & 0xff);
2565 */
2566}
John Daiker141fa612009-03-10 06:59:54 -07002567
Linus Torvalds1da177e2005-04-16 15:20:36 -07002568/*===========================================================================*/
2569static void clear_interrupt(ray_dev_t *local)
2570{
John Daiker141fa612009-03-10 06:59:54 -07002571 writeb(0, local->amem + CIS_OFFSET + HCS_INTR_OFFSET);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002572}
John Daiker141fa612009-03-10 06:59:54 -07002573
Linus Torvalds1da177e2005-04-16 15:20:36 -07002574/*===========================================================================*/
2575#ifdef CONFIG_PROC_FS
2576#define MAXDATA (PAGE_SIZE - 80)
2577
2578static char *card_status[] = {
John Daiker141fa612009-03-10 06:59:54 -07002579 "Card inserted - uninitialized", /* 0 */
2580 "Card not downloaded", /* 1 */
2581 "Waiting for download parameters", /* 2 */
2582 "Card doing acquisition", /* 3 */
2583 "Acquisition complete", /* 4 */
2584 "Authentication complete", /* 5 */
2585 "Association complete", /* 6 */
2586 "???", "???", "???", "???", /* 7 8 9 10 undefined */
2587 "Card init error", /* 11 */
2588 "Download parameters error", /* 12 */
2589 "???", /* 13 */
2590 "Acquisition failed", /* 14 */
2591 "Authentication refused", /* 15 */
2592 "Association failed" /* 16 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002593};
2594
John Daiker141fa612009-03-10 06:59:54 -07002595static char *nettype[] = { "Adhoc", "Infra " };
2596static char *framing[] = { "Encapsulation", "Translation" }
2597
Linus Torvalds1da177e2005-04-16 15:20:36 -07002598;
2599/*===========================================================================*/
Alexey Dobriyan6b914c52008-04-10 14:34:35 -07002600static int ray_cs_proc_show(struct seq_file *m, void *v)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002601{
2602/* Print current values which are not available via other means
John Daiker141fa612009-03-10 06:59:54 -07002603 * eg ifconfig
Linus Torvalds1da177e2005-04-16 15:20:36 -07002604 */
John Daiker141fa612009-03-10 06:59:54 -07002605 int i;
2606 struct pcmcia_device *link;
2607 struct net_device *dev;
2608 ray_dev_t *local;
2609 UCHAR *p;
2610 struct freq_hop_element *pfh;
2611 UCHAR c[33];
Linus Torvalds1da177e2005-04-16 15:20:36 -07002612
John Daiker141fa612009-03-10 06:59:54 -07002613 link = this_device;
2614 if (!link)
2615 return 0;
2616 dev = (struct net_device *)link->priv;
2617 if (!dev)
2618 return 0;
2619 local = netdev_priv(dev);
2620 if (!local)
2621 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002622
John Daiker141fa612009-03-10 06:59:54 -07002623 seq_puts(m, "Raylink Wireless LAN driver status\n");
2624 seq_printf(m, "%s\n", rcsid);
2625 /* build 4 does not report version, and field is 0x55 after memtest */
2626 seq_puts(m, "Firmware version = ");
2627 if (local->fw_ver == 0x55)
2628 seq_puts(m, "4 - Use dump_cis for more details\n");
2629 else
2630 seq_printf(m, "%2d.%02d.%02d\n",
2631 local->fw_ver, local->fw_bld, local->fw_var);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002632
John Daiker141fa612009-03-10 06:59:54 -07002633 for (i = 0; i < 32; i++)
2634 c[i] = local->sparm.b5.a_current_ess_id[i];
2635 c[32] = 0;
2636 seq_printf(m, "%s network ESSID = \"%s\"\n",
2637 nettype[local->sparm.b5.a_network_type], c);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002638
John Daiker141fa612009-03-10 06:59:54 -07002639 p = local->bss_id;
2640 seq_printf(m, "BSSID = %pM\n", p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002641
John Daiker141fa612009-03-10 06:59:54 -07002642 seq_printf(m, "Country code = %d\n",
2643 local->sparm.b5.a_curr_country_code);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002644
John Daiker141fa612009-03-10 06:59:54 -07002645 i = local->card_status;
2646 if (i < 0)
2647 i = 10;
2648 if (i > 16)
2649 i = 10;
2650 seq_printf(m, "Card status = %s\n", card_status[i]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002651
John Daiker141fa612009-03-10 06:59:54 -07002652 seq_printf(m, "Framing mode = %s\n", framing[translate]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002653
John Daiker141fa612009-03-10 06:59:54 -07002654 seq_printf(m, "Last pkt signal lvl = %d\n", local->last_rsl);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002655
John Daiker141fa612009-03-10 06:59:54 -07002656 if (local->beacon_rxed) {
2657 /* Pull some fields out of last beacon received */
2658 seq_printf(m, "Beacon Interval = %d Kus\n",
2659 local->last_bcn.beacon_intvl[0]
2660 + 256 * local->last_bcn.beacon_intvl[1]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002661
John Daiker141fa612009-03-10 06:59:54 -07002662 p = local->last_bcn.elements;
2663 if (p[0] == C_ESSID_ELEMENT_ID)
2664 p += p[1] + 2;
2665 else {
2666 seq_printf(m,
2667 "Parse beacon failed at essid element id = %d\n",
2668 p[0]);
2669 return 0;
2670 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002671
John Daiker141fa612009-03-10 06:59:54 -07002672 if (p[0] == C_SUPPORTED_RATES_ELEMENT_ID) {
2673 seq_puts(m, "Supported rate codes = ");
2674 for (i = 2; i < p[1] + 2; i++)
2675 seq_printf(m, "0x%02x ", p[i]);
2676 seq_putc(m, '\n');
2677 p += p[1] + 2;
2678 } else {
2679 seq_puts(m, "Parse beacon failed at rates element\n");
2680 return 0;
2681 }
2682
2683 if (p[0] == C_FH_PARAM_SET_ELEMENT_ID) {
2684 pfh = (struct freq_hop_element *)p;
2685 seq_printf(m, "Hop dwell = %d Kus\n",
2686 pfh->dwell_time[0] +
2687 256 * pfh->dwell_time[1]);
Frans Popcb01b092010-03-24 19:46:34 +01002688 seq_printf(m, "Hop set = %d\n",
John Daiker141fa612009-03-10 06:59:54 -07002689 pfh->hop_set);
Frans Popcb01b092010-03-24 19:46:34 +01002690 seq_printf(m, "Hop pattern = %d\n",
John Daiker141fa612009-03-10 06:59:54 -07002691 pfh->hop_pattern);
Frans Popcb01b092010-03-24 19:46:34 +01002692 seq_printf(m, "Hop index = %d\n",
John Daiker141fa612009-03-10 06:59:54 -07002693 pfh->hop_index);
2694 p += p[1] + 2;
2695 } else {
2696 seq_puts(m,
2697 "Parse beacon failed at FH param element\n");
2698 return 0;
2699 }
2700 } else {
2701 seq_puts(m, "No beacons received\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002702 }
John Daiker141fa612009-03-10 06:59:54 -07002703 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002704}
2705
Alexey Dobriyan6b914c52008-04-10 14:34:35 -07002706static int ray_cs_proc_open(struct inode *inode, struct file *file)
2707{
2708 return single_open(file, ray_cs_proc_show, NULL);
2709}
2710
2711static const struct file_operations ray_cs_proc_fops = {
John Daiker141fa612009-03-10 06:59:54 -07002712 .owner = THIS_MODULE,
2713 .open = ray_cs_proc_open,
2714 .read = seq_read,
2715 .llseek = seq_lseek,
2716 .release = single_release,
Alexey Dobriyan6b914c52008-04-10 14:34:35 -07002717};
Linus Torvalds1da177e2005-04-16 15:20:36 -07002718#endif
2719/*===========================================================================*/
2720static int build_auth_frame(ray_dev_t *local, UCHAR *dest, int auth_type)
2721{
John Daiker141fa612009-03-10 06:59:54 -07002722 int addr;
2723 struct ccs __iomem *pccs;
2724 struct tx_msg __iomem *ptx;
2725 int ccsindex;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002726
John Daiker141fa612009-03-10 06:59:54 -07002727 /* If no tx buffers available, return */
2728 if ((ccsindex = get_free_tx_ccs(local)) < 0) {
Dominik Brodowski624dd662009-10-24 15:52:44 +02002729 pr_debug("ray_cs send authenticate - No free tx ccs\n");
John Daiker141fa612009-03-10 06:59:54 -07002730 return -1;
2731 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002732
John Daiker141fa612009-03-10 06:59:54 -07002733 pccs = ccs_base(local) + ccsindex;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002734
John Daiker141fa612009-03-10 06:59:54 -07002735 /* Address in card space */
2736 addr = TX_BUF_BASE + (ccsindex << 11);
2737 /* fill in the CCS */
2738 writeb(CCS_TX_REQUEST, &pccs->cmd);
2739 writeb(addr >> 8, pccs->var.tx_request.tx_data_ptr);
2740 writeb(0x20, pccs->var.tx_request.tx_data_ptr + 1);
2741 writeb(TX_AUTHENTICATE_LENGTH_MSB, pccs->var.tx_request.tx_data_length);
2742 writeb(TX_AUTHENTICATE_LENGTH_LSB,
2743 pccs->var.tx_request.tx_data_length + 1);
2744 writeb(0, &pccs->var.tx_request.pow_sav_mode);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002745
John Daiker141fa612009-03-10 06:59:54 -07002746 ptx = local->sram + addr;
2747 /* fill in the mac header */
2748 writeb(PROTOCOL_VER | AUTHENTIC_TYPE, &ptx->mac.frame_ctl_1);
2749 writeb(0, &ptx->mac.frame_ctl_2);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002750
John Daiker141fa612009-03-10 06:59:54 -07002751 memcpy_toio(ptx->mac.addr_1, dest, ADDRLEN);
2752 memcpy_toio(ptx->mac.addr_2, local->sparm.b4.a_mac_addr, ADDRLEN);
2753 memcpy_toio(ptx->mac.addr_3, local->bss_id, ADDRLEN);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002754
John Daiker141fa612009-03-10 06:59:54 -07002755 /* Fill in msg body with protocol 00 00, sequence 01 00 ,status 00 00 */
2756 memset_io(ptx->var, 0, 6);
2757 writeb(auth_type & 0xff, ptx->var + 2);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002758
John Daiker141fa612009-03-10 06:59:54 -07002759 /* Interrupt the firmware to process the command */
2760 if (interrupt_ecf(local, ccsindex)) {
Dominik Brodowski624dd662009-10-24 15:52:44 +02002761 pr_debug(
John Daiker141fa612009-03-10 06:59:54 -07002762 "ray_cs send authentication request failed - ECF not ready for intr\n");
2763 writeb(CCS_BUFFER_FREE, &(pccs++)->buffer_status);
2764 return -1;
2765 }
2766 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002767} /* End build_auth_frame */
2768
2769/*===========================================================================*/
2770#ifdef CONFIG_PROC_FS
Alexey Dobriyan83daee02009-11-25 10:12:20 +03002771static ssize_t ray_cs_essid_proc_write(struct file *file,
2772 const char __user *buffer, size_t count, loff_t *pos)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002773{
2774 static char proc_essid[33];
Alan Cox575c9ed2009-10-27 15:35:55 +00002775 unsigned int len = count;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002776
2777 if (len > 32)
2778 len = 32;
2779 memset(proc_essid, 0, 33);
2780 if (copy_from_user(proc_essid, buffer, len))
2781 return -EFAULT;
2782 essid = proc_essid;
2783 return count;
2784}
2785
Alexey Dobriyan83daee02009-11-25 10:12:20 +03002786static const struct file_operations ray_cs_essid_proc_fops = {
2787 .owner = THIS_MODULE,
2788 .write = ray_cs_essid_proc_write,
2789};
2790
2791static ssize_t int_proc_write(struct file *file, const char __user *buffer,
2792 size_t count, loff_t *pos)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002793{
2794 static char proc_number[10];
2795 char *p;
2796 int nr, len;
2797
2798 if (!count)
2799 return 0;
2800
2801 if (count > 9)
2802 return -EINVAL;
2803 if (copy_from_user(proc_number, buffer, count))
2804 return -EFAULT;
2805 p = proc_number;
2806 nr = 0;
2807 len = count;
2808 do {
2809 unsigned int c = *p - '0';
2810 if (c > 9)
2811 return -EINVAL;
John Daiker141fa612009-03-10 06:59:54 -07002812 nr = nr * 10 + c;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002813 p++;
2814 } while (--len);
Alexey Dobriyan83daee02009-11-25 10:12:20 +03002815 *(int *)PDE(file->f_path.dentry->d_inode)->data = nr;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002816 return count;
2817}
Alexey Dobriyan83daee02009-11-25 10:12:20 +03002818
2819static const struct file_operations int_proc_fops = {
2820 .owner = THIS_MODULE,
2821 .write = int_proc_write,
2822};
Linus Torvalds1da177e2005-04-16 15:20:36 -07002823#endif
2824
Dominik Brodowskif57ea2a2005-06-27 16:28:24 -07002825static struct pcmcia_device_id ray_ids[] = {
2826 PCMCIA_DEVICE_MANF_CARD(0x01a6, 0x0000),
2827 PCMCIA_DEVICE_NULL,
2828};
John Daiker141fa612009-03-10 06:59:54 -07002829
Dominik Brodowskif57ea2a2005-06-27 16:28:24 -07002830MODULE_DEVICE_TABLE(pcmcia, ray_ids);
2831
Linus Torvalds1da177e2005-04-16 15:20:36 -07002832static struct pcmcia_driver ray_driver = {
John Daiker141fa612009-03-10 06:59:54 -07002833 .owner = THIS_MODULE,
2834 .drv = {
2835 .name = "ray_cs",
2836 },
2837 .probe = ray_probe,
2838 .remove = ray_detach,
2839 .id_table = ray_ids,
2840 .suspend = ray_suspend,
2841 .resume = ray_resume,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002842};
2843
2844static int __init init_ray_cs(void)
2845{
John Daiker141fa612009-03-10 06:59:54 -07002846 int rc;
2847
Dominik Brodowski624dd662009-10-24 15:52:44 +02002848 pr_debug("%s\n", rcsid);
John Daiker141fa612009-03-10 06:59:54 -07002849 rc = pcmcia_register_driver(&ray_driver);
Dominik Brodowski624dd662009-10-24 15:52:44 +02002850 pr_debug("raylink init_module register_pcmcia_driver returns 0x%x\n",
John Daiker141fa612009-03-10 06:59:54 -07002851 rc);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002852
2853#ifdef CONFIG_PROC_FS
John Daiker141fa612009-03-10 06:59:54 -07002854 proc_mkdir("driver/ray_cs", NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002855
John Daiker141fa612009-03-10 06:59:54 -07002856 proc_create("driver/ray_cs/ray_cs", 0, NULL, &ray_cs_proc_fops);
Alexey Dobriyan83daee02009-11-25 10:12:20 +03002857 proc_create("driver/ray_cs/essid", S_IWUSR, NULL, &ray_cs_essid_proc_fops);
2858 proc_create_data("driver/ray_cs/net_type", S_IWUSR, NULL, &int_proc_fops, &net_type);
2859 proc_create_data("driver/ray_cs/translate", S_IWUSR, NULL, &int_proc_fops, &translate);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002860#endif
John Daiker141fa612009-03-10 06:59:54 -07002861 if (translate != 0)
2862 translate = 1;
2863 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002864} /* init_ray_cs */
2865
2866/*===========================================================================*/
2867
2868static void __exit exit_ray_cs(void)
2869{
Dominik Brodowski624dd662009-10-24 15:52:44 +02002870 pr_debug("ray_cs: cleanup_module\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002871
2872#ifdef CONFIG_PROC_FS
John Daiker141fa612009-03-10 06:59:54 -07002873 remove_proc_entry("driver/ray_cs/ray_cs", NULL);
2874 remove_proc_entry("driver/ray_cs/essid", NULL);
2875 remove_proc_entry("driver/ray_cs/net_type", NULL);
2876 remove_proc_entry("driver/ray_cs/translate", NULL);
2877 remove_proc_entry("driver/ray_cs", NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002878#endif
2879
John Daiker141fa612009-03-10 06:59:54 -07002880 pcmcia_unregister_driver(&ray_driver);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002881} /* exit_ray_cs */
2882
2883module_init(init_ray_cs);
2884module_exit(exit_ray_cs);
2885
2886/*===========================================================================*/