blob: b83d5ef1dffeb39cef0dd66c0e2ed169deacf7dd [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*=============================================================================
2 *
3 * A PCMCIA client driver for the Raylink wireless LAN card.
4 * The starting point for this module was the skeleton.c in the
5 * PCMCIA 2.9.12 package written by David Hinds, dahinds@users.sourceforge.net
6 *
7 *
8 * Copyright (c) 1998 Corey Thomas (corey@world.std.com)
9 *
10 * This driver is free software; you can redistribute it and/or modify
John Daiker141fa612009-03-10 06:59:54 -070011 * it under the terms of version 2 only of the GNU General Public License as
Linus Torvalds1da177e2005-04-16 15:20:36 -070012 * published by the Free Software Foundation.
13 *
14 * It is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
22 *
23 * Changes:
24 * Arnaldo Carvalho de Melo <acme@conectiva.com.br> - 08/08/2000
25 * - reorganize kmallocs in ray_attach, checking all for failure
26 * and releasing the previous allocations if one fails
27 *
28 * Daniele Bellucci <bellucda@tiscali.it> - 07/10/2003
29 * - Audit copy_to_user in ioctl(SIOCGIWESSID)
John Daiker141fa612009-03-10 06:59:54 -070030 *
Linus Torvalds1da177e2005-04-16 15:20:36 -070031=============================================================================*/
32
Linus Torvalds1da177e2005-04-16 15:20:36 -070033#include <linux/module.h>
34#include <linux/kernel.h>
35#include <linux/proc_fs.h>
36#include <linux/ptrace.h>
Alexey Dobriyan6b914c52008-04-10 14:34:35 -070037#include <linux/seq_file.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070038#include <linux/string.h>
39#include <linux/timer.h>
40#include <linux/init.h>
41#include <linux/netdevice.h>
42#include <linux/etherdevice.h>
43#include <linux/if_arp.h>
44#include <linux/ioport.h>
45#include <linux/skbuff.h>
46#include <linux/ethtool.h>
Al Viro7698d692007-12-29 04:55:50 -050047#include <linux/ieee80211.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070048
Linus Torvalds1da177e2005-04-16 15:20:36 -070049#include <pcmcia/cs.h>
50#include <pcmcia/cistpl.h>
51#include <pcmcia/cisreg.h>
52#include <pcmcia/ds.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070053
54#include <linux/wireless.h>
Michael Wu113b8982006-08-13 23:27:17 -070055#include <net/iw_handler.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070056
57#include <asm/io.h>
58#include <asm/system.h>
59#include <asm/byteorder.h>
60#include <asm/uaccess.h>
61
62/* Warning : these stuff will slow down the driver... */
63#define WIRELESS_SPY /* Enable spying addresses */
64/* Definitions we need for spy */
John Daiker141fa612009-03-10 06:59:54 -070065typedef struct iw_statistics iw_stats;
66typedef u_char mac_addr[ETH_ALEN]; /* Hardware address */
Linus Torvalds1da177e2005-04-16 15:20:36 -070067
68#include "rayctl.h"
69#include "ray_cs.h"
70
Linus Torvalds1da177e2005-04-16 15:20:36 -070071
Linus Torvalds1da177e2005-04-16 15:20:36 -070072/** Prototypes based on PCMCIA skeleton driver *******************************/
Dominik Brodowski15b99ac2006-03-31 17:26:06 +020073static int ray_config(struct pcmcia_device *link);
Dominik Brodowskifba395e2006-03-31 17:21:06 +020074static void ray_release(struct pcmcia_device *link);
Dominik Brodowskicc3b4862005-11-14 21:23:14 +010075static void ray_detach(struct pcmcia_device *p_dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -070076
77/***** Prototypes indicated by device structure ******************************/
78static int ray_dev_close(struct net_device *dev);
79static int ray_dev_config(struct net_device *dev, struct ifmap *map);
80static struct net_device_stats *ray_get_stats(struct net_device *dev);
81static int ray_dev_init(struct net_device *dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -070082
Jeff Garzik7282d492006-09-13 14:30:00 -040083static const struct ethtool_ops netdev_ethtool_ops;
Linus Torvalds1da177e2005-04-16 15:20:36 -070084
85static int ray_open(struct net_device *dev);
Stephen Hemmingerd0cf9c02009-08-31 19:50:57 +000086static netdev_tx_t ray_dev_start_xmit(struct sk_buff *skb,
87 struct net_device *dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -070088static void set_multicast_list(struct net_device *dev);
89static void ray_update_multi_list(struct net_device *dev, int all);
90static int translate_frame(ray_dev_t *local, struct tx_msg __iomem *ptx,
John Daiker141fa612009-03-10 06:59:54 -070091 unsigned char *data, int len);
92static void ray_build_header(ray_dev_t *local, struct tx_msg __iomem *ptx,
93 UCHAR msg_type, unsigned char *data);
Linus Torvalds1da177e2005-04-16 15:20:36 -070094static void untranslate(ray_dev_t *local, struct sk_buff *skb, int len);
John Daiker141fa612009-03-10 06:59:54 -070095static iw_stats *ray_get_wireless_stats(struct net_device *dev);
96static const struct iw_handler_def ray_handler_def;
Linus Torvalds1da177e2005-04-16 15:20:36 -070097
98/***** Prototypes for raylink functions **************************************/
99static int asc_to_int(char a);
100static void authenticate(ray_dev_t *local);
101static int build_auth_frame(ray_dev_t *local, UCHAR *dest, int auth_type);
102static void authenticate_timeout(u_long);
103static int get_free_ccs(ray_dev_t *local);
104static int get_free_tx_ccs(ray_dev_t *local);
105static void init_startup_params(ray_dev_t *local);
106static int parse_addr(char *in_str, UCHAR *out);
John Daiker141fa612009-03-10 06:59:54 -0700107static int ray_hw_xmit(unsigned char *data, int len, struct net_device *dev, UCHAR type);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700108static int ray_init(struct net_device *dev);
109static int interrupt_ecf(ray_dev_t *local, int ccs);
110static void ray_reset(struct net_device *dev);
111static void ray_update_parm(struct net_device *dev, UCHAR objid, UCHAR *value, int len);
112static void verify_dl_startup(u_long);
113
114/* Prototypes for interrpt time functions **********************************/
John Daiker141fa612009-03-10 06:59:54 -0700115static irqreturn_t ray_interrupt(int reg, void *dev_id);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700116static void clear_interrupt(ray_dev_t *local);
John Daiker141fa612009-03-10 06:59:54 -0700117static void rx_deauthenticate(ray_dev_t *local, struct rcs __iomem *prcs,
118 unsigned int pkt_addr, int rx_len);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700119static int copy_from_rx_buff(ray_dev_t *local, UCHAR *dest, int pkt_addr, int len);
120static void ray_rx(struct net_device *dev, ray_dev_t *local, struct rcs __iomem *prcs);
121static void release_frag_chain(ray_dev_t *local, struct rcs __iomem *prcs);
122static void rx_authenticate(ray_dev_t *local, struct rcs __iomem *prcs,
John Daiker141fa612009-03-10 06:59:54 -0700123 unsigned int pkt_addr, int rx_len);
124static void rx_data(struct net_device *dev, struct rcs __iomem *prcs,
125 unsigned int pkt_addr, int rx_len);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700126static void associate(ray_dev_t *local);
127
128/* Card command functions */
129static int dl_startup_params(struct net_device *dev);
130static void join_net(u_long local);
131static void start_net(u_long local);
132/* void start_net(ray_dev_t *local); */
133
134/*===========================================================================*/
135/* Parameters that can be set with 'insmod' */
136
137/* ADHOC=0, Infrastructure=1 */
138static int net_type = ADHOC;
139
140/* Hop dwell time in Kus (1024 us units defined by 802.11) */
141static int hop_dwell = 128;
142
143/* Beacon period in Kus */
144static int beacon_period = 256;
145
146/* power save mode (0 = off, 1 = save power) */
147static int psm;
148
149/* String for network's Extended Service Set ID. 32 Characters max */
150static char *essid;
151
152/* Default to encapsulation unless translation requested */
153static int translate = 1;
154
155static int country = USA;
156
157static int sniffer;
158
159static int bc;
160
161/* 48 bit physical card address if overriding card's real physical
162 * address is required. Since IEEE 802.11 addresses are 48 bits
163 * like ethernet, an int can't be used, so a string is used. To
164 * allow use of addresses starting with a decimal digit, the first
165 * character must be a letter and will be ignored. This letter is
166 * followed by up to 12 hex digits which are the address. If less
167 * than 12 digits are used, the address will be left filled with 0's.
168 * Note that bit 0 of the first byte is the broadcast bit, and evil
169 * things will happen if it is not 0 in a card address.
170 */
171static char *phy_addr = NULL;
172
173
Dominik Brodowskifba395e2006-03-31 17:21:06 +0200174/* A struct pcmcia_device structure has fields for most things that are needed
Linus Torvalds1da177e2005-04-16 15:20:36 -0700175 to keep track of a socket, but there will usually be some device
176 specific information that also needs to be kept track of. The
Dominik Brodowskifba395e2006-03-31 17:21:06 +0200177 'priv' pointer in a struct pcmcia_device structure can be used to point to
Linus Torvalds1da177e2005-04-16 15:20:36 -0700178 a device-specific private data structure, like this.
179*/
180static unsigned int ray_mem_speed = 500;
181
Dominik Brodowskifd238232006-03-05 10:45:09 +0100182/* WARNING: THIS DRIVER IS NOT CAPABLE OF HANDLING MULTIPLE DEVICES! */
183static struct pcmcia_device *this_device = NULL;
184
Linus Torvalds1da177e2005-04-16 15:20:36 -0700185MODULE_AUTHOR("Corey Thomas <corey@world.std.com>");
186MODULE_DESCRIPTION("Raylink/WebGear wireless LAN driver");
187MODULE_LICENSE("GPL");
188
189module_param(net_type, int, 0);
190module_param(hop_dwell, int, 0);
191module_param(beacon_period, int, 0);
192module_param(psm, int, 0);
193module_param(essid, charp, 0);
194module_param(translate, int, 0);
195module_param(country, int, 0);
196module_param(sniffer, int, 0);
197module_param(bc, int, 0);
198module_param(phy_addr, charp, 0);
199module_param(ray_mem_speed, int, 0);
200
201static UCHAR b5_default_startup_parms[] = {
John Daiker141fa612009-03-10 06:59:54 -0700202 0, 0, /* Adhoc station */
203 'L', 'I', 'N', 'U', 'X', 0, 0, 0, /* 32 char ESSID */
204 0, 0, 0, 0, 0, 0, 0, 0,
205 0, 0, 0, 0, 0, 0, 0, 0,
206 0, 0, 0, 0, 0, 0, 0, 0,
207 1, 0, /* Active scan, CA Mode */
208 0, 0, 0, 0, 0, 0, /* No default MAC addr */
209 0x7f, 0xff, /* Frag threshold */
210 0x00, 0x80, /* Hop time 128 Kus */
211 0x01, 0x00, /* Beacon period 256 Kus */
212 0x01, 0x07, 0xa3, /* DTIM, retries, ack timeout */
213 0x1d, 0x82, 0x4e, /* SIFS, DIFS, PIFS */
214 0x7f, 0xff, /* RTS threshold */
215 0x04, 0xe2, 0x38, 0xA4, /* scan_dwell, max_scan_dwell */
216 0x05, /* assoc resp timeout thresh */
217 0x08, 0x02, 0x08, /* adhoc, infra, super cycle max */
218 0, /* Promiscuous mode */
219 0x0c, 0x0bd, /* Unique word */
220 0x32, /* Slot time */
221 0xff, 0xff, /* roam-low snr, low snr count */
222 0x05, 0xff, /* Infra, adhoc missed bcn thresh */
223 0x01, 0x0b, 0x4f, /* USA, hop pattern, hop pat length */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700224/* b4 - b5 differences start here */
John Daiker141fa612009-03-10 06:59:54 -0700225 0x00, 0x3f, /* CW max */
226 0x00, 0x0f, /* CW min */
227 0x04, 0x08, /* Noise gain, limit offset */
228 0x28, 0x28, /* det rssi, med busy offsets */
229 7, /* det sync thresh */
230 0, 2, 2, /* test mode, min, max */
231 0, /* allow broadcast SSID probe resp */
232 0, 0, /* privacy must start, can join */
233 2, 0, 0, 0, 0, 0, 0, 0 /* basic rate set */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700234};
235
236static UCHAR b4_default_startup_parms[] = {
John Daiker141fa612009-03-10 06:59:54 -0700237 0, 0, /* Adhoc station */
238 'L', 'I', 'N', 'U', 'X', 0, 0, 0, /* 32 char ESSID */
239 0, 0, 0, 0, 0, 0, 0, 0,
240 0, 0, 0, 0, 0, 0, 0, 0,
241 0, 0, 0, 0, 0, 0, 0, 0,
242 1, 0, /* Active scan, CA Mode */
243 0, 0, 0, 0, 0, 0, /* No default MAC addr */
244 0x7f, 0xff, /* Frag threshold */
245 0x02, 0x00, /* Hop time */
246 0x00, 0x01, /* Beacon period */
247 0x01, 0x07, 0xa3, /* DTIM, retries, ack timeout */
248 0x1d, 0x82, 0xce, /* SIFS, DIFS, PIFS */
249 0x7f, 0xff, /* RTS threshold */
250 0xfb, 0x1e, 0xc7, 0x5c, /* scan_dwell, max_scan_dwell */
251 0x05, /* assoc resp timeout thresh */
252 0x04, 0x02, 0x4, /* adhoc, infra, super cycle max */
253 0, /* Promiscuous mode */
254 0x0c, 0x0bd, /* Unique word */
255 0x4e, /* Slot time (TBD seems wrong) */
256 0xff, 0xff, /* roam-low snr, low snr count */
257 0x05, 0xff, /* Infra, adhoc missed bcn thresh */
258 0x01, 0x0b, 0x4e, /* USA, hop pattern, hop pat length */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700259/* b4 - b5 differences start here */
John Daiker141fa612009-03-10 06:59:54 -0700260 0x3f, 0x0f, /* CW max, min */
261 0x04, 0x08, /* Noise gain, limit offset */
262 0x28, 0x28, /* det rssi, med busy offsets */
263 7, /* det sync thresh */
264 0, 2, 2 /* test mode, min, max */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700265};
John Daiker141fa612009-03-10 06:59:54 -0700266
Linus Torvalds1da177e2005-04-16 15:20:36 -0700267/*===========================================================================*/
John Daiker141fa612009-03-10 06:59:54 -0700268static unsigned char eth2_llc[] = { 0xaa, 0xaa, 3, 0, 0, 0 };
Linus Torvalds1da177e2005-04-16 15:20:36 -0700269
270static char hop_pattern_length[] = { 1,
John Daiker141fa612009-03-10 06:59:54 -0700271 USA_HOP_MOD, EUROPE_HOP_MOD,
272 JAPAN_HOP_MOD, KOREA_HOP_MOD,
273 SPAIN_HOP_MOD, FRANCE_HOP_MOD,
274 ISRAEL_HOP_MOD, AUSTRALIA_HOP_MOD,
275 JAPAN_TEST_HOP_MOD
Linus Torvalds1da177e2005-04-16 15:20:36 -0700276};
277
John Daiker141fa612009-03-10 06:59:54 -0700278static char rcsid[] =
279 "Raylink/WebGear wireless LAN - Corey <Thomas corey@world.std.com>";
Linus Torvalds1da177e2005-04-16 15:20:36 -0700280
Stephen Hemminger32f5a332009-03-20 19:36:28 +0000281static const struct net_device_ops ray_netdev_ops = {
282 .ndo_init = ray_dev_init,
283 .ndo_open = ray_open,
284 .ndo_stop = ray_dev_close,
285 .ndo_start_xmit = ray_dev_start_xmit,
286 .ndo_set_config = ray_dev_config,
287 .ndo_get_stats = ray_get_stats,
288 .ndo_set_multicast_list = set_multicast_list,
289 .ndo_change_mtu = eth_change_mtu,
290 .ndo_set_mac_address = eth_mac_addr,
291 .ndo_validate_addr = eth_validate_addr,
292};
293
Linus Torvalds1da177e2005-04-16 15:20:36 -0700294/*=============================================================================
295 ray_attach() creates an "instance" of the driver, allocating
296 local data structures for one device. The device is registered
297 with Card Services.
298 The dev_link structure is initialized, but we don't actually
299 configure the card at this point -- we wait until we receive a
300 card insertion event.
301=============================================================================*/
Dominik Brodowski15b99ac2006-03-31 17:26:06 +0200302static int ray_probe(struct pcmcia_device *p_dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700303{
John Daiker141fa612009-03-10 06:59:54 -0700304 ray_dev_t *local;
305 struct net_device *dev;
Dominik Brodowskifd238232006-03-05 10:45:09 +0100306
Dominik Brodowski624dd662009-10-24 15:52:44 +0200307 dev_dbg(&p_dev->dev, "ray_attach()\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700308
John Daiker141fa612009-03-10 06:59:54 -0700309 /* Allocate space for private device-specific data */
310 dev = alloc_etherdev(sizeof(ray_dev_t));
311 if (!dev)
312 goto fail_alloc_dev;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700313
John Daiker141fa612009-03-10 06:59:54 -0700314 local = netdev_priv(dev);
315 local->finder = p_dev;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700316
John Daiker141fa612009-03-10 06:59:54 -0700317 /* The io structure describes IO port mapping. None used here */
Dominik Brodowski90abdc32010-07-24 17:23:51 +0200318 p_dev->resource[0]->end = 0;
319 p_dev->resource[0]->flags |= IO_DATA_PATH_WIDTH_8;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700320
John Daiker141fa612009-03-10 06:59:54 -0700321 /* General socket configuration */
322 p_dev->conf.Attributes = CONF_ENABLE_IRQ;
323 p_dev->conf.IntType = INT_MEMORY_AND_IO;
324 p_dev->conf.ConfigIndex = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700325
John Daiker141fa612009-03-10 06:59:54 -0700326 p_dev->priv = dev;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700327
John Daiker141fa612009-03-10 06:59:54 -0700328 local->finder = p_dev;
329 local->card_status = CARD_INSERTED;
330 local->authentication_state = UNAUTHENTICATED;
331 local->num_multi = 0;
Dominik Brodowski624dd662009-10-24 15:52:44 +0200332 dev_dbg(&p_dev->dev, "ray_attach p_dev = %p, dev = %p, local = %p, intr = %p\n",
John Daiker141fa612009-03-10 06:59:54 -0700333 p_dev, dev, local, &ray_interrupt);
334
335 /* Raylink entries in the device structure */
Stephen Hemminger32f5a332009-03-20 19:36:28 +0000336 dev->netdev_ops = &ray_netdev_ops;
John Daiker141fa612009-03-10 06:59:54 -0700337 SET_ETHTOOL_OPS(dev, &netdev_ethtool_ops);
338 dev->wireless_handlers = &ray_handler_def;
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -0700339#ifdef WIRELESS_SPY
John Daiker141fa612009-03-10 06:59:54 -0700340 local->wireless_data.spy_data = &local->spy_data;
341 dev->wireless_data = &local->wireless_data;
342#endif /* WIRELESS_SPY */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700343
Linus Torvalds1da177e2005-04-16 15:20:36 -0700344
Dominik Brodowski624dd662009-10-24 15:52:44 +0200345 dev_dbg(&p_dev->dev, "ray_cs ray_attach calling ether_setup.)\n");
John Daiker141fa612009-03-10 06:59:54 -0700346 netif_stop_queue(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700347
John Daiker141fa612009-03-10 06:59:54 -0700348 init_timer(&local->timer);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700349
John Daiker141fa612009-03-10 06:59:54 -0700350 this_device = p_dev;
351 return ray_config(p_dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700352
353fail_alloc_dev:
John Daiker141fa612009-03-10 06:59:54 -0700354 return -ENOMEM;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700355} /* ray_attach */
John Daiker141fa612009-03-10 06:59:54 -0700356
Linus Torvalds1da177e2005-04-16 15:20:36 -0700357/*=============================================================================
358 This deletes a driver "instance". The device is de-registered
359 with Card Services. If it has been released, all local data
360 structures are freed. Otherwise, the structures will be freed
361 when the device is released.
362=============================================================================*/
Dominik Brodowskifba395e2006-03-31 17:21:06 +0200363static void ray_detach(struct pcmcia_device *link)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700364{
John Daiker141fa612009-03-10 06:59:54 -0700365 struct net_device *dev;
366 ray_dev_t *local;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700367
Dominik Brodowski624dd662009-10-24 15:52:44 +0200368 dev_dbg(&link->dev, "ray_detach\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700369
John Daiker141fa612009-03-10 06:59:54 -0700370 this_device = NULL;
371 dev = link->priv;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700372
John Daiker141fa612009-03-10 06:59:54 -0700373 ray_release(link);
Dominik Brodowskicc3b4862005-11-14 21:23:14 +0100374
John Daiker141fa612009-03-10 06:59:54 -0700375 local = netdev_priv(dev);
376 del_timer(&local->timer);
Dominik Brodowskicc3b4862005-11-14 21:23:14 +0100377
John Daiker141fa612009-03-10 06:59:54 -0700378 if (link->priv) {
Dominik Brodowskic7c2fa02010-03-20 19:39:26 +0100379 unregister_netdev(dev);
John Daiker141fa612009-03-10 06:59:54 -0700380 free_netdev(dev);
381 }
Dominik Brodowski624dd662009-10-24 15:52:44 +0200382 dev_dbg(&link->dev, "ray_cs ray_detach ending\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700383} /* ray_detach */
John Daiker141fa612009-03-10 06:59:54 -0700384
Linus Torvalds1da177e2005-04-16 15:20:36 -0700385/*=============================================================================
386 ray_config() is run after a CARD_INSERTION event
387 is received, to configure the PCMCIA socket, and to make the
388 ethernet device available to the system.
389=============================================================================*/
Linus Torvalds1da177e2005-04-16 15:20:36 -0700390#define MAX_TUPLE_SIZE 128
Dominik Brodowski15b99ac2006-03-31 17:26:06 +0200391static int ray_config(struct pcmcia_device *link)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700392{
Dominik Brodowski624dd662009-10-24 15:52:44 +0200393 int ret = 0;
John Daiker141fa612009-03-10 06:59:54 -0700394 int i;
395 win_req_t req;
396 memreq_t mem;
397 struct net_device *dev = (struct net_device *)link->priv;
398 ray_dev_t *local = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700399
Dominik Brodowski624dd662009-10-24 15:52:44 +0200400 dev_dbg(&link->dev, "ray_config\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700401
John Daiker141fa612009-03-10 06:59:54 -0700402 /* Determine card type and firmware version */
403 printk(KERN_INFO "ray_cs Detected: %s%s%s%s\n",
404 link->prod_id[0] ? link->prod_id[0] : " ",
405 link->prod_id[1] ? link->prod_id[1] : " ",
406 link->prod_id[2] ? link->prod_id[2] : " ",
407 link->prod_id[3] ? link->prod_id[3] : " ");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700408
John Daiker141fa612009-03-10 06:59:54 -0700409 /* Now allocate an interrupt line. Note that this does not
410 actually assign a handler to the interrupt.
411 */
Dominik Brodowskieb141202010-03-07 12:21:16 +0100412 ret = pcmcia_request_irq(link, ray_interrupt);
Dominik Brodowski624dd662009-10-24 15:52:44 +0200413 if (ret)
414 goto failed;
Dominik Brodowskieb141202010-03-07 12:21:16 +0100415 dev->irq = link->irq;
John Daiker141fa612009-03-10 06:59:54 -0700416
417 /* This actually configures the PCMCIA socket -- setting up
418 the I/O windows and the interrupt mapping.
419 */
Dominik Brodowski624dd662009-10-24 15:52:44 +0200420 ret = pcmcia_request_configuration(link, &link->conf);
421 if (ret)
422 goto failed;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700423
424/*** Set up 32k window for shared memory (transmit and control) ************/
John Daiker141fa612009-03-10 06:59:54 -0700425 req.Attributes =
426 WIN_DATA_WIDTH_8 | WIN_MEMORY_TYPE_CM | WIN_ENABLE | WIN_USE_WAIT;
427 req.Base = 0;
428 req.Size = 0x8000;
429 req.AccessSpeed = ray_mem_speed;
Dominik Brodowski6838b032009-11-03 01:31:52 +0100430 ret = pcmcia_request_window(link, &req, &link->win);
Dominik Brodowski624dd662009-10-24 15:52:44 +0200431 if (ret)
432 goto failed;
John Daiker141fa612009-03-10 06:59:54 -0700433 mem.CardOffset = 0x0000;
434 mem.Page = 0;
Magnus Damm868575d2006-12-13 19:46:43 +0900435 ret = pcmcia_map_mem_page(link, link->win, &mem);
Dominik Brodowski624dd662009-10-24 15:52:44 +0200436 if (ret)
437 goto failed;
John Daiker141fa612009-03-10 06:59:54 -0700438 local->sram = ioremap(req.Base, req.Size);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700439
440/*** Set up 16k window for shared memory (receive buffer) ***************/
John Daiker141fa612009-03-10 06:59:54 -0700441 req.Attributes =
442 WIN_DATA_WIDTH_8 | WIN_MEMORY_TYPE_CM | WIN_ENABLE | WIN_USE_WAIT;
443 req.Base = 0;
444 req.Size = 0x4000;
445 req.AccessSpeed = ray_mem_speed;
Dominik Brodowski6838b032009-11-03 01:31:52 +0100446 ret = pcmcia_request_window(link, &req, &local->rmem_handle);
Dominik Brodowski624dd662009-10-24 15:52:44 +0200447 if (ret)
448 goto failed;
John Daiker141fa612009-03-10 06:59:54 -0700449 mem.CardOffset = 0x8000;
450 mem.Page = 0;
Magnus Damm868575d2006-12-13 19:46:43 +0900451 ret = pcmcia_map_mem_page(link, local->rmem_handle, &mem);
Dominik Brodowski624dd662009-10-24 15:52:44 +0200452 if (ret)
453 goto failed;
John Daiker141fa612009-03-10 06:59:54 -0700454 local->rmem = ioremap(req.Base, req.Size);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700455
456/*** Set up window for attribute memory ***********************************/
John Daiker141fa612009-03-10 06:59:54 -0700457 req.Attributes =
458 WIN_DATA_WIDTH_8 | WIN_MEMORY_TYPE_AM | WIN_ENABLE | WIN_USE_WAIT;
459 req.Base = 0;
460 req.Size = 0x1000;
461 req.AccessSpeed = ray_mem_speed;
Dominik Brodowski6838b032009-11-03 01:31:52 +0100462 ret = pcmcia_request_window(link, &req, &local->amem_handle);
Dominik Brodowski624dd662009-10-24 15:52:44 +0200463 if (ret)
464 goto failed;
John Daiker141fa612009-03-10 06:59:54 -0700465 mem.CardOffset = 0x0000;
466 mem.Page = 0;
Magnus Damm868575d2006-12-13 19:46:43 +0900467 ret = pcmcia_map_mem_page(link, local->amem_handle, &mem);
Dominik Brodowski624dd662009-10-24 15:52:44 +0200468 if (ret)
469 goto failed;
John Daiker141fa612009-03-10 06:59:54 -0700470 local->amem = ioremap(req.Base, req.Size);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700471
Dominik Brodowski624dd662009-10-24 15:52:44 +0200472 dev_dbg(&link->dev, "ray_config sram=%p\n", local->sram);
473 dev_dbg(&link->dev, "ray_config rmem=%p\n", local->rmem);
474 dev_dbg(&link->dev, "ray_config amem=%p\n", local->amem);
John Daiker141fa612009-03-10 06:59:54 -0700475 if (ray_init(dev) < 0) {
476 ray_release(link);
477 return -ENODEV;
478 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700479
Dominik Brodowskidd2e5a12009-11-03 10:27:34 +0100480 SET_NETDEV_DEV(dev, &link->dev);
John Daiker141fa612009-03-10 06:59:54 -0700481 i = register_netdev(dev);
482 if (i != 0) {
483 printk("ray_config register_netdev() failed\n");
484 ray_release(link);
485 return i;
486 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700487
John Daiker141fa612009-03-10 06:59:54 -0700488 printk(KERN_INFO "%s: RayLink, irq %d, hw_addr %pM\n",
489 dev->name, dev->irq, dev->dev_addr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700490
John Daiker141fa612009-03-10 06:59:54 -0700491 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700492
Dominik Brodowski624dd662009-10-24 15:52:44 +0200493failed:
John Daiker141fa612009-03-10 06:59:54 -0700494 ray_release(link);
495 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700496} /* ray_config */
497
498static inline struct ccs __iomem *ccs_base(ray_dev_t *dev)
499{
500 return dev->sram + CCS_BASE;
501}
502
503static inline struct rcs __iomem *rcs_base(ray_dev_t *dev)
504{
505 /*
506 * This looks nonsensical, since there is a separate
507 * RCS_BASE. But the difference between a "struct rcs"
508 * and a "struct ccs" ends up being in the _index_ off
509 * the base, so the base pointer is the same for both
510 * ccs/rcs.
511 */
512 return dev->sram + CCS_BASE;
513}
514
515/*===========================================================================*/
516static int ray_init(struct net_device *dev)
517{
John Daiker141fa612009-03-10 06:59:54 -0700518 int i;
519 UCHAR *p;
520 struct ccs __iomem *pccs;
521 ray_dev_t *local = netdev_priv(dev);
522 struct pcmcia_device *link = local->finder;
Dominik Brodowski624dd662009-10-24 15:52:44 +0200523 dev_dbg(&link->dev, "ray_init(0x%p)\n", dev);
John Daiker141fa612009-03-10 06:59:54 -0700524 if (!(pcmcia_dev_present(link))) {
Dominik Brodowski624dd662009-10-24 15:52:44 +0200525 dev_dbg(&link->dev, "ray_init - device not present\n");
John Daiker141fa612009-03-10 06:59:54 -0700526 return -1;
527 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700528
John Daiker141fa612009-03-10 06:59:54 -0700529 local->net_type = net_type;
530 local->sta_type = TYPE_STA;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700531
John Daiker141fa612009-03-10 06:59:54 -0700532 /* Copy the startup results to local memory */
533 memcpy_fromio(&local->startup_res, local->sram + ECF_TO_HOST_BASE,
534 sizeof(struct startup_res_6));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700535
John Daiker141fa612009-03-10 06:59:54 -0700536 /* Check Power up test status and get mac address from card */
537 if (local->startup_res.startup_word != 0x80) {
538 printk(KERN_INFO "ray_init ERROR card status = %2x\n",
539 local->startup_res.startup_word);
540 local->card_status = CARD_INIT_ERROR;
541 return -1;
542 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700543
John Daiker141fa612009-03-10 06:59:54 -0700544 local->fw_ver = local->startup_res.firmware_version[0];
545 local->fw_bld = local->startup_res.firmware_version[1];
546 local->fw_var = local->startup_res.firmware_version[2];
Frans Popcb01b092010-03-24 19:46:34 +0100547 dev_dbg(&link->dev, "ray_init firmware version %d.%d\n", local->fw_ver,
John Daiker141fa612009-03-10 06:59:54 -0700548 local->fw_bld);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700549
John Daiker141fa612009-03-10 06:59:54 -0700550 local->tib_length = 0x20;
551 if ((local->fw_ver == 5) && (local->fw_bld >= 30))
552 local->tib_length = local->startup_res.tib_length;
Dominik Brodowski624dd662009-10-24 15:52:44 +0200553 dev_dbg(&link->dev, "ray_init tib_length = 0x%02x\n", local->tib_length);
John Daiker141fa612009-03-10 06:59:54 -0700554 /* Initialize CCS's to buffer free state */
555 pccs = ccs_base(local);
556 for (i = 0; i < NUMBER_OF_CCS; i++) {
557 writeb(CCS_BUFFER_FREE, &(pccs++)->buffer_status);
558 }
559 init_startup_params(local);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700560
John Daiker141fa612009-03-10 06:59:54 -0700561 /* copy mac address to startup parameters */
562 if (parse_addr(phy_addr, local->sparm.b4.a_mac_addr)) {
563 p = local->sparm.b4.a_mac_addr;
564 } else {
565 memcpy(&local->sparm.b4.a_mac_addr,
566 &local->startup_res.station_addr, ADDRLEN);
567 p = local->sparm.b4.a_mac_addr;
568 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700569
John Daiker141fa612009-03-10 06:59:54 -0700570 clear_interrupt(local); /* Clear any interrupt from the card */
571 local->card_status = CARD_AWAITING_PARAM;
Dominik Brodowski624dd662009-10-24 15:52:44 +0200572 dev_dbg(&link->dev, "ray_init ending\n");
John Daiker141fa612009-03-10 06:59:54 -0700573 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700574} /* ray_init */
John Daiker141fa612009-03-10 06:59:54 -0700575
Linus Torvalds1da177e2005-04-16 15:20:36 -0700576/*===========================================================================*/
577/* Download startup parameters to the card and command it to read them */
578static int dl_startup_params(struct net_device *dev)
579{
John Daiker141fa612009-03-10 06:59:54 -0700580 int ccsindex;
581 ray_dev_t *local = netdev_priv(dev);
582 struct ccs __iomem *pccs;
583 struct pcmcia_device *link = local->finder;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700584
Dominik Brodowski624dd662009-10-24 15:52:44 +0200585 dev_dbg(&link->dev, "dl_startup_params entered\n");
John Daiker141fa612009-03-10 06:59:54 -0700586 if (!(pcmcia_dev_present(link))) {
Dominik Brodowski624dd662009-10-24 15:52:44 +0200587 dev_dbg(&link->dev, "ray_cs dl_startup_params - device not present\n");
John Daiker141fa612009-03-10 06:59:54 -0700588 return -1;
589 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700590
John Daiker141fa612009-03-10 06:59:54 -0700591 /* Copy parameters to host to ECF area */
592 if (local->fw_ver == 0x55)
593 memcpy_toio(local->sram + HOST_TO_ECF_BASE, &local->sparm.b4,
594 sizeof(struct b4_startup_params));
595 else
596 memcpy_toio(local->sram + HOST_TO_ECF_BASE, &local->sparm.b5,
597 sizeof(struct b5_startup_params));
598
599 /* Fill in the CCS fields for the ECF */
600 if ((ccsindex = get_free_ccs(local)) < 0)
601 return -1;
602 local->dl_param_ccs = ccsindex;
603 pccs = ccs_base(local) + ccsindex;
604 writeb(CCS_DOWNLOAD_STARTUP_PARAMS, &pccs->cmd);
Dominik Brodowski624dd662009-10-24 15:52:44 +0200605 dev_dbg(&link->dev, "dl_startup_params start ccsindex = %d\n",
John Daiker141fa612009-03-10 06:59:54 -0700606 local->dl_param_ccs);
607 /* Interrupt the firmware to process the command */
608 if (interrupt_ecf(local, ccsindex)) {
609 printk(KERN_INFO "ray dl_startup_params failed - "
610 "ECF not ready for intr\n");
611 local->card_status = CARD_DL_PARAM_ERROR;
612 writeb(CCS_BUFFER_FREE, &(pccs++)->buffer_status);
613 return -2;
614 }
615 local->card_status = CARD_DL_PARAM;
616 /* Start kernel timer to wait for dl startup to complete. */
617 local->timer.expires = jiffies + HZ / 2;
618 local->timer.data = (long)local;
619 local->timer.function = &verify_dl_startup;
620 add_timer(&local->timer);
Dominik Brodowski624dd662009-10-24 15:52:44 +0200621 dev_dbg(&link->dev,
John Daiker141fa612009-03-10 06:59:54 -0700622 "ray_cs dl_startup_params started timer for verify_dl_startup\n");
623 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700624} /* dl_startup_params */
John Daiker141fa612009-03-10 06:59:54 -0700625
Linus Torvalds1da177e2005-04-16 15:20:36 -0700626/*===========================================================================*/
627static void init_startup_params(ray_dev_t *local)
628{
John Daiker141fa612009-03-10 06:59:54 -0700629 int i;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700630
John Daiker141fa612009-03-10 06:59:54 -0700631 if (country > JAPAN_TEST)
632 country = USA;
633 else if (country < USA)
634 country = USA;
635 /* structure for hop time and beacon period is defined here using
636 * New 802.11D6.1 format. Card firmware is still using old format
637 * until version 6.
638 * Before After
639 * a_hop_time ms byte a_hop_time ms byte
640 * a_hop_time 2s byte a_hop_time ls byte
641 * a_hop_time ls byte a_beacon_period ms byte
642 * a_beacon_period a_beacon_period ls byte
643 *
644 * a_hop_time = uS a_hop_time = KuS
645 * a_beacon_period = hops a_beacon_period = KuS
646 *//* 64ms = 010000 */
647 if (local->fw_ver == 0x55) {
648 memcpy((UCHAR *) &local->sparm.b4, b4_default_startup_parms,
649 sizeof(struct b4_startup_params));
650 /* Translate sane kus input values to old build 4/5 format */
651 /* i = hop time in uS truncated to 3 bytes */
652 i = (hop_dwell * 1024) & 0xffffff;
653 local->sparm.b4.a_hop_time[0] = (i >> 16) & 0xff;
654 local->sparm.b4.a_hop_time[1] = (i >> 8) & 0xff;
655 local->sparm.b4.a_beacon_period[0] = 0;
656 local->sparm.b4.a_beacon_period[1] =
657 ((beacon_period / hop_dwell) - 1) & 0xff;
658 local->sparm.b4.a_curr_country_code = country;
659 local->sparm.b4.a_hop_pattern_length =
660 hop_pattern_length[(int)country] - 1;
661 if (bc) {
662 local->sparm.b4.a_ack_timeout = 0x50;
663 local->sparm.b4.a_sifs = 0x3f;
664 }
665 } else { /* Version 5 uses real kus values */
666 memcpy((UCHAR *) &local->sparm.b5, b5_default_startup_parms,
667 sizeof(struct b5_startup_params));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700668
John Daiker141fa612009-03-10 06:59:54 -0700669 local->sparm.b5.a_hop_time[0] = (hop_dwell >> 8) & 0xff;
670 local->sparm.b5.a_hop_time[1] = hop_dwell & 0xff;
671 local->sparm.b5.a_beacon_period[0] =
672 (beacon_period >> 8) & 0xff;
673 local->sparm.b5.a_beacon_period[1] = beacon_period & 0xff;
674 if (psm)
675 local->sparm.b5.a_power_mgt_state = 1;
676 local->sparm.b5.a_curr_country_code = country;
677 local->sparm.b5.a_hop_pattern_length =
678 hop_pattern_length[(int)country];
679 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700680
John Daiker141fa612009-03-10 06:59:54 -0700681 local->sparm.b4.a_network_type = net_type & 0x01;
682 local->sparm.b4.a_acting_as_ap_status = TYPE_STA;
683
684 if (essid != NULL)
685 strncpy(local->sparm.b4.a_current_ess_id, essid, ESSID_SIZE);
686} /* init_startup_params */
687
Linus Torvalds1da177e2005-04-16 15:20:36 -0700688/*===========================================================================*/
689static void verify_dl_startup(u_long data)
690{
John Daiker141fa612009-03-10 06:59:54 -0700691 ray_dev_t *local = (ray_dev_t *) data;
692 struct ccs __iomem *pccs = ccs_base(local) + local->dl_param_ccs;
693 UCHAR status;
694 struct pcmcia_device *link = local->finder;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700695
John Daiker141fa612009-03-10 06:59:54 -0700696 if (!(pcmcia_dev_present(link))) {
Dominik Brodowski624dd662009-10-24 15:52:44 +0200697 dev_dbg(&link->dev, "ray_cs verify_dl_startup - device not present\n");
John Daiker141fa612009-03-10 06:59:54 -0700698 return;
699 }
Dominik Brodowski624dd662009-10-24 15:52:44 +0200700#if 0
701 {
John Daiker141fa612009-03-10 06:59:54 -0700702 int i;
703 printk(KERN_DEBUG
704 "verify_dl_startup parameters sent via ccs %d:\n",
705 local->dl_param_ccs);
706 for (i = 0; i < sizeof(struct b5_startup_params); i++) {
707 printk(" %2x",
708 (unsigned int)readb(local->sram +
709 HOST_TO_ECF_BASE + i));
710 }
711 printk("\n");
712 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700713#endif
714
John Daiker141fa612009-03-10 06:59:54 -0700715 status = readb(&pccs->buffer_status);
716 if (status != CCS_BUFFER_FREE) {
717 printk(KERN_INFO
718 "Download startup params failed. Status = %d\n",
719 status);
720 local->card_status = CARD_DL_PARAM_ERROR;
721 return;
722 }
723 if (local->sparm.b4.a_network_type == ADHOC)
724 start_net((u_long) local);
725 else
726 join_net((u_long) local);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700727} /* end verify_dl_startup */
John Daiker141fa612009-03-10 06:59:54 -0700728
Linus Torvalds1da177e2005-04-16 15:20:36 -0700729/*===========================================================================*/
730/* Command card to start a network */
731static void start_net(u_long data)
732{
John Daiker141fa612009-03-10 06:59:54 -0700733 ray_dev_t *local = (ray_dev_t *) data;
734 struct ccs __iomem *pccs;
735 int ccsindex;
736 struct pcmcia_device *link = local->finder;
737 if (!(pcmcia_dev_present(link))) {
Dominik Brodowski624dd662009-10-24 15:52:44 +0200738 dev_dbg(&link->dev, "ray_cs start_net - device not present\n");
John Daiker141fa612009-03-10 06:59:54 -0700739 return;
740 }
741 /* Fill in the CCS fields for the ECF */
742 if ((ccsindex = get_free_ccs(local)) < 0)
743 return;
744 pccs = ccs_base(local) + ccsindex;
745 writeb(CCS_START_NETWORK, &pccs->cmd);
746 writeb(0, &pccs->var.start_network.update_param);
747 /* Interrupt the firmware to process the command */
748 if (interrupt_ecf(local, ccsindex)) {
Dominik Brodowski624dd662009-10-24 15:52:44 +0200749 dev_dbg(&link->dev, "ray start net failed - card not ready for intr\n");
John Daiker141fa612009-03-10 06:59:54 -0700750 writeb(CCS_BUFFER_FREE, &(pccs++)->buffer_status);
751 return;
752 }
753 local->card_status = CARD_DOING_ACQ;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700754} /* end start_net */
John Daiker141fa612009-03-10 06:59:54 -0700755
Linus Torvalds1da177e2005-04-16 15:20:36 -0700756/*===========================================================================*/
757/* Command card to join a network */
758static void join_net(u_long data)
759{
John Daiker141fa612009-03-10 06:59:54 -0700760 ray_dev_t *local = (ray_dev_t *) data;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700761
John Daiker141fa612009-03-10 06:59:54 -0700762 struct ccs __iomem *pccs;
763 int ccsindex;
764 struct pcmcia_device *link = local->finder;
765
766 if (!(pcmcia_dev_present(link))) {
Dominik Brodowski624dd662009-10-24 15:52:44 +0200767 dev_dbg(&link->dev, "ray_cs join_net - device not present\n");
John Daiker141fa612009-03-10 06:59:54 -0700768 return;
769 }
770 /* Fill in the CCS fields for the ECF */
771 if ((ccsindex = get_free_ccs(local)) < 0)
772 return;
773 pccs = ccs_base(local) + ccsindex;
774 writeb(CCS_JOIN_NETWORK, &pccs->cmd);
775 writeb(0, &pccs->var.join_network.update_param);
776 writeb(0, &pccs->var.join_network.net_initiated);
777 /* Interrupt the firmware to process the command */
778 if (interrupt_ecf(local, ccsindex)) {
Dominik Brodowski624dd662009-10-24 15:52:44 +0200779 dev_dbg(&link->dev, "ray join net failed - card not ready for intr\n");
John Daiker141fa612009-03-10 06:59:54 -0700780 writeb(CCS_BUFFER_FREE, &(pccs++)->buffer_status);
781 return;
782 }
783 local->card_status = CARD_DOING_ACQ;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700784}
John Daiker141fa612009-03-10 06:59:54 -0700785
Linus Torvalds1da177e2005-04-16 15:20:36 -0700786/*============================================================================
787 After a card is removed, ray_release() will unregister the net
788 device, and release the PCMCIA configuration. If the device is
789 still open, this will be postponed until it is closed.
790=============================================================================*/
Dominik Brodowskifba395e2006-03-31 17:21:06 +0200791static void ray_release(struct pcmcia_device *link)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700792{
John Daiker141fa612009-03-10 06:59:54 -0700793 struct net_device *dev = link->priv;
794 ray_dev_t *local = netdev_priv(dev);
795 int i;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700796
Dominik Brodowski624dd662009-10-24 15:52:44 +0200797 dev_dbg(&link->dev, "ray_release\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700798
John Daiker141fa612009-03-10 06:59:54 -0700799 del_timer(&local->timer);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700800
John Daiker141fa612009-03-10 06:59:54 -0700801 iounmap(local->sram);
802 iounmap(local->rmem);
803 iounmap(local->amem);
804 /* Do bother checking to see if these succeed or not */
Magnus Dammf5560da2006-12-13 19:46:38 +0900805 i = pcmcia_release_window(link, local->amem_handle);
John Daiker141fa612009-03-10 06:59:54 -0700806 if (i != 0)
Dominik Brodowski624dd662009-10-24 15:52:44 +0200807 dev_dbg(&link->dev, "ReleaseWindow(local->amem) ret = %x\n", i);
Magnus Dammf5560da2006-12-13 19:46:38 +0900808 i = pcmcia_release_window(link, local->rmem_handle);
John Daiker141fa612009-03-10 06:59:54 -0700809 if (i != 0)
Dominik Brodowski624dd662009-10-24 15:52:44 +0200810 dev_dbg(&link->dev, "ReleaseWindow(local->rmem) ret = %x\n", i);
John Daiker141fa612009-03-10 06:59:54 -0700811 pcmcia_disable_device(link);
812
Dominik Brodowski624dd662009-10-24 15:52:44 +0200813 dev_dbg(&link->dev, "ray_release ending\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700814}
815
Dominik Brodowskifba395e2006-03-31 17:21:06 +0200816static int ray_suspend(struct pcmcia_device *link)
Dominik Brodowski98e4c282005-11-14 21:21:18 +0100817{
Dominik Brodowski98e4c282005-11-14 21:21:18 +0100818 struct net_device *dev = link->priv;
819
Dominik Brodowskie2d40962006-03-02 00:09:29 +0100820 if (link->open)
Dominik Brodowski8661bb52006-03-02 00:02:33 +0100821 netif_device_detach(dev);
Dominik Brodowski98e4c282005-11-14 21:21:18 +0100822
823 return 0;
824}
825
Dominik Brodowskifba395e2006-03-31 17:21:06 +0200826static int ray_resume(struct pcmcia_device *link)
Dominik Brodowski98e4c282005-11-14 21:21:18 +0100827{
Dominik Brodowski98e4c282005-11-14 21:21:18 +0100828 struct net_device *dev = link->priv;
829
Dominik Brodowskie2d40962006-03-02 00:09:29 +0100830 if (link->open) {
Dominik Brodowski8661bb52006-03-02 00:02:33 +0100831 ray_reset(dev);
832 netif_device_attach(dev);
833 }
Dominik Brodowski98e4c282005-11-14 21:21:18 +0100834
835 return 0;
836}
837
Linus Torvalds1da177e2005-04-16 15:20:36 -0700838/*===========================================================================*/
Hannes Eder2ed5ba82008-12-26 00:12:59 -0800839static int ray_dev_init(struct net_device *dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700840{
841#ifdef RAY_IMMEDIATE_INIT
John Daiker141fa612009-03-10 06:59:54 -0700842 int i;
843#endif /* RAY_IMMEDIATE_INIT */
844 ray_dev_t *local = netdev_priv(dev);
845 struct pcmcia_device *link = local->finder;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700846
Dominik Brodowski624dd662009-10-24 15:52:44 +0200847 dev_dbg(&link->dev, "ray_dev_init(dev=%p)\n", dev);
John Daiker141fa612009-03-10 06:59:54 -0700848 if (!(pcmcia_dev_present(link))) {
Dominik Brodowski624dd662009-10-24 15:52:44 +0200849 dev_dbg(&link->dev, "ray_dev_init - device not present\n");
John Daiker141fa612009-03-10 06:59:54 -0700850 return -1;
851 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700852#ifdef RAY_IMMEDIATE_INIT
John Daiker141fa612009-03-10 06:59:54 -0700853 /* Download startup parameters */
854 if ((i = dl_startup_params(dev)) < 0) {
855 printk(KERN_INFO "ray_dev_init dl_startup_params failed - "
856 "returns 0x%x\n", i);
857 return -1;
858 }
859#else /* RAY_IMMEDIATE_INIT */
860 /* Postpone the card init so that we can still configure the card,
861 * for example using the Wireless Extensions. The init will happen
862 * in ray_open() - Jean II */
Dominik Brodowski624dd662009-10-24 15:52:44 +0200863 dev_dbg(&link->dev,
John Daiker141fa612009-03-10 06:59:54 -0700864 "ray_dev_init: postponing card init to ray_open() ; Status = %d\n",
865 local->card_status);
866#endif /* RAY_IMMEDIATE_INIT */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700867
John Daiker141fa612009-03-10 06:59:54 -0700868 /* copy mac and broadcast addresses to linux device */
Jiri Pirko3a6d54c2009-05-11 23:37:15 +0000869 memcpy(dev->dev_addr, &local->sparm.b4.a_mac_addr, ADDRLEN);
John Daiker141fa612009-03-10 06:59:54 -0700870 memset(dev->broadcast, 0xff, ETH_ALEN);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700871
Dominik Brodowski624dd662009-10-24 15:52:44 +0200872 dev_dbg(&link->dev, "ray_dev_init ending\n");
John Daiker141fa612009-03-10 06:59:54 -0700873 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700874}
John Daiker141fa612009-03-10 06:59:54 -0700875
Linus Torvalds1da177e2005-04-16 15:20:36 -0700876/*===========================================================================*/
877static int ray_dev_config(struct net_device *dev, struct ifmap *map)
878{
John Daiker141fa612009-03-10 06:59:54 -0700879 ray_dev_t *local = netdev_priv(dev);
880 struct pcmcia_device *link = local->finder;
881 /* Dummy routine to satisfy device structure */
Dominik Brodowski624dd662009-10-24 15:52:44 +0200882 dev_dbg(&link->dev, "ray_dev_config(dev=%p,ifmap=%p)\n", dev, map);
John Daiker141fa612009-03-10 06:59:54 -0700883 if (!(pcmcia_dev_present(link))) {
Dominik Brodowski624dd662009-10-24 15:52:44 +0200884 dev_dbg(&link->dev, "ray_dev_config - device not present\n");
John Daiker141fa612009-03-10 06:59:54 -0700885 return -1;
886 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700887
John Daiker141fa612009-03-10 06:59:54 -0700888 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700889}
John Daiker141fa612009-03-10 06:59:54 -0700890
Linus Torvalds1da177e2005-04-16 15:20:36 -0700891/*===========================================================================*/
Stephen Hemmingerd0cf9c02009-08-31 19:50:57 +0000892static netdev_tx_t ray_dev_start_xmit(struct sk_buff *skb,
893 struct net_device *dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700894{
John Daiker141fa612009-03-10 06:59:54 -0700895 ray_dev_t *local = netdev_priv(dev);
896 struct pcmcia_device *link = local->finder;
897 short length = skb->len;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700898
Stephen Hemmingerd0cf9c02009-08-31 19:50:57 +0000899 if (!pcmcia_dev_present(link)) {
Dominik Brodowski624dd662009-10-24 15:52:44 +0200900 dev_dbg(&link->dev, "ray_dev_start_xmit - device not present\n");
Stephen Hemmingerd0cf9c02009-08-31 19:50:57 +0000901 dev_kfree_skb(skb);
902 return NETDEV_TX_OK;
John Daiker141fa612009-03-10 06:59:54 -0700903 }
Stephen Hemmingerd0cf9c02009-08-31 19:50:57 +0000904
Dominik Brodowski624dd662009-10-24 15:52:44 +0200905 dev_dbg(&link->dev, "ray_dev_start_xmit(skb=%p, dev=%p)\n", skb, dev);
John Daiker141fa612009-03-10 06:59:54 -0700906 if (local->authentication_state == NEED_TO_AUTH) {
Dominik Brodowski624dd662009-10-24 15:52:44 +0200907 dev_dbg(&link->dev, "ray_cs Sending authentication request.\n");
John Daiker141fa612009-03-10 06:59:54 -0700908 if (!build_auth_frame(local, local->auth_id, OPEN_AUTH_REQUEST)) {
909 local->authentication_state = AUTHENTICATED;
910 netif_stop_queue(dev);
Patrick McHardy5b548142009-06-12 06:22:29 +0000911 return NETDEV_TX_BUSY;
John Daiker141fa612009-03-10 06:59:54 -0700912 }
913 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700914
John Daiker141fa612009-03-10 06:59:54 -0700915 if (length < ETH_ZLEN) {
916 if (skb_padto(skb, ETH_ZLEN))
Patrick McHardy6ed10652009-06-23 06:03:08 +0000917 return NETDEV_TX_OK;
John Daiker141fa612009-03-10 06:59:54 -0700918 length = ETH_ZLEN;
919 }
920 switch (ray_hw_xmit(skb->data, length, dev, DATA_TYPE)) {
921 case XMIT_NO_CCS:
922 case XMIT_NEED_AUTH:
923 netif_stop_queue(dev);
Patrick McHardy5b548142009-06-12 06:22:29 +0000924 return NETDEV_TX_BUSY;
John Daiker141fa612009-03-10 06:59:54 -0700925 case XMIT_NO_INTR:
926 case XMIT_MSG_BAD:
927 case XMIT_OK:
928 default:
John Daiker141fa612009-03-10 06:59:54 -0700929 dev_kfree_skb(skb);
John Daiker141fa612009-03-10 06:59:54 -0700930 }
Stephen Hemmingerd0cf9c02009-08-31 19:50:57 +0000931
Patrick McHardy6ed10652009-06-23 06:03:08 +0000932 return NETDEV_TX_OK;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700933} /* ray_dev_start_xmit */
John Daiker141fa612009-03-10 06:59:54 -0700934
Linus Torvalds1da177e2005-04-16 15:20:36 -0700935/*===========================================================================*/
John Daiker141fa612009-03-10 06:59:54 -0700936static int ray_hw_xmit(unsigned char *data, int len, struct net_device *dev,
937 UCHAR msg_type)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700938{
John Daiker141fa612009-03-10 06:59:54 -0700939 ray_dev_t *local = netdev_priv(dev);
940 struct ccs __iomem *pccs;
941 int ccsindex;
942 int offset;
943 struct tx_msg __iomem *ptx; /* Address of xmit buffer in PC space */
944 short int addr; /* Address of xmit buffer in card space */
945
Dominik Brodowski624dd662009-10-24 15:52:44 +0200946 pr_debug("ray_hw_xmit(data=%p, len=%d, dev=%p)\n", data, len, dev);
John Daiker141fa612009-03-10 06:59:54 -0700947 if (len + TX_HEADER_LENGTH > TX_BUF_SIZE) {
948 printk(KERN_INFO "ray_hw_xmit packet too large: %d bytes\n",
949 len);
950 return XMIT_MSG_BAD;
951 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700952 switch (ccsindex = get_free_tx_ccs(local)) {
953 case ECCSBUSY:
Dominik Brodowski624dd662009-10-24 15:52:44 +0200954 pr_debug("ray_hw_xmit tx_ccs table busy\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700955 case ECCSFULL:
Dominik Brodowski624dd662009-10-24 15:52:44 +0200956 pr_debug("ray_hw_xmit No free tx ccs\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700957 case ECARDGONE:
John Daiker141fa612009-03-10 06:59:54 -0700958 netif_stop_queue(dev);
959 return XMIT_NO_CCS;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700960 default:
961 break;
962 }
John Daiker141fa612009-03-10 06:59:54 -0700963 addr = TX_BUF_BASE + (ccsindex << 11);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700964
John Daiker141fa612009-03-10 06:59:54 -0700965 if (msg_type == DATA_TYPE) {
966 local->stats.tx_bytes += len;
967 local->stats.tx_packets++;
968 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700969
John Daiker141fa612009-03-10 06:59:54 -0700970 ptx = local->sram + addr;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700971
John Daiker141fa612009-03-10 06:59:54 -0700972 ray_build_header(local, ptx, msg_type, data);
973 if (translate) {
974 offset = translate_frame(local, ptx, data, len);
975 } else { /* Encapsulate frame */
976 /* TBD TIB length will move address of ptx->var */
977 memcpy_toio(&ptx->var, data, len);
978 offset = 0;
979 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700980
John Daiker141fa612009-03-10 06:59:54 -0700981 /* fill in the CCS */
982 pccs = ccs_base(local) + ccsindex;
983 len += TX_HEADER_LENGTH + offset;
984 writeb(CCS_TX_REQUEST, &pccs->cmd);
985 writeb(addr >> 8, &pccs->var.tx_request.tx_data_ptr[0]);
986 writeb(local->tib_length, &pccs->var.tx_request.tx_data_ptr[1]);
987 writeb(len >> 8, &pccs->var.tx_request.tx_data_length[0]);
988 writeb(len & 0xff, &pccs->var.tx_request.tx_data_length[1]);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700989/* TBD still need psm_cam? */
John Daiker141fa612009-03-10 06:59:54 -0700990 writeb(PSM_CAM, &pccs->var.tx_request.pow_sav_mode);
991 writeb(local->net_default_tx_rate, &pccs->var.tx_request.tx_rate);
992 writeb(0, &pccs->var.tx_request.antenna);
Dominik Brodowski624dd662009-10-24 15:52:44 +0200993 pr_debug("ray_hw_xmit default_tx_rate = 0x%x\n",
John Daiker141fa612009-03-10 06:59:54 -0700994 local->net_default_tx_rate);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700995
John Daiker141fa612009-03-10 06:59:54 -0700996 /* Interrupt the firmware to process the command */
997 if (interrupt_ecf(local, ccsindex)) {
Dominik Brodowski624dd662009-10-24 15:52:44 +0200998 pr_debug("ray_hw_xmit failed - ECF not ready for intr\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700999/* TBD very inefficient to copy packet to buffer, and then not
1000 send it, but the alternative is to queue the messages and that
1001 won't be done for a while. Maybe set tbusy until a CCS is free?
1002*/
John Daiker141fa612009-03-10 06:59:54 -07001003 writeb(CCS_BUFFER_FREE, &pccs->buffer_status);
1004 return XMIT_NO_INTR;
1005 }
1006 return XMIT_OK;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001007} /* end ray_hw_xmit */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001008
John Daiker141fa612009-03-10 06:59:54 -07001009/*===========================================================================*/
1010static int translate_frame(ray_dev_t *local, struct tx_msg __iomem *ptx,
1011 unsigned char *data, int len)
1012{
1013 __be16 proto = ((struct ethhdr *)data)->h_proto;
1014 if (ntohs(proto) >= 1536) { /* DIX II ethernet frame */
Dominik Brodowski624dd662009-10-24 15:52:44 +02001015 pr_debug("ray_cs translate_frame DIX II\n");
John Daiker141fa612009-03-10 06:59:54 -07001016 /* Copy LLC header to card buffer */
1017 memcpy_toio(&ptx->var, eth2_llc, sizeof(eth2_llc));
1018 memcpy_toio(((void __iomem *)&ptx->var) + sizeof(eth2_llc),
1019 (UCHAR *) &proto, 2);
1020 if (proto == htons(ETH_P_AARP) || proto == htons(ETH_P_IPX)) {
1021 /* This is the selective translation table, only 2 entries */
1022 writeb(0xf8,
1023 &((struct snaphdr_t __iomem *)ptx->var)->org[3]);
1024 }
1025 /* Copy body of ethernet packet without ethernet header */
1026 memcpy_toio((void __iomem *)&ptx->var +
1027 sizeof(struct snaphdr_t), data + ETH_HLEN,
1028 len - ETH_HLEN);
1029 return (int)sizeof(struct snaphdr_t) - ETH_HLEN;
1030 } else { /* already 802 type, and proto is length */
Dominik Brodowski624dd662009-10-24 15:52:44 +02001031 pr_debug("ray_cs translate_frame 802\n");
John Daiker141fa612009-03-10 06:59:54 -07001032 if (proto == htons(0xffff)) { /* evil netware IPX 802.3 without LLC */
Dominik Brodowski624dd662009-10-24 15:52:44 +02001033 pr_debug("ray_cs translate_frame evil IPX\n");
John Daiker141fa612009-03-10 06:59:54 -07001034 memcpy_toio(&ptx->var, data + ETH_HLEN, len - ETH_HLEN);
1035 return 0 - ETH_HLEN;
1036 }
1037 memcpy_toio(&ptx->var, data + ETH_HLEN, len - ETH_HLEN);
1038 return 0 - ETH_HLEN;
1039 }
1040 /* TBD do other frame types */
1041} /* end translate_frame */
1042
1043/*===========================================================================*/
1044static void ray_build_header(ray_dev_t *local, struct tx_msg __iomem *ptx,
1045 UCHAR msg_type, unsigned char *data)
1046{
1047 writeb(PROTOCOL_VER | msg_type, &ptx->mac.frame_ctl_1);
1048/*** IEEE 802.11 Address field assignments *************
1049 TODS FROMDS addr_1 addr_2 addr_3 addr_4
1050Adhoc 0 0 dest src (terminal) BSSID N/A
1051AP to Terminal 0 1 dest AP(BSSID) source N/A
1052Terminal to AP 1 0 AP(BSSID) src (terminal) dest N/A
1053AP to AP 1 1 dest AP src AP dest source
1054*******************************************************/
1055 if (local->net_type == ADHOC) {
1056 writeb(0, &ptx->mac.frame_ctl_2);
1057 memcpy_toio(ptx->mac.addr_1, ((struct ethhdr *)data)->h_dest,
1058 2 * ADDRLEN);
1059 memcpy_toio(ptx->mac.addr_3, local->bss_id, ADDRLEN);
1060 } else { /* infrastructure */
1061
1062 if (local->sparm.b4.a_acting_as_ap_status) {
1063 writeb(FC2_FROM_DS, &ptx->mac.frame_ctl_2);
1064 memcpy_toio(ptx->mac.addr_1,
1065 ((struct ethhdr *)data)->h_dest, ADDRLEN);
1066 memcpy_toio(ptx->mac.addr_2, local->bss_id, 6);
1067 memcpy_toio(ptx->mac.addr_3,
1068 ((struct ethhdr *)data)->h_source, ADDRLEN);
1069 } else { /* Terminal */
1070
1071 writeb(FC2_TO_DS, &ptx->mac.frame_ctl_2);
1072 memcpy_toio(ptx->mac.addr_1, local->bss_id, ADDRLEN);
1073 memcpy_toio(ptx->mac.addr_2,
1074 ((struct ethhdr *)data)->h_source, ADDRLEN);
1075 memcpy_toio(ptx->mac.addr_3,
1076 ((struct ethhdr *)data)->h_dest, ADDRLEN);
1077 }
1078 }
1079} /* end encapsulate_frame */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001080
1081/*===========================================================================*/
1082
1083static void netdev_get_drvinfo(struct net_device *dev,
1084 struct ethtool_drvinfo *info)
1085{
1086 strcpy(info->driver, "ray_cs");
1087}
1088
Jeff Garzik7282d492006-09-13 14:30:00 -04001089static const struct ethtool_ops netdev_ethtool_ops = {
John Daiker141fa612009-03-10 06:59:54 -07001090 .get_drvinfo = netdev_get_drvinfo,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001091};
1092
1093/*====================================================================*/
1094
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001095/*------------------------------------------------------------------*/
1096/*
1097 * Wireless Handler : get protocol name
1098 */
Joe Perches43ead782010-03-18 18:29:40 -07001099static int ray_get_name(struct net_device *dev, struct iw_request_info *info,
1100 union iwreq_data *wrqu, char *extra)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001101{
Joe Perches43ead782010-03-18 18:29:40 -07001102 strcpy(wrqu->name, "IEEE 802.11-FH");
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001103 return 0;
1104}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001105
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001106/*------------------------------------------------------------------*/
1107/*
1108 * Wireless Handler : set frequency
1109 */
Joe Perches43ead782010-03-18 18:29:40 -07001110static int ray_set_freq(struct net_device *dev, struct iw_request_info *info,
1111 union iwreq_data *wrqu, char *extra)
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001112{
Yoann Padioleau6dbc9c82007-08-03 19:37:16 +02001113 ray_dev_t *local = netdev_priv(dev);
John Daiker141fa612009-03-10 06:59:54 -07001114 int err = -EINPROGRESS; /* Call commit handler */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001115
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001116 /* Reject if card is already initialised */
John Daiker141fa612009-03-10 06:59:54 -07001117 if (local->card_status != CARD_AWAITING_PARAM)
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001118 return -EBUSY;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001119
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001120 /* Setting by channel number */
Joe Perches43ead782010-03-18 18:29:40 -07001121 if ((wrqu->freq.m > USA_HOP_MOD) || (wrqu->freq.e > 0))
Linus Torvalds1da177e2005-04-16 15:20:36 -07001122 err = -EOPNOTSUPP;
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001123 else
Joe Perches43ead782010-03-18 18:29:40 -07001124 local->sparm.b5.a_hop_pattern = wrqu->freq.m;
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001125
1126 return err;
1127}
John Daiker141fa612009-03-10 06:59:54 -07001128
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001129/*------------------------------------------------------------------*/
1130/*
1131 * Wireless Handler : get frequency
1132 */
Joe Perches43ead782010-03-18 18:29:40 -07001133static int ray_get_freq(struct net_device *dev, struct iw_request_info *info,
1134 union iwreq_data *wrqu, char *extra)
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001135{
Yoann Padioleau6dbc9c82007-08-03 19:37:16 +02001136 ray_dev_t *local = netdev_priv(dev);
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001137
Joe Perches43ead782010-03-18 18:29:40 -07001138 wrqu->freq.m = local->sparm.b5.a_hop_pattern;
1139 wrqu->freq.e = 0;
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001140 return 0;
1141}
1142
1143/*------------------------------------------------------------------*/
1144/*
1145 * Wireless Handler : set ESSID
1146 */
Joe Perches43ead782010-03-18 18:29:40 -07001147static int ray_set_essid(struct net_device *dev, struct iw_request_info *info,
1148 union iwreq_data *wrqu, char *extra)
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001149{
Yoann Padioleau6dbc9c82007-08-03 19:37:16 +02001150 ray_dev_t *local = netdev_priv(dev);
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001151
1152 /* Reject if card is already initialised */
John Daiker141fa612009-03-10 06:59:54 -07001153 if (local->card_status != CARD_AWAITING_PARAM)
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001154 return -EBUSY;
1155
1156 /* Check if we asked for `any' */
Joe Perches43ead782010-03-18 18:29:40 -07001157 if (wrqu->essid.flags == 0)
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001158 /* Corey : can you do that ? */
1159 return -EOPNOTSUPP;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001160
Joe Perches43ead782010-03-18 18:29:40 -07001161 /* Check the size of the string */
1162 if (wrqu->essid.length > IW_ESSID_MAX_SIZE)
1163 return -E2BIG;
1164
1165 /* Set the ESSID in the card */
1166 memset(local->sparm.b5.a_current_ess_id, 0, IW_ESSID_MAX_SIZE);
1167 memcpy(local->sparm.b5.a_current_ess_id, extra, wrqu->essid.length);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001168
John Daiker141fa612009-03-10 06:59:54 -07001169 return -EINPROGRESS; /* Call commit handler */
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001170}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001171
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001172/*------------------------------------------------------------------*/
1173/*
1174 * Wireless Handler : get ESSID
1175 */
Joe Perches43ead782010-03-18 18:29:40 -07001176static int ray_get_essid(struct net_device *dev, struct iw_request_info *info,
1177 union iwreq_data *wrqu, char *extra)
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001178{
Yoann Padioleau6dbc9c82007-08-03 19:37:16 +02001179 ray_dev_t *local = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001180
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001181 /* Get the essid that was set */
1182 memcpy(extra, local->sparm.b5.a_current_ess_id, IW_ESSID_MAX_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001183
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001184 /* Push it out ! */
Joe Perches43ead782010-03-18 18:29:40 -07001185 wrqu->essid.length = strlen(extra);
1186 wrqu->essid.flags = 1; /* active */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001187
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001188 return 0;
1189}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001190
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001191/*------------------------------------------------------------------*/
1192/*
1193 * Wireless Handler : get AP address
1194 */
Joe Perches43ead782010-03-18 18:29:40 -07001195static int ray_get_wap(struct net_device *dev, struct iw_request_info *info,
1196 union iwreq_data *wrqu, char *extra)
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001197{
Yoann Padioleau6dbc9c82007-08-03 19:37:16 +02001198 ray_dev_t *local = netdev_priv(dev);
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001199
Joe Perches43ead782010-03-18 18:29:40 -07001200 memcpy(wrqu->ap_addr.sa_data, local->bss_id, ETH_ALEN);
1201 wrqu->ap_addr.sa_family = ARPHRD_ETHER;
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001202
1203 return 0;
1204}
1205
1206/*------------------------------------------------------------------*/
1207/*
1208 * Wireless Handler : set Bit-Rate
1209 */
Joe Perches43ead782010-03-18 18:29:40 -07001210static int ray_set_rate(struct net_device *dev, struct iw_request_info *info,
1211 union iwreq_data *wrqu, char *extra)
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001212{
Yoann Padioleau6dbc9c82007-08-03 19:37:16 +02001213 ray_dev_t *local = netdev_priv(dev);
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001214
1215 /* Reject if card is already initialised */
John Daiker141fa612009-03-10 06:59:54 -07001216 if (local->card_status != CARD_AWAITING_PARAM)
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001217 return -EBUSY;
1218
1219 /* Check if rate is in range */
Joe Perches43ead782010-03-18 18:29:40 -07001220 if ((wrqu->bitrate.value != 1000000) && (wrqu->bitrate.value != 2000000))
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001221 return -EINVAL;
1222
1223 /* Hack for 1.5 Mb/s instead of 2 Mb/s */
John Daiker141fa612009-03-10 06:59:54 -07001224 if ((local->fw_ver == 0x55) && /* Please check */
Joe Perches43ead782010-03-18 18:29:40 -07001225 (wrqu->bitrate.value == 2000000))
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001226 local->net_default_tx_rate = 3;
1227 else
Joe Perches43ead782010-03-18 18:29:40 -07001228 local->net_default_tx_rate = wrqu->bitrate.value / 500000;
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001229
1230 return 0;
1231}
1232
1233/*------------------------------------------------------------------*/
1234/*
1235 * Wireless Handler : get Bit-Rate
1236 */
Joe Perches43ead782010-03-18 18:29:40 -07001237static int ray_get_rate(struct net_device *dev, struct iw_request_info *info,
1238 union iwreq_data *wrqu, char *extra)
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001239{
Yoann Padioleau6dbc9c82007-08-03 19:37:16 +02001240 ray_dev_t *local = netdev_priv(dev);
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001241
John Daiker141fa612009-03-10 06:59:54 -07001242 if (local->net_default_tx_rate == 3)
Joe Perches43ead782010-03-18 18:29:40 -07001243 wrqu->bitrate.value = 2000000; /* Hum... */
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001244 else
Joe Perches43ead782010-03-18 18:29:40 -07001245 wrqu->bitrate.value = local->net_default_tx_rate * 500000;
1246 wrqu->bitrate.fixed = 0; /* We are in auto mode */
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001247
1248 return 0;
1249}
1250
1251/*------------------------------------------------------------------*/
1252/*
1253 * Wireless Handler : set RTS threshold
1254 */
Joe Perches43ead782010-03-18 18:29:40 -07001255static int ray_set_rts(struct net_device *dev, struct iw_request_info *info,
1256 union iwreq_data *wrqu, char *extra)
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001257{
Yoann Padioleau6dbc9c82007-08-03 19:37:16 +02001258 ray_dev_t *local = netdev_priv(dev);
Joe Perches43ead782010-03-18 18:29:40 -07001259 int rthr = wrqu->rts.value;
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001260
1261 /* Reject if card is already initialised */
John Daiker141fa612009-03-10 06:59:54 -07001262 if (local->card_status != CARD_AWAITING_PARAM)
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001263 return -EBUSY;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001264
1265 /* if(wrq->u.rts.fixed == 0) we should complain */
Joe Perches43ead782010-03-18 18:29:40 -07001266 if (wrqu->rts.disabled)
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001267 rthr = 32767;
1268 else {
John Daiker141fa612009-03-10 06:59:54 -07001269 if ((rthr < 0) || (rthr > 2347)) /* What's the max packet size ??? */
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001270 return -EINVAL;
1271 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001272 local->sparm.b5.a_rts_threshold[0] = (rthr >> 8) & 0xFF;
1273 local->sparm.b5.a_rts_threshold[1] = rthr & 0xFF;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001274
John Daiker141fa612009-03-10 06:59:54 -07001275 return -EINPROGRESS; /* Call commit handler */
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001276}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001277
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001278/*------------------------------------------------------------------*/
1279/*
1280 * Wireless Handler : get RTS threshold
1281 */
Joe Perches43ead782010-03-18 18:29:40 -07001282static int ray_get_rts(struct net_device *dev, struct iw_request_info *info,
1283 union iwreq_data *wrqu, char *extra)
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001284{
Yoann Padioleau6dbc9c82007-08-03 19:37:16 +02001285 ray_dev_t *local = netdev_priv(dev);
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001286
Joe Perches43ead782010-03-18 18:29:40 -07001287 wrqu->rts.value = (local->sparm.b5.a_rts_threshold[0] << 8)
John Daiker141fa612009-03-10 06:59:54 -07001288 + local->sparm.b5.a_rts_threshold[1];
Joe Perches43ead782010-03-18 18:29:40 -07001289 wrqu->rts.disabled = (wrqu->rts.value == 32767);
1290 wrqu->rts.fixed = 1;
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001291
1292 return 0;
1293}
1294
1295/*------------------------------------------------------------------*/
1296/*
1297 * Wireless Handler : set Fragmentation threshold
1298 */
Joe Perches43ead782010-03-18 18:29:40 -07001299static int ray_set_frag(struct net_device *dev, struct iw_request_info *info,
1300 union iwreq_data *wrqu, char *extra)
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001301{
Yoann Padioleau6dbc9c82007-08-03 19:37:16 +02001302 ray_dev_t *local = netdev_priv(dev);
Joe Perches43ead782010-03-18 18:29:40 -07001303 int fthr = wrqu->frag.value;
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001304
1305 /* Reject if card is already initialised */
John Daiker141fa612009-03-10 06:59:54 -07001306 if (local->card_status != CARD_AWAITING_PARAM)
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001307 return -EBUSY;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001308
1309 /* if(wrq->u.frag.fixed == 0) should complain */
Joe Perches43ead782010-03-18 18:29:40 -07001310 if (wrqu->frag.disabled)
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001311 fthr = 32767;
1312 else {
John Daiker141fa612009-03-10 06:59:54 -07001313 if ((fthr < 256) || (fthr > 2347)) /* To check out ! */
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001314 return -EINVAL;
1315 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001316 local->sparm.b5.a_frag_threshold[0] = (fthr >> 8) & 0xFF;
1317 local->sparm.b5.a_frag_threshold[1] = fthr & 0xFF;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001318
John Daiker141fa612009-03-10 06:59:54 -07001319 return -EINPROGRESS; /* Call commit handler */
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001320}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001321
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001322/*------------------------------------------------------------------*/
1323/*
1324 * Wireless Handler : get Fragmentation threshold
1325 */
Joe Perches43ead782010-03-18 18:29:40 -07001326static int ray_get_frag(struct net_device *dev, struct iw_request_info *info,
1327 union iwreq_data *wrqu, char *extra)
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001328{
Yoann Padioleau6dbc9c82007-08-03 19:37:16 +02001329 ray_dev_t *local = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001330
Joe Perches43ead782010-03-18 18:29:40 -07001331 wrqu->frag.value = (local->sparm.b5.a_frag_threshold[0] << 8)
John Daiker141fa612009-03-10 06:59:54 -07001332 + local->sparm.b5.a_frag_threshold[1];
Joe Perches43ead782010-03-18 18:29:40 -07001333 wrqu->frag.disabled = (wrqu->frag.value == 32767);
1334 wrqu->frag.fixed = 1;
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001335
1336 return 0;
1337}
1338
1339/*------------------------------------------------------------------*/
1340/*
1341 * Wireless Handler : set Mode of Operation
1342 */
Joe Perches43ead782010-03-18 18:29:40 -07001343static int ray_set_mode(struct net_device *dev, struct iw_request_info *info,
1344 union iwreq_data *wrqu, char *extra)
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001345{
Yoann Padioleau6dbc9c82007-08-03 19:37:16 +02001346 ray_dev_t *local = netdev_priv(dev);
John Daiker141fa612009-03-10 06:59:54 -07001347 int err = -EINPROGRESS; /* Call commit handler */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001348 char card_mode = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001349
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001350 /* Reject if card is already initialised */
John Daiker141fa612009-03-10 06:59:54 -07001351 if (local->card_status != CARD_AWAITING_PARAM)
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001352 return -EBUSY;
1353
Joe Perches43ead782010-03-18 18:29:40 -07001354 switch (wrqu->mode) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001355 case IW_MODE_ADHOC:
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001356 card_mode = 0;
John Daiker141fa612009-03-10 06:59:54 -07001357 /* Fall through */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001358 case IW_MODE_INFRA:
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001359 local->sparm.b5.a_network_type = card_mode;
1360 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001361 default:
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001362 err = -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001363 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001364
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001365 return err;
1366}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001367
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001368/*------------------------------------------------------------------*/
1369/*
1370 * Wireless Handler : get Mode of Operation
1371 */
Joe Perches43ead782010-03-18 18:29:40 -07001372static int ray_get_mode(struct net_device *dev, struct iw_request_info *info,
1373 union iwreq_data *wrqu, char *extra)
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001374{
Yoann Padioleau6dbc9c82007-08-03 19:37:16 +02001375 ray_dev_t *local = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001376
John Daiker141fa612009-03-10 06:59:54 -07001377 if (local->sparm.b5.a_network_type)
Joe Perches43ead782010-03-18 18:29:40 -07001378 wrqu->mode = IW_MODE_INFRA;
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001379 else
Joe Perches43ead782010-03-18 18:29:40 -07001380 wrqu->mode = IW_MODE_ADHOC;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001381
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001382 return 0;
1383}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001384
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001385/*------------------------------------------------------------------*/
1386/*
1387 * Wireless Handler : get range info
1388 */
Joe Perches43ead782010-03-18 18:29:40 -07001389static int ray_get_range(struct net_device *dev, struct iw_request_info *info,
1390 union iwreq_data *wrqu, char *extra)
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001391{
John Daiker141fa612009-03-10 06:59:54 -07001392 struct iw_range *range = (struct iw_range *)extra;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001393
Joe Perches43ead782010-03-18 18:29:40 -07001394 memset(range, 0, sizeof(struct iw_range));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001395
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001396 /* Set the length (very important for backward compatibility) */
Joe Perches43ead782010-03-18 18:29:40 -07001397 wrqu->data.length = sizeof(struct iw_range);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001398
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001399 /* Set the Wireless Extension versions */
1400 range->we_version_compiled = WIRELESS_EXT;
1401 range->we_version_source = 9;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001402
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001403 /* Set information in the range struct */
1404 range->throughput = 1.1 * 1000 * 1000; /* Put the right number here */
John Daiker141fa612009-03-10 06:59:54 -07001405 range->num_channels = hop_pattern_length[(int)country];
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001406 range->num_frequency = 0;
1407 range->max_qual.qual = 0;
1408 range->max_qual.level = 255; /* What's the correct value ? */
1409 range->max_qual.noise = 255; /* Idem */
1410 range->num_bitrates = 2;
1411 range->bitrate[0] = 1000000; /* 1 Mb/s */
1412 range->bitrate[1] = 2000000; /* 2 Mb/s */
1413 return 0;
1414}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001415
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001416/*------------------------------------------------------------------*/
1417/*
1418 * Wireless Private Handler : set framing mode
1419 */
Joe Perches43ead782010-03-18 18:29:40 -07001420static int ray_set_framing(struct net_device *dev, struct iw_request_info *info,
John Daiker141fa612009-03-10 06:59:54 -07001421 union iwreq_data *wrqu, char *extra)
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001422{
1423 translate = *(extra); /* Set framing mode */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001424
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001425 return 0;
1426}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001427
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001428/*------------------------------------------------------------------*/
1429/*
1430 * Wireless Private Handler : get framing mode
1431 */
Joe Perches43ead782010-03-18 18:29:40 -07001432static int ray_get_framing(struct net_device *dev, struct iw_request_info *info,
John Daiker141fa612009-03-10 06:59:54 -07001433 union iwreq_data *wrqu, char *extra)
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001434{
1435 *(extra) = translate;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001436
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001437 return 0;
1438}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001439
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001440/*------------------------------------------------------------------*/
1441/*
1442 * Wireless Private Handler : get country
1443 */
Joe Perches43ead782010-03-18 18:29:40 -07001444static int ray_get_country(struct net_device *dev, struct iw_request_info *info,
John Daiker141fa612009-03-10 06:59:54 -07001445 union iwreq_data *wrqu, char *extra)
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001446{
1447 *(extra) = country;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001448
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001449 return 0;
1450}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001451
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001452/*------------------------------------------------------------------*/
1453/*
1454 * Commit handler : called after a bunch of SET operations
1455 */
Joe Perches43ead782010-03-18 18:29:40 -07001456static int ray_commit(struct net_device *dev, struct iw_request_info *info,
1457 union iwreq_data *wrqu, char *extra)
1458{
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001459 return 0;
1460}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001461
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001462/*------------------------------------------------------------------*/
1463/*
1464 * Stats handler : return Wireless Stats
1465 */
John Daiker141fa612009-03-10 06:59:54 -07001466static iw_stats *ray_get_wireless_stats(struct net_device *dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001467{
John Daiker141fa612009-03-10 06:59:54 -07001468 ray_dev_t *local = netdev_priv(dev);
1469 struct pcmcia_device *link = local->finder;
1470 struct status __iomem *p = local->sram + STATUS_BASE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001471
John Daiker141fa612009-03-10 06:59:54 -07001472 local->wstats.status = local->card_status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001473#ifdef WIRELESS_SPY
John Daiker141fa612009-03-10 06:59:54 -07001474 if ((local->spy_data.spy_number > 0)
1475 && (local->sparm.b5.a_network_type == 0)) {
1476 /* Get it from the first node in spy list */
1477 local->wstats.qual.qual = local->spy_data.spy_stat[0].qual;
1478 local->wstats.qual.level = local->spy_data.spy_stat[0].level;
1479 local->wstats.qual.noise = local->spy_data.spy_stat[0].noise;
1480 local->wstats.qual.updated =
1481 local->spy_data.spy_stat[0].updated;
1482 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001483#endif /* WIRELESS_SPY */
1484
John Daiker141fa612009-03-10 06:59:54 -07001485 if (pcmcia_dev_present(link)) {
1486 local->wstats.qual.noise = readb(&p->rxnoise);
1487 local->wstats.qual.updated |= 4;
1488 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001489
John Daiker141fa612009-03-10 06:59:54 -07001490 return &local->wstats;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001491} /* end ray_get_wireless_stats */
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001492
1493/*------------------------------------------------------------------*/
1494/*
1495 * Structures to export the Wireless Handlers
1496 */
1497
John Daiker141fa612009-03-10 06:59:54 -07001498static const iw_handler ray_handler[] = {
Joe Perches43ead782010-03-18 18:29:40 -07001499 IW_HANDLER(SIOCSIWCOMMIT, ray_commit),
1500 IW_HANDLER(SIOCGIWNAME, ray_get_name),
1501 IW_HANDLER(SIOCSIWFREQ, ray_set_freq),
1502 IW_HANDLER(SIOCGIWFREQ, ray_get_freq),
1503 IW_HANDLER(SIOCSIWMODE, ray_set_mode),
1504 IW_HANDLER(SIOCGIWMODE, ray_get_mode),
1505 IW_HANDLER(SIOCGIWRANGE, ray_get_range),
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001506#ifdef WIRELESS_SPY
Joe Perches270020e2010-03-18 18:29:37 -07001507 IW_HANDLER(SIOCSIWSPY, iw_handler_set_spy),
1508 IW_HANDLER(SIOCGIWSPY, iw_handler_get_spy),
1509 IW_HANDLER(SIOCSIWTHRSPY, iw_handler_set_thrspy),
1510 IW_HANDLER(SIOCGIWTHRSPY, iw_handler_get_thrspy),
John Daiker141fa612009-03-10 06:59:54 -07001511#endif /* WIRELESS_SPY */
Joe Perches43ead782010-03-18 18:29:40 -07001512 IW_HANDLER(SIOCGIWAP, ray_get_wap),
1513 IW_HANDLER(SIOCSIWESSID, ray_set_essid),
1514 IW_HANDLER(SIOCGIWESSID, ray_get_essid),
1515 IW_HANDLER(SIOCSIWRATE, ray_set_rate),
1516 IW_HANDLER(SIOCGIWRATE, ray_get_rate),
1517 IW_HANDLER(SIOCSIWRTS, ray_set_rts),
1518 IW_HANDLER(SIOCGIWRTS, ray_get_rts),
1519 IW_HANDLER(SIOCSIWFRAG, ray_set_frag),
1520 IW_HANDLER(SIOCGIWFRAG, ray_get_frag),
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001521};
1522
John Daiker141fa612009-03-10 06:59:54 -07001523#define SIOCSIPFRAMING SIOCIWFIRSTPRIV /* Set framing mode */
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001524#define SIOCGIPFRAMING SIOCIWFIRSTPRIV + 1 /* Get framing mode */
1525#define SIOCGIPCOUNTRY SIOCIWFIRSTPRIV + 3 /* Get country code */
1526
John Daiker141fa612009-03-10 06:59:54 -07001527static const iw_handler ray_private_handler[] = {
Joe Perches43ead782010-03-18 18:29:40 -07001528 [0] = ray_set_framing,
1529 [1] = ray_get_framing,
1530 [3] = ray_get_country,
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001531};
1532
John Daiker141fa612009-03-10 06:59:54 -07001533static const struct iw_priv_args ray_private_args[] = {
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001534/* cmd, set_args, get_args, name */
John Daiker141fa612009-03-10 06:59:54 -07001535 {SIOCSIPFRAMING, IW_PRIV_TYPE_BYTE | IW_PRIV_SIZE_FIXED | 1, 0,
1536 "set_framing"},
1537 {SIOCGIPFRAMING, 0, IW_PRIV_TYPE_BYTE | IW_PRIV_SIZE_FIXED | 1,
1538 "get_framing"},
1539 {SIOCGIPCOUNTRY, 0, IW_PRIV_TYPE_BYTE | IW_PRIV_SIZE_FIXED | 1,
1540 "get_country"},
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001541};
1542
John Daiker141fa612009-03-10 06:59:54 -07001543static const struct iw_handler_def ray_handler_def = {
1544 .num_standard = ARRAY_SIZE(ray_handler),
1545 .num_private = ARRAY_SIZE(ray_private_handler),
Denis Chengff8ac602007-09-02 18:30:18 +08001546 .num_private_args = ARRAY_SIZE(ray_private_args),
John Daiker141fa612009-03-10 06:59:54 -07001547 .standard = ray_handler,
1548 .private = ray_private_handler,
1549 .private_args = ray_private_args,
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001550 .get_wireless_stats = ray_get_wireless_stats,
1551};
1552
Linus Torvalds1da177e2005-04-16 15:20:36 -07001553/*===========================================================================*/
1554static int ray_open(struct net_device *dev)
1555{
John Daiker141fa612009-03-10 06:59:54 -07001556 ray_dev_t *local = netdev_priv(dev);
1557 struct pcmcia_device *link;
1558 link = local->finder;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001559
Dominik Brodowski624dd662009-10-24 15:52:44 +02001560 dev_dbg(&link->dev, "ray_open('%s')\n", dev->name);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001561
John Daiker141fa612009-03-10 06:59:54 -07001562 if (link->open == 0)
1563 local->num_multi = 0;
1564 link->open++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001565
John Daiker141fa612009-03-10 06:59:54 -07001566 /* If the card is not started, time to start it ! - Jean II */
1567 if (local->card_status == CARD_AWAITING_PARAM) {
1568 int i;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001569
Dominik Brodowski624dd662009-10-24 15:52:44 +02001570 dev_dbg(&link->dev, "ray_open: doing init now !\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001571
John Daiker141fa612009-03-10 06:59:54 -07001572 /* Download startup parameters */
1573 if ((i = dl_startup_params(dev)) < 0) {
1574 printk(KERN_INFO
1575 "ray_dev_init dl_startup_params failed - "
1576 "returns 0x%x\n", i);
1577 return -1;
1578 }
1579 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001580
John Daiker141fa612009-03-10 06:59:54 -07001581 if (sniffer)
1582 netif_stop_queue(dev);
1583 else
1584 netif_start_queue(dev);
1585
Dominik Brodowski624dd662009-10-24 15:52:44 +02001586 dev_dbg(&link->dev, "ray_open ending\n");
John Daiker141fa612009-03-10 06:59:54 -07001587 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001588} /* end ray_open */
John Daiker141fa612009-03-10 06:59:54 -07001589
Linus Torvalds1da177e2005-04-16 15:20:36 -07001590/*===========================================================================*/
1591static int ray_dev_close(struct net_device *dev)
1592{
John Daiker141fa612009-03-10 06:59:54 -07001593 ray_dev_t *local = netdev_priv(dev);
1594 struct pcmcia_device *link;
1595 link = local->finder;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001596
Dominik Brodowski624dd662009-10-24 15:52:44 +02001597 dev_dbg(&link->dev, "ray_dev_close('%s')\n", dev->name);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001598
John Daiker141fa612009-03-10 06:59:54 -07001599 link->open--;
1600 netif_stop_queue(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001601
John Daiker141fa612009-03-10 06:59:54 -07001602 /* In here, we should stop the hardware (stop card from beeing active)
1603 * and set local->card_status to CARD_AWAITING_PARAM, so that while the
1604 * card is closed we can chage its configuration.
1605 * Probably also need a COR reset to get sane state - Jean II */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001606
John Daiker141fa612009-03-10 06:59:54 -07001607 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001608} /* end ray_dev_close */
John Daiker141fa612009-03-10 06:59:54 -07001609
Linus Torvalds1da177e2005-04-16 15:20:36 -07001610/*===========================================================================*/
John Daiker141fa612009-03-10 06:59:54 -07001611static void ray_reset(struct net_device *dev)
1612{
Dominik Brodowski624dd662009-10-24 15:52:44 +02001613 pr_debug("ray_reset entered\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001614}
John Daiker141fa612009-03-10 06:59:54 -07001615
Linus Torvalds1da177e2005-04-16 15:20:36 -07001616/*===========================================================================*/
1617/* Cause a firmware interrupt if it is ready for one */
1618/* Return nonzero if not ready */
1619static int interrupt_ecf(ray_dev_t *local, int ccs)
1620{
John Daiker141fa612009-03-10 06:59:54 -07001621 int i = 50;
1622 struct pcmcia_device *link = local->finder;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001623
John Daiker141fa612009-03-10 06:59:54 -07001624 if (!(pcmcia_dev_present(link))) {
Dominik Brodowski624dd662009-10-24 15:52:44 +02001625 dev_dbg(&link->dev, "ray_cs interrupt_ecf - device not present\n");
John Daiker141fa612009-03-10 06:59:54 -07001626 return -1;
1627 }
Dominik Brodowski624dd662009-10-24 15:52:44 +02001628 dev_dbg(&link->dev, "interrupt_ecf(local=%p, ccs = 0x%x\n", local, ccs);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001629
John Daiker141fa612009-03-10 06:59:54 -07001630 while (i &&
1631 (readb(local->amem + CIS_OFFSET + ECF_INTR_OFFSET) &
1632 ECF_INTR_SET))
1633 i--;
1634 if (i == 0) {
Dominik Brodowski624dd662009-10-24 15:52:44 +02001635 dev_dbg(&link->dev, "ray_cs interrupt_ecf card not ready for interrupt\n");
John Daiker141fa612009-03-10 06:59:54 -07001636 return -1;
1637 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001638 /* Fill the mailbox, then kick the card */
John Daiker141fa612009-03-10 06:59:54 -07001639 writeb(ccs, local->sram + SCB_BASE);
1640 writeb(ECF_INTR_SET, local->amem + CIS_OFFSET + ECF_INTR_OFFSET);
1641 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001642} /* interrupt_ecf */
John Daiker141fa612009-03-10 06:59:54 -07001643
Linus Torvalds1da177e2005-04-16 15:20:36 -07001644/*===========================================================================*/
1645/* Get next free transmit CCS */
1646/* Return - index of current tx ccs */
1647static int get_free_tx_ccs(ray_dev_t *local)
1648{
John Daiker141fa612009-03-10 06:59:54 -07001649 int i;
1650 struct ccs __iomem *pccs = ccs_base(local);
1651 struct pcmcia_device *link = local->finder;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001652
John Daiker141fa612009-03-10 06:59:54 -07001653 if (!(pcmcia_dev_present(link))) {
Dominik Brodowski624dd662009-10-24 15:52:44 +02001654 dev_dbg(&link->dev, "ray_cs get_free_tx_ccs - device not present\n");
John Daiker141fa612009-03-10 06:59:54 -07001655 return ECARDGONE;
1656 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001657
John Daiker141fa612009-03-10 06:59:54 -07001658 if (test_and_set_bit(0, &local->tx_ccs_lock)) {
Dominik Brodowski624dd662009-10-24 15:52:44 +02001659 dev_dbg(&link->dev, "ray_cs tx_ccs_lock busy\n");
John Daiker141fa612009-03-10 06:59:54 -07001660 return ECCSBUSY;
1661 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001662
John Daiker141fa612009-03-10 06:59:54 -07001663 for (i = 0; i < NUMBER_OF_TX_CCS; i++) {
1664 if (readb(&(pccs + i)->buffer_status) == CCS_BUFFER_FREE) {
1665 writeb(CCS_BUFFER_BUSY, &(pccs + i)->buffer_status);
1666 writeb(CCS_END_LIST, &(pccs + i)->link);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001667 local->tx_ccs_lock = 0;
John Daiker141fa612009-03-10 06:59:54 -07001668 return i;
1669 }
1670 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001671 local->tx_ccs_lock = 0;
Dominik Brodowski624dd662009-10-24 15:52:44 +02001672 dev_dbg(&link->dev, "ray_cs ERROR no free tx CCS for raylink card\n");
John Daiker141fa612009-03-10 06:59:54 -07001673 return ECCSFULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001674} /* get_free_tx_ccs */
John Daiker141fa612009-03-10 06:59:54 -07001675
Linus Torvalds1da177e2005-04-16 15:20:36 -07001676/*===========================================================================*/
1677/* Get next free CCS */
1678/* Return - index of current ccs */
1679static int get_free_ccs(ray_dev_t *local)
1680{
John Daiker141fa612009-03-10 06:59:54 -07001681 int i;
1682 struct ccs __iomem *pccs = ccs_base(local);
1683 struct pcmcia_device *link = local->finder;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001684
John Daiker141fa612009-03-10 06:59:54 -07001685 if (!(pcmcia_dev_present(link))) {
Dominik Brodowski624dd662009-10-24 15:52:44 +02001686 dev_dbg(&link->dev, "ray_cs get_free_ccs - device not present\n");
John Daiker141fa612009-03-10 06:59:54 -07001687 return ECARDGONE;
1688 }
1689 if (test_and_set_bit(0, &local->ccs_lock)) {
Dominik Brodowski624dd662009-10-24 15:52:44 +02001690 dev_dbg(&link->dev, "ray_cs ccs_lock busy\n");
John Daiker141fa612009-03-10 06:59:54 -07001691 return ECCSBUSY;
1692 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001693
John Daiker141fa612009-03-10 06:59:54 -07001694 for (i = NUMBER_OF_TX_CCS; i < NUMBER_OF_CCS; i++) {
1695 if (readb(&(pccs + i)->buffer_status) == CCS_BUFFER_FREE) {
1696 writeb(CCS_BUFFER_BUSY, &(pccs + i)->buffer_status);
1697 writeb(CCS_END_LIST, &(pccs + i)->link);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001698 local->ccs_lock = 0;
John Daiker141fa612009-03-10 06:59:54 -07001699 return i;
1700 }
1701 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001702 local->ccs_lock = 0;
Dominik Brodowski624dd662009-10-24 15:52:44 +02001703 dev_dbg(&link->dev, "ray_cs ERROR no free CCS for raylink card\n");
John Daiker141fa612009-03-10 06:59:54 -07001704 return ECCSFULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001705} /* get_free_ccs */
John Daiker141fa612009-03-10 06:59:54 -07001706
Linus Torvalds1da177e2005-04-16 15:20:36 -07001707/*===========================================================================*/
1708static void authenticate_timeout(u_long data)
1709{
John Daiker141fa612009-03-10 06:59:54 -07001710 ray_dev_t *local = (ray_dev_t *) data;
1711 del_timer(&local->timer);
1712 printk(KERN_INFO "ray_cs Authentication with access point failed"
1713 " - timeout\n");
1714 join_net((u_long) local);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001715}
John Daiker141fa612009-03-10 06:59:54 -07001716
Linus Torvalds1da177e2005-04-16 15:20:36 -07001717/*===========================================================================*/
1718static int asc_to_int(char a)
1719{
John Daiker141fa612009-03-10 06:59:54 -07001720 if (a < '0')
1721 return -1;
1722 if (a <= '9')
1723 return (a - '0');
1724 if (a < 'A')
1725 return -1;
1726 if (a <= 'F')
1727 return (10 + a - 'A');
1728 if (a < 'a')
1729 return -1;
1730 if (a <= 'f')
1731 return (10 + a - 'a');
1732 return -1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001733}
John Daiker141fa612009-03-10 06:59:54 -07001734
Linus Torvalds1da177e2005-04-16 15:20:36 -07001735/*===========================================================================*/
1736static int parse_addr(char *in_str, UCHAR *out)
1737{
John Daiker141fa612009-03-10 06:59:54 -07001738 int len;
1739 int i, j, k;
1740 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001741
John Daiker141fa612009-03-10 06:59:54 -07001742 if (in_str == NULL)
1743 return 0;
1744 if ((len = strlen(in_str)) < 2)
1745 return 0;
1746 memset(out, 0, ADDRLEN);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001747
John Daiker141fa612009-03-10 06:59:54 -07001748 status = 1;
1749 j = len - 1;
1750 if (j > 12)
1751 j = 12;
1752 i = 5;
1753
1754 while (j > 0) {
1755 if ((k = asc_to_int(in_str[j--])) != -1)
1756 out[i] = k;
1757 else
1758 return 0;
1759
1760 if (j == 0)
1761 break;
1762 if ((k = asc_to_int(in_str[j--])) != -1)
1763 out[i] += k << 4;
1764 else
1765 return 0;
1766 if (!i--)
1767 break;
1768 }
1769 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001770}
John Daiker141fa612009-03-10 06:59:54 -07001771
Linus Torvalds1da177e2005-04-16 15:20:36 -07001772/*===========================================================================*/
1773static struct net_device_stats *ray_get_stats(struct net_device *dev)
1774{
John Daiker141fa612009-03-10 06:59:54 -07001775 ray_dev_t *local = netdev_priv(dev);
1776 struct pcmcia_device *link = local->finder;
1777 struct status __iomem *p = local->sram + STATUS_BASE;
1778 if (!(pcmcia_dev_present(link))) {
Dominik Brodowski624dd662009-10-24 15:52:44 +02001779 dev_dbg(&link->dev, "ray_cs net_device_stats - device not present\n");
John Daiker141fa612009-03-10 06:59:54 -07001780 return &local->stats;
1781 }
1782 if (readb(&p->mrx_overflow_for_host)) {
1783 local->stats.rx_over_errors += swab16(readw(&p->mrx_overflow));
1784 writeb(0, &p->mrx_overflow);
1785 writeb(0, &p->mrx_overflow_for_host);
1786 }
1787 if (readb(&p->mrx_checksum_error_for_host)) {
1788 local->stats.rx_crc_errors +=
1789 swab16(readw(&p->mrx_checksum_error));
1790 writeb(0, &p->mrx_checksum_error);
1791 writeb(0, &p->mrx_checksum_error_for_host);
1792 }
1793 if (readb(&p->rx_hec_error_for_host)) {
1794 local->stats.rx_frame_errors += swab16(readw(&p->rx_hec_error));
1795 writeb(0, &p->rx_hec_error);
1796 writeb(0, &p->rx_hec_error_for_host);
1797 }
1798 return &local->stats;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001799}
John Daiker141fa612009-03-10 06:59:54 -07001800
Linus Torvalds1da177e2005-04-16 15:20:36 -07001801/*===========================================================================*/
John Daiker141fa612009-03-10 06:59:54 -07001802static void ray_update_parm(struct net_device *dev, UCHAR objid, UCHAR *value,
1803 int len)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001804{
John Daiker141fa612009-03-10 06:59:54 -07001805 ray_dev_t *local = netdev_priv(dev);
1806 struct pcmcia_device *link = local->finder;
1807 int ccsindex;
1808 int i;
1809 struct ccs __iomem *pccs;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001810
John Daiker141fa612009-03-10 06:59:54 -07001811 if (!(pcmcia_dev_present(link))) {
Dominik Brodowski624dd662009-10-24 15:52:44 +02001812 dev_dbg(&link->dev, "ray_update_parm - device not present\n");
John Daiker141fa612009-03-10 06:59:54 -07001813 return;
1814 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001815
John Daiker141fa612009-03-10 06:59:54 -07001816 if ((ccsindex = get_free_ccs(local)) < 0) {
Dominik Brodowski624dd662009-10-24 15:52:44 +02001817 dev_dbg(&link->dev, "ray_update_parm - No free ccs\n");
John Daiker141fa612009-03-10 06:59:54 -07001818 return;
1819 }
1820 pccs = ccs_base(local) + ccsindex;
1821 writeb(CCS_UPDATE_PARAMS, &pccs->cmd);
1822 writeb(objid, &pccs->var.update_param.object_id);
1823 writeb(1, &pccs->var.update_param.number_objects);
1824 writeb(0, &pccs->var.update_param.failure_cause);
1825 for (i = 0; i < len; i++) {
1826 writeb(value[i], local->sram + HOST_TO_ECF_BASE);
1827 }
1828 /* Interrupt the firmware to process the command */
1829 if (interrupt_ecf(local, ccsindex)) {
Dominik Brodowski624dd662009-10-24 15:52:44 +02001830 dev_dbg(&link->dev, "ray_cs associate failed - ECF not ready for intr\n");
John Daiker141fa612009-03-10 06:59:54 -07001831 writeb(CCS_BUFFER_FREE, &(pccs++)->buffer_status);
1832 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001833}
John Daiker141fa612009-03-10 06:59:54 -07001834
Linus Torvalds1da177e2005-04-16 15:20:36 -07001835/*===========================================================================*/
1836static void ray_update_multi_list(struct net_device *dev, int all)
1837{
John Daiker141fa612009-03-10 06:59:54 -07001838 int ccsindex;
1839 struct ccs __iomem *pccs;
John Daiker141fa612009-03-10 06:59:54 -07001840 ray_dev_t *local = netdev_priv(dev);
1841 struct pcmcia_device *link = local->finder;
1842 void __iomem *p = local->sram + HOST_TO_ECF_BASE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001843
John Daiker141fa612009-03-10 06:59:54 -07001844 if (!(pcmcia_dev_present(link))) {
Dominik Brodowski624dd662009-10-24 15:52:44 +02001845 dev_dbg(&link->dev, "ray_update_multi_list - device not present\n");
John Daiker141fa612009-03-10 06:59:54 -07001846 return;
1847 } else
Dominik Brodowski624dd662009-10-24 15:52:44 +02001848 dev_dbg(&link->dev, "ray_update_multi_list(%p)\n", dev);
John Daiker141fa612009-03-10 06:59:54 -07001849 if ((ccsindex = get_free_ccs(local)) < 0) {
Dominik Brodowski624dd662009-10-24 15:52:44 +02001850 dev_dbg(&link->dev, "ray_update_multi - No free ccs\n");
John Daiker141fa612009-03-10 06:59:54 -07001851 return;
1852 }
1853 pccs = ccs_base(local) + ccsindex;
1854 writeb(CCS_UPDATE_MULTICAST_LIST, &pccs->cmd);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001855
John Daiker141fa612009-03-10 06:59:54 -07001856 if (all) {
1857 writeb(0xff, &pccs->var);
1858 local->num_multi = 0xff;
1859 } else {
Jiri Pirko22bedad32010-04-01 21:22:57 +00001860 struct netdev_hw_addr *ha;
Jiri Pirko655ffee2010-02-27 07:35:45 +00001861 int i = 0;
1862
John Daiker141fa612009-03-10 06:59:54 -07001863 /* Copy the kernel's list of MC addresses to card */
Jiri Pirko22bedad32010-04-01 21:22:57 +00001864 netdev_for_each_mc_addr(ha, dev) {
1865 memcpy_toio(p, ha->addr, ETH_ALEN);
Dominik Brodowski624dd662009-10-24 15:52:44 +02001866 dev_dbg(&link->dev,
John Daiker141fa612009-03-10 06:59:54 -07001867 "ray_update_multi add addr %02x%02x%02x%02x%02x%02x\n",
Jiri Pirko22bedad32010-04-01 21:22:57 +00001868 ha->addr[0], ha->addr[1],
1869 ha->addr[2], ha->addr[3],
1870 ha->addr[4], ha->addr[5]);
John Daiker141fa612009-03-10 06:59:54 -07001871 p += ETH_ALEN;
1872 i++;
1873 }
1874 if (i > 256 / ADDRLEN)
1875 i = 256 / ADDRLEN;
1876 writeb((UCHAR) i, &pccs->var);
Dominik Brodowski624dd662009-10-24 15:52:44 +02001877 dev_dbg(&link->dev, "ray_cs update_multi %d addresses in list\n", i);
John Daiker141fa612009-03-10 06:59:54 -07001878 /* Interrupt the firmware to process the command */
1879 local->num_multi = i;
1880 }
1881 if (interrupt_ecf(local, ccsindex)) {
Dominik Brodowski624dd662009-10-24 15:52:44 +02001882 dev_dbg(&link->dev,
John Daiker141fa612009-03-10 06:59:54 -07001883 "ray_cs update_multi failed - ECF not ready for intr\n");
1884 writeb(CCS_BUFFER_FREE, &(pccs++)->buffer_status);
1885 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001886} /* end ray_update_multi_list */
John Daiker141fa612009-03-10 06:59:54 -07001887
Linus Torvalds1da177e2005-04-16 15:20:36 -07001888/*===========================================================================*/
1889static void set_multicast_list(struct net_device *dev)
1890{
John Daiker141fa612009-03-10 06:59:54 -07001891 ray_dev_t *local = netdev_priv(dev);
1892 UCHAR promisc;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001893
Dominik Brodowski624dd662009-10-24 15:52:44 +02001894 pr_debug("ray_cs set_multicast_list(%p)\n", dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001895
John Daiker141fa612009-03-10 06:59:54 -07001896 if (dev->flags & IFF_PROMISC) {
1897 if (local->sparm.b5.a_promiscuous_mode == 0) {
Dominik Brodowski624dd662009-10-24 15:52:44 +02001898 pr_debug("ray_cs set_multicast_list promisc on\n");
John Daiker141fa612009-03-10 06:59:54 -07001899 local->sparm.b5.a_promiscuous_mode = 1;
1900 promisc = 1;
1901 ray_update_parm(dev, OBJID_promiscuous_mode,
1902 &promisc, sizeof(promisc));
1903 }
1904 } else {
1905 if (local->sparm.b5.a_promiscuous_mode == 1) {
Dominik Brodowski624dd662009-10-24 15:52:44 +02001906 pr_debug("ray_cs set_multicast_list promisc off\n");
John Daiker141fa612009-03-10 06:59:54 -07001907 local->sparm.b5.a_promiscuous_mode = 0;
1908 promisc = 0;
1909 ray_update_parm(dev, OBJID_promiscuous_mode,
1910 &promisc, sizeof(promisc));
1911 }
1912 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001913
John Daiker141fa612009-03-10 06:59:54 -07001914 if (dev->flags & IFF_ALLMULTI)
1915 ray_update_multi_list(dev, 1);
1916 else {
Jiri Pirko4cd24ea2010-02-08 04:30:35 +00001917 if (local->num_multi != netdev_mc_count(dev))
John Daiker141fa612009-03-10 06:59:54 -07001918 ray_update_multi_list(dev, 0);
1919 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001920} /* end set_multicast_list */
John Daiker141fa612009-03-10 06:59:54 -07001921
Linus Torvalds1da177e2005-04-16 15:20:36 -07001922/*=============================================================================
1923 * All routines below here are run at interrupt time.
1924=============================================================================*/
David Howells7d12e782006-10-05 14:55:46 +01001925static irqreturn_t ray_interrupt(int irq, void *dev_id)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001926{
John Daiker141fa612009-03-10 06:59:54 -07001927 struct net_device *dev = (struct net_device *)dev_id;
1928 struct pcmcia_device *link;
1929 ray_dev_t *local;
1930 struct ccs __iomem *pccs;
1931 struct rcs __iomem *prcs;
1932 UCHAR rcsindex;
1933 UCHAR tmp;
1934 UCHAR cmd;
1935 UCHAR status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001936
John Daiker141fa612009-03-10 06:59:54 -07001937 if (dev == NULL) /* Note that we want interrupts with dev->start == 0 */
1938 return IRQ_NONE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001939
Dominik Brodowski624dd662009-10-24 15:52:44 +02001940 pr_debug("ray_cs: interrupt for *dev=%p\n", dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001941
John Daiker141fa612009-03-10 06:59:54 -07001942 local = netdev_priv(dev);
1943 link = (struct pcmcia_device *)local->finder;
1944 if (!pcmcia_dev_present(link)) {
Dominik Brodowski624dd662009-10-24 15:52:44 +02001945 pr_debug(
1946 "ray_cs interrupt from device not present or suspended.\n");
John Daiker141fa612009-03-10 06:59:54 -07001947 return IRQ_NONE;
1948 }
1949 rcsindex = readb(&((struct scb __iomem *)(local->sram))->rcs_index);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001950
John Daiker141fa612009-03-10 06:59:54 -07001951 if (rcsindex >= (NUMBER_OF_CCS + NUMBER_OF_RCS)) {
Dominik Brodowski624dd662009-10-24 15:52:44 +02001952 dev_dbg(&link->dev, "ray_cs interrupt bad rcsindex = 0x%x\n", rcsindex);
John Daiker141fa612009-03-10 06:59:54 -07001953 clear_interrupt(local);
1954 return IRQ_HANDLED;
1955 }
1956 if (rcsindex < NUMBER_OF_CCS) { /* If it's a returned CCS */
1957 pccs = ccs_base(local) + rcsindex;
1958 cmd = readb(&pccs->cmd);
1959 status = readb(&pccs->buffer_status);
1960 switch (cmd) {
1961 case CCS_DOWNLOAD_STARTUP_PARAMS: /* Happens in firmware someday */
1962 del_timer(&local->timer);
1963 if (status == CCS_COMMAND_COMPLETE) {
Dominik Brodowski624dd662009-10-24 15:52:44 +02001964 dev_dbg(&link->dev,
John Daiker141fa612009-03-10 06:59:54 -07001965 "ray_cs interrupt download_startup_parameters OK\n");
1966 } else {
Dominik Brodowski624dd662009-10-24 15:52:44 +02001967 dev_dbg(&link->dev,
John Daiker141fa612009-03-10 06:59:54 -07001968 "ray_cs interrupt download_startup_parameters fail\n");
1969 }
1970 break;
1971 case CCS_UPDATE_PARAMS:
Dominik Brodowski624dd662009-10-24 15:52:44 +02001972 dev_dbg(&link->dev, "ray_cs interrupt update params done\n");
John Daiker141fa612009-03-10 06:59:54 -07001973 if (status != CCS_COMMAND_COMPLETE) {
1974 tmp =
1975 readb(&pccs->var.update_param.
1976 failure_cause);
Dominik Brodowski624dd662009-10-24 15:52:44 +02001977 dev_dbg(&link->dev,
John Daiker141fa612009-03-10 06:59:54 -07001978 "ray_cs interrupt update params failed - reason %d\n",
1979 tmp);
1980 }
1981 break;
1982 case CCS_REPORT_PARAMS:
Dominik Brodowski624dd662009-10-24 15:52:44 +02001983 dev_dbg(&link->dev, "ray_cs interrupt report params done\n");
John Daiker141fa612009-03-10 06:59:54 -07001984 break;
1985 case CCS_UPDATE_MULTICAST_LIST: /* Note that this CCS isn't returned */
Dominik Brodowski624dd662009-10-24 15:52:44 +02001986 dev_dbg(&link->dev,
John Daiker141fa612009-03-10 06:59:54 -07001987 "ray_cs interrupt CCS Update Multicast List done\n");
1988 break;
1989 case CCS_UPDATE_POWER_SAVINGS_MODE:
Dominik Brodowski624dd662009-10-24 15:52:44 +02001990 dev_dbg(&link->dev,
John Daiker141fa612009-03-10 06:59:54 -07001991 "ray_cs interrupt update power save mode done\n");
1992 break;
1993 case CCS_START_NETWORK:
1994 case CCS_JOIN_NETWORK:
1995 if (status == CCS_COMMAND_COMPLETE) {
1996 if (readb
1997 (&pccs->var.start_network.net_initiated) ==
1998 1) {
Dominik Brodowski624dd662009-10-24 15:52:44 +02001999 dev_dbg(&link->dev,
John Daiker141fa612009-03-10 06:59:54 -07002000 "ray_cs interrupt network \"%s\" started\n",
2001 local->sparm.b4.a_current_ess_id);
2002 } else {
Dominik Brodowski624dd662009-10-24 15:52:44 +02002003 dev_dbg(&link->dev,
John Daiker141fa612009-03-10 06:59:54 -07002004 "ray_cs interrupt network \"%s\" joined\n",
2005 local->sparm.b4.a_current_ess_id);
2006 }
2007 memcpy_fromio(&local->bss_id,
2008 pccs->var.start_network.bssid,
2009 ADDRLEN);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002010
John Daiker141fa612009-03-10 06:59:54 -07002011 if (local->fw_ver == 0x55)
2012 local->net_default_tx_rate = 3;
2013 else
2014 local->net_default_tx_rate =
2015 readb(&pccs->var.start_network.
2016 net_default_tx_rate);
2017 local->encryption =
2018 readb(&pccs->var.start_network.encryption);
2019 if (!sniffer && (local->net_type == INFRA)
2020 && !(local->sparm.b4.a_acting_as_ap_status)) {
2021 authenticate(local);
2022 }
2023 local->card_status = CARD_ACQ_COMPLETE;
2024 } else {
2025 local->card_status = CARD_ACQ_FAILED;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002026
John Daiker141fa612009-03-10 06:59:54 -07002027 del_timer(&local->timer);
2028 local->timer.expires = jiffies + HZ * 5;
2029 local->timer.data = (long)local;
2030 if (status == CCS_START_NETWORK) {
Dominik Brodowski624dd662009-10-24 15:52:44 +02002031 dev_dbg(&link->dev,
John Daiker141fa612009-03-10 06:59:54 -07002032 "ray_cs interrupt network \"%s\" start failed\n",
2033 local->sparm.b4.a_current_ess_id);
2034 local->timer.function = &start_net;
2035 } else {
Dominik Brodowski624dd662009-10-24 15:52:44 +02002036 dev_dbg(&link->dev,
John Daiker141fa612009-03-10 06:59:54 -07002037 "ray_cs interrupt network \"%s\" join failed\n",
2038 local->sparm.b4.a_current_ess_id);
2039 local->timer.function = &join_net;
2040 }
2041 add_timer(&local->timer);
2042 }
2043 break;
2044 case CCS_START_ASSOCIATION:
2045 if (status == CCS_COMMAND_COMPLETE) {
2046 local->card_status = CARD_ASSOC_COMPLETE;
Dominik Brodowski624dd662009-10-24 15:52:44 +02002047 dev_dbg(&link->dev, "ray_cs association successful\n");
John Daiker141fa612009-03-10 06:59:54 -07002048 } else {
Dominik Brodowski624dd662009-10-24 15:52:44 +02002049 dev_dbg(&link->dev, "ray_cs association failed,\n");
John Daiker141fa612009-03-10 06:59:54 -07002050 local->card_status = CARD_ASSOC_FAILED;
2051 join_net((u_long) local);
2052 }
2053 break;
2054 case CCS_TX_REQUEST:
2055 if (status == CCS_COMMAND_COMPLETE) {
Dominik Brodowski624dd662009-10-24 15:52:44 +02002056 dev_dbg(&link->dev,
John Daiker141fa612009-03-10 06:59:54 -07002057 "ray_cs interrupt tx request complete\n");
2058 } else {
Dominik Brodowski624dd662009-10-24 15:52:44 +02002059 dev_dbg(&link->dev,
John Daiker141fa612009-03-10 06:59:54 -07002060 "ray_cs interrupt tx request failed\n");
2061 }
2062 if (!sniffer)
2063 netif_start_queue(dev);
2064 netif_wake_queue(dev);
2065 break;
2066 case CCS_TEST_MEMORY:
Dominik Brodowski624dd662009-10-24 15:52:44 +02002067 dev_dbg(&link->dev, "ray_cs interrupt mem test done\n");
John Daiker141fa612009-03-10 06:59:54 -07002068 break;
2069 case CCS_SHUTDOWN:
Dominik Brodowski624dd662009-10-24 15:52:44 +02002070 dev_dbg(&link->dev,
John Daiker141fa612009-03-10 06:59:54 -07002071 "ray_cs interrupt Unexpected CCS returned - Shutdown\n");
2072 break;
2073 case CCS_DUMP_MEMORY:
Dominik Brodowski624dd662009-10-24 15:52:44 +02002074 dev_dbg(&link->dev, "ray_cs interrupt dump memory done\n");
John Daiker141fa612009-03-10 06:59:54 -07002075 break;
2076 case CCS_START_TIMER:
Dominik Brodowski624dd662009-10-24 15:52:44 +02002077 dev_dbg(&link->dev,
John Daiker141fa612009-03-10 06:59:54 -07002078 "ray_cs interrupt DING - raylink timer expired\n");
2079 break;
2080 default:
Dominik Brodowski624dd662009-10-24 15:52:44 +02002081 dev_dbg(&link->dev,
John Daiker141fa612009-03-10 06:59:54 -07002082 "ray_cs interrupt Unexpected CCS 0x%x returned 0x%x\n",
2083 rcsindex, cmd);
2084 }
2085 writeb(CCS_BUFFER_FREE, &pccs->buffer_status);
2086 } else { /* It's an RCS */
2087
2088 prcs = rcs_base(local) + rcsindex;
2089
2090 switch (readb(&prcs->interrupt_id)) {
2091 case PROCESS_RX_PACKET:
2092 ray_rx(dev, local, prcs);
2093 break;
2094 case REJOIN_NET_COMPLETE:
Dominik Brodowski624dd662009-10-24 15:52:44 +02002095 dev_dbg(&link->dev, "ray_cs interrupt rejoin net complete\n");
John Daiker141fa612009-03-10 06:59:54 -07002096 local->card_status = CARD_ACQ_COMPLETE;
2097 /* do we need to clear tx buffers CCS's? */
2098 if (local->sparm.b4.a_network_type == ADHOC) {
2099 if (!sniffer)
2100 netif_start_queue(dev);
2101 } else {
2102 memcpy_fromio(&local->bss_id,
2103 prcs->var.rejoin_net_complete.
2104 bssid, ADDRLEN);
Dominik Brodowski624dd662009-10-24 15:52:44 +02002105 dev_dbg(&link->dev,
John Daiker141fa612009-03-10 06:59:54 -07002106 "ray_cs new BSSID = %02x%02x%02x%02x%02x%02x\n",
2107 local->bss_id[0], local->bss_id[1],
2108 local->bss_id[2], local->bss_id[3],
2109 local->bss_id[4], local->bss_id[5]);
2110 if (!sniffer)
2111 authenticate(local);
2112 }
2113 break;
2114 case ROAMING_INITIATED:
Dominik Brodowski624dd662009-10-24 15:52:44 +02002115 dev_dbg(&link->dev, "ray_cs interrupt roaming initiated\n");
John Daiker141fa612009-03-10 06:59:54 -07002116 netif_stop_queue(dev);
2117 local->card_status = CARD_DOING_ACQ;
2118 break;
2119 case JAPAN_CALL_SIGN_RXD:
Dominik Brodowski624dd662009-10-24 15:52:44 +02002120 dev_dbg(&link->dev, "ray_cs interrupt japan call sign rx\n");
John Daiker141fa612009-03-10 06:59:54 -07002121 break;
2122 default:
Dominik Brodowski624dd662009-10-24 15:52:44 +02002123 dev_dbg(&link->dev,
John Daiker141fa612009-03-10 06:59:54 -07002124 "ray_cs Unexpected interrupt for RCS 0x%x cmd = 0x%x\n",
2125 rcsindex,
2126 (unsigned int)readb(&prcs->interrupt_id));
2127 break;
2128 }
2129 writeb(CCS_BUFFER_FREE, &prcs->buffer_status);
2130 }
2131 clear_interrupt(local);
2132 return IRQ_HANDLED;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002133} /* ray_interrupt */
John Daiker141fa612009-03-10 06:59:54 -07002134
Linus Torvalds1da177e2005-04-16 15:20:36 -07002135/*===========================================================================*/
John Daiker141fa612009-03-10 06:59:54 -07002136static void ray_rx(struct net_device *dev, ray_dev_t *local,
2137 struct rcs __iomem *prcs)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002138{
John Daiker141fa612009-03-10 06:59:54 -07002139 int rx_len;
2140 unsigned int pkt_addr;
2141 void __iomem *pmsg;
Dominik Brodowski624dd662009-10-24 15:52:44 +02002142 pr_debug("ray_rx process rx packet\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002143
John Daiker141fa612009-03-10 06:59:54 -07002144 /* Calculate address of packet within Rx buffer */
2145 pkt_addr = ((readb(&prcs->var.rx_packet.rx_data_ptr[0]) << 8)
2146 + readb(&prcs->var.rx_packet.rx_data_ptr[1])) & RX_BUFF_END;
2147 /* Length of first packet fragment */
2148 rx_len = (readb(&prcs->var.rx_packet.rx_data_length[0]) << 8)
2149 + readb(&prcs->var.rx_packet.rx_data_length[1]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002150
John Daiker141fa612009-03-10 06:59:54 -07002151 local->last_rsl = readb(&prcs->var.rx_packet.rx_sig_lev);
2152 pmsg = local->rmem + pkt_addr;
2153 switch (readb(pmsg)) {
2154 case DATA_TYPE:
Dominik Brodowski624dd662009-10-24 15:52:44 +02002155 pr_debug("ray_rx data type\n");
John Daiker141fa612009-03-10 06:59:54 -07002156 rx_data(dev, prcs, pkt_addr, rx_len);
2157 break;
2158 case AUTHENTIC_TYPE:
Dominik Brodowski624dd662009-10-24 15:52:44 +02002159 pr_debug("ray_rx authentic type\n");
John Daiker141fa612009-03-10 06:59:54 -07002160 if (sniffer)
2161 rx_data(dev, prcs, pkt_addr, rx_len);
2162 else
2163 rx_authenticate(local, prcs, pkt_addr, rx_len);
2164 break;
2165 case DEAUTHENTIC_TYPE:
Dominik Brodowski624dd662009-10-24 15:52:44 +02002166 pr_debug("ray_rx deauth type\n");
John Daiker141fa612009-03-10 06:59:54 -07002167 if (sniffer)
2168 rx_data(dev, prcs, pkt_addr, rx_len);
2169 else
2170 rx_deauthenticate(local, prcs, pkt_addr, rx_len);
2171 break;
2172 case NULL_MSG_TYPE:
Dominik Brodowski624dd662009-10-24 15:52:44 +02002173 pr_debug("ray_cs rx NULL msg\n");
John Daiker141fa612009-03-10 06:59:54 -07002174 break;
2175 case BEACON_TYPE:
Dominik Brodowski624dd662009-10-24 15:52:44 +02002176 pr_debug("ray_rx beacon type\n");
John Daiker141fa612009-03-10 06:59:54 -07002177 if (sniffer)
2178 rx_data(dev, prcs, pkt_addr, rx_len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002179
John Daiker141fa612009-03-10 06:59:54 -07002180 copy_from_rx_buff(local, (UCHAR *) &local->last_bcn, pkt_addr,
2181 rx_len < sizeof(struct beacon_rx) ?
2182 rx_len : sizeof(struct beacon_rx));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002183
John Daiker141fa612009-03-10 06:59:54 -07002184 local->beacon_rxed = 1;
2185 /* Get the statistics so the card counters never overflow */
2186 ray_get_stats(dev);
2187 break;
2188 default:
Dominik Brodowski624dd662009-10-24 15:52:44 +02002189 pr_debug("ray_cs unknown pkt type %2x\n",
John Daiker141fa612009-03-10 06:59:54 -07002190 (unsigned int)readb(pmsg));
2191 break;
2192 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002193
2194} /* end ray_rx */
John Daiker141fa612009-03-10 06:59:54 -07002195
Linus Torvalds1da177e2005-04-16 15:20:36 -07002196/*===========================================================================*/
John Daiker141fa612009-03-10 06:59:54 -07002197static void rx_data(struct net_device *dev, struct rcs __iomem *prcs,
2198 unsigned int pkt_addr, int rx_len)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002199{
John Daiker141fa612009-03-10 06:59:54 -07002200 struct sk_buff *skb = NULL;
2201 struct rcs __iomem *prcslink = prcs;
2202 ray_dev_t *local = netdev_priv(dev);
2203 UCHAR *rx_ptr;
2204 int total_len;
2205 int tmp;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002206#ifdef WIRELESS_SPY
John Daiker141fa612009-03-10 06:59:54 -07002207 int siglev = local->last_rsl;
2208 u_char linksrcaddr[ETH_ALEN]; /* Other end of the wireless link */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002209#endif
2210
John Daiker141fa612009-03-10 06:59:54 -07002211 if (!sniffer) {
2212 if (translate) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002213/* TBD length needs fixing for translated header */
John Daiker141fa612009-03-10 06:59:54 -07002214 if (rx_len < (ETH_HLEN + RX_MAC_HEADER_LENGTH) ||
2215 rx_len >
2216 (dev->mtu + RX_MAC_HEADER_LENGTH + ETH_HLEN +
2217 FCS_LEN)) {
Dominik Brodowski624dd662009-10-24 15:52:44 +02002218 pr_debug(
Frans Popcb01b092010-03-24 19:46:34 +01002219 "ray_cs invalid packet length %d received\n",
John Daiker141fa612009-03-10 06:59:54 -07002220 rx_len);
2221 return;
2222 }
2223 } else { /* encapsulated ethernet */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002224
John Daiker141fa612009-03-10 06:59:54 -07002225 if (rx_len < (ETH_HLEN + RX_MAC_HEADER_LENGTH) ||
2226 rx_len >
2227 (dev->mtu + RX_MAC_HEADER_LENGTH + ETH_HLEN +
2228 FCS_LEN)) {
Dominik Brodowski624dd662009-10-24 15:52:44 +02002229 pr_debug(
Frans Popcb01b092010-03-24 19:46:34 +01002230 "ray_cs invalid packet length %d received\n",
John Daiker141fa612009-03-10 06:59:54 -07002231 rx_len);
2232 return;
2233 }
2234 }
2235 }
Dominik Brodowski624dd662009-10-24 15:52:44 +02002236 pr_debug("ray_cs rx_data packet\n");
John Daiker141fa612009-03-10 06:59:54 -07002237 /* If fragmented packet, verify sizes of fragments add up */
2238 if (readb(&prcs->var.rx_packet.next_frag_rcs_index) != 0xFF) {
Dominik Brodowski624dd662009-10-24 15:52:44 +02002239 pr_debug("ray_cs rx'ed fragment\n");
John Daiker141fa612009-03-10 06:59:54 -07002240 tmp = (readb(&prcs->var.rx_packet.totalpacketlength[0]) << 8)
2241 + readb(&prcs->var.rx_packet.totalpacketlength[1]);
2242 total_len = tmp;
2243 prcslink = prcs;
2244 do {
2245 tmp -=
2246 (readb(&prcslink->var.rx_packet.rx_data_length[0])
2247 << 8)
2248 + readb(&prcslink->var.rx_packet.rx_data_length[1]);
2249 if (readb(&prcslink->var.rx_packet.next_frag_rcs_index)
2250 == 0xFF || tmp < 0)
2251 break;
2252 prcslink = rcs_base(local)
2253 + readb(&prcslink->link_field);
2254 } while (1);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002255
John Daiker141fa612009-03-10 06:59:54 -07002256 if (tmp < 0) {
Dominik Brodowski624dd662009-10-24 15:52:44 +02002257 pr_debug(
John Daiker141fa612009-03-10 06:59:54 -07002258 "ray_cs rx_data fragment lengths don't add up\n");
2259 local->stats.rx_dropped++;
2260 release_frag_chain(local, prcs);
2261 return;
2262 }
2263 } else { /* Single unfragmented packet */
2264 total_len = rx_len;
2265 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002266
John Daiker141fa612009-03-10 06:59:54 -07002267 skb = dev_alloc_skb(total_len + 5);
2268 if (skb == NULL) {
Dominik Brodowski624dd662009-10-24 15:52:44 +02002269 pr_debug("ray_cs rx_data could not allocate skb\n");
John Daiker141fa612009-03-10 06:59:54 -07002270 local->stats.rx_dropped++;
2271 if (readb(&prcs->var.rx_packet.next_frag_rcs_index) != 0xFF)
2272 release_frag_chain(local, prcs);
2273 return;
2274 }
2275 skb_reserve(skb, 2); /* Align IP on 16 byte (TBD check this) */
2276
Dominik Brodowski624dd662009-10-24 15:52:44 +02002277 pr_debug("ray_cs rx_data total_len = %x, rx_len = %x\n", total_len,
John Daiker141fa612009-03-10 06:59:54 -07002278 rx_len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002279
2280/************************/
John Daiker141fa612009-03-10 06:59:54 -07002281 /* Reserve enough room for the whole damn packet. */
2282 rx_ptr = skb_put(skb, total_len);
2283 /* Copy the whole packet to sk_buff */
2284 rx_ptr +=
2285 copy_from_rx_buff(local, rx_ptr, pkt_addr & RX_BUFF_END, rx_len);
2286 /* Get source address */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002287#ifdef WIRELESS_SPY
John Daiker141fa612009-03-10 06:59:54 -07002288 skb_copy_from_linear_data_offset(skb,
2289 offsetof(struct mac_header, addr_2),
2290 linksrcaddr, ETH_ALEN);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002291#endif
John Daiker141fa612009-03-10 06:59:54 -07002292 /* Now, deal with encapsulation/translation/sniffer */
2293 if (!sniffer) {
2294 if (!translate) {
2295 /* Encapsulated ethernet, so just lop off 802.11 MAC header */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002296/* TBD reserve skb_reserve( skb, RX_MAC_HEADER_LENGTH); */
John Daiker141fa612009-03-10 06:59:54 -07002297 skb_pull(skb, RX_MAC_HEADER_LENGTH);
2298 } else {
2299 /* Do translation */
2300 untranslate(local, skb, total_len);
2301 }
2302 } else { /* sniffer mode, so just pass whole packet */
2303 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002304
2305/************************/
John Daiker141fa612009-03-10 06:59:54 -07002306 /* Now pick up the rest of the fragments if any */
2307 tmp = 17;
2308 if (readb(&prcs->var.rx_packet.next_frag_rcs_index) != 0xFF) {
2309 prcslink = prcs;
Dominik Brodowski624dd662009-10-24 15:52:44 +02002310 pr_debug("ray_cs rx_data in fragment loop\n");
John Daiker141fa612009-03-10 06:59:54 -07002311 do {
2312 prcslink = rcs_base(local)
2313 +
2314 readb(&prcslink->var.rx_packet.next_frag_rcs_index);
2315 rx_len =
2316 ((readb(&prcslink->var.rx_packet.rx_data_length[0])
2317 << 8)
2318 +
2319 readb(&prcslink->var.rx_packet.rx_data_length[1]))
2320 & RX_BUFF_END;
2321 pkt_addr =
2322 ((readb(&prcslink->var.rx_packet.rx_data_ptr[0]) <<
2323 8)
2324 + readb(&prcslink->var.rx_packet.rx_data_ptr[1]))
2325 & RX_BUFF_END;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002326
John Daiker141fa612009-03-10 06:59:54 -07002327 rx_ptr +=
2328 copy_from_rx_buff(local, rx_ptr, pkt_addr, rx_len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002329
John Daiker141fa612009-03-10 06:59:54 -07002330 } while (tmp-- &&
2331 readb(&prcslink->var.rx_packet.next_frag_rcs_index) !=
2332 0xFF);
2333 release_frag_chain(local, prcs);
2334 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002335
John Daiker141fa612009-03-10 06:59:54 -07002336 skb->protocol = eth_type_trans(skb, dev);
2337 netif_rx(skb);
2338 local->stats.rx_packets++;
2339 local->stats.rx_bytes += total_len;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002340
John Daiker141fa612009-03-10 06:59:54 -07002341 /* Gather signal strength per address */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002342#ifdef WIRELESS_SPY
John Daiker141fa612009-03-10 06:59:54 -07002343 /* For the Access Point or the node having started the ad-hoc net
2344 * note : ad-hoc work only in some specific configurations, but we
2345 * kludge in ray_get_wireless_stats... */
2346 if (!memcmp(linksrcaddr, local->bss_id, ETH_ALEN)) {
2347 /* Update statistics */
2348 /*local->wstats.qual.qual = none ? */
2349 local->wstats.qual.level = siglev;
2350 /*local->wstats.qual.noise = none ? */
2351 local->wstats.qual.updated = 0x2;
2352 }
2353 /* Now, update the spy stuff */
2354 {
2355 struct iw_quality wstats;
2356 wstats.level = siglev;
2357 /* wstats.noise = none ? */
2358 /* wstats.qual = none ? */
2359 wstats.updated = 0x2;
2360 /* Update spy records */
2361 wireless_spy_update(dev, linksrcaddr, &wstats);
2362 }
2363#endif /* WIRELESS_SPY */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002364} /* end rx_data */
John Daiker141fa612009-03-10 06:59:54 -07002365
Linus Torvalds1da177e2005-04-16 15:20:36 -07002366/*===========================================================================*/
2367static void untranslate(ray_dev_t *local, struct sk_buff *skb, int len)
2368{
John Daiker141fa612009-03-10 06:59:54 -07002369 snaphdr_t *psnap = (snaphdr_t *) (skb->data + RX_MAC_HEADER_LENGTH);
2370 struct ieee80211_hdr *pmac = (struct ieee80211_hdr *)skb->data;
2371 __be16 type = *(__be16 *) psnap->ethertype;
2372 int delta;
2373 struct ethhdr *peth;
2374 UCHAR srcaddr[ADDRLEN];
2375 UCHAR destaddr[ADDRLEN];
2376 static UCHAR org_bridge[3] = { 0, 0, 0xf8 };
2377 static UCHAR org_1042[3] = { 0, 0, 0 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002378
John Daiker141fa612009-03-10 06:59:54 -07002379 memcpy(destaddr, ieee80211_get_DA(pmac), ADDRLEN);
2380 memcpy(srcaddr, ieee80211_get_SA(pmac), ADDRLEN);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002381
Dominik Brodowski624dd662009-10-24 15:52:44 +02002382#if 0
2383 if {
Joe Perchesad361c92009-07-06 13:05:40 -07002384 print_hex_dump(KERN_DEBUG, "skb->data before untranslate: ",
2385 DUMP_PREFIX_NONE, 16, 1,
2386 skb->data, 64, true);
2387 printk(KERN_DEBUG
John Daiker141fa612009-03-10 06:59:54 -07002388 "type = %08x, xsap = %02x%02x%02x, org = %02x02x02x\n",
2389 ntohs(type), psnap->dsap, psnap->ssap, psnap->ctrl,
2390 psnap->org[0], psnap->org[1], psnap->org[2]);
2391 printk(KERN_DEBUG "untranslate skb->data = %p\n", skb->data);
2392 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002393#endif
2394
John Daiker141fa612009-03-10 06:59:54 -07002395 if (psnap->dsap != 0xaa || psnap->ssap != 0xaa || psnap->ctrl != 3) {
2396 /* not a snap type so leave it alone */
Dominik Brodowski624dd662009-10-24 15:52:44 +02002397 pr_debug("ray_cs untranslate NOT SNAP %02x %02x %02x\n",
John Daiker141fa612009-03-10 06:59:54 -07002398 psnap->dsap, psnap->ssap, psnap->ctrl);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002399
John Daiker141fa612009-03-10 06:59:54 -07002400 delta = RX_MAC_HEADER_LENGTH - ETH_HLEN;
2401 peth = (struct ethhdr *)(skb->data + delta);
2402 peth->h_proto = htons(len - RX_MAC_HEADER_LENGTH);
2403 } else { /* Its a SNAP */
2404 if (memcmp(psnap->org, org_bridge, 3) == 0) {
2405 /* EtherII and nuke the LLC */
Dominik Brodowski624dd662009-10-24 15:52:44 +02002406 pr_debug("ray_cs untranslate Bridge encap\n");
John Daiker141fa612009-03-10 06:59:54 -07002407 delta = RX_MAC_HEADER_LENGTH
2408 + sizeof(struct snaphdr_t) - ETH_HLEN;
2409 peth = (struct ethhdr *)(skb->data + delta);
2410 peth->h_proto = type;
2411 } else if (memcmp(psnap->org, org_1042, 3) == 0) {
2412 switch (ntohs(type)) {
2413 case ETH_P_IPX:
2414 case ETH_P_AARP:
Dominik Brodowski624dd662009-10-24 15:52:44 +02002415 pr_debug("ray_cs untranslate RFC IPX/AARP\n");
John Daiker141fa612009-03-10 06:59:54 -07002416 delta = RX_MAC_HEADER_LENGTH - ETH_HLEN;
2417 peth = (struct ethhdr *)(skb->data + delta);
2418 peth->h_proto =
2419 htons(len - RX_MAC_HEADER_LENGTH);
2420 break;
2421 default:
Dominik Brodowski624dd662009-10-24 15:52:44 +02002422 pr_debug("ray_cs untranslate RFC default\n");
John Daiker141fa612009-03-10 06:59:54 -07002423 delta = RX_MAC_HEADER_LENGTH +
2424 sizeof(struct snaphdr_t) - ETH_HLEN;
2425 peth = (struct ethhdr *)(skb->data + delta);
2426 peth->h_proto = type;
2427 break;
2428 }
2429 } else {
2430 printk("ray_cs untranslate very confused by packet\n");
2431 delta = RX_MAC_HEADER_LENGTH - ETH_HLEN;
2432 peth = (struct ethhdr *)(skb->data + delta);
2433 peth->h_proto = type;
2434 }
Al Viro7698d692007-12-29 04:55:50 -05002435 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002436/* TBD reserve skb_reserve(skb, delta); */
John Daiker141fa612009-03-10 06:59:54 -07002437 skb_pull(skb, delta);
Dominik Brodowski624dd662009-10-24 15:52:44 +02002438 pr_debug("untranslate after skb_pull(%d), skb->data = %p\n", delta,
John Daiker141fa612009-03-10 06:59:54 -07002439 skb->data);
2440 memcpy(peth->h_dest, destaddr, ADDRLEN);
2441 memcpy(peth->h_source, srcaddr, ADDRLEN);
Dominik Brodowski624dd662009-10-24 15:52:44 +02002442#if 0
2443 {
John Daiker141fa612009-03-10 06:59:54 -07002444 int i;
2445 printk(KERN_DEBUG "skb->data after untranslate:");
2446 for (i = 0; i < 64; i++)
2447 printk("%02x ", skb->data[i]);
2448 printk("\n");
2449 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002450#endif
2451} /* end untranslate */
John Daiker141fa612009-03-10 06:59:54 -07002452
Linus Torvalds1da177e2005-04-16 15:20:36 -07002453/*===========================================================================*/
2454/* Copy data from circular receive buffer to PC memory.
2455 * dest = destination address in PC memory
2456 * pkt_addr = source address in receive buffer
2457 * len = length of packet to copy
2458 */
John Daiker141fa612009-03-10 06:59:54 -07002459static int copy_from_rx_buff(ray_dev_t *local, UCHAR *dest, int pkt_addr,
2460 int length)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002461{
John Daiker141fa612009-03-10 06:59:54 -07002462 int wrap_bytes = (pkt_addr + length) - (RX_BUFF_END + 1);
2463 if (wrap_bytes <= 0) {
2464 memcpy_fromio(dest, local->rmem + pkt_addr, length);
2465 } else { /* Packet wrapped in circular buffer */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002466
John Daiker141fa612009-03-10 06:59:54 -07002467 memcpy_fromio(dest, local->rmem + pkt_addr,
2468 length - wrap_bytes);
2469 memcpy_fromio(dest + length - wrap_bytes, local->rmem,
2470 wrap_bytes);
2471 }
2472 return length;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002473}
John Daiker141fa612009-03-10 06:59:54 -07002474
2475/*===========================================================================*/
2476static void release_frag_chain(ray_dev_t *local, struct rcs __iomem *prcs)
2477{
2478 struct rcs __iomem *prcslink = prcs;
2479 int tmp = 17;
2480 unsigned rcsindex = readb(&prcs->var.rx_packet.next_frag_rcs_index);
2481
2482 while (tmp--) {
2483 writeb(CCS_BUFFER_FREE, &prcslink->buffer_status);
2484 if (rcsindex >= (NUMBER_OF_CCS + NUMBER_OF_RCS)) {
Dominik Brodowski624dd662009-10-24 15:52:44 +02002485 pr_debug("ray_cs interrupt bad rcsindex = 0x%x\n",
John Daiker141fa612009-03-10 06:59:54 -07002486 rcsindex);
2487 break;
2488 }
2489 prcslink = rcs_base(local) + rcsindex;
2490 rcsindex = readb(&prcslink->var.rx_packet.next_frag_rcs_index);
2491 }
2492 writeb(CCS_BUFFER_FREE, &prcslink->buffer_status);
2493}
2494
Linus Torvalds1da177e2005-04-16 15:20:36 -07002495/*===========================================================================*/
2496static void authenticate(ray_dev_t *local)
2497{
John Daiker141fa612009-03-10 06:59:54 -07002498 struct pcmcia_device *link = local->finder;
Dominik Brodowski624dd662009-10-24 15:52:44 +02002499 dev_dbg(&link->dev, "ray_cs Starting authentication.\n");
John Daiker141fa612009-03-10 06:59:54 -07002500 if (!(pcmcia_dev_present(link))) {
Dominik Brodowski624dd662009-10-24 15:52:44 +02002501 dev_dbg(&link->dev, "ray_cs authenticate - device not present\n");
John Daiker141fa612009-03-10 06:59:54 -07002502 return;
2503 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002504
John Daiker141fa612009-03-10 06:59:54 -07002505 del_timer(&local->timer);
2506 if (build_auth_frame(local, local->bss_id, OPEN_AUTH_REQUEST)) {
2507 local->timer.function = &join_net;
2508 } else {
2509 local->timer.function = &authenticate_timeout;
2510 }
2511 local->timer.expires = jiffies + HZ * 2;
2512 local->timer.data = (long)local;
2513 add_timer(&local->timer);
2514 local->authentication_state = AWAITING_RESPONSE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002515} /* end authenticate */
John Daiker141fa612009-03-10 06:59:54 -07002516
Linus Torvalds1da177e2005-04-16 15:20:36 -07002517/*===========================================================================*/
2518static void rx_authenticate(ray_dev_t *local, struct rcs __iomem *prcs,
John Daiker141fa612009-03-10 06:59:54 -07002519 unsigned int pkt_addr, int rx_len)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002520{
John Daiker141fa612009-03-10 06:59:54 -07002521 UCHAR buff[256];
2522 struct rx_msg *msg = (struct rx_msg *)buff;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002523
John Daiker141fa612009-03-10 06:59:54 -07002524 del_timer(&local->timer);
2525
2526 copy_from_rx_buff(local, buff, pkt_addr, rx_len & 0xff);
2527 /* if we are trying to get authenticated */
2528 if (local->sparm.b4.a_network_type == ADHOC) {
Dominik Brodowski624dd662009-10-24 15:52:44 +02002529 pr_debug("ray_cs rx_auth var= %02x %02x %02x %02x %02x %02x\n",
John Daiker141fa612009-03-10 06:59:54 -07002530 msg->var[0], msg->var[1], msg->var[2], msg->var[3],
2531 msg->var[4], msg->var[5]);
2532 if (msg->var[2] == 1) {
Dominik Brodowski624dd662009-10-24 15:52:44 +02002533 pr_debug("ray_cs Sending authentication response.\n");
John Daiker141fa612009-03-10 06:59:54 -07002534 if (!build_auth_frame
2535 (local, msg->mac.addr_2, OPEN_AUTH_RESPONSE)) {
2536 local->authentication_state = NEED_TO_AUTH;
2537 memcpy(local->auth_id, msg->mac.addr_2,
2538 ADDRLEN);
2539 }
2540 }
2541 } else { /* Infrastructure network */
2542
2543 if (local->authentication_state == AWAITING_RESPONSE) {
2544 /* Verify authentication sequence #2 and success */
2545 if (msg->var[2] == 2) {
2546 if ((msg->var[3] | msg->var[4]) == 0) {
Dominik Brodowski624dd662009-10-24 15:52:44 +02002547 pr_debug("Authentication successful\n");
John Daiker141fa612009-03-10 06:59:54 -07002548 local->card_status = CARD_AUTH_COMPLETE;
2549 associate(local);
2550 local->authentication_state =
2551 AUTHENTICATED;
2552 } else {
Dominik Brodowski624dd662009-10-24 15:52:44 +02002553 pr_debug("Authentication refused\n");
John Daiker141fa612009-03-10 06:59:54 -07002554 local->card_status = CARD_AUTH_REFUSED;
2555 join_net((u_long) local);
2556 local->authentication_state =
2557 UNAUTHENTICATED;
2558 }
2559 }
2560 }
2561 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002562
2563} /* end rx_authenticate */
John Daiker141fa612009-03-10 06:59:54 -07002564
Linus Torvalds1da177e2005-04-16 15:20:36 -07002565/*===========================================================================*/
2566static void associate(ray_dev_t *local)
2567{
John Daiker141fa612009-03-10 06:59:54 -07002568 struct ccs __iomem *pccs;
2569 struct pcmcia_device *link = local->finder;
2570 struct net_device *dev = link->priv;
2571 int ccsindex;
2572 if (!(pcmcia_dev_present(link))) {
Dominik Brodowski624dd662009-10-24 15:52:44 +02002573 dev_dbg(&link->dev, "ray_cs associate - device not present\n");
John Daiker141fa612009-03-10 06:59:54 -07002574 return;
2575 }
2576 /* If no tx buffers available, return */
2577 if ((ccsindex = get_free_ccs(local)) < 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002578/* TBD should never be here but... what if we are? */
Dominik Brodowski624dd662009-10-24 15:52:44 +02002579 dev_dbg(&link->dev, "ray_cs associate - No free ccs\n");
John Daiker141fa612009-03-10 06:59:54 -07002580 return;
2581 }
Dominik Brodowski624dd662009-10-24 15:52:44 +02002582 dev_dbg(&link->dev, "ray_cs Starting association with access point\n");
John Daiker141fa612009-03-10 06:59:54 -07002583 pccs = ccs_base(local) + ccsindex;
2584 /* fill in the CCS */
2585 writeb(CCS_START_ASSOCIATION, &pccs->cmd);
2586 /* Interrupt the firmware to process the command */
2587 if (interrupt_ecf(local, ccsindex)) {
Dominik Brodowski624dd662009-10-24 15:52:44 +02002588 dev_dbg(&link->dev, "ray_cs associate failed - ECF not ready for intr\n");
John Daiker141fa612009-03-10 06:59:54 -07002589 writeb(CCS_BUFFER_FREE, &(pccs++)->buffer_status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002590
John Daiker141fa612009-03-10 06:59:54 -07002591 del_timer(&local->timer);
2592 local->timer.expires = jiffies + HZ * 2;
2593 local->timer.data = (long)local;
2594 local->timer.function = &join_net;
2595 add_timer(&local->timer);
2596 local->card_status = CARD_ASSOC_FAILED;
2597 return;
2598 }
2599 if (!sniffer)
2600 netif_start_queue(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002601
2602} /* end associate */
John Daiker141fa612009-03-10 06:59:54 -07002603
Linus Torvalds1da177e2005-04-16 15:20:36 -07002604/*===========================================================================*/
John Daiker141fa612009-03-10 06:59:54 -07002605static void rx_deauthenticate(ray_dev_t *local, struct rcs __iomem *prcs,
2606 unsigned int pkt_addr, int rx_len)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002607{
2608/* UCHAR buff[256];
2609 struct rx_msg *msg = (struct rx_msg *)buff;
2610*/
Dominik Brodowski624dd662009-10-24 15:52:44 +02002611 pr_debug("Deauthentication frame received\n");
John Daiker141fa612009-03-10 06:59:54 -07002612 local->authentication_state = UNAUTHENTICATED;
2613 /* Need to reauthenticate or rejoin depending on reason code */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002614/* copy_from_rx_buff(local, buff, pkt_addr, rx_len & 0xff);
2615 */
2616}
John Daiker141fa612009-03-10 06:59:54 -07002617
Linus Torvalds1da177e2005-04-16 15:20:36 -07002618/*===========================================================================*/
2619static void clear_interrupt(ray_dev_t *local)
2620{
John Daiker141fa612009-03-10 06:59:54 -07002621 writeb(0, local->amem + CIS_OFFSET + HCS_INTR_OFFSET);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002622}
John Daiker141fa612009-03-10 06:59:54 -07002623
Linus Torvalds1da177e2005-04-16 15:20:36 -07002624/*===========================================================================*/
2625#ifdef CONFIG_PROC_FS
2626#define MAXDATA (PAGE_SIZE - 80)
2627
2628static char *card_status[] = {
John Daiker141fa612009-03-10 06:59:54 -07002629 "Card inserted - uninitialized", /* 0 */
2630 "Card not downloaded", /* 1 */
2631 "Waiting for download parameters", /* 2 */
2632 "Card doing acquisition", /* 3 */
2633 "Acquisition complete", /* 4 */
2634 "Authentication complete", /* 5 */
2635 "Association complete", /* 6 */
2636 "???", "???", "???", "???", /* 7 8 9 10 undefined */
2637 "Card init error", /* 11 */
2638 "Download parameters error", /* 12 */
2639 "???", /* 13 */
2640 "Acquisition failed", /* 14 */
2641 "Authentication refused", /* 15 */
2642 "Association failed" /* 16 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002643};
2644
John Daiker141fa612009-03-10 06:59:54 -07002645static char *nettype[] = { "Adhoc", "Infra " };
2646static char *framing[] = { "Encapsulation", "Translation" }
2647
Linus Torvalds1da177e2005-04-16 15:20:36 -07002648;
2649/*===========================================================================*/
Alexey Dobriyan6b914c52008-04-10 14:34:35 -07002650static int ray_cs_proc_show(struct seq_file *m, void *v)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002651{
2652/* Print current values which are not available via other means
John Daiker141fa612009-03-10 06:59:54 -07002653 * eg ifconfig
Linus Torvalds1da177e2005-04-16 15:20:36 -07002654 */
John Daiker141fa612009-03-10 06:59:54 -07002655 int i;
2656 struct pcmcia_device *link;
2657 struct net_device *dev;
2658 ray_dev_t *local;
2659 UCHAR *p;
2660 struct freq_hop_element *pfh;
2661 UCHAR c[33];
Linus Torvalds1da177e2005-04-16 15:20:36 -07002662
John Daiker141fa612009-03-10 06:59:54 -07002663 link = this_device;
2664 if (!link)
2665 return 0;
2666 dev = (struct net_device *)link->priv;
2667 if (!dev)
2668 return 0;
2669 local = netdev_priv(dev);
2670 if (!local)
2671 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002672
John Daiker141fa612009-03-10 06:59:54 -07002673 seq_puts(m, "Raylink Wireless LAN driver status\n");
2674 seq_printf(m, "%s\n", rcsid);
2675 /* build 4 does not report version, and field is 0x55 after memtest */
2676 seq_puts(m, "Firmware version = ");
2677 if (local->fw_ver == 0x55)
2678 seq_puts(m, "4 - Use dump_cis for more details\n");
2679 else
2680 seq_printf(m, "%2d.%02d.%02d\n",
2681 local->fw_ver, local->fw_bld, local->fw_var);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002682
John Daiker141fa612009-03-10 06:59:54 -07002683 for (i = 0; i < 32; i++)
2684 c[i] = local->sparm.b5.a_current_ess_id[i];
2685 c[32] = 0;
2686 seq_printf(m, "%s network ESSID = \"%s\"\n",
2687 nettype[local->sparm.b5.a_network_type], c);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002688
John Daiker141fa612009-03-10 06:59:54 -07002689 p = local->bss_id;
2690 seq_printf(m, "BSSID = %pM\n", p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002691
John Daiker141fa612009-03-10 06:59:54 -07002692 seq_printf(m, "Country code = %d\n",
2693 local->sparm.b5.a_curr_country_code);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002694
John Daiker141fa612009-03-10 06:59:54 -07002695 i = local->card_status;
2696 if (i < 0)
2697 i = 10;
2698 if (i > 16)
2699 i = 10;
2700 seq_printf(m, "Card status = %s\n", card_status[i]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002701
John Daiker141fa612009-03-10 06:59:54 -07002702 seq_printf(m, "Framing mode = %s\n", framing[translate]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002703
John Daiker141fa612009-03-10 06:59:54 -07002704 seq_printf(m, "Last pkt signal lvl = %d\n", local->last_rsl);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002705
John Daiker141fa612009-03-10 06:59:54 -07002706 if (local->beacon_rxed) {
2707 /* Pull some fields out of last beacon received */
2708 seq_printf(m, "Beacon Interval = %d Kus\n",
2709 local->last_bcn.beacon_intvl[0]
2710 + 256 * local->last_bcn.beacon_intvl[1]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002711
John Daiker141fa612009-03-10 06:59:54 -07002712 p = local->last_bcn.elements;
2713 if (p[0] == C_ESSID_ELEMENT_ID)
2714 p += p[1] + 2;
2715 else {
2716 seq_printf(m,
2717 "Parse beacon failed at essid element id = %d\n",
2718 p[0]);
2719 return 0;
2720 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002721
John Daiker141fa612009-03-10 06:59:54 -07002722 if (p[0] == C_SUPPORTED_RATES_ELEMENT_ID) {
2723 seq_puts(m, "Supported rate codes = ");
2724 for (i = 2; i < p[1] + 2; i++)
2725 seq_printf(m, "0x%02x ", p[i]);
2726 seq_putc(m, '\n');
2727 p += p[1] + 2;
2728 } else {
2729 seq_puts(m, "Parse beacon failed at rates element\n");
2730 return 0;
2731 }
2732
2733 if (p[0] == C_FH_PARAM_SET_ELEMENT_ID) {
2734 pfh = (struct freq_hop_element *)p;
2735 seq_printf(m, "Hop dwell = %d Kus\n",
2736 pfh->dwell_time[0] +
2737 256 * pfh->dwell_time[1]);
Frans Popcb01b092010-03-24 19:46:34 +01002738 seq_printf(m, "Hop set = %d\n",
John Daiker141fa612009-03-10 06:59:54 -07002739 pfh->hop_set);
Frans Popcb01b092010-03-24 19:46:34 +01002740 seq_printf(m, "Hop pattern = %d\n",
John Daiker141fa612009-03-10 06:59:54 -07002741 pfh->hop_pattern);
Frans Popcb01b092010-03-24 19:46:34 +01002742 seq_printf(m, "Hop index = %d\n",
John Daiker141fa612009-03-10 06:59:54 -07002743 pfh->hop_index);
2744 p += p[1] + 2;
2745 } else {
2746 seq_puts(m,
2747 "Parse beacon failed at FH param element\n");
2748 return 0;
2749 }
2750 } else {
2751 seq_puts(m, "No beacons received\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002752 }
John Daiker141fa612009-03-10 06:59:54 -07002753 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002754}
2755
Alexey Dobriyan6b914c52008-04-10 14:34:35 -07002756static int ray_cs_proc_open(struct inode *inode, struct file *file)
2757{
2758 return single_open(file, ray_cs_proc_show, NULL);
2759}
2760
2761static const struct file_operations ray_cs_proc_fops = {
John Daiker141fa612009-03-10 06:59:54 -07002762 .owner = THIS_MODULE,
2763 .open = ray_cs_proc_open,
2764 .read = seq_read,
2765 .llseek = seq_lseek,
2766 .release = single_release,
Alexey Dobriyan6b914c52008-04-10 14:34:35 -07002767};
Linus Torvalds1da177e2005-04-16 15:20:36 -07002768#endif
2769/*===========================================================================*/
2770static int build_auth_frame(ray_dev_t *local, UCHAR *dest, int auth_type)
2771{
John Daiker141fa612009-03-10 06:59:54 -07002772 int addr;
2773 struct ccs __iomem *pccs;
2774 struct tx_msg __iomem *ptx;
2775 int ccsindex;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002776
John Daiker141fa612009-03-10 06:59:54 -07002777 /* If no tx buffers available, return */
2778 if ((ccsindex = get_free_tx_ccs(local)) < 0) {
Dominik Brodowski624dd662009-10-24 15:52:44 +02002779 pr_debug("ray_cs send authenticate - No free tx ccs\n");
John Daiker141fa612009-03-10 06:59:54 -07002780 return -1;
2781 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002782
John Daiker141fa612009-03-10 06:59:54 -07002783 pccs = ccs_base(local) + ccsindex;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002784
John Daiker141fa612009-03-10 06:59:54 -07002785 /* Address in card space */
2786 addr = TX_BUF_BASE + (ccsindex << 11);
2787 /* fill in the CCS */
2788 writeb(CCS_TX_REQUEST, &pccs->cmd);
2789 writeb(addr >> 8, pccs->var.tx_request.tx_data_ptr);
2790 writeb(0x20, pccs->var.tx_request.tx_data_ptr + 1);
2791 writeb(TX_AUTHENTICATE_LENGTH_MSB, pccs->var.tx_request.tx_data_length);
2792 writeb(TX_AUTHENTICATE_LENGTH_LSB,
2793 pccs->var.tx_request.tx_data_length + 1);
2794 writeb(0, &pccs->var.tx_request.pow_sav_mode);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002795
John Daiker141fa612009-03-10 06:59:54 -07002796 ptx = local->sram + addr;
2797 /* fill in the mac header */
2798 writeb(PROTOCOL_VER | AUTHENTIC_TYPE, &ptx->mac.frame_ctl_1);
2799 writeb(0, &ptx->mac.frame_ctl_2);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002800
John Daiker141fa612009-03-10 06:59:54 -07002801 memcpy_toio(ptx->mac.addr_1, dest, ADDRLEN);
2802 memcpy_toio(ptx->mac.addr_2, local->sparm.b4.a_mac_addr, ADDRLEN);
2803 memcpy_toio(ptx->mac.addr_3, local->bss_id, ADDRLEN);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002804
John Daiker141fa612009-03-10 06:59:54 -07002805 /* Fill in msg body with protocol 00 00, sequence 01 00 ,status 00 00 */
2806 memset_io(ptx->var, 0, 6);
2807 writeb(auth_type & 0xff, ptx->var + 2);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002808
John Daiker141fa612009-03-10 06:59:54 -07002809 /* Interrupt the firmware to process the command */
2810 if (interrupt_ecf(local, ccsindex)) {
Dominik Brodowski624dd662009-10-24 15:52:44 +02002811 pr_debug(
John Daiker141fa612009-03-10 06:59:54 -07002812 "ray_cs send authentication request failed - ECF not ready for intr\n");
2813 writeb(CCS_BUFFER_FREE, &(pccs++)->buffer_status);
2814 return -1;
2815 }
2816 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002817} /* End build_auth_frame */
2818
2819/*===========================================================================*/
2820#ifdef CONFIG_PROC_FS
Alexey Dobriyan83daee02009-11-25 10:12:20 +03002821static ssize_t ray_cs_essid_proc_write(struct file *file,
2822 const char __user *buffer, size_t count, loff_t *pos)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002823{
2824 static char proc_essid[33];
Alan Cox575c9ed2009-10-27 15:35:55 +00002825 unsigned int len = count;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002826
2827 if (len > 32)
2828 len = 32;
2829 memset(proc_essid, 0, 33);
2830 if (copy_from_user(proc_essid, buffer, len))
2831 return -EFAULT;
2832 essid = proc_essid;
2833 return count;
2834}
2835
Alexey Dobriyan83daee02009-11-25 10:12:20 +03002836static const struct file_operations ray_cs_essid_proc_fops = {
2837 .owner = THIS_MODULE,
2838 .write = ray_cs_essid_proc_write,
2839};
2840
2841static ssize_t int_proc_write(struct file *file, const char __user *buffer,
2842 size_t count, loff_t *pos)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002843{
2844 static char proc_number[10];
2845 char *p;
2846 int nr, len;
2847
2848 if (!count)
2849 return 0;
2850
2851 if (count > 9)
2852 return -EINVAL;
2853 if (copy_from_user(proc_number, buffer, count))
2854 return -EFAULT;
2855 p = proc_number;
2856 nr = 0;
2857 len = count;
2858 do {
2859 unsigned int c = *p - '0';
2860 if (c > 9)
2861 return -EINVAL;
John Daiker141fa612009-03-10 06:59:54 -07002862 nr = nr * 10 + c;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002863 p++;
2864 } while (--len);
Alexey Dobriyan83daee02009-11-25 10:12:20 +03002865 *(int *)PDE(file->f_path.dentry->d_inode)->data = nr;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002866 return count;
2867}
Alexey Dobriyan83daee02009-11-25 10:12:20 +03002868
2869static const struct file_operations int_proc_fops = {
2870 .owner = THIS_MODULE,
2871 .write = int_proc_write,
2872};
Linus Torvalds1da177e2005-04-16 15:20:36 -07002873#endif
2874
Dominik Brodowskif57ea2a2005-06-27 16:28:24 -07002875static struct pcmcia_device_id ray_ids[] = {
2876 PCMCIA_DEVICE_MANF_CARD(0x01a6, 0x0000),
2877 PCMCIA_DEVICE_NULL,
2878};
John Daiker141fa612009-03-10 06:59:54 -07002879
Dominik Brodowskif57ea2a2005-06-27 16:28:24 -07002880MODULE_DEVICE_TABLE(pcmcia, ray_ids);
2881
Linus Torvalds1da177e2005-04-16 15:20:36 -07002882static struct pcmcia_driver ray_driver = {
John Daiker141fa612009-03-10 06:59:54 -07002883 .owner = THIS_MODULE,
2884 .drv = {
2885 .name = "ray_cs",
2886 },
2887 .probe = ray_probe,
2888 .remove = ray_detach,
2889 .id_table = ray_ids,
2890 .suspend = ray_suspend,
2891 .resume = ray_resume,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002892};
2893
2894static int __init init_ray_cs(void)
2895{
John Daiker141fa612009-03-10 06:59:54 -07002896 int rc;
2897
Dominik Brodowski624dd662009-10-24 15:52:44 +02002898 pr_debug("%s\n", rcsid);
John Daiker141fa612009-03-10 06:59:54 -07002899 rc = pcmcia_register_driver(&ray_driver);
Dominik Brodowski624dd662009-10-24 15:52:44 +02002900 pr_debug("raylink init_module register_pcmcia_driver returns 0x%x\n",
John Daiker141fa612009-03-10 06:59:54 -07002901 rc);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002902
2903#ifdef CONFIG_PROC_FS
John Daiker141fa612009-03-10 06:59:54 -07002904 proc_mkdir("driver/ray_cs", NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002905
John Daiker141fa612009-03-10 06:59:54 -07002906 proc_create("driver/ray_cs/ray_cs", 0, NULL, &ray_cs_proc_fops);
Alexey Dobriyan83daee02009-11-25 10:12:20 +03002907 proc_create("driver/ray_cs/essid", S_IWUSR, NULL, &ray_cs_essid_proc_fops);
2908 proc_create_data("driver/ray_cs/net_type", S_IWUSR, NULL, &int_proc_fops, &net_type);
2909 proc_create_data("driver/ray_cs/translate", S_IWUSR, NULL, &int_proc_fops, &translate);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002910#endif
John Daiker141fa612009-03-10 06:59:54 -07002911 if (translate != 0)
2912 translate = 1;
2913 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002914} /* init_ray_cs */
2915
2916/*===========================================================================*/
2917
2918static void __exit exit_ray_cs(void)
2919{
Dominik Brodowski624dd662009-10-24 15:52:44 +02002920 pr_debug("ray_cs: cleanup_module\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002921
2922#ifdef CONFIG_PROC_FS
John Daiker141fa612009-03-10 06:59:54 -07002923 remove_proc_entry("driver/ray_cs/ray_cs", NULL);
2924 remove_proc_entry("driver/ray_cs/essid", NULL);
2925 remove_proc_entry("driver/ray_cs/net_type", NULL);
2926 remove_proc_entry("driver/ray_cs/translate", NULL);
2927 remove_proc_entry("driver/ray_cs", NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002928#endif
2929
John Daiker141fa612009-03-10 06:59:54 -07002930 pcmcia_unregister_driver(&ray_driver);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002931} /* exit_ray_cs */
2932
2933module_init(init_ray_cs);
2934module_exit(exit_ray_cs);
2935
2936/*===========================================================================*/