Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /*============================================================================= |
| 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 Daiker | 141fa61 | 2009-03-10 06:59:54 -0700 | [diff] [blame] | 11 | * it under the terms of version 2 only of the GNU General Public License as |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 12 | * 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 Daiker | 141fa61 | 2009-03-10 06:59:54 -0700 | [diff] [blame] | 30 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 31 | =============================================================================*/ |
| 32 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 33 | #include <linux/module.h> |
| 34 | #include <linux/kernel.h> |
| 35 | #include <linux/proc_fs.h> |
| 36 | #include <linux/ptrace.h> |
Alexey Dobriyan | 6b914c5 | 2008-04-10 14:34:35 -0700 | [diff] [blame] | 37 | #include <linux/seq_file.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 38 | #include <linux/slab.h> |
| 39 | #include <linux/string.h> |
| 40 | #include <linux/timer.h> |
| 41 | #include <linux/init.h> |
| 42 | #include <linux/netdevice.h> |
| 43 | #include <linux/etherdevice.h> |
| 44 | #include <linux/if_arp.h> |
| 45 | #include <linux/ioport.h> |
| 46 | #include <linux/skbuff.h> |
| 47 | #include <linux/ethtool.h> |
Al Viro | 7698d69 | 2007-12-29 04:55:50 -0500 | [diff] [blame] | 48 | #include <linux/ieee80211.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 49 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 50 | #include <pcmcia/cs_types.h> |
| 51 | #include <pcmcia/cs.h> |
| 52 | #include <pcmcia/cistpl.h> |
| 53 | #include <pcmcia/cisreg.h> |
| 54 | #include <pcmcia/ds.h> |
| 55 | #include <pcmcia/mem_op.h> |
| 56 | |
| 57 | #include <linux/wireless.h> |
Michael Wu | 113b898 | 2006-08-13 23:27:17 -0700 | [diff] [blame] | 58 | #include <net/iw_handler.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 59 | |
| 60 | #include <asm/io.h> |
| 61 | #include <asm/system.h> |
| 62 | #include <asm/byteorder.h> |
| 63 | #include <asm/uaccess.h> |
| 64 | |
| 65 | /* Warning : these stuff will slow down the driver... */ |
| 66 | #define WIRELESS_SPY /* Enable spying addresses */ |
| 67 | /* Definitions we need for spy */ |
John Daiker | 141fa61 | 2009-03-10 06:59:54 -0700 | [diff] [blame] | 68 | typedef struct iw_statistics iw_stats; |
| 69 | typedef u_char mac_addr[ETH_ALEN]; /* Hardware address */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 70 | |
| 71 | #include "rayctl.h" |
| 72 | #include "ray_cs.h" |
| 73 | |
| 74 | /* All the PCMCIA modules use PCMCIA_DEBUG to control debugging. If |
| 75 | you do not define PCMCIA_DEBUG at all, all the debug code will be |
| 76 | left out. If you compile with PCMCIA_DEBUG=0, the debug code will |
| 77 | be present but disabled -- but it can then be enabled for specific |
| 78 | modules at load time with a 'pc_debug=#' option to insmod. |
| 79 | */ |
| 80 | |
| 81 | #ifdef RAYLINK_DEBUG |
| 82 | #define PCMCIA_DEBUG RAYLINK_DEBUG |
| 83 | #endif |
| 84 | #ifdef PCMCIA_DEBUG |
| 85 | static int ray_debug; |
| 86 | static int pc_debug = PCMCIA_DEBUG; |
| 87 | module_param(pc_debug, int, 0); |
| 88 | /* #define DEBUG(n, args...) if (pc_debug>(n)) printk(KERN_DEBUG args); */ |
John Daiker | 141fa61 | 2009-03-10 06:59:54 -0700 | [diff] [blame] | 89 | #define DEBUG(n, args...) if (pc_debug > (n)) printk(args); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 90 | #else |
| 91 | #define DEBUG(n, args...) |
| 92 | #endif |
| 93 | /** Prototypes based on PCMCIA skeleton driver *******************************/ |
Dominik Brodowski | 15b99ac | 2006-03-31 17:26:06 +0200 | [diff] [blame] | 94 | static int ray_config(struct pcmcia_device *link); |
Dominik Brodowski | fba395e | 2006-03-31 17:21:06 +0200 | [diff] [blame] | 95 | static void ray_release(struct pcmcia_device *link); |
Dominik Brodowski | cc3b486 | 2005-11-14 21:23:14 +0100 | [diff] [blame] | 96 | static void ray_detach(struct pcmcia_device *p_dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 97 | |
| 98 | /***** Prototypes indicated by device structure ******************************/ |
| 99 | static int ray_dev_close(struct net_device *dev); |
| 100 | static int ray_dev_config(struct net_device *dev, struct ifmap *map); |
| 101 | static struct net_device_stats *ray_get_stats(struct net_device *dev); |
| 102 | static int ray_dev_init(struct net_device *dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 103 | |
Jeff Garzik | 7282d49 | 2006-09-13 14:30:00 -0400 | [diff] [blame] | 104 | static const struct ethtool_ops netdev_ethtool_ops; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 105 | |
| 106 | static int ray_open(struct net_device *dev); |
| 107 | static int ray_dev_start_xmit(struct sk_buff *skb, struct net_device *dev); |
| 108 | static void set_multicast_list(struct net_device *dev); |
| 109 | static void ray_update_multi_list(struct net_device *dev, int all); |
| 110 | static int translate_frame(ray_dev_t *local, struct tx_msg __iomem *ptx, |
John Daiker | 141fa61 | 2009-03-10 06:59:54 -0700 | [diff] [blame] | 111 | unsigned char *data, int len); |
| 112 | static void ray_build_header(ray_dev_t *local, struct tx_msg __iomem *ptx, |
| 113 | UCHAR msg_type, unsigned char *data); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 114 | static void untranslate(ray_dev_t *local, struct sk_buff *skb, int len); |
John Daiker | 141fa61 | 2009-03-10 06:59:54 -0700 | [diff] [blame] | 115 | static iw_stats *ray_get_wireless_stats(struct net_device *dev); |
| 116 | static const struct iw_handler_def ray_handler_def; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 117 | |
| 118 | /***** Prototypes for raylink functions **************************************/ |
| 119 | static int asc_to_int(char a); |
| 120 | static void authenticate(ray_dev_t *local); |
| 121 | static int build_auth_frame(ray_dev_t *local, UCHAR *dest, int auth_type); |
| 122 | static void authenticate_timeout(u_long); |
| 123 | static int get_free_ccs(ray_dev_t *local); |
| 124 | static int get_free_tx_ccs(ray_dev_t *local); |
| 125 | static void init_startup_params(ray_dev_t *local); |
| 126 | static int parse_addr(char *in_str, UCHAR *out); |
John Daiker | 141fa61 | 2009-03-10 06:59:54 -0700 | [diff] [blame] | 127 | static int ray_hw_xmit(unsigned char *data, int len, struct net_device *dev, UCHAR type); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 128 | static int ray_init(struct net_device *dev); |
| 129 | static int interrupt_ecf(ray_dev_t *local, int ccs); |
| 130 | static void ray_reset(struct net_device *dev); |
| 131 | static void ray_update_parm(struct net_device *dev, UCHAR objid, UCHAR *value, int len); |
| 132 | static void verify_dl_startup(u_long); |
| 133 | |
| 134 | /* Prototypes for interrpt time functions **********************************/ |
John Daiker | 141fa61 | 2009-03-10 06:59:54 -0700 | [diff] [blame] | 135 | static irqreturn_t ray_interrupt(int reg, void *dev_id); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 136 | static void clear_interrupt(ray_dev_t *local); |
John Daiker | 141fa61 | 2009-03-10 06:59:54 -0700 | [diff] [blame] | 137 | static void rx_deauthenticate(ray_dev_t *local, struct rcs __iomem *prcs, |
| 138 | unsigned int pkt_addr, int rx_len); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 139 | static int copy_from_rx_buff(ray_dev_t *local, UCHAR *dest, int pkt_addr, int len); |
| 140 | static void ray_rx(struct net_device *dev, ray_dev_t *local, struct rcs __iomem *prcs); |
| 141 | static void release_frag_chain(ray_dev_t *local, struct rcs __iomem *prcs); |
| 142 | static void rx_authenticate(ray_dev_t *local, struct rcs __iomem *prcs, |
John Daiker | 141fa61 | 2009-03-10 06:59:54 -0700 | [diff] [blame] | 143 | unsigned int pkt_addr, int rx_len); |
| 144 | static void rx_data(struct net_device *dev, struct rcs __iomem *prcs, |
| 145 | unsigned int pkt_addr, int rx_len); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 146 | static void associate(ray_dev_t *local); |
| 147 | |
| 148 | /* Card command functions */ |
| 149 | static int dl_startup_params(struct net_device *dev); |
| 150 | static void join_net(u_long local); |
| 151 | static void start_net(u_long local); |
| 152 | /* void start_net(ray_dev_t *local); */ |
| 153 | |
| 154 | /*===========================================================================*/ |
| 155 | /* Parameters that can be set with 'insmod' */ |
| 156 | |
| 157 | /* ADHOC=0, Infrastructure=1 */ |
| 158 | static int net_type = ADHOC; |
| 159 | |
| 160 | /* Hop dwell time in Kus (1024 us units defined by 802.11) */ |
| 161 | static int hop_dwell = 128; |
| 162 | |
| 163 | /* Beacon period in Kus */ |
| 164 | static int beacon_period = 256; |
| 165 | |
| 166 | /* power save mode (0 = off, 1 = save power) */ |
| 167 | static int psm; |
| 168 | |
| 169 | /* String for network's Extended Service Set ID. 32 Characters max */ |
| 170 | static char *essid; |
| 171 | |
| 172 | /* Default to encapsulation unless translation requested */ |
| 173 | static int translate = 1; |
| 174 | |
| 175 | static int country = USA; |
| 176 | |
| 177 | static int sniffer; |
| 178 | |
| 179 | static int bc; |
| 180 | |
| 181 | /* 48 bit physical card address if overriding card's real physical |
| 182 | * address is required. Since IEEE 802.11 addresses are 48 bits |
| 183 | * like ethernet, an int can't be used, so a string is used. To |
| 184 | * allow use of addresses starting with a decimal digit, the first |
| 185 | * character must be a letter and will be ignored. This letter is |
| 186 | * followed by up to 12 hex digits which are the address. If less |
| 187 | * than 12 digits are used, the address will be left filled with 0's. |
| 188 | * Note that bit 0 of the first byte is the broadcast bit, and evil |
| 189 | * things will happen if it is not 0 in a card address. |
| 190 | */ |
| 191 | static char *phy_addr = NULL; |
| 192 | |
| 193 | |
Dominik Brodowski | fba395e | 2006-03-31 17:21:06 +0200 | [diff] [blame] | 194 | /* A struct pcmcia_device structure has fields for most things that are needed |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 195 | to keep track of a socket, but there will usually be some device |
| 196 | specific information that also needs to be kept track of. The |
Dominik Brodowski | fba395e | 2006-03-31 17:21:06 +0200 | [diff] [blame] | 197 | 'priv' pointer in a struct pcmcia_device structure can be used to point to |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 198 | a device-specific private data structure, like this. |
| 199 | */ |
| 200 | static unsigned int ray_mem_speed = 500; |
| 201 | |
Dominik Brodowski | fd23823 | 2006-03-05 10:45:09 +0100 | [diff] [blame] | 202 | /* WARNING: THIS DRIVER IS NOT CAPABLE OF HANDLING MULTIPLE DEVICES! */ |
| 203 | static struct pcmcia_device *this_device = NULL; |
| 204 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 205 | MODULE_AUTHOR("Corey Thomas <corey@world.std.com>"); |
| 206 | MODULE_DESCRIPTION("Raylink/WebGear wireless LAN driver"); |
| 207 | MODULE_LICENSE("GPL"); |
| 208 | |
| 209 | module_param(net_type, int, 0); |
| 210 | module_param(hop_dwell, int, 0); |
| 211 | module_param(beacon_period, int, 0); |
| 212 | module_param(psm, int, 0); |
| 213 | module_param(essid, charp, 0); |
| 214 | module_param(translate, int, 0); |
| 215 | module_param(country, int, 0); |
| 216 | module_param(sniffer, int, 0); |
| 217 | module_param(bc, int, 0); |
| 218 | module_param(phy_addr, charp, 0); |
| 219 | module_param(ray_mem_speed, int, 0); |
| 220 | |
| 221 | static UCHAR b5_default_startup_parms[] = { |
John Daiker | 141fa61 | 2009-03-10 06:59:54 -0700 | [diff] [blame] | 222 | 0, 0, /* Adhoc station */ |
| 223 | 'L', 'I', 'N', 'U', 'X', 0, 0, 0, /* 32 char ESSID */ |
| 224 | 0, 0, 0, 0, 0, 0, 0, 0, |
| 225 | 0, 0, 0, 0, 0, 0, 0, 0, |
| 226 | 0, 0, 0, 0, 0, 0, 0, 0, |
| 227 | 1, 0, /* Active scan, CA Mode */ |
| 228 | 0, 0, 0, 0, 0, 0, /* No default MAC addr */ |
| 229 | 0x7f, 0xff, /* Frag threshold */ |
| 230 | 0x00, 0x80, /* Hop time 128 Kus */ |
| 231 | 0x01, 0x00, /* Beacon period 256 Kus */ |
| 232 | 0x01, 0x07, 0xa3, /* DTIM, retries, ack timeout */ |
| 233 | 0x1d, 0x82, 0x4e, /* SIFS, DIFS, PIFS */ |
| 234 | 0x7f, 0xff, /* RTS threshold */ |
| 235 | 0x04, 0xe2, 0x38, 0xA4, /* scan_dwell, max_scan_dwell */ |
| 236 | 0x05, /* assoc resp timeout thresh */ |
| 237 | 0x08, 0x02, 0x08, /* adhoc, infra, super cycle max */ |
| 238 | 0, /* Promiscuous mode */ |
| 239 | 0x0c, 0x0bd, /* Unique word */ |
| 240 | 0x32, /* Slot time */ |
| 241 | 0xff, 0xff, /* roam-low snr, low snr count */ |
| 242 | 0x05, 0xff, /* Infra, adhoc missed bcn thresh */ |
| 243 | 0x01, 0x0b, 0x4f, /* USA, hop pattern, hop pat length */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 244 | /* b4 - b5 differences start here */ |
John Daiker | 141fa61 | 2009-03-10 06:59:54 -0700 | [diff] [blame] | 245 | 0x00, 0x3f, /* CW max */ |
| 246 | 0x00, 0x0f, /* CW min */ |
| 247 | 0x04, 0x08, /* Noise gain, limit offset */ |
| 248 | 0x28, 0x28, /* det rssi, med busy offsets */ |
| 249 | 7, /* det sync thresh */ |
| 250 | 0, 2, 2, /* test mode, min, max */ |
| 251 | 0, /* allow broadcast SSID probe resp */ |
| 252 | 0, 0, /* privacy must start, can join */ |
| 253 | 2, 0, 0, 0, 0, 0, 0, 0 /* basic rate set */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 254 | }; |
| 255 | |
| 256 | static UCHAR b4_default_startup_parms[] = { |
John Daiker | 141fa61 | 2009-03-10 06:59:54 -0700 | [diff] [blame] | 257 | 0, 0, /* Adhoc station */ |
| 258 | 'L', 'I', 'N', 'U', 'X', 0, 0, 0, /* 32 char ESSID */ |
| 259 | 0, 0, 0, 0, 0, 0, 0, 0, |
| 260 | 0, 0, 0, 0, 0, 0, 0, 0, |
| 261 | 0, 0, 0, 0, 0, 0, 0, 0, |
| 262 | 1, 0, /* Active scan, CA Mode */ |
| 263 | 0, 0, 0, 0, 0, 0, /* No default MAC addr */ |
| 264 | 0x7f, 0xff, /* Frag threshold */ |
| 265 | 0x02, 0x00, /* Hop time */ |
| 266 | 0x00, 0x01, /* Beacon period */ |
| 267 | 0x01, 0x07, 0xa3, /* DTIM, retries, ack timeout */ |
| 268 | 0x1d, 0x82, 0xce, /* SIFS, DIFS, PIFS */ |
| 269 | 0x7f, 0xff, /* RTS threshold */ |
| 270 | 0xfb, 0x1e, 0xc7, 0x5c, /* scan_dwell, max_scan_dwell */ |
| 271 | 0x05, /* assoc resp timeout thresh */ |
| 272 | 0x04, 0x02, 0x4, /* adhoc, infra, super cycle max */ |
| 273 | 0, /* Promiscuous mode */ |
| 274 | 0x0c, 0x0bd, /* Unique word */ |
| 275 | 0x4e, /* Slot time (TBD seems wrong) */ |
| 276 | 0xff, 0xff, /* roam-low snr, low snr count */ |
| 277 | 0x05, 0xff, /* Infra, adhoc missed bcn thresh */ |
| 278 | 0x01, 0x0b, 0x4e, /* USA, hop pattern, hop pat length */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 279 | /* b4 - b5 differences start here */ |
John Daiker | 141fa61 | 2009-03-10 06:59:54 -0700 | [diff] [blame] | 280 | 0x3f, 0x0f, /* CW max, min */ |
| 281 | 0x04, 0x08, /* Noise gain, limit offset */ |
| 282 | 0x28, 0x28, /* det rssi, med busy offsets */ |
| 283 | 7, /* det sync thresh */ |
| 284 | 0, 2, 2 /* test mode, min, max */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 285 | }; |
John Daiker | 141fa61 | 2009-03-10 06:59:54 -0700 | [diff] [blame] | 286 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 287 | /*===========================================================================*/ |
John Daiker | 141fa61 | 2009-03-10 06:59:54 -0700 | [diff] [blame] | 288 | static unsigned char eth2_llc[] = { 0xaa, 0xaa, 3, 0, 0, 0 }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 289 | |
| 290 | static char hop_pattern_length[] = { 1, |
John Daiker | 141fa61 | 2009-03-10 06:59:54 -0700 | [diff] [blame] | 291 | USA_HOP_MOD, EUROPE_HOP_MOD, |
| 292 | JAPAN_HOP_MOD, KOREA_HOP_MOD, |
| 293 | SPAIN_HOP_MOD, FRANCE_HOP_MOD, |
| 294 | ISRAEL_HOP_MOD, AUSTRALIA_HOP_MOD, |
| 295 | JAPAN_TEST_HOP_MOD |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 296 | }; |
| 297 | |
John Daiker | 141fa61 | 2009-03-10 06:59:54 -0700 | [diff] [blame] | 298 | static char rcsid[] = |
| 299 | "Raylink/WebGear wireless LAN - Corey <Thomas corey@world.std.com>"; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 300 | |
Stephen Hemminger | 32f5a33 | 2009-03-20 19:36:28 +0000 | [diff] [blame^] | 301 | static const struct net_device_ops ray_netdev_ops = { |
| 302 | .ndo_init = ray_dev_init, |
| 303 | .ndo_open = ray_open, |
| 304 | .ndo_stop = ray_dev_close, |
| 305 | .ndo_start_xmit = ray_dev_start_xmit, |
| 306 | .ndo_set_config = ray_dev_config, |
| 307 | .ndo_get_stats = ray_get_stats, |
| 308 | .ndo_set_multicast_list = set_multicast_list, |
| 309 | .ndo_change_mtu = eth_change_mtu, |
| 310 | .ndo_set_mac_address = eth_mac_addr, |
| 311 | .ndo_validate_addr = eth_validate_addr, |
| 312 | }; |
| 313 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 314 | /*============================================================================= |
| 315 | ray_attach() creates an "instance" of the driver, allocating |
| 316 | local data structures for one device. The device is registered |
| 317 | with Card Services. |
| 318 | The dev_link structure is initialized, but we don't actually |
| 319 | configure the card at this point -- we wait until we receive a |
| 320 | card insertion event. |
| 321 | =============================================================================*/ |
Dominik Brodowski | 15b99ac | 2006-03-31 17:26:06 +0200 | [diff] [blame] | 322 | static int ray_probe(struct pcmcia_device *p_dev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 323 | { |
John Daiker | 141fa61 | 2009-03-10 06:59:54 -0700 | [diff] [blame] | 324 | ray_dev_t *local; |
| 325 | struct net_device *dev; |
Dominik Brodowski | fd23823 | 2006-03-05 10:45:09 +0100 | [diff] [blame] | 326 | |
John Daiker | 141fa61 | 2009-03-10 06:59:54 -0700 | [diff] [blame] | 327 | DEBUG(1, "ray_attach()\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 328 | |
John Daiker | 141fa61 | 2009-03-10 06:59:54 -0700 | [diff] [blame] | 329 | /* Allocate space for private device-specific data */ |
| 330 | dev = alloc_etherdev(sizeof(ray_dev_t)); |
| 331 | if (!dev) |
| 332 | goto fail_alloc_dev; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 333 | |
John Daiker | 141fa61 | 2009-03-10 06:59:54 -0700 | [diff] [blame] | 334 | local = netdev_priv(dev); |
| 335 | local->finder = p_dev; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 336 | |
John Daiker | 141fa61 | 2009-03-10 06:59:54 -0700 | [diff] [blame] | 337 | /* The io structure describes IO port mapping. None used here */ |
| 338 | p_dev->io.NumPorts1 = 0; |
| 339 | p_dev->io.Attributes1 = IO_DATA_PATH_WIDTH_8; |
| 340 | p_dev->io.IOAddrLines = 5; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 341 | |
John Daiker | 141fa61 | 2009-03-10 06:59:54 -0700 | [diff] [blame] | 342 | /* Interrupt setup. For PCMCIA, driver takes what's given */ |
| 343 | p_dev->irq.Attributes = IRQ_TYPE_DYNAMIC_SHARING | IRQ_HANDLE_PRESENT; |
| 344 | p_dev->irq.IRQInfo1 = IRQ_LEVEL_ID; |
| 345 | p_dev->irq.Handler = &ray_interrupt; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 346 | |
John Daiker | 141fa61 | 2009-03-10 06:59:54 -0700 | [diff] [blame] | 347 | /* General socket configuration */ |
| 348 | p_dev->conf.Attributes = CONF_ENABLE_IRQ; |
| 349 | p_dev->conf.IntType = INT_MEMORY_AND_IO; |
| 350 | p_dev->conf.ConfigIndex = 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 351 | |
John Daiker | 141fa61 | 2009-03-10 06:59:54 -0700 | [diff] [blame] | 352 | p_dev->priv = dev; |
| 353 | p_dev->irq.Instance = dev; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 354 | |
John Daiker | 141fa61 | 2009-03-10 06:59:54 -0700 | [diff] [blame] | 355 | local->finder = p_dev; |
| 356 | local->card_status = CARD_INSERTED; |
| 357 | local->authentication_state = UNAUTHENTICATED; |
| 358 | local->num_multi = 0; |
| 359 | DEBUG(2, "ray_attach p_dev = %p, dev = %p, local = %p, intr = %p\n", |
| 360 | p_dev, dev, local, &ray_interrupt); |
| 361 | |
| 362 | /* Raylink entries in the device structure */ |
Stephen Hemminger | 32f5a33 | 2009-03-20 19:36:28 +0000 | [diff] [blame^] | 363 | dev->netdev_ops = &ray_netdev_ops; |
John Daiker | 141fa61 | 2009-03-10 06:59:54 -0700 | [diff] [blame] | 364 | SET_ETHTOOL_OPS(dev, &netdev_ethtool_ops); |
| 365 | dev->wireless_handlers = &ray_handler_def; |
Jean Tourrilhes | 3d5d5ac | 2005-09-02 11:40:39 -0700 | [diff] [blame] | 366 | #ifdef WIRELESS_SPY |
John Daiker | 141fa61 | 2009-03-10 06:59:54 -0700 | [diff] [blame] | 367 | local->wireless_data.spy_data = &local->spy_data; |
| 368 | dev->wireless_data = &local->wireless_data; |
| 369 | #endif /* WIRELESS_SPY */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 370 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 371 | |
John Daiker | 141fa61 | 2009-03-10 06:59:54 -0700 | [diff] [blame] | 372 | DEBUG(2, "ray_cs ray_attach calling ether_setup.)\n"); |
John Daiker | 141fa61 | 2009-03-10 06:59:54 -0700 | [diff] [blame] | 373 | netif_stop_queue(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 374 | |
John Daiker | 141fa61 | 2009-03-10 06:59:54 -0700 | [diff] [blame] | 375 | init_timer(&local->timer); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 376 | |
John Daiker | 141fa61 | 2009-03-10 06:59:54 -0700 | [diff] [blame] | 377 | this_device = p_dev; |
| 378 | return ray_config(p_dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 379 | |
| 380 | fail_alloc_dev: |
John Daiker | 141fa61 | 2009-03-10 06:59:54 -0700 | [diff] [blame] | 381 | return -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 382 | } /* ray_attach */ |
John Daiker | 141fa61 | 2009-03-10 06:59:54 -0700 | [diff] [blame] | 383 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 384 | /*============================================================================= |
| 385 | This deletes a driver "instance". The device is de-registered |
| 386 | with Card Services. If it has been released, all local data |
| 387 | structures are freed. Otherwise, the structures will be freed |
| 388 | when the device is released. |
| 389 | =============================================================================*/ |
Dominik Brodowski | fba395e | 2006-03-31 17:21:06 +0200 | [diff] [blame] | 390 | static void ray_detach(struct pcmcia_device *link) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 391 | { |
John Daiker | 141fa61 | 2009-03-10 06:59:54 -0700 | [diff] [blame] | 392 | struct net_device *dev; |
| 393 | ray_dev_t *local; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 394 | |
John Daiker | 141fa61 | 2009-03-10 06:59:54 -0700 | [diff] [blame] | 395 | DEBUG(1, "ray_detach(0x%p)\n", link); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 396 | |
John Daiker | 141fa61 | 2009-03-10 06:59:54 -0700 | [diff] [blame] | 397 | this_device = NULL; |
| 398 | dev = link->priv; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 399 | |
John Daiker | 141fa61 | 2009-03-10 06:59:54 -0700 | [diff] [blame] | 400 | ray_release(link); |
Dominik Brodowski | cc3b486 | 2005-11-14 21:23:14 +0100 | [diff] [blame] | 401 | |
John Daiker | 141fa61 | 2009-03-10 06:59:54 -0700 | [diff] [blame] | 402 | local = netdev_priv(dev); |
| 403 | del_timer(&local->timer); |
Dominik Brodowski | cc3b486 | 2005-11-14 21:23:14 +0100 | [diff] [blame] | 404 | |
John Daiker | 141fa61 | 2009-03-10 06:59:54 -0700 | [diff] [blame] | 405 | if (link->priv) { |
| 406 | if (link->dev_node) |
| 407 | unregister_netdev(dev); |
| 408 | free_netdev(dev); |
| 409 | } |
| 410 | DEBUG(2, "ray_cs ray_detach ending\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 411 | } /* ray_detach */ |
John Daiker | 141fa61 | 2009-03-10 06:59:54 -0700 | [diff] [blame] | 412 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 413 | /*============================================================================= |
| 414 | ray_config() is run after a CARD_INSERTION event |
| 415 | is received, to configure the PCMCIA socket, and to make the |
| 416 | ethernet device available to the system. |
| 417 | =============================================================================*/ |
| 418 | #define CS_CHECK(fn, ret) \ |
| 419 | do { last_fn = (fn); if ((last_ret = (ret)) != 0) goto cs_failed; } while (0) |
| 420 | #define MAX_TUPLE_SIZE 128 |
Dominik Brodowski | 15b99ac | 2006-03-31 17:26:06 +0200 | [diff] [blame] | 421 | static int ray_config(struct pcmcia_device *link) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 422 | { |
John Daiker | 141fa61 | 2009-03-10 06:59:54 -0700 | [diff] [blame] | 423 | int last_fn = 0, last_ret = 0; |
| 424 | int i; |
| 425 | win_req_t req; |
| 426 | memreq_t mem; |
| 427 | struct net_device *dev = (struct net_device *)link->priv; |
| 428 | ray_dev_t *local = netdev_priv(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 429 | |
John Daiker | 141fa61 | 2009-03-10 06:59:54 -0700 | [diff] [blame] | 430 | DEBUG(1, "ray_config(0x%p)\n", link); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 431 | |
John Daiker | 141fa61 | 2009-03-10 06:59:54 -0700 | [diff] [blame] | 432 | /* Determine card type and firmware version */ |
| 433 | printk(KERN_INFO "ray_cs Detected: %s%s%s%s\n", |
| 434 | link->prod_id[0] ? link->prod_id[0] : " ", |
| 435 | link->prod_id[1] ? link->prod_id[1] : " ", |
| 436 | link->prod_id[2] ? link->prod_id[2] : " ", |
| 437 | link->prod_id[3] ? link->prod_id[3] : " "); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 438 | |
John Daiker | 141fa61 | 2009-03-10 06:59:54 -0700 | [diff] [blame] | 439 | /* Now allocate an interrupt line. Note that this does not |
| 440 | actually assign a handler to the interrupt. |
| 441 | */ |
| 442 | CS_CHECK(RequestIRQ, pcmcia_request_irq(link, &link->irq)); |
| 443 | dev->irq = link->irq.AssignedIRQ; |
| 444 | |
| 445 | /* This actually configures the PCMCIA socket -- setting up |
| 446 | the I/O windows and the interrupt mapping. |
| 447 | */ |
| 448 | CS_CHECK(RequestConfiguration, |
| 449 | pcmcia_request_configuration(link, &link->conf)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 450 | |
| 451 | /*** Set up 32k window for shared memory (transmit and control) ************/ |
John Daiker | 141fa61 | 2009-03-10 06:59:54 -0700 | [diff] [blame] | 452 | req.Attributes = |
| 453 | WIN_DATA_WIDTH_8 | WIN_MEMORY_TYPE_CM | WIN_ENABLE | WIN_USE_WAIT; |
| 454 | req.Base = 0; |
| 455 | req.Size = 0x8000; |
| 456 | req.AccessSpeed = ray_mem_speed; |
| 457 | CS_CHECK(RequestWindow, pcmcia_request_window(&link, &req, &link->win)); |
| 458 | mem.CardOffset = 0x0000; |
| 459 | mem.Page = 0; |
| 460 | CS_CHECK(MapMemPage, pcmcia_map_mem_page(link->win, &mem)); |
| 461 | local->sram = ioremap(req.Base, req.Size); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 462 | |
| 463 | /*** Set up 16k window for shared memory (receive buffer) ***************/ |
John Daiker | 141fa61 | 2009-03-10 06:59:54 -0700 | [diff] [blame] | 464 | req.Attributes = |
| 465 | WIN_DATA_WIDTH_8 | WIN_MEMORY_TYPE_CM | WIN_ENABLE | WIN_USE_WAIT; |
| 466 | req.Base = 0; |
| 467 | req.Size = 0x4000; |
| 468 | req.AccessSpeed = ray_mem_speed; |
| 469 | CS_CHECK(RequestWindow, |
| 470 | pcmcia_request_window(&link, &req, &local->rmem_handle)); |
| 471 | mem.CardOffset = 0x8000; |
| 472 | mem.Page = 0; |
| 473 | CS_CHECK(MapMemPage, pcmcia_map_mem_page(local->rmem_handle, &mem)); |
| 474 | local->rmem = ioremap(req.Base, req.Size); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 475 | |
| 476 | /*** Set up window for attribute memory ***********************************/ |
John Daiker | 141fa61 | 2009-03-10 06:59:54 -0700 | [diff] [blame] | 477 | req.Attributes = |
| 478 | WIN_DATA_WIDTH_8 | WIN_MEMORY_TYPE_AM | WIN_ENABLE | WIN_USE_WAIT; |
| 479 | req.Base = 0; |
| 480 | req.Size = 0x1000; |
| 481 | req.AccessSpeed = ray_mem_speed; |
| 482 | CS_CHECK(RequestWindow, |
| 483 | pcmcia_request_window(&link, &req, &local->amem_handle)); |
| 484 | mem.CardOffset = 0x0000; |
| 485 | mem.Page = 0; |
| 486 | CS_CHECK(MapMemPage, pcmcia_map_mem_page(local->amem_handle, &mem)); |
| 487 | local->amem = ioremap(req.Base, req.Size); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 488 | |
John Daiker | 141fa61 | 2009-03-10 06:59:54 -0700 | [diff] [blame] | 489 | DEBUG(3, "ray_config sram=%p\n", local->sram); |
| 490 | DEBUG(3, "ray_config rmem=%p\n", local->rmem); |
| 491 | DEBUG(3, "ray_config amem=%p\n", local->amem); |
| 492 | if (ray_init(dev) < 0) { |
| 493 | ray_release(link); |
| 494 | return -ENODEV; |
| 495 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 496 | |
John Daiker | 141fa61 | 2009-03-10 06:59:54 -0700 | [diff] [blame] | 497 | SET_NETDEV_DEV(dev, &handle_to_dev(link)); |
| 498 | i = register_netdev(dev); |
| 499 | if (i != 0) { |
| 500 | printk("ray_config register_netdev() failed\n"); |
| 501 | ray_release(link); |
| 502 | return i; |
| 503 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 504 | |
John Daiker | 141fa61 | 2009-03-10 06:59:54 -0700 | [diff] [blame] | 505 | strcpy(local->node.dev_name, dev->name); |
| 506 | link->dev_node = &local->node; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 507 | |
John Daiker | 141fa61 | 2009-03-10 06:59:54 -0700 | [diff] [blame] | 508 | printk(KERN_INFO "%s: RayLink, irq %d, hw_addr %pM\n", |
| 509 | dev->name, dev->irq, dev->dev_addr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 510 | |
John Daiker | 141fa61 | 2009-03-10 06:59:54 -0700 | [diff] [blame] | 511 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 512 | |
| 513 | cs_failed: |
John Daiker | 141fa61 | 2009-03-10 06:59:54 -0700 | [diff] [blame] | 514 | cs_error(link, last_fn, last_ret); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 515 | |
John Daiker | 141fa61 | 2009-03-10 06:59:54 -0700 | [diff] [blame] | 516 | ray_release(link); |
| 517 | return -ENODEV; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 518 | } /* ray_config */ |
| 519 | |
| 520 | static inline struct ccs __iomem *ccs_base(ray_dev_t *dev) |
| 521 | { |
| 522 | return dev->sram + CCS_BASE; |
| 523 | } |
| 524 | |
| 525 | static inline struct rcs __iomem *rcs_base(ray_dev_t *dev) |
| 526 | { |
| 527 | /* |
| 528 | * This looks nonsensical, since there is a separate |
| 529 | * RCS_BASE. But the difference between a "struct rcs" |
| 530 | * and a "struct ccs" ends up being in the _index_ off |
| 531 | * the base, so the base pointer is the same for both |
| 532 | * ccs/rcs. |
| 533 | */ |
| 534 | return dev->sram + CCS_BASE; |
| 535 | } |
| 536 | |
| 537 | /*===========================================================================*/ |
| 538 | static int ray_init(struct net_device *dev) |
| 539 | { |
John Daiker | 141fa61 | 2009-03-10 06:59:54 -0700 | [diff] [blame] | 540 | int i; |
| 541 | UCHAR *p; |
| 542 | struct ccs __iomem *pccs; |
| 543 | ray_dev_t *local = netdev_priv(dev); |
| 544 | struct pcmcia_device *link = local->finder; |
| 545 | DEBUG(1, "ray_init(0x%p)\n", dev); |
| 546 | if (!(pcmcia_dev_present(link))) { |
| 547 | DEBUG(0, "ray_init - device not present\n"); |
| 548 | return -1; |
| 549 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 550 | |
John Daiker | 141fa61 | 2009-03-10 06:59:54 -0700 | [diff] [blame] | 551 | local->net_type = net_type; |
| 552 | local->sta_type = TYPE_STA; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 553 | |
John Daiker | 141fa61 | 2009-03-10 06:59:54 -0700 | [diff] [blame] | 554 | /* Copy the startup results to local memory */ |
| 555 | memcpy_fromio(&local->startup_res, local->sram + ECF_TO_HOST_BASE, |
| 556 | sizeof(struct startup_res_6)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 557 | |
John Daiker | 141fa61 | 2009-03-10 06:59:54 -0700 | [diff] [blame] | 558 | /* Check Power up test status and get mac address from card */ |
| 559 | if (local->startup_res.startup_word != 0x80) { |
| 560 | printk(KERN_INFO "ray_init ERROR card status = %2x\n", |
| 561 | local->startup_res.startup_word); |
| 562 | local->card_status = CARD_INIT_ERROR; |
| 563 | return -1; |
| 564 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 565 | |
John Daiker | 141fa61 | 2009-03-10 06:59:54 -0700 | [diff] [blame] | 566 | local->fw_ver = local->startup_res.firmware_version[0]; |
| 567 | local->fw_bld = local->startup_res.firmware_version[1]; |
| 568 | local->fw_var = local->startup_res.firmware_version[2]; |
| 569 | DEBUG(1, "ray_init firmware version %d.%d \n", local->fw_ver, |
| 570 | local->fw_bld); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 571 | |
John Daiker | 141fa61 | 2009-03-10 06:59:54 -0700 | [diff] [blame] | 572 | local->tib_length = 0x20; |
| 573 | if ((local->fw_ver == 5) && (local->fw_bld >= 30)) |
| 574 | local->tib_length = local->startup_res.tib_length; |
| 575 | DEBUG(2, "ray_init tib_length = 0x%02x\n", local->tib_length); |
| 576 | /* Initialize CCS's to buffer free state */ |
| 577 | pccs = ccs_base(local); |
| 578 | for (i = 0; i < NUMBER_OF_CCS; i++) { |
| 579 | writeb(CCS_BUFFER_FREE, &(pccs++)->buffer_status); |
| 580 | } |
| 581 | init_startup_params(local); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 582 | |
John Daiker | 141fa61 | 2009-03-10 06:59:54 -0700 | [diff] [blame] | 583 | /* copy mac address to startup parameters */ |
| 584 | if (parse_addr(phy_addr, local->sparm.b4.a_mac_addr)) { |
| 585 | p = local->sparm.b4.a_mac_addr; |
| 586 | } else { |
| 587 | memcpy(&local->sparm.b4.a_mac_addr, |
| 588 | &local->startup_res.station_addr, ADDRLEN); |
| 589 | p = local->sparm.b4.a_mac_addr; |
| 590 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 591 | |
John Daiker | 141fa61 | 2009-03-10 06:59:54 -0700 | [diff] [blame] | 592 | clear_interrupt(local); /* Clear any interrupt from the card */ |
| 593 | local->card_status = CARD_AWAITING_PARAM; |
| 594 | DEBUG(2, "ray_init ending\n"); |
| 595 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 596 | } /* ray_init */ |
John Daiker | 141fa61 | 2009-03-10 06:59:54 -0700 | [diff] [blame] | 597 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 598 | /*===========================================================================*/ |
| 599 | /* Download startup parameters to the card and command it to read them */ |
| 600 | static int dl_startup_params(struct net_device *dev) |
| 601 | { |
John Daiker | 141fa61 | 2009-03-10 06:59:54 -0700 | [diff] [blame] | 602 | int ccsindex; |
| 603 | ray_dev_t *local = netdev_priv(dev); |
| 604 | struct ccs __iomem *pccs; |
| 605 | struct pcmcia_device *link = local->finder; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 606 | |
John Daiker | 141fa61 | 2009-03-10 06:59:54 -0700 | [diff] [blame] | 607 | DEBUG(1, "dl_startup_params entered\n"); |
| 608 | if (!(pcmcia_dev_present(link))) { |
| 609 | DEBUG(2, "ray_cs dl_startup_params - device not present\n"); |
| 610 | return -1; |
| 611 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 612 | |
John Daiker | 141fa61 | 2009-03-10 06:59:54 -0700 | [diff] [blame] | 613 | /* Copy parameters to host to ECF area */ |
| 614 | if (local->fw_ver == 0x55) |
| 615 | memcpy_toio(local->sram + HOST_TO_ECF_BASE, &local->sparm.b4, |
| 616 | sizeof(struct b4_startup_params)); |
| 617 | else |
| 618 | memcpy_toio(local->sram + HOST_TO_ECF_BASE, &local->sparm.b5, |
| 619 | sizeof(struct b5_startup_params)); |
| 620 | |
| 621 | /* Fill in the CCS fields for the ECF */ |
| 622 | if ((ccsindex = get_free_ccs(local)) < 0) |
| 623 | return -1; |
| 624 | local->dl_param_ccs = ccsindex; |
| 625 | pccs = ccs_base(local) + ccsindex; |
| 626 | writeb(CCS_DOWNLOAD_STARTUP_PARAMS, &pccs->cmd); |
| 627 | DEBUG(2, "dl_startup_params start ccsindex = %d\n", |
| 628 | local->dl_param_ccs); |
| 629 | /* Interrupt the firmware to process the command */ |
| 630 | if (interrupt_ecf(local, ccsindex)) { |
| 631 | printk(KERN_INFO "ray dl_startup_params failed - " |
| 632 | "ECF not ready for intr\n"); |
| 633 | local->card_status = CARD_DL_PARAM_ERROR; |
| 634 | writeb(CCS_BUFFER_FREE, &(pccs++)->buffer_status); |
| 635 | return -2; |
| 636 | } |
| 637 | local->card_status = CARD_DL_PARAM; |
| 638 | /* Start kernel timer to wait for dl startup to complete. */ |
| 639 | local->timer.expires = jiffies + HZ / 2; |
| 640 | local->timer.data = (long)local; |
| 641 | local->timer.function = &verify_dl_startup; |
| 642 | add_timer(&local->timer); |
| 643 | DEBUG(2, |
| 644 | "ray_cs dl_startup_params started timer for verify_dl_startup\n"); |
| 645 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 646 | } /* dl_startup_params */ |
John Daiker | 141fa61 | 2009-03-10 06:59:54 -0700 | [diff] [blame] | 647 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 648 | /*===========================================================================*/ |
| 649 | static void init_startup_params(ray_dev_t *local) |
| 650 | { |
John Daiker | 141fa61 | 2009-03-10 06:59:54 -0700 | [diff] [blame] | 651 | int i; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 652 | |
John Daiker | 141fa61 | 2009-03-10 06:59:54 -0700 | [diff] [blame] | 653 | if (country > JAPAN_TEST) |
| 654 | country = USA; |
| 655 | else if (country < USA) |
| 656 | country = USA; |
| 657 | /* structure for hop time and beacon period is defined here using |
| 658 | * New 802.11D6.1 format. Card firmware is still using old format |
| 659 | * until version 6. |
| 660 | * Before After |
| 661 | * a_hop_time ms byte a_hop_time ms byte |
| 662 | * a_hop_time 2s byte a_hop_time ls byte |
| 663 | * a_hop_time ls byte a_beacon_period ms byte |
| 664 | * a_beacon_period a_beacon_period ls byte |
| 665 | * |
| 666 | * a_hop_time = uS a_hop_time = KuS |
| 667 | * a_beacon_period = hops a_beacon_period = KuS |
| 668 | *//* 64ms = 010000 */ |
| 669 | if (local->fw_ver == 0x55) { |
| 670 | memcpy((UCHAR *) &local->sparm.b4, b4_default_startup_parms, |
| 671 | sizeof(struct b4_startup_params)); |
| 672 | /* Translate sane kus input values to old build 4/5 format */ |
| 673 | /* i = hop time in uS truncated to 3 bytes */ |
| 674 | i = (hop_dwell * 1024) & 0xffffff; |
| 675 | local->sparm.b4.a_hop_time[0] = (i >> 16) & 0xff; |
| 676 | local->sparm.b4.a_hop_time[1] = (i >> 8) & 0xff; |
| 677 | local->sparm.b4.a_beacon_period[0] = 0; |
| 678 | local->sparm.b4.a_beacon_period[1] = |
| 679 | ((beacon_period / hop_dwell) - 1) & 0xff; |
| 680 | local->sparm.b4.a_curr_country_code = country; |
| 681 | local->sparm.b4.a_hop_pattern_length = |
| 682 | hop_pattern_length[(int)country] - 1; |
| 683 | if (bc) { |
| 684 | local->sparm.b4.a_ack_timeout = 0x50; |
| 685 | local->sparm.b4.a_sifs = 0x3f; |
| 686 | } |
| 687 | } else { /* Version 5 uses real kus values */ |
| 688 | memcpy((UCHAR *) &local->sparm.b5, b5_default_startup_parms, |
| 689 | sizeof(struct b5_startup_params)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 690 | |
John Daiker | 141fa61 | 2009-03-10 06:59:54 -0700 | [diff] [blame] | 691 | local->sparm.b5.a_hop_time[0] = (hop_dwell >> 8) & 0xff; |
| 692 | local->sparm.b5.a_hop_time[1] = hop_dwell & 0xff; |
| 693 | local->sparm.b5.a_beacon_period[0] = |
| 694 | (beacon_period >> 8) & 0xff; |
| 695 | local->sparm.b5.a_beacon_period[1] = beacon_period & 0xff; |
| 696 | if (psm) |
| 697 | local->sparm.b5.a_power_mgt_state = 1; |
| 698 | local->sparm.b5.a_curr_country_code = country; |
| 699 | local->sparm.b5.a_hop_pattern_length = |
| 700 | hop_pattern_length[(int)country]; |
| 701 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 702 | |
John Daiker | 141fa61 | 2009-03-10 06:59:54 -0700 | [diff] [blame] | 703 | local->sparm.b4.a_network_type = net_type & 0x01; |
| 704 | local->sparm.b4.a_acting_as_ap_status = TYPE_STA; |
| 705 | |
| 706 | if (essid != NULL) |
| 707 | strncpy(local->sparm.b4.a_current_ess_id, essid, ESSID_SIZE); |
| 708 | } /* init_startup_params */ |
| 709 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 710 | /*===========================================================================*/ |
| 711 | static void verify_dl_startup(u_long data) |
| 712 | { |
John Daiker | 141fa61 | 2009-03-10 06:59:54 -0700 | [diff] [blame] | 713 | ray_dev_t *local = (ray_dev_t *) data; |
| 714 | struct ccs __iomem *pccs = ccs_base(local) + local->dl_param_ccs; |
| 715 | UCHAR status; |
| 716 | struct pcmcia_device *link = local->finder; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 717 | |
John Daiker | 141fa61 | 2009-03-10 06:59:54 -0700 | [diff] [blame] | 718 | if (!(pcmcia_dev_present(link))) { |
| 719 | DEBUG(2, "ray_cs verify_dl_startup - device not present\n"); |
| 720 | return; |
| 721 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 722 | #ifdef PCMCIA_DEBUG |
John Daiker | 141fa61 | 2009-03-10 06:59:54 -0700 | [diff] [blame] | 723 | if (pc_debug > 2) { |
| 724 | int i; |
| 725 | printk(KERN_DEBUG |
| 726 | "verify_dl_startup parameters sent via ccs %d:\n", |
| 727 | local->dl_param_ccs); |
| 728 | for (i = 0; i < sizeof(struct b5_startup_params); i++) { |
| 729 | printk(" %2x", |
| 730 | (unsigned int)readb(local->sram + |
| 731 | HOST_TO_ECF_BASE + i)); |
| 732 | } |
| 733 | printk("\n"); |
| 734 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 735 | #endif |
| 736 | |
John Daiker | 141fa61 | 2009-03-10 06:59:54 -0700 | [diff] [blame] | 737 | status = readb(&pccs->buffer_status); |
| 738 | if (status != CCS_BUFFER_FREE) { |
| 739 | printk(KERN_INFO |
| 740 | "Download startup params failed. Status = %d\n", |
| 741 | status); |
| 742 | local->card_status = CARD_DL_PARAM_ERROR; |
| 743 | return; |
| 744 | } |
| 745 | if (local->sparm.b4.a_network_type == ADHOC) |
| 746 | start_net((u_long) local); |
| 747 | else |
| 748 | join_net((u_long) local); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 749 | |
John Daiker | 141fa61 | 2009-03-10 06:59:54 -0700 | [diff] [blame] | 750 | return; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 751 | } /* end verify_dl_startup */ |
John Daiker | 141fa61 | 2009-03-10 06:59:54 -0700 | [diff] [blame] | 752 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 753 | /*===========================================================================*/ |
| 754 | /* Command card to start a network */ |
| 755 | static void start_net(u_long data) |
| 756 | { |
John Daiker | 141fa61 | 2009-03-10 06:59:54 -0700 | [diff] [blame] | 757 | ray_dev_t *local = (ray_dev_t *) data; |
| 758 | struct ccs __iomem *pccs; |
| 759 | int ccsindex; |
| 760 | struct pcmcia_device *link = local->finder; |
| 761 | if (!(pcmcia_dev_present(link))) { |
| 762 | DEBUG(2, "ray_cs start_net - device not present\n"); |
| 763 | return; |
| 764 | } |
| 765 | /* Fill in the CCS fields for the ECF */ |
| 766 | if ((ccsindex = get_free_ccs(local)) < 0) |
| 767 | return; |
| 768 | pccs = ccs_base(local) + ccsindex; |
| 769 | writeb(CCS_START_NETWORK, &pccs->cmd); |
| 770 | writeb(0, &pccs->var.start_network.update_param); |
| 771 | /* Interrupt the firmware to process the command */ |
| 772 | if (interrupt_ecf(local, ccsindex)) { |
| 773 | DEBUG(1, "ray start net failed - card not ready for intr\n"); |
| 774 | writeb(CCS_BUFFER_FREE, &(pccs++)->buffer_status); |
| 775 | return; |
| 776 | } |
| 777 | local->card_status = CARD_DOING_ACQ; |
| 778 | return; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 779 | } /* end start_net */ |
John Daiker | 141fa61 | 2009-03-10 06:59:54 -0700 | [diff] [blame] | 780 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 781 | /*===========================================================================*/ |
| 782 | /* Command card to join a network */ |
| 783 | static void join_net(u_long data) |
| 784 | { |
John Daiker | 141fa61 | 2009-03-10 06:59:54 -0700 | [diff] [blame] | 785 | ray_dev_t *local = (ray_dev_t *) data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 786 | |
John Daiker | 141fa61 | 2009-03-10 06:59:54 -0700 | [diff] [blame] | 787 | struct ccs __iomem *pccs; |
| 788 | int ccsindex; |
| 789 | struct pcmcia_device *link = local->finder; |
| 790 | |
| 791 | if (!(pcmcia_dev_present(link))) { |
| 792 | DEBUG(2, "ray_cs join_net - device not present\n"); |
| 793 | return; |
| 794 | } |
| 795 | /* Fill in the CCS fields for the ECF */ |
| 796 | if ((ccsindex = get_free_ccs(local)) < 0) |
| 797 | return; |
| 798 | pccs = ccs_base(local) + ccsindex; |
| 799 | writeb(CCS_JOIN_NETWORK, &pccs->cmd); |
| 800 | writeb(0, &pccs->var.join_network.update_param); |
| 801 | writeb(0, &pccs->var.join_network.net_initiated); |
| 802 | /* Interrupt the firmware to process the command */ |
| 803 | if (interrupt_ecf(local, ccsindex)) { |
| 804 | DEBUG(1, "ray join net failed - card not ready for intr\n"); |
| 805 | writeb(CCS_BUFFER_FREE, &(pccs++)->buffer_status); |
| 806 | return; |
| 807 | } |
| 808 | local->card_status = CARD_DOING_ACQ; |
| 809 | return; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 810 | } |
John Daiker | 141fa61 | 2009-03-10 06:59:54 -0700 | [diff] [blame] | 811 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 812 | /*============================================================================ |
| 813 | After a card is removed, ray_release() will unregister the net |
| 814 | device, and release the PCMCIA configuration. If the device is |
| 815 | still open, this will be postponed until it is closed. |
| 816 | =============================================================================*/ |
Dominik Brodowski | fba395e | 2006-03-31 17:21:06 +0200 | [diff] [blame] | 817 | static void ray_release(struct pcmcia_device *link) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 818 | { |
John Daiker | 141fa61 | 2009-03-10 06:59:54 -0700 | [diff] [blame] | 819 | struct net_device *dev = link->priv; |
| 820 | ray_dev_t *local = netdev_priv(dev); |
| 821 | int i; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 822 | |
John Daiker | 141fa61 | 2009-03-10 06:59:54 -0700 | [diff] [blame] | 823 | DEBUG(1, "ray_release(0x%p)\n", link); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 824 | |
John Daiker | 141fa61 | 2009-03-10 06:59:54 -0700 | [diff] [blame] | 825 | del_timer(&local->timer); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 826 | |
John Daiker | 141fa61 | 2009-03-10 06:59:54 -0700 | [diff] [blame] | 827 | iounmap(local->sram); |
| 828 | iounmap(local->rmem); |
| 829 | iounmap(local->amem); |
| 830 | /* Do bother checking to see if these succeed or not */ |
| 831 | i = pcmcia_release_window(local->amem_handle); |
| 832 | if (i != 0) |
| 833 | DEBUG(0, "ReleaseWindow(local->amem) ret = %x\n", i); |
| 834 | i = pcmcia_release_window(local->rmem_handle); |
| 835 | if (i != 0) |
| 836 | DEBUG(0, "ReleaseWindow(local->rmem) ret = %x\n", i); |
| 837 | pcmcia_disable_device(link); |
| 838 | |
| 839 | DEBUG(2, "ray_release ending\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 840 | } |
| 841 | |
Dominik Brodowski | fba395e | 2006-03-31 17:21:06 +0200 | [diff] [blame] | 842 | static int ray_suspend(struct pcmcia_device *link) |
Dominik Brodowski | 98e4c28 | 2005-11-14 21:21:18 +0100 | [diff] [blame] | 843 | { |
Dominik Brodowski | 98e4c28 | 2005-11-14 21:21:18 +0100 | [diff] [blame] | 844 | struct net_device *dev = link->priv; |
| 845 | |
Dominik Brodowski | e2d4096 | 2006-03-02 00:09:29 +0100 | [diff] [blame] | 846 | if (link->open) |
Dominik Brodowski | 8661bb5 | 2006-03-02 00:02:33 +0100 | [diff] [blame] | 847 | netif_device_detach(dev); |
Dominik Brodowski | 98e4c28 | 2005-11-14 21:21:18 +0100 | [diff] [blame] | 848 | |
| 849 | return 0; |
| 850 | } |
| 851 | |
Dominik Brodowski | fba395e | 2006-03-31 17:21:06 +0200 | [diff] [blame] | 852 | static int ray_resume(struct pcmcia_device *link) |
Dominik Brodowski | 98e4c28 | 2005-11-14 21:21:18 +0100 | [diff] [blame] | 853 | { |
Dominik Brodowski | 98e4c28 | 2005-11-14 21:21:18 +0100 | [diff] [blame] | 854 | struct net_device *dev = link->priv; |
| 855 | |
Dominik Brodowski | e2d4096 | 2006-03-02 00:09:29 +0100 | [diff] [blame] | 856 | if (link->open) { |
Dominik Brodowski | 8661bb5 | 2006-03-02 00:02:33 +0100 | [diff] [blame] | 857 | ray_reset(dev); |
| 858 | netif_device_attach(dev); |
| 859 | } |
Dominik Brodowski | 98e4c28 | 2005-11-14 21:21:18 +0100 | [diff] [blame] | 860 | |
| 861 | return 0; |
| 862 | } |
| 863 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 864 | /*===========================================================================*/ |
Hannes Eder | 2ed5ba8 | 2008-12-26 00:12:59 -0800 | [diff] [blame] | 865 | static int ray_dev_init(struct net_device *dev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 866 | { |
| 867 | #ifdef RAY_IMMEDIATE_INIT |
John Daiker | 141fa61 | 2009-03-10 06:59:54 -0700 | [diff] [blame] | 868 | int i; |
| 869 | #endif /* RAY_IMMEDIATE_INIT */ |
| 870 | ray_dev_t *local = netdev_priv(dev); |
| 871 | struct pcmcia_device *link = local->finder; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 872 | |
John Daiker | 141fa61 | 2009-03-10 06:59:54 -0700 | [diff] [blame] | 873 | DEBUG(1, "ray_dev_init(dev=%p)\n", dev); |
| 874 | if (!(pcmcia_dev_present(link))) { |
| 875 | DEBUG(2, "ray_dev_init - device not present\n"); |
| 876 | return -1; |
| 877 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 878 | #ifdef RAY_IMMEDIATE_INIT |
John Daiker | 141fa61 | 2009-03-10 06:59:54 -0700 | [diff] [blame] | 879 | /* Download startup parameters */ |
| 880 | if ((i = dl_startup_params(dev)) < 0) { |
| 881 | printk(KERN_INFO "ray_dev_init dl_startup_params failed - " |
| 882 | "returns 0x%x\n", i); |
| 883 | return -1; |
| 884 | } |
| 885 | #else /* RAY_IMMEDIATE_INIT */ |
| 886 | /* Postpone the card init so that we can still configure the card, |
| 887 | * for example using the Wireless Extensions. The init will happen |
| 888 | * in ray_open() - Jean II */ |
| 889 | DEBUG(1, |
| 890 | "ray_dev_init: postponing card init to ray_open() ; Status = %d\n", |
| 891 | local->card_status); |
| 892 | #endif /* RAY_IMMEDIATE_INIT */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 893 | |
John Daiker | 141fa61 | 2009-03-10 06:59:54 -0700 | [diff] [blame] | 894 | /* copy mac and broadcast addresses to linux device */ |
| 895 | memcpy(&dev->dev_addr, &local->sparm.b4.a_mac_addr, ADDRLEN); |
| 896 | memset(dev->broadcast, 0xff, ETH_ALEN); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 897 | |
John Daiker | 141fa61 | 2009-03-10 06:59:54 -0700 | [diff] [blame] | 898 | DEBUG(2, "ray_dev_init ending\n"); |
| 899 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 900 | } |
John Daiker | 141fa61 | 2009-03-10 06:59:54 -0700 | [diff] [blame] | 901 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 902 | /*===========================================================================*/ |
| 903 | static int ray_dev_config(struct net_device *dev, struct ifmap *map) |
| 904 | { |
John Daiker | 141fa61 | 2009-03-10 06:59:54 -0700 | [diff] [blame] | 905 | ray_dev_t *local = netdev_priv(dev); |
| 906 | struct pcmcia_device *link = local->finder; |
| 907 | /* Dummy routine to satisfy device structure */ |
| 908 | DEBUG(1, "ray_dev_config(dev=%p,ifmap=%p)\n", dev, map); |
| 909 | if (!(pcmcia_dev_present(link))) { |
| 910 | DEBUG(2, "ray_dev_config - device not present\n"); |
| 911 | return -1; |
| 912 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 913 | |
John Daiker | 141fa61 | 2009-03-10 06:59:54 -0700 | [diff] [blame] | 914 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 915 | } |
John Daiker | 141fa61 | 2009-03-10 06:59:54 -0700 | [diff] [blame] | 916 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 917 | /*===========================================================================*/ |
| 918 | static int ray_dev_start_xmit(struct sk_buff *skb, struct net_device *dev) |
| 919 | { |
John Daiker | 141fa61 | 2009-03-10 06:59:54 -0700 | [diff] [blame] | 920 | ray_dev_t *local = netdev_priv(dev); |
| 921 | struct pcmcia_device *link = local->finder; |
| 922 | short length = skb->len; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 923 | |
John Daiker | 141fa61 | 2009-03-10 06:59:54 -0700 | [diff] [blame] | 924 | if (!(pcmcia_dev_present(link))) { |
| 925 | DEBUG(2, "ray_dev_start_xmit - device not present\n"); |
| 926 | return -1; |
| 927 | } |
| 928 | DEBUG(3, "ray_dev_start_xmit(skb=%p, dev=%p)\n", skb, dev); |
| 929 | if (local->authentication_state == NEED_TO_AUTH) { |
| 930 | DEBUG(0, "ray_cs Sending authentication request.\n"); |
| 931 | if (!build_auth_frame(local, local->auth_id, OPEN_AUTH_REQUEST)) { |
| 932 | local->authentication_state = AUTHENTICATED; |
| 933 | netif_stop_queue(dev); |
| 934 | return 1; |
| 935 | } |
| 936 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 937 | |
John Daiker | 141fa61 | 2009-03-10 06:59:54 -0700 | [diff] [blame] | 938 | if (length < ETH_ZLEN) { |
| 939 | if (skb_padto(skb, ETH_ZLEN)) |
| 940 | return 0; |
| 941 | length = ETH_ZLEN; |
| 942 | } |
| 943 | switch (ray_hw_xmit(skb->data, length, dev, DATA_TYPE)) { |
| 944 | case XMIT_NO_CCS: |
| 945 | case XMIT_NEED_AUTH: |
| 946 | netif_stop_queue(dev); |
| 947 | return 1; |
| 948 | case XMIT_NO_INTR: |
| 949 | case XMIT_MSG_BAD: |
| 950 | case XMIT_OK: |
| 951 | default: |
| 952 | dev->trans_start = jiffies; |
| 953 | dev_kfree_skb(skb); |
| 954 | return 0; |
| 955 | } |
| 956 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 957 | } /* ray_dev_start_xmit */ |
John Daiker | 141fa61 | 2009-03-10 06:59:54 -0700 | [diff] [blame] | 958 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 959 | /*===========================================================================*/ |
John Daiker | 141fa61 | 2009-03-10 06:59:54 -0700 | [diff] [blame] | 960 | static int ray_hw_xmit(unsigned char *data, int len, struct net_device *dev, |
| 961 | UCHAR msg_type) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 962 | { |
John Daiker | 141fa61 | 2009-03-10 06:59:54 -0700 | [diff] [blame] | 963 | ray_dev_t *local = netdev_priv(dev); |
| 964 | struct ccs __iomem *pccs; |
| 965 | int ccsindex; |
| 966 | int offset; |
| 967 | struct tx_msg __iomem *ptx; /* Address of xmit buffer in PC space */ |
| 968 | short int addr; /* Address of xmit buffer in card space */ |
| 969 | |
| 970 | DEBUG(3, "ray_hw_xmit(data=%p, len=%d, dev=%p)\n", data, len, dev); |
| 971 | if (len + TX_HEADER_LENGTH > TX_BUF_SIZE) { |
| 972 | printk(KERN_INFO "ray_hw_xmit packet too large: %d bytes\n", |
| 973 | len); |
| 974 | return XMIT_MSG_BAD; |
| 975 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 976 | switch (ccsindex = get_free_tx_ccs(local)) { |
| 977 | case ECCSBUSY: |
John Daiker | 141fa61 | 2009-03-10 06:59:54 -0700 | [diff] [blame] | 978 | DEBUG(2, "ray_hw_xmit tx_ccs table busy\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 979 | case ECCSFULL: |
John Daiker | 141fa61 | 2009-03-10 06:59:54 -0700 | [diff] [blame] | 980 | DEBUG(2, "ray_hw_xmit No free tx ccs\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 981 | case ECARDGONE: |
John Daiker | 141fa61 | 2009-03-10 06:59:54 -0700 | [diff] [blame] | 982 | netif_stop_queue(dev); |
| 983 | return XMIT_NO_CCS; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 984 | default: |
| 985 | break; |
| 986 | } |
John Daiker | 141fa61 | 2009-03-10 06:59:54 -0700 | [diff] [blame] | 987 | addr = TX_BUF_BASE + (ccsindex << 11); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 988 | |
John Daiker | 141fa61 | 2009-03-10 06:59:54 -0700 | [diff] [blame] | 989 | if (msg_type == DATA_TYPE) { |
| 990 | local->stats.tx_bytes += len; |
| 991 | local->stats.tx_packets++; |
| 992 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 993 | |
John Daiker | 141fa61 | 2009-03-10 06:59:54 -0700 | [diff] [blame] | 994 | ptx = local->sram + addr; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 995 | |
John Daiker | 141fa61 | 2009-03-10 06:59:54 -0700 | [diff] [blame] | 996 | ray_build_header(local, ptx, msg_type, data); |
| 997 | if (translate) { |
| 998 | offset = translate_frame(local, ptx, data, len); |
| 999 | } else { /* Encapsulate frame */ |
| 1000 | /* TBD TIB length will move address of ptx->var */ |
| 1001 | memcpy_toio(&ptx->var, data, len); |
| 1002 | offset = 0; |
| 1003 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1004 | |
John Daiker | 141fa61 | 2009-03-10 06:59:54 -0700 | [diff] [blame] | 1005 | /* fill in the CCS */ |
| 1006 | pccs = ccs_base(local) + ccsindex; |
| 1007 | len += TX_HEADER_LENGTH + offset; |
| 1008 | writeb(CCS_TX_REQUEST, &pccs->cmd); |
| 1009 | writeb(addr >> 8, &pccs->var.tx_request.tx_data_ptr[0]); |
| 1010 | writeb(local->tib_length, &pccs->var.tx_request.tx_data_ptr[1]); |
| 1011 | writeb(len >> 8, &pccs->var.tx_request.tx_data_length[0]); |
| 1012 | writeb(len & 0xff, &pccs->var.tx_request.tx_data_length[1]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1013 | /* TBD still need psm_cam? */ |
John Daiker | 141fa61 | 2009-03-10 06:59:54 -0700 | [diff] [blame] | 1014 | writeb(PSM_CAM, &pccs->var.tx_request.pow_sav_mode); |
| 1015 | writeb(local->net_default_tx_rate, &pccs->var.tx_request.tx_rate); |
| 1016 | writeb(0, &pccs->var.tx_request.antenna); |
| 1017 | DEBUG(3, "ray_hw_xmit default_tx_rate = 0x%x\n", |
| 1018 | local->net_default_tx_rate); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1019 | |
John Daiker | 141fa61 | 2009-03-10 06:59:54 -0700 | [diff] [blame] | 1020 | /* Interrupt the firmware to process the command */ |
| 1021 | if (interrupt_ecf(local, ccsindex)) { |
| 1022 | DEBUG(2, "ray_hw_xmit failed - ECF not ready for intr\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1023 | /* TBD very inefficient to copy packet to buffer, and then not |
| 1024 | send it, but the alternative is to queue the messages and that |
| 1025 | won't be done for a while. Maybe set tbusy until a CCS is free? |
| 1026 | */ |
John Daiker | 141fa61 | 2009-03-10 06:59:54 -0700 | [diff] [blame] | 1027 | writeb(CCS_BUFFER_FREE, &pccs->buffer_status); |
| 1028 | return XMIT_NO_INTR; |
| 1029 | } |
| 1030 | return XMIT_OK; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1031 | } /* end ray_hw_xmit */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1032 | |
John Daiker | 141fa61 | 2009-03-10 06:59:54 -0700 | [diff] [blame] | 1033 | /*===========================================================================*/ |
| 1034 | static int translate_frame(ray_dev_t *local, struct tx_msg __iomem *ptx, |
| 1035 | unsigned char *data, int len) |
| 1036 | { |
| 1037 | __be16 proto = ((struct ethhdr *)data)->h_proto; |
| 1038 | if (ntohs(proto) >= 1536) { /* DIX II ethernet frame */ |
| 1039 | DEBUG(3, "ray_cs translate_frame DIX II\n"); |
| 1040 | /* Copy LLC header to card buffer */ |
| 1041 | memcpy_toio(&ptx->var, eth2_llc, sizeof(eth2_llc)); |
| 1042 | memcpy_toio(((void __iomem *)&ptx->var) + sizeof(eth2_llc), |
| 1043 | (UCHAR *) &proto, 2); |
| 1044 | if (proto == htons(ETH_P_AARP) || proto == htons(ETH_P_IPX)) { |
| 1045 | /* This is the selective translation table, only 2 entries */ |
| 1046 | writeb(0xf8, |
| 1047 | &((struct snaphdr_t __iomem *)ptx->var)->org[3]); |
| 1048 | } |
| 1049 | /* Copy body of ethernet packet without ethernet header */ |
| 1050 | memcpy_toio((void __iomem *)&ptx->var + |
| 1051 | sizeof(struct snaphdr_t), data + ETH_HLEN, |
| 1052 | len - ETH_HLEN); |
| 1053 | return (int)sizeof(struct snaphdr_t) - ETH_HLEN; |
| 1054 | } else { /* already 802 type, and proto is length */ |
| 1055 | DEBUG(3, "ray_cs translate_frame 802\n"); |
| 1056 | if (proto == htons(0xffff)) { /* evil netware IPX 802.3 without LLC */ |
| 1057 | DEBUG(3, "ray_cs translate_frame evil IPX\n"); |
| 1058 | memcpy_toio(&ptx->var, data + ETH_HLEN, len - ETH_HLEN); |
| 1059 | return 0 - ETH_HLEN; |
| 1060 | } |
| 1061 | memcpy_toio(&ptx->var, data + ETH_HLEN, len - ETH_HLEN); |
| 1062 | return 0 - ETH_HLEN; |
| 1063 | } |
| 1064 | /* TBD do other frame types */ |
| 1065 | } /* end translate_frame */ |
| 1066 | |
| 1067 | /*===========================================================================*/ |
| 1068 | static void ray_build_header(ray_dev_t *local, struct tx_msg __iomem *ptx, |
| 1069 | UCHAR msg_type, unsigned char *data) |
| 1070 | { |
| 1071 | writeb(PROTOCOL_VER | msg_type, &ptx->mac.frame_ctl_1); |
| 1072 | /*** IEEE 802.11 Address field assignments ************* |
| 1073 | TODS FROMDS addr_1 addr_2 addr_3 addr_4 |
| 1074 | Adhoc 0 0 dest src (terminal) BSSID N/A |
| 1075 | AP to Terminal 0 1 dest AP(BSSID) source N/A |
| 1076 | Terminal to AP 1 0 AP(BSSID) src (terminal) dest N/A |
| 1077 | AP to AP 1 1 dest AP src AP dest source |
| 1078 | *******************************************************/ |
| 1079 | if (local->net_type == ADHOC) { |
| 1080 | writeb(0, &ptx->mac.frame_ctl_2); |
| 1081 | memcpy_toio(ptx->mac.addr_1, ((struct ethhdr *)data)->h_dest, |
| 1082 | 2 * ADDRLEN); |
| 1083 | memcpy_toio(ptx->mac.addr_3, local->bss_id, ADDRLEN); |
| 1084 | } else { /* infrastructure */ |
| 1085 | |
| 1086 | if (local->sparm.b4.a_acting_as_ap_status) { |
| 1087 | writeb(FC2_FROM_DS, &ptx->mac.frame_ctl_2); |
| 1088 | memcpy_toio(ptx->mac.addr_1, |
| 1089 | ((struct ethhdr *)data)->h_dest, ADDRLEN); |
| 1090 | memcpy_toio(ptx->mac.addr_2, local->bss_id, 6); |
| 1091 | memcpy_toio(ptx->mac.addr_3, |
| 1092 | ((struct ethhdr *)data)->h_source, ADDRLEN); |
| 1093 | } else { /* Terminal */ |
| 1094 | |
| 1095 | writeb(FC2_TO_DS, &ptx->mac.frame_ctl_2); |
| 1096 | memcpy_toio(ptx->mac.addr_1, local->bss_id, ADDRLEN); |
| 1097 | memcpy_toio(ptx->mac.addr_2, |
| 1098 | ((struct ethhdr *)data)->h_source, ADDRLEN); |
| 1099 | memcpy_toio(ptx->mac.addr_3, |
| 1100 | ((struct ethhdr *)data)->h_dest, ADDRLEN); |
| 1101 | } |
| 1102 | } |
| 1103 | } /* end encapsulate_frame */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1104 | |
| 1105 | /*===========================================================================*/ |
| 1106 | |
| 1107 | static void netdev_get_drvinfo(struct net_device *dev, |
| 1108 | struct ethtool_drvinfo *info) |
| 1109 | { |
| 1110 | strcpy(info->driver, "ray_cs"); |
| 1111 | } |
| 1112 | |
Jeff Garzik | 7282d49 | 2006-09-13 14:30:00 -0400 | [diff] [blame] | 1113 | static const struct ethtool_ops netdev_ethtool_ops = { |
John Daiker | 141fa61 | 2009-03-10 06:59:54 -0700 | [diff] [blame] | 1114 | .get_drvinfo = netdev_get_drvinfo, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1115 | }; |
| 1116 | |
| 1117 | /*====================================================================*/ |
| 1118 | |
Jean Tourrilhes | 3d5d5ac | 2005-09-02 11:40:39 -0700 | [diff] [blame] | 1119 | /*------------------------------------------------------------------*/ |
| 1120 | /* |
| 1121 | * Wireless Handler : get protocol name |
| 1122 | */ |
| 1123 | static int ray_get_name(struct net_device *dev, |
John Daiker | 141fa61 | 2009-03-10 06:59:54 -0700 | [diff] [blame] | 1124 | struct iw_request_info *info, char *cwrq, char *extra) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1125 | { |
Jean Tourrilhes | 3d5d5ac | 2005-09-02 11:40:39 -0700 | [diff] [blame] | 1126 | strcpy(cwrq, "IEEE 802.11-FH"); |
| 1127 | return 0; |
| 1128 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1129 | |
Jean Tourrilhes | 3d5d5ac | 2005-09-02 11:40:39 -0700 | [diff] [blame] | 1130 | /*------------------------------------------------------------------*/ |
| 1131 | /* |
| 1132 | * Wireless Handler : set frequency |
| 1133 | */ |
| 1134 | static int ray_set_freq(struct net_device *dev, |
| 1135 | struct iw_request_info *info, |
John Daiker | 141fa61 | 2009-03-10 06:59:54 -0700 | [diff] [blame] | 1136 | struct iw_freq *fwrq, char *extra) |
Jean Tourrilhes | 3d5d5ac | 2005-09-02 11:40:39 -0700 | [diff] [blame] | 1137 | { |
Yoann Padioleau | 6dbc9c8 | 2007-08-03 19:37:16 +0200 | [diff] [blame] | 1138 | ray_dev_t *local = netdev_priv(dev); |
John Daiker | 141fa61 | 2009-03-10 06:59:54 -0700 | [diff] [blame] | 1139 | int err = -EINPROGRESS; /* Call commit handler */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1140 | |
Jean Tourrilhes | 3d5d5ac | 2005-09-02 11:40:39 -0700 | [diff] [blame] | 1141 | /* Reject if card is already initialised */ |
John Daiker | 141fa61 | 2009-03-10 06:59:54 -0700 | [diff] [blame] | 1142 | if (local->card_status != CARD_AWAITING_PARAM) |
Jean Tourrilhes | 3d5d5ac | 2005-09-02 11:40:39 -0700 | [diff] [blame] | 1143 | return -EBUSY; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1144 | |
Jean Tourrilhes | 3d5d5ac | 2005-09-02 11:40:39 -0700 | [diff] [blame] | 1145 | /* Setting by channel number */ |
| 1146 | if ((fwrq->m > USA_HOP_MOD) || (fwrq->e > 0)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1147 | err = -EOPNOTSUPP; |
Jean Tourrilhes | 3d5d5ac | 2005-09-02 11:40:39 -0700 | [diff] [blame] | 1148 | else |
| 1149 | local->sparm.b5.a_hop_pattern = fwrq->m; |
| 1150 | |
| 1151 | return err; |
| 1152 | } |
John Daiker | 141fa61 | 2009-03-10 06:59:54 -0700 | [diff] [blame] | 1153 | |
Jean Tourrilhes | 3d5d5ac | 2005-09-02 11:40:39 -0700 | [diff] [blame] | 1154 | /*------------------------------------------------------------------*/ |
| 1155 | /* |
| 1156 | * Wireless Handler : get frequency |
| 1157 | */ |
| 1158 | static int ray_get_freq(struct net_device *dev, |
| 1159 | struct iw_request_info *info, |
John Daiker | 141fa61 | 2009-03-10 06:59:54 -0700 | [diff] [blame] | 1160 | struct iw_freq *fwrq, char *extra) |
Jean Tourrilhes | 3d5d5ac | 2005-09-02 11:40:39 -0700 | [diff] [blame] | 1161 | { |
Yoann Padioleau | 6dbc9c8 | 2007-08-03 19:37:16 +0200 | [diff] [blame] | 1162 | ray_dev_t *local = netdev_priv(dev); |
Jean Tourrilhes | 3d5d5ac | 2005-09-02 11:40:39 -0700 | [diff] [blame] | 1163 | |
| 1164 | fwrq->m = local->sparm.b5.a_hop_pattern; |
| 1165 | fwrq->e = 0; |
| 1166 | return 0; |
| 1167 | } |
| 1168 | |
| 1169 | /*------------------------------------------------------------------*/ |
| 1170 | /* |
| 1171 | * Wireless Handler : set ESSID |
| 1172 | */ |
| 1173 | static int ray_set_essid(struct net_device *dev, |
| 1174 | struct iw_request_info *info, |
John Daiker | 141fa61 | 2009-03-10 06:59:54 -0700 | [diff] [blame] | 1175 | struct iw_point *dwrq, char *extra) |
Jean Tourrilhes | 3d5d5ac | 2005-09-02 11:40:39 -0700 | [diff] [blame] | 1176 | { |
Yoann Padioleau | 6dbc9c8 | 2007-08-03 19:37:16 +0200 | [diff] [blame] | 1177 | ray_dev_t *local = netdev_priv(dev); |
Jean Tourrilhes | 3d5d5ac | 2005-09-02 11:40:39 -0700 | [diff] [blame] | 1178 | |
| 1179 | /* Reject if card is already initialised */ |
John Daiker | 141fa61 | 2009-03-10 06:59:54 -0700 | [diff] [blame] | 1180 | if (local->card_status != CARD_AWAITING_PARAM) |
Jean Tourrilhes | 3d5d5ac | 2005-09-02 11:40:39 -0700 | [diff] [blame] | 1181 | return -EBUSY; |
| 1182 | |
| 1183 | /* Check if we asked for `any' */ |
John Daiker | 141fa61 | 2009-03-10 06:59:54 -0700 | [diff] [blame] | 1184 | if (dwrq->flags == 0) { |
Jean Tourrilhes | 3d5d5ac | 2005-09-02 11:40:39 -0700 | [diff] [blame] | 1185 | /* Corey : can you do that ? */ |
| 1186 | return -EOPNOTSUPP; |
| 1187 | } else { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1188 | /* Check the size of the string */ |
John Daiker | 141fa61 | 2009-03-10 06:59:54 -0700 | [diff] [blame] | 1189 | if (dwrq->length > IW_ESSID_MAX_SIZE) { |
Jean Tourrilhes | 3d5d5ac | 2005-09-02 11:40:39 -0700 | [diff] [blame] | 1190 | return -E2BIG; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1191 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1192 | |
| 1193 | /* Set the ESSID in the card */ |
Jean Tourrilhes | 3d5d5ac | 2005-09-02 11:40:39 -0700 | [diff] [blame] | 1194 | memset(local->sparm.b5.a_current_ess_id, 0, IW_ESSID_MAX_SIZE); |
| 1195 | memcpy(local->sparm.b5.a_current_ess_id, extra, dwrq->length); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1196 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1197 | |
John Daiker | 141fa61 | 2009-03-10 06:59:54 -0700 | [diff] [blame] | 1198 | return -EINPROGRESS; /* Call commit handler */ |
Jean Tourrilhes | 3d5d5ac | 2005-09-02 11:40:39 -0700 | [diff] [blame] | 1199 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1200 | |
Jean Tourrilhes | 3d5d5ac | 2005-09-02 11:40:39 -0700 | [diff] [blame] | 1201 | /*------------------------------------------------------------------*/ |
| 1202 | /* |
| 1203 | * Wireless Handler : get ESSID |
| 1204 | */ |
| 1205 | static int ray_get_essid(struct net_device *dev, |
| 1206 | struct iw_request_info *info, |
John Daiker | 141fa61 | 2009-03-10 06:59:54 -0700 | [diff] [blame] | 1207 | struct iw_point *dwrq, char *extra) |
Jean Tourrilhes | 3d5d5ac | 2005-09-02 11:40:39 -0700 | [diff] [blame] | 1208 | { |
Yoann Padioleau | 6dbc9c8 | 2007-08-03 19:37:16 +0200 | [diff] [blame] | 1209 | ray_dev_t *local = netdev_priv(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1210 | |
Jean Tourrilhes | 3d5d5ac | 2005-09-02 11:40:39 -0700 | [diff] [blame] | 1211 | /* Get the essid that was set */ |
| 1212 | memcpy(extra, local->sparm.b5.a_current_ess_id, IW_ESSID_MAX_SIZE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1213 | |
Jean Tourrilhes | 3d5d5ac | 2005-09-02 11:40:39 -0700 | [diff] [blame] | 1214 | /* Push it out ! */ |
Dan Williams | d6a13a2 | 2006-01-12 15:00:58 -0500 | [diff] [blame] | 1215 | dwrq->length = strlen(extra); |
John Daiker | 141fa61 | 2009-03-10 06:59:54 -0700 | [diff] [blame] | 1216 | dwrq->flags = 1; /* active */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1217 | |
Jean Tourrilhes | 3d5d5ac | 2005-09-02 11:40:39 -0700 | [diff] [blame] | 1218 | return 0; |
| 1219 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1220 | |
Jean Tourrilhes | 3d5d5ac | 2005-09-02 11:40:39 -0700 | [diff] [blame] | 1221 | /*------------------------------------------------------------------*/ |
| 1222 | /* |
| 1223 | * Wireless Handler : get AP address |
| 1224 | */ |
| 1225 | static int ray_get_wap(struct net_device *dev, |
John Daiker | 141fa61 | 2009-03-10 06:59:54 -0700 | [diff] [blame] | 1226 | struct iw_request_info *info, |
| 1227 | struct sockaddr *awrq, char *extra) |
Jean Tourrilhes | 3d5d5ac | 2005-09-02 11:40:39 -0700 | [diff] [blame] | 1228 | { |
Yoann Padioleau | 6dbc9c8 | 2007-08-03 19:37:16 +0200 | [diff] [blame] | 1229 | ray_dev_t *local = netdev_priv(dev); |
Jean Tourrilhes | 3d5d5ac | 2005-09-02 11:40:39 -0700 | [diff] [blame] | 1230 | |
| 1231 | memcpy(awrq->sa_data, local->bss_id, ETH_ALEN); |
| 1232 | awrq->sa_family = ARPHRD_ETHER; |
| 1233 | |
| 1234 | return 0; |
| 1235 | } |
| 1236 | |
| 1237 | /*------------------------------------------------------------------*/ |
| 1238 | /* |
| 1239 | * Wireless Handler : set Bit-Rate |
| 1240 | */ |
| 1241 | static int ray_set_rate(struct net_device *dev, |
| 1242 | struct iw_request_info *info, |
John Daiker | 141fa61 | 2009-03-10 06:59:54 -0700 | [diff] [blame] | 1243 | struct iw_param *vwrq, char *extra) |
Jean Tourrilhes | 3d5d5ac | 2005-09-02 11:40:39 -0700 | [diff] [blame] | 1244 | { |
Yoann Padioleau | 6dbc9c8 | 2007-08-03 19:37:16 +0200 | [diff] [blame] | 1245 | ray_dev_t *local = netdev_priv(dev); |
Jean Tourrilhes | 3d5d5ac | 2005-09-02 11:40:39 -0700 | [diff] [blame] | 1246 | |
| 1247 | /* Reject if card is already initialised */ |
John Daiker | 141fa61 | 2009-03-10 06:59:54 -0700 | [diff] [blame] | 1248 | if (local->card_status != CARD_AWAITING_PARAM) |
Jean Tourrilhes | 3d5d5ac | 2005-09-02 11:40:39 -0700 | [diff] [blame] | 1249 | return -EBUSY; |
| 1250 | |
| 1251 | /* Check if rate is in range */ |
John Daiker | 141fa61 | 2009-03-10 06:59:54 -0700 | [diff] [blame] | 1252 | if ((vwrq->value != 1000000) && (vwrq->value != 2000000)) |
Jean Tourrilhes | 3d5d5ac | 2005-09-02 11:40:39 -0700 | [diff] [blame] | 1253 | return -EINVAL; |
| 1254 | |
| 1255 | /* Hack for 1.5 Mb/s instead of 2 Mb/s */ |
John Daiker | 141fa61 | 2009-03-10 06:59:54 -0700 | [diff] [blame] | 1256 | if ((local->fw_ver == 0x55) && /* Please check */ |
| 1257 | (vwrq->value == 2000000)) |
Jean Tourrilhes | 3d5d5ac | 2005-09-02 11:40:39 -0700 | [diff] [blame] | 1258 | local->net_default_tx_rate = 3; |
| 1259 | else |
John Daiker | 141fa61 | 2009-03-10 06:59:54 -0700 | [diff] [blame] | 1260 | local->net_default_tx_rate = vwrq->value / 500000; |
Jean Tourrilhes | 3d5d5ac | 2005-09-02 11:40:39 -0700 | [diff] [blame] | 1261 | |
| 1262 | return 0; |
| 1263 | } |
| 1264 | |
| 1265 | /*------------------------------------------------------------------*/ |
| 1266 | /* |
| 1267 | * Wireless Handler : get Bit-Rate |
| 1268 | */ |
| 1269 | static int ray_get_rate(struct net_device *dev, |
| 1270 | struct iw_request_info *info, |
John Daiker | 141fa61 | 2009-03-10 06:59:54 -0700 | [diff] [blame] | 1271 | struct iw_param *vwrq, char *extra) |
Jean Tourrilhes | 3d5d5ac | 2005-09-02 11:40:39 -0700 | [diff] [blame] | 1272 | { |
Yoann Padioleau | 6dbc9c8 | 2007-08-03 19:37:16 +0200 | [diff] [blame] | 1273 | ray_dev_t *local = netdev_priv(dev); |
Jean Tourrilhes | 3d5d5ac | 2005-09-02 11:40:39 -0700 | [diff] [blame] | 1274 | |
John Daiker | 141fa61 | 2009-03-10 06:59:54 -0700 | [diff] [blame] | 1275 | if (local->net_default_tx_rate == 3) |
| 1276 | vwrq->value = 2000000; /* Hum... */ |
Jean Tourrilhes | 3d5d5ac | 2005-09-02 11:40:39 -0700 | [diff] [blame] | 1277 | else |
| 1278 | vwrq->value = local->net_default_tx_rate * 500000; |
John Daiker | 141fa61 | 2009-03-10 06:59:54 -0700 | [diff] [blame] | 1279 | vwrq->fixed = 0; /* We are in auto mode */ |
Jean Tourrilhes | 3d5d5ac | 2005-09-02 11:40:39 -0700 | [diff] [blame] | 1280 | |
| 1281 | return 0; |
| 1282 | } |
| 1283 | |
| 1284 | /*------------------------------------------------------------------*/ |
| 1285 | /* |
| 1286 | * Wireless Handler : set RTS threshold |
| 1287 | */ |
| 1288 | static int ray_set_rts(struct net_device *dev, |
| 1289 | struct iw_request_info *info, |
John Daiker | 141fa61 | 2009-03-10 06:59:54 -0700 | [diff] [blame] | 1290 | struct iw_param *vwrq, char *extra) |
Jean Tourrilhes | 3d5d5ac | 2005-09-02 11:40:39 -0700 | [diff] [blame] | 1291 | { |
Yoann Padioleau | 6dbc9c8 | 2007-08-03 19:37:16 +0200 | [diff] [blame] | 1292 | ray_dev_t *local = netdev_priv(dev); |
Jean Tourrilhes | 3d5d5ac | 2005-09-02 11:40:39 -0700 | [diff] [blame] | 1293 | int rthr = vwrq->value; |
| 1294 | |
| 1295 | /* Reject if card is already initialised */ |
John Daiker | 141fa61 | 2009-03-10 06:59:54 -0700 | [diff] [blame] | 1296 | if (local->card_status != CARD_AWAITING_PARAM) |
Jean Tourrilhes | 3d5d5ac | 2005-09-02 11:40:39 -0700 | [diff] [blame] | 1297 | return -EBUSY; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1298 | |
| 1299 | /* if(wrq->u.rts.fixed == 0) we should complain */ |
John Daiker | 141fa61 | 2009-03-10 06:59:54 -0700 | [diff] [blame] | 1300 | if (vwrq->disabled) |
Jean Tourrilhes | 3d5d5ac | 2005-09-02 11:40:39 -0700 | [diff] [blame] | 1301 | rthr = 32767; |
| 1302 | else { |
John Daiker | 141fa61 | 2009-03-10 06:59:54 -0700 | [diff] [blame] | 1303 | if ((rthr < 0) || (rthr > 2347)) /* What's the max packet size ??? */ |
Jean Tourrilhes | 3d5d5ac | 2005-09-02 11:40:39 -0700 | [diff] [blame] | 1304 | return -EINVAL; |
| 1305 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1306 | local->sparm.b5.a_rts_threshold[0] = (rthr >> 8) & 0xFF; |
| 1307 | local->sparm.b5.a_rts_threshold[1] = rthr & 0xFF; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1308 | |
John Daiker | 141fa61 | 2009-03-10 06:59:54 -0700 | [diff] [blame] | 1309 | return -EINPROGRESS; /* Call commit handler */ |
Jean Tourrilhes | 3d5d5ac | 2005-09-02 11:40:39 -0700 | [diff] [blame] | 1310 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1311 | |
Jean Tourrilhes | 3d5d5ac | 2005-09-02 11:40:39 -0700 | [diff] [blame] | 1312 | /*------------------------------------------------------------------*/ |
| 1313 | /* |
| 1314 | * Wireless Handler : get RTS threshold |
| 1315 | */ |
| 1316 | static int ray_get_rts(struct net_device *dev, |
| 1317 | struct iw_request_info *info, |
John Daiker | 141fa61 | 2009-03-10 06:59:54 -0700 | [diff] [blame] | 1318 | struct iw_param *vwrq, char *extra) |
Jean Tourrilhes | 3d5d5ac | 2005-09-02 11:40:39 -0700 | [diff] [blame] | 1319 | { |
Yoann Padioleau | 6dbc9c8 | 2007-08-03 19:37:16 +0200 | [diff] [blame] | 1320 | ray_dev_t *local = netdev_priv(dev); |
Jean Tourrilhes | 3d5d5ac | 2005-09-02 11:40:39 -0700 | [diff] [blame] | 1321 | |
| 1322 | vwrq->value = (local->sparm.b5.a_rts_threshold[0] << 8) |
John Daiker | 141fa61 | 2009-03-10 06:59:54 -0700 | [diff] [blame] | 1323 | + local->sparm.b5.a_rts_threshold[1]; |
Jean Tourrilhes | 3d5d5ac | 2005-09-02 11:40:39 -0700 | [diff] [blame] | 1324 | vwrq->disabled = (vwrq->value == 32767); |
| 1325 | vwrq->fixed = 1; |
| 1326 | |
| 1327 | return 0; |
| 1328 | } |
| 1329 | |
| 1330 | /*------------------------------------------------------------------*/ |
| 1331 | /* |
| 1332 | * Wireless Handler : set Fragmentation threshold |
| 1333 | */ |
| 1334 | static int ray_set_frag(struct net_device *dev, |
| 1335 | struct iw_request_info *info, |
John Daiker | 141fa61 | 2009-03-10 06:59:54 -0700 | [diff] [blame] | 1336 | struct iw_param *vwrq, char *extra) |
Jean Tourrilhes | 3d5d5ac | 2005-09-02 11:40:39 -0700 | [diff] [blame] | 1337 | { |
Yoann Padioleau | 6dbc9c8 | 2007-08-03 19:37:16 +0200 | [diff] [blame] | 1338 | ray_dev_t *local = netdev_priv(dev); |
Jean Tourrilhes | 3d5d5ac | 2005-09-02 11:40:39 -0700 | [diff] [blame] | 1339 | int fthr = vwrq->value; |
| 1340 | |
| 1341 | /* Reject if card is already initialised */ |
John Daiker | 141fa61 | 2009-03-10 06:59:54 -0700 | [diff] [blame] | 1342 | if (local->card_status != CARD_AWAITING_PARAM) |
Jean Tourrilhes | 3d5d5ac | 2005-09-02 11:40:39 -0700 | [diff] [blame] | 1343 | return -EBUSY; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1344 | |
| 1345 | /* if(wrq->u.frag.fixed == 0) should complain */ |
John Daiker | 141fa61 | 2009-03-10 06:59:54 -0700 | [diff] [blame] | 1346 | if (vwrq->disabled) |
Jean Tourrilhes | 3d5d5ac | 2005-09-02 11:40:39 -0700 | [diff] [blame] | 1347 | fthr = 32767; |
| 1348 | else { |
John Daiker | 141fa61 | 2009-03-10 06:59:54 -0700 | [diff] [blame] | 1349 | if ((fthr < 256) || (fthr > 2347)) /* To check out ! */ |
Jean Tourrilhes | 3d5d5ac | 2005-09-02 11:40:39 -0700 | [diff] [blame] | 1350 | return -EINVAL; |
| 1351 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1352 | local->sparm.b5.a_frag_threshold[0] = (fthr >> 8) & 0xFF; |
| 1353 | local->sparm.b5.a_frag_threshold[1] = fthr & 0xFF; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1354 | |
John Daiker | 141fa61 | 2009-03-10 06:59:54 -0700 | [diff] [blame] | 1355 | return -EINPROGRESS; /* Call commit handler */ |
Jean Tourrilhes | 3d5d5ac | 2005-09-02 11:40:39 -0700 | [diff] [blame] | 1356 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1357 | |
Jean Tourrilhes | 3d5d5ac | 2005-09-02 11:40:39 -0700 | [diff] [blame] | 1358 | /*------------------------------------------------------------------*/ |
| 1359 | /* |
| 1360 | * Wireless Handler : get Fragmentation threshold |
| 1361 | */ |
| 1362 | static int ray_get_frag(struct net_device *dev, |
| 1363 | struct iw_request_info *info, |
John Daiker | 141fa61 | 2009-03-10 06:59:54 -0700 | [diff] [blame] | 1364 | struct iw_param *vwrq, char *extra) |
Jean Tourrilhes | 3d5d5ac | 2005-09-02 11:40:39 -0700 | [diff] [blame] | 1365 | { |
Yoann Padioleau | 6dbc9c8 | 2007-08-03 19:37:16 +0200 | [diff] [blame] | 1366 | ray_dev_t *local = netdev_priv(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1367 | |
Jean Tourrilhes | 3d5d5ac | 2005-09-02 11:40:39 -0700 | [diff] [blame] | 1368 | vwrq->value = (local->sparm.b5.a_frag_threshold[0] << 8) |
John Daiker | 141fa61 | 2009-03-10 06:59:54 -0700 | [diff] [blame] | 1369 | + local->sparm.b5.a_frag_threshold[1]; |
Jean Tourrilhes | 3d5d5ac | 2005-09-02 11:40:39 -0700 | [diff] [blame] | 1370 | vwrq->disabled = (vwrq->value == 32767); |
| 1371 | vwrq->fixed = 1; |
| 1372 | |
| 1373 | return 0; |
| 1374 | } |
| 1375 | |
| 1376 | /*------------------------------------------------------------------*/ |
| 1377 | /* |
| 1378 | * Wireless Handler : set Mode of Operation |
| 1379 | */ |
| 1380 | static int ray_set_mode(struct net_device *dev, |
John Daiker | 141fa61 | 2009-03-10 06:59:54 -0700 | [diff] [blame] | 1381 | struct iw_request_info *info, __u32 *uwrq, char *extra) |
Jean Tourrilhes | 3d5d5ac | 2005-09-02 11:40:39 -0700 | [diff] [blame] | 1382 | { |
Yoann Padioleau | 6dbc9c8 | 2007-08-03 19:37:16 +0200 | [diff] [blame] | 1383 | ray_dev_t *local = netdev_priv(dev); |
John Daiker | 141fa61 | 2009-03-10 06:59:54 -0700 | [diff] [blame] | 1384 | int err = -EINPROGRESS; /* Call commit handler */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1385 | char card_mode = 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1386 | |
Jean Tourrilhes | 3d5d5ac | 2005-09-02 11:40:39 -0700 | [diff] [blame] | 1387 | /* Reject if card is already initialised */ |
John Daiker | 141fa61 | 2009-03-10 06:59:54 -0700 | [diff] [blame] | 1388 | if (local->card_status != CARD_AWAITING_PARAM) |
Jean Tourrilhes | 3d5d5ac | 2005-09-02 11:40:39 -0700 | [diff] [blame] | 1389 | return -EBUSY; |
| 1390 | |
John Daiker | 141fa61 | 2009-03-10 06:59:54 -0700 | [diff] [blame] | 1391 | switch (*uwrq) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1392 | case IW_MODE_ADHOC: |
Jean Tourrilhes | 3d5d5ac | 2005-09-02 11:40:39 -0700 | [diff] [blame] | 1393 | card_mode = 0; |
John Daiker | 141fa61 | 2009-03-10 06:59:54 -0700 | [diff] [blame] | 1394 | /* Fall through */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1395 | case IW_MODE_INFRA: |
Jean Tourrilhes | 3d5d5ac | 2005-09-02 11:40:39 -0700 | [diff] [blame] | 1396 | local->sparm.b5.a_network_type = card_mode; |
| 1397 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1398 | default: |
Jean Tourrilhes | 3d5d5ac | 2005-09-02 11:40:39 -0700 | [diff] [blame] | 1399 | err = -EINVAL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1400 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1401 | |
Jean Tourrilhes | 3d5d5ac | 2005-09-02 11:40:39 -0700 | [diff] [blame] | 1402 | return err; |
| 1403 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1404 | |
Jean Tourrilhes | 3d5d5ac | 2005-09-02 11:40:39 -0700 | [diff] [blame] | 1405 | /*------------------------------------------------------------------*/ |
| 1406 | /* |
| 1407 | * Wireless Handler : get Mode of Operation |
| 1408 | */ |
| 1409 | static int ray_get_mode(struct net_device *dev, |
John Daiker | 141fa61 | 2009-03-10 06:59:54 -0700 | [diff] [blame] | 1410 | struct iw_request_info *info, __u32 *uwrq, char *extra) |
Jean Tourrilhes | 3d5d5ac | 2005-09-02 11:40:39 -0700 | [diff] [blame] | 1411 | { |
Yoann Padioleau | 6dbc9c8 | 2007-08-03 19:37:16 +0200 | [diff] [blame] | 1412 | ray_dev_t *local = netdev_priv(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1413 | |
John Daiker | 141fa61 | 2009-03-10 06:59:54 -0700 | [diff] [blame] | 1414 | if (local->sparm.b5.a_network_type) |
Jean Tourrilhes | 3d5d5ac | 2005-09-02 11:40:39 -0700 | [diff] [blame] | 1415 | *uwrq = IW_MODE_INFRA; |
| 1416 | else |
| 1417 | *uwrq = IW_MODE_ADHOC; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1418 | |
Jean Tourrilhes | 3d5d5ac | 2005-09-02 11:40:39 -0700 | [diff] [blame] | 1419 | return 0; |
| 1420 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1421 | |
Jean Tourrilhes | 3d5d5ac | 2005-09-02 11:40:39 -0700 | [diff] [blame] | 1422 | /*------------------------------------------------------------------*/ |
| 1423 | /* |
| 1424 | * Wireless Handler : get range info |
| 1425 | */ |
| 1426 | static int ray_get_range(struct net_device *dev, |
| 1427 | struct iw_request_info *info, |
John Daiker | 141fa61 | 2009-03-10 06:59:54 -0700 | [diff] [blame] | 1428 | struct iw_point *dwrq, char *extra) |
Jean Tourrilhes | 3d5d5ac | 2005-09-02 11:40:39 -0700 | [diff] [blame] | 1429 | { |
John Daiker | 141fa61 | 2009-03-10 06:59:54 -0700 | [diff] [blame] | 1430 | struct iw_range *range = (struct iw_range *)extra; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1431 | |
John Daiker | 141fa61 | 2009-03-10 06:59:54 -0700 | [diff] [blame] | 1432 | memset((char *)range, 0, sizeof(struct iw_range)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1433 | |
Jean Tourrilhes | 3d5d5ac | 2005-09-02 11:40:39 -0700 | [diff] [blame] | 1434 | /* Set the length (very important for backward compatibility) */ |
| 1435 | dwrq->length = sizeof(struct iw_range); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1436 | |
Jean Tourrilhes | 3d5d5ac | 2005-09-02 11:40:39 -0700 | [diff] [blame] | 1437 | /* Set the Wireless Extension versions */ |
| 1438 | range->we_version_compiled = WIRELESS_EXT; |
| 1439 | range->we_version_source = 9; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1440 | |
Jean Tourrilhes | 3d5d5ac | 2005-09-02 11:40:39 -0700 | [diff] [blame] | 1441 | /* Set information in the range struct */ |
| 1442 | range->throughput = 1.1 * 1000 * 1000; /* Put the right number here */ |
John Daiker | 141fa61 | 2009-03-10 06:59:54 -0700 | [diff] [blame] | 1443 | range->num_channels = hop_pattern_length[(int)country]; |
Jean Tourrilhes | 3d5d5ac | 2005-09-02 11:40:39 -0700 | [diff] [blame] | 1444 | range->num_frequency = 0; |
| 1445 | range->max_qual.qual = 0; |
| 1446 | range->max_qual.level = 255; /* What's the correct value ? */ |
| 1447 | range->max_qual.noise = 255; /* Idem */ |
| 1448 | range->num_bitrates = 2; |
| 1449 | range->bitrate[0] = 1000000; /* 1 Mb/s */ |
| 1450 | range->bitrate[1] = 2000000; /* 2 Mb/s */ |
| 1451 | return 0; |
| 1452 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1453 | |
Jean Tourrilhes | 3d5d5ac | 2005-09-02 11:40:39 -0700 | [diff] [blame] | 1454 | /*------------------------------------------------------------------*/ |
| 1455 | /* |
| 1456 | * Wireless Private Handler : set framing mode |
| 1457 | */ |
| 1458 | static int ray_set_framing(struct net_device *dev, |
| 1459 | struct iw_request_info *info, |
John Daiker | 141fa61 | 2009-03-10 06:59:54 -0700 | [diff] [blame] | 1460 | union iwreq_data *wrqu, char *extra) |
Jean Tourrilhes | 3d5d5ac | 2005-09-02 11:40:39 -0700 | [diff] [blame] | 1461 | { |
| 1462 | translate = *(extra); /* Set framing mode */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1463 | |
Jean Tourrilhes | 3d5d5ac | 2005-09-02 11:40:39 -0700 | [diff] [blame] | 1464 | return 0; |
| 1465 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1466 | |
Jean Tourrilhes | 3d5d5ac | 2005-09-02 11:40:39 -0700 | [diff] [blame] | 1467 | /*------------------------------------------------------------------*/ |
| 1468 | /* |
| 1469 | * Wireless Private Handler : get framing mode |
| 1470 | */ |
| 1471 | static int ray_get_framing(struct net_device *dev, |
| 1472 | struct iw_request_info *info, |
John Daiker | 141fa61 | 2009-03-10 06:59:54 -0700 | [diff] [blame] | 1473 | union iwreq_data *wrqu, char *extra) |
Jean Tourrilhes | 3d5d5ac | 2005-09-02 11:40:39 -0700 | [diff] [blame] | 1474 | { |
| 1475 | *(extra) = translate; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1476 | |
Jean Tourrilhes | 3d5d5ac | 2005-09-02 11:40:39 -0700 | [diff] [blame] | 1477 | return 0; |
| 1478 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1479 | |
Jean Tourrilhes | 3d5d5ac | 2005-09-02 11:40:39 -0700 | [diff] [blame] | 1480 | /*------------------------------------------------------------------*/ |
| 1481 | /* |
| 1482 | * Wireless Private Handler : get country |
| 1483 | */ |
| 1484 | static int ray_get_country(struct net_device *dev, |
| 1485 | struct iw_request_info *info, |
John Daiker | 141fa61 | 2009-03-10 06:59:54 -0700 | [diff] [blame] | 1486 | union iwreq_data *wrqu, char *extra) |
Jean Tourrilhes | 3d5d5ac | 2005-09-02 11:40:39 -0700 | [diff] [blame] | 1487 | { |
| 1488 | *(extra) = country; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1489 | |
Jean Tourrilhes | 3d5d5ac | 2005-09-02 11:40:39 -0700 | [diff] [blame] | 1490 | return 0; |
| 1491 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1492 | |
Jean Tourrilhes | 3d5d5ac | 2005-09-02 11:40:39 -0700 | [diff] [blame] | 1493 | /*------------------------------------------------------------------*/ |
| 1494 | /* |
| 1495 | * Commit handler : called after a bunch of SET operations |
| 1496 | */ |
John Daiker | 141fa61 | 2009-03-10 06:59:54 -0700 | [diff] [blame] | 1497 | static int ray_commit(struct net_device *dev, struct iw_request_info *info, /* NULL */ |
| 1498 | void *zwrq, /* NULL */ |
| 1499 | char *extra) |
| 1500 | { /* NULL */ |
Jean Tourrilhes | 3d5d5ac | 2005-09-02 11:40:39 -0700 | [diff] [blame] | 1501 | return 0; |
| 1502 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1503 | |
Jean Tourrilhes | 3d5d5ac | 2005-09-02 11:40:39 -0700 | [diff] [blame] | 1504 | /*------------------------------------------------------------------*/ |
| 1505 | /* |
| 1506 | * Stats handler : return Wireless Stats |
| 1507 | */ |
John Daiker | 141fa61 | 2009-03-10 06:59:54 -0700 | [diff] [blame] | 1508 | static iw_stats *ray_get_wireless_stats(struct net_device *dev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1509 | { |
John Daiker | 141fa61 | 2009-03-10 06:59:54 -0700 | [diff] [blame] | 1510 | ray_dev_t *local = netdev_priv(dev); |
| 1511 | struct pcmcia_device *link = local->finder; |
| 1512 | struct status __iomem *p = local->sram + STATUS_BASE; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1513 | |
John Daiker | 141fa61 | 2009-03-10 06:59:54 -0700 | [diff] [blame] | 1514 | if (local == (ray_dev_t *) NULL) |
| 1515 | return (iw_stats *) NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1516 | |
John Daiker | 141fa61 | 2009-03-10 06:59:54 -0700 | [diff] [blame] | 1517 | local->wstats.status = local->card_status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1518 | #ifdef WIRELESS_SPY |
John Daiker | 141fa61 | 2009-03-10 06:59:54 -0700 | [diff] [blame] | 1519 | if ((local->spy_data.spy_number > 0) |
| 1520 | && (local->sparm.b5.a_network_type == 0)) { |
| 1521 | /* Get it from the first node in spy list */ |
| 1522 | local->wstats.qual.qual = local->spy_data.spy_stat[0].qual; |
| 1523 | local->wstats.qual.level = local->spy_data.spy_stat[0].level; |
| 1524 | local->wstats.qual.noise = local->spy_data.spy_stat[0].noise; |
| 1525 | local->wstats.qual.updated = |
| 1526 | local->spy_data.spy_stat[0].updated; |
| 1527 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1528 | #endif /* WIRELESS_SPY */ |
| 1529 | |
John Daiker | 141fa61 | 2009-03-10 06:59:54 -0700 | [diff] [blame] | 1530 | if (pcmcia_dev_present(link)) { |
| 1531 | local->wstats.qual.noise = readb(&p->rxnoise); |
| 1532 | local->wstats.qual.updated |= 4; |
| 1533 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1534 | |
John Daiker | 141fa61 | 2009-03-10 06:59:54 -0700 | [diff] [blame] | 1535 | return &local->wstats; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1536 | } /* end ray_get_wireless_stats */ |
Jean Tourrilhes | 3d5d5ac | 2005-09-02 11:40:39 -0700 | [diff] [blame] | 1537 | |
| 1538 | /*------------------------------------------------------------------*/ |
| 1539 | /* |
| 1540 | * Structures to export the Wireless Handlers |
| 1541 | */ |
| 1542 | |
John Daiker | 141fa61 | 2009-03-10 06:59:54 -0700 | [diff] [blame] | 1543 | static const iw_handler ray_handler[] = { |
| 1544 | [SIOCSIWCOMMIT - SIOCIWFIRST] = (iw_handler) ray_commit, |
| 1545 | [SIOCGIWNAME - SIOCIWFIRST] = (iw_handler) ray_get_name, |
| 1546 | [SIOCSIWFREQ - SIOCIWFIRST] = (iw_handler) ray_set_freq, |
| 1547 | [SIOCGIWFREQ - SIOCIWFIRST] = (iw_handler) ray_get_freq, |
| 1548 | [SIOCSIWMODE - SIOCIWFIRST] = (iw_handler) ray_set_mode, |
| 1549 | [SIOCGIWMODE - SIOCIWFIRST] = (iw_handler) ray_get_mode, |
| 1550 | [SIOCGIWRANGE - SIOCIWFIRST] = (iw_handler) ray_get_range, |
Jean Tourrilhes | 3d5d5ac | 2005-09-02 11:40:39 -0700 | [diff] [blame] | 1551 | #ifdef WIRELESS_SPY |
John Daiker | 141fa61 | 2009-03-10 06:59:54 -0700 | [diff] [blame] | 1552 | [SIOCSIWSPY - SIOCIWFIRST] = (iw_handler) iw_handler_set_spy, |
| 1553 | [SIOCGIWSPY - SIOCIWFIRST] = (iw_handler) iw_handler_get_spy, |
| 1554 | [SIOCSIWTHRSPY - SIOCIWFIRST] = (iw_handler) iw_handler_set_thrspy, |
| 1555 | [SIOCGIWTHRSPY - SIOCIWFIRST] = (iw_handler) iw_handler_get_thrspy, |
| 1556 | #endif /* WIRELESS_SPY */ |
| 1557 | [SIOCGIWAP - SIOCIWFIRST] = (iw_handler) ray_get_wap, |
| 1558 | [SIOCSIWESSID - SIOCIWFIRST] = (iw_handler) ray_set_essid, |
| 1559 | [SIOCGIWESSID - SIOCIWFIRST] = (iw_handler) ray_get_essid, |
| 1560 | [SIOCSIWRATE - SIOCIWFIRST] = (iw_handler) ray_set_rate, |
| 1561 | [SIOCGIWRATE - SIOCIWFIRST] = (iw_handler) ray_get_rate, |
| 1562 | [SIOCSIWRTS - SIOCIWFIRST] = (iw_handler) ray_set_rts, |
| 1563 | [SIOCGIWRTS - SIOCIWFIRST] = (iw_handler) ray_get_rts, |
| 1564 | [SIOCSIWFRAG - SIOCIWFIRST] = (iw_handler) ray_set_frag, |
| 1565 | [SIOCGIWFRAG - SIOCIWFIRST] = (iw_handler) ray_get_frag, |
Jean Tourrilhes | 3d5d5ac | 2005-09-02 11:40:39 -0700 | [diff] [blame] | 1566 | }; |
| 1567 | |
John Daiker | 141fa61 | 2009-03-10 06:59:54 -0700 | [diff] [blame] | 1568 | #define SIOCSIPFRAMING SIOCIWFIRSTPRIV /* Set framing mode */ |
Jean Tourrilhes | 3d5d5ac | 2005-09-02 11:40:39 -0700 | [diff] [blame] | 1569 | #define SIOCGIPFRAMING SIOCIWFIRSTPRIV + 1 /* Get framing mode */ |
| 1570 | #define SIOCGIPCOUNTRY SIOCIWFIRSTPRIV + 3 /* Get country code */ |
| 1571 | |
John Daiker | 141fa61 | 2009-03-10 06:59:54 -0700 | [diff] [blame] | 1572 | static const iw_handler ray_private_handler[] = { |
viro@ZenIV.linux.org.uk | 7a700fa | 2005-09-09 20:40:23 +0100 | [diff] [blame] | 1573 | [0] = (iw_handler) ray_set_framing, |
| 1574 | [1] = (iw_handler) ray_get_framing, |
| 1575 | [3] = (iw_handler) ray_get_country, |
Jean Tourrilhes | 3d5d5ac | 2005-09-02 11:40:39 -0700 | [diff] [blame] | 1576 | }; |
| 1577 | |
John Daiker | 141fa61 | 2009-03-10 06:59:54 -0700 | [diff] [blame] | 1578 | static const struct iw_priv_args ray_private_args[] = { |
Jean Tourrilhes | 3d5d5ac | 2005-09-02 11:40:39 -0700 | [diff] [blame] | 1579 | /* cmd, set_args, get_args, name */ |
John Daiker | 141fa61 | 2009-03-10 06:59:54 -0700 | [diff] [blame] | 1580 | {SIOCSIPFRAMING, IW_PRIV_TYPE_BYTE | IW_PRIV_SIZE_FIXED | 1, 0, |
| 1581 | "set_framing"}, |
| 1582 | {SIOCGIPFRAMING, 0, IW_PRIV_TYPE_BYTE | IW_PRIV_SIZE_FIXED | 1, |
| 1583 | "get_framing"}, |
| 1584 | {SIOCGIPCOUNTRY, 0, IW_PRIV_TYPE_BYTE | IW_PRIV_SIZE_FIXED | 1, |
| 1585 | "get_country"}, |
Jean Tourrilhes | 3d5d5ac | 2005-09-02 11:40:39 -0700 | [diff] [blame] | 1586 | }; |
| 1587 | |
John Daiker | 141fa61 | 2009-03-10 06:59:54 -0700 | [diff] [blame] | 1588 | static const struct iw_handler_def ray_handler_def = { |
| 1589 | .num_standard = ARRAY_SIZE(ray_handler), |
| 1590 | .num_private = ARRAY_SIZE(ray_private_handler), |
Denis Cheng | ff8ac60 | 2007-09-02 18:30:18 +0800 | [diff] [blame] | 1591 | .num_private_args = ARRAY_SIZE(ray_private_args), |
John Daiker | 141fa61 | 2009-03-10 06:59:54 -0700 | [diff] [blame] | 1592 | .standard = ray_handler, |
| 1593 | .private = ray_private_handler, |
| 1594 | .private_args = ray_private_args, |
Jean Tourrilhes | 3d5d5ac | 2005-09-02 11:40:39 -0700 | [diff] [blame] | 1595 | .get_wireless_stats = ray_get_wireless_stats, |
| 1596 | }; |
| 1597 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1598 | /*===========================================================================*/ |
| 1599 | static int ray_open(struct net_device *dev) |
| 1600 | { |
John Daiker | 141fa61 | 2009-03-10 06:59:54 -0700 | [diff] [blame] | 1601 | ray_dev_t *local = netdev_priv(dev); |
| 1602 | struct pcmcia_device *link; |
| 1603 | link = local->finder; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1604 | |
John Daiker | 141fa61 | 2009-03-10 06:59:54 -0700 | [diff] [blame] | 1605 | DEBUG(1, "ray_open('%s')\n", dev->name); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1606 | |
John Daiker | 141fa61 | 2009-03-10 06:59:54 -0700 | [diff] [blame] | 1607 | if (link->open == 0) |
| 1608 | local->num_multi = 0; |
| 1609 | link->open++; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1610 | |
John Daiker | 141fa61 | 2009-03-10 06:59:54 -0700 | [diff] [blame] | 1611 | /* If the card is not started, time to start it ! - Jean II */ |
| 1612 | if (local->card_status == CARD_AWAITING_PARAM) { |
| 1613 | int i; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1614 | |
John Daiker | 141fa61 | 2009-03-10 06:59:54 -0700 | [diff] [blame] | 1615 | DEBUG(1, "ray_open: doing init now !\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1616 | |
John Daiker | 141fa61 | 2009-03-10 06:59:54 -0700 | [diff] [blame] | 1617 | /* Download startup parameters */ |
| 1618 | if ((i = dl_startup_params(dev)) < 0) { |
| 1619 | printk(KERN_INFO |
| 1620 | "ray_dev_init dl_startup_params failed - " |
| 1621 | "returns 0x%x\n", i); |
| 1622 | return -1; |
| 1623 | } |
| 1624 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1625 | |
John Daiker | 141fa61 | 2009-03-10 06:59:54 -0700 | [diff] [blame] | 1626 | if (sniffer) |
| 1627 | netif_stop_queue(dev); |
| 1628 | else |
| 1629 | netif_start_queue(dev); |
| 1630 | |
| 1631 | DEBUG(2, "ray_open ending\n"); |
| 1632 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1633 | } /* end ray_open */ |
John Daiker | 141fa61 | 2009-03-10 06:59:54 -0700 | [diff] [blame] | 1634 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1635 | /*===========================================================================*/ |
| 1636 | static int ray_dev_close(struct net_device *dev) |
| 1637 | { |
John Daiker | 141fa61 | 2009-03-10 06:59:54 -0700 | [diff] [blame] | 1638 | ray_dev_t *local = netdev_priv(dev); |
| 1639 | struct pcmcia_device *link; |
| 1640 | link = local->finder; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1641 | |
John Daiker | 141fa61 | 2009-03-10 06:59:54 -0700 | [diff] [blame] | 1642 | DEBUG(1, "ray_dev_close('%s')\n", dev->name); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1643 | |
John Daiker | 141fa61 | 2009-03-10 06:59:54 -0700 | [diff] [blame] | 1644 | link->open--; |
| 1645 | netif_stop_queue(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1646 | |
John Daiker | 141fa61 | 2009-03-10 06:59:54 -0700 | [diff] [blame] | 1647 | /* In here, we should stop the hardware (stop card from beeing active) |
| 1648 | * and set local->card_status to CARD_AWAITING_PARAM, so that while the |
| 1649 | * card is closed we can chage its configuration. |
| 1650 | * Probably also need a COR reset to get sane state - Jean II */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1651 | |
John Daiker | 141fa61 | 2009-03-10 06:59:54 -0700 | [diff] [blame] | 1652 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1653 | } /* end ray_dev_close */ |
John Daiker | 141fa61 | 2009-03-10 06:59:54 -0700 | [diff] [blame] | 1654 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1655 | /*===========================================================================*/ |
John Daiker | 141fa61 | 2009-03-10 06:59:54 -0700 | [diff] [blame] | 1656 | static void ray_reset(struct net_device *dev) |
| 1657 | { |
| 1658 | DEBUG(1, "ray_reset entered\n"); |
| 1659 | return; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1660 | } |
John Daiker | 141fa61 | 2009-03-10 06:59:54 -0700 | [diff] [blame] | 1661 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1662 | /*===========================================================================*/ |
| 1663 | /* Cause a firmware interrupt if it is ready for one */ |
| 1664 | /* Return nonzero if not ready */ |
| 1665 | static int interrupt_ecf(ray_dev_t *local, int ccs) |
| 1666 | { |
John Daiker | 141fa61 | 2009-03-10 06:59:54 -0700 | [diff] [blame] | 1667 | int i = 50; |
| 1668 | struct pcmcia_device *link = local->finder; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1669 | |
John Daiker | 141fa61 | 2009-03-10 06:59:54 -0700 | [diff] [blame] | 1670 | if (!(pcmcia_dev_present(link))) { |
| 1671 | DEBUG(2, "ray_cs interrupt_ecf - device not present\n"); |
| 1672 | return -1; |
| 1673 | } |
| 1674 | DEBUG(2, "interrupt_ecf(local=%p, ccs = 0x%x\n", local, ccs); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1675 | |
John Daiker | 141fa61 | 2009-03-10 06:59:54 -0700 | [diff] [blame] | 1676 | while (i && |
| 1677 | (readb(local->amem + CIS_OFFSET + ECF_INTR_OFFSET) & |
| 1678 | ECF_INTR_SET)) |
| 1679 | i--; |
| 1680 | if (i == 0) { |
| 1681 | DEBUG(2, "ray_cs interrupt_ecf card not ready for interrupt\n"); |
| 1682 | return -1; |
| 1683 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1684 | /* Fill the mailbox, then kick the card */ |
John Daiker | 141fa61 | 2009-03-10 06:59:54 -0700 | [diff] [blame] | 1685 | writeb(ccs, local->sram + SCB_BASE); |
| 1686 | writeb(ECF_INTR_SET, local->amem + CIS_OFFSET + ECF_INTR_OFFSET); |
| 1687 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1688 | } /* interrupt_ecf */ |
John Daiker | 141fa61 | 2009-03-10 06:59:54 -0700 | [diff] [blame] | 1689 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1690 | /*===========================================================================*/ |
| 1691 | /* Get next free transmit CCS */ |
| 1692 | /* Return - index of current tx ccs */ |
| 1693 | static int get_free_tx_ccs(ray_dev_t *local) |
| 1694 | { |
John Daiker | 141fa61 | 2009-03-10 06:59:54 -0700 | [diff] [blame] | 1695 | int i; |
| 1696 | struct ccs __iomem *pccs = ccs_base(local); |
| 1697 | struct pcmcia_device *link = local->finder; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1698 | |
John Daiker | 141fa61 | 2009-03-10 06:59:54 -0700 | [diff] [blame] | 1699 | if (!(pcmcia_dev_present(link))) { |
| 1700 | DEBUG(2, "ray_cs get_free_tx_ccs - device not present\n"); |
| 1701 | return ECARDGONE; |
| 1702 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1703 | |
John Daiker | 141fa61 | 2009-03-10 06:59:54 -0700 | [diff] [blame] | 1704 | if (test_and_set_bit(0, &local->tx_ccs_lock)) { |
| 1705 | DEBUG(1, "ray_cs tx_ccs_lock busy\n"); |
| 1706 | return ECCSBUSY; |
| 1707 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1708 | |
John Daiker | 141fa61 | 2009-03-10 06:59:54 -0700 | [diff] [blame] | 1709 | for (i = 0; i < NUMBER_OF_TX_CCS; i++) { |
| 1710 | if (readb(&(pccs + i)->buffer_status) == CCS_BUFFER_FREE) { |
| 1711 | writeb(CCS_BUFFER_BUSY, &(pccs + i)->buffer_status); |
| 1712 | writeb(CCS_END_LIST, &(pccs + i)->link); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1713 | local->tx_ccs_lock = 0; |
John Daiker | 141fa61 | 2009-03-10 06:59:54 -0700 | [diff] [blame] | 1714 | return i; |
| 1715 | } |
| 1716 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1717 | local->tx_ccs_lock = 0; |
John Daiker | 141fa61 | 2009-03-10 06:59:54 -0700 | [diff] [blame] | 1718 | DEBUG(2, "ray_cs ERROR no free tx CCS for raylink card\n"); |
| 1719 | return ECCSFULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1720 | } /* get_free_tx_ccs */ |
John Daiker | 141fa61 | 2009-03-10 06:59:54 -0700 | [diff] [blame] | 1721 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1722 | /*===========================================================================*/ |
| 1723 | /* Get next free CCS */ |
| 1724 | /* Return - index of current ccs */ |
| 1725 | static int get_free_ccs(ray_dev_t *local) |
| 1726 | { |
John Daiker | 141fa61 | 2009-03-10 06:59:54 -0700 | [diff] [blame] | 1727 | int i; |
| 1728 | struct ccs __iomem *pccs = ccs_base(local); |
| 1729 | struct pcmcia_device *link = local->finder; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1730 | |
John Daiker | 141fa61 | 2009-03-10 06:59:54 -0700 | [diff] [blame] | 1731 | if (!(pcmcia_dev_present(link))) { |
| 1732 | DEBUG(2, "ray_cs get_free_ccs - device not present\n"); |
| 1733 | return ECARDGONE; |
| 1734 | } |
| 1735 | if (test_and_set_bit(0, &local->ccs_lock)) { |
| 1736 | DEBUG(1, "ray_cs ccs_lock busy\n"); |
| 1737 | return ECCSBUSY; |
| 1738 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1739 | |
John Daiker | 141fa61 | 2009-03-10 06:59:54 -0700 | [diff] [blame] | 1740 | for (i = NUMBER_OF_TX_CCS; i < NUMBER_OF_CCS; i++) { |
| 1741 | if (readb(&(pccs + i)->buffer_status) == CCS_BUFFER_FREE) { |
| 1742 | writeb(CCS_BUFFER_BUSY, &(pccs + i)->buffer_status); |
| 1743 | writeb(CCS_END_LIST, &(pccs + i)->link); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1744 | local->ccs_lock = 0; |
John Daiker | 141fa61 | 2009-03-10 06:59:54 -0700 | [diff] [blame] | 1745 | return i; |
| 1746 | } |
| 1747 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1748 | local->ccs_lock = 0; |
John Daiker | 141fa61 | 2009-03-10 06:59:54 -0700 | [diff] [blame] | 1749 | DEBUG(1, "ray_cs ERROR no free CCS for raylink card\n"); |
| 1750 | return ECCSFULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1751 | } /* get_free_ccs */ |
John Daiker | 141fa61 | 2009-03-10 06:59:54 -0700 | [diff] [blame] | 1752 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1753 | /*===========================================================================*/ |
| 1754 | static void authenticate_timeout(u_long data) |
| 1755 | { |
John Daiker | 141fa61 | 2009-03-10 06:59:54 -0700 | [diff] [blame] | 1756 | ray_dev_t *local = (ray_dev_t *) data; |
| 1757 | del_timer(&local->timer); |
| 1758 | printk(KERN_INFO "ray_cs Authentication with access point failed" |
| 1759 | " - timeout\n"); |
| 1760 | join_net((u_long) local); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1761 | } |
John Daiker | 141fa61 | 2009-03-10 06:59:54 -0700 | [diff] [blame] | 1762 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1763 | /*===========================================================================*/ |
| 1764 | static int asc_to_int(char a) |
| 1765 | { |
John Daiker | 141fa61 | 2009-03-10 06:59:54 -0700 | [diff] [blame] | 1766 | if (a < '0') |
| 1767 | return -1; |
| 1768 | if (a <= '9') |
| 1769 | return (a - '0'); |
| 1770 | if (a < 'A') |
| 1771 | return -1; |
| 1772 | if (a <= 'F') |
| 1773 | return (10 + a - 'A'); |
| 1774 | if (a < 'a') |
| 1775 | return -1; |
| 1776 | if (a <= 'f') |
| 1777 | return (10 + a - 'a'); |
| 1778 | return -1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1779 | } |
John Daiker | 141fa61 | 2009-03-10 06:59:54 -0700 | [diff] [blame] | 1780 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1781 | /*===========================================================================*/ |
| 1782 | static int parse_addr(char *in_str, UCHAR *out) |
| 1783 | { |
John Daiker | 141fa61 | 2009-03-10 06:59:54 -0700 | [diff] [blame] | 1784 | int len; |
| 1785 | int i, j, k; |
| 1786 | int status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1787 | |
John Daiker | 141fa61 | 2009-03-10 06:59:54 -0700 | [diff] [blame] | 1788 | if (in_str == NULL) |
| 1789 | return 0; |
| 1790 | if ((len = strlen(in_str)) < 2) |
| 1791 | return 0; |
| 1792 | memset(out, 0, ADDRLEN); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1793 | |
John Daiker | 141fa61 | 2009-03-10 06:59:54 -0700 | [diff] [blame] | 1794 | status = 1; |
| 1795 | j = len - 1; |
| 1796 | if (j > 12) |
| 1797 | j = 12; |
| 1798 | i = 5; |
| 1799 | |
| 1800 | while (j > 0) { |
| 1801 | if ((k = asc_to_int(in_str[j--])) != -1) |
| 1802 | out[i] = k; |
| 1803 | else |
| 1804 | return 0; |
| 1805 | |
| 1806 | if (j == 0) |
| 1807 | break; |
| 1808 | if ((k = asc_to_int(in_str[j--])) != -1) |
| 1809 | out[i] += k << 4; |
| 1810 | else |
| 1811 | return 0; |
| 1812 | if (!i--) |
| 1813 | break; |
| 1814 | } |
| 1815 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1816 | } |
John Daiker | 141fa61 | 2009-03-10 06:59:54 -0700 | [diff] [blame] | 1817 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1818 | /*===========================================================================*/ |
| 1819 | static struct net_device_stats *ray_get_stats(struct net_device *dev) |
| 1820 | { |
John Daiker | 141fa61 | 2009-03-10 06:59:54 -0700 | [diff] [blame] | 1821 | ray_dev_t *local = netdev_priv(dev); |
| 1822 | struct pcmcia_device *link = local->finder; |
| 1823 | struct status __iomem *p = local->sram + STATUS_BASE; |
| 1824 | if (!(pcmcia_dev_present(link))) { |
| 1825 | DEBUG(2, "ray_cs net_device_stats - device not present\n"); |
| 1826 | return &local->stats; |
| 1827 | } |
| 1828 | if (readb(&p->mrx_overflow_for_host)) { |
| 1829 | local->stats.rx_over_errors += swab16(readw(&p->mrx_overflow)); |
| 1830 | writeb(0, &p->mrx_overflow); |
| 1831 | writeb(0, &p->mrx_overflow_for_host); |
| 1832 | } |
| 1833 | if (readb(&p->mrx_checksum_error_for_host)) { |
| 1834 | local->stats.rx_crc_errors += |
| 1835 | swab16(readw(&p->mrx_checksum_error)); |
| 1836 | writeb(0, &p->mrx_checksum_error); |
| 1837 | writeb(0, &p->mrx_checksum_error_for_host); |
| 1838 | } |
| 1839 | if (readb(&p->rx_hec_error_for_host)) { |
| 1840 | local->stats.rx_frame_errors += swab16(readw(&p->rx_hec_error)); |
| 1841 | writeb(0, &p->rx_hec_error); |
| 1842 | writeb(0, &p->rx_hec_error_for_host); |
| 1843 | } |
| 1844 | return &local->stats; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1845 | } |
John Daiker | 141fa61 | 2009-03-10 06:59:54 -0700 | [diff] [blame] | 1846 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1847 | /*===========================================================================*/ |
John Daiker | 141fa61 | 2009-03-10 06:59:54 -0700 | [diff] [blame] | 1848 | static void ray_update_parm(struct net_device *dev, UCHAR objid, UCHAR *value, |
| 1849 | int len) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1850 | { |
John Daiker | 141fa61 | 2009-03-10 06:59:54 -0700 | [diff] [blame] | 1851 | ray_dev_t *local = netdev_priv(dev); |
| 1852 | struct pcmcia_device *link = local->finder; |
| 1853 | int ccsindex; |
| 1854 | int i; |
| 1855 | struct ccs __iomem *pccs; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1856 | |
John Daiker | 141fa61 | 2009-03-10 06:59:54 -0700 | [diff] [blame] | 1857 | if (!(pcmcia_dev_present(link))) { |
| 1858 | DEBUG(2, "ray_update_parm - device not present\n"); |
| 1859 | return; |
| 1860 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1861 | |
John Daiker | 141fa61 | 2009-03-10 06:59:54 -0700 | [diff] [blame] | 1862 | if ((ccsindex = get_free_ccs(local)) < 0) { |
| 1863 | DEBUG(0, "ray_update_parm - No free ccs\n"); |
| 1864 | return; |
| 1865 | } |
| 1866 | pccs = ccs_base(local) + ccsindex; |
| 1867 | writeb(CCS_UPDATE_PARAMS, &pccs->cmd); |
| 1868 | writeb(objid, &pccs->var.update_param.object_id); |
| 1869 | writeb(1, &pccs->var.update_param.number_objects); |
| 1870 | writeb(0, &pccs->var.update_param.failure_cause); |
| 1871 | for (i = 0; i < len; i++) { |
| 1872 | writeb(value[i], local->sram + HOST_TO_ECF_BASE); |
| 1873 | } |
| 1874 | /* Interrupt the firmware to process the command */ |
| 1875 | if (interrupt_ecf(local, ccsindex)) { |
| 1876 | DEBUG(0, "ray_cs associate failed - ECF not ready for intr\n"); |
| 1877 | writeb(CCS_BUFFER_FREE, &(pccs++)->buffer_status); |
| 1878 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1879 | } |
John Daiker | 141fa61 | 2009-03-10 06:59:54 -0700 | [diff] [blame] | 1880 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1881 | /*===========================================================================*/ |
| 1882 | static void ray_update_multi_list(struct net_device *dev, int all) |
| 1883 | { |
John Daiker | 141fa61 | 2009-03-10 06:59:54 -0700 | [diff] [blame] | 1884 | struct dev_mc_list *dmi, **dmip; |
| 1885 | int ccsindex; |
| 1886 | struct ccs __iomem *pccs; |
| 1887 | int i = 0; |
| 1888 | ray_dev_t *local = netdev_priv(dev); |
| 1889 | struct pcmcia_device *link = local->finder; |
| 1890 | void __iomem *p = local->sram + HOST_TO_ECF_BASE; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1891 | |
John Daiker | 141fa61 | 2009-03-10 06:59:54 -0700 | [diff] [blame] | 1892 | if (!(pcmcia_dev_present(link))) { |
| 1893 | DEBUG(2, "ray_update_multi_list - device not present\n"); |
| 1894 | return; |
| 1895 | } else |
| 1896 | DEBUG(2, "ray_update_multi_list(%p)\n", dev); |
| 1897 | if ((ccsindex = get_free_ccs(local)) < 0) { |
| 1898 | DEBUG(1, "ray_update_multi - No free ccs\n"); |
| 1899 | return; |
| 1900 | } |
| 1901 | pccs = ccs_base(local) + ccsindex; |
| 1902 | writeb(CCS_UPDATE_MULTICAST_LIST, &pccs->cmd); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1903 | |
John Daiker | 141fa61 | 2009-03-10 06:59:54 -0700 | [diff] [blame] | 1904 | if (all) { |
| 1905 | writeb(0xff, &pccs->var); |
| 1906 | local->num_multi = 0xff; |
| 1907 | } else { |
| 1908 | /* Copy the kernel's list of MC addresses to card */ |
| 1909 | for (dmip = &dev->mc_list; (dmi = *dmip) != NULL; |
| 1910 | dmip = &dmi->next) { |
| 1911 | memcpy_toio(p, dmi->dmi_addr, ETH_ALEN); |
| 1912 | DEBUG(1, |
| 1913 | "ray_update_multi add addr %02x%02x%02x%02x%02x%02x\n", |
| 1914 | dmi->dmi_addr[0], dmi->dmi_addr[1], |
| 1915 | dmi->dmi_addr[2], dmi->dmi_addr[3], |
| 1916 | dmi->dmi_addr[4], dmi->dmi_addr[5]); |
| 1917 | p += ETH_ALEN; |
| 1918 | i++; |
| 1919 | } |
| 1920 | if (i > 256 / ADDRLEN) |
| 1921 | i = 256 / ADDRLEN; |
| 1922 | writeb((UCHAR) i, &pccs->var); |
| 1923 | DEBUG(1, "ray_cs update_multi %d addresses in list\n", i); |
| 1924 | /* Interrupt the firmware to process the command */ |
| 1925 | local->num_multi = i; |
| 1926 | } |
| 1927 | if (interrupt_ecf(local, ccsindex)) { |
| 1928 | DEBUG(1, |
| 1929 | "ray_cs update_multi failed - ECF not ready for intr\n"); |
| 1930 | writeb(CCS_BUFFER_FREE, &(pccs++)->buffer_status); |
| 1931 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1932 | } /* end ray_update_multi_list */ |
John Daiker | 141fa61 | 2009-03-10 06:59:54 -0700 | [diff] [blame] | 1933 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1934 | /*===========================================================================*/ |
| 1935 | static void set_multicast_list(struct net_device *dev) |
| 1936 | { |
John Daiker | 141fa61 | 2009-03-10 06:59:54 -0700 | [diff] [blame] | 1937 | ray_dev_t *local = netdev_priv(dev); |
| 1938 | UCHAR promisc; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1939 | |
John Daiker | 141fa61 | 2009-03-10 06:59:54 -0700 | [diff] [blame] | 1940 | DEBUG(2, "ray_cs set_multicast_list(%p)\n", dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1941 | |
John Daiker | 141fa61 | 2009-03-10 06:59:54 -0700 | [diff] [blame] | 1942 | if (dev->flags & IFF_PROMISC) { |
| 1943 | if (local->sparm.b5.a_promiscuous_mode == 0) { |
| 1944 | DEBUG(1, "ray_cs set_multicast_list promisc on\n"); |
| 1945 | local->sparm.b5.a_promiscuous_mode = 1; |
| 1946 | promisc = 1; |
| 1947 | ray_update_parm(dev, OBJID_promiscuous_mode, |
| 1948 | &promisc, sizeof(promisc)); |
| 1949 | } |
| 1950 | } else { |
| 1951 | if (local->sparm.b5.a_promiscuous_mode == 1) { |
| 1952 | DEBUG(1, "ray_cs set_multicast_list promisc off\n"); |
| 1953 | local->sparm.b5.a_promiscuous_mode = 0; |
| 1954 | promisc = 0; |
| 1955 | ray_update_parm(dev, OBJID_promiscuous_mode, |
| 1956 | &promisc, sizeof(promisc)); |
| 1957 | } |
| 1958 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1959 | |
John Daiker | 141fa61 | 2009-03-10 06:59:54 -0700 | [diff] [blame] | 1960 | if (dev->flags & IFF_ALLMULTI) |
| 1961 | ray_update_multi_list(dev, 1); |
| 1962 | else { |
| 1963 | if (local->num_multi != dev->mc_count) |
| 1964 | ray_update_multi_list(dev, 0); |
| 1965 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1966 | } /* end set_multicast_list */ |
John Daiker | 141fa61 | 2009-03-10 06:59:54 -0700 | [diff] [blame] | 1967 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1968 | /*============================================================================= |
| 1969 | * All routines below here are run at interrupt time. |
| 1970 | =============================================================================*/ |
David Howells | 7d12e78 | 2006-10-05 14:55:46 +0100 | [diff] [blame] | 1971 | static irqreturn_t ray_interrupt(int irq, void *dev_id) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1972 | { |
John Daiker | 141fa61 | 2009-03-10 06:59:54 -0700 | [diff] [blame] | 1973 | struct net_device *dev = (struct net_device *)dev_id; |
| 1974 | struct pcmcia_device *link; |
| 1975 | ray_dev_t *local; |
| 1976 | struct ccs __iomem *pccs; |
| 1977 | struct rcs __iomem *prcs; |
| 1978 | UCHAR rcsindex; |
| 1979 | UCHAR tmp; |
| 1980 | UCHAR cmd; |
| 1981 | UCHAR status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1982 | |
John Daiker | 141fa61 | 2009-03-10 06:59:54 -0700 | [diff] [blame] | 1983 | if (dev == NULL) /* Note that we want interrupts with dev->start == 0 */ |
| 1984 | return IRQ_NONE; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1985 | |
John Daiker | 141fa61 | 2009-03-10 06:59:54 -0700 | [diff] [blame] | 1986 | DEBUG(4, "ray_cs: interrupt for *dev=%p\n", dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1987 | |
John Daiker | 141fa61 | 2009-03-10 06:59:54 -0700 | [diff] [blame] | 1988 | local = netdev_priv(dev); |
| 1989 | link = (struct pcmcia_device *)local->finder; |
| 1990 | if (!pcmcia_dev_present(link)) { |
| 1991 | DEBUG(2, |
| 1992 | "ray_cs interrupt from device not present or suspended.\n"); |
| 1993 | return IRQ_NONE; |
| 1994 | } |
| 1995 | rcsindex = readb(&((struct scb __iomem *)(local->sram))->rcs_index); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1996 | |
John Daiker | 141fa61 | 2009-03-10 06:59:54 -0700 | [diff] [blame] | 1997 | if (rcsindex >= (NUMBER_OF_CCS + NUMBER_OF_RCS)) { |
| 1998 | DEBUG(1, "ray_cs interrupt bad rcsindex = 0x%x\n", rcsindex); |
| 1999 | clear_interrupt(local); |
| 2000 | return IRQ_HANDLED; |
| 2001 | } |
| 2002 | if (rcsindex < NUMBER_OF_CCS) { /* If it's a returned CCS */ |
| 2003 | pccs = ccs_base(local) + rcsindex; |
| 2004 | cmd = readb(&pccs->cmd); |
| 2005 | status = readb(&pccs->buffer_status); |
| 2006 | switch (cmd) { |
| 2007 | case CCS_DOWNLOAD_STARTUP_PARAMS: /* Happens in firmware someday */ |
| 2008 | del_timer(&local->timer); |
| 2009 | if (status == CCS_COMMAND_COMPLETE) { |
| 2010 | DEBUG(1, |
| 2011 | "ray_cs interrupt download_startup_parameters OK\n"); |
| 2012 | } else { |
| 2013 | DEBUG(1, |
| 2014 | "ray_cs interrupt download_startup_parameters fail\n"); |
| 2015 | } |
| 2016 | break; |
| 2017 | case CCS_UPDATE_PARAMS: |
| 2018 | DEBUG(1, "ray_cs interrupt update params done\n"); |
| 2019 | if (status != CCS_COMMAND_COMPLETE) { |
| 2020 | tmp = |
| 2021 | readb(&pccs->var.update_param. |
| 2022 | failure_cause); |
| 2023 | DEBUG(0, |
| 2024 | "ray_cs interrupt update params failed - reason %d\n", |
| 2025 | tmp); |
| 2026 | } |
| 2027 | break; |
| 2028 | case CCS_REPORT_PARAMS: |
| 2029 | DEBUG(1, "ray_cs interrupt report params done\n"); |
| 2030 | break; |
| 2031 | case CCS_UPDATE_MULTICAST_LIST: /* Note that this CCS isn't returned */ |
| 2032 | DEBUG(1, |
| 2033 | "ray_cs interrupt CCS Update Multicast List done\n"); |
| 2034 | break; |
| 2035 | case CCS_UPDATE_POWER_SAVINGS_MODE: |
| 2036 | DEBUG(1, |
| 2037 | "ray_cs interrupt update power save mode done\n"); |
| 2038 | break; |
| 2039 | case CCS_START_NETWORK: |
| 2040 | case CCS_JOIN_NETWORK: |
| 2041 | if (status == CCS_COMMAND_COMPLETE) { |
| 2042 | if (readb |
| 2043 | (&pccs->var.start_network.net_initiated) == |
| 2044 | 1) { |
| 2045 | DEBUG(0, |
| 2046 | "ray_cs interrupt network \"%s\" started\n", |
| 2047 | local->sparm.b4.a_current_ess_id); |
| 2048 | } else { |
| 2049 | DEBUG(0, |
| 2050 | "ray_cs interrupt network \"%s\" joined\n", |
| 2051 | local->sparm.b4.a_current_ess_id); |
| 2052 | } |
| 2053 | memcpy_fromio(&local->bss_id, |
| 2054 | pccs->var.start_network.bssid, |
| 2055 | ADDRLEN); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2056 | |
John Daiker | 141fa61 | 2009-03-10 06:59:54 -0700 | [diff] [blame] | 2057 | if (local->fw_ver == 0x55) |
| 2058 | local->net_default_tx_rate = 3; |
| 2059 | else |
| 2060 | local->net_default_tx_rate = |
| 2061 | readb(&pccs->var.start_network. |
| 2062 | net_default_tx_rate); |
| 2063 | local->encryption = |
| 2064 | readb(&pccs->var.start_network.encryption); |
| 2065 | if (!sniffer && (local->net_type == INFRA) |
| 2066 | && !(local->sparm.b4.a_acting_as_ap_status)) { |
| 2067 | authenticate(local); |
| 2068 | } |
| 2069 | local->card_status = CARD_ACQ_COMPLETE; |
| 2070 | } else { |
| 2071 | local->card_status = CARD_ACQ_FAILED; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2072 | |
John Daiker | 141fa61 | 2009-03-10 06:59:54 -0700 | [diff] [blame] | 2073 | del_timer(&local->timer); |
| 2074 | local->timer.expires = jiffies + HZ * 5; |
| 2075 | local->timer.data = (long)local; |
| 2076 | if (status == CCS_START_NETWORK) { |
| 2077 | DEBUG(0, |
| 2078 | "ray_cs interrupt network \"%s\" start failed\n", |
| 2079 | local->sparm.b4.a_current_ess_id); |
| 2080 | local->timer.function = &start_net; |
| 2081 | } else { |
| 2082 | DEBUG(0, |
| 2083 | "ray_cs interrupt network \"%s\" join failed\n", |
| 2084 | local->sparm.b4.a_current_ess_id); |
| 2085 | local->timer.function = &join_net; |
| 2086 | } |
| 2087 | add_timer(&local->timer); |
| 2088 | } |
| 2089 | break; |
| 2090 | case CCS_START_ASSOCIATION: |
| 2091 | if (status == CCS_COMMAND_COMPLETE) { |
| 2092 | local->card_status = CARD_ASSOC_COMPLETE; |
| 2093 | DEBUG(0, "ray_cs association successful\n"); |
| 2094 | } else { |
| 2095 | DEBUG(0, "ray_cs association failed,\n"); |
| 2096 | local->card_status = CARD_ASSOC_FAILED; |
| 2097 | join_net((u_long) local); |
| 2098 | } |
| 2099 | break; |
| 2100 | case CCS_TX_REQUEST: |
| 2101 | if (status == CCS_COMMAND_COMPLETE) { |
| 2102 | DEBUG(3, |
| 2103 | "ray_cs interrupt tx request complete\n"); |
| 2104 | } else { |
| 2105 | DEBUG(1, |
| 2106 | "ray_cs interrupt tx request failed\n"); |
| 2107 | } |
| 2108 | if (!sniffer) |
| 2109 | netif_start_queue(dev); |
| 2110 | netif_wake_queue(dev); |
| 2111 | break; |
| 2112 | case CCS_TEST_MEMORY: |
| 2113 | DEBUG(1, "ray_cs interrupt mem test done\n"); |
| 2114 | break; |
| 2115 | case CCS_SHUTDOWN: |
| 2116 | DEBUG(1, |
| 2117 | "ray_cs interrupt Unexpected CCS returned - Shutdown\n"); |
| 2118 | break; |
| 2119 | case CCS_DUMP_MEMORY: |
| 2120 | DEBUG(1, "ray_cs interrupt dump memory done\n"); |
| 2121 | break; |
| 2122 | case CCS_START_TIMER: |
| 2123 | DEBUG(2, |
| 2124 | "ray_cs interrupt DING - raylink timer expired\n"); |
| 2125 | break; |
| 2126 | default: |
| 2127 | DEBUG(1, |
| 2128 | "ray_cs interrupt Unexpected CCS 0x%x returned 0x%x\n", |
| 2129 | rcsindex, cmd); |
| 2130 | } |
| 2131 | writeb(CCS_BUFFER_FREE, &pccs->buffer_status); |
| 2132 | } else { /* It's an RCS */ |
| 2133 | |
| 2134 | prcs = rcs_base(local) + rcsindex; |
| 2135 | |
| 2136 | switch (readb(&prcs->interrupt_id)) { |
| 2137 | case PROCESS_RX_PACKET: |
| 2138 | ray_rx(dev, local, prcs); |
| 2139 | break; |
| 2140 | case REJOIN_NET_COMPLETE: |
| 2141 | DEBUG(1, "ray_cs interrupt rejoin net complete\n"); |
| 2142 | local->card_status = CARD_ACQ_COMPLETE; |
| 2143 | /* do we need to clear tx buffers CCS's? */ |
| 2144 | if (local->sparm.b4.a_network_type == ADHOC) { |
| 2145 | if (!sniffer) |
| 2146 | netif_start_queue(dev); |
| 2147 | } else { |
| 2148 | memcpy_fromio(&local->bss_id, |
| 2149 | prcs->var.rejoin_net_complete. |
| 2150 | bssid, ADDRLEN); |
| 2151 | DEBUG(1, |
| 2152 | "ray_cs new BSSID = %02x%02x%02x%02x%02x%02x\n", |
| 2153 | local->bss_id[0], local->bss_id[1], |
| 2154 | local->bss_id[2], local->bss_id[3], |
| 2155 | local->bss_id[4], local->bss_id[5]); |
| 2156 | if (!sniffer) |
| 2157 | authenticate(local); |
| 2158 | } |
| 2159 | break; |
| 2160 | case ROAMING_INITIATED: |
| 2161 | DEBUG(1, "ray_cs interrupt roaming initiated\n"); |
| 2162 | netif_stop_queue(dev); |
| 2163 | local->card_status = CARD_DOING_ACQ; |
| 2164 | break; |
| 2165 | case JAPAN_CALL_SIGN_RXD: |
| 2166 | DEBUG(1, "ray_cs interrupt japan call sign rx\n"); |
| 2167 | break; |
| 2168 | default: |
| 2169 | DEBUG(1, |
| 2170 | "ray_cs Unexpected interrupt for RCS 0x%x cmd = 0x%x\n", |
| 2171 | rcsindex, |
| 2172 | (unsigned int)readb(&prcs->interrupt_id)); |
| 2173 | break; |
| 2174 | } |
| 2175 | writeb(CCS_BUFFER_FREE, &prcs->buffer_status); |
| 2176 | } |
| 2177 | clear_interrupt(local); |
| 2178 | return IRQ_HANDLED; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2179 | } /* ray_interrupt */ |
John Daiker | 141fa61 | 2009-03-10 06:59:54 -0700 | [diff] [blame] | 2180 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2181 | /*===========================================================================*/ |
John Daiker | 141fa61 | 2009-03-10 06:59:54 -0700 | [diff] [blame] | 2182 | static void ray_rx(struct net_device *dev, ray_dev_t *local, |
| 2183 | struct rcs __iomem *prcs) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2184 | { |
John Daiker | 141fa61 | 2009-03-10 06:59:54 -0700 | [diff] [blame] | 2185 | int rx_len; |
| 2186 | unsigned int pkt_addr; |
| 2187 | void __iomem *pmsg; |
| 2188 | DEBUG(4, "ray_rx process rx packet\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2189 | |
John Daiker | 141fa61 | 2009-03-10 06:59:54 -0700 | [diff] [blame] | 2190 | /* Calculate address of packet within Rx buffer */ |
| 2191 | pkt_addr = ((readb(&prcs->var.rx_packet.rx_data_ptr[0]) << 8) |
| 2192 | + readb(&prcs->var.rx_packet.rx_data_ptr[1])) & RX_BUFF_END; |
| 2193 | /* Length of first packet fragment */ |
| 2194 | rx_len = (readb(&prcs->var.rx_packet.rx_data_length[0]) << 8) |
| 2195 | + readb(&prcs->var.rx_packet.rx_data_length[1]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2196 | |
John Daiker | 141fa61 | 2009-03-10 06:59:54 -0700 | [diff] [blame] | 2197 | local->last_rsl = readb(&prcs->var.rx_packet.rx_sig_lev); |
| 2198 | pmsg = local->rmem + pkt_addr; |
| 2199 | switch (readb(pmsg)) { |
| 2200 | case DATA_TYPE: |
| 2201 | DEBUG(4, "ray_rx data type\n"); |
| 2202 | rx_data(dev, prcs, pkt_addr, rx_len); |
| 2203 | break; |
| 2204 | case AUTHENTIC_TYPE: |
| 2205 | DEBUG(4, "ray_rx authentic type\n"); |
| 2206 | if (sniffer) |
| 2207 | rx_data(dev, prcs, pkt_addr, rx_len); |
| 2208 | else |
| 2209 | rx_authenticate(local, prcs, pkt_addr, rx_len); |
| 2210 | break; |
| 2211 | case DEAUTHENTIC_TYPE: |
| 2212 | DEBUG(4, "ray_rx deauth type\n"); |
| 2213 | if (sniffer) |
| 2214 | rx_data(dev, prcs, pkt_addr, rx_len); |
| 2215 | else |
| 2216 | rx_deauthenticate(local, prcs, pkt_addr, rx_len); |
| 2217 | break; |
| 2218 | case NULL_MSG_TYPE: |
| 2219 | DEBUG(3, "ray_cs rx NULL msg\n"); |
| 2220 | break; |
| 2221 | case BEACON_TYPE: |
| 2222 | DEBUG(4, "ray_rx beacon type\n"); |
| 2223 | if (sniffer) |
| 2224 | rx_data(dev, prcs, pkt_addr, rx_len); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2225 | |
John Daiker | 141fa61 | 2009-03-10 06:59:54 -0700 | [diff] [blame] | 2226 | copy_from_rx_buff(local, (UCHAR *) &local->last_bcn, pkt_addr, |
| 2227 | rx_len < sizeof(struct beacon_rx) ? |
| 2228 | rx_len : sizeof(struct beacon_rx)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2229 | |
John Daiker | 141fa61 | 2009-03-10 06:59:54 -0700 | [diff] [blame] | 2230 | local->beacon_rxed = 1; |
| 2231 | /* Get the statistics so the card counters never overflow */ |
| 2232 | ray_get_stats(dev); |
| 2233 | break; |
| 2234 | default: |
| 2235 | DEBUG(0, "ray_cs unknown pkt type %2x\n", |
| 2236 | (unsigned int)readb(pmsg)); |
| 2237 | break; |
| 2238 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2239 | |
| 2240 | } /* end ray_rx */ |
John Daiker | 141fa61 | 2009-03-10 06:59:54 -0700 | [diff] [blame] | 2241 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2242 | /*===========================================================================*/ |
John Daiker | 141fa61 | 2009-03-10 06:59:54 -0700 | [diff] [blame] | 2243 | static void rx_data(struct net_device *dev, struct rcs __iomem *prcs, |
| 2244 | unsigned int pkt_addr, int rx_len) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2245 | { |
John Daiker | 141fa61 | 2009-03-10 06:59:54 -0700 | [diff] [blame] | 2246 | struct sk_buff *skb = NULL; |
| 2247 | struct rcs __iomem *prcslink = prcs; |
| 2248 | ray_dev_t *local = netdev_priv(dev); |
| 2249 | UCHAR *rx_ptr; |
| 2250 | int total_len; |
| 2251 | int tmp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2252 | #ifdef WIRELESS_SPY |
John Daiker | 141fa61 | 2009-03-10 06:59:54 -0700 | [diff] [blame] | 2253 | int siglev = local->last_rsl; |
| 2254 | u_char linksrcaddr[ETH_ALEN]; /* Other end of the wireless link */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2255 | #endif |
| 2256 | |
John Daiker | 141fa61 | 2009-03-10 06:59:54 -0700 | [diff] [blame] | 2257 | if (!sniffer) { |
| 2258 | if (translate) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2259 | /* TBD length needs fixing for translated header */ |
John Daiker | 141fa61 | 2009-03-10 06:59:54 -0700 | [diff] [blame] | 2260 | if (rx_len < (ETH_HLEN + RX_MAC_HEADER_LENGTH) || |
| 2261 | rx_len > |
| 2262 | (dev->mtu + RX_MAC_HEADER_LENGTH + ETH_HLEN + |
| 2263 | FCS_LEN)) { |
| 2264 | DEBUG(0, |
| 2265 | "ray_cs invalid packet length %d received \n", |
| 2266 | rx_len); |
| 2267 | return; |
| 2268 | } |
| 2269 | } else { /* encapsulated ethernet */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2270 | |
John Daiker | 141fa61 | 2009-03-10 06:59:54 -0700 | [diff] [blame] | 2271 | if (rx_len < (ETH_HLEN + RX_MAC_HEADER_LENGTH) || |
| 2272 | rx_len > |
| 2273 | (dev->mtu + RX_MAC_HEADER_LENGTH + ETH_HLEN + |
| 2274 | FCS_LEN)) { |
| 2275 | DEBUG(0, |
| 2276 | "ray_cs invalid packet length %d received \n", |
| 2277 | rx_len); |
| 2278 | return; |
| 2279 | } |
| 2280 | } |
| 2281 | } |
| 2282 | DEBUG(4, "ray_cs rx_data packet\n"); |
| 2283 | /* If fragmented packet, verify sizes of fragments add up */ |
| 2284 | if (readb(&prcs->var.rx_packet.next_frag_rcs_index) != 0xFF) { |
| 2285 | DEBUG(1, "ray_cs rx'ed fragment\n"); |
| 2286 | tmp = (readb(&prcs->var.rx_packet.totalpacketlength[0]) << 8) |
| 2287 | + readb(&prcs->var.rx_packet.totalpacketlength[1]); |
| 2288 | total_len = tmp; |
| 2289 | prcslink = prcs; |
| 2290 | do { |
| 2291 | tmp -= |
| 2292 | (readb(&prcslink->var.rx_packet.rx_data_length[0]) |
| 2293 | << 8) |
| 2294 | + readb(&prcslink->var.rx_packet.rx_data_length[1]); |
| 2295 | if (readb(&prcslink->var.rx_packet.next_frag_rcs_index) |
| 2296 | == 0xFF || tmp < 0) |
| 2297 | break; |
| 2298 | prcslink = rcs_base(local) |
| 2299 | + readb(&prcslink->link_field); |
| 2300 | } while (1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2301 | |
John Daiker | 141fa61 | 2009-03-10 06:59:54 -0700 | [diff] [blame] | 2302 | if (tmp < 0) { |
| 2303 | DEBUG(0, |
| 2304 | "ray_cs rx_data fragment lengths don't add up\n"); |
| 2305 | local->stats.rx_dropped++; |
| 2306 | release_frag_chain(local, prcs); |
| 2307 | return; |
| 2308 | } |
| 2309 | } else { /* Single unfragmented packet */ |
| 2310 | total_len = rx_len; |
| 2311 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2312 | |
John Daiker | 141fa61 | 2009-03-10 06:59:54 -0700 | [diff] [blame] | 2313 | skb = dev_alloc_skb(total_len + 5); |
| 2314 | if (skb == NULL) { |
| 2315 | DEBUG(0, "ray_cs rx_data could not allocate skb\n"); |
| 2316 | local->stats.rx_dropped++; |
| 2317 | if (readb(&prcs->var.rx_packet.next_frag_rcs_index) != 0xFF) |
| 2318 | release_frag_chain(local, prcs); |
| 2319 | return; |
| 2320 | } |
| 2321 | skb_reserve(skb, 2); /* Align IP on 16 byte (TBD check this) */ |
| 2322 | |
| 2323 | DEBUG(4, "ray_cs rx_data total_len = %x, rx_len = %x\n", total_len, |
| 2324 | rx_len); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2325 | |
| 2326 | /************************/ |
John Daiker | 141fa61 | 2009-03-10 06:59:54 -0700 | [diff] [blame] | 2327 | /* Reserve enough room for the whole damn packet. */ |
| 2328 | rx_ptr = skb_put(skb, total_len); |
| 2329 | /* Copy the whole packet to sk_buff */ |
| 2330 | rx_ptr += |
| 2331 | copy_from_rx_buff(local, rx_ptr, pkt_addr & RX_BUFF_END, rx_len); |
| 2332 | /* Get source address */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2333 | #ifdef WIRELESS_SPY |
John Daiker | 141fa61 | 2009-03-10 06:59:54 -0700 | [diff] [blame] | 2334 | skb_copy_from_linear_data_offset(skb, |
| 2335 | offsetof(struct mac_header, addr_2), |
| 2336 | linksrcaddr, ETH_ALEN); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2337 | #endif |
John Daiker | 141fa61 | 2009-03-10 06:59:54 -0700 | [diff] [blame] | 2338 | /* Now, deal with encapsulation/translation/sniffer */ |
| 2339 | if (!sniffer) { |
| 2340 | if (!translate) { |
| 2341 | /* Encapsulated ethernet, so just lop off 802.11 MAC header */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2342 | /* TBD reserve skb_reserve( skb, RX_MAC_HEADER_LENGTH); */ |
John Daiker | 141fa61 | 2009-03-10 06:59:54 -0700 | [diff] [blame] | 2343 | skb_pull(skb, RX_MAC_HEADER_LENGTH); |
| 2344 | } else { |
| 2345 | /* Do translation */ |
| 2346 | untranslate(local, skb, total_len); |
| 2347 | } |
| 2348 | } else { /* sniffer mode, so just pass whole packet */ |
| 2349 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2350 | |
| 2351 | /************************/ |
John Daiker | 141fa61 | 2009-03-10 06:59:54 -0700 | [diff] [blame] | 2352 | /* Now pick up the rest of the fragments if any */ |
| 2353 | tmp = 17; |
| 2354 | if (readb(&prcs->var.rx_packet.next_frag_rcs_index) != 0xFF) { |
| 2355 | prcslink = prcs; |
| 2356 | DEBUG(1, "ray_cs rx_data in fragment loop\n"); |
| 2357 | do { |
| 2358 | prcslink = rcs_base(local) |
| 2359 | + |
| 2360 | readb(&prcslink->var.rx_packet.next_frag_rcs_index); |
| 2361 | rx_len = |
| 2362 | ((readb(&prcslink->var.rx_packet.rx_data_length[0]) |
| 2363 | << 8) |
| 2364 | + |
| 2365 | readb(&prcslink->var.rx_packet.rx_data_length[1])) |
| 2366 | & RX_BUFF_END; |
| 2367 | pkt_addr = |
| 2368 | ((readb(&prcslink->var.rx_packet.rx_data_ptr[0]) << |
| 2369 | 8) |
| 2370 | + readb(&prcslink->var.rx_packet.rx_data_ptr[1])) |
| 2371 | & RX_BUFF_END; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2372 | |
John Daiker | 141fa61 | 2009-03-10 06:59:54 -0700 | [diff] [blame] | 2373 | rx_ptr += |
| 2374 | copy_from_rx_buff(local, rx_ptr, pkt_addr, rx_len); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2375 | |
John Daiker | 141fa61 | 2009-03-10 06:59:54 -0700 | [diff] [blame] | 2376 | } while (tmp-- && |
| 2377 | readb(&prcslink->var.rx_packet.next_frag_rcs_index) != |
| 2378 | 0xFF); |
| 2379 | release_frag_chain(local, prcs); |
| 2380 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2381 | |
John Daiker | 141fa61 | 2009-03-10 06:59:54 -0700 | [diff] [blame] | 2382 | skb->protocol = eth_type_trans(skb, dev); |
| 2383 | netif_rx(skb); |
| 2384 | local->stats.rx_packets++; |
| 2385 | local->stats.rx_bytes += total_len; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2386 | |
John Daiker | 141fa61 | 2009-03-10 06:59:54 -0700 | [diff] [blame] | 2387 | /* Gather signal strength per address */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2388 | #ifdef WIRELESS_SPY |
John Daiker | 141fa61 | 2009-03-10 06:59:54 -0700 | [diff] [blame] | 2389 | /* For the Access Point or the node having started the ad-hoc net |
| 2390 | * note : ad-hoc work only in some specific configurations, but we |
| 2391 | * kludge in ray_get_wireless_stats... */ |
| 2392 | if (!memcmp(linksrcaddr, local->bss_id, ETH_ALEN)) { |
| 2393 | /* Update statistics */ |
| 2394 | /*local->wstats.qual.qual = none ? */ |
| 2395 | local->wstats.qual.level = siglev; |
| 2396 | /*local->wstats.qual.noise = none ? */ |
| 2397 | local->wstats.qual.updated = 0x2; |
| 2398 | } |
| 2399 | /* Now, update the spy stuff */ |
| 2400 | { |
| 2401 | struct iw_quality wstats; |
| 2402 | wstats.level = siglev; |
| 2403 | /* wstats.noise = none ? */ |
| 2404 | /* wstats.qual = none ? */ |
| 2405 | wstats.updated = 0x2; |
| 2406 | /* Update spy records */ |
| 2407 | wireless_spy_update(dev, linksrcaddr, &wstats); |
| 2408 | } |
| 2409 | #endif /* WIRELESS_SPY */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2410 | } /* end rx_data */ |
John Daiker | 141fa61 | 2009-03-10 06:59:54 -0700 | [diff] [blame] | 2411 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2412 | /*===========================================================================*/ |
| 2413 | static void untranslate(ray_dev_t *local, struct sk_buff *skb, int len) |
| 2414 | { |
John Daiker | 141fa61 | 2009-03-10 06:59:54 -0700 | [diff] [blame] | 2415 | snaphdr_t *psnap = (snaphdr_t *) (skb->data + RX_MAC_HEADER_LENGTH); |
| 2416 | struct ieee80211_hdr *pmac = (struct ieee80211_hdr *)skb->data; |
| 2417 | __be16 type = *(__be16 *) psnap->ethertype; |
| 2418 | int delta; |
| 2419 | struct ethhdr *peth; |
| 2420 | UCHAR srcaddr[ADDRLEN]; |
| 2421 | UCHAR destaddr[ADDRLEN]; |
| 2422 | static UCHAR org_bridge[3] = { 0, 0, 0xf8 }; |
| 2423 | static UCHAR org_1042[3] = { 0, 0, 0 }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2424 | |
John Daiker | 141fa61 | 2009-03-10 06:59:54 -0700 | [diff] [blame] | 2425 | memcpy(destaddr, ieee80211_get_DA(pmac), ADDRLEN); |
| 2426 | memcpy(srcaddr, ieee80211_get_SA(pmac), ADDRLEN); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2427 | |
| 2428 | #ifdef PCMCIA_DEBUG |
John Daiker | 141fa61 | 2009-03-10 06:59:54 -0700 | [diff] [blame] | 2429 | if (pc_debug > 3) { |
| 2430 | int i; |
| 2431 | printk(KERN_DEBUG "skb->data before untranslate"); |
| 2432 | for (i = 0; i < 64; i++) |
| 2433 | printk("%02x ", skb->data[i]); |
| 2434 | printk("\n" KERN_DEBUG |
| 2435 | "type = %08x, xsap = %02x%02x%02x, org = %02x02x02x\n", |
| 2436 | ntohs(type), psnap->dsap, psnap->ssap, psnap->ctrl, |
| 2437 | psnap->org[0], psnap->org[1], psnap->org[2]); |
| 2438 | printk(KERN_DEBUG "untranslate skb->data = %p\n", skb->data); |
| 2439 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2440 | #endif |
| 2441 | |
John Daiker | 141fa61 | 2009-03-10 06:59:54 -0700 | [diff] [blame] | 2442 | if (psnap->dsap != 0xaa || psnap->ssap != 0xaa || psnap->ctrl != 3) { |
| 2443 | /* not a snap type so leave it alone */ |
| 2444 | DEBUG(3, "ray_cs untranslate NOT SNAP %02x %02x %02x\n", |
| 2445 | psnap->dsap, psnap->ssap, psnap->ctrl); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2446 | |
John Daiker | 141fa61 | 2009-03-10 06:59:54 -0700 | [diff] [blame] | 2447 | delta = RX_MAC_HEADER_LENGTH - ETH_HLEN; |
| 2448 | peth = (struct ethhdr *)(skb->data + delta); |
| 2449 | peth->h_proto = htons(len - RX_MAC_HEADER_LENGTH); |
| 2450 | } else { /* Its a SNAP */ |
| 2451 | if (memcmp(psnap->org, org_bridge, 3) == 0) { |
| 2452 | /* EtherII and nuke the LLC */ |
| 2453 | DEBUG(3, "ray_cs untranslate Bridge encap\n"); |
| 2454 | delta = RX_MAC_HEADER_LENGTH |
| 2455 | + sizeof(struct snaphdr_t) - ETH_HLEN; |
| 2456 | peth = (struct ethhdr *)(skb->data + delta); |
| 2457 | peth->h_proto = type; |
| 2458 | } else if (memcmp(psnap->org, org_1042, 3) == 0) { |
| 2459 | switch (ntohs(type)) { |
| 2460 | case ETH_P_IPX: |
| 2461 | case ETH_P_AARP: |
| 2462 | DEBUG(3, "ray_cs untranslate RFC IPX/AARP\n"); |
| 2463 | delta = RX_MAC_HEADER_LENGTH - ETH_HLEN; |
| 2464 | peth = (struct ethhdr *)(skb->data + delta); |
| 2465 | peth->h_proto = |
| 2466 | htons(len - RX_MAC_HEADER_LENGTH); |
| 2467 | break; |
| 2468 | default: |
| 2469 | DEBUG(3, "ray_cs untranslate RFC default\n"); |
| 2470 | delta = RX_MAC_HEADER_LENGTH + |
| 2471 | sizeof(struct snaphdr_t) - ETH_HLEN; |
| 2472 | peth = (struct ethhdr *)(skb->data + delta); |
| 2473 | peth->h_proto = type; |
| 2474 | break; |
| 2475 | } |
| 2476 | } else { |
| 2477 | printk("ray_cs untranslate very confused by packet\n"); |
| 2478 | delta = RX_MAC_HEADER_LENGTH - ETH_HLEN; |
| 2479 | peth = (struct ethhdr *)(skb->data + delta); |
| 2480 | peth->h_proto = type; |
| 2481 | } |
Al Viro | 7698d69 | 2007-12-29 04:55:50 -0500 | [diff] [blame] | 2482 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2483 | /* TBD reserve skb_reserve(skb, delta); */ |
John Daiker | 141fa61 | 2009-03-10 06:59:54 -0700 | [diff] [blame] | 2484 | skb_pull(skb, delta); |
| 2485 | DEBUG(3, "untranslate after skb_pull(%d), skb->data = %p\n", delta, |
| 2486 | skb->data); |
| 2487 | memcpy(peth->h_dest, destaddr, ADDRLEN); |
| 2488 | memcpy(peth->h_source, srcaddr, ADDRLEN); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2489 | #ifdef PCMCIA_DEBUG |
John Daiker | 141fa61 | 2009-03-10 06:59:54 -0700 | [diff] [blame] | 2490 | if (pc_debug > 3) { |
| 2491 | int i; |
| 2492 | printk(KERN_DEBUG "skb->data after untranslate:"); |
| 2493 | for (i = 0; i < 64; i++) |
| 2494 | printk("%02x ", skb->data[i]); |
| 2495 | printk("\n"); |
| 2496 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2497 | #endif |
| 2498 | } /* end untranslate */ |
John Daiker | 141fa61 | 2009-03-10 06:59:54 -0700 | [diff] [blame] | 2499 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2500 | /*===========================================================================*/ |
| 2501 | /* Copy data from circular receive buffer to PC memory. |
| 2502 | * dest = destination address in PC memory |
| 2503 | * pkt_addr = source address in receive buffer |
| 2504 | * len = length of packet to copy |
| 2505 | */ |
John Daiker | 141fa61 | 2009-03-10 06:59:54 -0700 | [diff] [blame] | 2506 | static int copy_from_rx_buff(ray_dev_t *local, UCHAR *dest, int pkt_addr, |
| 2507 | int length) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2508 | { |
John Daiker | 141fa61 | 2009-03-10 06:59:54 -0700 | [diff] [blame] | 2509 | int wrap_bytes = (pkt_addr + length) - (RX_BUFF_END + 1); |
| 2510 | if (wrap_bytes <= 0) { |
| 2511 | memcpy_fromio(dest, local->rmem + pkt_addr, length); |
| 2512 | } else { /* Packet wrapped in circular buffer */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2513 | |
John Daiker | 141fa61 | 2009-03-10 06:59:54 -0700 | [diff] [blame] | 2514 | memcpy_fromio(dest, local->rmem + pkt_addr, |
| 2515 | length - wrap_bytes); |
| 2516 | memcpy_fromio(dest + length - wrap_bytes, local->rmem, |
| 2517 | wrap_bytes); |
| 2518 | } |
| 2519 | return length; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2520 | } |
John Daiker | 141fa61 | 2009-03-10 06:59:54 -0700 | [diff] [blame] | 2521 | |
| 2522 | /*===========================================================================*/ |
| 2523 | static void release_frag_chain(ray_dev_t *local, struct rcs __iomem *prcs) |
| 2524 | { |
| 2525 | struct rcs __iomem *prcslink = prcs; |
| 2526 | int tmp = 17; |
| 2527 | unsigned rcsindex = readb(&prcs->var.rx_packet.next_frag_rcs_index); |
| 2528 | |
| 2529 | while (tmp--) { |
| 2530 | writeb(CCS_BUFFER_FREE, &prcslink->buffer_status); |
| 2531 | if (rcsindex >= (NUMBER_OF_CCS + NUMBER_OF_RCS)) { |
| 2532 | DEBUG(1, "ray_cs interrupt bad rcsindex = 0x%x\n", |
| 2533 | rcsindex); |
| 2534 | break; |
| 2535 | } |
| 2536 | prcslink = rcs_base(local) + rcsindex; |
| 2537 | rcsindex = readb(&prcslink->var.rx_packet.next_frag_rcs_index); |
| 2538 | } |
| 2539 | writeb(CCS_BUFFER_FREE, &prcslink->buffer_status); |
| 2540 | } |
| 2541 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2542 | /*===========================================================================*/ |
| 2543 | static void authenticate(ray_dev_t *local) |
| 2544 | { |
John Daiker | 141fa61 | 2009-03-10 06:59:54 -0700 | [diff] [blame] | 2545 | struct pcmcia_device *link = local->finder; |
| 2546 | DEBUG(0, "ray_cs Starting authentication.\n"); |
| 2547 | if (!(pcmcia_dev_present(link))) { |
| 2548 | DEBUG(2, "ray_cs authenticate - device not present\n"); |
| 2549 | return; |
| 2550 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2551 | |
John Daiker | 141fa61 | 2009-03-10 06:59:54 -0700 | [diff] [blame] | 2552 | del_timer(&local->timer); |
| 2553 | if (build_auth_frame(local, local->bss_id, OPEN_AUTH_REQUEST)) { |
| 2554 | local->timer.function = &join_net; |
| 2555 | } else { |
| 2556 | local->timer.function = &authenticate_timeout; |
| 2557 | } |
| 2558 | local->timer.expires = jiffies + HZ * 2; |
| 2559 | local->timer.data = (long)local; |
| 2560 | add_timer(&local->timer); |
| 2561 | local->authentication_state = AWAITING_RESPONSE; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2562 | } /* end authenticate */ |
John Daiker | 141fa61 | 2009-03-10 06:59:54 -0700 | [diff] [blame] | 2563 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2564 | /*===========================================================================*/ |
| 2565 | static void rx_authenticate(ray_dev_t *local, struct rcs __iomem *prcs, |
John Daiker | 141fa61 | 2009-03-10 06:59:54 -0700 | [diff] [blame] | 2566 | unsigned int pkt_addr, int rx_len) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2567 | { |
John Daiker | 141fa61 | 2009-03-10 06:59:54 -0700 | [diff] [blame] | 2568 | UCHAR buff[256]; |
| 2569 | struct rx_msg *msg = (struct rx_msg *)buff; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2570 | |
John Daiker | 141fa61 | 2009-03-10 06:59:54 -0700 | [diff] [blame] | 2571 | del_timer(&local->timer); |
| 2572 | |
| 2573 | copy_from_rx_buff(local, buff, pkt_addr, rx_len & 0xff); |
| 2574 | /* if we are trying to get authenticated */ |
| 2575 | if (local->sparm.b4.a_network_type == ADHOC) { |
| 2576 | DEBUG(1, "ray_cs rx_auth var= %02x %02x %02x %02x %02x %02x\n", |
| 2577 | msg->var[0], msg->var[1], msg->var[2], msg->var[3], |
| 2578 | msg->var[4], msg->var[5]); |
| 2579 | if (msg->var[2] == 1) { |
| 2580 | DEBUG(0, "ray_cs Sending authentication response.\n"); |
| 2581 | if (!build_auth_frame |
| 2582 | (local, msg->mac.addr_2, OPEN_AUTH_RESPONSE)) { |
| 2583 | local->authentication_state = NEED_TO_AUTH; |
| 2584 | memcpy(local->auth_id, msg->mac.addr_2, |
| 2585 | ADDRLEN); |
| 2586 | } |
| 2587 | } |
| 2588 | } else { /* Infrastructure network */ |
| 2589 | |
| 2590 | if (local->authentication_state == AWAITING_RESPONSE) { |
| 2591 | /* Verify authentication sequence #2 and success */ |
| 2592 | if (msg->var[2] == 2) { |
| 2593 | if ((msg->var[3] | msg->var[4]) == 0) { |
| 2594 | DEBUG(1, "Authentication successful\n"); |
| 2595 | local->card_status = CARD_AUTH_COMPLETE; |
| 2596 | associate(local); |
| 2597 | local->authentication_state = |
| 2598 | AUTHENTICATED; |
| 2599 | } else { |
| 2600 | DEBUG(0, "Authentication refused\n"); |
| 2601 | local->card_status = CARD_AUTH_REFUSED; |
| 2602 | join_net((u_long) local); |
| 2603 | local->authentication_state = |
| 2604 | UNAUTHENTICATED; |
| 2605 | } |
| 2606 | } |
| 2607 | } |
| 2608 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2609 | |
| 2610 | } /* end rx_authenticate */ |
John Daiker | 141fa61 | 2009-03-10 06:59:54 -0700 | [diff] [blame] | 2611 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2612 | /*===========================================================================*/ |
| 2613 | static void associate(ray_dev_t *local) |
| 2614 | { |
John Daiker | 141fa61 | 2009-03-10 06:59:54 -0700 | [diff] [blame] | 2615 | struct ccs __iomem *pccs; |
| 2616 | struct pcmcia_device *link = local->finder; |
| 2617 | struct net_device *dev = link->priv; |
| 2618 | int ccsindex; |
| 2619 | if (!(pcmcia_dev_present(link))) { |
| 2620 | DEBUG(2, "ray_cs associate - device not present\n"); |
| 2621 | return; |
| 2622 | } |
| 2623 | /* If no tx buffers available, return */ |
| 2624 | if ((ccsindex = get_free_ccs(local)) < 0) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2625 | /* TBD should never be here but... what if we are? */ |
John Daiker | 141fa61 | 2009-03-10 06:59:54 -0700 | [diff] [blame] | 2626 | DEBUG(1, "ray_cs associate - No free ccs\n"); |
| 2627 | return; |
| 2628 | } |
| 2629 | DEBUG(1, "ray_cs Starting association with access point\n"); |
| 2630 | pccs = ccs_base(local) + ccsindex; |
| 2631 | /* fill in the CCS */ |
| 2632 | writeb(CCS_START_ASSOCIATION, &pccs->cmd); |
| 2633 | /* Interrupt the firmware to process the command */ |
| 2634 | if (interrupt_ecf(local, ccsindex)) { |
| 2635 | DEBUG(1, "ray_cs associate failed - ECF not ready for intr\n"); |
| 2636 | writeb(CCS_BUFFER_FREE, &(pccs++)->buffer_status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2637 | |
John Daiker | 141fa61 | 2009-03-10 06:59:54 -0700 | [diff] [blame] | 2638 | del_timer(&local->timer); |
| 2639 | local->timer.expires = jiffies + HZ * 2; |
| 2640 | local->timer.data = (long)local; |
| 2641 | local->timer.function = &join_net; |
| 2642 | add_timer(&local->timer); |
| 2643 | local->card_status = CARD_ASSOC_FAILED; |
| 2644 | return; |
| 2645 | } |
| 2646 | if (!sniffer) |
| 2647 | netif_start_queue(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2648 | |
| 2649 | } /* end associate */ |
John Daiker | 141fa61 | 2009-03-10 06:59:54 -0700 | [diff] [blame] | 2650 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2651 | /*===========================================================================*/ |
John Daiker | 141fa61 | 2009-03-10 06:59:54 -0700 | [diff] [blame] | 2652 | static void rx_deauthenticate(ray_dev_t *local, struct rcs __iomem *prcs, |
| 2653 | unsigned int pkt_addr, int rx_len) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2654 | { |
| 2655 | /* UCHAR buff[256]; |
| 2656 | struct rx_msg *msg = (struct rx_msg *)buff; |
| 2657 | */ |
John Daiker | 141fa61 | 2009-03-10 06:59:54 -0700 | [diff] [blame] | 2658 | DEBUG(0, "Deauthentication frame received\n"); |
| 2659 | local->authentication_state = UNAUTHENTICATED; |
| 2660 | /* Need to reauthenticate or rejoin depending on reason code */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2661 | /* copy_from_rx_buff(local, buff, pkt_addr, rx_len & 0xff); |
| 2662 | */ |
| 2663 | } |
John Daiker | 141fa61 | 2009-03-10 06:59:54 -0700 | [diff] [blame] | 2664 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2665 | /*===========================================================================*/ |
| 2666 | static void clear_interrupt(ray_dev_t *local) |
| 2667 | { |
John Daiker | 141fa61 | 2009-03-10 06:59:54 -0700 | [diff] [blame] | 2668 | writeb(0, local->amem + CIS_OFFSET + HCS_INTR_OFFSET); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2669 | } |
John Daiker | 141fa61 | 2009-03-10 06:59:54 -0700 | [diff] [blame] | 2670 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2671 | /*===========================================================================*/ |
| 2672 | #ifdef CONFIG_PROC_FS |
| 2673 | #define MAXDATA (PAGE_SIZE - 80) |
| 2674 | |
| 2675 | static char *card_status[] = { |
John Daiker | 141fa61 | 2009-03-10 06:59:54 -0700 | [diff] [blame] | 2676 | "Card inserted - uninitialized", /* 0 */ |
| 2677 | "Card not downloaded", /* 1 */ |
| 2678 | "Waiting for download parameters", /* 2 */ |
| 2679 | "Card doing acquisition", /* 3 */ |
| 2680 | "Acquisition complete", /* 4 */ |
| 2681 | "Authentication complete", /* 5 */ |
| 2682 | "Association complete", /* 6 */ |
| 2683 | "???", "???", "???", "???", /* 7 8 9 10 undefined */ |
| 2684 | "Card init error", /* 11 */ |
| 2685 | "Download parameters error", /* 12 */ |
| 2686 | "???", /* 13 */ |
| 2687 | "Acquisition failed", /* 14 */ |
| 2688 | "Authentication refused", /* 15 */ |
| 2689 | "Association failed" /* 16 */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2690 | }; |
| 2691 | |
John Daiker | 141fa61 | 2009-03-10 06:59:54 -0700 | [diff] [blame] | 2692 | static char *nettype[] = { "Adhoc", "Infra " }; |
| 2693 | static char *framing[] = { "Encapsulation", "Translation" } |
| 2694 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2695 | ; |
| 2696 | /*===========================================================================*/ |
Alexey Dobriyan | 6b914c5 | 2008-04-10 14:34:35 -0700 | [diff] [blame] | 2697 | static int ray_cs_proc_show(struct seq_file *m, void *v) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2698 | { |
| 2699 | /* Print current values which are not available via other means |
John Daiker | 141fa61 | 2009-03-10 06:59:54 -0700 | [diff] [blame] | 2700 | * eg ifconfig |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2701 | */ |
John Daiker | 141fa61 | 2009-03-10 06:59:54 -0700 | [diff] [blame] | 2702 | int i; |
| 2703 | struct pcmcia_device *link; |
| 2704 | struct net_device *dev; |
| 2705 | ray_dev_t *local; |
| 2706 | UCHAR *p; |
| 2707 | struct freq_hop_element *pfh; |
| 2708 | UCHAR c[33]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2709 | |
John Daiker | 141fa61 | 2009-03-10 06:59:54 -0700 | [diff] [blame] | 2710 | link = this_device; |
| 2711 | if (!link) |
| 2712 | return 0; |
| 2713 | dev = (struct net_device *)link->priv; |
| 2714 | if (!dev) |
| 2715 | return 0; |
| 2716 | local = netdev_priv(dev); |
| 2717 | if (!local) |
| 2718 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2719 | |
John Daiker | 141fa61 | 2009-03-10 06:59:54 -0700 | [diff] [blame] | 2720 | seq_puts(m, "Raylink Wireless LAN driver status\n"); |
| 2721 | seq_printf(m, "%s\n", rcsid); |
| 2722 | /* build 4 does not report version, and field is 0x55 after memtest */ |
| 2723 | seq_puts(m, "Firmware version = "); |
| 2724 | if (local->fw_ver == 0x55) |
| 2725 | seq_puts(m, "4 - Use dump_cis for more details\n"); |
| 2726 | else |
| 2727 | seq_printf(m, "%2d.%02d.%02d\n", |
| 2728 | local->fw_ver, local->fw_bld, local->fw_var); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2729 | |
John Daiker | 141fa61 | 2009-03-10 06:59:54 -0700 | [diff] [blame] | 2730 | for (i = 0; i < 32; i++) |
| 2731 | c[i] = local->sparm.b5.a_current_ess_id[i]; |
| 2732 | c[32] = 0; |
| 2733 | seq_printf(m, "%s network ESSID = \"%s\"\n", |
| 2734 | nettype[local->sparm.b5.a_network_type], c); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2735 | |
John Daiker | 141fa61 | 2009-03-10 06:59:54 -0700 | [diff] [blame] | 2736 | p = local->bss_id; |
| 2737 | seq_printf(m, "BSSID = %pM\n", p); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2738 | |
John Daiker | 141fa61 | 2009-03-10 06:59:54 -0700 | [diff] [blame] | 2739 | seq_printf(m, "Country code = %d\n", |
| 2740 | local->sparm.b5.a_curr_country_code); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2741 | |
John Daiker | 141fa61 | 2009-03-10 06:59:54 -0700 | [diff] [blame] | 2742 | i = local->card_status; |
| 2743 | if (i < 0) |
| 2744 | i = 10; |
| 2745 | if (i > 16) |
| 2746 | i = 10; |
| 2747 | seq_printf(m, "Card status = %s\n", card_status[i]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2748 | |
John Daiker | 141fa61 | 2009-03-10 06:59:54 -0700 | [diff] [blame] | 2749 | seq_printf(m, "Framing mode = %s\n", framing[translate]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2750 | |
John Daiker | 141fa61 | 2009-03-10 06:59:54 -0700 | [diff] [blame] | 2751 | seq_printf(m, "Last pkt signal lvl = %d\n", local->last_rsl); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2752 | |
John Daiker | 141fa61 | 2009-03-10 06:59:54 -0700 | [diff] [blame] | 2753 | if (local->beacon_rxed) { |
| 2754 | /* Pull some fields out of last beacon received */ |
| 2755 | seq_printf(m, "Beacon Interval = %d Kus\n", |
| 2756 | local->last_bcn.beacon_intvl[0] |
| 2757 | + 256 * local->last_bcn.beacon_intvl[1]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2758 | |
John Daiker | 141fa61 | 2009-03-10 06:59:54 -0700 | [diff] [blame] | 2759 | p = local->last_bcn.elements; |
| 2760 | if (p[0] == C_ESSID_ELEMENT_ID) |
| 2761 | p += p[1] + 2; |
| 2762 | else { |
| 2763 | seq_printf(m, |
| 2764 | "Parse beacon failed at essid element id = %d\n", |
| 2765 | p[0]); |
| 2766 | return 0; |
| 2767 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2768 | |
John Daiker | 141fa61 | 2009-03-10 06:59:54 -0700 | [diff] [blame] | 2769 | if (p[0] == C_SUPPORTED_RATES_ELEMENT_ID) { |
| 2770 | seq_puts(m, "Supported rate codes = "); |
| 2771 | for (i = 2; i < p[1] + 2; i++) |
| 2772 | seq_printf(m, "0x%02x ", p[i]); |
| 2773 | seq_putc(m, '\n'); |
| 2774 | p += p[1] + 2; |
| 2775 | } else { |
| 2776 | seq_puts(m, "Parse beacon failed at rates element\n"); |
| 2777 | return 0; |
| 2778 | } |
| 2779 | |
| 2780 | if (p[0] == C_FH_PARAM_SET_ELEMENT_ID) { |
| 2781 | pfh = (struct freq_hop_element *)p; |
| 2782 | seq_printf(m, "Hop dwell = %d Kus\n", |
| 2783 | pfh->dwell_time[0] + |
| 2784 | 256 * pfh->dwell_time[1]); |
| 2785 | seq_printf(m, "Hop set = %d \n", |
| 2786 | pfh->hop_set); |
| 2787 | seq_printf(m, "Hop pattern = %d \n", |
| 2788 | pfh->hop_pattern); |
| 2789 | seq_printf(m, "Hop index = %d \n", |
| 2790 | pfh->hop_index); |
| 2791 | p += p[1] + 2; |
| 2792 | } else { |
| 2793 | seq_puts(m, |
| 2794 | "Parse beacon failed at FH param element\n"); |
| 2795 | return 0; |
| 2796 | } |
| 2797 | } else { |
| 2798 | seq_puts(m, "No beacons received\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2799 | } |
John Daiker | 141fa61 | 2009-03-10 06:59:54 -0700 | [diff] [blame] | 2800 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2801 | } |
| 2802 | |
Alexey Dobriyan | 6b914c5 | 2008-04-10 14:34:35 -0700 | [diff] [blame] | 2803 | static int ray_cs_proc_open(struct inode *inode, struct file *file) |
| 2804 | { |
| 2805 | return single_open(file, ray_cs_proc_show, NULL); |
| 2806 | } |
| 2807 | |
| 2808 | static const struct file_operations ray_cs_proc_fops = { |
John Daiker | 141fa61 | 2009-03-10 06:59:54 -0700 | [diff] [blame] | 2809 | .owner = THIS_MODULE, |
| 2810 | .open = ray_cs_proc_open, |
| 2811 | .read = seq_read, |
| 2812 | .llseek = seq_lseek, |
| 2813 | .release = single_release, |
Alexey Dobriyan | 6b914c5 | 2008-04-10 14:34:35 -0700 | [diff] [blame] | 2814 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2815 | #endif |
| 2816 | /*===========================================================================*/ |
| 2817 | static int build_auth_frame(ray_dev_t *local, UCHAR *dest, int auth_type) |
| 2818 | { |
John Daiker | 141fa61 | 2009-03-10 06:59:54 -0700 | [diff] [blame] | 2819 | int addr; |
| 2820 | struct ccs __iomem *pccs; |
| 2821 | struct tx_msg __iomem *ptx; |
| 2822 | int ccsindex; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2823 | |
John Daiker | 141fa61 | 2009-03-10 06:59:54 -0700 | [diff] [blame] | 2824 | /* If no tx buffers available, return */ |
| 2825 | if ((ccsindex = get_free_tx_ccs(local)) < 0) { |
| 2826 | DEBUG(1, "ray_cs send authenticate - No free tx ccs\n"); |
| 2827 | return -1; |
| 2828 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2829 | |
John Daiker | 141fa61 | 2009-03-10 06:59:54 -0700 | [diff] [blame] | 2830 | pccs = ccs_base(local) + ccsindex; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2831 | |
John Daiker | 141fa61 | 2009-03-10 06:59:54 -0700 | [diff] [blame] | 2832 | /* Address in card space */ |
| 2833 | addr = TX_BUF_BASE + (ccsindex << 11); |
| 2834 | /* fill in the CCS */ |
| 2835 | writeb(CCS_TX_REQUEST, &pccs->cmd); |
| 2836 | writeb(addr >> 8, pccs->var.tx_request.tx_data_ptr); |
| 2837 | writeb(0x20, pccs->var.tx_request.tx_data_ptr + 1); |
| 2838 | writeb(TX_AUTHENTICATE_LENGTH_MSB, pccs->var.tx_request.tx_data_length); |
| 2839 | writeb(TX_AUTHENTICATE_LENGTH_LSB, |
| 2840 | pccs->var.tx_request.tx_data_length + 1); |
| 2841 | writeb(0, &pccs->var.tx_request.pow_sav_mode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2842 | |
John Daiker | 141fa61 | 2009-03-10 06:59:54 -0700 | [diff] [blame] | 2843 | ptx = local->sram + addr; |
| 2844 | /* fill in the mac header */ |
| 2845 | writeb(PROTOCOL_VER | AUTHENTIC_TYPE, &ptx->mac.frame_ctl_1); |
| 2846 | writeb(0, &ptx->mac.frame_ctl_2); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2847 | |
John Daiker | 141fa61 | 2009-03-10 06:59:54 -0700 | [diff] [blame] | 2848 | memcpy_toio(ptx->mac.addr_1, dest, ADDRLEN); |
| 2849 | memcpy_toio(ptx->mac.addr_2, local->sparm.b4.a_mac_addr, ADDRLEN); |
| 2850 | memcpy_toio(ptx->mac.addr_3, local->bss_id, ADDRLEN); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2851 | |
John Daiker | 141fa61 | 2009-03-10 06:59:54 -0700 | [diff] [blame] | 2852 | /* Fill in msg body with protocol 00 00, sequence 01 00 ,status 00 00 */ |
| 2853 | memset_io(ptx->var, 0, 6); |
| 2854 | writeb(auth_type & 0xff, ptx->var + 2); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2855 | |
John Daiker | 141fa61 | 2009-03-10 06:59:54 -0700 | [diff] [blame] | 2856 | /* Interrupt the firmware to process the command */ |
| 2857 | if (interrupt_ecf(local, ccsindex)) { |
| 2858 | DEBUG(1, |
| 2859 | "ray_cs send authentication request failed - ECF not ready for intr\n"); |
| 2860 | writeb(CCS_BUFFER_FREE, &(pccs++)->buffer_status); |
| 2861 | return -1; |
| 2862 | } |
| 2863 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2864 | } /* End build_auth_frame */ |
| 2865 | |
| 2866 | /*===========================================================================*/ |
| 2867 | #ifdef CONFIG_PROC_FS |
| 2868 | static void raycs_write(const char *name, write_proc_t *w, void *data) |
| 2869 | { |
John Daiker | 141fa61 | 2009-03-10 06:59:54 -0700 | [diff] [blame] | 2870 | struct proc_dir_entry *entry = |
| 2871 | create_proc_entry(name, S_IFREG | S_IWUSR, NULL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2872 | if (entry) { |
| 2873 | entry->write_proc = w; |
| 2874 | entry->data = data; |
| 2875 | } |
| 2876 | } |
| 2877 | |
John Daiker | 141fa61 | 2009-03-10 06:59:54 -0700 | [diff] [blame] | 2878 | static int write_essid(struct file *file, const char __user *buffer, |
| 2879 | unsigned long count, void *data) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2880 | { |
| 2881 | static char proc_essid[33]; |
| 2882 | int len = count; |
| 2883 | |
| 2884 | if (len > 32) |
| 2885 | len = 32; |
| 2886 | memset(proc_essid, 0, 33); |
| 2887 | if (copy_from_user(proc_essid, buffer, len)) |
| 2888 | return -EFAULT; |
| 2889 | essid = proc_essid; |
| 2890 | return count; |
| 2891 | } |
| 2892 | |
John Daiker | 141fa61 | 2009-03-10 06:59:54 -0700 | [diff] [blame] | 2893 | static int write_int(struct file *file, const char __user *buffer, |
| 2894 | unsigned long count, void *data) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2895 | { |
| 2896 | static char proc_number[10]; |
| 2897 | char *p; |
| 2898 | int nr, len; |
| 2899 | |
| 2900 | if (!count) |
| 2901 | return 0; |
| 2902 | |
| 2903 | if (count > 9) |
| 2904 | return -EINVAL; |
| 2905 | if (copy_from_user(proc_number, buffer, count)) |
| 2906 | return -EFAULT; |
| 2907 | p = proc_number; |
| 2908 | nr = 0; |
| 2909 | len = count; |
| 2910 | do { |
| 2911 | unsigned int c = *p - '0'; |
| 2912 | if (c > 9) |
| 2913 | return -EINVAL; |
John Daiker | 141fa61 | 2009-03-10 06:59:54 -0700 | [diff] [blame] | 2914 | nr = nr * 10 + c; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2915 | p++; |
| 2916 | } while (--len); |
| 2917 | *(int *)data = nr; |
| 2918 | return count; |
| 2919 | } |
| 2920 | #endif |
| 2921 | |
Dominik Brodowski | f57ea2a | 2005-06-27 16:28:24 -0700 | [diff] [blame] | 2922 | static struct pcmcia_device_id ray_ids[] = { |
| 2923 | PCMCIA_DEVICE_MANF_CARD(0x01a6, 0x0000), |
| 2924 | PCMCIA_DEVICE_NULL, |
| 2925 | }; |
John Daiker | 141fa61 | 2009-03-10 06:59:54 -0700 | [diff] [blame] | 2926 | |
Dominik Brodowski | f57ea2a | 2005-06-27 16:28:24 -0700 | [diff] [blame] | 2927 | MODULE_DEVICE_TABLE(pcmcia, ray_ids); |
| 2928 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2929 | static struct pcmcia_driver ray_driver = { |
John Daiker | 141fa61 | 2009-03-10 06:59:54 -0700 | [diff] [blame] | 2930 | .owner = THIS_MODULE, |
| 2931 | .drv = { |
| 2932 | .name = "ray_cs", |
| 2933 | }, |
| 2934 | .probe = ray_probe, |
| 2935 | .remove = ray_detach, |
| 2936 | .id_table = ray_ids, |
| 2937 | .suspend = ray_suspend, |
| 2938 | .resume = ray_resume, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2939 | }; |
| 2940 | |
| 2941 | static int __init init_ray_cs(void) |
| 2942 | { |
John Daiker | 141fa61 | 2009-03-10 06:59:54 -0700 | [diff] [blame] | 2943 | int rc; |
| 2944 | |
| 2945 | DEBUG(1, "%s\n", rcsid); |
| 2946 | rc = pcmcia_register_driver(&ray_driver); |
| 2947 | DEBUG(1, "raylink init_module register_pcmcia_driver returns 0x%x\n", |
| 2948 | rc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2949 | |
| 2950 | #ifdef CONFIG_PROC_FS |
John Daiker | 141fa61 | 2009-03-10 06:59:54 -0700 | [diff] [blame] | 2951 | proc_mkdir("driver/ray_cs", NULL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2952 | |
John Daiker | 141fa61 | 2009-03-10 06:59:54 -0700 | [diff] [blame] | 2953 | proc_create("driver/ray_cs/ray_cs", 0, NULL, &ray_cs_proc_fops); |
| 2954 | raycs_write("driver/ray_cs/essid", write_essid, NULL); |
| 2955 | raycs_write("driver/ray_cs/net_type", write_int, &net_type); |
| 2956 | raycs_write("driver/ray_cs/translate", write_int, &translate); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2957 | #endif |
John Daiker | 141fa61 | 2009-03-10 06:59:54 -0700 | [diff] [blame] | 2958 | if (translate != 0) |
| 2959 | translate = 1; |
| 2960 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2961 | } /* init_ray_cs */ |
| 2962 | |
| 2963 | /*===========================================================================*/ |
| 2964 | |
| 2965 | static void __exit exit_ray_cs(void) |
| 2966 | { |
John Daiker | 141fa61 | 2009-03-10 06:59:54 -0700 | [diff] [blame] | 2967 | DEBUG(0, "ray_cs: cleanup_module\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2968 | |
| 2969 | #ifdef CONFIG_PROC_FS |
John Daiker | 141fa61 | 2009-03-10 06:59:54 -0700 | [diff] [blame] | 2970 | remove_proc_entry("driver/ray_cs/ray_cs", NULL); |
| 2971 | remove_proc_entry("driver/ray_cs/essid", NULL); |
| 2972 | remove_proc_entry("driver/ray_cs/net_type", NULL); |
| 2973 | remove_proc_entry("driver/ray_cs/translate", NULL); |
| 2974 | remove_proc_entry("driver/ray_cs", NULL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2975 | #endif |
| 2976 | |
John Daiker | 141fa61 | 2009-03-10 06:59:54 -0700 | [diff] [blame] | 2977 | pcmcia_unregister_driver(&ray_driver); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2978 | } /* exit_ray_cs */ |
| 2979 | |
| 2980 | module_init(init_ray_cs); |
| 2981 | module_exit(exit_ray_cs); |
| 2982 | |
| 2983 | /*===========================================================================*/ |