iPXE
myson.c
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2012 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 <ipxe/mii.h>
38 #include "myson.h"
39 
40 /** @file
41  *
42  * Myson Technology network card driver
43  *
44  */
45 
46 /******************************************************************************
47  *
48  * Device reset
49  *
50  ******************************************************************************
51  */
52 
53 /**
54  * Reset controller chip
55  *
56  * @v myson Myson device
57  * @ret rc Return status code
58  */
59 static int myson_soft_reset ( struct myson_nic *myson ) {
60  uint32_t bcr;
61  unsigned int i;
62 
63  /* Initiate reset */
64  bcr = readl ( myson->regs + MYSON_BCR );
65  writel ( ( bcr | MYSON_BCR_SWR ), myson->regs + MYSON_BCR );
66 
67  /* Wait for reset to complete */
68  for ( i = 0 ; i < MYSON_RESET_MAX_WAIT_MS ; i++ ) {
69 
70  /* If reset is not complete, delay 1ms and retry */
71  if ( readl ( myson->regs + MYSON_BCR ) & MYSON_BCR_SWR ) {
72  mdelay ( 1 );
73  continue;
74  }
75 
76  /* Apply a sensible default bus configuration */
77  bcr = readl ( myson->regs + MYSON_BCR );
78  bcr &= ~MYSON_BCR_PBL_MASK;
81  writel ( bcr, myson->regs + MYSON_BCR );
82  DBGC ( myson, "MYSON %p using configuration %08x\n",
83  myson, bcr );
84 
85  return 0;
86  }
87 
88  DBGC ( myson, "MYSON %p timed out waiting for reset\n", myson );
89  return -ETIMEDOUT;
90 }
91 
92 /**
93  * Reload configuration from EEPROM
94  *
95  * @v myson Myson device
96  * @ret rc Return status code
97  */
98 static int myson_reload_config ( struct myson_nic *myson ) {
99  unsigned int i;
100 
101  /* Initiate reload */
103 
104  /* Wait for reload to complete */
105  for ( i = 0 ; i < MYSON_AUTOLD_MAX_WAIT_MS ; i++ ) {
106 
107  /* If reload is not complete, delay 1ms and retry */
108  if ( readl ( myson->regs + MYSON_ROM_MII ) & MYSON_ROM_AUTOLD ){
109  mdelay ( 1 );
110  continue;
111  }
112 
113  return 0;
114  }
115 
116  DBGC ( myson, "MYSON %p timed out waiting for configuration "
117  "reload\n", myson );
118  return -ETIMEDOUT;
119 }
120 
121 /**
122  * Reset hardware
123  *
124  * @v myson Myson device
125  * @ret rc Return status code
126  */
127 static int myson_reset ( struct myson_nic *myson ) {
128  int rc;
129 
130  /* Disable all interrupts */
131  writel ( 0, myson->regs + MYSON_IMR );
132 
133  /* Perform soft reset */
134  if ( ( rc = myson_soft_reset ( myson ) ) != 0 )
135  return rc;
136 
137  /* Reload configuration from EEPROM */
138  if ( ( rc = myson_reload_config ( myson ) ) != 0 )
139  return rc;
140 
141  return 0;
142 }
143 
144 /******************************************************************************
145  *
146  * Network device interface
147  *
148  ******************************************************************************
149  */
150 
151 /**
152  * Create descriptor ring
153  *
154  * @v myson Myson device
155  * @v ring Descriptor ring
156  * @ret rc Return status code
157  */
158 static int myson_create_ring ( struct myson_nic *myson,
159  struct myson_ring *ring ) {
160  size_t len = ( ring->count * sizeof ( ring->desc[0] ) );
161  struct myson_descriptor *desc;
162  struct myson_descriptor *next;
164  unsigned int i;
165  int rc;
166 
167  /* Allocate descriptor ring */
168  ring->desc = malloc_dma ( len, MYSON_RING_ALIGN );
169  if ( ! ring->desc ) {
170  rc = -ENOMEM;
171  goto err_alloc;
172  }
173  address = virt_to_bus ( ring->desc );
174 
175  /* Check address is usable by card */
176  if ( ! myson_address_ok ( address + len ) ) {
177  DBGC ( myson, "MYSON %p cannot support 64-bit ring address\n",
178  myson );
179  rc = -ENOTSUP;
180  goto err_64bit;
181  }
182 
183  /* Initialise descriptor ring */
184  memset ( ring->desc, 0, len );
185  for ( i = 0 ; i < ring->count ; i++ ) {
186  desc = &ring->desc[i];
187  next = &ring->desc[ ( i + 1 ) % ring->count ];
188  desc->next = cpu_to_le32 ( virt_to_bus ( next ) );
189  }
190 
191  /* Program ring address */
192  writel ( address, myson->regs + ring->reg );
193  DBGC ( myson, "MYSON %p ring %02x is at [%08llx,%08llx)\n",
194  myson, ring->reg, ( ( unsigned long long ) address ),
195  ( ( unsigned long long ) address + len ) );
196 
197  return 0;
198 
199  err_64bit:
200  free_dma ( ring->desc, len );
201  ring->desc = NULL;
202  err_alloc:
203  return rc;
204 }
205 
206 /**
207  * Destroy descriptor ring
208  *
209  * @v myson Myson device
210  * @v ring Descriptor ring
211  */
212 static void myson_destroy_ring ( struct myson_nic *myson,
213  struct myson_ring *ring ) {
214  size_t len = ( ring->count * sizeof ( ring->desc[0] ) );
215 
216  /* Clear ring address */
217  writel ( 0, myson->regs + ring->reg );
218 
219  /* Free descriptor ring */
220  free_dma ( ring->desc, len );
221  ring->desc = NULL;
222  ring->prod = 0;
223  ring->cons = 0;
224 }
225 
226 /**
227  * Refill receive descriptor ring
228  *
229  * @v netdev Network device
230  */
231 static void myson_refill_rx ( struct net_device *netdev ) {
232  struct myson_nic *myson = netdev->priv;
233  struct myson_descriptor *rx;
234  struct io_buffer *iobuf;
235  unsigned int rx_idx;
237 
238  while ( ( myson->rx.prod - myson->rx.cons ) < MYSON_NUM_RX_DESC ) {
239 
240  /* Allocate I/O buffer */
241  iobuf = alloc_iob ( MYSON_RX_MAX_LEN );
242  if ( ! iobuf ) {
243  /* Wait for next refill */
244  return;
245  }
246 
247  /* Check address is usable by card */
248  address = virt_to_bus ( iobuf->data );
249  if ( ! myson_address_ok ( address ) ) {
250  DBGC ( myson, "MYSON %p cannot support 64-bit RX "
251  "buffer address\n", myson );
252  netdev_rx_err ( netdev, iobuf, -ENOTSUP );
253  return;
254  }
255 
256  /* Get next receive descriptor */
257  rx_idx = ( myson->rx.prod++ % MYSON_NUM_RX_DESC );
258  rx = &myson->rx.desc[rx_idx];
259 
260  /* Populate receive descriptor */
261  rx->address = cpu_to_le32 ( address );
262  rx->control =
264  wmb();
265  rx->status = cpu_to_le32 ( MYSON_RX_STAT_OWN );
266  wmb();
267 
268  /* Record I/O buffer */
269  assert ( myson->rx_iobuf[rx_idx] == NULL );
270  myson->rx_iobuf[rx_idx] = iobuf;
271 
272  /* Notify card that there are descriptors available */
273  writel ( 0, myson->regs + MYSON_RXPDR );
274 
275  DBGC2 ( myson, "MYSON %p RX %d is [%llx,%llx)\n", myson,
276  rx_idx, ( ( unsigned long long ) address ),
277  ( ( unsigned long long ) address + MYSON_RX_MAX_LEN ) );
278  }
279 }
280 
281 /**
282  * Open network device
283  *
284  * @v netdev Network device
285  * @ret rc Return status code
286  */
287 static int myson_open ( struct net_device *netdev ) {
288  struct myson_nic *myson = netdev->priv;
290  int rc;
291 
292  /* Set MAC address */
293  memset ( &mac, 0, sizeof ( mac ) );
294  memcpy ( mac.raw, netdev->ll_addr, ETH_ALEN );
295  writel ( le32_to_cpu ( mac.reg.low ), myson->regs + MYSON_PAR0 );
296  writel ( le32_to_cpu ( mac.reg.high ), myson->regs + MYSON_PAR4 );
297 
298  /* Create transmit descriptor ring */
299  if ( ( rc = myson_create_ring ( myson, &myson->tx ) ) != 0 )
300  goto err_create_tx;
301 
302  /* Create receive descriptor ring */
303  if ( ( rc = myson_create_ring ( myson, &myson->rx ) ) != 0 )
304  goto err_create_rx;
305 
306  /* Configure transmitter and receiver */
309  myson->regs + MYSON_TCR_RCR );
310 
311  /* Fill receive ring */
313 
314  return 0;
315 
316  myson_destroy_ring ( myson, &myson->rx );
317  err_create_rx:
318  myson_destroy_ring ( myson, &myson->tx );
319  err_create_tx:
320  return rc;
321 }
322 
323 /**
324  * Wait for transmit and receive to become idle
325  *
326  * @v myson Myson device
327  * @ret rc Return status code
328  */
329 static int myson_wait_idle ( struct myson_nic *myson ) {
330  uint32_t tcr_rcr;
331  unsigned int i;
332 
333  /* Wait for both transmit and receive to be idle */
334  for ( i = 0 ; i < MYSON_IDLE_MAX_WAIT_MS ; i++ ) {
335 
336  /* If either process is running, delay 1ms and retry */
337  tcr_rcr = readl ( myson->regs + MYSON_TCR_RCR );
338  if ( tcr_rcr & ( MYSON_TCR_TXS | MYSON_RCR_RXS ) ) {
339  mdelay ( 1 );
340  continue;
341  }
342 
343  return 0;
344  }
345 
346  DBGC ( myson, "MYSON %p timed out waiting for idle state (status "
347  "%08x)\n", myson, tcr_rcr );
348  return -ETIMEDOUT;
349 }
350 
351 /**
352  * Close network device
353  *
354  * @v netdev Network device
355  */
356 static void myson_close ( struct net_device *netdev ) {
357  struct myson_nic *myson = netdev->priv;
358  unsigned int i;
359 
360  /* Disable receiver and transmitter */
361  writel ( 0, myson->regs + MYSON_TCR_RCR );
362 
363  /* Allow time for receiver and transmitter to become idle */
364  myson_wait_idle ( myson );
365 
366  /* Destroy receive descriptor ring */
367  myson_destroy_ring ( myson, &myson->rx );
368 
369  /* Discard any unused receive buffers */
370  for ( i = 0 ; i < MYSON_NUM_RX_DESC ; i++ ) {
371  if ( myson->rx_iobuf[i] )
372  free_iob ( myson->rx_iobuf[i] );
373  myson->rx_iobuf[i] = NULL;
374  }
375 
376  /* Destroy transmit descriptor ring */
377  myson_destroy_ring ( myson, &myson->tx );
378 }
379 
380 /**
381  * Transmit packet
382  *
383  * @v netdev Network device
384  * @v iobuf I/O buffer
385  * @ret rc Return status code
386  */
387 static int myson_transmit ( struct net_device *netdev,
388  struct io_buffer *iobuf ) {
389  struct myson_nic *myson = netdev->priv;
390  struct myson_descriptor *tx;
391  unsigned int tx_idx;
393 
394  /* Check address is usable by card */
395  address = virt_to_bus ( iobuf->data );
396  if ( ! myson_address_ok ( address ) ) {
397  DBGC ( myson, "MYSON %p cannot support 64-bit TX buffer "
398  "address\n", myson );
399  return -ENOTSUP;
400  }
401 
402  /* Get next transmit descriptor */
403  if ( ( myson->tx.prod - myson->tx.cons ) >= MYSON_NUM_TX_DESC ) {
404  DBGC ( myson, "MYSON %p out of transmit descriptors\n",
405  myson );
406  return -ENOBUFS;
407  }
408  tx_idx = ( myson->tx.prod++ % MYSON_NUM_TX_DESC );
409  tx = &myson->tx.desc[tx_idx];
410 
411  /* Populate transmit descriptor */
412  tx->address = cpu_to_le32 ( address );
416  MYSON_TX_CTRL_PKTS ( iob_len ( iobuf ) ) |
417  MYSON_TX_CTRL_TBS ( iob_len ( iobuf ) ) );
418  wmb();
419  tx->status = cpu_to_le32 ( MYSON_TX_STAT_OWN );
420  wmb();
421 
422  /* Notify card that there are packets ready to transmit */
423  writel ( 0, myson->regs + MYSON_TXPDR );
424 
425  DBGC2 ( myson, "MYSON %p TX %d is [%llx,%llx)\n", myson, tx_idx,
426  ( ( unsigned long long ) address ),
427  ( ( unsigned long long ) address + iob_len ( iobuf ) ) );
428 
429  return 0;
430 }
431 
432 /**
433  * Poll for completed packets
434  *
435  * @v netdev Network device
436  */
437 static void myson_poll_tx ( struct net_device *netdev ) {
438  struct myson_nic *myson = netdev->priv;
439  struct myson_descriptor *tx;
440  unsigned int tx_idx;
441 
442  /* Check for completed packets */
443  while ( myson->tx.cons != myson->tx.prod ) {
444 
445  /* Get next transmit descriptor */
446  tx_idx = ( myson->tx.cons % MYSON_NUM_TX_DESC );
447  tx = &myson->tx.desc[tx_idx];
448 
449  /* Stop if descriptor is still in use */
450  if ( tx->status & cpu_to_le32 ( MYSON_TX_STAT_OWN ) )
451  return;
452 
453  /* Complete TX descriptor */
454  if ( tx->status & cpu_to_le32 ( MYSON_TX_STAT_ABORT |
455  MYSON_TX_STAT_CSL ) ) {
456  DBGC ( myson, "MYSON %p TX %d completion error "
457  "(%08x)\n", myson, tx_idx,
458  le32_to_cpu ( tx->status ) );
460  } else {
461  DBGC2 ( myson, "MYSON %p TX %d complete\n",
462  myson, tx_idx );
464  }
465  myson->tx.cons++;
466  }
467 }
468 
469 /**
470  * Poll for received packets
471  *
472  * @v netdev Network device
473  */
474 static void myson_poll_rx ( struct net_device *netdev ) {
475  struct myson_nic *myson = netdev->priv;
476  struct myson_descriptor *rx;
477  struct io_buffer *iobuf;
478  unsigned int rx_idx;
479  size_t len;
480 
481  /* Check for received packets */
482  while ( myson->rx.cons != myson->rx.prod ) {
483 
484  /* Get next receive descriptor */
485  rx_idx = ( myson->rx.cons % MYSON_NUM_RX_DESC );
486  rx = &myson->rx.desc[rx_idx];
487 
488  /* Stop if descriptor is still in use */
489  if ( rx->status & MYSON_RX_STAT_OWN )
490  return;
491 
492  /* Populate I/O buffer */
493  iobuf = myson->rx_iobuf[rx_idx];
494  myson->rx_iobuf[rx_idx] = NULL;
495  len = MYSON_RX_STAT_FLNG ( le32_to_cpu ( rx->status ) );
496  iob_put ( iobuf, len - 4 /* strip CRC */ );
497 
498  /* Hand off to network stack */
499  if ( rx->status & cpu_to_le32 ( MYSON_RX_STAT_ES ) ) {
500  DBGC ( myson, "MYSON %p RX %d error (length %zd, "
501  "status %08x)\n", myson, rx_idx, len,
502  le32_to_cpu ( rx->status ) );
503  netdev_rx_err ( netdev, iobuf, -EIO );
504  } else {
505  DBGC2 ( myson, "MYSON %p RX %d complete (length "
506  "%zd)\n", myson, rx_idx, len );
507  netdev_rx ( netdev, iobuf );
508  }
509  myson->rx.cons++;
510  }
511 }
512 
513 /**
514  * Poll for completed and received packets
515  *
516  * @v netdev Network device
517  */
518 static void myson_poll ( struct net_device *netdev ) {
519  struct myson_nic *myson = netdev->priv;
520  uint32_t isr;
521  unsigned int i;
522 
523  /* Polling the ISR seems to really upset this card; it ends up
524  * getting no useful PCI transfers done and, for some reason,
525  * flooding the network with invalid packets. Work around
526  * this by introducing deliberate delays between ISR reads.
527  */
528  for ( i = 0 ; i < MYSON_ISR_IODELAY_COUNT ; i++ )
529  iodelay();
530 
531  /* Check for and acknowledge interrupts */
532  isr = readl ( myson->regs + MYSON_ISR );
533  if ( ! isr )
534  return;
535  writel ( isr, myson->regs + MYSON_ISR );
536 
537  /* Poll for TX completions, if applicable */
538  if ( isr & MYSON_IRQ_TI )
539  myson_poll_tx ( netdev );
540 
541  /* Poll for RX completionsm, if applicable */
542  if ( isr & MYSON_IRQ_RI )
543  myson_poll_rx ( netdev );
544 
545  /* Refill RX ring */
547 }
548 
549 /**
550  * Enable or disable interrupts
551  *
552  * @v netdev Network device
553  * @v enable Interrupts should be enabled
554  */
555 static void myson_irq ( struct net_device *netdev, int enable ) {
556  struct myson_nic *myson = netdev->priv;
557  uint32_t imr;
558 
559  imr = ( enable ? ( MYSON_IRQ_TI | MYSON_IRQ_RI ) : 0 );
560  writel ( imr, myson->regs + MYSON_IMR );
561 }
562 
563 /** Myson network device operations */
565  .open = myson_open,
566  .close = myson_close,
567  .transmit = myson_transmit,
568  .poll = myson_poll,
569  .irq = myson_irq,
570 };
571 
572 /******************************************************************************
573  *
574  * PCI interface
575  *
576  ******************************************************************************
577  */
578 
579 /**
580  * Probe PCI device
581  *
582  * @v pci PCI device
583  * @ret rc Return status code
584  */
585 static int myson_probe ( struct pci_device *pci ) {
586  struct net_device *netdev;
587  struct myson_nic *myson;
589  int rc;
590 
591  /* Allocate and initialise net device */
592  netdev = alloc_etherdev ( sizeof ( *myson ) );
593  if ( ! netdev ) {
594  rc = -ENOMEM;
595  goto err_alloc;
596  }
598  myson = netdev->priv;
599  pci_set_drvdata ( pci, netdev );
600  netdev->dev = &pci->dev;
601  memset ( myson, 0, sizeof ( *myson ) );
602  myson_init_ring ( &myson->tx, MYSON_NUM_TX_DESC, MYSON_TXLBA );
603  myson_init_ring ( &myson->rx, MYSON_NUM_RX_DESC, MYSON_RXLBA );
604 
605  /* Fix up PCI device */
606  adjust_pci_device ( pci );
607 
608  /* Map registers */
609  myson->regs = ioremap ( pci->membase, MYSON_BAR_SIZE );
610  if ( ! myson->regs ) {
611  rc = -ENODEV;
612  goto err_ioremap;
613  }
614 
615  /* Reset the NIC */
616  if ( ( rc = myson_reset ( myson ) ) != 0 )
617  goto err_reset;
618 
619  /* Read MAC address */
620  mac.reg.low = cpu_to_le32 ( readl ( myson->regs + MYSON_PAR0 ) );
621  mac.reg.high = cpu_to_le32 ( readl ( myson->regs + MYSON_PAR4 ) );
622  memcpy ( netdev->hw_addr, mac.raw, ETH_ALEN );
623 
624  /* Register network device */
625  if ( ( rc = register_netdev ( netdev ) ) != 0 )
626  goto err_register_netdev;
627 
628  /* Mark as link up; we don't yet handle link state */
630 
631  return 0;
632 
634  err_register_netdev:
635  myson_reset ( myson );
636  err_reset:
637  iounmap ( myson->regs );
638  err_ioremap:
640  netdev_put ( netdev );
641  err_alloc:
642  return rc;
643 }
644 
645 /**
646  * Remove PCI device
647  *
648  * @v pci PCI device
649  */
650 static void myson_remove ( struct pci_device *pci ) {
651  struct net_device *netdev = pci_get_drvdata ( pci );
652  struct myson_nic *myson = netdev->priv;
653 
654  /* Unregister network device */
656 
657  /* Reset card */
658  myson_reset ( myson );
659 
660  /* Free network device */
661  iounmap ( myson->regs );
663  netdev_put ( netdev );
664 }
665 
666 /** Myson PCI device IDs */
667 static struct pci_device_id myson_nics[] = {
668  PCI_ROM ( 0x1516, 0x0800, "mtd800", "MTD-8xx", 0 ),
669  PCI_ROM ( 0x1516, 0x0803, "mtd803", "Surecom EP-320X-S", 0 ),
670  PCI_ROM ( 0x1516, 0x0891, "mtd891", "MTD-8xx", 0 ),
671 };
672 
673 /** Myson PCI driver */
674 struct pci_driver myson_driver __pci_driver = {
675  .ids = myson_nics,
676  .id_count = ( sizeof ( myson_nics ) / sizeof ( myson_nics[0] ) ),
677  .probe = myson_probe,
678  .remove = myson_remove,
679 };
#define MYSON_RX_STAT_OWN
Owner.
Definition: myson.h:46
unsigned long membase
Memory base.
Definition: pci.h:194
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
wmb()
#define iob_put(iobuf, len)
Definition: iobuf.h:116
void netdev_rx_err(struct net_device *netdev, struct io_buffer *iobuf, int rc)
Discard received packet.
Definition: netdevice.c:501
static void myson_poll(struct net_device *netdev)
Poll for completed and received packets.
Definition: myson.c:518
A PCI driver.
Definition: pci.h:224
#define MYSON_RCR_RE
Receive enable.
Definition: myson.h:81
#define MYSON_BCR_PBL_MASK
Definition: myson.h:92
Definition: sis900.h:27
#define le32_to_cpu(value)
Definition: byteswap.h:113
int(* open)(struct net_device *netdev)
Open network device.
Definition: netdevice.h:222
static void myson_remove(struct pci_device *pci)
Remove PCI device.
Definition: myson.c:650
uint32_t next
Next descriptor address.
Definition: myson.h:18
static void myson_poll_tx(struct net_device *netdev)
Poll for completed packets.
Definition: myson.c:437
Error codes.
#define MYSON_AUTOLD_MAX_WAIT_MS
Maximum time to wait for a configuration reload, in milliseconds.
Definition: myson.h:136
#define MYSON_TCR_RCR
Transmit and Receive Configuration Register.
Definition: myson.h:72
#define MYSON_TX_STAT_ABORT
Abort.
Definition: myson.h:32
static void netdev_tx_complete_next(struct net_device *netdev)
Complete network transmission.
Definition: netdevice.h:758
I/O buffers.
void free_iob(struct io_buffer *iobuf)
Free I/O buffer.
Definition: iobuf.c:145
struct pci_device_id * ids
PCI ID table.
Definition: pci.h:226
uint64_t address
Base address.
Definition: ena.h:24
struct pci_driver myson_driver __pci_driver
Myson PCI driver.
Definition: myson.c:674
uint32_t readl(volatile uint32_t *io_addr)
Read 32-bit dword from memory-mapped device.
struct myson_descriptor * desc
Descriptors.
Definition: myson.h:141
#define DBGC(...)
Definition: compiler.h:505
struct io_buffer * rx_iobuf[MYSON_NUM_RX_DESC]
Receive I/O buffers.
Definition: myson.h:177
#define MYSON_RCR_ALP
Accept long packet.
Definition: myson.h:80
#define MYSON_ISR_IODELAY_COUNT
Number of I/O delays between ISR reads.
Definition: myson.h:126
A packet descriptor.
Definition: myson.h:19
void netdev_tx_complete_next_err(struct net_device *netdev, int rc)
Complete network transmission.
Definition: netdevice.c:434
static void myson_irq(struct net_device *netdev, int enable)
Enable or disable interrupts.
Definition: myson.c:555
#define MYSON_RCR_AB
Accept broadcast.
Definition: myson.h:77
#define MYSON_RING_ALIGN
Descriptor ring alignment.
Definition: myson.h:54
static int myson_open(struct net_device *netdev)
Open network device.
Definition: myson.c:287
#define MYSON_ROM_MII
Boot ROM / EEPROM / MII Management Register.
Definition: myson.h:132
uint8_t mac[ETH_ALEN]
MAC address.
Definition: ena.h:24
static int myson_reload_config(struct myson_nic *myson)
Reload configuration from EEPROM.
Definition: myson.c:98
#define MYSON_RX_CTRL_RBS(x)
Receive buffer size.
Definition: myson.h:51
void adjust_pci_device(struct pci_device *pci)
Enable PCI device.
Definition: pci.c:149
struct io_buffer * alloc_iob(size_t len)
Allocate I/O buffer.
Definition: iobuf.c:128
#define MYSON_RCR_RXS
Receive status.
Definition: myson.h:75
struct device dev
Generic device.
Definition: pci.h:189
#define MYSON_RCR_ARP
Accept runt packet.
Definition: myson.h:79
#define ENOTSUP
Operation not supported.
Definition: errno.h:589
Dynamic memory allocation.
static int myson_reset(struct myson_nic *myson)
Reset hardware.
Definition: myson.c:127
Myson Technology network card driver.
#define MYSON_ISR
Interrupt Status Register.
Definition: myson.h:121
static void netdev_init(struct net_device *netdev, struct net_device_operations *op)
Initialise a network device.
Definition: netdevice.h:498
static void pci_set_drvdata(struct pci_device *pci, void *priv)
Set PCI driver-private data.
Definition: pci.h:338
#define ENOMEM
Not enough space.
Definition: errno.h:534
#define MYSON_TX_CTRL_TBS(x)
Transmit buffer size.
Definition: myson.h:43
static struct net_device_operations myson_operations
Myson network device operations.
Definition: myson.c:564
void * memcpy(void *dest, const void *src, size_t len) __nonnull
static int myson_soft_reset(struct myson_nic *myson)
Reset controller chip.
Definition: myson.c:59
static __always_inline unsigned long virt_to_bus(volatile const void *addr)
Convert virtual address to a bus address.
Definition: io.h:183
assert((readw(&hdr->flags) &(GTF_reading|GTF_writing))==0)
#define MYSON_BCR_WIE
Write and invalidate.
Definition: myson.h:90
static void netdev_put(struct net_device *netdev)
Drop reference to network device.
Definition: netdevice.h:555
Ethernet protocol.
unsigned int reg
Descriptor start address register.
Definition: myson.h:150
void * priv
Driver private data.
Definition: netdevice.h:425
#define MYSON_TCR_TE
Transmit enable.
Definition: myson.h:74
#define MYSON_RXLBA
Receive List Base Address.
Definition: myson.h:112
static void netdev_link_up(struct net_device *netdev)
Mark network device as having link up.
Definition: netdevice.h:768
void writel(uint32_t data, volatile uint32_t *io_addr)
Write 32-bit dword to memory-mapped device.
#define MYSON_BCR_RLE
Read line enable.
Definition: myson.h:88
static struct net_device * netdev
Definition: gdbudp.c:52
static struct pci_device_id myson_nics[]
Myson PCI device IDs.
Definition: myson.c:667
Definition: sis900.h:26
static void myson_destroy_ring(struct myson_nic *myson, struct myson_ring *ring)
Destroy descriptor ring.
Definition: myson.c:212
void unregister_netdev(struct net_device *netdev)
Unregister network device.
Definition: netdevice.c:844
struct myson_ring rx
Receive descriptor ring.
Definition: myson.h:175
#define MYSON_TX_STAT_CSL
Carrier sense lost.
Definition: myson.h:33
uint32_t rx
Maximum number of receive queues.
Definition: intelvf.h:16
#define cpu_to_le32(value)
Definition: byteswap.h:107
static void myson_poll_rx(struct net_device *netdev)
Poll for received packets.
Definition: myson.c:474
FILE_LICENCE(GPL2_OR_LATER_OR_UBDL)
#define MYSON_PAR4
Physical Address Register 4.
Definition: myson.h:60
unsigned int prod
Producer index.
Definition: myson.h:143
#define MYSON_IDLE_MAX_WAIT_MS
Maximum time to wait for transmit and receive to be idle, in milliseconds.
Definition: myson.h:84
struct myson_ring tx
Transmit descriptor ring.
Definition: myson.h:173
uint32_t tx
Maximum number of transmit queues.
Definition: intelvf.h:14
#define MYSON_TXLBA
Transmit List Base Address.
Definition: myson.h:106
#define MYSON_TX_CTRL_PAD
Pad control.
Definition: myson.h:40
PCI bus.
static int myson_probe(struct pci_device *pci)
Probe PCI device.
Definition: myson.c:585
static int myson_wait_idle(struct myson_nic *myson)
Wait for transmit and receive to become idle.
Definition: myson.c:329
A PCI device.
Definition: pci.h:187
int register_netdev(struct net_device *netdev)
Register network device.
Definition: netdevice.c:667
static size_t iob_len(struct io_buffer *iobuf)
Calculate length of data in an I/O buffer.
Definition: iobuf.h:151
#define MYSON_RCR_PROM
Promiscuous mode.
Definition: myson.h:76
A network device.
Definition: netdevice.h:348
Media Independent Interface.
#define ENODEV
No such device.
Definition: errno.h:509
#define MYSON_NUM_TX_DESC
Number of transmit descriptors.
Definition: myson.h:109
static void netdev_nullify(struct net_device *netdev)
Stop using a network device.
Definition: netdevice.h:511
unsigned int cons
Consumer index.
Definition: myson.h:145
static void myson_refill_rx(struct net_device *netdev)
Refill receive descriptor ring.
Definition: myson.c:231
#define MYSON_PAR0
Physical Address Register 0.
Definition: myson.h:57
#define MYSON_RCR_AM
Accept multicast.
Definition: myson.h:78
#define MYSON_BCR_PBL_DEFAULT
Definition: myson.h:93
#define ETH_ALEN
Definition: if_ether.h:8
A PCI device ID list entry.
Definition: pci.h:151
#define MYSON_BCR
Bus Command Register.
Definition: myson.h:87
unsigned int uint32_t
Definition: stdint.h:12
#define MYSON_BCR_SWR
Software reset.
Definition: myson.h:94
#define MYSON_BAR_SIZE
BAR size.
Definition: myson.h:16
#define MYSON_IRQ_TI
Transmit interrupt.
Definition: myson.h:122
static struct xen_remove_from_physmap * remove
Definition: xenmem.h:39
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:470
#define MYSON_NUM_RX_DESC
Number of receive descriptors.
Definition: myson.h:115
struct device * dev
Underlying hardware device.
Definition: netdevice.h:360
static void myson_close(struct net_device *netdev)
Close network device.
Definition: myson.c:356
#define MYSON_TXPDR
Transmit Poll Demand Register.
Definition: myson.h:100
Network device management.
#define MYSON_TX_CTRL_FD
First descriptor.
Definition: myson.h:38
unsigned long physaddr_t
Definition: stdint.h:20
#define MYSON_IRQ_RI
Receive interrupt.
Definition: myson.h:123
static void * pci_get_drvdata(struct pci_device *pci)
Get PCI driver-private data.
Definition: pci.h:348
void mdelay(unsigned long msecs)
Delay for a fixed number of milliseconds.
Definition: timer.c:78
Physical address.
Definition: myson.h:63
uint32_t len
Length.
Definition: ena.h:14
#define ENOBUFS
No buffer space available.
Definition: errno.h:498
#define DBGC2(...)
Definition: compiler.h:522
int(* probe)(struct pci_device *pci)
Probe device.
Definition: pci.h:237
#define MYSON_RX_MAX_LEN
Receive buffer length.
Definition: myson.h:118
static int myson_transmit(struct net_device *netdev, struct io_buffer *iobuf)
Transmit packet.
Definition: myson.c:387
#define MYSON_BCR_RME
Read multiple enable.
Definition: myson.h:89
void * data
Start of data.
Definition: iobuf.h:44
#define EIO
Input/output error.
Definition: errno.h:433
#define MYSON_TX_CTRL_RTLC
Retry late collision.
Definition: myson.h:41
unsigned int count
Number of descriptors.
Definition: myson.h:148
#define MYSON_TX_CTRL_PKTS(x)
Packet size.
Definition: myson.h:42
struct net_device * alloc_etherdev(size_t priv_size)
Allocate Ethernet device.
Definition: ethernet.c:264
static void *__malloc malloc_dma(size_t size, size_t phys_align)
Allocate memory for DMA.
Definition: malloc.h:66
#define MYSON_TX_CTRL_LD
Last descriptor.
Definition: myson.h:37
void iounmap(volatile const void *io_addr)
Unmap I/O address.
#define MYSON_TCR_TXS
Transmit status.
Definition: myson.h:73
#define MYSON_TX_STAT_OWN
Owner.
Definition: myson.h:31
#define MYSON_TX_CTRL_IC
Interrupt control.
Definition: myson.h:36
void * regs
Registers.
Definition: myson.h:170
#define MYSON_RX_STAT_ES
Error summary.
Definition: myson.h:48
uint8_t ll_addr[MAX_LL_ADDR_LEN]
Link-layer address.
Definition: netdevice.h:381
#define MYSON_RX_STAT_FLNG(status)
Definition: myson.h:47
A myson network card.
Definition: myson.h:168
void * ioremap(unsigned long bus_addr, size_t len)
Map bus address as an I/O address.
#define MYSON_TX_CTRL_CRC
CRC append.
Definition: myson.h:39
#define MYSON_ROM_AUTOLD
Auto load.
Definition: myson.h:133
void iodelay(void)
Slow down I/O.
static void free_dma(void *ptr, size_t size)
Free memory allocated with malloc_dma()
Definition: malloc.h:81
uint8_t hw_addr[MAX_HW_ADDR_LEN]
Hardware address.
Definition: netdevice.h:375
#define NULL
NULL pointer (VOID *)
Definition: Base.h:362
#define ETIMEDOUT
Connection timed out.
Definition: errno.h:669
A Myson descriptor ring.
Definition: myson.h:139
String functions.
#define PCI_ROM(_vendor, _device, _name, _description, _data)
Definition: pci.h:283
#define MYSON_IMR
Interrupt Mask Register.
Definition: myson.h:129
uint32_t next
Next descriptor address.
Definition: myson.h:27
#define MYSON_RXPDR
Receive Poll Demand Register.
Definition: myson.h:103
static int myson_create_ring(struct myson_nic *myson, struct myson_ring *ring)
Create descriptor ring.
Definition: myson.c:158
void * memset(void *dest, int character, size_t len) __nonnull
A persistent I/O buffer.
Definition: iobuf.h:32
#define MYSON_RESET_MAX_WAIT_MS
Maximum time to wait for a reset, in milliseconds.
Definition: myson.h:97