You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

rtl818x.h 9.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359
  1. /*
  2. * Definitions for RTL818x hardware
  3. *
  4. * Copyright 2007 Michael Wu <flamingice@sourmilk.net>
  5. * Copyright 2007 Andrea Merello <andreamrl@tiscali.it>
  6. *
  7. * Modified for iPXE, June 2009, by Joshua Oreman <oremanj@rwcr.net>
  8. *
  9. * Based on the r8187 driver, which is:
  10. * Copyright 2005 Andrea Merello <andreamrl@tiscali.it>, et al.
  11. *
  12. * This program is free software; you can redistribute it and/or modify
  13. * it under the terms of the GNU General Public License version 2 as
  14. * published by the Free Software Foundation.
  15. */
  16. #ifndef RTL818X_H
  17. #define RTL818X_H
  18. #include <ipxe/spi_bit.h>
  19. #include <ipxe/tables.h>
  20. FILE_LICENCE(GPL2_ONLY);
  21. struct rtl818x_csr {
  22. u8 MAC[6];
  23. u8 reserved_0[2];
  24. u32 MAR[2];
  25. u8 RX_FIFO_COUNT;
  26. u8 reserved_1;
  27. u8 TX_FIFO_COUNT;
  28. u8 BQREQ;
  29. u8 reserved_2[4];
  30. u32 TSFT[2];
  31. u32 TLPDA;
  32. u32 TNPDA;
  33. u32 THPDA;
  34. u16 BRSR;
  35. u8 BSSID[6];
  36. u8 RESP_RATE;
  37. u8 EIFS;
  38. u8 reserved_3[1];
  39. u8 CMD;
  40. #define RTL818X_CMD_TX_ENABLE (1 << 2)
  41. #define RTL818X_CMD_RX_ENABLE (1 << 3)
  42. #define RTL818X_CMD_RESET (1 << 4)
  43. u8 reserved_4[4];
  44. u16 INT_MASK;
  45. u16 INT_STATUS;
  46. #define RTL818X_INT_RX_OK (1 << 0)
  47. #define RTL818X_INT_RX_ERR (1 << 1)
  48. #define RTL818X_INT_TXL_OK (1 << 2)
  49. #define RTL818X_INT_TXL_ERR (1 << 3)
  50. #define RTL818X_INT_RX_DU (1 << 4)
  51. #define RTL818X_INT_RX_FO (1 << 5)
  52. #define RTL818X_INT_TXN_OK (1 << 6)
  53. #define RTL818X_INT_TXN_ERR (1 << 7)
  54. #define RTL818X_INT_TXH_OK (1 << 8)
  55. #define RTL818X_INT_TXH_ERR (1 << 9)
  56. #define RTL818X_INT_TXB_OK (1 << 10)
  57. #define RTL818X_INT_TXB_ERR (1 << 11)
  58. #define RTL818X_INT_ATIM (1 << 12)
  59. #define RTL818X_INT_BEACON (1 << 13)
  60. #define RTL818X_INT_TIME_OUT (1 << 14)
  61. #define RTL818X_INT_TX_FO (1 << 15)
  62. u32 TX_CONF;
  63. #define RTL818X_TX_CONF_LOOPBACK_MAC (1 << 17)
  64. #define RTL818X_TX_CONF_LOOPBACK_CONT (3 << 17)
  65. #define RTL818X_TX_CONF_NO_ICV (1 << 19)
  66. #define RTL818X_TX_CONF_DISCW (1 << 20)
  67. #define RTL818X_TX_CONF_SAT_HWPLCP (1 << 24)
  68. #define RTL818X_TX_CONF_R8180_ABCD (2 << 25)
  69. #define RTL818X_TX_CONF_R8180_F (3 << 25)
  70. #define RTL818X_TX_CONF_R8185_ABC (4 << 25)
  71. #define RTL818X_TX_CONF_R8185_D (5 << 25)
  72. #define RTL818X_TX_CONF_R8187vD (5 << 25)
  73. #define RTL818X_TX_CONF_R8187vD_B (6 << 25)
  74. #define RTL818X_TX_CONF_HWVER_MASK (7 << 25)
  75. #define RTL818X_TX_CONF_DISREQQSIZE (1 << 28)
  76. #define RTL818X_TX_CONF_PROBE_DTS (1 << 29)
  77. #define RTL818X_TX_CONF_HW_SEQNUM (1 << 30)
  78. #define RTL818X_TX_CONF_CW_MIN (1 << 31)
  79. u32 RX_CONF;
  80. #define RTL818X_RX_CONF_MONITOR (1 << 0)
  81. #define RTL818X_RX_CONF_NICMAC (1 << 1)
  82. #define RTL818X_RX_CONF_MULTICAST (1 << 2)
  83. #define RTL818X_RX_CONF_BROADCAST (1 << 3)
  84. #define RTL818X_RX_CONF_FCS (1 << 5)
  85. #define RTL818X_RX_CONF_DATA (1 << 18)
  86. #define RTL818X_RX_CONF_CTRL (1 << 19)
  87. #define RTL818X_RX_CONF_MGMT (1 << 20)
  88. #define RTL818X_RX_CONF_ADDR3 (1 << 21)
  89. #define RTL818X_RX_CONF_PM (1 << 22)
  90. #define RTL818X_RX_CONF_BSSID (1 << 23)
  91. #define RTL818X_RX_CONF_RX_AUTORESETPHY (1 << 28)
  92. #define RTL818X_RX_CONF_CSDM1 (1 << 29)
  93. #define RTL818X_RX_CONF_CSDM2 (1 << 30)
  94. #define RTL818X_RX_CONF_ONLYERLPKT (1 << 31)
  95. u32 INT_TIMEOUT;
  96. u32 TBDA;
  97. u8 EEPROM_CMD;
  98. #define RTL818X_EEPROM_CMD_READ (1 << 0)
  99. #define RTL818X_EEPROM_CMD_WRITE (1 << 1)
  100. #define RTL818X_EEPROM_CMD_CK (1 << 2)
  101. #define RTL818X_EEPROM_CMD_CS (1 << 3)
  102. #define RTL818X_EEPROM_CMD_NORMAL (0 << 6)
  103. #define RTL818X_EEPROM_CMD_LOAD (1 << 6)
  104. #define RTL818X_EEPROM_CMD_PROGRAM (2 << 6)
  105. #define RTL818X_EEPROM_CMD_CONFIG (3 << 6)
  106. u8 CONFIG0;
  107. u8 CONFIG1;
  108. u8 CONFIG2;
  109. #define RTL818X_CONFIG2_ANTENNA_DIV (1 << 6)
  110. u32 ANAPARAM;
  111. u8 MSR;
  112. #define RTL818X_MSR_NO_LINK (0 << 2)
  113. #define RTL818X_MSR_ADHOC (1 << 2)
  114. #define RTL818X_MSR_INFRA (2 << 2)
  115. #define RTL818X_MSR_MASTER (3 << 2)
  116. #define RTL818X_MSR_ENEDCA (4 << 2)
  117. u8 CONFIG3;
  118. #define RTL818X_CONFIG3_ANAPARAM_WRITE (1 << 6)
  119. #define RTL818X_CONFIG3_GNT_SELECT (1 << 7)
  120. u8 CONFIG4;
  121. #define RTL818X_CONFIG4_POWEROFF (1 << 6)
  122. #define RTL818X_CONFIG4_VCOOFF (1 << 7)
  123. u8 TESTR;
  124. u8 reserved_9[2];
  125. u8 PGSELECT;
  126. u8 SECURITY;
  127. u32 ANAPARAM2;
  128. u8 reserved_10[12];
  129. u16 BEACON_INTERVAL;
  130. u16 ATIM_WND;
  131. u16 BEACON_INTERVAL_TIME;
  132. u16 ATIMTR_INTERVAL;
  133. u8 PHY_DELAY;
  134. u8 CARRIER_SENSE_COUNTER;
  135. u8 reserved_11[2];
  136. u8 PHY[4];
  137. u16 RFPinsOutput;
  138. u16 RFPinsEnable;
  139. u16 RFPinsSelect;
  140. u16 RFPinsInput;
  141. u32 RF_PARA;
  142. u32 RF_TIMING;
  143. u8 GP_ENABLE;
  144. u8 GPIO;
  145. u8 reserved_12[2];
  146. u32 HSSI_PARA;
  147. u8 reserved_13[4];
  148. u8 TX_AGC_CTL;
  149. #define RTL818X_TX_AGC_CTL_PERPACKET_GAIN_SHIFT (1 << 0)
  150. #define RTL818X_TX_AGC_CTL_PERPACKET_ANTSEL_SHIFT (1 << 1)
  151. #define RTL818X_TX_AGC_CTL_FEEDBACK_ANT (1 << 2)
  152. u8 TX_GAIN_CCK;
  153. u8 TX_GAIN_OFDM;
  154. u8 TX_ANTENNA;
  155. u8 reserved_14[16];
  156. u8 WPA_CONF;
  157. u8 reserved_15[3];
  158. u8 SIFS;
  159. u8 DIFS;
  160. u8 SLOT;
  161. u8 reserved_16[5];
  162. u8 CW_CONF;
  163. #define RTL818X_CW_CONF_PERPACKET_CW_SHIFT (1 << 0)
  164. #define RTL818X_CW_CONF_PERPACKET_RETRY_SHIFT (1 << 1)
  165. u8 CW_VAL;
  166. u8 RATE_FALLBACK;
  167. #define RTL818X_RATE_FALLBACK_ENABLE (1 << 7)
  168. u8 ACM_CONTROL;
  169. u8 reserved_17[24];
  170. u8 CONFIG5;
  171. u8 TX_DMA_POLLING;
  172. u8 reserved_18[2];
  173. u16 CWR;
  174. u8 RETRY_CTR;
  175. u8 reserved_19[3];
  176. u16 INT_MIG;
  177. /* RTL818X_R8187B_*: magic numbers from ioregisters */
  178. #define RTL818X_R8187B_B 0
  179. #define RTL818X_R8187B_D 1
  180. #define RTL818X_R8187B_E 2
  181. u32 RDSAR;
  182. u16 TID_AC_MAP;
  183. u8 reserved_20[4];
  184. u8 ANAPARAM3;
  185. u8 reserved_21[5];
  186. u16 FEMR;
  187. u8 reserved_22[4];
  188. u16 TALLY_CNT;
  189. u8 TALLY_SEL;
  190. } __attribute__((packed));
  191. #define MAX_RX_SIZE IEEE80211_MAX_FRAME_LEN
  192. #define RF_PARAM_ANALOGPHY (1 << 0)
  193. #define RF_PARAM_ANTBDEFAULT (1 << 1)
  194. #define RF_PARAM_CARRIERSENSE1 (1 << 2)
  195. #define RF_PARAM_CARRIERSENSE2 (1 << 3)
  196. #define BB_ANTATTEN_CHAN14 0x0C
  197. #define BB_ANTENNA_B 0x40
  198. #define BB_HOST_BANG (1 << 30)
  199. #define BB_HOST_BANG_EN (1 << 2)
  200. #define BB_HOST_BANG_CLK (1 << 1)
  201. #define BB_HOST_BANG_DATA 1
  202. #define ANAPARAM_TXDACOFF_SHIFT 27
  203. #define ANAPARAM_PWR0_SHIFT 28
  204. #define ANAPARAM_PWR0_MASK (0x07 << ANAPARAM_PWR0_SHIFT)
  205. #define ANAPARAM_PWR1_SHIFT 20
  206. #define ANAPARAM_PWR1_MASK (0x7F << ANAPARAM_PWR1_SHIFT)
  207. #define RTL818X_RX_RING_SIZE 8 /* doesn't have to be a power of 2 */
  208. #define RTL818X_TX_RING_SIZE 8 /* nor this [but 2^n is very slightly faster] */
  209. #define RTL818X_RING_ALIGN 256
  210. #define RTL818X_MAX_RETRIES 4
  211. enum rtl818x_tx_desc_flags {
  212. RTL818X_TX_DESC_FLAG_NO_ENC = (1 << 15),
  213. RTL818X_TX_DESC_FLAG_TX_OK = (1 << 15),
  214. RTL818X_TX_DESC_FLAG_SPLCP = (1 << 16),
  215. RTL818X_TX_DESC_FLAG_RX_UNDER = (1 << 16),
  216. RTL818X_TX_DESC_FLAG_MOREFRAG = (1 << 17),
  217. RTL818X_TX_DESC_FLAG_CTS = (1 << 18),
  218. RTL818X_TX_DESC_FLAG_RTS = (1 << 23),
  219. RTL818X_TX_DESC_FLAG_LS = (1 << 28),
  220. RTL818X_TX_DESC_FLAG_FS = (1 << 29),
  221. RTL818X_TX_DESC_FLAG_DMA = (1 << 30),
  222. RTL818X_TX_DESC_FLAG_OWN = (1 << 31)
  223. };
  224. struct rtl818x_tx_desc {
  225. u32 flags;
  226. u16 rts_duration;
  227. u16 plcp_len;
  228. u32 tx_buf;
  229. u32 frame_len;
  230. u32 next_tx_desc;
  231. u8 cw;
  232. u8 retry_limit;
  233. u8 agc;
  234. u8 flags2;
  235. u32 reserved[2];
  236. } __attribute__ ((packed));
  237. enum rtl818x_rx_desc_flags {
  238. RTL818X_RX_DESC_FLAG_ICV_ERR = (1 << 12),
  239. RTL818X_RX_DESC_FLAG_CRC32_ERR = (1 << 13),
  240. RTL818X_RX_DESC_FLAG_PM = (1 << 14),
  241. RTL818X_RX_DESC_FLAG_RX_ERR = (1 << 15),
  242. RTL818X_RX_DESC_FLAG_BCAST = (1 << 16),
  243. RTL818X_RX_DESC_FLAG_PAM = (1 << 17),
  244. RTL818X_RX_DESC_FLAG_MCAST = (1 << 18),
  245. RTL818X_RX_DESC_FLAG_QOS = (1 << 19), /* RTL8187(B) only */
  246. RTL818X_RX_DESC_FLAG_TRSW = (1 << 24), /* RTL8187(B) only */
  247. RTL818X_RX_DESC_FLAG_SPLCP = (1 << 25),
  248. RTL818X_RX_DESC_FLAG_FOF = (1 << 26),
  249. RTL818X_RX_DESC_FLAG_DMA_FAIL = (1 << 27),
  250. RTL818X_RX_DESC_FLAG_LS = (1 << 28),
  251. RTL818X_RX_DESC_FLAG_FS = (1 << 29),
  252. RTL818X_RX_DESC_FLAG_EOR = (1 << 30),
  253. RTL818X_RX_DESC_FLAG_OWN = (1 << 31)
  254. };
  255. struct rtl818x_rx_desc {
  256. u32 flags;
  257. u32 flags2;
  258. union {
  259. u32 rx_buf;
  260. u64 tsft;
  261. };
  262. } __attribute__ ((packed));
  263. struct rtl818x_priv {
  264. struct rtl818x_csr *map;
  265. const struct rtl818x_rf_ops *rf;
  266. int rf_flag; /* whatever RF driver wishes to use it for */
  267. int hw_rate;
  268. int hw_rtscts_rate;
  269. struct spi_bit_basher spibit;
  270. struct spi_device eeprom;
  271. struct rtl818x_rx_desc *rx_ring;
  272. u32 rx_ring_dma;
  273. unsigned int rx_idx; /* next desc to be filled by card */
  274. struct io_buffer *rx_buf[RTL818X_RX_RING_SIZE];
  275. struct rtl818x_tx_desc *tx_ring;
  276. u32 tx_ring_dma;
  277. unsigned int tx_cons; /* next desc to be filled by card */
  278. unsigned int tx_prod; /* next desc to be filled by driver */
  279. struct io_buffer *tx_buf[RTL818X_TX_RING_SIZE];
  280. struct pci_device *pdev;
  281. u32 rx_conf;
  282. u16 txpower[14];
  283. int r8185;
  284. u32 anaparam;
  285. u16 rfparam;
  286. u8 csthreshold;
  287. };
  288. void rtl818x_write_phy(struct net80211_device *dev, u8 addr, u32 data);
  289. void rtl818x_set_anaparam(struct rtl818x_priv *priv, u32 anaparam);
  290. static inline u8 rtl818x_ioread8(struct rtl818x_priv *priv __unused, u8 *addr)
  291. {
  292. return inb(addr);
  293. }
  294. static inline u16 rtl818x_ioread16(struct rtl818x_priv *priv __unused, u16 *addr)
  295. {
  296. return inw(addr);
  297. }
  298. static inline u32 rtl818x_ioread32(struct rtl818x_priv *priv __unused, u32 *addr)
  299. {
  300. return inl(addr);
  301. }
  302. static inline void rtl818x_iowrite8(struct rtl818x_priv *priv __unused,
  303. u8 *addr, u8 val)
  304. {
  305. outb(val, addr);
  306. }
  307. static inline void rtl818x_iowrite16(struct rtl818x_priv *priv __unused,
  308. u16 *addr, u16 val)
  309. {
  310. outw(val, addr);
  311. }
  312. static inline void rtl818x_iowrite32(struct rtl818x_priv *priv __unused,
  313. u32 *addr, u32 val)
  314. {
  315. outl(val, addr);
  316. }
  317. #define RTL818X_RF_DRIVERS __table(struct rtl818x_rf_ops, "rtl818x_rf_drivers")
  318. #define __rtl818x_rf_driver __table_entry(RTL818X_RF_DRIVERS, 01)
  319. struct rtl818x_rf_ops {
  320. char *name;
  321. u8 id; /* as identified in EEPROM */
  322. void (*init)(struct net80211_device *dev);
  323. void (*stop)(struct net80211_device *dev);
  324. void (*set_chan)(struct net80211_device *dev, struct net80211_channel *chan);
  325. void (*conf_erp)(struct net80211_device *dev); /* set based on dev->erp_flags */
  326. };
  327. #endif /* RTL818X_H */