iPXE
rtl818x.h
Go to the documentation of this file.
00001 /*
00002  * Definitions for RTL818x hardware
00003  *
00004  * Copyright 2007 Michael Wu <flamingice@sourmilk.net>
00005  * Copyright 2007 Andrea Merello <andreamrl@tiscali.it>
00006  *
00007  * Modified for iPXE, June 2009, by Joshua Oreman <oremanj@rwcr.net>
00008  *
00009  * Based on the r8187 driver, which is:
00010  * Copyright 2005 Andrea Merello <andreamrl@tiscali.it>, et al.
00011  *
00012  * This program is free software; you can redistribute it and/or modify
00013  * it under the terms of the GNU General Public License version 2 as
00014  * published by the Free Software Foundation.
00015  */
00016 
00017 #ifndef RTL818X_H
00018 #define RTL818X_H
00019 
00020 #include <ipxe/spi_bit.h>
00021 #include <ipxe/tables.h>
00022 #include <ipxe/net80211.h>
00023 
00024 FILE_LICENCE(GPL2_ONLY);
00025 
00026 struct rtl818x_csr {
00027         u8      MAC[6];
00028         u8      reserved_0[2];
00029         u32     MAR[2];
00030         u8      RX_FIFO_COUNT;
00031         u8      reserved_1;
00032         u8      TX_FIFO_COUNT;
00033         u8      BQREQ;
00034         u8      reserved_2[4];
00035         u32     TSFT[2];
00036         u32     TLPDA;
00037         u32     TNPDA;
00038         u32     THPDA;
00039         u16     BRSR;
00040         u8      BSSID[6];
00041         u8      RESP_RATE;
00042         u8      EIFS;
00043         u8      reserved_3[1];
00044         u8      CMD;
00045 #define RTL818X_CMD_TX_ENABLE           (1 << 2)
00046 #define RTL818X_CMD_RX_ENABLE           (1 << 3)
00047 #define RTL818X_CMD_RESET               (1 << 4)
00048         u8      reserved_4[4];
00049         u16     INT_MASK;
00050         u16     INT_STATUS;
00051 #define RTL818X_INT_RX_OK               (1 <<  0)
00052 #define RTL818X_INT_RX_ERR              (1 <<  1)
00053 #define RTL818X_INT_TXL_OK              (1 <<  2)
00054 #define RTL818X_INT_TXL_ERR             (1 <<  3)
00055 #define RTL818X_INT_RX_DU               (1 <<  4)
00056 #define RTL818X_INT_RX_FO               (1 <<  5)
00057 #define RTL818X_INT_TXN_OK              (1 <<  6)
00058 #define RTL818X_INT_TXN_ERR             (1 <<  7)
00059 #define RTL818X_INT_TXH_OK              (1 <<  8)
00060 #define RTL818X_INT_TXH_ERR             (1 <<  9)
00061 #define RTL818X_INT_TXB_OK              (1 << 10)
00062 #define RTL818X_INT_TXB_ERR             (1 << 11)
00063 #define RTL818X_INT_ATIM                (1 << 12)
00064 #define RTL818X_INT_BEACON              (1 << 13)
00065 #define RTL818X_INT_TIME_OUT            (1 << 14)
00066 #define RTL818X_INT_TX_FO               (1 << 15)
00067         u32     TX_CONF;
00068 #define RTL818X_TX_CONF_LOOPBACK_MAC    (1 << 17)
00069 #define RTL818X_TX_CONF_LOOPBACK_CONT   (3 << 17)
00070 #define RTL818X_TX_CONF_NO_ICV          (1 << 19)
00071 #define RTL818X_TX_CONF_DISCW           (1 << 20)
00072 #define RTL818X_TX_CONF_SAT_HWPLCP      (1 << 24)
00073 #define RTL818X_TX_CONF_R8180_ABCD      (2 << 25)
00074 #define RTL818X_TX_CONF_R8180_F         (3 << 25)
00075 #define RTL818X_TX_CONF_R8185_ABC       (4 << 25)
00076 #define RTL818X_TX_CONF_R8185_D         (5 << 25)
00077 #define RTL818X_TX_CONF_R8187vD         (5 << 25)
00078 #define RTL818X_TX_CONF_R8187vD_B       (6 << 25)
00079 #define RTL818X_TX_CONF_HWVER_MASK      (7 << 25)
00080 #define RTL818X_TX_CONF_DISREQQSIZE     (1 << 28)
00081 #define RTL818X_TX_CONF_PROBE_DTS       (1 << 29)
00082 #define RTL818X_TX_CONF_HW_SEQNUM       (1 << 30)
00083 #define RTL818X_TX_CONF_CW_MIN          (1 << 31)
00084         u32     RX_CONF;
00085 #define RTL818X_RX_CONF_MONITOR         (1 <<  0)
00086 #define RTL818X_RX_CONF_NICMAC          (1 <<  1)
00087 #define RTL818X_RX_CONF_MULTICAST       (1 <<  2)
00088 #define RTL818X_RX_CONF_BROADCAST       (1 <<  3)
00089 #define RTL818X_RX_CONF_FCS             (1 <<  5)
00090 #define RTL818X_RX_CONF_DATA            (1 << 18)
00091 #define RTL818X_RX_CONF_CTRL            (1 << 19)
00092 #define RTL818X_RX_CONF_MGMT            (1 << 20)
00093 #define RTL818X_RX_CONF_ADDR3           (1 << 21)
00094 #define RTL818X_RX_CONF_PM              (1 << 22)
00095 #define RTL818X_RX_CONF_BSSID           (1 << 23)
00096 #define RTL818X_RX_CONF_RX_AUTORESETPHY (1 << 28)
00097 #define RTL818X_RX_CONF_CSDM1           (1 << 29)
00098 #define RTL818X_RX_CONF_CSDM2           (1 << 30)
00099 #define RTL818X_RX_CONF_ONLYERLPKT      (1 << 31)
00100         u32     INT_TIMEOUT;
00101         u32     TBDA;
00102         u8      EEPROM_CMD;
00103 #define RTL818X_EEPROM_CMD_READ         (1 << 0)
00104 #define RTL818X_EEPROM_CMD_WRITE        (1 << 1)
00105 #define RTL818X_EEPROM_CMD_CK           (1 << 2)
00106 #define RTL818X_EEPROM_CMD_CS           (1 << 3)
00107 #define RTL818X_EEPROM_CMD_NORMAL       (0 << 6)
00108 #define RTL818X_EEPROM_CMD_LOAD         (1 << 6)
00109 #define RTL818X_EEPROM_CMD_PROGRAM      (2 << 6)
00110 #define RTL818X_EEPROM_CMD_CONFIG       (3 << 6)
00111         u8      CONFIG0;
00112         u8      CONFIG1;
00113         u8      CONFIG2;
00114 #define RTL818X_CONFIG2_ANTENNA_DIV     (1 << 6)
00115         u32     ANAPARAM;
00116         u8      MSR;
00117 #define RTL818X_MSR_NO_LINK             (0 << 2)
00118 #define RTL818X_MSR_ADHOC               (1 << 2)
00119 #define RTL818X_MSR_INFRA               (2 << 2)
00120 #define RTL818X_MSR_MASTER              (3 << 2)
00121 #define RTL818X_MSR_ENEDCA              (4 << 2)
00122         u8      CONFIG3;
00123 #define RTL818X_CONFIG3_ANAPARAM_WRITE  (1 << 6)
00124 #define RTL818X_CONFIG3_GNT_SELECT      (1 << 7)
00125         u8      CONFIG4;
00126 #define RTL818X_CONFIG4_POWEROFF        (1 << 6)
00127 #define RTL818X_CONFIG4_VCOOFF          (1 << 7)
00128         u8      TESTR;
00129         u8      reserved_9[2];
00130         u8      PGSELECT;
00131         u8      SECURITY;
00132         u32     ANAPARAM2;
00133         u8      reserved_10[12];
00134         u16     BEACON_INTERVAL;
00135         u16     ATIM_WND;
00136         u16     BEACON_INTERVAL_TIME;
00137         u16     ATIMTR_INTERVAL;
00138         u8      PHY_DELAY;
00139         u8      CARRIER_SENSE_COUNTER;
00140         u8      reserved_11[2];
00141         u8      PHY[4];
00142         u16     RFPinsOutput;
00143         u16     RFPinsEnable;
00144         u16     RFPinsSelect;
00145         u16     RFPinsInput;
00146         u32     RF_PARA;
00147         u32     RF_TIMING;
00148         u8      GP_ENABLE;
00149         u8      GPIO;
00150         u8      reserved_12[2];
00151         u32     HSSI_PARA;
00152         u8      reserved_13[4];
00153         u8      TX_AGC_CTL;
00154 #define RTL818X_TX_AGC_CTL_PERPACKET_GAIN_SHIFT         (1 << 0)
00155 #define RTL818X_TX_AGC_CTL_PERPACKET_ANTSEL_SHIFT       (1 << 1)
00156 #define RTL818X_TX_AGC_CTL_FEEDBACK_ANT                 (1 << 2)
00157         u8      TX_GAIN_CCK;
00158         u8      TX_GAIN_OFDM;
00159         u8      TX_ANTENNA;
00160         u8      reserved_14[16];
00161         u8      WPA_CONF;
00162         u8      reserved_15[3];
00163         u8      SIFS;
00164         u8      DIFS;
00165         u8      SLOT;
00166         u8      reserved_16[5];
00167         u8      CW_CONF;
00168 #define RTL818X_CW_CONF_PERPACKET_CW_SHIFT      (1 << 0)
00169 #define RTL818X_CW_CONF_PERPACKET_RETRY_SHIFT   (1 << 1)
00170         u8      CW_VAL;
00171         u8      RATE_FALLBACK;
00172 #define RTL818X_RATE_FALLBACK_ENABLE    (1 << 7)
00173         u8      ACM_CONTROL;
00174         u8      reserved_17[24];
00175         u8      CONFIG5;
00176         u8      TX_DMA_POLLING;
00177         u8      reserved_18[2];
00178         u16     CWR;
00179         u8      RETRY_CTR;
00180         u8      reserved_19[3];
00181         u16     INT_MIG;
00182 /* RTL818X_R8187B_*: magic numbers from ioregisters */
00183 #define RTL818X_R8187B_B        0
00184 #define RTL818X_R8187B_D        1
00185 #define RTL818X_R8187B_E        2
00186         u32     RDSAR;
00187         u16     TID_AC_MAP;
00188         u8      reserved_20[4];
00189         u8      ANAPARAM3;
00190         u8      reserved_21[5];
00191         u16     FEMR;
00192         u8      reserved_22[4];
00193         u16     TALLY_CNT;
00194         u8      TALLY_SEL;
00195 } __attribute__((packed));
00196 
00197 #define MAX_RX_SIZE IEEE80211_MAX_FRAME_LEN
00198 
00199 #define RF_PARAM_ANALOGPHY      (1 << 0)
00200 #define RF_PARAM_ANTBDEFAULT    (1 << 1)
00201 #define RF_PARAM_CARRIERSENSE1  (1 << 2)
00202 #define RF_PARAM_CARRIERSENSE2  (1 << 3)
00203 
00204 #define BB_ANTATTEN_CHAN14      0x0C
00205 #define BB_ANTENNA_B            0x40
00206 
00207 #define BB_HOST_BANG            (1 << 30)
00208 #define BB_HOST_BANG_EN         (1 << 2)
00209 #define BB_HOST_BANG_CLK        (1 << 1)
00210 #define BB_HOST_BANG_DATA       1
00211 
00212 #define ANAPARAM_TXDACOFF_SHIFT 27
00213 #define ANAPARAM_PWR0_SHIFT     28
00214 #define ANAPARAM_PWR0_MASK      (0x07 << ANAPARAM_PWR0_SHIFT)
00215 #define ANAPARAM_PWR1_SHIFT     20
00216 #define ANAPARAM_PWR1_MASK      (0x7F << ANAPARAM_PWR1_SHIFT)
00217 
00218 #define RTL818X_RX_RING_SIZE    8 /* doesn't have to be a power of 2 */
00219 #define RTL818X_TX_RING_SIZE    8 /* nor this [but 2^n is very slightly faster] */
00220 #define RTL818X_RING_ALIGN      256
00221 
00222 #define RTL818X_MAX_RETRIES     4
00223 
00224 enum rtl818x_tx_desc_flags {
00225         RTL818X_TX_DESC_FLAG_NO_ENC     = (1 << 15),
00226         RTL818X_TX_DESC_FLAG_TX_OK      = (1 << 15),
00227         RTL818X_TX_DESC_FLAG_SPLCP      = (1 << 16),
00228         RTL818X_TX_DESC_FLAG_RX_UNDER   = (1 << 16),
00229         RTL818X_TX_DESC_FLAG_MOREFRAG   = (1 << 17),
00230         RTL818X_TX_DESC_FLAG_CTS        = (1 << 18),
00231         RTL818X_TX_DESC_FLAG_RTS        = (1 << 23),
00232         RTL818X_TX_DESC_FLAG_LS         = (1 << 28),
00233         RTL818X_TX_DESC_FLAG_FS         = (1 << 29),
00234         RTL818X_TX_DESC_FLAG_DMA        = (1 << 30),
00235         RTL818X_TX_DESC_FLAG_OWN        = (1 << 31)
00236 };
00237 
00238 struct rtl818x_tx_desc {
00239         u32 flags;
00240         u16 rts_duration;
00241         u16 plcp_len;
00242         u32 tx_buf;
00243         u32 frame_len;
00244         u32 next_tx_desc;
00245         u8 cw;
00246         u8 retry_limit;
00247         u8 agc;
00248         u8 flags2;
00249         u32 reserved[2];
00250 } __attribute__ ((packed));
00251 
00252 enum rtl818x_rx_desc_flags {
00253         RTL818X_RX_DESC_FLAG_ICV_ERR    = (1 << 12),
00254         RTL818X_RX_DESC_FLAG_CRC32_ERR  = (1 << 13),
00255         RTL818X_RX_DESC_FLAG_PM         = (1 << 14),
00256         RTL818X_RX_DESC_FLAG_RX_ERR     = (1 << 15),
00257         RTL818X_RX_DESC_FLAG_BCAST      = (1 << 16),
00258         RTL818X_RX_DESC_FLAG_PAM        = (1 << 17),
00259         RTL818X_RX_DESC_FLAG_MCAST      = (1 << 18),
00260         RTL818X_RX_DESC_FLAG_QOS        = (1 << 19), /* RTL8187(B) only */
00261         RTL818X_RX_DESC_FLAG_TRSW       = (1 << 24), /* RTL8187(B) only */
00262         RTL818X_RX_DESC_FLAG_SPLCP      = (1 << 25),
00263         RTL818X_RX_DESC_FLAG_FOF        = (1 << 26),
00264         RTL818X_RX_DESC_FLAG_DMA_FAIL   = (1 << 27),
00265         RTL818X_RX_DESC_FLAG_LS         = (1 << 28),
00266         RTL818X_RX_DESC_FLAG_FS         = (1 << 29),
00267         RTL818X_RX_DESC_FLAG_EOR        = (1 << 30),
00268         RTL818X_RX_DESC_FLAG_OWN        = (1 << 31)
00269 };
00270 
00271 struct rtl818x_rx_desc {
00272         u32 flags;
00273         u32 flags2;
00274         union {
00275                 u32 rx_buf;
00276                 u64 tsft;
00277         };
00278 } __attribute__ ((packed));
00279 
00280 struct rtl818x_priv {
00281         struct rtl818x_csr *map;
00282         const struct rtl818x_rf_ops *rf;
00283         int rf_flag; /* whatever RF driver wishes to use it for */
00284         int hw_rate;
00285         int hw_rtscts_rate;
00286 
00287         struct spi_bit_basher spibit;
00288         struct spi_device eeprom;
00289 
00290         struct rtl818x_rx_desc *rx_ring;
00291         u32 rx_ring_dma;
00292         unsigned int rx_idx;    /* next desc to be filled by card */
00293         struct io_buffer *rx_buf[RTL818X_RX_RING_SIZE];
00294 
00295         struct rtl818x_tx_desc *tx_ring;
00296         u32 tx_ring_dma;
00297         unsigned int tx_cons;   /* next desc to be filled by card */
00298         unsigned int tx_prod;   /* next desc to be filled by driver */
00299         struct io_buffer *tx_buf[RTL818X_TX_RING_SIZE];
00300 
00301         struct pci_device *pdev;
00302         u32 rx_conf;
00303 
00304         u16 txpower[14];
00305 
00306         int r8185;
00307         u32 anaparam;
00308         u16 rfparam;
00309         u8 csthreshold;
00310 };
00311 
00312 void rtl818x_write_phy(struct net80211_device *dev, u8 addr, u32 data);
00313 void rtl818x_set_anaparam(struct rtl818x_priv *priv, u32 anaparam);
00314 
00315 static inline u8 rtl818x_ioread8(struct rtl818x_priv *priv __unused, u8 *addr)
00316 {
00317         return inb(addr);
00318 }
00319 
00320 static inline u16 rtl818x_ioread16(struct rtl818x_priv *priv __unused, u16 *addr)
00321 {
00322         return inw(addr);
00323 }
00324 
00325 static inline u32 rtl818x_ioread32(struct rtl818x_priv *priv __unused, u32 *addr)
00326 {
00327         return inl(addr);
00328 }
00329 
00330 static inline void rtl818x_iowrite8(struct rtl818x_priv *priv __unused,
00331                                     u8 *addr, u8 val)
00332 {
00333         outb(val, addr);
00334 }
00335 
00336 static inline void rtl818x_iowrite16(struct rtl818x_priv *priv __unused,
00337                                      u16 *addr, u16 val)
00338 {
00339         outw(val, addr);
00340 }
00341 
00342 static inline void rtl818x_iowrite32(struct rtl818x_priv *priv __unused,
00343                                      u32 *addr, u32 val)
00344 {
00345         outl(val, addr);
00346 }
00347 
00348 #define RTL818X_RF_DRIVERS __table(struct rtl818x_rf_ops, "rtl818x_rf_drivers")
00349 #define __rtl818x_rf_driver __table_entry(RTL818X_RF_DRIVERS, 01)
00350 
00351 struct rtl818x_rf_ops {
00352         char *name;
00353         u8 id;                  /* as identified in EEPROM */
00354         void (*init)(struct net80211_device *dev);
00355         void (*stop)(struct net80211_device *dev);
00356         void (*set_chan)(struct net80211_device *dev, struct net80211_channel *chan);
00357         void (*conf_erp)(struct net80211_device *dev); /* set based on dev->erp_flags */
00358 };
00359 
00360 extern int rtl818x_probe(struct pci_device *pdev );
00361 extern void rtl818x_remove(struct pci_device *pdev);
00362 
00363 #endif /* RTL818X_H */