iPXE
Functions | Variables
dwmac.c File Reference

Synopsys DesignWare MAC network driver. More...

#include <stdint.h>
#include <string.h>
#include <errno.h>
#include <byteswap.h>
#include <ipxe/netdevice.h>
#include <ipxe/ethernet.h>
#include <ipxe/if_ether.h>
#include <ipxe/iobuf.h>
#include <ipxe/timer.h>
#include <ipxe/devtree.h>
#include <ipxe/fdt.h>
#include "dwmac.h"

Go to the source code of this file.

Functions

 FILE_LICENCE (GPL2_OR_LATER_OR_UBDL)
 
static void dwmac_dump_mac (struct dwmac *dwmac)
 Dump MAC registers (for debugging) More...
 
static void dwmac_dump_dma (struct dwmac *dwmac)
 Dump DMA registers (for debugging) More...
 
static void dwmac_dump (struct dwmac *dwmac)
 Dump all registers (for debugging) More...
 
static int dwmac_reset (struct dwmac *dwmac)
 Reset hardware. More...
 
static void dwmac_check_link (struct net_device *netdev)
 Check link state. More...
 
static int dwmac_create_ring (struct dwmac *dwmac, struct dwmac_ring *ring)
 Create descriptor ring. More...
 
static void dwmac_destroy_ring (struct dwmac *dwmac, struct dwmac_ring *ring)
 Destroy descriptor ring. More...
 
static void dwmac_refill_rx (struct dwmac *dwmac)
 Refill receive descriptor ring. More...
 
static int dwmac_open (struct net_device *netdev)
 Open network device. More...
 
static void dwmac_close (struct net_device *netdev)
 Close network device. More...
 
static int dwmac_transmit (struct net_device *netdev, struct io_buffer *iobuf)
 Transmit packet. More...
 
static void dwmac_poll_tx (struct net_device *netdev)
 Poll for completed packets. More...
 
static void dwmac_poll_rx (struct net_device *netdev)
 Poll for received packets. More...
 
static void dwmac_poll (struct net_device *netdev)
 Poll for completed and received packets. More...
 
static int dwmac_probe (struct dt_device *dt, unsigned int offset)
 Probe devicetree device. More...
 
static void dwmac_remove (struct dt_device *dt)
 Remove devicetree device. More...
 

Variables

static struct net_device_operations dwmac_operations
 DesignWare MAC network device operations. More...
 
static const char * dwmac_ids []
 DesignWare MAC compatible model identifiers. More...
 
struct dt_driver dwmac_driver __dt_driver
 DesignWare MAC devicetree driver. More...
 

Detailed Description

Synopsys DesignWare MAC network driver.

Definition in file dwmac.c.

Function Documentation

◆ FILE_LICENCE()

FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL  )

◆ dwmac_dump_mac()

static void dwmac_dump_mac ( struct dwmac dwmac)
static

Dump MAC registers (for debugging)

Parameters
dwmacDesignWare MAC device

Definition at line 57 of file dwmac.c.

57  {
58 
59  /* Do nothing unless debugging is enabled */
60  if ( ! DBG_LOG )
61  return;
62 
63  /* Dump MAC registers */
64  DBGC ( dwmac, "DWMAC %s ver %08x cfg %08x flt %08x flo %08x\n",
66  readl ( dwmac->regs + DWMAC_CFG ),
68  readl ( dwmac->regs + DWMAC_FLOW ) );
69  DBGC ( dwmac, "DWMAC %s isr %08x dbg %08x gmi %08x\n",
71  readl ( dwmac->regs + DWMAC_DEBUG ),
72  readl ( dwmac->regs + DWMAC_GMII ) );
73 }
#define DWMAC_CFG
MAC configuration register.
Definition: dwmac.h:26
#define DWMAC_GMII
SGMII/RGMII status register.
Definition: dwmac.h:76
uint32_t readl(volatile uint32_t *io_addr)
Read 32-bit dword from memory-mapped device.
#define DWMAC_FILTER
MAC filter register.
Definition: dwmac.h:33
#define DBGC(...)
Definition: compiler.h:505
#define DWMAC_VER
Version register.
Definition: dwmac.h:40
A DesignWare MAC network card.
Definition: dwmac.h:235
const char * name
Device name (for debugging)
Definition: dwmac.h:241
void * regs
Registers.
Definition: dwmac.h:237
#define DWMAC_DEBUG
Debug register.
Definition: dwmac.h:55
#define DWMAC_FLOW
Flow control register.
Definition: dwmac.h:37
#define DBG_LOG
Definition: compiler.h:317
#define DWMAC_ISR
Interrupt status register.
Definition: dwmac.h:58

References DBG_LOG, DBGC, DWMAC_CFG, DWMAC_DEBUG, DWMAC_FILTER, DWMAC_FLOW, DWMAC_GMII, DWMAC_ISR, DWMAC_VER, dwmac::name, readl(), and dwmac::regs.

Referenced by dwmac_dump().

◆ dwmac_dump_dma()

static void dwmac_dump_dma ( struct dwmac dwmac)
static

Dump DMA registers (for debugging)

Parameters
dwmacDesignWare MAC device

Definition at line 80 of file dwmac.c.

80  {
82 
83  /* Do nothing unless debugging is enabled */
84  if ( ! DBG_LOG )
85  return;
86 
87  /* Dump DMA registers */
89  DBGC ( dwmac, "DWMAC %s bus %08x fea %08x axi %08x ahb %08x\n",
92  readl ( dwmac->regs + DWMAC_AXI ),
93  readl ( dwmac->regs + DWMAC_AHB ) );
94  DBGC ( dwmac, "DWMAC %s opm %08x sta %08x drp %08x\n",
95  dwmac->name, readl ( dwmac->regs + DWMAC_OP ),
96  status, readl ( dwmac->regs + DWMAC_DROP ) );
97  DBGC ( dwmac, "DWMAC %s txb %08x txd %08x txb %08x\n",
100  readl ( dwmac->regs + DWMAC_TXBUF ) );
101  DBGC ( dwmac, "DWMAC %s rxb %08x rxd %08x rxb %08x\n",
103  readl ( dwmac->regs + DWMAC_RXDESC ),
104  readl ( dwmac->regs + DWMAC_RXBUF ) );
105 
106  /* Clear sticky bits in status register, since nothing else will */
107  writel ( status, ( dwmac->regs + DWMAC_STATUS ) );
108 }
#define DWMAC_AXI
AXI bus mode register.
Definition: dwmac.h:122
uint32_t readl(volatile uint32_t *io_addr)
Read 32-bit dword from memory-mapped device.
#define DBGC(...)
Definition: compiler.h:505
#define DWMAC_OP
Operation mode register.
Definition: dwmac.h:112
#define DWMAC_BUS
Bus mode register.
Definition: dwmac.h:84
#define DWMAC_RXBUF
Current receive buffer address register.
Definition: dwmac.h:137
#define DWMAC_RXBASE
Receive descriptor list address register.
Definition: dwmac.h:102
A DesignWare MAC network card.
Definition: dwmac.h:235
const char * name
Device name (for debugging)
Definition: dwmac.h:241
void writel(uint32_t data, volatile uint32_t *io_addr)
Write 32-bit dword to memory-mapped device.
#define DWMAC_RXDESC
Current receive descriptor register.
Definition: dwmac.h:131
#define DWMAC_DROP
Packet drop counter register.
Definition: dwmac.h:119
unsigned int uint32_t
Definition: stdint.h:12
uint8_t status
Status.
Definition: ena.h:16
#define DWMAC_AHB
AHB or AXI status register.
Definition: dwmac.h:125
#define DWMAC_STATUS
Status register.
Definition: dwmac.h:108
#define DWMAC_TXDESC
Current transmit descriptor register.
Definition: dwmac.h:128
void * regs
Registers.
Definition: dwmac.h:237
#define DWMAC_FEATURE
Hardware feature register.
Definition: dwmac.h:140
#define DBG_LOG
Definition: compiler.h:317
#define DWMAC_TXBUF
Current transmit buffer address register.
Definition: dwmac.h:134
#define DWMAC_TXBASE
Transmit descriptor list address register.
Definition: dwmac.h:105

