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

Generated on Tue Apr 6 20:01:03 2010 for gPXE by  doxygen 1.5.7.1