hermes.h 15 KB

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