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