blob: fe4642a49bfb208200c7572a4b57cc14bb44d600 [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) {
382 if (link->dev_node)
383 unregister_netdev(dev);
384 free_netdev(dev);
385 }
Dominik Brodowski624dd662009-10-24 15:52:44 +0200386 dev_dbg(&link->dev, "ray_cs ray_detach ending\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700387} /* ray_detach */
John Daiker141fa612009-03-10 06:59:54 -0700388
Linus Torvalds1da177e2005-04-16 15:20:36 -0700389/*=============================================================================
390 ray_config() is run after a CARD_INSERTION event
391 is received, to configure the PCMCIA socket, and to make the
392 ethernet device available to the system.
393=============================================================================*/
Linus Torvalds1da177e2005-04-16 15:20:36 -0700394#define MAX_TUPLE_SIZE 128
Dominik Brodowski15b99ac2006-03-31 17:26:06 +0200395static int ray_config(struct pcmcia_device *link)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700396{
Dominik Brodowski624dd662009-10-24 15:52:44 +0200397 int ret = 0;
John Daiker141fa612009-03-10 06:59:54 -0700398 int i;
399 win_req_t req;
400 memreq_t mem;
401 struct net_device *dev = (struct net_device *)link->priv;
402 ray_dev_t *local = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700403
Dominik Brodowski624dd662009-10-24 15:52:44 +0200404 dev_dbg(&link->dev, "ray_config\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700405
John Daiker141fa612009-03-10 06:59:54 -0700406 /* Determine card type and firmware version */
407 printk(KERN_INFO "ray_cs Detected: %s%s%s%s\n",
408 link->prod_id[0] ? link->prod_id[0] : " ",
409 link->prod_id[1] ? link->prod_id[1] : " ",
410 link->prod_id[2] ? link->prod_id[2] : " ",
411 link->prod_id[3] ? link->prod_id[3] : " ");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700412
John Daiker141fa612009-03-10 06:59:54 -0700413 /* Now allocate an interrupt line. Note that this does not
414 actually assign a handler to the interrupt.
415 */
Dominik Brodowskieb141202010-03-07 12:21:16 +0100416 ret = pcmcia_request_irq(link, ray_interrupt);
Dominik Brodowski624dd662009-10-24 15:52:44 +0200417 if (ret)
418 goto failed;
Dominik Brodowskieb141202010-03-07 12:21:16 +0100419 dev->irq = link->irq;
John Daiker141fa612009-03-10 06:59:54 -0700420
421 /* This actually configures the PCMCIA socket -- setting up
422 the I/O windows and the interrupt mapping.
423 */
Dominik Brodowski624dd662009-10-24 15:52:44 +0200424 ret = pcmcia_request_configuration(link, &link->conf);
425 if (ret)
426 goto failed;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700427
428/*** Set up 32k window for shared memory (transmit and control) ************/
John Daiker141fa612009-03-10 06:59:54 -0700429 req.Attributes =
430 WIN_DATA_WIDTH_8 | WIN_MEMORY_TYPE_CM | WIN_ENABLE | WIN_USE_WAIT;
431 req.Base = 0;
432 req.Size = 0x8000;
433 req.AccessSpeed = ray_mem_speed;
Dominik Brodowski6838b032009-11-03 01:31:52 +0100434 ret = pcmcia_request_window(link, &req, &link->win);
Dominik Brodowski624dd662009-10-24 15:52:44 +0200435 if (ret)
436 goto failed;
John Daiker141fa612009-03-10 06:59:54 -0700437 mem.CardOffset = 0x0000;
438 mem.Page = 0;
Magnus Damm868575d2006-12-13 19:46:43 +0900439 ret = pcmcia_map_mem_page(link, link->win, &mem);
Dominik Brodowski624dd662009-10-24 15:52:44 +0200440 if (ret)
441 goto failed;
John Daiker141fa612009-03-10 06:59:54 -0700442 local->sram = ioremap(req.Base, req.Size);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700443
444/*** Set up 16k window for shared memory (receive buffer) ***************/
John Daiker141fa612009-03-10 06:59:54 -0700445 req.Attributes =
446 WIN_DATA_WIDTH_8 | WIN_MEMORY_TYPE_CM | WIN_ENABLE | WIN_USE_WAIT;
447 req.Base = 0;
448 req.Size = 0x4000;
449 req.AccessSpeed = ray_mem_speed;
Dominik Brodowski6838b032009-11-03 01:31:52 +0100450 ret = pcmcia_request_window(link, &req, &local->rmem_handle);
Dominik Brodowski624dd662009-10-24 15:52:44 +0200451 if (ret)
452 goto failed;
John Daiker141fa612009-03-10 06:59:54 -0700453 mem.CardOffset = 0x8000;
454 mem.Page = 0;
Magnus Damm868575d2006-12-13 19:46:43 +0900455 ret = pcmcia_map_mem_page(link, local->rmem_handle, &mem);
Dominik Brodowski624dd662009-10-24 15:52:44 +0200456 if (ret)
457 goto failed;
John Daiker141fa612009-03-10 06:59:54 -0700458 local->rmem = ioremap(req.Base, req.Size);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700459
460/*** Set up window for attribute memory ***********************************/
John Daiker141fa612009-03-10 06:59:54 -0700461 req.Attributes =
462 WIN_DATA_WIDTH_8 | WIN_MEMORY_TYPE_AM | WIN_ENABLE | WIN_USE_WAIT;
463 req.Base = 0;
464 req.Size = 0x1000;
465 req.AccessSpeed = ray_mem_speed;
Dominik Brodowski6838b032009-11-03 01:31:52 +0100466 ret = pcmcia_request_window(link, &req, &local->amem_handle);
Dominik Brodowski624dd662009-10-24 15:52:44 +0200467 if (ret)
468 goto failed;
John Daiker141fa612009-03-10 06:59:54 -0700469 mem.CardOffset = 0x0000;
470 mem.Page = 0;
Magnus Damm868575d2006-12-13 19:46:43 +0900471 ret = pcmcia_map_mem_page(link, local->amem_handle, &mem);
Dominik Brodowski624dd662009-10-24 15:52:44 +0200472 if (ret)
473 goto failed;
John Daiker141fa612009-03-10 06:59:54 -0700474 local->amem = ioremap(req.Base, req.Size);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700475
Dominik Brodowski624dd662009-10-24 15:52:44 +0200476 dev_dbg(&link->dev, "ray_config sram=%p\n", local->sram);
477 dev_dbg(&link->dev, "ray_config rmem=%p\n", local->rmem);
478 dev_dbg(&link->dev, "ray_config amem=%p\n", local->amem);
John Daiker141fa612009-03-10 06:59:54 -0700479 if (ray_init(dev) < 0) {
480 ray_release(link);
481 return -ENODEV;
482 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700483
Dominik Brodowskidd2e5a12009-11-03 10:27:34 +0100484 SET_NETDEV_DEV(dev, &link->dev);
John Daiker141fa612009-03-10 06:59:54 -0700485 i = register_netdev(dev);
486 if (i != 0) {
487 printk("ray_config register_netdev() failed\n");
488 ray_release(link);
489 return i;
490 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700491
John Daiker141fa612009-03-10 06:59:54 -0700492 strcpy(local->node.dev_name, dev->name);
493 link->dev_node = &local->node;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700494
John Daiker141fa612009-03-10 06:59:54 -0700495 printk(KERN_INFO "%s: RayLink, irq %d, hw_addr %pM\n",
496 dev->name, dev->irq, dev->dev_addr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700497
John Daiker141fa612009-03-10 06:59:54 -0700498 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700499
Dominik Brodowski624dd662009-10-24 15:52:44 +0200500failed:
John Daiker141fa612009-03-10 06:59:54 -0700501 ray_release(link);
502 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700503} /* ray_config */
504
505static inline struct ccs __iomem *ccs_base(ray_dev_t *dev)
506{
507 return dev->sram + CCS_BASE;
508}
509
510static inline struct rcs __iomem *rcs_base(ray_dev_t *dev)
511{
512 /*
513 * This looks nonsensical, since there is a separate
514 * RCS_BASE. But the difference between a "struct rcs"
515 * and a "struct ccs" ends up being in the _index_ off
516 * the base, so the base pointer is the same for both
517 * ccs/rcs.
518 */
519 return dev->sram + CCS_BASE;
520}
521
522/*===========================================================================*/
523static int ray_init(struct net_device *dev)
524{
John Daiker141fa612009-03-10 06:59:54 -0700525 int i;
526 UCHAR *p;
527 struct ccs __iomem *pccs;
528 ray_dev_t *local = netdev_priv(dev);
529 struct pcmcia_device *link = local->finder;
Dominik Brodowski624dd662009-10-24 15:52:44 +0200530 dev_dbg(&link->dev, "ray_init(0x%p)\n", dev);
John Daiker141fa612009-03-10 06:59:54 -0700531 if (!(pcmcia_dev_present(link))) {
Dominik Brodowski624dd662009-10-24 15:52:44 +0200532 dev_dbg(&link->dev, "ray_init - device not present\n");
John Daiker141fa612009-03-10 06:59:54 -0700533 return -1;
534 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700535
John Daiker141fa612009-03-10 06:59:54 -0700536 local->net_type = net_type;
537 local->sta_type = TYPE_STA;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700538
John Daiker141fa612009-03-10 06:59:54 -0700539 /* Copy the startup results to local memory */
540 memcpy_fromio(&local->startup_res, local->sram + ECF_TO_HOST_BASE,
541 sizeof(struct startup_res_6));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700542
John Daiker141fa612009-03-10 06:59:54 -0700543 /* Check Power up test status and get mac address from card */
544 if (local->startup_res.startup_word != 0x80) {
545 printk(KERN_INFO "ray_init ERROR card status = %2x\n",
546 local->startup_res.startup_word);
547 local->card_status = CARD_INIT_ERROR;
548 return -1;
549 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700550
John Daiker141fa612009-03-10 06:59:54 -0700551 local->fw_ver = local->startup_res.firmware_version[0];
552 local->fw_bld = local->startup_res.firmware_version[1];
553 local->fw_var = local->startup_res.firmware_version[2];
Dominik Brodowski624dd662009-10-24 15:52:44 +0200554 dev_dbg(&link->dev, "ray_init firmware version %d.%d \n", local->fw_ver,
John Daiker141fa612009-03-10 06:59:54 -0700555 local->fw_bld);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700556
John Daiker141fa612009-03-10 06:59:54 -0700557 local->tib_length = 0x20;
558 if ((local->fw_ver == 5) && (local->fw_bld >= 30))
559 local->tib_length = local->startup_res.tib_length;
Dominik Brodowski624dd662009-10-24 15:52:44 +0200560 dev_dbg(&link->dev, "ray_init tib_length = 0x%02x\n", local->tib_length);
John Daiker141fa612009-03-10 06:59:54 -0700561 /* Initialize CCS's to buffer free state */
562 pccs = ccs_base(local);
563 for (i = 0; i < NUMBER_OF_CCS; i++) {
564 writeb(CCS_BUFFER_FREE, &(pccs++)->buffer_status);
565 }
566 init_startup_params(local);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700567
John Daiker141fa612009-03-10 06:59:54 -0700568 /* copy mac address to startup parameters */
569 if (parse_addr(phy_addr, local->sparm.b4.a_mac_addr)) {
570 p = local->sparm.b4.a_mac_addr;
571 } else {
572 memcpy(&local->sparm.b4.a_mac_addr,
573 &local->startup_res.station_addr, ADDRLEN);
574 p = local->sparm.b4.a_mac_addr;
575 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700576
John Daiker141fa612009-03-10 06:59:54 -0700577 clear_interrupt(local); /* Clear any interrupt from the card */
578 local->card_status = CARD_AWAITING_PARAM;
Dominik Brodowski624dd662009-10-24 15:52:44 +0200579 dev_dbg(&link->dev, "ray_init ending\n");
John Daiker141fa612009-03-10 06:59:54 -0700580 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700581} /* ray_init */
John Daiker141fa612009-03-10 06:59:54 -0700582
Linus Torvalds1da177e2005-04-16 15:20:36 -0700583/*===========================================================================*/
584/* Download startup parameters to the card and command it to read them */
585static int dl_startup_params(struct net_device *dev)
586{
John Daiker141fa612009-03-10 06:59:54 -0700587 int ccsindex;
588 ray_dev_t *local = netdev_priv(dev);
589 struct ccs __iomem *pccs;
590 struct pcmcia_device *link = local->finder;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700591
Dominik Brodowski624dd662009-10-24 15:52:44 +0200592 dev_dbg(&link->dev, "dl_startup_params entered\n");
John Daiker141fa612009-03-10 06:59:54 -0700593 if (!(pcmcia_dev_present(link))) {
Dominik Brodowski624dd662009-10-24 15:52:44 +0200594 dev_dbg(&link->dev, "ray_cs dl_startup_params - device not present\n");
John Daiker141fa612009-03-10 06:59:54 -0700595 return -1;
596 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700597
John Daiker141fa612009-03-10 06:59:54 -0700598 /* Copy parameters to host to ECF area */
599 if (local->fw_ver == 0x55)
600 memcpy_toio(local->sram + HOST_TO_ECF_BASE, &local->sparm.b4,
601 sizeof(struct b4_startup_params));
602 else
603 memcpy_toio(local->sram + HOST_TO_ECF_BASE, &local->sparm.b5,
604 sizeof(struct b5_startup_params));
605
606 /* Fill in the CCS fields for the ECF */
607 if ((ccsindex = get_free_ccs(local)) < 0)
608 return -1;
609 local->dl_param_ccs = ccsindex;
610 pccs = ccs_base(local) + ccsindex;
611 writeb(CCS_DOWNLOAD_STARTUP_PARAMS, &pccs->cmd);
Dominik Brodowski624dd662009-10-24 15:52:44 +0200612 dev_dbg(&link->dev, "dl_startup_params start ccsindex = %d\n",
John Daiker141fa612009-03-10 06:59:54 -0700613 local->dl_param_ccs);
614 /* Interrupt the firmware to process the command */
615 if (interrupt_ecf(local, ccsindex)) {
616 printk(KERN_INFO "ray dl_startup_params failed - "
617 "ECF not ready for intr\n");
618 local->card_status = CARD_DL_PARAM_ERROR;
619 writeb(CCS_BUFFER_FREE, &(pccs++)->buffer_status);
620 return -2;
621 }
622 local->card_status = CARD_DL_PARAM;
623 /* Start kernel timer to wait for dl startup to complete. */
624 local->timer.expires = jiffies + HZ / 2;
625 local->timer.data = (long)local;
626 local->timer.function = &verify_dl_startup;
627 add_timer(&local->timer);
Dominik Brodowski624dd662009-10-24 15:52:44 +0200628 dev_dbg(&link->dev,
John Daiker141fa612009-03-10 06:59:54 -0700629 "ray_cs dl_startup_params started timer for verify_dl_startup\n");
630 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700631} /* dl_startup_params */
John Daiker141fa612009-03-10 06:59:54 -0700632
Linus Torvalds1da177e2005-04-16 15:20:36 -0700633/*===========================================================================*/
634static void init_startup_params(ray_dev_t *local)
635{
John Daiker141fa612009-03-10 06:59:54 -0700636 int i;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700637
John Daiker141fa612009-03-10 06:59:54 -0700638 if (country > JAPAN_TEST)
639 country = USA;
640 else if (country < USA)
641 country = USA;
642 /* structure for hop time and beacon period is defined here using
643 * New 802.11D6.1 format. Card firmware is still using old format
644 * until version 6.
645 * Before After
646 * a_hop_time ms byte a_hop_time ms byte
647 * a_hop_time 2s byte a_hop_time ls byte
648 * a_hop_time ls byte a_beacon_period ms byte
649 * a_beacon_period a_beacon_period ls byte
650 *
651 * a_hop_time = uS a_hop_time = KuS
652 * a_beacon_period = hops a_beacon_period = KuS
653 *//* 64ms = 010000 */
654 if (local->fw_ver == 0x55) {
655 memcpy((UCHAR *) &local->sparm.b4, b4_default_startup_parms,
656 sizeof(struct b4_startup_params));
657 /* Translate sane kus input values to old build 4/5 format */
658 /* i = hop time in uS truncated to 3 bytes */
659 i = (hop_dwell * 1024) & 0xffffff;
660 local->sparm.b4.a_hop_time[0] = (i >> 16) & 0xff;
661 local->sparm.b4.a_hop_time[1] = (i >> 8) & 0xff;
662 local->sparm.b4.a_beacon_period[0] = 0;
663 local->sparm.b4.a_beacon_period[1] =
664 ((beacon_period / hop_dwell) - 1) & 0xff;
665 local->sparm.b4.a_curr_country_code = country;
666 local->sparm.b4.a_hop_pattern_length =
667 hop_pattern_length[(int)country] - 1;
668 if (bc) {
669 local->sparm.b4.a_ack_timeout = 0x50;
670 local->sparm.b4.a_sifs = 0x3f;
671 }
672 } else { /* Version 5 uses real kus values */
673 memcpy((UCHAR *) &local->sparm.b5, b5_default_startup_parms,
674 sizeof(struct b5_startup_params));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700675
John Daiker141fa612009-03-10 06:59:54 -0700676 local->sparm.b5.a_hop_time[0] = (hop_dwell >> 8) & 0xff;
677 local->sparm.b5.a_hop_time[1] = hop_dwell & 0xff;
678 local->sparm.b5.a_beacon_period[0] =
679 (beacon_period >> 8) & 0xff;
680 local->sparm.b5.a_beacon_period[1] = beacon_period & 0xff;
681 if (psm)
682 local->sparm.b5.a_power_mgt_state = 1;
683 local->sparm.b5.a_curr_country_code = country;
684 local->sparm.b5.a_hop_pattern_length =
685 hop_pattern_length[(int)country];
686 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700687
John Daiker141fa612009-03-10 06:59:54 -0700688 local->sparm.b4.a_network_type = net_type & 0x01;
689 local->sparm.b4.a_acting_as_ap_status = TYPE_STA;
690
691 if (essid != NULL)
692 strncpy(local->sparm.b4.a_current_ess_id, essid, ESSID_SIZE);
693} /* init_startup_params */
694
Linus Torvalds1da177e2005-04-16 15:20:36 -0700695/*===========================================================================*/
696static void verify_dl_startup(u_long data)
697{
John Daiker141fa612009-03-10 06:59:54 -0700698 ray_dev_t *local = (ray_dev_t *) data;
699 struct ccs __iomem *pccs = ccs_base(local) + local->dl_param_ccs;
700 UCHAR status;
701 struct pcmcia_device *link = local->finder;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700702
John Daiker141fa612009-03-10 06:59:54 -0700703 if (!(pcmcia_dev_present(link))) {
Dominik Brodowski624dd662009-10-24 15:52:44 +0200704 dev_dbg(&link->dev, "ray_cs verify_dl_startup - device not present\n");
John Daiker141fa612009-03-10 06:59:54 -0700705 return;
706 }
Dominik Brodowski624dd662009-10-24 15:52:44 +0200707#if 0
708 {
John Daiker141fa612009-03-10 06:59:54 -0700709 int i;
710 printk(KERN_DEBUG
711 "verify_dl_startup parameters sent via ccs %d:\n",
712 local->dl_param_ccs);
713 for (i = 0; i < sizeof(struct b5_startup_params); i++) {
714 printk(" %2x",
715 (unsigned int)readb(local->sram +
716 HOST_TO_ECF_BASE + i));
717 }
718 printk("\n");
719 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700720#endif
721
John Daiker141fa612009-03-10 06:59:54 -0700722 status = readb(&pccs->buffer_status);
723 if (status != CCS_BUFFER_FREE) {
724 printk(KERN_INFO
725 "Download startup params failed. Status = %d\n",
726 status);
727 local->card_status = CARD_DL_PARAM_ERROR;
728 return;
729 }
730 if (local->sparm.b4.a_network_type == ADHOC)
731 start_net((u_long) local);
732 else
733 join_net((u_long) local);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700734
John Daiker141fa612009-03-10 06:59:54 -0700735 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700736} /* end verify_dl_startup */
John Daiker141fa612009-03-10 06:59:54 -0700737
Linus Torvalds1da177e2005-04-16 15:20:36 -0700738/*===========================================================================*/
739/* Command card to start a network */
740static void start_net(u_long data)
741{
John Daiker141fa612009-03-10 06:59:54 -0700742 ray_dev_t *local = (ray_dev_t *) data;
743 struct ccs __iomem *pccs;
744 int ccsindex;
745 struct pcmcia_device *link = local->finder;
746 if (!(pcmcia_dev_present(link))) {
Dominik Brodowski624dd662009-10-24 15:52:44 +0200747 dev_dbg(&link->dev, "ray_cs start_net - device not present\n");
John Daiker141fa612009-03-10 06:59:54 -0700748 return;
749 }
750 /* Fill in the CCS fields for the ECF */
751 if ((ccsindex = get_free_ccs(local)) < 0)
752 return;
753 pccs = ccs_base(local) + ccsindex;
754 writeb(CCS_START_NETWORK, &pccs->cmd);
755 writeb(0, &pccs->var.start_network.update_param);
756 /* Interrupt the firmware to process the command */
757 if (interrupt_ecf(local, ccsindex)) {
Dominik Brodowski624dd662009-10-24 15:52:44 +0200758 dev_dbg(&link->dev, "ray start net failed - card not ready for intr\n");
John Daiker141fa612009-03-10 06:59:54 -0700759 writeb(CCS_BUFFER_FREE, &(pccs++)->buffer_status);
760 return;
761 }
762 local->card_status = CARD_DOING_ACQ;
763 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700764} /* end start_net */
John Daiker141fa612009-03-10 06:59:54 -0700765
Linus Torvalds1da177e2005-04-16 15:20:36 -0700766/*===========================================================================*/
767/* Command card to join a network */
768static void join_net(u_long data)
769{
John Daiker141fa612009-03-10 06:59:54 -0700770 ray_dev_t *local = (ray_dev_t *) data;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700771
John Daiker141fa612009-03-10 06:59:54 -0700772 struct ccs __iomem *pccs;
773 int ccsindex;
774 struct pcmcia_device *link = local->finder;
775
776 if (!(pcmcia_dev_present(link))) {
Dominik Brodowski624dd662009-10-24 15:52:44 +0200777 dev_dbg(&link->dev, "ray_cs join_net - device not present\n");
John Daiker141fa612009-03-10 06:59:54 -0700778 return;
779 }
780 /* Fill in the CCS fields for the ECF */
781 if ((ccsindex = get_free_ccs(local)) < 0)
782 return;
783 pccs = ccs_base(local) + ccsindex;
784 writeb(CCS_JOIN_NETWORK, &pccs->cmd);
785 writeb(0, &pccs->var.join_network.update_param);
786 writeb(0, &pccs->var.join_network.net_initiated);
787 /* Interrupt the firmware to process the command */
788 if (interrupt_ecf(local, ccsindex)) {
Dominik Brodowski624dd662009-10-24 15:52:44 +0200789 dev_dbg(&link->dev, "ray join net failed - card not ready for intr\n");
John Daiker141fa612009-03-10 06:59:54 -0700790 writeb(CCS_BUFFER_FREE, &(pccs++)->buffer_status);
791 return;
792 }
793 local->card_status = CARD_DOING_ACQ;
794 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700795}
John Daiker141fa612009-03-10 06:59:54 -0700796
Linus Torvalds1da177e2005-04-16 15:20:36 -0700797/*============================================================================
798 After a card is removed, ray_release() will unregister the net
799 device, and release the PCMCIA configuration. If the device is
800 still open, this will be postponed until it is closed.
801=============================================================================*/
Dominik Brodowskifba395e2006-03-31 17:21:06 +0200802static void ray_release(struct pcmcia_device *link)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700803{
John Daiker141fa612009-03-10 06:59:54 -0700804 struct net_device *dev = link->priv;
805 ray_dev_t *local = netdev_priv(dev);
806 int i;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700807
Dominik Brodowski624dd662009-10-24 15:52:44 +0200808 dev_dbg(&link->dev, "ray_release\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700809
John Daiker141fa612009-03-10 06:59:54 -0700810 del_timer(&local->timer);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700811
John Daiker141fa612009-03-10 06:59:54 -0700812 iounmap(local->sram);
813 iounmap(local->rmem);
814 iounmap(local->amem);
815 /* Do bother checking to see if these succeed or not */
Magnus Dammf5560da2006-12-13 19:46:38 +0900816 i = pcmcia_release_window(link, local->amem_handle);
John Daiker141fa612009-03-10 06:59:54 -0700817 if (i != 0)
Dominik Brodowski624dd662009-10-24 15:52:44 +0200818 dev_dbg(&link->dev, "ReleaseWindow(local->amem) ret = %x\n", i);
Magnus Dammf5560da2006-12-13 19:46:38 +0900819 i = pcmcia_release_window(link, local->rmem_handle);
John Daiker141fa612009-03-10 06:59:54 -0700820 if (i != 0)
Dominik Brodowski624dd662009-10-24 15:52:44 +0200821 dev_dbg(&link->dev, "ReleaseWindow(local->rmem) ret = %x\n", i);
John Daiker141fa612009-03-10 06:59:54 -0700822 pcmcia_disable_device(link);
823
Dominik Brodowski624dd662009-10-24 15:52:44 +0200824 dev_dbg(&link->dev, "ray_release ending\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700825}
826
Dominik Brodowskifba395e2006-03-31 17:21:06 +0200827static int ray_suspend(struct pcmcia_device *link)
Dominik Brodowski98e4c282005-11-14 21:21:18 +0100828{
Dominik Brodowski98e4c282005-11-14 21:21:18 +0100829 struct net_device *dev = link->priv;
830
Dominik Brodowskie2d40962006-03-02 00:09:29 +0100831 if (link->open)
Dominik Brodowski8661bb52006-03-02 00:02:33 +0100832 netif_device_detach(dev);
Dominik Brodowski98e4c282005-11-14 21:21:18 +0100833
834 return 0;
835}
836
Dominik Brodowskifba395e2006-03-31 17:21:06 +0200837static int ray_resume(struct pcmcia_device *link)
Dominik Brodowski98e4c282005-11-14 21:21:18 +0100838{
Dominik Brodowski98e4c282005-11-14 21:21:18 +0100839 struct net_device *dev = link->priv;
840
Dominik Brodowskie2d40962006-03-02 00:09:29 +0100841 if (link->open) {
Dominik Brodowski8661bb52006-03-02 00:02:33 +0100842 ray_reset(dev);
843 netif_device_attach(dev);
844 }
Dominik Brodowski98e4c282005-11-14 21:21:18 +0100845
846 return 0;
847}
848
Linus Torvalds1da177e2005-04-16 15:20:36 -0700849/*===========================================================================*/
Hannes Eder2ed5ba82008-12-26 00:12:59 -0800850static int ray_dev_init(struct net_device *dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700851{
852#ifdef RAY_IMMEDIATE_INIT
John Daiker141fa612009-03-10 06:59:54 -0700853 int i;
854#endif /* RAY_IMMEDIATE_INIT */
855 ray_dev_t *local = netdev_priv(dev);
856 struct pcmcia_device *link = local->finder;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700857
Dominik Brodowski624dd662009-10-24 15:52:44 +0200858 dev_dbg(&link->dev, "ray_dev_init(dev=%p)\n", dev);
John Daiker141fa612009-03-10 06:59:54 -0700859 if (!(pcmcia_dev_present(link))) {
Dominik Brodowski624dd662009-10-24 15:52:44 +0200860 dev_dbg(&link->dev, "ray_dev_init - device not present\n");
John Daiker141fa612009-03-10 06:59:54 -0700861 return -1;
862 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700863#ifdef RAY_IMMEDIATE_INIT
John Daiker141fa612009-03-10 06:59:54 -0700864 /* Download startup parameters */
865 if ((i = dl_startup_params(dev)) < 0) {
866 printk(KERN_INFO "ray_dev_init dl_startup_params failed - "
867 "returns 0x%x\n", i);
868 return -1;
869 }
870#else /* RAY_IMMEDIATE_INIT */
871 /* Postpone the card init so that we can still configure the card,
872 * for example using the Wireless Extensions. The init will happen
873 * in ray_open() - Jean II */
Dominik Brodowski624dd662009-10-24 15:52:44 +0200874 dev_dbg(&link->dev,
John Daiker141fa612009-03-10 06:59:54 -0700875 "ray_dev_init: postponing card init to ray_open() ; Status = %d\n",
876 local->card_status);
877#endif /* RAY_IMMEDIATE_INIT */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700878
John Daiker141fa612009-03-10 06:59:54 -0700879 /* copy mac and broadcast addresses to linux device */
Jiri Pirko3a6d54c2009-05-11 23:37:15 +0000880 memcpy(dev->dev_addr, &local->sparm.b4.a_mac_addr, ADDRLEN);
John Daiker141fa612009-03-10 06:59:54 -0700881 memset(dev->broadcast, 0xff, ETH_ALEN);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700882
Dominik Brodowski624dd662009-10-24 15:52:44 +0200883 dev_dbg(&link->dev, "ray_dev_init ending\n");
John Daiker141fa612009-03-10 06:59:54 -0700884 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700885}
John Daiker141fa612009-03-10 06:59:54 -0700886
Linus Torvalds1da177e2005-04-16 15:20:36 -0700887/*===========================================================================*/
888static int ray_dev_config(struct net_device *dev, struct ifmap *map)
889{
John Daiker141fa612009-03-10 06:59:54 -0700890 ray_dev_t *local = netdev_priv(dev);
891 struct pcmcia_device *link = local->finder;
892 /* Dummy routine to satisfy device structure */
Dominik Brodowski624dd662009-10-24 15:52:44 +0200893 dev_dbg(&link->dev, "ray_dev_config(dev=%p,ifmap=%p)\n", dev, map);
John Daiker141fa612009-03-10 06:59:54 -0700894 if (!(pcmcia_dev_present(link))) {
Dominik Brodowski624dd662009-10-24 15:52:44 +0200895 dev_dbg(&link->dev, "ray_dev_config - device not present\n");
John Daiker141fa612009-03-10 06:59:54 -0700896 return -1;
897 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700898
John Daiker141fa612009-03-10 06:59:54 -0700899 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700900}
John Daiker141fa612009-03-10 06:59:54 -0700901
Linus Torvalds1da177e2005-04-16 15:20:36 -0700902/*===========================================================================*/
Stephen Hemmingerd0cf9c02009-08-31 19:50:57 +0000903static netdev_tx_t ray_dev_start_xmit(struct sk_buff *skb,
904 struct net_device *dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700905{
John Daiker141fa612009-03-10 06:59:54 -0700906 ray_dev_t *local = netdev_priv(dev);
907 struct pcmcia_device *link = local->finder;
908 short length = skb->len;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700909
Stephen Hemmingerd0cf9c02009-08-31 19:50:57 +0000910 if (!pcmcia_dev_present(link)) {
Dominik Brodowski624dd662009-10-24 15:52:44 +0200911 dev_dbg(&link->dev, "ray_dev_start_xmit - device not present\n");
Stephen Hemmingerd0cf9c02009-08-31 19:50:57 +0000912 dev_kfree_skb(skb);
913 return NETDEV_TX_OK;
John Daiker141fa612009-03-10 06:59:54 -0700914 }
Stephen Hemmingerd0cf9c02009-08-31 19:50:57 +0000915
Dominik Brodowski624dd662009-10-24 15:52:44 +0200916 dev_dbg(&link->dev, "ray_dev_start_xmit(skb=%p, dev=%p)\n", skb, dev);
John Daiker141fa612009-03-10 06:59:54 -0700917 if (local->authentication_state == NEED_TO_AUTH) {
Dominik Brodowski624dd662009-10-24 15:52:44 +0200918 dev_dbg(&link->dev, "ray_cs Sending authentication request.\n");
John Daiker141fa612009-03-10 06:59:54 -0700919 if (!build_auth_frame(local, local->auth_id, OPEN_AUTH_REQUEST)) {
920 local->authentication_state = AUTHENTICATED;
921 netif_stop_queue(dev);
Patrick McHardy5b548142009-06-12 06:22:29 +0000922 return NETDEV_TX_BUSY;
John Daiker141fa612009-03-10 06:59:54 -0700923 }
924 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700925
John Daiker141fa612009-03-10 06:59:54 -0700926 if (length < ETH_ZLEN) {
927 if (skb_padto(skb, ETH_ZLEN))
Patrick McHardy6ed10652009-06-23 06:03:08 +0000928 return NETDEV_TX_OK;
John Daiker141fa612009-03-10 06:59:54 -0700929 length = ETH_ZLEN;
930 }
931 switch (ray_hw_xmit(skb->data, length, dev, DATA_TYPE)) {
932 case XMIT_NO_CCS:
933 case XMIT_NEED_AUTH:
934 netif_stop_queue(dev);
Patrick McHardy5b548142009-06-12 06:22:29 +0000935 return NETDEV_TX_BUSY;
John Daiker141fa612009-03-10 06:59:54 -0700936 case XMIT_NO_INTR:
937 case XMIT_MSG_BAD:
938 case XMIT_OK:
939 default:
940 dev->trans_start = jiffies;
941 dev_kfree_skb(skb);
John Daiker141fa612009-03-10 06:59:54 -0700942 }
Stephen Hemmingerd0cf9c02009-08-31 19:50:57 +0000943
Patrick McHardy6ed10652009-06-23 06:03:08 +0000944 return NETDEV_TX_OK;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700945} /* ray_dev_start_xmit */
John Daiker141fa612009-03-10 06:59:54 -0700946
Linus Torvalds1da177e2005-04-16 15:20:36 -0700947/*===========================================================================*/
John Daiker141fa612009-03-10 06:59:54 -0700948static int ray_hw_xmit(unsigned char *data, int len, struct net_device *dev,
949 UCHAR msg_type)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700950{
John Daiker141fa612009-03-10 06:59:54 -0700951 ray_dev_t *local = netdev_priv(dev);
952 struct ccs __iomem *pccs;
953 int ccsindex;
954 int offset;
955 struct tx_msg __iomem *ptx; /* Address of xmit buffer in PC space */
956 short int addr; /* Address of xmit buffer in card space */
957
Dominik Brodowski624dd662009-10-24 15:52:44 +0200958 pr_debug("ray_hw_xmit(data=%p, len=%d, dev=%p)\n", data, len, dev);
John Daiker141fa612009-03-10 06:59:54 -0700959 if (len + TX_HEADER_LENGTH > TX_BUF_SIZE) {
960 printk(KERN_INFO "ray_hw_xmit packet too large: %d bytes\n",
961 len);
962 return XMIT_MSG_BAD;
963 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700964 switch (ccsindex = get_free_tx_ccs(local)) {
965 case ECCSBUSY:
Dominik Brodowski624dd662009-10-24 15:52:44 +0200966 pr_debug("ray_hw_xmit tx_ccs table busy\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700967 case ECCSFULL:
Dominik Brodowski624dd662009-10-24 15:52:44 +0200968 pr_debug("ray_hw_xmit No free tx ccs\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700969 case ECARDGONE:
John Daiker141fa612009-03-10 06:59:54 -0700970 netif_stop_queue(dev);
971 return XMIT_NO_CCS;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700972 default:
973 break;
974 }
John Daiker141fa612009-03-10 06:59:54 -0700975 addr = TX_BUF_BASE + (ccsindex << 11);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700976
John Daiker141fa612009-03-10 06:59:54 -0700977 if (msg_type == DATA_TYPE) {
978 local->stats.tx_bytes += len;
979 local->stats.tx_packets++;
980 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700981
John Daiker141fa612009-03-10 06:59:54 -0700982 ptx = local->sram + addr;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700983
John Daiker141fa612009-03-10 06:59:54 -0700984 ray_build_header(local, ptx, msg_type, data);
985 if (translate) {
986 offset = translate_frame(local, ptx, data, len);
987 } else { /* Encapsulate frame */
988 /* TBD TIB length will move address of ptx->var */
989 memcpy_toio(&ptx->var, data, len);
990 offset = 0;
991 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700992
John Daiker141fa612009-03-10 06:59:54 -0700993 /* fill in the CCS */
994 pccs = ccs_base(local) + ccsindex;
995 len += TX_HEADER_LENGTH + offset;
996 writeb(CCS_TX_REQUEST, &pccs->cmd);
997 writeb(addr >> 8, &pccs->var.tx_request.tx_data_ptr[0]);
998 writeb(local->tib_length, &pccs->var.tx_request.tx_data_ptr[1]);
999 writeb(len >> 8, &pccs->var.tx_request.tx_data_length[0]);
1000 writeb(len & 0xff, &pccs->var.tx_request.tx_data_length[1]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001001/* TBD still need psm_cam? */
John Daiker141fa612009-03-10 06:59:54 -07001002 writeb(PSM_CAM, &pccs->var.tx_request.pow_sav_mode);
1003 writeb(local->net_default_tx_rate, &pccs->var.tx_request.tx_rate);
1004 writeb(0, &pccs->var.tx_request.antenna);
Dominik Brodowski624dd662009-10-24 15:52:44 +02001005 pr_debug("ray_hw_xmit default_tx_rate = 0x%x\n",
John Daiker141fa612009-03-10 06:59:54 -07001006 local->net_default_tx_rate);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001007
John Daiker141fa612009-03-10 06:59:54 -07001008 /* Interrupt the firmware to process the command */
1009 if (interrupt_ecf(local, ccsindex)) {
Dominik Brodowski624dd662009-10-24 15:52:44 +02001010 pr_debug("ray_hw_xmit failed - ECF not ready for intr\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001011/* TBD very inefficient to copy packet to buffer, and then not
1012 send it, but the alternative is to queue the messages and that
1013 won't be done for a while. Maybe set tbusy until a CCS is free?
1014*/
John Daiker141fa612009-03-10 06:59:54 -07001015 writeb(CCS_BUFFER_FREE, &pccs->buffer_status);
1016 return XMIT_NO_INTR;
1017 }
1018 return XMIT_OK;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001019} /* end ray_hw_xmit */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001020
John Daiker141fa612009-03-10 06:59:54 -07001021/*===========================================================================*/
1022static int translate_frame(ray_dev_t *local, struct tx_msg __iomem *ptx,
1023 unsigned char *data, int len)
1024{
1025 __be16 proto = ((struct ethhdr *)data)->h_proto;
1026 if (ntohs(proto) >= 1536) { /* DIX II ethernet frame */
Dominik Brodowski624dd662009-10-24 15:52:44 +02001027 pr_debug("ray_cs translate_frame DIX II\n");
John Daiker141fa612009-03-10 06:59:54 -07001028 /* Copy LLC header to card buffer */
1029 memcpy_toio(&ptx->var, eth2_llc, sizeof(eth2_llc));
1030 memcpy_toio(((void __iomem *)&ptx->var) + sizeof(eth2_llc),
1031 (UCHAR *) &proto, 2);
1032 if (proto == htons(ETH_P_AARP) || proto == htons(ETH_P_IPX)) {
1033 /* This is the selective translation table, only 2 entries */
1034 writeb(0xf8,
1035 &((struct snaphdr_t __iomem *)ptx->var)->org[3]);
1036 }
1037 /* Copy body of ethernet packet without ethernet header */
1038 memcpy_toio((void __iomem *)&ptx->var +
1039 sizeof(struct snaphdr_t), data + ETH_HLEN,
1040 len - ETH_HLEN);
1041 return (int)sizeof(struct snaphdr_t) - ETH_HLEN;
1042 } else { /* already 802 type, and proto is length */
Dominik Brodowski624dd662009-10-24 15:52:44 +02001043 pr_debug("ray_cs translate_frame 802\n");
John Daiker141fa612009-03-10 06:59:54 -07001044 if (proto == htons(0xffff)) { /* evil netware IPX 802.3 without LLC */
Dominik Brodowski624dd662009-10-24 15:52:44 +02001045 pr_debug("ray_cs translate_frame evil IPX\n");
John Daiker141fa612009-03-10 06:59:54 -07001046 memcpy_toio(&ptx->var, data + ETH_HLEN, len - ETH_HLEN);
1047 return 0 - ETH_HLEN;
1048 }
1049 memcpy_toio(&ptx->var, data + ETH_HLEN, len - ETH_HLEN);
1050 return 0 - ETH_HLEN;
1051 }
1052 /* TBD do other frame types */
1053} /* end translate_frame */
1054
1055/*===========================================================================*/
1056static void ray_build_header(ray_dev_t *local, struct tx_msg __iomem *ptx,
1057 UCHAR msg_type, unsigned char *data)
1058{
1059 writeb(PROTOCOL_VER | msg_type, &ptx->mac.frame_ctl_1);
1060/*** IEEE 802.11 Address field assignments *************
1061 TODS FROMDS addr_1 addr_2 addr_3 addr_4
1062Adhoc 0 0 dest src (terminal) BSSID N/A
1063AP to Terminal 0 1 dest AP(BSSID) source N/A
1064Terminal to AP 1 0 AP(BSSID) src (terminal) dest N/A
1065AP to AP 1 1 dest AP src AP dest source
1066*******************************************************/
1067 if (local->net_type == ADHOC) {
1068 writeb(0, &ptx->mac.frame_ctl_2);
1069 memcpy_toio(ptx->mac.addr_1, ((struct ethhdr *)data)->h_dest,
1070 2 * ADDRLEN);
1071 memcpy_toio(ptx->mac.addr_3, local->bss_id, ADDRLEN);
1072 } else { /* infrastructure */
1073
1074 if (local->sparm.b4.a_acting_as_ap_status) {
1075 writeb(FC2_FROM_DS, &ptx->mac.frame_ctl_2);
1076 memcpy_toio(ptx->mac.addr_1,
1077 ((struct ethhdr *)data)->h_dest, ADDRLEN);
1078 memcpy_toio(ptx->mac.addr_2, local->bss_id, 6);
1079 memcpy_toio(ptx->mac.addr_3,
1080 ((struct ethhdr *)data)->h_source, ADDRLEN);
1081 } else { /* Terminal */
1082
1083 writeb(FC2_TO_DS, &ptx->mac.frame_ctl_2);
1084 memcpy_toio(ptx->mac.addr_1, local->bss_id, ADDRLEN);
1085 memcpy_toio(ptx->mac.addr_2,
1086 ((struct ethhdr *)data)->h_source, ADDRLEN);
1087 memcpy_toio(ptx->mac.addr_3,
1088 ((struct ethhdr *)data)->h_dest, ADDRLEN);
1089 }
1090 }
1091} /* end encapsulate_frame */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001092
1093/*===========================================================================*/
1094
1095static void netdev_get_drvinfo(struct net_device *dev,
1096 struct ethtool_drvinfo *info)
1097{
1098 strcpy(info->driver, "ray_cs");
1099}
1100
Jeff Garzik7282d492006-09-13 14:30:00 -04001101static const struct ethtool_ops netdev_ethtool_ops = {
John Daiker141fa612009-03-10 06:59:54 -07001102 .get_drvinfo = netdev_get_drvinfo,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001103};
1104
1105/*====================================================================*/
1106
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001107/*------------------------------------------------------------------*/
1108/*
1109 * Wireless Handler : get protocol name
1110 */
1111static int ray_get_name(struct net_device *dev,
John Daiker141fa612009-03-10 06:59:54 -07001112 struct iw_request_info *info, char *cwrq, char *extra)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001113{
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001114 strcpy(cwrq, "IEEE 802.11-FH");
1115 return 0;
1116}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001117
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001118/*------------------------------------------------------------------*/
1119/*
1120 * Wireless Handler : set frequency
1121 */
1122static int ray_set_freq(struct net_device *dev,
1123 struct iw_request_info *info,
John Daiker141fa612009-03-10 06:59:54 -07001124 struct iw_freq *fwrq, char *extra)
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001125{
Yoann Padioleau6dbc9c82007-08-03 19:37:16 +02001126 ray_dev_t *local = netdev_priv(dev);
John Daiker141fa612009-03-10 06:59:54 -07001127 int err = -EINPROGRESS; /* Call commit handler */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001128
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001129 /* Reject if card is already initialised */
John Daiker141fa612009-03-10 06:59:54 -07001130 if (local->card_status != CARD_AWAITING_PARAM)
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001131 return -EBUSY;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001132
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001133 /* Setting by channel number */
1134 if ((fwrq->m > USA_HOP_MOD) || (fwrq->e > 0))
Linus Torvalds1da177e2005-04-16 15:20:36 -07001135 err = -EOPNOTSUPP;
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001136 else
1137 local->sparm.b5.a_hop_pattern = fwrq->m;
1138
1139 return err;
1140}
John Daiker141fa612009-03-10 06:59:54 -07001141
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001142/*------------------------------------------------------------------*/
1143/*
1144 * Wireless Handler : get frequency
1145 */
1146static int ray_get_freq(struct net_device *dev,
1147 struct iw_request_info *info,
John Daiker141fa612009-03-10 06:59:54 -07001148 struct iw_freq *fwrq, char *extra)
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001149{
Yoann Padioleau6dbc9c82007-08-03 19:37:16 +02001150 ray_dev_t *local = netdev_priv(dev);
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001151
1152 fwrq->m = local->sparm.b5.a_hop_pattern;
1153 fwrq->e = 0;
1154 return 0;
1155}
1156
1157/*------------------------------------------------------------------*/
1158/*
1159 * Wireless Handler : set ESSID
1160 */
1161static int ray_set_essid(struct net_device *dev,
1162 struct iw_request_info *info,
John Daiker141fa612009-03-10 06:59:54 -07001163 struct iw_point *dwrq, char *extra)
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001164{
Yoann Padioleau6dbc9c82007-08-03 19:37:16 +02001165 ray_dev_t *local = netdev_priv(dev);
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001166
1167 /* Reject if card is already initialised */
John Daiker141fa612009-03-10 06:59:54 -07001168 if (local->card_status != CARD_AWAITING_PARAM)
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001169 return -EBUSY;
1170
1171 /* Check if we asked for `any' */
John Daiker141fa612009-03-10 06:59:54 -07001172 if (dwrq->flags == 0) {
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001173 /* Corey : can you do that ? */
1174 return -EOPNOTSUPP;
1175 } else {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001176 /* Check the size of the string */
John Daiker141fa612009-03-10 06:59:54 -07001177 if (dwrq->length > IW_ESSID_MAX_SIZE) {
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001178 return -E2BIG;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001179 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001180
1181 /* Set the ESSID in the card */
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001182 memset(local->sparm.b5.a_current_ess_id, 0, IW_ESSID_MAX_SIZE);
1183 memcpy(local->sparm.b5.a_current_ess_id, extra, dwrq->length);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001184 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001185
John Daiker141fa612009-03-10 06:59:54 -07001186 return -EINPROGRESS; /* Call commit handler */
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001187}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001188
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001189/*------------------------------------------------------------------*/
1190/*
1191 * Wireless Handler : get ESSID
1192 */
1193static int ray_get_essid(struct net_device *dev,
1194 struct iw_request_info *info,
John Daiker141fa612009-03-10 06:59:54 -07001195 struct iw_point *dwrq, char *extra)
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001196{
Yoann Padioleau6dbc9c82007-08-03 19:37:16 +02001197 ray_dev_t *local = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001198
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001199 /* Get the essid that was set */
1200 memcpy(extra, local->sparm.b5.a_current_ess_id, IW_ESSID_MAX_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001201
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001202 /* Push it out ! */
Dan Williamsd6a13a22006-01-12 15:00:58 -05001203 dwrq->length = strlen(extra);
John Daiker141fa612009-03-10 06:59:54 -07001204 dwrq->flags = 1; /* active */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001205
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001206 return 0;
1207}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001208
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001209/*------------------------------------------------------------------*/
1210/*
1211 * Wireless Handler : get AP address
1212 */
1213static int ray_get_wap(struct net_device *dev,
John Daiker141fa612009-03-10 06:59:54 -07001214 struct iw_request_info *info,
1215 struct sockaddr *awrq, char *extra)
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001216{
Yoann Padioleau6dbc9c82007-08-03 19:37:16 +02001217 ray_dev_t *local = netdev_priv(dev);
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001218
1219 memcpy(awrq->sa_data, local->bss_id, ETH_ALEN);
1220 awrq->sa_family = ARPHRD_ETHER;
1221
1222 return 0;
1223}
1224
1225/*------------------------------------------------------------------*/
1226/*
1227 * Wireless Handler : set Bit-Rate
1228 */
1229static int ray_set_rate(struct net_device *dev,
1230 struct iw_request_info *info,
John Daiker141fa612009-03-10 06:59:54 -07001231 struct iw_param *vwrq, char *extra)
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001232{
Yoann Padioleau6dbc9c82007-08-03 19:37:16 +02001233 ray_dev_t *local = netdev_priv(dev);
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001234
1235 /* Reject if card is already initialised */
John Daiker141fa612009-03-10 06:59:54 -07001236 if (local->card_status != CARD_AWAITING_PARAM)
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001237 return -EBUSY;
1238
1239 /* Check if rate is in range */
John Daiker141fa612009-03-10 06:59:54 -07001240 if ((vwrq->value != 1000000) && (vwrq->value != 2000000))
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001241 return -EINVAL;
1242
1243 /* Hack for 1.5 Mb/s instead of 2 Mb/s */
John Daiker141fa612009-03-10 06:59:54 -07001244 if ((local->fw_ver == 0x55) && /* Please check */
1245 (vwrq->value == 2000000))
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001246 local->net_default_tx_rate = 3;
1247 else
John Daiker141fa612009-03-10 06:59:54 -07001248 local->net_default_tx_rate = vwrq->value / 500000;
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001249
1250 return 0;
1251}
1252
1253/*------------------------------------------------------------------*/
1254/*
1255 * Wireless Handler : get Bit-Rate
1256 */
1257static int ray_get_rate(struct net_device *dev,
1258 struct iw_request_info *info,
John Daiker141fa612009-03-10 06:59:54 -07001259 struct iw_param *vwrq, char *extra)
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001260{
Yoann Padioleau6dbc9c82007-08-03 19:37:16 +02001261 ray_dev_t *local = netdev_priv(dev);
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001262
John Daiker141fa612009-03-10 06:59:54 -07001263 if (local->net_default_tx_rate == 3)
1264 vwrq->value = 2000000; /* Hum... */
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001265 else
1266 vwrq->value = local->net_default_tx_rate * 500000;
John Daiker141fa612009-03-10 06:59:54 -07001267 vwrq->fixed = 0; /* We are in auto mode */
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001268
1269 return 0;
1270}
1271
1272/*------------------------------------------------------------------*/
1273/*
1274 * Wireless Handler : set RTS threshold
1275 */
1276static int ray_set_rts(struct net_device *dev,
1277 struct iw_request_info *info,
John Daiker141fa612009-03-10 06:59:54 -07001278 struct iw_param *vwrq, char *extra)
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001279{
Yoann Padioleau6dbc9c82007-08-03 19:37:16 +02001280 ray_dev_t *local = netdev_priv(dev);
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001281 int rthr = vwrq->value;
1282
1283 /* Reject if card is already initialised */
John Daiker141fa612009-03-10 06:59:54 -07001284 if (local->card_status != CARD_AWAITING_PARAM)
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001285 return -EBUSY;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001286
1287 /* if(wrq->u.rts.fixed == 0) we should complain */
John Daiker141fa612009-03-10 06:59:54 -07001288 if (vwrq->disabled)
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001289 rthr = 32767;
1290 else {
John Daiker141fa612009-03-10 06:59:54 -07001291 if ((rthr < 0) || (rthr > 2347)) /* What's the max packet size ??? */
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001292 return -EINVAL;
1293 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001294 local->sparm.b5.a_rts_threshold[0] = (rthr >> 8) & 0xFF;
1295 local->sparm.b5.a_rts_threshold[1] = rthr & 0xFF;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001296
John Daiker141fa612009-03-10 06:59:54 -07001297 return -EINPROGRESS; /* Call commit handler */
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001298}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001299
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001300/*------------------------------------------------------------------*/
1301/*
1302 * Wireless Handler : get RTS threshold
1303 */
1304static int ray_get_rts(struct net_device *dev,
1305 struct iw_request_info *info,
John Daiker141fa612009-03-10 06:59:54 -07001306 struct iw_param *vwrq, char *extra)
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001307{
Yoann Padioleau6dbc9c82007-08-03 19:37:16 +02001308 ray_dev_t *local = netdev_priv(dev);
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001309
1310 vwrq->value = (local->sparm.b5.a_rts_threshold[0] << 8)
John Daiker141fa612009-03-10 06:59:54 -07001311 + local->sparm.b5.a_rts_threshold[1];
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001312 vwrq->disabled = (vwrq->value == 32767);
1313 vwrq->fixed = 1;
1314
1315 return 0;
1316}
1317
1318/*------------------------------------------------------------------*/
1319/*
1320 * Wireless Handler : set Fragmentation threshold
1321 */
1322static int ray_set_frag(struct net_device *dev,
1323 struct iw_request_info *info,
John Daiker141fa612009-03-10 06:59:54 -07001324 struct iw_param *vwrq, char *extra)
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001325{
Yoann Padioleau6dbc9c82007-08-03 19:37:16 +02001326 ray_dev_t *local = netdev_priv(dev);
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001327 int fthr = vwrq->value;
1328
1329 /* Reject if card is already initialised */
John Daiker141fa612009-03-10 06:59:54 -07001330 if (local->card_status != CARD_AWAITING_PARAM)
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001331 return -EBUSY;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001332
1333 /* if(wrq->u.frag.fixed == 0) should complain */
John Daiker141fa612009-03-10 06:59:54 -07001334 if (vwrq->disabled)
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001335 fthr = 32767;
1336 else {
John Daiker141fa612009-03-10 06:59:54 -07001337 if ((fthr < 256) || (fthr > 2347)) /* To check out ! */
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001338 return -EINVAL;
1339 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001340 local->sparm.b5.a_frag_threshold[0] = (fthr >> 8) & 0xFF;
1341 local->sparm.b5.a_frag_threshold[1] = fthr & 0xFF;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001342
John Daiker141fa612009-03-10 06:59:54 -07001343 return -EINPROGRESS; /* Call commit handler */
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001344}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001345
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001346/*------------------------------------------------------------------*/
1347/*
1348 * Wireless Handler : get Fragmentation threshold
1349 */
1350static int ray_get_frag(struct net_device *dev,
1351 struct iw_request_info *info,
John Daiker141fa612009-03-10 06:59:54 -07001352 struct iw_param *vwrq, char *extra)
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001353{
Yoann Padioleau6dbc9c82007-08-03 19:37:16 +02001354 ray_dev_t *local = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001355
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001356 vwrq->value = (local->sparm.b5.a_frag_threshold[0] << 8)
John Daiker141fa612009-03-10 06:59:54 -07001357 + local->sparm.b5.a_frag_threshold[1];
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001358 vwrq->disabled = (vwrq->value == 32767);
1359 vwrq->fixed = 1;
1360
1361 return 0;
1362}
1363
1364/*------------------------------------------------------------------*/
1365/*
1366 * Wireless Handler : set Mode of Operation
1367 */
1368static int ray_set_mode(struct net_device *dev,
John Daiker141fa612009-03-10 06:59:54 -07001369 struct iw_request_info *info, __u32 *uwrq, char *extra)
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001370{
Yoann Padioleau6dbc9c82007-08-03 19:37:16 +02001371 ray_dev_t *local = netdev_priv(dev);
John Daiker141fa612009-03-10 06:59:54 -07001372 int err = -EINPROGRESS; /* Call commit handler */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001373 char card_mode = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001374
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001375 /* Reject if card is already initialised */
John Daiker141fa612009-03-10 06:59:54 -07001376 if (local->card_status != CARD_AWAITING_PARAM)
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001377 return -EBUSY;
1378
John Daiker141fa612009-03-10 06:59:54 -07001379 switch (*uwrq) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001380 case IW_MODE_ADHOC:
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001381 card_mode = 0;
John Daiker141fa612009-03-10 06:59:54 -07001382 /* Fall through */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001383 case IW_MODE_INFRA:
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001384 local->sparm.b5.a_network_type = card_mode;
1385 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001386 default:
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001387 err = -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001388 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001389
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001390 return err;
1391}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001392
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001393/*------------------------------------------------------------------*/
1394/*
1395 * Wireless Handler : get Mode of Operation
1396 */
1397static int ray_get_mode(struct net_device *dev,
John Daiker141fa612009-03-10 06:59:54 -07001398 struct iw_request_info *info, __u32 *uwrq, char *extra)
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001399{
Yoann Padioleau6dbc9c82007-08-03 19:37:16 +02001400 ray_dev_t *local = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001401
John Daiker141fa612009-03-10 06:59:54 -07001402 if (local->sparm.b5.a_network_type)
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001403 *uwrq = IW_MODE_INFRA;
1404 else
1405 *uwrq = IW_MODE_ADHOC;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001406
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001407 return 0;
1408}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001409
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001410/*------------------------------------------------------------------*/
1411/*
1412 * Wireless Handler : get range info
1413 */
1414static int ray_get_range(struct net_device *dev,
1415 struct iw_request_info *info,
John Daiker141fa612009-03-10 06:59:54 -07001416 struct iw_point *dwrq, char *extra)
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001417{
John Daiker141fa612009-03-10 06:59:54 -07001418 struct iw_range *range = (struct iw_range *)extra;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001419
John Daiker141fa612009-03-10 06:59:54 -07001420 memset((char *)range, 0, sizeof(struct iw_range));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001421
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001422 /* Set the length (very important for backward compatibility) */
1423 dwrq->length = sizeof(struct iw_range);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001424
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001425 /* Set the Wireless Extension versions */
1426 range->we_version_compiled = WIRELESS_EXT;
1427 range->we_version_source = 9;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001428
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001429 /* Set information in the range struct */
1430 range->throughput = 1.1 * 1000 * 1000; /* Put the right number here */
John Daiker141fa612009-03-10 06:59:54 -07001431 range->num_channels = hop_pattern_length[(int)country];
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001432 range->num_frequency = 0;
1433 range->max_qual.qual = 0;
1434 range->max_qual.level = 255; /* What's the correct value ? */
1435 range->max_qual.noise = 255; /* Idem */
1436 range->num_bitrates = 2;
1437 range->bitrate[0] = 1000000; /* 1 Mb/s */
1438 range->bitrate[1] = 2000000; /* 2 Mb/s */
1439 return 0;
1440}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001441
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001442/*------------------------------------------------------------------*/
1443/*
1444 * Wireless Private Handler : set framing mode
1445 */
1446static int ray_set_framing(struct net_device *dev,
1447 struct iw_request_info *info,
John Daiker141fa612009-03-10 06:59:54 -07001448 union iwreq_data *wrqu, char *extra)
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001449{
1450 translate = *(extra); /* Set framing mode */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001451
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001452 return 0;
1453}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001454
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001455/*------------------------------------------------------------------*/
1456/*
1457 * Wireless Private Handler : get framing mode
1458 */
1459static int ray_get_framing(struct net_device *dev,
1460 struct iw_request_info *info,
John Daiker141fa612009-03-10 06:59:54 -07001461 union iwreq_data *wrqu, char *extra)
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001462{
1463 *(extra) = translate;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001464
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001465 return 0;
1466}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001467
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001468/*------------------------------------------------------------------*/
1469/*
1470 * Wireless Private Handler : get country
1471 */
1472static int ray_get_country(struct net_device *dev,
1473 struct iw_request_info *info,
John Daiker141fa612009-03-10 06:59:54 -07001474 union iwreq_data *wrqu, char *extra)
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001475{
1476 *(extra) = country;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001477
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001478 return 0;
1479}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001480
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001481/*------------------------------------------------------------------*/
1482/*
1483 * Commit handler : called after a bunch of SET operations
1484 */
John Daiker141fa612009-03-10 06:59:54 -07001485static int ray_commit(struct net_device *dev, struct iw_request_info *info, /* NULL */
1486 void *zwrq, /* NULL */
1487 char *extra)
1488{ /* NULL */
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001489 return 0;
1490}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001491
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001492/*------------------------------------------------------------------*/
1493/*
1494 * Stats handler : return Wireless Stats
1495 */
John Daiker141fa612009-03-10 06:59:54 -07001496static iw_stats *ray_get_wireless_stats(struct net_device *dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001497{
John Daiker141fa612009-03-10 06:59:54 -07001498 ray_dev_t *local = netdev_priv(dev);
1499 struct pcmcia_device *link = local->finder;
1500 struct status __iomem *p = local->sram + STATUS_BASE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001501
John Daiker141fa612009-03-10 06:59:54 -07001502 local->wstats.status = local->card_status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001503#ifdef WIRELESS_SPY
John Daiker141fa612009-03-10 06:59:54 -07001504 if ((local->spy_data.spy_number > 0)
1505 && (local->sparm.b5.a_network_type == 0)) {
1506 /* Get it from the first node in spy list */
1507 local->wstats.qual.qual = local->spy_data.spy_stat[0].qual;
1508 local->wstats.qual.level = local->spy_data.spy_stat[0].level;
1509 local->wstats.qual.noise = local->spy_data.spy_stat[0].noise;
1510 local->wstats.qual.updated =
1511 local->spy_data.spy_stat[0].updated;
1512 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001513#endif /* WIRELESS_SPY */
1514
John Daiker141fa612009-03-10 06:59:54 -07001515 if (pcmcia_dev_present(link)) {
1516 local->wstats.qual.noise = readb(&p->rxnoise);
1517 local->wstats.qual.updated |= 4;
1518 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001519
John Daiker141fa612009-03-10 06:59:54 -07001520 return &local->wstats;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001521} /* end ray_get_wireless_stats */
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001522
1523/*------------------------------------------------------------------*/
1524/*
1525 * Structures to export the Wireless Handlers
1526 */
1527
John Daiker141fa612009-03-10 06:59:54 -07001528static const iw_handler ray_handler[] = {
1529 [SIOCSIWCOMMIT - SIOCIWFIRST] = (iw_handler) ray_commit,
1530 [SIOCGIWNAME - SIOCIWFIRST] = (iw_handler) ray_get_name,
1531 [SIOCSIWFREQ - SIOCIWFIRST] = (iw_handler) ray_set_freq,
1532 [SIOCGIWFREQ - SIOCIWFIRST] = (iw_handler) ray_get_freq,
1533 [SIOCSIWMODE - SIOCIWFIRST] = (iw_handler) ray_set_mode,
1534 [SIOCGIWMODE - SIOCIWFIRST] = (iw_handler) ray_get_mode,
1535 [SIOCGIWRANGE - SIOCIWFIRST] = (iw_handler) ray_get_range,
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001536#ifdef WIRELESS_SPY
John Daiker141fa612009-03-10 06:59:54 -07001537 [SIOCSIWSPY - SIOCIWFIRST] = (iw_handler) iw_handler_set_spy,
1538 [SIOCGIWSPY - SIOCIWFIRST] = (iw_handler) iw_handler_get_spy,
1539 [SIOCSIWTHRSPY - SIOCIWFIRST] = (iw_handler) iw_handler_set_thrspy,
1540 [SIOCGIWTHRSPY - SIOCIWFIRST] = (iw_handler) iw_handler_get_thrspy,
1541#endif /* WIRELESS_SPY */
1542 [SIOCGIWAP - SIOCIWFIRST] = (iw_handler) ray_get_wap,
1543 [SIOCSIWESSID - SIOCIWFIRST] = (iw_handler) ray_set_essid,
1544 [SIOCGIWESSID - SIOCIWFIRST] = (iw_handler) ray_get_essid,
1545 [SIOCSIWRATE - SIOCIWFIRST] = (iw_handler) ray_set_rate,
1546 [SIOCGIWRATE - SIOCIWFIRST] = (iw_handler) ray_get_rate,
1547 [SIOCSIWRTS - SIOCIWFIRST] = (iw_handler) ray_set_rts,
1548 [SIOCGIWRTS - SIOCIWFIRST] = (iw_handler) ray_get_rts,
1549 [SIOCSIWFRAG - SIOCIWFIRST] = (iw_handler) ray_set_frag,
1550 [SIOCGIWFRAG - SIOCIWFIRST] = (iw_handler) ray_get_frag,
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001551};
1552
John Daiker141fa612009-03-10 06:59:54 -07001553#define SIOCSIPFRAMING SIOCIWFIRSTPRIV /* Set framing mode */
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001554#define SIOCGIPFRAMING SIOCIWFIRSTPRIV + 1 /* Get framing mode */
1555#define SIOCGIPCOUNTRY SIOCIWFIRSTPRIV + 3 /* Get country code */
1556
John Daiker141fa612009-03-10 06:59:54 -07001557static const iw_handler ray_private_handler[] = {
viro@ZenIV.linux.org.uk7a700fa2005-09-09 20:40:23 +01001558 [0] = (iw_handler) ray_set_framing,
1559 [1] = (iw_handler) ray_get_framing,
1560 [3] = (iw_handler) ray_get_country,
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001561};
1562
John Daiker141fa612009-03-10 06:59:54 -07001563static const struct iw_priv_args ray_private_args[] = {
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001564/* cmd, set_args, get_args, name */
John Daiker141fa612009-03-10 06:59:54 -07001565 {SIOCSIPFRAMING, IW_PRIV_TYPE_BYTE | IW_PRIV_SIZE_FIXED | 1, 0,
1566 "set_framing"},
1567 {SIOCGIPFRAMING, 0, IW_PRIV_TYPE_BYTE | IW_PRIV_SIZE_FIXED | 1,
1568 "get_framing"},
1569 {SIOCGIPCOUNTRY, 0, IW_PRIV_TYPE_BYTE | IW_PRIV_SIZE_FIXED | 1,
1570 "get_country"},
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001571};
1572
John Daiker141fa612009-03-10 06:59:54 -07001573static const struct iw_handler_def ray_handler_def = {
1574 .num_standard = ARRAY_SIZE(ray_handler),
1575 .num_private = ARRAY_SIZE(ray_private_handler),
Denis Chengff8ac602007-09-02 18:30:18 +08001576 .num_private_args = ARRAY_SIZE(ray_private_args),
John Daiker141fa612009-03-10 06:59:54 -07001577 .standard = ray_handler,
1578 .private = ray_private_handler,
1579 .private_args = ray_private_args,
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001580 .get_wireless_stats = ray_get_wireless_stats,
1581};
1582
Linus Torvalds1da177e2005-04-16 15:20:36 -07001583/*===========================================================================*/
1584static int ray_open(struct net_device *dev)
1585{
John Daiker141fa612009-03-10 06:59:54 -07001586 ray_dev_t *local = netdev_priv(dev);
1587 struct pcmcia_device *link;
1588 link = local->finder;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001589
Dominik Brodowski624dd662009-10-24 15:52:44 +02001590 dev_dbg(&link->dev, "ray_open('%s')\n", dev->name);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001591
John Daiker141fa612009-03-10 06:59:54 -07001592 if (link->open == 0)
1593 local->num_multi = 0;
1594 link->open++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001595
John Daiker141fa612009-03-10 06:59:54 -07001596 /* If the card is not started, time to start it ! - Jean II */
1597 if (local->card_status == CARD_AWAITING_PARAM) {
1598 int i;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001599
Dominik Brodowski624dd662009-10-24 15:52:44 +02001600 dev_dbg(&link->dev, "ray_open: doing init now !\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001601
John Daiker141fa612009-03-10 06:59:54 -07001602 /* Download startup parameters */
1603 if ((i = dl_startup_params(dev)) < 0) {
1604 printk(KERN_INFO
1605 "ray_dev_init dl_startup_params failed - "
1606 "returns 0x%x\n", i);
1607 return -1;
1608 }
1609 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001610
John Daiker141fa612009-03-10 06:59:54 -07001611 if (sniffer)
1612 netif_stop_queue(dev);
1613 else
1614 netif_start_queue(dev);
1615
Dominik Brodowski624dd662009-10-24 15:52:44 +02001616 dev_dbg(&link->dev, "ray_open ending\n");
John Daiker141fa612009-03-10 06:59:54 -07001617 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001618} /* end ray_open */
John Daiker141fa612009-03-10 06:59:54 -07001619
Linus Torvalds1da177e2005-04-16 15:20:36 -07001620/*===========================================================================*/
1621static int ray_dev_close(struct net_device *dev)
1622{
John Daiker141fa612009-03-10 06:59:54 -07001623 ray_dev_t *local = netdev_priv(dev);
1624 struct pcmcia_device *link;
1625 link = local->finder;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001626
Dominik Brodowski624dd662009-10-24 15:52:44 +02001627 dev_dbg(&link->dev, "ray_dev_close('%s')\n", dev->name);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001628
John Daiker141fa612009-03-10 06:59:54 -07001629 link->open--;
1630 netif_stop_queue(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001631
John Daiker141fa612009-03-10 06:59:54 -07001632 /* In here, we should stop the hardware (stop card from beeing active)
1633 * and set local->card_status to CARD_AWAITING_PARAM, so that while the
1634 * card is closed we can chage its configuration.
1635 * Probably also need a COR reset to get sane state - Jean II */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001636
John Daiker141fa612009-03-10 06:59:54 -07001637 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001638} /* end ray_dev_close */
John Daiker141fa612009-03-10 06:59:54 -07001639
Linus Torvalds1da177e2005-04-16 15:20:36 -07001640/*===========================================================================*/
John Daiker141fa612009-03-10 06:59:54 -07001641static void ray_reset(struct net_device *dev)
1642{
Dominik Brodowski624dd662009-10-24 15:52:44 +02001643 pr_debug("ray_reset entered\n");
John Daiker141fa612009-03-10 06:59:54 -07001644 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001645}
John Daiker141fa612009-03-10 06:59:54 -07001646
Linus Torvalds1da177e2005-04-16 15:20:36 -07001647/*===========================================================================*/
1648/* Cause a firmware interrupt if it is ready for one */
1649/* Return nonzero if not ready */
1650static int interrupt_ecf(ray_dev_t *local, int ccs)
1651{
John Daiker141fa612009-03-10 06:59:54 -07001652 int i = 50;
1653 struct pcmcia_device *link = local->finder;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001654
John Daiker141fa612009-03-10 06:59:54 -07001655 if (!(pcmcia_dev_present(link))) {
Dominik Brodowski624dd662009-10-24 15:52:44 +02001656 dev_dbg(&link->dev, "ray_cs interrupt_ecf - device not present\n");
John Daiker141fa612009-03-10 06:59:54 -07001657 return -1;
1658 }
Dominik Brodowski624dd662009-10-24 15:52:44 +02001659 dev_dbg(&link->dev, "interrupt_ecf(local=%p, ccs = 0x%x\n", local, ccs);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001660
John Daiker141fa612009-03-10 06:59:54 -07001661 while (i &&
1662 (readb(local->amem + CIS_OFFSET + ECF_INTR_OFFSET) &
1663 ECF_INTR_SET))
1664 i--;
1665 if (i == 0) {
Dominik Brodowski624dd662009-10-24 15:52:44 +02001666 dev_dbg(&link->dev, "ray_cs interrupt_ecf card not ready for interrupt\n");
John Daiker141fa612009-03-10 06:59:54 -07001667 return -1;
1668 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001669 /* Fill the mailbox, then kick the card */
John Daiker141fa612009-03-10 06:59:54 -07001670 writeb(ccs, local->sram + SCB_BASE);
1671 writeb(ECF_INTR_SET, local->amem + CIS_OFFSET + ECF_INTR_OFFSET);
1672 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001673} /* interrupt_ecf */
John Daiker141fa612009-03-10 06:59:54 -07001674
Linus Torvalds1da177e2005-04-16 15:20:36 -07001675/*===========================================================================*/
1676/* Get next free transmit CCS */
1677/* Return - index of current tx ccs */
1678static int get_free_tx_ccs(ray_dev_t *local)
1679{
John Daiker141fa612009-03-10 06:59:54 -07001680 int i;
1681 struct ccs __iomem *pccs = ccs_base(local);
1682 struct pcmcia_device *link = local->finder;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001683
John Daiker141fa612009-03-10 06:59:54 -07001684 if (!(pcmcia_dev_present(link))) {
Dominik Brodowski624dd662009-10-24 15:52:44 +02001685 dev_dbg(&link->dev, "ray_cs get_free_tx_ccs - device not present\n");
John Daiker141fa612009-03-10 06:59:54 -07001686 return ECARDGONE;
1687 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001688
John Daiker141fa612009-03-10 06:59:54 -07001689 if (test_and_set_bit(0, &local->tx_ccs_lock)) {
Dominik Brodowski624dd662009-10-24 15:52:44 +02001690 dev_dbg(&link->dev, "ray_cs tx_ccs_lock busy\n");
John Daiker141fa612009-03-10 06:59:54 -07001691 return ECCSBUSY;
1692 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001693
John Daiker141fa612009-03-10 06:59:54 -07001694 for (i = 0; i < NUMBER_OF_TX_CCS; i++) {
1695 if (readb(&(pccs + i)->buffer_status) == CCS_BUFFER_FREE) {
1696 writeb(CCS_BUFFER_BUSY, &(pccs + i)->buffer_status);
1697 writeb(CCS_END_LIST, &(pccs + i)->link);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001698 local->tx_ccs_lock = 0;
John Daiker141fa612009-03-10 06:59:54 -07001699 return i;
1700 }
1701 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001702 local->tx_ccs_lock = 0;
Dominik Brodowski624dd662009-10-24 15:52:44 +02001703 dev_dbg(&link->dev, "ray_cs ERROR no free tx CCS for raylink card\n");
John Daiker141fa612009-03-10 06:59:54 -07001704 return ECCSFULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001705} /* get_free_tx_ccs */
John Daiker141fa612009-03-10 06:59:54 -07001706
Linus Torvalds1da177e2005-04-16 15:20:36 -07001707/*===========================================================================*/
1708/* Get next free CCS */
1709/* Return - index of current ccs */
1710static int get_free_ccs(ray_dev_t *local)
1711{
John Daiker141fa612009-03-10 06:59:54 -07001712 int i;
1713 struct ccs __iomem *pccs = ccs_base(local);
1714 struct pcmcia_device *link = local->finder;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001715
John Daiker141fa612009-03-10 06:59:54 -07001716 if (!(pcmcia_dev_present(link))) {
Dominik Brodowski624dd662009-10-24 15:52:44 +02001717 dev_dbg(&link->dev, "ray_cs get_free_ccs - device not present\n");
John Daiker141fa612009-03-10 06:59:54 -07001718 return ECARDGONE;
1719 }
1720 if (test_and_set_bit(0, &local->ccs_lock)) {
Dominik Brodowski624dd662009-10-24 15:52:44 +02001721 dev_dbg(&link->dev, "ray_cs ccs_lock busy\n");
John Daiker141fa612009-03-10 06:59:54 -07001722 return ECCSBUSY;
1723 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001724
John Daiker141fa612009-03-10 06:59:54 -07001725 for (i = NUMBER_OF_TX_CCS; i < NUMBER_OF_CCS; i++) {
1726 if (readb(&(pccs + i)->buffer_status) == CCS_BUFFER_FREE) {
1727 writeb(CCS_BUFFER_BUSY, &(pccs + i)->buffer_status);
1728 writeb(CCS_END_LIST, &(pccs + i)->link);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001729 local->ccs_lock = 0;
John Daiker141fa612009-03-10 06:59:54 -07001730 return i;
1731 }
1732 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001733 local->ccs_lock = 0;
Dominik Brodowski624dd662009-10-24 15:52:44 +02001734 dev_dbg(&link->dev, "ray_cs ERROR no free CCS for raylink card\n");
John Daiker141fa612009-03-10 06:59:54 -07001735 return ECCSFULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001736} /* get_free_ccs */
John Daiker141fa612009-03-10 06:59:54 -07001737
Linus Torvalds1da177e2005-04-16 15:20:36 -07001738/*===========================================================================*/
1739static void authenticate_timeout(u_long data)
1740{
John Daiker141fa612009-03-10 06:59:54 -07001741 ray_dev_t *local = (ray_dev_t *) data;
1742 del_timer(&local->timer);
1743 printk(KERN_INFO "ray_cs Authentication with access point failed"
1744 " - timeout\n");
1745 join_net((u_long) local);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001746}
John Daiker141fa612009-03-10 06:59:54 -07001747
Linus Torvalds1da177e2005-04-16 15:20:36 -07001748/*===========================================================================*/
1749static int asc_to_int(char a)
1750{
John Daiker141fa612009-03-10 06:59:54 -07001751 if (a < '0')
1752 return -1;
1753 if (a <= '9')
1754 return (a - '0');
1755 if (a < 'A')
1756 return -1;
1757 if (a <= 'F')
1758 return (10 + a - 'A');
1759 if (a < 'a')
1760 return -1;
1761 if (a <= 'f')
1762 return (10 + a - 'a');
1763 return -1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001764}
John Daiker141fa612009-03-10 06:59:54 -07001765
Linus Torvalds1da177e2005-04-16 15:20:36 -07001766/*===========================================================================*/
1767static int parse_addr(char *in_str, UCHAR *out)
1768{
John Daiker141fa612009-03-10 06:59:54 -07001769 int len;
1770 int i, j, k;
1771 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001772
John Daiker141fa612009-03-10 06:59:54 -07001773 if (in_str == NULL)
1774 return 0;
1775 if ((len = strlen(in_str)) < 2)
1776 return 0;
1777 memset(out, 0, ADDRLEN);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001778
John Daiker141fa612009-03-10 06:59:54 -07001779 status = 1;
1780 j = len - 1;
1781 if (j > 12)
1782 j = 12;
1783 i = 5;
1784
1785 while (j > 0) {
1786 if ((k = asc_to_int(in_str[j--])) != -1)
1787 out[i] = k;
1788 else
1789 return 0;
1790
1791 if (j == 0)
1792 break;
1793 if ((k = asc_to_int(in_str[j--])) != -1)
1794 out[i] += k << 4;
1795 else
1796 return 0;
1797 if (!i--)
1798 break;
1799 }
1800 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001801}
John Daiker141fa612009-03-10 06:59:54 -07001802
Linus Torvalds1da177e2005-04-16 15:20:36 -07001803/*===========================================================================*/
1804static struct net_device_stats *ray_get_stats(struct net_device *dev)
1805{
John Daiker141fa612009-03-10 06:59:54 -07001806 ray_dev_t *local = netdev_priv(dev);
1807 struct pcmcia_device *link = local->finder;
1808 struct status __iomem *p = local->sram + STATUS_BASE;
1809 if (!(pcmcia_dev_present(link))) {
Dominik Brodowski624dd662009-10-24 15:52:44 +02001810 dev_dbg(&link->dev, "ray_cs net_device_stats - device not present\n");
John Daiker141fa612009-03-10 06:59:54 -07001811 return &local->stats;
1812 }
1813 if (readb(&p->mrx_overflow_for_host)) {
1814 local->stats.rx_over_errors += swab16(readw(&p->mrx_overflow));
1815 writeb(0, &p->mrx_overflow);
1816 writeb(0, &p->mrx_overflow_for_host);
1817 }
1818 if (readb(&p->mrx_checksum_error_for_host)) {
1819 local->stats.rx_crc_errors +=
1820 swab16(readw(&p->mrx_checksum_error));
1821 writeb(0, &p->mrx_checksum_error);
1822 writeb(0, &p->mrx_checksum_error_for_host);
1823 }
1824 if (readb(&p->rx_hec_error_for_host)) {
1825 local->stats.rx_frame_errors += swab16(readw(&p->rx_hec_error));
1826 writeb(0, &p->rx_hec_error);
1827 writeb(0, &p->rx_hec_error_for_host);
1828 }
1829 return &local->stats;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001830}
John Daiker141fa612009-03-10 06:59:54 -07001831
Linus Torvalds1da177e2005-04-16 15:20:36 -07001832/*===========================================================================*/
John Daiker141fa612009-03-10 06:59:54 -07001833static void ray_update_parm(struct net_device *dev, UCHAR objid, UCHAR *value,
1834 int len)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001835{
John Daiker141fa612009-03-10 06:59:54 -07001836 ray_dev_t *local = netdev_priv(dev);
1837 struct pcmcia_device *link = local->finder;
1838 int ccsindex;
1839 int i;
1840 struct ccs __iomem *pccs;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001841
John Daiker141fa612009-03-10 06:59:54 -07001842 if (!(pcmcia_dev_present(link))) {
Dominik Brodowski624dd662009-10-24 15:52:44 +02001843 dev_dbg(&link->dev, "ray_update_parm - device not present\n");
John Daiker141fa612009-03-10 06:59:54 -07001844 return;
1845 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001846
John Daiker141fa612009-03-10 06:59:54 -07001847 if ((ccsindex = get_free_ccs(local)) < 0) {
Dominik Brodowski624dd662009-10-24 15:52:44 +02001848 dev_dbg(&link->dev, "ray_update_parm - No free ccs\n");
John Daiker141fa612009-03-10 06:59:54 -07001849 return;
1850 }
1851 pccs = ccs_base(local) + ccsindex;
1852 writeb(CCS_UPDATE_PARAMS, &pccs->cmd);
1853 writeb(objid, &pccs->var.update_param.object_id);
1854 writeb(1, &pccs->var.update_param.number_objects);
1855 writeb(0, &pccs->var.update_param.failure_cause);
1856 for (i = 0; i < len; i++) {
1857 writeb(value[i], local->sram + HOST_TO_ECF_BASE);
1858 }
1859 /* Interrupt the firmware to process the command */
1860 if (interrupt_ecf(local, ccsindex)) {
Dominik Brodowski624dd662009-10-24 15:52:44 +02001861 dev_dbg(&link->dev, "ray_cs associate failed - ECF not ready for intr\n");
John Daiker141fa612009-03-10 06:59:54 -07001862 writeb(CCS_BUFFER_FREE, &(pccs++)->buffer_status);
1863 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001864}
John Daiker141fa612009-03-10 06:59:54 -07001865
Linus Torvalds1da177e2005-04-16 15:20:36 -07001866/*===========================================================================*/
1867static void ray_update_multi_list(struct net_device *dev, int all)
1868{
John Daiker141fa612009-03-10 06:59:54 -07001869 int ccsindex;
1870 struct ccs __iomem *pccs;
John Daiker141fa612009-03-10 06:59:54 -07001871 ray_dev_t *local = netdev_priv(dev);
1872 struct pcmcia_device *link = local->finder;
1873 void __iomem *p = local->sram + HOST_TO_ECF_BASE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001874
John Daiker141fa612009-03-10 06:59:54 -07001875 if (!(pcmcia_dev_present(link))) {
Dominik Brodowski624dd662009-10-24 15:52:44 +02001876 dev_dbg(&link->dev, "ray_update_multi_list - device not present\n");
John Daiker141fa612009-03-10 06:59:54 -07001877 return;
1878 } else
Dominik Brodowski624dd662009-10-24 15:52:44 +02001879 dev_dbg(&link->dev, "ray_update_multi_list(%p)\n", dev);
John Daiker141fa612009-03-10 06:59:54 -07001880 if ((ccsindex = get_free_ccs(local)) < 0) {
Dominik Brodowski624dd662009-10-24 15:52:44 +02001881 dev_dbg(&link->dev, "ray_update_multi - No free ccs\n");
John Daiker141fa612009-03-10 06:59:54 -07001882 return;
1883 }
1884 pccs = ccs_base(local) + ccsindex;
1885 writeb(CCS_UPDATE_MULTICAST_LIST, &pccs->cmd);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001886
John Daiker141fa612009-03-10 06:59:54 -07001887 if (all) {
1888 writeb(0xff, &pccs->var);
1889 local->num_multi = 0xff;
1890 } else {
Jiri Pirko655ffee2010-02-27 07:35:45 +00001891 struct dev_mc_list *dmi;
1892 int i = 0;
1893
John Daiker141fa612009-03-10 06:59:54 -07001894 /* Copy the kernel's list of MC addresses to card */
Jiri Pirko655ffee2010-02-27 07:35:45 +00001895 netdev_for_each_mc_addr(dmi, dev) {
John Daiker141fa612009-03-10 06:59:54 -07001896 memcpy_toio(p, dmi->dmi_addr, ETH_ALEN);
Dominik Brodowski624dd662009-10-24 15:52:44 +02001897 dev_dbg(&link->dev,
John Daiker141fa612009-03-10 06:59:54 -07001898 "ray_update_multi add addr %02x%02x%02x%02x%02x%02x\n",
1899 dmi->dmi_addr[0], dmi->dmi_addr[1],
1900 dmi->dmi_addr[2], dmi->dmi_addr[3],
1901 dmi->dmi_addr[4], dmi->dmi_addr[5]);
1902 p += ETH_ALEN;
1903 i++;
1904 }
1905 if (i > 256 / ADDRLEN)
1906 i = 256 / ADDRLEN;
1907 writeb((UCHAR) i, &pccs->var);
Dominik Brodowski624dd662009-10-24 15:52:44 +02001908 dev_dbg(&link->dev, "ray_cs update_multi %d addresses in list\n", i);
John Daiker141fa612009-03-10 06:59:54 -07001909 /* Interrupt the firmware to process the command */
1910 local->num_multi = i;
1911 }
1912 if (interrupt_ecf(local, ccsindex)) {
Dominik Brodowski624dd662009-10-24 15:52:44 +02001913 dev_dbg(&link->dev,
John Daiker141fa612009-03-10 06:59:54 -07001914 "ray_cs update_multi failed - ECF not ready for intr\n");
1915 writeb(CCS_BUFFER_FREE, &(pccs++)->buffer_status);
1916 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001917} /* end ray_update_multi_list */
John Daiker141fa612009-03-10 06:59:54 -07001918
Linus Torvalds1da177e2005-04-16 15:20:36 -07001919/*===========================================================================*/
1920static void set_multicast_list(struct net_device *dev)
1921{
John Daiker141fa612009-03-10 06:59:54 -07001922 ray_dev_t *local = netdev_priv(dev);
1923 UCHAR promisc;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001924
Dominik Brodowski624dd662009-10-24 15:52:44 +02001925 pr_debug("ray_cs set_multicast_list(%p)\n", dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001926
John Daiker141fa612009-03-10 06:59:54 -07001927 if (dev->flags & IFF_PROMISC) {
1928 if (local->sparm.b5.a_promiscuous_mode == 0) {
Dominik Brodowski624dd662009-10-24 15:52:44 +02001929 pr_debug("ray_cs set_multicast_list promisc on\n");
John Daiker141fa612009-03-10 06:59:54 -07001930 local->sparm.b5.a_promiscuous_mode = 1;
1931 promisc = 1;
1932 ray_update_parm(dev, OBJID_promiscuous_mode,
1933 &promisc, sizeof(promisc));
1934 }
1935 } else {
1936 if (local->sparm.b5.a_promiscuous_mode == 1) {
Dominik Brodowski624dd662009-10-24 15:52:44 +02001937 pr_debug("ray_cs set_multicast_list promisc off\n");
John Daiker141fa612009-03-10 06:59:54 -07001938 local->sparm.b5.a_promiscuous_mode = 0;
1939 promisc = 0;
1940 ray_update_parm(dev, OBJID_promiscuous_mode,
1941 &promisc, sizeof(promisc));
1942 }
1943 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001944
John Daiker141fa612009-03-10 06:59:54 -07001945 if (dev->flags & IFF_ALLMULTI)
1946 ray_update_multi_list(dev, 1);
1947 else {
Jiri Pirko4cd24ea2010-02-08 04:30:35 +00001948 if (local->num_multi != netdev_mc_count(dev))
John Daiker141fa612009-03-10 06:59:54 -07001949 ray_update_multi_list(dev, 0);
1950 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001951} /* end set_multicast_list */
John Daiker141fa612009-03-10 06:59:54 -07001952
Linus Torvalds1da177e2005-04-16 15:20:36 -07001953/*=============================================================================
1954 * All routines below here are run at interrupt time.
1955=============================================================================*/
David Howells7d12e782006-10-05 14:55:46 +01001956static irqreturn_t ray_interrupt(int irq, void *dev_id)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001957{
John Daiker141fa612009-03-10 06:59:54 -07001958 struct net_device *dev = (struct net_device *)dev_id;
1959 struct pcmcia_device *link;
1960 ray_dev_t *local;
1961 struct ccs __iomem *pccs;
1962 struct rcs __iomem *prcs;
1963 UCHAR rcsindex;
1964 UCHAR tmp;
1965 UCHAR cmd;
1966 UCHAR status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001967
John Daiker141fa612009-03-10 06:59:54 -07001968 if (dev == NULL) /* Note that we want interrupts with dev->start == 0 */
1969 return IRQ_NONE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001970
Dominik Brodowski624dd662009-10-24 15:52:44 +02001971 pr_debug("ray_cs: interrupt for *dev=%p\n", dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001972
John Daiker141fa612009-03-10 06:59:54 -07001973 local = netdev_priv(dev);
1974 link = (struct pcmcia_device *)local->finder;
1975 if (!pcmcia_dev_present(link)) {
Dominik Brodowski624dd662009-10-24 15:52:44 +02001976 pr_debug(
1977 "ray_cs interrupt from device not present or suspended.\n");
John Daiker141fa612009-03-10 06:59:54 -07001978 return IRQ_NONE;
1979 }
1980 rcsindex = readb(&((struct scb __iomem *)(local->sram))->rcs_index);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001981
John Daiker141fa612009-03-10 06:59:54 -07001982 if (rcsindex >= (NUMBER_OF_CCS + NUMBER_OF_RCS)) {
Dominik Brodowski624dd662009-10-24 15:52:44 +02001983 dev_dbg(&link->dev, "ray_cs interrupt bad rcsindex = 0x%x\n", rcsindex);
John Daiker141fa612009-03-10 06:59:54 -07001984 clear_interrupt(local);
1985 return IRQ_HANDLED;
1986 }
1987 if (rcsindex < NUMBER_OF_CCS) { /* If it's a returned CCS */
1988 pccs = ccs_base(local) + rcsindex;
1989 cmd = readb(&pccs->cmd);
1990 status = readb(&pccs->buffer_status);
1991 switch (cmd) {
1992 case CCS_DOWNLOAD_STARTUP_PARAMS: /* Happens in firmware someday */
1993 del_timer(&local->timer);
1994 if (status == CCS_COMMAND_COMPLETE) {
Dominik Brodowski624dd662009-10-24 15:52:44 +02001995 dev_dbg(&link->dev,
John Daiker141fa612009-03-10 06:59:54 -07001996 "ray_cs interrupt download_startup_parameters OK\n");
1997 } else {
Dominik Brodowski624dd662009-10-24 15:52:44 +02001998 dev_dbg(&link->dev,
John Daiker141fa612009-03-10 06:59:54 -07001999 "ray_cs interrupt download_startup_parameters fail\n");
2000 }
2001 break;
2002 case CCS_UPDATE_PARAMS:
Dominik Brodowski624dd662009-10-24 15:52:44 +02002003 dev_dbg(&link->dev, "ray_cs interrupt update params done\n");
John Daiker141fa612009-03-10 06:59:54 -07002004 if (status != CCS_COMMAND_COMPLETE) {
2005 tmp =
2006 readb(&pccs->var.update_param.
2007 failure_cause);
Dominik Brodowski624dd662009-10-24 15:52:44 +02002008 dev_dbg(&link->dev,
John Daiker141fa612009-03-10 06:59:54 -07002009 "ray_cs interrupt update params failed - reason %d\n",
2010 tmp);
2011 }
2012 break;
2013 case CCS_REPORT_PARAMS:
Dominik Brodowski624dd662009-10-24 15:52:44 +02002014 dev_dbg(&link->dev, "ray_cs interrupt report params done\n");
John Daiker141fa612009-03-10 06:59:54 -07002015 break;
2016 case CCS_UPDATE_MULTICAST_LIST: /* Note that this CCS isn't returned */
Dominik Brodowski624dd662009-10-24 15:52:44 +02002017 dev_dbg(&link->dev,
John Daiker141fa612009-03-10 06:59:54 -07002018 "ray_cs interrupt CCS Update Multicast List done\n");
2019 break;
2020 case CCS_UPDATE_POWER_SAVINGS_MODE:
Dominik Brodowski624dd662009-10-24 15:52:44 +02002021 dev_dbg(&link->dev,
John Daiker141fa612009-03-10 06:59:54 -07002022 "ray_cs interrupt update power save mode done\n");
2023 break;
2024 case CCS_START_NETWORK:
2025 case CCS_JOIN_NETWORK:
2026 if (status == CCS_COMMAND_COMPLETE) {
2027 if (readb
2028 (&pccs->var.start_network.net_initiated) ==
2029 1) {
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\" started\n",
2032 local->sparm.b4.a_current_ess_id);
2033 } else {
Dominik Brodowski624dd662009-10-24 15:52:44 +02002034 dev_dbg(&link->dev,
John Daiker141fa612009-03-10 06:59:54 -07002035 "ray_cs interrupt network \"%s\" joined\n",
2036 local->sparm.b4.a_current_ess_id);
2037 }
2038 memcpy_fromio(&local->bss_id,
2039 pccs->var.start_network.bssid,
2040 ADDRLEN);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002041
John Daiker141fa612009-03-10 06:59:54 -07002042 if (local->fw_ver == 0x55)
2043 local->net_default_tx_rate = 3;
2044 else
2045 local->net_default_tx_rate =
2046 readb(&pccs->var.start_network.
2047 net_default_tx_rate);
2048 local->encryption =
2049 readb(&pccs->var.start_network.encryption);
2050 if (!sniffer && (local->net_type == INFRA)
2051 && !(local->sparm.b4.a_acting_as_ap_status)) {
2052 authenticate(local);
2053 }
2054 local->card_status = CARD_ACQ_COMPLETE;
2055 } else {
2056 local->card_status = CARD_ACQ_FAILED;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002057
John Daiker141fa612009-03-10 06:59:54 -07002058 del_timer(&local->timer);
2059 local->timer.expires = jiffies + HZ * 5;
2060 local->timer.data = (long)local;
2061 if (status == CCS_START_NETWORK) {
Dominik Brodowski624dd662009-10-24 15:52:44 +02002062 dev_dbg(&link->dev,
John Daiker141fa612009-03-10 06:59:54 -07002063 "ray_cs interrupt network \"%s\" start failed\n",
2064 local->sparm.b4.a_current_ess_id);
2065 local->timer.function = &start_net;
2066 } else {
Dominik Brodowski624dd662009-10-24 15:52:44 +02002067 dev_dbg(&link->dev,
John Daiker141fa612009-03-10 06:59:54 -07002068 "ray_cs interrupt network \"%s\" join failed\n",
2069 local->sparm.b4.a_current_ess_id);
2070 local->timer.function = &join_net;
2071 }
2072 add_timer(&local->timer);
2073 }
2074 break;
2075 case CCS_START_ASSOCIATION:
2076 if (status == CCS_COMMAND_COMPLETE) {
2077 local->card_status = CARD_ASSOC_COMPLETE;
Dominik Brodowski624dd662009-10-24 15:52:44 +02002078 dev_dbg(&link->dev, "ray_cs association successful\n");
John Daiker141fa612009-03-10 06:59:54 -07002079 } else {
Dominik Brodowski624dd662009-10-24 15:52:44 +02002080 dev_dbg(&link->dev, "ray_cs association failed,\n");
John Daiker141fa612009-03-10 06:59:54 -07002081 local->card_status = CARD_ASSOC_FAILED;
2082 join_net((u_long) local);
2083 }
2084 break;
2085 case CCS_TX_REQUEST:
2086 if (status == CCS_COMMAND_COMPLETE) {
Dominik Brodowski624dd662009-10-24 15:52:44 +02002087 dev_dbg(&link->dev,
John Daiker141fa612009-03-10 06:59:54 -07002088 "ray_cs interrupt tx request complete\n");
2089 } else {
Dominik Brodowski624dd662009-10-24 15:52:44 +02002090 dev_dbg(&link->dev,
John Daiker141fa612009-03-10 06:59:54 -07002091 "ray_cs interrupt tx request failed\n");
2092 }
2093 if (!sniffer)
2094 netif_start_queue(dev);
2095 netif_wake_queue(dev);
2096 break;
2097 case CCS_TEST_MEMORY:
Dominik Brodowski624dd662009-10-24 15:52:44 +02002098 dev_dbg(&link->dev, "ray_cs interrupt mem test done\n");
John Daiker141fa612009-03-10 06:59:54 -07002099 break;
2100 case CCS_SHUTDOWN:
Dominik Brodowski624dd662009-10-24 15:52:44 +02002101 dev_dbg(&link->dev,
John Daiker141fa612009-03-10 06:59:54 -07002102 "ray_cs interrupt Unexpected CCS returned - Shutdown\n");
2103 break;
2104 case CCS_DUMP_MEMORY:
Dominik Brodowski624dd662009-10-24 15:52:44 +02002105 dev_dbg(&link->dev, "ray_cs interrupt dump memory done\n");
John Daiker141fa612009-03-10 06:59:54 -07002106 break;
2107 case CCS_START_TIMER:
Dominik Brodowski624dd662009-10-24 15:52:44 +02002108 dev_dbg(&link->dev,
John Daiker141fa612009-03-10 06:59:54 -07002109 "ray_cs interrupt DING - raylink timer expired\n");
2110 break;
2111 default:
Dominik Brodowski624dd662009-10-24 15:52:44 +02002112 dev_dbg(&link->dev,
John Daiker141fa612009-03-10 06:59:54 -07002113 "ray_cs interrupt Unexpected CCS 0x%x returned 0x%x\n",
2114 rcsindex, cmd);
2115 }
2116 writeb(CCS_BUFFER_FREE, &pccs->buffer_status);
2117 } else { /* It's an RCS */
2118
2119 prcs = rcs_base(local) + rcsindex;
2120
2121 switch (readb(&prcs->interrupt_id)) {
2122 case PROCESS_RX_PACKET:
2123 ray_rx(dev, local, prcs);
2124 break;
2125 case REJOIN_NET_COMPLETE:
Dominik Brodowski624dd662009-10-24 15:52:44 +02002126 dev_dbg(&link->dev, "ray_cs interrupt rejoin net complete\n");
John Daiker141fa612009-03-10 06:59:54 -07002127 local->card_status = CARD_ACQ_COMPLETE;
2128 /* do we need to clear tx buffers CCS's? */
2129 if (local->sparm.b4.a_network_type == ADHOC) {
2130 if (!sniffer)
2131 netif_start_queue(dev);
2132 } else {
2133 memcpy_fromio(&local->bss_id,
2134 prcs->var.rejoin_net_complete.
2135 bssid, ADDRLEN);
Dominik Brodowski624dd662009-10-24 15:52:44 +02002136 dev_dbg(&link->dev,
John Daiker141fa612009-03-10 06:59:54 -07002137 "ray_cs new BSSID = %02x%02x%02x%02x%02x%02x\n",
2138 local->bss_id[0], local->bss_id[1],
2139 local->bss_id[2], local->bss_id[3],
2140 local->bss_id[4], local->bss_id[5]);
2141 if (!sniffer)
2142 authenticate(local);
2143 }
2144 break;
2145 case ROAMING_INITIATED:
Dominik Brodowski624dd662009-10-24 15:52:44 +02002146 dev_dbg(&link->dev, "ray_cs interrupt roaming initiated\n");
John Daiker141fa612009-03-10 06:59:54 -07002147 netif_stop_queue(dev);
2148 local->card_status = CARD_DOING_ACQ;
2149 break;
2150 case JAPAN_CALL_SIGN_RXD:
Dominik Brodowski624dd662009-10-24 15:52:44 +02002151 dev_dbg(&link->dev, "ray_cs interrupt japan call sign rx\n");
John Daiker141fa612009-03-10 06:59:54 -07002152 break;
2153 default:
Dominik Brodowski624dd662009-10-24 15:52:44 +02002154 dev_dbg(&link->dev,
John Daiker141fa612009-03-10 06:59:54 -07002155 "ray_cs Unexpected interrupt for RCS 0x%x cmd = 0x%x\n",
2156 rcsindex,
2157 (unsigned int)readb(&prcs->interrupt_id));
2158 break;
2159 }
2160 writeb(CCS_BUFFER_FREE, &prcs->buffer_status);
2161 }
2162 clear_interrupt(local);
2163 return IRQ_HANDLED;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002164} /* ray_interrupt */
John Daiker141fa612009-03-10 06:59:54 -07002165
Linus Torvalds1da177e2005-04-16 15:20:36 -07002166/*===========================================================================*/
John Daiker141fa612009-03-10 06:59:54 -07002167static void ray_rx(struct net_device *dev, ray_dev_t *local,
2168 struct rcs __iomem *prcs)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002169{
John Daiker141fa612009-03-10 06:59:54 -07002170 int rx_len;
2171 unsigned int pkt_addr;
2172 void __iomem *pmsg;
Dominik Brodowski624dd662009-10-24 15:52:44 +02002173 pr_debug("ray_rx process rx packet\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002174
John Daiker141fa612009-03-10 06:59:54 -07002175 /* Calculate address of packet within Rx buffer */
2176 pkt_addr = ((readb(&prcs->var.rx_packet.rx_data_ptr[0]) << 8)
2177 + readb(&prcs->var.rx_packet.rx_data_ptr[1])) & RX_BUFF_END;
2178 /* Length of first packet fragment */
2179 rx_len = (readb(&prcs->var.rx_packet.rx_data_length[0]) << 8)
2180 + readb(&prcs->var.rx_packet.rx_data_length[1]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002181
John Daiker141fa612009-03-10 06:59:54 -07002182 local->last_rsl = readb(&prcs->var.rx_packet.rx_sig_lev);
2183 pmsg = local->rmem + pkt_addr;
2184 switch (readb(pmsg)) {
2185 case DATA_TYPE:
Dominik Brodowski624dd662009-10-24 15:52:44 +02002186 pr_debug("ray_rx data type\n");
John Daiker141fa612009-03-10 06:59:54 -07002187 rx_data(dev, prcs, pkt_addr, rx_len);
2188 break;
2189 case AUTHENTIC_TYPE:
Dominik Brodowski624dd662009-10-24 15:52:44 +02002190 pr_debug("ray_rx authentic type\n");
John Daiker141fa612009-03-10 06:59:54 -07002191 if (sniffer)
2192 rx_data(dev, prcs, pkt_addr, rx_len);
2193 else
2194 rx_authenticate(local, prcs, pkt_addr, rx_len);
2195 break;
2196 case DEAUTHENTIC_TYPE:
Dominik Brodowski624dd662009-10-24 15:52:44 +02002197 pr_debug("ray_rx deauth type\n");
John Daiker141fa612009-03-10 06:59:54 -07002198 if (sniffer)
2199 rx_data(dev, prcs, pkt_addr, rx_len);
2200 else
2201 rx_deauthenticate(local, prcs, pkt_addr, rx_len);
2202 break;
2203 case NULL_MSG_TYPE:
Dominik Brodowski624dd662009-10-24 15:52:44 +02002204 pr_debug("ray_cs rx NULL msg\n");
John Daiker141fa612009-03-10 06:59:54 -07002205 break;
2206 case BEACON_TYPE:
Dominik Brodowski624dd662009-10-24 15:52:44 +02002207 pr_debug("ray_rx beacon type\n");
John Daiker141fa612009-03-10 06:59:54 -07002208 if (sniffer)
2209 rx_data(dev, prcs, pkt_addr, rx_len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002210
John Daiker141fa612009-03-10 06:59:54 -07002211 copy_from_rx_buff(local, (UCHAR *) &local->last_bcn, pkt_addr,
2212 rx_len < sizeof(struct beacon_rx) ?
2213 rx_len : sizeof(struct beacon_rx));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002214
John Daiker141fa612009-03-10 06:59:54 -07002215 local->beacon_rxed = 1;
2216 /* Get the statistics so the card counters never overflow */
2217 ray_get_stats(dev);
2218 break;
2219 default:
Dominik Brodowski624dd662009-10-24 15:52:44 +02002220 pr_debug("ray_cs unknown pkt type %2x\n",
John Daiker141fa612009-03-10 06:59:54 -07002221 (unsigned int)readb(pmsg));
2222 break;
2223 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002224
2225} /* end ray_rx */
John Daiker141fa612009-03-10 06:59:54 -07002226
Linus Torvalds1da177e2005-04-16 15:20:36 -07002227/*===========================================================================*/
John Daiker141fa612009-03-10 06:59:54 -07002228static void rx_data(struct net_device *dev, struct rcs __iomem *prcs,
2229 unsigned int pkt_addr, int rx_len)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002230{
John Daiker141fa612009-03-10 06:59:54 -07002231 struct sk_buff *skb = NULL;
2232 struct rcs __iomem *prcslink = prcs;
2233 ray_dev_t *local = netdev_priv(dev);
2234 UCHAR *rx_ptr;
2235 int total_len;
2236 int tmp;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002237#ifdef WIRELESS_SPY
John Daiker141fa612009-03-10 06:59:54 -07002238 int siglev = local->last_rsl;
2239 u_char linksrcaddr[ETH_ALEN]; /* Other end of the wireless link */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002240#endif
2241
John Daiker141fa612009-03-10 06:59:54 -07002242 if (!sniffer) {
2243 if (translate) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002244/* TBD length needs fixing for translated header */
John Daiker141fa612009-03-10 06:59:54 -07002245 if (rx_len < (ETH_HLEN + RX_MAC_HEADER_LENGTH) ||
2246 rx_len >
2247 (dev->mtu + RX_MAC_HEADER_LENGTH + ETH_HLEN +
2248 FCS_LEN)) {
Dominik Brodowski624dd662009-10-24 15:52:44 +02002249 pr_debug(
John Daiker141fa612009-03-10 06:59:54 -07002250 "ray_cs invalid packet length %d received \n",
2251 rx_len);
2252 return;
2253 }
2254 } else { /* encapsulated ethernet */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002255
John Daiker141fa612009-03-10 06:59:54 -07002256 if (rx_len < (ETH_HLEN + RX_MAC_HEADER_LENGTH) ||
2257 rx_len >
2258 (dev->mtu + RX_MAC_HEADER_LENGTH + ETH_HLEN +
2259 FCS_LEN)) {
Dominik Brodowski624dd662009-10-24 15:52:44 +02002260 pr_debug(
John Daiker141fa612009-03-10 06:59:54 -07002261 "ray_cs invalid packet length %d received \n",
2262 rx_len);
2263 return;
2264 }
2265 }
2266 }
Dominik Brodowski624dd662009-10-24 15:52:44 +02002267 pr_debug("ray_cs rx_data packet\n");
John Daiker141fa612009-03-10 06:59:54 -07002268 /* If fragmented packet, verify sizes of fragments add up */
2269 if (readb(&prcs->var.rx_packet.next_frag_rcs_index) != 0xFF) {
Dominik Brodowski624dd662009-10-24 15:52:44 +02002270 pr_debug("ray_cs rx'ed fragment\n");
John Daiker141fa612009-03-10 06:59:54 -07002271 tmp = (readb(&prcs->var.rx_packet.totalpacketlength[0]) << 8)
2272 + readb(&prcs->var.rx_packet.totalpacketlength[1]);
2273 total_len = tmp;
2274 prcslink = prcs;
2275 do {
2276 tmp -=
2277 (readb(&prcslink->var.rx_packet.rx_data_length[0])
2278 << 8)
2279 + readb(&prcslink->var.rx_packet.rx_data_length[1]);
2280 if (readb(&prcslink->var.rx_packet.next_frag_rcs_index)
2281 == 0xFF || tmp < 0)
2282 break;
2283 prcslink = rcs_base(local)
2284 + readb(&prcslink->link_field);
2285 } while (1);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002286
John Daiker141fa612009-03-10 06:59:54 -07002287 if (tmp < 0) {
Dominik Brodowski624dd662009-10-24 15:52:44 +02002288 pr_debug(
John Daiker141fa612009-03-10 06:59:54 -07002289 "ray_cs rx_data fragment lengths don't add up\n");
2290 local->stats.rx_dropped++;
2291 release_frag_chain(local, prcs);
2292 return;
2293 }
2294 } else { /* Single unfragmented packet */
2295 total_len = rx_len;
2296 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002297
John Daiker141fa612009-03-10 06:59:54 -07002298 skb = dev_alloc_skb(total_len + 5);
2299 if (skb == NULL) {
Dominik Brodowski624dd662009-10-24 15:52:44 +02002300 pr_debug("ray_cs rx_data could not allocate skb\n");
John Daiker141fa612009-03-10 06:59:54 -07002301 local->stats.rx_dropped++;
2302 if (readb(&prcs->var.rx_packet.next_frag_rcs_index) != 0xFF)
2303 release_frag_chain(local, prcs);
2304 return;
2305 }
2306 skb_reserve(skb, 2); /* Align IP on 16 byte (TBD check this) */
2307
Dominik Brodowski624dd662009-10-24 15:52:44 +02002308 pr_debug("ray_cs rx_data total_len = %x, rx_len = %x\n", total_len,
John Daiker141fa612009-03-10 06:59:54 -07002309 rx_len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002310
2311/************************/
John Daiker141fa612009-03-10 06:59:54 -07002312 /* Reserve enough room for the whole damn packet. */
2313 rx_ptr = skb_put(skb, total_len);
2314 /* Copy the whole packet to sk_buff */
2315 rx_ptr +=
2316 copy_from_rx_buff(local, rx_ptr, pkt_addr & RX_BUFF_END, rx_len);
2317 /* Get source address */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002318#ifdef WIRELESS_SPY
John Daiker141fa612009-03-10 06:59:54 -07002319 skb_copy_from_linear_data_offset(skb,
2320 offsetof(struct mac_header, addr_2),
2321 linksrcaddr, ETH_ALEN);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002322#endif
John Daiker141fa612009-03-10 06:59:54 -07002323 /* Now, deal with encapsulation/translation/sniffer */
2324 if (!sniffer) {
2325 if (!translate) {
2326 /* Encapsulated ethernet, so just lop off 802.11 MAC header */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002327/* TBD reserve skb_reserve( skb, RX_MAC_HEADER_LENGTH); */
John Daiker141fa612009-03-10 06:59:54 -07002328 skb_pull(skb, RX_MAC_HEADER_LENGTH);
2329 } else {
2330 /* Do translation */
2331 untranslate(local, skb, total_len);
2332 }
2333 } else { /* sniffer mode, so just pass whole packet */
2334 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002335
2336/************************/
John Daiker141fa612009-03-10 06:59:54 -07002337 /* Now pick up the rest of the fragments if any */
2338 tmp = 17;
2339 if (readb(&prcs->var.rx_packet.next_frag_rcs_index) != 0xFF) {
2340 prcslink = prcs;
Dominik Brodowski624dd662009-10-24 15:52:44 +02002341 pr_debug("ray_cs rx_data in fragment loop\n");
John Daiker141fa612009-03-10 06:59:54 -07002342 do {
2343 prcslink = rcs_base(local)
2344 +
2345 readb(&prcslink->var.rx_packet.next_frag_rcs_index);
2346 rx_len =
2347 ((readb(&prcslink->var.rx_packet.rx_data_length[0])
2348 << 8)
2349 +
2350 readb(&prcslink->var.rx_packet.rx_data_length[1]))
2351 & RX_BUFF_END;
2352 pkt_addr =
2353 ((readb(&prcslink->var.rx_packet.rx_data_ptr[0]) <<
2354 8)
2355 + readb(&prcslink->var.rx_packet.rx_data_ptr[1]))
2356 & RX_BUFF_END;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002357
John Daiker141fa612009-03-10 06:59:54 -07002358 rx_ptr +=
2359 copy_from_rx_buff(local, rx_ptr, pkt_addr, rx_len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002360
John Daiker141fa612009-03-10 06:59:54 -07002361 } while (tmp-- &&
2362 readb(&prcslink->var.rx_packet.next_frag_rcs_index) !=
2363 0xFF);
2364 release_frag_chain(local, prcs);
2365 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002366
John Daiker141fa612009-03-10 06:59:54 -07002367 skb->protocol = eth_type_trans(skb, dev);
2368 netif_rx(skb);
2369 local->stats.rx_packets++;
2370 local->stats.rx_bytes += total_len;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002371
John Daiker141fa612009-03-10 06:59:54 -07002372 /* Gather signal strength per address */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002373#ifdef WIRELESS_SPY
John Daiker141fa612009-03-10 06:59:54 -07002374 /* For the Access Point or the node having started the ad-hoc net
2375 * note : ad-hoc work only in some specific configurations, but we
2376 * kludge in ray_get_wireless_stats... */
2377 if (!memcmp(linksrcaddr, local->bss_id, ETH_ALEN)) {
2378 /* Update statistics */
2379 /*local->wstats.qual.qual = none ? */
2380 local->wstats.qual.level = siglev;
2381 /*local->wstats.qual.noise = none ? */
2382 local->wstats.qual.updated = 0x2;
2383 }
2384 /* Now, update the spy stuff */
2385 {
2386 struct iw_quality wstats;
2387 wstats.level = siglev;
2388 /* wstats.noise = none ? */
2389 /* wstats.qual = none ? */
2390 wstats.updated = 0x2;
2391 /* Update spy records */
2392 wireless_spy_update(dev, linksrcaddr, &wstats);
2393 }
2394#endif /* WIRELESS_SPY */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002395} /* end rx_data */
John Daiker141fa612009-03-10 06:59:54 -07002396
Linus Torvalds1da177e2005-04-16 15:20:36 -07002397/*===========================================================================*/
2398static void untranslate(ray_dev_t *local, struct sk_buff *skb, int len)
2399{
John Daiker141fa612009-03-10 06:59:54 -07002400 snaphdr_t *psnap = (snaphdr_t *) (skb->data + RX_MAC_HEADER_LENGTH);
2401 struct ieee80211_hdr *pmac = (struct ieee80211_hdr *)skb->data;
2402 __be16 type = *(__be16 *) psnap->ethertype;
2403 int delta;
2404 struct ethhdr *peth;
2405 UCHAR srcaddr[ADDRLEN];
2406 UCHAR destaddr[ADDRLEN];
2407 static UCHAR org_bridge[3] = { 0, 0, 0xf8 };
2408 static UCHAR org_1042[3] = { 0, 0, 0 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002409
John Daiker141fa612009-03-10 06:59:54 -07002410 memcpy(destaddr, ieee80211_get_DA(pmac), ADDRLEN);
2411 memcpy(srcaddr, ieee80211_get_SA(pmac), ADDRLEN);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002412
Dominik Brodowski624dd662009-10-24 15:52:44 +02002413#if 0
2414 if {
Joe Perchesad361c92009-07-06 13:05:40 -07002415 print_hex_dump(KERN_DEBUG, "skb->data before untranslate: ",
2416 DUMP_PREFIX_NONE, 16, 1,
2417 skb->data, 64, true);
2418 printk(KERN_DEBUG
John Daiker141fa612009-03-10 06:59:54 -07002419 "type = %08x, xsap = %02x%02x%02x, org = %02x02x02x\n",
2420 ntohs(type), psnap->dsap, psnap->ssap, psnap->ctrl,
2421 psnap->org[0], psnap->org[1], psnap->org[2]);
2422 printk(KERN_DEBUG "untranslate skb->data = %p\n", skb->data);
2423 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002424#endif
2425
John Daiker141fa612009-03-10 06:59:54 -07002426 if (psnap->dsap != 0xaa || psnap->ssap != 0xaa || psnap->ctrl != 3) {
2427 /* not a snap type so leave it alone */
Dominik Brodowski624dd662009-10-24 15:52:44 +02002428 pr_debug("ray_cs untranslate NOT SNAP %02x %02x %02x\n",
John Daiker141fa612009-03-10 06:59:54 -07002429 psnap->dsap, psnap->ssap, psnap->ctrl);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002430
John Daiker141fa612009-03-10 06:59:54 -07002431 delta = RX_MAC_HEADER_LENGTH - ETH_HLEN;
2432 peth = (struct ethhdr *)(skb->data + delta);
2433 peth->h_proto = htons(len - RX_MAC_HEADER_LENGTH);
2434 } else { /* Its a SNAP */
2435 if (memcmp(psnap->org, org_bridge, 3) == 0) {
2436 /* EtherII and nuke the LLC */
Dominik Brodowski624dd662009-10-24 15:52:44 +02002437 pr_debug("ray_cs untranslate Bridge encap\n");
John Daiker141fa612009-03-10 06:59:54 -07002438 delta = RX_MAC_HEADER_LENGTH
2439 + sizeof(struct snaphdr_t) - ETH_HLEN;
2440 peth = (struct ethhdr *)(skb->data + delta);
2441 peth->h_proto = type;
2442 } else if (memcmp(psnap->org, org_1042, 3) == 0) {
2443 switch (ntohs(type)) {
2444 case ETH_P_IPX:
2445 case ETH_P_AARP:
Dominik Brodowski624dd662009-10-24 15:52:44 +02002446 pr_debug("ray_cs untranslate RFC IPX/AARP\n");
John Daiker141fa612009-03-10 06:59:54 -07002447 delta = RX_MAC_HEADER_LENGTH - ETH_HLEN;
2448 peth = (struct ethhdr *)(skb->data + delta);
2449 peth->h_proto =
2450 htons(len - RX_MAC_HEADER_LENGTH);
2451 break;
2452 default:
Dominik Brodowski624dd662009-10-24 15:52:44 +02002453 pr_debug("ray_cs untranslate RFC default\n");
John Daiker141fa612009-03-10 06:59:54 -07002454 delta = RX_MAC_HEADER_LENGTH +
2455 sizeof(struct snaphdr_t) - ETH_HLEN;
2456 peth = (struct ethhdr *)(skb->data + delta);
2457 peth->h_proto = type;
2458 break;
2459 }
2460 } else {
2461 printk("ray_cs untranslate very confused by packet\n");
2462 delta = RX_MAC_HEADER_LENGTH - ETH_HLEN;
2463 peth = (struct ethhdr *)(skb->data + delta);
2464 peth->h_proto = type;
2465 }
Al Viro7698d692007-12-29 04:55:50 -05002466 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002467/* TBD reserve skb_reserve(skb, delta); */
John Daiker141fa612009-03-10 06:59:54 -07002468 skb_pull(skb, delta);
Dominik Brodowski624dd662009-10-24 15:52:44 +02002469 pr_debug("untranslate after skb_pull(%d), skb->data = %p\n", delta,
John Daiker141fa612009-03-10 06:59:54 -07002470 skb->data);
2471 memcpy(peth->h_dest, destaddr, ADDRLEN);
2472 memcpy(peth->h_source, srcaddr, ADDRLEN);
Dominik Brodowski624dd662009-10-24 15:52:44 +02002473#if 0
2474 {
John Daiker141fa612009-03-10 06:59:54 -07002475 int i;
2476 printk(KERN_DEBUG "skb->data after untranslate:");
2477 for (i = 0; i < 64; i++)
2478 printk("%02x ", skb->data[i]);
2479 printk("\n");
2480 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002481#endif
2482} /* end untranslate */
John Daiker141fa612009-03-10 06:59:54 -07002483
Linus Torvalds1da177e2005-04-16 15:20:36 -07002484/*===========================================================================*/
2485/* Copy data from circular receive buffer to PC memory.
2486 * dest = destination address in PC memory
2487 * pkt_addr = source address in receive buffer
2488 * len = length of packet to copy
2489 */
John Daiker141fa612009-03-10 06:59:54 -07002490static int copy_from_rx_buff(ray_dev_t *local, UCHAR *dest, int pkt_addr,
2491 int length)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002492{
John Daiker141fa612009-03-10 06:59:54 -07002493 int wrap_bytes = (pkt_addr + length) - (RX_BUFF_END + 1);
2494 if (wrap_bytes <= 0) {
2495 memcpy_fromio(dest, local->rmem + pkt_addr, length);
2496 } else { /* Packet wrapped in circular buffer */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002497
John Daiker141fa612009-03-10 06:59:54 -07002498 memcpy_fromio(dest, local->rmem + pkt_addr,
2499 length - wrap_bytes);
2500 memcpy_fromio(dest + length - wrap_bytes, local->rmem,
2501 wrap_bytes);
2502 }
2503 return length;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002504}
John Daiker141fa612009-03-10 06:59:54 -07002505
2506/*===========================================================================*/
2507static void release_frag_chain(ray_dev_t *local, struct rcs __iomem *prcs)
2508{
2509 struct rcs __iomem *prcslink = prcs;
2510 int tmp = 17;
2511 unsigned rcsindex = readb(&prcs->var.rx_packet.next_frag_rcs_index);
2512
2513 while (tmp--) {
2514 writeb(CCS_BUFFER_FREE, &prcslink->buffer_status);
2515 if (rcsindex >= (NUMBER_OF_CCS + NUMBER_OF_RCS)) {
Dominik Brodowski624dd662009-10-24 15:52:44 +02002516 pr_debug("ray_cs interrupt bad rcsindex = 0x%x\n",
John Daiker141fa612009-03-10 06:59:54 -07002517 rcsindex);
2518 break;
2519 }
2520 prcslink = rcs_base(local) + rcsindex;
2521 rcsindex = readb(&prcslink->var.rx_packet.next_frag_rcs_index);
2522 }
2523 writeb(CCS_BUFFER_FREE, &prcslink->buffer_status);
2524}
2525
Linus Torvalds1da177e2005-04-16 15:20:36 -07002526/*===========================================================================*/
2527static void authenticate(ray_dev_t *local)
2528{
John Daiker141fa612009-03-10 06:59:54 -07002529 struct pcmcia_device *link = local->finder;
Dominik Brodowski624dd662009-10-24 15:52:44 +02002530 dev_dbg(&link->dev, "ray_cs Starting authentication.\n");
John Daiker141fa612009-03-10 06:59:54 -07002531 if (!(pcmcia_dev_present(link))) {
Dominik Brodowski624dd662009-10-24 15:52:44 +02002532 dev_dbg(&link->dev, "ray_cs authenticate - device not present\n");
John Daiker141fa612009-03-10 06:59:54 -07002533 return;
2534 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002535
John Daiker141fa612009-03-10 06:59:54 -07002536 del_timer(&local->timer);
2537 if (build_auth_frame(local, local->bss_id, OPEN_AUTH_REQUEST)) {
2538 local->timer.function = &join_net;
2539 } else {
2540 local->timer.function = &authenticate_timeout;
2541 }
2542 local->timer.expires = jiffies + HZ * 2;
2543 local->timer.data = (long)local;
2544 add_timer(&local->timer);
2545 local->authentication_state = AWAITING_RESPONSE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002546} /* end authenticate */
John Daiker141fa612009-03-10 06:59:54 -07002547
Linus Torvalds1da177e2005-04-16 15:20:36 -07002548/*===========================================================================*/
2549static void rx_authenticate(ray_dev_t *local, struct rcs __iomem *prcs,
John Daiker141fa612009-03-10 06:59:54 -07002550 unsigned int pkt_addr, int rx_len)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002551{
John Daiker141fa612009-03-10 06:59:54 -07002552 UCHAR buff[256];
2553 struct rx_msg *msg = (struct rx_msg *)buff;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002554
John Daiker141fa612009-03-10 06:59:54 -07002555 del_timer(&local->timer);
2556
2557 copy_from_rx_buff(local, buff, pkt_addr, rx_len & 0xff);
2558 /* if we are trying to get authenticated */
2559 if (local->sparm.b4.a_network_type == ADHOC) {
Dominik Brodowski624dd662009-10-24 15:52:44 +02002560 pr_debug("ray_cs rx_auth var= %02x %02x %02x %02x %02x %02x\n",
John Daiker141fa612009-03-10 06:59:54 -07002561 msg->var[0], msg->var[1], msg->var[2], msg->var[3],
2562 msg->var[4], msg->var[5]);
2563 if (msg->var[2] == 1) {
Dominik Brodowski624dd662009-10-24 15:52:44 +02002564 pr_debug("ray_cs Sending authentication response.\n");
John Daiker141fa612009-03-10 06:59:54 -07002565 if (!build_auth_frame
2566 (local, msg->mac.addr_2, OPEN_AUTH_RESPONSE)) {
2567 local->authentication_state = NEED_TO_AUTH;
2568 memcpy(local->auth_id, msg->mac.addr_2,
2569 ADDRLEN);
2570 }
2571 }
2572 } else { /* Infrastructure network */
2573
2574 if (local->authentication_state == AWAITING_RESPONSE) {
2575 /* Verify authentication sequence #2 and success */
2576 if (msg->var[2] == 2) {
2577 if ((msg->var[3] | msg->var[4]) == 0) {
Dominik Brodowski624dd662009-10-24 15:52:44 +02002578 pr_debug("Authentication successful\n");
John Daiker141fa612009-03-10 06:59:54 -07002579 local->card_status = CARD_AUTH_COMPLETE;
2580 associate(local);
2581 local->authentication_state =
2582 AUTHENTICATED;
2583 } else {
Dominik Brodowski624dd662009-10-24 15:52:44 +02002584 pr_debug("Authentication refused\n");
John Daiker141fa612009-03-10 06:59:54 -07002585 local->card_status = CARD_AUTH_REFUSED;
2586 join_net((u_long) local);
2587 local->authentication_state =
2588 UNAUTHENTICATED;
2589 }
2590 }
2591 }
2592 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002593
2594} /* end rx_authenticate */
John Daiker141fa612009-03-10 06:59:54 -07002595
Linus Torvalds1da177e2005-04-16 15:20:36 -07002596/*===========================================================================*/
2597static void associate(ray_dev_t *local)
2598{
John Daiker141fa612009-03-10 06:59:54 -07002599 struct ccs __iomem *pccs;
2600 struct pcmcia_device *link = local->finder;
2601 struct net_device *dev = link->priv;
2602 int ccsindex;
2603 if (!(pcmcia_dev_present(link))) {
Dominik Brodowski624dd662009-10-24 15:52:44 +02002604 dev_dbg(&link->dev, "ray_cs associate - device not present\n");
John Daiker141fa612009-03-10 06:59:54 -07002605 return;
2606 }
2607 /* If no tx buffers available, return */
2608 if ((ccsindex = get_free_ccs(local)) < 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002609/* TBD should never be here but... what if we are? */
Dominik Brodowski624dd662009-10-24 15:52:44 +02002610 dev_dbg(&link->dev, "ray_cs associate - No free ccs\n");
John Daiker141fa612009-03-10 06:59:54 -07002611 return;
2612 }
Dominik Brodowski624dd662009-10-24 15:52:44 +02002613 dev_dbg(&link->dev, "ray_cs Starting association with access point\n");
John Daiker141fa612009-03-10 06:59:54 -07002614 pccs = ccs_base(local) + ccsindex;
2615 /* fill in the CCS */
2616 writeb(CCS_START_ASSOCIATION, &pccs->cmd);
2617 /* Interrupt the firmware to process the command */
2618 if (interrupt_ecf(local, ccsindex)) {
Dominik Brodowski624dd662009-10-24 15:52:44 +02002619 dev_dbg(&link->dev, "ray_cs associate failed - ECF not ready for intr\n");
John Daiker141fa612009-03-10 06:59:54 -07002620 writeb(CCS_BUFFER_FREE, &(pccs++)->buffer_status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002621
John Daiker141fa612009-03-10 06:59:54 -07002622 del_timer(&local->timer);
2623 local->timer.expires = jiffies + HZ * 2;
2624 local->timer.data = (long)local;
2625 local->timer.function = &join_net;
2626 add_timer(&local->timer);
2627 local->card_status = CARD_ASSOC_FAILED;
2628 return;
2629 }
2630 if (!sniffer)
2631 netif_start_queue(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002632
2633} /* end associate */
John Daiker141fa612009-03-10 06:59:54 -07002634
Linus Torvalds1da177e2005-04-16 15:20:36 -07002635/*===========================================================================*/
John Daiker141fa612009-03-10 06:59:54 -07002636static void rx_deauthenticate(ray_dev_t *local, struct rcs __iomem *prcs,
2637 unsigned int pkt_addr, int rx_len)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002638{
2639/* UCHAR buff[256];
2640 struct rx_msg *msg = (struct rx_msg *)buff;
2641*/
Dominik Brodowski624dd662009-10-24 15:52:44 +02002642 pr_debug("Deauthentication frame received\n");
John Daiker141fa612009-03-10 06:59:54 -07002643 local->authentication_state = UNAUTHENTICATED;
2644 /* Need to reauthenticate or rejoin depending on reason code */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002645/* copy_from_rx_buff(local, buff, pkt_addr, rx_len & 0xff);
2646 */
2647}
John Daiker141fa612009-03-10 06:59:54 -07002648
Linus Torvalds1da177e2005-04-16 15:20:36 -07002649/*===========================================================================*/
2650static void clear_interrupt(ray_dev_t *local)
2651{
John Daiker141fa612009-03-10 06:59:54 -07002652 writeb(0, local->amem + CIS_OFFSET + HCS_INTR_OFFSET);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002653}
John Daiker141fa612009-03-10 06:59:54 -07002654
Linus Torvalds1da177e2005-04-16 15:20:36 -07002655/*===========================================================================*/
2656#ifdef CONFIG_PROC_FS
2657#define MAXDATA (PAGE_SIZE - 80)
2658
2659static char *card_status[] = {
John Daiker141fa612009-03-10 06:59:54 -07002660 "Card inserted - uninitialized", /* 0 */
2661 "Card not downloaded", /* 1 */
2662 "Waiting for download parameters", /* 2 */
2663 "Card doing acquisition", /* 3 */
2664 "Acquisition complete", /* 4 */
2665 "Authentication complete", /* 5 */
2666 "Association complete", /* 6 */
2667 "???", "???", "???", "???", /* 7 8 9 10 undefined */
2668 "Card init error", /* 11 */
2669 "Download parameters error", /* 12 */
2670 "???", /* 13 */
2671 "Acquisition failed", /* 14 */
2672 "Authentication refused", /* 15 */
2673 "Association failed" /* 16 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002674};
2675
John Daiker141fa612009-03-10 06:59:54 -07002676static char *nettype[] = { "Adhoc", "Infra " };
2677static char *framing[] = { "Encapsulation", "Translation" }
2678
Linus Torvalds1da177e2005-04-16 15:20:36 -07002679;
2680/*===========================================================================*/
Alexey Dobriyan6b914c52008-04-10 14:34:35 -07002681static int ray_cs_proc_show(struct seq_file *m, void *v)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002682{
2683/* Print current values which are not available via other means
John Daiker141fa612009-03-10 06:59:54 -07002684 * eg ifconfig
Linus Torvalds1da177e2005-04-16 15:20:36 -07002685 */
John Daiker141fa612009-03-10 06:59:54 -07002686 int i;
2687 struct pcmcia_device *link;
2688 struct net_device *dev;
2689 ray_dev_t *local;
2690 UCHAR *p;
2691 struct freq_hop_element *pfh;
2692 UCHAR c[33];
Linus Torvalds1da177e2005-04-16 15:20:36 -07002693
John Daiker141fa612009-03-10 06:59:54 -07002694 link = this_device;
2695 if (!link)
2696 return 0;
2697 dev = (struct net_device *)link->priv;
2698 if (!dev)
2699 return 0;
2700 local = netdev_priv(dev);
2701 if (!local)
2702 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002703
John Daiker141fa612009-03-10 06:59:54 -07002704 seq_puts(m, "Raylink Wireless LAN driver status\n");
2705 seq_printf(m, "%s\n", rcsid);
2706 /* build 4 does not report version, and field is 0x55 after memtest */
2707 seq_puts(m, "Firmware version = ");
2708 if (local->fw_ver == 0x55)
2709 seq_puts(m, "4 - Use dump_cis for more details\n");
2710 else
2711 seq_printf(m, "%2d.%02d.%02d\n",
2712 local->fw_ver, local->fw_bld, local->fw_var);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002713
John Daiker141fa612009-03-10 06:59:54 -07002714 for (i = 0; i < 32; i++)
2715 c[i] = local->sparm.b5.a_current_ess_id[i];
2716 c[32] = 0;
2717 seq_printf(m, "%s network ESSID = \"%s\"\n",
2718 nettype[local->sparm.b5.a_network_type], c);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002719
John Daiker141fa612009-03-10 06:59:54 -07002720 p = local->bss_id;
2721 seq_printf(m, "BSSID = %pM\n", p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002722
John Daiker141fa612009-03-10 06:59:54 -07002723 seq_printf(m, "Country code = %d\n",
2724 local->sparm.b5.a_curr_country_code);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002725
John Daiker141fa612009-03-10 06:59:54 -07002726 i = local->card_status;
2727 if (i < 0)
2728 i = 10;
2729 if (i > 16)
2730 i = 10;
2731 seq_printf(m, "Card status = %s\n", card_status[i]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002732
John Daiker141fa612009-03-10 06:59:54 -07002733 seq_printf(m, "Framing mode = %s\n", framing[translate]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002734
John Daiker141fa612009-03-10 06:59:54 -07002735 seq_printf(m, "Last pkt signal lvl = %d\n", local->last_rsl);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002736
John Daiker141fa612009-03-10 06:59:54 -07002737 if (local->beacon_rxed) {
2738 /* Pull some fields out of last beacon received */
2739 seq_printf(m, "Beacon Interval = %d Kus\n",
2740 local->last_bcn.beacon_intvl[0]
2741 + 256 * local->last_bcn.beacon_intvl[1]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002742
John Daiker141fa612009-03-10 06:59:54 -07002743 p = local->last_bcn.elements;
2744 if (p[0] == C_ESSID_ELEMENT_ID)
2745 p += p[1] + 2;
2746 else {
2747 seq_printf(m,
2748 "Parse beacon failed at essid element id = %d\n",
2749 p[0]);
2750 return 0;
2751 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002752
John Daiker141fa612009-03-10 06:59:54 -07002753 if (p[0] == C_SUPPORTED_RATES_ELEMENT_ID) {
2754 seq_puts(m, "Supported rate codes = ");
2755 for (i = 2; i < p[1] + 2; i++)
2756 seq_printf(m, "0x%02x ", p[i]);
2757 seq_putc(m, '\n');
2758 p += p[1] + 2;
2759 } else {
2760 seq_puts(m, "Parse beacon failed at rates element\n");
2761 return 0;
2762 }
2763
2764 if (p[0] == C_FH_PARAM_SET_ELEMENT_ID) {
2765 pfh = (struct freq_hop_element *)p;
2766 seq_printf(m, "Hop dwell = %d Kus\n",
2767 pfh->dwell_time[0] +
2768 256 * pfh->dwell_time[1]);
2769 seq_printf(m, "Hop set = %d \n",
2770 pfh->hop_set);
2771 seq_printf(m, "Hop pattern = %d \n",
2772 pfh->hop_pattern);
2773 seq_printf(m, "Hop index = %d \n",
2774 pfh->hop_index);
2775 p += p[1] + 2;
2776 } else {
2777 seq_puts(m,
2778 "Parse beacon failed at FH param element\n");
2779 return 0;
2780 }
2781 } else {
2782 seq_puts(m, "No beacons received\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002783 }
John Daiker141fa612009-03-10 06:59:54 -07002784 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002785}
2786
Alexey Dobriyan6b914c52008-04-10 14:34:35 -07002787static int ray_cs_proc_open(struct inode *inode, struct file *file)
2788{
2789 return single_open(file, ray_cs_proc_show, NULL);
2790}
2791
2792static const struct file_operations ray_cs_proc_fops = {
John Daiker141fa612009-03-10 06:59:54 -07002793 .owner = THIS_MODULE,
2794 .open = ray_cs_proc_open,
2795 .read = seq_read,
2796 .llseek = seq_lseek,
2797 .release = single_release,
Alexey Dobriyan6b914c52008-04-10 14:34:35 -07002798};
Linus Torvalds1da177e2005-04-16 15:20:36 -07002799#endif
2800/*===========================================================================*/
2801static int build_auth_frame(ray_dev_t *local, UCHAR *dest, int auth_type)
2802{
John Daiker141fa612009-03-10 06:59:54 -07002803 int addr;
2804 struct ccs __iomem *pccs;
2805 struct tx_msg __iomem *ptx;
2806 int ccsindex;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002807
John Daiker141fa612009-03-10 06:59:54 -07002808 /* If no tx buffers available, return */
2809 if ((ccsindex = get_free_tx_ccs(local)) < 0) {
Dominik Brodowski624dd662009-10-24 15:52:44 +02002810 pr_debug("ray_cs send authenticate - No free tx ccs\n");
John Daiker141fa612009-03-10 06:59:54 -07002811 return -1;
2812 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002813
John Daiker141fa612009-03-10 06:59:54 -07002814 pccs = ccs_base(local) + ccsindex;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002815
John Daiker141fa612009-03-10 06:59:54 -07002816 /* Address in card space */
2817 addr = TX_BUF_BASE + (ccsindex << 11);
2818 /* fill in the CCS */
2819 writeb(CCS_TX_REQUEST, &pccs->cmd);
2820 writeb(addr >> 8, pccs->var.tx_request.tx_data_ptr);
2821 writeb(0x20, pccs->var.tx_request.tx_data_ptr + 1);
2822 writeb(TX_AUTHENTICATE_LENGTH_MSB, pccs->var.tx_request.tx_data_length);
2823 writeb(TX_AUTHENTICATE_LENGTH_LSB,
2824 pccs->var.tx_request.tx_data_length + 1);
2825 writeb(0, &pccs->var.tx_request.pow_sav_mode);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002826
John Daiker141fa612009-03-10 06:59:54 -07002827 ptx = local->sram + addr;
2828 /* fill in the mac header */
2829 writeb(PROTOCOL_VER | AUTHENTIC_TYPE, &ptx->mac.frame_ctl_1);
2830 writeb(0, &ptx->mac.frame_ctl_2);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002831
John Daiker141fa612009-03-10 06:59:54 -07002832 memcpy_toio(ptx->mac.addr_1, dest, ADDRLEN);
2833 memcpy_toio(ptx->mac.addr_2, local->sparm.b4.a_mac_addr, ADDRLEN);
2834 memcpy_toio(ptx->mac.addr_3, local->bss_id, ADDRLEN);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002835
John Daiker141fa612009-03-10 06:59:54 -07002836 /* Fill in msg body with protocol 00 00, sequence 01 00 ,status 00 00 */
2837 memset_io(ptx->var, 0, 6);
2838 writeb(auth_type & 0xff, ptx->var + 2);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002839
John Daiker141fa612009-03-10 06:59:54 -07002840 /* Interrupt the firmware to process the command */
2841 if (interrupt_ecf(local, ccsindex)) {
Dominik Brodowski624dd662009-10-24 15:52:44 +02002842 pr_debug(
John Daiker141fa612009-03-10 06:59:54 -07002843 "ray_cs send authentication request failed - ECF not ready for intr\n");
2844 writeb(CCS_BUFFER_FREE, &(pccs++)->buffer_status);
2845 return -1;
2846 }
2847 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002848} /* End build_auth_frame */
2849
2850/*===========================================================================*/
2851#ifdef CONFIG_PROC_FS
Alexey Dobriyan83daee02009-11-25 10:12:20 +03002852static ssize_t ray_cs_essid_proc_write(struct file *file,
2853 const char __user *buffer, size_t count, loff_t *pos)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002854{
2855 static char proc_essid[33];
Alan Cox575c9ed2009-10-27 15:35:55 +00002856 unsigned int len = count;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002857
2858 if (len > 32)
2859 len = 32;
2860 memset(proc_essid, 0, 33);
2861 if (copy_from_user(proc_essid, buffer, len))
2862 return -EFAULT;
2863 essid = proc_essid;
2864 return count;
2865}
2866
Alexey Dobriyan83daee02009-11-25 10:12:20 +03002867static const struct file_operations ray_cs_essid_proc_fops = {
2868 .owner = THIS_MODULE,
2869 .write = ray_cs_essid_proc_write,
2870};
2871
2872static ssize_t int_proc_write(struct file *file, const char __user *buffer,
2873 size_t count, loff_t *pos)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002874{
2875 static char proc_number[10];
2876 char *p;
2877 int nr, len;
2878
2879 if (!count)
2880 return 0;
2881
2882 if (count > 9)
2883 return -EINVAL;
2884 if (copy_from_user(proc_number, buffer, count))
2885 return -EFAULT;
2886 p = proc_number;
2887 nr = 0;
2888 len = count;
2889 do {
2890 unsigned int c = *p - '0';
2891 if (c > 9)
2892 return -EINVAL;
John Daiker141fa612009-03-10 06:59:54 -07002893 nr = nr * 10 + c;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002894 p++;
2895 } while (--len);
Alexey Dobriyan83daee02009-11-25 10:12:20 +03002896 *(int *)PDE(file->f_path.dentry->d_inode)->data = nr;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002897 return count;
2898}
Alexey Dobriyan83daee02009-11-25 10:12:20 +03002899
2900static const struct file_operations int_proc_fops = {
2901 .owner = THIS_MODULE,
2902 .write = int_proc_write,
2903};
Linus Torvalds1da177e2005-04-16 15:20:36 -07002904#endif
2905
Dominik Brodowskif57ea2a2005-06-27 16:28:24 -07002906static struct pcmcia_device_id ray_ids[] = {
2907 PCMCIA_DEVICE_MANF_CARD(0x01a6, 0x0000),
2908 PCMCIA_DEVICE_NULL,
2909};
John Daiker141fa612009-03-10 06:59:54 -07002910
Dominik Brodowskif57ea2a2005-06-27 16:28:24 -07002911MODULE_DEVICE_TABLE(pcmcia, ray_ids);
2912
Linus Torvalds1da177e2005-04-16 15:20:36 -07002913static struct pcmcia_driver ray_driver = {
John Daiker141fa612009-03-10 06:59:54 -07002914 .owner = THIS_MODULE,
2915 .drv = {
2916 .name = "ray_cs",
2917 },
2918 .probe = ray_probe,
2919 .remove = ray_detach,
2920 .id_table = ray_ids,
2921 .suspend = ray_suspend,
2922 .resume = ray_resume,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002923};
2924
2925static int __init init_ray_cs(void)
2926{
John Daiker141fa612009-03-10 06:59:54 -07002927 int rc;
2928
Dominik Brodowski624dd662009-10-24 15:52:44 +02002929 pr_debug("%s\n", rcsid);
John Daiker141fa612009-03-10 06:59:54 -07002930 rc = pcmcia_register_driver(&ray_driver);
Dominik Brodowski624dd662009-10-24 15:52:44 +02002931 pr_debug("raylink init_module register_pcmcia_driver returns 0x%x\n",
John Daiker141fa612009-03-10 06:59:54 -07002932 rc);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002933
2934#ifdef CONFIG_PROC_FS
John Daiker141fa612009-03-10 06:59:54 -07002935 proc_mkdir("driver/ray_cs", NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002936
John Daiker141fa612009-03-10 06:59:54 -07002937 proc_create("driver/ray_cs/ray_cs", 0, NULL, &ray_cs_proc_fops);
Alexey Dobriyan83daee02009-11-25 10:12:20 +03002938 proc_create("driver/ray_cs/essid", S_IWUSR, NULL, &ray_cs_essid_proc_fops);
2939 proc_create_data("driver/ray_cs/net_type", S_IWUSR, NULL, &int_proc_fops, &net_type);
2940 proc_create_data("driver/ray_cs/translate", S_IWUSR, NULL, &int_proc_fops, &translate);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002941#endif
John Daiker141fa612009-03-10 06:59:54 -07002942 if (translate != 0)
2943 translate = 1;
2944 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002945} /* init_ray_cs */
2946
2947/*===========================================================================*/
2948
2949static void __exit exit_ray_cs(void)
2950{
Dominik Brodowski624dd662009-10-24 15:52:44 +02002951 pr_debug("ray_cs: cleanup_module\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002952
2953#ifdef CONFIG_PROC_FS
John Daiker141fa612009-03-10 06:59:54 -07002954 remove_proc_entry("driver/ray_cs/ray_cs", NULL);
2955 remove_proc_entry("driver/ray_cs/essid", NULL);
2956 remove_proc_entry("driver/ray_cs/net_type", NULL);
2957 remove_proc_entry("driver/ray_cs/translate", NULL);
2958 remove_proc_entry("driver/ray_cs", NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002959#endif
2960
John Daiker141fa612009-03-10 06:59:54 -07002961 pcmcia_unregister_driver(&ray_driver);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002962} /* exit_ray_cs */
2963
2964module_init(init_ray_cs);
2965module_exit(exit_ray_cs);
2966
2967/*===========================================================================*/