Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* hermes.h |
| 2 | * |
| 3 | * Driver core for the "Hermes" wireless MAC controller, as used in |
| 4 | * the Lucent Orinoco and Cabletron RoamAbout cards. It should also |
| 5 | * work on the hfa3841 and hfa3842 MAC controller chips used in the |
| 6 | * Prism I & II chipsets. |
| 7 | * |
| 8 | * This is not a complete driver, just low-level access routines for |
| 9 | * the MAC controller itself. |
| 10 | * |
| 11 | * Based on the prism2 driver from Absolute Value Systems' linux-wlan |
| 12 | * project, the Linux wvlan_cs driver, Lucent's HCF-Light |
| 13 | * (wvlan_hcf.c) library, and the NetBSD wireless driver. |
| 14 | * |
| 15 | * Copyright (C) 2000, David Gibson, Linuxcare Australia. |
| 16 | * (C) Copyright David Gibson, IBM Corp. 2001-2003. |
| 17 | * |
| 18 | * Portions taken from hfa384x.h, Copyright (C) 1999 AbsoluteValue Systems, Inc. All Rights Reserved. |
| 19 | * |
| 20 | * This file distributed under the GPL, version 2. |
| 21 | */ |
| 22 | |
| 23 | #ifndef _HERMES_H |
| 24 | #define _HERMES_H |
| 25 | |
| 26 | /* Notes on locking: |
| 27 | * |
| 28 | * As a module of low level hardware access routines, there is no |
| 29 | * locking. Users of this module should ensure that they serialize |
| 30 | * access to the hermes_t structure, and to the hardware |
| 31 | */ |
| 32 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 33 | #include <linux/if_ether.h> |
Pavel Roskin | ef846bf | 2005-09-23 04:18:07 -0400 | [diff] [blame] | 34 | #include <asm/io.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 35 | |
| 36 | /* |
| 37 | * Limits and constants |
| 38 | */ |
| 39 | #define HERMES_ALLOC_LEN_MIN (4) |
| 40 | #define HERMES_ALLOC_LEN_MAX (2400) |
| 41 | #define HERMES_LTV_LEN_MAX (34) |
| 42 | #define HERMES_BAP_DATALEN_MAX (4096) |
| 43 | #define HERMES_BAP_OFFSET_MAX (4096) |
| 44 | #define HERMES_PORTID_MAX (7) |
| 45 | #define HERMES_NUMPORTS_MAX (HERMES_PORTID_MAX+1) |
| 46 | #define HERMES_PDR_LEN_MAX (260) /* in bytes, from EK */ |
| 47 | #define HERMES_PDA_RECS_MAX (200) /* a guess */ |
| 48 | #define HERMES_PDA_LEN_MAX (1024) /* in bytes, from EK */ |
| 49 | #define HERMES_SCANRESULT_MAX (35) |
| 50 | #define HERMES_CHINFORESULT_MAX (8) |
| 51 | #define HERMES_MAX_MULTICAST (16) |
| 52 | #define HERMES_MAGIC (0x7d1f) |
| 53 | |
| 54 | /* |
| 55 | * Hermes register offsets |
| 56 | */ |
| 57 | #define HERMES_CMD (0x00) |
| 58 | #define HERMES_PARAM0 (0x02) |
| 59 | #define HERMES_PARAM1 (0x04) |
| 60 | #define HERMES_PARAM2 (0x06) |
| 61 | #define HERMES_STATUS (0x08) |
| 62 | #define HERMES_RESP0 (0x0A) |
| 63 | #define HERMES_RESP1 (0x0C) |
| 64 | #define HERMES_RESP2 (0x0E) |
| 65 | #define HERMES_INFOFID (0x10) |
| 66 | #define HERMES_RXFID (0x20) |
| 67 | #define HERMES_ALLOCFID (0x22) |
| 68 | #define HERMES_TXCOMPLFID (0x24) |
| 69 | #define HERMES_SELECT0 (0x18) |
| 70 | #define HERMES_OFFSET0 (0x1C) |
| 71 | #define HERMES_DATA0 (0x36) |
| 72 | #define HERMES_SELECT1 (0x1A) |
| 73 | #define HERMES_OFFSET1 (0x1E) |
| 74 | #define HERMES_DATA1 (0x38) |
| 75 | #define HERMES_EVSTAT (0x30) |
| 76 | #define HERMES_INTEN (0x32) |
| 77 | #define HERMES_EVACK (0x34) |
| 78 | #define HERMES_CONTROL (0x14) |
| 79 | #define HERMES_SWSUPPORT0 (0x28) |
| 80 | #define HERMES_SWSUPPORT1 (0x2A) |
| 81 | #define HERMES_SWSUPPORT2 (0x2C) |
| 82 | #define HERMES_AUXPAGE (0x3A) |
| 83 | #define HERMES_AUXOFFSET (0x3C) |
| 84 | #define HERMES_AUXDATA (0x3E) |
| 85 | |
| 86 | /* |
| 87 | * CMD register bitmasks |
| 88 | */ |
| 89 | #define HERMES_CMD_BUSY (0x8000) |
| 90 | #define HERMES_CMD_AINFO (0x7f00) |
| 91 | #define HERMES_CMD_MACPORT (0x0700) |
| 92 | #define HERMES_CMD_RECL (0x0100) |
| 93 | #define HERMES_CMD_WRITE (0x0100) |
| 94 | #define HERMES_CMD_PROGMODE (0x0300) |
| 95 | #define HERMES_CMD_CMDCODE (0x003f) |
| 96 | |
| 97 | /* |
| 98 | * STATUS register bitmasks |
| 99 | */ |
| 100 | #define HERMES_STATUS_RESULT (0x7f00) |
| 101 | #define HERMES_STATUS_CMDCODE (0x003f) |
| 102 | |
| 103 | /* |
| 104 | * OFFSET register bitmasks |
| 105 | */ |
| 106 | #define HERMES_OFFSET_BUSY (0x8000) |
| 107 | #define HERMES_OFFSET_ERR (0x4000) |
| 108 | #define HERMES_OFFSET_DATAOFF (0x0ffe) |
| 109 | |
| 110 | /* |
| 111 | * Event register bitmasks (INTEN, EVSTAT, EVACK) |
| 112 | */ |
| 113 | #define HERMES_EV_TICK (0x8000) |
| 114 | #define HERMES_EV_WTERR (0x4000) |
| 115 | #define HERMES_EV_INFDROP (0x2000) |
| 116 | #define HERMES_EV_INFO (0x0080) |
| 117 | #define HERMES_EV_DTIM (0x0020) |
| 118 | #define HERMES_EV_CMD (0x0010) |
| 119 | #define HERMES_EV_ALLOC (0x0008) |
| 120 | #define HERMES_EV_TXEXC (0x0004) |
| 121 | #define HERMES_EV_TX (0x0002) |
| 122 | #define HERMES_EV_RX (0x0001) |
| 123 | |
| 124 | /* |
| 125 | * Command codes |
| 126 | */ |
| 127 | /*--- Controller Commands ----------------------------*/ |
| 128 | #define HERMES_CMD_INIT (0x0000) |
| 129 | #define HERMES_CMD_ENABLE (0x0001) |
| 130 | #define HERMES_CMD_DISABLE (0x0002) |
| 131 | #define HERMES_CMD_DIAG (0x0003) |
| 132 | |
| 133 | /*--- Buffer Mgmt Commands ---------------------------*/ |
| 134 | #define HERMES_CMD_ALLOC (0x000A) |
| 135 | #define HERMES_CMD_TX (0x000B) |
| 136 | |
| 137 | /*--- Regulate Commands ------------------------------*/ |
| 138 | #define HERMES_CMD_NOTIFY (0x0010) |
| 139 | #define HERMES_CMD_INQUIRE (0x0011) |
| 140 | |
| 141 | /*--- Configure Commands -----------------------------*/ |
| 142 | #define HERMES_CMD_ACCESS (0x0021) |
| 143 | #define HERMES_CMD_DOWNLD (0x0022) |
| 144 | |
| 145 | /*--- Serial I/O Commands ----------------------------*/ |
| 146 | #define HERMES_CMD_READMIF (0x0030) |
| 147 | #define HERMES_CMD_WRITEMIF (0x0031) |
| 148 | |
| 149 | /*--- Debugging Commands -----------------------------*/ |
| 150 | #define HERMES_CMD_TEST (0x0038) |
| 151 | |
| 152 | |
| 153 | /* Test command arguments */ |
| 154 | #define HERMES_TEST_SET_CHANNEL 0x0800 |
| 155 | #define HERMES_TEST_MONITOR 0x0b00 |
| 156 | #define HERMES_TEST_STOP 0x0f00 |
| 157 | |
| 158 | /* Authentication algorithms */ |
| 159 | #define HERMES_AUTH_OPEN 1 |
| 160 | #define HERMES_AUTH_SHARED_KEY 2 |
| 161 | |
| 162 | /* WEP settings */ |
| 163 | #define HERMES_WEP_PRIVACY_INVOKED 0x0001 |
| 164 | #define HERMES_WEP_EXCL_UNENCRYPTED 0x0002 |
| 165 | #define HERMES_WEP_HOST_ENCRYPT 0x0010 |
| 166 | #define HERMES_WEP_HOST_DECRYPT 0x0080 |
| 167 | |
| 168 | /* Symbol hostscan options */ |
| 169 | #define HERMES_HOSTSCAN_SYMBOL_5SEC 0x0001 |
| 170 | #define HERMES_HOSTSCAN_SYMBOL_ONCE 0x0002 |
| 171 | #define HERMES_HOSTSCAN_SYMBOL_PASSIVE 0x0040 |
| 172 | #define HERMES_HOSTSCAN_SYMBOL_BCAST 0x0080 |
| 173 | |
| 174 | /* |
| 175 | * Frame structures and constants |
| 176 | */ |
| 177 | |
| 178 | #define HERMES_DESCRIPTOR_OFFSET 0 |
| 179 | #define HERMES_802_11_OFFSET (14) |
| 180 | #define HERMES_802_3_OFFSET (14+32) |
| 181 | #define HERMES_802_2_OFFSET (14+32+14) |
| 182 | |
| 183 | #define HERMES_RXSTAT_ERR (0x0003) |
| 184 | #define HERMES_RXSTAT_BADCRC (0x0001) |
| 185 | #define HERMES_RXSTAT_UNDECRYPTABLE (0x0002) |
| 186 | #define HERMES_RXSTAT_MACPORT (0x0700) |
| 187 | #define HERMES_RXSTAT_PCF (0x1000) /* Frame was received in CF period */ |
| 188 | #define HERMES_RXSTAT_MSGTYPE (0xE000) |
| 189 | #define HERMES_RXSTAT_1042 (0x2000) /* RFC-1042 frame */ |
| 190 | #define HERMES_RXSTAT_TUNNEL (0x4000) /* bridge-tunnel encoded frame */ |
| 191 | #define HERMES_RXSTAT_WMP (0x6000) /* Wavelan-II Management Protocol frame */ |
| 192 | |
| 193 | struct hermes_tx_descriptor { |
Pavel Roskin | d133ae4 | 2005-09-23 04:18:06 -0400 | [diff] [blame] | 194 | __le16 status; |
| 195 | __le16 reserved1; |
| 196 | __le16 reserved2; |
| 197 | __le32 sw_support; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 198 | u8 retry_count; |
| 199 | u8 tx_rate; |
Pavel Roskin | d133ae4 | 2005-09-23 04:18:06 -0400 | [diff] [blame] | 200 | __le16 tx_control; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 201 | } __attribute__ ((packed)); |
| 202 | |
| 203 | #define HERMES_TXSTAT_RETRYERR (0x0001) |
| 204 | #define HERMES_TXSTAT_AGEDERR (0x0002) |
| 205 | #define HERMES_TXSTAT_DISCON (0x0004) |
| 206 | #define HERMES_TXSTAT_FORMERR (0x0008) |
| 207 | |
| 208 | #define HERMES_TXCTRL_TX_OK (0x0002) /* ?? interrupt on Tx complete */ |
| 209 | #define HERMES_TXCTRL_TX_EX (0x0004) /* ?? interrupt on Tx exception */ |
| 210 | #define HERMES_TXCTRL_802_11 (0x0008) /* We supply 802.11 header */ |
| 211 | #define HERMES_TXCTRL_ALT_RTRY (0x0020) |
| 212 | |
| 213 | /* Inquiry constants and data types */ |
| 214 | |
| 215 | #define HERMES_INQ_TALLIES (0xF100) |
| 216 | #define HERMES_INQ_SCAN (0xF101) |
| 217 | #define HERMES_INQ_CHANNELINFO (0xF102) |
| 218 | #define HERMES_INQ_HOSTSCAN (0xF103) |
| 219 | #define HERMES_INQ_HOSTSCAN_SYMBOL (0xF104) |
| 220 | #define HERMES_INQ_LINKSTATUS (0xF200) |
| 221 | #define HERMES_INQ_SEC_STAT_AGERE (0xF202) |
| 222 | |
| 223 | struct hermes_tallies_frame { |
Pavel Roskin | d133ae4 | 2005-09-23 04:18:06 -0400 | [diff] [blame] | 224 | __le16 TxUnicastFrames; |
| 225 | __le16 TxMulticastFrames; |
| 226 | __le16 TxFragments; |
| 227 | __le16 TxUnicastOctets; |
| 228 | __le16 TxMulticastOctets; |
| 229 | __le16 TxDeferredTransmissions; |
| 230 | __le16 TxSingleRetryFrames; |
| 231 | __le16 TxMultipleRetryFrames; |
| 232 | __le16 TxRetryLimitExceeded; |
| 233 | __le16 TxDiscards; |
| 234 | __le16 RxUnicastFrames; |
| 235 | __le16 RxMulticastFrames; |
| 236 | __le16 RxFragments; |
| 237 | __le16 RxUnicastOctets; |
| 238 | __le16 RxMulticastOctets; |
| 239 | __le16 RxFCSErrors; |
| 240 | __le16 RxDiscards_NoBuffer; |
| 241 | __le16 TxDiscardsWrongSA; |
| 242 | __le16 RxWEPUndecryptable; |
| 243 | __le16 RxMsgInMsgFragments; |
| 244 | __le16 RxMsgInBadMsgFragments; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 245 | /* Those last are probably not available in very old firmwares */ |
Pavel Roskin | d133ae4 | 2005-09-23 04:18:06 -0400 | [diff] [blame] | 246 | __le16 RxDiscards_WEPICVError; |
| 247 | __le16 RxDiscards_WEPExcluded; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 248 | } __attribute__ ((packed)); |
| 249 | |
| 250 | /* Grabbed from wlan-ng - Thanks Mark... - Jean II |
| 251 | * This is the result of a scan inquiry command */ |
| 252 | /* Structure describing info about an Access Point */ |
| 253 | struct prism2_scan_apinfo { |
Pavel Roskin | d133ae4 | 2005-09-23 04:18:06 -0400 | [diff] [blame] | 254 | __le16 channel; /* Channel where the AP sits */ |
| 255 | __le16 noise; /* Noise level */ |
| 256 | __le16 level; /* Signal level */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 257 | u8 bssid[ETH_ALEN]; /* MAC address of the Access Point */ |
Pavel Roskin | d133ae4 | 2005-09-23 04:18:06 -0400 | [diff] [blame] | 258 | __le16 beacon_interv; /* Beacon interval */ |
| 259 | __le16 capabilities; /* Capabilities */ |
| 260 | __le16 essid_len; /* ESSID length */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 261 | u8 essid[32]; /* ESSID of the network */ |
| 262 | u8 rates[10]; /* Bit rate supported */ |
Pavel Roskin | d133ae4 | 2005-09-23 04:18:06 -0400 | [diff] [blame] | 263 | __le16 proberesp_rate; /* Data rate of the response frame */ |
| 264 | __le16 atim; /* ATIM window time, Kus (hostscan only) */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 265 | } __attribute__ ((packed)); |
| 266 | |
| 267 | /* Same stuff for the Lucent/Agere card. |
| 268 | * Thanks to h1kari <h1kari AT dachb0den.com> - Jean II */ |
| 269 | struct agere_scan_apinfo { |
Pavel Roskin | d133ae4 | 2005-09-23 04:18:06 -0400 | [diff] [blame] | 270 | __le16 channel; /* Channel where the AP sits */ |
| 271 | __le16 noise; /* Noise level */ |
| 272 | __le16 level; /* Signal level */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 273 | u8 bssid[ETH_ALEN]; /* MAC address of the Access Point */ |
Pavel Roskin | d133ae4 | 2005-09-23 04:18:06 -0400 | [diff] [blame] | 274 | __le16 beacon_interv; /* Beacon interval */ |
| 275 | __le16 capabilities; /* Capabilities */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 276 | /* bits: 0-ess, 1-ibss, 4-privacy [wep] */ |
Pavel Roskin | d133ae4 | 2005-09-23 04:18:06 -0400 | [diff] [blame] | 277 | __le16 essid_len; /* ESSID length */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 278 | u8 essid[32]; /* ESSID of the network */ |
| 279 | } __attribute__ ((packed)); |
| 280 | |
| 281 | /* Moustafa: Scan structure for Symbol cards */ |
| 282 | struct symbol_scan_apinfo { |
| 283 | u8 channel; /* Channel where the AP sits */ |
| 284 | u8 unknown1; /* 8 in 2.9x and 3.9x f/w, 0 otherwise */ |
Pavel Roskin | d133ae4 | 2005-09-23 04:18:06 -0400 | [diff] [blame] | 285 | __le16 noise; /* Noise level */ |
| 286 | __le16 level; /* Signal level */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 287 | u8 bssid[ETH_ALEN]; /* MAC address of the Access Point */ |
Pavel Roskin | d133ae4 | 2005-09-23 04:18:06 -0400 | [diff] [blame] | 288 | __le16 beacon_interv; /* Beacon interval */ |
| 289 | __le16 capabilities; /* Capabilities */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 290 | /* bits: 0-ess, 1-ibss, 4-privacy [wep] */ |
Pavel Roskin | d133ae4 | 2005-09-23 04:18:06 -0400 | [diff] [blame] | 291 | __le16 essid_len; /* ESSID length */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 292 | u8 essid[32]; /* ESSID of the network */ |
Pavel Roskin | d133ae4 | 2005-09-23 04:18:06 -0400 | [diff] [blame] | 293 | __le16 rates[5]; /* Bit rate supported */ |
| 294 | __le16 basic_rates; /* Basic rates bitmask */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 295 | u8 unknown2[6]; /* Always FF:FF:FF:FF:00:00 */ |
| 296 | u8 unknown3[8]; /* Always 0, appeared in f/w 3.91-68 */ |
| 297 | } __attribute__ ((packed)); |
| 298 | |
| 299 | union hermes_scan_info { |
| 300 | struct agere_scan_apinfo a; |
| 301 | struct prism2_scan_apinfo p; |
| 302 | struct symbol_scan_apinfo s; |
| 303 | }; |
| 304 | |
| 305 | #define HERMES_LINKSTATUS_NOT_CONNECTED (0x0000) |
| 306 | #define HERMES_LINKSTATUS_CONNECTED (0x0001) |
| 307 | #define HERMES_LINKSTATUS_DISCONNECTED (0x0002) |
| 308 | #define HERMES_LINKSTATUS_AP_CHANGE (0x0003) |
| 309 | #define HERMES_LINKSTATUS_AP_OUT_OF_RANGE (0x0004) |
| 310 | #define HERMES_LINKSTATUS_AP_IN_RANGE (0x0005) |
| 311 | #define HERMES_LINKSTATUS_ASSOC_FAILED (0x0006) |
| 312 | |
| 313 | struct hermes_linkstatus { |
Pavel Roskin | d133ae4 | 2005-09-23 04:18:06 -0400 | [diff] [blame] | 314 | __le16 linkstatus; /* Link status */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 315 | } __attribute__ ((packed)); |
| 316 | |
| 317 | struct hermes_response { |
| 318 | u16 status, resp0, resp1, resp2; |
| 319 | }; |
| 320 | |
| 321 | /* "ID" structure - used for ESSID and station nickname */ |
| 322 | struct hermes_idstring { |
Pavel Roskin | d133ae4 | 2005-09-23 04:18:06 -0400 | [diff] [blame] | 323 | __le16 len; |
| 324 | __le16 val[16]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 325 | } __attribute__ ((packed)); |
| 326 | |
| 327 | struct hermes_multicast { |
| 328 | u8 addr[HERMES_MAX_MULTICAST][ETH_ALEN]; |
| 329 | } __attribute__ ((packed)); |
| 330 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 331 | /* Timeouts */ |
| 332 | #define HERMES_BAP_BUSY_TIMEOUT (10000) /* In iterations of ~1us */ |
| 333 | |
| 334 | /* Basic control structure */ |
| 335 | typedef struct hermes { |
| 336 | void __iomem *iobase; |
| 337 | int reg_spacing; |
| 338 | #define HERMES_16BIT_REGSPACING 0 |
| 339 | #define HERMES_32BIT_REGSPACING 1 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 340 | u16 inten; /* Which interrupts should be enabled? */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 341 | } hermes_t; |
| 342 | |
| 343 | /* Register access convenience macros */ |
| 344 | #define hermes_read_reg(hw, off) \ |
| 345 | (ioread16((hw)->iobase + ( (off) << (hw)->reg_spacing ))) |
| 346 | #define hermes_write_reg(hw, off, val) \ |
| 347 | (iowrite16((val), (hw)->iobase + ((off) << (hw)->reg_spacing))) |
| 348 | #define hermes_read_regn(hw, name) hermes_read_reg((hw), HERMES_##name) |
| 349 | #define hermes_write_regn(hw, name, val) hermes_write_reg((hw), HERMES_##name, (val)) |
| 350 | |
| 351 | /* Function prototypes */ |
| 352 | void hermes_struct_init(hermes_t *hw, void __iomem *address, int reg_spacing); |
| 353 | int hermes_init(hermes_t *hw); |
| 354 | int hermes_docmd_wait(hermes_t *hw, u16 cmd, u16 parm0, |
| 355 | struct hermes_response *resp); |
| 356 | int hermes_allocate(hermes_t *hw, u16 size, u16 *fid); |
| 357 | |
Jeff Garzik | f7492f1 | 2005-11-18 15:06:59 -0500 | [diff] [blame] | 358 | int hermes_bap_pread(hermes_t *hw, int bap, void *buf, int len, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 359 | u16 id, u16 offset); |
Jeff Garzik | f7492f1 | 2005-11-18 15:06:59 -0500 | [diff] [blame] | 360 | int hermes_bap_pwrite(hermes_t *hw, int bap, const void *buf, int len, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 361 | u16 id, u16 offset); |
| 362 | int hermes_read_ltv(hermes_t *hw, int bap, u16 rid, unsigned buflen, |
| 363 | u16 *length, void *buf); |
| 364 | int hermes_write_ltv(hermes_t *hw, int bap, u16 rid, |
| 365 | u16 length, const void *value); |
| 366 | |
| 367 | /* Inline functions */ |
| 368 | |
| 369 | static inline int hermes_present(hermes_t *hw) |
| 370 | { |
| 371 | return hermes_read_regn(hw, SWSUPPORT0) == HERMES_MAGIC; |
| 372 | } |
| 373 | |
| 374 | static inline void hermes_set_irqmask(hermes_t *hw, u16 events) |
| 375 | { |
| 376 | hw->inten = events; |
| 377 | hermes_write_regn(hw, INTEN, events); |
| 378 | } |
| 379 | |
| 380 | static inline int hermes_enable_port(hermes_t *hw, int port) |
| 381 | { |
| 382 | return hermes_docmd_wait(hw, HERMES_CMD_ENABLE | (port << 8), |
| 383 | 0, NULL); |
| 384 | } |
| 385 | |
| 386 | static inline int hermes_disable_port(hermes_t *hw, int port) |
| 387 | { |
| 388 | return hermes_docmd_wait(hw, HERMES_CMD_DISABLE | (port << 8), |
| 389 | 0, NULL); |
| 390 | } |
| 391 | |
| 392 | /* Initiate an INQUIRE command (tallies or scan). The result will come as an |
| 393 | * information frame in __orinoco_ev_info() */ |
| 394 | static inline int hermes_inquire(hermes_t *hw, u16 rid) |
| 395 | { |
| 396 | return hermes_docmd_wait(hw, HERMES_CMD_INQUIRE, rid, NULL); |
| 397 | } |
| 398 | |
| 399 | #define HERMES_BYTES_TO_RECLEN(n) ( (((n)+1)/2) + 1 ) |
| 400 | #define HERMES_RECLEN_TO_BYTES(n) ( ((n)-1) * 2 ) |
| 401 | |
| 402 | /* Note that for the next two, the count is in 16-bit words, not bytes */ |
| 403 | static inline void hermes_read_words(struct hermes *hw, int off, void *buf, unsigned count) |
| 404 | { |
| 405 | off = off << hw->reg_spacing; |
| 406 | ioread16_rep(hw->iobase + off, buf, count); |
| 407 | } |
| 408 | |
Pavel Roskin | 6b61626 | 2006-04-07 04:10:39 -0400 | [diff] [blame] | 409 | static inline void hermes_write_bytes(struct hermes *hw, int off, |
| 410 | const char *buf, unsigned count) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 411 | { |
| 412 | off = off << hw->reg_spacing; |
Pavel Roskin | 6b61626 | 2006-04-07 04:10:39 -0400 | [diff] [blame] | 413 | iowrite16_rep(hw->iobase + off, buf, count >> 1); |
| 414 | if (unlikely(count & 1)) |
| 415 | iowrite8(buf[count - 1], hw->iobase + off); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 416 | } |
| 417 | |
| 418 | static inline void hermes_clear_words(struct hermes *hw, int off, unsigned count) |
| 419 | { |
| 420 | unsigned i; |
| 421 | |
| 422 | off = off << hw->reg_spacing; |
| 423 | |
| 424 | for (i = 0; i < count; i++) |
| 425 | iowrite16(0, hw->iobase + off); |
| 426 | } |
| 427 | |
| 428 | #define HERMES_READ_RECORD(hw, bap, rid, buf) \ |
| 429 | (hermes_read_ltv((hw),(bap),(rid), sizeof(*buf), NULL, (buf))) |
| 430 | #define HERMES_WRITE_RECORD(hw, bap, rid, buf) \ |
| 431 | (hermes_write_ltv((hw),(bap),(rid),HERMES_BYTES_TO_RECLEN(sizeof(*buf)),(buf))) |
| 432 | |
| 433 | static inline int hermes_read_wordrec(hermes_t *hw, int bap, u16 rid, u16 *word) |
| 434 | { |
Pavel Roskin | d133ae4 | 2005-09-23 04:18:06 -0400 | [diff] [blame] | 435 | __le16 rec; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 436 | int err; |
| 437 | |
| 438 | err = HERMES_READ_RECORD(hw, bap, rid, &rec); |
| 439 | *word = le16_to_cpu(rec); |
| 440 | return err; |
| 441 | } |
| 442 | |
| 443 | static inline int hermes_write_wordrec(hermes_t *hw, int bap, u16 rid, u16 word) |
| 444 | { |
Pavel Roskin | d133ae4 | 2005-09-23 04:18:06 -0400 | [diff] [blame] | 445 | __le16 rec = cpu_to_le16(word); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 446 | return HERMES_WRITE_RECORD(hw, bap, rid, &rec); |
| 447 | } |
| 448 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 449 | #endif /* _HERMES_H */ |