blob: ab34cb8c56c7aeb055bdf38f92adb6eace6aeaad [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;
John Daiker141fa612009-03-10 06:59:54 -0700394 struct net_device *dev = (struct net_device *)link->priv;
395 ray_dev_t *local = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700396
Dominik Brodowski624dd662009-10-24 15:52:44 +0200397 dev_dbg(&link->dev, "ray_config\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700398
John Daiker141fa612009-03-10 06:59:54 -0700399 /* Determine card type and firmware version */
400 printk(KERN_INFO "ray_cs Detected: %s%s%s%s\n",
401 link->prod_id[0] ? link->prod_id[0] : " ",
402 link->prod_id[1] ? link->prod_id[1] : " ",
403 link->prod_id[2] ? link->prod_id[2] : " ",
404 link->prod_id[3] ? link->prod_id[3] : " ");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700405
John Daiker141fa612009-03-10 06:59:54 -0700406 /* Now allocate an interrupt line. Note that this does not
407 actually assign a handler to the interrupt.
408 */
Dominik Brodowskieb141202010-03-07 12:21:16 +0100409 ret = pcmcia_request_irq(link, ray_interrupt);
Dominik Brodowski624dd662009-10-24 15:52:44 +0200410 if (ret)
411 goto failed;
Dominik Brodowskieb141202010-03-07 12:21:16 +0100412 dev->irq = link->irq;
John Daiker141fa612009-03-10 06:59:54 -0700413
414 /* This actually configures the PCMCIA socket -- setting up
415 the I/O windows and the interrupt mapping.
416 */
Dominik Brodowski624dd662009-10-24 15:52:44 +0200417 ret = pcmcia_request_configuration(link, &link->conf);
418 if (ret)
419 goto failed;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700420
421/*** Set up 32k window for shared memory (transmit and control) ************/
Dominik Brodowskicdb13802010-07-28 10:59:06 +0200422 link->resource[2]->flags |= WIN_DATA_WIDTH_8 | WIN_MEMORY_TYPE_CM | WIN_ENABLE | WIN_USE_WAIT;
423 link->resource[2]->start = 0;
424 link->resource[2]->end = 0x8000;
425 ret = pcmcia_request_window(link, link->resource[2], ray_mem_speed);
Dominik Brodowski624dd662009-10-24 15:52:44 +0200426 if (ret)
427 goto failed;
Dominik Brodowskicdb13802010-07-28 10:59:06 +0200428 ret = pcmcia_map_mem_page(link, link->resource[2], 0);
Dominik Brodowski624dd662009-10-24 15:52:44 +0200429 if (ret)
430 goto failed;
Dominik Brodowskicdb13802010-07-28 10:59:06 +0200431 local->sram = ioremap(link->resource[2]->start,
432 resource_size(link->resource[2]));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700433
434/*** Set up 16k window for shared memory (receive buffer) ***************/
Dominik Brodowskicdb13802010-07-28 10:59:06 +0200435 link->resource[3]->flags |=
John Daiker141fa612009-03-10 06:59:54 -0700436 WIN_DATA_WIDTH_8 | WIN_MEMORY_TYPE_CM | WIN_ENABLE | WIN_USE_WAIT;
Dominik Brodowskicdb13802010-07-28 10:59:06 +0200437 link->resource[3]->start = 0;
438 link->resource[3]->end = 0x4000;
439 ret = pcmcia_request_window(link, link->resource[3], ray_mem_speed);
Dominik Brodowski624dd662009-10-24 15:52:44 +0200440 if (ret)
441 goto failed;
Dominik Brodowskicdb13802010-07-28 10:59:06 +0200442 ret = pcmcia_map_mem_page(link, link->resource[3], 0x8000);
Dominik Brodowski624dd662009-10-24 15:52:44 +0200443 if (ret)
444 goto failed;
Dominik Brodowskicdb13802010-07-28 10:59:06 +0200445 local->rmem = ioremap(link->resource[3]->start,
446 resource_size(link->resource[3]));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700447
448/*** Set up window for attribute memory ***********************************/
Dominik Brodowskicdb13802010-07-28 10:59:06 +0200449 link->resource[4]->flags |=
John Daiker141fa612009-03-10 06:59:54 -0700450 WIN_DATA_WIDTH_8 | WIN_MEMORY_TYPE_AM | WIN_ENABLE | WIN_USE_WAIT;
Dominik Brodowskicdb13802010-07-28 10:59:06 +0200451 link->resource[4]->start = 0;
452 link->resource[4]->end = 0x1000;
453 ret = pcmcia_request_window(link, link->resource[4], ray_mem_speed);
Dominik Brodowski624dd662009-10-24 15:52:44 +0200454 if (ret)
455 goto failed;
Dominik Brodowskicdb13802010-07-28 10:59:06 +0200456 ret = pcmcia_map_mem_page(link, link->resource[4], 0);
Dominik Brodowski624dd662009-10-24 15:52:44 +0200457 if (ret)
458 goto failed;
Dominik Brodowskicdb13802010-07-28 10:59:06 +0200459 local->amem = ioremap(link->resource[4]->start,
460 resource_size(link->resource[4]));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700461
Dominik Brodowski624dd662009-10-24 15:52:44 +0200462 dev_dbg(&link->dev, "ray_config sram=%p\n", local->sram);
463 dev_dbg(&link->dev, "ray_config rmem=%p\n", local->rmem);
464 dev_dbg(&link->dev, "ray_config amem=%p\n", local->amem);
John Daiker141fa612009-03-10 06:59:54 -0700465 if (ray_init(dev) < 0) {
466 ray_release(link);
467 return -ENODEV;
468 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700469
Dominik Brodowskidd2e5a12009-11-03 10:27:34 +0100470 SET_NETDEV_DEV(dev, &link->dev);
John Daiker141fa612009-03-10 06:59:54 -0700471 i = register_netdev(dev);
472 if (i != 0) {
473 printk("ray_config register_netdev() failed\n");
474 ray_release(link);
475 return i;
476 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700477
John Daiker141fa612009-03-10 06:59:54 -0700478 printk(KERN_INFO "%s: RayLink, irq %d, hw_addr %pM\n",
479 dev->name, dev->irq, dev->dev_addr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700480
John Daiker141fa612009-03-10 06:59:54 -0700481 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700482
Dominik Brodowski624dd662009-10-24 15:52:44 +0200483failed:
John Daiker141fa612009-03-10 06:59:54 -0700484 ray_release(link);
485 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700486} /* ray_config */
487
488static inline struct ccs __iomem *ccs_base(ray_dev_t *dev)
489{
490 return dev->sram + CCS_BASE;
491}
492
493static inline struct rcs __iomem *rcs_base(ray_dev_t *dev)
494{
495 /*
496 * This looks nonsensical, since there is a separate
497 * RCS_BASE. But the difference between a "struct rcs"
498 * and a "struct ccs" ends up being in the _index_ off
499 * the base, so the base pointer is the same for both
500 * ccs/rcs.
501 */
502 return dev->sram + CCS_BASE;
503}
504
505/*===========================================================================*/
506static int ray_init(struct net_device *dev)
507{
John Daiker141fa612009-03-10 06:59:54 -0700508 int i;
509 UCHAR *p;
510 struct ccs __iomem *pccs;
511 ray_dev_t *local = netdev_priv(dev);
512 struct pcmcia_device *link = local->finder;
Dominik Brodowski624dd662009-10-24 15:52:44 +0200513 dev_dbg(&link->dev, "ray_init(0x%p)\n", dev);
John Daiker141fa612009-03-10 06:59:54 -0700514 if (!(pcmcia_dev_present(link))) {
Dominik Brodowski624dd662009-10-24 15:52:44 +0200515 dev_dbg(&link->dev, "ray_init - device not present\n");
John Daiker141fa612009-03-10 06:59:54 -0700516 return -1;
517 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700518
John Daiker141fa612009-03-10 06:59:54 -0700519 local->net_type = net_type;
520 local->sta_type = TYPE_STA;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700521
John Daiker141fa612009-03-10 06:59:54 -0700522 /* Copy the startup results to local memory */
523 memcpy_fromio(&local->startup_res, local->sram + ECF_TO_HOST_BASE,
524 sizeof(struct startup_res_6));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700525
John Daiker141fa612009-03-10 06:59:54 -0700526 /* Check Power up test status and get mac address from card */
527 if (local->startup_res.startup_word != 0x80) {
528 printk(KERN_INFO "ray_init ERROR card status = %2x\n",
529 local->startup_res.startup_word);
530 local->card_status = CARD_INIT_ERROR;
531 return -1;
532 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700533
John Daiker141fa612009-03-10 06:59:54 -0700534 local->fw_ver = local->startup_res.firmware_version[0];
535 local->fw_bld = local->startup_res.firmware_version[1];
536 local->fw_var = local->startup_res.firmware_version[2];
Frans Popcb01b092010-03-24 19:46:34 +0100537 dev_dbg(&link->dev, "ray_init firmware version %d.%d\n", local->fw_ver,
John Daiker141fa612009-03-10 06:59:54 -0700538 local->fw_bld);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700539
John Daiker141fa612009-03-10 06:59:54 -0700540 local->tib_length = 0x20;
541 if ((local->fw_ver == 5) && (local->fw_bld >= 30))
542 local->tib_length = local->startup_res.tib_length;
Dominik Brodowski624dd662009-10-24 15:52:44 +0200543 dev_dbg(&link->dev, "ray_init tib_length = 0x%02x\n", local->tib_length);
John Daiker141fa612009-03-10 06:59:54 -0700544 /* Initialize CCS's to buffer free state */
545 pccs = ccs_base(local);
546 for (i = 0; i < NUMBER_OF_CCS; i++) {
547 writeb(CCS_BUFFER_FREE, &(pccs++)->buffer_status);
548 }
549 init_startup_params(local);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700550
John Daiker141fa612009-03-10 06:59:54 -0700551 /* copy mac address to startup parameters */
552 if (parse_addr(phy_addr, local->sparm.b4.a_mac_addr)) {
553 p = local->sparm.b4.a_mac_addr;
554 } else {
555 memcpy(&local->sparm.b4.a_mac_addr,
556 &local->startup_res.station_addr, ADDRLEN);
557 p = local->sparm.b4.a_mac_addr;
558 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700559
John Daiker141fa612009-03-10 06:59:54 -0700560 clear_interrupt(local); /* Clear any interrupt from the card */
561 local->card_status = CARD_AWAITING_PARAM;
Dominik Brodowski624dd662009-10-24 15:52:44 +0200562 dev_dbg(&link->dev, "ray_init ending\n");
John Daiker141fa612009-03-10 06:59:54 -0700563 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700564} /* ray_init */
John Daiker141fa612009-03-10 06:59:54 -0700565
Linus Torvalds1da177e2005-04-16 15:20:36 -0700566/*===========================================================================*/
567/* Download startup parameters to the card and command it to read them */
568static int dl_startup_params(struct net_device *dev)
569{
John Daiker141fa612009-03-10 06:59:54 -0700570 int ccsindex;
571 ray_dev_t *local = netdev_priv(dev);
572 struct ccs __iomem *pccs;
573 struct pcmcia_device *link = local->finder;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700574
Dominik Brodowski624dd662009-10-24 15:52:44 +0200575 dev_dbg(&link->dev, "dl_startup_params entered\n");
John Daiker141fa612009-03-10 06:59:54 -0700576 if (!(pcmcia_dev_present(link))) {
Dominik Brodowski624dd662009-10-24 15:52:44 +0200577 dev_dbg(&link->dev, "ray_cs dl_startup_params - device not present\n");
John Daiker141fa612009-03-10 06:59:54 -0700578 return -1;
579 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700580
John Daiker141fa612009-03-10 06:59:54 -0700581 /* Copy parameters to host to ECF area */
582 if (local->fw_ver == 0x55)
583 memcpy_toio(local->sram + HOST_TO_ECF_BASE, &local->sparm.b4,
584 sizeof(struct b4_startup_params));
585 else
586 memcpy_toio(local->sram + HOST_TO_ECF_BASE, &local->sparm.b5,
587 sizeof(struct b5_startup_params));
588
589 /* Fill in the CCS fields for the ECF */
590 if ((ccsindex = get_free_ccs(local)) < 0)
591 return -1;
592 local->dl_param_ccs = ccsindex;
593 pccs = ccs_base(local) + ccsindex;
594 writeb(CCS_DOWNLOAD_STARTUP_PARAMS, &pccs->cmd);
Dominik Brodowski624dd662009-10-24 15:52:44 +0200595 dev_dbg(&link->dev, "dl_startup_params start ccsindex = %d\n",
John Daiker141fa612009-03-10 06:59:54 -0700596 local->dl_param_ccs);
597 /* Interrupt the firmware to process the command */
598 if (interrupt_ecf(local, ccsindex)) {
599 printk(KERN_INFO "ray dl_startup_params failed - "
600 "ECF not ready for intr\n");
601 local->card_status = CARD_DL_PARAM_ERROR;
602 writeb(CCS_BUFFER_FREE, &(pccs++)->buffer_status);
603 return -2;
604 }
605 local->card_status = CARD_DL_PARAM;
606 /* Start kernel timer to wait for dl startup to complete. */
607 local->timer.expires = jiffies + HZ / 2;
608 local->timer.data = (long)local;
609 local->timer.function = &verify_dl_startup;
610 add_timer(&local->timer);
Dominik Brodowski624dd662009-10-24 15:52:44 +0200611 dev_dbg(&link->dev,
John Daiker141fa612009-03-10 06:59:54 -0700612 "ray_cs dl_startup_params started timer for verify_dl_startup\n");
613 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700614} /* dl_startup_params */
John Daiker141fa612009-03-10 06:59:54 -0700615
Linus Torvalds1da177e2005-04-16 15:20:36 -0700616/*===========================================================================*/
617static void init_startup_params(ray_dev_t *local)
618{
John Daiker141fa612009-03-10 06:59:54 -0700619 int i;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700620
John Daiker141fa612009-03-10 06:59:54 -0700621 if (country > JAPAN_TEST)
622 country = USA;
623 else if (country < USA)
624 country = USA;
625 /* structure for hop time and beacon period is defined here using
626 * New 802.11D6.1 format. Card firmware is still using old format
627 * until version 6.
628 * Before After
629 * a_hop_time ms byte a_hop_time ms byte
630 * a_hop_time 2s byte a_hop_time ls byte
631 * a_hop_time ls byte a_beacon_period ms byte
632 * a_beacon_period a_beacon_period ls byte
633 *
634 * a_hop_time = uS a_hop_time = KuS
635 * a_beacon_period = hops a_beacon_period = KuS
636 *//* 64ms = 010000 */
637 if (local->fw_ver == 0x55) {
638 memcpy((UCHAR *) &local->sparm.b4, b4_default_startup_parms,
639 sizeof(struct b4_startup_params));
640 /* Translate sane kus input values to old build 4/5 format */
641 /* i = hop time in uS truncated to 3 bytes */
642 i = (hop_dwell * 1024) & 0xffffff;
643 local->sparm.b4.a_hop_time[0] = (i >> 16) & 0xff;
644 local->sparm.b4.a_hop_time[1] = (i >> 8) & 0xff;
645 local->sparm.b4.a_beacon_period[0] = 0;
646 local->sparm.b4.a_beacon_period[1] =
647 ((beacon_period / hop_dwell) - 1) & 0xff;
648 local->sparm.b4.a_curr_country_code = country;
649 local->sparm.b4.a_hop_pattern_length =
650 hop_pattern_length[(int)country] - 1;
651 if (bc) {
652 local->sparm.b4.a_ack_timeout = 0x50;
653 local->sparm.b4.a_sifs = 0x3f;
654 }
655 } else { /* Version 5 uses real kus values */
656 memcpy((UCHAR *) &local->sparm.b5, b5_default_startup_parms,
657 sizeof(struct b5_startup_params));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700658
John Daiker141fa612009-03-10 06:59:54 -0700659 local->sparm.b5.a_hop_time[0] = (hop_dwell >> 8) & 0xff;
660 local->sparm.b5.a_hop_time[1] = hop_dwell & 0xff;
661 local->sparm.b5.a_beacon_period[0] =
662 (beacon_period >> 8) & 0xff;
663 local->sparm.b5.a_beacon_period[1] = beacon_period & 0xff;
664 if (psm)
665 local->sparm.b5.a_power_mgt_state = 1;
666 local->sparm.b5.a_curr_country_code = country;
667 local->sparm.b5.a_hop_pattern_length =
668 hop_pattern_length[(int)country];
669 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700670
John Daiker141fa612009-03-10 06:59:54 -0700671 local->sparm.b4.a_network_type = net_type & 0x01;
672 local->sparm.b4.a_acting_as_ap_status = TYPE_STA;
673
674 if (essid != NULL)
675 strncpy(local->sparm.b4.a_current_ess_id, essid, ESSID_SIZE);
676} /* init_startup_params */
677
Linus Torvalds1da177e2005-04-16 15:20:36 -0700678/*===========================================================================*/
679static void verify_dl_startup(u_long data)
680{
John Daiker141fa612009-03-10 06:59:54 -0700681 ray_dev_t *local = (ray_dev_t *) data;
682 struct ccs __iomem *pccs = ccs_base(local) + local->dl_param_ccs;
683 UCHAR status;
684 struct pcmcia_device *link = local->finder;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700685
John Daiker141fa612009-03-10 06:59:54 -0700686 if (!(pcmcia_dev_present(link))) {
Dominik Brodowski624dd662009-10-24 15:52:44 +0200687 dev_dbg(&link->dev, "ray_cs verify_dl_startup - device not present\n");
John Daiker141fa612009-03-10 06:59:54 -0700688 return;
689 }
Dominik Brodowski624dd662009-10-24 15:52:44 +0200690#if 0
691 {
John Daiker141fa612009-03-10 06:59:54 -0700692 int i;
693 printk(KERN_DEBUG
694 "verify_dl_startup parameters sent via ccs %d:\n",
695 local->dl_param_ccs);
696 for (i = 0; i < sizeof(struct b5_startup_params); i++) {
697 printk(" %2x",
698 (unsigned int)readb(local->sram +
699 HOST_TO_ECF_BASE + i));
700 }
701 printk("\n");
702 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700703#endif
704
John Daiker141fa612009-03-10 06:59:54 -0700705 status = readb(&pccs->buffer_status);
706 if (status != CCS_BUFFER_FREE) {
707 printk(KERN_INFO
708 "Download startup params failed. Status = %d\n",
709 status);
710 local->card_status = CARD_DL_PARAM_ERROR;
711 return;
712 }
713 if (local->sparm.b4.a_network_type == ADHOC)
714 start_net((u_long) local);
715 else
716 join_net((u_long) local);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700717} /* end verify_dl_startup */
John Daiker141fa612009-03-10 06:59:54 -0700718
Linus Torvalds1da177e2005-04-16 15:20:36 -0700719/*===========================================================================*/
720/* Command card to start a network */
721static void start_net(u_long data)
722{
John Daiker141fa612009-03-10 06:59:54 -0700723 ray_dev_t *local = (ray_dev_t *) data;
724 struct ccs __iomem *pccs;
725 int ccsindex;
726 struct pcmcia_device *link = local->finder;
727 if (!(pcmcia_dev_present(link))) {
Dominik Brodowski624dd662009-10-24 15:52:44 +0200728 dev_dbg(&link->dev, "ray_cs start_net - device not present\n");
John Daiker141fa612009-03-10 06:59:54 -0700729 return;
730 }
731 /* Fill in the CCS fields for the ECF */
732 if ((ccsindex = get_free_ccs(local)) < 0)
733 return;
734 pccs = ccs_base(local) + ccsindex;
735 writeb(CCS_START_NETWORK, &pccs->cmd);
736 writeb(0, &pccs->var.start_network.update_param);
737 /* Interrupt the firmware to process the command */
738 if (interrupt_ecf(local, ccsindex)) {
Dominik Brodowski624dd662009-10-24 15:52:44 +0200739 dev_dbg(&link->dev, "ray start net failed - card not ready for intr\n");
John Daiker141fa612009-03-10 06:59:54 -0700740 writeb(CCS_BUFFER_FREE, &(pccs++)->buffer_status);
741 return;
742 }
743 local->card_status = CARD_DOING_ACQ;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700744} /* end start_net */
John Daiker141fa612009-03-10 06:59:54 -0700745
Linus Torvalds1da177e2005-04-16 15:20:36 -0700746/*===========================================================================*/
747/* Command card to join a network */
748static void join_net(u_long data)
749{
John Daiker141fa612009-03-10 06:59:54 -0700750 ray_dev_t *local = (ray_dev_t *) data;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700751
John Daiker141fa612009-03-10 06:59:54 -0700752 struct ccs __iomem *pccs;
753 int ccsindex;
754 struct pcmcia_device *link = local->finder;
755
756 if (!(pcmcia_dev_present(link))) {
Dominik Brodowski624dd662009-10-24 15:52:44 +0200757 dev_dbg(&link->dev, "ray_cs join_net - device not present\n");
John Daiker141fa612009-03-10 06:59:54 -0700758 return;
759 }
760 /* Fill in the CCS fields for the ECF */
761 if ((ccsindex = get_free_ccs(local)) < 0)
762 return;
763 pccs = ccs_base(local) + ccsindex;
764 writeb(CCS_JOIN_NETWORK, &pccs->cmd);
765 writeb(0, &pccs->var.join_network.update_param);
766 writeb(0, &pccs->var.join_network.net_initiated);
767 /* Interrupt the firmware to process the command */
768 if (interrupt_ecf(local, ccsindex)) {
Dominik Brodowski624dd662009-10-24 15:52:44 +0200769 dev_dbg(&link->dev, "ray join net failed - card not ready for intr\n");
John Daiker141fa612009-03-10 06:59:54 -0700770 writeb(CCS_BUFFER_FREE, &(pccs++)->buffer_status);
771 return;
772 }
773 local->card_status = CARD_DOING_ACQ;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700774}
John Daiker141fa612009-03-10 06:59:54 -0700775
Linus Torvalds1da177e2005-04-16 15:20:36 -0700776/*============================================================================
777 After a card is removed, ray_release() will unregister the net
778 device, and release the PCMCIA configuration. If the device is
779 still open, this will be postponed until it is closed.
780=============================================================================*/
Dominik Brodowskifba395e2006-03-31 17:21:06 +0200781static void ray_release(struct pcmcia_device *link)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700782{
John Daiker141fa612009-03-10 06:59:54 -0700783 struct net_device *dev = link->priv;
784 ray_dev_t *local = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700785
Dominik Brodowski624dd662009-10-24 15:52:44 +0200786 dev_dbg(&link->dev, "ray_release\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700787
John Daiker141fa612009-03-10 06:59:54 -0700788 del_timer(&local->timer);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700789
John Daiker141fa612009-03-10 06:59:54 -0700790 iounmap(local->sram);
791 iounmap(local->rmem);
792 iounmap(local->amem);
John Daiker141fa612009-03-10 06:59:54 -0700793 pcmcia_disable_device(link);
794
Dominik Brodowski624dd662009-10-24 15:52:44 +0200795 dev_dbg(&link->dev, "ray_release ending\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700796}
797
Dominik Brodowskifba395e2006-03-31 17:21:06 +0200798static int ray_suspend(struct pcmcia_device *link)
Dominik Brodowski98e4c282005-11-14 21:21:18 +0100799{
Dominik Brodowski98e4c282005-11-14 21:21:18 +0100800 struct net_device *dev = link->priv;
801
Dominik Brodowskie2d40962006-03-02 00:09:29 +0100802 if (link->open)
Dominik Brodowski8661bb52006-03-02 00:02:33 +0100803 netif_device_detach(dev);
Dominik Brodowski98e4c282005-11-14 21:21:18 +0100804
805 return 0;
806}
807
Dominik Brodowskifba395e2006-03-31 17:21:06 +0200808static int ray_resume(struct pcmcia_device *link)
Dominik Brodowski98e4c282005-11-14 21:21:18 +0100809{
Dominik Brodowski98e4c282005-11-14 21:21:18 +0100810 struct net_device *dev = link->priv;
811
Dominik Brodowskie2d40962006-03-02 00:09:29 +0100812 if (link->open) {
Dominik Brodowski8661bb52006-03-02 00:02:33 +0100813 ray_reset(dev);
814 netif_device_attach(dev);
815 }
Dominik Brodowski98e4c282005-11-14 21:21:18 +0100816
817 return 0;
818}
819
Linus Torvalds1da177e2005-04-16 15:20:36 -0700820/*===========================================================================*/
Hannes Eder2ed5ba82008-12-26 00:12:59 -0800821static int ray_dev_init(struct net_device *dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700822{
823#ifdef RAY_IMMEDIATE_INIT
John Daiker141fa612009-03-10 06:59:54 -0700824 int i;
825#endif /* RAY_IMMEDIATE_INIT */
826 ray_dev_t *local = netdev_priv(dev);
827 struct pcmcia_device *link = local->finder;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700828
Dominik Brodowski624dd662009-10-24 15:52:44 +0200829 dev_dbg(&link->dev, "ray_dev_init(dev=%p)\n", dev);
John Daiker141fa612009-03-10 06:59:54 -0700830 if (!(pcmcia_dev_present(link))) {
Dominik Brodowski624dd662009-10-24 15:52:44 +0200831 dev_dbg(&link->dev, "ray_dev_init - device not present\n");
John Daiker141fa612009-03-10 06:59:54 -0700832 return -1;
833 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700834#ifdef RAY_IMMEDIATE_INIT
John Daiker141fa612009-03-10 06:59:54 -0700835 /* Download startup parameters */
836 if ((i = dl_startup_params(dev)) < 0) {
837 printk(KERN_INFO "ray_dev_init dl_startup_params failed - "
838 "returns 0x%x\n", i);
839 return -1;
840 }
841#else /* RAY_IMMEDIATE_INIT */
842 /* Postpone the card init so that we can still configure the card,
843 * for example using the Wireless Extensions. The init will happen
844 * in ray_open() - Jean II */
Dominik Brodowski624dd662009-10-24 15:52:44 +0200845 dev_dbg(&link->dev,
John Daiker141fa612009-03-10 06:59:54 -0700846 "ray_dev_init: postponing card init to ray_open() ; Status = %d\n",
847 local->card_status);
848#endif /* RAY_IMMEDIATE_INIT */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700849
John Daiker141fa612009-03-10 06:59:54 -0700850 /* copy mac and broadcast addresses to linux device */
Jiri Pirko3a6d54c2009-05-11 23:37:15 +0000851 memcpy(dev->dev_addr, &local->sparm.b4.a_mac_addr, ADDRLEN);
John Daiker141fa612009-03-10 06:59:54 -0700852 memset(dev->broadcast, 0xff, ETH_ALEN);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700853
Dominik Brodowski624dd662009-10-24 15:52:44 +0200854 dev_dbg(&link->dev, "ray_dev_init ending\n");
John Daiker141fa612009-03-10 06:59:54 -0700855 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700856}
John Daiker141fa612009-03-10 06:59:54 -0700857
Linus Torvalds1da177e2005-04-16 15:20:36 -0700858/*===========================================================================*/
859static int ray_dev_config(struct net_device *dev, struct ifmap *map)
860{
John Daiker141fa612009-03-10 06:59:54 -0700861 ray_dev_t *local = netdev_priv(dev);
862 struct pcmcia_device *link = local->finder;
863 /* Dummy routine to satisfy device structure */
Dominik Brodowski624dd662009-10-24 15:52:44 +0200864 dev_dbg(&link->dev, "ray_dev_config(dev=%p,ifmap=%p)\n", dev, map);
John Daiker141fa612009-03-10 06:59:54 -0700865 if (!(pcmcia_dev_present(link))) {
Dominik Brodowski624dd662009-10-24 15:52:44 +0200866 dev_dbg(&link->dev, "ray_dev_config - device not present\n");
John Daiker141fa612009-03-10 06:59:54 -0700867 return -1;
868 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700869
John Daiker141fa612009-03-10 06:59:54 -0700870 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700871}
John Daiker141fa612009-03-10 06:59:54 -0700872
Linus Torvalds1da177e2005-04-16 15:20:36 -0700873/*===========================================================================*/
Stephen Hemmingerd0cf9c02009-08-31 19:50:57 +0000874static netdev_tx_t ray_dev_start_xmit(struct sk_buff *skb,
875 struct net_device *dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700876{
John Daiker141fa612009-03-10 06:59:54 -0700877 ray_dev_t *local = netdev_priv(dev);
878 struct pcmcia_device *link = local->finder;
879 short length = skb->len;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700880
Stephen Hemmingerd0cf9c02009-08-31 19:50:57 +0000881 if (!pcmcia_dev_present(link)) {
Dominik Brodowski624dd662009-10-24 15:52:44 +0200882 dev_dbg(&link->dev, "ray_dev_start_xmit - device not present\n");
Stephen Hemmingerd0cf9c02009-08-31 19:50:57 +0000883 dev_kfree_skb(skb);
884 return NETDEV_TX_OK;
John Daiker141fa612009-03-10 06:59:54 -0700885 }
Stephen Hemmingerd0cf9c02009-08-31 19:50:57 +0000886
Dominik Brodowski624dd662009-10-24 15:52:44 +0200887 dev_dbg(&link->dev, "ray_dev_start_xmit(skb=%p, dev=%p)\n", skb, dev);
John Daiker141fa612009-03-10 06:59:54 -0700888 if (local->authentication_state == NEED_TO_AUTH) {
Dominik Brodowski624dd662009-10-24 15:52:44 +0200889 dev_dbg(&link->dev, "ray_cs Sending authentication request.\n");
John Daiker141fa612009-03-10 06:59:54 -0700890 if (!build_auth_frame(local, local->auth_id, OPEN_AUTH_REQUEST)) {
891 local->authentication_state = AUTHENTICATED;
892 netif_stop_queue(dev);
Patrick McHardy5b548142009-06-12 06:22:29 +0000893 return NETDEV_TX_BUSY;
John Daiker141fa612009-03-10 06:59:54 -0700894 }
895 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700896
John Daiker141fa612009-03-10 06:59:54 -0700897 if (length < ETH_ZLEN) {
898 if (skb_padto(skb, ETH_ZLEN))
Patrick McHardy6ed10652009-06-23 06:03:08 +0000899 return NETDEV_TX_OK;
John Daiker141fa612009-03-10 06:59:54 -0700900 length = ETH_ZLEN;
901 }
902 switch (ray_hw_xmit(skb->data, length, dev, DATA_TYPE)) {
903 case XMIT_NO_CCS:
904 case XMIT_NEED_AUTH:
905 netif_stop_queue(dev);
Patrick McHardy5b548142009-06-12 06:22:29 +0000906 return NETDEV_TX_BUSY;
John Daiker141fa612009-03-10 06:59:54 -0700907 case XMIT_NO_INTR:
908 case XMIT_MSG_BAD:
909 case XMIT_OK:
910 default:
John Daiker141fa612009-03-10 06:59:54 -0700911 dev_kfree_skb(skb);
John Daiker141fa612009-03-10 06:59:54 -0700912 }
Stephen Hemmingerd0cf9c02009-08-31 19:50:57 +0000913
Patrick McHardy6ed10652009-06-23 06:03:08 +0000914 return NETDEV_TX_OK;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700915} /* ray_dev_start_xmit */
John Daiker141fa612009-03-10 06:59:54 -0700916
Linus Torvalds1da177e2005-04-16 15:20:36 -0700917/*===========================================================================*/
John Daiker141fa612009-03-10 06:59:54 -0700918static int ray_hw_xmit(unsigned char *data, int len, struct net_device *dev,
919 UCHAR msg_type)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700920{
John Daiker141fa612009-03-10 06:59:54 -0700921 ray_dev_t *local = netdev_priv(dev);
922 struct ccs __iomem *pccs;
923 int ccsindex;
924 int offset;
925 struct tx_msg __iomem *ptx; /* Address of xmit buffer in PC space */
926 short int addr; /* Address of xmit buffer in card space */
927
Dominik Brodowski624dd662009-10-24 15:52:44 +0200928 pr_debug("ray_hw_xmit(data=%p, len=%d, dev=%p)\n", data, len, dev);
John Daiker141fa612009-03-10 06:59:54 -0700929 if (len + TX_HEADER_LENGTH > TX_BUF_SIZE) {
930 printk(KERN_INFO "ray_hw_xmit packet too large: %d bytes\n",
931 len);
932 return XMIT_MSG_BAD;
933 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700934 switch (ccsindex = get_free_tx_ccs(local)) {
935 case ECCSBUSY:
Dominik Brodowski624dd662009-10-24 15:52:44 +0200936 pr_debug("ray_hw_xmit tx_ccs table busy\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700937 case ECCSFULL:
Dominik Brodowski624dd662009-10-24 15:52:44 +0200938 pr_debug("ray_hw_xmit No free tx ccs\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700939 case ECARDGONE:
John Daiker141fa612009-03-10 06:59:54 -0700940 netif_stop_queue(dev);
941 return XMIT_NO_CCS;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700942 default:
943 break;
944 }
John Daiker141fa612009-03-10 06:59:54 -0700945 addr = TX_BUF_BASE + (ccsindex << 11);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700946
John Daiker141fa612009-03-10 06:59:54 -0700947 if (msg_type == DATA_TYPE) {
948 local->stats.tx_bytes += len;
949 local->stats.tx_packets++;
950 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700951
John Daiker141fa612009-03-10 06:59:54 -0700952 ptx = local->sram + addr;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700953
John Daiker141fa612009-03-10 06:59:54 -0700954 ray_build_header(local, ptx, msg_type, data);
955 if (translate) {
956 offset = translate_frame(local, ptx, data, len);
957 } else { /* Encapsulate frame */
958 /* TBD TIB length will move address of ptx->var */
959 memcpy_toio(&ptx->var, data, len);
960 offset = 0;
961 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700962
John Daiker141fa612009-03-10 06:59:54 -0700963 /* fill in the CCS */
964 pccs = ccs_base(local) + ccsindex;
965 len += TX_HEADER_LENGTH + offset;
966 writeb(CCS_TX_REQUEST, &pccs->cmd);
967 writeb(addr >> 8, &pccs->var.tx_request.tx_data_ptr[0]);
968 writeb(local->tib_length, &pccs->var.tx_request.tx_data_ptr[1]);
969 writeb(len >> 8, &pccs->var.tx_request.tx_data_length[0]);
970 writeb(len & 0xff, &pccs->var.tx_request.tx_data_length[1]);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700971/* TBD still need psm_cam? */
John Daiker141fa612009-03-10 06:59:54 -0700972 writeb(PSM_CAM, &pccs->var.tx_request.pow_sav_mode);
973 writeb(local->net_default_tx_rate, &pccs->var.tx_request.tx_rate);
974 writeb(0, &pccs->var.tx_request.antenna);
Dominik Brodowski624dd662009-10-24 15:52:44 +0200975 pr_debug("ray_hw_xmit default_tx_rate = 0x%x\n",
John Daiker141fa612009-03-10 06:59:54 -0700976 local->net_default_tx_rate);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700977
John Daiker141fa612009-03-10 06:59:54 -0700978 /* Interrupt the firmware to process the command */
979 if (interrupt_ecf(local, ccsindex)) {
Dominik Brodowski624dd662009-10-24 15:52:44 +0200980 pr_debug("ray_hw_xmit failed - ECF not ready for intr\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700981/* TBD very inefficient to copy packet to buffer, and then not
982 send it, but the alternative is to queue the messages and that
983 won't be done for a while. Maybe set tbusy until a CCS is free?
984*/
John Daiker141fa612009-03-10 06:59:54 -0700985 writeb(CCS_BUFFER_FREE, &pccs->buffer_status);
986 return XMIT_NO_INTR;
987 }
988 return XMIT_OK;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700989} /* end ray_hw_xmit */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700990
John Daiker141fa612009-03-10 06:59:54 -0700991/*===========================================================================*/
992static int translate_frame(ray_dev_t *local, struct tx_msg __iomem *ptx,
993 unsigned char *data, int len)
994{
995 __be16 proto = ((struct ethhdr *)data)->h_proto;
996 if (ntohs(proto) >= 1536) { /* DIX II ethernet frame */
Dominik Brodowski624dd662009-10-24 15:52:44 +0200997 pr_debug("ray_cs translate_frame DIX II\n");
John Daiker141fa612009-03-10 06:59:54 -0700998 /* Copy LLC header to card buffer */
999 memcpy_toio(&ptx->var, eth2_llc, sizeof(eth2_llc));
1000 memcpy_toio(((void __iomem *)&ptx->var) + sizeof(eth2_llc),
1001 (UCHAR *) &proto, 2);
1002 if (proto == htons(ETH_P_AARP) || proto == htons(ETH_P_IPX)) {
1003 /* This is the selective translation table, only 2 entries */
1004 writeb(0xf8,
1005 &((struct snaphdr_t __iomem *)ptx->var)->org[3]);
1006 }
1007 /* Copy body of ethernet packet without ethernet header */
1008 memcpy_toio((void __iomem *)&ptx->var +
1009 sizeof(struct snaphdr_t), data + ETH_HLEN,
1010 len - ETH_HLEN);
1011 return (int)sizeof(struct snaphdr_t) - ETH_HLEN;
1012 } else { /* already 802 type, and proto is length */
Dominik Brodowski624dd662009-10-24 15:52:44 +02001013 pr_debug("ray_cs translate_frame 802\n");
John Daiker141fa612009-03-10 06:59:54 -07001014 if (proto == htons(0xffff)) { /* evil netware IPX 802.3 without LLC */
Dominik Brodowski624dd662009-10-24 15:52:44 +02001015 pr_debug("ray_cs translate_frame evil IPX\n");
John Daiker141fa612009-03-10 06:59:54 -07001016 memcpy_toio(&ptx->var, data + ETH_HLEN, len - ETH_HLEN);
1017 return 0 - ETH_HLEN;
1018 }
1019 memcpy_toio(&ptx->var, data + ETH_HLEN, len - ETH_HLEN);
1020 return 0 - ETH_HLEN;
1021 }
1022 /* TBD do other frame types */
1023} /* end translate_frame */
1024
1025/*===========================================================================*/
1026static void ray_build_header(ray_dev_t *local, struct tx_msg __iomem *ptx,
1027 UCHAR msg_type, unsigned char *data)
1028{
1029 writeb(PROTOCOL_VER | msg_type, &ptx->mac.frame_ctl_1);
1030/*** IEEE 802.11 Address field assignments *************
1031 TODS FROMDS addr_1 addr_2 addr_3 addr_4
1032Adhoc 0 0 dest src (terminal) BSSID N/A
1033AP to Terminal 0 1 dest AP(BSSID) source N/A
1034Terminal to AP 1 0 AP(BSSID) src (terminal) dest N/A
1035AP to AP 1 1 dest AP src AP dest source
1036*******************************************************/
1037 if (local->net_type == ADHOC) {
1038 writeb(0, &ptx->mac.frame_ctl_2);
1039 memcpy_toio(ptx->mac.addr_1, ((struct ethhdr *)data)->h_dest,
1040 2 * ADDRLEN);
1041 memcpy_toio(ptx->mac.addr_3, local->bss_id, ADDRLEN);
1042 } else { /* infrastructure */
1043
1044 if (local->sparm.b4.a_acting_as_ap_status) {
1045 writeb(FC2_FROM_DS, &ptx->mac.frame_ctl_2);
1046 memcpy_toio(ptx->mac.addr_1,
1047 ((struct ethhdr *)data)->h_dest, ADDRLEN);
1048 memcpy_toio(ptx->mac.addr_2, local->bss_id, 6);
1049 memcpy_toio(ptx->mac.addr_3,
1050 ((struct ethhdr *)data)->h_source, ADDRLEN);
1051 } else { /* Terminal */
1052
1053 writeb(FC2_TO_DS, &ptx->mac.frame_ctl_2);
1054 memcpy_toio(ptx->mac.addr_1, local->bss_id, ADDRLEN);
1055 memcpy_toio(ptx->mac.addr_2,
1056 ((struct ethhdr *)data)->h_source, ADDRLEN);
1057 memcpy_toio(ptx->mac.addr_3,
1058 ((struct ethhdr *)data)->h_dest, ADDRLEN);
1059 }
1060 }
1061} /* end encapsulate_frame */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001062
1063/*===========================================================================*/
1064
1065static void netdev_get_drvinfo(struct net_device *dev,
1066 struct ethtool_drvinfo *info)
1067{
1068 strcpy(info->driver, "ray_cs");
1069}
1070
Jeff Garzik7282d492006-09-13 14:30:00 -04001071static const struct ethtool_ops netdev_ethtool_ops = {
John Daiker141fa612009-03-10 06:59:54 -07001072 .get_drvinfo = netdev_get_drvinfo,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001073};
1074
1075/*====================================================================*/
1076
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001077/*------------------------------------------------------------------*/
1078/*
1079 * Wireless Handler : get protocol name
1080 */
Joe Perches43ead782010-03-18 18:29:40 -07001081static int ray_get_name(struct net_device *dev, struct iw_request_info *info,
1082 union iwreq_data *wrqu, char *extra)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001083{
Joe Perches43ead782010-03-18 18:29:40 -07001084 strcpy(wrqu->name, "IEEE 802.11-FH");
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001085 return 0;
1086}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001087
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001088/*------------------------------------------------------------------*/
1089/*
1090 * Wireless Handler : set frequency
1091 */
Joe Perches43ead782010-03-18 18:29:40 -07001092static int ray_set_freq(struct net_device *dev, struct iw_request_info *info,
1093 union iwreq_data *wrqu, char *extra)
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001094{
Yoann Padioleau6dbc9c82007-08-03 19:37:16 +02001095 ray_dev_t *local = netdev_priv(dev);
John Daiker141fa612009-03-10 06:59:54 -07001096 int err = -EINPROGRESS; /* Call commit handler */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001097
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001098 /* Reject if card is already initialised */
John Daiker141fa612009-03-10 06:59:54 -07001099 if (local->card_status != CARD_AWAITING_PARAM)
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001100 return -EBUSY;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001101
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001102 /* Setting by channel number */
Joe Perches43ead782010-03-18 18:29:40 -07001103 if ((wrqu->freq.m > USA_HOP_MOD) || (wrqu->freq.e > 0))
Linus Torvalds1da177e2005-04-16 15:20:36 -07001104 err = -EOPNOTSUPP;
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001105 else
Joe Perches43ead782010-03-18 18:29:40 -07001106 local->sparm.b5.a_hop_pattern = wrqu->freq.m;
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001107
1108 return err;
1109}
John Daiker141fa612009-03-10 06:59:54 -07001110
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001111/*------------------------------------------------------------------*/
1112/*
1113 * Wireless Handler : get frequency
1114 */
Joe Perches43ead782010-03-18 18:29:40 -07001115static int ray_get_freq(struct net_device *dev, struct iw_request_info *info,
1116 union iwreq_data *wrqu, char *extra)
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001117{
Yoann Padioleau6dbc9c82007-08-03 19:37:16 +02001118 ray_dev_t *local = netdev_priv(dev);
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001119
Joe Perches43ead782010-03-18 18:29:40 -07001120 wrqu->freq.m = local->sparm.b5.a_hop_pattern;
1121 wrqu->freq.e = 0;
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001122 return 0;
1123}
1124
1125/*------------------------------------------------------------------*/
1126/*
1127 * Wireless Handler : set ESSID
1128 */
Joe Perches43ead782010-03-18 18:29:40 -07001129static int ray_set_essid(struct net_device *dev, struct iw_request_info *info,
1130 union iwreq_data *wrqu, char *extra)
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001131{
Yoann Padioleau6dbc9c82007-08-03 19:37:16 +02001132 ray_dev_t *local = netdev_priv(dev);
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001133
1134 /* Reject if card is already initialised */
John Daiker141fa612009-03-10 06:59:54 -07001135 if (local->card_status != CARD_AWAITING_PARAM)
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001136 return -EBUSY;
1137
1138 /* Check if we asked for `any' */
Joe Perches43ead782010-03-18 18:29:40 -07001139 if (wrqu->essid.flags == 0)
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001140 /* Corey : can you do that ? */
1141 return -EOPNOTSUPP;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001142
Joe Perches43ead782010-03-18 18:29:40 -07001143 /* Check the size of the string */
1144 if (wrqu->essid.length > IW_ESSID_MAX_SIZE)
1145 return -E2BIG;
1146
1147 /* Set the ESSID in the card */
1148 memset(local->sparm.b5.a_current_ess_id, 0, IW_ESSID_MAX_SIZE);
1149 memcpy(local->sparm.b5.a_current_ess_id, extra, wrqu->essid.length);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001150
John Daiker141fa612009-03-10 06:59:54 -07001151 return -EINPROGRESS; /* Call commit handler */
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001152}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001153
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001154/*------------------------------------------------------------------*/
1155/*
1156 * Wireless Handler : get ESSID
1157 */
Joe Perches43ead782010-03-18 18:29:40 -07001158static int ray_get_essid(struct net_device *dev, struct iw_request_info *info,
1159 union iwreq_data *wrqu, char *extra)
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001160{
Yoann Padioleau6dbc9c82007-08-03 19:37:16 +02001161 ray_dev_t *local = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001162
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001163 /* Get the essid that was set */
1164 memcpy(extra, local->sparm.b5.a_current_ess_id, IW_ESSID_MAX_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001165
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001166 /* Push it out ! */
Joe Perches43ead782010-03-18 18:29:40 -07001167 wrqu->essid.length = strlen(extra);
1168 wrqu->essid.flags = 1; /* active */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001169
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001170 return 0;
1171}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001172
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001173/*------------------------------------------------------------------*/
1174/*
1175 * Wireless Handler : get AP address
1176 */
Joe Perches43ead782010-03-18 18:29:40 -07001177static int ray_get_wap(struct net_device *dev, struct iw_request_info *info,
1178 union iwreq_data *wrqu, char *extra)
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001179{
Yoann Padioleau6dbc9c82007-08-03 19:37:16 +02001180 ray_dev_t *local = netdev_priv(dev);
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001181
Joe Perches43ead782010-03-18 18:29:40 -07001182 memcpy(wrqu->ap_addr.sa_data, local->bss_id, ETH_ALEN);
1183 wrqu->ap_addr.sa_family = ARPHRD_ETHER;
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001184
1185 return 0;
1186}
1187
1188/*------------------------------------------------------------------*/
1189/*
1190 * Wireless Handler : set Bit-Rate
1191 */
Joe Perches43ead782010-03-18 18:29:40 -07001192static int ray_set_rate(struct net_device *dev, struct iw_request_info *info,
1193 union iwreq_data *wrqu, char *extra)
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001194{
Yoann Padioleau6dbc9c82007-08-03 19:37:16 +02001195 ray_dev_t *local = netdev_priv(dev);
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001196
1197 /* Reject if card is already initialised */
John Daiker141fa612009-03-10 06:59:54 -07001198 if (local->card_status != CARD_AWAITING_PARAM)
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001199 return -EBUSY;
1200
1201 /* Check if rate is in range */
Joe Perches43ead782010-03-18 18:29:40 -07001202 if ((wrqu->bitrate.value != 1000000) && (wrqu->bitrate.value != 2000000))
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001203 return -EINVAL;
1204
1205 /* Hack for 1.5 Mb/s instead of 2 Mb/s */
John Daiker141fa612009-03-10 06:59:54 -07001206 if ((local->fw_ver == 0x55) && /* Please check */
Joe Perches43ead782010-03-18 18:29:40 -07001207 (wrqu->bitrate.value == 2000000))
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001208 local->net_default_tx_rate = 3;
1209 else
Joe Perches43ead782010-03-18 18:29:40 -07001210 local->net_default_tx_rate = wrqu->bitrate.value / 500000;
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001211
1212 return 0;
1213}
1214
1215/*------------------------------------------------------------------*/
1216/*
1217 * Wireless Handler : get Bit-Rate
1218 */
Joe Perches43ead782010-03-18 18:29:40 -07001219static int ray_get_rate(struct net_device *dev, struct iw_request_info *info,
1220 union iwreq_data *wrqu, char *extra)
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001221{
Yoann Padioleau6dbc9c82007-08-03 19:37:16 +02001222 ray_dev_t *local = netdev_priv(dev);
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001223
John Daiker141fa612009-03-10 06:59:54 -07001224 if (local->net_default_tx_rate == 3)
Joe Perches43ead782010-03-18 18:29:40 -07001225 wrqu->bitrate.value = 2000000; /* Hum... */
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001226 else
Joe Perches43ead782010-03-18 18:29:40 -07001227 wrqu->bitrate.value = local->net_default_tx_rate * 500000;
1228 wrqu->bitrate.fixed = 0; /* We are in auto mode */
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001229
1230 return 0;
1231}
1232
1233/*------------------------------------------------------------------*/
1234/*
1235 * Wireless Handler : set RTS threshold
1236 */
Joe Perches43ead782010-03-18 18:29:40 -07001237static int ray_set_rts(struct net_device *dev, struct iw_request_info *info,
1238 union iwreq_data *wrqu, char *extra)
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001239{
Yoann Padioleau6dbc9c82007-08-03 19:37:16 +02001240 ray_dev_t *local = netdev_priv(dev);
Joe Perches43ead782010-03-18 18:29:40 -07001241 int rthr = wrqu->rts.value;
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001242
1243 /* Reject if card is already initialised */
John Daiker141fa612009-03-10 06:59:54 -07001244 if (local->card_status != CARD_AWAITING_PARAM)
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001245 return -EBUSY;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001246
1247 /* if(wrq->u.rts.fixed == 0) we should complain */
Joe Perches43ead782010-03-18 18:29:40 -07001248 if (wrqu->rts.disabled)
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001249 rthr = 32767;
1250 else {
John Daiker141fa612009-03-10 06:59:54 -07001251 if ((rthr < 0) || (rthr > 2347)) /* What's the max packet size ??? */
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001252 return -EINVAL;
1253 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001254 local->sparm.b5.a_rts_threshold[0] = (rthr >> 8) & 0xFF;
1255 local->sparm.b5.a_rts_threshold[1] = rthr & 0xFF;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001256
John Daiker141fa612009-03-10 06:59:54 -07001257 return -EINPROGRESS; /* Call commit handler */
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001258}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001259
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001260/*------------------------------------------------------------------*/
1261/*
1262 * Wireless Handler : get RTS threshold
1263 */
Joe Perches43ead782010-03-18 18:29:40 -07001264static int ray_get_rts(struct net_device *dev, struct iw_request_info *info,
1265 union iwreq_data *wrqu, char *extra)
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001266{
Yoann Padioleau6dbc9c82007-08-03 19:37:16 +02001267 ray_dev_t *local = netdev_priv(dev);
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001268
Joe Perches43ead782010-03-18 18:29:40 -07001269 wrqu->rts.value = (local->sparm.b5.a_rts_threshold[0] << 8)
John Daiker141fa612009-03-10 06:59:54 -07001270 + local->sparm.b5.a_rts_threshold[1];
Joe Perches43ead782010-03-18 18:29:40 -07001271 wrqu->rts.disabled = (wrqu->rts.value == 32767);
1272 wrqu->rts.fixed = 1;
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001273
1274 return 0;
1275}
1276
1277/*------------------------------------------------------------------*/
1278/*
1279 * Wireless Handler : set Fragmentation threshold
1280 */
Joe Perches43ead782010-03-18 18:29:40 -07001281static int ray_set_frag(struct net_device *dev, struct iw_request_info *info,
1282 union iwreq_data *wrqu, char *extra)
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001283{
Yoann Padioleau6dbc9c82007-08-03 19:37:16 +02001284 ray_dev_t *local = netdev_priv(dev);
Joe Perches43ead782010-03-18 18:29:40 -07001285 int fthr = wrqu->frag.value;
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001286
1287 /* Reject if card is already initialised */
John Daiker141fa612009-03-10 06:59:54 -07001288 if (local->card_status != CARD_AWAITING_PARAM)
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001289 return -EBUSY;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001290
1291 /* if(wrq->u.frag.fixed == 0) should complain */
Joe Perches43ead782010-03-18 18:29:40 -07001292 if (wrqu->frag.disabled)
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001293 fthr = 32767;
1294 else {
John Daiker141fa612009-03-10 06:59:54 -07001295 if ((fthr < 256) || (fthr > 2347)) /* To check out ! */
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001296 return -EINVAL;
1297 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001298 local->sparm.b5.a_frag_threshold[0] = (fthr >> 8) & 0xFF;
1299 local->sparm.b5.a_frag_threshold[1] = fthr & 0xFF;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001300
John Daiker141fa612009-03-10 06:59:54 -07001301 return -EINPROGRESS; /* Call commit handler */
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001302}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001303
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001304/*------------------------------------------------------------------*/
1305/*
1306 * Wireless Handler : get Fragmentation threshold
1307 */
Joe Perches43ead782010-03-18 18:29:40 -07001308static int ray_get_frag(struct net_device *dev, struct iw_request_info *info,
1309 union iwreq_data *wrqu, char *extra)
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001310{
Yoann Padioleau6dbc9c82007-08-03 19:37:16 +02001311 ray_dev_t *local = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001312
Joe Perches43ead782010-03-18 18:29:40 -07001313 wrqu->frag.value = (local->sparm.b5.a_frag_threshold[0] << 8)
John Daiker141fa612009-03-10 06:59:54 -07001314 + local->sparm.b5.a_frag_threshold[1];
Joe Perches43ead782010-03-18 18:29:40 -07001315 wrqu->frag.disabled = (wrqu->frag.value == 32767);
1316 wrqu->frag.fixed = 1;
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001317
1318 return 0;
1319}
1320
1321/*------------------------------------------------------------------*/
1322/*
1323 * Wireless Handler : set Mode of Operation
1324 */
Joe Perches43ead782010-03-18 18:29:40 -07001325static int ray_set_mode(struct net_device *dev, struct iw_request_info *info,
1326 union iwreq_data *wrqu, char *extra)
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001327{
Yoann Padioleau6dbc9c82007-08-03 19:37:16 +02001328 ray_dev_t *local = netdev_priv(dev);
John Daiker141fa612009-03-10 06:59:54 -07001329 int err = -EINPROGRESS; /* Call commit handler */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001330 char card_mode = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001331
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001332 /* Reject if card is already initialised */
John Daiker141fa612009-03-10 06:59:54 -07001333 if (local->card_status != CARD_AWAITING_PARAM)
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001334 return -EBUSY;
1335
Joe Perches43ead782010-03-18 18:29:40 -07001336 switch (wrqu->mode) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001337 case IW_MODE_ADHOC:
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001338 card_mode = 0;
John Daiker141fa612009-03-10 06:59:54 -07001339 /* Fall through */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001340 case IW_MODE_INFRA:
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001341 local->sparm.b5.a_network_type = card_mode;
1342 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001343 default:
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001344 err = -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001345 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001346
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001347 return err;
1348}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001349
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001350/*------------------------------------------------------------------*/
1351/*
1352 * Wireless Handler : get Mode of Operation
1353 */
Joe Perches43ead782010-03-18 18:29:40 -07001354static int ray_get_mode(struct net_device *dev, struct iw_request_info *info,
1355 union iwreq_data *wrqu, char *extra)
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001356{
Yoann Padioleau6dbc9c82007-08-03 19:37:16 +02001357 ray_dev_t *local = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001358
John Daiker141fa612009-03-10 06:59:54 -07001359 if (local->sparm.b5.a_network_type)
Joe Perches43ead782010-03-18 18:29:40 -07001360 wrqu->mode = IW_MODE_INFRA;
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001361 else
Joe Perches43ead782010-03-18 18:29:40 -07001362 wrqu->mode = IW_MODE_ADHOC;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001363
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001364 return 0;
1365}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001366
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001367/*------------------------------------------------------------------*/
1368/*
1369 * Wireless Handler : get range info
1370 */
Joe Perches43ead782010-03-18 18:29:40 -07001371static int ray_get_range(struct net_device *dev, struct iw_request_info *info,
1372 union iwreq_data *wrqu, char *extra)
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001373{
John Daiker141fa612009-03-10 06:59:54 -07001374 struct iw_range *range = (struct iw_range *)extra;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001375
Joe Perches43ead782010-03-18 18:29:40 -07001376 memset(range, 0, sizeof(struct iw_range));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001377
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001378 /* Set the length (very important for backward compatibility) */
Joe Perches43ead782010-03-18 18:29:40 -07001379 wrqu->data.length = sizeof(struct iw_range);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001380
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001381 /* Set the Wireless Extension versions */
1382 range->we_version_compiled = WIRELESS_EXT;
1383 range->we_version_source = 9;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001384
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001385 /* Set information in the range struct */
1386 range->throughput = 1.1 * 1000 * 1000; /* Put the right number here */
John Daiker141fa612009-03-10 06:59:54 -07001387 range->num_channels = hop_pattern_length[(int)country];
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001388 range->num_frequency = 0;
1389 range->max_qual.qual = 0;
1390 range->max_qual.level = 255; /* What's the correct value ? */
1391 range->max_qual.noise = 255; /* Idem */
1392 range->num_bitrates = 2;
1393 range->bitrate[0] = 1000000; /* 1 Mb/s */
1394 range->bitrate[1] = 2000000; /* 2 Mb/s */
1395 return 0;
1396}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001397
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001398/*------------------------------------------------------------------*/
1399/*
1400 * Wireless Private Handler : set framing mode
1401 */
Joe Perches43ead782010-03-18 18:29:40 -07001402static int ray_set_framing(struct net_device *dev, struct iw_request_info *info,
John Daiker141fa612009-03-10 06:59:54 -07001403 union iwreq_data *wrqu, char *extra)
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001404{
1405 translate = *(extra); /* Set framing mode */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001406
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001407 return 0;
1408}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001409
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001410/*------------------------------------------------------------------*/
1411/*
1412 * Wireless Private Handler : get framing mode
1413 */
Joe Perches43ead782010-03-18 18:29:40 -07001414static int ray_get_framing(struct net_device *dev, struct iw_request_info *info,
John Daiker141fa612009-03-10 06:59:54 -07001415 union iwreq_data *wrqu, char *extra)
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001416{
1417 *(extra) = translate;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001418
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001419 return 0;
1420}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001421
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001422/*------------------------------------------------------------------*/
1423/*
1424 * Wireless Private Handler : get country
1425 */
Joe Perches43ead782010-03-18 18:29:40 -07001426static int ray_get_country(struct net_device *dev, struct iw_request_info *info,
John Daiker141fa612009-03-10 06:59:54 -07001427 union iwreq_data *wrqu, char *extra)
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001428{
1429 *(extra) = country;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001430
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001431 return 0;
1432}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001433
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001434/*------------------------------------------------------------------*/
1435/*
1436 * Commit handler : called after a bunch of SET operations
1437 */
Joe Perches43ead782010-03-18 18:29:40 -07001438static int ray_commit(struct net_device *dev, struct iw_request_info *info,
1439 union iwreq_data *wrqu, char *extra)
1440{
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001441 return 0;
1442}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001443
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001444/*------------------------------------------------------------------*/
1445/*
1446 * Stats handler : return Wireless Stats
1447 */
John Daiker141fa612009-03-10 06:59:54 -07001448static iw_stats *ray_get_wireless_stats(struct net_device *dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001449{
John Daiker141fa612009-03-10 06:59:54 -07001450 ray_dev_t *local = netdev_priv(dev);
1451 struct pcmcia_device *link = local->finder;
1452 struct status __iomem *p = local->sram + STATUS_BASE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001453
John Daiker141fa612009-03-10 06:59:54 -07001454 local->wstats.status = local->card_status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001455#ifdef WIRELESS_SPY
John Daiker141fa612009-03-10 06:59:54 -07001456 if ((local->spy_data.spy_number > 0)
1457 && (local->sparm.b5.a_network_type == 0)) {
1458 /* Get it from the first node in spy list */
1459 local->wstats.qual.qual = local->spy_data.spy_stat[0].qual;
1460 local->wstats.qual.level = local->spy_data.spy_stat[0].level;
1461 local->wstats.qual.noise = local->spy_data.spy_stat[0].noise;
1462 local->wstats.qual.updated =
1463 local->spy_data.spy_stat[0].updated;
1464 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001465#endif /* WIRELESS_SPY */
1466
John Daiker141fa612009-03-10 06:59:54 -07001467 if (pcmcia_dev_present(link)) {
1468 local->wstats.qual.noise = readb(&p->rxnoise);
1469 local->wstats.qual.updated |= 4;
1470 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001471
John Daiker141fa612009-03-10 06:59:54 -07001472 return &local->wstats;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001473} /* end ray_get_wireless_stats */
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001474
1475/*------------------------------------------------------------------*/
1476/*
1477 * Structures to export the Wireless Handlers
1478 */
1479
John Daiker141fa612009-03-10 06:59:54 -07001480static const iw_handler ray_handler[] = {
Joe Perches43ead782010-03-18 18:29:40 -07001481 IW_HANDLER(SIOCSIWCOMMIT, ray_commit),
1482 IW_HANDLER(SIOCGIWNAME, ray_get_name),
1483 IW_HANDLER(SIOCSIWFREQ, ray_set_freq),
1484 IW_HANDLER(SIOCGIWFREQ, ray_get_freq),
1485 IW_HANDLER(SIOCSIWMODE, ray_set_mode),
1486 IW_HANDLER(SIOCGIWMODE, ray_get_mode),
1487 IW_HANDLER(SIOCGIWRANGE, ray_get_range),
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001488#ifdef WIRELESS_SPY
Joe Perches270020e2010-03-18 18:29:37 -07001489 IW_HANDLER(SIOCSIWSPY, iw_handler_set_spy),
1490 IW_HANDLER(SIOCGIWSPY, iw_handler_get_spy),
1491 IW_HANDLER(SIOCSIWTHRSPY, iw_handler_set_thrspy),
1492 IW_HANDLER(SIOCGIWTHRSPY, iw_handler_get_thrspy),
John Daiker141fa612009-03-10 06:59:54 -07001493#endif /* WIRELESS_SPY */
Joe Perches43ead782010-03-18 18:29:40 -07001494 IW_HANDLER(SIOCGIWAP, ray_get_wap),
1495 IW_HANDLER(SIOCSIWESSID, ray_set_essid),
1496 IW_HANDLER(SIOCGIWESSID, ray_get_essid),
1497 IW_HANDLER(SIOCSIWRATE, ray_set_rate),
1498 IW_HANDLER(SIOCGIWRATE, ray_get_rate),
1499 IW_HANDLER(SIOCSIWRTS, ray_set_rts),
1500 IW_HANDLER(SIOCGIWRTS, ray_get_rts),
1501 IW_HANDLER(SIOCSIWFRAG, ray_set_frag),
1502 IW_HANDLER(SIOCGIWFRAG, ray_get_frag),
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001503};
1504
John Daiker141fa612009-03-10 06:59:54 -07001505#define SIOCSIPFRAMING SIOCIWFIRSTPRIV /* Set framing mode */
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001506#define SIOCGIPFRAMING SIOCIWFIRSTPRIV + 1 /* Get framing mode */
1507#define SIOCGIPCOUNTRY SIOCIWFIRSTPRIV + 3 /* Get country code */
1508
John Daiker141fa612009-03-10 06:59:54 -07001509static const iw_handler ray_private_handler[] = {
Joe Perches43ead782010-03-18 18:29:40 -07001510 [0] = ray_set_framing,
1511 [1] = ray_get_framing,
1512 [3] = ray_get_country,
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001513};
1514
John Daiker141fa612009-03-10 06:59:54 -07001515static const struct iw_priv_args ray_private_args[] = {
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001516/* cmd, set_args, get_args, name */
John Daiker141fa612009-03-10 06:59:54 -07001517 {SIOCSIPFRAMING, IW_PRIV_TYPE_BYTE | IW_PRIV_SIZE_FIXED | 1, 0,
1518 "set_framing"},
1519 {SIOCGIPFRAMING, 0, IW_PRIV_TYPE_BYTE | IW_PRIV_SIZE_FIXED | 1,
1520 "get_framing"},
1521 {SIOCGIPCOUNTRY, 0, IW_PRIV_TYPE_BYTE | IW_PRIV_SIZE_FIXED | 1,
1522 "get_country"},
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001523};
1524
John Daiker141fa612009-03-10 06:59:54 -07001525static const struct iw_handler_def ray_handler_def = {
1526 .num_standard = ARRAY_SIZE(ray_handler),
1527 .num_private = ARRAY_SIZE(ray_private_handler),
Denis Chengff8ac602007-09-02 18:30:18 +08001528 .num_private_args = ARRAY_SIZE(ray_private_args),
John Daiker141fa612009-03-10 06:59:54 -07001529 .standard = ray_handler,
1530 .private = ray_private_handler,
1531 .private_args = ray_private_args,
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001532 .get_wireless_stats = ray_get_wireless_stats,
1533};
1534
Linus Torvalds1da177e2005-04-16 15:20:36 -07001535/*===========================================================================*/
1536static int ray_open(struct net_device *dev)
1537{
John Daiker141fa612009-03-10 06:59:54 -07001538 ray_dev_t *local = netdev_priv(dev);
1539 struct pcmcia_device *link;
1540 link = local->finder;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001541
Dominik Brodowski624dd662009-10-24 15:52:44 +02001542 dev_dbg(&link->dev, "ray_open('%s')\n", dev->name);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001543
John Daiker141fa612009-03-10 06:59:54 -07001544 if (link->open == 0)
1545 local->num_multi = 0;
1546 link->open++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001547
John Daiker141fa612009-03-10 06:59:54 -07001548 /* If the card is not started, time to start it ! - Jean II */
1549 if (local->card_status == CARD_AWAITING_PARAM) {
1550 int i;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001551
Dominik Brodowski624dd662009-10-24 15:52:44 +02001552 dev_dbg(&link->dev, "ray_open: doing init now !\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001553
John Daiker141fa612009-03-10 06:59:54 -07001554 /* Download startup parameters */
1555 if ((i = dl_startup_params(dev)) < 0) {
1556 printk(KERN_INFO
1557 "ray_dev_init dl_startup_params failed - "
1558 "returns 0x%x\n", i);
1559 return -1;
1560 }
1561 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001562
John Daiker141fa612009-03-10 06:59:54 -07001563 if (sniffer)
1564 netif_stop_queue(dev);
1565 else
1566 netif_start_queue(dev);
1567
Dominik Brodowski624dd662009-10-24 15:52:44 +02001568 dev_dbg(&link->dev, "ray_open ending\n");
John Daiker141fa612009-03-10 06:59:54 -07001569 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001570} /* end ray_open */
John Daiker141fa612009-03-10 06:59:54 -07001571
Linus Torvalds1da177e2005-04-16 15:20:36 -07001572/*===========================================================================*/
1573static int ray_dev_close(struct net_device *dev)
1574{
John Daiker141fa612009-03-10 06:59:54 -07001575 ray_dev_t *local = netdev_priv(dev);
1576 struct pcmcia_device *link;
1577 link = local->finder;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001578
Dominik Brodowski624dd662009-10-24 15:52:44 +02001579 dev_dbg(&link->dev, "ray_dev_close('%s')\n", dev->name);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001580
John Daiker141fa612009-03-10 06:59:54 -07001581 link->open--;
1582 netif_stop_queue(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001583
John Daiker141fa612009-03-10 06:59:54 -07001584 /* In here, we should stop the hardware (stop card from beeing active)
1585 * and set local->card_status to CARD_AWAITING_PARAM, so that while the
1586 * card is closed we can chage its configuration.
1587 * Probably also need a COR reset to get sane state - Jean II */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001588
John Daiker141fa612009-03-10 06:59:54 -07001589 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001590} /* end ray_dev_close */
John Daiker141fa612009-03-10 06:59:54 -07001591
Linus Torvalds1da177e2005-04-16 15:20:36 -07001592/*===========================================================================*/
John Daiker141fa612009-03-10 06:59:54 -07001593static void ray_reset(struct net_device *dev)
1594{
Dominik Brodowski624dd662009-10-24 15:52:44 +02001595 pr_debug("ray_reset entered\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001596}
John Daiker141fa612009-03-10 06:59:54 -07001597
Linus Torvalds1da177e2005-04-16 15:20:36 -07001598/*===========================================================================*/
1599/* Cause a firmware interrupt if it is ready for one */
1600/* Return nonzero if not ready */
1601static int interrupt_ecf(ray_dev_t *local, int ccs)
1602{
John Daiker141fa612009-03-10 06:59:54 -07001603 int i = 50;
1604 struct pcmcia_device *link = local->finder;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001605
John Daiker141fa612009-03-10 06:59:54 -07001606 if (!(pcmcia_dev_present(link))) {
Dominik Brodowski624dd662009-10-24 15:52:44 +02001607 dev_dbg(&link->dev, "ray_cs interrupt_ecf - device not present\n");
John Daiker141fa612009-03-10 06:59:54 -07001608 return -1;
1609 }
Dominik Brodowski624dd662009-10-24 15:52:44 +02001610 dev_dbg(&link->dev, "interrupt_ecf(local=%p, ccs = 0x%x\n", local, ccs);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001611
John Daiker141fa612009-03-10 06:59:54 -07001612 while (i &&
1613 (readb(local->amem + CIS_OFFSET + ECF_INTR_OFFSET) &
1614 ECF_INTR_SET))
1615 i--;
1616 if (i == 0) {
Dominik Brodowski624dd662009-10-24 15:52:44 +02001617 dev_dbg(&link->dev, "ray_cs interrupt_ecf card not ready for interrupt\n");
John Daiker141fa612009-03-10 06:59:54 -07001618 return -1;
1619 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001620 /* Fill the mailbox, then kick the card */
John Daiker141fa612009-03-10 06:59:54 -07001621 writeb(ccs, local->sram + SCB_BASE);
1622 writeb(ECF_INTR_SET, local->amem + CIS_OFFSET + ECF_INTR_OFFSET);
1623 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001624} /* interrupt_ecf */
John Daiker141fa612009-03-10 06:59:54 -07001625
Linus Torvalds1da177e2005-04-16 15:20:36 -07001626/*===========================================================================*/
1627/* Get next free transmit CCS */
1628/* Return - index of current tx ccs */
1629static int get_free_tx_ccs(ray_dev_t *local)
1630{
John Daiker141fa612009-03-10 06:59:54 -07001631 int i;
1632 struct ccs __iomem *pccs = ccs_base(local);
1633 struct pcmcia_device *link = local->finder;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001634
John Daiker141fa612009-03-10 06:59:54 -07001635 if (!(pcmcia_dev_present(link))) {
Dominik Brodowski624dd662009-10-24 15:52:44 +02001636 dev_dbg(&link->dev, "ray_cs get_free_tx_ccs - device not present\n");
John Daiker141fa612009-03-10 06:59:54 -07001637 return ECARDGONE;
1638 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001639
John Daiker141fa612009-03-10 06:59:54 -07001640 if (test_and_set_bit(0, &local->tx_ccs_lock)) {
Dominik Brodowski624dd662009-10-24 15:52:44 +02001641 dev_dbg(&link->dev, "ray_cs tx_ccs_lock busy\n");
John Daiker141fa612009-03-10 06:59:54 -07001642 return ECCSBUSY;
1643 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001644
John Daiker141fa612009-03-10 06:59:54 -07001645 for (i = 0; i < NUMBER_OF_TX_CCS; i++) {
1646 if (readb(&(pccs + i)->buffer_status) == CCS_BUFFER_FREE) {
1647 writeb(CCS_BUFFER_BUSY, &(pccs + i)->buffer_status);
1648 writeb(CCS_END_LIST, &(pccs + i)->link);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001649 local->tx_ccs_lock = 0;
John Daiker141fa612009-03-10 06:59:54 -07001650 return i;
1651 }
1652 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001653 local->tx_ccs_lock = 0;
Dominik Brodowski624dd662009-10-24 15:52:44 +02001654 dev_dbg(&link->dev, "ray_cs ERROR no free tx CCS for raylink card\n");
John Daiker141fa612009-03-10 06:59:54 -07001655 return ECCSFULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001656} /* get_free_tx_ccs */
John Daiker141fa612009-03-10 06:59:54 -07001657
Linus Torvalds1da177e2005-04-16 15:20:36 -07001658/*===========================================================================*/
1659/* Get next free CCS */
1660/* Return - index of current ccs */
1661static int get_free_ccs(ray_dev_t *local)
1662{
John Daiker141fa612009-03-10 06:59:54 -07001663 int i;
1664 struct ccs __iomem *pccs = ccs_base(local);
1665 struct pcmcia_device *link = local->finder;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001666
John Daiker141fa612009-03-10 06:59:54 -07001667 if (!(pcmcia_dev_present(link))) {
Dominik Brodowski624dd662009-10-24 15:52:44 +02001668 dev_dbg(&link->dev, "ray_cs get_free_ccs - device not present\n");
John Daiker141fa612009-03-10 06:59:54 -07001669 return ECARDGONE;
1670 }
1671 if (test_and_set_bit(0, &local->ccs_lock)) {
Dominik Brodowski624dd662009-10-24 15:52:44 +02001672 dev_dbg(&link->dev, "ray_cs ccs_lock busy\n");
John Daiker141fa612009-03-10 06:59:54 -07001673 return ECCSBUSY;
1674 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001675
John Daiker141fa612009-03-10 06:59:54 -07001676 for (i = NUMBER_OF_TX_CCS; i < NUMBER_OF_CCS; i++) {
1677 if (readb(&(pccs + i)->buffer_status) == CCS_BUFFER_FREE) {
1678 writeb(CCS_BUFFER_BUSY, &(pccs + i)->buffer_status);
1679 writeb(CCS_END_LIST, &(pccs + i)->link);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001680 local->ccs_lock = 0;
John Daiker141fa612009-03-10 06:59:54 -07001681 return i;
1682 }
1683 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001684 local->ccs_lock = 0;
Dominik Brodowski624dd662009-10-24 15:52:44 +02001685 dev_dbg(&link->dev, "ray_cs ERROR no free CCS for raylink card\n");
John Daiker141fa612009-03-10 06:59:54 -07001686 return ECCSFULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001687} /* get_free_ccs */
John Daiker141fa612009-03-10 06:59:54 -07001688
Linus Torvalds1da177e2005-04-16 15:20:36 -07001689/*===========================================================================*/
1690static void authenticate_timeout(u_long data)
1691{
John Daiker141fa612009-03-10 06:59:54 -07001692 ray_dev_t *local = (ray_dev_t *) data;
1693 del_timer(&local->timer);
1694 printk(KERN_INFO "ray_cs Authentication with access point failed"
1695 " - timeout\n");
1696 join_net((u_long) local);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001697}
John Daiker141fa612009-03-10 06:59:54 -07001698
Linus Torvalds1da177e2005-04-16 15:20:36 -07001699/*===========================================================================*/
Linus Torvalds1da177e2005-04-16 15:20:36 -07001700static int parse_addr(char *in_str, UCHAR *out)
1701{
John Daiker141fa612009-03-10 06:59:54 -07001702 int len;
1703 int i, j, k;
1704 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001705
John Daiker141fa612009-03-10 06:59:54 -07001706 if (in_str == NULL)
1707 return 0;
1708 if ((len = strlen(in_str)) < 2)
1709 return 0;
1710 memset(out, 0, ADDRLEN);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001711
John Daiker141fa612009-03-10 06:59:54 -07001712 status = 1;
1713 j = len - 1;
1714 if (j > 12)
1715 j = 12;
1716 i = 5;
1717
1718 while (j > 0) {
Andy Shevchenko882d8292010-07-23 03:18:09 +00001719 if ((k = hex_to_bin(in_str[j--])) != -1)
John Daiker141fa612009-03-10 06:59:54 -07001720 out[i] = k;
1721 else
1722 return 0;
1723
1724 if (j == 0)
1725 break;
Andy Shevchenko882d8292010-07-23 03:18:09 +00001726 if ((k = hex_to_bin(in_str[j--])) != -1)
John Daiker141fa612009-03-10 06:59:54 -07001727 out[i] += k << 4;
1728 else
1729 return 0;
1730 if (!i--)
1731 break;
1732 }
1733 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001734}
John Daiker141fa612009-03-10 06:59:54 -07001735
Linus Torvalds1da177e2005-04-16 15:20:36 -07001736/*===========================================================================*/
1737static struct net_device_stats *ray_get_stats(struct net_device *dev)
1738{
John Daiker141fa612009-03-10 06:59:54 -07001739 ray_dev_t *local = netdev_priv(dev);
1740 struct pcmcia_device *link = local->finder;
1741 struct status __iomem *p = local->sram + STATUS_BASE;
1742 if (!(pcmcia_dev_present(link))) {
Dominik Brodowski624dd662009-10-24 15:52:44 +02001743 dev_dbg(&link->dev, "ray_cs net_device_stats - device not present\n");
John Daiker141fa612009-03-10 06:59:54 -07001744 return &local->stats;
1745 }
1746 if (readb(&p->mrx_overflow_for_host)) {
1747 local->stats.rx_over_errors += swab16(readw(&p->mrx_overflow));
1748 writeb(0, &p->mrx_overflow);
1749 writeb(0, &p->mrx_overflow_for_host);
1750 }
1751 if (readb(&p->mrx_checksum_error_for_host)) {
1752 local->stats.rx_crc_errors +=
1753 swab16(readw(&p->mrx_checksum_error));
1754 writeb(0, &p->mrx_checksum_error);
1755 writeb(0, &p->mrx_checksum_error_for_host);
1756 }
1757 if (readb(&p->rx_hec_error_for_host)) {
1758 local->stats.rx_frame_errors += swab16(readw(&p->rx_hec_error));
1759 writeb(0, &p->rx_hec_error);
1760 writeb(0, &p->rx_hec_error_for_host);
1761 }
1762 return &local->stats;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001763}
John Daiker141fa612009-03-10 06:59:54 -07001764
Linus Torvalds1da177e2005-04-16 15:20:36 -07001765/*===========================================================================*/
John Daiker141fa612009-03-10 06:59:54 -07001766static void ray_update_parm(struct net_device *dev, UCHAR objid, UCHAR *value,
1767 int len)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001768{
John Daiker141fa612009-03-10 06:59:54 -07001769 ray_dev_t *local = netdev_priv(dev);
1770 struct pcmcia_device *link = local->finder;
1771 int ccsindex;
1772 int i;
1773 struct ccs __iomem *pccs;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001774
John Daiker141fa612009-03-10 06:59:54 -07001775 if (!(pcmcia_dev_present(link))) {
Dominik Brodowski624dd662009-10-24 15:52:44 +02001776 dev_dbg(&link->dev, "ray_update_parm - device not present\n");
John Daiker141fa612009-03-10 06:59:54 -07001777 return;
1778 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001779
John Daiker141fa612009-03-10 06:59:54 -07001780 if ((ccsindex = get_free_ccs(local)) < 0) {
Dominik Brodowski624dd662009-10-24 15:52:44 +02001781 dev_dbg(&link->dev, "ray_update_parm - No free ccs\n");
John Daiker141fa612009-03-10 06:59:54 -07001782 return;
1783 }
1784 pccs = ccs_base(local) + ccsindex;
1785 writeb(CCS_UPDATE_PARAMS, &pccs->cmd);
1786 writeb(objid, &pccs->var.update_param.object_id);
1787 writeb(1, &pccs->var.update_param.number_objects);
1788 writeb(0, &pccs->var.update_param.failure_cause);
1789 for (i = 0; i < len; i++) {
1790 writeb(value[i], local->sram + HOST_TO_ECF_BASE);
1791 }
1792 /* Interrupt the firmware to process the command */
1793 if (interrupt_ecf(local, ccsindex)) {
Dominik Brodowski624dd662009-10-24 15:52:44 +02001794 dev_dbg(&link->dev, "ray_cs associate failed - ECF not ready for intr\n");
John Daiker141fa612009-03-10 06:59:54 -07001795 writeb(CCS_BUFFER_FREE, &(pccs++)->buffer_status);
1796 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001797}
John Daiker141fa612009-03-10 06:59:54 -07001798
Linus Torvalds1da177e2005-04-16 15:20:36 -07001799/*===========================================================================*/
1800static void ray_update_multi_list(struct net_device *dev, int all)
1801{
John Daiker141fa612009-03-10 06:59:54 -07001802 int ccsindex;
1803 struct ccs __iomem *pccs;
John Daiker141fa612009-03-10 06:59:54 -07001804 ray_dev_t *local = netdev_priv(dev);
1805 struct pcmcia_device *link = local->finder;
1806 void __iomem *p = local->sram + HOST_TO_ECF_BASE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001807
John Daiker141fa612009-03-10 06:59:54 -07001808 if (!(pcmcia_dev_present(link))) {
Dominik Brodowski624dd662009-10-24 15:52:44 +02001809 dev_dbg(&link->dev, "ray_update_multi_list - device not present\n");
John Daiker141fa612009-03-10 06:59:54 -07001810 return;
1811 } else
Dominik Brodowski624dd662009-10-24 15:52:44 +02001812 dev_dbg(&link->dev, "ray_update_multi_list(%p)\n", dev);
John Daiker141fa612009-03-10 06:59:54 -07001813 if ((ccsindex = get_free_ccs(local)) < 0) {
Dominik Brodowski624dd662009-10-24 15:52:44 +02001814 dev_dbg(&link->dev, "ray_update_multi - No free ccs\n");
John Daiker141fa612009-03-10 06:59:54 -07001815 return;
1816 }
1817 pccs = ccs_base(local) + ccsindex;
1818 writeb(CCS_UPDATE_MULTICAST_LIST, &pccs->cmd);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001819
John Daiker141fa612009-03-10 06:59:54 -07001820 if (all) {
1821 writeb(0xff, &pccs->var);
1822 local->num_multi = 0xff;
1823 } else {
Jiri Pirko22bedad32010-04-01 21:22:57 +00001824 struct netdev_hw_addr *ha;
Jiri Pirko655ffee2010-02-27 07:35:45 +00001825 int i = 0;
1826
John Daiker141fa612009-03-10 06:59:54 -07001827 /* Copy the kernel's list of MC addresses to card */
Jiri Pirko22bedad32010-04-01 21:22:57 +00001828 netdev_for_each_mc_addr(ha, dev) {
1829 memcpy_toio(p, ha->addr, ETH_ALEN);
Dominik Brodowski624dd662009-10-24 15:52:44 +02001830 dev_dbg(&link->dev,
John Daiker141fa612009-03-10 06:59:54 -07001831 "ray_update_multi add addr %02x%02x%02x%02x%02x%02x\n",
Jiri Pirko22bedad32010-04-01 21:22:57 +00001832 ha->addr[0], ha->addr[1],
1833 ha->addr[2], ha->addr[3],
1834 ha->addr[4], ha->addr[5]);
John Daiker141fa612009-03-10 06:59:54 -07001835 p += ETH_ALEN;
1836 i++;
1837 }
1838 if (i > 256 / ADDRLEN)
1839 i = 256 / ADDRLEN;
1840 writeb((UCHAR) i, &pccs->var);
Dominik Brodowski624dd662009-10-24 15:52:44 +02001841 dev_dbg(&link->dev, "ray_cs update_multi %d addresses in list\n", i);
John Daiker141fa612009-03-10 06:59:54 -07001842 /* Interrupt the firmware to process the command */
1843 local->num_multi = i;
1844 }
1845 if (interrupt_ecf(local, ccsindex)) {
Dominik Brodowski624dd662009-10-24 15:52:44 +02001846 dev_dbg(&link->dev,
John Daiker141fa612009-03-10 06:59:54 -07001847 "ray_cs update_multi failed - ECF not ready for intr\n");
1848 writeb(CCS_BUFFER_FREE, &(pccs++)->buffer_status);
1849 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001850} /* end ray_update_multi_list */
John Daiker141fa612009-03-10 06:59:54 -07001851
Linus Torvalds1da177e2005-04-16 15:20:36 -07001852/*===========================================================================*/
1853static void set_multicast_list(struct net_device *dev)
1854{
John Daiker141fa612009-03-10 06:59:54 -07001855 ray_dev_t *local = netdev_priv(dev);
1856 UCHAR promisc;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001857
Dominik Brodowski624dd662009-10-24 15:52:44 +02001858 pr_debug("ray_cs set_multicast_list(%p)\n", dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001859
John Daiker141fa612009-03-10 06:59:54 -07001860 if (dev->flags & IFF_PROMISC) {
1861 if (local->sparm.b5.a_promiscuous_mode == 0) {
Dominik Brodowski624dd662009-10-24 15:52:44 +02001862 pr_debug("ray_cs set_multicast_list promisc on\n");
John Daiker141fa612009-03-10 06:59:54 -07001863 local->sparm.b5.a_promiscuous_mode = 1;
1864 promisc = 1;
1865 ray_update_parm(dev, OBJID_promiscuous_mode,
1866 &promisc, sizeof(promisc));
1867 }
1868 } else {
1869 if (local->sparm.b5.a_promiscuous_mode == 1) {
Dominik Brodowski624dd662009-10-24 15:52:44 +02001870 pr_debug("ray_cs set_multicast_list promisc off\n");
John Daiker141fa612009-03-10 06:59:54 -07001871 local->sparm.b5.a_promiscuous_mode = 0;
1872 promisc = 0;
1873 ray_update_parm(dev, OBJID_promiscuous_mode,
1874 &promisc, sizeof(promisc));
1875 }
1876 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001877
John Daiker141fa612009-03-10 06:59:54 -07001878 if (dev->flags & IFF_ALLMULTI)
1879 ray_update_multi_list(dev, 1);
1880 else {
Jiri Pirko4cd24ea2010-02-08 04:30:35 +00001881 if (local->num_multi != netdev_mc_count(dev))
John Daiker141fa612009-03-10 06:59:54 -07001882 ray_update_multi_list(dev, 0);
1883 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001884} /* end set_multicast_list */
John Daiker141fa612009-03-10 06:59:54 -07001885
Linus Torvalds1da177e2005-04-16 15:20:36 -07001886/*=============================================================================
1887 * All routines below here are run at interrupt time.
1888=============================================================================*/
David Howells7d12e782006-10-05 14:55:46 +01001889static irqreturn_t ray_interrupt(int irq, void *dev_id)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001890{
John Daiker141fa612009-03-10 06:59:54 -07001891 struct net_device *dev = (struct net_device *)dev_id;
1892 struct pcmcia_device *link;
1893 ray_dev_t *local;
1894 struct ccs __iomem *pccs;
1895 struct rcs __iomem *prcs;
1896 UCHAR rcsindex;
1897 UCHAR tmp;
1898 UCHAR cmd;
1899 UCHAR status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001900
John Daiker141fa612009-03-10 06:59:54 -07001901 if (dev == NULL) /* Note that we want interrupts with dev->start == 0 */
1902 return IRQ_NONE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001903
Dominik Brodowski624dd662009-10-24 15:52:44 +02001904 pr_debug("ray_cs: interrupt for *dev=%p\n", dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001905
John Daiker141fa612009-03-10 06:59:54 -07001906 local = netdev_priv(dev);
1907 link = (struct pcmcia_device *)local->finder;
1908 if (!pcmcia_dev_present(link)) {
Dominik Brodowski624dd662009-10-24 15:52:44 +02001909 pr_debug(
1910 "ray_cs interrupt from device not present or suspended.\n");
John Daiker141fa612009-03-10 06:59:54 -07001911 return IRQ_NONE;
1912 }
1913 rcsindex = readb(&((struct scb __iomem *)(local->sram))->rcs_index);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001914
John Daiker141fa612009-03-10 06:59:54 -07001915 if (rcsindex >= (NUMBER_OF_CCS + NUMBER_OF_RCS)) {
Dominik Brodowski624dd662009-10-24 15:52:44 +02001916 dev_dbg(&link->dev, "ray_cs interrupt bad rcsindex = 0x%x\n", rcsindex);
John Daiker141fa612009-03-10 06:59:54 -07001917 clear_interrupt(local);
1918 return IRQ_HANDLED;
1919 }
1920 if (rcsindex < NUMBER_OF_CCS) { /* If it's a returned CCS */
1921 pccs = ccs_base(local) + rcsindex;
1922 cmd = readb(&pccs->cmd);
1923 status = readb(&pccs->buffer_status);
1924 switch (cmd) {
1925 case CCS_DOWNLOAD_STARTUP_PARAMS: /* Happens in firmware someday */
1926 del_timer(&local->timer);
1927 if (status == CCS_COMMAND_COMPLETE) {
Dominik Brodowski624dd662009-10-24 15:52:44 +02001928 dev_dbg(&link->dev,
John Daiker141fa612009-03-10 06:59:54 -07001929 "ray_cs interrupt download_startup_parameters OK\n");
1930 } else {
Dominik Brodowski624dd662009-10-24 15:52:44 +02001931 dev_dbg(&link->dev,
John Daiker141fa612009-03-10 06:59:54 -07001932 "ray_cs interrupt download_startup_parameters fail\n");
1933 }
1934 break;
1935 case CCS_UPDATE_PARAMS:
Dominik Brodowski624dd662009-10-24 15:52:44 +02001936 dev_dbg(&link->dev, "ray_cs interrupt update params done\n");
John Daiker141fa612009-03-10 06:59:54 -07001937 if (status != CCS_COMMAND_COMPLETE) {
1938 tmp =
1939 readb(&pccs->var.update_param.
1940 failure_cause);
Dominik Brodowski624dd662009-10-24 15:52:44 +02001941 dev_dbg(&link->dev,
John Daiker141fa612009-03-10 06:59:54 -07001942 "ray_cs interrupt update params failed - reason %d\n",
1943 tmp);
1944 }
1945 break;
1946 case CCS_REPORT_PARAMS:
Dominik Brodowski624dd662009-10-24 15:52:44 +02001947 dev_dbg(&link->dev, "ray_cs interrupt report params done\n");
John Daiker141fa612009-03-10 06:59:54 -07001948 break;
1949 case CCS_UPDATE_MULTICAST_LIST: /* Note that this CCS isn't returned */
Dominik Brodowski624dd662009-10-24 15:52:44 +02001950 dev_dbg(&link->dev,
John Daiker141fa612009-03-10 06:59:54 -07001951 "ray_cs interrupt CCS Update Multicast List done\n");
1952 break;
1953 case CCS_UPDATE_POWER_SAVINGS_MODE:
Dominik Brodowski624dd662009-10-24 15:52:44 +02001954 dev_dbg(&link->dev,
John Daiker141fa612009-03-10 06:59:54 -07001955 "ray_cs interrupt update power save mode done\n");
1956 break;
1957 case CCS_START_NETWORK:
1958 case CCS_JOIN_NETWORK:
1959 if (status == CCS_COMMAND_COMPLETE) {
1960 if (readb
1961 (&pccs->var.start_network.net_initiated) ==
1962 1) {
Dominik Brodowski624dd662009-10-24 15:52:44 +02001963 dev_dbg(&link->dev,
John Daiker141fa612009-03-10 06:59:54 -07001964 "ray_cs interrupt network \"%s\" started\n",
1965 local->sparm.b4.a_current_ess_id);
1966 } else {
Dominik Brodowski624dd662009-10-24 15:52:44 +02001967 dev_dbg(&link->dev,
John Daiker141fa612009-03-10 06:59:54 -07001968 "ray_cs interrupt network \"%s\" joined\n",
1969 local->sparm.b4.a_current_ess_id);
1970 }
1971 memcpy_fromio(&local->bss_id,
1972 pccs->var.start_network.bssid,
1973 ADDRLEN);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001974
John Daiker141fa612009-03-10 06:59:54 -07001975 if (local->fw_ver == 0x55)
1976 local->net_default_tx_rate = 3;
1977 else
1978 local->net_default_tx_rate =
1979 readb(&pccs->var.start_network.
1980 net_default_tx_rate);
1981 local->encryption =
1982 readb(&pccs->var.start_network.encryption);
1983 if (!sniffer && (local->net_type == INFRA)
1984 && !(local->sparm.b4.a_acting_as_ap_status)) {
1985 authenticate(local);
1986 }
1987 local->card_status = CARD_ACQ_COMPLETE;
1988 } else {
1989 local->card_status = CARD_ACQ_FAILED;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001990
John Daiker141fa612009-03-10 06:59:54 -07001991 del_timer(&local->timer);
1992 local->timer.expires = jiffies + HZ * 5;
1993 local->timer.data = (long)local;
1994 if (status == CCS_START_NETWORK) {
Dominik Brodowski624dd662009-10-24 15:52:44 +02001995 dev_dbg(&link->dev,
John Daiker141fa612009-03-10 06:59:54 -07001996 "ray_cs interrupt network \"%s\" start failed\n",
1997 local->sparm.b4.a_current_ess_id);
1998 local->timer.function = &start_net;
1999 } else {
Dominik Brodowski624dd662009-10-24 15:52:44 +02002000 dev_dbg(&link->dev,
John Daiker141fa612009-03-10 06:59:54 -07002001 "ray_cs interrupt network \"%s\" join failed\n",
2002 local->sparm.b4.a_current_ess_id);
2003 local->timer.function = &join_net;
2004 }
2005 add_timer(&local->timer);
2006 }
2007 break;
2008 case CCS_START_ASSOCIATION:
2009 if (status == CCS_COMMAND_COMPLETE) {
2010 local->card_status = CARD_ASSOC_COMPLETE;
Dominik Brodowski624dd662009-10-24 15:52:44 +02002011 dev_dbg(&link->dev, "ray_cs association successful\n");
John Daiker141fa612009-03-10 06:59:54 -07002012 } else {
Dominik Brodowski624dd662009-10-24 15:52:44 +02002013 dev_dbg(&link->dev, "ray_cs association failed,\n");
John Daiker141fa612009-03-10 06:59:54 -07002014 local->card_status = CARD_ASSOC_FAILED;
2015 join_net((u_long) local);
2016 }
2017 break;
2018 case CCS_TX_REQUEST:
2019 if (status == CCS_COMMAND_COMPLETE) {
Dominik Brodowski624dd662009-10-24 15:52:44 +02002020 dev_dbg(&link->dev,
John Daiker141fa612009-03-10 06:59:54 -07002021 "ray_cs interrupt tx request complete\n");
2022 } else {
Dominik Brodowski624dd662009-10-24 15:52:44 +02002023 dev_dbg(&link->dev,
John Daiker141fa612009-03-10 06:59:54 -07002024 "ray_cs interrupt tx request failed\n");
2025 }
2026 if (!sniffer)
2027 netif_start_queue(dev);
2028 netif_wake_queue(dev);
2029 break;
2030 case CCS_TEST_MEMORY:
Dominik Brodowski624dd662009-10-24 15:52:44 +02002031 dev_dbg(&link->dev, "ray_cs interrupt mem test done\n");
John Daiker141fa612009-03-10 06:59:54 -07002032 break;
2033 case CCS_SHUTDOWN:
Dominik Brodowski624dd662009-10-24 15:52:44 +02002034 dev_dbg(&link->dev,
John Daiker141fa612009-03-10 06:59:54 -07002035 "ray_cs interrupt Unexpected CCS returned - Shutdown\n");
2036 break;
2037 case CCS_DUMP_MEMORY:
Dominik Brodowski624dd662009-10-24 15:52:44 +02002038 dev_dbg(&link->dev, "ray_cs interrupt dump memory done\n");
John Daiker141fa612009-03-10 06:59:54 -07002039 break;
2040 case CCS_START_TIMER:
Dominik Brodowski624dd662009-10-24 15:52:44 +02002041 dev_dbg(&link->dev,
John Daiker141fa612009-03-10 06:59:54 -07002042 "ray_cs interrupt DING - raylink timer expired\n");
2043 break;
2044 default:
Dominik Brodowski624dd662009-10-24 15:52:44 +02002045 dev_dbg(&link->dev,
John Daiker141fa612009-03-10 06:59:54 -07002046 "ray_cs interrupt Unexpected CCS 0x%x returned 0x%x\n",
2047 rcsindex, cmd);
2048 }
2049 writeb(CCS_BUFFER_FREE, &pccs->buffer_status);
2050 } else { /* It's an RCS */
2051
2052 prcs = rcs_base(local) + rcsindex;
2053
2054 switch (readb(&prcs->interrupt_id)) {
2055 case PROCESS_RX_PACKET:
2056 ray_rx(dev, local, prcs);
2057 break;
2058 case REJOIN_NET_COMPLETE:
Dominik Brodowski624dd662009-10-24 15:52:44 +02002059 dev_dbg(&link->dev, "ray_cs interrupt rejoin net complete\n");
John Daiker141fa612009-03-10 06:59:54 -07002060 local->card_status = CARD_ACQ_COMPLETE;
2061 /* do we need to clear tx buffers CCS's? */
2062 if (local->sparm.b4.a_network_type == ADHOC) {
2063 if (!sniffer)
2064 netif_start_queue(dev);
2065 } else {
2066 memcpy_fromio(&local->bss_id,
2067 prcs->var.rejoin_net_complete.
2068 bssid, ADDRLEN);
Dominik Brodowski624dd662009-10-24 15:52:44 +02002069 dev_dbg(&link->dev,
John Daiker141fa612009-03-10 06:59:54 -07002070 "ray_cs new BSSID = %02x%02x%02x%02x%02x%02x\n",
2071 local->bss_id[0], local->bss_id[1],
2072 local->bss_id[2], local->bss_id[3],
2073 local->bss_id[4], local->bss_id[5]);
2074 if (!sniffer)
2075 authenticate(local);
2076 }
2077 break;
2078 case ROAMING_INITIATED:
Dominik Brodowski624dd662009-10-24 15:52:44 +02002079 dev_dbg(&link->dev, "ray_cs interrupt roaming initiated\n");
John Daiker141fa612009-03-10 06:59:54 -07002080 netif_stop_queue(dev);
2081 local->card_status = CARD_DOING_ACQ;
2082 break;
2083 case JAPAN_CALL_SIGN_RXD:
Dominik Brodowski624dd662009-10-24 15:52:44 +02002084 dev_dbg(&link->dev, "ray_cs interrupt japan call sign rx\n");
John Daiker141fa612009-03-10 06:59:54 -07002085 break;
2086 default:
Dominik Brodowski624dd662009-10-24 15:52:44 +02002087 dev_dbg(&link->dev,
John Daiker141fa612009-03-10 06:59:54 -07002088 "ray_cs Unexpected interrupt for RCS 0x%x cmd = 0x%x\n",
2089 rcsindex,
2090 (unsigned int)readb(&prcs->interrupt_id));
2091 break;
2092 }
2093 writeb(CCS_BUFFER_FREE, &prcs->buffer_status);
2094 }
2095 clear_interrupt(local);
2096 return IRQ_HANDLED;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002097} /* ray_interrupt */
John Daiker141fa612009-03-10 06:59:54 -07002098
Linus Torvalds1da177e2005-04-16 15:20:36 -07002099/*===========================================================================*/
John Daiker141fa612009-03-10 06:59:54 -07002100static void ray_rx(struct net_device *dev, ray_dev_t *local,
2101 struct rcs __iomem *prcs)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002102{
John Daiker141fa612009-03-10 06:59:54 -07002103 int rx_len;
2104 unsigned int pkt_addr;
2105 void __iomem *pmsg;
Dominik Brodowski624dd662009-10-24 15:52:44 +02002106 pr_debug("ray_rx process rx packet\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002107
John Daiker141fa612009-03-10 06:59:54 -07002108 /* Calculate address of packet within Rx buffer */
2109 pkt_addr = ((readb(&prcs->var.rx_packet.rx_data_ptr[0]) << 8)
2110 + readb(&prcs->var.rx_packet.rx_data_ptr[1])) & RX_BUFF_END;
2111 /* Length of first packet fragment */
2112 rx_len = (readb(&prcs->var.rx_packet.rx_data_length[0]) << 8)
2113 + readb(&prcs->var.rx_packet.rx_data_length[1]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002114
John Daiker141fa612009-03-10 06:59:54 -07002115 local->last_rsl = readb(&prcs->var.rx_packet.rx_sig_lev);
2116 pmsg = local->rmem + pkt_addr;
2117 switch (readb(pmsg)) {
2118 case DATA_TYPE:
Dominik Brodowski624dd662009-10-24 15:52:44 +02002119 pr_debug("ray_rx data type\n");
John Daiker141fa612009-03-10 06:59:54 -07002120 rx_data(dev, prcs, pkt_addr, rx_len);
2121 break;
2122 case AUTHENTIC_TYPE:
Dominik Brodowski624dd662009-10-24 15:52:44 +02002123 pr_debug("ray_rx authentic type\n");
John Daiker141fa612009-03-10 06:59:54 -07002124 if (sniffer)
2125 rx_data(dev, prcs, pkt_addr, rx_len);
2126 else
2127 rx_authenticate(local, prcs, pkt_addr, rx_len);
2128 break;
2129 case DEAUTHENTIC_TYPE:
Dominik Brodowski624dd662009-10-24 15:52:44 +02002130 pr_debug("ray_rx deauth type\n");
John Daiker141fa612009-03-10 06:59:54 -07002131 if (sniffer)
2132 rx_data(dev, prcs, pkt_addr, rx_len);
2133 else
2134 rx_deauthenticate(local, prcs, pkt_addr, rx_len);
2135 break;
2136 case NULL_MSG_TYPE:
Dominik Brodowski624dd662009-10-24 15:52:44 +02002137 pr_debug("ray_cs rx NULL msg\n");
John Daiker141fa612009-03-10 06:59:54 -07002138 break;
2139 case BEACON_TYPE:
Dominik Brodowski624dd662009-10-24 15:52:44 +02002140 pr_debug("ray_rx beacon type\n");
John Daiker141fa612009-03-10 06:59:54 -07002141 if (sniffer)
2142 rx_data(dev, prcs, pkt_addr, rx_len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002143
John Daiker141fa612009-03-10 06:59:54 -07002144 copy_from_rx_buff(local, (UCHAR *) &local->last_bcn, pkt_addr,
2145 rx_len < sizeof(struct beacon_rx) ?
2146 rx_len : sizeof(struct beacon_rx));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002147
John Daiker141fa612009-03-10 06:59:54 -07002148 local->beacon_rxed = 1;
2149 /* Get the statistics so the card counters never overflow */
2150 ray_get_stats(dev);
2151 break;
2152 default:
Dominik Brodowski624dd662009-10-24 15:52:44 +02002153 pr_debug("ray_cs unknown pkt type %2x\n",
John Daiker141fa612009-03-10 06:59:54 -07002154 (unsigned int)readb(pmsg));
2155 break;
2156 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002157
2158} /* end ray_rx */
John Daiker141fa612009-03-10 06:59:54 -07002159
Linus Torvalds1da177e2005-04-16 15:20:36 -07002160/*===========================================================================*/
John Daiker141fa612009-03-10 06:59:54 -07002161static void rx_data(struct net_device *dev, struct rcs __iomem *prcs,
2162 unsigned int pkt_addr, int rx_len)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002163{
John Daiker141fa612009-03-10 06:59:54 -07002164 struct sk_buff *skb = NULL;
2165 struct rcs __iomem *prcslink = prcs;
2166 ray_dev_t *local = netdev_priv(dev);
2167 UCHAR *rx_ptr;
2168 int total_len;
2169 int tmp;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002170#ifdef WIRELESS_SPY
John Daiker141fa612009-03-10 06:59:54 -07002171 int siglev = local->last_rsl;
2172 u_char linksrcaddr[ETH_ALEN]; /* Other end of the wireless link */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002173#endif
2174
John Daiker141fa612009-03-10 06:59:54 -07002175 if (!sniffer) {
2176 if (translate) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002177/* TBD length needs fixing for translated header */
John Daiker141fa612009-03-10 06:59:54 -07002178 if (rx_len < (ETH_HLEN + RX_MAC_HEADER_LENGTH) ||
2179 rx_len >
2180 (dev->mtu + RX_MAC_HEADER_LENGTH + ETH_HLEN +
2181 FCS_LEN)) {
Dominik Brodowski624dd662009-10-24 15:52:44 +02002182 pr_debug(
Frans Popcb01b092010-03-24 19:46:34 +01002183 "ray_cs invalid packet length %d received\n",
John Daiker141fa612009-03-10 06:59:54 -07002184 rx_len);
2185 return;
2186 }
2187 } else { /* encapsulated ethernet */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002188
John Daiker141fa612009-03-10 06:59:54 -07002189 if (rx_len < (ETH_HLEN + RX_MAC_HEADER_LENGTH) ||
2190 rx_len >
2191 (dev->mtu + RX_MAC_HEADER_LENGTH + ETH_HLEN +
2192 FCS_LEN)) {
Dominik Brodowski624dd662009-10-24 15:52:44 +02002193 pr_debug(
Frans Popcb01b092010-03-24 19:46:34 +01002194 "ray_cs invalid packet length %d received\n",
John Daiker141fa612009-03-10 06:59:54 -07002195 rx_len);
2196 return;
2197 }
2198 }
2199 }
Dominik Brodowski624dd662009-10-24 15:52:44 +02002200 pr_debug("ray_cs rx_data packet\n");
John Daiker141fa612009-03-10 06:59:54 -07002201 /* If fragmented packet, verify sizes of fragments add up */
2202 if (readb(&prcs->var.rx_packet.next_frag_rcs_index) != 0xFF) {
Dominik Brodowski624dd662009-10-24 15:52:44 +02002203 pr_debug("ray_cs rx'ed fragment\n");
John Daiker141fa612009-03-10 06:59:54 -07002204 tmp = (readb(&prcs->var.rx_packet.totalpacketlength[0]) << 8)
2205 + readb(&prcs->var.rx_packet.totalpacketlength[1]);
2206 total_len = tmp;
2207 prcslink = prcs;
2208 do {
2209 tmp -=
2210 (readb(&prcslink->var.rx_packet.rx_data_length[0])
2211 << 8)
2212 + readb(&prcslink->var.rx_packet.rx_data_length[1]);
2213 if (readb(&prcslink->var.rx_packet.next_frag_rcs_index)
2214 == 0xFF || tmp < 0)
2215 break;
2216 prcslink = rcs_base(local)
2217 + readb(&prcslink->link_field);
2218 } while (1);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002219
John Daiker141fa612009-03-10 06:59:54 -07002220 if (tmp < 0) {
Dominik Brodowski624dd662009-10-24 15:52:44 +02002221 pr_debug(
John Daiker141fa612009-03-10 06:59:54 -07002222 "ray_cs rx_data fragment lengths don't add up\n");
2223 local->stats.rx_dropped++;
2224 release_frag_chain(local, prcs);
2225 return;
2226 }
2227 } else { /* Single unfragmented packet */
2228 total_len = rx_len;
2229 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002230
John Daiker141fa612009-03-10 06:59:54 -07002231 skb = dev_alloc_skb(total_len + 5);
2232 if (skb == NULL) {
Dominik Brodowski624dd662009-10-24 15:52:44 +02002233 pr_debug("ray_cs rx_data could not allocate skb\n");
John Daiker141fa612009-03-10 06:59:54 -07002234 local->stats.rx_dropped++;
2235 if (readb(&prcs->var.rx_packet.next_frag_rcs_index) != 0xFF)
2236 release_frag_chain(local, prcs);
2237 return;
2238 }
2239 skb_reserve(skb, 2); /* Align IP on 16 byte (TBD check this) */
2240
Dominik Brodowski624dd662009-10-24 15:52:44 +02002241 pr_debug("ray_cs rx_data total_len = %x, rx_len = %x\n", total_len,
John Daiker141fa612009-03-10 06:59:54 -07002242 rx_len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002243
2244/************************/
John Daiker141fa612009-03-10 06:59:54 -07002245 /* Reserve enough room for the whole damn packet. */
2246 rx_ptr = skb_put(skb, total_len);
2247 /* Copy the whole packet to sk_buff */
2248 rx_ptr +=
2249 copy_from_rx_buff(local, rx_ptr, pkt_addr & RX_BUFF_END, rx_len);
2250 /* Get source address */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002251#ifdef WIRELESS_SPY
John Daiker141fa612009-03-10 06:59:54 -07002252 skb_copy_from_linear_data_offset(skb,
2253 offsetof(struct mac_header, addr_2),
2254 linksrcaddr, ETH_ALEN);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002255#endif
John Daiker141fa612009-03-10 06:59:54 -07002256 /* Now, deal with encapsulation/translation/sniffer */
2257 if (!sniffer) {
2258 if (!translate) {
2259 /* Encapsulated ethernet, so just lop off 802.11 MAC header */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002260/* TBD reserve skb_reserve( skb, RX_MAC_HEADER_LENGTH); */
John Daiker141fa612009-03-10 06:59:54 -07002261 skb_pull(skb, RX_MAC_HEADER_LENGTH);
2262 } else {
2263 /* Do translation */
2264 untranslate(local, skb, total_len);
2265 }
2266 } else { /* sniffer mode, so just pass whole packet */
2267 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002268
2269/************************/
John Daiker141fa612009-03-10 06:59:54 -07002270 /* Now pick up the rest of the fragments if any */
2271 tmp = 17;
2272 if (readb(&prcs->var.rx_packet.next_frag_rcs_index) != 0xFF) {
2273 prcslink = prcs;
Dominik Brodowski624dd662009-10-24 15:52:44 +02002274 pr_debug("ray_cs rx_data in fragment loop\n");
John Daiker141fa612009-03-10 06:59:54 -07002275 do {
2276 prcslink = rcs_base(local)
2277 +
2278 readb(&prcslink->var.rx_packet.next_frag_rcs_index);
2279 rx_len =
2280 ((readb(&prcslink->var.rx_packet.rx_data_length[0])
2281 << 8)
2282 +
2283 readb(&prcslink->var.rx_packet.rx_data_length[1]))
2284 & RX_BUFF_END;
2285 pkt_addr =
2286 ((readb(&prcslink->var.rx_packet.rx_data_ptr[0]) <<
2287 8)
2288 + readb(&prcslink->var.rx_packet.rx_data_ptr[1]))
2289 & RX_BUFF_END;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002290
John Daiker141fa612009-03-10 06:59:54 -07002291 rx_ptr +=
2292 copy_from_rx_buff(local, rx_ptr, pkt_addr, rx_len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002293
John Daiker141fa612009-03-10 06:59:54 -07002294 } while (tmp-- &&
2295 readb(&prcslink->var.rx_packet.next_frag_rcs_index) !=
2296 0xFF);
2297 release_frag_chain(local, prcs);
2298 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002299
John Daiker141fa612009-03-10 06:59:54 -07002300 skb->protocol = eth_type_trans(skb, dev);
2301 netif_rx(skb);
2302 local->stats.rx_packets++;
2303 local->stats.rx_bytes += total_len;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002304
John Daiker141fa612009-03-10 06:59:54 -07002305 /* Gather signal strength per address */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002306#ifdef WIRELESS_SPY
John Daiker141fa612009-03-10 06:59:54 -07002307 /* For the Access Point or the node having started the ad-hoc net
2308 * note : ad-hoc work only in some specific configurations, but we
2309 * kludge in ray_get_wireless_stats... */
2310 if (!memcmp(linksrcaddr, local->bss_id, ETH_ALEN)) {
2311 /* Update statistics */
2312 /*local->wstats.qual.qual = none ? */
2313 local->wstats.qual.level = siglev;
2314 /*local->wstats.qual.noise = none ? */
2315 local->wstats.qual.updated = 0x2;
2316 }
2317 /* Now, update the spy stuff */
2318 {
2319 struct iw_quality wstats;
2320 wstats.level = siglev;
2321 /* wstats.noise = none ? */
2322 /* wstats.qual = none ? */
2323 wstats.updated = 0x2;
2324 /* Update spy records */
2325 wireless_spy_update(dev, linksrcaddr, &wstats);
2326 }
2327#endif /* WIRELESS_SPY */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002328} /* end rx_data */
John Daiker141fa612009-03-10 06:59:54 -07002329
Linus Torvalds1da177e2005-04-16 15:20:36 -07002330/*===========================================================================*/
2331static void untranslate(ray_dev_t *local, struct sk_buff *skb, int len)
2332{
John Daiker141fa612009-03-10 06:59:54 -07002333 snaphdr_t *psnap = (snaphdr_t *) (skb->data + RX_MAC_HEADER_LENGTH);
2334 struct ieee80211_hdr *pmac = (struct ieee80211_hdr *)skb->data;
2335 __be16 type = *(__be16 *) psnap->ethertype;
2336 int delta;
2337 struct ethhdr *peth;
2338 UCHAR srcaddr[ADDRLEN];
2339 UCHAR destaddr[ADDRLEN];
2340 static UCHAR org_bridge[3] = { 0, 0, 0xf8 };
2341 static UCHAR org_1042[3] = { 0, 0, 0 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002342
John Daiker141fa612009-03-10 06:59:54 -07002343 memcpy(destaddr, ieee80211_get_DA(pmac), ADDRLEN);
2344 memcpy(srcaddr, ieee80211_get_SA(pmac), ADDRLEN);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002345
Dominik Brodowski624dd662009-10-24 15:52:44 +02002346#if 0
2347 if {
Joe Perchesad361c92009-07-06 13:05:40 -07002348 print_hex_dump(KERN_DEBUG, "skb->data before untranslate: ",
2349 DUMP_PREFIX_NONE, 16, 1,
2350 skb->data, 64, true);
2351 printk(KERN_DEBUG
John Daiker141fa612009-03-10 06:59:54 -07002352 "type = %08x, xsap = %02x%02x%02x, org = %02x02x02x\n",
2353 ntohs(type), psnap->dsap, psnap->ssap, psnap->ctrl,
2354 psnap->org[0], psnap->org[1], psnap->org[2]);
2355 printk(KERN_DEBUG "untranslate skb->data = %p\n", skb->data);
2356 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002357#endif
2358
John Daiker141fa612009-03-10 06:59:54 -07002359 if (psnap->dsap != 0xaa || psnap->ssap != 0xaa || psnap->ctrl != 3) {
2360 /* not a snap type so leave it alone */
Dominik Brodowski624dd662009-10-24 15:52:44 +02002361 pr_debug("ray_cs untranslate NOT SNAP %02x %02x %02x\n",
John Daiker141fa612009-03-10 06:59:54 -07002362 psnap->dsap, psnap->ssap, psnap->ctrl);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002363
John Daiker141fa612009-03-10 06:59:54 -07002364 delta = RX_MAC_HEADER_LENGTH - ETH_HLEN;
2365 peth = (struct ethhdr *)(skb->data + delta);
2366 peth->h_proto = htons(len - RX_MAC_HEADER_LENGTH);
2367 } else { /* Its a SNAP */
2368 if (memcmp(psnap->org, org_bridge, 3) == 0) {
2369 /* EtherII and nuke the LLC */
Dominik Brodowski624dd662009-10-24 15:52:44 +02002370 pr_debug("ray_cs untranslate Bridge encap\n");
John Daiker141fa612009-03-10 06:59:54 -07002371 delta = RX_MAC_HEADER_LENGTH
2372 + sizeof(struct snaphdr_t) - ETH_HLEN;
2373 peth = (struct ethhdr *)(skb->data + delta);
2374 peth->h_proto = type;
2375 } else if (memcmp(psnap->org, org_1042, 3) == 0) {
2376 switch (ntohs(type)) {
2377 case ETH_P_IPX:
2378 case ETH_P_AARP:
Dominik Brodowski624dd662009-10-24 15:52:44 +02002379 pr_debug("ray_cs untranslate RFC IPX/AARP\n");
John Daiker141fa612009-03-10 06:59:54 -07002380 delta = RX_MAC_HEADER_LENGTH - ETH_HLEN;
2381 peth = (struct ethhdr *)(skb->data + delta);
2382 peth->h_proto =
2383 htons(len - RX_MAC_HEADER_LENGTH);
2384 break;
2385 default:
Dominik Brodowski624dd662009-10-24 15:52:44 +02002386 pr_debug("ray_cs untranslate RFC default\n");
John Daiker141fa612009-03-10 06:59:54 -07002387 delta = RX_MAC_HEADER_LENGTH +
2388 sizeof(struct snaphdr_t) - ETH_HLEN;
2389 peth = (struct ethhdr *)(skb->data + delta);
2390 peth->h_proto = type;
2391 break;
2392 }
2393 } else {
2394 printk("ray_cs untranslate very confused by packet\n");
2395 delta = RX_MAC_HEADER_LENGTH - ETH_HLEN;
2396 peth = (struct ethhdr *)(skb->data + delta);
2397 peth->h_proto = type;
2398 }
Al Viro7698d692007-12-29 04:55:50 -05002399 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002400/* TBD reserve skb_reserve(skb, delta); */
John Daiker141fa612009-03-10 06:59:54 -07002401 skb_pull(skb, delta);
Dominik Brodowski624dd662009-10-24 15:52:44 +02002402 pr_debug("untranslate after skb_pull(%d), skb->data = %p\n", delta,
John Daiker141fa612009-03-10 06:59:54 -07002403 skb->data);
2404 memcpy(peth->h_dest, destaddr, ADDRLEN);
2405 memcpy(peth->h_source, srcaddr, ADDRLEN);
Dominik Brodowski624dd662009-10-24 15:52:44 +02002406#if 0
2407 {
John Daiker141fa612009-03-10 06:59:54 -07002408 int i;
2409 printk(KERN_DEBUG "skb->data after untranslate:");
2410 for (i = 0; i < 64; i++)
2411 printk("%02x ", skb->data[i]);
2412 printk("\n");
2413 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002414#endif
2415} /* end untranslate */
John Daiker141fa612009-03-10 06:59:54 -07002416
Linus Torvalds1da177e2005-04-16 15:20:36 -07002417/*===========================================================================*/
2418/* Copy data from circular receive buffer to PC memory.
2419 * dest = destination address in PC memory
2420 * pkt_addr = source address in receive buffer
2421 * len = length of packet to copy
2422 */
John Daiker141fa612009-03-10 06:59:54 -07002423static int copy_from_rx_buff(ray_dev_t *local, UCHAR *dest, int pkt_addr,
2424 int length)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002425{
John Daiker141fa612009-03-10 06:59:54 -07002426 int wrap_bytes = (pkt_addr + length) - (RX_BUFF_END + 1);
2427 if (wrap_bytes <= 0) {
2428 memcpy_fromio(dest, local->rmem + pkt_addr, length);
2429 } else { /* Packet wrapped in circular buffer */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002430
John Daiker141fa612009-03-10 06:59:54 -07002431 memcpy_fromio(dest, local->rmem + pkt_addr,
2432 length - wrap_bytes);
2433 memcpy_fromio(dest + length - wrap_bytes, local->rmem,
2434 wrap_bytes);
2435 }
2436 return length;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002437}
John Daiker141fa612009-03-10 06:59:54 -07002438
2439/*===========================================================================*/
2440static void release_frag_chain(ray_dev_t *local, struct rcs __iomem *prcs)
2441{
2442 struct rcs __iomem *prcslink = prcs;
2443 int tmp = 17;
2444 unsigned rcsindex = readb(&prcs->var.rx_packet.next_frag_rcs_index);
2445
2446 while (tmp--) {
2447 writeb(CCS_BUFFER_FREE, &prcslink->buffer_status);
2448 if (rcsindex >= (NUMBER_OF_CCS + NUMBER_OF_RCS)) {
Dominik Brodowski624dd662009-10-24 15:52:44 +02002449 pr_debug("ray_cs interrupt bad rcsindex = 0x%x\n",
John Daiker141fa612009-03-10 06:59:54 -07002450 rcsindex);
2451 break;
2452 }
2453 prcslink = rcs_base(local) + rcsindex;
2454 rcsindex = readb(&prcslink->var.rx_packet.next_frag_rcs_index);
2455 }
2456 writeb(CCS_BUFFER_FREE, &prcslink->buffer_status);
2457}
2458
Linus Torvalds1da177e2005-04-16 15:20:36 -07002459/*===========================================================================*/
2460static void authenticate(ray_dev_t *local)
2461{
John Daiker141fa612009-03-10 06:59:54 -07002462 struct pcmcia_device *link = local->finder;
Dominik Brodowski624dd662009-10-24 15:52:44 +02002463 dev_dbg(&link->dev, "ray_cs Starting authentication.\n");
John Daiker141fa612009-03-10 06:59:54 -07002464 if (!(pcmcia_dev_present(link))) {
Dominik Brodowski624dd662009-10-24 15:52:44 +02002465 dev_dbg(&link->dev, "ray_cs authenticate - device not present\n");
John Daiker141fa612009-03-10 06:59:54 -07002466 return;
2467 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002468
John Daiker141fa612009-03-10 06:59:54 -07002469 del_timer(&local->timer);
2470 if (build_auth_frame(local, local->bss_id, OPEN_AUTH_REQUEST)) {
2471 local->timer.function = &join_net;
2472 } else {
2473 local->timer.function = &authenticate_timeout;
2474 }
2475 local->timer.expires = jiffies + HZ * 2;
2476 local->timer.data = (long)local;
2477 add_timer(&local->timer);
2478 local->authentication_state = AWAITING_RESPONSE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002479} /* end authenticate */
John Daiker141fa612009-03-10 06:59:54 -07002480
Linus Torvalds1da177e2005-04-16 15:20:36 -07002481/*===========================================================================*/
2482static void rx_authenticate(ray_dev_t *local, struct rcs __iomem *prcs,
John Daiker141fa612009-03-10 06:59:54 -07002483 unsigned int pkt_addr, int rx_len)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002484{
John Daiker141fa612009-03-10 06:59:54 -07002485 UCHAR buff[256];
2486 struct rx_msg *msg = (struct rx_msg *)buff;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002487
John Daiker141fa612009-03-10 06:59:54 -07002488 del_timer(&local->timer);
2489
2490 copy_from_rx_buff(local, buff, pkt_addr, rx_len & 0xff);
2491 /* if we are trying to get authenticated */
2492 if (local->sparm.b4.a_network_type == ADHOC) {
Dominik Brodowski624dd662009-10-24 15:52:44 +02002493 pr_debug("ray_cs rx_auth var= %02x %02x %02x %02x %02x %02x\n",
John Daiker141fa612009-03-10 06:59:54 -07002494 msg->var[0], msg->var[1], msg->var[2], msg->var[3],
2495 msg->var[4], msg->var[5]);
2496 if (msg->var[2] == 1) {
Dominik Brodowski624dd662009-10-24 15:52:44 +02002497 pr_debug("ray_cs Sending authentication response.\n");
John Daiker141fa612009-03-10 06:59:54 -07002498 if (!build_auth_frame
2499 (local, msg->mac.addr_2, OPEN_AUTH_RESPONSE)) {
2500 local->authentication_state = NEED_TO_AUTH;
2501 memcpy(local->auth_id, msg->mac.addr_2,
2502 ADDRLEN);
2503 }
2504 }
2505 } else { /* Infrastructure network */
2506
2507 if (local->authentication_state == AWAITING_RESPONSE) {
2508 /* Verify authentication sequence #2 and success */
2509 if (msg->var[2] == 2) {
2510 if ((msg->var[3] | msg->var[4]) == 0) {
Dominik Brodowski624dd662009-10-24 15:52:44 +02002511 pr_debug("Authentication successful\n");
John Daiker141fa612009-03-10 06:59:54 -07002512 local->card_status = CARD_AUTH_COMPLETE;
2513 associate(local);
2514 local->authentication_state =
2515 AUTHENTICATED;
2516 } else {
Dominik Brodowski624dd662009-10-24 15:52:44 +02002517 pr_debug("Authentication refused\n");
John Daiker141fa612009-03-10 06:59:54 -07002518 local->card_status = CARD_AUTH_REFUSED;
2519 join_net((u_long) local);
2520 local->authentication_state =
2521 UNAUTHENTICATED;
2522 }
2523 }
2524 }
2525 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002526
2527} /* end rx_authenticate */
John Daiker141fa612009-03-10 06:59:54 -07002528
Linus Torvalds1da177e2005-04-16 15:20:36 -07002529/*===========================================================================*/
2530static void associate(ray_dev_t *local)
2531{
John Daiker141fa612009-03-10 06:59:54 -07002532 struct ccs __iomem *pccs;
2533 struct pcmcia_device *link = local->finder;
2534 struct net_device *dev = link->priv;
2535 int ccsindex;
2536 if (!(pcmcia_dev_present(link))) {
Dominik Brodowski624dd662009-10-24 15:52:44 +02002537 dev_dbg(&link->dev, "ray_cs associate - device not present\n");
John Daiker141fa612009-03-10 06:59:54 -07002538 return;
2539 }
2540 /* If no tx buffers available, return */
2541 if ((ccsindex = get_free_ccs(local)) < 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002542/* TBD should never be here but... what if we are? */
Dominik Brodowski624dd662009-10-24 15:52:44 +02002543 dev_dbg(&link->dev, "ray_cs associate - No free ccs\n");
John Daiker141fa612009-03-10 06:59:54 -07002544 return;
2545 }
Dominik Brodowski624dd662009-10-24 15:52:44 +02002546 dev_dbg(&link->dev, "ray_cs Starting association with access point\n");
John Daiker141fa612009-03-10 06:59:54 -07002547 pccs = ccs_base(local) + ccsindex;
2548 /* fill in the CCS */
2549 writeb(CCS_START_ASSOCIATION, &pccs->cmd);
2550 /* Interrupt the firmware to process the command */
2551 if (interrupt_ecf(local, ccsindex)) {
Dominik Brodowski624dd662009-10-24 15:52:44 +02002552 dev_dbg(&link->dev, "ray_cs associate failed - ECF not ready for intr\n");
John Daiker141fa612009-03-10 06:59:54 -07002553 writeb(CCS_BUFFER_FREE, &(pccs++)->buffer_status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002554
John Daiker141fa612009-03-10 06:59:54 -07002555 del_timer(&local->timer);
2556 local->timer.expires = jiffies + HZ * 2;
2557 local->timer.data = (long)local;
2558 local->timer.function = &join_net;
2559 add_timer(&local->timer);
2560 local->card_status = CARD_ASSOC_FAILED;
2561 return;
2562 }
2563 if (!sniffer)
2564 netif_start_queue(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002565
2566} /* end associate */
John Daiker141fa612009-03-10 06:59:54 -07002567
Linus Torvalds1da177e2005-04-16 15:20:36 -07002568/*===========================================================================*/
John Daiker141fa612009-03-10 06:59:54 -07002569static void rx_deauthenticate(ray_dev_t *local, struct rcs __iomem *prcs,
2570 unsigned int pkt_addr, int rx_len)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002571{
2572/* UCHAR buff[256];
2573 struct rx_msg *msg = (struct rx_msg *)buff;
2574*/
Dominik Brodowski624dd662009-10-24 15:52:44 +02002575 pr_debug("Deauthentication frame received\n");
John Daiker141fa612009-03-10 06:59:54 -07002576 local->authentication_state = UNAUTHENTICATED;
2577 /* Need to reauthenticate or rejoin depending on reason code */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002578/* copy_from_rx_buff(local, buff, pkt_addr, rx_len & 0xff);
2579 */
2580}
John Daiker141fa612009-03-10 06:59:54 -07002581
Linus Torvalds1da177e2005-04-16 15:20:36 -07002582/*===========================================================================*/
2583static void clear_interrupt(ray_dev_t *local)
2584{
John Daiker141fa612009-03-10 06:59:54 -07002585 writeb(0, local->amem + CIS_OFFSET + HCS_INTR_OFFSET);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002586}
John Daiker141fa612009-03-10 06:59:54 -07002587
Linus Torvalds1da177e2005-04-16 15:20:36 -07002588/*===========================================================================*/
2589#ifdef CONFIG_PROC_FS
2590#define MAXDATA (PAGE_SIZE - 80)
2591
2592static char *card_status[] = {
John Daiker141fa612009-03-10 06:59:54 -07002593 "Card inserted - uninitialized", /* 0 */
2594 "Card not downloaded", /* 1 */
2595 "Waiting for download parameters", /* 2 */
2596 "Card doing acquisition", /* 3 */
2597 "Acquisition complete", /* 4 */
2598 "Authentication complete", /* 5 */
2599 "Association complete", /* 6 */
2600 "???", "???", "???", "???", /* 7 8 9 10 undefined */
2601 "Card init error", /* 11 */
2602 "Download parameters error", /* 12 */
2603 "???", /* 13 */
2604 "Acquisition failed", /* 14 */
2605 "Authentication refused", /* 15 */
2606 "Association failed" /* 16 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002607};
2608
John Daiker141fa612009-03-10 06:59:54 -07002609static char *nettype[] = { "Adhoc", "Infra " };
2610static char *framing[] = { "Encapsulation", "Translation" }
2611
Linus Torvalds1da177e2005-04-16 15:20:36 -07002612;
2613/*===========================================================================*/
Alexey Dobriyan6b914c52008-04-10 14:34:35 -07002614static int ray_cs_proc_show(struct seq_file *m, void *v)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002615{
2616/* Print current values which are not available via other means
John Daiker141fa612009-03-10 06:59:54 -07002617 * eg ifconfig
Linus Torvalds1da177e2005-04-16 15:20:36 -07002618 */
John Daiker141fa612009-03-10 06:59:54 -07002619 int i;
2620 struct pcmcia_device *link;
2621 struct net_device *dev;
2622 ray_dev_t *local;
2623 UCHAR *p;
2624 struct freq_hop_element *pfh;
2625 UCHAR c[33];
Linus Torvalds1da177e2005-04-16 15:20:36 -07002626
John Daiker141fa612009-03-10 06:59:54 -07002627 link = this_device;
2628 if (!link)
2629 return 0;
2630 dev = (struct net_device *)link->priv;
2631 if (!dev)
2632 return 0;
2633 local = netdev_priv(dev);
2634 if (!local)
2635 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002636
John Daiker141fa612009-03-10 06:59:54 -07002637 seq_puts(m, "Raylink Wireless LAN driver status\n");
2638 seq_printf(m, "%s\n", rcsid);
2639 /* build 4 does not report version, and field is 0x55 after memtest */
2640 seq_puts(m, "Firmware version = ");
2641 if (local->fw_ver == 0x55)
2642 seq_puts(m, "4 - Use dump_cis for more details\n");
2643 else
2644 seq_printf(m, "%2d.%02d.%02d\n",
2645 local->fw_ver, local->fw_bld, local->fw_var);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002646
John Daiker141fa612009-03-10 06:59:54 -07002647 for (i = 0; i < 32; i++)
2648 c[i] = local->sparm.b5.a_current_ess_id[i];
2649 c[32] = 0;
2650 seq_printf(m, "%s network ESSID = \"%s\"\n",
2651 nettype[local->sparm.b5.a_network_type], c);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002652
John Daiker141fa612009-03-10 06:59:54 -07002653 p = local->bss_id;
2654 seq_printf(m, "BSSID = %pM\n", p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002655
John Daiker141fa612009-03-10 06:59:54 -07002656 seq_printf(m, "Country code = %d\n",
2657 local->sparm.b5.a_curr_country_code);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002658
John Daiker141fa612009-03-10 06:59:54 -07002659 i = local->card_status;
2660 if (i < 0)
2661 i = 10;
2662 if (i > 16)
2663 i = 10;
2664 seq_printf(m, "Card status = %s\n", card_status[i]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002665
John Daiker141fa612009-03-10 06:59:54 -07002666 seq_printf(m, "Framing mode = %s\n", framing[translate]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002667
John Daiker141fa612009-03-10 06:59:54 -07002668 seq_printf(m, "Last pkt signal lvl = %d\n", local->last_rsl);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002669
John Daiker141fa612009-03-10 06:59:54 -07002670 if (local->beacon_rxed) {
2671 /* Pull some fields out of last beacon received */
2672 seq_printf(m, "Beacon Interval = %d Kus\n",
2673 local->last_bcn.beacon_intvl[0]
2674 + 256 * local->last_bcn.beacon_intvl[1]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002675
John Daiker141fa612009-03-10 06:59:54 -07002676 p = local->last_bcn.elements;
2677 if (p[0] == C_ESSID_ELEMENT_ID)
2678 p += p[1] + 2;
2679 else {
2680 seq_printf(m,
2681 "Parse beacon failed at essid element id = %d\n",
2682 p[0]);
2683 return 0;
2684 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002685
John Daiker141fa612009-03-10 06:59:54 -07002686 if (p[0] == C_SUPPORTED_RATES_ELEMENT_ID) {
2687 seq_puts(m, "Supported rate codes = ");
2688 for (i = 2; i < p[1] + 2; i++)
2689 seq_printf(m, "0x%02x ", p[i]);
2690 seq_putc(m, '\n');
2691 p += p[1] + 2;
2692 } else {
2693 seq_puts(m, "Parse beacon failed at rates element\n");
2694 return 0;
2695 }
2696
2697 if (p[0] == C_FH_PARAM_SET_ELEMENT_ID) {
2698 pfh = (struct freq_hop_element *)p;
2699 seq_printf(m, "Hop dwell = %d Kus\n",
2700 pfh->dwell_time[0] +
2701 256 * pfh->dwell_time[1]);
Frans Popcb01b092010-03-24 19:46:34 +01002702 seq_printf(m, "Hop set = %d\n",
John Daiker141fa612009-03-10 06:59:54 -07002703 pfh->hop_set);
Frans Popcb01b092010-03-24 19:46:34 +01002704 seq_printf(m, "Hop pattern = %d\n",
John Daiker141fa612009-03-10 06:59:54 -07002705 pfh->hop_pattern);
Frans Popcb01b092010-03-24 19:46:34 +01002706 seq_printf(m, "Hop index = %d\n",
John Daiker141fa612009-03-10 06:59:54 -07002707 pfh->hop_index);
2708 p += p[1] + 2;
2709 } else {
2710 seq_puts(m,
2711 "Parse beacon failed at FH param element\n");
2712 return 0;
2713 }
2714 } else {
2715 seq_puts(m, "No beacons received\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002716 }
John Daiker141fa612009-03-10 06:59:54 -07002717 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002718}
2719
Alexey Dobriyan6b914c52008-04-10 14:34:35 -07002720static int ray_cs_proc_open(struct inode *inode, struct file *file)
2721{
2722 return single_open(file, ray_cs_proc_show, NULL);
2723}
2724
2725static const struct file_operations ray_cs_proc_fops = {
John Daiker141fa612009-03-10 06:59:54 -07002726 .owner = THIS_MODULE,
2727 .open = ray_cs_proc_open,
2728 .read = seq_read,
2729 .llseek = seq_lseek,
2730 .release = single_release,
Alexey Dobriyan6b914c52008-04-10 14:34:35 -07002731};
Linus Torvalds1da177e2005-04-16 15:20:36 -07002732#endif
2733/*===========================================================================*/
2734static int build_auth_frame(ray_dev_t *local, UCHAR *dest, int auth_type)
2735{
John Daiker141fa612009-03-10 06:59:54 -07002736 int addr;
2737 struct ccs __iomem *pccs;
2738 struct tx_msg __iomem *ptx;
2739 int ccsindex;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002740
John Daiker141fa612009-03-10 06:59:54 -07002741 /* If no tx buffers available, return */
2742 if ((ccsindex = get_free_tx_ccs(local)) < 0) {
Dominik Brodowski624dd662009-10-24 15:52:44 +02002743 pr_debug("ray_cs send authenticate - No free tx ccs\n");
John Daiker141fa612009-03-10 06:59:54 -07002744 return -1;
2745 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002746
John Daiker141fa612009-03-10 06:59:54 -07002747 pccs = ccs_base(local) + ccsindex;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002748
John Daiker141fa612009-03-10 06:59:54 -07002749 /* Address in card space */
2750 addr = TX_BUF_BASE + (ccsindex << 11);
2751 /* fill in the CCS */
2752 writeb(CCS_TX_REQUEST, &pccs->cmd);
2753 writeb(addr >> 8, pccs->var.tx_request.tx_data_ptr);
2754 writeb(0x20, pccs->var.tx_request.tx_data_ptr + 1);
2755 writeb(TX_AUTHENTICATE_LENGTH_MSB, pccs->var.tx_request.tx_data_length);
2756 writeb(TX_AUTHENTICATE_LENGTH_LSB,
2757 pccs->var.tx_request.tx_data_length + 1);
2758 writeb(0, &pccs->var.tx_request.pow_sav_mode);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002759
John Daiker141fa612009-03-10 06:59:54 -07002760 ptx = local->sram + addr;
2761 /* fill in the mac header */
2762 writeb(PROTOCOL_VER | AUTHENTIC_TYPE, &ptx->mac.frame_ctl_1);
2763 writeb(0, &ptx->mac.frame_ctl_2);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002764
John Daiker141fa612009-03-10 06:59:54 -07002765 memcpy_toio(ptx->mac.addr_1, dest, ADDRLEN);
2766 memcpy_toio(ptx->mac.addr_2, local->sparm.b4.a_mac_addr, ADDRLEN);
2767 memcpy_toio(ptx->mac.addr_3, local->bss_id, ADDRLEN);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002768
John Daiker141fa612009-03-10 06:59:54 -07002769 /* Fill in msg body with protocol 00 00, sequence 01 00 ,status 00 00 */
2770 memset_io(ptx->var, 0, 6);
2771 writeb(auth_type & 0xff, ptx->var + 2);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002772
John Daiker141fa612009-03-10 06:59:54 -07002773 /* Interrupt the firmware to process the command */
2774 if (interrupt_ecf(local, ccsindex)) {
Dominik Brodowski624dd662009-10-24 15:52:44 +02002775 pr_debug(
John Daiker141fa612009-03-10 06:59:54 -07002776 "ray_cs send authentication request failed - ECF not ready for intr\n");
2777 writeb(CCS_BUFFER_FREE, &(pccs++)->buffer_status);
2778 return -1;
2779 }
2780 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002781} /* End build_auth_frame */
2782
2783/*===========================================================================*/
2784#ifdef CONFIG_PROC_FS
Alexey Dobriyan83daee02009-11-25 10:12:20 +03002785static ssize_t ray_cs_essid_proc_write(struct file *file,
2786 const char __user *buffer, size_t count, loff_t *pos)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002787{
2788 static char proc_essid[33];
Alan Cox575c9ed2009-10-27 15:35:55 +00002789 unsigned int len = count;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002790
2791 if (len > 32)
2792 len = 32;
2793 memset(proc_essid, 0, 33);
2794 if (copy_from_user(proc_essid, buffer, len))
2795 return -EFAULT;
2796 essid = proc_essid;
2797 return count;
2798}
2799
Alexey Dobriyan83daee02009-11-25 10:12:20 +03002800static const struct file_operations ray_cs_essid_proc_fops = {
2801 .owner = THIS_MODULE,
2802 .write = ray_cs_essid_proc_write,
2803};
2804
2805static ssize_t int_proc_write(struct file *file, const char __user *buffer,
2806 size_t count, loff_t *pos)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002807{
2808 static char proc_number[10];
2809 char *p;
2810 int nr, len;
2811
2812 if (!count)
2813 return 0;
2814
2815 if (count > 9)
2816 return -EINVAL;
2817 if (copy_from_user(proc_number, buffer, count))
2818 return -EFAULT;
2819 p = proc_number;
2820 nr = 0;
2821 len = count;
2822 do {
2823 unsigned int c = *p - '0';
2824 if (c > 9)
2825 return -EINVAL;
John Daiker141fa612009-03-10 06:59:54 -07002826 nr = nr * 10 + c;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002827 p++;
2828 } while (--len);
Alexey Dobriyan83daee02009-11-25 10:12:20 +03002829 *(int *)PDE(file->f_path.dentry->d_inode)->data = nr;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002830 return count;
2831}
Alexey Dobriyan83daee02009-11-25 10:12:20 +03002832
2833static const struct file_operations int_proc_fops = {
2834 .owner = THIS_MODULE,
2835 .write = int_proc_write,
2836};
Linus Torvalds1da177e2005-04-16 15:20:36 -07002837#endif
2838
Dominik Brodowskif57ea2a2005-06-27 16:28:24 -07002839static struct pcmcia_device_id ray_ids[] = {
2840 PCMCIA_DEVICE_MANF_CARD(0x01a6, 0x0000),
2841 PCMCIA_DEVICE_NULL,
2842};
John Daiker141fa612009-03-10 06:59:54 -07002843
Dominik Brodowskif57ea2a2005-06-27 16:28:24 -07002844MODULE_DEVICE_TABLE(pcmcia, ray_ids);
2845
Linus Torvalds1da177e2005-04-16 15:20:36 -07002846static struct pcmcia_driver ray_driver = {
John Daiker141fa612009-03-10 06:59:54 -07002847 .owner = THIS_MODULE,
2848 .drv = {
2849 .name = "ray_cs",
2850 },
2851 .probe = ray_probe,
2852 .remove = ray_detach,
2853 .id_table = ray_ids,
2854 .suspend = ray_suspend,
2855 .resume = ray_resume,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002856};
2857
2858static int __init init_ray_cs(void)
2859{
John Daiker141fa612009-03-10 06:59:54 -07002860 int rc;
2861
Dominik Brodowski624dd662009-10-24 15:52:44 +02002862 pr_debug("%s\n", rcsid);
John Daiker141fa612009-03-10 06:59:54 -07002863 rc = pcmcia_register_driver(&ray_driver);
Dominik Brodowski624dd662009-10-24 15:52:44 +02002864 pr_debug("raylink init_module register_pcmcia_driver returns 0x%x\n",
John Daiker141fa612009-03-10 06:59:54 -07002865 rc);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002866
2867#ifdef CONFIG_PROC_FS
John Daiker141fa612009-03-10 06:59:54 -07002868 proc_mkdir("driver/ray_cs", NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002869
John Daiker141fa612009-03-10 06:59:54 -07002870 proc_create("driver/ray_cs/ray_cs", 0, NULL, &ray_cs_proc_fops);
Alexey Dobriyan83daee02009-11-25 10:12:20 +03002871 proc_create("driver/ray_cs/essid", S_IWUSR, NULL, &ray_cs_essid_proc_fops);
2872 proc_create_data("driver/ray_cs/net_type", S_IWUSR, NULL, &int_proc_fops, &net_type);
2873 proc_create_data("driver/ray_cs/translate", S_IWUSR, NULL, &int_proc_fops, &translate);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002874#endif
John Daiker141fa612009-03-10 06:59:54 -07002875 if (translate != 0)
2876 translate = 1;
2877 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002878} /* init_ray_cs */
2879
2880/*===========================================================================*/
2881
2882static void __exit exit_ray_cs(void)
2883{
Dominik Brodowski624dd662009-10-24 15:52:44 +02002884 pr_debug("ray_cs: cleanup_module\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002885
2886#ifdef CONFIG_PROC_FS
John Daiker141fa612009-03-10 06:59:54 -07002887 remove_proc_entry("driver/ray_cs/ray_cs", NULL);
2888 remove_proc_entry("driver/ray_cs/essid", NULL);
2889 remove_proc_entry("driver/ray_cs/net_type", NULL);
2890 remove_proc_entry("driver/ray_cs/translate", NULL);
2891 remove_proc_entry("driver/ray_cs", NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002892#endif
2893
John Daiker141fa612009-03-10 06:59:54 -07002894 pcmcia_unregister_driver(&ray_driver);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002895} /* exit_ray_cs */
2896
2897module_init(init_ray_cs);
2898module_exit(exit_ray_cs);
2899
2900/*===========================================================================*/