hermes.h 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494
  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_TXCNTL2_OFFSET (HERMES_802_3_OFFSET - 2)
  161. #define HERMES_RXSTAT_ERR (0x0003)
  162. #define HERMES_RXSTAT_BADCRC (0x0001)
  163. #define HERMES_RXSTAT_UNDECRYPTABLE (0x0002)
  164. #define HERMES_RXSTAT_MIC (0x0010) /* Frame contains MIC */
  165. #define HERMES_RXSTAT_MACPORT (0x0700)
  166. #define HERMES_RXSTAT_PCF (0x1000) /* Frame was received in CF period */
  167. #define HERMES_RXSTAT_MIC_KEY_ID (0x1800) /* MIC key used */
  168. #define HERMES_RXSTAT_MSGTYPE (0xE000)
  169. #define HERMES_RXSTAT_1042 (0x2000) /* RFC-1042 frame */
  170. #define HERMES_RXSTAT_TUNNEL (0x4000) /* bridge-tunnel encoded frame */
  171. #define HERMES_RXSTAT_WMP (0x6000) /* Wavelan-II Management Protocol frame */
  172. /* Shift amount for key ID in RXSTAT and TXCTRL */
  173. #define HERMES_MIC_KEY_ID_SHIFT 11
  174. struct hermes_tx_descriptor {
  175. __le16 status;
  176. __le16 reserved1;
  177. __le16 reserved2;
  178. __le32 sw_support;
  179. u8 retry_count;
  180. u8 tx_rate;
  181. __le16 tx_control;
  182. } __attribute__ ((packed));
  183. #define HERMES_TXSTAT_RETRYERR (0x0001)
  184. #define HERMES_TXSTAT_AGEDERR (0x0002)
  185. #define HERMES_TXSTAT_DISCON (0x0004)
  186. #define HERMES_TXSTAT_FORMERR (0x0008)
  187. #define HERMES_TXCTRL_TX_OK (0x0002) /* ?? interrupt on Tx complete */
  188. #define HERMES_TXCTRL_TX_EX (0x0004) /* ?? interrupt on Tx exception */
  189. #define HERMES_TXCTRL_802_11 (0x0008) /* We supply 802.11 header */
  190. #define HERMES_TXCTRL_MIC (0x0010) /* 802.3 + TKIP */
  191. #define HERMES_TXCTRL_MIC_KEY_ID (0x1800) /* MIC Key ID mask */
  192. #define HERMES_TXCTRL_ALT_RTRY (0x0020)
  193. /* Inquiry constants and data types */
  194. #define HERMES_INQ_TALLIES (0xF100)
  195. #define HERMES_INQ_SCAN (0xF101)
  196. #define HERMES_INQ_CHANNELINFO (0xF102)
  197. #define HERMES_INQ_HOSTSCAN (0xF103)
  198. #define HERMES_INQ_HOSTSCAN_SYMBOL (0xF104)
  199. #define HERMES_INQ_LINKSTATUS (0xF200)
  200. #define HERMES_INQ_SEC_STAT_AGERE (0xF202)
  201. struct hermes_tallies_frame {
  202. __le16 TxUnicastFrames;
  203. __le16 TxMulticastFrames;
  204. __le16 TxFragments;
  205. __le16 TxUnicastOctets;
  206. __le16 TxMulticastOctets;
  207. __le16 TxDeferredTransmissions;
  208. __le16 TxSingleRetryFrames;
  209. __le16 TxMultipleRetryFrames;
  210. __le16 TxRetryLimitExceeded;
  211. __le16 TxDiscards;
  212. __le16 RxUnicastFrames;
  213. __le16 RxMulticastFrames;
  214. __le16 RxFragments;
  215. __le16 RxUnicastOctets;
  216. __le16 RxMulticastOctets;
  217. __le16 RxFCSErrors;
  218. __le16 RxDiscards_NoBuffer;
  219. __le16 TxDiscardsWrongSA;
  220. __le16 RxWEPUndecryptable;
  221. __le16 RxMsgInMsgFragments;
  222. __le16 RxMsgInBadMsgFragments;
  223. /* Those last are probably not available in very old firmwares */
  224. __le16 RxDiscards_WEPICVError;
  225. __le16 RxDiscards_WEPExcluded;
  226. } __attribute__ ((packed));
  227. /* Grabbed from wlan-ng - Thanks Mark... - Jean II
  228. * This is the result of a scan inquiry command */
  229. /* Structure describing info about an Access Point */
  230. struct prism2_scan_apinfo {
  231. __le16 channel; /* Channel where the AP sits */
  232. __le16 noise; /* Noise level */
  233. __le16 level; /* Signal level */
  234. u8 bssid[ETH_ALEN]; /* MAC address of the Access Point */
  235. __le16 beacon_interv; /* Beacon interval */
  236. __le16 capabilities; /* Capabilities */
  237. __le16 essid_len; /* ESSID length */
  238. u8 essid[32]; /* ESSID of the network */
  239. u8 rates[10]; /* Bit rate supported */
  240. __le16 proberesp_rate; /* Data rate of the response frame */
  241. __le16 atim; /* ATIM window time, Kus (hostscan only) */
  242. } __attribute__ ((packed));
  243. /* Same stuff for the Lucent/Agere card.
  244. * Thanks to h1kari <h1kari AT dachb0den.com> - Jean II */
  245. struct agere_scan_apinfo {
  246. __le16 channel; /* Channel where the AP sits */
  247. __le16 noise; /* Noise level */
  248. __le16 level; /* Signal level */
  249. u8 bssid[ETH_ALEN]; /* MAC address of the Access Point */
  250. __le16 beacon_interv; /* Beacon interval */
  251. __le16 capabilities; /* Capabilities */
  252. /* bits: 0-ess, 1-ibss, 4-privacy [wep] */
  253. __le16 essid_len; /* ESSID length */
  254. u8 essid[32]; /* ESSID of the network */
  255. } __attribute__ ((packed));
  256. /* Moustafa: Scan structure for Symbol cards */
  257. struct symbol_scan_apinfo {
  258. u8 channel; /* Channel where the AP sits */
  259. u8 unknown1; /* 8 in 2.9x and 3.9x f/w, 0 otherwise */
  260. __le16 noise; /* Noise level */
  261. __le16 level; /* Signal level */
  262. u8 bssid[ETH_ALEN]; /* MAC address of the Access Point */
  263. __le16 beacon_interv; /* Beacon interval */
  264. __le16 capabilities; /* Capabilities */
  265. /* bits: 0-ess, 1-ibss, 4-privacy [wep] */
  266. __le16 essid_len; /* ESSID length */
  267. u8 essid[32]; /* ESSID of the network */
  268. __le16 rates[5]; /* Bit rate supported */
  269. __le16 basic_rates; /* Basic rates bitmask */
  270. u8 unknown2[6]; /* Always FF:FF:FF:FF:00:00 */
  271. u8 unknown3[8]; /* Always 0, appeared in f/w 3.91-68 */
  272. } __attribute__ ((packed));
  273. union hermes_scan_info {
  274. struct agere_scan_apinfo a;
  275. struct prism2_scan_apinfo p;
  276. struct symbol_scan_apinfo s;
  277. };
  278. /* Extended scan struct for HERMES_INQ_CHANNELINFO.
  279. * wl_lkm calls this an ACS scan (Automatic Channel Select).
  280. * Keep out of union hermes_scan_info because it is much bigger than
  281. * the older scan structures. */
  282. struct agere_ext_scan_info {
  283. __le16 reserved0;
  284. u8 noise;
  285. u8 level;
  286. u8 rx_flow;
  287. u8 rate;
  288. __le16 reserved1[2];
  289. __le16 frame_control;
  290. __le16 dur_id;
  291. u8 addr1[ETH_ALEN];
  292. u8 addr2[ETH_ALEN];
  293. u8 bssid[ETH_ALEN];
  294. __le16 sequence;
  295. u8 addr4[ETH_ALEN];
  296. __le16 data_length;
  297. /* Next 3 fields do not get filled in. */
  298. u8 daddr[ETH_ALEN];
  299. u8 saddr[ETH_ALEN];
  300. __le16 len_type;
  301. __le64 timestamp;
  302. __le16 beacon_interval;
  303. __le16 capabilities;
  304. u8 data[316];
  305. } __attribute__ ((packed));
  306. #define HERMES_LINKSTATUS_NOT_CONNECTED (0x0000)
  307. #define HERMES_LINKSTATUS_CONNECTED (0x0001)
  308. #define HERMES_LINKSTATUS_DISCONNECTED (0x0002)
  309. #define HERMES_LINKSTATUS_AP_CHANGE (0x0003)
  310. #define HERMES_LINKSTATUS_AP_OUT_OF_RANGE (0x0004)
  311. #define HERMES_LINKSTATUS_AP_IN_RANGE (0x0005)
  312. #define HERMES_LINKSTATUS_ASSOC_FAILED (0x0006)
  313. struct hermes_linkstatus {
  314. __le16 linkstatus; /* Link status */
  315. } __attribute__ ((packed));
  316. struct hermes_response {
  317. u16 status, resp0, resp1, resp2;
  318. };
  319. /* "ID" structure - used for ESSID and station nickname */
  320. struct hermes_idstring {
  321. __le16 len;
  322. __le16 val[16];
  323. } __attribute__ ((packed));
  324. struct hermes_multicast {
  325. u8 addr[HERMES_MAX_MULTICAST][ETH_ALEN];
  326. } __attribute__ ((packed));
  327. /* Timeouts */
  328. #define HERMES_BAP_BUSY_TIMEOUT (10000) /* In iterations of ~1us */
  329. /* Basic control structure */
  330. typedef struct hermes {
  331. void __iomem *iobase;
  332. int reg_spacing;
  333. #define HERMES_16BIT_REGSPACING 0
  334. #define HERMES_32BIT_REGSPACING 1
  335. u16 inten; /* Which interrupts should be enabled? */
  336. } hermes_t;
  337. /* Register access convenience macros */
  338. #define hermes_read_reg(hw, off) \
  339. (ioread16((hw)->iobase + ( (off) << (hw)->reg_spacing )))
  340. #define hermes_write_reg(hw, off, val) \
  341. (iowrite16((val), (hw)->iobase + ((off) << (hw)->reg_spacing)))
  342. #define hermes_read_regn(hw, name) hermes_read_reg((hw), HERMES_##name)
  343. #define hermes_write_regn(hw, name, val) hermes_write_reg((hw), HERMES_##name, (val))
  344. /* Function prototypes */
  345. void hermes_struct_init(hermes_t *hw, void __iomem *address, int reg_spacing);
  346. int hermes_init(hermes_t *hw);
  347. int hermes_docmd_wait(hermes_t *hw, u16 cmd, u16 parm0,
  348. struct hermes_response *resp);
  349. int hermes_doicmd_wait(hermes_t *hw, u16 cmd,
  350. u16 parm0, u16 parm1, u16 parm2,
  351. struct hermes_response *resp);
  352. int hermes_allocate(hermes_t *hw, u16 size, u16 *fid);
  353. int hermes_bap_pread(hermes_t *hw, int bap, void *buf, int len,
  354. u16 id, u16 offset);
  355. int hermes_bap_pwrite(hermes_t *hw, int bap, const void *buf, int len,
  356. u16 id, u16 offset);
  357. int hermes_read_ltv(hermes_t *hw, int bap, u16 rid, unsigned buflen,
  358. u16 *length, void *buf);
  359. int hermes_write_ltv(hermes_t *hw, int bap, u16 rid,
  360. u16 length, const void *value);
  361. /* Inline functions */
  362. static inline int hermes_present(hermes_t *hw)
  363. {
  364. return hermes_read_regn(hw, SWSUPPORT0) == HERMES_MAGIC;
  365. }
  366. static inline void hermes_set_irqmask(hermes_t *hw, u16 events)
  367. {
  368. hw->inten = events;
  369. hermes_write_regn(hw, INTEN, events);
  370. }
  371. static inline int hermes_enable_port(hermes_t *hw, int port)
  372. {
  373. return hermes_docmd_wait(hw, HERMES_CMD_ENABLE | (port << 8),
  374. 0, NULL);
  375. }
  376. static inline int hermes_disable_port(hermes_t *hw, int port)
  377. {
  378. return hermes_docmd_wait(hw, HERMES_CMD_DISABLE | (port << 8),
  379. 0, NULL);
  380. }
  381. /* Initiate an INQUIRE command (tallies or scan). The result will come as an
  382. * information frame in __orinoco_ev_info() */
  383. static inline int hermes_inquire(hermes_t *hw, u16 rid)
  384. {
  385. return hermes_docmd_wait(hw, HERMES_CMD_INQUIRE, rid, NULL);
  386. }
  387. #define HERMES_BYTES_TO_RECLEN(n) ( (((n)+1)/2) + 1 )
  388. #define HERMES_RECLEN_TO_BYTES(n) ( ((n)-1) * 2 )
  389. /* Note that for the next two, the count is in 16-bit words, not bytes */
  390. static inline void hermes_read_words(struct hermes *hw, int off, void *buf, unsigned count)
  391. {
  392. off = off << hw->reg_spacing;
  393. ioread16_rep(hw->iobase + off, buf, count);
  394. }
  395. static inline void hermes_write_bytes(struct hermes *hw, int off,
  396. const char *buf, unsigned count)
  397. {
  398. off = off << hw->reg_spacing;
  399. iowrite16_rep(hw->iobase + off, buf, count >> 1);
  400. if (unlikely(count & 1))
  401. iowrite8(buf[count - 1], hw->iobase + off);
  402. }
  403. static inline void hermes_clear_words(struct hermes *hw, int off, unsigned count)
  404. {
  405. unsigned i;
  406. off = off << hw->reg_spacing;
  407. for (i = 0; i < count; i++)
  408. iowrite16(0, hw->iobase + off);
  409. }
  410. #define HERMES_READ_RECORD(hw, bap, rid, buf) \
  411. (hermes_read_ltv((hw),(bap),(rid), sizeof(*buf), NULL, (buf)))
  412. #define HERMES_WRITE_RECORD(hw, bap, rid, buf) \
  413. (hermes_write_ltv((hw),(bap),(rid),HERMES_BYTES_TO_RECLEN(sizeof(*buf)),(buf)))
  414. static inline int hermes_read_wordrec(hermes_t *hw, int bap, u16 rid, u16 *word)
  415. {
  416. __le16 rec;
  417. int err;
  418. err = HERMES_READ_RECORD(hw, bap, rid, &rec);
  419. *word = le16_to_cpu(rec);
  420. return err;
  421. }
  422. static inline int hermes_write_wordrec(hermes_t *hw, int bap, u16 rid, u16 word)
  423. {
  424. __le16 rec = cpu_to_le16(word);
  425. return HERMES_WRITE_RECORD(hw, bap, rid, &rec);
  426. }
  427. #endif /* _HERMES_H */