References DBG_LOG, DBGC, DWMAC_AHB, DWMAC_AXI, DWMAC_BUS, DWMAC_DROP, DWMAC_FEATURE, DWMAC_OP, DWMAC_RXBASE, DWMAC_RXBUF, DWMAC_RXDESC, DWMAC_STATUS, DWMAC_TXBASE, DWMAC_TXBUF, DWMAC_TXDESC, dwmac::name, readl(), dwmac::regs, status, and writel().

Referenced by dwmac_dump().

◆ dwmac_dump()

static void dwmac_dump ( struct dwmac dwmac)
static

Dump all registers (for debugging)

Parameters
dwmacDesignWare MAC device

Definition at line 115 of file dwmac.c.

115  {
116 
117  /* Dump MAC and DMA registers */
118  dwmac_dump_mac ( dwmac );
119  dwmac_dump_dma ( dwmac );
120 }
static void dwmac_dump_mac(struct dwmac *dwmac)
Dump MAC registers (for debugging)
Definition: dwmac.c:57
static void dwmac_dump_dma(struct dwmac *dwmac)
Dump DMA registers (for debugging)
Definition: dwmac.c:80
A DesignWare MAC network card.
Definition: dwmac.h:235

References dwmac_dump_dma(), and dwmac_dump_mac().

Referenced by dwmac_poll_rx(), and dwmac_poll_tx().

◆ dwmac_reset()

static int dwmac_reset ( struct dwmac dwmac)
static

Reset hardware.

Parameters
dwmacDesignWare MAC device
Return values
rcReturn status code

Definition at line 135 of file dwmac.c.

135  {
136  unsigned int i;
137  uint32_t bus;
138 
139  /* Trigger software reset */
141 
142  /* Wait for reset to complete */
143  for ( i = 0 ; i < DWMAC_RESET_MAX_WAIT_MS ; i++ ) {
144 
145  /* Delay */
146  mdelay ( 1 );
147 
148  /* Check for reset completion */
149  bus = readl ( dwmac->regs + DWMAC_BUS );
150  if ( ! ( bus & DWMAC_BUS_SWR ) )
151  return 0;
152  }
153 
154  DBGC ( dwmac, "DWMAC %s timed out waiting for reset\n",
155  dwmac->name );
156  return -ETIMEDOUT;
157 }
uint32_t readl(volatile uint32_t *io_addr)
Read 32-bit dword from memory-mapped device.
#define DBGC(...)
Definition: compiler.h:505
#define DWMAC_BUS
Bus mode register.
Definition: dwmac.h:84
A DesignWare MAC network card.
Definition: dwmac.h:235
const char * name
Device name (for debugging)
Definition: dwmac.h:241
void writel(uint32_t data, volatile uint32_t *io_addr)
Write 32-bit dword to memory-mapped device.
#define DWMAC_RESET_MAX_WAIT_MS
Time to wait for software reset to complete.
Definition: dwmac.h:93
unsigned int uint32_t
Definition: stdint.h:12
#define DWMAC_BUS_SWR
Software reset.
Definition: dwmac.h:90
void mdelay(unsigned long msecs)
Delay for a fixed number of milliseconds.
Definition: timer.c:78
void * regs
Registers.
Definition: dwmac.h:237
#define ETIMEDOUT
Connection timed out.
Definition: errno.h:669
uint8_t bus
Bus.
Definition: edd.h:14

References bus, DBGC, DWMAC_BUS, DWMAC_BUS_SWR, DWMAC_RESET_MAX_WAIT_MS, ETIMEDOUT, mdelay(), dwmac::name, readl(), dwmac::regs, and writel().

Referenced by dwmac_close(), dwmac_probe(), and dwmac_remove().

◆ dwmac_check_link()

static void dwmac_check_link ( struct net_device netdev)
static

Check link state.

Parameters
netdevNetwork device

Definition at line 171 of file dwmac.c.

171  {
172  struct dwmac *dwmac = netdev->priv;
173  uint32_t gmii;
174 
175  /* Read SGMII/RGMII link status */
176  gmii = readl ( dwmac->regs + DWMAC_GMII );
177  DBGC ( dwmac, "DWMAC %s GMII link status %#08x\n", dwmac->name, gmii );
178 
179  /* Update network device */
180  if ( gmii & DWMAC_GMII_LINK ) {
182  } else {
184  }
185 }
#define DWMAC_GMII
SGMII/RGMII status register.
Definition: dwmac.h:76
uint32_t readl(volatile uint32_t *io_addr)
Read 32-bit dword from memory-mapped device.
#define DBGC(...)
Definition: compiler.h:505
void netdev_link_down(struct net_device *netdev)
Mark network device as having link down.
Definition: netdevice.c:230
void * priv
Driver private data.
Definition: netdevice.h:431
A DesignWare MAC network card.
Definition: dwmac.h:235
static void netdev_link_up(struct net_device *netdev)
Mark network device as having link up.
Definition: netdevice.h:788
const char * name
Device name (for debugging)
Definition: dwmac.h:241
static struct net_device * netdev
Definition: gdbudp.c:52
unsigned int uint32_t
Definition: stdint.h:12
#define DWMAC_GMII_LINK
Link up.
Definition: dwmac.h:77
void * regs
Registers.
Definition: dwmac.h:237

References DBGC, DWMAC_GMII, DWMAC_GMII_LINK, dwmac::name, netdev, netdev_link_down(), netdev_link_up(), net_device::priv, readl(), and dwmac::regs.

Referenced by dwmac_open(), dwmac_poll(), and dwmac_probe().

◆ dwmac_create_ring()

static int dwmac_create_ring ( struct dwmac dwmac,
struct dwmac_ring ring 
)
static

Create descriptor ring.

Parameters
dwmacDesignWare MAC device
ringDescriptor ring
Return values
rcReturn status code

Definition at line 201 of file dwmac.c.

