1 /**************************************************************************
3 * Etherboot driver for Level 5 Etherfabric network cards
5 * Written by Michael Brown <mbrown@fensystems.co.uk>
7 * Copyright Fen Systems Ltd. 2005
8 * Copyright Level 5 Networks Inc. 2005
10 * This software may be used and distributed according to the terms of
11 * the GNU General Public License (GPL), incorporated herein by
12 * reference. Drivers based on or derived from this code fall under
13 * the GPL and must retain the authorship, copyright and license
16 **************************************************************************
19 #include "etherboot.h"
23 #define dma_addr_t unsigned long
24 #include "etherfabric.h"
26 /**************************************************************************
28 * Constants and macros
30 **************************************************************************
35 #define EFAB_ASSERT(x) \
38 DBG ( "ASSERT(%s) failed at %s line %d [%s]\n", #x, \
39 __FILE__, __LINE__, __FUNCTION__ ); \
43 #define EFAB_TRACE(...)
45 #define EFAB_REGDUMP(...)
47 #define FALCON_USE_IO_BAR 1
50 * EtherFabric constants
55 #define EFAB_VENDID_LEVEL5 0x1924
56 #define FALCON_P_DEVID 0x0703 /* Temporary PCI ID */
57 #define EF1002_DEVID 0xC101
59 /**************************************************************************
63 **************************************************************************
67 * Buffers used for TX, RX and event queue
70 #define EFAB_BUF_ALIGN 4096
71 #define EFAB_DATA_BUF_SIZE 2048
72 #define EFAB_RX_BUFS 16
73 #define EFAB_RXD_SIZE 512
74 #define EFAB_TXD_SIZE 512
75 #define EFAB_EVQ_SIZE 512
80 uint8_t tx_buf[EFAB_DATA_BUF_SIZE];
81 uint8_t rx_buf[EFAB_RX_BUFS][EFAB_DATA_BUF_SIZE];
82 uint8_t padding[EFAB_BUF_ALIGN-1];
84 static struct efab_buffers efab_buffers;
100 /** Etherfabric event type */
101 enum efab_event_type {
107 /** Etherfabric event */
110 enum efab_event_type type;
118 * Etherfabric abstraction layer
122 struct efab_operations {
123 void ( * get_membase ) ( struct efab_nic *efab );
124 int ( * reset ) ( struct efab_nic *efab );
125 int ( * init_nic ) ( struct efab_nic *efab );
126 int ( * read_eeprom ) ( struct efab_nic *efab );
127 void ( * build_rx_desc ) ( struct efab_nic *efab,
128 struct efab_rx_buf *rx_buf );
129 void ( * notify_rx_desc ) ( struct efab_nic *efab );
130 void ( * build_tx_desc ) ( struct efab_nic *efab,
131 struct efab_tx_buf *tx_buf );
132 void ( * notify_tx_desc ) ( struct efab_nic *efab );
133 int ( * fetch_event ) ( struct efab_nic *efab,
134 struct efab_event *event );
135 void ( * mask_irq ) ( struct efab_nic *efab, int enabled );
136 void ( * generate_irq ) ( struct efab_nic *efab );
137 void ( * mac_writel ) ( struct efab_nic *efab, efab_dword_t *value,
138 unsigned int mac_reg );
139 void ( * mac_readl ) ( struct efab_nic *efab, efab_dword_t *value,
140 unsigned int mac_reg );
141 int ( * init_mac ) ( struct efab_nic *efab );
142 void ( * mdio_write ) ( struct efab_nic *efab, int location,
144 int ( * mdio_read ) ( struct efab_nic *efab, int location );
148 * Driver private data structure
154 struct pci_device *pci;
156 /** Operations table */
157 struct efab_operations *op;
166 uint8_t *eventq; /* Falcon only */
167 uint8_t *txd; /* Falcon only */
168 uint8_t *rxd; /* Falcon only */
169 struct efab_tx_buf tx_buf;
170 struct efab_rx_buf rx_bufs[EFAB_RX_BUFS];
172 /** Buffer pointers */
173 unsigned int eventq_read_ptr; /* Falcon only */
174 unsigned int tx_write_ptr;
175 unsigned int rx_write_ptr;
178 /** Port 0/1 on the NIC */
182 uint8_t mac_addr[ETH_ALEN];
183 /** GMII link options */
184 unsigned int link_options;
188 /** INT_REG_KER for Falcon */
189 efab_oword_t int_ker __attribute__ (( aligned ( 16 ) ));
192 /**************************************************************************
196 **************************************************************************
199 #define EFAB_EEPROM_SDA 0x80000000u
200 #define EFAB_EEPROM_SCL 0x40000000u
201 #define ARIZONA_24xx00_SLAVE 0xa0
202 #define EFAB_EEPROM_READ_SELECT ( ARIZONA_24xx00_SLAVE | 1 )
203 #define EFAB_EEPROM_WRITE_SELECT ( ARIZONA_24xx00_SLAVE | 0 )
205 static void eeprom_release ( uint32_t *eeprom_reg ) {
209 dev = readl ( eeprom_reg );
210 writel ( dev | ( EFAB_EEPROM_SDA | EFAB_EEPROM_SCL ),
215 static void eeprom_start ( uint32_t *eeprom_reg ) {
219 dev = readl ( eeprom_reg );
221 if ( ( dev & ( EFAB_EEPROM_SDA | EFAB_EEPROM_SCL ) ) !=
222 ( EFAB_EEPROM_SDA | EFAB_EEPROM_SCL ) ) {
224 writel ( dev | ( EFAB_EEPROM_SDA | EFAB_EEPROM_SCL ),
228 dev &=~ ( EFAB_EEPROM_SDA | EFAB_EEPROM_SCL );
231 writel ( dev | EFAB_EEPROM_SCL, eeprom_reg) ;
235 writel ( dev, eeprom_reg );
239 static void eeprom_stop ( uint32_t *eeprom_reg ) {
243 dev = readl ( eeprom_reg );
244 EFAB_ASSERT ( ! ( dev & EFAB_EEPROM_SCL ) );
246 if ( dev & ( EFAB_EEPROM_SDA | EFAB_EEPROM_SCL ) ) {
247 dev &=~ ( EFAB_EEPROM_SDA | EFAB_EEPROM_SCL );
249 writel ( dev, eeprom_reg );
254 dev |= EFAB_EEPROM_SCL;
255 writel ( dev, eeprom_reg );
259 dev |= EFAB_EEPROM_SDA;
260 writel ( dev, eeprom_reg );
264 static void eeprom_write ( uint32_t *eeprom_reg, unsigned char data ) {
269 dev = readl ( eeprom_reg );
271 EFAB_ASSERT ( ! ( dev & EFAB_EEPROM_SCL ) );
273 for ( i = 0 ; i < 8 ; i++, data <<= 1 ) {
275 dev |= EFAB_EEPROM_SDA;
277 dev &=~ EFAB_EEPROM_SDA;
280 writel ( dev, eeprom_reg );
284 writel ( dev | EFAB_EEPROM_SCL, eeprom_reg );
288 writel ( dev, eeprom_reg );
292 if( ! ( dev & EFAB_EEPROM_SDA ) ) {
294 writel ( dev | EFAB_EEPROM_SDA, eeprom_reg );
299 static unsigned char eeprom_read ( uint32_t *eeprom_reg ) {
300 unsigned int i, dev, rd;
301 unsigned char val = 0;
304 dev = readl ( eeprom_reg );
306 EFAB_ASSERT ( ! ( dev & EFAB_EEPROM_SCL ) );
308 if( ! ( dev & EFAB_EEPROM_SDA ) ) {
309 dev |= EFAB_EEPROM_SDA;
311 writel ( dev, eeprom_reg );
315 for( i = 0 ; i < 8 ; i++ ) {
317 writel ( dev | EFAB_EEPROM_SCL, eeprom_reg );
321 rd = readl ( eeprom_reg );
323 val = ( val << 1 ) | ( ( rd & EFAB_EEPROM_SDA ) != 0 );
326 writel ( dev, eeprom_reg );
333 static int eeprom_check_ack ( uint32_t *eeprom_reg ) {
338 dev = readl ( eeprom_reg );
339 EFAB_ASSERT ( ! ( dev & EFAB_EEPROM_SCL ) );
341 writel ( dev | EFAB_EEPROM_SCL, eeprom_reg );
345 ack = readl ( eeprom_reg ) & EFAB_EEPROM_SDA;
348 writel ( ack & ~EFAB_EEPROM_SCL, eeprom_reg );
354 static void eeprom_send_ack ( uint32_t *eeprom_reg ) {
358 dev = readl ( eeprom_reg );
359 EFAB_ASSERT ( ! ( dev & EFAB_EEPROM_SCL ) );
362 dev &= ~EFAB_EEPROM_SDA;
363 writel ( dev, eeprom_reg );
367 dev |= EFAB_EEPROM_SCL;
368 writel ( dev, eeprom_reg );
372 dev |= EFAB_EEPROM_SDA;
373 writel ( dev & ~EFAB_EEPROM_SCL, eeprom_reg );
377 static int efab_eeprom_read_mac ( uint32_t *eeprom_reg, uint8_t *mac_addr ) {
380 eeprom_start ( eeprom_reg );
382 eeprom_write ( eeprom_reg, EFAB_EEPROM_WRITE_SELECT );
383 if ( ! eeprom_check_ack ( eeprom_reg ) )
386 eeprom_write ( eeprom_reg, 0 );
387 if ( ! eeprom_check_ack ( eeprom_reg ) )
390 eeprom_stop ( eeprom_reg );
391 eeprom_start ( eeprom_reg );
393 eeprom_write ( eeprom_reg, EFAB_EEPROM_READ_SELECT );
394 if ( ! eeprom_check_ack ( eeprom_reg ) )
397 for ( i = 0 ; i < ETH_ALEN ; i++ ) {
398 mac_addr[i] = eeprom_read ( eeprom_reg );
399 eeprom_send_ack ( eeprom_reg );
402 eeprom_stop ( eeprom_reg );
404 eeprom_release ( eeprom_reg );
409 /**************************************************************************
413 **************************************************************************
417 #define MII_BMSR 0x01 /* Basic mode status register */
418 #define MII_ADVERTISE 0x04 /* Advertisement control register */
419 #define MII_LPA 0x05 /* Link partner ability register*/
420 #define GMII_GTCR 0x09 /* 1000BASE-T control register */
421 #define GMII_GTSR 0x0a /* 1000BASE-T status register */
422 #define GMII_PSSR 0x11 /* PHY-specific status register */
424 /* Basic mode status register. */
425 #define BMSR_LSTATUS 0x0004 /* Link status */
427 /* Link partner ability register. */
428 #define LPA_10HALF 0x0020 /* Can do 10mbps half-duplex */
429 #define LPA_10FULL 0x0040 /* Can do 10mbps full-duplex */
430 #define LPA_100HALF 0x0080 /* Can do 100mbps half-duplex */
431 #define LPA_100FULL 0x0100 /* Can do 100mbps full-duplex */
432 #define LPA_100BASE4 0x0200 /* Can do 100mbps 4k packets */
433 #define LPA_PAUSE 0x0400 /* Bit 10 - MAC pause */
435 /* Pseudo extensions to the link partner ability register */
436 #define LPA_1000FULL 0x00020000
437 #define LPA_1000HALF 0x00010000
439 #define LPA_100 (LPA_100FULL | LPA_100HALF | LPA_100BASE4)
440 #define LPA_1000 ( LPA_1000FULL | LPA_1000HALF )
441 #define LPA_DUPLEX ( LPA_10FULL | LPA_100FULL | LPA_1000FULL )
443 /* Mask of bits not associated with speed or duplexity. */
444 #define LPA_OTHER ~( LPA_10FULL | LPA_10HALF | LPA_100FULL | \
445 LPA_100HALF | LPA_1000FULL | LPA_1000HALF )
447 /* PHY-specific status register */
448 #define PSSR_LSTATUS 0x0400 /* Bit 10 - link status */
451 * Retrieve GMII autonegotiation advertised abilities
454 static unsigned int gmii_autoneg_advertised ( struct efab_nic *efab ) {
455 unsigned int mii_advertise;
456 unsigned int gmii_advertise;
458 /* Extended bits are in bits 8 and 9 of GMII_GTCR */
459 mii_advertise = efab->op->mdio_read ( efab, MII_ADVERTISE );
460 gmii_advertise = ( ( efab->op->mdio_read ( efab, GMII_GTCR ) >> 8 )
462 return ( ( gmii_advertise << 16 ) | mii_advertise );
466 * Retrieve GMII autonegotiation link partner abilities
469 static unsigned int gmii_autoneg_lpa ( struct efab_nic *efab ) {
470 unsigned int mii_lpa;
471 unsigned int gmii_lpa;
473 /* Extended bits are in bits 10 and 11 of GMII_GTSR */
474 mii_lpa = efab->op->mdio_read ( efab, MII_LPA );
475 gmii_lpa = ( efab->op->mdio_read ( efab, GMII_GTSR ) >> 10 ) & 0x03;
476 return ( ( gmii_lpa << 16 ) | mii_lpa );
480 * Calculate GMII autonegotiated link technology
483 static unsigned int gmii_nway_result ( unsigned int negotiated ) {
484 unsigned int other_bits;
486 /* Mask out the speed and duplexity bits */
487 other_bits = negotiated & LPA_OTHER;
489 if ( negotiated & LPA_1000FULL )
490 return ( other_bits | LPA_1000FULL );
491 else if ( negotiated & LPA_1000HALF )
492 return ( other_bits | LPA_1000HALF );
493 else if ( negotiated & LPA_100FULL )
494 return ( other_bits | LPA_100FULL );
495 else if ( negotiated & LPA_100BASE4 )
496 return ( other_bits | LPA_100BASE4 );
497 else if ( negotiated & LPA_100HALF )
498 return ( other_bits | LPA_100HALF );
499 else if ( negotiated & LPA_10FULL )
500 return ( other_bits | LPA_10FULL );
501 else return ( other_bits | LPA_10HALF );
505 * Check GMII PHY link status
508 static int gmii_link_ok ( struct efab_nic *efab ) {
512 /* BMSR is latching - it returns "link down" if the link has
513 * been down at any point since the last read. To get a
514 * real-time status, we therefore read the register twice and
515 * use the result of the second read.
517 efab->op->mdio_read ( efab, MII_BMSR );
518 status = efab->op->mdio_read ( efab, MII_BMSR );
520 /* Read the PHY-specific Status Register. This is
521 * non-latching, so we need do only a single read.
523 phy_status = efab->op->mdio_read ( efab, GMII_PSSR );
525 return ( ( status & BMSR_LSTATUS ) && ( phy_status & PSSR_LSTATUS ) );
528 /**************************************************************************
532 **************************************************************************
536 * Initialise Alaska PHY
539 static void alaska_init ( struct efab_nic *efab ) {
540 unsigned int advertised, lpa;
542 /* Read link up status */
543 efab->link_up = gmii_link_ok ( efab );
545 if ( ! efab->link_up )
548 /* Determine link options from PHY. */
549 advertised = gmii_autoneg_advertised ( efab );
550 lpa = gmii_autoneg_lpa ( efab );
551 efab->link_options = gmii_nway_result ( advertised & lpa );
553 printf ( "%dMbps %s-duplex (%04x,%04x)\n",
554 ( efab->link_options & LPA_1000 ? 1000 :
555 ( efab->link_options & LPA_100 ? 100 : 10 ) ),
556 ( efab->link_options & LPA_DUPLEX ? "full" : "half" ),
560 /**************************************************************************
564 **************************************************************************
567 /* GMAC configuration register 1 */
568 #define GM_CFG1_REG_MAC 0x00
569 #define GM_SW_RST_LBN 31
570 #define GM_SW_RST_WIDTH 1
571 #define GM_RX_FC_EN_LBN 5
572 #define GM_RX_FC_EN_WIDTH 1
573 #define GM_TX_FC_EN_LBN 4
574 #define GM_TX_FC_EN_WIDTH 1
575 #define GM_RX_EN_LBN 2
576 #define GM_RX_EN_WIDTH 1
577 #define GM_TX_EN_LBN 0
578 #define GM_TX_EN_WIDTH 1
580 /* GMAC configuration register 2 */
581 #define GM_CFG2_REG_MAC 0x01
582 #define GM_PAMBL_LEN_LBN 12
583 #define GM_PAMBL_LEN_WIDTH 4
584 #define GM_IF_MODE_LBN 8
585 #define GM_IF_MODE_WIDTH 2
586 #define GM_PAD_CRC_EN_LBN 2
587 #define GM_PAD_CRC_EN_WIDTH 1
589 #define GM_FD_WIDTH 1
591 /* GMAC maximum frame length register */
592 #define GM_MAX_FLEN_REG_MAC 0x04
593 #define GM_MAX_FLEN_LBN 0
594 #define GM_MAX_FLEN_WIDTH 16
596 /* GMAC MII management configuration register */
597 #define GM_MII_MGMT_CFG_REG_MAC 0x08
598 #define GM_MGMT_CLK_SEL_LBN 0
599 #define GM_MGMT_CLK_SEL_WIDTH 3
601 /* GMAC MII management command register */
602 #define GM_MII_MGMT_CMD_REG_MAC 0x09
603 #define GM_MGMT_SCAN_CYC_LBN 1
604 #define GM_MGMT_SCAN_CYC_WIDTH 1
605 #define GM_MGMT_RD_CYC_LBN 0
606 #define GM_MGMT_RD_CYC_WIDTH 1
608 /* GMAC MII management address register */
609 #define GM_MII_MGMT_ADR_REG_MAC 0x0a
610 #define GM_MGMT_PHY_ADDR_LBN 8
611 #define GM_MGMT_PHY_ADDR_WIDTH 5
612 #define GM_MGMT_REG_ADDR_LBN 0
613 #define GM_MGMT_REG_ADDR_WIDTH 5
615 /* GMAC MII management control register */
616 #define GM_MII_MGMT_CTL_REG_MAC 0x0b
617 #define GM_MGMT_CTL_LBN 0
618 #define GM_MGMT_CTL_WIDTH 16
620 /* GMAC MII management status register */
621 #define GM_MII_MGMT_STAT_REG_MAC 0x0c
622 #define GM_MGMT_STAT_LBN 0
623 #define GM_MGMT_STAT_WIDTH 16
625 /* GMAC MII management indicators register */
626 #define GM_MII_MGMT_IND_REG_MAC 0x0d
627 #define GM_MGMT_BUSY_LBN 0
628 #define GM_MGMT_BUSY_WIDTH 1
630 /* GMAC station address register 1 */
631 #define GM_ADR1_REG_MAC 0x10
632 #define GM_HWADDR_5_LBN 24
633 #define GM_HWADDR_5_WIDTH 8
634 #define GM_HWADDR_4_LBN 16
635 #define GM_HWADDR_4_WIDTH 8
636 #define GM_HWADDR_3_LBN 8
637 #define GM_HWADDR_3_WIDTH 8
638 #define GM_HWADDR_2_LBN 0
639 #define GM_HWADDR_2_WIDTH 8
641 /* GMAC station address register 2 */
642 #define GM_ADR2_REG_MAC 0x11
643 #define GM_HWADDR_1_LBN 24
644 #define GM_HWADDR_1_WIDTH 8
645 #define GM_HWADDR_0_LBN 16
646 #define GM_HWADDR_0_WIDTH 8
648 /* GMAC FIFO configuration register 0 */
649 #define GMF_CFG0_REG_MAC 0x12
650 #define GMF_FTFENREQ_LBN 12
651 #define GMF_FTFENREQ_WIDTH 1
652 #define GMF_STFENREQ_LBN 11
653 #define GMF_STFENREQ_WIDTH 1
654 #define GMF_FRFENREQ_LBN 10
655 #define GMF_FRFENREQ_WIDTH 1
656 #define GMF_SRFENREQ_LBN 9
657 #define GMF_SRFENREQ_WIDTH 1
658 #define GMF_WTMENREQ_LBN 8
659 #define GMF_WTMENREQ_WIDTH 1
661 /* GMAC FIFO configuration register 1 */
662 #define GMF_CFG1_REG_MAC 0x13
663 #define GMF_CFGFRTH_LBN 16
664 #define GMF_CFGFRTH_WIDTH 5
665 #define GMF_CFGXOFFRTX_LBN 0
666 #define GMF_CFGXOFFRTX_WIDTH 16
668 /* GMAC FIFO configuration register 2 */
669 #define GMF_CFG2_REG_MAC 0x14
670 #define GMF_CFGHWM_LBN 16
671 #define GMF_CFGHWM_WIDTH 6
672 #define GMF_CFGLWM_LBN 0
673 #define GMF_CFGLWM_WIDTH 6
675 /* GMAC FIFO configuration register 3 */
676 #define GMF_CFG3_REG_MAC 0x15
677 #define GMF_CFGHWMFT_LBN 16
678 #define GMF_CFGHWMFT_WIDTH 6
679 #define GMF_CFGFTTH_LBN 0
680 #define GMF_CFGFTTH_WIDTH 6
682 /* GMAC FIFO configuration register 4 */
683 #define GMF_CFG4_REG_MAC 0x16
684 #define GMF_HSTFLTRFRM_PAUSE_LBN 12
685 #define GMF_HSTFLTRFRM_PAUSE_WIDTH 12
687 /* GMAC FIFO configuration register 5 */
688 #define GMF_CFG5_REG_MAC 0x17
689 #define GMF_CFGHDPLX_LBN 22
690 #define GMF_CFGHDPLX_WIDTH 1
691 #define GMF_CFGBYTMODE_LBN 19
692 #define GMF_CFGBYTMODE_WIDTH 1
693 #define GMF_HSTDRPLT64_LBN 18
694 #define GMF_HSTDRPLT64_WIDTH 1
695 #define GMF_HSTFLTRFRMDC_PAUSE_LBN 12
696 #define GMF_HSTFLTRFRMDC_PAUSE_WIDTH 1
698 struct efab_mentormac_parameters {
710 static void mentormac_reset ( struct efab_nic *efab, int reset ) {
713 EFAB_POPULATE_DWORD_1 ( reg, GM_SW_RST, reset );
714 efab->op->mac_writel ( efab, ®, GM_CFG1_REG_MAC );
717 if ( ( ! reset ) && ( efab->port == 0 ) ) {
718 /* Configure GMII interface so PHY is accessible.
719 * Note that GMII interface is connected only to port
722 EFAB_POPULATE_DWORD_1 ( reg, GM_MGMT_CLK_SEL, 0x4 );
723 efab->op->mac_writel ( efab, ®, GM_MII_MGMT_CFG_REG_MAC );
729 * Initialise Mentor MAC
732 static void mentormac_init ( struct efab_nic *efab,
733 struct efab_mentormac_parameters *params ) {
734 int pause, if_mode, full_duplex, bytemode, half_duplex;
737 /* Configuration register 1 */
738 pause = ( efab->link_options & LPA_PAUSE ) ? 1 : 0;
739 if ( ! ( efab->link_options & LPA_DUPLEX ) ) {
740 /* Half-duplex operation requires TX flow control */
743 EFAB_POPULATE_DWORD_4 ( reg,
748 efab->op->mac_writel ( efab, ®, GM_CFG1_REG_MAC );
751 /* Configuration register 2 */
752 if_mode = ( efab->link_options & LPA_1000 ) ? 2 : 1;
753 full_duplex = ( efab->link_options & LPA_DUPLEX ) ? 1 : 0;
754 EFAB_POPULATE_DWORD_4 ( reg,
758 GM_PAMBL_LEN, 0x7 /* ? */ );
759 efab->op->mac_writel ( efab, ®, GM_CFG2_REG_MAC );
762 /* Max frame len register */
763 EFAB_POPULATE_DWORD_1 ( reg, GM_MAX_FLEN, ETH_FRAME_LEN );
764 efab->op->mac_writel ( efab, ®, GM_MAX_FLEN_REG_MAC );
767 /* FIFO configuration register 0 */
768 EFAB_POPULATE_DWORD_5 ( reg,
774 efab->op->mac_writel ( efab, ®, GMF_CFG0_REG_MAC );
777 /* FIFO configuration register 1 */
778 EFAB_POPULATE_DWORD_2 ( reg,
779 GMF_CFGFRTH, params->gmf_cfgfrth,
780 GMF_CFGXOFFRTX, 0xffff );
781 efab->op->mac_writel ( efab, ®, GMF_CFG1_REG_MAC );
784 /* FIFO configuration register 2 */
785 EFAB_POPULATE_DWORD_2 ( reg,
786 GMF_CFGHWM, params->gmf_cfghwm,
787 GMF_CFGLWM, params->gmf_cfglwm );
788 efab->op->mac_writel ( efab, ®, GMF_CFG2_REG_MAC );
791 /* FIFO configuration register 3 */
792 EFAB_POPULATE_DWORD_2 ( reg,
793 GMF_CFGHWMFT, params->gmf_cfghwmft,
794 GMF_CFGFTTH, params->gmf_cfgftth );
795 efab->op->mac_writel ( efab, ®, GMF_CFG3_REG_MAC );
798 /* FIFO configuration register 4 */
799 EFAB_POPULATE_DWORD_1 ( reg, GMF_HSTFLTRFRM_PAUSE, 1 );
800 efab->op->mac_writel ( efab, ®, GMF_CFG4_REG_MAC );
803 /* FIFO configuration register 5 */
804 bytemode = ( efab->link_options & LPA_1000 ) ? 1 : 0;
805 half_duplex = ( efab->link_options & LPA_DUPLEX ) ? 0 : 1;
806 efab->op->mac_readl ( efab, ®, GMF_CFG5_REG_MAC );
807 EFAB_SET_DWORD_FIELD ( reg, GMF_CFGBYTMODE, bytemode );
808 EFAB_SET_DWORD_FIELD ( reg, GMF_CFGHDPLX, half_duplex );
809 EFAB_SET_DWORD_FIELD ( reg, GMF_HSTDRPLT64, half_duplex );
810 EFAB_SET_DWORD_FIELD ( reg, GMF_HSTFLTRFRMDC_PAUSE, 0 );
811 efab->op->mac_writel ( efab, ®, GMF_CFG5_REG_MAC );
815 EFAB_POPULATE_DWORD_4 ( reg,
816 GM_HWADDR_5, efab->mac_addr[5],
817 GM_HWADDR_4, efab->mac_addr[4],
818 GM_HWADDR_3, efab->mac_addr[3],
819 GM_HWADDR_2, efab->mac_addr[2] );
820 efab->op->mac_writel ( efab, ®, GM_ADR1_REG_MAC );
822 EFAB_POPULATE_DWORD_2 ( reg,
823 GM_HWADDR_1, efab->mac_addr[1],
824 GM_HWADDR_0, efab->mac_addr[0] );
825 efab->op->mac_writel ( efab, ®, GM_ADR2_REG_MAC );
830 * Wait for GMII access to complete
833 static int mentormac_gmii_wait ( struct efab_nic *efab ) {
835 efab_dword_t indicator;
837 for ( count = 0 ; count < 1000 ; count++ ) {
839 efab->op->mac_readl ( efab, &indicator,
840 GM_MII_MGMT_IND_REG_MAC );
841 if ( EFAB_DWORD_FIELD ( indicator, GM_MGMT_BUSY ) == 0 )
844 printf ( "Timed out waiting for GMII\n" );
849 * Write a GMII register
852 static void mentormac_mdio_write ( struct efab_nic *efab, int phy_id,
853 int location, int value ) {
857 EFAB_TRACE ( "Writing GMII %d register %02x with %04x\n", phy_id,
860 /* Mentor MAC connects both PHYs to MAC 0 */
861 save_port = efab->port;
864 /* Check MII not currently being accessed */
865 if ( ! mentormac_gmii_wait ( efab ) )
868 /* Write the address register */
869 EFAB_POPULATE_DWORD_2 ( reg,
870 GM_MGMT_PHY_ADDR, phy_id,
871 GM_MGMT_REG_ADDR, location );
872 efab->op->mac_writel ( efab, ®, GM_MII_MGMT_ADR_REG_MAC );
876 EFAB_POPULATE_DWORD_1 ( reg, GM_MGMT_CTL, value );
877 efab->op->mac_writel ( efab, ®, GM_MII_MGMT_CTL_REG_MAC );
879 /* Wait for data to be written */
880 mentormac_gmii_wait ( efab );
883 /* Restore efab->port */
884 efab->port = save_port;
888 * Read a GMII register
891 static int mentormac_mdio_read ( struct efab_nic *efab, int phy_id,
897 /* Mentor MAC connects both PHYs to MAC 0 */
898 save_port = efab->port;
901 /* Check MII not currently being accessed */
902 if ( ! mentormac_gmii_wait ( efab ) )
905 /* Write the address register */
906 EFAB_POPULATE_DWORD_2 ( reg,
907 GM_MGMT_PHY_ADDR, phy_id,
908 GM_MGMT_REG_ADDR, location );
909 efab->op->mac_writel ( efab, ®, GM_MII_MGMT_ADR_REG_MAC );
912 /* Request data to be read */
913 EFAB_POPULATE_DWORD_1 ( reg, GM_MGMT_RD_CYC, 1 );
914 efab->op->mac_writel ( efab, ®, GM_MII_MGMT_CMD_REG_MAC );
916 /* Wait for data to be become available */
917 if ( mentormac_gmii_wait ( efab ) ) {
919 efab->op->mac_readl ( efab, ®, GM_MII_MGMT_STAT_REG_MAC );
920 value = EFAB_DWORD_FIELD ( reg, GM_MGMT_STAT );
921 EFAB_TRACE ( "Read from GMII %d register %02x, got %04x\n",
922 phy_id, location, value );
925 /* Signal completion */
926 EFAB_ZERO_DWORD ( reg );
927 efab->op->mac_writel ( efab, ®, GM_MII_MGMT_CMD_REG_MAC );
931 /* Restore efab->port */
932 efab->port = save_port;
937 /**************************************************************************
941 **************************************************************************
944 /** Control and General Status */
945 #define EF1_CTR_GEN_STATUS0_REG 0x0
946 #define EF1_MASTER_EVENTS_LBN 12
947 #define EF1_MASTER_EVENTS_WIDTH 1
948 #define EF1_TX_ENGINE_EN_LBN 19
949 #define EF1_TX_ENGINE_EN_WIDTH 1
950 #define EF1_RX_ENGINE_EN_LBN 18
951 #define EF1_RX_ENGINE_EN_WIDTH 1
952 #define EF1_LB_RESET_LBN 3
953 #define EF1_LB_RESET_WIDTH 1
954 #define EF1_MAC_RESET_LBN 2
955 #define EF1_MAC_RESET_WIDTH 1
956 #define EF1_CAM_ENABLE_LBN 1
957 #define EF1_CAM_ENABLE_WIDTH 1
960 #define EF1_IRQ_SRC_REG 0x0008
963 #define EF1_IRQ_MASK_REG 0x000c
964 #define EF1_IRQ_PHY1_LBN 11
965 #define EF1_IRQ_PHY1_WIDTH 1
966 #define EF1_IRQ_PHY0_LBN 10
967 #define EF1_IRQ_PHY0_WIDTH 1
968 #define EF1_IRQ_SERR_LBN 7
969 #define EF1_IRQ_SERR_WIDTH 1
970 #define EF1_IRQ_EVQ_LBN 3
971 #define EF1_IRQ_EVQ_WIDTH 1
973 /** Event generation */
974 #define EF1_EVT3_REG 0x38
977 #define EF1_EEPROM_REG 0x0040
979 /** Control register 2 */
980 #define EF1_CTL2_REG 0x4c
981 #define EF1_MEM_MAP_4MB_LBN 11
982 #define EF1_MEM_MAP_4MB_WIDTH 1
983 #define EF1_EV_INTR_CLR_WRITE_LBN 6
984 #define EF1_EV_INTR_CLR_WRITE_WIDTH 1
985 #define EF1_SW_RESET_LBN 2
986 #define EF1_SW_RESET_WIDTH 1
987 #define EF1_INTR_AFTER_EVENT_LBN 1
988 #define EF1_INTR_AFTER_EVENT_WIDTH 1
991 #define EF1_EVENT_FIFO_REG 0x50
993 /** Event FIFO count */
994 #define EF1_EVENT_FIFO_COUNT_REG 0x5c
995 #define EF1_EV_COUNT_LBN 0
996 #define EF1_EV_COUNT_WIDTH 16
998 /** TX DMA control and status */
999 #define EF1_DMA_TX_CSR_REG 0x80
1000 #define EF1_DMA_TX_CSR_CHAIN_EN_LBN 8
1001 #define EF1_DMA_TX_CSR_CHAIN_EN_WIDTH 1
1002 #define EF1_DMA_TX_CSR_ENABLE_LBN 4
1003 #define EF1_DMA_TX_CSR_ENABLE_WIDTH 1
1004 #define EF1_DMA_TX_CSR_INT_EN_LBN 0
1005 #define EF1_DMA_TX_CSR_INT_EN_WIDTH 1
1007 /** RX DMA control and status */
1008 #define EF1_DMA_RX_CSR_REG 0xa0
1009 #define EF1_DMA_RX_ABOVE_1GB_EN_LBN 6
1010 #define EF1_DMA_RX_ABOVE_1GB_EN_WIDTH 1
1011 #define EF1_DMA_RX_BELOW_1MB_EN_LBN 5
1012 #define EF1_DMA_RX_BELOW_1MB_EN_WIDTH 1
1013 #define EF1_DMA_RX_CSR_ENABLE_LBN 0
1014 #define EF1_DMA_RX_CSR_ENABLE_WIDTH 1
1016 /** Level 5 watermark register (in MAC space) */
1017 #define EF1_GMF_L5WM_REG_MAC 0x20
1018 #define EF1_L5WM_LBN 0
1019 #define EF1_L5WM_WIDTH 32
1022 #define EF1_GM_MAC_CLK_REG 0x112000
1023 #define EF1_GM_PORT0_MAC_CLK_LBN 0
1024 #define EF1_GM_PORT0_MAC_CLK_WIDTH 1
1025 #define EF1_GM_PORT1_MAC_CLK_LBN 1
1026 #define EF1_GM_PORT1_MAC_CLK_WIDTH 1
1028 /** TX descriptor FIFO */
1029 #define EF1_TX_DESC_FIFO 0x141000
1030 #define EF1_TX_KER_EVQ_LBN 80
1031 #define EF1_TX_KER_EVQ_WIDTH 12
1032 #define EF1_TX_KER_IDX_LBN 64
1033 #define EF1_TX_KER_IDX_WIDTH 16
1034 #define EF1_TX_KER_MODE_LBN 63
1035 #define EF1_TX_KER_MODE_WIDTH 1
1036 #define EF1_TX_KER_PORT_LBN 60
1037 #define EF1_TX_KER_PORT_WIDTH 1
1038 #define EF1_TX_KER_CONT_LBN 56
1039 #define EF1_TX_KER_CONT_WIDTH 1
1040 #define EF1_TX_KER_BYTE_CNT_LBN 32
1041 #define EF1_TX_KER_BYTE_CNT_WIDTH 24
1042 #define EF1_TX_KER_BUF_ADR_LBN 0
1043 #define EF1_TX_KER_BUF_ADR_WIDTH 32
1045 /** TX descriptor FIFO flush */
1046 #define EF1_TX_DESC_FIFO_FLUSH 0x141ffc
1048 /** RX descriptor FIFO */
1049 #define EF1_RX_DESC_FIFO 0x145000
1050 #define EF1_RX_KER_EVQ_LBN 48
1051 #define EF1_RX_KER_EVQ_WIDTH 12
1052 #define EF1_RX_KER_IDX_LBN 32
1053 #define EF1_RX_KER_IDX_WIDTH 16
1054 #define EF1_RX_KER_BUF_ADR_LBN 0
1055 #define EF1_RX_KER_BUF_ADR_WIDTH 32
1057 /** RX descriptor FIFO flush */
1058 #define EF1_RX_DESC_FIFO_FLUSH 0x145ffc
1061 #define EF1_CAM_BASE 0x1c0000
1062 #define EF1_CAM_WTF_DOES_THIS_DO_LBN 0
1063 #define EF1_CAM_WTF_DOES_THIS_DO_WIDTH 32
1065 /** Event queue pointers */
1066 #define EF1_EVQ_PTR_BASE 0x260000
1067 #define EF1_EVQ_SIZE_LBN 29
1068 #define EF1_EVQ_SIZE_WIDTH 2
1069 #define EF1_EVQ_SIZE_4K 3
1070 #define EF1_EVQ_SIZE_2K 2
1071 #define EF1_EVQ_SIZE_1K 1
1072 #define EF1_EVQ_SIZE_512 0
1073 #define EF1_EVQ_BUF_BASE_ID_LBN 0
1074 #define EF1_EVQ_BUF_BASE_ID_WIDTH 29
1077 #define EF1002_MAC_REGBANK 0x110000
1078 #define EF1002_MAC_REGBANK_SIZE 0x1000
1079 #define EF1002_MAC_REG_SIZE 0x08
1081 /** Offset of a MAC register within EF1002 */
1082 #define EF1002_MAC_REG( efab, mac_reg ) \
1083 ( EF1002_MAC_REGBANK + \
1084 ( (efab)->port * EF1002_MAC_REGBANK_SIZE ) + \
1085 ( (mac_reg) * EF1002_MAC_REG_SIZE ) )
1087 /* Event queue entries */
1088 #define EF1_EV_CODE_LBN 20
1089 #define EF1_EV_CODE_WIDTH 8
1090 #define EF1_RX_EV_DECODE 0x01
1091 #define EF1_TX_EV_DECODE 0x02
1092 #define EF1_DRV_GEN_EV_DECODE 0x0f
1094 /* Receive events */
1095 #define EF1_RX_EV_LEN_LBN 48
1096 #define EF1_RX_EV_LEN_WIDTH 16
1097 #define EF1_RX_EV_PORT_LBN 17
1098 #define EF1_RX_EV_PORT_WIDTH 3
1099 #define EF1_RX_EV_OK_LBN 16
1100 #define EF1_RX_EV_OK_WIDTH 1
1101 #define EF1_RX_EV_IDX_LBN 0
1102 #define EF1_RX_EV_IDX_WIDTH 16
1104 /* Transmit events */
1105 #define EF1_TX_EV_PORT_LBN 17
1106 #define EF1_TX_EV_PORT_WIDTH 3
1107 #define EF1_TX_EV_OK_LBN 16
1108 #define EF1_TX_EV_OK_WIDTH 1
1109 #define EF1_TX_EV_IDX_LBN 0
1110 #define EF1_TX_EV_IDX_WIDTH 16
1113 * Write dword to EF1002 register
1116 static inline void ef1002_writel ( struct efab_nic *efab, efab_dword_t *value,
1117 unsigned int reg ) {
1118 EFAB_REGDUMP ( "Writing register %x with " EFAB_DWORD_FMT "\n",
1119 reg, EFAB_DWORD_VAL ( *value ) );
1120 writel ( value->u32[0], efab->membase + reg );
1124 * Read dword from an EF1002 register
1127 static inline void ef1002_readl ( struct efab_nic *efab, efab_dword_t *value,
1128 unsigned int reg ) {
1129 value->u32[0] = readl ( efab->membase + reg );
1130 EFAB_REGDUMP ( "Read from register %x, got " EFAB_DWORD_FMT "\n",
1131 reg, EFAB_DWORD_VAL ( *value ) );
1135 * Read dword from an EF1002 register, silently
1138 static inline void ef1002_readl_silent ( struct efab_nic *efab,
1139 efab_dword_t *value,
1140 unsigned int reg ) {
1141 value->u32[0] = readl ( efab->membase + reg );
1148 static void ef1002_get_membase ( struct efab_nic *efab ) {
1149 unsigned long membase_phys;
1151 membase_phys = pci_bar_start ( efab->pci, PCI_BASE_ADDRESS_0 );
1152 efab->membase = ioremap ( membase_phys, 0x800000 );
1155 /** PCI registers to backup/restore over a device reset */
1156 static const unsigned int efab_pci_reg_addr[] = {
1157 PCI_COMMAND, 0x0c /* PCI_CACHE_LINE_SIZE */,
1158 PCI_BASE_ADDRESS_0, PCI_BASE_ADDRESS_1, PCI_BASE_ADDRESS_2,
1159 PCI_BASE_ADDRESS_3, PCI_ROM_ADDRESS, PCI_INTERRUPT_LINE,
1161 /** Number of registers in efab_pci_reg_addr */
1162 #define EFAB_NUM_PCI_REG \
1163 ( sizeof ( efab_pci_reg_addr ) / sizeof ( efab_pci_reg_addr[0] ) )
1164 /** PCI configuration space backup */
1165 struct efab_pci_reg {
1166 uint32_t reg[EFAB_NUM_PCI_REG];
1173 static int ef1002_reset ( struct efab_nic *efab ) {
1174 struct efab_pci_reg pci_reg;
1175 struct pci_device *pci_dev = efab->pci;
1180 /* Back up PCI configuration registers */
1181 for ( i = 0 ; i < EFAB_NUM_PCI_REG ; i++ ) {
1182 pci_read_config_dword ( pci_dev, efab_pci_reg_addr[i],
1186 /* Reset the whole device. */
1187 EFAB_POPULATE_DWORD_1 ( reg, EF1_SW_RESET, 1 );
1188 ef1002_writel ( efab, ®, EF1_CTL2_REG );
1191 /* Restore PCI configuration space */
1192 for ( i = 0 ; i < EFAB_NUM_PCI_REG ; i++ ) {
1193 pci_write_config_dword ( pci_dev, efab_pci_reg_addr[i],
1197 /* Verify PCI configuration space */
1198 for ( i = 0 ; i < EFAB_NUM_PCI_REG ; i++ ) {
1199 pci_read_config_dword ( pci_dev, efab_pci_reg_addr[i], &tmp );
1200 if ( tmp != pci_reg.reg[i] ) {
1201 printf ( "PCI restore failed on register %02x "
1202 "(is %08x, should be %08x); reboot\n",
1203 i, tmp, pci_reg.reg[i] );
1208 /* Verify device reset complete */
1209 ef1002_readl ( efab, ®, EF1_CTR_GEN_STATUS0_REG );
1210 if ( EFAB_DWORD_IS_ALL_ONES ( reg ) ) {
1211 printf ( "Reset failed\n" );
1222 static int ef1002_init_nic ( struct efab_nic *efab ) {
1226 /* No idea what CAM is, but the 'datasheet' says that we have
1227 * to write these values in at start of day
1229 EFAB_POPULATE_DWORD_1 ( reg, EF1_CAM_WTF_DOES_THIS_DO, 0x6 );
1230 ef1002_writel ( efab, ®, EF1_CAM_BASE + 0x20018 );
1232 EFAB_POPULATE_DWORD_1 ( reg, EF1_CAM_WTF_DOES_THIS_DO, 0x01000000 );
1233 ef1002_writel ( efab, ®, EF1_CAM_BASE + 0x00018 );
1236 /* General control register 0 */
1237 ef1002_readl ( efab, ®, EF1_CTR_GEN_STATUS0_REG );
1238 EFAB_SET_DWORD_FIELD ( reg, EF1_MASTER_EVENTS, 0 );
1239 EFAB_SET_DWORD_FIELD ( reg, EF1_CAM_ENABLE, 1 );
1240 ef1002_writel ( efab, ®, EF1_CTR_GEN_STATUS0_REG );
1243 /* General control register 2 */
1244 ef1002_readl ( efab, ®, EF1_CTL2_REG );
1245 EFAB_SET_DWORD_FIELD ( reg, EF1_INTR_AFTER_EVENT, 1 );
1246 EFAB_SET_DWORD_FIELD ( reg, EF1_EV_INTR_CLR_WRITE, 0 );
1247 EFAB_SET_DWORD_FIELD ( reg, EF1_MEM_MAP_4MB, 0 );
1248 ef1002_writel ( efab, ®, EF1_CTL2_REG );
1252 ef1002_readl ( efab, ®, EF1_DMA_RX_CSR_REG );
1253 EFAB_SET_DWORD_FIELD ( reg, EF1_DMA_RX_CSR_ENABLE, 1 );
1254 EFAB_SET_DWORD_FIELD ( reg, EF1_DMA_RX_BELOW_1MB_EN, 1 );
1255 EFAB_SET_DWORD_FIELD ( reg, EF1_DMA_RX_ABOVE_1GB_EN, 1 );
1256 ef1002_writel ( efab, ®, EF1_DMA_RX_CSR_REG );
1260 ef1002_readl ( efab, ®, EF1_DMA_TX_CSR_REG );
1261 EFAB_SET_DWORD_FIELD ( reg, EF1_DMA_TX_CSR_CHAIN_EN, 1 );
1262 EFAB_SET_DWORD_FIELD ( reg, EF1_DMA_TX_CSR_ENABLE, 0 /* ?? */ );
1263 EFAB_SET_DWORD_FIELD ( reg, EF1_DMA_TX_CSR_INT_EN, 0 /* ?? */ );
1264 ef1002_writel ( efab, ®, EF1_DMA_TX_CSR_REG );
1267 /* Flush descriptor queues */
1268 EFAB_ZERO_DWORD ( reg );
1269 ef1002_writel ( efab, ®, EF1_RX_DESC_FIFO_FLUSH );
1270 ef1002_writel ( efab, ®, EF1_TX_DESC_FIFO_FLUSH );
1274 /* Reset both MACs */
1275 save_port = efab->port;
1277 mentormac_reset ( efab, 1 );
1279 mentormac_reset ( efab, 1 );
1281 /* Reset both PHYs */
1282 ef1002_readl ( efab, ®, EF1_CTR_GEN_STATUS0_REG );
1283 EFAB_SET_DWORD_FIELD ( reg, EF1_MAC_RESET, 1 );
1284 ef1002_writel ( efab, ®, EF1_CTR_GEN_STATUS0_REG );
1286 EFAB_SET_DWORD_FIELD ( reg, EF1_MAC_RESET, 0 );
1287 ef1002_writel ( efab, ®, EF1_CTR_GEN_STATUS0_REG );
1290 /* Take MACs out of reset */
1292 mentormac_reset ( efab, 0 );
1294 mentormac_reset ( efab, 0 );
1295 efab->port = save_port;
1297 /* Give PHY time to wake up. It takes a while. */
1304 * Read MAC address from EEPROM
1307 static int ef1002_read_eeprom ( struct efab_nic *efab ) {
1308 return efab_eeprom_read_mac ( efab->membase + EF1_EEPROM_REG,
1312 /** RX descriptor */
1313 typedef efab_qword_t ef1002_rx_desc_t;
1316 * Build RX descriptor
1319 static void ef1002_build_rx_desc ( struct efab_nic *efab,
1320 struct efab_rx_buf *rx_buf ) {
1321 ef1002_rx_desc_t rxd;
1323 EFAB_POPULATE_QWORD_3 ( rxd,
1325 EF1_RX_KER_IDX, rx_buf->id,
1327 virt_to_bus ( rx_buf->addr ) );
1328 ef1002_writel ( efab, &rxd.dword[0], EF1_RX_DESC_FIFO + 0 );
1329 ef1002_writel ( efab, &rxd.dword[1], EF1_RX_DESC_FIFO + 4 );
1334 * Update RX descriptor write pointer
1337 static void ef1002_notify_rx_desc ( struct efab_nic *efab __unused ) {
1341 /** TX descriptor */
1342 typedef efab_oword_t ef1002_tx_desc_t;
1345 * Build TX descriptor
1348 static void ef1002_build_tx_desc ( struct efab_nic *efab,
1349 struct efab_tx_buf *tx_buf ) {
1350 ef1002_tx_desc_t txd;
1352 EFAB_POPULATE_OWORD_7 ( txd,
1354 EF1_TX_KER_IDX, tx_buf->id,
1355 EF1_TX_KER_MODE, 0 /* IP mode */,
1356 EF1_TX_KER_PORT, efab->port,
1358 EF1_TX_KER_BYTE_CNT, tx_buf->len,
1360 virt_to_bus ( tx_buf->addr ) );
1362 ef1002_writel ( efab, &txd.dword[0], EF1_TX_DESC_FIFO + 0 );
1363 ef1002_writel ( efab, &txd.dword[1], EF1_TX_DESC_FIFO + 4 );
1364 ef1002_writel ( efab, &txd.dword[2], EF1_TX_DESC_FIFO + 8 );
1369 * Update TX descriptor write pointer
1372 static void ef1002_notify_tx_desc ( struct efab_nic *efab __unused ) {
1377 typedef efab_qword_t ef1002_event_t;
1380 * Retrieve event from event queue
1383 static int ef1002_fetch_event ( struct efab_nic *efab,
1384 struct efab_event *event ) {
1389 /* Check event FIFO depth */
1390 ef1002_readl_silent ( efab, ®, EF1_EVENT_FIFO_COUNT_REG );
1391 words = EFAB_DWORD_FIELD ( reg, EF1_EV_COUNT );
1395 /* Read event data */
1396 ef1002_readl ( efab, ®, EF1_EVENT_FIFO_REG );
1397 DBG ( "Event is " EFAB_DWORD_FMT "\n", EFAB_DWORD_VAL ( reg ) );
1400 ev_code = EFAB_DWORD_FIELD ( reg, EF1_EV_CODE );
1401 switch ( ev_code ) {
1402 case EF1_TX_EV_DECODE:
1403 event->type = EFAB_EV_TX;
1405 case EF1_RX_EV_DECODE:
1406 event->type = EFAB_EV_RX;
1407 event->rx_id = EFAB_DWORD_FIELD ( reg, EF1_RX_EV_IDX );
1408 /* RX len not available via event FIFO */
1409 event->rx_len = ETH_FRAME_LEN;
1412 printf ( "Unknown event type %d\n", ev_code );
1413 event->type = EFAB_EV_NONE;
1416 /* Clear any pending interrupts */
1417 ef1002_readl ( efab, ®, EF1_IRQ_SRC_REG );
1423 * Enable/disable interrupts
1426 static void ef1002_mask_irq ( struct efab_nic *efab, int enabled ) {
1427 efab_dword_t irq_mask;
1429 EFAB_POPULATE_DWORD_2 ( irq_mask,
1430 EF1_IRQ_SERR, enabled,
1431 EF1_IRQ_EVQ, enabled );
1432 ef1002_writel ( efab, &irq_mask, EF1_IRQ_MASK_REG );
1436 * Generate interrupt
1439 static void ef1002_generate_irq ( struct efab_nic *efab ) {
1440 ef1002_event_t test_event;
1442 EFAB_POPULATE_QWORD_1 ( test_event,
1443 EF1_EV_CODE, EF1_DRV_GEN_EV_DECODE );
1444 ef1002_writel ( efab, &test_event.dword[0], EF1_EVT3_REG );
1448 * Write dword to an EF1002 MAC register
1451 static void ef1002_mac_writel ( struct efab_nic *efab,
1452 efab_dword_t *value, unsigned int mac_reg ) {
1453 ef1002_writel ( efab, value, EF1002_MAC_REG ( efab, mac_reg ) );
1457 * Read dword from an EF1002 MAC register
1460 static void ef1002_mac_readl ( struct efab_nic *efab,
1461 efab_dword_t *value, unsigned int mac_reg ) {
1462 ef1002_readl ( efab, value, EF1002_MAC_REG ( efab, mac_reg ) );
1469 static int ef1002_init_mac ( struct efab_nic *efab ) {
1470 static struct efab_mentormac_parameters ef1002_mentormac_params = {
1471 .gmf_cfgfrth = 0x13,
1472 .gmf_cfgftth = 0x10,
1473 .gmf_cfghwmft = 0x555,
1478 unsigned int mac_clk;
1480 /* Initialise PHY */
1481 alaska_init ( efab );
1483 /* Initialise MAC */
1484 mentormac_init ( efab, &ef1002_mentormac_params );
1486 /* Write Level 5 watermark register */
1487 EFAB_POPULATE_DWORD_1 ( reg, EF1_L5WM, 0x10040000 );
1488 efab->op->mac_writel ( efab, ®, EF1_GMF_L5WM_REG_MAC );
1491 /* Set MAC clock speed */
1492 ef1002_readl ( efab, ®, EF1_GM_MAC_CLK_REG );
1493 mac_clk = ( efab->link_options & LPA_1000 ) ? 0 : 1;
1494 if ( efab->port == 0 ) {
1495 EFAB_SET_DWORD_FIELD ( reg, EF1_GM_PORT0_MAC_CLK, mac_clk );
1497 EFAB_SET_DWORD_FIELD ( reg, EF1_GM_PORT1_MAC_CLK, mac_clk );
1499 ef1002_writel ( efab, ®, EF1_GM_MAC_CLK_REG );
1506 static void ef1002_mdio_write ( struct efab_nic *efab, int location,
1508 mentormac_mdio_write ( efab, efab->port + 2, location, value );
1512 static int ef1002_mdio_read ( struct efab_nic *efab, int location ) {
1513 return mentormac_mdio_read ( efab, efab->port + 2, location );
1516 static struct efab_operations ef1002_operations = {
1517 .get_membase = ef1002_get_membase,
1518 .reset = ef1002_reset,
1519 .init_nic = ef1002_init_nic,
1520 .read_eeprom = ef1002_read_eeprom,
1521 .build_rx_desc = ef1002_build_rx_desc,
1522 .notify_rx_desc = ef1002_notify_rx_desc,
1523 .build_tx_desc = ef1002_build_tx_desc,
1524 .notify_tx_desc = ef1002_notify_tx_desc,
1525 .fetch_event = ef1002_fetch_event,
1526 .mask_irq = ef1002_mask_irq,
1527 .generate_irq = ef1002_generate_irq,
1528 .mac_writel = ef1002_mac_writel,
1529 .mac_readl = ef1002_mac_readl,
1530 .init_mac = ef1002_init_mac,
1531 .mdio_write = ef1002_mdio_write,
1532 .mdio_read = ef1002_mdio_read,
1535 /**************************************************************************
1539 **************************************************************************
1542 /* I/O BAR address register */
1543 #define FCN_IOM_IND_ADR_REG 0x0
1545 /* I/O BAR data register */
1546 #define FCN_IOM_IND_DAT_REG 0x4
1548 /* Interrupt enable register */
1549 #define FCN_INT_EN_REG_KER 0x0010
1550 #define FCN_MEM_PERR_INT_EN_KER_LBN 5
1551 #define FCN_MEM_PERR_INT_EN_KER_WIDTH 1
1552 #define FCN_KER_INT_CHAR_LBN 4
1553 #define FCN_KER_INT_CHAR_WIDTH 1
1554 #define FCN_KER_INT_KER_LBN 3
1555 #define FCN_KER_INT_KER_WIDTH 1
1556 #define FCN_ILL_ADR_ERR_INT_EN_KER_LBN 2
1557 #define FCN_ILL_ADR_ERR_INT_EN_KER_WIDTH 1
1558 #define FCN_SRM_PERR_INT_EN_KER_LBN 1
1559 #define FCN_SRM_PERR_INT_EN_KER_WIDTH 1
1560 #define FCN_DRV_INT_EN_KER_LBN 0
1561 #define FCN_DRV_INT_EN_KER_WIDTH 1
1563 /* Interrupt status register */
1564 #define FCN_INT_ADR_REG_KER 0x0030
1565 #define FCN_INT_ADR_KER_LBN 0
1566 #define FCN_INT_ADR_KER_WIDTH EFAB_DMA_TYPE_WIDTH ( 64 )
1568 /* Interrupt acknowledge register */
1569 #define FCN_INT_ACK_KER_REG 0x0050
1571 /* SPI host command register */
1572 #define FCN_EE_SPI_HCMD_REG_KER 0x0100
1573 #define FCN_EE_SPI_HCMD_CMD_EN_LBN 31
1574 #define FCN_EE_SPI_HCMD_CMD_EN_WIDTH 1
1575 #define FCN_EE_WR_TIMER_ACTIVE_LBN 28
1576 #define FCN_EE_WR_TIMER_ACTIVE_WIDTH 1
1577 #define FCN_EE_SPI_HCMD_SF_SEL_LBN 24
1578 #define FCN_EE_SPI_HCMD_SF_SEL_WIDTH 1
1579 #define FCN_EE_SPI_EEPROM 0
1580 #define FCN_EE_SPI_FLASH 1
1581 #define FCN_EE_SPI_HCMD_DABCNT_LBN 16
1582 #define FCN_EE_SPI_HCMD_DABCNT_WIDTH 5
1583 #define FCN_EE_SPI_HCMD_READ_LBN 15
1584 #define FCN_EE_SPI_HCMD_READ_WIDTH 1
1585 #define FCN_EE_SPI_READ 1
1586 #define FCN_EE_SPI_WRITE 0
1587 #define FCN_EE_SPI_HCMD_DUBCNT_LBN 12
1588 #define FCN_EE_SPI_HCMD_DUBCNT_WIDTH 2
1589 #define FCN_EE_SPI_HCMD_ADBCNT_LBN 8
1590 #define FCN_EE_SPI_HCMD_ADBCNT_WIDTH 2
1591 #define FCN_EE_SPI_HCMD_ENC_LBN 0
1592 #define FCN_EE_SPI_HCMD_ENC_WIDTH 8
1594 /* SPI host address register */
1595 #define FCN_EE_SPI_HADR_REG_KER 0x0110
1596 #define FCN_EE_SPI_HADR_DUBYTE_LBN 24
1597 #define FCN_EE_SPI_HADR_DUBYTE_WIDTH 8
1598 #define FCN_EE_SPI_HADR_ADR_LBN 0
1599 #define FCN_EE_SPI_HADR_ADR_WIDTH 24
1601 /* SPI host data register */
1602 #define FCN_EE_SPI_HDATA_REG_KER 0x0120
1603 #define FCN_EE_SPI_HDATA3_LBN 96
1604 #define FCN_EE_SPI_HDATA3_WIDTH 32
1605 #define FCN_EE_SPI_HDATA2_LBN 64
1606 #define FCN_EE_SPI_HDATA2_WIDTH 32
1607 #define FCN_EE_SPI_HDATA1_LBN 32
1608 #define FCN_EE_SPI_HDATA1_WIDTH 32
1609 #define FCN_EE_SPI_HDATA0_LBN 0
1610 #define FCN_EE_SPI_HDATA0_WIDTH 32
1612 /* GPIO control register */
1613 #define FCN_GPIO_CTL_REG_KER 0x0210
1614 #define FCN_FLASH_PRESENT_LBN 7
1615 #define FCN_FLASH_PRESENT_WIDTH 1
1616 #define FCN_EEPROM_PRESENT_LBN 6
1617 #define FCN_EEPROM_PRESENT_WIDTH 1
1619 /* Global control register */
1620 #define FCN_GLB_CTL_REG_KER 0x0220
1621 #define FCN_EXT_PHY_RST_CTL_LBN 63
1622 #define FCN_EXT_PHY_RST_CTL_WIDTH 1
1623 #define FCN_PCIE_SD_RST_CTL_LBN 61
1624 #define FCN_PCIE_SD_RST_CTL_WIDTH 1
1625 #define FCN_PCIX_RST_CTL_LBN 60
1626 #define FCN_PCIX_RST_CTL_WIDTH 1
1627 #define FCN_RST_EXT_PHY_LBN 31
1628 #define FCN_RST_EXT_PHY_WIDTH 1
1629 #define FCN_INT_RST_DUR_LBN 4
1630 #define FCN_INT_RST_DUR_WIDTH 3
1631 #define FCN_EXT_PHY_RST_DUR_LBN 1
1632 #define FCN_EXT_PHY_RST_DUR_WIDTH 3
1633 #define FCN_SWRST_LBN 0
1634 #define FCN_SWRST_WIDTH 1
1635 #define FCN_INCLUDE_IN_RESET 0
1636 #define FCN_EXCLUDE_FROM_RESET 1
1638 /* Timer table for kernel access */
1639 #define FCN_TIMER_CMD_REG_KER 0x420
1640 #define FCN_TIMER_MODE_LBN 12
1641 #define FCN_TIMER_MODE_WIDTH 2
1642 #define FCN_TIMER_MODE_DIS 0
1643 #define FCN_TIMER_MODE_INT_HLDOFF 1
1644 #define FCN_TIMER_VAL_LBN 0
1645 #define FCN_TIMER_VAL_WIDTH 12
1647 /* SRAM receive descriptor cache configuration register */
1648 #define FCN_SRM_RX_DC_CFG_REG_KER 0x610
1649 #define FCN_SRM_RX_DC_BASE_ADR_LBN 0
1650 #define FCN_SRM_RX_DC_BASE_ADR_WIDTH 21
1652 /* SRAM transmit descriptor cache configuration register */
1653 #define FCN_SRM_TX_DC_CFG_REG_KER 0x620
1654 #define FCN_SRM_TX_DC_BASE_ADR_LBN 0
1655 #define FCN_SRM_TX_DC_BASE_ADR_WIDTH 21
1657 /* Receive filter control register */
1658 #define FCN_RX_FILTER_CTL_REG_KER 0x810
1659 #define FCN_NUM_KER_LBN 24
1660 #define FCN_NUM_KER_WIDTH 2
1662 /* Receive descriptor update register */
1663 #define FCN_RX_DESC_UPD_REG_KER 0x0830
1664 #define FCN_RX_DESC_WPTR_LBN 96
1665 #define FCN_RX_DESC_WPTR_WIDTH 12
1666 #define FCN_RX_DESC_UPD_REG_KER_DWORD ( FCN_RX_DESC_UPD_REG_KER + 12 )
1667 #define FCN_RX_DESC_WPTR_DWORD_LBN 0
1668 #define FCN_RX_DESC_WPTR_DWORD_WIDTH 12
1670 /* Receive descriptor cache configuration register */
1671 #define FCN_RX_DC_CFG_REG_KER 0x840
1672 #define FCN_RX_DC_SIZE_LBN 0
1673 #define FCN_RX_DC_SIZE_WIDTH 2
1675 /* Transmit descriptor update register */
1676 #define FCN_TX_DESC_UPD_REG_KER 0x0a10
1677 #define FCN_TX_DESC_WPTR_LBN 96
1678 #define FCN_TX_DESC_WPTR_WIDTH 12
1679 #define FCN_TX_DESC_UPD_REG_KER_DWORD ( FCN_TX_DESC_UPD_REG_KER + 12 )
1680 #define FCN_TX_DESC_WPTR_DWORD_LBN 0
1681 #define FCN_TX_DESC_WPTR_DWORD_WIDTH 12
1683 /* Transmit descriptor cache configuration register */
1684 #define FCN_TX_DC_CFG_REG_KER 0xa20
1685 #define FCN_TX_DC_SIZE_LBN 0
1686 #define FCN_TX_DC_SIZE_WIDTH 2
1688 /* PHY management transmit data register */
1689 #define FCN_MD_TXD_REG_KER 0xc00
1690 #define FCN_MD_TXD_LBN 0
1691 #define FCN_MD_TXD_WIDTH 16
1693 /* PHY management receive data register */
1694 #define FCN_MD_RXD_REG_KER 0xc10
1695 #define FCN_MD_RXD_LBN 0
1696 #define FCN_MD_RXD_WIDTH 16
1698 /* PHY management configuration & status register */
1699 #define FCN_MD_CS_REG_KER 0xc20
1700 #define FCN_MD_GC_LBN 4
1701 #define FCN_MD_GC_WIDTH 1
1702 #define FCN_MD_RIC_LBN 2
1703 #define FCN_MD_RIC_WIDTH 1
1704 #define FCN_MD_WRC_LBN 0
1705 #define FCN_MD_WRC_WIDTH 1
1707 /* PHY management PHY address register */
1708 #define FCN_MD_PHY_ADR_REG_KER 0xc30
1709 #define FCN_MD_PHY_ADR_LBN 0
1710 #define FCN_MD_PHY_ADR_WIDTH 16
1712 /* PHY management ID register */
1713 #define FCN_MD_ID_REG_KER 0xc40
1714 #define FCN_MD_PRT_ADR_LBN 11
1715 #define FCN_MD_PRT_ADR_WIDTH 5
1716 #define FCN_MD_DEV_ADR_LBN 6
1717 #define FCN_MD_DEV_ADR_WIDTH 5
1719 /* PHY management status & mask register */
1720 #define FCN_MD_STAT_REG_KER 0xc50
1721 #define FCN_MD_BSY_LBN 0
1722 #define FCN_MD_BSY_WIDTH 1
1724 /* Port 0 and 1 MAC control registers */
1725 #define FCN_MAC0_CTRL_REG_KER 0xc80
1726 #define FCN_MAC1_CTRL_REG_KER 0xc90
1727 #define FCN_MAC_XOFF_VAL_LBN 16
1728 #define FCN_MAC_XOFF_VAL_WIDTH 16
1729 #define FCN_MAC_BCAD_ACPT_LBN 4
1730 #define FCN_MAC_BCAD_ACPT_WIDTH 1
1731 #define FCN_MAC_UC_PROM_LBN 3
1732 #define FCN_MAC_UC_PROM_WIDTH 1
1733 #define FCN_MAC_LINK_STATUS_LBN 2
1734 #define FCN_MAC_LINK_STATUS_WIDTH 1
1735 #define FCN_MAC_SPEED_LBN 0
1736 #define FCN_MAC_SPEED_WIDTH 2
1738 /* XGMAC global configuration - port 0*/
1739 #define FCN_XM_GLB_CFG_REG_P0_KER 0x1220
1740 #define FCN_XM_RX_STAT_EN_LBN 11
1741 #define FCN_XM_RX_STAT_EN_WIDTH 1
1742 #define FCN_XM_TX_STAT_EN_LBN 10
1743 #define FCN_XM_TX_STAT_EN_WIDTH 1
1744 #define FCN_XM_CUT_THRU_MODE_LBN 7
1745 #define FCN_XM_CUT_THRU_MODE_WIDTH 1
1746 #define FCN_XM_RX_JUMBO_MODE_LBN 6
1747 #define FCN_XM_RX_JUMBO_MODE_WIDTH 1
1749 /* XGMAC transmit configuration - port 0 */
1750 #define FCN_XM_TX_CFG_REG_P0_KER 0x1230
1751 #define FCN_XM_IPG_LBN 16
1752 #define FCN_XM_IPG_WIDTH 4
1753 #define FCN_XM_WTF_DOES_THIS_DO_LBN 9
1754 #define FCN_XM_WTF_DOES_THIS_DO_WIDTH 1
1755 #define FCN_XM_TXCRC_LBN 8
1756 #define FCN_XM_TXCRC_WIDTH 1
1757 #define FCN_XM_AUTO_PAD_LBN 5
1758 #define FCN_XM_AUTO_PAD_WIDTH 1
1759 #define FCN_XM_TX_PRMBL_LBN 2
1760 #define FCN_XM_TX_PRMBL_WIDTH 1
1761 #define FCN_XM_TXEN_LBN 1
1762 #define FCN_XM_TXEN_WIDTH 1
1764 /* XGMAC receive configuration - port 0 */
1765 #define FCN_XM_RX_CFG_REG_P0_KER 0x1240
1766 #define FCN_XM_PASS_CRC_ERR_LBN 25
1767 #define FCN_XM_PASS_CRC_ERR_WIDTH 1
1768 #define FCN_XM_AUTO_DEPAD_LBN 8
1769 #define FCN_XM_AUTO_DEPAD_WIDTH 1
1770 #define FCN_XM_RXEN_LBN 1
1771 #define FCN_XM_RXEN_WIDTH 1
1773 /* Receive descriptor pointer table */
1774 #define FCN_RX_DESC_PTR_TBL_KER 0x11800
1775 #define FCN_RX_DESCQ_BUF_BASE_ID_LBN 36
1776 #define FCN_RX_DESCQ_BUF_BASE_ID_WIDTH 20
1777 #define FCN_RX_DESCQ_EVQ_ID_LBN 24
1778 #define FCN_RX_DESCQ_EVQ_ID_WIDTH 12
1779 #define FCN_RX_DESCQ_OWNER_ID_LBN 10
1780 #define FCN_RX_DESCQ_OWNER_ID_WIDTH 14
1781 #define FCN_RX_DESCQ_SIZE_LBN 3
1782 #define FCN_RX_DESCQ_SIZE_WIDTH 2
1783 #define FCN_RX_DESCQ_SIZE_4K 3
1784 #define FCN_RX_DESCQ_SIZE_2K 2
1785 #define FCN_RX_DESCQ_SIZE_1K 1
1786 #define FCN_RX_DESCQ_SIZE_512 0
1787 #define FCN_RX_DESCQ_TYPE_LBN 2
1788 #define FCN_RX_DESCQ_TYPE_WIDTH 1
1789 #define FCN_RX_DESCQ_JUMBO_LBN 1
1790 #define FCN_RX_DESCQ_JUMBO_WIDTH 1
1791 #define FCN_RX_DESCQ_EN_LBN 0
1792 #define FCN_RX_DESCQ_EN_WIDTH 1
1794 /* Transmit descriptor pointer table */
1795 #define FCN_TX_DESC_PTR_TBL_KER 0x11900
1796 #define FCN_TX_DESCQ_EN_LBN 88
1797 #define FCN_TX_DESCQ_EN_WIDTH 1
1798 #define FCN_TX_DESCQ_BUF_BASE_ID_LBN 36
1799 #define FCN_TX_DESCQ_BUF_BASE_ID_WIDTH 20
1800 #define FCN_TX_DESCQ_EVQ_ID_LBN 24
1801 #define FCN_TX_DESCQ_EVQ_ID_WIDTH 12
1802 #define FCN_TX_DESCQ_OWNER_ID_LBN 10
1803 #define FCN_TX_DESCQ_OWNER_ID_WIDTH 14
1804 #define FCN_TX_DESCQ_SIZE_LBN 3
1805 #define FCN_TX_DESCQ_SIZE_WIDTH 2
1806 #define FCN_TX_DESCQ_SIZE_4K 3
1807 #define FCN_TX_DESCQ_SIZE_2K 2
1808 #define FCN_TX_DESCQ_SIZE_1K 1
1809 #define FCN_TX_DESCQ_SIZE_512 0
1810 #define FCN_TX_DESCQ_TYPE_LBN 1
1811 #define FCN_TX_DESCQ_TYPE_WIDTH 2
1812 #define FCN_TX_DESCQ_FLUSH_LBN 0
1813 #define FCN_TX_DESCQ_FLUSH_WIDTH 1
1815 /* Event queue pointer */
1816 #define FCN_EVQ_PTR_TBL_KER 0x11a00
1817 #define FCN_EVQ_EN_LBN 23
1818 #define FCN_EVQ_EN_WIDTH 1
1819 #define FCN_EVQ_SIZE_LBN 20
1820 #define FCN_EVQ_SIZE_WIDTH 3
1821 #define FCN_EVQ_SIZE_32K 6
1822 #define FCN_EVQ_SIZE_16K 5
1823 #define FCN_EVQ_SIZE_8K 4
1824 #define FCN_EVQ_SIZE_4K 3
1825 #define FCN_EVQ_SIZE_2K 2
1826 #define FCN_EVQ_SIZE_1K 1
1827 #define FCN_EVQ_SIZE_512 0
1828 #define FCN_EVQ_BUF_BASE_ID_LBN 0
1829 #define FCN_EVQ_BUF_BASE_ID_WIDTH 20
1831 /* Event queue read pointer */
1832 #define FCN_EVQ_RPTR_REG_KER 0x11b00
1833 #define FCN_EVQ_RPTR_LBN 0
1834 #define FCN_EVQ_RPTR_WIDTH 14
1835 #define FCN_EVQ_RPTR_REG_KER_DWORD ( FCN_EVQ_RPTR_REG_KER + 0 )
1836 #define FCN_EVQ_RPTR_DWORD_LBN 0
1837 #define FCN_EVQ_RPTR_DWORD_WIDTH 14
1839 /* Special buffer descriptors */
1840 #define FCN_BUF_FULL_TBL_KER 0x18000
1841 #define FCN_IP_DAT_BUF_SIZE_LBN 50
1842 #define FCN_IP_DAT_BUF_SIZE_WIDTH 1
1843 #define FCN_IP_DAT_BUF_SIZE_8K 1
1844 #define FCN_IP_DAT_BUF_SIZE_4K 0
1845 #define FCN_BUF_ADR_FBUF_LBN 14
1846 #define FCN_BUF_ADR_FBUF_WIDTH 34
1847 #define FCN_BUF_OWNER_ID_FBUF_LBN 0
1848 #define FCN_BUF_OWNER_ID_FBUF_WIDTH 14
1851 #define FALCON_MAC_REGBANK 0xe00
1852 #define FALCON_MAC_REGBANK_SIZE 0x200
1853 #define FALCON_MAC_REG_SIZE 0x10
1855 /** Offset of a MAC register within Falcon */
1856 #define FALCON_MAC_REG( efab, mac_reg ) \
1857 ( FALCON_MAC_REGBANK + \
1858 ( (efab)->port * FALCON_MAC_REGBANK_SIZE ) + \
1859 ( (mac_reg) * FALCON_MAC_REG_SIZE ) )
1860 #define FCN_MAC_DATA_LBN 0
1861 #define FCN_MAC_DATA_WIDTH 32
1863 /* Transmit descriptor */
1864 #define FCN_TX_KER_PORT_LBN 63
1865 #define FCN_TX_KER_PORT_WIDTH 1
1866 #define FCN_TX_KER_BYTE_CNT_LBN 48
1867 #define FCN_TX_KER_BYTE_CNT_WIDTH 14
1868 #define FCN_TX_KER_BUF_ADR_LBN 0
1869 #define FCN_TX_KER_BUF_ADR_WIDTH EFAB_DMA_TYPE_WIDTH ( 46 )
1871 /* Receive descriptor */
1872 #define FCN_RX_KER_BUF_SIZE_LBN 48
1873 #define FCN_RX_KER_BUF_SIZE_WIDTH 14
1874 #define FCN_RX_KER_BUF_ADR_LBN 0
1875 #define FCN_RX_KER_BUF_ADR_WIDTH EFAB_DMA_TYPE_WIDTH ( 46 )
1877 /* Event queue entries */
1878 #define FCN_EV_CODE_LBN 60
1879 #define FCN_EV_CODE_WIDTH 4
1880 #define FCN_RX_IP_EV_DECODE 0
1881 #define FCN_TX_IP_EV_DECODE 2
1882 #define FCN_DRIVER_EV_DECODE 5
1884 /* Receive events */
1885 #define FCN_RX_PORT_LBN 30
1886 #define FCN_RX_PORT_WIDTH 1
1887 #define FCN_RX_EV_BYTE_CNT_LBN 16
1888 #define FCN_RX_EV_BYTE_CNT_WIDTH 14
1889 #define FCN_RX_EV_DESC_PTR_LBN 0
1890 #define FCN_RX_EV_DESC_PTR_WIDTH 12
1892 /* Transmit events */
1893 #define FCN_TX_EV_DESC_PTR_LBN 0
1894 #define FCN_TX_EV_DESC_PTR_WIDTH 12
1896 /* Fixed special buffer numbers to use */
1897 #define FALCON_EVQ_ID 0
1898 #define FALCON_TXD_ID 1
1899 #define FALCON_RXD_ID 2
1901 #if FALCON_USE_IO_BAR
1903 /* Write dword via the I/O BAR */
1904 static inline void _falcon_writel ( struct efab_nic *efab, uint32_t value,
1905 unsigned int reg ) {
1906 outl ( reg, efab->iobase + FCN_IOM_IND_ADR_REG );
1907 outl ( value, efab->iobase + FCN_IOM_IND_DAT_REG );
1910 /* Read dword via the I/O BAR */
1911 static inline uint32_t _falcon_readl ( struct efab_nic *efab,
1912 unsigned int reg ) {
1913 outl ( reg, efab->iobase + FCN_IOM_IND_ADR_REG );
1914 return inl ( efab->iobase + FCN_IOM_IND_DAT_REG );
1917 #else /* FALCON_USE_IO_BAR */
1919 #define _falcon_writel( efab, value, reg ) \
1920 writel ( (value), (efab)->membase + (reg) )
1921 #define _falcon_readl( efab, reg ) readl ( (efab)->membase + (reg) )
1923 #endif /* FALCON_USE_IO_BAR */
1926 * Write to a Falcon register
1929 static inline void falcon_write ( struct efab_nic *efab, efab_oword_t *value,
1930 unsigned int reg ) {
1932 EFAB_REGDUMP ( "Writing register %x with " EFAB_OWORD_FMT "\n",
1933 reg, EFAB_OWORD_VAL ( *value ) );
1935 _falcon_writel ( efab, value->u32[0], reg + 0 );
1936 _falcon_writel ( efab, value->u32[1], reg + 4 );
1937 _falcon_writel ( efab, value->u32[2], reg + 8 );
1938 _falcon_writel ( efab, value->u32[3], reg + 12 );
1943 * Write to Falcon SRAM
1946 static inline void falcon_write_sram ( struct efab_nic *efab,
1947 efab_qword_t *value,
1948 unsigned int index ) {
1949 unsigned int reg = ( FCN_BUF_FULL_TBL_KER +
1950 ( index * sizeof ( *value ) ) );
1952 EFAB_REGDUMP ( "Writing SRAM register %x with " EFAB_QWORD_FMT "\n",
1953 reg, EFAB_QWORD_VAL ( *value ) );
1955 _falcon_writel ( efab, value->u32[0], reg + 0 );
1956 _falcon_writel ( efab, value->u32[1], reg + 4 );
1961 * Write dword to Falcon register that allows partial writes
1964 static inline void falcon_writel ( struct efab_nic *efab, efab_dword_t *value,
1965 unsigned int reg ) {
1966 EFAB_REGDUMP ( "Writing partial register %x with " EFAB_DWORD_FMT "\n",
1967 reg, EFAB_DWORD_VAL ( *value ) );
1968 _falcon_writel ( efab, value->u32[0], reg );
1972 * Read from a Falcon register
1975 static inline void falcon_read ( struct efab_nic *efab, efab_oword_t *value,
1976 unsigned int reg ) {
1977 value->u32[0] = _falcon_readl ( efab, reg + 0 );
1978 value->u32[1] = _falcon_readl ( efab, reg + 4 );
1979 value->u32[2] = _falcon_readl ( efab, reg + 8 );
1980 value->u32[3] = _falcon_readl ( efab, reg + 12 );
1982 EFAB_REGDUMP ( "Read from register %x, got " EFAB_OWORD_FMT "\n",
1983 reg, EFAB_OWORD_VAL ( *value ) );
1987 * Read from Falcon SRAM
1990 static inline void falcon_read_sram ( struct efab_nic *efab,
1991 efab_qword_t *value,
1992 unsigned int index ) {
1993 unsigned int reg = ( FCN_BUF_FULL_TBL_KER +
1994 ( index * sizeof ( *value ) ) );
1996 value->u32[0] = _falcon_readl ( efab, reg + 0 );
1997 value->u32[1] = _falcon_readl ( efab, reg + 4 );
1998 EFAB_REGDUMP ( "Read from SRAM register %x, got " EFAB_QWORD_FMT "\n",
1999 reg, EFAB_QWORD_VAL ( *value ) );
2003 * Read dword from a portion of a Falcon register
2006 static inline void falcon_readl ( struct efab_nic *efab, efab_dword_t *value,
2007 unsigned int reg ) {
2008 value->u32[0] = _falcon_readl ( efab, reg );
2009 EFAB_REGDUMP ( "Read from register %x, got " EFAB_DWORD_FMT "\n",
2010 reg, EFAB_DWORD_VAL ( *value ) );
2014 * Verified write to Falcon SRAM
2017 static inline void falcon_write_sram_verify ( struct efab_nic *efab,
2018 efab_qword_t *value,
2019 unsigned int index ) {
2020 efab_qword_t verify;
2022 falcon_write_sram ( efab, value, index );
2024 falcon_read_sram ( efab, &verify, index );
2025 if ( memcmp ( &verify, value, sizeof ( verify ) ) != 0 ) {
2026 printf ( "SRAM index %x failure: wrote " EFAB_QWORD_FMT
2027 " got " EFAB_QWORD_FMT "\n", index,
2028 EFAB_QWORD_VAL ( *value ),
2029 EFAB_QWORD_VAL ( verify ) );
2037 static void falcon_get_membase ( struct efab_nic *efab ) {
2038 unsigned long membase_phys;
2040 membase_phys = pci_bar_start ( efab->pci, PCI_BASE_ADDRESS_2 );
2041 efab->membase = ioremap ( membase_phys, 0x20000 );
2044 #define FCN_DUMP_REG( efab, _reg ) do { \
2046 falcon_read ( efab, ®, _reg ); \
2047 printf ( #_reg " = " EFAB_OWORD_FMT "\n", \
2048 EFAB_OWORD_VAL ( reg ) ); \
2051 #define FCN_DUMP_MAC_REG( efab, _mac_reg ) do { \
2053 efab->op->mac_readl ( efab, ®, _mac_reg ); \
2054 printf ( #_mac_reg " = " EFAB_DWORD_FMT "\n", \
2055 EFAB_DWORD_VAL ( reg ) ); \
2059 * Dump register contents (for debugging)
2061 * Marked as static inline so that it will not be compiled in if not
2064 static inline void falcon_dump_regs ( struct efab_nic *efab ) {
2065 FCN_DUMP_REG ( efab, FCN_INT_EN_REG_KER );
2066 FCN_DUMP_REG ( efab, FCN_INT_ADR_REG_KER );
2067 FCN_DUMP_REG ( efab, FCN_GLB_CTL_REG_KER );
2068 FCN_DUMP_REG ( efab, FCN_TIMER_CMD_REG_KER );
2069 FCN_DUMP_REG ( efab, FCN_SRM_RX_DC_CFG_REG_KER );
2070 FCN_DUMP_REG ( efab, FCN_SRM_TX_DC_CFG_REG_KER );
2071 FCN_DUMP_REG ( efab, FCN_RX_FILTER_CTL_REG_KER );
2072 FCN_DUMP_REG ( efab, FCN_RX_DC_CFG_REG_KER );
2073 FCN_DUMP_REG ( efab, FCN_TX_DC_CFG_REG_KER );
2074 FCN_DUMP_REG ( efab, FCN_MAC0_CTRL_REG_KER );
2075 FCN_DUMP_REG ( efab, FCN_MAC1_CTRL_REG_KER );
2076 FCN_DUMP_REG ( efab, FCN_XM_GLB_CFG_REG_P0_KER );
2077 FCN_DUMP_REG ( efab, FCN_XM_TX_CFG_REG_P0_KER );
2078 FCN_DUMP_REG ( efab, FCN_XM_RX_CFG_REG_P0_KER );
2079 FCN_DUMP_REG ( efab, FCN_RX_DESC_PTR_TBL_KER );
2080 FCN_DUMP_REG ( efab, FCN_TX_DESC_PTR_TBL_KER );
2081 FCN_DUMP_REG ( efab, FCN_EVQ_PTR_TBL_KER );
2082 FCN_DUMP_MAC_REG ( efab, GM_CFG1_REG_MAC );
2083 FCN_DUMP_MAC_REG ( efab, GM_CFG2_REG_MAC );
2084 FCN_DUMP_MAC_REG ( efab, GM_MAX_FLEN_REG_MAC );
2085 FCN_DUMP_MAC_REG ( efab, GM_MII_MGMT_CFG_REG_MAC );
2086 FCN_DUMP_MAC_REG ( efab, GM_ADR1_REG_MAC );
2087 FCN_DUMP_MAC_REG ( efab, GM_ADR2_REG_MAC );
2088 FCN_DUMP_MAC_REG ( efab, GMF_CFG0_REG_MAC );
2089 FCN_DUMP_MAC_REG ( efab, GMF_CFG1_REG_MAC );
2090 FCN_DUMP_MAC_REG ( efab, GMF_CFG2_REG_MAC );
2091 FCN_DUMP_MAC_REG ( efab, GMF_CFG3_REG_MAC );
2092 FCN_DUMP_MAC_REG ( efab, GMF_CFG4_REG_MAC );
2093 FCN_DUMP_MAC_REG ( efab, GMF_CFG5_REG_MAC );
2097 * Create special buffer
2100 static void falcon_create_special_buffer ( struct efab_nic *efab,
2101 void *addr, unsigned int index ) {
2102 efab_qword_t buf_desc;
2103 unsigned long dma_addr;
2105 memset ( addr, 0, 4096 );
2106 dma_addr = virt_to_bus ( addr );
2107 EFAB_ASSERT ( ( dma_addr & ( EFAB_BUF_ALIGN - 1 ) ) == 0 );
2108 EFAB_POPULATE_QWORD_3 ( buf_desc,
2109 FCN_IP_DAT_BUF_SIZE, FCN_IP_DAT_BUF_SIZE_4K,
2110 FCN_BUF_ADR_FBUF, ( dma_addr >> 12 ),
2111 FCN_BUF_OWNER_ID_FBUF, 0 );
2112 falcon_write_sram_verify ( efab, &buf_desc, index );
2116 * Update event queue read pointer
2119 static void falcon_eventq_read_ack ( struct efab_nic *efab ) {
2122 EFAB_ASSERT ( efab->eventq_read_ptr < EFAB_EVQ_SIZE );
2124 EFAB_POPULATE_DWORD_1 ( reg, FCN_EVQ_RPTR_DWORD,
2125 efab->eventq_read_ptr );
2126 falcon_writel ( efab, ®, FCN_EVQ_RPTR_REG_KER_DWORD );
2133 static int falcon_reset ( struct efab_nic *efab ) {
2134 efab_oword_t glb_ctl_reg_ker;
2136 /* Initiate software reset */
2137 EFAB_POPULATE_OWORD_5 ( glb_ctl_reg_ker,
2138 FCN_EXT_PHY_RST_CTL, FCN_EXCLUDE_FROM_RESET,
2139 FCN_PCIE_SD_RST_CTL, FCN_EXCLUDE_FROM_RESET,
2140 FCN_PCIX_RST_CTL, FCN_EXCLUDE_FROM_RESET,
2141 FCN_INT_RST_DUR, 0x7 /* datasheet */,
2143 falcon_write ( efab, &glb_ctl_reg_ker, FCN_GLB_CTL_REG_KER );
2145 /* Allow 20ms for reset */
2148 /* Check for device reset complete */
2149 falcon_read ( efab, &glb_ctl_reg_ker, FCN_GLB_CTL_REG_KER );
2150 if ( EFAB_OWORD_FIELD ( glb_ctl_reg_ker, FCN_SWRST ) != 0 ) {
2151 printf ( "Reset failed\n" );
2162 static int falcon_init_nic ( struct efab_nic *efab ) {
2164 efab_dword_t timer_cmd;
2166 /* Set up TX and RX descriptor caches in SRAM */
2167 EFAB_POPULATE_OWORD_1 ( reg, FCN_SRM_TX_DC_BASE_ADR,
2168 0x130000 /* recommended in datasheet */ );
2169 falcon_write ( efab, ®, FCN_SRM_TX_DC_CFG_REG_KER );
2170 EFAB_POPULATE_OWORD_1 ( reg, FCN_TX_DC_SIZE, 2 /* 32 descriptors */ );
2171 falcon_write ( efab, ®, FCN_TX_DC_CFG_REG_KER );
2172 EFAB_POPULATE_OWORD_1 ( reg, FCN_SRM_RX_DC_BASE_ADR,
2173 0x100000 /* recommended in datasheet */ );
2174 falcon_write ( efab, ®, FCN_SRM_RX_DC_CFG_REG_KER );
2175 EFAB_POPULATE_OWORD_1 ( reg, FCN_RX_DC_SIZE, 2 /* 32 descriptors */ );
2176 falcon_write ( efab, ®, FCN_RX_DC_CFG_REG_KER );
2178 /* Set number of RSS CPUs */
2179 EFAB_POPULATE_OWORD_1 ( reg, FCN_NUM_KER, 0 );
2180 falcon_write ( efab, ®, FCN_RX_FILTER_CTL_REG_KER );
2184 mentormac_reset ( efab, 1 );
2185 /* Take MAC out of reset */
2186 mentormac_reset ( efab, 0 );
2188 /* Set up event queue */
2189 falcon_create_special_buffer ( efab, efab->eventq, FALCON_EVQ_ID );
2190 EFAB_POPULATE_OWORD_3 ( reg,
2192 FCN_EVQ_SIZE, FCN_EVQ_SIZE_512,
2193 FCN_EVQ_BUF_BASE_ID, FALCON_EVQ_ID );
2194 falcon_write ( efab, ®, FCN_EVQ_PTR_TBL_KER );
2197 /* Set timer register */
2198 EFAB_POPULATE_DWORD_2 ( timer_cmd,
2199 FCN_TIMER_MODE, FCN_TIMER_MODE_DIS,
2201 falcon_writel ( efab, &timer_cmd, FCN_TIMER_CMD_REG_KER );
2204 /* Initialise event queue read pointer */
2205 falcon_eventq_read_ack ( efab );
2207 /* Set up TX descriptor ring */
2208 falcon_create_special_buffer ( efab, efab->txd, FALCON_TXD_ID );
2209 EFAB_POPULATE_OWORD_5 ( reg,
2211 FCN_TX_DESCQ_BUF_BASE_ID, FALCON_TXD_ID,
2212 FCN_TX_DESCQ_EVQ_ID, 0,
2213 FCN_TX_DESCQ_SIZE, FCN_TX_DESCQ_SIZE_512,
2214 FCN_TX_DESCQ_TYPE, 0 /* kernel queue */ );
2215 falcon_write ( efab, ®, FCN_TX_DESC_PTR_TBL_KER );
2217 /* Set up RX descriptor ring */
2218 falcon_create_special_buffer ( efab, efab->rxd, FALCON_RXD_ID );
2219 EFAB_POPULATE_OWORD_6 ( reg,
2220 FCN_RX_DESCQ_BUF_BASE_ID, FALCON_RXD_ID,
2221 FCN_RX_DESCQ_EVQ_ID, 0,
2222 FCN_RX_DESCQ_SIZE, FCN_RX_DESCQ_SIZE_512,
2223 FCN_RX_DESCQ_TYPE, 0 /* kernel queue */,
2224 FCN_RX_DESCQ_JUMBO, 1,
2225 FCN_RX_DESCQ_EN, 1 );
2226 falcon_write ( efab, ®, FCN_RX_DESC_PTR_TBL_KER );
2228 /* Program INT_ADR_REG_KER */
2229 EFAB_POPULATE_OWORD_1 ( reg,
2231 virt_to_bus ( &efab->int_ker ) );
2232 falcon_write ( efab, ®, FCN_INT_ADR_REG_KER );
2239 struct efab_spi_device {
2241 unsigned int device_id;
2242 /** Address length (in bytes) */
2243 unsigned int addr_len;
2245 unsigned int read_command;
2249 * Wait for SPI command completion
2252 static int falcon_spi_wait ( struct efab_nic *efab ) {
2259 falcon_read ( efab, ®, FCN_EE_SPI_HCMD_REG_KER );
2260 if ( EFAB_OWORD_FIELD ( reg, FCN_EE_SPI_HCMD_CMD_EN ) == 0 )
2262 } while ( ++count < 1000 );
2263 printf ( "Timed out waiting for SPI\n" );
2271 static int falcon_spi_read ( struct efab_nic *efab,
2272 struct efab_spi_device *spi,
2273 int address, void *data, unsigned int len ) {
2276 /* Program address register */
2277 EFAB_POPULATE_OWORD_1 ( reg, FCN_EE_SPI_HADR_ADR, address );
2278 falcon_write ( efab, ®, FCN_EE_SPI_HADR_REG_KER );
2280 /* Issue read command */
2281 EFAB_POPULATE_OWORD_7 ( reg,
2282 FCN_EE_SPI_HCMD_CMD_EN, 1,
2283 FCN_EE_SPI_HCMD_SF_SEL, spi->device_id,
2284 FCN_EE_SPI_HCMD_DABCNT, len,
2285 FCN_EE_SPI_HCMD_READ, FCN_EE_SPI_READ,
2286 FCN_EE_SPI_HCMD_DUBCNT, 0,
2287 FCN_EE_SPI_HCMD_ADBCNT, spi->addr_len,
2288 FCN_EE_SPI_HCMD_ENC, spi->read_command );
2289 falcon_write ( efab, ®, FCN_EE_SPI_HCMD_REG_KER );
2291 /* Wait for read to complete */
2292 if ( ! falcon_spi_wait ( efab ) )
2296 falcon_read ( efab, ®, FCN_EE_SPI_HDATA_REG_KER );
2297 memcpy ( data, ®, len );
2302 #define SPI_READ_CMD 0x03
2303 #define AT25F1024_ADDR_LEN 3
2304 #define AT25F1024_READ_CMD SPI_READ_CMD
2305 #define MC25XX640_ADDR_LEN 2
2306 #define MC25XX640_READ_CMD SPI_READ_CMD
2308 /** Falcon Flash SPI device */
2309 static struct efab_spi_device falcon_spi_flash = {
2310 .device_id = FCN_EE_SPI_FLASH,
2311 .addr_len = AT25F1024_ADDR_LEN,
2312 .read_command = AT25F1024_READ_CMD,
2315 /** Falcon EEPROM SPI device */
2316 static struct efab_spi_device falcon_spi_large_eeprom = {
2317 .device_id = FCN_EE_SPI_EEPROM,
2318 .addr_len = MC25XX640_ADDR_LEN,
2319 .read_command = MC25XX640_READ_CMD,
2322 /** Offset of MAC address within EEPROM or Flash */
2323 #define FALCON_MAC_ADDRESS_OFFSET(port) ( 0x310 + 0x08 * (port) )
2326 * Read MAC address from EEPROM
2329 static int falcon_read_eeprom ( struct efab_nic *efab ) {
2332 struct efab_spi_device *spi;
2334 /* Determine the SPI device containing the MAC address */
2335 falcon_read ( efab, ®, FCN_GPIO_CTL_REG_KER );
2336 has_flash = EFAB_OWORD_FIELD ( reg, FCN_FLASH_PRESENT );
2337 spi = has_flash ? &falcon_spi_flash : &falcon_spi_large_eeprom;
2339 return falcon_spi_read ( efab, spi,
2340 FALCON_MAC_ADDRESS_OFFSET ( efab->port ),
2341 efab->mac_addr, sizeof ( efab->mac_addr ) );
2344 /** RX descriptor */
2345 typedef efab_qword_t falcon_rx_desc_t;
2348 * Build RX descriptor
2351 static void falcon_build_rx_desc ( struct efab_nic *efab,
2352 struct efab_rx_buf *rx_buf ) {
2353 falcon_rx_desc_t *rxd;
2355 rxd = ( ( falcon_rx_desc_t * ) efab->rxd ) + rx_buf->id;
2356 EFAB_POPULATE_QWORD_2 ( *rxd,
2357 FCN_RX_KER_BUF_SIZE, EFAB_DATA_BUF_SIZE,
2359 virt_to_bus ( rx_buf->addr ) );
2363 * Update RX descriptor write pointer
2366 static void falcon_notify_rx_desc ( struct efab_nic *efab ) {
2369 EFAB_POPULATE_DWORD_1 ( reg, FCN_RX_DESC_WPTR_DWORD,
2370 efab->rx_write_ptr );
2371 falcon_writel ( efab, ®, FCN_RX_DESC_UPD_REG_KER_DWORD );
2374 /** TX descriptor */
2375 typedef efab_qword_t falcon_tx_desc_t;
2378 * Build TX descriptor
2381 static void falcon_build_tx_desc ( struct efab_nic *efab,
2382 struct efab_tx_buf *tx_buf ) {
2383 falcon_rx_desc_t *txd;
2385 txd = ( ( falcon_rx_desc_t * ) efab->txd ) + tx_buf->id;
2386 EFAB_POPULATE_QWORD_3 ( *txd,
2387 FCN_TX_KER_PORT, efab->port,
2388 FCN_TX_KER_BYTE_CNT, tx_buf->len,
2390 virt_to_bus ( tx_buf->addr ) );
2394 * Update TX descriptor write pointer
2397 static void falcon_notify_tx_desc ( struct efab_nic *efab ) {
2400 EFAB_POPULATE_DWORD_1 ( reg, FCN_TX_DESC_WPTR_DWORD,
2401 efab->tx_write_ptr );
2402 falcon_writel ( efab, ®, FCN_TX_DESC_UPD_REG_KER_DWORD );
2406 typedef efab_qword_t falcon_event_t;
2409 * Retrieve event from event queue
2412 static int falcon_fetch_event ( struct efab_nic *efab,
2413 struct efab_event *event ) {
2414 falcon_event_t *evt;
2418 /* Check for event */
2419 evt = ( ( falcon_event_t * ) efab->eventq ) + efab->eventq_read_ptr;
2420 if ( EFAB_QWORD_IS_ZERO ( *evt ) ) {
2425 DBG ( "Event is " EFAB_QWORD_FMT "\n", EFAB_QWORD_VAL ( *evt ) );
2428 ev_code = EFAB_QWORD_FIELD ( *evt, FCN_EV_CODE );
2429 switch ( ev_code ) {
2430 case FCN_TX_IP_EV_DECODE:
2431 event->type = EFAB_EV_TX;
2433 case FCN_RX_IP_EV_DECODE:
2434 event->type = EFAB_EV_RX;
2435 event->rx_id = EFAB_QWORD_FIELD ( *evt, FCN_RX_EV_DESC_PTR );
2436 event->rx_len = EFAB_QWORD_FIELD ( *evt, FCN_RX_EV_BYTE_CNT );
2437 rx_port = EFAB_QWORD_FIELD ( *evt, FCN_RX_PORT );
2438 if ( rx_port != efab->port ) {
2439 /* Ignore packets on the wrong port. We can't
2440 * just set event->type = EFAB_EV_NONE,
2441 * because then the descriptor ring won't get
2447 case FCN_DRIVER_EV_DECODE:
2448 /* Ignore start-of-day events */
2449 event->type = EFAB_EV_NONE;
2452 printf ( "Unknown event type %d\n", ev_code );
2453 event->type = EFAB_EV_NONE;
2456 /* Clear event and any pending interrupts */
2457 EFAB_ZERO_QWORD ( *evt );
2458 falcon_writel ( efab, 0, FCN_INT_ACK_KER_REG );
2461 /* Increment and update event queue read pointer */
2462 efab->eventq_read_ptr = ( ( efab->eventq_read_ptr + 1 )
2464 falcon_eventq_read_ack ( efab );
2470 * Enable/disable/generate interrupt
2473 static inline void falcon_interrupts ( struct efab_nic *efab, int enabled,
2475 efab_oword_t int_en_reg_ker;
2477 EFAB_POPULATE_OWORD_2 ( int_en_reg_ker,
2478 FCN_KER_INT_KER, force,
2479 FCN_DRV_INT_EN_KER, enabled );
2480 falcon_write ( efab, &int_en_reg_ker, FCN_INT_EN_REG_KER );
2484 * Enable/disable interrupts
2487 static void falcon_mask_irq ( struct efab_nic *efab, int enabled ) {
2488 falcon_interrupts ( efab, enabled, 0 );
2490 /* Events won't trigger interrupts until we do this */
2491 falcon_eventq_read_ack ( efab );
2496 * Generate interrupt
2499 static void falcon_generate_irq ( struct efab_nic *efab ) {
2500 falcon_interrupts ( efab, 1, 1 );
2504 * Write dword to a Falcon MAC register
2507 static void falcon_mac_writel ( struct efab_nic *efab,
2508 efab_dword_t *value, unsigned int mac_reg ) {
2511 EFAB_POPULATE_OWORD_1 ( temp, FCN_MAC_DATA,
2512 EFAB_DWORD_FIELD ( *value, FCN_MAC_DATA ) );
2513 falcon_write ( efab, &temp, FALCON_MAC_REG ( efab, mac_reg ) );
2517 * Read dword from a Falcon MAC register
2520 static void falcon_mac_readl ( struct efab_nic *efab, efab_dword_t *value,
2521 unsigned int mac_reg ) {
2524 falcon_read ( efab, &temp, FALCON_MAC_REG ( efab, mac_reg ) );
2525 EFAB_POPULATE_DWORD_1 ( *value, FCN_MAC_DATA,
2526 EFAB_OWORD_FIELD ( temp, FCN_MAC_DATA ) );
2533 static int falcon_init_mac ( struct efab_nic *efab ) {
2534 static struct efab_mentormac_parameters falcon_mentormac_params = {
2535 .gmf_cfgfrth = 0x12,
2536 .gmf_cfgftth = 0x08,
2537 .gmf_cfghwmft = 0x1c,
2544 /* Initialise PHY */
2545 alaska_init ( efab );
2547 /* Initialise MAC */
2548 mentormac_init ( efab, &falcon_mentormac_params );
2550 /* Configure the Falcon MAC wrapper */
2551 EFAB_POPULATE_OWORD_4 ( reg,
2552 FCN_XM_RX_JUMBO_MODE, 0,
2553 FCN_XM_CUT_THRU_MODE, 0,
2554 FCN_XM_TX_STAT_EN, 1,
2555 FCN_XM_RX_STAT_EN, 1);
2556 falcon_write ( efab, ®, FCN_XM_GLB_CFG_REG_P0_KER );
2558 EFAB_POPULATE_OWORD_6 ( reg,
2563 FCN_XM_WTF_DOES_THIS_DO, 1,
2565 falcon_write ( efab, ®, FCN_XM_TX_CFG_REG_P0_KER );
2567 EFAB_POPULATE_OWORD_3 ( reg,
2569 FCN_XM_AUTO_DEPAD, 1,
2570 FCN_XM_PASS_CRC_ERR, 1 );
2571 falcon_write ( efab, ®, FCN_XM_RX_CFG_REG_P0_KER );
2573 #warning "10G support not yet present"
2575 if ( efab->link_options & LPA_10000 ) {
2577 } else if ( efab->link_options & LPA_1000 ) {
2579 } else if ( efab->link_options & LPA_100 ) {
2584 EFAB_POPULATE_OWORD_5 ( reg,
2585 FCN_MAC_XOFF_VAL, 0xffff /* datasheet */,
2586 FCN_MAC_BCAD_ACPT, 1,
2588 FCN_MAC_LINK_STATUS, 1,
2589 FCN_MAC_SPEED, link_speed );
2590 falcon_write ( efab, ®, ( efab->port == 0 ?
2591 FCN_MAC0_CTRL_REG_KER : FCN_MAC1_CTRL_REG_KER ) );
2597 * Wait for GMII access to complete
2600 static int falcon_gmii_wait ( struct efab_nic *efab ) {
2601 efab_oword_t md_stat;
2604 for ( count = 0 ; count < 1000 ; count++ ) {
2606 falcon_read ( efab, &md_stat, FCN_MD_STAT_REG_KER );
2607 if ( EFAB_OWORD_FIELD ( md_stat, FCN_MD_BSY ) == 0 )
2610 printf ( "Timed out waiting for GMII\n" );
2615 static void falcon_mdio_write ( struct efab_nic *efab, int location,
2617 int phy_id = efab->port + 2;
2620 #warning "10G PHY access not yet in place"
2622 EFAB_TRACE ( "Writing GMII %d register %02x with %04x\n",
2623 phy_id, location, value );
2625 /* Check MII not currently being accessed */
2626 if ( ! falcon_gmii_wait ( efab ) )
2629 /* Write the address registers */
2630 EFAB_POPULATE_OWORD_1 ( reg, FCN_MD_PHY_ADR, 0 /* phy_id ? */ );
2631 falcon_write ( efab, ®, FCN_MD_PHY_ADR_REG_KER );
2633 EFAB_POPULATE_OWORD_2 ( reg,
2634 FCN_MD_PRT_ADR, phy_id,
2635 FCN_MD_DEV_ADR, location );
2636 falcon_write ( efab, ®, FCN_MD_ID_REG_KER );
2640 EFAB_POPULATE_OWORD_1 ( reg, FCN_MD_TXD, value );
2641 falcon_write ( efab, ®, FCN_MD_TXD_REG_KER );
2643 EFAB_POPULATE_OWORD_2 ( reg,
2646 falcon_write ( efab, ®, FCN_MD_CS_REG_KER );
2649 /* Wait for data to be written */
2650 falcon_gmii_wait ( efab );
2654 static int falcon_mdio_read ( struct efab_nic *efab, int location ) {
2655 int phy_id = efab->port + 2;
2659 /* Check MII not currently being accessed */
2660 if ( ! falcon_gmii_wait ( efab ) )
2663 /* Write the address registers */
2664 EFAB_POPULATE_OWORD_1 ( reg, FCN_MD_PHY_ADR, 0 /* phy_id ? */ );
2665 falcon_write ( efab, ®, FCN_MD_PHY_ADR_REG_KER );
2667 EFAB_POPULATE_OWORD_2 ( reg,
2668 FCN_MD_PRT_ADR, phy_id,
2669 FCN_MD_DEV_ADR, location );
2670 falcon_write ( efab, ®, FCN_MD_ID_REG_KER );
2673 /* Request data to be read */
2674 EFAB_POPULATE_OWORD_2 ( reg,
2677 falcon_write ( efab, ®, FCN_MD_CS_REG_KER );
2680 /* Wait for data to become available */
2681 falcon_gmii_wait ( efab );
2684 falcon_read ( efab, ®, FCN_MD_RXD_REG_KER );
2685 value = EFAB_OWORD_FIELD ( reg, FCN_MD_RXD );
2687 EFAB_TRACE ( "Read from GMII %d register %02x, got %04x\n",
2688 phy_id, location, value );
2693 static struct efab_operations falcon_operations = {
2694 .get_membase = falcon_get_membase,
2695 .reset = falcon_reset,
2696 .init_nic = falcon_init_nic,
2697 .read_eeprom = falcon_read_eeprom,
2698 .build_rx_desc = falcon_build_rx_desc,
2699 .notify_rx_desc = falcon_notify_rx_desc,
2700 .build_tx_desc = falcon_build_tx_desc,
2701 .notify_tx_desc = falcon_notify_tx_desc,
2702 .fetch_event = falcon_fetch_event,
2703 .mask_irq = falcon_mask_irq,
2704 .generate_irq = falcon_generate_irq,
2705 .mac_writel = falcon_mac_writel,
2706 .mac_readl = falcon_mac_readl,
2707 .init_mac = falcon_init_mac,
2708 .mdio_write = falcon_mdio_write,
2709 .mdio_read = falcon_mdio_read,
2712 /**************************************************************************
2714 * Etherfabric abstraction layer
2716 **************************************************************************
2720 * Push RX buffer to RXD ring
2723 static inline void efab_push_rx_buffer ( struct efab_nic *efab,
2724 struct efab_rx_buf *rx_buf ) {
2725 /* Create RX descriptor */
2726 rx_buf->id = efab->rx_write_ptr;
2727 efab->op->build_rx_desc ( efab, rx_buf );
2729 /* Update RX write pointer */
2730 efab->rx_write_ptr = ( efab->rx_write_ptr + 1 ) % EFAB_RXD_SIZE;
2731 efab->op->notify_rx_desc ( efab );
2733 DBG ( "Added RX id %x\n", rx_buf->id );
2737 * Push TX buffer to TXD ring
2740 static inline void efab_push_tx_buffer ( struct efab_nic *efab,
2741 struct efab_tx_buf *tx_buf ) {
2742 /* Create TX descriptor */
2743 tx_buf->id = efab->tx_write_ptr;
2744 efab->op->build_tx_desc ( efab, tx_buf );
2746 /* Update TX write pointer */
2747 efab->tx_write_ptr = ( efab->tx_write_ptr + 1 ) % EFAB_TXD_SIZE;
2748 efab->op->notify_tx_desc ( efab );
2750 DBG ( "Added TX id %x\n", tx_buf->id );
2754 * Initialise MAC and wait for link up
2757 static int efab_init_mac ( struct efab_nic *efab ) {
2760 /* This can take several seconds */
2761 printf ( "Waiting for link.." );
2765 if ( ! efab->op->init_mac ( efab ) ) {
2766 printf ( "failed\n" );
2769 if ( efab->link_up ) {
2770 /* PHY init printed the message for us */
2774 } while ( ++count < 5 );
2775 printf ( "timed out\n" );
2784 static int efab_init_nic ( struct efab_nic *efab ) {
2788 if ( ! efab->op->reset ( efab ) )
2791 /* Initialise NIC */
2792 if ( ! efab->op->init_nic ( efab ) )
2795 /* Push RX descriptors */
2796 for ( i = 0 ; i < EFAB_RX_BUFS ; i++ ) {
2797 efab_push_rx_buffer ( efab, &efab->rx_bufs[i] );
2800 /* Read MAC address from EEPROM */
2801 if ( ! efab->op->read_eeprom ( efab ) )
2803 efab->mac_addr[ETH_ALEN-1] += efab->port;
2805 /* Initialise MAC and wait for link up */
2806 if ( ! efab_init_mac ( efab ) )
2812 /**************************************************************************
2814 * Etherboot interface
2816 **************************************************************************
2819 /**************************************************************************
2820 POLL - Wait for a frame
2821 ***************************************************************************/
2822 static int etherfabric_poll ( struct nic *nic, int retrieve ) {
2823 struct efab_nic *efab = nic->priv_data;
2824 struct efab_event event;
2825 static struct efab_rx_buf *rx_buf = NULL;
2828 /* Process the event queue until we hit either a packet
2829 * received event or an empty event slot.
2831 while ( ( rx_buf == NULL ) &&
2832 efab->op->fetch_event ( efab, &event ) ) {
2833 if ( event.type == EFAB_EV_TX ) {
2834 /* TX completed - mark as done */
2835 DBG ( "TX id %x complete\n",
2837 efab->tx_in_progress = 0;
2838 } else if ( event.type == EFAB_EV_RX ) {
2839 /* RX - find corresponding buffer */
2840 for ( i = 0 ; i < EFAB_RX_BUFS ; i++ ) {
2841 if ( efab->rx_bufs[i].id == event.rx_id ) {
2842 rx_buf = &efab->rx_bufs[i];
2843 rx_buf->len = event.rx_len;
2844 DBG ( "RX id %x (len %x) received\n",
2845 rx_buf->id, rx_buf->len );
2850 printf ( "Invalid RX ID %x\n", event.rx_id );
2852 } else if ( event.type == EFAB_EV_NONE ) {
2853 DBG ( "Ignorable event\n" );
2855 DBG ( "Unknown event\n" );
2859 /* If there is no packet, return 0 */
2863 /* If we don't want to retrieve it just yet, return 1 */
2867 /* Copy packet contents */
2868 nic->packetlen = rx_buf->len;
2869 memcpy ( nic->packet, rx_buf->addr, nic->packetlen );
2871 /* Give this buffer back to the NIC */
2872 efab_push_rx_buffer ( efab, rx_buf );
2874 /* Prepare to receive next packet */
2880 /**************************************************************************
2881 TRANSMIT - Transmit a frame
2882 ***************************************************************************/
2883 static void etherfabric_transmit ( struct nic *nic, const char *dest,
2884 unsigned int type, unsigned int size,
2885 const char *data ) {
2886 struct efab_nic *efab = nic->priv_data;
2887 unsigned int nstype = htons ( type );
2889 /* We can only transmit one packet at a time; a TX completion
2890 * event must be received before we can transmit the next
2891 * packet. Since there is only one static TX buffer, we don't
2892 * worry unduly about overflow, but we report it anyway.
2894 if ( efab->tx_in_progress ) {
2895 printf ( "TX overflow!\n" );
2898 /* Fill TX buffer, pad to ETH_ZLEN */
2899 memcpy ( efab->tx_buf.addr, dest, ETH_ALEN );
2900 memcpy ( efab->tx_buf.addr + ETH_ALEN, nic->node_addr, ETH_ALEN );
2901 memcpy ( efab->tx_buf.addr + 2 * ETH_ALEN, &nstype, 2 );
2902 memcpy ( efab->tx_buf.addr + ETH_HLEN, data, size );
2904 while ( size < ETH_ZLEN ) {
2905 efab->tx_buf.addr[size++] = '\0';
2907 efab->tx_buf.len = size;
2909 /* Push TX descriptor */
2910 efab_push_tx_buffer ( efab, &efab->tx_buf );
2912 /* There is no way to wait for TX complete (i.e. TX buffer
2913 * available to re-use for the next transmit) without reading
2914 * from the event queue. We therefore simply leave the TX
2915 * buffer marked as "in use" until a TX completion event
2916 * happens to be picked up by a call to etherfabric_poll().
2918 efab->tx_in_progress = 1;
2923 /**************************************************************************
2924 DISABLE - Turn off ethernet interface
2925 ***************************************************************************/
2926 static void etherfabric_disable ( struct dev *dev ) {
2927 struct nic *nic = ( struct nic * ) dev;
2928 struct efab_nic *efab = nic->priv_data;
2930 efab->op->reset ( efab );
2931 if ( efab->membase )
2932 iounmap ( efab->membase );
2935 /**************************************************************************
2936 IRQ - handle interrupts
2937 ***************************************************************************/
2938 static void etherfabric_irq ( struct nic *nic, irq_action_t action ) {
2939 struct efab_nic *efab = nic->priv_data;
2943 efab->op->mask_irq ( efab, 1 );
2946 efab->op->mask_irq ( efab, 0 );
2949 /* Force NIC to generate a receive interrupt */
2950 efab->op->generate_irq ( efab );
2957 /**************************************************************************
2958 PROBE - Look for an adapter, this routine's visible to the outside
2959 ***************************************************************************/
2960 static int etherfabric_probe ( struct dev *dev, struct pci_device *pci ) {
2961 struct nic *nic = ( struct nic * ) dev;
2962 static struct efab_nic efab;
2963 static int nic_port = 1;
2964 struct efab_buffers *buffers;
2967 /* Set up our private data structure */
2968 nic->priv_data = &efab;
2969 memset ( &efab, 0, sizeof ( efab ) );
2970 memset ( &efab_buffers, 0, sizeof ( efab_buffers ) );
2972 /* Hook in appropriate operations table. Do this early. */
2973 if ( pci->dev_id == EF1002_DEVID ) {
2974 efab.op = &ef1002_operations;
2976 efab.op = &falcon_operations;
2979 /* Initialise efab data structure */
2981 buffers = ( ( struct efab_buffers * )
2982 ( ( ( void * ) &efab_buffers ) +
2983 ( - virt_to_bus ( &efab_buffers ) ) % EFAB_BUF_ALIGN ) );
2984 efab.eventq = buffers->eventq;
2985 efab.txd = buffers->txd;
2986 efab.rxd = buffers->rxd;
2987 efab.tx_buf.addr = buffers->tx_buf;
2988 for ( i = 0 ; i < EFAB_RX_BUFS ; i++ ) {
2989 efab.rx_bufs[i].addr = buffers->rx_buf[i];
2992 /* Enable the PCI device */
2993 adjust_pci_device ( pci );
2994 nic->ioaddr = pci->ioaddr & ~3;
2995 nic->irqno = pci->irq;
2997 /* Get iobase/membase */
2998 efab.iobase = nic->ioaddr;
2999 efab.op->get_membase ( &efab );
3001 /* Switch NIC ports (i.e. try different ports on each probe) */
3002 nic_port = 1 - nic_port;
3003 efab.port = nic_port;
3005 /* Initialise hardware */
3006 if ( ! efab_init_nic ( &efab ) )
3008 memcpy ( nic->node_addr, efab.mac_addr, ETH_ALEN );
3011 printf ( "Found EtherFabric %s NIC %!\n", pci->name, nic->node_addr );
3013 /* point to NIC specific routines */
3014 dev->disable = etherfabric_disable;
3015 nic->poll = etherfabric_poll;
3016 nic->transmit = etherfabric_transmit;
3017 nic->irq = etherfabric_irq;
3022 static struct pci_id etherfabric_nics[] = {
3023 PCI_ROM(0x1924, 0xC101, "ef1002", "EtherFabric EF1002"),
3024 PCI_ROM(0x1924, 0x0703, "falcon", "EtherFabric Falcon"),
3027 static struct pci_driver etherfabric_driver __pci_driver = {
3030 .probe = etherfabric_probe,
3031 .ids = etherfabric_nics,
3032 .id_count = sizeof(etherfabric_nics)/sizeof(etherfabric_nics[0]),