blob: 1457f34efa9a4e9f6324b35aaba5e43128144e42 [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/cistpl.h>
50#include <pcmcia/cisreg.h>
51#include <pcmcia/ds.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070052
53#include <linux/wireless.h>
Michael Wu113b8982006-08-13 23:27:17 -070054#include <net/iw_handler.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070055
56#include <asm/io.h>
57#include <asm/system.h>
58#include <asm/byteorder.h>
59#include <asm/uaccess.h>
60
61/* Warning : these stuff will slow down the driver... */
62#define WIRELESS_SPY /* Enable spying addresses */
63/* Definitions we need for spy */
John Daiker141fa612009-03-10 06:59:54 -070064typedef struct iw_statistics iw_stats;
65typedef u_char mac_addr[ETH_ALEN]; /* Hardware address */
Linus Torvalds1da177e2005-04-16 15:20:36 -070066
67#include "rayctl.h"
68#include "ray_cs.h"
69
Linus Torvalds1da177e2005-04-16 15:20:36 -070070
Linus Torvalds1da177e2005-04-16 15:20:36 -070071/** Prototypes based on PCMCIA skeleton driver *******************************/
Dominik Brodowski15b99ac2006-03-31 17:26:06 +020072static int ray_config(struct pcmcia_device *link);
Dominik Brodowskifba395e2006-03-31 17:21:06 +020073static void ray_release(struct pcmcia_device *link);
Dominik Brodowskicc3b4862005-11-14 21:23:14 +010074static void ray_detach(struct pcmcia_device *p_dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -070075
76/***** Prototypes indicated by device structure ******************************/
77static int ray_dev_close(struct net_device *dev);
78static int ray_dev_config(struct net_device *dev, struct ifmap *map);
79static struct net_device_stats *ray_get_stats(struct net_device *dev);
80static int ray_dev_init(struct net_device *dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -070081
Jeff Garzik7282d492006-09-13 14:30:00 -040082static const struct ethtool_ops netdev_ethtool_ops;
Linus Torvalds1da177e2005-04-16 15:20:36 -070083
84static int ray_open(struct net_device *dev);
Stephen Hemmingerd0cf9c02009-08-31 19:50:57 +000085static netdev_tx_t ray_dev_start_xmit(struct sk_buff *skb,
86 struct net_device *dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -070087static void set_multicast_list(struct net_device *dev);
88static void ray_update_multi_list(struct net_device *dev, int all);
89static int translate_frame(ray_dev_t *local, struct tx_msg __iomem *ptx,
John Daiker141fa612009-03-10 06:59:54 -070090 unsigned char *data, int len);
91static void ray_build_header(ray_dev_t *local, struct tx_msg __iomem *ptx,
92 UCHAR msg_type, unsigned char *data);
Linus Torvalds1da177e2005-04-16 15:20:36 -070093static void untranslate(ray_dev_t *local, struct sk_buff *skb, int len);
John Daiker141fa612009-03-10 06:59:54 -070094static iw_stats *ray_get_wireless_stats(struct net_device *dev);
95static const struct iw_handler_def ray_handler_def;
Linus Torvalds1da177e2005-04-16 15:20:36 -070096
97/***** Prototypes for raylink functions **************************************/
Linus Torvalds1da177e2005-04-16 15:20:36 -070098static void authenticate(ray_dev_t *local);
99static int build_auth_frame(ray_dev_t *local, UCHAR *dest, int auth_type);
100static void authenticate_timeout(u_long);
101static int get_free_ccs(ray_dev_t *local);
102static int get_free_tx_ccs(ray_dev_t *local);
103static void init_startup_params(ray_dev_t *local);
104static int parse_addr(char *in_str, UCHAR *out);
John Daiker141fa612009-03-10 06:59:54 -0700105static int ray_hw_xmit(unsigned char *data, int len, struct net_device *dev, UCHAR type);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700106static int ray_init(struct net_device *dev);
107static int interrupt_ecf(ray_dev_t *local, int ccs);
108static void ray_reset(struct net_device *dev);
109static void ray_update_parm(struct net_device *dev, UCHAR objid, UCHAR *value, int len);
110static void verify_dl_startup(u_long);
111
112/* Prototypes for interrpt time functions **********************************/
John Daiker141fa612009-03-10 06:59:54 -0700113static irqreturn_t ray_interrupt(int reg, void *dev_id);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700114static void clear_interrupt(ray_dev_t *local);
John Daiker141fa612009-03-10 06:59:54 -0700115static void rx_deauthenticate(ray_dev_t *local, struct rcs __iomem *prcs,
116 unsigned int pkt_addr, int rx_len);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700117static int copy_from_rx_buff(ray_dev_t *local, UCHAR *dest, int pkt_addr, int len);
118static void ray_rx(struct net_device *dev, ray_dev_t *local, struct rcs __iomem *prcs);
119static void release_frag_chain(ray_dev_t *local, struct rcs __iomem *prcs);
120static void rx_authenticate(ray_dev_t *local, struct rcs __iomem *prcs,
John Daiker141fa612009-03-10 06:59:54 -0700121 unsigned int pkt_addr, int rx_len);
122static void rx_data(struct net_device *dev, struct rcs __iomem *prcs,
123 unsigned int pkt_addr, int rx_len);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700124static void associate(ray_dev_t *local);
125
126/* Card command functions */
127static int dl_startup_params(struct net_device *dev);
128static void join_net(u_long local);
129static void start_net(u_long local);
130/* void start_net(ray_dev_t *local); */
131
132/*===========================================================================*/
133/* Parameters that can be set with 'insmod' */
134
135/* ADHOC=0, Infrastructure=1 */
136static int net_type = ADHOC;
137
138/* Hop dwell time in Kus (1024 us units defined by 802.11) */
139static int hop_dwell = 128;
140
141/* Beacon period in Kus */
142static int beacon_period = 256;
143
144/* power save mode (0 = off, 1 = save power) */
145static int psm;
146
147/* String for network's Extended Service Set ID. 32 Characters max */
148static char *essid;
149
150/* Default to encapsulation unless translation requested */
151static int translate = 1;
152
153static int country = USA;
154
155static int sniffer;
156
157static int bc;
158
159/* 48 bit physical card address if overriding card's real physical
160 * address is required. Since IEEE 802.11 addresses are 48 bits
161 * like ethernet, an int can't be used, so a string is used. To
162 * allow use of addresses starting with a decimal digit, the first
163 * character must be a letter and will be ignored. This letter is
164 * followed by up to 12 hex digits which are the address. If less
165 * than 12 digits are used, the address will be left filled with 0's.
166 * Note that bit 0 of the first byte is the broadcast bit, and evil
167 * things will happen if it is not 0 in a card address.
168 */
169static char *phy_addr = NULL;
170
171
Dominik Brodowskifba395e2006-03-31 17:21:06 +0200172/* A struct pcmcia_device structure has fields for most things that are needed
Linus Torvalds1da177e2005-04-16 15:20:36 -0700173 to keep track of a socket, but there will usually be some device
174 specific information that also needs to be kept track of. The
Dominik Brodowskifba395e2006-03-31 17:21:06 +0200175 'priv' pointer in a struct pcmcia_device structure can be used to point to
Linus Torvalds1da177e2005-04-16 15:20:36 -0700176 a device-specific private data structure, like this.
177*/
178static unsigned int ray_mem_speed = 500;
179
Dominik Brodowskifd238232006-03-05 10:45:09 +0100180/* WARNING: THIS DRIVER IS NOT CAPABLE OF HANDLING MULTIPLE DEVICES! */
181static struct pcmcia_device *this_device = NULL;
182
Linus Torvalds1da177e2005-04-16 15:20:36 -0700183MODULE_AUTHOR("Corey Thomas <corey@world.std.com>");
184MODULE_DESCRIPTION("Raylink/WebGear wireless LAN driver");
185MODULE_LICENSE("GPL");
186
187module_param(net_type, int, 0);
188module_param(hop_dwell, int, 0);
189module_param(beacon_period, int, 0);
190module_param(psm, int, 0);
191module_param(essid, charp, 0);
192module_param(translate, int, 0);
193module_param(country, int, 0);
194module_param(sniffer, int, 0);
195module_param(bc, int, 0);
196module_param(phy_addr, charp, 0);
197module_param(ray_mem_speed, int, 0);
198
199static UCHAR b5_default_startup_parms[] = {
John Daiker141fa612009-03-10 06:59:54 -0700200 0, 0, /* Adhoc station */
201 'L', 'I', 'N', 'U', 'X', 0, 0, 0, /* 32 char ESSID */
202 0, 0, 0, 0, 0, 0, 0, 0,
203 0, 0, 0, 0, 0, 0, 0, 0,
204 0, 0, 0, 0, 0, 0, 0, 0,
205 1, 0, /* Active scan, CA Mode */
206 0, 0, 0, 0, 0, 0, /* No default MAC addr */
207 0x7f, 0xff, /* Frag threshold */
208 0x00, 0x80, /* Hop time 128 Kus */
209 0x01, 0x00, /* Beacon period 256 Kus */
210 0x01, 0x07, 0xa3, /* DTIM, retries, ack timeout */
211 0x1d, 0x82, 0x4e, /* SIFS, DIFS, PIFS */
212 0x7f, 0xff, /* RTS threshold */
213 0x04, 0xe2, 0x38, 0xA4, /* scan_dwell, max_scan_dwell */
214 0x05, /* assoc resp timeout thresh */
215 0x08, 0x02, 0x08, /* adhoc, infra, super cycle max */
216 0, /* Promiscuous mode */
217 0x0c, 0x0bd, /* Unique word */
218 0x32, /* Slot time */
219 0xff, 0xff, /* roam-low snr, low snr count */
220 0x05, 0xff, /* Infra, adhoc missed bcn thresh */
221 0x01, 0x0b, 0x4f, /* USA, hop pattern, hop pat length */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700222/* b4 - b5 differences start here */
John Daiker141fa612009-03-10 06:59:54 -0700223 0x00, 0x3f, /* CW max */
224 0x00, 0x0f, /* CW min */
225 0x04, 0x08, /* Noise gain, limit offset */
226 0x28, 0x28, /* det rssi, med busy offsets */
227 7, /* det sync thresh */
228 0, 2, 2, /* test mode, min, max */
229 0, /* allow broadcast SSID probe resp */
230 0, 0, /* privacy must start, can join */
231 2, 0, 0, 0, 0, 0, 0, 0 /* basic rate set */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700232};
233
234static UCHAR b4_default_startup_parms[] = {
John Daiker141fa612009-03-10 06:59:54 -0700235 0, 0, /* Adhoc station */
236 'L', 'I', 'N', 'U', 'X', 0, 0, 0, /* 32 char ESSID */
237 0, 0, 0, 0, 0, 0, 0, 0,
238 0, 0, 0, 0, 0, 0, 0, 0,
239 0, 0, 0, 0, 0, 0, 0, 0,
240 1, 0, /* Active scan, CA Mode */
241 0, 0, 0, 0, 0, 0, /* No default MAC addr */
242 0x7f, 0xff, /* Frag threshold */
243 0x02, 0x00, /* Hop time */
244 0x00, 0x01, /* Beacon period */
245 0x01, 0x07, 0xa3, /* DTIM, retries, ack timeout */
246 0x1d, 0x82, 0xce, /* SIFS, DIFS, PIFS */
247 0x7f, 0xff, /* RTS threshold */
248 0xfb, 0x1e, 0xc7, 0x5c, /* scan_dwell, max_scan_dwell */
249 0x05, /* assoc resp timeout thresh */
250 0x04, 0x02, 0x4, /* adhoc, infra, super cycle max */
251 0, /* Promiscuous mode */
252 0x0c, 0x0bd, /* Unique word */
253 0x4e, /* Slot time (TBD seems wrong) */
254 0xff, 0xff, /* roam-low snr, low snr count */
255 0x05, 0xff, /* Infra, adhoc missed bcn thresh */
256 0x01, 0x0b, 0x4e, /* USA, hop pattern, hop pat length */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700257/* b4 - b5 differences start here */
John Daiker141fa612009-03-10 06:59:54 -0700258 0x3f, 0x0f, /* CW max, min */
259 0x04, 0x08, /* Noise gain, limit offset */
260 0x28, 0x28, /* det rssi, med busy offsets */
261 7, /* det sync thresh */
262 0, 2, 2 /* test mode, min, max */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700263};
John Daiker141fa612009-03-10 06:59:54 -0700264
Linus Torvalds1da177e2005-04-16 15:20:36 -0700265/*===========================================================================*/
John Daiker141fa612009-03-10 06:59:54 -0700266static unsigned char eth2_llc[] = { 0xaa, 0xaa, 3, 0, 0, 0 };
Linus Torvalds1da177e2005-04-16 15:20:36 -0700267
268static char hop_pattern_length[] = { 1,
John Daiker141fa612009-03-10 06:59:54 -0700269 USA_HOP_MOD, EUROPE_HOP_MOD,
270 JAPAN_HOP_MOD, KOREA_HOP_MOD,
271 SPAIN_HOP_MOD, FRANCE_HOP_MOD,
272 ISRAEL_HOP_MOD, AUSTRALIA_HOP_MOD,
273 JAPAN_TEST_HOP_MOD
Linus Torvalds1da177e2005-04-16 15:20:36 -0700274};
275
John Daiker141fa612009-03-10 06:59:54 -0700276static char rcsid[] =
277 "Raylink/WebGear wireless LAN - Corey <Thomas corey@world.std.com>";
Linus Torvalds1da177e2005-04-16 15:20:36 -0700278
Stephen Hemminger32f5a332009-03-20 19:36:28 +0000279static const struct net_device_ops ray_netdev_ops = {
280 .ndo_init = ray_dev_init,
281 .ndo_open = ray_open,
282 .ndo_stop = ray_dev_close,
283 .ndo_start_xmit = ray_dev_start_xmit,
284 .ndo_set_config = ray_dev_config,
285 .ndo_get_stats = ray_get_stats,
286 .ndo_set_multicast_list = set_multicast_list,
287 .ndo_change_mtu = eth_change_mtu,
288 .ndo_set_mac_address = eth_mac_addr,
289 .ndo_validate_addr = eth_validate_addr,
290};
291
Linus Torvalds1da177e2005-04-16 15:20:36 -0700292/*=============================================================================
293 ray_attach() creates an "instance" of the driver, allocating
294 local data structures for one device. The device is registered
295 with Card Services.
296 The dev_link structure is initialized, but we don't actually
297 configure the card at this point -- we wait until we receive a
298 card insertion event.
299=============================================================================*/
Dominik Brodowski15b99ac2006-03-31 17:26:06 +0200300static int ray_probe(struct pcmcia_device *p_dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700301{
John Daiker141fa612009-03-10 06:59:54 -0700302 ray_dev_t *local;
303 struct net_device *dev;
Dominik Brodowskifd238232006-03-05 10:45:09 +0100304
Dominik Brodowski624dd662009-10-24 15:52:44 +0200305 dev_dbg(&p_dev->dev, "ray_attach()\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700306
John Daiker141fa612009-03-10 06:59:54 -0700307 /* Allocate space for private device-specific data */
308 dev = alloc_etherdev(sizeof(ray_dev_t));
309 if (!dev)
310 goto fail_alloc_dev;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700311
John Daiker141fa612009-03-10 06:59:54 -0700312 local = netdev_priv(dev);
313 local->finder = p_dev;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700314
John Daiker141fa612009-03-10 06:59:54 -0700315 /* The io structure describes IO port mapping. None used here */
Dominik Brodowski90abdc32010-07-24 17:23:51 +0200316 p_dev->resource[0]->end = 0;
317 p_dev->resource[0]->flags |= IO_DATA_PATH_WIDTH_8;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700318
John Daiker141fa612009-03-10 06:59:54 -0700319 /* General socket configuration */
Dominik Brodowski1ac71e52010-07-29 19:27:09 +0200320 p_dev->config_flags |= CONF_ENABLE_IRQ;
Dominik Brodowski7feabb62010-07-29 18:35:47 +0200321 p_dev->config_index = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700322
John Daiker141fa612009-03-10 06:59:54 -0700323 p_dev->priv = dev;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700324
John Daiker141fa612009-03-10 06:59:54 -0700325 local->finder = p_dev;
326 local->card_status = CARD_INSERTED;
327 local->authentication_state = UNAUTHENTICATED;
328 local->num_multi = 0;
Dominik Brodowski624dd662009-10-24 15:52:44 +0200329 dev_dbg(&p_dev->dev, "ray_attach p_dev = %p, dev = %p, local = %p, intr = %p\n",
John Daiker141fa612009-03-10 06:59:54 -0700330 p_dev, dev, local, &ray_interrupt);
331
332 /* Raylink entries in the device structure */
Stephen Hemminger32f5a332009-03-20 19:36:28 +0000333 dev->netdev_ops = &ray_netdev_ops;
John Daiker141fa612009-03-10 06:59:54 -0700334 SET_ETHTOOL_OPS(dev, &netdev_ethtool_ops);
335 dev->wireless_handlers = &ray_handler_def;
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -0700336#ifdef WIRELESS_SPY
John Daiker141fa612009-03-10 06:59:54 -0700337 local->wireless_data.spy_data = &local->spy_data;
338 dev->wireless_data = &local->wireless_data;
339#endif /* WIRELESS_SPY */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700340
Linus Torvalds1da177e2005-04-16 15:20:36 -0700341
Dominik Brodowski624dd662009-10-24 15:52:44 +0200342 dev_dbg(&p_dev->dev, "ray_cs ray_attach calling ether_setup.)\n");
John Daiker141fa612009-03-10 06:59:54 -0700343 netif_stop_queue(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700344
John Daiker141fa612009-03-10 06:59:54 -0700345 init_timer(&local->timer);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700346
John Daiker141fa612009-03-10 06:59:54 -0700347 this_device = p_dev;
348 return ray_config(p_dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700349
350fail_alloc_dev:
John Daiker141fa612009-03-10 06:59:54 -0700351 return -ENOMEM;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700352} /* ray_attach */
John Daiker141fa612009-03-10 06:59:54 -0700353
Linus Torvalds1da177e2005-04-16 15:20:36 -0700354/*=============================================================================
355 This deletes a driver "instance". The device is de-registered
356 with Card Services. If it has been released, all local data
357 structures are freed. Otherwise, the structures will be freed
358 when the device is released.
359=============================================================================*/
Dominik Brodowskifba395e2006-03-31 17:21:06 +0200360static void ray_detach(struct pcmcia_device *link)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700361{
John Daiker141fa612009-03-10 06:59:54 -0700362 struct net_device *dev;
363 ray_dev_t *local;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700364
Dominik Brodowski624dd662009-10-24 15:52:44 +0200365 dev_dbg(&link->dev, "ray_detach\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700366
John Daiker141fa612009-03-10 06:59:54 -0700367 this_device = NULL;
368 dev = link->priv;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700369
John Daiker141fa612009-03-10 06:59:54 -0700370 ray_release(link);
Dominik Brodowskicc3b4862005-11-14 21:23:14 +0100371
John Daiker141fa612009-03-10 06:59:54 -0700372 local = netdev_priv(dev);
373 del_timer(&local->timer);
Dominik Brodowskicc3b4862005-11-14 21:23:14 +0100374
John Daiker141fa612009-03-10 06:59:54 -0700375 if (link->priv) {
Dominik Brodowskic7c2fa02010-03-20 19:39:26 +0100376 unregister_netdev(dev);
John Daiker141fa612009-03-10 06:59:54 -0700377 free_netdev(dev);
378 }
Dominik Brodowski624dd662009-10-24 15:52:44 +0200379 dev_dbg(&link->dev, "ray_cs ray_detach ending\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700380} /* ray_detach */
John Daiker141fa612009-03-10 06:59:54 -0700381
Linus Torvalds1da177e2005-04-16 15:20:36 -0700382/*=============================================================================
383 ray_config() is run after a CARD_INSERTION event
384 is received, to configure the PCMCIA socket, and to make the
385 ethernet device available to the system.
386=============================================================================*/
Linus Torvalds1da177e2005-04-16 15:20:36 -0700387#define MAX_TUPLE_SIZE 128
Dominik Brodowski15b99ac2006-03-31 17:26:06 +0200388static int ray_config(struct pcmcia_device *link)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700389{
Dominik Brodowski624dd662009-10-24 15:52:44 +0200390 int ret = 0;
John Daiker141fa612009-03-10 06:59:54 -0700391 int i;
John Daiker141fa612009-03-10 06:59:54 -0700392 struct net_device *dev = (struct net_device *)link->priv;
393 ray_dev_t *local = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700394
Dominik Brodowski624dd662009-10-24 15:52:44 +0200395 dev_dbg(&link->dev, "ray_config\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700396
John Daiker141fa612009-03-10 06:59:54 -0700397 /* Determine card type and firmware version */
398 printk(KERN_INFO "ray_cs Detected: %s%s%s%s\n",
399 link->prod_id[0] ? link->prod_id[0] : " ",
400 link->prod_id[1] ? link->prod_id[1] : " ",
401 link->prod_id[2] ? link->prod_id[2] : " ",
402 link->prod_id[3] ? link->prod_id[3] : " ");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700403
John Daiker141fa612009-03-10 06:59:54 -0700404 /* Now allocate an interrupt line. Note that this does not
405 actually assign a handler to the interrupt.
406 */
Dominik Brodowskieb141202010-03-07 12:21:16 +0100407 ret = pcmcia_request_irq(link, ray_interrupt);
Dominik Brodowski624dd662009-10-24 15:52:44 +0200408 if (ret)
409 goto failed;
Dominik Brodowskieb141202010-03-07 12:21:16 +0100410 dev->irq = link->irq;
John Daiker141fa612009-03-10 06:59:54 -0700411
412 /* This actually configures the PCMCIA socket -- setting up
413 the I/O windows and the interrupt mapping.
414 */
Dominik Brodowski1ac71e52010-07-29 19:27:09 +0200415 ret = pcmcia_enable_device(link);
Dominik Brodowski624dd662009-10-24 15:52:44 +0200416 if (ret)
417 goto failed;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700418
419/*** Set up 32k window for shared memory (transmit and control) ************/
Dominik Brodowskicdb13802010-07-28 10:59:06 +0200420 link->resource[2]->flags |= WIN_DATA_WIDTH_8 | WIN_MEMORY_TYPE_CM | WIN_ENABLE | WIN_USE_WAIT;
421 link->resource[2]->start = 0;
422 link->resource[2]->end = 0x8000;
423 ret = pcmcia_request_window(link, link->resource[2], ray_mem_speed);
Dominik Brodowski624dd662009-10-24 15:52:44 +0200424 if (ret)
425 goto failed;
Dominik Brodowskicdb13802010-07-28 10:59:06 +0200426 ret = pcmcia_map_mem_page(link, link->resource[2], 0);
Dominik Brodowski624dd662009-10-24 15:52:44 +0200427 if (ret)
428 goto failed;
Dominik Brodowskicdb13802010-07-28 10:59:06 +0200429 local->sram = ioremap(link->resource[2]->start,
430 resource_size(link->resource[2]));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700431
432/*** Set up 16k window for shared memory (receive buffer) ***************/
Dominik Brodowskicdb13802010-07-28 10:59:06 +0200433 link->resource[3]->flags |=
John Daiker141fa612009-03-10 06:59:54 -0700434 WIN_DATA_WIDTH_8 | WIN_MEMORY_TYPE_CM | WIN_ENABLE | WIN_USE_WAIT;
Dominik Brodowskicdb13802010-07-28 10:59:06 +0200435 link->resource[3]->start = 0;
436 link->resource[3]->end = 0x4000;
437 ret = pcmcia_request_window(link, link->resource[3], ray_mem_speed);
Dominik Brodowski624dd662009-10-24 15:52:44 +0200438 if (ret)
439 goto failed;
Dominik Brodowskicdb13802010-07-28 10:59:06 +0200440 ret = pcmcia_map_mem_page(link, link->resource[3], 0x8000);
Dominik Brodowski624dd662009-10-24 15:52:44 +0200441 if (ret)
442 goto failed;
Dominik Brodowskicdb13802010-07-28 10:59:06 +0200443 local->rmem = ioremap(link->resource[3]->start,
444 resource_size(link->resource[3]));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700445
446/*** Set up window for attribute memory ***********************************/
Dominik Brodowskicdb13802010-07-28 10:59:06 +0200447 link->resource[4]->flags |=
John Daiker141fa612009-03-10 06:59:54 -0700448 WIN_DATA_WIDTH_8 | WIN_MEMORY_TYPE_AM | WIN_ENABLE | WIN_USE_WAIT;
Dominik Brodowskicdb13802010-07-28 10:59:06 +0200449 link->resource[4]->start = 0;
450 link->resource[4]->end = 0x1000;
451 ret = pcmcia_request_window(link, link->resource[4], ray_mem_speed);
Dominik Brodowski624dd662009-10-24 15:52:44 +0200452 if (ret)
453 goto failed;
Dominik Brodowskicdb13802010-07-28 10:59:06 +0200454 ret = pcmcia_map_mem_page(link, link->resource[4], 0);
Dominik Brodowski624dd662009-10-24 15:52:44 +0200455 if (ret)
456 goto failed;
Dominik Brodowskicdb13802010-07-28 10:59:06 +0200457 local->amem = ioremap(link->resource[4]->start,
458 resource_size(link->resource[4]));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700459
Dominik Brodowski624dd662009-10-24 15:52:44 +0200460 dev_dbg(&link->dev, "ray_config sram=%p\n", local->sram);
461 dev_dbg(&link->dev, "ray_config rmem=%p\n", local->rmem);
462 dev_dbg(&link->dev, "ray_config amem=%p\n", local->amem);
John Daiker141fa612009-03-10 06:59:54 -0700463 if (ray_init(dev) < 0) {
464 ray_release(link);
465 return -ENODEV;
466 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700467
Dominik Brodowskidd2e5a12009-11-03 10:27:34 +0100468 SET_NETDEV_DEV(dev, &link->dev);
John Daiker141fa612009-03-10 06:59:54 -0700469 i = register_netdev(dev);
470 if (i != 0) {
471 printk("ray_config register_netdev() failed\n");
472 ray_release(link);
473 return i;
474 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700475
John Daiker141fa612009-03-10 06:59:54 -0700476 printk(KERN_INFO "%s: RayLink, irq %d, hw_addr %pM\n",
477 dev->name, dev->irq, dev->dev_addr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700478
John Daiker141fa612009-03-10 06:59:54 -0700479 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700480
Dominik Brodowski624dd662009-10-24 15:52:44 +0200481failed:
John Daiker141fa612009-03-10 06:59:54 -0700482 ray_release(link);
483 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700484} /* ray_config */
485
486static inline struct ccs __iomem *ccs_base(ray_dev_t *dev)
487{
488 return dev->sram + CCS_BASE;
489}
490
491static inline struct rcs __iomem *rcs_base(ray_dev_t *dev)
492{
493 /*
494 * This looks nonsensical, since there is a separate
495 * RCS_BASE. But the difference between a "struct rcs"
496 * and a "struct ccs" ends up being in the _index_ off
497 * the base, so the base pointer is the same for both
498 * ccs/rcs.
499 */
500 return dev->sram + CCS_BASE;
501}
502
503/*===========================================================================*/
504static int ray_init(struct net_device *dev)
505{
John Daiker141fa612009-03-10 06:59:54 -0700506 int i;
507 UCHAR *p;
508 struct ccs __iomem *pccs;
509 ray_dev_t *local = netdev_priv(dev);
510 struct pcmcia_device *link = local->finder;
Dominik Brodowski624dd662009-10-24 15:52:44 +0200511 dev_dbg(&link->dev, "ray_init(0x%p)\n", dev);
John Daiker141fa612009-03-10 06:59:54 -0700512 if (!(pcmcia_dev_present(link))) {
Dominik Brodowski624dd662009-10-24 15:52:44 +0200513 dev_dbg(&link->dev, "ray_init - device not present\n");
John Daiker141fa612009-03-10 06:59:54 -0700514 return -1;
515 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700516
John Daiker141fa612009-03-10 06:59:54 -0700517 local->net_type = net_type;
518 local->sta_type = TYPE_STA;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700519
John Daiker141fa612009-03-10 06:59:54 -0700520 /* Copy the startup results to local memory */
521 memcpy_fromio(&local->startup_res, local->sram + ECF_TO_HOST_BASE,
522 sizeof(struct startup_res_6));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700523
John Daiker141fa612009-03-10 06:59:54 -0700524 /* Check Power up test status and get mac address from card */
525 if (local->startup_res.startup_word != 0x80) {
526 printk(KERN_INFO "ray_init ERROR card status = %2x\n",
527 local->startup_res.startup_word);
528 local->card_status = CARD_INIT_ERROR;
529 return -1;
530 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700531
John Daiker141fa612009-03-10 06:59:54 -0700532 local->fw_ver = local->startup_res.firmware_version[0];
533 local->fw_bld = local->startup_res.firmware_version[1];
534 local->fw_var = local->startup_res.firmware_version[2];
Frans Popcb01b092010-03-24 19:46:34 +0100535 dev_dbg(&link->dev, "ray_init firmware version %d.%d\n", local->fw_ver,
John Daiker141fa612009-03-10 06:59:54 -0700536 local->fw_bld);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700537
John Daiker141fa612009-03-10 06:59:54 -0700538 local->tib_length = 0x20;
539 if ((local->fw_ver == 5) && (local->fw_bld >= 30))
540 local->tib_length = local->startup_res.tib_length;
Dominik Brodowski624dd662009-10-24 15:52:44 +0200541 dev_dbg(&link->dev, "ray_init tib_length = 0x%02x\n", local->tib_length);
John Daiker141fa612009-03-10 06:59:54 -0700542 /* Initialize CCS's to buffer free state */
543 pccs = ccs_base(local);
544 for (i = 0; i < NUMBER_OF_CCS; i++) {
545 writeb(CCS_BUFFER_FREE, &(pccs++)->buffer_status);
546 }
547 init_startup_params(local);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700548
John Daiker141fa612009-03-10 06:59:54 -0700549 /* copy mac address to startup parameters */
550 if (parse_addr(phy_addr, local->sparm.b4.a_mac_addr)) {
551 p = local->sparm.b4.a_mac_addr;
552 } else {
553 memcpy(&local->sparm.b4.a_mac_addr,
554 &local->startup_res.station_addr, ADDRLEN);
555 p = local->sparm.b4.a_mac_addr;
556 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700557
John Daiker141fa612009-03-10 06:59:54 -0700558 clear_interrupt(local); /* Clear any interrupt from the card */
559 local->card_status = CARD_AWAITING_PARAM;
Dominik Brodowski624dd662009-10-24 15:52:44 +0200560 dev_dbg(&link->dev, "ray_init ending\n");
John Daiker141fa612009-03-10 06:59:54 -0700561 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700562} /* ray_init */
John Daiker141fa612009-03-10 06:59:54 -0700563
Linus Torvalds1da177e2005-04-16 15:20:36 -0700564/*===========================================================================*/
565/* Download startup parameters to the card and command it to read them */
566static int dl_startup_params(struct net_device *dev)
567{
John Daiker141fa612009-03-10 06:59:54 -0700568 int ccsindex;
569 ray_dev_t *local = netdev_priv(dev);
570 struct ccs __iomem *pccs;
571 struct pcmcia_device *link = local->finder;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700572
Dominik Brodowski624dd662009-10-24 15:52:44 +0200573 dev_dbg(&link->dev, "dl_startup_params entered\n");
John Daiker141fa612009-03-10 06:59:54 -0700574 if (!(pcmcia_dev_present(link))) {
Dominik Brodowski624dd662009-10-24 15:52:44 +0200575 dev_dbg(&link->dev, "ray_cs dl_startup_params - device not present\n");
John Daiker141fa612009-03-10 06:59:54 -0700576 return -1;
577 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700578
John Daiker141fa612009-03-10 06:59:54 -0700579 /* Copy parameters to host to ECF area */
580 if (local->fw_ver == 0x55)
581 memcpy_toio(local->sram + HOST_TO_ECF_BASE, &local->sparm.b4,
582 sizeof(struct b4_startup_params));
583 else
584 memcpy_toio(local->sram + HOST_TO_ECF_BASE, &local->sparm.b5,
585 sizeof(struct b5_startup_params));
586
587 /* Fill in the CCS fields for the ECF */
588 if ((ccsindex = get_free_ccs(local)) < 0)
589 return -1;
590 local->dl_param_ccs = ccsindex;
591 pccs = ccs_base(local) + ccsindex;
592 writeb(CCS_DOWNLOAD_STARTUP_PARAMS, &pccs->cmd);
Dominik Brodowski624dd662009-10-24 15:52:44 +0200593 dev_dbg(&link->dev, "dl_startup_params start ccsindex = %d\n",
John Daiker141fa612009-03-10 06:59:54 -0700594 local->dl_param_ccs);
595 /* Interrupt the firmware to process the command */
596 if (interrupt_ecf(local, ccsindex)) {
597 printk(KERN_INFO "ray dl_startup_params failed - "
598 "ECF not ready for intr\n");
599 local->card_status = CARD_DL_PARAM_ERROR;
600 writeb(CCS_BUFFER_FREE, &(pccs++)->buffer_status);
601 return -2;
602 }
603 local->card_status = CARD_DL_PARAM;
604 /* Start kernel timer to wait for dl startup to complete. */
605 local->timer.expires = jiffies + HZ / 2;
606 local->timer.data = (long)local;
607 local->timer.function = &verify_dl_startup;
608 add_timer(&local->timer);
Dominik Brodowski624dd662009-10-24 15:52:44 +0200609 dev_dbg(&link->dev,
John Daiker141fa612009-03-10 06:59:54 -0700610 "ray_cs dl_startup_params started timer for verify_dl_startup\n");
611 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700612} /* dl_startup_params */
John Daiker141fa612009-03-10 06:59:54 -0700613
Linus Torvalds1da177e2005-04-16 15:20:36 -0700614/*===========================================================================*/
615static void init_startup_params(ray_dev_t *local)
616{
John Daiker141fa612009-03-10 06:59:54 -0700617 int i;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700618
John Daiker141fa612009-03-10 06:59:54 -0700619 if (country > JAPAN_TEST)
620 country = USA;
621 else if (country < USA)
622 country = USA;
623 /* structure for hop time and beacon period is defined here using
624 * New 802.11D6.1 format. Card firmware is still using old format
625 * until version 6.
626 * Before After
627 * a_hop_time ms byte a_hop_time ms byte
628 * a_hop_time 2s byte a_hop_time ls byte
629 * a_hop_time ls byte a_beacon_period ms byte
630 * a_beacon_period a_beacon_period ls byte
631 *
632 * a_hop_time = uS a_hop_time = KuS
633 * a_beacon_period = hops a_beacon_period = KuS
634 *//* 64ms = 010000 */
635 if (local->fw_ver == 0x55) {
636 memcpy((UCHAR *) &local->sparm.b4, b4_default_startup_parms,
637 sizeof(struct b4_startup_params));
638 /* Translate sane kus input values to old build 4/5 format */
639 /* i = hop time in uS truncated to 3 bytes */
640 i = (hop_dwell * 1024) & 0xffffff;
641 local->sparm.b4.a_hop_time[0] = (i >> 16) & 0xff;
642 local->sparm.b4.a_hop_time[1] = (i >> 8) & 0xff;
643 local->sparm.b4.a_beacon_period[0] = 0;
644 local->sparm.b4.a_beacon_period[1] =
645 ((beacon_period / hop_dwell) - 1) & 0xff;
646 local->sparm.b4.a_curr_country_code = country;
647 local->sparm.b4.a_hop_pattern_length =
648 hop_pattern_length[(int)country] - 1;
649 if (bc) {
650 local->sparm.b4.a_ack_timeout = 0x50;
651 local->sparm.b4.a_sifs = 0x3f;
652 }
653 } else { /* Version 5 uses real kus values */
654 memcpy((UCHAR *) &local->sparm.b5, b5_default_startup_parms,
655 sizeof(struct b5_startup_params));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700656
John Daiker141fa612009-03-10 06:59:54 -0700657 local->sparm.b5.a_hop_time[0] = (hop_dwell >> 8) & 0xff;
658 local->sparm.b5.a_hop_time[1] = hop_dwell & 0xff;
659 local->sparm.b5.a_beacon_period[0] =
660 (beacon_period >> 8) & 0xff;
661 local->sparm.b5.a_beacon_period[1] = beacon_period & 0xff;
662 if (psm)
663 local->sparm.b5.a_power_mgt_state = 1;
664 local->sparm.b5.a_curr_country_code = country;
665 local->sparm.b5.a_hop_pattern_length =
666 hop_pattern_length[(int)country];
667 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700668
John Daiker141fa612009-03-10 06:59:54 -0700669 local->sparm.b4.a_network_type = net_type & 0x01;
670 local->sparm.b4.a_acting_as_ap_status = TYPE_STA;
671
672 if (essid != NULL)
673 strncpy(local->sparm.b4.a_current_ess_id, essid, ESSID_SIZE);
674} /* init_startup_params */
675
Linus Torvalds1da177e2005-04-16 15:20:36 -0700676/*===========================================================================*/
677static void verify_dl_startup(u_long data)
678{
John Daiker141fa612009-03-10 06:59:54 -0700679 ray_dev_t *local = (ray_dev_t *) data;
680 struct ccs __iomem *pccs = ccs_base(local) + local->dl_param_ccs;
681 UCHAR status;
682 struct pcmcia_device *link = local->finder;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700683
John Daiker141fa612009-03-10 06:59:54 -0700684 if (!(pcmcia_dev_present(link))) {
Dominik Brodowski624dd662009-10-24 15:52:44 +0200685 dev_dbg(&link->dev, "ray_cs verify_dl_startup - device not present\n");
John Daiker141fa612009-03-10 06:59:54 -0700686 return;
687 }
Dominik Brodowski624dd662009-10-24 15:52:44 +0200688#if 0
689 {
John Daiker141fa612009-03-10 06:59:54 -0700690 int i;
691 printk(KERN_DEBUG
692 "verify_dl_startup parameters sent via ccs %d:\n",
693 local->dl_param_ccs);
694 for (i = 0; i < sizeof(struct b5_startup_params); i++) {
695 printk(" %2x",
696 (unsigned int)readb(local->sram +
697 HOST_TO_ECF_BASE + i));
698 }
699 printk("\n");
700 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700701#endif
702
John Daiker141fa612009-03-10 06:59:54 -0700703 status = readb(&pccs->buffer_status);
704 if (status != CCS_BUFFER_FREE) {
705 printk(KERN_INFO
706 "Download startup params failed. Status = %d\n",
707 status);
708 local->card_status = CARD_DL_PARAM_ERROR;
709 return;
710 }
711 if (local->sparm.b4.a_network_type == ADHOC)
712 start_net((u_long) local);
713 else
714 join_net((u_long) local);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700715} /* end verify_dl_startup */
John Daiker141fa612009-03-10 06:59:54 -0700716
Linus Torvalds1da177e2005-04-16 15:20:36 -0700717/*===========================================================================*/
718/* Command card to start a network */
719static void start_net(u_long data)
720{
John Daiker141fa612009-03-10 06:59:54 -0700721 ray_dev_t *local = (ray_dev_t *) data;
722 struct ccs __iomem *pccs;
723 int ccsindex;
724 struct pcmcia_device *link = local->finder;
725 if (!(pcmcia_dev_present(link))) {
Dominik Brodowski624dd662009-10-24 15:52:44 +0200726 dev_dbg(&link->dev, "ray_cs start_net - device not present\n");
John Daiker141fa612009-03-10 06:59:54 -0700727 return;
728 }
729 /* Fill in the CCS fields for the ECF */
730 if ((ccsindex = get_free_ccs(local)) < 0)
731 return;
732 pccs = ccs_base(local) + ccsindex;
733 writeb(CCS_START_NETWORK, &pccs->cmd);
734 writeb(0, &pccs->var.start_network.update_param);
735 /* Interrupt the firmware to process the command */
736 if (interrupt_ecf(local, ccsindex)) {
Dominik Brodowski624dd662009-10-24 15:52:44 +0200737 dev_dbg(&link->dev, "ray start net failed - card not ready for intr\n");
John Daiker141fa612009-03-10 06:59:54 -0700738 writeb(CCS_BUFFER_FREE, &(pccs++)->buffer_status);
739 return;
740 }
741 local->card_status = CARD_DOING_ACQ;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700742} /* end start_net */
John Daiker141fa612009-03-10 06:59:54 -0700743
Linus Torvalds1da177e2005-04-16 15:20:36 -0700744/*===========================================================================*/
745/* Command card to join a network */
746static void join_net(u_long data)
747{
John Daiker141fa612009-03-10 06:59:54 -0700748 ray_dev_t *local = (ray_dev_t *) data;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700749
John Daiker141fa612009-03-10 06:59:54 -0700750 struct ccs __iomem *pccs;
751 int ccsindex;
752 struct pcmcia_device *link = local->finder;
753
754 if (!(pcmcia_dev_present(link))) {
Dominik Brodowski624dd662009-10-24 15:52:44 +0200755 dev_dbg(&link->dev, "ray_cs join_net - device not present\n");
John Daiker141fa612009-03-10 06:59:54 -0700756 return;
757 }
758 /* Fill in the CCS fields for the ECF */
759 if ((ccsindex = get_free_ccs(local)) < 0)
760 return;
761 pccs = ccs_base(local) + ccsindex;
762 writeb(CCS_JOIN_NETWORK, &pccs->cmd);
763 writeb(0, &pccs->var.join_network.update_param);
764 writeb(0, &pccs->var.join_network.net_initiated);
765 /* Interrupt the firmware to process the command */
766 if (interrupt_ecf(local, ccsindex)) {
Dominik Brodowski624dd662009-10-24 15:52:44 +0200767 dev_dbg(&link->dev, "ray join net failed - card not ready for intr\n");
John Daiker141fa612009-03-10 06:59:54 -0700768 writeb(CCS_BUFFER_FREE, &(pccs++)->buffer_status);
769 return;
770 }
771 local->card_status = CARD_DOING_ACQ;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700772}
John Daiker141fa612009-03-10 06:59:54 -0700773
Linus Torvalds1da177e2005-04-16 15:20:36 -0700774/*============================================================================
775 After a card is removed, ray_release() will unregister the net
776 device, and release the PCMCIA configuration. If the device is
777 still open, this will be postponed until it is closed.
778=============================================================================*/
Dominik Brodowskifba395e2006-03-31 17:21:06 +0200779static void ray_release(struct pcmcia_device *link)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700780{
John Daiker141fa612009-03-10 06:59:54 -0700781 struct net_device *dev = link->priv;
782 ray_dev_t *local = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700783
Dominik Brodowski624dd662009-10-24 15:52:44 +0200784 dev_dbg(&link->dev, "ray_release\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700785
John Daiker141fa612009-03-10 06:59:54 -0700786 del_timer(&local->timer);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700787
John Daiker141fa612009-03-10 06:59:54 -0700788 iounmap(local->sram);
789 iounmap(local->rmem);
790 iounmap(local->amem);
John Daiker141fa612009-03-10 06:59:54 -0700791 pcmcia_disable_device(link);
792
Dominik Brodowski624dd662009-10-24 15:52:44 +0200793 dev_dbg(&link->dev, "ray_release ending\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700794}
795
Dominik Brodowskifba395e2006-03-31 17:21:06 +0200796static int ray_suspend(struct pcmcia_device *link)
Dominik Brodowski98e4c282005-11-14 21:21:18 +0100797{
Dominik Brodowski98e4c282005-11-14 21:21:18 +0100798 struct net_device *dev = link->priv;
799
Dominik Brodowskie2d40962006-03-02 00:09:29 +0100800 if (link->open)
Dominik Brodowski8661bb52006-03-02 00:02:33 +0100801 netif_device_detach(dev);
Dominik Brodowski98e4c282005-11-14 21:21:18 +0100802
803 return 0;
804}
805
Dominik Brodowskifba395e2006-03-31 17:21:06 +0200806static int ray_resume(struct pcmcia_device *link)
Dominik Brodowski98e4c282005-11-14 21:21:18 +0100807{
Dominik Brodowski98e4c282005-11-14 21:21:18 +0100808 struct net_device *dev = link->priv;
809
Dominik Brodowskie2d40962006-03-02 00:09:29 +0100810 if (link->open) {
Dominik Brodowski8661bb52006-03-02 00:02:33 +0100811 ray_reset(dev);
812 netif_device_attach(dev);
813 }
Dominik Brodowski98e4c282005-11-14 21:21:18 +0100814
815 return 0;
816}
817
Linus Torvalds1da177e2005-04-16 15:20:36 -0700818/*===========================================================================*/
Hannes Eder2ed5ba82008-12-26 00:12:59 -0800819static int ray_dev_init(struct net_device *dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700820{
821#ifdef RAY_IMMEDIATE_INIT
John Daiker141fa612009-03-10 06:59:54 -0700822 int i;
823#endif /* RAY_IMMEDIATE_INIT */
824 ray_dev_t *local = netdev_priv(dev);
825 struct pcmcia_device *link = local->finder;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700826
Dominik Brodowski624dd662009-10-24 15:52:44 +0200827 dev_dbg(&link->dev, "ray_dev_init(dev=%p)\n", dev);
John Daiker141fa612009-03-10 06:59:54 -0700828 if (!(pcmcia_dev_present(link))) {
Dominik Brodowski624dd662009-10-24 15:52:44 +0200829 dev_dbg(&link->dev, "ray_dev_init - device not present\n");
John Daiker141fa612009-03-10 06:59:54 -0700830 return -1;
831 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700832#ifdef RAY_IMMEDIATE_INIT
John Daiker141fa612009-03-10 06:59:54 -0700833 /* Download startup parameters */
834 if ((i = dl_startup_params(dev)) < 0) {
835 printk(KERN_INFO "ray_dev_init dl_startup_params failed - "
836 "returns 0x%x\n", i);
837 return -1;
838 }
839#else /* RAY_IMMEDIATE_INIT */
840 /* Postpone the card init so that we can still configure the card,
841 * for example using the Wireless Extensions. The init will happen
842 * in ray_open() - Jean II */
Dominik Brodowski624dd662009-10-24 15:52:44 +0200843 dev_dbg(&link->dev,
John Daiker141fa612009-03-10 06:59:54 -0700844 "ray_dev_init: postponing card init to ray_open() ; Status = %d\n",
845 local->card_status);
846#endif /* RAY_IMMEDIATE_INIT */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700847
John Daiker141fa612009-03-10 06:59:54 -0700848 /* copy mac and broadcast addresses to linux device */
Jiri Pirko3a6d54c2009-05-11 23:37:15 +0000849 memcpy(dev->dev_addr, &local->sparm.b4.a_mac_addr, ADDRLEN);
John Daiker141fa612009-03-10 06:59:54 -0700850 memset(dev->broadcast, 0xff, ETH_ALEN);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700851
Dominik Brodowski624dd662009-10-24 15:52:44 +0200852 dev_dbg(&link->dev, "ray_dev_init ending\n");
John Daiker141fa612009-03-10 06:59:54 -0700853 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700854}
John Daiker141fa612009-03-10 06:59:54 -0700855
Linus Torvalds1da177e2005-04-16 15:20:36 -0700856/*===========================================================================*/
857static int ray_dev_config(struct net_device *dev, struct ifmap *map)
858{
John Daiker141fa612009-03-10 06:59:54 -0700859 ray_dev_t *local = netdev_priv(dev);
860 struct pcmcia_device *link = local->finder;
861 /* Dummy routine to satisfy device structure */
Dominik Brodowski624dd662009-10-24 15:52:44 +0200862 dev_dbg(&link->dev, "ray_dev_config(dev=%p,ifmap=%p)\n", dev, map);
John Daiker141fa612009-03-10 06:59:54 -0700863 if (!(pcmcia_dev_present(link))) {
Dominik Brodowski624dd662009-10-24 15:52:44 +0200864 dev_dbg(&link->dev, "ray_dev_config - device not present\n");
John Daiker141fa612009-03-10 06:59:54 -0700865 return -1;
866 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700867
John Daiker141fa612009-03-10 06:59:54 -0700868 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700869}
John Daiker141fa612009-03-10 06:59:54 -0700870
Linus Torvalds1da177e2005-04-16 15:20:36 -0700871/*===========================================================================*/
Stephen Hemmingerd0cf9c02009-08-31 19:50:57 +0000872static netdev_tx_t ray_dev_start_xmit(struct sk_buff *skb,
873 struct net_device *dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700874{
John Daiker141fa612009-03-10 06:59:54 -0700875 ray_dev_t *local = netdev_priv(dev);
876 struct pcmcia_device *link = local->finder;
877 short length = skb->len;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700878
Stephen Hemmingerd0cf9c02009-08-31 19:50:57 +0000879 if (!pcmcia_dev_present(link)) {
Dominik Brodowski624dd662009-10-24 15:52:44 +0200880 dev_dbg(&link->dev, "ray_dev_start_xmit - device not present\n");
Stephen Hemmingerd0cf9c02009-08-31 19:50:57 +0000881 dev_kfree_skb(skb);
882 return NETDEV_TX_OK;
John Daiker141fa612009-03-10 06:59:54 -0700883 }
Stephen Hemmingerd0cf9c02009-08-31 19:50:57 +0000884
Dominik Brodowski624dd662009-10-24 15:52:44 +0200885 dev_dbg(&link->dev, "ray_dev_start_xmit(skb=%p, dev=%p)\n", skb, dev);
John Daiker141fa612009-03-10 06:59:54 -0700886 if (local->authentication_state == NEED_TO_AUTH) {
Dominik Brodowski624dd662009-10-24 15:52:44 +0200887 dev_dbg(&link->dev, "ray_cs Sending authentication request.\n");
John Daiker141fa612009-03-10 06:59:54 -0700888 if (!build_auth_frame(local, local->auth_id, OPEN_AUTH_REQUEST)) {
889 local->authentication_state = AUTHENTICATED;
890 netif_stop_queue(dev);
Patrick McHardy5b548142009-06-12 06:22:29 +0000891 return NETDEV_TX_BUSY;
John Daiker141fa612009-03-10 06:59:54 -0700892 }
893 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700894
John Daiker141fa612009-03-10 06:59:54 -0700895 if (length < ETH_ZLEN) {
896 if (skb_padto(skb, ETH_ZLEN))
Patrick McHardy6ed10652009-06-23 06:03:08 +0000897 return NETDEV_TX_OK;
John Daiker141fa612009-03-10 06:59:54 -0700898 length = ETH_ZLEN;
899 }
900 switch (ray_hw_xmit(skb->data, length, dev, DATA_TYPE)) {
901 case XMIT_NO_CCS:
902 case XMIT_NEED_AUTH:
903 netif_stop_queue(dev);
Patrick McHardy5b548142009-06-12 06:22:29 +0000904 return NETDEV_TX_BUSY;
John Daiker141fa612009-03-10 06:59:54 -0700905 case XMIT_NO_INTR:
906 case XMIT_MSG_BAD:
907 case XMIT_OK:
908 default:
John Daiker141fa612009-03-10 06:59:54 -0700909 dev_kfree_skb(skb);
John Daiker141fa612009-03-10 06:59:54 -0700910 }
Stephen Hemmingerd0cf9c02009-08-31 19:50:57 +0000911
Patrick McHardy6ed10652009-06-23 06:03:08 +0000912 return NETDEV_TX_OK;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700913} /* ray_dev_start_xmit */
John Daiker141fa612009-03-10 06:59:54 -0700914
Linus Torvalds1da177e2005-04-16 15:20:36 -0700915/*===========================================================================*/
John Daiker141fa612009-03-10 06:59:54 -0700916static int ray_hw_xmit(unsigned char *data, int len, struct net_device *dev,
917 UCHAR msg_type)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700918{
John Daiker141fa612009-03-10 06:59:54 -0700919 ray_dev_t *local = netdev_priv(dev);
920 struct ccs __iomem *pccs;
921 int ccsindex;
922 int offset;
923 struct tx_msg __iomem *ptx; /* Address of xmit buffer in PC space */
924 short int addr; /* Address of xmit buffer in card space */
925
Dominik Brodowski624dd662009-10-24 15:52:44 +0200926 pr_debug("ray_hw_xmit(data=%p, len=%d, dev=%p)\n", data, len, dev);
John Daiker141fa612009-03-10 06:59:54 -0700927 if (len + TX_HEADER_LENGTH > TX_BUF_SIZE) {
928 printk(KERN_INFO "ray_hw_xmit packet too large: %d bytes\n",
929 len);
930 return XMIT_MSG_BAD;
931 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700932 switch (ccsindex = get_free_tx_ccs(local)) {
933 case ECCSBUSY:
Dominik Brodowski624dd662009-10-24 15:52:44 +0200934 pr_debug("ray_hw_xmit tx_ccs table busy\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700935 case ECCSFULL:
Dominik Brodowski624dd662009-10-24 15:52:44 +0200936 pr_debug("ray_hw_xmit No free tx ccs\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700937 case ECARDGONE:
John Daiker141fa612009-03-10 06:59:54 -0700938 netif_stop_queue(dev);
939 return XMIT_NO_CCS;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700940 default:
941 break;
942 }
John Daiker141fa612009-03-10 06:59:54 -0700943 addr = TX_BUF_BASE + (ccsindex << 11);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700944
John Daiker141fa612009-03-10 06:59:54 -0700945 if (msg_type == DATA_TYPE) {
946 local->stats.tx_bytes += len;
947 local->stats.tx_packets++;
948 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700949
John Daiker141fa612009-03-10 06:59:54 -0700950 ptx = local->sram + addr;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700951
John Daiker141fa612009-03-10 06:59:54 -0700952 ray_build_header(local, ptx, msg_type, data);
953 if (translate) {
954 offset = translate_frame(local, ptx, data, len);
955 } else { /* Encapsulate frame */
956 /* TBD TIB length will move address of ptx->var */
957 memcpy_toio(&ptx->var, data, len);
958 offset = 0;
959 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700960
John Daiker141fa612009-03-10 06:59:54 -0700961 /* fill in the CCS */
962 pccs = ccs_base(local) + ccsindex;
963 len += TX_HEADER_LENGTH + offset;
964 writeb(CCS_TX_REQUEST, &pccs->cmd);
965 writeb(addr >> 8, &pccs->var.tx_request.tx_data_ptr[0]);
966 writeb(local->tib_length, &pccs->var.tx_request.tx_data_ptr[1]);
967 writeb(len >> 8, &pccs->var.tx_request.tx_data_length[0]);
968 writeb(len & 0xff, &pccs->var.tx_request.tx_data_length[1]);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700969/* TBD still need psm_cam? */
John Daiker141fa612009-03-10 06:59:54 -0700970 writeb(PSM_CAM, &pccs->var.tx_request.pow_sav_mode);
971 writeb(local->net_default_tx_rate, &pccs->var.tx_request.tx_rate);
972 writeb(0, &pccs->var.tx_request.antenna);
Dominik Brodowski624dd662009-10-24 15:52:44 +0200973 pr_debug("ray_hw_xmit default_tx_rate = 0x%x\n",
John Daiker141fa612009-03-10 06:59:54 -0700974 local->net_default_tx_rate);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700975
John Daiker141fa612009-03-10 06:59:54 -0700976 /* Interrupt the firmware to process the command */
977 if (interrupt_ecf(local, ccsindex)) {
Dominik Brodowski624dd662009-10-24 15:52:44 +0200978 pr_debug("ray_hw_xmit failed - ECF not ready for intr\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700979/* TBD very inefficient to copy packet to buffer, and then not
980 send it, but the alternative is to queue the messages and that
981 won't be done for a while. Maybe set tbusy until a CCS is free?
982*/
John Daiker141fa612009-03-10 06:59:54 -0700983 writeb(CCS_BUFFER_FREE, &pccs->buffer_status);
984 return XMIT_NO_INTR;
985 }
986 return XMIT_OK;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700987} /* end ray_hw_xmit */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700988
John Daiker141fa612009-03-10 06:59:54 -0700989/*===========================================================================*/
990static int translate_frame(ray_dev_t *local, struct tx_msg __iomem *ptx,
991 unsigned char *data, int len)
992{
993 __be16 proto = ((struct ethhdr *)data)->h_proto;
994 if (ntohs(proto) >= 1536) { /* DIX II ethernet frame */
Dominik Brodowski624dd662009-10-24 15:52:44 +0200995 pr_debug("ray_cs translate_frame DIX II\n");
John Daiker141fa612009-03-10 06:59:54 -0700996 /* Copy LLC header to card buffer */
997 memcpy_toio(&ptx->var, eth2_llc, sizeof(eth2_llc));
998 memcpy_toio(((void __iomem *)&ptx->var) + sizeof(eth2_llc),
999 (UCHAR *) &proto, 2);
1000 if (proto == htons(ETH_P_AARP) || proto == htons(ETH_P_IPX)) {
1001 /* This is the selective translation table, only 2 entries */
1002 writeb(0xf8,
1003 &((struct snaphdr_t __iomem *)ptx->var)->org[3]);
1004 }
1005 /* Copy body of ethernet packet without ethernet header */
1006 memcpy_toio((void __iomem *)&ptx->var +
1007 sizeof(struct snaphdr_t), data + ETH_HLEN,
1008 len - ETH_HLEN);
1009 return (int)sizeof(struct snaphdr_t) - ETH_HLEN;
1010 } else { /* already 802 type, and proto is length */
Dominik Brodowski624dd662009-10-24 15:52:44 +02001011 pr_debug("ray_cs translate_frame 802\n");
John Daiker141fa612009-03-10 06:59:54 -07001012 if (proto == htons(0xffff)) { /* evil netware IPX 802.3 without LLC */
Dominik Brodowski624dd662009-10-24 15:52:44 +02001013 pr_debug("ray_cs translate_frame evil IPX\n");
John Daiker141fa612009-03-10 06:59:54 -07001014 memcpy_toio(&ptx->var, data + ETH_HLEN, len - ETH_HLEN);
1015 return 0 - ETH_HLEN;
1016 }
1017 memcpy_toio(&ptx->var, data + ETH_HLEN, len - ETH_HLEN);
1018 return 0 - ETH_HLEN;
1019 }
1020 /* TBD do other frame types */
1021} /* end translate_frame */
1022
1023/*===========================================================================*/
1024static void ray_build_header(ray_dev_t *local, struct tx_msg __iomem *ptx,
1025 UCHAR msg_type, unsigned char *data)
1026{
1027 writeb(PROTOCOL_VER | msg_type, &ptx->mac.frame_ctl_1);
1028/*** IEEE 802.11 Address field assignments *************
1029 TODS FROMDS addr_1 addr_2 addr_3 addr_4
1030Adhoc 0 0 dest src (terminal) BSSID N/A
1031AP to Terminal 0 1 dest AP(BSSID) source N/A
1032Terminal to AP 1 0 AP(BSSID) src (terminal) dest N/A
1033AP to AP 1 1 dest AP src AP dest source
1034*******************************************************/
1035 if (local->net_type == ADHOC) {
1036 writeb(0, &ptx->mac.frame_ctl_2);
1037 memcpy_toio(ptx->mac.addr_1, ((struct ethhdr *)data)->h_dest,
1038 2 * ADDRLEN);
1039 memcpy_toio(ptx->mac.addr_3, local->bss_id, ADDRLEN);
1040 } else { /* infrastructure */
1041
1042 if (local->sparm.b4.a_acting_as_ap_status) {
1043 writeb(FC2_FROM_DS, &ptx->mac.frame_ctl_2);
1044 memcpy_toio(ptx->mac.addr_1,
1045 ((struct ethhdr *)data)->h_dest, ADDRLEN);
1046 memcpy_toio(ptx->mac.addr_2, local->bss_id, 6);
1047 memcpy_toio(ptx->mac.addr_3,
1048 ((struct ethhdr *)data)->h_source, ADDRLEN);
1049 } else { /* Terminal */
1050
1051 writeb(FC2_TO_DS, &ptx->mac.frame_ctl_2);
1052 memcpy_toio(ptx->mac.addr_1, local->bss_id, ADDRLEN);
1053 memcpy_toio(ptx->mac.addr_2,
1054 ((struct ethhdr *)data)->h_source, ADDRLEN);
1055 memcpy_toio(ptx->mac.addr_3,
1056 ((struct ethhdr *)data)->h_dest, ADDRLEN);
1057 }
1058 }
1059} /* end encapsulate_frame */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001060
1061/*===========================================================================*/
1062
1063static void netdev_get_drvinfo(struct net_device *dev,
1064 struct ethtool_drvinfo *info)
1065{
1066 strcpy(info->driver, "ray_cs");
1067}
1068
Jeff Garzik7282d492006-09-13 14:30:00 -04001069static const struct ethtool_ops netdev_ethtool_ops = {
John Daiker141fa612009-03-10 06:59:54 -07001070 .get_drvinfo = netdev_get_drvinfo,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001071};
1072
1073/*====================================================================*/
1074
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001075/*------------------------------------------------------------------*/
1076/*
1077 * Wireless Handler : get protocol name
1078 */
Joe Perches43ead782010-03-18 18:29:40 -07001079static int ray_get_name(struct net_device *dev, struct iw_request_info *info,
1080 union iwreq_data *wrqu, char *extra)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001081{
Joe Perches43ead782010-03-18 18:29:40 -07001082 strcpy(wrqu->name, "IEEE 802.11-FH");
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001083 return 0;
1084}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001085
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001086/*------------------------------------------------------------------*/
1087/*
1088 * Wireless Handler : set frequency
1089 */
Joe Perches43ead782010-03-18 18:29:40 -07001090static int ray_set_freq(struct net_device *dev, struct iw_request_info *info,
1091 union iwreq_data *wrqu, char *extra)
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001092{
Yoann Padioleau6dbc9c82007-08-03 19:37:16 +02001093 ray_dev_t *local = netdev_priv(dev);
John Daiker141fa612009-03-10 06:59:54 -07001094 int err = -EINPROGRESS; /* Call commit handler */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001095
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001096 /* Reject if card is already initialised */
John Daiker141fa612009-03-10 06:59:54 -07001097 if (local->card_status != CARD_AWAITING_PARAM)
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001098 return -EBUSY;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001099
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001100 /* Setting by channel number */
Joe Perches43ead782010-03-18 18:29:40 -07001101 if ((wrqu->freq.m > USA_HOP_MOD) || (wrqu->freq.e > 0))
Linus Torvalds1da177e2005-04-16 15:20:36 -07001102 err = -EOPNOTSUPP;
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001103 else
Joe Perches43ead782010-03-18 18:29:40 -07001104 local->sparm.b5.a_hop_pattern = wrqu->freq.m;
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001105
1106 return err;
1107}
John Daiker141fa612009-03-10 06:59:54 -07001108
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001109/*------------------------------------------------------------------*/
1110/*
1111 * Wireless Handler : get frequency
1112 */
Joe Perches43ead782010-03-18 18:29:40 -07001113static int ray_get_freq(struct net_device *dev, struct iw_request_info *info,
1114 union iwreq_data *wrqu, char *extra)
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001115{
Yoann Padioleau6dbc9c82007-08-03 19:37:16 +02001116 ray_dev_t *local = netdev_priv(dev);
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001117
Joe Perches43ead782010-03-18 18:29:40 -07001118 wrqu->freq.m = local->sparm.b5.a_hop_pattern;
1119 wrqu->freq.e = 0;
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001120 return 0;
1121}
1122
1123/*------------------------------------------------------------------*/
1124/*
1125 * Wireless Handler : set ESSID
1126 */
Joe Perches43ead782010-03-18 18:29:40 -07001127static int ray_set_essid(struct net_device *dev, struct iw_request_info *info,
1128 union iwreq_data *wrqu, char *extra)
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001129{
Yoann Padioleau6dbc9c82007-08-03 19:37:16 +02001130 ray_dev_t *local = netdev_priv(dev);
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001131
1132 /* Reject if card is already initialised */
John Daiker141fa612009-03-10 06:59:54 -07001133 if (local->card_status != CARD_AWAITING_PARAM)
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001134 return -EBUSY;
1135
1136 /* Check if we asked for `any' */
Joe Perches43ead782010-03-18 18:29:40 -07001137 if (wrqu->essid.flags == 0)
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001138 /* Corey : can you do that ? */
1139 return -EOPNOTSUPP;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001140
Joe Perches43ead782010-03-18 18:29:40 -07001141 /* Check the size of the string */
1142 if (wrqu->essid.length > IW_ESSID_MAX_SIZE)
1143 return -E2BIG;
1144
1145 /* Set the ESSID in the card */
1146 memset(local->sparm.b5.a_current_ess_id, 0, IW_ESSID_MAX_SIZE);
1147 memcpy(local->sparm.b5.a_current_ess_id, extra, wrqu->essid.length);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001148
John Daiker141fa612009-03-10 06:59:54 -07001149 return -EINPROGRESS; /* Call commit handler */
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001150}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001151
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001152/*------------------------------------------------------------------*/
1153/*
1154 * Wireless Handler : get ESSID
1155 */
Joe Perches43ead782010-03-18 18:29:40 -07001156static int ray_get_essid(struct net_device *dev, struct iw_request_info *info,
1157 union iwreq_data *wrqu, char *extra)
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001158{
Yoann Padioleau6dbc9c82007-08-03 19:37:16 +02001159 ray_dev_t *local = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001160
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001161 /* Get the essid that was set */
1162 memcpy(extra, local->sparm.b5.a_current_ess_id, IW_ESSID_MAX_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001163
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001164 /* Push it out ! */
Joe Perches43ead782010-03-18 18:29:40 -07001165 wrqu->essid.length = strlen(extra);
1166 wrqu->essid.flags = 1; /* active */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001167
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001168 return 0;
1169}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001170
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001171/*------------------------------------------------------------------*/
1172/*
1173 * Wireless Handler : get AP address
1174 */
Joe Perches43ead782010-03-18 18:29:40 -07001175static int ray_get_wap(struct net_device *dev, struct iw_request_info *info,
1176 union iwreq_data *wrqu, char *extra)
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001177{
Yoann Padioleau6dbc9c82007-08-03 19:37:16 +02001178 ray_dev_t *local = netdev_priv(dev);
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001179
Joe Perches43ead782010-03-18 18:29:40 -07001180 memcpy(wrqu->ap_addr.sa_data, local->bss_id, ETH_ALEN);
1181 wrqu->ap_addr.sa_family = ARPHRD_ETHER;
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001182
1183 return 0;
1184}
1185
1186/*------------------------------------------------------------------*/
1187/*
1188 * Wireless Handler : set Bit-Rate
1189 */
Joe Perches43ead782010-03-18 18:29:40 -07001190static int ray_set_rate(struct net_device *dev, struct iw_request_info *info,
1191 union iwreq_data *wrqu, char *extra)
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001192{
Yoann Padioleau6dbc9c82007-08-03 19:37:16 +02001193 ray_dev_t *local = netdev_priv(dev);
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001194
1195 /* Reject if card is already initialised */
John Daiker141fa612009-03-10 06:59:54 -07001196 if (local->card_status != CARD_AWAITING_PARAM)
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001197 return -EBUSY;
1198
1199 /* Check if rate is in range */
Joe Perches43ead782010-03-18 18:29:40 -07001200 if ((wrqu->bitrate.value != 1000000) && (wrqu->bitrate.value != 2000000))
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001201 return -EINVAL;
1202
1203 /* Hack for 1.5 Mb/s instead of 2 Mb/s */
John Daiker141fa612009-03-10 06:59:54 -07001204 if ((local->fw_ver == 0x55) && /* Please check */
Joe Perches43ead782010-03-18 18:29:40 -07001205 (wrqu->bitrate.value == 2000000))
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001206 local->net_default_tx_rate = 3;
1207 else
Joe Perches43ead782010-03-18 18:29:40 -07001208 local->net_default_tx_rate = wrqu->bitrate.value / 500000;
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001209
1210 return 0;
1211}
1212
1213/*------------------------------------------------------------------*/
1214/*
1215 * Wireless Handler : get Bit-Rate
1216 */
Joe Perches43ead782010-03-18 18:29:40 -07001217static int ray_get_rate(struct net_device *dev, struct iw_request_info *info,
1218 union iwreq_data *wrqu, char *extra)
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001219{
Yoann Padioleau6dbc9c82007-08-03 19:37:16 +02001220 ray_dev_t *local = netdev_priv(dev);
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001221
John Daiker141fa612009-03-10 06:59:54 -07001222 if (local->net_default_tx_rate == 3)
Joe Perches43ead782010-03-18 18:29:40 -07001223 wrqu->bitrate.value = 2000000; /* Hum... */
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001224 else
Joe Perches43ead782010-03-18 18:29:40 -07001225 wrqu->bitrate.value = local->net_default_tx_rate * 500000;
1226 wrqu->bitrate.fixed = 0; /* We are in auto mode */
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001227
1228 return 0;
1229}
1230
1231/*------------------------------------------------------------------*/
1232/*
1233 * Wireless Handler : set RTS threshold
1234 */
Joe Perches43ead782010-03-18 18:29:40 -07001235static int ray_set_rts(struct net_device *dev, struct iw_request_info *info,
1236 union iwreq_data *wrqu, char *extra)
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001237{
Yoann Padioleau6dbc9c82007-08-03 19:37:16 +02001238 ray_dev_t *local = netdev_priv(dev);
Joe Perches43ead782010-03-18 18:29:40 -07001239 int rthr = wrqu->rts.value;
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001240
1241 /* Reject if card is already initialised */
John Daiker141fa612009-03-10 06:59:54 -07001242 if (local->card_status != CARD_AWAITING_PARAM)
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001243 return -EBUSY;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001244
1245 /* if(wrq->u.rts.fixed == 0) we should complain */
Joe Perches43ead782010-03-18 18:29:40 -07001246 if (wrqu->rts.disabled)
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001247 rthr = 32767;
1248 else {
John Daiker141fa612009-03-10 06:59:54 -07001249 if ((rthr < 0) || (rthr > 2347)) /* What's the max packet size ??? */
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001250 return -EINVAL;
1251 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001252 local->sparm.b5.a_rts_threshold[0] = (rthr >> 8) & 0xFF;
1253 local->sparm.b5.a_rts_threshold[1] = rthr & 0xFF;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001254
John Daiker141fa612009-03-10 06:59:54 -07001255 return -EINPROGRESS; /* Call commit handler */
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001256}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001257
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001258/*------------------------------------------------------------------*/
1259/*
1260 * Wireless Handler : get RTS threshold
1261 */
Joe Perches43ead782010-03-18 18:29:40 -07001262static int ray_get_rts(struct net_device *dev, struct iw_request_info *info,
1263 union iwreq_data *wrqu, char *extra)
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001264{
Yoann Padioleau6dbc9c82007-08-03 19:37:16 +02001265 ray_dev_t *local = netdev_priv(dev);
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001266
Joe Perches43ead782010-03-18 18:29:40 -07001267 wrqu->rts.value = (local->sparm.b5.a_rts_threshold[0] << 8)
John Daiker141fa612009-03-10 06:59:54 -07001268 + local->sparm.b5.a_rts_threshold[1];
Joe Perches43ead782010-03-18 18:29:40 -07001269 wrqu->rts.disabled = (wrqu->rts.value == 32767);
1270 wrqu->rts.fixed = 1;
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001271
1272 return 0;
1273}
1274
1275/*------------------------------------------------------------------*/
1276/*
1277 * Wireless Handler : set Fragmentation threshold
1278 */
Joe Perches43ead782010-03-18 18:29:40 -07001279static int ray_set_frag(struct net_device *dev, struct iw_request_info *info,
1280 union iwreq_data *wrqu, char *extra)
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001281{
Yoann Padioleau6dbc9c82007-08-03 19:37:16 +02001282 ray_dev_t *local = netdev_priv(dev);
Joe Perches43ead782010-03-18 18:29:40 -07001283 int fthr = wrqu->frag.value;
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001284
1285 /* Reject if card is already initialised */
John Daiker141fa612009-03-10 06:59:54 -07001286 if (local->card_status != CARD_AWAITING_PARAM)
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001287 return -EBUSY;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001288
1289 /* if(wrq->u.frag.fixed == 0) should complain */
Joe Perches43ead782010-03-18 18:29:40 -07001290 if (wrqu->frag.disabled)
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001291 fthr = 32767;
1292 else {
John Daiker141fa612009-03-10 06:59:54 -07001293 if ((fthr < 256) || (fthr > 2347)) /* To check out ! */
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001294 return -EINVAL;
1295 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001296 local->sparm.b5.a_frag_threshold[0] = (fthr >> 8) & 0xFF;
1297 local->sparm.b5.a_frag_threshold[1] = fthr & 0xFF;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001298
John Daiker141fa612009-03-10 06:59:54 -07001299 return -EINPROGRESS; /* Call commit handler */
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001300}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001301
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001302/*------------------------------------------------------------------*/
1303/*
1304 * Wireless Handler : get Fragmentation threshold
1305 */
Joe Perches43ead782010-03-18 18:29:40 -07001306static int ray_get_frag(struct net_device *dev, struct iw_request_info *info,
1307 union iwreq_data *wrqu, char *extra)
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001308{
Yoann Padioleau6dbc9c82007-08-03 19:37:16 +02001309 ray_dev_t *local = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001310
Joe Perches43ead782010-03-18 18:29:40 -07001311 wrqu->frag.value = (local->sparm.b5.a_frag_threshold[0] << 8)
John Daiker141fa612009-03-10 06:59:54 -07001312 + local->sparm.b5.a_frag_threshold[1];
Joe Perches43ead782010-03-18 18:29:40 -07001313 wrqu->frag.disabled = (wrqu->frag.value == 32767);
1314 wrqu->frag.fixed = 1;
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001315
1316 return 0;
1317}
1318
1319/*------------------------------------------------------------------*/
1320/*
1321 * Wireless Handler : set Mode of Operation
1322 */
Joe Perches43ead782010-03-18 18:29:40 -07001323static int ray_set_mode(struct net_device *dev, struct iw_request_info *info,
1324 union iwreq_data *wrqu, char *extra)
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001325{
Yoann Padioleau6dbc9c82007-08-03 19:37:16 +02001326 ray_dev_t *local = netdev_priv(dev);
John Daiker141fa612009-03-10 06:59:54 -07001327 int err = -EINPROGRESS; /* Call commit handler */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001328 char card_mode = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001329
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001330 /* Reject if card is already initialised */
John Daiker141fa612009-03-10 06:59:54 -07001331 if (local->card_status != CARD_AWAITING_PARAM)
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001332 return -EBUSY;
1333
Joe Perches43ead782010-03-18 18:29:40 -07001334 switch (wrqu->mode) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001335 case IW_MODE_ADHOC:
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001336 card_mode = 0;
John Daiker141fa612009-03-10 06:59:54 -07001337 /* Fall through */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001338 case IW_MODE_INFRA:
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001339 local->sparm.b5.a_network_type = card_mode;
1340 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001341 default:
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001342 err = -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001343 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001344
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001345 return err;
1346}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001347
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001348/*------------------------------------------------------------------*/
1349/*
1350 * Wireless Handler : get Mode of Operation
1351 */
Joe Perches43ead782010-03-18 18:29:40 -07001352static int ray_get_mode(struct net_device *dev, struct iw_request_info *info,
1353 union iwreq_data *wrqu, char *extra)
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001354{
Yoann Padioleau6dbc9c82007-08-03 19:37:16 +02001355 ray_dev_t *local = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001356
John Daiker141fa612009-03-10 06:59:54 -07001357 if (local->sparm.b5.a_network_type)
Joe Perches43ead782010-03-18 18:29:40 -07001358 wrqu->mode = IW_MODE_INFRA;
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001359 else
Joe Perches43ead782010-03-18 18:29:40 -07001360 wrqu->mode = IW_MODE_ADHOC;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001361
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001362 return 0;
1363}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001364
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001365/*------------------------------------------------------------------*/
1366/*
1367 * Wireless Handler : get range info
1368 */
Joe Perches43ead782010-03-18 18:29:40 -07001369static int ray_get_range(struct net_device *dev, struct iw_request_info *info,
1370 union iwreq_data *wrqu, char *extra)
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001371{
John Daiker141fa612009-03-10 06:59:54 -07001372 struct iw_range *range = (struct iw_range *)extra;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001373
Joe Perches43ead782010-03-18 18:29:40 -07001374 memset(range, 0, sizeof(struct iw_range));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001375
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001376 /* Set the length (very important for backward compatibility) */
Joe Perches43ead782010-03-18 18:29:40 -07001377 wrqu->data.length = sizeof(struct iw_range);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001378
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001379 /* Set the Wireless Extension versions */
1380 range->we_version_compiled = WIRELESS_EXT;
1381 range->we_version_source = 9;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001382
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001383 /* Set information in the range struct */
1384 range->throughput = 1.1 * 1000 * 1000; /* Put the right number here */
John Daiker141fa612009-03-10 06:59:54 -07001385 range->num_channels = hop_pattern_length[(int)country];
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001386 range->num_frequency = 0;
1387 range->max_qual.qual = 0;
1388 range->max_qual.level = 255; /* What's the correct value ? */
1389 range->max_qual.noise = 255; /* Idem */
1390 range->num_bitrates = 2;
1391 range->bitrate[0] = 1000000; /* 1 Mb/s */
1392 range->bitrate[1] = 2000000; /* 2 Mb/s */
1393 return 0;
1394}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001395
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001396/*------------------------------------------------------------------*/
1397/*
1398 * Wireless Private Handler : set framing mode
1399 */
Joe Perches43ead782010-03-18 18:29:40 -07001400static int ray_set_framing(struct net_device *dev, struct iw_request_info *info,
John Daiker141fa612009-03-10 06:59:54 -07001401 union iwreq_data *wrqu, char *extra)
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001402{
1403 translate = *(extra); /* Set framing mode */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001404
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001405 return 0;
1406}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001407
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001408/*------------------------------------------------------------------*/
1409/*
1410 * Wireless Private Handler : get framing mode
1411 */
Joe Perches43ead782010-03-18 18:29:40 -07001412static int ray_get_framing(struct net_device *dev, struct iw_request_info *info,
John Daiker141fa612009-03-10 06:59:54 -07001413 union iwreq_data *wrqu, char *extra)
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001414{
1415 *(extra) = translate;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001416
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001417 return 0;
1418}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001419
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001420/*------------------------------------------------------------------*/
1421/*
1422 * Wireless Private Handler : get country
1423 */
Joe Perches43ead782010-03-18 18:29:40 -07001424static int ray_get_country(struct net_device *dev, struct iw_request_info *info,
John Daiker141fa612009-03-10 06:59:54 -07001425 union iwreq_data *wrqu, char *extra)
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001426{
1427 *(extra) = country;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001428
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001429 return 0;
1430}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001431
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001432/*------------------------------------------------------------------*/
1433/*
1434 * Commit handler : called after a bunch of SET operations
1435 */
Joe Perches43ead782010-03-18 18:29:40 -07001436static int ray_commit(struct net_device *dev, struct iw_request_info *info,
1437 union iwreq_data *wrqu, char *extra)
1438{
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001439 return 0;
1440}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001441
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001442/*------------------------------------------------------------------*/
1443/*
1444 * Stats handler : return Wireless Stats
1445 */
John Daiker141fa612009-03-10 06:59:54 -07001446static iw_stats *ray_get_wireless_stats(struct net_device *dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001447{
John Daiker141fa612009-03-10 06:59:54 -07001448 ray_dev_t *local = netdev_priv(dev);
1449 struct pcmcia_device *link = local->finder;
1450 struct status __iomem *p = local->sram + STATUS_BASE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001451
John Daiker141fa612009-03-10 06:59:54 -07001452 local->wstats.status = local->card_status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001453#ifdef WIRELESS_SPY
John Daiker141fa612009-03-10 06:59:54 -07001454 if ((local->spy_data.spy_number > 0)
1455 && (local->sparm.b5.a_network_type == 0)) {
1456 /* Get it from the first node in spy list */
1457 local->wstats.qual.qual = local->spy_data.spy_stat[0].qual;
1458 local->wstats.qual.level = local->spy_data.spy_stat[0].level;
1459 local->wstats.qual.noise = local->spy_data.spy_stat[0].noise;
1460 local->wstats.qual.updated =
1461 local->spy_data.spy_stat[0].updated;
1462 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001463#endif /* WIRELESS_SPY */
1464
John Daiker141fa612009-03-10 06:59:54 -07001465 if (pcmcia_dev_present(link)) {
1466 local->wstats.qual.noise = readb(&p->rxnoise);
1467 local->wstats.qual.updated |= 4;
1468 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001469
John Daiker141fa612009-03-10 06:59:54 -07001470 return &local->wstats;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001471} /* end ray_get_wireless_stats */
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001472
1473/*------------------------------------------------------------------*/
1474/*
1475 * Structures to export the Wireless Handlers
1476 */
1477
John Daiker141fa612009-03-10 06:59:54 -07001478static const iw_handler ray_handler[] = {
Joe Perches43ead782010-03-18 18:29:40 -07001479 IW_HANDLER(SIOCSIWCOMMIT, ray_commit),
1480 IW_HANDLER(SIOCGIWNAME, ray_get_name),
1481 IW_HANDLER(SIOCSIWFREQ, ray_set_freq),
1482 IW_HANDLER(SIOCGIWFREQ, ray_get_freq),
1483 IW_HANDLER(SIOCSIWMODE, ray_set_mode),
1484 IW_HANDLER(SIOCGIWMODE, ray_get_mode),
1485 IW_HANDLER(SIOCGIWRANGE, ray_get_range),
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001486#ifdef WIRELESS_SPY
Joe Perches270020e2010-03-18 18:29:37 -07001487 IW_HANDLER(SIOCSIWSPY, iw_handler_set_spy),
1488 IW_HANDLER(SIOCGIWSPY, iw_handler_get_spy),
1489 IW_HANDLER(SIOCSIWTHRSPY, iw_handler_set_thrspy),
1490 IW_HANDLER(SIOCGIWTHRSPY, iw_handler_get_thrspy),
John Daiker141fa612009-03-10 06:59:54 -07001491#endif /* WIRELESS_SPY */
Joe Perches43ead782010-03-18 18:29:40 -07001492 IW_HANDLER(SIOCGIWAP, ray_get_wap),
1493 IW_HANDLER(SIOCSIWESSID, ray_set_essid),
1494 IW_HANDLER(SIOCGIWESSID, ray_get_essid),
1495 IW_HANDLER(SIOCSIWRATE, ray_set_rate),
1496 IW_HANDLER(SIOCGIWRATE, ray_get_rate),
1497 IW_HANDLER(SIOCSIWRTS, ray_set_rts),
1498 IW_HANDLER(SIOCGIWRTS, ray_get_rts),
1499 IW_HANDLER(SIOCSIWFRAG, ray_set_frag),
1500 IW_HANDLER(SIOCGIWFRAG, ray_get_frag),
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001501};
1502
John Daiker141fa612009-03-10 06:59:54 -07001503#define SIOCSIPFRAMING SIOCIWFIRSTPRIV /* Set framing mode */
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001504#define SIOCGIPFRAMING SIOCIWFIRSTPRIV + 1 /* Get framing mode */
1505#define SIOCGIPCOUNTRY SIOCIWFIRSTPRIV + 3 /* Get country code */
1506
John Daiker141fa612009-03-10 06:59:54 -07001507static const iw_handler ray_private_handler[] = {
Joe Perches43ead782010-03-18 18:29:40 -07001508 [0] = ray_set_framing,
1509 [1] = ray_get_framing,
1510 [3] = ray_get_country,
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001511};
1512
John Daiker141fa612009-03-10 06:59:54 -07001513static const struct iw_priv_args ray_private_args[] = {
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001514/* cmd, set_args, get_args, name */
John Daiker141fa612009-03-10 06:59:54 -07001515 {SIOCSIPFRAMING, IW_PRIV_TYPE_BYTE | IW_PRIV_SIZE_FIXED | 1, 0,
1516 "set_framing"},
1517 {SIOCGIPFRAMING, 0, IW_PRIV_TYPE_BYTE | IW_PRIV_SIZE_FIXED | 1,
1518 "get_framing"},
1519 {SIOCGIPCOUNTRY, 0, IW_PRIV_TYPE_BYTE | IW_PRIV_SIZE_FIXED | 1,
1520 "get_country"},
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001521};
1522
John Daiker141fa612009-03-10 06:59:54 -07001523static const struct iw_handler_def ray_handler_def = {
1524 .num_standard = ARRAY_SIZE(ray_handler),
1525 .num_private = ARRAY_SIZE(ray_private_handler),
Denis Chengff8ac602007-09-02 18:30:18 +08001526 .num_private_args = ARRAY_SIZE(ray_private_args),
John Daiker141fa612009-03-10 06:59:54 -07001527 .standard = ray_handler,
1528 .private = ray_private_handler,
1529 .private_args = ray_private_args,
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001530 .get_wireless_stats = ray_get_wireless_stats,
1531};
1532
Linus Torvalds1da177e2005-04-16 15:20:36 -07001533/*===========================================================================*/
1534static int ray_open(struct net_device *dev)
1535{
John Daiker141fa612009-03-10 06:59:54 -07001536 ray_dev_t *local = netdev_priv(dev);
1537 struct pcmcia_device *link;
1538 link = local->finder;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001539
Dominik Brodowski624dd662009-10-24 15:52:44 +02001540 dev_dbg(&link->dev, "ray_open('%s')\n", dev->name);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001541
John Daiker141fa612009-03-10 06:59:54 -07001542 if (link->open == 0)
1543 local->num_multi = 0;
1544 link->open++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001545
John Daiker141fa612009-03-10 06:59:54 -07001546 /* If the card is not started, time to start it ! - Jean II */
1547 if (local->card_status == CARD_AWAITING_PARAM) {
1548 int i;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001549
Dominik Brodowski624dd662009-10-24 15:52:44 +02001550 dev_dbg(&link->dev, "ray_open: doing init now !\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001551
John Daiker141fa612009-03-10 06:59:54 -07001552 /* Download startup parameters */
1553 if ((i = dl_startup_params(dev)) < 0) {
1554 printk(KERN_INFO
1555 "ray_dev_init dl_startup_params failed - "
1556 "returns 0x%x\n", i);
1557 return -1;
1558 }
1559 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001560
John Daiker141fa612009-03-10 06:59:54 -07001561 if (sniffer)
1562 netif_stop_queue(dev);
1563 else
1564 netif_start_queue(dev);
1565
Dominik Brodowski624dd662009-10-24 15:52:44 +02001566 dev_dbg(&link->dev, "ray_open ending\n");
John Daiker141fa612009-03-10 06:59:54 -07001567 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001568} /* end ray_open */
John Daiker141fa612009-03-10 06:59:54 -07001569
Linus Torvalds1da177e2005-04-16 15:20:36 -07001570/*===========================================================================*/
1571static int ray_dev_close(struct net_device *dev)
1572{
John Daiker141fa612009-03-10 06:59:54 -07001573 ray_dev_t *local = netdev_priv(dev);
1574 struct pcmcia_device *link;
1575 link = local->finder;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001576
Dominik Brodowski624dd662009-10-24 15:52:44 +02001577 dev_dbg(&link->dev, "ray_dev_close('%s')\n", dev->name);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001578
John Daiker141fa612009-03-10 06:59:54 -07001579 link->open--;
1580 netif_stop_queue(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001581
John Daiker141fa612009-03-10 06:59:54 -07001582 /* In here, we should stop the hardware (stop card from beeing active)
1583 * and set local->card_status to CARD_AWAITING_PARAM, so that while the
1584 * card is closed we can chage its configuration.
1585 * Probably also need a COR reset to get sane state - Jean II */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001586
John Daiker141fa612009-03-10 06:59:54 -07001587 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001588} /* end ray_dev_close */
John Daiker141fa612009-03-10 06:59:54 -07001589
Linus Torvalds1da177e2005-04-16 15:20:36 -07001590/*===========================================================================*/
John Daiker141fa612009-03-10 06:59:54 -07001591static void ray_reset(struct net_device *dev)
1592{
Dominik Brodowski624dd662009-10-24 15:52:44 +02001593 pr_debug("ray_reset entered\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001594}
John Daiker141fa612009-03-10 06:59:54 -07001595
Linus Torvalds1da177e2005-04-16 15:20:36 -07001596/*===========================================================================*/
1597/* Cause a firmware interrupt if it is ready for one */
1598/* Return nonzero if not ready */
1599static int interrupt_ecf(ray_dev_t *local, int ccs)
1600{
John Daiker141fa612009-03-10 06:59:54 -07001601 int i = 50;
1602 struct pcmcia_device *link = local->finder;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001603
John Daiker141fa612009-03-10 06:59:54 -07001604 if (!(pcmcia_dev_present(link))) {
Dominik Brodowski624dd662009-10-24 15:52:44 +02001605 dev_dbg(&link->dev, "ray_cs interrupt_ecf - device not present\n");
John Daiker141fa612009-03-10 06:59:54 -07001606 return -1;
1607 }
Dominik Brodowski624dd662009-10-24 15:52:44 +02001608 dev_dbg(&link->dev, "interrupt_ecf(local=%p, ccs = 0x%x\n", local, ccs);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001609
John Daiker141fa612009-03-10 06:59:54 -07001610 while (i &&
1611 (readb(local->amem + CIS_OFFSET + ECF_INTR_OFFSET) &
1612 ECF_INTR_SET))
1613 i--;
1614 if (i == 0) {
Dominik Brodowski624dd662009-10-24 15:52:44 +02001615 dev_dbg(&link->dev, "ray_cs interrupt_ecf card not ready for interrupt\n");
John Daiker141fa612009-03-10 06:59:54 -07001616 return -1;
1617 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001618 /* Fill the mailbox, then kick the card */
John Daiker141fa612009-03-10 06:59:54 -07001619 writeb(ccs, local->sram + SCB_BASE);
1620 writeb(ECF_INTR_SET, local->amem + CIS_OFFSET + ECF_INTR_OFFSET);
1621 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001622} /* interrupt_ecf */
John Daiker141fa612009-03-10 06:59:54 -07001623
Linus Torvalds1da177e2005-04-16 15:20:36 -07001624/*===========================================================================*/
1625/* Get next free transmit CCS */
1626/* Return - index of current tx ccs */
1627static int get_free_tx_ccs(ray_dev_t *local)
1628{
John Daiker141fa612009-03-10 06:59:54 -07001629 int i;
1630 struct ccs __iomem *pccs = ccs_base(local);
1631 struct pcmcia_device *link = local->finder;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001632
John Daiker141fa612009-03-10 06:59:54 -07001633 if (!(pcmcia_dev_present(link))) {
Dominik Brodowski624dd662009-10-24 15:52:44 +02001634 dev_dbg(&link->dev, "ray_cs get_free_tx_ccs - device not present\n");
John Daiker141fa612009-03-10 06:59:54 -07001635 return ECARDGONE;
1636 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001637
John Daiker141fa612009-03-10 06:59:54 -07001638 if (test_and_set_bit(0, &local->tx_ccs_lock)) {
Dominik Brodowski624dd662009-10-24 15:52:44 +02001639 dev_dbg(&link->dev, "ray_cs tx_ccs_lock busy\n");
John Daiker141fa612009-03-10 06:59:54 -07001640 return ECCSBUSY;
1641 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001642
John Daiker141fa612009-03-10 06:59:54 -07001643 for (i = 0; i < NUMBER_OF_TX_CCS; i++) {
1644 if (readb(&(pccs + i)->buffer_status) == CCS_BUFFER_FREE) {
1645 writeb(CCS_BUFFER_BUSY, &(pccs + i)->buffer_status);
1646 writeb(CCS_END_LIST, &(pccs + i)->link);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001647 local->tx_ccs_lock = 0;
John Daiker141fa612009-03-10 06:59:54 -07001648 return i;
1649 }
1650 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001651 local->tx_ccs_lock = 0;
Dominik Brodowski624dd662009-10-24 15:52:44 +02001652 dev_dbg(&link->dev, "ray_cs ERROR no free tx CCS for raylink card\n");
John Daiker141fa612009-03-10 06:59:54 -07001653 return ECCSFULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001654} /* get_free_tx_ccs */
John Daiker141fa612009-03-10 06:59:54 -07001655
Linus Torvalds1da177e2005-04-16 15:20:36 -07001656/*===========================================================================*/
1657/* Get next free CCS */
1658/* Return - index of current ccs */
1659static int get_free_ccs(ray_dev_t *local)
1660{
John Daiker141fa612009-03-10 06:59:54 -07001661 int i;
1662 struct ccs __iomem *pccs = ccs_base(local);
1663 struct pcmcia_device *link = local->finder;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001664
John Daiker141fa612009-03-10 06:59:54 -07001665 if (!(pcmcia_dev_present(link))) {
Dominik Brodowski624dd662009-10-24 15:52:44 +02001666 dev_dbg(&link->dev, "ray_cs get_free_ccs - device not present\n");
John Daiker141fa612009-03-10 06:59:54 -07001667 return ECARDGONE;
1668 }
1669 if (test_and_set_bit(0, &local->ccs_lock)) {
Dominik Brodowski624dd662009-10-24 15:52:44 +02001670 dev_dbg(&link->dev, "ray_cs ccs_lock busy\n");
John Daiker141fa612009-03-10 06:59:54 -07001671 return ECCSBUSY;
1672 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001673
John Daiker141fa612009-03-10 06:59:54 -07001674 for (i = NUMBER_OF_TX_CCS; i < NUMBER_OF_CCS; i++) {
1675 if (readb(&(pccs + i)->buffer_status) == CCS_BUFFER_FREE) {
1676 writeb(CCS_BUFFER_BUSY, &(pccs + i)->buffer_status);
1677 writeb(CCS_END_LIST, &(pccs + i)->link);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001678 local->ccs_lock = 0;
John Daiker141fa612009-03-10 06:59:54 -07001679 return i;
1680 }
1681 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001682 local->ccs_lock = 0;
Dominik Brodowski624dd662009-10-24 15:52:44 +02001683 dev_dbg(&link->dev, "ray_cs ERROR no free CCS for raylink card\n");
John Daiker141fa612009-03-10 06:59:54 -07001684 return ECCSFULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001685} /* get_free_ccs */
John Daiker141fa612009-03-10 06:59:54 -07001686
Linus Torvalds1da177e2005-04-16 15:20:36 -07001687/*===========================================================================*/
1688static void authenticate_timeout(u_long data)
1689{
John Daiker141fa612009-03-10 06:59:54 -07001690 ray_dev_t *local = (ray_dev_t *) data;
1691 del_timer(&local->timer);
1692 printk(KERN_INFO "ray_cs Authentication with access point failed"
1693 " - timeout\n");
1694 join_net((u_long) local);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001695}
John Daiker141fa612009-03-10 06:59:54 -07001696
Linus Torvalds1da177e2005-04-16 15:20:36 -07001697/*===========================================================================*/
Linus Torvalds1da177e2005-04-16 15:20:36 -07001698static int parse_addr(char *in_str, UCHAR *out)
1699{
John Daiker141fa612009-03-10 06:59:54 -07001700 int len;
1701 int i, j, k;
1702 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001703
John Daiker141fa612009-03-10 06:59:54 -07001704 if (in_str == NULL)
1705 return 0;
1706 if ((len = strlen(in_str)) < 2)
1707 return 0;
1708 memset(out, 0, ADDRLEN);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001709
John Daiker141fa612009-03-10 06:59:54 -07001710 status = 1;
1711 j = len - 1;
1712 if (j > 12)
1713 j = 12;
1714 i = 5;
1715
1716 while (j > 0) {
Andy Shevchenko882d8292010-07-23 03:18:09 +00001717 if ((k = hex_to_bin(in_str[j--])) != -1)
John Daiker141fa612009-03-10 06:59:54 -07001718 out[i] = k;
1719 else
1720 return 0;
1721
1722 if (j == 0)
1723 break;
Andy Shevchenko882d8292010-07-23 03:18:09 +00001724 if ((k = hex_to_bin(in_str[j--])) != -1)
John Daiker141fa612009-03-10 06:59:54 -07001725 out[i] += k << 4;
1726 else
1727 return 0;
1728 if (!i--)
1729 break;
1730 }
1731 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001732}
John Daiker141fa612009-03-10 06:59:54 -07001733
Linus Torvalds1da177e2005-04-16 15:20:36 -07001734/*===========================================================================*/
1735static struct net_device_stats *ray_get_stats(struct net_device *dev)
1736{
John Daiker141fa612009-03-10 06:59:54 -07001737 ray_dev_t *local = netdev_priv(dev);
1738 struct pcmcia_device *link = local->finder;
1739 struct status __iomem *p = local->sram + STATUS_BASE;
1740 if (!(pcmcia_dev_present(link))) {
Dominik Brodowski624dd662009-10-24 15:52:44 +02001741 dev_dbg(&link->dev, "ray_cs net_device_stats - device not present\n");
John Daiker141fa612009-03-10 06:59:54 -07001742 return &local->stats;
1743 }
1744 if (readb(&p->mrx_overflow_for_host)) {
1745 local->stats.rx_over_errors += swab16(readw(&p->mrx_overflow));
1746 writeb(0, &p->mrx_overflow);
1747 writeb(0, &p->mrx_overflow_for_host);
1748 }
1749 if (readb(&p->mrx_checksum_error_for_host)) {
1750 local->stats.rx_crc_errors +=
1751 swab16(readw(&p->mrx_checksum_error));
1752 writeb(0, &p->mrx_checksum_error);
1753 writeb(0, &p->mrx_checksum_error_for_host);
1754 }
1755 if (readb(&p->rx_hec_error_for_host)) {
1756 local->stats.rx_frame_errors += swab16(readw(&p->rx_hec_error));
1757 writeb(0, &p->rx_hec_error);
1758 writeb(0, &p->rx_hec_error_for_host);
1759 }
1760 return &local->stats;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001761}
John Daiker141fa612009-03-10 06:59:54 -07001762
Linus Torvalds1da177e2005-04-16 15:20:36 -07001763/*===========================================================================*/
John Daiker141fa612009-03-10 06:59:54 -07001764static void ray_update_parm(struct net_device *dev, UCHAR objid, UCHAR *value,
1765 int len)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001766{
John Daiker141fa612009-03-10 06:59:54 -07001767 ray_dev_t *local = netdev_priv(dev);
1768 struct pcmcia_device *link = local->finder;
1769 int ccsindex;
1770 int i;
1771 struct ccs __iomem *pccs;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001772
John Daiker141fa612009-03-10 06:59:54 -07001773 if (!(pcmcia_dev_present(link))) {
Dominik Brodowski624dd662009-10-24 15:52:44 +02001774 dev_dbg(&link->dev, "ray_update_parm - device not present\n");
John Daiker141fa612009-03-10 06:59:54 -07001775 return;
1776 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001777
John Daiker141fa612009-03-10 06:59:54 -07001778 if ((ccsindex = get_free_ccs(local)) < 0) {
Dominik Brodowski624dd662009-10-24 15:52:44 +02001779 dev_dbg(&link->dev, "ray_update_parm - No free ccs\n");
John Daiker141fa612009-03-10 06:59:54 -07001780 return;
1781 }
1782 pccs = ccs_base(local) + ccsindex;
1783 writeb(CCS_UPDATE_PARAMS, &pccs->cmd);
1784 writeb(objid, &pccs->var.update_param.object_id);
1785 writeb(1, &pccs->var.update_param.number_objects);
1786 writeb(0, &pccs->var.update_param.failure_cause);
1787 for (i = 0; i < len; i++) {
1788 writeb(value[i], local->sram + HOST_TO_ECF_BASE);
1789 }
1790 /* Interrupt the firmware to process the command */
1791 if (interrupt_ecf(local, ccsindex)) {
Dominik Brodowski624dd662009-10-24 15:52:44 +02001792 dev_dbg(&link->dev, "ray_cs associate failed - ECF not ready for intr\n");
John Daiker141fa612009-03-10 06:59:54 -07001793 writeb(CCS_BUFFER_FREE, &(pccs++)->buffer_status);
1794 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001795}
John Daiker141fa612009-03-10 06:59:54 -07001796
Linus Torvalds1da177e2005-04-16 15:20:36 -07001797/*===========================================================================*/
1798static void ray_update_multi_list(struct net_device *dev, int all)
1799{
John Daiker141fa612009-03-10 06:59:54 -07001800 int ccsindex;
1801 struct ccs __iomem *pccs;
John Daiker141fa612009-03-10 06:59:54 -07001802 ray_dev_t *local = netdev_priv(dev);
1803 struct pcmcia_device *link = local->finder;
1804 void __iomem *p = local->sram + HOST_TO_ECF_BASE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001805
John Daiker141fa612009-03-10 06:59:54 -07001806 if (!(pcmcia_dev_present(link))) {
Dominik Brodowski624dd662009-10-24 15:52:44 +02001807 dev_dbg(&link->dev, "ray_update_multi_list - device not present\n");
John Daiker141fa612009-03-10 06:59:54 -07001808 return;
1809 } else
Dominik Brodowski624dd662009-10-24 15:52:44 +02001810 dev_dbg(&link->dev, "ray_update_multi_list(%p)\n", dev);
John Daiker141fa612009-03-10 06:59:54 -07001811 if ((ccsindex = get_free_ccs(local)) < 0) {
Dominik Brodowski624dd662009-10-24 15:52:44 +02001812 dev_dbg(&link->dev, "ray_update_multi - No free ccs\n");
John Daiker141fa612009-03-10 06:59:54 -07001813 return;
1814 }
1815 pccs = ccs_base(local) + ccsindex;
1816 writeb(CCS_UPDATE_MULTICAST_LIST, &pccs->cmd);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001817
John Daiker141fa612009-03-10 06:59:54 -07001818 if (all) {
1819 writeb(0xff, &pccs->var);
1820 local->num_multi = 0xff;
1821 } else {
Jiri Pirko22bedad32010-04-01 21:22:57 +00001822 struct netdev_hw_addr *ha;
Jiri Pirko655ffee2010-02-27 07:35:45 +00001823 int i = 0;
1824
John Daiker141fa612009-03-10 06:59:54 -07001825 /* Copy the kernel's list of MC addresses to card */
Jiri Pirko22bedad32010-04-01 21:22:57 +00001826 netdev_for_each_mc_addr(ha, dev) {
1827 memcpy_toio(p, ha->addr, ETH_ALEN);
Dominik Brodowski624dd662009-10-24 15:52:44 +02001828 dev_dbg(&link->dev,
John Daiker141fa612009-03-10 06:59:54 -07001829 "ray_update_multi add addr %02x%02x%02x%02x%02x%02x\n",
Jiri Pirko22bedad32010-04-01 21:22:57 +00001830 ha->addr[0], ha->addr[1],
1831 ha->addr[2], ha->addr[3],
1832 ha->addr[4], ha->addr[5]);
John Daiker141fa612009-03-10 06:59:54 -07001833 p += ETH_ALEN;
1834 i++;
1835 }
1836 if (i > 256 / ADDRLEN)
1837 i = 256 / ADDRLEN;
1838 writeb((UCHAR) i, &pccs->var);
Dominik Brodowski624dd662009-10-24 15:52:44 +02001839 dev_dbg(&link->dev, "ray_cs update_multi %d addresses in list\n", i);
John Daiker141fa612009-03-10 06:59:54 -07001840 /* Interrupt the firmware to process the command */
1841 local->num_multi = i;
1842 }
1843 if (interrupt_ecf(local, ccsindex)) {
Dominik Brodowski624dd662009-10-24 15:52:44 +02001844 dev_dbg(&link->dev,
John Daiker141fa612009-03-10 06:59:54 -07001845 "ray_cs update_multi failed - ECF not ready for intr\n");
1846 writeb(CCS_BUFFER_FREE, &(pccs++)->buffer_status);
1847 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001848} /* end ray_update_multi_list */
John Daiker141fa612009-03-10 06:59:54 -07001849
Linus Torvalds1da177e2005-04-16 15:20:36 -07001850/*===========================================================================*/
1851static void set_multicast_list(struct net_device *dev)
1852{
John Daiker141fa612009-03-10 06:59:54 -07001853 ray_dev_t *local = netdev_priv(dev);
1854 UCHAR promisc;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001855
Dominik Brodowski624dd662009-10-24 15:52:44 +02001856 pr_debug("ray_cs set_multicast_list(%p)\n", dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001857
John Daiker141fa612009-03-10 06:59:54 -07001858 if (dev->flags & IFF_PROMISC) {
1859 if (local->sparm.b5.a_promiscuous_mode == 0) {
Dominik Brodowski624dd662009-10-24 15:52:44 +02001860 pr_debug("ray_cs set_multicast_list promisc on\n");
John Daiker141fa612009-03-10 06:59:54 -07001861 local->sparm.b5.a_promiscuous_mode = 1;
1862 promisc = 1;
1863 ray_update_parm(dev, OBJID_promiscuous_mode,
1864 &promisc, sizeof(promisc));
1865 }
1866 } else {
1867 if (local->sparm.b5.a_promiscuous_mode == 1) {
Dominik Brodowski624dd662009-10-24 15:52:44 +02001868 pr_debug("ray_cs set_multicast_list promisc off\n");
John Daiker141fa612009-03-10 06:59:54 -07001869 local->sparm.b5.a_promiscuous_mode = 0;
1870 promisc = 0;
1871 ray_update_parm(dev, OBJID_promiscuous_mode,
1872 &promisc, sizeof(promisc));
1873 }
1874 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001875
John Daiker141fa612009-03-10 06:59:54 -07001876 if (dev->flags & IFF_ALLMULTI)
1877 ray_update_multi_list(dev, 1);
1878 else {
Jiri Pirko4cd24ea2010-02-08 04:30:35 +00001879 if (local->num_multi != netdev_mc_count(dev))
John Daiker141fa612009-03-10 06:59:54 -07001880 ray_update_multi_list(dev, 0);
1881 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001882} /* end set_multicast_list */
John Daiker141fa612009-03-10 06:59:54 -07001883
Linus Torvalds1da177e2005-04-16 15:20:36 -07001884/*=============================================================================
1885 * All routines below here are run at interrupt time.
1886=============================================================================*/
David Howells7d12e782006-10-05 14:55:46 +01001887static irqreturn_t ray_interrupt(int irq, void *dev_id)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001888{
John Daiker141fa612009-03-10 06:59:54 -07001889 struct net_device *dev = (struct net_device *)dev_id;
1890 struct pcmcia_device *link;
1891 ray_dev_t *local;
1892 struct ccs __iomem *pccs;
1893 struct rcs __iomem *prcs;
1894 UCHAR rcsindex;
1895 UCHAR tmp;
1896 UCHAR cmd;
1897 UCHAR status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001898
John Daiker141fa612009-03-10 06:59:54 -07001899 if (dev == NULL) /* Note that we want interrupts with dev->start == 0 */
1900 return IRQ_NONE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001901
Dominik Brodowski624dd662009-10-24 15:52:44 +02001902 pr_debug("ray_cs: interrupt for *dev=%p\n", dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001903
John Daiker141fa612009-03-10 06:59:54 -07001904 local = netdev_priv(dev);
1905 link = (struct pcmcia_device *)local->finder;
1906 if (!pcmcia_dev_present(link)) {
Dominik Brodowski624dd662009-10-24 15:52:44 +02001907 pr_debug(
1908 "ray_cs interrupt from device not present or suspended.\n");
John Daiker141fa612009-03-10 06:59:54 -07001909 return IRQ_NONE;
1910 }
1911 rcsindex = readb(&((struct scb __iomem *)(local->sram))->rcs_index);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001912
John Daiker141fa612009-03-10 06:59:54 -07001913 if (rcsindex >= (NUMBER_OF_CCS + NUMBER_OF_RCS)) {
Dominik Brodowski624dd662009-10-24 15:52:44 +02001914 dev_dbg(&link->dev, "ray_cs interrupt bad rcsindex = 0x%x\n", rcsindex);
John Daiker141fa612009-03-10 06:59:54 -07001915 clear_interrupt(local);
1916 return IRQ_HANDLED;
1917 }
1918 if (rcsindex < NUMBER_OF_CCS) { /* If it's a returned CCS */
1919 pccs = ccs_base(local) + rcsindex;
1920 cmd = readb(&pccs->cmd);
1921 status = readb(&pccs->buffer_status);
1922 switch (cmd) {
1923 case CCS_DOWNLOAD_STARTUP_PARAMS: /* Happens in firmware someday */
1924 del_timer(&local->timer);
1925 if (status == CCS_COMMAND_COMPLETE) {
Dominik Brodowski624dd662009-10-24 15:52:44 +02001926 dev_dbg(&link->dev,
John Daiker141fa612009-03-10 06:59:54 -07001927 "ray_cs interrupt download_startup_parameters OK\n");
1928 } else {
Dominik Brodowski624dd662009-10-24 15:52:44 +02001929 dev_dbg(&link->dev,
John Daiker141fa612009-03-10 06:59:54 -07001930 "ray_cs interrupt download_startup_parameters fail\n");
1931 }
1932 break;
1933 case CCS_UPDATE_PARAMS:
Dominik Brodowski624dd662009-10-24 15:52:44 +02001934 dev_dbg(&link->dev, "ray_cs interrupt update params done\n");
John Daiker141fa612009-03-10 06:59:54 -07001935 if (status != CCS_COMMAND_COMPLETE) {
1936 tmp =
1937 readb(&pccs->var.update_param.
1938 failure_cause);
Dominik Brodowski624dd662009-10-24 15:52:44 +02001939 dev_dbg(&link->dev,
John Daiker141fa612009-03-10 06:59:54 -07001940 "ray_cs interrupt update params failed - reason %d\n",
1941 tmp);
1942 }
1943 break;
1944 case CCS_REPORT_PARAMS:
Dominik Brodowski624dd662009-10-24 15:52:44 +02001945 dev_dbg(&link->dev, "ray_cs interrupt report params done\n");
John Daiker141fa612009-03-10 06:59:54 -07001946 break;
1947 case CCS_UPDATE_MULTICAST_LIST: /* Note that this CCS isn't returned */
Dominik Brodowski624dd662009-10-24 15:52:44 +02001948 dev_dbg(&link->dev,
John Daiker141fa612009-03-10 06:59:54 -07001949 "ray_cs interrupt CCS Update Multicast List done\n");
1950 break;
1951 case CCS_UPDATE_POWER_SAVINGS_MODE:
Dominik Brodowski624dd662009-10-24 15:52:44 +02001952 dev_dbg(&link->dev,
John Daiker141fa612009-03-10 06:59:54 -07001953 "ray_cs interrupt update power save mode done\n");
1954 break;
1955 case CCS_START_NETWORK:
1956 case CCS_JOIN_NETWORK:
1957 if (status == CCS_COMMAND_COMPLETE) {
1958 if (readb
1959 (&pccs->var.start_network.net_initiated) ==
1960 1) {
Dominik Brodowski624dd662009-10-24 15:52:44 +02001961 dev_dbg(&link->dev,
John Daiker141fa612009-03-10 06:59:54 -07001962 "ray_cs interrupt network \"%s\" started\n",
1963 local->sparm.b4.a_current_ess_id);
1964 } else {
Dominik Brodowski624dd662009-10-24 15:52:44 +02001965 dev_dbg(&link->dev,
John Daiker141fa612009-03-10 06:59:54 -07001966 "ray_cs interrupt network \"%s\" joined\n",
1967 local->sparm.b4.a_current_ess_id);
1968 }
1969 memcpy_fromio(&local->bss_id,
1970 pccs->var.start_network.bssid,
1971 ADDRLEN);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001972
John Daiker141fa612009-03-10 06:59:54 -07001973 if (local->fw_ver == 0x55)
1974 local->net_default_tx_rate = 3;
1975 else
1976 local->net_default_tx_rate =
1977 readb(&pccs->var.start_network.
1978 net_default_tx_rate);
1979 local->encryption =
1980 readb(&pccs->var.start_network.encryption);
1981 if (!sniffer && (local->net_type == INFRA)
1982 && !(local->sparm.b4.a_acting_as_ap_status)) {
1983 authenticate(local);
1984 }
1985 local->card_status = CARD_ACQ_COMPLETE;
1986 } else {
1987 local->card_status = CARD_ACQ_FAILED;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001988
John Daiker141fa612009-03-10 06:59:54 -07001989 del_timer(&local->timer);
1990 local->timer.expires = jiffies + HZ * 5;
1991 local->timer.data = (long)local;
1992 if (status == CCS_START_NETWORK) {
Dominik Brodowski624dd662009-10-24 15:52:44 +02001993 dev_dbg(&link->dev,
John Daiker141fa612009-03-10 06:59:54 -07001994 "ray_cs interrupt network \"%s\" start failed\n",
1995 local->sparm.b4.a_current_ess_id);
1996 local->timer.function = &start_net;
1997 } else {
Dominik Brodowski624dd662009-10-24 15:52:44 +02001998 dev_dbg(&link->dev,
John Daiker141fa612009-03-10 06:59:54 -07001999 "ray_cs interrupt network \"%s\" join failed\n",
2000 local->sparm.b4.a_current_ess_id);
2001 local->timer.function = &join_net;
2002 }
2003 add_timer(&local->timer);
2004 }
2005 break;
2006 case CCS_START_ASSOCIATION:
2007 if (status == CCS_COMMAND_COMPLETE) {
2008 local->card_status = CARD_ASSOC_COMPLETE;
Dominik Brodowski624dd662009-10-24 15:52:44 +02002009 dev_dbg(&link->dev, "ray_cs association successful\n");
John Daiker141fa612009-03-10 06:59:54 -07002010 } else {
Dominik Brodowski624dd662009-10-24 15:52:44 +02002011 dev_dbg(&link->dev, "ray_cs association failed,\n");
John Daiker141fa612009-03-10 06:59:54 -07002012 local->card_status = CARD_ASSOC_FAILED;
2013 join_net((u_long) local);
2014 }
2015 break;
2016 case CCS_TX_REQUEST:
2017 if (status == CCS_COMMAND_COMPLETE) {
Dominik Brodowski624dd662009-10-24 15:52:44 +02002018 dev_dbg(&link->dev,
John Daiker141fa612009-03-10 06:59:54 -07002019 "ray_cs interrupt tx request complete\n");
2020 } else {
Dominik Brodowski624dd662009-10-24 15:52:44 +02002021 dev_dbg(&link->dev,
John Daiker141fa612009-03-10 06:59:54 -07002022 "ray_cs interrupt tx request failed\n");
2023 }
2024 if (!sniffer)
2025 netif_start_queue(dev);
2026 netif_wake_queue(dev);
2027 break;
2028 case CCS_TEST_MEMORY:
Dominik Brodowski624dd662009-10-24 15:52:44 +02002029 dev_dbg(&link->dev, "ray_cs interrupt mem test done\n");
John Daiker141fa612009-03-10 06:59:54 -07002030 break;
2031 case CCS_SHUTDOWN:
Dominik Brodowski624dd662009-10-24 15:52:44 +02002032 dev_dbg(&link->dev,
John Daiker141fa612009-03-10 06:59:54 -07002033 "ray_cs interrupt Unexpected CCS returned - Shutdown\n");
2034 break;
2035 case CCS_DUMP_MEMORY:
Dominik Brodowski624dd662009-10-24 15:52:44 +02002036 dev_dbg(&link->dev, "ray_cs interrupt dump memory done\n");
John Daiker141fa612009-03-10 06:59:54 -07002037 break;
2038 case CCS_START_TIMER:
Dominik Brodowski624dd662009-10-24 15:52:44 +02002039 dev_dbg(&link->dev,
John Daiker141fa612009-03-10 06:59:54 -07002040 "ray_cs interrupt DING - raylink timer expired\n");
2041 break;
2042 default:
Dominik Brodowski624dd662009-10-24 15:52:44 +02002043 dev_dbg(&link->dev,
John Daiker141fa612009-03-10 06:59:54 -07002044 "ray_cs interrupt Unexpected CCS 0x%x returned 0x%x\n",
2045 rcsindex, cmd);
2046 }
2047 writeb(CCS_BUFFER_FREE, &pccs->buffer_status);
2048 } else { /* It's an RCS */
2049
2050 prcs = rcs_base(local) + rcsindex;
2051
2052 switch (readb(&prcs->interrupt_id)) {
2053 case PROCESS_RX_PACKET:
2054 ray_rx(dev, local, prcs);
2055 break;
2056 case REJOIN_NET_COMPLETE:
Dominik Brodowski624dd662009-10-24 15:52:44 +02002057 dev_dbg(&link->dev, "ray_cs interrupt rejoin net complete\n");
John Daiker141fa612009-03-10 06:59:54 -07002058 local->card_status = CARD_ACQ_COMPLETE;
2059 /* do we need to clear tx buffers CCS's? */
2060 if (local->sparm.b4.a_network_type == ADHOC) {
2061 if (!sniffer)
2062 netif_start_queue(dev);
2063 } else {
2064 memcpy_fromio(&local->bss_id,
2065 prcs->var.rejoin_net_complete.
2066 bssid, ADDRLEN);
Dominik Brodowski624dd662009-10-24 15:52:44 +02002067 dev_dbg(&link->dev,
John Daiker141fa612009-03-10 06:59:54 -07002068 "ray_cs new BSSID = %02x%02x%02x%02x%02x%02x\n",
2069 local->bss_id[0], local->bss_id[1],
2070 local->bss_id[2], local->bss_id[3],
2071 local->bss_id[4], local->bss_id[5]);
2072 if (!sniffer)
2073 authenticate(local);
2074 }
2075 break;
2076 case ROAMING_INITIATED:
Dominik Brodowski624dd662009-10-24 15:52:44 +02002077 dev_dbg(&link->dev, "ray_cs interrupt roaming initiated\n");
John Daiker141fa612009-03-10 06:59:54 -07002078 netif_stop_queue(dev);
2079 local->card_status = CARD_DOING_ACQ;
2080 break;
2081 case JAPAN_CALL_SIGN_RXD:
Dominik Brodowski624dd662009-10-24 15:52:44 +02002082 dev_dbg(&link->dev, "ray_cs interrupt japan call sign rx\n");
John Daiker141fa612009-03-10 06:59:54 -07002083 break;
2084 default:
Dominik Brodowski624dd662009-10-24 15:52:44 +02002085 dev_dbg(&link->dev,
John Daiker141fa612009-03-10 06:59:54 -07002086 "ray_cs Unexpected interrupt for RCS 0x%x cmd = 0x%x\n",
2087 rcsindex,
2088 (unsigned int)readb(&prcs->interrupt_id));
2089 break;
2090 }
2091 writeb(CCS_BUFFER_FREE, &prcs->buffer_status);
2092 }
2093 clear_interrupt(local);
2094 return IRQ_HANDLED;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002095} /* ray_interrupt */
John Daiker141fa612009-03-10 06:59:54 -07002096
Linus Torvalds1da177e2005-04-16 15:20:36 -07002097/*===========================================================================*/
John Daiker141fa612009-03-10 06:59:54 -07002098static void ray_rx(struct net_device *dev, ray_dev_t *local,
2099 struct rcs __iomem *prcs)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002100{
John Daiker141fa612009-03-10 06:59:54 -07002101 int rx_len;
2102 unsigned int pkt_addr;
2103 void __iomem *pmsg;
Dominik Brodowski624dd662009-10-24 15:52:44 +02002104 pr_debug("ray_rx process rx packet\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002105
John Daiker141fa612009-03-10 06:59:54 -07002106 /* Calculate address of packet within Rx buffer */
2107 pkt_addr = ((readb(&prcs->var.rx_packet.rx_data_ptr[0]) << 8)
2108 + readb(&prcs->var.rx_packet.rx_data_ptr[1])) & RX_BUFF_END;
2109 /* Length of first packet fragment */
2110 rx_len = (readb(&prcs->var.rx_packet.rx_data_length[0]) << 8)
2111 + readb(&prcs->var.rx_packet.rx_data_length[1]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002112
John Daiker141fa612009-03-10 06:59:54 -07002113 local->last_rsl = readb(&prcs->var.rx_packet.rx_sig_lev);
2114 pmsg = local->rmem + pkt_addr;
2115 switch (readb(pmsg)) {
2116 case DATA_TYPE:
Dominik Brodowski624dd662009-10-24 15:52:44 +02002117 pr_debug("ray_rx data type\n");
John Daiker141fa612009-03-10 06:59:54 -07002118 rx_data(dev, prcs, pkt_addr, rx_len);
2119 break;
2120 case AUTHENTIC_TYPE:
Dominik Brodowski624dd662009-10-24 15:52:44 +02002121 pr_debug("ray_rx authentic type\n");
John Daiker141fa612009-03-10 06:59:54 -07002122 if (sniffer)
2123 rx_data(dev, prcs, pkt_addr, rx_len);
2124 else
2125 rx_authenticate(local, prcs, pkt_addr, rx_len);
2126 break;
2127 case DEAUTHENTIC_TYPE:
Dominik Brodowski624dd662009-10-24 15:52:44 +02002128 pr_debug("ray_rx deauth type\n");
John Daiker141fa612009-03-10 06:59:54 -07002129 if (sniffer)
2130 rx_data(dev, prcs, pkt_addr, rx_len);
2131 else
2132 rx_deauthenticate(local, prcs, pkt_addr, rx_len);
2133 break;
2134 case NULL_MSG_TYPE:
Dominik Brodowski624dd662009-10-24 15:52:44 +02002135 pr_debug("ray_cs rx NULL msg\n");
John Daiker141fa612009-03-10 06:59:54 -07002136 break;
2137 case BEACON_TYPE:
Dominik Brodowski624dd662009-10-24 15:52:44 +02002138 pr_debug("ray_rx beacon type\n");
John Daiker141fa612009-03-10 06:59:54 -07002139 if (sniffer)
2140 rx_data(dev, prcs, pkt_addr, rx_len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002141
John Daiker141fa612009-03-10 06:59:54 -07002142 copy_from_rx_buff(local, (UCHAR *) &local->last_bcn, pkt_addr,
2143 rx_len < sizeof(struct beacon_rx) ?
2144 rx_len : sizeof(struct beacon_rx));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002145
John Daiker141fa612009-03-10 06:59:54 -07002146 local->beacon_rxed = 1;
2147 /* Get the statistics so the card counters never overflow */
2148 ray_get_stats(dev);
2149 break;
2150 default:
Dominik Brodowski624dd662009-10-24 15:52:44 +02002151 pr_debug("ray_cs unknown pkt type %2x\n",
John Daiker141fa612009-03-10 06:59:54 -07002152 (unsigned int)readb(pmsg));
2153 break;
2154 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002155
2156} /* end ray_rx */
John Daiker141fa612009-03-10 06:59:54 -07002157
Linus Torvalds1da177e2005-04-16 15:20:36 -07002158/*===========================================================================*/
John Daiker141fa612009-03-10 06:59:54 -07002159static void rx_data(struct net_device *dev, struct rcs __iomem *prcs,
2160 unsigned int pkt_addr, int rx_len)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002161{
John Daiker141fa612009-03-10 06:59:54 -07002162 struct sk_buff *skb = NULL;
2163 struct rcs __iomem *prcslink = prcs;
2164 ray_dev_t *local = netdev_priv(dev);
2165 UCHAR *rx_ptr;
2166 int total_len;
2167 int tmp;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002168#ifdef WIRELESS_SPY
John Daiker141fa612009-03-10 06:59:54 -07002169 int siglev = local->last_rsl;
2170 u_char linksrcaddr[ETH_ALEN]; /* Other end of the wireless link */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002171#endif
2172
John Daiker141fa612009-03-10 06:59:54 -07002173 if (!sniffer) {
2174 if (translate) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002175/* TBD length needs fixing for translated header */
John Daiker141fa612009-03-10 06:59:54 -07002176 if (rx_len < (ETH_HLEN + RX_MAC_HEADER_LENGTH) ||
2177 rx_len >
2178 (dev->mtu + RX_MAC_HEADER_LENGTH + ETH_HLEN +
2179 FCS_LEN)) {
Dominik Brodowski624dd662009-10-24 15:52:44 +02002180 pr_debug(
Frans Popcb01b092010-03-24 19:46:34 +01002181 "ray_cs invalid packet length %d received\n",
John Daiker141fa612009-03-10 06:59:54 -07002182 rx_len);
2183 return;
2184 }
2185 } else { /* encapsulated ethernet */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002186
John Daiker141fa612009-03-10 06:59:54 -07002187 if (rx_len < (ETH_HLEN + RX_MAC_HEADER_LENGTH) ||
2188 rx_len >
2189 (dev->mtu + RX_MAC_HEADER_LENGTH + ETH_HLEN +
2190 FCS_LEN)) {
Dominik Brodowski624dd662009-10-24 15:52:44 +02002191 pr_debug(
Frans Popcb01b092010-03-24 19:46:34 +01002192 "ray_cs invalid packet length %d received\n",
John Daiker141fa612009-03-10 06:59:54 -07002193 rx_len);
2194 return;
2195 }
2196 }
2197 }
Dominik Brodowski624dd662009-10-24 15:52:44 +02002198 pr_debug("ray_cs rx_data packet\n");
John Daiker141fa612009-03-10 06:59:54 -07002199 /* If fragmented packet, verify sizes of fragments add up */
2200 if (readb(&prcs->var.rx_packet.next_frag_rcs_index) != 0xFF) {
Dominik Brodowski624dd662009-10-24 15:52:44 +02002201 pr_debug("ray_cs rx'ed fragment\n");
John Daiker141fa612009-03-10 06:59:54 -07002202 tmp = (readb(&prcs->var.rx_packet.totalpacketlength[0]) << 8)
2203 + readb(&prcs->var.rx_packet.totalpacketlength[1]);
2204 total_len = tmp;
2205 prcslink = prcs;
2206 do {
2207 tmp -=
2208 (readb(&prcslink->var.rx_packet.rx_data_length[0])
2209 << 8)
2210 + readb(&prcslink->var.rx_packet.rx_data_length[1]);
2211 if (readb(&prcslink->var.rx_packet.next_frag_rcs_index)
2212 == 0xFF || tmp < 0)
2213 break;
2214 prcslink = rcs_base(local)
2215 + readb(&prcslink->link_field);
2216 } while (1);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002217
John Daiker141fa612009-03-10 06:59:54 -07002218 if (tmp < 0) {
Dominik Brodowski624dd662009-10-24 15:52:44 +02002219 pr_debug(
John Daiker141fa612009-03-10 06:59:54 -07002220 "ray_cs rx_data fragment lengths don't add up\n");
2221 local->stats.rx_dropped++;
2222 release_frag_chain(local, prcs);
2223 return;
2224 }
2225 } else { /* Single unfragmented packet */
2226 total_len = rx_len;
2227 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002228
John Daiker141fa612009-03-10 06:59:54 -07002229 skb = dev_alloc_skb(total_len + 5);
2230 if (skb == NULL) {
Dominik Brodowski624dd662009-10-24 15:52:44 +02002231 pr_debug("ray_cs rx_data could not allocate skb\n");
John Daiker141fa612009-03-10 06:59:54 -07002232 local->stats.rx_dropped++;
2233 if (readb(&prcs->var.rx_packet.next_frag_rcs_index) != 0xFF)
2234 release_frag_chain(local, prcs);
2235 return;
2236 }
2237 skb_reserve(skb, 2); /* Align IP on 16 byte (TBD check this) */
2238
Dominik Brodowski624dd662009-10-24 15:52:44 +02002239 pr_debug("ray_cs rx_data total_len = %x, rx_len = %x\n", total_len,
John Daiker141fa612009-03-10 06:59:54 -07002240 rx_len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002241
2242/************************/
John Daiker141fa612009-03-10 06:59:54 -07002243 /* Reserve enough room for the whole damn packet. */
2244 rx_ptr = skb_put(skb, total_len);
2245 /* Copy the whole packet to sk_buff */
2246 rx_ptr +=
2247 copy_from_rx_buff(local, rx_ptr, pkt_addr & RX_BUFF_END, rx_len);
2248 /* Get source address */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002249#ifdef WIRELESS_SPY
John Daiker141fa612009-03-10 06:59:54 -07002250 skb_copy_from_linear_data_offset(skb,
2251 offsetof(struct mac_header, addr_2),
2252 linksrcaddr, ETH_ALEN);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002253#endif
John Daiker141fa612009-03-10 06:59:54 -07002254 /* Now, deal with encapsulation/translation/sniffer */
2255 if (!sniffer) {
2256 if (!translate) {
2257 /* Encapsulated ethernet, so just lop off 802.11 MAC header */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002258/* TBD reserve skb_reserve( skb, RX_MAC_HEADER_LENGTH); */
John Daiker141fa612009-03-10 06:59:54 -07002259 skb_pull(skb, RX_MAC_HEADER_LENGTH);
2260 } else {
2261 /* Do translation */
2262 untranslate(local, skb, total_len);
2263 }
2264 } else { /* sniffer mode, so just pass whole packet */
2265 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002266
2267/************************/
John Daiker141fa612009-03-10 06:59:54 -07002268 /* Now pick up the rest of the fragments if any */
2269 tmp = 17;
2270 if (readb(&prcs->var.rx_packet.next_frag_rcs_index) != 0xFF) {
2271 prcslink = prcs;
Dominik Brodowski624dd662009-10-24 15:52:44 +02002272 pr_debug("ray_cs rx_data in fragment loop\n");
John Daiker141fa612009-03-10 06:59:54 -07002273 do {
2274 prcslink = rcs_base(local)
2275 +
2276 readb(&prcslink->var.rx_packet.next_frag_rcs_index);
2277 rx_len =
2278 ((readb(&prcslink->var.rx_packet.rx_data_length[0])
2279 << 8)
2280 +
2281 readb(&prcslink->var.rx_packet.rx_data_length[1]))
2282 & RX_BUFF_END;
2283 pkt_addr =
2284 ((readb(&prcslink->var.rx_packet.rx_data_ptr[0]) <<
2285 8)
2286 + readb(&prcslink->var.rx_packet.rx_data_ptr[1]))
2287 & RX_BUFF_END;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002288
John Daiker141fa612009-03-10 06:59:54 -07002289 rx_ptr +=
2290 copy_from_rx_buff(local, rx_ptr, pkt_addr, rx_len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002291
John Daiker141fa612009-03-10 06:59:54 -07002292 } while (tmp-- &&
2293 readb(&prcslink->var.rx_packet.next_frag_rcs_index) !=
2294 0xFF);
2295 release_frag_chain(local, prcs);
2296 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002297
John Daiker141fa612009-03-10 06:59:54 -07002298 skb->protocol = eth_type_trans(skb, dev);
2299 netif_rx(skb);
2300 local->stats.rx_packets++;
2301 local->stats.rx_bytes += total_len;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002302
John Daiker141fa612009-03-10 06:59:54 -07002303 /* Gather signal strength per address */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002304#ifdef WIRELESS_SPY
John Daiker141fa612009-03-10 06:59:54 -07002305 /* For the Access Point or the node having started the ad-hoc net
2306 * note : ad-hoc work only in some specific configurations, but we
2307 * kludge in ray_get_wireless_stats... */
2308 if (!memcmp(linksrcaddr, local->bss_id, ETH_ALEN)) {
2309 /* Update statistics */
2310 /*local->wstats.qual.qual = none ? */
2311 local->wstats.qual.level = siglev;
2312 /*local->wstats.qual.noise = none ? */
2313 local->wstats.qual.updated = 0x2;
2314 }
2315 /* Now, update the spy stuff */
2316 {
2317 struct iw_quality wstats;
2318 wstats.level = siglev;
2319 /* wstats.noise = none ? */
2320 /* wstats.qual = none ? */
2321 wstats.updated = 0x2;
2322 /* Update spy records */
2323 wireless_spy_update(dev, linksrcaddr, &wstats);
2324 }
2325#endif /* WIRELESS_SPY */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002326} /* end rx_data */
John Daiker141fa612009-03-10 06:59:54 -07002327
Linus Torvalds1da177e2005-04-16 15:20:36 -07002328/*===========================================================================*/
2329static void untranslate(ray_dev_t *local, struct sk_buff *skb, int len)
2330{
John Daiker141fa612009-03-10 06:59:54 -07002331 snaphdr_t *psnap = (snaphdr_t *) (skb->data + RX_MAC_HEADER_LENGTH);
2332 struct ieee80211_hdr *pmac = (struct ieee80211_hdr *)skb->data;
2333 __be16 type = *(__be16 *) psnap->ethertype;
2334 int delta;
2335 struct ethhdr *peth;
2336 UCHAR srcaddr[ADDRLEN];
2337 UCHAR destaddr[ADDRLEN];
2338 static UCHAR org_bridge[3] = { 0, 0, 0xf8 };
2339 static UCHAR org_1042[3] = { 0, 0, 0 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002340
John Daiker141fa612009-03-10 06:59:54 -07002341 memcpy(destaddr, ieee80211_get_DA(pmac), ADDRLEN);
2342 memcpy(srcaddr, ieee80211_get_SA(pmac), ADDRLEN);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002343
Dominik Brodowski624dd662009-10-24 15:52:44 +02002344#if 0
2345 if {
Joe Perchesad361c92009-07-06 13:05:40 -07002346 print_hex_dump(KERN_DEBUG, "skb->data before untranslate: ",
2347 DUMP_PREFIX_NONE, 16, 1,
2348 skb->data, 64, true);
2349 printk(KERN_DEBUG
John Daiker141fa612009-03-10 06:59:54 -07002350 "type = %08x, xsap = %02x%02x%02x, org = %02x02x02x\n",
2351 ntohs(type), psnap->dsap, psnap->ssap, psnap->ctrl,
2352 psnap->org[0], psnap->org[1], psnap->org[2]);
2353 printk(KERN_DEBUG "untranslate skb->data = %p\n", skb->data);
2354 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002355#endif
2356
John Daiker141fa612009-03-10 06:59:54 -07002357 if (psnap->dsap != 0xaa || psnap->ssap != 0xaa || psnap->ctrl != 3) {
2358 /* not a snap type so leave it alone */
Dominik Brodowski624dd662009-10-24 15:52:44 +02002359 pr_debug("ray_cs untranslate NOT SNAP %02x %02x %02x\n",
John Daiker141fa612009-03-10 06:59:54 -07002360 psnap->dsap, psnap->ssap, psnap->ctrl);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002361
John Daiker141fa612009-03-10 06:59:54 -07002362 delta = RX_MAC_HEADER_LENGTH - ETH_HLEN;
2363 peth = (struct ethhdr *)(skb->data + delta);
2364 peth->h_proto = htons(len - RX_MAC_HEADER_LENGTH);
2365 } else { /* Its a SNAP */
2366 if (memcmp(psnap->org, org_bridge, 3) == 0) {
2367 /* EtherII and nuke the LLC */
Dominik Brodowski624dd662009-10-24 15:52:44 +02002368 pr_debug("ray_cs untranslate Bridge encap\n");
John Daiker141fa612009-03-10 06:59:54 -07002369 delta = RX_MAC_HEADER_LENGTH
2370 + sizeof(struct snaphdr_t) - ETH_HLEN;
2371 peth = (struct ethhdr *)(skb->data + delta);
2372 peth->h_proto = type;
2373 } else if (memcmp(psnap->org, org_1042, 3) == 0) {
2374 switch (ntohs(type)) {
2375 case ETH_P_IPX:
2376 case ETH_P_AARP:
Dominik Brodowski624dd662009-10-24 15:52:44 +02002377 pr_debug("ray_cs untranslate RFC IPX/AARP\n");
John Daiker141fa612009-03-10 06:59:54 -07002378 delta = RX_MAC_HEADER_LENGTH - ETH_HLEN;
2379 peth = (struct ethhdr *)(skb->data + delta);
2380 peth->h_proto =
2381 htons(len - RX_MAC_HEADER_LENGTH);
2382 break;
2383 default:
Dominik Brodowski624dd662009-10-24 15:52:44 +02002384 pr_debug("ray_cs untranslate RFC default\n");
John Daiker141fa612009-03-10 06:59:54 -07002385 delta = RX_MAC_HEADER_LENGTH +
2386 sizeof(struct snaphdr_t) - ETH_HLEN;
2387 peth = (struct ethhdr *)(skb->data + delta);
2388 peth->h_proto = type;
2389 break;
2390 }
2391 } else {
2392 printk("ray_cs untranslate very confused by packet\n");
2393 delta = RX_MAC_HEADER_LENGTH - ETH_HLEN;
2394 peth = (struct ethhdr *)(skb->data + delta);
2395 peth->h_proto = type;
2396 }
Al Viro7698d692007-12-29 04:55:50 -05002397 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002398/* TBD reserve skb_reserve(skb, delta); */
John Daiker141fa612009-03-10 06:59:54 -07002399 skb_pull(skb, delta);
Dominik Brodowski624dd662009-10-24 15:52:44 +02002400 pr_debug("untranslate after skb_pull(%d), skb->data = %p\n", delta,
John Daiker141fa612009-03-10 06:59:54 -07002401 skb->data);
2402 memcpy(peth->h_dest, destaddr, ADDRLEN);
2403 memcpy(peth->h_source, srcaddr, ADDRLEN);
Dominik Brodowski624dd662009-10-24 15:52:44 +02002404#if 0
2405 {
John Daiker141fa612009-03-10 06:59:54 -07002406 int i;
2407 printk(KERN_DEBUG "skb->data after untranslate:");
2408 for (i = 0; i < 64; i++)
2409 printk("%02x ", skb->data[i]);
2410 printk("\n");
2411 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002412#endif
2413} /* end untranslate */
John Daiker141fa612009-03-10 06:59:54 -07002414
Linus Torvalds1da177e2005-04-16 15:20:36 -07002415/*===========================================================================*/
2416/* Copy data from circular receive buffer to PC memory.
2417 * dest = destination address in PC memory
2418 * pkt_addr = source address in receive buffer
2419 * len = length of packet to copy
2420 */
John Daiker141fa612009-03-10 06:59:54 -07002421static int copy_from_rx_buff(ray_dev_t *local, UCHAR *dest, int pkt_addr,
2422 int length)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002423{
John Daiker141fa612009-03-10 06:59:54 -07002424 int wrap_bytes = (pkt_addr + length) - (RX_BUFF_END + 1);
2425 if (wrap_bytes <= 0) {
2426 memcpy_fromio(dest, local->rmem + pkt_addr, length);
2427 } else { /* Packet wrapped in circular buffer */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002428
John Daiker141fa612009-03-10 06:59:54 -07002429 memcpy_fromio(dest, local->rmem + pkt_addr,
2430 length - wrap_bytes);
2431 memcpy_fromio(dest + length - wrap_bytes, local->rmem,
2432 wrap_bytes);
2433 }
2434 return length;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002435}
John Daiker141fa612009-03-10 06:59:54 -07002436
2437/*===========================================================================*/
2438static void release_frag_chain(ray_dev_t *local, struct rcs __iomem *prcs)
2439{
2440 struct rcs __iomem *prcslink = prcs;
2441 int tmp = 17;
2442 unsigned rcsindex = readb(&prcs->var.rx_packet.next_frag_rcs_index);
2443
2444 while (tmp--) {
2445 writeb(CCS_BUFFER_FREE, &prcslink->buffer_status);
2446 if (rcsindex >= (NUMBER_OF_CCS + NUMBER_OF_RCS)) {
Dominik Brodowski624dd662009-10-24 15:52:44 +02002447 pr_debug("ray_cs interrupt bad rcsindex = 0x%x\n",
John Daiker141fa612009-03-10 06:59:54 -07002448 rcsindex);
2449 break;
2450 }
2451 prcslink = rcs_base(local) + rcsindex;
2452 rcsindex = readb(&prcslink->var.rx_packet.next_frag_rcs_index);
2453 }
2454 writeb(CCS_BUFFER_FREE, &prcslink->buffer_status);
2455}
2456
Linus Torvalds1da177e2005-04-16 15:20:36 -07002457/*===========================================================================*/
2458static void authenticate(ray_dev_t *local)
2459{
John Daiker141fa612009-03-10 06:59:54 -07002460 struct pcmcia_device *link = local->finder;
Dominik Brodowski624dd662009-10-24 15:52:44 +02002461 dev_dbg(&link->dev, "ray_cs Starting authentication.\n");
John Daiker141fa612009-03-10 06:59:54 -07002462 if (!(pcmcia_dev_present(link))) {
Dominik Brodowski624dd662009-10-24 15:52:44 +02002463 dev_dbg(&link->dev, "ray_cs authenticate - device not present\n");
John Daiker141fa612009-03-10 06:59:54 -07002464 return;
2465 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002466
John Daiker141fa612009-03-10 06:59:54 -07002467 del_timer(&local->timer);
2468 if (build_auth_frame(local, local->bss_id, OPEN_AUTH_REQUEST)) {
2469 local->timer.function = &join_net;
2470 } else {
2471 local->timer.function = &authenticate_timeout;
2472 }
2473 local->timer.expires = jiffies + HZ * 2;
2474 local->timer.data = (long)local;
2475 add_timer(&local->timer);
2476 local->authentication_state = AWAITING_RESPONSE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002477} /* end authenticate */
John Daiker141fa612009-03-10 06:59:54 -07002478
Linus Torvalds1da177e2005-04-16 15:20:36 -07002479/*===========================================================================*/
2480static void rx_authenticate(ray_dev_t *local, struct rcs __iomem *prcs,
John Daiker141fa612009-03-10 06:59:54 -07002481 unsigned int pkt_addr, int rx_len)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002482{
John Daiker141fa612009-03-10 06:59:54 -07002483 UCHAR buff[256];
2484 struct rx_msg *msg = (struct rx_msg *)buff;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002485
John Daiker141fa612009-03-10 06:59:54 -07002486 del_timer(&local->timer);
2487
2488 copy_from_rx_buff(local, buff, pkt_addr, rx_len & 0xff);
2489 /* if we are trying to get authenticated */
2490 if (local->sparm.b4.a_network_type == ADHOC) {
Dominik Brodowski624dd662009-10-24 15:52:44 +02002491 pr_debug("ray_cs rx_auth var= %02x %02x %02x %02x %02x %02x\n",
John Daiker141fa612009-03-10 06:59:54 -07002492 msg->var[0], msg->var[1], msg->var[2], msg->var[3],
2493 msg->var[4], msg->var[5]);
2494 if (msg->var[2] == 1) {
Dominik Brodowski624dd662009-10-24 15:52:44 +02002495 pr_debug("ray_cs Sending authentication response.\n");
John Daiker141fa612009-03-10 06:59:54 -07002496 if (!build_auth_frame
2497 (local, msg->mac.addr_2, OPEN_AUTH_RESPONSE)) {
2498 local->authentication_state = NEED_TO_AUTH;
2499 memcpy(local->auth_id, msg->mac.addr_2,
2500 ADDRLEN);
2501 }
2502 }
2503 } else { /* Infrastructure network */
2504
2505 if (local->authentication_state == AWAITING_RESPONSE) {
2506 /* Verify authentication sequence #2 and success */
2507 if (msg->var[2] == 2) {
2508 if ((msg->var[3] | msg->var[4]) == 0) {
Dominik Brodowski624dd662009-10-24 15:52:44 +02002509 pr_debug("Authentication successful\n");
John Daiker141fa612009-03-10 06:59:54 -07002510 local->card_status = CARD_AUTH_COMPLETE;
2511 associate(local);
2512 local->authentication_state =
2513 AUTHENTICATED;
2514 } else {
Dominik Brodowski624dd662009-10-24 15:52:44 +02002515 pr_debug("Authentication refused\n");
John Daiker141fa612009-03-10 06:59:54 -07002516 local->card_status = CARD_AUTH_REFUSED;
2517 join_net((u_long) local);
2518 local->authentication_state =
2519 UNAUTHENTICATED;
2520 }
2521 }
2522 }
2523 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002524
2525} /* end rx_authenticate */
John Daiker141fa612009-03-10 06:59:54 -07002526
Linus Torvalds1da177e2005-04-16 15:20:36 -07002527/*===========================================================================*/
2528static void associate(ray_dev_t *local)
2529{
John Daiker141fa612009-03-10 06:59:54 -07002530 struct ccs __iomem *pccs;
2531 struct pcmcia_device *link = local->finder;
2532 struct net_device *dev = link->priv;
2533 int ccsindex;
2534 if (!(pcmcia_dev_present(link))) {
Dominik Brodowski624dd662009-10-24 15:52:44 +02002535 dev_dbg(&link->dev, "ray_cs associate - device not present\n");
John Daiker141fa612009-03-10 06:59:54 -07002536 return;
2537 }
2538 /* If no tx buffers available, return */
2539 if ((ccsindex = get_free_ccs(local)) < 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002540/* TBD should never be here but... what if we are? */
Dominik Brodowski624dd662009-10-24 15:52:44 +02002541 dev_dbg(&link->dev, "ray_cs associate - No free ccs\n");
John Daiker141fa612009-03-10 06:59:54 -07002542 return;
2543 }
Dominik Brodowski624dd662009-10-24 15:52:44 +02002544 dev_dbg(&link->dev, "ray_cs Starting association with access point\n");
John Daiker141fa612009-03-10 06:59:54 -07002545 pccs = ccs_base(local) + ccsindex;
2546 /* fill in the CCS */
2547 writeb(CCS_START_ASSOCIATION, &pccs->cmd);
2548 /* Interrupt the firmware to process the command */
2549 if (interrupt_ecf(local, ccsindex)) {
Dominik Brodowski624dd662009-10-24 15:52:44 +02002550 dev_dbg(&link->dev, "ray_cs associate failed - ECF not ready for intr\n");
John Daiker141fa612009-03-10 06:59:54 -07002551 writeb(CCS_BUFFER_FREE, &(pccs++)->buffer_status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002552
John Daiker141fa612009-03-10 06:59:54 -07002553 del_timer(&local->timer);
2554 local->timer.expires = jiffies + HZ * 2;
2555 local->timer.data = (long)local;
2556 local->timer.function = &join_net;
2557 add_timer(&local->timer);
2558 local->card_status = CARD_ASSOC_FAILED;
2559 return;
2560 }
2561 if (!sniffer)
2562 netif_start_queue(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002563
2564} /* end associate */
John Daiker141fa612009-03-10 06:59:54 -07002565
Linus Torvalds1da177e2005-04-16 15:20:36 -07002566/*===========================================================================*/
John Daiker141fa612009-03-10 06:59:54 -07002567static void rx_deauthenticate(ray_dev_t *local, struct rcs __iomem *prcs,
2568 unsigned int pkt_addr, int rx_len)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002569{
2570/* UCHAR buff[256];
2571 struct rx_msg *msg = (struct rx_msg *)buff;
2572*/
Dominik Brodowski624dd662009-10-24 15:52:44 +02002573 pr_debug("Deauthentication frame received\n");
John Daiker141fa612009-03-10 06:59:54 -07002574 local->authentication_state = UNAUTHENTICATED;
2575 /* Need to reauthenticate or rejoin depending on reason code */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002576/* copy_from_rx_buff(local, buff, pkt_addr, rx_len & 0xff);
2577 */
2578}
John Daiker141fa612009-03-10 06:59:54 -07002579
Linus Torvalds1da177e2005-04-16 15:20:36 -07002580/*===========================================================================*/
2581static void clear_interrupt(ray_dev_t *local)
2582{
John Daiker141fa612009-03-10 06:59:54 -07002583 writeb(0, local->amem + CIS_OFFSET + HCS_INTR_OFFSET);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002584}
John Daiker141fa612009-03-10 06:59:54 -07002585
Linus Torvalds1da177e2005-04-16 15:20:36 -07002586/*===========================================================================*/
2587#ifdef CONFIG_PROC_FS
2588#define MAXDATA (PAGE_SIZE - 80)
2589
2590static char *card_status[] = {
John Daiker141fa612009-03-10 06:59:54 -07002591 "Card inserted - uninitialized", /* 0 */
2592 "Card not downloaded", /* 1 */
2593 "Waiting for download parameters", /* 2 */
2594 "Card doing acquisition", /* 3 */
2595 "Acquisition complete", /* 4 */
2596 "Authentication complete", /* 5 */
2597 "Association complete", /* 6 */
2598 "???", "???", "???", "???", /* 7 8 9 10 undefined */
2599 "Card init error", /* 11 */
2600 "Download parameters error", /* 12 */
2601 "???", /* 13 */
2602 "Acquisition failed", /* 14 */
2603 "Authentication refused", /* 15 */
2604 "Association failed" /* 16 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002605};
2606
John Daiker141fa612009-03-10 06:59:54 -07002607static char *nettype[] = { "Adhoc", "Infra " };
2608static char *framing[] = { "Encapsulation", "Translation" }
2609
Linus Torvalds1da177e2005-04-16 15:20:36 -07002610;
2611/*===========================================================================*/
Alexey Dobriyan6b914c52008-04-10 14:34:35 -07002612static int ray_cs_proc_show(struct seq_file *m, void *v)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002613{
2614/* Print current values which are not available via other means
John Daiker141fa612009-03-10 06:59:54 -07002615 * eg ifconfig
Linus Torvalds1da177e2005-04-16 15:20:36 -07002616 */
John Daiker141fa612009-03-10 06:59:54 -07002617 int i;
2618 struct pcmcia_device *link;
2619 struct net_device *dev;
2620 ray_dev_t *local;
2621 UCHAR *p;
2622 struct freq_hop_element *pfh;
2623 UCHAR c[33];
Linus Torvalds1da177e2005-04-16 15:20:36 -07002624
John Daiker141fa612009-03-10 06:59:54 -07002625 link = this_device;
2626 if (!link)
2627 return 0;
2628 dev = (struct net_device *)link->priv;
2629 if (!dev)
2630 return 0;
2631 local = netdev_priv(dev);
2632 if (!local)
2633 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002634
John Daiker141fa612009-03-10 06:59:54 -07002635 seq_puts(m, "Raylink Wireless LAN driver status\n");
2636 seq_printf(m, "%s\n", rcsid);
2637 /* build 4 does not report version, and field is 0x55 after memtest */
2638 seq_puts(m, "Firmware version = ");
2639 if (local->fw_ver == 0x55)
2640 seq_puts(m, "4 - Use dump_cis for more details\n");
2641 else
2642 seq_printf(m, "%2d.%02d.%02d\n",
2643 local->fw_ver, local->fw_bld, local->fw_var);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002644
John Daiker141fa612009-03-10 06:59:54 -07002645 for (i = 0; i < 32; i++)
2646 c[i] = local->sparm.b5.a_current_ess_id[i];
2647 c[32] = 0;
2648 seq_printf(m, "%s network ESSID = \"%s\"\n",
2649 nettype[local->sparm.b5.a_network_type], c);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002650
John Daiker141fa612009-03-10 06:59:54 -07002651 p = local->bss_id;
2652 seq_printf(m, "BSSID = %pM\n", p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002653
John Daiker141fa612009-03-10 06:59:54 -07002654 seq_printf(m, "Country code = %d\n",
2655 local->sparm.b5.a_curr_country_code);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002656
John Daiker141fa612009-03-10 06:59:54 -07002657 i = local->card_status;
2658 if (i < 0)
2659 i = 10;
2660 if (i > 16)
2661 i = 10;
2662 seq_printf(m, "Card status = %s\n", card_status[i]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002663
John Daiker141fa612009-03-10 06:59:54 -07002664 seq_printf(m, "Framing mode = %s\n", framing[translate]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002665
John Daiker141fa612009-03-10 06:59:54 -07002666 seq_printf(m, "Last pkt signal lvl = %d\n", local->last_rsl);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002667
John Daiker141fa612009-03-10 06:59:54 -07002668 if (local->beacon_rxed) {
2669 /* Pull some fields out of last beacon received */
2670 seq_printf(m, "Beacon Interval = %d Kus\n",
2671 local->last_bcn.beacon_intvl[0]
2672 + 256 * local->last_bcn.beacon_intvl[1]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002673
John Daiker141fa612009-03-10 06:59:54 -07002674 p = local->last_bcn.elements;
2675 if (p[0] == C_ESSID_ELEMENT_ID)
2676 p += p[1] + 2;
2677 else {
2678 seq_printf(m,
2679 "Parse beacon failed at essid element id = %d\n",
2680 p[0]);
2681 return 0;
2682 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002683
John Daiker141fa612009-03-10 06:59:54 -07002684 if (p[0] == C_SUPPORTED_RATES_ELEMENT_ID) {
2685 seq_puts(m, "Supported rate codes = ");
2686 for (i = 2; i < p[1] + 2; i++)
2687 seq_printf(m, "0x%02x ", p[i]);
2688 seq_putc(m, '\n');
2689 p += p[1] + 2;
2690 } else {
2691 seq_puts(m, "Parse beacon failed at rates element\n");
2692 return 0;
2693 }
2694
2695 if (p[0] == C_FH_PARAM_SET_ELEMENT_ID) {
2696 pfh = (struct freq_hop_element *)p;
2697 seq_printf(m, "Hop dwell = %d Kus\n",
2698 pfh->dwell_time[0] +
2699 256 * pfh->dwell_time[1]);
Frans Popcb01b092010-03-24 19:46:34 +01002700 seq_printf(m, "Hop set = %d\n",
John Daiker141fa612009-03-10 06:59:54 -07002701 pfh->hop_set);
Frans Popcb01b092010-03-24 19:46:34 +01002702 seq_printf(m, "Hop pattern = %d\n",
John Daiker141fa612009-03-10 06:59:54 -07002703 pfh->hop_pattern);
Frans Popcb01b092010-03-24 19:46:34 +01002704 seq_printf(m, "Hop index = %d\n",
John Daiker141fa612009-03-10 06:59:54 -07002705 pfh->hop_index);
2706 p += p[1] + 2;
2707 } else {
2708 seq_puts(m,
2709 "Parse beacon failed at FH param element\n");
2710 return 0;
2711 }
2712 } else {
2713 seq_puts(m, "No beacons received\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002714 }
John Daiker141fa612009-03-10 06:59:54 -07002715 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002716}
2717
Alexey Dobriyan6b914c52008-04-10 14:34:35 -07002718static int ray_cs_proc_open(struct inode *inode, struct file *file)
2719{
2720 return single_open(file, ray_cs_proc_show, NULL);
2721}
2722
2723static const struct file_operations ray_cs_proc_fops = {
John Daiker141fa612009-03-10 06:59:54 -07002724 .owner = THIS_MODULE,
2725 .open = ray_cs_proc_open,
2726 .read = seq_read,
2727 .llseek = seq_lseek,
2728 .release = single_release,
Alexey Dobriyan6b914c52008-04-10 14:34:35 -07002729};
Linus Torvalds1da177e2005-04-16 15:20:36 -07002730#endif
2731/*===========================================================================*/
2732static int build_auth_frame(ray_dev_t *local, UCHAR *dest, int auth_type)
2733{
John Daiker141fa612009-03-10 06:59:54 -07002734 int addr;
2735 struct ccs __iomem *pccs;
2736 struct tx_msg __iomem *ptx;
2737 int ccsindex;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002738
John Daiker141fa612009-03-10 06:59:54 -07002739 /* If no tx buffers available, return */
2740 if ((ccsindex = get_free_tx_ccs(local)) < 0) {
Dominik Brodowski624dd662009-10-24 15:52:44 +02002741 pr_debug("ray_cs send authenticate - No free tx ccs\n");
John Daiker141fa612009-03-10 06:59:54 -07002742 return -1;
2743 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002744
John Daiker141fa612009-03-10 06:59:54 -07002745 pccs = ccs_base(local) + ccsindex;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002746
John Daiker141fa612009-03-10 06:59:54 -07002747 /* Address in card space */
2748 addr = TX_BUF_BASE + (ccsindex << 11);
2749 /* fill in the CCS */
2750 writeb(CCS_TX_REQUEST, &pccs->cmd);
2751 writeb(addr >> 8, pccs->var.tx_request.tx_data_ptr);
2752 writeb(0x20, pccs->var.tx_request.tx_data_ptr + 1);
2753 writeb(TX_AUTHENTICATE_LENGTH_MSB, pccs->var.tx_request.tx_data_length);
2754 writeb(TX_AUTHENTICATE_LENGTH_LSB,
2755 pccs->var.tx_request.tx_data_length + 1);
2756 writeb(0, &pccs->var.tx_request.pow_sav_mode);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002757
John Daiker141fa612009-03-10 06:59:54 -07002758 ptx = local->sram + addr;
2759 /* fill in the mac header */
2760 writeb(PROTOCOL_VER | AUTHENTIC_TYPE, &ptx->mac.frame_ctl_1);
2761 writeb(0, &ptx->mac.frame_ctl_2);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002762
John Daiker141fa612009-03-10 06:59:54 -07002763 memcpy_toio(ptx->mac.addr_1, dest, ADDRLEN);
2764 memcpy_toio(ptx->mac.addr_2, local->sparm.b4.a_mac_addr, ADDRLEN);
2765 memcpy_toio(ptx->mac.addr_3, local->bss_id, ADDRLEN);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002766
John Daiker141fa612009-03-10 06:59:54 -07002767 /* Fill in msg body with protocol 00 00, sequence 01 00 ,status 00 00 */
2768 memset_io(ptx->var, 0, 6);
2769 writeb(auth_type & 0xff, ptx->var + 2);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002770
John Daiker141fa612009-03-10 06:59:54 -07002771 /* Interrupt the firmware to process the command */
2772 if (interrupt_ecf(local, ccsindex)) {
Dominik Brodowski624dd662009-10-24 15:52:44 +02002773 pr_debug(
John Daiker141fa612009-03-10 06:59:54 -07002774 "ray_cs send authentication request failed - ECF not ready for intr\n");
2775 writeb(CCS_BUFFER_FREE, &(pccs++)->buffer_status);
2776 return -1;
2777 }
2778 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002779} /* End build_auth_frame */
2780
2781/*===========================================================================*/
2782#ifdef CONFIG_PROC_FS
Alexey Dobriyan83daee02009-11-25 10:12:20 +03002783static ssize_t ray_cs_essid_proc_write(struct file *file,
2784 const char __user *buffer, size_t count, loff_t *pos)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002785{
2786 static char proc_essid[33];
Alan Cox575c9ed2009-10-27 15:35:55 +00002787 unsigned int len = count;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002788
2789 if (len > 32)
2790 len = 32;
2791 memset(proc_essid, 0, 33);
2792 if (copy_from_user(proc_essid, buffer, len))
2793 return -EFAULT;
2794 essid = proc_essid;
2795 return count;
2796}
2797
Alexey Dobriyan83daee02009-11-25 10:12:20 +03002798static const struct file_operations ray_cs_essid_proc_fops = {
2799 .owner = THIS_MODULE,
2800 .write = ray_cs_essid_proc_write,
2801};
2802
2803static ssize_t int_proc_write(struct file *file, const char __user *buffer,
2804 size_t count, loff_t *pos)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002805{
2806 static char proc_number[10];
2807 char *p;
2808 int nr, len;
2809
2810 if (!count)
2811 return 0;
2812
2813 if (count > 9)
2814 return -EINVAL;
2815 if (copy_from_user(proc_number, buffer, count))
2816 return -EFAULT;
2817 p = proc_number;
2818 nr = 0;
2819 len = count;
2820 do {
2821 unsigned int c = *p - '0';
2822 if (c > 9)
2823 return -EINVAL;
John Daiker141fa612009-03-10 06:59:54 -07002824 nr = nr * 10 + c;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002825 p++;
2826 } while (--len);
Alexey Dobriyan83daee02009-11-25 10:12:20 +03002827 *(int *)PDE(file->f_path.dentry->d_inode)->data = nr;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002828 return count;
2829}
Alexey Dobriyan83daee02009-11-25 10:12:20 +03002830
2831static const struct file_operations int_proc_fops = {
2832 .owner = THIS_MODULE,
2833 .write = int_proc_write,
2834};
Linus Torvalds1da177e2005-04-16 15:20:36 -07002835#endif
2836
Dominik Brodowskif57ea2a2005-06-27 16:28:24 -07002837static struct pcmcia_device_id ray_ids[] = {
2838 PCMCIA_DEVICE_MANF_CARD(0x01a6, 0x0000),
2839 PCMCIA_DEVICE_NULL,
2840};
John Daiker141fa612009-03-10 06:59:54 -07002841
Dominik Brodowskif57ea2a2005-06-27 16:28:24 -07002842MODULE_DEVICE_TABLE(pcmcia, ray_ids);
2843
Linus Torvalds1da177e2005-04-16 15:20:36 -07002844static struct pcmcia_driver ray_driver = {
John Daiker141fa612009-03-10 06:59:54 -07002845 .owner = THIS_MODULE,
2846 .drv = {
2847 .name = "ray_cs",
2848 },
2849 .probe = ray_probe,
2850 .remove = ray_detach,
2851 .id_table = ray_ids,
2852 .suspend = ray_suspend,
2853 .resume = ray_resume,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002854};
2855
2856static int __init init_ray_cs(void)
2857{
John Daiker141fa612009-03-10 06:59:54 -07002858 int rc;
2859
Dominik Brodowski624dd662009-10-24 15:52:44 +02002860 pr_debug("%s\n", rcsid);
John Daiker141fa612009-03-10 06:59:54 -07002861 rc = pcmcia_register_driver(&ray_driver);
Dominik Brodowski624dd662009-10-24 15:52:44 +02002862 pr_debug("raylink init_module register_pcmcia_driver returns 0x%x\n",
John Daiker141fa612009-03-10 06:59:54 -07002863 rc);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002864
2865#ifdef CONFIG_PROC_FS
John Daiker141fa612009-03-10 06:59:54 -07002866 proc_mkdir("driver/ray_cs", NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002867
John Daiker141fa612009-03-10 06:59:54 -07002868 proc_create("driver/ray_cs/ray_cs", 0, NULL, &ray_cs_proc_fops);
Alexey Dobriyan83daee02009-11-25 10:12:20 +03002869 proc_create("driver/ray_cs/essid", S_IWUSR, NULL, &ray_cs_essid_proc_fops);
2870 proc_create_data("driver/ray_cs/net_type", S_IWUSR, NULL, &int_proc_fops, &net_type);
2871 proc_create_data("driver/ray_cs/translate", S_IWUSR, NULL, &int_proc_fops, &translate);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002872#endif
John Daiker141fa612009-03-10 06:59:54 -07002873 if (translate != 0)
2874 translate = 1;
2875 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002876} /* init_ray_cs */
2877
2878/*===========================================================================*/
2879
2880static void __exit exit_ray_cs(void)
2881{
Dominik Brodowski624dd662009-10-24 15:52:44 +02002882 pr_debug("ray_cs: cleanup_module\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002883
2884#ifdef CONFIG_PROC_FS
John Daiker141fa612009-03-10 06:59:54 -07002885 remove_proc_entry("driver/ray_cs/ray_cs", NULL);
2886 remove_proc_entry("driver/ray_cs/essid", NULL);
2887 remove_proc_entry("driver/ray_cs/net_type", NULL);
2888 remove_proc_entry("driver/ray_cs/translate", NULL);
2889 remove_proc_entry("driver/ray_cs", NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002890#endif
2891
John Daiker141fa612009-03-10 06:59:54 -07002892 pcmcia_unregister_driver(&ray_driver);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002893} /* exit_ray_cs */
2894
2895module_init(init_ray_cs);
2896module_exit(exit_ray_cs);
2897
2898/*===========================================================================*/