iPXE
rdc.c
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2021 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 <unistd.h>
29 #include <errno.h>
30 #include <byteswap.h>
31 #include <ipxe/netdevice.h>
32 #include <ipxe/ethernet.h>
33 #include <ipxe/if_ether.h>
34 #include <ipxe/iobuf.h>
35 #include <ipxe/malloc.h>
36 #include <ipxe/pci.h>
37 #include "rdc.h"
38 
39 /** @file
40  *
41  * RDC R6040 network driver
42  *
43  */
44 
45 /******************************************************************************
46  *
47  * Device reset
48  *
49  ******************************************************************************
50  */
51 
52 /**
53  * Reset hardware
54  *
55  * @v rdc RDC device
56  * @ret rc Return status code
57  */
58 static int rdc_reset ( struct rdc_nic *rdc ) {
59  unsigned int i;
60 
61  /* Reset NIC */
62  writew ( RDC_MCR1_RST, rdc->regs + RDC_MCR1 );
63 
64  /* Wait for reset to complete */
65  for ( i = 0 ; i < RDC_RESET_MAX_WAIT_MS ; i++ ) {
66 
67  /* Check for reset completion */
68  if ( readw ( rdc->regs + RDC_MCR1 ) & RDC_MCR1_RST ) {
69  mdelay ( 1 );
70  continue;
71  }
72 
73  /* Reset internal state machine */
74  writew ( RDC_MACSM_RST, rdc->regs + RDC_MACSM );
75  writew ( 0, rdc->regs + RDC_MACSM );
77 
78  return 0;
79  }
80 
81  DBGC ( rdc, "RDC %p timed out waiting for reset\n", rdc );
82  return -ETIMEDOUT;
83 }
84 
85 /******************************************************************************
86  *
87  * MII interface
88  *
89  ******************************************************************************
90  */
91 
92 /**
93  * Read from MII register
94  *
95  * @v mdio MII interface
96  * @v phy PHY address
97  * @v reg Register address
98  * @ret value Data read, or negative error
99  */
100 static int rdc_mii_read ( struct mii_interface *mdio, unsigned int phy,
101  unsigned int reg ) {
102  struct rdc_nic *rdc = container_of ( mdio, struct rdc_nic, mdio );
103  uint16_t mmdio;
104  unsigned int i;
105 
106  /* Initiate read */
107  mmdio = ( RDC_MMDIO_MIIRD | RDC_MMDIO_PHYAD ( phy ) |
108  RDC_MMDIO_REGAD ( reg ) );
109  writew ( mmdio, rdc->regs + RDC_MMDIO );
110 
111  /* Wait for read to complete */
112  for ( i = 0 ; i < RDC_MII_MAX_WAIT_US ; i++ ) {
113 
114  /* Check for read completion */
115  if ( readw ( rdc->regs + RDC_MMDIO ) & RDC_MMDIO_MIIRD ) {
116  udelay ( 1 );
117  continue;
118  }
119 
120  /* Return register value */
121  return ( readw ( rdc->regs + RDC_MMRD ) );
122  }
123 
124  DBGC ( rdc, "RDC %p timed out waiting for MII read\n", rdc );
125  return -ETIMEDOUT;
126 }
127 
128 /**
129  * Write to MII register
130  *
131  * @v mdio MII interface
132  * @v phy PHY address
133  * @v reg Register address
134  * @v data Data to write
135  * @ret rc Return status code
136  */
137 static int rdc_mii_write ( struct mii_interface *mdio, unsigned int phy,
138  unsigned int reg, unsigned int data ) {
139  struct rdc_nic *rdc = container_of ( mdio, struct rdc_nic, mdio );
140  uint16_t mmdio;
141  unsigned int i;
142 
143  /* Initiate write */
144  mmdio = ( RDC_MMDIO_MIIWR | RDC_MMDIO_PHYAD ( phy ) |
145  RDC_MMDIO_REGAD ( reg ) );
146  writew ( data, rdc->regs + RDC_MMWD );
147  writew ( mmdio, rdc->regs + RDC_MMDIO );
148 
149  /* Wait for write to complete */
150  for ( i = 0 ; i < RDC_MII_MAX_WAIT_US ; i++ ) {
151 
152  /* Check for write completion */
153  if ( readw ( rdc->regs + RDC_MMDIO ) & RDC_MMDIO_MIIWR ) {
154  udelay ( 1 );
155  continue;
156  }
157 
158  return 0;
159  }
160 
161  DBGC ( rdc, "RDC %p timed out waiting for MII write\n", rdc );
162  return -ETIMEDOUT;
163 }
164 
165 /** RDC MII operations */
167  .read = rdc_mii_read,
168  .write = rdc_mii_write,
169 };
170 
171 /******************************************************************************
172  *
173  * Link state
174  *
175  ******************************************************************************
176  */
177 
178 /**
179  * Initialise PHY
180  *
181  * @v rdc RDC device
182  * @ret rc Return status code
183  */
184 static int rdc_init_phy ( struct rdc_nic *rdc ) {
185  int rc;
186 
187  /* Find PHY address */
188  if ( ( rc = mii_find ( &rdc->mii ) ) != 0 ) {
189  DBGC ( rdc, "RDC %p could not find PHY address: %s\n",
190  rdc, strerror ( rc ) );
191  return rc;
192  }
193 
194  /* Reset PHY */
195  if ( ( rc = mii_reset ( &rdc->mii ) ) != 0 ) {
196  DBGC ( rdc, "RDC %p could not reset PHY: %s\n",
197  rdc, strerror ( rc ) );
198  return rc;
199  }
200 
201  return 0;
202 }
203 
204 /**
205  * Check link state
206  *
207  * @v netdev Network device
208  * @ret rc Return status code
209  */
210 static int rdc_check_link ( struct net_device *netdev ) {
211  struct rdc_nic *rdc = netdev->priv;
212  int rc;
213 
214  /* Check link state */
215  if ( ( rc = mii_check_link ( &rdc->mii, netdev ) ) != 0 ) {
216  DBGC ( rdc, "RDC %p could not check link: %s\n",
217  rdc, strerror ( rc ) );
218  return rc;
219  }
220 
221  return 0;
222 }
223 
224 /******************************************************************************
225  *
226  * Network device interface
227  *
228  ******************************************************************************
229  */
230 
231 /**
232  * Create descriptor ring
233  *
234  * @v rdc RDC device
235  * @v ring Descriptor ring
236  * @ret rc Return status code
237  */
238 static int rdc_create_ring ( struct rdc_nic *rdc, struct rdc_ring *ring ) {
239  size_t len = ( ring->count * sizeof ( ring->desc[0] ) );
240  struct rdc_descriptor *desc;
241  struct rdc_descriptor *next;
243  unsigned int i;
244 
245  /* Allocate descriptor ring */
246  ring->desc = dma_alloc ( rdc->dma, &ring->map, len, len );
247  if ( ! ring->desc )
248  return -ENOMEM;
249 
250  /* Initialise descriptor ring */
251  memset ( ring->desc, 0, len );
252  for ( i = 0 ; i < ring->count ; i++ ) {
253  desc = &ring->desc[i];
254  next = &ring->desc[ ( i + 1 ) & ( ring->count - 1 ) ];
255  desc->next = cpu_to_le32 ( dma ( &ring->map, next ) );
256  }
257 
258  /* Program ring address */
259  start = dma ( &ring->map, ring->desc );
260  writew ( ( start >> 0 ), ( rdc->regs + ring->reg + RDC_MxDSA_LO ) );
261  writew ( ( start >> 16 ), ( rdc->regs + ring->reg + RDC_MxDSA_HI ) );
262 
263  DBGC ( rdc, "RDC %p ring %#02x is at [%08lx,%08lx)\n",
264  rdc, ring->reg, virt_to_phys ( ring->desc ),
265  ( virt_to_phys ( ring->desc ) + len ) );
266  return 0;
267 }
268 
269 /**
270  * Destroy descriptor ring
271  *
272  * @v rdc RDC device
273  * @v ring Descriptor ring
274  */
275 static void rdc_destroy_ring ( struct rdc_nic *rdc, struct rdc_ring *ring ) {
276  size_t len = ( ring->count * sizeof ( ring->desc[0] ) );
277 
278  /* Clear ring address */
279  writew ( 0, ( rdc->regs + ring->reg + RDC_MxDSA_LO ) );
280  writew ( 0, ( rdc->regs + ring->reg + RDC_MxDSA_HI ) );
281 
282  /* Free descriptors */
283  dma_free ( &ring->map, ring->desc, len );
284  ring->desc = NULL;
285 
286  /* Reset ring */
287  ring->prod = 0;
288  ring->cons = 0;
289 }
290 
291 /**
292  * Refill receive descriptor ring
293  *
294  * @v rdc RDC device
295  */
296 static void rdc_refill_rx ( struct rdc_nic *rdc ) {
297  struct rdc_descriptor *rx;
298  struct io_buffer *iobuf;
299  unsigned int rx_idx;
300 
301  /* Refill ring */
302  while ( ( rdc->rx.prod - rdc->rx.cons ) < RDC_NUM_RX_DESC ) {
303 
304  /* Allocate I/O buffer */
305  iobuf = alloc_rx_iob ( RDC_RX_MAX_LEN, rdc->dma );
306  if ( ! iobuf ) {
307  /* Wait for next refill */
308  break;
309  }
310 
311  /* Get next receive descriptor */
312  rx_idx = ( rdc->rx.prod++ % RDC_NUM_RX_DESC );
313  rx = &rdc->rx.desc[rx_idx];
314 
315  /* Populate receive descriptor */
316  rx->len = cpu_to_le16 ( RDC_RX_MAX_LEN );
317  rx->addr = cpu_to_le32 ( iob_dma ( iobuf ) );
318  wmb();
319  rx->flags = cpu_to_le16 ( RDC_FL_OWNED );
320 
321  /* Record I/O buffer */
322  assert ( rdc->rx_iobuf[rx_idx] == NULL );
323  rdc->rx_iobuf[rx_idx] = iobuf;
324 
325  DBGC2 ( rdc, "RDC %p RX %d is [%lx,%lx)\n",
326  rdc, rx_idx, virt_to_phys ( iobuf->data ),
327  ( virt_to_phys ( iobuf->data ) + RDC_RX_MAX_LEN ) );
328  }
329 }
330 
331 /**
332  * Open network device
333  *
334  * @v netdev Network device
335  * @ret rc Return status code
336  */
337 static int rdc_open ( struct net_device *netdev ) {
338  struct rdc_nic *rdc = netdev->priv;
339  int rc;
340 
341  /* Create transmit descriptor ring */
342  if ( ( rc = rdc_create_ring ( rdc, &rdc->tx ) ) != 0 )
343  goto err_create_tx;
344 
345  /* Create receive descriptor ring */
346  if ( ( rc = rdc_create_ring ( rdc, &rdc->rx ) ) != 0 )
347  goto err_create_rx;
348 
349  /* Program receive buffer length */
350  writew ( RDC_RX_MAX_LEN, rdc->regs + RDC_MRBSR );
351 
352  /* Enable transmit and receive */
354  RDC_MCR0_RXEN ),
355  rdc->regs + RDC_MCR0 );
356 
357  /* Enable PHY status polling */
359  RDC_MPSCCR_SLOW ),
360  rdc->regs + RDC_MPSCCR );
361 
362  /* Fill receive ring */
363  rdc_refill_rx ( rdc );
364 
365  /* Update link state */
367 
368  return 0;
369 
370  rdc_destroy_ring ( rdc, &rdc->rx );
371  err_create_rx:
372  rdc_destroy_ring ( rdc, &rdc->tx );
373  err_create_tx:
374  return rc;
375 }
376 
377 /**
378  * Close network device
379  *
380  * @v netdev Network device
381  */
382 static void rdc_close ( struct net_device *netdev ) {
383  struct rdc_nic *rdc = netdev->priv;
384  unsigned int i;
385 
386  /* Disable NIC */
387  writew ( 0, rdc->regs + RDC_MCR0 );
388 
389  /* Destroy receive descriptor ring */
390  rdc_destroy_ring ( rdc, &rdc->rx );
391 
392  /* Discard any unused receive buffers */
393  for ( i = 0 ; i < RDC_NUM_RX_DESC ; i++ ) {
394  if ( rdc->rx_iobuf[i] )
395  free_rx_iob ( rdc->rx_iobuf[i] );
396  rdc->rx_iobuf[i] = NULL;
397  }
398 
399  /* Destroy transmit descriptor ring */
400  rdc_destroy_ring ( rdc, &rdc->tx );
401 }
402 
403 /**
404  * Transmit packet
405  *
406  * @v netdev Network device
407  * @v iobuf I/O buffer
408  * @ret rc Return status code
409  */
410 static int rdc_transmit ( struct net_device *netdev, struct io_buffer *iobuf ) {
411  struct rdc_nic *rdc = netdev->priv;
412  struct rdc_descriptor *tx;
413  unsigned int tx_idx;
414  int rc;
415 
416  /* Get next transmit descriptor */
417  if ( ( rdc->tx.prod - rdc->tx.cons ) >= RDC_NUM_TX_DESC ) {
418  DBGC ( rdc, "RDC %p out of transmit descriptors\n", rdc );
419  return -ENOBUFS;
420  }
421  tx_idx = ( rdc->tx.prod % RDC_NUM_TX_DESC );
422  tx = &rdc->tx.desc[tx_idx];
423 
424  /* Pad to minimum length */
425  iob_pad ( iobuf, ETH_ZLEN );
426 
427  /* Map I/O buffer */
428  if ( ( rc = iob_map_tx ( iobuf, rdc->dma ) ) != 0 )
429  return rc;
430 
431  /* Update producer index */
432  rdc->tx.prod++;
433 
434  /* Populate transmit descriptor */
435  tx->len = cpu_to_le16 ( iob_len ( iobuf ) );
436  tx->addr = cpu_to_le32 ( iob_dma ( iobuf ) );
437  wmb();
438  tx->flags = cpu_to_le16 ( RDC_FL_OWNED );
439  wmb();
440 
441  /* Notify card that there are packets ready to transmit */
442  writew ( RDC_MTPR_TM2TX, rdc->regs + RDC_MTPR );
443 
444  return 0;
445 }
446 
447 /**
448  * Poll for completed packets
449  *
450  * @v netdev Network device
451  */
452 static void rdc_poll_tx ( struct net_device *netdev ) {
453  struct rdc_nic *rdc = netdev->priv;
454  struct rdc_descriptor *tx;
455  unsigned int tx_idx;
456 
457  /* Check for completed packets */
458  while ( rdc->tx.cons != rdc->tx.prod ) {
459 
460  /* Get next transmit descriptor */
461  tx_idx = ( rdc->tx.cons % RDC_NUM_TX_DESC );
462  tx = &rdc->tx.desc[tx_idx];
463 
464  /* Stop if descriptor is still in use */
465  if ( tx->flags & cpu_to_le16 ( RDC_FL_OWNED ) )
466  return;
467  DBGC2 ( rdc, "RDC %p TX %d complete\n", rdc, tx_idx );
468 
469  /* Complete transmit descriptor */
470  rdc->tx.cons++;
472  }
473 }
474 
475 /**
476  * Poll for received packets
477  *
478  * @v netdev Network device
479  */
480 static void rdc_poll_rx ( struct net_device *netdev ) {
481  struct rdc_nic *rdc = netdev->priv;
482  struct rdc_descriptor *rx;
483  struct io_buffer *iobuf;
484  unsigned int rx_idx;
485  size_t len;
486 
487  /* Check for received packets */
488  while ( rdc->rx.cons != rdc->rx.prod ) {
489 
490  /* Get next receive descriptor */
491  rx_idx = ( rdc->rx.cons % RDC_NUM_RX_DESC );
492  rx = &rdc->rx.desc[rx_idx];
493 
494  /* Stop if descriptor is still in use */
495  if ( rx->flags & cpu_to_le16 ( RDC_FL_OWNED ) )
496  return;
497 
498  /* Populate I/O buffer */
499  iobuf = rdc->rx_iobuf[rx_idx];
500  rdc->rx_iobuf[rx_idx] = NULL;
501  len = le16_to_cpu ( rx->len );
502  iob_put ( iobuf, len );
503  iob_unput ( iobuf, 4 /* strip CRC */ );
504 
505  /* Hand off to network stack */
506  if ( rx->flags & cpu_to_le16 ( RDC_FL_OK ) ) {
507  DBGC2 ( rdc, "RDC %p RX %d complete (length %zd)\n",
508  rdc, rx_idx, len );
509  netdev_rx ( netdev, iobuf );
510  } else {
511  DBGC2 ( rdc, "RDC %p RX %d error (length %zd, "
512  "flags %#04x)\n", rdc, rx_idx, len,
513  le16_to_cpu ( rx->flags ) );
514  netdev_rx_err ( netdev, iobuf, -EIO );
515  }
516  rdc->rx.cons++;
517  }
518 }
519 
520 /**
521  * Poll for completed and received packets
522  *
523  * @v netdev Network device
524  */
525 static void rdc_poll ( struct net_device *netdev ) {
526  struct rdc_nic *rdc = netdev->priv;
527  uint16_t misr;
528 
529  /* Check for (and acknowledge) interrupts */
530  misr = readw ( rdc->regs + RDC_MISR );
531 
532  /* Poll for TX completions, if applicable */
533  if ( misr & RDC_MIRQ_TX )
534  rdc_poll_tx ( netdev );
535 
536  /* Poll for RX completions, if applicable */
537  if ( misr & RDC_MIRQ_RX )
538  rdc_poll_rx ( netdev );
539 
540  /* Check link state, if applicable */
541  if ( misr & RDC_MIRQ_LINK )
543 
544  /* Check for unexpected interrupts */
545  if ( misr & ~( RDC_MIRQ_LINK | RDC_MIRQ_TX | RDC_MIRQ_RX_EARLY |
547  DBGC ( rdc, "RDC %p unexpected MISR %#04x\n", rdc, misr );
548  /* Report as a TX error */
550  }
551 
552  /* Refill receive ring */
553  rdc_refill_rx ( rdc );
554 }
555 
556 /**
557  * Enable or disable interrupts
558  *
559  * @v netdev Network device
560  * @v enable Interrupts should be enabled
561  */
562 static void rdc_irq ( struct net_device *netdev, int enable ) {
563  struct rdc_nic *rdc = netdev->priv;
564  uint16_t mier;
565 
566  /* Enable/disable interrupts */
567  mier = ( enable ? ( RDC_MIRQ_LINK | RDC_MIRQ_TX | RDC_MIRQ_RX ) : 0 );
568  writew ( mier, rdc->regs + RDC_MIER );
569 }
570 
571 /** RDC network device operations */
573  .open = rdc_open,
574  .close = rdc_close,
575  .transmit = rdc_transmit,
576  .poll = rdc_poll,
577  .irq = rdc_irq,
578 };
579 
580 /******************************************************************************
581  *
582  * PCI interface
583  *
584  ******************************************************************************
585  */
586 
587 /**
588  * Probe PCI device
589  *
590  * @v pci PCI device
591  * @ret rc Return status code
592  */
593 static int rdc_probe ( struct pci_device *pci ) {
594  struct net_device *netdev;
595  struct rdc_nic *rdc;
596  union rdc_mac mac;
597  int rc;
598 
599  /* Allocate and initialise net device */
600  netdev = alloc_etherdev ( sizeof ( *rdc ) );
601  if ( ! netdev ) {
602  rc = -ENOMEM;
603  goto err_alloc;
604  }
606  rdc = netdev->priv;
607  pci_set_drvdata ( pci, netdev );
608  netdev->dev = &pci->dev;
609  memset ( rdc, 0, sizeof ( *rdc ) );
610  rdc->dma = &pci->dma;
611  mdio_init ( &rdc->mdio, &rdc_mii_operations );
612  mii_init ( &rdc->mii, &rdc->mdio, 0 );
615 
616  /* Fix up PCI device */
617  adjust_pci_device ( pci );
618 
619  /* Map registers */
620  rdc->regs = pci_ioremap ( pci, pci->membase, RDC_BAR_SIZE );
621  if ( ! rdc->regs ) {
622  rc = -ENODEV;
623  goto err_ioremap;
624  }
625 
626  /* Fetch MAC address */
627  mac.mid[0] = cpu_to_le16 ( readw ( rdc->regs + RDC_MID0 ) );
628  mac.mid[1] = cpu_to_le16 ( readw ( rdc->regs + RDC_MID1 ) );
629  mac.mid[2] = cpu_to_le16 ( readw ( rdc->regs + RDC_MID2 ) );
630  memcpy ( netdev->hw_addr, mac.raw, ETH_ALEN );
631 
632  /* Reset the NIC */
633  if ( ( rc = rdc_reset ( rdc ) ) != 0 )
634  goto err_reset;
635 
636  /* Initialise PHY */
637  if ( ( rc = rdc_init_phy ( rdc ) ) != 0 )
638  goto err_init_phy;
639 
640  /* Register network device */
641  if ( ( rc = register_netdev ( netdev ) ) != 0 )
642  goto err_register_netdev;
643 
644  /* Set initial link state */
646 
647  return 0;
648 
650  err_register_netdev:
651  err_init_phy:
652  rdc_reset ( rdc );
653  err_reset:
654  iounmap ( rdc->regs );
655  err_ioremap:
657  netdev_put ( netdev );
658  err_alloc:
659  return rc;
660 }
661 
662 /**
663  * Remove PCI device
664  *
665  * @v pci PCI device
666  */
667 static void rdc_remove ( struct pci_device *pci ) {
668  struct net_device *netdev = pci_get_drvdata ( pci );
669  struct rdc_nic *rdc = netdev->priv;
670 
671  /* Unregister network device */
673 
674  /* Reset card */
675  rdc_reset ( rdc );
676 
677  /* Free network device */
678  iounmap ( rdc->regs );
680  netdev_put ( netdev );
681 }
682 
683 /** RDC PCI device IDs */
684 static struct pci_device_id rdc_nics[] = {
685  PCI_ROM ( 0x17f3, 0x6040, "r6040", "RDC R6040", 0 ),
686 };
687 
688 /** RDC PCI driver */
689 struct pci_driver rdc_driver __pci_driver = {
690  .ids = rdc_nics,
691  .id_count = ( sizeof ( rdc_nics ) / sizeof ( rdc_nics[0] ) ),
692  .probe = rdc_probe,
693  .remove = rdc_remove,
694 };
unsigned long membase
Memory base.
Definition: pci.h:215
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
unsigned short uint16_t
Definition: stdint.h:11
wmb()
static int rdc_create_ring(struct rdc_nic *rdc, struct rdc_ring *ring)
Create descriptor ring.
Definition: rdc.c:238
#define iob_put(iobuf, len)
Definition: iobuf.h:120
struct dma_device dma
DMA device.
Definition: pci.h:210
void netdev_rx_err(struct net_device *netdev, struct io_buffer *iobuf, int rc)
Discard received packet.
Definition: netdevice.c:586
#define RDC_MIRQ_RX
Receive complete.
Definition: rdc.h:94
A PCI driver.
Definition: pci.h:247
#define RDC_MACSM
MAC state machine register.
Definition: rdc.h:115
static unsigned int unsigned int reg
Definition: myson.h:162
#define RDC_MCR0_TXEN
Transmit enable.
Definition: rdc.h:42
static void rdc_init_ring(struct rdc_ring *ring, unsigned int count, unsigned int reg)
Initialise descriptor ring.
Definition: rdc.h:154
#define RDC_MID2
MAC address word 2.
Definition: rdc.h:106
static int rdc_check_link(struct net_device *netdev)
Check link state.
Definition: rdc.c:210
int(* open)(struct net_device *netdev)
Open network device.
Definition: netdevice.h:222
#define RDC_MID1
MAC address word 1.
Definition: rdc.h:103
static void rdc_destroy_ring(struct rdc_nic *rdc, struct rdc_ring *ring)
Destroy descriptor ring.
Definition: rdc.c:275
uint32_t next
Next descriptor address.
Definition: myson.h:18
void netdev_tx_err(struct net_device *netdev, struct io_buffer *iobuf, int rc)
Discard transmitted packet.
Definition: netdevice.c:440
#define RDC_MMDIO_PHYAD(x)
PHY address.
Definition: rdc.h:64
Error codes.
#define RDC_MTDSA
MAC transmit descriptor start address.
Definition: rdc.h:77
#define RDC_MMWD
MAC MDIO write data register.
Definition: rdc.h:74
uint16_t readw(volatile uint16_t *io_addr)
Read 16-bit word from memory-mapped device.
static void netdev_tx_complete_next(struct net_device *netdev)
Complete network transmission.
Definition: netdevice.h:764
I/O buffers.
struct pci_device_id * ids
PCI ID table.
Definition: pci.h:249
#define RDC_MACSM_RESET_DELAY_MS
Time to wait after resetting MAC state machine.
Definition: rdc.h:119
int(* read)(struct mii_interface *mdio, unsigned int phy, unsigned int reg)
Read from MII register.
Definition: mii.h:27
static int rdc_reset(struct rdc_nic *rdc)
Reset hardware.
Definition: rdc.c:58
static int rdc_open(struct net_device *netdev)
Open network device.
Definition: rdc.c:337
uint64_t desc
Microcode descriptor list physical address.
Definition: ucode.h:12
#define DBGC(...)
Definition: compiler.h:505
#define RDC_MTPR_TM2TX
Trigger MAC to transmit.
Definition: rdc.h:55
static int rdc_mii_read(struct mii_interface *mdio, unsigned int phy, unsigned int reg)
Read from MII register.
Definition: rdc.c:100
#define RDC_MPSCCR
MAC PHY status change configuration register.
Definition: rdc.h:109
uint8_t mac[ETH_ALEN]
MAC address.
Definition: ena.h:24
#define RDC_MACSM_RST
Reset state machine.
Definition: rdc.h:116
void adjust_pci_device(struct pci_device *pci)
Enable PCI device.
Definition: pci.c:154
struct pci_driver rdc_driver __pci_driver
RDC PCI driver.
Definition: rdc.c:689
static __always_inline unsigned long virt_to_phys(volatile const void *addr)
Convert virtual address to a physical address.
Definition: uaccess.h:287
static int rdc_mii_write(struct mii_interface *mdio, unsigned int phy, unsigned int reg, unsigned int data)
Write to MII register.
Definition: rdc.c:137
struct device dev
Generic device.
Definition: pci.h:208
An RDC network card.
Definition: rdc.h:176
#define RDC_MMRD
MAC MDIO read data register.
Definition: rdc.h:71
#define RDC_FL_OWNED
Descriptor is owned by NIC.
Definition: rdc.h:34
#define RDC_MIER
MAC interrupt enable register.
Definition: rdc.h:97
#define ENOTSUP
Operation not supported.
Definition: errno.h:589
static void mdio_init(struct mii_interface *mdio, struct mii_operations *op)
Initialise MII interface.
Definition: mii.h:63
static struct mii_operations rdc_mii_operations
RDC MII operations.
Definition: rdc.c:166
struct rdc_ring rx
Receive descriptor ring.
Definition: rdc.h:189
Dynamic memory allocation.
static __always_inline int iob_map_tx(struct io_buffer *iobuf, struct dma_device *dma)
Map I/O buffer for transmit DMA.
Definition: iobuf.h:240
uint32_t start
Starting offset.
Definition: netvsc.h:12
An RDC descriptor.
Definition: rdc.h:20
static void netdev_init(struct net_device *netdev, struct net_device_operations *op)
Initialise a network device.
Definition: netdevice.h:515
#define RDC_NUM_TX_DESC
Number of transmit descriptors.
Definition: rdc.h:164
#define RDC_MID0
MAC address word 0.
Definition: rdc.h:100
static void pci_set_drvdata(struct pci_device *pci, void *priv)
Set PCI driver-private data.
Definition: pci.h:359
struct dma_mapping map
Descriptor ring DMA mapping.
Definition: rdc.h:134
#define ENOMEM
Not enough space.
Definition: errno.h:534
#define RDC_MMDIO_MIIWR
MDIO write.
Definition: rdc.h:62
void * memcpy(void *dest, const void *src, size_t len) __nonnull
#define RDC_MRBSR
MAC receive buffer size register.
Definition: rdc.h:58
static void rdc_poll_tx(struct net_device *netdev)
Poll for completed packets.
Definition: rdc.c:452
#define RDC_FL_OK
Packet OK.
Definition: rdc.h:37
#define RDC_MCR0_PROMISC
Promiscuous mode.
Definition: rdc.h:43
static void rdc_poll_rx(struct net_device *netdev)
Poll for received packets.
Definition: rdc.c:480
void dma_free(struct dma_mapping *map, void *addr, size_t len)
Unmap and free DMA-coherent buffer.
static void rdc_close(struct net_device *netdev)
Close network device.
Definition: rdc.c:382
static int rdc_probe(struct pci_device *pci)
Probe PCI device.
Definition: rdc.c:593
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:572
#define container_of(ptr, type, field)
Get containing structure.
Definition: stddef.h:35
Ethernet protocol.
#define RDC_MIRQ_RX_EARLY
Receive early interrupt.
Definition: rdc.h:92
struct rdc_ring tx
Transmit descriptor ring.
Definition: rdc.h:187
void * priv
Driver private data.
Definition: netdevice.h:431
#define RDC_MPSCCR_SLOW
Poll slowly.
Definition: rdc.h:112
void udelay(unsigned long usecs)
Delay for a fixed number of microseconds.
Definition: timer.c:60
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:264
static struct net_device_operations rdc_operations
RDC network device operations.
Definition: rdc.c:572
unsigned int prod
Producer index.
Definition: rdc.h:136
struct io_buffer * rx_iobuf[RDC_NUM_RX_DESC]
Receive I/O buffers.
Definition: rdc.h:191
void unregister_netdev(struct net_device *netdev)
Unregister network device.
Definition: netdevice.c:941
unsigned int reg
Start address register 0.
Definition: rdc.h:143
#define cpu_to_le32(value)
Definition: byteswap.h:107
#define RDC_NUM_RX_DESC
Number of receive descriptors.
Definition: rdc.h:170
unsigned int cons
Consumer index.
Definition: rdc.h:138
#define iob_unput(iobuf, len)
Definition: iobuf.h:135
static struct pci_device_id rdc_nics[]
RDC PCI device IDs.
Definition: rdc.c:684
char * strerror(int errno)
Retrieve string representation of error number.
Definition: strerror.c:78
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:181
#define RDC_MMDIO_REGAD(x)
Register address.
Definition: rdc.h:65
PCI bus.
A PCI device.
Definition: pci.h:206
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:155
A network device.
Definition: netdevice.h:352
RDC R6040 network driver.
#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:528
struct dma_device * dma
DMA device.
Definition: rdc.h:180
struct mii_interface mdio
MII interface.
Definition: rdc.h:182
#define RDC_MCR0_RXEN
Receive enable.
Definition: rdc.h:44
int mii_reset(struct mii_device *mii)
Reset MII device.
Definition: mii.c:74
#define ETH_ALEN
Definition: if_ether.h:8
#define ETH_ZLEN
Definition: if_ether.h:10
A PCI device ID list entry.
Definition: pci.h:170
#define RDC_MIRQ_RX_EMPTY
Receive descriptor unavailable.
Definition: rdc.h:93
#define le16_to_cpu(value)
Definition: byteswap.h:112
int mii_check_link(struct mii_device *mii, struct net_device *netdev)
Update link status via MII.
Definition: mii.c:126
#define RDC_MPSCCR_EN
PHY status change enable.
Definition: rdc.h:110
static struct xen_remove_from_physmap * remove
Definition: xenmem.h:39
#define RDC_BAR_SIZE
RDC BAR size.
Definition: rdc.h:17
A descriptor ring.
Definition: rdc.h:130
A MAC address.
Definition: rdc.h:122
FILE_LICENCE(GPL2_OR_LATER_OR_UBDL)
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
struct device * dev
Underlying hardware device.
Definition: netdevice.h:364
static int rdc_init_phy(struct rdc_nic *rdc)
Initialise PHY.
Definition: rdc.c:184
static void mii_init(struct mii_device *mii, struct mii_interface *mdio, unsigned int address)
Initialise MII device.
Definition: mii.h:75
void * dma_alloc(struct dma_device *dma, struct dma_mapping *map, size_t len, size_t align)
Allocate and map DMA-coherent buffer.
Network device management.
MII interface operations.
Definition: mii.h:18
unsigned long physaddr_t
Definition: stdint.h:20
#define RDC_RESET_MAX_WAIT_MS
Maximum time to wait for reset.
Definition: rdc.h:51
static void * pci_get_drvdata(struct pci_device *pci)
Get PCI driver-private data.
Definition: pci.h:369
int mii_find(struct mii_device *mii)
Find PHY address.
Definition: mii.c:157
void mdelay(unsigned long msecs)
Delay for a fixed number of milliseconds.
Definition: timer.c:78
static void rdc_remove(struct pci_device *pci)
Remove PCI device.
Definition: rdc.c:667
unsigned int count
Number of descriptors.
Definition: rdc.h:141
uint32_t len
Length.
Definition: ena.h:14
void free_rx_iob(struct io_buffer *iobuf)
Unmap and free I/O buffer for receive DMA.
Definition: iobuf.c:208
#define ENOBUFS
No buffer space available.
Definition: errno.h:498
#define RDC_MTPR
MAC transmit poll command register.
Definition: rdc.h:54
#define DBGC2(...)
Definition: compiler.h:522
#define RDC_MMDIO_MIIRD
MDIO read.
Definition: rdc.h:63
int(* probe)(struct pci_device *pci)
Probe device.
Definition: pci.h:260
#define writew
Definition: w89c840.c:159
void * data
Start of data.
Definition: iobuf.h:48
#define EIO
Input/output error.
Definition: errno.h:433
#define RDC_MxDSA_HI
MAC descriptor start address low half.
Definition: rdc.h:86
struct net_device * alloc_etherdev(size_t priv_size)
Allocate Ethernet device.
Definition: ethernet.c:264
u8 rx[WPA_TKIP_MIC_KEY_LEN]
MIC key for packets from the AP.
Definition: wpa.h:234
An MII interface.
Definition: mii.h:43
#define RDC_MCR0
MAC control register 0.
Definition: rdc.h:40
#define cpu_to_le16(value)
Definition: byteswap.h:106
void iounmap(volatile const void *io_addr)
Unmap I/O address.
uint8_t data[48]
Additional event data.
Definition: ena.h:22
struct rdc_descriptor * desc
Descriptors.
Definition: rdc.h:132
unsigned int address
PHY address.
Definition: mii.h:53
#define RDC_MMDIO
MAC MDIO control register.
Definition: rdc.h:61
#define RDC_MISR
MAC interrupt status register.
Definition: rdc.h:89
#define RDC_MCR1_RST
MAC reset.
Definition: rdc.h:48
static void rdc_refill_rx(struct rdc_nic *rdc)
Refill receive descriptor ring.
Definition: rdc.c:296
#define RDC_MIRQ_LINK
Link status changed.
Definition: rdc.h:90
#define RDC_MIRQ_TX
Transmit complete.
Definition: rdc.h:91
#define RDC_MRDSA
MAC receive descriptor start address.
Definition: rdc.h:80
#define RDC_MxDSA_LO
MAC descriptor start address low half.
Definition: rdc.h:83
static __always_inline physaddr_t dma(struct dma_mapping *map, void *addr)
Get DMA address from virtual address.
Definition: dma.h:436
void * pci_ioremap(struct pci_device *pci, unsigned long bus_addr, size_t len)
Map PCI bus address as an I/O address.
#define RDC_MPSCCR_PHYAD(x)
PHY address.
Definition: rdc.h:111
#define RDC_RX_MAX_LEN
Receive buffer length.
Definition: rdc.h:173
uint8_t hw_addr[MAX_HW_ADDR_LEN]
Hardware address.
Definition: netdevice.h:381
#define NULL
NULL pointer (VOID *)
Definition: Base.h:321
#define ETIMEDOUT
Connection timed out.
Definition: errno.h:669
String functions.
#define PCI_ROM(_vendor, _device, _name, _description, _data)
Definition: pci.h:303
void iob_pad(struct io_buffer *iobuf, size_t min_len)
Pad I/O buffer.
Definition: iobpad.c:49
#define RDC_MCR1
MAC control register 1.
Definition: rdc.h:47
void * regs
Registers.
Definition: rdc.h:178
static void rdc_irq(struct net_device *netdev, int enable)
Enable or disable interrupts.
Definition: rdc.c:562
struct mii_device mii
MII device.
Definition: rdc.h:184
u8 tx[WPA_TKIP_MIC_KEY_LEN]
MIC key for packets to the AP.
Definition: wpa.h:237
#define RDC_MII_MAX_WAIT_US
Maximum time to wait for an MII read or write.
Definition: rdc.h:68
static void rdc_poll(struct net_device *netdev)
Poll for completed and received packets.
Definition: rdc.c:525
void * memset(void *dest, int character, size_t len) __nonnull
A persistent I/O buffer.
Definition: iobuf.h:33
#define RDC_MCR0_FD
Full duplex.
Definition: rdc.h:41
static int rdc_transmit(struct net_device *netdev, struct io_buffer *iobuf)
Transmit packet.
Definition: rdc.c:410