201  {
202  struct dwmac_descriptor *desc;
203  struct dwmac_descriptor *next;
205  unsigned int i;
206 
207  /* Allocate descriptor ring (on its own size) */
208  ring->desc = dma_alloc ( dwmac->dma, &ring->map, ring->len, ring->len );
209  if ( ! ring->desc )
210  return -ENOMEM;
211 
212  /* Initialise descriptor ring */
213  memset ( ring->desc, 0, ring->len );
214  for ( i = 0 ; i < ring->count ; i++ ) {
215  desc = &ring->desc[i];
216  desc->size = cpu_to_le16 ( DWMAC_RX_LEN |
218  desc->ctrl = ring->ctrl;
219  assert ( desc->ctrl & DWMAC_CTRL_CHAIN );
220  next = &ring->desc[ ( i + 1 ) & ( ring->count - 1 ) ];
221  desc->next = dma ( &ring->map, next );
222  }
223  wmb();
224 
225  /* Program ring address */
226  base = dma ( &ring->map, ring->desc );
227  assert ( base == ( ( uint32_t ) base ) );
228  writel ( base, ( dwmac->regs + DWMAC_DMA + ring->qbase ) );
229 
230  DBGC ( dwmac, "DWMAC %s ring %02x is at [%08lx,%08lx)\n",
231  dwmac->name, ring->qbase, virt_to_phys ( ring->desc ),
232  ( virt_to_phys ( ring->desc ) + ring->len ) );
233  return 0;
234 }
uint32_t base
Base.
Definition: librm.h:138
wmb()
#define DBGC(...)
Definition: compiler.h:505
size_t len
Length of descriptors.
Definition: dwmac.h:201
struct dwmac_descriptor * desc
Descriptors.
Definition: dwmac.h:186
A frame descriptor.
Definition: dwmac.h:148
uint8_t count
Number of descriptors.
Definition: dwmac.h:197
struct ena_llq_option desc
Descriptor counts.
Definition: ena.h:20
#define ENOMEM
Not enough space.
Definition: errno.h:534
#define DWMAC_CTRL_CHAIN
Chained descriptor.
Definition: dwmac.h:181
assert((readw(&hdr->flags) &(GTF_reading|GTF_writing))==0)
#define DWMAC_SIZE_RX_CHAIN
Buffer size.
Definition: dwmac.h:176
A DesignWare MAC network card.
Definition: dwmac.h:235
const char * name
Device name (for debugging)
Definition: dwmac.h:241
void writel(uint32_t data, volatile uint32_t *io_addr)
Write 32-bit dword to memory-mapped device.
#define DWMAC_DMA
DMA register block.
Definition: dwmac.h:80
unsigned int uint32_t
Definition: stdint.h:12
void * dma_alloc(struct dma_device *dma, struct dma_mapping *map, size_t len, size_t align)
Allocate and map DMA-coherent buffer.
uint32_t next
Next descriptor address.
Definition: dwmac.h:22
unsigned long physaddr_t
Definition: stdint.h:20
void * regs
Registers.
Definition: dwmac.h:237
uint8_t qbase
Queue base address register (within DMA block)
Definition: dwmac.h:195
#define DWMAC_RX_LEN
Length of receive buffers.
Definition: dwmac.h:214
#define cpu_to_le16(value)
Definition: byteswap.h:106
uint8_t ctrl
Default control flags.
Definition: dwmac.h:199
physaddr_t dma(struct dma_mapping *map, void *addr)
Get DMA address from virtual address.
struct dma_mapping map
Descriptor ring DMA mapping.
Definition: dwmac.h:188
void * memset(void *dest, int character, size_t len) __nonnull
struct dma_device * dma
DMA device.
Definition: dwmac.h:239

References assert(), base, dwmac_ring::count, cpu_to_le16, dwmac_ring::ctrl, DBGC, desc, dwmac_ring::desc, dwmac::dma, dma(), dma_alloc(), DWMAC_CTRL_CHAIN, DWMAC_DMA, DWMAC_RX_LEN, DWMAC_SIZE_RX_CHAIN, ENOMEM, dwmac_ring::len, dwmac_ring::map, memset(), dwmac::name, next, dwmac_ring::qbase, dwmac::regs, wmb(), and writel().

Referenced by dwmac_open().

◆ dwmac_destroy_ring()

static void dwmac_destroy_ring ( struct dwmac dwmac,
struct dwmac_ring ring 
)
static

Destroy descriptor ring.

Parameters
dwmacDesignWare MAC device
ringDescriptor ring

Definition at line 242 of file dwmac.c.

243  {
244 
245  /* Clear ring address */
246  writel ( 0, ( dwmac->regs + DWMAC_DMA + ring->qbase ) );
247 
248  /* Free descriptor ring */
249  dma_free ( &ring->map, ring->desc, ring->len );
250  ring->desc = NULL;
251  ring->prod = 0;
252  ring->cons = 0;
253 }
unsigned int cons
Consumer index.
Definition: dwmac.h:192
size_t len
Length of descriptors.
Definition: dwmac.h:201
struct dwmac_descriptor * desc
Descriptors.
Definition: dwmac.h:186
void dma_free(struct dma_mapping *map, void *addr, size_t len)
Unmap and free DMA-coherent buffer.
A DesignWare MAC network card.
Definition: dwmac.h:235
void writel(uint32_t data, volatile uint32_t *io_addr)
Write 32-bit dword to memory-mapped device.
#define DWMAC_DMA
DMA register block.
Definition: dwmac.h:80
void * regs
Registers.
Definition: dwmac.h:237
uint8_t qbase
Queue base address register (within DMA block)
Definition: dwmac.h:195
unsigned int prod
Producer index.
Definition: dwmac.h:190
#define NULL
NULL pointer (VOID *)
Definition: Base.h:321
struct dma_mapping map
Descriptor ring DMA mapping.
Definition: dwmac.h:188

References dwmac_ring::cons, dwmac_ring::desc, dma_free(), DWMAC_DMA, dwmac_ring::len, dwmac_ring::map, NULL, dwmac_ring::prod, dwmac_ring::qbase, dwmac::regs, and writel().

Referenced by dwmac_close(), and dwmac_open().

◆ dwmac_refill_rx()

static void dwmac_refill_rx ( struct dwmac dwmac)
static

Refill receive descriptor ring.

Parameters
dwmacDesignWare MAC device

Definition at line 260 of file dwmac.c.

260  {
261  struct dwmac_descriptor *rx;
262  struct io_buffer *iobuf;
263  unsigned int rx_idx;
264  unsigned int refilled = 0;
265 
266  /* Refill ring */
267  while ( ( dwmac->rx.prod - dwmac->rx.cons ) != DWMAC_NUM_RX_DESC ) {
268 
269  /* Allocate I/O buffer */
270  iobuf = alloc_rx_iob ( DWMAC_RX_LEN, dwmac->dma );
271  if ( ! iobuf ) {
272  /* Wait for next refill */
273  break;
274  }
275 
276  /* Get next receive descriptor */
277  rx_idx = ( dwmac->rx.prod++ % DWMAC_NUM_RX_DESC );
278  rx = &dwmac->rx.desc[rx_idx];
279 
280  /* Populate receive descriptor */
281  rx->addr = cpu_to_le32 ( iob_dma ( iobuf ) );
282  wmb();
283  rx->stat = cpu_to_le32 ( DWMAC_STAT_OWN );
284 
285  /* Record I/O buffer */
286  assert ( dwmac->rx_iobuf[rx_idx] == NULL );
287  dwmac->rx_iobuf[rx_idx] = iobuf;
288 
289  DBGC2 ( dwmac, "DWMAC %s RX %d is [%08lx,%08lx)\n",
290  dwmac->name, rx_idx, virt_to_phys ( iobuf->data ),
291  ( virt_to_phys ( iobuf->data ) + DWMAC_RX_LEN ) );
292  refilled++;
293  }
294 
295  /* Trigger poll */
296  if ( refilled ) {
297  wmb();
298  writel ( 0, ( dwmac->regs + DWMAC_RXPOLL ) );
299  }
300 }
wmb()
unsigned int cons
Consumer index.
Definition: dwmac.h:192
struct dwmac_descriptor * desc
Descriptors.
Definition: dwmac.h:186
A frame descriptor.
Definition: dwmac.h:148
assert((readw(&hdr->flags) &(GTF_reading|GTF_writing))==0)
A DesignWare MAC network card.
Definition: dwmac.h:235
struct io_buffer * rx_iobuf[DWMAC_NUM_RX_DESC]
Receive I/O buffers.
Definition: dwmac.h:248
const char * name
Device name (for debugging)
Definition: dwmac.h:241
void writel(uint32_t data, volatile uint32_t *io_addr)
Write 32-bit dword to memory-mapped device.
static __always_inline physaddr_t iob_dma(struct io_buffer *iobuf)
Get I/O buffer DMA address.
Definition: iobuf.h:267
#define cpu_to_le32(value)
Definition: byteswap.h:107
struct io_buffer * alloc_rx_iob(size_t len, struct dma_device *dma)
Allocate and map I/O buffer for receive DMA.
Definition: iobuf.c:187
#define DWMAC_RXPOLL
Receive poll demand register.
Definition: dwmac.h:99
#define DWMAC_NUM_RX_DESC
Number of receive descriptors.
Definition: dwmac.h:208
void * regs
Registers.
Definition: dwmac.h:237
#define DBGC2(...)
Definition: compiler.h:522
#define DWMAC_RX_LEN
Length of receive buffers.
Definition: dwmac.h:214
void * data
Start of data.
Definition: iobuf.h:52
u8 rx[WPA_TKIP_MIC_KEY_LEN]
MIC key for packets from the AP.
Definition: wpa.h:234
unsigned int prod
Producer index.
Definition: dwmac.h:190
#define NULL
NULL pointer (VOID *)
Definition: Base.h:321
struct dwmac_ring rx
Receive ring.
Definition: dwmac.h:246
#define DWMAC_STAT_OWN
Owned by hardware.
Definition: dwmac.h:164
struct dma_device * dma
DMA device.
Definition: dwmac.h:239
A persistent I/O buffer.
Definition: iobuf.h:37

References alloc_rx_iob(), assert(), dwmac_ring::cons, cpu_to_le32, io_buffer::data, DBGC2, dwmac_ring::desc, dwmac::dma, DWMAC_NUM_RX_DESC, DWMAC_RX_LEN, DWMAC_RXPOLL, DWMAC_STAT_OWN, iob_dma(), dwmac::name, NULL, dwmac_ring::prod, dwmac::regs, rx, dwmac::rx, dwmac::rx_iobuf, wmb(), and writel().

Referenced by dwmac_open(), and dwmac_poll().

◆ dwmac_open()

static int dwmac_open ( struct net_device netdev)
static

Open network device.

Parameters
netdevNetwork device
Return values
rcReturn status code

Definition at line 308 of file dwmac.c.

308  {
309  struct dwmac *dwmac = netdev->priv;
310  union dwmac_mac mac;
311  int rc;
312 
313  /* Create transmit descriptor ring */
314  if ( ( rc = dwmac_create_ring ( dwmac, &dwmac->tx ) ) != 0 )
315  goto err_create_tx;
316 
317  /* Create receive descriptor ring */
318  if ( ( rc = dwmac_create_ring ( dwmac, &dwmac->rx ) ) != 0 )
319  goto err_create_rx;
320 
321  /* Set MAC address */
322  memcpy ( mac.raw, netdev->ll_addr, ETH_ALEN );
323  writel ( mac.reg.addrl, ( dwmac->regs + DWMAC_ADDRL ) );
324  writel ( mac.reg.addrh, ( dwmac->regs + DWMAC_ADDRH ) );
325 
326  /* Enable promiscuous mode */
328 
329  /* Enable transmit and receive */
332  ( dwmac->regs + DWMAC_OP ) );
335  ( dwmac->regs + DWMAC_CFG ) );
336 
337  /* Refill receive descriptor ring */
339 
340  /* Update link state */
342 
343  return 0;
344 
346  err_create_rx:
348  err_create_tx:
349  return rc;
350 }
#define DWMAC_CFG
MAC configuration register.
Definition: dwmac.h:26
#define DWMAC_FILTER_PR
Promiscuous mode.
Definition: dwmac.h:34
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
#define DWMAC_CFG_FD
Full duplex.
Definition: dwmac.h:28
#define DWMAC_OP_RXEN
RX enabled.
Definition: dwmac.h:116
#define DWMAC_FILTER
MAC filter register.
Definition: dwmac.h:33
#define DWMAC_OP
Operation mode register.
Definition: dwmac.h:112
uint8_t mac[ETH_ALEN]
MAC address.
Definition: ena.h:24
A DesignWare MAC address.
Definition: dwmac.h:67
void * memcpy(void *dest, const void *src, size_t len) __nonnull
#define DWMAC_CFG_RXEN
RX enabled.
Definition: dwmac.h:30
void * priv
Driver private data.
Definition: netdevice.h:431
A DesignWare MAC network card.
Definition: dwmac.h:235
void writel(uint32_t data, volatile uint32_t *io_addr)
Write 32-bit dword to memory-mapped device.
#define DWMAC_OP_RXSF
RX store and forward.
Definition: dwmac.h:113
static struct net_device * netdev
Definition: gdbudp.c:52
#define DWMAC_ADDRL
MAC address low register.
Definition: dwmac.h:64
#define DWMAC_OP_TXEN
TX enabled.
Definition: dwmac.h:115
#define DWMAC_CFG_DO
Disable RX own frames.
Definition: dwmac.h:27
#define DWMAC_OP_TXSF
TX store and forward.
Definition: dwmac.h:114
#define DWMAC_CFG_TXEN
TX enabled.
Definition: dwmac.h:29
#define ETH_ALEN
Definition: if_ether.h:8
static void dwmac_destroy_ring(struct dwmac *dwmac, struct dwmac_ring *ring)
Destroy descriptor ring.
Definition: dwmac.c:242
struct dwmac_ring tx
Transmit ring.
Definition: dwmac.h:244
static void dwmac_check_link(struct net_device *netdev)
Check link state.
Definition: dwmac.c:171
void * regs
Registers.
Definition: dwmac.h:237
static void dwmac_refill_rx(struct dwmac *dwmac)
Refill receive descriptor ring.
Definition: dwmac.c:260
#define DWMAC_ADDRH
MAC address high register.
Definition: dwmac.h:61
uint8_t ll_addr[MAX_LL_ADDR_LEN]
Link-layer address.
Definition: netdevice.h:387
struct dwmac_ring rx
Receive ring.
Definition: dwmac.h:246
static int dwmac_create_ring(struct dwmac *dwmac, struct dwmac_ring *ring)
Create descriptor ring.
Definition: dwmac.c:201

