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