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