References DWMAC_ADDRH, DWMAC_ADDRL, DWMAC_CFG, DWMAC_CFG_DO, DWMAC_CFG_FD, DWMAC_CFG_RXEN, DWMAC_CFG_TXEN, dwmac_check_link(), dwmac_create_ring(), dwmac_destroy_ring(), DWMAC_FILTER, DWMAC_FILTER_PR, DWMAC_OP, DWMAC_OP_RXEN, DWMAC_OP_RXSF, DWMAC_OP_TXEN, DWMAC_OP_TXSF, dwmac_refill_rx(), ETH_ALEN, net_device::ll_addr, mac, memcpy(), netdev, net_device::priv, rc, dwmac::regs, dwmac::rx, dwmac::tx, and writel().

◆ dwmac_close()

static void dwmac_close ( struct net_device netdev)
static

Close network device.

Parameters
netdevNetwork device

Definition at line 357 of file dwmac.c.

357  {
358  struct dwmac *dwmac = netdev->priv;
359  unsigned int i;
360 
361  /* Reset NIC */
362  dwmac_reset ( dwmac );
363 
364  /* Discard unused receive buffers */
365  for ( i = 0 ; i < DWMAC_NUM_RX_DESC ; i++ ) {
366  if ( dwmac->rx_iobuf[i] )
367  free_rx_iob ( dwmac->rx_iobuf[i] );
368  dwmac->rx_iobuf[i] = NULL;
369  }
370 
371  /* Destroy receive descriptor ring */
373 
374  /* Destroy transmit descriptor ring */
376 }
void * priv
Driver private data.
Definition: netdevice.h:431
A DesignWare MAC network card.
Definition: dwmac.h:235
struct io_buffer * rx_iobuf[DWMAC_NUM_RX_DESC]
Receive I/O buffers.
Definition: dwmac.h:248
static struct net_device * netdev
Definition: gdbudp.c:52
#define DWMAC_NUM_RX_DESC
Number of receive descriptors.
Definition: dwmac.h:208
static void dwmac_destroy_ring(struct dwmac *dwmac, struct dwmac_ring *ring)
Destroy descriptor ring.
Definition: dwmac.c:242
struct dwmac_ring tx
Transmit ring.
Definition: dwmac.h:244
static int dwmac_reset(struct dwmac *dwmac)
Reset hardware.
Definition: dwmac.c:135
void free_rx_iob(struct io_buffer *iobuf)
Unmap and free I/O buffer for receive DMA.
Definition: iobuf.c:214
#define NULL
NULL pointer (VOID *)
Definition: Base.h:321
struct dwmac_ring rx
Receive ring.
Definition: dwmac.h:246

