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