iPXE
exanic.c
Go to the documentation of this file.
1/*
2 * Copyright (C) 2017 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
24FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
25
26#include <stdint.h>
27#include <string.h>
28#include <strings.h>
29#include <unistd.h>
30#include <errno.h>
31#include <byteswap.h>
32#include <ipxe/netdevice.h>
33#include <ipxe/ethernet.h>
34#include <ipxe/if_ether.h>
35#include <ipxe/iobuf.h>
36#include <ipxe/malloc.h>
37#include <ipxe/umalloc.h>
38#include <ipxe/pci.h>
39#include "exanic.h"
40
41/** @file
42 *
43 * Exablaze ExaNIC driver
44 *
45 */
46
47/* Disambiguate the various error causes */
48#define EIO_ABORTED __einfo_error ( EINFO_EIO_ABORTED )
49#define EINFO_EIO_ABORTED \
50 __einfo_uniqify ( EINFO_EIO, 0x01, "Frame aborted" )
51#define EIO_CORRUPT __einfo_error ( EINFO_EIO_CORRUPT )
52#define EINFO_EIO_CORRUPT \
53 __einfo_uniqify ( EINFO_EIO, 0x02, "CRC incorrect" )
54#define EIO_HWOVFL __einfo_error ( EINFO_EIO_HWOVFL )
55#define EINFO_EIO_HWOVFL \
56 __einfo_uniqify ( EINFO_EIO, 0x03, "Hardware overflow" )
57#define EIO_STATUS( status ) \
58 EUNIQ ( EINFO_EIO, ( (status) & EXANIC_STATUS_ERROR_MASK ), \
59 EIO_ABORTED, EIO_CORRUPT, EIO_HWOVFL )
60
61/**
62 * Write DMA base address register
63 *
64 * @v addr DMA base address
65 * @v reg Register
66 */
67static void exanic_write_base ( physaddr_t addr, void *reg ) {
68 uint32_t lo;
69 uint32_t hi;
70
71 /* Write high and low registers, setting flags as appropriate */
72 lo = addr;
73 if ( sizeof ( physaddr_t ) > sizeof ( uint32_t ) ) {
74 /* 64-bit build; may be a 32-bit or 64-bit address */
75 hi = ( ( ( uint64_t ) addr ) >> 32 );
76 if ( ! hi )
78 } else {
79 /* 32-bit build; always a 32-bit address */
80 hi = 0;
82 }
83 writel ( hi, ( reg + 0 ) );
84 writel ( lo, ( reg + 4 ) );
85}
86
87/**
88 * Clear DMA base address register
89 *
90 * @v reg Register
91 */
92static inline void exanic_clear_base ( void *reg ) {
93
94 /* Clear both high and low registers */
95 writel ( 0, ( reg + 0 ) );
96 writel ( 0, ( reg + 4 ) );
97}
98
99/******************************************************************************
100 *
101 * Device reset
102 *
103 ******************************************************************************
104 */
105
106/**
107 * Reset hardware
108 *
109 * @v exanic ExaNIC device
110 */
111static void exanic_reset ( struct exanic *exanic ) {
112 void *port_regs;
113 unsigned int i;
114
115 /* Disable all possible ports */
116 for ( i = 0 ; i < EXANIC_MAX_PORTS ; i++ ) {
117 port_regs = ( exanic->regs + EXANIC_PORT_REGS ( i ) );
118 writel ( 0, ( port_regs + EXANIC_PORT_ENABLE ) );
119 writel ( 0, ( port_regs + EXANIC_PORT_IRQ ) );
121 }
122
123 /* Disable transmit feedback */
125}
126
127/******************************************************************************
128 *
129 * MAC address
130 *
131 ******************************************************************************
132 */
133
134/**
135 * Read I2C line status
136 *
137 * @v basher Bit-bashing interface
138 * @v bit_id Bit number
139 * @ret zero Input is a logic 0
140 * @ret non-zero Input is a logic 1
141 */
142static int exanic_i2c_read_bit ( struct bit_basher *basher,
143 unsigned int bit_id ) {
144 struct exanic *exanic =
146 unsigned int shift;
147 uint32_t i2c;
148
149 /* Identify bit */
150 assert ( bit_id == I2C_BIT_SDA );
151 shift = exanic->i2cfg.getsda;
152
153 /* Read I2C register */
155 i2c = readl ( exanic->regs + EXANIC_I2C );
157 return ( ( i2c >> shift ) & 1 );
158}
159
160/**
161 * Write I2C line status
162 *
163 * @v basher Bit-bashing interface
164 * @v bit_id Bit number
165 * @v data Value to write
166 */
168 unsigned int bit_id, unsigned long data ) {
169 struct exanic *exanic =
171 unsigned int shift;
172 uint32_t mask;
173 uint32_t i2c;
174
175 /* Identify shift */
176 assert ( ( bit_id == I2C_BIT_SCL ) || ( bit_id == I2C_BIT_SDA ) );
177 shift = ( ( bit_id == I2C_BIT_SCL ) ?
179 mask = ( 1UL << shift );
180
181 /* Modify I2C register */
183 i2c = readl ( exanic->regs + EXANIC_I2C );
184 i2c &= ~mask;
185 if ( ! data )
186 i2c |= mask;
187 writel ( i2c, ( exanic->regs + EXANIC_I2C ) );
189}
190
191/** I2C bit-bashing interface operations */
196
197/** Possible I2C bus configurations */
199 /* X2/X10 */
200 { .setscl = 7, .setsda = 4, .getsda = 12 },
201 /* X4 */
202 { .setscl = 7, .setsda = 5, .getsda = 13 },
203};
204
205/**
206 * Initialise EEPROM
207 *
208 * @v exanic ExaNIC device
209 * @v i2cfg I2C bus configuration
210 * @ret rc Return status code
211 */
213 struct exanic_i2c_config *i2cfg ) {
214 int rc;
215
216 /* Configure I2C bus */
217 memcpy ( &exanic->i2cfg, i2cfg, sizeof ( exanic->i2cfg ) );
218
219 /* Initialise I2C bus */
220 if ( ( rc = init_i2c_bit_basher ( &exanic->basher,
221 &exanic_i2c_basher_ops ) ) != 0 ) {
222 DBGC2 ( exanic, "EXANIC %p found no I2C bus via %d/%d/%d\n",
225 return rc;
226 }
227
228 /* Check for EEPROM presence */
231 &exanic->eeprom ) ) != 0 ) {
232 DBGC2 ( exanic, "EXANIC %p found no EEPROM via %d/%d/%d\n",
235 return rc;
236 }
237
238 DBGC ( exanic, "EXANIC %p found EEPROM via %d/%d/%d\n",
241 return 0;
242}
243
244/**
245 * Initialise EEPROM
246 *
247 * @v exanic ExaNIC device
248 * @ret rc Return status code
249 */
250static int exanic_init_eeprom ( struct exanic *exanic ) {
251 struct exanic_i2c_config *i2cfg;
252 unsigned int i;
253 int rc;
254
255 /* Try all possible bus configurations */
256 for ( i = 0 ; i < ( sizeof ( exanic_i2cfgs ) /
257 sizeof ( exanic_i2cfgs[0] ) ) ; i++ ) {
258 i2cfg = &exanic_i2cfgs[i];
259 if ( ( rc = exanic_try_init_eeprom ( exanic, i2cfg ) ) == 0 )
260 return 0;
261 }
262
263 DBGC ( exanic, "EXANIC %p found no EEPROM\n", exanic );
264 return -ENODEV;
265}
266
267/**
268 * Fetch base MAC address
269 *
270 * @v exanic ExaNIC device
271 * @ret rc Return status code
272 */
273static int exanic_fetch_mac ( struct exanic *exanic ) {
274 struct i2c_interface *i2c = &exanic->basher.i2c;
275 int rc;
276
277 /* Initialise EEPROM */
278 if ( ( rc = exanic_init_eeprom ( exanic ) ) != 0 )
279 return rc;
280
281 /* Fetch base MAC address */
282 if ( ( rc = i2c->read ( i2c, &exanic->eeprom, 0, exanic->mac,
283 sizeof ( exanic->mac ) ) ) != 0 ) {
284 DBGC ( exanic, "EXANIC %p could not read MAC address: %s\n",
285 exanic, strerror ( rc ) );
286 return rc;
287 }
288
289 return 0;
290}
291
292/******************************************************************************
293 *
294 * Link state
295 *
296 ******************************************************************************
297 */
298
299/**
300 * Check link state
301 *
302 * @v netdev Network device
303 */
304static void exanic_check_link ( struct net_device *netdev ) {
305 struct exanic_port *port = netdev->priv;
308
309 /* Report port status changes */
310 status = readl ( port->regs + EXANIC_PORT_STATUS );
311 speed = readl ( port->regs + EXANIC_PORT_SPEED );
312 if ( status != port->status ) {
313 DBGC ( port, "EXANIC %s port status %#08x speed %dMbps\n",
314 netdev->name, status, speed );
317 } else {
319 }
320 port->status = status;
321 }
322}
323
324/**
325 * Check link state periodically
326 *
327 * @v retry Link state check timer
328 * @v over Failure indicator
329 */
330static void exanic_expired ( struct retry_timer *timer, int over __unused ) {
331 struct exanic_port *port =
332 container_of ( timer, struct exanic_port, timer );
333 struct net_device *netdev = port->netdev;
334 static const uint32_t speeds[] = {
335 100, 1000, 10000, 40000, 100000,
336 };
337 unsigned int index;
338
339 /* Restart timer */
341
342 /* Check link state */
344
345 /* Do nothing further if link is already up */
346 if ( netdev_link_ok ( netdev ) )
347 return;
348
349 /* Do nothing further unless we have a valid list of supported speeds */
350 if ( ! port->speeds )
351 return;
352
353 /* Autonegotiation is not supported; try manually selecting
354 * the next supported link speed.
355 */
356 do {
357 if ( ! port->speed )
358 port->speed = ( 8 * sizeof ( port->speeds ) );
359 port->speed--;
360 } while ( ! ( ( 1UL << port->speed ) & port->speeds ) );
361 index = ( port->speed - ( ffs ( EXANIC_CAPS_SPEED_MASK ) - 1 ) );
362 assert ( index < ( sizeof ( speeds ) / sizeof ( speeds[0] ) ) );
363
364 /* Attempt the selected speed */
365 DBGC ( netdev, "EXANIC %s attempting %dMbps\n",
366 netdev->name, speeds[index] );
367 writel ( speeds[index], ( port->regs + EXANIC_PORT_SPEED ) );
368}
369
370/******************************************************************************
371 *
372 * Network device interface
373 *
374 ******************************************************************************
375 */
376
377/**
378 * Open network device
379 *
380 * @v netdev Network device
381 * @ret rc Return status code
382 */
383static int exanic_open ( struct net_device *netdev ) {
384 struct exanic_port *port = netdev->priv;
385 struct exanic_tx_chunk *tx;
386 unsigned int i;
387
388 /* Reset transmit region contents */
389 for ( i = 0 ; i < port->tx_count ; i++ ) {
390 tx = ( port->tx + ( i * sizeof ( *tx ) ) );
391 writew ( port->txf_slot, &tx->desc.txf_slot );
392 writeb ( EXANIC_TYPE_RAW, &tx->desc.type );
393 writeb ( 0, &tx->desc.flags );
394 writew ( 0, &tx->pad );
395 }
396
397 /* Reset receive region contents */
398 memset ( port->rx, 0xff, EXANIC_RX_LEN );
399
400 /* Reset transmit feedback region */
401 *(port->txf) = 0;
402
403 /* Reset counters */
404 port->tx_prod = 0;
405 port->tx_cons = 0;
406 port->rx_cons = 0;
407
408 /* Map receive region */
409 exanic_write_base ( phys_to_bus ( virt_to_phys ( port->rx ) ),
410 ( port->regs + EXANIC_PORT_RX_BASE ) );
411
412 /* Enable promiscuous mode */
414 ( port->regs + EXANIC_PORT_FLAGS ) );
415
416 /* Reset to default speed and clear cached status */
417 writel ( port->default_speed, ( port->regs + EXANIC_PORT_SPEED ) );
418 port->speed = 0;
419 port->status = 0;
420
421 /* Enable port */
422 wmb();
424 ( port->regs + EXANIC_PORT_ENABLE ) );
425
426 /* Start link state timer */
428
429 return 0;
430}
431
432/**
433 * Close network device
434 *
435 * @v netdev Network device
436 */
437static void exanic_close ( struct net_device *netdev ) {
438 struct exanic_port *port = netdev->priv;
439
440 /* Stop link state timer */
441 stop_timer ( &port->timer );
442
443 /* Disable port */
444 writel ( 0, ( port->regs + EXANIC_PORT_ENABLE ) );
445 wmb();
446
447 /* Clear receive region */
449
450 /* Discard any in-progress receive */
451 if ( port->rx_iobuf ) {
452 netdev_rx_err ( netdev, port->rx_iobuf, -ECANCELED );
453 port->rx_iobuf = NULL;
454 }
455}
456
457/**
458 * Transmit packet
459 *
460 * @v netdev Network device
461 * @v iobuf I/O buffer
462 * @ret rc Return status code
463 */
464static int exanic_transmit ( struct net_device *netdev,
465 struct io_buffer *iobuf ) {
466 struct exanic_port *port = netdev->priv;
467 struct exanic_tx_chunk *tx;
468 unsigned int tx_fill;
469 unsigned int tx_index;
470 size_t offset;
471 size_t len;
472 uint8_t *src;
473 uint8_t *dst;
474
475 /* Sanity check */
476 len = iob_len ( iobuf );
477 if ( len > sizeof ( tx->data ) ) {
478 DBGC ( port, "EXANIC %s transmit too large\n", netdev->name );
479 return -ENOTSUP;
480 }
481
482 /* Get next transmit descriptor */
483 tx_fill = ( port->tx_prod - port->tx_cons );
484 if ( tx_fill >= port->tx_count ) {
485 DBGC ( port, "EXANIC %s out of transmit descriptors\n",
486 netdev->name );
487 return -ENOBUFS;
488 }
489 tx_index = ( port->tx_prod & ( port->tx_count - 1 ) );
490 offset = ( tx_index * sizeof ( *tx ) );
491 tx = ( port->tx + offset );
492 DBGC2 ( port, "EXANIC %s TX %04x at [%05zx,%05zx)\n",
493 netdev->name, port->tx_prod, ( port->tx_offset + offset ),
494 ( port->tx_offset + offset +
495 offsetof ( typeof ( *tx ), data ) + len ) );
496 port->tx_prod++;
497
498 /* Populate transmit descriptor */
499 writew ( port->tx_prod, &tx->desc.txf_id );
500 writew ( ( sizeof ( tx->pad ) + len ), &tx->desc.len );
501
502 /* Copy data to transmit region. There is no DMA on the
503 * transmit data path.
504 */
505 src = iobuf->data;
506 dst = tx->data;
507 while ( len-- )
508 writeb ( *(src++), dst++ );
509
510 /* Send transmit command */
511 wmb();
512 writel ( ( port->tx_offset + offset ),
513 ( port->regs + EXANIC_PORT_TX_COMMAND ) );
514
515 return 0;
516}
517
518/**
519 * Poll for completed packets
520 *
521 * @v netdev Network device
522 */
523static void exanic_poll_tx ( struct net_device *netdev ) {
524 struct exanic_port *port = netdev->priv;
525
526 /* Report any completed packets */
527 while ( port->tx_cons != *(port->txf) ) {
528 DBGC2 ( port, "EXANIC %s TX %04x complete\n",
529 netdev->name, port->tx_cons );
531 port->tx_cons++;
532 }
533}
534
535/**
536 * Poll for received packets
537 *
538 * @v netdev Network device
539 */
540static void exanic_poll_rx ( struct net_device *netdev ) {
541 struct exanic_port *port = netdev->priv;
542 struct exanic_rx_chunk *rx;
543 unsigned int index;
544 uint8_t current;
545 uint8_t previous;
546 size_t len;
547
548 for ( ; ; port->rx_cons++ ) {
549
550 /* Fetch descriptor */
551 index = ( port->rx_cons % EXANIC_RX_COUNT );
552 rx = &port->rx[index];
553
554 /* Calculate generation */
555 current = ( port->rx_cons / EXANIC_RX_COUNT );
556 previous = ( current - 1 );
557
558 /* Do nothing if no chunk is ready */
559 if ( rx->desc.generation == previous )
560 break;
561
562 /* Allocate I/O buffer if needed */
563 if ( ! port->rx_iobuf ) {
564 port->rx_iobuf = alloc_iob ( EXANIC_MAX_RX_LEN );
565 if ( ! port->rx_iobuf ) {
566 /* Wait for next poll */
567 break;
568 }
569 port->rx_rc = 0;
570 }
571
572 /* Calculate chunk length */
573 len = ( rx->desc.len ? rx->desc.len : sizeof ( rx->data ) );
574
575 /* Append data to I/O buffer */
576 if ( len <= iob_tailroom ( port->rx_iobuf ) ) {
577 memcpy ( iob_put ( port->rx_iobuf, len ),
578 rx->data, len );
579 } else {
580 DBGC ( port, "EXANIC %s RX too large\n",
581 netdev->name );
582 port->rx_rc = -ERANGE;
583 }
584
585 /* Check for overrun */
586 rmb();
587 if ( rx->desc.generation != current ) {
588 DBGC ( port, "EXANIC %s RX overrun\n", netdev->name );
589 port->rx_rc = -ENOBUFS;
590 continue;
591 }
592
593 /* Wait for end of packet */
594 if ( ! rx->desc.len )
595 continue;
596
597 /* Check for receive errors */
598 if ( rx->desc.status & EXANIC_STATUS_ERROR_MASK ) {
599 port->rx_rc = -EIO_STATUS ( rx->desc.status );
600 DBGC ( port, "EXANIC %s RX %04x error: %s\n",
601 netdev->name, port->rx_cons,
602 strerror ( port->rx_rc ) );
603 } else {
604 DBGC2 ( port, "EXANIC %s RX %04x\n",
605 netdev->name, port->rx_cons );
606 }
607
608 /* Hand off to network stack */
609 if ( port->rx_rc ) {
610 netdev_rx_err ( netdev, port->rx_iobuf, port->rx_rc );
611 } else {
612 iob_unput ( port->rx_iobuf, 4 /* strip CRC */ );
613 netdev_rx ( netdev, port->rx_iobuf );
614 }
615 port->rx_iobuf = NULL;
616 }
617}
618
619/**
620 * Poll for completed and received packets
621 *
622 * @v netdev Network device
623 */
624static void exanic_poll ( struct net_device *netdev ) {
625
626 /* Poll for completed packets */
628
629 /* Poll for received packets */
631}
632
633/** ExaNIC network device operations */
635 .open = exanic_open,
636 .close = exanic_close,
637 .transmit = exanic_transmit,
638 .poll = exanic_poll,
639};
640
641/******************************************************************************
642 *
643 * PCI interface
644 *
645 ******************************************************************************
646 */
647
648/**
649 * Probe port
650 *
651 * @v exanic ExaNIC device
652 * @v dev Parent device
653 * @v index Port number
654 * @ret rc Return status code
655 */
656static int exanic_probe_port ( struct exanic *exanic, struct device *dev,
657 unsigned int index ) {
658 struct net_device *netdev;
659 struct exanic_port *port;
660 void *port_regs;
662 size_t tx_len;
663 int rc;
664
665 /* Do nothing if port is not physically present */
666 port_regs = ( exanic->regs + EXANIC_PORT_REGS ( index ) );
667 status = readl ( port_regs + EXANIC_PORT_STATUS );
668 tx_len = readl ( port_regs + EXANIC_PORT_TX_LEN );
669 if ( ( status & EXANIC_PORT_STATUS_ABSENT ) || ( tx_len == 0 ) ) {
670 rc = 0;
671 goto absent;
672 }
673
674 /* Allocate network device */
675 netdev = alloc_etherdev ( sizeof ( *port ) );
676 if ( ! netdev ) {
677 rc = -ENOMEM;
678 goto err_alloc_netdev;
679 }
681 netdev->dev = dev;
682 port = netdev->priv;
683 memset ( port, 0, sizeof ( *port ) );
684 exanic->port[index] = port;
685 port->netdev = netdev;
686 port->regs = port_regs;
687 timer_init ( &port->timer, exanic_expired, &netdev->refcnt );
688
689 /* Identify transmit region */
690 port->tx_offset = readl ( port->regs + EXANIC_PORT_TX_OFFSET );
691 if ( tx_len > EXANIC_MAX_TX_LEN )
692 tx_len = EXANIC_MAX_TX_LEN;
693 assert ( ! ( tx_len & ( tx_len - 1 ) ) );
694 port->tx = ( exanic->tx + port->tx_offset );
695 port->tx_count = ( tx_len / sizeof ( struct exanic_tx_chunk ) );
696
697 /* Identify transmit feedback region */
698 port->txf_slot = EXANIC_TXF_SLOT ( index );
699 port->txf = ( exanic->txf +
700 ( port->txf_slot * sizeof ( *(port->txf) ) ) );
701
702 /* Allocate receive region (via umalloc()) */
703 port->rx = umalloc ( EXANIC_RX_LEN );
704 if ( ! port->rx ) {
705 rc = -ENOMEM;
706 goto err_alloc_rx;
707 }
708
709 /* Set MAC address */
710 memcpy ( netdev->hw_addr, exanic->mac, ETH_ALEN );
711 netdev->hw_addr[ ETH_ALEN - 1 ] += index;
712
713 /* Record default link speed and supported speeds */
714 port->default_speed = readl ( port->regs + EXANIC_PORT_SPEED );
715 port->speeds = ( exanic->caps & EXANIC_CAPS_SPEED_MASK );
716
717 /* Register network device */
718 if ( ( rc = register_netdev ( netdev ) ) != 0 )
719 goto err_register_netdev;
720 DBGC ( port, "EXANIC %s port %d TX [%#05zx,%#05zx) TXF %#02x RX "
721 "[%#lx,%#lx)\n", netdev->name, index, port->tx_offset,
722 ( port->tx_offset + tx_len ), port->txf_slot,
723 virt_to_phys ( port->rx ),
724 ( virt_to_phys ( port->rx ) + EXANIC_RX_LEN ) );
725
726 /* Set initial link state */
728
729 return 0;
730
732 err_register_netdev:
733 ufree ( port->rx );
734 err_alloc_rx:
736 netdev_put ( netdev );
737 err_alloc_netdev:
738 absent:
739 return rc;
740}
741
742/**
743 * Probe port
744 *
745 * @v exanic ExaNIC device
746 * @v index Port number
747 */
748static void exanic_remove_port ( struct exanic *exanic, unsigned int index ) {
749 struct exanic_port *port;
750
751 /* Do nothing if port is not physically present */
752 port = exanic->port[index];
753 if ( ! port )
754 return;
755
756 /* Unregister network device */
757 unregister_netdev ( port->netdev );
758
759 /* Free receive region */
760 ufree ( port->rx );
761
762 /* Free network device */
763 netdev_nullify ( port->netdev );
764 netdev_put ( port->netdev );
765}
766
767/**
768 * Probe PCI device
769 *
770 * @v pci PCI device
771 * @ret rc Return status code
772 */
773static int exanic_probe ( struct pci_device *pci ) {
774 struct exanic *exanic;
775 unsigned long regs_bar_start;
776 unsigned long tx_bar_start;
777 size_t tx_bar_len;
778 int i;
779 int rc;
780
781 /* Allocate and initialise structure */
782 exanic = zalloc ( sizeof ( *exanic ) );
783 if ( ! exanic ) {
784 rc = -ENOMEM;
785 goto err_alloc;
786 }
787 pci_set_drvdata ( pci, exanic );
788
789 /* Fix up PCI device */
790 adjust_pci_device ( pci );
791
792 /* Map registers */
793 regs_bar_start = pci_bar_start ( pci, EXANIC_REGS_BAR );
794 exanic->regs = pci_ioremap ( pci, regs_bar_start, EXANIC_REGS_LEN );
795 if ( ! exanic->regs ) {
796 rc = -ENODEV;
797 goto err_ioremap_regs;
798 }
799
800 /* Reset device */
802
803 /* Read capabilities */
805
806 /* Power up PHYs */
808
809 /* Fetch base MAC address */
810 if ( ( rc = exanic_fetch_mac ( exanic ) ) != 0 )
811 goto err_fetch_mac;
812 DBGC ( exanic, "EXANIC %p capabilities %#08x base MAC %s\n",
814
815 /* Map transmit region */
816 tx_bar_start = pci_bar_start ( pci, EXANIC_TX_BAR );
817 tx_bar_len = pci_bar_size ( pci, EXANIC_TX_BAR );
818 exanic->tx = pci_ioremap ( pci, tx_bar_start, tx_bar_len );
819 if ( ! exanic->tx ) {
820 rc = -ENODEV;
821 goto err_ioremap_tx;
822 }
823
824 /* Allocate transmit feedback region (shared between all ports) */
826 if ( ! exanic->txf ) {
827 rc = -ENOMEM;
828 goto err_alloc_txf;
829 }
832 ( exanic->regs + EXANIC_TXF_BASE ) );
833
834 /* Allocate and initialise per-port network devices */
835 for ( i = 0 ; i < EXANIC_MAX_PORTS ; i++ ) {
836 if ( ( rc = exanic_probe_port ( exanic, &pci->dev, i ) ) != 0 )
837 goto err_probe_port;
838 }
839
840 return 0;
841
843 err_probe_port:
844 for ( i-- ; i >= 0 ; i-- )
848 err_alloc_txf:
849 iounmap ( exanic->tx );
850 err_ioremap_tx:
851 iounmap ( exanic->regs );
852 err_fetch_mac:
853 err_ioremap_regs:
854 free ( exanic );
855 err_alloc:
856 return rc;
857}
858
859/**
860 * Remove PCI device
861 *
862 * @v pci PCI device
863 */
864static void exanic_remove ( struct pci_device *pci ) {
865 struct exanic *exanic = pci_get_drvdata ( pci );
866 unsigned int i;
867
868 /* Remove all ports */
869 for ( i = 0 ; i < EXANIC_MAX_PORTS ; i++ )
871
872 /* Reset device */
874
875 /* Free transmit feedback region */
877
878 /* Unmap transmit region */
879 iounmap ( exanic->tx );
880
881 /* Unmap registers */
882 iounmap ( exanic->regs );
883
884 /* Free device */
885 free ( exanic );
886}
887
888/** ExaNIC PCI device IDs */
889static struct pci_device_id exanic_ids[] = {
890 PCI_ROM ( 0x10ee, 0x2b00, "exanic-old", "ExaNIC (old)", 0 ),
891 PCI_ROM ( 0x1ce4, 0x0001, "exanic-x4", "ExaNIC X4", 0 ),
892 PCI_ROM ( 0x1ce4, 0x0002, "exanic-x2", "ExaNIC X2", 0 ),
893 PCI_ROM ( 0x1ce4, 0x0003, "exanic-x10", "ExaNIC X10", 0 ),
894 PCI_ROM ( 0x1ce4, 0x0004, "exanic-x10gm", "ExaNIC X10 GM", 0 ),
895 PCI_ROM ( 0x1ce4, 0x0005, "exanic-x40", "ExaNIC X40", 0 ),
896 PCI_ROM ( 0x1ce4, 0x0006, "exanic-x10hpt", "ExaNIC X10 HPT", 0 ),
897 PCI_ROM ( 0x1ce4, 0x0007, "exanic-x40g", "ExaNIC X40", 0 ),
898};
899
900/** ExaNIC PCI driver */
901struct pci_driver exanic_driver __pci_driver = {
902 .ids = exanic_ids,
903 .id_count = ( sizeof ( exanic_ids ) / sizeof ( exanic_ids[0] ) ),
906};
#define NULL
NULL pointer (VOID *)
Definition Base.h:322
u8 port
Port number.
Definition CIB_PRM.h:3
typeof(acpi_finder=acpi_find)
ACPI table finder.
Definition acpi.c:48
struct arbelprm_rc_send_wqe rc
Definition arbel.h:3
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
long index
Definition bigint.h:65
static const void * src
Definition string.h:48
#define assert(condition)
Assert a condition at run-time.
Definition assert.h:50
uint16_t offset
Offset to command line.
Definition bzimage.h:3
ring len
Length.
Definition dwmac.h:226
uint32_t addr
Buffer address.
Definition dwmac.h:9
uint8_t data[48]
Additional event data.
Definition ena.h:11
uint8_t status
Status.
Definition ena.h:5
Error codes.
struct net_device * alloc_etherdev(size_t priv_size)
Allocate Ethernet device.
Definition ethernet.c:265
const char * eth_ntoa(const void *ll_addr)
Transcribe Ethernet address.
Definition ethernet.c:176
Ethernet protocol.
static struct pci_device_id exanic_ids[]
ExaNIC PCI device IDs.
Definition exanic.c:889
static void exanic_reset(struct exanic *exanic)
Reset hardware.
Definition exanic.c:111
static void exanic_remove(struct pci_device *pci)
Remove PCI device.
Definition exanic.c:864
static struct bit_basher_operations exanic_i2c_basher_ops
I2C bit-bashing interface operations.
Definition exanic.c:192
static int exanic_open(struct net_device *netdev)
Open network device.
Definition exanic.c:383
static void exanic_check_link(struct net_device *netdev)
Check link state.
Definition exanic.c:304
static void exanic_expired(struct retry_timer *timer, int over __unused)
Check link state periodically.
Definition exanic.c:330
static void exanic_i2c_write_bit(struct bit_basher *basher, unsigned int bit_id, unsigned long data)
Write I2C line status.
Definition exanic.c:167
static int exanic_probe(struct pci_device *pci)
Probe PCI device.
Definition exanic.c:773
static void exanic_close(struct net_device *netdev)
Close network device.
Definition exanic.c:437
static struct exanic_i2c_config exanic_i2cfgs[]
Possible I2C bus configurations.
Definition exanic.c:198
static int exanic_fetch_mac(struct exanic *exanic)
Fetch base MAC address.
Definition exanic.c:273
static int exanic_try_init_eeprom(struct exanic *exanic, struct exanic_i2c_config *i2cfg)
Initialise EEPROM.
Definition exanic.c:212
static int exanic_i2c_read_bit(struct bit_basher *basher, unsigned int bit_id)
Read I2C line status.
Definition exanic.c:142
static void exanic_poll_rx(struct net_device *netdev)
Poll for received packets.
Definition exanic.c:540
#define EIO_STATUS(status)
Definition exanic.c:57
static int exanic_transmit(struct net_device *netdev, struct io_buffer *iobuf)
Transmit packet.
Definition exanic.c:464
static void exanic_write_base(physaddr_t addr, void *reg)
Write DMA base address register.
Definition exanic.c:67
static int exanic_init_eeprom(struct exanic *exanic)
Initialise EEPROM.
Definition exanic.c:250
static void exanic_poll(struct net_device *netdev)
Poll for completed and received packets.
Definition exanic.c:624
static int exanic_probe_port(struct exanic *exanic, struct device *dev, unsigned int index)
Probe port.
Definition exanic.c:656
static void exanic_clear_base(void *reg)
Clear DMA base address register.
Definition exanic.c:92
static struct net_device_operations exanic_operations
ExaNIC network device operations.
Definition exanic.c:634
static void exanic_poll_tx(struct net_device *netdev)
Poll for completed packets.
Definition exanic.c:523
static void exanic_remove_port(struct exanic *exanic, unsigned int index)
Probe port.
Definition exanic.c:748
Exablaze ExaNIC driver.
#define EXANIC_RX_COUNT
Number of receive chunks.
Definition exanic.h:161
#define EXANIC_CAPS_SPEED_MASK
Supported speeds mask.
Definition exanic.h:59
#define EXANIC_LINK_INTERVAL
Interval between link state checks.
Definition exanic.h:261
#define EXANIC_CAPS
Capabilities register.
Definition exanic.h:53
#define EXANIC_PORT_SPEED
Port speed register.
Definition exanic.h:76
#define EXANIC_EEPROM_ADDRESS
EEPROM address.
Definition exanic.h:174
#define EXANIC_PORT_TX_OFFSET
Port transmit region offset register.
Definition exanic.h:97
#define EXANIC_POWER_ON
Power on PHYs.
Definition exanic.h:66
#define EXANIC_STATUS_ERROR_MASK
Receive status error mask.
Definition exanic.h:158
#define EXANIC_PORT_STATUS_ABSENT
Port is not present.
Definition exanic.h:81
#define EXANIC_ALIGN
Alignment for DMA regions.
Definition exanic.h:29
#define EXANIC_REGS_LEN
Register set length.
Definition exanic.h:35
#define EXANIC_PORT_STATUS_LINK
Link is up.
Definition exanic.h:80
#define EXANIC_RX_LEN
Receive region length.
Definition exanic.h:47
#define EXANIC_PORT_RX_BASE
Port receive chunk base address register.
Definition exanic.h:91
#define EXANIC_I2C
I2C GPIO register.
Definition exanic.h:62
#define EXANIC_POWER
Power control register.
Definition exanic.h:65
#define EXANIC_MAX_PORTS
Maximum number of ports.
Definition exanic.h:20
#define EXANIC_PORT_FLAGS_PROMISC
Promiscuous mode.
Definition exanic.h:88
#define EXANIC_MAX_RX_LEN
Maximum length of received packet.
Definition exanic.h:255
#define EXANIC_TXF_LEN
Transmit feedback region length.
Definition exanic.h:38
#define EXANIC_PORT_IRQ
Port interrupt configuration register.
Definition exanic.h:106
#define EXANIC_DMA_32_BIT
Flag for 32-bit DMA addresses.
Definition exanic.h:32
#define EXANIC_PORT_ENABLE
Port enable register.
Definition exanic.h:72
#define EXANIC_PORT_STATUS
Port status register.
Definition exanic.h:79
#define EXANIC_PORT_TX_LEN
Port transmit region length register.
Definition exanic.h:100
#define EXANIC_TXF_SLOT(index)
Transmit feedback slot.
Definition exanic.h:44
#define EXANIC_REGS_BAR
Register BAR.
Definition exanic.h:23
#define EXANIC_TYPE_RAW
Raw Ethernet frame type.
Definition exanic.h:133
#define EXANIC_TXF_BASE
Transmit feedback base address register.
Definition exanic.h:50
#define EXANIC_PORT_TX_COMMAND
Port transmit command register.
Definition exanic.h:94
#define EXANIC_MAX_TX_LEN
Maximum used length of transmit region.
Definition exanic.h:249
#define EXANIC_PORT_ENABLE_ENABLED
Port is enabled.
Definition exanic.h:73
#define EXANIC_TX_BAR
Transmit region BAR.
Definition exanic.h:26
#define EXANIC_PORT_REGS(index)
Port register offset.
Definition exanic.h:69
#define EXANIC_PORT_FLAGS
Port flags register.
Definition exanic.h:87
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 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 ENOMEM
Not enough space.
Definition errno.h:535
#define ENOTSUP
Operation not supported.
Definition errno.h:590
#define ECANCELED
Operation canceled.
Definition errno.h:344
#define ENOBUFS
No buffer space available.
Definition errno.h:499
#define ERANGE
Result too large.
Definition errno.h:640
#define ENODEV
No such device.
Definition errno.h:510
static int i2c_check_presence(struct i2c_interface *i2c, struct i2c_device *i2cdev)
Check presence of I2C device.
Definition i2c.h:135
@ I2C_BIT_SDA
Serial data.
Definition i2c.h:116
@ I2C_BIT_SCL
Serial clock.
Definition i2c.h:114
static __always_inline void init_i2c_eeprom(struct i2c_device *i2cdev, unsigned int dev_addr)
Initialise generic I2C EEPROM device.
Definition i2c.h:149
int init_i2c_bit_basher(struct i2c_bit_basher *i2cbit, struct bit_basher_operations *bash_op)
Initialise I2C bit-bashing interface.
Definition i2c_bit.c:387
#define ETH_ALEN
Definition if_ether.h:9
#define rmb()
Definition io.h:545
unsigned long phys_to_bus(unsigned long phys_addr)
Convert physical address to a bus address.
#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.
User memory allocation.
static __always_inline void * umalloc(size_t size)
Allocate external memory.
Definition umalloc.h:57
static __always_inline void ufree(void *ptr)
Free external memory.
Definition umalloc.h:68
String functions.
void * memcpy(void *dest, const void *src, size_t len) __nonnull
void * memset(void *dest, int character, size_t len) __nonnull
String functions.
#define ffs(x)
Find first (i.e.
Definition strings.h:141
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
#define iob_unput(iobuf, len)
Definition iobuf.h:140
static size_t iob_tailroom(struct io_buffer *iobuf)
Calculate available space at end of an I/O buffer.
Definition iobuf.h:180
void * zalloc(size_t size)
Allocate cleared memory.
Definition malloc.c:662
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.
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 int netdev_link_ok(struct net_device *netdev)
Check link state of network device.
Definition netdevice.h:640
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
unsigned long pci_bar_size(struct pci_device *pci, unsigned int reg)
Get the size of a PCI BAR.
Definition pci.c:164
void adjust_pci_device(struct pci_device *pci)
Enable PCI device.
Definition pci.c:241
unsigned long pci_bar_start(struct pci_device *pci, unsigned int reg)
Find the start of a PCI BAR.
Definition pci.c:97
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
static void(* free)(struct refcnt *refcnt))
Definition refcnt.h:55
void start_timer_fixed(struct retry_timer *timer, unsigned long timeout)
Start timer with a specified timeout.
Definition retry.c:65
void stop_timer(struct retry_timer *timer)
Stop timer.
Definition retry.c:118
#define offsetof(type, field)
Get offset of a field within a structure.
Definition stddef.h:25
#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
A hardware device.
Definition device.h:77
An ExaNIC I2C bus configuration.
Definition exanic.h:164
uint8_t getsda
GPIO bit for reading SDA.
Definition exanic.h:170
uint8_t setscl
GPIO bit for pulling SCL low.
Definition exanic.h:166
uint8_t setsda
GPIO bit for pulling SDA low.
Definition exanic.h:168
An ExaNIC port.
Definition exanic.h:177
unsigned int speed
Current attempted link speed (as a capability bit index)
Definition exanic.h:214
An ExaNIC receive chunk.
Definition exanic.h:150
An ExaNIC transmit chunk.
Definition exanic.h:123
An ExaNIC.
Definition exanic.h:220
struct exanic_port * port[EXANIC_MAX_PORTS]
Ports.
Definition exanic.h:241
void * regs
Registers.
Definition exanic.h:222
void * txf
Transmit feedback region.
Definition exanic.h:226
uint8_t mac[ETH_ALEN]
Base MAC address.
Definition exanic.h:238
struct exanic_i2c_config i2cfg
I2C bus configuration.
Definition exanic.h:229
uint32_t caps
Capabilities.
Definition exanic.h:236
struct i2c_device eeprom
I2C serial EEPROM.
Definition exanic.h:233
void * tx
Transmit region.
Definition exanic.h:224
struct i2c_bit_basher basher
I2C bit-bashing interface.
Definition exanic.h:231
struct i2c_interface i2c
I2C interface.
Definition i2c.h:93
struct bit_basher basher
Bit-bashing interface.
Definition i2c.h:95
An I2C interface.
Definition i2c.h:57
int(* read)(struct i2c_interface *i2c, struct i2c_device *i2cdev, unsigned int offset, uint8_t *data, unsigned int len)
Read data from I2C device.
Definition i2c.h:68
A persistent I/O buffer.
Definition iobuf.h:38
void * data
Start of data.
Definition iobuf.h:53
Network device operations.
Definition netdevice.h:214
A network device.
Definition netdevice.h:353
A PCI device ID list entry.
Definition pci.h:175
A PCI device.
Definition pci.h:211
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
A retry timer.
Definition retry.h:22
A timer.
Definition timer.h:29
#define readl
Definition w89c840.c:157
#define writel
Definition w89c840.c:160
#define writew
Definition w89c840.c:159
#define writeb
Definition w89c840.c:158
u8 tx[WPA_TKIP_MIC_KEY_LEN]
MIC key for packets to the AP.
Definition wpa.h:4
u8 rx[WPA_TKIP_MIC_KEY_LEN]
MIC key for packets from the AP.
Definition wpa.h:1
static struct xen_remove_from_physmap * remove
Definition xenmem.h:40