blob: af5b17ce5a15132385de6bf472bc4a36002bfb8b [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*=============================================================================
2 *
3 * A PCMCIA client driver for the Raylink wireless LAN card.
4 * The starting point for this module was the skeleton.c in the
5 * PCMCIA 2.9.12 package written by David Hinds, dahinds@users.sourceforge.net
6 *
7 *
8 * Copyright (c) 1998 Corey Thomas (corey@world.std.com)
9 *
10 * This driver is free software; you can redistribute it and/or modify
John Daiker141fa612009-03-10 06:59:54 -070011 * it under the terms of version 2 only of the GNU General Public License as
Linus Torvalds1da177e2005-04-16 15:20:36 -070012 * published by the Free Software Foundation.
13 *
14 * It is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
22 *
23 * Changes:
24 * Arnaldo Carvalho de Melo <acme@conectiva.com.br> - 08/08/2000
25 * - reorganize kmallocs in ray_attach, checking all for failure
26 * and releasing the previous allocations if one fails
27 *
28 * Daniele Bellucci <bellucda@tiscali.it> - 07/10/2003
29 * - Audit copy_to_user in ioctl(SIOCGIWESSID)
John Daiker141fa612009-03-10 06:59:54 -070030 *
Linus Torvalds1da177e2005-04-16 15:20:36 -070031=============================================================================*/
32
Linus Torvalds1da177e2005-04-16 15:20:36 -070033#include <linux/module.h>
34#include <linux/kernel.h>
35#include <linux/proc_fs.h>
36#include <linux/ptrace.h>
Alexey Dobriyan6b914c52008-04-10 14:34:35 -070037#include <linux/seq_file.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070038#include <linux/string.h>
39#include <linux/timer.h>
40#include <linux/init.h>
41#include <linux/netdevice.h>
42#include <linux/etherdevice.h>
43#include <linux/if_arp.h>
44#include <linux/ioport.h>
45#include <linux/skbuff.h>
46#include <linux/ethtool.h>
Al Viro7698d692007-12-29 04:55:50 -050047#include <linux/ieee80211.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070048
Linus Torvalds1da177e2005-04-16 15:20:36 -070049#include <pcmcia/cistpl.h>
50#include <pcmcia/cisreg.h>
51#include <pcmcia/ds.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070052
53#include <linux/wireless.h>
Michael Wu113b8982006-08-13 23:27:17 -070054#include <net/iw_handler.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070055
56#include <asm/io.h>
57#include <asm/system.h>
58#include <asm/byteorder.h>
59#include <asm/uaccess.h>
60
61/* Warning : these stuff will slow down the driver... */
62#define WIRELESS_SPY /* Enable spying addresses */
63/* Definitions we need for spy */
John Daiker141fa612009-03-10 06:59:54 -070064typedef struct iw_statistics iw_stats;
65typedef u_char mac_addr[ETH_ALEN]; /* Hardware address */
Linus Torvalds1da177e2005-04-16 15:20:36 -070066
67#include "rayctl.h"
68#include "ray_cs.h"
69
Linus Torvalds1da177e2005-04-16 15:20:36 -070070
Linus Torvalds1da177e2005-04-16 15:20:36 -070071/** Prototypes based on PCMCIA skeleton driver *******************************/
Dominik Brodowski15b99ac2006-03-31 17:26:06 +020072static int ray_config(struct pcmcia_device *link);
Dominik Brodowskifba395e2006-03-31 17:21:06 +020073static void ray_release(struct pcmcia_device *link);
Dominik Brodowskicc3b4862005-11-14 21:23:14 +010074static void ray_detach(struct pcmcia_device *p_dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -070075
76/***** Prototypes indicated by device structure ******************************/
77static int ray_dev_close(struct net_device *dev);
78static int ray_dev_config(struct net_device *dev, struct ifmap *map);
79static struct net_device_stats *ray_get_stats(struct net_device *dev);
80static int ray_dev_init(struct net_device *dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -070081
Jeff Garzik7282d492006-09-13 14:30:00 -040082static const struct ethtool_ops netdev_ethtool_ops;
Linus Torvalds1da177e2005-04-16 15:20:36 -070083
84static int ray_open(struct net_device *dev);
Stephen Hemmingerd0cf9c02009-08-31 19:50:57 +000085static netdev_tx_t ray_dev_start_xmit(struct sk_buff *skb,
86 struct net_device *dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -070087static void set_multicast_list(struct net_device *dev);
88static void ray_update_multi_list(struct net_device *dev, int all);
89static int translate_frame(ray_dev_t *local, struct tx_msg __iomem *ptx,
John Daiker141fa612009-03-10 06:59:54 -070090 unsigned char *data, int len);
91static void ray_build_header(ray_dev_t *local, struct tx_msg __iomem *ptx,
92 UCHAR msg_type, unsigned char *data);
Linus Torvalds1da177e2005-04-16 15:20:36 -070093static void untranslate(ray_dev_t *local, struct sk_buff *skb, int len);
John Daiker141fa612009-03-10 06:59:54 -070094static iw_stats *ray_get_wireless_stats(struct net_device *dev);
95static const struct iw_handler_def ray_handler_def;
Linus Torvalds1da177e2005-04-16 15:20:36 -070096
97/***** Prototypes for raylink functions **************************************/
Linus Torvalds1da177e2005-04-16 15:20:36 -070098static void authenticate(ray_dev_t *local);
99static int build_auth_frame(ray_dev_t *local, UCHAR *dest, int auth_type);
100static void authenticate_timeout(u_long);
101static int get_free_ccs(ray_dev_t *local);
102static int get_free_tx_ccs(ray_dev_t *local);
103static void init_startup_params(ray_dev_t *local);
104static int parse_addr(char *in_str, UCHAR *out);
John Daiker141fa612009-03-10 06:59:54 -0700105static int ray_hw_xmit(unsigned char *data, int len, struct net_device *dev, UCHAR type);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700106static int ray_init(struct net_device *dev);
107static int interrupt_ecf(ray_dev_t *local, int ccs);
108static void ray_reset(struct net_device *dev);
109static void ray_update_parm(struct net_device *dev, UCHAR objid, UCHAR *value, int len);
110static void verify_dl_startup(u_long);
111
112/* Prototypes for interrpt time functions **********************************/
John Daiker141fa612009-03-10 06:59:54 -0700113static irqreturn_t ray_interrupt(int reg, void *dev_id);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700114static void clear_interrupt(ray_dev_t *local);
John Daiker141fa612009-03-10 06:59:54 -0700115static void rx_deauthenticate(ray_dev_t *local, struct rcs __iomem *prcs,
116 unsigned int pkt_addr, int rx_len);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700117static int copy_from_rx_buff(ray_dev_t *local, UCHAR *dest, int pkt_addr, int len);
118static void ray_rx(struct net_device *dev, ray_dev_t *local, struct rcs __iomem *prcs);
119static void release_frag_chain(ray_dev_t *local, struct rcs __iomem *prcs);
120static void rx_authenticate(ray_dev_t *local, struct rcs __iomem *prcs,
John Daiker141fa612009-03-10 06:59:54 -0700121 unsigned int pkt_addr, int rx_len);
122static void rx_data(struct net_device *dev, struct rcs __iomem *prcs,
123 unsigned int pkt_addr, int rx_len);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700124static void associate(ray_dev_t *local);
125
126/* Card command functions */
127static int dl_startup_params(struct net_device *dev);
128static void join_net(u_long local);
129static void start_net(u_long local);
130/* void start_net(ray_dev_t *local); */
131
132/*===========================================================================*/
133/* Parameters that can be set with 'insmod' */
134
135/* ADHOC=0, Infrastructure=1 */
136static int net_type = ADHOC;
137
138/* Hop dwell time in Kus (1024 us units defined by 802.11) */
139static int hop_dwell = 128;
140
141/* Beacon period in Kus */
142static int beacon_period = 256;
143
144/* power save mode (0 = off, 1 = save power) */
145static int psm;
146
147/* String for network's Extended Service Set ID. 32 Characters max */
148static char *essid;
149
150/* Default to encapsulation unless translation requested */
151static int translate = 1;
152
153static int country = USA;
154
155static int sniffer;
156
157static int bc;
158
159/* 48 bit physical card address if overriding card's real physical
160 * address is required. Since IEEE 802.11 addresses are 48 bits
161 * like ethernet, an int can't be used, so a string is used. To
162 * allow use of addresses starting with a decimal digit, the first
163 * character must be a letter and will be ignored. This letter is
164 * followed by up to 12 hex digits which are the address. If less
165 * than 12 digits are used, the address will be left filled with 0's.
166 * Note that bit 0 of the first byte is the broadcast bit, and evil
167 * things will happen if it is not 0 in a card address.
168 */
169static char *phy_addr = NULL;
170
Linus Torvalds1da177e2005-04-16 15:20:36 -0700171static unsigned int ray_mem_speed = 500;
172
Dominik Brodowskifd238232006-03-05 10:45:09 +0100173/* WARNING: THIS DRIVER IS NOT CAPABLE OF HANDLING MULTIPLE DEVICES! */
174static struct pcmcia_device *this_device = NULL;
175
Linus Torvalds1da177e2005-04-16 15:20:36 -0700176MODULE_AUTHOR("Corey Thomas <corey@world.std.com>");
177MODULE_DESCRIPTION("Raylink/WebGear wireless LAN driver");
178MODULE_LICENSE("GPL");
179
180module_param(net_type, int, 0);
181module_param(hop_dwell, int, 0);
182module_param(beacon_period, int, 0);
183module_param(psm, int, 0);
184module_param(essid, charp, 0);
185module_param(translate, int, 0);
186module_param(country, int, 0);
187module_param(sniffer, int, 0);
188module_param(bc, int, 0);
189module_param(phy_addr, charp, 0);
190module_param(ray_mem_speed, int, 0);
191
192static UCHAR b5_default_startup_parms[] = {
John Daiker141fa612009-03-10 06:59:54 -0700193 0, 0, /* Adhoc station */
194 'L', 'I', 'N', 'U', 'X', 0, 0, 0, /* 32 char ESSID */
195 0, 0, 0, 0, 0, 0, 0, 0,
196 0, 0, 0, 0, 0, 0, 0, 0,
197 0, 0, 0, 0, 0, 0, 0, 0,
198 1, 0, /* Active scan, CA Mode */
199 0, 0, 0, 0, 0, 0, /* No default MAC addr */
200 0x7f, 0xff, /* Frag threshold */
201 0x00, 0x80, /* Hop time 128 Kus */
202 0x01, 0x00, /* Beacon period 256 Kus */
203 0x01, 0x07, 0xa3, /* DTIM, retries, ack timeout */
204 0x1d, 0x82, 0x4e, /* SIFS, DIFS, PIFS */
205 0x7f, 0xff, /* RTS threshold */
206 0x04, 0xe2, 0x38, 0xA4, /* scan_dwell, max_scan_dwell */
207 0x05, /* assoc resp timeout thresh */
208 0x08, 0x02, 0x08, /* adhoc, infra, super cycle max */
209 0, /* Promiscuous mode */
210 0x0c, 0x0bd, /* Unique word */
211 0x32, /* Slot time */
212 0xff, 0xff, /* roam-low snr, low snr count */
213 0x05, 0xff, /* Infra, adhoc missed bcn thresh */
214 0x01, 0x0b, 0x4f, /* USA, hop pattern, hop pat length */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700215/* b4 - b5 differences start here */
John Daiker141fa612009-03-10 06:59:54 -0700216 0x00, 0x3f, /* CW max */
217 0x00, 0x0f, /* CW min */
218 0x04, 0x08, /* Noise gain, limit offset */
219 0x28, 0x28, /* det rssi, med busy offsets */
220 7, /* det sync thresh */
221 0, 2, 2, /* test mode, min, max */
222 0, /* allow broadcast SSID probe resp */
223 0, 0, /* privacy must start, can join */
224 2, 0, 0, 0, 0, 0, 0, 0 /* basic rate set */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700225};
226
227static UCHAR b4_default_startup_parms[] = {
John Daiker141fa612009-03-10 06:59:54 -0700228 0, 0, /* Adhoc station */
229 'L', 'I', 'N', 'U', 'X', 0, 0, 0, /* 32 char ESSID */
230 0, 0, 0, 0, 0, 0, 0, 0,
231 0, 0, 0, 0, 0, 0, 0, 0,
232 0, 0, 0, 0, 0, 0, 0, 0,
233 1, 0, /* Active scan, CA Mode */
234 0, 0, 0, 0, 0, 0, /* No default MAC addr */
235 0x7f, 0xff, /* Frag threshold */
236 0x02, 0x00, /* Hop time */
237 0x00, 0x01, /* Beacon period */
238 0x01, 0x07, 0xa3, /* DTIM, retries, ack timeout */
239 0x1d, 0x82, 0xce, /* SIFS, DIFS, PIFS */
240 0x7f, 0xff, /* RTS threshold */
241 0xfb, 0x1e, 0xc7, 0x5c, /* scan_dwell, max_scan_dwell */
242 0x05, /* assoc resp timeout thresh */
243 0x04, 0x02, 0x4, /* adhoc, infra, super cycle max */
244 0, /* Promiscuous mode */
245 0x0c, 0x0bd, /* Unique word */
246 0x4e, /* Slot time (TBD seems wrong) */
247 0xff, 0xff, /* roam-low snr, low snr count */
248 0x05, 0xff, /* Infra, adhoc missed bcn thresh */
249 0x01, 0x0b, 0x4e, /* USA, hop pattern, hop pat length */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700250/* b4 - b5 differences start here */
John Daiker141fa612009-03-10 06:59:54 -0700251 0x3f, 0x0f, /* CW max, min */
252 0x04, 0x08, /* Noise gain, limit offset */
253 0x28, 0x28, /* det rssi, med busy offsets */
254 7, /* det sync thresh */
255 0, 2, 2 /* test mode, min, max */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700256};
John Daiker141fa612009-03-10 06:59:54 -0700257
Linus Torvalds1da177e2005-04-16 15:20:36 -0700258/*===========================================================================*/
John Daiker141fa612009-03-10 06:59:54 -0700259static unsigned char eth2_llc[] = { 0xaa, 0xaa, 3, 0, 0, 0 };
Linus Torvalds1da177e2005-04-16 15:20:36 -0700260
261static char hop_pattern_length[] = { 1,
John Daiker141fa612009-03-10 06:59:54 -0700262 USA_HOP_MOD, EUROPE_HOP_MOD,
263 JAPAN_HOP_MOD, KOREA_HOP_MOD,
264 SPAIN_HOP_MOD, FRANCE_HOP_MOD,
265 ISRAEL_HOP_MOD, AUSTRALIA_HOP_MOD,
266 JAPAN_TEST_HOP_MOD
Linus Torvalds1da177e2005-04-16 15:20:36 -0700267};
268
John Daiker141fa612009-03-10 06:59:54 -0700269static char rcsid[] =
270 "Raylink/WebGear wireless LAN - Corey <Thomas corey@world.std.com>";
Linus Torvalds1da177e2005-04-16 15:20:36 -0700271
Stephen Hemminger32f5a332009-03-20 19:36:28 +0000272static const struct net_device_ops ray_netdev_ops = {
273 .ndo_init = ray_dev_init,
274 .ndo_open = ray_open,
275 .ndo_stop = ray_dev_close,
276 .ndo_start_xmit = ray_dev_start_xmit,
277 .ndo_set_config = ray_dev_config,
278 .ndo_get_stats = ray_get_stats,
279 .ndo_set_multicast_list = set_multicast_list,
280 .ndo_change_mtu = eth_change_mtu,
281 .ndo_set_mac_address = eth_mac_addr,
282 .ndo_validate_addr = eth_validate_addr,
283};
284
Dominik Brodowski15b99ac2006-03-31 17:26:06 +0200285static int ray_probe(struct pcmcia_device *p_dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700286{
John Daiker141fa612009-03-10 06:59:54 -0700287 ray_dev_t *local;
288 struct net_device *dev;
Dominik Brodowskifd238232006-03-05 10:45:09 +0100289
Dominik Brodowski624dd662009-10-24 15:52:44 +0200290 dev_dbg(&p_dev->dev, "ray_attach()\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700291
John Daiker141fa612009-03-10 06:59:54 -0700292 /* Allocate space for private device-specific data */
293 dev = alloc_etherdev(sizeof(ray_dev_t));
294 if (!dev)
295 goto fail_alloc_dev;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700296
John Daiker141fa612009-03-10 06:59:54 -0700297 local = netdev_priv(dev);
298 local->finder = p_dev;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700299
John Daiker141fa612009-03-10 06:59:54 -0700300 /* The io structure describes IO port mapping. None used here */
Dominik Brodowski90abdc32010-07-24 17:23:51 +0200301 p_dev->resource[0]->end = 0;
302 p_dev->resource[0]->flags |= IO_DATA_PATH_WIDTH_8;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700303
John Daiker141fa612009-03-10 06:59:54 -0700304 /* General socket configuration */
Dominik Brodowski1ac71e52010-07-29 19:27:09 +0200305 p_dev->config_flags |= CONF_ENABLE_IRQ;
Dominik Brodowski7feabb62010-07-29 18:35:47 +0200306 p_dev->config_index = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700307
John Daiker141fa612009-03-10 06:59:54 -0700308 p_dev->priv = dev;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700309
John Daiker141fa612009-03-10 06:59:54 -0700310 local->finder = p_dev;
311 local->card_status = CARD_INSERTED;
312 local->authentication_state = UNAUTHENTICATED;
313 local->num_multi = 0;
Dominik Brodowski624dd662009-10-24 15:52:44 +0200314 dev_dbg(&p_dev->dev, "ray_attach p_dev = %p, dev = %p, local = %p, intr = %p\n",
John Daiker141fa612009-03-10 06:59:54 -0700315 p_dev, dev, local, &ray_interrupt);
316
317 /* Raylink entries in the device structure */
Stephen Hemminger32f5a332009-03-20 19:36:28 +0000318 dev->netdev_ops = &ray_netdev_ops;
John Daiker141fa612009-03-10 06:59:54 -0700319 SET_ETHTOOL_OPS(dev, &netdev_ethtool_ops);
320 dev->wireless_handlers = &ray_handler_def;
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -0700321#ifdef WIRELESS_SPY
John Daiker141fa612009-03-10 06:59:54 -0700322 local->wireless_data.spy_data = &local->spy_data;
323 dev->wireless_data = &local->wireless_data;
324#endif /* WIRELESS_SPY */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700325
Linus Torvalds1da177e2005-04-16 15:20:36 -0700326
Dominik Brodowski624dd662009-10-24 15:52:44 +0200327 dev_dbg(&p_dev->dev, "ray_cs ray_attach calling ether_setup.)\n");
John Daiker141fa612009-03-10 06:59:54 -0700328 netif_stop_queue(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700329
John Daiker141fa612009-03-10 06:59:54 -0700330 init_timer(&local->timer);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700331
John Daiker141fa612009-03-10 06:59:54 -0700332 this_device = p_dev;
333 return ray_config(p_dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700334
335fail_alloc_dev:
John Daiker141fa612009-03-10 06:59:54 -0700336 return -ENOMEM;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700337} /* ray_attach */
John Daiker141fa612009-03-10 06:59:54 -0700338
Dominik Brodowskifba395e2006-03-31 17:21:06 +0200339static void ray_detach(struct pcmcia_device *link)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700340{
John Daiker141fa612009-03-10 06:59:54 -0700341 struct net_device *dev;
342 ray_dev_t *local;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700343
Dominik Brodowski624dd662009-10-24 15:52:44 +0200344 dev_dbg(&link->dev, "ray_detach\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700345
John Daiker141fa612009-03-10 06:59:54 -0700346 this_device = NULL;
347 dev = link->priv;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700348
John Daiker141fa612009-03-10 06:59:54 -0700349 ray_release(link);
Dominik Brodowskicc3b4862005-11-14 21:23:14 +0100350
John Daiker141fa612009-03-10 06:59:54 -0700351 local = netdev_priv(dev);
352 del_timer(&local->timer);
Dominik Brodowskicc3b4862005-11-14 21:23:14 +0100353
John Daiker141fa612009-03-10 06:59:54 -0700354 if (link->priv) {
Dominik Brodowskic7c2fa02010-03-20 19:39:26 +0100355 unregister_netdev(dev);
John Daiker141fa612009-03-10 06:59:54 -0700356 free_netdev(dev);
357 }
Dominik Brodowski624dd662009-10-24 15:52:44 +0200358 dev_dbg(&link->dev, "ray_cs ray_detach ending\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700359} /* ray_detach */
John Daiker141fa612009-03-10 06:59:54 -0700360
Linus Torvalds1da177e2005-04-16 15:20:36 -0700361#define MAX_TUPLE_SIZE 128
Dominik Brodowski15b99ac2006-03-31 17:26:06 +0200362static int ray_config(struct pcmcia_device *link)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700363{
Dominik Brodowski624dd662009-10-24 15:52:44 +0200364 int ret = 0;
John Daiker141fa612009-03-10 06:59:54 -0700365 int i;
John Daiker141fa612009-03-10 06:59:54 -0700366 struct net_device *dev = (struct net_device *)link->priv;
367 ray_dev_t *local = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700368
Dominik Brodowski624dd662009-10-24 15:52:44 +0200369 dev_dbg(&link->dev, "ray_config\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700370
John Daiker141fa612009-03-10 06:59:54 -0700371 /* Determine card type and firmware version */
372 printk(KERN_INFO "ray_cs Detected: %s%s%s%s\n",
373 link->prod_id[0] ? link->prod_id[0] : " ",
374 link->prod_id[1] ? link->prod_id[1] : " ",
375 link->prod_id[2] ? link->prod_id[2] : " ",
376 link->prod_id[3] ? link->prod_id[3] : " ");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700377
John Daiker141fa612009-03-10 06:59:54 -0700378 /* Now allocate an interrupt line. Note that this does not
379 actually assign a handler to the interrupt.
380 */
Dominik Brodowskieb141202010-03-07 12:21:16 +0100381 ret = pcmcia_request_irq(link, ray_interrupt);
Dominik Brodowski624dd662009-10-24 15:52:44 +0200382 if (ret)
383 goto failed;
Dominik Brodowskieb141202010-03-07 12:21:16 +0100384 dev->irq = link->irq;
John Daiker141fa612009-03-10 06:59:54 -0700385
Dominik Brodowski1ac71e52010-07-29 19:27:09 +0200386 ret = pcmcia_enable_device(link);
Dominik Brodowski624dd662009-10-24 15:52:44 +0200387 if (ret)
388 goto failed;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700389
390/*** Set up 32k window for shared memory (transmit and control) ************/
Dominik Brodowskicdb13802010-07-28 10:59:06 +0200391 link->resource[2]->flags |= WIN_DATA_WIDTH_8 | WIN_MEMORY_TYPE_CM | WIN_ENABLE | WIN_USE_WAIT;
392 link->resource[2]->start = 0;
393 link->resource[2]->end = 0x8000;
394 ret = pcmcia_request_window(link, link->resource[2], ray_mem_speed);
Dominik Brodowski624dd662009-10-24 15:52:44 +0200395 if (ret)
396 goto failed;
Dominik Brodowskicdb13802010-07-28 10:59:06 +0200397 ret = pcmcia_map_mem_page(link, link->resource[2], 0);
Dominik Brodowski624dd662009-10-24 15:52:44 +0200398 if (ret)
399 goto failed;
Dominik Brodowskicdb13802010-07-28 10:59:06 +0200400 local->sram = ioremap(link->resource[2]->start,
401 resource_size(link->resource[2]));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700402
403/*** Set up 16k window for shared memory (receive buffer) ***************/
Dominik Brodowskicdb13802010-07-28 10:59:06 +0200404 link->resource[3]->flags |=
John Daiker141fa612009-03-10 06:59:54 -0700405 WIN_DATA_WIDTH_8 | WIN_MEMORY_TYPE_CM | WIN_ENABLE | WIN_USE_WAIT;
Dominik Brodowskicdb13802010-07-28 10:59:06 +0200406 link->resource[3]->start = 0;
407 link->resource[3]->end = 0x4000;
408 ret = pcmcia_request_window(link, link->resource[3], ray_mem_speed);
Dominik Brodowski624dd662009-10-24 15:52:44 +0200409 if (ret)
410 goto failed;
Dominik Brodowskicdb13802010-07-28 10:59:06 +0200411 ret = pcmcia_map_mem_page(link, link->resource[3], 0x8000);
Dominik Brodowski624dd662009-10-24 15:52:44 +0200412 if (ret)
413 goto failed;
Dominik Brodowskicdb13802010-07-28 10:59:06 +0200414 local->rmem = ioremap(link->resource[3]->start,
415 resource_size(link->resource[3]));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700416
417/*** Set up window for attribute memory ***********************************/
Dominik Brodowskicdb13802010-07-28 10:59:06 +0200418 link->resource[4]->flags |=
John Daiker141fa612009-03-10 06:59:54 -0700419 WIN_DATA_WIDTH_8 | WIN_MEMORY_TYPE_AM | WIN_ENABLE | WIN_USE_WAIT;
Dominik Brodowskicdb13802010-07-28 10:59:06 +0200420 link->resource[4]->start = 0;
421 link->resource[4]->end = 0x1000;
422 ret = pcmcia_request_window(link, link->resource[4], ray_mem_speed);
Dominik Brodowski624dd662009-10-24 15:52:44 +0200423 if (ret)
424 goto failed;
Dominik Brodowskicdb13802010-07-28 10:59:06 +0200425 ret = pcmcia_map_mem_page(link, link->resource[4], 0);
Dominik Brodowski624dd662009-10-24 15:52:44 +0200426 if (ret)
427 goto failed;
Dominik Brodowskicdb13802010-07-28 10:59:06 +0200428 local->amem = ioremap(link->resource[4]->start,
429 resource_size(link->resource[4]));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700430
Dominik Brodowski624dd662009-10-24 15:52:44 +0200431 dev_dbg(&link->dev, "ray_config sram=%p\n", local->sram);
432 dev_dbg(&link->dev, "ray_config rmem=%p\n", local->rmem);
433 dev_dbg(&link->dev, "ray_config amem=%p\n", local->amem);
John Daiker141fa612009-03-10 06:59:54 -0700434 if (ray_init(dev) < 0) {
435 ray_release(link);
436 return -ENODEV;
437 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700438
Dominik Brodowskidd2e5a12009-11-03 10:27:34 +0100439 SET_NETDEV_DEV(dev, &link->dev);
John Daiker141fa612009-03-10 06:59:54 -0700440 i = register_netdev(dev);
441 if (i != 0) {
442 printk("ray_config register_netdev() failed\n");
443 ray_release(link);
444 return i;
445 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700446
John Daiker141fa612009-03-10 06:59:54 -0700447 printk(KERN_INFO "%s: RayLink, irq %d, hw_addr %pM\n",
448 dev->name, dev->irq, dev->dev_addr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700449
John Daiker141fa612009-03-10 06:59:54 -0700450 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700451
Dominik Brodowski624dd662009-10-24 15:52:44 +0200452failed:
John Daiker141fa612009-03-10 06:59:54 -0700453 ray_release(link);
454 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700455} /* ray_config */
456
457static inline struct ccs __iomem *ccs_base(ray_dev_t *dev)
458{
459 return dev->sram + CCS_BASE;
460}
461
462static inline struct rcs __iomem *rcs_base(ray_dev_t *dev)
463{
464 /*
465 * This looks nonsensical, since there is a separate
466 * RCS_BASE. But the difference between a "struct rcs"
467 * and a "struct ccs" ends up being in the _index_ off
468 * the base, so the base pointer is the same for both
469 * ccs/rcs.
470 */
471 return dev->sram + CCS_BASE;
472}
473
474/*===========================================================================*/
475static int ray_init(struct net_device *dev)
476{
John Daiker141fa612009-03-10 06:59:54 -0700477 int i;
478 UCHAR *p;
479 struct ccs __iomem *pccs;
480 ray_dev_t *local = netdev_priv(dev);
481 struct pcmcia_device *link = local->finder;
Dominik Brodowski624dd662009-10-24 15:52:44 +0200482 dev_dbg(&link->dev, "ray_init(0x%p)\n", dev);
John Daiker141fa612009-03-10 06:59:54 -0700483 if (!(pcmcia_dev_present(link))) {
Dominik Brodowski624dd662009-10-24 15:52:44 +0200484 dev_dbg(&link->dev, "ray_init - device not present\n");
John Daiker141fa612009-03-10 06:59:54 -0700485 return -1;
486 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700487
John Daiker141fa612009-03-10 06:59:54 -0700488 local->net_type = net_type;
489 local->sta_type = TYPE_STA;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700490
John Daiker141fa612009-03-10 06:59:54 -0700491 /* Copy the startup results to local memory */
492 memcpy_fromio(&local->startup_res, local->sram + ECF_TO_HOST_BASE,
493 sizeof(struct startup_res_6));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700494
John Daiker141fa612009-03-10 06:59:54 -0700495 /* Check Power up test status and get mac address from card */
496 if (local->startup_res.startup_word != 0x80) {
497 printk(KERN_INFO "ray_init ERROR card status = %2x\n",
498 local->startup_res.startup_word);
499 local->card_status = CARD_INIT_ERROR;
500 return -1;
501 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700502
John Daiker141fa612009-03-10 06:59:54 -0700503 local->fw_ver = local->startup_res.firmware_version[0];
504 local->fw_bld = local->startup_res.firmware_version[1];
505 local->fw_var = local->startup_res.firmware_version[2];
Frans Popcb01b092010-03-24 19:46:34 +0100506 dev_dbg(&link->dev, "ray_init firmware version %d.%d\n", local->fw_ver,
John Daiker141fa612009-03-10 06:59:54 -0700507 local->fw_bld);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700508
John Daiker141fa612009-03-10 06:59:54 -0700509 local->tib_length = 0x20;
510 if ((local->fw_ver == 5) && (local->fw_bld >= 30))
511 local->tib_length = local->startup_res.tib_length;
Dominik Brodowski624dd662009-10-24 15:52:44 +0200512 dev_dbg(&link->dev, "ray_init tib_length = 0x%02x\n", local->tib_length);
John Daiker141fa612009-03-10 06:59:54 -0700513 /* Initialize CCS's to buffer free state */
514 pccs = ccs_base(local);
515 for (i = 0; i < NUMBER_OF_CCS; i++) {
516 writeb(CCS_BUFFER_FREE, &(pccs++)->buffer_status);
517 }
518 init_startup_params(local);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700519
John Daiker141fa612009-03-10 06:59:54 -0700520 /* copy mac address to startup parameters */
521 if (parse_addr(phy_addr, local->sparm.b4.a_mac_addr)) {
522 p = local->sparm.b4.a_mac_addr;
523 } else {
524 memcpy(&local->sparm.b4.a_mac_addr,
525 &local->startup_res.station_addr, ADDRLEN);
526 p = local->sparm.b4.a_mac_addr;
527 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700528
John Daiker141fa612009-03-10 06:59:54 -0700529 clear_interrupt(local); /* Clear any interrupt from the card */
530 local->card_status = CARD_AWAITING_PARAM;
Dominik Brodowski624dd662009-10-24 15:52:44 +0200531 dev_dbg(&link->dev, "ray_init ending\n");
John Daiker141fa612009-03-10 06:59:54 -0700532 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700533} /* ray_init */
John Daiker141fa612009-03-10 06:59:54 -0700534
Linus Torvalds1da177e2005-04-16 15:20:36 -0700535/*===========================================================================*/
536/* Download startup parameters to the card and command it to read them */
537static int dl_startup_params(struct net_device *dev)
538{
John Daiker141fa612009-03-10 06:59:54 -0700539 int ccsindex;
540 ray_dev_t *local = netdev_priv(dev);
541 struct ccs __iomem *pccs;
542 struct pcmcia_device *link = local->finder;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700543
Dominik Brodowski624dd662009-10-24 15:52:44 +0200544 dev_dbg(&link->dev, "dl_startup_params entered\n");
John Daiker141fa612009-03-10 06:59:54 -0700545 if (!(pcmcia_dev_present(link))) {
Dominik Brodowski624dd662009-10-24 15:52:44 +0200546 dev_dbg(&link->dev, "ray_cs dl_startup_params - device not present\n");
John Daiker141fa612009-03-10 06:59:54 -0700547 return -1;
548 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700549
John Daiker141fa612009-03-10 06:59:54 -0700550 /* Copy parameters to host to ECF area */
551 if (local->fw_ver == 0x55)
552 memcpy_toio(local->sram + HOST_TO_ECF_BASE, &local->sparm.b4,
553 sizeof(struct b4_startup_params));
554 else
555 memcpy_toio(local->sram + HOST_TO_ECF_BASE, &local->sparm.b5,
556 sizeof(struct b5_startup_params));
557
558 /* Fill in the CCS fields for the ECF */
559 if ((ccsindex = get_free_ccs(local)) < 0)
560 return -1;
561 local->dl_param_ccs = ccsindex;
562 pccs = ccs_base(local) + ccsindex;
563 writeb(CCS_DOWNLOAD_STARTUP_PARAMS, &pccs->cmd);
Dominik Brodowski624dd662009-10-24 15:52:44 +0200564 dev_dbg(&link->dev, "dl_startup_params start ccsindex = %d\n",
John Daiker141fa612009-03-10 06:59:54 -0700565 local->dl_param_ccs);
566 /* Interrupt the firmware to process the command */
567 if (interrupt_ecf(local, ccsindex)) {
568 printk(KERN_INFO "ray dl_startup_params failed - "
569 "ECF not ready for intr\n");
570 local->card_status = CARD_DL_PARAM_ERROR;
571 writeb(CCS_BUFFER_FREE, &(pccs++)->buffer_status);
572 return -2;
573 }
574 local->card_status = CARD_DL_PARAM;
575 /* Start kernel timer to wait for dl startup to complete. */
576 local->timer.expires = jiffies + HZ / 2;
577 local->timer.data = (long)local;
578 local->timer.function = &verify_dl_startup;
579 add_timer(&local->timer);
Dominik Brodowski624dd662009-10-24 15:52:44 +0200580 dev_dbg(&link->dev,
John Daiker141fa612009-03-10 06:59:54 -0700581 "ray_cs dl_startup_params started timer for verify_dl_startup\n");
582 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700583} /* dl_startup_params */
John Daiker141fa612009-03-10 06:59:54 -0700584
Linus Torvalds1da177e2005-04-16 15:20:36 -0700585/*===========================================================================*/
586static void init_startup_params(ray_dev_t *local)
587{
John Daiker141fa612009-03-10 06:59:54 -0700588 int i;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700589
John Daiker141fa612009-03-10 06:59:54 -0700590 if (country > JAPAN_TEST)
591 country = USA;
592 else if (country < USA)
593 country = USA;
594 /* structure for hop time and beacon period is defined here using
595 * New 802.11D6.1 format. Card firmware is still using old format
596 * until version 6.
597 * Before After
598 * a_hop_time ms byte a_hop_time ms byte
599 * a_hop_time 2s byte a_hop_time ls byte
600 * a_hop_time ls byte a_beacon_period ms byte
601 * a_beacon_period a_beacon_period ls byte
602 *
603 * a_hop_time = uS a_hop_time = KuS
604 * a_beacon_period = hops a_beacon_period = KuS
605 *//* 64ms = 010000 */
606 if (local->fw_ver == 0x55) {
607 memcpy((UCHAR *) &local->sparm.b4, b4_default_startup_parms,
608 sizeof(struct b4_startup_params));
609 /* Translate sane kus input values to old build 4/5 format */
610 /* i = hop time in uS truncated to 3 bytes */
611 i = (hop_dwell * 1024) & 0xffffff;
612 local->sparm.b4.a_hop_time[0] = (i >> 16) & 0xff;
613 local->sparm.b4.a_hop_time[1] = (i >> 8) & 0xff;
614 local->sparm.b4.a_beacon_period[0] = 0;
615 local->sparm.b4.a_beacon_period[1] =
616 ((beacon_period / hop_dwell) - 1) & 0xff;
617 local->sparm.b4.a_curr_country_code = country;
618 local->sparm.b4.a_hop_pattern_length =
619 hop_pattern_length[(int)country] - 1;
620 if (bc) {
621 local->sparm.b4.a_ack_timeout = 0x50;
622 local->sparm.b4.a_sifs = 0x3f;
623 }
624 } else { /* Version 5 uses real kus values */
625 memcpy((UCHAR *) &local->sparm.b5, b5_default_startup_parms,
626 sizeof(struct b5_startup_params));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700627
John Daiker141fa612009-03-10 06:59:54 -0700628 local->sparm.b5.a_hop_time[0] = (hop_dwell >> 8) & 0xff;
629 local->sparm.b5.a_hop_time[1] = hop_dwell & 0xff;
630 local->sparm.b5.a_beacon_period[0] =
631 (beacon_period >> 8) & 0xff;
632 local->sparm.b5.a_beacon_period[1] = beacon_period & 0xff;
633 if (psm)
634 local->sparm.b5.a_power_mgt_state = 1;
635 local->sparm.b5.a_curr_country_code = country;
636 local->sparm.b5.a_hop_pattern_length =
637 hop_pattern_length[(int)country];
638 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700639
John Daiker141fa612009-03-10 06:59:54 -0700640 local->sparm.b4.a_network_type = net_type & 0x01;
641 local->sparm.b4.a_acting_as_ap_status = TYPE_STA;
642
643 if (essid != NULL)
644 strncpy(local->sparm.b4.a_current_ess_id, essid, ESSID_SIZE);
645} /* init_startup_params */
646
Linus Torvalds1da177e2005-04-16 15:20:36 -0700647/*===========================================================================*/
648static void verify_dl_startup(u_long data)
649{
John Daiker141fa612009-03-10 06:59:54 -0700650 ray_dev_t *local = (ray_dev_t *) data;
651 struct ccs __iomem *pccs = ccs_base(local) + local->dl_param_ccs;
652 UCHAR status;
653 struct pcmcia_device *link = local->finder;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700654
John Daiker141fa612009-03-10 06:59:54 -0700655 if (!(pcmcia_dev_present(link))) {
Dominik Brodowski624dd662009-10-24 15:52:44 +0200656 dev_dbg(&link->dev, "ray_cs verify_dl_startup - device not present\n");
John Daiker141fa612009-03-10 06:59:54 -0700657 return;
658 }
Dominik Brodowski624dd662009-10-24 15:52:44 +0200659#if 0
660 {
John Daiker141fa612009-03-10 06:59:54 -0700661 int i;
662 printk(KERN_DEBUG
663 "verify_dl_startup parameters sent via ccs %d:\n",
664 local->dl_param_ccs);
665 for (i = 0; i < sizeof(struct b5_startup_params); i++) {
666 printk(" %2x",
667 (unsigned int)readb(local->sram +
668 HOST_TO_ECF_BASE + i));
669 }
670 printk("\n");
671 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700672#endif
673
John Daiker141fa612009-03-10 06:59:54 -0700674 status = readb(&pccs->buffer_status);
675 if (status != CCS_BUFFER_FREE) {
676 printk(KERN_INFO
677 "Download startup params failed. Status = %d\n",
678 status);
679 local->card_status = CARD_DL_PARAM_ERROR;
680 return;
681 }
682 if (local->sparm.b4.a_network_type == ADHOC)
683 start_net((u_long) local);
684 else
685 join_net((u_long) local);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700686} /* end verify_dl_startup */
John Daiker141fa612009-03-10 06:59:54 -0700687
Linus Torvalds1da177e2005-04-16 15:20:36 -0700688/*===========================================================================*/
689/* Command card to start a network */
690static void start_net(u_long data)
691{
John Daiker141fa612009-03-10 06:59:54 -0700692 ray_dev_t *local = (ray_dev_t *) data;
693 struct ccs __iomem *pccs;
694 int ccsindex;
695 struct pcmcia_device *link = local->finder;
696 if (!(pcmcia_dev_present(link))) {
Dominik Brodowski624dd662009-10-24 15:52:44 +0200697 dev_dbg(&link->dev, "ray_cs start_net - device not present\n");
John Daiker141fa612009-03-10 06:59:54 -0700698 return;
699 }
700 /* Fill in the CCS fields for the ECF */
701 if ((ccsindex = get_free_ccs(local)) < 0)
702 return;
703 pccs = ccs_base(local) + ccsindex;
704 writeb(CCS_START_NETWORK, &pccs->cmd);
705 writeb(0, &pccs->var.start_network.update_param);
706 /* Interrupt the firmware to process the command */
707 if (interrupt_ecf(local, ccsindex)) {
Dominik Brodowski624dd662009-10-24 15:52:44 +0200708 dev_dbg(&link->dev, "ray start net failed - card not ready for intr\n");
John Daiker141fa612009-03-10 06:59:54 -0700709 writeb(CCS_BUFFER_FREE, &(pccs++)->buffer_status);
710 return;
711 }
712 local->card_status = CARD_DOING_ACQ;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700713} /* end start_net */
John Daiker141fa612009-03-10 06:59:54 -0700714
Linus Torvalds1da177e2005-04-16 15:20:36 -0700715/*===========================================================================*/
716/* Command card to join a network */
717static void join_net(u_long data)
718{
John Daiker141fa612009-03-10 06:59:54 -0700719 ray_dev_t *local = (ray_dev_t *) data;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700720
John Daiker141fa612009-03-10 06:59:54 -0700721 struct ccs __iomem *pccs;
722 int ccsindex;
723 struct pcmcia_device *link = local->finder;
724
725 if (!(pcmcia_dev_present(link))) {
Dominik Brodowski624dd662009-10-24 15:52:44 +0200726 dev_dbg(&link->dev, "ray_cs join_net - device not present\n");
John Daiker141fa612009-03-10 06:59:54 -0700727 return;
728 }
729 /* Fill in the CCS fields for the ECF */
730 if ((ccsindex = get_free_ccs(local)) < 0)
731 return;
732 pccs = ccs_base(local) + ccsindex;
733 writeb(CCS_JOIN_NETWORK, &pccs->cmd);
734 writeb(0, &pccs->var.join_network.update_param);
735 writeb(0, &pccs->var.join_network.net_initiated);
736 /* Interrupt the firmware to process the command */
737 if (interrupt_ecf(local, ccsindex)) {
Dominik Brodowski624dd662009-10-24 15:52:44 +0200738 dev_dbg(&link->dev, "ray join net failed - card not ready for intr\n");
John Daiker141fa612009-03-10 06:59:54 -0700739 writeb(CCS_BUFFER_FREE, &(pccs++)->buffer_status);
740 return;
741 }
742 local->card_status = CARD_DOING_ACQ;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700743}
John Daiker141fa612009-03-10 06:59:54 -0700744
Dominik Brodowski22620542010-08-15 08:38:38 +0200745
Dominik Brodowskifba395e2006-03-31 17:21:06 +0200746static void ray_release(struct pcmcia_device *link)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700747{
John Daiker141fa612009-03-10 06:59:54 -0700748 struct net_device *dev = link->priv;
749 ray_dev_t *local = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700750
Dominik Brodowski624dd662009-10-24 15:52:44 +0200751 dev_dbg(&link->dev, "ray_release\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700752
John Daiker141fa612009-03-10 06:59:54 -0700753 del_timer(&local->timer);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700754
John Daiker141fa612009-03-10 06:59:54 -0700755 iounmap(local->sram);
756 iounmap(local->rmem);
757 iounmap(local->amem);
John Daiker141fa612009-03-10 06:59:54 -0700758 pcmcia_disable_device(link);
759
Dominik Brodowski624dd662009-10-24 15:52:44 +0200760 dev_dbg(&link->dev, "ray_release ending\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700761}
762
Dominik Brodowskifba395e2006-03-31 17:21:06 +0200763static int ray_suspend(struct pcmcia_device *link)
Dominik Brodowski98e4c282005-11-14 21:21:18 +0100764{
Dominik Brodowski98e4c282005-11-14 21:21:18 +0100765 struct net_device *dev = link->priv;
766
Dominik Brodowskie2d40962006-03-02 00:09:29 +0100767 if (link->open)
Dominik Brodowski8661bb52006-03-02 00:02:33 +0100768 netif_device_detach(dev);
Dominik Brodowski98e4c282005-11-14 21:21:18 +0100769
770 return 0;
771}
772
Dominik Brodowskifba395e2006-03-31 17:21:06 +0200773static int ray_resume(struct pcmcia_device *link)
Dominik Brodowski98e4c282005-11-14 21:21:18 +0100774{
Dominik Brodowski98e4c282005-11-14 21:21:18 +0100775 struct net_device *dev = link->priv;
776
Dominik Brodowskie2d40962006-03-02 00:09:29 +0100777 if (link->open) {
Dominik Brodowski8661bb52006-03-02 00:02:33 +0100778 ray_reset(dev);
779 netif_device_attach(dev);
780 }
Dominik Brodowski98e4c282005-11-14 21:21:18 +0100781
782 return 0;
783}
784
Linus Torvalds1da177e2005-04-16 15:20:36 -0700785/*===========================================================================*/
Hannes Eder2ed5ba82008-12-26 00:12:59 -0800786static int ray_dev_init(struct net_device *dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700787{
788#ifdef RAY_IMMEDIATE_INIT
John Daiker141fa612009-03-10 06:59:54 -0700789 int i;
790#endif /* RAY_IMMEDIATE_INIT */
791 ray_dev_t *local = netdev_priv(dev);
792 struct pcmcia_device *link = local->finder;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700793
Dominik Brodowski624dd662009-10-24 15:52:44 +0200794 dev_dbg(&link->dev, "ray_dev_init(dev=%p)\n", dev);
John Daiker141fa612009-03-10 06:59:54 -0700795 if (!(pcmcia_dev_present(link))) {
Dominik Brodowski624dd662009-10-24 15:52:44 +0200796 dev_dbg(&link->dev, "ray_dev_init - device not present\n");
John Daiker141fa612009-03-10 06:59:54 -0700797 return -1;
798 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700799#ifdef RAY_IMMEDIATE_INIT
John Daiker141fa612009-03-10 06:59:54 -0700800 /* Download startup parameters */
801 if ((i = dl_startup_params(dev)) < 0) {
802 printk(KERN_INFO "ray_dev_init dl_startup_params failed - "
803 "returns 0x%x\n", i);
804 return -1;
805 }
806#else /* RAY_IMMEDIATE_INIT */
807 /* Postpone the card init so that we can still configure the card,
808 * for example using the Wireless Extensions. The init will happen
809 * in ray_open() - Jean II */
Dominik Brodowski624dd662009-10-24 15:52:44 +0200810 dev_dbg(&link->dev,
John Daiker141fa612009-03-10 06:59:54 -0700811 "ray_dev_init: postponing card init to ray_open() ; Status = %d\n",
812 local->card_status);
813#endif /* RAY_IMMEDIATE_INIT */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700814
John Daiker141fa612009-03-10 06:59:54 -0700815 /* copy mac and broadcast addresses to linux device */
Jiri Pirko3a6d54c2009-05-11 23:37:15 +0000816 memcpy(dev->dev_addr, &local->sparm.b4.a_mac_addr, ADDRLEN);
John Daiker141fa612009-03-10 06:59:54 -0700817 memset(dev->broadcast, 0xff, ETH_ALEN);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700818
Dominik Brodowski624dd662009-10-24 15:52:44 +0200819 dev_dbg(&link->dev, "ray_dev_init ending\n");
John Daiker141fa612009-03-10 06:59:54 -0700820 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700821}
John Daiker141fa612009-03-10 06:59:54 -0700822
Linus Torvalds1da177e2005-04-16 15:20:36 -0700823/*===========================================================================*/
824static int ray_dev_config(struct net_device *dev, struct ifmap *map)
825{
John Daiker141fa612009-03-10 06:59:54 -0700826 ray_dev_t *local = netdev_priv(dev);
827 struct pcmcia_device *link = local->finder;
828 /* Dummy routine to satisfy device structure */
Dominik Brodowski624dd662009-10-24 15:52:44 +0200829 dev_dbg(&link->dev, "ray_dev_config(dev=%p,ifmap=%p)\n", dev, map);
John Daiker141fa612009-03-10 06:59:54 -0700830 if (!(pcmcia_dev_present(link))) {
Dominik Brodowski624dd662009-10-24 15:52:44 +0200831 dev_dbg(&link->dev, "ray_dev_config - device not present\n");
John Daiker141fa612009-03-10 06:59:54 -0700832 return -1;
833 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700834
John Daiker141fa612009-03-10 06:59:54 -0700835 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700836}
John Daiker141fa612009-03-10 06:59:54 -0700837
Linus Torvalds1da177e2005-04-16 15:20:36 -0700838/*===========================================================================*/
Stephen Hemmingerd0cf9c02009-08-31 19:50:57 +0000839static netdev_tx_t ray_dev_start_xmit(struct sk_buff *skb,
840 struct net_device *dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700841{
John Daiker141fa612009-03-10 06:59:54 -0700842 ray_dev_t *local = netdev_priv(dev);
843 struct pcmcia_device *link = local->finder;
844 short length = skb->len;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700845
Stephen Hemmingerd0cf9c02009-08-31 19:50:57 +0000846 if (!pcmcia_dev_present(link)) {
Dominik Brodowski624dd662009-10-24 15:52:44 +0200847 dev_dbg(&link->dev, "ray_dev_start_xmit - device not present\n");
Stephen Hemmingerd0cf9c02009-08-31 19:50:57 +0000848 dev_kfree_skb(skb);
849 return NETDEV_TX_OK;
John Daiker141fa612009-03-10 06:59:54 -0700850 }
Stephen Hemmingerd0cf9c02009-08-31 19:50:57 +0000851
Dominik Brodowski624dd662009-10-24 15:52:44 +0200852 dev_dbg(&link->dev, "ray_dev_start_xmit(skb=%p, dev=%p)\n", skb, dev);
John Daiker141fa612009-03-10 06:59:54 -0700853 if (local->authentication_state == NEED_TO_AUTH) {
Dominik Brodowski624dd662009-10-24 15:52:44 +0200854 dev_dbg(&link->dev, "ray_cs Sending authentication request.\n");
John Daiker141fa612009-03-10 06:59:54 -0700855 if (!build_auth_frame(local, local->auth_id, OPEN_AUTH_REQUEST)) {
856 local->authentication_state = AUTHENTICATED;
857 netif_stop_queue(dev);
Patrick McHardy5b548142009-06-12 06:22:29 +0000858 return NETDEV_TX_BUSY;
John Daiker141fa612009-03-10 06:59:54 -0700859 }
860 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700861
John Daiker141fa612009-03-10 06:59:54 -0700862 if (length < ETH_ZLEN) {
863 if (skb_padto(skb, ETH_ZLEN))
Patrick McHardy6ed10652009-06-23 06:03:08 +0000864 return NETDEV_TX_OK;
John Daiker141fa612009-03-10 06:59:54 -0700865 length = ETH_ZLEN;
866 }
867 switch (ray_hw_xmit(skb->data, length, dev, DATA_TYPE)) {
868 case XMIT_NO_CCS:
869 case XMIT_NEED_AUTH:
870 netif_stop_queue(dev);
Patrick McHardy5b548142009-06-12 06:22:29 +0000871 return NETDEV_TX_BUSY;
John Daiker141fa612009-03-10 06:59:54 -0700872 case XMIT_NO_INTR:
873 case XMIT_MSG_BAD:
874 case XMIT_OK:
875 default:
John Daiker141fa612009-03-10 06:59:54 -0700876 dev_kfree_skb(skb);
John Daiker141fa612009-03-10 06:59:54 -0700877 }
Stephen Hemmingerd0cf9c02009-08-31 19:50:57 +0000878
Patrick McHardy6ed10652009-06-23 06:03:08 +0000879 return NETDEV_TX_OK;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700880} /* ray_dev_start_xmit */
John Daiker141fa612009-03-10 06:59:54 -0700881
Linus Torvalds1da177e2005-04-16 15:20:36 -0700882/*===========================================================================*/
John Daiker141fa612009-03-10 06:59:54 -0700883static int ray_hw_xmit(unsigned char *data, int len, struct net_device *dev,
884 UCHAR msg_type)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700885{
John Daiker141fa612009-03-10 06:59:54 -0700886 ray_dev_t *local = netdev_priv(dev);
887 struct ccs __iomem *pccs;
888 int ccsindex;
889 int offset;
890 struct tx_msg __iomem *ptx; /* Address of xmit buffer in PC space */
891 short int addr; /* Address of xmit buffer in card space */
892
Dominik Brodowski624dd662009-10-24 15:52:44 +0200893 pr_debug("ray_hw_xmit(data=%p, len=%d, dev=%p)\n", data, len, dev);
John Daiker141fa612009-03-10 06:59:54 -0700894 if (len + TX_HEADER_LENGTH > TX_BUF_SIZE) {
895 printk(KERN_INFO "ray_hw_xmit packet too large: %d bytes\n",
896 len);
897 return XMIT_MSG_BAD;
898 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700899 switch (ccsindex = get_free_tx_ccs(local)) {
900 case ECCSBUSY:
Dominik Brodowski624dd662009-10-24 15:52:44 +0200901 pr_debug("ray_hw_xmit tx_ccs table busy\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700902 case ECCSFULL:
Dominik Brodowski624dd662009-10-24 15:52:44 +0200903 pr_debug("ray_hw_xmit No free tx ccs\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700904 case ECARDGONE:
John Daiker141fa612009-03-10 06:59:54 -0700905 netif_stop_queue(dev);
906 return XMIT_NO_CCS;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700907 default:
908 break;
909 }
John Daiker141fa612009-03-10 06:59:54 -0700910 addr = TX_BUF_BASE + (ccsindex << 11);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700911
John Daiker141fa612009-03-10 06:59:54 -0700912 if (msg_type == DATA_TYPE) {
913 local->stats.tx_bytes += len;
914 local->stats.tx_packets++;
915 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700916
John Daiker141fa612009-03-10 06:59:54 -0700917 ptx = local->sram + addr;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700918
John Daiker141fa612009-03-10 06:59:54 -0700919 ray_build_header(local, ptx, msg_type, data);
920 if (translate) {
921 offset = translate_frame(local, ptx, data, len);
922 } else { /* Encapsulate frame */
923 /* TBD TIB length will move address of ptx->var */
924 memcpy_toio(&ptx->var, data, len);
925 offset = 0;
926 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700927
John Daiker141fa612009-03-10 06:59:54 -0700928 /* fill in the CCS */
929 pccs = ccs_base(local) + ccsindex;
930 len += TX_HEADER_LENGTH + offset;
931 writeb(CCS_TX_REQUEST, &pccs->cmd);
932 writeb(addr >> 8, &pccs->var.tx_request.tx_data_ptr[0]);
933 writeb(local->tib_length, &pccs->var.tx_request.tx_data_ptr[1]);
934 writeb(len >> 8, &pccs->var.tx_request.tx_data_length[0]);
935 writeb(len & 0xff, &pccs->var.tx_request.tx_data_length[1]);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700936/* TBD still need psm_cam? */
John Daiker141fa612009-03-10 06:59:54 -0700937 writeb(PSM_CAM, &pccs->var.tx_request.pow_sav_mode);
938 writeb(local->net_default_tx_rate, &pccs->var.tx_request.tx_rate);
939 writeb(0, &pccs->var.tx_request.antenna);
Dominik Brodowski624dd662009-10-24 15:52:44 +0200940 pr_debug("ray_hw_xmit default_tx_rate = 0x%x\n",
John Daiker141fa612009-03-10 06:59:54 -0700941 local->net_default_tx_rate);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700942
John Daiker141fa612009-03-10 06:59:54 -0700943 /* Interrupt the firmware to process the command */
944 if (interrupt_ecf(local, ccsindex)) {
Dominik Brodowski624dd662009-10-24 15:52:44 +0200945 pr_debug("ray_hw_xmit failed - ECF not ready for intr\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700946/* TBD very inefficient to copy packet to buffer, and then not
947 send it, but the alternative is to queue the messages and that
948 won't be done for a while. Maybe set tbusy until a CCS is free?
949*/
John Daiker141fa612009-03-10 06:59:54 -0700950 writeb(CCS_BUFFER_FREE, &pccs->buffer_status);
951 return XMIT_NO_INTR;
952 }
953 return XMIT_OK;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700954} /* end ray_hw_xmit */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700955
John Daiker141fa612009-03-10 06:59:54 -0700956/*===========================================================================*/
957static int translate_frame(ray_dev_t *local, struct tx_msg __iomem *ptx,
958 unsigned char *data, int len)
959{
960 __be16 proto = ((struct ethhdr *)data)->h_proto;
961 if (ntohs(proto) >= 1536) { /* DIX II ethernet frame */
Dominik Brodowski624dd662009-10-24 15:52:44 +0200962 pr_debug("ray_cs translate_frame DIX II\n");
John Daiker141fa612009-03-10 06:59:54 -0700963 /* Copy LLC header to card buffer */
964 memcpy_toio(&ptx->var, eth2_llc, sizeof(eth2_llc));
965 memcpy_toio(((void __iomem *)&ptx->var) + sizeof(eth2_llc),
966 (UCHAR *) &proto, 2);
967 if (proto == htons(ETH_P_AARP) || proto == htons(ETH_P_IPX)) {
968 /* This is the selective translation table, only 2 entries */
969 writeb(0xf8,
970 &((struct snaphdr_t __iomem *)ptx->var)->org[3]);
971 }
972 /* Copy body of ethernet packet without ethernet header */
973 memcpy_toio((void __iomem *)&ptx->var +
974 sizeof(struct snaphdr_t), data + ETH_HLEN,
975 len - ETH_HLEN);
976 return (int)sizeof(struct snaphdr_t) - ETH_HLEN;
977 } else { /* already 802 type, and proto is length */
Dominik Brodowski624dd662009-10-24 15:52:44 +0200978 pr_debug("ray_cs translate_frame 802\n");
John Daiker141fa612009-03-10 06:59:54 -0700979 if (proto == htons(0xffff)) { /* evil netware IPX 802.3 without LLC */
Dominik Brodowski624dd662009-10-24 15:52:44 +0200980 pr_debug("ray_cs translate_frame evil IPX\n");
John Daiker141fa612009-03-10 06:59:54 -0700981 memcpy_toio(&ptx->var, data + ETH_HLEN, len - ETH_HLEN);
982 return 0 - ETH_HLEN;
983 }
984 memcpy_toio(&ptx->var, data + ETH_HLEN, len - ETH_HLEN);
985 return 0 - ETH_HLEN;
986 }
987 /* TBD do other frame types */
988} /* end translate_frame */
989
990/*===========================================================================*/
991static void ray_build_header(ray_dev_t *local, struct tx_msg __iomem *ptx,
992 UCHAR msg_type, unsigned char *data)
993{
994 writeb(PROTOCOL_VER | msg_type, &ptx->mac.frame_ctl_1);
995/*** IEEE 802.11 Address field assignments *************
996 TODS FROMDS addr_1 addr_2 addr_3 addr_4
997Adhoc 0 0 dest src (terminal) BSSID N/A
998AP to Terminal 0 1 dest AP(BSSID) source N/A
999Terminal to AP 1 0 AP(BSSID) src (terminal) dest N/A
1000AP to AP 1 1 dest AP src AP dest source
1001*******************************************************/
1002 if (local->net_type == ADHOC) {
1003 writeb(0, &ptx->mac.frame_ctl_2);
1004 memcpy_toio(ptx->mac.addr_1, ((struct ethhdr *)data)->h_dest,
1005 2 * ADDRLEN);
1006 memcpy_toio(ptx->mac.addr_3, local->bss_id, ADDRLEN);
1007 } else { /* infrastructure */
1008
1009 if (local->sparm.b4.a_acting_as_ap_status) {
1010 writeb(FC2_FROM_DS, &ptx->mac.frame_ctl_2);
1011 memcpy_toio(ptx->mac.addr_1,
1012 ((struct ethhdr *)data)->h_dest, ADDRLEN);
1013 memcpy_toio(ptx->mac.addr_2, local->bss_id, 6);
1014 memcpy_toio(ptx->mac.addr_3,
1015 ((struct ethhdr *)data)->h_source, ADDRLEN);
1016 } else { /* Terminal */
1017
1018 writeb(FC2_TO_DS, &ptx->mac.frame_ctl_2);
1019 memcpy_toio(ptx->mac.addr_1, local->bss_id, ADDRLEN);
1020 memcpy_toio(ptx->mac.addr_2,
1021 ((struct ethhdr *)data)->h_source, ADDRLEN);
1022 memcpy_toio(ptx->mac.addr_3,
1023 ((struct ethhdr *)data)->h_dest, ADDRLEN);
1024 }
1025 }
1026} /* end encapsulate_frame */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001027
1028/*===========================================================================*/
1029
1030static void netdev_get_drvinfo(struct net_device *dev,
1031 struct ethtool_drvinfo *info)
1032{
1033 strcpy(info->driver, "ray_cs");
1034}
1035
Jeff Garzik7282d492006-09-13 14:30:00 -04001036static const struct ethtool_ops netdev_ethtool_ops = {
John Daiker141fa612009-03-10 06:59:54 -07001037 .get_drvinfo = netdev_get_drvinfo,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001038};
1039
1040/*====================================================================*/
1041
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001042/*------------------------------------------------------------------*/
1043/*
1044 * Wireless Handler : get protocol name
1045 */
Joe Perches43ead782010-03-18 18:29:40 -07001046static int ray_get_name(struct net_device *dev, struct iw_request_info *info,
1047 union iwreq_data *wrqu, char *extra)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001048{
Joe Perches43ead782010-03-18 18:29:40 -07001049 strcpy(wrqu->name, "IEEE 802.11-FH");
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001050 return 0;
1051}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001052
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001053/*------------------------------------------------------------------*/
1054/*
1055 * Wireless Handler : set frequency
1056 */
Joe Perches43ead782010-03-18 18:29:40 -07001057static int ray_set_freq(struct net_device *dev, struct iw_request_info *info,
1058 union iwreq_data *wrqu, char *extra)
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001059{
Yoann Padioleau6dbc9c82007-08-03 19:37:16 +02001060 ray_dev_t *local = netdev_priv(dev);
John Daiker141fa612009-03-10 06:59:54 -07001061 int err = -EINPROGRESS; /* Call commit handler */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001062
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001063 /* Reject if card is already initialised */
John Daiker141fa612009-03-10 06:59:54 -07001064 if (local->card_status != CARD_AWAITING_PARAM)
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001065 return -EBUSY;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001066
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001067 /* Setting by channel number */
Joe Perches43ead782010-03-18 18:29:40 -07001068 if ((wrqu->freq.m > USA_HOP_MOD) || (wrqu->freq.e > 0))
Linus Torvalds1da177e2005-04-16 15:20:36 -07001069 err = -EOPNOTSUPP;
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001070 else
Joe Perches43ead782010-03-18 18:29:40 -07001071 local->sparm.b5.a_hop_pattern = wrqu->freq.m;
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001072
1073 return err;
1074}
John Daiker141fa612009-03-10 06:59:54 -07001075
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001076/*------------------------------------------------------------------*/
1077/*
1078 * Wireless Handler : get frequency
1079 */
Joe Perches43ead782010-03-18 18:29:40 -07001080static int ray_get_freq(struct net_device *dev, struct iw_request_info *info,
1081 union iwreq_data *wrqu, char *extra)
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001082{
Yoann Padioleau6dbc9c82007-08-03 19:37:16 +02001083 ray_dev_t *local = netdev_priv(dev);
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001084
Joe Perches43ead782010-03-18 18:29:40 -07001085 wrqu->freq.m = local->sparm.b5.a_hop_pattern;
1086 wrqu->freq.e = 0;
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001087 return 0;
1088}
1089
1090/*------------------------------------------------------------------*/
1091/*
1092 * Wireless Handler : set ESSID
1093 */
Joe Perches43ead782010-03-18 18:29:40 -07001094static int ray_set_essid(struct net_device *dev, struct iw_request_info *info,
1095 union iwreq_data *wrqu, char *extra)
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001096{
Yoann Padioleau6dbc9c82007-08-03 19:37:16 +02001097 ray_dev_t *local = netdev_priv(dev);
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001098
1099 /* Reject if card is already initialised */
John Daiker141fa612009-03-10 06:59:54 -07001100 if (local->card_status != CARD_AWAITING_PARAM)
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001101 return -EBUSY;
1102
1103 /* Check if we asked for `any' */
Joe Perches43ead782010-03-18 18:29:40 -07001104 if (wrqu->essid.flags == 0)
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001105 /* Corey : can you do that ? */
1106 return -EOPNOTSUPP;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001107
Joe Perches43ead782010-03-18 18:29:40 -07001108 /* Check the size of the string */
1109 if (wrqu->essid.length > IW_ESSID_MAX_SIZE)
1110 return -E2BIG;
1111
1112 /* Set the ESSID in the card */
1113 memset(local->sparm.b5.a_current_ess_id, 0, IW_ESSID_MAX_SIZE);
1114 memcpy(local->sparm.b5.a_current_ess_id, extra, wrqu->essid.length);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001115
John Daiker141fa612009-03-10 06:59:54 -07001116 return -EINPROGRESS; /* Call commit handler */
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001117}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001118
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001119/*------------------------------------------------------------------*/
1120/*
1121 * Wireless Handler : get ESSID
1122 */
Joe Perches43ead782010-03-18 18:29:40 -07001123static int ray_get_essid(struct net_device *dev, struct iw_request_info *info,
1124 union iwreq_data *wrqu, char *extra)
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001125{
Yoann Padioleau6dbc9c82007-08-03 19:37:16 +02001126 ray_dev_t *local = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001127
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001128 /* Get the essid that was set */
1129 memcpy(extra, local->sparm.b5.a_current_ess_id, IW_ESSID_MAX_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001130
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001131 /* Push it out ! */
Joe Perches43ead782010-03-18 18:29:40 -07001132 wrqu->essid.length = strlen(extra);
1133 wrqu->essid.flags = 1; /* active */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001134
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001135 return 0;
1136}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001137
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001138/*------------------------------------------------------------------*/
1139/*
1140 * Wireless Handler : get AP address
1141 */
Joe Perches43ead782010-03-18 18:29:40 -07001142static int ray_get_wap(struct net_device *dev, struct iw_request_info *info,
1143 union iwreq_data *wrqu, char *extra)
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001144{
Yoann Padioleau6dbc9c82007-08-03 19:37:16 +02001145 ray_dev_t *local = netdev_priv(dev);
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001146
Joe Perches43ead782010-03-18 18:29:40 -07001147 memcpy(wrqu->ap_addr.sa_data, local->bss_id, ETH_ALEN);
1148 wrqu->ap_addr.sa_family = ARPHRD_ETHER;
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001149
1150 return 0;
1151}
1152
1153/*------------------------------------------------------------------*/
1154/*
1155 * Wireless Handler : set Bit-Rate
1156 */
Joe Perches43ead782010-03-18 18:29:40 -07001157static int ray_set_rate(struct net_device *dev, struct iw_request_info *info,
1158 union iwreq_data *wrqu, char *extra)
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001159{
Yoann Padioleau6dbc9c82007-08-03 19:37:16 +02001160 ray_dev_t *local = netdev_priv(dev);
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001161
1162 /* Reject if card is already initialised */
John Daiker141fa612009-03-10 06:59:54 -07001163 if (local->card_status != CARD_AWAITING_PARAM)
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001164 return -EBUSY;
1165
1166 /* Check if rate is in range */
Joe Perches43ead782010-03-18 18:29:40 -07001167 if ((wrqu->bitrate.value != 1000000) && (wrqu->bitrate.value != 2000000))
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001168 return -EINVAL;
1169
1170 /* Hack for 1.5 Mb/s instead of 2 Mb/s */
John Daiker141fa612009-03-10 06:59:54 -07001171 if ((local->fw_ver == 0x55) && /* Please check */
Joe Perches43ead782010-03-18 18:29:40 -07001172 (wrqu->bitrate.value == 2000000))
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001173 local->net_default_tx_rate = 3;
1174 else
Joe Perches43ead782010-03-18 18:29:40 -07001175 local->net_default_tx_rate = wrqu->bitrate.value / 500000;
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001176
1177 return 0;
1178}
1179
1180/*------------------------------------------------------------------*/
1181/*
1182 * Wireless Handler : get Bit-Rate
1183 */
Joe Perches43ead782010-03-18 18:29:40 -07001184static int ray_get_rate(struct net_device *dev, struct iw_request_info *info,
1185 union iwreq_data *wrqu, char *extra)
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001186{
Yoann Padioleau6dbc9c82007-08-03 19:37:16 +02001187 ray_dev_t *local = netdev_priv(dev);
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001188
John Daiker141fa612009-03-10 06:59:54 -07001189 if (local->net_default_tx_rate == 3)
Joe Perches43ead782010-03-18 18:29:40 -07001190 wrqu->bitrate.value = 2000000; /* Hum... */
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001191 else
Joe Perches43ead782010-03-18 18:29:40 -07001192 wrqu->bitrate.value = local->net_default_tx_rate * 500000;
1193 wrqu->bitrate.fixed = 0; /* We are in auto mode */
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001194
1195 return 0;
1196}
1197
1198/*------------------------------------------------------------------*/
1199/*
1200 * Wireless Handler : set RTS threshold
1201 */
Joe Perches43ead782010-03-18 18:29:40 -07001202static int ray_set_rts(struct net_device *dev, struct iw_request_info *info,
1203 union iwreq_data *wrqu, char *extra)
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001204{
Yoann Padioleau6dbc9c82007-08-03 19:37:16 +02001205 ray_dev_t *local = netdev_priv(dev);
Joe Perches43ead782010-03-18 18:29:40 -07001206 int rthr = wrqu->rts.value;
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001207
1208 /* Reject if card is already initialised */
John Daiker141fa612009-03-10 06:59:54 -07001209 if (local->card_status != CARD_AWAITING_PARAM)
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001210 return -EBUSY;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001211
1212 /* if(wrq->u.rts.fixed == 0) we should complain */
Joe Perches43ead782010-03-18 18:29:40 -07001213 if (wrqu->rts.disabled)
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001214 rthr = 32767;
1215 else {
John Daiker141fa612009-03-10 06:59:54 -07001216 if ((rthr < 0) || (rthr > 2347)) /* What's the max packet size ??? */
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001217 return -EINVAL;
1218 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001219 local->sparm.b5.a_rts_threshold[0] = (rthr >> 8) & 0xFF;
1220 local->sparm.b5.a_rts_threshold[1] = rthr & 0xFF;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001221
John Daiker141fa612009-03-10 06:59:54 -07001222 return -EINPROGRESS; /* Call commit handler */
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001223}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001224
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001225/*------------------------------------------------------------------*/
1226/*
1227 * Wireless Handler : get RTS threshold
1228 */
Joe Perches43ead782010-03-18 18:29:40 -07001229static int ray_get_rts(struct net_device *dev, struct iw_request_info *info,
1230 union iwreq_data *wrqu, char *extra)
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001231{
Yoann Padioleau6dbc9c82007-08-03 19:37:16 +02001232 ray_dev_t *local = netdev_priv(dev);
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001233
Joe Perches43ead782010-03-18 18:29:40 -07001234 wrqu->rts.value = (local->sparm.b5.a_rts_threshold[0] << 8)
John Daiker141fa612009-03-10 06:59:54 -07001235 + local->sparm.b5.a_rts_threshold[1];
Joe Perches43ead782010-03-18 18:29:40 -07001236 wrqu->rts.disabled = (wrqu->rts.value == 32767);
1237 wrqu->rts.fixed = 1;
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001238
1239 return 0;
1240}
1241
1242/*------------------------------------------------------------------*/
1243/*
1244 * Wireless Handler : set Fragmentation threshold
1245 */
Joe Perches43ead782010-03-18 18:29:40 -07001246static int ray_set_frag(struct net_device *dev, struct iw_request_info *info,
1247 union iwreq_data *wrqu, char *extra)
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001248{
Yoann Padioleau6dbc9c82007-08-03 19:37:16 +02001249 ray_dev_t *local = netdev_priv(dev);
Joe Perches43ead782010-03-18 18:29:40 -07001250 int fthr = wrqu->frag.value;
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001251
1252 /* Reject if card is already initialised */
John Daiker141fa612009-03-10 06:59:54 -07001253 if (local->card_status != CARD_AWAITING_PARAM)
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001254 return -EBUSY;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001255
1256 /* if(wrq->u.frag.fixed == 0) should complain */
Joe Perches43ead782010-03-18 18:29:40 -07001257 if (wrqu->frag.disabled)
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001258 fthr = 32767;
1259 else {
John Daiker141fa612009-03-10 06:59:54 -07001260 if ((fthr < 256) || (fthr > 2347)) /* To check out ! */
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001261 return -EINVAL;
1262 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001263 local->sparm.b5.a_frag_threshold[0] = (fthr >> 8) & 0xFF;
1264 local->sparm.b5.a_frag_threshold[1] = fthr & 0xFF;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001265
John Daiker141fa612009-03-10 06:59:54 -07001266 return -EINPROGRESS; /* Call commit handler */
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001267}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001268
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001269/*------------------------------------------------------------------*/
1270/*
1271 * Wireless Handler : get Fragmentation threshold
1272 */
Joe Perches43ead782010-03-18 18:29:40 -07001273static int ray_get_frag(struct net_device *dev, struct iw_request_info *info,
1274 union iwreq_data *wrqu, char *extra)
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001275{
Yoann Padioleau6dbc9c82007-08-03 19:37:16 +02001276 ray_dev_t *local = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001277
Joe Perches43ead782010-03-18 18:29:40 -07001278 wrqu->frag.value = (local->sparm.b5.a_frag_threshold[0] << 8)
John Daiker141fa612009-03-10 06:59:54 -07001279 + local->sparm.b5.a_frag_threshold[1];
Joe Perches43ead782010-03-18 18:29:40 -07001280 wrqu->frag.disabled = (wrqu->frag.value == 32767);
1281 wrqu->frag.fixed = 1;
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001282
1283 return 0;
1284}
1285
1286/*------------------------------------------------------------------*/
1287/*
1288 * Wireless Handler : set Mode of Operation
1289 */
Joe Perches43ead782010-03-18 18:29:40 -07001290static int ray_set_mode(struct net_device *dev, struct iw_request_info *info,
1291 union iwreq_data *wrqu, char *extra)
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001292{
Yoann Padioleau6dbc9c82007-08-03 19:37:16 +02001293 ray_dev_t *local = netdev_priv(dev);
John Daiker141fa612009-03-10 06:59:54 -07001294 int err = -EINPROGRESS; /* Call commit handler */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001295 char card_mode = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001296
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001297 /* Reject if card is already initialised */
John Daiker141fa612009-03-10 06:59:54 -07001298 if (local->card_status != CARD_AWAITING_PARAM)
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001299 return -EBUSY;
1300
Joe Perches43ead782010-03-18 18:29:40 -07001301 switch (wrqu->mode) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001302 case IW_MODE_ADHOC:
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001303 card_mode = 0;
John Daiker141fa612009-03-10 06:59:54 -07001304 /* Fall through */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001305 case IW_MODE_INFRA:
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001306 local->sparm.b5.a_network_type = card_mode;
1307 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001308 default:
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001309 err = -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001310 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001311
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001312 return err;
1313}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001314
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001315/*------------------------------------------------------------------*/
1316/*
1317 * Wireless Handler : get Mode of Operation
1318 */
Joe Perches43ead782010-03-18 18:29:40 -07001319static int ray_get_mode(struct net_device *dev, struct iw_request_info *info,
1320 union iwreq_data *wrqu, char *extra)
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001321{
Yoann Padioleau6dbc9c82007-08-03 19:37:16 +02001322 ray_dev_t *local = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001323
John Daiker141fa612009-03-10 06:59:54 -07001324 if (local->sparm.b5.a_network_type)
Joe Perches43ead782010-03-18 18:29:40 -07001325 wrqu->mode = IW_MODE_INFRA;
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001326 else
Joe Perches43ead782010-03-18 18:29:40 -07001327 wrqu->mode = IW_MODE_ADHOC;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001328
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001329 return 0;
1330}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001331
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001332/*------------------------------------------------------------------*/
1333/*
1334 * Wireless Handler : get range info
1335 */
Joe Perches43ead782010-03-18 18:29:40 -07001336static int ray_get_range(struct net_device *dev, struct iw_request_info *info,
1337 union iwreq_data *wrqu, char *extra)
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001338{
John Daiker141fa612009-03-10 06:59:54 -07001339 struct iw_range *range = (struct iw_range *)extra;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001340
Joe Perches43ead782010-03-18 18:29:40 -07001341 memset(range, 0, sizeof(struct iw_range));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001342
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001343 /* Set the length (very important for backward compatibility) */
Joe Perches43ead782010-03-18 18:29:40 -07001344 wrqu->data.length = sizeof(struct iw_range);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001345
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001346 /* Set the Wireless Extension versions */
1347 range->we_version_compiled = WIRELESS_EXT;
1348 range->we_version_source = 9;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001349
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001350 /* Set information in the range struct */
1351 range->throughput = 1.1 * 1000 * 1000; /* Put the right number here */
John Daiker141fa612009-03-10 06:59:54 -07001352 range->num_channels = hop_pattern_length[(int)country];
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001353 range->num_frequency = 0;
1354 range->max_qual.qual = 0;
1355 range->max_qual.level = 255; /* What's the correct value ? */
1356 range->max_qual.noise = 255; /* Idem */
1357 range->num_bitrates = 2;
1358 range->bitrate[0] = 1000000; /* 1 Mb/s */
1359 range->bitrate[1] = 2000000; /* 2 Mb/s */
1360 return 0;
1361}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001362
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001363/*------------------------------------------------------------------*/
1364/*
1365 * Wireless Private Handler : set framing mode
1366 */
Joe Perches43ead782010-03-18 18:29:40 -07001367static int ray_set_framing(struct net_device *dev, struct iw_request_info *info,
John Daiker141fa612009-03-10 06:59:54 -07001368 union iwreq_data *wrqu, char *extra)
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001369{
1370 translate = *(extra); /* Set framing mode */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001371
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001372 return 0;
1373}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001374
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001375/*------------------------------------------------------------------*/
1376/*
1377 * Wireless Private Handler : get framing mode
1378 */
Joe Perches43ead782010-03-18 18:29:40 -07001379static int ray_get_framing(struct net_device *dev, struct iw_request_info *info,
John Daiker141fa612009-03-10 06:59:54 -07001380 union iwreq_data *wrqu, char *extra)
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001381{
1382 *(extra) = translate;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001383
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001384 return 0;
1385}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001386
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001387/*------------------------------------------------------------------*/
1388/*
1389 * Wireless Private Handler : get country
1390 */
Joe Perches43ead782010-03-18 18:29:40 -07001391static int ray_get_country(struct net_device *dev, struct iw_request_info *info,
John Daiker141fa612009-03-10 06:59:54 -07001392 union iwreq_data *wrqu, char *extra)
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001393{
1394 *(extra) = country;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001395
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001396 return 0;
1397}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001398
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001399/*------------------------------------------------------------------*/
1400/*
1401 * Commit handler : called after a bunch of SET operations
1402 */
Joe Perches43ead782010-03-18 18:29:40 -07001403static int ray_commit(struct net_device *dev, struct iw_request_info *info,
1404 union iwreq_data *wrqu, char *extra)
1405{
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001406 return 0;
1407}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001408
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001409/*------------------------------------------------------------------*/
1410/*
1411 * Stats handler : return Wireless Stats
1412 */
John Daiker141fa612009-03-10 06:59:54 -07001413static iw_stats *ray_get_wireless_stats(struct net_device *dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001414{
John Daiker141fa612009-03-10 06:59:54 -07001415 ray_dev_t *local = netdev_priv(dev);
1416 struct pcmcia_device *link = local->finder;
1417 struct status __iomem *p = local->sram + STATUS_BASE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001418
John Daiker141fa612009-03-10 06:59:54 -07001419 local->wstats.status = local->card_status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001420#ifdef WIRELESS_SPY
John Daiker141fa612009-03-10 06:59:54 -07001421 if ((local->spy_data.spy_number > 0)
1422 && (local->sparm.b5.a_network_type == 0)) {
1423 /* Get it from the first node in spy list */
1424 local->wstats.qual.qual = local->spy_data.spy_stat[0].qual;
1425 local->wstats.qual.level = local->spy_data.spy_stat[0].level;
1426 local->wstats.qual.noise = local->spy_data.spy_stat[0].noise;
1427 local->wstats.qual.updated =
1428 local->spy_data.spy_stat[0].updated;
1429 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001430#endif /* WIRELESS_SPY */
1431
John Daiker141fa612009-03-10 06:59:54 -07001432 if (pcmcia_dev_present(link)) {
1433 local->wstats.qual.noise = readb(&p->rxnoise);
1434 local->wstats.qual.updated |= 4;
1435 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001436
John Daiker141fa612009-03-10 06:59:54 -07001437 return &local->wstats;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001438} /* end ray_get_wireless_stats */
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001439
1440/*------------------------------------------------------------------*/
1441/*
1442 * Structures to export the Wireless Handlers
1443 */
1444
John Daiker141fa612009-03-10 06:59:54 -07001445static const iw_handler ray_handler[] = {
Joe Perches43ead782010-03-18 18:29:40 -07001446 IW_HANDLER(SIOCSIWCOMMIT, ray_commit),
1447 IW_HANDLER(SIOCGIWNAME, ray_get_name),
1448 IW_HANDLER(SIOCSIWFREQ, ray_set_freq),
1449 IW_HANDLER(SIOCGIWFREQ, ray_get_freq),
1450 IW_HANDLER(SIOCSIWMODE, ray_set_mode),
1451 IW_HANDLER(SIOCGIWMODE, ray_get_mode),
1452 IW_HANDLER(SIOCGIWRANGE, ray_get_range),
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001453#ifdef WIRELESS_SPY
Joe Perches270020e2010-03-18 18:29:37 -07001454 IW_HANDLER(SIOCSIWSPY, iw_handler_set_spy),
1455 IW_HANDLER(SIOCGIWSPY, iw_handler_get_spy),
1456 IW_HANDLER(SIOCSIWTHRSPY, iw_handler_set_thrspy),
1457 IW_HANDLER(SIOCGIWTHRSPY, iw_handler_get_thrspy),
John Daiker141fa612009-03-10 06:59:54 -07001458#endif /* WIRELESS_SPY */
Joe Perches43ead782010-03-18 18:29:40 -07001459 IW_HANDLER(SIOCGIWAP, ray_get_wap),
1460 IW_HANDLER(SIOCSIWESSID, ray_set_essid),
1461 IW_HANDLER(SIOCGIWESSID, ray_get_essid),
1462 IW_HANDLER(SIOCSIWRATE, ray_set_rate),
1463 IW_HANDLER(SIOCGIWRATE, ray_get_rate),
1464 IW_HANDLER(SIOCSIWRTS, ray_set_rts),
1465 IW_HANDLER(SIOCGIWRTS, ray_get_rts),
1466 IW_HANDLER(SIOCSIWFRAG, ray_set_frag),
1467 IW_HANDLER(SIOCGIWFRAG, ray_get_frag),
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001468};
1469
John Daiker141fa612009-03-10 06:59:54 -07001470#define SIOCSIPFRAMING SIOCIWFIRSTPRIV /* Set framing mode */
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001471#define SIOCGIPFRAMING SIOCIWFIRSTPRIV + 1 /* Get framing mode */
1472#define SIOCGIPCOUNTRY SIOCIWFIRSTPRIV + 3 /* Get country code */
1473
John Daiker141fa612009-03-10 06:59:54 -07001474static const iw_handler ray_private_handler[] = {
Joe Perches43ead782010-03-18 18:29:40 -07001475 [0] = ray_set_framing,
1476 [1] = ray_get_framing,
1477 [3] = ray_get_country,
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001478};
1479
John Daiker141fa612009-03-10 06:59:54 -07001480static const struct iw_priv_args ray_private_args[] = {
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001481/* cmd, set_args, get_args, name */
John Daiker141fa612009-03-10 06:59:54 -07001482 {SIOCSIPFRAMING, IW_PRIV_TYPE_BYTE | IW_PRIV_SIZE_FIXED | 1, 0,
1483 "set_framing"},
1484 {SIOCGIPFRAMING, 0, IW_PRIV_TYPE_BYTE | IW_PRIV_SIZE_FIXED | 1,
1485 "get_framing"},
1486 {SIOCGIPCOUNTRY, 0, IW_PRIV_TYPE_BYTE | IW_PRIV_SIZE_FIXED | 1,
1487 "get_country"},
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001488};
1489
John Daiker141fa612009-03-10 06:59:54 -07001490static const struct iw_handler_def ray_handler_def = {
1491 .num_standard = ARRAY_SIZE(ray_handler),
1492 .num_private = ARRAY_SIZE(ray_private_handler),
Denis Chengff8ac602007-09-02 18:30:18 +08001493 .num_private_args = ARRAY_SIZE(ray_private_args),
John Daiker141fa612009-03-10 06:59:54 -07001494 .standard = ray_handler,
1495 .private = ray_private_handler,
1496 .private_args = ray_private_args,
Jean Tourrilhes3d5d5ac2005-09-02 11:40:39 -07001497 .get_wireless_stats = ray_get_wireless_stats,
1498};
1499
Linus Torvalds1da177e2005-04-16 15:20:36 -07001500/*===========================================================================*/
1501static int ray_open(struct net_device *dev)
1502{
John Daiker141fa612009-03-10 06:59:54 -07001503 ray_dev_t *local = netdev_priv(dev);
1504 struct pcmcia_device *link;
1505 link = local->finder;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001506
Dominik Brodowski624dd662009-10-24 15:52:44 +02001507 dev_dbg(&link->dev, "ray_open('%s')\n", dev->name);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001508
John Daiker141fa612009-03-10 06:59:54 -07001509 if (link->open == 0)
1510 local->num_multi = 0;
1511 link->open++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001512
John Daiker141fa612009-03-10 06:59:54 -07001513 /* If the card is not started, time to start it ! - Jean II */
1514 if (local->card_status == CARD_AWAITING_PARAM) {
1515 int i;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001516
Dominik Brodowski624dd662009-10-24 15:52:44 +02001517 dev_dbg(&link->dev, "ray_open: doing init now !\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001518
John Daiker141fa612009-03-10 06:59:54 -07001519 /* Download startup parameters */
1520 if ((i = dl_startup_params(dev)) < 0) {
1521 printk(KERN_INFO
1522 "ray_dev_init dl_startup_params failed - "
1523 "returns 0x%x\n", i);
1524 return -1;
1525 }
1526 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001527
John Daiker141fa612009-03-10 06:59:54 -07001528 if (sniffer)
1529 netif_stop_queue(dev);
1530 else
1531 netif_start_queue(dev);
1532
Dominik Brodowski624dd662009-10-24 15:52:44 +02001533 dev_dbg(&link->dev, "ray_open ending\n");
John Daiker141fa612009-03-10 06:59:54 -07001534 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001535} /* end ray_open */
John Daiker141fa612009-03-10 06:59:54 -07001536
Linus Torvalds1da177e2005-04-16 15:20:36 -07001537/*===========================================================================*/
1538static int ray_dev_close(struct net_device *dev)
1539{
John Daiker141fa612009-03-10 06:59:54 -07001540 ray_dev_t *local = netdev_priv(dev);
1541 struct pcmcia_device *link;
1542 link = local->finder;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001543
Dominik Brodowski624dd662009-10-24 15:52:44 +02001544 dev_dbg(&link->dev, "ray_dev_close('%s')\n", dev->name);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001545
John Daiker141fa612009-03-10 06:59:54 -07001546 link->open--;
1547 netif_stop_queue(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001548
John Daiker141fa612009-03-10 06:59:54 -07001549 /* In here, we should stop the hardware (stop card from beeing active)
1550 * and set local->card_status to CARD_AWAITING_PARAM, so that while the
1551 * card is closed we can chage its configuration.
1552 * Probably also need a COR reset to get sane state - Jean II */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001553
John Daiker141fa612009-03-10 06:59:54 -07001554 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001555} /* end ray_dev_close */
John Daiker141fa612009-03-10 06:59:54 -07001556
Linus Torvalds1da177e2005-04-16 15:20:36 -07001557/*===========================================================================*/
John Daiker141fa612009-03-10 06:59:54 -07001558static void ray_reset(struct net_device *dev)
1559{
Dominik Brodowski624dd662009-10-24 15:52:44 +02001560 pr_debug("ray_reset entered\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001561}
John Daiker141fa612009-03-10 06:59:54 -07001562
Linus Torvalds1da177e2005-04-16 15:20:36 -07001563/*===========================================================================*/
1564/* Cause a firmware interrupt if it is ready for one */
1565/* Return nonzero if not ready */
1566static int interrupt_ecf(ray_dev_t *local, int ccs)
1567{
John Daiker141fa612009-03-10 06:59:54 -07001568 int i = 50;
1569 struct pcmcia_device *link = local->finder;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001570
John Daiker141fa612009-03-10 06:59:54 -07001571 if (!(pcmcia_dev_present(link))) {
Dominik Brodowski624dd662009-10-24 15:52:44 +02001572 dev_dbg(&link->dev, "ray_cs interrupt_ecf - device not present\n");
John Daiker141fa612009-03-10 06:59:54 -07001573 return -1;
1574 }
Dominik Brodowski624dd662009-10-24 15:52:44 +02001575 dev_dbg(&link->dev, "interrupt_ecf(local=%p, ccs = 0x%x\n", local, ccs);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001576
John Daiker141fa612009-03-10 06:59:54 -07001577 while (i &&
1578 (readb(local->amem + CIS_OFFSET + ECF_INTR_OFFSET) &
1579 ECF_INTR_SET))
1580 i--;
1581 if (i == 0) {
Dominik Brodowski624dd662009-10-24 15:52:44 +02001582 dev_dbg(&link->dev, "ray_cs interrupt_ecf card not ready for interrupt\n");
John Daiker141fa612009-03-10 06:59:54 -07001583 return -1;
1584 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001585 /* Fill the mailbox, then kick the card */
John Daiker141fa612009-03-10 06:59:54 -07001586 writeb(ccs, local->sram + SCB_BASE);
1587 writeb(ECF_INTR_SET, local->amem + CIS_OFFSET + ECF_INTR_OFFSET);
1588 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001589} /* interrupt_ecf */
John Daiker141fa612009-03-10 06:59:54 -07001590
Linus Torvalds1da177e2005-04-16 15:20:36 -07001591/*===========================================================================*/
1592/* Get next free transmit CCS */
1593/* Return - index of current tx ccs */
1594static int get_free_tx_ccs(ray_dev_t *local)
1595{
John Daiker141fa612009-03-10 06:59:54 -07001596 int i;
1597 struct ccs __iomem *pccs = ccs_base(local);
1598 struct pcmcia_device *link = local->finder;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001599
John Daiker141fa612009-03-10 06:59:54 -07001600 if (!(pcmcia_dev_present(link))) {
Dominik Brodowski624dd662009-10-24 15:52:44 +02001601 dev_dbg(&link->dev, "ray_cs get_free_tx_ccs - device not present\n");
John Daiker141fa612009-03-10 06:59:54 -07001602 return ECARDGONE;
1603 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001604
John Daiker141fa612009-03-10 06:59:54 -07001605 if (test_and_set_bit(0, &local->tx_ccs_lock)) {
Dominik Brodowski624dd662009-10-24 15:52:44 +02001606 dev_dbg(&link->dev, "ray_cs tx_ccs_lock busy\n");
John Daiker141fa612009-03-10 06:59:54 -07001607 return ECCSBUSY;
1608 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001609
John Daiker141fa612009-03-10 06:59:54 -07001610 for (i = 0; i < NUMBER_OF_TX_CCS; i++) {
1611 if (readb(&(pccs + i)->buffer_status) == CCS_BUFFER_FREE) {
1612 writeb(CCS_BUFFER_BUSY, &(pccs + i)->buffer_status);
1613 writeb(CCS_END_LIST, &(pccs + i)->link);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001614 local->tx_ccs_lock = 0;
John Daiker141fa612009-03-10 06:59:54 -07001615 return i;
1616 }
1617 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001618 local->tx_ccs_lock = 0;
Dominik Brodowski624dd662009-10-24 15:52:44 +02001619 dev_dbg(&link->dev, "ray_cs ERROR no free tx CCS for raylink card\n");
John Daiker141fa612009-03-10 06:59:54 -07001620 return ECCSFULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001621} /* get_free_tx_ccs */
John Daiker141fa612009-03-10 06:59:54 -07001622
Linus Torvalds1da177e2005-04-16 15:20:36 -07001623/*===========================================================================*/
1624/* Get next free CCS */
1625/* Return - index of current ccs */
1626static int get_free_ccs(ray_dev_t *local)
1627{
John Daiker141fa612009-03-10 06:59:54 -07001628 int i;
1629 struct ccs __iomem *pccs = ccs_base(local);
1630 struct pcmcia_device *link = local->finder;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001631
John Daiker141fa612009-03-10 06:59:54 -07001632 if (!(pcmcia_dev_present(link))) {
Dominik Brodowski624dd662009-10-24 15:52:44 +02001633 dev_dbg(&link->dev, "ray_cs get_free_ccs - device not present\n");
John Daiker141fa612009-03-10 06:59:54 -07001634 return ECARDGONE;
1635 }
1636 if (test_and_set_bit(0, &local->ccs_lock)) {
Dominik Brodowski624dd662009-10-24 15:52:44 +02001637 dev_dbg(&link->dev, "ray_cs ccs_lock busy\n");
John Daiker141fa612009-03-10 06:59:54 -07001638 return ECCSBUSY;
1639 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001640
John Daiker141fa612009-03-10 06:59:54 -07001641 for (i = NUMBER_OF_TX_CCS; i < NUMBER_OF_CCS; i++) {
1642 if (readb(&(pccs + i)->buffer_status) == CCS_BUFFER_FREE) {
1643 writeb(CCS_BUFFER_BUSY, &(pccs + i)->buffer_status);
1644 writeb(CCS_END_LIST, &(pccs + i)->link);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001645 local->ccs_lock = 0;
John Daiker141fa612009-03-10 06:59:54 -07001646 return i;
1647 }
1648 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001649 local->ccs_lock = 0;
Dominik Brodowski624dd662009-10-24 15:52:44 +02001650 dev_dbg(&link->dev, "ray_cs ERROR no free CCS for raylink card\n");
John Daiker141fa612009-03-10 06:59:54 -07001651 return ECCSFULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001652} /* get_free_ccs */
John Daiker141fa612009-03-10 06:59:54 -07001653
Linus Torvalds1da177e2005-04-16 15:20:36 -07001654/*===========================================================================*/
1655static void authenticate_timeout(u_long data)
1656{
John Daiker141fa612009-03-10 06:59:54 -07001657 ray_dev_t *local = (ray_dev_t *) data;
1658 del_timer(&local->timer);
1659 printk(KERN_INFO "ray_cs Authentication with access point failed"
1660 " - timeout\n");
1661 join_net((u_long) local);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001662}
John Daiker141fa612009-03-10 06:59:54 -07001663
Linus Torvalds1da177e2005-04-16 15:20:36 -07001664/*===========================================================================*/
Linus Torvalds1da177e2005-04-16 15:20:36 -07001665static int parse_addr(char *in_str, UCHAR *out)
1666{
John Daiker141fa612009-03-10 06:59:54 -07001667 int len;
1668 int i, j, k;
1669 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001670
John Daiker141fa612009-03-10 06:59:54 -07001671 if (in_str == NULL)
1672 return 0;
1673 if ((len = strlen(in_str)) < 2)
1674 return 0;
1675 memset(out, 0, ADDRLEN);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001676
John Daiker141fa612009-03-10 06:59:54 -07001677 status = 1;
1678 j = len - 1;
1679 if (j > 12)
1680 j = 12;
1681 i = 5;
1682
1683 while (j > 0) {
Andy Shevchenko882d8292010-07-23 03:18:09 +00001684 if ((k = hex_to_bin(in_str[j--])) != -1)
John Daiker141fa612009-03-10 06:59:54 -07001685 out[i] = k;
1686 else
1687 return 0;
1688
1689 if (j == 0)
1690 break;
Andy Shevchenko882d8292010-07-23 03:18:09 +00001691 if ((k = hex_to_bin(in_str[j--])) != -1)
John Daiker141fa612009-03-10 06:59:54 -07001692 out[i] += k << 4;
1693 else
1694 return 0;
1695 if (!i--)
1696 break;
1697 }
1698 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001699}
John Daiker141fa612009-03-10 06:59:54 -07001700
Linus Torvalds1da177e2005-04-16 15:20:36 -07001701/*===========================================================================*/
1702static struct net_device_stats *ray_get_stats(struct net_device *dev)
1703{
John Daiker141fa612009-03-10 06:59:54 -07001704 ray_dev_t *local = netdev_priv(dev);
1705 struct pcmcia_device *link = local->finder;
1706 struct status __iomem *p = local->sram + STATUS_BASE;
1707 if (!(pcmcia_dev_present(link))) {
Dominik Brodowski624dd662009-10-24 15:52:44 +02001708 dev_dbg(&link->dev, "ray_cs net_device_stats - device not present\n");
John Daiker141fa612009-03-10 06:59:54 -07001709 return &local->stats;
1710 }
1711 if (readb(&p->mrx_overflow_for_host)) {
1712 local->stats.rx_over_errors += swab16(readw(&p->mrx_overflow));
1713 writeb(0, &p->mrx_overflow);
1714 writeb(0, &p->mrx_overflow_for_host);
1715 }
1716 if (readb(&p->mrx_checksum_error_for_host)) {
1717 local->stats.rx_crc_errors +=
1718 swab16(readw(&p->mrx_checksum_error));
1719 writeb(0, &p->mrx_checksum_error);
1720 writeb(0, &p->mrx_checksum_error_for_host);
1721 }
1722 if (readb(&p->rx_hec_error_for_host)) {
1723 local->stats.rx_frame_errors += swab16(readw(&p->rx_hec_error));
1724 writeb(0, &p->rx_hec_error);
1725 writeb(0, &p->rx_hec_error_for_host);
1726 }
1727 return &local->stats;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001728}
John Daiker141fa612009-03-10 06:59:54 -07001729
Linus Torvalds1da177e2005-04-16 15:20:36 -07001730/*===========================================================================*/
John Daiker141fa612009-03-10 06:59:54 -07001731static void ray_update_parm(struct net_device *dev, UCHAR objid, UCHAR *value,
1732 int len)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001733{
John Daiker141fa612009-03-10 06:59:54 -07001734 ray_dev_t *local = netdev_priv(dev);
1735 struct pcmcia_device *link = local->finder;
1736 int ccsindex;
1737 int i;
1738 struct ccs __iomem *pccs;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001739
John Daiker141fa612009-03-10 06:59:54 -07001740 if (!(pcmcia_dev_present(link))) {
Dominik Brodowski624dd662009-10-24 15:52:44 +02001741 dev_dbg(&link->dev, "ray_update_parm - device not present\n");
John Daiker141fa612009-03-10 06:59:54 -07001742 return;
1743 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001744
John Daiker141fa612009-03-10 06:59:54 -07001745 if ((ccsindex = get_free_ccs(local)) < 0) {
Dominik Brodowski624dd662009-10-24 15:52:44 +02001746 dev_dbg(&link->dev, "ray_update_parm - No free ccs\n");
John Daiker141fa612009-03-10 06:59:54 -07001747 return;
1748 }
1749 pccs = ccs_base(local) + ccsindex;
1750 writeb(CCS_UPDATE_PARAMS, &pccs->cmd);
1751 writeb(objid, &pccs->var.update_param.object_id);
1752 writeb(1, &pccs->var.update_param.number_objects);
1753 writeb(0, &pccs->var.update_param.failure_cause);
1754 for (i = 0; i < len; i++) {
1755 writeb(value[i], local->sram + HOST_TO_ECF_BASE);
1756 }
1757 /* Interrupt the firmware to process the command */
1758 if (interrupt_ecf(local, ccsindex)) {
Dominik Brodowski624dd662009-10-24 15:52:44 +02001759 dev_dbg(&link->dev, "ray_cs associate failed - ECF not ready for intr\n");
John Daiker141fa612009-03-10 06:59:54 -07001760 writeb(CCS_BUFFER_FREE, &(pccs++)->buffer_status);
1761 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001762}
John Daiker141fa612009-03-10 06:59:54 -07001763
Linus Torvalds1da177e2005-04-16 15:20:36 -07001764/*===========================================================================*/
1765static void ray_update_multi_list(struct net_device *dev, int all)
1766{
John Daiker141fa612009-03-10 06:59:54 -07001767 int ccsindex;
1768 struct ccs __iomem *pccs;
John Daiker141fa612009-03-10 06:59:54 -07001769 ray_dev_t *local = netdev_priv(dev);
1770 struct pcmcia_device *link = local->finder;
1771 void __iomem *p = local->sram + HOST_TO_ECF_BASE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001772
John Daiker141fa612009-03-10 06:59:54 -07001773 if (!(pcmcia_dev_present(link))) {
Dominik Brodowski624dd662009-10-24 15:52:44 +02001774 dev_dbg(&link->dev, "ray_update_multi_list - device not present\n");
John Daiker141fa612009-03-10 06:59:54 -07001775 return;
1776 } else
Dominik Brodowski624dd662009-10-24 15:52:44 +02001777 dev_dbg(&link->dev, "ray_update_multi_list(%p)\n", dev);
John Daiker141fa612009-03-10 06:59:54 -07001778 if ((ccsindex = get_free_ccs(local)) < 0) {
Dominik Brodowski624dd662009-10-24 15:52:44 +02001779 dev_dbg(&link->dev, "ray_update_multi - No free ccs\n");
John Daiker141fa612009-03-10 06:59:54 -07001780 return;
1781 }
1782 pccs = ccs_base(local) + ccsindex;
1783 writeb(CCS_UPDATE_MULTICAST_LIST, &pccs->cmd);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001784
John Daiker141fa612009-03-10 06:59:54 -07001785 if (all) {
1786 writeb(0xff, &pccs->var);
1787 local->num_multi = 0xff;
1788 } else {
Jiri Pirko22bedad32010-04-01 21:22:57 +00001789 struct netdev_hw_addr *ha;
Jiri Pirko655ffee2010-02-27 07:35:45 +00001790 int i = 0;
1791
John Daiker141fa612009-03-10 06:59:54 -07001792 /* Copy the kernel's list of MC addresses to card */
Jiri Pirko22bedad32010-04-01 21:22:57 +00001793 netdev_for_each_mc_addr(ha, dev) {
1794 memcpy_toio(p, ha->addr, ETH_ALEN);
Dominik Brodowski624dd662009-10-24 15:52:44 +02001795 dev_dbg(&link->dev,
John Daiker141fa612009-03-10 06:59:54 -07001796 "ray_update_multi add addr %02x%02x%02x%02x%02x%02x\n",
Jiri Pirko22bedad32010-04-01 21:22:57 +00001797 ha->addr[0], ha->addr[1],
1798 ha->addr[2], ha->addr[3],
1799 ha->addr[4], ha->addr[5]);
John Daiker141fa612009-03-10 06:59:54 -07001800 p += ETH_ALEN;
1801 i++;
1802 }
1803 if (i > 256 / ADDRLEN)
1804 i = 256 / ADDRLEN;
1805 writeb((UCHAR) i, &pccs->var);
Dominik Brodowski624dd662009-10-24 15:52:44 +02001806 dev_dbg(&link->dev, "ray_cs update_multi %d addresses in list\n", i);
John Daiker141fa612009-03-10 06:59:54 -07001807 /* Interrupt the firmware to process the command */
1808 local->num_multi = i;
1809 }
1810 if (interrupt_ecf(local, ccsindex)) {
Dominik Brodowski624dd662009-10-24 15:52:44 +02001811 dev_dbg(&link->dev,
John Daiker141fa612009-03-10 06:59:54 -07001812 "ray_cs update_multi failed - ECF not ready for intr\n");
1813 writeb(CCS_BUFFER_FREE, &(pccs++)->buffer_status);
1814 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001815} /* end ray_update_multi_list */
John Daiker141fa612009-03-10 06:59:54 -07001816
Linus Torvalds1da177e2005-04-16 15:20:36 -07001817/*===========================================================================*/
1818static void set_multicast_list(struct net_device *dev)
1819{
John Daiker141fa612009-03-10 06:59:54 -07001820 ray_dev_t *local = netdev_priv(dev);
1821 UCHAR promisc;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001822
Dominik Brodowski624dd662009-10-24 15:52:44 +02001823 pr_debug("ray_cs set_multicast_list(%p)\n", dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001824
John Daiker141fa612009-03-10 06:59:54 -07001825 if (dev->flags & IFF_PROMISC) {
1826 if (local->sparm.b5.a_promiscuous_mode == 0) {
Dominik Brodowski624dd662009-10-24 15:52:44 +02001827 pr_debug("ray_cs set_multicast_list promisc on\n");
John Daiker141fa612009-03-10 06:59:54 -07001828 local->sparm.b5.a_promiscuous_mode = 1;
1829 promisc = 1;
1830 ray_update_parm(dev, OBJID_promiscuous_mode,
1831 &promisc, sizeof(promisc));
1832 }
1833 } else {
1834 if (local->sparm.b5.a_promiscuous_mode == 1) {
Dominik Brodowski624dd662009-10-24 15:52:44 +02001835 pr_debug("ray_cs set_multicast_list promisc off\n");
John Daiker141fa612009-03-10 06:59:54 -07001836 local->sparm.b5.a_promiscuous_mode = 0;
1837 promisc = 0;
1838 ray_update_parm(dev, OBJID_promiscuous_mode,
1839 &promisc, sizeof(promisc));
1840 }
1841 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001842
John Daiker141fa612009-03-10 06:59:54 -07001843 if (dev->flags & IFF_ALLMULTI)
1844 ray_update_multi_list(dev, 1);
1845 else {
Jiri Pirko4cd24ea2010-02-08 04:30:35 +00001846 if (local->num_multi != netdev_mc_count(dev))
John Daiker141fa612009-03-10 06:59:54 -07001847 ray_update_multi_list(dev, 0);
1848 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001849} /* end set_multicast_list */
John Daiker141fa612009-03-10 06:59:54 -07001850
Linus Torvalds1da177e2005-04-16 15:20:36 -07001851/*=============================================================================
1852 * All routines below here are run at interrupt time.
1853=============================================================================*/
David Howells7d12e782006-10-05 14:55:46 +01001854static irqreturn_t ray_interrupt(int irq, void *dev_id)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001855{
John Daiker141fa612009-03-10 06:59:54 -07001856 struct net_device *dev = (struct net_device *)dev_id;
1857 struct pcmcia_device *link;
1858 ray_dev_t *local;
1859 struct ccs __iomem *pccs;
1860 struct rcs __iomem *prcs;
1861 UCHAR rcsindex;
1862 UCHAR tmp;
1863 UCHAR cmd;
1864 UCHAR status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001865
John Daiker141fa612009-03-10 06:59:54 -07001866 if (dev == NULL) /* Note that we want interrupts with dev->start == 0 */
1867 return IRQ_NONE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001868
Dominik Brodowski624dd662009-10-24 15:52:44 +02001869 pr_debug("ray_cs: interrupt for *dev=%p\n", dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001870
John Daiker141fa612009-03-10 06:59:54 -07001871 local = netdev_priv(dev);
1872 link = (struct pcmcia_device *)local->finder;
1873 if (!pcmcia_dev_present(link)) {
Dominik Brodowski624dd662009-10-24 15:52:44 +02001874 pr_debug(
1875 "ray_cs interrupt from device not present or suspended.\n");
John Daiker141fa612009-03-10 06:59:54 -07001876 return IRQ_NONE;
1877 }
1878 rcsindex = readb(&((struct scb __iomem *)(local->sram))->rcs_index);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001879
John Daiker141fa612009-03-10 06:59:54 -07001880 if (rcsindex >= (NUMBER_OF_CCS + NUMBER_OF_RCS)) {
Dominik Brodowski624dd662009-10-24 15:52:44 +02001881 dev_dbg(&link->dev, "ray_cs interrupt bad rcsindex = 0x%x\n", rcsindex);
John Daiker141fa612009-03-10 06:59:54 -07001882 clear_interrupt(local);
1883 return IRQ_HANDLED;
1884 }
1885 if (rcsindex < NUMBER_OF_CCS) { /* If it's a returned CCS */
1886 pccs = ccs_base(local) + rcsindex;
1887 cmd = readb(&pccs->cmd);
1888 status = readb(&pccs->buffer_status);
1889 switch (cmd) {
1890 case CCS_DOWNLOAD_STARTUP_PARAMS: /* Happens in firmware someday */
1891 del_timer(&local->timer);
1892 if (status == CCS_COMMAND_COMPLETE) {
Dominik Brodowski624dd662009-10-24 15:52:44 +02001893 dev_dbg(&link->dev,
John Daiker141fa612009-03-10 06:59:54 -07001894 "ray_cs interrupt download_startup_parameters OK\n");
1895 } else {
Dominik Brodowski624dd662009-10-24 15:52:44 +02001896 dev_dbg(&link->dev,
John Daiker141fa612009-03-10 06:59:54 -07001897 "ray_cs interrupt download_startup_parameters fail\n");
1898 }
1899 break;
1900 case CCS_UPDATE_PARAMS:
Dominik Brodowski624dd662009-10-24 15:52:44 +02001901 dev_dbg(&link->dev, "ray_cs interrupt update params done\n");
John Daiker141fa612009-03-10 06:59:54 -07001902 if (status != CCS_COMMAND_COMPLETE) {
1903 tmp =
1904 readb(&pccs->var.update_param.
1905 failure_cause);
Dominik Brodowski624dd662009-10-24 15:52:44 +02001906 dev_dbg(&link->dev,
John Daiker141fa612009-03-10 06:59:54 -07001907 "ray_cs interrupt update params failed - reason %d\n",
1908 tmp);
1909 }
1910 break;
1911 case CCS_REPORT_PARAMS:
Dominik Brodowski624dd662009-10-24 15:52:44 +02001912 dev_dbg(&link->dev, "ray_cs interrupt report params done\n");
John Daiker141fa612009-03-10 06:59:54 -07001913 break;
1914 case CCS_UPDATE_MULTICAST_LIST: /* Note that this CCS isn't returned */
Dominik Brodowski624dd662009-10-24 15:52:44 +02001915 dev_dbg(&link->dev,
John Daiker141fa612009-03-10 06:59:54 -07001916 "ray_cs interrupt CCS Update Multicast List done\n");
1917 break;
1918 case CCS_UPDATE_POWER_SAVINGS_MODE:
Dominik Brodowski624dd662009-10-24 15:52:44 +02001919 dev_dbg(&link->dev,
John Daiker141fa612009-03-10 06:59:54 -07001920 "ray_cs interrupt update power save mode done\n");
1921 break;
1922 case CCS_START_NETWORK:
1923 case CCS_JOIN_NETWORK:
1924 if (status == CCS_COMMAND_COMPLETE) {
1925 if (readb
1926 (&pccs->var.start_network.net_initiated) ==
1927 1) {
Dominik Brodowski624dd662009-10-24 15:52:44 +02001928 dev_dbg(&link->dev,
John Daiker141fa612009-03-10 06:59:54 -07001929 "ray_cs interrupt network \"%s\" started\n",
1930 local->sparm.b4.a_current_ess_id);
1931 } else {
Dominik Brodowski624dd662009-10-24 15:52:44 +02001932 dev_dbg(&link->dev,
John Daiker141fa612009-03-10 06:59:54 -07001933 "ray_cs interrupt network \"%s\" joined\n",
1934 local->sparm.b4.a_current_ess_id);
1935 }
1936 memcpy_fromio(&local->bss_id,
1937 pccs->var.start_network.bssid,
1938 ADDRLEN);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001939
John Daiker141fa612009-03-10 06:59:54 -07001940 if (local->fw_ver == 0x55)
1941 local->net_default_tx_rate = 3;
1942 else
1943 local->net_default_tx_rate =
1944 readb(&pccs->var.start_network.
1945 net_default_tx_rate);
1946 local->encryption =
1947 readb(&pccs->var.start_network.encryption);
1948 if (!sniffer && (local->net_type == INFRA)
1949 && !(local->sparm.b4.a_acting_as_ap_status)) {
1950 authenticate(local);
1951 }
1952 local->card_status = CARD_ACQ_COMPLETE;
1953 } else {
1954 local->card_status = CARD_ACQ_FAILED;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001955
John Daiker141fa612009-03-10 06:59:54 -07001956 del_timer(&local->timer);
1957 local->timer.expires = jiffies + HZ * 5;
1958 local->timer.data = (long)local;
1959 if (status == CCS_START_NETWORK) {
Dominik Brodowski624dd662009-10-24 15:52:44 +02001960 dev_dbg(&link->dev,
John Daiker141fa612009-03-10 06:59:54 -07001961 "ray_cs interrupt network \"%s\" start failed\n",
1962 local->sparm.b4.a_current_ess_id);
1963 local->timer.function = &start_net;
1964 } else {
Dominik Brodowski624dd662009-10-24 15:52:44 +02001965 dev_dbg(&link->dev,
John Daiker141fa612009-03-10 06:59:54 -07001966 "ray_cs interrupt network \"%s\" join failed\n",
1967 local->sparm.b4.a_current_ess_id);
1968 local->timer.function = &join_net;
1969 }
1970 add_timer(&local->timer);
1971 }
1972 break;
1973 case CCS_START_ASSOCIATION:
1974 if (status == CCS_COMMAND_COMPLETE) {
1975 local->card_status = CARD_ASSOC_COMPLETE;
Dominik Brodowski624dd662009-10-24 15:52:44 +02001976 dev_dbg(&link->dev, "ray_cs association successful\n");
John Daiker141fa612009-03-10 06:59:54 -07001977 } else {
Dominik Brodowski624dd662009-10-24 15:52:44 +02001978 dev_dbg(&link->dev, "ray_cs association failed,\n");
John Daiker141fa612009-03-10 06:59:54 -07001979 local->card_status = CARD_ASSOC_FAILED;
1980 join_net((u_long) local);
1981 }
1982 break;
1983 case CCS_TX_REQUEST:
1984 if (status == CCS_COMMAND_COMPLETE) {
Dominik Brodowski624dd662009-10-24 15:52:44 +02001985 dev_dbg(&link->dev,
John Daiker141fa612009-03-10 06:59:54 -07001986 "ray_cs interrupt tx request complete\n");
1987 } else {
Dominik Brodowski624dd662009-10-24 15:52:44 +02001988 dev_dbg(&link->dev,
John Daiker141fa612009-03-10 06:59:54 -07001989 "ray_cs interrupt tx request failed\n");
1990 }
1991 if (!sniffer)
1992 netif_start_queue(dev);
1993 netif_wake_queue(dev);
1994 break;
1995 case CCS_TEST_MEMORY:
Dominik Brodowski624dd662009-10-24 15:52:44 +02001996 dev_dbg(&link->dev, "ray_cs interrupt mem test done\n");
John Daiker141fa612009-03-10 06:59:54 -07001997 break;
1998 case CCS_SHUTDOWN:
Dominik Brodowski624dd662009-10-24 15:52:44 +02001999 dev_dbg(&link->dev,
John Daiker141fa612009-03-10 06:59:54 -07002000 "ray_cs interrupt Unexpected CCS returned - Shutdown\n");
2001 break;
2002 case CCS_DUMP_MEMORY:
Dominik Brodowski624dd662009-10-24 15:52:44 +02002003 dev_dbg(&link->dev, "ray_cs interrupt dump memory done\n");
John Daiker141fa612009-03-10 06:59:54 -07002004 break;
2005 case CCS_START_TIMER:
Dominik Brodowski624dd662009-10-24 15:52:44 +02002006 dev_dbg(&link->dev,
John Daiker141fa612009-03-10 06:59:54 -07002007 "ray_cs interrupt DING - raylink timer expired\n");
2008 break;
2009 default:
Dominik Brodowski624dd662009-10-24 15:52:44 +02002010 dev_dbg(&link->dev,
John Daiker141fa612009-03-10 06:59:54 -07002011 "ray_cs interrupt Unexpected CCS 0x%x returned 0x%x\n",
2012 rcsindex, cmd);
2013 }
2014 writeb(CCS_BUFFER_FREE, &pccs->buffer_status);
2015 } else { /* It's an RCS */
2016
2017 prcs = rcs_base(local) + rcsindex;
2018
2019 switch (readb(&prcs->interrupt_id)) {
2020 case PROCESS_RX_PACKET:
2021 ray_rx(dev, local, prcs);
2022 break;
2023 case REJOIN_NET_COMPLETE:
Dominik Brodowski624dd662009-10-24 15:52:44 +02002024 dev_dbg(&link->dev, "ray_cs interrupt rejoin net complete\n");
John Daiker141fa612009-03-10 06:59:54 -07002025 local->card_status = CARD_ACQ_COMPLETE;
2026 /* do we need to clear tx buffers CCS's? */
2027 if (local->sparm.b4.a_network_type == ADHOC) {
2028 if (!sniffer)
2029 netif_start_queue(dev);
2030 } else {
2031 memcpy_fromio(&local->bss_id,
2032 prcs->var.rejoin_net_complete.
2033 bssid, ADDRLEN);
Dominik Brodowski624dd662009-10-24 15:52:44 +02002034 dev_dbg(&link->dev,
John Daiker141fa612009-03-10 06:59:54 -07002035 "ray_cs new BSSID = %02x%02x%02x%02x%02x%02x\n",
2036 local->bss_id[0], local->bss_id[1],
2037 local->bss_id[2], local->bss_id[3],
2038 local->bss_id[4], local->bss_id[5]);
2039 if (!sniffer)
2040 authenticate(local);
2041 }
2042 break;
2043 case ROAMING_INITIATED:
Dominik Brodowski624dd662009-10-24 15:52:44 +02002044 dev_dbg(&link->dev, "ray_cs interrupt roaming initiated\n");
John Daiker141fa612009-03-10 06:59:54 -07002045 netif_stop_queue(dev);
2046 local->card_status = CARD_DOING_ACQ;
2047 break;
2048 case JAPAN_CALL_SIGN_RXD:
Dominik Brodowski624dd662009-10-24 15:52:44 +02002049 dev_dbg(&link->dev, "ray_cs interrupt japan call sign rx\n");
John Daiker141fa612009-03-10 06:59:54 -07002050 break;
2051 default:
Dominik Brodowski624dd662009-10-24 15:52:44 +02002052 dev_dbg(&link->dev,
John Daiker141fa612009-03-10 06:59:54 -07002053 "ray_cs Unexpected interrupt for RCS 0x%x cmd = 0x%x\n",
2054 rcsindex,
2055 (unsigned int)readb(&prcs->interrupt_id));
2056 break;
2057 }
2058 writeb(CCS_BUFFER_FREE, &prcs->buffer_status);
2059 }
2060 clear_interrupt(local);
2061 return IRQ_HANDLED;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002062} /* ray_interrupt */
John Daiker141fa612009-03-10 06:59:54 -07002063
Linus Torvalds1da177e2005-04-16 15:20:36 -07002064/*===========================================================================*/
John Daiker141fa612009-03-10 06:59:54 -07002065static void ray_rx(struct net_device *dev, ray_dev_t *local,
2066 struct rcs __iomem *prcs)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002067{
John Daiker141fa612009-03-10 06:59:54 -07002068 int rx_len;
2069 unsigned int pkt_addr;
2070 void __iomem *pmsg;
Dominik Brodowski624dd662009-10-24 15:52:44 +02002071 pr_debug("ray_rx process rx packet\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002072
John Daiker141fa612009-03-10 06:59:54 -07002073 /* Calculate address of packet within Rx buffer */
2074 pkt_addr = ((readb(&prcs->var.rx_packet.rx_data_ptr[0]) << 8)
2075 + readb(&prcs->var.rx_packet.rx_data_ptr[1])) & RX_BUFF_END;
2076 /* Length of first packet fragment */
2077 rx_len = (readb(&prcs->var.rx_packet.rx_data_length[0]) << 8)
2078 + readb(&prcs->var.rx_packet.rx_data_length[1]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002079
John Daiker141fa612009-03-10 06:59:54 -07002080 local->last_rsl = readb(&prcs->var.rx_packet.rx_sig_lev);
2081 pmsg = local->rmem + pkt_addr;
2082 switch (readb(pmsg)) {
2083 case DATA_TYPE:
Dominik Brodowski624dd662009-10-24 15:52:44 +02002084 pr_debug("ray_rx data type\n");
John Daiker141fa612009-03-10 06:59:54 -07002085 rx_data(dev, prcs, pkt_addr, rx_len);
2086 break;
2087 case AUTHENTIC_TYPE:
Dominik Brodowski624dd662009-10-24 15:52:44 +02002088 pr_debug("ray_rx authentic type\n");
John Daiker141fa612009-03-10 06:59:54 -07002089 if (sniffer)
2090 rx_data(dev, prcs, pkt_addr, rx_len);
2091 else
2092 rx_authenticate(local, prcs, pkt_addr, rx_len);
2093 break;
2094 case DEAUTHENTIC_TYPE:
Dominik Brodowski624dd662009-10-24 15:52:44 +02002095 pr_debug("ray_rx deauth type\n");
John Daiker141fa612009-03-10 06:59:54 -07002096 if (sniffer)
2097 rx_data(dev, prcs, pkt_addr, rx_len);
2098 else
2099 rx_deauthenticate(local, prcs, pkt_addr, rx_len);
2100 break;
2101 case NULL_MSG_TYPE:
Dominik Brodowski624dd662009-10-24 15:52:44 +02002102 pr_debug("ray_cs rx NULL msg\n");
John Daiker141fa612009-03-10 06:59:54 -07002103 break;
2104 case BEACON_TYPE:
Dominik Brodowski624dd662009-10-24 15:52:44 +02002105 pr_debug("ray_rx beacon type\n");
John Daiker141fa612009-03-10 06:59:54 -07002106 if (sniffer)
2107 rx_data(dev, prcs, pkt_addr, rx_len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002108
John Daiker141fa612009-03-10 06:59:54 -07002109 copy_from_rx_buff(local, (UCHAR *) &local->last_bcn, pkt_addr,
2110 rx_len < sizeof(struct beacon_rx) ?
2111 rx_len : sizeof(struct beacon_rx));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002112
John Daiker141fa612009-03-10 06:59:54 -07002113 local->beacon_rxed = 1;
2114 /* Get the statistics so the card counters never overflow */
2115 ray_get_stats(dev);
2116 break;
2117 default:
Dominik Brodowski624dd662009-10-24 15:52:44 +02002118 pr_debug("ray_cs unknown pkt type %2x\n",
John Daiker141fa612009-03-10 06:59:54 -07002119 (unsigned int)readb(pmsg));
2120 break;
2121 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002122
2123} /* end ray_rx */
John Daiker141fa612009-03-10 06:59:54 -07002124
Linus Torvalds1da177e2005-04-16 15:20:36 -07002125/*===========================================================================*/
John Daiker141fa612009-03-10 06:59:54 -07002126static void rx_data(struct net_device *dev, struct rcs __iomem *prcs,
2127 unsigned int pkt_addr, int rx_len)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002128{
John Daiker141fa612009-03-10 06:59:54 -07002129 struct sk_buff *skb = NULL;
2130 struct rcs __iomem *prcslink = prcs;
2131 ray_dev_t *local = netdev_priv(dev);
2132 UCHAR *rx_ptr;
2133 int total_len;
2134 int tmp;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002135#ifdef WIRELESS_SPY
John Daiker141fa612009-03-10 06:59:54 -07002136 int siglev = local->last_rsl;
2137 u_char linksrcaddr[ETH_ALEN]; /* Other end of the wireless link */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002138#endif
2139
John Daiker141fa612009-03-10 06:59:54 -07002140 if (!sniffer) {
2141 if (translate) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002142/* TBD length needs fixing for translated header */
John Daiker141fa612009-03-10 06:59:54 -07002143 if (rx_len < (ETH_HLEN + RX_MAC_HEADER_LENGTH) ||
2144 rx_len >
2145 (dev->mtu + RX_MAC_HEADER_LENGTH + ETH_HLEN +
2146 FCS_LEN)) {
Dominik Brodowski624dd662009-10-24 15:52:44 +02002147 pr_debug(
Frans Popcb01b092010-03-24 19:46:34 +01002148 "ray_cs invalid packet length %d received\n",
John Daiker141fa612009-03-10 06:59:54 -07002149 rx_len);
2150 return;
2151 }
2152 } else { /* encapsulated ethernet */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002153
John Daiker141fa612009-03-10 06:59:54 -07002154 if (rx_len < (ETH_HLEN + RX_MAC_HEADER_LENGTH) ||
2155 rx_len >
2156 (dev->mtu + RX_MAC_HEADER_LENGTH + ETH_HLEN +
2157 FCS_LEN)) {
Dominik Brodowski624dd662009-10-24 15:52:44 +02002158 pr_debug(
Frans Popcb01b092010-03-24 19:46:34 +01002159 "ray_cs invalid packet length %d received\n",
John Daiker141fa612009-03-10 06:59:54 -07002160 rx_len);
2161 return;
2162 }
2163 }
2164 }
Dominik Brodowski624dd662009-10-24 15:52:44 +02002165 pr_debug("ray_cs rx_data packet\n");
John Daiker141fa612009-03-10 06:59:54 -07002166 /* If fragmented packet, verify sizes of fragments add up */
2167 if (readb(&prcs->var.rx_packet.next_frag_rcs_index) != 0xFF) {
Dominik Brodowski624dd662009-10-24 15:52:44 +02002168 pr_debug("ray_cs rx'ed fragment\n");
John Daiker141fa612009-03-10 06:59:54 -07002169 tmp = (readb(&prcs->var.rx_packet.totalpacketlength[0]) << 8)
2170 + readb(&prcs->var.rx_packet.totalpacketlength[1]);
2171 total_len = tmp;
2172 prcslink = prcs;
2173 do {
2174 tmp -=
2175 (readb(&prcslink->var.rx_packet.rx_data_length[0])
2176 << 8)
2177 + readb(&prcslink->var.rx_packet.rx_data_length[1]);
2178 if (readb(&prcslink->var.rx_packet.next_frag_rcs_index)
2179 == 0xFF || tmp < 0)
2180 break;
2181 prcslink = rcs_base(local)
2182 + readb(&prcslink->link_field);
2183 } while (1);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002184
John Daiker141fa612009-03-10 06:59:54 -07002185 if (tmp < 0) {
Dominik Brodowski624dd662009-10-24 15:52:44 +02002186 pr_debug(
John Daiker141fa612009-03-10 06:59:54 -07002187 "ray_cs rx_data fragment lengths don't add up\n");
2188 local->stats.rx_dropped++;
2189 release_frag_chain(local, prcs);
2190 return;
2191 }
2192 } else { /* Single unfragmented packet */
2193 total_len = rx_len;
2194 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002195
John Daiker141fa612009-03-10 06:59:54 -07002196 skb = dev_alloc_skb(total_len + 5);
2197 if (skb == NULL) {
Dominik Brodowski624dd662009-10-24 15:52:44 +02002198 pr_debug("ray_cs rx_data could not allocate skb\n");
John Daiker141fa612009-03-10 06:59:54 -07002199 local->stats.rx_dropped++;
2200 if (readb(&prcs->var.rx_packet.next_frag_rcs_index) != 0xFF)
2201 release_frag_chain(local, prcs);
2202 return;
2203 }
2204 skb_reserve(skb, 2); /* Align IP on 16 byte (TBD check this) */
2205
Dominik Brodowski624dd662009-10-24 15:52:44 +02002206 pr_debug("ray_cs rx_data total_len = %x, rx_len = %x\n", total_len,
John Daiker141fa612009-03-10 06:59:54 -07002207 rx_len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002208
2209/************************/
John Daiker141fa612009-03-10 06:59:54 -07002210 /* Reserve enough room for the whole damn packet. */
2211 rx_ptr = skb_put(skb, total_len);
2212 /* Copy the whole packet to sk_buff */
2213 rx_ptr +=
2214 copy_from_rx_buff(local, rx_ptr, pkt_addr & RX_BUFF_END, rx_len);
2215 /* Get source address */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002216#ifdef WIRELESS_SPY
John Daiker141fa612009-03-10 06:59:54 -07002217 skb_copy_from_linear_data_offset(skb,
2218 offsetof(struct mac_header, addr_2),
2219 linksrcaddr, ETH_ALEN);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002220#endif
John Daiker141fa612009-03-10 06:59:54 -07002221 /* Now, deal with encapsulation/translation/sniffer */
2222 if (!sniffer) {
2223 if (!translate) {
2224 /* Encapsulated ethernet, so just lop off 802.11 MAC header */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002225/* TBD reserve skb_reserve( skb, RX_MAC_HEADER_LENGTH); */
John Daiker141fa612009-03-10 06:59:54 -07002226 skb_pull(skb, RX_MAC_HEADER_LENGTH);
2227 } else {
2228 /* Do translation */
2229 untranslate(local, skb, total_len);
2230 }
2231 } else { /* sniffer mode, so just pass whole packet */
2232 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002233
2234/************************/
John Daiker141fa612009-03-10 06:59:54 -07002235 /* Now pick up the rest of the fragments if any */
2236 tmp = 17;
2237 if (readb(&prcs->var.rx_packet.next_frag_rcs_index) != 0xFF) {
2238 prcslink = prcs;
Dominik Brodowski624dd662009-10-24 15:52:44 +02002239 pr_debug("ray_cs rx_data in fragment loop\n");
John Daiker141fa612009-03-10 06:59:54 -07002240 do {
2241 prcslink = rcs_base(local)
2242 +
2243 readb(&prcslink->var.rx_packet.next_frag_rcs_index);
2244 rx_len =
2245 ((readb(&prcslink->var.rx_packet.rx_data_length[0])
2246 << 8)
2247 +
2248 readb(&prcslink->var.rx_packet.rx_data_length[1]))
2249 & RX_BUFF_END;
2250 pkt_addr =
2251 ((readb(&prcslink->var.rx_packet.rx_data_ptr[0]) <<
2252 8)
2253 + readb(&prcslink->var.rx_packet.rx_data_ptr[1]))
2254 & RX_BUFF_END;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002255
John Daiker141fa612009-03-10 06:59:54 -07002256 rx_ptr +=
2257 copy_from_rx_buff(local, rx_ptr, pkt_addr, rx_len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002258
John Daiker141fa612009-03-10 06:59:54 -07002259 } while (tmp-- &&
2260 readb(&prcslink->var.rx_packet.next_frag_rcs_index) !=
2261 0xFF);
2262 release_frag_chain(local, prcs);
2263 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002264
John Daiker141fa612009-03-10 06:59:54 -07002265 skb->protocol = eth_type_trans(skb, dev);
2266 netif_rx(skb);
2267 local->stats.rx_packets++;
2268 local->stats.rx_bytes += total_len;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002269
John Daiker141fa612009-03-10 06:59:54 -07002270 /* Gather signal strength per address */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002271#ifdef WIRELESS_SPY
John Daiker141fa612009-03-10 06:59:54 -07002272 /* For the Access Point or the node having started the ad-hoc net
2273 * note : ad-hoc work only in some specific configurations, but we
2274 * kludge in ray_get_wireless_stats... */
2275 if (!memcmp(linksrcaddr, local->bss_id, ETH_ALEN)) {
2276 /* Update statistics */
2277 /*local->wstats.qual.qual = none ? */
2278 local->wstats.qual.level = siglev;
2279 /*local->wstats.qual.noise = none ? */
2280 local->wstats.qual.updated = 0x2;
2281 }
2282 /* Now, update the spy stuff */
2283 {
2284 struct iw_quality wstats;
2285 wstats.level = siglev;
2286 /* wstats.noise = none ? */
2287 /* wstats.qual = none ? */
2288 wstats.updated = 0x2;
2289 /* Update spy records */
2290 wireless_spy_update(dev, linksrcaddr, &wstats);
2291 }
2292#endif /* WIRELESS_SPY */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002293} /* end rx_data */
John Daiker141fa612009-03-10 06:59:54 -07002294
Linus Torvalds1da177e2005-04-16 15:20:36 -07002295/*===========================================================================*/
2296static void untranslate(ray_dev_t *local, struct sk_buff *skb, int len)
2297{
John Daiker141fa612009-03-10 06:59:54 -07002298 snaphdr_t *psnap = (snaphdr_t *) (skb->data + RX_MAC_HEADER_LENGTH);
2299 struct ieee80211_hdr *pmac = (struct ieee80211_hdr *)skb->data;
2300 __be16 type = *(__be16 *) psnap->ethertype;
2301 int delta;
2302 struct ethhdr *peth;
2303 UCHAR srcaddr[ADDRLEN];
2304 UCHAR destaddr[ADDRLEN];
2305 static UCHAR org_bridge[3] = { 0, 0, 0xf8 };
2306 static UCHAR org_1042[3] = { 0, 0, 0 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002307
John Daiker141fa612009-03-10 06:59:54 -07002308 memcpy(destaddr, ieee80211_get_DA(pmac), ADDRLEN);
2309 memcpy(srcaddr, ieee80211_get_SA(pmac), ADDRLEN);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002310
Dominik Brodowski624dd662009-10-24 15:52:44 +02002311#if 0
2312 if {
Joe Perchesad361c92009-07-06 13:05:40 -07002313 print_hex_dump(KERN_DEBUG, "skb->data before untranslate: ",
2314 DUMP_PREFIX_NONE, 16, 1,
2315 skb->data, 64, true);
2316 printk(KERN_DEBUG
John Daiker141fa612009-03-10 06:59:54 -07002317 "type = %08x, xsap = %02x%02x%02x, org = %02x02x02x\n",
2318 ntohs(type), psnap->dsap, psnap->ssap, psnap->ctrl,
2319 psnap->org[0], psnap->org[1], psnap->org[2]);
2320 printk(KERN_DEBUG "untranslate skb->data = %p\n", skb->data);
2321 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002322#endif
2323
John Daiker141fa612009-03-10 06:59:54 -07002324 if (psnap->dsap != 0xaa || psnap->ssap != 0xaa || psnap->ctrl != 3) {
2325 /* not a snap type so leave it alone */
Dominik Brodowski624dd662009-10-24 15:52:44 +02002326 pr_debug("ray_cs untranslate NOT SNAP %02x %02x %02x\n",
John Daiker141fa612009-03-10 06:59:54 -07002327 psnap->dsap, psnap->ssap, psnap->ctrl);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002328
John Daiker141fa612009-03-10 06:59:54 -07002329 delta = RX_MAC_HEADER_LENGTH - ETH_HLEN;
2330 peth = (struct ethhdr *)(skb->data + delta);
2331 peth->h_proto = htons(len - RX_MAC_HEADER_LENGTH);
2332 } else { /* Its a SNAP */
2333 if (memcmp(psnap->org, org_bridge, 3) == 0) {
2334 /* EtherII and nuke the LLC */
Dominik Brodowski624dd662009-10-24 15:52:44 +02002335 pr_debug("ray_cs untranslate Bridge encap\n");
John Daiker141fa612009-03-10 06:59:54 -07002336 delta = RX_MAC_HEADER_LENGTH
2337 + sizeof(struct snaphdr_t) - ETH_HLEN;
2338 peth = (struct ethhdr *)(skb->data + delta);
2339 peth->h_proto = type;
2340 } else if (memcmp(psnap->org, org_1042, 3) == 0) {
2341 switch (ntohs(type)) {
2342 case ETH_P_IPX:
2343 case ETH_P_AARP:
Dominik Brodowski624dd662009-10-24 15:52:44 +02002344 pr_debug("ray_cs untranslate RFC IPX/AARP\n");
John Daiker141fa612009-03-10 06:59:54 -07002345 delta = RX_MAC_HEADER_LENGTH - ETH_HLEN;
2346 peth = (struct ethhdr *)(skb->data + delta);
2347 peth->h_proto =
2348 htons(len - RX_MAC_HEADER_LENGTH);
2349 break;
2350 default:
Dominik Brodowski624dd662009-10-24 15:52:44 +02002351 pr_debug("ray_cs untranslate RFC default\n");
John Daiker141fa612009-03-10 06:59:54 -07002352 delta = RX_MAC_HEADER_LENGTH +
2353 sizeof(struct snaphdr_t) - ETH_HLEN;
2354 peth = (struct ethhdr *)(skb->data + delta);
2355 peth->h_proto = type;
2356 break;
2357 }
2358 } else {
2359 printk("ray_cs untranslate very confused by packet\n");
2360 delta = RX_MAC_HEADER_LENGTH - ETH_HLEN;
2361 peth = (struct ethhdr *)(skb->data + delta);
2362 peth->h_proto = type;
2363 }
Al Viro7698d692007-12-29 04:55:50 -05002364 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002365/* TBD reserve skb_reserve(skb, delta); */
John Daiker141fa612009-03-10 06:59:54 -07002366 skb_pull(skb, delta);
Dominik Brodowski624dd662009-10-24 15:52:44 +02002367 pr_debug("untranslate after skb_pull(%d), skb->data = %p\n", delta,
John Daiker141fa612009-03-10 06:59:54 -07002368 skb->data);
2369 memcpy(peth->h_dest, destaddr, ADDRLEN);
2370 memcpy(peth->h_source, srcaddr, ADDRLEN);
Dominik Brodowski624dd662009-10-24 15:52:44 +02002371#if 0
2372 {
John Daiker141fa612009-03-10 06:59:54 -07002373 int i;
2374 printk(KERN_DEBUG "skb->data after untranslate:");
2375 for (i = 0; i < 64; i++)
2376 printk("%02x ", skb->data[i]);
2377 printk("\n");
2378 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002379#endif
2380} /* end untranslate */
John Daiker141fa612009-03-10 06:59:54 -07002381
Linus Torvalds1da177e2005-04-16 15:20:36 -07002382/*===========================================================================*/
2383/* Copy data from circular receive buffer to PC memory.
2384 * dest = destination address in PC memory
2385 * pkt_addr = source address in receive buffer
2386 * len = length of packet to copy
2387 */
John Daiker141fa612009-03-10 06:59:54 -07002388static int copy_from_rx_buff(ray_dev_t *local, UCHAR *dest, int pkt_addr,
2389 int length)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002390{
John Daiker141fa612009-03-10 06:59:54 -07002391 int wrap_bytes = (pkt_addr + length) - (RX_BUFF_END + 1);
2392 if (wrap_bytes <= 0) {
2393 memcpy_fromio(dest, local->rmem + pkt_addr, length);
2394 } else { /* Packet wrapped in circular buffer */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002395
John Daiker141fa612009-03-10 06:59:54 -07002396 memcpy_fromio(dest, local->rmem + pkt_addr,
2397 length - wrap_bytes);
2398 memcpy_fromio(dest + length - wrap_bytes, local->rmem,
2399 wrap_bytes);
2400 }
2401 return length;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002402}
John Daiker141fa612009-03-10 06:59:54 -07002403
2404/*===========================================================================*/
2405static void release_frag_chain(ray_dev_t *local, struct rcs __iomem *prcs)
2406{
2407 struct rcs __iomem *prcslink = prcs;
2408 int tmp = 17;
2409 unsigned rcsindex = readb(&prcs->var.rx_packet.next_frag_rcs_index);
2410
2411 while (tmp--) {
2412 writeb(CCS_BUFFER_FREE, &prcslink->buffer_status);
2413 if (rcsindex >= (NUMBER_OF_CCS + NUMBER_OF_RCS)) {
Dominik Brodowski624dd662009-10-24 15:52:44 +02002414 pr_debug("ray_cs interrupt bad rcsindex = 0x%x\n",
John Daiker141fa612009-03-10 06:59:54 -07002415 rcsindex);
2416 break;
2417 }
2418 prcslink = rcs_base(local) + rcsindex;
2419 rcsindex = readb(&prcslink->var.rx_packet.next_frag_rcs_index);
2420 }
2421 writeb(CCS_BUFFER_FREE, &prcslink->buffer_status);
2422}
2423
Linus Torvalds1da177e2005-04-16 15:20:36 -07002424/*===========================================================================*/
2425static void authenticate(ray_dev_t *local)
2426{
John Daiker141fa612009-03-10 06:59:54 -07002427 struct pcmcia_device *link = local->finder;
Dominik Brodowski624dd662009-10-24 15:52:44 +02002428 dev_dbg(&link->dev, "ray_cs Starting authentication.\n");
John Daiker141fa612009-03-10 06:59:54 -07002429 if (!(pcmcia_dev_present(link))) {
Dominik Brodowski624dd662009-10-24 15:52:44 +02002430 dev_dbg(&link->dev, "ray_cs authenticate - device not present\n");
John Daiker141fa612009-03-10 06:59:54 -07002431 return;
2432 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002433
John Daiker141fa612009-03-10 06:59:54 -07002434 del_timer(&local->timer);
2435 if (build_auth_frame(local, local->bss_id, OPEN_AUTH_REQUEST)) {
2436 local->timer.function = &join_net;
2437 } else {
2438 local->timer.function = &authenticate_timeout;
2439 }
2440 local->timer.expires = jiffies + HZ * 2;
2441 local->timer.data = (long)local;
2442 add_timer(&local->timer);
2443 local->authentication_state = AWAITING_RESPONSE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002444} /* end authenticate */
John Daiker141fa612009-03-10 06:59:54 -07002445
Linus Torvalds1da177e2005-04-16 15:20:36 -07002446/*===========================================================================*/
2447static void rx_authenticate(ray_dev_t *local, struct rcs __iomem *prcs,
John Daiker141fa612009-03-10 06:59:54 -07002448 unsigned int pkt_addr, int rx_len)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002449{
John Daiker141fa612009-03-10 06:59:54 -07002450 UCHAR buff[256];
2451 struct rx_msg *msg = (struct rx_msg *)buff;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002452
John Daiker141fa612009-03-10 06:59:54 -07002453 del_timer(&local->timer);
2454
2455 copy_from_rx_buff(local, buff, pkt_addr, rx_len & 0xff);
2456 /* if we are trying to get authenticated */
2457 if (local->sparm.b4.a_network_type == ADHOC) {
Dominik Brodowski624dd662009-10-24 15:52:44 +02002458 pr_debug("ray_cs rx_auth var= %02x %02x %02x %02x %02x %02x\n",
John Daiker141fa612009-03-10 06:59:54 -07002459 msg->var[0], msg->var[1], msg->var[2], msg->var[3],
2460 msg->var[4], msg->var[5]);
2461 if (msg->var[2] == 1) {
Dominik Brodowski624dd662009-10-24 15:52:44 +02002462 pr_debug("ray_cs Sending authentication response.\n");
John Daiker141fa612009-03-10 06:59:54 -07002463 if (!build_auth_frame
2464 (local, msg->mac.addr_2, OPEN_AUTH_RESPONSE)) {
2465 local->authentication_state = NEED_TO_AUTH;
2466 memcpy(local->auth_id, msg->mac.addr_2,
2467 ADDRLEN);
2468 }
2469 }
2470 } else { /* Infrastructure network */
2471
2472 if (local->authentication_state == AWAITING_RESPONSE) {
2473 /* Verify authentication sequence #2 and success */
2474 if (msg->var[2] == 2) {
2475 if ((msg->var[3] | msg->var[4]) == 0) {
Dominik Brodowski624dd662009-10-24 15:52:44 +02002476 pr_debug("Authentication successful\n");
John Daiker141fa612009-03-10 06:59:54 -07002477 local->card_status = CARD_AUTH_COMPLETE;
2478 associate(local);
2479 local->authentication_state =
2480 AUTHENTICATED;
2481 } else {
Dominik Brodowski624dd662009-10-24 15:52:44 +02002482 pr_debug("Authentication refused\n");
John Daiker141fa612009-03-10 06:59:54 -07002483 local->card_status = CARD_AUTH_REFUSED;
2484 join_net((u_long) local);
2485 local->authentication_state =
2486 UNAUTHENTICATED;
2487 }
2488 }
2489 }
2490 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002491
2492} /* end rx_authenticate */
John Daiker141fa612009-03-10 06:59:54 -07002493
Linus Torvalds1da177e2005-04-16 15:20:36 -07002494/*===========================================================================*/
2495static void associate(ray_dev_t *local)
2496{
John Daiker141fa612009-03-10 06:59:54 -07002497 struct ccs __iomem *pccs;
2498 struct pcmcia_device *link = local->finder;
2499 struct net_device *dev = link->priv;
2500 int ccsindex;
2501 if (!(pcmcia_dev_present(link))) {
Dominik Brodowski624dd662009-10-24 15:52:44 +02002502 dev_dbg(&link->dev, "ray_cs associate - device not present\n");
John Daiker141fa612009-03-10 06:59:54 -07002503 return;
2504 }
2505 /* If no tx buffers available, return */
2506 if ((ccsindex = get_free_ccs(local)) < 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002507/* TBD should never be here but... what if we are? */
Dominik Brodowski624dd662009-10-24 15:52:44 +02002508 dev_dbg(&link->dev, "ray_cs associate - No free ccs\n");
John Daiker141fa612009-03-10 06:59:54 -07002509 return;
2510 }
Dominik Brodowski624dd662009-10-24 15:52:44 +02002511 dev_dbg(&link->dev, "ray_cs Starting association with access point\n");
John Daiker141fa612009-03-10 06:59:54 -07002512 pccs = ccs_base(local) + ccsindex;
2513 /* fill in the CCS */
2514 writeb(CCS_START_ASSOCIATION, &pccs->cmd);
2515 /* Interrupt the firmware to process the command */
2516 if (interrupt_ecf(local, ccsindex)) {
Dominik Brodowski624dd662009-10-24 15:52:44 +02002517 dev_dbg(&link->dev, "ray_cs associate failed - ECF not ready for intr\n");
John Daiker141fa612009-03-10 06:59:54 -07002518 writeb(CCS_BUFFER_FREE, &(pccs++)->buffer_status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002519
John Daiker141fa612009-03-10 06:59:54 -07002520 del_timer(&local->timer);
2521 local->timer.expires = jiffies + HZ * 2;
2522 local->timer.data = (long)local;
2523 local->timer.function = &join_net;
2524 add_timer(&local->timer);
2525 local->card_status = CARD_ASSOC_FAILED;
2526 return;
2527 }
2528 if (!sniffer)
2529 netif_start_queue(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002530
2531} /* end associate */
John Daiker141fa612009-03-10 06:59:54 -07002532
Linus Torvalds1da177e2005-04-16 15:20:36 -07002533/*===========================================================================*/
John Daiker141fa612009-03-10 06:59:54 -07002534static void rx_deauthenticate(ray_dev_t *local, struct rcs __iomem *prcs,
2535 unsigned int pkt_addr, int rx_len)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002536{
2537/* UCHAR buff[256];
2538 struct rx_msg *msg = (struct rx_msg *)buff;
2539*/
Dominik Brodowski624dd662009-10-24 15:52:44 +02002540 pr_debug("Deauthentication frame received\n");
John Daiker141fa612009-03-10 06:59:54 -07002541 local->authentication_state = UNAUTHENTICATED;
2542 /* Need to reauthenticate or rejoin depending on reason code */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002543/* copy_from_rx_buff(local, buff, pkt_addr, rx_len & 0xff);
2544 */
2545}
John Daiker141fa612009-03-10 06:59:54 -07002546
Linus Torvalds1da177e2005-04-16 15:20:36 -07002547/*===========================================================================*/
2548static void clear_interrupt(ray_dev_t *local)
2549{
John Daiker141fa612009-03-10 06:59:54 -07002550 writeb(0, local->amem + CIS_OFFSET + HCS_INTR_OFFSET);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002551}
John Daiker141fa612009-03-10 06:59:54 -07002552
Linus Torvalds1da177e2005-04-16 15:20:36 -07002553/*===========================================================================*/
2554#ifdef CONFIG_PROC_FS
2555#define MAXDATA (PAGE_SIZE - 80)
2556
2557static char *card_status[] = {
John Daiker141fa612009-03-10 06:59:54 -07002558 "Card inserted - uninitialized", /* 0 */
2559 "Card not downloaded", /* 1 */
2560 "Waiting for download parameters", /* 2 */
2561 "Card doing acquisition", /* 3 */
2562 "Acquisition complete", /* 4 */
2563 "Authentication complete", /* 5 */
2564 "Association complete", /* 6 */
2565 "???", "???", "???", "???", /* 7 8 9 10 undefined */
2566 "Card init error", /* 11 */
2567 "Download parameters error", /* 12 */
2568 "???", /* 13 */
2569 "Acquisition failed", /* 14 */
2570 "Authentication refused", /* 15 */
2571 "Association failed" /* 16 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002572};
2573
John Daiker141fa612009-03-10 06:59:54 -07002574static char *nettype[] = { "Adhoc", "Infra " };
2575static char *framing[] = { "Encapsulation", "Translation" }
2576
Linus Torvalds1da177e2005-04-16 15:20:36 -07002577;
2578/*===========================================================================*/
Alexey Dobriyan6b914c52008-04-10 14:34:35 -07002579static int ray_cs_proc_show(struct seq_file *m, void *v)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002580{
2581/* Print current values which are not available via other means
John Daiker141fa612009-03-10 06:59:54 -07002582 * eg ifconfig
Linus Torvalds1da177e2005-04-16 15:20:36 -07002583 */
John Daiker141fa612009-03-10 06:59:54 -07002584 int i;
2585 struct pcmcia_device *link;
2586 struct net_device *dev;
2587 ray_dev_t *local;
2588 UCHAR *p;
2589 struct freq_hop_element *pfh;
2590 UCHAR c[33];
Linus Torvalds1da177e2005-04-16 15:20:36 -07002591
John Daiker141fa612009-03-10 06:59:54 -07002592 link = this_device;
2593 if (!link)
2594 return 0;
2595 dev = (struct net_device *)link->priv;
2596 if (!dev)
2597 return 0;
2598 local = netdev_priv(dev);
2599 if (!local)
2600 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002601
John Daiker141fa612009-03-10 06:59:54 -07002602 seq_puts(m, "Raylink Wireless LAN driver status\n");
2603 seq_printf(m, "%s\n", rcsid);
2604 /* build 4 does not report version, and field is 0x55 after memtest */
2605 seq_puts(m, "Firmware version = ");
2606 if (local->fw_ver == 0x55)
2607 seq_puts(m, "4 - Use dump_cis for more details\n");
2608 else
2609 seq_printf(m, "%2d.%02d.%02d\n",
2610 local->fw_ver, local->fw_bld, local->fw_var);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002611
John Daiker141fa612009-03-10 06:59:54 -07002612 for (i = 0; i < 32; i++)
2613 c[i] = local->sparm.b5.a_current_ess_id[i];
2614 c[32] = 0;
2615 seq_printf(m, "%s network ESSID = \"%s\"\n",
2616 nettype[local->sparm.b5.a_network_type], c);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002617
John Daiker141fa612009-03-10 06:59:54 -07002618 p = local->bss_id;
2619 seq_printf(m, "BSSID = %pM\n", p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002620
John Daiker141fa612009-03-10 06:59:54 -07002621 seq_printf(m, "Country code = %d\n",
2622 local->sparm.b5.a_curr_country_code);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002623
John Daiker141fa612009-03-10 06:59:54 -07002624 i = local->card_status;
2625 if (i < 0)
2626 i = 10;
2627 if (i > 16)
2628 i = 10;
2629 seq_printf(m, "Card status = %s\n", card_status[i]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002630
John Daiker141fa612009-03-10 06:59:54 -07002631 seq_printf(m, "Framing mode = %s\n", framing[translate]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002632
John Daiker141fa612009-03-10 06:59:54 -07002633 seq_printf(m, "Last pkt signal lvl = %d\n", local->last_rsl);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002634
John Daiker141fa612009-03-10 06:59:54 -07002635 if (local->beacon_rxed) {
2636 /* Pull some fields out of last beacon received */
2637 seq_printf(m, "Beacon Interval = %d Kus\n",
2638 local->last_bcn.beacon_intvl[0]
2639 + 256 * local->last_bcn.beacon_intvl[1]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002640
John Daiker141fa612009-03-10 06:59:54 -07002641 p = local->last_bcn.elements;
2642 if (p[0] == C_ESSID_ELEMENT_ID)
2643 p += p[1] + 2;
2644 else {
2645 seq_printf(m,
2646 "Parse beacon failed at essid element id = %d\n",
2647 p[0]);
2648 return 0;
2649 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002650
John Daiker141fa612009-03-10 06:59:54 -07002651 if (p[0] == C_SUPPORTED_RATES_ELEMENT_ID) {
2652 seq_puts(m, "Supported rate codes = ");
2653 for (i = 2; i < p[1] + 2; i++)
2654 seq_printf(m, "0x%02x ", p[i]);
2655 seq_putc(m, '\n');
2656 p += p[1] + 2;
2657 } else {
2658 seq_puts(m, "Parse beacon failed at rates element\n");
2659 return 0;
2660 }
2661
2662 if (p[0] == C_FH_PARAM_SET_ELEMENT_ID) {
2663 pfh = (struct freq_hop_element *)p;
2664 seq_printf(m, "Hop dwell = %d Kus\n",
2665 pfh->dwell_time[0] +
2666 256 * pfh->dwell_time[1]);
Frans Popcb01b092010-03-24 19:46:34 +01002667 seq_printf(m, "Hop set = %d\n",
John Daiker141fa612009-03-10 06:59:54 -07002668 pfh->hop_set);
Frans Popcb01b092010-03-24 19:46:34 +01002669 seq_printf(m, "Hop pattern = %d\n",
John Daiker141fa612009-03-10 06:59:54 -07002670 pfh->hop_pattern);
Frans Popcb01b092010-03-24 19:46:34 +01002671 seq_printf(m, "Hop index = %d\n",
John Daiker141fa612009-03-10 06:59:54 -07002672 pfh->hop_index);
2673 p += p[1] + 2;
2674 } else {
2675 seq_puts(m,
2676 "Parse beacon failed at FH param element\n");
2677 return 0;
2678 }
2679 } else {
2680 seq_puts(m, "No beacons received\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002681 }
John Daiker141fa612009-03-10 06:59:54 -07002682 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002683}
2684
Alexey Dobriyan6b914c52008-04-10 14:34:35 -07002685static int ray_cs_proc_open(struct inode *inode, struct file *file)
2686{
2687 return single_open(file, ray_cs_proc_show, NULL);
2688}
2689
2690static const struct file_operations ray_cs_proc_fops = {
John Daiker141fa612009-03-10 06:59:54 -07002691 .owner = THIS_MODULE,
2692 .open = ray_cs_proc_open,
2693 .read = seq_read,
2694 .llseek = seq_lseek,
2695 .release = single_release,
Alexey Dobriyan6b914c52008-04-10 14:34:35 -07002696};
Linus Torvalds1da177e2005-04-16 15:20:36 -07002697#endif
2698/*===========================================================================*/
2699static int build_auth_frame(ray_dev_t *local, UCHAR *dest, int auth_type)
2700{
John Daiker141fa612009-03-10 06:59:54 -07002701 int addr;
2702 struct ccs __iomem *pccs;
2703 struct tx_msg __iomem *ptx;
2704 int ccsindex;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002705
John Daiker141fa612009-03-10 06:59:54 -07002706 /* If no tx buffers available, return */
2707 if ((ccsindex = get_free_tx_ccs(local)) < 0) {
Dominik Brodowski624dd662009-10-24 15:52:44 +02002708 pr_debug("ray_cs send authenticate - No free tx ccs\n");
John Daiker141fa612009-03-10 06:59:54 -07002709 return -1;
2710 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002711
John Daiker141fa612009-03-10 06:59:54 -07002712 pccs = ccs_base(local) + ccsindex;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002713
John Daiker141fa612009-03-10 06:59:54 -07002714 /* Address in card space */
2715 addr = TX_BUF_BASE + (ccsindex << 11);
2716 /* fill in the CCS */
2717 writeb(CCS_TX_REQUEST, &pccs->cmd);
2718 writeb(addr >> 8, pccs->var.tx_request.tx_data_ptr);
2719 writeb(0x20, pccs->var.tx_request.tx_data_ptr + 1);
2720 writeb(TX_AUTHENTICATE_LENGTH_MSB, pccs->var.tx_request.tx_data_length);
2721 writeb(TX_AUTHENTICATE_LENGTH_LSB,
2722 pccs->var.tx_request.tx_data_length + 1);
2723 writeb(0, &pccs->var.tx_request.pow_sav_mode);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002724
John Daiker141fa612009-03-10 06:59:54 -07002725 ptx = local->sram + addr;
2726 /* fill in the mac header */
2727 writeb(PROTOCOL_VER | AUTHENTIC_TYPE, &ptx->mac.frame_ctl_1);
2728 writeb(0, &ptx->mac.frame_ctl_2);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002729
John Daiker141fa612009-03-10 06:59:54 -07002730 memcpy_toio(ptx->mac.addr_1, dest, ADDRLEN);
2731 memcpy_toio(ptx->mac.addr_2, local->sparm.b4.a_mac_addr, ADDRLEN);
2732 memcpy_toio(ptx->mac.addr_3, local->bss_id, ADDRLEN);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002733
John Daiker141fa612009-03-10 06:59:54 -07002734 /* Fill in msg body with protocol 00 00, sequence 01 00 ,status 00 00 */
2735 memset_io(ptx->var, 0, 6);
2736 writeb(auth_type & 0xff, ptx->var + 2);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002737
John Daiker141fa612009-03-10 06:59:54 -07002738 /* Interrupt the firmware to process the command */
2739 if (interrupt_ecf(local, ccsindex)) {
Dominik Brodowski624dd662009-10-24 15:52:44 +02002740 pr_debug(
John Daiker141fa612009-03-10 06:59:54 -07002741 "ray_cs send authentication request failed - ECF not ready for intr\n");
2742 writeb(CCS_BUFFER_FREE, &(pccs++)->buffer_status);
2743 return -1;
2744 }
2745 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002746} /* End build_auth_frame */
2747
2748/*===========================================================================*/
2749#ifdef CONFIG_PROC_FS
Alexey Dobriyan83daee02009-11-25 10:12:20 +03002750static ssize_t ray_cs_essid_proc_write(struct file *file,
2751 const char __user *buffer, size_t count, loff_t *pos)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002752{
2753 static char proc_essid[33];
Alan Cox575c9ed2009-10-27 15:35:55 +00002754 unsigned int len = count;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002755
2756 if (len > 32)
2757 len = 32;
2758 memset(proc_essid, 0, 33);
2759 if (copy_from_user(proc_essid, buffer, len))
2760 return -EFAULT;
2761 essid = proc_essid;
2762 return count;
2763}
2764
Alexey Dobriyan83daee02009-11-25 10:12:20 +03002765static const struct file_operations ray_cs_essid_proc_fops = {
2766 .owner = THIS_MODULE,
2767 .write = ray_cs_essid_proc_write,
2768};
2769
2770static ssize_t int_proc_write(struct file *file, const char __user *buffer,
2771 size_t count, loff_t *pos)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002772{
2773 static char proc_number[10];
2774 char *p;
2775 int nr, len;
2776
2777 if (!count)
2778 return 0;
2779
2780 if (count > 9)
2781 return -EINVAL;
2782 if (copy_from_user(proc_number, buffer, count))
2783 return -EFAULT;
2784 p = proc_number;
2785 nr = 0;
2786 len = count;
2787 do {
2788 unsigned int c = *p - '0';
2789 if (c > 9)
2790 return -EINVAL;
John Daiker141fa612009-03-10 06:59:54 -07002791 nr = nr * 10 + c;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002792 p++;
2793 } while (--len);
Alexey Dobriyan83daee02009-11-25 10:12:20 +03002794 *(int *)PDE(file->f_path.dentry->d_inode)->data = nr;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002795 return count;
2796}
Alexey Dobriyan83daee02009-11-25 10:12:20 +03002797
2798static const struct file_operations int_proc_fops = {
2799 .owner = THIS_MODULE,
2800 .write = int_proc_write,
2801};
Linus Torvalds1da177e2005-04-16 15:20:36 -07002802#endif
2803
Dominik Brodowskif57ea2a2005-06-27 16:28:24 -07002804static struct pcmcia_device_id ray_ids[] = {
2805 PCMCIA_DEVICE_MANF_CARD(0x01a6, 0x0000),
2806 PCMCIA_DEVICE_NULL,
2807};
John Daiker141fa612009-03-10 06:59:54 -07002808
Dominik Brodowskif57ea2a2005-06-27 16:28:24 -07002809MODULE_DEVICE_TABLE(pcmcia, ray_ids);
2810
Linus Torvalds1da177e2005-04-16 15:20:36 -07002811static struct pcmcia_driver ray_driver = {
John Daiker141fa612009-03-10 06:59:54 -07002812 .owner = THIS_MODULE,
Dominik Brodowski2e9b9812010-08-08 11:36:26 +02002813 .name = "ray_cs",
John Daiker141fa612009-03-10 06:59:54 -07002814 .probe = ray_probe,
2815 .remove = ray_detach,
2816 .id_table = ray_ids,
2817 .suspend = ray_suspend,
2818 .resume = ray_resume,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002819};
2820
2821static int __init init_ray_cs(void)
2822{
John Daiker141fa612009-03-10 06:59:54 -07002823 int rc;
2824
Dominik Brodowski624dd662009-10-24 15:52:44 +02002825 pr_debug("%s\n", rcsid);
John Daiker141fa612009-03-10 06:59:54 -07002826 rc = pcmcia_register_driver(&ray_driver);
Dominik Brodowski624dd662009-10-24 15:52:44 +02002827 pr_debug("raylink init_module register_pcmcia_driver returns 0x%x\n",
John Daiker141fa612009-03-10 06:59:54 -07002828 rc);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002829
2830#ifdef CONFIG_PROC_FS
John Daiker141fa612009-03-10 06:59:54 -07002831 proc_mkdir("driver/ray_cs", NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002832
John Daiker141fa612009-03-10 06:59:54 -07002833 proc_create("driver/ray_cs/ray_cs", 0, NULL, &ray_cs_proc_fops);
Alexey Dobriyan83daee02009-11-25 10:12:20 +03002834 proc_create("driver/ray_cs/essid", S_IWUSR, NULL, &ray_cs_essid_proc_fops);
2835 proc_create_data("driver/ray_cs/net_type", S_IWUSR, NULL, &int_proc_fops, &net_type);
2836 proc_create_data("driver/ray_cs/translate", S_IWUSR, NULL, &int_proc_fops, &translate);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002837#endif
John Daiker141fa612009-03-10 06:59:54 -07002838 if (translate != 0)
2839 translate = 1;
2840 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002841} /* init_ray_cs */
2842
2843/*===========================================================================*/
2844
2845static void __exit exit_ray_cs(void)
2846{
Dominik Brodowski624dd662009-10-24 15:52:44 +02002847 pr_debug("ray_cs: cleanup_module\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002848
2849#ifdef CONFIG_PROC_FS
John Daiker141fa612009-03-10 06:59:54 -07002850 remove_proc_entry("driver/ray_cs/ray_cs", NULL);
2851 remove_proc_entry("driver/ray_cs/essid", NULL);
2852 remove_proc_entry("driver/ray_cs/net_type", NULL);
2853 remove_proc_entry("driver/ray_cs/translate", NULL);
2854 remove_proc_entry("driver/ray_cs", NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002855#endif
2856
John Daiker141fa612009-03-10 06:59:54 -07002857 pcmcia_unregister_driver(&ray_driver);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002858} /* exit_ray_cs */
2859
2860module_init(init_ray_cs);
2861module_exit(exit_ray_cs);
2862
2863/*===========================================================================*/