1 /* SPDX-License-Identifier: GPL-2.0 */
2 #ifndef RTL8180_H
3 #define RTL8180_H
4
5 #include "rtl818x.h"
6
7 #define MAX_RX_SIZE IEEE80211_MAX_RTS_THRESHOLD
8
9 #define RF_PARAM_ANALOGPHY (1 << 0)
10 #define RF_PARAM_ANTBDEFAULT (1 << 1)
11 #define RF_PARAM_CARRIERSENSE1 (1 << 2)
12 #define RF_PARAM_CARRIERSENSE2 (1 << 3)
13
14 #define BB_ANTATTEN_CHAN14 0x0C
15 #define BB_ANTENNA_B 0x40
16
17 #define BB_HOST_BANG (1 << 30)
18 #define BB_HOST_BANG_EN (1 << 2)
19 #define BB_HOST_BANG_CLK (1 << 1)
20 #define BB_HOST_BANG_DATA 1
21
22 #define ANAPARAM_TXDACOFF_SHIFT 27
23 #define ANAPARAM_PWR0_SHIFT 28
24 #define ANAPARAM_PWR0_MASK (0x07 << ANAPARAM_PWR0_SHIFT)
25 #define ANAPARAM_PWR1_SHIFT 20
26 #define ANAPARAM_PWR1_MASK (0x7F << ANAPARAM_PWR1_SHIFT)
27
28 /* rtl8180/rtl8185 have 3 queue + beacon queue.
29 * mac80211 can use just one, + beacon = 2 tot.
30 */
31 #define RTL8180_NR_TX_QUEUES 2
32
33 /* rtl8187SE have 6 queues + beacon queues
34 * mac80211 can use 4 QoS data queue, + beacon = 5 tot
35 */
36 #define RTL8187SE_NR_TX_QUEUES 5
37
38 /* for array static allocation, it is the max of above */
39 #define RTL818X_NR_TX_QUEUES 5
40
41 struct rtl8180_tx_desc {
42 __le32 flags;
43 __le16 rts_duration;
44 __le16 plcp_len;
45 __le32 tx_buf;
46 union{
47 __le32 frame_len;
48 struct {
49 __le16 frame_len_se;
50 __le16 frame_duration;
51 } __packed;
52 } __packed;
53 __le32 next_tx_desc;
54 u8 cw;
55 u8 retry_limit;
56 u8 agc;
57 u8 flags2;
58 /* rsvd for 8180/8185.
59 * valid for 8187se but we dont use it
60 */
61 u32 reserved;
62 /* all rsvd for 8180/8185 */
63 __le16 flags3;
64 __le16 frag_qsize;
65 } __packed;
66
67 struct rtl818x_rx_cmd_desc {
68 __le32 flags;
69 u32 reserved;
70 __le32 rx_buf;
71 } __packed;
72
73 struct rtl8180_rx_desc {
74 __le32 flags;
75 __le32 flags2;
76 __le64 tsft;
77
78 } __packed;
79
80 struct rtl8187se_rx_desc {
81 __le32 flags;
82 __le64 tsft;
83 __le32 flags2;
84 __le32 flags3;
85 u32 reserved[3];
86 } __packed;
87
88 struct rtl8180_tx_ring {
89 struct rtl8180_tx_desc *desc;
90 dma_addr_t dma;
91 unsigned int idx;
92 unsigned int entries;
93 struct sk_buff_head queue;
94 };
95
96 struct rtl8180_vif {
97 struct ieee80211_hw *dev;
98
99 /* beaconing */
100 struct delayed_work beacon_work;
101 bool enable_beacon;
102 };
103
104 struct rtl8180_priv {
105 /* common between rtl818x drivers */
106 struct rtl818x_csr __iomem *map;
107 const struct rtl818x_rf_ops *rf;
108 struct ieee80211_vif *vif;
109
110 /* rtl8180 driver specific */
111 bool map_pio;
112 spinlock_t lock;
113 void *rx_ring;
114 u8 rx_ring_sz;
115 dma_addr_t rx_ring_dma;
116 unsigned int rx_idx;
117 struct sk_buff *rx_buf[32];
118 struct rtl8180_tx_ring tx_ring[RTL818X_NR_TX_QUEUES];
119 struct ieee80211_channel channels[14];
120 struct ieee80211_rate rates[12];
121 struct ieee80211_supported_band band;
122 struct ieee80211_tx_queue_params queue_param[4];
123 struct pci_dev *pdev;
124 u32 rx_conf;
125 u8 slot_time;
126 u16 ack_time;
127
128 enum {
129 RTL818X_CHIP_FAMILY_RTL8180,
130 RTL818X_CHIP_FAMILY_RTL8185,
131 RTL818X_CHIP_FAMILY_RTL8187SE,
132 } chip_family;
133 u32 anaparam;
134 u16 rfparam;
135 u8 csthreshold;
136 u8 mac_addr[ETH_ALEN];
137 u8 rf_type;
138 u8 xtal_out;
139 u8 xtal_in;
140 u8 xtal_cal;
141 u8 thermal_meter_val;
142 u8 thermal_meter_en;
143 u8 antenna_diversity_en;
144 u8 antenna_diversity_default;
145 /* sequence # */
146 u16 seqno;
147 };
148
149 void rtl8180_write_phy(struct ieee80211_hw *dev, u8 addr, u32 data);
150 void rtl8180_set_anaparam(struct rtl8180_priv *priv, u32 anaparam);
151 void rtl8180_set_anaparam2(struct rtl8180_priv *priv, u32 anaparam2);
152
rtl818x_ioread8(struct rtl8180_priv * priv,u8 __iomem * addr)153 static inline u8 rtl818x_ioread8(struct rtl8180_priv *priv, u8 __iomem *addr)
154 {
155 return ioread8(addr);
156 }
157
rtl818x_ioread16(struct rtl8180_priv * priv,__le16 __iomem * addr)158 static inline u16 rtl818x_ioread16(struct rtl8180_priv *priv, __le16 __iomem *addr)
159 {
160 return ioread16(addr);
161 }
162
rtl818x_ioread32(struct rtl8180_priv * priv,__le32 __iomem * addr)163 static inline u32 rtl818x_ioread32(struct rtl8180_priv *priv, __le32 __iomem *addr)
164 {
165 return ioread32(addr);
166 }
167
rtl818x_iowrite8(struct rtl8180_priv * priv,u8 __iomem * addr,u8 val)168 static inline void rtl818x_iowrite8(struct rtl8180_priv *priv,
169 u8 __iomem *addr, u8 val)
170 {
171 iowrite8(val, addr);
172 }
173
rtl818x_iowrite16(struct rtl8180_priv * priv,__le16 __iomem * addr,u16 val)174 static inline void rtl818x_iowrite16(struct rtl8180_priv *priv,
175 __le16 __iomem *addr, u16 val)
176 {
177 iowrite16(val, addr);
178 }
179
rtl818x_iowrite32(struct rtl8180_priv * priv,__le32 __iomem * addr,u32 val)180 static inline void rtl818x_iowrite32(struct rtl8180_priv *priv,
181 __le32 __iomem *addr, u32 val)
182 {
183 iowrite32(val, addr);
184 }
185
186 #endif /* RTL8180_H */
187