iPXE
icplus.c
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2018 Sylvie Barlow <sylvie.c.barlow@gmail.com>.
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 "icplus.h"
38 
39 /** @file
40  *
41  * IC+ network driver
42  *
43  */
44 
45 /******************************************************************************
46  *
47  * Device reset
48  *
49  ******************************************************************************
50  */
51 
52 /**
53  * Reset hardware
54  *
55  * @v icp IC+ device
56  * @ret rc Return status code
57  */
58 static int icplus_reset ( struct icplus_nic *icp ) {
59  uint32_t asicctrl;
60  unsigned int i;
61 
62  /* Trigger reset */
65  ICP_ASICCTRL_AUTOINIT ), ( icp->regs + ICP_ASICCTRL ) );
66 
67  /* Wait for reset to complete */
68  for ( i = 0 ; i < ICP_RESET_MAX_WAIT_MS ; i++ ) {
69 
70  /* Check if device is ready */
71  asicctrl = readl ( icp->regs + ICP_ASICCTRL );
72  if ( ! ( asicctrl & ICP_ASICCTRL_RESETBUSY ) )
73  return 0;
74 
75  /* Delay */
76  mdelay ( 1 );
77  }
78 
79  DBGC ( icp, "ICPLUS %p timed out waiting for reset (asicctrl %#08x)\n",
80  icp, asicctrl );
81  return -ETIMEDOUT;
82 }
83 
84 /******************************************************************************
85  *
86  * EEPROM interface
87  *
88  ******************************************************************************
89  */
90 
91 /**
92  * Read data from EEPROM
93  *
94  * @v nvs NVS device
95  * @v address Address from which to read
96  * @v data Data buffer
97  * @v len Length of data buffer
98  * @ret rc Return status code
99  */
100 static int icplus_read_eeprom ( struct nvs_device *nvs, unsigned int address,
101  void *data, size_t len ) {
102  struct icplus_nic *icp =
103  container_of ( nvs, struct icplus_nic, eeprom );
104  unsigned int i;
105  uint16_t eepromctrl;
106  uint16_t *data_word = data;
107 
108  /* Sanity check. We advertise a blocksize of one word, so
109  * should only ever receive single-word requests.
110  */
111  assert ( len == sizeof ( *data_word ) );
112 
113  /* Initiate read */
116  ( icp->regs + ICP_EEPROMCTRL ) );
117 
118  /* Wait for read to complete */
119  for ( i = 0 ; i < ICP_EEPROM_MAX_WAIT_MS ; i++ ) {
120 
121  /* If read is not complete, delay 1ms and retry */
122  eepromctrl = readw ( icp->regs + ICP_EEPROMCTRL );
123  if ( eepromctrl & ICP_EEPROMCTRL_BUSY ) {
124  mdelay ( 1 );
125  continue;
126  }
127 
128  /* Extract data */
129  *data_word = cpu_to_le16 ( readw ( icp->regs + ICP_EEPROMDATA ));
130  return 0;
131  }
132 
133  DBGC ( icp, "ICPLUS %p timed out waiting for EEPROM read\n", icp );
134  return -ETIMEDOUT;
135 }
136 
137 /**
138  * Write data to EEPROM
139  *
140  * @v nvs NVS device
141  * @v address Address to which to write
142  * @v data Data buffer
143  * @v len Length of data buffer
144  * @ret rc Return status code
145  */
146 static int icplus_write_eeprom ( struct nvs_device *nvs,
147  unsigned int address __unused,
148  const void *data __unused,
149  size_t len __unused ) {
150  struct icplus_nic *icp =
151  container_of ( nvs, struct icplus_nic, eeprom );
152 
153  DBGC ( icp, "ICPLUS %p EEPROM write not supported\n", icp );
154  return -ENOTSUP;
155 }
156 
157 /**
158  * Initialise EEPROM
159  *
160  * @v icp IC+ device
161  */
162 static void icplus_init_eeprom ( struct icplus_nic *icp ) {
163 
164  /* The hardware supports only single-word reads */
167  icp->eeprom.block_size = 1;
170 }
171 
172 /******************************************************************************
173  *
174  * MII interface
175  *
176  ******************************************************************************
177  */
178 
179 /** Pin mapping for MII bit-bashing interface */
180 static const uint8_t icplus_mii_bits[] = {
184 };
185 
186 /**
187  * Read input bit
188  *
189  * @v basher Bit-bashing interface
190  * @v bit_id Bit number
191  * @ret zero Input is a logic 0
192  * @ret non-zero Input is a logic 1
193  */
194 static int icplus_mii_read_bit ( struct bit_basher *basher,
195  unsigned int bit_id ) {
196  struct icplus_nic *icp = container_of ( basher, struct icplus_nic,
197  miibit.basher );
198  uint8_t mask = icplus_mii_bits[bit_id];
199  uint8_t reg;
200 
202  reg = readb ( icp->regs + ICP_PHYCTRL );
203  DBG_ENABLE ( DBGLVL_IO );
204  return ( reg & mask );
205 }
206 
207 /**
208  * Set/clear output bit
209  *
210  * @v basher Bit-bashing interface
211  * @v bit_id Bit number
212  * @v data Value to write
213  */
214 static void icplus_mii_write_bit ( struct bit_basher *basher,
215  unsigned int bit_id, unsigned long data ) {
216  struct icplus_nic *icp = container_of ( basher, struct icplus_nic,
217  miibit.basher );
218  uint8_t mask = icplus_mii_bits[bit_id];
219  uint8_t reg;
220 
222  reg = readb ( icp->regs + ICP_PHYCTRL );
223  reg &= ~mask;
224  reg |= ( data & mask );
225  writeb ( reg, icp->regs + ICP_PHYCTRL );
226  readb ( icp->regs + ICP_PHYCTRL ); /* Ensure write reaches chip */
227  DBG_ENABLE ( DBGLVL_IO );
228 }
229 
230 /** MII bit-bashing interface */
233  .write = icplus_mii_write_bit,
234 };
235 
236 /******************************************************************************
237  *
238  * Link state
239  *
240  ******************************************************************************
241  */
242 
243 /**
244  * Configure PHY
245  *
246  * @v icp IC+ device
247  * @ret rc Return status code
248  */
249 static int icplus_init_phy ( struct icplus_nic *icp ) {
250  uint32_t asicctrl;
251  int rc;
252 
253  /* Find PHY address */
254  if ( ( rc = mii_find ( &icp->mii ) ) != 0 ) {
255  DBGC ( icp, "ICPLUS %p could not find PHY address: %s\n",
256  icp, strerror ( rc ) );
257  return rc;
258  }
259 
260  /* Configure PHY to advertise 1000Mbps if applicable */
261  asicctrl = readl ( icp->regs + ICP_ASICCTRL );
262  if ( asicctrl & ICP_ASICCTRL_PHYSPEED1000 ) {
263  if ( ( rc = mii_write ( &icp->mii, MII_CTRL1000,
264  ADVERTISE_1000FULL ) ) != 0 ) {
265  DBGC ( icp, "ICPLUS %p could not advertise 1000Mbps: "
266  "%s\n", icp, strerror ( rc ) );
267  return rc;
268  }
269  }
270 
271  /* Reset PHY */
272  if ( ( rc = mii_reset ( &icp->mii ) ) != 0 ) {
273  DBGC ( icp, "ICPLUS %p could not reset PHY: %s\n",
274  icp, strerror ( rc ) );
275  return rc;
276  }
277 
278  return 0;
279 }
280 
281 /**
282  * Check link state
283  *
284  * @v netdev Network device
285  */
286 static void icplus_check_link ( struct net_device *netdev ) {
287  struct icplus_nic *icp = netdev->priv;
288  uint8_t phyctrl;
289 
290  /* Read link status */
291  phyctrl = readb ( icp->regs + ICP_PHYCTRL );
292  DBGC ( icp, "ICPLUS %p PHY control is %02x\n", icp, phyctrl );
293 
294  /* Update network device */
295  if ( phyctrl & ICP_PHYCTRL_LINKSPEED ) {
297  } else {
299  }
300 }
301 
302 /******************************************************************************
303  *
304  * Network device interface
305  *
306  ******************************************************************************
307  */
308 
309 /**
310  * Set descriptor ring base address
311  *
312  * @v icp IC+ device
313  * @v offset Register offset
314  * @v address Base address
315  */
316 static inline void icplus_set_base ( struct icplus_nic *icp, unsigned int offset,
317  void *base ) {
319 
320  /* Program base address registers */
321  writel ( ( phys & 0xffffffffUL ),
322  ( icp->regs + offset + ICP_BASE_LO ) );
323  if ( sizeof ( phys ) > sizeof ( uint32_t ) ) {
324  writel ( ( ( ( uint64_t ) phys ) >> 32 ),
325  ( icp->regs + offset + ICP_BASE_HI ) );
326  } else {
327  writel ( 0, ( icp->regs + offset + ICP_BASE_HI ) );
328  }
329 }
330 
331 /**
332  * Create descriptor ring
333  *
334  * @v icp IC+ device
335  * @v ring Descriptor ring
336  * @ret rc Return status code
337  */
338 static int icplus_create_ring ( struct icplus_nic *icp, struct icplus_ring *ring ) {
339  size_t len = ( sizeof ( ring->entry[0] ) * ICP_NUM_DESC );
340  int rc;
341  unsigned int i;
342  struct icplus_descriptor *desc;
343  struct icplus_descriptor *next;
344 
345  /* Allocate descriptor ring */
346  ring->entry = malloc_dma ( len, ICP_ALIGN );
347  if ( ! ring->entry ) {
348  rc = -ENOMEM;
349  goto err_alloc;
350  }
351 
352  /* Initialise descriptor ring */
353  memset ( ring->entry, 0, len );
354  for ( i = 0 ; i < ICP_NUM_DESC ; i++ ) {
355  desc = &ring->entry[i];
356  next = &ring->entry[ ( i + 1 ) % ICP_NUM_DESC ];
357  desc->next = cpu_to_le64 ( virt_to_bus ( next ) );
358  desc->flags = ( ICP_TX_UNALIGN | ICP_TX_INDICATE );
359  desc->control = ( ICP_TX_SOLE_FRAG | ICP_DONE );
360  }
361 
362  /* Reset transmit producer & consumer counters */
363  ring->prod = 0;
364  ring->cons = 0;
365 
366  DBGC ( icp, "ICP %p %s ring at [%#08lx,%#08lx)\n",
367  icp, ( ( ring->listptr == ICP_TFDLISTPTR ) ? "TX" : "RX" ),
368  virt_to_bus ( ring->entry ),
369  ( virt_to_bus ( ring->entry ) + len ) );
370  return 0;
371 
372  free_dma ( ring->entry, len );
373  ring->entry = NULL;
374  err_alloc:
375  return rc;
376 }
377 
378 /**
379  * Destroy descriptor ring
380  *
381  * @v icp IC+ device
382  * @v ring Descriptor ring
383  */
384 static void icplus_destroy_ring ( struct icplus_nic *icp __unused,
385  struct icplus_ring *ring ) {
386  size_t len = ( sizeof ( ring->entry[0] ) * ICP_NUM_DESC );
387 
388  /* Free descriptor ring */
389  free_dma ( ring->entry, len );
390  ring->entry = NULL;
391 }
392 
393 /**
394  * Refill receive descriptor ring
395  *
396  * @v icp IC+ device
397  */
398 void icplus_refill_rx ( struct icplus_nic *icp ) {
399  struct icplus_descriptor *desc;
400  struct io_buffer *iobuf;
401  unsigned int rx_idx;
403  unsigned int refilled = 0;
404 
405  /* Refill ring */
406  while ( ( icp->rx.prod - icp->rx.cons ) < ICP_NUM_DESC ) {
407 
408  /* Allocate I/O buffer */
409  iobuf = alloc_iob ( ICP_RX_MAX_LEN );
410  if ( ! iobuf ) {
411  /* Wait for next refill */
412  break;
413  }
414 
415  /* Get next receive descriptor */
416  rx_idx = ( icp->rx.prod++ % ICP_NUM_DESC );
417  desc = &icp->rx.entry[rx_idx];
418 
419  /* Populate receive descriptor */
420  address = virt_to_bus ( iobuf->data );
421  desc->data.address = cpu_to_le64 ( address );
422  desc->data.len = cpu_to_le16 ( ICP_RX_MAX_LEN );
423  wmb();
424  desc->control = 0;
425 
426  /* Record I/O buffer */
427  assert ( icp->rx_iobuf[rx_idx] == NULL );
428  icp->rx_iobuf[rx_idx] = iobuf;
429 
430  DBGC2 ( icp, "ICP %p RX %d is [%llx,%llx)\n", icp, rx_idx,
431  ( ( unsigned long long ) address ),
432  ( ( unsigned long long ) address + ICP_RX_MAX_LEN ) );
433  refilled++;
434  }
435 
436  /* Push descriptors to card, if applicable */
437  if ( refilled ) {
438  wmb();
440  }
441 }
442 
443 /**
444  * Open network device
445  *
446  * @v netdev Network device
447  * @ret rc Return status code
448  */
449 static int icplus_open ( struct net_device *netdev ) {
450  struct icplus_nic *icp = netdev->priv;
451  int rc;
452 
453  /* Create transmit descriptor ring */
454  if ( ( rc = icplus_create_ring ( icp, &icp->tx ) ) != 0 )
455  goto err_create_tx;
456 
457  /* Create receive descriptor ring */
458  if ( ( rc = icplus_create_ring ( icp, &icp->rx ) ) != 0 )
459  goto err_create_rx;
460 
461  /* Program descriptor base address */
462  icplus_set_base ( icp, icp->tx.listptr, icp->tx.entry );
463  icplus_set_base ( icp, icp->rx.listptr, icp->rx.entry );
464 
465  /* Enable receive mode */
468  icp->regs + ICP_RXMODE );
469 
470  /* Enable transmitter and receiver */
472  ICP_MACCTRL_DUPLEX ), icp->regs + ICP_MACCTRL );
473 
474  /* Fill receive ring */
475  icplus_refill_rx ( icp );
476 
477  /* Check link state */
479 
480  return 0;
481 
482  icplus_reset ( icp );
483  icplus_destroy_ring ( icp, &icp->rx );
484  err_create_rx:
485  icplus_destroy_ring ( icp, &icp->tx );
486  err_create_tx:
487  return rc;
488 }
489 
490 /**
491  * Close network device
492  *
493  * @v netdev Network device
494  */
495 static void icplus_close ( struct net_device *netdev ) {
496  struct icplus_nic *icp = netdev->priv;
497  unsigned int i;
498 
499  /* Perform global reset */
500  icplus_reset ( icp );
501 
502  /* Destroy receive descriptor ring */
503  icplus_destroy_ring ( icp, &icp->rx );
504 
505  /* Destroy transmit descriptor ring */
506  icplus_destroy_ring ( icp, &icp->tx );
507 
508  /* Discard any unused receive buffers */
509  for ( i = 0 ; i < ICP_NUM_DESC ; i++ ) {
510  if ( icp->rx_iobuf[i] )
511  free_iob ( icp->rx_iobuf[i] );
512  icp->rx_iobuf[i] = NULL;
513  }
514 }
515 
516 /**
517  * Transmit packet
518  *
519  * @v netdev Network device
520  * @v iobuf I/O buffer
521  * @ret rc Return status code
522  */
523 static int icplus_transmit ( struct net_device *netdev,
524  struct io_buffer *iobuf ) {
525  struct icplus_nic *icp = netdev->priv;
526  struct icplus_descriptor *desc;
527  unsigned int tx_idx;
529 
530  /* Check if ring is full */
531  if ( ( icp->tx.prod - icp->tx.cons ) >= ICP_NUM_DESC ) {
532  DBGC ( icp, "ICP %p out of transmit descriptors\n", icp );
533  return -ENOBUFS;
534  }
535 
536  /* Find TX descriptor entry to use */
537  tx_idx = ( icp->tx.prod++ % ICP_NUM_DESC );
538  desc = &icp->tx.entry[tx_idx];
539 
540  /* Fill in TX descriptor */
541  address = virt_to_bus ( iobuf->data );
542  desc->data.address = cpu_to_le64 ( address );
543  desc->data.len = cpu_to_le16 ( iob_len ( iobuf ) );
544  wmb();
545  desc->control = ICP_TX_SOLE_FRAG;
546  wmb();
547 
548  /* Ring doorbell */
550 
551  DBGC2 ( icp, "ICP %p TX %d is [%llx,%llx)\n", icp, tx_idx,
552  ( ( unsigned long long ) address ),
553  ( ( unsigned long long ) address + iob_len ( iobuf ) ) );
554  DBGC2_HDA ( icp, virt_to_phys ( desc ), desc, sizeof ( *desc ) );
555  return 0;
556 }
557 
558 /**
559  * Poll for completed packets
560  *
561  * @v netdev Network device
562  */
563 static void icplus_poll_tx ( struct net_device *netdev ) {
564  struct icplus_nic *icp = netdev->priv;
565  struct icplus_descriptor *desc;
566  unsigned int tx_idx;
567 
568  /* Check for completed packets */
569  while ( icp->tx.cons != icp->tx.prod ) {
570 
571  /* Get next transmit descriptor */
572  tx_idx = ( icp->tx.cons % ICP_NUM_DESC );
573  desc = &icp->tx.entry[tx_idx];
574 
575  /* Stop if descriptor is still in use */
576  if ( ! ( desc->control & ICP_DONE ) )
577  return;
578 
579  /* Complete TX descriptor */
580  DBGC2 ( icp, "ICP %p TX %d complete\n", icp, tx_idx );
582  icp->tx.cons++;
583  }
584 }
585 
586 /**
587  * Poll for received packets
588  *
589  * @v netdev Network device
590  */
591 static void icplus_poll_rx ( struct net_device *netdev ) {
592  struct icplus_nic *icp = netdev->priv;
593  struct icplus_descriptor *desc;
594  struct io_buffer *iobuf;
595  unsigned int rx_idx;
596  size_t len;
597 
598  /* Check for received packets */
599  while ( icp->rx.cons != icp->rx.prod ) {
600 
601  /* Get next transmit descriptor */
602  rx_idx = ( icp->rx.cons % ICP_NUM_DESC );
603  desc = &icp->rx.entry[rx_idx];
604 
605  /* Stop if descriptor is still in use */
606  if ( ! ( desc->control & ICP_DONE ) )
607  return;
608 
609  /* Populate I/O buffer */
610  iobuf = icp->rx_iobuf[rx_idx];
611  icp->rx_iobuf[rx_idx] = NULL;
612  len = le16_to_cpu ( desc->len );
613  iob_put ( iobuf, len );
614 
615  /* Hand off to network stack */
616  if ( desc->flags & ( ICP_RX_ERR_OVERRUN | ICP_RX_ERR_RUNT |
619  DBGC ( icp, "ICP %p RX %d error (length %zd, "
620  "flags %02x)\n", icp, rx_idx, len, desc->flags );
621  netdev_rx_err ( netdev, iobuf, -EIO );
622  } else {
623  DBGC2 ( icp, "ICP %p RX %d complete (length "
624  "%zd)\n", icp, rx_idx, len );
625  netdev_rx ( netdev, iobuf );
626  }
627  icp->rx.cons++;
628  }
629 }
630 
631 /**
632  * Poll for completed and received packets
633  *
634  * @v netdev Network device
635  */
636 static void icplus_poll ( struct net_device *netdev ) {
637  struct icplus_nic *icp = netdev->priv;
638  uint16_t intstatus;
639  uint32_t txstatus;
640 
641  /* Check for interrupts */
642  intstatus = readw ( icp->regs + ICP_INTSTATUS );
643 
644  /* Poll for TX completions, if applicable */
645  if ( intstatus & ICP_INTSTATUS_TXCOMPLETE ) {
646  txstatus = readl ( icp->regs + ICP_TXSTATUS );
647  if ( txstatus & ICP_TXSTATUS_ERROR )
648  DBGC ( icp, "ICP %p TX error: %08x\n", icp, txstatus );
650  }
651 
652  /* Poll for RX completions, if applicable */
653  if ( intstatus & ICP_INTSTATUS_RXDMACOMPLETE ) {
656  }
657 
658  /* Check link state, if applicable */
659  if ( intstatus & ICP_INTSTATUS_LINKEVENT ) {
662  }
663 
664  /* Refill receive ring */
665  icplus_refill_rx ( icp );
666 }
667 
668 /**
669  * Enable or disable interrupts
670  *
671  * @v netdev Network device
672  * @v enable Interrupts should be enabled
673  */
674 static void icplus_irq ( struct net_device *netdev, int enable ) {
675  struct icplus_nic *icp = netdev->priv;
676 
677  DBGC ( icp, "ICPLUS %p does not yet support interrupts\n", icp );
678  ( void ) enable;
679 }
680 
681 /** IC+ network device operations */
683  .open = icplus_open,
684  .close = icplus_close,
685  .transmit = icplus_transmit,
686  .poll = icplus_poll,
687  .irq = icplus_irq,
688 };
689 
690 /******************************************************************************
691  *
692  * PCI interface
693  *
694  ******************************************************************************
695  */
696 
697 /**
698  * Probe PCI device
699  *
700  * @v pci PCI device
701  * @ret rc Return status code
702  */
703 static int icplus_probe ( struct pci_device *pci ) {
704  struct net_device *netdev;
705  struct icplus_nic *icp;
706  int rc;
707 
708  /* Allocate and initialise net device */
709  netdev = alloc_etherdev ( sizeof ( *icp ) );
710  if ( ! netdev ) {
711  rc = -ENOMEM;
712  goto err_alloc;
713  }
715  icp = netdev->priv;
716  pci_set_drvdata ( pci, netdev );
717  netdev->dev = &pci->dev;
718  memset ( icp, 0, sizeof ( *icp ) );
720  init_mii_bit_basher ( &icp->miibit );
721  mii_init ( &icp->mii, &icp->miibit.mdio, 0 );
722  icp->tx.listptr = ICP_TFDLISTPTR;
723  icp->rx.listptr = ICP_RFDLISTPTR;
724 
725  /* Fix up PCI device */
726  adjust_pci_device ( pci );
727 
728  /* Map registers */
729  icp->regs = ioremap ( pci->membase, ICP_BAR_SIZE );
730  if ( ! icp->regs ) {
731  rc = -ENODEV;
732  goto err_ioremap;
733  }
734 
735  /* Reset the NIC */
736  if ( ( rc = icplus_reset ( icp ) ) != 0 )
737  goto err_reset;
738 
739  /* Initialise EEPROM */
740  icplus_init_eeprom ( icp );
741 
742  /* Read EEPROM MAC address */
743  if ( ( rc = nvs_read ( &icp->eeprom, ICP_EEPROM_MAC,
744  netdev->hw_addr, ETH_ALEN ) ) != 0 ) {
745  DBGC ( icp, "ICPLUS %p could not read EEPROM MAC address: %s\n",
746  icp, strerror ( rc ) );
747  goto err_eeprom;
748  }
749 
750  /* Configure PHY */
751  if ( ( rc = icplus_init_phy ( icp ) ) != 0 )
752  goto err_phy;
753 
754  /* Register network device */
755  if ( ( rc = register_netdev ( netdev ) ) != 0 )
756  goto err_register_netdev;
757 
758  /* Set initial link state */
760 
761  return 0;
762 
764  err_register_netdev:
765  err_phy:
766  err_eeprom:
767  icplus_reset ( icp );
768  err_reset:
769  iounmap ( icp->regs );
770  err_ioremap:
772  netdev_put ( netdev );
773  err_alloc:
774  return rc;
775 }
776 
777 /**
778  * Remove PCI device
779  *
780  * @v pci PCI device
781  */
782 static void icplus_remove ( struct pci_device *pci ) {
783  struct net_device *netdev = pci_get_drvdata ( pci );
784  struct icplus_nic *icp = netdev->priv;
785 
786  /* Unregister network device */
788 
789  /* Reset card */
790  icplus_reset ( icp );
791 
792  /* Free network device */
793  iounmap ( icp->regs );
795  netdev_put ( netdev );
796 }
797 
798 /** IC+ PCI device IDs */
799 static struct pci_device_id icplus_nics[] = {
800  PCI_ROM ( 0x13f0, 0x1023, "ip1000a", "IP1000A", 0 ),
801 };
802 
803 /** IC+ PCI driver */
804 struct pci_driver icplus_driver __pci_driver = {
805  .ids = icplus_nics,
806  .id_count = ( sizeof ( icplus_nics ) / sizeof ( icplus_nics[0] ) ),
807  .probe = icplus_probe,
809 };
#define ICP_ASICCTRL_PHYSPEED1000
PHY speed 1000.
Definition: icplus.h:29
#define ICP_ASICCTRL_AUTOINIT
Auto init.
Definition: icplus.h:35
#define ICP_EEPROM_WORD_LEN_LOG2
EEPROM word length.
Definition: icplus.h:58
#define ICP_TXSTATUS_ERROR
TX error.
Definition: icplus.h:105
#define ICP_EEPROM_MAC
Address of MAC address within EEPROM.
Definition: icplus.h:64
int(* write)(struct nvs_device *nvs, unsigned int address, const void *data, size_t len)
Write data to device.
Definition: nvs.h:59
#define ICP_MACCTRL
MAC control register (double word)
Definition: icplus.h:76
unsigned long membase
Memory base.
Definition: pci.h:194
static void icplus_close(struct net_device *netdev)
Close network device.
Definition: icplus.c:495
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
unsigned short uint16_t
Definition: stdint.h:11
#define ICP_ASICCTRL_FIFO
FIFO.
Definition: icplus.h:32
wmb()
unsigned int word_len_log2
Word length.
Definition: nvs.h:22
struct mii_interface mdio
MII interface.
Definition: mii_bit.h:35
uint8_t readb(volatile uint8_t *io_addr)
Read byte from memory-mapped device.
#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
#define ICP_RX_ERR_ALIGN
Receive alignment error.
Definition: icplus.h:159
#define ADVERTISE_1000FULL
Definition: mii.h:131
A PCI driver.
Definition: pci.h:224
#define ICP_EEPROM_MAX_WAIT_MS
Maximum time to wait for reading EEPROM.
Definition: icplus.h:55
#define DBGLVL_IO
Definition: compiler.h:322
#define ICP_TX_UNALIGN
Transmit alignment disabled.
Definition: icplus.h:144
static void icplus_check_link(struct net_device *netdev)
Check link state.
Definition: icplus.c:286
struct nvs_device eeprom
EEPROM.
Definition: icplus.h:193
static int icplus_reset(struct icplus_nic *icp)
Reset hardware.
Definition: icplus.c:58
int(* open)(struct net_device *netdev)
Open network device.
Definition: netdevice.h:222
static void icplus_destroy_ring(struct icplus_nic *icp __unused, struct icplus_ring *ring)
Destroy descriptor ring.
Definition: icplus.c:384
uint8_t flags
Flags.
Definition: icplus.h:127
#define ICP_TFDLISTPTR
List pointer transmit register.
Definition: icplus.h:101
uint32_t next
Next descriptor address.
Definition: myson.h:18
struct icplus_ring tx
Transmit descriptor ring.
Definition: icplus.h:199
void init_mii_bit_basher(struct mii_bit_basher *miibit)
Initialise bit-bashing interface.
Definition: mii_bit.c:160
Error codes.
Bit-bashing operations.
Definition: bitbash.h:15
static struct bit_basher_operations icplus_basher_ops
MII bit-bashing interface.
Definition: icplus.c:231
unsigned int prod
Producer counter.
Definition: icplus.h:173
#define ICP_RX_MAX_LEN
Maximum receive packet length.
Definition: icplus.h:186
#define ICP_EEPROMCTRL_OPCODE_READ
Read register.
Definition: icplus.h:50
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:758
I/O buffers.
void free_iob(struct io_buffer *iobuf)
Free I/O buffer.
Definition: iobuf.c:145
A non-volatile storage device.
Definition: nvs.h:15
#define DBG_ENABLE(level)
Definition: compiler.h:313
struct pci_device_id * ids
PCI ID table.
Definition: pci.h:226
uint64_t address
Base address.
Definition: ena.h:24
#define ICP_RXMODE_ALLFRAMES
Receive all frames.
Definition: icplus.h:95
#define ICP_RESET_MAX_WAIT_MS
Maximum time to wait for reset.
Definition: icplus.h:39
Descriptor ring.
Definition: icplus.h:171
#define ICP_RFDLISTPTR
List pointer receive register.
Definition: icplus.h:98
static int icplus_write_eeprom(struct nvs_device *nvs, unsigned int address __unused, const void *data __unused, size_t len __unused)
Write data to EEPROM.
Definition: icplus.c:146
#define ICP_DMACTRL
DMA control register (word/double word)
Definition: icplus.h:42
uint32_t readl(volatile uint32_t *io_addr)
Read 32-bit dword from memory-mapped device.
#define ICP_RX_ERR_OVERSIZED
Receive oversized frame error.
Definition: icplus.h:165
static void icplus_set_base(struct icplus_nic *icp, unsigned int offset, void *base)
Set descriptor ring base address.
Definition: icplus.c:316
#define ICP_INTSTATUS
Interupt status register (word)
Definition: icplus.h:70
#define DBGC(...)
Definition: compiler.h:505
static void icplus_mii_write_bit(struct bit_basher *basher, unsigned int bit_id, unsigned long data)
Set/clear output bit.
Definition: icplus.c:214
static const uint8_t icplus_mii_bits[]
Pin mapping for MII bit-bashing interface.
Definition: icplus.c:180
#define ICP_RXMODE_MULTICAST
Receice multicast.
Definition: icplus.h:93
#define ICP_MACCTRL_TXENABLE
TX enable.
Definition: icplus.h:78
unsigned long long uint64_t
Definition: stdint.h:13
#define DBG_DISABLE(level)
Definition: compiler.h:312
#define cpu_to_le64(value)
Definition: byteswap.h:108
#define ICP_ASICCTRL_NETWORK
Network.
Definition: icplus.h:33
void netdev_link_down(struct net_device *netdev)
Mark network device as having link down.
Definition: netdevice.c:186
struct icplus_descriptor * entry
Ring entries.
Definition: icplus.h:177
static void icplus_init_eeprom(struct icplus_nic *icp)
Initialise EEPROM.
Definition: icplus.c:162
uint16_t len
Actual length.
Definition: icplus.h:125
#define ICP_DMACTRL_RXPOLLNOW
Receive poll now.
Definition: icplus.h:43
void adjust_pci_device(struct pci_device *pci)
Enable PCI device.
Definition: pci.c:149
struct bit_basher_operations * op
Bit-bashing operations.
Definition: bitbash.h:57
struct io_buffer * alloc_iob(size_t len)
Allocate I/O buffer.
Definition: iobuf.c:128
static __always_inline unsigned long virt_to_phys(volatile const void *addr)
Convert virtual address to a physical address.
Definition: uaccess.h:287
#define ICP_RXMODE
Receive mode register (word)
Definition: icplus.h:91
struct device dev
Generic device.
Definition: pci.h:189
static void icplus_poll_tx(struct net_device *netdev)
Poll for completed packets.
Definition: icplus.c:563
#define ICP_TX_INDICATE
Request transmit completion.
Definition: icplus.h:147
#define ICP_RX_ERR_RUNT
Receive runt frame error.
Definition: icplus.h:156
void writeb(uint8_t data, volatile uint8_t *io_addr)
Write byte to memory-mapped device.
uint8_t control
Control.
Definition: icplus.h:129
#define ENOTSUP
Operation not supported.
Definition: errno.h:589
MII clock.
Definition: mii_bit.h:43
uint64_t address
Address of data.
Definition: icplus.h:110
Dynamic memory allocation.
eeprom
Definition: 3c90x.h:232
#define ICP_BAR_SIZE
BAR size.
Definition: icplus.h:16
#define ICP_INTSTATUS_LINKEVENT
Link event.
Definition: icplus.h:72
static void netdev_init(struct net_device *netdev, struct net_device_operations *op)
Initialise a network device.
Definition: netdevice.h:498
#define ICP_MACCTRL_RXENABLE
RX enable.
Definition: icplus.h:80
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 ICP_EEPROMCTRL_BUSY
EEPROM busy.
Definition: icplus.h:52
#define ICP_ASICCTRL_HOST
Host.
Definition: icplus.h:34
static void icplus_poll_rx(struct net_device *netdev)
Poll for received packets.
Definition: icplus.c:591
static signed char phys[4]
Definition: epic100.c:88
#define ICP_RXMODE_UNICAST
Receive unicast.
Definition: icplus.h:92
static int icplus_transmit(struct net_device *netdev, struct io_buffer *iobuf)
Transmit packet.
Definition: icplus.c:523
static __always_inline unsigned long virt_to_bus(volatile const void *addr)
Convert virtual address to a bus address.
Definition: io.h:183
unsigned int block_size
Data block size (in words)
Definition: nvs.h:36
#define ICP_BASE_HI
Base address high register offset.
Definition: icplus.h:25
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:555
#define container_of(ptr, type, field)
Get containing structure.
Definition: stddef.h:35
Ethernet protocol.
#define ICP_MACCTRL_DUPLEX
Duplex select.
Definition: icplus.h:77
#define ICP_BASE_LO
Base address low register offset.
Definition: icplus.h:22
#define ICP_INTSTATUS_RXDMACOMPLETE
RX DMA complete.
Definition: icplus.h:73
void * priv
Driver private data.
Definition: netdevice.h:425
static int icplus_read_eeprom(struct nvs_device *nvs, unsigned int address, void *data, size_t len)
Read data from EEPROM.
Definition: icplus.c:100
static void netdev_link_up(struct net_device *netdev)
Mark network device as having link up.
Definition: netdevice.h:768
#define ICP_EEPROM_MIN_SIZE_WORDS
Minimum EEPROM size, in words.
Definition: icplus.h:61
void writel(uint32_t data, volatile uint32_t *io_addr)
Write 32-bit dword to memory-mapped device.
static userptr_t size_t offset
Offset of the first segment within the content.
Definition: deflate.h:259
static struct net_device * netdev
Definition: gdbudp.c:52
static void icplus_irq(struct net_device *netdev, int enable)
Enable or disable interrupts.
Definition: icplus.c:674
static void icplus_poll(struct net_device *netdev)
Poll for completed and received packets.
Definition: icplus.c:636
#define ICP_PHYCTRL_MGMTDIR
Management direction.
Definition: icplus.h:87
#define ICP_TXSTATUS
Transmit status register.
Definition: icplus.h:104
static int icplus_init_phy(struct icplus_nic *icp)
Configure PHY.
Definition: icplus.c:249
#define MII_CTRL1000
Definition: mii.h:24
void unregister_netdev(struct net_device *netdev)
Unregister network device.
Definition: netdevice.c:844
int(* read)(struct nvs_device *nvs, unsigned int address, void *data, size_t len)
Read data from device.
Definition: nvs.h:47
#define ICP_RXMODE_BROADCAST
Receive broadcast.
Definition: icplus.h:94
#define ICP_RX_ERR_FCS
Receive FCS error.
Definition: icplus.h:162
#define ICP_TX_SOLE_FRAG
Sole transmit fragment.
Definition: icplus.h:150
#define ICP_EEPROMCTRL
EEPROM control register (word)
Definition: icplus.h:47
#define DBGC2_HDA(...)
Definition: compiler.h:523
IC+ network driver.
int(* read)(struct bit_basher *basher, unsigned int bit_id)
Read input bit.
Definition: bitbash.h:51
unsigned int cons
Consumer counter.
Definition: icplus.h:175
A bit-bashing interface.
Definition: bitbash.h:55
Transmit or receive descriptor.
Definition: icplus.h:121
char * strerror(int errno)
Retrieve string representation of error number.
Definition: strerror.c:78
#define ICP_EEPROMDATA
EEPROM data register (word)
Definition: icplus.h:67
static unsigned int unsigned int reg
Definition: intel.h:245
PCI bus.
#define ICP_ASICCTRL
ASIC control register (double word)
Definition: icplus.h:28
A PCI device.
Definition: pci.h:187
int register_netdev(struct net_device *netdev)
Register network device.
Definition: netdevice.c:667
struct pci_driver icplus_driver __pci_driver
IC+ PCI driver.
Definition: icplus.c:804
static size_t iob_len(struct io_buffer *iobuf)
Calculate length of data in an I/O buffer.
Definition: iobuf.h:151
#define ICP_RX_ERR_OVERRUN
Recieve frame overrun error.
Definition: icplus.h:153
A network device.
Definition: netdevice.h:348
#define ENODEV
No such device.
Definition: errno.h:509
#define ICP_EEPROMCTRL_ADDRESS(x)
Address.
Definition: icplus.h:48
static void netdev_nullify(struct net_device *netdev)
Stop using a network device.
Definition: netdevice.h:511
uint16_t len
Length of data.
Definition: icplus.h:116
unsigned char uint8_t
Definition: stdint.h:10
static void icplus_remove(struct pci_device *pci)
Remove PCI device.
Definition: icplus.c:782
static int icplus_open(struct net_device *netdev)
Open network device.
Definition: icplus.c:449
static struct pci_device_id icplus_nics[]
IC+ PCI device IDs.
Definition: icplus.c:799
#define ICP_ASICCTRL_GLOBALRESET
Global reset.
Definition: icplus.h:30
int mii_reset(struct mii_device *mii)
Reset MII device.
Definition: mii.c:74
#define ETH_ALEN
Definition: if_ether.h:8
A PCI device ID list entry.
Definition: pci.h:151
#define le16_to_cpu(value)
Definition: byteswap.h:112
unsigned int uint32_t
Definition: stdint.h:12
void icplus_refill_rx(struct icplus_nic *icp)
Refill receive descriptor ring.
Definition: icplus.c:398
An IC+ network card.
Definition: icplus.h:189
unsigned int listptr
Definition: icplus.h:179
uint16_t base
Base address.
Definition: edd.h:14
static struct xen_remove_from_physmap * remove
Definition: xenmem.h:39
Network device operations.
Definition: netdevice.h:213
static int icplus_probe(struct pci_device *pci)
Probe PCI device.
Definition: icplus.c:703
void netdev_rx(struct net_device *netdev, struct io_buffer *iobuf)
Add packet to receive queue.
Definition: netdevice.c:470
struct device * dev
Underlying hardware device.
Definition: netdevice.h:360
static void mii_init(struct mii_device *mii, struct mii_interface *mdio, unsigned int address)
Initialise MII device.
Definition: mii.h:75
FILE_LICENCE(GPL2_OR_LATER_OR_UBDL)
Network device management.
unsigned long physaddr_t
Definition: stdint.h:20
#define __unused
Declare a variable or data structure as unused.
Definition: compiler.h:573
static void * pci_get_drvdata(struct pci_device *pci)
Get PCI driver-private data.
Definition: pci.h:348
struct mii_bit_basher miibit
MII bit bashing interface.
Definition: icplus.h:195
int mii_find(struct mii_device *mii)
Find PHY address.
Definition: mii.c:157
#define ICP_NUM_DESC
Number of descriptors.
Definition: icplus.h:183
void mdelay(unsigned long msecs)
Delay for a fixed number of milliseconds.
Definition: timer.c:78
#define ICP_DMACTRL_TXPOLLNOW
Transmit poll now.
Definition: icplus.h:44
struct mii_device mii
MII device.
Definition: icplus.h:197
uint32_t len
Length.
Definition: ena.h:14
#define ENOBUFS
No buffer space available.
Definition: errno.h:498
#define DBGC2(...)
Definition: compiler.h:522
static struct net_device_operations icplus_operations
IC+ network device operations.
Definition: icplus.c:682
int(* probe)(struct pci_device *pci)
Probe device.
Definition: pci.h:237
static int icplus_mii_read_bit(struct bit_basher *basher, unsigned int bit_id)
Read input bit.
Definition: icplus.c:194
struct io_buffer * rx_iobuf[ICP_NUM_DESC]
Receive I/O buffers.
Definition: icplus.h:203
#define ICP_ASICCTRL_RESETBUSY
Reset busy.
Definition: icplus.h:36
struct bit_basher basher
Bit-bashing interface.
Definition: mii_bit.h:37
#define writew
Definition: w89c840.c:159
void * data
Start of data.
Definition: iobuf.h:44
MII data direction.
Definition: mii_bit.h:47
#define EIO
Input/output error.
Definition: errno.h:433
#define ICP_ALIGN
Alignment requirement.
Definition: icplus.h:19
struct net_device * alloc_etherdev(size_t priv_size)
Allocate Ethernet device.
Definition: ethernet.c:264
#define ICP_PHYCTRL
PHY control register (byte)
Definition: icplus.h:84
#define ICP_PHYCTRL_MGMTDATA
Management data.
Definition: icplus.h:86
static void *__malloc malloc_dma(size_t size, size_t phys_align)
Allocate memory for DMA.
Definition: malloc.h:66
uint64_t next
Address of next descriptor.
Definition: icplus.h:123
#define cpu_to_le16(value)
Definition: byteswap.h:106
void iounmap(volatile const void *io_addr)
Unmap I/O address.
struct icplus_ring rx
Receive descriptor ring.
Definition: icplus.h:201
union icplus_fragment data
Data buffer.
Definition: icplus.h:135
int nvs_read(struct nvs_device *nvs, unsigned int address, void *data, size_t len)
Read from non-volatile storage device.
Definition: nvs.c:75
#define ICP_RX_ERR_LEN
Recieve length error.
Definition: icplus.h:168
MII data.
Definition: mii_bit.h:45
#define ICP_DONE
Descriptor complete.
Definition: icplus.h:141
struct arbelprm_port_state_change_st data
Message.
Definition: arbel.h:12
void * ioremap(unsigned long bus_addr, size_t len)
Map bus address as an I/O address.
static void free_dma(void *ptr, size_t size)
Free memory allocated with malloc_dma()
Definition: malloc.h:81
static int icplus_create_ring(struct icplus_nic *icp, struct icplus_ring *ring)
Create descriptor ring.
Definition: icplus.c:338
static int mii_write(struct mii_device *mii, unsigned int reg, unsigned int data)
Write to MII register.
Definition: mii.h:104
#define ICP_INTSTATUS_TXCOMPLETE
TX complete.
Definition: icplus.h:71
#define ICP_PHYCTRL_LINKSPEED
Link speed.
Definition: icplus.h:88
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
String functions.
#define PCI_ROM(_vendor, _device, _name, _description, _data)
Definition: pci.h:283
unsigned int size
Device size (in words)
Definition: nvs.h:24
#define ICP_ASICCTRL_DMA
DMA.
Definition: icplus.h:31
#define ICP_PHYCTRL_MGMTCLK
Management clock.
Definition: icplus.h:85
void * memset(void *dest, int character, size_t len) __nonnull
A persistent I/O buffer.
Definition: iobuf.h:32
void * regs
Registers.
Definition: icplus.h:191