References dwmac_destroy_ring(), DWMAC_NUM_RX_DESC, dwmac_reset(), free_rx_iob(), netdev, NULL, net_device::priv, dwmac::rx, dwmac::rx_iobuf, and dwmac::tx.

◆ dwmac_transmit()

static int dwmac_transmit ( struct net_device netdev,
struct io_buffer iobuf 
)
static

Transmit packet.

Parameters
netdevNetwork device
iobufI/O buffer
Return values
rcReturn status code

Definition at line 385 of file dwmac.c.

386  {
387  struct dwmac *dwmac = netdev->priv;
388  struct dwmac_descriptor *tx;
389  unsigned int tx_idx;
390 
391  /* Get next transmit descriptor */
392  if ( ( dwmac->tx.prod - dwmac->tx.cons ) >= DWMAC_NUM_TX_DESC ) {
393  DBGC ( dwmac, "DWMAC %s out of transmit descriptors\n",
394  dwmac->name );
395  return -ENOBUFS;
396  }
397  tx_idx = ( dwmac->tx.prod % DWMAC_NUM_TX_DESC );
398  tx = &dwmac->tx.desc[tx_idx];
399 
400  /* Update producer index */
401  dwmac->tx.prod++;
402 
403  /* Populate transmit descriptor */
404  tx->size = cpu_to_le16 ( iob_len ( iobuf ) );
405  tx->addr = cpu_to_le32 ( iob_dma ( iobuf ) );
406  wmb();
409  wmb();
410 
411  /* Initiate transmission */
412  writel ( 0, ( dwmac->regs + DWMAC_TXPOLL ) );
413 
414  DBGC2 ( dwmac, "DWMAC %s TX %d is [%08lx,%08lx)\n",
415  dwmac->name, tx_idx, virt_to_phys ( iobuf->data ),
416  ( virt_to_phys ( iobuf->data ) + iob_len ( iobuf ) ) );
417  return 0;
418 }
wmb()
#define DWMAC_NUM_TX_DESC
Number of transmit descriptors.
Definition: dwmac.h:205
unsigned int cons
Consumer index.
Definition: dwmac.h:192
#define DBGC(...)
Definition: compiler.h:505
struct dwmac_descriptor * desc
Descriptors.
Definition: dwmac.h:186
A frame descriptor.
Definition: dwmac.h:148
void * priv
Driver private data.
Definition: netdevice.h:431
A DesignWare MAC network card.
Definition: dwmac.h:235
const char * name
Device name (for debugging)
Definition: dwmac.h:241
void writel(uint32_t data, volatile uint32_t *io_addr)
Write 32-bit dword to memory-mapped device.
static struct net_device * netdev
Definition: gdbudp.c:52
static __always_inline physaddr_t iob_dma(struct io_buffer *iobuf)
Get I/O buffer DMA address.
Definition: iobuf.h:267
#define DWMAC_STAT_TX_CHAIN
Chained descriptor (TX)
Definition: dwmac.h:167
#define cpu_to_le32(value)
Definition: byteswap.h:107
static size_t iob_len(struct io_buffer *iobuf)
Calculate length of data in an I/O buffer.
Definition: iobuf.h:159
#define DWMAC_STAT_TX_LAST
Last segment (TX)
Definition: dwmac.h:165
struct dwmac_ring tx
Transmit ring.
Definition: dwmac.h:244
void * regs
Registers.
Definition: dwmac.h:237
#define ENOBUFS
No buffer space available.
Definition: errno.h:498
#define DBGC2(...)
Definition: compiler.h:522
void * data
Start of data.
Definition: iobuf.h:52
#define DWMAC_TXPOLL
Transmit poll demand register.
Definition: dwmac.h:96
#define cpu_to_le16(value)
Definition: byteswap.h:106
unsigned int prod
Producer index.
Definition: dwmac.h:190
#define DWMAC_STAT_TX_FIRST
First segment (TX)
Definition: dwmac.h:166
#define DWMAC_STAT_OWN
Owned by hardware.
Definition: dwmac.h:164
u8 tx[WPA_TKIP_MIC_KEY_LEN]
MIC key for packets to the AP.
Definition: wpa.h:237

References dwmac_ring::cons, cpu_to_le16, cpu_to_le32, io_buffer::data, DBGC, DBGC2, dwmac_ring::desc, DWMAC_NUM_TX_DESC, DWMAC_STAT_OWN, DWMAC_STAT_TX_CHAIN, DWMAC_STAT_TX_FIRST, DWMAC_STAT_TX_LAST, DWMAC_TXPOLL, ENOBUFS, iob_dma(), iob_len(), dwmac::name, netdev, net_device::priv, dwmac_ring::prod, dwmac::regs, tx, dwmac::tx, wmb(), and writel().

◆ dwmac_poll_tx()

static void dwmac_poll_tx ( struct net_device netdev)
static

Poll for completed packets.

@V netdev Network device

Definition at line 425 of file dwmac.c.

