hermes.h 15 KB

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