blob: 7fb66cc1e9fd3b9ea6fff3f259bb62343456dbe7 [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;
Dominik Brodowski7feabb62010-07-29 18:35:47 +0200322 p_dev->config_index = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700323
John Daiker141fa612009-03-10 06:59:54 -0700324 p_dev->priv = dev;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700325
John Daiker141fa612009-03-10 06:59:54 -0700326 local->finder = p_dev;
327 local->card_status = CARD_INSERTED;
328 local->authentication_state = UNAUTHENTICATED;
329 local->num_multi = 0;
Dominik Brodowski624dd662009-10-24 15:52:44 +0200330 dev_dbg(&p_dev->dev, "ray_attach p_dev = %p, dev = %p, local = %p, intr = %p\n",
John Daiker141fa612009-03-10 06:59:54 -0700331 p_dev, dev, local, &ray_interrupt);
332
333 /* Raylink entries in the device structure */
Stephen Hemminger32f5a332009-03-20 19:36:28 +0000334 dev->netdev_ops = &ray_netdev_ops;
John Daiker141fa612009-03-10 06:59:54 -0700335 SET_ETHTOOL_OPS(dev, &netdev_ethtool_ops);
336 dev->wireless_handlers = &ray_handler_def;
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -0700337#ifdef WIRELESS_SPY
John Daiker141fa612009-03-10 06:59:54 -0700338 local->wireless_data.spy_data = &local->spy_data;
339 dev->wireless_data = &local->wireless_data;
340#endif /* WIRELESS_SPY */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700341
Linus Torvalds1da177e2005-04-16 15:20:36 -0700342
Dominik Brodowski624dd662009-10-24 15:52:44 +0200343 dev_dbg(&p_dev->dev, "ray_cs ray_attach calling ether_setup.)\n");
John Daiker141fa612009-03-10 06:59:54 -0700344 netif_stop_queue(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700345
John Daiker141fa612009-03-10 06:59:54 -0700346 init_timer(&local->timer);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700347
John Daiker141fa612009-03-10 06:59:54 -0700348 this_device = p_dev;
349 return ray_config(p_dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700350
351fail_alloc_dev:
John Daiker141fa612009-03-10 06:59:54 -0700352 return -ENOMEM;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700353} /* ray_attach */
John Daiker141fa612009-03-10 06:59:54 -0700354
Linus Torvalds1da177e2005-04-16 15:20:36 -0700355/*=============================================================================
356 This deletes a driver "instance". The device is de-registered
357 with Card Services. If it has been released, all local data
358 structures are freed. Otherwise, the structures will be freed
359 when the device is released.
360=============================================================================*/
Dominik Brodowskifba395e2006-03-31 17:21:06 +0200361static void ray_detach(struct pcmcia_device *link)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700362{
John Daiker141fa612009-03-10 06:59:54 -0700363 struct net_device *dev;
364 ray_dev_t *local;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700365
Dominik Brodowski624dd662009-10-24 15:52:44 +0200366 dev_dbg(&link->dev, "ray_detach\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700367
John Daiker141fa612009-03-10 06:59:54 -0700368 this_device = NULL;
369 dev = link->priv;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700370
John Daiker141fa612009-03-10 06:59:54 -0700371 ray_release(link);
Dominik Brodowskicc3b4862005-11-14 21:23:14 +0100372
John Daiker141fa612009-03-10 06:59:54 -0700373 local = netdev_priv(dev);
374 del_timer(&local->timer);
Dominik Brodowskicc3b4862005-11-14 21:23:14 +0100375
John Daiker141fa612009-03-10 06:59:54 -0700376 if (link->priv) {
Dominik Brodowskic7c2fa02010-03-20 19:39:26 +0100377 unregister_netdev(dev);
John Daiker141fa612009-03-10 06:59:54 -0700378 free_netdev(dev);
379 }
Dominik Brodowski624dd662009-10-24 15:52:44 +0200380 dev_dbg(&link->dev, "ray_cs ray_detach ending\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700381} /* ray_detach */
John Daiker141fa612009-03-10 06:59:54 -0700382
Linus Torvalds1da177e2005-04-16 15:20:36 -0700383/*=============================================================================
384 ray_config() is run after a CARD_INSERTION event
385 is received, to configure the PCMCIA socket, and to make the
386 ethernet device available to the system.
387=============================================================================*/
Linus Torvalds1da177e2005-04-16 15:20:36 -0700388#define MAX_TUPLE_SIZE 128
Dominik Brodowski15b99ac2006-03-31 17:26:06 +0200389static int ray_config(struct pcmcia_device *link)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700390{
Dominik Brodowski624dd662009-10-24 15:52:44 +0200391 int ret = 0;
John Daiker141fa612009-03-10 06:59:54 -0700392 int i;
John Daiker141fa612009-03-10 06:59:54 -0700393 struct net_device *dev = (struct net_device *)link->priv;
394 ray_dev_t *local = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700395
Dominik Brodowski624dd662009-10-24 15:52:44 +0200396 dev_dbg(&link->dev, "ray_config\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700397
John Daiker141fa612009-03-10 06:59:54 -0700398 /* Determine card type and firmware version */
399 printk(KERN_INFO "ray_cs Detected: %s%s%s%s\n",
400 link->prod_id[0] ? link->prod_id[0] : " ",
401 link->prod_id[1] ? link->prod_id[1] : " ",
402 link->prod_id[2] ? link->prod_id[2] : " ",
403 link->prod_id[3] ? link->prod_id[3] : " ");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700404
John Daiker141fa612009-03-10 06:59:54 -0700405 /* Now allocate an interrupt line. Note that this does not
406 actually assign a handler to the interrupt.
407 */
Dominik Brodowskieb141202010-03-07 12:21:16 +0100408 ret = pcmcia_request_irq(link, ray_interrupt);
Dominik Brodowski624dd662009-10-24 15:52:44 +0200409 if (ret)
410 goto failed;
Dominik Brodowskieb141202010-03-07 12:21:16 +0100411 dev->irq = link->irq;
John Daiker141fa612009-03-10 06:59:54 -0700412
413 /* This actually configures the PCMCIA socket -- setting up
414 the I/O windows and the interrupt mapping.
415 */
Dominik Brodowski624dd662009-10-24 15:52:44 +0200416 ret = pcmcia_request_configuration(link, &link->conf);
417 if (ret)
418 goto failed;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700419
420/*** Set up 32k window for shared memory (transmit and control) ************/
Dominik Brodowskicdb13802010-07-28 10:59:06 +0200421 link->resource[2]->flags |= WIN_DATA_WIDTH_8 | WIN_MEMORY_TYPE_CM | WIN_ENABLE | WIN_USE_WAIT;
422 link->resource[2]->start = 0;
423 link->resource[2]->end = 0x8000;
424 ret = pcmcia_request_window(link, link->resource[2], ray_mem_speed);
Dominik Brodowski624dd662009-10-24 15:52:44 +0200425 if (ret)
426 goto failed;
Dominik Brodowskicdb13802010-07-28 10:59:06 +0200427 ret = pcmcia_map_mem_page(link, link->resource[2], 0);
Dominik Brodowski624dd662009-10-24 15:52:44 +0200428 if (ret)
429 goto failed;
Dominik Brodowskicdb13802010-07-28 10:59:06 +0200430 local->sram = ioremap(link->resource[2]->start,
431 resource_size(link->resource[2]));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700432
433/*** Set up 16k window for shared memory (receive buffer) ***************/
Dominik Brodowskicdb13802010-07-28 10:59:06 +0200434 link->resource[3]->flags |=
John Daiker141fa612009-03-10 06:59:54 -0700435 WIN_DATA_WIDTH_8 | WIN_MEMORY_TYPE_CM | WIN_ENABLE | WIN_USE_WAIT;
Dominik Brodowskicdb13802010-07-28 10:59:06 +0200436 link->resource[3]->start = 0;
437 link->resource[3]->end = 0x4000;
438 ret = pcmcia_request_window(link, link->resource[3], ray_mem_speed);
Dominik Brodowski624dd662009-10-24 15:52:44 +0200439 if (ret)
440 goto failed;
Dominik Brodowskicdb13802010-07-28 10:59:06 +0200441 ret = pcmcia_map_mem_page(link, link->resource[3], 0x8000);
Dominik Brodowski624dd662009-10-24 15:52:44 +0200442 if (ret)
443 goto failed;
Dominik Brodowskicdb13802010-07-28 10:59:06 +0200444 local->rmem = ioremap(link->resource[3]->start,
445 resource_size(link->resource[3]));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700446
447/*** Set up window for attribute memory ***********************************/
Dominik Brodowskicdb13802010-07-28 10:59:06 +0200448 link->resource[4]->flags |=
John Daiker141fa612009-03-10 06:59:54 -0700449 WIN_DATA_WIDTH_8 | WIN_MEMORY_TYPE_AM | WIN_ENABLE | WIN_USE_WAIT;
Dominik Brodowskicdb13802010-07-28 10:59:06 +0200450 link->resource[4]->start = 0;
451 link->resource[4]->end = 0x1000;
452 ret = pcmcia_request_window(link, link->resource[4], ray_mem_speed);
Dominik Brodowski624dd662009-10-24 15:52:44 +0200453 if (ret)
454 goto failed;
Dominik Brodowskicdb13802010-07-28 10:59:06 +0200455 ret = pcmcia_map_mem_page(link, link->resource[4], 0);
Dominik Brodowski624dd662009-10-24 15:52:44 +0200456 if (ret)
457 goto failed;
Dominik Brodowskicdb13802010-07-28 10:59:06 +0200458 local->amem = ioremap(link->resource[4]->start,
459 resource_size(link->resource[4]));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700460
Dominik Brodowski624dd662009-10-24 15:52:44 +0200461 dev_dbg(&link->dev, "ray_config sram=%p\n", local->sram);
462 dev_dbg(&link->dev, "ray_config rmem=%p\n", local->rmem);
463 dev_dbg(&link->dev, "ray_config amem=%p\n", local->amem);
John Daiker141fa612009-03-10 06:59:54 -0700464 if (ray_init(dev) < 0) {
465 ray_release(link);
466 return -ENODEV;
467 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700468
Dominik Brodowskidd2e5a12009-11-03 10:27:34 +0100469 SET_NETDEV_DEV(dev, &link->dev);
John Daiker141fa612009-03-10 06:59:54 -0700470 i = register_netdev(dev);
471 if (i != 0) {
472 printk("ray_config register_netdev() failed\n");
473 ray_release(link);
474 return i;
475 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700476
John Daiker141fa612009-03-10 06:59:54 -0700477 printk(KERN_INFO "%s: RayLink, irq %d, hw_addr %pM\n",
478 dev->name, dev->irq, dev->dev_addr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700479
John Daiker141fa612009-03-10 06:59:54 -0700480 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700481
Dominik Brodowski624dd662009-10-24 15:52:44 +0200482failed:
John Daiker141fa612009-03-10 06:59:54 -0700483 ray_release(link);
484 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700485} /* ray_config */
486
487static inline struct ccs __iomem *ccs_base(ray_dev_t *dev)
488{
489 return dev->sram + CCS_BASE;
490}
491
492static inline struct rcs __iomem *rcs_base(ray_dev_t *dev)
493{
494 /*
495 * This looks nonsensical, since there is a separate
496 * RCS_BASE. But the difference between a "struct rcs"
497 * and a "struct ccs" ends up being in the _index_ off
498 * the base, so the base pointer is the same for both
499 * ccs/rcs.
500 */
501 return dev->sram + CCS_BASE;
502}
503
504/*===========================================================================*/
505static int ray_init(struct net_device *dev)
506{
John Daiker141fa612009-03-10 06:59:54 -0700507 int i;
508 UCHAR *p;
509 struct ccs __iomem *pccs;
510 ray_dev_t *local = netdev_priv(dev);
511 struct pcmcia_device *link = local->finder;
Dominik Brodowski624dd662009-10-24 15:52:44 +0200512 dev_dbg(&link->dev, "ray_init(0x%p)\n", dev);
John Daiker141fa612009-03-10 06:59:54 -0700513 if (!(pcmcia_dev_present(link))) {
Dominik Brodowski624dd662009-10-24 15:52:44 +0200514 dev_dbg(&link->dev, "ray_init - device not present\n");
John Daiker141fa612009-03-10 06:59:54 -0700515 return -1;
516 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700517
John Daiker141fa612009-03-10 06:59:54 -0700518 local->net_type = net_type;
519 local->sta_type = TYPE_STA;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700520
John Daiker141fa612009-03-10 06:59:54 -0700521 /* Copy the startup results to local memory */
522 memcpy_fromio(&local->startup_res, local->sram + ECF_TO_HOST_BASE,
523 sizeof(struct startup_res_6));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700524
John Daiker141fa612009-03-10 06:59:54 -0700525 /* Check Power up test status and get mac address from card */
526 if (local->startup_res.startup_word != 0x80) {
527 printk(KERN_INFO "ray_init ERROR card status = %2x\n",
528 local->startup_res.startup_word);
529 local->card_status = CARD_INIT_ERROR;
530 return -1;
531 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700532
John Daiker141fa612009-03-10 06:59:54 -0700533 local->fw_ver = local->startup_res.firmware_version[0];
534 local->fw_bld = local->startup_res.firmware_version[1];
535 local->fw_var = local->startup_res.firmware_version[2];
Frans Popcb01b092010-03-24 19:46:34 +0100536 dev_dbg(&link->dev, "ray_init firmware version %d.%d\n", local->fw_ver,
John Daiker141fa612009-03-10 06:59:54 -0700537 local->fw_bld);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700538
John Daiker141fa612009-03-10 06:59:54 -0700539 local->tib_length = 0x20;
540 if ((local->fw_ver == 5) && (local->fw_bld >= 30))
541 local->tib_length = local->startup_res.tib_length;
Dominik Brodowski624dd662009-10-24 15:52:44 +0200542 dev_dbg(&link->dev, "ray_init tib_length = 0x%02x\n", local->tib_length);
John Daiker141fa612009-03-10 06:59:54 -0700543 /* Initialize CCS's to buffer free state */
544 pccs = ccs_base(local);
545 for (i = 0; i < NUMBER_OF_CCS; i++) {
546 writeb(CCS_BUFFER_FREE, &(pccs++)->buffer_status);
547 }
548 init_startup_params(local);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700549
John Daiker141fa612009-03-10 06:59:54 -0700550 /* copy mac address to startup parameters */
551 if (parse_addr(phy_addr, local->sparm.b4.a_mac_addr)) {
552 p = local->sparm.b4.a_mac_addr;
553 } else {
554 memcpy(&local->sparm.b4.a_mac_addr,
555 &local->startup_res.station_addr, ADDRLEN);
556 p = local->sparm.b4.a_mac_addr;
557 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700558
John Daiker141fa612009-03-10 06:59:54 -0700559 clear_interrupt(local); /* Clear any interrupt from the card */
560 local->card_status = CARD_AWAITING_PARAM;
Dominik Brodowski624dd662009-10-24 15:52:44 +0200561 dev_dbg(&link->dev, "ray_init ending\n");
John Daiker141fa612009-03-10 06:59:54 -0700562 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700563} /* ray_init */
John Daiker141fa612009-03-10 06:59:54 -0700564
Linus Torvalds1da177e2005-04-16 15:20:36 -0700565/*===========================================================================*/
566/* Download startup parameters to the card and command it to read them */
567static int dl_startup_params(struct net_device *dev)
568{
John Daiker141fa612009-03-10 06:59:54 -0700569 int ccsindex;
570 ray_dev_t *local = netdev_priv(dev);
571 struct ccs __iomem *pccs;
572 struct pcmcia_device *link = local->finder;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700573
Dominik Brodowski624dd662009-10-24 15:52:44 +0200574 dev_dbg(&link->dev, "dl_startup_params entered\n");
John Daiker141fa612009-03-10 06:59:54 -0700575 if (!(pcmcia_dev_present(link))) {
Dominik Brodowski624dd662009-10-24 15:52:44 +0200576 dev_dbg(&link->dev, "ray_cs dl_startup_params - device not present\n");
John Daiker141fa612009-03-10 06:59:54 -0700577 return -1;
578 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700579
John Daiker141fa612009-03-10 06:59:54 -0700580 /* Copy parameters to host to ECF area */
581 if (local->fw_ver == 0x55)
582 memcpy_toio(local->sram + HOST_TO_ECF_BASE, &local->sparm.b4,
583 sizeof(struct b4_startup_params));
584 else
585 memcpy_toio(local->sram + HOST_TO_ECF_BASE, &local->sparm.b5,
586 sizeof(struct b5_startup_params));
587
588 /* Fill in the CCS fields for the ECF */
589 if ((ccsindex = get_free_ccs(local)) < 0)
590 return -1;
591 local->dl_param_ccs = ccsindex;
592 pccs = ccs_base(local) + ccsindex;
593 writeb(CCS_DOWNLOAD_STARTUP_PARAMS, &pccs->cmd);
Dominik Brodowski624dd662009-10-24 15:52:44 +0200594 dev_dbg(&link->dev, "dl_startup_params start ccsindex = %d\n",
John Daiker141fa612009-03-10 06:59:54 -0700595 local->dl_param_ccs);
596 /* Interrupt the firmware to process the command */
597 if (interrupt_ecf(local, ccsindex)) {
598 printk(KERN_INFO "ray dl_startup_params failed - "
599 "ECF not ready for intr\n");
600 local->card_status = CARD_DL_PARAM_ERROR;
601 writeb(CCS_BUFFER_FREE, &(pccs++)->buffer_status);
602 return -2;
603 }
604 local->card_status = CARD_DL_PARAM;
605 /* Start kernel timer to wait for dl startup to complete. */
606 local->timer.expires = jiffies + HZ / 2;
607 local->timer.data = (long)local;
608 local->timer.function = &verify_dl_startup;
609 add_timer(&local->timer);
Dominik Brodowski624dd662009-10-24 15:52:44 +0200610 dev_dbg(&link->dev,
John Daiker141fa612009-03-10 06:59:54 -0700611 "ray_cs dl_startup_params started timer for verify_dl_startup\n");
612 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700613} /* dl_startup_params */
John Daiker141fa612009-03-10 06:59:54 -0700614
Linus Torvalds1da177e2005-04-16 15:20:36 -0700615/*===========================================================================*/
616static void init_startup_params(ray_dev_t *local)
617{
John Daiker141fa612009-03-10 06:59:54 -0700618 int i;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700619
John Daiker141fa612009-03-10 06:59:54 -0700620 if (country > JAPAN_TEST)
621 country = USA;
622 else if (country < USA)
623 country = USA;
624 /* structure for hop time and beacon period is defined here using
625 * New 802.11D6.1 format. Card firmware is still using old format
626 * until version 6.
627 * Before After
628 * a_hop_time ms byte a_hop_time ms byte
629 * a_hop_time 2s byte a_hop_time ls byte
630 * a_hop_time ls byte a_beacon_period ms byte
631 * a_beacon_period a_beacon_period ls byte
632 *
633 * a_hop_time = uS a_hop_time = KuS
634 * a_beacon_period = hops a_beacon_period = KuS
635 *//* 64ms = 010000 */
636 if (local->fw_ver == 0x55) {
637 memcpy((UCHAR *) &local->sparm.b4, b4_default_startup_parms,
638 sizeof(struct b4_startup_params));
639 /* Translate sane kus input values to old build 4/5 format */
640 /* i = hop time in uS truncated to 3 bytes */
641 i = (hop_dwell * 1024) & 0xffffff;
642 local->sparm.b4.a_hop_time[0] = (i >> 16) & 0xff;
643 local->sparm.b4.a_hop_time[1] = (i >> 8) & 0xff;
644 local->sparm.b4.a_beacon_period[0] = 0;
645 local->sparm.b4.a_beacon_period[1] =
646 ((beacon_period / hop_dwell) - 1) & 0xff;
647 local->sparm.b4.a_curr_country_code = country;
648 local->sparm.b4.a_hop_pattern_length =
649 hop_pattern_length[(int)country] - 1;
650 if (bc) {
651 local->sparm.b4.a_ack_timeout = 0x50;
652 local->sparm.b4.a_sifs = 0x3f;
653 }
654 } else { /* Version 5 uses real kus values */
655 memcpy((UCHAR *) &local->sparm.b5, b5_default_startup_parms,
656 sizeof(struct b5_startup_params));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700657
John Daiker141fa612009-03-10 06:59:54 -0700658 local->sparm.b5.a_hop_time[0] = (hop_dwell >> 8) & 0xff;
659 local->sparm.b5.a_hop_time[1] = hop_dwell & 0xff;
660 local->sparm.b5.a_beacon_period[0] =
661 (beacon_period >> 8) & 0xff;
662 local->sparm.b5.a_beacon_period[1] = beacon_period & 0xff;
663 if (psm)
664 local->sparm.b5.a_power_mgt_state = 1;
665 local->sparm.b5.a_curr_country_code = country;
666 local->sparm.b5.a_hop_pattern_length =
667 hop_pattern_length[(int)country];
668 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700669
John Daiker141fa612009-03-10 06:59:54 -0700670 local->sparm.b4.a_network_type = net_type & 0x01;
671 local->sparm.b4.a_acting_as_ap_status = TYPE_STA;
672
673 if (essid != NULL)
674 strncpy(local->sparm.b4.a_current_ess_id, essid, ESSID_SIZE);
675} /* init_startup_params */
676
Linus Torvalds1da177e2005-04-16 15:20:36 -0700677/*===========================================================================*/
678static void verify_dl_startup(u_long data)
679{
John Daiker141fa612009-03-10 06:59:54 -0700680 ray_dev_t *local = (ray_dev_t *) data;
681 struct ccs __iomem *pccs = ccs_base(local) + local->dl_param_ccs;
682 UCHAR status;
683 struct pcmcia_device *link = local->finder;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700684
John Daiker141fa612009-03-10 06:59:54 -0700685 if (!(pcmcia_dev_present(link))) {
Dominik Brodowski624dd662009-10-24 15:52:44 +0200686 dev_dbg(&link->dev, "ray_cs verify_dl_startup - device not present\n");
John Daiker141fa612009-03-10 06:59:54 -0700687 return;
688 }
Dominik Brodowski624dd662009-10-24 15:52:44 +0200689#if 0
690 {
John Daiker141fa612009-03-10 06:59:54 -0700691 int i;
692 printk(KERN_DEBUG
693 "verify_dl_startup parameters sent via ccs %d:\n",
694 local->dl_param_ccs);
695 for (i = 0; i < sizeof(struct b5_startup_params); i++) {
696 printk(" %2x",
697 (unsigned int)readb(local->sram +
698 HOST_TO_ECF_BASE + i));
699 }
700 printk("\n");
701 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700702#endif
703
John Daiker141fa612009-03-10 06:59:54 -0700704 status = readb(&pccs->buffer_status);
705 if (status != CCS_BUFFER_FREE) {
706 printk(KERN_INFO
707 "Download startup params failed. Status = %d\n",
708 status);
709 local->card_status = CARD_DL_PARAM_ERROR;
710 return;
711 }
712 if (local->sparm.b4.a_network_type == ADHOC)
713 start_net((u_long) local);
714 else
715 join_net((u_long) local);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700716} /* end verify_dl_startup */
John Daiker141fa612009-03-10 06:59:54 -0700717
Linus Torvalds1da177e2005-04-16 15:20:36 -0700718/*===========================================================================*/
719/* Command card to start a network */
720static void start_net(u_long data)
721{
John Daiker141fa612009-03-10 06:59:54 -0700722 ray_dev_t *local = (ray_dev_t *) data;
723 struct ccs __iomem *pccs;
724 int ccsindex;
725 struct pcmcia_device *link = local->finder;
726 if (!(pcmcia_dev_present(link))) {
Dominik Brodowski624dd662009-10-24 15:52:44 +0200727 dev_dbg(&link->dev, "ray_cs start_net - device not present\n");
John Daiker141fa612009-03-10 06:59:54 -0700728 return;
729 }
730 /* Fill in the CCS fields for the ECF */
731 if ((ccsindex = get_free_ccs(local)) < 0)
732 return;
733 pccs = ccs_base(local) + ccsindex;
734 writeb(CCS_START_NETWORK, &pccs->cmd);
735 writeb(0, &pccs->var.start_network.update_param);
736 /* Interrupt the firmware to process the command */
737 if (interrupt_ecf(local, ccsindex)) {
Dominik Brodowski624dd662009-10-24 15:52:44 +0200738 dev_dbg(&link->dev, "ray start net failed - card not ready for intr\n");
John Daiker141fa612009-03-10 06:59:54 -0700739 writeb(CCS_BUFFER_FREE, &(pccs++)->buffer_status);
740 return;
741 }
742 local->card_status = CARD_DOING_ACQ;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700743} /* end start_net */
John Daiker141fa612009-03-10 06:59:54 -0700744
Linus Torvalds1da177e2005-04-16 15:20:36 -0700745/*===========================================================================*/
746/* Command card to join a network */
747static void join_net(u_long data)
748{
John Daiker141fa612009-03-10 06:59:54 -0700749 ray_dev_t *local = (ray_dev_t *) data;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700750
John Daiker141fa612009-03-10 06:59:54 -0700751 struct ccs __iomem *pccs;
752 int ccsindex;
753 struct pcmcia_device *link = local->finder;
754
755 if (!(pcmcia_dev_present(link))) {
Dominik Brodowski624dd662009-10-24 15:52:44 +0200756 dev_dbg(&link->dev, "ray_cs join_net - device not present\n");
John Daiker141fa612009-03-10 06:59:54 -0700757 return;
758 }
759 /* Fill in the CCS fields for the ECF */
760 if ((ccsindex = get_free_ccs(local)) < 0)
761 return;
762 pccs = ccs_base(local) + ccsindex;
763 writeb(CCS_JOIN_NETWORK, &pccs->cmd);
764 writeb(0, &pccs->var.join_network.update_param);
765 writeb(0, &pccs->var.join_network.net_initiated);
766 /* Interrupt the firmware to process the command */
767 if (interrupt_ecf(local, ccsindex)) {
Dominik Brodowski624dd662009-10-24 15:52:44 +0200768 dev_dbg(&link->dev, "ray join net failed - card not ready for intr\n");
John Daiker141fa612009-03-10 06:59:54 -0700769 writeb(CCS_BUFFER_FREE, &(pccs++)->buffer_status);
770 return;
771 }
772 local->card_status = CARD_DOING_ACQ;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700773}
John Daiker141fa612009-03-10 06:59:54 -0700774
Linus Torvalds1da177e2005-04-16 15:20:36 -0700775/*============================================================================
776 After a card is removed, ray_release() will unregister the net
777 device, and release the PCMCIA configuration. If the device is
778 still open, this will be postponed until it is closed.
779=============================================================================*/
Dominik Brodowskifba395e2006-03-31 17:21:06 +0200780static void ray_release(struct pcmcia_device *link)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700781{
John Daiker141fa612009-03-10 06:59:54 -0700782 struct net_device *dev = link->priv;
783 ray_dev_t *local = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700784
Dominik Brodowski624dd662009-10-24 15:52:44 +0200785 dev_dbg(&link->dev, "ray_release\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700786
John Daiker141fa612009-03-10 06:59:54 -0700787 del_timer(&local->timer);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700788
John Daiker141fa612009-03-10 06:59:54 -0700789 iounmap(local->sram);
790 iounmap(local->rmem);
791 iounmap(local->amem);
John Daiker141fa612009-03-10 06:59:54 -0700792 pcmcia_disable_device(link);
793
Dominik Brodowski624dd662009-10-24 15:52:44 +0200794 dev_dbg(&link->dev, "ray_release ending\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700795}
796
Dominik Brodowskifba395e2006-03-31 17:21:06 +0200797static int ray_suspend(struct pcmcia_device *link)
Dominik Brodowski98e4c282005-11-14 21:21:18 +0100798{
Dominik Brodowski98e4c282005-11-14 21:21:18 +0100799 struct net_device *dev = link->priv;
800
Dominik Brodowskie2d40962006-03-02 00:09:29 +0100801 if (link->open)
Dominik Brodowski8661bb52006-03-02 00:02:33 +0100802 netif_device_detach(dev);
Dominik Brodowski98e4c282005-11-14 21:21:18 +0100803
804 return 0;
805}
806
Dominik Brodowskifba395e2006-03-31 17:21:06 +0200807static int ray_resume(struct pcmcia_device *link)
Dominik Brodowski98e4c282005-11-14 21:21:18 +0100808{
Dominik Brodowski98e4c282005-11-14 21:21:18 +0100809 struct net_device *dev = link->priv;
810
Dominik Brodowskie2d40962006-03-02 00:09:29 +0100811 if (link->open) {
Dominik Brodowski8661bb52006-03-02 00:02:33 +0100812 ray_reset(dev);
813 netif_device_attach(dev);
814 }
Dominik Brodowski98e4c282005-11-14 21:21:18 +0100815
816 return 0;
817}
818
Linus Torvalds1da177e2005-04-16 15:20:36 -0700819/*===========================================================================*/
Hannes Eder2ed5ba82008-12-26 00:12:59 -0800820static int ray_dev_init(struct net_device *dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700821{
822#ifdef RAY_IMMEDIATE_INIT
John Daiker141fa612009-03-10 06:59:54 -0700823 int i;
824#endif /* RAY_IMMEDIATE_INIT */
825 ray_dev_t *local = netdev_priv(dev);
826 struct pcmcia_device *link = local->finder;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700827
Dominik Brodowski624dd662009-10-24 15:52:44 +0200828 dev_dbg(&link->dev, "ray_dev_init(dev=%p)\n", dev);
John Daiker141fa612009-03-10 06:59:54 -0700829 if (!(pcmcia_dev_present(link))) {
Dominik Brodowski624dd662009-10-24 15:52:44 +0200830 dev_dbg(&link->dev, "ray_dev_init - device not present\n");
John Daiker141fa612009-03-10 06:59:54 -0700831 return -1;
832 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700833#ifdef RAY_IMMEDIATE_INIT
John Daiker141fa612009-03-10 06:59:54 -0700834 /* Download startup parameters */
835 if ((i = dl_startup_params(dev)) < 0) {
836 printk(KERN_INFO "ray_dev_init dl_startup_params failed - "
837 "returns 0x%x\n", i);
838 return -1;
839 }
840#else /* RAY_IMMEDIATE_INIT */
841 /* Postpone the card init so that we can still configure the card,
842 * for example using the Wireless Extensions. The init will happen
843 * in ray_open() - Jean II */
Dominik Brodowski624dd662009-10-24 15:52:44 +0200844 dev_dbg(&link->dev,
John Daiker141fa612009-03-10 06:59:54 -0700845 "ray_dev_init: postponing card init to ray_open() ; Status = %d\n",
846 local->card_status);
847#endif /* RAY_IMMEDIATE_INIT */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700848
John Daiker141fa612009-03-10 06:59:54 -0700849 /* copy mac and broadcast addresses to linux device */
Jiri Pirko3a6d54c2009-05-11 23:37:15 +0000850 memcpy(dev->dev_addr, &local->sparm.b4.a_mac_addr, ADDRLEN);
John Daiker141fa612009-03-10 06:59:54 -0700851 memset(dev->broadcast, 0xff, ETH_ALEN);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700852
Dominik Brodowski624dd662009-10-24 15:52:44 +0200853 dev_dbg(&link->dev, "ray_dev_init ending\n");
John Daiker141fa612009-03-10 06:59:54 -0700854 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700855}
John Daiker141fa612009-03-10 06:59:54 -0700856
Linus Torvalds1da177e2005-04-16 15:20:36 -0700857/*===========================================================================*/
858static int ray_dev_config(struct net_device *dev, struct ifmap *map)
859{
John Daiker141fa612009-03-10 06:59:54 -0700860 ray_dev_t *local = netdev_priv(dev);
861 struct pcmcia_device *link = local->finder;
862 /* Dummy routine to satisfy device structure */
Dominik Brodowski624dd662009-10-24 15:52:44 +0200863 dev_dbg(&link->dev, "ray_dev_config(dev=%p,ifmap=%p)\n", dev, map);
John Daiker141fa612009-03-10 06:59:54 -0700864 if (!(pcmcia_dev_present(link))) {
Dominik Brodowski624dd662009-10-24 15:52:44 +0200865 dev_dbg(&link->dev, "ray_dev_config - device not present\n");
John Daiker141fa612009-03-10 06:59:54 -0700866 return -1;
867 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700868
John Daiker141fa612009-03-10 06:59:54 -0700869 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700870}
John Daiker141fa612009-03-10 06:59:54 -0700871
Linus Torvalds1da177e2005-04-16 15:20:36 -0700872/*===========================================================================*/
Stephen Hemmingerd0cf9c02009-08-31 19:50:57 +0000873static netdev_tx_t ray_dev_start_xmit(struct sk_buff *skb,
874 struct net_device *dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700875{
John Daiker141fa612009-03-10 06:59:54 -0700876 ray_dev_t *local = netdev_priv(dev);
877 struct pcmcia_device *link = local->finder;
878 short length = skb->len;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700879
Stephen Hemmingerd0cf9c02009-08-31 19:50:57 +0000880 if (!pcmcia_dev_present(link)) {
Dominik Brodowski624dd662009-10-24 15:52:44 +0200881 dev_dbg(&link->dev, "ray_dev_start_xmit - device not present\n");
Stephen Hemmingerd0cf9c02009-08-31 19:50:57 +0000882 dev_kfree_skb(skb);
883 return NETDEV_TX_OK;
John Daiker141fa612009-03-10 06:59:54 -0700884 }
Stephen Hemmingerd0cf9c02009-08-31 19:50:57 +0000885
Dominik Brodowski624dd662009-10-24 15:52:44 +0200886 dev_dbg(&link->dev, "ray_dev_start_xmit(skb=%p, dev=%p)\n", skb, dev);
John Daiker141fa612009-03-10 06:59:54 -0700887 if (local->authentication_state == NEED_TO_AUTH) {
Dominik Brodowski624dd662009-10-24 15:52:44 +0200888 dev_dbg(&link->dev, "ray_cs Sending authentication request.\n");
John Daiker141fa612009-03-10 06:59:54 -0700889 if (!build_auth_frame(local, local->auth_id, OPEN_AUTH_REQUEST)) {
890 local->authentication_state = AUTHENTICATED;
891 netif_stop_queue(dev);
Patrick McHardy5b548142009-06-12 06:22:29 +0000892 return NETDEV_TX_BUSY;
John Daiker141fa612009-03-10 06:59:54 -0700893 }
894 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700895
John Daiker141fa612009-03-10 06:59:54 -0700896 if (length < ETH_ZLEN) {
897 if (skb_padto(skb, ETH_ZLEN))
Patrick McHardy6ed10652009-06-23 06:03:08 +0000898 return NETDEV_TX_OK;
John Daiker141fa612009-03-10 06:59:54 -0700899 length = ETH_ZLEN;
900 }
901 switch (ray_hw_xmit(skb->data, length, dev, DATA_TYPE)) {
902 case XMIT_NO_CCS:
903 case XMIT_NEED_AUTH:
904 netif_stop_queue(dev);
Patrick McHardy5b548142009-06-12 06:22:29 +0000905 return NETDEV_TX_BUSY;
John Daiker141fa612009-03-10 06:59:54 -0700906 case XMIT_NO_INTR:
907 case XMIT_MSG_BAD:
908 case XMIT_OK:
909 default:
John Daiker141fa612009-03-10 06:59:54 -0700910 dev_kfree_skb(skb);
John Daiker141fa612009-03-10 06:59:54 -0700911 }
Stephen Hemmingerd0cf9c02009-08-31 19:50:57 +0000912
Patrick McHardy6ed10652009-06-23 06:03:08 +0000913 return NETDEV_TX_OK;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700914} /* ray_dev_start_xmit */
John Daiker141fa612009-03-10 06:59:54 -0700915
Linus Torvalds1da177e2005-04-16 15:20:36 -0700916/*===========================================================================*/
John Daiker141fa612009-03-10 06:59:54 -0700917static int ray_hw_xmit(unsigned char *data, int len, struct net_device *dev,
918 UCHAR msg_type)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700919{
John Daiker141fa612009-03-10 06:59:54 -0700920 ray_dev_t *local = netdev_priv(dev);
921 struct ccs __iomem *pccs;
922 int ccsindex;
923 int offset;
924 struct tx_msg __iomem *ptx; /* Address of xmit buffer in PC space */
925 short int addr; /* Address of xmit buffer in card space */
926
Dominik Brodowski624dd662009-10-24 15:52:44 +0200927 pr_debug("ray_hw_xmit(data=%p, len=%d, dev=%p)\n", data, len, dev);
John Daiker141fa612009-03-10 06:59:54 -0700928 if (len + TX_HEADER_LENGTH > TX_BUF_SIZE) {
929 printk(KERN_INFO "ray_hw_xmit packet too large: %d bytes\n",
930 len);
931 return XMIT_MSG_BAD;
932 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700933 switch (ccsindex = get_free_tx_ccs(local)) {
934 case ECCSBUSY:
Dominik Brodowski624dd662009-10-24 15:52:44 +0200935 pr_debug("ray_hw_xmit tx_ccs table busy\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700936 case ECCSFULL:
Dominik Brodowski624dd662009-10-24 15:52:44 +0200937 pr_debug("ray_hw_xmit No free tx ccs\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700938 case ECARDGONE:
John Daiker141fa612009-03-10 06:59:54 -0700939 netif_stop_queue(dev);
940 return XMIT_NO_CCS;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700941 default:
942 break;
943 }
John Daiker141fa612009-03-10 06:59:54 -0700944 addr = TX_BUF_BASE + (ccsindex << 11);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700945
John Daiker141fa612009-03-10 06:59:54 -0700946 if (msg_type == DATA_TYPE) {
947 local->stats.tx_bytes += len;
948 local->stats.tx_packets++;
949 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700950
John Daiker141fa612009-03-10 06:59:54 -0700951 ptx = local->sram + addr;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700952
John Daiker141fa612009-03-10 06:59:54 -0700953 ray_build_header(local, ptx, msg_type, data);
954 if (translate) {
955 offset = translate_frame(local, ptx, data, len);
956 } else { /* Encapsulate frame */
957 /* TBD TIB length will move address of ptx->var */
958 memcpy_toio(&ptx->var, data, len);
959 offset = 0;
960 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700961
John Daiker141fa612009-03-10 06:59:54 -0700962 /* fill in the CCS */
963 pccs = ccs_base(local) + ccsindex;
964 len += TX_HEADER_LENGTH + offset;
965 writeb(CCS_TX_REQUEST, &pccs->cmd);
966 writeb(addr >> 8, &pccs->var.tx_request.tx_data_ptr[0]);
967 writeb(local->tib_length, &pccs->var.tx_request.tx_data_ptr[1]);
968 writeb(len >> 8, &pccs->var.tx_request.tx_data_length[0]);
969 writeb(len & 0xff, &pccs->var.tx_request.tx_data_length[1]);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700970/* TBD still need psm_cam? */
John Daiker141fa612009-03-10 06:59:54 -0700971 writeb(PSM_CAM, &pccs->var.tx_request.pow_sav_mode);
972 writeb(local->net_default_tx_rate, &pccs->var.tx_request.tx_rate);
973 writeb(0, &pccs->var.tx_request.antenna);
Dominik Brodowski624dd662009-10-24 15:52:44 +0200974 pr_debug("ray_hw_xmit default_tx_rate = 0x%x\n",
John Daiker141fa612009-03-10 06:59:54 -0700975 local->net_default_tx_rate);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700976
John Daiker141fa612009-03-10 06:59:54 -0700977 /* Interrupt the firmware to process the command */
978 if (interrupt_ecf(local, ccsindex)) {
Dominik Brodowski624dd662009-10-24 15:52:44 +0200979 pr_debug("ray_hw_xmit failed - ECF not ready for intr\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700980/* TBD very inefficient to copy packet to buffer, and then not
981 send it, but the alternative is to queue the messages and that
982 won't be done for a while. Maybe set tbusy until a CCS is free?
983*/
John Daiker141fa612009-03-10 06:59:54 -0700984 writeb(CCS_BUFFER_FREE, &pccs->buffer_status);
985 return XMIT_NO_INTR;
986 }
987 return XMIT_OK;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700988} /* end ray_hw_xmit */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700989
John Daiker141fa612009-03-10 06:59:54 -0700990/*===========================================================================*/
991static int translate_frame(ray_dev_t *local, struct tx_msg __iomem *ptx,
992 unsigned char *data, int len)
993{
994 __be16 proto = ((struct ethhdr *)data)->h_proto;
995 if (ntohs(proto) >= 1536) { /* DIX II ethernet frame */
Dominik Brodowski624dd662009-10-24 15:52:44 +0200996 pr_debug("ray_cs translate_frame DIX II\n");
John Daiker141fa612009-03-10 06:59:54 -0700997 /* Copy LLC header to card buffer */
998 memcpy_toio(&ptx->var, eth2_llc, sizeof(eth2_llc));
999 memcpy_toio(((void __iomem *)&ptx->var) + sizeof(eth2_llc),
1000 (UCHAR *) &proto, 2);
1001 if (proto == htons(ETH_P_AARP) || proto == htons(ETH_P_IPX)) {
1002 /* This is the selective translation table, only 2 entries */
1003 writeb(0xf8,
1004 &((struct snaphdr_t __iomem *)ptx->var)->org[3]);
1005 }
1006 /* Copy body of ethernet packet without ethernet header */
1007 memcpy_toio((void __iomem *)&ptx->var +
1008 sizeof(struct snaphdr_t), data + ETH_HLEN,
1009 len - ETH_HLEN);
1010 return (int)sizeof(struct snaphdr_t) - ETH_HLEN;
1011 } else { /* already 802 type, and proto is length */
Dominik Brodowski624dd662009-10-24 15:52:44 +02001012 pr_debug("ray_cs translate_frame 802\n");
John Daiker141fa612009-03-10 06:59:54 -07001013 if (proto == htons(0xffff)) { /* evil netware IPX 802.3 without LLC */
Dominik Brodowski624dd662009-10-24 15:52:44 +02001014 pr_debug("ray_cs translate_frame evil IPX\n");
John Daiker141fa612009-03-10 06:59:54 -07001015 memcpy_toio(&ptx->var, data + ETH_HLEN, len - ETH_HLEN);
1016 return 0 - ETH_HLEN;
1017 }
1018 memcpy_toio(&ptx->var, data + ETH_HLEN, len - ETH_HLEN);
1019 return 0 - ETH_HLEN;
1020 }
1021 /* TBD do other frame types */
1022} /* end translate_frame */
1023
1024/*===========================================================================*/
1025static void ray_build_header(ray_dev_t *local, struct tx_msg __iomem *ptx,
1026 UCHAR msg_type, unsigned char *data)
1027{
1028 writeb(PROTOCOL_VER | msg_type, &ptx->mac.frame_ctl_1);
1029/*** IEEE 802.11 Address field assignments *************
1030 TODS FROMDS addr_1 addr_2 addr_3 addr_4
1031Adhoc 0 0 dest src (terminal) BSSID N/A
1032AP to Terminal 0 1 dest AP(BSSID) source N/A
1033Terminal to AP 1 0 AP(BSSID) src (terminal) dest N/A
1034AP to AP 1 1 dest AP src AP dest source
1035*******************************************************/
1036 if (local->net_type == ADHOC) {
1037 writeb(0, &ptx->mac.frame_ctl_2);
1038 memcpy_toio(ptx->mac.addr_1, ((struct ethhdr *)data)->h_dest,
1039 2 * ADDRLEN);
1040 memcpy_toio(ptx->mac.addr_3, local->bss_id, ADDRLEN);
1041 } else { /* infrastructure */
1042
1043 if (local->sparm.b4.a_acting_as_ap_status) {
1044 writeb(FC2_FROM_DS, &ptx->mac.frame_ctl_2);
1045 memcpy_toio(ptx->mac.addr_1,
1046 ((struct ethhdr *)data)->h_dest, ADDRLEN);
1047 memcpy_toio(ptx->mac.addr_2, local->bss_id, 6);
1048 memcpy_toio(ptx->mac.addr_3,
1049 ((struct ethhdr *)data)->h_source, ADDRLEN);
1050 } else { /* Terminal */
1051
1052 writeb(FC2_TO_DS, &ptx->mac.frame_ctl_2);
1053 memcpy_toio(ptx->mac.addr_1, local->bss_id, ADDRLEN);
1054 memcpy_toio(ptx->mac.addr_2,
1055 ((struct ethhdr *)data)->h_source, ADDRLEN);
1056 memcpy_toio(ptx->mac.addr_3,
1057 ((struct ethhdr *)data)->h_dest, ADDRLEN);
1058 }
1059 }
1060} /* end encapsulate_frame */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001061
1062/*===========================================================================*/
1063
1064static void netdev_get_drvinfo(struct net_device *dev,
1065 struct ethtool_drvinfo *info)
1066{
1067 strcpy(info->driver, "ray_cs");
1068}
1069
Jeff Garzik7282d492006-09-13 14:30:00 -04001070static const struct ethtool_ops netdev_ethtool_ops = {
John Daiker141fa612009-03-10 06:59:54 -07001071 .get_drvinfo = netdev_get_drvinfo,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001072};
1073
1074/*====================================================================*/
1075
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001076/*------------------------------------------------------------------*/
1077/*
1078 * Wireless Handler : get protocol name
1079 */
Joe Perches43ead782010-03-18 18:29:40 -07001080static int ray_get_name(struct net_device *dev, struct iw_request_info *info,
1081 union iwreq_data *wrqu, char *extra)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001082{
Joe Perches43ead782010-03-18 18:29:40 -07001083 strcpy(wrqu->name, "IEEE 802.11-FH");
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001084 return 0;
1085}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001086
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001087/*------------------------------------------------------------------*/
1088/*
1089 * Wireless Handler : set frequency
1090 */
Joe Perches43ead782010-03-18 18:29:40 -07001091static int ray_set_freq(struct net_device *dev, struct iw_request_info *info,
1092 union iwreq_data *wrqu, char *extra)
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001093{
Yoann Padioleau6dbc9c82007-08-03 19:37:16 +02001094 ray_dev_t *local = netdev_priv(dev);
John Daiker141fa612009-03-10 06:59:54 -07001095 int err = -EINPROGRESS; /* Call commit handler */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001096
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001097 /* Reject if card is already initialised */
John Daiker141fa612009-03-10 06:59:54 -07001098 if (local->card_status != CARD_AWAITING_PARAM)
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001099 return -EBUSY;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001100
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001101 /* Setting by channel number */
Joe Perches43ead782010-03-18 18:29:40 -07001102 if ((wrqu->freq.m > USA_HOP_MOD) || (wrqu->freq.e > 0))
Linus Torvalds1da177e2005-04-16 15:20:36 -07001103 err = -EOPNOTSUPP;
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001104 else
Joe Perches43ead782010-03-18 18:29:40 -07001105 local->sparm.b5.a_hop_pattern = wrqu->freq.m;
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001106
1107 return err;
1108}
John Daiker141fa612009-03-10 06:59:54 -07001109
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001110/*------------------------------------------------------------------*/
1111/*
1112 * Wireless Handler : get frequency
1113 */
Joe Perches43ead782010-03-18 18:29:40 -07001114static int ray_get_freq(struct net_device *dev, struct iw_request_info *info,
1115 union iwreq_data *wrqu, char *extra)
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001116{
Yoann Padioleau6dbc9c82007-08-03 19:37:16 +02001117 ray_dev_t *local = netdev_priv(dev);
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001118
Joe Perches43ead782010-03-18 18:29:40 -07001119 wrqu->freq.m = local->sparm.b5.a_hop_pattern;
1120 wrqu->freq.e = 0;
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001121 return 0;
1122}
1123
1124/*------------------------------------------------------------------*/
1125/*
1126 * Wireless Handler : set ESSID
1127 */
Joe Perches43ead782010-03-18 18:29:40 -07001128static int ray_set_essid(struct net_device *dev, struct iw_request_info *info,
1129 union iwreq_data *wrqu, char *extra)
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001130{
Yoann Padioleau6dbc9c82007-08-03 19:37:16 +02001131 ray_dev_t *local = netdev_priv(dev);
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001132
1133 /* Reject if card is already initialised */
John Daiker141fa612009-03-10 06:59:54 -07001134 if (local->card_status != CARD_AWAITING_PARAM)
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001135 return -EBUSY;
1136
1137 /* Check if we asked for `any' */
Joe Perches43ead782010-03-18 18:29:40 -07001138 if (wrqu->essid.flags == 0)
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001139 /* Corey : can you do that ? */
1140 return -EOPNOTSUPP;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001141
Joe Perches43ead782010-03-18 18:29:40 -07001142 /* Check the size of the string */
1143 if (wrqu->essid.length > IW_ESSID_MAX_SIZE)
1144 return -E2BIG;
1145
1146 /* Set the ESSID in the card */
1147 memset(local->sparm.b5.a_current_ess_id, 0, IW_ESSID_MAX_SIZE);
1148 memcpy(local->sparm.b5.a_current_ess_id, extra, wrqu->essid.length);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001149
John Daiker141fa612009-03-10 06:59:54 -07001150 return -EINPROGRESS; /* Call commit handler */
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001151}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001152
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001153/*------------------------------------------------------------------*/
1154/*
1155 * Wireless Handler : get ESSID
1156 */
Joe Perches43ead782010-03-18 18:29:40 -07001157static int ray_get_essid(struct net_device *dev, struct iw_request_info *info,
1158 union iwreq_data *wrqu, char *extra)
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001159{
Yoann Padioleau6dbc9c82007-08-03 19:37:16 +02001160 ray_dev_t *local = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001161
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001162 /* Get the essid that was set */
1163 memcpy(extra, local->sparm.b5.a_current_ess_id, IW_ESSID_MAX_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001164
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001165 /* Push it out ! */
Joe Perches43ead782010-03-18 18:29:40 -07001166 wrqu->essid.length = strlen(extra);
1167 wrqu->essid.flags = 1; /* active */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001168
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001169 return 0;
1170}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001171
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001172/*------------------------------------------------------------------*/
1173/*
1174 * Wireless Handler : get AP address
1175 */
Joe Perches43ead782010-03-18 18:29:40 -07001176static int ray_get_wap(struct net_device *dev, struct iw_request_info *info,
1177 union iwreq_data *wrqu, char *extra)
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001178{
Yoann Padioleau6dbc9c82007-08-03 19:37:16 +02001179 ray_dev_t *local = netdev_priv(dev);
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001180
Joe Perches43ead782010-03-18 18:29:40 -07001181 memcpy(wrqu->ap_addr.sa_data, local->bss_id, ETH_ALEN);
1182 wrqu->ap_addr.sa_family = ARPHRD_ETHER;
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001183
1184 return 0;
1185}
1186
1187/*------------------------------------------------------------------*/
1188/*
1189 * Wireless Handler : set Bit-Rate
1190 */
Joe Perches43ead782010-03-18 18:29:40 -07001191static int ray_set_rate(struct net_device *dev, struct iw_request_info *info,
1192 union iwreq_data *wrqu, char *extra)
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001193{
Yoann Padioleau6dbc9c82007-08-03 19:37:16 +02001194 ray_dev_t *local = netdev_priv(dev);
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001195
1196 /* Reject if card is already initialised */
John Daiker141fa612009-03-10 06:59:54 -07001197 if (local->card_status != CARD_AWAITING_PARAM)
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001198 return -EBUSY;
1199
1200 /* Check if rate is in range */
Joe Perches43ead782010-03-18 18:29:40 -07001201 if ((wrqu->bitrate.value != 1000000) && (wrqu->bitrate.value != 2000000))
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001202 return -EINVAL;
1203
1204 /* Hack for 1.5 Mb/s instead of 2 Mb/s */
John Daiker141fa612009-03-10 06:59:54 -07001205 if ((local->fw_ver == 0x55) && /* Please check */
Joe Perches43ead782010-03-18 18:29:40 -07001206 (wrqu->bitrate.value == 2000000))
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001207 local->net_default_tx_rate = 3;
1208 else
Joe Perches43ead782010-03-18 18:29:40 -07001209 local->net_default_tx_rate = wrqu->bitrate.value / 500000;
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001210
1211 return 0;
1212}
1213
1214/*------------------------------------------------------------------*/
1215/*
1216 * Wireless Handler : get Bit-Rate
1217 */
Joe Perches43ead782010-03-18 18:29:40 -07001218static int ray_get_rate(struct net_device *dev, struct iw_request_info *info,
1219 union iwreq_data *wrqu, char *extra)
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001220{
Yoann Padioleau6dbc9c82007-08-03 19:37:16 +02001221 ray_dev_t *local = netdev_priv(dev);
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001222
John Daiker141fa612009-03-10 06:59:54 -07001223 if (local->net_default_tx_rate == 3)
Joe Perches43ead782010-03-18 18:29:40 -07001224 wrqu->bitrate.value = 2000000; /* Hum... */
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001225 else
Joe Perches43ead782010-03-18 18:29:40 -07001226 wrqu->bitrate.value = local->net_default_tx_rate * 500000;
1227 wrqu->bitrate.fixed = 0; /* We are in auto mode */
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001228
1229 return 0;
1230}
1231
1232/*------------------------------------------------------------------*/
1233/*
1234 * Wireless Handler : set RTS threshold
1235 */
Joe Perches43ead782010-03-18 18:29:40 -07001236static int ray_set_rts(struct net_device *dev, struct iw_request_info *info,
1237 union iwreq_data *wrqu, char *extra)
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001238{
Yoann Padioleau6dbc9c82007-08-03 19:37:16 +02001239 ray_dev_t *local = netdev_priv(dev);
Joe Perches43ead782010-03-18 18:29:40 -07001240 int rthr = wrqu->rts.value;
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001241
1242 /* Reject if card is already initialised */
John Daiker141fa612009-03-10 06:59:54 -07001243 if (local->card_status != CARD_AWAITING_PARAM)
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001244 return -EBUSY;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001245
1246 /* if(wrq->u.rts.fixed == 0) we should complain */
Joe Perches43ead782010-03-18 18:29:40 -07001247 if (wrqu->rts.disabled)
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001248 rthr = 32767;
1249 else {
John Daiker141fa612009-03-10 06:59:54 -07001250 if ((rthr < 0) || (rthr > 2347)) /* What's the max packet size ??? */
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001251 return -EINVAL;
1252 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001253 local->sparm.b5.a_rts_threshold[0] = (rthr >> 8) & 0xFF;
1254 local->sparm.b5.a_rts_threshold[1] = rthr & 0xFF;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001255
John Daiker141fa612009-03-10 06:59:54 -07001256 return -EINPROGRESS; /* Call commit handler */
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001257}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001258
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001259/*------------------------------------------------------------------*/
1260/*
1261 * Wireless Handler : get RTS threshold
1262 */
Joe Perches43ead782010-03-18 18:29:40 -07001263static int ray_get_rts(struct net_device *dev, struct iw_request_info *info,
1264 union iwreq_data *wrqu, char *extra)
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001265{
Yoann Padioleau6dbc9c82007-08-03 19:37:16 +02001266 ray_dev_t *local = netdev_priv(dev);
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001267
Joe Perches43ead782010-03-18 18:29:40 -07001268 wrqu->rts.value = (local->sparm.b5.a_rts_threshold[0] << 8)
John Daiker141fa612009-03-10 06:59:54 -07001269 + local->sparm.b5.a_rts_threshold[1];
Joe Perches43ead782010-03-18 18:29:40 -07001270 wrqu->rts.disabled = (wrqu->rts.value == 32767);
1271 wrqu->rts.fixed = 1;
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001272
1273 return 0;
1274}
1275
1276/*------------------------------------------------------------------*/
1277/*
1278 * Wireless Handler : set Fragmentation threshold
1279 */
Joe Perches43ead782010-03-18 18:29:40 -07001280static int ray_set_frag(struct net_device *dev, struct iw_request_info *info,
1281 union iwreq_data *wrqu, char *extra)
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001282{
Yoann Padioleau6dbc9c82007-08-03 19:37:16 +02001283 ray_dev_t *local = netdev_priv(dev);
Joe Perches43ead782010-03-18 18:29:40 -07001284 int fthr = wrqu->frag.value;
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001285
1286 /* Reject if card is already initialised */
John Daiker141fa612009-03-10 06:59:54 -07001287 if (local->card_status != CARD_AWAITING_PARAM)
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001288 return -EBUSY;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001289
1290 /* if(wrq->u.frag.fixed == 0) should complain */
Joe Perches43ead782010-03-18 18:29:40 -07001291 if (wrqu->frag.disabled)
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001292 fthr = 32767;
1293 else {
John Daiker141fa612009-03-10 06:59:54 -07001294 if ((fthr < 256) || (fthr > 2347)) /* To check out ! */
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001295 return -EINVAL;
1296 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001297 local->sparm.b5.a_frag_threshold[0] = (fthr >> 8) & 0xFF;
1298 local->sparm.b5.a_frag_threshold[1] = fthr & 0xFF;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001299
John Daiker141fa612009-03-10 06:59:54 -07001300 return -EINPROGRESS; /* Call commit handler */
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001301}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001302
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001303/*------------------------------------------------------------------*/
1304/*
1305 * Wireless Handler : get Fragmentation threshold
1306 */
Joe Perches43ead782010-03-18 18:29:40 -07001307static int ray_get_frag(struct net_device *dev, struct iw_request_info *info,
1308 union iwreq_data *wrqu, char *extra)
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001309{
Yoann Padioleau6dbc9c82007-08-03 19:37:16 +02001310 ray_dev_t *local = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001311
Joe Perches43ead782010-03-18 18:29:40 -07001312 wrqu->frag.value = (local->sparm.b5.a_frag_threshold[0] << 8)
John Daiker141fa612009-03-10 06:59:54 -07001313 + local->sparm.b5.a_frag_threshold[1];
Joe Perches43ead782010-03-18 18:29:40 -07001314 wrqu->frag.disabled = (wrqu->frag.value == 32767);
1315 wrqu->frag.fixed = 1;
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001316
1317 return 0;
1318}
1319
1320/*------------------------------------------------------------------*/
1321/*
1322 * Wireless Handler : set Mode of Operation
1323 */
Joe Perches43ead782010-03-18 18:29:40 -07001324static int ray_set_mode(struct net_device *dev, struct iw_request_info *info,
1325 union iwreq_data *wrqu, char *extra)
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001326{
Yoann Padioleau6dbc9c82007-08-03 19:37:16 +02001327 ray_dev_t *local = netdev_priv(dev);
John Daiker141fa612009-03-10 06:59:54 -07001328 int err = -EINPROGRESS; /* Call commit handler */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001329 char card_mode = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001330
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001331 /* Reject if card is already initialised */
John Daiker141fa612009-03-10 06:59:54 -07001332 if (local->card_status != CARD_AWAITING_PARAM)
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001333 return -EBUSY;
1334
Joe Perches43ead782010-03-18 18:29:40 -07001335 switch (wrqu->mode) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001336 case IW_MODE_ADHOC:
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001337 card_mode = 0;
John Daiker141fa612009-03-10 06:59:54 -07001338 /* Fall through */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001339 case IW_MODE_INFRA:
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001340 local->sparm.b5.a_network_type = card_mode;
1341 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001342 default:
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001343 err = -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001344 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001345
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001346 return err;
1347}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001348
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001349/*------------------------------------------------------------------*/
1350/*
1351 * Wireless Handler : get Mode of Operation
1352 */
Joe Perches43ead782010-03-18 18:29:40 -07001353static int ray_get_mode(struct net_device *dev, struct iw_request_info *info,
1354 union iwreq_data *wrqu, char *extra)
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001355{
Yoann Padioleau6dbc9c82007-08-03 19:37:16 +02001356 ray_dev_t *local = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001357
John Daiker141fa612009-03-10 06:59:54 -07001358 if (local->sparm.b5.a_network_type)
Joe Perches43ead782010-03-18 18:29:40 -07001359 wrqu->mode = IW_MODE_INFRA;
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001360 else
Joe Perches43ead782010-03-18 18:29:40 -07001361 wrqu->mode = IW_MODE_ADHOC;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001362
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001363 return 0;
1364}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001365
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001366/*------------------------------------------------------------------*/
1367/*
1368 * Wireless Handler : get range info
1369 */
Joe Perches43ead782010-03-18 18:29:40 -07001370static int ray_get_range(struct net_device *dev, struct iw_request_info *info,
1371 union iwreq_data *wrqu, char *extra)
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001372{
John Daiker141fa612009-03-10 06:59:54 -07001373 struct iw_range *range = (struct iw_range *)extra;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001374
Joe Perches43ead782010-03-18 18:29:40 -07001375 memset(range, 0, sizeof(struct iw_range));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001376
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001377 /* Set the length (very important for backward compatibility) */
Joe Perches43ead782010-03-18 18:29:40 -07001378 wrqu->data.length = sizeof(struct iw_range);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001379
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001380 /* Set the Wireless Extension versions */
1381 range->we_version_compiled = WIRELESS_EXT;
1382 range->we_version_source = 9;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001383
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001384 /* Set information in the range struct */
1385 range->throughput = 1.1 * 1000 * 1000; /* Put the right number here */
John Daiker141fa612009-03-10 06:59:54 -07001386 range->num_channels = hop_pattern_length[(int)country];
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001387 range->num_frequency = 0;
1388 range->max_qual.qual = 0;
1389 range->max_qual.level = 255; /* What's the correct value ? */
1390 range->max_qual.noise = 255; /* Idem */
1391 range->num_bitrates = 2;
1392 range->bitrate[0] = 1000000; /* 1 Mb/s */
1393 range->bitrate[1] = 2000000; /* 2 Mb/s */
1394 return 0;
1395}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001396
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001397/*------------------------------------------------------------------*/
1398/*
1399 * Wireless Private Handler : set framing mode
1400 */
Joe Perches43ead782010-03-18 18:29:40 -07001401static int ray_set_framing(struct net_device *dev, struct iw_request_info *info,
John Daiker141fa612009-03-10 06:59:54 -07001402 union iwreq_data *wrqu, char *extra)
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001403{
1404 translate = *(extra); /* Set framing mode */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001405
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001406 return 0;
1407}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001408
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001409/*------------------------------------------------------------------*/
1410/*
1411 * Wireless Private Handler : get framing mode
1412 */
Joe Perches43ead782010-03-18 18:29:40 -07001413static int ray_get_framing(struct net_device *dev, struct iw_request_info *info,
John Daiker141fa612009-03-10 06:59:54 -07001414 union iwreq_data *wrqu, char *extra)
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001415{
1416 *(extra) = translate;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001417
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001418 return 0;
1419}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001420
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001421/*------------------------------------------------------------------*/
1422/*
1423 * Wireless Private Handler : get country
1424 */
Joe Perches43ead782010-03-18 18:29:40 -07001425static int ray_get_country(struct net_device *dev, struct iw_request_info *info,
John Daiker141fa612009-03-10 06:59:54 -07001426 union iwreq_data *wrqu, char *extra)
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001427{
1428 *(extra) = country;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001429
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001430 return 0;
1431}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001432
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001433/*------------------------------------------------------------------*/
1434/*
1435 * Commit handler : called after a bunch of SET operations
1436 */
Joe Perches43ead782010-03-18 18:29:40 -07001437static int ray_commit(struct net_device *dev, struct iw_request_info *info,
1438 union iwreq_data *wrqu, char *extra)
1439{
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001440 return 0;
1441}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001442
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001443/*------------------------------------------------------------------*/
1444/*
1445 * Stats handler : return Wireless Stats
1446 */
John Daiker141fa612009-03-10 06:59:54 -07001447static iw_stats *ray_get_wireless_stats(struct net_device *dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001448{
John Daiker141fa612009-03-10 06:59:54 -07001449 ray_dev_t *local = netdev_priv(dev);
1450 struct pcmcia_device *link = local->finder;
1451 struct status __iomem *p = local->sram + STATUS_BASE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001452
John Daiker141fa612009-03-10 06:59:54 -07001453 local->wstats.status = local->card_status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001454#ifdef WIRELESS_SPY
John Daiker141fa612009-03-10 06:59:54 -07001455 if ((local->spy_data.spy_number > 0)
1456 && (local->sparm.b5.a_network_type == 0)) {
1457 /* Get it from the first node in spy list */
1458 local->wstats.qual.qual = local->spy_data.spy_stat[0].qual;
1459 local->wstats.qual.level = local->spy_data.spy_stat[0].level;
1460 local->wstats.qual.noise = local->spy_data.spy_stat[0].noise;
1461 local->wstats.qual.updated =
1462 local->spy_data.spy_stat[0].updated;
1463 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001464#endif /* WIRELESS_SPY */
1465
John Daiker141fa612009-03-10 06:59:54 -07001466 if (pcmcia_dev_present(link)) {
1467 local->wstats.qual.noise = readb(&p->rxnoise);
1468 local->wstats.qual.updated |= 4;
1469 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001470
John Daiker141fa612009-03-10 06:59:54 -07001471 return &local->wstats;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001472} /* end ray_get_wireless_stats */
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001473
1474/*------------------------------------------------------------------*/
1475/*
1476 * Structures to export the Wireless Handlers
1477 */
1478
John Daiker141fa612009-03-10 06:59:54 -07001479static const iw_handler ray_handler[] = {
Joe Perches43ead782010-03-18 18:29:40 -07001480 IW_HANDLER(SIOCSIWCOMMIT, ray_commit),
1481 IW_HANDLER(SIOCGIWNAME, ray_get_name),
1482 IW_HANDLER(SIOCSIWFREQ, ray_set_freq),
1483 IW_HANDLER(SIOCGIWFREQ, ray_get_freq),
1484 IW_HANDLER(SIOCSIWMODE, ray_set_mode),
1485 IW_HANDLER(SIOCGIWMODE, ray_get_mode),
1486 IW_HANDLER(SIOCGIWRANGE, ray_get_range),
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001487#ifdef WIRELESS_SPY
Joe Perches270020e2010-03-18 18:29:37 -07001488 IW_HANDLER(SIOCSIWSPY, iw_handler_set_spy),
1489 IW_HANDLER(SIOCGIWSPY, iw_handler_get_spy),
1490 IW_HANDLER(SIOCSIWTHRSPY, iw_handler_set_thrspy),
1491 IW_HANDLER(SIOCGIWTHRSPY, iw_handler_get_thrspy),
John Daiker141fa612009-03-10 06:59:54 -07001492#endif /* WIRELESS_SPY */
Joe Perches43ead782010-03-18 18:29:40 -07001493 IW_HANDLER(SIOCGIWAP, ray_get_wap),
1494 IW_HANDLER(SIOCSIWESSID, ray_set_essid),
1495 IW_HANDLER(SIOCGIWESSID, ray_get_essid),
1496 IW_HANDLER(SIOCSIWRATE, ray_set_rate),
1497 IW_HANDLER(SIOCGIWRATE, ray_get_rate),
1498 IW_HANDLER(SIOCSIWRTS, ray_set_rts),
1499 IW_HANDLER(SIOCGIWRTS, ray_get_rts),
1500 IW_HANDLER(SIOCSIWFRAG, ray_set_frag),
1501 IW_HANDLER(SIOCGIWFRAG, ray_get_frag),
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001502};
1503
John Daiker141fa612009-03-10 06:59:54 -07001504#define SIOCSIPFRAMING SIOCIWFIRSTPRIV /* Set framing mode */
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001505#define SIOCGIPFRAMING SIOCIWFIRSTPRIV + 1 /* Get framing mode */
1506#define SIOCGIPCOUNTRY SIOCIWFIRSTPRIV + 3 /* Get country code */
1507
John Daiker141fa612009-03-10 06:59:54 -07001508static const iw_handler ray_private_handler[] = {
Joe Perches43ead782010-03-18 18:29:40 -07001509 [0] = ray_set_framing,
1510 [1] = ray_get_framing,
1511 [3] = ray_get_country,
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001512};
1513
John Daiker141fa612009-03-10 06:59:54 -07001514static const struct iw_priv_args ray_private_args[] = {
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001515/* cmd, set_args, get_args, name */
John Daiker141fa612009-03-10 06:59:54 -07001516 {SIOCSIPFRAMING, IW_PRIV_TYPE_BYTE | IW_PRIV_SIZE_FIXED | 1, 0,
1517 "set_framing"},
1518 {SIOCGIPFRAMING, 0, IW_PRIV_TYPE_BYTE | IW_PRIV_SIZE_FIXED | 1,
1519 "get_framing"},
1520 {SIOCGIPCOUNTRY, 0, IW_PRIV_TYPE_BYTE | IW_PRIV_SIZE_FIXED | 1,
1521 "get_country"},
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001522};
1523
John Daiker141fa612009-03-10 06:59:54 -07001524static const struct iw_handler_def ray_handler_def = {
1525 .num_standard = ARRAY_SIZE(ray_handler),
1526 .num_private = ARRAY_SIZE(ray_private_handler),
Denis Chengff8ac602007-09-02 18:30:18 +08001527 .num_private_args = ARRAY_SIZE(ray_private_args),
John Daiker141fa612009-03-10 06:59:54 -07001528 .standard = ray_handler,
1529 .private = ray_private_handler,
1530 .private_args = ray_private_args,
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001531 .get_wireless_stats = ray_get_wireless_stats,
1532};
1533
Linus Torvalds1da177e2005-04-16 15:20:36 -07001534/*===========================================================================*/
1535static int ray_open(struct net_device *dev)
1536{
John Daiker141fa612009-03-10 06:59:54 -07001537 ray_dev_t *local = netdev_priv(dev);
1538 struct pcmcia_device *link;
1539 link = local->finder;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001540
Dominik Brodowski624dd662009-10-24 15:52:44 +02001541 dev_dbg(&link->dev, "ray_open('%s')\n", dev->name);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001542
John Daiker141fa612009-03-10 06:59:54 -07001543 if (link->open == 0)
1544 local->num_multi = 0;
1545 link->open++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001546
John Daiker141fa612009-03-10 06:59:54 -07001547 /* If the card is not started, time to start it ! - Jean II */
1548 if (local->card_status == CARD_AWAITING_PARAM) {
1549 int i;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001550
Dominik Brodowski624dd662009-10-24 15:52:44 +02001551 dev_dbg(&link->dev, "ray_open: doing init now !\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001552
John Daiker141fa612009-03-10 06:59:54 -07001553 /* Download startup parameters */
1554 if ((i = dl_startup_params(dev)) < 0) {
1555 printk(KERN_INFO
1556 "ray_dev_init dl_startup_params failed - "
1557 "returns 0x%x\n", i);
1558 return -1;
1559 }
1560 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001561
John Daiker141fa612009-03-10 06:59:54 -07001562 if (sniffer)
1563 netif_stop_queue(dev);
1564 else
1565 netif_start_queue(dev);
1566
Dominik Brodowski624dd662009-10-24 15:52:44 +02001567 dev_dbg(&link->dev, "ray_open ending\n");
John Daiker141fa612009-03-10 06:59:54 -07001568 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001569} /* end ray_open */
John Daiker141fa612009-03-10 06:59:54 -07001570
Linus Torvalds1da177e2005-04-16 15:20:36 -07001571/*===========================================================================*/
1572static int ray_dev_close(struct net_device *dev)
1573{
John Daiker141fa612009-03-10 06:59:54 -07001574 ray_dev_t *local = netdev_priv(dev);
1575 struct pcmcia_device *link;
1576 link = local->finder;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001577
Dominik Brodowski624dd662009-10-24 15:52:44 +02001578 dev_dbg(&link->dev, "ray_dev_close('%s')\n", dev->name);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001579
John Daiker141fa612009-03-10 06:59:54 -07001580 link->open--;
1581 netif_stop_queue(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001582
John Daiker141fa612009-03-10 06:59:54 -07001583 /* In here, we should stop the hardware (stop card from beeing active)
1584 * and set local->card_status to CARD_AWAITING_PARAM, so that while the
1585 * card is closed we can chage its configuration.
1586 * Probably also need a COR reset to get sane state - Jean II */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001587
John Daiker141fa612009-03-10 06:59:54 -07001588 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001589} /* end ray_dev_close */
John Daiker141fa612009-03-10 06:59:54 -07001590
Linus Torvalds1da177e2005-04-16 15:20:36 -07001591/*===========================================================================*/
John Daiker141fa612009-03-10 06:59:54 -07001592static void ray_reset(struct net_device *dev)
1593{
Dominik Brodowski624dd662009-10-24 15:52:44 +02001594 pr_debug("ray_reset entered\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001595}
John Daiker141fa612009-03-10 06:59:54 -07001596
Linus Torvalds1da177e2005-04-16 15:20:36 -07001597/*===========================================================================*/
1598/* Cause a firmware interrupt if it is ready for one */
1599/* Return nonzero if not ready */
1600static int interrupt_ecf(ray_dev_t *local, int ccs)
1601{
John Daiker141fa612009-03-10 06:59:54 -07001602 int i = 50;
1603 struct pcmcia_device *link = local->finder;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001604
John Daiker141fa612009-03-10 06:59:54 -07001605 if (!(pcmcia_dev_present(link))) {
Dominik Brodowski624dd662009-10-24 15:52:44 +02001606 dev_dbg(&link->dev, "ray_cs interrupt_ecf - device not present\n");
John Daiker141fa612009-03-10 06:59:54 -07001607 return -1;
1608 }
Dominik Brodowski624dd662009-10-24 15:52:44 +02001609 dev_dbg(&link->dev, "interrupt_ecf(local=%p, ccs = 0x%x\n", local, ccs);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001610
John Daiker141fa612009-03-10 06:59:54 -07001611 while (i &&
1612 (readb(local->amem + CIS_OFFSET + ECF_INTR_OFFSET) &
1613 ECF_INTR_SET))
1614 i--;
1615 if (i == 0) {
Dominik Brodowski624dd662009-10-24 15:52:44 +02001616 dev_dbg(&link->dev, "ray_cs interrupt_ecf card not ready for interrupt\n");
John Daiker141fa612009-03-10 06:59:54 -07001617 return -1;
1618 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001619 /* Fill the mailbox, then kick the card */
John Daiker141fa612009-03-10 06:59:54 -07001620 writeb(ccs, local->sram + SCB_BASE);
1621 writeb(ECF_INTR_SET, local->amem + CIS_OFFSET + ECF_INTR_OFFSET);
1622 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001623} /* interrupt_ecf */
John Daiker141fa612009-03-10 06:59:54 -07001624
Linus Torvalds1da177e2005-04-16 15:20:36 -07001625/*===========================================================================*/
1626/* Get next free transmit CCS */
1627/* Return - index of current tx ccs */
1628static int get_free_tx_ccs(ray_dev_t *local)
1629{
John Daiker141fa612009-03-10 06:59:54 -07001630 int i;
1631 struct ccs __iomem *pccs = ccs_base(local);
1632 struct pcmcia_device *link = local->finder;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001633
John Daiker141fa612009-03-10 06:59:54 -07001634 if (!(pcmcia_dev_present(link))) {
Dominik Brodowski624dd662009-10-24 15:52:44 +02001635 dev_dbg(&link->dev, "ray_cs get_free_tx_ccs - device not present\n");
John Daiker141fa612009-03-10 06:59:54 -07001636 return ECARDGONE;
1637 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001638
John Daiker141fa612009-03-10 06:59:54 -07001639 if (test_and_set_bit(0, &local->tx_ccs_lock)) {
Dominik Brodowski624dd662009-10-24 15:52:44 +02001640 dev_dbg(&link->dev, "ray_cs tx_ccs_lock busy\n");
John Daiker141fa612009-03-10 06:59:54 -07001641 return ECCSBUSY;
1642 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001643
John Daiker141fa612009-03-10 06:59:54 -07001644 for (i = 0; i < NUMBER_OF_TX_CCS; i++) {
1645 if (readb(&(pccs + i)->buffer_status) == CCS_BUFFER_FREE) {
1646 writeb(CCS_BUFFER_BUSY, &(pccs + i)->buffer_status);
1647 writeb(CCS_END_LIST, &(pccs + i)->link);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001648 local->tx_ccs_lock = 0;
John Daiker141fa612009-03-10 06:59:54 -07001649 return i;
1650 }
1651 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001652 local->tx_ccs_lock = 0;
Dominik Brodowski624dd662009-10-24 15:52:44 +02001653 dev_dbg(&link->dev, "ray_cs ERROR no free tx CCS for raylink card\n");
John Daiker141fa612009-03-10 06:59:54 -07001654 return ECCSFULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001655} /* get_free_tx_ccs */
John Daiker141fa612009-03-10 06:59:54 -07001656
Linus Torvalds1da177e2005-04-16 15:20:36 -07001657/*===========================================================================*/
1658/* Get next free CCS */
1659/* Return - index of current ccs */
1660static int get_free_ccs(ray_dev_t *local)
1661{
John Daiker141fa612009-03-10 06:59:54 -07001662 int i;
1663 struct ccs __iomem *pccs = ccs_base(local);
1664 struct pcmcia_device *link = local->finder;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001665
John Daiker141fa612009-03-10 06:59:54 -07001666 if (!(pcmcia_dev_present(link))) {
Dominik Brodowski624dd662009-10-24 15:52:44 +02001667 dev_dbg(&link->dev, "ray_cs get_free_ccs - device not present\n");
John Daiker141fa612009-03-10 06:59:54 -07001668 return ECARDGONE;
1669 }
1670 if (test_and_set_bit(0, &local->ccs_lock)) {
Dominik Brodowski624dd662009-10-24 15:52:44 +02001671 dev_dbg(&link->dev, "ray_cs ccs_lock busy\n");
John Daiker141fa612009-03-10 06:59:54 -07001672 return ECCSBUSY;
1673 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001674
John Daiker141fa612009-03-10 06:59:54 -07001675 for (i = NUMBER_OF_TX_CCS; i < NUMBER_OF_CCS; i++) {
1676 if (readb(&(pccs + i)->buffer_status) == CCS_BUFFER_FREE) {
1677 writeb(CCS_BUFFER_BUSY, &(pccs + i)->buffer_status);
1678 writeb(CCS_END_LIST, &(pccs + i)->link);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001679 local->ccs_lock = 0;
John Daiker141fa612009-03-10 06:59:54 -07001680 return i;
1681 }
1682 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001683 local->ccs_lock = 0;
Dominik Brodowski624dd662009-10-24 15:52:44 +02001684 dev_dbg(&link->dev, "ray_cs ERROR no free CCS for raylink card\n");
John Daiker141fa612009-03-10 06:59:54 -07001685 return ECCSFULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001686} /* get_free_ccs */
John Daiker141fa612009-03-10 06:59:54 -07001687
Linus Torvalds1da177e2005-04-16 15:20:36 -07001688/*===========================================================================*/
1689static void authenticate_timeout(u_long data)
1690{
John Daiker141fa612009-03-10 06:59:54 -07001691 ray_dev_t *local = (ray_dev_t *) data;
1692 del_timer(&local->timer);
1693 printk(KERN_INFO "ray_cs Authentication with access point failed"
1694 " - timeout\n");
1695 join_net((u_long) local);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001696}
John Daiker141fa612009-03-10 06:59:54 -07001697
Linus Torvalds1da177e2005-04-16 15:20:36 -07001698/*===========================================================================*/
Linus Torvalds1da177e2005-04-16 15:20:36 -07001699static int parse_addr(char *in_str, UCHAR *out)
1700{
John Daiker141fa612009-03-10 06:59:54 -07001701 int len;
1702 int i, j, k;
1703 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001704
John Daiker141fa612009-03-10 06:59:54 -07001705 if (in_str == NULL)
1706 return 0;
1707 if ((len = strlen(in_str)) < 2)
1708 return 0;
1709 memset(out, 0, ADDRLEN);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001710
John Daiker141fa612009-03-10 06:59:54 -07001711 status = 1;
1712 j = len - 1;
1713 if (j > 12)
1714 j = 12;
1715 i = 5;
1716
1717 while (j > 0) {
Andy Shevchenko882d8292010-07-23 03:18:09 +00001718 if ((k = hex_to_bin(in_str[j--])) != -1)
John Daiker141fa612009-03-10 06:59:54 -07001719 out[i] = k;
1720 else
1721 return 0;
1722
1723 if (j == 0)
1724 break;
Andy Shevchenko882d8292010-07-23 03:18:09 +00001725 if ((k = hex_to_bin(in_str[j--])) != -1)
John Daiker141fa612009-03-10 06:59:54 -07001726 out[i] += k << 4;
1727 else
1728 return 0;
1729 if (!i--)
1730 break;
1731 }
1732 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001733}
John Daiker141fa612009-03-10 06:59:54 -07001734
Linus Torvalds1da177e2005-04-16 15:20:36 -07001735/*===========================================================================*/
1736static struct net_device_stats *ray_get_stats(struct net_device *dev)
1737{
John Daiker141fa612009-03-10 06:59:54 -07001738 ray_dev_t *local = netdev_priv(dev);
1739 struct pcmcia_device *link = local->finder;
1740 struct status __iomem *p = local->sram + STATUS_BASE;
1741 if (!(pcmcia_dev_present(link))) {
Dominik Brodowski624dd662009-10-24 15:52:44 +02001742 dev_dbg(&link->dev, "ray_cs net_device_stats - device not present\n");
John Daiker141fa612009-03-10 06:59:54 -07001743 return &local->stats;
1744 }
1745 if (readb(&p->mrx_overflow_for_host)) {
1746 local->stats.rx_over_errors += swab16(readw(&p->mrx_overflow));
1747 writeb(0, &p->mrx_overflow);
1748 writeb(0, &p->mrx_overflow_for_host);
1749 }
1750 if (readb(&p->mrx_checksum_error_for_host)) {
1751 local->stats.rx_crc_errors +=
1752 swab16(readw(&p->mrx_checksum_error));
1753 writeb(0, &p->mrx_checksum_error);
1754 writeb(0, &p->mrx_checksum_error_for_host);
1755 }
1756 if (readb(&p->rx_hec_error_for_host)) {
1757 local->stats.rx_frame_errors += swab16(readw(&p->rx_hec_error));
1758 writeb(0, &p->rx_hec_error);
1759 writeb(0, &p->rx_hec_error_for_host);
1760 }
1761 return &local->stats;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001762}
John Daiker141fa612009-03-10 06:59:54 -07001763
Linus Torvalds1da177e2005-04-16 15:20:36 -07001764/*===========================================================================*/
John Daiker141fa612009-03-10 06:59:54 -07001765static void ray_update_parm(struct net_device *dev, UCHAR objid, UCHAR *value,
1766 int len)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001767{
John Daiker141fa612009-03-10 06:59:54 -07001768 ray_dev_t *local = netdev_priv(dev);
1769 struct pcmcia_device *link = local->finder;
1770 int ccsindex;
1771 int i;
1772 struct ccs __iomem *pccs;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001773
John Daiker141fa612009-03-10 06:59:54 -07001774 if (!(pcmcia_dev_present(link))) {
Dominik Brodowski624dd662009-10-24 15:52:44 +02001775 dev_dbg(&link->dev, "ray_update_parm - device not present\n");
John Daiker141fa612009-03-10 06:59:54 -07001776 return;
1777 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001778
John Daiker141fa612009-03-10 06:59:54 -07001779 if ((ccsindex = get_free_ccs(local)) < 0) {
Dominik Brodowski624dd662009-10-24 15:52:44 +02001780 dev_dbg(&link->dev, "ray_update_parm - No free ccs\n");
John Daiker141fa612009-03-10 06:59:54 -07001781 return;
1782 }
1783 pccs = ccs_base(local) + ccsindex;
1784 writeb(CCS_UPDATE_PARAMS, &pccs->cmd);
1785 writeb(objid, &pccs->var.update_param.object_id);
1786 writeb(1, &pccs->var.update_param.number_objects);
1787 writeb(0, &pccs->var.update_param.failure_cause);
1788 for (i = 0; i < len; i++) {
1789 writeb(value[i], local->sram + HOST_TO_ECF_BASE);
1790 }
1791 /* Interrupt the firmware to process the command */
1792 if (interrupt_ecf(local, ccsindex)) {
Dominik Brodowski624dd662009-10-24 15:52:44 +02001793 dev_dbg(&link->dev, "ray_cs associate failed - ECF not ready for intr\n");
John Daiker141fa612009-03-10 06:59:54 -07001794 writeb(CCS_BUFFER_FREE, &(pccs++)->buffer_status);
1795 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001796}
John Daiker141fa612009-03-10 06:59:54 -07001797
Linus Torvalds1da177e2005-04-16 15:20:36 -07001798/*===========================================================================*/
1799static void ray_update_multi_list(struct net_device *dev, int all)
1800{
John Daiker141fa612009-03-10 06:59:54 -07001801 int ccsindex;
1802 struct ccs __iomem *pccs;
John Daiker141fa612009-03-10 06:59:54 -07001803 ray_dev_t *local = netdev_priv(dev);
1804 struct pcmcia_device *link = local->finder;
1805 void __iomem *p = local->sram + HOST_TO_ECF_BASE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001806
John Daiker141fa612009-03-10 06:59:54 -07001807 if (!(pcmcia_dev_present(link))) {
Dominik Brodowski624dd662009-10-24 15:52:44 +02001808 dev_dbg(&link->dev, "ray_update_multi_list - device not present\n");
John Daiker141fa612009-03-10 06:59:54 -07001809 return;
1810 } else
Dominik Brodowski624dd662009-10-24 15:52:44 +02001811 dev_dbg(&link->dev, "ray_update_multi_list(%p)\n", dev);
John Daiker141fa612009-03-10 06:59:54 -07001812 if ((ccsindex = get_free_ccs(local)) < 0) {
Dominik Brodowski624dd662009-10-24 15:52:44 +02001813 dev_dbg(&link->dev, "ray_update_multi - No free ccs\n");
John Daiker141fa612009-03-10 06:59:54 -07001814 return;
1815 }
1816 pccs = ccs_base(local) + ccsindex;
1817 writeb(CCS_UPDATE_MULTICAST_LIST, &pccs->cmd);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001818
John Daiker141fa612009-03-10 06:59:54 -07001819 if (all) {
1820 writeb(0xff, &pccs->var);
1821 local->num_multi = 0xff;
1822 } else {
Jiri Pirko22bedad32010-04-01 21:22:57 +00001823 struct netdev_hw_addr *ha;
Jiri Pirko655ffee2010-02-27 07:35:45 +00001824 int i = 0;
1825
John Daiker141fa612009-03-10 06:59:54 -07001826 /* Copy the kernel's list of MC addresses to card */
Jiri Pirko22bedad32010-04-01 21:22:57 +00001827 netdev_for_each_mc_addr(ha, dev) {
1828 memcpy_toio(p, ha->addr, ETH_ALEN);
Dominik Brodowski624dd662009-10-24 15:52:44 +02001829 dev_dbg(&link->dev,
John Daiker141fa612009-03-10 06:59:54 -07001830 "ray_update_multi add addr %02x%02x%02x%02x%02x%02x\n",
Jiri Pirko22bedad32010-04-01 21:22:57 +00001831 ha->addr[0], ha->addr[1],
1832 ha->addr[2], ha->addr[3],
1833 ha->addr[4], ha->addr[5]);
John Daiker141fa612009-03-10 06:59:54 -07001834 p += ETH_ALEN;
1835 i++;
1836 }
1837 if (i > 256 / ADDRLEN)
1838 i = 256 / ADDRLEN;
1839 writeb((UCHAR) i, &pccs->var);
Dominik Brodowski624dd662009-10-24 15:52:44 +02001840 dev_dbg(&link->dev, "ray_cs update_multi %d addresses in list\n", i);
John Daiker141fa612009-03-10 06:59:54 -07001841 /* Interrupt the firmware to process the command */
1842 local->num_multi = i;
1843 }
1844 if (interrupt_ecf(local, ccsindex)) {
Dominik Brodowski624dd662009-10-24 15:52:44 +02001845 dev_dbg(&link->dev,
John Daiker141fa612009-03-10 06:59:54 -07001846 "ray_cs update_multi failed - ECF not ready for intr\n");
1847 writeb(CCS_BUFFER_FREE, &(pccs++)->buffer_status);
1848 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001849} /* end ray_update_multi_list */
John Daiker141fa612009-03-10 06:59:54 -07001850
Linus Torvalds1da177e2005-04-16 15:20:36 -07001851/*===========================================================================*/
1852static void set_multicast_list(struct net_device *dev)
1853{
John Daiker141fa612009-03-10 06:59:54 -07001854 ray_dev_t *local = netdev_priv(dev);
1855 UCHAR promisc;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001856
Dominik Brodowski624dd662009-10-24 15:52:44 +02001857 pr_debug("ray_cs set_multicast_list(%p)\n", dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001858
John Daiker141fa612009-03-10 06:59:54 -07001859 if (dev->flags & IFF_PROMISC) {
1860 if (local->sparm.b5.a_promiscuous_mode == 0) {
Dominik Brodowski624dd662009-10-24 15:52:44 +02001861 pr_debug("ray_cs set_multicast_list promisc on\n");
John Daiker141fa612009-03-10 06:59:54 -07001862 local->sparm.b5.a_promiscuous_mode = 1;
1863 promisc = 1;
1864 ray_update_parm(dev, OBJID_promiscuous_mode,
1865 &promisc, sizeof(promisc));
1866 }
1867 } else {
1868 if (local->sparm.b5.a_promiscuous_mode == 1) {
Dominik Brodowski624dd662009-10-24 15:52:44 +02001869 pr_debug("ray_cs set_multicast_list promisc off\n");
John Daiker141fa612009-03-10 06:59:54 -07001870 local->sparm.b5.a_promiscuous_mode = 0;
1871 promisc = 0;
1872 ray_update_parm(dev, OBJID_promiscuous_mode,
1873 &promisc, sizeof(promisc));
1874 }
1875 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001876
John Daiker141fa612009-03-10 06:59:54 -07001877 if (dev->flags & IFF_ALLMULTI)
1878 ray_update_multi_list(dev, 1);
1879 else {
Jiri Pirko4cd24ea2010-02-08 04:30:35 +00001880 if (local->num_multi != netdev_mc_count(dev))
John Daiker141fa612009-03-10 06:59:54 -07001881 ray_update_multi_list(dev, 0);
1882 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001883} /* end set_multicast_list */
John Daiker141fa612009-03-10 06:59:54 -07001884
Linus Torvalds1da177e2005-04-16 15:20:36 -07001885/*=============================================================================
1886 * All routines below here are run at interrupt time.
1887=============================================================================*/
David Howells7d12e782006-10-05 14:55:46 +01001888static irqreturn_t ray_interrupt(int irq, void *dev_id)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001889{
John Daiker141fa612009-03-10 06:59:54 -07001890 struct net_device *dev = (struct net_device *)dev_id;
1891 struct pcmcia_device *link;
1892 ray_dev_t *local;
1893 struct ccs __iomem *pccs;
1894 struct rcs __iomem *prcs;
1895 UCHAR rcsindex;
1896 UCHAR tmp;
1897 UCHAR cmd;
1898 UCHAR status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001899
John Daiker141fa612009-03-10 06:59:54 -07001900 if (dev == NULL) /* Note that we want interrupts with dev->start == 0 */
1901 return IRQ_NONE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001902
Dominik Brodowski624dd662009-10-24 15:52:44 +02001903 pr_debug("ray_cs: interrupt for *dev=%p\n", dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001904
John Daiker141fa612009-03-10 06:59:54 -07001905 local = netdev_priv(dev);
1906 link = (struct pcmcia_device *)local->finder;
1907 if (!pcmcia_dev_present(link)) {
Dominik Brodowski624dd662009-10-24 15:52:44 +02001908 pr_debug(
1909 "ray_cs interrupt from device not present or suspended.\n");
John Daiker141fa612009-03-10 06:59:54 -07001910 return IRQ_NONE;
1911 }
1912 rcsindex = readb(&((struct scb __iomem *)(local->sram))->rcs_index);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001913
John Daiker141fa612009-03-10 06:59:54 -07001914 if (rcsindex >= (NUMBER_OF_CCS + NUMBER_OF_RCS)) {
Dominik Brodowski624dd662009-10-24 15:52:44 +02001915 dev_dbg(&link->dev, "ray_cs interrupt bad rcsindex = 0x%x\n", rcsindex);
John Daiker141fa612009-03-10 06:59:54 -07001916 clear_interrupt(local);
1917 return IRQ_HANDLED;
1918 }
1919 if (rcsindex < NUMBER_OF_CCS) { /* If it's a returned CCS */
1920 pccs = ccs_base(local) + rcsindex;
1921 cmd = readb(&pccs->cmd);
1922 status = readb(&pccs->buffer_status);
1923 switch (cmd) {
1924 case CCS_DOWNLOAD_STARTUP_PARAMS: /* Happens in firmware someday */
1925 del_timer(&local->timer);
1926 if (status == CCS_COMMAND_COMPLETE) {
Dominik Brodowski624dd662009-10-24 15:52:44 +02001927 dev_dbg(&link->dev,
John Daiker141fa612009-03-10 06:59:54 -07001928 "ray_cs interrupt download_startup_parameters OK\n");
1929 } else {
Dominik Brodowski624dd662009-10-24 15:52:44 +02001930 dev_dbg(&link->dev,
John Daiker141fa612009-03-10 06:59:54 -07001931 "ray_cs interrupt download_startup_parameters fail\n");
1932 }
1933 break;
1934 case CCS_UPDATE_PARAMS:
Dominik Brodowski624dd662009-10-24 15:52:44 +02001935 dev_dbg(&link->dev, "ray_cs interrupt update params done\n");
John Daiker141fa612009-03-10 06:59:54 -07001936 if (status != CCS_COMMAND_COMPLETE) {
1937 tmp =
1938 readb(&pccs->var.update_param.
1939 failure_cause);
Dominik Brodowski624dd662009-10-24 15:52:44 +02001940 dev_dbg(&link->dev,
John Daiker141fa612009-03-10 06:59:54 -07001941 "ray_cs interrupt update params failed - reason %d\n",
1942 tmp);
1943 }
1944 break;
1945 case CCS_REPORT_PARAMS:
Dominik Brodowski624dd662009-10-24 15:52:44 +02001946 dev_dbg(&link->dev, "ray_cs interrupt report params done\n");
John Daiker141fa612009-03-10 06:59:54 -07001947 break;
1948 case CCS_UPDATE_MULTICAST_LIST: /* Note that this CCS isn't returned */
Dominik Brodowski624dd662009-10-24 15:52:44 +02001949 dev_dbg(&link->dev,
John Daiker141fa612009-03-10 06:59:54 -07001950 "ray_cs interrupt CCS Update Multicast List done\n");
1951 break;
1952 case CCS_UPDATE_POWER_SAVINGS_MODE:
Dominik Brodowski624dd662009-10-24 15:52:44 +02001953 dev_dbg(&link->dev,
John Daiker141fa612009-03-10 06:59:54 -07001954 "ray_cs interrupt update power save mode done\n");
1955 break;
1956 case CCS_START_NETWORK:
1957 case CCS_JOIN_NETWORK:
1958 if (status == CCS_COMMAND_COMPLETE) {
1959 if (readb
1960 (&pccs->var.start_network.net_initiated) ==
1961 1) {
Dominik Brodowski624dd662009-10-24 15:52:44 +02001962 dev_dbg(&link->dev,
John Daiker141fa612009-03-10 06:59:54 -07001963 "ray_cs interrupt network \"%s\" started\n",
1964 local->sparm.b4.a_current_ess_id);
1965 } else {
Dominik Brodowski624dd662009-10-24 15:52:44 +02001966 dev_dbg(&link->dev,
John Daiker141fa612009-03-10 06:59:54 -07001967 "ray_cs interrupt network \"%s\" joined\n",
1968 local->sparm.b4.a_current_ess_id);
1969 }
1970 memcpy_fromio(&local->bss_id,
1971 pccs->var.start_network.bssid,
1972 ADDRLEN);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001973
John Daiker141fa612009-03-10 06:59:54 -07001974 if (local->fw_ver == 0x55)
1975 local->net_default_tx_rate = 3;
1976 else
1977 local->net_default_tx_rate =
1978 readb(&pccs->var.start_network.
1979 net_default_tx_rate);
1980 local->encryption =
1981 readb(&pccs->var.start_network.encryption);
1982 if (!sniffer && (local->net_type == INFRA)
1983 && !(local->sparm.b4.a_acting_as_ap_status)) {
1984 authenticate(local);
1985 }
1986 local->card_status = CARD_ACQ_COMPLETE;
1987 } else {
1988 local->card_status = CARD_ACQ_FAILED;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001989
John Daiker141fa612009-03-10 06:59:54 -07001990 del_timer(&local->timer);
1991 local->timer.expires = jiffies + HZ * 5;
1992 local->timer.data = (long)local;
1993 if (status == CCS_START_NETWORK) {
Dominik Brodowski624dd662009-10-24 15:52:44 +02001994 dev_dbg(&link->dev,
John Daiker141fa612009-03-10 06:59:54 -07001995 "ray_cs interrupt network \"%s\" start failed\n",
1996 local->sparm.b4.a_current_ess_id);
1997 local->timer.function = &start_net;
1998 } else {
Dominik Brodowski624dd662009-10-24 15:52:44 +02001999 dev_dbg(&link->dev,
John Daiker141fa612009-03-10 06:59:54 -07002000 "ray_cs interrupt network \"%s\" join failed\n",
2001 local->sparm.b4.a_current_ess_id);
2002 local->timer.function = &join_net;
2003 }
2004 add_timer(&local->timer);
2005 }
2006 break;
2007 case CCS_START_ASSOCIATION:
2008 if (status == CCS_COMMAND_COMPLETE) {
2009 local->card_status = CARD_ASSOC_COMPLETE;
Dominik Brodowski624dd662009-10-24 15:52:44 +02002010 dev_dbg(&link->dev, "ray_cs association successful\n");
John Daiker141fa612009-03-10 06:59:54 -07002011 } else {
Dominik Brodowski624dd662009-10-24 15:52:44 +02002012 dev_dbg(&link->dev, "ray_cs association failed,\n");
John Daiker141fa612009-03-10 06:59:54 -07002013 local->card_status = CARD_ASSOC_FAILED;
2014 join_net((u_long) local);
2015 }
2016 break;
2017 case CCS_TX_REQUEST:
2018 if (status == CCS_COMMAND_COMPLETE) {
Dominik Brodowski624dd662009-10-24 15:52:44 +02002019 dev_dbg(&link->dev,
John Daiker141fa612009-03-10 06:59:54 -07002020 "ray_cs interrupt tx request complete\n");
2021 } else {
Dominik Brodowski624dd662009-10-24 15:52:44 +02002022 dev_dbg(&link->dev,
John Daiker141fa612009-03-10 06:59:54 -07002023 "ray_cs interrupt tx request failed\n");
2024 }
2025 if (!sniffer)
2026 netif_start_queue(dev);
2027 netif_wake_queue(dev);
2028 break;
2029 case CCS_TEST_MEMORY:
Dominik Brodowski624dd662009-10-24 15:52:44 +02002030 dev_dbg(&link->dev, "ray_cs interrupt mem test done\n");
John Daiker141fa612009-03-10 06:59:54 -07002031 break;
2032 case CCS_SHUTDOWN:
Dominik Brodowski624dd662009-10-24 15:52:44 +02002033 dev_dbg(&link->dev,
John Daiker141fa612009-03-10 06:59:54 -07002034 "ray_cs interrupt Unexpected CCS returned - Shutdown\n");
2035 break;
2036 case CCS_DUMP_MEMORY:
Dominik Brodowski624dd662009-10-24 15:52:44 +02002037 dev_dbg(&link->dev, "ray_cs interrupt dump memory done\n");
John Daiker141fa612009-03-10 06:59:54 -07002038 break;
2039 case CCS_START_TIMER:
Dominik Brodowski624dd662009-10-24 15:52:44 +02002040 dev_dbg(&link->dev,
John Daiker141fa612009-03-10 06:59:54 -07002041 "ray_cs interrupt DING - raylink timer expired\n");
2042 break;
2043 default:
Dominik Brodowski624dd662009-10-24 15:52:44 +02002044 dev_dbg(&link->dev,
John Daiker141fa612009-03-10 06:59:54 -07002045 "ray_cs interrupt Unexpected CCS 0x%x returned 0x%x\n",
2046 rcsindex, cmd);
2047 }
2048 writeb(CCS_BUFFER_FREE, &pccs->buffer_status);
2049 } else { /* It's an RCS */
2050
2051 prcs = rcs_base(local) + rcsindex;
2052
2053 switch (readb(&prcs->interrupt_id)) {
2054 case PROCESS_RX_PACKET:
2055 ray_rx(dev, local, prcs);
2056 break;
2057 case REJOIN_NET_COMPLETE:
Dominik Brodowski624dd662009-10-24 15:52:44 +02002058 dev_dbg(&link->dev, "ray_cs interrupt rejoin net complete\n");
John Daiker141fa612009-03-10 06:59:54 -07002059 local->card_status = CARD_ACQ_COMPLETE;
2060 /* do we need to clear tx buffers CCS's? */
2061 if (local->sparm.b4.a_network_type == ADHOC) {
2062 if (!sniffer)
2063 netif_start_queue(dev);
2064 } else {
2065 memcpy_fromio(&local->bss_id,
2066 prcs->var.rejoin_net_complete.
2067 bssid, ADDRLEN);
Dominik Brodowski624dd662009-10-24 15:52:44 +02002068 dev_dbg(&link->dev,
John Daiker141fa612009-03-10 06:59:54 -07002069 "ray_cs new BSSID = %02x%02x%02x%02x%02x%02x\n",
2070 local->bss_id[0], local->bss_id[1],
2071 local->bss_id[2], local->bss_id[3],
2072 local->bss_id[4], local->bss_id[5]);
2073 if (!sniffer)
2074 authenticate(local);
2075 }
2076 break;
2077 case ROAMING_INITIATED:
Dominik Brodowski624dd662009-10-24 15:52:44 +02002078 dev_dbg(&link->dev, "ray_cs interrupt roaming initiated\n");
John Daiker141fa612009-03-10 06:59:54 -07002079 netif_stop_queue(dev);
2080 local->card_status = CARD_DOING_ACQ;
2081 break;
2082 case JAPAN_CALL_SIGN_RXD:
Dominik Brodowski624dd662009-10-24 15:52:44 +02002083 dev_dbg(&link->dev, "ray_cs interrupt japan call sign rx\n");
John Daiker141fa612009-03-10 06:59:54 -07002084 break;
2085 default:
Dominik Brodowski624dd662009-10-24 15:52:44 +02002086 dev_dbg(&link->dev,
John Daiker141fa612009-03-10 06:59:54 -07002087 "ray_cs Unexpected interrupt for RCS 0x%x cmd = 0x%x\n",
2088 rcsindex,
2089 (unsigned int)readb(&prcs->interrupt_id));
2090 break;
2091 }
2092 writeb(CCS_BUFFER_FREE, &prcs->buffer_status);
2093 }
2094 clear_interrupt(local);
2095 return IRQ_HANDLED;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002096} /* ray_interrupt */
John Daiker141fa612009-03-10 06:59:54 -07002097
Linus Torvalds1da177e2005-04-16 15:20:36 -07002098/*===========================================================================*/
John Daiker141fa612009-03-10 06:59:54 -07002099static void ray_rx(struct net_device *dev, ray_dev_t *local,
2100 struct rcs __iomem *prcs)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002101{
John Daiker141fa612009-03-10 06:59:54 -07002102 int rx_len;
2103 unsigned int pkt_addr;
2104 void __iomem *pmsg;
Dominik Brodowski624dd662009-10-24 15:52:44 +02002105 pr_debug("ray_rx process rx packet\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002106
John Daiker141fa612009-03-10 06:59:54 -07002107 /* Calculate address of packet within Rx buffer */
2108 pkt_addr = ((readb(&prcs->var.rx_packet.rx_data_ptr[0]) << 8)
2109 + readb(&prcs->var.rx_packet.rx_data_ptr[1])) & RX_BUFF_END;
2110 /* Length of first packet fragment */
2111 rx_len = (readb(&prcs->var.rx_packet.rx_data_length[0]) << 8)
2112 + readb(&prcs->var.rx_packet.rx_data_length[1]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002113
John Daiker141fa612009-03-10 06:59:54 -07002114 local->last_rsl = readb(&prcs->var.rx_packet.rx_sig_lev);
2115 pmsg = local->rmem + pkt_addr;
2116 switch (readb(pmsg)) {
2117 case DATA_TYPE:
Dominik Brodowski624dd662009-10-24 15:52:44 +02002118 pr_debug("ray_rx data type\n");
John Daiker141fa612009-03-10 06:59:54 -07002119 rx_data(dev, prcs, pkt_addr, rx_len);
2120 break;
2121 case AUTHENTIC_TYPE:
Dominik Brodowski624dd662009-10-24 15:52:44 +02002122 pr_debug("ray_rx authentic type\n");
John Daiker141fa612009-03-10 06:59:54 -07002123 if (sniffer)
2124 rx_data(dev, prcs, pkt_addr, rx_len);
2125 else
2126 rx_authenticate(local, prcs, pkt_addr, rx_len);
2127 break;
2128 case DEAUTHENTIC_TYPE:
Dominik Brodowski624dd662009-10-24 15:52:44 +02002129 pr_debug("ray_rx deauth type\n");
John Daiker141fa612009-03-10 06:59:54 -07002130 if (sniffer)
2131 rx_data(dev, prcs, pkt_addr, rx_len);
2132 else
2133 rx_deauthenticate(local, prcs, pkt_addr, rx_len);
2134 break;
2135 case NULL_MSG_TYPE:
Dominik Brodowski624dd662009-10-24 15:52:44 +02002136 pr_debug("ray_cs rx NULL msg\n");
John Daiker141fa612009-03-10 06:59:54 -07002137 break;
2138 case BEACON_TYPE:
Dominik Brodowski624dd662009-10-24 15:52:44 +02002139 pr_debug("ray_rx beacon type\n");
John Daiker141fa612009-03-10 06:59:54 -07002140 if (sniffer)
2141 rx_data(dev, prcs, pkt_addr, rx_len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002142
John Daiker141fa612009-03-10 06:59:54 -07002143 copy_from_rx_buff(local, (UCHAR *) &local->last_bcn, pkt_addr,
2144 rx_len < sizeof(struct beacon_rx) ?
2145 rx_len : sizeof(struct beacon_rx));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002146
John Daiker141fa612009-03-10 06:59:54 -07002147 local->beacon_rxed = 1;
2148 /* Get the statistics so the card counters never overflow */
2149 ray_get_stats(dev);
2150 break;
2151 default:
Dominik Brodowski624dd662009-10-24 15:52:44 +02002152 pr_debug("ray_cs unknown pkt type %2x\n",
John Daiker141fa612009-03-10 06:59:54 -07002153 (unsigned int)readb(pmsg));
2154 break;
2155 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002156
2157} /* end ray_rx */
John Daiker141fa612009-03-10 06:59:54 -07002158
Linus Torvalds1da177e2005-04-16 15:20:36 -07002159/*===========================================================================*/
John Daiker141fa612009-03-10 06:59:54 -07002160static void rx_data(struct net_device *dev, struct rcs __iomem *prcs,
2161 unsigned int pkt_addr, int rx_len)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002162{
John Daiker141fa612009-03-10 06:59:54 -07002163 struct sk_buff *skb = NULL;
2164 struct rcs __iomem *prcslink = prcs;
2165 ray_dev_t *local = netdev_priv(dev);
2166 UCHAR *rx_ptr;
2167 int total_len;
2168 int tmp;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002169#ifdef WIRELESS_SPY
John Daiker141fa612009-03-10 06:59:54 -07002170 int siglev = local->last_rsl;
2171 u_char linksrcaddr[ETH_ALEN]; /* Other end of the wireless link */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002172#endif
2173
John Daiker141fa612009-03-10 06:59:54 -07002174 if (!sniffer) {
2175 if (translate) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002176/* TBD length needs fixing for translated header */
John Daiker141fa612009-03-10 06:59:54 -07002177 if (rx_len < (ETH_HLEN + RX_MAC_HEADER_LENGTH) ||
2178 rx_len >
2179 (dev->mtu + RX_MAC_HEADER_LENGTH + ETH_HLEN +
2180 FCS_LEN)) {
Dominik Brodowski624dd662009-10-24 15:52:44 +02002181 pr_debug(
Frans Popcb01b092010-03-24 19:46:34 +01002182 "ray_cs invalid packet length %d received\n",
John Daiker141fa612009-03-10 06:59:54 -07002183 rx_len);
2184 return;
2185 }
2186 } else { /* encapsulated ethernet */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002187
John Daiker141fa612009-03-10 06:59:54 -07002188 if (rx_len < (ETH_HLEN + RX_MAC_HEADER_LENGTH) ||
2189 rx_len >
2190 (dev->mtu + RX_MAC_HEADER_LENGTH + ETH_HLEN +
2191 FCS_LEN)) {
Dominik Brodowski624dd662009-10-24 15:52:44 +02002192 pr_debug(
Frans Popcb01b092010-03-24 19:46:34 +01002193 "ray_cs invalid packet length %d received\n",
John Daiker141fa612009-03-10 06:59:54 -07002194 rx_len);
2195 return;
2196 }
2197 }
2198 }
Dominik Brodowski624dd662009-10-24 15:52:44 +02002199 pr_debug("ray_cs rx_data packet\n");
John Daiker141fa612009-03-10 06:59:54 -07002200 /* If fragmented packet, verify sizes of fragments add up */
2201 if (readb(&prcs->var.rx_packet.next_frag_rcs_index) != 0xFF) {
Dominik Brodowski624dd662009-10-24 15:52:44 +02002202 pr_debug("ray_cs rx'ed fragment\n");
John Daiker141fa612009-03-10 06:59:54 -07002203 tmp = (readb(&prcs->var.rx_packet.totalpacketlength[0]) << 8)
2204 + readb(&prcs->var.rx_packet.totalpacketlength[1]);
2205 total_len = tmp;
2206 prcslink = prcs;
2207 do {
2208 tmp -=
2209 (readb(&prcslink->var.rx_packet.rx_data_length[0])
2210 << 8)
2211 + readb(&prcslink->var.rx_packet.rx_data_length[1]);
2212 if (readb(&prcslink->var.rx_packet.next_frag_rcs_index)
2213 == 0xFF || tmp < 0)
2214 break;
2215 prcslink = rcs_base(local)
2216 + readb(&prcslink->link_field);
2217 } while (1);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002218
John Daiker141fa612009-03-10 06:59:54 -07002219 if (tmp < 0) {
Dominik Brodowski624dd662009-10-24 15:52:44 +02002220 pr_debug(
John Daiker141fa612009-03-10 06:59:54 -07002221 "ray_cs rx_data fragment lengths don't add up\n");
2222 local->stats.rx_dropped++;
2223 release_frag_chain(local, prcs);
2224 return;
2225 }
2226 } else { /* Single unfragmented packet */
2227 total_len = rx_len;
2228 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002229
John Daiker141fa612009-03-10 06:59:54 -07002230 skb = dev_alloc_skb(total_len + 5);
2231 if (skb == NULL) {
Dominik Brodowski624dd662009-10-24 15:52:44 +02002232 pr_debug("ray_cs rx_data could not allocate skb\n");
John Daiker141fa612009-03-10 06:59:54 -07002233 local->stats.rx_dropped++;
2234 if (readb(&prcs->var.rx_packet.next_frag_rcs_index) != 0xFF)
2235 release_frag_chain(local, prcs);
2236 return;
2237 }
2238 skb_reserve(skb, 2); /* Align IP on 16 byte (TBD check this) */
2239
Dominik Brodowski624dd662009-10-24 15:52:44 +02002240 pr_debug("ray_cs rx_data total_len = %x, rx_len = %x\n", total_len,
John Daiker141fa612009-03-10 06:59:54 -07002241 rx_len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002242
2243/************************/
John Daiker141fa612009-03-10 06:59:54 -07002244 /* Reserve enough room for the whole damn packet. */
2245 rx_ptr = skb_put(skb, total_len);
2246 /* Copy the whole packet to sk_buff */
2247 rx_ptr +=
2248 copy_from_rx_buff(local, rx_ptr, pkt_addr & RX_BUFF_END, rx_len);
2249 /* Get source address */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002250#ifdef WIRELESS_SPY
John Daiker141fa612009-03-10 06:59:54 -07002251 skb_copy_from_linear_data_offset(skb,
2252 offsetof(struct mac_header, addr_2),
2253 linksrcaddr, ETH_ALEN);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002254#endif
John Daiker141fa612009-03-10 06:59:54 -07002255 /* Now, deal with encapsulation/translation/sniffer */
2256 if (!sniffer) {
2257 if (!translate) {
2258 /* Encapsulated ethernet, so just lop off 802.11 MAC header */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002259/* TBD reserve skb_reserve( skb, RX_MAC_HEADER_LENGTH); */
John Daiker141fa612009-03-10 06:59:54 -07002260 skb_pull(skb, RX_MAC_HEADER_LENGTH);
2261 } else {
2262 /* Do translation */
2263 untranslate(local, skb, total_len);
2264 }
2265 } else { /* sniffer mode, so just pass whole packet */
2266 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002267
2268/************************/
John Daiker141fa612009-03-10 06:59:54 -07002269 /* Now pick up the rest of the fragments if any */
2270 tmp = 17;
2271 if (readb(&prcs->var.rx_packet.next_frag_rcs_index) != 0xFF) {
2272 prcslink = prcs;
Dominik Brodowski624dd662009-10-24 15:52:44 +02002273 pr_debug("ray_cs rx_data in fragment loop\n");
John Daiker141fa612009-03-10 06:59:54 -07002274 do {
2275 prcslink = rcs_base(local)
2276 +
2277 readb(&prcslink->var.rx_packet.next_frag_rcs_index);
2278 rx_len =
2279 ((readb(&prcslink->var.rx_packet.rx_data_length[0])
2280 << 8)
2281 +
2282 readb(&prcslink->var.rx_packet.rx_data_length[1]))
2283 & RX_BUFF_END;
2284 pkt_addr =
2285 ((readb(&prcslink->var.rx_packet.rx_data_ptr[0]) <<
2286 8)
2287 + readb(&prcslink->var.rx_packet.rx_data_ptr[1]))
2288 & RX_BUFF_END;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002289
John Daiker141fa612009-03-10 06:59:54 -07002290 rx_ptr +=
2291 copy_from_rx_buff(local, rx_ptr, pkt_addr, rx_len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002292
John Daiker141fa612009-03-10 06:59:54 -07002293 } while (tmp-- &&
2294 readb(&prcslink->var.rx_packet.next_frag_rcs_index) !=
2295 0xFF);
2296 release_frag_chain(local, prcs);
2297 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002298
John Daiker141fa612009-03-10 06:59:54 -07002299 skb->protocol = eth_type_trans(skb, dev);
2300 netif_rx(skb);
2301 local->stats.rx_packets++;
2302 local->stats.rx_bytes += total_len;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002303
John Daiker141fa612009-03-10 06:59:54 -07002304 /* Gather signal strength per address */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002305#ifdef WIRELESS_SPY
John Daiker141fa612009-03-10 06:59:54 -07002306 /* For the Access Point or the node having started the ad-hoc net
2307 * note : ad-hoc work only in some specific configurations, but we
2308 * kludge in ray_get_wireless_stats... */
2309 if (!memcmp(linksrcaddr, local->bss_id, ETH_ALEN)) {
2310 /* Update statistics */
2311 /*local->wstats.qual.qual = none ? */
2312 local->wstats.qual.level = siglev;
2313 /*local->wstats.qual.noise = none ? */
2314 local->wstats.qual.updated = 0x2;
2315 }
2316 /* Now, update the spy stuff */
2317 {
2318 struct iw_quality wstats;
2319 wstats.level = siglev;
2320 /* wstats.noise = none ? */
2321 /* wstats.qual = none ? */
2322 wstats.updated = 0x2;
2323 /* Update spy records */
2324 wireless_spy_update(dev, linksrcaddr, &wstats);
2325 }
2326#endif /* WIRELESS_SPY */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002327} /* end rx_data */
John Daiker141fa612009-03-10 06:59:54 -07002328
Linus Torvalds1da177e2005-04-16 15:20:36 -07002329/*===========================================================================*/
2330static void untranslate(ray_dev_t *local, struct sk_buff *skb, int len)
2331{
John Daiker141fa612009-03-10 06:59:54 -07002332 snaphdr_t *psnap = (snaphdr_t *) (skb->data + RX_MAC_HEADER_LENGTH);
2333 struct ieee80211_hdr *pmac = (struct ieee80211_hdr *)skb->data;
2334 __be16 type = *(__be16 *) psnap->ethertype;
2335 int delta;
2336 struct ethhdr *peth;
2337 UCHAR srcaddr[ADDRLEN];
2338 UCHAR destaddr[ADDRLEN];
2339 static UCHAR org_bridge[3] = { 0, 0, 0xf8 };
2340 static UCHAR org_1042[3] = { 0, 0, 0 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002341
John Daiker141fa612009-03-10 06:59:54 -07002342 memcpy(destaddr, ieee80211_get_DA(pmac), ADDRLEN);
2343 memcpy(srcaddr, ieee80211_get_SA(pmac), ADDRLEN);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002344
Dominik Brodowski624dd662009-10-24 15:52:44 +02002345#if 0
2346 if {
Joe Perchesad361c92009-07-06 13:05:40 -07002347 print_hex_dump(KERN_DEBUG, "skb->data before untranslate: ",
2348 DUMP_PREFIX_NONE, 16, 1,
2349 skb->data, 64, true);
2350 printk(KERN_DEBUG
John Daiker141fa612009-03-10 06:59:54 -07002351 "type = %08x, xsap = %02x%02x%02x, org = %02x02x02x\n",
2352 ntohs(type), psnap->dsap, psnap->ssap, psnap->ctrl,
2353 psnap->org[0], psnap->org[1], psnap->org[2]);
2354 printk(KERN_DEBUG "untranslate skb->data = %p\n", skb->data);
2355 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002356#endif
2357
John Daiker141fa612009-03-10 06:59:54 -07002358 if (psnap->dsap != 0xaa || psnap->ssap != 0xaa || psnap->ctrl != 3) {
2359 /* not a snap type so leave it alone */
Dominik Brodowski624dd662009-10-24 15:52:44 +02002360 pr_debug("ray_cs untranslate NOT SNAP %02x %02x %02x\n",
John Daiker141fa612009-03-10 06:59:54 -07002361 psnap->dsap, psnap->ssap, psnap->ctrl);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002362
John Daiker141fa612009-03-10 06:59:54 -07002363 delta = RX_MAC_HEADER_LENGTH - ETH_HLEN;
2364 peth = (struct ethhdr *)(skb->data + delta);
2365 peth->h_proto = htons(len - RX_MAC_HEADER_LENGTH);
2366 } else { /* Its a SNAP */
2367 if (memcmp(psnap->org, org_bridge, 3) == 0) {
2368 /* EtherII and nuke the LLC */
Dominik Brodowski624dd662009-10-24 15:52:44 +02002369 pr_debug("ray_cs untranslate Bridge encap\n");
John Daiker141fa612009-03-10 06:59:54 -07002370 delta = RX_MAC_HEADER_LENGTH
2371 + sizeof(struct snaphdr_t) - ETH_HLEN;
2372 peth = (struct ethhdr *)(skb->data + delta);
2373 peth->h_proto = type;
2374 } else if (memcmp(psnap->org, org_1042, 3) == 0) {
2375 switch (ntohs(type)) {
2376 case ETH_P_IPX:
2377 case ETH_P_AARP:
Dominik Brodowski624dd662009-10-24 15:52:44 +02002378 pr_debug("ray_cs untranslate RFC IPX/AARP\n");
John Daiker141fa612009-03-10 06:59:54 -07002379 delta = RX_MAC_HEADER_LENGTH - ETH_HLEN;
2380 peth = (struct ethhdr *)(skb->data + delta);
2381 peth->h_proto =
2382 htons(len - RX_MAC_HEADER_LENGTH);
2383 break;
2384 default:
Dominik Brodowski624dd662009-10-24 15:52:44 +02002385 pr_debug("ray_cs untranslate RFC default\n");
John Daiker141fa612009-03-10 06:59:54 -07002386 delta = RX_MAC_HEADER_LENGTH +
2387 sizeof(struct snaphdr_t) - ETH_HLEN;
2388 peth = (struct ethhdr *)(skb->data + delta);
2389 peth->h_proto = type;
2390 break;
2391 }
2392 } else {
2393 printk("ray_cs untranslate very confused by packet\n");
2394 delta = RX_MAC_HEADER_LENGTH - ETH_HLEN;
2395 peth = (struct ethhdr *)(skb->data + delta);
2396 peth->h_proto = type;
2397 }
Al Viro7698d692007-12-29 04:55:50 -05002398 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002399/* TBD reserve skb_reserve(skb, delta); */
John Daiker141fa612009-03-10 06:59:54 -07002400 skb_pull(skb, delta);
Dominik Brodowski624dd662009-10-24 15:52:44 +02002401 pr_debug("untranslate after skb_pull(%d), skb->data = %p\n", delta,
John Daiker141fa612009-03-10 06:59:54 -07002402 skb->data);
2403 memcpy(peth->h_dest, destaddr, ADDRLEN);
2404 memcpy(peth->h_source, srcaddr, ADDRLEN);
Dominik Brodowski624dd662009-10-24 15:52:44 +02002405#if 0
2406 {
John Daiker141fa612009-03-10 06:59:54 -07002407 int i;
2408 printk(KERN_DEBUG "skb->data after untranslate:");
2409 for (i = 0; i < 64; i++)
2410 printk("%02x ", skb->data[i]);
2411 printk("\n");
2412 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002413#endif
2414} /* end untranslate */
John Daiker141fa612009-03-10 06:59:54 -07002415
Linus Torvalds1da177e2005-04-16 15:20:36 -07002416/*===========================================================================*/
2417/* Copy data from circular receive buffer to PC memory.
2418 * dest = destination address in PC memory
2419 * pkt_addr = source address in receive buffer
2420 * len = length of packet to copy
2421 */
John Daiker141fa612009-03-10 06:59:54 -07002422static int copy_from_rx_buff(ray_dev_t *local, UCHAR *dest, int pkt_addr,
2423 int length)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002424{
John Daiker141fa612009-03-10 06:59:54 -07002425 int wrap_bytes = (pkt_addr + length) - (RX_BUFF_END + 1);
2426 if (wrap_bytes <= 0) {
2427 memcpy_fromio(dest, local->rmem + pkt_addr, length);
2428 } else { /* Packet wrapped in circular buffer */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002429
John Daiker141fa612009-03-10 06:59:54 -07002430 memcpy_fromio(dest, local->rmem + pkt_addr,
2431 length - wrap_bytes);
2432 memcpy_fromio(dest + length - wrap_bytes, local->rmem,
2433 wrap_bytes);
2434 }
2435 return length;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002436}
John Daiker141fa612009-03-10 06:59:54 -07002437
2438/*===========================================================================*/
2439static void release_frag_chain(ray_dev_t *local, struct rcs __iomem *prcs)
2440{
2441 struct rcs __iomem *prcslink = prcs;
2442 int tmp = 17;
2443 unsigned rcsindex = readb(&prcs->var.rx_packet.next_frag_rcs_index);
2444
2445 while (tmp--) {
2446 writeb(CCS_BUFFER_FREE, &prcslink->buffer_status);
2447 if (rcsindex >= (NUMBER_OF_CCS + NUMBER_OF_RCS)) {
Dominik Brodowski624dd662009-10-24 15:52:44 +02002448 pr_debug("ray_cs interrupt bad rcsindex = 0x%x\n",
John Daiker141fa612009-03-10 06:59:54 -07002449 rcsindex);
2450 break;
2451 }
2452 prcslink = rcs_base(local) + rcsindex;
2453 rcsindex = readb(&prcslink->var.rx_packet.next_frag_rcs_index);
2454 }
2455 writeb(CCS_BUFFER_FREE, &prcslink->buffer_status);
2456}
2457
Linus Torvalds1da177e2005-04-16 15:20:36 -07002458/*===========================================================================*/
2459static void authenticate(ray_dev_t *local)
2460{
John Daiker141fa612009-03-10 06:59:54 -07002461 struct pcmcia_device *link = local->finder;
Dominik Brodowski624dd662009-10-24 15:52:44 +02002462 dev_dbg(&link->dev, "ray_cs Starting authentication.\n");
John Daiker141fa612009-03-10 06:59:54 -07002463 if (!(pcmcia_dev_present(link))) {
Dominik Brodowski624dd662009-10-24 15:52:44 +02002464 dev_dbg(&link->dev, "ray_cs authenticate - device not present\n");
John Daiker141fa612009-03-10 06:59:54 -07002465 return;
2466 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002467
John Daiker141fa612009-03-10 06:59:54 -07002468 del_timer(&local->timer);
2469 if (build_auth_frame(local, local->bss_id, OPEN_AUTH_REQUEST)) {
2470 local->timer.function = &join_net;
2471 } else {
2472 local->timer.function = &authenticate_timeout;
2473 }
2474 local->timer.expires = jiffies + HZ * 2;
2475 local->timer.data = (long)local;
2476 add_timer(&local->timer);
2477 local->authentication_state = AWAITING_RESPONSE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002478} /* end authenticate */
John Daiker141fa612009-03-10 06:59:54 -07002479
Linus Torvalds1da177e2005-04-16 15:20:36 -07002480/*===========================================================================*/
2481static void rx_authenticate(ray_dev_t *local, struct rcs __iomem *prcs,
John Daiker141fa612009-03-10 06:59:54 -07002482 unsigned int pkt_addr, int rx_len)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002483{
John Daiker141fa612009-03-10 06:59:54 -07002484 UCHAR buff[256];
2485 struct rx_msg *msg = (struct rx_msg *)buff;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002486
John Daiker141fa612009-03-10 06:59:54 -07002487 del_timer(&local->timer);
2488
2489 copy_from_rx_buff(local, buff, pkt_addr, rx_len & 0xff);
2490 /* if we are trying to get authenticated */
2491 if (local->sparm.b4.a_network_type == ADHOC) {
Dominik Brodowski624dd662009-10-24 15:52:44 +02002492 pr_debug("ray_cs rx_auth var= %02x %02x %02x %02x %02x %02x\n",
John Daiker141fa612009-03-10 06:59:54 -07002493 msg->var[0], msg->var[1], msg->var[2], msg->var[3],
2494 msg->var[4], msg->var[5]);
2495 if (msg->var[2] == 1) {
Dominik Brodowski624dd662009-10-24 15:52:44 +02002496 pr_debug("ray_cs Sending authentication response.\n");
John Daiker141fa612009-03-10 06:59:54 -07002497 if (!build_auth_frame
2498 (local, msg->mac.addr_2, OPEN_AUTH_RESPONSE)) {
2499 local->authentication_state = NEED_TO_AUTH;
2500 memcpy(local->auth_id, msg->mac.addr_2,
2501 ADDRLEN);
2502 }
2503 }
2504 } else { /* Infrastructure network */
2505
2506 if (local->authentication_state == AWAITING_RESPONSE) {
2507 /* Verify authentication sequence #2 and success */
2508 if (msg->var[2] == 2) {
2509 if ((msg->var[3] | msg->var[4]) == 0) {
Dominik Brodowski624dd662009-10-24 15:52:44 +02002510 pr_debug("Authentication successful\n");
John Daiker141fa612009-03-10 06:59:54 -07002511 local->card_status = CARD_AUTH_COMPLETE;
2512 associate(local);
2513 local->authentication_state =
2514 AUTHENTICATED;
2515 } else {
Dominik Brodowski624dd662009-10-24 15:52:44 +02002516 pr_debug("Authentication refused\n");
John Daiker141fa612009-03-10 06:59:54 -07002517 local->card_status = CARD_AUTH_REFUSED;
2518 join_net((u_long) local);
2519 local->authentication_state =
2520 UNAUTHENTICATED;
2521 }
2522 }
2523 }
2524 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002525
2526} /* end rx_authenticate */
John Daiker141fa612009-03-10 06:59:54 -07002527
Linus Torvalds1da177e2005-04-16 15:20:36 -07002528/*===========================================================================*/
2529static void associate(ray_dev_t *local)
2530{
John Daiker141fa612009-03-10 06:59:54 -07002531 struct ccs __iomem *pccs;
2532 struct pcmcia_device *link = local->finder;
2533 struct net_device *dev = link->priv;
2534 int ccsindex;
2535 if (!(pcmcia_dev_present(link))) {
Dominik Brodowski624dd662009-10-24 15:52:44 +02002536 dev_dbg(&link->dev, "ray_cs associate - device not present\n");
John Daiker141fa612009-03-10 06:59:54 -07002537 return;
2538 }
2539 /* If no tx buffers available, return */
2540 if ((ccsindex = get_free_ccs(local)) < 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002541/* TBD should never be here but... what if we are? */
Dominik Brodowski624dd662009-10-24 15:52:44 +02002542 dev_dbg(&link->dev, "ray_cs associate - No free ccs\n");
John Daiker141fa612009-03-10 06:59:54 -07002543 return;
2544 }
Dominik Brodowski624dd662009-10-24 15:52:44 +02002545 dev_dbg(&link->dev, "ray_cs Starting association with access point\n");
John Daiker141fa612009-03-10 06:59:54 -07002546 pccs = ccs_base(local) + ccsindex;
2547 /* fill in the CCS */
2548 writeb(CCS_START_ASSOCIATION, &pccs->cmd);
2549 /* Interrupt the firmware to process the command */
2550 if (interrupt_ecf(local, ccsindex)) {
Dominik Brodowski624dd662009-10-24 15:52:44 +02002551 dev_dbg(&link->dev, "ray_cs associate failed - ECF not ready for intr\n");
John Daiker141fa612009-03-10 06:59:54 -07002552 writeb(CCS_BUFFER_FREE, &(pccs++)->buffer_status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002553
John Daiker141fa612009-03-10 06:59:54 -07002554 del_timer(&local->timer);
2555 local->timer.expires = jiffies + HZ * 2;
2556 local->timer.data = (long)local;
2557 local->timer.function = &join_net;
2558 add_timer(&local->timer);
2559 local->card_status = CARD_ASSOC_FAILED;
2560 return;
2561 }
2562 if (!sniffer)
2563 netif_start_queue(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002564
2565} /* end associate */
John Daiker141fa612009-03-10 06:59:54 -07002566
Linus Torvalds1da177e2005-04-16 15:20:36 -07002567/*===========================================================================*/
John Daiker141fa612009-03-10 06:59:54 -07002568static void rx_deauthenticate(ray_dev_t *local, struct rcs __iomem *prcs,
2569 unsigned int pkt_addr, int rx_len)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002570{
2571/* UCHAR buff[256];
2572 struct rx_msg *msg = (struct rx_msg *)buff;
2573*/
Dominik Brodowski624dd662009-10-24 15:52:44 +02002574 pr_debug("Deauthentication frame received\n");
John Daiker141fa612009-03-10 06:59:54 -07002575 local->authentication_state = UNAUTHENTICATED;
2576 /* Need to reauthenticate or rejoin depending on reason code */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002577/* copy_from_rx_buff(local, buff, pkt_addr, rx_len & 0xff);
2578 */
2579}
John Daiker141fa612009-03-10 06:59:54 -07002580
Linus Torvalds1da177e2005-04-16 15:20:36 -07002581/*===========================================================================*/
2582static void clear_interrupt(ray_dev_t *local)
2583{
John Daiker141fa612009-03-10 06:59:54 -07002584 writeb(0, local->amem + CIS_OFFSET + HCS_INTR_OFFSET);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002585}
John Daiker141fa612009-03-10 06:59:54 -07002586
Linus Torvalds1da177e2005-04-16 15:20:36 -07002587/*===========================================================================*/
2588#ifdef CONFIG_PROC_FS
2589#define MAXDATA (PAGE_SIZE - 80)
2590
2591static char *card_status[] = {
John Daiker141fa612009-03-10 06:59:54 -07002592 "Card inserted - uninitialized", /* 0 */
2593 "Card not downloaded", /* 1 */
2594 "Waiting for download parameters", /* 2 */
2595 "Card doing acquisition", /* 3 */
2596 "Acquisition complete", /* 4 */
2597 "Authentication complete", /* 5 */
2598 "Association complete", /* 6 */
2599 "???", "???", "???", "???", /* 7 8 9 10 undefined */
2600 "Card init error", /* 11 */
2601 "Download parameters error", /* 12 */
2602 "???", /* 13 */
2603 "Acquisition failed", /* 14 */
2604 "Authentication refused", /* 15 */
2605 "Association failed" /* 16 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002606};
2607
John Daiker141fa612009-03-10 06:59:54 -07002608static char *nettype[] = { "Adhoc", "Infra " };
2609static char *framing[] = { "Encapsulation", "Translation" }
2610
Linus Torvalds1da177e2005-04-16 15:20:36 -07002611;
2612/*===========================================================================*/
Alexey Dobriyan6b914c52008-04-10 14:34:35 -07002613static int ray_cs_proc_show(struct seq_file *m, void *v)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002614{
2615/* Print current values which are not available via other means
John Daiker141fa612009-03-10 06:59:54 -07002616 * eg ifconfig
Linus Torvalds1da177e2005-04-16 15:20:36 -07002617 */
John Daiker141fa612009-03-10 06:59:54 -07002618 int i;
2619 struct pcmcia_device *link;
2620 struct net_device *dev;
2621 ray_dev_t *local;
2622 UCHAR *p;
2623 struct freq_hop_element *pfh;
2624 UCHAR c[33];
Linus Torvalds1da177e2005-04-16 15:20:36 -07002625
John Daiker141fa612009-03-10 06:59:54 -07002626 link = this_device;
2627 if (!link)
2628 return 0;
2629 dev = (struct net_device *)link->priv;
2630 if (!dev)
2631 return 0;
2632 local = netdev_priv(dev);
2633 if (!local)
2634 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002635
John Daiker141fa612009-03-10 06:59:54 -07002636 seq_puts(m, "Raylink Wireless LAN driver status\n");
2637 seq_printf(m, "%s\n", rcsid);
2638 /* build 4 does not report version, and field is 0x55 after memtest */
2639 seq_puts(m, "Firmware version = ");
2640 if (local->fw_ver == 0x55)
2641 seq_puts(m, "4 - Use dump_cis for more details\n");
2642 else
2643 seq_printf(m, "%2d.%02d.%02d\n",
2644 local->fw_ver, local->fw_bld, local->fw_var);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002645
John Daiker141fa612009-03-10 06:59:54 -07002646 for (i = 0; i < 32; i++)
2647 c[i] = local->sparm.b5.a_current_ess_id[i];
2648 c[32] = 0;
2649 seq_printf(m, "%s network ESSID = \"%s\"\n",
2650 nettype[local->sparm.b5.a_network_type], c);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002651
John Daiker141fa612009-03-10 06:59:54 -07002652 p = local->bss_id;
2653 seq_printf(m, "BSSID = %pM\n", p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002654
John Daiker141fa612009-03-10 06:59:54 -07002655 seq_printf(m, "Country code = %d\n",
2656 local->sparm.b5.a_curr_country_code);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002657
John Daiker141fa612009-03-10 06:59:54 -07002658 i = local->card_status;
2659 if (i < 0)
2660 i = 10;
2661 if (i > 16)
2662 i = 10;
2663 seq_printf(m, "Card status = %s\n", card_status[i]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002664
John Daiker141fa612009-03-10 06:59:54 -07002665 seq_printf(m, "Framing mode = %s\n", framing[translate]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002666
John Daiker141fa612009-03-10 06:59:54 -07002667 seq_printf(m, "Last pkt signal lvl = %d\n", local->last_rsl);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002668
John Daiker141fa612009-03-10 06:59:54 -07002669 if (local->beacon_rxed) {
2670 /* Pull some fields out of last beacon received */
2671 seq_printf(m, "Beacon Interval = %d Kus\n",
2672 local->last_bcn.beacon_intvl[0]
2673 + 256 * local->last_bcn.beacon_intvl[1]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002674
John Daiker141fa612009-03-10 06:59:54 -07002675 p = local->last_bcn.elements;
2676 if (p[0] == C_ESSID_ELEMENT_ID)
2677 p += p[1] + 2;
2678 else {
2679 seq_printf(m,
2680 "Parse beacon failed at essid element id = %d\n",
2681 p[0]);
2682 return 0;
2683 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002684
John Daiker141fa612009-03-10 06:59:54 -07002685 if (p[0] == C_SUPPORTED_RATES_ELEMENT_ID) {
2686 seq_puts(m, "Supported rate codes = ");
2687 for (i = 2; i < p[1] + 2; i++)
2688 seq_printf(m, "0x%02x ", p[i]);
2689 seq_putc(m, '\n');
2690 p += p[1] + 2;
2691 } else {
2692 seq_puts(m, "Parse beacon failed at rates element\n");
2693 return 0;
2694 }
2695
2696 if (p[0] == C_FH_PARAM_SET_ELEMENT_ID) {
2697 pfh = (struct freq_hop_element *)p;
2698 seq_printf(m, "Hop dwell = %d Kus\n",
2699 pfh->dwell_time[0] +
2700 256 * pfh->dwell_time[1]);
Frans Popcb01b092010-03-24 19:46:34 +01002701 seq_printf(m, "Hop set = %d\n",
John Daiker141fa612009-03-10 06:59:54 -07002702 pfh->hop_set);
Frans Popcb01b092010-03-24 19:46:34 +01002703 seq_printf(m, "Hop pattern = %d\n",
John Daiker141fa612009-03-10 06:59:54 -07002704 pfh->hop_pattern);
Frans Popcb01b092010-03-24 19:46:34 +01002705 seq_printf(m, "Hop index = %d\n",
John Daiker141fa612009-03-10 06:59:54 -07002706 pfh->hop_index);
2707 p += p[1] + 2;
2708 } else {
2709 seq_puts(m,
2710 "Parse beacon failed at FH param element\n");
2711 return 0;
2712 }
2713 } else {
2714 seq_puts(m, "No beacons received\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002715 }
John Daiker141fa612009-03-10 06:59:54 -07002716 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002717}
2718
Alexey Dobriyan6b914c52008-04-10 14:34:35 -07002719static int ray_cs_proc_open(struct inode *inode, struct file *file)
2720{
2721 return single_open(file, ray_cs_proc_show, NULL);
2722}
2723
2724static const struct file_operations ray_cs_proc_fops = {
John Daiker141fa612009-03-10 06:59:54 -07002725 .owner = THIS_MODULE,
2726 .open = ray_cs_proc_open,
2727 .read = seq_read,
2728 .llseek = seq_lseek,
2729 .release = single_release,
Alexey Dobriyan6b914c52008-04-10 14:34:35 -07002730};
Linus Torvalds1da177e2005-04-16 15:20:36 -07002731#endif
2732/*===========================================================================*/
2733static int build_auth_frame(ray_dev_t *local, UCHAR *dest, int auth_type)
2734{
John Daiker141fa612009-03-10 06:59:54 -07002735 int addr;
2736 struct ccs __iomem *pccs;
2737 struct tx_msg __iomem *ptx;
2738 int ccsindex;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002739
John Daiker141fa612009-03-10 06:59:54 -07002740 /* If no tx buffers available, return */
2741 if ((ccsindex = get_free_tx_ccs(local)) < 0) {
Dominik Brodowski624dd662009-10-24 15:52:44 +02002742 pr_debug("ray_cs send authenticate - No free tx ccs\n");
John Daiker141fa612009-03-10 06:59:54 -07002743 return -1;
2744 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002745
John Daiker141fa612009-03-10 06:59:54 -07002746 pccs = ccs_base(local) + ccsindex;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002747
John Daiker141fa612009-03-10 06:59:54 -07002748 /* Address in card space */
2749 addr = TX_BUF_BASE + (ccsindex << 11);
2750 /* fill in the CCS */
2751 writeb(CCS_TX_REQUEST, &pccs->cmd);
2752 writeb(addr >> 8, pccs->var.tx_request.tx_data_ptr);
2753 writeb(0x20, pccs->var.tx_request.tx_data_ptr + 1);
2754 writeb(TX_AUTHENTICATE_LENGTH_MSB, pccs->var.tx_request.tx_data_length);
2755 writeb(TX_AUTHENTICATE_LENGTH_LSB,
2756 pccs->var.tx_request.tx_data_length + 1);
2757 writeb(0, &pccs->var.tx_request.pow_sav_mode);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002758
John Daiker141fa612009-03-10 06:59:54 -07002759 ptx = local->sram + addr;
2760 /* fill in the mac header */
2761 writeb(PROTOCOL_VER | AUTHENTIC_TYPE, &ptx->mac.frame_ctl_1);
2762 writeb(0, &ptx->mac.frame_ctl_2);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002763
John Daiker141fa612009-03-10 06:59:54 -07002764 memcpy_toio(ptx->mac.addr_1, dest, ADDRLEN);
2765 memcpy_toio(ptx->mac.addr_2, local->sparm.b4.a_mac_addr, ADDRLEN);
2766 memcpy_toio(ptx->mac.addr_3, local->bss_id, ADDRLEN);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002767
John Daiker141fa612009-03-10 06:59:54 -07002768 /* Fill in msg body with protocol 00 00, sequence 01 00 ,status 00 00 */
2769 memset_io(ptx->var, 0, 6);
2770 writeb(auth_type & 0xff, ptx->var + 2);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002771
John Daiker141fa612009-03-10 06:59:54 -07002772 /* Interrupt the firmware to process the command */
2773 if (interrupt_ecf(local, ccsindex)) {
Dominik Brodowski624dd662009-10-24 15:52:44 +02002774 pr_debug(
John Daiker141fa612009-03-10 06:59:54 -07002775 "ray_cs send authentication request failed - ECF not ready for intr\n");
2776 writeb(CCS_BUFFER_FREE, &(pccs++)->buffer_status);
2777 return -1;
2778 }
2779 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002780} /* End build_auth_frame */
2781
2782/*===========================================================================*/
2783#ifdef CONFIG_PROC_FS
Alexey Dobriyan83daee02009-11-25 10:12:20 +03002784static ssize_t ray_cs_essid_proc_write(struct file *file,
2785 const char __user *buffer, size_t count, loff_t *pos)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002786{
2787 static char proc_essid[33];
Alan Cox575c9ed2009-10-27 15:35:55 +00002788 unsigned int len = count;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002789
2790 if (len > 32)
2791 len = 32;
2792 memset(proc_essid, 0, 33);
2793 if (copy_from_user(proc_essid, buffer, len))
2794 return -EFAULT;
2795 essid = proc_essid;
2796 return count;
2797}
2798
Alexey Dobriyan83daee02009-11-25 10:12:20 +03002799static const struct file_operations ray_cs_essid_proc_fops = {
2800 .owner = THIS_MODULE,
2801 .write = ray_cs_essid_proc_write,
2802};
2803
2804static ssize_t int_proc_write(struct file *file, const char __user *buffer,
2805 size_t count, loff_t *pos)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002806{
2807 static char proc_number[10];
2808 char *p;
2809 int nr, len;
2810
2811 if (!count)
2812 return 0;
2813
2814 if (count > 9)
2815 return -EINVAL;
2816 if (copy_from_user(proc_number, buffer, count))
2817 return -EFAULT;
2818 p = proc_number;
2819 nr = 0;
2820 len = count;
2821 do {
2822 unsigned int c = *p - '0';
2823 if (c > 9)
2824 return -EINVAL;
John Daiker141fa612009-03-10 06:59:54 -07002825 nr = nr * 10 + c;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002826 p++;
2827 } while (--len);
Alexey Dobriyan83daee02009-11-25 10:12:20 +03002828 *(int *)PDE(file->f_path.dentry->d_inode)->data = nr;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002829 return count;
2830}
Alexey Dobriyan83daee02009-11-25 10:12:20 +03002831
2832static const struct file_operations int_proc_fops = {
2833 .owner = THIS_MODULE,
2834 .write = int_proc_write,
2835};
Linus Torvalds1da177e2005-04-16 15:20:36 -07002836#endif
2837
Dominik Brodowskif57ea2a2005-06-27 16:28:24 -07002838static struct pcmcia_device_id ray_ids[] = {
2839 PCMCIA_DEVICE_MANF_CARD(0x01a6, 0x0000),
2840 PCMCIA_DEVICE_NULL,
2841};
John Daiker141fa612009-03-10 06:59:54 -07002842
Dominik Brodowskif57ea2a2005-06-27 16:28:24 -07002843MODULE_DEVICE_TABLE(pcmcia, ray_ids);
2844
Linus Torvalds1da177e2005-04-16 15:20:36 -07002845static struct pcmcia_driver ray_driver = {
John Daiker141fa612009-03-10 06:59:54 -07002846 .owner = THIS_MODULE,
2847 .drv = {
2848 .name = "ray_cs",
2849 },
2850 .probe = ray_probe,
2851 .remove = ray_detach,
2852 .id_table = ray_ids,
2853 .suspend = ray_suspend,
2854 .resume = ray_resume,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002855};
2856
2857static int __init init_ray_cs(void)
2858{
John Daiker141fa612009-03-10 06:59:54 -07002859 int rc;
2860
Dominik Brodowski624dd662009-10-24 15:52:44 +02002861 pr_debug("%s\n", rcsid);
John Daiker141fa612009-03-10 06:59:54 -07002862 rc = pcmcia_register_driver(&ray_driver);
Dominik Brodowski624dd662009-10-24 15:52:44 +02002863 pr_debug("raylink init_module register_pcmcia_driver returns 0x%x\n",
John Daiker141fa612009-03-10 06:59:54 -07002864 rc);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002865
2866#ifdef CONFIG_PROC_FS
John Daiker141fa612009-03-10 06:59:54 -07002867 proc_mkdir("driver/ray_cs", NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002868
John Daiker141fa612009-03-10 06:59:54 -07002869 proc_create("driver/ray_cs/ray_cs", 0, NULL, &ray_cs_proc_fops);
Alexey Dobriyan83daee02009-11-25 10:12:20 +03002870 proc_create("driver/ray_cs/essid", S_IWUSR, NULL, &ray_cs_essid_proc_fops);
2871 proc_create_data("driver/ray_cs/net_type", S_IWUSR, NULL, &int_proc_fops, &net_type);
2872 proc_create_data("driver/ray_cs/translate", S_IWUSR, NULL, &int_proc_fops, &translate);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002873#endif
John Daiker141fa612009-03-10 06:59:54 -07002874 if (translate != 0)
2875 translate = 1;
2876 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002877} /* init_ray_cs */
2878
2879/*===========================================================================*/
2880
2881static void __exit exit_ray_cs(void)
2882{
Dominik Brodowski624dd662009-10-24 15:52:44 +02002883 pr_debug("ray_cs: cleanup_module\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002884
2885#ifdef CONFIG_PROC_FS
John Daiker141fa612009-03-10 06:59:54 -07002886 remove_proc_entry("driver/ray_cs/ray_cs", NULL);
2887 remove_proc_entry("driver/ray_cs/essid", NULL);
2888 remove_proc_entry("driver/ray_cs/net_type", NULL);
2889 remove_proc_entry("driver/ray_cs/translate", NULL);
2890 remove_proc_entry("driver/ray_cs", NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002891#endif
2892
John Daiker141fa612009-03-10 06:59:54 -07002893 pcmcia_unregister_driver(&ray_driver);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002894} /* exit_ray_cs */
2895
2896module_init(init_ray_cs);
2897module_exit(exit_ray_cs);
2898
2899/*===========================================================================*/