iPXE
Macros | Functions | Variables
rtl818x.c File Reference
#include <stdint.h>
#include <string.h>
#include <errno.h>
#include <stdio.h>
#include <unistd.h>
#include <byteswap.h>
#include <ipxe/iobuf.h>
#include <ipxe/malloc.h>
#include <ipxe/pci.h>
#include <ipxe/net80211.h>
#include <ipxe/netdevice.h>
#include <ipxe/threewire.h>
#include "rtl818x.h"

Go to the source code of this file.

Macros

#define RTL818X_NR_B_RATES   4
 
#define RTL818X_NR_RATES   12
 
#define DIV_ROUND_UP(n, d)   (((n)+(d)-1)/(d))
 

Functions

 FILE_LICENCE (GPL2_ONLY)
 
 FILE_SECBOOT (FORBIDDEN)
 
void rtl818x_write_phy (struct net80211_device *dev, u8 addr, u32 data)
 
static void rtl818x_handle_rx (struct net80211_device *dev)
 
static void rtl818x_handle_tx (struct net80211_device *dev)
 
static void rtl818x_poll (struct net80211_device *dev)
 
static int rtl818x_tx (struct net80211_device *dev, struct io_buffer *iob)
 
void rtl818x_set_anaparam (struct rtl818x_priv *priv, u32 anaparam)
 
static int rtl818x_init_hw (struct net80211_device *dev)
 
static int rtl818x_init_rx_ring (struct net80211_device *dev)
 
static void rtl818x_free_rx_ring (struct net80211_device *dev)
 
static int rtl818x_init_tx_ring (struct net80211_device *dev)
 
static void rtl818x_free_tx_ring (struct net80211_device *dev)
 
static void rtl818x_irq (struct net80211_device *dev, int enable)
 
static void rtl818x_set_hwaddr (struct net80211_device *dev, u8 *hwaddr)
 
static int rtl818x_start (struct net80211_device *dev)
 
static void rtl818x_stop (struct net80211_device *dev)
 
static int rtl818x_config (struct net80211_device *dev, int changed)
 
static int rtl818x_spi_read_bit (struct bit_basher *basher, unsigned int bit_id)
 
static void rtl818x_spi_write_bit (struct bit_basher *basher, unsigned int bit_id, unsigned long data)
 
int rtl818x_probe (struct pci_device *pdev)
 
void rtl818x_remove (struct pci_device *pdev)
 

Variables

static const u16 rtl818x_rates []
 
static const u8 rtl818x_eeprom_bits []
 
static struct bit_basher_operations rtl818x_basher_ops
 
struct net80211_device_operations rtl818x_operations
 

Macro Definition Documentation

◆ RTL818X_NR_B_RATES

#define RTL818X_NR_B_RATES   4

Definition at line 44 of file rtl818x.c.

◆ RTL818X_NR_RATES

#define RTL818X_NR_RATES   12

Definition at line 45 of file rtl818x.c.

◆ DIV_ROUND_UP

#define DIV_ROUND_UP (   n,
 
)    (((n)+(d)-1)/(d))

Definition at line 163 of file rtl818x.c.

Function Documentation

◆ FILE_LICENCE()

FILE_LICENCE ( GPL2_ONLY  )

◆ FILE_SECBOOT()

FILE_SECBOOT ( FORBIDDEN  )

◆ rtl818x_write_phy()

void rtl818x_write_phy ( struct net80211_device dev,
u8  addr,
u32  data 
)

Definition at line 48 of file rtl818x.c.

49 {
50  struct rtl818x_priv *priv = dev->priv;
51  int i = 10;
52  u32 buf;
53 
54  buf = (data << 8) | addr;
55 
56  rtl818x_iowrite32(priv, (u32 *)&priv->map->PHY[0], buf | 0x80);
57  while (i--) {
58  rtl818x_iowrite32(priv, (u32 *)&priv->map->PHY[0], buf);
59  if (rtl818x_ioread8(priv, &priv->map->PHY[2]) == (data & 0xFF))
60  return;
61  }
62 }
static u8 rtl818x_ioread8(struct rtl818x_priv *priv __unused, u8 *addr)
Definition: rtl818x.h:316
static void rtl818x_iowrite32(struct rtl818x_priv *priv __unused, u32 *addr, u32 val)
Definition: rtl818x.h:343
void * priv
Driver private data.
Definition: net80211.h:798
uint32_t addr
Buffer address.
Definition: dwmac.h:20
static struct tlan_private * priv
Definition: tlan.c:225
uint8_t data[48]
Additional event data.
Definition: ena.h:22
uint32_t u32
Definition: stdint.h:24

References addr, data, priv, net80211_device::priv, rtl818x_ioread8(), and rtl818x_iowrite32().

Referenced by grf5101_rf_init(), grf5101_write_phy_antenna(), max2820_rf_init(), max2820_rf_set_channel(), max2820_rf_stop(), max2820_write_phy_antenna(), rtl8225_write_phy_cck(), rtl8225_write_phy_ofdm(), sa2400_rf_init(), and sa2400_write_phy_antenna().

◆ rtl818x_handle_rx()

static void rtl818x_handle_rx ( struct net80211_device dev)
static

Definition at line 64 of file rtl818x.c.

65 {
66  struct rtl818x_priv *priv = dev->priv;
67  unsigned int count = RTL818X_RX_RING_SIZE;
68 
69  while (count--) {
70  struct rtl818x_rx_desc *entry = &priv->rx_ring[priv->rx_idx];
71  struct io_buffer *iob = priv->rx_buf[priv->rx_idx];
72  u32 flags = le32_to_cpu(entry->flags);
73 
75  return;
76 
80  /* This is crappy hardware. The Linux driver
81  doesn't even log these. */
82  goto done;
84  /* This is actually a corrupt packet. */
85  DBG2("rtl818x RX:%d CRC fail: flags %08x\n",
86  priv->rx_idx, flags);
87  net80211_rx_err(dev, NULL, EIO);
88  } else {
89  u32 flags2 = le32_to_cpu(entry->flags2);
90  struct io_buffer *new_iob = alloc_iob(MAX_RX_SIZE);
91  if (!new_iob) {
93  goto done;
94  }
95 
96  DBGP("rtl818x RX:%d success: flags %08x %08x\n",
97  priv->rx_idx, flags, flags2);
98 
99  iob_put(iob, flags & 0xFFF);
100 
101  net80211_rx(dev, iob, (flags2 >> 8) & 0x7f,
102  rtl818x_rates[(flags >> 20) & 0xf]);
103 
104  iob = new_iob;
105  priv->rx_buf[priv->rx_idx] = iob;
106  }
107 
108  done:
109  entry->rx_buf = cpu_to_le32(virt_to_bus(iob->data));
111 
112  if (priv->rx_idx == RTL818X_RX_RING_SIZE - 1)
114 
115  priv->rx_idx = (priv->rx_idx + 1) % RTL818X_RX_RING_SIZE;
116  }
117 }
#define iob_put(iobuf, len)
Definition: iobuf.h:125
#define le32_to_cpu(value)
Definition: byteswap.h:114
void net80211_rx_err(struct net80211_device *dev, struct io_buffer *iob, int rc)
Indicate an error in receiving a packet.
Definition: net80211.c:2789
void net80211_rx(struct net80211_device *dev, struct io_buffer *iob, int signal, u16 rate)
Handle receipt of 802.11 frame.
Definition: net80211.c:2690
static const u16 rtl818x_rates[]
Definition: rtl818x.c:39
struct io_buffer * alloc_iob(size_t len)
Allocate I/O buffer.
Definition: iobuf.c:131
#define ENOMEM
Not enough space.
Definition: errno.h:535
static __always_inline unsigned long virt_to_bus(volatile const void *addr)
Convert virtual address to a bus address.
Definition: io.h:184
#define DBGP(...)
Definition: compiler.h:532
static unsigned int count
Number of entries.
Definition: dwmac.h:225
#define cpu_to_le32(value)
Definition: byteswap.h:108
void * priv
Driver private data.
Definition: net80211.h:798
uint8_t flags
Flags.
Definition: ena.h:18
#define RTL818X_RX_RING_SIZE
Definition: rtl818x.h:219
static struct tlan_private * priv
Definition: tlan.c:225
#define MAX_RX_SIZE
Definition: rtl818x.h:198
void * data
Start of data.
Definition: iobuf.h:53
#define EIO
Input/output error.
Definition: errno.h:434
#define NULL
NULL pointer (VOID *)
Definition: Base.h:322
struct bofm_section_header done
Definition: bofm_test.c:46
uint32_t u32
Definition: stdint.h:24
#define DBG2(...)
Definition: compiler.h:515
A persistent I/O buffer.
Definition: iobuf.h:38

References alloc_iob(), count, cpu_to_le32, io_buffer::data, DBG2, DBGP, done, EIO, ENOMEM, flags, rtl818x_rx_desc::flags, rtl818x_rx_desc::flags2, iob_put, le32_to_cpu, MAX_RX_SIZE, net80211_rx(), net80211_rx_err(), NULL, priv, net80211_device::priv, rtl818x_rates, RTL818X_RX_DESC_FLAG_CRC32_ERR, RTL818X_RX_DESC_FLAG_DMA_FAIL, RTL818X_RX_DESC_FLAG_EOR, RTL818X_RX_DESC_FLAG_FOF, RTL818X_RX_DESC_FLAG_OWN, RTL818X_RX_DESC_FLAG_RX_ERR, RTL818X_RX_RING_SIZE, rtl818x_rx_desc::rx_buf, and virt_to_bus().

