blob: 18a93f1adcc477fb4a2bbef078d62daed2bb3375 [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>
46#include <linux/ethtool.h>
Al Viro7698d692007-12-29 04:55:50 -050047#include <linux/ieee80211.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070048
Linus Torvalds1da177e2005-04-16 15:20:36 -070049#include <pcmcia/cs_types.h>
50#include <pcmcia/cs.h>
51#include <pcmcia/cistpl.h>
52#include <pcmcia/cisreg.h>
53#include <pcmcia/ds.h>
54#include <pcmcia/mem_op.h>
55
56#include <linux/wireless.h>
Michael Wu113b8982006-08-13 23:27:17 -070057#include <net/iw_handler.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070058
59#include <asm/io.h>
60#include <asm/system.h>
61#include <asm/byteorder.h>
62#include <asm/uaccess.h>
63
64/* Warning : these stuff will slow down the driver... */
65#define WIRELESS_SPY /* Enable spying addresses */
66/* Definitions we need for spy */
John Daiker141fa612009-03-10 06:59:54 -070067typedef struct iw_statistics iw_stats;
68typedef u_char mac_addr[ETH_ALEN]; /* Hardware address */
Linus Torvalds1da177e2005-04-16 15:20:36 -070069
70#include "rayctl.h"
71#include "ray_cs.h"
72
Linus Torvalds1da177e2005-04-16 15:20:36 -070073
Linus Torvalds1da177e2005-04-16 15:20:36 -070074/** Prototypes based on PCMCIA skeleton driver *******************************/
Dominik Brodowski15b99ac2006-03-31 17:26:06 +020075static int ray_config(struct pcmcia_device *link);
Dominik Brodowskifba395e2006-03-31 17:21:06 +020076static void ray_release(struct pcmcia_device *link);
Dominik Brodowskicc3b4862005-11-14 21:23:14 +010077static void ray_detach(struct pcmcia_device *p_dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -070078
79/***** Prototypes indicated by device structure ******************************/
80static int ray_dev_close(struct net_device *dev);
81static int ray_dev_config(struct net_device *dev, struct ifmap *map);
82static struct net_device_stats *ray_get_stats(struct net_device *dev);
83static int ray_dev_init(struct net_device *dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -070084
Jeff Garzik7282d492006-09-13 14:30:00 -040085static const struct ethtool_ops netdev_ethtool_ops;
Linus Torvalds1da177e2005-04-16 15:20:36 -070086
87static int ray_open(struct net_device *dev);
Stephen Hemmingerd0cf9c02009-08-31 19:50:57 +000088static netdev_tx_t ray_dev_start_xmit(struct sk_buff *skb,
89 struct net_device *dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -070090static void set_multicast_list(struct net_device *dev);
91static void ray_update_multi_list(struct net_device *dev, int all);
92static int translate_frame(ray_dev_t *local, struct tx_msg __iomem *ptx,
John Daiker141fa612009-03-10 06:59:54 -070093 unsigned char *data, int len);
94static void ray_build_header(ray_dev_t *local, struct tx_msg __iomem *ptx,
95 UCHAR msg_type, unsigned char *data);
Linus Torvalds1da177e2005-04-16 15:20:36 -070096static void untranslate(ray_dev_t *local, struct sk_buff *skb, int len);
John Daiker141fa612009-03-10 06:59:54 -070097static iw_stats *ray_get_wireless_stats(struct net_device *dev);
98static const struct iw_handler_def ray_handler_def;
Linus Torvalds1da177e2005-04-16 15:20:36 -070099
100/***** Prototypes for raylink functions **************************************/
101static int asc_to_int(char a);
102static void authenticate(ray_dev_t *local);
103static int build_auth_frame(ray_dev_t *local, UCHAR *dest, int auth_type);
104static void authenticate_timeout(u_long);
105static int get_free_ccs(ray_dev_t *local);
106static int get_free_tx_ccs(ray_dev_t *local);
107static void init_startup_params(ray_dev_t *local);
108static int parse_addr(char *in_str, UCHAR *out);
John Daiker141fa612009-03-10 06:59:54 -0700109static int ray_hw_xmit(unsigned char *data, int len, struct net_device *dev, UCHAR type);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700110static int ray_init(struct net_device *dev);
111static int interrupt_ecf(ray_dev_t *local, int ccs);
112static void ray_reset(struct net_device *dev);
113static void ray_update_parm(struct net_device *dev, UCHAR objid, UCHAR *value, int len);
114static void verify_dl_startup(u_long);
115
116/* Prototypes for interrpt time functions **********************************/
John Daiker141fa612009-03-10 06:59:54 -0700117static irqreturn_t ray_interrupt(int reg, void *dev_id);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700118static void clear_interrupt(ray_dev_t *local);
John Daiker141fa612009-03-10 06:59:54 -0700119static void rx_deauthenticate(ray_dev_t *local, struct rcs __iomem *prcs,
120 unsigned int pkt_addr, int rx_len);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700121static int copy_from_rx_buff(ray_dev_t *local, UCHAR *dest, int pkt_addr, int len);
122static void ray_rx(struct net_device *dev, ray_dev_t *local, struct rcs __iomem *prcs);
123static void release_frag_chain(ray_dev_t *local, struct rcs __iomem *prcs);
124static void rx_authenticate(ray_dev_t *local, struct rcs __iomem *prcs,
John Daiker141fa612009-03-10 06:59:54 -0700125 unsigned int pkt_addr, int rx_len);
126static void rx_data(struct net_device *dev, struct rcs __iomem *prcs,
127 unsigned int pkt_addr, int rx_len);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700128static void associate(ray_dev_t *local);
129
130/* Card command functions */
131static int dl_startup_params(struct net_device *dev);
132static void join_net(u_long local);
133static void start_net(u_long local);
134/* void start_net(ray_dev_t *local); */
135
136/*===========================================================================*/
137/* Parameters that can be set with 'insmod' */
138
139/* ADHOC=0, Infrastructure=1 */
140static int net_type = ADHOC;
141
142/* Hop dwell time in Kus (1024 us units defined by 802.11) */
143static int hop_dwell = 128;
144
145/* Beacon period in Kus */
146static int beacon_period = 256;
147
148/* power save mode (0 = off, 1 = save power) */
149static int psm;
150
151/* String for network's Extended Service Set ID. 32 Characters max */
152static char *essid;
153
154/* Default to encapsulation unless translation requested */
155static int translate = 1;
156
157static int country = USA;
158
159static int sniffer;
160
161static int bc;
162
163/* 48 bit physical card address if overriding card's real physical
164 * address is required. Since IEEE 802.11 addresses are 48 bits
165 * like ethernet, an int can't be used, so a string is used. To
166 * allow use of addresses starting with a decimal digit, the first
167 * character must be a letter and will be ignored. This letter is
168 * followed by up to 12 hex digits which are the address. If less
169 * than 12 digits are used, the address will be left filled with 0's.
170 * Note that bit 0 of the first byte is the broadcast bit, and evil
171 * things will happen if it is not 0 in a card address.
172 */
173static char *phy_addr = NULL;
174
175
Dominik Brodowskifba395e2006-03-31 17:21:06 +0200176/* A struct pcmcia_device structure has fields for most things that are needed
Linus Torvalds1da177e2005-04-16 15:20:36 -0700177 to keep track of a socket, but there will usually be some device
178 specific information that also needs to be kept track of. The
Dominik Brodowskifba395e2006-03-31 17:21:06 +0200179 'priv' pointer in a struct pcmcia_device structure can be used to point to
Linus Torvalds1da177e2005-04-16 15:20:36 -0700180 a device-specific private data structure, like this.
181*/
182static unsigned int ray_mem_speed = 500;
183
Dominik Brodowskifd238232006-03-05 10:45:09 +0100184/* WARNING: THIS DRIVER IS NOT CAPABLE OF HANDLING MULTIPLE DEVICES! */
185static struct pcmcia_device *this_device = NULL;
186
Linus Torvalds1da177e2005-04-16 15:20:36 -0700187MODULE_AUTHOR("Corey Thomas <corey@world.std.com>");
188MODULE_DESCRIPTION("Raylink/WebGear wireless LAN driver");
189MODULE_LICENSE("GPL");
190
191module_param(net_type, int, 0);
192module_param(hop_dwell, int, 0);
193module_param(beacon_period, int, 0);
194module_param(psm, int, 0);
195module_param(essid, charp, 0);
196module_param(translate, int, 0);
197module_param(country, int, 0);
198module_param(sniffer, int, 0);
199module_param(bc, int, 0);
200module_param(phy_addr, charp, 0);
201module_param(ray_mem_speed, int, 0);
202
203static UCHAR b5_default_startup_parms[] = {
John Daiker141fa612009-03-10 06:59:54 -0700204 0, 0, /* Adhoc station */
205 'L', 'I', 'N', 'U', 'X', 0, 0, 0, /* 32 char ESSID */
206 0, 0, 0, 0, 0, 0, 0, 0,
207 0, 0, 0, 0, 0, 0, 0, 0,
208 0, 0, 0, 0, 0, 0, 0, 0,
209 1, 0, /* Active scan, CA Mode */
210 0, 0, 0, 0, 0, 0, /* No default MAC addr */
211 0x7f, 0xff, /* Frag threshold */
212 0x00, 0x80, /* Hop time 128 Kus */
213 0x01, 0x00, /* Beacon period 256 Kus */
214 0x01, 0x07, 0xa3, /* DTIM, retries, ack timeout */
215 0x1d, 0x82, 0x4e, /* SIFS, DIFS, PIFS */
216 0x7f, 0xff, /* RTS threshold */
217 0x04, 0xe2, 0x38, 0xA4, /* scan_dwell, max_scan_dwell */
218 0x05, /* assoc resp timeout thresh */
219 0x08, 0x02, 0x08, /* adhoc, infra, super cycle max */
220 0, /* Promiscuous mode */
221 0x0c, 0x0bd, /* Unique word */
222 0x32, /* Slot time */
223 0xff, 0xff, /* roam-low snr, low snr count */
224 0x05, 0xff, /* Infra, adhoc missed bcn thresh */
225 0x01, 0x0b, 0x4f, /* USA, hop pattern, hop pat length */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700226/* b4 - b5 differences start here */
John Daiker141fa612009-03-10 06:59:54 -0700227 0x00, 0x3f, /* CW max */
228 0x00, 0x0f, /* CW min */
229 0x04, 0x08, /* Noise gain, limit offset */
230 0x28, 0x28, /* det rssi, med busy offsets */
231 7, /* det sync thresh */
232 0, 2, 2, /* test mode, min, max */
233 0, /* allow broadcast SSID probe resp */
234 0, 0, /* privacy must start, can join */
235 2, 0, 0, 0, 0, 0, 0, 0 /* basic rate set */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700236};
237
238static UCHAR b4_default_startup_parms[] = {
John Daiker141fa612009-03-10 06:59:54 -0700239 0, 0, /* Adhoc station */
240 'L', 'I', 'N', 'U', 'X', 0, 0, 0, /* 32 char ESSID */
241 0, 0, 0, 0, 0, 0, 0, 0,
242 0, 0, 0, 0, 0, 0, 0, 0,
243 0, 0, 0, 0, 0, 0, 0, 0,
244 1, 0, /* Active scan, CA Mode */
245 0, 0, 0, 0, 0, 0, /* No default MAC addr */
246 0x7f, 0xff, /* Frag threshold */
247 0x02, 0x00, /* Hop time */
248 0x00, 0x01, /* Beacon period */
249 0x01, 0x07, 0xa3, /* DTIM, retries, ack timeout */
250 0x1d, 0x82, 0xce, /* SIFS, DIFS, PIFS */
251 0x7f, 0xff, /* RTS threshold */
252 0xfb, 0x1e, 0xc7, 0x5c, /* scan_dwell, max_scan_dwell */
253 0x05, /* assoc resp timeout thresh */
254 0x04, 0x02, 0x4, /* adhoc, infra, super cycle max */
255 0, /* Promiscuous mode */
256 0x0c, 0x0bd, /* Unique word */
257 0x4e, /* Slot time (TBD seems wrong) */
258 0xff, 0xff, /* roam-low snr, low snr count */
259 0x05, 0xff, /* Infra, adhoc missed bcn thresh */
260 0x01, 0x0b, 0x4e, /* USA, hop pattern, hop pat length */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700261/* b4 - b5 differences start here */
John Daiker141fa612009-03-10 06:59:54 -0700262 0x3f, 0x0f, /* CW max, min */
263 0x04, 0x08, /* Noise gain, limit offset */
264 0x28, 0x28, /* det rssi, med busy offsets */
265 7, /* det sync thresh */
266 0, 2, 2 /* test mode, min, max */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700267};
John Daiker141fa612009-03-10 06:59:54 -0700268
Linus Torvalds1da177e2005-04-16 15:20:36 -0700269/*===========================================================================*/
John Daiker141fa612009-03-10 06:59:54 -0700270static unsigned char eth2_llc[] = { 0xaa, 0xaa, 3, 0, 0, 0 };
Linus Torvalds1da177e2005-04-16 15:20:36 -0700271
272static char hop_pattern_length[] = { 1,
John Daiker141fa612009-03-10 06:59:54 -0700273 USA_HOP_MOD, EUROPE_HOP_MOD,
274 JAPAN_HOP_MOD, KOREA_HOP_MOD,
275 SPAIN_HOP_MOD, FRANCE_HOP_MOD,
276 ISRAEL_HOP_MOD, AUSTRALIA_HOP_MOD,
277 JAPAN_TEST_HOP_MOD
Linus Torvalds1da177e2005-04-16 15:20:36 -0700278};
279
John Daiker141fa612009-03-10 06:59:54 -0700280static char rcsid[] =
281 "Raylink/WebGear wireless LAN - Corey <Thomas corey@world.std.com>";
Linus Torvalds1da177e2005-04-16 15:20:36 -0700282
Stephen Hemminger32f5a332009-03-20 19:36:28 +0000283static const struct net_device_ops ray_netdev_ops = {
284 .ndo_init = ray_dev_init,
285 .ndo_open = ray_open,
286 .ndo_stop = ray_dev_close,
287 .ndo_start_xmit = ray_dev_start_xmit,
288 .ndo_set_config = ray_dev_config,
289 .ndo_get_stats = ray_get_stats,
290 .ndo_set_multicast_list = set_multicast_list,
291 .ndo_change_mtu = eth_change_mtu,
292 .ndo_set_mac_address = eth_mac_addr,
293 .ndo_validate_addr = eth_validate_addr,
294};
295
Linus Torvalds1da177e2005-04-16 15:20:36 -0700296/*=============================================================================
297 ray_attach() creates an "instance" of the driver, allocating
298 local data structures for one device. The device is registered
299 with Card Services.
300 The dev_link structure is initialized, but we don't actually
301 configure the card at this point -- we wait until we receive a
302 card insertion event.
303=============================================================================*/
Dominik Brodowski15b99ac2006-03-31 17:26:06 +0200304static int ray_probe(struct pcmcia_device *p_dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700305{
John Daiker141fa612009-03-10 06:59:54 -0700306 ray_dev_t *local;
307 struct net_device *dev;
Dominik Brodowskifd238232006-03-05 10:45:09 +0100308
Dominik Brodowski624dd662009-10-24 15:52:44 +0200309 dev_dbg(&p_dev->dev, "ray_attach()\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700310
John Daiker141fa612009-03-10 06:59:54 -0700311 /* Allocate space for private device-specific data */
312 dev = alloc_etherdev(sizeof(ray_dev_t));
313 if (!dev)
314 goto fail_alloc_dev;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700315
John Daiker141fa612009-03-10 06:59:54 -0700316 local = netdev_priv(dev);
317 local->finder = p_dev;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700318
John Daiker141fa612009-03-10 06:59:54 -0700319 /* The io structure describes IO port mapping. None used here */
320 p_dev->io.NumPorts1 = 0;
321 p_dev->io.Attributes1 = IO_DATA_PATH_WIDTH_8;
322 p_dev->io.IOAddrLines = 5;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700323
John Daiker141fa612009-03-10 06:59:54 -0700324 /* General socket configuration */
325 p_dev->conf.Attributes = CONF_ENABLE_IRQ;
326 p_dev->conf.IntType = INT_MEMORY_AND_IO;
327 p_dev->conf.ConfigIndex = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700328
John Daiker141fa612009-03-10 06:59:54 -0700329 p_dev->priv = dev;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700330
John Daiker141fa612009-03-10 06:59:54 -0700331 local->finder = p_dev;
332 local->card_status = CARD_INSERTED;
333 local->authentication_state = UNAUTHENTICATED;
334 local->num_multi = 0;
Dominik Brodowski624dd662009-10-24 15:52:44 +0200335 dev_dbg(&p_dev->dev, "ray_attach p_dev = %p, dev = %p, local = %p, intr = %p\n",
John Daiker141fa612009-03-10 06:59:54 -0700336 p_dev, dev, local, &ray_interrupt);
337
338 /* Raylink entries in the device structure */
Stephen Hemminger32f5a332009-03-20 19:36:28 +0000339 dev->netdev_ops = &ray_netdev_ops;
John Daiker141fa612009-03-10 06:59:54 -0700340 SET_ETHTOOL_OPS(dev, &netdev_ethtool_ops);
341 dev->wireless_handlers = &ray_handler_def;
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -0700342#ifdef WIRELESS_SPY
John Daiker141fa612009-03-10 06:59:54 -0700343 local->wireless_data.spy_data = &local->spy_data;
344 dev->wireless_data = &local->wireless_data;
345#endif /* WIRELESS_SPY */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700346
Linus Torvalds1da177e2005-04-16 15:20:36 -0700347
Dominik Brodowski624dd662009-10-24 15:52:44 +0200348 dev_dbg(&p_dev->dev, "ray_cs ray_attach calling ether_setup.)\n");
John Daiker141fa612009-03-10 06:59:54 -0700349 netif_stop_queue(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700350
John Daiker141fa612009-03-10 06:59:54 -0700351 init_timer(&local->timer);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700352
John Daiker141fa612009-03-10 06:59:54 -0700353 this_device = p_dev;
354 return ray_config(p_dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700355
356fail_alloc_dev:
John Daiker141fa612009-03-10 06:59:54 -0700357 return -ENOMEM;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700358} /* ray_attach */
John Daiker141fa612009-03-10 06:59:54 -0700359
Linus Torvalds1da177e2005-04-16 15:20:36 -0700360/*=============================================================================
361 This deletes a driver "instance". The device is de-registered
362 with Card Services. If it has been released, all local data
363 structures are freed. Otherwise, the structures will be freed
364 when the device is released.
365=============================================================================*/
Dominik Brodowskifba395e2006-03-31 17:21:06 +0200366static void ray_detach(struct pcmcia_device *link)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700367{
John Daiker141fa612009-03-10 06:59:54 -0700368 struct net_device *dev;
369 ray_dev_t *local;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700370
Dominik Brodowski624dd662009-10-24 15:52:44 +0200371 dev_dbg(&link->dev, "ray_detach\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700372
John Daiker141fa612009-03-10 06:59:54 -0700373 this_device = NULL;
374 dev = link->priv;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700375
John Daiker141fa612009-03-10 06:59:54 -0700376 ray_release(link);
Dominik Brodowskicc3b4862005-11-14 21:23:14 +0100377
John Daiker141fa612009-03-10 06:59:54 -0700378 local = netdev_priv(dev);
379 del_timer(&local->timer);
Dominik Brodowskicc3b4862005-11-14 21:23:14 +0100380
John Daiker141fa612009-03-10 06:59:54 -0700381 if (link->priv) {
Dominik Brodowskic7c2fa02010-03-20 19:39:26 +0100382 unregister_netdev(dev);
John Daiker141fa612009-03-10 06:59:54 -0700383 free_netdev(dev);
384 }
Dominik Brodowski624dd662009-10-24 15:52:44 +0200385 dev_dbg(&link->dev, "ray_cs ray_detach ending\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700386} /* ray_detach */
John Daiker141fa612009-03-10 06:59:54 -0700387
Linus Torvalds1da177e2005-04-16 15:20:36 -0700388/*=============================================================================
389 ray_config() is run after a CARD_INSERTION event
390 is received, to configure the PCMCIA socket, and to make the
391 ethernet device available to the system.
392=============================================================================*/
Linus Torvalds1da177e2005-04-16 15:20:36 -0700393#define MAX_TUPLE_SIZE 128
Dominik Brodowski15b99ac2006-03-31 17:26:06 +0200394static int ray_config(struct pcmcia_device *link)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700395{
Dominik Brodowski624dd662009-10-24 15:52:44 +0200396 int ret = 0;
John Daiker141fa612009-03-10 06:59:54 -0700397 int i;
398 win_req_t req;
399 memreq_t mem;
400 struct net_device *dev = (struct net_device *)link->priv;
401 ray_dev_t *local = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700402
Dominik Brodowski624dd662009-10-24 15:52:44 +0200403 dev_dbg(&link->dev, "ray_config\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700404
John Daiker141fa612009-03-10 06:59:54 -0700405 /* Determine card type and firmware version */
406 printk(KERN_INFO "ray_cs Detected: %s%s%s%s\n",
407 link->prod_id[0] ? link->prod_id[0] : " ",
408 link->prod_id[1] ? link->prod_id[1] : " ",
409 link->prod_id[2] ? link->prod_id[2] : " ",
410 link->prod_id[3] ? link->prod_id[3] : " ");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700411
John Daiker141fa612009-03-10 06:59:54 -0700412 /* Now allocate an interrupt line. Note that this does not
413 actually assign a handler to the interrupt.
414 */
Dominik Brodowskieb141202010-03-07 12:21:16 +0100415 ret = pcmcia_request_irq(link, ray_interrupt);
Dominik Brodowski624dd662009-10-24 15:52:44 +0200416 if (ret)
417 goto failed;
Dominik Brodowskieb141202010-03-07 12:21:16 +0100418 dev->irq = link->irq;
John Daiker141fa612009-03-10 06:59:54 -0700419
420 /* This actually configures the PCMCIA socket -- setting up
421 the I/O windows and the interrupt mapping.
422 */
Dominik Brodowski624dd662009-10-24 15:52:44 +0200423 ret = pcmcia_request_configuration(link, &link->conf);
424 if (ret)
425 goto failed;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700426
427/*** Set up 32k window for shared memory (transmit and control) ************/
John Daiker141fa612009-03-10 06:59:54 -0700428 req.Attributes =
429 WIN_DATA_WIDTH_8 | WIN_MEMORY_TYPE_CM | WIN_ENABLE | WIN_USE_WAIT;
430 req.Base = 0;
431 req.Size = 0x8000;
432 req.AccessSpeed = ray_mem_speed;
Dominik Brodowski6838b032009-11-03 01:31:52 +0100433 ret = pcmcia_request_window(link, &req, &link->win);
Dominik Brodowski624dd662009-10-24 15:52:44 +0200434 if (ret)
435 goto failed;
John Daiker141fa612009-03-10 06:59:54 -0700436 mem.CardOffset = 0x0000;
437 mem.Page = 0;
Magnus Damm868575d2006-12-13 19:46:43 +0900438 ret = pcmcia_map_mem_page(link, link->win, &mem);
Dominik Brodowski624dd662009-10-24 15:52:44 +0200439 if (ret)
440 goto failed;
John Daiker141fa612009-03-10 06:59:54 -0700441 local->sram = ioremap(req.Base, req.Size);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700442
443/*** Set up 16k window for shared memory (receive buffer) ***************/
John Daiker141fa612009-03-10 06:59:54 -0700444 req.Attributes =
445 WIN_DATA_WIDTH_8 | WIN_MEMORY_TYPE_CM | WIN_ENABLE | WIN_USE_WAIT;
446 req.Base = 0;
447 req.Size = 0x4000;
448 req.AccessSpeed = ray_mem_speed;
Dominik Brodowski6838b032009-11-03 01:31:52 +0100449 ret = pcmcia_request_window(link, &req, &local->rmem_handle);
Dominik Brodowski624dd662009-10-24 15:52:44 +0200450 if (ret)
451 goto failed;
John Daiker141fa612009-03-10 06:59:54 -0700452 mem.CardOffset = 0x8000;
453 mem.Page = 0;
Magnus Damm868575d2006-12-13 19:46:43 +0900454 ret = pcmcia_map_mem_page(link, local->rmem_handle, &mem);
Dominik Brodowski624dd662009-10-24 15:52:44 +0200455 if (ret)
456 goto failed;
John Daiker141fa612009-03-10 06:59:54 -0700457 local->rmem = ioremap(req.Base, req.Size);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700458
459/*** Set up window for attribute memory ***********************************/
John Daiker141fa612009-03-10 06:59:54 -0700460 req.Attributes =
461 WIN_DATA_WIDTH_8 | WIN_MEMORY_TYPE_AM | WIN_ENABLE | WIN_USE_WAIT;
462 req.Base = 0;
463 req.Size = 0x1000;
464 req.AccessSpeed = ray_mem_speed;
Dominik Brodowski6838b032009-11-03 01:31:52 +0100465 ret = pcmcia_request_window(link, &req, &local->amem_handle);
Dominik Brodowski624dd662009-10-24 15:52:44 +0200466 if (ret)
467 goto failed;
John Daiker141fa612009-03-10 06:59:54 -0700468 mem.CardOffset = 0x0000;
469 mem.Page = 0;
Magnus Damm868575d2006-12-13 19:46:43 +0900470 ret = pcmcia_map_mem_page(link, local->amem_handle, &mem);
Dominik Brodowski624dd662009-10-24 15:52:44 +0200471 if (ret)
472 goto failed;
John Daiker141fa612009-03-10 06:59:54 -0700473 local->amem = ioremap(req.Base, req.Size);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700474
Dominik Brodowski624dd662009-10-24 15:52:44 +0200475 dev_dbg(&link->dev, "ray_config sram=%p\n", local->sram);
476 dev_dbg(&link->dev, "ray_config rmem=%p\n", local->rmem);
477 dev_dbg(&link->dev, "ray_config amem=%p\n", local->amem);
John Daiker141fa612009-03-10 06:59:54 -0700478 if (ray_init(dev) < 0) {
479 ray_release(link);
480 return -ENODEV;
481 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700482
Dominik Brodowskidd2e5a12009-11-03 10:27:34 +0100483 SET_NETDEV_DEV(dev, &link->dev);
John Daiker141fa612009-03-10 06:59:54 -0700484 i = register_netdev(dev);
485 if (i != 0) {
486 printk("ray_config register_netdev() failed\n");
487 ray_release(link);
488 return i;
489 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700490
John Daiker141fa612009-03-10 06:59:54 -0700491 printk(KERN_INFO "%s: RayLink, irq %d, hw_addr %pM\n",
492 dev->name, dev->irq, dev->dev_addr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700493
John Daiker141fa612009-03-10 06:59:54 -0700494 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700495
Dominik Brodowski624dd662009-10-24 15:52:44 +0200496failed:
John Daiker141fa612009-03-10 06:59:54 -0700497 ray_release(link);
498 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700499} /* ray_config */
500
501static inline struct ccs __iomem *ccs_base(ray_dev_t *dev)
502{
503 return dev->sram + CCS_BASE;
504}
505
506static inline struct rcs __iomem *rcs_base(ray_dev_t *dev)
507{
508 /*
509 * This looks nonsensical, since there is a separate
510 * RCS_BASE. But the difference between a "struct rcs"
511 * and a "struct ccs" ends up being in the _index_ off
512 * the base, so the base pointer is the same for both
513 * ccs/rcs.
514 */
515 return dev->sram + CCS_BASE;
516}
517
518/*===========================================================================*/
519static int ray_init(struct net_device *dev)
520{
John Daiker141fa612009-03-10 06:59:54 -0700521 int i;
522 UCHAR *p;
523 struct ccs __iomem *pccs;
524 ray_dev_t *local = netdev_priv(dev);
525 struct pcmcia_device *link = local->finder;
Dominik Brodowski624dd662009-10-24 15:52:44 +0200526 dev_dbg(&link->dev, "ray_init(0x%p)\n", dev);
John Daiker141fa612009-03-10 06:59:54 -0700527 if (!(pcmcia_dev_present(link))) {
Dominik Brodowski624dd662009-10-24 15:52:44 +0200528 dev_dbg(&link->dev, "ray_init - device not present\n");
John Daiker141fa612009-03-10 06:59:54 -0700529 return -1;
530 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700531
John Daiker141fa612009-03-10 06:59:54 -0700532 local->net_type = net_type;
533 local->sta_type = TYPE_STA;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700534
John Daiker141fa612009-03-10 06:59:54 -0700535 /* Copy the startup results to local memory */
536 memcpy_fromio(&local->startup_res, local->sram + ECF_TO_HOST_BASE,
537 sizeof(struct startup_res_6));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700538
John Daiker141fa612009-03-10 06:59:54 -0700539 /* Check Power up test status and get mac address from card */
540 if (local->startup_res.startup_word != 0x80) {
541 printk(KERN_INFO "ray_init ERROR card status = %2x\n",
542 local->startup_res.startup_word);
543 local->card_status = CARD_INIT_ERROR;
544 return -1;
545 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700546
John Daiker141fa612009-03-10 06:59:54 -0700547 local->fw_ver = local->startup_res.firmware_version[0];
548 local->fw_bld = local->startup_res.firmware_version[1];
549 local->fw_var = local->startup_res.firmware_version[2];
Dominik Brodowski624dd662009-10-24 15:52:44 +0200550 dev_dbg(&link->dev, "ray_init firmware version %d.%d \n", local->fw_ver,
John Daiker141fa612009-03-10 06:59:54 -0700551 local->fw_bld);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700552
John Daiker141fa612009-03-10 06:59:54 -0700553 local->tib_length = 0x20;
554 if ((local->fw_ver == 5) && (local->fw_bld >= 30))
555 local->tib_length = local->startup_res.tib_length;
Dominik Brodowski624dd662009-10-24 15:52:44 +0200556 dev_dbg(&link->dev, "ray_init tib_length = 0x%02x\n", local->tib_length);
John Daiker141fa612009-03-10 06:59:54 -0700557 /* Initialize CCS's to buffer free state */
558 pccs = ccs_base(local);
559 for (i = 0; i < NUMBER_OF_CCS; i++) {
560 writeb(CCS_BUFFER_FREE, &(pccs++)->buffer_status);
561 }
562 init_startup_params(local);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700563
John Daiker141fa612009-03-10 06:59:54 -0700564 /* copy mac address to startup parameters */
565 if (parse_addr(phy_addr, local->sparm.b4.a_mac_addr)) {
566 p = local->sparm.b4.a_mac_addr;
567 } else {
568 memcpy(&local->sparm.b4.a_mac_addr,
569 &local->startup_res.station_addr, ADDRLEN);
570 p = local->sparm.b4.a_mac_addr;
571 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700572
John Daiker141fa612009-03-10 06:59:54 -0700573 clear_interrupt(local); /* Clear any interrupt from the card */
574 local->card_status = CARD_AWAITING_PARAM;
Dominik Brodowski624dd662009-10-24 15:52:44 +0200575 dev_dbg(&link->dev, "ray_init ending\n");
John Daiker141fa612009-03-10 06:59:54 -0700576 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700577} /* ray_init */
John Daiker141fa612009-03-10 06:59:54 -0700578
Linus Torvalds1da177e2005-04-16 15:20:36 -0700579/*===========================================================================*/
580/* Download startup parameters to the card and command it to read them */
581static int dl_startup_params(struct net_device *dev)
582{
John Daiker141fa612009-03-10 06:59:54 -0700583 int ccsindex;
584 ray_dev_t *local = netdev_priv(dev);
585 struct ccs __iomem *pccs;
586 struct pcmcia_device *link = local->finder;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700587
Dominik Brodowski624dd662009-10-24 15:52:44 +0200588 dev_dbg(&link->dev, "dl_startup_params entered\n");
John Daiker141fa612009-03-10 06:59:54 -0700589 if (!(pcmcia_dev_present(link))) {
Dominik Brodowski624dd662009-10-24 15:52:44 +0200590 dev_dbg(&link->dev, "ray_cs dl_startup_params - device not present\n");
John Daiker141fa612009-03-10 06:59:54 -0700591 return -1;
592 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700593
John Daiker141fa612009-03-10 06:59:54 -0700594 /* Copy parameters to host to ECF area */
595 if (local->fw_ver == 0x55)
596 memcpy_toio(local->sram + HOST_TO_ECF_BASE, &local->sparm.b4,
597 sizeof(struct b4_startup_params));
598 else
599 memcpy_toio(local->sram + HOST_TO_ECF_BASE, &local->sparm.b5,
600 sizeof(struct b5_startup_params));
601
602 /* Fill in the CCS fields for the ECF */
603 if ((ccsindex = get_free_ccs(local)) < 0)
604 return -1;
605 local->dl_param_ccs = ccsindex;
606 pccs = ccs_base(local) + ccsindex;
607 writeb(CCS_DOWNLOAD_STARTUP_PARAMS, &pccs->cmd);
Dominik Brodowski624dd662009-10-24 15:52:44 +0200608 dev_dbg(&link->dev, "dl_startup_params start ccsindex = %d\n",
John Daiker141fa612009-03-10 06:59:54 -0700609 local->dl_param_ccs);
610 /* Interrupt the firmware to process the command */
611 if (interrupt_ecf(local, ccsindex)) {
612 printk(KERN_INFO "ray dl_startup_params failed - "
613 "ECF not ready for intr\n");
614 local->card_status = CARD_DL_PARAM_ERROR;
615 writeb(CCS_BUFFER_FREE, &(pccs++)->buffer_status);
616 return -2;
617 }
618 local->card_status = CARD_DL_PARAM;
619 /* Start kernel timer to wait for dl startup to complete. */
620 local->timer.expires = jiffies + HZ / 2;
621 local->timer.data = (long)local;
622 local->timer.function = &verify_dl_startup;
623 add_timer(&local->timer);
Dominik Brodowski624dd662009-10-24 15:52:44 +0200624 dev_dbg(&link->dev,
John Daiker141fa612009-03-10 06:59:54 -0700625 "ray_cs dl_startup_params started timer for verify_dl_startup\n");
626 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700627} /* dl_startup_params */
John Daiker141fa612009-03-10 06:59:54 -0700628
Linus Torvalds1da177e2005-04-16 15:20:36 -0700629/*===========================================================================*/
630static void init_startup_params(ray_dev_t *local)
631{
John Daiker141fa612009-03-10 06:59:54 -0700632 int i;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700633
John Daiker141fa612009-03-10 06:59:54 -0700634 if (country > JAPAN_TEST)
635 country = USA;
636 else if (country < USA)
637 country = USA;
638 /* structure for hop time and beacon period is defined here using
639 * New 802.11D6.1 format. Card firmware is still using old format
640 * until version 6.
641 * Before After
642 * a_hop_time ms byte a_hop_time ms byte
643 * a_hop_time 2s byte a_hop_time ls byte
644 * a_hop_time ls byte a_beacon_period ms byte
645 * a_beacon_period a_beacon_period ls byte
646 *
647 * a_hop_time = uS a_hop_time = KuS
648 * a_beacon_period = hops a_beacon_period = KuS
649 *//* 64ms = 010000 */
650 if (local->fw_ver == 0x55) {
651 memcpy((UCHAR *) &local->sparm.b4, b4_default_startup_parms,
652 sizeof(struct b4_startup_params));
653 /* Translate sane kus input values to old build 4/5 format */
654 /* i = hop time in uS truncated to 3 bytes */
655 i = (hop_dwell * 1024) & 0xffffff;
656 local->sparm.b4.a_hop_time[0] = (i >> 16) & 0xff;
657 local->sparm.b4.a_hop_time[1] = (i >> 8) & 0xff;
658 local->sparm.b4.a_beacon_period[0] = 0;
659 local->sparm.b4.a_beacon_period[1] =
660 ((beacon_period / hop_dwell) - 1) & 0xff;
661 local->sparm.b4.a_curr_country_code = country;
662 local->sparm.b4.a_hop_pattern_length =
663 hop_pattern_length[(int)country] - 1;
664 if (bc) {
665 local->sparm.b4.a_ack_timeout = 0x50;
666 local->sparm.b4.a_sifs = 0x3f;
667 }
668 } else { /* Version 5 uses real kus values */
669 memcpy((UCHAR *) &local->sparm.b5, b5_default_startup_parms,
670 sizeof(struct b5_startup_params));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700671
John Daiker141fa612009-03-10 06:59:54 -0700672 local->sparm.b5.a_hop_time[0] = (hop_dwell >> 8) & 0xff;
673 local->sparm.b5.a_hop_time[1] = hop_dwell & 0xff;
674 local->sparm.b5.a_beacon_period[0] =
675 (beacon_period >> 8) & 0xff;
676 local->sparm.b5.a_beacon_period[1] = beacon_period & 0xff;
677 if (psm)
678 local->sparm.b5.a_power_mgt_state = 1;
679 local->sparm.b5.a_curr_country_code = country;
680 local->sparm.b5.a_hop_pattern_length =
681 hop_pattern_length[(int)country];
682 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700683
John Daiker141fa612009-03-10 06:59:54 -0700684 local->sparm.b4.a_network_type = net_type & 0x01;
685 local->sparm.b4.a_acting_as_ap_status = TYPE_STA;
686
687 if (essid != NULL)
688 strncpy(local->sparm.b4.a_current_ess_id, essid, ESSID_SIZE);
689} /* init_startup_params */
690
Linus Torvalds1da177e2005-04-16 15:20:36 -0700691/*===========================================================================*/
692static void verify_dl_startup(u_long data)
693{
John Daiker141fa612009-03-10 06:59:54 -0700694 ray_dev_t *local = (ray_dev_t *) data;
695 struct ccs __iomem *pccs = ccs_base(local) + local->dl_param_ccs;
696 UCHAR status;
697 struct pcmcia_device *link = local->finder;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700698
John Daiker141fa612009-03-10 06:59:54 -0700699 if (!(pcmcia_dev_present(link))) {
Dominik Brodowski624dd662009-10-24 15:52:44 +0200700 dev_dbg(&link->dev, "ray_cs verify_dl_startup - device not present\n");
John Daiker141fa612009-03-10 06:59:54 -0700701 return;
702 }
Dominik Brodowski624dd662009-10-24 15:52:44 +0200703#if 0
704 {
John Daiker141fa612009-03-10 06:59:54 -0700705 int i;
706 printk(KERN_DEBUG
707 "verify_dl_startup parameters sent via ccs %d:\n",
708 local->dl_param_ccs);
709 for (i = 0; i < sizeof(struct b5_startup_params); i++) {
710 printk(" %2x",
711 (unsigned int)readb(local->sram +
712 HOST_TO_ECF_BASE + i));
713 }
714 printk("\n");
715 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700716#endif
717
John Daiker141fa612009-03-10 06:59:54 -0700718 status = readb(&pccs->buffer_status);
719 if (status != CCS_BUFFER_FREE) {
720 printk(KERN_INFO
721 "Download startup params failed. Status = %d\n",
722 status);
723 local->card_status = CARD_DL_PARAM_ERROR;
724 return;
725 }
726 if (local->sparm.b4.a_network_type == ADHOC)
727 start_net((u_long) local);
728 else
729 join_net((u_long) local);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700730
John Daiker141fa612009-03-10 06:59:54 -0700731 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700732} /* end verify_dl_startup */
John Daiker141fa612009-03-10 06:59:54 -0700733
Linus Torvalds1da177e2005-04-16 15:20:36 -0700734/*===========================================================================*/
735/* Command card to start a network */
736static void start_net(u_long data)
737{
John Daiker141fa612009-03-10 06:59:54 -0700738 ray_dev_t *local = (ray_dev_t *) data;
739 struct ccs __iomem *pccs;
740 int ccsindex;
741 struct pcmcia_device *link = local->finder;
742 if (!(pcmcia_dev_present(link))) {
Dominik Brodowski624dd662009-10-24 15:52:44 +0200743 dev_dbg(&link->dev, "ray_cs start_net - device not present\n");
John Daiker141fa612009-03-10 06:59:54 -0700744 return;
745 }
746 /* Fill in the CCS fields for the ECF */
747 if ((ccsindex = get_free_ccs(local)) < 0)
748 return;
749 pccs = ccs_base(local) + ccsindex;
750 writeb(CCS_START_NETWORK, &pccs->cmd);
751 writeb(0, &pccs->var.start_network.update_param);
752 /* Interrupt the firmware to process the command */
753 if (interrupt_ecf(local, ccsindex)) {
Dominik Brodowski624dd662009-10-24 15:52:44 +0200754 dev_dbg(&link->dev, "ray start net failed - card not ready for intr\n");
John Daiker141fa612009-03-10 06:59:54 -0700755 writeb(CCS_BUFFER_FREE, &(pccs++)->buffer_status);
756 return;
757 }
758 local->card_status = CARD_DOING_ACQ;
759 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700760} /* end start_net */
John Daiker141fa612009-03-10 06:59:54 -0700761
Linus Torvalds1da177e2005-04-16 15:20:36 -0700762/*===========================================================================*/
763/* Command card to join a network */
764static void join_net(u_long data)
765{
John Daiker141fa612009-03-10 06:59:54 -0700766 ray_dev_t *local = (ray_dev_t *) data;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700767
John Daiker141fa612009-03-10 06:59:54 -0700768 struct ccs __iomem *pccs;
769 int ccsindex;
770 struct pcmcia_device *link = local->finder;
771
772 if (!(pcmcia_dev_present(link))) {
Dominik Brodowski624dd662009-10-24 15:52:44 +0200773 dev_dbg(&link->dev, "ray_cs join_net - device not present\n");
John Daiker141fa612009-03-10 06:59:54 -0700774 return;
775 }
776 /* Fill in the CCS fields for the ECF */
777 if ((ccsindex = get_free_ccs(local)) < 0)
778 return;
779 pccs = ccs_base(local) + ccsindex;
780 writeb(CCS_JOIN_NETWORK, &pccs->cmd);
781 writeb(0, &pccs->var.join_network.update_param);
782 writeb(0, &pccs->var.join_network.net_initiated);
783 /* Interrupt the firmware to process the command */
784 if (interrupt_ecf(local, ccsindex)) {
Dominik Brodowski624dd662009-10-24 15:52:44 +0200785 dev_dbg(&link->dev, "ray join net failed - card not ready for intr\n");
John Daiker141fa612009-03-10 06:59:54 -0700786 writeb(CCS_BUFFER_FREE, &(pccs++)->buffer_status);
787 return;
788 }
789 local->card_status = CARD_DOING_ACQ;
790 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700791}
John Daiker141fa612009-03-10 06:59:54 -0700792
Linus Torvalds1da177e2005-04-16 15:20:36 -0700793/*============================================================================
794 After a card is removed, ray_release() will unregister the net
795 device, and release the PCMCIA configuration. If the device is
796 still open, this will be postponed until it is closed.
797=============================================================================*/
Dominik Brodowskifba395e2006-03-31 17:21:06 +0200798static void ray_release(struct pcmcia_device *link)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700799{
John Daiker141fa612009-03-10 06:59:54 -0700800 struct net_device *dev = link->priv;
801 ray_dev_t *local = netdev_priv(dev);
802 int i;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700803
Dominik Brodowski624dd662009-10-24 15:52:44 +0200804 dev_dbg(&link->dev, "ray_release\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700805
John Daiker141fa612009-03-10 06:59:54 -0700806 del_timer(&local->timer);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700807
John Daiker141fa612009-03-10 06:59:54 -0700808 iounmap(local->sram);
809 iounmap(local->rmem);
810 iounmap(local->amem);
811 /* Do bother checking to see if these succeed or not */
Magnus Dammf5560da2006-12-13 19:46:38 +0900812 i = pcmcia_release_window(link, local->amem_handle);
John Daiker141fa612009-03-10 06:59:54 -0700813 if (i != 0)
Dominik Brodowski624dd662009-10-24 15:52:44 +0200814 dev_dbg(&link->dev, "ReleaseWindow(local->amem) ret = %x\n", i);
Magnus Dammf5560da2006-12-13 19:46:38 +0900815 i = pcmcia_release_window(link, local->rmem_handle);
John Daiker141fa612009-03-10 06:59:54 -0700816 if (i != 0)
Dominik Brodowski624dd662009-10-24 15:52:44 +0200817 dev_dbg(&link->dev, "ReleaseWindow(local->rmem) ret = %x\n", i);
John Daiker141fa612009-03-10 06:59:54 -0700818 pcmcia_disable_device(link);
819
Dominik Brodowski624dd662009-10-24 15:52:44 +0200820 dev_dbg(&link->dev, "ray_release ending\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700821}
822
Dominik Brodowskifba395e2006-03-31 17:21:06 +0200823static int ray_suspend(struct pcmcia_device *link)
Dominik Brodowski98e4c282005-11-14 21:21:18 +0100824{
Dominik Brodowski98e4c282005-11-14 21:21:18 +0100825 struct net_device *dev = link->priv;
826
Dominik Brodowskie2d40962006-03-02 00:09:29 +0100827 if (link->open)
Dominik Brodowski8661bb52006-03-02 00:02:33 +0100828 netif_device_detach(dev);
Dominik Brodowski98e4c282005-11-14 21:21:18 +0100829
830 return 0;
831}
832
Dominik Brodowskifba395e2006-03-31 17:21:06 +0200833static int ray_resume(struct pcmcia_device *link)
Dominik Brodowski98e4c282005-11-14 21:21:18 +0100834{
Dominik Brodowski98e4c282005-11-14 21:21:18 +0100835 struct net_device *dev = link->priv;
836
Dominik Brodowskie2d40962006-03-02 00:09:29 +0100837 if (link->open) {
Dominik Brodowski8661bb52006-03-02 00:02:33 +0100838 ray_reset(dev);
839 netif_device_attach(dev);
840 }
Dominik Brodowski98e4c282005-11-14 21:21:18 +0100841
842 return 0;
843}
844
Linus Torvalds1da177e2005-04-16 15:20:36 -0700845/*===========================================================================*/
Hannes Eder2ed5ba82008-12-26 00:12:59 -0800846static int ray_dev_init(struct net_device *dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700847{
848#ifdef RAY_IMMEDIATE_INIT
John Daiker141fa612009-03-10 06:59:54 -0700849 int i;
850#endif /* RAY_IMMEDIATE_INIT */
851 ray_dev_t *local = netdev_priv(dev);
852 struct pcmcia_device *link = local->finder;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700853
Dominik Brodowski624dd662009-10-24 15:52:44 +0200854 dev_dbg(&link->dev, "ray_dev_init(dev=%p)\n", dev);
John Daiker141fa612009-03-10 06:59:54 -0700855 if (!(pcmcia_dev_present(link))) {
Dominik Brodowski624dd662009-10-24 15:52:44 +0200856 dev_dbg(&link->dev, "ray_dev_init - device not present\n");
John Daiker141fa612009-03-10 06:59:54 -0700857 return -1;
858 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700859#ifdef RAY_IMMEDIATE_INIT
John Daiker141fa612009-03-10 06:59:54 -0700860 /* Download startup parameters */
861 if ((i = dl_startup_params(dev)) < 0) {
862 printk(KERN_INFO "ray_dev_init dl_startup_params failed - "
863 "returns 0x%x\n", i);
864 return -1;
865 }
866#else /* RAY_IMMEDIATE_INIT */
867 /* Postpone the card init so that we can still configure the card,
868 * for example using the Wireless Extensions. The init will happen
869 * in ray_open() - Jean II */
Dominik Brodowski624dd662009-10-24 15:52:44 +0200870 dev_dbg(&link->dev,
John Daiker141fa612009-03-10 06:59:54 -0700871 "ray_dev_init: postponing card init to ray_open() ; Status = %d\n",
872 local->card_status);
873#endif /* RAY_IMMEDIATE_INIT */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700874
John Daiker141fa612009-03-10 06:59:54 -0700875 /* copy mac and broadcast addresses to linux device */
Jiri Pirko3a6d54c2009-05-11 23:37:15 +0000876 memcpy(dev->dev_addr, &local->sparm.b4.a_mac_addr, ADDRLEN);
John Daiker141fa612009-03-10 06:59:54 -0700877 memset(dev->broadcast, 0xff, ETH_ALEN);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700878
Dominik Brodowski624dd662009-10-24 15:52:44 +0200879 dev_dbg(&link->dev, "ray_dev_init ending\n");
John Daiker141fa612009-03-10 06:59:54 -0700880 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700881}
John Daiker141fa612009-03-10 06:59:54 -0700882
Linus Torvalds1da177e2005-04-16 15:20:36 -0700883/*===========================================================================*/
884static int ray_dev_config(struct net_device *dev, struct ifmap *map)
885{
John Daiker141fa612009-03-10 06:59:54 -0700886 ray_dev_t *local = netdev_priv(dev);
887 struct pcmcia_device *link = local->finder;
888 /* Dummy routine to satisfy device structure */
Dominik Brodowski624dd662009-10-24 15:52:44 +0200889 dev_dbg(&link->dev, "ray_dev_config(dev=%p,ifmap=%p)\n", dev, map);
John Daiker141fa612009-03-10 06:59:54 -0700890 if (!(pcmcia_dev_present(link))) {
Dominik Brodowski624dd662009-10-24 15:52:44 +0200891 dev_dbg(&link->dev, "ray_dev_config - device not present\n");
John Daiker141fa612009-03-10 06:59:54 -0700892 return -1;
893 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700894
John Daiker141fa612009-03-10 06:59:54 -0700895 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700896}
John Daiker141fa612009-03-10 06:59:54 -0700897
Linus Torvalds1da177e2005-04-16 15:20:36 -0700898/*===========================================================================*/
Stephen Hemmingerd0cf9c02009-08-31 19:50:57 +0000899static netdev_tx_t ray_dev_start_xmit(struct sk_buff *skb,
900 struct net_device *dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700901{
John Daiker141fa612009-03-10 06:59:54 -0700902 ray_dev_t *local = netdev_priv(dev);
903 struct pcmcia_device *link = local->finder;
904 short length = skb->len;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700905
Stephen Hemmingerd0cf9c02009-08-31 19:50:57 +0000906 if (!pcmcia_dev_present(link)) {
Dominik Brodowski624dd662009-10-24 15:52:44 +0200907 dev_dbg(&link->dev, "ray_dev_start_xmit - device not present\n");
Stephen Hemmingerd0cf9c02009-08-31 19:50:57 +0000908 dev_kfree_skb(skb);
909 return NETDEV_TX_OK;
John Daiker141fa612009-03-10 06:59:54 -0700910 }
Stephen Hemmingerd0cf9c02009-08-31 19:50:57 +0000911
Dominik Brodowski624dd662009-10-24 15:52:44 +0200912 dev_dbg(&link->dev, "ray_dev_start_xmit(skb=%p, dev=%p)\n", skb, dev);
John Daiker141fa612009-03-10 06:59:54 -0700913 if (local->authentication_state == NEED_TO_AUTH) {
Dominik Brodowski624dd662009-10-24 15:52:44 +0200914 dev_dbg(&link->dev, "ray_cs Sending authentication request.\n");
John Daiker141fa612009-03-10 06:59:54 -0700915 if (!build_auth_frame(local, local->auth_id, OPEN_AUTH_REQUEST)) {
916 local->authentication_state = AUTHENTICATED;
917 netif_stop_queue(dev);
Patrick McHardy5b548142009-06-12 06:22:29 +0000918 return NETDEV_TX_BUSY;
John Daiker141fa612009-03-10 06:59:54 -0700919 }
920 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700921
John Daiker141fa612009-03-10 06:59:54 -0700922 if (length < ETH_ZLEN) {
923 if (skb_padto(skb, ETH_ZLEN))
Patrick McHardy6ed10652009-06-23 06:03:08 +0000924 return NETDEV_TX_OK;
John Daiker141fa612009-03-10 06:59:54 -0700925 length = ETH_ZLEN;
926 }
927 switch (ray_hw_xmit(skb->data, length, dev, DATA_TYPE)) {
928 case XMIT_NO_CCS:
929 case XMIT_NEED_AUTH:
930 netif_stop_queue(dev);
Patrick McHardy5b548142009-06-12 06:22:29 +0000931 return NETDEV_TX_BUSY;
John Daiker141fa612009-03-10 06:59:54 -0700932 case XMIT_NO_INTR:
933 case XMIT_MSG_BAD:
934 case XMIT_OK:
935 default:
936 dev->trans_start = jiffies;
937 dev_kfree_skb(skb);
John Daiker141fa612009-03-10 06:59:54 -0700938 }
Stephen Hemmingerd0cf9c02009-08-31 19:50:57 +0000939
Patrick McHardy6ed10652009-06-23 06:03:08 +0000940 return NETDEV_TX_OK;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700941} /* ray_dev_start_xmit */
John Daiker141fa612009-03-10 06:59:54 -0700942
Linus Torvalds1da177e2005-04-16 15:20:36 -0700943/*===========================================================================*/
John Daiker141fa612009-03-10 06:59:54 -0700944static int ray_hw_xmit(unsigned char *data, int len, struct net_device *dev,
945 UCHAR msg_type)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700946{
John Daiker141fa612009-03-10 06:59:54 -0700947 ray_dev_t *local = netdev_priv(dev);
948 struct ccs __iomem *pccs;
949 int ccsindex;
950 int offset;
951 struct tx_msg __iomem *ptx; /* Address of xmit buffer in PC space */
952 short int addr; /* Address of xmit buffer in card space */
953
Dominik Brodowski624dd662009-10-24 15:52:44 +0200954 pr_debug("ray_hw_xmit(data=%p, len=%d, dev=%p)\n", data, len, dev);
John Daiker141fa612009-03-10 06:59:54 -0700955 if (len + TX_HEADER_LENGTH > TX_BUF_SIZE) {
956 printk(KERN_INFO "ray_hw_xmit packet too large: %d bytes\n",
957 len);
958 return XMIT_MSG_BAD;
959 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700960 switch (ccsindex = get_free_tx_ccs(local)) {
961 case ECCSBUSY:
Dominik Brodowski624dd662009-10-24 15:52:44 +0200962 pr_debug("ray_hw_xmit tx_ccs table busy\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700963 case ECCSFULL:
Dominik Brodowski624dd662009-10-24 15:52:44 +0200964 pr_debug("ray_hw_xmit No free tx ccs\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700965 case ECARDGONE:
John Daiker141fa612009-03-10 06:59:54 -0700966 netif_stop_queue(dev);
967 return XMIT_NO_CCS;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700968 default:
969 break;
970 }
John Daiker141fa612009-03-10 06:59:54 -0700971 addr = TX_BUF_BASE + (ccsindex << 11);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700972
John Daiker141fa612009-03-10 06:59:54 -0700973 if (msg_type == DATA_TYPE) {
974 local->stats.tx_bytes += len;
975 local->stats.tx_packets++;
976 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700977
John Daiker141fa612009-03-10 06:59:54 -0700978 ptx = local->sram + addr;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700979
John Daiker141fa612009-03-10 06:59:54 -0700980 ray_build_header(local, ptx, msg_type, data);
981 if (translate) {
982 offset = translate_frame(local, ptx, data, len);
983 } else { /* Encapsulate frame */
984 /* TBD TIB length will move address of ptx->var */
985 memcpy_toio(&ptx->var, data, len);
986 offset = 0;
987 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700988
John Daiker141fa612009-03-10 06:59:54 -0700989 /* fill in the CCS */
990 pccs = ccs_base(local) + ccsindex;
991 len += TX_HEADER_LENGTH + offset;
992 writeb(CCS_TX_REQUEST, &pccs->cmd);
993 writeb(addr >> 8, &pccs->var.tx_request.tx_data_ptr[0]);
994 writeb(local->tib_length, &pccs->var.tx_request.tx_data_ptr[1]);
995 writeb(len >> 8, &pccs->var.tx_request.tx_data_length[0]);
996 writeb(len & 0xff, &pccs->var.tx_request.tx_data_length[1]);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700997/* TBD still need psm_cam? */
John Daiker141fa612009-03-10 06:59:54 -0700998 writeb(PSM_CAM, &pccs->var.tx_request.pow_sav_mode);
999 writeb(local->net_default_tx_rate, &pccs->var.tx_request.tx_rate);
1000 writeb(0, &pccs->var.tx_request.antenna);
Dominik Brodowski624dd662009-10-24 15:52:44 +02001001 pr_debug("ray_hw_xmit default_tx_rate = 0x%x\n",
John Daiker141fa612009-03-10 06:59:54 -07001002 local->net_default_tx_rate);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001003
John Daiker141fa612009-03-10 06:59:54 -07001004 /* Interrupt the firmware to process the command */
1005 if (interrupt_ecf(local, ccsindex)) {
Dominik Brodowski624dd662009-10-24 15:52:44 +02001006 pr_debug("ray_hw_xmit failed - ECF not ready for intr\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001007/* TBD very inefficient to copy packet to buffer, and then not
1008 send it, but the alternative is to queue the messages and that
1009 won't be done for a while. Maybe set tbusy until a CCS is free?
1010*/
John Daiker141fa612009-03-10 06:59:54 -07001011 writeb(CCS_BUFFER_FREE, &pccs->buffer_status);
1012 return XMIT_NO_INTR;
1013 }
1014 return XMIT_OK;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001015} /* end ray_hw_xmit */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001016
John Daiker141fa612009-03-10 06:59:54 -07001017/*===========================================================================*/
1018static int translate_frame(ray_dev_t *local, struct tx_msg __iomem *ptx,
1019 unsigned char *data, int len)
1020{
1021 __be16 proto = ((struct ethhdr *)data)->h_proto;
1022 if (ntohs(proto) >= 1536) { /* DIX II ethernet frame */
Dominik Brodowski624dd662009-10-24 15:52:44 +02001023 pr_debug("ray_cs translate_frame DIX II\n");
John Daiker141fa612009-03-10 06:59:54 -07001024 /* Copy LLC header to card buffer */
1025 memcpy_toio(&ptx->var, eth2_llc, sizeof(eth2_llc));
1026 memcpy_toio(((void __iomem *)&ptx->var) + sizeof(eth2_llc),
1027 (UCHAR *) &proto, 2);
1028 if (proto == htons(ETH_P_AARP) || proto == htons(ETH_P_IPX)) {
1029 /* This is the selective translation table, only 2 entries */
1030 writeb(0xf8,
1031 &((struct snaphdr_t __iomem *)ptx->var)->org[3]);
1032 }
1033 /* Copy body of ethernet packet without ethernet header */
1034 memcpy_toio((void __iomem *)&ptx->var +
1035 sizeof(struct snaphdr_t), data + ETH_HLEN,
1036 len - ETH_HLEN);
1037 return (int)sizeof(struct snaphdr_t) - ETH_HLEN;
1038 } else { /* already 802 type, and proto is length */
Dominik Brodowski624dd662009-10-24 15:52:44 +02001039 pr_debug("ray_cs translate_frame 802\n");
John Daiker141fa612009-03-10 06:59:54 -07001040 if (proto == htons(0xffff)) { /* evil netware IPX 802.3 without LLC */
Dominik Brodowski624dd662009-10-24 15:52:44 +02001041 pr_debug("ray_cs translate_frame evil IPX\n");
John Daiker141fa612009-03-10 06:59:54 -07001042 memcpy_toio(&ptx->var, data + ETH_HLEN, len - ETH_HLEN);
1043 return 0 - ETH_HLEN;
1044 }
1045 memcpy_toio(&ptx->var, data + ETH_HLEN, len - ETH_HLEN);
1046 return 0 - ETH_HLEN;
1047 }
1048 /* TBD do other frame types */
1049} /* end translate_frame */
1050
1051/*===========================================================================*/
1052static void ray_build_header(ray_dev_t *local, struct tx_msg __iomem *ptx,
1053 UCHAR msg_type, unsigned char *data)
1054{
1055 writeb(PROTOCOL_VER | msg_type, &ptx->mac.frame_ctl_1);
1056/*** IEEE 802.11 Address field assignments *************
1057 TODS FROMDS addr_1 addr_2 addr_3 addr_4
1058Adhoc 0 0 dest src (terminal) BSSID N/A
1059AP to Terminal 0 1 dest AP(BSSID) source N/A
1060Terminal to AP 1 0 AP(BSSID) src (terminal) dest N/A
1061AP to AP 1 1 dest AP src AP dest source
1062*******************************************************/
1063 if (local->net_type == ADHOC) {
1064 writeb(0, &ptx->mac.frame_ctl_2);
1065 memcpy_toio(ptx->mac.addr_1, ((struct ethhdr *)data)->h_dest,
1066 2 * ADDRLEN);
1067 memcpy_toio(ptx->mac.addr_3, local->bss_id, ADDRLEN);
1068 } else { /* infrastructure */
1069
1070 if (local->sparm.b4.a_acting_as_ap_status) {
1071 writeb(FC2_FROM_DS, &ptx->mac.frame_ctl_2);
1072 memcpy_toio(ptx->mac.addr_1,
1073 ((struct ethhdr *)data)->h_dest, ADDRLEN);
1074 memcpy_toio(ptx->mac.addr_2, local->bss_id, 6);
1075 memcpy_toio(ptx->mac.addr_3,
1076 ((struct ethhdr *)data)->h_source, ADDRLEN);
1077 } else { /* Terminal */
1078
1079 writeb(FC2_TO_DS, &ptx->mac.frame_ctl_2);
1080 memcpy_toio(ptx->mac.addr_1, local->bss_id, ADDRLEN);
1081 memcpy_toio(ptx->mac.addr_2,
1082 ((struct ethhdr *)data)->h_source, ADDRLEN);
1083 memcpy_toio(ptx->mac.addr_3,
1084 ((struct ethhdr *)data)->h_dest, ADDRLEN);
1085 }
1086 }
1087} /* end encapsulate_frame */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001088
1089/*===========================================================================*/
1090
1091static void netdev_get_drvinfo(struct net_device *dev,
1092 struct ethtool_drvinfo *info)
1093{
1094 strcpy(info->driver, "ray_cs");
1095}
1096
Jeff Garzik7282d492006-09-13 14:30:00 -04001097static const struct ethtool_ops netdev_ethtool_ops = {
John Daiker141fa612009-03-10 06:59:54 -07001098 .get_drvinfo = netdev_get_drvinfo,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001099};
1100
1101/*====================================================================*/
1102
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001103/*------------------------------------------------------------------*/
1104/*
1105 * Wireless Handler : get protocol name
1106 */
1107static int ray_get_name(struct net_device *dev,
John Daiker141fa612009-03-10 06:59:54 -07001108 struct iw_request_info *info, char *cwrq, char *extra)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001109{
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001110 strcpy(cwrq, "IEEE 802.11-FH");
1111 return 0;
1112}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001113
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001114/*------------------------------------------------------------------*/
1115/*
1116 * Wireless Handler : set frequency
1117 */
1118static int ray_set_freq(struct net_device *dev,
1119 struct iw_request_info *info,
John Daiker141fa612009-03-10 06:59:54 -07001120 struct iw_freq *fwrq, char *extra)
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001121{
Yoann Padioleau6dbc9c82007-08-03 19:37:16 +02001122 ray_dev_t *local = netdev_priv(dev);
John Daiker141fa612009-03-10 06:59:54 -07001123 int err = -EINPROGRESS; /* Call commit handler */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001124
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001125 /* Reject if card is already initialised */
John Daiker141fa612009-03-10 06:59:54 -07001126 if (local->card_status != CARD_AWAITING_PARAM)
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001127 return -EBUSY;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001128
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001129 /* Setting by channel number */
1130 if ((fwrq->m > USA_HOP_MOD) || (fwrq->e > 0))
Linus Torvalds1da177e2005-04-16 15:20:36 -07001131 err = -EOPNOTSUPP;
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001132 else
1133 local->sparm.b5.a_hop_pattern = fwrq->m;
1134
1135 return err;
1136}
John Daiker141fa612009-03-10 06:59:54 -07001137
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001138/*------------------------------------------------------------------*/
1139/*
1140 * Wireless Handler : get frequency
1141 */
1142static int ray_get_freq(struct net_device *dev,
1143 struct iw_request_info *info,
John Daiker141fa612009-03-10 06:59:54 -07001144 struct iw_freq *fwrq, char *extra)
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001145{
Yoann Padioleau6dbc9c82007-08-03 19:37:16 +02001146 ray_dev_t *local = netdev_priv(dev);
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001147
1148 fwrq->m = local->sparm.b5.a_hop_pattern;
1149 fwrq->e = 0;
1150 return 0;
1151}
1152
1153/*------------------------------------------------------------------*/
1154/*
1155 * Wireless Handler : set ESSID
1156 */
1157static int ray_set_essid(struct net_device *dev,
1158 struct iw_request_info *info,
John Daiker141fa612009-03-10 06:59:54 -07001159 struct iw_point *dwrq, char *extra)
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001160{
Yoann Padioleau6dbc9c82007-08-03 19:37:16 +02001161 ray_dev_t *local = netdev_priv(dev);
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001162
1163 /* Reject if card is already initialised */
John Daiker141fa612009-03-10 06:59:54 -07001164 if (local->card_status != CARD_AWAITING_PARAM)
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001165 return -EBUSY;
1166
1167 /* Check if we asked for `any' */
John Daiker141fa612009-03-10 06:59:54 -07001168 if (dwrq->flags == 0) {
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001169 /* Corey : can you do that ? */
1170 return -EOPNOTSUPP;
1171 } else {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001172 /* Check the size of the string */
John Daiker141fa612009-03-10 06:59:54 -07001173 if (dwrq->length > IW_ESSID_MAX_SIZE) {
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001174 return -E2BIG;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001175 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001176
1177 /* Set the ESSID in the card */
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001178 memset(local->sparm.b5.a_current_ess_id, 0, IW_ESSID_MAX_SIZE);
1179 memcpy(local->sparm.b5.a_current_ess_id, extra, dwrq->length);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001180 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001181
John Daiker141fa612009-03-10 06:59:54 -07001182 return -EINPROGRESS; /* Call commit handler */
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001183}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001184
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001185/*------------------------------------------------------------------*/
1186/*
1187 * Wireless Handler : get ESSID
1188 */
1189static int ray_get_essid(struct net_device *dev,
1190 struct iw_request_info *info,
John Daiker141fa612009-03-10 06:59:54 -07001191 struct iw_point *dwrq, char *extra)
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001192{
Yoann Padioleau6dbc9c82007-08-03 19:37:16 +02001193 ray_dev_t *local = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001194
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001195 /* Get the essid that was set */
1196 memcpy(extra, local->sparm.b5.a_current_ess_id, IW_ESSID_MAX_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001197
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001198 /* Push it out ! */
Dan Williamsd6a13a22006-01-12 15:00:58 -05001199 dwrq->length = strlen(extra);
John Daiker141fa612009-03-10 06:59:54 -07001200 dwrq->flags = 1; /* active */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001201
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001202 return 0;
1203}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001204
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001205/*------------------------------------------------------------------*/
1206/*
1207 * Wireless Handler : get AP address
1208 */
1209static int ray_get_wap(struct net_device *dev,
John Daiker141fa612009-03-10 06:59:54 -07001210 struct iw_request_info *info,
1211 struct sockaddr *awrq, char *extra)
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001212{
Yoann Padioleau6dbc9c82007-08-03 19:37:16 +02001213 ray_dev_t *local = netdev_priv(dev);
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001214
1215 memcpy(awrq->sa_data, local->bss_id, ETH_ALEN);
1216 awrq->sa_family = ARPHRD_ETHER;
1217
1218 return 0;
1219}
1220
1221/*------------------------------------------------------------------*/
1222/*
1223 * Wireless Handler : set Bit-Rate
1224 */
1225static int ray_set_rate(struct net_device *dev,
1226 struct iw_request_info *info,
John Daiker141fa612009-03-10 06:59:54 -07001227 struct iw_param *vwrq, char *extra)
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001228{
Yoann Padioleau6dbc9c82007-08-03 19:37:16 +02001229 ray_dev_t *local = netdev_priv(dev);
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001230
1231 /* Reject if card is already initialised */
John Daiker141fa612009-03-10 06:59:54 -07001232 if (local->card_status != CARD_AWAITING_PARAM)
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001233 return -EBUSY;
1234
1235 /* Check if rate is in range */
John Daiker141fa612009-03-10 06:59:54 -07001236 if ((vwrq->value != 1000000) && (vwrq->value != 2000000))
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001237 return -EINVAL;
1238
1239 /* Hack for 1.5 Mb/s instead of 2 Mb/s */
John Daiker141fa612009-03-10 06:59:54 -07001240 if ((local->fw_ver == 0x55) && /* Please check */
1241 (vwrq->value == 2000000))
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001242 local->net_default_tx_rate = 3;
1243 else
John Daiker141fa612009-03-10 06:59:54 -07001244 local->net_default_tx_rate = vwrq->value / 500000;
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001245
1246 return 0;
1247}
1248
1249/*------------------------------------------------------------------*/
1250/*
1251 * Wireless Handler : get Bit-Rate
1252 */
1253static int ray_get_rate(struct net_device *dev,
1254 struct iw_request_info *info,
John Daiker141fa612009-03-10 06:59:54 -07001255 struct iw_param *vwrq, char *extra)
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001256{
Yoann Padioleau6dbc9c82007-08-03 19:37:16 +02001257 ray_dev_t *local = netdev_priv(dev);
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001258
John Daiker141fa612009-03-10 06:59:54 -07001259 if (local->net_default_tx_rate == 3)
1260 vwrq->value = 2000000; /* Hum... */
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001261 else
1262 vwrq->value = local->net_default_tx_rate * 500000;
John Daiker141fa612009-03-10 06:59:54 -07001263 vwrq->fixed = 0; /* We are in auto mode */
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001264
1265 return 0;
1266}
1267
1268/*------------------------------------------------------------------*/
1269/*
1270 * Wireless Handler : set RTS threshold
1271 */
1272static int ray_set_rts(struct net_device *dev,
1273 struct iw_request_info *info,
John Daiker141fa612009-03-10 06:59:54 -07001274 struct iw_param *vwrq, char *extra)
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001275{
Yoann Padioleau6dbc9c82007-08-03 19:37:16 +02001276 ray_dev_t *local = netdev_priv(dev);
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001277 int rthr = vwrq->value;
1278
1279 /* Reject if card is already initialised */
John Daiker141fa612009-03-10 06:59:54 -07001280 if (local->card_status != CARD_AWAITING_PARAM)
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001281 return -EBUSY;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001282
1283 /* if(wrq->u.rts.fixed == 0) we should complain */
John Daiker141fa612009-03-10 06:59:54 -07001284 if (vwrq->disabled)
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001285 rthr = 32767;
1286 else {
John Daiker141fa612009-03-10 06:59:54 -07001287 if ((rthr < 0) || (rthr > 2347)) /* What's the max packet size ??? */
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001288 return -EINVAL;
1289 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001290 local->sparm.b5.a_rts_threshold[0] = (rthr >> 8) & 0xFF;
1291 local->sparm.b5.a_rts_threshold[1] = rthr & 0xFF;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001292
John Daiker141fa612009-03-10 06:59:54 -07001293 return -EINPROGRESS; /* Call commit handler */
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001294}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001295
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001296/*------------------------------------------------------------------*/
1297/*
1298 * Wireless Handler : get RTS threshold
1299 */
1300static int ray_get_rts(struct net_device *dev,
1301 struct iw_request_info *info,
John Daiker141fa612009-03-10 06:59:54 -07001302 struct iw_param *vwrq, char *extra)
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001303{
Yoann Padioleau6dbc9c82007-08-03 19:37:16 +02001304 ray_dev_t *local = netdev_priv(dev);
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001305
1306 vwrq->value = (local->sparm.b5.a_rts_threshold[0] << 8)
John Daiker141fa612009-03-10 06:59:54 -07001307 + local->sparm.b5.a_rts_threshold[1];
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001308 vwrq->disabled = (vwrq->value == 32767);
1309 vwrq->fixed = 1;
1310
1311 return 0;
1312}
1313
1314/*------------------------------------------------------------------*/
1315/*
1316 * Wireless Handler : set Fragmentation threshold
1317 */
1318static int ray_set_frag(struct net_device *dev,
1319 struct iw_request_info *info,
John Daiker141fa612009-03-10 06:59:54 -07001320 struct iw_param *vwrq, char *extra)
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001321{
Yoann Padioleau6dbc9c82007-08-03 19:37:16 +02001322 ray_dev_t *local = netdev_priv(dev);
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001323 int fthr = vwrq->value;
1324
1325 /* Reject if card is already initialised */
John Daiker141fa612009-03-10 06:59:54 -07001326 if (local->card_status != CARD_AWAITING_PARAM)
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001327 return -EBUSY;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001328
1329 /* if(wrq->u.frag.fixed == 0) should complain */
John Daiker141fa612009-03-10 06:59:54 -07001330 if (vwrq->disabled)
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001331 fthr = 32767;
1332 else {
John Daiker141fa612009-03-10 06:59:54 -07001333 if ((fthr < 256) || (fthr > 2347)) /* To check out ! */
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001334 return -EINVAL;
1335 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001336 local->sparm.b5.a_frag_threshold[0] = (fthr >> 8) & 0xFF;
1337 local->sparm.b5.a_frag_threshold[1] = fthr & 0xFF;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001338
John Daiker141fa612009-03-10 06:59:54 -07001339 return -EINPROGRESS; /* Call commit handler */
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001340}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001341
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001342/*------------------------------------------------------------------*/
1343/*
1344 * Wireless Handler : get Fragmentation threshold
1345 */
1346static int ray_get_frag(struct net_device *dev,
1347 struct iw_request_info *info,
John Daiker141fa612009-03-10 06:59:54 -07001348 struct iw_param *vwrq, char *extra)
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001349{
Yoann Padioleau6dbc9c82007-08-03 19:37:16 +02001350 ray_dev_t *local = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001351
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001352 vwrq->value = (local->sparm.b5.a_frag_threshold[0] << 8)
John Daiker141fa612009-03-10 06:59:54 -07001353 + local->sparm.b5.a_frag_threshold[1];
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001354 vwrq->disabled = (vwrq->value == 32767);
1355 vwrq->fixed = 1;
1356
1357 return 0;
1358}
1359
1360/*------------------------------------------------------------------*/
1361/*
1362 * Wireless Handler : set Mode of Operation
1363 */
1364static int ray_set_mode(struct net_device *dev,
John Daiker141fa612009-03-10 06:59:54 -07001365 struct iw_request_info *info, __u32 *uwrq, char *extra)
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001366{
Yoann Padioleau6dbc9c82007-08-03 19:37:16 +02001367 ray_dev_t *local = netdev_priv(dev);
John Daiker141fa612009-03-10 06:59:54 -07001368 int err = -EINPROGRESS; /* Call commit handler */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001369 char card_mode = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001370
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001371 /* Reject if card is already initialised */
John Daiker141fa612009-03-10 06:59:54 -07001372 if (local->card_status != CARD_AWAITING_PARAM)
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001373 return -EBUSY;
1374
John Daiker141fa612009-03-10 06:59:54 -07001375 switch (*uwrq) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001376 case IW_MODE_ADHOC:
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001377 card_mode = 0;
John Daiker141fa612009-03-10 06:59:54 -07001378 /* Fall through */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001379 case IW_MODE_INFRA:
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001380 local->sparm.b5.a_network_type = card_mode;
1381 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001382 default:
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001383 err = -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001384 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001385
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001386 return err;
1387}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001388
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001389/*------------------------------------------------------------------*/
1390/*
1391 * Wireless Handler : get Mode of Operation
1392 */
1393static int ray_get_mode(struct net_device *dev,
John Daiker141fa612009-03-10 06:59:54 -07001394 struct iw_request_info *info, __u32 *uwrq, char *extra)
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001395{
Yoann Padioleau6dbc9c82007-08-03 19:37:16 +02001396 ray_dev_t *local = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001397
John Daiker141fa612009-03-10 06:59:54 -07001398 if (local->sparm.b5.a_network_type)
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001399 *uwrq = IW_MODE_INFRA;
1400 else
1401 *uwrq = IW_MODE_ADHOC;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001402
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001403 return 0;
1404}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001405
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001406/*------------------------------------------------------------------*/
1407/*
1408 * Wireless Handler : get range info
1409 */
1410static int ray_get_range(struct net_device *dev,
1411 struct iw_request_info *info,
John Daiker141fa612009-03-10 06:59:54 -07001412 struct iw_point *dwrq, char *extra)
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001413{
John Daiker141fa612009-03-10 06:59:54 -07001414 struct iw_range *range = (struct iw_range *)extra;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001415
John Daiker141fa612009-03-10 06:59:54 -07001416 memset((char *)range, 0, sizeof(struct iw_range));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001417
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001418 /* Set the length (very important for backward compatibility) */
1419 dwrq->length = sizeof(struct iw_range);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001420
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001421 /* Set the Wireless Extension versions */
1422 range->we_version_compiled = WIRELESS_EXT;
1423 range->we_version_source = 9;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001424
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001425 /* Set information in the range struct */
1426 range->throughput = 1.1 * 1000 * 1000; /* Put the right number here */
John Daiker141fa612009-03-10 06:59:54 -07001427 range->num_channels = hop_pattern_length[(int)country];
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001428 range->num_frequency = 0;
1429 range->max_qual.qual = 0;
1430 range->max_qual.level = 255; /* What's the correct value ? */
1431 range->max_qual.noise = 255; /* Idem */
1432 range->num_bitrates = 2;
1433 range->bitrate[0] = 1000000; /* 1 Mb/s */
1434 range->bitrate[1] = 2000000; /* 2 Mb/s */
1435 return 0;
1436}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001437
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001438/*------------------------------------------------------------------*/
1439/*
1440 * Wireless Private Handler : set framing mode
1441 */
1442static int ray_set_framing(struct net_device *dev,
1443 struct iw_request_info *info,
John Daiker141fa612009-03-10 06:59:54 -07001444 union iwreq_data *wrqu, char *extra)
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001445{
1446 translate = *(extra); /* Set framing mode */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001447
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001448 return 0;
1449}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001450
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001451/*------------------------------------------------------------------*/
1452/*
1453 * Wireless Private Handler : get framing mode
1454 */
1455static int ray_get_framing(struct net_device *dev,
1456 struct iw_request_info *info,
John Daiker141fa612009-03-10 06:59:54 -07001457 union iwreq_data *wrqu, char *extra)
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001458{
1459 *(extra) = translate;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001460
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001461 return 0;
1462}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001463
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001464/*------------------------------------------------------------------*/
1465/*
1466 * Wireless Private Handler : get country
1467 */
1468static int ray_get_country(struct net_device *dev,
1469 struct iw_request_info *info,
John Daiker141fa612009-03-10 06:59:54 -07001470 union iwreq_data *wrqu, char *extra)
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001471{
1472 *(extra) = country;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001473
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001474 return 0;
1475}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001476
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001477/*------------------------------------------------------------------*/
1478/*
1479 * Commit handler : called after a bunch of SET operations
1480 */
John Daiker141fa612009-03-10 06:59:54 -07001481static int ray_commit(struct net_device *dev, struct iw_request_info *info, /* NULL */
1482 void *zwrq, /* NULL */
1483 char *extra)
1484{ /* NULL */
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001485 return 0;
1486}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001487
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001488/*------------------------------------------------------------------*/
1489/*
1490 * Stats handler : return Wireless Stats
1491 */
John Daiker141fa612009-03-10 06:59:54 -07001492static iw_stats *ray_get_wireless_stats(struct net_device *dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001493{
John Daiker141fa612009-03-10 06:59:54 -07001494 ray_dev_t *local = netdev_priv(dev);
1495 struct pcmcia_device *link = local->finder;
1496 struct status __iomem *p = local->sram + STATUS_BASE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001497
John Daiker141fa612009-03-10 06:59:54 -07001498 local->wstats.status = local->card_status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001499#ifdef WIRELESS_SPY
John Daiker141fa612009-03-10 06:59:54 -07001500 if ((local->spy_data.spy_number > 0)
1501 && (local->sparm.b5.a_network_type == 0)) {
1502 /* Get it from the first node in spy list */
1503 local->wstats.qual.qual = local->spy_data.spy_stat[0].qual;
1504 local->wstats.qual.level = local->spy_data.spy_stat[0].level;
1505 local->wstats.qual.noise = local->spy_data.spy_stat[0].noise;
1506 local->wstats.qual.updated =
1507 local->spy_data.spy_stat[0].updated;
1508 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001509#endif /* WIRELESS_SPY */
1510
John Daiker141fa612009-03-10 06:59:54 -07001511 if (pcmcia_dev_present(link)) {
1512 local->wstats.qual.noise = readb(&p->rxnoise);
1513 local->wstats.qual.updated |= 4;
1514 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001515
John Daiker141fa612009-03-10 06:59:54 -07001516 return &local->wstats;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001517} /* end ray_get_wireless_stats */
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001518
1519/*------------------------------------------------------------------*/
1520/*
1521 * Structures to export the Wireless Handlers
1522 */
1523
John Daiker141fa612009-03-10 06:59:54 -07001524static const iw_handler ray_handler[] = {
1525 [SIOCSIWCOMMIT - SIOCIWFIRST] = (iw_handler) ray_commit,
1526 [SIOCGIWNAME - SIOCIWFIRST] = (iw_handler) ray_get_name,
1527 [SIOCSIWFREQ - SIOCIWFIRST] = (iw_handler) ray_set_freq,
1528 [SIOCGIWFREQ - SIOCIWFIRST] = (iw_handler) ray_get_freq,
1529 [SIOCSIWMODE - SIOCIWFIRST] = (iw_handler) ray_set_mode,
1530 [SIOCGIWMODE - SIOCIWFIRST] = (iw_handler) ray_get_mode,
1531 [SIOCGIWRANGE - SIOCIWFIRST] = (iw_handler) ray_get_range,
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001532#ifdef WIRELESS_SPY
John Daiker141fa612009-03-10 06:59:54 -07001533 [SIOCSIWSPY - SIOCIWFIRST] = (iw_handler) iw_handler_set_spy,
1534 [SIOCGIWSPY - SIOCIWFIRST] = (iw_handler) iw_handler_get_spy,
1535 [SIOCSIWTHRSPY - SIOCIWFIRST] = (iw_handler) iw_handler_set_thrspy,
1536 [SIOCGIWTHRSPY - SIOCIWFIRST] = (iw_handler) iw_handler_get_thrspy,
1537#endif /* WIRELESS_SPY */
1538 [SIOCGIWAP - SIOCIWFIRST] = (iw_handler) ray_get_wap,
1539 [SIOCSIWESSID - SIOCIWFIRST] = (iw_handler) ray_set_essid,
1540 [SIOCGIWESSID - SIOCIWFIRST] = (iw_handler) ray_get_essid,
1541 [SIOCSIWRATE - SIOCIWFIRST] = (iw_handler) ray_set_rate,
1542 [SIOCGIWRATE - SIOCIWFIRST] = (iw_handler) ray_get_rate,
1543 [SIOCSIWRTS - SIOCIWFIRST] = (iw_handler) ray_set_rts,
1544 [SIOCGIWRTS - SIOCIWFIRST] = (iw_handler) ray_get_rts,
1545 [SIOCSIWFRAG - SIOCIWFIRST] = (iw_handler) ray_set_frag,
1546 [SIOCGIWFRAG - SIOCIWFIRST] = (iw_handler) ray_get_frag,
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001547};
1548
John Daiker141fa612009-03-10 06:59:54 -07001549#define SIOCSIPFRAMING SIOCIWFIRSTPRIV /* Set framing mode */
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001550#define SIOCGIPFRAMING SIOCIWFIRSTPRIV + 1 /* Get framing mode */
1551#define SIOCGIPCOUNTRY SIOCIWFIRSTPRIV + 3 /* Get country code */
1552
John Daiker141fa612009-03-10 06:59:54 -07001553static const iw_handler ray_private_handler[] = {
viro@ZenIV.linux.org.uk7a700fa2005-09-09 20:40:23 +01001554 [0] = (iw_handler) ray_set_framing,
1555 [1] = (iw_handler) ray_get_framing,
1556 [3] = (iw_handler) ray_get_country,
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001557};
1558
John Daiker141fa612009-03-10 06:59:54 -07001559static const struct iw_priv_args ray_private_args[] = {
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001560/* cmd, set_args, get_args, name */
John Daiker141fa612009-03-10 06:59:54 -07001561 {SIOCSIPFRAMING, IW_PRIV_TYPE_BYTE | IW_PRIV_SIZE_FIXED | 1, 0,
1562 "set_framing"},
1563 {SIOCGIPFRAMING, 0, IW_PRIV_TYPE_BYTE | IW_PRIV_SIZE_FIXED | 1,
1564 "get_framing"},
1565 {SIOCGIPCOUNTRY, 0, IW_PRIV_TYPE_BYTE | IW_PRIV_SIZE_FIXED | 1,
1566 "get_country"},
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001567};
1568
John Daiker141fa612009-03-10 06:59:54 -07001569static const struct iw_handler_def ray_handler_def = {
1570 .num_standard = ARRAY_SIZE(ray_handler),
1571 .num_private = ARRAY_SIZE(ray_private_handler),
Denis Chengff8ac602007-09-02 18:30:18 +08001572 .num_private_args = ARRAY_SIZE(ray_private_args),
John Daiker141fa612009-03-10 06:59:54 -07001573 .standard = ray_handler,
1574 .private = ray_private_handler,
1575 .private_args = ray_private_args,
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001576 .get_wireless_stats = ray_get_wireless_stats,
1577};
1578
Linus Torvalds1da177e2005-04-16 15:20:36 -07001579/*===========================================================================*/
1580static int ray_open(struct net_device *dev)
1581{
John Daiker141fa612009-03-10 06:59:54 -07001582 ray_dev_t *local = netdev_priv(dev);
1583 struct pcmcia_device *link;
1584 link = local->finder;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001585
Dominik Brodowski624dd662009-10-24 15:52:44 +02001586 dev_dbg(&link->dev, "ray_open('%s')\n", dev->name);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001587
John Daiker141fa612009-03-10 06:59:54 -07001588 if (link->open == 0)
1589 local->num_multi = 0;
1590 link->open++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001591
John Daiker141fa612009-03-10 06:59:54 -07001592 /* If the card is not started, time to start it ! - Jean II */
1593 if (local->card_status == CARD_AWAITING_PARAM) {
1594 int i;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001595
Dominik Brodowski624dd662009-10-24 15:52:44 +02001596 dev_dbg(&link->dev, "ray_open: doing init now !\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001597
John Daiker141fa612009-03-10 06:59:54 -07001598 /* Download startup parameters */
1599 if ((i = dl_startup_params(dev)) < 0) {
1600 printk(KERN_INFO
1601 "ray_dev_init dl_startup_params failed - "
1602 "returns 0x%x\n", i);
1603 return -1;
1604 }
1605 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001606
John Daiker141fa612009-03-10 06:59:54 -07001607 if (sniffer)
1608 netif_stop_queue(dev);
1609 else
1610 netif_start_queue(dev);
1611
Dominik Brodowski624dd662009-10-24 15:52:44 +02001612 dev_dbg(&link->dev, "ray_open ending\n");
John Daiker141fa612009-03-10 06:59:54 -07001613 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001614} /* end ray_open */
John Daiker141fa612009-03-10 06:59:54 -07001615
Linus Torvalds1da177e2005-04-16 15:20:36 -07001616/*===========================================================================*/
1617static int ray_dev_close(struct net_device *dev)
1618{
John Daiker141fa612009-03-10 06:59:54 -07001619 ray_dev_t *local = netdev_priv(dev);
1620 struct pcmcia_device *link;
1621 link = local->finder;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001622
Dominik Brodowski624dd662009-10-24 15:52:44 +02001623 dev_dbg(&link->dev, "ray_dev_close('%s')\n", dev->name);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001624
John Daiker141fa612009-03-10 06:59:54 -07001625 link->open--;
1626 netif_stop_queue(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001627
John Daiker141fa612009-03-10 06:59:54 -07001628 /* In here, we should stop the hardware (stop card from beeing active)
1629 * and set local->card_status to CARD_AWAITING_PARAM, so that while the
1630 * card is closed we can chage its configuration.
1631 * Probably also need a COR reset to get sane state - Jean II */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001632
John Daiker141fa612009-03-10 06:59:54 -07001633 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001634} /* end ray_dev_close */
John Daiker141fa612009-03-10 06:59:54 -07001635
Linus Torvalds1da177e2005-04-16 15:20:36 -07001636/*===========================================================================*/
John Daiker141fa612009-03-10 06:59:54 -07001637static void ray_reset(struct net_device *dev)
1638{
Dominik Brodowski624dd662009-10-24 15:52:44 +02001639 pr_debug("ray_reset entered\n");
John Daiker141fa612009-03-10 06:59:54 -07001640 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001641}
John Daiker141fa612009-03-10 06:59:54 -07001642
Linus Torvalds1da177e2005-04-16 15:20:36 -07001643/*===========================================================================*/
1644/* Cause a firmware interrupt if it is ready for one */
1645/* Return nonzero if not ready */
1646static int interrupt_ecf(ray_dev_t *local, int ccs)
1647{
John Daiker141fa612009-03-10 06:59:54 -07001648 int i = 50;
1649 struct pcmcia_device *link = local->finder;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001650
John Daiker141fa612009-03-10 06:59:54 -07001651 if (!(pcmcia_dev_present(link))) {
Dominik Brodowski624dd662009-10-24 15:52:44 +02001652 dev_dbg(&link->dev, "ray_cs interrupt_ecf - device not present\n");
John Daiker141fa612009-03-10 06:59:54 -07001653 return -1;
1654 }
Dominik Brodowski624dd662009-10-24 15:52:44 +02001655 dev_dbg(&link->dev, "interrupt_ecf(local=%p, ccs = 0x%x\n", local, ccs);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001656
John Daiker141fa612009-03-10 06:59:54 -07001657 while (i &&
1658 (readb(local->amem + CIS_OFFSET + ECF_INTR_OFFSET) &
1659 ECF_INTR_SET))
1660 i--;
1661 if (i == 0) {
Dominik Brodowski624dd662009-10-24 15:52:44 +02001662 dev_dbg(&link->dev, "ray_cs interrupt_ecf card not ready for interrupt\n");
John Daiker141fa612009-03-10 06:59:54 -07001663 return -1;
1664 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001665 /* Fill the mailbox, then kick the card */
John Daiker141fa612009-03-10 06:59:54 -07001666 writeb(ccs, local->sram + SCB_BASE);
1667 writeb(ECF_INTR_SET, local->amem + CIS_OFFSET + ECF_INTR_OFFSET);
1668 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001669} /* interrupt_ecf */
John Daiker141fa612009-03-10 06:59:54 -07001670
Linus Torvalds1da177e2005-04-16 15:20:36 -07001671/*===========================================================================*/
1672/* Get next free transmit CCS */
1673/* Return - index of current tx ccs */
1674static int get_free_tx_ccs(ray_dev_t *local)
1675{
John Daiker141fa612009-03-10 06:59:54 -07001676 int i;
1677 struct ccs __iomem *pccs = ccs_base(local);
1678 struct pcmcia_device *link = local->finder;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001679
John Daiker141fa612009-03-10 06:59:54 -07001680 if (!(pcmcia_dev_present(link))) {
Dominik Brodowski624dd662009-10-24 15:52:44 +02001681 dev_dbg(&link->dev, "ray_cs get_free_tx_ccs - device not present\n");
John Daiker141fa612009-03-10 06:59:54 -07001682 return ECARDGONE;
1683 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001684
John Daiker141fa612009-03-10 06:59:54 -07001685 if (test_and_set_bit(0, &local->tx_ccs_lock)) {
Dominik Brodowski624dd662009-10-24 15:52:44 +02001686 dev_dbg(&link->dev, "ray_cs tx_ccs_lock busy\n");
John Daiker141fa612009-03-10 06:59:54 -07001687 return ECCSBUSY;
1688 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001689
John Daiker141fa612009-03-10 06:59:54 -07001690 for (i = 0; i < NUMBER_OF_TX_CCS; i++) {
1691 if (readb(&(pccs + i)->buffer_status) == CCS_BUFFER_FREE) {
1692 writeb(CCS_BUFFER_BUSY, &(pccs + i)->buffer_status);
1693 writeb(CCS_END_LIST, &(pccs + i)->link);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001694 local->tx_ccs_lock = 0;
John Daiker141fa612009-03-10 06:59:54 -07001695 return i;
1696 }
1697 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001698 local->tx_ccs_lock = 0;
Dominik Brodowski624dd662009-10-24 15:52:44 +02001699 dev_dbg(&link->dev, "ray_cs ERROR no free tx CCS for raylink card\n");
John Daiker141fa612009-03-10 06:59:54 -07001700 return ECCSFULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001701} /* get_free_tx_ccs */
John Daiker141fa612009-03-10 06:59:54 -07001702
Linus Torvalds1da177e2005-04-16 15:20:36 -07001703/*===========================================================================*/
1704/* Get next free CCS */
1705/* Return - index of current ccs */
1706static int get_free_ccs(ray_dev_t *local)
1707{
John Daiker141fa612009-03-10 06:59:54 -07001708 int i;
1709 struct ccs __iomem *pccs = ccs_base(local);
1710 struct pcmcia_device *link = local->finder;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001711
John Daiker141fa612009-03-10 06:59:54 -07001712 if (!(pcmcia_dev_present(link))) {
Dominik Brodowski624dd662009-10-24 15:52:44 +02001713 dev_dbg(&link->dev, "ray_cs get_free_ccs - device not present\n");
John Daiker141fa612009-03-10 06:59:54 -07001714 return ECARDGONE;
1715 }
1716 if (test_and_set_bit(0, &local->ccs_lock)) {
Dominik Brodowski624dd662009-10-24 15:52:44 +02001717 dev_dbg(&link->dev, "ray_cs ccs_lock busy\n");
John Daiker141fa612009-03-10 06:59:54 -07001718 return ECCSBUSY;
1719 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001720
John Daiker141fa612009-03-10 06:59:54 -07001721 for (i = NUMBER_OF_TX_CCS; i < NUMBER_OF_CCS; i++) {
1722 if (readb(&(pccs + i)->buffer_status) == CCS_BUFFER_FREE) {
1723 writeb(CCS_BUFFER_BUSY, &(pccs + i)->buffer_status);
1724 writeb(CCS_END_LIST, &(pccs + i)->link);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001725 local->ccs_lock = 0;
John Daiker141fa612009-03-10 06:59:54 -07001726 return i;
1727 }
1728 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001729 local->ccs_lock = 0;
Dominik Brodowski624dd662009-10-24 15:52:44 +02001730 dev_dbg(&link->dev, "ray_cs ERROR no free CCS for raylink card\n");
John Daiker141fa612009-03-10 06:59:54 -07001731 return ECCSFULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001732} /* get_free_ccs */
John Daiker141fa612009-03-10 06:59:54 -07001733
Linus Torvalds1da177e2005-04-16 15:20:36 -07001734/*===========================================================================*/
1735static void authenticate_timeout(u_long data)
1736{
John Daiker141fa612009-03-10 06:59:54 -07001737 ray_dev_t *local = (ray_dev_t *) data;
1738 del_timer(&local->timer);
1739 printk(KERN_INFO "ray_cs Authentication with access point failed"
1740 " - timeout\n");
1741 join_net((u_long) local);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001742}
John Daiker141fa612009-03-10 06:59:54 -07001743
Linus Torvalds1da177e2005-04-16 15:20:36 -07001744/*===========================================================================*/
1745static int asc_to_int(char a)
1746{
John Daiker141fa612009-03-10 06:59:54 -07001747 if (a < '0')
1748 return -1;
1749 if (a <= '9')
1750 return (a - '0');
1751 if (a < 'A')
1752 return -1;
1753 if (a <= 'F')
1754 return (10 + a - 'A');
1755 if (a < 'a')
1756 return -1;
1757 if (a <= 'f')
1758 return (10 + a - 'a');
1759 return -1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001760}
John Daiker141fa612009-03-10 06:59:54 -07001761
Linus Torvalds1da177e2005-04-16 15:20:36 -07001762/*===========================================================================*/
1763static int parse_addr(char *in_str, UCHAR *out)
1764{
John Daiker141fa612009-03-10 06:59:54 -07001765 int len;
1766 int i, j, k;
1767 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001768
John Daiker141fa612009-03-10 06:59:54 -07001769 if (in_str == NULL)
1770 return 0;
1771 if ((len = strlen(in_str)) < 2)
1772 return 0;
1773 memset(out, 0, ADDRLEN);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001774
John Daiker141fa612009-03-10 06:59:54 -07001775 status = 1;
1776 j = len - 1;
1777 if (j > 12)
1778 j = 12;
1779 i = 5;
1780
1781 while (j > 0) {
1782 if ((k = asc_to_int(in_str[j--])) != -1)
1783 out[i] = k;
1784 else
1785 return 0;
1786
1787 if (j == 0)
1788 break;
1789 if ((k = asc_to_int(in_str[j--])) != -1)
1790 out[i] += k << 4;
1791 else
1792 return 0;
1793 if (!i--)
1794 break;
1795 }
1796 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001797}
John Daiker141fa612009-03-10 06:59:54 -07001798
Linus Torvalds1da177e2005-04-16 15:20:36 -07001799/*===========================================================================*/
1800static struct net_device_stats *ray_get_stats(struct net_device *dev)
1801{
John Daiker141fa612009-03-10 06:59:54 -07001802 ray_dev_t *local = netdev_priv(dev);
1803 struct pcmcia_device *link = local->finder;
1804 struct status __iomem *p = local->sram + STATUS_BASE;
1805 if (!(pcmcia_dev_present(link))) {
Dominik Brodowski624dd662009-10-24 15:52:44 +02001806 dev_dbg(&link->dev, "ray_cs net_device_stats - device not present\n");
John Daiker141fa612009-03-10 06:59:54 -07001807 return &local->stats;
1808 }
1809 if (readb(&p->mrx_overflow_for_host)) {
1810 local->stats.rx_over_errors += swab16(readw(&p->mrx_overflow));
1811 writeb(0, &p->mrx_overflow);
1812 writeb(0, &p->mrx_overflow_for_host);
1813 }
1814 if (readb(&p->mrx_checksum_error_for_host)) {
1815 local->stats.rx_crc_errors +=
1816 swab16(readw(&p->mrx_checksum_error));
1817 writeb(0, &p->mrx_checksum_error);
1818 writeb(0, &p->mrx_checksum_error_for_host);
1819 }
1820 if (readb(&p->rx_hec_error_for_host)) {
1821 local->stats.rx_frame_errors += swab16(readw(&p->rx_hec_error));
1822 writeb(0, &p->rx_hec_error);
1823 writeb(0, &p->rx_hec_error_for_host);
1824 }
1825 return &local->stats;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001826}
John Daiker141fa612009-03-10 06:59:54 -07001827
Linus Torvalds1da177e2005-04-16 15:20:36 -07001828/*===========================================================================*/
John Daiker141fa612009-03-10 06:59:54 -07001829static void ray_update_parm(struct net_device *dev, UCHAR objid, UCHAR *value,
1830 int len)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001831{
John Daiker141fa612009-03-10 06:59:54 -07001832 ray_dev_t *local = netdev_priv(dev);
1833 struct pcmcia_device *link = local->finder;
1834 int ccsindex;
1835 int i;
1836 struct ccs __iomem *pccs;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001837
John Daiker141fa612009-03-10 06:59:54 -07001838 if (!(pcmcia_dev_present(link))) {
Dominik Brodowski624dd662009-10-24 15:52:44 +02001839 dev_dbg(&link->dev, "ray_update_parm - device not present\n");
John Daiker141fa612009-03-10 06:59:54 -07001840 return;
1841 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001842
John Daiker141fa612009-03-10 06:59:54 -07001843 if ((ccsindex = get_free_ccs(local)) < 0) {
Dominik Brodowski624dd662009-10-24 15:52:44 +02001844 dev_dbg(&link->dev, "ray_update_parm - No free ccs\n");
John Daiker141fa612009-03-10 06:59:54 -07001845 return;
1846 }
1847 pccs = ccs_base(local) + ccsindex;
1848 writeb(CCS_UPDATE_PARAMS, &pccs->cmd);
1849 writeb(objid, &pccs->var.update_param.object_id);
1850 writeb(1, &pccs->var.update_param.number_objects);
1851 writeb(0, &pccs->var.update_param.failure_cause);
1852 for (i = 0; i < len; i++) {
1853 writeb(value[i], local->sram + HOST_TO_ECF_BASE);
1854 }
1855 /* Interrupt the firmware to process the command */
1856 if (interrupt_ecf(local, ccsindex)) {
Dominik Brodowski624dd662009-10-24 15:52:44 +02001857 dev_dbg(&link->dev, "ray_cs associate failed - ECF not ready for intr\n");
John Daiker141fa612009-03-10 06:59:54 -07001858 writeb(CCS_BUFFER_FREE, &(pccs++)->buffer_status);
1859 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001860}
John Daiker141fa612009-03-10 06:59:54 -07001861
Linus Torvalds1da177e2005-04-16 15:20:36 -07001862/*===========================================================================*/
1863static void ray_update_multi_list(struct net_device *dev, int all)
1864{
John Daiker141fa612009-03-10 06:59:54 -07001865 int ccsindex;
1866 struct ccs __iomem *pccs;
John Daiker141fa612009-03-10 06:59:54 -07001867 ray_dev_t *local = netdev_priv(dev);
1868 struct pcmcia_device *link = local->finder;
1869 void __iomem *p = local->sram + HOST_TO_ECF_BASE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001870
John Daiker141fa612009-03-10 06:59:54 -07001871 if (!(pcmcia_dev_present(link))) {
Dominik Brodowski624dd662009-10-24 15:52:44 +02001872 dev_dbg(&link->dev, "ray_update_multi_list - device not present\n");
John Daiker141fa612009-03-10 06:59:54 -07001873 return;
1874 } else
Dominik Brodowski624dd662009-10-24 15:52:44 +02001875 dev_dbg(&link->dev, "ray_update_multi_list(%p)\n", dev);
John Daiker141fa612009-03-10 06:59:54 -07001876 if ((ccsindex = get_free_ccs(local)) < 0) {
Dominik Brodowski624dd662009-10-24 15:52:44 +02001877 dev_dbg(&link->dev, "ray_update_multi - No free ccs\n");
John Daiker141fa612009-03-10 06:59:54 -07001878 return;
1879 }
1880 pccs = ccs_base(local) + ccsindex;
1881 writeb(CCS_UPDATE_MULTICAST_LIST, &pccs->cmd);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001882
John Daiker141fa612009-03-10 06:59:54 -07001883 if (all) {
1884 writeb(0xff, &pccs->var);
1885 local->num_multi = 0xff;
1886 } else {
Jiri Pirko655ffee2010-02-27 07:35:45 +00001887 struct dev_mc_list *dmi;
1888 int i = 0;
1889
John Daiker141fa612009-03-10 06:59:54 -07001890 /* Copy the kernel's list of MC addresses to card */
Jiri Pirko655ffee2010-02-27 07:35:45 +00001891 netdev_for_each_mc_addr(dmi, dev) {
John Daiker141fa612009-03-10 06:59:54 -07001892 memcpy_toio(p, dmi->dmi_addr, ETH_ALEN);
Dominik Brodowski624dd662009-10-24 15:52:44 +02001893 dev_dbg(&link->dev,
John Daiker141fa612009-03-10 06:59:54 -07001894 "ray_update_multi add addr %02x%02x%02x%02x%02x%02x\n",
1895 dmi->dmi_addr[0], dmi->dmi_addr[1],
1896 dmi->dmi_addr[2], dmi->dmi_addr[3],
1897 dmi->dmi_addr[4], dmi->dmi_addr[5]);
1898 p += ETH_ALEN;
1899 i++;
1900 }
1901 if (i > 256 / ADDRLEN)
1902 i = 256 / ADDRLEN;
1903 writeb((UCHAR) i, &pccs->var);
Dominik Brodowski624dd662009-10-24 15:52:44 +02001904 dev_dbg(&link->dev, "ray_cs update_multi %d addresses in list\n", i);
John Daiker141fa612009-03-10 06:59:54 -07001905 /* Interrupt the firmware to process the command */
1906 local->num_multi = i;
1907 }
1908 if (interrupt_ecf(local, ccsindex)) {
Dominik Brodowski624dd662009-10-24 15:52:44 +02001909 dev_dbg(&link->dev,
John Daiker141fa612009-03-10 06:59:54 -07001910 "ray_cs update_multi failed - ECF not ready for intr\n");
1911 writeb(CCS_BUFFER_FREE, &(pccs++)->buffer_status);
1912 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001913} /* end ray_update_multi_list */
John Daiker141fa612009-03-10 06:59:54 -07001914
Linus Torvalds1da177e2005-04-16 15:20:36 -07001915/*===========================================================================*/
1916static void set_multicast_list(struct net_device *dev)
1917{
John Daiker141fa612009-03-10 06:59:54 -07001918 ray_dev_t *local = netdev_priv(dev);
1919 UCHAR promisc;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001920
Dominik Brodowski624dd662009-10-24 15:52:44 +02001921 pr_debug("ray_cs set_multicast_list(%p)\n", dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001922
John Daiker141fa612009-03-10 06:59:54 -07001923 if (dev->flags & IFF_PROMISC) {
1924 if (local->sparm.b5.a_promiscuous_mode == 0) {
Dominik Brodowski624dd662009-10-24 15:52:44 +02001925 pr_debug("ray_cs set_multicast_list promisc on\n");
John Daiker141fa612009-03-10 06:59:54 -07001926 local->sparm.b5.a_promiscuous_mode = 1;
1927 promisc = 1;
1928 ray_update_parm(dev, OBJID_promiscuous_mode,
1929 &promisc, sizeof(promisc));
1930 }
1931 } else {
1932 if (local->sparm.b5.a_promiscuous_mode == 1) {
Dominik Brodowski624dd662009-10-24 15:52:44 +02001933 pr_debug("ray_cs set_multicast_list promisc off\n");
John Daiker141fa612009-03-10 06:59:54 -07001934 local->sparm.b5.a_promiscuous_mode = 0;
1935 promisc = 0;
1936 ray_update_parm(dev, OBJID_promiscuous_mode,
1937 &promisc, sizeof(promisc));
1938 }
1939 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001940
John Daiker141fa612009-03-10 06:59:54 -07001941 if (dev->flags & IFF_ALLMULTI)
1942 ray_update_multi_list(dev, 1);
1943 else {
Jiri Pirko4cd24ea2010-02-08 04:30:35 +00001944 if (local->num_multi != netdev_mc_count(dev))
John Daiker141fa612009-03-10 06:59:54 -07001945 ray_update_multi_list(dev, 0);
1946 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001947} /* end set_multicast_list */
John Daiker141fa612009-03-10 06:59:54 -07001948
Linus Torvalds1da177e2005-04-16 15:20:36 -07001949/*=============================================================================
1950 * All routines below here are run at interrupt time.
1951=============================================================================*/
David Howells7d12e782006-10-05 14:55:46 +01001952static irqreturn_t ray_interrupt(int irq, void *dev_id)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001953{
John Daiker141fa612009-03-10 06:59:54 -07001954 struct net_device *dev = (struct net_device *)dev_id;
1955 struct pcmcia_device *link;
1956 ray_dev_t *local;
1957 struct ccs __iomem *pccs;
1958 struct rcs __iomem *prcs;
1959 UCHAR rcsindex;
1960 UCHAR tmp;
1961 UCHAR cmd;
1962 UCHAR status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001963
John Daiker141fa612009-03-10 06:59:54 -07001964 if (dev == NULL) /* Note that we want interrupts with dev->start == 0 */
1965 return IRQ_NONE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001966
Dominik Brodowski624dd662009-10-24 15:52:44 +02001967 pr_debug("ray_cs: interrupt for *dev=%p\n", dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001968
John Daiker141fa612009-03-10 06:59:54 -07001969 local = netdev_priv(dev);
1970 link = (struct pcmcia_device *)local->finder;
1971 if (!pcmcia_dev_present(link)) {
Dominik Brodowski624dd662009-10-24 15:52:44 +02001972 pr_debug(
1973 "ray_cs interrupt from device not present or suspended.\n");
John Daiker141fa612009-03-10 06:59:54 -07001974 return IRQ_NONE;
1975 }
1976 rcsindex = readb(&((struct scb __iomem *)(local->sram))->rcs_index);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001977
John Daiker141fa612009-03-10 06:59:54 -07001978 if (rcsindex >= (NUMBER_OF_CCS + NUMBER_OF_RCS)) {
Dominik Brodowski624dd662009-10-24 15:52:44 +02001979 dev_dbg(&link->dev, "ray_cs interrupt bad rcsindex = 0x%x\n", rcsindex);
John Daiker141fa612009-03-10 06:59:54 -07001980 clear_interrupt(local);
1981 return IRQ_HANDLED;
1982 }
1983 if (rcsindex < NUMBER_OF_CCS) { /* If it's a returned CCS */
1984 pccs = ccs_base(local) + rcsindex;
1985 cmd = readb(&pccs->cmd);
1986 status = readb(&pccs->buffer_status);
1987 switch (cmd) {
1988 case CCS_DOWNLOAD_STARTUP_PARAMS: /* Happens in firmware someday */
1989 del_timer(&local->timer);
1990 if (status == CCS_COMMAND_COMPLETE) {
Dominik Brodowski624dd662009-10-24 15:52:44 +02001991 dev_dbg(&link->dev,
John Daiker141fa612009-03-10 06:59:54 -07001992 "ray_cs interrupt download_startup_parameters OK\n");
1993 } else {
Dominik Brodowski624dd662009-10-24 15:52:44 +02001994 dev_dbg(&link->dev,
John Daiker141fa612009-03-10 06:59:54 -07001995 "ray_cs interrupt download_startup_parameters fail\n");
1996 }
1997 break;
1998 case CCS_UPDATE_PARAMS:
Dominik Brodowski624dd662009-10-24 15:52:44 +02001999 dev_dbg(&link->dev, "ray_cs interrupt update params done\n");
John Daiker141fa612009-03-10 06:59:54 -07002000 if (status != CCS_COMMAND_COMPLETE) {
2001 tmp =
2002 readb(&pccs->var.update_param.
2003 failure_cause);
Dominik Brodowski624dd662009-10-24 15:52:44 +02002004 dev_dbg(&link->dev,
John Daiker141fa612009-03-10 06:59:54 -07002005 "ray_cs interrupt update params failed - reason %d\n",
2006 tmp);
2007 }
2008 break;
2009 case CCS_REPORT_PARAMS:
Dominik Brodowski624dd662009-10-24 15:52:44 +02002010 dev_dbg(&link->dev, "ray_cs interrupt report params done\n");
John Daiker141fa612009-03-10 06:59:54 -07002011 break;
2012 case CCS_UPDATE_MULTICAST_LIST: /* Note that this CCS isn't returned */
Dominik Brodowski624dd662009-10-24 15:52:44 +02002013 dev_dbg(&link->dev,
John Daiker141fa612009-03-10 06:59:54 -07002014 "ray_cs interrupt CCS Update Multicast List done\n");
2015 break;
2016 case CCS_UPDATE_POWER_SAVINGS_MODE:
Dominik Brodowski624dd662009-10-24 15:52:44 +02002017 dev_dbg(&link->dev,
John Daiker141fa612009-03-10 06:59:54 -07002018 "ray_cs interrupt update power save mode done\n");
2019 break;
2020 case CCS_START_NETWORK:
2021 case CCS_JOIN_NETWORK:
2022 if (status == CCS_COMMAND_COMPLETE) {
2023 if (readb
2024 (&pccs->var.start_network.net_initiated) ==
2025 1) {
Dominik Brodowski624dd662009-10-24 15:52:44 +02002026 dev_dbg(&link->dev,
John Daiker141fa612009-03-10 06:59:54 -07002027 "ray_cs interrupt network \"%s\" started\n",
2028 local->sparm.b4.a_current_ess_id);
2029 } else {
Dominik Brodowski624dd662009-10-24 15:52:44 +02002030 dev_dbg(&link->dev,
John Daiker141fa612009-03-10 06:59:54 -07002031 "ray_cs interrupt network \"%s\" joined\n",
2032 local->sparm.b4.a_current_ess_id);
2033 }
2034 memcpy_fromio(&local->bss_id,
2035 pccs->var.start_network.bssid,
2036 ADDRLEN);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002037
John Daiker141fa612009-03-10 06:59:54 -07002038 if (local->fw_ver == 0x55)
2039 local->net_default_tx_rate = 3;
2040 else
2041 local->net_default_tx_rate =
2042 readb(&pccs->var.start_network.
2043 net_default_tx_rate);
2044 local->encryption =
2045 readb(&pccs->var.start_network.encryption);
2046 if (!sniffer && (local->net_type == INFRA)
2047 && !(local->sparm.b4.a_acting_as_ap_status)) {
2048 authenticate(local);
2049 }
2050 local->card_status = CARD_ACQ_COMPLETE;
2051 } else {
2052 local->card_status = CARD_ACQ_FAILED;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002053
John Daiker141fa612009-03-10 06:59:54 -07002054 del_timer(&local->timer);
2055 local->timer.expires = jiffies + HZ * 5;
2056 local->timer.data = (long)local;
2057 if (status == CCS_START_NETWORK) {
Dominik Brodowski624dd662009-10-24 15:52:44 +02002058 dev_dbg(&link->dev,
John Daiker141fa612009-03-10 06:59:54 -07002059 "ray_cs interrupt network \"%s\" start failed\n",
2060 local->sparm.b4.a_current_ess_id);
2061 local->timer.function = &start_net;
2062 } else {
Dominik Brodowski624dd662009-10-24 15:52:44 +02002063 dev_dbg(&link->dev,
John Daiker141fa612009-03-10 06:59:54 -07002064 "ray_cs interrupt network \"%s\" join failed\n",
2065 local->sparm.b4.a_current_ess_id);
2066 local->timer.function = &join_net;
2067 }
2068 add_timer(&local->timer);
2069 }
2070 break;
2071 case CCS_START_ASSOCIATION:
2072 if (status == CCS_COMMAND_COMPLETE) {
2073 local->card_status = CARD_ASSOC_COMPLETE;
Dominik Brodowski624dd662009-10-24 15:52:44 +02002074 dev_dbg(&link->dev, "ray_cs association successful\n");
John Daiker141fa612009-03-10 06:59:54 -07002075 } else {
Dominik Brodowski624dd662009-10-24 15:52:44 +02002076 dev_dbg(&link->dev, "ray_cs association failed,\n");
John Daiker141fa612009-03-10 06:59:54 -07002077 local->card_status = CARD_ASSOC_FAILED;
2078 join_net((u_long) local);
2079 }
2080 break;
2081 case CCS_TX_REQUEST:
2082 if (status == CCS_COMMAND_COMPLETE) {
Dominik Brodowski624dd662009-10-24 15:52:44 +02002083 dev_dbg(&link->dev,
John Daiker141fa612009-03-10 06:59:54 -07002084 "ray_cs interrupt tx request complete\n");
2085 } else {
Dominik Brodowski624dd662009-10-24 15:52:44 +02002086 dev_dbg(&link->dev,
John Daiker141fa612009-03-10 06:59:54 -07002087 "ray_cs interrupt tx request failed\n");
2088 }
2089 if (!sniffer)
2090 netif_start_queue(dev);
2091 netif_wake_queue(dev);
2092 break;
2093 case CCS_TEST_MEMORY:
Dominik Brodowski624dd662009-10-24 15:52:44 +02002094 dev_dbg(&link->dev, "ray_cs interrupt mem test done\n");
John Daiker141fa612009-03-10 06:59:54 -07002095 break;
2096 case CCS_SHUTDOWN:
Dominik Brodowski624dd662009-10-24 15:52:44 +02002097 dev_dbg(&link->dev,
John Daiker141fa612009-03-10 06:59:54 -07002098 "ray_cs interrupt Unexpected CCS returned - Shutdown\n");
2099 break;
2100 case CCS_DUMP_MEMORY:
Dominik Brodowski624dd662009-10-24 15:52:44 +02002101 dev_dbg(&link->dev, "ray_cs interrupt dump memory done\n");
John Daiker141fa612009-03-10 06:59:54 -07002102 break;
2103 case CCS_START_TIMER:
Dominik Brodowski624dd662009-10-24 15:52:44 +02002104 dev_dbg(&link->dev,
John Daiker141fa612009-03-10 06:59:54 -07002105 "ray_cs interrupt DING - raylink timer expired\n");
2106 break;
2107 default:
Dominik Brodowski624dd662009-10-24 15:52:44 +02002108 dev_dbg(&link->dev,
John Daiker141fa612009-03-10 06:59:54 -07002109 "ray_cs interrupt Unexpected CCS 0x%x returned 0x%x\n",
2110 rcsindex, cmd);
2111 }
2112 writeb(CCS_BUFFER_FREE, &pccs->buffer_status);
2113 } else { /* It's an RCS */
2114
2115 prcs = rcs_base(local) + rcsindex;
2116
2117 switch (readb(&prcs->interrupt_id)) {
2118 case PROCESS_RX_PACKET:
2119 ray_rx(dev, local, prcs);
2120 break;
2121 case REJOIN_NET_COMPLETE:
Dominik Brodowski624dd662009-10-24 15:52:44 +02002122 dev_dbg(&link->dev, "ray_cs interrupt rejoin net complete\n");
John Daiker141fa612009-03-10 06:59:54 -07002123 local->card_status = CARD_ACQ_COMPLETE;
2124 /* do we need to clear tx buffers CCS's? */
2125 if (local->sparm.b4.a_network_type == ADHOC) {
2126 if (!sniffer)
2127 netif_start_queue(dev);
2128 } else {
2129 memcpy_fromio(&local->bss_id,
2130 prcs->var.rejoin_net_complete.
2131 bssid, ADDRLEN);
Dominik Brodowski624dd662009-10-24 15:52:44 +02002132 dev_dbg(&link->dev,
John Daiker141fa612009-03-10 06:59:54 -07002133 "ray_cs new BSSID = %02x%02x%02x%02x%02x%02x\n",
2134 local->bss_id[0], local->bss_id[1],
2135 local->bss_id[2], local->bss_id[3],
2136 local->bss_id[4], local->bss_id[5]);
2137 if (!sniffer)
2138 authenticate(local);
2139 }
2140 break;
2141 case ROAMING_INITIATED:
Dominik Brodowski624dd662009-10-24 15:52:44 +02002142 dev_dbg(&link->dev, "ray_cs interrupt roaming initiated\n");
John Daiker141fa612009-03-10 06:59:54 -07002143 netif_stop_queue(dev);
2144 local->card_status = CARD_DOING_ACQ;
2145 break;
2146 case JAPAN_CALL_SIGN_RXD:
Dominik Brodowski624dd662009-10-24 15:52:44 +02002147 dev_dbg(&link->dev, "ray_cs interrupt japan call sign rx\n");
John Daiker141fa612009-03-10 06:59:54 -07002148 break;
2149 default:
Dominik Brodowski624dd662009-10-24 15:52:44 +02002150 dev_dbg(&link->dev,
John Daiker141fa612009-03-10 06:59:54 -07002151 "ray_cs Unexpected interrupt for RCS 0x%x cmd = 0x%x\n",
2152 rcsindex,
2153 (unsigned int)readb(&prcs->interrupt_id));
2154 break;
2155 }
2156 writeb(CCS_BUFFER_FREE, &prcs->buffer_status);
2157 }
2158 clear_interrupt(local);
2159 return IRQ_HANDLED;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002160} /* ray_interrupt */
John Daiker141fa612009-03-10 06:59:54 -07002161
Linus Torvalds1da177e2005-04-16 15:20:36 -07002162/*===========================================================================*/
John Daiker141fa612009-03-10 06:59:54 -07002163static void ray_rx(struct net_device *dev, ray_dev_t *local,
2164 struct rcs __iomem *prcs)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002165{
John Daiker141fa612009-03-10 06:59:54 -07002166 int rx_len;
2167 unsigned int pkt_addr;
2168 void __iomem *pmsg;
Dominik Brodowski624dd662009-10-24 15:52:44 +02002169 pr_debug("ray_rx process rx packet\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002170
John Daiker141fa612009-03-10 06:59:54 -07002171 /* Calculate address of packet within Rx buffer */
2172 pkt_addr = ((readb(&prcs->var.rx_packet.rx_data_ptr[0]) << 8)
2173 + readb(&prcs->var.rx_packet.rx_data_ptr[1])) & RX_BUFF_END;
2174 /* Length of first packet fragment */
2175 rx_len = (readb(&prcs->var.rx_packet.rx_data_length[0]) << 8)
2176 + readb(&prcs->var.rx_packet.rx_data_length[1]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002177
John Daiker141fa612009-03-10 06:59:54 -07002178 local->last_rsl = readb(&prcs->var.rx_packet.rx_sig_lev);
2179 pmsg = local->rmem + pkt_addr;
2180 switch (readb(pmsg)) {
2181 case DATA_TYPE:
Dominik Brodowski624dd662009-10-24 15:52:44 +02002182 pr_debug("ray_rx data type\n");
John Daiker141fa612009-03-10 06:59:54 -07002183 rx_data(dev, prcs, pkt_addr, rx_len);
2184 break;
2185 case AUTHENTIC_TYPE:
Dominik Brodowski624dd662009-10-24 15:52:44 +02002186 pr_debug("ray_rx authentic type\n");
John Daiker141fa612009-03-10 06:59:54 -07002187 if (sniffer)
2188 rx_data(dev, prcs, pkt_addr, rx_len);
2189 else
2190 rx_authenticate(local, prcs, pkt_addr, rx_len);
2191 break;
2192 case DEAUTHENTIC_TYPE:
Dominik Brodowski624dd662009-10-24 15:52:44 +02002193 pr_debug("ray_rx deauth type\n");
John Daiker141fa612009-03-10 06:59:54 -07002194 if (sniffer)
2195 rx_data(dev, prcs, pkt_addr, rx_len);
2196 else
2197 rx_deauthenticate(local, prcs, pkt_addr, rx_len);
2198 break;
2199 case NULL_MSG_TYPE:
Dominik Brodowski624dd662009-10-24 15:52:44 +02002200 pr_debug("ray_cs rx NULL msg\n");
John Daiker141fa612009-03-10 06:59:54 -07002201 break;
2202 case BEACON_TYPE:
Dominik Brodowski624dd662009-10-24 15:52:44 +02002203 pr_debug("ray_rx beacon type\n");
John Daiker141fa612009-03-10 06:59:54 -07002204 if (sniffer)
2205 rx_data(dev, prcs, pkt_addr, rx_len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002206
John Daiker141fa612009-03-10 06:59:54 -07002207 copy_from_rx_buff(local, (UCHAR *) &local->last_bcn, pkt_addr,
2208 rx_len < sizeof(struct beacon_rx) ?
2209 rx_len : sizeof(struct beacon_rx));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002210
John Daiker141fa612009-03-10 06:59:54 -07002211 local->beacon_rxed = 1;
2212 /* Get the statistics so the card counters never overflow */
2213 ray_get_stats(dev);
2214 break;
2215 default:
Dominik Brodowski624dd662009-10-24 15:52:44 +02002216 pr_debug("ray_cs unknown pkt type %2x\n",
John Daiker141fa612009-03-10 06:59:54 -07002217 (unsigned int)readb(pmsg));
2218 break;
2219 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002220
2221} /* end ray_rx */
John Daiker141fa612009-03-10 06:59:54 -07002222
Linus Torvalds1da177e2005-04-16 15:20:36 -07002223/*===========================================================================*/
John Daiker141fa612009-03-10 06:59:54 -07002224static void rx_data(struct net_device *dev, struct rcs __iomem *prcs,
2225 unsigned int pkt_addr, int rx_len)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002226{
John Daiker141fa612009-03-10 06:59:54 -07002227 struct sk_buff *skb = NULL;
2228 struct rcs __iomem *prcslink = prcs;
2229 ray_dev_t *local = netdev_priv(dev);
2230 UCHAR *rx_ptr;
2231 int total_len;
2232 int tmp;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002233#ifdef WIRELESS_SPY
John Daiker141fa612009-03-10 06:59:54 -07002234 int siglev = local->last_rsl;
2235 u_char linksrcaddr[ETH_ALEN]; /* Other end of the wireless link */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002236#endif
2237
John Daiker141fa612009-03-10 06:59:54 -07002238 if (!sniffer) {
2239 if (translate) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002240/* TBD length needs fixing for translated header */
John Daiker141fa612009-03-10 06:59:54 -07002241 if (rx_len < (ETH_HLEN + RX_MAC_HEADER_LENGTH) ||
2242 rx_len >
2243 (dev->mtu + RX_MAC_HEADER_LENGTH + ETH_HLEN +
2244 FCS_LEN)) {
Dominik Brodowski624dd662009-10-24 15:52:44 +02002245 pr_debug(
John Daiker141fa612009-03-10 06:59:54 -07002246 "ray_cs invalid packet length %d received \n",
2247 rx_len);
2248 return;
2249 }
2250 } else { /* encapsulated ethernet */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002251
John Daiker141fa612009-03-10 06:59:54 -07002252 if (rx_len < (ETH_HLEN + RX_MAC_HEADER_LENGTH) ||
2253 rx_len >
2254 (dev->mtu + RX_MAC_HEADER_LENGTH + ETH_HLEN +
2255 FCS_LEN)) {
Dominik Brodowski624dd662009-10-24 15:52:44 +02002256 pr_debug(
John Daiker141fa612009-03-10 06:59:54 -07002257 "ray_cs invalid packet length %d received \n",
2258 rx_len);
2259 return;
2260 }
2261 }
2262 }
Dominik Brodowski624dd662009-10-24 15:52:44 +02002263 pr_debug("ray_cs rx_data packet\n");
John Daiker141fa612009-03-10 06:59:54 -07002264 /* If fragmented packet, verify sizes of fragments add up */
2265 if (readb(&prcs->var.rx_packet.next_frag_rcs_index) != 0xFF) {
Dominik Brodowski624dd662009-10-24 15:52:44 +02002266 pr_debug("ray_cs rx'ed fragment\n");
John Daiker141fa612009-03-10 06:59:54 -07002267 tmp = (readb(&prcs->var.rx_packet.totalpacketlength[0]) << 8)
2268 + readb(&prcs->var.rx_packet.totalpacketlength[1]);
2269 total_len = tmp;
2270 prcslink = prcs;
2271 do {
2272 tmp -=
2273 (readb(&prcslink->var.rx_packet.rx_data_length[0])
2274 << 8)
2275 + readb(&prcslink->var.rx_packet.rx_data_length[1]);
2276 if (readb(&prcslink->var.rx_packet.next_frag_rcs_index)
2277 == 0xFF || tmp < 0)
2278 break;
2279 prcslink = rcs_base(local)
2280 + readb(&prcslink->link_field);
2281 } while (1);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002282
John Daiker141fa612009-03-10 06:59:54 -07002283 if (tmp < 0) {
Dominik Brodowski624dd662009-10-24 15:52:44 +02002284 pr_debug(
John Daiker141fa612009-03-10 06:59:54 -07002285 "ray_cs rx_data fragment lengths don't add up\n");
2286 local->stats.rx_dropped++;
2287 release_frag_chain(local, prcs);
2288 return;
2289 }
2290 } else { /* Single unfragmented packet */
2291 total_len = rx_len;
2292 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002293
John Daiker141fa612009-03-10 06:59:54 -07002294 skb = dev_alloc_skb(total_len + 5);
2295 if (skb == NULL) {
Dominik Brodowski624dd662009-10-24 15:52:44 +02002296 pr_debug("ray_cs rx_data could not allocate skb\n");
John Daiker141fa612009-03-10 06:59:54 -07002297 local->stats.rx_dropped++;
2298 if (readb(&prcs->var.rx_packet.next_frag_rcs_index) != 0xFF)
2299 release_frag_chain(local, prcs);
2300 return;
2301 }
2302 skb_reserve(skb, 2); /* Align IP on 16 byte (TBD check this) */
2303
Dominik Brodowski624dd662009-10-24 15:52:44 +02002304 pr_debug("ray_cs rx_data total_len = %x, rx_len = %x\n", total_len,
John Daiker141fa612009-03-10 06:59:54 -07002305 rx_len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002306
2307/************************/
John Daiker141fa612009-03-10 06:59:54 -07002308 /* Reserve enough room for the whole damn packet. */
2309 rx_ptr = skb_put(skb, total_len);
2310 /* Copy the whole packet to sk_buff */
2311 rx_ptr +=
2312 copy_from_rx_buff(local, rx_ptr, pkt_addr & RX_BUFF_END, rx_len);
2313 /* Get source address */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002314#ifdef WIRELESS_SPY
John Daiker141fa612009-03-10 06:59:54 -07002315 skb_copy_from_linear_data_offset(skb,
2316 offsetof(struct mac_header, addr_2),
2317 linksrcaddr, ETH_ALEN);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002318#endif
John Daiker141fa612009-03-10 06:59:54 -07002319 /* Now, deal with encapsulation/translation/sniffer */
2320 if (!sniffer) {
2321 if (!translate) {
2322 /* Encapsulated ethernet, so just lop off 802.11 MAC header */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002323/* TBD reserve skb_reserve( skb, RX_MAC_HEADER_LENGTH); */
John Daiker141fa612009-03-10 06:59:54 -07002324 skb_pull(skb, RX_MAC_HEADER_LENGTH);
2325 } else {
2326 /* Do translation */
2327 untranslate(local, skb, total_len);
2328 }
2329 } else { /* sniffer mode, so just pass whole packet */
2330 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002331
2332/************************/
John Daiker141fa612009-03-10 06:59:54 -07002333 /* Now pick up the rest of the fragments if any */
2334 tmp = 17;
2335 if (readb(&prcs->var.rx_packet.next_frag_rcs_index) != 0xFF) {
2336 prcslink = prcs;
Dominik Brodowski624dd662009-10-24 15:52:44 +02002337 pr_debug("ray_cs rx_data in fragment loop\n");
John Daiker141fa612009-03-10 06:59:54 -07002338 do {
2339 prcslink = rcs_base(local)
2340 +
2341 readb(&prcslink->var.rx_packet.next_frag_rcs_index);
2342 rx_len =
2343 ((readb(&prcslink->var.rx_packet.rx_data_length[0])
2344 << 8)
2345 +
2346 readb(&prcslink->var.rx_packet.rx_data_length[1]))
2347 & RX_BUFF_END;
2348 pkt_addr =
2349 ((readb(&prcslink->var.rx_packet.rx_data_ptr[0]) <<
2350 8)
2351 + readb(&prcslink->var.rx_packet.rx_data_ptr[1]))
2352 & RX_BUFF_END;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002353
John Daiker141fa612009-03-10 06:59:54 -07002354 rx_ptr +=
2355 copy_from_rx_buff(local, rx_ptr, pkt_addr, rx_len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002356
John Daiker141fa612009-03-10 06:59:54 -07002357 } while (tmp-- &&
2358 readb(&prcslink->var.rx_packet.next_frag_rcs_index) !=
2359 0xFF);
2360 release_frag_chain(local, prcs);
2361 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002362
John Daiker141fa612009-03-10 06:59:54 -07002363 skb->protocol = eth_type_trans(skb, dev);
2364 netif_rx(skb);
2365 local->stats.rx_packets++;
2366 local->stats.rx_bytes += total_len;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002367
John Daiker141fa612009-03-10 06:59:54 -07002368 /* Gather signal strength per address */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002369#ifdef WIRELESS_SPY
John Daiker141fa612009-03-10 06:59:54 -07002370 /* For the Access Point or the node having started the ad-hoc net
2371 * note : ad-hoc work only in some specific configurations, but we
2372 * kludge in ray_get_wireless_stats... */
2373 if (!memcmp(linksrcaddr, local->bss_id, ETH_ALEN)) {
2374 /* Update statistics */
2375 /*local->wstats.qual.qual = none ? */
2376 local->wstats.qual.level = siglev;
2377 /*local->wstats.qual.noise = none ? */
2378 local->wstats.qual.updated = 0x2;
2379 }
2380 /* Now, update the spy stuff */
2381 {
2382 struct iw_quality wstats;
2383 wstats.level = siglev;
2384 /* wstats.noise = none ? */
2385 /* wstats.qual = none ? */
2386 wstats.updated = 0x2;
2387 /* Update spy records */
2388 wireless_spy_update(dev, linksrcaddr, &wstats);
2389 }
2390#endif /* WIRELESS_SPY */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002391} /* end rx_data */
John Daiker141fa612009-03-10 06:59:54 -07002392
Linus Torvalds1da177e2005-04-16 15:20:36 -07002393/*===========================================================================*/
2394static void untranslate(ray_dev_t *local, struct sk_buff *skb, int len)
2395{
John Daiker141fa612009-03-10 06:59:54 -07002396 snaphdr_t *psnap = (snaphdr_t *) (skb->data + RX_MAC_HEADER_LENGTH);
2397 struct ieee80211_hdr *pmac = (struct ieee80211_hdr *)skb->data;
2398 __be16 type = *(__be16 *) psnap->ethertype;
2399 int delta;
2400 struct ethhdr *peth;
2401 UCHAR srcaddr[ADDRLEN];
2402 UCHAR destaddr[ADDRLEN];
2403 static UCHAR org_bridge[3] = { 0, 0, 0xf8 };
2404 static UCHAR org_1042[3] = { 0, 0, 0 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002405
John Daiker141fa612009-03-10 06:59:54 -07002406 memcpy(destaddr, ieee80211_get_DA(pmac), ADDRLEN);
2407 memcpy(srcaddr, ieee80211_get_SA(pmac), ADDRLEN);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002408
Dominik Brodowski624dd662009-10-24 15:52:44 +02002409#if 0
2410 if {
Joe Perchesad361c92009-07-06 13:05:40 -07002411 print_hex_dump(KERN_DEBUG, "skb->data before untranslate: ",
2412 DUMP_PREFIX_NONE, 16, 1,
2413 skb->data, 64, true);
2414 printk(KERN_DEBUG
John Daiker141fa612009-03-10 06:59:54 -07002415 "type = %08x, xsap = %02x%02x%02x, org = %02x02x02x\n",
2416 ntohs(type), psnap->dsap, psnap->ssap, psnap->ctrl,
2417 psnap->org[0], psnap->org[1], psnap->org[2]);
2418 printk(KERN_DEBUG "untranslate skb->data = %p\n", skb->data);
2419 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002420#endif
2421
John Daiker141fa612009-03-10 06:59:54 -07002422 if (psnap->dsap != 0xaa || psnap->ssap != 0xaa || psnap->ctrl != 3) {
2423 /* not a snap type so leave it alone */
Dominik Brodowski624dd662009-10-24 15:52:44 +02002424 pr_debug("ray_cs untranslate NOT SNAP %02x %02x %02x\n",
John Daiker141fa612009-03-10 06:59:54 -07002425 psnap->dsap, psnap->ssap, psnap->ctrl);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002426
John Daiker141fa612009-03-10 06:59:54 -07002427 delta = RX_MAC_HEADER_LENGTH - ETH_HLEN;
2428 peth = (struct ethhdr *)(skb->data + delta);
2429 peth->h_proto = htons(len - RX_MAC_HEADER_LENGTH);
2430 } else { /* Its a SNAP */
2431 if (memcmp(psnap->org, org_bridge, 3) == 0) {
2432 /* EtherII and nuke the LLC */
Dominik Brodowski624dd662009-10-24 15:52:44 +02002433 pr_debug("ray_cs untranslate Bridge encap\n");
John Daiker141fa612009-03-10 06:59:54 -07002434 delta = RX_MAC_HEADER_LENGTH
2435 + sizeof(struct snaphdr_t) - ETH_HLEN;
2436 peth = (struct ethhdr *)(skb->data + delta);
2437 peth->h_proto = type;
2438 } else if (memcmp(psnap->org, org_1042, 3) == 0) {
2439 switch (ntohs(type)) {
2440 case ETH_P_IPX:
2441 case ETH_P_AARP:
Dominik Brodowski624dd662009-10-24 15:52:44 +02002442 pr_debug("ray_cs untranslate RFC IPX/AARP\n");
John Daiker141fa612009-03-10 06:59:54 -07002443 delta = RX_MAC_HEADER_LENGTH - ETH_HLEN;
2444 peth = (struct ethhdr *)(skb->data + delta);
2445 peth->h_proto =
2446 htons(len - RX_MAC_HEADER_LENGTH);
2447 break;
2448 default:
Dominik Brodowski624dd662009-10-24 15:52:44 +02002449 pr_debug("ray_cs untranslate RFC default\n");
John Daiker141fa612009-03-10 06:59:54 -07002450 delta = RX_MAC_HEADER_LENGTH +
2451 sizeof(struct snaphdr_t) - ETH_HLEN;
2452 peth = (struct ethhdr *)(skb->data + delta);
2453 peth->h_proto = type;
2454 break;
2455 }
2456 } else {
2457 printk("ray_cs untranslate very confused by packet\n");
2458 delta = RX_MAC_HEADER_LENGTH - ETH_HLEN;
2459 peth = (struct ethhdr *)(skb->data + delta);
2460 peth->h_proto = type;
2461 }
Al Viro7698d692007-12-29 04:55:50 -05002462 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002463/* TBD reserve skb_reserve(skb, delta); */
John Daiker141fa612009-03-10 06:59:54 -07002464 skb_pull(skb, delta);
Dominik Brodowski624dd662009-10-24 15:52:44 +02002465 pr_debug("untranslate after skb_pull(%d), skb->data = %p\n", delta,
John Daiker141fa612009-03-10 06:59:54 -07002466 skb->data);
2467 memcpy(peth->h_dest, destaddr, ADDRLEN);
2468 memcpy(peth->h_source, srcaddr, ADDRLEN);
Dominik Brodowski624dd662009-10-24 15:52:44 +02002469#if 0
2470 {
John Daiker141fa612009-03-10 06:59:54 -07002471 int i;
2472 printk(KERN_DEBUG "skb->data after untranslate:");
2473 for (i = 0; i < 64; i++)
2474 printk("%02x ", skb->data[i]);
2475 printk("\n");
2476 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002477#endif
2478} /* end untranslate */
John Daiker141fa612009-03-10 06:59:54 -07002479
Linus Torvalds1da177e2005-04-16 15:20:36 -07002480/*===========================================================================*/
2481/* Copy data from circular receive buffer to PC memory.
2482 * dest = destination address in PC memory
2483 * pkt_addr = source address in receive buffer
2484 * len = length of packet to copy
2485 */
John Daiker141fa612009-03-10 06:59:54 -07002486static int copy_from_rx_buff(ray_dev_t *local, UCHAR *dest, int pkt_addr,
2487 int length)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002488{
John Daiker141fa612009-03-10 06:59:54 -07002489 int wrap_bytes = (pkt_addr + length) - (RX_BUFF_END + 1);
2490 if (wrap_bytes <= 0) {
2491 memcpy_fromio(dest, local->rmem + pkt_addr, length);
2492 } else { /* Packet wrapped in circular buffer */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002493
John Daiker141fa612009-03-10 06:59:54 -07002494 memcpy_fromio(dest, local->rmem + pkt_addr,
2495 length - wrap_bytes);
2496 memcpy_fromio(dest + length - wrap_bytes, local->rmem,
2497 wrap_bytes);
2498 }
2499 return length;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002500}
John Daiker141fa612009-03-10 06:59:54 -07002501
2502/*===========================================================================*/
2503static void release_frag_chain(ray_dev_t *local, struct rcs __iomem *prcs)
2504{
2505 struct rcs __iomem *prcslink = prcs;
2506 int tmp = 17;
2507 unsigned rcsindex = readb(&prcs->var.rx_packet.next_frag_rcs_index);
2508
2509 while (tmp--) {
2510 writeb(CCS_BUFFER_FREE, &prcslink->buffer_status);
2511 if (rcsindex >= (NUMBER_OF_CCS + NUMBER_OF_RCS)) {
Dominik Brodowski624dd662009-10-24 15:52:44 +02002512 pr_debug("ray_cs interrupt bad rcsindex = 0x%x\n",
John Daiker141fa612009-03-10 06:59:54 -07002513 rcsindex);
2514 break;
2515 }
2516 prcslink = rcs_base(local) + rcsindex;
2517 rcsindex = readb(&prcslink->var.rx_packet.next_frag_rcs_index);
2518 }
2519 writeb(CCS_BUFFER_FREE, &prcslink->buffer_status);
2520}
2521
Linus Torvalds1da177e2005-04-16 15:20:36 -07002522/*===========================================================================*/
2523static void authenticate(ray_dev_t *local)
2524{
John Daiker141fa612009-03-10 06:59:54 -07002525 struct pcmcia_device *link = local->finder;
Dominik Brodowski624dd662009-10-24 15:52:44 +02002526 dev_dbg(&link->dev, "ray_cs Starting authentication.\n");
John Daiker141fa612009-03-10 06:59:54 -07002527 if (!(pcmcia_dev_present(link))) {
Dominik Brodowski624dd662009-10-24 15:52:44 +02002528 dev_dbg(&link->dev, "ray_cs authenticate - device not present\n");
John Daiker141fa612009-03-10 06:59:54 -07002529 return;
2530 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002531
John Daiker141fa612009-03-10 06:59:54 -07002532 del_timer(&local->timer);
2533 if (build_auth_frame(local, local->bss_id, OPEN_AUTH_REQUEST)) {
2534 local->timer.function = &join_net;
2535 } else {
2536 local->timer.function = &authenticate_timeout;
2537 }
2538 local->timer.expires = jiffies + HZ * 2;
2539 local->timer.data = (long)local;
2540 add_timer(&local->timer);
2541 local->authentication_state = AWAITING_RESPONSE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002542} /* end authenticate */
John Daiker141fa612009-03-10 06:59:54 -07002543
Linus Torvalds1da177e2005-04-16 15:20:36 -07002544/*===========================================================================*/
2545static void rx_authenticate(ray_dev_t *local, struct rcs __iomem *prcs,
John Daiker141fa612009-03-10 06:59:54 -07002546 unsigned int pkt_addr, int rx_len)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002547{
John Daiker141fa612009-03-10 06:59:54 -07002548 UCHAR buff[256];
2549 struct rx_msg *msg = (struct rx_msg *)buff;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002550
John Daiker141fa612009-03-10 06:59:54 -07002551 del_timer(&local->timer);
2552
2553 copy_from_rx_buff(local, buff, pkt_addr, rx_len & 0xff);
2554 /* if we are trying to get authenticated */
2555 if (local->sparm.b4.a_network_type == ADHOC) {
Dominik Brodowski624dd662009-10-24 15:52:44 +02002556 pr_debug("ray_cs rx_auth var= %02x %02x %02x %02x %02x %02x\n",
John Daiker141fa612009-03-10 06:59:54 -07002557 msg->var[0], msg->var[1], msg->var[2], msg->var[3],
2558 msg->var[4], msg->var[5]);
2559 if (msg->var[2] == 1) {
Dominik Brodowski624dd662009-10-24 15:52:44 +02002560 pr_debug("ray_cs Sending authentication response.\n");
John Daiker141fa612009-03-10 06:59:54 -07002561 if (!build_auth_frame
2562 (local, msg->mac.addr_2, OPEN_AUTH_RESPONSE)) {
2563 local->authentication_state = NEED_TO_AUTH;
2564 memcpy(local->auth_id, msg->mac.addr_2,
2565 ADDRLEN);
2566 }
2567 }
2568 } else { /* Infrastructure network */
2569
2570 if (local->authentication_state == AWAITING_RESPONSE) {
2571 /* Verify authentication sequence #2 and success */
2572 if (msg->var[2] == 2) {
2573 if ((msg->var[3] | msg->var[4]) == 0) {
Dominik Brodowski624dd662009-10-24 15:52:44 +02002574 pr_debug("Authentication successful\n");
John Daiker141fa612009-03-10 06:59:54 -07002575 local->card_status = CARD_AUTH_COMPLETE;
2576 associate(local);
2577 local->authentication_state =
2578 AUTHENTICATED;
2579 } else {
Dominik Brodowski624dd662009-10-24 15:52:44 +02002580 pr_debug("Authentication refused\n");
John Daiker141fa612009-03-10 06:59:54 -07002581 local->card_status = CARD_AUTH_REFUSED;
2582 join_net((u_long) local);
2583 local->authentication_state =
2584 UNAUTHENTICATED;
2585 }
2586 }
2587 }
2588 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002589
2590} /* end rx_authenticate */
John Daiker141fa612009-03-10 06:59:54 -07002591
Linus Torvalds1da177e2005-04-16 15:20:36 -07002592/*===========================================================================*/
2593static void associate(ray_dev_t *local)
2594{
John Daiker141fa612009-03-10 06:59:54 -07002595 struct ccs __iomem *pccs;
2596 struct pcmcia_device *link = local->finder;
2597 struct net_device *dev = link->priv;
2598 int ccsindex;
2599 if (!(pcmcia_dev_present(link))) {
Dominik Brodowski624dd662009-10-24 15:52:44 +02002600 dev_dbg(&link->dev, "ray_cs associate - device not present\n");
John Daiker141fa612009-03-10 06:59:54 -07002601 return;
2602 }
2603 /* If no tx buffers available, return */
2604 if ((ccsindex = get_free_ccs(local)) < 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002605/* TBD should never be here but... what if we are? */
Dominik Brodowski624dd662009-10-24 15:52:44 +02002606 dev_dbg(&link->dev, "ray_cs associate - No free ccs\n");
John Daiker141fa612009-03-10 06:59:54 -07002607 return;
2608 }
Dominik Brodowski624dd662009-10-24 15:52:44 +02002609 dev_dbg(&link->dev, "ray_cs Starting association with access point\n");
John Daiker141fa612009-03-10 06:59:54 -07002610 pccs = ccs_base(local) + ccsindex;
2611 /* fill in the CCS */
2612 writeb(CCS_START_ASSOCIATION, &pccs->cmd);
2613 /* Interrupt the firmware to process the command */
2614 if (interrupt_ecf(local, ccsindex)) {
Dominik Brodowski624dd662009-10-24 15:52:44 +02002615 dev_dbg(&link->dev, "ray_cs associate failed - ECF not ready for intr\n");
John Daiker141fa612009-03-10 06:59:54 -07002616 writeb(CCS_BUFFER_FREE, &(pccs++)->buffer_status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002617
John Daiker141fa612009-03-10 06:59:54 -07002618 del_timer(&local->timer);
2619 local->timer.expires = jiffies + HZ * 2;
2620 local->timer.data = (long)local;
2621 local->timer.function = &join_net;
2622 add_timer(&local->timer);
2623 local->card_status = CARD_ASSOC_FAILED;
2624 return;
2625 }
2626 if (!sniffer)
2627 netif_start_queue(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002628
2629} /* end associate */
John Daiker141fa612009-03-10 06:59:54 -07002630
Linus Torvalds1da177e2005-04-16 15:20:36 -07002631/*===========================================================================*/
John Daiker141fa612009-03-10 06:59:54 -07002632static void rx_deauthenticate(ray_dev_t *local, struct rcs __iomem *prcs,
2633 unsigned int pkt_addr, int rx_len)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002634{
2635/* UCHAR buff[256];
2636 struct rx_msg *msg = (struct rx_msg *)buff;
2637*/
Dominik Brodowski624dd662009-10-24 15:52:44 +02002638 pr_debug("Deauthentication frame received\n");
John Daiker141fa612009-03-10 06:59:54 -07002639 local->authentication_state = UNAUTHENTICATED;
2640 /* Need to reauthenticate or rejoin depending on reason code */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002641/* copy_from_rx_buff(local, buff, pkt_addr, rx_len & 0xff);
2642 */
2643}
John Daiker141fa612009-03-10 06:59:54 -07002644
Linus Torvalds1da177e2005-04-16 15:20:36 -07002645/*===========================================================================*/
2646static void clear_interrupt(ray_dev_t *local)
2647{
John Daiker141fa612009-03-10 06:59:54 -07002648 writeb(0, local->amem + CIS_OFFSET + HCS_INTR_OFFSET);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002649}
John Daiker141fa612009-03-10 06:59:54 -07002650
Linus Torvalds1da177e2005-04-16 15:20:36 -07002651/*===========================================================================*/
2652#ifdef CONFIG_PROC_FS
2653#define MAXDATA (PAGE_SIZE - 80)
2654
2655static char *card_status[] = {
John Daiker141fa612009-03-10 06:59:54 -07002656 "Card inserted - uninitialized", /* 0 */
2657 "Card not downloaded", /* 1 */
2658 "Waiting for download parameters", /* 2 */
2659 "Card doing acquisition", /* 3 */
2660 "Acquisition complete", /* 4 */
2661 "Authentication complete", /* 5 */
2662 "Association complete", /* 6 */
2663 "???", "???", "???", "???", /* 7 8 9 10 undefined */
2664 "Card init error", /* 11 */
2665 "Download parameters error", /* 12 */
2666 "???", /* 13 */
2667 "Acquisition failed", /* 14 */
2668 "Authentication refused", /* 15 */
2669 "Association failed" /* 16 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002670};
2671
John Daiker141fa612009-03-10 06:59:54 -07002672static char *nettype[] = { "Adhoc", "Infra " };
2673static char *framing[] = { "Encapsulation", "Translation" }
2674
Linus Torvalds1da177e2005-04-16 15:20:36 -07002675;
2676/*===========================================================================*/
Alexey Dobriyan6b914c52008-04-10 14:34:35 -07002677static int ray_cs_proc_show(struct seq_file *m, void *v)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002678{
2679/* Print current values which are not available via other means
John Daiker141fa612009-03-10 06:59:54 -07002680 * eg ifconfig
Linus Torvalds1da177e2005-04-16 15:20:36 -07002681 */
John Daiker141fa612009-03-10 06:59:54 -07002682 int i;
2683 struct pcmcia_device *link;
2684 struct net_device *dev;
2685 ray_dev_t *local;
2686 UCHAR *p;
2687 struct freq_hop_element *pfh;
2688 UCHAR c[33];
Linus Torvalds1da177e2005-04-16 15:20:36 -07002689
John Daiker141fa612009-03-10 06:59:54 -07002690 link = this_device;
2691 if (!link)
2692 return 0;
2693 dev = (struct net_device *)link->priv;
2694 if (!dev)
2695 return 0;
2696 local = netdev_priv(dev);
2697 if (!local)
2698 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002699
John Daiker141fa612009-03-10 06:59:54 -07002700 seq_puts(m, "Raylink Wireless LAN driver status\n");
2701 seq_printf(m, "%s\n", rcsid);
2702 /* build 4 does not report version, and field is 0x55 after memtest */
2703 seq_puts(m, "Firmware version = ");
2704 if (local->fw_ver == 0x55)
2705 seq_puts(m, "4 - Use dump_cis for more details\n");
2706 else
2707 seq_printf(m, "%2d.%02d.%02d\n",
2708 local->fw_ver, local->fw_bld, local->fw_var);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002709
John Daiker141fa612009-03-10 06:59:54 -07002710 for (i = 0; i < 32; i++)
2711 c[i] = local->sparm.b5.a_current_ess_id[i];
2712 c[32] = 0;
2713 seq_printf(m, "%s network ESSID = \"%s\"\n",
2714 nettype[local->sparm.b5.a_network_type], c);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002715
John Daiker141fa612009-03-10 06:59:54 -07002716 p = local->bss_id;
2717 seq_printf(m, "BSSID = %pM\n", p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002718
John Daiker141fa612009-03-10 06:59:54 -07002719 seq_printf(m, "Country code = %d\n",
2720 local->sparm.b5.a_curr_country_code);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002721
John Daiker141fa612009-03-10 06:59:54 -07002722 i = local->card_status;
2723 if (i < 0)
2724 i = 10;
2725 if (i > 16)
2726 i = 10;
2727 seq_printf(m, "Card status = %s\n", card_status[i]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002728
John Daiker141fa612009-03-10 06:59:54 -07002729 seq_printf(m, "Framing mode = %s\n", framing[translate]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002730
John Daiker141fa612009-03-10 06:59:54 -07002731 seq_printf(m, "Last pkt signal lvl = %d\n", local->last_rsl);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002732
John Daiker141fa612009-03-10 06:59:54 -07002733 if (local->beacon_rxed) {
2734 /* Pull some fields out of last beacon received */
2735 seq_printf(m, "Beacon Interval = %d Kus\n",
2736 local->last_bcn.beacon_intvl[0]
2737 + 256 * local->last_bcn.beacon_intvl[1]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002738
John Daiker141fa612009-03-10 06:59:54 -07002739 p = local->last_bcn.elements;
2740 if (p[0] == C_ESSID_ELEMENT_ID)
2741 p += p[1] + 2;
2742 else {
2743 seq_printf(m,
2744 "Parse beacon failed at essid element id = %d\n",
2745 p[0]);
2746 return 0;
2747 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002748
John Daiker141fa612009-03-10 06:59:54 -07002749 if (p[0] == C_SUPPORTED_RATES_ELEMENT_ID) {
2750 seq_puts(m, "Supported rate codes = ");
2751 for (i = 2; i < p[1] + 2; i++)
2752 seq_printf(m, "0x%02x ", p[i]);
2753 seq_putc(m, '\n');
2754 p += p[1] + 2;
2755 } else {
2756 seq_puts(m, "Parse beacon failed at rates element\n");
2757 return 0;
2758 }
2759
2760 if (p[0] == C_FH_PARAM_SET_ELEMENT_ID) {
2761 pfh = (struct freq_hop_element *)p;
2762 seq_printf(m, "Hop dwell = %d Kus\n",
2763 pfh->dwell_time[0] +
2764 256 * pfh->dwell_time[1]);
2765 seq_printf(m, "Hop set = %d \n",
2766 pfh->hop_set);
2767 seq_printf(m, "Hop pattern = %d \n",
2768 pfh->hop_pattern);
2769 seq_printf(m, "Hop index = %d \n",
2770 pfh->hop_index);
2771 p += p[1] + 2;
2772 } else {
2773 seq_puts(m,
2774 "Parse beacon failed at FH param element\n");
2775 return 0;
2776 }
2777 } else {
2778 seq_puts(m, "No beacons received\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002779 }
John Daiker141fa612009-03-10 06:59:54 -07002780 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002781}
2782
Alexey Dobriyan6b914c52008-04-10 14:34:35 -07002783static int ray_cs_proc_open(struct inode *inode, struct file *file)
2784{
2785 return single_open(file, ray_cs_proc_show, NULL);
2786}
2787
2788static const struct file_operations ray_cs_proc_fops = {
John Daiker141fa612009-03-10 06:59:54 -07002789 .owner = THIS_MODULE,
2790 .open = ray_cs_proc_open,
2791 .read = seq_read,
2792 .llseek = seq_lseek,
2793 .release = single_release,
Alexey Dobriyan6b914c52008-04-10 14:34:35 -07002794};
Linus Torvalds1da177e2005-04-16 15:20:36 -07002795#endif
2796/*===========================================================================*/
2797static int build_auth_frame(ray_dev_t *local, UCHAR *dest, int auth_type)
2798{
John Daiker141fa612009-03-10 06:59:54 -07002799 int addr;
2800 struct ccs __iomem *pccs;
2801 struct tx_msg __iomem *ptx;
2802 int ccsindex;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002803
John Daiker141fa612009-03-10 06:59:54 -07002804 /* If no tx buffers available, return */
2805 if ((ccsindex = get_free_tx_ccs(local)) < 0) {
Dominik Brodowski624dd662009-10-24 15:52:44 +02002806 pr_debug("ray_cs send authenticate - No free tx ccs\n");
John Daiker141fa612009-03-10 06:59:54 -07002807 return -1;
2808 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002809
John Daiker141fa612009-03-10 06:59:54 -07002810 pccs = ccs_base(local) + ccsindex;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002811
John Daiker141fa612009-03-10 06:59:54 -07002812 /* Address in card space */
2813 addr = TX_BUF_BASE + (ccsindex << 11);
2814 /* fill in the CCS */
2815 writeb(CCS_TX_REQUEST, &pccs->cmd);
2816 writeb(addr >> 8, pccs->var.tx_request.tx_data_ptr);
2817 writeb(0x20, pccs->var.tx_request.tx_data_ptr + 1);
2818 writeb(TX_AUTHENTICATE_LENGTH_MSB, pccs->var.tx_request.tx_data_length);
2819 writeb(TX_AUTHENTICATE_LENGTH_LSB,
2820 pccs->var.tx_request.tx_data_length + 1);
2821 writeb(0, &pccs->var.tx_request.pow_sav_mode);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002822
John Daiker141fa612009-03-10 06:59:54 -07002823 ptx = local->sram + addr;
2824 /* fill in the mac header */
2825 writeb(PROTOCOL_VER | AUTHENTIC_TYPE, &ptx->mac.frame_ctl_1);
2826 writeb(0, &ptx->mac.frame_ctl_2);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002827
John Daiker141fa612009-03-10 06:59:54 -07002828 memcpy_toio(ptx->mac.addr_1, dest, ADDRLEN);
2829 memcpy_toio(ptx->mac.addr_2, local->sparm.b4.a_mac_addr, ADDRLEN);
2830 memcpy_toio(ptx->mac.addr_3, local->bss_id, ADDRLEN);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002831
John Daiker141fa612009-03-10 06:59:54 -07002832 /* Fill in msg body with protocol 00 00, sequence 01 00 ,status 00 00 */
2833 memset_io(ptx->var, 0, 6);
2834 writeb(auth_type & 0xff, ptx->var + 2);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002835
John Daiker141fa612009-03-10 06:59:54 -07002836 /* Interrupt the firmware to process the command */
2837 if (interrupt_ecf(local, ccsindex)) {
Dominik Brodowski624dd662009-10-24 15:52:44 +02002838 pr_debug(
John Daiker141fa612009-03-10 06:59:54 -07002839 "ray_cs send authentication request failed - ECF not ready for intr\n");
2840 writeb(CCS_BUFFER_FREE, &(pccs++)->buffer_status);
2841 return -1;
2842 }
2843 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002844} /* End build_auth_frame */
2845
2846/*===========================================================================*/
2847#ifdef CONFIG_PROC_FS
Alexey Dobriyan83daee02009-11-25 10:12:20 +03002848static ssize_t ray_cs_essid_proc_write(struct file *file,
2849 const char __user *buffer, size_t count, loff_t *pos)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002850{
2851 static char proc_essid[33];
Alan Cox575c9ed2009-10-27 15:35:55 +00002852 unsigned int len = count;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002853
2854 if (len > 32)
2855 len = 32;
2856 memset(proc_essid, 0, 33);
2857 if (copy_from_user(proc_essid, buffer, len))
2858 return -EFAULT;
2859 essid = proc_essid;
2860 return count;
2861}
2862
Alexey Dobriyan83daee02009-11-25 10:12:20 +03002863static const struct file_operations ray_cs_essid_proc_fops = {
2864 .owner = THIS_MODULE,
2865 .write = ray_cs_essid_proc_write,
2866};
2867
2868static ssize_t int_proc_write(struct file *file, const char __user *buffer,
2869 size_t count, loff_t *pos)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002870{
2871 static char proc_number[10];
2872 char *p;
2873 int nr, len;
2874
2875 if (!count)
2876 return 0;
2877
2878 if (count > 9)
2879 return -EINVAL;
2880 if (copy_from_user(proc_number, buffer, count))
2881 return -EFAULT;
2882 p = proc_number;
2883 nr = 0;
2884 len = count;
2885 do {
2886 unsigned int c = *p - '0';
2887 if (c > 9)
2888 return -EINVAL;
John Daiker141fa612009-03-10 06:59:54 -07002889 nr = nr * 10 + c;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002890 p++;
2891 } while (--len);
Alexey Dobriyan83daee02009-11-25 10:12:20 +03002892 *(int *)PDE(file->f_path.dentry->d_inode)->data = nr;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002893 return count;
2894}
Alexey Dobriyan83daee02009-11-25 10:12:20 +03002895
2896static const struct file_operations int_proc_fops = {
2897 .owner = THIS_MODULE,
2898 .write = int_proc_write,
2899};
Linus Torvalds1da177e2005-04-16 15:20:36 -07002900#endif
2901
Dominik Brodowskif57ea2a2005-06-27 16:28:24 -07002902static struct pcmcia_device_id ray_ids[] = {
2903 PCMCIA_DEVICE_MANF_CARD(0x01a6, 0x0000),
2904 PCMCIA_DEVICE_NULL,
2905};
John Daiker141fa612009-03-10 06:59:54 -07002906
Dominik Brodowskif57ea2a2005-06-27 16:28:24 -07002907MODULE_DEVICE_TABLE(pcmcia, ray_ids);
2908
Linus Torvalds1da177e2005-04-16 15:20:36 -07002909static struct pcmcia_driver ray_driver = {
John Daiker141fa612009-03-10 06:59:54 -07002910 .owner = THIS_MODULE,
2911 .drv = {
2912 .name = "ray_cs",
2913 },
2914 .probe = ray_probe,
2915 .remove = ray_detach,
2916 .id_table = ray_ids,
2917 .suspend = ray_suspend,
2918 .resume = ray_resume,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002919};
2920
2921static int __init init_ray_cs(void)
2922{
John Daiker141fa612009-03-10 06:59:54 -07002923 int rc;
2924
Dominik Brodowski624dd662009-10-24 15:52:44 +02002925 pr_debug("%s\n", rcsid);
John Daiker141fa612009-03-10 06:59:54 -07002926 rc = pcmcia_register_driver(&ray_driver);
Dominik Brodowski624dd662009-10-24 15:52:44 +02002927 pr_debug("raylink init_module register_pcmcia_driver returns 0x%x\n",
John Daiker141fa612009-03-10 06:59:54 -07002928 rc);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002929
2930#ifdef CONFIG_PROC_FS
John Daiker141fa612009-03-10 06:59:54 -07002931 proc_mkdir("driver/ray_cs", NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002932
John Daiker141fa612009-03-10 06:59:54 -07002933 proc_create("driver/ray_cs/ray_cs", 0, NULL, &ray_cs_proc_fops);
Alexey Dobriyan83daee02009-11-25 10:12:20 +03002934 proc_create("driver/ray_cs/essid", S_IWUSR, NULL, &ray_cs_essid_proc_fops);
2935 proc_create_data("driver/ray_cs/net_type", S_IWUSR, NULL, &int_proc_fops, &net_type);
2936 proc_create_data("driver/ray_cs/translate", S_IWUSR, NULL, &int_proc_fops, &translate);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002937#endif
John Daiker141fa612009-03-10 06:59:54 -07002938 if (translate != 0)
2939 translate = 1;
2940 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002941} /* init_ray_cs */
2942
2943/*===========================================================================*/
2944
2945static void __exit exit_ray_cs(void)
2946{
Dominik Brodowski624dd662009-10-24 15:52:44 +02002947 pr_debug("ray_cs: cleanup_module\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002948
2949#ifdef CONFIG_PROC_FS
John Daiker141fa612009-03-10 06:59:54 -07002950 remove_proc_entry("driver/ray_cs/ray_cs", NULL);
2951 remove_proc_entry("driver/ray_cs/essid", NULL);
2952 remove_proc_entry("driver/ray_cs/net_type", NULL);
2953 remove_proc_entry("driver/ray_cs/translate", NULL);
2954 remove_proc_entry("driver/ray_cs", NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002955#endif
2956
John Daiker141fa612009-03-10 06:59:54 -07002957 pcmcia_unregister_driver(&ray_driver);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002958} /* exit_ray_cs */
2959
2960module_init(init_ray_cs);
2961module_exit(exit_ray_cs);
2962
2963/*===========================================================================*/