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 **************************************************************************
33 #define EFAB_ASSERT(x) \
36 DBG ( "ASSERT(%s) failed at %s line %d [%s]\n", #x, \
37 __FILE__, __LINE__, __FUNCTION__ ); \
41 #define EFAB_TRACE(...)
43 #define EFAB_REGDUMP(...)
45 #define FALCON_USE_IO_BAR 1
48 * EtherFabric constants
53 #define EFAB_VENDID_LEVEL5 0x1924
54 #define FALCON_P_DEVID 0x0703 /* Temporary PCI ID */
55 #define EF1002_DEVID 0xC101
57 /**************************************************************************
61 **************************************************************************
65 * Buffers used for TX, RX and event queue
68 #define EFAB_BUF_ALIGN 4096
69 #define EFAB_DATA_BUF_SIZE 2048
70 #define EFAB_RX_BUFS 16
71 #define EFAB_RXD_SIZE 512
72 #define EFAB_TXD_SIZE 512
73 #define EFAB_EVQ_SIZE 512
78 uint8_t tx_buf[EFAB_DATA_BUF_SIZE];
79 uint8_t rx_buf[EFAB_RX_BUFS][EFAB_DATA_BUF_SIZE];
80 uint8_t padding[EFAB_BUF_ALIGN-1];
82 static struct efab_buffers efab_buffers;
98 /** Etherfabric event type */
99 enum efab_event_type {
105 /** Etherfabric event */
108 enum efab_event_type type;
116 * Etherfabric abstraction layer
120 struct efab_operations {
121 void ( * get_membase ) ( struct efab_nic *efab );
122 int ( * reset ) ( struct efab_nic *efab );
123 int ( * init_nic ) ( struct efab_nic *efab );
124 int ( * read_eeprom ) ( struct efab_nic *efab );
125 void ( * build_rx_desc ) ( struct efab_nic *efab,
126 struct efab_rx_buf *rx_buf );
127 void ( * notify_rx_desc ) ( struct efab_nic *efab );
128 void ( * build_tx_desc ) ( struct efab_nic *efab,
129 struct efab_tx_buf *tx_buf );
130 void ( * notify_tx_desc ) ( struct efab_nic *efab );
131 int ( * fetch_event ) ( struct efab_nic *efab,
132 struct efab_event *event );
133 void ( * mask_irq ) ( struct efab_nic *efab, int enabled );
134 void ( * generate_irq ) ( struct efab_nic *efab );
135 void ( * mac_writel ) ( struct efab_nic *efab, efab_dword_t *value,
136 unsigned int mac_reg );
137 void ( * mac_readl ) ( struct efab_nic *efab, efab_dword_t *value,
138 unsigned int mac_reg );
139 int ( * init_mac ) ( struct efab_nic *efab );
140 void ( * mdio_write ) ( struct efab_nic *efab, int location,
142 int ( * mdio_read ) ( struct efab_nic *efab, int location );
146 * Driver private data structure
152 struct pci_device *pci;
154 /** Operations table */
155 struct efab_operations *op;
164 uint8_t *eventq; /* Falcon only */
165 uint8_t *txd; /* Falcon only */
166 uint8_t *rxd; /* Falcon only */
167 struct efab_tx_buf tx_buf;
168 struct efab_rx_buf rx_bufs[EFAB_RX_BUFS];
170 /** Buffer pointers */
171 unsigned int eventq_read_ptr; /* Falcon only */
172 unsigned int tx_write_ptr;
173 unsigned int rx_write_ptr;
176 /** Port 0/1 on the NIC */
180 uint8_t mac_addr[ETH_ALEN];
181 /** GMII link options */
182 unsigned int link_options;
186 /** INT_REG_KER for Falcon */
187 efab_oword_t int_ker __attribute__ (( aligned ( 16 ) ));
190 /**************************************************************************
194 **************************************************************************
197 #define EFAB_EEPROM_SDA 0x80000000u
198 #define EFAB_EEPROM_SCL 0x40000000u
199 #define ARIZONA_24xx00_SLAVE 0xa0
200 #define EFAB_EEPROM_READ_SELECT ( ARIZONA_24xx00_SLAVE | 1 )
201 #define EFAB_EEPROM_WRITE_SELECT ( ARIZONA_24xx00_SLAVE | 0 )
203 static void eeprom_release ( uint32_t *eeprom_reg ) {
207 dev = readl ( eeprom_reg );
208 writel ( dev | ( EFAB_EEPROM_SDA | EFAB_EEPROM_SCL ),
213 static void eeprom_start ( uint32_t *eeprom_reg ) {
217 dev = readl ( eeprom_reg );
219 if ( ( dev & ( EFAB_EEPROM_SDA | EFAB_EEPROM_SCL ) ) !=
220 ( EFAB_EEPROM_SDA | EFAB_EEPROM_SCL ) ) {
222 writel ( dev | ( EFAB_EEPROM_SDA | EFAB_EEPROM_SCL ),
226 dev &=~ ( EFAB_EEPROM_SDA | EFAB_EEPROM_SCL );
229 writel ( dev | EFAB_EEPROM_SCL, eeprom_reg) ;
233 writel ( dev, eeprom_reg );
237 static void eeprom_stop ( uint32_t *eeprom_reg ) {
241 dev = readl ( eeprom_reg );
242 EFAB_ASSERT ( ! ( dev & EFAB_EEPROM_SCL ) );
244 if ( dev & ( EFAB_EEPROM_SDA | EFAB_EEPROM_SCL ) ) {
245 dev &=~ ( EFAB_EEPROM_SDA | EFAB_EEPROM_SCL );
247 writel ( dev, eeprom_reg );
252 dev |= EFAB_EEPROM_SCL;
253 writel ( dev, eeprom_reg );
257 dev |= EFAB_EEPROM_SDA;
258 writel ( dev, eeprom_reg );
262 static void eeprom_write ( uint32_t *eeprom_reg, unsigned char data ) {
267 dev = readl ( eeprom_reg );
269 EFAB_ASSERT ( ! ( dev & EFAB_EEPROM_SCL ) );
271 for ( i = 0 ; i < 8 ; i++, data <<= 1 ) {
273 dev |= EFAB_EEPROM_SDA;
275 dev &=~ EFAB_EEPROM_SDA;
278 writel ( dev, eeprom_reg );
282 writel ( dev | EFAB_EEPROM_SCL, eeprom_reg );
286 writel ( dev, eeprom_reg );
290 if( ! ( dev & EFAB_EEPROM_SDA ) ) {
292 writel ( dev | EFAB_EEPROM_SDA, eeprom_reg );
297 static unsigned char eeprom_read ( uint32_t *eeprom_reg ) {
298 unsigned int i, dev, rd;
299 unsigned char val = 0;
302 dev = readl ( eeprom_reg );
304 EFAB_ASSERT ( ! ( dev & EFAB_EEPROM_SCL ) );
306 if( ! ( dev & EFAB_EEPROM_SDA ) ) {
307 dev |= EFAB_EEPROM_SDA;
309 writel ( dev, eeprom_reg );
313 for( i = 0 ; i < 8 ; i++ ) {
315 writel ( dev | EFAB_EEPROM_SCL, eeprom_reg );
319 rd = readl ( eeprom_reg );
321 val = ( val << 1 ) | ( ( rd & EFAB_EEPROM_SDA ) != 0 );
324 writel ( dev, eeprom_reg );
331 static int eeprom_check_ack ( uint32_t *eeprom_reg ) {
336 dev = readl ( eeprom_reg );
337 EFAB_ASSERT ( ! ( dev & EFAB_EEPROM_SCL ) );
339 writel ( dev | EFAB_EEPROM_SCL, eeprom_reg );
343 ack = readl ( eeprom_reg ) & EFAB_EEPROM_SDA;
346 writel ( ack & ~EFAB_EEPROM_SCL, eeprom_reg );
352 static void eeprom_send_ack ( uint32_t *eeprom_reg ) {
356 dev = readl ( eeprom_reg );
357 EFAB_ASSERT ( ! ( dev & EFAB_EEPROM_SCL ) );
360 dev &= ~EFAB_EEPROM_SDA;
361 writel ( dev, eeprom_reg );
365 dev |= EFAB_EEPROM_SCL;
366 writel ( dev, eeprom_reg );
370 dev |= EFAB_EEPROM_SDA;
371 writel ( dev & ~EFAB_EEPROM_SCL, eeprom_reg );
375 static int efab_eeprom_read_mac ( uint32_t *eeprom_reg, uint8_t *mac_addr ) {
378 eeprom_start ( eeprom_reg );
380 eeprom_write ( eeprom_reg, EFAB_EEPROM_WRITE_SELECT );
381 if ( ! eeprom_check_ack ( eeprom_reg ) )
384 eeprom_write ( eeprom_reg, 0 );
385 if ( ! eeprom_check_ack ( eeprom_reg ) )
388 eeprom_stop ( eeprom_reg );
389 eeprom_start ( eeprom_reg );
391 eeprom_write ( eeprom_reg, EFAB_EEPROM_READ_SELECT );
392 if ( ! eeprom_check_ack ( eeprom_reg ) )
395 for ( i = 0 ; i < ETH_ALEN ; i++ ) {
396 mac_addr[i] = eeprom_read ( eeprom_reg );
397 eeprom_send_ack ( eeprom_reg );
400 eeprom_stop ( eeprom_reg );
402 eeprom_release ( eeprom_reg );
407 /**************************************************************************
411 **************************************************************************
415 #define MII_BMSR 0x01 /* Basic mode status register */
416 #define MII_ADVERTISE 0x04 /* Advertisement control register */
417 #define MII_LPA 0x05 /* Link partner ability register*/
418 #define GMII_GTCR 0x09 /* 1000BASE-T control register */
419 #define GMII_GTSR 0x0a /* 1000BASE-T status register */
420 #define GMII_PSSR 0x11 /* PHY-specific status register */
422 /* Basic mode status register. */
423 #define BMSR_LSTATUS 0x0004 /* Link status */
425 /* Link partner ability register. */
426 #define LPA_10HALF 0x0020 /* Can do 10mbps half-duplex */
427 #define LPA_10FULL 0x0040 /* Can do 10mbps full-duplex */
428 #define LPA_100HALF 0x0080 /* Can do 100mbps half-duplex */
429 #define LPA_100FULL 0x0100 /* Can do 100mbps full-duplex */
430 #define LPA_100BASE4 0x0200 /* Can do 100mbps 4k packets */
431 #define LPA_PAUSE 0x0400 /* Bit 10 - MAC pause */
433 /* Pseudo extensions to the link partner ability register */
434 #define LPA_1000FULL 0x00020000
435 #define LPA_1000HALF 0x00010000
437 #define LPA_100 (LPA_100FULL | LPA_100HALF | LPA_100BASE4)
438 #define LPA_1000 ( LPA_1000FULL | LPA_1000HALF )
439 #define LPA_DUPLEX ( LPA_10FULL | LPA_100FULL | LPA_1000FULL )
441 /* Mask of bits not associated with speed or duplexity. */
442 #define LPA_OTHER ~( LPA_10FULL | LPA_10HALF | LPA_100FULL | \
443 LPA_100HALF | LPA_1000FULL | LPA_1000HALF )
445 /* PHY-specific status register */
446 #define PSSR_LSTATUS 0x0400 /* Bit 10 - link status */
449 * Retrieve GMII autonegotiation advertised abilities
452 static unsigned int gmii_autoneg_advertised ( struct efab_nic *efab ) {
453 unsigned int mii_advertise;
454 unsigned int gmii_advertise;
456 /* Extended bits are in bits 8 and 9 of GMII_GTCR */
457 mii_advertise = efab->op->mdio_read ( efab, MII_ADVERTISE );
458 gmii_advertise = ( ( efab->op->mdio_read ( efab, GMII_GTCR ) >> 8 )
460 return ( ( gmii_advertise << 16 ) | mii_advertise );
464 * Retrieve GMII autonegotiation link partner abilities
467 static unsigned int gmii_autoneg_lpa ( struct efab_nic *efab ) {
468 unsigned int mii_lpa;
469 unsigned int gmii_lpa;
471 /* Extended bits are in bits 10 and 11 of GMII_GTSR */
472 mii_lpa = efab->op->mdio_read ( efab, MII_LPA );
473 gmii_lpa = ( efab->op->mdio_read ( efab, GMII_GTSR ) >> 10 ) & 0x03;
474 return ( ( gmii_lpa << 16 ) | mii_lpa );
478 * Calculate GMII autonegotiated link technology
481 static unsigned int gmii_nway_result ( unsigned int negotiated ) {
482 unsigned int other_bits;
484 /* Mask out the speed and duplexity bits */
485 other_bits = negotiated & LPA_OTHER;
487 if ( negotiated & LPA_1000FULL )
488 return ( other_bits | LPA_1000FULL );
489 else if ( negotiated & LPA_1000HALF )
490 return ( other_bits | LPA_1000HALF );
491 else if ( negotiated & LPA_100FULL )
492 return ( other_bits | LPA_100FULL );
493 else if ( negotiated & LPA_100BASE4 )
494 return ( other_bits | LPA_100BASE4 );
495 else if ( negotiated & LPA_100HALF )
496 return ( other_bits | LPA_100HALF );
497 else if ( negotiated & LPA_10FULL )
498 return ( other_bits | LPA_10FULL );
499 else return ( other_bits | LPA_10HALF );
503 * Check GMII PHY link status
506 static int gmii_link_ok ( struct efab_nic *efab ) {
510 /* BMSR is latching - it returns "link down" if the link has
511 * been down at any point since the last read. To get a
512 * real-time status, we therefore read the register twice and
513 * use the result of the second read.
515 efab->op->mdio_read ( efab, MII_BMSR );
516 status = efab->op->mdio_read ( efab, MII_BMSR );
518 /* Read the PHY-specific Status Register. This is
519 * non-latching, so we need do only a single read.
521 phy_status = efab->op->mdio_read ( efab, GMII_PSSR );
523 return ( ( status & BMSR_LSTATUS ) && ( phy_status & PSSR_LSTATUS ) );
526 /**************************************************************************
530 **************************************************************************
534 * Initialise Alaska PHY
537 static void alaska_init ( struct efab_nic *efab ) {
538 unsigned int advertised, lpa;
540 /* Read link up status */
541 efab->link_up = gmii_link_ok ( efab );
543 if ( ! efab->link_up )
546 /* Determine link options from PHY. */
547 advertised = gmii_autoneg_advertised ( efab );
548 lpa = gmii_autoneg_lpa ( efab );
549 efab->link_options = gmii_nway_result ( advertised & lpa );
551 printf ( "%dMbps %s-duplex (%04x,%04x)\n",
552 ( efab->link_options & LPA_1000 ? 1000 :
553 ( efab->link_options & LPA_100 ? 100 : 10 ) ),
554 ( efab->link_options & LPA_DUPLEX ? "full" : "half" ),
558 /**************************************************************************
562 **************************************************************************
565 /* GMAC configuration register 1 */
566 #define GM_CFG1_REG_MAC 0x00
567 #define GM_SW_RST_LBN 31
568 #define GM_SW_RST_WIDTH 1
569 #define GM_RX_FC_EN_LBN 5
570 #define GM_RX_FC_EN_WIDTH 1
571 #define GM_TX_FC_EN_LBN 4
572 #define GM_TX_FC_EN_WIDTH 1
573 #define GM_RX_EN_LBN 2
574 #define GM_RX_EN_WIDTH 1
575 #define GM_TX_EN_LBN 0
576 #define GM_TX_EN_WIDTH 1
578 /* GMAC configuration register 2 */
579 #define GM_CFG2_REG_MAC 0x01
580 #define GM_PAMBL_LEN_LBN 12
581 #define GM_PAMBL_LEN_WIDTH 4
582 #define GM_IF_MODE_LBN 8
583 #define GM_IF_MODE_WIDTH 2
584 #define GM_PAD_CRC_EN_LBN 2
585 #define GM_PAD_CRC_EN_WIDTH 1
587 #define GM_FD_WIDTH 1
589 /* GMAC maximum frame length register */
590 #define GM_MAX_FLEN_REG_MAC 0x04
591 #define GM_MAX_FLEN_LBN 0
592 #define GM_MAX_FLEN_WIDTH 16
594 /* GMAC MII management configuration register */
595 #define GM_MII_MGMT_CFG_REG_MAC 0x08
596 #define GM_MGMT_CLK_SEL_LBN 0
597 #define GM_MGMT_CLK_SEL_WIDTH 3
599 /* GMAC MII management command register */
600 #define GM_MII_MGMT_CMD_REG_MAC 0x09
601 #define GM_MGMT_SCAN_CYC_LBN 1
602 #define GM_MGMT_SCAN_CYC_WIDTH 1
603 #define GM_MGMT_RD_CYC_LBN 0
604 #define GM_MGMT_RD_CYC_WIDTH 1
606 /* GMAC MII management address register */
607 #define GM_MII_MGMT_ADR_REG_MAC 0x0a
608 #define GM_MGMT_PHY_ADDR_LBN 8
609 #define GM_MGMT_PHY_ADDR_WIDTH 5
610 #define GM_MGMT_REG_ADDR_LBN 0
611 #define GM_MGMT_REG_ADDR_WIDTH 5
613 /* GMAC MII management control register */
614 #define GM_MII_MGMT_CTL_REG_MAC 0x0b
615 #define GM_MGMT_CTL_LBN 0
616 #define GM_MGMT_CTL_WIDTH 16
618 /* GMAC MII management status register */
619 #define GM_MII_MGMT_STAT_REG_MAC 0x0c
620 #define GM_MGMT_STAT_LBN 0
621 #define GM_MGMT_STAT_WIDTH 16
623 /* GMAC MII management indicators register */
624 #define GM_MII_MGMT_IND_REG_MAC 0x0d
625 #define GM_MGMT_BUSY_LBN 0
626 #define GM_MGMT_BUSY_WIDTH 1
628 /* GMAC station address register 1 */
629 #define GM_ADR1_REG_MAC 0x10
630 #define GM_HWADDR_5_LBN 24
631 #define GM_HWADDR_5_WIDTH 8
632 #define GM_HWADDR_4_LBN 16
633 #define GM_HWADDR_4_WIDTH 8
634 #define GM_HWADDR_3_LBN 8
635 #define GM_HWADDR_3_WIDTH 8
636 #define GM_HWADDR_2_LBN 0
637 #define GM_HWADDR_2_WIDTH 8
639 /* GMAC station address register 2 */
640 #define GM_ADR2_REG_MAC 0x11
641 #define GM_HWADDR_1_LBN 24
642 #define GM_HWADDR_1_WIDTH 8
643 #define GM_HWADDR_0_LBN 16
644 #define GM_HWADDR_0_WIDTH 8
646 /* GMAC FIFO configuration register 0 */
647 #define GMF_CFG0_REG_MAC 0x12
648 #define GMF_FTFENREQ_LBN 12
649 #define GMF_FTFENREQ_WIDTH 1
650 #define GMF_STFENREQ_LBN 11
651 #define GMF_STFENREQ_WIDTH 1
652 #define GMF_FRFENREQ_LBN 10
653 #define GMF_FRFENREQ_WIDTH 1
654 #define GMF_SRFENREQ_LBN 9
655 #define GMF_SRFENREQ_WIDTH 1
656 #define GMF_WTMENREQ_LBN 8
657 #define GMF_WTMENREQ_WIDTH 1
659 /* GMAC FIFO configuration register 1 */
660 #define GMF_CFG1_REG_MAC 0x13
661 #define GMF_CFGFRTH_LBN 16
662 #define GMF_CFGFRTH_WIDTH 5
663 #define GMF_CFGXOFFRTX_LBN 0
664 #define GMF_CFGXOFFRTX_WIDTH 16
666 /* GMAC FIFO configuration register 2 */
667 #define GMF_CFG2_REG_MAC 0x14
668 #define GMF_CFGHWM_LBN 16
669 #define GMF_CFGHWM_WIDTH 6
670 #define GMF_CFGLWM_LBN 0
671 #define GMF_CFGLWM_WIDTH 6
673 /* GMAC FIFO configuration register 3 */
674 #define GMF_CFG3_REG_MAC 0x15
675 #define GMF_CFGHWMFT_LBN 16
676 #define GMF_CFGHWMFT_WIDTH 6
677 #define GMF_CFGFTTH_LBN 0
678 #define GMF_CFGFTTH_WIDTH 6
680 /* GMAC FIFO configuration register 4 */
681 #define GMF_CFG4_REG_MAC 0x16
682 #define GMF_HSTFLTRFRM_PAUSE_LBN 12
683 #define GMF_HSTFLTRFRM_PAUSE_WIDTH 12
685 /* GMAC FIFO configuration register 5 */
686 #define GMF_CFG5_REG_MAC 0x17
687 #define GMF_CFGHDPLX_LBN 22
688 #define GMF_CFGHDPLX_WIDTH 1
689 #define GMF_CFGBYTMODE_LBN 19
690 #define GMF_CFGBYTMODE_WIDTH 1
691 #define GMF_HSTDRPLT64_LBN 18
692 #define GMF_HSTDRPLT64_WIDTH 1
693 #define GMF_HSTFLTRFRMDC_PAUSE_LBN 12
694 #define GMF_HSTFLTRFRMDC_PAUSE_WIDTH 1
696 struct efab_mentormac_parameters {
708 static void mentormac_reset ( struct efab_nic *efab, int reset ) {
711 EFAB_POPULATE_DWORD_1 ( reg, GM_SW_RST, reset );
712 efab->op->mac_writel ( efab, ®, GM_CFG1_REG_MAC );
715 if ( ( ! reset ) && ( efab->port == 0 ) ) {
716 /* Configure GMII interface so PHY is accessible.
717 * Note that GMII interface is connected only to port
720 EFAB_POPULATE_DWORD_1 ( reg, GM_MGMT_CLK_SEL, 0x4 );
721 efab->op->mac_writel ( efab, ®, GM_MII_MGMT_CFG_REG_MAC );
727 * Initialise Mentor MAC
730 static void mentormac_init ( struct efab_nic *efab,
731 struct efab_mentormac_parameters *params ) {
732 int pause, if_mode, full_duplex, bytemode, half_duplex;
735 /* Configuration register 1 */
736 pause = ( efab->link_options & LPA_PAUSE ) ? 1 : 0;
737 if ( ! ( efab->link_options & LPA_DUPLEX ) ) {
738 /* Half-duplex operation requires TX flow control */
741 EFAB_POPULATE_DWORD_4 ( reg,
746 efab->op->mac_writel ( efab, ®, GM_CFG1_REG_MAC );
749 /* Configuration register 2 */
750 if_mode = ( efab->link_options & LPA_1000 ) ? 2 : 1;
751 full_duplex = ( efab->link_options & LPA_DUPLEX ) ? 1 : 0;
752 EFAB_POPULATE_DWORD_4 ( reg,
756 GM_PAMBL_LEN, 0x7 /* ? */ );
757 efab->op->mac_writel ( efab, ®, GM_CFG2_REG_MAC );
760 /* Max frame len register */
761 EFAB_POPULATE_DWORD_1 ( reg, GM_MAX_FLEN, ETH_FRAME_LEN );
762 efab->op->mac_writel ( efab, ®, GM_MAX_FLEN_REG_MAC );
765 /* FIFO configuration register 0 */
766 EFAB_POPULATE_DWORD_5 ( reg,
772 efab->op->mac_writel ( efab, ®, GMF_CFG0_REG_MAC );
775 /* FIFO configuration register 1 */
776 EFAB_POPULATE_DWORD_2 ( reg,
777 GMF_CFGFRTH, params->gmf_cfgfrth,
778 GMF_CFGXOFFRTX, 0xffff );
779 efab->op->mac_writel ( efab, ®, GMF_CFG1_REG_MAC );
782 /* FIFO configuration register 2 */
783 EFAB_POPULATE_DWORD_2 ( reg,
784 GMF_CFGHWM, params->gmf_cfghwm,
785 GMF_CFGLWM, params->gmf_cfglwm );
786 efab->op->mac_writel ( efab, ®, GMF_CFG2_REG_MAC );
789 /* FIFO configuration register 3 */
790 EFAB_POPULATE_DWORD_2 ( reg,
791 GMF_CFGHWMFT, params->gmf_cfghwmft,
792 GMF_CFGFTTH, params->gmf_cfgftth );
793 efab->op->mac_writel ( efab, ®, GMF_CFG3_REG_MAC );
796 /* FIFO configuration register 4 */
797 EFAB_POPULATE_DWORD_1 ( reg, GMF_HSTFLTRFRM_PAUSE, 1 );
798 efab->op->mac_writel ( efab, ®, GMF_CFG4_REG_MAC );
801 /* FIFO configuration register 5 */
802 bytemode = ( efab->link_options & LPA_1000 ) ? 1 : 0;
803 half_duplex = ( efab->link_options & LPA_DUPLEX ) ? 0 : 1;
804 efab->op->mac_readl ( efab, ®, GMF_CFG5_REG_MAC );
805 EFAB_SET_DWORD_FIELD ( reg, GMF_CFGBYTMODE, bytemode );
806 EFAB_SET_DWORD_FIELD ( reg, GMF_CFGHDPLX, half_duplex );
807 EFAB_SET_DWORD_FIELD ( reg, GMF_HSTDRPLT64, half_duplex );
808 EFAB_SET_DWORD_FIELD ( reg, GMF_HSTFLTRFRMDC_PAUSE, 0 );
809 efab->op->mac_writel ( efab, ®, GMF_CFG5_REG_MAC );
813 EFAB_POPULATE_DWORD_4 ( reg,
814 GM_HWADDR_5, efab->mac_addr[5],
815 GM_HWADDR_4, efab->mac_addr[4],
816 GM_HWADDR_3, efab->mac_addr[3],
817 GM_HWADDR_2, efab->mac_addr[2] );
818 efab->op->mac_writel ( efab, ®, GM_ADR1_REG_MAC );
820 EFAB_POPULATE_DWORD_2 ( reg,
821 GM_HWADDR_1, efab->mac_addr[1],
822 GM_HWADDR_0, efab->mac_addr[0] );
823 efab->op->mac_writel ( efab, ®, GM_ADR2_REG_MAC );
828 * Wait for GMII access to complete
831 static int mentormac_gmii_wait ( struct efab_nic *efab ) {
833 efab_dword_t indicator;
835 for ( count = 0 ; count < 1000 ; count++ ) {
837 efab->op->mac_readl ( efab, &indicator,
838 GM_MII_MGMT_IND_REG_MAC );
839 if ( EFAB_DWORD_FIELD ( indicator, GM_MGMT_BUSY ) == 0 )
842 printf ( "Timed out waiting for GMII\n" );
847 * Write a GMII register
850 static void mentormac_mdio_write ( struct efab_nic *efab, int phy_id,
851 int location, int value ) {
855 EFAB_TRACE ( "Writing GMII %d register %02x with %04x\n", phy_id,
858 /* Mentor MAC connects both PHYs to MAC 0 */
859 save_port = efab->port;
862 /* Check MII not currently being accessed */
863 if ( ! mentormac_gmii_wait ( efab ) )
866 /* Write the address register */
867 EFAB_POPULATE_DWORD_2 ( reg,
868 GM_MGMT_PHY_ADDR, phy_id,
869 GM_MGMT_REG_ADDR, location );
870 efab->op->mac_writel ( efab, ®, GM_MII_MGMT_ADR_REG_MAC );
874 EFAB_POPULATE_DWORD_1 ( reg, GM_MGMT_CTL, value );
875 efab->op->mac_writel ( efab, ®, GM_MII_MGMT_CTL_REG_MAC );
877 /* Wait for data to be written */
878 mentormac_gmii_wait ( efab );
881 /* Restore efab->port */
882 efab->port = save_port;
886 * Read a GMII register
889 static int mentormac_mdio_read ( struct efab_nic *efab, int phy_id,
895 /* Mentor MAC connects both PHYs to MAC 0 */
896 save_port = efab->port;
899 /* Check MII not currently being accessed */
900 if ( ! mentormac_gmii_wait ( efab ) )
903 /* Write the address register */
904 EFAB_POPULATE_DWORD_2 ( reg,
905 GM_MGMT_PHY_ADDR, phy_id,
906 GM_MGMT_REG_ADDR, location );
907 efab->op->mac_writel ( efab, ®, GM_MII_MGMT_ADR_REG_MAC );
910 /* Request data to be read */
911 EFAB_POPULATE_DWORD_1 ( reg, GM_MGMT_RD_CYC, 1 );
912 efab->op->mac_writel ( efab, ®, GM_MII_MGMT_CMD_REG_MAC );
914 /* Wait for data to be become available */
915 if ( mentormac_gmii_wait ( efab ) ) {
917 efab->op->mac_readl ( efab, ®, GM_MII_MGMT_STAT_REG_MAC );
918 value = EFAB_DWORD_FIELD ( reg, GM_MGMT_STAT );
919 EFAB_TRACE ( "Read from GMII %d register %02x, got %04x\n",
920 phy_id, location, value );
923 /* Signal completion */
924 EFAB_ZERO_DWORD ( reg );
925 efab->op->mac_writel ( efab, ®, GM_MII_MGMT_CMD_REG_MAC );
929 /* Restore efab->port */
930 efab->port = save_port;
935 /**************************************************************************
939 **************************************************************************
942 /** Control and General Status */
943 #define EF1_CTR_GEN_STATUS0_REG 0x0
944 #define EF1_MASTER_EVENTS_LBN 12
945 #define EF1_MASTER_EVENTS_WIDTH 1
946 #define EF1_TX_ENGINE_EN_LBN 19
947 #define EF1_TX_ENGINE_EN_WIDTH 1
948 #define EF1_RX_ENGINE_EN_LBN 18
949 #define EF1_RX_ENGINE_EN_WIDTH 1
950 #define EF1_LB_RESET_LBN 3
951 #define EF1_LB_RESET_WIDTH 1
952 #define EF1_MAC_RESET_LBN 2
953 #define EF1_MAC_RESET_WIDTH 1
954 #define EF1_CAM_ENABLE_LBN 1
955 #define EF1_CAM_ENABLE_WIDTH 1
958 #define EF1_IRQ_SRC_REG 0x0008
961 #define EF1_IRQ_MASK_REG 0x000c
962 #define EF1_IRQ_PHY1_LBN 11
963 #define EF1_IRQ_PHY1_WIDTH 1
964 #define EF1_IRQ_PHY0_LBN 10
965 #define EF1_IRQ_PHY0_WIDTH 1
966 #define EF1_IRQ_SERR_LBN 7
967 #define EF1_IRQ_SERR_WIDTH 1
968 #define EF1_IRQ_EVQ_LBN 3
969 #define EF1_IRQ_EVQ_WIDTH 1
971 /** Event generation */
972 #define EF1_EVT3_REG 0x38
975 #define EF1_EEPROM_REG 0x0040
977 /** Control register 2 */
978 #define EF1_CTL2_REG 0x4c
979 #define EF1_MEM_MAP_4MB_LBN 11
980 #define EF1_MEM_MAP_4MB_WIDTH 1
981 #define EF1_EV_INTR_CLR_WRITE_LBN 6
982 #define EF1_EV_INTR_CLR_WRITE_WIDTH 1
983 #define EF1_SW_RESET_LBN 2
984 #define EF1_SW_RESET_WIDTH 1
985 #define EF1_INTR_AFTER_EVENT_LBN 1
986 #define EF1_INTR_AFTER_EVENT_WIDTH 1
989 #define EF1_EVENT_FIFO_REG 0x50
991 /** Event FIFO count */
992 #define EF1_EVENT_FIFO_COUNT_REG 0x5c
993 #define EF1_EV_COUNT_LBN 0
994 #define EF1_EV_COUNT_WIDTH 16
996 /** TX DMA control and status */
997 #define EF1_DMA_TX_CSR_REG 0x80
998 #define EF1_DMA_TX_CSR_CHAIN_EN_LBN 8
999 #define EF1_DMA_TX_CSR_CHAIN_EN_WIDTH 1
1000 #define EF1_DMA_TX_CSR_ENABLE_LBN 4
1001 #define EF1_DMA_TX_CSR_ENABLE_WIDTH 1
1002 #define EF1_DMA_TX_CSR_INT_EN_LBN 0
1003 #define EF1_DMA_TX_CSR_INT_EN_WIDTH 1
1005 /** RX DMA control and status */
1006 #define EF1_DMA_RX_CSR_REG 0xa0
1007 #define EF1_DMA_RX_ABOVE_1GB_EN_LBN 6
1008 #define EF1_DMA_RX_ABOVE_1GB_EN_WIDTH 1
1009 #define EF1_DMA_RX_BELOW_1MB_EN_LBN 5
1010 #define EF1_DMA_RX_BELOW_1MB_EN_WIDTH 1
1011 #define EF1_DMA_RX_CSR_ENABLE_LBN 0
1012 #define EF1_DMA_RX_CSR_ENABLE_WIDTH 1
1014 /** Level 5 watermark register (in MAC space) */
1015 #define EF1_GMF_L5WM_REG_MAC 0x20
1016 #define EF1_L5WM_LBN 0
1017 #define EF1_L5WM_WIDTH 32
1020 #define EF1_GM_MAC_CLK_REG 0x112000
1021 #define EF1_GM_PORT0_MAC_CLK_LBN 0
1022 #define EF1_GM_PORT0_MAC_CLK_WIDTH 1
1023 #define EF1_GM_PORT1_MAC_CLK_LBN 1
1024 #define EF1_GM_PORT1_MAC_CLK_WIDTH 1
1026 /** TX descriptor FIFO */
1027 #define EF1_TX_DESC_FIFO 0x141000
1028 #define EF1_TX_KER_EVQ_LBN 80
1029 #define EF1_TX_KER_EVQ_WIDTH 12
1030 #define EF1_TX_KER_IDX_LBN 64
1031 #define EF1_TX_KER_IDX_WIDTH 16
1032 #define EF1_TX_KER_MODE_LBN 63
1033 #define EF1_TX_KER_MODE_WIDTH 1
1034 #define EF1_TX_KER_PORT_LBN 60
1035 #define EF1_TX_KER_PORT_WIDTH 1
1036 #define EF1_TX_KER_CONT_LBN 56
1037 #define EF1_TX_KER_CONT_WIDTH 1
1038 #define EF1_TX_KER_BYTE_CNT_LBN 32
1039 #define EF1_TX_KER_BYTE_CNT_WIDTH 24
1040 #define EF1_TX_KER_BUF_ADR_LBN 0
1041 #define EF1_TX_KER_BUF_ADR_WIDTH 32
1043 /** TX descriptor FIFO flush */
1044 #define EF1_TX_DESC_FIFO_FLUSH 0x141ffc
1046 /** RX descriptor FIFO */
1047 #define EF1_RX_DESC_FIFO 0x145000
1048 #define EF1_RX_KER_EVQ_LBN 48
1049 #define EF1_RX_KER_EVQ_WIDTH 12
1050 #define EF1_RX_KER_IDX_LBN 32
1051 #define EF1_RX_KER_IDX_WIDTH 16
1052 #define EF1_RX_KER_BUF_ADR_LBN 0
1053 #define EF1_RX_KER_BUF_ADR_WIDTH 32
1055 /** RX descriptor FIFO flush */
1056 #define EF1_RX_DESC_FIFO_FLUSH 0x145ffc
1059 #define EF1_CAM_BASE 0x1c0000
1060 #define EF1_CAM_WTF_DOES_THIS_DO_LBN 0
1061 #define EF1_CAM_WTF_DOES_THIS_DO_WIDTH 32
1063 /** Event queue pointers */
1064 #define EF1_EVQ_PTR_BASE 0x260000
1065 #define EF1_EVQ_SIZE_LBN 29
1066 #define EF1_EVQ_SIZE_WIDTH 2
1067 #define EF1_EVQ_SIZE_4K 3
1068 #define EF1_EVQ_SIZE_2K 2
1069 #define EF1_EVQ_SIZE_1K 1
1070 #define EF1_EVQ_SIZE_512 0
1071 #define EF1_EVQ_BUF_BASE_ID_LBN 0
1072 #define EF1_EVQ_BUF_BASE_ID_WIDTH 29
1075 #define EF1002_MAC_REGBANK 0x110000
1076 #define EF1002_MAC_REGBANK_SIZE 0x1000
1077 #define EF1002_MAC_REG_SIZE 0x08
1079 /** Offset of a MAC register within EF1002 */
1080 #define EF1002_MAC_REG( efab, mac_reg ) \
1081 ( EF1002_MAC_REGBANK + \
1082 ( (efab)->port * EF1002_MAC_REGBANK_SIZE ) + \
1083 ( (mac_reg) * EF1002_MAC_REG_SIZE ) )
1085 /* Event queue entries */
1086 #define EF1_EV_CODE_LBN 20
1087 #define EF1_EV_CODE_WIDTH 8
1088 #define EF1_RX_EV_DECODE 0x01
1089 #define EF1_TX_EV_DECODE 0x02
1090 #define EF1_DRV_GEN_EV_DECODE 0x0f
1092 /* Receive events */
1093 #define EF1_RX_EV_LEN_LBN 48
1094 #define EF1_RX_EV_LEN_WIDTH 16
1095 #define EF1_RX_EV_PORT_LBN 17
1096 #define EF1_RX_EV_PORT_WIDTH 3
1097 #define EF1_RX_EV_OK_LBN 16
1098 #define EF1_RX_EV_OK_WIDTH 1
1099 #define EF1_RX_EV_IDX_LBN 0
1100 #define EF1_RX_EV_IDX_WIDTH 16
1102 /* Transmit events */
1103 #define EF1_TX_EV_PORT_LBN 17
1104 #define EF1_TX_EV_PORT_WIDTH 3
1105 #define EF1_TX_EV_OK_LBN 16
1106 #define EF1_TX_EV_OK_WIDTH 1
1107 #define EF1_TX_EV_IDX_LBN 0
1108 #define EF1_TX_EV_IDX_WIDTH 16
1111 * Write dword to EF1002 register
1114 static inline void ef1002_writel ( struct efab_nic *efab, efab_dword_t *value,
1115 unsigned int reg ) {
1116 EFAB_REGDUMP ( "Writing register %x with " EFAB_DWORD_FMT "\n",
1117 reg, EFAB_DWORD_VAL ( *value ) );
1118 writel ( value->u32[0], efab->membase + reg );
1122 * Read dword from an EF1002 register
1125 static inline void ef1002_readl ( struct efab_nic *efab, efab_dword_t *value,
1126 unsigned int reg ) {
1127 value->u32[0] = readl ( efab->membase + reg );
1128 EFAB_REGDUMP ( "Read from register %x, got " EFAB_DWORD_FMT "\n",
1129 reg, EFAB_DWORD_VAL ( *value ) );
1133 * Read dword from an EF1002 register, silently
1136 static inline void ef1002_readl_silent ( struct efab_nic *efab,
1137 efab_dword_t *value,
1138 unsigned int reg ) {
1139 value->u32[0] = readl ( efab->membase + reg );
1146 static void ef1002_get_membase ( struct efab_nic *efab ) {
1147 unsigned long membase_phys;
1149 membase_phys = pci_bar_start ( efab->pci, PCI_BASE_ADDRESS_0 );
1150 efab->membase = ioremap ( membase_phys, 0x800000 );
1153 /** PCI registers to backup/restore over a device reset */
1154 static const unsigned int efab_pci_reg_addr[] = {
1155 PCI_COMMAND, 0x0c /* PCI_CACHE_LINE_SIZE */,
1156 PCI_BASE_ADDRESS_0, PCI_BASE_ADDRESS_1, PCI_BASE_ADDRESS_2,
1157 PCI_BASE_ADDRESS_3, PCI_ROM_ADDRESS, PCI_INTERRUPT_LINE,
1159 /** Number of registers in efab_pci_reg_addr */
1160 #define EFAB_NUM_PCI_REG \
1161 ( sizeof ( efab_pci_reg_addr ) / sizeof ( efab_pci_reg_addr[0] ) )
1162 /** PCI configuration space backup */
1163 struct efab_pci_reg {
1164 uint32_t reg[EFAB_NUM_PCI_REG];
1171 static int ef1002_reset ( struct efab_nic *efab ) {
1172 struct efab_pci_reg pci_reg;
1173 struct pci_device *pci_dev = efab->pci;
1178 /* Back up PCI configuration registers */
1179 for ( i = 0 ; i < EFAB_NUM_PCI_REG ; i++ ) {
1180 pci_read_config_dword ( pci_dev, efab_pci_reg_addr[i],
1184 /* Reset the whole device. */
1185 EFAB_POPULATE_DWORD_1 ( reg, EF1_SW_RESET, 1 );
1186 ef1002_writel ( efab, ®, EF1_CTL2_REG );
1189 /* Restore PCI configuration space */
1190 for ( i = 0 ; i < EFAB_NUM_PCI_REG ; i++ ) {
1191 pci_write_config_dword ( pci_dev, efab_pci_reg_addr[i],
1195 /* Verify PCI configuration space */
1196 for ( i = 0 ; i < EFAB_NUM_PCI_REG ; i++ ) {
1197 pci_read_config_dword ( pci_dev, efab_pci_reg_addr[i], &tmp );
1198 if ( tmp != pci_reg.reg[i] ) {
1199 printf ( "PCI restore failed on register %02x "
1200 "(is %08x, should be %08x); reboot\n",
1201 i, tmp, pci_reg.reg[i] );
1206 /* Verify device reset complete */
1207 ef1002_readl ( efab, ®, EF1_CTR_GEN_STATUS0_REG );
1208 if ( EFAB_DWORD_IS_ALL_ONES ( reg ) ) {
1209 printf ( "Reset failed\n" );
1220 static int ef1002_init_nic ( struct efab_nic *efab ) {
1224 /* No idea what CAM is, but the 'datasheet' says that we have
1225 * to write these values in at start of day
1227 EFAB_POPULATE_DWORD_1 ( reg, EF1_CAM_WTF_DOES_THIS_DO, 0x6 );
1228 ef1002_writel ( efab, ®, EF1_CAM_BASE + 0x20018 );
1230 EFAB_POPULATE_DWORD_1 ( reg, EF1_CAM_WTF_DOES_THIS_DO, 0x01000000 );
1231 ef1002_writel ( efab, ®, EF1_CAM_BASE + 0x00018 );
1234 /* General control register 0 */
1235 ef1002_readl ( efab, ®, EF1_CTR_GEN_STATUS0_REG );
1236 EFAB_SET_DWORD_FIELD ( reg, EF1_MASTER_EVENTS, 0 );
1237 EFAB_SET_DWORD_FIELD ( reg, EF1_CAM_ENABLE, 1 );
1238 ef1002_writel ( efab, ®, EF1_CTR_GEN_STATUS0_REG );
1241 /* General control register 2 */
1242 ef1002_readl ( efab, ®, EF1_CTL2_REG );
1243 EFAB_SET_DWORD_FIELD ( reg, EF1_INTR_AFTER_EVENT, 1 );
1244 EFAB_SET_DWORD_FIELD ( reg, EF1_EV_INTR_CLR_WRITE, 0 );
1245 EFAB_SET_DWORD_FIELD ( reg, EF1_MEM_MAP_4MB, 0 );
1246 ef1002_writel ( efab, ®, EF1_CTL2_REG );
1250 ef1002_readl ( efab, ®, EF1_DMA_RX_CSR_REG );
1251 EFAB_SET_DWORD_FIELD ( reg, EF1_DMA_RX_CSR_ENABLE, 1 );
1252 EFAB_SET_DWORD_FIELD ( reg, EF1_DMA_RX_BELOW_1MB_EN, 1 );
1253 EFAB_SET_DWORD_FIELD ( reg, EF1_DMA_RX_ABOVE_1GB_EN, 1 );
1254 ef1002_writel ( efab, ®, EF1_DMA_RX_CSR_REG );
1258 ef1002_readl ( efab, ®, EF1_DMA_TX_CSR_REG );
1259 EFAB_SET_DWORD_FIELD ( reg, EF1_DMA_TX_CSR_CHAIN_EN, 1 );
1260 EFAB_SET_DWORD_FIELD ( reg, EF1_DMA_TX_CSR_ENABLE, 0 /* ?? */ );
1261 EFAB_SET_DWORD_FIELD ( reg, EF1_DMA_TX_CSR_INT_EN, 0 /* ?? */ );
1262 ef1002_writel ( efab, ®, EF1_DMA_TX_CSR_REG );
1265 /* Flush descriptor queues */
1266 EFAB_ZERO_DWORD ( reg );
1267 ef1002_writel ( efab, ®, EF1_RX_DESC_FIFO_FLUSH );
1268 ef1002_writel ( efab, ®, EF1_TX_DESC_FIFO_FLUSH );
1272 /* Reset both MACs */
1273 save_port = efab->port;
1275 mentormac_reset ( efab, 1 );
1277 mentormac_reset ( efab, 1 );
1279 /* Reset both PHYs */
1280 ef1002_readl ( efab, ®, EF1_CTR_GEN_STATUS0_REG );
1281 EFAB_SET_DWORD_FIELD ( reg, EF1_MAC_RESET, 1 );
1282 ef1002_writel ( efab, ®, EF1_CTR_GEN_STATUS0_REG );
1284 EFAB_SET_DWORD_FIELD ( reg, EF1_MAC_RESET, 0 );
1285 ef1002_writel ( efab, ®, EF1_CTR_GEN_STATUS0_REG );
1288 /* Take MACs out of reset */
1290 mentormac_reset ( efab, 0 );
1292 mentormac_reset ( efab, 0 );
1293 efab->port = save_port;
1295 /* Give PHY time to wake up. It takes a while. */
1302 * Read MAC address from EEPROM
1305 static int ef1002_read_eeprom ( struct efab_nic *efab ) {
1306 return efab_eeprom_read_mac ( efab->membase + EF1_EEPROM_REG,
1310 /** RX descriptor */
1311 typedef efab_qword_t ef1002_rx_desc_t;
1314 * Build RX descriptor
1317 static void ef1002_build_rx_desc ( struct efab_nic *efab,
1318 struct efab_rx_buf *rx_buf ) {
1319 ef1002_rx_desc_t rxd;
1321 EFAB_POPULATE_QWORD_3 ( rxd,
1323 EF1_RX_KER_IDX, rx_buf->id,
1325 virt_to_bus ( rx_buf->addr ) );
1326 ef1002_writel ( efab, &rxd.dword[0], EF1_RX_DESC_FIFO + 0 );
1327 ef1002_writel ( efab, &rxd.dword[1], EF1_RX_DESC_FIFO + 4 );
1332 * Update RX descriptor write pointer
1335 static void ef1002_notify_rx_desc ( struct efab_nic *efab __unused ) {
1339 /** TX descriptor */
1340 typedef efab_oword_t ef1002_tx_desc_t;
1343 * Build TX descriptor
1346 static void ef1002_build_tx_desc ( struct efab_nic *efab,
1347 struct efab_tx_buf *tx_buf ) {
1348 ef1002_tx_desc_t txd;
1350 EFAB_POPULATE_OWORD_7 ( txd,
1352 EF1_TX_KER_IDX, tx_buf->id,
1353 EF1_TX_KER_MODE, 0 /* IP mode */,
1354 EF1_TX_KER_PORT, efab->port,
1356 EF1_TX_KER_BYTE_CNT, tx_buf->len,
1358 virt_to_bus ( tx_buf->addr ) );
1360 ef1002_writel ( efab, &txd.dword[0], EF1_TX_DESC_FIFO + 0 );
1361 ef1002_writel ( efab, &txd.dword[1], EF1_TX_DESC_FIFO + 4 );
1362 ef1002_writel ( efab, &txd.dword[2], EF1_TX_DESC_FIFO + 8 );
1367 * Update TX descriptor write pointer
1370 static void ef1002_notify_tx_desc ( struct efab_nic *efab __unused ) {
1375 typedef efab_qword_t ef1002_event_t;
1378 * Retrieve event from event queue
1381 static int ef1002_fetch_event ( struct efab_nic *efab,
1382 struct efab_event *event ) {
1387 /* Check event FIFO depth */
1388 ef1002_readl_silent ( efab, ®, EF1_EVENT_FIFO_COUNT_REG );
1389 words = EFAB_DWORD_FIELD ( reg, EF1_EV_COUNT );
1393 /* Read event data */
1394 ef1002_readl ( efab, ®, EF1_EVENT_FIFO_REG );
1395 DBG ( "Event is " EFAB_DWORD_FMT "\n", EFAB_DWORD_VAL ( reg ) );
1398 ev_code = EFAB_DWORD_FIELD ( reg, EF1_EV_CODE );
1399 switch ( ev_code ) {
1400 case EF1_TX_EV_DECODE:
1401 event->type = EFAB_EV_TX;
1403 case EF1_RX_EV_DECODE:
1404 event->type = EFAB_EV_RX;
1405 event->rx_id = EFAB_DWORD_FIELD ( reg, EF1_RX_EV_IDX );
1406 /* RX len not available via event FIFO */
1407 event->rx_len = ETH_FRAME_LEN;
1410 printf ( "Unknown event type %d\n", ev_code );
1411 event->type = EFAB_EV_NONE;
1414 /* Clear any pending interrupts */
1415 ef1002_readl ( efab, ®, EF1_IRQ_SRC_REG );
1421 * Enable/disable interrupts
1424 static void ef1002_mask_irq ( struct efab_nic *efab, int enabled ) {
1425 efab_dword_t irq_mask;
1427 EFAB_POPULATE_DWORD_2 ( irq_mask,
1428 EF1_IRQ_SERR, enabled,
1429 EF1_IRQ_EVQ, enabled );
1430 ef1002_writel ( efab, &irq_mask, EF1_IRQ_MASK_REG );
1434 * Generate interrupt
1437 static void ef1002_generate_irq ( struct efab_nic *efab ) {
1438 ef1002_event_t test_event;
1440 EFAB_POPULATE_QWORD_1 ( test_event,
1441 EF1_EV_CODE, EF1_DRV_GEN_EV_DECODE );
1442 ef1002_writel ( efab, &test_event.dword[0], EF1_EVT3_REG );
1446 * Write dword to an EF1002 MAC register
1449 static void ef1002_mac_writel ( struct efab_nic *efab,
1450 efab_dword_t *value, unsigned int mac_reg ) {
1451 ef1002_writel ( efab, value, EF1002_MAC_REG ( efab, mac_reg ) );
1455 * Read dword from an EF1002 MAC register
1458 static void ef1002_mac_readl ( struct efab_nic *efab,
1459 efab_dword_t *value, unsigned int mac_reg ) {
1460 ef1002_readl ( efab, value, EF1002_MAC_REG ( efab, mac_reg ) );
1467 static int ef1002_init_mac ( struct efab_nic *efab ) {
1468 static struct efab_mentormac_parameters ef1002_mentormac_params = {
1469 .gmf_cfgfrth = 0x13,
1470 .gmf_cfgftth = 0x10,
1471 .gmf_cfghwmft = 0x555,
1476 unsigned int mac_clk;
1478 /* Initialise PHY */
1479 alaska_init ( efab );
1481 /* Initialise MAC */
1482 mentormac_init ( efab, &ef1002_mentormac_params );
1484 /* Write Level 5 watermark register */
1485 EFAB_POPULATE_DWORD_1 ( reg, EF1_L5WM, 0x10040000 );
1486 efab->op->mac_writel ( efab, ®, EF1_GMF_L5WM_REG_MAC );
1489 /* Set MAC clock speed */
1490 ef1002_readl ( efab, ®, EF1_GM_MAC_CLK_REG );
1491 mac_clk = ( efab->link_options & LPA_1000 ) ? 0 : 1;
1492 if ( efab->port == 0 ) {
1493 EFAB_SET_DWORD_FIELD ( reg, EF1_GM_PORT0_MAC_CLK, mac_clk );
1495 EFAB_SET_DWORD_FIELD ( reg, EF1_GM_PORT1_MAC_CLK, mac_clk );
1497 ef1002_writel ( efab, ®, EF1_GM_MAC_CLK_REG );
1504 static void ef1002_mdio_write ( struct efab_nic *efab, int location,
1506 mentormac_mdio_write ( efab, efab->port + 2, location, value );
1510 static int ef1002_mdio_read ( struct efab_nic *efab, int location ) {
1511 return mentormac_mdio_read ( efab, efab->port + 2, location );
1514 static struct efab_operations ef1002_operations = {
1515 .get_membase = ef1002_get_membase,
1516 .reset = ef1002_reset,
1517 .init_nic = ef1002_init_nic,
1518 .read_eeprom = ef1002_read_eeprom,
1519 .build_rx_desc = ef1002_build_rx_desc,
1520 .notify_rx_desc = ef1002_notify_rx_desc,
1521 .build_tx_desc = ef1002_build_tx_desc,
1522 .notify_tx_desc = ef1002_notify_tx_desc,
1523 .fetch_event = ef1002_fetch_event,
1524 .mask_irq = ef1002_mask_irq,
1525 .generate_irq = ef1002_generate_irq,
1526 .mac_writel = ef1002_mac_writel,
1527 .mac_readl = ef1002_mac_readl,
1528 .init_mac = ef1002_init_mac,
1529 .mdio_write = ef1002_mdio_write,
1530 .mdio_read = ef1002_mdio_read,
1533 /**************************************************************************
1537 **************************************************************************
1540 /* I/O BAR address register */
1541 #define FCN_IOM_IND_ADR_REG 0x0
1543 /* I/O BAR data register */
1544 #define FCN_IOM_IND_DAT_REG 0x4
1546 /* Interrupt enable register */
1547 #define FCN_INT_EN_REG_KER 0x0010
1548 #define FCN_MEM_PERR_INT_EN_KER_LBN 5
1549 #define FCN_MEM_PERR_INT_EN_KER_WIDTH 1
1550 #define FCN_KER_INT_CHAR_LBN 4
1551 #define FCN_KER_INT_CHAR_WIDTH 1
1552 #define FCN_KER_INT_KER_LBN 3
1553 #define FCN_KER_INT_KER_WIDTH 1
1554 #define FCN_ILL_ADR_ERR_INT_EN_KER_LBN 2
1555 #define FCN_ILL_ADR_ERR_INT_EN_KER_WIDTH 1
1556 #define FCN_SRM_PERR_INT_EN_KER_LBN 1
1557 #define FCN_SRM_PERR_INT_EN_KER_WIDTH 1
1558 #define FCN_DRV_INT_EN_KER_LBN 0
1559 #define FCN_DRV_INT_EN_KER_WIDTH 1
1561 /* Interrupt status register */
1562 #define FCN_INT_ADR_REG_KER 0x0030
1563 #define FCN_INT_ADR_KER_LBN 0
1564 #define FCN_INT_ADR_KER_WIDTH EFAB_DMA_TYPE_WIDTH ( 64 )
1566 /* Interrupt acknowledge register */
1567 #define FCN_INT_ACK_KER_REG 0x0050
1569 /* SPI host command register */
1570 #define FCN_EE_SPI_HCMD_REG_KER 0x0100
1571 #define FCN_EE_SPI_HCMD_CMD_EN_LBN 31
1572 #define FCN_EE_SPI_HCMD_CMD_EN_WIDTH 1
1573 #define FCN_EE_WR_TIMER_ACTIVE_LBN 28
1574 #define FCN_EE_WR_TIMER_ACTIVE_WIDTH 1
1575 #define FCN_EE_SPI_HCMD_SF_SEL_LBN 24
1576 #define FCN_EE_SPI_HCMD_SF_SEL_WIDTH 1
1577 #define FCN_EE_SPI_EEPROM 0
1578 #define FCN_EE_SPI_FLASH 1
1579 #define FCN_EE_SPI_HCMD_DABCNT_LBN 16
1580 #define FCN_EE_SPI_HCMD_DABCNT_WIDTH 5
1581 #define FCN_EE_SPI_HCMD_READ_LBN 15
1582 #define FCN_EE_SPI_HCMD_READ_WIDTH 1
1583 #define FCN_EE_SPI_READ 1
1584 #define FCN_EE_SPI_WRITE 0
1585 #define FCN_EE_SPI_HCMD_DUBCNT_LBN 12
1586 #define FCN_EE_SPI_HCMD_DUBCNT_WIDTH 2
1587 #define FCN_EE_SPI_HCMD_ADBCNT_LBN 8
1588 #define FCN_EE_SPI_HCMD_ADBCNT_WIDTH 2
1589 #define FCN_EE_SPI_HCMD_ENC_LBN 0
1590 #define FCN_EE_SPI_HCMD_ENC_WIDTH 8
1592 /* SPI host address register */
1593 #define FCN_EE_SPI_HADR_REG_KER 0x0110
1594 #define FCN_EE_SPI_HADR_DUBYTE_LBN 24
1595 #define FCN_EE_SPI_HADR_DUBYTE_WIDTH 8
1596 #define FCN_EE_SPI_HADR_ADR_LBN 0
1597 #define FCN_EE_SPI_HADR_ADR_WIDTH 24
1599 /* SPI host data register */
1600 #define FCN_EE_SPI_HDATA_REG_KER 0x0120
1601 #define FCN_EE_SPI_HDATA3_LBN 96
1602 #define FCN_EE_SPI_HDATA3_WIDTH 32
1603 #define FCN_EE_SPI_HDATA2_LBN 64
1604 #define FCN_EE_SPI_HDATA2_WIDTH 32
1605 #define FCN_EE_SPI_HDATA1_LBN 32
1606 #define FCN_EE_SPI_HDATA1_WIDTH 32
1607 #define FCN_EE_SPI_HDATA0_LBN 0
1608 #define FCN_EE_SPI_HDATA0_WIDTH 32
1610 /* GPIO control register */
1611 #define FCN_GPIO_CTL_REG_KER 0x0210
1612 #define FCN_FLASH_PRESENT_LBN 7
1613 #define FCN_FLASH_PRESENT_WIDTH 1
1614 #define FCN_EEPROM_PRESENT_LBN 6
1615 #define FCN_EEPROM_PRESENT_WIDTH 1
1617 /* Global control register */
1618 #define FCN_GLB_CTL_REG_KER 0x0220
1619 #define FCN_EXT_PHY_RST_CTL_LBN 63
1620 #define FCN_EXT_PHY_RST_CTL_WIDTH 1
1621 #define FCN_PCIE_SD_RST_CTL_LBN 61
1622 #define FCN_PCIE_SD_RST_CTL_WIDTH 1
1623 #define FCN_PCIX_RST_CTL_LBN 60
1624 #define FCN_PCIX_RST_CTL_WIDTH 1
1625 #define FCN_RST_EXT_PHY_LBN 31
1626 #define FCN_RST_EXT_PHY_WIDTH 1
1627 #define FCN_INT_RST_DUR_LBN 4
1628 #define FCN_INT_RST_DUR_WIDTH 3
1629 #define FCN_EXT_PHY_RST_DUR_LBN 1
1630 #define FCN_EXT_PHY_RST_DUR_WIDTH 3
1631 #define FCN_SWRST_LBN 0
1632 #define FCN_SWRST_WIDTH 1
1633 #define FCN_INCLUDE_IN_RESET 0
1634 #define FCN_EXCLUDE_FROM_RESET 1
1636 /* Timer table for kernel access */
1637 #define FCN_TIMER_CMD_REG_KER 0x420
1638 #define FCN_TIMER_MODE_LBN 12
1639 #define FCN_TIMER_MODE_WIDTH 2
1640 #define FCN_TIMER_MODE_DIS 0
1641 #define FCN_TIMER_MODE_INT_HLDOFF 1
1642 #define FCN_TIMER_VAL_LBN 0
1643 #define FCN_TIMER_VAL_WIDTH 12
1645 /* SRAM receive descriptor cache configuration register */
1646 #define FCN_SRM_RX_DC_CFG_REG_KER 0x610
1647 #define FCN_SRM_RX_DC_BASE_ADR_LBN 0
1648 #define FCN_SRM_RX_DC_BASE_ADR_WIDTH 21
1650 /* SRAM transmit descriptor cache configuration register */
1651 #define FCN_SRM_TX_DC_CFG_REG_KER 0x620
1652 #define FCN_SRM_TX_DC_BASE_ADR_LBN 0
1653 #define FCN_SRM_TX_DC_BASE_ADR_WIDTH 21
1655 /* Receive filter control register */
1656 #define FCN_RX_FILTER_CTL_REG_KER 0x810
1657 #define FCN_NUM_KER_LBN 24
1658 #define FCN_NUM_KER_WIDTH 2
1660 /* Receive descriptor update register */
1661 #define FCN_RX_DESC_UPD_REG_KER 0x0830
1662 #define FCN_RX_DESC_WPTR_LBN 96
1663 #define FCN_RX_DESC_WPTR_WIDTH 12
1664 #define FCN_RX_DESC_UPD_REG_KER_DWORD ( FCN_RX_DESC_UPD_REG_KER + 12 )
1665 #define FCN_RX_DESC_WPTR_DWORD_LBN 0
1666 #define FCN_RX_DESC_WPTR_DWORD_WIDTH 12
1668 /* Receive descriptor cache configuration register */
1669 #define FCN_RX_DC_CFG_REG_KER 0x840
1670 #define FCN_RX_DC_SIZE_LBN 0
1671 #define FCN_RX_DC_SIZE_WIDTH 2
1673 /* Transmit descriptor update register */
1674 #define FCN_TX_DESC_UPD_REG_KER 0x0a10
1675 #define FCN_TX_DESC_WPTR_LBN 96
1676 #define FCN_TX_DESC_WPTR_WIDTH 12
1677 #define FCN_TX_DESC_UPD_REG_KER_DWORD ( FCN_TX_DESC_UPD_REG_KER + 12 )
1678 #define FCN_TX_DESC_WPTR_DWORD_LBN 0
1679 #define FCN_TX_DESC_WPTR_DWORD_WIDTH 12
1681 /* Transmit descriptor cache configuration register */
1682 #define FCN_TX_DC_CFG_REG_KER 0xa20
1683 #define FCN_TX_DC_SIZE_LBN 0
1684 #define FCN_TX_DC_SIZE_WIDTH 2
1686 /* PHY management transmit data register */
1687 #define FCN_MD_TXD_REG_KER 0xc00
1688 #define FCN_MD_TXD_LBN 0
1689 #define FCN_MD_TXD_WIDTH 16
1691 /* PHY management receive data register */
1692 #define FCN_MD_RXD_REG_KER 0xc10
1693 #define FCN_MD_RXD_LBN 0
1694 #define FCN_MD_RXD_WIDTH 16
1696 /* PHY management configuration & status register */
1697 #define FCN_MD_CS_REG_KER 0xc20
1698 #define FCN_MD_GC_LBN 4
1699 #define FCN_MD_GC_WIDTH 1
1700 #define FCN_MD_RIC_LBN 2
1701 #define FCN_MD_RIC_WIDTH 1
1702 #define FCN_MD_WRC_LBN 0
1703 #define FCN_MD_WRC_WIDTH 1
1705 /* PHY management PHY address register */
1706 #define FCN_MD_PHY_ADR_REG_KER 0xc30
1707 #define FCN_MD_PHY_ADR_LBN 0
1708 #define FCN_MD_PHY_ADR_WIDTH 16
1710 /* PHY management ID register */
1711 #define FCN_MD_ID_REG_KER 0xc40
1712 #define FCN_MD_PRT_ADR_LBN 11
1713 #define FCN_MD_PRT_ADR_WIDTH 5
1714 #define FCN_MD_DEV_ADR_LBN 6
1715 #define FCN_MD_DEV_ADR_WIDTH 5
1717 /* PHY management status & mask register */
1718 #define FCN_MD_STAT_REG_KER 0xc50
1719 #define FCN_MD_BSY_LBN 0
1720 #define FCN_MD_BSY_WIDTH 1
1722 /* Port 0 and 1 MAC control registers */
1723 #define FCN_MAC0_CTRL_REG_KER 0xc80
1724 #define FCN_MAC1_CTRL_REG_KER 0xc90
1725 #define FCN_MAC_XOFF_VAL_LBN 16
1726 #define FCN_MAC_XOFF_VAL_WIDTH 16
1727 #define FCN_MAC_BCAD_ACPT_LBN 4
1728 #define FCN_MAC_BCAD_ACPT_WIDTH 1
1729 #define FCN_MAC_UC_PROM_LBN 3
1730 #define FCN_MAC_UC_PROM_WIDTH 1
1731 #define FCN_MAC_LINK_STATUS_LBN 2
1732 #define FCN_MAC_LINK_STATUS_WIDTH 1
1733 #define FCN_MAC_SPEED_LBN 0
1734 #define FCN_MAC_SPEED_WIDTH 2
1736 /* XGMAC global configuration - port 0*/
1737 #define FCN_XM_GLB_CFG_REG_P0_KER 0x1220
1738 #define FCN_XM_RX_STAT_EN_LBN 11
1739 #define FCN_XM_RX_STAT_EN_WIDTH 1
1740 #define FCN_XM_TX_STAT_EN_LBN 10
1741 #define FCN_XM_TX_STAT_EN_WIDTH 1
1742 #define FCN_XM_CUT_THRU_MODE_LBN 7
1743 #define FCN_XM_CUT_THRU_MODE_WIDTH 1
1744 #define FCN_XM_RX_JUMBO_MODE_LBN 6
1745 #define FCN_XM_RX_JUMBO_MODE_WIDTH 1
1747 /* XGMAC transmit configuration - port 0 */
1748 #define FCN_XM_TX_CFG_REG_P0_KER 0x1230
1749 #define FCN_XM_IPG_LBN 16
1750 #define FCN_XM_IPG_WIDTH 4
1751 #define FCN_XM_WTF_DOES_THIS_DO_LBN 9
1752 #define FCN_XM_WTF_DOES_THIS_DO_WIDTH 1
1753 #define FCN_XM_TXCRC_LBN 8
1754 #define FCN_XM_TXCRC_WIDTH 1
1755 #define FCN_XM_AUTO_PAD_LBN 5
1756 #define FCN_XM_AUTO_PAD_WIDTH 1
1757 #define FCN_XM_TX_PRMBL_LBN 2
1758 #define FCN_XM_TX_PRMBL_WIDTH 1
1759 #define FCN_XM_TXEN_LBN 1
1760 #define FCN_XM_TXEN_WIDTH 1
1762 /* XGMAC receive configuration - port 0 */
1763 #define FCN_XM_RX_CFG_REG_P0_KER 0x1240
1764 #define FCN_XM_PASS_CRC_ERR_LBN 25
1765 #define FCN_XM_PASS_CRC_ERR_WIDTH 1
1766 #define FCN_XM_AUTO_DEPAD_LBN 8
1767 #define FCN_XM_AUTO_DEPAD_WIDTH 1
1768 #define FCN_XM_RXEN_LBN 1
1769 #define FCN_XM_RXEN_WIDTH 1
1771 /* Receive descriptor pointer table */
1772 #define FCN_RX_DESC_PTR_TBL_KER 0x11800
1773 #define FCN_RX_DESCQ_BUF_BASE_ID_LBN 36
1774 #define FCN_RX_DESCQ_BUF_BASE_ID_WIDTH 20
1775 #define FCN_RX_DESCQ_EVQ_ID_LBN 24
1776 #define FCN_RX_DESCQ_EVQ_ID_WIDTH 12
1777 #define FCN_RX_DESCQ_OWNER_ID_LBN 10
1778 #define FCN_RX_DESCQ_OWNER_ID_WIDTH 14
1779 #define FCN_RX_DESCQ_SIZE_LBN 3
1780 #define FCN_RX_DESCQ_SIZE_WIDTH 2
1781 #define FCN_RX_DESCQ_SIZE_4K 3
1782 #define FCN_RX_DESCQ_SIZE_2K 2
1783 #define FCN_RX_DESCQ_SIZE_1K 1
1784 #define FCN_RX_DESCQ_SIZE_512 0
1785 #define FCN_RX_DESCQ_TYPE_LBN 2
1786 #define FCN_RX_DESCQ_TYPE_WIDTH 1
1787 #define FCN_RX_DESCQ_JUMBO_LBN 1
1788 #define FCN_RX_DESCQ_JUMBO_WIDTH 1
1789 #define FCN_RX_DESCQ_EN_LBN 0
1790 #define FCN_RX_DESCQ_EN_WIDTH 1
1792 /* Transmit descriptor pointer table */
1793 #define FCN_TX_DESC_PTR_TBL_KER 0x11900
1794 #define FCN_TX_DESCQ_EN_LBN 88
1795 #define FCN_TX_DESCQ_EN_WIDTH 1
1796 #define FCN_TX_DESCQ_BUF_BASE_ID_LBN 36
1797 #define FCN_TX_DESCQ_BUF_BASE_ID_WIDTH 20
1798 #define FCN_TX_DESCQ_EVQ_ID_LBN 24
1799 #define FCN_TX_DESCQ_EVQ_ID_WIDTH 12
1800 #define FCN_TX_DESCQ_OWNER_ID_LBN 10
1801 #define FCN_TX_DESCQ_OWNER_ID_WIDTH 14
1802 #define FCN_TX_DESCQ_SIZE_LBN 3
1803 #define FCN_TX_DESCQ_SIZE_WIDTH 2
1804 #define FCN_TX_DESCQ_SIZE_4K 3
1805 #define FCN_TX_DESCQ_SIZE_2K 2
1806 #define FCN_TX_DESCQ_SIZE_1K 1
1807 #define FCN_TX_DESCQ_SIZE_512 0
1808 #define FCN_TX_DESCQ_TYPE_LBN 1
1809 #define FCN_TX_DESCQ_TYPE_WIDTH 2
1810 #define FCN_TX_DESCQ_FLUSH_LBN 0
1811 #define FCN_TX_DESCQ_FLUSH_WIDTH 1
1813 /* Event queue pointer */
1814 #define FCN_EVQ_PTR_TBL_KER 0x11a00
1815 #define FCN_EVQ_EN_LBN 23
1816 #define FCN_EVQ_EN_WIDTH 1
1817 #define FCN_EVQ_SIZE_LBN 20
1818 #define FCN_EVQ_SIZE_WIDTH 3
1819 #define FCN_EVQ_SIZE_32K 6
1820 #define FCN_EVQ_SIZE_16K 5
1821 #define FCN_EVQ_SIZE_8K 4
1822 #define FCN_EVQ_SIZE_4K 3
1823 #define FCN_EVQ_SIZE_2K 2
1824 #define FCN_EVQ_SIZE_1K 1
1825 #define FCN_EVQ_SIZE_512 0
1826 #define FCN_EVQ_BUF_BASE_ID_LBN 0
1827 #define FCN_EVQ_BUF_BASE_ID_WIDTH 20
1829 /* Event queue read pointer */
1830 #define FCN_EVQ_RPTR_REG_KER 0x11b00
1831 #define FCN_EVQ_RPTR_LBN 0
1832 #define FCN_EVQ_RPTR_WIDTH 14
1833 #define FCN_EVQ_RPTR_REG_KER_DWORD ( FCN_EVQ_RPTR_REG_KER + 0 )
1834 #define FCN_EVQ_RPTR_DWORD_LBN 0
1835 #define FCN_EVQ_RPTR_DWORD_WIDTH 14
1837 /* Special buffer descriptors */
1838 #define FCN_BUF_FULL_TBL_KER 0x18000
1839 #define FCN_IP_DAT_BUF_SIZE_LBN 50
1840 #define FCN_IP_DAT_BUF_SIZE_WIDTH 1
1841 #define FCN_IP_DAT_BUF_SIZE_8K 1
1842 #define FCN_IP_DAT_BUF_SIZE_4K 0
1843 #define FCN_BUF_ADR_FBUF_LBN 14
1844 #define FCN_BUF_ADR_FBUF_WIDTH 34
1845 #define FCN_BUF_OWNER_ID_FBUF_LBN 0
1846 #define FCN_BUF_OWNER_ID_FBUF_WIDTH 14
1849 #define FALCON_MAC_REGBANK 0xe00
1850 #define FALCON_MAC_REGBANK_SIZE 0x200
1851 #define FALCON_MAC_REG_SIZE 0x10
1853 /** Offset of a MAC register within Falcon */
1854 #define FALCON_MAC_REG( efab, mac_reg ) \
1855 ( FALCON_MAC_REGBANK + \
1856 ( (efab)->port * FALCON_MAC_REGBANK_SIZE ) + \
1857 ( (mac_reg) * FALCON_MAC_REG_SIZE ) )
1858 #define FCN_MAC_DATA_LBN 0
1859 #define FCN_MAC_DATA_WIDTH 32
1861 /* Transmit descriptor */
1862 #define FCN_TX_KER_PORT_LBN 63
1863 #define FCN_TX_KER_PORT_WIDTH 1
1864 #define FCN_TX_KER_BYTE_CNT_LBN 48
1865 #define FCN_TX_KER_BYTE_CNT_WIDTH 14
1866 #define FCN_TX_KER_BUF_ADR_LBN 0
1867 #define FCN_TX_KER_BUF_ADR_WIDTH EFAB_DMA_TYPE_WIDTH ( 46 )
1869 /* Receive descriptor */
1870 #define FCN_RX_KER_BUF_SIZE_LBN 48
1871 #define FCN_RX_KER_BUF_SIZE_WIDTH 14
1872 #define FCN_RX_KER_BUF_ADR_LBN 0
1873 #define FCN_RX_KER_BUF_ADR_WIDTH EFAB_DMA_TYPE_WIDTH ( 46 )
1875 /* Event queue entries */
1876 #define FCN_EV_CODE_LBN 60
1877 #define FCN_EV_CODE_WIDTH 4
1878 #define FCN_RX_IP_EV_DECODE 0
1879 #define FCN_TX_IP_EV_DECODE 2
1880 #define FCN_DRIVER_EV_DECODE 5
1882 /* Receive events */
1883 #define FCN_RX_PORT_LBN 30
1884 #define FCN_RX_PORT_WIDTH 1
1885 #define FCN_RX_EV_BYTE_CNT_LBN 16
1886 #define FCN_RX_EV_BYTE_CNT_WIDTH 14
1887 #define FCN_RX_EV_DESC_PTR_LBN 0
1888 #define FCN_RX_EV_DESC_PTR_WIDTH 12
1890 /* Transmit events */
1891 #define FCN_TX_EV_DESC_PTR_LBN 0
1892 #define FCN_TX_EV_DESC_PTR_WIDTH 12
1894 /* Fixed special buffer numbers to use */
1895 #define FALCON_EVQ_ID 0
1896 #define FALCON_TXD_ID 1
1897 #define FALCON_RXD_ID 2
1899 #if FALCON_USE_IO_BAR
1901 /* Write dword via the I/O BAR */
1902 static inline void _falcon_writel ( struct efab_nic *efab, uint32_t value,
1903 unsigned int reg ) {
1904 outl ( reg, efab->iobase + FCN_IOM_IND_ADR_REG );
1905 outl ( value, efab->iobase + FCN_IOM_IND_DAT_REG );
1908 /* Read dword via the I/O BAR */
1909 static inline uint32_t _falcon_readl ( struct efab_nic *efab,
1910 unsigned int reg ) {
1911 outl ( reg, efab->iobase + FCN_IOM_IND_ADR_REG );
1912 return inl ( efab->iobase + FCN_IOM_IND_DAT_REG );
1915 #else /* FALCON_USE_IO_BAR */
1917 #define _falcon_writel( efab, value, reg ) \
1918 writel ( (value), (efab)->membase + (reg) )
1919 #define _falcon_readl( efab, reg ) readl ( (efab)->membase + (reg) )
1921 #endif /* FALCON_USE_IO_BAR */
1924 * Write to a Falcon register
1927 static inline void falcon_write ( struct efab_nic *efab, efab_oword_t *value,
1928 unsigned int reg ) {
1930 EFAB_REGDUMP ( "Writing register %x with " EFAB_OWORD_FMT "\n",
1931 reg, EFAB_OWORD_VAL ( *value ) );
1933 _falcon_writel ( efab, value->u32[0], reg + 0 );
1934 _falcon_writel ( efab, value->u32[1], reg + 4 );
1935 _falcon_writel ( efab, value->u32[2], reg + 8 );
1936 _falcon_writel ( efab, value->u32[3], reg + 12 );
1941 * Write to Falcon SRAM
1944 static inline void falcon_write_sram ( struct efab_nic *efab,
1945 efab_qword_t *value,
1946 unsigned int index ) {
1947 unsigned int reg = ( FCN_BUF_FULL_TBL_KER +
1948 ( index * sizeof ( *value ) ) );
1950 EFAB_REGDUMP ( "Writing SRAM register %x with " EFAB_QWORD_FMT "\n",
1951 reg, EFAB_QWORD_VAL ( *value ) );
1953 _falcon_writel ( efab, value->u32[0], reg + 0 );
1954 _falcon_writel ( efab, value->u32[1], reg + 4 );
1959 * Write dword to Falcon register that allows partial writes
1962 static inline void falcon_writel ( struct efab_nic *efab, efab_dword_t *value,
1963 unsigned int reg ) {
1964 EFAB_REGDUMP ( "Writing partial register %x with " EFAB_DWORD_FMT "\n",
1965 reg, EFAB_DWORD_VAL ( *value ) );
1966 _falcon_writel ( efab, value->u32[0], reg );
1970 * Read from a Falcon register
1973 static inline void falcon_read ( struct efab_nic *efab, efab_oword_t *value,
1974 unsigned int reg ) {
1975 value->u32[0] = _falcon_readl ( efab, reg + 0 );
1976 value->u32[1] = _falcon_readl ( efab, reg + 4 );
1977 value->u32[2] = _falcon_readl ( efab, reg + 8 );
1978 value->u32[3] = _falcon_readl ( efab, reg + 12 );
1980 EFAB_REGDUMP ( "Read from register %x, got " EFAB_OWORD_FMT "\n",
1981 reg, EFAB_OWORD_VAL ( *value ) );
1985 * Read from Falcon SRAM
1988 static inline void falcon_read_sram ( struct efab_nic *efab,
1989 efab_qword_t *value,
1990 unsigned int index ) {
1991 unsigned int reg = ( FCN_BUF_FULL_TBL_KER +
1992 ( index * sizeof ( *value ) ) );
1994 value->u32[0] = _falcon_readl ( efab, reg + 0 );
1995 value->u32[1] = _falcon_readl ( efab, reg + 4 );
1996 EFAB_REGDUMP ( "Read from SRAM register %x, got " EFAB_QWORD_FMT "\n",
1997 reg, EFAB_QWORD_VAL ( *value ) );
2001 * Read dword from a portion of a Falcon register
2004 static inline void falcon_readl ( struct efab_nic *efab, efab_dword_t *value,
2005 unsigned int reg ) {
2006 value->u32[0] = _falcon_readl ( efab, reg );
2007 EFAB_REGDUMP ( "Read from register %x, got " EFAB_DWORD_FMT "\n",
2008 reg, EFAB_DWORD_VAL ( *value ) );
2012 * Verified write to Falcon SRAM
2015 static inline void falcon_write_sram_verify ( struct efab_nic *efab,
2016 efab_qword_t *value,
2017 unsigned int index ) {
2018 efab_qword_t verify;
2020 falcon_write_sram ( efab, value, index );
2022 falcon_read_sram ( efab, &verify, index );
2023 if ( memcmp ( &verify, value, sizeof ( verify ) ) != 0 ) {
2024 printf ( "SRAM index %x failure: wrote " EFAB_QWORD_FMT
2025 " got " EFAB_QWORD_FMT "\n", index,
2026 EFAB_QWORD_VAL ( *value ),
2027 EFAB_QWORD_VAL ( verify ) );
2035 static void falcon_get_membase ( struct efab_nic *efab ) {
2036 unsigned long membase_phys;
2038 membase_phys = pci_bar_start ( efab->pci, PCI_BASE_ADDRESS_2 );
2039 efab->membase = ioremap ( membase_phys, 0x20000 );
2042 #define FCN_DUMP_REG( efab, _reg ) do { \
2044 falcon_read ( efab, ®, _reg ); \
2045 printf ( #_reg " = " EFAB_OWORD_FMT "\n", \
2046 EFAB_OWORD_VAL ( reg ) ); \
2049 #define FCN_DUMP_MAC_REG( efab, _mac_reg ) do { \
2051 efab->op->mac_readl ( efab, ®, _mac_reg ); \
2052 printf ( #_mac_reg " = " EFAB_DWORD_FMT "\n", \
2053 EFAB_DWORD_VAL ( reg ) ); \
2057 * Dump register contents (for debugging)
2059 * Marked as static inline so that it will not be compiled in if not
2062 static inline void falcon_dump_regs ( struct efab_nic *efab ) {
2063 FCN_DUMP_REG ( efab, FCN_INT_EN_REG_KER );
2064 FCN_DUMP_REG ( efab, FCN_INT_ADR_REG_KER );
2065 FCN_DUMP_REG ( efab, FCN_GLB_CTL_REG_KER );
2066 FCN_DUMP_REG ( efab, FCN_TIMER_CMD_REG_KER );
2067 FCN_DUMP_REG ( efab, FCN_SRM_RX_DC_CFG_REG_KER );
2068 FCN_DUMP_REG ( efab, FCN_SRM_TX_DC_CFG_REG_KER );
2069 FCN_DUMP_REG ( efab, FCN_RX_FILTER_CTL_REG_KER );
2070 FCN_DUMP_REG ( efab, FCN_RX_DC_CFG_REG_KER );
2071 FCN_DUMP_REG ( efab, FCN_TX_DC_CFG_REG_KER );
2072 FCN_DUMP_REG ( efab, FCN_MAC0_CTRL_REG_KER );
2073 FCN_DUMP_REG ( efab, FCN_MAC1_CTRL_REG_KER );
2074 FCN_DUMP_REG ( efab, FCN_XM_GLB_CFG_REG_P0_KER );
2075 FCN_DUMP_REG ( efab, FCN_XM_TX_CFG_REG_P0_KER );
2076 FCN_DUMP_REG ( efab, FCN_XM_RX_CFG_REG_P0_KER );
2077 FCN_DUMP_REG ( efab, FCN_RX_DESC_PTR_TBL_KER );
2078 FCN_DUMP_REG ( efab, FCN_TX_DESC_PTR_TBL_KER );
2079 FCN_DUMP_REG ( efab, FCN_EVQ_PTR_TBL_KER );
2080 FCN_DUMP_MAC_REG ( efab, GM_CFG1_REG_MAC );
2081 FCN_DUMP_MAC_REG ( efab, GM_CFG2_REG_MAC );
2082 FCN_DUMP_MAC_REG ( efab, GM_MAX_FLEN_REG_MAC );
2083 FCN_DUMP_MAC_REG ( efab, GM_MII_MGMT_CFG_REG_MAC );
2084 FCN_DUMP_MAC_REG ( efab, GM_ADR1_REG_MAC );
2085 FCN_DUMP_MAC_REG ( efab, GM_ADR2_REG_MAC );
2086 FCN_DUMP_MAC_REG ( efab, GMF_CFG0_REG_MAC );
2087 FCN_DUMP_MAC_REG ( efab, GMF_CFG1_REG_MAC );
2088 FCN_DUMP_MAC_REG ( efab, GMF_CFG2_REG_MAC );
2089 FCN_DUMP_MAC_REG ( efab, GMF_CFG3_REG_MAC );
2090 FCN_DUMP_MAC_REG ( efab, GMF_CFG4_REG_MAC );
2091 FCN_DUMP_MAC_REG ( efab, GMF_CFG5_REG_MAC );
2095 * Create special buffer
2098 static void falcon_create_special_buffer ( struct efab_nic *efab,
2099 void *addr, unsigned int index ) {
2100 efab_qword_t buf_desc;
2101 unsigned long dma_addr;
2103 memset ( addr, 0, 4096 );
2104 dma_addr = virt_to_bus ( addr );
2105 EFAB_ASSERT ( ( dma_addr & ( EFAB_BUF_ALIGN - 1 ) ) == 0 );
2106 EFAB_POPULATE_QWORD_3 ( buf_desc,
2107 FCN_IP_DAT_BUF_SIZE, FCN_IP_DAT_BUF_SIZE_4K,
2108 FCN_BUF_ADR_FBUF, ( dma_addr >> 12 ),
2109 FCN_BUF_OWNER_ID_FBUF, 0 );
2110 falcon_write_sram_verify ( efab, &buf_desc, index );
2114 * Update event queue read pointer
2117 static void falcon_eventq_read_ack ( struct efab_nic *efab ) {
2120 EFAB_ASSERT ( efab->eventq_read_ptr < EFAB_EVQ_SIZE );
2122 EFAB_POPULATE_DWORD_1 ( reg, FCN_EVQ_RPTR_DWORD,
2123 efab->eventq_read_ptr );
2124 falcon_writel ( efab, ®, FCN_EVQ_RPTR_REG_KER_DWORD );
2131 static int falcon_reset ( struct efab_nic *efab ) {
2132 efab_oword_t glb_ctl_reg_ker;
2134 /* Initiate software reset */
2135 EFAB_POPULATE_OWORD_5 ( glb_ctl_reg_ker,
2136 FCN_EXT_PHY_RST_CTL, FCN_EXCLUDE_FROM_RESET,
2137 FCN_PCIE_SD_RST_CTL, FCN_EXCLUDE_FROM_RESET,
2138 FCN_PCIX_RST_CTL, FCN_EXCLUDE_FROM_RESET,
2139 FCN_INT_RST_DUR, 0x7 /* datasheet */,
2141 falcon_write ( efab, &glb_ctl_reg_ker, FCN_GLB_CTL_REG_KER );
2143 /* Allow 20ms for reset */
2146 /* Check for device reset complete */
2147 falcon_read ( efab, &glb_ctl_reg_ker, FCN_GLB_CTL_REG_KER );
2148 if ( EFAB_OWORD_FIELD ( glb_ctl_reg_ker, FCN_SWRST ) != 0 ) {
2149 printf ( "Reset failed\n" );
2160 static int falcon_init_nic ( struct efab_nic *efab ) {
2162 efab_dword_t timer_cmd;
2164 /* Set up TX and RX descriptor caches in SRAM */
2165 EFAB_POPULATE_OWORD_1 ( reg, FCN_SRM_TX_DC_BASE_ADR,
2166 0x130000 /* recommended in datasheet */ );
2167 falcon_write ( efab, ®, FCN_SRM_TX_DC_CFG_REG_KER );
2168 EFAB_POPULATE_OWORD_1 ( reg, FCN_TX_DC_SIZE, 2 /* 32 descriptors */ );
2169 falcon_write ( efab, ®, FCN_TX_DC_CFG_REG_KER );
2170 EFAB_POPULATE_OWORD_1 ( reg, FCN_SRM_RX_DC_BASE_ADR,
2171 0x100000 /* recommended in datasheet */ );
2172 falcon_write ( efab, ®, FCN_SRM_RX_DC_CFG_REG_KER );
2173 EFAB_POPULATE_OWORD_1 ( reg, FCN_RX_DC_SIZE, 2 /* 32 descriptors */ );
2174 falcon_write ( efab, ®, FCN_RX_DC_CFG_REG_KER );
2176 /* Set number of RSS CPUs */
2177 EFAB_POPULATE_OWORD_1 ( reg, FCN_NUM_KER, 0 );
2178 falcon_write ( efab, ®, FCN_RX_FILTER_CTL_REG_KER );
2182 mentormac_reset ( efab, 1 );
2183 /* Take MAC out of reset */
2184 mentormac_reset ( efab, 0 );
2186 /* Set up event queue */
2187 falcon_create_special_buffer ( efab, efab->eventq, FALCON_EVQ_ID );
2188 EFAB_POPULATE_OWORD_3 ( reg,
2190 FCN_EVQ_SIZE, FCN_EVQ_SIZE_512,
2191 FCN_EVQ_BUF_BASE_ID, FALCON_EVQ_ID );
2192 falcon_write ( efab, ®, FCN_EVQ_PTR_TBL_KER );
2195 /* Set timer register */
2196 EFAB_POPULATE_DWORD_2 ( timer_cmd,
2197 FCN_TIMER_MODE, FCN_TIMER_MODE_DIS,
2199 falcon_writel ( efab, &timer_cmd, FCN_TIMER_CMD_REG_KER );
2202 /* Initialise event queue read pointer */
2203 falcon_eventq_read_ack ( efab );
2205 /* Set up TX descriptor ring */
2206 falcon_create_special_buffer ( efab, efab->txd, FALCON_TXD_ID );
2207 EFAB_POPULATE_OWORD_5 ( reg,
2209 FCN_TX_DESCQ_BUF_BASE_ID, FALCON_TXD_ID,
2210 FCN_TX_DESCQ_EVQ_ID, 0,
2211 FCN_TX_DESCQ_SIZE, FCN_TX_DESCQ_SIZE_512,
2212 FCN_TX_DESCQ_TYPE, 0 /* kernel queue */ );
2213 falcon_write ( efab, ®, FCN_TX_DESC_PTR_TBL_KER );
2215 /* Set up RX descriptor ring */
2216 falcon_create_special_buffer ( efab, efab->rxd, FALCON_RXD_ID );
2217 EFAB_POPULATE_OWORD_6 ( reg,
2218 FCN_RX_DESCQ_BUF_BASE_ID, FALCON_RXD_ID,
2219 FCN_RX_DESCQ_EVQ_ID, 0,
2220 FCN_RX_DESCQ_SIZE, FCN_RX_DESCQ_SIZE_512,
2221 FCN_RX_DESCQ_TYPE, 0 /* kernel queue */,
2222 FCN_RX_DESCQ_JUMBO, 1,
2223 FCN_RX_DESCQ_EN, 1 );
2224 falcon_write ( efab, ®, FCN_RX_DESC_PTR_TBL_KER );
2226 /* Program INT_ADR_REG_KER */
2227 EFAB_POPULATE_OWORD_1 ( reg,
2229 virt_to_bus ( &efab->int_ker ) );
2230 falcon_write ( efab, ®, FCN_INT_ADR_REG_KER );
2237 struct efab_spi_device {
2239 unsigned int device_id;
2240 /** Address length (in bytes) */
2241 unsigned int addr_len;
2243 unsigned int read_command;
2247 * Wait for SPI command completion
2250 static int falcon_spi_wait ( struct efab_nic *efab ) {
2257 falcon_read ( efab, ®, FCN_EE_SPI_HCMD_REG_KER );
2258 if ( EFAB_OWORD_FIELD ( reg, FCN_EE_SPI_HCMD_CMD_EN ) == 0 )
2260 } while ( ++count < 1000 );
2261 printf ( "Timed out waiting for SPI\n" );
2269 static int falcon_spi_read ( struct efab_nic *efab,
2270 struct efab_spi_device *spi,
2271 int address, void *data, unsigned int len ) {
2274 /* Program address register */
2275 EFAB_POPULATE_OWORD_1 ( reg, FCN_EE_SPI_HADR_ADR, address );
2276 falcon_write ( efab, ®, FCN_EE_SPI_HADR_REG_KER );
2278 /* Issue read command */
2279 EFAB_POPULATE_OWORD_7 ( reg,
2280 FCN_EE_SPI_HCMD_CMD_EN, 1,
2281 FCN_EE_SPI_HCMD_SF_SEL, spi->device_id,
2282 FCN_EE_SPI_HCMD_DABCNT, len,
2283 FCN_EE_SPI_HCMD_READ, FCN_EE_SPI_READ,
2284 FCN_EE_SPI_HCMD_DUBCNT, 0,
2285 FCN_EE_SPI_HCMD_ADBCNT, spi->addr_len,
2286 FCN_EE_SPI_HCMD_ENC, spi->read_command );
2287 falcon_write ( efab, ®, FCN_EE_SPI_HCMD_REG_KER );
2289 /* Wait for read to complete */
2290 if ( ! falcon_spi_wait ( efab ) )
2294 falcon_read ( efab, ®, FCN_EE_SPI_HDATA_REG_KER );
2295 memcpy ( data, ®, len );
2300 #define SPI_READ_CMD 0x03
2301 #define AT25F1024_ADDR_LEN 3
2302 #define AT25F1024_READ_CMD SPI_READ_CMD
2303 #define MC25XX640_ADDR_LEN 2
2304 #define MC25XX640_READ_CMD SPI_READ_CMD
2306 /** Falcon Flash SPI device */
2307 static struct efab_spi_device falcon_spi_flash = {
2308 .device_id = FCN_EE_SPI_FLASH,
2309 .addr_len = AT25F1024_ADDR_LEN,
2310 .read_command = AT25F1024_READ_CMD,
2313 /** Falcon EEPROM SPI device */
2314 static struct efab_spi_device falcon_spi_large_eeprom = {
2315 .device_id = FCN_EE_SPI_EEPROM,
2316 .addr_len = MC25XX640_ADDR_LEN,
2317 .read_command = MC25XX640_READ_CMD,
2320 /** Offset of MAC address within EEPROM or Flash */
2321 #define FALCON_MAC_ADDRESS_OFFSET(port) ( 0x310 + 0x08 * (port) )
2324 * Read MAC address from EEPROM
2327 static int falcon_read_eeprom ( struct efab_nic *efab ) {
2330 struct efab_spi_device *spi;
2332 /* Determine the SPI device containing the MAC address */
2333 falcon_read ( efab, ®, FCN_GPIO_CTL_REG_KER );
2334 has_flash = EFAB_OWORD_FIELD ( reg, FCN_FLASH_PRESENT );
2335 spi = has_flash ? &falcon_spi_flash : &falcon_spi_large_eeprom;
2337 return falcon_spi_read ( efab, spi,
2338 FALCON_MAC_ADDRESS_OFFSET ( efab->port ),
2339 efab->mac_addr, sizeof ( efab->mac_addr ) );
2342 /** RX descriptor */
2343 typedef efab_qword_t falcon_rx_desc_t;
2346 * Build RX descriptor
2349 static void falcon_build_rx_desc ( struct efab_nic *efab,
2350 struct efab_rx_buf *rx_buf ) {
2351 falcon_rx_desc_t *rxd;
2353 rxd = ( ( falcon_rx_desc_t * ) efab->rxd ) + rx_buf->id;
2354 EFAB_POPULATE_QWORD_2 ( *rxd,
2355 FCN_RX_KER_BUF_SIZE, EFAB_DATA_BUF_SIZE,
2357 virt_to_bus ( rx_buf->addr ) );
2361 * Update RX descriptor write pointer
2364 static void falcon_notify_rx_desc ( struct efab_nic *efab ) {
2367 EFAB_POPULATE_DWORD_1 ( reg, FCN_RX_DESC_WPTR_DWORD,
2368 efab->rx_write_ptr );
2369 falcon_writel ( efab, ®, FCN_RX_DESC_UPD_REG_KER_DWORD );
2372 /** TX descriptor */
2373 typedef efab_qword_t falcon_tx_desc_t;
2376 * Build TX descriptor
2379 static void falcon_build_tx_desc ( struct efab_nic *efab,
2380 struct efab_tx_buf *tx_buf ) {
2381 falcon_rx_desc_t *txd;
2383 txd = ( ( falcon_rx_desc_t * ) efab->txd ) + tx_buf->id;
2384 EFAB_POPULATE_QWORD_3 ( *txd,
2385 FCN_TX_KER_PORT, efab->port,
2386 FCN_TX_KER_BYTE_CNT, tx_buf->len,
2388 virt_to_bus ( tx_buf->addr ) );
2392 * Update TX descriptor write pointer
2395 static void falcon_notify_tx_desc ( struct efab_nic *efab ) {
2398 EFAB_POPULATE_DWORD_1 ( reg, FCN_TX_DESC_WPTR_DWORD,
2399 efab->tx_write_ptr );
2400 falcon_writel ( efab, ®, FCN_TX_DESC_UPD_REG_KER_DWORD );
2404 typedef efab_qword_t falcon_event_t;
2407 * Retrieve event from event queue
2410 static int falcon_fetch_event ( struct efab_nic *efab,
2411 struct efab_event *event ) {
2412 falcon_event_t *evt;
2416 /* Check for event */
2417 evt = ( ( falcon_event_t * ) efab->eventq ) + efab->eventq_read_ptr;
2418 if ( EFAB_QWORD_IS_ZERO ( *evt ) ) {
2423 DBG ( "Event is " EFAB_QWORD_FMT "\n", EFAB_QWORD_VAL ( *evt ) );
2426 ev_code = EFAB_QWORD_FIELD ( *evt, FCN_EV_CODE );
2427 switch ( ev_code ) {
2428 case FCN_TX_IP_EV_DECODE:
2429 event->type = EFAB_EV_TX;
2431 case FCN_RX_IP_EV_DECODE:
2432 event->type = EFAB_EV_RX;
2433 event->rx_id = EFAB_QWORD_FIELD ( *evt, FCN_RX_EV_DESC_PTR );
2434 event->rx_len = EFAB_QWORD_FIELD ( *evt, FCN_RX_EV_BYTE_CNT );
2435 rx_port = EFAB_QWORD_FIELD ( *evt, FCN_RX_PORT );
2436 if ( rx_port != efab->port ) {
2437 /* Ignore packets on the wrong port. We can't
2438 * just set event->type = EFAB_EV_NONE,
2439 * because then the descriptor ring won't get
2445 case FCN_DRIVER_EV_DECODE:
2446 /* Ignore start-of-day events */
2447 event->type = EFAB_EV_NONE;
2450 printf ( "Unknown event type %d\n", ev_code );
2451 event->type = EFAB_EV_NONE;
2454 /* Clear event and any pending interrupts */
2455 EFAB_ZERO_QWORD ( *evt );
2456 falcon_writel ( efab, 0, FCN_INT_ACK_KER_REG );
2459 /* Increment and update event queue read pointer */
2460 efab->eventq_read_ptr = ( ( efab->eventq_read_ptr + 1 )
2462 falcon_eventq_read_ack ( efab );
2468 * Enable/disable/generate interrupt
2471 static inline void falcon_interrupts ( struct efab_nic *efab, int enabled,
2473 efab_oword_t int_en_reg_ker;
2475 EFAB_POPULATE_OWORD_2 ( int_en_reg_ker,
2476 FCN_KER_INT_KER, force,
2477 FCN_DRV_INT_EN_KER, enabled );
2478 falcon_write ( efab, &int_en_reg_ker, FCN_INT_EN_REG_KER );
2482 * Enable/disable interrupts
2485 static void falcon_mask_irq ( struct efab_nic *efab, int enabled ) {
2486 falcon_interrupts ( efab, enabled, 0 );
2488 /* Events won't trigger interrupts until we do this */
2489 falcon_eventq_read_ack ( efab );
2494 * Generate interrupt
2497 static void falcon_generate_irq ( struct efab_nic *efab ) {
2498 falcon_interrupts ( efab, 1, 1 );
2502 * Write dword to a Falcon MAC register
2505 static void falcon_mac_writel ( struct efab_nic *efab,
2506 efab_dword_t *value, unsigned int mac_reg ) {
2509 EFAB_POPULATE_OWORD_1 ( temp, FCN_MAC_DATA,
2510 EFAB_DWORD_FIELD ( *value, FCN_MAC_DATA ) );
2511 falcon_write ( efab, &temp, FALCON_MAC_REG ( efab, mac_reg ) );
2515 * Read dword from a Falcon MAC register
2518 static void falcon_mac_readl ( struct efab_nic *efab, efab_dword_t *value,
2519 unsigned int mac_reg ) {
2522 falcon_read ( efab, &temp, FALCON_MAC_REG ( efab, mac_reg ) );
2523 EFAB_POPULATE_DWORD_1 ( *value, FCN_MAC_DATA,
2524 EFAB_OWORD_FIELD ( temp, FCN_MAC_DATA ) );
2531 static int falcon_init_mac ( struct efab_nic *efab ) {
2532 static struct efab_mentormac_parameters falcon_mentormac_params = {
2533 .gmf_cfgfrth = 0x12,
2534 .gmf_cfgftth = 0x08,
2535 .gmf_cfghwmft = 0x1c,
2542 /* Initialise PHY */
2543 alaska_init ( efab );
2545 /* Initialise MAC */
2546 mentormac_init ( efab, &falcon_mentormac_params );
2548 /* Configure the Falcon MAC wrapper */
2549 EFAB_POPULATE_OWORD_4 ( reg,
2550 FCN_XM_RX_JUMBO_MODE, 0,
2551 FCN_XM_CUT_THRU_MODE, 0,
2552 FCN_XM_TX_STAT_EN, 1,
2553 FCN_XM_RX_STAT_EN, 1);
2554 falcon_write ( efab, ®, FCN_XM_GLB_CFG_REG_P0_KER );
2556 EFAB_POPULATE_OWORD_6 ( reg,
2561 FCN_XM_WTF_DOES_THIS_DO, 1,
2563 falcon_write ( efab, ®, FCN_XM_TX_CFG_REG_P0_KER );
2565 EFAB_POPULATE_OWORD_3 ( reg,
2567 FCN_XM_AUTO_DEPAD, 1,
2568 FCN_XM_PASS_CRC_ERR, 1 );
2569 falcon_write ( efab, ®, FCN_XM_RX_CFG_REG_P0_KER );
2571 #warning "10G support not yet present"
2573 if ( efab->link_options & LPA_10000 ) {
2575 } else if ( efab->link_options & LPA_1000 ) {
2577 } else if ( efab->link_options & LPA_100 ) {
2582 EFAB_POPULATE_OWORD_5 ( reg,
2583 FCN_MAC_XOFF_VAL, 0xffff /* datasheet */,
2584 FCN_MAC_BCAD_ACPT, 1,
2586 FCN_MAC_LINK_STATUS, 1,
2587 FCN_MAC_SPEED, link_speed );
2588 falcon_write ( efab, ®, ( efab->port == 0 ?
2589 FCN_MAC0_CTRL_REG_KER : FCN_MAC1_CTRL_REG_KER ) );
2595 * Wait for GMII access to complete
2598 static int falcon_gmii_wait ( struct efab_nic *efab ) {
2599 efab_oword_t md_stat;
2602 for ( count = 0 ; count < 1000 ; count++ ) {
2604 falcon_read ( efab, &md_stat, FCN_MD_STAT_REG_KER );
2605 if ( EFAB_OWORD_FIELD ( md_stat, FCN_MD_BSY ) == 0 )
2608 printf ( "Timed out waiting for GMII\n" );
2613 static void falcon_mdio_write ( struct efab_nic *efab, int location,
2615 int phy_id = efab->port + 2;
2618 #warning "10G PHY access not yet in place"
2620 EFAB_TRACE ( "Writing GMII %d register %02x with %04x\n",
2621 phy_id, location, value );
2623 /* Check MII not currently being accessed */
2624 if ( ! falcon_gmii_wait ( efab ) )
2627 /* Write the address registers */
2628 EFAB_POPULATE_OWORD_1 ( reg, FCN_MD_PHY_ADR, 0 /* phy_id ? */ );
2629 falcon_write ( efab, ®, FCN_MD_PHY_ADR_REG_KER );
2631 EFAB_POPULATE_OWORD_2 ( reg,
2632 FCN_MD_PRT_ADR, phy_id,
2633 FCN_MD_DEV_ADR, location );
2634 falcon_write ( efab, ®, FCN_MD_ID_REG_KER );
2638 EFAB_POPULATE_OWORD_1 ( reg, FCN_MD_TXD, value );
2639 falcon_write ( efab, ®, FCN_MD_TXD_REG_KER );
2641 EFAB_POPULATE_OWORD_2 ( reg,
2644 falcon_write ( efab, ®, FCN_MD_CS_REG_KER );
2647 /* Wait for data to be written */
2648 falcon_gmii_wait ( efab );
2652 static int falcon_mdio_read ( struct efab_nic *efab, int location ) {
2653 int phy_id = efab->port + 2;
2657 /* Check MII not currently being accessed */
2658 if ( ! falcon_gmii_wait ( efab ) )
2661 /* Write the address registers */
2662 EFAB_POPULATE_OWORD_1 ( reg, FCN_MD_PHY_ADR, 0 /* phy_id ? */ );
2663 falcon_write ( efab, ®, FCN_MD_PHY_ADR_REG_KER );
2665 EFAB_POPULATE_OWORD_2 ( reg,
2666 FCN_MD_PRT_ADR, phy_id,
2667 FCN_MD_DEV_ADR, location );
2668 falcon_write ( efab, ®, FCN_MD_ID_REG_KER );
2671 /* Request data to be read */
2672 EFAB_POPULATE_OWORD_2 ( reg,
2675 falcon_write ( efab, ®, FCN_MD_CS_REG_KER );
2678 /* Wait for data to become available */
2679 falcon_gmii_wait ( efab );
2682 falcon_read ( efab, ®, FCN_MD_RXD_REG_KER );
2683 value = EFAB_OWORD_FIELD ( reg, FCN_MD_RXD );
2685 EFAB_TRACE ( "Read from GMII %d register %02x, got %04x\n",
2686 phy_id, location, value );
2691 static struct efab_operations falcon_operations = {
2692 .get_membase = falcon_get_membase,
2693 .reset = falcon_reset,
2694 .init_nic = falcon_init_nic,
2695 .read_eeprom = falcon_read_eeprom,
2696 .build_rx_desc = falcon_build_rx_desc,
2697 .notify_rx_desc = falcon_notify_rx_desc,
2698 .build_tx_desc = falcon_build_tx_desc,
2699 .notify_tx_desc = falcon_notify_tx_desc,
2700 .fetch_event = falcon_fetch_event,
2701 .mask_irq = falcon_mask_irq,
2702 .generate_irq = falcon_generate_irq,
2703 .mac_writel = falcon_mac_writel,
2704 .mac_readl = falcon_mac_readl,
2705 .init_mac = falcon_init_mac,
2706 .mdio_write = falcon_mdio_write,
2707 .mdio_read = falcon_mdio_read,
2710 /**************************************************************************
2712 * Etherfabric abstraction layer
2714 **************************************************************************
2718 * Push RX buffer to RXD ring
2721 static inline void efab_push_rx_buffer ( struct efab_nic *efab,
2722 struct efab_rx_buf *rx_buf ) {
2723 /* Create RX descriptor */
2724 rx_buf->id = efab->rx_write_ptr;
2725 efab->op->build_rx_desc ( efab, rx_buf );
2727 /* Update RX write pointer */
2728 efab->rx_write_ptr = ( efab->rx_write_ptr + 1 ) % EFAB_RXD_SIZE;
2729 efab->op->notify_rx_desc ( efab );
2731 DBG ( "Added RX id %x\n", rx_buf->id );
2735 * Push TX buffer to TXD ring
2738 static inline void efab_push_tx_buffer ( struct efab_nic *efab,
2739 struct efab_tx_buf *tx_buf ) {
2740 /* Create TX descriptor */
2741 tx_buf->id = efab->tx_write_ptr;
2742 efab->op->build_tx_desc ( efab, tx_buf );
2744 /* Update TX write pointer */
2745 efab->tx_write_ptr = ( efab->tx_write_ptr + 1 ) % EFAB_TXD_SIZE;
2746 efab->op->notify_tx_desc ( efab );
2748 DBG ( "Added TX id %x\n", tx_buf->id );
2752 * Initialise MAC and wait for link up
2755 static int efab_init_mac ( struct efab_nic *efab ) {
2758 /* This can take several seconds */
2759 printf ( "Waiting for link.." );
2763 if ( ! efab->op->init_mac ( efab ) ) {
2764 printf ( "failed\n" );
2767 if ( efab->link_up ) {
2768 /* PHY init printed the message for us */
2772 } while ( ++count < 5 );
2773 printf ( "timed out\n" );
2782 static int efab_init_nic ( struct efab_nic *efab ) {
2786 if ( ! efab->op->reset ( efab ) )
2789 /* Initialise NIC */
2790 if ( ! efab->op->init_nic ( efab ) )
2793 /* Push RX descriptors */
2794 for ( i = 0 ; i < EFAB_RX_BUFS ; i++ ) {
2795 efab_push_rx_buffer ( efab, &efab->rx_bufs[i] );
2798 /* Read MAC address from EEPROM */
2799 if ( ! efab->op->read_eeprom ( efab ) )
2801 efab->mac_addr[ETH_ALEN-1] += efab->port;
2803 /* Initialise MAC and wait for link up */
2804 if ( ! efab_init_mac ( efab ) )
2810 /**************************************************************************
2812 * Etherboot interface
2814 **************************************************************************
2817 /**************************************************************************
2818 POLL - Wait for a frame
2819 ***************************************************************************/
2820 static int etherfabric_poll ( struct nic *nic, int retrieve ) {
2821 struct efab_nic *efab = nic->priv_data;
2822 struct efab_event event;
2823 static struct efab_rx_buf *rx_buf = NULL;
2826 /* Process the event queue until we hit either a packet
2827 * received event or an empty event slot.
2829 while ( ( rx_buf == NULL ) &&
2830 efab->op->fetch_event ( efab, &event ) ) {
2831 if ( event.type == EFAB_EV_TX ) {
2832 /* TX completed - mark as done */
2833 DBG ( "TX id %x complete\n",
2835 efab->tx_in_progress = 0;
2836 } else if ( event.type == EFAB_EV_RX ) {
2837 /* RX - find corresponding buffer */
2838 for ( i = 0 ; i < EFAB_RX_BUFS ; i++ ) {
2839 if ( efab->rx_bufs[i].id == event.rx_id ) {
2840 rx_buf = &efab->rx_bufs[i];
2841 rx_buf->len = event.rx_len;
2842 DBG ( "RX id %x (len %x) received\n",
2843 rx_buf->id, rx_buf->len );
2848 printf ( "Invalid RX ID %x\n", event.rx_id );
2850 } else if ( event.type == EFAB_EV_NONE ) {
2851 DBG ( "Ignorable event\n" );
2853 DBG ( "Unknown event\n" );
2857 /* If there is no packet, return 0 */
2861 /* If we don't want to retrieve it just yet, return 1 */
2865 /* Copy packet contents */
2866 nic->packetlen = rx_buf->len;
2867 memcpy ( nic->packet, rx_buf->addr, nic->packetlen );
2869 /* Give this buffer back to the NIC */
2870 efab_push_rx_buffer ( efab, rx_buf );
2872 /* Prepare to receive next packet */
2878 /**************************************************************************
2879 TRANSMIT - Transmit a frame
2880 ***************************************************************************/
2881 static void etherfabric_transmit ( struct nic *nic, const char *dest,
2882 unsigned int type, unsigned int size,
2883 const char *data ) {
2884 struct efab_nic *efab = nic->priv_data;
2885 unsigned int nstype = htons ( type );
2887 /* We can only transmit one packet at a time; a TX completion
2888 * event must be received before we can transmit the next
2889 * packet. Since there is only one static TX buffer, we don't
2890 * worry unduly about overflow, but we report it anyway.
2892 if ( efab->tx_in_progress ) {
2893 printf ( "TX overflow!\n" );
2896 /* Fill TX buffer, pad to ETH_ZLEN */
2897 memcpy ( efab->tx_buf.addr, dest, ETH_ALEN );
2898 memcpy ( efab->tx_buf.addr + ETH_ALEN, nic->node_addr, ETH_ALEN );
2899 memcpy ( efab->tx_buf.addr + 2 * ETH_ALEN, &nstype, 2 );
2900 memcpy ( efab->tx_buf.addr + ETH_HLEN, data, size );
2902 while ( size < ETH_ZLEN ) {
2903 efab->tx_buf.addr[size++] = '\0';
2905 efab->tx_buf.len = size;
2907 /* Push TX descriptor */
2908 efab_push_tx_buffer ( efab, &efab->tx_buf );
2910 /* There is no way to wait for TX complete (i.e. TX buffer
2911 * available to re-use for the next transmit) without reading
2912 * from the event queue. We therefore simply leave the TX
2913 * buffer marked as "in use" until a TX completion event
2914 * happens to be picked up by a call to etherfabric_poll().
2916 efab->tx_in_progress = 1;
2921 /**************************************************************************
2922 DISABLE - Turn off ethernet interface
2923 ***************************************************************************/
2924 static void etherfabric_disable ( struct nic *nic,
2925 struct pci_device *pci __unused ) {
2926 struct efab_nic *efab = nic->priv_data;
2928 efab->op->reset ( efab );
2929 if ( efab->membase )
2930 iounmap ( efab->membase );
2933 /**************************************************************************
2934 IRQ - handle interrupts
2935 ***************************************************************************/
2936 static void etherfabric_irq ( struct nic *nic, irq_action_t action ) {
2937 struct efab_nic *efab = nic->priv_data;
2941 efab->op->mask_irq ( efab, 1 );
2944 efab->op->mask_irq ( efab, 0 );
2947 /* Force NIC to generate a receive interrupt */
2948 efab->op->generate_irq ( efab );
2955 static struct nic_operations etherfabric_operations = {
2956 .connect = dummy_connect,
2957 .poll = etherfabric_poll,
2958 .transmit = etherfabric_transmit,
2959 .irq = etherfabric_irq,
2962 /**************************************************************************
2963 PROBE - Look for an adapter, this routine's visible to the outside
2964 ***************************************************************************/
2965 static int etherfabric_probe ( struct dev *dev, struct pci_device *pci ) {
2966 struct nic *nic = ( struct nic * ) dev;
2967 static struct efab_nic efab;
2968 static int nic_port = 1;
2969 struct efab_buffers *buffers;
2972 /* Set up our private data structure */
2973 nic->priv_data = &efab;
2974 memset ( &efab, 0, sizeof ( efab ) );
2975 memset ( &efab_buffers, 0, sizeof ( efab_buffers ) );
2977 /* Hook in appropriate operations table. Do this early. */
2978 if ( pci->device == EF1002_DEVID ) {
2979 efab.op = &ef1002_operations;
2981 efab.op = &falcon_operations;
2984 /* Initialise efab data structure */
2986 buffers = ( ( struct efab_buffers * )
2987 ( ( ( void * ) &efab_buffers ) +
2988 ( - virt_to_bus ( &efab_buffers ) ) % EFAB_BUF_ALIGN ) );
2989 efab.eventq = buffers->eventq;
2990 efab.txd = buffers->txd;
2991 efab.rxd = buffers->rxd;
2992 efab.tx_buf.addr = buffers->tx_buf;
2993 for ( i = 0 ; i < EFAB_RX_BUFS ; i++ ) {
2994 efab.rx_bufs[i].addr = buffers->rx_buf[i];
2997 /* Enable the PCI device */
2998 adjust_pci_device ( pci );
2999 nic->ioaddr = pci->ioaddr & ~3;
3000 nic->irqno = pci->irq;
3002 /* Get iobase/membase */
3003 efab.iobase = nic->ioaddr;
3004 efab.op->get_membase ( &efab );
3006 /* Switch NIC ports (i.e. try different ports on each probe) */
3007 nic_port = 1 - nic_port;
3008 efab.port = nic_port;
3010 /* Initialise hardware */
3011 if ( ! efab_init_nic ( &efab ) )
3013 memcpy ( nic->node_addr, efab.mac_addr, ETH_ALEN );
3016 printf ( "Found EtherFabric %s NIC %!\n", pci->name, nic->node_addr );
3018 /* point to NIC specific routines */
3019 nic->nic_op = ðerfabric_operations;
3024 static struct pci_device_id etherfabric_nics[] = {
3025 PCI_ROM(0x1924, 0xC101, "ef1002", "EtherFabric EF1002"),
3026 PCI_ROM(0x1924, 0x0703, "falcon", "EtherFabric Falcon"),
3029 PCI_DRIVER ( etherfabric_driver, etherfabric_nics, PCI_NO_CLASS );
3031 DRIVER ( "EFAB", nic_driver, pci_driver, etherfabric_driver,
3032 etherfabric_probe, etherfabric_disable );