Referenced by rtl818x_poll().

◆ rtl818x_handle_tx()

static void rtl818x_handle_tx ( struct net80211_device dev)
static

Definition at line 119 of file rtl818x.c.

120 {
121  struct rtl818x_priv *priv = dev->priv;
122  unsigned int count = RTL818X_TX_RING_SIZE;
123 
124  while (count--) {
125  struct rtl818x_tx_desc *entry = &priv->tx_ring[priv->tx_cons];
126  struct io_buffer *iob = priv->tx_buf[priv->tx_cons];
127  u32 flags = le32_to_cpu(entry->flags);
128  int rc;
129 
130  if ((flags & RTL818X_TX_DESC_FLAG_OWN) || !iob)
131  return;
132 
133  rc = 0;
135  /* our packet was not ACKed properly */
136  rc = EIO;
137  }
138 
139  net80211_tx_complete(dev, iob, flags & 0xFF, rc);
140 
141  priv->tx_buf[priv->tx_cons] = NULL;
142  priv->tx_cons = (priv->tx_cons + 1) % RTL818X_TX_RING_SIZE;
143  }
144 }
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
#define le32_to_cpu(value)
Definition: byteswap.h:114
static unsigned int count
Number of entries.
Definition: dwmac.h:225
void * priv
Driver private data.
Definition: net80211.h:798
uint8_t flags
Flags.
Definition: ena.h:18
void net80211_tx_complete(struct net80211_device *dev, struct io_buffer *iob, int retries, int rc)
Indicate the completed transmission of a packet.
Definition: net80211.c:2809
static struct tlan_private * priv
Definition: tlan.c:225
#define EIO
Input/output error.
Definition: errno.h:434
#define RTL818X_TX_RING_SIZE
Definition: rtl818x.h:220
#define NULL
NULL pointer (VOID *)
Definition: Base.h:322
uint32_t u32
Definition: stdint.h:24
A persistent I/O buffer.
Definition: iobuf.h:38

References count, EIO, flags, rtl818x_tx_desc::flags, le32_to_cpu, net80211_tx_complete(), NULL, priv, net80211_device::priv, rc, RTL818X_TX_DESC_FLAG_OWN, RTL818X_TX_DESC_FLAG_TX_OK, and RTL818X_TX_RING_SIZE.

Referenced by rtl818x_poll().

◆ rtl818x_poll()

static void rtl818x_poll ( struct net80211_device dev)
static

Definition at line 146 of file rtl818x.c.

147 {
148  struct rtl818x_priv *priv = dev->priv;
149  u16 reg = rtl818x_ioread16(priv, &priv->map->INT_STATUS);
150 
151  if (reg == 0xFFFF)
152  return;
153 
154  rtl818x_iowrite16(priv, &priv->map->INT_STATUS, reg);
155 
157  rtl818x_handle_tx(dev);
158 
160  rtl818x_handle_rx(dev);
161 }
uint16_t u16
Definition: stdint.h:22
#define RTL818X_INT_RX_OK
Definition: rtl818x.h:52
static unsigned int unsigned int reg
Definition: myson.h:162
static void rtl818x_handle_tx(struct net80211_device *dev)
Definition: rtl818x.c:119
static void rtl818x_handle_rx(struct net80211_device *dev)
Definition: rtl818x.c:64
void * priv
Driver private data.
Definition: net80211.h:798
#define RTL818X_INT_TXN_OK
Definition: rtl818x.h:58
#define RTL818X_INT_RX_ERR
Definition: rtl818x.h:53
#define RTL818X_INT_TXN_ERR
Definition: rtl818x.h:59
static struct tlan_private * priv
Definition: tlan.c:225
static void rtl818x_iowrite16(struct rtl818x_priv *priv __unused, u16 *addr, u16 val)
Definition: rtl818x.h:337
static u16 rtl818x_ioread16(struct rtl818x_priv *priv __unused, u16 *addr)
Definition: rtl818x.h:321

References priv, net80211_device::priv, reg, rtl818x_handle_rx(), rtl818x_handle_tx(), RTL818X_INT_RX_ERR, RTL818X_INT_RX_OK, RTL818X_INT_TXN_ERR, RTL818X_INT_TXN_OK, rtl818x_ioread16(), and rtl818x_iowrite16().

◆ rtl818x_tx()

static int rtl818x_tx ( struct net80211_device dev,
struct io_buffer iob 
)
static

Definition at line 165 of file rtl818x.c.

166 {
167  struct rtl818x_priv *priv = dev->priv;
168  struct rtl818x_tx_desc *entry;
169  u32 tx_flags;
170  u16 plcp_len = 0;
171  int len = iob_len(iob);
172 
174  RTL818X_TX_DESC_FLAG_LS | (priv->hw_rate << 24) | len;
175 
176  if (priv->r8185) {
177  tx_flags |= RTL818X_TX_DESC_FLAG_DMA |
179  } else {
180  unsigned int remainder;
181 
182  plcp_len = DIV_ROUND_UP(16 * (len + 4),
183  (dev->rates[dev->rate] * 2) / 10);
184  remainder = (16 * (len + 4)) %
185  ((dev->rates[dev->rate] * 2) / 10);
186 
187  if (remainder > 0 && remainder <= 6)
188  plcp_len |= 1 << 15;
189  }
190 
191  entry = &priv->tx_ring[priv->tx_prod];
192 
194  tx_flags |= RTL818X_TX_DESC_FLAG_CTS;
195  tx_flags |= priv->hw_rtscts_rate << 19;
196  entry->rts_duration = net80211_cts_duration(dev, len);
197  } else {
198  entry->rts_duration = 0;
199  }
200 
201  if (entry->flags & RTL818X_TX_DESC_FLAG_OWN) {
202  /* card hasn't processed the old packet yet! */
203  return -EBUSY;
204  }
205 
206  priv->tx_buf[priv->tx_prod] = iob;
207  priv->tx_prod = (priv->tx_prod + 1) % RTL818X_TX_RING_SIZE;
208 
209  entry->plcp_len = cpu_to_le16(plcp_len);
210  entry->tx_buf = cpu_to_le32(virt_to_bus(iob->data));
211  entry->frame_len = cpu_to_le32(len);
212  entry->flags2 = /* alternate retry rate in 100kbps << 4 */ 0;
214  entry->flags = cpu_to_le32(tx_flags);
215 
216  rtl818x_iowrite8(priv, &priv->map->TX_DMA_POLLING, (1 << 5));
217 
218  return 0;
219 }
uint16_t u16
Definition: stdint.h:22
#define EBUSY
Device or resource busy.
Definition: errno.h:339
static void rtl818x_iowrite8(struct rtl818x_priv *priv __unused, u8 *addr, u8 val)
Definition: rtl818x.h:331
static __always_inline unsigned long virt_to_bus(volatile const void *addr)
Convert virtual address to a bus address.
Definition: io.h:184
ring len
Length.
Definition: dwmac.h:231
#define cpu_to_le32(value)
Definition: byteswap.h:108
void * priv
Driver private data.
Definition: net80211.h:798
#define DIV_ROUND_UP(n, d)
Definition: rtl818x.c:163
#define NET80211_PHY_USE_PROTECTION
Whether to use RTS/CTS or CTS-to-self protection for transmissions.
Definition: net80211.h:251
static size_t iob_len(struct io_buffer *iobuf)
Calculate length of data in an I/O buffer.
Definition: iobuf.h:160
u16 rates[NET80211_MAX_RATES]
A list of all possible TX rates we might use.
Definition: net80211.h:818
#define RTL818X_MAX_RETRIES
Definition: rtl818x.h:223
int phy_flags
Physical layer options.
Definition: net80211.h:983
static struct tlan_private * priv
Definition: tlan.c:225
void * data
Start of data.
Definition: iobuf.h:53
#define cpu_to_le16(value)
Definition: byteswap.h:107
static u16 net80211_cts_duration(struct net80211_device *dev, int size)
Calculate duration field for a CTS control frame.
Definition: net80211.h:1179
#define RTL818X_TX_RING_SIZE
Definition: rtl818x.h:220
u8 rate
The rate currently in use, as an index into the rates array.
Definition: net80211.h:824
uint32_t u32
Definition: stdint.h:24
u16 rts_duration
Definition: rtl818x.h:241

References cpu_to_le16, cpu_to_le32, io_buffer::data, DIV_ROUND_UP, EBUSY, rtl818x_tx_desc::flags, rtl818x_tx_desc::flags2, rtl818x_tx_desc::frame_len, iob_len(), len, net80211_cts_duration(), NET80211_PHY_USE_PROTECTION, net80211_device::phy_flags, rtl818x_tx_desc::plcp_len, priv, net80211_device::priv, net80211_device::rate, net80211_device::rates, rtl818x_tx_desc::retry_limit, rtl818x_iowrite8(), RTL818X_MAX_RETRIES, RTL818X_TX_DESC_FLAG_CTS, RTL818X_TX_DESC_FLAG_DMA, RTL818X_TX_DESC_FLAG_FS, RTL818X_TX_DESC_FLAG_LS, RTL818X_TX_DESC_FLAG_NO_ENC, RTL818X_TX_DESC_FLAG_OWN, RTL818X_TX_RING_SIZE, rtl818x_tx_desc::rts_duration, rtl818x_tx_desc::tx_buf, and virt_to_bus().

