blob: 7eb339af351b53585f4111e952da8d91de91f3d4 [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.h>
50#include <pcmcia/cistpl.h>
51#include <pcmcia/cisreg.h>
52#include <pcmcia/ds.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070053
54#include <linux/wireless.h>
Michael Wu113b8982006-08-13 23:27:17 -070055#include <net/iw_handler.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070056
57#include <asm/io.h>
58#include <asm/system.h>
59#include <asm/byteorder.h>
60#include <asm/uaccess.h>
61
62/* Warning : these stuff will slow down the driver... */
63#define WIRELESS_SPY /* Enable spying addresses */
64/* Definitions we need for spy */
John Daiker141fa612009-03-10 06:59:54 -070065typedef struct iw_statistics iw_stats;
66typedef u_char mac_addr[ETH_ALEN]; /* Hardware address */
Linus Torvalds1da177e2005-04-16 15:20:36 -070067
68#include "rayctl.h"
69#include "ray_cs.h"
70
Linus Torvalds1da177e2005-04-16 15:20:36 -070071
Linus Torvalds1da177e2005-04-16 15:20:36 -070072/** Prototypes based on PCMCIA skeleton driver *******************************/
Dominik Brodowski15b99ac2006-03-31 17:26:06 +020073static int ray_config(struct pcmcia_device *link);
Dominik Brodowskifba395e2006-03-31 17:21:06 +020074static void ray_release(struct pcmcia_device *link);
Dominik Brodowskicc3b4862005-11-14 21:23:14 +010075static void ray_detach(struct pcmcia_device *p_dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -070076
77/***** Prototypes indicated by device structure ******************************/
78static int ray_dev_close(struct net_device *dev);
79static int ray_dev_config(struct net_device *dev, struct ifmap *map);
80static struct net_device_stats *ray_get_stats(struct net_device *dev);
81static int ray_dev_init(struct net_device *dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -070082
Jeff Garzik7282d492006-09-13 14:30:00 -040083static const struct ethtool_ops netdev_ethtool_ops;
Linus Torvalds1da177e2005-04-16 15:20:36 -070084
85static int ray_open(struct net_device *dev);
Stephen Hemmingerd0cf9c02009-08-31 19:50:57 +000086static netdev_tx_t ray_dev_start_xmit(struct sk_buff *skb,
87 struct net_device *dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -070088static void set_multicast_list(struct net_device *dev);
89static void ray_update_multi_list(struct net_device *dev, int all);
90static int translate_frame(ray_dev_t *local, struct tx_msg __iomem *ptx,
John Daiker141fa612009-03-10 06:59:54 -070091 unsigned char *data, int len);
92static void ray_build_header(ray_dev_t *local, struct tx_msg __iomem *ptx,
93 UCHAR msg_type, unsigned char *data);
Linus Torvalds1da177e2005-04-16 15:20:36 -070094static void untranslate(ray_dev_t *local, struct sk_buff *skb, int len);
John Daiker141fa612009-03-10 06:59:54 -070095static iw_stats *ray_get_wireless_stats(struct net_device *dev);
96static const struct iw_handler_def ray_handler_def;
Linus Torvalds1da177e2005-04-16 15:20:36 -070097
98/***** Prototypes for raylink functions **************************************/
99static int asc_to_int(char a);
100static void authenticate(ray_dev_t *local);
101static int build_auth_frame(ray_dev_t *local, UCHAR *dest, int auth_type);
102static void authenticate_timeout(u_long);
103static int get_free_ccs(ray_dev_t *local);
104static int get_free_tx_ccs(ray_dev_t *local);
105static void init_startup_params(ray_dev_t *local);
106static int parse_addr(char *in_str, UCHAR *out);
John Daiker141fa612009-03-10 06:59:54 -0700107static int ray_hw_xmit(unsigned char *data, int len, struct net_device *dev, UCHAR type);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700108static int ray_init(struct net_device *dev);
109static int interrupt_ecf(ray_dev_t *local, int ccs);
110static void ray_reset(struct net_device *dev);
111static void ray_update_parm(struct net_device *dev, UCHAR objid, UCHAR *value, int len);
112static void verify_dl_startup(u_long);
113
114/* Prototypes for interrpt time functions **********************************/
John Daiker141fa612009-03-10 06:59:54 -0700115static irqreturn_t ray_interrupt(int reg, void *dev_id);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700116static void clear_interrupt(ray_dev_t *local);
John Daiker141fa612009-03-10 06:59:54 -0700117static void rx_deauthenticate(ray_dev_t *local, struct rcs __iomem *prcs,
118 unsigned int pkt_addr, int rx_len);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700119static int copy_from_rx_buff(ray_dev_t *local, UCHAR *dest, int pkt_addr, int len);
120static void ray_rx(struct net_device *dev, ray_dev_t *local, struct rcs __iomem *prcs);
121static void release_frag_chain(ray_dev_t *local, struct rcs __iomem *prcs);
122static void rx_authenticate(ray_dev_t *local, struct rcs __iomem *prcs,
John Daiker141fa612009-03-10 06:59:54 -0700123 unsigned int pkt_addr, int rx_len);
124static void rx_data(struct net_device *dev, struct rcs __iomem *prcs,
125 unsigned int pkt_addr, int rx_len);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700126static void associate(ray_dev_t *local);
127
128/* Card command functions */
129static int dl_startup_params(struct net_device *dev);
130static void join_net(u_long local);
131static void start_net(u_long local);
132/* void start_net(ray_dev_t *local); */
133
134/*===========================================================================*/
135/* Parameters that can be set with 'insmod' */
136
137/* ADHOC=0, Infrastructure=1 */
138static int net_type = ADHOC;
139
140/* Hop dwell time in Kus (1024 us units defined by 802.11) */
141static int hop_dwell = 128;
142
143/* Beacon period in Kus */
144static int beacon_period = 256;
145
146/* power save mode (0 = off, 1 = save power) */
147static int psm;
148
149/* String for network's Extended Service Set ID. 32 Characters max */
150static char *essid;
151
152/* Default to encapsulation unless translation requested */
153static int translate = 1;
154
155static int country = USA;
156
157static int sniffer;
158
159static int bc;
160
161/* 48 bit physical card address if overriding card's real physical
162 * address is required. Since IEEE 802.11 addresses are 48 bits
163 * like ethernet, an int can't be used, so a string is used. To
164 * allow use of addresses starting with a decimal digit, the first
165 * character must be a letter and will be ignored. This letter is
166 * followed by up to 12 hex digits which are the address. If less
167 * than 12 digits are used, the address will be left filled with 0's.
168 * Note that bit 0 of the first byte is the broadcast bit, and evil
169 * things will happen if it is not 0 in a card address.
170 */
171static char *phy_addr = NULL;
172
173
Dominik Brodowskifba395e2006-03-31 17:21:06 +0200174/* A struct pcmcia_device structure has fields for most things that are needed
Linus Torvalds1da177e2005-04-16 15:20:36 -0700175 to keep track of a socket, but there will usually be some device
176 specific information that also needs to be kept track of. The
Dominik Brodowskifba395e2006-03-31 17:21:06 +0200177 'priv' pointer in a struct pcmcia_device structure can be used to point to
Linus Torvalds1da177e2005-04-16 15:20:36 -0700178 a device-specific private data structure, like this.
179*/
180static unsigned int ray_mem_speed = 500;
181
Dominik Brodowskifd238232006-03-05 10:45:09 +0100182/* WARNING: THIS DRIVER IS NOT CAPABLE OF HANDLING MULTIPLE DEVICES! */
183static struct pcmcia_device *this_device = NULL;
184
Linus Torvalds1da177e2005-04-16 15:20:36 -0700185MODULE_AUTHOR("Corey Thomas <corey@world.std.com>");
186MODULE_DESCRIPTION("Raylink/WebGear wireless LAN driver");
187MODULE_LICENSE("GPL");
188
189module_param(net_type, int, 0);
190module_param(hop_dwell, int, 0);
191module_param(beacon_period, int, 0);
192module_param(psm, int, 0);
193module_param(essid, charp, 0);
194module_param(translate, int, 0);
195module_param(country, int, 0);
196module_param(sniffer, int, 0);
197module_param(bc, int, 0);
198module_param(phy_addr, charp, 0);
199module_param(ray_mem_speed, int, 0);
200
201static UCHAR b5_default_startup_parms[] = {
John Daiker141fa612009-03-10 06:59:54 -0700202 0, 0, /* Adhoc station */
203 'L', 'I', 'N', 'U', 'X', 0, 0, 0, /* 32 char ESSID */
204 0, 0, 0, 0, 0, 0, 0, 0,
205 0, 0, 0, 0, 0, 0, 0, 0,
206 0, 0, 0, 0, 0, 0, 0, 0,
207 1, 0, /* Active scan, CA Mode */
208 0, 0, 0, 0, 0, 0, /* No default MAC addr */
209 0x7f, 0xff, /* Frag threshold */
210 0x00, 0x80, /* Hop time 128 Kus */
211 0x01, 0x00, /* Beacon period 256 Kus */
212 0x01, 0x07, 0xa3, /* DTIM, retries, ack timeout */
213 0x1d, 0x82, 0x4e, /* SIFS, DIFS, PIFS */
214 0x7f, 0xff, /* RTS threshold */
215 0x04, 0xe2, 0x38, 0xA4, /* scan_dwell, max_scan_dwell */
216 0x05, /* assoc resp timeout thresh */
217 0x08, 0x02, 0x08, /* adhoc, infra, super cycle max */
218 0, /* Promiscuous mode */
219 0x0c, 0x0bd, /* Unique word */
220 0x32, /* Slot time */
221 0xff, 0xff, /* roam-low snr, low snr count */
222 0x05, 0xff, /* Infra, adhoc missed bcn thresh */
223 0x01, 0x0b, 0x4f, /* USA, hop pattern, hop pat length */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700224/* b4 - b5 differences start here */
John Daiker141fa612009-03-10 06:59:54 -0700225 0x00, 0x3f, /* CW max */
226 0x00, 0x0f, /* CW min */
227 0x04, 0x08, /* Noise gain, limit offset */
228 0x28, 0x28, /* det rssi, med busy offsets */
229 7, /* det sync thresh */
230 0, 2, 2, /* test mode, min, max */
231 0, /* allow broadcast SSID probe resp */
232 0, 0, /* privacy must start, can join */
233 2, 0, 0, 0, 0, 0, 0, 0 /* basic rate set */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700234};
235
236static UCHAR b4_default_startup_parms[] = {
John Daiker141fa612009-03-10 06:59:54 -0700237 0, 0, /* Adhoc station */
238 'L', 'I', 'N', 'U', 'X', 0, 0, 0, /* 32 char ESSID */
239 0, 0, 0, 0, 0, 0, 0, 0,
240 0, 0, 0, 0, 0, 0, 0, 0,
241 0, 0, 0, 0, 0, 0, 0, 0,
242 1, 0, /* Active scan, CA Mode */
243 0, 0, 0, 0, 0, 0, /* No default MAC addr */
244 0x7f, 0xff, /* Frag threshold */
245 0x02, 0x00, /* Hop time */
246 0x00, 0x01, /* Beacon period */
247 0x01, 0x07, 0xa3, /* DTIM, retries, ack timeout */
248 0x1d, 0x82, 0xce, /* SIFS, DIFS, PIFS */
249 0x7f, 0xff, /* RTS threshold */
250 0xfb, 0x1e, 0xc7, 0x5c, /* scan_dwell, max_scan_dwell */
251 0x05, /* assoc resp timeout thresh */
252 0x04, 0x02, 0x4, /* adhoc, infra, super cycle max */
253 0, /* Promiscuous mode */
254 0x0c, 0x0bd, /* Unique word */
255 0x4e, /* Slot time (TBD seems wrong) */
256 0xff, 0xff, /* roam-low snr, low snr count */
257 0x05, 0xff, /* Infra, adhoc missed bcn thresh */
258 0x01, 0x0b, 0x4e, /* USA, hop pattern, hop pat length */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700259/* b4 - b5 differences start here */
John Daiker141fa612009-03-10 06:59:54 -0700260 0x3f, 0x0f, /* CW max, min */
261 0x04, 0x08, /* Noise gain, limit offset */
262 0x28, 0x28, /* det rssi, med busy offsets */
263 7, /* det sync thresh */
264 0, 2, 2 /* test mode, min, max */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700265};
John Daiker141fa612009-03-10 06:59:54 -0700266
Linus Torvalds1da177e2005-04-16 15:20:36 -0700267/*===========================================================================*/
John Daiker141fa612009-03-10 06:59:54 -0700268static unsigned char eth2_llc[] = { 0xaa, 0xaa, 3, 0, 0, 0 };
Linus Torvalds1da177e2005-04-16 15:20:36 -0700269
270static char hop_pattern_length[] = { 1,
John Daiker141fa612009-03-10 06:59:54 -0700271 USA_HOP_MOD, EUROPE_HOP_MOD,
272 JAPAN_HOP_MOD, KOREA_HOP_MOD,
273 SPAIN_HOP_MOD, FRANCE_HOP_MOD,
274 ISRAEL_HOP_MOD, AUSTRALIA_HOP_MOD,
275 JAPAN_TEST_HOP_MOD
Linus Torvalds1da177e2005-04-16 15:20:36 -0700276};
277
John Daiker141fa612009-03-10 06:59:54 -0700278static char rcsid[] =
279 "Raylink/WebGear wireless LAN - Corey <Thomas corey@world.std.com>";
Linus Torvalds1da177e2005-04-16 15:20:36 -0700280
Stephen Hemminger32f5a332009-03-20 19:36:28 +0000281static const struct net_device_ops ray_netdev_ops = {
282 .ndo_init = ray_dev_init,
283 .ndo_open = ray_open,
284 .ndo_stop = ray_dev_close,
285 .ndo_start_xmit = ray_dev_start_xmit,
286 .ndo_set_config = ray_dev_config,
287 .ndo_get_stats = ray_get_stats,
288 .ndo_set_multicast_list = set_multicast_list,
289 .ndo_change_mtu = eth_change_mtu,
290 .ndo_set_mac_address = eth_mac_addr,
291 .ndo_validate_addr = eth_validate_addr,
292};
293
Linus Torvalds1da177e2005-04-16 15:20:36 -0700294/*=============================================================================
295 ray_attach() creates an "instance" of the driver, allocating
296 local data structures for one device. The device is registered
297 with Card Services.
298 The dev_link structure is initialized, but we don't actually
299 configure the card at this point -- we wait until we receive a
300 card insertion event.
301=============================================================================*/
Dominik Brodowski15b99ac2006-03-31 17:26:06 +0200302static int ray_probe(struct pcmcia_device *p_dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700303{
John Daiker141fa612009-03-10 06:59:54 -0700304 ray_dev_t *local;
305 struct net_device *dev;
Dominik Brodowskifd238232006-03-05 10:45:09 +0100306
Dominik Brodowski624dd662009-10-24 15:52:44 +0200307 dev_dbg(&p_dev->dev, "ray_attach()\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700308
John Daiker141fa612009-03-10 06:59:54 -0700309 /* Allocate space for private device-specific data */
310 dev = alloc_etherdev(sizeof(ray_dev_t));
311 if (!dev)
312 goto fail_alloc_dev;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700313
John Daiker141fa612009-03-10 06:59:54 -0700314 local = netdev_priv(dev);
315 local->finder = p_dev;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700316
John Daiker141fa612009-03-10 06:59:54 -0700317 /* The io structure describes IO port mapping. None used here */
Dominik Brodowski90abdc32010-07-24 17:23:51 +0200318 p_dev->resource[0]->end = 0;
319 p_dev->resource[0]->flags |= IO_DATA_PATH_WIDTH_8;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700320
John Daiker141fa612009-03-10 06:59:54 -0700321 /* General socket configuration */
322 p_dev->conf.Attributes = CONF_ENABLE_IRQ;
323 p_dev->conf.IntType = INT_MEMORY_AND_IO;
324 p_dev->conf.ConfigIndex = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700325
John Daiker141fa612009-03-10 06:59:54 -0700326 p_dev->priv = dev;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700327
John Daiker141fa612009-03-10 06:59:54 -0700328 local->finder = p_dev;
329 local->card_status = CARD_INSERTED;
330 local->authentication_state = UNAUTHENTICATED;
331 local->num_multi = 0;
Dominik Brodowski624dd662009-10-24 15:52:44 +0200332 dev_dbg(&p_dev->dev, "ray_attach p_dev = %p, dev = %p, local = %p, intr = %p\n",
John Daiker141fa612009-03-10 06:59:54 -0700333 p_dev, dev, local, &ray_interrupt);
334
335 /* Raylink entries in the device structure */
Stephen Hemminger32f5a332009-03-20 19:36:28 +0000336 dev->netdev_ops = &ray_netdev_ops;
John Daiker141fa612009-03-10 06:59:54 -0700337 SET_ETHTOOL_OPS(dev, &netdev_ethtool_ops);
338 dev->wireless_handlers = &ray_handler_def;
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -0700339#ifdef WIRELESS_SPY
John Daiker141fa612009-03-10 06:59:54 -0700340 local->wireless_data.spy_data = &local->spy_data;
341 dev->wireless_data = &local->wireless_data;
342#endif /* WIRELESS_SPY */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700343
Linus Torvalds1da177e2005-04-16 15:20:36 -0700344
Dominik Brodowski624dd662009-10-24 15:52:44 +0200345 dev_dbg(&p_dev->dev, "ray_cs ray_attach calling ether_setup.)\n");
John Daiker141fa612009-03-10 06:59:54 -0700346 netif_stop_queue(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700347
John Daiker141fa612009-03-10 06:59:54 -0700348 init_timer(&local->timer);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700349
John Daiker141fa612009-03-10 06:59:54 -0700350 this_device = p_dev;
351 return ray_config(p_dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700352
353fail_alloc_dev:
John Daiker141fa612009-03-10 06:59:54 -0700354 return -ENOMEM;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700355} /* ray_attach */
John Daiker141fa612009-03-10 06:59:54 -0700356
Linus Torvalds1da177e2005-04-16 15:20:36 -0700357/*=============================================================================
358 This deletes a driver "instance". The device is de-registered
359 with Card Services. If it has been released, all local data
360 structures are freed. Otherwise, the structures will be freed
361 when the device is released.
362=============================================================================*/
Dominik Brodowskifba395e2006-03-31 17:21:06 +0200363static void ray_detach(struct pcmcia_device *link)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700364{
John Daiker141fa612009-03-10 06:59:54 -0700365 struct net_device *dev;
366 ray_dev_t *local;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700367
Dominik Brodowski624dd662009-10-24 15:52:44 +0200368 dev_dbg(&link->dev, "ray_detach\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700369
John Daiker141fa612009-03-10 06:59:54 -0700370 this_device = NULL;
371 dev = link->priv;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700372
John Daiker141fa612009-03-10 06:59:54 -0700373 ray_release(link);
Dominik Brodowskicc3b4862005-11-14 21:23:14 +0100374
John Daiker141fa612009-03-10 06:59:54 -0700375 local = netdev_priv(dev);
376 del_timer(&local->timer);
Dominik Brodowskicc3b4862005-11-14 21:23:14 +0100377
John Daiker141fa612009-03-10 06:59:54 -0700378 if (link->priv) {
Dominik Brodowskic7c2fa02010-03-20 19:39:26 +0100379 unregister_netdev(dev);
John Daiker141fa612009-03-10 06:59:54 -0700380 free_netdev(dev);
381 }
Dominik Brodowski624dd662009-10-24 15:52:44 +0200382 dev_dbg(&link->dev, "ray_cs ray_detach ending\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700383} /* ray_detach */
John Daiker141fa612009-03-10 06:59:54 -0700384
Linus Torvalds1da177e2005-04-16 15:20:36 -0700385/*=============================================================================
386 ray_config() is run after a CARD_INSERTION event
387 is received, to configure the PCMCIA socket, and to make the
388 ethernet device available to the system.
389=============================================================================*/
Linus Torvalds1da177e2005-04-16 15:20:36 -0700390#define MAX_TUPLE_SIZE 128
Dominik Brodowski15b99ac2006-03-31 17:26:06 +0200391static int ray_config(struct pcmcia_device *link)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700392{
Dominik Brodowski624dd662009-10-24 15:52:44 +0200393 int ret = 0;
John Daiker141fa612009-03-10 06:59:54 -0700394 int i;
395 win_req_t req;
John Daiker141fa612009-03-10 06:59:54 -0700396 struct net_device *dev = (struct net_device *)link->priv;
397 ray_dev_t *local = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700398
Dominik Brodowski624dd662009-10-24 15:52:44 +0200399 dev_dbg(&link->dev, "ray_config\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700400
John Daiker141fa612009-03-10 06:59:54 -0700401 /* Determine card type and firmware version */
402 printk(KERN_INFO "ray_cs Detected: %s%s%s%s\n",
403 link->prod_id[0] ? link->prod_id[0] : " ",
404 link->prod_id[1] ? link->prod_id[1] : " ",
405 link->prod_id[2] ? link->prod_id[2] : " ",
406 link->prod_id[3] ? link->prod_id[3] : " ");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700407
John Daiker141fa612009-03-10 06:59:54 -0700408 /* Now allocate an interrupt line. Note that this does not
409 actually assign a handler to the interrupt.
410 */
Dominik Brodowskieb141202010-03-07 12:21:16 +0100411 ret = pcmcia_request_irq(link, ray_interrupt);
Dominik Brodowski624dd662009-10-24 15:52:44 +0200412 if (ret)
413 goto failed;
Dominik Brodowskieb141202010-03-07 12:21:16 +0100414 dev->irq = link->irq;
John Daiker141fa612009-03-10 06:59:54 -0700415
416 /* This actually configures the PCMCIA socket -- setting up
417 the I/O windows and the interrupt mapping.
418 */
Dominik Brodowski624dd662009-10-24 15:52:44 +0200419 ret = pcmcia_request_configuration(link, &link->conf);
420 if (ret)
421 goto failed;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700422
423/*** Set up 32k window for shared memory (transmit and control) ************/
John Daiker141fa612009-03-10 06:59:54 -0700424 req.Attributes =
425 WIN_DATA_WIDTH_8 | WIN_MEMORY_TYPE_CM | WIN_ENABLE | WIN_USE_WAIT;
426 req.Base = 0;
427 req.Size = 0x8000;
428 req.AccessSpeed = ray_mem_speed;
Dominik Brodowski6838b032009-11-03 01:31:52 +0100429 ret = pcmcia_request_window(link, &req, &link->win);
Dominik Brodowski624dd662009-10-24 15:52:44 +0200430 if (ret)
431 goto failed;
Dominik Brodowskib5cb2592010-07-24 18:46:42 +0200432 ret = pcmcia_map_mem_page(link, link->win, 0);
Dominik Brodowski624dd662009-10-24 15:52:44 +0200433 if (ret)
434 goto failed;
John Daiker141fa612009-03-10 06:59:54 -0700435 local->sram = ioremap(req.Base, req.Size);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700436
437/*** Set up 16k window for shared memory (receive buffer) ***************/
John Daiker141fa612009-03-10 06:59:54 -0700438 req.Attributes =
439 WIN_DATA_WIDTH_8 | WIN_MEMORY_TYPE_CM | WIN_ENABLE | WIN_USE_WAIT;
440 req.Base = 0;
441 req.Size = 0x4000;
442 req.AccessSpeed = ray_mem_speed;
Dominik Brodowski6838b032009-11-03 01:31:52 +0100443 ret = pcmcia_request_window(link, &req, &local->rmem_handle);
Dominik Brodowski624dd662009-10-24 15:52:44 +0200444 if (ret)
445 goto failed;
Dominik Brodowskib5cb2592010-07-24 18:46:42 +0200446 ret = pcmcia_map_mem_page(link, local->rmem_handle, 0x8000);
Dominik Brodowski624dd662009-10-24 15:52:44 +0200447 if (ret)
448 goto failed;
John Daiker141fa612009-03-10 06:59:54 -0700449 local->rmem = ioremap(req.Base, req.Size);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700450
451/*** Set up window for attribute memory ***********************************/
John Daiker141fa612009-03-10 06:59:54 -0700452 req.Attributes =
453 WIN_DATA_WIDTH_8 | WIN_MEMORY_TYPE_AM | WIN_ENABLE | WIN_USE_WAIT;
454 req.Base = 0;
455 req.Size = 0x1000;
456 req.AccessSpeed = ray_mem_speed;
Dominik Brodowski6838b032009-11-03 01:31:52 +0100457 ret = pcmcia_request_window(link, &req, &local->amem_handle);
Dominik Brodowski624dd662009-10-24 15:52:44 +0200458 if (ret)
459 goto failed;
Dominik Brodowskib5cb2592010-07-24 18:46:42 +0200460 ret = pcmcia_map_mem_page(link, local->amem_handle, 0);
Dominik Brodowski624dd662009-10-24 15:52:44 +0200461 if (ret)
462 goto failed;
John Daiker141fa612009-03-10 06:59:54 -0700463 local->amem = ioremap(req.Base, req.Size);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700464
Dominik Brodowski624dd662009-10-24 15:52:44 +0200465 dev_dbg(&link->dev, "ray_config sram=%p\n", local->sram);
466 dev_dbg(&link->dev, "ray_config rmem=%p\n", local->rmem);
467 dev_dbg(&link->dev, "ray_config amem=%p\n", local->amem);
John Daiker141fa612009-03-10 06:59:54 -0700468 if (ray_init(dev) < 0) {
469 ray_release(link);
470 return -ENODEV;
471 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700472
Dominik Brodowskidd2e5a12009-11-03 10:27:34 +0100473 SET_NETDEV_DEV(dev, &link->dev);
John Daiker141fa612009-03-10 06:59:54 -0700474 i = register_netdev(dev);
475 if (i != 0) {
476 printk("ray_config register_netdev() failed\n");
477 ray_release(link);
478 return i;
479 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700480
John Daiker141fa612009-03-10 06:59:54 -0700481 printk(KERN_INFO "%s: RayLink, irq %d, hw_addr %pM\n",
482 dev->name, dev->irq, dev->dev_addr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700483
John Daiker141fa612009-03-10 06:59:54 -0700484 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700485
Dominik Brodowski624dd662009-10-24 15:52:44 +0200486failed:
John Daiker141fa612009-03-10 06:59:54 -0700487 ray_release(link);
488 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700489} /* ray_config */
490
491static inline struct ccs __iomem *ccs_base(ray_dev_t *dev)
492{
493 return dev->sram + CCS_BASE;
494}
495
496static inline struct rcs __iomem *rcs_base(ray_dev_t *dev)
497{
498 /*
499 * This looks nonsensical, since there is a separate
500 * RCS_BASE. But the difference between a "struct rcs"
501 * and a "struct ccs" ends up being in the _index_ off
502 * the base, so the base pointer is the same for both
503 * ccs/rcs.
504 */
505 return dev->sram + CCS_BASE;
506}
507
508/*===========================================================================*/
509static int ray_init(struct net_device *dev)
510{
John Daiker141fa612009-03-10 06:59:54 -0700511 int i;
512 UCHAR *p;
513 struct ccs __iomem *pccs;
514 ray_dev_t *local = netdev_priv(dev);
515 struct pcmcia_device *link = local->finder;
Dominik Brodowski624dd662009-10-24 15:52:44 +0200516 dev_dbg(&link->dev, "ray_init(0x%p)\n", dev);
John Daiker141fa612009-03-10 06:59:54 -0700517 if (!(pcmcia_dev_present(link))) {
Dominik Brodowski624dd662009-10-24 15:52:44 +0200518 dev_dbg(&link->dev, "ray_init - device not present\n");
John Daiker141fa612009-03-10 06:59:54 -0700519 return -1;
520 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700521
John Daiker141fa612009-03-10 06:59:54 -0700522 local->net_type = net_type;
523 local->sta_type = TYPE_STA;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700524
John Daiker141fa612009-03-10 06:59:54 -0700525 /* Copy the startup results to local memory */
526 memcpy_fromio(&local->startup_res, local->sram + ECF_TO_HOST_BASE,
527 sizeof(struct startup_res_6));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700528
John Daiker141fa612009-03-10 06:59:54 -0700529 /* Check Power up test status and get mac address from card */
530 if (local->startup_res.startup_word != 0x80) {
531 printk(KERN_INFO "ray_init ERROR card status = %2x\n",
532 local->startup_res.startup_word);
533 local->card_status = CARD_INIT_ERROR;
534 return -1;
535 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700536
John Daiker141fa612009-03-10 06:59:54 -0700537 local->fw_ver = local->startup_res.firmware_version[0];
538 local->fw_bld = local->startup_res.firmware_version[1];
539 local->fw_var = local->startup_res.firmware_version[2];
Frans Popcb01b092010-03-24 19:46:34 +0100540 dev_dbg(&link->dev, "ray_init firmware version %d.%d\n", local->fw_ver,
John Daiker141fa612009-03-10 06:59:54 -0700541 local->fw_bld);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700542
John Daiker141fa612009-03-10 06:59:54 -0700543 local->tib_length = 0x20;
544 if ((local->fw_ver == 5) && (local->fw_bld >= 30))
545 local->tib_length = local->startup_res.tib_length;
Dominik Brodowski624dd662009-10-24 15:52:44 +0200546 dev_dbg(&link->dev, "ray_init tib_length = 0x%02x\n", local->tib_length);
John Daiker141fa612009-03-10 06:59:54 -0700547 /* Initialize CCS's to buffer free state */
548 pccs = ccs_base(local);
549 for (i = 0; i < NUMBER_OF_CCS; i++) {
550 writeb(CCS_BUFFER_FREE, &(pccs++)->buffer_status);
551 }
552 init_startup_params(local);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700553
John Daiker141fa612009-03-10 06:59:54 -0700554 /* copy mac address to startup parameters */
555 if (parse_addr(phy_addr, local->sparm.b4.a_mac_addr)) {
556 p = local->sparm.b4.a_mac_addr;
557 } else {
558 memcpy(&local->sparm.b4.a_mac_addr,
559 &local->startup_res.station_addr, ADDRLEN);
560 p = local->sparm.b4.a_mac_addr;
561 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700562
John Daiker141fa612009-03-10 06:59:54 -0700563 clear_interrupt(local); /* Clear any interrupt from the card */
564 local->card_status = CARD_AWAITING_PARAM;
Dominik Brodowski624dd662009-10-24 15:52:44 +0200565 dev_dbg(&link->dev, "ray_init ending\n");
John Daiker141fa612009-03-10 06:59:54 -0700566 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700567} /* ray_init */
John Daiker141fa612009-03-10 06:59:54 -0700568
Linus Torvalds1da177e2005-04-16 15:20:36 -0700569/*===========================================================================*/
570/* Download startup parameters to the card and command it to read them */
571static int dl_startup_params(struct net_device *dev)
572{
John Daiker141fa612009-03-10 06:59:54 -0700573 int ccsindex;
574 ray_dev_t *local = netdev_priv(dev);
575 struct ccs __iomem *pccs;
576 struct pcmcia_device *link = local->finder;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700577
Dominik Brodowski624dd662009-10-24 15:52:44 +0200578 dev_dbg(&link->dev, "dl_startup_params entered\n");
John Daiker141fa612009-03-10 06:59:54 -0700579 if (!(pcmcia_dev_present(link))) {
Dominik Brodowski624dd662009-10-24 15:52:44 +0200580 dev_dbg(&link->dev, "ray_cs dl_startup_params - device not present\n");
John Daiker141fa612009-03-10 06:59:54 -0700581 return -1;
582 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700583
John Daiker141fa612009-03-10 06:59:54 -0700584 /* Copy parameters to host to ECF area */
585 if (local->fw_ver == 0x55)
586 memcpy_toio(local->sram + HOST_TO_ECF_BASE, &local->sparm.b4,
587 sizeof(struct b4_startup_params));
588 else
589 memcpy_toio(local->sram + HOST_TO_ECF_BASE, &local->sparm.b5,
590 sizeof(struct b5_startup_params));
591
592 /* Fill in the CCS fields for the ECF */
593 if ((ccsindex = get_free_ccs(local)) < 0)
594 return -1;
595 local->dl_param_ccs = ccsindex;
596 pccs = ccs_base(local) + ccsindex;
597 writeb(CCS_DOWNLOAD_STARTUP_PARAMS, &pccs->cmd);
Dominik Brodowski624dd662009-10-24 15:52:44 +0200598 dev_dbg(&link->dev, "dl_startup_params start ccsindex = %d\n",
John Daiker141fa612009-03-10 06:59:54 -0700599 local->dl_param_ccs);
600 /* Interrupt the firmware to process the command */
601 if (interrupt_ecf(local, ccsindex)) {
602 printk(KERN_INFO "ray dl_startup_params failed - "
603 "ECF not ready for intr\n");
604 local->card_status = CARD_DL_PARAM_ERROR;
605 writeb(CCS_BUFFER_FREE, &(pccs++)->buffer_status);
606 return -2;
607 }
608 local->card_status = CARD_DL_PARAM;
609 /* Start kernel timer to wait for dl startup to complete. */
610 local->timer.expires = jiffies + HZ / 2;
611 local->timer.data = (long)local;
612 local->timer.function = &verify_dl_startup;
613 add_timer(&local->timer);
Dominik Brodowski624dd662009-10-24 15:52:44 +0200614 dev_dbg(&link->dev,
John Daiker141fa612009-03-10 06:59:54 -0700615 "ray_cs dl_startup_params started timer for verify_dl_startup\n");
616 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700617} /* dl_startup_params */
John Daiker141fa612009-03-10 06:59:54 -0700618
Linus Torvalds1da177e2005-04-16 15:20:36 -0700619/*===========================================================================*/
620static void init_startup_params(ray_dev_t *local)
621{
John Daiker141fa612009-03-10 06:59:54 -0700622 int i;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700623
John Daiker141fa612009-03-10 06:59:54 -0700624 if (country > JAPAN_TEST)
625 country = USA;
626 else if (country < USA)
627 country = USA;
628 /* structure for hop time and beacon period is defined here using
629 * New 802.11D6.1 format. Card firmware is still using old format
630 * until version 6.
631 * Before After
632 * a_hop_time ms byte a_hop_time ms byte
633 * a_hop_time 2s byte a_hop_time ls byte
634 * a_hop_time ls byte a_beacon_period ms byte
635 * a_beacon_period a_beacon_period ls byte
636 *
637 * a_hop_time = uS a_hop_time = KuS
638 * a_beacon_period = hops a_beacon_period = KuS
639 *//* 64ms = 010000 */
640 if (local->fw_ver == 0x55) {
641 memcpy((UCHAR *) &local->sparm.b4, b4_default_startup_parms,
642 sizeof(struct b4_startup_params));
643 /* Translate sane kus input values to old build 4/5 format */
644 /* i = hop time in uS truncated to 3 bytes */
645 i = (hop_dwell * 1024) & 0xffffff;
646 local->sparm.b4.a_hop_time[0] = (i >> 16) & 0xff;
647 local->sparm.b4.a_hop_time[1] = (i >> 8) & 0xff;
648 local->sparm.b4.a_beacon_period[0] = 0;
649 local->sparm.b4.a_beacon_period[1] =
650 ((beacon_period / hop_dwell) - 1) & 0xff;
651 local->sparm.b4.a_curr_country_code = country;
652 local->sparm.b4.a_hop_pattern_length =
653 hop_pattern_length[(int)country] - 1;
654 if (bc) {
655 local->sparm.b4.a_ack_timeout = 0x50;
656 local->sparm.b4.a_sifs = 0x3f;
657 }
658 } else { /* Version 5 uses real kus values */
659 memcpy((UCHAR *) &local->sparm.b5, b5_default_startup_parms,
660 sizeof(struct b5_startup_params));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700661
John Daiker141fa612009-03-10 06:59:54 -0700662 local->sparm.b5.a_hop_time[0] = (hop_dwell >> 8) & 0xff;
663 local->sparm.b5.a_hop_time[1] = hop_dwell & 0xff;
664 local->sparm.b5.a_beacon_period[0] =
665 (beacon_period >> 8) & 0xff;
666 local->sparm.b5.a_beacon_period[1] = beacon_period & 0xff;
667 if (psm)
668 local->sparm.b5.a_power_mgt_state = 1;
669 local->sparm.b5.a_curr_country_code = country;
670 local->sparm.b5.a_hop_pattern_length =
671 hop_pattern_length[(int)country];
672 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700673
John Daiker141fa612009-03-10 06:59:54 -0700674 local->sparm.b4.a_network_type = net_type & 0x01;
675 local->sparm.b4.a_acting_as_ap_status = TYPE_STA;
676
677 if (essid != NULL)
678 strncpy(local->sparm.b4.a_current_ess_id, essid, ESSID_SIZE);
679} /* init_startup_params */
680
Linus Torvalds1da177e2005-04-16 15:20:36 -0700681/*===========================================================================*/
682static void verify_dl_startup(u_long data)
683{
John Daiker141fa612009-03-10 06:59:54 -0700684 ray_dev_t *local = (ray_dev_t *) data;
685 struct ccs __iomem *pccs = ccs_base(local) + local->dl_param_ccs;
686 UCHAR status;
687 struct pcmcia_device *link = local->finder;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700688
John Daiker141fa612009-03-10 06:59:54 -0700689 if (!(pcmcia_dev_present(link))) {
Dominik Brodowski624dd662009-10-24 15:52:44 +0200690 dev_dbg(&link->dev, "ray_cs verify_dl_startup - device not present\n");
John Daiker141fa612009-03-10 06:59:54 -0700691 return;
692 }
Dominik Brodowski624dd662009-10-24 15:52:44 +0200693#if 0
694 {
John Daiker141fa612009-03-10 06:59:54 -0700695 int i;
696 printk(KERN_DEBUG
697 "verify_dl_startup parameters sent via ccs %d:\n",
698 local->dl_param_ccs);
699 for (i = 0; i < sizeof(struct b5_startup_params); i++) {
700 printk(" %2x",
701 (unsigned int)readb(local->sram +
702 HOST_TO_ECF_BASE + i));
703 }
704 printk("\n");
705 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700706#endif
707
John Daiker141fa612009-03-10 06:59:54 -0700708 status = readb(&pccs->buffer_status);
709 if (status != CCS_BUFFER_FREE) {
710 printk(KERN_INFO
711 "Download startup params failed. Status = %d\n",
712 status);
713 local->card_status = CARD_DL_PARAM_ERROR;
714 return;
715 }
716 if (local->sparm.b4.a_network_type == ADHOC)
717 start_net((u_long) local);
718 else
719 join_net((u_long) local);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700720} /* end verify_dl_startup */
John Daiker141fa612009-03-10 06:59:54 -0700721
Linus Torvalds1da177e2005-04-16 15:20:36 -0700722/*===========================================================================*/
723/* Command card to start a network */
724static void start_net(u_long data)
725{
John Daiker141fa612009-03-10 06:59:54 -0700726 ray_dev_t *local = (ray_dev_t *) data;
727 struct ccs __iomem *pccs;
728 int ccsindex;
729 struct pcmcia_device *link = local->finder;
730 if (!(pcmcia_dev_present(link))) {
Dominik Brodowski624dd662009-10-24 15:52:44 +0200731 dev_dbg(&link->dev, "ray_cs start_net - device not present\n");
John Daiker141fa612009-03-10 06:59:54 -0700732 return;
733 }
734 /* Fill in the CCS fields for the ECF */
735 if ((ccsindex = get_free_ccs(local)) < 0)
736 return;
737 pccs = ccs_base(local) + ccsindex;
738 writeb(CCS_START_NETWORK, &pccs->cmd);
739 writeb(0, &pccs->var.start_network.update_param);
740 /* Interrupt the firmware to process the command */
741 if (interrupt_ecf(local, ccsindex)) {
Dominik Brodowski624dd662009-10-24 15:52:44 +0200742 dev_dbg(&link->dev, "ray start net failed - card not ready for intr\n");
John Daiker141fa612009-03-10 06:59:54 -0700743 writeb(CCS_BUFFER_FREE, &(pccs++)->buffer_status);
744 return;
745 }
746 local->card_status = CARD_DOING_ACQ;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700747} /* end start_net */
John Daiker141fa612009-03-10 06:59:54 -0700748
Linus Torvalds1da177e2005-04-16 15:20:36 -0700749/*===========================================================================*/
750/* Command card to join a network */
751static void join_net(u_long data)
752{
John Daiker141fa612009-03-10 06:59:54 -0700753 ray_dev_t *local = (ray_dev_t *) data;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700754
John Daiker141fa612009-03-10 06:59:54 -0700755 struct ccs __iomem *pccs;
756 int ccsindex;
757 struct pcmcia_device *link = local->finder;
758
759 if (!(pcmcia_dev_present(link))) {
Dominik Brodowski624dd662009-10-24 15:52:44 +0200760 dev_dbg(&link->dev, "ray_cs join_net - device not present\n");
John Daiker141fa612009-03-10 06:59:54 -0700761 return;
762 }
763 /* Fill in the CCS fields for the ECF */
764 if ((ccsindex = get_free_ccs(local)) < 0)
765 return;
766 pccs = ccs_base(local) + ccsindex;
767 writeb(CCS_JOIN_NETWORK, &pccs->cmd);
768 writeb(0, &pccs->var.join_network.update_param);
769 writeb(0, &pccs->var.join_network.net_initiated);
770 /* Interrupt the firmware to process the command */
771 if (interrupt_ecf(local, ccsindex)) {
Dominik Brodowski624dd662009-10-24 15:52:44 +0200772 dev_dbg(&link->dev, "ray join net failed - card not ready for intr\n");
John Daiker141fa612009-03-10 06:59:54 -0700773 writeb(CCS_BUFFER_FREE, &(pccs++)->buffer_status);
774 return;
775 }
776 local->card_status = CARD_DOING_ACQ;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700777}
John Daiker141fa612009-03-10 06:59:54 -0700778
Linus Torvalds1da177e2005-04-16 15:20:36 -0700779/*============================================================================
780 After a card is removed, ray_release() will unregister the net
781 device, and release the PCMCIA configuration. If the device is
782 still open, this will be postponed until it is closed.
783=============================================================================*/
Dominik Brodowskifba395e2006-03-31 17:21:06 +0200784static void ray_release(struct pcmcia_device *link)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700785{
John Daiker141fa612009-03-10 06:59:54 -0700786 struct net_device *dev = link->priv;
787 ray_dev_t *local = netdev_priv(dev);
788 int i;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700789
Dominik Brodowski624dd662009-10-24 15:52:44 +0200790 dev_dbg(&link->dev, "ray_release\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700791
John Daiker141fa612009-03-10 06:59:54 -0700792 del_timer(&local->timer);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700793
John Daiker141fa612009-03-10 06:59:54 -0700794 iounmap(local->sram);
795 iounmap(local->rmem);
796 iounmap(local->amem);
797 /* Do bother checking to see if these succeed or not */
Magnus Dammf5560da2006-12-13 19:46:38 +0900798 i = pcmcia_release_window(link, local->amem_handle);
John Daiker141fa612009-03-10 06:59:54 -0700799 if (i != 0)
Dominik Brodowski624dd662009-10-24 15:52:44 +0200800 dev_dbg(&link->dev, "ReleaseWindow(local->amem) ret = %x\n", i);
Magnus Dammf5560da2006-12-13 19:46:38 +0900801 i = pcmcia_release_window(link, local->rmem_handle);
John Daiker141fa612009-03-10 06:59:54 -0700802 if (i != 0)
Dominik Brodowski624dd662009-10-24 15:52:44 +0200803 dev_dbg(&link->dev, "ReleaseWindow(local->rmem) ret = %x\n", i);
John Daiker141fa612009-03-10 06:59:54 -0700804 pcmcia_disable_device(link);
805
Dominik Brodowski624dd662009-10-24 15:52:44 +0200806 dev_dbg(&link->dev, "ray_release ending\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700807}
808
Dominik Brodowskifba395e2006-03-31 17:21:06 +0200809static int ray_suspend(struct pcmcia_device *link)
Dominik Brodowski98e4c282005-11-14 21:21:18 +0100810{
Dominik Brodowski98e4c282005-11-14 21:21:18 +0100811 struct net_device *dev = link->priv;
812
Dominik Brodowskie2d40962006-03-02 00:09:29 +0100813 if (link->open)
Dominik Brodowski8661bb52006-03-02 00:02:33 +0100814 netif_device_detach(dev);
Dominik Brodowski98e4c282005-11-14 21:21:18 +0100815
816 return 0;
817}
818
Dominik Brodowskifba395e2006-03-31 17:21:06 +0200819static int ray_resume(struct pcmcia_device *link)
Dominik Brodowski98e4c282005-11-14 21:21:18 +0100820{
Dominik Brodowski98e4c282005-11-14 21:21:18 +0100821 struct net_device *dev = link->priv;
822
Dominik Brodowskie2d40962006-03-02 00:09:29 +0100823 if (link->open) {
Dominik Brodowski8661bb52006-03-02 00:02:33 +0100824 ray_reset(dev);
825 netif_device_attach(dev);
826 }
Dominik Brodowski98e4c282005-11-14 21:21:18 +0100827
828 return 0;
829}
830
Linus Torvalds1da177e2005-04-16 15:20:36 -0700831/*===========================================================================*/
Hannes Eder2ed5ba82008-12-26 00:12:59 -0800832static int ray_dev_init(struct net_device *dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700833{
834#ifdef RAY_IMMEDIATE_INIT
John Daiker141fa612009-03-10 06:59:54 -0700835 int i;
836#endif /* RAY_IMMEDIATE_INIT */
837 ray_dev_t *local = netdev_priv(dev);
838 struct pcmcia_device *link = local->finder;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700839
Dominik Brodowski624dd662009-10-24 15:52:44 +0200840 dev_dbg(&link->dev, "ray_dev_init(dev=%p)\n", dev);
John Daiker141fa612009-03-10 06:59:54 -0700841 if (!(pcmcia_dev_present(link))) {
Dominik Brodowski624dd662009-10-24 15:52:44 +0200842 dev_dbg(&link->dev, "ray_dev_init - device not present\n");
John Daiker141fa612009-03-10 06:59:54 -0700843 return -1;
844 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700845#ifdef RAY_IMMEDIATE_INIT
John Daiker141fa612009-03-10 06:59:54 -0700846 /* Download startup parameters */
847 if ((i = dl_startup_params(dev)) < 0) {
848 printk(KERN_INFO "ray_dev_init dl_startup_params failed - "
849 "returns 0x%x\n", i);
850 return -1;
851 }
852#else /* RAY_IMMEDIATE_INIT */
853 /* Postpone the card init so that we can still configure the card,
854 * for example using the Wireless Extensions. The init will happen
855 * in ray_open() - Jean II */
Dominik Brodowski624dd662009-10-24 15:52:44 +0200856 dev_dbg(&link->dev,
John Daiker141fa612009-03-10 06:59:54 -0700857 "ray_dev_init: postponing card init to ray_open() ; Status = %d\n",
858 local->card_status);
859#endif /* RAY_IMMEDIATE_INIT */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700860
John Daiker141fa612009-03-10 06:59:54 -0700861 /* copy mac and broadcast addresses to linux device */
Jiri Pirko3a6d54c2009-05-11 23:37:15 +0000862 memcpy(dev->dev_addr, &local->sparm.b4.a_mac_addr, ADDRLEN);
John Daiker141fa612009-03-10 06:59:54 -0700863 memset(dev->broadcast, 0xff, ETH_ALEN);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700864
Dominik Brodowski624dd662009-10-24 15:52:44 +0200865 dev_dbg(&link->dev, "ray_dev_init ending\n");
John Daiker141fa612009-03-10 06:59:54 -0700866 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700867}
John Daiker141fa612009-03-10 06:59:54 -0700868
Linus Torvalds1da177e2005-04-16 15:20:36 -0700869/*===========================================================================*/
870static int ray_dev_config(struct net_device *dev, struct ifmap *map)
871{
John Daiker141fa612009-03-10 06:59:54 -0700872 ray_dev_t *local = netdev_priv(dev);
873 struct pcmcia_device *link = local->finder;
874 /* Dummy routine to satisfy device structure */
Dominik Brodowski624dd662009-10-24 15:52:44 +0200875 dev_dbg(&link->dev, "ray_dev_config(dev=%p,ifmap=%p)\n", dev, map);
John Daiker141fa612009-03-10 06:59:54 -0700876 if (!(pcmcia_dev_present(link))) {
Dominik Brodowski624dd662009-10-24 15:52:44 +0200877 dev_dbg(&link->dev, "ray_dev_config - device not present\n");
John Daiker141fa612009-03-10 06:59:54 -0700878 return -1;
879 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700880
John Daiker141fa612009-03-10 06:59:54 -0700881 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700882}
John Daiker141fa612009-03-10 06:59:54 -0700883
Linus Torvalds1da177e2005-04-16 15:20:36 -0700884/*===========================================================================*/
Stephen Hemmingerd0cf9c02009-08-31 19:50:57 +0000885static netdev_tx_t ray_dev_start_xmit(struct sk_buff *skb,
886 struct net_device *dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700887{
John Daiker141fa612009-03-10 06:59:54 -0700888 ray_dev_t *local = netdev_priv(dev);
889 struct pcmcia_device *link = local->finder;
890 short length = skb->len;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700891
Stephen Hemmingerd0cf9c02009-08-31 19:50:57 +0000892 if (!pcmcia_dev_present(link)) {
Dominik Brodowski624dd662009-10-24 15:52:44 +0200893 dev_dbg(&link->dev, "ray_dev_start_xmit - device not present\n");
Stephen Hemmingerd0cf9c02009-08-31 19:50:57 +0000894 dev_kfree_skb(skb);
895 return NETDEV_TX_OK;
John Daiker141fa612009-03-10 06:59:54 -0700896 }
Stephen Hemmingerd0cf9c02009-08-31 19:50:57 +0000897
Dominik Brodowski624dd662009-10-24 15:52:44 +0200898 dev_dbg(&link->dev, "ray_dev_start_xmit(skb=%p, dev=%p)\n", skb, dev);
John Daiker141fa612009-03-10 06:59:54 -0700899 if (local->authentication_state == NEED_TO_AUTH) {
Dominik Brodowski624dd662009-10-24 15:52:44 +0200900 dev_dbg(&link->dev, "ray_cs Sending authentication request.\n");
John Daiker141fa612009-03-10 06:59:54 -0700901 if (!build_auth_frame(local, local->auth_id, OPEN_AUTH_REQUEST)) {
902 local->authentication_state = AUTHENTICATED;
903 netif_stop_queue(dev);
Patrick McHardy5b548142009-06-12 06:22:29 +0000904 return NETDEV_TX_BUSY;
John Daiker141fa612009-03-10 06:59:54 -0700905 }
906 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700907
John Daiker141fa612009-03-10 06:59:54 -0700908 if (length < ETH_ZLEN) {
909 if (skb_padto(skb, ETH_ZLEN))
Patrick McHardy6ed10652009-06-23 06:03:08 +0000910 return NETDEV_TX_OK;
John Daiker141fa612009-03-10 06:59:54 -0700911 length = ETH_ZLEN;
912 }
913 switch (ray_hw_xmit(skb->data, length, dev, DATA_TYPE)) {
914 case XMIT_NO_CCS:
915 case XMIT_NEED_AUTH:
916 netif_stop_queue(dev);
Patrick McHardy5b548142009-06-12 06:22:29 +0000917 return NETDEV_TX_BUSY;
John Daiker141fa612009-03-10 06:59:54 -0700918 case XMIT_NO_INTR:
919 case XMIT_MSG_BAD:
920 case XMIT_OK:
921 default:
John Daiker141fa612009-03-10 06:59:54 -0700922 dev_kfree_skb(skb);
John Daiker141fa612009-03-10 06:59:54 -0700923 }
Stephen Hemmingerd0cf9c02009-08-31 19:50:57 +0000924
Patrick McHardy6ed10652009-06-23 06:03:08 +0000925 return NETDEV_TX_OK;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700926} /* ray_dev_start_xmit */
John Daiker141fa612009-03-10 06:59:54 -0700927
Linus Torvalds1da177e2005-04-16 15:20:36 -0700928/*===========================================================================*/
John Daiker141fa612009-03-10 06:59:54 -0700929static int ray_hw_xmit(unsigned char *data, int len, struct net_device *dev,
930 UCHAR msg_type)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700931{
John Daiker141fa612009-03-10 06:59:54 -0700932 ray_dev_t *local = netdev_priv(dev);
933 struct ccs __iomem *pccs;
934 int ccsindex;
935 int offset;
936 struct tx_msg __iomem *ptx; /* Address of xmit buffer in PC space */
937 short int addr; /* Address of xmit buffer in card space */
938
Dominik Brodowski624dd662009-10-24 15:52:44 +0200939 pr_debug("ray_hw_xmit(data=%p, len=%d, dev=%p)\n", data, len, dev);
John Daiker141fa612009-03-10 06:59:54 -0700940 if (len + TX_HEADER_LENGTH > TX_BUF_SIZE) {
941 printk(KERN_INFO "ray_hw_xmit packet too large: %d bytes\n",
942 len);
943 return XMIT_MSG_BAD;
944 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700945 switch (ccsindex = get_free_tx_ccs(local)) {
946 case ECCSBUSY:
Dominik Brodowski624dd662009-10-24 15:52:44 +0200947 pr_debug("ray_hw_xmit tx_ccs table busy\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700948 case ECCSFULL:
Dominik Brodowski624dd662009-10-24 15:52:44 +0200949 pr_debug("ray_hw_xmit No free tx ccs\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700950 case ECARDGONE:
John Daiker141fa612009-03-10 06:59:54 -0700951 netif_stop_queue(dev);
952 return XMIT_NO_CCS;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700953 default:
954 break;
955 }
John Daiker141fa612009-03-10 06:59:54 -0700956 addr = TX_BUF_BASE + (ccsindex << 11);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700957
John Daiker141fa612009-03-10 06:59:54 -0700958 if (msg_type == DATA_TYPE) {
959 local->stats.tx_bytes += len;
960 local->stats.tx_packets++;
961 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700962
John Daiker141fa612009-03-10 06:59:54 -0700963 ptx = local->sram + addr;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700964
John Daiker141fa612009-03-10 06:59:54 -0700965 ray_build_header(local, ptx, msg_type, data);
966 if (translate) {
967 offset = translate_frame(local, ptx, data, len);
968 } else { /* Encapsulate frame */
969 /* TBD TIB length will move address of ptx->var */
970 memcpy_toio(&ptx->var, data, len);
971 offset = 0;
972 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700973
John Daiker141fa612009-03-10 06:59:54 -0700974 /* fill in the CCS */
975 pccs = ccs_base(local) + ccsindex;
976 len += TX_HEADER_LENGTH + offset;
977 writeb(CCS_TX_REQUEST, &pccs->cmd);
978 writeb(addr >> 8, &pccs->var.tx_request.tx_data_ptr[0]);
979 writeb(local->tib_length, &pccs->var.tx_request.tx_data_ptr[1]);
980 writeb(len >> 8, &pccs->var.tx_request.tx_data_length[0]);
981 writeb(len & 0xff, &pccs->var.tx_request.tx_data_length[1]);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700982/* TBD still need psm_cam? */
John Daiker141fa612009-03-10 06:59:54 -0700983 writeb(PSM_CAM, &pccs->var.tx_request.pow_sav_mode);
984 writeb(local->net_default_tx_rate, &pccs->var.tx_request.tx_rate);
985 writeb(0, &pccs->var.tx_request.antenna);
Dominik Brodowski624dd662009-10-24 15:52:44 +0200986 pr_debug("ray_hw_xmit default_tx_rate = 0x%x\n",
John Daiker141fa612009-03-10 06:59:54 -0700987 local->net_default_tx_rate);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700988
John Daiker141fa612009-03-10 06:59:54 -0700989 /* Interrupt the firmware to process the command */
990 if (interrupt_ecf(local, ccsindex)) {
Dominik Brodowski624dd662009-10-24 15:52:44 +0200991 pr_debug("ray_hw_xmit failed - ECF not ready for intr\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700992/* TBD very inefficient to copy packet to buffer, and then not
993 send it, but the alternative is to queue the messages and that
994 won't be done for a while. Maybe set tbusy until a CCS is free?
995*/
John Daiker141fa612009-03-10 06:59:54 -0700996 writeb(CCS_BUFFER_FREE, &pccs->buffer_status);
997 return XMIT_NO_INTR;
998 }
999 return XMIT_OK;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001000} /* end ray_hw_xmit */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001001
John Daiker141fa612009-03-10 06:59:54 -07001002/*===========================================================================*/
1003static int translate_frame(ray_dev_t *local, struct tx_msg __iomem *ptx,
1004 unsigned char *data, int len)
1005{
1006 __be16 proto = ((struct ethhdr *)data)->h_proto;
1007 if (ntohs(proto) >= 1536) { /* DIX II ethernet frame */
Dominik Brodowski624dd662009-10-24 15:52:44 +02001008 pr_debug("ray_cs translate_frame DIX II\n");
John Daiker141fa612009-03-10 06:59:54 -07001009 /* Copy LLC header to card buffer */
1010 memcpy_toio(&ptx->var, eth2_llc, sizeof(eth2_llc));
1011 memcpy_toio(((void __iomem *)&ptx->var) + sizeof(eth2_llc),
1012 (UCHAR *) &proto, 2);
1013 if (proto == htons(ETH_P_AARP) || proto == htons(ETH_P_IPX)) {
1014 /* This is the selective translation table, only 2 entries */
1015 writeb(0xf8,
1016 &((struct snaphdr_t __iomem *)ptx->var)->org[3]);
1017 }
1018 /* Copy body of ethernet packet without ethernet header */
1019 memcpy_toio((void __iomem *)&ptx->var +
1020 sizeof(struct snaphdr_t), data + ETH_HLEN,
1021 len - ETH_HLEN);
1022 return (int)sizeof(struct snaphdr_t) - ETH_HLEN;
1023 } else { /* already 802 type, and proto is length */
Dominik Brodowski624dd662009-10-24 15:52:44 +02001024 pr_debug("ray_cs translate_frame 802\n");
John Daiker141fa612009-03-10 06:59:54 -07001025 if (proto == htons(0xffff)) { /* evil netware IPX 802.3 without LLC */
Dominik Brodowski624dd662009-10-24 15:52:44 +02001026 pr_debug("ray_cs translate_frame evil IPX\n");
John Daiker141fa612009-03-10 06:59:54 -07001027 memcpy_toio(&ptx->var, data + ETH_HLEN, len - ETH_HLEN);
1028 return 0 - ETH_HLEN;
1029 }
1030 memcpy_toio(&ptx->var, data + ETH_HLEN, len - ETH_HLEN);
1031 return 0 - ETH_HLEN;
1032 }
1033 /* TBD do other frame types */
1034} /* end translate_frame */
1035
1036/*===========================================================================*/
1037static void ray_build_header(ray_dev_t *local, struct tx_msg __iomem *ptx,
1038 UCHAR msg_type, unsigned char *data)
1039{
1040 writeb(PROTOCOL_VER | msg_type, &ptx->mac.frame_ctl_1);
1041/*** IEEE 802.11 Address field assignments *************
1042 TODS FROMDS addr_1 addr_2 addr_3 addr_4
1043Adhoc 0 0 dest src (terminal) BSSID N/A
1044AP to Terminal 0 1 dest AP(BSSID) source N/A
1045Terminal to AP 1 0 AP(BSSID) src (terminal) dest N/A
1046AP to AP 1 1 dest AP src AP dest source
1047*******************************************************/
1048 if (local->net_type == ADHOC) {
1049 writeb(0, &ptx->mac.frame_ctl_2);
1050 memcpy_toio(ptx->mac.addr_1, ((struct ethhdr *)data)->h_dest,
1051 2 * ADDRLEN);
1052 memcpy_toio(ptx->mac.addr_3, local->bss_id, ADDRLEN);
1053 } else { /* infrastructure */
1054
1055 if (local->sparm.b4.a_acting_as_ap_status) {
1056 writeb(FC2_FROM_DS, &ptx->mac.frame_ctl_2);
1057 memcpy_toio(ptx->mac.addr_1,
1058 ((struct ethhdr *)data)->h_dest, ADDRLEN);
1059 memcpy_toio(ptx->mac.addr_2, local->bss_id, 6);
1060 memcpy_toio(ptx->mac.addr_3,
1061 ((struct ethhdr *)data)->h_source, ADDRLEN);
1062 } else { /* Terminal */
1063
1064 writeb(FC2_TO_DS, &ptx->mac.frame_ctl_2);
1065 memcpy_toio(ptx->mac.addr_1, local->bss_id, ADDRLEN);
1066 memcpy_toio(ptx->mac.addr_2,
1067 ((struct ethhdr *)data)->h_source, ADDRLEN);
1068 memcpy_toio(ptx->mac.addr_3,
1069 ((struct ethhdr *)data)->h_dest, ADDRLEN);
1070 }
1071 }
1072} /* end encapsulate_frame */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001073
1074/*===========================================================================*/
1075
1076static void netdev_get_drvinfo(struct net_device *dev,
1077 struct ethtool_drvinfo *info)
1078{
1079 strcpy(info->driver, "ray_cs");
1080}
1081
Jeff Garzik7282d492006-09-13 14:30:00 -04001082static const struct ethtool_ops netdev_ethtool_ops = {
John Daiker141fa612009-03-10 06:59:54 -07001083 .get_drvinfo = netdev_get_drvinfo,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001084};
1085
1086/*====================================================================*/
1087
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001088/*------------------------------------------------------------------*/
1089/*
1090 * Wireless Handler : get protocol name
1091 */
Joe Perches43ead782010-03-18 18:29:40 -07001092static int ray_get_name(struct net_device *dev, struct iw_request_info *info,
1093 union iwreq_data *wrqu, char *extra)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001094{
Joe Perches43ead782010-03-18 18:29:40 -07001095 strcpy(wrqu->name, "IEEE 802.11-FH");
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001096 return 0;
1097}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001098
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001099/*------------------------------------------------------------------*/
1100/*
1101 * Wireless Handler : set frequency
1102 */
Joe Perches43ead782010-03-18 18:29:40 -07001103static int ray_set_freq(struct net_device *dev, struct iw_request_info *info,
1104 union iwreq_data *wrqu, char *extra)
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001105{
Yoann Padioleau6dbc9c82007-08-03 19:37:16 +02001106 ray_dev_t *local = netdev_priv(dev);
John Daiker141fa612009-03-10 06:59:54 -07001107 int err = -EINPROGRESS; /* Call commit handler */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001108
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001109 /* Reject if card is already initialised */
John Daiker141fa612009-03-10 06:59:54 -07001110 if (local->card_status != CARD_AWAITING_PARAM)
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001111 return -EBUSY;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001112
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001113 /* Setting by channel number */
Joe Perches43ead782010-03-18 18:29:40 -07001114 if ((wrqu->freq.m > USA_HOP_MOD) || (wrqu->freq.e > 0))
Linus Torvalds1da177e2005-04-16 15:20:36 -07001115 err = -EOPNOTSUPP;
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001116 else
Joe Perches43ead782010-03-18 18:29:40 -07001117 local->sparm.b5.a_hop_pattern = wrqu->freq.m;
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001118
1119 return err;
1120}
John Daiker141fa612009-03-10 06:59:54 -07001121
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001122/*------------------------------------------------------------------*/
1123/*
1124 * Wireless Handler : get frequency
1125 */
Joe Perches43ead782010-03-18 18:29:40 -07001126static int ray_get_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);
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001130
Joe Perches43ead782010-03-18 18:29:40 -07001131 wrqu->freq.m = local->sparm.b5.a_hop_pattern;
1132 wrqu->freq.e = 0;
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001133 return 0;
1134}
1135
1136/*------------------------------------------------------------------*/
1137/*
1138 * Wireless Handler : set ESSID
1139 */
Joe Perches43ead782010-03-18 18:29:40 -07001140static int ray_set_essid(struct net_device *dev, struct iw_request_info *info,
1141 union iwreq_data *wrqu, char *extra)
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001142{
Yoann Padioleau6dbc9c82007-08-03 19:37:16 +02001143 ray_dev_t *local = netdev_priv(dev);
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001144
1145 /* Reject if card is already initialised */
John Daiker141fa612009-03-10 06:59:54 -07001146 if (local->card_status != CARD_AWAITING_PARAM)
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001147 return -EBUSY;
1148
1149 /* Check if we asked for `any' */
Joe Perches43ead782010-03-18 18:29:40 -07001150 if (wrqu->essid.flags == 0)
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001151 /* Corey : can you do that ? */
1152 return -EOPNOTSUPP;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001153
Joe Perches43ead782010-03-18 18:29:40 -07001154 /* Check the size of the string */
1155 if (wrqu->essid.length > IW_ESSID_MAX_SIZE)
1156 return -E2BIG;
1157
1158 /* Set the ESSID in the card */
1159 memset(local->sparm.b5.a_current_ess_id, 0, IW_ESSID_MAX_SIZE);
1160 memcpy(local->sparm.b5.a_current_ess_id, extra, wrqu->essid.length);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001161
John Daiker141fa612009-03-10 06:59:54 -07001162 return -EINPROGRESS; /* Call commit handler */
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001163}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001164
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001165/*------------------------------------------------------------------*/
1166/*
1167 * Wireless Handler : get ESSID
1168 */
Joe Perches43ead782010-03-18 18:29:40 -07001169static int ray_get_essid(struct net_device *dev, struct iw_request_info *info,
1170 union iwreq_data *wrqu, char *extra)
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001171{
Yoann Padioleau6dbc9c82007-08-03 19:37:16 +02001172 ray_dev_t *local = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001173
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001174 /* Get the essid that was set */
1175 memcpy(extra, local->sparm.b5.a_current_ess_id, IW_ESSID_MAX_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001176
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001177 /* Push it out ! */
Joe Perches43ead782010-03-18 18:29:40 -07001178 wrqu->essid.length = strlen(extra);
1179 wrqu->essid.flags = 1; /* active */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001180
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001181 return 0;
1182}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001183
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001184/*------------------------------------------------------------------*/
1185/*
1186 * Wireless Handler : get AP address
1187 */
Joe Perches43ead782010-03-18 18:29:40 -07001188static int ray_get_wap(struct net_device *dev, struct iw_request_info *info,
1189 union iwreq_data *wrqu, char *extra)
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001190{
Yoann Padioleau6dbc9c82007-08-03 19:37:16 +02001191 ray_dev_t *local = netdev_priv(dev);
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001192
Joe Perches43ead782010-03-18 18:29:40 -07001193 memcpy(wrqu->ap_addr.sa_data, local->bss_id, ETH_ALEN);
1194 wrqu->ap_addr.sa_family = ARPHRD_ETHER;
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001195
1196 return 0;
1197}
1198
1199/*------------------------------------------------------------------*/
1200/*
1201 * Wireless Handler : set Bit-Rate
1202 */
Joe Perches43ead782010-03-18 18:29:40 -07001203static int ray_set_rate(struct net_device *dev, struct iw_request_info *info,
1204 union iwreq_data *wrqu, char *extra)
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001205{
Yoann Padioleau6dbc9c82007-08-03 19:37:16 +02001206 ray_dev_t *local = netdev_priv(dev);
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001207
1208 /* Reject if card is already initialised */
John Daiker141fa612009-03-10 06:59:54 -07001209 if (local->card_status != CARD_AWAITING_PARAM)
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001210 return -EBUSY;
1211
1212 /* Check if rate is in range */
Joe Perches43ead782010-03-18 18:29:40 -07001213 if ((wrqu->bitrate.value != 1000000) && (wrqu->bitrate.value != 2000000))
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001214 return -EINVAL;
1215
1216 /* Hack for 1.5 Mb/s instead of 2 Mb/s */
John Daiker141fa612009-03-10 06:59:54 -07001217 if ((local->fw_ver == 0x55) && /* Please check */
Joe Perches43ead782010-03-18 18:29:40 -07001218 (wrqu->bitrate.value == 2000000))
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001219 local->net_default_tx_rate = 3;
1220 else
Joe Perches43ead782010-03-18 18:29:40 -07001221 local->net_default_tx_rate = wrqu->bitrate.value / 500000;
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001222
1223 return 0;
1224}
1225
1226/*------------------------------------------------------------------*/
1227/*
1228 * Wireless Handler : get Bit-Rate
1229 */
Joe Perches43ead782010-03-18 18:29:40 -07001230static int ray_get_rate(struct net_device *dev, struct iw_request_info *info,
1231 union iwreq_data *wrqu, char *extra)
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001232{
Yoann Padioleau6dbc9c82007-08-03 19:37:16 +02001233 ray_dev_t *local = netdev_priv(dev);
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001234
John Daiker141fa612009-03-10 06:59:54 -07001235 if (local->net_default_tx_rate == 3)
Joe Perches43ead782010-03-18 18:29:40 -07001236 wrqu->bitrate.value = 2000000; /* Hum... */
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001237 else
Joe Perches43ead782010-03-18 18:29:40 -07001238 wrqu->bitrate.value = local->net_default_tx_rate * 500000;
1239 wrqu->bitrate.fixed = 0; /* We are in auto mode */
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001240
1241 return 0;
1242}
1243
1244/*------------------------------------------------------------------*/
1245/*
1246 * Wireless Handler : set RTS threshold
1247 */
Joe Perches43ead782010-03-18 18:29:40 -07001248static int ray_set_rts(struct net_device *dev, struct iw_request_info *info,
1249 union iwreq_data *wrqu, char *extra)
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001250{
Yoann Padioleau6dbc9c82007-08-03 19:37:16 +02001251 ray_dev_t *local = netdev_priv(dev);
Joe Perches43ead782010-03-18 18:29:40 -07001252 int rthr = wrqu->rts.value;
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001253
1254 /* Reject if card is already initialised */
John Daiker141fa612009-03-10 06:59:54 -07001255 if (local->card_status != CARD_AWAITING_PARAM)
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001256 return -EBUSY;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001257
1258 /* if(wrq->u.rts.fixed == 0) we should complain */
Joe Perches43ead782010-03-18 18:29:40 -07001259 if (wrqu->rts.disabled)
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001260 rthr = 32767;
1261 else {
John Daiker141fa612009-03-10 06:59:54 -07001262 if ((rthr < 0) || (rthr > 2347)) /* What's the max packet size ??? */
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001263 return -EINVAL;
1264 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001265 local->sparm.b5.a_rts_threshold[0] = (rthr >> 8) & 0xFF;
1266 local->sparm.b5.a_rts_threshold[1] = rthr & 0xFF;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001267
John Daiker141fa612009-03-10 06:59:54 -07001268 return -EINPROGRESS; /* Call commit handler */
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001269}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001270
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001271/*------------------------------------------------------------------*/
1272/*
1273 * Wireless Handler : get RTS threshold
1274 */
Joe Perches43ead782010-03-18 18:29:40 -07001275static int ray_get_rts(struct net_device *dev, struct iw_request_info *info,
1276 union iwreq_data *wrqu, char *extra)
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001277{
Yoann Padioleau6dbc9c82007-08-03 19:37:16 +02001278 ray_dev_t *local = netdev_priv(dev);
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001279
Joe Perches43ead782010-03-18 18:29:40 -07001280 wrqu->rts.value = (local->sparm.b5.a_rts_threshold[0] << 8)
John Daiker141fa612009-03-10 06:59:54 -07001281 + local->sparm.b5.a_rts_threshold[1];
Joe Perches43ead782010-03-18 18:29:40 -07001282 wrqu->rts.disabled = (wrqu->rts.value == 32767);
1283 wrqu->rts.fixed = 1;
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001284
1285 return 0;
1286}
1287
1288/*------------------------------------------------------------------*/
1289/*
1290 * Wireless Handler : set Fragmentation threshold
1291 */
Joe Perches43ead782010-03-18 18:29:40 -07001292static int ray_set_frag(struct net_device *dev, struct iw_request_info *info,
1293 union iwreq_data *wrqu, char *extra)
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001294{
Yoann Padioleau6dbc9c82007-08-03 19:37:16 +02001295 ray_dev_t *local = netdev_priv(dev);
Joe Perches43ead782010-03-18 18:29:40 -07001296 int fthr = wrqu->frag.value;
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001297
1298 /* Reject if card is already initialised */
John Daiker141fa612009-03-10 06:59:54 -07001299 if (local->card_status != CARD_AWAITING_PARAM)
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001300 return -EBUSY;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001301
1302 /* if(wrq->u.frag.fixed == 0) should complain */
Joe Perches43ead782010-03-18 18:29:40 -07001303 if (wrqu->frag.disabled)
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001304 fthr = 32767;
1305 else {
John Daiker141fa612009-03-10 06:59:54 -07001306 if ((fthr < 256) || (fthr > 2347)) /* To check out ! */
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001307 return -EINVAL;
1308 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001309 local->sparm.b5.a_frag_threshold[0] = (fthr >> 8) & 0xFF;
1310 local->sparm.b5.a_frag_threshold[1] = fthr & 0xFF;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001311
John Daiker141fa612009-03-10 06:59:54 -07001312 return -EINPROGRESS; /* Call commit handler */
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001313}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001314
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001315/*------------------------------------------------------------------*/
1316/*
1317 * Wireless Handler : get Fragmentation threshold
1318 */
Joe Perches43ead782010-03-18 18:29:40 -07001319static int ray_get_frag(struct net_device *dev, struct iw_request_info *info,
1320 union iwreq_data *wrqu, char *extra)
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001321{
Yoann Padioleau6dbc9c82007-08-03 19:37:16 +02001322 ray_dev_t *local = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001323
Joe Perches43ead782010-03-18 18:29:40 -07001324 wrqu->frag.value = (local->sparm.b5.a_frag_threshold[0] << 8)
John Daiker141fa612009-03-10 06:59:54 -07001325 + local->sparm.b5.a_frag_threshold[1];
Joe Perches43ead782010-03-18 18:29:40 -07001326 wrqu->frag.disabled = (wrqu->frag.value == 32767);
1327 wrqu->frag.fixed = 1;
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001328
1329 return 0;
1330}
1331
1332/*------------------------------------------------------------------*/
1333/*
1334 * Wireless Handler : set Mode of Operation
1335 */
Joe Perches43ead782010-03-18 18:29:40 -07001336static int ray_set_mode(struct net_device *dev, struct iw_request_info *info,
1337 union iwreq_data *wrqu, char *extra)
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001338{
Yoann Padioleau6dbc9c82007-08-03 19:37:16 +02001339 ray_dev_t *local = netdev_priv(dev);
John Daiker141fa612009-03-10 06:59:54 -07001340 int err = -EINPROGRESS; /* Call commit handler */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001341 char card_mode = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001342
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001343 /* Reject if card is already initialised */
John Daiker141fa612009-03-10 06:59:54 -07001344 if (local->card_status != CARD_AWAITING_PARAM)
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001345 return -EBUSY;
1346
Joe Perches43ead782010-03-18 18:29:40 -07001347 switch (wrqu->mode) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001348 case IW_MODE_ADHOC:
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001349 card_mode = 0;
John Daiker141fa612009-03-10 06:59:54 -07001350 /* Fall through */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001351 case IW_MODE_INFRA:
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001352 local->sparm.b5.a_network_type = card_mode;
1353 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001354 default:
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001355 err = -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001356 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001357
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001358 return err;
1359}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001360
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001361/*------------------------------------------------------------------*/
1362/*
1363 * Wireless Handler : get Mode of Operation
1364 */
Joe Perches43ead782010-03-18 18:29:40 -07001365static int ray_get_mode(struct net_device *dev, struct iw_request_info *info,
1366 union iwreq_data *wrqu, char *extra)
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001367{
Yoann Padioleau6dbc9c82007-08-03 19:37:16 +02001368 ray_dev_t *local = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001369
John Daiker141fa612009-03-10 06:59:54 -07001370 if (local->sparm.b5.a_network_type)
Joe Perches43ead782010-03-18 18:29:40 -07001371 wrqu->mode = IW_MODE_INFRA;
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001372 else
Joe Perches43ead782010-03-18 18:29:40 -07001373 wrqu->mode = IW_MODE_ADHOC;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001374
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001375 return 0;
1376}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001377
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001378/*------------------------------------------------------------------*/
1379/*
1380 * Wireless Handler : get range info
1381 */
Joe Perches43ead782010-03-18 18:29:40 -07001382static int ray_get_range(struct net_device *dev, struct iw_request_info *info,
1383 union iwreq_data *wrqu, char *extra)
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001384{
John Daiker141fa612009-03-10 06:59:54 -07001385 struct iw_range *range = (struct iw_range *)extra;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001386
Joe Perches43ead782010-03-18 18:29:40 -07001387 memset(range, 0, sizeof(struct iw_range));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001388
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001389 /* Set the length (very important for backward compatibility) */
Joe Perches43ead782010-03-18 18:29:40 -07001390 wrqu->data.length = sizeof(struct iw_range);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001391
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001392 /* Set the Wireless Extension versions */
1393 range->we_version_compiled = WIRELESS_EXT;
1394 range->we_version_source = 9;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001395
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001396 /* Set information in the range struct */
1397 range->throughput = 1.1 * 1000 * 1000; /* Put the right number here */
John Daiker141fa612009-03-10 06:59:54 -07001398 range->num_channels = hop_pattern_length[(int)country];
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001399 range->num_frequency = 0;
1400 range->max_qual.qual = 0;
1401 range->max_qual.level = 255; /* What's the correct value ? */
1402 range->max_qual.noise = 255; /* Idem */
1403 range->num_bitrates = 2;
1404 range->bitrate[0] = 1000000; /* 1 Mb/s */
1405 range->bitrate[1] = 2000000; /* 2 Mb/s */
1406 return 0;
1407}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001408
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001409/*------------------------------------------------------------------*/
1410/*
1411 * Wireless Private Handler : set framing mode
1412 */
Joe Perches43ead782010-03-18 18:29:40 -07001413static int ray_set_framing(struct net_device *dev, struct iw_request_info *info,
John Daiker141fa612009-03-10 06:59:54 -07001414 union iwreq_data *wrqu, char *extra)
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001415{
1416 translate = *(extra); /* Set framing mode */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001417
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001418 return 0;
1419}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001420
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001421/*------------------------------------------------------------------*/
1422/*
1423 * Wireless Private Handler : get framing mode
1424 */
Joe Perches43ead782010-03-18 18:29:40 -07001425static int ray_get_framing(struct net_device *dev, struct iw_request_info *info,
John Daiker141fa612009-03-10 06:59:54 -07001426 union iwreq_data *wrqu, char *extra)
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001427{
1428 *(extra) = translate;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001429
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001430 return 0;
1431}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001432
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001433/*------------------------------------------------------------------*/
1434/*
1435 * Wireless Private Handler : get country
1436 */
Joe Perches43ead782010-03-18 18:29:40 -07001437static int ray_get_country(struct net_device *dev, struct iw_request_info *info,
John Daiker141fa612009-03-10 06:59:54 -07001438 union iwreq_data *wrqu, char *extra)
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001439{
1440 *(extra) = country;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001441
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001442 return 0;
1443}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001444
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001445/*------------------------------------------------------------------*/
1446/*
1447 * Commit handler : called after a bunch of SET operations
1448 */
Joe Perches43ead782010-03-18 18:29:40 -07001449static int ray_commit(struct net_device *dev, struct iw_request_info *info,
1450 union iwreq_data *wrqu, char *extra)
1451{
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001452 return 0;
1453}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001454
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001455/*------------------------------------------------------------------*/
1456/*
1457 * Stats handler : return Wireless Stats
1458 */
John Daiker141fa612009-03-10 06:59:54 -07001459static iw_stats *ray_get_wireless_stats(struct net_device *dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001460{
John Daiker141fa612009-03-10 06:59:54 -07001461 ray_dev_t *local = netdev_priv(dev);
1462 struct pcmcia_device *link = local->finder;
1463 struct status __iomem *p = local->sram + STATUS_BASE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001464
John Daiker141fa612009-03-10 06:59:54 -07001465 local->wstats.status = local->card_status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001466#ifdef WIRELESS_SPY
John Daiker141fa612009-03-10 06:59:54 -07001467 if ((local->spy_data.spy_number > 0)
1468 && (local->sparm.b5.a_network_type == 0)) {
1469 /* Get it from the first node in spy list */
1470 local->wstats.qual.qual = local->spy_data.spy_stat[0].qual;
1471 local->wstats.qual.level = local->spy_data.spy_stat[0].level;
1472 local->wstats.qual.noise = local->spy_data.spy_stat[0].noise;
1473 local->wstats.qual.updated =
1474 local->spy_data.spy_stat[0].updated;
1475 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001476#endif /* WIRELESS_SPY */
1477
John Daiker141fa612009-03-10 06:59:54 -07001478 if (pcmcia_dev_present(link)) {
1479 local->wstats.qual.noise = readb(&p->rxnoise);
1480 local->wstats.qual.updated |= 4;
1481 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001482
John Daiker141fa612009-03-10 06:59:54 -07001483 return &local->wstats;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001484} /* end ray_get_wireless_stats */
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001485
1486/*------------------------------------------------------------------*/
1487/*
1488 * Structures to export the Wireless Handlers
1489 */
1490
John Daiker141fa612009-03-10 06:59:54 -07001491static const iw_handler ray_handler[] = {
Joe Perches43ead782010-03-18 18:29:40 -07001492 IW_HANDLER(SIOCSIWCOMMIT, ray_commit),
1493 IW_HANDLER(SIOCGIWNAME, ray_get_name),
1494 IW_HANDLER(SIOCSIWFREQ, ray_set_freq),
1495 IW_HANDLER(SIOCGIWFREQ, ray_get_freq),
1496 IW_HANDLER(SIOCSIWMODE, ray_set_mode),
1497 IW_HANDLER(SIOCGIWMODE, ray_get_mode),
1498 IW_HANDLER(SIOCGIWRANGE, ray_get_range),
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001499#ifdef WIRELESS_SPY
Joe Perches270020e2010-03-18 18:29:37 -07001500 IW_HANDLER(SIOCSIWSPY, iw_handler_set_spy),
1501 IW_HANDLER(SIOCGIWSPY, iw_handler_get_spy),
1502 IW_HANDLER(SIOCSIWTHRSPY, iw_handler_set_thrspy),
1503 IW_HANDLER(SIOCGIWTHRSPY, iw_handler_get_thrspy),
John Daiker141fa612009-03-10 06:59:54 -07001504#endif /* WIRELESS_SPY */
Joe Perches43ead782010-03-18 18:29:40 -07001505 IW_HANDLER(SIOCGIWAP, ray_get_wap),
1506 IW_HANDLER(SIOCSIWESSID, ray_set_essid),
1507 IW_HANDLER(SIOCGIWESSID, ray_get_essid),
1508 IW_HANDLER(SIOCSIWRATE, ray_set_rate),
1509 IW_HANDLER(SIOCGIWRATE, ray_get_rate),
1510 IW_HANDLER(SIOCSIWRTS, ray_set_rts),
1511 IW_HANDLER(SIOCGIWRTS, ray_get_rts),
1512 IW_HANDLER(SIOCSIWFRAG, ray_set_frag),
1513 IW_HANDLER(SIOCGIWFRAG, ray_get_frag),
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001514};
1515
John Daiker141fa612009-03-10 06:59:54 -07001516#define SIOCSIPFRAMING SIOCIWFIRSTPRIV /* Set framing mode */
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001517#define SIOCGIPFRAMING SIOCIWFIRSTPRIV + 1 /* Get framing mode */
1518#define SIOCGIPCOUNTRY SIOCIWFIRSTPRIV + 3 /* Get country code */
1519
John Daiker141fa612009-03-10 06:59:54 -07001520static const iw_handler ray_private_handler[] = {
Joe Perches43ead782010-03-18 18:29:40 -07001521 [0] = ray_set_framing,
1522 [1] = ray_get_framing,
1523 [3] = ray_get_country,
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001524};
1525
John Daiker141fa612009-03-10 06:59:54 -07001526static const struct iw_priv_args ray_private_args[] = {
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001527/* cmd, set_args, get_args, name */
John Daiker141fa612009-03-10 06:59:54 -07001528 {SIOCSIPFRAMING, IW_PRIV_TYPE_BYTE | IW_PRIV_SIZE_FIXED | 1, 0,
1529 "set_framing"},
1530 {SIOCGIPFRAMING, 0, IW_PRIV_TYPE_BYTE | IW_PRIV_SIZE_FIXED | 1,
1531 "get_framing"},
1532 {SIOCGIPCOUNTRY, 0, IW_PRIV_TYPE_BYTE | IW_PRIV_SIZE_FIXED | 1,
1533 "get_country"},
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001534};
1535
John Daiker141fa612009-03-10 06:59:54 -07001536static const struct iw_handler_def ray_handler_def = {
1537 .num_standard = ARRAY_SIZE(ray_handler),
1538 .num_private = ARRAY_SIZE(ray_private_handler),
Denis Chengff8ac602007-09-02 18:30:18 +08001539 .num_private_args = ARRAY_SIZE(ray_private_args),
John Daiker141fa612009-03-10 06:59:54 -07001540 .standard = ray_handler,
1541 .private = ray_private_handler,
1542 .private_args = ray_private_args,
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001543 .get_wireless_stats = ray_get_wireless_stats,
1544};
1545
Linus Torvalds1da177e2005-04-16 15:20:36 -07001546/*===========================================================================*/
1547static int ray_open(struct net_device *dev)
1548{
John Daiker141fa612009-03-10 06:59:54 -07001549 ray_dev_t *local = netdev_priv(dev);
1550 struct pcmcia_device *link;
1551 link = local->finder;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001552
Dominik Brodowski624dd662009-10-24 15:52:44 +02001553 dev_dbg(&link->dev, "ray_open('%s')\n", dev->name);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001554
John Daiker141fa612009-03-10 06:59:54 -07001555 if (link->open == 0)
1556 local->num_multi = 0;
1557 link->open++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001558
John Daiker141fa612009-03-10 06:59:54 -07001559 /* If the card is not started, time to start it ! - Jean II */
1560 if (local->card_status == CARD_AWAITING_PARAM) {
1561 int i;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001562
Dominik Brodowski624dd662009-10-24 15:52:44 +02001563 dev_dbg(&link->dev, "ray_open: doing init now !\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001564
John Daiker141fa612009-03-10 06:59:54 -07001565 /* Download startup parameters */
1566 if ((i = dl_startup_params(dev)) < 0) {
1567 printk(KERN_INFO
1568 "ray_dev_init dl_startup_params failed - "
1569 "returns 0x%x\n", i);
1570 return -1;
1571 }
1572 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001573
John Daiker141fa612009-03-10 06:59:54 -07001574 if (sniffer)
1575 netif_stop_queue(dev);
1576 else
1577 netif_start_queue(dev);
1578
Dominik Brodowski624dd662009-10-24 15:52:44 +02001579 dev_dbg(&link->dev, "ray_open ending\n");
John Daiker141fa612009-03-10 06:59:54 -07001580 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001581} /* end ray_open */
John Daiker141fa612009-03-10 06:59:54 -07001582
Linus Torvalds1da177e2005-04-16 15:20:36 -07001583/*===========================================================================*/
1584static int ray_dev_close(struct net_device *dev)
1585{
John Daiker141fa612009-03-10 06:59:54 -07001586 ray_dev_t *local = netdev_priv(dev);
1587 struct pcmcia_device *link;
1588 link = local->finder;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001589
Dominik Brodowski624dd662009-10-24 15:52:44 +02001590 dev_dbg(&link->dev, "ray_dev_close('%s')\n", dev->name);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001591
John Daiker141fa612009-03-10 06:59:54 -07001592 link->open--;
1593 netif_stop_queue(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001594
John Daiker141fa612009-03-10 06:59:54 -07001595 /* In here, we should stop the hardware (stop card from beeing active)
1596 * and set local->card_status to CARD_AWAITING_PARAM, so that while the
1597 * card is closed we can chage its configuration.
1598 * Probably also need a COR reset to get sane state - Jean II */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001599
John Daiker141fa612009-03-10 06:59:54 -07001600 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001601} /* end ray_dev_close */
John Daiker141fa612009-03-10 06:59:54 -07001602
Linus Torvalds1da177e2005-04-16 15:20:36 -07001603/*===========================================================================*/
John Daiker141fa612009-03-10 06:59:54 -07001604static void ray_reset(struct net_device *dev)
1605{
Dominik Brodowski624dd662009-10-24 15:52:44 +02001606 pr_debug("ray_reset entered\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001607}
John Daiker141fa612009-03-10 06:59:54 -07001608
Linus Torvalds1da177e2005-04-16 15:20:36 -07001609/*===========================================================================*/
1610/* Cause a firmware interrupt if it is ready for one */
1611/* Return nonzero if not ready */
1612static int interrupt_ecf(ray_dev_t *local, int ccs)
1613{
John Daiker141fa612009-03-10 06:59:54 -07001614 int i = 50;
1615 struct pcmcia_device *link = local->finder;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001616
John Daiker141fa612009-03-10 06:59:54 -07001617 if (!(pcmcia_dev_present(link))) {
Dominik Brodowski624dd662009-10-24 15:52:44 +02001618 dev_dbg(&link->dev, "ray_cs interrupt_ecf - device not present\n");
John Daiker141fa612009-03-10 06:59:54 -07001619 return -1;
1620 }
Dominik Brodowski624dd662009-10-24 15:52:44 +02001621 dev_dbg(&link->dev, "interrupt_ecf(local=%p, ccs = 0x%x\n", local, ccs);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001622
John Daiker141fa612009-03-10 06:59:54 -07001623 while (i &&
1624 (readb(local->amem + CIS_OFFSET + ECF_INTR_OFFSET) &
1625 ECF_INTR_SET))
1626 i--;
1627 if (i == 0) {
Dominik Brodowski624dd662009-10-24 15:52:44 +02001628 dev_dbg(&link->dev, "ray_cs interrupt_ecf card not ready for interrupt\n");
John Daiker141fa612009-03-10 06:59:54 -07001629 return -1;
1630 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001631 /* Fill the mailbox, then kick the card */
John Daiker141fa612009-03-10 06:59:54 -07001632 writeb(ccs, local->sram + SCB_BASE);
1633 writeb(ECF_INTR_SET, local->amem + CIS_OFFSET + ECF_INTR_OFFSET);
1634 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001635} /* interrupt_ecf */
John Daiker141fa612009-03-10 06:59:54 -07001636
Linus Torvalds1da177e2005-04-16 15:20:36 -07001637/*===========================================================================*/
1638/* Get next free transmit CCS */
1639/* Return - index of current tx ccs */
1640static int get_free_tx_ccs(ray_dev_t *local)
1641{
John Daiker141fa612009-03-10 06:59:54 -07001642 int i;
1643 struct ccs __iomem *pccs = ccs_base(local);
1644 struct pcmcia_device *link = local->finder;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001645
John Daiker141fa612009-03-10 06:59:54 -07001646 if (!(pcmcia_dev_present(link))) {
Dominik Brodowski624dd662009-10-24 15:52:44 +02001647 dev_dbg(&link->dev, "ray_cs get_free_tx_ccs - device not present\n");
John Daiker141fa612009-03-10 06:59:54 -07001648 return ECARDGONE;
1649 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001650
John Daiker141fa612009-03-10 06:59:54 -07001651 if (test_and_set_bit(0, &local->tx_ccs_lock)) {
Dominik Brodowski624dd662009-10-24 15:52:44 +02001652 dev_dbg(&link->dev, "ray_cs tx_ccs_lock busy\n");
John Daiker141fa612009-03-10 06:59:54 -07001653 return ECCSBUSY;
1654 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001655
John Daiker141fa612009-03-10 06:59:54 -07001656 for (i = 0; i < NUMBER_OF_TX_CCS; i++) {
1657 if (readb(&(pccs + i)->buffer_status) == CCS_BUFFER_FREE) {
1658 writeb(CCS_BUFFER_BUSY, &(pccs + i)->buffer_status);
1659 writeb(CCS_END_LIST, &(pccs + i)->link);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001660 local->tx_ccs_lock = 0;
John Daiker141fa612009-03-10 06:59:54 -07001661 return i;
1662 }
1663 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001664 local->tx_ccs_lock = 0;
Dominik Brodowski624dd662009-10-24 15:52:44 +02001665 dev_dbg(&link->dev, "ray_cs ERROR no free tx CCS for raylink card\n");
John Daiker141fa612009-03-10 06:59:54 -07001666 return ECCSFULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001667} /* get_free_tx_ccs */
John Daiker141fa612009-03-10 06:59:54 -07001668
Linus Torvalds1da177e2005-04-16 15:20:36 -07001669/*===========================================================================*/
1670/* Get next free CCS */
1671/* Return - index of current ccs */
1672static int get_free_ccs(ray_dev_t *local)
1673{
John Daiker141fa612009-03-10 06:59:54 -07001674 int i;
1675 struct ccs __iomem *pccs = ccs_base(local);
1676 struct pcmcia_device *link = local->finder;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001677
John Daiker141fa612009-03-10 06:59:54 -07001678 if (!(pcmcia_dev_present(link))) {
Dominik Brodowski624dd662009-10-24 15:52:44 +02001679 dev_dbg(&link->dev, "ray_cs get_free_ccs - device not present\n");
John Daiker141fa612009-03-10 06:59:54 -07001680 return ECARDGONE;
1681 }
1682 if (test_and_set_bit(0, &local->ccs_lock)) {
Dominik Brodowski624dd662009-10-24 15:52:44 +02001683 dev_dbg(&link->dev, "ray_cs ccs_lock busy\n");
John Daiker141fa612009-03-10 06:59:54 -07001684 return ECCSBUSY;
1685 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001686
John Daiker141fa612009-03-10 06:59:54 -07001687 for (i = NUMBER_OF_TX_CCS; i < NUMBER_OF_CCS; i++) {
1688 if (readb(&(pccs + i)->buffer_status) == CCS_BUFFER_FREE) {
1689 writeb(CCS_BUFFER_BUSY, &(pccs + i)->buffer_status);
1690 writeb(CCS_END_LIST, &(pccs + i)->link);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001691 local->ccs_lock = 0;
John Daiker141fa612009-03-10 06:59:54 -07001692 return i;
1693 }
1694 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001695 local->ccs_lock = 0;
Dominik Brodowski624dd662009-10-24 15:52:44 +02001696 dev_dbg(&link->dev, "ray_cs ERROR no free CCS for raylink card\n");
John Daiker141fa612009-03-10 06:59:54 -07001697 return ECCSFULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001698} /* get_free_ccs */
John Daiker141fa612009-03-10 06:59:54 -07001699
Linus Torvalds1da177e2005-04-16 15:20:36 -07001700/*===========================================================================*/
1701static void authenticate_timeout(u_long data)
1702{
John Daiker141fa612009-03-10 06:59:54 -07001703 ray_dev_t *local = (ray_dev_t *) data;
1704 del_timer(&local->timer);
1705 printk(KERN_INFO "ray_cs Authentication with access point failed"
1706 " - timeout\n");
1707 join_net((u_long) local);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001708}
John Daiker141fa612009-03-10 06:59:54 -07001709
Linus Torvalds1da177e2005-04-16 15:20:36 -07001710/*===========================================================================*/
1711static int asc_to_int(char a)
1712{
John Daiker141fa612009-03-10 06:59:54 -07001713 if (a < '0')
1714 return -1;
1715 if (a <= '9')
1716 return (a - '0');
1717 if (a < 'A')
1718 return -1;
1719 if (a <= 'F')
1720 return (10 + a - 'A');
1721 if (a < 'a')
1722 return -1;
1723 if (a <= 'f')
1724 return (10 + a - 'a');
1725 return -1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001726}
John Daiker141fa612009-03-10 06:59:54 -07001727
Linus Torvalds1da177e2005-04-16 15:20:36 -07001728/*===========================================================================*/
1729static int parse_addr(char *in_str, UCHAR *out)
1730{
John Daiker141fa612009-03-10 06:59:54 -07001731 int len;
1732 int i, j, k;
1733 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001734
John Daiker141fa612009-03-10 06:59:54 -07001735 if (in_str == NULL)
1736 return 0;
1737 if ((len = strlen(in_str)) < 2)
1738 return 0;
1739 memset(out, 0, ADDRLEN);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001740
John Daiker141fa612009-03-10 06:59:54 -07001741 status = 1;
1742 j = len - 1;
1743 if (j > 12)
1744 j = 12;
1745 i = 5;
1746
1747 while (j > 0) {
1748 if ((k = asc_to_int(in_str[j--])) != -1)
1749 out[i] = k;
1750 else
1751 return 0;
1752
1753 if (j == 0)
1754 break;
1755 if ((k = asc_to_int(in_str[j--])) != -1)
1756 out[i] += k << 4;
1757 else
1758 return 0;
1759 if (!i--)
1760 break;
1761 }
1762 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001763}
John Daiker141fa612009-03-10 06:59:54 -07001764
Linus Torvalds1da177e2005-04-16 15:20:36 -07001765/*===========================================================================*/
1766static struct net_device_stats *ray_get_stats(struct net_device *dev)
1767{
John Daiker141fa612009-03-10 06:59:54 -07001768 ray_dev_t *local = netdev_priv(dev);
1769 struct pcmcia_device *link = local->finder;
1770 struct status __iomem *p = local->sram + STATUS_BASE;
1771 if (!(pcmcia_dev_present(link))) {
Dominik Brodowski624dd662009-10-24 15:52:44 +02001772 dev_dbg(&link->dev, "ray_cs net_device_stats - device not present\n");
John Daiker141fa612009-03-10 06:59:54 -07001773 return &local->stats;
1774 }
1775 if (readb(&p->mrx_overflow_for_host)) {
1776 local->stats.rx_over_errors += swab16(readw(&p->mrx_overflow));
1777 writeb(0, &p->mrx_overflow);
1778 writeb(0, &p->mrx_overflow_for_host);
1779 }
1780 if (readb(&p->mrx_checksum_error_for_host)) {
1781 local->stats.rx_crc_errors +=
1782 swab16(readw(&p->mrx_checksum_error));
1783 writeb(0, &p->mrx_checksum_error);
1784 writeb(0, &p->mrx_checksum_error_for_host);
1785 }
1786 if (readb(&p->rx_hec_error_for_host)) {
1787 local->stats.rx_frame_errors += swab16(readw(&p->rx_hec_error));
1788 writeb(0, &p->rx_hec_error);
1789 writeb(0, &p->rx_hec_error_for_host);
1790 }
1791 return &local->stats;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001792}
John Daiker141fa612009-03-10 06:59:54 -07001793
Linus Torvalds1da177e2005-04-16 15:20:36 -07001794/*===========================================================================*/
John Daiker141fa612009-03-10 06:59:54 -07001795static void ray_update_parm(struct net_device *dev, UCHAR objid, UCHAR *value,
1796 int len)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001797{
John Daiker141fa612009-03-10 06:59:54 -07001798 ray_dev_t *local = netdev_priv(dev);
1799 struct pcmcia_device *link = local->finder;
1800 int ccsindex;
1801 int i;
1802 struct ccs __iomem *pccs;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001803
John Daiker141fa612009-03-10 06:59:54 -07001804 if (!(pcmcia_dev_present(link))) {
Dominik Brodowski624dd662009-10-24 15:52:44 +02001805 dev_dbg(&link->dev, "ray_update_parm - device not present\n");
John Daiker141fa612009-03-10 06:59:54 -07001806 return;
1807 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001808
John Daiker141fa612009-03-10 06:59:54 -07001809 if ((ccsindex = get_free_ccs(local)) < 0) {
Dominik Brodowski624dd662009-10-24 15:52:44 +02001810 dev_dbg(&link->dev, "ray_update_parm - No free ccs\n");
John Daiker141fa612009-03-10 06:59:54 -07001811 return;
1812 }
1813 pccs = ccs_base(local) + ccsindex;
1814 writeb(CCS_UPDATE_PARAMS, &pccs->cmd);
1815 writeb(objid, &pccs->var.update_param.object_id);
1816 writeb(1, &pccs->var.update_param.number_objects);
1817 writeb(0, &pccs->var.update_param.failure_cause);
1818 for (i = 0; i < len; i++) {
1819 writeb(value[i], local->sram + HOST_TO_ECF_BASE);
1820 }
1821 /* Interrupt the firmware to process the command */
1822 if (interrupt_ecf(local, ccsindex)) {
Dominik Brodowski624dd662009-10-24 15:52:44 +02001823 dev_dbg(&link->dev, "ray_cs associate failed - ECF not ready for intr\n");
John Daiker141fa612009-03-10 06:59:54 -07001824 writeb(CCS_BUFFER_FREE, &(pccs++)->buffer_status);
1825 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001826}
John Daiker141fa612009-03-10 06:59:54 -07001827
Linus Torvalds1da177e2005-04-16 15:20:36 -07001828/*===========================================================================*/
1829static void ray_update_multi_list(struct net_device *dev, int all)
1830{
John Daiker141fa612009-03-10 06:59:54 -07001831 int ccsindex;
1832 struct ccs __iomem *pccs;
John Daiker141fa612009-03-10 06:59:54 -07001833 ray_dev_t *local = netdev_priv(dev);
1834 struct pcmcia_device *link = local->finder;
1835 void __iomem *p = local->sram + HOST_TO_ECF_BASE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001836
John Daiker141fa612009-03-10 06:59:54 -07001837 if (!(pcmcia_dev_present(link))) {
Dominik Brodowski624dd662009-10-24 15:52:44 +02001838 dev_dbg(&link->dev, "ray_update_multi_list - device not present\n");
John Daiker141fa612009-03-10 06:59:54 -07001839 return;
1840 } else
Dominik Brodowski624dd662009-10-24 15:52:44 +02001841 dev_dbg(&link->dev, "ray_update_multi_list(%p)\n", dev);
John Daiker141fa612009-03-10 06:59:54 -07001842 if ((ccsindex = get_free_ccs(local)) < 0) {
Dominik Brodowski624dd662009-10-24 15:52:44 +02001843 dev_dbg(&link->dev, "ray_update_multi - No free ccs\n");
John Daiker141fa612009-03-10 06:59:54 -07001844 return;
1845 }
1846 pccs = ccs_base(local) + ccsindex;
1847 writeb(CCS_UPDATE_MULTICAST_LIST, &pccs->cmd);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001848
John Daiker141fa612009-03-10 06:59:54 -07001849 if (all) {
1850 writeb(0xff, &pccs->var);
1851 local->num_multi = 0xff;
1852 } else {
Jiri Pirko22bedad2010-04-01 21:22:57 +00001853 struct netdev_hw_addr *ha;
Jiri Pirko655ffee2010-02-27 07:35:45 +00001854 int i = 0;
1855
John Daiker141fa612009-03-10 06:59:54 -07001856 /* Copy the kernel's list of MC addresses to card */
Jiri Pirko22bedad2010-04-01 21:22:57 +00001857 netdev_for_each_mc_addr(ha, dev) {
1858 memcpy_toio(p, ha->addr, ETH_ALEN);
Dominik Brodowski624dd662009-10-24 15:52:44 +02001859 dev_dbg(&link->dev,
John Daiker141fa612009-03-10 06:59:54 -07001860 "ray_update_multi add addr %02x%02x%02x%02x%02x%02x\n",
Jiri Pirko22bedad2010-04-01 21:22:57 +00001861 ha->addr[0], ha->addr[1],
1862 ha->addr[2], ha->addr[3],
1863 ha->addr[4], ha->addr[5]);
John Daiker141fa612009-03-10 06:59:54 -07001864 p += ETH_ALEN;
1865 i++;
1866 }
1867 if (i > 256 / ADDRLEN)
1868 i = 256 / ADDRLEN;
1869 writeb((UCHAR) i, &pccs->var);
Dominik Brodowski624dd662009-10-24 15:52:44 +02001870 dev_dbg(&link->dev, "ray_cs update_multi %d addresses in list\n", i);
John Daiker141fa612009-03-10 06:59:54 -07001871 /* Interrupt the firmware to process the command */
1872 local->num_multi = i;
1873 }
1874 if (interrupt_ecf(local, ccsindex)) {
Dominik Brodowski624dd662009-10-24 15:52:44 +02001875 dev_dbg(&link->dev,
John Daiker141fa612009-03-10 06:59:54 -07001876 "ray_cs update_multi failed - ECF not ready for intr\n");
1877 writeb(CCS_BUFFER_FREE, &(pccs++)->buffer_status);
1878 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001879} /* end ray_update_multi_list */
John Daiker141fa612009-03-10 06:59:54 -07001880
Linus Torvalds1da177e2005-04-16 15:20:36 -07001881/*===========================================================================*/
1882static void set_multicast_list(struct net_device *dev)
1883{
John Daiker141fa612009-03-10 06:59:54 -07001884 ray_dev_t *local = netdev_priv(dev);
1885 UCHAR promisc;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001886
Dominik Brodowski624dd662009-10-24 15:52:44 +02001887 pr_debug("ray_cs set_multicast_list(%p)\n", dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001888
John Daiker141fa612009-03-10 06:59:54 -07001889 if (dev->flags & IFF_PROMISC) {
1890 if (local->sparm.b5.a_promiscuous_mode == 0) {
Dominik Brodowski624dd662009-10-24 15:52:44 +02001891 pr_debug("ray_cs set_multicast_list promisc on\n");
John Daiker141fa612009-03-10 06:59:54 -07001892 local->sparm.b5.a_promiscuous_mode = 1;
1893 promisc = 1;
1894 ray_update_parm(dev, OBJID_promiscuous_mode,
1895 &promisc, sizeof(promisc));
1896 }
1897 } else {
1898 if (local->sparm.b5.a_promiscuous_mode == 1) {
Dominik Brodowski624dd662009-10-24 15:52:44 +02001899 pr_debug("ray_cs set_multicast_list promisc off\n");
John Daiker141fa612009-03-10 06:59:54 -07001900 local->sparm.b5.a_promiscuous_mode = 0;
1901 promisc = 0;
1902 ray_update_parm(dev, OBJID_promiscuous_mode,
1903 &promisc, sizeof(promisc));
1904 }
1905 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001906
John Daiker141fa612009-03-10 06:59:54 -07001907 if (dev->flags & IFF_ALLMULTI)
1908 ray_update_multi_list(dev, 1);
1909 else {
Jiri Pirko4cd24ea2010-02-08 04:30:35 +00001910 if (local->num_multi != netdev_mc_count(dev))
John Daiker141fa612009-03-10 06:59:54 -07001911 ray_update_multi_list(dev, 0);
1912 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001913} /* end set_multicast_list */
John Daiker141fa612009-03-10 06:59:54 -07001914
Linus Torvalds1da177e2005-04-16 15:20:36 -07001915/*=============================================================================
1916 * All routines below here are run at interrupt time.
1917=============================================================================*/
David Howells7d12e782006-10-05 14:55:46 +01001918static irqreturn_t ray_interrupt(int irq, void *dev_id)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001919{
John Daiker141fa612009-03-10 06:59:54 -07001920 struct net_device *dev = (struct net_device *)dev_id;
1921 struct pcmcia_device *link;
1922 ray_dev_t *local;
1923 struct ccs __iomem *pccs;
1924 struct rcs __iomem *prcs;
1925 UCHAR rcsindex;
1926 UCHAR tmp;
1927 UCHAR cmd;
1928 UCHAR status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001929
John Daiker141fa612009-03-10 06:59:54 -07001930 if (dev == NULL) /* Note that we want interrupts with dev->start == 0 */
1931 return IRQ_NONE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001932
Dominik Brodowski624dd662009-10-24 15:52:44 +02001933 pr_debug("ray_cs: interrupt for *dev=%p\n", dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001934
John Daiker141fa612009-03-10 06:59:54 -07001935 local = netdev_priv(dev);
1936 link = (struct pcmcia_device *)local->finder;
1937 if (!pcmcia_dev_present(link)) {
Dominik Brodowski624dd662009-10-24 15:52:44 +02001938 pr_debug(
1939 "ray_cs interrupt from device not present or suspended.\n");
John Daiker141fa612009-03-10 06:59:54 -07001940 return IRQ_NONE;
1941 }
1942 rcsindex = readb(&((struct scb __iomem *)(local->sram))->rcs_index);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001943
John Daiker141fa612009-03-10 06:59:54 -07001944 if (rcsindex >= (NUMBER_OF_CCS + NUMBER_OF_RCS)) {
Dominik Brodowski624dd662009-10-24 15:52:44 +02001945 dev_dbg(&link->dev, "ray_cs interrupt bad rcsindex = 0x%x\n", rcsindex);
John Daiker141fa612009-03-10 06:59:54 -07001946 clear_interrupt(local);
1947 return IRQ_HANDLED;
1948 }
1949 if (rcsindex < NUMBER_OF_CCS) { /* If it's a returned CCS */
1950 pccs = ccs_base(local) + rcsindex;
1951 cmd = readb(&pccs->cmd);
1952 status = readb(&pccs->buffer_status);
1953 switch (cmd) {
1954 case CCS_DOWNLOAD_STARTUP_PARAMS: /* Happens in firmware someday */
1955 del_timer(&local->timer);
1956 if (status == CCS_COMMAND_COMPLETE) {
Dominik Brodowski624dd662009-10-24 15:52:44 +02001957 dev_dbg(&link->dev,
John Daiker141fa612009-03-10 06:59:54 -07001958 "ray_cs interrupt download_startup_parameters OK\n");
1959 } else {
Dominik Brodowski624dd662009-10-24 15:52:44 +02001960 dev_dbg(&link->dev,
John Daiker141fa612009-03-10 06:59:54 -07001961 "ray_cs interrupt download_startup_parameters fail\n");
1962 }
1963 break;
1964 case CCS_UPDATE_PARAMS:
Dominik Brodowski624dd662009-10-24 15:52:44 +02001965 dev_dbg(&link->dev, "ray_cs interrupt update params done\n");
John Daiker141fa612009-03-10 06:59:54 -07001966 if (status != CCS_COMMAND_COMPLETE) {
1967 tmp =
1968 readb(&pccs->var.update_param.
1969 failure_cause);
Dominik Brodowski624dd662009-10-24 15:52:44 +02001970 dev_dbg(&link->dev,
John Daiker141fa612009-03-10 06:59:54 -07001971 "ray_cs interrupt update params failed - reason %d\n",
1972 tmp);
1973 }
1974 break;
1975 case CCS_REPORT_PARAMS:
Dominik Brodowski624dd662009-10-24 15:52:44 +02001976 dev_dbg(&link->dev, "ray_cs interrupt report params done\n");
John Daiker141fa612009-03-10 06:59:54 -07001977 break;
1978 case CCS_UPDATE_MULTICAST_LIST: /* Note that this CCS isn't returned */
Dominik Brodowski624dd662009-10-24 15:52:44 +02001979 dev_dbg(&link->dev,
John Daiker141fa612009-03-10 06:59:54 -07001980 "ray_cs interrupt CCS Update Multicast List done\n");
1981 break;
1982 case CCS_UPDATE_POWER_SAVINGS_MODE:
Dominik Brodowski624dd662009-10-24 15:52:44 +02001983 dev_dbg(&link->dev,
John Daiker141fa612009-03-10 06:59:54 -07001984 "ray_cs interrupt update power save mode done\n");
1985 break;
1986 case CCS_START_NETWORK:
1987 case CCS_JOIN_NETWORK:
1988 if (status == CCS_COMMAND_COMPLETE) {
1989 if (readb
1990 (&pccs->var.start_network.net_initiated) ==
1991 1) {
Dominik Brodowski624dd662009-10-24 15:52:44 +02001992 dev_dbg(&link->dev,
John Daiker141fa612009-03-10 06:59:54 -07001993 "ray_cs interrupt network \"%s\" started\n",
1994 local->sparm.b4.a_current_ess_id);
1995 } else {
Dominik Brodowski624dd662009-10-24 15:52:44 +02001996 dev_dbg(&link->dev,
John Daiker141fa612009-03-10 06:59:54 -07001997 "ray_cs interrupt network \"%s\" joined\n",
1998 local->sparm.b4.a_current_ess_id);
1999 }
2000 memcpy_fromio(&local->bss_id,
2001 pccs->var.start_network.bssid,
2002 ADDRLEN);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002003
John Daiker141fa612009-03-10 06:59:54 -07002004 if (local->fw_ver == 0x55)
2005 local->net_default_tx_rate = 3;
2006 else
2007 local->net_default_tx_rate =
2008 readb(&pccs->var.start_network.
2009 net_default_tx_rate);
2010 local->encryption =
2011 readb(&pccs->var.start_network.encryption);
2012 if (!sniffer && (local->net_type == INFRA)
2013 && !(local->sparm.b4.a_acting_as_ap_status)) {
2014 authenticate(local);
2015 }
2016 local->card_status = CARD_ACQ_COMPLETE;
2017 } else {
2018 local->card_status = CARD_ACQ_FAILED;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002019
John Daiker141fa612009-03-10 06:59:54 -07002020 del_timer(&local->timer);
2021 local->timer.expires = jiffies + HZ * 5;
2022 local->timer.data = (long)local;
2023 if (status == CCS_START_NETWORK) {
Dominik Brodowski624dd662009-10-24 15:52:44 +02002024 dev_dbg(&link->dev,
John Daiker141fa612009-03-10 06:59:54 -07002025 "ray_cs interrupt network \"%s\" start failed\n",
2026 local->sparm.b4.a_current_ess_id);
2027 local->timer.function = &start_net;
2028 } else {
Dominik Brodowski624dd662009-10-24 15:52:44 +02002029 dev_dbg(&link->dev,
John Daiker141fa612009-03-10 06:59:54 -07002030 "ray_cs interrupt network \"%s\" join failed\n",
2031 local->sparm.b4.a_current_ess_id);
2032 local->timer.function = &join_net;
2033 }
2034 add_timer(&local->timer);
2035 }
2036 break;
2037 case CCS_START_ASSOCIATION:
2038 if (status == CCS_COMMAND_COMPLETE) {
2039 local->card_status = CARD_ASSOC_COMPLETE;
Dominik Brodowski624dd662009-10-24 15:52:44 +02002040 dev_dbg(&link->dev, "ray_cs association successful\n");
John Daiker141fa612009-03-10 06:59:54 -07002041 } else {
Dominik Brodowski624dd662009-10-24 15:52:44 +02002042 dev_dbg(&link->dev, "ray_cs association failed,\n");
John Daiker141fa612009-03-10 06:59:54 -07002043 local->card_status = CARD_ASSOC_FAILED;
2044 join_net((u_long) local);
2045 }
2046 break;
2047 case CCS_TX_REQUEST:
2048 if (status == CCS_COMMAND_COMPLETE) {
Dominik Brodowski624dd662009-10-24 15:52:44 +02002049 dev_dbg(&link->dev,
John Daiker141fa612009-03-10 06:59:54 -07002050 "ray_cs interrupt tx request complete\n");
2051 } else {
Dominik Brodowski624dd662009-10-24 15:52:44 +02002052 dev_dbg(&link->dev,
John Daiker141fa612009-03-10 06:59:54 -07002053 "ray_cs interrupt tx request failed\n");
2054 }
2055 if (!sniffer)
2056 netif_start_queue(dev);
2057 netif_wake_queue(dev);
2058 break;
2059 case CCS_TEST_MEMORY:
Dominik Brodowski624dd662009-10-24 15:52:44 +02002060 dev_dbg(&link->dev, "ray_cs interrupt mem test done\n");
John Daiker141fa612009-03-10 06:59:54 -07002061 break;
2062 case CCS_SHUTDOWN:
Dominik Brodowski624dd662009-10-24 15:52:44 +02002063 dev_dbg(&link->dev,
John Daiker141fa612009-03-10 06:59:54 -07002064 "ray_cs interrupt Unexpected CCS returned - Shutdown\n");
2065 break;
2066 case CCS_DUMP_MEMORY:
Dominik Brodowski624dd662009-10-24 15:52:44 +02002067 dev_dbg(&link->dev, "ray_cs interrupt dump memory done\n");
John Daiker141fa612009-03-10 06:59:54 -07002068 break;
2069 case CCS_START_TIMER:
Dominik Brodowski624dd662009-10-24 15:52:44 +02002070 dev_dbg(&link->dev,
John Daiker141fa612009-03-10 06:59:54 -07002071 "ray_cs interrupt DING - raylink timer expired\n");
2072 break;
2073 default:
Dominik Brodowski624dd662009-10-24 15:52:44 +02002074 dev_dbg(&link->dev,
John Daiker141fa612009-03-10 06:59:54 -07002075 "ray_cs interrupt Unexpected CCS 0x%x returned 0x%x\n",
2076 rcsindex, cmd);
2077 }
2078 writeb(CCS_BUFFER_FREE, &pccs->buffer_status);
2079 } else { /* It's an RCS */
2080
2081 prcs = rcs_base(local) + rcsindex;
2082
2083 switch (readb(&prcs->interrupt_id)) {
2084 case PROCESS_RX_PACKET:
2085 ray_rx(dev, local, prcs);
2086 break;
2087 case REJOIN_NET_COMPLETE:
Dominik Brodowski624dd662009-10-24 15:52:44 +02002088 dev_dbg(&link->dev, "ray_cs interrupt rejoin net complete\n");
John Daiker141fa612009-03-10 06:59:54 -07002089 local->card_status = CARD_ACQ_COMPLETE;
2090 /* do we need to clear tx buffers CCS's? */
2091 if (local->sparm.b4.a_network_type == ADHOC) {
2092 if (!sniffer)
2093 netif_start_queue(dev);
2094 } else {
2095 memcpy_fromio(&local->bss_id,
2096 prcs->var.rejoin_net_complete.
2097 bssid, ADDRLEN);
Dominik Brodowski624dd662009-10-24 15:52:44 +02002098 dev_dbg(&link->dev,
John Daiker141fa612009-03-10 06:59:54 -07002099 "ray_cs new BSSID = %02x%02x%02x%02x%02x%02x\n",
2100 local->bss_id[0], local->bss_id[1],
2101 local->bss_id[2], local->bss_id[3],
2102 local->bss_id[4], local->bss_id[5]);
2103 if (!sniffer)
2104 authenticate(local);
2105 }
2106 break;
2107 case ROAMING_INITIATED:
Dominik Brodowski624dd662009-10-24 15:52:44 +02002108 dev_dbg(&link->dev, "ray_cs interrupt roaming initiated\n");
John Daiker141fa612009-03-10 06:59:54 -07002109 netif_stop_queue(dev);
2110 local->card_status = CARD_DOING_ACQ;
2111 break;
2112 case JAPAN_CALL_SIGN_RXD:
Dominik Brodowski624dd662009-10-24 15:52:44 +02002113 dev_dbg(&link->dev, "ray_cs interrupt japan call sign rx\n");
John Daiker141fa612009-03-10 06:59:54 -07002114 break;
2115 default:
Dominik Brodowski624dd662009-10-24 15:52:44 +02002116 dev_dbg(&link->dev,
John Daiker141fa612009-03-10 06:59:54 -07002117 "ray_cs Unexpected interrupt for RCS 0x%x cmd = 0x%x\n",
2118 rcsindex,
2119 (unsigned int)readb(&prcs->interrupt_id));
2120 break;
2121 }
2122 writeb(CCS_BUFFER_FREE, &prcs->buffer_status);
2123 }
2124 clear_interrupt(local);
2125 return IRQ_HANDLED;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002126} /* ray_interrupt */
John Daiker141fa612009-03-10 06:59:54 -07002127
Linus Torvalds1da177e2005-04-16 15:20:36 -07002128/*===========================================================================*/
John Daiker141fa612009-03-10 06:59:54 -07002129static void ray_rx(struct net_device *dev, ray_dev_t *local,
2130 struct rcs __iomem *prcs)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002131{
John Daiker141fa612009-03-10 06:59:54 -07002132 int rx_len;
2133 unsigned int pkt_addr;
2134 void __iomem *pmsg;
Dominik Brodowski624dd662009-10-24 15:52:44 +02002135 pr_debug("ray_rx process rx packet\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002136
John Daiker141fa612009-03-10 06:59:54 -07002137 /* Calculate address of packet within Rx buffer */
2138 pkt_addr = ((readb(&prcs->var.rx_packet.rx_data_ptr[0]) << 8)
2139 + readb(&prcs->var.rx_packet.rx_data_ptr[1])) & RX_BUFF_END;
2140 /* Length of first packet fragment */
2141 rx_len = (readb(&prcs->var.rx_packet.rx_data_length[0]) << 8)
2142 + readb(&prcs->var.rx_packet.rx_data_length[1]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002143
John Daiker141fa612009-03-10 06:59:54 -07002144 local->last_rsl = readb(&prcs->var.rx_packet.rx_sig_lev);
2145 pmsg = local->rmem + pkt_addr;
2146 switch (readb(pmsg)) {
2147 case DATA_TYPE:
Dominik Brodowski624dd662009-10-24 15:52:44 +02002148 pr_debug("ray_rx data type\n");
John Daiker141fa612009-03-10 06:59:54 -07002149 rx_data(dev, prcs, pkt_addr, rx_len);
2150 break;
2151 case AUTHENTIC_TYPE:
Dominik Brodowski624dd662009-10-24 15:52:44 +02002152 pr_debug("ray_rx authentic type\n");
John Daiker141fa612009-03-10 06:59:54 -07002153 if (sniffer)
2154 rx_data(dev, prcs, pkt_addr, rx_len);
2155 else
2156 rx_authenticate(local, prcs, pkt_addr, rx_len);
2157 break;
2158 case DEAUTHENTIC_TYPE:
Dominik Brodowski624dd662009-10-24 15:52:44 +02002159 pr_debug("ray_rx deauth type\n");
John Daiker141fa612009-03-10 06:59:54 -07002160 if (sniffer)
2161 rx_data(dev, prcs, pkt_addr, rx_len);
2162 else
2163 rx_deauthenticate(local, prcs, pkt_addr, rx_len);
2164 break;
2165 case NULL_MSG_TYPE:
Dominik Brodowski624dd662009-10-24 15:52:44 +02002166 pr_debug("ray_cs rx NULL msg\n");
John Daiker141fa612009-03-10 06:59:54 -07002167 break;
2168 case BEACON_TYPE:
Dominik Brodowski624dd662009-10-24 15:52:44 +02002169 pr_debug("ray_rx beacon type\n");
John Daiker141fa612009-03-10 06:59:54 -07002170 if (sniffer)
2171 rx_data(dev, prcs, pkt_addr, rx_len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002172
John Daiker141fa612009-03-10 06:59:54 -07002173 copy_from_rx_buff(local, (UCHAR *) &local->last_bcn, pkt_addr,
2174 rx_len < sizeof(struct beacon_rx) ?
2175 rx_len : sizeof(struct beacon_rx));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002176
John Daiker141fa612009-03-10 06:59:54 -07002177 local->beacon_rxed = 1;
2178 /* Get the statistics so the card counters never overflow */
2179 ray_get_stats(dev);
2180 break;
2181 default:
Dominik Brodowski624dd662009-10-24 15:52:44 +02002182 pr_debug("ray_cs unknown pkt type %2x\n",
John Daiker141fa612009-03-10 06:59:54 -07002183 (unsigned int)readb(pmsg));
2184 break;
2185 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002186
2187} /* end ray_rx */
John Daiker141fa612009-03-10 06:59:54 -07002188
Linus Torvalds1da177e2005-04-16 15:20:36 -07002189/*===========================================================================*/
John Daiker141fa612009-03-10 06:59:54 -07002190static void rx_data(struct net_device *dev, struct rcs __iomem *prcs,
2191 unsigned int pkt_addr, int rx_len)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002192{
John Daiker141fa612009-03-10 06:59:54 -07002193 struct sk_buff *skb = NULL;
2194 struct rcs __iomem *prcslink = prcs;
2195 ray_dev_t *local = netdev_priv(dev);
2196 UCHAR *rx_ptr;
2197 int total_len;
2198 int tmp;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002199#ifdef WIRELESS_SPY
John Daiker141fa612009-03-10 06:59:54 -07002200 int siglev = local->last_rsl;
2201 u_char linksrcaddr[ETH_ALEN]; /* Other end of the wireless link */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002202#endif
2203
John Daiker141fa612009-03-10 06:59:54 -07002204 if (!sniffer) {
2205 if (translate) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002206/* TBD length needs fixing for translated header */
John Daiker141fa612009-03-10 06:59:54 -07002207 if (rx_len < (ETH_HLEN + RX_MAC_HEADER_LENGTH) ||
2208 rx_len >
2209 (dev->mtu + RX_MAC_HEADER_LENGTH + ETH_HLEN +
2210 FCS_LEN)) {
Dominik Brodowski624dd662009-10-24 15:52:44 +02002211 pr_debug(
Frans Popcb01b092010-03-24 19:46:34 +01002212 "ray_cs invalid packet length %d received\n",
John Daiker141fa612009-03-10 06:59:54 -07002213 rx_len);
2214 return;
2215 }
2216 } else { /* encapsulated ethernet */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002217
John Daiker141fa612009-03-10 06:59:54 -07002218 if (rx_len < (ETH_HLEN + RX_MAC_HEADER_LENGTH) ||
2219 rx_len >
2220 (dev->mtu + RX_MAC_HEADER_LENGTH + ETH_HLEN +
2221 FCS_LEN)) {
Dominik Brodowski624dd662009-10-24 15:52:44 +02002222 pr_debug(
Frans Popcb01b092010-03-24 19:46:34 +01002223 "ray_cs invalid packet length %d received\n",
John Daiker141fa612009-03-10 06:59:54 -07002224 rx_len);
2225 return;
2226 }
2227 }
2228 }
Dominik Brodowski624dd662009-10-24 15:52:44 +02002229 pr_debug("ray_cs rx_data packet\n");
John Daiker141fa612009-03-10 06:59:54 -07002230 /* If fragmented packet, verify sizes of fragments add up */
2231 if (readb(&prcs->var.rx_packet.next_frag_rcs_index) != 0xFF) {
Dominik Brodowski624dd662009-10-24 15:52:44 +02002232 pr_debug("ray_cs rx'ed fragment\n");
John Daiker141fa612009-03-10 06:59:54 -07002233 tmp = (readb(&prcs->var.rx_packet.totalpacketlength[0]) << 8)
2234 + readb(&prcs->var.rx_packet.totalpacketlength[1]);
2235 total_len = tmp;
2236 prcslink = prcs;
2237 do {
2238 tmp -=
2239 (readb(&prcslink->var.rx_packet.rx_data_length[0])
2240 << 8)
2241 + readb(&prcslink->var.rx_packet.rx_data_length[1]);
2242 if (readb(&prcslink->var.rx_packet.next_frag_rcs_index)
2243 == 0xFF || tmp < 0)
2244 break;
2245 prcslink = rcs_base(local)
2246 + readb(&prcslink->link_field);
2247 } while (1);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002248
John Daiker141fa612009-03-10 06:59:54 -07002249 if (tmp < 0) {
Dominik Brodowski624dd662009-10-24 15:52:44 +02002250 pr_debug(
John Daiker141fa612009-03-10 06:59:54 -07002251 "ray_cs rx_data fragment lengths don't add up\n");
2252 local->stats.rx_dropped++;
2253 release_frag_chain(local, prcs);
2254 return;
2255 }
2256 } else { /* Single unfragmented packet */
2257 total_len = rx_len;
2258 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002259
John Daiker141fa612009-03-10 06:59:54 -07002260 skb = dev_alloc_skb(total_len + 5);
2261 if (skb == NULL) {
Dominik Brodowski624dd662009-10-24 15:52:44 +02002262 pr_debug("ray_cs rx_data could not allocate skb\n");
John Daiker141fa612009-03-10 06:59:54 -07002263 local->stats.rx_dropped++;
2264 if (readb(&prcs->var.rx_packet.next_frag_rcs_index) != 0xFF)
2265 release_frag_chain(local, prcs);
2266 return;
2267 }
2268 skb_reserve(skb, 2); /* Align IP on 16 byte (TBD check this) */
2269
Dominik Brodowski624dd662009-10-24 15:52:44 +02002270 pr_debug("ray_cs rx_data total_len = %x, rx_len = %x\n", total_len,
John Daiker141fa612009-03-10 06:59:54 -07002271 rx_len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002272
2273/************************/
John Daiker141fa612009-03-10 06:59:54 -07002274 /* Reserve enough room for the whole damn packet. */
2275 rx_ptr = skb_put(skb, total_len);
2276 /* Copy the whole packet to sk_buff */
2277 rx_ptr +=
2278 copy_from_rx_buff(local, rx_ptr, pkt_addr & RX_BUFF_END, rx_len);
2279 /* Get source address */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002280#ifdef WIRELESS_SPY
John Daiker141fa612009-03-10 06:59:54 -07002281 skb_copy_from_linear_data_offset(skb,
2282 offsetof(struct mac_header, addr_2),
2283 linksrcaddr, ETH_ALEN);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002284#endif
John Daiker141fa612009-03-10 06:59:54 -07002285 /* Now, deal with encapsulation/translation/sniffer */
2286 if (!sniffer) {
2287 if (!translate) {
2288 /* Encapsulated ethernet, so just lop off 802.11 MAC header */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002289/* TBD reserve skb_reserve( skb, RX_MAC_HEADER_LENGTH); */
John Daiker141fa612009-03-10 06:59:54 -07002290 skb_pull(skb, RX_MAC_HEADER_LENGTH);
2291 } else {
2292 /* Do translation */
2293 untranslate(local, skb, total_len);
2294 }
2295 } else { /* sniffer mode, so just pass whole packet */
2296 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002297
2298/************************/
John Daiker141fa612009-03-10 06:59:54 -07002299 /* Now pick up the rest of the fragments if any */
2300 tmp = 17;
2301 if (readb(&prcs->var.rx_packet.next_frag_rcs_index) != 0xFF) {
2302 prcslink = prcs;
Dominik Brodowski624dd662009-10-24 15:52:44 +02002303 pr_debug("ray_cs rx_data in fragment loop\n");
John Daiker141fa612009-03-10 06:59:54 -07002304 do {
2305 prcslink = rcs_base(local)
2306 +
2307 readb(&prcslink->var.rx_packet.next_frag_rcs_index);
2308 rx_len =
2309 ((readb(&prcslink->var.rx_packet.rx_data_length[0])
2310 << 8)
2311 +
2312 readb(&prcslink->var.rx_packet.rx_data_length[1]))
2313 & RX_BUFF_END;
2314 pkt_addr =
2315 ((readb(&prcslink->var.rx_packet.rx_data_ptr[0]) <<
2316 8)
2317 + readb(&prcslink->var.rx_packet.rx_data_ptr[1]))
2318 & RX_BUFF_END;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002319
John Daiker141fa612009-03-10 06:59:54 -07002320 rx_ptr +=
2321 copy_from_rx_buff(local, rx_ptr, pkt_addr, rx_len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002322
John Daiker141fa612009-03-10 06:59:54 -07002323 } while (tmp-- &&
2324 readb(&prcslink->var.rx_packet.next_frag_rcs_index) !=
2325 0xFF);
2326 release_frag_chain(local, prcs);
2327 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002328
John Daiker141fa612009-03-10 06:59:54 -07002329 skb->protocol = eth_type_trans(skb, dev);
2330 netif_rx(skb);
2331 local->stats.rx_packets++;
2332 local->stats.rx_bytes += total_len;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002333
John Daiker141fa612009-03-10 06:59:54 -07002334 /* Gather signal strength per address */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002335#ifdef WIRELESS_SPY
John Daiker141fa612009-03-10 06:59:54 -07002336 /* For the Access Point or the node having started the ad-hoc net
2337 * note : ad-hoc work only in some specific configurations, but we
2338 * kludge in ray_get_wireless_stats... */
2339 if (!memcmp(linksrcaddr, local->bss_id, ETH_ALEN)) {
2340 /* Update statistics */
2341 /*local->wstats.qual.qual = none ? */
2342 local->wstats.qual.level = siglev;
2343 /*local->wstats.qual.noise = none ? */
2344 local->wstats.qual.updated = 0x2;
2345 }
2346 /* Now, update the spy stuff */
2347 {
2348 struct iw_quality wstats;
2349 wstats.level = siglev;
2350 /* wstats.noise = none ? */
2351 /* wstats.qual = none ? */
2352 wstats.updated = 0x2;
2353 /* Update spy records */
2354 wireless_spy_update(dev, linksrcaddr, &wstats);
2355 }
2356#endif /* WIRELESS_SPY */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002357} /* end rx_data */
John Daiker141fa612009-03-10 06:59:54 -07002358
Linus Torvalds1da177e2005-04-16 15:20:36 -07002359/*===========================================================================*/
2360static void untranslate(ray_dev_t *local, struct sk_buff *skb, int len)
2361{
John Daiker141fa612009-03-10 06:59:54 -07002362 snaphdr_t *psnap = (snaphdr_t *) (skb->data + RX_MAC_HEADER_LENGTH);
2363 struct ieee80211_hdr *pmac = (struct ieee80211_hdr *)skb->data;
2364 __be16 type = *(__be16 *) psnap->ethertype;
2365 int delta;
2366 struct ethhdr *peth;
2367 UCHAR srcaddr[ADDRLEN];
2368 UCHAR destaddr[ADDRLEN];
2369 static UCHAR org_bridge[3] = { 0, 0, 0xf8 };
2370 static UCHAR org_1042[3] = { 0, 0, 0 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002371
John Daiker141fa612009-03-10 06:59:54 -07002372 memcpy(destaddr, ieee80211_get_DA(pmac), ADDRLEN);
2373 memcpy(srcaddr, ieee80211_get_SA(pmac), ADDRLEN);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002374
Dominik Brodowski624dd662009-10-24 15:52:44 +02002375#if 0
2376 if {
Joe Perchesad361c92009-07-06 13:05:40 -07002377 print_hex_dump(KERN_DEBUG, "skb->data before untranslate: ",
2378 DUMP_PREFIX_NONE, 16, 1,
2379 skb->data, 64, true);
2380 printk(KERN_DEBUG
John Daiker141fa612009-03-10 06:59:54 -07002381 "type = %08x, xsap = %02x%02x%02x, org = %02x02x02x\n",
2382 ntohs(type), psnap->dsap, psnap->ssap, psnap->ctrl,
2383 psnap->org[0], psnap->org[1], psnap->org[2]);
2384 printk(KERN_DEBUG "untranslate skb->data = %p\n", skb->data);
2385 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002386#endif
2387
John Daiker141fa612009-03-10 06:59:54 -07002388 if (psnap->dsap != 0xaa || psnap->ssap != 0xaa || psnap->ctrl != 3) {
2389 /* not a snap type so leave it alone */
Dominik Brodowski624dd662009-10-24 15:52:44 +02002390 pr_debug("ray_cs untranslate NOT SNAP %02x %02x %02x\n",
John Daiker141fa612009-03-10 06:59:54 -07002391 psnap->dsap, psnap->ssap, psnap->ctrl);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002392
John Daiker141fa612009-03-10 06:59:54 -07002393 delta = RX_MAC_HEADER_LENGTH - ETH_HLEN;
2394 peth = (struct ethhdr *)(skb->data + delta);
2395 peth->h_proto = htons(len - RX_MAC_HEADER_LENGTH);
2396 } else { /* Its a SNAP */
2397 if (memcmp(psnap->org, org_bridge, 3) == 0) {
2398 /* EtherII and nuke the LLC */
Dominik Brodowski624dd662009-10-24 15:52:44 +02002399 pr_debug("ray_cs untranslate Bridge encap\n");
John Daiker141fa612009-03-10 06:59:54 -07002400 delta = RX_MAC_HEADER_LENGTH
2401 + sizeof(struct snaphdr_t) - ETH_HLEN;
2402 peth = (struct ethhdr *)(skb->data + delta);
2403 peth->h_proto = type;
2404 } else if (memcmp(psnap->org, org_1042, 3) == 0) {
2405 switch (ntohs(type)) {
2406 case ETH_P_IPX:
2407 case ETH_P_AARP:
Dominik Brodowski624dd662009-10-24 15:52:44 +02002408 pr_debug("ray_cs untranslate RFC IPX/AARP\n");
John Daiker141fa612009-03-10 06:59:54 -07002409 delta = RX_MAC_HEADER_LENGTH - ETH_HLEN;
2410 peth = (struct ethhdr *)(skb->data + delta);
2411 peth->h_proto =
2412 htons(len - RX_MAC_HEADER_LENGTH);
2413 break;
2414 default:
Dominik Brodowski624dd662009-10-24 15:52:44 +02002415 pr_debug("ray_cs untranslate RFC default\n");
John Daiker141fa612009-03-10 06:59:54 -07002416 delta = RX_MAC_HEADER_LENGTH +
2417 sizeof(struct snaphdr_t) - ETH_HLEN;
2418 peth = (struct ethhdr *)(skb->data + delta);
2419 peth->h_proto = type;
2420 break;
2421 }
2422 } else {
2423 printk("ray_cs untranslate very confused by packet\n");
2424 delta = RX_MAC_HEADER_LENGTH - ETH_HLEN;
2425 peth = (struct ethhdr *)(skb->data + delta);
2426 peth->h_proto = type;
2427 }
Al Viro7698d692007-12-29 04:55:50 -05002428 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002429/* TBD reserve skb_reserve(skb, delta); */
John Daiker141fa612009-03-10 06:59:54 -07002430 skb_pull(skb, delta);
Dominik Brodowski624dd662009-10-24 15:52:44 +02002431 pr_debug("untranslate after skb_pull(%d), skb->data = %p\n", delta,
John Daiker141fa612009-03-10 06:59:54 -07002432 skb->data);
2433 memcpy(peth->h_dest, destaddr, ADDRLEN);
2434 memcpy(peth->h_source, srcaddr, ADDRLEN);
Dominik Brodowski624dd662009-10-24 15:52:44 +02002435#if 0
2436 {
John Daiker141fa612009-03-10 06:59:54 -07002437 int i;
2438 printk(KERN_DEBUG "skb->data after untranslate:");
2439 for (i = 0; i < 64; i++)
2440 printk("%02x ", skb->data[i]);
2441 printk("\n");
2442 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002443#endif
2444} /* end untranslate */
John Daiker141fa612009-03-10 06:59:54 -07002445
Linus Torvalds1da177e2005-04-16 15:20:36 -07002446/*===========================================================================*/
2447/* Copy data from circular receive buffer to PC memory.
2448 * dest = destination address in PC memory
2449 * pkt_addr = source address in receive buffer
2450 * len = length of packet to copy
2451 */
John Daiker141fa612009-03-10 06:59:54 -07002452static int copy_from_rx_buff(ray_dev_t *local, UCHAR *dest, int pkt_addr,
2453 int length)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002454{
John Daiker141fa612009-03-10 06:59:54 -07002455 int wrap_bytes = (pkt_addr + length) - (RX_BUFF_END + 1);
2456 if (wrap_bytes <= 0) {
2457 memcpy_fromio(dest, local->rmem + pkt_addr, length);
2458 } else { /* Packet wrapped in circular buffer */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002459
John Daiker141fa612009-03-10 06:59:54 -07002460 memcpy_fromio(dest, local->rmem + pkt_addr,
2461 length - wrap_bytes);
2462 memcpy_fromio(dest + length - wrap_bytes, local->rmem,
2463 wrap_bytes);
2464 }
2465 return length;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002466}
John Daiker141fa612009-03-10 06:59:54 -07002467
2468/*===========================================================================*/
2469static void release_frag_chain(ray_dev_t *local, struct rcs __iomem *prcs)
2470{
2471 struct rcs __iomem *prcslink = prcs;
2472 int tmp = 17;
2473 unsigned rcsindex = readb(&prcs->var.rx_packet.next_frag_rcs_index);
2474
2475 while (tmp--) {
2476 writeb(CCS_BUFFER_FREE, &prcslink->buffer_status);
2477 if (rcsindex >= (NUMBER_OF_CCS + NUMBER_OF_RCS)) {
Dominik Brodowski624dd662009-10-24 15:52:44 +02002478 pr_debug("ray_cs interrupt bad rcsindex = 0x%x\n",
John Daiker141fa612009-03-10 06:59:54 -07002479 rcsindex);
2480 break;
2481 }
2482 prcslink = rcs_base(local) + rcsindex;
2483 rcsindex = readb(&prcslink->var.rx_packet.next_frag_rcs_index);
2484 }
2485 writeb(CCS_BUFFER_FREE, &prcslink->buffer_status);
2486}
2487
Linus Torvalds1da177e2005-04-16 15:20:36 -07002488/*===========================================================================*/
2489static void authenticate(ray_dev_t *local)
2490{
John Daiker141fa612009-03-10 06:59:54 -07002491 struct pcmcia_device *link = local->finder;
Dominik Brodowski624dd662009-10-24 15:52:44 +02002492 dev_dbg(&link->dev, "ray_cs Starting authentication.\n");
John Daiker141fa612009-03-10 06:59:54 -07002493 if (!(pcmcia_dev_present(link))) {
Dominik Brodowski624dd662009-10-24 15:52:44 +02002494 dev_dbg(&link->dev, "ray_cs authenticate - device not present\n");
John Daiker141fa612009-03-10 06:59:54 -07002495 return;
2496 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002497
John Daiker141fa612009-03-10 06:59:54 -07002498 del_timer(&local->timer);
2499 if (build_auth_frame(local, local->bss_id, OPEN_AUTH_REQUEST)) {
2500 local->timer.function = &join_net;
2501 } else {
2502 local->timer.function = &authenticate_timeout;
2503 }
2504 local->timer.expires = jiffies + HZ * 2;
2505 local->timer.data = (long)local;
2506 add_timer(&local->timer);
2507 local->authentication_state = AWAITING_RESPONSE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002508} /* end authenticate */
John Daiker141fa612009-03-10 06:59:54 -07002509
Linus Torvalds1da177e2005-04-16 15:20:36 -07002510/*===========================================================================*/
2511static void rx_authenticate(ray_dev_t *local, struct rcs __iomem *prcs,
John Daiker141fa612009-03-10 06:59:54 -07002512 unsigned int pkt_addr, int rx_len)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002513{
John Daiker141fa612009-03-10 06:59:54 -07002514 UCHAR buff[256];
2515 struct rx_msg *msg = (struct rx_msg *)buff;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002516
John Daiker141fa612009-03-10 06:59:54 -07002517 del_timer(&local->timer);
2518
2519 copy_from_rx_buff(local, buff, pkt_addr, rx_len & 0xff);
2520 /* if we are trying to get authenticated */
2521 if (local->sparm.b4.a_network_type == ADHOC) {
Dominik Brodowski624dd662009-10-24 15:52:44 +02002522 pr_debug("ray_cs rx_auth var= %02x %02x %02x %02x %02x %02x\n",
John Daiker141fa612009-03-10 06:59:54 -07002523 msg->var[0], msg->var[1], msg->var[2], msg->var[3],
2524 msg->var[4], msg->var[5]);
2525 if (msg->var[2] == 1) {
Dominik Brodowski624dd662009-10-24 15:52:44 +02002526 pr_debug("ray_cs Sending authentication response.\n");
John Daiker141fa612009-03-10 06:59:54 -07002527 if (!build_auth_frame
2528 (local, msg->mac.addr_2, OPEN_AUTH_RESPONSE)) {
2529 local->authentication_state = NEED_TO_AUTH;
2530 memcpy(local->auth_id, msg->mac.addr_2,
2531 ADDRLEN);
2532 }
2533 }
2534 } else { /* Infrastructure network */
2535
2536 if (local->authentication_state == AWAITING_RESPONSE) {
2537 /* Verify authentication sequence #2 and success */
2538 if (msg->var[2] == 2) {
2539 if ((msg->var[3] | msg->var[4]) == 0) {
Dominik Brodowski624dd662009-10-24 15:52:44 +02002540 pr_debug("Authentication successful\n");
John Daiker141fa612009-03-10 06:59:54 -07002541 local->card_status = CARD_AUTH_COMPLETE;
2542 associate(local);
2543 local->authentication_state =
2544 AUTHENTICATED;
2545 } else {
Dominik Brodowski624dd662009-10-24 15:52:44 +02002546 pr_debug("Authentication refused\n");
John Daiker141fa612009-03-10 06:59:54 -07002547 local->card_status = CARD_AUTH_REFUSED;
2548 join_net((u_long) local);
2549 local->authentication_state =
2550 UNAUTHENTICATED;
2551 }
2552 }
2553 }
2554 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002555
2556} /* end rx_authenticate */
John Daiker141fa612009-03-10 06:59:54 -07002557
Linus Torvalds1da177e2005-04-16 15:20:36 -07002558/*===========================================================================*/
2559static void associate(ray_dev_t *local)
2560{
John Daiker141fa612009-03-10 06:59:54 -07002561 struct ccs __iomem *pccs;
2562 struct pcmcia_device *link = local->finder;
2563 struct net_device *dev = link->priv;
2564 int ccsindex;
2565 if (!(pcmcia_dev_present(link))) {
Dominik Brodowski624dd662009-10-24 15:52:44 +02002566 dev_dbg(&link->dev, "ray_cs associate - device not present\n");
John Daiker141fa612009-03-10 06:59:54 -07002567 return;
2568 }
2569 /* If no tx buffers available, return */
2570 if ((ccsindex = get_free_ccs(local)) < 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002571/* TBD should never be here but... what if we are? */
Dominik Brodowski624dd662009-10-24 15:52:44 +02002572 dev_dbg(&link->dev, "ray_cs associate - No free ccs\n");
John Daiker141fa612009-03-10 06:59:54 -07002573 return;
2574 }
Dominik Brodowski624dd662009-10-24 15:52:44 +02002575 dev_dbg(&link->dev, "ray_cs Starting association with access point\n");
John Daiker141fa612009-03-10 06:59:54 -07002576 pccs = ccs_base(local) + ccsindex;
2577 /* fill in the CCS */
2578 writeb(CCS_START_ASSOCIATION, &pccs->cmd);
2579 /* Interrupt the firmware to process the command */
2580 if (interrupt_ecf(local, ccsindex)) {
Dominik Brodowski624dd662009-10-24 15:52:44 +02002581 dev_dbg(&link->dev, "ray_cs associate failed - ECF not ready for intr\n");
John Daiker141fa612009-03-10 06:59:54 -07002582 writeb(CCS_BUFFER_FREE, &(pccs++)->buffer_status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002583
John Daiker141fa612009-03-10 06:59:54 -07002584 del_timer(&local->timer);
2585 local->timer.expires = jiffies + HZ * 2;
2586 local->timer.data = (long)local;
2587 local->timer.function = &join_net;
2588 add_timer(&local->timer);
2589 local->card_status = CARD_ASSOC_FAILED;
2590 return;
2591 }
2592 if (!sniffer)
2593 netif_start_queue(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002594
2595} /* end associate */
John Daiker141fa612009-03-10 06:59:54 -07002596
Linus Torvalds1da177e2005-04-16 15:20:36 -07002597/*===========================================================================*/
John Daiker141fa612009-03-10 06:59:54 -07002598static void rx_deauthenticate(ray_dev_t *local, struct rcs __iomem *prcs,
2599 unsigned int pkt_addr, int rx_len)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002600{
2601/* UCHAR buff[256];
2602 struct rx_msg *msg = (struct rx_msg *)buff;
2603*/
Dominik Brodowski624dd662009-10-24 15:52:44 +02002604 pr_debug("Deauthentication frame received\n");
John Daiker141fa612009-03-10 06:59:54 -07002605 local->authentication_state = UNAUTHENTICATED;
2606 /* Need to reauthenticate or rejoin depending on reason code */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002607/* copy_from_rx_buff(local, buff, pkt_addr, rx_len & 0xff);
2608 */
2609}
John Daiker141fa612009-03-10 06:59:54 -07002610
Linus Torvalds1da177e2005-04-16 15:20:36 -07002611/*===========================================================================*/
2612static void clear_interrupt(ray_dev_t *local)
2613{
John Daiker141fa612009-03-10 06:59:54 -07002614 writeb(0, local->amem + CIS_OFFSET + HCS_INTR_OFFSET);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002615}
John Daiker141fa612009-03-10 06:59:54 -07002616
Linus Torvalds1da177e2005-04-16 15:20:36 -07002617/*===========================================================================*/
2618#ifdef CONFIG_PROC_FS
2619#define MAXDATA (PAGE_SIZE - 80)
2620
2621static char *card_status[] = {
John Daiker141fa612009-03-10 06:59:54 -07002622 "Card inserted - uninitialized", /* 0 */
2623 "Card not downloaded", /* 1 */
2624 "Waiting for download parameters", /* 2 */
2625 "Card doing acquisition", /* 3 */
2626 "Acquisition complete", /* 4 */
2627 "Authentication complete", /* 5 */
2628 "Association complete", /* 6 */
2629 "???", "???", "???", "???", /* 7 8 9 10 undefined */
2630 "Card init error", /* 11 */
2631 "Download parameters error", /* 12 */
2632 "???", /* 13 */
2633 "Acquisition failed", /* 14 */
2634 "Authentication refused", /* 15 */
2635 "Association failed" /* 16 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002636};
2637
John Daiker141fa612009-03-10 06:59:54 -07002638static char *nettype[] = { "Adhoc", "Infra " };
2639static char *framing[] = { "Encapsulation", "Translation" }
2640
Linus Torvalds1da177e2005-04-16 15:20:36 -07002641;
2642/*===========================================================================*/
Alexey Dobriyan6b914c52008-04-10 14:34:35 -07002643static int ray_cs_proc_show(struct seq_file *m, void *v)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002644{
2645/* Print current values which are not available via other means
John Daiker141fa612009-03-10 06:59:54 -07002646 * eg ifconfig
Linus Torvalds1da177e2005-04-16 15:20:36 -07002647 */
John Daiker141fa612009-03-10 06:59:54 -07002648 int i;
2649 struct pcmcia_device *link;
2650 struct net_device *dev;
2651 ray_dev_t *local;
2652 UCHAR *p;
2653 struct freq_hop_element *pfh;
2654 UCHAR c[33];
Linus Torvalds1da177e2005-04-16 15:20:36 -07002655
John Daiker141fa612009-03-10 06:59:54 -07002656 link = this_device;
2657 if (!link)
2658 return 0;
2659 dev = (struct net_device *)link->priv;
2660 if (!dev)
2661 return 0;
2662 local = netdev_priv(dev);
2663 if (!local)
2664 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002665
John Daiker141fa612009-03-10 06:59:54 -07002666 seq_puts(m, "Raylink Wireless LAN driver status\n");
2667 seq_printf(m, "%s\n", rcsid);
2668 /* build 4 does not report version, and field is 0x55 after memtest */
2669 seq_puts(m, "Firmware version = ");
2670 if (local->fw_ver == 0x55)
2671 seq_puts(m, "4 - Use dump_cis for more details\n");
2672 else
2673 seq_printf(m, "%2d.%02d.%02d\n",
2674 local->fw_ver, local->fw_bld, local->fw_var);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002675
John Daiker141fa612009-03-10 06:59:54 -07002676 for (i = 0; i < 32; i++)
2677 c[i] = local->sparm.b5.a_current_ess_id[i];
2678 c[32] = 0;
2679 seq_printf(m, "%s network ESSID = \"%s\"\n",
2680 nettype[local->sparm.b5.a_network_type], c);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002681
John Daiker141fa612009-03-10 06:59:54 -07002682 p = local->bss_id;
2683 seq_printf(m, "BSSID = %pM\n", p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002684
John Daiker141fa612009-03-10 06:59:54 -07002685 seq_printf(m, "Country code = %d\n",
2686 local->sparm.b5.a_curr_country_code);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002687
John Daiker141fa612009-03-10 06:59:54 -07002688 i = local->card_status;
2689 if (i < 0)
2690 i = 10;
2691 if (i > 16)
2692 i = 10;
2693 seq_printf(m, "Card status = %s\n", card_status[i]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002694
John Daiker141fa612009-03-10 06:59:54 -07002695 seq_printf(m, "Framing mode = %s\n", framing[translate]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002696
John Daiker141fa612009-03-10 06:59:54 -07002697 seq_printf(m, "Last pkt signal lvl = %d\n", local->last_rsl);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002698
John Daiker141fa612009-03-10 06:59:54 -07002699 if (local->beacon_rxed) {
2700 /* Pull some fields out of last beacon received */
2701 seq_printf(m, "Beacon Interval = %d Kus\n",
2702 local->last_bcn.beacon_intvl[0]
2703 + 256 * local->last_bcn.beacon_intvl[1]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002704
John Daiker141fa612009-03-10 06:59:54 -07002705 p = local->last_bcn.elements;
2706 if (p[0] == C_ESSID_ELEMENT_ID)
2707 p += p[1] + 2;
2708 else {
2709 seq_printf(m,
2710 "Parse beacon failed at essid element id = %d\n",
2711 p[0]);
2712 return 0;
2713 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002714
John Daiker141fa612009-03-10 06:59:54 -07002715 if (p[0] == C_SUPPORTED_RATES_ELEMENT_ID) {
2716 seq_puts(m, "Supported rate codes = ");
2717 for (i = 2; i < p[1] + 2; i++)
2718 seq_printf(m, "0x%02x ", p[i]);
2719 seq_putc(m, '\n');
2720 p += p[1] + 2;
2721 } else {
2722 seq_puts(m, "Parse beacon failed at rates element\n");
2723 return 0;
2724 }
2725
2726 if (p[0] == C_FH_PARAM_SET_ELEMENT_ID) {
2727 pfh = (struct freq_hop_element *)p;
2728 seq_printf(m, "Hop dwell = %d Kus\n",
2729 pfh->dwell_time[0] +
2730 256 * pfh->dwell_time[1]);
Frans Popcb01b092010-03-24 19:46:34 +01002731 seq_printf(m, "Hop set = %d\n",
John Daiker141fa612009-03-10 06:59:54 -07002732 pfh->hop_set);
Frans Popcb01b092010-03-24 19:46:34 +01002733 seq_printf(m, "Hop pattern = %d\n",
John Daiker141fa612009-03-10 06:59:54 -07002734 pfh->hop_pattern);
Frans Popcb01b092010-03-24 19:46:34 +01002735 seq_printf(m, "Hop index = %d\n",
John Daiker141fa612009-03-10 06:59:54 -07002736 pfh->hop_index);
2737 p += p[1] + 2;
2738 } else {
2739 seq_puts(m,
2740 "Parse beacon failed at FH param element\n");
2741 return 0;
2742 }
2743 } else {
2744 seq_puts(m, "No beacons received\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002745 }
John Daiker141fa612009-03-10 06:59:54 -07002746 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002747}
2748
Alexey Dobriyan6b914c52008-04-10 14:34:35 -07002749static int ray_cs_proc_open(struct inode *inode, struct file *file)
2750{
2751 return single_open(file, ray_cs_proc_show, NULL);
2752}
2753
2754static const struct file_operations ray_cs_proc_fops = {
John Daiker141fa612009-03-10 06:59:54 -07002755 .owner = THIS_MODULE,
2756 .open = ray_cs_proc_open,
2757 .read = seq_read,
2758 .llseek = seq_lseek,
2759 .release = single_release,
Alexey Dobriyan6b914c52008-04-10 14:34:35 -07002760};
Linus Torvalds1da177e2005-04-16 15:20:36 -07002761#endif
2762/*===========================================================================*/
2763static int build_auth_frame(ray_dev_t *local, UCHAR *dest, int auth_type)
2764{
John Daiker141fa612009-03-10 06:59:54 -07002765 int addr;
2766 struct ccs __iomem *pccs;
2767 struct tx_msg __iomem *ptx;
2768 int ccsindex;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002769
John Daiker141fa612009-03-10 06:59:54 -07002770 /* If no tx buffers available, return */
2771 if ((ccsindex = get_free_tx_ccs(local)) < 0) {
Dominik Brodowski624dd662009-10-24 15:52:44 +02002772 pr_debug("ray_cs send authenticate - No free tx ccs\n");
John Daiker141fa612009-03-10 06:59:54 -07002773 return -1;
2774 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002775
John Daiker141fa612009-03-10 06:59:54 -07002776 pccs = ccs_base(local) + ccsindex;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002777
John Daiker141fa612009-03-10 06:59:54 -07002778 /* Address in card space */
2779 addr = TX_BUF_BASE + (ccsindex << 11);
2780 /* fill in the CCS */
2781 writeb(CCS_TX_REQUEST, &pccs->cmd);
2782 writeb(addr >> 8, pccs->var.tx_request.tx_data_ptr);
2783 writeb(0x20, pccs->var.tx_request.tx_data_ptr + 1);
2784 writeb(TX_AUTHENTICATE_LENGTH_MSB, pccs->var.tx_request.tx_data_length);
2785 writeb(TX_AUTHENTICATE_LENGTH_LSB,
2786 pccs->var.tx_request.tx_data_length + 1);
2787 writeb(0, &pccs->var.tx_request.pow_sav_mode);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002788
John Daiker141fa612009-03-10 06:59:54 -07002789 ptx = local->sram + addr;
2790 /* fill in the mac header */
2791 writeb(PROTOCOL_VER | AUTHENTIC_TYPE, &ptx->mac.frame_ctl_1);
2792 writeb(0, &ptx->mac.frame_ctl_2);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002793
John Daiker141fa612009-03-10 06:59:54 -07002794 memcpy_toio(ptx->mac.addr_1, dest, ADDRLEN);
2795 memcpy_toio(ptx->mac.addr_2, local->sparm.b4.a_mac_addr, ADDRLEN);
2796 memcpy_toio(ptx->mac.addr_3, local->bss_id, ADDRLEN);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002797
John Daiker141fa612009-03-10 06:59:54 -07002798 /* Fill in msg body with protocol 00 00, sequence 01 00 ,status 00 00 */
2799 memset_io(ptx->var, 0, 6);
2800 writeb(auth_type & 0xff, ptx->var + 2);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002801
John Daiker141fa612009-03-10 06:59:54 -07002802 /* Interrupt the firmware to process the command */
2803 if (interrupt_ecf(local, ccsindex)) {
Dominik Brodowski624dd662009-10-24 15:52:44 +02002804 pr_debug(
John Daiker141fa612009-03-10 06:59:54 -07002805 "ray_cs send authentication request failed - ECF not ready for intr\n");
2806 writeb(CCS_BUFFER_FREE, &(pccs++)->buffer_status);
2807 return -1;
2808 }
2809 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002810} /* End build_auth_frame */
2811
2812/*===========================================================================*/
2813#ifdef CONFIG_PROC_FS
Alexey Dobriyan83daee02009-11-25 10:12:20 +03002814static ssize_t ray_cs_essid_proc_write(struct file *file,
2815 const char __user *buffer, size_t count, loff_t *pos)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002816{
2817 static char proc_essid[33];
Alan Cox575c9ed2009-10-27 15:35:55 +00002818 unsigned int len = count;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002819
2820 if (len > 32)
2821 len = 32;
2822 memset(proc_essid, 0, 33);
2823 if (copy_from_user(proc_essid, buffer, len))
2824 return -EFAULT;
2825 essid = proc_essid;
2826 return count;
2827}
2828
Alexey Dobriyan83daee02009-11-25 10:12:20 +03002829static const struct file_operations ray_cs_essid_proc_fops = {
2830 .owner = THIS_MODULE,
2831 .write = ray_cs_essid_proc_write,
2832};
2833
2834static ssize_t int_proc_write(struct file *file, const char __user *buffer,
2835 size_t count, loff_t *pos)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002836{
2837 static char proc_number[10];
2838 char *p;
2839 int nr, len;
2840
2841 if (!count)
2842 return 0;
2843
2844 if (count > 9)
2845 return -EINVAL;
2846 if (copy_from_user(proc_number, buffer, count))
2847 return -EFAULT;
2848 p = proc_number;
2849 nr = 0;
2850 len = count;
2851 do {
2852 unsigned int c = *p - '0';
2853 if (c > 9)
2854 return -EINVAL;
John Daiker141fa612009-03-10 06:59:54 -07002855 nr = nr * 10 + c;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002856 p++;
2857 } while (--len);
Alexey Dobriyan83daee02009-11-25 10:12:20 +03002858 *(int *)PDE(file->f_path.dentry->d_inode)->data = nr;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002859 return count;
2860}
Alexey Dobriyan83daee02009-11-25 10:12:20 +03002861
2862static const struct file_operations int_proc_fops = {
2863 .owner = THIS_MODULE,
2864 .write = int_proc_write,
2865};
Linus Torvalds1da177e2005-04-16 15:20:36 -07002866#endif
2867
Dominik Brodowskif57ea2a2005-06-27 16:28:24 -07002868static struct pcmcia_device_id ray_ids[] = {
2869 PCMCIA_DEVICE_MANF_CARD(0x01a6, 0x0000),
2870 PCMCIA_DEVICE_NULL,
2871};
John Daiker141fa612009-03-10 06:59:54 -07002872
Dominik Brodowskif57ea2a2005-06-27 16:28:24 -07002873MODULE_DEVICE_TABLE(pcmcia, ray_ids);
2874
Linus Torvalds1da177e2005-04-16 15:20:36 -07002875static struct pcmcia_driver ray_driver = {
John Daiker141fa612009-03-10 06:59:54 -07002876 .owner = THIS_MODULE,
2877 .drv = {
2878 .name = "ray_cs",
2879 },
2880 .probe = ray_probe,
2881 .remove = ray_detach,
2882 .id_table = ray_ids,
2883 .suspend = ray_suspend,
2884 .resume = ray_resume,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002885};
2886
2887static int __init init_ray_cs(void)
2888{
John Daiker141fa612009-03-10 06:59:54 -07002889 int rc;
2890
Dominik Brodowski624dd662009-10-24 15:52:44 +02002891 pr_debug("%s\n", rcsid);
John Daiker141fa612009-03-10 06:59:54 -07002892 rc = pcmcia_register_driver(&ray_driver);
Dominik Brodowski624dd662009-10-24 15:52:44 +02002893 pr_debug("raylink init_module register_pcmcia_driver returns 0x%x\n",
John Daiker141fa612009-03-10 06:59:54 -07002894 rc);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002895
2896#ifdef CONFIG_PROC_FS
John Daiker141fa612009-03-10 06:59:54 -07002897 proc_mkdir("driver/ray_cs", NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002898
John Daiker141fa612009-03-10 06:59:54 -07002899 proc_create("driver/ray_cs/ray_cs", 0, NULL, &ray_cs_proc_fops);
Alexey Dobriyan83daee02009-11-25 10:12:20 +03002900 proc_create("driver/ray_cs/essid", S_IWUSR, NULL, &ray_cs_essid_proc_fops);
2901 proc_create_data("driver/ray_cs/net_type", S_IWUSR, NULL, &int_proc_fops, &net_type);
2902 proc_create_data("driver/ray_cs/translate", S_IWUSR, NULL, &int_proc_fops, &translate);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002903#endif
John Daiker141fa612009-03-10 06:59:54 -07002904 if (translate != 0)
2905 translate = 1;
2906 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002907} /* init_ray_cs */
2908
2909/*===========================================================================*/
2910
2911static void __exit exit_ray_cs(void)
2912{
Dominik Brodowski624dd662009-10-24 15:52:44 +02002913 pr_debug("ray_cs: cleanup_module\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002914
2915#ifdef CONFIG_PROC_FS
John Daiker141fa612009-03-10 06:59:54 -07002916 remove_proc_entry("driver/ray_cs/ray_cs", NULL);
2917 remove_proc_entry("driver/ray_cs/essid", NULL);
2918 remove_proc_entry("driver/ray_cs/net_type", NULL);
2919 remove_proc_entry("driver/ray_cs/translate", NULL);
2920 remove_proc_entry("driver/ray_cs", NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002921#endif
2922
John Daiker141fa612009-03-10 06:59:54 -07002923 pcmcia_unregister_driver(&ray_driver);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002924} /* exit_ray_cs */
2925
2926module_init(init_ray_cs);
2927module_exit(exit_ray_cs);
2928
2929/*===========================================================================*/