blob: 165beb6af8496b2522eacaaa775569da14df22a5 [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 */
318 p_dev->io.NumPorts1 = 0;
319 p_dev->io.Attributes1 = IO_DATA_PATH_WIDTH_8;
320 p_dev->io.IOAddrLines = 5;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700321
John Daiker141fa612009-03-10 06:59:54 -0700322 /* General socket configuration */
323 p_dev->conf.Attributes = CONF_ENABLE_IRQ;
324 p_dev->conf.IntType = INT_MEMORY_AND_IO;
325 p_dev->conf.ConfigIndex = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700326
John Daiker141fa612009-03-10 06:59:54 -0700327 p_dev->priv = dev;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700328
John Daiker141fa612009-03-10 06:59:54 -0700329 local->finder = p_dev;
330 local->card_status = CARD_INSERTED;
331 local->authentication_state = UNAUTHENTICATED;
332 local->num_multi = 0;
Dominik Brodowski624dd662009-10-24 15:52:44 +0200333 dev_dbg(&p_dev->dev, "ray_attach p_dev = %p, dev = %p, local = %p, intr = %p\n",
John Daiker141fa612009-03-10 06:59:54 -0700334 p_dev, dev, local, &ray_interrupt);
335
336 /* Raylink entries in the device structure */
Stephen Hemminger32f5a332009-03-20 19:36:28 +0000337 dev->netdev_ops = &ray_netdev_ops;
John Daiker141fa612009-03-10 06:59:54 -0700338 SET_ETHTOOL_OPS(dev, &netdev_ethtool_ops);
339 dev->wireless_handlers = &ray_handler_def;
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -0700340#ifdef WIRELESS_SPY
John Daiker141fa612009-03-10 06:59:54 -0700341 local->wireless_data.spy_data = &local->spy_data;
342 dev->wireless_data = &local->wireless_data;
343#endif /* WIRELESS_SPY */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700344
Linus Torvalds1da177e2005-04-16 15:20:36 -0700345
Dominik Brodowski624dd662009-10-24 15:52:44 +0200346 dev_dbg(&p_dev->dev, "ray_cs ray_attach calling ether_setup.)\n");
John Daiker141fa612009-03-10 06:59:54 -0700347 netif_stop_queue(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700348
John Daiker141fa612009-03-10 06:59:54 -0700349 init_timer(&local->timer);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700350
John Daiker141fa612009-03-10 06:59:54 -0700351 this_device = p_dev;
352 return ray_config(p_dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700353
354fail_alloc_dev:
John Daiker141fa612009-03-10 06:59:54 -0700355 return -ENOMEM;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700356} /* ray_attach */
John Daiker141fa612009-03-10 06:59:54 -0700357
Linus Torvalds1da177e2005-04-16 15:20:36 -0700358/*=============================================================================
359 This deletes a driver "instance". The device is de-registered
360 with Card Services. If it has been released, all local data
361 structures are freed. Otherwise, the structures will be freed
362 when the device is released.
363=============================================================================*/
Dominik Brodowskifba395e2006-03-31 17:21:06 +0200364static void ray_detach(struct pcmcia_device *link)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700365{
John Daiker141fa612009-03-10 06:59:54 -0700366 struct net_device *dev;
367 ray_dev_t *local;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700368
Dominik Brodowski624dd662009-10-24 15:52:44 +0200369 dev_dbg(&link->dev, "ray_detach\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700370
John Daiker141fa612009-03-10 06:59:54 -0700371 this_device = NULL;
372 dev = link->priv;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700373
John Daiker141fa612009-03-10 06:59:54 -0700374 ray_release(link);
Dominik Brodowskicc3b4862005-11-14 21:23:14 +0100375
John Daiker141fa612009-03-10 06:59:54 -0700376 local = netdev_priv(dev);
377 del_timer(&local->timer);
Dominik Brodowskicc3b4862005-11-14 21:23:14 +0100378
John Daiker141fa612009-03-10 06:59:54 -0700379 if (link->priv) {
Dominik Brodowskic7c2fa02010-03-20 19:39:26 +0100380 unregister_netdev(dev);
John Daiker141fa612009-03-10 06:59:54 -0700381 free_netdev(dev);
382 }
Dominik Brodowski624dd662009-10-24 15:52:44 +0200383 dev_dbg(&link->dev, "ray_cs ray_detach ending\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700384} /* ray_detach */
John Daiker141fa612009-03-10 06:59:54 -0700385
Linus Torvalds1da177e2005-04-16 15:20:36 -0700386/*=============================================================================
387 ray_config() is run after a CARD_INSERTION event
388 is received, to configure the PCMCIA socket, and to make the
389 ethernet device available to the system.
390=============================================================================*/
Linus Torvalds1da177e2005-04-16 15:20:36 -0700391#define MAX_TUPLE_SIZE 128
Dominik Brodowski15b99ac2006-03-31 17:26:06 +0200392static int ray_config(struct pcmcia_device *link)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700393{
Dominik Brodowski624dd662009-10-24 15:52:44 +0200394 int ret = 0;
John Daiker141fa612009-03-10 06:59:54 -0700395 int i;
396 win_req_t req;
397 memreq_t mem;
398 struct net_device *dev = (struct net_device *)link->priv;
399 ray_dev_t *local = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700400
Dominik Brodowski624dd662009-10-24 15:52:44 +0200401 dev_dbg(&link->dev, "ray_config\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700402
John Daiker141fa612009-03-10 06:59:54 -0700403 /* Determine card type and firmware version */
404 printk(KERN_INFO "ray_cs Detected: %s%s%s%s\n",
405 link->prod_id[0] ? link->prod_id[0] : " ",
406 link->prod_id[1] ? link->prod_id[1] : " ",
407 link->prod_id[2] ? link->prod_id[2] : " ",
408 link->prod_id[3] ? link->prod_id[3] : " ");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700409
John Daiker141fa612009-03-10 06:59:54 -0700410 /* Now allocate an interrupt line. Note that this does not
411 actually assign a handler to the interrupt.
412 */
Dominik Brodowskieb141202010-03-07 12:21:16 +0100413 ret = pcmcia_request_irq(link, ray_interrupt);
Dominik Brodowski624dd662009-10-24 15:52:44 +0200414 if (ret)
415 goto failed;
Dominik Brodowskieb141202010-03-07 12:21:16 +0100416 dev->irq = link->irq;
John Daiker141fa612009-03-10 06:59:54 -0700417
418 /* This actually configures the PCMCIA socket -- setting up
419 the I/O windows and the interrupt mapping.
420 */
Dominik Brodowski624dd662009-10-24 15:52:44 +0200421 ret = pcmcia_request_configuration(link, &link->conf);
422 if (ret)
423 goto failed;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700424
425/*** Set up 32k window for shared memory (transmit and control) ************/
John Daiker141fa612009-03-10 06:59:54 -0700426 req.Attributes =
427 WIN_DATA_WIDTH_8 | WIN_MEMORY_TYPE_CM | WIN_ENABLE | WIN_USE_WAIT;
428 req.Base = 0;
429 req.Size = 0x8000;
430 req.AccessSpeed = ray_mem_speed;
Dominik Brodowski6838b032009-11-03 01:31:52 +0100431 ret = pcmcia_request_window(link, &req, &link->win);
Dominik Brodowski624dd662009-10-24 15:52:44 +0200432 if (ret)
433 goto failed;
John Daiker141fa612009-03-10 06:59:54 -0700434 mem.CardOffset = 0x0000;
435 mem.Page = 0;
Magnus Damm868575d2006-12-13 19:46:43 +0900436 ret = pcmcia_map_mem_page(link, link->win, &mem);
Dominik Brodowski624dd662009-10-24 15:52:44 +0200437 if (ret)
438 goto failed;
John Daiker141fa612009-03-10 06:59:54 -0700439 local->sram = ioremap(req.Base, req.Size);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700440
441/*** Set up 16k window for shared memory (receive buffer) ***************/
John Daiker141fa612009-03-10 06:59:54 -0700442 req.Attributes =
443 WIN_DATA_WIDTH_8 | WIN_MEMORY_TYPE_CM | WIN_ENABLE | WIN_USE_WAIT;
444 req.Base = 0;
445 req.Size = 0x4000;
446 req.AccessSpeed = ray_mem_speed;
Dominik Brodowski6838b032009-11-03 01:31:52 +0100447 ret = pcmcia_request_window(link, &req, &local->rmem_handle);
Dominik Brodowski624dd662009-10-24 15:52:44 +0200448 if (ret)
449 goto failed;
John Daiker141fa612009-03-10 06:59:54 -0700450 mem.CardOffset = 0x8000;
451 mem.Page = 0;
Magnus Damm868575d2006-12-13 19:46:43 +0900452 ret = pcmcia_map_mem_page(link, local->rmem_handle, &mem);
Dominik Brodowski624dd662009-10-24 15:52:44 +0200453 if (ret)
454 goto failed;
John Daiker141fa612009-03-10 06:59:54 -0700455 local->rmem = ioremap(req.Base, req.Size);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700456
457/*** Set up window for attribute memory ***********************************/
John Daiker141fa612009-03-10 06:59:54 -0700458 req.Attributes =
459 WIN_DATA_WIDTH_8 | WIN_MEMORY_TYPE_AM | WIN_ENABLE | WIN_USE_WAIT;
460 req.Base = 0;
461 req.Size = 0x1000;
462 req.AccessSpeed = ray_mem_speed;
Dominik Brodowski6838b032009-11-03 01:31:52 +0100463 ret = pcmcia_request_window(link, &req, &local->amem_handle);
Dominik Brodowski624dd662009-10-24 15:52:44 +0200464 if (ret)
465 goto failed;
John Daiker141fa612009-03-10 06:59:54 -0700466 mem.CardOffset = 0x0000;
467 mem.Page = 0;
Magnus Damm868575d2006-12-13 19:46:43 +0900468 ret = pcmcia_map_mem_page(link, local->amem_handle, &mem);
Dominik Brodowski624dd662009-10-24 15:52:44 +0200469 if (ret)
470 goto failed;
John Daiker141fa612009-03-10 06:59:54 -0700471 local->amem = ioremap(req.Base, req.Size);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700472
Dominik Brodowski624dd662009-10-24 15:52:44 +0200473 dev_dbg(&link->dev, "ray_config sram=%p\n", local->sram);
474 dev_dbg(&link->dev, "ray_config rmem=%p\n", local->rmem);
475 dev_dbg(&link->dev, "ray_config amem=%p\n", local->amem);
John Daiker141fa612009-03-10 06:59:54 -0700476 if (ray_init(dev) < 0) {
477 ray_release(link);
478 return -ENODEV;
479 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700480
Dominik Brodowskidd2e5a12009-11-03 10:27:34 +0100481 SET_NETDEV_DEV(dev, &link->dev);
John Daiker141fa612009-03-10 06:59:54 -0700482 i = register_netdev(dev);
483 if (i != 0) {
484 printk("ray_config register_netdev() failed\n");
485 ray_release(link);
486 return i;
487 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700488
John Daiker141fa612009-03-10 06:59:54 -0700489 printk(KERN_INFO "%s: RayLink, irq %d, hw_addr %pM\n",
490 dev->name, dev->irq, dev->dev_addr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700491
John Daiker141fa612009-03-10 06:59:54 -0700492 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700493
Dominik Brodowski624dd662009-10-24 15:52:44 +0200494failed:
John Daiker141fa612009-03-10 06:59:54 -0700495 ray_release(link);
496 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700497} /* ray_config */
498
499static inline struct ccs __iomem *ccs_base(ray_dev_t *dev)
500{
501 return dev->sram + CCS_BASE;
502}
503
504static inline struct rcs __iomem *rcs_base(ray_dev_t *dev)
505{
506 /*
507 * This looks nonsensical, since there is a separate
508 * RCS_BASE. But the difference between a "struct rcs"
509 * and a "struct ccs" ends up being in the _index_ off
510 * the base, so the base pointer is the same for both
511 * ccs/rcs.
512 */
513 return dev->sram + CCS_BASE;
514}
515
516/*===========================================================================*/
517static int ray_init(struct net_device *dev)
518{
John Daiker141fa612009-03-10 06:59:54 -0700519 int i;
520 UCHAR *p;
521 struct ccs __iomem *pccs;
522 ray_dev_t *local = netdev_priv(dev);
523 struct pcmcia_device *link = local->finder;
Dominik Brodowski624dd662009-10-24 15:52:44 +0200524 dev_dbg(&link->dev, "ray_init(0x%p)\n", dev);
John Daiker141fa612009-03-10 06:59:54 -0700525 if (!(pcmcia_dev_present(link))) {
Dominik Brodowski624dd662009-10-24 15:52:44 +0200526 dev_dbg(&link->dev, "ray_init - device not present\n");
John Daiker141fa612009-03-10 06:59:54 -0700527 return -1;
528 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700529
John Daiker141fa612009-03-10 06:59:54 -0700530 local->net_type = net_type;
531 local->sta_type = TYPE_STA;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700532
John Daiker141fa612009-03-10 06:59:54 -0700533 /* Copy the startup results to local memory */
534 memcpy_fromio(&local->startup_res, local->sram + ECF_TO_HOST_BASE,
535 sizeof(struct startup_res_6));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700536
John Daiker141fa612009-03-10 06:59:54 -0700537 /* Check Power up test status and get mac address from card */
538 if (local->startup_res.startup_word != 0x80) {
539 printk(KERN_INFO "ray_init ERROR card status = %2x\n",
540 local->startup_res.startup_word);
541 local->card_status = CARD_INIT_ERROR;
542 return -1;
543 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700544
John Daiker141fa612009-03-10 06:59:54 -0700545 local->fw_ver = local->startup_res.firmware_version[0];
546 local->fw_bld = local->startup_res.firmware_version[1];
547 local->fw_var = local->startup_res.firmware_version[2];
Frans Popcb01b092010-03-24 19:46:34 +0100548 dev_dbg(&link->dev, "ray_init firmware version %d.%d\n", local->fw_ver,
John Daiker141fa612009-03-10 06:59:54 -0700549 local->fw_bld);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700550
John Daiker141fa612009-03-10 06:59:54 -0700551 local->tib_length = 0x20;
552 if ((local->fw_ver == 5) && (local->fw_bld >= 30))
553 local->tib_length = local->startup_res.tib_length;
Dominik Brodowski624dd662009-10-24 15:52:44 +0200554 dev_dbg(&link->dev, "ray_init tib_length = 0x%02x\n", local->tib_length);
John Daiker141fa612009-03-10 06:59:54 -0700555 /* Initialize CCS's to buffer free state */
556 pccs = ccs_base(local);
557 for (i = 0; i < NUMBER_OF_CCS; i++) {
558 writeb(CCS_BUFFER_FREE, &(pccs++)->buffer_status);
559 }
560 init_startup_params(local);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700561
John Daiker141fa612009-03-10 06:59:54 -0700562 /* copy mac address to startup parameters */
563 if (parse_addr(phy_addr, local->sparm.b4.a_mac_addr)) {
564 p = local->sparm.b4.a_mac_addr;
565 } else {
566 memcpy(&local->sparm.b4.a_mac_addr,
567 &local->startup_res.station_addr, ADDRLEN);
568 p = local->sparm.b4.a_mac_addr;
569 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700570
John Daiker141fa612009-03-10 06:59:54 -0700571 clear_interrupt(local); /* Clear any interrupt from the card */
572 local->card_status = CARD_AWAITING_PARAM;
Dominik Brodowski624dd662009-10-24 15:52:44 +0200573 dev_dbg(&link->dev, "ray_init ending\n");
John Daiker141fa612009-03-10 06:59:54 -0700574 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700575} /* ray_init */
John Daiker141fa612009-03-10 06:59:54 -0700576
Linus Torvalds1da177e2005-04-16 15:20:36 -0700577/*===========================================================================*/
578/* Download startup parameters to the card and command it to read them */
579static int dl_startup_params(struct net_device *dev)
580{
John Daiker141fa612009-03-10 06:59:54 -0700581 int ccsindex;
582 ray_dev_t *local = netdev_priv(dev);
583 struct ccs __iomem *pccs;
584 struct pcmcia_device *link = local->finder;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700585
Dominik Brodowski624dd662009-10-24 15:52:44 +0200586 dev_dbg(&link->dev, "dl_startup_params entered\n");
John Daiker141fa612009-03-10 06:59:54 -0700587 if (!(pcmcia_dev_present(link))) {
Dominik Brodowski624dd662009-10-24 15:52:44 +0200588 dev_dbg(&link->dev, "ray_cs dl_startup_params - device not present\n");
John Daiker141fa612009-03-10 06:59:54 -0700589 return -1;
590 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700591
John Daiker141fa612009-03-10 06:59:54 -0700592 /* Copy parameters to host to ECF area */
593 if (local->fw_ver == 0x55)
594 memcpy_toio(local->sram + HOST_TO_ECF_BASE, &local->sparm.b4,
595 sizeof(struct b4_startup_params));
596 else
597 memcpy_toio(local->sram + HOST_TO_ECF_BASE, &local->sparm.b5,
598 sizeof(struct b5_startup_params));
599
600 /* Fill in the CCS fields for the ECF */
601 if ((ccsindex = get_free_ccs(local)) < 0)
602 return -1;
603 local->dl_param_ccs = ccsindex;
604 pccs = ccs_base(local) + ccsindex;
605 writeb(CCS_DOWNLOAD_STARTUP_PARAMS, &pccs->cmd);
Dominik Brodowski624dd662009-10-24 15:52:44 +0200606 dev_dbg(&link->dev, "dl_startup_params start ccsindex = %d\n",
John Daiker141fa612009-03-10 06:59:54 -0700607 local->dl_param_ccs);
608 /* Interrupt the firmware to process the command */
609 if (interrupt_ecf(local, ccsindex)) {
610 printk(KERN_INFO "ray dl_startup_params failed - "
611 "ECF not ready for intr\n");
612 local->card_status = CARD_DL_PARAM_ERROR;
613 writeb(CCS_BUFFER_FREE, &(pccs++)->buffer_status);
614 return -2;
615 }
616 local->card_status = CARD_DL_PARAM;
617 /* Start kernel timer to wait for dl startup to complete. */
618 local->timer.expires = jiffies + HZ / 2;
619 local->timer.data = (long)local;
620 local->timer.function = &verify_dl_startup;
621 add_timer(&local->timer);
Dominik Brodowski624dd662009-10-24 15:52:44 +0200622 dev_dbg(&link->dev,
John Daiker141fa612009-03-10 06:59:54 -0700623 "ray_cs dl_startup_params started timer for verify_dl_startup\n");
624 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700625} /* dl_startup_params */
John Daiker141fa612009-03-10 06:59:54 -0700626
Linus Torvalds1da177e2005-04-16 15:20:36 -0700627/*===========================================================================*/
628static void init_startup_params(ray_dev_t *local)
629{
John Daiker141fa612009-03-10 06:59:54 -0700630 int i;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700631
John Daiker141fa612009-03-10 06:59:54 -0700632 if (country > JAPAN_TEST)
633 country = USA;
634 else if (country < USA)
635 country = USA;
636 /* structure for hop time and beacon period is defined here using
637 * New 802.11D6.1 format. Card firmware is still using old format
638 * until version 6.
639 * Before After
640 * a_hop_time ms byte a_hop_time ms byte
641 * a_hop_time 2s byte a_hop_time ls byte
642 * a_hop_time ls byte a_beacon_period ms byte
643 * a_beacon_period a_beacon_period ls byte
644 *
645 * a_hop_time = uS a_hop_time = KuS
646 * a_beacon_period = hops a_beacon_period = KuS
647 *//* 64ms = 010000 */
648 if (local->fw_ver == 0x55) {
649 memcpy((UCHAR *) &local->sparm.b4, b4_default_startup_parms,
650 sizeof(struct b4_startup_params));
651 /* Translate sane kus input values to old build 4/5 format */
652 /* i = hop time in uS truncated to 3 bytes */
653 i = (hop_dwell * 1024) & 0xffffff;
654 local->sparm.b4.a_hop_time[0] = (i >> 16) & 0xff;
655 local->sparm.b4.a_hop_time[1] = (i >> 8) & 0xff;
656 local->sparm.b4.a_beacon_period[0] = 0;
657 local->sparm.b4.a_beacon_period[1] =
658 ((beacon_period / hop_dwell) - 1) & 0xff;
659 local->sparm.b4.a_curr_country_code = country;
660 local->sparm.b4.a_hop_pattern_length =
661 hop_pattern_length[(int)country] - 1;
662 if (bc) {
663 local->sparm.b4.a_ack_timeout = 0x50;
664 local->sparm.b4.a_sifs = 0x3f;
665 }
666 } else { /* Version 5 uses real kus values */
667 memcpy((UCHAR *) &local->sparm.b5, b5_default_startup_parms,
668 sizeof(struct b5_startup_params));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700669
John Daiker141fa612009-03-10 06:59:54 -0700670 local->sparm.b5.a_hop_time[0] = (hop_dwell >> 8) & 0xff;
671 local->sparm.b5.a_hop_time[1] = hop_dwell & 0xff;
672 local->sparm.b5.a_beacon_period[0] =
673 (beacon_period >> 8) & 0xff;
674 local->sparm.b5.a_beacon_period[1] = beacon_period & 0xff;
675 if (psm)
676 local->sparm.b5.a_power_mgt_state = 1;
677 local->sparm.b5.a_curr_country_code = country;
678 local->sparm.b5.a_hop_pattern_length =
679 hop_pattern_length[(int)country];
680 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700681
John Daiker141fa612009-03-10 06:59:54 -0700682 local->sparm.b4.a_network_type = net_type & 0x01;
683 local->sparm.b4.a_acting_as_ap_status = TYPE_STA;
684
685 if (essid != NULL)
686 strncpy(local->sparm.b4.a_current_ess_id, essid, ESSID_SIZE);
687} /* init_startup_params */
688
Linus Torvalds1da177e2005-04-16 15:20:36 -0700689/*===========================================================================*/
690static void verify_dl_startup(u_long data)
691{
John Daiker141fa612009-03-10 06:59:54 -0700692 ray_dev_t *local = (ray_dev_t *) data;
693 struct ccs __iomem *pccs = ccs_base(local) + local->dl_param_ccs;
694 UCHAR status;
695 struct pcmcia_device *link = local->finder;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700696
John Daiker141fa612009-03-10 06:59:54 -0700697 if (!(pcmcia_dev_present(link))) {
Dominik Brodowski624dd662009-10-24 15:52:44 +0200698 dev_dbg(&link->dev, "ray_cs verify_dl_startup - device not present\n");
John Daiker141fa612009-03-10 06:59:54 -0700699 return;
700 }
Dominik Brodowski624dd662009-10-24 15:52:44 +0200701#if 0
702 {
John Daiker141fa612009-03-10 06:59:54 -0700703 int i;
704 printk(KERN_DEBUG
705 "verify_dl_startup parameters sent via ccs %d:\n",
706 local->dl_param_ccs);
707 for (i = 0; i < sizeof(struct b5_startup_params); i++) {
708 printk(" %2x",
709 (unsigned int)readb(local->sram +
710 HOST_TO_ECF_BASE + i));
711 }
712 printk("\n");
713 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700714#endif
715
John Daiker141fa612009-03-10 06:59:54 -0700716 status = readb(&pccs->buffer_status);
717 if (status != CCS_BUFFER_FREE) {
718 printk(KERN_INFO
719 "Download startup params failed. Status = %d\n",
720 status);
721 local->card_status = CARD_DL_PARAM_ERROR;
722 return;
723 }
724 if (local->sparm.b4.a_network_type == ADHOC)
725 start_net((u_long) local);
726 else
727 join_net((u_long) local);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700728} /* end verify_dl_startup */
John Daiker141fa612009-03-10 06:59:54 -0700729
Linus Torvalds1da177e2005-04-16 15:20:36 -0700730/*===========================================================================*/
731/* Command card to start a network */
732static void start_net(u_long data)
733{
John Daiker141fa612009-03-10 06:59:54 -0700734 ray_dev_t *local = (ray_dev_t *) data;
735 struct ccs __iomem *pccs;
736 int ccsindex;
737 struct pcmcia_device *link = local->finder;
738 if (!(pcmcia_dev_present(link))) {
Dominik Brodowski624dd662009-10-24 15:52:44 +0200739 dev_dbg(&link->dev, "ray_cs start_net - device not present\n");
John Daiker141fa612009-03-10 06:59:54 -0700740 return;
741 }
742 /* Fill in the CCS fields for the ECF */
743 if ((ccsindex = get_free_ccs(local)) < 0)
744 return;
745 pccs = ccs_base(local) + ccsindex;
746 writeb(CCS_START_NETWORK, &pccs->cmd);
747 writeb(0, &pccs->var.start_network.update_param);
748 /* Interrupt the firmware to process the command */
749 if (interrupt_ecf(local, ccsindex)) {
Dominik Brodowski624dd662009-10-24 15:52:44 +0200750 dev_dbg(&link->dev, "ray start net failed - card not ready for intr\n");
John Daiker141fa612009-03-10 06:59:54 -0700751 writeb(CCS_BUFFER_FREE, &(pccs++)->buffer_status);
752 return;
753 }
754 local->card_status = CARD_DOING_ACQ;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700755} /* end start_net */
John Daiker141fa612009-03-10 06:59:54 -0700756
Linus Torvalds1da177e2005-04-16 15:20:36 -0700757/*===========================================================================*/
758/* Command card to join a network */
759static void join_net(u_long data)
760{
John Daiker141fa612009-03-10 06:59:54 -0700761 ray_dev_t *local = (ray_dev_t *) data;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700762
John Daiker141fa612009-03-10 06:59:54 -0700763 struct ccs __iomem *pccs;
764 int ccsindex;
765 struct pcmcia_device *link = local->finder;
766
767 if (!(pcmcia_dev_present(link))) {
Dominik Brodowski624dd662009-10-24 15:52:44 +0200768 dev_dbg(&link->dev, "ray_cs join_net - device not present\n");
John Daiker141fa612009-03-10 06:59:54 -0700769 return;
770 }
771 /* Fill in the CCS fields for the ECF */
772 if ((ccsindex = get_free_ccs(local)) < 0)
773 return;
774 pccs = ccs_base(local) + ccsindex;
775 writeb(CCS_JOIN_NETWORK, &pccs->cmd);
776 writeb(0, &pccs->var.join_network.update_param);
777 writeb(0, &pccs->var.join_network.net_initiated);
778 /* Interrupt the firmware to process the command */
779 if (interrupt_ecf(local, ccsindex)) {
Dominik Brodowski624dd662009-10-24 15:52:44 +0200780 dev_dbg(&link->dev, "ray join net failed - card not ready for intr\n");
John Daiker141fa612009-03-10 06:59:54 -0700781 writeb(CCS_BUFFER_FREE, &(pccs++)->buffer_status);
782 return;
783 }
784 local->card_status = CARD_DOING_ACQ;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700785}
John Daiker141fa612009-03-10 06:59:54 -0700786
Linus Torvalds1da177e2005-04-16 15:20:36 -0700787/*============================================================================
788 After a card is removed, ray_release() will unregister the net
789 device, and release the PCMCIA configuration. If the device is
790 still open, this will be postponed until it is closed.
791=============================================================================*/
Dominik Brodowskifba395e2006-03-31 17:21:06 +0200792static void ray_release(struct pcmcia_device *link)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700793{
John Daiker141fa612009-03-10 06:59:54 -0700794 struct net_device *dev = link->priv;
795 ray_dev_t *local = netdev_priv(dev);
796 int i;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700797
Dominik Brodowski624dd662009-10-24 15:52:44 +0200798 dev_dbg(&link->dev, "ray_release\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700799
John Daiker141fa612009-03-10 06:59:54 -0700800 del_timer(&local->timer);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700801
John Daiker141fa612009-03-10 06:59:54 -0700802 iounmap(local->sram);
803 iounmap(local->rmem);
804 iounmap(local->amem);
805 /* Do bother checking to see if these succeed or not */
Magnus Dammf5560da2006-12-13 19:46:38 +0900806 i = pcmcia_release_window(link, local->amem_handle);
John Daiker141fa612009-03-10 06:59:54 -0700807 if (i != 0)
Dominik Brodowski624dd662009-10-24 15:52:44 +0200808 dev_dbg(&link->dev, "ReleaseWindow(local->amem) ret = %x\n", i);
Magnus Dammf5560da2006-12-13 19:46:38 +0900809 i = pcmcia_release_window(link, local->rmem_handle);
John Daiker141fa612009-03-10 06:59:54 -0700810 if (i != 0)
Dominik Brodowski624dd662009-10-24 15:52:44 +0200811 dev_dbg(&link->dev, "ReleaseWindow(local->rmem) ret = %x\n", i);
John Daiker141fa612009-03-10 06:59:54 -0700812 pcmcia_disable_device(link);
813
Dominik Brodowski624dd662009-10-24 15:52:44 +0200814 dev_dbg(&link->dev, "ray_release ending\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700815}
816
Dominik Brodowskifba395e2006-03-31 17:21:06 +0200817static int ray_suspend(struct pcmcia_device *link)
Dominik Brodowski98e4c282005-11-14 21:21:18 +0100818{
Dominik Brodowski98e4c282005-11-14 21:21:18 +0100819 struct net_device *dev = link->priv;
820
Dominik Brodowskie2d40962006-03-02 00:09:29 +0100821 if (link->open)
Dominik Brodowski8661bb52006-03-02 00:02:33 +0100822 netif_device_detach(dev);
Dominik Brodowski98e4c282005-11-14 21:21:18 +0100823
824 return 0;
825}
826
Dominik Brodowskifba395e2006-03-31 17:21:06 +0200827static int ray_resume(struct pcmcia_device *link)
Dominik Brodowski98e4c282005-11-14 21:21:18 +0100828{
Dominik Brodowski98e4c282005-11-14 21:21:18 +0100829 struct net_device *dev = link->priv;
830
Dominik Brodowskie2d40962006-03-02 00:09:29 +0100831 if (link->open) {
Dominik Brodowski8661bb52006-03-02 00:02:33 +0100832 ray_reset(dev);
833 netif_device_attach(dev);
834 }
Dominik Brodowski98e4c282005-11-14 21:21:18 +0100835
836 return 0;
837}
838
Linus Torvalds1da177e2005-04-16 15:20:36 -0700839/*===========================================================================*/
Hannes Eder2ed5ba82008-12-26 00:12:59 -0800840static int ray_dev_init(struct net_device *dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700841{
842#ifdef RAY_IMMEDIATE_INIT
John Daiker141fa612009-03-10 06:59:54 -0700843 int i;
844#endif /* RAY_IMMEDIATE_INIT */
845 ray_dev_t *local = netdev_priv(dev);
846 struct pcmcia_device *link = local->finder;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700847
Dominik Brodowski624dd662009-10-24 15:52:44 +0200848 dev_dbg(&link->dev, "ray_dev_init(dev=%p)\n", dev);
John Daiker141fa612009-03-10 06:59:54 -0700849 if (!(pcmcia_dev_present(link))) {
Dominik Brodowski624dd662009-10-24 15:52:44 +0200850 dev_dbg(&link->dev, "ray_dev_init - device not present\n");
John Daiker141fa612009-03-10 06:59:54 -0700851 return -1;
852 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700853#ifdef RAY_IMMEDIATE_INIT
John Daiker141fa612009-03-10 06:59:54 -0700854 /* Download startup parameters */
855 if ((i = dl_startup_params(dev)) < 0) {
856 printk(KERN_INFO "ray_dev_init dl_startup_params failed - "
857 "returns 0x%x\n", i);
858 return -1;
859 }
860#else /* RAY_IMMEDIATE_INIT */
861 /* Postpone the card init so that we can still configure the card,
862 * for example using the Wireless Extensions. The init will happen
863 * in ray_open() - Jean II */
Dominik Brodowski624dd662009-10-24 15:52:44 +0200864 dev_dbg(&link->dev,
John Daiker141fa612009-03-10 06:59:54 -0700865 "ray_dev_init: postponing card init to ray_open() ; Status = %d\n",
866 local->card_status);
867#endif /* RAY_IMMEDIATE_INIT */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700868
John Daiker141fa612009-03-10 06:59:54 -0700869 /* copy mac and broadcast addresses to linux device */
Jiri Pirko3a6d54c2009-05-11 23:37:15 +0000870 memcpy(dev->dev_addr, &local->sparm.b4.a_mac_addr, ADDRLEN);
John Daiker141fa612009-03-10 06:59:54 -0700871 memset(dev->broadcast, 0xff, ETH_ALEN);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700872
Dominik Brodowski624dd662009-10-24 15:52:44 +0200873 dev_dbg(&link->dev, "ray_dev_init ending\n");
John Daiker141fa612009-03-10 06:59:54 -0700874 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700875}
John Daiker141fa612009-03-10 06:59:54 -0700876
Linus Torvalds1da177e2005-04-16 15:20:36 -0700877/*===========================================================================*/
878static int ray_dev_config(struct net_device *dev, struct ifmap *map)
879{
John Daiker141fa612009-03-10 06:59:54 -0700880 ray_dev_t *local = netdev_priv(dev);
881 struct pcmcia_device *link = local->finder;
882 /* Dummy routine to satisfy device structure */
Dominik Brodowski624dd662009-10-24 15:52:44 +0200883 dev_dbg(&link->dev, "ray_dev_config(dev=%p,ifmap=%p)\n", dev, map);
John Daiker141fa612009-03-10 06:59:54 -0700884 if (!(pcmcia_dev_present(link))) {
Dominik Brodowski624dd662009-10-24 15:52:44 +0200885 dev_dbg(&link->dev, "ray_dev_config - device not present\n");
John Daiker141fa612009-03-10 06:59:54 -0700886 return -1;
887 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700888
John Daiker141fa612009-03-10 06:59:54 -0700889 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700890}
John Daiker141fa612009-03-10 06:59:54 -0700891
Linus Torvalds1da177e2005-04-16 15:20:36 -0700892/*===========================================================================*/
Stephen Hemmingerd0cf9c02009-08-31 19:50:57 +0000893static netdev_tx_t ray_dev_start_xmit(struct sk_buff *skb,
894 struct net_device *dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700895{
John Daiker141fa612009-03-10 06:59:54 -0700896 ray_dev_t *local = netdev_priv(dev);
897 struct pcmcia_device *link = local->finder;
898 short length = skb->len;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700899
Stephen Hemmingerd0cf9c02009-08-31 19:50:57 +0000900 if (!pcmcia_dev_present(link)) {
Dominik Brodowski624dd662009-10-24 15:52:44 +0200901 dev_dbg(&link->dev, "ray_dev_start_xmit - device not present\n");
Stephen Hemmingerd0cf9c02009-08-31 19:50:57 +0000902 dev_kfree_skb(skb);
903 return NETDEV_TX_OK;
John Daiker141fa612009-03-10 06:59:54 -0700904 }
Stephen Hemmingerd0cf9c02009-08-31 19:50:57 +0000905
Dominik Brodowski624dd662009-10-24 15:52:44 +0200906 dev_dbg(&link->dev, "ray_dev_start_xmit(skb=%p, dev=%p)\n", skb, dev);
John Daiker141fa612009-03-10 06:59:54 -0700907 if (local->authentication_state == NEED_TO_AUTH) {
Dominik Brodowski624dd662009-10-24 15:52:44 +0200908 dev_dbg(&link->dev, "ray_cs Sending authentication request.\n");
John Daiker141fa612009-03-10 06:59:54 -0700909 if (!build_auth_frame(local, local->auth_id, OPEN_AUTH_REQUEST)) {
910 local->authentication_state = AUTHENTICATED;
911 netif_stop_queue(dev);
Patrick McHardy5b548142009-06-12 06:22:29 +0000912 return NETDEV_TX_BUSY;
John Daiker141fa612009-03-10 06:59:54 -0700913 }
914 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700915
John Daiker141fa612009-03-10 06:59:54 -0700916 if (length < ETH_ZLEN) {
917 if (skb_padto(skb, ETH_ZLEN))
Patrick McHardy6ed10652009-06-23 06:03:08 +0000918 return NETDEV_TX_OK;
John Daiker141fa612009-03-10 06:59:54 -0700919 length = ETH_ZLEN;
920 }
921 switch (ray_hw_xmit(skb->data, length, dev, DATA_TYPE)) {
922 case XMIT_NO_CCS:
923 case XMIT_NEED_AUTH:
924 netif_stop_queue(dev);
Patrick McHardy5b548142009-06-12 06:22:29 +0000925 return NETDEV_TX_BUSY;
John Daiker141fa612009-03-10 06:59:54 -0700926 case XMIT_NO_INTR:
927 case XMIT_MSG_BAD:
928 case XMIT_OK:
929 default:
John Daiker141fa612009-03-10 06:59:54 -0700930 dev_kfree_skb(skb);
John Daiker141fa612009-03-10 06:59:54 -0700931 }
Stephen Hemmingerd0cf9c02009-08-31 19:50:57 +0000932
Patrick McHardy6ed10652009-06-23 06:03:08 +0000933 return NETDEV_TX_OK;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700934} /* ray_dev_start_xmit */
John Daiker141fa612009-03-10 06:59:54 -0700935
Linus Torvalds1da177e2005-04-16 15:20:36 -0700936/*===========================================================================*/
John Daiker141fa612009-03-10 06:59:54 -0700937static int ray_hw_xmit(unsigned char *data, int len, struct net_device *dev,
938 UCHAR msg_type)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700939{
John Daiker141fa612009-03-10 06:59:54 -0700940 ray_dev_t *local = netdev_priv(dev);
941 struct ccs __iomem *pccs;
942 int ccsindex;
943 int offset;
944 struct tx_msg __iomem *ptx; /* Address of xmit buffer in PC space */
945 short int addr; /* Address of xmit buffer in card space */
946
Dominik Brodowski624dd662009-10-24 15:52:44 +0200947 pr_debug("ray_hw_xmit(data=%p, len=%d, dev=%p)\n", data, len, dev);
John Daiker141fa612009-03-10 06:59:54 -0700948 if (len + TX_HEADER_LENGTH > TX_BUF_SIZE) {
949 printk(KERN_INFO "ray_hw_xmit packet too large: %d bytes\n",
950 len);
951 return XMIT_MSG_BAD;
952 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700953 switch (ccsindex = get_free_tx_ccs(local)) {
954 case ECCSBUSY:
Dominik Brodowski624dd662009-10-24 15:52:44 +0200955 pr_debug("ray_hw_xmit tx_ccs table busy\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700956 case ECCSFULL:
Dominik Brodowski624dd662009-10-24 15:52:44 +0200957 pr_debug("ray_hw_xmit No free tx ccs\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700958 case ECARDGONE:
John Daiker141fa612009-03-10 06:59:54 -0700959 netif_stop_queue(dev);
960 return XMIT_NO_CCS;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700961 default:
962 break;
963 }
John Daiker141fa612009-03-10 06:59:54 -0700964 addr = TX_BUF_BASE + (ccsindex << 11);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700965
John Daiker141fa612009-03-10 06:59:54 -0700966 if (msg_type == DATA_TYPE) {
967 local->stats.tx_bytes += len;
968 local->stats.tx_packets++;
969 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700970
John Daiker141fa612009-03-10 06:59:54 -0700971 ptx = local->sram + addr;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700972
John Daiker141fa612009-03-10 06:59:54 -0700973 ray_build_header(local, ptx, msg_type, data);
974 if (translate) {
975 offset = translate_frame(local, ptx, data, len);
976 } else { /* Encapsulate frame */
977 /* TBD TIB length will move address of ptx->var */
978 memcpy_toio(&ptx->var, data, len);
979 offset = 0;
980 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700981
John Daiker141fa612009-03-10 06:59:54 -0700982 /* fill in the CCS */
983 pccs = ccs_base(local) + ccsindex;
984 len += TX_HEADER_LENGTH + offset;
985 writeb(CCS_TX_REQUEST, &pccs->cmd);
986 writeb(addr >> 8, &pccs->var.tx_request.tx_data_ptr[0]);
987 writeb(local->tib_length, &pccs->var.tx_request.tx_data_ptr[1]);
988 writeb(len >> 8, &pccs->var.tx_request.tx_data_length[0]);
989 writeb(len & 0xff, &pccs->var.tx_request.tx_data_length[1]);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700990/* TBD still need psm_cam? */
John Daiker141fa612009-03-10 06:59:54 -0700991 writeb(PSM_CAM, &pccs->var.tx_request.pow_sav_mode);
992 writeb(local->net_default_tx_rate, &pccs->var.tx_request.tx_rate);
993 writeb(0, &pccs->var.tx_request.antenna);
Dominik Brodowski624dd662009-10-24 15:52:44 +0200994 pr_debug("ray_hw_xmit default_tx_rate = 0x%x\n",
John Daiker141fa612009-03-10 06:59:54 -0700995 local->net_default_tx_rate);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700996
John Daiker141fa612009-03-10 06:59:54 -0700997 /* Interrupt the firmware to process the command */
998 if (interrupt_ecf(local, ccsindex)) {
Dominik Brodowski624dd662009-10-24 15:52:44 +0200999 pr_debug("ray_hw_xmit failed - ECF not ready for intr\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001000/* TBD very inefficient to copy packet to buffer, and then not
1001 send it, but the alternative is to queue the messages and that
1002 won't be done for a while. Maybe set tbusy until a CCS is free?
1003*/
John Daiker141fa612009-03-10 06:59:54 -07001004 writeb(CCS_BUFFER_FREE, &pccs->buffer_status);
1005 return XMIT_NO_INTR;
1006 }
1007 return XMIT_OK;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001008} /* end ray_hw_xmit */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001009
John Daiker141fa612009-03-10 06:59:54 -07001010/*===========================================================================*/
1011static int translate_frame(ray_dev_t *local, struct tx_msg __iomem *ptx,
1012 unsigned char *data, int len)
1013{
1014 __be16 proto = ((struct ethhdr *)data)->h_proto;
1015 if (ntohs(proto) >= 1536) { /* DIX II ethernet frame */
Dominik Brodowski624dd662009-10-24 15:52:44 +02001016 pr_debug("ray_cs translate_frame DIX II\n");
John Daiker141fa612009-03-10 06:59:54 -07001017 /* Copy LLC header to card buffer */
1018 memcpy_toio(&ptx->var, eth2_llc, sizeof(eth2_llc));
1019 memcpy_toio(((void __iomem *)&ptx->var) + sizeof(eth2_llc),
1020 (UCHAR *) &proto, 2);
1021 if (proto == htons(ETH_P_AARP) || proto == htons(ETH_P_IPX)) {
1022 /* This is the selective translation table, only 2 entries */
1023 writeb(0xf8,
1024 &((struct snaphdr_t __iomem *)ptx->var)->org[3]);
1025 }
1026 /* Copy body of ethernet packet without ethernet header */
1027 memcpy_toio((void __iomem *)&ptx->var +
1028 sizeof(struct snaphdr_t), data + ETH_HLEN,
1029 len - ETH_HLEN);
1030 return (int)sizeof(struct snaphdr_t) - ETH_HLEN;
1031 } else { /* already 802 type, and proto is length */
Dominik Brodowski624dd662009-10-24 15:52:44 +02001032 pr_debug("ray_cs translate_frame 802\n");
John Daiker141fa612009-03-10 06:59:54 -07001033 if (proto == htons(0xffff)) { /* evil netware IPX 802.3 without LLC */
Dominik Brodowski624dd662009-10-24 15:52:44 +02001034 pr_debug("ray_cs translate_frame evil IPX\n");
John Daiker141fa612009-03-10 06:59:54 -07001035 memcpy_toio(&ptx->var, data + ETH_HLEN, len - ETH_HLEN);
1036 return 0 - ETH_HLEN;
1037 }
1038 memcpy_toio(&ptx->var, data + ETH_HLEN, len - ETH_HLEN);
1039 return 0 - ETH_HLEN;
1040 }
1041 /* TBD do other frame types */
1042} /* end translate_frame */
1043
1044/*===========================================================================*/
1045static void ray_build_header(ray_dev_t *local, struct tx_msg __iomem *ptx,
1046 UCHAR msg_type, unsigned char *data)
1047{
1048 writeb(PROTOCOL_VER | msg_type, &ptx->mac.frame_ctl_1);
1049/*** IEEE 802.11 Address field assignments *************
1050 TODS FROMDS addr_1 addr_2 addr_3 addr_4
1051Adhoc 0 0 dest src (terminal) BSSID N/A
1052AP to Terminal 0 1 dest AP(BSSID) source N/A
1053Terminal to AP 1 0 AP(BSSID) src (terminal) dest N/A
1054AP to AP 1 1 dest AP src AP dest source
1055*******************************************************/
1056 if (local->net_type == ADHOC) {
1057 writeb(0, &ptx->mac.frame_ctl_2);
1058 memcpy_toio(ptx->mac.addr_1, ((struct ethhdr *)data)->h_dest,
1059 2 * ADDRLEN);
1060 memcpy_toio(ptx->mac.addr_3, local->bss_id, ADDRLEN);
1061 } else { /* infrastructure */
1062
1063 if (local->sparm.b4.a_acting_as_ap_status) {
1064 writeb(FC2_FROM_DS, &ptx->mac.frame_ctl_2);
1065 memcpy_toio(ptx->mac.addr_1,
1066 ((struct ethhdr *)data)->h_dest, ADDRLEN);
1067 memcpy_toio(ptx->mac.addr_2, local->bss_id, 6);
1068 memcpy_toio(ptx->mac.addr_3,
1069 ((struct ethhdr *)data)->h_source, ADDRLEN);
1070 } else { /* Terminal */
1071
1072 writeb(FC2_TO_DS, &ptx->mac.frame_ctl_2);
1073 memcpy_toio(ptx->mac.addr_1, local->bss_id, ADDRLEN);
1074 memcpy_toio(ptx->mac.addr_2,
1075 ((struct ethhdr *)data)->h_source, ADDRLEN);
1076 memcpy_toio(ptx->mac.addr_3,
1077 ((struct ethhdr *)data)->h_dest, ADDRLEN);
1078 }
1079 }
1080} /* end encapsulate_frame */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001081
1082/*===========================================================================*/
1083
1084static void netdev_get_drvinfo(struct net_device *dev,
1085 struct ethtool_drvinfo *info)
1086{
1087 strcpy(info->driver, "ray_cs");
1088}
1089
Jeff Garzik7282d492006-09-13 14:30:00 -04001090static const struct ethtool_ops netdev_ethtool_ops = {
John Daiker141fa612009-03-10 06:59:54 -07001091 .get_drvinfo = netdev_get_drvinfo,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001092};
1093
1094/*====================================================================*/
1095
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001096/*------------------------------------------------------------------*/
1097/*
1098 * Wireless Handler : get protocol name
1099 */
Joe Perches43ead782010-03-18 18:29:40 -07001100static int ray_get_name(struct net_device *dev, struct iw_request_info *info,
1101 union iwreq_data *wrqu, char *extra)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001102{
Joe Perches43ead782010-03-18 18:29:40 -07001103 strcpy(wrqu->name, "IEEE 802.11-FH");
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001104 return 0;
1105}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001106
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001107/*------------------------------------------------------------------*/
1108/*
1109 * Wireless Handler : set frequency
1110 */
Joe Perches43ead782010-03-18 18:29:40 -07001111static int ray_set_freq(struct net_device *dev, struct iw_request_info *info,
1112 union iwreq_data *wrqu, char *extra)
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001113{
Yoann Padioleau6dbc9c82007-08-03 19:37:16 +02001114 ray_dev_t *local = netdev_priv(dev);
John Daiker141fa612009-03-10 06:59:54 -07001115 int err = -EINPROGRESS; /* Call commit handler */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001116
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001117 /* Reject if card is already initialised */
John Daiker141fa612009-03-10 06:59:54 -07001118 if (local->card_status != CARD_AWAITING_PARAM)
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001119 return -EBUSY;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001120
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001121 /* Setting by channel number */
Joe Perches43ead782010-03-18 18:29:40 -07001122 if ((wrqu->freq.m > USA_HOP_MOD) || (wrqu->freq.e > 0))
Linus Torvalds1da177e2005-04-16 15:20:36 -07001123 err = -EOPNOTSUPP;
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001124 else
Joe Perches43ead782010-03-18 18:29:40 -07001125 local->sparm.b5.a_hop_pattern = wrqu->freq.m;
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001126
1127 return err;
1128}
John Daiker141fa612009-03-10 06:59:54 -07001129
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001130/*------------------------------------------------------------------*/
1131/*
1132 * Wireless Handler : get frequency
1133 */
Joe Perches43ead782010-03-18 18:29:40 -07001134static int ray_get_freq(struct net_device *dev, struct iw_request_info *info,
1135 union iwreq_data *wrqu, char *extra)
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001136{
Yoann Padioleau6dbc9c82007-08-03 19:37:16 +02001137 ray_dev_t *local = netdev_priv(dev);
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001138
Joe Perches43ead782010-03-18 18:29:40 -07001139 wrqu->freq.m = local->sparm.b5.a_hop_pattern;
1140 wrqu->freq.e = 0;
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001141 return 0;
1142}
1143
1144/*------------------------------------------------------------------*/
1145/*
1146 * Wireless Handler : set ESSID
1147 */
Joe Perches43ead782010-03-18 18:29:40 -07001148static int ray_set_essid(struct net_device *dev, struct iw_request_info *info,
1149 union iwreq_data *wrqu, char *extra)
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001150{
Yoann Padioleau6dbc9c82007-08-03 19:37:16 +02001151 ray_dev_t *local = netdev_priv(dev);
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001152
1153 /* Reject if card is already initialised */
John Daiker141fa612009-03-10 06:59:54 -07001154 if (local->card_status != CARD_AWAITING_PARAM)
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001155 return -EBUSY;
1156
1157 /* Check if we asked for `any' */
Joe Perches43ead782010-03-18 18:29:40 -07001158 if (wrqu->essid.flags == 0)
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001159 /* Corey : can you do that ? */
1160 return -EOPNOTSUPP;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001161
Joe Perches43ead782010-03-18 18:29:40 -07001162 /* Check the size of the string */
1163 if (wrqu->essid.length > IW_ESSID_MAX_SIZE)
1164 return -E2BIG;
1165
1166 /* Set the ESSID in the card */
1167 memset(local->sparm.b5.a_current_ess_id, 0, IW_ESSID_MAX_SIZE);
1168 memcpy(local->sparm.b5.a_current_ess_id, extra, wrqu->essid.length);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001169
John Daiker141fa612009-03-10 06:59:54 -07001170 return -EINPROGRESS; /* Call commit handler */
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001171}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001172
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001173/*------------------------------------------------------------------*/
1174/*
1175 * Wireless Handler : get ESSID
1176 */
Joe Perches43ead782010-03-18 18:29:40 -07001177static int ray_get_essid(struct net_device *dev, struct iw_request_info *info,
1178 union iwreq_data *wrqu, char *extra)
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001179{
Yoann Padioleau6dbc9c82007-08-03 19:37:16 +02001180 ray_dev_t *local = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001181
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001182 /* Get the essid that was set */
1183 memcpy(extra, local->sparm.b5.a_current_ess_id, IW_ESSID_MAX_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001184
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001185 /* Push it out ! */
Joe Perches43ead782010-03-18 18:29:40 -07001186 wrqu->essid.length = strlen(extra);
1187 wrqu->essid.flags = 1; /* active */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001188
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001189 return 0;
1190}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001191
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001192/*------------------------------------------------------------------*/
1193/*
1194 * Wireless Handler : get AP address
1195 */
Joe Perches43ead782010-03-18 18:29:40 -07001196static int ray_get_wap(struct net_device *dev, struct iw_request_info *info,
1197 union iwreq_data *wrqu, char *extra)
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001198{
Yoann Padioleau6dbc9c82007-08-03 19:37:16 +02001199 ray_dev_t *local = netdev_priv(dev);
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001200
Joe Perches43ead782010-03-18 18:29:40 -07001201 memcpy(wrqu->ap_addr.sa_data, local->bss_id, ETH_ALEN);
1202 wrqu->ap_addr.sa_family = ARPHRD_ETHER;
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001203
1204 return 0;
1205}
1206
1207/*------------------------------------------------------------------*/
1208/*
1209 * Wireless Handler : set Bit-Rate
1210 */
Joe Perches43ead782010-03-18 18:29:40 -07001211static int ray_set_rate(struct net_device *dev, struct iw_request_info *info,
1212 union iwreq_data *wrqu, char *extra)
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001213{
Yoann Padioleau6dbc9c82007-08-03 19:37:16 +02001214 ray_dev_t *local = netdev_priv(dev);
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001215
1216 /* Reject if card is already initialised */
John Daiker141fa612009-03-10 06:59:54 -07001217 if (local->card_status != CARD_AWAITING_PARAM)
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001218 return -EBUSY;
1219
1220 /* Check if rate is in range */
Joe Perches43ead782010-03-18 18:29:40 -07001221 if ((wrqu->bitrate.value != 1000000) && (wrqu->bitrate.value != 2000000))
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001222 return -EINVAL;
1223
1224 /* Hack for 1.5 Mb/s instead of 2 Mb/s */
John Daiker141fa612009-03-10 06:59:54 -07001225 if ((local->fw_ver == 0x55) && /* Please check */
Joe Perches43ead782010-03-18 18:29:40 -07001226 (wrqu->bitrate.value == 2000000))
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001227 local->net_default_tx_rate = 3;
1228 else
Joe Perches43ead782010-03-18 18:29:40 -07001229 local->net_default_tx_rate = wrqu->bitrate.value / 500000;
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001230
1231 return 0;
1232}
1233
1234/*------------------------------------------------------------------*/
1235/*
1236 * Wireless Handler : get Bit-Rate
1237 */
Joe Perches43ead782010-03-18 18:29:40 -07001238static int ray_get_rate(struct net_device *dev, struct iw_request_info *info,
1239 union iwreq_data *wrqu, char *extra)
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001240{
Yoann Padioleau6dbc9c82007-08-03 19:37:16 +02001241 ray_dev_t *local = netdev_priv(dev);
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001242
John Daiker141fa612009-03-10 06:59:54 -07001243 if (local->net_default_tx_rate == 3)
Joe Perches43ead782010-03-18 18:29:40 -07001244 wrqu->bitrate.value = 2000000; /* Hum... */
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001245 else
Joe Perches43ead782010-03-18 18:29:40 -07001246 wrqu->bitrate.value = local->net_default_tx_rate * 500000;
1247 wrqu->bitrate.fixed = 0; /* We are in auto mode */
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001248
1249 return 0;
1250}
1251
1252/*------------------------------------------------------------------*/
1253/*
1254 * Wireless Handler : set RTS threshold
1255 */
Joe Perches43ead782010-03-18 18:29:40 -07001256static int ray_set_rts(struct net_device *dev, struct iw_request_info *info,
1257 union iwreq_data *wrqu, char *extra)
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001258{
Yoann Padioleau6dbc9c82007-08-03 19:37:16 +02001259 ray_dev_t *local = netdev_priv(dev);
Joe Perches43ead782010-03-18 18:29:40 -07001260 int rthr = wrqu->rts.value;
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001261
1262 /* Reject if card is already initialised */
John Daiker141fa612009-03-10 06:59:54 -07001263 if (local->card_status != CARD_AWAITING_PARAM)
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001264 return -EBUSY;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001265
1266 /* if(wrq->u.rts.fixed == 0) we should complain */
Joe Perches43ead782010-03-18 18:29:40 -07001267 if (wrqu->rts.disabled)
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001268 rthr = 32767;
1269 else {
John Daiker141fa612009-03-10 06:59:54 -07001270 if ((rthr < 0) || (rthr > 2347)) /* What's the max packet size ??? */
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001271 return -EINVAL;
1272 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001273 local->sparm.b5.a_rts_threshold[0] = (rthr >> 8) & 0xFF;
1274 local->sparm.b5.a_rts_threshold[1] = rthr & 0xFF;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001275
John Daiker141fa612009-03-10 06:59:54 -07001276 return -EINPROGRESS; /* Call commit handler */
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001277}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001278
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001279/*------------------------------------------------------------------*/
1280/*
1281 * Wireless Handler : get RTS threshold
1282 */
Joe Perches43ead782010-03-18 18:29:40 -07001283static int ray_get_rts(struct net_device *dev, struct iw_request_info *info,
1284 union iwreq_data *wrqu, char *extra)
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001285{
Yoann Padioleau6dbc9c82007-08-03 19:37:16 +02001286 ray_dev_t *local = netdev_priv(dev);
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001287
Joe Perches43ead782010-03-18 18:29:40 -07001288 wrqu->rts.value = (local->sparm.b5.a_rts_threshold[0] << 8)
John Daiker141fa612009-03-10 06:59:54 -07001289 + local->sparm.b5.a_rts_threshold[1];
Joe Perches43ead782010-03-18 18:29:40 -07001290 wrqu->rts.disabled = (wrqu->rts.value == 32767);
1291 wrqu->rts.fixed = 1;
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001292
1293 return 0;
1294}
1295
1296/*------------------------------------------------------------------*/
1297/*
1298 * Wireless Handler : set Fragmentation threshold
1299 */
Joe Perches43ead782010-03-18 18:29:40 -07001300static int ray_set_frag(struct net_device *dev, struct iw_request_info *info,
1301 union iwreq_data *wrqu, char *extra)
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001302{
Yoann Padioleau6dbc9c82007-08-03 19:37:16 +02001303 ray_dev_t *local = netdev_priv(dev);
Joe Perches43ead782010-03-18 18:29:40 -07001304 int fthr = wrqu->frag.value;
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001305
1306 /* Reject if card is already initialised */
John Daiker141fa612009-03-10 06:59:54 -07001307 if (local->card_status != CARD_AWAITING_PARAM)
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001308 return -EBUSY;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001309
1310 /* if(wrq->u.frag.fixed == 0) should complain */
Joe Perches43ead782010-03-18 18:29:40 -07001311 if (wrqu->frag.disabled)
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001312 fthr = 32767;
1313 else {
John Daiker141fa612009-03-10 06:59:54 -07001314 if ((fthr < 256) || (fthr > 2347)) /* To check out ! */
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001315 return -EINVAL;
1316 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001317 local->sparm.b5.a_frag_threshold[0] = (fthr >> 8) & 0xFF;
1318 local->sparm.b5.a_frag_threshold[1] = fthr & 0xFF;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001319
John Daiker141fa612009-03-10 06:59:54 -07001320 return -EINPROGRESS; /* Call commit handler */
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001321}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001322
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001323/*------------------------------------------------------------------*/
1324/*
1325 * Wireless Handler : get Fragmentation threshold
1326 */
Joe Perches43ead782010-03-18 18:29:40 -07001327static int ray_get_frag(struct net_device *dev, struct iw_request_info *info,
1328 union iwreq_data *wrqu, char *extra)
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001329{
Yoann Padioleau6dbc9c82007-08-03 19:37:16 +02001330 ray_dev_t *local = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001331
Joe Perches43ead782010-03-18 18:29:40 -07001332 wrqu->frag.value = (local->sparm.b5.a_frag_threshold[0] << 8)
John Daiker141fa612009-03-10 06:59:54 -07001333 + local->sparm.b5.a_frag_threshold[1];
Joe Perches43ead782010-03-18 18:29:40 -07001334 wrqu->frag.disabled = (wrqu->frag.value == 32767);
1335 wrqu->frag.fixed = 1;
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001336
1337 return 0;
1338}
1339
1340/*------------------------------------------------------------------*/
1341/*
1342 * Wireless Handler : set Mode of Operation
1343 */
Joe Perches43ead782010-03-18 18:29:40 -07001344static int ray_set_mode(struct net_device *dev, struct iw_request_info *info,
1345 union iwreq_data *wrqu, char *extra)
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001346{
Yoann Padioleau6dbc9c82007-08-03 19:37:16 +02001347 ray_dev_t *local = netdev_priv(dev);
John Daiker141fa612009-03-10 06:59:54 -07001348 int err = -EINPROGRESS; /* Call commit handler */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001349 char card_mode = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001350
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001351 /* Reject if card is already initialised */
John Daiker141fa612009-03-10 06:59:54 -07001352 if (local->card_status != CARD_AWAITING_PARAM)
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001353 return -EBUSY;
1354
Joe Perches43ead782010-03-18 18:29:40 -07001355 switch (wrqu->mode) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001356 case IW_MODE_ADHOC:
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001357 card_mode = 0;
John Daiker141fa612009-03-10 06:59:54 -07001358 /* Fall through */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001359 case IW_MODE_INFRA:
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001360 local->sparm.b5.a_network_type = card_mode;
1361 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001362 default:
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001363 err = -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001364 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001365
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001366 return err;
1367}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001368
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001369/*------------------------------------------------------------------*/
1370/*
1371 * Wireless Handler : get Mode of Operation
1372 */
Joe Perches43ead782010-03-18 18:29:40 -07001373static int ray_get_mode(struct net_device *dev, struct iw_request_info *info,
1374 union iwreq_data *wrqu, char *extra)
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001375{
Yoann Padioleau6dbc9c82007-08-03 19:37:16 +02001376 ray_dev_t *local = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001377
John Daiker141fa612009-03-10 06:59:54 -07001378 if (local->sparm.b5.a_network_type)
Joe Perches43ead782010-03-18 18:29:40 -07001379 wrqu->mode = IW_MODE_INFRA;
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001380 else
Joe Perches43ead782010-03-18 18:29:40 -07001381 wrqu->mode = IW_MODE_ADHOC;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001382
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001383 return 0;
1384}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001385
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001386/*------------------------------------------------------------------*/
1387/*
1388 * Wireless Handler : get range info
1389 */
Joe Perches43ead782010-03-18 18:29:40 -07001390static int ray_get_range(struct net_device *dev, struct iw_request_info *info,
1391 union iwreq_data *wrqu, char *extra)
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001392{
John Daiker141fa612009-03-10 06:59:54 -07001393 struct iw_range *range = (struct iw_range *)extra;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001394
Joe Perches43ead782010-03-18 18:29:40 -07001395 memset(range, 0, sizeof(struct iw_range));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001396
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001397 /* Set the length (very important for backward compatibility) */
Joe Perches43ead782010-03-18 18:29:40 -07001398 wrqu->data.length = sizeof(struct iw_range);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001399
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001400 /* Set the Wireless Extension versions */
1401 range->we_version_compiled = WIRELESS_EXT;
1402 range->we_version_source = 9;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001403
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001404 /* Set information in the range struct */
1405 range->throughput = 1.1 * 1000 * 1000; /* Put the right number here */
John Daiker141fa612009-03-10 06:59:54 -07001406 range->num_channels = hop_pattern_length[(int)country];
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001407 range->num_frequency = 0;
1408 range->max_qual.qual = 0;
1409 range->max_qual.level = 255; /* What's the correct value ? */
1410 range->max_qual.noise = 255; /* Idem */
1411 range->num_bitrates = 2;
1412 range->bitrate[0] = 1000000; /* 1 Mb/s */
1413 range->bitrate[1] = 2000000; /* 2 Mb/s */
1414 return 0;
1415}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001416
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001417/*------------------------------------------------------------------*/
1418/*
1419 * Wireless Private Handler : set framing mode
1420 */
Joe Perches43ead782010-03-18 18:29:40 -07001421static int ray_set_framing(struct net_device *dev, struct iw_request_info *info,
John Daiker141fa612009-03-10 06:59:54 -07001422 union iwreq_data *wrqu, char *extra)
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001423{
1424 translate = *(extra); /* Set framing mode */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001425
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001426 return 0;
1427}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001428
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001429/*------------------------------------------------------------------*/
1430/*
1431 * Wireless Private Handler : get framing mode
1432 */
Joe Perches43ead782010-03-18 18:29:40 -07001433static int ray_get_framing(struct net_device *dev, struct iw_request_info *info,
John Daiker141fa612009-03-10 06:59:54 -07001434 union iwreq_data *wrqu, char *extra)
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001435{
1436 *(extra) = translate;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001437
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001438 return 0;
1439}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001440
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001441/*------------------------------------------------------------------*/
1442/*
1443 * Wireless Private Handler : get country
1444 */
Joe Perches43ead782010-03-18 18:29:40 -07001445static int ray_get_country(struct net_device *dev, struct iw_request_info *info,
John Daiker141fa612009-03-10 06:59:54 -07001446 union iwreq_data *wrqu, char *extra)
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001447{
1448 *(extra) = country;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001449
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001450 return 0;
1451}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001452
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001453/*------------------------------------------------------------------*/
1454/*
1455 * Commit handler : called after a bunch of SET operations
1456 */
Joe Perches43ead782010-03-18 18:29:40 -07001457static int ray_commit(struct net_device *dev, struct iw_request_info *info,
1458 union iwreq_data *wrqu, char *extra)
1459{
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001460 return 0;
1461}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001462
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001463/*------------------------------------------------------------------*/
1464/*
1465 * Stats handler : return Wireless Stats
1466 */
John Daiker141fa612009-03-10 06:59:54 -07001467static iw_stats *ray_get_wireless_stats(struct net_device *dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001468{
John Daiker141fa612009-03-10 06:59:54 -07001469 ray_dev_t *local = netdev_priv(dev);
1470 struct pcmcia_device *link = local->finder;
1471 struct status __iomem *p = local->sram + STATUS_BASE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001472
John Daiker141fa612009-03-10 06:59:54 -07001473 local->wstats.status = local->card_status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001474#ifdef WIRELESS_SPY
John Daiker141fa612009-03-10 06:59:54 -07001475 if ((local->spy_data.spy_number > 0)
1476 && (local->sparm.b5.a_network_type == 0)) {
1477 /* Get it from the first node in spy list */
1478 local->wstats.qual.qual = local->spy_data.spy_stat[0].qual;
1479 local->wstats.qual.level = local->spy_data.spy_stat[0].level;
1480 local->wstats.qual.noise = local->spy_data.spy_stat[0].noise;
1481 local->wstats.qual.updated =
1482 local->spy_data.spy_stat[0].updated;
1483 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001484#endif /* WIRELESS_SPY */
1485
John Daiker141fa612009-03-10 06:59:54 -07001486 if (pcmcia_dev_present(link)) {
1487 local->wstats.qual.noise = readb(&p->rxnoise);
1488 local->wstats.qual.updated |= 4;
1489 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001490
John Daiker141fa612009-03-10 06:59:54 -07001491 return &local->wstats;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001492} /* end ray_get_wireless_stats */
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001493
1494/*------------------------------------------------------------------*/
1495/*
1496 * Structures to export the Wireless Handlers
1497 */
1498
John Daiker141fa612009-03-10 06:59:54 -07001499static const iw_handler ray_handler[] = {
Joe Perches43ead782010-03-18 18:29:40 -07001500 IW_HANDLER(SIOCSIWCOMMIT, ray_commit),
1501 IW_HANDLER(SIOCGIWNAME, ray_get_name),
1502 IW_HANDLER(SIOCSIWFREQ, ray_set_freq),
1503 IW_HANDLER(SIOCGIWFREQ, ray_get_freq),
1504 IW_HANDLER(SIOCSIWMODE, ray_set_mode),
1505 IW_HANDLER(SIOCGIWMODE, ray_get_mode),
1506 IW_HANDLER(SIOCGIWRANGE, ray_get_range),
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001507#ifdef WIRELESS_SPY
Joe Perches270020e2010-03-18 18:29:37 -07001508 IW_HANDLER(SIOCSIWSPY, iw_handler_set_spy),
1509 IW_HANDLER(SIOCGIWSPY, iw_handler_get_spy),
1510 IW_HANDLER(SIOCSIWTHRSPY, iw_handler_set_thrspy),
1511 IW_HANDLER(SIOCGIWTHRSPY, iw_handler_get_thrspy),
John Daiker141fa612009-03-10 06:59:54 -07001512#endif /* WIRELESS_SPY */
Joe Perches43ead782010-03-18 18:29:40 -07001513 IW_HANDLER(SIOCGIWAP, ray_get_wap),
1514 IW_HANDLER(SIOCSIWESSID, ray_set_essid),
1515 IW_HANDLER(SIOCGIWESSID, ray_get_essid),
1516 IW_HANDLER(SIOCSIWRATE, ray_set_rate),
1517 IW_HANDLER(SIOCGIWRATE, ray_get_rate),
1518 IW_HANDLER(SIOCSIWRTS, ray_set_rts),
1519 IW_HANDLER(SIOCGIWRTS, ray_get_rts),
1520 IW_HANDLER(SIOCSIWFRAG, ray_set_frag),
1521 IW_HANDLER(SIOCGIWFRAG, ray_get_frag),
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001522};
1523
John Daiker141fa612009-03-10 06:59:54 -07001524#define SIOCSIPFRAMING SIOCIWFIRSTPRIV /* Set framing mode */
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001525#define SIOCGIPFRAMING SIOCIWFIRSTPRIV + 1 /* Get framing mode */
1526#define SIOCGIPCOUNTRY SIOCIWFIRSTPRIV + 3 /* Get country code */
1527
John Daiker141fa612009-03-10 06:59:54 -07001528static const iw_handler ray_private_handler[] = {
Joe Perches43ead782010-03-18 18:29:40 -07001529 [0] = ray_set_framing,
1530 [1] = ray_get_framing,
1531 [3] = ray_get_country,
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001532};
1533
John Daiker141fa612009-03-10 06:59:54 -07001534static const struct iw_priv_args ray_private_args[] = {
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001535/* cmd, set_args, get_args, name */
John Daiker141fa612009-03-10 06:59:54 -07001536 {SIOCSIPFRAMING, IW_PRIV_TYPE_BYTE | IW_PRIV_SIZE_FIXED | 1, 0,
1537 "set_framing"},
1538 {SIOCGIPFRAMING, 0, IW_PRIV_TYPE_BYTE | IW_PRIV_SIZE_FIXED | 1,
1539 "get_framing"},
1540 {SIOCGIPCOUNTRY, 0, IW_PRIV_TYPE_BYTE | IW_PRIV_SIZE_FIXED | 1,
1541 "get_country"},
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001542};
1543
John Daiker141fa612009-03-10 06:59:54 -07001544static const struct iw_handler_def ray_handler_def = {
1545 .num_standard = ARRAY_SIZE(ray_handler),
1546 .num_private = ARRAY_SIZE(ray_private_handler),
Denis Chengff8ac602007-09-02 18:30:18 +08001547 .num_private_args = ARRAY_SIZE(ray_private_args),
John Daiker141fa612009-03-10 06:59:54 -07001548 .standard = ray_handler,
1549 .private = ray_private_handler,
1550 .private_args = ray_private_args,
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001551 .get_wireless_stats = ray_get_wireless_stats,
1552};
1553
Linus Torvalds1da177e2005-04-16 15:20:36 -07001554/*===========================================================================*/
1555static int ray_open(struct net_device *dev)
1556{
John Daiker141fa612009-03-10 06:59:54 -07001557 ray_dev_t *local = netdev_priv(dev);
1558 struct pcmcia_device *link;
1559 link = local->finder;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001560
Dominik Brodowski624dd662009-10-24 15:52:44 +02001561 dev_dbg(&link->dev, "ray_open('%s')\n", dev->name);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001562
John Daiker141fa612009-03-10 06:59:54 -07001563 if (link->open == 0)
1564 local->num_multi = 0;
1565 link->open++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001566
John Daiker141fa612009-03-10 06:59:54 -07001567 /* If the card is not started, time to start it ! - Jean II */
1568 if (local->card_status == CARD_AWAITING_PARAM) {
1569 int i;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001570
Dominik Brodowski624dd662009-10-24 15:52:44 +02001571 dev_dbg(&link->dev, "ray_open: doing init now !\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001572
John Daiker141fa612009-03-10 06:59:54 -07001573 /* Download startup parameters */
1574 if ((i = dl_startup_params(dev)) < 0) {
1575 printk(KERN_INFO
1576 "ray_dev_init dl_startup_params failed - "
1577 "returns 0x%x\n", i);
1578 return -1;
1579 }
1580 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001581
John Daiker141fa612009-03-10 06:59:54 -07001582 if (sniffer)
1583 netif_stop_queue(dev);
1584 else
1585 netif_start_queue(dev);
1586
Dominik Brodowski624dd662009-10-24 15:52:44 +02001587 dev_dbg(&link->dev, "ray_open ending\n");
John Daiker141fa612009-03-10 06:59:54 -07001588 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001589} /* end ray_open */
John Daiker141fa612009-03-10 06:59:54 -07001590
Linus Torvalds1da177e2005-04-16 15:20:36 -07001591/*===========================================================================*/
1592static int ray_dev_close(struct net_device *dev)
1593{
John Daiker141fa612009-03-10 06:59:54 -07001594 ray_dev_t *local = netdev_priv(dev);
1595 struct pcmcia_device *link;
1596 link = local->finder;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001597
Dominik Brodowski624dd662009-10-24 15:52:44 +02001598 dev_dbg(&link->dev, "ray_dev_close('%s')\n", dev->name);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001599
John Daiker141fa612009-03-10 06:59:54 -07001600 link->open--;
1601 netif_stop_queue(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001602
John Daiker141fa612009-03-10 06:59:54 -07001603 /* In here, we should stop the hardware (stop card from beeing active)
1604 * and set local->card_status to CARD_AWAITING_PARAM, so that while the
1605 * card is closed we can chage its configuration.
1606 * Probably also need a COR reset to get sane state - Jean II */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001607
John Daiker141fa612009-03-10 06:59:54 -07001608 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001609} /* end ray_dev_close */
John Daiker141fa612009-03-10 06:59:54 -07001610
Linus Torvalds1da177e2005-04-16 15:20:36 -07001611/*===========================================================================*/
John Daiker141fa612009-03-10 06:59:54 -07001612static void ray_reset(struct net_device *dev)
1613{
Dominik Brodowski624dd662009-10-24 15:52:44 +02001614 pr_debug("ray_reset entered\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001615}
John Daiker141fa612009-03-10 06:59:54 -07001616
Linus Torvalds1da177e2005-04-16 15:20:36 -07001617/*===========================================================================*/
1618/* Cause a firmware interrupt if it is ready for one */
1619/* Return nonzero if not ready */
1620static int interrupt_ecf(ray_dev_t *local, int ccs)
1621{
John Daiker141fa612009-03-10 06:59:54 -07001622 int i = 50;
1623 struct pcmcia_device *link = local->finder;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001624
John Daiker141fa612009-03-10 06:59:54 -07001625 if (!(pcmcia_dev_present(link))) {
Dominik Brodowski624dd662009-10-24 15:52:44 +02001626 dev_dbg(&link->dev, "ray_cs interrupt_ecf - device not present\n");
John Daiker141fa612009-03-10 06:59:54 -07001627 return -1;
1628 }
Dominik Brodowski624dd662009-10-24 15:52:44 +02001629 dev_dbg(&link->dev, "interrupt_ecf(local=%p, ccs = 0x%x\n", local, ccs);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001630
John Daiker141fa612009-03-10 06:59:54 -07001631 while (i &&
1632 (readb(local->amem + CIS_OFFSET + ECF_INTR_OFFSET) &
1633 ECF_INTR_SET))
1634 i--;
1635 if (i == 0) {
Dominik Brodowski624dd662009-10-24 15:52:44 +02001636 dev_dbg(&link->dev, "ray_cs interrupt_ecf card not ready for interrupt\n");
John Daiker141fa612009-03-10 06:59:54 -07001637 return -1;
1638 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001639 /* Fill the mailbox, then kick the card */
John Daiker141fa612009-03-10 06:59:54 -07001640 writeb(ccs, local->sram + SCB_BASE);
1641 writeb(ECF_INTR_SET, local->amem + CIS_OFFSET + ECF_INTR_OFFSET);
1642 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001643} /* interrupt_ecf */
John Daiker141fa612009-03-10 06:59:54 -07001644
Linus Torvalds1da177e2005-04-16 15:20:36 -07001645/*===========================================================================*/
1646/* Get next free transmit CCS */
1647/* Return - index of current tx ccs */
1648static int get_free_tx_ccs(ray_dev_t *local)
1649{
John Daiker141fa612009-03-10 06:59:54 -07001650 int i;
1651 struct ccs __iomem *pccs = ccs_base(local);
1652 struct pcmcia_device *link = local->finder;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001653
John Daiker141fa612009-03-10 06:59:54 -07001654 if (!(pcmcia_dev_present(link))) {
Dominik Brodowski624dd662009-10-24 15:52:44 +02001655 dev_dbg(&link->dev, "ray_cs get_free_tx_ccs - device not present\n");
John Daiker141fa612009-03-10 06:59:54 -07001656 return ECARDGONE;
1657 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001658
John Daiker141fa612009-03-10 06:59:54 -07001659 if (test_and_set_bit(0, &local->tx_ccs_lock)) {
Dominik Brodowski624dd662009-10-24 15:52:44 +02001660 dev_dbg(&link->dev, "ray_cs tx_ccs_lock busy\n");
John Daiker141fa612009-03-10 06:59:54 -07001661 return ECCSBUSY;
1662 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001663
John Daiker141fa612009-03-10 06:59:54 -07001664 for (i = 0; i < NUMBER_OF_TX_CCS; i++) {
1665 if (readb(&(pccs + i)->buffer_status) == CCS_BUFFER_FREE) {
1666 writeb(CCS_BUFFER_BUSY, &(pccs + i)->buffer_status);
1667 writeb(CCS_END_LIST, &(pccs + i)->link);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001668 local->tx_ccs_lock = 0;
John Daiker141fa612009-03-10 06:59:54 -07001669 return i;
1670 }
1671 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001672 local->tx_ccs_lock = 0;
Dominik Brodowski624dd662009-10-24 15:52:44 +02001673 dev_dbg(&link->dev, "ray_cs ERROR no free tx CCS for raylink card\n");
John Daiker141fa612009-03-10 06:59:54 -07001674 return ECCSFULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001675} /* get_free_tx_ccs */
John Daiker141fa612009-03-10 06:59:54 -07001676
Linus Torvalds1da177e2005-04-16 15:20:36 -07001677/*===========================================================================*/
1678/* Get next free CCS */
1679/* Return - index of current ccs */
1680static int get_free_ccs(ray_dev_t *local)
1681{
John Daiker141fa612009-03-10 06:59:54 -07001682 int i;
1683 struct ccs __iomem *pccs = ccs_base(local);
1684 struct pcmcia_device *link = local->finder;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001685
John Daiker141fa612009-03-10 06:59:54 -07001686 if (!(pcmcia_dev_present(link))) {
Dominik Brodowski624dd662009-10-24 15:52:44 +02001687 dev_dbg(&link->dev, "ray_cs get_free_ccs - device not present\n");
John Daiker141fa612009-03-10 06:59:54 -07001688 return ECARDGONE;
1689 }
1690 if (test_and_set_bit(0, &local->ccs_lock)) {
Dominik Brodowski624dd662009-10-24 15:52:44 +02001691 dev_dbg(&link->dev, "ray_cs ccs_lock busy\n");
John Daiker141fa612009-03-10 06:59:54 -07001692 return ECCSBUSY;
1693 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001694
John Daiker141fa612009-03-10 06:59:54 -07001695 for (i = NUMBER_OF_TX_CCS; i < NUMBER_OF_CCS; i++) {
1696 if (readb(&(pccs + i)->buffer_status) == CCS_BUFFER_FREE) {
1697 writeb(CCS_BUFFER_BUSY, &(pccs + i)->buffer_status);
1698 writeb(CCS_END_LIST, &(pccs + i)->link);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001699 local->ccs_lock = 0;
John Daiker141fa612009-03-10 06:59:54 -07001700 return i;
1701 }
1702 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001703 local->ccs_lock = 0;
Dominik Brodowski624dd662009-10-24 15:52:44 +02001704 dev_dbg(&link->dev, "ray_cs ERROR no free CCS for raylink card\n");
John Daiker141fa612009-03-10 06:59:54 -07001705 return ECCSFULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001706} /* get_free_ccs */
John Daiker141fa612009-03-10 06:59:54 -07001707
Linus Torvalds1da177e2005-04-16 15:20:36 -07001708/*===========================================================================*/
1709static void authenticate_timeout(u_long data)
1710{
John Daiker141fa612009-03-10 06:59:54 -07001711 ray_dev_t *local = (ray_dev_t *) data;
1712 del_timer(&local->timer);
1713 printk(KERN_INFO "ray_cs Authentication with access point failed"
1714 " - timeout\n");
1715 join_net((u_long) local);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001716}
John Daiker141fa612009-03-10 06:59:54 -07001717
Linus Torvalds1da177e2005-04-16 15:20:36 -07001718/*===========================================================================*/
1719static int asc_to_int(char a)
1720{
John Daiker141fa612009-03-10 06:59:54 -07001721 if (a < '0')
1722 return -1;
1723 if (a <= '9')
1724 return (a - '0');
1725 if (a < 'A')
1726 return -1;
1727 if (a <= 'F')
1728 return (10 + a - 'A');
1729 if (a < 'a')
1730 return -1;
1731 if (a <= 'f')
1732 return (10 + a - 'a');
1733 return -1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001734}
John Daiker141fa612009-03-10 06:59:54 -07001735
Linus Torvalds1da177e2005-04-16 15:20:36 -07001736/*===========================================================================*/
1737static int parse_addr(char *in_str, UCHAR *out)
1738{
John Daiker141fa612009-03-10 06:59:54 -07001739 int len;
1740 int i, j, k;
1741 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001742
John Daiker141fa612009-03-10 06:59:54 -07001743 if (in_str == NULL)
1744 return 0;
1745 if ((len = strlen(in_str)) < 2)
1746 return 0;
1747 memset(out, 0, ADDRLEN);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001748
John Daiker141fa612009-03-10 06:59:54 -07001749 status = 1;
1750 j = len - 1;
1751 if (j > 12)
1752 j = 12;
1753 i = 5;
1754
1755 while (j > 0) {
1756 if ((k = asc_to_int(in_str[j--])) != -1)
1757 out[i] = k;
1758 else
1759 return 0;
1760
1761 if (j == 0)
1762 break;
1763 if ((k = asc_to_int(in_str[j--])) != -1)
1764 out[i] += k << 4;
1765 else
1766 return 0;
1767 if (!i--)
1768 break;
1769 }
1770 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001771}
John Daiker141fa612009-03-10 06:59:54 -07001772
Linus Torvalds1da177e2005-04-16 15:20:36 -07001773/*===========================================================================*/
1774static struct net_device_stats *ray_get_stats(struct net_device *dev)
1775{
John Daiker141fa612009-03-10 06:59:54 -07001776 ray_dev_t *local = netdev_priv(dev);
1777 struct pcmcia_device *link = local->finder;
1778 struct status __iomem *p = local->sram + STATUS_BASE;
1779 if (!(pcmcia_dev_present(link))) {
Dominik Brodowski624dd662009-10-24 15:52:44 +02001780 dev_dbg(&link->dev, "ray_cs net_device_stats - device not present\n");
John Daiker141fa612009-03-10 06:59:54 -07001781 return &local->stats;
1782 }
1783 if (readb(&p->mrx_overflow_for_host)) {
1784 local->stats.rx_over_errors += swab16(readw(&p->mrx_overflow));
1785 writeb(0, &p->mrx_overflow);
1786 writeb(0, &p->mrx_overflow_for_host);
1787 }
1788 if (readb(&p->mrx_checksum_error_for_host)) {
1789 local->stats.rx_crc_errors +=
1790 swab16(readw(&p->mrx_checksum_error));
1791 writeb(0, &p->mrx_checksum_error);
1792 writeb(0, &p->mrx_checksum_error_for_host);
1793 }
1794 if (readb(&p->rx_hec_error_for_host)) {
1795 local->stats.rx_frame_errors += swab16(readw(&p->rx_hec_error));
1796 writeb(0, &p->rx_hec_error);
1797 writeb(0, &p->rx_hec_error_for_host);
1798 }
1799 return &local->stats;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001800}
John Daiker141fa612009-03-10 06:59:54 -07001801
Linus Torvalds1da177e2005-04-16 15:20:36 -07001802/*===========================================================================*/
John Daiker141fa612009-03-10 06:59:54 -07001803static void ray_update_parm(struct net_device *dev, UCHAR objid, UCHAR *value,
1804 int len)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001805{
John Daiker141fa612009-03-10 06:59:54 -07001806 ray_dev_t *local = netdev_priv(dev);
1807 struct pcmcia_device *link = local->finder;
1808 int ccsindex;
1809 int i;
1810 struct ccs __iomem *pccs;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001811
John Daiker141fa612009-03-10 06:59:54 -07001812 if (!(pcmcia_dev_present(link))) {
Dominik Brodowski624dd662009-10-24 15:52:44 +02001813 dev_dbg(&link->dev, "ray_update_parm - device not present\n");
John Daiker141fa612009-03-10 06:59:54 -07001814 return;
1815 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001816
John Daiker141fa612009-03-10 06:59:54 -07001817 if ((ccsindex = get_free_ccs(local)) < 0) {
Dominik Brodowski624dd662009-10-24 15:52:44 +02001818 dev_dbg(&link->dev, "ray_update_parm - No free ccs\n");
John Daiker141fa612009-03-10 06:59:54 -07001819 return;
1820 }
1821 pccs = ccs_base(local) + ccsindex;
1822 writeb(CCS_UPDATE_PARAMS, &pccs->cmd);
1823 writeb(objid, &pccs->var.update_param.object_id);
1824 writeb(1, &pccs->var.update_param.number_objects);
1825 writeb(0, &pccs->var.update_param.failure_cause);
1826 for (i = 0; i < len; i++) {
1827 writeb(value[i], local->sram + HOST_TO_ECF_BASE);
1828 }
1829 /* Interrupt the firmware to process the command */
1830 if (interrupt_ecf(local, ccsindex)) {
Dominik Brodowski624dd662009-10-24 15:52:44 +02001831 dev_dbg(&link->dev, "ray_cs associate failed - ECF not ready for intr\n");
John Daiker141fa612009-03-10 06:59:54 -07001832 writeb(CCS_BUFFER_FREE, &(pccs++)->buffer_status);
1833 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001834}
John Daiker141fa612009-03-10 06:59:54 -07001835
Linus Torvalds1da177e2005-04-16 15:20:36 -07001836/*===========================================================================*/
1837static void ray_update_multi_list(struct net_device *dev, int all)
1838{
John Daiker141fa612009-03-10 06:59:54 -07001839 int ccsindex;
1840 struct ccs __iomem *pccs;
John Daiker141fa612009-03-10 06:59:54 -07001841 ray_dev_t *local = netdev_priv(dev);
1842 struct pcmcia_device *link = local->finder;
1843 void __iomem *p = local->sram + HOST_TO_ECF_BASE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001844
John Daiker141fa612009-03-10 06:59:54 -07001845 if (!(pcmcia_dev_present(link))) {
Dominik Brodowski624dd662009-10-24 15:52:44 +02001846 dev_dbg(&link->dev, "ray_update_multi_list - device not present\n");
John Daiker141fa612009-03-10 06:59:54 -07001847 return;
1848 } else
Dominik Brodowski624dd662009-10-24 15:52:44 +02001849 dev_dbg(&link->dev, "ray_update_multi_list(%p)\n", dev);
John Daiker141fa612009-03-10 06:59:54 -07001850 if ((ccsindex = get_free_ccs(local)) < 0) {
Dominik Brodowski624dd662009-10-24 15:52:44 +02001851 dev_dbg(&link->dev, "ray_update_multi - No free ccs\n");
John Daiker141fa612009-03-10 06:59:54 -07001852 return;
1853 }
1854 pccs = ccs_base(local) + ccsindex;
1855 writeb(CCS_UPDATE_MULTICAST_LIST, &pccs->cmd);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001856
John Daiker141fa612009-03-10 06:59:54 -07001857 if (all) {
1858 writeb(0xff, &pccs->var);
1859 local->num_multi = 0xff;
1860 } else {
Jiri Pirko22bedad2010-04-01 21:22:57 +00001861 struct netdev_hw_addr *ha;
Jiri Pirko655ffee2010-02-27 07:35:45 +00001862 int i = 0;
1863
John Daiker141fa612009-03-10 06:59:54 -07001864 /* Copy the kernel's list of MC addresses to card */
Jiri Pirko22bedad2010-04-01 21:22:57 +00001865 netdev_for_each_mc_addr(ha, dev) {
1866 memcpy_toio(p, ha->addr, ETH_ALEN);
Dominik Brodowski624dd662009-10-24 15:52:44 +02001867 dev_dbg(&link->dev,
John Daiker141fa612009-03-10 06:59:54 -07001868 "ray_update_multi add addr %02x%02x%02x%02x%02x%02x\n",
Jiri Pirko22bedad2010-04-01 21:22:57 +00001869 ha->addr[0], ha->addr[1],
1870 ha->addr[2], ha->addr[3],
1871 ha->addr[4], ha->addr[5]);
John Daiker141fa612009-03-10 06:59:54 -07001872 p += ETH_ALEN;
1873 i++;
1874 }
1875 if (i > 256 / ADDRLEN)
1876 i = 256 / ADDRLEN;
1877 writeb((UCHAR) i, &pccs->var);
Dominik Brodowski624dd662009-10-24 15:52:44 +02001878 dev_dbg(&link->dev, "ray_cs update_multi %d addresses in list\n", i);
John Daiker141fa612009-03-10 06:59:54 -07001879 /* Interrupt the firmware to process the command */
1880 local->num_multi = i;
1881 }
1882 if (interrupt_ecf(local, ccsindex)) {
Dominik Brodowski624dd662009-10-24 15:52:44 +02001883 dev_dbg(&link->dev,
John Daiker141fa612009-03-10 06:59:54 -07001884 "ray_cs update_multi failed - ECF not ready for intr\n");
1885 writeb(CCS_BUFFER_FREE, &(pccs++)->buffer_status);
1886 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001887} /* end ray_update_multi_list */
John Daiker141fa612009-03-10 06:59:54 -07001888
Linus Torvalds1da177e2005-04-16 15:20:36 -07001889/*===========================================================================*/
1890static void set_multicast_list(struct net_device *dev)
1891{
John Daiker141fa612009-03-10 06:59:54 -07001892 ray_dev_t *local = netdev_priv(dev);
1893 UCHAR promisc;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001894
Dominik Brodowski624dd662009-10-24 15:52:44 +02001895 pr_debug("ray_cs set_multicast_list(%p)\n", dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001896
John Daiker141fa612009-03-10 06:59:54 -07001897 if (dev->flags & IFF_PROMISC) {
1898 if (local->sparm.b5.a_promiscuous_mode == 0) {
Dominik Brodowski624dd662009-10-24 15:52:44 +02001899 pr_debug("ray_cs set_multicast_list promisc on\n");
John Daiker141fa612009-03-10 06:59:54 -07001900 local->sparm.b5.a_promiscuous_mode = 1;
1901 promisc = 1;
1902 ray_update_parm(dev, OBJID_promiscuous_mode,
1903 &promisc, sizeof(promisc));
1904 }
1905 } else {
1906 if (local->sparm.b5.a_promiscuous_mode == 1) {
Dominik Brodowski624dd662009-10-24 15:52:44 +02001907 pr_debug("ray_cs set_multicast_list promisc off\n");
John Daiker141fa612009-03-10 06:59:54 -07001908 local->sparm.b5.a_promiscuous_mode = 0;
1909 promisc = 0;
1910 ray_update_parm(dev, OBJID_promiscuous_mode,
1911 &promisc, sizeof(promisc));
1912 }
1913 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001914
John Daiker141fa612009-03-10 06:59:54 -07001915 if (dev->flags & IFF_ALLMULTI)
1916 ray_update_multi_list(dev, 1);
1917 else {
Jiri Pirko4cd24ea2010-02-08 04:30:35 +00001918 if (local->num_multi != netdev_mc_count(dev))
John Daiker141fa612009-03-10 06:59:54 -07001919 ray_update_multi_list(dev, 0);
1920 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001921} /* end set_multicast_list */
John Daiker141fa612009-03-10 06:59:54 -07001922
Linus Torvalds1da177e2005-04-16 15:20:36 -07001923/*=============================================================================
1924 * All routines below here are run at interrupt time.
1925=============================================================================*/
David Howells7d12e782006-10-05 14:55:46 +01001926static irqreturn_t ray_interrupt(int irq, void *dev_id)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001927{
John Daiker141fa612009-03-10 06:59:54 -07001928 struct net_device *dev = (struct net_device *)dev_id;
1929 struct pcmcia_device *link;
1930 ray_dev_t *local;
1931 struct ccs __iomem *pccs;
1932 struct rcs __iomem *prcs;
1933 UCHAR rcsindex;
1934 UCHAR tmp;
1935 UCHAR cmd;
1936 UCHAR status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001937
John Daiker141fa612009-03-10 06:59:54 -07001938 if (dev == NULL) /* Note that we want interrupts with dev->start == 0 */
1939 return IRQ_NONE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001940
Dominik Brodowski624dd662009-10-24 15:52:44 +02001941 pr_debug("ray_cs: interrupt for *dev=%p\n", dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001942
John Daiker141fa612009-03-10 06:59:54 -07001943 local = netdev_priv(dev);
1944 link = (struct pcmcia_device *)local->finder;
1945 if (!pcmcia_dev_present(link)) {
Dominik Brodowski624dd662009-10-24 15:52:44 +02001946 pr_debug(
1947 "ray_cs interrupt from device not present or suspended.\n");
John Daiker141fa612009-03-10 06:59:54 -07001948 return IRQ_NONE;
1949 }
1950 rcsindex = readb(&((struct scb __iomem *)(local->sram))->rcs_index);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001951
John Daiker141fa612009-03-10 06:59:54 -07001952 if (rcsindex >= (NUMBER_OF_CCS + NUMBER_OF_RCS)) {
Dominik Brodowski624dd662009-10-24 15:52:44 +02001953 dev_dbg(&link->dev, "ray_cs interrupt bad rcsindex = 0x%x\n", rcsindex);
John Daiker141fa612009-03-10 06:59:54 -07001954 clear_interrupt(local);
1955 return IRQ_HANDLED;
1956 }
1957 if (rcsindex < NUMBER_OF_CCS) { /* If it's a returned CCS */
1958 pccs = ccs_base(local) + rcsindex;
1959 cmd = readb(&pccs->cmd);
1960 status = readb(&pccs->buffer_status);
1961 switch (cmd) {
1962 case CCS_DOWNLOAD_STARTUP_PARAMS: /* Happens in firmware someday */
1963 del_timer(&local->timer);
1964 if (status == CCS_COMMAND_COMPLETE) {
Dominik Brodowski624dd662009-10-24 15:52:44 +02001965 dev_dbg(&link->dev,
John Daiker141fa612009-03-10 06:59:54 -07001966 "ray_cs interrupt download_startup_parameters OK\n");
1967 } else {
Dominik Brodowski624dd662009-10-24 15:52:44 +02001968 dev_dbg(&link->dev,
John Daiker141fa612009-03-10 06:59:54 -07001969 "ray_cs interrupt download_startup_parameters fail\n");
1970 }
1971 break;
1972 case CCS_UPDATE_PARAMS:
Dominik Brodowski624dd662009-10-24 15:52:44 +02001973 dev_dbg(&link->dev, "ray_cs interrupt update params done\n");
John Daiker141fa612009-03-10 06:59:54 -07001974 if (status != CCS_COMMAND_COMPLETE) {
1975 tmp =
1976 readb(&pccs->var.update_param.
1977 failure_cause);
Dominik Brodowski624dd662009-10-24 15:52:44 +02001978 dev_dbg(&link->dev,
John Daiker141fa612009-03-10 06:59:54 -07001979 "ray_cs interrupt update params failed - reason %d\n",
1980 tmp);
1981 }
1982 break;
1983 case CCS_REPORT_PARAMS:
Dominik Brodowski624dd662009-10-24 15:52:44 +02001984 dev_dbg(&link->dev, "ray_cs interrupt report params done\n");
John Daiker141fa612009-03-10 06:59:54 -07001985 break;
1986 case CCS_UPDATE_MULTICAST_LIST: /* Note that this CCS isn't returned */
Dominik Brodowski624dd662009-10-24 15:52:44 +02001987 dev_dbg(&link->dev,
John Daiker141fa612009-03-10 06:59:54 -07001988 "ray_cs interrupt CCS Update Multicast List done\n");
1989 break;
1990 case CCS_UPDATE_POWER_SAVINGS_MODE:
Dominik Brodowski624dd662009-10-24 15:52:44 +02001991 dev_dbg(&link->dev,
John Daiker141fa612009-03-10 06:59:54 -07001992 "ray_cs interrupt update power save mode done\n");
1993 break;
1994 case CCS_START_NETWORK:
1995 case CCS_JOIN_NETWORK:
1996 if (status == CCS_COMMAND_COMPLETE) {
1997 if (readb
1998 (&pccs->var.start_network.net_initiated) ==
1999 1) {
Dominik Brodowski624dd662009-10-24 15:52:44 +02002000 dev_dbg(&link->dev,
John Daiker141fa612009-03-10 06:59:54 -07002001 "ray_cs interrupt network \"%s\" started\n",
2002 local->sparm.b4.a_current_ess_id);
2003 } else {
Dominik Brodowski624dd662009-10-24 15:52:44 +02002004 dev_dbg(&link->dev,
John Daiker141fa612009-03-10 06:59:54 -07002005 "ray_cs interrupt network \"%s\" joined\n",
2006 local->sparm.b4.a_current_ess_id);
2007 }
2008 memcpy_fromio(&local->bss_id,
2009 pccs->var.start_network.bssid,
2010 ADDRLEN);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002011
John Daiker141fa612009-03-10 06:59:54 -07002012 if (local->fw_ver == 0x55)
2013 local->net_default_tx_rate = 3;
2014 else
2015 local->net_default_tx_rate =
2016 readb(&pccs->var.start_network.
2017 net_default_tx_rate);
2018 local->encryption =
2019 readb(&pccs->var.start_network.encryption);
2020 if (!sniffer && (local->net_type == INFRA)
2021 && !(local->sparm.b4.a_acting_as_ap_status)) {
2022 authenticate(local);
2023 }
2024 local->card_status = CARD_ACQ_COMPLETE;
2025 } else {
2026 local->card_status = CARD_ACQ_FAILED;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002027
John Daiker141fa612009-03-10 06:59:54 -07002028 del_timer(&local->timer);
2029 local->timer.expires = jiffies + HZ * 5;
2030 local->timer.data = (long)local;
2031 if (status == CCS_START_NETWORK) {
Dominik Brodowski624dd662009-10-24 15:52:44 +02002032 dev_dbg(&link->dev,
John Daiker141fa612009-03-10 06:59:54 -07002033 "ray_cs interrupt network \"%s\" start failed\n",
2034 local->sparm.b4.a_current_ess_id);
2035 local->timer.function = &start_net;
2036 } else {
Dominik Brodowski624dd662009-10-24 15:52:44 +02002037 dev_dbg(&link->dev,
John Daiker141fa612009-03-10 06:59:54 -07002038 "ray_cs interrupt network \"%s\" join failed\n",
2039 local->sparm.b4.a_current_ess_id);
2040 local->timer.function = &join_net;
2041 }
2042 add_timer(&local->timer);
2043 }
2044 break;
2045 case CCS_START_ASSOCIATION:
2046 if (status == CCS_COMMAND_COMPLETE) {
2047 local->card_status = CARD_ASSOC_COMPLETE;
Dominik Brodowski624dd662009-10-24 15:52:44 +02002048 dev_dbg(&link->dev, "ray_cs association successful\n");
John Daiker141fa612009-03-10 06:59:54 -07002049 } else {
Dominik Brodowski624dd662009-10-24 15:52:44 +02002050 dev_dbg(&link->dev, "ray_cs association failed,\n");
John Daiker141fa612009-03-10 06:59:54 -07002051 local->card_status = CARD_ASSOC_FAILED;
2052 join_net((u_long) local);
2053 }
2054 break;
2055 case CCS_TX_REQUEST:
2056 if (status == CCS_COMMAND_COMPLETE) {
Dominik Brodowski624dd662009-10-24 15:52:44 +02002057 dev_dbg(&link->dev,
John Daiker141fa612009-03-10 06:59:54 -07002058 "ray_cs interrupt tx request complete\n");
2059 } else {
Dominik Brodowski624dd662009-10-24 15:52:44 +02002060 dev_dbg(&link->dev,
John Daiker141fa612009-03-10 06:59:54 -07002061 "ray_cs interrupt tx request failed\n");
2062 }
2063 if (!sniffer)
2064 netif_start_queue(dev);
2065 netif_wake_queue(dev);
2066 break;
2067 case CCS_TEST_MEMORY:
Dominik Brodowski624dd662009-10-24 15:52:44 +02002068 dev_dbg(&link->dev, "ray_cs interrupt mem test done\n");
John Daiker141fa612009-03-10 06:59:54 -07002069 break;
2070 case CCS_SHUTDOWN:
Dominik Brodowski624dd662009-10-24 15:52:44 +02002071 dev_dbg(&link->dev,
John Daiker141fa612009-03-10 06:59:54 -07002072 "ray_cs interrupt Unexpected CCS returned - Shutdown\n");
2073 break;
2074 case CCS_DUMP_MEMORY:
Dominik Brodowski624dd662009-10-24 15:52:44 +02002075 dev_dbg(&link->dev, "ray_cs interrupt dump memory done\n");
John Daiker141fa612009-03-10 06:59:54 -07002076 break;
2077 case CCS_START_TIMER:
Dominik Brodowski624dd662009-10-24 15:52:44 +02002078 dev_dbg(&link->dev,
John Daiker141fa612009-03-10 06:59:54 -07002079 "ray_cs interrupt DING - raylink timer expired\n");
2080 break;
2081 default:
Dominik Brodowski624dd662009-10-24 15:52:44 +02002082 dev_dbg(&link->dev,
John Daiker141fa612009-03-10 06:59:54 -07002083 "ray_cs interrupt Unexpected CCS 0x%x returned 0x%x\n",
2084 rcsindex, cmd);
2085 }
2086 writeb(CCS_BUFFER_FREE, &pccs->buffer_status);
2087 } else { /* It's an RCS */
2088
2089 prcs = rcs_base(local) + rcsindex;
2090
2091 switch (readb(&prcs->interrupt_id)) {
2092 case PROCESS_RX_PACKET:
2093 ray_rx(dev, local, prcs);
2094 break;
2095 case REJOIN_NET_COMPLETE:
Dominik Brodowski624dd662009-10-24 15:52:44 +02002096 dev_dbg(&link->dev, "ray_cs interrupt rejoin net complete\n");
John Daiker141fa612009-03-10 06:59:54 -07002097 local->card_status = CARD_ACQ_COMPLETE;
2098 /* do we need to clear tx buffers CCS's? */
2099 if (local->sparm.b4.a_network_type == ADHOC) {
2100 if (!sniffer)
2101 netif_start_queue(dev);
2102 } else {
2103 memcpy_fromio(&local->bss_id,
2104 prcs->var.rejoin_net_complete.
2105 bssid, ADDRLEN);
Dominik Brodowski624dd662009-10-24 15:52:44 +02002106 dev_dbg(&link->dev,
John Daiker141fa612009-03-10 06:59:54 -07002107 "ray_cs new BSSID = %02x%02x%02x%02x%02x%02x\n",
2108 local->bss_id[0], local->bss_id[1],
2109 local->bss_id[2], local->bss_id[3],
2110 local->bss_id[4], local->bss_id[5]);
2111 if (!sniffer)
2112 authenticate(local);
2113 }
2114 break;
2115 case ROAMING_INITIATED:
Dominik Brodowski624dd662009-10-24 15:52:44 +02002116 dev_dbg(&link->dev, "ray_cs interrupt roaming initiated\n");
John Daiker141fa612009-03-10 06:59:54 -07002117 netif_stop_queue(dev);
2118 local->card_status = CARD_DOING_ACQ;
2119 break;
2120 case JAPAN_CALL_SIGN_RXD:
Dominik Brodowski624dd662009-10-24 15:52:44 +02002121 dev_dbg(&link->dev, "ray_cs interrupt japan call sign rx\n");
John Daiker141fa612009-03-10 06:59:54 -07002122 break;
2123 default:
Dominik Brodowski624dd662009-10-24 15:52:44 +02002124 dev_dbg(&link->dev,
John Daiker141fa612009-03-10 06:59:54 -07002125 "ray_cs Unexpected interrupt for RCS 0x%x cmd = 0x%x\n",
2126 rcsindex,
2127 (unsigned int)readb(&prcs->interrupt_id));
2128 break;
2129 }
2130 writeb(CCS_BUFFER_FREE, &prcs->buffer_status);
2131 }
2132 clear_interrupt(local);
2133 return IRQ_HANDLED;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002134} /* ray_interrupt */
John Daiker141fa612009-03-10 06:59:54 -07002135
Linus Torvalds1da177e2005-04-16 15:20:36 -07002136/*===========================================================================*/
John Daiker141fa612009-03-10 06:59:54 -07002137static void ray_rx(struct net_device *dev, ray_dev_t *local,
2138 struct rcs __iomem *prcs)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002139{
John Daiker141fa612009-03-10 06:59:54 -07002140 int rx_len;
2141 unsigned int pkt_addr;
2142 void __iomem *pmsg;
Dominik Brodowski624dd662009-10-24 15:52:44 +02002143 pr_debug("ray_rx process rx packet\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002144
John Daiker141fa612009-03-10 06:59:54 -07002145 /* Calculate address of packet within Rx buffer */
2146 pkt_addr = ((readb(&prcs->var.rx_packet.rx_data_ptr[0]) << 8)
2147 + readb(&prcs->var.rx_packet.rx_data_ptr[1])) & RX_BUFF_END;
2148 /* Length of first packet fragment */
2149 rx_len = (readb(&prcs->var.rx_packet.rx_data_length[0]) << 8)
2150 + readb(&prcs->var.rx_packet.rx_data_length[1]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002151
John Daiker141fa612009-03-10 06:59:54 -07002152 local->last_rsl = readb(&prcs->var.rx_packet.rx_sig_lev);
2153 pmsg = local->rmem + pkt_addr;
2154 switch (readb(pmsg)) {
2155 case DATA_TYPE:
Dominik Brodowski624dd662009-10-24 15:52:44 +02002156 pr_debug("ray_rx data type\n");
John Daiker141fa612009-03-10 06:59:54 -07002157 rx_data(dev, prcs, pkt_addr, rx_len);
2158 break;
2159 case AUTHENTIC_TYPE:
Dominik Brodowski624dd662009-10-24 15:52:44 +02002160 pr_debug("ray_rx authentic type\n");
John Daiker141fa612009-03-10 06:59:54 -07002161 if (sniffer)
2162 rx_data(dev, prcs, pkt_addr, rx_len);
2163 else
2164 rx_authenticate(local, prcs, pkt_addr, rx_len);
2165 break;
2166 case DEAUTHENTIC_TYPE:
Dominik Brodowski624dd662009-10-24 15:52:44 +02002167 pr_debug("ray_rx deauth type\n");
John Daiker141fa612009-03-10 06:59:54 -07002168 if (sniffer)
2169 rx_data(dev, prcs, pkt_addr, rx_len);
2170 else
2171 rx_deauthenticate(local, prcs, pkt_addr, rx_len);
2172 break;
2173 case NULL_MSG_TYPE:
Dominik Brodowski624dd662009-10-24 15:52:44 +02002174 pr_debug("ray_cs rx NULL msg\n");
John Daiker141fa612009-03-10 06:59:54 -07002175 break;
2176 case BEACON_TYPE:
Dominik Brodowski624dd662009-10-24 15:52:44 +02002177 pr_debug("ray_rx beacon type\n");
John Daiker141fa612009-03-10 06:59:54 -07002178 if (sniffer)
2179 rx_data(dev, prcs, pkt_addr, rx_len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002180
John Daiker141fa612009-03-10 06:59:54 -07002181 copy_from_rx_buff(local, (UCHAR *) &local->last_bcn, pkt_addr,
2182 rx_len < sizeof(struct beacon_rx) ?
2183 rx_len : sizeof(struct beacon_rx));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002184
John Daiker141fa612009-03-10 06:59:54 -07002185 local->beacon_rxed = 1;
2186 /* Get the statistics so the card counters never overflow */
2187 ray_get_stats(dev);
2188 break;
2189 default:
Dominik Brodowski624dd662009-10-24 15:52:44 +02002190 pr_debug("ray_cs unknown pkt type %2x\n",
John Daiker141fa612009-03-10 06:59:54 -07002191 (unsigned int)readb(pmsg));
2192 break;
2193 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002194
2195} /* end ray_rx */
John Daiker141fa612009-03-10 06:59:54 -07002196
Linus Torvalds1da177e2005-04-16 15:20:36 -07002197/*===========================================================================*/
John Daiker141fa612009-03-10 06:59:54 -07002198static void rx_data(struct net_device *dev, struct rcs __iomem *prcs,
2199 unsigned int pkt_addr, int rx_len)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002200{
John Daiker141fa612009-03-10 06:59:54 -07002201 struct sk_buff *skb = NULL;
2202 struct rcs __iomem *prcslink = prcs;
2203 ray_dev_t *local = netdev_priv(dev);
2204 UCHAR *rx_ptr;
2205 int total_len;
2206 int tmp;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002207#ifdef WIRELESS_SPY
John Daiker141fa612009-03-10 06:59:54 -07002208 int siglev = local->last_rsl;
2209 u_char linksrcaddr[ETH_ALEN]; /* Other end of the wireless link */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002210#endif
2211
John Daiker141fa612009-03-10 06:59:54 -07002212 if (!sniffer) {
2213 if (translate) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002214/* TBD length needs fixing for translated header */
John Daiker141fa612009-03-10 06:59:54 -07002215 if (rx_len < (ETH_HLEN + RX_MAC_HEADER_LENGTH) ||
2216 rx_len >
2217 (dev->mtu + RX_MAC_HEADER_LENGTH + ETH_HLEN +
2218 FCS_LEN)) {
Dominik Brodowski624dd662009-10-24 15:52:44 +02002219 pr_debug(
Frans Popcb01b092010-03-24 19:46:34 +01002220 "ray_cs invalid packet length %d received\n",
John Daiker141fa612009-03-10 06:59:54 -07002221 rx_len);
2222 return;
2223 }
2224 } else { /* encapsulated ethernet */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002225
John Daiker141fa612009-03-10 06:59:54 -07002226 if (rx_len < (ETH_HLEN + RX_MAC_HEADER_LENGTH) ||
2227 rx_len >
2228 (dev->mtu + RX_MAC_HEADER_LENGTH + ETH_HLEN +
2229 FCS_LEN)) {
Dominik Brodowski624dd662009-10-24 15:52:44 +02002230 pr_debug(
Frans Popcb01b092010-03-24 19:46:34 +01002231 "ray_cs invalid packet length %d received\n",
John Daiker141fa612009-03-10 06:59:54 -07002232 rx_len);
2233 return;
2234 }
2235 }
2236 }
Dominik Brodowski624dd662009-10-24 15:52:44 +02002237 pr_debug("ray_cs rx_data packet\n");
John Daiker141fa612009-03-10 06:59:54 -07002238 /* If fragmented packet, verify sizes of fragments add up */
2239 if (readb(&prcs->var.rx_packet.next_frag_rcs_index) != 0xFF) {
Dominik Brodowski624dd662009-10-24 15:52:44 +02002240 pr_debug("ray_cs rx'ed fragment\n");
John Daiker141fa612009-03-10 06:59:54 -07002241 tmp = (readb(&prcs->var.rx_packet.totalpacketlength[0]) << 8)
2242 + readb(&prcs->var.rx_packet.totalpacketlength[1]);
2243 total_len = tmp;
2244 prcslink = prcs;
2245 do {
2246 tmp -=
2247 (readb(&prcslink->var.rx_packet.rx_data_length[0])
2248 << 8)
2249 + readb(&prcslink->var.rx_packet.rx_data_length[1]);
2250 if (readb(&prcslink->var.rx_packet.next_frag_rcs_index)
2251 == 0xFF || tmp < 0)
2252 break;
2253 prcslink = rcs_base(local)
2254 + readb(&prcslink->link_field);
2255 } while (1);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002256
John Daiker141fa612009-03-10 06:59:54 -07002257 if (tmp < 0) {
Dominik Brodowski624dd662009-10-24 15:52:44 +02002258 pr_debug(
John Daiker141fa612009-03-10 06:59:54 -07002259 "ray_cs rx_data fragment lengths don't add up\n");
2260 local->stats.rx_dropped++;
2261 release_frag_chain(local, prcs);
2262 return;
2263 }
2264 } else { /* Single unfragmented packet */
2265 total_len = rx_len;
2266 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002267
John Daiker141fa612009-03-10 06:59:54 -07002268 skb = dev_alloc_skb(total_len + 5);
2269 if (skb == NULL) {
Dominik Brodowski624dd662009-10-24 15:52:44 +02002270 pr_debug("ray_cs rx_data could not allocate skb\n");
John Daiker141fa612009-03-10 06:59:54 -07002271 local->stats.rx_dropped++;
2272 if (readb(&prcs->var.rx_packet.next_frag_rcs_index) != 0xFF)
2273 release_frag_chain(local, prcs);
2274 return;
2275 }
2276 skb_reserve(skb, 2); /* Align IP on 16 byte (TBD check this) */
2277
Dominik Brodowski624dd662009-10-24 15:52:44 +02002278 pr_debug("ray_cs rx_data total_len = %x, rx_len = %x\n", total_len,
John Daiker141fa612009-03-10 06:59:54 -07002279 rx_len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002280
2281/************************/
John Daiker141fa612009-03-10 06:59:54 -07002282 /* Reserve enough room for the whole damn packet. */
2283 rx_ptr = skb_put(skb, total_len);
2284 /* Copy the whole packet to sk_buff */
2285 rx_ptr +=
2286 copy_from_rx_buff(local, rx_ptr, pkt_addr & RX_BUFF_END, rx_len);
2287 /* Get source address */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002288#ifdef WIRELESS_SPY
John Daiker141fa612009-03-10 06:59:54 -07002289 skb_copy_from_linear_data_offset(skb,
2290 offsetof(struct mac_header, addr_2),
2291 linksrcaddr, ETH_ALEN);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002292#endif
John Daiker141fa612009-03-10 06:59:54 -07002293 /* Now, deal with encapsulation/translation/sniffer */
2294 if (!sniffer) {
2295 if (!translate) {
2296 /* Encapsulated ethernet, so just lop off 802.11 MAC header */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002297/* TBD reserve skb_reserve( skb, RX_MAC_HEADER_LENGTH); */
John Daiker141fa612009-03-10 06:59:54 -07002298 skb_pull(skb, RX_MAC_HEADER_LENGTH);
2299 } else {
2300 /* Do translation */
2301 untranslate(local, skb, total_len);
2302 }
2303 } else { /* sniffer mode, so just pass whole packet */
2304 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002305
2306/************************/
John Daiker141fa612009-03-10 06:59:54 -07002307 /* Now pick up the rest of the fragments if any */
2308 tmp = 17;
2309 if (readb(&prcs->var.rx_packet.next_frag_rcs_index) != 0xFF) {
2310 prcslink = prcs;
Dominik Brodowski624dd662009-10-24 15:52:44 +02002311 pr_debug("ray_cs rx_data in fragment loop\n");
John Daiker141fa612009-03-10 06:59:54 -07002312 do {
2313 prcslink = rcs_base(local)
2314 +
2315 readb(&prcslink->var.rx_packet.next_frag_rcs_index);
2316 rx_len =
2317 ((readb(&prcslink->var.rx_packet.rx_data_length[0])
2318 << 8)
2319 +
2320 readb(&prcslink->var.rx_packet.rx_data_length[1]))
2321 & RX_BUFF_END;
2322 pkt_addr =
2323 ((readb(&prcslink->var.rx_packet.rx_data_ptr[0]) <<
2324 8)
2325 + readb(&prcslink->var.rx_packet.rx_data_ptr[1]))
2326 & RX_BUFF_END;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002327
John Daiker141fa612009-03-10 06:59:54 -07002328 rx_ptr +=
2329 copy_from_rx_buff(local, rx_ptr, pkt_addr, rx_len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002330
John Daiker141fa612009-03-10 06:59:54 -07002331 } while (tmp-- &&
2332 readb(&prcslink->var.rx_packet.next_frag_rcs_index) !=
2333 0xFF);
2334 release_frag_chain(local, prcs);
2335 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002336
John Daiker141fa612009-03-10 06:59:54 -07002337 skb->protocol = eth_type_trans(skb, dev);
2338 netif_rx(skb);
2339 local->stats.rx_packets++;
2340 local->stats.rx_bytes += total_len;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002341
John Daiker141fa612009-03-10 06:59:54 -07002342 /* Gather signal strength per address */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002343#ifdef WIRELESS_SPY
John Daiker141fa612009-03-10 06:59:54 -07002344 /* For the Access Point or the node having started the ad-hoc net
2345 * note : ad-hoc work only in some specific configurations, but we
2346 * kludge in ray_get_wireless_stats... */
2347 if (!memcmp(linksrcaddr, local->bss_id, ETH_ALEN)) {
2348 /* Update statistics */
2349 /*local->wstats.qual.qual = none ? */
2350 local->wstats.qual.level = siglev;
2351 /*local->wstats.qual.noise = none ? */
2352 local->wstats.qual.updated = 0x2;
2353 }
2354 /* Now, update the spy stuff */
2355 {
2356 struct iw_quality wstats;
2357 wstats.level = siglev;
2358 /* wstats.noise = none ? */
2359 /* wstats.qual = none ? */
2360 wstats.updated = 0x2;
2361 /* Update spy records */
2362 wireless_spy_update(dev, linksrcaddr, &wstats);
2363 }
2364#endif /* WIRELESS_SPY */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002365} /* end rx_data */
John Daiker141fa612009-03-10 06:59:54 -07002366
Linus Torvalds1da177e2005-04-16 15:20:36 -07002367/*===========================================================================*/
2368static void untranslate(ray_dev_t *local, struct sk_buff *skb, int len)
2369{
John Daiker141fa612009-03-10 06:59:54 -07002370 snaphdr_t *psnap = (snaphdr_t *) (skb->data + RX_MAC_HEADER_LENGTH);
2371 struct ieee80211_hdr *pmac = (struct ieee80211_hdr *)skb->data;
2372 __be16 type = *(__be16 *) psnap->ethertype;
2373 int delta;
2374 struct ethhdr *peth;
2375 UCHAR srcaddr[ADDRLEN];
2376 UCHAR destaddr[ADDRLEN];
2377 static UCHAR org_bridge[3] = { 0, 0, 0xf8 };
2378 static UCHAR org_1042[3] = { 0, 0, 0 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002379
John Daiker141fa612009-03-10 06:59:54 -07002380 memcpy(destaddr, ieee80211_get_DA(pmac), ADDRLEN);
2381 memcpy(srcaddr, ieee80211_get_SA(pmac), ADDRLEN);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002382
Dominik Brodowski624dd662009-10-24 15:52:44 +02002383#if 0
2384 if {
Joe Perchesad361c92009-07-06 13:05:40 -07002385 print_hex_dump(KERN_DEBUG, "skb->data before untranslate: ",
2386 DUMP_PREFIX_NONE, 16, 1,
2387 skb->data, 64, true);
2388 printk(KERN_DEBUG
John Daiker141fa612009-03-10 06:59:54 -07002389 "type = %08x, xsap = %02x%02x%02x, org = %02x02x02x\n",
2390 ntohs(type), psnap->dsap, psnap->ssap, psnap->ctrl,
2391 psnap->org[0], psnap->org[1], psnap->org[2]);
2392 printk(KERN_DEBUG "untranslate skb->data = %p\n", skb->data);
2393 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002394#endif
2395
John Daiker141fa612009-03-10 06:59:54 -07002396 if (psnap->dsap != 0xaa || psnap->ssap != 0xaa || psnap->ctrl != 3) {
2397 /* not a snap type so leave it alone */
Dominik Brodowski624dd662009-10-24 15:52:44 +02002398 pr_debug("ray_cs untranslate NOT SNAP %02x %02x %02x\n",
John Daiker141fa612009-03-10 06:59:54 -07002399 psnap->dsap, psnap->ssap, psnap->ctrl);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002400
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 = htons(len - RX_MAC_HEADER_LENGTH);
2404 } else { /* Its a SNAP */
2405 if (memcmp(psnap->org, org_bridge, 3) == 0) {
2406 /* EtherII and nuke the LLC */
Dominik Brodowski624dd662009-10-24 15:52:44 +02002407 pr_debug("ray_cs untranslate Bridge encap\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 } else if (memcmp(psnap->org, org_1042, 3) == 0) {
2413 switch (ntohs(type)) {
2414 case ETH_P_IPX:
2415 case ETH_P_AARP:
Dominik Brodowski624dd662009-10-24 15:52:44 +02002416 pr_debug("ray_cs untranslate RFC IPX/AARP\n");
John Daiker141fa612009-03-10 06:59:54 -07002417 delta = RX_MAC_HEADER_LENGTH - ETH_HLEN;
2418 peth = (struct ethhdr *)(skb->data + delta);
2419 peth->h_proto =
2420 htons(len - RX_MAC_HEADER_LENGTH);
2421 break;
2422 default:
Dominik Brodowski624dd662009-10-24 15:52:44 +02002423 pr_debug("ray_cs untranslate RFC default\n");
John Daiker141fa612009-03-10 06:59:54 -07002424 delta = RX_MAC_HEADER_LENGTH +
2425 sizeof(struct snaphdr_t) - ETH_HLEN;
2426 peth = (struct ethhdr *)(skb->data + delta);
2427 peth->h_proto = type;
2428 break;
2429 }
2430 } else {
2431 printk("ray_cs untranslate very confused by packet\n");
2432 delta = RX_MAC_HEADER_LENGTH - ETH_HLEN;
2433 peth = (struct ethhdr *)(skb->data + delta);
2434 peth->h_proto = type;
2435 }
Al Viro7698d692007-12-29 04:55:50 -05002436 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002437/* TBD reserve skb_reserve(skb, delta); */
John Daiker141fa612009-03-10 06:59:54 -07002438 skb_pull(skb, delta);
Dominik Brodowski624dd662009-10-24 15:52:44 +02002439 pr_debug("untranslate after skb_pull(%d), skb->data = %p\n", delta,
John Daiker141fa612009-03-10 06:59:54 -07002440 skb->data);
2441 memcpy(peth->h_dest, destaddr, ADDRLEN);
2442 memcpy(peth->h_source, srcaddr, ADDRLEN);
Dominik Brodowski624dd662009-10-24 15:52:44 +02002443#if 0
2444 {
John Daiker141fa612009-03-10 06:59:54 -07002445 int i;
2446 printk(KERN_DEBUG "skb->data after untranslate:");
2447 for (i = 0; i < 64; i++)
2448 printk("%02x ", skb->data[i]);
2449 printk("\n");
2450 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002451#endif
2452} /* end untranslate */
John Daiker141fa612009-03-10 06:59:54 -07002453
Linus Torvalds1da177e2005-04-16 15:20:36 -07002454/*===========================================================================*/
2455/* Copy data from circular receive buffer to PC memory.
2456 * dest = destination address in PC memory
2457 * pkt_addr = source address in receive buffer
2458 * len = length of packet to copy
2459 */
John Daiker141fa612009-03-10 06:59:54 -07002460static int copy_from_rx_buff(ray_dev_t *local, UCHAR *dest, int pkt_addr,
2461 int length)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002462{
John Daiker141fa612009-03-10 06:59:54 -07002463 int wrap_bytes = (pkt_addr + length) - (RX_BUFF_END + 1);
2464 if (wrap_bytes <= 0) {
2465 memcpy_fromio(dest, local->rmem + pkt_addr, length);
2466 } else { /* Packet wrapped in circular buffer */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002467
John Daiker141fa612009-03-10 06:59:54 -07002468 memcpy_fromio(dest, local->rmem + pkt_addr,
2469 length - wrap_bytes);
2470 memcpy_fromio(dest + length - wrap_bytes, local->rmem,
2471 wrap_bytes);
2472 }
2473 return length;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002474}
John Daiker141fa612009-03-10 06:59:54 -07002475
2476/*===========================================================================*/
2477static void release_frag_chain(ray_dev_t *local, struct rcs __iomem *prcs)
2478{
2479 struct rcs __iomem *prcslink = prcs;
2480 int tmp = 17;
2481 unsigned rcsindex = readb(&prcs->var.rx_packet.next_frag_rcs_index);
2482
2483 while (tmp--) {
2484 writeb(CCS_BUFFER_FREE, &prcslink->buffer_status);
2485 if (rcsindex >= (NUMBER_OF_CCS + NUMBER_OF_RCS)) {
Dominik Brodowski624dd662009-10-24 15:52:44 +02002486 pr_debug("ray_cs interrupt bad rcsindex = 0x%x\n",
John Daiker141fa612009-03-10 06:59:54 -07002487 rcsindex);
2488 break;
2489 }
2490 prcslink = rcs_base(local) + rcsindex;
2491 rcsindex = readb(&prcslink->var.rx_packet.next_frag_rcs_index);
2492 }
2493 writeb(CCS_BUFFER_FREE, &prcslink->buffer_status);
2494}
2495
Linus Torvalds1da177e2005-04-16 15:20:36 -07002496/*===========================================================================*/
2497static void authenticate(ray_dev_t *local)
2498{
John Daiker141fa612009-03-10 06:59:54 -07002499 struct pcmcia_device *link = local->finder;
Dominik Brodowski624dd662009-10-24 15:52:44 +02002500 dev_dbg(&link->dev, "ray_cs Starting authentication.\n");
John Daiker141fa612009-03-10 06:59:54 -07002501 if (!(pcmcia_dev_present(link))) {
Dominik Brodowski624dd662009-10-24 15:52:44 +02002502 dev_dbg(&link->dev, "ray_cs authenticate - device not present\n");
John Daiker141fa612009-03-10 06:59:54 -07002503 return;
2504 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002505
John Daiker141fa612009-03-10 06:59:54 -07002506 del_timer(&local->timer);
2507 if (build_auth_frame(local, local->bss_id, OPEN_AUTH_REQUEST)) {
2508 local->timer.function = &join_net;
2509 } else {
2510 local->timer.function = &authenticate_timeout;
2511 }
2512 local->timer.expires = jiffies + HZ * 2;
2513 local->timer.data = (long)local;
2514 add_timer(&local->timer);
2515 local->authentication_state = AWAITING_RESPONSE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002516} /* end authenticate */
John Daiker141fa612009-03-10 06:59:54 -07002517
Linus Torvalds1da177e2005-04-16 15:20:36 -07002518/*===========================================================================*/
2519static void rx_authenticate(ray_dev_t *local, struct rcs __iomem *prcs,
John Daiker141fa612009-03-10 06:59:54 -07002520 unsigned int pkt_addr, int rx_len)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002521{
John Daiker141fa612009-03-10 06:59:54 -07002522 UCHAR buff[256];
2523 struct rx_msg *msg = (struct rx_msg *)buff;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002524
John Daiker141fa612009-03-10 06:59:54 -07002525 del_timer(&local->timer);
2526
2527 copy_from_rx_buff(local, buff, pkt_addr, rx_len & 0xff);
2528 /* if we are trying to get authenticated */
2529 if (local->sparm.b4.a_network_type == ADHOC) {
Dominik Brodowski624dd662009-10-24 15:52:44 +02002530 pr_debug("ray_cs rx_auth var= %02x %02x %02x %02x %02x %02x\n",
John Daiker141fa612009-03-10 06:59:54 -07002531 msg->var[0], msg->var[1], msg->var[2], msg->var[3],
2532 msg->var[4], msg->var[5]);
2533 if (msg->var[2] == 1) {
Dominik Brodowski624dd662009-10-24 15:52:44 +02002534 pr_debug("ray_cs Sending authentication response.\n");
John Daiker141fa612009-03-10 06:59:54 -07002535 if (!build_auth_frame
2536 (local, msg->mac.addr_2, OPEN_AUTH_RESPONSE)) {
2537 local->authentication_state = NEED_TO_AUTH;
2538 memcpy(local->auth_id, msg->mac.addr_2,
2539 ADDRLEN);
2540 }
2541 }
2542 } else { /* Infrastructure network */
2543
2544 if (local->authentication_state == AWAITING_RESPONSE) {
2545 /* Verify authentication sequence #2 and success */
2546 if (msg->var[2] == 2) {
2547 if ((msg->var[3] | msg->var[4]) == 0) {
Dominik Brodowski624dd662009-10-24 15:52:44 +02002548 pr_debug("Authentication successful\n");
John Daiker141fa612009-03-10 06:59:54 -07002549 local->card_status = CARD_AUTH_COMPLETE;
2550 associate(local);
2551 local->authentication_state =
2552 AUTHENTICATED;
2553 } else {
Dominik Brodowski624dd662009-10-24 15:52:44 +02002554 pr_debug("Authentication refused\n");
John Daiker141fa612009-03-10 06:59:54 -07002555 local->card_status = CARD_AUTH_REFUSED;
2556 join_net((u_long) local);
2557 local->authentication_state =
2558 UNAUTHENTICATED;
2559 }
2560 }
2561 }
2562 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002563
2564} /* end rx_authenticate */
John Daiker141fa612009-03-10 06:59:54 -07002565
Linus Torvalds1da177e2005-04-16 15:20:36 -07002566/*===========================================================================*/
2567static void associate(ray_dev_t *local)
2568{
John Daiker141fa612009-03-10 06:59:54 -07002569 struct ccs __iomem *pccs;
2570 struct pcmcia_device *link = local->finder;
2571 struct net_device *dev = link->priv;
2572 int ccsindex;
2573 if (!(pcmcia_dev_present(link))) {
Dominik Brodowski624dd662009-10-24 15:52:44 +02002574 dev_dbg(&link->dev, "ray_cs associate - device not present\n");
John Daiker141fa612009-03-10 06:59:54 -07002575 return;
2576 }
2577 /* If no tx buffers available, return */
2578 if ((ccsindex = get_free_ccs(local)) < 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002579/* TBD should never be here but... what if we are? */
Dominik Brodowski624dd662009-10-24 15:52:44 +02002580 dev_dbg(&link->dev, "ray_cs associate - No free ccs\n");
John Daiker141fa612009-03-10 06:59:54 -07002581 return;
2582 }
Dominik Brodowski624dd662009-10-24 15:52:44 +02002583 dev_dbg(&link->dev, "ray_cs Starting association with access point\n");
John Daiker141fa612009-03-10 06:59:54 -07002584 pccs = ccs_base(local) + ccsindex;
2585 /* fill in the CCS */
2586 writeb(CCS_START_ASSOCIATION, &pccs->cmd);
2587 /* Interrupt the firmware to process the command */
2588 if (interrupt_ecf(local, ccsindex)) {
Dominik Brodowski624dd662009-10-24 15:52:44 +02002589 dev_dbg(&link->dev, "ray_cs associate failed - ECF not ready for intr\n");
John Daiker141fa612009-03-10 06:59:54 -07002590 writeb(CCS_BUFFER_FREE, &(pccs++)->buffer_status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002591
John Daiker141fa612009-03-10 06:59:54 -07002592 del_timer(&local->timer);
2593 local->timer.expires = jiffies + HZ * 2;
2594 local->timer.data = (long)local;
2595 local->timer.function = &join_net;
2596 add_timer(&local->timer);
2597 local->card_status = CARD_ASSOC_FAILED;
2598 return;
2599 }
2600 if (!sniffer)
2601 netif_start_queue(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002602
2603} /* end associate */
John Daiker141fa612009-03-10 06:59:54 -07002604
Linus Torvalds1da177e2005-04-16 15:20:36 -07002605/*===========================================================================*/
John Daiker141fa612009-03-10 06:59:54 -07002606static void rx_deauthenticate(ray_dev_t *local, struct rcs __iomem *prcs,
2607 unsigned int pkt_addr, int rx_len)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002608{
2609/* UCHAR buff[256];
2610 struct rx_msg *msg = (struct rx_msg *)buff;
2611*/
Dominik Brodowski624dd662009-10-24 15:52:44 +02002612 pr_debug("Deauthentication frame received\n");
John Daiker141fa612009-03-10 06:59:54 -07002613 local->authentication_state = UNAUTHENTICATED;
2614 /* Need to reauthenticate or rejoin depending on reason code */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002615/* copy_from_rx_buff(local, buff, pkt_addr, rx_len & 0xff);
2616 */
2617}
John Daiker141fa612009-03-10 06:59:54 -07002618
Linus Torvalds1da177e2005-04-16 15:20:36 -07002619/*===========================================================================*/
2620static void clear_interrupt(ray_dev_t *local)
2621{
John Daiker141fa612009-03-10 06:59:54 -07002622 writeb(0, local->amem + CIS_OFFSET + HCS_INTR_OFFSET);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002623}
John Daiker141fa612009-03-10 06:59:54 -07002624
Linus Torvalds1da177e2005-04-16 15:20:36 -07002625/*===========================================================================*/
2626#ifdef CONFIG_PROC_FS
2627#define MAXDATA (PAGE_SIZE - 80)
2628
2629static char *card_status[] = {
John Daiker141fa612009-03-10 06:59:54 -07002630 "Card inserted - uninitialized", /* 0 */
2631 "Card not downloaded", /* 1 */
2632 "Waiting for download parameters", /* 2 */
2633 "Card doing acquisition", /* 3 */
2634 "Acquisition complete", /* 4 */
2635 "Authentication complete", /* 5 */
2636 "Association complete", /* 6 */
2637 "???", "???", "???", "???", /* 7 8 9 10 undefined */
2638 "Card init error", /* 11 */
2639 "Download parameters error", /* 12 */
2640 "???", /* 13 */
2641 "Acquisition failed", /* 14 */
2642 "Authentication refused", /* 15 */
2643 "Association failed" /* 16 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002644};
2645
John Daiker141fa612009-03-10 06:59:54 -07002646static char *nettype[] = { "Adhoc", "Infra " };
2647static char *framing[] = { "Encapsulation", "Translation" }
2648
Linus Torvalds1da177e2005-04-16 15:20:36 -07002649;
2650/*===========================================================================*/
Alexey Dobriyan6b914c52008-04-10 14:34:35 -07002651static int ray_cs_proc_show(struct seq_file *m, void *v)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002652{
2653/* Print current values which are not available via other means
John Daiker141fa612009-03-10 06:59:54 -07002654 * eg ifconfig
Linus Torvalds1da177e2005-04-16 15:20:36 -07002655 */
John Daiker141fa612009-03-10 06:59:54 -07002656 int i;
2657 struct pcmcia_device *link;
2658 struct net_device *dev;
2659 ray_dev_t *local;
2660 UCHAR *p;
2661 struct freq_hop_element *pfh;
2662 UCHAR c[33];
Linus Torvalds1da177e2005-04-16 15:20:36 -07002663
John Daiker141fa612009-03-10 06:59:54 -07002664 link = this_device;
2665 if (!link)
2666 return 0;
2667 dev = (struct net_device *)link->priv;
2668 if (!dev)
2669 return 0;
2670 local = netdev_priv(dev);
2671 if (!local)
2672 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002673
John Daiker141fa612009-03-10 06:59:54 -07002674 seq_puts(m, "Raylink Wireless LAN driver status\n");
2675 seq_printf(m, "%s\n", rcsid);
2676 /* build 4 does not report version, and field is 0x55 after memtest */
2677 seq_puts(m, "Firmware version = ");
2678 if (local->fw_ver == 0x55)
2679 seq_puts(m, "4 - Use dump_cis for more details\n");
2680 else
2681 seq_printf(m, "%2d.%02d.%02d\n",
2682 local->fw_ver, local->fw_bld, local->fw_var);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002683
John Daiker141fa612009-03-10 06:59:54 -07002684 for (i = 0; i < 32; i++)
2685 c[i] = local->sparm.b5.a_current_ess_id[i];
2686 c[32] = 0;
2687 seq_printf(m, "%s network ESSID = \"%s\"\n",
2688 nettype[local->sparm.b5.a_network_type], c);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002689
John Daiker141fa612009-03-10 06:59:54 -07002690 p = local->bss_id;
2691 seq_printf(m, "BSSID = %pM\n", p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002692
John Daiker141fa612009-03-10 06:59:54 -07002693 seq_printf(m, "Country code = %d\n",
2694 local->sparm.b5.a_curr_country_code);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002695
John Daiker141fa612009-03-10 06:59:54 -07002696 i = local->card_status;
2697 if (i < 0)
2698 i = 10;
2699 if (i > 16)
2700 i = 10;
2701 seq_printf(m, "Card status = %s\n", card_status[i]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002702
John Daiker141fa612009-03-10 06:59:54 -07002703 seq_printf(m, "Framing mode = %s\n", framing[translate]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002704
John Daiker141fa612009-03-10 06:59:54 -07002705 seq_printf(m, "Last pkt signal lvl = %d\n", local->last_rsl);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002706
John Daiker141fa612009-03-10 06:59:54 -07002707 if (local->beacon_rxed) {
2708 /* Pull some fields out of last beacon received */
2709 seq_printf(m, "Beacon Interval = %d Kus\n",
2710 local->last_bcn.beacon_intvl[0]
2711 + 256 * local->last_bcn.beacon_intvl[1]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002712
John Daiker141fa612009-03-10 06:59:54 -07002713 p = local->last_bcn.elements;
2714 if (p[0] == C_ESSID_ELEMENT_ID)
2715 p += p[1] + 2;
2716 else {
2717 seq_printf(m,
2718 "Parse beacon failed at essid element id = %d\n",
2719 p[0]);
2720 return 0;
2721 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002722
John Daiker141fa612009-03-10 06:59:54 -07002723 if (p[0] == C_SUPPORTED_RATES_ELEMENT_ID) {
2724 seq_puts(m, "Supported rate codes = ");
2725 for (i = 2; i < p[1] + 2; i++)
2726 seq_printf(m, "0x%02x ", p[i]);
2727 seq_putc(m, '\n');
2728 p += p[1] + 2;
2729 } else {
2730 seq_puts(m, "Parse beacon failed at rates element\n");
2731 return 0;
2732 }
2733
2734 if (p[0] == C_FH_PARAM_SET_ELEMENT_ID) {
2735 pfh = (struct freq_hop_element *)p;
2736 seq_printf(m, "Hop dwell = %d Kus\n",
2737 pfh->dwell_time[0] +
2738 256 * pfh->dwell_time[1]);
Frans Popcb01b092010-03-24 19:46:34 +01002739 seq_printf(m, "Hop set = %d\n",
John Daiker141fa612009-03-10 06:59:54 -07002740 pfh->hop_set);
Frans Popcb01b092010-03-24 19:46:34 +01002741 seq_printf(m, "Hop pattern = %d\n",
John Daiker141fa612009-03-10 06:59:54 -07002742 pfh->hop_pattern);
Frans Popcb01b092010-03-24 19:46:34 +01002743 seq_printf(m, "Hop index = %d\n",
John Daiker141fa612009-03-10 06:59:54 -07002744 pfh->hop_index);
2745 p += p[1] + 2;
2746 } else {
2747 seq_puts(m,
2748 "Parse beacon failed at FH param element\n");
2749 return 0;
2750 }
2751 } else {
2752 seq_puts(m, "No beacons received\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002753 }
John Daiker141fa612009-03-10 06:59:54 -07002754 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002755}
2756
Alexey Dobriyan6b914c52008-04-10 14:34:35 -07002757static int ray_cs_proc_open(struct inode *inode, struct file *file)
2758{
2759 return single_open(file, ray_cs_proc_show, NULL);
2760}
2761
2762static const struct file_operations ray_cs_proc_fops = {
John Daiker141fa612009-03-10 06:59:54 -07002763 .owner = THIS_MODULE,
2764 .open = ray_cs_proc_open,
2765 .read = seq_read,
2766 .llseek = seq_lseek,
2767 .release = single_release,
Alexey Dobriyan6b914c52008-04-10 14:34:35 -07002768};
Linus Torvalds1da177e2005-04-16 15:20:36 -07002769#endif
2770/*===========================================================================*/
2771static int build_auth_frame(ray_dev_t *local, UCHAR *dest, int auth_type)
2772{
John Daiker141fa612009-03-10 06:59:54 -07002773 int addr;
2774 struct ccs __iomem *pccs;
2775 struct tx_msg __iomem *ptx;
2776 int ccsindex;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002777
John Daiker141fa612009-03-10 06:59:54 -07002778 /* If no tx buffers available, return */
2779 if ((ccsindex = get_free_tx_ccs(local)) < 0) {
Dominik Brodowski624dd662009-10-24 15:52:44 +02002780 pr_debug("ray_cs send authenticate - No free tx ccs\n");
John Daiker141fa612009-03-10 06:59:54 -07002781 return -1;
2782 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002783
John Daiker141fa612009-03-10 06:59:54 -07002784 pccs = ccs_base(local) + ccsindex;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002785
John Daiker141fa612009-03-10 06:59:54 -07002786 /* Address in card space */
2787 addr = TX_BUF_BASE + (ccsindex << 11);
2788 /* fill in the CCS */
2789 writeb(CCS_TX_REQUEST, &pccs->cmd);
2790 writeb(addr >> 8, pccs->var.tx_request.tx_data_ptr);
2791 writeb(0x20, pccs->var.tx_request.tx_data_ptr + 1);
2792 writeb(TX_AUTHENTICATE_LENGTH_MSB, pccs->var.tx_request.tx_data_length);
2793 writeb(TX_AUTHENTICATE_LENGTH_LSB,
2794 pccs->var.tx_request.tx_data_length + 1);
2795 writeb(0, &pccs->var.tx_request.pow_sav_mode);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002796
John Daiker141fa612009-03-10 06:59:54 -07002797 ptx = local->sram + addr;
2798 /* fill in the mac header */
2799 writeb(PROTOCOL_VER | AUTHENTIC_TYPE, &ptx->mac.frame_ctl_1);
2800 writeb(0, &ptx->mac.frame_ctl_2);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002801
John Daiker141fa612009-03-10 06:59:54 -07002802 memcpy_toio(ptx->mac.addr_1, dest, ADDRLEN);
2803 memcpy_toio(ptx->mac.addr_2, local->sparm.b4.a_mac_addr, ADDRLEN);
2804 memcpy_toio(ptx->mac.addr_3, local->bss_id, ADDRLEN);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002805
John Daiker141fa612009-03-10 06:59:54 -07002806 /* Fill in msg body with protocol 00 00, sequence 01 00 ,status 00 00 */
2807 memset_io(ptx->var, 0, 6);
2808 writeb(auth_type & 0xff, ptx->var + 2);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002809
John Daiker141fa612009-03-10 06:59:54 -07002810 /* Interrupt the firmware to process the command */
2811 if (interrupt_ecf(local, ccsindex)) {
Dominik Brodowski624dd662009-10-24 15:52:44 +02002812 pr_debug(
John Daiker141fa612009-03-10 06:59:54 -07002813 "ray_cs send authentication request failed - ECF not ready for intr\n");
2814 writeb(CCS_BUFFER_FREE, &(pccs++)->buffer_status);
2815 return -1;
2816 }
2817 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002818} /* End build_auth_frame */
2819
2820/*===========================================================================*/
2821#ifdef CONFIG_PROC_FS
Alexey Dobriyan83daee02009-11-25 10:12:20 +03002822static ssize_t ray_cs_essid_proc_write(struct file *file,
2823 const char __user *buffer, size_t count, loff_t *pos)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002824{
2825 static char proc_essid[33];
Alan Cox575c9ed2009-10-27 15:35:55 +00002826 unsigned int len = count;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002827
2828 if (len > 32)
2829 len = 32;
2830 memset(proc_essid, 0, 33);
2831 if (copy_from_user(proc_essid, buffer, len))
2832 return -EFAULT;
2833 essid = proc_essid;
2834 return count;
2835}
2836
Alexey Dobriyan83daee02009-11-25 10:12:20 +03002837static const struct file_operations ray_cs_essid_proc_fops = {
2838 .owner = THIS_MODULE,
2839 .write = ray_cs_essid_proc_write,
2840};
2841
2842static ssize_t int_proc_write(struct file *file, const char __user *buffer,
2843 size_t count, loff_t *pos)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002844{
2845 static char proc_number[10];
2846 char *p;
2847 int nr, len;
2848
2849 if (!count)
2850 return 0;
2851
2852 if (count > 9)
2853 return -EINVAL;
2854 if (copy_from_user(proc_number, buffer, count))
2855 return -EFAULT;
2856 p = proc_number;
2857 nr = 0;
2858 len = count;
2859 do {
2860 unsigned int c = *p - '0';
2861 if (c > 9)
2862 return -EINVAL;
John Daiker141fa612009-03-10 06:59:54 -07002863 nr = nr * 10 + c;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002864 p++;
2865 } while (--len);
Alexey Dobriyan83daee02009-11-25 10:12:20 +03002866 *(int *)PDE(file->f_path.dentry->d_inode)->data = nr;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002867 return count;
2868}
Alexey Dobriyan83daee02009-11-25 10:12:20 +03002869
2870static const struct file_operations int_proc_fops = {
2871 .owner = THIS_MODULE,
2872 .write = int_proc_write,
2873};
Linus Torvalds1da177e2005-04-16 15:20:36 -07002874#endif
2875
Dominik Brodowskif57ea2a2005-06-27 16:28:24 -07002876static struct pcmcia_device_id ray_ids[] = {
2877 PCMCIA_DEVICE_MANF_CARD(0x01a6, 0x0000),
2878 PCMCIA_DEVICE_NULL,
2879};
John Daiker141fa612009-03-10 06:59:54 -07002880
Dominik Brodowskif57ea2a2005-06-27 16:28:24 -07002881MODULE_DEVICE_TABLE(pcmcia, ray_ids);
2882
Linus Torvalds1da177e2005-04-16 15:20:36 -07002883static struct pcmcia_driver ray_driver = {
John Daiker141fa612009-03-10 06:59:54 -07002884 .owner = THIS_MODULE,
2885 .drv = {
2886 .name = "ray_cs",
2887 },
2888 .probe = ray_probe,
2889 .remove = ray_detach,
2890 .id_table = ray_ids,
2891 .suspend = ray_suspend,
2892 .resume = ray_resume,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002893};
2894
2895static int __init init_ray_cs(void)
2896{
John Daiker141fa612009-03-10 06:59:54 -07002897 int rc;
2898
Dominik Brodowski624dd662009-10-24 15:52:44 +02002899 pr_debug("%s\n", rcsid);
John Daiker141fa612009-03-10 06:59:54 -07002900 rc = pcmcia_register_driver(&ray_driver);
Dominik Brodowski624dd662009-10-24 15:52:44 +02002901 pr_debug("raylink init_module register_pcmcia_driver returns 0x%x\n",
John Daiker141fa612009-03-10 06:59:54 -07002902 rc);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002903
2904#ifdef CONFIG_PROC_FS
John Daiker141fa612009-03-10 06:59:54 -07002905 proc_mkdir("driver/ray_cs", NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002906
John Daiker141fa612009-03-10 06:59:54 -07002907 proc_create("driver/ray_cs/ray_cs", 0, NULL, &ray_cs_proc_fops);
Alexey Dobriyan83daee02009-11-25 10:12:20 +03002908 proc_create("driver/ray_cs/essid", S_IWUSR, NULL, &ray_cs_essid_proc_fops);
2909 proc_create_data("driver/ray_cs/net_type", S_IWUSR, NULL, &int_proc_fops, &net_type);
2910 proc_create_data("driver/ray_cs/translate", S_IWUSR, NULL, &int_proc_fops, &translate);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002911#endif
John Daiker141fa612009-03-10 06:59:54 -07002912 if (translate != 0)
2913 translate = 1;
2914 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002915} /* init_ray_cs */
2916
2917/*===========================================================================*/
2918
2919static void __exit exit_ray_cs(void)
2920{
Dominik Brodowski624dd662009-10-24 15:52:44 +02002921 pr_debug("ray_cs: cleanup_module\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002922
2923#ifdef CONFIG_PROC_FS
John Daiker141fa612009-03-10 06:59:54 -07002924 remove_proc_entry("driver/ray_cs/ray_cs", NULL);
2925 remove_proc_entry("driver/ray_cs/essid", NULL);
2926 remove_proc_entry("driver/ray_cs/net_type", NULL);
2927 remove_proc_entry("driver/ray_cs/translate", NULL);
2928 remove_proc_entry("driver/ray_cs", NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002929#endif
2930
John Daiker141fa612009-03-10 06:59:54 -07002931 pcmcia_unregister_driver(&ray_driver);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002932} /* exit_ray_cs */
2933
2934module_init(init_ray_cs);
2935module_exit(exit_ray_cs);
2936
2937/*===========================================================================*/