iPXE
dwmac.c
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2025 Michael Brown <mbrown@fensystems.co.uk>.
3  *
4  * This program is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU General Public License as
6  * published by the Free Software Foundation; either version 2 of the
7  * License, or (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful, but
10  * WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12  * General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software
16  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
17  * 02110-1301, USA.
18  *
19  * You can also choose to distribute this program under the terms of
20  * the Unmodified Binary Distribution Licence (as given in the file
21  * COPYING.UBDL), provided that you have satisfied its requirements.
22  */
23 
24 FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
25 
26 #include <stdint.h>
27 #include <string.h>
28 #include <errno.h>
29 #include <byteswap.h>
30 #include <ipxe/netdevice.h>
31 #include <ipxe/ethernet.h>
32 #include <ipxe/if_ether.h>
33 #include <ipxe/iobuf.h>
34 #include <ipxe/timer.h>
35 #include <ipxe/devtree.h>
36 #include <ipxe/fdt.h>
37 #include "dwmac.h"
38 
39 /** @file
40  *
41  * Synopsys DesignWare MAC network driver
42  *
43  */
44 
45 /******************************************************************************
46  *
47  * Debug
48  *
49  ******************************************************************************
50  */
51 
52 /**
53  * Dump MAC registers (for debugging)
54  *
55  * @v dwmac DesignWare MAC device
56  */
57 static void dwmac_dump_mac ( struct dwmac *dwmac ) {
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 }
74 
75 /**
76  * Dump DMA registers (for debugging)
77  *
78  * @v dwmac DesignWare MAC device
79  */
80 static void dwmac_dump_dma ( struct dwmac *dwmac ) {
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 }
109 
110 /**
111  * Dump all registers (for debugging)
112  *
113  * @v dwmac DesignWare MAC device
114  */
115 static void __attribute__ (( unused )) dwmac_dump ( struct dwmac *dwmac ) {
116 
117  /* Dump MAC and DMA registers */
118  dwmac_dump_mac ( dwmac );
119  dwmac_dump_dma ( dwmac );
120 }
121 
122 /******************************************************************************
123  *
124  * Device reset
125  *
126  ******************************************************************************
127  */
128 
129 /**
130  * Reset hardware
131  *
132  * @v dwmac DesignWare MAC device
133  * @ret rc Return status code
134  */
135 static int dwmac_reset ( struct dwmac *dwmac ) {
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 }
158 
159 /******************************************************************************
160  *
161  * Link state
162  *
163  ******************************************************************************
164  */
165 
166 /**
167  * Check link state
168  *
169  * @v netdev Network device
170  */
171 static void dwmac_check_link ( struct net_device *netdev ) {
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 }
186 
187 /******************************************************************************
188  *
189  * Network device interface
190  *
191  ******************************************************************************
192  */
193 
194 /**
195  * Create descriptor ring
196  *
197  * @v dwmac DesignWare MAC device
198  * @v ring Descriptor ring
199  * @ret rc Return status code
200  */
201 static int dwmac_create_ring ( struct dwmac *dwmac, struct dwmac_ring *ring ) {
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 }
235 
236 /**
237  * Destroy descriptor ring
238  *
239  * @v dwmac DesignWare MAC device
240  * @v ring Descriptor ring
241  */
242 static void dwmac_destroy_ring ( struct dwmac *dwmac,
243  struct dwmac_ring *ring ) {
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 }
254 
255 /**
256  * Refill receive descriptor ring
257  *
258  * @v dwmac DesignWare MAC device
259  */
260 static void dwmac_refill_rx ( struct dwmac *dwmac ) {
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 }
301 
302 /**
303  * Open network device
304  *
305  * @v netdev Network device
306  * @ret rc Return status code
307  */
308 static int dwmac_open ( struct net_device *netdev ) {
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 }
351 
352 /**
353  * Close network device
354  *
355  * @v netdev Network device
356  */
357 static void dwmac_close ( struct net_device *netdev ) {
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 }
377 
378 /**
379  * Transmit packet
380  *
381  * @v netdev Network device
382  * @v iobuf I/O buffer
383  * @ret rc Return status code
384  */
385 static int dwmac_transmit ( struct net_device *netdev,
386  struct io_buffer *iobuf ) {
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 }
419 
420 /**
421  * Poll for completed packets
422  *
423  * @V netdev Network device
424  */
425 static void dwmac_poll_tx ( struct net_device *netdev ) {
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 }
455 
456 /**
457  * Poll for received packets
458  *
459  * @v netdev Network device
460  */
461 static void dwmac_poll_rx ( struct net_device *netdev ) {
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 }
504 
505 /**
506  * Poll for completed and received packets
507  *
508  * @v netdev Network device
509  */
510 static void dwmac_poll ( struct net_device *netdev ) {
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 }
528 
529 /** DesignWare MAC network device operations */
531  .open = dwmac_open,
532  .close = dwmac_close,
533  .transmit = dwmac_transmit,
534  .poll = dwmac_poll,
535 };
536 
537 /******************************************************************************
538  *
539  * Devicetree interface
540  *
541  ******************************************************************************
542  */
543 
544 /**
545  * Probe devicetree device
546  *
547  * @v dt Devicetree device
548  * @v offset Starting node offset
549  * @ret rc Return status code
550  */
551 static int dwmac_probe ( struct dt_device *dt, unsigned int offset ) {
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 }
628 
629 /**
630  * Remove devicetree device
631  *
632  * @v dt Devicetree device
633  */
634 static void dwmac_remove ( struct dt_device *dt ) {
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 }
649 
650 /** DesignWare MAC compatible model identifiers */
651 static const char * dwmac_ids[] = {
652  "thead,light-dwmac",
653  "snps,dwmac",
654 };
655 
656 /** DesignWare MAC devicetree driver */
657 struct dt_driver dwmac_driver __dt_driver = {
658  .name = "dwmac",
659  .ids = dwmac_ids,
660  .id_count = ( sizeof ( dwmac_ids ) / sizeof ( dwmac_ids[0] ) ),
661  .probe = dwmac_probe,
662  .remove = dwmac_remove,
663 };
#define DWMAC_CFG
MAC configuration register.
Definition: dwmac.h:26
#define DWMAC_FILTER_PR
Promiscuous mode.
Definition: dwmac.h:34
#define __attribute__(x)
Definition: compiler.h:10
uint32_t base
Base.
Definition: librm.h:138
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
wmb()
#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
static void dwmac_poll(struct net_device *netdev)
Poll for completed and received packets.
Definition: dwmac.c:510
static struct net_device_operations dwmac_operations
DesignWare MAC network device operations.
Definition: dwmac.c:530
static void dwmac_poll_rx(struct net_device *netdev)
Poll for received packets.
Definition: dwmac.c:461
uint32_t stat
Completion status.
Definition: dwmac.h:12
#define DWMAC_NUM_TX_DESC
Number of transmit descriptors.
Definition: dwmac.h:205
#define le32_to_cpu(value)
Definition: byteswap.h:113
int(* open)(struct net_device *netdev)
Open network device.
Definition: netdevice.h:222
unsigned int cons
Consumer index.
Definition: dwmac.h:192
Error codes.
#define DWMAC_AXI
AXI bus mode register.
Definition: dwmac.h:122
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
A devicetree driver.
Definition: devtree.h:31
I/O buffers.
#define DWMAC_CFG_FD
Full duplex.
Definition: dwmac.h:28
static void dwmac_poll_tx(struct net_device *netdev)
Poll for completed packets.
Definition: dwmac.c:425
#define DWMAC_OP_RXEN
RX enabled.
Definition: dwmac.h:116
#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
static void dwmac_dump_mac(struct dwmac *dwmac)
Dump MAC registers (for debugging)
Definition: dwmac.c:57
static int dwmac_transmit(struct net_device *netdev, struct io_buffer *iobuf)
Transmit packet.
Definition: dwmac.c:385
#define DBGC(...)
Definition: compiler.h:505
char name[40]
Name.
Definition: device.h:78
size_t len
Length of descriptors.
Definition: dwmac.h:201
#define DWMAC_OP
Operation mode register.
Definition: dwmac.h:112
struct dwmac_descriptor * desc
Descriptors.
Definition: dwmac.h:186
struct dma_device * dma
DMA device.
Definition: netdevice.h:366
void netdev_tx_complete_next_err(struct net_device *netdev, int rc)
Complete network transmission.
Definition: netdevice.c:509
void netdev_link_down(struct net_device *netdev)
Mark network device as having link down.
Definition: netdevice.c:230
iPXE timers
uint8_t mac[ETH_ALEN]
MAC address.
Definition: ena.h:24
A frame descriptor.
Definition: dwmac.h:148
int fdt_mac(struct fdt *fdt, unsigned int offset, struct net_device *netdev)
Get MAC address from property.
Definition: fdt.c:866
#define DWMAC_BUS
Bus mode register.
Definition: dwmac.h:84
#define DWMAC_STAT_RX_LAST
Last segment (RX)
Definition: dwmac.h:170
#define DWMAC_RXBUF
Current receive buffer address register.
Definition: dwmac.h:137
static int dwmac_open(struct net_device *netdev)
Open network device.
Definition: dwmac.c:308
uint8_t count
Number of descriptors.
Definition: dwmac.h:197
struct device dev
Generic device.
Definition: devtree.h:21
static void dwmac_dump_dma(struct dwmac *dwmac)
Dump DMA registers (for debugging)
Definition: dwmac.c:80
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
struct ena_llq_option desc
Descriptor counts.
Definition: ena.h:20
void dma_free(struct dma_mapping *map, void *addr, size_t len)
Unmap and free DMA-coherent buffer.
int(* probe)(struct dt_device *dt, unsigned int offset)
Probe device.
Definition: devtree.h:45
#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
#define DWMAC_CFG_RXEN
RX enabled.
Definition: dwmac.h:30
assert((readw(&hdr->flags) &(GTF_reading|GTF_writing))==0)
static void netdev_put(struct net_device *netdev)
Drop reference to network device.
Definition: netdevice.h:575
Ethernet protocol.
Devicetree bus.
#define DWMAC_SIZE_RX_CHAIN
Buffer size.
Definition: dwmac.h:176
static int dwmac_probe(struct dt_device *dt, unsigned int offset)
Probe devicetree device.
Definition: dwmac.c:551
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
FILE_LICENCE(GPL2_OR_LATER_OR_UBDL)
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
ring len
Length.
Definition: dwmac.h:231
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
#define DWMAC_STATUS_LINK
Link status change.
Definition: dwmac.h:109
#define DWMAC_RXDESC
Current receive descriptor register.
Definition: dwmac.h:131
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
A devicetree device.
Definition: devtree.h:17
#define DWMAC_STAT_ERR
Error summary.
Definition: dwmac.h:168
#define DWMAC_ADDRL
MAC address low register.
Definition: dwmac.h:64
#define DWMAC_STAT_TX_CHAIN
Chained descriptor (TX)
Definition: dwmac.h:167
#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
#define DWMAC_OP_TXEN
TX enabled.
Definition: dwmac.h:115
#define DWMAC_DMA
DMA register block.
Definition: dwmac.h:80
#define cpu_to_le32(value)
Definition: byteswap.h:107
#define DWMAC_STAT_RX_FIRST
First segment (RX)
Definition: dwmac.h:169
#define DWMAC_DROP
Packet drop counter register.
Definition: dwmac.h:119
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
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_CFG_DO
Disable RX own frames.
Definition: dwmac.h:27
Synopsys DesignWare MAC network driver.
int register_netdev(struct net_device *netdev)
Register network device.
Definition: netdevice.c:759
static size_t iob_len(struct io_buffer *iobuf)
Calculate length of data in an I/O buffer.
Definition: iobuf.h:159
static const char * dwmac_ids[]
DesignWare MAC compatible model identifiers.
Definition: dwmac.c:651
A network device.
Definition: netdevice.h:352
#define DWMAC_OP_TXSF
TX store and forward.
Definition: dwmac.h:114
#define DWMAC_RESET_MAX_WAIT_MS
Time to wait for software reset to complete.
Definition: dwmac.h:93
#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
A DesignWare descriptor ring.
Definition: dwmac.h:184
struct dt_driver dwmac_driver __dt_driver
DesignWare MAC devicetree driver.
Definition: dwmac.c:657
#define DWMAC_CFG_TXEN
TX enabled.
Definition: dwmac.h:29
#define ETH_ALEN
Definition: if_ether.h:8
#define DWMAC_RXPOLL
Receive poll demand register.
Definition: dwmac.h:99
unsigned int uint32_t
Definition: stdint.h:12
#define DWMAC_NUM_RX_DESC
Number of receive descriptors.
Definition: dwmac.h:208
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
#define DWMAC_BUS_SWR
Software reset.
Definition: dwmac.h:90
static struct xen_remove_from_physmap * remove
Definition: xenmem.h:39
uint8_t unused
Unused.
Definition: librm.h:140
static void dwmac_destroy_ring(struct dwmac *dwmac, struct dwmac_ring *ring)
Destroy descriptor ring.
Definition: dwmac.c:242
#define DWMAC_STAT_TX_LAST
Last segment (TX)
Definition: dwmac.h:165
uint8_t status
Status.
Definition: ena.h:16
Network device operations.
Definition: netdevice.h:213
void netdev_rx(struct net_device *netdev, struct io_buffer *iobuf)
Add packet to receive queue.
Definition: netdevice.c:548
#define DWMAC_AHB
AHB or AXI status register.
Definition: dwmac.h:125
struct device * dev
Underlying hardware device.
Definition: netdevice.h:364
Network device management.
unsigned long physaddr_t
Definition: stdint.h:20
struct dwmac_ring tx
Transmit ring.
Definition: dwmac.h:244
#define DWMAC_STATUS
Status register.
Definition: dwmac.h:108
void mdelay(unsigned long msecs)
Delay for a fixed number of milliseconds.
Definition: timer.c:78
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_GMII_LINK
Link up.
Definition: dwmac.h:77
#define DWMAC_CTRL_TX_LAST
Last segment (TX)
Definition: dwmac.h:179
#define DWMAC_TXDESC
Current transmit descriptor register.
Definition: dwmac.h:128
void * regs
Registers.
Definition: dwmac.h:237
const char * name
Driver name.
Definition: devtree.h:33
void free_rx_iob(struct io_buffer *iobuf)
Unmap and free I/O buffer for receive DMA.
Definition: iobuf.c:214
#define ENOBUFS
No buffer space available.
Definition: errno.h:498
uint8_t qbase
Queue base address register (within DMA block)
Definition: dwmac.h:195
#define DBGC2(...)
Definition: compiler.h:522
#define DWMAC_VER_USER_MINOR(x)
User minor version.
Definition: dwmac.h:44
static void dwmac_refill_rx(struct dwmac *dwmac)
Refill receive descriptor ring.
Definition: dwmac.c:260
#define DWMAC_DEBUG
Debug register.
Definition: dwmac.h:55
#define DWMAC_RX_LEN
Length of receive buffers.
Definition: dwmac.h:214
#define DWMAC_ADDRH
MAC address high register.
Definition: dwmac.h:61
void * data
Start of data.
Definition: iobuf.h:52
#define EIO
Input/output error.
Definition: errno.h:433
#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
Flattened Device Tree.
void * dt_ioremap(struct dt_device *dt, unsigned int offset, unsigned int index, size_t len)
Map devicetree range.
Definition: devtree.c:52
u8 rx[WPA_TKIP_MIC_KEY_LEN]
MIC key for packets from the AP.
Definition: wpa.h:234
#define DWMAC_TXPOLL
Transmit poll demand register.
Definition: dwmac.h:96
#define cpu_to_le16(value)
Definition: byteswap.h:106
void iounmap(volatile const void *io_addr)
Unmap I/O address.
#define DWMAC_FEATURE
Hardware feature register.
Definition: dwmac.h:140
uint8_t ctrl
Default control flags.
Definition: dwmac.h:199
#define DWMAC_FLOW
Flow control register.
Definition: dwmac.h:37
unsigned int prod
Producer index.
Definition: dwmac.h:190
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
#define DWMAC_STAT_TX_FIRST
First segment (TX)
Definition: dwmac.h:166
#define DBG_LOG
Definition: compiler.h:317
struct dma_device dma
DMA device.
Definition: devtree.h:23
#define NULL
NULL pointer (VOID *)
Definition: Base.h:321
struct dwmac_ring rx
Receive ring.
Definition: dwmac.h:246
#define ETIMEDOUT
Connection timed out.
Definition: errno.h:669
String functions.
static void dwmac_close(struct net_device *netdev)
Close network device.
Definition: dwmac.c:357
#define DWMAC_STAT_RX_LEN(x)
Frame length (RX)
Definition: dwmac.h:171
uint8_t bus
Bus.
Definition: edd.h:14
physaddr_t dma(struct dma_mapping *map, void *addr)
Get DMA address from virtual address.
#define DWMAC_TXBUF
Current transmit buffer address register.
Definition: dwmac.h:134
#define DWMAC_STAT_OWN
Owned by hardware.
Definition: dwmac.h:164
#define DWMAC_CTRL_TX_FIRST
First segment (TX)
Definition: dwmac.h:180
static int dwmac_create_ring(struct dwmac *dwmac, struct dwmac_ring *ring)
Create descriptor ring.
Definition: dwmac.c:201
#define DWMAC_TXBASE
Transmit descriptor list address register.
Definition: dwmac.h:105
u8 tx[WPA_TKIP_MIC_KEY_LEN]
MIC key for packets to the AP.
Definition: wpa.h:237
#define DWMAC_ISR
Interrupt status register.
Definition: dwmac.h:58
static void * dt_get_drvdata(struct dt_device *dt)
Get devicetree driver-private data.
Definition: devtree.h:76
struct dma_mapping map
Descriptor ring DMA mapping.
Definition: dwmac.h:188
static void dwmac_remove(struct dt_device *dt)
Remove devicetree device.
Definition: dwmac.c:634
void * memset(void *dest, int character, size_t len) __nonnull
struct dma_device * dma
DMA device.
Definition: dwmac.h:239
A persistent I/O buffer.
Definition: iobuf.h:37
struct fdt sysfdt
The system flattened device tree (if present)
Definition: fdt.c:44