blob: a860bce6849b0d4517bcf6d8f4ee57559f5e70f1 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*=============================================================================
2 *
3 * A PCMCIA client driver for the Raylink wireless LAN card.
4 * The starting point for this module was the skeleton.c in the
5 * PCMCIA 2.9.12 package written by David Hinds, dahinds@users.sourceforge.net
6 *
7 *
8 * Copyright (c) 1998 Corey Thomas (corey@world.std.com)
9 *
10 * This driver is free software; you can redistribute it and/or modify
John Daiker141fa612009-03-10 06:59:54 -070011 * it under the terms of version 2 only of the GNU General Public License as
Linus Torvalds1da177e2005-04-16 15:20:36 -070012 * published by the Free Software Foundation.
13 *
14 * It is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
22 *
23 * Changes:
24 * Arnaldo Carvalho de Melo <acme@conectiva.com.br> - 08/08/2000
25 * - reorganize kmallocs in ray_attach, checking all for failure
26 * and releasing the previous allocations if one fails
27 *
28 * Daniele Bellucci <bellucda@tiscali.it> - 07/10/2003
29 * - Audit copy_to_user in ioctl(SIOCGIWESSID)
John Daiker141fa612009-03-10 06:59:54 -070030 *
Linus Torvalds1da177e2005-04-16 15:20:36 -070031=============================================================================*/
32
Linus Torvalds1da177e2005-04-16 15:20:36 -070033#include <linux/module.h>
34#include <linux/kernel.h>
35#include <linux/proc_fs.h>
36#include <linux/ptrace.h>
Alexey Dobriyan6b914c52008-04-10 14:34:35 -070037#include <linux/seq_file.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070038#include <linux/string.h>
39#include <linux/timer.h>
40#include <linux/init.h>
41#include <linux/netdevice.h>
42#include <linux/etherdevice.h>
43#include <linux/if_arp.h>
44#include <linux/ioport.h>
45#include <linux/skbuff.h>
46#include <linux/ethtool.h>
Al Viro7698d692007-12-29 04:55:50 -050047#include <linux/ieee80211.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070048
Linus Torvalds1da177e2005-04-16 15:20:36 -070049#include <pcmcia/cs.h>
50#include <pcmcia/cistpl.h>
51#include <pcmcia/cisreg.h>
52#include <pcmcia/ds.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070053
54#include <linux/wireless.h>
Michael Wu113b8982006-08-13 23:27:17 -070055#include <net/iw_handler.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070056
57#include <asm/io.h>
58#include <asm/system.h>
59#include <asm/byteorder.h>
60#include <asm/uaccess.h>
61
62/* Warning : these stuff will slow down the driver... */
63#define WIRELESS_SPY /* Enable spying addresses */
64/* Definitions we need for spy */
John Daiker141fa612009-03-10 06:59:54 -070065typedef struct iw_statistics iw_stats;
66typedef u_char mac_addr[ETH_ALEN]; /* Hardware address */
Linus Torvalds1da177e2005-04-16 15:20:36 -070067
68#include "rayctl.h"
69#include "ray_cs.h"
70
Linus Torvalds1da177e2005-04-16 15:20:36 -070071
Linus Torvalds1da177e2005-04-16 15:20:36 -070072/** Prototypes based on PCMCIA skeleton driver *******************************/
Dominik Brodowski15b99ac2006-03-31 17:26:06 +020073static int ray_config(struct pcmcia_device *link);
Dominik Brodowskifba395e2006-03-31 17:21:06 +020074static void ray_release(struct pcmcia_device *link);
Dominik Brodowskicc3b4862005-11-14 21:23:14 +010075static void ray_detach(struct pcmcia_device *p_dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -070076
77/***** Prototypes indicated by device structure ******************************/
78static int ray_dev_close(struct net_device *dev);
79static int ray_dev_config(struct net_device *dev, struct ifmap *map);
80static struct net_device_stats *ray_get_stats(struct net_device *dev);
81static int ray_dev_init(struct net_device *dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -070082
Jeff Garzik7282d492006-09-13 14:30:00 -040083static const struct ethtool_ops netdev_ethtool_ops;
Linus Torvalds1da177e2005-04-16 15:20:36 -070084
85static int ray_open(struct net_device *dev);
Stephen Hemmingerd0cf9c02009-08-31 19:50:57 +000086static netdev_tx_t ray_dev_start_xmit(struct sk_buff *skb,
87 struct net_device *dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -070088static void set_multicast_list(struct net_device *dev);
89static void ray_update_multi_list(struct net_device *dev, int all);
90static int translate_frame(ray_dev_t *local, struct tx_msg __iomem *ptx,
John Daiker141fa612009-03-10 06:59:54 -070091 unsigned char *data, int len);
92static void ray_build_header(ray_dev_t *local, struct tx_msg __iomem *ptx,
93 UCHAR msg_type, unsigned char *data);
Linus Torvalds1da177e2005-04-16 15:20:36 -070094static void untranslate(ray_dev_t *local, struct sk_buff *skb, int len);
John Daiker141fa612009-03-10 06:59:54 -070095static iw_stats *ray_get_wireless_stats(struct net_device *dev);
96static const struct iw_handler_def ray_handler_def;
Linus Torvalds1da177e2005-04-16 15:20:36 -070097
98/***** Prototypes for raylink functions **************************************/
99static int asc_to_int(char a);
100static void authenticate(ray_dev_t *local);
101static int build_auth_frame(ray_dev_t *local, UCHAR *dest, int auth_type);
102static void authenticate_timeout(u_long);
103static int get_free_ccs(ray_dev_t *local);
104static int get_free_tx_ccs(ray_dev_t *local);
105static void init_startup_params(ray_dev_t *local);
106static int parse_addr(char *in_str, UCHAR *out);
John Daiker141fa612009-03-10 06:59:54 -0700107static int ray_hw_xmit(unsigned char *data, int len, struct net_device *dev, UCHAR type);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700108static int ray_init(struct net_device *dev);
109static int interrupt_ecf(ray_dev_t *local, int ccs);
110static void ray_reset(struct net_device *dev);
111static void ray_update_parm(struct net_device *dev, UCHAR objid, UCHAR *value, int len);
112static void verify_dl_startup(u_long);
113
114/* Prototypes for interrpt time functions **********************************/
John Daiker141fa612009-03-10 06:59:54 -0700115static irqreturn_t ray_interrupt(int reg, void *dev_id);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700116static void clear_interrupt(ray_dev_t *local);
John Daiker141fa612009-03-10 06:59:54 -0700117static void rx_deauthenticate(ray_dev_t *local, struct rcs __iomem *prcs,
118 unsigned int pkt_addr, int rx_len);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700119static int copy_from_rx_buff(ray_dev_t *local, UCHAR *dest, int pkt_addr, int len);
120static void ray_rx(struct net_device *dev, ray_dev_t *local, struct rcs __iomem *prcs);
121static void release_frag_chain(ray_dev_t *local, struct rcs __iomem *prcs);
122static void rx_authenticate(ray_dev_t *local, struct rcs __iomem *prcs,
John Daiker141fa612009-03-10 06:59:54 -0700123 unsigned int pkt_addr, int rx_len);
124static void rx_data(struct net_device *dev, struct rcs __iomem *prcs,
125 unsigned int pkt_addr, int rx_len);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700126static void associate(ray_dev_t *local);
127
128/* Card command functions */
129static int dl_startup_params(struct net_device *dev);
130static void join_net(u_long local);
131static void start_net(u_long local);
132/* void start_net(ray_dev_t *local); */
133
134/*===========================================================================*/
135/* Parameters that can be set with 'insmod' */
136
137/* ADHOC=0, Infrastructure=1 */
138static int net_type = ADHOC;
139
140/* Hop dwell time in Kus (1024 us units defined by 802.11) */
141static int hop_dwell = 128;
142
143/* Beacon period in Kus */
144static int beacon_period = 256;
145
146/* power save mode (0 = off, 1 = save power) */
147static int psm;
148
149/* String for network's Extended Service Set ID. 32 Characters max */
150static char *essid;
151
152/* Default to encapsulation unless translation requested */
153static int translate = 1;
154
155static int country = USA;
156
157static int sniffer;
158
159static int bc;
160
161/* 48 bit physical card address if overriding card's real physical
162 * address is required. Since IEEE 802.11 addresses are 48 bits
163 * like ethernet, an int can't be used, so a string is used. To
164 * allow use of addresses starting with a decimal digit, the first
165 * character must be a letter and will be ignored. This letter is
166 * followed by up to 12 hex digits which are the address. If less
167 * than 12 digits are used, the address will be left filled with 0's.
168 * Note that bit 0 of the first byte is the broadcast bit, and evil
169 * things will happen if it is not 0 in a card address.
170 */
171static char *phy_addr = NULL;
172
173
Dominik Brodowskifba395e2006-03-31 17:21:06 +0200174/* A struct pcmcia_device structure has fields for most things that are needed
Linus Torvalds1da177e2005-04-16 15:20:36 -0700175 to keep track of a socket, but there will usually be some device
176 specific information that also needs to be kept track of. The
Dominik Brodowskifba395e2006-03-31 17:21:06 +0200177 'priv' pointer in a struct pcmcia_device structure can be used to point to
Linus Torvalds1da177e2005-04-16 15:20:36 -0700178 a device-specific private data structure, like this.
179*/
180static unsigned int ray_mem_speed = 500;
181
Dominik Brodowskifd238232006-03-05 10:45:09 +0100182/* WARNING: THIS DRIVER IS NOT CAPABLE OF HANDLING MULTIPLE DEVICES! */
183static struct pcmcia_device *this_device = NULL;
184
Linus Torvalds1da177e2005-04-16 15:20:36 -0700185MODULE_AUTHOR("Corey Thomas <corey@world.std.com>");
186MODULE_DESCRIPTION("Raylink/WebGear wireless LAN driver");
187MODULE_LICENSE("GPL");
188
189module_param(net_type, int, 0);
190module_param(hop_dwell, int, 0);
191module_param(beacon_period, int, 0);
192module_param(psm, int, 0);
193module_param(essid, charp, 0);
194module_param(translate, int, 0);
195module_param(country, int, 0);
196module_param(sniffer, int, 0);
197module_param(bc, int, 0);
198module_param(phy_addr, charp, 0);
199module_param(ray_mem_speed, int, 0);
200
201static UCHAR b5_default_startup_parms[] = {
John Daiker141fa612009-03-10 06:59:54 -0700202 0, 0, /* Adhoc station */
203 'L', 'I', 'N', 'U', 'X', 0, 0, 0, /* 32 char ESSID */
204 0, 0, 0, 0, 0, 0, 0, 0,
205 0, 0, 0, 0, 0, 0, 0, 0,
206 0, 0, 0, 0, 0, 0, 0, 0,
207 1, 0, /* Active scan, CA Mode */
208 0, 0, 0, 0, 0, 0, /* No default MAC addr */
209 0x7f, 0xff, /* Frag threshold */
210 0x00, 0x80, /* Hop time 128 Kus */
211 0x01, 0x00, /* Beacon period 256 Kus */
212 0x01, 0x07, 0xa3, /* DTIM, retries, ack timeout */
213 0x1d, 0x82, 0x4e, /* SIFS, DIFS, PIFS */
214 0x7f, 0xff, /* RTS threshold */
215 0x04, 0xe2, 0x38, 0xA4, /* scan_dwell, max_scan_dwell */
216 0x05, /* assoc resp timeout thresh */
217 0x08, 0x02, 0x08, /* adhoc, infra, super cycle max */
218 0, /* Promiscuous mode */
219 0x0c, 0x0bd, /* Unique word */
220 0x32, /* Slot time */
221 0xff, 0xff, /* roam-low snr, low snr count */
222 0x05, 0xff, /* Infra, adhoc missed bcn thresh */
223 0x01, 0x0b, 0x4f, /* USA, hop pattern, hop pat length */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700224/* b4 - b5 differences start here */
John Daiker141fa612009-03-10 06:59:54 -0700225 0x00, 0x3f, /* CW max */
226 0x00, 0x0f, /* CW min */
227 0x04, 0x08, /* Noise gain, limit offset */
228 0x28, 0x28, /* det rssi, med busy offsets */
229 7, /* det sync thresh */
230 0, 2, 2, /* test mode, min, max */
231 0, /* allow broadcast SSID probe resp */
232 0, 0, /* privacy must start, can join */
233 2, 0, 0, 0, 0, 0, 0, 0 /* basic rate set */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700234};
235
236static UCHAR b4_default_startup_parms[] = {
John Daiker141fa612009-03-10 06:59:54 -0700237 0, 0, /* Adhoc station */
238 'L', 'I', 'N', 'U', 'X', 0, 0, 0, /* 32 char ESSID */
239 0, 0, 0, 0, 0, 0, 0, 0,
240 0, 0, 0, 0, 0, 0, 0, 0,
241 0, 0, 0, 0, 0, 0, 0, 0,
242 1, 0, /* Active scan, CA Mode */
243 0, 0, 0, 0, 0, 0, /* No default MAC addr */
244 0x7f, 0xff, /* Frag threshold */
245 0x02, 0x00, /* Hop time */
246 0x00, 0x01, /* Beacon period */
247 0x01, 0x07, 0xa3, /* DTIM, retries, ack timeout */
248 0x1d, 0x82, 0xce, /* SIFS, DIFS, PIFS */
249 0x7f, 0xff, /* RTS threshold */
250 0xfb, 0x1e, 0xc7, 0x5c, /* scan_dwell, max_scan_dwell */
251 0x05, /* assoc resp timeout thresh */
252 0x04, 0x02, 0x4, /* adhoc, infra, super cycle max */
253 0, /* Promiscuous mode */
254 0x0c, 0x0bd, /* Unique word */
255 0x4e, /* Slot time (TBD seems wrong) */
256 0xff, 0xff, /* roam-low snr, low snr count */
257 0x05, 0xff, /* Infra, adhoc missed bcn thresh */
258 0x01, 0x0b, 0x4e, /* USA, hop pattern, hop pat length */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700259/* b4 - b5 differences start here */
John Daiker141fa612009-03-10 06:59:54 -0700260 0x3f, 0x0f, /* CW max, min */
261 0x04, 0x08, /* Noise gain, limit offset */
262 0x28, 0x28, /* det rssi, med busy offsets */
263 7, /* det sync thresh */
264 0, 2, 2 /* test mode, min, max */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700265};
John Daiker141fa612009-03-10 06:59:54 -0700266
Linus Torvalds1da177e2005-04-16 15:20:36 -0700267/*===========================================================================*/
John Daiker141fa612009-03-10 06:59:54 -0700268static unsigned char eth2_llc[] = { 0xaa, 0xaa, 3, 0, 0, 0 };
Linus Torvalds1da177e2005-04-16 15:20:36 -0700269
270static char hop_pattern_length[] = { 1,
John Daiker141fa612009-03-10 06:59:54 -0700271 USA_HOP_MOD, EUROPE_HOP_MOD,
272 JAPAN_HOP_MOD, KOREA_HOP_MOD,
273 SPAIN_HOP_MOD, FRANCE_HOP_MOD,
274 ISRAEL_HOP_MOD, AUSTRALIA_HOP_MOD,
275 JAPAN_TEST_HOP_MOD
Linus Torvalds1da177e2005-04-16 15:20:36 -0700276};
277
John Daiker141fa612009-03-10 06:59:54 -0700278static char rcsid[] =
279 "Raylink/WebGear wireless LAN - Corey <Thomas corey@world.std.com>";
Linus Torvalds1da177e2005-04-16 15:20:36 -0700280
Stephen Hemminger32f5a332009-03-20 19:36:28 +0000281static const struct net_device_ops ray_netdev_ops = {
282 .ndo_init = ray_dev_init,
283 .ndo_open = ray_open,
284 .ndo_stop = ray_dev_close,
285 .ndo_start_xmit = ray_dev_start_xmit,
286 .ndo_set_config = ray_dev_config,
287 .ndo_get_stats = ray_get_stats,
288 .ndo_set_multicast_list = set_multicast_list,
289 .ndo_change_mtu = eth_change_mtu,
290 .ndo_set_mac_address = eth_mac_addr,
291 .ndo_validate_addr = eth_validate_addr,
292};
293
Linus Torvalds1da177e2005-04-16 15:20:36 -0700294/*=============================================================================
295 ray_attach() creates an "instance" of the driver, allocating
296 local data structures for one device. The device is registered
297 with Card Services.
298 The dev_link structure is initialized, but we don't actually
299 configure the card at this point -- we wait until we receive a
300 card insertion event.
301=============================================================================*/
Dominik Brodowski15b99ac2006-03-31 17:26:06 +0200302static int ray_probe(struct pcmcia_device *p_dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700303{
John Daiker141fa612009-03-10 06:59:54 -0700304 ray_dev_t *local;
305 struct net_device *dev;
Dominik Brodowskifd238232006-03-05 10:45:09 +0100306
Dominik Brodowski624dd662009-10-24 15:52:44 +0200307 dev_dbg(&p_dev->dev, "ray_attach()\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700308
John Daiker141fa612009-03-10 06:59:54 -0700309 /* Allocate space for private device-specific data */
310 dev = alloc_etherdev(sizeof(ray_dev_t));
311 if (!dev)
312 goto fail_alloc_dev;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700313
John Daiker141fa612009-03-10 06:59:54 -0700314 local = netdev_priv(dev);
315 local->finder = p_dev;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700316
John Daiker141fa612009-03-10 06:59:54 -0700317 /* The io structure describes IO port mapping. None used here */
Dominik Brodowski90abdc32010-07-24 17:23:51 +0200318 p_dev->resource[0]->end = 0;
319 p_dev->resource[0]->flags |= IO_DATA_PATH_WIDTH_8;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700320
John Daiker141fa612009-03-10 06:59:54 -0700321 /* General socket configuration */
322 p_dev->conf.Attributes = CONF_ENABLE_IRQ;
323 p_dev->conf.IntType = INT_MEMORY_AND_IO;
324 p_dev->conf.ConfigIndex = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700325
John Daiker141fa612009-03-10 06:59:54 -0700326 p_dev->priv = dev;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700327
John Daiker141fa612009-03-10 06:59:54 -0700328 local->finder = p_dev;
329 local->card_status = CARD_INSERTED;
330 local->authentication_state = UNAUTHENTICATED;
331 local->num_multi = 0;
Dominik Brodowski624dd662009-10-24 15:52:44 +0200332 dev_dbg(&p_dev->dev, "ray_attach p_dev = %p, dev = %p, local = %p, intr = %p\n",
John Daiker141fa612009-03-10 06:59:54 -0700333 p_dev, dev, local, &ray_interrupt);
334
335 /* Raylink entries in the device structure */
Stephen Hemminger32f5a332009-03-20 19:36:28 +0000336 dev->netdev_ops = &ray_netdev_ops;
John Daiker141fa612009-03-10 06:59:54 -0700337 SET_ETHTOOL_OPS(dev, &netdev_ethtool_ops);
338 dev->wireless_handlers = &ray_handler_def;
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -0700339#ifdef WIRELESS_SPY
John Daiker141fa612009-03-10 06:59:54 -0700340 local->wireless_data.spy_data = &local->spy_data;
341 dev->wireless_data = &local->wireless_data;
342#endif /* WIRELESS_SPY */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700343
Linus Torvalds1da177e2005-04-16 15:20:36 -0700344
Dominik Brodowski624dd662009-10-24 15:52:44 +0200345 dev_dbg(&p_dev->dev, "ray_cs ray_attach calling ether_setup.)\n");
John Daiker141fa612009-03-10 06:59:54 -0700346 netif_stop_queue(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700347
John Daiker141fa612009-03-10 06:59:54 -0700348 init_timer(&local->timer);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700349
John Daiker141fa612009-03-10 06:59:54 -0700350 this_device = p_dev;
351 return ray_config(p_dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700352
353fail_alloc_dev:
John Daiker141fa612009-03-10 06:59:54 -0700354 return -ENOMEM;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700355} /* ray_attach */
John Daiker141fa612009-03-10 06:59:54 -0700356
Linus Torvalds1da177e2005-04-16 15:20:36 -0700357/*=============================================================================
358 This deletes a driver "instance". The device is de-registered
359 with Card Services. If it has been released, all local data
360 structures are freed. Otherwise, the structures will be freed
361 when the device is released.
362=============================================================================*/
Dominik Brodowskifba395e2006-03-31 17:21:06 +0200363static void ray_detach(struct pcmcia_device *link)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700364{
John Daiker141fa612009-03-10 06:59:54 -0700365 struct net_device *dev;
366 ray_dev_t *local;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700367
Dominik Brodowski624dd662009-10-24 15:52:44 +0200368 dev_dbg(&link->dev, "ray_detach\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700369
John Daiker141fa612009-03-10 06:59:54 -0700370 this_device = NULL;
371 dev = link->priv;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700372
John Daiker141fa612009-03-10 06:59:54 -0700373 ray_release(link);
Dominik Brodowskicc3b4862005-11-14 21:23:14 +0100374
John Daiker141fa612009-03-10 06:59:54 -0700375 local = netdev_priv(dev);
376 del_timer(&local->timer);
Dominik Brodowskicc3b4862005-11-14 21:23:14 +0100377
John Daiker141fa612009-03-10 06:59:54 -0700378 if (link->priv) {
Dominik Brodowskic7c2fa02010-03-20 19:39:26 +0100379 unregister_netdev(dev);
John Daiker141fa612009-03-10 06:59:54 -0700380 free_netdev(dev);
381 }
Dominik Brodowski624dd662009-10-24 15:52:44 +0200382 dev_dbg(&link->dev, "ray_cs ray_detach ending\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700383} /* ray_detach */
John Daiker141fa612009-03-10 06:59:54 -0700384
Linus Torvalds1da177e2005-04-16 15:20:36 -0700385/*=============================================================================
386 ray_config() is run after a CARD_INSERTION event
387 is received, to configure the PCMCIA socket, and to make the
388 ethernet device available to the system.
389=============================================================================*/
Linus Torvalds1da177e2005-04-16 15:20:36 -0700390#define MAX_TUPLE_SIZE 128
Dominik Brodowski15b99ac2006-03-31 17:26:06 +0200391static int ray_config(struct pcmcia_device *link)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700392{
Dominik Brodowski624dd662009-10-24 15:52:44 +0200393 int ret = 0;
John Daiker141fa612009-03-10 06:59:54 -0700394 int i;
395 win_req_t req;
John Daiker141fa612009-03-10 06:59:54 -0700396 struct net_device *dev = (struct net_device *)link->priv;
397 ray_dev_t *local = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700398
Dominik Brodowski624dd662009-10-24 15:52:44 +0200399 dev_dbg(&link->dev, "ray_config\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700400
John Daiker141fa612009-03-10 06:59:54 -0700401 /* Determine card type and firmware version */
402 printk(KERN_INFO "ray_cs Detected: %s%s%s%s\n",
403 link->prod_id[0] ? link->prod_id[0] : " ",
404 link->prod_id[1] ? link->prod_id[1] : " ",
405 link->prod_id[2] ? link->prod_id[2] : " ",
406 link->prod_id[3] ? link->prod_id[3] : " ");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700407
John Daiker141fa612009-03-10 06:59:54 -0700408 /* Now allocate an interrupt line. Note that this does not
409 actually assign a handler to the interrupt.
410 */
Dominik Brodowskieb141202010-03-07 12:21:16 +0100411 ret = pcmcia_request_irq(link, ray_interrupt);
Dominik Brodowski624dd662009-10-24 15:52:44 +0200412 if (ret)
413 goto failed;
Dominik Brodowskieb141202010-03-07 12:21:16 +0100414 dev->irq = link->irq;
John Daiker141fa612009-03-10 06:59:54 -0700415
416 /* This actually configures the PCMCIA socket -- setting up
417 the I/O windows and the interrupt mapping.
418 */
Dominik Brodowski624dd662009-10-24 15:52:44 +0200419 ret = pcmcia_request_configuration(link, &link->conf);
420 if (ret)
421 goto failed;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700422
423/*** Set up 32k window for shared memory (transmit and control) ************/
John Daiker141fa612009-03-10 06:59:54 -0700424 req.Attributes =
425 WIN_DATA_WIDTH_8 | WIN_MEMORY_TYPE_CM | WIN_ENABLE | WIN_USE_WAIT;
426 req.Base = 0;
427 req.Size = 0x8000;
428 req.AccessSpeed = ray_mem_speed;
Dominik Brodowski6838b032009-11-03 01:31:52 +0100429 ret = pcmcia_request_window(link, &req, &link->win);
Dominik Brodowski624dd662009-10-24 15:52:44 +0200430 if (ret)
431 goto failed;
Dominik Brodowskib5cb2592010-07-24 18:46:42 +0200432 ret = pcmcia_map_mem_page(link, link->win, 0);
Dominik Brodowski624dd662009-10-24 15:52:44 +0200433 if (ret)
434 goto failed;
John Daiker141fa612009-03-10 06:59:54 -0700435 local->sram = ioremap(req.Base, req.Size);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700436
437/*** Set up 16k window for shared memory (receive buffer) ***************/
John Daiker141fa612009-03-10 06:59:54 -0700438 req.Attributes =
439 WIN_DATA_WIDTH_8 | WIN_MEMORY_TYPE_CM | WIN_ENABLE | WIN_USE_WAIT;
440 req.Base = 0;
441 req.Size = 0x4000;
442 req.AccessSpeed = ray_mem_speed;
Dominik Brodowski6838b032009-11-03 01:31:52 +0100443 ret = pcmcia_request_window(link, &req, &local->rmem_handle);
Dominik Brodowski624dd662009-10-24 15:52:44 +0200444 if (ret)
445 goto failed;
Dominik Brodowskib5cb2592010-07-24 18:46:42 +0200446 ret = pcmcia_map_mem_page(link, local->rmem_handle, 0x8000);
Dominik Brodowski624dd662009-10-24 15:52:44 +0200447 if (ret)
448 goto failed;
John Daiker141fa612009-03-10 06:59:54 -0700449 local->rmem = ioremap(req.Base, req.Size);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700450
451/*** Set up window for attribute memory ***********************************/
John Daiker141fa612009-03-10 06:59:54 -0700452 req.Attributes =
453 WIN_DATA_WIDTH_8 | WIN_MEMORY_TYPE_AM | WIN_ENABLE | WIN_USE_WAIT;
454 req.Base = 0;
455 req.Size = 0x1000;
456 req.AccessSpeed = ray_mem_speed;
Dominik Brodowski6838b032009-11-03 01:31:52 +0100457 ret = pcmcia_request_window(link, &req, &local->amem_handle);
Dominik Brodowski624dd662009-10-24 15:52:44 +0200458 if (ret)
459 goto failed;
Dominik Brodowskib5cb2592010-07-24 18:46:42 +0200460 ret = pcmcia_map_mem_page(link, local->amem_handle, 0);
Dominik Brodowski624dd662009-10-24 15:52:44 +0200461 if (ret)
462 goto failed;
John Daiker141fa612009-03-10 06:59:54 -0700463 local->amem = ioremap(req.Base, req.Size);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700464
Dominik Brodowski624dd662009-10-24 15:52:44 +0200465 dev_dbg(&link->dev, "ray_config sram=%p\n", local->sram);
466 dev_dbg(&link->dev, "ray_config rmem=%p\n", local->rmem);
467 dev_dbg(&link->dev, "ray_config amem=%p\n", local->amem);
John Daiker141fa612009-03-10 06:59:54 -0700468 if (ray_init(dev) < 0) {
469 ray_release(link);
470 return -ENODEV;
471 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700472
Dominik Brodowskidd2e5a12009-11-03 10:27:34 +0100473 SET_NETDEV_DEV(dev, &link->dev);
John Daiker141fa612009-03-10 06:59:54 -0700474 i = register_netdev(dev);
475 if (i != 0) {
476 printk("ray_config register_netdev() failed\n");
477 ray_release(link);
478 return i;
479 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700480
John Daiker141fa612009-03-10 06:59:54 -0700481 printk(KERN_INFO "%s: RayLink, irq %d, hw_addr %pM\n",
482 dev->name, dev->irq, dev->dev_addr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700483
John Daiker141fa612009-03-10 06:59:54 -0700484 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700485
Dominik Brodowski624dd662009-10-24 15:52:44 +0200486failed:
John Daiker141fa612009-03-10 06:59:54 -0700487 ray_release(link);
488 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700489} /* ray_config */
490
491static inline struct ccs __iomem *ccs_base(ray_dev_t *dev)
492{
493 return dev->sram + CCS_BASE;
494}
495
496static inline struct rcs __iomem *rcs_base(ray_dev_t *dev)
497{
498 /*
499 * This looks nonsensical, since there is a separate
500 * RCS_BASE. But the difference between a "struct rcs"
501 * and a "struct ccs" ends up being in the _index_ off
502 * the base, so the base pointer is the same for both
503 * ccs/rcs.
504 */
505 return dev->sram + CCS_BASE;
506}
507
508/*===========================================================================*/
509static int ray_init(struct net_device *dev)
510{
John Daiker141fa612009-03-10 06:59:54 -0700511 int i;
512 UCHAR *p;
513 struct ccs __iomem *pccs;
514 ray_dev_t *local = netdev_priv(dev);
515 struct pcmcia_device *link = local->finder;
Dominik Brodowski624dd662009-10-24 15:52:44 +0200516 dev_dbg(&link->dev, "ray_init(0x%p)\n", dev);
John Daiker141fa612009-03-10 06:59:54 -0700517 if (!(pcmcia_dev_present(link))) {
Dominik Brodowski624dd662009-10-24 15:52:44 +0200518 dev_dbg(&link->dev, "ray_init - device not present\n");
John Daiker141fa612009-03-10 06:59:54 -0700519 return -1;
520 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700521
John Daiker141fa612009-03-10 06:59:54 -0700522 local->net_type = net_type;
523 local->sta_type = TYPE_STA;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700524
John Daiker141fa612009-03-10 06:59:54 -0700525 /* Copy the startup results to local memory */
526 memcpy_fromio(&local->startup_res, local->sram + ECF_TO_HOST_BASE,
527 sizeof(struct startup_res_6));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700528
John Daiker141fa612009-03-10 06:59:54 -0700529 /* Check Power up test status and get mac address from card */
530 if (local->startup_res.startup_word != 0x80) {
531 printk(KERN_INFO "ray_init ERROR card status = %2x\n",
532 local->startup_res.startup_word);
533 local->card_status = CARD_INIT_ERROR;
534 return -1;
535 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700536
John Daiker141fa612009-03-10 06:59:54 -0700537 local->fw_ver = local->startup_res.firmware_version[0];
538 local->fw_bld = local->startup_res.firmware_version[1];
539 local->fw_var = local->startup_res.firmware_version[2];
Frans Popcb01b092010-03-24 19:46:34 +0100540 dev_dbg(&link->dev, "ray_init firmware version %d.%d\n", local->fw_ver,
John Daiker141fa612009-03-10 06:59:54 -0700541 local->fw_bld);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700542
John Daiker141fa612009-03-10 06:59:54 -0700543 local->tib_length = 0x20;
544 if ((local->fw_ver == 5) && (local->fw_bld >= 30))
545 local->tib_length = local->startup_res.tib_length;
Dominik Brodowski624dd662009-10-24 15:52:44 +0200546 dev_dbg(&link->dev, "ray_init tib_length = 0x%02x\n", local->tib_length);
John Daiker141fa612009-03-10 06:59:54 -0700547 /* Initialize CCS's to buffer free state */
548 pccs = ccs_base(local);
549 for (i = 0; i < NUMBER_OF_CCS; i++) {
550 writeb(CCS_BUFFER_FREE, &(pccs++)->buffer_status);
551 }
552 init_startup_params(local);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700553
John Daiker141fa612009-03-10 06:59:54 -0700554 /* copy mac address to startup parameters */
555 if (parse_addr(phy_addr, local->sparm.b4.a_mac_addr)) {
556 p = local->sparm.b4.a_mac_addr;
557 } else {
558 memcpy(&local->sparm.b4.a_mac_addr,
559 &local->startup_res.station_addr, ADDRLEN);
560 p = local->sparm.b4.a_mac_addr;
561 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700562
John Daiker141fa612009-03-10 06:59:54 -0700563 clear_interrupt(local); /* Clear any interrupt from the card */
564 local->card_status = CARD_AWAITING_PARAM;
Dominik Brodowski624dd662009-10-24 15:52:44 +0200565 dev_dbg(&link->dev, "ray_init ending\n");
John Daiker141fa612009-03-10 06:59:54 -0700566 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700567} /* ray_init */
John Daiker141fa612009-03-10 06:59:54 -0700568
Linus Torvalds1da177e2005-04-16 15:20:36 -0700569/*===========================================================================*/
570/* Download startup parameters to the card and command it to read them */
571static int dl_startup_params(struct net_device *dev)
572{
John Daiker141fa612009-03-10 06:59:54 -0700573 int ccsindex;
574 ray_dev_t *local = netdev_priv(dev);
575 struct ccs __iomem *pccs;
576 struct pcmcia_device *link = local->finder;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700577
Dominik Brodowski624dd662009-10-24 15:52:44 +0200578 dev_dbg(&link->dev, "dl_startup_params entered\n");
John Daiker141fa612009-03-10 06:59:54 -0700579 if (!(pcmcia_dev_present(link))) {
Dominik Brodowski624dd662009-10-24 15:52:44 +0200580 dev_dbg(&link->dev, "ray_cs dl_startup_params - device not present\n");
John Daiker141fa612009-03-10 06:59:54 -0700581 return -1;
582 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700583
John Daiker141fa612009-03-10 06:59:54 -0700584 /* Copy parameters to host to ECF area */
585 if (local->fw_ver == 0x55)
586 memcpy_toio(local->sram + HOST_TO_ECF_BASE, &local->sparm.b4,
587 sizeof(struct b4_startup_params));
588 else
589 memcpy_toio(local->sram + HOST_TO_ECF_BASE, &local->sparm.b5,
590 sizeof(struct b5_startup_params));
591
592 /* Fill in the CCS fields for the ECF */
593 if ((ccsindex = get_free_ccs(local)) < 0)
594 return -1;
595 local->dl_param_ccs = ccsindex;
596 pccs = ccs_base(local) + ccsindex;
597 writeb(CCS_DOWNLOAD_STARTUP_PARAMS, &pccs->cmd);
Dominik Brodowski624dd662009-10-24 15:52:44 +0200598 dev_dbg(&link->dev, "dl_startup_params start ccsindex = %d\n",
John Daiker141fa612009-03-10 06:59:54 -0700599 local->dl_param_ccs);
600 /* Interrupt the firmware to process the command */
601 if (interrupt_ecf(local, ccsindex)) {
602 printk(KERN_INFO "ray dl_startup_params failed - "
603 "ECF not ready for intr\n");
604 local->card_status = CARD_DL_PARAM_ERROR;
605 writeb(CCS_BUFFER_FREE, &(pccs++)->buffer_status);
606 return -2;
607 }
608 local->card_status = CARD_DL_PARAM;
609 /* Start kernel timer to wait for dl startup to complete. */
610 local->timer.expires = jiffies + HZ / 2;
611 local->timer.data = (long)local;
612 local->timer.function = &verify_dl_startup;
613 add_timer(&local->timer);
Dominik Brodowski624dd662009-10-24 15:52:44 +0200614 dev_dbg(&link->dev,
John Daiker141fa612009-03-10 06:59:54 -0700615 "ray_cs dl_startup_params started timer for verify_dl_startup\n");
616 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700617} /* dl_startup_params */
John Daiker141fa612009-03-10 06:59:54 -0700618
Linus Torvalds1da177e2005-04-16 15:20:36 -0700619/*===========================================================================*/
620static void init_startup_params(ray_dev_t *local)
621{
John Daiker141fa612009-03-10 06:59:54 -0700622 int i;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700623
John Daiker141fa612009-03-10 06:59:54 -0700624 if (country > JAPAN_TEST)
625 country = USA;
626 else if (country < USA)
627 country = USA;
628 /* structure for hop time and beacon period is defined here using
629 * New 802.11D6.1 format. Card firmware is still using old format
630 * until version 6.
631 * Before After
632 * a_hop_time ms byte a_hop_time ms byte
633 * a_hop_time 2s byte a_hop_time ls byte
634 * a_hop_time ls byte a_beacon_period ms byte
635 * a_beacon_period a_beacon_period ls byte
636 *
637 * a_hop_time = uS a_hop_time = KuS
638 * a_beacon_period = hops a_beacon_period = KuS
639 *//* 64ms = 010000 */
640 if (local->fw_ver == 0x55) {
641 memcpy((UCHAR *) &local->sparm.b4, b4_default_startup_parms,
642 sizeof(struct b4_startup_params));
643 /* Translate sane kus input values to old build 4/5 format */
644 /* i = hop time in uS truncated to 3 bytes */
645 i = (hop_dwell * 1024) & 0xffffff;
646 local->sparm.b4.a_hop_time[0] = (i >> 16) & 0xff;
647 local->sparm.b4.a_hop_time[1] = (i >> 8) & 0xff;
648 local->sparm.b4.a_beacon_period[0] = 0;
649 local->sparm.b4.a_beacon_period[1] =
650 ((beacon_period / hop_dwell) - 1) & 0xff;
651 local->sparm.b4.a_curr_country_code = country;
652 local->sparm.b4.a_hop_pattern_length =
653 hop_pattern_length[(int)country] - 1;
654 if (bc) {
655 local->sparm.b4.a_ack_timeout = 0x50;
656 local->sparm.b4.a_sifs = 0x3f;
657 }
658 } else { /* Version 5 uses real kus values */
659 memcpy((UCHAR *) &local->sparm.b5, b5_default_startup_parms,
660 sizeof(struct b5_startup_params));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700661
John Daiker141fa612009-03-10 06:59:54 -0700662 local->sparm.b5.a_hop_time[0] = (hop_dwell >> 8) & 0xff;
663 local->sparm.b5.a_hop_time[1] = hop_dwell & 0xff;
664 local->sparm.b5.a_beacon_period[0] =
665 (beacon_period >> 8) & 0xff;
666 local->sparm.b5.a_beacon_period[1] = beacon_period & 0xff;
667 if (psm)
668 local->sparm.b5.a_power_mgt_state = 1;
669 local->sparm.b5.a_curr_country_code = country;
670 local->sparm.b5.a_hop_pattern_length =
671 hop_pattern_length[(int)country];
672 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700673
John Daiker141fa612009-03-10 06:59:54 -0700674 local->sparm.b4.a_network_type = net_type & 0x01;
675 local->sparm.b4.a_acting_as_ap_status = TYPE_STA;
676
677 if (essid != NULL)
678 strncpy(local->sparm.b4.a_current_ess_id, essid, ESSID_SIZE);
679} /* init_startup_params */
680
Linus Torvalds1da177e2005-04-16 15:20:36 -0700681/*===========================================================================*/
682static void verify_dl_startup(u_long data)
683{
John Daiker141fa612009-03-10 06:59:54 -0700684 ray_dev_t *local = (ray_dev_t *) data;
685 struct ccs __iomem *pccs = ccs_base(local) + local->dl_param_ccs;
686 UCHAR status;
687 struct pcmcia_device *link = local->finder;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700688
John Daiker141fa612009-03-10 06:59:54 -0700689 if (!(pcmcia_dev_present(link))) {
Dominik Brodowski624dd662009-10-24 15:52:44 +0200690 dev_dbg(&link->dev, "ray_cs verify_dl_startup - device not present\n");
John Daiker141fa612009-03-10 06:59:54 -0700691 return;
692 }
Dominik Brodowski624dd662009-10-24 15:52:44 +0200693#if 0
694 {
John Daiker141fa612009-03-10 06:59:54 -0700695 int i;
696 printk(KERN_DEBUG
697 "verify_dl_startup parameters sent via ccs %d:\n",
698 local->dl_param_ccs);
699 for (i = 0; i < sizeof(struct b5_startup_params); i++) {
700 printk(" %2x",
701 (unsigned int)readb(local->sram +
702 HOST_TO_ECF_BASE + i));
703 }
704 printk("\n");
705 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700706#endif
707
John Daiker141fa612009-03-10 06:59:54 -0700708 status = readb(&pccs->buffer_status);
709 if (status != CCS_BUFFER_FREE) {
710 printk(KERN_INFO
711 "Download startup params failed. Status = %d\n",
712 status);
713 local->card_status = CARD_DL_PARAM_ERROR;
714 return;
715 }
716 if (local->sparm.b4.a_network_type == ADHOC)
717 start_net((u_long) local);
718 else
719 join_net((u_long) local);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700720} /* end verify_dl_startup */
John Daiker141fa612009-03-10 06:59:54 -0700721
Linus Torvalds1da177e2005-04-16 15:20:36 -0700722/*===========================================================================*/
723/* Command card to start a network */
724static void start_net(u_long data)
725{
John Daiker141fa612009-03-10 06:59:54 -0700726 ray_dev_t *local = (ray_dev_t *) data;
727 struct ccs __iomem *pccs;
728 int ccsindex;
729 struct pcmcia_device *link = local->finder;
730 if (!(pcmcia_dev_present(link))) {
Dominik Brodowski624dd662009-10-24 15:52:44 +0200731 dev_dbg(&link->dev, "ray_cs start_net - device not present\n");
John Daiker141fa612009-03-10 06:59:54 -0700732 return;
733 }
734 /* Fill in the CCS fields for the ECF */
735 if ((ccsindex = get_free_ccs(local)) < 0)
736 return;
737 pccs = ccs_base(local) + ccsindex;
738 writeb(CCS_START_NETWORK, &pccs->cmd);
739 writeb(0, &pccs->var.start_network.update_param);
740 /* Interrupt the firmware to process the command */
741 if (interrupt_ecf(local, ccsindex)) {
Dominik Brodowski624dd662009-10-24 15:52:44 +0200742 dev_dbg(&link->dev, "ray start net failed - card not ready for intr\n");
John Daiker141fa612009-03-10 06:59:54 -0700743 writeb(CCS_BUFFER_FREE, &(pccs++)->buffer_status);
744 return;
745 }
746 local->card_status = CARD_DOING_ACQ;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700747} /* end start_net */
John Daiker141fa612009-03-10 06:59:54 -0700748
Linus Torvalds1da177e2005-04-16 15:20:36 -0700749/*===========================================================================*/
750/* Command card to join a network */
751static void join_net(u_long data)
752{
John Daiker141fa612009-03-10 06:59:54 -0700753 ray_dev_t *local = (ray_dev_t *) data;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700754
John Daiker141fa612009-03-10 06:59:54 -0700755 struct ccs __iomem *pccs;
756 int ccsindex;
757 struct pcmcia_device *link = local->finder;
758
759 if (!(pcmcia_dev_present(link))) {
Dominik Brodowski624dd662009-10-24 15:52:44 +0200760 dev_dbg(&link->dev, "ray_cs join_net - device not present\n");
John Daiker141fa612009-03-10 06:59:54 -0700761 return;
762 }
763 /* Fill in the CCS fields for the ECF */
764 if ((ccsindex = get_free_ccs(local)) < 0)
765 return;
766 pccs = ccs_base(local) + ccsindex;
767 writeb(CCS_JOIN_NETWORK, &pccs->cmd);
768 writeb(0, &pccs->var.join_network.update_param);
769 writeb(0, &pccs->var.join_network.net_initiated);
770 /* Interrupt the firmware to process the command */
771 if (interrupt_ecf(local, ccsindex)) {
Dominik Brodowski624dd662009-10-24 15:52:44 +0200772 dev_dbg(&link->dev, "ray join net failed - card not ready for intr\n");
John Daiker141fa612009-03-10 06:59:54 -0700773 writeb(CCS_BUFFER_FREE, &(pccs++)->buffer_status);
774 return;
775 }
776 local->card_status = CARD_DOING_ACQ;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700777}
John Daiker141fa612009-03-10 06:59:54 -0700778
Linus Torvalds1da177e2005-04-16 15:20:36 -0700779/*============================================================================
780 After a card is removed, ray_release() will unregister the net
781 device, and release the PCMCIA configuration. If the device is
782 still open, this will be postponed until it is closed.
783=============================================================================*/
Dominik Brodowskifba395e2006-03-31 17:21:06 +0200784static void ray_release(struct pcmcia_device *link)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700785{
John Daiker141fa612009-03-10 06:59:54 -0700786 struct net_device *dev = link->priv;
787 ray_dev_t *local = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700788
Dominik Brodowski624dd662009-10-24 15:52:44 +0200789 dev_dbg(&link->dev, "ray_release\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700790
John Daiker141fa612009-03-10 06:59:54 -0700791 del_timer(&local->timer);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700792
John Daiker141fa612009-03-10 06:59:54 -0700793 iounmap(local->sram);
794 iounmap(local->rmem);
795 iounmap(local->amem);
John Daiker141fa612009-03-10 06:59:54 -0700796 pcmcia_disable_device(link);
797
Dominik Brodowski624dd662009-10-24 15:52:44 +0200798 dev_dbg(&link->dev, "ray_release ending\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700799}
800
Dominik Brodowskifba395e2006-03-31 17:21:06 +0200801static int ray_suspend(struct pcmcia_device *link)
Dominik Brodowski98e4c282005-11-14 21:21:18 +0100802{
Dominik Brodowski98e4c282005-11-14 21:21:18 +0100803 struct net_device *dev = link->priv;
804
Dominik Brodowskie2d40962006-03-02 00:09:29 +0100805 if (link->open)
Dominik Brodowski8661bb52006-03-02 00:02:33 +0100806 netif_device_detach(dev);
Dominik Brodowski98e4c282005-11-14 21:21:18 +0100807
808 return 0;
809}
810
Dominik Brodowskifba395e2006-03-31 17:21:06 +0200811static int ray_resume(struct pcmcia_device *link)
Dominik Brodowski98e4c282005-11-14 21:21:18 +0100812{
Dominik Brodowski98e4c282005-11-14 21:21:18 +0100813 struct net_device *dev = link->priv;
814
Dominik Brodowskie2d40962006-03-02 00:09:29 +0100815 if (link->open) {
Dominik Brodowski8661bb52006-03-02 00:02:33 +0100816 ray_reset(dev);
817 netif_device_attach(dev);
818 }
Dominik Brodowski98e4c282005-11-14 21:21:18 +0100819
820 return 0;
821}
822
Linus Torvalds1da177e2005-04-16 15:20:36 -0700823/*===========================================================================*/
Hannes Eder2ed5ba82008-12-26 00:12:59 -0800824static int ray_dev_init(struct net_device *dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700825{
826#ifdef RAY_IMMEDIATE_INIT
John Daiker141fa612009-03-10 06:59:54 -0700827 int i;
828#endif /* RAY_IMMEDIATE_INIT */
829 ray_dev_t *local = netdev_priv(dev);
830 struct pcmcia_device *link = local->finder;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700831
Dominik Brodowski624dd662009-10-24 15:52:44 +0200832 dev_dbg(&link->dev, "ray_dev_init(dev=%p)\n", dev);
John Daiker141fa612009-03-10 06:59:54 -0700833 if (!(pcmcia_dev_present(link))) {
Dominik Brodowski624dd662009-10-24 15:52:44 +0200834 dev_dbg(&link->dev, "ray_dev_init - device not present\n");
John Daiker141fa612009-03-10 06:59:54 -0700835 return -1;
836 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700837#ifdef RAY_IMMEDIATE_INIT
John Daiker141fa612009-03-10 06:59:54 -0700838 /* Download startup parameters */
839 if ((i = dl_startup_params(dev)) < 0) {
840 printk(KERN_INFO "ray_dev_init dl_startup_params failed - "
841 "returns 0x%x\n", i);
842 return -1;
843 }
844#else /* RAY_IMMEDIATE_INIT */
845 /* Postpone the card init so that we can still configure the card,
846 * for example using the Wireless Extensions. The init will happen
847 * in ray_open() - Jean II */
Dominik Brodowski624dd662009-10-24 15:52:44 +0200848 dev_dbg(&link->dev,
John Daiker141fa612009-03-10 06:59:54 -0700849 "ray_dev_init: postponing card init to ray_open() ; Status = %d\n",
850 local->card_status);
851#endif /* RAY_IMMEDIATE_INIT */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700852
John Daiker141fa612009-03-10 06:59:54 -0700853 /* copy mac and broadcast addresses to linux device */
Jiri Pirko3a6d54c2009-05-11 23:37:15 +0000854 memcpy(dev->dev_addr, &local->sparm.b4.a_mac_addr, ADDRLEN);
John Daiker141fa612009-03-10 06:59:54 -0700855 memset(dev->broadcast, 0xff, ETH_ALEN);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700856
Dominik Brodowski624dd662009-10-24 15:52:44 +0200857 dev_dbg(&link->dev, "ray_dev_init ending\n");
John Daiker141fa612009-03-10 06:59:54 -0700858 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700859}
John Daiker141fa612009-03-10 06:59:54 -0700860
Linus Torvalds1da177e2005-04-16 15:20:36 -0700861/*===========================================================================*/
862static int ray_dev_config(struct net_device *dev, struct ifmap *map)
863{
John Daiker141fa612009-03-10 06:59:54 -0700864 ray_dev_t *local = netdev_priv(dev);
865 struct pcmcia_device *link = local->finder;
866 /* Dummy routine to satisfy device structure */
Dominik Brodowski624dd662009-10-24 15:52:44 +0200867 dev_dbg(&link->dev, "ray_dev_config(dev=%p,ifmap=%p)\n", dev, map);
John Daiker141fa612009-03-10 06:59:54 -0700868 if (!(pcmcia_dev_present(link))) {
Dominik Brodowski624dd662009-10-24 15:52:44 +0200869 dev_dbg(&link->dev, "ray_dev_config - device not present\n");
John Daiker141fa612009-03-10 06:59:54 -0700870 return -1;
871 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700872
John Daiker141fa612009-03-10 06:59:54 -0700873 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700874}
John Daiker141fa612009-03-10 06:59:54 -0700875
Linus Torvalds1da177e2005-04-16 15:20:36 -0700876/*===========================================================================*/
Stephen Hemmingerd0cf9c02009-08-31 19:50:57 +0000877static netdev_tx_t ray_dev_start_xmit(struct sk_buff *skb,
878 struct net_device *dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700879{
John Daiker141fa612009-03-10 06:59:54 -0700880 ray_dev_t *local = netdev_priv(dev);
881 struct pcmcia_device *link = local->finder;
882 short length = skb->len;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700883
Stephen Hemmingerd0cf9c02009-08-31 19:50:57 +0000884 if (!pcmcia_dev_present(link)) {
Dominik Brodowski624dd662009-10-24 15:52:44 +0200885 dev_dbg(&link->dev, "ray_dev_start_xmit - device not present\n");
Stephen Hemmingerd0cf9c02009-08-31 19:50:57 +0000886 dev_kfree_skb(skb);
887 return NETDEV_TX_OK;
John Daiker141fa612009-03-10 06:59:54 -0700888 }
Stephen Hemmingerd0cf9c02009-08-31 19:50:57 +0000889
Dominik Brodowski624dd662009-10-24 15:52:44 +0200890 dev_dbg(&link->dev, "ray_dev_start_xmit(skb=%p, dev=%p)\n", skb, dev);
John Daiker141fa612009-03-10 06:59:54 -0700891 if (local->authentication_state == NEED_TO_AUTH) {
Dominik Brodowski624dd662009-10-24 15:52:44 +0200892 dev_dbg(&link->dev, "ray_cs Sending authentication request.\n");
John Daiker141fa612009-03-10 06:59:54 -0700893 if (!build_auth_frame(local, local->auth_id, OPEN_AUTH_REQUEST)) {
894 local->authentication_state = AUTHENTICATED;
895 netif_stop_queue(dev);
Patrick McHardy5b548142009-06-12 06:22:29 +0000896 return NETDEV_TX_BUSY;
John Daiker141fa612009-03-10 06:59:54 -0700897 }
898 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700899
John Daiker141fa612009-03-10 06:59:54 -0700900 if (length < ETH_ZLEN) {
901 if (skb_padto(skb, ETH_ZLEN))
Patrick McHardy6ed10652009-06-23 06:03:08 +0000902 return NETDEV_TX_OK;
John Daiker141fa612009-03-10 06:59:54 -0700903 length = ETH_ZLEN;
904 }
905 switch (ray_hw_xmit(skb->data, length, dev, DATA_TYPE)) {
906 case XMIT_NO_CCS:
907 case XMIT_NEED_AUTH:
908 netif_stop_queue(dev);
Patrick McHardy5b548142009-06-12 06:22:29 +0000909 return NETDEV_TX_BUSY;
John Daiker141fa612009-03-10 06:59:54 -0700910 case XMIT_NO_INTR:
911 case XMIT_MSG_BAD:
912 case XMIT_OK:
913 default:
John Daiker141fa612009-03-10 06:59:54 -0700914 dev_kfree_skb(skb);
John Daiker141fa612009-03-10 06:59:54 -0700915 }
Stephen Hemmingerd0cf9c02009-08-31 19:50:57 +0000916
Patrick McHardy6ed10652009-06-23 06:03:08 +0000917 return NETDEV_TX_OK;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700918} /* ray_dev_start_xmit */
John Daiker141fa612009-03-10 06:59:54 -0700919
Linus Torvalds1da177e2005-04-16 15:20:36 -0700920/*===========================================================================*/
John Daiker141fa612009-03-10 06:59:54 -0700921static int ray_hw_xmit(unsigned char *data, int len, struct net_device *dev,
922 UCHAR msg_type)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700923{
John Daiker141fa612009-03-10 06:59:54 -0700924 ray_dev_t *local = netdev_priv(dev);
925 struct ccs __iomem *pccs;
926 int ccsindex;
927 int offset;
928 struct tx_msg __iomem *ptx; /* Address of xmit buffer in PC space */
929 short int addr; /* Address of xmit buffer in card space */
930
Dominik Brodowski624dd662009-10-24 15:52:44 +0200931 pr_debug("ray_hw_xmit(data=%p, len=%d, dev=%p)\n", data, len, dev);
John Daiker141fa612009-03-10 06:59:54 -0700932 if (len + TX_HEADER_LENGTH > TX_BUF_SIZE) {
933 printk(KERN_INFO "ray_hw_xmit packet too large: %d bytes\n",
934 len);
935 return XMIT_MSG_BAD;
936 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700937 switch (ccsindex = get_free_tx_ccs(local)) {
938 case ECCSBUSY:
Dominik Brodowski624dd662009-10-24 15:52:44 +0200939 pr_debug("ray_hw_xmit tx_ccs table busy\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700940 case ECCSFULL:
Dominik Brodowski624dd662009-10-24 15:52:44 +0200941 pr_debug("ray_hw_xmit No free tx ccs\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700942 case ECARDGONE:
John Daiker141fa612009-03-10 06:59:54 -0700943 netif_stop_queue(dev);
944 return XMIT_NO_CCS;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700945 default:
946 break;
947 }
John Daiker141fa612009-03-10 06:59:54 -0700948 addr = TX_BUF_BASE + (ccsindex << 11);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700949
John Daiker141fa612009-03-10 06:59:54 -0700950 if (msg_type == DATA_TYPE) {
951 local->stats.tx_bytes += len;
952 local->stats.tx_packets++;
953 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700954
John Daiker141fa612009-03-10 06:59:54 -0700955 ptx = local->sram + addr;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700956
John Daiker141fa612009-03-10 06:59:54 -0700957 ray_build_header(local, ptx, msg_type, data);
958 if (translate) {
959 offset = translate_frame(local, ptx, data, len);
960 } else { /* Encapsulate frame */
961 /* TBD TIB length will move address of ptx->var */
962 memcpy_toio(&ptx->var, data, len);
963 offset = 0;
964 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700965
John Daiker141fa612009-03-10 06:59:54 -0700966 /* fill in the CCS */
967 pccs = ccs_base(local) + ccsindex;
968 len += TX_HEADER_LENGTH + offset;
969 writeb(CCS_TX_REQUEST, &pccs->cmd);
970 writeb(addr >> 8, &pccs->var.tx_request.tx_data_ptr[0]);
971 writeb(local->tib_length, &pccs->var.tx_request.tx_data_ptr[1]);
972 writeb(len >> 8, &pccs->var.tx_request.tx_data_length[0]);
973 writeb(len & 0xff, &pccs->var.tx_request.tx_data_length[1]);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700974/* TBD still need psm_cam? */
John Daiker141fa612009-03-10 06:59:54 -0700975 writeb(PSM_CAM, &pccs->var.tx_request.pow_sav_mode);
976 writeb(local->net_default_tx_rate, &pccs->var.tx_request.tx_rate);
977 writeb(0, &pccs->var.tx_request.antenna);
Dominik Brodowski624dd662009-10-24 15:52:44 +0200978 pr_debug("ray_hw_xmit default_tx_rate = 0x%x\n",
John Daiker141fa612009-03-10 06:59:54 -0700979 local->net_default_tx_rate);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700980
John Daiker141fa612009-03-10 06:59:54 -0700981 /* Interrupt the firmware to process the command */
982 if (interrupt_ecf(local, ccsindex)) {
Dominik Brodowski624dd662009-10-24 15:52:44 +0200983 pr_debug("ray_hw_xmit failed - ECF not ready for intr\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700984/* TBD very inefficient to copy packet to buffer, and then not
985 send it, but the alternative is to queue the messages and that
986 won't be done for a while. Maybe set tbusy until a CCS is free?
987*/
John Daiker141fa612009-03-10 06:59:54 -0700988 writeb(CCS_BUFFER_FREE, &pccs->buffer_status);
989 return XMIT_NO_INTR;
990 }
991 return XMIT_OK;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700992} /* end ray_hw_xmit */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700993
John Daiker141fa612009-03-10 06:59:54 -0700994/*===========================================================================*/
995static int translate_frame(ray_dev_t *local, struct tx_msg __iomem *ptx,
996 unsigned char *data, int len)
997{
998 __be16 proto = ((struct ethhdr *)data)->h_proto;
999 if (ntohs(proto) >= 1536) { /* DIX II ethernet frame */
Dominik Brodowski624dd662009-10-24 15:52:44 +02001000 pr_debug("ray_cs translate_frame DIX II\n");
John Daiker141fa612009-03-10 06:59:54 -07001001 /* Copy LLC header to card buffer */
1002 memcpy_toio(&ptx->var, eth2_llc, sizeof(eth2_llc));
1003 memcpy_toio(((void __iomem *)&ptx->var) + sizeof(eth2_llc),
1004 (UCHAR *) &proto, 2);
1005 if (proto == htons(ETH_P_AARP) || proto == htons(ETH_P_IPX)) {
1006 /* This is the selective translation table, only 2 entries */
1007 writeb(0xf8,
1008 &((struct snaphdr_t __iomem *)ptx->var)->org[3]);
1009 }
1010 /* Copy body of ethernet packet without ethernet header */
1011 memcpy_toio((void __iomem *)&ptx->var +
1012 sizeof(struct snaphdr_t), data + ETH_HLEN,
1013 len - ETH_HLEN);
1014 return (int)sizeof(struct snaphdr_t) - ETH_HLEN;
1015 } else { /* already 802 type, and proto is length */
Dominik Brodowski624dd662009-10-24 15:52:44 +02001016 pr_debug("ray_cs translate_frame 802\n");
John Daiker141fa612009-03-10 06:59:54 -07001017 if (proto == htons(0xffff)) { /* evil netware IPX 802.3 without LLC */
Dominik Brodowski624dd662009-10-24 15:52:44 +02001018 pr_debug("ray_cs translate_frame evil IPX\n");
John Daiker141fa612009-03-10 06:59:54 -07001019 memcpy_toio(&ptx->var, data + ETH_HLEN, len - ETH_HLEN);
1020 return 0 - ETH_HLEN;
1021 }
1022 memcpy_toio(&ptx->var, data + ETH_HLEN, len - ETH_HLEN);
1023 return 0 - ETH_HLEN;
1024 }
1025 /* TBD do other frame types */
1026} /* end translate_frame */
1027
1028/*===========================================================================*/
1029static void ray_build_header(ray_dev_t *local, struct tx_msg __iomem *ptx,
1030 UCHAR msg_type, unsigned char *data)
1031{
1032 writeb(PROTOCOL_VER | msg_type, &ptx->mac.frame_ctl_1);
1033/*** IEEE 802.11 Address field assignments *************
1034 TODS FROMDS addr_1 addr_2 addr_3 addr_4
1035Adhoc 0 0 dest src (terminal) BSSID N/A
1036AP to Terminal 0 1 dest AP(BSSID) source N/A
1037Terminal to AP 1 0 AP(BSSID) src (terminal) dest N/A
1038AP to AP 1 1 dest AP src AP dest source
1039*******************************************************/
1040 if (local->net_type == ADHOC) {
1041 writeb(0, &ptx->mac.frame_ctl_2);
1042 memcpy_toio(ptx->mac.addr_1, ((struct ethhdr *)data)->h_dest,
1043 2 * ADDRLEN);
1044 memcpy_toio(ptx->mac.addr_3, local->bss_id, ADDRLEN);
1045 } else { /* infrastructure */
1046
1047 if (local->sparm.b4.a_acting_as_ap_status) {
1048 writeb(FC2_FROM_DS, &ptx->mac.frame_ctl_2);
1049 memcpy_toio(ptx->mac.addr_1,
1050 ((struct ethhdr *)data)->h_dest, ADDRLEN);
1051 memcpy_toio(ptx->mac.addr_2, local->bss_id, 6);
1052 memcpy_toio(ptx->mac.addr_3,
1053 ((struct ethhdr *)data)->h_source, ADDRLEN);
1054 } else { /* Terminal */
1055
1056 writeb(FC2_TO_DS, &ptx->mac.frame_ctl_2);
1057 memcpy_toio(ptx->mac.addr_1, local->bss_id, ADDRLEN);
1058 memcpy_toio(ptx->mac.addr_2,
1059 ((struct ethhdr *)data)->h_source, ADDRLEN);
1060 memcpy_toio(ptx->mac.addr_3,
1061 ((struct ethhdr *)data)->h_dest, ADDRLEN);
1062 }
1063 }
1064} /* end encapsulate_frame */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001065
1066/*===========================================================================*/
1067
1068static void netdev_get_drvinfo(struct net_device *dev,
1069 struct ethtool_drvinfo *info)
1070{
1071 strcpy(info->driver, "ray_cs");
1072}
1073
Jeff Garzik7282d492006-09-13 14:30:00 -04001074static const struct ethtool_ops netdev_ethtool_ops = {
John Daiker141fa612009-03-10 06:59:54 -07001075 .get_drvinfo = netdev_get_drvinfo,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001076};
1077
1078/*====================================================================*/
1079
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001080/*------------------------------------------------------------------*/
1081/*
1082 * Wireless Handler : get protocol name
1083 */
Joe Perches43ead782010-03-18 18:29:40 -07001084static int ray_get_name(struct net_device *dev, struct iw_request_info *info,
1085 union iwreq_data *wrqu, char *extra)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001086{
Joe Perches43ead782010-03-18 18:29:40 -07001087 strcpy(wrqu->name, "IEEE 802.11-FH");
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001088 return 0;
1089}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001090
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001091/*------------------------------------------------------------------*/
1092/*
1093 * Wireless Handler : set frequency
1094 */
Joe Perches43ead782010-03-18 18:29:40 -07001095static int ray_set_freq(struct net_device *dev, struct iw_request_info *info,
1096 union iwreq_data *wrqu, char *extra)
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001097{
Yoann Padioleau6dbc9c82007-08-03 19:37:16 +02001098 ray_dev_t *local = netdev_priv(dev);
John Daiker141fa612009-03-10 06:59:54 -07001099 int err = -EINPROGRESS; /* Call commit handler */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001100
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001101 /* Reject if card is already initialised */
John Daiker141fa612009-03-10 06:59:54 -07001102 if (local->card_status != CARD_AWAITING_PARAM)
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001103 return -EBUSY;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001104
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001105 /* Setting by channel number */
Joe Perches43ead782010-03-18 18:29:40 -07001106 if ((wrqu->freq.m > USA_HOP_MOD) || (wrqu->freq.e > 0))
Linus Torvalds1da177e2005-04-16 15:20:36 -07001107 err = -EOPNOTSUPP;
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001108 else
Joe Perches43ead782010-03-18 18:29:40 -07001109 local->sparm.b5.a_hop_pattern = wrqu->freq.m;
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001110
1111 return err;
1112}
John Daiker141fa612009-03-10 06:59:54 -07001113
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001114/*------------------------------------------------------------------*/
1115/*
1116 * Wireless Handler : get frequency
1117 */
Joe Perches43ead782010-03-18 18:29:40 -07001118static int ray_get_freq(struct net_device *dev, struct iw_request_info *info,
1119 union iwreq_data *wrqu, char *extra)
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001120{
Yoann Padioleau6dbc9c82007-08-03 19:37:16 +02001121 ray_dev_t *local = netdev_priv(dev);
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001122
Joe Perches43ead782010-03-18 18:29:40 -07001123 wrqu->freq.m = local->sparm.b5.a_hop_pattern;
1124 wrqu->freq.e = 0;
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001125 return 0;
1126}
1127
1128/*------------------------------------------------------------------*/
1129/*
1130 * Wireless Handler : set ESSID
1131 */
Joe Perches43ead782010-03-18 18:29:40 -07001132static int ray_set_essid(struct net_device *dev, struct iw_request_info *info,
1133 union iwreq_data *wrqu, char *extra)
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001134{
Yoann Padioleau6dbc9c82007-08-03 19:37:16 +02001135 ray_dev_t *local = netdev_priv(dev);
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001136
1137 /* Reject if card is already initialised */
John Daiker141fa612009-03-10 06:59:54 -07001138 if (local->card_status != CARD_AWAITING_PARAM)
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001139 return -EBUSY;
1140
1141 /* Check if we asked for `any' */
Joe Perches43ead782010-03-18 18:29:40 -07001142 if (wrqu->essid.flags == 0)
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001143 /* Corey : can you do that ? */
1144 return -EOPNOTSUPP;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001145
Joe Perches43ead782010-03-18 18:29:40 -07001146 /* Check the size of the string */
1147 if (wrqu->essid.length > IW_ESSID_MAX_SIZE)
1148 return -E2BIG;
1149
1150 /* Set the ESSID in the card */
1151 memset(local->sparm.b5.a_current_ess_id, 0, IW_ESSID_MAX_SIZE);
1152 memcpy(local->sparm.b5.a_current_ess_id, extra, wrqu->essid.length);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001153
John Daiker141fa612009-03-10 06:59:54 -07001154 return -EINPROGRESS; /* Call commit handler */
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001155}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001156
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001157/*------------------------------------------------------------------*/
1158/*
1159 * Wireless Handler : get ESSID
1160 */
Joe Perches43ead782010-03-18 18:29:40 -07001161static int ray_get_essid(struct net_device *dev, struct iw_request_info *info,
1162 union iwreq_data *wrqu, char *extra)
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001163{
Yoann Padioleau6dbc9c82007-08-03 19:37:16 +02001164 ray_dev_t *local = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001165
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001166 /* Get the essid that was set */
1167 memcpy(extra, local->sparm.b5.a_current_ess_id, IW_ESSID_MAX_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001168
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001169 /* Push it out ! */
Joe Perches43ead782010-03-18 18:29:40 -07001170 wrqu->essid.length = strlen(extra);
1171 wrqu->essid.flags = 1; /* active */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001172
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001173 return 0;
1174}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001175
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001176/*------------------------------------------------------------------*/
1177/*
1178 * Wireless Handler : get AP address
1179 */
Joe Perches43ead782010-03-18 18:29:40 -07001180static int ray_get_wap(struct net_device *dev, struct iw_request_info *info,
1181 union iwreq_data *wrqu, char *extra)
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001182{
Yoann Padioleau6dbc9c82007-08-03 19:37:16 +02001183 ray_dev_t *local = netdev_priv(dev);
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001184
Joe Perches43ead782010-03-18 18:29:40 -07001185 memcpy(wrqu->ap_addr.sa_data, local->bss_id, ETH_ALEN);
1186 wrqu->ap_addr.sa_family = ARPHRD_ETHER;
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001187
1188 return 0;
1189}
1190
1191/*------------------------------------------------------------------*/
1192/*
1193 * Wireless Handler : set Bit-Rate
1194 */
Joe Perches43ead782010-03-18 18:29:40 -07001195static int ray_set_rate(struct net_device *dev, struct iw_request_info *info,
1196 union iwreq_data *wrqu, char *extra)
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001197{
Yoann Padioleau6dbc9c82007-08-03 19:37:16 +02001198 ray_dev_t *local = netdev_priv(dev);
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001199
1200 /* Reject if card is already initialised */
John Daiker141fa612009-03-10 06:59:54 -07001201 if (local->card_status != CARD_AWAITING_PARAM)
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001202 return -EBUSY;
1203
1204 /* Check if rate is in range */
Joe Perches43ead782010-03-18 18:29:40 -07001205 if ((wrqu->bitrate.value != 1000000) && (wrqu->bitrate.value != 2000000))
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001206 return -EINVAL;
1207
1208 /* Hack for 1.5 Mb/s instead of 2 Mb/s */
John Daiker141fa612009-03-10 06:59:54 -07001209 if ((local->fw_ver == 0x55) && /* Please check */
Joe Perches43ead782010-03-18 18:29:40 -07001210 (wrqu->bitrate.value == 2000000))
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001211 local->net_default_tx_rate = 3;
1212 else
Joe Perches43ead782010-03-18 18:29:40 -07001213 local->net_default_tx_rate = wrqu->bitrate.value / 500000;
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001214
1215 return 0;
1216}
1217
1218/*------------------------------------------------------------------*/
1219/*
1220 * Wireless Handler : get Bit-Rate
1221 */
Joe Perches43ead782010-03-18 18:29:40 -07001222static int ray_get_rate(struct net_device *dev, struct iw_request_info *info,
1223 union iwreq_data *wrqu, char *extra)
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001224{
Yoann Padioleau6dbc9c82007-08-03 19:37:16 +02001225 ray_dev_t *local = netdev_priv(dev);
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001226
John Daiker141fa612009-03-10 06:59:54 -07001227 if (local->net_default_tx_rate == 3)
Joe Perches43ead782010-03-18 18:29:40 -07001228 wrqu->bitrate.value = 2000000; /* Hum... */
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001229 else
Joe Perches43ead782010-03-18 18:29:40 -07001230 wrqu->bitrate.value = local->net_default_tx_rate * 500000;
1231 wrqu->bitrate.fixed = 0; /* We are in auto mode */
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001232
1233 return 0;
1234}
1235
1236/*------------------------------------------------------------------*/
1237/*
1238 * Wireless Handler : set RTS threshold
1239 */
Joe Perches43ead782010-03-18 18:29:40 -07001240static int ray_set_rts(struct net_device *dev, struct iw_request_info *info,
1241 union iwreq_data *wrqu, char *extra)
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001242{
Yoann Padioleau6dbc9c82007-08-03 19:37:16 +02001243 ray_dev_t *local = netdev_priv(dev);
Joe Perches43ead782010-03-18 18:29:40 -07001244 int rthr = wrqu->rts.value;
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001245
1246 /* Reject if card is already initialised */
John Daiker141fa612009-03-10 06:59:54 -07001247 if (local->card_status != CARD_AWAITING_PARAM)
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001248 return -EBUSY;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001249
1250 /* if(wrq->u.rts.fixed == 0) we should complain */
Joe Perches43ead782010-03-18 18:29:40 -07001251 if (wrqu->rts.disabled)
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001252 rthr = 32767;
1253 else {
John Daiker141fa612009-03-10 06:59:54 -07001254 if ((rthr < 0) || (rthr > 2347)) /* What's the max packet size ??? */
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001255 return -EINVAL;
1256 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001257 local->sparm.b5.a_rts_threshold[0] = (rthr >> 8) & 0xFF;
1258 local->sparm.b5.a_rts_threshold[1] = rthr & 0xFF;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001259
John Daiker141fa612009-03-10 06:59:54 -07001260 return -EINPROGRESS; /* Call commit handler */
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001261}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001262
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001263/*------------------------------------------------------------------*/
1264/*
1265 * Wireless Handler : get RTS threshold
1266 */
Joe Perches43ead782010-03-18 18:29:40 -07001267static int ray_get_rts(struct net_device *dev, struct iw_request_info *info,
1268 union iwreq_data *wrqu, char *extra)
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001269{
Yoann Padioleau6dbc9c82007-08-03 19:37:16 +02001270 ray_dev_t *local = netdev_priv(dev);
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001271
Joe Perches43ead782010-03-18 18:29:40 -07001272 wrqu->rts.value = (local->sparm.b5.a_rts_threshold[0] << 8)
John Daiker141fa612009-03-10 06:59:54 -07001273 + local->sparm.b5.a_rts_threshold[1];
Joe Perches43ead782010-03-18 18:29:40 -07001274 wrqu->rts.disabled = (wrqu->rts.value == 32767);
1275 wrqu->rts.fixed = 1;
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001276
1277 return 0;
1278}
1279
1280/*------------------------------------------------------------------*/
1281/*
1282 * Wireless Handler : set Fragmentation threshold
1283 */
Joe Perches43ead782010-03-18 18:29:40 -07001284static int ray_set_frag(struct net_device *dev, struct iw_request_info *info,
1285 union iwreq_data *wrqu, char *extra)
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001286{
Yoann Padioleau6dbc9c82007-08-03 19:37:16 +02001287 ray_dev_t *local = netdev_priv(dev);
Joe Perches43ead782010-03-18 18:29:40 -07001288 int fthr = wrqu->frag.value;
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001289
1290 /* Reject if card is already initialised */
John Daiker141fa612009-03-10 06:59:54 -07001291 if (local->card_status != CARD_AWAITING_PARAM)
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001292 return -EBUSY;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001293
1294 /* if(wrq->u.frag.fixed == 0) should complain */
Joe Perches43ead782010-03-18 18:29:40 -07001295 if (wrqu->frag.disabled)
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001296 fthr = 32767;
1297 else {
John Daiker141fa612009-03-10 06:59:54 -07001298 if ((fthr < 256) || (fthr > 2347)) /* To check out ! */
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001299 return -EINVAL;
1300 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001301 local->sparm.b5.a_frag_threshold[0] = (fthr >> 8) & 0xFF;
1302 local->sparm.b5.a_frag_threshold[1] = fthr & 0xFF;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001303
John Daiker141fa612009-03-10 06:59:54 -07001304 return -EINPROGRESS; /* Call commit handler */
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001305}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001306
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001307/*------------------------------------------------------------------*/
1308/*
1309 * Wireless Handler : get Fragmentation threshold
1310 */
Joe Perches43ead782010-03-18 18:29:40 -07001311static int ray_get_frag(struct net_device *dev, struct iw_request_info *info,
1312 union iwreq_data *wrqu, char *extra)
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001313{
Yoann Padioleau6dbc9c82007-08-03 19:37:16 +02001314 ray_dev_t *local = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001315
Joe Perches43ead782010-03-18 18:29:40 -07001316 wrqu->frag.value = (local->sparm.b5.a_frag_threshold[0] << 8)
John Daiker141fa612009-03-10 06:59:54 -07001317 + local->sparm.b5.a_frag_threshold[1];
Joe Perches43ead782010-03-18 18:29:40 -07001318 wrqu->frag.disabled = (wrqu->frag.value == 32767);
1319 wrqu->frag.fixed = 1;
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001320
1321 return 0;
1322}
1323
1324/*------------------------------------------------------------------*/
1325/*
1326 * Wireless Handler : set Mode of Operation
1327 */
Joe Perches43ead782010-03-18 18:29:40 -07001328static int ray_set_mode(struct net_device *dev, struct iw_request_info *info,
1329 union iwreq_data *wrqu, char *extra)
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001330{
Yoann Padioleau6dbc9c82007-08-03 19:37:16 +02001331 ray_dev_t *local = netdev_priv(dev);
John Daiker141fa612009-03-10 06:59:54 -07001332 int err = -EINPROGRESS; /* Call commit handler */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001333 char card_mode = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001334
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001335 /* Reject if card is already initialised */
John Daiker141fa612009-03-10 06:59:54 -07001336 if (local->card_status != CARD_AWAITING_PARAM)
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001337 return -EBUSY;
1338
Joe Perches43ead782010-03-18 18:29:40 -07001339 switch (wrqu->mode) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001340 case IW_MODE_ADHOC:
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001341 card_mode = 0;
John Daiker141fa612009-03-10 06:59:54 -07001342 /* Fall through */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001343 case IW_MODE_INFRA:
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001344 local->sparm.b5.a_network_type = card_mode;
1345 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001346 default:
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001347 err = -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001348 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001349
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001350 return err;
1351}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001352
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001353/*------------------------------------------------------------------*/
1354/*
1355 * Wireless Handler : get Mode of Operation
1356 */
Joe Perches43ead782010-03-18 18:29:40 -07001357static int ray_get_mode(struct net_device *dev, struct iw_request_info *info,
1358 union iwreq_data *wrqu, char *extra)
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001359{
Yoann Padioleau6dbc9c82007-08-03 19:37:16 +02001360 ray_dev_t *local = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001361
John Daiker141fa612009-03-10 06:59:54 -07001362 if (local->sparm.b5.a_network_type)
Joe Perches43ead782010-03-18 18:29:40 -07001363 wrqu->mode = IW_MODE_INFRA;
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001364 else
Joe Perches43ead782010-03-18 18:29:40 -07001365 wrqu->mode = IW_MODE_ADHOC;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001366
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001367 return 0;
1368}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001369
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001370/*------------------------------------------------------------------*/
1371/*
1372 * Wireless Handler : get range info
1373 */
Joe Perches43ead782010-03-18 18:29:40 -07001374static int ray_get_range(struct net_device *dev, struct iw_request_info *info,
1375 union iwreq_data *wrqu, char *extra)
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001376{
John Daiker141fa612009-03-10 06:59:54 -07001377 struct iw_range *range = (struct iw_range *)extra;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001378
Joe Perches43ead782010-03-18 18:29:40 -07001379 memset(range, 0, sizeof(struct iw_range));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001380
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001381 /* Set the length (very important for backward compatibility) */
Joe Perches43ead782010-03-18 18:29:40 -07001382 wrqu->data.length = sizeof(struct iw_range);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001383
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001384 /* Set the Wireless Extension versions */
1385 range->we_version_compiled = WIRELESS_EXT;
1386 range->we_version_source = 9;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001387
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001388 /* Set information in the range struct */
1389 range->throughput = 1.1 * 1000 * 1000; /* Put the right number here */
John Daiker141fa612009-03-10 06:59:54 -07001390 range->num_channels = hop_pattern_length[(int)country];
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001391 range->num_frequency = 0;
1392 range->max_qual.qual = 0;
1393 range->max_qual.level = 255; /* What's the correct value ? */
1394 range->max_qual.noise = 255; /* Idem */
1395 range->num_bitrates = 2;
1396 range->bitrate[0] = 1000000; /* 1 Mb/s */
1397 range->bitrate[1] = 2000000; /* 2 Mb/s */
1398 return 0;
1399}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001400
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001401/*------------------------------------------------------------------*/
1402/*
1403 * Wireless Private Handler : set framing mode
1404 */
Joe Perches43ead782010-03-18 18:29:40 -07001405static int ray_set_framing(struct net_device *dev, struct iw_request_info *info,
John Daiker141fa612009-03-10 06:59:54 -07001406 union iwreq_data *wrqu, char *extra)
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001407{
1408 translate = *(extra); /* Set framing mode */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001409
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001410 return 0;
1411}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001412
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001413/*------------------------------------------------------------------*/
1414/*
1415 * Wireless Private Handler : get framing mode
1416 */
Joe Perches43ead782010-03-18 18:29:40 -07001417static int ray_get_framing(struct net_device *dev, struct iw_request_info *info,
John Daiker141fa612009-03-10 06:59:54 -07001418 union iwreq_data *wrqu, char *extra)
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001419{
1420 *(extra) = translate;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001421
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001422 return 0;
1423}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001424
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001425/*------------------------------------------------------------------*/
1426/*
1427 * Wireless Private Handler : get country
1428 */
Joe Perches43ead782010-03-18 18:29:40 -07001429static int ray_get_country(struct net_device *dev, struct iw_request_info *info,
John Daiker141fa612009-03-10 06:59:54 -07001430 union iwreq_data *wrqu, char *extra)
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001431{
1432 *(extra) = country;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001433
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001434 return 0;
1435}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001436
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001437/*------------------------------------------------------------------*/
1438/*
1439 * Commit handler : called after a bunch of SET operations
1440 */
Joe Perches43ead782010-03-18 18:29:40 -07001441static int ray_commit(struct net_device *dev, struct iw_request_info *info,
1442 union iwreq_data *wrqu, char *extra)
1443{
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001444 return 0;
1445}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001446
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001447/*------------------------------------------------------------------*/
1448/*
1449 * Stats handler : return Wireless Stats
1450 */
John Daiker141fa612009-03-10 06:59:54 -07001451static iw_stats *ray_get_wireless_stats(struct net_device *dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001452{
John Daiker141fa612009-03-10 06:59:54 -07001453 ray_dev_t *local = netdev_priv(dev);
1454 struct pcmcia_device *link = local->finder;
1455 struct status __iomem *p = local->sram + STATUS_BASE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001456
John Daiker141fa612009-03-10 06:59:54 -07001457 local->wstats.status = local->card_status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001458#ifdef WIRELESS_SPY
John Daiker141fa612009-03-10 06:59:54 -07001459 if ((local->spy_data.spy_number > 0)
1460 && (local->sparm.b5.a_network_type == 0)) {
1461 /* Get it from the first node in spy list */
1462 local->wstats.qual.qual = local->spy_data.spy_stat[0].qual;
1463 local->wstats.qual.level = local->spy_data.spy_stat[0].level;
1464 local->wstats.qual.noise = local->spy_data.spy_stat[0].noise;
1465 local->wstats.qual.updated =
1466 local->spy_data.spy_stat[0].updated;
1467 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001468#endif /* WIRELESS_SPY */
1469
John Daiker141fa612009-03-10 06:59:54 -07001470 if (pcmcia_dev_present(link)) {
1471 local->wstats.qual.noise = readb(&p->rxnoise);
1472 local->wstats.qual.updated |= 4;
1473 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001474
John Daiker141fa612009-03-10 06:59:54 -07001475 return &local->wstats;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001476} /* end ray_get_wireless_stats */
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001477
1478/*------------------------------------------------------------------*/
1479/*
1480 * Structures to export the Wireless Handlers
1481 */
1482
John Daiker141fa612009-03-10 06:59:54 -07001483static const iw_handler ray_handler[] = {
Joe Perches43ead782010-03-18 18:29:40 -07001484 IW_HANDLER(SIOCSIWCOMMIT, ray_commit),
1485 IW_HANDLER(SIOCGIWNAME, ray_get_name),
1486 IW_HANDLER(SIOCSIWFREQ, ray_set_freq),
1487 IW_HANDLER(SIOCGIWFREQ, ray_get_freq),
1488 IW_HANDLER(SIOCSIWMODE, ray_set_mode),
1489 IW_HANDLER(SIOCGIWMODE, ray_get_mode),
1490 IW_HANDLER(SIOCGIWRANGE, ray_get_range),
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001491#ifdef WIRELESS_SPY
Joe Perches270020e2010-03-18 18:29:37 -07001492 IW_HANDLER(SIOCSIWSPY, iw_handler_set_spy),
1493 IW_HANDLER(SIOCGIWSPY, iw_handler_get_spy),
1494 IW_HANDLER(SIOCSIWTHRSPY, iw_handler_set_thrspy),
1495 IW_HANDLER(SIOCGIWTHRSPY, iw_handler_get_thrspy),
John Daiker141fa612009-03-10 06:59:54 -07001496#endif /* WIRELESS_SPY */
Joe Perches43ead782010-03-18 18:29:40 -07001497 IW_HANDLER(SIOCGIWAP, ray_get_wap),
1498 IW_HANDLER(SIOCSIWESSID, ray_set_essid),
1499 IW_HANDLER(SIOCGIWESSID, ray_get_essid),
1500 IW_HANDLER(SIOCSIWRATE, ray_set_rate),
1501 IW_HANDLER(SIOCGIWRATE, ray_get_rate),
1502 IW_HANDLER(SIOCSIWRTS, ray_set_rts),
1503 IW_HANDLER(SIOCGIWRTS, ray_get_rts),
1504 IW_HANDLER(SIOCSIWFRAG, ray_set_frag),
1505 IW_HANDLER(SIOCGIWFRAG, ray_get_frag),
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001506};
1507
John Daiker141fa612009-03-10 06:59:54 -07001508#define SIOCSIPFRAMING SIOCIWFIRSTPRIV /* Set framing mode */
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001509#define SIOCGIPFRAMING SIOCIWFIRSTPRIV + 1 /* Get framing mode */
1510#define SIOCGIPCOUNTRY SIOCIWFIRSTPRIV + 3 /* Get country code */
1511
John Daiker141fa612009-03-10 06:59:54 -07001512static const iw_handler ray_private_handler[] = {
Joe Perches43ead782010-03-18 18:29:40 -07001513 [0] = ray_set_framing,
1514 [1] = ray_get_framing,
1515 [3] = ray_get_country,
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001516};
1517
John Daiker141fa612009-03-10 06:59:54 -07001518static const struct iw_priv_args ray_private_args[] = {
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001519/* cmd, set_args, get_args, name */
John Daiker141fa612009-03-10 06:59:54 -07001520 {SIOCSIPFRAMING, IW_PRIV_TYPE_BYTE | IW_PRIV_SIZE_FIXED | 1, 0,
1521 "set_framing"},
1522 {SIOCGIPFRAMING, 0, IW_PRIV_TYPE_BYTE | IW_PRIV_SIZE_FIXED | 1,
1523 "get_framing"},
1524 {SIOCGIPCOUNTRY, 0, IW_PRIV_TYPE_BYTE | IW_PRIV_SIZE_FIXED | 1,
1525 "get_country"},
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001526};
1527
John Daiker141fa612009-03-10 06:59:54 -07001528static const struct iw_handler_def ray_handler_def = {
1529 .num_standard = ARRAY_SIZE(ray_handler),
1530 .num_private = ARRAY_SIZE(ray_private_handler),
Denis Chengff8ac602007-09-02 18:30:18 +08001531 .num_private_args = ARRAY_SIZE(ray_private_args),
John Daiker141fa612009-03-10 06:59:54 -07001532 .standard = ray_handler,
1533 .private = ray_private_handler,
1534 .private_args = ray_private_args,
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001535 .get_wireless_stats = ray_get_wireless_stats,
1536};
1537
Linus Torvalds1da177e2005-04-16 15:20:36 -07001538/*===========================================================================*/
1539static int ray_open(struct net_device *dev)
1540{
John Daiker141fa612009-03-10 06:59:54 -07001541 ray_dev_t *local = netdev_priv(dev);
1542 struct pcmcia_device *link;
1543 link = local->finder;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001544
Dominik Brodowski624dd662009-10-24 15:52:44 +02001545 dev_dbg(&link->dev, "ray_open('%s')\n", dev->name);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001546
John Daiker141fa612009-03-10 06:59:54 -07001547 if (link->open == 0)
1548 local->num_multi = 0;
1549 link->open++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001550
John Daiker141fa612009-03-10 06:59:54 -07001551 /* If the card is not started, time to start it ! - Jean II */
1552 if (local->card_status == CARD_AWAITING_PARAM) {
1553 int i;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001554
Dominik Brodowski624dd662009-10-24 15:52:44 +02001555 dev_dbg(&link->dev, "ray_open: doing init now !\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001556
John Daiker141fa612009-03-10 06:59:54 -07001557 /* Download startup parameters */
1558 if ((i = dl_startup_params(dev)) < 0) {
1559 printk(KERN_INFO
1560 "ray_dev_init dl_startup_params failed - "
1561 "returns 0x%x\n", i);
1562 return -1;
1563 }
1564 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001565
John Daiker141fa612009-03-10 06:59:54 -07001566 if (sniffer)
1567 netif_stop_queue(dev);
1568 else
1569 netif_start_queue(dev);
1570
Dominik Brodowski624dd662009-10-24 15:52:44 +02001571 dev_dbg(&link->dev, "ray_open ending\n");
John Daiker141fa612009-03-10 06:59:54 -07001572 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001573} /* end ray_open */
John Daiker141fa612009-03-10 06:59:54 -07001574
Linus Torvalds1da177e2005-04-16 15:20:36 -07001575/*===========================================================================*/
1576static int ray_dev_close(struct net_device *dev)
1577{
John Daiker141fa612009-03-10 06:59:54 -07001578 ray_dev_t *local = netdev_priv(dev);
1579 struct pcmcia_device *link;
1580 link = local->finder;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001581
Dominik Brodowski624dd662009-10-24 15:52:44 +02001582 dev_dbg(&link->dev, "ray_dev_close('%s')\n", dev->name);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001583
John Daiker141fa612009-03-10 06:59:54 -07001584 link->open--;
1585 netif_stop_queue(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001586
John Daiker141fa612009-03-10 06:59:54 -07001587 /* In here, we should stop the hardware (stop card from beeing active)
1588 * and set local->card_status to CARD_AWAITING_PARAM, so that while the
1589 * card is closed we can chage its configuration.
1590 * Probably also need a COR reset to get sane state - Jean II */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001591
John Daiker141fa612009-03-10 06:59:54 -07001592 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001593} /* end ray_dev_close */
John Daiker141fa612009-03-10 06:59:54 -07001594
Linus Torvalds1da177e2005-04-16 15:20:36 -07001595/*===========================================================================*/
John Daiker141fa612009-03-10 06:59:54 -07001596static void ray_reset(struct net_device *dev)
1597{
Dominik Brodowski624dd662009-10-24 15:52:44 +02001598 pr_debug("ray_reset entered\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001599}
John Daiker141fa612009-03-10 06:59:54 -07001600
Linus Torvalds1da177e2005-04-16 15:20:36 -07001601/*===========================================================================*/
1602/* Cause a firmware interrupt if it is ready for one */
1603/* Return nonzero if not ready */
1604static int interrupt_ecf(ray_dev_t *local, int ccs)
1605{
John Daiker141fa612009-03-10 06:59:54 -07001606 int i = 50;
1607 struct pcmcia_device *link = local->finder;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001608
John Daiker141fa612009-03-10 06:59:54 -07001609 if (!(pcmcia_dev_present(link))) {
Dominik Brodowski624dd662009-10-24 15:52:44 +02001610 dev_dbg(&link->dev, "ray_cs interrupt_ecf - device not present\n");
John Daiker141fa612009-03-10 06:59:54 -07001611 return -1;
1612 }
Dominik Brodowski624dd662009-10-24 15:52:44 +02001613 dev_dbg(&link->dev, "interrupt_ecf(local=%p, ccs = 0x%x\n", local, ccs);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001614
John Daiker141fa612009-03-10 06:59:54 -07001615 while (i &&
1616 (readb(local->amem + CIS_OFFSET + ECF_INTR_OFFSET) &
1617 ECF_INTR_SET))
1618 i--;
1619 if (i == 0) {
Dominik Brodowski624dd662009-10-24 15:52:44 +02001620 dev_dbg(&link->dev, "ray_cs interrupt_ecf card not ready for interrupt\n");
John Daiker141fa612009-03-10 06:59:54 -07001621 return -1;
1622 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001623 /* Fill the mailbox, then kick the card */
John Daiker141fa612009-03-10 06:59:54 -07001624 writeb(ccs, local->sram + SCB_BASE);
1625 writeb(ECF_INTR_SET, local->amem + CIS_OFFSET + ECF_INTR_OFFSET);
1626 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001627} /* interrupt_ecf */
John Daiker141fa612009-03-10 06:59:54 -07001628
Linus Torvalds1da177e2005-04-16 15:20:36 -07001629/*===========================================================================*/
1630/* Get next free transmit CCS */
1631/* Return - index of current tx ccs */
1632static int get_free_tx_ccs(ray_dev_t *local)
1633{
John Daiker141fa612009-03-10 06:59:54 -07001634 int i;
1635 struct ccs __iomem *pccs = ccs_base(local);
1636 struct pcmcia_device *link = local->finder;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001637
John Daiker141fa612009-03-10 06:59:54 -07001638 if (!(pcmcia_dev_present(link))) {
Dominik Brodowski624dd662009-10-24 15:52:44 +02001639 dev_dbg(&link->dev, "ray_cs get_free_tx_ccs - device not present\n");
John Daiker141fa612009-03-10 06:59:54 -07001640 return ECARDGONE;
1641 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001642
John Daiker141fa612009-03-10 06:59:54 -07001643 if (test_and_set_bit(0, &local->tx_ccs_lock)) {
Dominik Brodowski624dd662009-10-24 15:52:44 +02001644 dev_dbg(&link->dev, "ray_cs tx_ccs_lock busy\n");
John Daiker141fa612009-03-10 06:59:54 -07001645 return ECCSBUSY;
1646 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001647
John Daiker141fa612009-03-10 06:59:54 -07001648 for (i = 0; i < NUMBER_OF_TX_CCS; i++) {
1649 if (readb(&(pccs + i)->buffer_status) == CCS_BUFFER_FREE) {
1650 writeb(CCS_BUFFER_BUSY, &(pccs + i)->buffer_status);
1651 writeb(CCS_END_LIST, &(pccs + i)->link);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001652 local->tx_ccs_lock = 0;
John Daiker141fa612009-03-10 06:59:54 -07001653 return i;
1654 }
1655 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001656 local->tx_ccs_lock = 0;
Dominik Brodowski624dd662009-10-24 15:52:44 +02001657 dev_dbg(&link->dev, "ray_cs ERROR no free tx CCS for raylink card\n");
John Daiker141fa612009-03-10 06:59:54 -07001658 return ECCSFULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001659} /* get_free_tx_ccs */
John Daiker141fa612009-03-10 06:59:54 -07001660
Linus Torvalds1da177e2005-04-16 15:20:36 -07001661/*===========================================================================*/
1662/* Get next free CCS */
1663/* Return - index of current ccs */
1664static int get_free_ccs(ray_dev_t *local)
1665{
John Daiker141fa612009-03-10 06:59:54 -07001666 int i;
1667 struct ccs __iomem *pccs = ccs_base(local);
1668 struct pcmcia_device *link = local->finder;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001669
John Daiker141fa612009-03-10 06:59:54 -07001670 if (!(pcmcia_dev_present(link))) {
Dominik Brodowski624dd662009-10-24 15:52:44 +02001671 dev_dbg(&link->dev, "ray_cs get_free_ccs - device not present\n");
John Daiker141fa612009-03-10 06:59:54 -07001672 return ECARDGONE;
1673 }
1674 if (test_and_set_bit(0, &local->ccs_lock)) {
Dominik Brodowski624dd662009-10-24 15:52:44 +02001675 dev_dbg(&link->dev, "ray_cs ccs_lock busy\n");
John Daiker141fa612009-03-10 06:59:54 -07001676 return ECCSBUSY;
1677 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001678
John Daiker141fa612009-03-10 06:59:54 -07001679 for (i = NUMBER_OF_TX_CCS; i < NUMBER_OF_CCS; i++) {
1680 if (readb(&(pccs + i)->buffer_status) == CCS_BUFFER_FREE) {
1681 writeb(CCS_BUFFER_BUSY, &(pccs + i)->buffer_status);
1682 writeb(CCS_END_LIST, &(pccs + i)->link);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001683 local->ccs_lock = 0;
John Daiker141fa612009-03-10 06:59:54 -07001684 return i;
1685 }
1686 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001687 local->ccs_lock = 0;
Dominik Brodowski624dd662009-10-24 15:52:44 +02001688 dev_dbg(&link->dev, "ray_cs ERROR no free CCS for raylink card\n");
John Daiker141fa612009-03-10 06:59:54 -07001689 return ECCSFULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001690} /* get_free_ccs */
John Daiker141fa612009-03-10 06:59:54 -07001691
Linus Torvalds1da177e2005-04-16 15:20:36 -07001692/*===========================================================================*/
1693static void authenticate_timeout(u_long data)
1694{
John Daiker141fa612009-03-10 06:59:54 -07001695 ray_dev_t *local = (ray_dev_t *) data;
1696 del_timer(&local->timer);
1697 printk(KERN_INFO "ray_cs Authentication with access point failed"
1698 " - timeout\n");
1699 join_net((u_long) local);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001700}
John Daiker141fa612009-03-10 06:59:54 -07001701
Linus Torvalds1da177e2005-04-16 15:20:36 -07001702/*===========================================================================*/
1703static int asc_to_int(char a)
1704{
John Daiker141fa612009-03-10 06:59:54 -07001705 if (a < '0')
1706 return -1;
1707 if (a <= '9')
1708 return (a - '0');
1709 if (a < 'A')
1710 return -1;
1711 if (a <= 'F')
1712 return (10 + a - 'A');
1713 if (a < 'a')
1714 return -1;
1715 if (a <= 'f')
1716 return (10 + a - 'a');
1717 return -1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001718}
John Daiker141fa612009-03-10 06:59:54 -07001719
Linus Torvalds1da177e2005-04-16 15:20:36 -07001720/*===========================================================================*/
1721static int parse_addr(char *in_str, UCHAR *out)
1722{
John Daiker141fa612009-03-10 06:59:54 -07001723 int len;
1724 int i, j, k;
1725 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001726
John Daiker141fa612009-03-10 06:59:54 -07001727 if (in_str == NULL)
1728 return 0;
1729 if ((len = strlen(in_str)) < 2)
1730 return 0;
1731 memset(out, 0, ADDRLEN);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001732
John Daiker141fa612009-03-10 06:59:54 -07001733 status = 1;
1734 j = len - 1;
1735 if (j > 12)
1736 j = 12;
1737 i = 5;
1738
1739 while (j > 0) {
1740 if ((k = asc_to_int(in_str[j--])) != -1)
1741 out[i] = k;
1742 else
1743 return 0;
1744
1745 if (j == 0)
1746 break;
1747 if ((k = asc_to_int(in_str[j--])) != -1)
1748 out[i] += k << 4;
1749 else
1750 return 0;
1751 if (!i--)
1752 break;
1753 }
1754 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001755}
John Daiker141fa612009-03-10 06:59:54 -07001756
Linus Torvalds1da177e2005-04-16 15:20:36 -07001757/*===========================================================================*/
1758static struct net_device_stats *ray_get_stats(struct net_device *dev)
1759{
John Daiker141fa612009-03-10 06:59:54 -07001760 ray_dev_t *local = netdev_priv(dev);
1761 struct pcmcia_device *link = local->finder;
1762 struct status __iomem *p = local->sram + STATUS_BASE;
1763 if (!(pcmcia_dev_present(link))) {
Dominik Brodowski624dd662009-10-24 15:52:44 +02001764 dev_dbg(&link->dev, "ray_cs net_device_stats - device not present\n");
John Daiker141fa612009-03-10 06:59:54 -07001765 return &local->stats;
1766 }
1767 if (readb(&p->mrx_overflow_for_host)) {
1768 local->stats.rx_over_errors += swab16(readw(&p->mrx_overflow));
1769 writeb(0, &p->mrx_overflow);
1770 writeb(0, &p->mrx_overflow_for_host);
1771 }
1772 if (readb(&p->mrx_checksum_error_for_host)) {
1773 local->stats.rx_crc_errors +=
1774 swab16(readw(&p->mrx_checksum_error));
1775 writeb(0, &p->mrx_checksum_error);
1776 writeb(0, &p->mrx_checksum_error_for_host);
1777 }
1778 if (readb(&p->rx_hec_error_for_host)) {
1779 local->stats.rx_frame_errors += swab16(readw(&p->rx_hec_error));
1780 writeb(0, &p->rx_hec_error);
1781 writeb(0, &p->rx_hec_error_for_host);
1782 }
1783 return &local->stats;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001784}
John Daiker141fa612009-03-10 06:59:54 -07001785
Linus Torvalds1da177e2005-04-16 15:20:36 -07001786/*===========================================================================*/
John Daiker141fa612009-03-10 06:59:54 -07001787static void ray_update_parm(struct net_device *dev, UCHAR objid, UCHAR *value,
1788 int len)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001789{
John Daiker141fa612009-03-10 06:59:54 -07001790 ray_dev_t *local = netdev_priv(dev);
1791 struct pcmcia_device *link = local->finder;
1792 int ccsindex;
1793 int i;
1794 struct ccs __iomem *pccs;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001795
John Daiker141fa612009-03-10 06:59:54 -07001796 if (!(pcmcia_dev_present(link))) {
Dominik Brodowski624dd662009-10-24 15:52:44 +02001797 dev_dbg(&link->dev, "ray_update_parm - device not present\n");
John Daiker141fa612009-03-10 06:59:54 -07001798 return;
1799 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001800
John Daiker141fa612009-03-10 06:59:54 -07001801 if ((ccsindex = get_free_ccs(local)) < 0) {
Dominik Brodowski624dd662009-10-24 15:52:44 +02001802 dev_dbg(&link->dev, "ray_update_parm - No free ccs\n");
John Daiker141fa612009-03-10 06:59:54 -07001803 return;
1804 }
1805 pccs = ccs_base(local) + ccsindex;
1806 writeb(CCS_UPDATE_PARAMS, &pccs->cmd);
1807 writeb(objid, &pccs->var.update_param.object_id);
1808 writeb(1, &pccs->var.update_param.number_objects);
1809 writeb(0, &pccs->var.update_param.failure_cause);
1810 for (i = 0; i < len; i++) {
1811 writeb(value[i], local->sram + HOST_TO_ECF_BASE);
1812 }
1813 /* Interrupt the firmware to process the command */
1814 if (interrupt_ecf(local, ccsindex)) {
Dominik Brodowski624dd662009-10-24 15:52:44 +02001815 dev_dbg(&link->dev, "ray_cs associate failed - ECF not ready for intr\n");
John Daiker141fa612009-03-10 06:59:54 -07001816 writeb(CCS_BUFFER_FREE, &(pccs++)->buffer_status);
1817 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001818}
John Daiker141fa612009-03-10 06:59:54 -07001819
Linus Torvalds1da177e2005-04-16 15:20:36 -07001820/*===========================================================================*/
1821static void ray_update_multi_list(struct net_device *dev, int all)
1822{
John Daiker141fa612009-03-10 06:59:54 -07001823 int ccsindex;
1824 struct ccs __iomem *pccs;
John Daiker141fa612009-03-10 06:59:54 -07001825 ray_dev_t *local = netdev_priv(dev);
1826 struct pcmcia_device *link = local->finder;
1827 void __iomem *p = local->sram + HOST_TO_ECF_BASE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001828
John Daiker141fa612009-03-10 06:59:54 -07001829 if (!(pcmcia_dev_present(link))) {
Dominik Brodowski624dd662009-10-24 15:52:44 +02001830 dev_dbg(&link->dev, "ray_update_multi_list - device not present\n");
John Daiker141fa612009-03-10 06:59:54 -07001831 return;
1832 } else
Dominik Brodowski624dd662009-10-24 15:52:44 +02001833 dev_dbg(&link->dev, "ray_update_multi_list(%p)\n", dev);
John Daiker141fa612009-03-10 06:59:54 -07001834 if ((ccsindex = get_free_ccs(local)) < 0) {
Dominik Brodowski624dd662009-10-24 15:52:44 +02001835 dev_dbg(&link->dev, "ray_update_multi - No free ccs\n");
John Daiker141fa612009-03-10 06:59:54 -07001836 return;
1837 }
1838 pccs = ccs_base(local) + ccsindex;
1839 writeb(CCS_UPDATE_MULTICAST_LIST, &pccs->cmd);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001840
John Daiker141fa612009-03-10 06:59:54 -07001841 if (all) {
1842 writeb(0xff, &pccs->var);
1843 local->num_multi = 0xff;
1844 } else {
Jiri Pirko22bedad2010-04-01 21:22:57 +00001845 struct netdev_hw_addr *ha;
Jiri Pirko655ffee2010-02-27 07:35:45 +00001846 int i = 0;
1847
John Daiker141fa612009-03-10 06:59:54 -07001848 /* Copy the kernel's list of MC addresses to card */
Jiri Pirko22bedad2010-04-01 21:22:57 +00001849 netdev_for_each_mc_addr(ha, dev) {
1850 memcpy_toio(p, ha->addr, ETH_ALEN);
Dominik Brodowski624dd662009-10-24 15:52:44 +02001851 dev_dbg(&link->dev,
John Daiker141fa612009-03-10 06:59:54 -07001852 "ray_update_multi add addr %02x%02x%02x%02x%02x%02x\n",
Jiri Pirko22bedad2010-04-01 21:22:57 +00001853 ha->addr[0], ha->addr[1],
1854 ha->addr[2], ha->addr[3],
1855 ha->addr[4], ha->addr[5]);
John Daiker141fa612009-03-10 06:59:54 -07001856 p += ETH_ALEN;
1857 i++;
1858 }
1859 if (i > 256 / ADDRLEN)
1860 i = 256 / ADDRLEN;
1861 writeb((UCHAR) i, &pccs->var);
Dominik Brodowski624dd662009-10-24 15:52:44 +02001862 dev_dbg(&link->dev, "ray_cs update_multi %d addresses in list\n", i);
John Daiker141fa612009-03-10 06:59:54 -07001863 /* Interrupt the firmware to process the command */
1864 local->num_multi = i;
1865 }
1866 if (interrupt_ecf(local, ccsindex)) {
Dominik Brodowski624dd662009-10-24 15:52:44 +02001867 dev_dbg(&link->dev,
John Daiker141fa612009-03-10 06:59:54 -07001868 "ray_cs update_multi failed - ECF not ready for intr\n");
1869 writeb(CCS_BUFFER_FREE, &(pccs++)->buffer_status);
1870 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001871} /* end ray_update_multi_list */
John Daiker141fa612009-03-10 06:59:54 -07001872
Linus Torvalds1da177e2005-04-16 15:20:36 -07001873/*===========================================================================*/
1874static void set_multicast_list(struct net_device *dev)
1875{
John Daiker141fa612009-03-10 06:59:54 -07001876 ray_dev_t *local = netdev_priv(dev);
1877 UCHAR promisc;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001878
Dominik Brodowski624dd662009-10-24 15:52:44 +02001879 pr_debug("ray_cs set_multicast_list(%p)\n", dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001880
John Daiker141fa612009-03-10 06:59:54 -07001881 if (dev->flags & IFF_PROMISC) {
1882 if (local->sparm.b5.a_promiscuous_mode == 0) {
Dominik Brodowski624dd662009-10-24 15:52:44 +02001883 pr_debug("ray_cs set_multicast_list promisc on\n");
John Daiker141fa612009-03-10 06:59:54 -07001884 local->sparm.b5.a_promiscuous_mode = 1;
1885 promisc = 1;
1886 ray_update_parm(dev, OBJID_promiscuous_mode,
1887 &promisc, sizeof(promisc));
1888 }
1889 } else {
1890 if (local->sparm.b5.a_promiscuous_mode == 1) {
Dominik Brodowski624dd662009-10-24 15:52:44 +02001891 pr_debug("ray_cs set_multicast_list promisc off\n");
John Daiker141fa612009-03-10 06:59:54 -07001892 local->sparm.b5.a_promiscuous_mode = 0;
1893 promisc = 0;
1894 ray_update_parm(dev, OBJID_promiscuous_mode,
1895 &promisc, sizeof(promisc));
1896 }
1897 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001898
John Daiker141fa612009-03-10 06:59:54 -07001899 if (dev->flags & IFF_ALLMULTI)
1900 ray_update_multi_list(dev, 1);
1901 else {
Jiri Pirko4cd24ea2010-02-08 04:30:35 +00001902 if (local->num_multi != netdev_mc_count(dev))
John Daiker141fa612009-03-10 06:59:54 -07001903 ray_update_multi_list(dev, 0);
1904 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001905} /* end set_multicast_list */
John Daiker141fa612009-03-10 06:59:54 -07001906
Linus Torvalds1da177e2005-04-16 15:20:36 -07001907/*=============================================================================
1908 * All routines below here are run at interrupt time.
1909=============================================================================*/
David Howells7d12e782006-10-05 14:55:46 +01001910static irqreturn_t ray_interrupt(int irq, void *dev_id)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001911{
John Daiker141fa612009-03-10 06:59:54 -07001912 struct net_device *dev = (struct net_device *)dev_id;
1913 struct pcmcia_device *link;
1914 ray_dev_t *local;
1915 struct ccs __iomem *pccs;
1916 struct rcs __iomem *prcs;
1917 UCHAR rcsindex;
1918 UCHAR tmp;
1919 UCHAR cmd;
1920 UCHAR status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001921
John Daiker141fa612009-03-10 06:59:54 -07001922 if (dev == NULL) /* Note that we want interrupts with dev->start == 0 */
1923 return IRQ_NONE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001924
Dominik Brodowski624dd662009-10-24 15:52:44 +02001925 pr_debug("ray_cs: interrupt for *dev=%p\n", dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001926
John Daiker141fa612009-03-10 06:59:54 -07001927 local = netdev_priv(dev);
1928 link = (struct pcmcia_device *)local->finder;
1929 if (!pcmcia_dev_present(link)) {
Dominik Brodowski624dd662009-10-24 15:52:44 +02001930 pr_debug(
1931 "ray_cs interrupt from device not present or suspended.\n");
John Daiker141fa612009-03-10 06:59:54 -07001932 return IRQ_NONE;
1933 }
1934 rcsindex = readb(&((struct scb __iomem *)(local->sram))->rcs_index);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001935
John Daiker141fa612009-03-10 06:59:54 -07001936 if (rcsindex >= (NUMBER_OF_CCS + NUMBER_OF_RCS)) {
Dominik Brodowski624dd662009-10-24 15:52:44 +02001937 dev_dbg(&link->dev, "ray_cs interrupt bad rcsindex = 0x%x\n", rcsindex);
John Daiker141fa612009-03-10 06:59:54 -07001938 clear_interrupt(local);
1939 return IRQ_HANDLED;
1940 }
1941 if (rcsindex < NUMBER_OF_CCS) { /* If it's a returned CCS */
1942 pccs = ccs_base(local) + rcsindex;
1943 cmd = readb(&pccs->cmd);
1944 status = readb(&pccs->buffer_status);
1945 switch (cmd) {
1946 case CCS_DOWNLOAD_STARTUP_PARAMS: /* Happens in firmware someday */
1947 del_timer(&local->timer);
1948 if (status == CCS_COMMAND_COMPLETE) {
Dominik Brodowski624dd662009-10-24 15:52:44 +02001949 dev_dbg(&link->dev,
John Daiker141fa612009-03-10 06:59:54 -07001950 "ray_cs interrupt download_startup_parameters OK\n");
1951 } else {
Dominik Brodowski624dd662009-10-24 15:52:44 +02001952 dev_dbg(&link->dev,
John Daiker141fa612009-03-10 06:59:54 -07001953 "ray_cs interrupt download_startup_parameters fail\n");
1954 }
1955 break;
1956 case CCS_UPDATE_PARAMS:
Dominik Brodowski624dd662009-10-24 15:52:44 +02001957 dev_dbg(&link->dev, "ray_cs interrupt update params done\n");
John Daiker141fa612009-03-10 06:59:54 -07001958 if (status != CCS_COMMAND_COMPLETE) {
1959 tmp =
1960 readb(&pccs->var.update_param.
1961 failure_cause);
Dominik Brodowski624dd662009-10-24 15:52:44 +02001962 dev_dbg(&link->dev,
John Daiker141fa612009-03-10 06:59:54 -07001963 "ray_cs interrupt update params failed - reason %d\n",
1964 tmp);
1965 }
1966 break;
1967 case CCS_REPORT_PARAMS:
Dominik Brodowski624dd662009-10-24 15:52:44 +02001968 dev_dbg(&link->dev, "ray_cs interrupt report params done\n");
John Daiker141fa612009-03-10 06:59:54 -07001969 break;
1970 case CCS_UPDATE_MULTICAST_LIST: /* Note that this CCS isn't returned */
Dominik Brodowski624dd662009-10-24 15:52:44 +02001971 dev_dbg(&link->dev,
John Daiker141fa612009-03-10 06:59:54 -07001972 "ray_cs interrupt CCS Update Multicast List done\n");
1973 break;
1974 case CCS_UPDATE_POWER_SAVINGS_MODE:
Dominik Brodowski624dd662009-10-24 15:52:44 +02001975 dev_dbg(&link->dev,
John Daiker141fa612009-03-10 06:59:54 -07001976 "ray_cs interrupt update power save mode done\n");
1977 break;
1978 case CCS_START_NETWORK:
1979 case CCS_JOIN_NETWORK:
1980 if (status == CCS_COMMAND_COMPLETE) {
1981 if (readb
1982 (&pccs->var.start_network.net_initiated) ==
1983 1) {
Dominik Brodowski624dd662009-10-24 15:52:44 +02001984 dev_dbg(&link->dev,
John Daiker141fa612009-03-10 06:59:54 -07001985 "ray_cs interrupt network \"%s\" started\n",
1986 local->sparm.b4.a_current_ess_id);
1987 } else {
Dominik Brodowski624dd662009-10-24 15:52:44 +02001988 dev_dbg(&link->dev,
John Daiker141fa612009-03-10 06:59:54 -07001989 "ray_cs interrupt network \"%s\" joined\n",
1990 local->sparm.b4.a_current_ess_id);
1991 }
1992 memcpy_fromio(&local->bss_id,
1993 pccs->var.start_network.bssid,
1994 ADDRLEN);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001995
John Daiker141fa612009-03-10 06:59:54 -07001996 if (local->fw_ver == 0x55)
1997 local->net_default_tx_rate = 3;
1998 else
1999 local->net_default_tx_rate =
2000 readb(&pccs->var.start_network.
2001 net_default_tx_rate);
2002 local->encryption =
2003 readb(&pccs->var.start_network.encryption);
2004 if (!sniffer && (local->net_type == INFRA)
2005 && !(local->sparm.b4.a_acting_as_ap_status)) {
2006 authenticate(local);
2007 }
2008 local->card_status = CARD_ACQ_COMPLETE;
2009 } else {
2010 local->card_status = CARD_ACQ_FAILED;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002011
John Daiker141fa612009-03-10 06:59:54 -07002012 del_timer(&local->timer);
2013 local->timer.expires = jiffies + HZ * 5;
2014 local->timer.data = (long)local;
2015 if (status == CCS_START_NETWORK) {
Dominik Brodowski624dd662009-10-24 15:52:44 +02002016 dev_dbg(&link->dev,
John Daiker141fa612009-03-10 06:59:54 -07002017 "ray_cs interrupt network \"%s\" start failed\n",
2018 local->sparm.b4.a_current_ess_id);
2019 local->timer.function = &start_net;
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 network \"%s\" join failed\n",
2023 local->sparm.b4.a_current_ess_id);
2024 local->timer.function = &join_net;
2025 }
2026 add_timer(&local->timer);
2027 }
2028 break;
2029 case CCS_START_ASSOCIATION:
2030 if (status == CCS_COMMAND_COMPLETE) {
2031 local->card_status = CARD_ASSOC_COMPLETE;
Dominik Brodowski624dd662009-10-24 15:52:44 +02002032 dev_dbg(&link->dev, "ray_cs association successful\n");
John Daiker141fa612009-03-10 06:59:54 -07002033 } else {
Dominik Brodowski624dd662009-10-24 15:52:44 +02002034 dev_dbg(&link->dev, "ray_cs association failed,\n");
John Daiker141fa612009-03-10 06:59:54 -07002035 local->card_status = CARD_ASSOC_FAILED;
2036 join_net((u_long) local);
2037 }
2038 break;
2039 case CCS_TX_REQUEST:
2040 if (status == CCS_COMMAND_COMPLETE) {
Dominik Brodowski624dd662009-10-24 15:52:44 +02002041 dev_dbg(&link->dev,
John Daiker141fa612009-03-10 06:59:54 -07002042 "ray_cs interrupt tx request complete\n");
2043 } else {
Dominik Brodowski624dd662009-10-24 15:52:44 +02002044 dev_dbg(&link->dev,
John Daiker141fa612009-03-10 06:59:54 -07002045 "ray_cs interrupt tx request failed\n");
2046 }
2047 if (!sniffer)
2048 netif_start_queue(dev);
2049 netif_wake_queue(dev);
2050 break;
2051 case CCS_TEST_MEMORY:
Dominik Brodowski624dd662009-10-24 15:52:44 +02002052 dev_dbg(&link->dev, "ray_cs interrupt mem test done\n");
John Daiker141fa612009-03-10 06:59:54 -07002053 break;
2054 case CCS_SHUTDOWN:
Dominik Brodowski624dd662009-10-24 15:52:44 +02002055 dev_dbg(&link->dev,
John Daiker141fa612009-03-10 06:59:54 -07002056 "ray_cs interrupt Unexpected CCS returned - Shutdown\n");
2057 break;
2058 case CCS_DUMP_MEMORY:
Dominik Brodowski624dd662009-10-24 15:52:44 +02002059 dev_dbg(&link->dev, "ray_cs interrupt dump memory done\n");
John Daiker141fa612009-03-10 06:59:54 -07002060 break;
2061 case CCS_START_TIMER:
Dominik Brodowski624dd662009-10-24 15:52:44 +02002062 dev_dbg(&link->dev,
John Daiker141fa612009-03-10 06:59:54 -07002063 "ray_cs interrupt DING - raylink timer expired\n");
2064 break;
2065 default:
Dominik Brodowski624dd662009-10-24 15:52:44 +02002066 dev_dbg(&link->dev,
John Daiker141fa612009-03-10 06:59:54 -07002067 "ray_cs interrupt Unexpected CCS 0x%x returned 0x%x\n",
2068 rcsindex, cmd);
2069 }
2070 writeb(CCS_BUFFER_FREE, &pccs->buffer_status);
2071 } else { /* It's an RCS */
2072
2073 prcs = rcs_base(local) + rcsindex;
2074
2075 switch (readb(&prcs->interrupt_id)) {
2076 case PROCESS_RX_PACKET:
2077 ray_rx(dev, local, prcs);
2078 break;
2079 case REJOIN_NET_COMPLETE:
Dominik Brodowski624dd662009-10-24 15:52:44 +02002080 dev_dbg(&link->dev, "ray_cs interrupt rejoin net complete\n");
John Daiker141fa612009-03-10 06:59:54 -07002081 local->card_status = CARD_ACQ_COMPLETE;
2082 /* do we need to clear tx buffers CCS's? */
2083 if (local->sparm.b4.a_network_type == ADHOC) {
2084 if (!sniffer)
2085 netif_start_queue(dev);
2086 } else {
2087 memcpy_fromio(&local->bss_id,
2088 prcs->var.rejoin_net_complete.
2089 bssid, ADDRLEN);
Dominik Brodowski624dd662009-10-24 15:52:44 +02002090 dev_dbg(&link->dev,
John Daiker141fa612009-03-10 06:59:54 -07002091 "ray_cs new BSSID = %02x%02x%02x%02x%02x%02x\n",
2092 local->bss_id[0], local->bss_id[1],
2093 local->bss_id[2], local->bss_id[3],
2094 local->bss_id[4], local->bss_id[5]);
2095 if (!sniffer)
2096 authenticate(local);
2097 }
2098 break;
2099 case ROAMING_INITIATED:
Dominik Brodowski624dd662009-10-24 15:52:44 +02002100 dev_dbg(&link->dev, "ray_cs interrupt roaming initiated\n");
John Daiker141fa612009-03-10 06:59:54 -07002101 netif_stop_queue(dev);
2102 local->card_status = CARD_DOING_ACQ;
2103 break;
2104 case JAPAN_CALL_SIGN_RXD:
Dominik Brodowski624dd662009-10-24 15:52:44 +02002105 dev_dbg(&link->dev, "ray_cs interrupt japan call sign rx\n");
John Daiker141fa612009-03-10 06:59:54 -07002106 break;
2107 default:
Dominik Brodowski624dd662009-10-24 15:52:44 +02002108 dev_dbg(&link->dev,
John Daiker141fa612009-03-10 06:59:54 -07002109 "ray_cs Unexpected interrupt for RCS 0x%x cmd = 0x%x\n",
2110 rcsindex,
2111 (unsigned int)readb(&prcs->interrupt_id));
2112 break;
2113 }
2114 writeb(CCS_BUFFER_FREE, &prcs->buffer_status);
2115 }
2116 clear_interrupt(local);
2117 return IRQ_HANDLED;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002118} /* ray_interrupt */
John Daiker141fa612009-03-10 06:59:54 -07002119
Linus Torvalds1da177e2005-04-16 15:20:36 -07002120/*===========================================================================*/
John Daiker141fa612009-03-10 06:59:54 -07002121static void ray_rx(struct net_device *dev, ray_dev_t *local,
2122 struct rcs __iomem *prcs)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002123{
John Daiker141fa612009-03-10 06:59:54 -07002124 int rx_len;
2125 unsigned int pkt_addr;
2126 void __iomem *pmsg;
Dominik Brodowski624dd662009-10-24 15:52:44 +02002127 pr_debug("ray_rx process rx packet\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002128
John Daiker141fa612009-03-10 06:59:54 -07002129 /* Calculate address of packet within Rx buffer */
2130 pkt_addr = ((readb(&prcs->var.rx_packet.rx_data_ptr[0]) << 8)
2131 + readb(&prcs->var.rx_packet.rx_data_ptr[1])) & RX_BUFF_END;
2132 /* Length of first packet fragment */
2133 rx_len = (readb(&prcs->var.rx_packet.rx_data_length[0]) << 8)
2134 + readb(&prcs->var.rx_packet.rx_data_length[1]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002135
John Daiker141fa612009-03-10 06:59:54 -07002136 local->last_rsl = readb(&prcs->var.rx_packet.rx_sig_lev);
2137 pmsg = local->rmem + pkt_addr;
2138 switch (readb(pmsg)) {
2139 case DATA_TYPE:
Dominik Brodowski624dd662009-10-24 15:52:44 +02002140 pr_debug("ray_rx data type\n");
John Daiker141fa612009-03-10 06:59:54 -07002141 rx_data(dev, prcs, pkt_addr, rx_len);
2142 break;
2143 case AUTHENTIC_TYPE:
Dominik Brodowski624dd662009-10-24 15:52:44 +02002144 pr_debug("ray_rx authentic type\n");
John Daiker141fa612009-03-10 06:59:54 -07002145 if (sniffer)
2146 rx_data(dev, prcs, pkt_addr, rx_len);
2147 else
2148 rx_authenticate(local, prcs, pkt_addr, rx_len);
2149 break;
2150 case DEAUTHENTIC_TYPE:
Dominik Brodowski624dd662009-10-24 15:52:44 +02002151 pr_debug("ray_rx deauth type\n");
John Daiker141fa612009-03-10 06:59:54 -07002152 if (sniffer)
2153 rx_data(dev, prcs, pkt_addr, rx_len);
2154 else
2155 rx_deauthenticate(local, prcs, pkt_addr, rx_len);
2156 break;
2157 case NULL_MSG_TYPE:
Dominik Brodowski624dd662009-10-24 15:52:44 +02002158 pr_debug("ray_cs rx NULL msg\n");
John Daiker141fa612009-03-10 06:59:54 -07002159 break;
2160 case BEACON_TYPE:
Dominik Brodowski624dd662009-10-24 15:52:44 +02002161 pr_debug("ray_rx beacon type\n");
John Daiker141fa612009-03-10 06:59:54 -07002162 if (sniffer)
2163 rx_data(dev, prcs, pkt_addr, rx_len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002164
John Daiker141fa612009-03-10 06:59:54 -07002165 copy_from_rx_buff(local, (UCHAR *) &local->last_bcn, pkt_addr,
2166 rx_len < sizeof(struct beacon_rx) ?
2167 rx_len : sizeof(struct beacon_rx));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002168
John Daiker141fa612009-03-10 06:59:54 -07002169 local->beacon_rxed = 1;
2170 /* Get the statistics so the card counters never overflow */
2171 ray_get_stats(dev);
2172 break;
2173 default:
Dominik Brodowski624dd662009-10-24 15:52:44 +02002174 pr_debug("ray_cs unknown pkt type %2x\n",
John Daiker141fa612009-03-10 06:59:54 -07002175 (unsigned int)readb(pmsg));
2176 break;
2177 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002178
2179} /* end ray_rx */
John Daiker141fa612009-03-10 06:59:54 -07002180
Linus Torvalds1da177e2005-04-16 15:20:36 -07002181/*===========================================================================*/
John Daiker141fa612009-03-10 06:59:54 -07002182static void rx_data(struct net_device *dev, struct rcs __iomem *prcs,
2183 unsigned int pkt_addr, int rx_len)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002184{
John Daiker141fa612009-03-10 06:59:54 -07002185 struct sk_buff *skb = NULL;
2186 struct rcs __iomem *prcslink = prcs;
2187 ray_dev_t *local = netdev_priv(dev);
2188 UCHAR *rx_ptr;
2189 int total_len;
2190 int tmp;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002191#ifdef WIRELESS_SPY
John Daiker141fa612009-03-10 06:59:54 -07002192 int siglev = local->last_rsl;
2193 u_char linksrcaddr[ETH_ALEN]; /* Other end of the wireless link */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002194#endif
2195
John Daiker141fa612009-03-10 06:59:54 -07002196 if (!sniffer) {
2197 if (translate) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002198/* TBD length needs fixing for translated header */
John Daiker141fa612009-03-10 06:59:54 -07002199 if (rx_len < (ETH_HLEN + RX_MAC_HEADER_LENGTH) ||
2200 rx_len >
2201 (dev->mtu + RX_MAC_HEADER_LENGTH + ETH_HLEN +
2202 FCS_LEN)) {
Dominik Brodowski624dd662009-10-24 15:52:44 +02002203 pr_debug(
Frans Popcb01b092010-03-24 19:46:34 +01002204 "ray_cs invalid packet length %d received\n",
John Daiker141fa612009-03-10 06:59:54 -07002205 rx_len);
2206 return;
2207 }
2208 } else { /* encapsulated ethernet */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002209
John Daiker141fa612009-03-10 06:59:54 -07002210 if (rx_len < (ETH_HLEN + RX_MAC_HEADER_LENGTH) ||
2211 rx_len >
2212 (dev->mtu + RX_MAC_HEADER_LENGTH + ETH_HLEN +
2213 FCS_LEN)) {
Dominik Brodowski624dd662009-10-24 15:52:44 +02002214 pr_debug(
Frans Popcb01b092010-03-24 19:46:34 +01002215 "ray_cs invalid packet length %d received\n",
John Daiker141fa612009-03-10 06:59:54 -07002216 rx_len);
2217 return;
2218 }
2219 }
2220 }
Dominik Brodowski624dd662009-10-24 15:52:44 +02002221 pr_debug("ray_cs rx_data packet\n");
John Daiker141fa612009-03-10 06:59:54 -07002222 /* If fragmented packet, verify sizes of fragments add up */
2223 if (readb(&prcs->var.rx_packet.next_frag_rcs_index) != 0xFF) {
Dominik Brodowski624dd662009-10-24 15:52:44 +02002224 pr_debug("ray_cs rx'ed fragment\n");
John Daiker141fa612009-03-10 06:59:54 -07002225 tmp = (readb(&prcs->var.rx_packet.totalpacketlength[0]) << 8)
2226 + readb(&prcs->var.rx_packet.totalpacketlength[1]);
2227 total_len = tmp;
2228 prcslink = prcs;
2229 do {
2230 tmp -=
2231 (readb(&prcslink->var.rx_packet.rx_data_length[0])
2232 << 8)
2233 + readb(&prcslink->var.rx_packet.rx_data_length[1]);
2234 if (readb(&prcslink->var.rx_packet.next_frag_rcs_index)
2235 == 0xFF || tmp < 0)
2236 break;
2237 prcslink = rcs_base(local)
2238 + readb(&prcslink->link_field);
2239 } while (1);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002240
John Daiker141fa612009-03-10 06:59:54 -07002241 if (tmp < 0) {
Dominik Brodowski624dd662009-10-24 15:52:44 +02002242 pr_debug(
John Daiker141fa612009-03-10 06:59:54 -07002243 "ray_cs rx_data fragment lengths don't add up\n");
2244 local->stats.rx_dropped++;
2245 release_frag_chain(local, prcs);
2246 return;
2247 }
2248 } else { /* Single unfragmented packet */
2249 total_len = rx_len;
2250 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002251
John Daiker141fa612009-03-10 06:59:54 -07002252 skb = dev_alloc_skb(total_len + 5);
2253 if (skb == NULL) {
Dominik Brodowski624dd662009-10-24 15:52:44 +02002254 pr_debug("ray_cs rx_data could not allocate skb\n");
John Daiker141fa612009-03-10 06:59:54 -07002255 local->stats.rx_dropped++;
2256 if (readb(&prcs->var.rx_packet.next_frag_rcs_index) != 0xFF)
2257 release_frag_chain(local, prcs);
2258 return;
2259 }
2260 skb_reserve(skb, 2); /* Align IP on 16 byte (TBD check this) */
2261
Dominik Brodowski624dd662009-10-24 15:52:44 +02002262 pr_debug("ray_cs rx_data total_len = %x, rx_len = %x\n", total_len,
John Daiker141fa612009-03-10 06:59:54 -07002263 rx_len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002264
2265/************************/
John Daiker141fa612009-03-10 06:59:54 -07002266 /* Reserve enough room for the whole damn packet. */
2267 rx_ptr = skb_put(skb, total_len);
2268 /* Copy the whole packet to sk_buff */
2269 rx_ptr +=
2270 copy_from_rx_buff(local, rx_ptr, pkt_addr & RX_BUFF_END, rx_len);
2271 /* Get source address */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002272#ifdef WIRELESS_SPY
John Daiker141fa612009-03-10 06:59:54 -07002273 skb_copy_from_linear_data_offset(skb,
2274 offsetof(struct mac_header, addr_2),
2275 linksrcaddr, ETH_ALEN);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002276#endif
John Daiker141fa612009-03-10 06:59:54 -07002277 /* Now, deal with encapsulation/translation/sniffer */
2278 if (!sniffer) {
2279 if (!translate) {
2280 /* Encapsulated ethernet, so just lop off 802.11 MAC header */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002281/* TBD reserve skb_reserve( skb, RX_MAC_HEADER_LENGTH); */
John Daiker141fa612009-03-10 06:59:54 -07002282 skb_pull(skb, RX_MAC_HEADER_LENGTH);
2283 } else {
2284 /* Do translation */
2285 untranslate(local, skb, total_len);
2286 }
2287 } else { /* sniffer mode, so just pass whole packet */
2288 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002289
2290/************************/
John Daiker141fa612009-03-10 06:59:54 -07002291 /* Now pick up the rest of the fragments if any */
2292 tmp = 17;
2293 if (readb(&prcs->var.rx_packet.next_frag_rcs_index) != 0xFF) {
2294 prcslink = prcs;
Dominik Brodowski624dd662009-10-24 15:52:44 +02002295 pr_debug("ray_cs rx_data in fragment loop\n");
John Daiker141fa612009-03-10 06:59:54 -07002296 do {
2297 prcslink = rcs_base(local)
2298 +
2299 readb(&prcslink->var.rx_packet.next_frag_rcs_index);
2300 rx_len =
2301 ((readb(&prcslink->var.rx_packet.rx_data_length[0])
2302 << 8)
2303 +
2304 readb(&prcslink->var.rx_packet.rx_data_length[1]))
2305 & RX_BUFF_END;
2306 pkt_addr =
2307 ((readb(&prcslink->var.rx_packet.rx_data_ptr[0]) <<
2308 8)
2309 + readb(&prcslink->var.rx_packet.rx_data_ptr[1]))
2310 & RX_BUFF_END;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002311
John Daiker141fa612009-03-10 06:59:54 -07002312 rx_ptr +=
2313 copy_from_rx_buff(local, rx_ptr, pkt_addr, rx_len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002314
John Daiker141fa612009-03-10 06:59:54 -07002315 } while (tmp-- &&
2316 readb(&prcslink->var.rx_packet.next_frag_rcs_index) !=
2317 0xFF);
2318 release_frag_chain(local, prcs);
2319 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002320
John Daiker141fa612009-03-10 06:59:54 -07002321 skb->protocol = eth_type_trans(skb, dev);
2322 netif_rx(skb);
2323 local->stats.rx_packets++;
2324 local->stats.rx_bytes += total_len;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002325
John Daiker141fa612009-03-10 06:59:54 -07002326 /* Gather signal strength per address */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002327#ifdef WIRELESS_SPY
John Daiker141fa612009-03-10 06:59:54 -07002328 /* For the Access Point or the node having started the ad-hoc net
2329 * note : ad-hoc work only in some specific configurations, but we
2330 * kludge in ray_get_wireless_stats... */
2331 if (!memcmp(linksrcaddr, local->bss_id, ETH_ALEN)) {
2332 /* Update statistics */
2333 /*local->wstats.qual.qual = none ? */
2334 local->wstats.qual.level = siglev;
2335 /*local->wstats.qual.noise = none ? */
2336 local->wstats.qual.updated = 0x2;
2337 }
2338 /* Now, update the spy stuff */
2339 {
2340 struct iw_quality wstats;
2341 wstats.level = siglev;
2342 /* wstats.noise = none ? */
2343 /* wstats.qual = none ? */
2344 wstats.updated = 0x2;
2345 /* Update spy records */
2346 wireless_spy_update(dev, linksrcaddr, &wstats);
2347 }
2348#endif /* WIRELESS_SPY */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002349} /* end rx_data */
John Daiker141fa612009-03-10 06:59:54 -07002350
Linus Torvalds1da177e2005-04-16 15:20:36 -07002351/*===========================================================================*/
2352static void untranslate(ray_dev_t *local, struct sk_buff *skb, int len)
2353{
John Daiker141fa612009-03-10 06:59:54 -07002354 snaphdr_t *psnap = (snaphdr_t *) (skb->data + RX_MAC_HEADER_LENGTH);
2355 struct ieee80211_hdr *pmac = (struct ieee80211_hdr *)skb->data;
2356 __be16 type = *(__be16 *) psnap->ethertype;
2357 int delta;
2358 struct ethhdr *peth;
2359 UCHAR srcaddr[ADDRLEN];
2360 UCHAR destaddr[ADDRLEN];
2361 static UCHAR org_bridge[3] = { 0, 0, 0xf8 };
2362 static UCHAR org_1042[3] = { 0, 0, 0 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002363
John Daiker141fa612009-03-10 06:59:54 -07002364 memcpy(destaddr, ieee80211_get_DA(pmac), ADDRLEN);
2365 memcpy(srcaddr, ieee80211_get_SA(pmac), ADDRLEN);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002366
Dominik Brodowski624dd662009-10-24 15:52:44 +02002367#if 0
2368 if {
Joe Perchesad361c92009-07-06 13:05:40 -07002369 print_hex_dump(KERN_DEBUG, "skb->data before untranslate: ",
2370 DUMP_PREFIX_NONE, 16, 1,
2371 skb->data, 64, true);
2372 printk(KERN_DEBUG
John Daiker141fa612009-03-10 06:59:54 -07002373 "type = %08x, xsap = %02x%02x%02x, org = %02x02x02x\n",
2374 ntohs(type), psnap->dsap, psnap->ssap, psnap->ctrl,
2375 psnap->org[0], psnap->org[1], psnap->org[2]);
2376 printk(KERN_DEBUG "untranslate skb->data = %p\n", skb->data);
2377 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002378#endif
2379
John Daiker141fa612009-03-10 06:59:54 -07002380 if (psnap->dsap != 0xaa || psnap->ssap != 0xaa || psnap->ctrl != 3) {
2381 /* not a snap type so leave it alone */
Dominik Brodowski624dd662009-10-24 15:52:44 +02002382 pr_debug("ray_cs untranslate NOT SNAP %02x %02x %02x\n",
John Daiker141fa612009-03-10 06:59:54 -07002383 psnap->dsap, psnap->ssap, psnap->ctrl);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002384
John Daiker141fa612009-03-10 06:59:54 -07002385 delta = RX_MAC_HEADER_LENGTH - ETH_HLEN;
2386 peth = (struct ethhdr *)(skb->data + delta);
2387 peth->h_proto = htons(len - RX_MAC_HEADER_LENGTH);
2388 } else { /* Its a SNAP */
2389 if (memcmp(psnap->org, org_bridge, 3) == 0) {
2390 /* EtherII and nuke the LLC */
Dominik Brodowski624dd662009-10-24 15:52:44 +02002391 pr_debug("ray_cs untranslate Bridge encap\n");
John Daiker141fa612009-03-10 06:59:54 -07002392 delta = RX_MAC_HEADER_LENGTH
2393 + sizeof(struct snaphdr_t) - ETH_HLEN;
2394 peth = (struct ethhdr *)(skb->data + delta);
2395 peth->h_proto = type;
2396 } else if (memcmp(psnap->org, org_1042, 3) == 0) {
2397 switch (ntohs(type)) {
2398 case ETH_P_IPX:
2399 case ETH_P_AARP:
Dominik Brodowski624dd662009-10-24 15:52:44 +02002400 pr_debug("ray_cs untranslate RFC IPX/AARP\n");
John Daiker141fa612009-03-10 06:59:54 -07002401 delta = RX_MAC_HEADER_LENGTH - ETH_HLEN;
2402 peth = (struct ethhdr *)(skb->data + delta);
2403 peth->h_proto =
2404 htons(len - RX_MAC_HEADER_LENGTH);
2405 break;
2406 default:
Dominik Brodowski624dd662009-10-24 15:52:44 +02002407 pr_debug("ray_cs untranslate RFC default\n");
John Daiker141fa612009-03-10 06:59:54 -07002408 delta = RX_MAC_HEADER_LENGTH +
2409 sizeof(struct snaphdr_t) - ETH_HLEN;
2410 peth = (struct ethhdr *)(skb->data + delta);
2411 peth->h_proto = type;
2412 break;
2413 }
2414 } else {
2415 printk("ray_cs untranslate very confused by packet\n");
2416 delta = RX_MAC_HEADER_LENGTH - ETH_HLEN;
2417 peth = (struct ethhdr *)(skb->data + delta);
2418 peth->h_proto = type;
2419 }
Al Viro7698d692007-12-29 04:55:50 -05002420 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002421/* TBD reserve skb_reserve(skb, delta); */
John Daiker141fa612009-03-10 06:59:54 -07002422 skb_pull(skb, delta);
Dominik Brodowski624dd662009-10-24 15:52:44 +02002423 pr_debug("untranslate after skb_pull(%d), skb->data = %p\n", delta,
John Daiker141fa612009-03-10 06:59:54 -07002424 skb->data);
2425 memcpy(peth->h_dest, destaddr, ADDRLEN);
2426 memcpy(peth->h_source, srcaddr, ADDRLEN);
Dominik Brodowski624dd662009-10-24 15:52:44 +02002427#if 0
2428 {
John Daiker141fa612009-03-10 06:59:54 -07002429 int i;
2430 printk(KERN_DEBUG "skb->data after untranslate:");
2431 for (i = 0; i < 64; i++)
2432 printk("%02x ", skb->data[i]);
2433 printk("\n");
2434 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002435#endif
2436} /* end untranslate */
John Daiker141fa612009-03-10 06:59:54 -07002437
Linus Torvalds1da177e2005-04-16 15:20:36 -07002438/*===========================================================================*/
2439/* Copy data from circular receive buffer to PC memory.
2440 * dest = destination address in PC memory
2441 * pkt_addr = source address in receive buffer
2442 * len = length of packet to copy
2443 */
John Daiker141fa612009-03-10 06:59:54 -07002444static int copy_from_rx_buff(ray_dev_t *local, UCHAR *dest, int pkt_addr,
2445 int length)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002446{
John Daiker141fa612009-03-10 06:59:54 -07002447 int wrap_bytes = (pkt_addr + length) - (RX_BUFF_END + 1);
2448 if (wrap_bytes <= 0) {
2449 memcpy_fromio(dest, local->rmem + pkt_addr, length);
2450 } else { /* Packet wrapped in circular buffer */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002451
John Daiker141fa612009-03-10 06:59:54 -07002452 memcpy_fromio(dest, local->rmem + pkt_addr,
2453 length - wrap_bytes);
2454 memcpy_fromio(dest + length - wrap_bytes, local->rmem,
2455 wrap_bytes);
2456 }
2457 return length;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002458}
John Daiker141fa612009-03-10 06:59:54 -07002459
2460/*===========================================================================*/
2461static void release_frag_chain(ray_dev_t *local, struct rcs __iomem *prcs)
2462{
2463 struct rcs __iomem *prcslink = prcs;
2464 int tmp = 17;
2465 unsigned rcsindex = readb(&prcs->var.rx_packet.next_frag_rcs_index);
2466
2467 while (tmp--) {
2468 writeb(CCS_BUFFER_FREE, &prcslink->buffer_status);
2469 if (rcsindex >= (NUMBER_OF_CCS + NUMBER_OF_RCS)) {
Dominik Brodowski624dd662009-10-24 15:52:44 +02002470 pr_debug("ray_cs interrupt bad rcsindex = 0x%x\n",
John Daiker141fa612009-03-10 06:59:54 -07002471 rcsindex);
2472 break;
2473 }
2474 prcslink = rcs_base(local) + rcsindex;
2475 rcsindex = readb(&prcslink->var.rx_packet.next_frag_rcs_index);
2476 }
2477 writeb(CCS_BUFFER_FREE, &prcslink->buffer_status);
2478}
2479
Linus Torvalds1da177e2005-04-16 15:20:36 -07002480/*===========================================================================*/
2481static void authenticate(ray_dev_t *local)
2482{
John Daiker141fa612009-03-10 06:59:54 -07002483 struct pcmcia_device *link = local->finder;
Dominik Brodowski624dd662009-10-24 15:52:44 +02002484 dev_dbg(&link->dev, "ray_cs Starting authentication.\n");
John Daiker141fa612009-03-10 06:59:54 -07002485 if (!(pcmcia_dev_present(link))) {
Dominik Brodowski624dd662009-10-24 15:52:44 +02002486 dev_dbg(&link->dev, "ray_cs authenticate - device not present\n");
John Daiker141fa612009-03-10 06:59:54 -07002487 return;
2488 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002489
John Daiker141fa612009-03-10 06:59:54 -07002490 del_timer(&local->timer);
2491 if (build_auth_frame(local, local->bss_id, OPEN_AUTH_REQUEST)) {
2492 local->timer.function = &join_net;
2493 } else {
2494 local->timer.function = &authenticate_timeout;
2495 }
2496 local->timer.expires = jiffies + HZ * 2;
2497 local->timer.data = (long)local;
2498 add_timer(&local->timer);
2499 local->authentication_state = AWAITING_RESPONSE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002500} /* end authenticate */
John Daiker141fa612009-03-10 06:59:54 -07002501
Linus Torvalds1da177e2005-04-16 15:20:36 -07002502/*===========================================================================*/
2503static void rx_authenticate(ray_dev_t *local, struct rcs __iomem *prcs,
John Daiker141fa612009-03-10 06:59:54 -07002504 unsigned int pkt_addr, int rx_len)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002505{
John Daiker141fa612009-03-10 06:59:54 -07002506 UCHAR buff[256];
2507 struct rx_msg *msg = (struct rx_msg *)buff;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002508
John Daiker141fa612009-03-10 06:59:54 -07002509 del_timer(&local->timer);
2510
2511 copy_from_rx_buff(local, buff, pkt_addr, rx_len & 0xff);
2512 /* if we are trying to get authenticated */
2513 if (local->sparm.b4.a_network_type == ADHOC) {
Dominik Brodowski624dd662009-10-24 15:52:44 +02002514 pr_debug("ray_cs rx_auth var= %02x %02x %02x %02x %02x %02x\n",
John Daiker141fa612009-03-10 06:59:54 -07002515 msg->var[0], msg->var[1], msg->var[2], msg->var[3],
2516 msg->var[4], msg->var[5]);
2517 if (msg->var[2] == 1) {
Dominik Brodowski624dd662009-10-24 15:52:44 +02002518 pr_debug("ray_cs Sending authentication response.\n");
John Daiker141fa612009-03-10 06:59:54 -07002519 if (!build_auth_frame
2520 (local, msg->mac.addr_2, OPEN_AUTH_RESPONSE)) {
2521 local->authentication_state = NEED_TO_AUTH;
2522 memcpy(local->auth_id, msg->mac.addr_2,
2523 ADDRLEN);
2524 }
2525 }
2526 } else { /* Infrastructure network */
2527
2528 if (local->authentication_state == AWAITING_RESPONSE) {
2529 /* Verify authentication sequence #2 and success */
2530 if (msg->var[2] == 2) {
2531 if ((msg->var[3] | msg->var[4]) == 0) {
Dominik Brodowski624dd662009-10-24 15:52:44 +02002532 pr_debug("Authentication successful\n");
John Daiker141fa612009-03-10 06:59:54 -07002533 local->card_status = CARD_AUTH_COMPLETE;
2534 associate(local);
2535 local->authentication_state =
2536 AUTHENTICATED;
2537 } else {
Dominik Brodowski624dd662009-10-24 15:52:44 +02002538 pr_debug("Authentication refused\n");
John Daiker141fa612009-03-10 06:59:54 -07002539 local->card_status = CARD_AUTH_REFUSED;
2540 join_net((u_long) local);
2541 local->authentication_state =
2542 UNAUTHENTICATED;
2543 }
2544 }
2545 }
2546 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002547
2548} /* end rx_authenticate */
John Daiker141fa612009-03-10 06:59:54 -07002549
Linus Torvalds1da177e2005-04-16 15:20:36 -07002550/*===========================================================================*/
2551static void associate(ray_dev_t *local)
2552{
John Daiker141fa612009-03-10 06:59:54 -07002553 struct ccs __iomem *pccs;
2554 struct pcmcia_device *link = local->finder;
2555 struct net_device *dev = link->priv;
2556 int ccsindex;
2557 if (!(pcmcia_dev_present(link))) {
Dominik Brodowski624dd662009-10-24 15:52:44 +02002558 dev_dbg(&link->dev, "ray_cs associate - device not present\n");
John Daiker141fa612009-03-10 06:59:54 -07002559 return;
2560 }
2561 /* If no tx buffers available, return */
2562 if ((ccsindex = get_free_ccs(local)) < 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002563/* TBD should never be here but... what if we are? */
Dominik Brodowski624dd662009-10-24 15:52:44 +02002564 dev_dbg(&link->dev, "ray_cs associate - No free ccs\n");
John Daiker141fa612009-03-10 06:59:54 -07002565 return;
2566 }
Dominik Brodowski624dd662009-10-24 15:52:44 +02002567 dev_dbg(&link->dev, "ray_cs Starting association with access point\n");
John Daiker141fa612009-03-10 06:59:54 -07002568 pccs = ccs_base(local) + ccsindex;
2569 /* fill in the CCS */
2570 writeb(CCS_START_ASSOCIATION, &pccs->cmd);
2571 /* Interrupt the firmware to process the command */
2572 if (interrupt_ecf(local, ccsindex)) {
Dominik Brodowski624dd662009-10-24 15:52:44 +02002573 dev_dbg(&link->dev, "ray_cs associate failed - ECF not ready for intr\n");
John Daiker141fa612009-03-10 06:59:54 -07002574 writeb(CCS_BUFFER_FREE, &(pccs++)->buffer_status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002575
John Daiker141fa612009-03-10 06:59:54 -07002576 del_timer(&local->timer);
2577 local->timer.expires = jiffies + HZ * 2;
2578 local->timer.data = (long)local;
2579 local->timer.function = &join_net;
2580 add_timer(&local->timer);
2581 local->card_status = CARD_ASSOC_FAILED;
2582 return;
2583 }
2584 if (!sniffer)
2585 netif_start_queue(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002586
2587} /* end associate */
John Daiker141fa612009-03-10 06:59:54 -07002588
Linus Torvalds1da177e2005-04-16 15:20:36 -07002589/*===========================================================================*/
John Daiker141fa612009-03-10 06:59:54 -07002590static void rx_deauthenticate(ray_dev_t *local, struct rcs __iomem *prcs,
2591 unsigned int pkt_addr, int rx_len)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002592{
2593/* UCHAR buff[256];
2594 struct rx_msg *msg = (struct rx_msg *)buff;
2595*/
Dominik Brodowski624dd662009-10-24 15:52:44 +02002596 pr_debug("Deauthentication frame received\n");
John Daiker141fa612009-03-10 06:59:54 -07002597 local->authentication_state = UNAUTHENTICATED;
2598 /* Need to reauthenticate or rejoin depending on reason code */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002599/* copy_from_rx_buff(local, buff, pkt_addr, rx_len & 0xff);
2600 */
2601}
John Daiker141fa612009-03-10 06:59:54 -07002602
Linus Torvalds1da177e2005-04-16 15:20:36 -07002603/*===========================================================================*/
2604static void clear_interrupt(ray_dev_t *local)
2605{
John Daiker141fa612009-03-10 06:59:54 -07002606 writeb(0, local->amem + CIS_OFFSET + HCS_INTR_OFFSET);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002607}
John Daiker141fa612009-03-10 06:59:54 -07002608
Linus Torvalds1da177e2005-04-16 15:20:36 -07002609/*===========================================================================*/
2610#ifdef CONFIG_PROC_FS
2611#define MAXDATA (PAGE_SIZE - 80)
2612
2613static char *card_status[] = {
John Daiker141fa612009-03-10 06:59:54 -07002614 "Card inserted - uninitialized", /* 0 */
2615 "Card not downloaded", /* 1 */
2616 "Waiting for download parameters", /* 2 */
2617 "Card doing acquisition", /* 3 */
2618 "Acquisition complete", /* 4 */
2619 "Authentication complete", /* 5 */
2620 "Association complete", /* 6 */
2621 "???", "???", "???", "???", /* 7 8 9 10 undefined */
2622 "Card init error", /* 11 */
2623 "Download parameters error", /* 12 */
2624 "???", /* 13 */
2625 "Acquisition failed", /* 14 */
2626 "Authentication refused", /* 15 */
2627 "Association failed" /* 16 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002628};
2629
John Daiker141fa612009-03-10 06:59:54 -07002630static char *nettype[] = { "Adhoc", "Infra " };
2631static char *framing[] = { "Encapsulation", "Translation" }
2632
Linus Torvalds1da177e2005-04-16 15:20:36 -07002633;
2634/*===========================================================================*/
Alexey Dobriyan6b914c52008-04-10 14:34:35 -07002635static int ray_cs_proc_show(struct seq_file *m, void *v)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002636{
2637/* Print current values which are not available via other means
John Daiker141fa612009-03-10 06:59:54 -07002638 * eg ifconfig
Linus Torvalds1da177e2005-04-16 15:20:36 -07002639 */
John Daiker141fa612009-03-10 06:59:54 -07002640 int i;
2641 struct pcmcia_device *link;
2642 struct net_device *dev;
2643 ray_dev_t *local;
2644 UCHAR *p;
2645 struct freq_hop_element *pfh;
2646 UCHAR c[33];
Linus Torvalds1da177e2005-04-16 15:20:36 -07002647
John Daiker141fa612009-03-10 06:59:54 -07002648 link = this_device;
2649 if (!link)
2650 return 0;
2651 dev = (struct net_device *)link->priv;
2652 if (!dev)
2653 return 0;
2654 local = netdev_priv(dev);
2655 if (!local)
2656 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002657
John Daiker141fa612009-03-10 06:59:54 -07002658 seq_puts(m, "Raylink Wireless LAN driver status\n");
2659 seq_printf(m, "%s\n", rcsid);
2660 /* build 4 does not report version, and field is 0x55 after memtest */
2661 seq_puts(m, "Firmware version = ");
2662 if (local->fw_ver == 0x55)
2663 seq_puts(m, "4 - Use dump_cis for more details\n");
2664 else
2665 seq_printf(m, "%2d.%02d.%02d\n",
2666 local->fw_ver, local->fw_bld, local->fw_var);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002667
John Daiker141fa612009-03-10 06:59:54 -07002668 for (i = 0; i < 32; i++)
2669 c[i] = local->sparm.b5.a_current_ess_id[i];
2670 c[32] = 0;
2671 seq_printf(m, "%s network ESSID = \"%s\"\n",
2672 nettype[local->sparm.b5.a_network_type], c);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002673
John Daiker141fa612009-03-10 06:59:54 -07002674 p = local->bss_id;
2675 seq_printf(m, "BSSID = %pM\n", p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002676
John Daiker141fa612009-03-10 06:59:54 -07002677 seq_printf(m, "Country code = %d\n",
2678 local->sparm.b5.a_curr_country_code);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002679
John Daiker141fa612009-03-10 06:59:54 -07002680 i = local->card_status;
2681 if (i < 0)
2682 i = 10;
2683 if (i > 16)
2684 i = 10;
2685 seq_printf(m, "Card status = %s\n", card_status[i]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002686
John Daiker141fa612009-03-10 06:59:54 -07002687 seq_printf(m, "Framing mode = %s\n", framing[translate]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002688
John Daiker141fa612009-03-10 06:59:54 -07002689 seq_printf(m, "Last pkt signal lvl = %d\n", local->last_rsl);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002690
John Daiker141fa612009-03-10 06:59:54 -07002691 if (local->beacon_rxed) {
2692 /* Pull some fields out of last beacon received */
2693 seq_printf(m, "Beacon Interval = %d Kus\n",
2694 local->last_bcn.beacon_intvl[0]
2695 + 256 * local->last_bcn.beacon_intvl[1]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002696
John Daiker141fa612009-03-10 06:59:54 -07002697 p = local->last_bcn.elements;
2698 if (p[0] == C_ESSID_ELEMENT_ID)
2699 p += p[1] + 2;
2700 else {
2701 seq_printf(m,
2702 "Parse beacon failed at essid element id = %d\n",
2703 p[0]);
2704 return 0;
2705 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002706
John Daiker141fa612009-03-10 06:59:54 -07002707 if (p[0] == C_SUPPORTED_RATES_ELEMENT_ID) {
2708 seq_puts(m, "Supported rate codes = ");
2709 for (i = 2; i < p[1] + 2; i++)
2710 seq_printf(m, "0x%02x ", p[i]);
2711 seq_putc(m, '\n');
2712 p += p[1] + 2;
2713 } else {
2714 seq_puts(m, "Parse beacon failed at rates element\n");
2715 return 0;
2716 }
2717
2718 if (p[0] == C_FH_PARAM_SET_ELEMENT_ID) {
2719 pfh = (struct freq_hop_element *)p;
2720 seq_printf(m, "Hop dwell = %d Kus\n",
2721 pfh->dwell_time[0] +
2722 256 * pfh->dwell_time[1]);
Frans Popcb01b092010-03-24 19:46:34 +01002723 seq_printf(m, "Hop set = %d\n",
John Daiker141fa612009-03-10 06:59:54 -07002724 pfh->hop_set);
Frans Popcb01b092010-03-24 19:46:34 +01002725 seq_printf(m, "Hop pattern = %d\n",
John Daiker141fa612009-03-10 06:59:54 -07002726 pfh->hop_pattern);
Frans Popcb01b092010-03-24 19:46:34 +01002727 seq_printf(m, "Hop index = %d\n",
John Daiker141fa612009-03-10 06:59:54 -07002728 pfh->hop_index);
2729 p += p[1] + 2;
2730 } else {
2731 seq_puts(m,
2732 "Parse beacon failed at FH param element\n");
2733 return 0;
2734 }
2735 } else {
2736 seq_puts(m, "No beacons received\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002737 }
John Daiker141fa612009-03-10 06:59:54 -07002738 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002739}
2740
Alexey Dobriyan6b914c52008-04-10 14:34:35 -07002741static int ray_cs_proc_open(struct inode *inode, struct file *file)
2742{
2743 return single_open(file, ray_cs_proc_show, NULL);
2744}
2745
2746static const struct file_operations ray_cs_proc_fops = {
John Daiker141fa612009-03-10 06:59:54 -07002747 .owner = THIS_MODULE,
2748 .open = ray_cs_proc_open,
2749 .read = seq_read,
2750 .llseek = seq_lseek,
2751 .release = single_release,
Alexey Dobriyan6b914c52008-04-10 14:34:35 -07002752};
Linus Torvalds1da177e2005-04-16 15:20:36 -07002753#endif
2754/*===========================================================================*/
2755static int build_auth_frame(ray_dev_t *local, UCHAR *dest, int auth_type)
2756{
John Daiker141fa612009-03-10 06:59:54 -07002757 int addr;
2758 struct ccs __iomem *pccs;
2759 struct tx_msg __iomem *ptx;
2760 int ccsindex;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002761
John Daiker141fa612009-03-10 06:59:54 -07002762 /* If no tx buffers available, return */
2763 if ((ccsindex = get_free_tx_ccs(local)) < 0) {
Dominik Brodowski624dd662009-10-24 15:52:44 +02002764 pr_debug("ray_cs send authenticate - No free tx ccs\n");
John Daiker141fa612009-03-10 06:59:54 -07002765 return -1;
2766 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002767
John Daiker141fa612009-03-10 06:59:54 -07002768 pccs = ccs_base(local) + ccsindex;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002769
John Daiker141fa612009-03-10 06:59:54 -07002770 /* Address in card space */
2771 addr = TX_BUF_BASE + (ccsindex << 11);
2772 /* fill in the CCS */
2773 writeb(CCS_TX_REQUEST, &pccs->cmd);
2774 writeb(addr >> 8, pccs->var.tx_request.tx_data_ptr);
2775 writeb(0x20, pccs->var.tx_request.tx_data_ptr + 1);
2776 writeb(TX_AUTHENTICATE_LENGTH_MSB, pccs->var.tx_request.tx_data_length);
2777 writeb(TX_AUTHENTICATE_LENGTH_LSB,
2778 pccs->var.tx_request.tx_data_length + 1);
2779 writeb(0, &pccs->var.tx_request.pow_sav_mode);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002780
John Daiker141fa612009-03-10 06:59:54 -07002781 ptx = local->sram + addr;
2782 /* fill in the mac header */
2783 writeb(PROTOCOL_VER | AUTHENTIC_TYPE, &ptx->mac.frame_ctl_1);
2784 writeb(0, &ptx->mac.frame_ctl_2);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002785
John Daiker141fa612009-03-10 06:59:54 -07002786 memcpy_toio(ptx->mac.addr_1, dest, ADDRLEN);
2787 memcpy_toio(ptx->mac.addr_2, local->sparm.b4.a_mac_addr, ADDRLEN);
2788 memcpy_toio(ptx->mac.addr_3, local->bss_id, ADDRLEN);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002789
John Daiker141fa612009-03-10 06:59:54 -07002790 /* Fill in msg body with protocol 00 00, sequence 01 00 ,status 00 00 */
2791 memset_io(ptx->var, 0, 6);
2792 writeb(auth_type & 0xff, ptx->var + 2);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002793
John Daiker141fa612009-03-10 06:59:54 -07002794 /* Interrupt the firmware to process the command */
2795 if (interrupt_ecf(local, ccsindex)) {
Dominik Brodowski624dd662009-10-24 15:52:44 +02002796 pr_debug(
John Daiker141fa612009-03-10 06:59:54 -07002797 "ray_cs send authentication request failed - ECF not ready for intr\n");
2798 writeb(CCS_BUFFER_FREE, &(pccs++)->buffer_status);
2799 return -1;
2800 }
2801 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002802} /* End build_auth_frame */
2803
2804/*===========================================================================*/
2805#ifdef CONFIG_PROC_FS
Alexey Dobriyan83daee02009-11-25 10:12:20 +03002806static ssize_t ray_cs_essid_proc_write(struct file *file,
2807 const char __user *buffer, size_t count, loff_t *pos)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002808{
2809 static char proc_essid[33];
Alan Cox575c9ed2009-10-27 15:35:55 +00002810 unsigned int len = count;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002811
2812 if (len > 32)
2813 len = 32;
2814 memset(proc_essid, 0, 33);
2815 if (copy_from_user(proc_essid, buffer, len))
2816 return -EFAULT;
2817 essid = proc_essid;
2818 return count;
2819}
2820
Alexey Dobriyan83daee02009-11-25 10:12:20 +03002821static const struct file_operations ray_cs_essid_proc_fops = {
2822 .owner = THIS_MODULE,
2823 .write = ray_cs_essid_proc_write,
2824};
2825
2826static ssize_t int_proc_write(struct file *file, const char __user *buffer,
2827 size_t count, loff_t *pos)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002828{
2829 static char proc_number[10];
2830 char *p;
2831 int nr, len;
2832
2833 if (!count)
2834 return 0;
2835
2836 if (count > 9)
2837 return -EINVAL;
2838 if (copy_from_user(proc_number, buffer, count))
2839 return -EFAULT;
2840 p = proc_number;
2841 nr = 0;
2842 len = count;
2843 do {
2844 unsigned int c = *p - '0';
2845 if (c > 9)
2846 return -EINVAL;
John Daiker141fa612009-03-10 06:59:54 -07002847 nr = nr * 10 + c;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002848 p++;
2849 } while (--len);
Alexey Dobriyan83daee02009-11-25 10:12:20 +03002850 *(int *)PDE(file->f_path.dentry->d_inode)->data = nr;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002851 return count;
2852}
Alexey Dobriyan83daee02009-11-25 10:12:20 +03002853
2854static const struct file_operations int_proc_fops = {
2855 .owner = THIS_MODULE,
2856 .write = int_proc_write,
2857};
Linus Torvalds1da177e2005-04-16 15:20:36 -07002858#endif
2859
Dominik Brodowskif57ea2a2005-06-27 16:28:24 -07002860static struct pcmcia_device_id ray_ids[] = {
2861 PCMCIA_DEVICE_MANF_CARD(0x01a6, 0x0000),
2862 PCMCIA_DEVICE_NULL,
2863};
John Daiker141fa612009-03-10 06:59:54 -07002864
Dominik Brodowskif57ea2a2005-06-27 16:28:24 -07002865MODULE_DEVICE_TABLE(pcmcia, ray_ids);
2866
Linus Torvalds1da177e2005-04-16 15:20:36 -07002867static struct pcmcia_driver ray_driver = {
John Daiker141fa612009-03-10 06:59:54 -07002868 .owner = THIS_MODULE,
2869 .drv = {
2870 .name = "ray_cs",
2871 },
2872 .probe = ray_probe,
2873 .remove = ray_detach,
2874 .id_table = ray_ids,
2875 .suspend = ray_suspend,
2876 .resume = ray_resume,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002877};
2878
2879static int __init init_ray_cs(void)
2880{
John Daiker141fa612009-03-10 06:59:54 -07002881 int rc;
2882
Dominik Brodowski624dd662009-10-24 15:52:44 +02002883 pr_debug("%s\n", rcsid);
John Daiker141fa612009-03-10 06:59:54 -07002884 rc = pcmcia_register_driver(&ray_driver);
Dominik Brodowski624dd662009-10-24 15:52:44 +02002885 pr_debug("raylink init_module register_pcmcia_driver returns 0x%x\n",
John Daiker141fa612009-03-10 06:59:54 -07002886 rc);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002887
2888#ifdef CONFIG_PROC_FS
John Daiker141fa612009-03-10 06:59:54 -07002889 proc_mkdir("driver/ray_cs", NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002890
John Daiker141fa612009-03-10 06:59:54 -07002891 proc_create("driver/ray_cs/ray_cs", 0, NULL, &ray_cs_proc_fops);
Alexey Dobriyan83daee02009-11-25 10:12:20 +03002892 proc_create("driver/ray_cs/essid", S_IWUSR, NULL, &ray_cs_essid_proc_fops);
2893 proc_create_data("driver/ray_cs/net_type", S_IWUSR, NULL, &int_proc_fops, &net_type);
2894 proc_create_data("driver/ray_cs/translate", S_IWUSR, NULL, &int_proc_fops, &translate);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002895#endif
John Daiker141fa612009-03-10 06:59:54 -07002896 if (translate != 0)
2897 translate = 1;
2898 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002899} /* init_ray_cs */
2900
2901/*===========================================================================*/
2902
2903static void __exit exit_ray_cs(void)
2904{
Dominik Brodowski624dd662009-10-24 15:52:44 +02002905 pr_debug("ray_cs: cleanup_module\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002906
2907#ifdef CONFIG_PROC_FS
John Daiker141fa612009-03-10 06:59:54 -07002908 remove_proc_entry("driver/ray_cs/ray_cs", NULL);
2909 remove_proc_entry("driver/ray_cs/essid", NULL);
2910 remove_proc_entry("driver/ray_cs/net_type", NULL);
2911 remove_proc_entry("driver/ray_cs/translate", NULL);
2912 remove_proc_entry("driver/ray_cs", NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002913#endif
2914
John Daiker141fa612009-03-10 06:59:54 -07002915 pcmcia_unregister_driver(&ray_driver);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002916} /* exit_ray_cs */
2917
2918module_init(init_ray_cs);
2919module_exit(exit_ray_cs);
2920
2921/*===========================================================================*/