blob: dab30a8c747033e0682f1feb7751f0b16fc8e089 [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 **************************************/
Linus Torvalds1da177e2005-04-16 15:20:36 -070099static void authenticate(ray_dev_t *local);
100static int build_auth_frame(ray_dev_t *local, UCHAR *dest, int auth_type);
101static void authenticate_timeout(u_long);
102static int get_free_ccs(ray_dev_t *local);
103static int get_free_tx_ccs(ray_dev_t *local);
104static void init_startup_params(ray_dev_t *local);
105static int parse_addr(char *in_str, UCHAR *out);
John Daiker141fa612009-03-10 06:59:54 -0700106static int ray_hw_xmit(unsigned char *data, int len, struct net_device *dev, UCHAR type);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700107static int ray_init(struct net_device *dev);
108static int interrupt_ecf(ray_dev_t *local, int ccs);
109static void ray_reset(struct net_device *dev);
110static void ray_update_parm(struct net_device *dev, UCHAR objid, UCHAR *value, int len);
111static void verify_dl_startup(u_long);
112
113/* Prototypes for interrpt time functions **********************************/
John Daiker141fa612009-03-10 06:59:54 -0700114static irqreturn_t ray_interrupt(int reg, void *dev_id);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700115static void clear_interrupt(ray_dev_t *local);
John Daiker141fa612009-03-10 06:59:54 -0700116static void rx_deauthenticate(ray_dev_t *local, struct rcs __iomem *prcs,
117 unsigned int pkt_addr, int rx_len);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700118static int copy_from_rx_buff(ray_dev_t *local, UCHAR *dest, int pkt_addr, int len);
119static void ray_rx(struct net_device *dev, ray_dev_t *local, struct rcs __iomem *prcs);
120static void release_frag_chain(ray_dev_t *local, struct rcs __iomem *prcs);
121static void rx_authenticate(ray_dev_t *local, struct rcs __iomem *prcs,
John Daiker141fa612009-03-10 06:59:54 -0700122 unsigned int pkt_addr, int rx_len);
123static void rx_data(struct net_device *dev, struct rcs __iomem *prcs,
124 unsigned int pkt_addr, int rx_len);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700125static void associate(ray_dev_t *local);
126
127/* Card command functions */
128static int dl_startup_params(struct net_device *dev);
129static void join_net(u_long local);
130static void start_net(u_long local);
131/* void start_net(ray_dev_t *local); */
132
133/*===========================================================================*/
134/* Parameters that can be set with 'insmod' */
135
136/* ADHOC=0, Infrastructure=1 */
137static int net_type = ADHOC;
138
139/* Hop dwell time in Kus (1024 us units defined by 802.11) */
140static int hop_dwell = 128;
141
142/* Beacon period in Kus */
143static int beacon_period = 256;
144
145/* power save mode (0 = off, 1 = save power) */
146static int psm;
147
148/* String for network's Extended Service Set ID. 32 Characters max */
149static char *essid;
150
151/* Default to encapsulation unless translation requested */
152static int translate = 1;
153
154static int country = USA;
155
156static int sniffer;
157
158static int bc;
159
160/* 48 bit physical card address if overriding card's real physical
161 * address is required. Since IEEE 802.11 addresses are 48 bits
162 * like ethernet, an int can't be used, so a string is used. To
163 * allow use of addresses starting with a decimal digit, the first
164 * character must be a letter and will be ignored. This letter is
165 * followed by up to 12 hex digits which are the address. If less
166 * than 12 digits are used, the address will be left filled with 0's.
167 * Note that bit 0 of the first byte is the broadcast bit, and evil
168 * things will happen if it is not 0 in a card address.
169 */
170static char *phy_addr = NULL;
171
172
Dominik Brodowskifba395e2006-03-31 17:21:06 +0200173/* A struct pcmcia_device structure has fields for most things that are needed
Linus Torvalds1da177e2005-04-16 15:20:36 -0700174 to keep track of a socket, but there will usually be some device
175 specific information that also needs to be kept track of. The
Dominik Brodowskifba395e2006-03-31 17:21:06 +0200176 'priv' pointer in a struct pcmcia_device structure can be used to point to
Linus Torvalds1da177e2005-04-16 15:20:36 -0700177 a device-specific private data structure, like this.
178*/
179static unsigned int ray_mem_speed = 500;
180
Dominik Brodowskifd238232006-03-05 10:45:09 +0100181/* WARNING: THIS DRIVER IS NOT CAPABLE OF HANDLING MULTIPLE DEVICES! */
182static struct pcmcia_device *this_device = NULL;
183
Linus Torvalds1da177e2005-04-16 15:20:36 -0700184MODULE_AUTHOR("Corey Thomas <corey@world.std.com>");
185MODULE_DESCRIPTION("Raylink/WebGear wireless LAN driver");
186MODULE_LICENSE("GPL");
187
188module_param(net_type, int, 0);
189module_param(hop_dwell, int, 0);
190module_param(beacon_period, int, 0);
191module_param(psm, int, 0);
192module_param(essid, charp, 0);
193module_param(translate, int, 0);
194module_param(country, int, 0);
195module_param(sniffer, int, 0);
196module_param(bc, int, 0);
197module_param(phy_addr, charp, 0);
198module_param(ray_mem_speed, int, 0);
199
200static UCHAR b5_default_startup_parms[] = {
John Daiker141fa612009-03-10 06:59:54 -0700201 0, 0, /* Adhoc station */
202 'L', 'I', 'N', 'U', 'X', 0, 0, 0, /* 32 char ESSID */
203 0, 0, 0, 0, 0, 0, 0, 0,
204 0, 0, 0, 0, 0, 0, 0, 0,
205 0, 0, 0, 0, 0, 0, 0, 0,
206 1, 0, /* Active scan, CA Mode */
207 0, 0, 0, 0, 0, 0, /* No default MAC addr */
208 0x7f, 0xff, /* Frag threshold */
209 0x00, 0x80, /* Hop time 128 Kus */
210 0x01, 0x00, /* Beacon period 256 Kus */
211 0x01, 0x07, 0xa3, /* DTIM, retries, ack timeout */
212 0x1d, 0x82, 0x4e, /* SIFS, DIFS, PIFS */
213 0x7f, 0xff, /* RTS threshold */
214 0x04, 0xe2, 0x38, 0xA4, /* scan_dwell, max_scan_dwell */
215 0x05, /* assoc resp timeout thresh */
216 0x08, 0x02, 0x08, /* adhoc, infra, super cycle max */
217 0, /* Promiscuous mode */
218 0x0c, 0x0bd, /* Unique word */
219 0x32, /* Slot time */
220 0xff, 0xff, /* roam-low snr, low snr count */
221 0x05, 0xff, /* Infra, adhoc missed bcn thresh */
222 0x01, 0x0b, 0x4f, /* USA, hop pattern, hop pat length */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700223/* b4 - b5 differences start here */
John Daiker141fa612009-03-10 06:59:54 -0700224 0x00, 0x3f, /* CW max */
225 0x00, 0x0f, /* CW min */
226 0x04, 0x08, /* Noise gain, limit offset */
227 0x28, 0x28, /* det rssi, med busy offsets */
228 7, /* det sync thresh */
229 0, 2, 2, /* test mode, min, max */
230 0, /* allow broadcast SSID probe resp */
231 0, 0, /* privacy must start, can join */
232 2, 0, 0, 0, 0, 0, 0, 0 /* basic rate set */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700233};
234
235static UCHAR b4_default_startup_parms[] = {
John Daiker141fa612009-03-10 06:59:54 -0700236 0, 0, /* Adhoc station */
237 'L', 'I', 'N', 'U', 'X', 0, 0, 0, /* 32 char ESSID */
238 0, 0, 0, 0, 0, 0, 0, 0,
239 0, 0, 0, 0, 0, 0, 0, 0,
240 0, 0, 0, 0, 0, 0, 0, 0,
241 1, 0, /* Active scan, CA Mode */
242 0, 0, 0, 0, 0, 0, /* No default MAC addr */
243 0x7f, 0xff, /* Frag threshold */
244 0x02, 0x00, /* Hop time */
245 0x00, 0x01, /* Beacon period */
246 0x01, 0x07, 0xa3, /* DTIM, retries, ack timeout */
247 0x1d, 0x82, 0xce, /* SIFS, DIFS, PIFS */
248 0x7f, 0xff, /* RTS threshold */
249 0xfb, 0x1e, 0xc7, 0x5c, /* scan_dwell, max_scan_dwell */
250 0x05, /* assoc resp timeout thresh */
251 0x04, 0x02, 0x4, /* adhoc, infra, super cycle max */
252 0, /* Promiscuous mode */
253 0x0c, 0x0bd, /* Unique word */
254 0x4e, /* Slot time (TBD seems wrong) */
255 0xff, 0xff, /* roam-low snr, low snr count */
256 0x05, 0xff, /* Infra, adhoc missed bcn thresh */
257 0x01, 0x0b, 0x4e, /* USA, hop pattern, hop pat length */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700258/* b4 - b5 differences start here */
John Daiker141fa612009-03-10 06:59:54 -0700259 0x3f, 0x0f, /* CW max, min */
260 0x04, 0x08, /* Noise gain, limit offset */
261 0x28, 0x28, /* det rssi, med busy offsets */
262 7, /* det sync thresh */
263 0, 2, 2 /* test mode, min, max */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700264};
John Daiker141fa612009-03-10 06:59:54 -0700265
Linus Torvalds1da177e2005-04-16 15:20:36 -0700266/*===========================================================================*/
John Daiker141fa612009-03-10 06:59:54 -0700267static unsigned char eth2_llc[] = { 0xaa, 0xaa, 3, 0, 0, 0 };
Linus Torvalds1da177e2005-04-16 15:20:36 -0700268
269static char hop_pattern_length[] = { 1,
John Daiker141fa612009-03-10 06:59:54 -0700270 USA_HOP_MOD, EUROPE_HOP_MOD,
271 JAPAN_HOP_MOD, KOREA_HOP_MOD,
272 SPAIN_HOP_MOD, FRANCE_HOP_MOD,
273 ISRAEL_HOP_MOD, AUSTRALIA_HOP_MOD,
274 JAPAN_TEST_HOP_MOD
Linus Torvalds1da177e2005-04-16 15:20:36 -0700275};
276
John Daiker141fa612009-03-10 06:59:54 -0700277static char rcsid[] =
278 "Raylink/WebGear wireless LAN - Corey <Thomas corey@world.std.com>";
Linus Torvalds1da177e2005-04-16 15:20:36 -0700279
Stephen Hemminger32f5a332009-03-20 19:36:28 +0000280static const struct net_device_ops ray_netdev_ops = {
281 .ndo_init = ray_dev_init,
282 .ndo_open = ray_open,
283 .ndo_stop = ray_dev_close,
284 .ndo_start_xmit = ray_dev_start_xmit,
285 .ndo_set_config = ray_dev_config,
286 .ndo_get_stats = ray_get_stats,
287 .ndo_set_multicast_list = set_multicast_list,
288 .ndo_change_mtu = eth_change_mtu,
289 .ndo_set_mac_address = eth_mac_addr,
290 .ndo_validate_addr = eth_validate_addr,
291};
292
Linus Torvalds1da177e2005-04-16 15:20:36 -0700293/*=============================================================================
294 ray_attach() creates an "instance" of the driver, allocating
295 local data structures for one device. The device is registered
296 with Card Services.
297 The dev_link structure is initialized, but we don't actually
298 configure the card at this point -- we wait until we receive a
299 card insertion event.
300=============================================================================*/
Dominik Brodowski15b99ac2006-03-31 17:26:06 +0200301static int ray_probe(struct pcmcia_device *p_dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700302{
John Daiker141fa612009-03-10 06:59:54 -0700303 ray_dev_t *local;
304 struct net_device *dev;
Dominik Brodowskifd238232006-03-05 10:45:09 +0100305
Dominik Brodowski624dd662009-10-24 15:52:44 +0200306 dev_dbg(&p_dev->dev, "ray_attach()\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700307
John Daiker141fa612009-03-10 06:59:54 -0700308 /* Allocate space for private device-specific data */
309 dev = alloc_etherdev(sizeof(ray_dev_t));
310 if (!dev)
311 goto fail_alloc_dev;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700312
John Daiker141fa612009-03-10 06:59:54 -0700313 local = netdev_priv(dev);
314 local->finder = p_dev;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700315
John Daiker141fa612009-03-10 06:59:54 -0700316 /* The io structure describes IO port mapping. None used here */
Dominik Brodowski90abdc32010-07-24 17:23:51 +0200317 p_dev->resource[0]->end = 0;
318 p_dev->resource[0]->flags |= IO_DATA_PATH_WIDTH_8;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700319
John Daiker141fa612009-03-10 06:59:54 -0700320 /* General socket configuration */
321 p_dev->conf.Attributes = CONF_ENABLE_IRQ;
322 p_dev->conf.IntType = INT_MEMORY_AND_IO;
323 p_dev->conf.ConfigIndex = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700324
John Daiker141fa612009-03-10 06:59:54 -0700325 p_dev->priv = dev;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700326
John Daiker141fa612009-03-10 06:59:54 -0700327 local->finder = p_dev;
328 local->card_status = CARD_INSERTED;
329 local->authentication_state = UNAUTHENTICATED;
330 local->num_multi = 0;
Dominik Brodowski624dd662009-10-24 15:52:44 +0200331 dev_dbg(&p_dev->dev, "ray_attach p_dev = %p, dev = %p, local = %p, intr = %p\n",
John Daiker141fa612009-03-10 06:59:54 -0700332 p_dev, dev, local, &ray_interrupt);
333
334 /* Raylink entries in the device structure */
Stephen Hemminger32f5a332009-03-20 19:36:28 +0000335 dev->netdev_ops = &ray_netdev_ops;
John Daiker141fa612009-03-10 06:59:54 -0700336 SET_ETHTOOL_OPS(dev, &netdev_ethtool_ops);
337 dev->wireless_handlers = &ray_handler_def;
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -0700338#ifdef WIRELESS_SPY
John Daiker141fa612009-03-10 06:59:54 -0700339 local->wireless_data.spy_data = &local->spy_data;
340 dev->wireless_data = &local->wireless_data;
341#endif /* WIRELESS_SPY */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700342
Linus Torvalds1da177e2005-04-16 15:20:36 -0700343
Dominik Brodowski624dd662009-10-24 15:52:44 +0200344 dev_dbg(&p_dev->dev, "ray_cs ray_attach calling ether_setup.)\n");
John Daiker141fa612009-03-10 06:59:54 -0700345 netif_stop_queue(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700346
John Daiker141fa612009-03-10 06:59:54 -0700347 init_timer(&local->timer);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700348
John Daiker141fa612009-03-10 06:59:54 -0700349 this_device = p_dev;
350 return ray_config(p_dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700351
352fail_alloc_dev:
John Daiker141fa612009-03-10 06:59:54 -0700353 return -ENOMEM;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700354} /* ray_attach */
John Daiker141fa612009-03-10 06:59:54 -0700355
Linus Torvalds1da177e2005-04-16 15:20:36 -0700356/*=============================================================================
357 This deletes a driver "instance". The device is de-registered
358 with Card Services. If it has been released, all local data
359 structures are freed. Otherwise, the structures will be freed
360 when the device is released.
361=============================================================================*/
Dominik Brodowskifba395e2006-03-31 17:21:06 +0200362static void ray_detach(struct pcmcia_device *link)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700363{
John Daiker141fa612009-03-10 06:59:54 -0700364 struct net_device *dev;
365 ray_dev_t *local;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700366
Dominik Brodowski624dd662009-10-24 15:52:44 +0200367 dev_dbg(&link->dev, "ray_detach\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700368
John Daiker141fa612009-03-10 06:59:54 -0700369 this_device = NULL;
370 dev = link->priv;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700371
John Daiker141fa612009-03-10 06:59:54 -0700372 ray_release(link);
Dominik Brodowskicc3b4862005-11-14 21:23:14 +0100373
John Daiker141fa612009-03-10 06:59:54 -0700374 local = netdev_priv(dev);
375 del_timer(&local->timer);
Dominik Brodowskicc3b4862005-11-14 21:23:14 +0100376
John Daiker141fa612009-03-10 06:59:54 -0700377 if (link->priv) {
Dominik Brodowskic7c2fa02010-03-20 19:39:26 +0100378 unregister_netdev(dev);
John Daiker141fa612009-03-10 06:59:54 -0700379 free_netdev(dev);
380 }
Dominik Brodowski624dd662009-10-24 15:52:44 +0200381 dev_dbg(&link->dev, "ray_cs ray_detach ending\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700382} /* ray_detach */
John Daiker141fa612009-03-10 06:59:54 -0700383
Linus Torvalds1da177e2005-04-16 15:20:36 -0700384/*=============================================================================
385 ray_config() is run after a CARD_INSERTION event
386 is received, to configure the PCMCIA socket, and to make the
387 ethernet device available to the system.
388=============================================================================*/
Linus Torvalds1da177e2005-04-16 15:20:36 -0700389#define MAX_TUPLE_SIZE 128
Dominik Brodowski15b99ac2006-03-31 17:26:06 +0200390static int ray_config(struct pcmcia_device *link)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700391{
Dominik Brodowski624dd662009-10-24 15:52:44 +0200392 int ret = 0;
John Daiker141fa612009-03-10 06:59:54 -0700393 int i;
394 win_req_t req;
John Daiker141fa612009-03-10 06:59:54 -0700395 struct net_device *dev = (struct net_device *)link->priv;
396 ray_dev_t *local = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700397
Dominik Brodowski624dd662009-10-24 15:52:44 +0200398 dev_dbg(&link->dev, "ray_config\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700399
John Daiker141fa612009-03-10 06:59:54 -0700400 /* Determine card type and firmware version */
401 printk(KERN_INFO "ray_cs Detected: %s%s%s%s\n",
402 link->prod_id[0] ? link->prod_id[0] : " ",
403 link->prod_id[1] ? link->prod_id[1] : " ",
404 link->prod_id[2] ? link->prod_id[2] : " ",
405 link->prod_id[3] ? link->prod_id[3] : " ");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700406
John Daiker141fa612009-03-10 06:59:54 -0700407 /* Now allocate an interrupt line. Note that this does not
408 actually assign a handler to the interrupt.
409 */
Dominik Brodowskieb141202010-03-07 12:21:16 +0100410 ret = pcmcia_request_irq(link, ray_interrupt);
Dominik Brodowski624dd662009-10-24 15:52:44 +0200411 if (ret)
412 goto failed;
Dominik Brodowskieb141202010-03-07 12:21:16 +0100413 dev->irq = link->irq;
John Daiker141fa612009-03-10 06:59:54 -0700414
415 /* This actually configures the PCMCIA socket -- setting up
416 the I/O windows and the interrupt mapping.
417 */
Dominik Brodowski624dd662009-10-24 15:52:44 +0200418 ret = pcmcia_request_configuration(link, &link->conf);
419 if (ret)
420 goto failed;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700421
422/*** Set up 32k window for shared memory (transmit and control) ************/
John Daiker141fa612009-03-10 06:59:54 -0700423 req.Attributes =
424 WIN_DATA_WIDTH_8 | WIN_MEMORY_TYPE_CM | WIN_ENABLE | WIN_USE_WAIT;
425 req.Base = 0;
426 req.Size = 0x8000;
427 req.AccessSpeed = ray_mem_speed;
Dominik Brodowski6838b032009-11-03 01:31:52 +0100428 ret = pcmcia_request_window(link, &req, &link->win);
Dominik Brodowski624dd662009-10-24 15:52:44 +0200429 if (ret)
430 goto failed;
Dominik Brodowskib5cb2592010-07-24 18:46:42 +0200431 ret = pcmcia_map_mem_page(link, link->win, 0);
Dominik Brodowski624dd662009-10-24 15:52:44 +0200432 if (ret)
433 goto failed;
John Daiker141fa612009-03-10 06:59:54 -0700434 local->sram = ioremap(req.Base, req.Size);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700435
436/*** Set up 16k window for shared memory (receive buffer) ***************/
John Daiker141fa612009-03-10 06:59:54 -0700437 req.Attributes =
438 WIN_DATA_WIDTH_8 | WIN_MEMORY_TYPE_CM | WIN_ENABLE | WIN_USE_WAIT;
439 req.Base = 0;
440 req.Size = 0x4000;
441 req.AccessSpeed = ray_mem_speed;
Dominik Brodowski6838b032009-11-03 01:31:52 +0100442 ret = pcmcia_request_window(link, &req, &local->rmem_handle);
Dominik Brodowski624dd662009-10-24 15:52:44 +0200443 if (ret)
444 goto failed;
Dominik Brodowskib5cb2592010-07-24 18:46:42 +0200445 ret = pcmcia_map_mem_page(link, local->rmem_handle, 0x8000);
Dominik Brodowski624dd662009-10-24 15:52:44 +0200446 if (ret)
447 goto failed;
John Daiker141fa612009-03-10 06:59:54 -0700448 local->rmem = ioremap(req.Base, req.Size);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700449
450/*** Set up window for attribute memory ***********************************/
John Daiker141fa612009-03-10 06:59:54 -0700451 req.Attributes =
452 WIN_DATA_WIDTH_8 | WIN_MEMORY_TYPE_AM | WIN_ENABLE | WIN_USE_WAIT;
453 req.Base = 0;
454 req.Size = 0x1000;
455 req.AccessSpeed = ray_mem_speed;
Dominik Brodowski6838b032009-11-03 01:31:52 +0100456 ret = pcmcia_request_window(link, &req, &local->amem_handle);
Dominik Brodowski624dd662009-10-24 15:52:44 +0200457 if (ret)
458 goto failed;
Dominik Brodowskib5cb2592010-07-24 18:46:42 +0200459 ret = pcmcia_map_mem_page(link, local->amem_handle, 0);
Dominik Brodowski624dd662009-10-24 15:52:44 +0200460 if (ret)
461 goto failed;
John Daiker141fa612009-03-10 06:59:54 -0700462 local->amem = ioremap(req.Base, req.Size);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700463
Dominik Brodowski624dd662009-10-24 15:52:44 +0200464 dev_dbg(&link->dev, "ray_config sram=%p\n", local->sram);
465 dev_dbg(&link->dev, "ray_config rmem=%p\n", local->rmem);
466 dev_dbg(&link->dev, "ray_config amem=%p\n", local->amem);
John Daiker141fa612009-03-10 06:59:54 -0700467 if (ray_init(dev) < 0) {
468 ray_release(link);
469 return -ENODEV;
470 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700471
Dominik Brodowskidd2e5a12009-11-03 10:27:34 +0100472 SET_NETDEV_DEV(dev, &link->dev);
John Daiker141fa612009-03-10 06:59:54 -0700473 i = register_netdev(dev);
474 if (i != 0) {
475 printk("ray_config register_netdev() failed\n");
476 ray_release(link);
477 return i;
478 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700479
John Daiker141fa612009-03-10 06:59:54 -0700480 printk(KERN_INFO "%s: RayLink, irq %d, hw_addr %pM\n",
481 dev->name, dev->irq, dev->dev_addr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700482
John Daiker141fa612009-03-10 06:59:54 -0700483 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700484
Dominik Brodowski624dd662009-10-24 15:52:44 +0200485failed:
John Daiker141fa612009-03-10 06:59:54 -0700486 ray_release(link);
487 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700488} /* ray_config */
489
490static inline struct ccs __iomem *ccs_base(ray_dev_t *dev)
491{
492 return dev->sram + CCS_BASE;
493}
494
495static inline struct rcs __iomem *rcs_base(ray_dev_t *dev)
496{
497 /*
498 * This looks nonsensical, since there is a separate
499 * RCS_BASE. But the difference between a "struct rcs"
500 * and a "struct ccs" ends up being in the _index_ off
501 * the base, so the base pointer is the same for both
502 * ccs/rcs.
503 */
504 return dev->sram + CCS_BASE;
505}
506
507/*===========================================================================*/
508static int ray_init(struct net_device *dev)
509{
John Daiker141fa612009-03-10 06:59:54 -0700510 int i;
511 UCHAR *p;
512 struct ccs __iomem *pccs;
513 ray_dev_t *local = netdev_priv(dev);
514 struct pcmcia_device *link = local->finder;
Dominik Brodowski624dd662009-10-24 15:52:44 +0200515 dev_dbg(&link->dev, "ray_init(0x%p)\n", dev);
John Daiker141fa612009-03-10 06:59:54 -0700516 if (!(pcmcia_dev_present(link))) {
Dominik Brodowski624dd662009-10-24 15:52:44 +0200517 dev_dbg(&link->dev, "ray_init - device not present\n");
John Daiker141fa612009-03-10 06:59:54 -0700518 return -1;
519 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700520
John Daiker141fa612009-03-10 06:59:54 -0700521 local->net_type = net_type;
522 local->sta_type = TYPE_STA;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700523
John Daiker141fa612009-03-10 06:59:54 -0700524 /* Copy the startup results to local memory */
525 memcpy_fromio(&local->startup_res, local->sram + ECF_TO_HOST_BASE,
526 sizeof(struct startup_res_6));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700527
John Daiker141fa612009-03-10 06:59:54 -0700528 /* Check Power up test status and get mac address from card */
529 if (local->startup_res.startup_word != 0x80) {
530 printk(KERN_INFO "ray_init ERROR card status = %2x\n",
531 local->startup_res.startup_word);
532 local->card_status = CARD_INIT_ERROR;
533 return -1;
534 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700535
John Daiker141fa612009-03-10 06:59:54 -0700536 local->fw_ver = local->startup_res.firmware_version[0];
537 local->fw_bld = local->startup_res.firmware_version[1];
538 local->fw_var = local->startup_res.firmware_version[2];
Frans Popcb01b092010-03-24 19:46:34 +0100539 dev_dbg(&link->dev, "ray_init firmware version %d.%d\n", local->fw_ver,
John Daiker141fa612009-03-10 06:59:54 -0700540 local->fw_bld);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700541
John Daiker141fa612009-03-10 06:59:54 -0700542 local->tib_length = 0x20;
543 if ((local->fw_ver == 5) && (local->fw_bld >= 30))
544 local->tib_length = local->startup_res.tib_length;
Dominik Brodowski624dd662009-10-24 15:52:44 +0200545 dev_dbg(&link->dev, "ray_init tib_length = 0x%02x\n", local->tib_length);
John Daiker141fa612009-03-10 06:59:54 -0700546 /* Initialize CCS's to buffer free state */
547 pccs = ccs_base(local);
548 for (i = 0; i < NUMBER_OF_CCS; i++) {
549 writeb(CCS_BUFFER_FREE, &(pccs++)->buffer_status);
550 }
551 init_startup_params(local);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700552
John Daiker141fa612009-03-10 06:59:54 -0700553 /* copy mac address to startup parameters */
554 if (parse_addr(phy_addr, local->sparm.b4.a_mac_addr)) {
555 p = local->sparm.b4.a_mac_addr;
556 } else {
557 memcpy(&local->sparm.b4.a_mac_addr,
558 &local->startup_res.station_addr, ADDRLEN);
559 p = local->sparm.b4.a_mac_addr;
560 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700561
John Daiker141fa612009-03-10 06:59:54 -0700562 clear_interrupt(local); /* Clear any interrupt from the card */
563 local->card_status = CARD_AWAITING_PARAM;
Dominik Brodowski624dd662009-10-24 15:52:44 +0200564 dev_dbg(&link->dev, "ray_init ending\n");
John Daiker141fa612009-03-10 06:59:54 -0700565 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700566} /* ray_init */
John Daiker141fa612009-03-10 06:59:54 -0700567
Linus Torvalds1da177e2005-04-16 15:20:36 -0700568/*===========================================================================*/
569/* Download startup parameters to the card and command it to read them */
570static int dl_startup_params(struct net_device *dev)
571{
John Daiker141fa612009-03-10 06:59:54 -0700572 int ccsindex;
573 ray_dev_t *local = netdev_priv(dev);
574 struct ccs __iomem *pccs;
575 struct pcmcia_device *link = local->finder;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700576
Dominik Brodowski624dd662009-10-24 15:52:44 +0200577 dev_dbg(&link->dev, "dl_startup_params entered\n");
John Daiker141fa612009-03-10 06:59:54 -0700578 if (!(pcmcia_dev_present(link))) {
Dominik Brodowski624dd662009-10-24 15:52:44 +0200579 dev_dbg(&link->dev, "ray_cs dl_startup_params - device not present\n");
John Daiker141fa612009-03-10 06:59:54 -0700580 return -1;
581 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700582
John Daiker141fa612009-03-10 06:59:54 -0700583 /* Copy parameters to host to ECF area */
584 if (local->fw_ver == 0x55)
585 memcpy_toio(local->sram + HOST_TO_ECF_BASE, &local->sparm.b4,
586 sizeof(struct b4_startup_params));
587 else
588 memcpy_toio(local->sram + HOST_TO_ECF_BASE, &local->sparm.b5,
589 sizeof(struct b5_startup_params));
590
591 /* Fill in the CCS fields for the ECF */
592 if ((ccsindex = get_free_ccs(local)) < 0)
593 return -1;
594 local->dl_param_ccs = ccsindex;
595 pccs = ccs_base(local) + ccsindex;
596 writeb(CCS_DOWNLOAD_STARTUP_PARAMS, &pccs->cmd);
Dominik Brodowski624dd662009-10-24 15:52:44 +0200597 dev_dbg(&link->dev, "dl_startup_params start ccsindex = %d\n",
John Daiker141fa612009-03-10 06:59:54 -0700598 local->dl_param_ccs);
599 /* Interrupt the firmware to process the command */
600 if (interrupt_ecf(local, ccsindex)) {
601 printk(KERN_INFO "ray dl_startup_params failed - "
602 "ECF not ready for intr\n");
603 local->card_status = CARD_DL_PARAM_ERROR;
604 writeb(CCS_BUFFER_FREE, &(pccs++)->buffer_status);
605 return -2;
606 }
607 local->card_status = CARD_DL_PARAM;
608 /* Start kernel timer to wait for dl startup to complete. */
609 local->timer.expires = jiffies + HZ / 2;
610 local->timer.data = (long)local;
611 local->timer.function = &verify_dl_startup;
612 add_timer(&local->timer);
Dominik Brodowski624dd662009-10-24 15:52:44 +0200613 dev_dbg(&link->dev,
John Daiker141fa612009-03-10 06:59:54 -0700614 "ray_cs dl_startup_params started timer for verify_dl_startup\n");
615 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700616} /* dl_startup_params */
John Daiker141fa612009-03-10 06:59:54 -0700617
Linus Torvalds1da177e2005-04-16 15:20:36 -0700618/*===========================================================================*/
619static void init_startup_params(ray_dev_t *local)
620{
John Daiker141fa612009-03-10 06:59:54 -0700621 int i;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700622
John Daiker141fa612009-03-10 06:59:54 -0700623 if (country > JAPAN_TEST)
624 country = USA;
625 else if (country < USA)
626 country = USA;
627 /* structure for hop time and beacon period is defined here using
628 * New 802.11D6.1 format. Card firmware is still using old format
629 * until version 6.
630 * Before After
631 * a_hop_time ms byte a_hop_time ms byte
632 * a_hop_time 2s byte a_hop_time ls byte
633 * a_hop_time ls byte a_beacon_period ms byte
634 * a_beacon_period a_beacon_period ls byte
635 *
636 * a_hop_time = uS a_hop_time = KuS
637 * a_beacon_period = hops a_beacon_period = KuS
638 *//* 64ms = 010000 */
639 if (local->fw_ver == 0x55) {
640 memcpy((UCHAR *) &local->sparm.b4, b4_default_startup_parms,
641 sizeof(struct b4_startup_params));
642 /* Translate sane kus input values to old build 4/5 format */
643 /* i = hop time in uS truncated to 3 bytes */
644 i = (hop_dwell * 1024) & 0xffffff;
645 local->sparm.b4.a_hop_time[0] = (i >> 16) & 0xff;
646 local->sparm.b4.a_hop_time[1] = (i >> 8) & 0xff;
647 local->sparm.b4.a_beacon_period[0] = 0;
648 local->sparm.b4.a_beacon_period[1] =
649 ((beacon_period / hop_dwell) - 1) & 0xff;
650 local->sparm.b4.a_curr_country_code = country;
651 local->sparm.b4.a_hop_pattern_length =
652 hop_pattern_length[(int)country] - 1;
653 if (bc) {
654 local->sparm.b4.a_ack_timeout = 0x50;
655 local->sparm.b4.a_sifs = 0x3f;
656 }
657 } else { /* Version 5 uses real kus values */
658 memcpy((UCHAR *) &local->sparm.b5, b5_default_startup_parms,
659 sizeof(struct b5_startup_params));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700660
John Daiker141fa612009-03-10 06:59:54 -0700661 local->sparm.b5.a_hop_time[0] = (hop_dwell >> 8) & 0xff;
662 local->sparm.b5.a_hop_time[1] = hop_dwell & 0xff;
663 local->sparm.b5.a_beacon_period[0] =
664 (beacon_period >> 8) & 0xff;
665 local->sparm.b5.a_beacon_period[1] = beacon_period & 0xff;
666 if (psm)
667 local->sparm.b5.a_power_mgt_state = 1;
668 local->sparm.b5.a_curr_country_code = country;
669 local->sparm.b5.a_hop_pattern_length =
670 hop_pattern_length[(int)country];
671 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700672
John Daiker141fa612009-03-10 06:59:54 -0700673 local->sparm.b4.a_network_type = net_type & 0x01;
674 local->sparm.b4.a_acting_as_ap_status = TYPE_STA;
675
676 if (essid != NULL)
677 strncpy(local->sparm.b4.a_current_ess_id, essid, ESSID_SIZE);
678} /* init_startup_params */
679
Linus Torvalds1da177e2005-04-16 15:20:36 -0700680/*===========================================================================*/
681static void verify_dl_startup(u_long data)
682{
John Daiker141fa612009-03-10 06:59:54 -0700683 ray_dev_t *local = (ray_dev_t *) data;
684 struct ccs __iomem *pccs = ccs_base(local) + local->dl_param_ccs;
685 UCHAR status;
686 struct pcmcia_device *link = local->finder;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700687
John Daiker141fa612009-03-10 06:59:54 -0700688 if (!(pcmcia_dev_present(link))) {
Dominik Brodowski624dd662009-10-24 15:52:44 +0200689 dev_dbg(&link->dev, "ray_cs verify_dl_startup - device not present\n");
John Daiker141fa612009-03-10 06:59:54 -0700690 return;
691 }
Dominik Brodowski624dd662009-10-24 15:52:44 +0200692#if 0
693 {
John Daiker141fa612009-03-10 06:59:54 -0700694 int i;
695 printk(KERN_DEBUG
696 "verify_dl_startup parameters sent via ccs %d:\n",
697 local->dl_param_ccs);
698 for (i = 0; i < sizeof(struct b5_startup_params); i++) {
699 printk(" %2x",
700 (unsigned int)readb(local->sram +
701 HOST_TO_ECF_BASE + i));
702 }
703 printk("\n");
704 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700705#endif
706
John Daiker141fa612009-03-10 06:59:54 -0700707 status = readb(&pccs->buffer_status);
708 if (status != CCS_BUFFER_FREE) {
709 printk(KERN_INFO
710 "Download startup params failed. Status = %d\n",
711 status);
712 local->card_status = CARD_DL_PARAM_ERROR;
713 return;
714 }
715 if (local->sparm.b4.a_network_type == ADHOC)
716 start_net((u_long) local);
717 else
718 join_net((u_long) local);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700719} /* end verify_dl_startup */
John Daiker141fa612009-03-10 06:59:54 -0700720
Linus Torvalds1da177e2005-04-16 15:20:36 -0700721/*===========================================================================*/
722/* Command card to start a network */
723static void start_net(u_long data)
724{
John Daiker141fa612009-03-10 06:59:54 -0700725 ray_dev_t *local = (ray_dev_t *) data;
726 struct ccs __iomem *pccs;
727 int ccsindex;
728 struct pcmcia_device *link = local->finder;
729 if (!(pcmcia_dev_present(link))) {
Dominik Brodowski624dd662009-10-24 15:52:44 +0200730 dev_dbg(&link->dev, "ray_cs start_net - device not present\n");
John Daiker141fa612009-03-10 06:59:54 -0700731 return;
732 }
733 /* Fill in the CCS fields for the ECF */
734 if ((ccsindex = get_free_ccs(local)) < 0)
735 return;
736 pccs = ccs_base(local) + ccsindex;
737 writeb(CCS_START_NETWORK, &pccs->cmd);
738 writeb(0, &pccs->var.start_network.update_param);
739 /* Interrupt the firmware to process the command */
740 if (interrupt_ecf(local, ccsindex)) {
Dominik Brodowski624dd662009-10-24 15:52:44 +0200741 dev_dbg(&link->dev, "ray start net failed - card not ready for intr\n");
John Daiker141fa612009-03-10 06:59:54 -0700742 writeb(CCS_BUFFER_FREE, &(pccs++)->buffer_status);
743 return;
744 }
745 local->card_status = CARD_DOING_ACQ;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700746} /* end start_net */
John Daiker141fa612009-03-10 06:59:54 -0700747
Linus Torvalds1da177e2005-04-16 15:20:36 -0700748/*===========================================================================*/
749/* Command card to join a network */
750static void join_net(u_long data)
751{
John Daiker141fa612009-03-10 06:59:54 -0700752 ray_dev_t *local = (ray_dev_t *) data;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700753
John Daiker141fa612009-03-10 06:59:54 -0700754 struct ccs __iomem *pccs;
755 int ccsindex;
756 struct pcmcia_device *link = local->finder;
757
758 if (!(pcmcia_dev_present(link))) {
Dominik Brodowski624dd662009-10-24 15:52:44 +0200759 dev_dbg(&link->dev, "ray_cs join_net - device not present\n");
John Daiker141fa612009-03-10 06:59:54 -0700760 return;
761 }
762 /* Fill in the CCS fields for the ECF */
763 if ((ccsindex = get_free_ccs(local)) < 0)
764 return;
765 pccs = ccs_base(local) + ccsindex;
766 writeb(CCS_JOIN_NETWORK, &pccs->cmd);
767 writeb(0, &pccs->var.join_network.update_param);
768 writeb(0, &pccs->var.join_network.net_initiated);
769 /* Interrupt the firmware to process the command */
770 if (interrupt_ecf(local, ccsindex)) {
Dominik Brodowski624dd662009-10-24 15:52:44 +0200771 dev_dbg(&link->dev, "ray join net failed - card not ready for intr\n");
John Daiker141fa612009-03-10 06:59:54 -0700772 writeb(CCS_BUFFER_FREE, &(pccs++)->buffer_status);
773 return;
774 }
775 local->card_status = CARD_DOING_ACQ;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700776}
John Daiker141fa612009-03-10 06:59:54 -0700777
Linus Torvalds1da177e2005-04-16 15:20:36 -0700778/*============================================================================
779 After a card is removed, ray_release() will unregister the net
780 device, and release the PCMCIA configuration. If the device is
781 still open, this will be postponed until it is closed.
782=============================================================================*/
Dominik Brodowskifba395e2006-03-31 17:21:06 +0200783static void ray_release(struct pcmcia_device *link)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700784{
John Daiker141fa612009-03-10 06:59:54 -0700785 struct net_device *dev = link->priv;
786 ray_dev_t *local = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700787
Dominik Brodowski624dd662009-10-24 15:52:44 +0200788 dev_dbg(&link->dev, "ray_release\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700789
John Daiker141fa612009-03-10 06:59:54 -0700790 del_timer(&local->timer);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700791
John Daiker141fa612009-03-10 06:59:54 -0700792 iounmap(local->sram);
793 iounmap(local->rmem);
794 iounmap(local->amem);
John Daiker141fa612009-03-10 06:59:54 -0700795 pcmcia_disable_device(link);
796
Dominik Brodowski624dd662009-10-24 15:52:44 +0200797 dev_dbg(&link->dev, "ray_release ending\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700798}
799
Dominik Brodowskifba395e2006-03-31 17:21:06 +0200800static int ray_suspend(struct pcmcia_device *link)
Dominik Brodowski98e4c282005-11-14 21:21:18 +0100801{
Dominik Brodowski98e4c282005-11-14 21:21:18 +0100802 struct net_device *dev = link->priv;
803
Dominik Brodowskie2d40962006-03-02 00:09:29 +0100804 if (link->open)
Dominik Brodowski8661bb52006-03-02 00:02:33 +0100805 netif_device_detach(dev);
Dominik Brodowski98e4c282005-11-14 21:21:18 +0100806
807 return 0;
808}
809
Dominik Brodowskifba395e2006-03-31 17:21:06 +0200810static int ray_resume(struct pcmcia_device *link)
Dominik Brodowski98e4c282005-11-14 21:21:18 +0100811{
Dominik Brodowski98e4c282005-11-14 21:21:18 +0100812 struct net_device *dev = link->priv;
813
Dominik Brodowskie2d40962006-03-02 00:09:29 +0100814 if (link->open) {
Dominik Brodowski8661bb52006-03-02 00:02:33 +0100815 ray_reset(dev);
816 netif_device_attach(dev);
817 }
Dominik Brodowski98e4c282005-11-14 21:21:18 +0100818
819 return 0;
820}
821
Linus Torvalds1da177e2005-04-16 15:20:36 -0700822/*===========================================================================*/
Hannes Eder2ed5ba82008-12-26 00:12:59 -0800823static int ray_dev_init(struct net_device *dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700824{
825#ifdef RAY_IMMEDIATE_INIT
John Daiker141fa612009-03-10 06:59:54 -0700826 int i;
827#endif /* RAY_IMMEDIATE_INIT */
828 ray_dev_t *local = netdev_priv(dev);
829 struct pcmcia_device *link = local->finder;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700830
Dominik Brodowski624dd662009-10-24 15:52:44 +0200831 dev_dbg(&link->dev, "ray_dev_init(dev=%p)\n", dev);
John Daiker141fa612009-03-10 06:59:54 -0700832 if (!(pcmcia_dev_present(link))) {
Dominik Brodowski624dd662009-10-24 15:52:44 +0200833 dev_dbg(&link->dev, "ray_dev_init - device not present\n");
John Daiker141fa612009-03-10 06:59:54 -0700834 return -1;
835 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700836#ifdef RAY_IMMEDIATE_INIT
John Daiker141fa612009-03-10 06:59:54 -0700837 /* Download startup parameters */
838 if ((i = dl_startup_params(dev)) < 0) {
839 printk(KERN_INFO "ray_dev_init dl_startup_params failed - "
840 "returns 0x%x\n", i);
841 return -1;
842 }
843#else /* RAY_IMMEDIATE_INIT */
844 /* Postpone the card init so that we can still configure the card,
845 * for example using the Wireless Extensions. The init will happen
846 * in ray_open() - Jean II */
Dominik Brodowski624dd662009-10-24 15:52:44 +0200847 dev_dbg(&link->dev,
John Daiker141fa612009-03-10 06:59:54 -0700848 "ray_dev_init: postponing card init to ray_open() ; Status = %d\n",
849 local->card_status);
850#endif /* RAY_IMMEDIATE_INIT */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700851
John Daiker141fa612009-03-10 06:59:54 -0700852 /* copy mac and broadcast addresses to linux device */
Jiri Pirko3a6d54c2009-05-11 23:37:15 +0000853 memcpy(dev->dev_addr, &local->sparm.b4.a_mac_addr, ADDRLEN);
John Daiker141fa612009-03-10 06:59:54 -0700854 memset(dev->broadcast, 0xff, ETH_ALEN);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700855
Dominik Brodowski624dd662009-10-24 15:52:44 +0200856 dev_dbg(&link->dev, "ray_dev_init ending\n");
John Daiker141fa612009-03-10 06:59:54 -0700857 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700858}
John Daiker141fa612009-03-10 06:59:54 -0700859
Linus Torvalds1da177e2005-04-16 15:20:36 -0700860/*===========================================================================*/
861static int ray_dev_config(struct net_device *dev, struct ifmap *map)
862{
John Daiker141fa612009-03-10 06:59:54 -0700863 ray_dev_t *local = netdev_priv(dev);
864 struct pcmcia_device *link = local->finder;
865 /* Dummy routine to satisfy device structure */
Dominik Brodowski624dd662009-10-24 15:52:44 +0200866 dev_dbg(&link->dev, "ray_dev_config(dev=%p,ifmap=%p)\n", dev, map);
John Daiker141fa612009-03-10 06:59:54 -0700867 if (!(pcmcia_dev_present(link))) {
Dominik Brodowski624dd662009-10-24 15:52:44 +0200868 dev_dbg(&link->dev, "ray_dev_config - device not present\n");
John Daiker141fa612009-03-10 06:59:54 -0700869 return -1;
870 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700871
John Daiker141fa612009-03-10 06:59:54 -0700872 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700873}
John Daiker141fa612009-03-10 06:59:54 -0700874
Linus Torvalds1da177e2005-04-16 15:20:36 -0700875/*===========================================================================*/
Stephen Hemmingerd0cf9c02009-08-31 19:50:57 +0000876static netdev_tx_t ray_dev_start_xmit(struct sk_buff *skb,
877 struct net_device *dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700878{
John Daiker141fa612009-03-10 06:59:54 -0700879 ray_dev_t *local = netdev_priv(dev);
880 struct pcmcia_device *link = local->finder;
881 short length = skb->len;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700882
Stephen Hemmingerd0cf9c02009-08-31 19:50:57 +0000883 if (!pcmcia_dev_present(link)) {
Dominik Brodowski624dd662009-10-24 15:52:44 +0200884 dev_dbg(&link->dev, "ray_dev_start_xmit - device not present\n");
Stephen Hemmingerd0cf9c02009-08-31 19:50:57 +0000885 dev_kfree_skb(skb);
886 return NETDEV_TX_OK;
John Daiker141fa612009-03-10 06:59:54 -0700887 }
Stephen Hemmingerd0cf9c02009-08-31 19:50:57 +0000888
Dominik Brodowski624dd662009-10-24 15:52:44 +0200889 dev_dbg(&link->dev, "ray_dev_start_xmit(skb=%p, dev=%p)\n", skb, dev);
John Daiker141fa612009-03-10 06:59:54 -0700890 if (local->authentication_state == NEED_TO_AUTH) {
Dominik Brodowski624dd662009-10-24 15:52:44 +0200891 dev_dbg(&link->dev, "ray_cs Sending authentication request.\n");
John Daiker141fa612009-03-10 06:59:54 -0700892 if (!build_auth_frame(local, local->auth_id, OPEN_AUTH_REQUEST)) {
893 local->authentication_state = AUTHENTICATED;
894 netif_stop_queue(dev);
Patrick McHardy5b548142009-06-12 06:22:29 +0000895 return NETDEV_TX_BUSY;
John Daiker141fa612009-03-10 06:59:54 -0700896 }
897 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700898
John Daiker141fa612009-03-10 06:59:54 -0700899 if (length < ETH_ZLEN) {
900 if (skb_padto(skb, ETH_ZLEN))
Patrick McHardy6ed10652009-06-23 06:03:08 +0000901 return NETDEV_TX_OK;
John Daiker141fa612009-03-10 06:59:54 -0700902 length = ETH_ZLEN;
903 }
904 switch (ray_hw_xmit(skb->data, length, dev, DATA_TYPE)) {
905 case XMIT_NO_CCS:
906 case XMIT_NEED_AUTH:
907 netif_stop_queue(dev);
Patrick McHardy5b548142009-06-12 06:22:29 +0000908 return NETDEV_TX_BUSY;
John Daiker141fa612009-03-10 06:59:54 -0700909 case XMIT_NO_INTR:
910 case XMIT_MSG_BAD:
911 case XMIT_OK:
912 default:
John Daiker141fa612009-03-10 06:59:54 -0700913 dev_kfree_skb(skb);
John Daiker141fa612009-03-10 06:59:54 -0700914 }
Stephen Hemmingerd0cf9c02009-08-31 19:50:57 +0000915
Patrick McHardy6ed10652009-06-23 06:03:08 +0000916 return NETDEV_TX_OK;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700917} /* ray_dev_start_xmit */
John Daiker141fa612009-03-10 06:59:54 -0700918
Linus Torvalds1da177e2005-04-16 15:20:36 -0700919/*===========================================================================*/
John Daiker141fa612009-03-10 06:59:54 -0700920static int ray_hw_xmit(unsigned char *data, int len, struct net_device *dev,
921 UCHAR msg_type)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700922{
John Daiker141fa612009-03-10 06:59:54 -0700923 ray_dev_t *local = netdev_priv(dev);
924 struct ccs __iomem *pccs;
925 int ccsindex;
926 int offset;
927 struct tx_msg __iomem *ptx; /* Address of xmit buffer in PC space */
928 short int addr; /* Address of xmit buffer in card space */
929
Dominik Brodowski624dd662009-10-24 15:52:44 +0200930 pr_debug("ray_hw_xmit(data=%p, len=%d, dev=%p)\n", data, len, dev);
John Daiker141fa612009-03-10 06:59:54 -0700931 if (len + TX_HEADER_LENGTH > TX_BUF_SIZE) {
932 printk(KERN_INFO "ray_hw_xmit packet too large: %d bytes\n",
933 len);
934 return XMIT_MSG_BAD;
935 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700936 switch (ccsindex = get_free_tx_ccs(local)) {
937 case ECCSBUSY:
Dominik Brodowski624dd662009-10-24 15:52:44 +0200938 pr_debug("ray_hw_xmit tx_ccs table busy\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700939 case ECCSFULL:
Dominik Brodowski624dd662009-10-24 15:52:44 +0200940 pr_debug("ray_hw_xmit No free tx ccs\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700941 case ECARDGONE:
John Daiker141fa612009-03-10 06:59:54 -0700942 netif_stop_queue(dev);
943 return XMIT_NO_CCS;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700944 default:
945 break;
946 }
John Daiker141fa612009-03-10 06:59:54 -0700947 addr = TX_BUF_BASE + (ccsindex << 11);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700948
John Daiker141fa612009-03-10 06:59:54 -0700949 if (msg_type == DATA_TYPE) {
950 local->stats.tx_bytes += len;
951 local->stats.tx_packets++;
952 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700953
John Daiker141fa612009-03-10 06:59:54 -0700954 ptx = local->sram + addr;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700955
John Daiker141fa612009-03-10 06:59:54 -0700956 ray_build_header(local, ptx, msg_type, data);
957 if (translate) {
958 offset = translate_frame(local, ptx, data, len);
959 } else { /* Encapsulate frame */
960 /* TBD TIB length will move address of ptx->var */
961 memcpy_toio(&ptx->var, data, len);
962 offset = 0;
963 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700964
John Daiker141fa612009-03-10 06:59:54 -0700965 /* fill in the CCS */
966 pccs = ccs_base(local) + ccsindex;
967 len += TX_HEADER_LENGTH + offset;
968 writeb(CCS_TX_REQUEST, &pccs->cmd);
969 writeb(addr >> 8, &pccs->var.tx_request.tx_data_ptr[0]);
970 writeb(local->tib_length, &pccs->var.tx_request.tx_data_ptr[1]);
971 writeb(len >> 8, &pccs->var.tx_request.tx_data_length[0]);
972 writeb(len & 0xff, &pccs->var.tx_request.tx_data_length[1]);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700973/* TBD still need psm_cam? */
John Daiker141fa612009-03-10 06:59:54 -0700974 writeb(PSM_CAM, &pccs->var.tx_request.pow_sav_mode);
975 writeb(local->net_default_tx_rate, &pccs->var.tx_request.tx_rate);
976 writeb(0, &pccs->var.tx_request.antenna);
Dominik Brodowski624dd662009-10-24 15:52:44 +0200977 pr_debug("ray_hw_xmit default_tx_rate = 0x%x\n",
John Daiker141fa612009-03-10 06:59:54 -0700978 local->net_default_tx_rate);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700979
John Daiker141fa612009-03-10 06:59:54 -0700980 /* Interrupt the firmware to process the command */
981 if (interrupt_ecf(local, ccsindex)) {
Dominik Brodowski624dd662009-10-24 15:52:44 +0200982 pr_debug("ray_hw_xmit failed - ECF not ready for intr\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700983/* TBD very inefficient to copy packet to buffer, and then not
984 send it, but the alternative is to queue the messages and that
985 won't be done for a while. Maybe set tbusy until a CCS is free?
986*/
John Daiker141fa612009-03-10 06:59:54 -0700987 writeb(CCS_BUFFER_FREE, &pccs->buffer_status);
988 return XMIT_NO_INTR;
989 }
990 return XMIT_OK;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700991} /* end ray_hw_xmit */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700992
John Daiker141fa612009-03-10 06:59:54 -0700993/*===========================================================================*/
994static int translate_frame(ray_dev_t *local, struct tx_msg __iomem *ptx,
995 unsigned char *data, int len)
996{
997 __be16 proto = ((struct ethhdr *)data)->h_proto;
998 if (ntohs(proto) >= 1536) { /* DIX II ethernet frame */
Dominik Brodowski624dd662009-10-24 15:52:44 +0200999 pr_debug("ray_cs translate_frame DIX II\n");
John Daiker141fa612009-03-10 06:59:54 -07001000 /* Copy LLC header to card buffer */
1001 memcpy_toio(&ptx->var, eth2_llc, sizeof(eth2_llc));
1002 memcpy_toio(((void __iomem *)&ptx->var) + sizeof(eth2_llc),
1003 (UCHAR *) &proto, 2);
1004 if (proto == htons(ETH_P_AARP) || proto == htons(ETH_P_IPX)) {
1005 /* This is the selective translation table, only 2 entries */
1006 writeb(0xf8,
1007 &((struct snaphdr_t __iomem *)ptx->var)->org[3]);
1008 }
1009 /* Copy body of ethernet packet without ethernet header */
1010 memcpy_toio((void __iomem *)&ptx->var +
1011 sizeof(struct snaphdr_t), data + ETH_HLEN,
1012 len - ETH_HLEN);
1013 return (int)sizeof(struct snaphdr_t) - ETH_HLEN;
1014 } else { /* already 802 type, and proto is length */
Dominik Brodowski624dd662009-10-24 15:52:44 +02001015 pr_debug("ray_cs translate_frame 802\n");
John Daiker141fa612009-03-10 06:59:54 -07001016 if (proto == htons(0xffff)) { /* evil netware IPX 802.3 without LLC */
Dominik Brodowski624dd662009-10-24 15:52:44 +02001017 pr_debug("ray_cs translate_frame evil IPX\n");
John Daiker141fa612009-03-10 06:59:54 -07001018 memcpy_toio(&ptx->var, data + ETH_HLEN, len - ETH_HLEN);
1019 return 0 - ETH_HLEN;
1020 }
1021 memcpy_toio(&ptx->var, data + ETH_HLEN, len - ETH_HLEN);
1022 return 0 - ETH_HLEN;
1023 }
1024 /* TBD do other frame types */
1025} /* end translate_frame */
1026
1027/*===========================================================================*/
1028static void ray_build_header(ray_dev_t *local, struct tx_msg __iomem *ptx,
1029 UCHAR msg_type, unsigned char *data)
1030{
1031 writeb(PROTOCOL_VER | msg_type, &ptx->mac.frame_ctl_1);
1032/*** IEEE 802.11 Address field assignments *************
1033 TODS FROMDS addr_1 addr_2 addr_3 addr_4
1034Adhoc 0 0 dest src (terminal) BSSID N/A
1035AP to Terminal 0 1 dest AP(BSSID) source N/A
1036Terminal to AP 1 0 AP(BSSID) src (terminal) dest N/A
1037AP to AP 1 1 dest AP src AP dest source
1038*******************************************************/
1039 if (local->net_type == ADHOC) {
1040 writeb(0, &ptx->mac.frame_ctl_2);
1041 memcpy_toio(ptx->mac.addr_1, ((struct ethhdr *)data)->h_dest,
1042 2 * ADDRLEN);
1043 memcpy_toio(ptx->mac.addr_3, local->bss_id, ADDRLEN);
1044 } else { /* infrastructure */
1045
1046 if (local->sparm.b4.a_acting_as_ap_status) {
1047 writeb(FC2_FROM_DS, &ptx->mac.frame_ctl_2);
1048 memcpy_toio(ptx->mac.addr_1,
1049 ((struct ethhdr *)data)->h_dest, ADDRLEN);
1050 memcpy_toio(ptx->mac.addr_2, local->bss_id, 6);
1051 memcpy_toio(ptx->mac.addr_3,
1052 ((struct ethhdr *)data)->h_source, ADDRLEN);
1053 } else { /* Terminal */
1054
1055 writeb(FC2_TO_DS, &ptx->mac.frame_ctl_2);
1056 memcpy_toio(ptx->mac.addr_1, local->bss_id, ADDRLEN);
1057 memcpy_toio(ptx->mac.addr_2,
1058 ((struct ethhdr *)data)->h_source, ADDRLEN);
1059 memcpy_toio(ptx->mac.addr_3,
1060 ((struct ethhdr *)data)->h_dest, ADDRLEN);
1061 }
1062 }
1063} /* end encapsulate_frame */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001064
1065/*===========================================================================*/
1066
1067static void netdev_get_drvinfo(struct net_device *dev,
1068 struct ethtool_drvinfo *info)
1069{
1070 strcpy(info->driver, "ray_cs");
1071}
1072
Jeff Garzik7282d492006-09-13 14:30:00 -04001073static const struct ethtool_ops netdev_ethtool_ops = {
John Daiker141fa612009-03-10 06:59:54 -07001074 .get_drvinfo = netdev_get_drvinfo,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001075};
1076
1077/*====================================================================*/
1078
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001079/*------------------------------------------------------------------*/
1080/*
1081 * Wireless Handler : get protocol name
1082 */
Joe Perches43ead782010-03-18 18:29:40 -07001083static int ray_get_name(struct net_device *dev, struct iw_request_info *info,
1084 union iwreq_data *wrqu, char *extra)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001085{
Joe Perches43ead782010-03-18 18:29:40 -07001086 strcpy(wrqu->name, "IEEE 802.11-FH");
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001087 return 0;
1088}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001089
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001090/*------------------------------------------------------------------*/
1091/*
1092 * Wireless Handler : set frequency
1093 */
Joe Perches43ead782010-03-18 18:29:40 -07001094static int ray_set_freq(struct net_device *dev, struct iw_request_info *info,
1095 union iwreq_data *wrqu, char *extra)
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001096{
Yoann Padioleau6dbc9c82007-08-03 19:37:16 +02001097 ray_dev_t *local = netdev_priv(dev);
John Daiker141fa612009-03-10 06:59:54 -07001098 int err = -EINPROGRESS; /* Call commit handler */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001099
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001100 /* Reject if card is already initialised */
John Daiker141fa612009-03-10 06:59:54 -07001101 if (local->card_status != CARD_AWAITING_PARAM)
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001102 return -EBUSY;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001103
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001104 /* Setting by channel number */
Joe Perches43ead782010-03-18 18:29:40 -07001105 if ((wrqu->freq.m > USA_HOP_MOD) || (wrqu->freq.e > 0))
Linus Torvalds1da177e2005-04-16 15:20:36 -07001106 err = -EOPNOTSUPP;
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001107 else
Joe Perches43ead782010-03-18 18:29:40 -07001108 local->sparm.b5.a_hop_pattern = wrqu->freq.m;
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001109
1110 return err;
1111}
John Daiker141fa612009-03-10 06:59:54 -07001112
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001113/*------------------------------------------------------------------*/
1114/*
1115 * Wireless Handler : get frequency
1116 */
Joe Perches43ead782010-03-18 18:29:40 -07001117static int ray_get_freq(struct net_device *dev, struct iw_request_info *info,
1118 union iwreq_data *wrqu, char *extra)
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001119{
Yoann Padioleau6dbc9c82007-08-03 19:37:16 +02001120 ray_dev_t *local = netdev_priv(dev);
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001121
Joe Perches43ead782010-03-18 18:29:40 -07001122 wrqu->freq.m = local->sparm.b5.a_hop_pattern;
1123 wrqu->freq.e = 0;
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001124 return 0;
1125}
1126
1127/*------------------------------------------------------------------*/
1128/*
1129 * Wireless Handler : set ESSID
1130 */
Joe Perches43ead782010-03-18 18:29:40 -07001131static int ray_set_essid(struct net_device *dev, struct iw_request_info *info,
1132 union iwreq_data *wrqu, char *extra)
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001133{
Yoann Padioleau6dbc9c82007-08-03 19:37:16 +02001134 ray_dev_t *local = netdev_priv(dev);
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001135
1136 /* Reject if card is already initialised */
John Daiker141fa612009-03-10 06:59:54 -07001137 if (local->card_status != CARD_AWAITING_PARAM)
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001138 return -EBUSY;
1139
1140 /* Check if we asked for `any' */
Joe Perches43ead782010-03-18 18:29:40 -07001141 if (wrqu->essid.flags == 0)
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001142 /* Corey : can you do that ? */
1143 return -EOPNOTSUPP;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001144
Joe Perches43ead782010-03-18 18:29:40 -07001145 /* Check the size of the string */
1146 if (wrqu->essid.length > IW_ESSID_MAX_SIZE)
1147 return -E2BIG;
1148
1149 /* Set the ESSID in the card */
1150 memset(local->sparm.b5.a_current_ess_id, 0, IW_ESSID_MAX_SIZE);
1151 memcpy(local->sparm.b5.a_current_ess_id, extra, wrqu->essid.length);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001152
John Daiker141fa612009-03-10 06:59:54 -07001153 return -EINPROGRESS; /* Call commit handler */
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001154}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001155
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001156/*------------------------------------------------------------------*/
1157/*
1158 * Wireless Handler : get ESSID
1159 */
Joe Perches43ead782010-03-18 18:29:40 -07001160static int ray_get_essid(struct net_device *dev, struct iw_request_info *info,
1161 union iwreq_data *wrqu, char *extra)
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001162{
Yoann Padioleau6dbc9c82007-08-03 19:37:16 +02001163 ray_dev_t *local = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001164
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001165 /* Get the essid that was set */
1166 memcpy(extra, local->sparm.b5.a_current_ess_id, IW_ESSID_MAX_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001167
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001168 /* Push it out ! */
Joe Perches43ead782010-03-18 18:29:40 -07001169 wrqu->essid.length = strlen(extra);
1170 wrqu->essid.flags = 1; /* active */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001171
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001172 return 0;
1173}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001174
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001175/*------------------------------------------------------------------*/
1176/*
1177 * Wireless Handler : get AP address
1178 */
Joe Perches43ead782010-03-18 18:29:40 -07001179static int ray_get_wap(struct net_device *dev, struct iw_request_info *info,
1180 union iwreq_data *wrqu, char *extra)
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001181{
Yoann Padioleau6dbc9c82007-08-03 19:37:16 +02001182 ray_dev_t *local = netdev_priv(dev);
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001183
Joe Perches43ead782010-03-18 18:29:40 -07001184 memcpy(wrqu->ap_addr.sa_data, local->bss_id, ETH_ALEN);
1185 wrqu->ap_addr.sa_family = ARPHRD_ETHER;
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001186
1187 return 0;
1188}
1189
1190/*------------------------------------------------------------------*/
1191/*
1192 * Wireless Handler : set Bit-Rate
1193 */
Joe Perches43ead782010-03-18 18:29:40 -07001194static int ray_set_rate(struct net_device *dev, struct iw_request_info *info,
1195 union iwreq_data *wrqu, char *extra)
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001196{
Yoann Padioleau6dbc9c82007-08-03 19:37:16 +02001197 ray_dev_t *local = netdev_priv(dev);
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001198
1199 /* Reject if card is already initialised */
John Daiker141fa612009-03-10 06:59:54 -07001200 if (local->card_status != CARD_AWAITING_PARAM)
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001201 return -EBUSY;
1202
1203 /* Check if rate is in range */
Joe Perches43ead782010-03-18 18:29:40 -07001204 if ((wrqu->bitrate.value != 1000000) && (wrqu->bitrate.value != 2000000))
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001205 return -EINVAL;
1206
1207 /* Hack for 1.5 Mb/s instead of 2 Mb/s */
John Daiker141fa612009-03-10 06:59:54 -07001208 if ((local->fw_ver == 0x55) && /* Please check */
Joe Perches43ead782010-03-18 18:29:40 -07001209 (wrqu->bitrate.value == 2000000))
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001210 local->net_default_tx_rate = 3;
1211 else
Joe Perches43ead782010-03-18 18:29:40 -07001212 local->net_default_tx_rate = wrqu->bitrate.value / 500000;
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001213
1214 return 0;
1215}
1216
1217/*------------------------------------------------------------------*/
1218/*
1219 * Wireless Handler : get Bit-Rate
1220 */
Joe Perches43ead782010-03-18 18:29:40 -07001221static int ray_get_rate(struct net_device *dev, struct iw_request_info *info,
1222 union iwreq_data *wrqu, char *extra)
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001223{
Yoann Padioleau6dbc9c82007-08-03 19:37:16 +02001224 ray_dev_t *local = netdev_priv(dev);
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001225
John Daiker141fa612009-03-10 06:59:54 -07001226 if (local->net_default_tx_rate == 3)
Joe Perches43ead782010-03-18 18:29:40 -07001227 wrqu->bitrate.value = 2000000; /* Hum... */
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001228 else
Joe Perches43ead782010-03-18 18:29:40 -07001229 wrqu->bitrate.value = local->net_default_tx_rate * 500000;
1230 wrqu->bitrate.fixed = 0; /* We are in auto mode */
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001231
1232 return 0;
1233}
1234
1235/*------------------------------------------------------------------*/
1236/*
1237 * Wireless Handler : set RTS threshold
1238 */
Joe Perches43ead782010-03-18 18:29:40 -07001239static int ray_set_rts(struct net_device *dev, struct iw_request_info *info,
1240 union iwreq_data *wrqu, char *extra)
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001241{
Yoann Padioleau6dbc9c82007-08-03 19:37:16 +02001242 ray_dev_t *local = netdev_priv(dev);
Joe Perches43ead782010-03-18 18:29:40 -07001243 int rthr = wrqu->rts.value;
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001244
1245 /* Reject if card is already initialised */
John Daiker141fa612009-03-10 06:59:54 -07001246 if (local->card_status != CARD_AWAITING_PARAM)
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001247 return -EBUSY;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001248
1249 /* if(wrq->u.rts.fixed == 0) we should complain */
Joe Perches43ead782010-03-18 18:29:40 -07001250 if (wrqu->rts.disabled)
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001251 rthr = 32767;
1252 else {
John Daiker141fa612009-03-10 06:59:54 -07001253 if ((rthr < 0) || (rthr > 2347)) /* What's the max packet size ??? */
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001254 return -EINVAL;
1255 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001256 local->sparm.b5.a_rts_threshold[0] = (rthr >> 8) & 0xFF;
1257 local->sparm.b5.a_rts_threshold[1] = rthr & 0xFF;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001258
John Daiker141fa612009-03-10 06:59:54 -07001259 return -EINPROGRESS; /* Call commit handler */
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001260}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001261
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001262/*------------------------------------------------------------------*/
1263/*
1264 * Wireless Handler : get RTS threshold
1265 */
Joe Perches43ead782010-03-18 18:29:40 -07001266static int ray_get_rts(struct net_device *dev, struct iw_request_info *info,
1267 union iwreq_data *wrqu, char *extra)
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001268{
Yoann Padioleau6dbc9c82007-08-03 19:37:16 +02001269 ray_dev_t *local = netdev_priv(dev);
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001270
Joe Perches43ead782010-03-18 18:29:40 -07001271 wrqu->rts.value = (local->sparm.b5.a_rts_threshold[0] << 8)
John Daiker141fa612009-03-10 06:59:54 -07001272 + local->sparm.b5.a_rts_threshold[1];
Joe Perches43ead782010-03-18 18:29:40 -07001273 wrqu->rts.disabled = (wrqu->rts.value == 32767);
1274 wrqu->rts.fixed = 1;
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001275
1276 return 0;
1277}
1278
1279/*------------------------------------------------------------------*/
1280/*
1281 * Wireless Handler : set Fragmentation threshold
1282 */
Joe Perches43ead782010-03-18 18:29:40 -07001283static int ray_set_frag(struct net_device *dev, struct iw_request_info *info,
1284 union iwreq_data *wrqu, char *extra)
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001285{
Yoann Padioleau6dbc9c82007-08-03 19:37:16 +02001286 ray_dev_t *local = netdev_priv(dev);
Joe Perches43ead782010-03-18 18:29:40 -07001287 int fthr = wrqu->frag.value;
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001288
1289 /* Reject if card is already initialised */
John Daiker141fa612009-03-10 06:59:54 -07001290 if (local->card_status != CARD_AWAITING_PARAM)
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001291 return -EBUSY;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001292
1293 /* if(wrq->u.frag.fixed == 0) should complain */
Joe Perches43ead782010-03-18 18:29:40 -07001294 if (wrqu->frag.disabled)
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001295 fthr = 32767;
1296 else {
John Daiker141fa612009-03-10 06:59:54 -07001297 if ((fthr < 256) || (fthr > 2347)) /* To check out ! */
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001298 return -EINVAL;
1299 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001300 local->sparm.b5.a_frag_threshold[0] = (fthr >> 8) & 0xFF;
1301 local->sparm.b5.a_frag_threshold[1] = fthr & 0xFF;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001302
John Daiker141fa612009-03-10 06:59:54 -07001303 return -EINPROGRESS; /* Call commit handler */
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001304}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001305
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001306/*------------------------------------------------------------------*/
1307/*
1308 * Wireless Handler : get Fragmentation threshold
1309 */
Joe Perches43ead782010-03-18 18:29:40 -07001310static int ray_get_frag(struct net_device *dev, struct iw_request_info *info,
1311 union iwreq_data *wrqu, char *extra)
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001312{
Yoann Padioleau6dbc9c82007-08-03 19:37:16 +02001313 ray_dev_t *local = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001314
Joe Perches43ead782010-03-18 18:29:40 -07001315 wrqu->frag.value = (local->sparm.b5.a_frag_threshold[0] << 8)
John Daiker141fa612009-03-10 06:59:54 -07001316 + local->sparm.b5.a_frag_threshold[1];
Joe Perches43ead782010-03-18 18:29:40 -07001317 wrqu->frag.disabled = (wrqu->frag.value == 32767);
1318 wrqu->frag.fixed = 1;
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001319
1320 return 0;
1321}
1322
1323/*------------------------------------------------------------------*/
1324/*
1325 * Wireless Handler : set Mode of Operation
1326 */
Joe Perches43ead782010-03-18 18:29:40 -07001327static int ray_set_mode(struct net_device *dev, struct iw_request_info *info,
1328 union iwreq_data *wrqu, char *extra)
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001329{
Yoann Padioleau6dbc9c82007-08-03 19:37:16 +02001330 ray_dev_t *local = netdev_priv(dev);
John Daiker141fa612009-03-10 06:59:54 -07001331 int err = -EINPROGRESS; /* Call commit handler */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001332 char card_mode = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001333
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001334 /* Reject if card is already initialised */
John Daiker141fa612009-03-10 06:59:54 -07001335 if (local->card_status != CARD_AWAITING_PARAM)
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001336 return -EBUSY;
1337
Joe Perches43ead782010-03-18 18:29:40 -07001338 switch (wrqu->mode) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001339 case IW_MODE_ADHOC:
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001340 card_mode = 0;
John Daiker141fa612009-03-10 06:59:54 -07001341 /* Fall through */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001342 case IW_MODE_INFRA:
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001343 local->sparm.b5.a_network_type = card_mode;
1344 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001345 default:
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001346 err = -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001347 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001348
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001349 return err;
1350}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001351
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001352/*------------------------------------------------------------------*/
1353/*
1354 * Wireless Handler : get Mode of Operation
1355 */
Joe Perches43ead782010-03-18 18:29:40 -07001356static int ray_get_mode(struct net_device *dev, struct iw_request_info *info,
1357 union iwreq_data *wrqu, char *extra)
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001358{
Yoann Padioleau6dbc9c82007-08-03 19:37:16 +02001359 ray_dev_t *local = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001360
John Daiker141fa612009-03-10 06:59:54 -07001361 if (local->sparm.b5.a_network_type)
Joe Perches43ead782010-03-18 18:29:40 -07001362 wrqu->mode = IW_MODE_INFRA;
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001363 else
Joe Perches43ead782010-03-18 18:29:40 -07001364 wrqu->mode = IW_MODE_ADHOC;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001365
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001366 return 0;
1367}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001368
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001369/*------------------------------------------------------------------*/
1370/*
1371 * Wireless Handler : get range info
1372 */
Joe Perches43ead782010-03-18 18:29:40 -07001373static int ray_get_range(struct net_device *dev, struct iw_request_info *info,
1374 union iwreq_data *wrqu, char *extra)
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001375{
John Daiker141fa612009-03-10 06:59:54 -07001376 struct iw_range *range = (struct iw_range *)extra;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001377
Joe Perches43ead782010-03-18 18:29:40 -07001378 memset(range, 0, sizeof(struct iw_range));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001379
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001380 /* Set the length (very important for backward compatibility) */
Joe Perches43ead782010-03-18 18:29:40 -07001381 wrqu->data.length = sizeof(struct iw_range);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001382
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001383 /* Set the Wireless Extension versions */
1384 range->we_version_compiled = WIRELESS_EXT;
1385 range->we_version_source = 9;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001386
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001387 /* Set information in the range struct */
1388 range->throughput = 1.1 * 1000 * 1000; /* Put the right number here */
John Daiker141fa612009-03-10 06:59:54 -07001389 range->num_channels = hop_pattern_length[(int)country];
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001390 range->num_frequency = 0;
1391 range->max_qual.qual = 0;
1392 range->max_qual.level = 255; /* What's the correct value ? */
1393 range->max_qual.noise = 255; /* Idem */
1394 range->num_bitrates = 2;
1395 range->bitrate[0] = 1000000; /* 1 Mb/s */
1396 range->bitrate[1] = 2000000; /* 2 Mb/s */
1397 return 0;
1398}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001399
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001400/*------------------------------------------------------------------*/
1401/*
1402 * Wireless Private Handler : set framing mode
1403 */
Joe Perches43ead782010-03-18 18:29:40 -07001404static int ray_set_framing(struct net_device *dev, struct iw_request_info *info,
John Daiker141fa612009-03-10 06:59:54 -07001405 union iwreq_data *wrqu, char *extra)
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001406{
1407 translate = *(extra); /* Set framing mode */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001408
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001409 return 0;
1410}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001411
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001412/*------------------------------------------------------------------*/
1413/*
1414 * Wireless Private Handler : get framing mode
1415 */
Joe Perches43ead782010-03-18 18:29:40 -07001416static int ray_get_framing(struct net_device *dev, struct iw_request_info *info,
John Daiker141fa612009-03-10 06:59:54 -07001417 union iwreq_data *wrqu, char *extra)
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001418{
1419 *(extra) = translate;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001420
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001421 return 0;
1422}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001423
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001424/*------------------------------------------------------------------*/
1425/*
1426 * Wireless Private Handler : get country
1427 */
Joe Perches43ead782010-03-18 18:29:40 -07001428static int ray_get_country(struct net_device *dev, struct iw_request_info *info,
John Daiker141fa612009-03-10 06:59:54 -07001429 union iwreq_data *wrqu, char *extra)
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001430{
1431 *(extra) = country;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001432
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001433 return 0;
1434}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001435
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001436/*------------------------------------------------------------------*/
1437/*
1438 * Commit handler : called after a bunch of SET operations
1439 */
Joe Perches43ead782010-03-18 18:29:40 -07001440static int ray_commit(struct net_device *dev, struct iw_request_info *info,
1441 union iwreq_data *wrqu, char *extra)
1442{
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001443 return 0;
1444}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001445
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001446/*------------------------------------------------------------------*/
1447/*
1448 * Stats handler : return Wireless Stats
1449 */
John Daiker141fa612009-03-10 06:59:54 -07001450static iw_stats *ray_get_wireless_stats(struct net_device *dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001451{
John Daiker141fa612009-03-10 06:59:54 -07001452 ray_dev_t *local = netdev_priv(dev);
1453 struct pcmcia_device *link = local->finder;
1454 struct status __iomem *p = local->sram + STATUS_BASE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001455
John Daiker141fa612009-03-10 06:59:54 -07001456 local->wstats.status = local->card_status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001457#ifdef WIRELESS_SPY
John Daiker141fa612009-03-10 06:59:54 -07001458 if ((local->spy_data.spy_number > 0)
1459 && (local->sparm.b5.a_network_type == 0)) {
1460 /* Get it from the first node in spy list */
1461 local->wstats.qual.qual = local->spy_data.spy_stat[0].qual;
1462 local->wstats.qual.level = local->spy_data.spy_stat[0].level;
1463 local->wstats.qual.noise = local->spy_data.spy_stat[0].noise;
1464 local->wstats.qual.updated =
1465 local->spy_data.spy_stat[0].updated;
1466 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001467#endif /* WIRELESS_SPY */
1468
John Daiker141fa612009-03-10 06:59:54 -07001469 if (pcmcia_dev_present(link)) {
1470 local->wstats.qual.noise = readb(&p->rxnoise);
1471 local->wstats.qual.updated |= 4;
1472 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001473
John Daiker141fa612009-03-10 06:59:54 -07001474 return &local->wstats;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001475} /* end ray_get_wireless_stats */
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001476
1477/*------------------------------------------------------------------*/
1478/*
1479 * Structures to export the Wireless Handlers
1480 */
1481
John Daiker141fa612009-03-10 06:59:54 -07001482static const iw_handler ray_handler[] = {
Joe Perches43ead782010-03-18 18:29:40 -07001483 IW_HANDLER(SIOCSIWCOMMIT, ray_commit),
1484 IW_HANDLER(SIOCGIWNAME, ray_get_name),
1485 IW_HANDLER(SIOCSIWFREQ, ray_set_freq),
1486 IW_HANDLER(SIOCGIWFREQ, ray_get_freq),
1487 IW_HANDLER(SIOCSIWMODE, ray_set_mode),
1488 IW_HANDLER(SIOCGIWMODE, ray_get_mode),
1489 IW_HANDLER(SIOCGIWRANGE, ray_get_range),
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001490#ifdef WIRELESS_SPY
Joe Perches270020e2010-03-18 18:29:37 -07001491 IW_HANDLER(SIOCSIWSPY, iw_handler_set_spy),
1492 IW_HANDLER(SIOCGIWSPY, iw_handler_get_spy),
1493 IW_HANDLER(SIOCSIWTHRSPY, iw_handler_set_thrspy),
1494 IW_HANDLER(SIOCGIWTHRSPY, iw_handler_get_thrspy),
John Daiker141fa612009-03-10 06:59:54 -07001495#endif /* WIRELESS_SPY */
Joe Perches43ead782010-03-18 18:29:40 -07001496 IW_HANDLER(SIOCGIWAP, ray_get_wap),
1497 IW_HANDLER(SIOCSIWESSID, ray_set_essid),
1498 IW_HANDLER(SIOCGIWESSID, ray_get_essid),
1499 IW_HANDLER(SIOCSIWRATE, ray_set_rate),
1500 IW_HANDLER(SIOCGIWRATE, ray_get_rate),
1501 IW_HANDLER(SIOCSIWRTS, ray_set_rts),
1502 IW_HANDLER(SIOCGIWRTS, ray_get_rts),
1503 IW_HANDLER(SIOCSIWFRAG, ray_set_frag),
1504 IW_HANDLER(SIOCGIWFRAG, ray_get_frag),
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001505};
1506
John Daiker141fa612009-03-10 06:59:54 -07001507#define SIOCSIPFRAMING SIOCIWFIRSTPRIV /* Set framing mode */
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001508#define SIOCGIPFRAMING SIOCIWFIRSTPRIV + 1 /* Get framing mode */
1509#define SIOCGIPCOUNTRY SIOCIWFIRSTPRIV + 3 /* Get country code */
1510
John Daiker141fa612009-03-10 06:59:54 -07001511static const iw_handler ray_private_handler[] = {
Joe Perches43ead782010-03-18 18:29:40 -07001512 [0] = ray_set_framing,
1513 [1] = ray_get_framing,
1514 [3] = ray_get_country,
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001515};
1516
John Daiker141fa612009-03-10 06:59:54 -07001517static const struct iw_priv_args ray_private_args[] = {
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001518/* cmd, set_args, get_args, name */
John Daiker141fa612009-03-10 06:59:54 -07001519 {SIOCSIPFRAMING, IW_PRIV_TYPE_BYTE | IW_PRIV_SIZE_FIXED | 1, 0,
1520 "set_framing"},
1521 {SIOCGIPFRAMING, 0, IW_PRIV_TYPE_BYTE | IW_PRIV_SIZE_FIXED | 1,
1522 "get_framing"},
1523 {SIOCGIPCOUNTRY, 0, IW_PRIV_TYPE_BYTE | IW_PRIV_SIZE_FIXED | 1,
1524 "get_country"},
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001525};
1526
John Daiker141fa612009-03-10 06:59:54 -07001527static const struct iw_handler_def ray_handler_def = {
1528 .num_standard = ARRAY_SIZE(ray_handler),
1529 .num_private = ARRAY_SIZE(ray_private_handler),
Denis Chengff8ac602007-09-02 18:30:18 +08001530 .num_private_args = ARRAY_SIZE(ray_private_args),
John Daiker141fa612009-03-10 06:59:54 -07001531 .standard = ray_handler,
1532 .private = ray_private_handler,
1533 .private_args = ray_private_args,
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001534 .get_wireless_stats = ray_get_wireless_stats,
1535};
1536
Linus Torvalds1da177e2005-04-16 15:20:36 -07001537/*===========================================================================*/
1538static int ray_open(struct net_device *dev)
1539{
John Daiker141fa612009-03-10 06:59:54 -07001540 ray_dev_t *local = netdev_priv(dev);
1541 struct pcmcia_device *link;
1542 link = local->finder;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001543
Dominik Brodowski624dd662009-10-24 15:52:44 +02001544 dev_dbg(&link->dev, "ray_open('%s')\n", dev->name);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001545
John Daiker141fa612009-03-10 06:59:54 -07001546 if (link->open == 0)
1547 local->num_multi = 0;
1548 link->open++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001549
John Daiker141fa612009-03-10 06:59:54 -07001550 /* If the card is not started, time to start it ! - Jean II */
1551 if (local->card_status == CARD_AWAITING_PARAM) {
1552 int i;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001553
Dominik Brodowski624dd662009-10-24 15:52:44 +02001554 dev_dbg(&link->dev, "ray_open: doing init now !\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001555
John Daiker141fa612009-03-10 06:59:54 -07001556 /* Download startup parameters */
1557 if ((i = dl_startup_params(dev)) < 0) {
1558 printk(KERN_INFO
1559 "ray_dev_init dl_startup_params failed - "
1560 "returns 0x%x\n", i);
1561 return -1;
1562 }
1563 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001564
John Daiker141fa612009-03-10 06:59:54 -07001565 if (sniffer)
1566 netif_stop_queue(dev);
1567 else
1568 netif_start_queue(dev);
1569
Dominik Brodowski624dd662009-10-24 15:52:44 +02001570 dev_dbg(&link->dev, "ray_open ending\n");
John Daiker141fa612009-03-10 06:59:54 -07001571 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001572} /* end ray_open */
John Daiker141fa612009-03-10 06:59:54 -07001573
Linus Torvalds1da177e2005-04-16 15:20:36 -07001574/*===========================================================================*/
1575static int ray_dev_close(struct net_device *dev)
1576{
John Daiker141fa612009-03-10 06:59:54 -07001577 ray_dev_t *local = netdev_priv(dev);
1578 struct pcmcia_device *link;
1579 link = local->finder;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001580
Dominik Brodowski624dd662009-10-24 15:52:44 +02001581 dev_dbg(&link->dev, "ray_dev_close('%s')\n", dev->name);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001582
John Daiker141fa612009-03-10 06:59:54 -07001583 link->open--;
1584 netif_stop_queue(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001585
John Daiker141fa612009-03-10 06:59:54 -07001586 /* In here, we should stop the hardware (stop card from beeing active)
1587 * and set local->card_status to CARD_AWAITING_PARAM, so that while the
1588 * card is closed we can chage its configuration.
1589 * Probably also need a COR reset to get sane state - Jean II */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001590
John Daiker141fa612009-03-10 06:59:54 -07001591 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001592} /* end ray_dev_close */
John Daiker141fa612009-03-10 06:59:54 -07001593
Linus Torvalds1da177e2005-04-16 15:20:36 -07001594/*===========================================================================*/
John Daiker141fa612009-03-10 06:59:54 -07001595static void ray_reset(struct net_device *dev)
1596{
Dominik Brodowski624dd662009-10-24 15:52:44 +02001597 pr_debug("ray_reset entered\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001598}
John Daiker141fa612009-03-10 06:59:54 -07001599
Linus Torvalds1da177e2005-04-16 15:20:36 -07001600/*===========================================================================*/
1601/* Cause a firmware interrupt if it is ready for one */
1602/* Return nonzero if not ready */
1603static int interrupt_ecf(ray_dev_t *local, int ccs)
1604{
John Daiker141fa612009-03-10 06:59:54 -07001605 int i = 50;
1606 struct pcmcia_device *link = local->finder;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001607
John Daiker141fa612009-03-10 06:59:54 -07001608 if (!(pcmcia_dev_present(link))) {
Dominik Brodowski624dd662009-10-24 15:52:44 +02001609 dev_dbg(&link->dev, "ray_cs interrupt_ecf - device not present\n");
John Daiker141fa612009-03-10 06:59:54 -07001610 return -1;
1611 }
Dominik Brodowski624dd662009-10-24 15:52:44 +02001612 dev_dbg(&link->dev, "interrupt_ecf(local=%p, ccs = 0x%x\n", local, ccs);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001613
John Daiker141fa612009-03-10 06:59:54 -07001614 while (i &&
1615 (readb(local->amem + CIS_OFFSET + ECF_INTR_OFFSET) &
1616 ECF_INTR_SET))
1617 i--;
1618 if (i == 0) {
Dominik Brodowski624dd662009-10-24 15:52:44 +02001619 dev_dbg(&link->dev, "ray_cs interrupt_ecf card not ready for interrupt\n");
John Daiker141fa612009-03-10 06:59:54 -07001620 return -1;
1621 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001622 /* Fill the mailbox, then kick the card */
John Daiker141fa612009-03-10 06:59:54 -07001623 writeb(ccs, local->sram + SCB_BASE);
1624 writeb(ECF_INTR_SET, local->amem + CIS_OFFSET + ECF_INTR_OFFSET);
1625 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001626} /* interrupt_ecf */
John Daiker141fa612009-03-10 06:59:54 -07001627
Linus Torvalds1da177e2005-04-16 15:20:36 -07001628/*===========================================================================*/
1629/* Get next free transmit CCS */
1630/* Return - index of current tx ccs */
1631static int get_free_tx_ccs(ray_dev_t *local)
1632{
John Daiker141fa612009-03-10 06:59:54 -07001633 int i;
1634 struct ccs __iomem *pccs = ccs_base(local);
1635 struct pcmcia_device *link = local->finder;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001636
John Daiker141fa612009-03-10 06:59:54 -07001637 if (!(pcmcia_dev_present(link))) {
Dominik Brodowski624dd662009-10-24 15:52:44 +02001638 dev_dbg(&link->dev, "ray_cs get_free_tx_ccs - device not present\n");
John Daiker141fa612009-03-10 06:59:54 -07001639 return ECARDGONE;
1640 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001641
John Daiker141fa612009-03-10 06:59:54 -07001642 if (test_and_set_bit(0, &local->tx_ccs_lock)) {
Dominik Brodowski624dd662009-10-24 15:52:44 +02001643 dev_dbg(&link->dev, "ray_cs tx_ccs_lock busy\n");
John Daiker141fa612009-03-10 06:59:54 -07001644 return ECCSBUSY;
1645 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001646
John Daiker141fa612009-03-10 06:59:54 -07001647 for (i = 0; i < NUMBER_OF_TX_CCS; i++) {
1648 if (readb(&(pccs + i)->buffer_status) == CCS_BUFFER_FREE) {
1649 writeb(CCS_BUFFER_BUSY, &(pccs + i)->buffer_status);
1650 writeb(CCS_END_LIST, &(pccs + i)->link);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001651 local->tx_ccs_lock = 0;
John Daiker141fa612009-03-10 06:59:54 -07001652 return i;
1653 }
1654 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001655 local->tx_ccs_lock = 0;
Dominik Brodowski624dd662009-10-24 15:52:44 +02001656 dev_dbg(&link->dev, "ray_cs ERROR no free tx CCS for raylink card\n");
John Daiker141fa612009-03-10 06:59:54 -07001657 return ECCSFULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001658} /* get_free_tx_ccs */
John Daiker141fa612009-03-10 06:59:54 -07001659
Linus Torvalds1da177e2005-04-16 15:20:36 -07001660/*===========================================================================*/
1661/* Get next free CCS */
1662/* Return - index of current ccs */
1663static int get_free_ccs(ray_dev_t *local)
1664{
John Daiker141fa612009-03-10 06:59:54 -07001665 int i;
1666 struct ccs __iomem *pccs = ccs_base(local);
1667 struct pcmcia_device *link = local->finder;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001668
John Daiker141fa612009-03-10 06:59:54 -07001669 if (!(pcmcia_dev_present(link))) {
Dominik Brodowski624dd662009-10-24 15:52:44 +02001670 dev_dbg(&link->dev, "ray_cs get_free_ccs - device not present\n");
John Daiker141fa612009-03-10 06:59:54 -07001671 return ECARDGONE;
1672 }
1673 if (test_and_set_bit(0, &local->ccs_lock)) {
Dominik Brodowski624dd662009-10-24 15:52:44 +02001674 dev_dbg(&link->dev, "ray_cs ccs_lock busy\n");
John Daiker141fa612009-03-10 06:59:54 -07001675 return ECCSBUSY;
1676 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001677
John Daiker141fa612009-03-10 06:59:54 -07001678 for (i = NUMBER_OF_TX_CCS; i < NUMBER_OF_CCS; i++) {
1679 if (readb(&(pccs + i)->buffer_status) == CCS_BUFFER_FREE) {
1680 writeb(CCS_BUFFER_BUSY, &(pccs + i)->buffer_status);
1681 writeb(CCS_END_LIST, &(pccs + i)->link);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001682 local->ccs_lock = 0;
John Daiker141fa612009-03-10 06:59:54 -07001683 return i;
1684 }
1685 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001686 local->ccs_lock = 0;
Dominik Brodowski624dd662009-10-24 15:52:44 +02001687 dev_dbg(&link->dev, "ray_cs ERROR no free CCS for raylink card\n");
John Daiker141fa612009-03-10 06:59:54 -07001688 return ECCSFULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001689} /* get_free_ccs */
John Daiker141fa612009-03-10 06:59:54 -07001690
Linus Torvalds1da177e2005-04-16 15:20:36 -07001691/*===========================================================================*/
1692static void authenticate_timeout(u_long data)
1693{
John Daiker141fa612009-03-10 06:59:54 -07001694 ray_dev_t *local = (ray_dev_t *) data;
1695 del_timer(&local->timer);
1696 printk(KERN_INFO "ray_cs Authentication with access point failed"
1697 " - timeout\n");
1698 join_net((u_long) local);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001699}
John Daiker141fa612009-03-10 06:59:54 -07001700
Linus Torvalds1da177e2005-04-16 15:20:36 -07001701/*===========================================================================*/
Linus Torvalds1da177e2005-04-16 15:20:36 -07001702static int parse_addr(char *in_str, UCHAR *out)
1703{
John Daiker141fa612009-03-10 06:59:54 -07001704 int len;
1705 int i, j, k;
1706 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001707
John Daiker141fa612009-03-10 06:59:54 -07001708 if (in_str == NULL)
1709 return 0;
1710 if ((len = strlen(in_str)) < 2)
1711 return 0;
1712 memset(out, 0, ADDRLEN);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001713
John Daiker141fa612009-03-10 06:59:54 -07001714 status = 1;
1715 j = len - 1;
1716 if (j > 12)
1717 j = 12;
1718 i = 5;
1719
1720 while (j > 0) {
Andy Shevchenko882d8292010-07-23 03:18:09 +00001721 if ((k = hex_to_bin(in_str[j--])) != -1)
John Daiker141fa612009-03-10 06:59:54 -07001722 out[i] = k;
1723 else
1724 return 0;
1725
1726 if (j == 0)
1727 break;
Andy Shevchenko882d8292010-07-23 03:18:09 +00001728 if ((k = hex_to_bin(in_str[j--])) != -1)
John Daiker141fa612009-03-10 06:59:54 -07001729 out[i] += k << 4;
1730 else
1731 return 0;
1732 if (!i--)
1733 break;
1734 }
1735 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001736}
John Daiker141fa612009-03-10 06:59:54 -07001737
Linus Torvalds1da177e2005-04-16 15:20:36 -07001738/*===========================================================================*/
1739static struct net_device_stats *ray_get_stats(struct net_device *dev)
1740{
John Daiker141fa612009-03-10 06:59:54 -07001741 ray_dev_t *local = netdev_priv(dev);
1742 struct pcmcia_device *link = local->finder;
1743 struct status __iomem *p = local->sram + STATUS_BASE;
1744 if (!(pcmcia_dev_present(link))) {
Dominik Brodowski624dd662009-10-24 15:52:44 +02001745 dev_dbg(&link->dev, "ray_cs net_device_stats - device not present\n");
John Daiker141fa612009-03-10 06:59:54 -07001746 return &local->stats;
1747 }
1748 if (readb(&p->mrx_overflow_for_host)) {
1749 local->stats.rx_over_errors += swab16(readw(&p->mrx_overflow));
1750 writeb(0, &p->mrx_overflow);
1751 writeb(0, &p->mrx_overflow_for_host);
1752 }
1753 if (readb(&p->mrx_checksum_error_for_host)) {
1754 local->stats.rx_crc_errors +=
1755 swab16(readw(&p->mrx_checksum_error));
1756 writeb(0, &p->mrx_checksum_error);
1757 writeb(0, &p->mrx_checksum_error_for_host);
1758 }
1759 if (readb(&p->rx_hec_error_for_host)) {
1760 local->stats.rx_frame_errors += swab16(readw(&p->rx_hec_error));
1761 writeb(0, &p->rx_hec_error);
1762 writeb(0, &p->rx_hec_error_for_host);
1763 }
1764 return &local->stats;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001765}
John Daiker141fa612009-03-10 06:59:54 -07001766
Linus Torvalds1da177e2005-04-16 15:20:36 -07001767/*===========================================================================*/
John Daiker141fa612009-03-10 06:59:54 -07001768static void ray_update_parm(struct net_device *dev, UCHAR objid, UCHAR *value,
1769 int len)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001770{
John Daiker141fa612009-03-10 06:59:54 -07001771 ray_dev_t *local = netdev_priv(dev);
1772 struct pcmcia_device *link = local->finder;
1773 int ccsindex;
1774 int i;
1775 struct ccs __iomem *pccs;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001776
John Daiker141fa612009-03-10 06:59:54 -07001777 if (!(pcmcia_dev_present(link))) {
Dominik Brodowski624dd662009-10-24 15:52:44 +02001778 dev_dbg(&link->dev, "ray_update_parm - device not present\n");
John Daiker141fa612009-03-10 06:59:54 -07001779 return;
1780 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001781
John Daiker141fa612009-03-10 06:59:54 -07001782 if ((ccsindex = get_free_ccs(local)) < 0) {
Dominik Brodowski624dd662009-10-24 15:52:44 +02001783 dev_dbg(&link->dev, "ray_update_parm - No free ccs\n");
John Daiker141fa612009-03-10 06:59:54 -07001784 return;
1785 }
1786 pccs = ccs_base(local) + ccsindex;
1787 writeb(CCS_UPDATE_PARAMS, &pccs->cmd);
1788 writeb(objid, &pccs->var.update_param.object_id);
1789 writeb(1, &pccs->var.update_param.number_objects);
1790 writeb(0, &pccs->var.update_param.failure_cause);
1791 for (i = 0; i < len; i++) {
1792 writeb(value[i], local->sram + HOST_TO_ECF_BASE);
1793 }
1794 /* Interrupt the firmware to process the command */
1795 if (interrupt_ecf(local, ccsindex)) {
Dominik Brodowski624dd662009-10-24 15:52:44 +02001796 dev_dbg(&link->dev, "ray_cs associate failed - ECF not ready for intr\n");
John Daiker141fa612009-03-10 06:59:54 -07001797 writeb(CCS_BUFFER_FREE, &(pccs++)->buffer_status);
1798 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001799}
John Daiker141fa612009-03-10 06:59:54 -07001800
Linus Torvalds1da177e2005-04-16 15:20:36 -07001801/*===========================================================================*/
1802static void ray_update_multi_list(struct net_device *dev, int all)
1803{
John Daiker141fa612009-03-10 06:59:54 -07001804 int ccsindex;
1805 struct ccs __iomem *pccs;
John Daiker141fa612009-03-10 06:59:54 -07001806 ray_dev_t *local = netdev_priv(dev);
1807 struct pcmcia_device *link = local->finder;
1808 void __iomem *p = local->sram + HOST_TO_ECF_BASE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001809
John Daiker141fa612009-03-10 06:59:54 -07001810 if (!(pcmcia_dev_present(link))) {
Dominik Brodowski624dd662009-10-24 15:52:44 +02001811 dev_dbg(&link->dev, "ray_update_multi_list - device not present\n");
John Daiker141fa612009-03-10 06:59:54 -07001812 return;
1813 } else
Dominik Brodowski624dd662009-10-24 15:52:44 +02001814 dev_dbg(&link->dev, "ray_update_multi_list(%p)\n", dev);
John Daiker141fa612009-03-10 06:59:54 -07001815 if ((ccsindex = get_free_ccs(local)) < 0) {
Dominik Brodowski624dd662009-10-24 15:52:44 +02001816 dev_dbg(&link->dev, "ray_update_multi - No free ccs\n");
John Daiker141fa612009-03-10 06:59:54 -07001817 return;
1818 }
1819 pccs = ccs_base(local) + ccsindex;
1820 writeb(CCS_UPDATE_MULTICAST_LIST, &pccs->cmd);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001821
John Daiker141fa612009-03-10 06:59:54 -07001822 if (all) {
1823 writeb(0xff, &pccs->var);
1824 local->num_multi = 0xff;
1825 } else {
Jiri Pirko22bedad32010-04-01 21:22:57 +00001826 struct netdev_hw_addr *ha;
Jiri Pirko655ffee2010-02-27 07:35:45 +00001827 int i = 0;
1828
John Daiker141fa612009-03-10 06:59:54 -07001829 /* Copy the kernel's list of MC addresses to card */
Jiri Pirko22bedad32010-04-01 21:22:57 +00001830 netdev_for_each_mc_addr(ha, dev) {
1831 memcpy_toio(p, ha->addr, ETH_ALEN);
Dominik Brodowski624dd662009-10-24 15:52:44 +02001832 dev_dbg(&link->dev,
John Daiker141fa612009-03-10 06:59:54 -07001833 "ray_update_multi add addr %02x%02x%02x%02x%02x%02x\n",
Jiri Pirko22bedad32010-04-01 21:22:57 +00001834 ha->addr[0], ha->addr[1],
1835 ha->addr[2], ha->addr[3],
1836 ha->addr[4], ha->addr[5]);
John Daiker141fa612009-03-10 06:59:54 -07001837 p += ETH_ALEN;
1838 i++;
1839 }
1840 if (i > 256 / ADDRLEN)
1841 i = 256 / ADDRLEN;
1842 writeb((UCHAR) i, &pccs->var);
Dominik Brodowski624dd662009-10-24 15:52:44 +02001843 dev_dbg(&link->dev, "ray_cs update_multi %d addresses in list\n", i);
John Daiker141fa612009-03-10 06:59:54 -07001844 /* Interrupt the firmware to process the command */
1845 local->num_multi = i;
1846 }
1847 if (interrupt_ecf(local, ccsindex)) {
Dominik Brodowski624dd662009-10-24 15:52:44 +02001848 dev_dbg(&link->dev,
John Daiker141fa612009-03-10 06:59:54 -07001849 "ray_cs update_multi failed - ECF not ready for intr\n");
1850 writeb(CCS_BUFFER_FREE, &(pccs++)->buffer_status);
1851 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001852} /* end ray_update_multi_list */
John Daiker141fa612009-03-10 06:59:54 -07001853
Linus Torvalds1da177e2005-04-16 15:20:36 -07001854/*===========================================================================*/
1855static void set_multicast_list(struct net_device *dev)
1856{
John Daiker141fa612009-03-10 06:59:54 -07001857 ray_dev_t *local = netdev_priv(dev);
1858 UCHAR promisc;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001859
Dominik Brodowski624dd662009-10-24 15:52:44 +02001860 pr_debug("ray_cs set_multicast_list(%p)\n", dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001861
John Daiker141fa612009-03-10 06:59:54 -07001862 if (dev->flags & IFF_PROMISC) {
1863 if (local->sparm.b5.a_promiscuous_mode == 0) {
Dominik Brodowski624dd662009-10-24 15:52:44 +02001864 pr_debug("ray_cs set_multicast_list promisc on\n");
John Daiker141fa612009-03-10 06:59:54 -07001865 local->sparm.b5.a_promiscuous_mode = 1;
1866 promisc = 1;
1867 ray_update_parm(dev, OBJID_promiscuous_mode,
1868 &promisc, sizeof(promisc));
1869 }
1870 } else {
1871 if (local->sparm.b5.a_promiscuous_mode == 1) {
Dominik Brodowski624dd662009-10-24 15:52:44 +02001872 pr_debug("ray_cs set_multicast_list promisc off\n");
John Daiker141fa612009-03-10 06:59:54 -07001873 local->sparm.b5.a_promiscuous_mode = 0;
1874 promisc = 0;
1875 ray_update_parm(dev, OBJID_promiscuous_mode,
1876 &promisc, sizeof(promisc));
1877 }
1878 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001879
John Daiker141fa612009-03-10 06:59:54 -07001880 if (dev->flags & IFF_ALLMULTI)
1881 ray_update_multi_list(dev, 1);
1882 else {
Jiri Pirko4cd24ea2010-02-08 04:30:35 +00001883 if (local->num_multi != netdev_mc_count(dev))
John Daiker141fa612009-03-10 06:59:54 -07001884 ray_update_multi_list(dev, 0);
1885 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001886} /* end set_multicast_list */
John Daiker141fa612009-03-10 06:59:54 -07001887
Linus Torvalds1da177e2005-04-16 15:20:36 -07001888/*=============================================================================
1889 * All routines below here are run at interrupt time.
1890=============================================================================*/
David Howells7d12e782006-10-05 14:55:46 +01001891static irqreturn_t ray_interrupt(int irq, void *dev_id)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001892{
John Daiker141fa612009-03-10 06:59:54 -07001893 struct net_device *dev = (struct net_device *)dev_id;
1894 struct pcmcia_device *link;
1895 ray_dev_t *local;
1896 struct ccs __iomem *pccs;
1897 struct rcs __iomem *prcs;
1898 UCHAR rcsindex;
1899 UCHAR tmp;
1900 UCHAR cmd;
1901 UCHAR status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001902
John Daiker141fa612009-03-10 06:59:54 -07001903 if (dev == NULL) /* Note that we want interrupts with dev->start == 0 */
1904 return IRQ_NONE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001905
Dominik Brodowski624dd662009-10-24 15:52:44 +02001906 pr_debug("ray_cs: interrupt for *dev=%p\n", dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001907
John Daiker141fa612009-03-10 06:59:54 -07001908 local = netdev_priv(dev);
1909 link = (struct pcmcia_device *)local->finder;
1910 if (!pcmcia_dev_present(link)) {
Dominik Brodowski624dd662009-10-24 15:52:44 +02001911 pr_debug(
1912 "ray_cs interrupt from device not present or suspended.\n");
John Daiker141fa612009-03-10 06:59:54 -07001913 return IRQ_NONE;
1914 }
1915 rcsindex = readb(&((struct scb __iomem *)(local->sram))->rcs_index);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001916
John Daiker141fa612009-03-10 06:59:54 -07001917 if (rcsindex >= (NUMBER_OF_CCS + NUMBER_OF_RCS)) {
Dominik Brodowski624dd662009-10-24 15:52:44 +02001918 dev_dbg(&link->dev, "ray_cs interrupt bad rcsindex = 0x%x\n", rcsindex);
John Daiker141fa612009-03-10 06:59:54 -07001919 clear_interrupt(local);
1920 return IRQ_HANDLED;
1921 }
1922 if (rcsindex < NUMBER_OF_CCS) { /* If it's a returned CCS */
1923 pccs = ccs_base(local) + rcsindex;
1924 cmd = readb(&pccs->cmd);
1925 status = readb(&pccs->buffer_status);
1926 switch (cmd) {
1927 case CCS_DOWNLOAD_STARTUP_PARAMS: /* Happens in firmware someday */
1928 del_timer(&local->timer);
1929 if (status == CCS_COMMAND_COMPLETE) {
Dominik Brodowski624dd662009-10-24 15:52:44 +02001930 dev_dbg(&link->dev,
John Daiker141fa612009-03-10 06:59:54 -07001931 "ray_cs interrupt download_startup_parameters OK\n");
1932 } else {
Dominik Brodowski624dd662009-10-24 15:52:44 +02001933 dev_dbg(&link->dev,
John Daiker141fa612009-03-10 06:59:54 -07001934 "ray_cs interrupt download_startup_parameters fail\n");
1935 }
1936 break;
1937 case CCS_UPDATE_PARAMS:
Dominik Brodowski624dd662009-10-24 15:52:44 +02001938 dev_dbg(&link->dev, "ray_cs interrupt update params done\n");
John Daiker141fa612009-03-10 06:59:54 -07001939 if (status != CCS_COMMAND_COMPLETE) {
1940 tmp =
1941 readb(&pccs->var.update_param.
1942 failure_cause);
Dominik Brodowski624dd662009-10-24 15:52:44 +02001943 dev_dbg(&link->dev,
John Daiker141fa612009-03-10 06:59:54 -07001944 "ray_cs interrupt update params failed - reason %d\n",
1945 tmp);
1946 }
1947 break;
1948 case CCS_REPORT_PARAMS:
Dominik Brodowski624dd662009-10-24 15:52:44 +02001949 dev_dbg(&link->dev, "ray_cs interrupt report params done\n");
John Daiker141fa612009-03-10 06:59:54 -07001950 break;
1951 case CCS_UPDATE_MULTICAST_LIST: /* Note that this CCS isn't returned */
Dominik Brodowski624dd662009-10-24 15:52:44 +02001952 dev_dbg(&link->dev,
John Daiker141fa612009-03-10 06:59:54 -07001953 "ray_cs interrupt CCS Update Multicast List done\n");
1954 break;
1955 case CCS_UPDATE_POWER_SAVINGS_MODE:
Dominik Brodowski624dd662009-10-24 15:52:44 +02001956 dev_dbg(&link->dev,
John Daiker141fa612009-03-10 06:59:54 -07001957 "ray_cs interrupt update power save mode done\n");
1958 break;
1959 case CCS_START_NETWORK:
1960 case CCS_JOIN_NETWORK:
1961 if (status == CCS_COMMAND_COMPLETE) {
1962 if (readb
1963 (&pccs->var.start_network.net_initiated) ==
1964 1) {
Dominik Brodowski624dd662009-10-24 15:52:44 +02001965 dev_dbg(&link->dev,
John Daiker141fa612009-03-10 06:59:54 -07001966 "ray_cs interrupt network \"%s\" started\n",
1967 local->sparm.b4.a_current_ess_id);
1968 } else {
Dominik Brodowski624dd662009-10-24 15:52:44 +02001969 dev_dbg(&link->dev,
John Daiker141fa612009-03-10 06:59:54 -07001970 "ray_cs interrupt network \"%s\" joined\n",
1971 local->sparm.b4.a_current_ess_id);
1972 }
1973 memcpy_fromio(&local->bss_id,
1974 pccs->var.start_network.bssid,
1975 ADDRLEN);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001976
John Daiker141fa612009-03-10 06:59:54 -07001977 if (local->fw_ver == 0x55)
1978 local->net_default_tx_rate = 3;
1979 else
1980 local->net_default_tx_rate =
1981 readb(&pccs->var.start_network.
1982 net_default_tx_rate);
1983 local->encryption =
1984 readb(&pccs->var.start_network.encryption);
1985 if (!sniffer && (local->net_type == INFRA)
1986 && !(local->sparm.b4.a_acting_as_ap_status)) {
1987 authenticate(local);
1988 }
1989 local->card_status = CARD_ACQ_COMPLETE;
1990 } else {
1991 local->card_status = CARD_ACQ_FAILED;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001992
John Daiker141fa612009-03-10 06:59:54 -07001993 del_timer(&local->timer);
1994 local->timer.expires = jiffies + HZ * 5;
1995 local->timer.data = (long)local;
1996 if (status == CCS_START_NETWORK) {
Dominik Brodowski624dd662009-10-24 15:52:44 +02001997 dev_dbg(&link->dev,
John Daiker141fa612009-03-10 06:59:54 -07001998 "ray_cs interrupt network \"%s\" start failed\n",
1999 local->sparm.b4.a_current_ess_id);
2000 local->timer.function = &start_net;
2001 } else {
Dominik Brodowski624dd662009-10-24 15:52:44 +02002002 dev_dbg(&link->dev,
John Daiker141fa612009-03-10 06:59:54 -07002003 "ray_cs interrupt network \"%s\" join failed\n",
2004 local->sparm.b4.a_current_ess_id);
2005 local->timer.function = &join_net;
2006 }
2007 add_timer(&local->timer);
2008 }
2009 break;
2010 case CCS_START_ASSOCIATION:
2011 if (status == CCS_COMMAND_COMPLETE) {
2012 local->card_status = CARD_ASSOC_COMPLETE;
Dominik Brodowski624dd662009-10-24 15:52:44 +02002013 dev_dbg(&link->dev, "ray_cs association successful\n");
John Daiker141fa612009-03-10 06:59:54 -07002014 } else {
Dominik Brodowski624dd662009-10-24 15:52:44 +02002015 dev_dbg(&link->dev, "ray_cs association failed,\n");
John Daiker141fa612009-03-10 06:59:54 -07002016 local->card_status = CARD_ASSOC_FAILED;
2017 join_net((u_long) local);
2018 }
2019 break;
2020 case CCS_TX_REQUEST:
2021 if (status == CCS_COMMAND_COMPLETE) {
Dominik Brodowski624dd662009-10-24 15:52:44 +02002022 dev_dbg(&link->dev,
John Daiker141fa612009-03-10 06:59:54 -07002023 "ray_cs interrupt tx request complete\n");
2024 } else {
Dominik Brodowski624dd662009-10-24 15:52:44 +02002025 dev_dbg(&link->dev,
John Daiker141fa612009-03-10 06:59:54 -07002026 "ray_cs interrupt tx request failed\n");
2027 }
2028 if (!sniffer)
2029 netif_start_queue(dev);
2030 netif_wake_queue(dev);
2031 break;
2032 case CCS_TEST_MEMORY:
Dominik Brodowski624dd662009-10-24 15:52:44 +02002033 dev_dbg(&link->dev, "ray_cs interrupt mem test done\n");
John Daiker141fa612009-03-10 06:59:54 -07002034 break;
2035 case CCS_SHUTDOWN:
Dominik Brodowski624dd662009-10-24 15:52:44 +02002036 dev_dbg(&link->dev,
John Daiker141fa612009-03-10 06:59:54 -07002037 "ray_cs interrupt Unexpected CCS returned - Shutdown\n");
2038 break;
2039 case CCS_DUMP_MEMORY:
Dominik Brodowski624dd662009-10-24 15:52:44 +02002040 dev_dbg(&link->dev, "ray_cs interrupt dump memory done\n");
John Daiker141fa612009-03-10 06:59:54 -07002041 break;
2042 case CCS_START_TIMER:
Dominik Brodowski624dd662009-10-24 15:52:44 +02002043 dev_dbg(&link->dev,
John Daiker141fa612009-03-10 06:59:54 -07002044 "ray_cs interrupt DING - raylink timer expired\n");
2045 break;
2046 default:
Dominik Brodowski624dd662009-10-24 15:52:44 +02002047 dev_dbg(&link->dev,
John Daiker141fa612009-03-10 06:59:54 -07002048 "ray_cs interrupt Unexpected CCS 0x%x returned 0x%x\n",
2049 rcsindex, cmd);
2050 }
2051 writeb(CCS_BUFFER_FREE, &pccs->buffer_status);
2052 } else { /* It's an RCS */
2053
2054 prcs = rcs_base(local) + rcsindex;
2055
2056 switch (readb(&prcs->interrupt_id)) {
2057 case PROCESS_RX_PACKET:
2058 ray_rx(dev, local, prcs);
2059 break;
2060 case REJOIN_NET_COMPLETE:
Dominik Brodowski624dd662009-10-24 15:52:44 +02002061 dev_dbg(&link->dev, "ray_cs interrupt rejoin net complete\n");
John Daiker141fa612009-03-10 06:59:54 -07002062 local->card_status = CARD_ACQ_COMPLETE;
2063 /* do we need to clear tx buffers CCS's? */
2064 if (local->sparm.b4.a_network_type == ADHOC) {
2065 if (!sniffer)
2066 netif_start_queue(dev);
2067 } else {
2068 memcpy_fromio(&local->bss_id,
2069 prcs->var.rejoin_net_complete.
2070 bssid, ADDRLEN);
Dominik Brodowski624dd662009-10-24 15:52:44 +02002071 dev_dbg(&link->dev,
John Daiker141fa612009-03-10 06:59:54 -07002072 "ray_cs new BSSID = %02x%02x%02x%02x%02x%02x\n",
2073 local->bss_id[0], local->bss_id[1],
2074 local->bss_id[2], local->bss_id[3],
2075 local->bss_id[4], local->bss_id[5]);
2076 if (!sniffer)
2077 authenticate(local);
2078 }
2079 break;
2080 case ROAMING_INITIATED:
Dominik Brodowski624dd662009-10-24 15:52:44 +02002081 dev_dbg(&link->dev, "ray_cs interrupt roaming initiated\n");
John Daiker141fa612009-03-10 06:59:54 -07002082 netif_stop_queue(dev);
2083 local->card_status = CARD_DOING_ACQ;
2084 break;
2085 case JAPAN_CALL_SIGN_RXD:
Dominik Brodowski624dd662009-10-24 15:52:44 +02002086 dev_dbg(&link->dev, "ray_cs interrupt japan call sign rx\n");
John Daiker141fa612009-03-10 06:59:54 -07002087 break;
2088 default:
Dominik Brodowski624dd662009-10-24 15:52:44 +02002089 dev_dbg(&link->dev,
John Daiker141fa612009-03-10 06:59:54 -07002090 "ray_cs Unexpected interrupt for RCS 0x%x cmd = 0x%x\n",
2091 rcsindex,
2092 (unsigned int)readb(&prcs->interrupt_id));
2093 break;
2094 }
2095 writeb(CCS_BUFFER_FREE, &prcs->buffer_status);
2096 }
2097 clear_interrupt(local);
2098 return IRQ_HANDLED;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002099} /* ray_interrupt */
John Daiker141fa612009-03-10 06:59:54 -07002100
Linus Torvalds1da177e2005-04-16 15:20:36 -07002101/*===========================================================================*/
John Daiker141fa612009-03-10 06:59:54 -07002102static void ray_rx(struct net_device *dev, ray_dev_t *local,
2103 struct rcs __iomem *prcs)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002104{
John Daiker141fa612009-03-10 06:59:54 -07002105 int rx_len;
2106 unsigned int pkt_addr;
2107 void __iomem *pmsg;
Dominik Brodowski624dd662009-10-24 15:52:44 +02002108 pr_debug("ray_rx process rx packet\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002109
John Daiker141fa612009-03-10 06:59:54 -07002110 /* Calculate address of packet within Rx buffer */
2111 pkt_addr = ((readb(&prcs->var.rx_packet.rx_data_ptr[0]) << 8)
2112 + readb(&prcs->var.rx_packet.rx_data_ptr[1])) & RX_BUFF_END;
2113 /* Length of first packet fragment */
2114 rx_len = (readb(&prcs->var.rx_packet.rx_data_length[0]) << 8)
2115 + readb(&prcs->var.rx_packet.rx_data_length[1]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002116
John Daiker141fa612009-03-10 06:59:54 -07002117 local->last_rsl = readb(&prcs->var.rx_packet.rx_sig_lev);
2118 pmsg = local->rmem + pkt_addr;
2119 switch (readb(pmsg)) {
2120 case DATA_TYPE:
Dominik Brodowski624dd662009-10-24 15:52:44 +02002121 pr_debug("ray_rx data type\n");
John Daiker141fa612009-03-10 06:59:54 -07002122 rx_data(dev, prcs, pkt_addr, rx_len);
2123 break;
2124 case AUTHENTIC_TYPE:
Dominik Brodowski624dd662009-10-24 15:52:44 +02002125 pr_debug("ray_rx authentic type\n");
John Daiker141fa612009-03-10 06:59:54 -07002126 if (sniffer)
2127 rx_data(dev, prcs, pkt_addr, rx_len);
2128 else
2129 rx_authenticate(local, prcs, pkt_addr, rx_len);
2130 break;
2131 case DEAUTHENTIC_TYPE:
Dominik Brodowski624dd662009-10-24 15:52:44 +02002132 pr_debug("ray_rx deauth type\n");
John Daiker141fa612009-03-10 06:59:54 -07002133 if (sniffer)
2134 rx_data(dev, prcs, pkt_addr, rx_len);
2135 else
2136 rx_deauthenticate(local, prcs, pkt_addr, rx_len);
2137 break;
2138 case NULL_MSG_TYPE:
Dominik Brodowski624dd662009-10-24 15:52:44 +02002139 pr_debug("ray_cs rx NULL msg\n");
John Daiker141fa612009-03-10 06:59:54 -07002140 break;
2141 case BEACON_TYPE:
Dominik Brodowski624dd662009-10-24 15:52:44 +02002142 pr_debug("ray_rx beacon type\n");
John Daiker141fa612009-03-10 06:59:54 -07002143 if (sniffer)
2144 rx_data(dev, prcs, pkt_addr, rx_len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002145
John Daiker141fa612009-03-10 06:59:54 -07002146 copy_from_rx_buff(local, (UCHAR *) &local->last_bcn, pkt_addr,
2147 rx_len < sizeof(struct beacon_rx) ?
2148 rx_len : sizeof(struct beacon_rx));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002149
John Daiker141fa612009-03-10 06:59:54 -07002150 local->beacon_rxed = 1;
2151 /* Get the statistics so the card counters never overflow */
2152 ray_get_stats(dev);
2153 break;
2154 default:
Dominik Brodowski624dd662009-10-24 15:52:44 +02002155 pr_debug("ray_cs unknown pkt type %2x\n",
John Daiker141fa612009-03-10 06:59:54 -07002156 (unsigned int)readb(pmsg));
2157 break;
2158 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002159
2160} /* end ray_rx */
John Daiker141fa612009-03-10 06:59:54 -07002161
Linus Torvalds1da177e2005-04-16 15:20:36 -07002162/*===========================================================================*/
John Daiker141fa612009-03-10 06:59:54 -07002163static void rx_data(struct net_device *dev, struct rcs __iomem *prcs,
2164 unsigned int pkt_addr, int rx_len)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002165{
John Daiker141fa612009-03-10 06:59:54 -07002166 struct sk_buff *skb = NULL;
2167 struct rcs __iomem *prcslink = prcs;
2168 ray_dev_t *local = netdev_priv(dev);
2169 UCHAR *rx_ptr;
2170 int total_len;
2171 int tmp;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002172#ifdef WIRELESS_SPY
John Daiker141fa612009-03-10 06:59:54 -07002173 int siglev = local->last_rsl;
2174 u_char linksrcaddr[ETH_ALEN]; /* Other end of the wireless link */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002175#endif
2176
John Daiker141fa612009-03-10 06:59:54 -07002177 if (!sniffer) {
2178 if (translate) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002179/* TBD length needs fixing for translated header */
John Daiker141fa612009-03-10 06:59:54 -07002180 if (rx_len < (ETH_HLEN + RX_MAC_HEADER_LENGTH) ||
2181 rx_len >
2182 (dev->mtu + RX_MAC_HEADER_LENGTH + ETH_HLEN +
2183 FCS_LEN)) {
Dominik Brodowski624dd662009-10-24 15:52:44 +02002184 pr_debug(
Frans Popcb01b092010-03-24 19:46:34 +01002185 "ray_cs invalid packet length %d received\n",
John Daiker141fa612009-03-10 06:59:54 -07002186 rx_len);
2187 return;
2188 }
2189 } else { /* encapsulated ethernet */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002190
John Daiker141fa612009-03-10 06:59:54 -07002191 if (rx_len < (ETH_HLEN + RX_MAC_HEADER_LENGTH) ||
2192 rx_len >
2193 (dev->mtu + RX_MAC_HEADER_LENGTH + ETH_HLEN +
2194 FCS_LEN)) {
Dominik Brodowski624dd662009-10-24 15:52:44 +02002195 pr_debug(
Frans Popcb01b092010-03-24 19:46:34 +01002196 "ray_cs invalid packet length %d received\n",
John Daiker141fa612009-03-10 06:59:54 -07002197 rx_len);
2198 return;
2199 }
2200 }
2201 }
Dominik Brodowski624dd662009-10-24 15:52:44 +02002202 pr_debug("ray_cs rx_data packet\n");
John Daiker141fa612009-03-10 06:59:54 -07002203 /* If fragmented packet, verify sizes of fragments add up */
2204 if (readb(&prcs->var.rx_packet.next_frag_rcs_index) != 0xFF) {
Dominik Brodowski624dd662009-10-24 15:52:44 +02002205 pr_debug("ray_cs rx'ed fragment\n");
John Daiker141fa612009-03-10 06:59:54 -07002206 tmp = (readb(&prcs->var.rx_packet.totalpacketlength[0]) << 8)
2207 + readb(&prcs->var.rx_packet.totalpacketlength[1]);
2208 total_len = tmp;
2209 prcslink = prcs;
2210 do {
2211 tmp -=
2212 (readb(&prcslink->var.rx_packet.rx_data_length[0])
2213 << 8)
2214 + readb(&prcslink->var.rx_packet.rx_data_length[1]);
2215 if (readb(&prcslink->var.rx_packet.next_frag_rcs_index)
2216 == 0xFF || tmp < 0)
2217 break;
2218 prcslink = rcs_base(local)
2219 + readb(&prcslink->link_field);
2220 } while (1);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002221
John Daiker141fa612009-03-10 06:59:54 -07002222 if (tmp < 0) {
Dominik Brodowski624dd662009-10-24 15:52:44 +02002223 pr_debug(
John Daiker141fa612009-03-10 06:59:54 -07002224 "ray_cs rx_data fragment lengths don't add up\n");
2225 local->stats.rx_dropped++;
2226 release_frag_chain(local, prcs);
2227 return;
2228 }
2229 } else { /* Single unfragmented packet */
2230 total_len = rx_len;
2231 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002232
John Daiker141fa612009-03-10 06:59:54 -07002233 skb = dev_alloc_skb(total_len + 5);
2234 if (skb == NULL) {
Dominik Brodowski624dd662009-10-24 15:52:44 +02002235 pr_debug("ray_cs rx_data could not allocate skb\n");
John Daiker141fa612009-03-10 06:59:54 -07002236 local->stats.rx_dropped++;
2237 if (readb(&prcs->var.rx_packet.next_frag_rcs_index) != 0xFF)
2238 release_frag_chain(local, prcs);
2239 return;
2240 }
2241 skb_reserve(skb, 2); /* Align IP on 16 byte (TBD check this) */
2242
Dominik Brodowski624dd662009-10-24 15:52:44 +02002243 pr_debug("ray_cs rx_data total_len = %x, rx_len = %x\n", total_len,
John Daiker141fa612009-03-10 06:59:54 -07002244 rx_len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002245
2246/************************/
John Daiker141fa612009-03-10 06:59:54 -07002247 /* Reserve enough room for the whole damn packet. */
2248 rx_ptr = skb_put(skb, total_len);
2249 /* Copy the whole packet to sk_buff */
2250 rx_ptr +=
2251 copy_from_rx_buff(local, rx_ptr, pkt_addr & RX_BUFF_END, rx_len);
2252 /* Get source address */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002253#ifdef WIRELESS_SPY
John Daiker141fa612009-03-10 06:59:54 -07002254 skb_copy_from_linear_data_offset(skb,
2255 offsetof(struct mac_header, addr_2),
2256 linksrcaddr, ETH_ALEN);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002257#endif
John Daiker141fa612009-03-10 06:59:54 -07002258 /* Now, deal with encapsulation/translation/sniffer */
2259 if (!sniffer) {
2260 if (!translate) {
2261 /* Encapsulated ethernet, so just lop off 802.11 MAC header */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002262/* TBD reserve skb_reserve( skb, RX_MAC_HEADER_LENGTH); */
John Daiker141fa612009-03-10 06:59:54 -07002263 skb_pull(skb, RX_MAC_HEADER_LENGTH);
2264 } else {
2265 /* Do translation */
2266 untranslate(local, skb, total_len);
2267 }
2268 } else { /* sniffer mode, so just pass whole packet */
2269 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002270
2271/************************/
John Daiker141fa612009-03-10 06:59:54 -07002272 /* Now pick up the rest of the fragments if any */
2273 tmp = 17;
2274 if (readb(&prcs->var.rx_packet.next_frag_rcs_index) != 0xFF) {
2275 prcslink = prcs;
Dominik Brodowski624dd662009-10-24 15:52:44 +02002276 pr_debug("ray_cs rx_data in fragment loop\n");
John Daiker141fa612009-03-10 06:59:54 -07002277 do {
2278 prcslink = rcs_base(local)
2279 +
2280 readb(&prcslink->var.rx_packet.next_frag_rcs_index);
2281 rx_len =
2282 ((readb(&prcslink->var.rx_packet.rx_data_length[0])
2283 << 8)
2284 +
2285 readb(&prcslink->var.rx_packet.rx_data_length[1]))
2286 & RX_BUFF_END;
2287 pkt_addr =
2288 ((readb(&prcslink->var.rx_packet.rx_data_ptr[0]) <<
2289 8)
2290 + readb(&prcslink->var.rx_packet.rx_data_ptr[1]))
2291 & RX_BUFF_END;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002292
John Daiker141fa612009-03-10 06:59:54 -07002293 rx_ptr +=
2294 copy_from_rx_buff(local, rx_ptr, pkt_addr, rx_len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002295
John Daiker141fa612009-03-10 06:59:54 -07002296 } while (tmp-- &&
2297 readb(&prcslink->var.rx_packet.next_frag_rcs_index) !=
2298 0xFF);
2299 release_frag_chain(local, prcs);
2300 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002301
John Daiker141fa612009-03-10 06:59:54 -07002302 skb->protocol = eth_type_trans(skb, dev);
2303 netif_rx(skb);
2304 local->stats.rx_packets++;
2305 local->stats.rx_bytes += total_len;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002306
John Daiker141fa612009-03-10 06:59:54 -07002307 /* Gather signal strength per address */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002308#ifdef WIRELESS_SPY
John Daiker141fa612009-03-10 06:59:54 -07002309 /* For the Access Point or the node having started the ad-hoc net
2310 * note : ad-hoc work only in some specific configurations, but we
2311 * kludge in ray_get_wireless_stats... */
2312 if (!memcmp(linksrcaddr, local->bss_id, ETH_ALEN)) {
2313 /* Update statistics */
2314 /*local->wstats.qual.qual = none ? */
2315 local->wstats.qual.level = siglev;
2316 /*local->wstats.qual.noise = none ? */
2317 local->wstats.qual.updated = 0x2;
2318 }
2319 /* Now, update the spy stuff */
2320 {
2321 struct iw_quality wstats;
2322 wstats.level = siglev;
2323 /* wstats.noise = none ? */
2324 /* wstats.qual = none ? */
2325 wstats.updated = 0x2;
2326 /* Update spy records */
2327 wireless_spy_update(dev, linksrcaddr, &wstats);
2328 }
2329#endif /* WIRELESS_SPY */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002330} /* end rx_data */
John Daiker141fa612009-03-10 06:59:54 -07002331
Linus Torvalds1da177e2005-04-16 15:20:36 -07002332/*===========================================================================*/
2333static void untranslate(ray_dev_t *local, struct sk_buff *skb, int len)
2334{
John Daiker141fa612009-03-10 06:59:54 -07002335 snaphdr_t *psnap = (snaphdr_t *) (skb->data + RX_MAC_HEADER_LENGTH);
2336 struct ieee80211_hdr *pmac = (struct ieee80211_hdr *)skb->data;
2337 __be16 type = *(__be16 *) psnap->ethertype;
2338 int delta;
2339 struct ethhdr *peth;
2340 UCHAR srcaddr[ADDRLEN];
2341 UCHAR destaddr[ADDRLEN];
2342 static UCHAR org_bridge[3] = { 0, 0, 0xf8 };
2343 static UCHAR org_1042[3] = { 0, 0, 0 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002344
John Daiker141fa612009-03-10 06:59:54 -07002345 memcpy(destaddr, ieee80211_get_DA(pmac), ADDRLEN);
2346 memcpy(srcaddr, ieee80211_get_SA(pmac), ADDRLEN);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002347
Dominik Brodowski624dd662009-10-24 15:52:44 +02002348#if 0
2349 if {
Joe Perchesad361c92009-07-06 13:05:40 -07002350 print_hex_dump(KERN_DEBUG, "skb->data before untranslate: ",
2351 DUMP_PREFIX_NONE, 16, 1,
2352 skb->data, 64, true);
2353 printk(KERN_DEBUG
John Daiker141fa612009-03-10 06:59:54 -07002354 "type = %08x, xsap = %02x%02x%02x, org = %02x02x02x\n",
2355 ntohs(type), psnap->dsap, psnap->ssap, psnap->ctrl,
2356 psnap->org[0], psnap->org[1], psnap->org[2]);
2357 printk(KERN_DEBUG "untranslate skb->data = %p\n", skb->data);
2358 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002359#endif
2360
John Daiker141fa612009-03-10 06:59:54 -07002361 if (psnap->dsap != 0xaa || psnap->ssap != 0xaa || psnap->ctrl != 3) {
2362 /* not a snap type so leave it alone */
Dominik Brodowski624dd662009-10-24 15:52:44 +02002363 pr_debug("ray_cs untranslate NOT SNAP %02x %02x %02x\n",
John Daiker141fa612009-03-10 06:59:54 -07002364 psnap->dsap, psnap->ssap, psnap->ctrl);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002365
John Daiker141fa612009-03-10 06:59:54 -07002366 delta = RX_MAC_HEADER_LENGTH - ETH_HLEN;
2367 peth = (struct ethhdr *)(skb->data + delta);
2368 peth->h_proto = htons(len - RX_MAC_HEADER_LENGTH);
2369 } else { /* Its a SNAP */
2370 if (memcmp(psnap->org, org_bridge, 3) == 0) {
2371 /* EtherII and nuke the LLC */
Dominik Brodowski624dd662009-10-24 15:52:44 +02002372 pr_debug("ray_cs untranslate Bridge encap\n");
John Daiker141fa612009-03-10 06:59:54 -07002373 delta = RX_MAC_HEADER_LENGTH
2374 + sizeof(struct snaphdr_t) - ETH_HLEN;
2375 peth = (struct ethhdr *)(skb->data + delta);
2376 peth->h_proto = type;
2377 } else if (memcmp(psnap->org, org_1042, 3) == 0) {
2378 switch (ntohs(type)) {
2379 case ETH_P_IPX:
2380 case ETH_P_AARP:
Dominik Brodowski624dd662009-10-24 15:52:44 +02002381 pr_debug("ray_cs untranslate RFC IPX/AARP\n");
John Daiker141fa612009-03-10 06:59:54 -07002382 delta = RX_MAC_HEADER_LENGTH - ETH_HLEN;
2383 peth = (struct ethhdr *)(skb->data + delta);
2384 peth->h_proto =
2385 htons(len - RX_MAC_HEADER_LENGTH);
2386 break;
2387 default:
Dominik Brodowski624dd662009-10-24 15:52:44 +02002388 pr_debug("ray_cs untranslate RFC default\n");
John Daiker141fa612009-03-10 06:59:54 -07002389 delta = RX_MAC_HEADER_LENGTH +
2390 sizeof(struct snaphdr_t) - ETH_HLEN;
2391 peth = (struct ethhdr *)(skb->data + delta);
2392 peth->h_proto = type;
2393 break;
2394 }
2395 } else {
2396 printk("ray_cs untranslate very confused by packet\n");
2397 delta = RX_MAC_HEADER_LENGTH - ETH_HLEN;
2398 peth = (struct ethhdr *)(skb->data + delta);
2399 peth->h_proto = type;
2400 }
Al Viro7698d692007-12-29 04:55:50 -05002401 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002402/* TBD reserve skb_reserve(skb, delta); */
John Daiker141fa612009-03-10 06:59:54 -07002403 skb_pull(skb, delta);
Dominik Brodowski624dd662009-10-24 15:52:44 +02002404 pr_debug("untranslate after skb_pull(%d), skb->data = %p\n", delta,
John Daiker141fa612009-03-10 06:59:54 -07002405 skb->data);
2406 memcpy(peth->h_dest, destaddr, ADDRLEN);
2407 memcpy(peth->h_source, srcaddr, ADDRLEN);
Dominik Brodowski624dd662009-10-24 15:52:44 +02002408#if 0
2409 {
John Daiker141fa612009-03-10 06:59:54 -07002410 int i;
2411 printk(KERN_DEBUG "skb->data after untranslate:");
2412 for (i = 0; i < 64; i++)
2413 printk("%02x ", skb->data[i]);
2414 printk("\n");
2415 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002416#endif
2417} /* end untranslate */
John Daiker141fa612009-03-10 06:59:54 -07002418
Linus Torvalds1da177e2005-04-16 15:20:36 -07002419/*===========================================================================*/
2420/* Copy data from circular receive buffer to PC memory.
2421 * dest = destination address in PC memory
2422 * pkt_addr = source address in receive buffer
2423 * len = length of packet to copy
2424 */
John Daiker141fa612009-03-10 06:59:54 -07002425static int copy_from_rx_buff(ray_dev_t *local, UCHAR *dest, int pkt_addr,
2426 int length)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002427{
John Daiker141fa612009-03-10 06:59:54 -07002428 int wrap_bytes = (pkt_addr + length) - (RX_BUFF_END + 1);
2429 if (wrap_bytes <= 0) {
2430 memcpy_fromio(dest, local->rmem + pkt_addr, length);
2431 } else { /* Packet wrapped in circular buffer */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002432
John Daiker141fa612009-03-10 06:59:54 -07002433 memcpy_fromio(dest, local->rmem + pkt_addr,
2434 length - wrap_bytes);
2435 memcpy_fromio(dest + length - wrap_bytes, local->rmem,
2436 wrap_bytes);
2437 }
2438 return length;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002439}
John Daiker141fa612009-03-10 06:59:54 -07002440
2441/*===========================================================================*/
2442static void release_frag_chain(ray_dev_t *local, struct rcs __iomem *prcs)
2443{
2444 struct rcs __iomem *prcslink = prcs;
2445 int tmp = 17;
2446 unsigned rcsindex = readb(&prcs->var.rx_packet.next_frag_rcs_index);
2447
2448 while (tmp--) {
2449 writeb(CCS_BUFFER_FREE, &prcslink->buffer_status);
2450 if (rcsindex >= (NUMBER_OF_CCS + NUMBER_OF_RCS)) {
Dominik Brodowski624dd662009-10-24 15:52:44 +02002451 pr_debug("ray_cs interrupt bad rcsindex = 0x%x\n",
John Daiker141fa612009-03-10 06:59:54 -07002452 rcsindex);
2453 break;
2454 }
2455 prcslink = rcs_base(local) + rcsindex;
2456 rcsindex = readb(&prcslink->var.rx_packet.next_frag_rcs_index);
2457 }
2458 writeb(CCS_BUFFER_FREE, &prcslink->buffer_status);
2459}
2460
Linus Torvalds1da177e2005-04-16 15:20:36 -07002461/*===========================================================================*/
2462static void authenticate(ray_dev_t *local)
2463{
John Daiker141fa612009-03-10 06:59:54 -07002464 struct pcmcia_device *link = local->finder;
Dominik Brodowski624dd662009-10-24 15:52:44 +02002465 dev_dbg(&link->dev, "ray_cs Starting authentication.\n");
John Daiker141fa612009-03-10 06:59:54 -07002466 if (!(pcmcia_dev_present(link))) {
Dominik Brodowski624dd662009-10-24 15:52:44 +02002467 dev_dbg(&link->dev, "ray_cs authenticate - device not present\n");
John Daiker141fa612009-03-10 06:59:54 -07002468 return;
2469 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002470
John Daiker141fa612009-03-10 06:59:54 -07002471 del_timer(&local->timer);
2472 if (build_auth_frame(local, local->bss_id, OPEN_AUTH_REQUEST)) {
2473 local->timer.function = &join_net;
2474 } else {
2475 local->timer.function = &authenticate_timeout;
2476 }
2477 local->timer.expires = jiffies + HZ * 2;
2478 local->timer.data = (long)local;
2479 add_timer(&local->timer);
2480 local->authentication_state = AWAITING_RESPONSE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002481} /* end authenticate */
John Daiker141fa612009-03-10 06:59:54 -07002482
Linus Torvalds1da177e2005-04-16 15:20:36 -07002483/*===========================================================================*/
2484static void rx_authenticate(ray_dev_t *local, struct rcs __iomem *prcs,
John Daiker141fa612009-03-10 06:59:54 -07002485 unsigned int pkt_addr, int rx_len)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002486{
John Daiker141fa612009-03-10 06:59:54 -07002487 UCHAR buff[256];
2488 struct rx_msg *msg = (struct rx_msg *)buff;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002489
John Daiker141fa612009-03-10 06:59:54 -07002490 del_timer(&local->timer);
2491
2492 copy_from_rx_buff(local, buff, pkt_addr, rx_len & 0xff);
2493 /* if we are trying to get authenticated */
2494 if (local->sparm.b4.a_network_type == ADHOC) {
Dominik Brodowski624dd662009-10-24 15:52:44 +02002495 pr_debug("ray_cs rx_auth var= %02x %02x %02x %02x %02x %02x\n",
John Daiker141fa612009-03-10 06:59:54 -07002496 msg->var[0], msg->var[1], msg->var[2], msg->var[3],
2497 msg->var[4], msg->var[5]);
2498 if (msg->var[2] == 1) {
Dominik Brodowski624dd662009-10-24 15:52:44 +02002499 pr_debug("ray_cs Sending authentication response.\n");
John Daiker141fa612009-03-10 06:59:54 -07002500 if (!build_auth_frame
2501 (local, msg->mac.addr_2, OPEN_AUTH_RESPONSE)) {
2502 local->authentication_state = NEED_TO_AUTH;
2503 memcpy(local->auth_id, msg->mac.addr_2,
2504 ADDRLEN);
2505 }
2506 }
2507 } else { /* Infrastructure network */
2508
2509 if (local->authentication_state == AWAITING_RESPONSE) {
2510 /* Verify authentication sequence #2 and success */
2511 if (msg->var[2] == 2) {
2512 if ((msg->var[3] | msg->var[4]) == 0) {
Dominik Brodowski624dd662009-10-24 15:52:44 +02002513 pr_debug("Authentication successful\n");
John Daiker141fa612009-03-10 06:59:54 -07002514 local->card_status = CARD_AUTH_COMPLETE;
2515 associate(local);
2516 local->authentication_state =
2517 AUTHENTICATED;
2518 } else {
Dominik Brodowski624dd662009-10-24 15:52:44 +02002519 pr_debug("Authentication refused\n");
John Daiker141fa612009-03-10 06:59:54 -07002520 local->card_status = CARD_AUTH_REFUSED;
2521 join_net((u_long) local);
2522 local->authentication_state =
2523 UNAUTHENTICATED;
2524 }
2525 }
2526 }
2527 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002528
2529} /* end rx_authenticate */
John Daiker141fa612009-03-10 06:59:54 -07002530
Linus Torvalds1da177e2005-04-16 15:20:36 -07002531/*===========================================================================*/
2532static void associate(ray_dev_t *local)
2533{
John Daiker141fa612009-03-10 06:59:54 -07002534 struct ccs __iomem *pccs;
2535 struct pcmcia_device *link = local->finder;
2536 struct net_device *dev = link->priv;
2537 int ccsindex;
2538 if (!(pcmcia_dev_present(link))) {
Dominik Brodowski624dd662009-10-24 15:52:44 +02002539 dev_dbg(&link->dev, "ray_cs associate - device not present\n");
John Daiker141fa612009-03-10 06:59:54 -07002540 return;
2541 }
2542 /* If no tx buffers available, return */
2543 if ((ccsindex = get_free_ccs(local)) < 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002544/* TBD should never be here but... what if we are? */
Dominik Brodowski624dd662009-10-24 15:52:44 +02002545 dev_dbg(&link->dev, "ray_cs associate - No free ccs\n");
John Daiker141fa612009-03-10 06:59:54 -07002546 return;
2547 }
Dominik Brodowski624dd662009-10-24 15:52:44 +02002548 dev_dbg(&link->dev, "ray_cs Starting association with access point\n");
John Daiker141fa612009-03-10 06:59:54 -07002549 pccs = ccs_base(local) + ccsindex;
2550 /* fill in the CCS */
2551 writeb(CCS_START_ASSOCIATION, &pccs->cmd);
2552 /* Interrupt the firmware to process the command */
2553 if (interrupt_ecf(local, ccsindex)) {
Dominik Brodowski624dd662009-10-24 15:52:44 +02002554 dev_dbg(&link->dev, "ray_cs associate failed - ECF not ready for intr\n");
John Daiker141fa612009-03-10 06:59:54 -07002555 writeb(CCS_BUFFER_FREE, &(pccs++)->buffer_status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002556
John Daiker141fa612009-03-10 06:59:54 -07002557 del_timer(&local->timer);
2558 local->timer.expires = jiffies + HZ * 2;
2559 local->timer.data = (long)local;
2560 local->timer.function = &join_net;
2561 add_timer(&local->timer);
2562 local->card_status = CARD_ASSOC_FAILED;
2563 return;
2564 }
2565 if (!sniffer)
2566 netif_start_queue(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002567
2568} /* end associate */
John Daiker141fa612009-03-10 06:59:54 -07002569
Linus Torvalds1da177e2005-04-16 15:20:36 -07002570/*===========================================================================*/
John Daiker141fa612009-03-10 06:59:54 -07002571static void rx_deauthenticate(ray_dev_t *local, struct rcs __iomem *prcs,
2572 unsigned int pkt_addr, int rx_len)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002573{
2574/* UCHAR buff[256];
2575 struct rx_msg *msg = (struct rx_msg *)buff;
2576*/
Dominik Brodowski624dd662009-10-24 15:52:44 +02002577 pr_debug("Deauthentication frame received\n");
John Daiker141fa612009-03-10 06:59:54 -07002578 local->authentication_state = UNAUTHENTICATED;
2579 /* Need to reauthenticate or rejoin depending on reason code */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002580/* copy_from_rx_buff(local, buff, pkt_addr, rx_len & 0xff);
2581 */
2582}
John Daiker141fa612009-03-10 06:59:54 -07002583
Linus Torvalds1da177e2005-04-16 15:20:36 -07002584/*===========================================================================*/
2585static void clear_interrupt(ray_dev_t *local)
2586{
John Daiker141fa612009-03-10 06:59:54 -07002587 writeb(0, local->amem + CIS_OFFSET + HCS_INTR_OFFSET);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002588}
John Daiker141fa612009-03-10 06:59:54 -07002589
Linus Torvalds1da177e2005-04-16 15:20:36 -07002590/*===========================================================================*/
2591#ifdef CONFIG_PROC_FS
2592#define MAXDATA (PAGE_SIZE - 80)
2593
2594static char *card_status[] = {
John Daiker141fa612009-03-10 06:59:54 -07002595 "Card inserted - uninitialized", /* 0 */
2596 "Card not downloaded", /* 1 */
2597 "Waiting for download parameters", /* 2 */
2598 "Card doing acquisition", /* 3 */
2599 "Acquisition complete", /* 4 */
2600 "Authentication complete", /* 5 */
2601 "Association complete", /* 6 */
2602 "???", "???", "???", "???", /* 7 8 9 10 undefined */
2603 "Card init error", /* 11 */
2604 "Download parameters error", /* 12 */
2605 "???", /* 13 */
2606 "Acquisition failed", /* 14 */
2607 "Authentication refused", /* 15 */
2608 "Association failed" /* 16 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002609};
2610
John Daiker141fa612009-03-10 06:59:54 -07002611static char *nettype[] = { "Adhoc", "Infra " };
2612static char *framing[] = { "Encapsulation", "Translation" }
2613
Linus Torvalds1da177e2005-04-16 15:20:36 -07002614;
2615/*===========================================================================*/
Alexey Dobriyan6b914c52008-04-10 14:34:35 -07002616static int ray_cs_proc_show(struct seq_file *m, void *v)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002617{
2618/* Print current values which are not available via other means
John Daiker141fa612009-03-10 06:59:54 -07002619 * eg ifconfig
Linus Torvalds1da177e2005-04-16 15:20:36 -07002620 */
John Daiker141fa612009-03-10 06:59:54 -07002621 int i;
2622 struct pcmcia_device *link;
2623 struct net_device *dev;
2624 ray_dev_t *local;
2625 UCHAR *p;
2626 struct freq_hop_element *pfh;
2627 UCHAR c[33];
Linus Torvalds1da177e2005-04-16 15:20:36 -07002628
John Daiker141fa612009-03-10 06:59:54 -07002629 link = this_device;
2630 if (!link)
2631 return 0;
2632 dev = (struct net_device *)link->priv;
2633 if (!dev)
2634 return 0;
2635 local = netdev_priv(dev);
2636 if (!local)
2637 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002638
John Daiker141fa612009-03-10 06:59:54 -07002639 seq_puts(m, "Raylink Wireless LAN driver status\n");
2640 seq_printf(m, "%s\n", rcsid);
2641 /* build 4 does not report version, and field is 0x55 after memtest */
2642 seq_puts(m, "Firmware version = ");
2643 if (local->fw_ver == 0x55)
2644 seq_puts(m, "4 - Use dump_cis for more details\n");
2645 else
2646 seq_printf(m, "%2d.%02d.%02d\n",
2647 local->fw_ver, local->fw_bld, local->fw_var);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002648
John Daiker141fa612009-03-10 06:59:54 -07002649 for (i = 0; i < 32; i++)
2650 c[i] = local->sparm.b5.a_current_ess_id[i];
2651 c[32] = 0;
2652 seq_printf(m, "%s network ESSID = \"%s\"\n",
2653 nettype[local->sparm.b5.a_network_type], c);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002654
John Daiker141fa612009-03-10 06:59:54 -07002655 p = local->bss_id;
2656 seq_printf(m, "BSSID = %pM\n", p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002657
John Daiker141fa612009-03-10 06:59:54 -07002658 seq_printf(m, "Country code = %d\n",
2659 local->sparm.b5.a_curr_country_code);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002660
John Daiker141fa612009-03-10 06:59:54 -07002661 i = local->card_status;
2662 if (i < 0)
2663 i = 10;
2664 if (i > 16)
2665 i = 10;
2666 seq_printf(m, "Card status = %s\n", card_status[i]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002667
John Daiker141fa612009-03-10 06:59:54 -07002668 seq_printf(m, "Framing mode = %s\n", framing[translate]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002669
John Daiker141fa612009-03-10 06:59:54 -07002670 seq_printf(m, "Last pkt signal lvl = %d\n", local->last_rsl);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002671
John Daiker141fa612009-03-10 06:59:54 -07002672 if (local->beacon_rxed) {
2673 /* Pull some fields out of last beacon received */
2674 seq_printf(m, "Beacon Interval = %d Kus\n",
2675 local->last_bcn.beacon_intvl[0]
2676 + 256 * local->last_bcn.beacon_intvl[1]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002677
John Daiker141fa612009-03-10 06:59:54 -07002678 p = local->last_bcn.elements;
2679 if (p[0] == C_ESSID_ELEMENT_ID)
2680 p += p[1] + 2;
2681 else {
2682 seq_printf(m,
2683 "Parse beacon failed at essid element id = %d\n",
2684 p[0]);
2685 return 0;
2686 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002687
John Daiker141fa612009-03-10 06:59:54 -07002688 if (p[0] == C_SUPPORTED_RATES_ELEMENT_ID) {
2689 seq_puts(m, "Supported rate codes = ");
2690 for (i = 2; i < p[1] + 2; i++)
2691 seq_printf(m, "0x%02x ", p[i]);
2692 seq_putc(m, '\n');
2693 p += p[1] + 2;
2694 } else {
2695 seq_puts(m, "Parse beacon failed at rates element\n");
2696 return 0;
2697 }
2698
2699 if (p[0] == C_FH_PARAM_SET_ELEMENT_ID) {
2700 pfh = (struct freq_hop_element *)p;
2701 seq_printf(m, "Hop dwell = %d Kus\n",
2702 pfh->dwell_time[0] +
2703 256 * pfh->dwell_time[1]);
Frans Popcb01b092010-03-24 19:46:34 +01002704 seq_printf(m, "Hop set = %d\n",
John Daiker141fa612009-03-10 06:59:54 -07002705 pfh->hop_set);
Frans Popcb01b092010-03-24 19:46:34 +01002706 seq_printf(m, "Hop pattern = %d\n",
John Daiker141fa612009-03-10 06:59:54 -07002707 pfh->hop_pattern);
Frans Popcb01b092010-03-24 19:46:34 +01002708 seq_printf(m, "Hop index = %d\n",
John Daiker141fa612009-03-10 06:59:54 -07002709 pfh->hop_index);
2710 p += p[1] + 2;
2711 } else {
2712 seq_puts(m,
2713 "Parse beacon failed at FH param element\n");
2714 return 0;
2715 }
2716 } else {
2717 seq_puts(m, "No beacons received\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002718 }
John Daiker141fa612009-03-10 06:59:54 -07002719 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002720}
2721
Alexey Dobriyan6b914c52008-04-10 14:34:35 -07002722static int ray_cs_proc_open(struct inode *inode, struct file *file)
2723{
2724 return single_open(file, ray_cs_proc_show, NULL);
2725}
2726
2727static const struct file_operations ray_cs_proc_fops = {
John Daiker141fa612009-03-10 06:59:54 -07002728 .owner = THIS_MODULE,
2729 .open = ray_cs_proc_open,
2730 .read = seq_read,
2731 .llseek = seq_lseek,
2732 .release = single_release,
Alexey Dobriyan6b914c52008-04-10 14:34:35 -07002733};
Linus Torvalds1da177e2005-04-16 15:20:36 -07002734#endif
2735/*===========================================================================*/
2736static int build_auth_frame(ray_dev_t *local, UCHAR *dest, int auth_type)
2737{
John Daiker141fa612009-03-10 06:59:54 -07002738 int addr;
2739 struct ccs __iomem *pccs;
2740 struct tx_msg __iomem *ptx;
2741 int ccsindex;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002742
John Daiker141fa612009-03-10 06:59:54 -07002743 /* If no tx buffers available, return */
2744 if ((ccsindex = get_free_tx_ccs(local)) < 0) {
Dominik Brodowski624dd662009-10-24 15:52:44 +02002745 pr_debug("ray_cs send authenticate - No free tx ccs\n");
John Daiker141fa612009-03-10 06:59:54 -07002746 return -1;
2747 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002748
John Daiker141fa612009-03-10 06:59:54 -07002749 pccs = ccs_base(local) + ccsindex;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002750
John Daiker141fa612009-03-10 06:59:54 -07002751 /* Address in card space */
2752 addr = TX_BUF_BASE + (ccsindex << 11);
2753 /* fill in the CCS */
2754 writeb(CCS_TX_REQUEST, &pccs->cmd);
2755 writeb(addr >> 8, pccs->var.tx_request.tx_data_ptr);
2756 writeb(0x20, pccs->var.tx_request.tx_data_ptr + 1);
2757 writeb(TX_AUTHENTICATE_LENGTH_MSB, pccs->var.tx_request.tx_data_length);
2758 writeb(TX_AUTHENTICATE_LENGTH_LSB,
2759 pccs->var.tx_request.tx_data_length + 1);
2760 writeb(0, &pccs->var.tx_request.pow_sav_mode);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002761
John Daiker141fa612009-03-10 06:59:54 -07002762 ptx = local->sram + addr;
2763 /* fill in the mac header */
2764 writeb(PROTOCOL_VER | AUTHENTIC_TYPE, &ptx->mac.frame_ctl_1);
2765 writeb(0, &ptx->mac.frame_ctl_2);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002766
John Daiker141fa612009-03-10 06:59:54 -07002767 memcpy_toio(ptx->mac.addr_1, dest, ADDRLEN);
2768 memcpy_toio(ptx->mac.addr_2, local->sparm.b4.a_mac_addr, ADDRLEN);
2769 memcpy_toio(ptx->mac.addr_3, local->bss_id, ADDRLEN);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002770
John Daiker141fa612009-03-10 06:59:54 -07002771 /* Fill in msg body with protocol 00 00, sequence 01 00 ,status 00 00 */
2772 memset_io(ptx->var, 0, 6);
2773 writeb(auth_type & 0xff, ptx->var + 2);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002774
John Daiker141fa612009-03-10 06:59:54 -07002775 /* Interrupt the firmware to process the command */
2776 if (interrupt_ecf(local, ccsindex)) {
Dominik Brodowski624dd662009-10-24 15:52:44 +02002777 pr_debug(
John Daiker141fa612009-03-10 06:59:54 -07002778 "ray_cs send authentication request failed - ECF not ready for intr\n");
2779 writeb(CCS_BUFFER_FREE, &(pccs++)->buffer_status);
2780 return -1;
2781 }
2782 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002783} /* End build_auth_frame */
2784
2785/*===========================================================================*/
2786#ifdef CONFIG_PROC_FS
Alexey Dobriyan83daee02009-11-25 10:12:20 +03002787static ssize_t ray_cs_essid_proc_write(struct file *file,
2788 const char __user *buffer, size_t count, loff_t *pos)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002789{
2790 static char proc_essid[33];
Alan Cox575c9ed2009-10-27 15:35:55 +00002791 unsigned int len = count;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002792
2793 if (len > 32)
2794 len = 32;
2795 memset(proc_essid, 0, 33);
2796 if (copy_from_user(proc_essid, buffer, len))
2797 return -EFAULT;
2798 essid = proc_essid;
2799 return count;
2800}
2801
Alexey Dobriyan83daee02009-11-25 10:12:20 +03002802static const struct file_operations ray_cs_essid_proc_fops = {
2803 .owner = THIS_MODULE,
2804 .write = ray_cs_essid_proc_write,
Arnd Bergmann6038f372010-08-15 18:52:59 +02002805 .llseek = noop_llseek,
Alexey Dobriyan83daee02009-11-25 10:12:20 +03002806};
2807
2808static ssize_t int_proc_write(struct file *file, const char __user *buffer,
2809 size_t count, loff_t *pos)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002810{
2811 static char proc_number[10];
2812 char *p;
2813 int nr, len;
2814
2815 if (!count)
2816 return 0;
2817
2818 if (count > 9)
2819 return -EINVAL;
2820 if (copy_from_user(proc_number, buffer, count))
2821 return -EFAULT;
2822 p = proc_number;
2823 nr = 0;
2824 len = count;
2825 do {
2826 unsigned int c = *p - '0';
2827 if (c > 9)
2828 return -EINVAL;
John Daiker141fa612009-03-10 06:59:54 -07002829 nr = nr * 10 + c;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002830 p++;
2831 } while (--len);
Alexey Dobriyan83daee02009-11-25 10:12:20 +03002832 *(int *)PDE(file->f_path.dentry->d_inode)->data = nr;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002833 return count;
2834}
Alexey Dobriyan83daee02009-11-25 10:12:20 +03002835
2836static const struct file_operations int_proc_fops = {
2837 .owner = THIS_MODULE,
2838 .write = int_proc_write,
Arnd Bergmann6038f372010-08-15 18:52:59 +02002839 .llseek = noop_llseek,
Alexey Dobriyan83daee02009-11-25 10:12:20 +03002840};
Linus Torvalds1da177e2005-04-16 15:20:36 -07002841#endif
2842
Dominik Brodowskif57ea2a2005-06-27 16:28:24 -07002843static struct pcmcia_device_id ray_ids[] = {
2844 PCMCIA_DEVICE_MANF_CARD(0x01a6, 0x0000),
2845 PCMCIA_DEVICE_NULL,
2846};
John Daiker141fa612009-03-10 06:59:54 -07002847
Dominik Brodowskif57ea2a2005-06-27 16:28:24 -07002848MODULE_DEVICE_TABLE(pcmcia, ray_ids);
2849
Linus Torvalds1da177e2005-04-16 15:20:36 -07002850static struct pcmcia_driver ray_driver = {
John Daiker141fa612009-03-10 06:59:54 -07002851 .owner = THIS_MODULE,
2852 .drv = {
2853 .name = "ray_cs",
2854 },
2855 .probe = ray_probe,
2856 .remove = ray_detach,
2857 .id_table = ray_ids,
2858 .suspend = ray_suspend,
2859 .resume = ray_resume,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002860};
2861
2862static int __init init_ray_cs(void)
2863{
John Daiker141fa612009-03-10 06:59:54 -07002864 int rc;
2865
Dominik Brodowski624dd662009-10-24 15:52:44 +02002866 pr_debug("%s\n", rcsid);
John Daiker141fa612009-03-10 06:59:54 -07002867 rc = pcmcia_register_driver(&ray_driver);
Dominik Brodowski624dd662009-10-24 15:52:44 +02002868 pr_debug("raylink init_module register_pcmcia_driver returns 0x%x\n",
John Daiker141fa612009-03-10 06:59:54 -07002869 rc);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002870
2871#ifdef CONFIG_PROC_FS
John Daiker141fa612009-03-10 06:59:54 -07002872 proc_mkdir("driver/ray_cs", NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002873
John Daiker141fa612009-03-10 06:59:54 -07002874 proc_create("driver/ray_cs/ray_cs", 0, NULL, &ray_cs_proc_fops);
Alexey Dobriyan83daee02009-11-25 10:12:20 +03002875 proc_create("driver/ray_cs/essid", S_IWUSR, NULL, &ray_cs_essid_proc_fops);
2876 proc_create_data("driver/ray_cs/net_type", S_IWUSR, NULL, &int_proc_fops, &net_type);
2877 proc_create_data("driver/ray_cs/translate", S_IWUSR, NULL, &int_proc_fops, &translate);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002878#endif
John Daiker141fa612009-03-10 06:59:54 -07002879 if (translate != 0)
2880 translate = 1;
2881 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002882} /* init_ray_cs */
2883
2884/*===========================================================================*/
2885
2886static void __exit exit_ray_cs(void)
2887{
Dominik Brodowski624dd662009-10-24 15:52:44 +02002888 pr_debug("ray_cs: cleanup_module\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002889
2890#ifdef CONFIG_PROC_FS
John Daiker141fa612009-03-10 06:59:54 -07002891 remove_proc_entry("driver/ray_cs/ray_cs", NULL);
2892 remove_proc_entry("driver/ray_cs/essid", NULL);
2893 remove_proc_entry("driver/ray_cs/net_type", NULL);
2894 remove_proc_entry("driver/ray_cs/translate", NULL);
2895 remove_proc_entry("driver/ray_cs", NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002896#endif
2897
John Daiker141fa612009-03-10 06:59:54 -07002898 pcmcia_unregister_driver(&ray_driver);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002899} /* exit_ray_cs */
2900
2901module_init(init_ray_cs);
2902module_exit(exit_ray_cs);
2903
2904/*===========================================================================*/