blob: a6ad79f61bf9bc026328c8be87414a5a7ef223d8 [file] [log] [blame]
John W. Linville0aec00a2007-06-12 22:11:42 -04001/*
2 * Definitions for RTL8187 hardware
3 *
4 * Copyright 2007 Michael Wu <flamingice@sourmilk.net>
Andrea Merello93ba2a82013-08-26 13:53:30 +02005 * Copyright 2007 Andrea Merello <andrea.merello@gmail.com>
John W. Linville0aec00a2007-06-12 22:11:42 -04006 *
7 * Based on the r8187 driver, which is:
Andrea Merello93ba2a82013-08-26 13:53:30 +02008 * Copyright 2005 Andrea Merello <andrea.merello@gmail.com>, et al.
John W. Linville0aec00a2007-06-12 22:11:42 -04009 *
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License version 2 as
12 * published by the Free Software Foundation.
13 */
14
Michael Wu605bebe2007-05-14 01:41:02 -040015#ifndef RTL8187_H
16#define RTL8187_H
17
Stanislaw Gruszkab6213e42014-02-10 22:38:28 +010018#include <linux/cache.h>
19
Michael Wu605bebe2007-05-14 01:41:02 -040020#include "rtl818x.h"
John W. Linville3cfeb0c2010-12-20 15:16:53 -050021#include "leds.h"
Michael Wu605bebe2007-05-14 01:41:02 -040022
23#define RTL8187_EEPROM_TXPWR_BASE 0x05
24#define RTL8187_EEPROM_MAC_ADDR 0x07
25#define RTL8187_EEPROM_TXPWR_CHAN_1 0x16 /* 3 channels */
26#define RTL8187_EEPROM_TXPWR_CHAN_6 0x1B /* 2 channels */
27#define RTL8187_EEPROM_TXPWR_CHAN_4 0x3D /* 2 channels */
Larry Finger70d57132009-12-05 19:25:22 -060028#define RTL8187_EEPROM_SELECT_GPIO 0x3B
Michael Wu605bebe2007-05-14 01:41:02 -040029
30#define RTL8187_REQT_READ 0xC0
31#define RTL8187_REQT_WRITE 0x40
32#define RTL8187_REQ_GET_REG 0x05
33#define RTL8187_REQ_SET_REG 0x05
34
35#define RTL8187_MAX_RX 0x9C4
36
Larry Finger70d57132009-12-05 19:25:22 -060037#define RFKILL_MASK_8187_89_97 0x2
38#define RFKILL_MASK_8198 0x4
39
Larry Finger6410db52011-02-28 23:36:09 -060040#define RETRY_COUNT 7
41
Michael Wu605bebe2007-05-14 01:41:02 -040042struct rtl8187_rx_info {
43 struct urb *urb;
44 struct ieee80211_hw *dev;
45};
46
47struct rtl8187_rx_hdr {
Johannes Berg4150c572007-09-17 01:29:23 -040048 __le32 flags;
Michael Wu605bebe2007-05-14 01:41:02 -040049 u8 noise;
50 u8 signal;
51 u8 agc;
52 u8 reserved;
53 __le64 mac_time;
Eric Dumazetba2d3582010-06-02 18:10:09 +000054} __packed;
Michael Wu605bebe2007-05-14 01:41:02 -040055
Hin-Tak Leungc44ac0b2008-07-08 12:27:54 +010056struct rtl8187b_rx_hdr {
Michael Wu605bebe2007-05-14 01:41:02 -040057 __le32 flags;
Hin-Tak Leungc44ac0b2008-07-08 12:27:54 +010058 __le64 mac_time;
Larry Finger0ccd58f2008-07-28 22:25:08 -050059 u8 sq;
60 u8 rssi;
Hin-Tak Leungc44ac0b2008-07-08 12:27:54 +010061 u8 agc;
Larry Finger0ccd58f2008-07-28 22:25:08 -050062 u8 flags2;
63 __le16 snr_long2end;
64 s8 pwdb_g12;
65 u8 fot;
Eric Dumazetba2d3582010-06-02 18:10:09 +000066} __packed;
Hin-Tak Leungc44ac0b2008-07-08 12:27:54 +010067
68/* {rtl8187,rtl8187b}_tx_info is in skb */
69
Hin-Tak Leungc44ac0b2008-07-08 12:27:54 +010070struct rtl8187_tx_hdr {
71 __le32 flags;
Michael Wu605bebe2007-05-14 01:41:02 -040072 __le16 rts_duration;
73 __le16 len;
74 __le32 retry;
Eric Dumazetba2d3582010-06-02 18:10:09 +000075} __packed;
Michael Wu605bebe2007-05-14 01:41:02 -040076
Hin-Tak Leungc44ac0b2008-07-08 12:27:54 +010077struct rtl8187b_tx_hdr {
78 __le32 flags;
79 __le16 rts_duration;
80 __le16 len;
81 __le32 unused_1;
82 __le16 unused_2;
83 __le16 tx_duration;
84 __le32 unused_3;
85 __le32 retry;
86 __le32 unused_4[2];
Eric Dumazetba2d3582010-06-02 18:10:09 +000087} __packed;
Hin-Tak Leungc44ac0b2008-07-08 12:27:54 +010088
89enum {
90 DEVICE_RTL8187,
91 DEVICE_RTL8187B
92};
93
Attila Fazekas41b58f12012-02-23 19:50:35 +010094struct rtl8187_vif {
95 struct ieee80211_hw *dev;
96
97 /* beaconing */
98 struct delayed_work beacon_work;
99 bool enable_beacon;
100};
101
Michael Wu605bebe2007-05-14 01:41:02 -0400102struct rtl8187_priv {
103 /* common between rtl818x drivers */
104 struct rtl818x_csr *map;
Michael Wuf6532112007-10-14 14:43:16 -0400105 const struct rtl818x_rf_ops *rf;
Johannes Berg32bfd352007-12-19 01:31:26 +0100106 struct ieee80211_vif *vif;
John W. Linvilled30506e2009-12-22 18:13:05 -0500107
Larry Finger7dcdd072008-07-31 19:30:48 -0500108 /* The mutex protects the TX loopback state.
109 * Any attempt to set channels concurrently locks the device.
110 */
111 struct mutex conf_mutex;
Michael Wu605bebe2007-05-14 01:41:02 -0400112
113 /* rtl8187 specific */
114 struct ieee80211_channel channels[14];
115 struct ieee80211_rate rates[12];
Johannes Berg8318d782008-01-24 19:38:38 +0100116 struct ieee80211_supported_band band;
Michael Wu605bebe2007-05-14 01:41:02 -0400117 struct usb_device *udev;
Johannes Berg4150c572007-09-17 01:29:23 -0400118 u32 rx_conf;
Larry Fingerc1db52b2008-12-09 23:34:27 -0600119 struct usb_anchor anchored;
Larry Finger2f476902009-01-23 11:40:22 -0600120 struct delayed_work work;
121 struct ieee80211_hw *dev;
Larry Fingera0270872009-04-16 19:56:38 -0500122#ifdef CONFIG_RTL8187_LEDS
Herton Ronaldo Krzesinski49d75902009-12-09 14:56:13 -0200123 struct rtl8187_led led_radio;
Larry Fingera0270872009-04-16 19:56:38 -0500124 struct rtl8187_led led_tx;
125 struct rtl8187_led led_rx;
126 struct delayed_work led_on;
127 struct delayed_work led_off;
128#endif
Michael Wu605bebe2007-05-14 01:41:02 -0400129 u16 txpwr_base;
130 u8 asic_rev;
Hin-Tak Leungc44ac0b2008-07-08 12:27:54 +0100131 u8 is_rtl8187b;
132 enum {
133 RTL8187BvB,
134 RTL8187BvD,
135 RTL8187BvE
136 } hw_rev;
Michael Wu605bebe2007-05-14 01:41:02 -0400137 struct sk_buff_head rx_queue;
Hin-Tak Leungc44ac0b2008-07-08 12:27:54 +0100138 u8 signal;
Hin-Tak Leungc44ac0b2008-07-08 12:27:54 +0100139 u8 noise;
Herton Ronaldo Krzesinskib4572a92008-11-13 10:39:15 -0500140 u8 slot_time;
141 u8 aifsn[4];
Larry Finger70d57132009-12-05 19:25:22 -0600142 u8 rfkill_mask;
Herton Ronaldo Krzesinski3517afd2008-11-13 10:39:16 -0500143 struct {
Stanislaw Gruszkab6213e42014-02-10 22:38:28 +0100144 union {
145 __le64 buf;
146 u8 dummy1[L1_CACHE_BYTES];
147 } ____cacheline_aligned;
Herton Ronaldo Krzesinski3517afd2008-11-13 10:39:16 -0500148 struct sk_buff_head queue;
Larry Finger2f476902009-01-23 11:40:22 -0600149 } b_tx_status; /* This queue is used by both -b and non-b devices */
John W. Linville9be6f0d2009-05-06 13:57:27 -0400150 struct mutex io_mutex;
151 union {
152 u8 bits8;
153 __le16 bits16;
154 __le32 bits32;
Stanislaw Gruszkab6213e42014-02-10 22:38:28 +0100155 u8 dummy2[L1_CACHE_BYTES];
156 } *io_dmabuf ____cacheline_aligned;
Herton Ronaldo Krzesinskica9152e2009-08-26 13:54:09 -0300157 bool rfkill_off;
Attila Fazekas41b58f12012-02-23 19:50:35 +0100158 u16 seqno;
Michael Wu605bebe2007-05-14 01:41:02 -0400159};
160
161void rtl8187_write_phy(struct ieee80211_hw *dev, u8 addr, u32 data);
162
Hin-Tak Leungc44ac0b2008-07-08 12:27:54 +0100163static inline u8 rtl818x_ioread8_idx(struct rtl8187_priv *priv,
164 u8 *addr, u8 idx)
Michael Wu605bebe2007-05-14 01:41:02 -0400165{
166 u8 val;
167
John W. Linville9be6f0d2009-05-06 13:57:27 -0400168 mutex_lock(&priv->io_mutex);
Michael Wu605bebe2007-05-14 01:41:02 -0400169 usb_control_msg(priv->udev, usb_rcvctrlpipe(priv->udev, 0),
170 RTL8187_REQ_GET_REG, RTL8187_REQT_READ,
John W. Linville9be6f0d2009-05-06 13:57:27 -0400171 (unsigned long)addr, idx & 0x03,
172 &priv->io_dmabuf->bits8, sizeof(val), HZ / 2);
173
174 val = priv->io_dmabuf->bits8;
175 mutex_unlock(&priv->io_mutex);
Michael Wu605bebe2007-05-14 01:41:02 -0400176
177 return val;
178}
179
Hin-Tak Leungc44ac0b2008-07-08 12:27:54 +0100180static inline u8 rtl818x_ioread8(struct rtl8187_priv *priv, u8 *addr)
181{
182 return rtl818x_ioread8_idx(priv, addr, 0);
183}
184
185static inline u16 rtl818x_ioread16_idx(struct rtl8187_priv *priv,
186 __le16 *addr, u8 idx)
Michael Wu605bebe2007-05-14 01:41:02 -0400187{
188 __le16 val;
189
John W. Linville9be6f0d2009-05-06 13:57:27 -0400190 mutex_lock(&priv->io_mutex);
Michael Wu605bebe2007-05-14 01:41:02 -0400191 usb_control_msg(priv->udev, usb_rcvctrlpipe(priv->udev, 0),
192 RTL8187_REQ_GET_REG, RTL8187_REQT_READ,
John W. Linville9be6f0d2009-05-06 13:57:27 -0400193 (unsigned long)addr, idx & 0x03,
194 &priv->io_dmabuf->bits16, sizeof(val), HZ / 2);
195
196 val = priv->io_dmabuf->bits16;
197 mutex_unlock(&priv->io_mutex);
Michael Wu605bebe2007-05-14 01:41:02 -0400198
199 return le16_to_cpu(val);
200}
201
Hin-Tak Leungc44ac0b2008-07-08 12:27:54 +0100202static inline u16 rtl818x_ioread16(struct rtl8187_priv *priv, __le16 *addr)
203{
204 return rtl818x_ioread16_idx(priv, addr, 0);
205}
206
207static inline u32 rtl818x_ioread32_idx(struct rtl8187_priv *priv,
208 __le32 *addr, u8 idx)
Michael Wu605bebe2007-05-14 01:41:02 -0400209{
210 __le32 val;
211
John W. Linville9be6f0d2009-05-06 13:57:27 -0400212 mutex_lock(&priv->io_mutex);
Michael Wu605bebe2007-05-14 01:41:02 -0400213 usb_control_msg(priv->udev, usb_rcvctrlpipe(priv->udev, 0),
214 RTL8187_REQ_GET_REG, RTL8187_REQT_READ,
John W. Linville9be6f0d2009-05-06 13:57:27 -0400215 (unsigned long)addr, idx & 0x03,
216 &priv->io_dmabuf->bits32, sizeof(val), HZ / 2);
217
218 val = priv->io_dmabuf->bits32;
219 mutex_unlock(&priv->io_mutex);
Michael Wu605bebe2007-05-14 01:41:02 -0400220
221 return le32_to_cpu(val);
222}
223
Hin-Tak Leungc44ac0b2008-07-08 12:27:54 +0100224static inline u32 rtl818x_ioread32(struct rtl8187_priv *priv, __le32 *addr)
225{
226 return rtl818x_ioread32_idx(priv, addr, 0);
227}
228
229static inline void rtl818x_iowrite8_idx(struct rtl8187_priv *priv,
230 u8 *addr, u8 val, u8 idx)
Michael Wu605bebe2007-05-14 01:41:02 -0400231{
John W. Linville9be6f0d2009-05-06 13:57:27 -0400232 mutex_lock(&priv->io_mutex);
233
234 priv->io_dmabuf->bits8 = val;
Michael Wu605bebe2007-05-14 01:41:02 -0400235 usb_control_msg(priv->udev, usb_sndctrlpipe(priv->udev, 0),
236 RTL8187_REQ_SET_REG, RTL8187_REQT_WRITE,
John W. Linville9be6f0d2009-05-06 13:57:27 -0400237 (unsigned long)addr, idx & 0x03,
238 &priv->io_dmabuf->bits8, sizeof(val), HZ / 2);
239
240 mutex_unlock(&priv->io_mutex);
Michael Wu605bebe2007-05-14 01:41:02 -0400241}
242
Hin-Tak Leungc44ac0b2008-07-08 12:27:54 +0100243static inline void rtl818x_iowrite8(struct rtl8187_priv *priv, u8 *addr, u8 val)
244{
245 rtl818x_iowrite8_idx(priv, addr, val, 0);
246}
247
248static inline void rtl818x_iowrite16_idx(struct rtl8187_priv *priv,
249 __le16 *addr, u16 val, u8 idx)
Michael Wu605bebe2007-05-14 01:41:02 -0400250{
John W. Linville9be6f0d2009-05-06 13:57:27 -0400251 mutex_lock(&priv->io_mutex);
Michael Wu605bebe2007-05-14 01:41:02 -0400252
John W. Linville9be6f0d2009-05-06 13:57:27 -0400253 priv->io_dmabuf->bits16 = cpu_to_le16(val);
Michael Wu605bebe2007-05-14 01:41:02 -0400254 usb_control_msg(priv->udev, usb_sndctrlpipe(priv->udev, 0),
255 RTL8187_REQ_SET_REG, RTL8187_REQT_WRITE,
John W. Linville9be6f0d2009-05-06 13:57:27 -0400256 (unsigned long)addr, idx & 0x03,
257 &priv->io_dmabuf->bits16, sizeof(val), HZ / 2);
258
259 mutex_unlock(&priv->io_mutex);
Michael Wu605bebe2007-05-14 01:41:02 -0400260}
261
Hin-Tak Leungc44ac0b2008-07-08 12:27:54 +0100262static inline void rtl818x_iowrite16(struct rtl8187_priv *priv, __le16 *addr,
263 u16 val)
264{
265 rtl818x_iowrite16_idx(priv, addr, val, 0);
266}
267
268static inline void rtl818x_iowrite32_idx(struct rtl8187_priv *priv,
269 __le32 *addr, u32 val, u8 idx)
Michael Wu605bebe2007-05-14 01:41:02 -0400270{
John W. Linville9be6f0d2009-05-06 13:57:27 -0400271 mutex_lock(&priv->io_mutex);
Michael Wu605bebe2007-05-14 01:41:02 -0400272
John W. Linville9be6f0d2009-05-06 13:57:27 -0400273 priv->io_dmabuf->bits32 = cpu_to_le32(val);
Michael Wu605bebe2007-05-14 01:41:02 -0400274 usb_control_msg(priv->udev, usb_sndctrlpipe(priv->udev, 0),
275 RTL8187_REQ_SET_REG, RTL8187_REQT_WRITE,
John W. Linville9be6f0d2009-05-06 13:57:27 -0400276 (unsigned long)addr, idx & 0x03,
277 &priv->io_dmabuf->bits32, sizeof(val), HZ / 2);
278
279 mutex_unlock(&priv->io_mutex);
Hin-Tak Leungc44ac0b2008-07-08 12:27:54 +0100280}
281
282static inline void rtl818x_iowrite32(struct rtl8187_priv *priv, __le32 *addr,
283 u32 val)
284{
285 rtl818x_iowrite32_idx(priv, addr, val, 0);
Michael Wu605bebe2007-05-14 01:41:02 -0400286}
287
288#endif /* RTL8187_H */