425  {
426  struct dwmac *dwmac = netdev->priv;
427  struct dwmac_descriptor *tx;
428  unsigned int tx_idx;
429 
430  /* Check for completed packets */
431  while ( dwmac->tx.cons != dwmac->tx.prod ) {
432 
433  /* Get next transmit descriptor */
434  tx_idx = ( dwmac->tx.cons % DWMAC_NUM_TX_DESC );
435  tx = &dwmac->tx.desc[tx_idx];
436 
437  /* Stop if descriptor is still owned by hardware */
438  if ( tx->stat & cpu_to_le32 ( DWMAC_STAT_OWN ) )
439  return;
440  dwmac->tx.cons++;
441 
442  /* Report completion */
443  if ( tx->stat & cpu_to_le32 ( DWMAC_STAT_ERR ) ) {
444  DBGC ( dwmac, "DWMAC %s TX %d error %#08x\n",
445  dwmac->name, tx_idx, le32_to_cpu ( tx->stat ) );
446  dwmac_dump ( dwmac );
448  } else {
449  DBGC2 ( dwmac, "DWMAC %s TX %d complete\n",
450  dwmac->name, tx_idx );
452  }
453  }
454 }
#define DWMAC_NUM_TX_DESC
Number of transmit descriptors.
Definition: dwmac.h:205
#define le32_to_cpu(value)
Definition: byteswap.h:113
unsigned int cons
Consumer index.
Definition: dwmac.h:192
static void netdev_tx_complete_next(struct net_device *netdev)
Complete network transmission.
Definition: netdevice.h:778
static void dwmac_dump(struct dwmac *dwmac)
Dump all registers (for debugging)
Definition: dwmac.c:115
#define DBGC(...)
Definition: compiler.h:505
struct dwmac_descriptor * desc
Descriptors.
Definition: dwmac.h:186
void netdev_tx_complete_next_err(struct net_device *netdev, int rc)
Complete network transmission.
Definition: netdevice.c:509
A frame descriptor.
Definition: dwmac.h:148
void * priv
Driver private data.
Definition: netdevice.h:431
A DesignWare MAC network card.
Definition: dwmac.h:235
const char * name
Device name (for debugging)
Definition: dwmac.h:241
static struct net_device * netdev
Definition: gdbudp.c:52
#define DWMAC_STAT_ERR
Error summary.
Definition: dwmac.h:168
#define cpu_to_le32(value)
Definition: byteswap.h:107
struct dwmac_ring tx
Transmit ring.
Definition: dwmac.h:244
#define DBGC2(...)
Definition: compiler.h:522
#define EIO
Input/output error.
Definition: errno.h:433
unsigned int prod
Producer index.
Definition: dwmac.h:190
#define DWMAC_STAT_OWN
Owned by hardware.
Definition: dwmac.h:164
u8 tx[WPA_TKIP_MIC_KEY_LEN]
MIC key for packets to the AP.
Definition: wpa.h:237

References dwmac_ring::cons, cpu_to_le32, DBGC, DBGC2, dwmac_ring::desc, dwmac_dump(), DWMAC_NUM_TX_DESC, DWMAC_STAT_ERR, DWMAC_STAT_OWN, EIO, le32_to_cpu, dwmac::name, netdev, netdev_tx_complete_next(), netdev_tx_complete_next_err(), net_device::priv, dwmac_ring::prod, tx, and dwmac::tx.

Referenced by dwmac_poll().

◆ dwmac_poll_rx()

static void dwmac_poll_rx ( struct net_device netdev)
static

Poll for received packets.

Parameters
netdevNetwork device

Definition at line 461 of file dwmac.c.

461  {
462  struct dwmac *dwmac = netdev->priv;
463  struct dwmac_descriptor *rx;
464  struct io_buffer *iobuf;
465  unsigned int rx_idx;
466  uint32_t stat;
467  size_t len;
468 
469  /* Check for received packets */
470  while ( dwmac->rx.cons != dwmac->rx.prod ) {
471 
472  /* Get next receive descriptor */
473  rx_idx = ( dwmac->rx.cons % DWMAC_NUM_RX_DESC );
474  rx = &dwmac->rx.desc[rx_idx];
475 
476  /* Stop if descriptor is still in use */
477  if ( rx->stat & cpu_to_le32 ( DWMAC_STAT_OWN ) )
478  return;
479  dwmac->rx.cons++;
480 
481  /* Consume I/O buffer */
482  iobuf = dwmac->rx_iobuf[rx_idx];
483  assert ( iobuf != NULL );
484  dwmac->rx_iobuf[rx_idx] = NULL;
485 
486  /* Hand off to network stack */
487  stat = le32_to_cpu ( rx->stat );
490  if ( stat & DWMAC_STAT_ERR ) {
491  DBGC ( dwmac, "DWMAC %s RX %d error %#08x\n",
492  dwmac->name, rx_idx, stat );
493  dwmac_dump ( dwmac );
494  netdev_rx_err ( netdev, iobuf, -EIO );
495  } else {
496  len = ( DWMAC_STAT_RX_LEN ( stat ) - 4 /* CRC */ );
497  iob_put ( iobuf, len );
498  DBGC2 ( dwmac, "DWMAC %s RX %d complete (length "
499  "%zd)\n", dwmac->name, rx_idx, len );
500  netdev_rx ( netdev, iobuf );
501  }
502  }
503 }
#define iob_put(iobuf, len)
Definition: iobuf.h:124
void netdev_rx_err(struct net_device *netdev, struct io_buffer *iobuf, int rc)
Discard received packet.
Definition: netdevice.c:586
uint32_t stat
Completion status.
Definition: dwmac.h:12
#define le32_to_cpu(value)
Definition: byteswap.h:113
unsigned int cons
Consumer index.
Definition: dwmac.h:192
static void dwmac_dump(struct dwmac *dwmac)
Dump all registers (for debugging)
Definition: dwmac.c:115
#define DBGC(...)
Definition: compiler.h:505
struct dwmac_descriptor * desc
Descriptors.
Definition: dwmac.h:186
A frame descriptor.
Definition: dwmac.h:148
#define DWMAC_STAT_RX_LAST
Last segment (RX)
Definition: dwmac.h:170
assert((readw(&hdr->flags) &(GTF_reading|GTF_writing))==0)
void * priv
Driver private data.
Definition: netdevice.h:431
A DesignWare MAC network card.
Definition: dwmac.h:235
struct io_buffer * rx_iobuf[DWMAC_NUM_RX_DESC]
Receive I/O buffers.
Definition: dwmac.h:248
const char * name
Device name (for debugging)
Definition: dwmac.h:241
ring len
Length.
Definition: dwmac.h:231
static struct net_device * netdev
Definition: gdbudp.c:52
#define DWMAC_STAT_ERR
Error summary.
Definition: dwmac.h:168
#define cpu_to_le32(value)
Definition: byteswap.h:107
#define DWMAC_STAT_RX_FIRST
First segment (RX)
Definition: dwmac.h:169
unsigned int uint32_t
Definition: stdint.h:12
#define DWMAC_NUM_RX_DESC
Number of receive descriptors.
Definition: dwmac.h:208
void netdev_rx(struct net_device *netdev, struct io_buffer *iobuf)
Add packet to receive queue.
Definition: netdevice.c:548
#define DBGC2(...)
Definition: compiler.h:522
#define EIO
Input/output error.
Definition: errno.h:433
u8 rx[WPA_TKIP_MIC_KEY_LEN]
MIC key for packets from the AP.
Definition: wpa.h:234
unsigned int prod
Producer index.
Definition: dwmac.h:190
#define NULL
NULL pointer (VOID *)
Definition: Base.h:321
struct dwmac_ring rx
Receive ring.
Definition: dwmac.h:246
#define DWMAC_STAT_RX_LEN(x)
Frame length (RX)
Definition: dwmac.h:171
#define DWMAC_STAT_OWN
Owned by hardware.
Definition: dwmac.h:164
A persistent I/O buffer.
Definition: iobuf.h:37

References assert(), dwmac_ring::cons, cpu_to_le32, DBGC, DBGC2, dwmac_ring::desc, dwmac_dump(), DWMAC_NUM_RX_DESC, DWMAC_STAT_ERR, DWMAC_STAT_OWN, DWMAC_STAT_RX_FIRST, DWMAC_STAT_RX_LAST, DWMAC_STAT_RX_LEN, EIO, iob_put, le32_to_cpu, len, dwmac::name, netdev, netdev_rx(), netdev_rx_err(), NULL, net_device::priv, dwmac_ring::prod, rx, dwmac::rx, dwmac::rx_iobuf, and stat.

