2 * Definitions for RTL818x hardware
4 * Copyright 2007 Michael Wu <flamingice@sourmilk.net>
5 * Copyright 2007 Andrea Merello <andreamrl@tiscali.it>
7 * Modified for iPXE, June 2009, by Joshua Oreman <oremanj@rwcr.net>
9 * Based on the r8187 driver, which is:
10 * Copyright 2005 Andrea Merello <andreamrl@tiscali.it>, et al.
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.
20 #include <ipxe/spi_bit.h>
21 #include <ipxe/tables.h>
22 #include <ipxe/net80211.h>
24 FILE_LICENCE(GPL2_ONLY);
45 #define RTL818X_CMD_TX_ENABLE (1 << 2)
46 #define RTL818X_CMD_RX_ENABLE (1 << 3)
47 #define RTL818X_CMD_RESET (1 << 4)
51 #define RTL818X_INT_RX_OK (1 << 0)
52 #define RTL818X_INT_RX_ERR (1 << 1)
53 #define RTL818X_INT_TXL_OK (1 << 2)
54 #define RTL818X_INT_TXL_ERR (1 << 3)
55 #define RTL818X_INT_RX_DU (1 << 4)
56 #define RTL818X_INT_RX_FO (1 << 5)
57 #define RTL818X_INT_TXN_OK (1 << 6)
58 #define RTL818X_INT_TXN_ERR (1 << 7)
59 #define RTL818X_INT_TXH_OK (1 << 8)
60 #define RTL818X_INT_TXH_ERR (1 << 9)
61 #define RTL818X_INT_TXB_OK (1 << 10)
62 #define RTL818X_INT_TXB_ERR (1 << 11)
63 #define RTL818X_INT_ATIM (1 << 12)
64 #define RTL818X_INT_BEACON (1 << 13)
65 #define RTL818X_INT_TIME_OUT (1 << 14)
66 #define RTL818X_INT_TX_FO (1 << 15)
68 #define RTL818X_TX_CONF_LOOPBACK_MAC (1 << 17)
69 #define RTL818X_TX_CONF_LOOPBACK_CONT (3 << 17)
70 #define RTL818X_TX_CONF_NO_ICV (1 << 19)
71 #define RTL818X_TX_CONF_DISCW (1 << 20)
72 #define RTL818X_TX_CONF_SAT_HWPLCP (1 << 24)
73 #define RTL818X_TX_CONF_R8180_ABCD (2 << 25)
74 #define RTL818X_TX_CONF_R8180_F (3 << 25)
75 #define RTL818X_TX_CONF_R8185_ABC (4 << 25)
76 #define RTL818X_TX_CONF_R8185_D (5 << 25)
77 #define RTL818X_TX_CONF_R8187vD (5 << 25)
78 #define RTL818X_TX_CONF_R8187vD_B (6 << 25)
79 #define RTL818X_TX_CONF_HWVER_MASK (7 << 25)
80 #define RTL818X_TX_CONF_DISREQQSIZE (1 << 28)
81 #define RTL818X_TX_CONF_PROBE_DTS (1 << 29)
82 #define RTL818X_TX_CONF_HW_SEQNUM (1 << 30)
83 #define RTL818X_TX_CONF_CW_MIN (1 << 31)
85 #define RTL818X_RX_CONF_MONITOR (1 << 0)
86 #define RTL818X_RX_CONF_NICMAC (1 << 1)
87 #define RTL818X_RX_CONF_MULTICAST (1 << 2)
88 #define RTL818X_RX_CONF_BROADCAST (1 << 3)
89 #define RTL818X_RX_CONF_FCS (1 << 5)
90 #define RTL818X_RX_CONF_DATA (1 << 18)
91 #define RTL818X_RX_CONF_CTRL (1 << 19)
92 #define RTL818X_RX_CONF_MGMT (1 << 20)
93 #define RTL818X_RX_CONF_ADDR3 (1 << 21)
94 #define RTL818X_RX_CONF_PM (1 << 22)
95 #define RTL818X_RX_CONF_BSSID (1 << 23)
96 #define RTL818X_RX_CONF_RX_AUTORESETPHY (1 << 28)
97 #define RTL818X_RX_CONF_CSDM1 (1 << 29)
98 #define RTL818X_RX_CONF_CSDM2 (1 << 30)
99 #define RTL818X_RX_CONF_ONLYERLPKT (1 << 31)
103 #define RTL818X_EEPROM_CMD_READ (1 << 0)
104 #define RTL818X_EEPROM_CMD_WRITE (1 << 1)
105 #define RTL818X_EEPROM_CMD_CK (1 << 2)
106 #define RTL818X_EEPROM_CMD_CS (1 << 3)
107 #define RTL818X_EEPROM_CMD_NORMAL (0 << 6)
108 #define RTL818X_EEPROM_CMD_LOAD (1 << 6)
109 #define RTL818X_EEPROM_CMD_PROGRAM (2 << 6)
110 #define RTL818X_EEPROM_CMD_CONFIG (3 << 6)
114 #define RTL818X_CONFIG2_ANTENNA_DIV (1 << 6)
117 #define RTL818X_MSR_NO_LINK (0 << 2)
118 #define RTL818X_MSR_ADHOC (1 << 2)
119 #define RTL818X_MSR_INFRA (2 << 2)
120 #define RTL818X_MSR_MASTER (3 << 2)
121 #define RTL818X_MSR_ENEDCA (4 << 2)
123 #define RTL818X_CONFIG3_ANAPARAM_WRITE (1 << 6)
124 #define RTL818X_CONFIG3_GNT_SELECT (1 << 7)
126 #define RTL818X_CONFIG4_POWEROFF (1 << 6)
127 #define RTL818X_CONFIG4_VCOOFF (1 << 7)
136 u16 BEACON_INTERVAL_TIME;
139 u8 CARRIER_SENSE_COUNTER;
154 #define RTL818X_TX_AGC_CTL_PERPACKET_GAIN_SHIFT (1 << 0)
155 #define RTL818X_TX_AGC_CTL_PERPACKET_ANTSEL_SHIFT (1 << 1)
156 #define RTL818X_TX_AGC_CTL_FEEDBACK_ANT (1 << 2)
168 #define RTL818X_CW_CONF_PERPACKET_CW_SHIFT (1 << 0)
169 #define RTL818X_CW_CONF_PERPACKET_RETRY_SHIFT (1 << 1)
172 #define RTL818X_RATE_FALLBACK_ENABLE (1 << 7)
182 /* RTL818X_R8187B_*: magic numbers from ioregisters */
183 #define RTL818X_R8187B_B 0
184 #define RTL818X_R8187B_D 1
185 #define RTL818X_R8187B_E 2
195 } __attribute__((packed));
197 #define MAX_RX_SIZE IEEE80211_MAX_FRAME_LEN
199 #define RF_PARAM_ANALOGPHY (1 << 0)
200 #define RF_PARAM_ANTBDEFAULT (1 << 1)
201 #define RF_PARAM_CARRIERSENSE1 (1 << 2)
202 #define RF_PARAM_CARRIERSENSE2 (1 << 3)
204 #define BB_ANTATTEN_CHAN14 0x0C
205 #define BB_ANTENNA_B 0x40
207 #define BB_HOST_BANG (1 << 30)
208 #define BB_HOST_BANG_EN (1 << 2)
209 #define BB_HOST_BANG_CLK (1 << 1)
210 #define BB_HOST_BANG_DATA 1
212 #define ANAPARAM_TXDACOFF_SHIFT 27
213 #define ANAPARAM_PWR0_SHIFT 28
214 #define ANAPARAM_PWR0_MASK (0x07 << ANAPARAM_PWR0_SHIFT)
215 #define ANAPARAM_PWR1_SHIFT 20
216 #define ANAPARAM_PWR1_MASK (0x7F << ANAPARAM_PWR1_SHIFT)
218 #define RTL818X_RX_RING_SIZE 8 /* doesn't have to be a power of 2 */
219 #define RTL818X_TX_RING_SIZE 8 /* nor this [but 2^n is very slightly faster] */
220 #define RTL818X_RING_ALIGN 256
222 #define RTL818X_MAX_RETRIES 4
224 enum rtl818x_tx_desc_flags {
225 RTL818X_TX_DESC_FLAG_NO_ENC = (1 << 15),
226 RTL818X_TX_DESC_FLAG_TX_OK = (1 << 15),
227 RTL818X_TX_DESC_FLAG_SPLCP = (1 << 16),
228 RTL818X_TX_DESC_FLAG_RX_UNDER = (1 << 16),
229 RTL818X_TX_DESC_FLAG_MOREFRAG = (1 << 17),
230 RTL818X_TX_DESC_FLAG_CTS = (1 << 18),
231 RTL818X_TX_DESC_FLAG_RTS = (1 << 23),
232 RTL818X_TX_DESC_FLAG_LS = (1 << 28),
233 RTL818X_TX_DESC_FLAG_FS = (1 << 29),
234 RTL818X_TX_DESC_FLAG_DMA = (1 << 30),
235 RTL818X_TX_DESC_FLAG_OWN = (1 << 31)
238 struct rtl818x_tx_desc {
250 } __attribute__ ((packed));
252 enum rtl818x_rx_desc_flags {
253 RTL818X_RX_DESC_FLAG_ICV_ERR = (1 << 12),
254 RTL818X_RX_DESC_FLAG_CRC32_ERR = (1 << 13),
255 RTL818X_RX_DESC_FLAG_PM = (1 << 14),
256 RTL818X_RX_DESC_FLAG_RX_ERR = (1 << 15),
257 RTL818X_RX_DESC_FLAG_BCAST = (1 << 16),
258 RTL818X_RX_DESC_FLAG_PAM = (1 << 17),
259 RTL818X_RX_DESC_FLAG_MCAST = (1 << 18),
260 RTL818X_RX_DESC_FLAG_QOS = (1 << 19), /* RTL8187(B) only */
261 RTL818X_RX_DESC_FLAG_TRSW = (1 << 24), /* RTL8187(B) only */
262 RTL818X_RX_DESC_FLAG_SPLCP = (1 << 25),
263 RTL818X_RX_DESC_FLAG_FOF = (1 << 26),
264 RTL818X_RX_DESC_FLAG_DMA_FAIL = (1 << 27),
265 RTL818X_RX_DESC_FLAG_LS = (1 << 28),
266 RTL818X_RX_DESC_FLAG_FS = (1 << 29),
267 RTL818X_RX_DESC_FLAG_EOR = (1 << 30),
268 RTL818X_RX_DESC_FLAG_OWN = (1 << 31)
271 struct rtl818x_rx_desc {
278 } __attribute__ ((packed));
280 struct rtl818x_priv {
281 struct rtl818x_csr *map;
282 const struct rtl818x_rf_ops *rf;
283 int rf_flag; /* whatever RF driver wishes to use it for */
287 struct spi_bit_basher spibit;
288 struct spi_device eeprom;
290 struct rtl818x_rx_desc *rx_ring;
292 unsigned int rx_idx; /* next desc to be filled by card */
293 struct io_buffer *rx_buf[RTL818X_RX_RING_SIZE];
295 struct rtl818x_tx_desc *tx_ring;
297 unsigned int tx_cons; /* next desc to be filled by card */
298 unsigned int tx_prod; /* next desc to be filled by driver */
299 struct io_buffer *tx_buf[RTL818X_TX_RING_SIZE];
301 struct pci_device *pdev;
312 void rtl818x_write_phy(struct net80211_device *dev, u8 addr, u32 data);
313 void rtl818x_set_anaparam(struct rtl818x_priv *priv, u32 anaparam);
315 static inline u8 rtl818x_ioread8(struct rtl818x_priv *priv __unused, u8 *addr)
320 static inline u16 rtl818x_ioread16(struct rtl818x_priv *priv __unused, u16 *addr)
325 static inline u32 rtl818x_ioread32(struct rtl818x_priv *priv __unused, u32 *addr)
330 static inline void rtl818x_iowrite8(struct rtl818x_priv *priv __unused,
336 static inline void rtl818x_iowrite16(struct rtl818x_priv *priv __unused,
342 static inline void rtl818x_iowrite32(struct rtl818x_priv *priv __unused,
348 #define RTL818X_RF_DRIVERS __table(struct rtl818x_rf_ops, "rtl818x_rf_drivers")
349 #define __rtl818x_rf_driver __table_entry(RTL818X_RF_DRIVERS, 01)
351 struct rtl818x_rf_ops {
353 u8 id; /* as identified in EEPROM */
354 void (*init)(struct net80211_device *dev);
355 void (*stop)(struct net80211_device *dev);
356 void (*set_chan)(struct net80211_device *dev, struct net80211_channel *chan);
357 void (*conf_erp)(struct net80211_device *dev); /* set based on dev->erp_flags */
360 extern int rtl818x_probe(struct pci_device *pdev );
361 extern void rtl818x_remove(struct pci_device *pdev);
363 #endif /* RTL818X_H */