blob: d9c45bfcee611f7961eaa8bd8e8fb0aa21c75896 [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 /* Interrupt setup. For PCMCIA, driver takes what's given */
Dominik Brodowski5fa91672009-11-08 17:24:46 +0100325 p_dev->irq.Attributes = IRQ_TYPE_DYNAMIC_SHARING;
John Daiker141fa612009-03-10 06:59:54 -0700326 p_dev->irq.Handler = &ray_interrupt;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700327
John Daiker141fa612009-03-10 06:59:54 -0700328 /* General socket configuration */
329 p_dev->conf.Attributes = CONF_ENABLE_IRQ;
330 p_dev->conf.IntType = INT_MEMORY_AND_IO;
331 p_dev->conf.ConfigIndex = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700332
John Daiker141fa612009-03-10 06:59:54 -0700333 p_dev->priv = dev;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700334
John Daiker141fa612009-03-10 06:59:54 -0700335 local->finder = p_dev;
336 local->card_status = CARD_INSERTED;
337 local->authentication_state = UNAUTHENTICATED;
338 local->num_multi = 0;
Dominik Brodowski624dd662009-10-24 15:52:44 +0200339 dev_dbg(&p_dev->dev, "ray_attach p_dev = %p, dev = %p, local = %p, intr = %p\n",
John Daiker141fa612009-03-10 06:59:54 -0700340 p_dev, dev, local, &ray_interrupt);
341
342 /* Raylink entries in the device structure */
Stephen Hemminger32f5a332009-03-20 19:36:28 +0000343 dev->netdev_ops = &ray_netdev_ops;
John Daiker141fa612009-03-10 06:59:54 -0700344 SET_ETHTOOL_OPS(dev, &netdev_ethtool_ops);
345 dev->wireless_handlers = &ray_handler_def;
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -0700346#ifdef WIRELESS_SPY
John Daiker141fa612009-03-10 06:59:54 -0700347 local->wireless_data.spy_data = &local->spy_data;
348 dev->wireless_data = &local->wireless_data;
349#endif /* WIRELESS_SPY */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700350
Linus Torvalds1da177e2005-04-16 15:20:36 -0700351
Dominik Brodowski624dd662009-10-24 15:52:44 +0200352 dev_dbg(&p_dev->dev, "ray_cs ray_attach calling ether_setup.)\n");
John Daiker141fa612009-03-10 06:59:54 -0700353 netif_stop_queue(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700354
John Daiker141fa612009-03-10 06:59:54 -0700355 init_timer(&local->timer);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700356
John Daiker141fa612009-03-10 06:59:54 -0700357 this_device = p_dev;
358 return ray_config(p_dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700359
360fail_alloc_dev:
John Daiker141fa612009-03-10 06:59:54 -0700361 return -ENOMEM;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700362} /* ray_attach */
John Daiker141fa612009-03-10 06:59:54 -0700363
Linus Torvalds1da177e2005-04-16 15:20:36 -0700364/*=============================================================================
365 This deletes a driver "instance". The device is de-registered
366 with Card Services. If it has been released, all local data
367 structures are freed. Otherwise, the structures will be freed
368 when the device is released.
369=============================================================================*/
Dominik Brodowskifba395e2006-03-31 17:21:06 +0200370static void ray_detach(struct pcmcia_device *link)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700371{
John Daiker141fa612009-03-10 06:59:54 -0700372 struct net_device *dev;
373 ray_dev_t *local;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700374
Dominik Brodowski624dd662009-10-24 15:52:44 +0200375 dev_dbg(&link->dev, "ray_detach\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700376
John Daiker141fa612009-03-10 06:59:54 -0700377 this_device = NULL;
378 dev = link->priv;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700379
John Daiker141fa612009-03-10 06:59:54 -0700380 ray_release(link);
Dominik Brodowskicc3b4862005-11-14 21:23:14 +0100381
John Daiker141fa612009-03-10 06:59:54 -0700382 local = netdev_priv(dev);
383 del_timer(&local->timer);
Dominik Brodowskicc3b4862005-11-14 21:23:14 +0100384
John Daiker141fa612009-03-10 06:59:54 -0700385 if (link->priv) {
386 if (link->dev_node)
387 unregister_netdev(dev);
388 free_netdev(dev);
389 }
Dominik Brodowski624dd662009-10-24 15:52:44 +0200390 dev_dbg(&link->dev, "ray_cs ray_detach ending\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700391} /* ray_detach */
John Daiker141fa612009-03-10 06:59:54 -0700392
Linus Torvalds1da177e2005-04-16 15:20:36 -0700393/*=============================================================================
394 ray_config() is run after a CARD_INSERTION event
395 is received, to configure the PCMCIA socket, and to make the
396 ethernet device available to the system.
397=============================================================================*/
Linus Torvalds1da177e2005-04-16 15:20:36 -0700398#define MAX_TUPLE_SIZE 128
Dominik Brodowski15b99ac2006-03-31 17:26:06 +0200399static int ray_config(struct pcmcia_device *link)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700400{
Dominik Brodowski624dd662009-10-24 15:52:44 +0200401 int ret = 0;
John Daiker141fa612009-03-10 06:59:54 -0700402 int i;
403 win_req_t req;
404 memreq_t mem;
405 struct net_device *dev = (struct net_device *)link->priv;
406 ray_dev_t *local = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700407
Dominik Brodowski624dd662009-10-24 15:52:44 +0200408 dev_dbg(&link->dev, "ray_config\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700409
John Daiker141fa612009-03-10 06:59:54 -0700410 /* Determine card type and firmware version */
411 printk(KERN_INFO "ray_cs Detected: %s%s%s%s\n",
412 link->prod_id[0] ? link->prod_id[0] : " ",
413 link->prod_id[1] ? link->prod_id[1] : " ",
414 link->prod_id[2] ? link->prod_id[2] : " ",
415 link->prod_id[3] ? link->prod_id[3] : " ");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700416
John Daiker141fa612009-03-10 06:59:54 -0700417 /* Now allocate an interrupt line. Note that this does not
418 actually assign a handler to the interrupt.
419 */
Dominik Brodowski624dd662009-10-24 15:52:44 +0200420 ret = pcmcia_request_irq(link, &link->irq);
421 if (ret)
422 goto failed;
John Daiker141fa612009-03-10 06:59:54 -0700423 dev->irq = link->irq.AssignedIRQ;
424
425 /* This actually configures the PCMCIA socket -- setting up
426 the I/O windows and the interrupt mapping.
427 */
Dominik Brodowski624dd662009-10-24 15:52:44 +0200428 ret = pcmcia_request_configuration(link, &link->conf);
429 if (ret)
430 goto failed;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700431
432/*** Set up 32k window for shared memory (transmit and control) ************/
John Daiker141fa612009-03-10 06:59:54 -0700433 req.Attributes =
434 WIN_DATA_WIDTH_8 | WIN_MEMORY_TYPE_CM | WIN_ENABLE | WIN_USE_WAIT;
435 req.Base = 0;
436 req.Size = 0x8000;
437 req.AccessSpeed = ray_mem_speed;
Dominik Brodowski6838b032009-11-03 01:31:52 +0100438 ret = pcmcia_request_window(link, &req, &link->win);
Dominik Brodowski624dd662009-10-24 15:52:44 +0200439 if (ret)
440 goto failed;
John Daiker141fa612009-03-10 06:59:54 -0700441 mem.CardOffset = 0x0000;
442 mem.Page = 0;
Magnus Damm868575d2006-12-13 19:46:43 +0900443 ret = pcmcia_map_mem_page(link, link->win, &mem);
Dominik Brodowski624dd662009-10-24 15:52:44 +0200444 if (ret)
445 goto failed;
John Daiker141fa612009-03-10 06:59:54 -0700446 local->sram = ioremap(req.Base, req.Size);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700447
448/*** Set up 16k window for shared memory (receive buffer) ***************/
John Daiker141fa612009-03-10 06:59:54 -0700449 req.Attributes =
450 WIN_DATA_WIDTH_8 | WIN_MEMORY_TYPE_CM | WIN_ENABLE | WIN_USE_WAIT;
451 req.Base = 0;
452 req.Size = 0x4000;
453 req.AccessSpeed = ray_mem_speed;
Dominik Brodowski6838b032009-11-03 01:31:52 +0100454 ret = pcmcia_request_window(link, &req, &local->rmem_handle);
Dominik Brodowski624dd662009-10-24 15:52:44 +0200455 if (ret)
456 goto failed;
John Daiker141fa612009-03-10 06:59:54 -0700457 mem.CardOffset = 0x8000;
458 mem.Page = 0;
Magnus Damm868575d2006-12-13 19:46:43 +0900459 ret = pcmcia_map_mem_page(link, local->rmem_handle, &mem);
Dominik Brodowski624dd662009-10-24 15:52:44 +0200460 if (ret)
461 goto failed;
John Daiker141fa612009-03-10 06:59:54 -0700462 local->rmem = ioremap(req.Base, req.Size);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700463
464/*** Set up window for attribute memory ***********************************/
John Daiker141fa612009-03-10 06:59:54 -0700465 req.Attributes =
466 WIN_DATA_WIDTH_8 | WIN_MEMORY_TYPE_AM | WIN_ENABLE | WIN_USE_WAIT;
467 req.Base = 0;
468 req.Size = 0x1000;
469 req.AccessSpeed = ray_mem_speed;
Dominik Brodowski6838b032009-11-03 01:31:52 +0100470 ret = pcmcia_request_window(link, &req, &local->amem_handle);
Dominik Brodowski624dd662009-10-24 15:52:44 +0200471 if (ret)
472 goto failed;
John Daiker141fa612009-03-10 06:59:54 -0700473 mem.CardOffset = 0x0000;
474 mem.Page = 0;
Magnus Damm868575d2006-12-13 19:46:43 +0900475 ret = pcmcia_map_mem_page(link, local->amem_handle, &mem);
Dominik Brodowski624dd662009-10-24 15:52:44 +0200476 if (ret)
477 goto failed;
John Daiker141fa612009-03-10 06:59:54 -0700478 local->amem = ioremap(req.Base, req.Size);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700479
Dominik Brodowski624dd662009-10-24 15:52:44 +0200480 dev_dbg(&link->dev, "ray_config sram=%p\n", local->sram);
481 dev_dbg(&link->dev, "ray_config rmem=%p\n", local->rmem);
482 dev_dbg(&link->dev, "ray_config amem=%p\n", local->amem);
John Daiker141fa612009-03-10 06:59:54 -0700483 if (ray_init(dev) < 0) {
484 ray_release(link);
485 return -ENODEV;
486 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700487
Dominik Brodowskidd2e5a12009-11-03 10:27:34 +0100488 SET_NETDEV_DEV(dev, &link->dev);
John Daiker141fa612009-03-10 06:59:54 -0700489 i = register_netdev(dev);
490 if (i != 0) {
491 printk("ray_config register_netdev() failed\n");
492 ray_release(link);
493 return i;
494 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700495
John Daiker141fa612009-03-10 06:59:54 -0700496 strcpy(local->node.dev_name, dev->name);
497 link->dev_node = &local->node;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700498
John Daiker141fa612009-03-10 06:59:54 -0700499 printk(KERN_INFO "%s: RayLink, irq %d, hw_addr %pM\n",
500 dev->name, dev->irq, dev->dev_addr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700501
John Daiker141fa612009-03-10 06:59:54 -0700502 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700503
Dominik Brodowski624dd662009-10-24 15:52:44 +0200504failed:
John Daiker141fa612009-03-10 06:59:54 -0700505 ray_release(link);
506 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700507} /* ray_config */
508
509static inline struct ccs __iomem *ccs_base(ray_dev_t *dev)
510{
511 return dev->sram + CCS_BASE;
512}
513
514static inline struct rcs __iomem *rcs_base(ray_dev_t *dev)
515{
516 /*
517 * This looks nonsensical, since there is a separate
518 * RCS_BASE. But the difference between a "struct rcs"
519 * and a "struct ccs" ends up being in the _index_ off
520 * the base, so the base pointer is the same for both
521 * ccs/rcs.
522 */
523 return dev->sram + CCS_BASE;
524}
525
526/*===========================================================================*/
527static int ray_init(struct net_device *dev)
528{
John Daiker141fa612009-03-10 06:59:54 -0700529 int i;
530 UCHAR *p;
531 struct ccs __iomem *pccs;
532 ray_dev_t *local = netdev_priv(dev);
533 struct pcmcia_device *link = local->finder;
Dominik Brodowski624dd662009-10-24 15:52:44 +0200534 dev_dbg(&link->dev, "ray_init(0x%p)\n", dev);
John Daiker141fa612009-03-10 06:59:54 -0700535 if (!(pcmcia_dev_present(link))) {
Dominik Brodowski624dd662009-10-24 15:52:44 +0200536 dev_dbg(&link->dev, "ray_init - device not present\n");
John Daiker141fa612009-03-10 06:59:54 -0700537 return -1;
538 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700539
John Daiker141fa612009-03-10 06:59:54 -0700540 local->net_type = net_type;
541 local->sta_type = TYPE_STA;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700542
John Daiker141fa612009-03-10 06:59:54 -0700543 /* Copy the startup results to local memory */
544 memcpy_fromio(&local->startup_res, local->sram + ECF_TO_HOST_BASE,
545 sizeof(struct startup_res_6));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700546
John Daiker141fa612009-03-10 06:59:54 -0700547 /* Check Power up test status and get mac address from card */
548 if (local->startup_res.startup_word != 0x80) {
549 printk(KERN_INFO "ray_init ERROR card status = %2x\n",
550 local->startup_res.startup_word);
551 local->card_status = CARD_INIT_ERROR;
552 return -1;
553 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700554
John Daiker141fa612009-03-10 06:59:54 -0700555 local->fw_ver = local->startup_res.firmware_version[0];
556 local->fw_bld = local->startup_res.firmware_version[1];
557 local->fw_var = local->startup_res.firmware_version[2];
Frans Popcb01b092010-03-24 19:46:34 +0100558 dev_dbg(&link->dev, "ray_init firmware version %d.%d\n", local->fw_ver,
John Daiker141fa612009-03-10 06:59:54 -0700559 local->fw_bld);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700560
John Daiker141fa612009-03-10 06:59:54 -0700561 local->tib_length = 0x20;
562 if ((local->fw_ver == 5) && (local->fw_bld >= 30))
563 local->tib_length = local->startup_res.tib_length;
Dominik Brodowski624dd662009-10-24 15:52:44 +0200564 dev_dbg(&link->dev, "ray_init tib_length = 0x%02x\n", local->tib_length);
John Daiker141fa612009-03-10 06:59:54 -0700565 /* Initialize CCS's to buffer free state */
566 pccs = ccs_base(local);
567 for (i = 0; i < NUMBER_OF_CCS; i++) {
568 writeb(CCS_BUFFER_FREE, &(pccs++)->buffer_status);
569 }
570 init_startup_params(local);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700571
John Daiker141fa612009-03-10 06:59:54 -0700572 /* copy mac address to startup parameters */
573 if (parse_addr(phy_addr, local->sparm.b4.a_mac_addr)) {
574 p = local->sparm.b4.a_mac_addr;
575 } else {
576 memcpy(&local->sparm.b4.a_mac_addr,
577 &local->startup_res.station_addr, ADDRLEN);
578 p = local->sparm.b4.a_mac_addr;
579 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700580
John Daiker141fa612009-03-10 06:59:54 -0700581 clear_interrupt(local); /* Clear any interrupt from the card */
582 local->card_status = CARD_AWAITING_PARAM;
Dominik Brodowski624dd662009-10-24 15:52:44 +0200583 dev_dbg(&link->dev, "ray_init ending\n");
John Daiker141fa612009-03-10 06:59:54 -0700584 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700585} /* ray_init */
John Daiker141fa612009-03-10 06:59:54 -0700586
Linus Torvalds1da177e2005-04-16 15:20:36 -0700587/*===========================================================================*/
588/* Download startup parameters to the card and command it to read them */
589static int dl_startup_params(struct net_device *dev)
590{
John Daiker141fa612009-03-10 06:59:54 -0700591 int ccsindex;
592 ray_dev_t *local = netdev_priv(dev);
593 struct ccs __iomem *pccs;
594 struct pcmcia_device *link = local->finder;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700595
Dominik Brodowski624dd662009-10-24 15:52:44 +0200596 dev_dbg(&link->dev, "dl_startup_params entered\n");
John Daiker141fa612009-03-10 06:59:54 -0700597 if (!(pcmcia_dev_present(link))) {
Dominik Brodowski624dd662009-10-24 15:52:44 +0200598 dev_dbg(&link->dev, "ray_cs dl_startup_params - device not present\n");
John Daiker141fa612009-03-10 06:59:54 -0700599 return -1;
600 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700601
John Daiker141fa612009-03-10 06:59:54 -0700602 /* Copy parameters to host to ECF area */
603 if (local->fw_ver == 0x55)
604 memcpy_toio(local->sram + HOST_TO_ECF_BASE, &local->sparm.b4,
605 sizeof(struct b4_startup_params));
606 else
607 memcpy_toio(local->sram + HOST_TO_ECF_BASE, &local->sparm.b5,
608 sizeof(struct b5_startup_params));
609
610 /* Fill in the CCS fields for the ECF */
611 if ((ccsindex = get_free_ccs(local)) < 0)
612 return -1;
613 local->dl_param_ccs = ccsindex;
614 pccs = ccs_base(local) + ccsindex;
615 writeb(CCS_DOWNLOAD_STARTUP_PARAMS, &pccs->cmd);
Dominik Brodowski624dd662009-10-24 15:52:44 +0200616 dev_dbg(&link->dev, "dl_startup_params start ccsindex = %d\n",
John Daiker141fa612009-03-10 06:59:54 -0700617 local->dl_param_ccs);
618 /* Interrupt the firmware to process the command */
619 if (interrupt_ecf(local, ccsindex)) {
620 printk(KERN_INFO "ray dl_startup_params failed - "
621 "ECF not ready for intr\n");
622 local->card_status = CARD_DL_PARAM_ERROR;
623 writeb(CCS_BUFFER_FREE, &(pccs++)->buffer_status);
624 return -2;
625 }
626 local->card_status = CARD_DL_PARAM;
627 /* Start kernel timer to wait for dl startup to complete. */
628 local->timer.expires = jiffies + HZ / 2;
629 local->timer.data = (long)local;
630 local->timer.function = &verify_dl_startup;
631 add_timer(&local->timer);
Dominik Brodowski624dd662009-10-24 15:52:44 +0200632 dev_dbg(&link->dev,
John Daiker141fa612009-03-10 06:59:54 -0700633 "ray_cs dl_startup_params started timer for verify_dl_startup\n");
634 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700635} /* dl_startup_params */
John Daiker141fa612009-03-10 06:59:54 -0700636
Linus Torvalds1da177e2005-04-16 15:20:36 -0700637/*===========================================================================*/
638static void init_startup_params(ray_dev_t *local)
639{
John Daiker141fa612009-03-10 06:59:54 -0700640 int i;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700641
John Daiker141fa612009-03-10 06:59:54 -0700642 if (country > JAPAN_TEST)
643 country = USA;
644 else if (country < USA)
645 country = USA;
646 /* structure for hop time and beacon period is defined here using
647 * New 802.11D6.1 format. Card firmware is still using old format
648 * until version 6.
649 * Before After
650 * a_hop_time ms byte a_hop_time ms byte
651 * a_hop_time 2s byte a_hop_time ls byte
652 * a_hop_time ls byte a_beacon_period ms byte
653 * a_beacon_period a_beacon_period ls byte
654 *
655 * a_hop_time = uS a_hop_time = KuS
656 * a_beacon_period = hops a_beacon_period = KuS
657 *//* 64ms = 010000 */
658 if (local->fw_ver == 0x55) {
659 memcpy((UCHAR *) &local->sparm.b4, b4_default_startup_parms,
660 sizeof(struct b4_startup_params));
661 /* Translate sane kus input values to old build 4/5 format */
662 /* i = hop time in uS truncated to 3 bytes */
663 i = (hop_dwell * 1024) & 0xffffff;
664 local->sparm.b4.a_hop_time[0] = (i >> 16) & 0xff;
665 local->sparm.b4.a_hop_time[1] = (i >> 8) & 0xff;
666 local->sparm.b4.a_beacon_period[0] = 0;
667 local->sparm.b4.a_beacon_period[1] =
668 ((beacon_period / hop_dwell) - 1) & 0xff;
669 local->sparm.b4.a_curr_country_code = country;
670 local->sparm.b4.a_hop_pattern_length =
671 hop_pattern_length[(int)country] - 1;
672 if (bc) {
673 local->sparm.b4.a_ack_timeout = 0x50;
674 local->sparm.b4.a_sifs = 0x3f;
675 }
676 } else { /* Version 5 uses real kus values */
677 memcpy((UCHAR *) &local->sparm.b5, b5_default_startup_parms,
678 sizeof(struct b5_startup_params));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700679
John Daiker141fa612009-03-10 06:59:54 -0700680 local->sparm.b5.a_hop_time[0] = (hop_dwell >> 8) & 0xff;
681 local->sparm.b5.a_hop_time[1] = hop_dwell & 0xff;
682 local->sparm.b5.a_beacon_period[0] =
683 (beacon_period >> 8) & 0xff;
684 local->sparm.b5.a_beacon_period[1] = beacon_period & 0xff;
685 if (psm)
686 local->sparm.b5.a_power_mgt_state = 1;
687 local->sparm.b5.a_curr_country_code = country;
688 local->sparm.b5.a_hop_pattern_length =
689 hop_pattern_length[(int)country];
690 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700691
John Daiker141fa612009-03-10 06:59:54 -0700692 local->sparm.b4.a_network_type = net_type & 0x01;
693 local->sparm.b4.a_acting_as_ap_status = TYPE_STA;
694
695 if (essid != NULL)
696 strncpy(local->sparm.b4.a_current_ess_id, essid, ESSID_SIZE);
697} /* init_startup_params */
698
Linus Torvalds1da177e2005-04-16 15:20:36 -0700699/*===========================================================================*/
700static void verify_dl_startup(u_long data)
701{
John Daiker141fa612009-03-10 06:59:54 -0700702 ray_dev_t *local = (ray_dev_t *) data;
703 struct ccs __iomem *pccs = ccs_base(local) + local->dl_param_ccs;
704 UCHAR status;
705 struct pcmcia_device *link = local->finder;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700706
John Daiker141fa612009-03-10 06:59:54 -0700707 if (!(pcmcia_dev_present(link))) {
Dominik Brodowski624dd662009-10-24 15:52:44 +0200708 dev_dbg(&link->dev, "ray_cs verify_dl_startup - device not present\n");
John Daiker141fa612009-03-10 06:59:54 -0700709 return;
710 }
Dominik Brodowski624dd662009-10-24 15:52:44 +0200711#if 0
712 {
John Daiker141fa612009-03-10 06:59:54 -0700713 int i;
714 printk(KERN_DEBUG
715 "verify_dl_startup parameters sent via ccs %d:\n",
716 local->dl_param_ccs);
717 for (i = 0; i < sizeof(struct b5_startup_params); i++) {
718 printk(" %2x",
719 (unsigned int)readb(local->sram +
720 HOST_TO_ECF_BASE + i));
721 }
722 printk("\n");
723 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700724#endif
725
John Daiker141fa612009-03-10 06:59:54 -0700726 status = readb(&pccs->buffer_status);
727 if (status != CCS_BUFFER_FREE) {
728 printk(KERN_INFO
729 "Download startup params failed. Status = %d\n",
730 status);
731 local->card_status = CARD_DL_PARAM_ERROR;
732 return;
733 }
734 if (local->sparm.b4.a_network_type == ADHOC)
735 start_net((u_long) local);
736 else
737 join_net((u_long) local);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700738
John Daiker141fa612009-03-10 06:59:54 -0700739 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700740} /* end verify_dl_startup */
John Daiker141fa612009-03-10 06:59:54 -0700741
Linus Torvalds1da177e2005-04-16 15:20:36 -0700742/*===========================================================================*/
743/* Command card to start a network */
744static void start_net(u_long data)
745{
John Daiker141fa612009-03-10 06:59:54 -0700746 ray_dev_t *local = (ray_dev_t *) data;
747 struct ccs __iomem *pccs;
748 int ccsindex;
749 struct pcmcia_device *link = local->finder;
750 if (!(pcmcia_dev_present(link))) {
Dominik Brodowski624dd662009-10-24 15:52:44 +0200751 dev_dbg(&link->dev, "ray_cs start_net - device not present\n");
John Daiker141fa612009-03-10 06:59:54 -0700752 return;
753 }
754 /* Fill in the CCS fields for the ECF */
755 if ((ccsindex = get_free_ccs(local)) < 0)
756 return;
757 pccs = ccs_base(local) + ccsindex;
758 writeb(CCS_START_NETWORK, &pccs->cmd);
759 writeb(0, &pccs->var.start_network.update_param);
760 /* Interrupt the firmware to process the command */
761 if (interrupt_ecf(local, ccsindex)) {
Dominik Brodowski624dd662009-10-24 15:52:44 +0200762 dev_dbg(&link->dev, "ray start net failed - card not ready for intr\n");
John Daiker141fa612009-03-10 06:59:54 -0700763 writeb(CCS_BUFFER_FREE, &(pccs++)->buffer_status);
764 return;
765 }
766 local->card_status = CARD_DOING_ACQ;
767 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700768} /* end start_net */
John Daiker141fa612009-03-10 06:59:54 -0700769
Linus Torvalds1da177e2005-04-16 15:20:36 -0700770/*===========================================================================*/
771/* Command card to join a network */
772static void join_net(u_long data)
773{
John Daiker141fa612009-03-10 06:59:54 -0700774 ray_dev_t *local = (ray_dev_t *) data;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700775
John Daiker141fa612009-03-10 06:59:54 -0700776 struct ccs __iomem *pccs;
777 int ccsindex;
778 struct pcmcia_device *link = local->finder;
779
780 if (!(pcmcia_dev_present(link))) {
Dominik Brodowski624dd662009-10-24 15:52:44 +0200781 dev_dbg(&link->dev, "ray_cs join_net - device not present\n");
John Daiker141fa612009-03-10 06:59:54 -0700782 return;
783 }
784 /* Fill in the CCS fields for the ECF */
785 if ((ccsindex = get_free_ccs(local)) < 0)
786 return;
787 pccs = ccs_base(local) + ccsindex;
788 writeb(CCS_JOIN_NETWORK, &pccs->cmd);
789 writeb(0, &pccs->var.join_network.update_param);
790 writeb(0, &pccs->var.join_network.net_initiated);
791 /* Interrupt the firmware to process the command */
792 if (interrupt_ecf(local, ccsindex)) {
Dominik Brodowski624dd662009-10-24 15:52:44 +0200793 dev_dbg(&link->dev, "ray join net failed - card not ready for intr\n");
John Daiker141fa612009-03-10 06:59:54 -0700794 writeb(CCS_BUFFER_FREE, &(pccs++)->buffer_status);
795 return;
796 }
797 local->card_status = CARD_DOING_ACQ;
798 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700799}
John Daiker141fa612009-03-10 06:59:54 -0700800
Linus Torvalds1da177e2005-04-16 15:20:36 -0700801/*============================================================================
802 After a card is removed, ray_release() will unregister the net
803 device, and release the PCMCIA configuration. If the device is
804 still open, this will be postponed until it is closed.
805=============================================================================*/
Dominik Brodowskifba395e2006-03-31 17:21:06 +0200806static void ray_release(struct pcmcia_device *link)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700807{
John Daiker141fa612009-03-10 06:59:54 -0700808 struct net_device *dev = link->priv;
809 ray_dev_t *local = netdev_priv(dev);
810 int i;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700811
Dominik Brodowski624dd662009-10-24 15:52:44 +0200812 dev_dbg(&link->dev, "ray_release\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700813
John Daiker141fa612009-03-10 06:59:54 -0700814 del_timer(&local->timer);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700815
John Daiker141fa612009-03-10 06:59:54 -0700816 iounmap(local->sram);
817 iounmap(local->rmem);
818 iounmap(local->amem);
819 /* Do bother checking to see if these succeed or not */
Magnus Dammf5560da2006-12-13 19:46:38 +0900820 i = pcmcia_release_window(link, local->amem_handle);
John Daiker141fa612009-03-10 06:59:54 -0700821 if (i != 0)
Dominik Brodowski624dd662009-10-24 15:52:44 +0200822 dev_dbg(&link->dev, "ReleaseWindow(local->amem) ret = %x\n", i);
Magnus Dammf5560da2006-12-13 19:46:38 +0900823 i = pcmcia_release_window(link, local->rmem_handle);
John Daiker141fa612009-03-10 06:59:54 -0700824 if (i != 0)
Dominik Brodowski624dd662009-10-24 15:52:44 +0200825 dev_dbg(&link->dev, "ReleaseWindow(local->rmem) ret = %x\n", i);
John Daiker141fa612009-03-10 06:59:54 -0700826 pcmcia_disable_device(link);
827
Dominik Brodowski624dd662009-10-24 15:52:44 +0200828 dev_dbg(&link->dev, "ray_release ending\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700829}
830
Dominik Brodowskifba395e2006-03-31 17:21:06 +0200831static int ray_suspend(struct pcmcia_device *link)
Dominik Brodowski98e4c282005-11-14 21:21:18 +0100832{
Dominik Brodowski98e4c282005-11-14 21:21:18 +0100833 struct net_device *dev = link->priv;
834
Dominik Brodowskie2d40962006-03-02 00:09:29 +0100835 if (link->open)
Dominik Brodowski8661bb52006-03-02 00:02:33 +0100836 netif_device_detach(dev);
Dominik Brodowski98e4c282005-11-14 21:21:18 +0100837
838 return 0;
839}
840
Dominik Brodowskifba395e2006-03-31 17:21:06 +0200841static int ray_resume(struct pcmcia_device *link)
Dominik Brodowski98e4c282005-11-14 21:21:18 +0100842{
Dominik Brodowski98e4c282005-11-14 21:21:18 +0100843 struct net_device *dev = link->priv;
844
Dominik Brodowskie2d40962006-03-02 00:09:29 +0100845 if (link->open) {
Dominik Brodowski8661bb52006-03-02 00:02:33 +0100846 ray_reset(dev);
847 netif_device_attach(dev);
848 }
Dominik Brodowski98e4c282005-11-14 21:21:18 +0100849
850 return 0;
851}
852
Linus Torvalds1da177e2005-04-16 15:20:36 -0700853/*===========================================================================*/
Hannes Eder2ed5ba82008-12-26 00:12:59 -0800854static int ray_dev_init(struct net_device *dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700855{
856#ifdef RAY_IMMEDIATE_INIT
John Daiker141fa612009-03-10 06:59:54 -0700857 int i;
858#endif /* RAY_IMMEDIATE_INIT */
859 ray_dev_t *local = netdev_priv(dev);
860 struct pcmcia_device *link = local->finder;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700861
Dominik Brodowski624dd662009-10-24 15:52:44 +0200862 dev_dbg(&link->dev, "ray_dev_init(dev=%p)\n", dev);
John Daiker141fa612009-03-10 06:59:54 -0700863 if (!(pcmcia_dev_present(link))) {
Dominik Brodowski624dd662009-10-24 15:52:44 +0200864 dev_dbg(&link->dev, "ray_dev_init - device not present\n");
John Daiker141fa612009-03-10 06:59:54 -0700865 return -1;
866 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700867#ifdef RAY_IMMEDIATE_INIT
John Daiker141fa612009-03-10 06:59:54 -0700868 /* Download startup parameters */
869 if ((i = dl_startup_params(dev)) < 0) {
870 printk(KERN_INFO "ray_dev_init dl_startup_params failed - "
871 "returns 0x%x\n", i);
872 return -1;
873 }
874#else /* RAY_IMMEDIATE_INIT */
875 /* Postpone the card init so that we can still configure the card,
876 * for example using the Wireless Extensions. The init will happen
877 * in ray_open() - Jean II */
Dominik Brodowski624dd662009-10-24 15:52:44 +0200878 dev_dbg(&link->dev,
John Daiker141fa612009-03-10 06:59:54 -0700879 "ray_dev_init: postponing card init to ray_open() ; Status = %d\n",
880 local->card_status);
881#endif /* RAY_IMMEDIATE_INIT */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700882
John Daiker141fa612009-03-10 06:59:54 -0700883 /* copy mac and broadcast addresses to linux device */
Jiri Pirko3a6d54c2009-05-11 23:37:15 +0000884 memcpy(dev->dev_addr, &local->sparm.b4.a_mac_addr, ADDRLEN);
John Daiker141fa612009-03-10 06:59:54 -0700885 memset(dev->broadcast, 0xff, ETH_ALEN);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700886
Dominik Brodowski624dd662009-10-24 15:52:44 +0200887 dev_dbg(&link->dev, "ray_dev_init ending\n");
John Daiker141fa612009-03-10 06:59:54 -0700888 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700889}
John Daiker141fa612009-03-10 06:59:54 -0700890
Linus Torvalds1da177e2005-04-16 15:20:36 -0700891/*===========================================================================*/
892static int ray_dev_config(struct net_device *dev, struct ifmap *map)
893{
John Daiker141fa612009-03-10 06:59:54 -0700894 ray_dev_t *local = netdev_priv(dev);
895 struct pcmcia_device *link = local->finder;
896 /* Dummy routine to satisfy device structure */
Dominik Brodowski624dd662009-10-24 15:52:44 +0200897 dev_dbg(&link->dev, "ray_dev_config(dev=%p,ifmap=%p)\n", dev, map);
John Daiker141fa612009-03-10 06:59:54 -0700898 if (!(pcmcia_dev_present(link))) {
Dominik Brodowski624dd662009-10-24 15:52:44 +0200899 dev_dbg(&link->dev, "ray_dev_config - device not present\n");
John Daiker141fa612009-03-10 06:59:54 -0700900 return -1;
901 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700902
John Daiker141fa612009-03-10 06:59:54 -0700903 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700904}
John Daiker141fa612009-03-10 06:59:54 -0700905
Linus Torvalds1da177e2005-04-16 15:20:36 -0700906/*===========================================================================*/
Stephen Hemmingerd0cf9c02009-08-31 19:50:57 +0000907static netdev_tx_t ray_dev_start_xmit(struct sk_buff *skb,
908 struct net_device *dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700909{
John Daiker141fa612009-03-10 06:59:54 -0700910 ray_dev_t *local = netdev_priv(dev);
911 struct pcmcia_device *link = local->finder;
912 short length = skb->len;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700913
Stephen Hemmingerd0cf9c02009-08-31 19:50:57 +0000914 if (!pcmcia_dev_present(link)) {
Dominik Brodowski624dd662009-10-24 15:52:44 +0200915 dev_dbg(&link->dev, "ray_dev_start_xmit - device not present\n");
Stephen Hemmingerd0cf9c02009-08-31 19:50:57 +0000916 dev_kfree_skb(skb);
917 return NETDEV_TX_OK;
John Daiker141fa612009-03-10 06:59:54 -0700918 }
Stephen Hemmingerd0cf9c02009-08-31 19:50:57 +0000919
Dominik Brodowski624dd662009-10-24 15:52:44 +0200920 dev_dbg(&link->dev, "ray_dev_start_xmit(skb=%p, dev=%p)\n", skb, dev);
John Daiker141fa612009-03-10 06:59:54 -0700921 if (local->authentication_state == NEED_TO_AUTH) {
Dominik Brodowski624dd662009-10-24 15:52:44 +0200922 dev_dbg(&link->dev, "ray_cs Sending authentication request.\n");
John Daiker141fa612009-03-10 06:59:54 -0700923 if (!build_auth_frame(local, local->auth_id, OPEN_AUTH_REQUEST)) {
924 local->authentication_state = AUTHENTICATED;
925 netif_stop_queue(dev);
Patrick McHardy5b548142009-06-12 06:22:29 +0000926 return NETDEV_TX_BUSY;
John Daiker141fa612009-03-10 06:59:54 -0700927 }
928 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700929
John Daiker141fa612009-03-10 06:59:54 -0700930 if (length < ETH_ZLEN) {
931 if (skb_padto(skb, ETH_ZLEN))
Patrick McHardy6ed10652009-06-23 06:03:08 +0000932 return NETDEV_TX_OK;
John Daiker141fa612009-03-10 06:59:54 -0700933 length = ETH_ZLEN;
934 }
935 switch (ray_hw_xmit(skb->data, length, dev, DATA_TYPE)) {
936 case XMIT_NO_CCS:
937 case XMIT_NEED_AUTH:
938 netif_stop_queue(dev);
Patrick McHardy5b548142009-06-12 06:22:29 +0000939 return NETDEV_TX_BUSY;
John Daiker141fa612009-03-10 06:59:54 -0700940 case XMIT_NO_INTR:
941 case XMIT_MSG_BAD:
942 case XMIT_OK:
943 default:
944 dev->trans_start = jiffies;
945 dev_kfree_skb(skb);
John Daiker141fa612009-03-10 06:59:54 -0700946 }
Stephen Hemmingerd0cf9c02009-08-31 19:50:57 +0000947
Patrick McHardy6ed10652009-06-23 06:03:08 +0000948 return NETDEV_TX_OK;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700949} /* ray_dev_start_xmit */
John Daiker141fa612009-03-10 06:59:54 -0700950
Linus Torvalds1da177e2005-04-16 15:20:36 -0700951/*===========================================================================*/
John Daiker141fa612009-03-10 06:59:54 -0700952static int ray_hw_xmit(unsigned char *data, int len, struct net_device *dev,
953 UCHAR msg_type)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700954{
John Daiker141fa612009-03-10 06:59:54 -0700955 ray_dev_t *local = netdev_priv(dev);
956 struct ccs __iomem *pccs;
957 int ccsindex;
958 int offset;
959 struct tx_msg __iomem *ptx; /* Address of xmit buffer in PC space */
960 short int addr; /* Address of xmit buffer in card space */
961
Dominik Brodowski624dd662009-10-24 15:52:44 +0200962 pr_debug("ray_hw_xmit(data=%p, len=%d, dev=%p)\n", data, len, dev);
John Daiker141fa612009-03-10 06:59:54 -0700963 if (len + TX_HEADER_LENGTH > TX_BUF_SIZE) {
964 printk(KERN_INFO "ray_hw_xmit packet too large: %d bytes\n",
965 len);
966 return XMIT_MSG_BAD;
967 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700968 switch (ccsindex = get_free_tx_ccs(local)) {
969 case ECCSBUSY:
Dominik Brodowski624dd662009-10-24 15:52:44 +0200970 pr_debug("ray_hw_xmit tx_ccs table busy\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700971 case ECCSFULL:
Dominik Brodowski624dd662009-10-24 15:52:44 +0200972 pr_debug("ray_hw_xmit No free tx ccs\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700973 case ECARDGONE:
John Daiker141fa612009-03-10 06:59:54 -0700974 netif_stop_queue(dev);
975 return XMIT_NO_CCS;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700976 default:
977 break;
978 }
John Daiker141fa612009-03-10 06:59:54 -0700979 addr = TX_BUF_BASE + (ccsindex << 11);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700980
John Daiker141fa612009-03-10 06:59:54 -0700981 if (msg_type == DATA_TYPE) {
982 local->stats.tx_bytes += len;
983 local->stats.tx_packets++;
984 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700985
John Daiker141fa612009-03-10 06:59:54 -0700986 ptx = local->sram + addr;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700987
John Daiker141fa612009-03-10 06:59:54 -0700988 ray_build_header(local, ptx, msg_type, data);
989 if (translate) {
990 offset = translate_frame(local, ptx, data, len);
991 } else { /* Encapsulate frame */
992 /* TBD TIB length will move address of ptx->var */
993 memcpy_toio(&ptx->var, data, len);
994 offset = 0;
995 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700996
John Daiker141fa612009-03-10 06:59:54 -0700997 /* fill in the CCS */
998 pccs = ccs_base(local) + ccsindex;
999 len += TX_HEADER_LENGTH + offset;
1000 writeb(CCS_TX_REQUEST, &pccs->cmd);
1001 writeb(addr >> 8, &pccs->var.tx_request.tx_data_ptr[0]);
1002 writeb(local->tib_length, &pccs->var.tx_request.tx_data_ptr[1]);
1003 writeb(len >> 8, &pccs->var.tx_request.tx_data_length[0]);
1004 writeb(len & 0xff, &pccs->var.tx_request.tx_data_length[1]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001005/* TBD still need psm_cam? */
John Daiker141fa612009-03-10 06:59:54 -07001006 writeb(PSM_CAM, &pccs->var.tx_request.pow_sav_mode);
1007 writeb(local->net_default_tx_rate, &pccs->var.tx_request.tx_rate);
1008 writeb(0, &pccs->var.tx_request.antenna);
Dominik Brodowski624dd662009-10-24 15:52:44 +02001009 pr_debug("ray_hw_xmit default_tx_rate = 0x%x\n",
John Daiker141fa612009-03-10 06:59:54 -07001010 local->net_default_tx_rate);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001011
John Daiker141fa612009-03-10 06:59:54 -07001012 /* Interrupt the firmware to process the command */
1013 if (interrupt_ecf(local, ccsindex)) {
Dominik Brodowski624dd662009-10-24 15:52:44 +02001014 pr_debug("ray_hw_xmit failed - ECF not ready for intr\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001015/* TBD very inefficient to copy packet to buffer, and then not
1016 send it, but the alternative is to queue the messages and that
1017 won't be done for a while. Maybe set tbusy until a CCS is free?
1018*/
John Daiker141fa612009-03-10 06:59:54 -07001019 writeb(CCS_BUFFER_FREE, &pccs->buffer_status);
1020 return XMIT_NO_INTR;
1021 }
1022 return XMIT_OK;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001023} /* end ray_hw_xmit */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001024
John Daiker141fa612009-03-10 06:59:54 -07001025/*===========================================================================*/
1026static int translate_frame(ray_dev_t *local, struct tx_msg __iomem *ptx,
1027 unsigned char *data, int len)
1028{
1029 __be16 proto = ((struct ethhdr *)data)->h_proto;
1030 if (ntohs(proto) >= 1536) { /* DIX II ethernet frame */
Dominik Brodowski624dd662009-10-24 15:52:44 +02001031 pr_debug("ray_cs translate_frame DIX II\n");
John Daiker141fa612009-03-10 06:59:54 -07001032 /* Copy LLC header to card buffer */
1033 memcpy_toio(&ptx->var, eth2_llc, sizeof(eth2_llc));
1034 memcpy_toio(((void __iomem *)&ptx->var) + sizeof(eth2_llc),
1035 (UCHAR *) &proto, 2);
1036 if (proto == htons(ETH_P_AARP) || proto == htons(ETH_P_IPX)) {
1037 /* This is the selective translation table, only 2 entries */
1038 writeb(0xf8,
1039 &((struct snaphdr_t __iomem *)ptx->var)->org[3]);
1040 }
1041 /* Copy body of ethernet packet without ethernet header */
1042 memcpy_toio((void __iomem *)&ptx->var +
1043 sizeof(struct snaphdr_t), data + ETH_HLEN,
1044 len - ETH_HLEN);
1045 return (int)sizeof(struct snaphdr_t) - ETH_HLEN;
1046 } else { /* already 802 type, and proto is length */
Dominik Brodowski624dd662009-10-24 15:52:44 +02001047 pr_debug("ray_cs translate_frame 802\n");
John Daiker141fa612009-03-10 06:59:54 -07001048 if (proto == htons(0xffff)) { /* evil netware IPX 802.3 without LLC */
Dominik Brodowski624dd662009-10-24 15:52:44 +02001049 pr_debug("ray_cs translate_frame evil IPX\n");
John Daiker141fa612009-03-10 06:59:54 -07001050 memcpy_toio(&ptx->var, data + ETH_HLEN, len - ETH_HLEN);
1051 return 0 - ETH_HLEN;
1052 }
1053 memcpy_toio(&ptx->var, data + ETH_HLEN, len - ETH_HLEN);
1054 return 0 - ETH_HLEN;
1055 }
1056 /* TBD do other frame types */
1057} /* end translate_frame */
1058
1059/*===========================================================================*/
1060static void ray_build_header(ray_dev_t *local, struct tx_msg __iomem *ptx,
1061 UCHAR msg_type, unsigned char *data)
1062{
1063 writeb(PROTOCOL_VER | msg_type, &ptx->mac.frame_ctl_1);
1064/*** IEEE 802.11 Address field assignments *************
1065 TODS FROMDS addr_1 addr_2 addr_3 addr_4
1066Adhoc 0 0 dest src (terminal) BSSID N/A
1067AP to Terminal 0 1 dest AP(BSSID) source N/A
1068Terminal to AP 1 0 AP(BSSID) src (terminal) dest N/A
1069AP to AP 1 1 dest AP src AP dest source
1070*******************************************************/
1071 if (local->net_type == ADHOC) {
1072 writeb(0, &ptx->mac.frame_ctl_2);
1073 memcpy_toio(ptx->mac.addr_1, ((struct ethhdr *)data)->h_dest,
1074 2 * ADDRLEN);
1075 memcpy_toio(ptx->mac.addr_3, local->bss_id, ADDRLEN);
1076 } else { /* infrastructure */
1077
1078 if (local->sparm.b4.a_acting_as_ap_status) {
1079 writeb(FC2_FROM_DS, &ptx->mac.frame_ctl_2);
1080 memcpy_toio(ptx->mac.addr_1,
1081 ((struct ethhdr *)data)->h_dest, ADDRLEN);
1082 memcpy_toio(ptx->mac.addr_2, local->bss_id, 6);
1083 memcpy_toio(ptx->mac.addr_3,
1084 ((struct ethhdr *)data)->h_source, ADDRLEN);
1085 } else { /* Terminal */
1086
1087 writeb(FC2_TO_DS, &ptx->mac.frame_ctl_2);
1088 memcpy_toio(ptx->mac.addr_1, local->bss_id, ADDRLEN);
1089 memcpy_toio(ptx->mac.addr_2,
1090 ((struct ethhdr *)data)->h_source, ADDRLEN);
1091 memcpy_toio(ptx->mac.addr_3,
1092 ((struct ethhdr *)data)->h_dest, ADDRLEN);
1093 }
1094 }
1095} /* end encapsulate_frame */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001096
1097/*===========================================================================*/
1098
1099static void netdev_get_drvinfo(struct net_device *dev,
1100 struct ethtool_drvinfo *info)
1101{
1102 strcpy(info->driver, "ray_cs");
1103}
1104
Jeff Garzik7282d492006-09-13 14:30:00 -04001105static const struct ethtool_ops netdev_ethtool_ops = {
John Daiker141fa612009-03-10 06:59:54 -07001106 .get_drvinfo = netdev_get_drvinfo,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001107};
1108
1109/*====================================================================*/
1110
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001111/*------------------------------------------------------------------*/
1112/*
1113 * Wireless Handler : get protocol name
1114 */
Joe Perches43ead782010-03-18 18:29:40 -07001115static int ray_get_name(struct net_device *dev, struct iw_request_info *info,
1116 union iwreq_data *wrqu, char *extra)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001117{
Joe Perches43ead782010-03-18 18:29:40 -07001118 strcpy(wrqu->name, "IEEE 802.11-FH");
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001119 return 0;
1120}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001121
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001122/*------------------------------------------------------------------*/
1123/*
1124 * Wireless Handler : set frequency
1125 */
Joe Perches43ead782010-03-18 18:29:40 -07001126static int ray_set_freq(struct net_device *dev, struct iw_request_info *info,
1127 union iwreq_data *wrqu, char *extra)
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001128{
Yoann Padioleau6dbc9c82007-08-03 19:37:16 +02001129 ray_dev_t *local = netdev_priv(dev);
John Daiker141fa612009-03-10 06:59:54 -07001130 int err = -EINPROGRESS; /* Call commit handler */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001131
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001132 /* Reject if card is already initialised */
John Daiker141fa612009-03-10 06:59:54 -07001133 if (local->card_status != CARD_AWAITING_PARAM)
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001134 return -EBUSY;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001135
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001136 /* Setting by channel number */
Joe Perches43ead782010-03-18 18:29:40 -07001137 if ((wrqu->freq.m > USA_HOP_MOD) || (wrqu->freq.e > 0))
Linus Torvalds1da177e2005-04-16 15:20:36 -07001138 err = -EOPNOTSUPP;
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001139 else
Joe Perches43ead782010-03-18 18:29:40 -07001140 local->sparm.b5.a_hop_pattern = wrqu->freq.m;
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001141
1142 return err;
1143}
John Daiker141fa612009-03-10 06:59:54 -07001144
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001145/*------------------------------------------------------------------*/
1146/*
1147 * Wireless Handler : get frequency
1148 */
Joe Perches43ead782010-03-18 18:29:40 -07001149static int ray_get_freq(struct net_device *dev, struct iw_request_info *info,
1150 union iwreq_data *wrqu, char *extra)
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001151{
Yoann Padioleau6dbc9c82007-08-03 19:37:16 +02001152 ray_dev_t *local = netdev_priv(dev);
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001153
Joe Perches43ead782010-03-18 18:29:40 -07001154 wrqu->freq.m = local->sparm.b5.a_hop_pattern;
1155 wrqu->freq.e = 0;
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001156 return 0;
1157}
1158
1159/*------------------------------------------------------------------*/
1160/*
1161 * Wireless Handler : set ESSID
1162 */
Joe Perches43ead782010-03-18 18:29:40 -07001163static int ray_set_essid(struct net_device *dev, struct iw_request_info *info,
1164 union iwreq_data *wrqu, char *extra)
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001165{
Yoann Padioleau6dbc9c82007-08-03 19:37:16 +02001166 ray_dev_t *local = netdev_priv(dev);
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001167
1168 /* Reject if card is already initialised */
John Daiker141fa612009-03-10 06:59:54 -07001169 if (local->card_status != CARD_AWAITING_PARAM)
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001170 return -EBUSY;
1171
1172 /* Check if we asked for `any' */
Joe Perches43ead782010-03-18 18:29:40 -07001173 if (wrqu->essid.flags == 0)
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001174 /* Corey : can you do that ? */
1175 return -EOPNOTSUPP;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001176
Joe Perches43ead782010-03-18 18:29:40 -07001177 /* Check the size of the string */
1178 if (wrqu->essid.length > IW_ESSID_MAX_SIZE)
1179 return -E2BIG;
1180
1181 /* Set the ESSID in the card */
1182 memset(local->sparm.b5.a_current_ess_id, 0, IW_ESSID_MAX_SIZE);
1183 memcpy(local->sparm.b5.a_current_ess_id, extra, wrqu->essid.length);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001184
John Daiker141fa612009-03-10 06:59:54 -07001185 return -EINPROGRESS; /* Call commit handler */
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001186}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001187
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001188/*------------------------------------------------------------------*/
1189/*
1190 * Wireless Handler : get ESSID
1191 */
Joe Perches43ead782010-03-18 18:29:40 -07001192static int ray_get_essid(struct net_device *dev, struct iw_request_info *info,
1193 union iwreq_data *wrqu, char *extra)
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001194{
Yoann Padioleau6dbc9c82007-08-03 19:37:16 +02001195 ray_dev_t *local = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001196
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001197 /* Get the essid that was set */
1198 memcpy(extra, local->sparm.b5.a_current_ess_id, IW_ESSID_MAX_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001199
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001200 /* Push it out ! */
Joe Perches43ead782010-03-18 18:29:40 -07001201 wrqu->essid.length = strlen(extra);
1202 wrqu->essid.flags = 1; /* active */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001203
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001204 return 0;
1205}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001206
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001207/*------------------------------------------------------------------*/
1208/*
1209 * Wireless Handler : get AP address
1210 */
Joe Perches43ead782010-03-18 18:29:40 -07001211static int ray_get_wap(struct net_device *dev, struct iw_request_info *info,
1212 union iwreq_data *wrqu, char *extra)
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001213{
Yoann Padioleau6dbc9c82007-08-03 19:37:16 +02001214 ray_dev_t *local = netdev_priv(dev);
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001215
Joe Perches43ead782010-03-18 18:29:40 -07001216 memcpy(wrqu->ap_addr.sa_data, local->bss_id, ETH_ALEN);
1217 wrqu->ap_addr.sa_family = ARPHRD_ETHER;
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001218
1219 return 0;
1220}
1221
1222/*------------------------------------------------------------------*/
1223/*
1224 * Wireless Handler : set Bit-Rate
1225 */
Joe Perches43ead782010-03-18 18:29:40 -07001226static int ray_set_rate(struct net_device *dev, struct iw_request_info *info,
1227 union iwreq_data *wrqu, char *extra)
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001228{
Yoann Padioleau6dbc9c82007-08-03 19:37:16 +02001229 ray_dev_t *local = netdev_priv(dev);
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001230
1231 /* Reject if card is already initialised */
John Daiker141fa612009-03-10 06:59:54 -07001232 if (local->card_status != CARD_AWAITING_PARAM)
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001233 return -EBUSY;
1234
1235 /* Check if rate is in range */
Joe Perches43ead782010-03-18 18:29:40 -07001236 if ((wrqu->bitrate.value != 1000000) && (wrqu->bitrate.value != 2000000))
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001237 return -EINVAL;
1238
1239 /* Hack for 1.5 Mb/s instead of 2 Mb/s */
John Daiker141fa612009-03-10 06:59:54 -07001240 if ((local->fw_ver == 0x55) && /* Please check */
Joe Perches43ead782010-03-18 18:29:40 -07001241 (wrqu->bitrate.value == 2000000))
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001242 local->net_default_tx_rate = 3;
1243 else
Joe Perches43ead782010-03-18 18:29:40 -07001244 local->net_default_tx_rate = wrqu->bitrate.value / 500000;
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001245
1246 return 0;
1247}
1248
1249/*------------------------------------------------------------------*/
1250/*
1251 * Wireless Handler : get Bit-Rate
1252 */
Joe Perches43ead782010-03-18 18:29:40 -07001253static int ray_get_rate(struct net_device *dev, struct iw_request_info *info,
1254 union iwreq_data *wrqu, char *extra)
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001255{
Yoann Padioleau6dbc9c82007-08-03 19:37:16 +02001256 ray_dev_t *local = netdev_priv(dev);
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001257
John Daiker141fa612009-03-10 06:59:54 -07001258 if (local->net_default_tx_rate == 3)
Joe Perches43ead782010-03-18 18:29:40 -07001259 wrqu->bitrate.value = 2000000; /* Hum... */
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001260 else
Joe Perches43ead782010-03-18 18:29:40 -07001261 wrqu->bitrate.value = local->net_default_tx_rate * 500000;
1262 wrqu->bitrate.fixed = 0; /* We are in auto mode */
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001263
1264 return 0;
1265}
1266
1267/*------------------------------------------------------------------*/
1268/*
1269 * Wireless Handler : set RTS threshold
1270 */
Joe Perches43ead782010-03-18 18:29:40 -07001271static int ray_set_rts(struct net_device *dev, struct iw_request_info *info,
1272 union iwreq_data *wrqu, char *extra)
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001273{
Yoann Padioleau6dbc9c82007-08-03 19:37:16 +02001274 ray_dev_t *local = netdev_priv(dev);
Joe Perches43ead782010-03-18 18:29:40 -07001275 int rthr = wrqu->rts.value;
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001276
1277 /* Reject if card is already initialised */
John Daiker141fa612009-03-10 06:59:54 -07001278 if (local->card_status != CARD_AWAITING_PARAM)
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001279 return -EBUSY;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001280
1281 /* if(wrq->u.rts.fixed == 0) we should complain */
Joe Perches43ead782010-03-18 18:29:40 -07001282 if (wrqu->rts.disabled)
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001283 rthr = 32767;
1284 else {
John Daiker141fa612009-03-10 06:59:54 -07001285 if ((rthr < 0) || (rthr > 2347)) /* What's the max packet size ??? */
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001286 return -EINVAL;
1287 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001288 local->sparm.b5.a_rts_threshold[0] = (rthr >> 8) & 0xFF;
1289 local->sparm.b5.a_rts_threshold[1] = rthr & 0xFF;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001290
John Daiker141fa612009-03-10 06:59:54 -07001291 return -EINPROGRESS; /* Call commit handler */
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001292}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001293
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001294/*------------------------------------------------------------------*/
1295/*
1296 * Wireless Handler : get RTS threshold
1297 */
Joe Perches43ead782010-03-18 18:29:40 -07001298static int ray_get_rts(struct net_device *dev, struct iw_request_info *info,
1299 union iwreq_data *wrqu, char *extra)
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001300{
Yoann Padioleau6dbc9c82007-08-03 19:37:16 +02001301 ray_dev_t *local = netdev_priv(dev);
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001302
Joe Perches43ead782010-03-18 18:29:40 -07001303 wrqu->rts.value = (local->sparm.b5.a_rts_threshold[0] << 8)
John Daiker141fa612009-03-10 06:59:54 -07001304 + local->sparm.b5.a_rts_threshold[1];
Joe Perches43ead782010-03-18 18:29:40 -07001305 wrqu->rts.disabled = (wrqu->rts.value == 32767);
1306 wrqu->rts.fixed = 1;
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001307
1308 return 0;
1309}
1310
1311/*------------------------------------------------------------------*/
1312/*
1313 * Wireless Handler : set Fragmentation threshold
1314 */
Joe Perches43ead782010-03-18 18:29:40 -07001315static int ray_set_frag(struct net_device *dev, struct iw_request_info *info,
1316 union iwreq_data *wrqu, char *extra)
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001317{
Yoann Padioleau6dbc9c82007-08-03 19:37:16 +02001318 ray_dev_t *local = netdev_priv(dev);
Joe Perches43ead782010-03-18 18:29:40 -07001319 int fthr = wrqu->frag.value;
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001320
1321 /* Reject if card is already initialised */
John Daiker141fa612009-03-10 06:59:54 -07001322 if (local->card_status != CARD_AWAITING_PARAM)
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001323 return -EBUSY;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001324
1325 /* if(wrq->u.frag.fixed == 0) should complain */
Joe Perches43ead782010-03-18 18:29:40 -07001326 if (wrqu->frag.disabled)
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001327 fthr = 32767;
1328 else {
John Daiker141fa612009-03-10 06:59:54 -07001329 if ((fthr < 256) || (fthr > 2347)) /* To check out ! */
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001330 return -EINVAL;
1331 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001332 local->sparm.b5.a_frag_threshold[0] = (fthr >> 8) & 0xFF;
1333 local->sparm.b5.a_frag_threshold[1] = fthr & 0xFF;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001334
John Daiker141fa612009-03-10 06:59:54 -07001335 return -EINPROGRESS; /* Call commit handler */
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001336}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001337
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001338/*------------------------------------------------------------------*/
1339/*
1340 * Wireless Handler : get Fragmentation threshold
1341 */
Joe Perches43ead782010-03-18 18:29:40 -07001342static int ray_get_frag(struct net_device *dev, struct iw_request_info *info,
1343 union iwreq_data *wrqu, char *extra)
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001344{
Yoann Padioleau6dbc9c82007-08-03 19:37:16 +02001345 ray_dev_t *local = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001346
Joe Perches43ead782010-03-18 18:29:40 -07001347 wrqu->frag.value = (local->sparm.b5.a_frag_threshold[0] << 8)
John Daiker141fa612009-03-10 06:59:54 -07001348 + local->sparm.b5.a_frag_threshold[1];
Joe Perches43ead782010-03-18 18:29:40 -07001349 wrqu->frag.disabled = (wrqu->frag.value == 32767);
1350 wrqu->frag.fixed = 1;
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001351
1352 return 0;
1353}
1354
1355/*------------------------------------------------------------------*/
1356/*
1357 * Wireless Handler : set Mode of Operation
1358 */
Joe Perches43ead782010-03-18 18:29:40 -07001359static int ray_set_mode(struct net_device *dev, struct iw_request_info *info,
1360 union iwreq_data *wrqu, char *extra)
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001361{
Yoann Padioleau6dbc9c82007-08-03 19:37:16 +02001362 ray_dev_t *local = netdev_priv(dev);
John Daiker141fa612009-03-10 06:59:54 -07001363 int err = -EINPROGRESS; /* Call commit handler */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001364 char card_mode = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001365
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001366 /* Reject if card is already initialised */
John Daiker141fa612009-03-10 06:59:54 -07001367 if (local->card_status != CARD_AWAITING_PARAM)
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001368 return -EBUSY;
1369
Joe Perches43ead782010-03-18 18:29:40 -07001370 switch (wrqu->mode) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001371 case IW_MODE_ADHOC:
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001372 card_mode = 0;
John Daiker141fa612009-03-10 06:59:54 -07001373 /* Fall through */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001374 case IW_MODE_INFRA:
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001375 local->sparm.b5.a_network_type = card_mode;
1376 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001377 default:
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001378 err = -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001379 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001380
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001381 return err;
1382}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001383
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001384/*------------------------------------------------------------------*/
1385/*
1386 * Wireless Handler : get Mode of Operation
1387 */
Joe Perches43ead782010-03-18 18:29:40 -07001388static int ray_get_mode(struct net_device *dev, struct iw_request_info *info,
1389 union iwreq_data *wrqu, char *extra)
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001390{
Yoann Padioleau6dbc9c82007-08-03 19:37:16 +02001391 ray_dev_t *local = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001392
John Daiker141fa612009-03-10 06:59:54 -07001393 if (local->sparm.b5.a_network_type)
Joe Perches43ead782010-03-18 18:29:40 -07001394 wrqu->mode = IW_MODE_INFRA;
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001395 else
Joe Perches43ead782010-03-18 18:29:40 -07001396 wrqu->mode = IW_MODE_ADHOC;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001397
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001398 return 0;
1399}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001400
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001401/*------------------------------------------------------------------*/
1402/*
1403 * Wireless Handler : get range info
1404 */
Joe Perches43ead782010-03-18 18:29:40 -07001405static int ray_get_range(struct net_device *dev, struct iw_request_info *info,
1406 union iwreq_data *wrqu, char *extra)
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001407{
John Daiker141fa612009-03-10 06:59:54 -07001408 struct iw_range *range = (struct iw_range *)extra;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001409
Joe Perches43ead782010-03-18 18:29:40 -07001410 memset(range, 0, sizeof(struct iw_range));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001411
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001412 /* Set the length (very important for backward compatibility) */
Joe Perches43ead782010-03-18 18:29:40 -07001413 wrqu->data.length = sizeof(struct iw_range);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001414
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001415 /* Set the Wireless Extension versions */
1416 range->we_version_compiled = WIRELESS_EXT;
1417 range->we_version_source = 9;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001418
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001419 /* Set information in the range struct */
1420 range->throughput = 1.1 * 1000 * 1000; /* Put the right number here */
John Daiker141fa612009-03-10 06:59:54 -07001421 range->num_channels = hop_pattern_length[(int)country];
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001422 range->num_frequency = 0;
1423 range->max_qual.qual = 0;
1424 range->max_qual.level = 255; /* What's the correct value ? */
1425 range->max_qual.noise = 255; /* Idem */
1426 range->num_bitrates = 2;
1427 range->bitrate[0] = 1000000; /* 1 Mb/s */
1428 range->bitrate[1] = 2000000; /* 2 Mb/s */
1429 return 0;
1430}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001431
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001432/*------------------------------------------------------------------*/
1433/*
1434 * Wireless Private Handler : set framing mode
1435 */
Joe Perches43ead782010-03-18 18:29:40 -07001436static int ray_set_framing(struct net_device *dev, struct iw_request_info *info,
John Daiker141fa612009-03-10 06:59:54 -07001437 union iwreq_data *wrqu, char *extra)
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001438{
1439 translate = *(extra); /* Set framing mode */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001440
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001441 return 0;
1442}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001443
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001444/*------------------------------------------------------------------*/
1445/*
1446 * Wireless Private Handler : get framing mode
1447 */
Joe Perches43ead782010-03-18 18:29:40 -07001448static int ray_get_framing(struct net_device *dev, struct iw_request_info *info,
John Daiker141fa612009-03-10 06:59:54 -07001449 union iwreq_data *wrqu, char *extra)
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001450{
1451 *(extra) = translate;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001452
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001453 return 0;
1454}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001455
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001456/*------------------------------------------------------------------*/
1457/*
1458 * Wireless Private Handler : get country
1459 */
Joe Perches43ead782010-03-18 18:29:40 -07001460static int ray_get_country(struct net_device *dev, 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) = country;
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 * Commit handler : called after a bunch of SET operations
1471 */
Joe Perches43ead782010-03-18 18:29:40 -07001472static int ray_commit(struct net_device *dev, struct iw_request_info *info,
1473 union iwreq_data *wrqu, char *extra)
1474{
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001475 return 0;
1476}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001477
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001478/*------------------------------------------------------------------*/
1479/*
1480 * Stats handler : return Wireless Stats
1481 */
John Daiker141fa612009-03-10 06:59:54 -07001482static iw_stats *ray_get_wireless_stats(struct net_device *dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001483{
John Daiker141fa612009-03-10 06:59:54 -07001484 ray_dev_t *local = netdev_priv(dev);
1485 struct pcmcia_device *link = local->finder;
1486 struct status __iomem *p = local->sram + STATUS_BASE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001487
John Daiker141fa612009-03-10 06:59:54 -07001488 local->wstats.status = local->card_status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001489#ifdef WIRELESS_SPY
John Daiker141fa612009-03-10 06:59:54 -07001490 if ((local->spy_data.spy_number > 0)
1491 && (local->sparm.b5.a_network_type == 0)) {
1492 /* Get it from the first node in spy list */
1493 local->wstats.qual.qual = local->spy_data.spy_stat[0].qual;
1494 local->wstats.qual.level = local->spy_data.spy_stat[0].level;
1495 local->wstats.qual.noise = local->spy_data.spy_stat[0].noise;
1496 local->wstats.qual.updated =
1497 local->spy_data.spy_stat[0].updated;
1498 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001499#endif /* WIRELESS_SPY */
1500
John Daiker141fa612009-03-10 06:59:54 -07001501 if (pcmcia_dev_present(link)) {
1502 local->wstats.qual.noise = readb(&p->rxnoise);
1503 local->wstats.qual.updated |= 4;
1504 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001505
John Daiker141fa612009-03-10 06:59:54 -07001506 return &local->wstats;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001507} /* end ray_get_wireless_stats */
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001508
1509/*------------------------------------------------------------------*/
1510/*
1511 * Structures to export the Wireless Handlers
1512 */
1513
John Daiker141fa612009-03-10 06:59:54 -07001514static const iw_handler ray_handler[] = {
Joe Perches43ead782010-03-18 18:29:40 -07001515 IW_HANDLER(SIOCSIWCOMMIT, ray_commit),
1516 IW_HANDLER(SIOCGIWNAME, ray_get_name),
1517 IW_HANDLER(SIOCSIWFREQ, ray_set_freq),
1518 IW_HANDLER(SIOCGIWFREQ, ray_get_freq),
1519 IW_HANDLER(SIOCSIWMODE, ray_set_mode),
1520 IW_HANDLER(SIOCGIWMODE, ray_get_mode),
1521 IW_HANDLER(SIOCGIWRANGE, ray_get_range),
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001522#ifdef WIRELESS_SPY
Joe Perches270020e2010-03-18 18:29:37 -07001523 IW_HANDLER(SIOCSIWSPY, iw_handler_set_spy),
1524 IW_HANDLER(SIOCGIWSPY, iw_handler_get_spy),
1525 IW_HANDLER(SIOCSIWTHRSPY, iw_handler_set_thrspy),
1526 IW_HANDLER(SIOCGIWTHRSPY, iw_handler_get_thrspy),
John Daiker141fa612009-03-10 06:59:54 -07001527#endif /* WIRELESS_SPY */
Joe Perches43ead782010-03-18 18:29:40 -07001528 IW_HANDLER(SIOCGIWAP, ray_get_wap),
1529 IW_HANDLER(SIOCSIWESSID, ray_set_essid),
1530 IW_HANDLER(SIOCGIWESSID, ray_get_essid),
1531 IW_HANDLER(SIOCSIWRATE, ray_set_rate),
1532 IW_HANDLER(SIOCGIWRATE, ray_get_rate),
1533 IW_HANDLER(SIOCSIWRTS, ray_set_rts),
1534 IW_HANDLER(SIOCGIWRTS, ray_get_rts),
1535 IW_HANDLER(SIOCSIWFRAG, ray_set_frag),
1536 IW_HANDLER(SIOCGIWFRAG, ray_get_frag),
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001537};
1538
John Daiker141fa612009-03-10 06:59:54 -07001539#define SIOCSIPFRAMING SIOCIWFIRSTPRIV /* Set framing mode */
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001540#define SIOCGIPFRAMING SIOCIWFIRSTPRIV + 1 /* Get framing mode */
1541#define SIOCGIPCOUNTRY SIOCIWFIRSTPRIV + 3 /* Get country code */
1542
John Daiker141fa612009-03-10 06:59:54 -07001543static const iw_handler ray_private_handler[] = {
Joe Perches43ead782010-03-18 18:29:40 -07001544 [0] = ray_set_framing,
1545 [1] = ray_get_framing,
1546 [3] = ray_get_country,
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001547};
1548
John Daiker141fa612009-03-10 06:59:54 -07001549static const struct iw_priv_args ray_private_args[] = {
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001550/* cmd, set_args, get_args, name */
John Daiker141fa612009-03-10 06:59:54 -07001551 {SIOCSIPFRAMING, IW_PRIV_TYPE_BYTE | IW_PRIV_SIZE_FIXED | 1, 0,
1552 "set_framing"},
1553 {SIOCGIPFRAMING, 0, IW_PRIV_TYPE_BYTE | IW_PRIV_SIZE_FIXED | 1,
1554 "get_framing"},
1555 {SIOCGIPCOUNTRY, 0, IW_PRIV_TYPE_BYTE | IW_PRIV_SIZE_FIXED | 1,
1556 "get_country"},
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001557};
1558
John Daiker141fa612009-03-10 06:59:54 -07001559static const struct iw_handler_def ray_handler_def = {
1560 .num_standard = ARRAY_SIZE(ray_handler),
1561 .num_private = ARRAY_SIZE(ray_private_handler),
Denis Chengff8ac602007-09-02 18:30:18 +08001562 .num_private_args = ARRAY_SIZE(ray_private_args),
John Daiker141fa612009-03-10 06:59:54 -07001563 .standard = ray_handler,
1564 .private = ray_private_handler,
1565 .private_args = ray_private_args,
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001566 .get_wireless_stats = ray_get_wireless_stats,
1567};
1568
Linus Torvalds1da177e2005-04-16 15:20:36 -07001569/*===========================================================================*/
1570static int ray_open(struct net_device *dev)
1571{
John Daiker141fa612009-03-10 06:59:54 -07001572 ray_dev_t *local = netdev_priv(dev);
1573 struct pcmcia_device *link;
1574 link = local->finder;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001575
Dominik Brodowski624dd662009-10-24 15:52:44 +02001576 dev_dbg(&link->dev, "ray_open('%s')\n", dev->name);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001577
John Daiker141fa612009-03-10 06:59:54 -07001578 if (link->open == 0)
1579 local->num_multi = 0;
1580 link->open++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001581
John Daiker141fa612009-03-10 06:59:54 -07001582 /* If the card is not started, time to start it ! - Jean II */
1583 if (local->card_status == CARD_AWAITING_PARAM) {
1584 int i;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001585
Dominik Brodowski624dd662009-10-24 15:52:44 +02001586 dev_dbg(&link->dev, "ray_open: doing init now !\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001587
John Daiker141fa612009-03-10 06:59:54 -07001588 /* Download startup parameters */
1589 if ((i = dl_startup_params(dev)) < 0) {
1590 printk(KERN_INFO
1591 "ray_dev_init dl_startup_params failed - "
1592 "returns 0x%x\n", i);
1593 return -1;
1594 }
1595 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001596
John Daiker141fa612009-03-10 06:59:54 -07001597 if (sniffer)
1598 netif_stop_queue(dev);
1599 else
1600 netif_start_queue(dev);
1601
Dominik Brodowski624dd662009-10-24 15:52:44 +02001602 dev_dbg(&link->dev, "ray_open ending\n");
John Daiker141fa612009-03-10 06:59:54 -07001603 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001604} /* end ray_open */
John Daiker141fa612009-03-10 06:59:54 -07001605
Linus Torvalds1da177e2005-04-16 15:20:36 -07001606/*===========================================================================*/
1607static int ray_dev_close(struct net_device *dev)
1608{
John Daiker141fa612009-03-10 06:59:54 -07001609 ray_dev_t *local = netdev_priv(dev);
1610 struct pcmcia_device *link;
1611 link = local->finder;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001612
Dominik Brodowski624dd662009-10-24 15:52:44 +02001613 dev_dbg(&link->dev, "ray_dev_close('%s')\n", dev->name);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001614
John Daiker141fa612009-03-10 06:59:54 -07001615 link->open--;
1616 netif_stop_queue(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001617
John Daiker141fa612009-03-10 06:59:54 -07001618 /* In here, we should stop the hardware (stop card from beeing active)
1619 * and set local->card_status to CARD_AWAITING_PARAM, so that while the
1620 * card is closed we can chage its configuration.
1621 * Probably also need a COR reset to get sane state - Jean II */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001622
John Daiker141fa612009-03-10 06:59:54 -07001623 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001624} /* end ray_dev_close */
John Daiker141fa612009-03-10 06:59:54 -07001625
Linus Torvalds1da177e2005-04-16 15:20:36 -07001626/*===========================================================================*/
John Daiker141fa612009-03-10 06:59:54 -07001627static void ray_reset(struct net_device *dev)
1628{
Dominik Brodowski624dd662009-10-24 15:52:44 +02001629 pr_debug("ray_reset entered\n");
John Daiker141fa612009-03-10 06:59:54 -07001630 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001631}
John Daiker141fa612009-03-10 06:59:54 -07001632
Linus Torvalds1da177e2005-04-16 15:20:36 -07001633/*===========================================================================*/
1634/* Cause a firmware interrupt if it is ready for one */
1635/* Return nonzero if not ready */
1636static int interrupt_ecf(ray_dev_t *local, int ccs)
1637{
John Daiker141fa612009-03-10 06:59:54 -07001638 int i = 50;
1639 struct pcmcia_device *link = local->finder;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001640
John Daiker141fa612009-03-10 06:59:54 -07001641 if (!(pcmcia_dev_present(link))) {
Dominik Brodowski624dd662009-10-24 15:52:44 +02001642 dev_dbg(&link->dev, "ray_cs interrupt_ecf - device not present\n");
John Daiker141fa612009-03-10 06:59:54 -07001643 return -1;
1644 }
Dominik Brodowski624dd662009-10-24 15:52:44 +02001645 dev_dbg(&link->dev, "interrupt_ecf(local=%p, ccs = 0x%x\n", local, ccs);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001646
John Daiker141fa612009-03-10 06:59:54 -07001647 while (i &&
1648 (readb(local->amem + CIS_OFFSET + ECF_INTR_OFFSET) &
1649 ECF_INTR_SET))
1650 i--;
1651 if (i == 0) {
Dominik Brodowski624dd662009-10-24 15:52:44 +02001652 dev_dbg(&link->dev, "ray_cs interrupt_ecf card not ready for interrupt\n");
John Daiker141fa612009-03-10 06:59:54 -07001653 return -1;
1654 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001655 /* Fill the mailbox, then kick the card */
John Daiker141fa612009-03-10 06:59:54 -07001656 writeb(ccs, local->sram + SCB_BASE);
1657 writeb(ECF_INTR_SET, local->amem + CIS_OFFSET + ECF_INTR_OFFSET);
1658 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001659} /* interrupt_ecf */
John Daiker141fa612009-03-10 06:59:54 -07001660
Linus Torvalds1da177e2005-04-16 15:20:36 -07001661/*===========================================================================*/
1662/* Get next free transmit CCS */
1663/* Return - index of current tx ccs */
1664static int get_free_tx_ccs(ray_dev_t *local)
1665{
John Daiker141fa612009-03-10 06:59:54 -07001666 int i;
1667 struct ccs __iomem *pccs = ccs_base(local);
1668 struct pcmcia_device *link = local->finder;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001669
John Daiker141fa612009-03-10 06:59:54 -07001670 if (!(pcmcia_dev_present(link))) {
Dominik Brodowski624dd662009-10-24 15:52:44 +02001671 dev_dbg(&link->dev, "ray_cs get_free_tx_ccs - device not present\n");
John Daiker141fa612009-03-10 06:59:54 -07001672 return ECARDGONE;
1673 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001674
John Daiker141fa612009-03-10 06:59:54 -07001675 if (test_and_set_bit(0, &local->tx_ccs_lock)) {
Dominik Brodowski624dd662009-10-24 15:52:44 +02001676 dev_dbg(&link->dev, "ray_cs tx_ccs_lock busy\n");
John Daiker141fa612009-03-10 06:59:54 -07001677 return ECCSBUSY;
1678 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001679
John Daiker141fa612009-03-10 06:59:54 -07001680 for (i = 0; i < NUMBER_OF_TX_CCS; i++) {
1681 if (readb(&(pccs + i)->buffer_status) == CCS_BUFFER_FREE) {
1682 writeb(CCS_BUFFER_BUSY, &(pccs + i)->buffer_status);
1683 writeb(CCS_END_LIST, &(pccs + i)->link);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001684 local->tx_ccs_lock = 0;
John Daiker141fa612009-03-10 06:59:54 -07001685 return i;
1686 }
1687 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001688 local->tx_ccs_lock = 0;
Dominik Brodowski624dd662009-10-24 15:52:44 +02001689 dev_dbg(&link->dev, "ray_cs ERROR no free tx CCS for raylink card\n");
John Daiker141fa612009-03-10 06:59:54 -07001690 return ECCSFULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001691} /* get_free_tx_ccs */
John Daiker141fa612009-03-10 06:59:54 -07001692
Linus Torvalds1da177e2005-04-16 15:20:36 -07001693/*===========================================================================*/
1694/* Get next free CCS */
1695/* Return - index of current ccs */
1696static int get_free_ccs(ray_dev_t *local)
1697{
John Daiker141fa612009-03-10 06:59:54 -07001698 int i;
1699 struct ccs __iomem *pccs = ccs_base(local);
1700 struct pcmcia_device *link = local->finder;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001701
John Daiker141fa612009-03-10 06:59:54 -07001702 if (!(pcmcia_dev_present(link))) {
Dominik Brodowski624dd662009-10-24 15:52:44 +02001703 dev_dbg(&link->dev, "ray_cs get_free_ccs - device not present\n");
John Daiker141fa612009-03-10 06:59:54 -07001704 return ECARDGONE;
1705 }
1706 if (test_and_set_bit(0, &local->ccs_lock)) {
Dominik Brodowski624dd662009-10-24 15:52:44 +02001707 dev_dbg(&link->dev, "ray_cs ccs_lock busy\n");
John Daiker141fa612009-03-10 06:59:54 -07001708 return ECCSBUSY;
1709 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001710
John Daiker141fa612009-03-10 06:59:54 -07001711 for (i = NUMBER_OF_TX_CCS; i < NUMBER_OF_CCS; i++) {
1712 if (readb(&(pccs + i)->buffer_status) == CCS_BUFFER_FREE) {
1713 writeb(CCS_BUFFER_BUSY, &(pccs + i)->buffer_status);
1714 writeb(CCS_END_LIST, &(pccs + i)->link);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001715 local->ccs_lock = 0;
John Daiker141fa612009-03-10 06:59:54 -07001716 return i;
1717 }
1718 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001719 local->ccs_lock = 0;
Dominik Brodowski624dd662009-10-24 15:52:44 +02001720 dev_dbg(&link->dev, "ray_cs ERROR no free CCS for raylink card\n");
John Daiker141fa612009-03-10 06:59:54 -07001721 return ECCSFULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001722} /* get_free_ccs */
John Daiker141fa612009-03-10 06:59:54 -07001723
Linus Torvalds1da177e2005-04-16 15:20:36 -07001724/*===========================================================================*/
1725static void authenticate_timeout(u_long data)
1726{
John Daiker141fa612009-03-10 06:59:54 -07001727 ray_dev_t *local = (ray_dev_t *) data;
1728 del_timer(&local->timer);
1729 printk(KERN_INFO "ray_cs Authentication with access point failed"
1730 " - timeout\n");
1731 join_net((u_long) local);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001732}
John Daiker141fa612009-03-10 06:59:54 -07001733
Linus Torvalds1da177e2005-04-16 15:20:36 -07001734/*===========================================================================*/
1735static int asc_to_int(char a)
1736{
John Daiker141fa612009-03-10 06:59:54 -07001737 if (a < '0')
1738 return -1;
1739 if (a <= '9')
1740 return (a - '0');
1741 if (a < 'A')
1742 return -1;
1743 if (a <= 'F')
1744 return (10 + a - 'A');
1745 if (a < 'a')
1746 return -1;
1747 if (a <= 'f')
1748 return (10 + a - 'a');
1749 return -1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001750}
John Daiker141fa612009-03-10 06:59:54 -07001751
Linus Torvalds1da177e2005-04-16 15:20:36 -07001752/*===========================================================================*/
1753static int parse_addr(char *in_str, UCHAR *out)
1754{
John Daiker141fa612009-03-10 06:59:54 -07001755 int len;
1756 int i, j, k;
1757 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001758
John Daiker141fa612009-03-10 06:59:54 -07001759 if (in_str == NULL)
1760 return 0;
1761 if ((len = strlen(in_str)) < 2)
1762 return 0;
1763 memset(out, 0, ADDRLEN);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001764
John Daiker141fa612009-03-10 06:59:54 -07001765 status = 1;
1766 j = len - 1;
1767 if (j > 12)
1768 j = 12;
1769 i = 5;
1770
1771 while (j > 0) {
1772 if ((k = asc_to_int(in_str[j--])) != -1)
1773 out[i] = k;
1774 else
1775 return 0;
1776
1777 if (j == 0)
1778 break;
1779 if ((k = asc_to_int(in_str[j--])) != -1)
1780 out[i] += k << 4;
1781 else
1782 return 0;
1783 if (!i--)
1784 break;
1785 }
1786 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001787}
John Daiker141fa612009-03-10 06:59:54 -07001788
Linus Torvalds1da177e2005-04-16 15:20:36 -07001789/*===========================================================================*/
1790static struct net_device_stats *ray_get_stats(struct net_device *dev)
1791{
John Daiker141fa612009-03-10 06:59:54 -07001792 ray_dev_t *local = netdev_priv(dev);
1793 struct pcmcia_device *link = local->finder;
1794 struct status __iomem *p = local->sram + STATUS_BASE;
1795 if (!(pcmcia_dev_present(link))) {
Dominik Brodowski624dd662009-10-24 15:52:44 +02001796 dev_dbg(&link->dev, "ray_cs net_device_stats - device not present\n");
John Daiker141fa612009-03-10 06:59:54 -07001797 return &local->stats;
1798 }
1799 if (readb(&p->mrx_overflow_for_host)) {
1800 local->stats.rx_over_errors += swab16(readw(&p->mrx_overflow));
1801 writeb(0, &p->mrx_overflow);
1802 writeb(0, &p->mrx_overflow_for_host);
1803 }
1804 if (readb(&p->mrx_checksum_error_for_host)) {
1805 local->stats.rx_crc_errors +=
1806 swab16(readw(&p->mrx_checksum_error));
1807 writeb(0, &p->mrx_checksum_error);
1808 writeb(0, &p->mrx_checksum_error_for_host);
1809 }
1810 if (readb(&p->rx_hec_error_for_host)) {
1811 local->stats.rx_frame_errors += swab16(readw(&p->rx_hec_error));
1812 writeb(0, &p->rx_hec_error);
1813 writeb(0, &p->rx_hec_error_for_host);
1814 }
1815 return &local->stats;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001816}
John Daiker141fa612009-03-10 06:59:54 -07001817
Linus Torvalds1da177e2005-04-16 15:20:36 -07001818/*===========================================================================*/
John Daiker141fa612009-03-10 06:59:54 -07001819static void ray_update_parm(struct net_device *dev, UCHAR objid, UCHAR *value,
1820 int len)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001821{
John Daiker141fa612009-03-10 06:59:54 -07001822 ray_dev_t *local = netdev_priv(dev);
1823 struct pcmcia_device *link = local->finder;
1824 int ccsindex;
1825 int i;
1826 struct ccs __iomem *pccs;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001827
John Daiker141fa612009-03-10 06:59:54 -07001828 if (!(pcmcia_dev_present(link))) {
Dominik Brodowski624dd662009-10-24 15:52:44 +02001829 dev_dbg(&link->dev, "ray_update_parm - device not present\n");
John Daiker141fa612009-03-10 06:59:54 -07001830 return;
1831 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001832
John Daiker141fa612009-03-10 06:59:54 -07001833 if ((ccsindex = get_free_ccs(local)) < 0) {
Dominik Brodowski624dd662009-10-24 15:52:44 +02001834 dev_dbg(&link->dev, "ray_update_parm - No free ccs\n");
John Daiker141fa612009-03-10 06:59:54 -07001835 return;
1836 }
1837 pccs = ccs_base(local) + ccsindex;
1838 writeb(CCS_UPDATE_PARAMS, &pccs->cmd);
1839 writeb(objid, &pccs->var.update_param.object_id);
1840 writeb(1, &pccs->var.update_param.number_objects);
1841 writeb(0, &pccs->var.update_param.failure_cause);
1842 for (i = 0; i < len; i++) {
1843 writeb(value[i], local->sram + HOST_TO_ECF_BASE);
1844 }
1845 /* Interrupt the firmware to process the command */
1846 if (interrupt_ecf(local, ccsindex)) {
Dominik Brodowski624dd662009-10-24 15:52:44 +02001847 dev_dbg(&link->dev, "ray_cs associate failed - ECF not ready for intr\n");
John Daiker141fa612009-03-10 06:59:54 -07001848 writeb(CCS_BUFFER_FREE, &(pccs++)->buffer_status);
1849 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001850}
John Daiker141fa612009-03-10 06:59:54 -07001851
Linus Torvalds1da177e2005-04-16 15:20:36 -07001852/*===========================================================================*/
1853static void ray_update_multi_list(struct net_device *dev, int all)
1854{
John Daiker141fa612009-03-10 06:59:54 -07001855 int ccsindex;
1856 struct ccs __iomem *pccs;
John Daiker141fa612009-03-10 06:59:54 -07001857 ray_dev_t *local = netdev_priv(dev);
1858 struct pcmcia_device *link = local->finder;
1859 void __iomem *p = local->sram + HOST_TO_ECF_BASE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001860
John Daiker141fa612009-03-10 06:59:54 -07001861 if (!(pcmcia_dev_present(link))) {
Dominik Brodowski624dd662009-10-24 15:52:44 +02001862 dev_dbg(&link->dev, "ray_update_multi_list - device not present\n");
John Daiker141fa612009-03-10 06:59:54 -07001863 return;
1864 } else
Dominik Brodowski624dd662009-10-24 15:52:44 +02001865 dev_dbg(&link->dev, "ray_update_multi_list(%p)\n", dev);
John Daiker141fa612009-03-10 06:59:54 -07001866 if ((ccsindex = get_free_ccs(local)) < 0) {
Dominik Brodowski624dd662009-10-24 15:52:44 +02001867 dev_dbg(&link->dev, "ray_update_multi - No free ccs\n");
John Daiker141fa612009-03-10 06:59:54 -07001868 return;
1869 }
1870 pccs = ccs_base(local) + ccsindex;
1871 writeb(CCS_UPDATE_MULTICAST_LIST, &pccs->cmd);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001872
John Daiker141fa612009-03-10 06:59:54 -07001873 if (all) {
1874 writeb(0xff, &pccs->var);
1875 local->num_multi = 0xff;
1876 } else {
Jiri Pirko22bedad2010-04-01 21:22:57 +00001877 struct netdev_hw_addr *ha;
Jiri Pirko655ffee2010-02-27 07:35:45 +00001878 int i = 0;
1879
John Daiker141fa612009-03-10 06:59:54 -07001880 /* Copy the kernel's list of MC addresses to card */
Jiri Pirko22bedad2010-04-01 21:22:57 +00001881 netdev_for_each_mc_addr(ha, dev) {
1882 memcpy_toio(p, ha->addr, ETH_ALEN);
Dominik Brodowski624dd662009-10-24 15:52:44 +02001883 dev_dbg(&link->dev,
John Daiker141fa612009-03-10 06:59:54 -07001884 "ray_update_multi add addr %02x%02x%02x%02x%02x%02x\n",
Jiri Pirko22bedad2010-04-01 21:22:57 +00001885 ha->addr[0], ha->addr[1],
1886 ha->addr[2], ha->addr[3],
1887 ha->addr[4], ha->addr[5]);
John Daiker141fa612009-03-10 06:59:54 -07001888 p += ETH_ALEN;
1889 i++;
1890 }
1891 if (i > 256 / ADDRLEN)
1892 i = 256 / ADDRLEN;
1893 writeb((UCHAR) i, &pccs->var);
Dominik Brodowski624dd662009-10-24 15:52:44 +02001894 dev_dbg(&link->dev, "ray_cs update_multi %d addresses in list\n", i);
John Daiker141fa612009-03-10 06:59:54 -07001895 /* Interrupt the firmware to process the command */
1896 local->num_multi = i;
1897 }
1898 if (interrupt_ecf(local, ccsindex)) {
Dominik Brodowski624dd662009-10-24 15:52:44 +02001899 dev_dbg(&link->dev,
John Daiker141fa612009-03-10 06:59:54 -07001900 "ray_cs update_multi failed - ECF not ready for intr\n");
1901 writeb(CCS_BUFFER_FREE, &(pccs++)->buffer_status);
1902 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001903} /* end ray_update_multi_list */
John Daiker141fa612009-03-10 06:59:54 -07001904
Linus Torvalds1da177e2005-04-16 15:20:36 -07001905/*===========================================================================*/
1906static void set_multicast_list(struct net_device *dev)
1907{
John Daiker141fa612009-03-10 06:59:54 -07001908 ray_dev_t *local = netdev_priv(dev);
1909 UCHAR promisc;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001910
Dominik Brodowski624dd662009-10-24 15:52:44 +02001911 pr_debug("ray_cs set_multicast_list(%p)\n", dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001912
John Daiker141fa612009-03-10 06:59:54 -07001913 if (dev->flags & IFF_PROMISC) {
1914 if (local->sparm.b5.a_promiscuous_mode == 0) {
Dominik Brodowski624dd662009-10-24 15:52:44 +02001915 pr_debug("ray_cs set_multicast_list promisc on\n");
John Daiker141fa612009-03-10 06:59:54 -07001916 local->sparm.b5.a_promiscuous_mode = 1;
1917 promisc = 1;
1918 ray_update_parm(dev, OBJID_promiscuous_mode,
1919 &promisc, sizeof(promisc));
1920 }
1921 } else {
1922 if (local->sparm.b5.a_promiscuous_mode == 1) {
Dominik Brodowski624dd662009-10-24 15:52:44 +02001923 pr_debug("ray_cs set_multicast_list promisc off\n");
John Daiker141fa612009-03-10 06:59:54 -07001924 local->sparm.b5.a_promiscuous_mode = 0;
1925 promisc = 0;
1926 ray_update_parm(dev, OBJID_promiscuous_mode,
1927 &promisc, sizeof(promisc));
1928 }
1929 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001930
John Daiker141fa612009-03-10 06:59:54 -07001931 if (dev->flags & IFF_ALLMULTI)
1932 ray_update_multi_list(dev, 1);
1933 else {
Jiri Pirko4cd24ea2010-02-08 04:30:35 +00001934 if (local->num_multi != netdev_mc_count(dev))
John Daiker141fa612009-03-10 06:59:54 -07001935 ray_update_multi_list(dev, 0);
1936 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001937} /* end set_multicast_list */
John Daiker141fa612009-03-10 06:59:54 -07001938
Linus Torvalds1da177e2005-04-16 15:20:36 -07001939/*=============================================================================
1940 * All routines below here are run at interrupt time.
1941=============================================================================*/
David Howells7d12e782006-10-05 14:55:46 +01001942static irqreturn_t ray_interrupt(int irq, void *dev_id)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001943{
John Daiker141fa612009-03-10 06:59:54 -07001944 struct net_device *dev = (struct net_device *)dev_id;
1945 struct pcmcia_device *link;
1946 ray_dev_t *local;
1947 struct ccs __iomem *pccs;
1948 struct rcs __iomem *prcs;
1949 UCHAR rcsindex;
1950 UCHAR tmp;
1951 UCHAR cmd;
1952 UCHAR status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001953
John Daiker141fa612009-03-10 06:59:54 -07001954 if (dev == NULL) /* Note that we want interrupts with dev->start == 0 */
1955 return IRQ_NONE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001956
Dominik Brodowski624dd662009-10-24 15:52:44 +02001957 pr_debug("ray_cs: interrupt for *dev=%p\n", dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001958
John Daiker141fa612009-03-10 06:59:54 -07001959 local = netdev_priv(dev);
1960 link = (struct pcmcia_device *)local->finder;
1961 if (!pcmcia_dev_present(link)) {
Dominik Brodowski624dd662009-10-24 15:52:44 +02001962 pr_debug(
1963 "ray_cs interrupt from device not present or suspended.\n");
John Daiker141fa612009-03-10 06:59:54 -07001964 return IRQ_NONE;
1965 }
1966 rcsindex = readb(&((struct scb __iomem *)(local->sram))->rcs_index);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001967
John Daiker141fa612009-03-10 06:59:54 -07001968 if (rcsindex >= (NUMBER_OF_CCS + NUMBER_OF_RCS)) {
Dominik Brodowski624dd662009-10-24 15:52:44 +02001969 dev_dbg(&link->dev, "ray_cs interrupt bad rcsindex = 0x%x\n", rcsindex);
John Daiker141fa612009-03-10 06:59:54 -07001970 clear_interrupt(local);
1971 return IRQ_HANDLED;
1972 }
1973 if (rcsindex < NUMBER_OF_CCS) { /* If it's a returned CCS */
1974 pccs = ccs_base(local) + rcsindex;
1975 cmd = readb(&pccs->cmd);
1976 status = readb(&pccs->buffer_status);
1977 switch (cmd) {
1978 case CCS_DOWNLOAD_STARTUP_PARAMS: /* Happens in firmware someday */
1979 del_timer(&local->timer);
1980 if (status == CCS_COMMAND_COMPLETE) {
Dominik Brodowski624dd662009-10-24 15:52:44 +02001981 dev_dbg(&link->dev,
John Daiker141fa612009-03-10 06:59:54 -07001982 "ray_cs interrupt download_startup_parameters OK\n");
1983 } else {
Dominik Brodowski624dd662009-10-24 15:52:44 +02001984 dev_dbg(&link->dev,
John Daiker141fa612009-03-10 06:59:54 -07001985 "ray_cs interrupt download_startup_parameters fail\n");
1986 }
1987 break;
1988 case CCS_UPDATE_PARAMS:
Dominik Brodowski624dd662009-10-24 15:52:44 +02001989 dev_dbg(&link->dev, "ray_cs interrupt update params done\n");
John Daiker141fa612009-03-10 06:59:54 -07001990 if (status != CCS_COMMAND_COMPLETE) {
1991 tmp =
1992 readb(&pccs->var.update_param.
1993 failure_cause);
Dominik Brodowski624dd662009-10-24 15:52:44 +02001994 dev_dbg(&link->dev,
John Daiker141fa612009-03-10 06:59:54 -07001995 "ray_cs interrupt update params failed - reason %d\n",
1996 tmp);
1997 }
1998 break;
1999 case CCS_REPORT_PARAMS:
Dominik Brodowski624dd662009-10-24 15:52:44 +02002000 dev_dbg(&link->dev, "ray_cs interrupt report params done\n");
John Daiker141fa612009-03-10 06:59:54 -07002001 break;
2002 case CCS_UPDATE_MULTICAST_LIST: /* Note that this CCS isn't returned */
Dominik Brodowski624dd662009-10-24 15:52:44 +02002003 dev_dbg(&link->dev,
John Daiker141fa612009-03-10 06:59:54 -07002004 "ray_cs interrupt CCS Update Multicast List done\n");
2005 break;
2006 case CCS_UPDATE_POWER_SAVINGS_MODE:
Dominik Brodowski624dd662009-10-24 15:52:44 +02002007 dev_dbg(&link->dev,
John Daiker141fa612009-03-10 06:59:54 -07002008 "ray_cs interrupt update power save mode done\n");
2009 break;
2010 case CCS_START_NETWORK:
2011 case CCS_JOIN_NETWORK:
2012 if (status == CCS_COMMAND_COMPLETE) {
2013 if (readb
2014 (&pccs->var.start_network.net_initiated) ==
2015 1) {
Dominik Brodowski624dd662009-10-24 15:52:44 +02002016 dev_dbg(&link->dev,
John Daiker141fa612009-03-10 06:59:54 -07002017 "ray_cs interrupt network \"%s\" started\n",
2018 local->sparm.b4.a_current_ess_id);
2019 } else {
Dominik Brodowski624dd662009-10-24 15:52:44 +02002020 dev_dbg(&link->dev,
John Daiker141fa612009-03-10 06:59:54 -07002021 "ray_cs interrupt network \"%s\" joined\n",
2022 local->sparm.b4.a_current_ess_id);
2023 }
2024 memcpy_fromio(&local->bss_id,
2025 pccs->var.start_network.bssid,
2026 ADDRLEN);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002027
John Daiker141fa612009-03-10 06:59:54 -07002028 if (local->fw_ver == 0x55)
2029 local->net_default_tx_rate = 3;
2030 else
2031 local->net_default_tx_rate =
2032 readb(&pccs->var.start_network.
2033 net_default_tx_rate);
2034 local->encryption =
2035 readb(&pccs->var.start_network.encryption);
2036 if (!sniffer && (local->net_type == INFRA)
2037 && !(local->sparm.b4.a_acting_as_ap_status)) {
2038 authenticate(local);
2039 }
2040 local->card_status = CARD_ACQ_COMPLETE;
2041 } else {
2042 local->card_status = CARD_ACQ_FAILED;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002043
John Daiker141fa612009-03-10 06:59:54 -07002044 del_timer(&local->timer);
2045 local->timer.expires = jiffies + HZ * 5;
2046 local->timer.data = (long)local;
2047 if (status == CCS_START_NETWORK) {
Dominik Brodowski624dd662009-10-24 15:52:44 +02002048 dev_dbg(&link->dev,
John Daiker141fa612009-03-10 06:59:54 -07002049 "ray_cs interrupt network \"%s\" start failed\n",
2050 local->sparm.b4.a_current_ess_id);
2051 local->timer.function = &start_net;
2052 } else {
Dominik Brodowski624dd662009-10-24 15:52:44 +02002053 dev_dbg(&link->dev,
John Daiker141fa612009-03-10 06:59:54 -07002054 "ray_cs interrupt network \"%s\" join failed\n",
2055 local->sparm.b4.a_current_ess_id);
2056 local->timer.function = &join_net;
2057 }
2058 add_timer(&local->timer);
2059 }
2060 break;
2061 case CCS_START_ASSOCIATION:
2062 if (status == CCS_COMMAND_COMPLETE) {
2063 local->card_status = CARD_ASSOC_COMPLETE;
Dominik Brodowski624dd662009-10-24 15:52:44 +02002064 dev_dbg(&link->dev, "ray_cs association successful\n");
John Daiker141fa612009-03-10 06:59:54 -07002065 } else {
Dominik Brodowski624dd662009-10-24 15:52:44 +02002066 dev_dbg(&link->dev, "ray_cs association failed,\n");
John Daiker141fa612009-03-10 06:59:54 -07002067 local->card_status = CARD_ASSOC_FAILED;
2068 join_net((u_long) local);
2069 }
2070 break;
2071 case CCS_TX_REQUEST:
2072 if (status == CCS_COMMAND_COMPLETE) {
Dominik Brodowski624dd662009-10-24 15:52:44 +02002073 dev_dbg(&link->dev,
John Daiker141fa612009-03-10 06:59:54 -07002074 "ray_cs interrupt tx request complete\n");
2075 } else {
Dominik Brodowski624dd662009-10-24 15:52:44 +02002076 dev_dbg(&link->dev,
John Daiker141fa612009-03-10 06:59:54 -07002077 "ray_cs interrupt tx request failed\n");
2078 }
2079 if (!sniffer)
2080 netif_start_queue(dev);
2081 netif_wake_queue(dev);
2082 break;
2083 case CCS_TEST_MEMORY:
Dominik Brodowski624dd662009-10-24 15:52:44 +02002084 dev_dbg(&link->dev, "ray_cs interrupt mem test done\n");
John Daiker141fa612009-03-10 06:59:54 -07002085 break;
2086 case CCS_SHUTDOWN:
Dominik Brodowski624dd662009-10-24 15:52:44 +02002087 dev_dbg(&link->dev,
John Daiker141fa612009-03-10 06:59:54 -07002088 "ray_cs interrupt Unexpected CCS returned - Shutdown\n");
2089 break;
2090 case CCS_DUMP_MEMORY:
Dominik Brodowski624dd662009-10-24 15:52:44 +02002091 dev_dbg(&link->dev, "ray_cs interrupt dump memory done\n");
John Daiker141fa612009-03-10 06:59:54 -07002092 break;
2093 case CCS_START_TIMER:
Dominik Brodowski624dd662009-10-24 15:52:44 +02002094 dev_dbg(&link->dev,
John Daiker141fa612009-03-10 06:59:54 -07002095 "ray_cs interrupt DING - raylink timer expired\n");
2096 break;
2097 default:
Dominik Brodowski624dd662009-10-24 15:52:44 +02002098 dev_dbg(&link->dev,
John Daiker141fa612009-03-10 06:59:54 -07002099 "ray_cs interrupt Unexpected CCS 0x%x returned 0x%x\n",
2100 rcsindex, cmd);
2101 }
2102 writeb(CCS_BUFFER_FREE, &pccs->buffer_status);
2103 } else { /* It's an RCS */
2104
2105 prcs = rcs_base(local) + rcsindex;
2106
2107 switch (readb(&prcs->interrupt_id)) {
2108 case PROCESS_RX_PACKET:
2109 ray_rx(dev, local, prcs);
2110 break;
2111 case REJOIN_NET_COMPLETE:
Dominik Brodowski624dd662009-10-24 15:52:44 +02002112 dev_dbg(&link->dev, "ray_cs interrupt rejoin net complete\n");
John Daiker141fa612009-03-10 06:59:54 -07002113 local->card_status = CARD_ACQ_COMPLETE;
2114 /* do we need to clear tx buffers CCS's? */
2115 if (local->sparm.b4.a_network_type == ADHOC) {
2116 if (!sniffer)
2117 netif_start_queue(dev);
2118 } else {
2119 memcpy_fromio(&local->bss_id,
2120 prcs->var.rejoin_net_complete.
2121 bssid, ADDRLEN);
Dominik Brodowski624dd662009-10-24 15:52:44 +02002122 dev_dbg(&link->dev,
John Daiker141fa612009-03-10 06:59:54 -07002123 "ray_cs new BSSID = %02x%02x%02x%02x%02x%02x\n",
2124 local->bss_id[0], local->bss_id[1],
2125 local->bss_id[2], local->bss_id[3],
2126 local->bss_id[4], local->bss_id[5]);
2127 if (!sniffer)
2128 authenticate(local);
2129 }
2130 break;
2131 case ROAMING_INITIATED:
Dominik Brodowski624dd662009-10-24 15:52:44 +02002132 dev_dbg(&link->dev, "ray_cs interrupt roaming initiated\n");
John Daiker141fa612009-03-10 06:59:54 -07002133 netif_stop_queue(dev);
2134 local->card_status = CARD_DOING_ACQ;
2135 break;
2136 case JAPAN_CALL_SIGN_RXD:
Dominik Brodowski624dd662009-10-24 15:52:44 +02002137 dev_dbg(&link->dev, "ray_cs interrupt japan call sign rx\n");
John Daiker141fa612009-03-10 06:59:54 -07002138 break;
2139 default:
Dominik Brodowski624dd662009-10-24 15:52:44 +02002140 dev_dbg(&link->dev,
John Daiker141fa612009-03-10 06:59:54 -07002141 "ray_cs Unexpected interrupt for RCS 0x%x cmd = 0x%x\n",
2142 rcsindex,
2143 (unsigned int)readb(&prcs->interrupt_id));
2144 break;
2145 }
2146 writeb(CCS_BUFFER_FREE, &prcs->buffer_status);
2147 }
2148 clear_interrupt(local);
2149 return IRQ_HANDLED;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002150} /* ray_interrupt */
John Daiker141fa612009-03-10 06:59:54 -07002151
Linus Torvalds1da177e2005-04-16 15:20:36 -07002152/*===========================================================================*/
John Daiker141fa612009-03-10 06:59:54 -07002153static void ray_rx(struct net_device *dev, ray_dev_t *local,
2154 struct rcs __iomem *prcs)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002155{
John Daiker141fa612009-03-10 06:59:54 -07002156 int rx_len;
2157 unsigned int pkt_addr;
2158 void __iomem *pmsg;
Dominik Brodowski624dd662009-10-24 15:52:44 +02002159 pr_debug("ray_rx process rx packet\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002160
John Daiker141fa612009-03-10 06:59:54 -07002161 /* Calculate address of packet within Rx buffer */
2162 pkt_addr = ((readb(&prcs->var.rx_packet.rx_data_ptr[0]) << 8)
2163 + readb(&prcs->var.rx_packet.rx_data_ptr[1])) & RX_BUFF_END;
2164 /* Length of first packet fragment */
2165 rx_len = (readb(&prcs->var.rx_packet.rx_data_length[0]) << 8)
2166 + readb(&prcs->var.rx_packet.rx_data_length[1]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002167
John Daiker141fa612009-03-10 06:59:54 -07002168 local->last_rsl = readb(&prcs->var.rx_packet.rx_sig_lev);
2169 pmsg = local->rmem + pkt_addr;
2170 switch (readb(pmsg)) {
2171 case DATA_TYPE:
Dominik Brodowski624dd662009-10-24 15:52:44 +02002172 pr_debug("ray_rx data type\n");
John Daiker141fa612009-03-10 06:59:54 -07002173 rx_data(dev, prcs, pkt_addr, rx_len);
2174 break;
2175 case AUTHENTIC_TYPE:
Dominik Brodowski624dd662009-10-24 15:52:44 +02002176 pr_debug("ray_rx authentic type\n");
John Daiker141fa612009-03-10 06:59:54 -07002177 if (sniffer)
2178 rx_data(dev, prcs, pkt_addr, rx_len);
2179 else
2180 rx_authenticate(local, prcs, pkt_addr, rx_len);
2181 break;
2182 case DEAUTHENTIC_TYPE:
Dominik Brodowski624dd662009-10-24 15:52:44 +02002183 pr_debug("ray_rx deauth type\n");
John Daiker141fa612009-03-10 06:59:54 -07002184 if (sniffer)
2185 rx_data(dev, prcs, pkt_addr, rx_len);
2186 else
2187 rx_deauthenticate(local, prcs, pkt_addr, rx_len);
2188 break;
2189 case NULL_MSG_TYPE:
Dominik Brodowski624dd662009-10-24 15:52:44 +02002190 pr_debug("ray_cs rx NULL msg\n");
John Daiker141fa612009-03-10 06:59:54 -07002191 break;
2192 case BEACON_TYPE:
Dominik Brodowski624dd662009-10-24 15:52:44 +02002193 pr_debug("ray_rx beacon type\n");
John Daiker141fa612009-03-10 06:59:54 -07002194 if (sniffer)
2195 rx_data(dev, prcs, pkt_addr, rx_len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002196
John Daiker141fa612009-03-10 06:59:54 -07002197 copy_from_rx_buff(local, (UCHAR *) &local->last_bcn, pkt_addr,
2198 rx_len < sizeof(struct beacon_rx) ?
2199 rx_len : sizeof(struct beacon_rx));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002200
John Daiker141fa612009-03-10 06:59:54 -07002201 local->beacon_rxed = 1;
2202 /* Get the statistics so the card counters never overflow */
2203 ray_get_stats(dev);
2204 break;
2205 default:
Dominik Brodowski624dd662009-10-24 15:52:44 +02002206 pr_debug("ray_cs unknown pkt type %2x\n",
John Daiker141fa612009-03-10 06:59:54 -07002207 (unsigned int)readb(pmsg));
2208 break;
2209 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002210
2211} /* end ray_rx */
John Daiker141fa612009-03-10 06:59:54 -07002212
Linus Torvalds1da177e2005-04-16 15:20:36 -07002213/*===========================================================================*/
John Daiker141fa612009-03-10 06:59:54 -07002214static void rx_data(struct net_device *dev, struct rcs __iomem *prcs,
2215 unsigned int pkt_addr, int rx_len)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002216{
John Daiker141fa612009-03-10 06:59:54 -07002217 struct sk_buff *skb = NULL;
2218 struct rcs __iomem *prcslink = prcs;
2219 ray_dev_t *local = netdev_priv(dev);
2220 UCHAR *rx_ptr;
2221 int total_len;
2222 int tmp;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002223#ifdef WIRELESS_SPY
John Daiker141fa612009-03-10 06:59:54 -07002224 int siglev = local->last_rsl;
2225 u_char linksrcaddr[ETH_ALEN]; /* Other end of the wireless link */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002226#endif
2227
John Daiker141fa612009-03-10 06:59:54 -07002228 if (!sniffer) {
2229 if (translate) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002230/* TBD length needs fixing for translated header */
John Daiker141fa612009-03-10 06:59:54 -07002231 if (rx_len < (ETH_HLEN + RX_MAC_HEADER_LENGTH) ||
2232 rx_len >
2233 (dev->mtu + RX_MAC_HEADER_LENGTH + ETH_HLEN +
2234 FCS_LEN)) {
Dominik Brodowski624dd662009-10-24 15:52:44 +02002235 pr_debug(
Frans Popcb01b092010-03-24 19:46:34 +01002236 "ray_cs invalid packet length %d received\n",
John Daiker141fa612009-03-10 06:59:54 -07002237 rx_len);
2238 return;
2239 }
2240 } else { /* encapsulated ethernet */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002241
John Daiker141fa612009-03-10 06:59:54 -07002242 if (rx_len < (ETH_HLEN + RX_MAC_HEADER_LENGTH) ||
2243 rx_len >
2244 (dev->mtu + RX_MAC_HEADER_LENGTH + ETH_HLEN +
2245 FCS_LEN)) {
Dominik Brodowski624dd662009-10-24 15:52:44 +02002246 pr_debug(
Frans Popcb01b092010-03-24 19:46:34 +01002247 "ray_cs invalid packet length %d received\n",
John Daiker141fa612009-03-10 06:59:54 -07002248 rx_len);
2249 return;
2250 }
2251 }
2252 }
Dominik Brodowski624dd662009-10-24 15:52:44 +02002253 pr_debug("ray_cs rx_data packet\n");
John Daiker141fa612009-03-10 06:59:54 -07002254 /* If fragmented packet, verify sizes of fragments add up */
2255 if (readb(&prcs->var.rx_packet.next_frag_rcs_index) != 0xFF) {
Dominik Brodowski624dd662009-10-24 15:52:44 +02002256 pr_debug("ray_cs rx'ed fragment\n");
John Daiker141fa612009-03-10 06:59:54 -07002257 tmp = (readb(&prcs->var.rx_packet.totalpacketlength[0]) << 8)
2258 + readb(&prcs->var.rx_packet.totalpacketlength[1]);
2259 total_len = tmp;
2260 prcslink = prcs;
2261 do {
2262 tmp -=
2263 (readb(&prcslink->var.rx_packet.rx_data_length[0])
2264 << 8)
2265 + readb(&prcslink->var.rx_packet.rx_data_length[1]);
2266 if (readb(&prcslink->var.rx_packet.next_frag_rcs_index)
2267 == 0xFF || tmp < 0)
2268 break;
2269 prcslink = rcs_base(local)
2270 + readb(&prcslink->link_field);
2271 } while (1);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002272
John Daiker141fa612009-03-10 06:59:54 -07002273 if (tmp < 0) {
Dominik Brodowski624dd662009-10-24 15:52:44 +02002274 pr_debug(
John Daiker141fa612009-03-10 06:59:54 -07002275 "ray_cs rx_data fragment lengths don't add up\n");
2276 local->stats.rx_dropped++;
2277 release_frag_chain(local, prcs);
2278 return;
2279 }
2280 } else { /* Single unfragmented packet */
2281 total_len = rx_len;
2282 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002283
John Daiker141fa612009-03-10 06:59:54 -07002284 skb = dev_alloc_skb(total_len + 5);
2285 if (skb == NULL) {
Dominik Brodowski624dd662009-10-24 15:52:44 +02002286 pr_debug("ray_cs rx_data could not allocate skb\n");
John Daiker141fa612009-03-10 06:59:54 -07002287 local->stats.rx_dropped++;
2288 if (readb(&prcs->var.rx_packet.next_frag_rcs_index) != 0xFF)
2289 release_frag_chain(local, prcs);
2290 return;
2291 }
2292 skb_reserve(skb, 2); /* Align IP on 16 byte (TBD check this) */
2293
Dominik Brodowski624dd662009-10-24 15:52:44 +02002294 pr_debug("ray_cs rx_data total_len = %x, rx_len = %x\n", total_len,
John Daiker141fa612009-03-10 06:59:54 -07002295 rx_len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002296
2297/************************/
John Daiker141fa612009-03-10 06:59:54 -07002298 /* Reserve enough room for the whole damn packet. */
2299 rx_ptr = skb_put(skb, total_len);
2300 /* Copy the whole packet to sk_buff */
2301 rx_ptr +=
2302 copy_from_rx_buff(local, rx_ptr, pkt_addr & RX_BUFF_END, rx_len);
2303 /* Get source address */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002304#ifdef WIRELESS_SPY
John Daiker141fa612009-03-10 06:59:54 -07002305 skb_copy_from_linear_data_offset(skb,
2306 offsetof(struct mac_header, addr_2),
2307 linksrcaddr, ETH_ALEN);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002308#endif
John Daiker141fa612009-03-10 06:59:54 -07002309 /* Now, deal with encapsulation/translation/sniffer */
2310 if (!sniffer) {
2311 if (!translate) {
2312 /* Encapsulated ethernet, so just lop off 802.11 MAC header */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002313/* TBD reserve skb_reserve( skb, RX_MAC_HEADER_LENGTH); */
John Daiker141fa612009-03-10 06:59:54 -07002314 skb_pull(skb, RX_MAC_HEADER_LENGTH);
2315 } else {
2316 /* Do translation */
2317 untranslate(local, skb, total_len);
2318 }
2319 } else { /* sniffer mode, so just pass whole packet */
2320 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002321
2322/************************/
John Daiker141fa612009-03-10 06:59:54 -07002323 /* Now pick up the rest of the fragments if any */
2324 tmp = 17;
2325 if (readb(&prcs->var.rx_packet.next_frag_rcs_index) != 0xFF) {
2326 prcslink = prcs;
Dominik Brodowski624dd662009-10-24 15:52:44 +02002327 pr_debug("ray_cs rx_data in fragment loop\n");
John Daiker141fa612009-03-10 06:59:54 -07002328 do {
2329 prcslink = rcs_base(local)
2330 +
2331 readb(&prcslink->var.rx_packet.next_frag_rcs_index);
2332 rx_len =
2333 ((readb(&prcslink->var.rx_packet.rx_data_length[0])
2334 << 8)
2335 +
2336 readb(&prcslink->var.rx_packet.rx_data_length[1]))
2337 & RX_BUFF_END;
2338 pkt_addr =
2339 ((readb(&prcslink->var.rx_packet.rx_data_ptr[0]) <<
2340 8)
2341 + readb(&prcslink->var.rx_packet.rx_data_ptr[1]))
2342 & RX_BUFF_END;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002343
John Daiker141fa612009-03-10 06:59:54 -07002344 rx_ptr +=
2345 copy_from_rx_buff(local, rx_ptr, pkt_addr, rx_len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002346
John Daiker141fa612009-03-10 06:59:54 -07002347 } while (tmp-- &&
2348 readb(&prcslink->var.rx_packet.next_frag_rcs_index) !=
2349 0xFF);
2350 release_frag_chain(local, prcs);
2351 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002352
John Daiker141fa612009-03-10 06:59:54 -07002353 skb->protocol = eth_type_trans(skb, dev);
2354 netif_rx(skb);
2355 local->stats.rx_packets++;
2356 local->stats.rx_bytes += total_len;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002357
John Daiker141fa612009-03-10 06:59:54 -07002358 /* Gather signal strength per address */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002359#ifdef WIRELESS_SPY
John Daiker141fa612009-03-10 06:59:54 -07002360 /* For the Access Point or the node having started the ad-hoc net
2361 * note : ad-hoc work only in some specific configurations, but we
2362 * kludge in ray_get_wireless_stats... */
2363 if (!memcmp(linksrcaddr, local->bss_id, ETH_ALEN)) {
2364 /* Update statistics */
2365 /*local->wstats.qual.qual = none ? */
2366 local->wstats.qual.level = siglev;
2367 /*local->wstats.qual.noise = none ? */
2368 local->wstats.qual.updated = 0x2;
2369 }
2370 /* Now, update the spy stuff */
2371 {
2372 struct iw_quality wstats;
2373 wstats.level = siglev;
2374 /* wstats.noise = none ? */
2375 /* wstats.qual = none ? */
2376 wstats.updated = 0x2;
2377 /* Update spy records */
2378 wireless_spy_update(dev, linksrcaddr, &wstats);
2379 }
2380#endif /* WIRELESS_SPY */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002381} /* end rx_data */
John Daiker141fa612009-03-10 06:59:54 -07002382
Linus Torvalds1da177e2005-04-16 15:20:36 -07002383/*===========================================================================*/
2384static void untranslate(ray_dev_t *local, struct sk_buff *skb, int len)
2385{
John Daiker141fa612009-03-10 06:59:54 -07002386 snaphdr_t *psnap = (snaphdr_t *) (skb->data + RX_MAC_HEADER_LENGTH);
2387 struct ieee80211_hdr *pmac = (struct ieee80211_hdr *)skb->data;
2388 __be16 type = *(__be16 *) psnap->ethertype;
2389 int delta;
2390 struct ethhdr *peth;
2391 UCHAR srcaddr[ADDRLEN];
2392 UCHAR destaddr[ADDRLEN];
2393 static UCHAR org_bridge[3] = { 0, 0, 0xf8 };
2394 static UCHAR org_1042[3] = { 0, 0, 0 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002395
John Daiker141fa612009-03-10 06:59:54 -07002396 memcpy(destaddr, ieee80211_get_DA(pmac), ADDRLEN);
2397 memcpy(srcaddr, ieee80211_get_SA(pmac), ADDRLEN);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002398
Dominik Brodowski624dd662009-10-24 15:52:44 +02002399#if 0
2400 if {
Joe Perchesad361c92009-07-06 13:05:40 -07002401 print_hex_dump(KERN_DEBUG, "skb->data before untranslate: ",
2402 DUMP_PREFIX_NONE, 16, 1,
2403 skb->data, 64, true);
2404 printk(KERN_DEBUG
John Daiker141fa612009-03-10 06:59:54 -07002405 "type = %08x, xsap = %02x%02x%02x, org = %02x02x02x\n",
2406 ntohs(type), psnap->dsap, psnap->ssap, psnap->ctrl,
2407 psnap->org[0], psnap->org[1], psnap->org[2]);
2408 printk(KERN_DEBUG "untranslate skb->data = %p\n", skb->data);
2409 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002410#endif
2411
John Daiker141fa612009-03-10 06:59:54 -07002412 if (psnap->dsap != 0xaa || psnap->ssap != 0xaa || psnap->ctrl != 3) {
2413 /* not a snap type so leave it alone */
Dominik Brodowski624dd662009-10-24 15:52:44 +02002414 pr_debug("ray_cs untranslate NOT SNAP %02x %02x %02x\n",
John Daiker141fa612009-03-10 06:59:54 -07002415 psnap->dsap, psnap->ssap, psnap->ctrl);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002416
John Daiker141fa612009-03-10 06:59:54 -07002417 delta = RX_MAC_HEADER_LENGTH - ETH_HLEN;
2418 peth = (struct ethhdr *)(skb->data + delta);
2419 peth->h_proto = htons(len - RX_MAC_HEADER_LENGTH);
2420 } else { /* Its a SNAP */
2421 if (memcmp(psnap->org, org_bridge, 3) == 0) {
2422 /* EtherII and nuke the LLC */
Dominik Brodowski624dd662009-10-24 15:52:44 +02002423 pr_debug("ray_cs untranslate Bridge encap\n");
John Daiker141fa612009-03-10 06:59:54 -07002424 delta = RX_MAC_HEADER_LENGTH
2425 + sizeof(struct snaphdr_t) - ETH_HLEN;
2426 peth = (struct ethhdr *)(skb->data + delta);
2427 peth->h_proto = type;
2428 } else if (memcmp(psnap->org, org_1042, 3) == 0) {
2429 switch (ntohs(type)) {
2430 case ETH_P_IPX:
2431 case ETH_P_AARP:
Dominik Brodowski624dd662009-10-24 15:52:44 +02002432 pr_debug("ray_cs untranslate RFC IPX/AARP\n");
John Daiker141fa612009-03-10 06:59:54 -07002433 delta = RX_MAC_HEADER_LENGTH - ETH_HLEN;
2434 peth = (struct ethhdr *)(skb->data + delta);
2435 peth->h_proto =
2436 htons(len - RX_MAC_HEADER_LENGTH);
2437 break;
2438 default:
Dominik Brodowski624dd662009-10-24 15:52:44 +02002439 pr_debug("ray_cs untranslate RFC default\n");
John Daiker141fa612009-03-10 06:59:54 -07002440 delta = RX_MAC_HEADER_LENGTH +
2441 sizeof(struct snaphdr_t) - ETH_HLEN;
2442 peth = (struct ethhdr *)(skb->data + delta);
2443 peth->h_proto = type;
2444 break;
2445 }
2446 } else {
2447 printk("ray_cs untranslate very confused by packet\n");
2448 delta = RX_MAC_HEADER_LENGTH - ETH_HLEN;
2449 peth = (struct ethhdr *)(skb->data + delta);
2450 peth->h_proto = type;
2451 }
Al Viro7698d692007-12-29 04:55:50 -05002452 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002453/* TBD reserve skb_reserve(skb, delta); */
John Daiker141fa612009-03-10 06:59:54 -07002454 skb_pull(skb, delta);
Dominik Brodowski624dd662009-10-24 15:52:44 +02002455 pr_debug("untranslate after skb_pull(%d), skb->data = %p\n", delta,
John Daiker141fa612009-03-10 06:59:54 -07002456 skb->data);
2457 memcpy(peth->h_dest, destaddr, ADDRLEN);
2458 memcpy(peth->h_source, srcaddr, ADDRLEN);
Dominik Brodowski624dd662009-10-24 15:52:44 +02002459#if 0
2460 {
John Daiker141fa612009-03-10 06:59:54 -07002461 int i;
2462 printk(KERN_DEBUG "skb->data after untranslate:");
2463 for (i = 0; i < 64; i++)
2464 printk("%02x ", skb->data[i]);
2465 printk("\n");
2466 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002467#endif
2468} /* end untranslate */
John Daiker141fa612009-03-10 06:59:54 -07002469
Linus Torvalds1da177e2005-04-16 15:20:36 -07002470/*===========================================================================*/
2471/* Copy data from circular receive buffer to PC memory.
2472 * dest = destination address in PC memory
2473 * pkt_addr = source address in receive buffer
2474 * len = length of packet to copy
2475 */
John Daiker141fa612009-03-10 06:59:54 -07002476static int copy_from_rx_buff(ray_dev_t *local, UCHAR *dest, int pkt_addr,
2477 int length)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002478{
John Daiker141fa612009-03-10 06:59:54 -07002479 int wrap_bytes = (pkt_addr + length) - (RX_BUFF_END + 1);
2480 if (wrap_bytes <= 0) {
2481 memcpy_fromio(dest, local->rmem + pkt_addr, length);
2482 } else { /* Packet wrapped in circular buffer */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002483
John Daiker141fa612009-03-10 06:59:54 -07002484 memcpy_fromio(dest, local->rmem + pkt_addr,
2485 length - wrap_bytes);
2486 memcpy_fromio(dest + length - wrap_bytes, local->rmem,
2487 wrap_bytes);
2488 }
2489 return length;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002490}
John Daiker141fa612009-03-10 06:59:54 -07002491
2492/*===========================================================================*/
2493static void release_frag_chain(ray_dev_t *local, struct rcs __iomem *prcs)
2494{
2495 struct rcs __iomem *prcslink = prcs;
2496 int tmp = 17;
2497 unsigned rcsindex = readb(&prcs->var.rx_packet.next_frag_rcs_index);
2498
2499 while (tmp--) {
2500 writeb(CCS_BUFFER_FREE, &prcslink->buffer_status);
2501 if (rcsindex >= (NUMBER_OF_CCS + NUMBER_OF_RCS)) {
Dominik Brodowski624dd662009-10-24 15:52:44 +02002502 pr_debug("ray_cs interrupt bad rcsindex = 0x%x\n",
John Daiker141fa612009-03-10 06:59:54 -07002503 rcsindex);
2504 break;
2505 }
2506 prcslink = rcs_base(local) + rcsindex;
2507 rcsindex = readb(&prcslink->var.rx_packet.next_frag_rcs_index);
2508 }
2509 writeb(CCS_BUFFER_FREE, &prcslink->buffer_status);
2510}
2511
Linus Torvalds1da177e2005-04-16 15:20:36 -07002512/*===========================================================================*/
2513static void authenticate(ray_dev_t *local)
2514{
John Daiker141fa612009-03-10 06:59:54 -07002515 struct pcmcia_device *link = local->finder;
Dominik Brodowski624dd662009-10-24 15:52:44 +02002516 dev_dbg(&link->dev, "ray_cs Starting authentication.\n");
John Daiker141fa612009-03-10 06:59:54 -07002517 if (!(pcmcia_dev_present(link))) {
Dominik Brodowski624dd662009-10-24 15:52:44 +02002518 dev_dbg(&link->dev, "ray_cs authenticate - device not present\n");
John Daiker141fa612009-03-10 06:59:54 -07002519 return;
2520 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002521
John Daiker141fa612009-03-10 06:59:54 -07002522 del_timer(&local->timer);
2523 if (build_auth_frame(local, local->bss_id, OPEN_AUTH_REQUEST)) {
2524 local->timer.function = &join_net;
2525 } else {
2526 local->timer.function = &authenticate_timeout;
2527 }
2528 local->timer.expires = jiffies + HZ * 2;
2529 local->timer.data = (long)local;
2530 add_timer(&local->timer);
2531 local->authentication_state = AWAITING_RESPONSE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002532} /* end authenticate */
John Daiker141fa612009-03-10 06:59:54 -07002533
Linus Torvalds1da177e2005-04-16 15:20:36 -07002534/*===========================================================================*/
2535static void rx_authenticate(ray_dev_t *local, struct rcs __iomem *prcs,
John Daiker141fa612009-03-10 06:59:54 -07002536 unsigned int pkt_addr, int rx_len)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002537{
John Daiker141fa612009-03-10 06:59:54 -07002538 UCHAR buff[256];
2539 struct rx_msg *msg = (struct rx_msg *)buff;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002540
John Daiker141fa612009-03-10 06:59:54 -07002541 del_timer(&local->timer);
2542
2543 copy_from_rx_buff(local, buff, pkt_addr, rx_len & 0xff);
2544 /* if we are trying to get authenticated */
2545 if (local->sparm.b4.a_network_type == ADHOC) {
Dominik Brodowski624dd662009-10-24 15:52:44 +02002546 pr_debug("ray_cs rx_auth var= %02x %02x %02x %02x %02x %02x\n",
John Daiker141fa612009-03-10 06:59:54 -07002547 msg->var[0], msg->var[1], msg->var[2], msg->var[3],
2548 msg->var[4], msg->var[5]);
2549 if (msg->var[2] == 1) {
Dominik Brodowski624dd662009-10-24 15:52:44 +02002550 pr_debug("ray_cs Sending authentication response.\n");
John Daiker141fa612009-03-10 06:59:54 -07002551 if (!build_auth_frame
2552 (local, msg->mac.addr_2, OPEN_AUTH_RESPONSE)) {
2553 local->authentication_state = NEED_TO_AUTH;
2554 memcpy(local->auth_id, msg->mac.addr_2,
2555 ADDRLEN);
2556 }
2557 }
2558 } else { /* Infrastructure network */
2559
2560 if (local->authentication_state == AWAITING_RESPONSE) {
2561 /* Verify authentication sequence #2 and success */
2562 if (msg->var[2] == 2) {
2563 if ((msg->var[3] | msg->var[4]) == 0) {
Dominik Brodowski624dd662009-10-24 15:52:44 +02002564 pr_debug("Authentication successful\n");
John Daiker141fa612009-03-10 06:59:54 -07002565 local->card_status = CARD_AUTH_COMPLETE;
2566 associate(local);
2567 local->authentication_state =
2568 AUTHENTICATED;
2569 } else {
Dominik Brodowski624dd662009-10-24 15:52:44 +02002570 pr_debug("Authentication refused\n");
John Daiker141fa612009-03-10 06:59:54 -07002571 local->card_status = CARD_AUTH_REFUSED;
2572 join_net((u_long) local);
2573 local->authentication_state =
2574 UNAUTHENTICATED;
2575 }
2576 }
2577 }
2578 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002579
2580} /* end rx_authenticate */
John Daiker141fa612009-03-10 06:59:54 -07002581
Linus Torvalds1da177e2005-04-16 15:20:36 -07002582/*===========================================================================*/
2583static void associate(ray_dev_t *local)
2584{
John Daiker141fa612009-03-10 06:59:54 -07002585 struct ccs __iomem *pccs;
2586 struct pcmcia_device *link = local->finder;
2587 struct net_device *dev = link->priv;
2588 int ccsindex;
2589 if (!(pcmcia_dev_present(link))) {
Dominik Brodowski624dd662009-10-24 15:52:44 +02002590 dev_dbg(&link->dev, "ray_cs associate - device not present\n");
John Daiker141fa612009-03-10 06:59:54 -07002591 return;
2592 }
2593 /* If no tx buffers available, return */
2594 if ((ccsindex = get_free_ccs(local)) < 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002595/* TBD should never be here but... what if we are? */
Dominik Brodowski624dd662009-10-24 15:52:44 +02002596 dev_dbg(&link->dev, "ray_cs associate - No free ccs\n");
John Daiker141fa612009-03-10 06:59:54 -07002597 return;
2598 }
Dominik Brodowski624dd662009-10-24 15:52:44 +02002599 dev_dbg(&link->dev, "ray_cs Starting association with access point\n");
John Daiker141fa612009-03-10 06:59:54 -07002600 pccs = ccs_base(local) + ccsindex;
2601 /* fill in the CCS */
2602 writeb(CCS_START_ASSOCIATION, &pccs->cmd);
2603 /* Interrupt the firmware to process the command */
2604 if (interrupt_ecf(local, ccsindex)) {
Dominik Brodowski624dd662009-10-24 15:52:44 +02002605 dev_dbg(&link->dev, "ray_cs associate failed - ECF not ready for intr\n");
John Daiker141fa612009-03-10 06:59:54 -07002606 writeb(CCS_BUFFER_FREE, &(pccs++)->buffer_status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002607
John Daiker141fa612009-03-10 06:59:54 -07002608 del_timer(&local->timer);
2609 local->timer.expires = jiffies + HZ * 2;
2610 local->timer.data = (long)local;
2611 local->timer.function = &join_net;
2612 add_timer(&local->timer);
2613 local->card_status = CARD_ASSOC_FAILED;
2614 return;
2615 }
2616 if (!sniffer)
2617 netif_start_queue(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002618
2619} /* end associate */
John Daiker141fa612009-03-10 06:59:54 -07002620
Linus Torvalds1da177e2005-04-16 15:20:36 -07002621/*===========================================================================*/
John Daiker141fa612009-03-10 06:59:54 -07002622static void rx_deauthenticate(ray_dev_t *local, struct rcs __iomem *prcs,
2623 unsigned int pkt_addr, int rx_len)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002624{
2625/* UCHAR buff[256];
2626 struct rx_msg *msg = (struct rx_msg *)buff;
2627*/
Dominik Brodowski624dd662009-10-24 15:52:44 +02002628 pr_debug("Deauthentication frame received\n");
John Daiker141fa612009-03-10 06:59:54 -07002629 local->authentication_state = UNAUTHENTICATED;
2630 /* Need to reauthenticate or rejoin depending on reason code */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002631/* copy_from_rx_buff(local, buff, pkt_addr, rx_len & 0xff);
2632 */
2633}
John Daiker141fa612009-03-10 06:59:54 -07002634
Linus Torvalds1da177e2005-04-16 15:20:36 -07002635/*===========================================================================*/
2636static void clear_interrupt(ray_dev_t *local)
2637{
John Daiker141fa612009-03-10 06:59:54 -07002638 writeb(0, local->amem + CIS_OFFSET + HCS_INTR_OFFSET);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002639}
John Daiker141fa612009-03-10 06:59:54 -07002640
Linus Torvalds1da177e2005-04-16 15:20:36 -07002641/*===========================================================================*/
2642#ifdef CONFIG_PROC_FS
2643#define MAXDATA (PAGE_SIZE - 80)
2644
2645static char *card_status[] = {
John Daiker141fa612009-03-10 06:59:54 -07002646 "Card inserted - uninitialized", /* 0 */
2647 "Card not downloaded", /* 1 */
2648 "Waiting for download parameters", /* 2 */
2649 "Card doing acquisition", /* 3 */
2650 "Acquisition complete", /* 4 */
2651 "Authentication complete", /* 5 */
2652 "Association complete", /* 6 */
2653 "???", "???", "???", "???", /* 7 8 9 10 undefined */
2654 "Card init error", /* 11 */
2655 "Download parameters error", /* 12 */
2656 "???", /* 13 */
2657 "Acquisition failed", /* 14 */
2658 "Authentication refused", /* 15 */
2659 "Association failed" /* 16 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002660};
2661
John Daiker141fa612009-03-10 06:59:54 -07002662static char *nettype[] = { "Adhoc", "Infra " };
2663static char *framing[] = { "Encapsulation", "Translation" }
2664
Linus Torvalds1da177e2005-04-16 15:20:36 -07002665;
2666/*===========================================================================*/
Alexey Dobriyan6b914c52008-04-10 14:34:35 -07002667static int ray_cs_proc_show(struct seq_file *m, void *v)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002668{
2669/* Print current values which are not available via other means
John Daiker141fa612009-03-10 06:59:54 -07002670 * eg ifconfig
Linus Torvalds1da177e2005-04-16 15:20:36 -07002671 */
John Daiker141fa612009-03-10 06:59:54 -07002672 int i;
2673 struct pcmcia_device *link;
2674 struct net_device *dev;
2675 ray_dev_t *local;
2676 UCHAR *p;
2677 struct freq_hop_element *pfh;
2678 UCHAR c[33];
Linus Torvalds1da177e2005-04-16 15:20:36 -07002679
John Daiker141fa612009-03-10 06:59:54 -07002680 link = this_device;
2681 if (!link)
2682 return 0;
2683 dev = (struct net_device *)link->priv;
2684 if (!dev)
2685 return 0;
2686 local = netdev_priv(dev);
2687 if (!local)
2688 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002689
John Daiker141fa612009-03-10 06:59:54 -07002690 seq_puts(m, "Raylink Wireless LAN driver status\n");
2691 seq_printf(m, "%s\n", rcsid);
2692 /* build 4 does not report version, and field is 0x55 after memtest */
2693 seq_puts(m, "Firmware version = ");
2694 if (local->fw_ver == 0x55)
2695 seq_puts(m, "4 - Use dump_cis for more details\n");
2696 else
2697 seq_printf(m, "%2d.%02d.%02d\n",
2698 local->fw_ver, local->fw_bld, local->fw_var);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002699
John Daiker141fa612009-03-10 06:59:54 -07002700 for (i = 0; i < 32; i++)
2701 c[i] = local->sparm.b5.a_current_ess_id[i];
2702 c[32] = 0;
2703 seq_printf(m, "%s network ESSID = \"%s\"\n",
2704 nettype[local->sparm.b5.a_network_type], c);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002705
John Daiker141fa612009-03-10 06:59:54 -07002706 p = local->bss_id;
2707 seq_printf(m, "BSSID = %pM\n", p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002708
John Daiker141fa612009-03-10 06:59:54 -07002709 seq_printf(m, "Country code = %d\n",
2710 local->sparm.b5.a_curr_country_code);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002711
John Daiker141fa612009-03-10 06:59:54 -07002712 i = local->card_status;
2713 if (i < 0)
2714 i = 10;
2715 if (i > 16)
2716 i = 10;
2717 seq_printf(m, "Card status = %s\n", card_status[i]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002718
John Daiker141fa612009-03-10 06:59:54 -07002719 seq_printf(m, "Framing mode = %s\n", framing[translate]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002720
John Daiker141fa612009-03-10 06:59:54 -07002721 seq_printf(m, "Last pkt signal lvl = %d\n", local->last_rsl);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002722
John Daiker141fa612009-03-10 06:59:54 -07002723 if (local->beacon_rxed) {
2724 /* Pull some fields out of last beacon received */
2725 seq_printf(m, "Beacon Interval = %d Kus\n",
2726 local->last_bcn.beacon_intvl[0]
2727 + 256 * local->last_bcn.beacon_intvl[1]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002728
John Daiker141fa612009-03-10 06:59:54 -07002729 p = local->last_bcn.elements;
2730 if (p[0] == C_ESSID_ELEMENT_ID)
2731 p += p[1] + 2;
2732 else {
2733 seq_printf(m,
2734 "Parse beacon failed at essid element id = %d\n",
2735 p[0]);
2736 return 0;
2737 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002738
John Daiker141fa612009-03-10 06:59:54 -07002739 if (p[0] == C_SUPPORTED_RATES_ELEMENT_ID) {
2740 seq_puts(m, "Supported rate codes = ");
2741 for (i = 2; i < p[1] + 2; i++)
2742 seq_printf(m, "0x%02x ", p[i]);
2743 seq_putc(m, '\n');
2744 p += p[1] + 2;
2745 } else {
2746 seq_puts(m, "Parse beacon failed at rates element\n");
2747 return 0;
2748 }
2749
2750 if (p[0] == C_FH_PARAM_SET_ELEMENT_ID) {
2751 pfh = (struct freq_hop_element *)p;
2752 seq_printf(m, "Hop dwell = %d Kus\n",
2753 pfh->dwell_time[0] +
2754 256 * pfh->dwell_time[1]);
Frans Popcb01b092010-03-24 19:46:34 +01002755 seq_printf(m, "Hop set = %d\n",
John Daiker141fa612009-03-10 06:59:54 -07002756 pfh->hop_set);
Frans Popcb01b092010-03-24 19:46:34 +01002757 seq_printf(m, "Hop pattern = %d\n",
John Daiker141fa612009-03-10 06:59:54 -07002758 pfh->hop_pattern);
Frans Popcb01b092010-03-24 19:46:34 +01002759 seq_printf(m, "Hop index = %d\n",
John Daiker141fa612009-03-10 06:59:54 -07002760 pfh->hop_index);
2761 p += p[1] + 2;
2762 } else {
2763 seq_puts(m,
2764 "Parse beacon failed at FH param element\n");
2765 return 0;
2766 }
2767 } else {
2768 seq_puts(m, "No beacons received\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002769 }
John Daiker141fa612009-03-10 06:59:54 -07002770 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002771}
2772
Alexey Dobriyan6b914c52008-04-10 14:34:35 -07002773static int ray_cs_proc_open(struct inode *inode, struct file *file)
2774{
2775 return single_open(file, ray_cs_proc_show, NULL);
2776}
2777
2778static const struct file_operations ray_cs_proc_fops = {
John Daiker141fa612009-03-10 06:59:54 -07002779 .owner = THIS_MODULE,
2780 .open = ray_cs_proc_open,
2781 .read = seq_read,
2782 .llseek = seq_lseek,
2783 .release = single_release,
Alexey Dobriyan6b914c52008-04-10 14:34:35 -07002784};
Linus Torvalds1da177e2005-04-16 15:20:36 -07002785#endif
2786/*===========================================================================*/
2787static int build_auth_frame(ray_dev_t *local, UCHAR *dest, int auth_type)
2788{
John Daiker141fa612009-03-10 06:59:54 -07002789 int addr;
2790 struct ccs __iomem *pccs;
2791 struct tx_msg __iomem *ptx;
2792 int ccsindex;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002793
John Daiker141fa612009-03-10 06:59:54 -07002794 /* If no tx buffers available, return */
2795 if ((ccsindex = get_free_tx_ccs(local)) < 0) {
Dominik Brodowski624dd662009-10-24 15:52:44 +02002796 pr_debug("ray_cs send authenticate - No free tx ccs\n");
John Daiker141fa612009-03-10 06:59:54 -07002797 return -1;
2798 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002799
John Daiker141fa612009-03-10 06:59:54 -07002800 pccs = ccs_base(local) + ccsindex;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002801
John Daiker141fa612009-03-10 06:59:54 -07002802 /* Address in card space */
2803 addr = TX_BUF_BASE + (ccsindex << 11);
2804 /* fill in the CCS */
2805 writeb(CCS_TX_REQUEST, &pccs->cmd);
2806 writeb(addr >> 8, pccs->var.tx_request.tx_data_ptr);
2807 writeb(0x20, pccs->var.tx_request.tx_data_ptr + 1);
2808 writeb(TX_AUTHENTICATE_LENGTH_MSB, pccs->var.tx_request.tx_data_length);
2809 writeb(TX_AUTHENTICATE_LENGTH_LSB,
2810 pccs->var.tx_request.tx_data_length + 1);
2811 writeb(0, &pccs->var.tx_request.pow_sav_mode);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002812
John Daiker141fa612009-03-10 06:59:54 -07002813 ptx = local->sram + addr;
2814 /* fill in the mac header */
2815 writeb(PROTOCOL_VER | AUTHENTIC_TYPE, &ptx->mac.frame_ctl_1);
2816 writeb(0, &ptx->mac.frame_ctl_2);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002817
John Daiker141fa612009-03-10 06:59:54 -07002818 memcpy_toio(ptx->mac.addr_1, dest, ADDRLEN);
2819 memcpy_toio(ptx->mac.addr_2, local->sparm.b4.a_mac_addr, ADDRLEN);
2820 memcpy_toio(ptx->mac.addr_3, local->bss_id, ADDRLEN);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002821
John Daiker141fa612009-03-10 06:59:54 -07002822 /* Fill in msg body with protocol 00 00, sequence 01 00 ,status 00 00 */
2823 memset_io(ptx->var, 0, 6);
2824 writeb(auth_type & 0xff, ptx->var + 2);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002825
John Daiker141fa612009-03-10 06:59:54 -07002826 /* Interrupt the firmware to process the command */
2827 if (interrupt_ecf(local, ccsindex)) {
Dominik Brodowski624dd662009-10-24 15:52:44 +02002828 pr_debug(
John Daiker141fa612009-03-10 06:59:54 -07002829 "ray_cs send authentication request failed - ECF not ready for intr\n");
2830 writeb(CCS_BUFFER_FREE, &(pccs++)->buffer_status);
2831 return -1;
2832 }
2833 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002834} /* End build_auth_frame */
2835
2836/*===========================================================================*/
2837#ifdef CONFIG_PROC_FS
Alexey Dobriyan83daee02009-11-25 10:12:20 +03002838static ssize_t ray_cs_essid_proc_write(struct file *file,
2839 const char __user *buffer, size_t count, loff_t *pos)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002840{
2841 static char proc_essid[33];
Alan Cox575c9ed2009-10-27 15:35:55 +00002842 unsigned int len = count;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002843
2844 if (len > 32)
2845 len = 32;
2846 memset(proc_essid, 0, 33);
2847 if (copy_from_user(proc_essid, buffer, len))
2848 return -EFAULT;
2849 essid = proc_essid;
2850 return count;
2851}
2852
Alexey Dobriyan83daee02009-11-25 10:12:20 +03002853static const struct file_operations ray_cs_essid_proc_fops = {
2854 .owner = THIS_MODULE,
2855 .write = ray_cs_essid_proc_write,
2856};
2857
2858static ssize_t int_proc_write(struct file *file, const char __user *buffer,
2859 size_t count, loff_t *pos)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002860{
2861 static char proc_number[10];
2862 char *p;
2863 int nr, len;
2864
2865 if (!count)
2866 return 0;
2867
2868 if (count > 9)
2869 return -EINVAL;
2870 if (copy_from_user(proc_number, buffer, count))
2871 return -EFAULT;
2872 p = proc_number;
2873 nr = 0;
2874 len = count;
2875 do {
2876 unsigned int c = *p - '0';
2877 if (c > 9)
2878 return -EINVAL;
John Daiker141fa612009-03-10 06:59:54 -07002879 nr = nr * 10 + c;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002880 p++;
2881 } while (--len);
Alexey Dobriyan83daee02009-11-25 10:12:20 +03002882 *(int *)PDE(file->f_path.dentry->d_inode)->data = nr;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002883 return count;
2884}
Alexey Dobriyan83daee02009-11-25 10:12:20 +03002885
2886static const struct file_operations int_proc_fops = {
2887 .owner = THIS_MODULE,
2888 .write = int_proc_write,
2889};
Linus Torvalds1da177e2005-04-16 15:20:36 -07002890#endif
2891
Dominik Brodowskif57ea2a2005-06-27 16:28:24 -07002892static struct pcmcia_device_id ray_ids[] = {
2893 PCMCIA_DEVICE_MANF_CARD(0x01a6, 0x0000),
2894 PCMCIA_DEVICE_NULL,
2895};
John Daiker141fa612009-03-10 06:59:54 -07002896
Dominik Brodowskif57ea2a2005-06-27 16:28:24 -07002897MODULE_DEVICE_TABLE(pcmcia, ray_ids);
2898
Linus Torvalds1da177e2005-04-16 15:20:36 -07002899static struct pcmcia_driver ray_driver = {
John Daiker141fa612009-03-10 06:59:54 -07002900 .owner = THIS_MODULE,
2901 .drv = {
2902 .name = "ray_cs",
2903 },
2904 .probe = ray_probe,
2905 .remove = ray_detach,
2906 .id_table = ray_ids,
2907 .suspend = ray_suspend,
2908 .resume = ray_resume,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002909};
2910
2911static int __init init_ray_cs(void)
2912{
John Daiker141fa612009-03-10 06:59:54 -07002913 int rc;
2914
Dominik Brodowski624dd662009-10-24 15:52:44 +02002915 pr_debug("%s\n", rcsid);
John Daiker141fa612009-03-10 06:59:54 -07002916 rc = pcmcia_register_driver(&ray_driver);
Dominik Brodowski624dd662009-10-24 15:52:44 +02002917 pr_debug("raylink init_module register_pcmcia_driver returns 0x%x\n",
John Daiker141fa612009-03-10 06:59:54 -07002918 rc);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002919
2920#ifdef CONFIG_PROC_FS
John Daiker141fa612009-03-10 06:59:54 -07002921 proc_mkdir("driver/ray_cs", NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002922
John Daiker141fa612009-03-10 06:59:54 -07002923 proc_create("driver/ray_cs/ray_cs", 0, NULL, &ray_cs_proc_fops);
Alexey Dobriyan83daee02009-11-25 10:12:20 +03002924 proc_create("driver/ray_cs/essid", S_IWUSR, NULL, &ray_cs_essid_proc_fops);
2925 proc_create_data("driver/ray_cs/net_type", S_IWUSR, NULL, &int_proc_fops, &net_type);
2926 proc_create_data("driver/ray_cs/translate", S_IWUSR, NULL, &int_proc_fops, &translate);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002927#endif
John Daiker141fa612009-03-10 06:59:54 -07002928 if (translate != 0)
2929 translate = 1;
2930 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002931} /* init_ray_cs */
2932
2933/*===========================================================================*/
2934
2935static void __exit exit_ray_cs(void)
2936{
Dominik Brodowski624dd662009-10-24 15:52:44 +02002937 pr_debug("ray_cs: cleanup_module\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002938
2939#ifdef CONFIG_PROC_FS
John Daiker141fa612009-03-10 06:59:54 -07002940 remove_proc_entry("driver/ray_cs/ray_cs", NULL);
2941 remove_proc_entry("driver/ray_cs/essid", NULL);
2942 remove_proc_entry("driver/ray_cs/net_type", NULL);
2943 remove_proc_entry("driver/ray_cs/translate", NULL);
2944 remove_proc_entry("driver/ray_cs", NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002945#endif
2946
John Daiker141fa612009-03-10 06:59:54 -07002947 pcmcia_unregister_driver(&ray_driver);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002948} /* exit_ray_cs */
2949
2950module_init(init_ray_cs);
2951module_exit(exit_ray_cs);
2952
2953/*===========================================================================*/