Referenced by dwmac_poll().

◆ dwmac_poll()

static void dwmac_poll ( struct net_device netdev)
static

Poll for completed and received packets.

Parameters
netdevNetwork device

Definition at line 510 of file dwmac.c.

510  {
511  struct dwmac *dwmac = netdev->priv;
513 
514  /* Check for link status changes */
516  if ( status & DWMAC_STATUS_LINK )
518 
519  /* Poll for TX competions, if applicable */
520  dwmac_poll_tx ( netdev );
521 
522  /* Poll for RX completions */
523  dwmac_poll_rx ( netdev );
524 
525  /* Refill RX ring */
527 }
static void dwmac_poll_rx(struct net_device *netdev)
Poll for received packets.
Definition: dwmac.c:461
static void dwmac_poll_tx(struct net_device *netdev)
Poll for completed packets.
Definition: dwmac.c:425
uint32_t readl(volatile uint32_t *io_addr)
Read 32-bit dword from memory-mapped device.
void * priv
Driver private data.
Definition: netdevice.h:431
A DesignWare MAC network card.
Definition: dwmac.h:235
#define DWMAC_STATUS_LINK
Link status change.
Definition: dwmac.h:109
static struct net_device * netdev
Definition: gdbudp.c:52
unsigned int uint32_t
Definition: stdint.h:12
uint8_t status
Status.
Definition: ena.h:16
#define DWMAC_STATUS
Status register.
Definition: dwmac.h:108
static void dwmac_check_link(struct net_device *netdev)
Check link state.
Definition: dwmac.c:171
void * regs
Registers.
Definition: dwmac.h:237
static void dwmac_refill_rx(struct dwmac *dwmac)
Refill receive descriptor ring.
Definition: dwmac.c:260

References dwmac_check_link(), dwmac_poll_rx(), dwmac_poll_tx(), dwmac_refill_rx(), DWMAC_STATUS, DWMAC_STATUS_LINK, netdev, net_device::priv, readl(), dwmac::regs, and status.

◆ dwmac_probe()

static int dwmac_probe ( struct dt_device dt,
unsigned int  offset 
)
static

Probe devicetree device.

Parameters
dtDevicetree device
offsetStarting node offset
Return values
rcReturn status code

Definition at line 551 of file dwmac.c.

