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
24FILE_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 */
58static int icplus_reset ( struct icplus_nic *icp ) {
59 uint32_t asicctrl;
60 unsigned int i;
61
62 /* Trigger reset */
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 */
100static 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 */
146static 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 */
162static 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 */
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 */
194static 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 );
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 */
214static 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 */
228}
229
230/** MII bit-bashing interface */
232 .read = icplus_mii_read_bit,
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 */
249static 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 */
286static 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 */
316static 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 */
338static 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_phys ( 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_phys ( 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 */
384static 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_phys ( ring->entry, len );
390 ring->entry = NULL;
391}
392
393/**
394 * Refill receive descriptor ring
395 *
396 * @v icp IC+ device
397 */
398void 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 */
449static 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 */
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 */
495static 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 */
523static 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 */
563static 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 */
591static 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 */
636static 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 */
674static 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 */
703static 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 );
724
725 /* Fix up PCI device */
726 adjust_pci_device ( pci );
727
728 /* Map registers */
729 icp->regs = pci_ioremap ( pci, 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 */
782static 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 */
799static struct pci_device_id icplus_nics[] = {
800 PCI_ROM ( 0x13f0, 0x1023, "ip1000a", "IP1000A", 0 ),
801};
802
803/** IC+ PCI driver */
804struct pci_driver icplus_driver __pci_driver = {
805 .ids = icplus_nics,
806 .id_count = ( sizeof ( icplus_nics ) / sizeof ( icplus_nics[0] ) ),
809};
eeprom
Definition 3c90x.h:232
#define NULL
NULL pointer (VOID *)
Definition Base.h:322
struct arbelprm_rc_send_wqe rc
Definition arbel.h:3
unsigned short uint16_t
Definition stdint.h:11
unsigned int uint32_t
Definition stdint.h:12
unsigned long physaddr_t
Definition stdint.h:20
unsigned long long uint64_t
Definition stdint.h:13
unsigned char uint8_t
Definition stdint.h:10
#define assert(condition)
Assert a condition at run-time.
Definition assert.h:50
uint16_t offset
Offset to command line.
Definition bzimage.h:3
uint32_t next
Next descriptor address.
Definition dwmac.h:11
ring len
Length.
Definition dwmac.h:226
uint8_t data[48]
Additional event data.
Definition ena.h:11
uint64_t address
Base address.
Definition ena.h:13
struct ena_llq_option desc
Descriptor counts.
Definition ena.h:9
static signed char phys[4]
Definition epic100.c:88
Error codes.
struct net_device * alloc_etherdev(size_t priv_size)
Allocate Ethernet device.
Definition ethernet.c:265
Ethernet protocol.
static struct net_device * netdev
Definition gdbudp.c:53
#define __unused
Declare a variable or data structure as unused.
Definition compiler.h:573
#define DBGC2(...)
Definition compiler.h:522
#define DBGLVL_IO
Definition compiler.h:322
#define DBG_DISABLE(level)
Definition compiler.h:312
#define DBGC2_HDA(...)
Definition compiler.h:523
#define DBG_ENABLE(level)
Definition compiler.h:313
#define DBGC(...)
Definition compiler.h:505
#define FILE_LICENCE(_licence)
Declare a particular licence as applying to a file.
Definition compiler.h:896
#define ETIMEDOUT
Connection timed out.
Definition errno.h:670
#define ENOMEM
Not enough space.
Definition errno.h:535
#define EIO
Input/output error.
Definition errno.h:434
#define ENOTSUP
Operation not supported.
Definition errno.h:590
#define ENOBUFS
No buffer space available.
Definition errno.h:499
#define ENODEV
No such device.
Definition errno.h:510
static struct bit_basher_operations icplus_basher_ops
MII bit-bashing interface.
Definition icplus.c:231
static void icplus_remove(struct pci_device *pci)
Remove PCI device.
Definition icplus.c:782
static int icplus_create_ring(struct icplus_nic *icp, struct icplus_ring *ring)
Create descriptor ring.
Definition icplus.c:338
static int icplus_probe(struct pci_device *pci)
Probe PCI device.
Definition icplus.c:703
static const uint8_t icplus_mii_bits[]
Pin mapping for MII bit-bashing interface.
Definition icplus.c:180
static void icplus_set_base(struct icplus_nic *icp, unsigned int offset, void *base)
Set descriptor ring base address.
Definition icplus.c:316
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 int icplus_open(struct net_device *netdev)
Open network device.
Definition icplus.c:449
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
static void icplus_init_eeprom(struct icplus_nic *icp)
Initialise EEPROM.
Definition icplus.c:162
void icplus_refill_rx(struct icplus_nic *icp)
Refill receive descriptor ring.
Definition icplus.c:398
static void icplus_poll_rx(struct net_device *netdev)
Poll for received packets.
Definition icplus.c:591
static int icplus_init_phy(struct icplus_nic *icp)
Configure PHY.
Definition icplus.c:249
static int icplus_reset(struct icplus_nic *icp)
Reset hardware.
Definition icplus.c:58
static void icplus_destroy_ring(struct icplus_nic *icp __unused, struct icplus_ring *ring)
Destroy descriptor ring.
Definition icplus.c:384
static int icplus_transmit(struct net_device *netdev, struct io_buffer *iobuf)
Transmit packet.
Definition icplus.c:523
static void icplus_poll(struct net_device *netdev)
Poll for completed and received packets.
Definition icplus.c:636
static void icplus_close(struct net_device *netdev)
Close network device.
Definition icplus.c:495
static struct net_device_operations icplus_operations
IC+ network device operations.
Definition icplus.c:682
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 struct pci_device_id icplus_nics[]
IC+ PCI device IDs.
Definition icplus.c:799
static void icplus_check_link(struct net_device *netdev)
Check link state.
Definition icplus.c:286
static int icplus_mii_read_bit(struct bit_basher *basher, unsigned int bit_id)
Read input bit.
Definition icplus.c:194
static void icplus_poll_tx(struct net_device *netdev)
Poll for completed packets.
Definition icplus.c:563
static void icplus_irq(struct net_device *netdev, int enable)
Enable or disable interrupts.
Definition icplus.c:674
IC+ network driver.
#define ICP_DMACTRL_TXPOLLNOW
Transmit poll now.
Definition icplus.h:44
#define ICP_INTSTATUS_LINKEVENT
Link event.
Definition icplus.h:72
#define ICP_RXMODE
Receive mode register (word)
Definition icplus.h:91
#define ICP_RFDLISTPTR
List pointer receive register.
Definition icplus.h:98
#define ICP_ASICCTRL_FIFO
FIFO.
Definition icplus.h:32
#define ICP_EEPROM_MAC
Address of MAC address within EEPROM.
Definition icplus.h:64
#define ICP_RX_ERR_OVERRUN
Recieve frame overrun error.
Definition icplus.h:153
#define ICP_PHYCTRL_LINKSPEED
Link speed.
Definition icplus.h:88
#define ICP_RXMODE_BROADCAST
Receive broadcast.
Definition icplus.h:94
#define ICP_TXSTATUS
Transmit status register.
Definition icplus.h:104
#define ICP_EEPROMCTRL_OPCODE_READ
Read register.
Definition icplus.h:50
#define ICP_EEPROM_MAX_WAIT_MS
Maximum time to wait for reading EEPROM.
Definition icplus.h:55
#define ICP_EEPROM_MIN_SIZE_WORDS
Minimum EEPROM size, in words.
Definition icplus.h:61
#define ICP_MACCTRL_TXENABLE
TX enable.
Definition icplus.h:78
#define ICP_MACCTRL
MAC control register (double word)
Definition icplus.h:76
#define ICP_PHYCTRL
PHY control register (byte)
Definition icplus.h:84
#define ICP_ASICCTRL_DMA
DMA.
Definition icplus.h:31
#define ICP_ASICCTRL_RESETBUSY
Reset busy.
Definition icplus.h:36
#define ICP_RX_ERR_FCS
Receive FCS error.
Definition icplus.h:162
#define ICP_EEPROMCTRL_ADDRESS(x)
Address.
Definition icplus.h:48
#define ICP_EEPROM_WORD_LEN_LOG2
EEPROM word length.
Definition icplus.h:58
#define ICP_BASE_HI
Base address high register offset.
Definition icplus.h:25
#define ICP_BASE_LO
Base address low register offset.
Definition icplus.h:22
#define ICP_RX_MAX_LEN
Maximum receive packet length.
Definition icplus.h:186
#define ICP_MACCTRL_RXENABLE
RX enable.
Definition icplus.h:80
#define ICP_RXMODE_MULTICAST
Receice multicast.
Definition icplus.h:93
#define ICP_PHYCTRL_MGMTDIR
Management direction.
Definition icplus.h:87
#define ICP_ASICCTRL_PHYSPEED1000
PHY speed 1000.
Definition icplus.h:29
#define ICP_DMACTRL
DMA control register (word/double word)
Definition icplus.h:42
#define ICP_INTSTATUS
Interupt status register (word)
Definition icplus.h:70
#define ICP_TFDLISTPTR
List pointer transmit register.
Definition icplus.h:101
#define ICP_BAR_SIZE
BAR size.
Definition icplus.h:16
#define ICP_INTSTATUS_TXCOMPLETE
TX complete.
Definition icplus.h:71
#define ICP_PHYCTRL_MGMTCLK
Management clock.
Definition icplus.h:85
#define ICP_TX_INDICATE
Request transmit completion.
Definition icplus.h:147
#define ICP_INTSTATUS_RXDMACOMPLETE
RX DMA complete.
Definition icplus.h:73
#define ICP_RESET_MAX_WAIT_MS
Maximum time to wait for reset.
Definition icplus.h:39
#define ICP_RXMODE_UNICAST
Receive unicast.
Definition icplus.h:92
#define ICP_ASICCTRL_AUTOINIT
Auto init.
Definition icplus.h:35
#define ICP_DONE
Descriptor complete.
Definition icplus.h:141
#define ICP_EEPROMCTRL
EEPROM control register (word)
Definition icplus.h:47
#define ICP_TX_UNALIGN
Transmit alignment disabled.
Definition icplus.h:144
#define ICP_ASICCTRL_GLOBALRESET
Global reset.
Definition icplus.h:30
#define ICP_ASICCTRL_NETWORK
Network.
Definition icplus.h:33
#define ICP_RXMODE_ALLFRAMES
Receive all frames.
Definition icplus.h:95
#define ICP_RX_ERR_OVERSIZED
Receive oversized frame error.
Definition icplus.h:165
#define ICP_DMACTRL_RXPOLLNOW
Receive poll now.
Definition icplus.h:43
#define ICP_RX_ERR_RUNT
Receive runt frame error.
Definition icplus.h:156
#define ICP_MACCTRL_DUPLEX
Duplex select.
Definition icplus.h:77
#define ICP_TXSTATUS_ERROR
TX error.
Definition icplus.h:105
#define ICP_EEPROMDATA
EEPROM data register (word)
Definition icplus.h:67
#define ICP_ASICCTRL_HOST
Host.
Definition icplus.h:34
#define ICP_RX_ERR_LEN
Recieve length error.
Definition icplus.h:168
#define ICP_ALIGN
Alignment requirement.
Definition icplus.h:19
#define ICP_EEPROMCTRL_BUSY
EEPROM busy.
Definition icplus.h:52
#define ICP_ASICCTRL
ASIC control register (double word)
Definition icplus.h:28
#define ICP_RX_ERR_ALIGN
Receive alignment error.
Definition icplus.h:159
#define ICP_NUM_DESC
Number of descriptors.
Definition icplus.h:183
#define ICP_PHYCTRL_MGMTDATA
Management data.
Definition icplus.h:86
#define ICP_TX_SOLE_FRAG
Sole transmit fragment.
Definition icplus.h:150
#define ETH_ALEN
Definition if_ether.h:9
#define cpu_to_le64(value)
Definition byteswap.h:109
#define le16_to_cpu(value)
Definition byteswap.h:113
#define cpu_to_le16(value)
Definition byteswap.h:107
#define wmb()
Definition io.h:546
static __always_inline unsigned long virt_to_bus(volatile const void *addr)
Convert virtual address to a bus address.
Definition io.h:184
void iounmap(volatile const void *io_addr)
Unmap I/O address.
void * pci_ioremap(struct pci_device *pci, unsigned long bus_addr, size_t len)
Map PCI bus address as an I/O address.
String functions.
void * memset(void *dest, int character, size_t len) __nonnull
void free_iob(struct io_buffer *iobuf)
Free I/O buffer.
Definition iobuf.c:153
struct io_buffer * alloc_iob(size_t len)
Allocate I/O buffer.
Definition iobuf.c:131
I/O buffers.
#define iob_put(iobuf, len)
Definition iobuf.h:125
static size_t iob_len(struct io_buffer *iobuf)
Calculate length of data in an I/O buffer.
Definition iobuf.h:160
static int mii_write(struct mii_device *mii, unsigned int reg, unsigned int data)
Write to MII register.
Definition mii.h:105
static void mii_init(struct mii_device *mii, struct mii_interface *mdio, unsigned int address)
Initialise MII device.
Definition mii.h:76
uint32_t base
Base.
Definition librm.h:3
void * malloc_phys(size_t size, size_t phys_align)
Allocate memory with specified physical alignment.
Definition malloc.c:707
void free_phys(void *ptr, size_t size)
Free memory allocated with malloc_phys()
Definition malloc.c:723
Dynamic memory allocation.
int mii_reset(struct mii_device *mii)
Reset MII device.
Definition mii.c:75
int mii_find(struct mii_device *mii)
Find PHY address.
Definition mii.c:158
#define MII_CTRL1000
Definition mii.h:25
#define ADVERTISE_1000FULL
Definition mii.h:134
void init_mii_bit_basher(struct mii_bit_basher *miibit)
Initialise bit-bashing interface.
Definition mii_bit.c:160
@ MII_BIT_MDC
MII clock.
Definition mii_bit.h:43
@ MII_BIT_MDIO
MII data.
Definition mii_bit.h:45
@ MII_BIT_DRIVE
MII data direction.
Definition mii_bit.h:47
static unsigned int unsigned int reg
Definition myson.h:162
void netdev_link_down(struct net_device *netdev)
Mark network device as having link down.
Definition netdevice.c:231
void netdev_rx(struct net_device *netdev, struct io_buffer *iobuf)
Add packet to receive queue.
Definition netdevice.c:549
void unregister_netdev(struct net_device *netdev)
Unregister network device.
Definition netdevice.c:942
void netdev_rx_err(struct net_device *netdev, struct io_buffer *iobuf, int rc)
Discard received packet.
Definition netdevice.c:587
int register_netdev(struct net_device *netdev)
Register network device.
Definition netdevice.c:760
Network device management.
static void netdev_link_up(struct net_device *netdev)
Mark network device as having link up.
Definition netdevice.h:789
static void netdev_init(struct net_device *netdev, struct net_device_operations *op)
Initialise a network device.
Definition netdevice.h:519
static void netdev_nullify(struct net_device *netdev)
Stop using a network device.
Definition netdevice.h:532
static void netdev_put(struct net_device *netdev)
Drop reference to network device.
Definition netdevice.h:576
static void netdev_tx_complete_next(struct net_device *netdev)
Complete network transmission.
Definition netdevice.h:779
int nvs_read(struct nvs_device *nvs, unsigned int address, void *data, size_t len)
Read from non-volatile storage device.
Definition nvs.c:76
void adjust_pci_device(struct pci_device *pci)
Enable PCI device.
Definition pci.c:241
PCI bus.
#define __pci_driver
Declare a PCI driver.
Definition pci.h:278
static void pci_set_drvdata(struct pci_device *pci, void *priv)
Set PCI driver-private data.
Definition pci.h:366
#define PCI_ROM(_vendor, _device, _name, _description, _data)
Definition pci.h:308
static void * pci_get_drvdata(struct pci_device *pci)
Get PCI driver-private data.
Definition pci.h:376
#define container_of(ptr, type, field)
Get containing structure.
Definition stddef.h:36
char * strerror(int errno)
Retrieve string representation of error number.
Definition strerror.c:79
Bit-bashing operations.
Definition bitbash.h:16
A bit-bashing interface.
Definition bitbash.h:56
struct bit_basher_operations * op
Bit-bashing operations.
Definition bitbash.h:58
Transmit or receive descriptor.
Definition icplus.h:121
An IC+ network card.
Definition icplus.h:189
void * regs
Registers.
Definition icplus.h:191
struct icplus_ring tx
Transmit descriptor ring.
Definition icplus.h:199
struct icplus_ring rx
Receive descriptor ring.
Definition icplus.h:201
struct mii_bit_basher miibit
MII bit bashing interface.
Definition icplus.h:195
struct io_buffer * rx_iobuf[ICP_NUM_DESC]
Receive I/O buffers.
Definition icplus.h:203
struct mii_device mii
MII device.
Definition icplus.h:197
struct nvs_device eeprom
EEPROM.
Definition icplus.h:193
Descriptor ring.
Definition icplus.h:171
struct icplus_descriptor * entry
Ring entries.
Definition icplus.h:177
unsigned int cons
Consumer counter.
Definition icplus.h:175
unsigned int listptr
Definition icplus.h:179
unsigned int prod
Producer counter.
Definition icplus.h:173
A persistent I/O buffer.
Definition iobuf.h:38
void * data
Start of data.
Definition iobuf.h:53
struct bit_basher basher
Bit-bashing interface.
Definition mii_bit.h:37
struct mii_interface mdio
MII interface.
Definition mii_bit.h:35
Network device operations.
Definition netdevice.h:214
A network device.
Definition netdevice.h:353
A non-volatile storage device.
Definition nvs.h:16
unsigned int block_size
Data block size (in words)
Definition nvs.h:37
unsigned int word_len_log2
Word length.
Definition nvs.h:23
int(* read)(struct nvs_device *nvs, unsigned int address, void *data, size_t len)
Read data from device.
Definition nvs.h:48
unsigned int size
Device size (in words)
Definition nvs.h:25
int(* write)(struct nvs_device *nvs, unsigned int address, const void *data, size_t len)
Write data to device.
Definition nvs.h:60
A PCI device ID list entry.
Definition pci.h:175
A PCI device.
Definition pci.h:211
unsigned long membase
Memory base.
Definition pci.h:220
struct device dev
Generic device.
Definition pci.h:213
A PCI driver.
Definition pci.h:252
int(* probe)(struct pci_device *pci)
Probe device.
Definition pci.h:265
void mdelay(unsigned long msecs)
Delay for a fixed number of milliseconds.
Definition timer.c:79
#define readl
Definition w89c840.c:157
#define writel
Definition w89c840.c:160
#define writew
Definition w89c840.c:159
#define readb
Definition w89c840.c:155
#define writeb
Definition w89c840.c:158
#define readw
Definition w89c840.c:156
static struct xen_remove_from_physmap * remove
Definition xenmem.h:40