◆ rtl818x_set_anaparam()

void rtl818x_set_anaparam ( struct rtl818x_priv priv,
u32  anaparam 
)

Definition at line 221 of file rtl818x.c.

222 {
223  u8 reg;
224 
226  reg = rtl818x_ioread8(priv, &priv->map->CONFIG3);
227  rtl818x_iowrite8(priv, &priv->map->CONFIG3,
229  rtl818x_iowrite32(priv, &priv->map->ANAPARAM, anaparam);
230  rtl818x_iowrite8(priv, &priv->map->CONFIG3,
233 }
#define RTL818X_CONFIG3_ANAPARAM_WRITE
Definition: rtl818x.h:124
static unsigned int unsigned int reg
Definition: myson.h:162
static u8 rtl818x_ioread8(struct rtl818x_priv *priv __unused, u8 *addr)
Definition: rtl818x.h:316
static void rtl818x_iowrite8(struct rtl818x_priv *priv __unused, u8 *addr, u8 val)
Definition: rtl818x.h:331
#define RTL818X_EEPROM_CMD_CONFIG
Definition: rtl818x.h:111
static void rtl818x_iowrite32(struct rtl818x_priv *priv __unused, u32 *addr, u32 val)
Definition: rtl818x.h:343
static struct tlan_private * priv
Definition: tlan.c:225
#define RTL818X_EEPROM_CMD_NORMAL
Definition: rtl818x.h:108
uint8_t u8
Definition: stdint.h:20

References priv, reg, RTL818X_CONFIG3_ANAPARAM_WRITE, RTL818X_EEPROM_CMD_CONFIG, RTL818X_EEPROM_CMD_NORMAL, rtl818x_ioread8(), rtl818x_iowrite32(), and rtl818x_iowrite8().

Referenced by grf5101_rf_init(), grf5101_rf_stop(), rtl818x_init_hw(), rtl8225_rf_init(), rtl8225z2_rf_init(), and sa2400_rf_init().

◆ rtl818x_init_hw()

static int rtl818x_init_hw ( struct net80211_device dev)
static

Definition at line 235 of file rtl818x.c.

236 {
237  struct rtl818x_priv *priv = dev->priv;
238  u16 reg;
239 
240  rtl818x_iowrite8(priv, &priv->map->CMD, 0);
241  rtl818x_ioread8(priv, &priv->map->CMD);
242  mdelay(10);
243 
244  /* reset */
245  rtl818x_iowrite16(priv, &priv->map->INT_MASK, 0);
246  rtl818x_ioread8(priv, &priv->map->CMD);
247 
248  reg = rtl818x_ioread8(priv, &priv->map->CMD);
249  reg &= (1 << 1);
252  rtl818x_ioread8(priv, &priv->map->CMD);
253  mdelay(200);
254 
255  /* check success of reset */
256  if (rtl818x_ioread8(priv, &priv->map->CMD) & RTL818X_CMD_RESET) {
257  DBG("rtl818x %s: reset timeout!\n", dev->netdev->name);
258  return -ETIMEDOUT;
259  }
260 
261  rtl818x_iowrite8(priv, &priv->map->EEPROM_CMD, RTL818X_EEPROM_CMD_LOAD);
262  rtl818x_ioread8(priv, &priv->map->CMD);
263  mdelay(200);
264 
265  if (rtl818x_ioread8(priv, &priv->map->CONFIG3) & (1 << 3)) {
266  /* For cardbus */
267  reg = rtl818x_ioread8(priv, &priv->map->CONFIG3);
268  reg |= 1 << 1;
269  rtl818x_iowrite8(priv, &priv->map->CONFIG3, reg);
270  reg = rtl818x_ioread16(priv, &priv->map->FEMR);
271  reg |= (1 << 15) | (1 << 14) | (1 << 4);
272  rtl818x_iowrite16(priv, &priv->map->FEMR, reg);
273  }
274 
275  rtl818x_iowrite8(priv, &priv->map->MSR, 0);
276 
277  if (!priv->r8185)
278  rtl818x_set_anaparam(priv, priv->anaparam);
279 
280  rtl818x_iowrite32(priv, &priv->map->RDSAR, priv->rx_ring_dma);
281  rtl818x_iowrite32(priv, &priv->map->TNPDA, priv->tx_ring_dma);
282 
283  /* TODO: necessary? specs indicate not */
285  reg = rtl818x_ioread8(priv, &priv->map->CONFIG2);
286  rtl818x_iowrite8(priv, &priv->map->CONFIG2, reg & ~(1 << 3));
287  if (priv->r8185) {
288  reg = rtl818x_ioread8(priv, &priv->map->CONFIG2);
289  rtl818x_iowrite8(priv, &priv->map->CONFIG2, reg | (1 << 4));
290  }
292 
293  /* TODO: set CONFIG5 for calibrating AGC on rtl8180 + philips radio? */
294 
295  /* TODO: turn off hw wep on rtl8180 */
296 
297  rtl818x_iowrite32(priv, &priv->map->INT_TIMEOUT, 0);
298 
299  if (priv->r8185) {
300  rtl818x_iowrite8(priv, &priv->map->WPA_CONF, 0);
301  rtl818x_iowrite8(priv, &priv->map->RATE_FALLBACK, 0x81);
302  rtl818x_iowrite8(priv, &priv->map->RESP_RATE, (8 << 4) | 0);
303 
304  rtl818x_iowrite16(priv, &priv->map->BRSR, 0x01F3);
305 
306  /* TODO: set ClkRun enable? necessary? */
307  reg = rtl818x_ioread8(priv, &priv->map->GP_ENABLE);
308  rtl818x_iowrite8(priv, &priv->map->GP_ENABLE, reg & ~(1 << 6));
310  reg = rtl818x_ioread8(priv, &priv->map->CONFIG3);
311  rtl818x_iowrite8(priv, &priv->map->CONFIG3, reg | (1 << 2));
313  } else {
314  rtl818x_iowrite16(priv, &priv->map->BRSR, 0x1);
315  rtl818x_iowrite8(priv, &priv->map->SECURITY, 0);
316 
317  rtl818x_iowrite8(priv, &priv->map->PHY_DELAY, 0x6);
318  rtl818x_iowrite8(priv, &priv->map->CARRIER_SENSE_COUNTER, 0x4C);
319  }
320 
321  priv->rf->init(dev);
322  if (priv->r8185)
323  rtl818x_iowrite16(priv, &priv->map->BRSR, 0x01F3);
324  return 0;
325 }
uint16_t u16
Definition: stdint.h:22
static unsigned int unsigned int reg
Definition: myson.h:162
static u8 rtl818x_ioread8(struct rtl818x_priv *priv __unused, u8 *addr)
Definition: rtl818x.h:316
static void rtl818x_iowrite8(struct rtl818x_priv *priv __unused, u8 *addr, u8 val)
Definition: rtl818x.h:331
#define RTL818X_EEPROM_CMD_CONFIG
Definition: rtl818x.h:111
#define RTL818X_CMD_RESET
Definition: rtl818x.h:48
static void rtl818x_iowrite32(struct rtl818x_priv *priv __unused, u32 *addr, u32 val)
Definition: rtl818x.h:343
void * priv
Driver private data.
Definition: net80211.h:798
struct net_device * netdev
The net_device that wraps us.
Definition: net80211.h:789
void mdelay(unsigned long msecs)
Delay for a fixed number of milliseconds.
Definition: timer.c:79
char name[NETDEV_NAME_LEN]
Name of this network device.
Definition: netdevice.h:363
static struct tlan_private * priv
Definition: tlan.c:225
#define RTL818X_EEPROM_CMD_NORMAL
Definition: rtl818x.h:108
static void rtl818x_iowrite16(struct rtl818x_priv *priv __unused, u16 *addr, u16 val)
Definition: rtl818x.h:337
#define RTL818X_EEPROM_CMD_LOAD
Definition: rtl818x.h:109
static u16 rtl818x_ioread16(struct rtl818x_priv *priv __unused, u16 *addr)
Definition: rtl818x.h:321
#define DBG(...)
Print a debugging message.
Definition: compiler.h:498
void rtl818x_set_anaparam(struct rtl818x_priv *priv, u32 anaparam)
Definition: rtl818x.c:221
#define ETIMEDOUT
Connection timed out.
Definition: errno.h:670

References DBG, ETIMEDOUT, mdelay(), net_device::name, net80211_device::netdev, priv, net80211_device::priv, reg, RTL818X_CMD_RESET, RTL818X_EEPROM_CMD_CONFIG, RTL818X_EEPROM_CMD_LOAD, RTL818X_EEPROM_CMD_NORMAL, rtl818x_ioread16(), rtl818x_ioread8(), rtl818x_iowrite16(), rtl818x_iowrite32(), rtl818x_iowrite8(), and rtl818x_set_anaparam().

Referenced by rtl818x_start().

◆ rtl818x_init_rx_ring()

static int rtl818x_init_rx_ring ( struct net80211_device dev)
static

Definition at line 327 of file rtl818x.c.

328 {
329  struct rtl818x_priv *priv = dev->priv;
330  struct rtl818x_rx_desc *entry;
331  int i;
332 
333  priv->rx_ring = malloc_phys(sizeof(*priv->rx_ring) * RTL818X_RX_RING_SIZE,
335  priv->rx_ring_dma = virt_to_bus(priv->rx_ring);
336  if (!priv->rx_ring) {
337  DBG("rtl818x %s: cannot allocate RX ring\n", dev->netdev->name);
338  return -ENOMEM;
339  }
340 
341  memset(priv->rx_ring, 0, sizeof(*priv->rx_ring) * RTL818X_RX_RING_SIZE);
342  priv->rx_idx = 0;
343 
344  for (i = 0; i < RTL818X_RX_RING_SIZE; i++) {
345  struct io_buffer *iob = alloc_iob(MAX_RX_SIZE);
346  entry = &priv->rx_ring[i];
347  if (!iob)
348  return -ENOMEM;
349 
350  priv->rx_buf[i] = iob;
351  entry->rx_buf = cpu_to_le32(virt_to_bus(iob->data));
353  MAX_RX_SIZE);
354  }
356  return 0;
357 }
struct io_buffer * alloc_iob(size_t len)
Allocate I/O buffer.
Definition: iobuf.c:131
#define ENOMEM
Not enough space.
Definition: errno.h:535
static __always_inline unsigned long virt_to_bus(volatile const void *addr)
Convert virtual address to a bus address.
Definition: io.h:184
#define cpu_to_le32(value)
Definition: byteswap.h:108
void * priv
Driver private data.
Definition: net80211.h:798
struct net_device * netdev
The net_device that wraps us.
Definition: net80211.h:789
#define RTL818X_RX_RING_SIZE
Definition: rtl818x.h:219
char name[NETDEV_NAME_LEN]
Name of this network device.
Definition: netdevice.h:363
static struct tlan_private * priv
Definition: tlan.c:225
#define MAX_RX_SIZE
Definition: rtl818x.h:198
void * data
Start of data.
Definition: iobuf.h:53
#define DBG(...)
Print a debugging message.
Definition: compiler.h:498
void * malloc_phys(size_t size, size_t phys_align)
Allocate memory with specified physical alignment.
Definition: malloc.c:707
#define RTL818X_RING_ALIGN
Definition: rtl818x.h:221
void * memset(void *dest, int character, size_t len) __nonnull
A persistent I/O buffer.
Definition: iobuf.h:38

References alloc_iob(), cpu_to_le32, io_buffer::data, DBG, ENOMEM, rtl818x_rx_desc::flags, malloc_phys(), MAX_RX_SIZE, memset(), net_device::name, net80211_device::netdev, priv, net80211_device::priv, RTL818X_RING_ALIGN, RTL818X_RX_DESC_FLAG_EOR, RTL818X_RX_DESC_FLAG_OWN, RTL818X_RX_RING_SIZE, rtl818x_rx_desc::rx_buf, and virt_to_bus().

Referenced by rtl818x_start().

◆ rtl818x_free_rx_ring()

static void rtl818x_free_rx_ring ( struct net80211_device dev)
static

Definition at line 359 of file rtl818x.c.

360 {
361  struct rtl818x_priv *priv = dev->priv;
362  int i;
363 
364  for (i = 0; i < RTL818X_RX_RING_SIZE; i++) {
365  free_iob(priv->rx_buf[i]);
366  priv->rx_buf[i] = NULL;
367  }
368 
369  free_phys(priv->rx_ring, sizeof(*priv->rx_ring) * RTL818X_RX_RING_SIZE);
370  priv->rx_ring = NULL;
371 }
void free_iob(struct io_buffer *iobuf)
Free I/O buffer.
Definition: iobuf.c:153
void * priv
Driver private data.
Definition: net80211.h:798
#define RTL818X_RX_RING_SIZE
Definition: rtl818x.h:219
static struct tlan_private * priv
Definition: tlan.c:225
void free_phys(void *ptr, size_t size)
Free memory allocated with malloc_phys()
Definition: malloc.c:723
#define NULL
NULL pointer (VOID *)
Definition: Base.h:322

References free_iob(), free_phys(), NULL, priv, net80211_device::priv, and RTL818X_RX_RING_SIZE.

Referenced by rtl818x_start(), and rtl818x_stop().

◆ rtl818x_init_tx_ring()

static int rtl818x_init_tx_ring ( struct net80211_device dev)
static

Definition at line 373 of file rtl818x.c.

374 {
375  struct rtl818x_priv *priv = dev->priv;
376  int i;
377 
378  priv->tx_ring = malloc_phys(sizeof(*priv->tx_ring) * RTL818X_TX_RING_SIZE,
380  priv->tx_ring_dma = virt_to_bus(priv->tx_ring);
381  if (!priv->tx_ring) {
382  DBG("rtl818x %s: cannot allocate TX ring\n", dev->netdev->name);
383  return -ENOMEM;
384  }
385 
386  memset(priv->tx_ring, 0, sizeof(*priv->tx_ring) * RTL818X_TX_RING_SIZE);
387  priv->tx_prod = priv->tx_cons = 0;
388 
389  for (i = 0; i < RTL818X_TX_RING_SIZE; i++)
390  priv->tx_ring[i].next_tx_desc = cpu_to_le32(priv->tx_ring_dma +
391  ((i + 1) % RTL818X_TX_RING_SIZE) * sizeof(*priv->tx_ring));
392 
393  return 0;
394 }
#define ENOMEM
Not enough space.
Definition: errno.h:535
static __always_inline unsigned long virt_to_bus(volatile const void *addr)
Convert virtual address to a bus address.
Definition: io.h:184
#define cpu_to_le32(value)
Definition: byteswap.h:108
void * priv
Driver private data.
Definition: net80211.h:798
struct net_device * netdev
The net_device that wraps us.
Definition: net80211.h:789
char name[NETDEV_NAME_LEN]
Name of this network device.
Definition: netdevice.h:363
static struct tlan_private * priv
Definition: tlan.c:225
#define RTL818X_TX_RING_SIZE
Definition: rtl818x.h:220
#define DBG(...)
Print a debugging message.
Definition: compiler.h:498
void * malloc_phys(size_t size, size_t phys_align)
Allocate memory with specified physical alignment.
Definition: malloc.c:707
#define RTL818X_RING_ALIGN
Definition: rtl818x.h:221
void * memset(void *dest, int character, size_t len) __nonnull

References cpu_to_le32, DBG, ENOMEM, malloc_phys(), memset(), net_device::name, net80211_device::netdev, priv, net80211_device::priv, RTL818X_RING_ALIGN, RTL818X_TX_RING_SIZE, and virt_to_bus().

Referenced by rtl818x_start().

◆ rtl818x_free_tx_ring()

static void rtl818x_free_tx_ring ( struct net80211_device dev)
static

Definition at line 396 of file rtl818x.c.

397 {
398  struct rtl818x_priv *priv = dev->priv;
399  int i;
400 
401  for (i = 0; i < RTL818X_TX_RING_SIZE; i++) {
402  if (priv->tx_buf[i])
403  net80211_tx_complete(dev, priv->tx_buf[i], 0, ECANCELED);
404  priv->tx_buf[i] = NULL;
405  }
406 
407  free_phys(priv->tx_ring, sizeof(*priv->tx_ring) * RTL818X_TX_RING_SIZE);
408  priv->tx_ring = NULL;
409 }
#define ECANCELED
Operation canceled.
Definition: errno.h:344
void * priv
Driver private data.
Definition: net80211.h:798
void net80211_tx_complete(struct net80211_device *dev, struct io_buffer *iob, int retries, int rc)
Indicate the completed transmission of a packet.
Definition: net80211.c:2809
static struct tlan_private * priv
Definition: tlan.c:225
void free_phys(void *ptr, size_t size)
Free memory allocated with malloc_phys()
Definition: malloc.c:723
#define RTL818X_TX_RING_SIZE
Definition: rtl818x.h:220
#define NULL
NULL pointer (VOID *)
Definition: Base.h:322

References ECANCELED, free_phys(), net80211_tx_complete(), NULL, priv, net80211_device::priv, and RTL818X_TX_RING_SIZE.

Referenced by rtl818x_start(), and rtl818x_stop().

◆ rtl818x_irq()

static void rtl818x_irq ( struct net80211_device dev,
int  enable 
)
static

Definition at line 411 of file rtl818x.c.

412 {
413  struct rtl818x_priv *priv = dev->priv;
414  rtl818x_iowrite16(priv, &priv->map->INT_MASK, enable? 0xFFFF : 0);
415 }
void * priv
Driver private data.
Definition: net80211.h:798
static struct tlan_private * priv
Definition: tlan.c:225
static void rtl818x_iowrite16(struct rtl818x_priv *priv __unused, u16 *addr, u16 val)
Definition: rtl818x.h:337

References priv, net80211_device::priv, and rtl818x_iowrite16().

Referenced by rtl818x_stop().

◆ rtl818x_set_hwaddr()

static void rtl818x_set_hwaddr ( struct net80211_device dev,
u8 hwaddr 
)
static

Definition at line 418 of file rtl818x.c.

419 {
420  struct rtl818x_priv *priv = dev->priv;
422  rtl818x_iowrite32(priv, (u32 *)&priv->map->MAC[0],
423  le32_to_cpu(*(u32 *)hwaddr));
424  rtl818x_iowrite16(priv, (u16 *)&priv->map->MAC[4],
425  le16_to_cpu(*(u16 *)(hwaddr + 4)));
427 }
uint16_t u16
Definition: stdint.h:22
#define le32_to_cpu(value)
Definition: byteswap.h:114
static void rtl818x_iowrite8(struct rtl818x_priv *priv __unused, u8 *addr, u8 val)
Definition: rtl818x.h:331
#define RTL818X_EEPROM_CMD_CONFIG
Definition: rtl818x.h:111
static void rtl818x_iowrite32(struct rtl818x_priv *priv __unused, u32 *addr, u32 val)
Definition: rtl818x.h:343
void * priv
Driver private data.
Definition: net80211.h:798
#define le16_to_cpu(value)
Definition: byteswap.h:113
static struct tlan_private * priv
Definition: tlan.c:225
#define RTL818X_EEPROM_CMD_NORMAL
Definition: rtl818x.h:108
static void rtl818x_iowrite16(struct rtl818x_priv *priv __unused, u16 *addr, u16 val)
Definition: rtl818x.h:337
uint32_t u32
Definition: stdint.h:24

References le16_to_cpu, le32_to_cpu, priv, net80211_device::priv, RTL818X_EEPROM_CMD_CONFIG, RTL818X_EEPROM_CMD_NORMAL, rtl818x_iowrite16(), rtl818x_iowrite32(), and rtl818x_iowrite8().

Referenced by rtl818x_start().

◆ rtl818x_start()

static int rtl818x_start ( struct net80211_device dev)
static

Definition at line 429 of file rtl818x.c.

430 {
431  struct rtl818x_priv *priv = dev->priv;
432  int ret;
433  u32 reg;
434 
435  ret = rtl818x_init_rx_ring(dev);
436  if (ret)
437  return ret;
438 
439  ret = rtl818x_init_tx_ring(dev);
440  if (ret)
441  goto err_free_rings;
442 
443  ret = rtl818x_init_hw(dev);
444  if (ret)
445  goto err_free_rings;
446 
447  rtl818x_set_hwaddr(dev, dev->netdev->ll_addr);
448 
449  rtl818x_iowrite32(priv, &priv->map->RDSAR, priv->rx_ring_dma);
450  rtl818x_iowrite32(priv, &priv->map->TNPDA, priv->tx_ring_dma);
451 
452  rtl818x_iowrite16(priv, &priv->map->INT_MASK, 0);
453 
454  rtl818x_iowrite32(priv, &priv->map->MAR[0], ~0);
455  rtl818x_iowrite32(priv, &priv->map->MAR[1], ~0);
456 
461  (7 << 8 /* MAX RX DMA */) |
464 
465  if (priv->r8185)
467  else {
468  reg |= (priv->rfparam & RF_PARAM_CARRIERSENSE1)
469  ? RTL818X_RX_CONF_CSDM1 : 0;
470  reg |= (priv->rfparam & RF_PARAM_CARRIERSENSE2)
471  ? RTL818X_RX_CONF_CSDM2 : 0;
472  }
473 
474  priv->rx_conf = reg;
475  rtl818x_iowrite32(priv, &priv->map->RX_CONF, reg);
476 
477  if (priv->r8185) {
478  reg = rtl818x_ioread8(priv, &priv->map->CW_CONF);
481  rtl818x_iowrite8(priv, &priv->map->CW_CONF, reg);
482 
483  reg = rtl818x_ioread8(priv, &priv->map->TX_AGC_CTL);
487  rtl818x_iowrite8(priv, &priv->map->TX_AGC_CTL, reg);
488 
489  /* disable early TX */
490  rtl818x_iowrite8(priv, (u8 *)priv->map + 0xec, 0x3f);
491  }
492 
493  reg = rtl818x_ioread32(priv, &priv->map->TX_CONF);
494  reg |= (6 << 21 /* MAX TX DMA */) |
496 
497  if (priv->r8185)
499  else
501 
502  /* different meaning, same value on both rtl8185 and rtl8180 */
504 
505  rtl818x_iowrite32(priv, &priv->map->TX_CONF, reg);
506 
507  reg = rtl818x_ioread8(priv, &priv->map->CMD);
510  rtl818x_iowrite8(priv, &priv->map->CMD, reg);
511 
512  DBG("%s rtl818x: started\n", dev->netdev->name);
513 
514  return 0;
515 
516  err_free_rings:
518  if (priv->tx_ring)
520 
521  DBG("%s rtl818x: failed to start\n", dev->netdev->name);
522 
523  return ret;
524 }
static int rtl818x_init_tx_ring(struct net80211_device *dev)
Definition: rtl818x.c:373
#define RTL818X_RX_CONF_CSDM1
Definition: rtl818x.h:98
#define RTL818X_RX_CONF_RX_AUTORESETPHY
Definition: rtl818x.h:97
static unsigned int unsigned int reg
Definition: myson.h:162
static u8 rtl818x_ioread8(struct rtl818x_priv *priv __unused, u8 *addr)
Definition: rtl818x.h:316
#define RTL818X_TX_AGC_CTL_FEEDBACK_ANT
Definition: rtl818x.h:157
#define RTL818X_TX_AGC_CTL_PERPACKET_ANTSEL_SHIFT
Definition: rtl818x.h:156
static void rtl818x_iowrite8(struct rtl818x_priv *priv __unused, u8 *addr, u8 val)
Definition: rtl818x.h:331
#define RTL818X_RX_CONF_CSDM2
Definition: rtl818x.h:99
#define RTL818X_CW_CONF_PERPACKET_RETRY_SHIFT
Definition: rtl818x.h:170
#define RTL818X_CMD_TX_ENABLE
Definition: rtl818x.h:46
#define RTL818X_RX_CONF_BROADCAST
Definition: rtl818x.h:89
static void rtl818x_iowrite32(struct rtl818x_priv *priv __unused, u32 *addr, u32 val)
Definition: rtl818x.h:343
#define RTL818X_CW_CONF_PERPACKET_CW_SHIFT
Definition: rtl818x.h:169
#define RTL818X_TX_CONF_HW_SEQNUM
Definition: rtl818x.h:83
#define RTL818X_TX_CONF_SAT_HWPLCP
Definition: rtl818x.h:73
static void rtl818x_free_rx_ring(struct net80211_device *dev)
Definition: rtl818x.c:359
#define RTL818X_RX_CONF_NICMAC
Definition: rtl818x.h:87
void * priv
Driver private data.
Definition: net80211.h:798
static int rtl818x_init_rx_ring(struct net80211_device *dev)
Definition: rtl818x.c:327
#define RTL818X_TX_CONF_PROBE_DTS
Definition: rtl818x.h:82
static int rtl818x_init_hw(struct net80211_device *dev)
Definition: rtl818x.c:235
#define RTL818X_RX_CONF_DATA
Definition: rtl818x.h:91
#define RTL818X_RX_CONF_ONLYERLPKT
Definition: rtl818x.h:100
struct net_device * netdev
The net_device that wraps us.
Definition: net80211.h:789
#define RF_PARAM_CARRIERSENSE1
Definition: rtl818x.h:202
char name[NETDEV_NAME_LEN]
Name of this network device.
Definition: netdevice.h:363
static struct tlan_private * priv
Definition: tlan.c:225
#define RTL818X_TX_CONF_NO_ICV
Definition: rtl818x.h:71
static void rtl818x_free_tx_ring(struct net80211_device *dev)
Definition: rtl818x.c:396
static void rtl818x_set_hwaddr(struct net80211_device *dev, u8 *hwaddr)
Definition: rtl818x.c:418
#define RF_PARAM_CARRIERSENSE2
Definition: rtl818x.h:203
#define RTL818X_RX_CONF_MGMT
Definition: rtl818x.h:93
static void rtl818x_iowrite16(struct rtl818x_priv *priv __unused, u16 *addr, u16 val)
Definition: rtl818x.h:337
#define RTL818X_CMD_RX_ENABLE
Definition: rtl818x.h:47
uint8_t ll_addr[MAX_LL_ADDR_LEN]
Link-layer address.
Definition: netdevice.h:388
#define DBG(...)
Print a debugging message.
Definition: compiler.h:498
#define RTL818X_TX_AGC_CTL_PERPACKET_GAIN_SHIFT
Definition: rtl818x.h:155
uint8_t u8
Definition: stdint.h:20
uint32_t u32
Definition: stdint.h:24
static u32 rtl818x_ioread32(struct rtl818x_priv *priv __unused, u32 *addr)
Definition: rtl818x.h:326

References DBG, net_device::ll_addr, net_device::name, net80211_device::netdev, priv, net80211_device::priv, reg, RF_PARAM_CARRIERSENSE1, RF_PARAM_CARRIERSENSE2, RTL818X_CMD_RX_ENABLE, RTL818X_CMD_TX_ENABLE, RTL818X_CW_CONF_PERPACKET_CW_SHIFT, RTL818X_CW_CONF_PERPACKET_RETRY_SHIFT, rtl818x_free_rx_ring(), rtl818x_free_tx_ring(), rtl818x_init_hw(), rtl818x_init_rx_ring(), rtl818x_init_tx_ring(), rtl818x_ioread32(), rtl818x_ioread8(), rtl818x_iowrite16(), rtl818x_iowrite32(), rtl818x_iowrite8(), RTL818X_RX_CONF_BROADCAST, RTL818X_RX_CONF_CSDM1, RTL818X_RX_CONF_CSDM2, RTL818X_RX_CONF_DATA, RTL818X_RX_CONF_MGMT, RTL818X_RX_CONF_NICMAC, RTL818X_RX_CONF_ONLYERLPKT, RTL818X_RX_CONF_RX_AUTORESETPHY, rtl818x_set_hwaddr(), RTL818X_TX_AGC_CTL_FEEDBACK_ANT, RTL818X_TX_AGC_CTL_PERPACKET_ANTSEL_SHIFT, RTL818X_TX_AGC_CTL_PERPACKET_GAIN_SHIFT, RTL818X_TX_CONF_HW_SEQNUM, RTL818X_TX_CONF_NO_ICV, RTL818X_TX_CONF_PROBE_DTS, and RTL818X_TX_CONF_SAT_HWPLCP.

◆ rtl818x_stop()

static void rtl818x_stop ( struct net80211_device dev)
static

Definition at line 526 of file rtl818x.c.

527 {
528  struct rtl818x_priv *priv = dev->priv;
529  u8 reg;
530 
531  rtl818x_irq(dev, 0);
532 
533  reg = rtl818x_ioread8(priv, &priv->map->CMD);
536  rtl818x_iowrite8(priv, &priv->map->CMD, reg);
537 
538  priv->rf->stop(dev);
539 
541  reg = rtl818x_ioread8(priv, &priv->map->CONFIG4);
544 
547 }
static unsigned int unsigned int reg
Definition: myson.h:162
static u8 rtl818x_ioread8(struct rtl818x_priv *priv __unused, u8 *addr)
Definition: rtl818x.h:316
static void rtl818x_iowrite8(struct rtl818x_priv *priv __unused, u8 *addr, u8 val)
Definition: rtl818x.h:331
#define RTL818X_EEPROM_CMD_CONFIG
Definition: rtl818x.h:111
#define RTL818X_CMD_TX_ENABLE
Definition: rtl818x.h:46
static void rtl818x_free_rx_ring(struct net80211_device *dev)
Definition: rtl818x.c:359
void * priv
Driver private data.
Definition: net80211.h:798
static void rtl818x_irq(struct net80211_device *dev, int enable)
Definition: rtl818x.c:411
static struct tlan_private * priv
Definition: tlan.c:225
#define RTL818X_EEPROM_CMD_NORMAL
Definition: rtl818x.h:108
static void rtl818x_free_tx_ring(struct net80211_device *dev)
Definition: rtl818x.c:396
#define RTL818X_CONFIG4_VCOOFF
Definition: rtl818x.h:128
#define RTL818X_CMD_RX_ENABLE
Definition: rtl818x.h:47
uint8_t u8
Definition: stdint.h:20

References priv, net80211_device::priv, reg, RTL818X_CMD_RX_ENABLE, RTL818X_CMD_TX_ENABLE, RTL818X_CONFIG4_VCOOFF, RTL818X_EEPROM_CMD_CONFIG, RTL818X_EEPROM_CMD_NORMAL, rtl818x_free_rx_ring(), rtl818x_free_tx_ring(), rtl818x_ioread8(), rtl818x_iowrite8(), and rtl818x_irq().

◆ rtl818x_config()

static int rtl818x_config ( struct net80211_device dev,
int  changed 
)
static

Definition at line 549 of file rtl818x.c.

550 {
551  struct rtl818x_priv *priv = dev->priv;
552  int i;
553 
554  if (changed & NET80211_CFG_CHANNEL)
555  priv->rf->set_chan(dev, &dev->channels[dev->channel]);
556 
557  if (changed & NET80211_CFG_ASSOC) {
558  for (i = 0; i < ETH_ALEN; i++)
559  rtl818x_iowrite8(priv, &priv->map->BSSID[i], dev->bssid[i]);
560  rtl818x_iowrite8(priv, &priv->map->MSR,
561  dev->state & NET80211_ASSOCIATED?
563  }
564 
565  if (changed & NET80211_CFG_PHY_PARAMS)
566  priv->rf->conf_erp(dev);
567 
568  if (changed & NET80211_CFG_RATE) {
569  /* figure out the hardware rate number for the new
570  logical rate */
571  int hw_rate;
572  for (hw_rate = 0; hw_rate < RTL818X_NR_RATES &&
573  rtl818x_rates[hw_rate] != dev->rates[dev->rate];
574  hw_rate++)
575  ;
576  if (hw_rate >= RTL818X_NR_RATES)
577  return -EINVAL;
578 
579  priv->hw_rate = hw_rate;
580 
581  /* and the RTS/CTS rate */
582  for (hw_rate = 0; hw_rate < RTL818X_NR_RATES &&
584  dev->rates[dev->rtscts_rate];
585  hw_rate++)
586  ;
587  if (hw_rate >= RTL818X_NR_RATES)
588  hw_rate = priv->hw_rate;
589 
590  priv->hw_rtscts_rate = hw_rate;
591  }
592 
593  return 0;
594 }
int hw_rate
Definition: rtl818x.h:285
#define EINVAL
Invalid argument.
Definition: errno.h:429
#define RTL818X_MSR_INFRA
Definition: rtl818x.h:120
u8 channel
The channel currently in use, as an index into the channels array.
Definition: net80211.h:812
static void rtl818x_iowrite8(struct rtl818x_priv *priv __unused, u8 *addr, u8 val)
Definition: rtl818x.h:331
u8 rtscts_rate
The rate to use for RTS/CTS transmissions.
Definition: net80211.h:831
static const u16 rtl818x_rates[]
Definition: rtl818x.c:39
void * priv
Driver private data.
Definition: net80211.h:798
#define NET80211_CFG_PHY_PARAMS
Low-level link parameters (short preamble, protection, etc) have changed.
Definition: net80211.h:90
#define NET80211_ASSOCIATED
Whether we have successfully associated with the network.
Definition: net80211.h:201
#define ETH_ALEN
Definition: if_ether.h:9
u16 rates[NET80211_MAX_RATES]
A list of all possible TX rates we might use.
Definition: net80211.h:818
static struct tlan_private * priv
Definition: tlan.c:225
struct net80211_channel channels[NET80211_MAX_CHANNELS]
A list of all possible channels we might use.
Definition: net80211.h:806
#define NET80211_CFG_RATE
Requested transmission rate (dev->rate) has changed.
Definition: net80211.h:84
#define NET80211_CFG_CHANNEL
Channel choice (dev->channel) or regulatory parameters have changed.
Definition: net80211.h:81
u8 bssid[ETH_ALEN]
MAC address of the access point most recently associated.
Definition: net80211.h:954
u16 state
State of our association to the network.
Definition: net80211.h:921
#define RTL818X_MSR_NO_LINK
Definition: rtl818x.h:118
#define NET80211_CFG_ASSOC
Association has been established with a new BSS (dev->bssid)
Definition: net80211.h:87
u8 rate
The rate currently in use, as an index into the rates array.
Definition: net80211.h:824
#define RTL818X_NR_RATES
Definition: rtl818x.c:45

References net80211_device::bssid, net80211_device::channel, net80211_device::channels, EINVAL, ETH_ALEN, rtl818x_priv::hw_rate, NET80211_ASSOCIATED, NET80211_CFG_ASSOC, NET80211_CFG_CHANNEL, NET80211_CFG_PHY_PARAMS, NET80211_CFG_RATE, priv, net80211_device::priv, net80211_device::rate, net80211_device::rates, rtl818x_iowrite8(), RTL818X_MSR_INFRA, RTL818X_MSR_NO_LINK, RTL818X_NR_RATES, rtl818x_rates, net80211_device::rtscts_rate, and net80211_device::state.

◆ rtl818x_spi_read_bit()

static int rtl818x_spi_read_bit ( struct bit_basher basher,
unsigned int  bit_id 
)
static

Definition at line 603 of file rtl818x.c.

604 {
605  struct rtl818x_priv *priv = container_of(basher, struct rtl818x_priv,
606  spibit.basher);
607 
608  u8 reg = rtl818x_ioread8(priv, &priv->map->EEPROM_CMD);
609  return reg & rtl818x_eeprom_bits[bit_id];
610 }
struct bit_basher basher
Bit-bashing interface.
Definition: spi_bit.h:20
static const u8 rtl818x_eeprom_bits[]
Definition: rtl818x.c:596
static unsigned int unsigned int reg
Definition: myson.h:162
static u8 rtl818x_ioread8(struct rtl818x_priv *priv __unused, u8 *addr)
Definition: rtl818x.h:316
#define container_of(ptr, type, field)
Get containing structure.
Definition: stddef.h:36
struct spi_bit_basher spibit
Definition: rtl818x.h:288
static struct tlan_private * priv
Definition: tlan.c:225
uint8_t u8
Definition: stdint.h:20

References spi_bit_basher::basher, container_of, priv, reg, rtl818x_eeprom_bits, rtl818x_ioread8(), and rtl818x_priv::spibit.

◆ rtl818x_spi_write_bit()

static void rtl818x_spi_write_bit ( struct bit_basher basher,
unsigned int  bit_id,
unsigned long  data 
)
static

Definition at line 612 of file rtl818x.c.

614 {
615  struct rtl818x_priv *priv = container_of(basher, struct rtl818x_priv,
616  spibit.basher);
617 
618  u8 reg = rtl818x_ioread8(priv, &priv->map->EEPROM_CMD);
619  u8 mask = rtl818x_eeprom_bits[bit_id];
620  reg = (reg & ~mask) | (data & mask);
621 
622  rtl818x_iowrite8(priv, &priv->map->EEPROM_CMD, reg);
623 
624  rtl818x_ioread8(priv, &priv->map->EEPROM_CMD);
625  udelay(10);
626 }
struct bit_basher basher
Bit-bashing interface.
Definition: spi_bit.h:20
static const u8 rtl818x_eeprom_bits[]
Definition: rtl818x.c:596
static unsigned int unsigned int reg
Definition: myson.h:162
static u8 rtl818x_ioread8(struct rtl818x_priv *priv __unused, u8 *addr)
Definition: rtl818x.h:316
static void rtl818x_iowrite8(struct rtl818x_priv *priv __unused, u8 *addr, u8 val)
Definition: rtl818x.h:331
#define container_of(ptr, type, field)
Get containing structure.
Definition: stddef.h:36
void udelay(unsigned long usecs)
Delay for a fixed number of microseconds.
Definition: timer.c:61
struct spi_bit_basher spibit
Definition: rtl818x.h:288
static struct tlan_private * priv
Definition: tlan.c:225
uint8_t data[48]
Additional event data.
Definition: ena.h:22
uint8_t u8
Definition: stdint.h:20

References spi_bit_basher::basher, container_of, data, priv, reg, rtl818x_eeprom_bits, rtl818x_ioread8(), rtl818x_iowrite8(), rtl818x_priv::spibit, and udelay().

◆ rtl818x_probe()

int rtl818x_probe ( struct pci_device pdev)

Definition at line 654 of file rtl818x.c.

655 {
656  struct net80211_device *dev;
657  struct rtl818x_priv *priv;
658  struct rtl818x_rf_ops *rf;
659  int err, i;
660  const char *chip_name;
661  u32 reg;
662  u16 eeprom_val;
663  struct net80211_hw_info *hwinfo;
664 
665  hwinfo = zalloc(sizeof(*hwinfo));
666  if (!hwinfo) {
667  DBG("rtl818x: hwinfo alloc failed\n");
668  err = -ENOMEM;
669  goto err_alloc_hwinfo;
670  }
671 
672  adjust_pci_device(pdev);
673 
674  dev = net80211_alloc(sizeof(*priv));
675  if (!dev) {
676  DBG("rtl818x: net80211 alloc failed\n");
677  err = -ENOMEM;
678  goto err_alloc_dev;
679  }
680 
681  priv = dev->priv;
682  priv->pdev = pdev;
683  dev->netdev->dev = &pdev->dev;
684 
685  priv->map = (struct rtl818x_csr *)pdev->ioaddr;
686  if (!priv->map) {
687  DBG("rtl818x: cannot find device memory\n");
688  err = -ENXIO;
689  goto err_free_dev;
690  }
691 
692  reg = rtl818x_ioread32(priv, &priv->map->TX_CONF);
694  switch (reg) {
696  chip_name = "0";
697  break;
699  chip_name = "0vF";
700  break;
702  chip_name = "5";
703  break;
705  chip_name = "5vD";
706  break;
707  default:
708  DBG("rtl818x: Unknown chip! (0x%x)\n", reg >> 25);
709  err = -ENOSYS;
710  goto err_free_dev;
711  }
712 
714 
715  hwinfo->bands = NET80211_BAND_BIT_2GHZ;
716  hwinfo->flags = NET80211_HW_RX_HAS_FCS;
717  hwinfo->signal_type = NET80211_SIGNAL_ARBITRARY;
718  hwinfo->signal_max = 65;
719  hwinfo->channel_change_time = 1000;
720 
722  sizeof(*rtl818x_rates) * RTL818X_NR_RATES);
723 
724  if (priv->r8185) {
727  } else {
728  hwinfo->modes = NET80211_MODE_B;
730  }
731 
732  priv->spibit.basher.op = &rtl818x_basher_ops;
733  priv->spibit.bus.mode = SPI_MODE_THREEWIRE;
734  init_spi_bit_basher(&priv->spibit);
735 
736  DBG2("rtl818x RX_CONF: %08x\n", rtl818x_ioread32(priv, &priv->map->RX_CONF));
737 
738  if (rtl818x_ioread32(priv, &priv->map->RX_CONF) & (1 << 6))
739  init_at93c66(&priv->eeprom, 16);
740  else
741  init_at93c46(&priv->eeprom, 16);
742  priv->eeprom.bus = &priv->spibit.bus;
743 
745  rtl818x_ioread8(priv, &priv->map->EEPROM_CMD);
746  udelay(10);
747 
748  nvs_read(&priv->eeprom.nvs, 0x06, &eeprom_val, 2);
749  DBG2("rtl818x eeprom val = %04x\n", eeprom_val);
750  eeprom_val &= 0xFF;
751 
752  priv->rf = NULL;
754  if (rf->id == eeprom_val) {
755  priv->rf = rf;
756  break;
757  }
758  }
759 
760  if (!priv->rf) {
761 #if DBGLVL_MAX
762  if (eeprom_val < RTL818X_NR_RF_NAMES &&
763  rtl818x_rf_names[eeprom_val] != NULL)
764  DBG("rtl818x: %s RF frontend not supported!\n",
765  rtl818x_rf_names[eeprom_val]);
766  else
767  DBG("rtl818x: RF frontend #%d not recognized!\n",
768  eeprom_val);
769 #endif
770 
771  err = -ENOSYS;
772  goto err_free_dev;
773  }
774 
775  nvs_read(&priv->eeprom.nvs, 0x17, &eeprom_val, 2);
776  priv->csthreshold = eeprom_val >> 8;
777  if (!priv->r8185) {
778  nvs_read(&priv->eeprom.nvs, 0xD, &priv->anaparam, 4);
779  nvs_read(&priv->eeprom.nvs, 0x19, &priv->rfparam, 2);
780  priv->anaparam = le32_to_cpu(priv->anaparam);
781  priv->rfparam = le16_to_cpu(priv->rfparam);
782  }
783 
784  /* read the MAC address */
785  nvs_read(&priv->eeprom.nvs, 0x7, hwinfo->hwaddr, 6);
786 
787  /* CCK TX power */
788  for (i = 0; i < 14; i += 2) {
789  u16 txpwr;
790  nvs_read(&priv->eeprom.nvs, 0x10 + (i >> 1), &txpwr, 2);
791  priv->txpower[i] = txpwr & 0xFF;
792  priv->txpower[i + 1] = txpwr >> 8;
793  }
794 
795  /* OFDM TX power */
796  if (priv->r8185) {
797  for (i = 0; i < 14; i += 2) {
798  u16 txpwr;
799  nvs_read(&priv->eeprom.nvs, 0x20 + (i >> 1), &txpwr, 2);
800  priv->txpower[i] |= (txpwr & 0xFF) << 8;
801  priv->txpower[i + 1] |= txpwr & 0xFF00;
802  }
803  }
804 
806 
807  err = net80211_register(dev, &rtl818x_operations, hwinfo);
808  if (err) {
809  DBG("rtl818x: cannot register device\n");
810  goto err_free_dev;
811  }
812 
813  free(hwinfo);
814 
815  DBG("rtl818x: Realtek RTL818%s (RF chip %s) with address %s\n",
816  chip_name, priv->rf->name, netdev_addr(dev->netdev));
817 
818  return 0;
819 
820  err_free_dev:
821  pci_set_drvdata(pdev, NULL);
822  net80211_free(dev);
823  err_alloc_dev:
824  free(hwinfo);
825  err_alloc_hwinfo:
826  return err;
827 }
uint16_t u16
Definition: stdint.h:22
int modes
A bitwise OR of the 802.11x modes supported by this device.
Definition: net80211.h:450
void net80211_free(struct net80211_device *dev)
Free 802.11 device.
Definition: net80211.c:839
static unsigned int unsigned int reg
Definition: myson.h:162
static u8 rtl818x_ioread8(struct rtl818x_priv *priv __unused, u8 *addr)
Definition: rtl818x.h:316
#define le32_to_cpu(value)
Definition: byteswap.h:114
#define RTL818X_TX_CONF_R8185_D
Definition: rtl818x.h:77
unsigned long ioaddr
I/O address.
Definition: pci.h:226
enum net80211_hw_info::@641 flags
A set of flags indicating peculiarities of this device.
static void rtl818x_iowrite8(struct rtl818x_priv *priv __unused, u8 *addr, u8 val)
Definition: rtl818x.h:331
static const u16 rtl818x_rates[]
Definition: rtl818x.c:39
#define RTL818X_TX_CONF_R8185_ABC
Definition: rtl818x.h:76
static struct bit_basher_operations rtl818x_basher_ops
Definition: rtl818x.c:628
unsigned signal_max
Maximum signal in arbitrary cases.
Definition: net80211.h:495
#define RTL818X_TX_CONF_R8180_ABCD
Definition: rtl818x.h:74
#define RTL818X_RF_DRIVERS
Definition: rtl818x.h:349
void adjust_pci_device(struct pci_device *pci)
Enable PCI device.
Definition: pci.c:241
static const char * netdev_addr(struct net_device *netdev)
Get printable network device link-layer address.
Definition: netdevice.h:542
struct device dev
Generic device.
Definition: pci.h:213
struct net80211_device_operations rtl818x_operations
Definition: rtl818x.c:645
#define NET80211_BAND_2GHZ
The 2.4 GHz ISM band, unlicensed in most countries.
Definition: net80211.h:45
u16 rates[NET80211_NR_BANDS][NET80211_MAX_RATES]
List of transmission rates supported by the card, indexed by band.
Definition: net80211.h:508
static void pci_set_drvdata(struct pci_device *pci, void *priv)
Set PCI driver-private data.
Definition: pci.h:366
#define ENOMEM
Not enough space.
Definition: errno.h:535
#define RTL818X_NR_B_RATES
Definition: rtl818x.c:44
void * memcpy(void *dest, const void *src, size_t len) __nonnull
enum net80211_hw_info::@642 signal_type
Signal strength information that can be provided by the device.
Information on the capabilities of an 802.11 hardware device.
Definition: net80211.h:436
u8 hwaddr[ETH_ALEN]
Default hardware MAC address.
Definition: net80211.h:447
void init_spi_bit_basher(struct spi_bit_basher *spibit)
Initialise SPI bit-bashing interface.
Definition: spi_bit.c:235
int nr_rates[NET80211_NR_BANDS]
Number of supported rates, indexed by band.
Definition: net80211.h:511
void udelay(unsigned long usecs)
Delay for a fixed number of microseconds.
Definition: timer.c:61
#define RTL818X_TX_CONF_R8180_F
Definition: rtl818x.h:75
#define RTL818X_EEPROM_CMD_PROGRAM
Definition: rtl818x.h:110
void * priv
Driver private data.
Definition: net80211.h:798
struct net80211_device * net80211_alloc(size_t priv_size)
Allocate 802.11 device.
Definition: net80211.c:755
static void(* free)(struct refcnt *refcnt))
Definition: refcnt.h:55
void * zalloc(size_t size)
Allocate cleared memory.
Definition: malloc.c:662
#define RTL818X_TX_CONF_HWVER_MASK
Definition: rtl818x.h:80
Structure encapsulating the complete state of an 802.11 device.
Definition: net80211.h:786
#define for_each_table_entry(pointer, table)
Iterate through all entries within a linker table.
Definition: tables.h:386
#define NET80211_MODE_B
802.11b: 1-11 Mbps operation using DSSS/CCK signaling on the 2.4GHz band
Definition: net80211.h:66
#define le16_to_cpu(value)
Definition: byteswap.h:113
struct device * dev
Underlying hardware device.
Definition: netdevice.h:365
struct net_device * netdev
The net_device that wraps us.
Definition: net80211.h:789
#define ENXIO
No such device or address.
Definition: errno.h:600
static struct tlan_private * priv
Definition: tlan.c:225
#define RTL818X_EEPROM_CMD_NORMAL
Definition: rtl818x.h:108
#define NET80211_BAND_BIT_2GHZ
Bitmask for the 2GHz band.
Definition: net80211.h:52
#define ENOSYS
Function not implemented.
Definition: errno.h:565
int nvs_read(struct nvs_device *nvs, unsigned int address, void *data, size_t len)
Read from non-volatile storage device.
Definition: nvs.c:76
int bands
A bitwise OR of the bands on which this device can communicate.
Definition: net80211.h:453
#define SPI_MODE_THREEWIRE
Threewire-compatible mode.
Definition: spi.h:199
#define DBG(...)
Print a debugging message.
Definition: compiler.h:498
#define NULL
NULL pointer (VOID *)
Definition: Base.h:322
unsigned channel_change_time
Estimate of the time required to change channels, in microseconds.
Definition: net80211.h:518
#define NET80211_MODE_G
802.11g: 54 Mbps operation using ERP/OFDM signaling on the 2.4GHz band
Definition: net80211.h:69
#define RTL818X_NR_RATES
Definition: rtl818x.c:45
uint32_t u32
Definition: stdint.h:24
static u32 rtl818x_ioread32(struct rtl818x_priv *priv __unused, u32 *addr)
Definition: rtl818x.h:326
int net80211_register(struct net80211_device *dev, struct net80211_device_operations *ops, struct net80211_hw_info *hw)
Register 802.11 device with network stack.
Definition: net80211.c:792
#define DBG2(...)
Definition: compiler.h:515
if(natsemi->flags &NATSEMI_64BIT) return 1

References adjust_pci_device(), net80211_hw_info::bands, net80211_hw_info::channel_change_time, DBG, DBG2, pci_device::dev, net_device::dev, ENOMEM, ENOSYS, ENXIO, net80211_hw_info::flags, for_each_table_entry, free, net80211_hw_info::hwaddr, rtl818x_rf_ops::id, if(), init_spi_bit_basher(), pci_device::ioaddr, le16_to_cpu, le32_to_cpu, memcpy(), net80211_hw_info::modes, net80211_alloc(), NET80211_BAND_2GHZ, NET80211_BAND_BIT_2GHZ, net80211_free(), NET80211_MODE_B, NET80211_MODE_G, net80211_register(), net80211_device::netdev, netdev_addr(), net80211_hw_info::nr_rates, NULL, nvs_read(), pci_set_drvdata(), priv, net80211_device::priv, net80211_hw_info::rates, reg, rtl818x_basher_ops, RTL818X_EEPROM_CMD_NORMAL, RTL818X_EEPROM_CMD_PROGRAM, rtl818x_ioread32(), rtl818x_ioread8(), rtl818x_iowrite8(), RTL818X_NR_B_RATES, RTL818X_NR_RATES, rtl818x_operations, rtl818x_rates, RTL818X_RF_DRIVERS, RTL818X_TX_CONF_HWVER_MASK, RTL818X_TX_CONF_R8180_ABCD, RTL818X_TX_CONF_R8180_F, RTL818X_TX_CONF_R8185_ABC, RTL818X_TX_CONF_R8185_D, net80211_hw_info::signal_max, net80211_hw_info::signal_type, SPI_MODE_THREEWIRE, udelay(), and zalloc().

◆ rtl818x_remove()

void rtl818x_remove ( struct pci_device pdev)

Definition at line 829 of file rtl818x.c.

830 {
831  struct net80211_device *dev = pci_get_drvdata(pdev);
832 
833  if (!dev)
834  return;
835 
836  net80211_unregister(dev);
837  net80211_free(dev);
838 }
void net80211_free(struct net80211_device *dev)
Free 802.11 device.
Definition: net80211.c:839
void net80211_unregister(struct net80211_device *dev)
Unregister 802.11 device from network stack.
Definition: net80211.c:825
Structure encapsulating the complete state of an 802.11 device.
Definition: net80211.h:786
static void * pci_get_drvdata(struct pci_device *pci)
Get PCI driver-private data.
Definition: pci.h:376

References net80211_free(), net80211_unregister(), and pci_get_drvdata().

Variable Documentation

◆ rtl818x_rates

const u16 rtl818x_rates[]
static
Initial value:
= {
10, 20, 55, 110,
60, 90, 120, 180, 240, 360, 480, 540,
0, 0, 0, 0,
}

Definition at line 39 of file rtl818x.c.

Referenced by rtl818x_config(), rtl818x_handle_rx(), and rtl818x_probe().

◆ rtl818x_eeprom_bits

const u8 rtl818x_eeprom_bits[]
static
Initial value:
= {
}
Master In Slave Out.
Definition: spi_bit.h:39
#define RTL818X_EEPROM_CMD_WRITE
Definition: rtl818x.h:105
#define RTL818X_EEPROM_CMD_CK
Definition: rtl818x.h:106
#define RTL818X_EEPROM_CMD_CS
Definition: rtl818x.h:107
#define SPI_BIT_SS(slave)
Determine bit index for a particular slave.
Definition: spi_bit.h:50
Master Out Slave In.
Definition: spi_bit.h:37
Serial clock.
Definition: spi_bit.h:35
#define RTL818X_EEPROM_CMD_READ
Definition: rtl818x.h:104

Definition at line 596 of file rtl818x.c.

Referenced by rtl818x_spi_read_bit(), and rtl818x_spi_write_bit().

◆ rtl818x_basher_ops

struct bit_basher_operations rtl818x_basher_ops
static
Initial value:
= {
}
static int rtl818x_spi_read_bit(struct bit_basher *basher, unsigned int bit_id)
Definition: rtl818x.c:603
static void rtl818x_spi_write_bit(struct bit_basher *basher, unsigned int bit_id, unsigned long data)
Definition: rtl818x.c:612

Definition at line 628 of file rtl818x.c.

Referenced by rtl818x_probe().

◆ rtl818x_operations

struct net80211_device_operations rtl818x_operations
Initial value:
= {
.open = rtl818x_start,
.close = rtl818x_stop,
.transmit = rtl818x_tx,
.poll = rtl818x_poll,
.irq = rtl818x_irq,
.config = rtl818x_config,
}
static void rtl818x_poll(struct net80211_device *dev)
Definition: rtl818x.c:146
static int rtl818x_tx(struct net80211_device *dev, struct io_buffer *iob)
Definition: rtl818x.c:165
static void rtl818x_stop(struct net80211_device *dev)
Definition: rtl818x.c:526
static int rtl818x_start(struct net80211_device *dev)
Definition: rtl818x.c:429
static void rtl818x_irq(struct net80211_device *dev, int enable)
Definition: rtl818x.c:411
static int rtl818x_config(struct net80211_device *dev, int changed)
Definition: rtl818x.c:549

Definition at line 645 of file rtl818x.c.

Referenced by rtl818x_probe().