551  {
552  struct net_device *netdev;
553  struct dwmac *dwmac;
554  union dwmac_mac mac;
556  int rc;
557 
558  /* Allocate and initialise net device */
559  netdev = alloc_etherdev ( sizeof ( *dwmac ) );
560  if ( ! netdev ) {
561  rc = -ENOMEM;
562  goto err_alloc;
563  }
565  dwmac = netdev->priv;
566  dt_set_drvdata ( dt, netdev );
567  netdev->dev = &dt->dev;
568  netdev->dma = &dt->dma;
569  memset ( dwmac, 0, sizeof ( *dwmac ) );
570  dwmac->dma = &dt->dma;
571  dwmac->name = netdev->dev->name;
572  dwmac_init_ring ( &dwmac->tx, DWMAC_NUM_TX_DESC, DWMAC_TXBASE,
574  DWMAC_CTRL_CHAIN ) );
575  dwmac_init_ring ( &dwmac->rx, DWMAC_NUM_RX_DESC, DWMAC_RXBASE,
577 
578  /* Map registers */
580  if ( ! dwmac->regs ) {
581  rc = -ENODEV;
582  goto err_ioremap;
583  }
584  version = readl ( dwmac->regs + DWMAC_VER );
585  DBGC ( dwmac, "DWMAC %s version %x.%x (user %x.%x)\n", dwmac->name,
590 
591  /* Fetch devicetree MAC address */
592  if ( ( rc = fdt_mac ( &sysfdt, offset, netdev ) ) != 0 ) {
593  DBGC ( dwmac, "DWMAC %s could not fetch MAC: %s\n",
594  dwmac->name, strerror ( rc ) );
595  goto err_mac;
596  }
597 
598  /* Fetch current MAC address, if set */
599  mac.reg.addrl = readl ( dwmac->regs + DWMAC_ADDRL );
600  mac.reg.addrh = readl ( dwmac->regs + DWMAC_ADDRH );
601  memcpy ( netdev->ll_addr, mac.raw, ETH_ALEN );
602 
603  /* Reset the NIC */
604  if ( ( rc = dwmac_reset ( dwmac ) ) != 0 )
605  goto err_reset;
606 
607  /* Register network device */
608  if ( ( rc = register_netdev ( netdev ) ) != 0 )
609  goto err_register_netdev;
610 
611  /* Update link state */
613 
614  return 0;
615 
617  err_register_netdev:
618  dwmac_reset ( dwmac );
619  err_reset:
620  err_mac:
621  iounmap ( dwmac->regs );
622  err_ioremap:
624  netdev_put ( netdev );
625  err_alloc:
626  return rc;
627 }
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
static struct net_device_operations dwmac_operations
DesignWare MAC network device operations.
Definition: dwmac.c:530
#define DWMAC_NUM_TX_DESC
Number of transmit descriptors.
Definition: dwmac.h:205
uint32_t readl(volatile uint32_t *io_addr)
Read 32-bit dword from memory-mapped device.
#define DBGC(...)
Definition: compiler.h:505
char name[40]
Name.
Definition: device.h:78
struct dma_device * dma
DMA device.
Definition: netdevice.h:366
uint8_t mac[ETH_ALEN]
MAC address.
Definition: ena.h:24
int fdt_mac(struct fdt *fdt, unsigned int offset, struct net_device *netdev)
Get MAC address from property.
Definition: fdt.c:866
struct device dev
Generic device.
Definition: devtree.h:21
static void netdev_init(struct net_device *netdev, struct net_device_operations *op)
Initialise a network device.
Definition: netdevice.h:518
A DesignWare MAC address.
Definition: dwmac.h:67
#define DWMAC_VER_CORE_MINOR(x)
Core minor version.
Definition: dwmac.h:50
#define ENOMEM
Not enough space.
Definition: errno.h:534
#define DWMAC_CTRL_CHAIN
Chained descriptor.
Definition: dwmac.h:181
#define DWMAC_VER
Version register.
Definition: dwmac.h:40
void * memcpy(void *dest, const void *src, size_t len) __nonnull
#define DWMAC_RXBASE
Receive descriptor list address register.
Definition: dwmac.h:102
#define DWMAC_VER_CORE_MAJOR(x)
Core major version.
Definition: dwmac.h:47
u32 version
Driver version.
Definition: ath9k_hw.c:1983
static void netdev_put(struct net_device *netdev)
Drop reference to network device.
Definition: netdevice.h:575
void * priv
Driver private data.
Definition: netdevice.h:431
A DesignWare MAC network card.
Definition: dwmac.h:235
const char * name
Device name (for debugging)
Definition: dwmac.h:241
static struct net_device * netdev
Definition: gdbudp.c:52
#define DWMAC_ADDRL
MAC address low register.
Definition: dwmac.h:64
#define DWMAC_REG_LEN
I/O region length.
Definition: dwmac.h:19
void unregister_netdev(struct net_device *netdev)
Unregister network device.
Definition: netdevice.c:941
char * strerror(int errno)
Retrieve string representation of error number.
Definition: strerror.c:78
static void dt_set_drvdata(struct dt_device *dt, void *priv)
Set devicetree driver-private data.
Definition: devtree.h:66
int register_netdev(struct net_device *netdev)
Register network device.
Definition: netdevice.c:759
A network device.
Definition: netdevice.h:352
#define ENODEV
No such device.
Definition: errno.h:509
static void netdev_nullify(struct net_device *netdev)
Stop using a network device.
Definition: netdevice.h:531
#define DWMAC_VER_USER_MAJOR(x)
User major version.
Definition: dwmac.h:41
#define ETH_ALEN
Definition: if_ether.h:8
unsigned int uint32_t
Definition: stdint.h:12
#define DWMAC_NUM_RX_DESC
Number of receive descriptors.
Definition: dwmac.h:208
struct device * dev
Underlying hardware device.
Definition: netdevice.h:364
struct dwmac_ring tx
Transmit ring.
Definition: dwmac.h:244
static void dwmac_check_link(struct net_device *netdev)
Check link state.
Definition: dwmac.c:171
static int dwmac_reset(struct dwmac *dwmac)
Reset hardware.
Definition: dwmac.c:135
#define DWMAC_CTRL_TX_LAST
Last segment (TX)
Definition: dwmac.h:179
void * regs
Registers.
Definition: dwmac.h:237
#define DWMAC_VER_USER_MINOR(x)
User minor version.
Definition: dwmac.h:44
#define DWMAC_ADDRH
MAC address high register.
Definition: dwmac.h:61
#define DWMAC_REG_IDX
I/O region index.
Definition: dwmac.h:16
struct net_device * alloc_etherdev(size_t priv_size)
Allocate Ethernet device.
Definition: ethernet.c:264
void * dt_ioremap(struct dt_device *dt, unsigned int offset, unsigned int index, size_t len)
Map devicetree range.
Definition: devtree.c:52
void iounmap(volatile const void *io_addr)
Unmap I/O address.
uint8_t ll_addr[MAX_LL_ADDR_LEN]
Link-layer address.
Definition: netdevice.h:387
uint16_t offset
Offset to command line.
Definition: bzimage.h:8
struct dma_device dma
DMA device.
Definition: devtree.h:23
struct dwmac_ring rx
Receive ring.
Definition: dwmac.h:246
#define DWMAC_CTRL_TX_FIRST
First segment (TX)
Definition: dwmac.h:180
#define DWMAC_TXBASE
Transmit descriptor list address register.
Definition: dwmac.h:105
void * memset(void *dest, int character, size_t len) __nonnull
struct dma_device * dma
DMA device.
Definition: dwmac.h:239
struct fdt sysfdt
The system flattened device tree (if present)
Definition: fdt.c:44

References alloc_etherdev(), DBGC, dt_device::dev, net_device::dev, dt_device::dma, dwmac::dma, net_device::dma, dt_ioremap(), dt_set_drvdata(), DWMAC_ADDRH, DWMAC_ADDRL, dwmac_check_link(), DWMAC_CTRL_CHAIN, DWMAC_CTRL_TX_FIRST, DWMAC_CTRL_TX_LAST, DWMAC_NUM_RX_DESC, DWMAC_NUM_TX_DESC, dwmac_operations, DWMAC_REG_IDX, DWMAC_REG_LEN, dwmac_reset(), DWMAC_RXBASE, DWMAC_TXBASE, DWMAC_VER, DWMAC_VER_CORE_MAJOR, DWMAC_VER_CORE_MINOR, DWMAC_VER_USER_MAJOR, DWMAC_VER_USER_MINOR, ENODEV, ENOMEM, ETH_ALEN, fdt_mac(), iounmap(), net_device::ll_addr, mac, memcpy(), memset(), device::name, dwmac::name, netdev, netdev_init(), netdev_nullify(), netdev_put(), offset, net_device::priv, rc, readl(), register_netdev(), dwmac::regs, dwmac::rx, strerror(), sysfdt, dwmac::tx, unregister_netdev(), and version.

◆ dwmac_remove()

static void dwmac_remove ( struct dt_device dt)
static

Remove devicetree device.

Parameters
dtDevicetree device

Definition at line 634 of file dwmac.c.

634  {
635  struct net_device *netdev = dt_get_drvdata ( dt );
636  struct dwmac *dwmac = netdev->priv;
637 
638  /* Unregister network device */
640 
641  /* Reset card */
642  dwmac_reset ( dwmac );
643 
644  /* Free network device */
645  iounmap ( dwmac->regs );
647  netdev_put ( netdev );
648 }
static void netdev_put(struct net_device *netdev)
Drop reference to network device.
Definition: netdevice.h:575
void * priv
Driver private data.
Definition: netdevice.h:431
A DesignWare MAC network card.
Definition: dwmac.h:235
static struct net_device * netdev
Definition: gdbudp.c:52
void unregister_netdev(struct net_device *netdev)
Unregister network device.
Definition: netdevice.c:941
A network device.
Definition: netdevice.h:352
static void netdev_nullify(struct net_device *netdev)
Stop using a network device.
Definition: netdevice.h:531
static int dwmac_reset(struct dwmac *dwmac)
Reset hardware.
Definition: dwmac.c:135
void * regs
Registers.
Definition: dwmac.h:237
void iounmap(volatile const void *io_addr)
Unmap I/O address.
static void * dt_get_drvdata(struct dt_device *dt)
Get devicetree driver-private data.
Definition: devtree.h:76

References dt_get_drvdata(), dwmac_reset(), iounmap(), netdev, netdev_nullify(), netdev_put(), net_device::priv, dwmac::regs, and unregister_netdev().

Variable Documentation

◆ dwmac_operations

struct net_device_operations dwmac_operations
static
Initial value:
= {
.open = dwmac_open,
.close = dwmac_close,
.transmit = dwmac_transmit,
.poll = dwmac_poll,
}
static void dwmac_poll(struct net_device *netdev)
Poll for completed and received packets.
Definition: dwmac.c:510
static int dwmac_transmit(struct net_device *netdev, struct io_buffer *iobuf)
Transmit packet.
Definition: dwmac.c:385
static int dwmac_open(struct net_device *netdev)
Open network device.
Definition: dwmac.c:308
static void dwmac_close(struct net_device *netdev)
Close network device.
Definition: dwmac.c:357

DesignWare MAC network device operations.

Definition at line 530 of file dwmac.c.

Referenced by dwmac_probe().

◆ dwmac_ids

const char* dwmac_ids[]
static
Initial value:
= {
"thead,light-dwmac",
"snps,dwmac",
}

DesignWare MAC compatible model identifiers.

Definition at line 651 of file dwmac.c.

◆ __dt_driver

struct dt_driver dwmac_driver __dt_driver
Initial value:
= {
.name = "dwmac",
.ids = dwmac_ids,
.id_count = ( sizeof ( dwmac_ids ) / sizeof ( dwmac_ids[0] ) ),
.probe = dwmac_probe,
}
static int dwmac_probe(struct dt_device *dt, unsigned int offset)
Probe devicetree device.
Definition: dwmac.c:551
static const char * dwmac_ids[]
DesignWare MAC compatible model identifiers.
Definition: dwmac.c:651
static struct xen_remove_from_physmap * remove
Definition: xenmem.h:39
static void dwmac_remove(struct dt_device *dt)
Remove devicetree device.
Definition: dwmac.c:634

DesignWare MAC devicetree driver.

Definition at line 657 of file dwmac.c.