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 struct efab_i2c_interface;
201 /** i2c bus direct control methods */
202 struct efab_i2c_bit_operations {
203 /** Set state of SDA line */
204 void ( * setsda ) ( struct efab_i2c_interface *i2c );
205 /** Set state of SCL line */
206 void ( * setscl ) ( struct efab_i2c_interface *i2c );
207 /** Get state of SDA line */
208 int ( * getsda ) ( struct efab_i2c_interface *i2c );
209 /** Get state of SCL line */
210 int ( * getscl ) ( struct efab_i2c_interface *i2c );
211 /** Delay between each bit operation */
213 /** Delay between each byte write */
217 /** An i2c interface */
218 struct efab_i2c_interface {
219 /** Attached Etherfabric NIC */
220 struct efab_nic *efab;
221 /** I2C bus control methods */
222 struct efab_i2c_bit_operations *op;
223 /** Current output state of SDA line */
224 unsigned int sda : 1;
225 /** Current output state of SCL line */
226 unsigned int scl : 1;
230 * SDA and SCL line read/writes
234 static inline void setsda ( struct efab_i2c_interface *i2c, int state ) {
235 udelay ( i2c->op->udelay );
237 i2c->op->setsda ( i2c );
238 udelay ( i2c->op->udelay );
241 static inline void setscl ( struct efab_i2c_interface *i2c, int state ) {
242 udelay ( i2c->op->udelay );
244 i2c->op->setscl ( i2c );
245 udelay ( i2c->op->udelay );
248 static inline int getsda ( struct efab_i2c_interface *i2c ) {
251 udelay ( i2c->op->udelay );
252 sda = i2c->op->getsda ( i2c );
253 udelay ( i2c->op->udelay );
257 static inline int getscl ( struct efab_i2c_interface *i2c ) {
260 udelay ( i2c->op->udelay );
261 scl = i2c->op->getscl ( i2c );
262 udelay ( i2c->op->udelay );
267 * i2c low-level protocol operations
271 static inline void i2c_release ( struct efab_i2c_interface *i2c ) {
272 EFAB_ASSERT ( i2c->scl );
273 EFAB_ASSERT ( i2c->sda );
277 EFAB_ASSERT ( getsda ( i2c ) == 1 );
278 EFAB_ASSERT ( getscl ( i2c ) == 1 );
281 static inline void i2c_start ( struct efab_i2c_interface *i2c ) {
282 /* We may be restarting immediately after a {send,recv}_bit,
283 * so SCL will not necessarily already be high.
285 EFAB_ASSERT ( i2c->sda );
292 static inline void i2c_send_bit ( struct efab_i2c_interface *i2c, int bit ) {
293 EFAB_ASSERT ( ! i2c->scl );
300 static inline int i2c_recv_bit ( struct efab_i2c_interface *i2c ) {
303 EFAB_ASSERT ( ! i2c->scl );
304 EFAB_ASSERT ( i2c->sda );
306 bit = getsda ( i2c );
311 static inline void i2c_stop ( struct efab_i2c_interface *i2c ) {
312 EFAB_ASSERT ( ! i2c->scl );
319 * i2c mid-level protocol operations
323 static int i2c_send_byte ( struct efab_i2c_interface *i2c, uint8_t byte ) {
327 for ( i = 0 ; i < 8 ; i++ ) {
328 i2c_send_bit ( i2c, !! ( byte & 0x80 ) );
332 /* Check for acknowledgement from slave */
333 return ( i2c_recv_bit ( i2c ) == 0 ? 1 : 0 );
336 static uint8_t i2c_recv_byte ( struct efab_i2c_interface *i2c, int ack ) {
341 for ( i = 0 ; i < 8 ; i++ ) {
342 value = ( value << 1 ) | i2c_recv_bit ( i2c );
346 i2c_send_bit ( i2c, ( ack ? 0 : 1 ) );
351 static inline uint8_t i2c_read_cmd ( uint8_t device_id ) {
352 return ( ( device_id << 1 ) | 1 );
355 static inline uint8_t i2c_write_cmd ( uint8_t device_id ) {
356 return ( ( device_id << 1 ) | 0 );
359 static int efab_i2c_fast_read ( struct efab_i2c_interface *i2c,
360 uint8_t device_id, uint8_t offset,
361 uint8_t *data, unsigned int len ) {
365 EFAB_ASSERT ( getsda ( i2c ) == 1 );
366 EFAB_ASSERT ( getscl ( i2c ) == 1 );
367 EFAB_ASSERT ( data != NULL );
368 EFAB_ASSERT ( len >= 1 );
370 /* Select device and starting offset */
372 if ( ! i2c_send_byte ( i2c, i2c_write_cmd ( device_id ) ) )
374 if ( ! i2c_send_byte ( i2c, offset ) )
377 /* Read data from device */
379 if ( ! i2c_send_byte ( i2c, i2c_read_cmd ( device_id ) ) )
381 for ( i = 0 ; i < ( len - 1 ); i++ ) {
382 /* Read and acknowledge all but the last byte */
383 data[i] = i2c_recv_byte ( i2c, 1 );
385 /* Read last byte with no acknowledgement */
386 data[i] = i2c_recv_byte ( i2c, 0 );
396 /**************************************************************************
400 **************************************************************************
404 #define MII_BMSR 0x01 /* Basic mode status register */
405 #define MII_ADVERTISE 0x04 /* Advertisement control register */
406 #define MII_LPA 0x05 /* Link partner ability register*/
407 #define GMII_GTCR 0x09 /* 1000BASE-T control register */
408 #define GMII_GTSR 0x0a /* 1000BASE-T status register */
409 #define GMII_PSSR 0x11 /* PHY-specific status register */
411 /* Basic mode status register. */
412 #define BMSR_LSTATUS 0x0004 /* Link status */
414 /* Link partner ability register. */
415 #define LPA_10HALF 0x0020 /* Can do 10mbps half-duplex */
416 #define LPA_10FULL 0x0040 /* Can do 10mbps full-duplex */
417 #define LPA_100HALF 0x0080 /* Can do 100mbps half-duplex */
418 #define LPA_100FULL 0x0100 /* Can do 100mbps full-duplex */
419 #define LPA_100BASE4 0x0200 /* Can do 100mbps 4k packets */
420 #define LPA_PAUSE 0x0400 /* Bit 10 - MAC pause */
422 /* Pseudo extensions to the link partner ability register */
423 #define LPA_1000FULL 0x00020000
424 #define LPA_1000HALF 0x00010000
426 #define LPA_100 (LPA_100FULL | LPA_100HALF | LPA_100BASE4)
427 #define LPA_1000 ( LPA_1000FULL | LPA_1000HALF )
428 #define LPA_DUPLEX ( LPA_10FULL | LPA_100FULL | LPA_1000FULL )
430 /* Mask of bits not associated with speed or duplexity. */
431 #define LPA_OTHER ~( LPA_10FULL | LPA_10HALF | LPA_100FULL | \
432 LPA_100HALF | LPA_1000FULL | LPA_1000HALF )
434 /* PHY-specific status register */
435 #define PSSR_LSTATUS 0x0400 /* Bit 10 - link status */
438 * Retrieve GMII autonegotiation advertised abilities
441 static unsigned int gmii_autoneg_advertised ( struct efab_nic *efab ) {
442 unsigned int mii_advertise;
443 unsigned int gmii_advertise;
445 /* Extended bits are in bits 8 and 9 of GMII_GTCR */
446 mii_advertise = efab->op->mdio_read ( efab, MII_ADVERTISE );
447 gmii_advertise = ( ( efab->op->mdio_read ( efab, GMII_GTCR ) >> 8 )
449 return ( ( gmii_advertise << 16 ) | mii_advertise );
453 * Retrieve GMII autonegotiation link partner abilities
456 static unsigned int gmii_autoneg_lpa ( struct efab_nic *efab ) {
457 unsigned int mii_lpa;
458 unsigned int gmii_lpa;
460 /* Extended bits are in bits 10 and 11 of GMII_GTSR */
461 mii_lpa = efab->op->mdio_read ( efab, MII_LPA );
462 gmii_lpa = ( efab->op->mdio_read ( efab, GMII_GTSR ) >> 10 ) & 0x03;
463 return ( ( gmii_lpa << 16 ) | mii_lpa );
467 * Calculate GMII autonegotiated link technology
470 static unsigned int gmii_nway_result ( unsigned int negotiated ) {
471 unsigned int other_bits;
473 /* Mask out the speed and duplexity bits */
474 other_bits = negotiated & LPA_OTHER;
476 if ( negotiated & LPA_1000FULL )
477 return ( other_bits | LPA_1000FULL );
478 else if ( negotiated & LPA_1000HALF )
479 return ( other_bits | LPA_1000HALF );
480 else if ( negotiated & LPA_100FULL )
481 return ( other_bits | LPA_100FULL );
482 else if ( negotiated & LPA_100BASE4 )
483 return ( other_bits | LPA_100BASE4 );
484 else if ( negotiated & LPA_100HALF )
485 return ( other_bits | LPA_100HALF );
486 else if ( negotiated & LPA_10FULL )
487 return ( other_bits | LPA_10FULL );
488 else return ( other_bits | LPA_10HALF );
492 * Check GMII PHY link status
495 static int gmii_link_ok ( struct efab_nic *efab ) {
499 /* BMSR is latching - it returns "link down" if the link has
500 * been down at any point since the last read. To get a
501 * real-time status, we therefore read the register twice and
502 * use the result of the second read.
504 efab->op->mdio_read ( efab, MII_BMSR );
505 status = efab->op->mdio_read ( efab, MII_BMSR );
507 /* Read the PHY-specific Status Register. This is
508 * non-latching, so we need do only a single read.
510 phy_status = efab->op->mdio_read ( efab, GMII_PSSR );
512 return ( ( status & BMSR_LSTATUS ) && ( phy_status & PSSR_LSTATUS ) );
515 /**************************************************************************
519 **************************************************************************
523 * Initialise Alaska PHY
526 static void alaska_init ( struct efab_nic *efab ) {
527 unsigned int advertised, lpa;
529 /* Read link up status */
530 efab->link_up = gmii_link_ok ( efab );
532 if ( ! efab->link_up )
535 /* Determine link options from PHY. */
536 advertised = gmii_autoneg_advertised ( efab );
537 lpa = gmii_autoneg_lpa ( efab );
538 efab->link_options = gmii_nway_result ( advertised & lpa );
540 printf ( "%dMbps %s-duplex (%04x,%04x)\n",
541 ( efab->link_options & LPA_1000 ? 1000 :
542 ( efab->link_options & LPA_100 ? 100 : 10 ) ),
543 ( efab->link_options & LPA_DUPLEX ? "full" : "half" ),
547 /**************************************************************************
551 **************************************************************************
554 /* GMAC configuration register 1 */
555 #define GM_CFG1_REG_MAC 0x00
556 #define GM_SW_RST_LBN 31
557 #define GM_SW_RST_WIDTH 1
558 #define GM_RX_FC_EN_LBN 5
559 #define GM_RX_FC_EN_WIDTH 1
560 #define GM_TX_FC_EN_LBN 4
561 #define GM_TX_FC_EN_WIDTH 1
562 #define GM_RX_EN_LBN 2
563 #define GM_RX_EN_WIDTH 1
564 #define GM_TX_EN_LBN 0
565 #define GM_TX_EN_WIDTH 1
567 /* GMAC configuration register 2 */
568 #define GM_CFG2_REG_MAC 0x01
569 #define GM_PAMBL_LEN_LBN 12
570 #define GM_PAMBL_LEN_WIDTH 4
571 #define GM_IF_MODE_LBN 8
572 #define GM_IF_MODE_WIDTH 2
573 #define GM_PAD_CRC_EN_LBN 2
574 #define GM_PAD_CRC_EN_WIDTH 1
576 #define GM_FD_WIDTH 1
578 /* GMAC maximum frame length register */
579 #define GM_MAX_FLEN_REG_MAC 0x04
580 #define GM_MAX_FLEN_LBN 0
581 #define GM_MAX_FLEN_WIDTH 16
583 /* GMAC MII management configuration register */
584 #define GM_MII_MGMT_CFG_REG_MAC 0x08
585 #define GM_MGMT_CLK_SEL_LBN 0
586 #define GM_MGMT_CLK_SEL_WIDTH 3
588 /* GMAC MII management command register */
589 #define GM_MII_MGMT_CMD_REG_MAC 0x09
590 #define GM_MGMT_SCAN_CYC_LBN 1
591 #define GM_MGMT_SCAN_CYC_WIDTH 1
592 #define GM_MGMT_RD_CYC_LBN 0
593 #define GM_MGMT_RD_CYC_WIDTH 1
595 /* GMAC MII management address register */
596 #define GM_MII_MGMT_ADR_REG_MAC 0x0a
597 #define GM_MGMT_PHY_ADDR_LBN 8
598 #define GM_MGMT_PHY_ADDR_WIDTH 5
599 #define GM_MGMT_REG_ADDR_LBN 0
600 #define GM_MGMT_REG_ADDR_WIDTH 5
602 /* GMAC MII management control register */
603 #define GM_MII_MGMT_CTL_REG_MAC 0x0b
604 #define GM_MGMT_CTL_LBN 0
605 #define GM_MGMT_CTL_WIDTH 16
607 /* GMAC MII management status register */
608 #define GM_MII_MGMT_STAT_REG_MAC 0x0c
609 #define GM_MGMT_STAT_LBN 0
610 #define GM_MGMT_STAT_WIDTH 16
612 /* GMAC MII management indicators register */
613 #define GM_MII_MGMT_IND_REG_MAC 0x0d
614 #define GM_MGMT_BUSY_LBN 0
615 #define GM_MGMT_BUSY_WIDTH 1
617 /* GMAC station address register 1 */
618 #define GM_ADR1_REG_MAC 0x10
619 #define GM_HWADDR_5_LBN 24
620 #define GM_HWADDR_5_WIDTH 8
621 #define GM_HWADDR_4_LBN 16
622 #define GM_HWADDR_4_WIDTH 8
623 #define GM_HWADDR_3_LBN 8
624 #define GM_HWADDR_3_WIDTH 8
625 #define GM_HWADDR_2_LBN 0
626 #define GM_HWADDR_2_WIDTH 8
628 /* GMAC station address register 2 */
629 #define GM_ADR2_REG_MAC 0x11
630 #define GM_HWADDR_1_LBN 24
631 #define GM_HWADDR_1_WIDTH 8
632 #define GM_HWADDR_0_LBN 16
633 #define GM_HWADDR_0_WIDTH 8
635 /* GMAC FIFO configuration register 0 */
636 #define GMF_CFG0_REG_MAC 0x12
637 #define GMF_FTFENREQ_LBN 12
638 #define GMF_FTFENREQ_WIDTH 1
639 #define GMF_STFENREQ_LBN 11
640 #define GMF_STFENREQ_WIDTH 1
641 #define GMF_FRFENREQ_LBN 10
642 #define GMF_FRFENREQ_WIDTH 1
643 #define GMF_SRFENREQ_LBN 9
644 #define GMF_SRFENREQ_WIDTH 1
645 #define GMF_WTMENREQ_LBN 8
646 #define GMF_WTMENREQ_WIDTH 1
648 /* GMAC FIFO configuration register 1 */
649 #define GMF_CFG1_REG_MAC 0x13
650 #define GMF_CFGFRTH_LBN 16
651 #define GMF_CFGFRTH_WIDTH 5
652 #define GMF_CFGXOFFRTX_LBN 0
653 #define GMF_CFGXOFFRTX_WIDTH 16
655 /* GMAC FIFO configuration register 2 */
656 #define GMF_CFG2_REG_MAC 0x14
657 #define GMF_CFGHWM_LBN 16
658 #define GMF_CFGHWM_WIDTH 6
659 #define GMF_CFGLWM_LBN 0
660 #define GMF_CFGLWM_WIDTH 6
662 /* GMAC FIFO configuration register 3 */
663 #define GMF_CFG3_REG_MAC 0x15
664 #define GMF_CFGHWMFT_LBN 16
665 #define GMF_CFGHWMFT_WIDTH 6
666 #define GMF_CFGFTTH_LBN 0
667 #define GMF_CFGFTTH_WIDTH 6
669 /* GMAC FIFO configuration register 4 */
670 #define GMF_CFG4_REG_MAC 0x16
671 #define GMF_HSTFLTRFRM_PAUSE_LBN 12
672 #define GMF_HSTFLTRFRM_PAUSE_WIDTH 12
674 /* GMAC FIFO configuration register 5 */
675 #define GMF_CFG5_REG_MAC 0x17
676 #define GMF_CFGHDPLX_LBN 22
677 #define GMF_CFGHDPLX_WIDTH 1
678 #define GMF_CFGBYTMODE_LBN 19
679 #define GMF_CFGBYTMODE_WIDTH 1
680 #define GMF_HSTDRPLT64_LBN 18
681 #define GMF_HSTDRPLT64_WIDTH 1
682 #define GMF_HSTFLTRFRMDC_PAUSE_LBN 12
683 #define GMF_HSTFLTRFRMDC_PAUSE_WIDTH 1
685 struct efab_mentormac_parameters {
697 static void mentormac_reset ( struct efab_nic *efab ) {
701 /* Take into reset */
702 EFAB_POPULATE_DWORD_1 ( reg, GM_SW_RST, 1 );
703 efab->op->mac_writel ( efab, ®, GM_CFG1_REG_MAC );
706 /* Take out of reset */
707 EFAB_POPULATE_DWORD_1 ( reg, GM_SW_RST, 0 );
708 efab->op->mac_writel ( efab, ®, GM_CFG1_REG_MAC );
711 /* Mentor MAC connects both PHYs to MAC 0 */
712 save_port = efab->port;
714 /* Configure GMII interface so PHY is accessible. Note that
715 * GMII interface is connected only to port 0, and that on
716 * Falcon this is a no-op.
718 EFAB_POPULATE_DWORD_1 ( reg, GM_MGMT_CLK_SEL, 0x4 );
719 efab->op->mac_writel ( efab, ®, GM_MII_MGMT_CFG_REG_MAC );
721 efab->port = save_port;
725 * Initialise Mentor MAC
728 static void mentormac_init ( struct efab_nic *efab,
729 struct efab_mentormac_parameters *params ) {
730 int pause, if_mode, full_duplex, bytemode, half_duplex;
733 /* Configuration register 1 */
734 pause = ( efab->link_options & LPA_PAUSE ) ? 1 : 0;
735 if ( ! ( efab->link_options & LPA_DUPLEX ) ) {
736 /* Half-duplex operation requires TX flow control */
739 EFAB_POPULATE_DWORD_4 ( reg,
744 efab->op->mac_writel ( efab, ®, GM_CFG1_REG_MAC );
747 /* Configuration register 2 */
748 if_mode = ( efab->link_options & LPA_1000 ) ? 2 : 1;
749 full_duplex = ( efab->link_options & LPA_DUPLEX ) ? 1 : 0;
750 EFAB_POPULATE_DWORD_4 ( reg,
754 GM_PAMBL_LEN, 0x7 /* ? */ );
755 efab->op->mac_writel ( efab, ®, GM_CFG2_REG_MAC );
758 /* Max frame len register */
759 EFAB_POPULATE_DWORD_1 ( reg, GM_MAX_FLEN, ETH_FRAME_LEN );
760 efab->op->mac_writel ( efab, ®, GM_MAX_FLEN_REG_MAC );
763 /* FIFO configuration register 0 */
764 EFAB_POPULATE_DWORD_5 ( reg,
770 efab->op->mac_writel ( efab, ®, GMF_CFG0_REG_MAC );
773 /* FIFO configuration register 1 */
774 EFAB_POPULATE_DWORD_2 ( reg,
775 GMF_CFGFRTH, params->gmf_cfgfrth,
776 GMF_CFGXOFFRTX, 0xffff );
777 efab->op->mac_writel ( efab, ®, GMF_CFG1_REG_MAC );
780 /* FIFO configuration register 2 */
781 EFAB_POPULATE_DWORD_2 ( reg,
782 GMF_CFGHWM, params->gmf_cfghwm,
783 GMF_CFGLWM, params->gmf_cfglwm );
784 efab->op->mac_writel ( efab, ®, GMF_CFG2_REG_MAC );
787 /* FIFO configuration register 3 */
788 EFAB_POPULATE_DWORD_2 ( reg,
789 GMF_CFGHWMFT, params->gmf_cfghwmft,
790 GMF_CFGFTTH, params->gmf_cfgftth );
791 efab->op->mac_writel ( efab, ®, GMF_CFG3_REG_MAC );
794 /* FIFO configuration register 4 */
795 EFAB_POPULATE_DWORD_1 ( reg, GMF_HSTFLTRFRM_PAUSE, 1 );
796 efab->op->mac_writel ( efab, ®, GMF_CFG4_REG_MAC );
799 /* FIFO configuration register 5 */
800 bytemode = ( efab->link_options & LPA_1000 ) ? 1 : 0;
801 half_duplex = ( efab->link_options & LPA_DUPLEX ) ? 0 : 1;
802 efab->op->mac_readl ( efab, ®, GMF_CFG5_REG_MAC );
803 EFAB_SET_DWORD_FIELD ( reg, GMF_CFGBYTMODE, bytemode );
804 EFAB_SET_DWORD_FIELD ( reg, GMF_CFGHDPLX, half_duplex );
805 EFAB_SET_DWORD_FIELD ( reg, GMF_HSTDRPLT64, half_duplex );
806 EFAB_SET_DWORD_FIELD ( reg, GMF_HSTFLTRFRMDC_PAUSE, 0 );
807 efab->op->mac_writel ( efab, ®, GMF_CFG5_REG_MAC );
811 EFAB_POPULATE_DWORD_4 ( reg,
812 GM_HWADDR_5, efab->mac_addr[5],
813 GM_HWADDR_4, efab->mac_addr[4],
814 GM_HWADDR_3, efab->mac_addr[3],
815 GM_HWADDR_2, efab->mac_addr[2] );
816 efab->op->mac_writel ( efab, ®, GM_ADR1_REG_MAC );
818 EFAB_POPULATE_DWORD_2 ( reg,
819 GM_HWADDR_1, efab->mac_addr[1],
820 GM_HWADDR_0, efab->mac_addr[0] );
821 efab->op->mac_writel ( efab, ®, GM_ADR2_REG_MAC );
826 * Wait for GMII access to complete
829 static int mentormac_gmii_wait ( struct efab_nic *efab ) {
831 efab_dword_t indicator;
833 for ( count = 0 ; count < 1000 ; count++ ) {
835 efab->op->mac_readl ( efab, &indicator,
836 GM_MII_MGMT_IND_REG_MAC );
837 if ( EFAB_DWORD_FIELD ( indicator, GM_MGMT_BUSY ) == 0 )
840 printf ( "Timed out waiting for GMII\n" );
845 * Write a GMII register
848 static void mentormac_mdio_write ( struct efab_nic *efab, int phy_id,
849 int location, int value ) {
853 EFAB_TRACE ( "Writing GMII %d register %02x with %04x\n", phy_id,
856 /* Mentor MAC connects both PHYs to MAC 0 */
857 save_port = efab->port;
860 /* Check MII not currently being accessed */
861 if ( ! mentormac_gmii_wait ( efab ) )
864 /* Write the address register */
865 EFAB_POPULATE_DWORD_2 ( reg,
866 GM_MGMT_PHY_ADDR, phy_id,
867 GM_MGMT_REG_ADDR, location );
868 efab->op->mac_writel ( efab, ®, GM_MII_MGMT_ADR_REG_MAC );
872 EFAB_POPULATE_DWORD_1 ( reg, GM_MGMT_CTL, value );
873 efab->op->mac_writel ( efab, ®, GM_MII_MGMT_CTL_REG_MAC );
875 /* Wait for data to be written */
876 mentormac_gmii_wait ( efab );
879 /* Restore efab->port */
880 efab->port = save_port;
884 * Read a GMII register
887 static int mentormac_mdio_read ( struct efab_nic *efab, int phy_id,
893 /* Mentor MAC connects both PHYs to MAC 0 */
894 save_port = efab->port;
897 /* Check MII not currently being accessed */
898 if ( ! mentormac_gmii_wait ( efab ) )
901 /* Write the address register */
902 EFAB_POPULATE_DWORD_2 ( reg,
903 GM_MGMT_PHY_ADDR, phy_id,
904 GM_MGMT_REG_ADDR, location );
905 efab->op->mac_writel ( efab, ®, GM_MII_MGMT_ADR_REG_MAC );
908 /* Request data to be read */
909 EFAB_POPULATE_DWORD_1 ( reg, GM_MGMT_RD_CYC, 1 );
910 efab->op->mac_writel ( efab, ®, GM_MII_MGMT_CMD_REG_MAC );
912 /* Wait for data to be become available */
913 if ( mentormac_gmii_wait ( efab ) ) {
915 efab->op->mac_readl ( efab, ®, GM_MII_MGMT_STAT_REG_MAC );
916 value = EFAB_DWORD_FIELD ( reg, GM_MGMT_STAT );
917 EFAB_TRACE ( "Read from GMII %d register %02x, got %04x\n",
918 phy_id, location, value );
921 /* Signal completion */
922 EFAB_ZERO_DWORD ( reg );
923 efab->op->mac_writel ( efab, ®, GM_MII_MGMT_CMD_REG_MAC );
927 /* Restore efab->port */
928 efab->port = save_port;
933 /**************************************************************************
937 **************************************************************************
940 /** Control and General Status */
941 #define EF1_CTR_GEN_STATUS0_REG 0x0
942 #define EF1_MASTER_EVENTS_LBN 12
943 #define EF1_MASTER_EVENTS_WIDTH 1
944 #define EF1_TX_ENGINE_EN_LBN 19
945 #define EF1_TX_ENGINE_EN_WIDTH 1
946 #define EF1_RX_ENGINE_EN_LBN 18
947 #define EF1_RX_ENGINE_EN_WIDTH 1
948 #define EF1_TURBO2_LBN 17
949 #define EF1_TURBO2_WIDTH 1
950 #define EF1_TURBO1_LBN 16
951 #define EF1_TURBO1_WIDTH 1
952 #define EF1_TURBO3_LBN 14
953 #define EF1_TURBO3_WIDTH 1
954 #define EF1_LB_RESET_LBN 3
955 #define EF1_LB_RESET_WIDTH 1
956 #define EF1_MAC_RESET_LBN 2
957 #define EF1_MAC_RESET_WIDTH 1
958 #define EF1_CAM_ENABLE_LBN 1
959 #define EF1_CAM_ENABLE_WIDTH 1
962 #define EF1_IRQ_SRC_REG 0x0008
965 #define EF1_IRQ_MASK_REG 0x000c
966 #define EF1_IRQ_PHY1_LBN 11
967 #define EF1_IRQ_PHY1_WIDTH 1
968 #define EF1_IRQ_PHY0_LBN 10
969 #define EF1_IRQ_PHY0_WIDTH 1
970 #define EF1_IRQ_SERR_LBN 7
971 #define EF1_IRQ_SERR_WIDTH 1
972 #define EF1_IRQ_EVQ_LBN 3
973 #define EF1_IRQ_EVQ_WIDTH 1
975 /** Event generation */
976 #define EF1_EVT3_REG 0x38
979 #define EF1_EEPROM_REG 0x40
980 #define EF1_EEPROM_SDA_LBN 31
981 #define EF1_EEPROM_SDA_WIDTH 1
982 #define EF1_EEPROM_SCL_LBN 30
983 #define EF1_EEPROM_SCL_WIDTH 1
984 #define EF1_JTAG_DISCONNECT_LBN 17
985 #define EF1_JTAG_DISCONNECT_WIDTH 1
987 /** Control register 2 */
988 #define EF1_CTL2_REG 0x4c
989 #define EF1_PLL_TRAP_LBN 31
990 #define EF1_PLL_TRAP_WIDTH 1
991 #define EF1_MEM_MAP_4MB_LBN 11
992 #define EF1_MEM_MAP_4MB_WIDTH 1
993 #define EF1_EV_INTR_CLR_WRITE_LBN 6
994 #define EF1_EV_INTR_CLR_WRITE_WIDTH 1
995 #define EF1_BURST_MERGE_LBN 5
996 #define EF1_BURST_MERGE_WIDTH 1
997 #define EF1_CLEAR_NULL_PAD_LBN 4
998 #define EF1_CLEAR_NULL_PAD_WIDTH 1
999 #define EF1_SW_RESET_LBN 2
1000 #define EF1_SW_RESET_WIDTH 1
1001 #define EF1_INTR_AFTER_EVENT_LBN 1
1002 #define EF1_INTR_AFTER_EVENT_WIDTH 1
1005 #define EF1_EVENT_FIFO_REG 0x50
1007 /** Event FIFO count */
1008 #define EF1_EVENT_FIFO_COUNT_REG 0x5c
1009 #define EF1_EV_COUNT_LBN 0
1010 #define EF1_EV_COUNT_WIDTH 16
1012 /** TX DMA control and status */
1013 #define EF1_DMA_TX_CSR_REG 0x80
1014 #define EF1_DMA_TX_CSR_CHAIN_EN_LBN 8
1015 #define EF1_DMA_TX_CSR_CHAIN_EN_WIDTH 1
1016 #define EF1_DMA_TX_CSR_ENABLE_LBN 4
1017 #define EF1_DMA_TX_CSR_ENABLE_WIDTH 1
1018 #define EF1_DMA_TX_CSR_INT_EN_LBN 0
1019 #define EF1_DMA_TX_CSR_INT_EN_WIDTH 1
1021 /** RX DMA control and status */
1022 #define EF1_DMA_RX_CSR_REG 0xa0
1023 #define EF1_DMA_RX_ABOVE_1GB_EN_LBN 6
1024 #define EF1_DMA_RX_ABOVE_1GB_EN_WIDTH 1
1025 #define EF1_DMA_RX_BELOW_1MB_EN_LBN 5
1026 #define EF1_DMA_RX_BELOW_1MB_EN_WIDTH 1
1027 #define EF1_DMA_RX_CSR_ENABLE_LBN 0
1028 #define EF1_DMA_RX_CSR_ENABLE_WIDTH 1
1030 /** Level 5 watermark register (in MAC space) */
1031 #define EF1_GMF_L5WM_REG_MAC 0x20
1032 #define EF1_L5WM_LBN 0
1033 #define EF1_L5WM_WIDTH 32
1036 #define EF1_GM_MAC_CLK_REG 0x112000
1037 #define EF1_GM_PORT0_MAC_CLK_LBN 0
1038 #define EF1_GM_PORT0_MAC_CLK_WIDTH 1
1039 #define EF1_GM_PORT1_MAC_CLK_LBN 1
1040 #define EF1_GM_PORT1_MAC_CLK_WIDTH 1
1042 /** TX descriptor FIFO */
1043 #define EF1_TX_DESC_FIFO 0x141000
1044 #define EF1_TX_KER_EVQ_LBN 80
1045 #define EF1_TX_KER_EVQ_WIDTH 12
1046 #define EF1_TX_KER_IDX_LBN 64
1047 #define EF1_TX_KER_IDX_WIDTH 16
1048 #define EF1_TX_KER_MODE_LBN 63
1049 #define EF1_TX_KER_MODE_WIDTH 1
1050 #define EF1_TX_KER_PORT_LBN 60
1051 #define EF1_TX_KER_PORT_WIDTH 1
1052 #define EF1_TX_KER_CONT_LBN 56
1053 #define EF1_TX_KER_CONT_WIDTH 1
1054 #define EF1_TX_KER_BYTE_CNT_LBN 32
1055 #define EF1_TX_KER_BYTE_CNT_WIDTH 24
1056 #define EF1_TX_KER_BUF_ADR_LBN 0
1057 #define EF1_TX_KER_BUF_ADR_WIDTH 32
1059 /** TX descriptor FIFO flush */
1060 #define EF1_TX_DESC_FIFO_FLUSH 0x141ffc
1062 /** RX descriptor FIFO */
1063 #define EF1_RX_DESC_FIFO 0x145000
1064 #define EF1_RX_KER_EVQ_LBN 48
1065 #define EF1_RX_KER_EVQ_WIDTH 12
1066 #define EF1_RX_KER_IDX_LBN 32
1067 #define EF1_RX_KER_IDX_WIDTH 16
1068 #define EF1_RX_KER_BUF_ADR_LBN 0
1069 #define EF1_RX_KER_BUF_ADR_WIDTH 32
1071 /** RX descriptor FIFO flush */
1072 #define EF1_RX_DESC_FIFO_FLUSH 0x145ffc
1075 #define EF1_CAM_BASE 0x1c0000
1076 #define EF1_CAM_WTF_DOES_THIS_DO_LBN 0
1077 #define EF1_CAM_WTF_DOES_THIS_DO_WIDTH 32
1079 /** Event queue pointers */
1080 #define EF1_EVQ_PTR_BASE 0x260000
1081 #define EF1_EVQ_SIZE_LBN 29
1082 #define EF1_EVQ_SIZE_WIDTH 2
1083 #define EF1_EVQ_SIZE_4K 3
1084 #define EF1_EVQ_SIZE_2K 2
1085 #define EF1_EVQ_SIZE_1K 1
1086 #define EF1_EVQ_SIZE_512 0
1087 #define EF1_EVQ_BUF_BASE_ID_LBN 0
1088 #define EF1_EVQ_BUF_BASE_ID_WIDTH 29
1091 #define EF1002_MAC_REGBANK 0x110000
1092 #define EF1002_MAC_REGBANK_SIZE 0x1000
1093 #define EF1002_MAC_REG_SIZE 0x08
1095 /** Offset of a MAC register within EF1002 */
1096 #define EF1002_MAC_REG( efab, mac_reg ) \
1097 ( EF1002_MAC_REGBANK + \
1098 ( (efab)->port * EF1002_MAC_REGBANK_SIZE ) + \
1099 ( (mac_reg) * EF1002_MAC_REG_SIZE ) )
1101 /* Event queue entries */
1102 #define EF1_EV_CODE_LBN 20
1103 #define EF1_EV_CODE_WIDTH 8
1104 #define EF1_RX_EV_DECODE 0x01
1105 #define EF1_TX_EV_DECODE 0x02
1106 #define EF1_TIMER_EV_DECODE 0x0b
1107 #define EF1_DRV_GEN_EV_DECODE 0x0f
1109 /* Receive events */
1110 #define EF1_RX_EV_LEN_LBN 48
1111 #define EF1_RX_EV_LEN_WIDTH 16
1112 #define EF1_RX_EV_PORT_LBN 17
1113 #define EF1_RX_EV_PORT_WIDTH 3
1114 #define EF1_RX_EV_OK_LBN 16
1115 #define EF1_RX_EV_OK_WIDTH 1
1116 #define EF1_RX_EV_IDX_LBN 0
1117 #define EF1_RX_EV_IDX_WIDTH 16
1119 /* Transmit events */
1120 #define EF1_TX_EV_PORT_LBN 17
1121 #define EF1_TX_EV_PORT_WIDTH 3
1122 #define EF1_TX_EV_OK_LBN 16
1123 #define EF1_TX_EV_OK_WIDTH 1
1124 #define EF1_TX_EV_IDX_LBN 0
1125 #define EF1_TX_EV_IDX_WIDTH 16
1128 * Write dword to EF1002 register
1131 static inline void ef1002_writel ( struct efab_nic *efab, efab_dword_t *value,
1132 unsigned int reg ) {
1133 EFAB_REGDUMP ( "Writing register %x with " EFAB_DWORD_FMT "\n",
1134 reg, EFAB_DWORD_VAL ( *value ) );
1135 writel ( value->u32[0], efab->membase + reg );
1139 * Read dword from an EF1002 register
1142 static inline void ef1002_readl ( struct efab_nic *efab, efab_dword_t *value,
1143 unsigned int reg ) {
1144 value->u32[0] = readl ( efab->membase + reg );
1145 EFAB_REGDUMP ( "Read from register %x, got " EFAB_DWORD_FMT "\n",
1146 reg, EFAB_DWORD_VAL ( *value ) );
1150 * Read dword from an EF1002 register, silently
1153 static inline void ef1002_readl_silent ( struct efab_nic *efab,
1154 efab_dword_t *value,
1155 unsigned int reg ) {
1156 value->u32[0] = readl ( efab->membase + reg );
1163 static void ef1002_get_membase ( struct efab_nic *efab ) {
1164 unsigned long membase_phys;
1166 membase_phys = pci_bar_start ( efab->pci, PCI_BASE_ADDRESS_0 );
1167 efab->membase = ioremap ( membase_phys, 0x800000 );
1170 /** PCI registers to backup/restore over a device reset */
1171 static const unsigned int efab_pci_reg_addr[] = {
1172 PCI_COMMAND, 0x0c /* PCI_CACHE_LINE_SIZE */,
1173 PCI_BASE_ADDRESS_0, PCI_BASE_ADDRESS_1, PCI_BASE_ADDRESS_2,
1174 PCI_BASE_ADDRESS_3, PCI_ROM_ADDRESS, PCI_INTERRUPT_LINE,
1176 /** Number of registers in efab_pci_reg_addr */
1177 #define EFAB_NUM_PCI_REG \
1178 ( sizeof ( efab_pci_reg_addr ) / sizeof ( efab_pci_reg_addr[0] ) )
1179 /** PCI configuration space backup */
1180 struct efab_pci_reg {
1181 uint32_t reg[EFAB_NUM_PCI_REG];
1188 static int ef1002_reset ( struct efab_nic *efab ) {
1189 struct efab_pci_reg pci_reg;
1190 struct pci_device *pci_dev = efab->pci;
1195 /* Back up PCI configuration registers */
1196 for ( i = 0 ; i < EFAB_NUM_PCI_REG ; i++ ) {
1197 pci_read_config_dword ( pci_dev, efab_pci_reg_addr[i],
1201 /* Reset the whole device. */
1202 EFAB_POPULATE_DWORD_1 ( reg, EF1_SW_RESET, 1 );
1203 ef1002_writel ( efab, ®, EF1_CTL2_REG );
1206 /* Restore PCI configuration space */
1207 for ( i = 0 ; i < EFAB_NUM_PCI_REG ; i++ ) {
1208 pci_write_config_dword ( pci_dev, efab_pci_reg_addr[i],
1212 /* Verify PCI configuration space */
1213 for ( i = 0 ; i < EFAB_NUM_PCI_REG ; i++ ) {
1214 pci_read_config_dword ( pci_dev, efab_pci_reg_addr[i], &tmp );
1215 if ( tmp != pci_reg.reg[i] ) {
1216 printf ( "PCI restore failed on register %02x "
1217 "(is %08x, should be %08x); reboot\n",
1218 i, tmp, pci_reg.reg[i] );
1223 /* Verify device reset complete */
1224 ef1002_readl ( efab, ®, EF1_CTR_GEN_STATUS0_REG );
1225 if ( EFAB_DWORD_IS_ALL_ONES ( reg ) ) {
1226 printf ( "Reset failed\n" );
1237 static int ef1002_init_nic ( struct efab_nic *efab ) {
1240 /* No idea what CAM is, but the 'datasheet' says that we have
1241 * to write these values in at start of day
1243 EFAB_POPULATE_DWORD_1 ( reg, EF1_CAM_WTF_DOES_THIS_DO, 0x6 );
1244 ef1002_writel ( efab, ®, EF1_CAM_BASE + 0x20018 );
1246 EFAB_POPULATE_DWORD_1 ( reg, EF1_CAM_WTF_DOES_THIS_DO, 0x01000000 );
1247 ef1002_writel ( efab, ®, EF1_CAM_BASE + 0x00018 );
1250 /* General control register 0 */
1251 ef1002_readl ( efab, ®, EF1_CTR_GEN_STATUS0_REG );
1252 EFAB_SET_DWORD_FIELD ( reg, EF1_MASTER_EVENTS, 0 );
1253 EFAB_SET_DWORD_FIELD ( reg, EF1_TX_ENGINE_EN, 0 );
1254 EFAB_SET_DWORD_FIELD ( reg, EF1_RX_ENGINE_EN, 0 );
1255 EFAB_SET_DWORD_FIELD ( reg, EF1_TURBO2, 1 );
1256 EFAB_SET_DWORD_FIELD ( reg, EF1_TURBO1, 1 );
1257 EFAB_SET_DWORD_FIELD ( reg, EF1_TURBO3, 1 );
1258 EFAB_SET_DWORD_FIELD ( reg, EF1_CAM_ENABLE, 1 );
1259 ef1002_writel ( efab, ®, EF1_CTR_GEN_STATUS0_REG );
1262 /* General control register 2 */
1263 ef1002_readl ( efab, ®, EF1_CTL2_REG );
1264 EFAB_SET_DWORD_FIELD ( reg, EF1_PLL_TRAP, 1 );
1265 EFAB_SET_DWORD_FIELD ( reg, EF1_MEM_MAP_4MB, 0 );
1266 EFAB_SET_DWORD_FIELD ( reg, EF1_EV_INTR_CLR_WRITE, 0 );
1267 EFAB_SET_DWORD_FIELD ( reg, EF1_BURST_MERGE, 0 );
1268 EFAB_SET_DWORD_FIELD ( reg, EF1_CLEAR_NULL_PAD, 1 );
1269 EFAB_SET_DWORD_FIELD ( reg, EF1_INTR_AFTER_EVENT, 1 );
1270 ef1002_writel ( efab, ®, EF1_CTL2_REG );
1274 ef1002_readl ( efab, ®, EF1_DMA_RX_CSR_REG );
1275 EFAB_SET_DWORD_FIELD ( reg, EF1_DMA_RX_CSR_ENABLE, 1 );
1276 EFAB_SET_DWORD_FIELD ( reg, EF1_DMA_RX_BELOW_1MB_EN, 1 );
1277 EFAB_SET_DWORD_FIELD ( reg, EF1_DMA_RX_ABOVE_1GB_EN, 1 );
1278 ef1002_writel ( efab, ®, EF1_DMA_RX_CSR_REG );
1282 ef1002_readl ( efab, ®, EF1_DMA_TX_CSR_REG );
1283 EFAB_SET_DWORD_FIELD ( reg, EF1_DMA_TX_CSR_CHAIN_EN, 1 );
1284 EFAB_SET_DWORD_FIELD ( reg, EF1_DMA_TX_CSR_ENABLE, 0 /* ?? */ );
1285 EFAB_SET_DWORD_FIELD ( reg, EF1_DMA_TX_CSR_INT_EN, 0 /* ?? */ );
1286 ef1002_writel ( efab, ®, EF1_DMA_TX_CSR_REG );
1289 /* Disconnect the JTAG chain. Read-modify-write is impossible
1290 * on the I2C control bits, since reading gives the state of
1291 * the line inputs rather than the last written state.
1293 ef1002_readl ( efab, ®, EF1_EEPROM_REG );
1294 EFAB_SET_DWORD_FIELD ( reg, EF1_EEPROM_SDA, 1 );
1295 EFAB_SET_DWORD_FIELD ( reg, EF1_EEPROM_SCL, 1 );
1296 EFAB_SET_DWORD_FIELD ( reg, EF1_JTAG_DISCONNECT, 1 );
1297 ef1002_writel ( efab, ®, EF1_EEPROM_REG );
1300 /* Flush descriptor queues */
1301 EFAB_ZERO_DWORD ( reg );
1302 ef1002_writel ( efab, ®, EF1_RX_DESC_FIFO_FLUSH );
1303 ef1002_writel ( efab, ®, EF1_TX_DESC_FIFO_FLUSH );
1308 mentormac_reset ( efab );
1313 /** I2C ID of the EEPROM */
1314 #define EF1002_EEPROM_I2C_ID 0x50
1316 /** Offset of MAC address within EEPROM */
1317 #define EF1002_EEPROM_HWADDR_OFFSET 0x0
1319 /** Set status of i2c outputs */
1320 static void ef1002_setsdascl ( struct efab_i2c_interface *i2c ) {
1321 efab_dword_t eeprom_reg;
1323 EFAB_POPULATE_DWORD_2 ( eeprom_reg,
1324 EF1_EEPROM_SDA, i2c->sda,
1325 EF1_EEPROM_SCL, i2c->scl );
1326 ef1002_writel ( i2c->efab, &eeprom_reg, EF1_EEPROM_REG );
1329 /** Get status of i2c SDA line */
1330 static int ef1002_getsda ( struct efab_i2c_interface *i2c ) {
1331 efab_dword_t eeprom_reg;
1333 ef1002_readl ( i2c->efab, &eeprom_reg, EF1_EEPROM_REG );
1334 return EFAB_DWORD_FIELD ( eeprom_reg, EF1_EEPROM_SDA );
1337 /** Get status of i2c SCL line */
1338 static int ef1002_getscl ( struct efab_i2c_interface *i2c ) {
1339 efab_dword_t eeprom_reg;
1341 ef1002_readl ( i2c->efab, &eeprom_reg, EF1_EEPROM_REG );
1342 return EFAB_DWORD_FIELD ( eeprom_reg, EF1_EEPROM_SCL );
1345 /** i2c bit-bashing data structure template */
1346 static struct efab_i2c_bit_operations ef1002_i2c_bit_operations = {
1347 .setsda = ef1002_setsdascl,
1348 .setscl = ef1002_setsdascl,
1349 .getsda = ef1002_getsda,
1350 .getscl = ef1002_getscl,
1356 * Read MAC address from EEPROM
1359 static int ef1002_read_eeprom ( struct efab_nic *efab ) {
1360 struct efab_i2c_interface i2c = {
1362 .op = &ef1002_i2c_bit_operations,
1367 if ( ! efab_i2c_fast_read ( &i2c, EF1002_EEPROM_I2C_ID,
1368 EF1002_EEPROM_HWADDR_OFFSET,
1369 efab->mac_addr, ETH_ALEN ) )
1371 efab->mac_addr[ETH_ALEN-1] += efab->port;
1375 /** RX descriptor */
1376 typedef efab_qword_t ef1002_rx_desc_t;
1379 * Build RX descriptor
1382 static void ef1002_build_rx_desc ( struct efab_nic *efab,
1383 struct efab_rx_buf *rx_buf ) {
1384 ef1002_rx_desc_t rxd;
1386 EFAB_POPULATE_QWORD_3 ( rxd,
1388 EF1_RX_KER_IDX, rx_buf->id,
1390 virt_to_bus ( rx_buf->addr ) );
1391 ef1002_writel ( efab, &rxd.dword[0], EF1_RX_DESC_FIFO + 0 );
1393 ef1002_writel ( efab, &rxd.dword[1], EF1_RX_DESC_FIFO + 4 );
1398 * Update RX descriptor write pointer
1401 static void ef1002_notify_rx_desc ( struct efab_nic *efab __unused ) {
1405 /** TX descriptor */
1406 typedef efab_oword_t ef1002_tx_desc_t;
1409 * Build TX descriptor
1412 static void ef1002_build_tx_desc ( struct efab_nic *efab,
1413 struct efab_tx_buf *tx_buf ) {
1414 ef1002_tx_desc_t txd;
1416 EFAB_POPULATE_OWORD_7 ( txd,
1418 EF1_TX_KER_IDX, tx_buf->id,
1419 EF1_TX_KER_MODE, 0 /* IP mode */,
1420 EF1_TX_KER_PORT, efab->port,
1422 EF1_TX_KER_BYTE_CNT, tx_buf->len,
1424 virt_to_bus ( tx_buf->addr ) );
1426 ef1002_writel ( efab, &txd.dword[0], EF1_TX_DESC_FIFO + 0 );
1427 ef1002_writel ( efab, &txd.dword[1], EF1_TX_DESC_FIFO + 4 );
1429 ef1002_writel ( efab, &txd.dword[2], EF1_TX_DESC_FIFO + 8 );
1434 * Update TX descriptor write pointer
1437 static void ef1002_notify_tx_desc ( struct efab_nic *efab __unused ) {
1442 typedef efab_qword_t ef1002_event_t;
1445 * Retrieve event from event queue
1448 static int ef1002_fetch_event ( struct efab_nic *efab,
1449 struct efab_event *event ) {
1454 /* Check event FIFO depth */
1455 ef1002_readl_silent ( efab, ®, EF1_EVENT_FIFO_COUNT_REG );
1456 words = EFAB_DWORD_FIELD ( reg, EF1_EV_COUNT );
1460 /* Read event data */
1461 ef1002_readl ( efab, ®, EF1_EVENT_FIFO_REG );
1462 DBG ( "Event is " EFAB_DWORD_FMT "\n", EFAB_DWORD_VAL ( reg ) );
1465 ev_code = EFAB_DWORD_FIELD ( reg, EF1_EV_CODE );
1466 switch ( ev_code ) {
1467 case EF1_TX_EV_DECODE:
1468 event->type = EFAB_EV_TX;
1470 case EF1_RX_EV_DECODE:
1471 event->type = EFAB_EV_RX;
1472 event->rx_id = EFAB_DWORD_FIELD ( reg, EF1_RX_EV_IDX );
1473 /* RX len not available via event FIFO */
1474 event->rx_len = ETH_FRAME_LEN;
1476 case EF1_TIMER_EV_DECODE:
1477 /* These are safe to ignore. We seem to get some at
1478 * start of day, presumably due to the timers starting
1479 * up with random contents.
1481 event->type = EFAB_EV_NONE;
1484 printf ( "Unknown event type %d\n", ev_code );
1485 event->type = EFAB_EV_NONE;
1488 /* Clear any pending interrupts */
1489 ef1002_readl ( efab, ®, EF1_IRQ_SRC_REG );
1495 * Enable/disable interrupts
1498 static void ef1002_mask_irq ( struct efab_nic *efab, int enabled ) {
1499 efab_dword_t irq_mask;
1501 EFAB_POPULATE_DWORD_2 ( irq_mask,
1502 EF1_IRQ_SERR, enabled,
1503 EF1_IRQ_EVQ, enabled );
1504 ef1002_writel ( efab, &irq_mask, EF1_IRQ_MASK_REG );
1508 * Generate interrupt
1511 static void ef1002_generate_irq ( struct efab_nic *efab ) {
1512 ef1002_event_t test_event;
1514 EFAB_POPULATE_QWORD_1 ( test_event,
1515 EF1_EV_CODE, EF1_DRV_GEN_EV_DECODE );
1516 ef1002_writel ( efab, &test_event.dword[0], EF1_EVT3_REG );
1520 * Write dword to an EF1002 MAC register
1523 static void ef1002_mac_writel ( struct efab_nic *efab,
1524 efab_dword_t *value, unsigned int mac_reg ) {
1525 ef1002_writel ( efab, value, EF1002_MAC_REG ( efab, mac_reg ) );
1529 * Read dword from an EF1002 MAC register
1532 static void ef1002_mac_readl ( struct efab_nic *efab,
1533 efab_dword_t *value, unsigned int mac_reg ) {
1534 ef1002_readl ( efab, value, EF1002_MAC_REG ( efab, mac_reg ) );
1541 static int ef1002_init_mac ( struct efab_nic *efab ) {
1542 static struct efab_mentormac_parameters ef1002_mentormac_params = {
1543 .gmf_cfgfrth = 0x13,
1544 .gmf_cfgftth = 0x10,
1545 .gmf_cfghwmft = 0x555,
1550 unsigned int mac_clk;
1552 /* Initialise PHY */
1553 alaska_init ( efab );
1555 /* Initialise MAC */
1556 mentormac_init ( efab, &ef1002_mentormac_params );
1558 /* Write Level 5 watermark register */
1559 EFAB_POPULATE_DWORD_1 ( reg, EF1_L5WM, 0x10040000 );
1560 efab->op->mac_writel ( efab, ®, EF1_GMF_L5WM_REG_MAC );
1563 /* Set MAC clock speed */
1564 ef1002_readl ( efab, ®, EF1_GM_MAC_CLK_REG );
1565 mac_clk = ( efab->link_options & LPA_1000 ) ? 0 : 1;
1566 if ( efab->port == 0 ) {
1567 EFAB_SET_DWORD_FIELD ( reg, EF1_GM_PORT0_MAC_CLK, mac_clk );
1569 EFAB_SET_DWORD_FIELD ( reg, EF1_GM_PORT1_MAC_CLK, mac_clk );
1571 ef1002_writel ( efab, ®, EF1_GM_MAC_CLK_REG );
1578 static void ef1002_mdio_write ( struct efab_nic *efab, int location,
1580 mentormac_mdio_write ( efab, efab->port + 2, location, value );
1584 static int ef1002_mdio_read ( struct efab_nic *efab, int location ) {
1585 return mentormac_mdio_read ( efab, efab->port + 2, location );
1588 static struct efab_operations ef1002_operations = {
1589 .get_membase = ef1002_get_membase,
1590 .reset = ef1002_reset,
1591 .init_nic = ef1002_init_nic,
1592 .read_eeprom = ef1002_read_eeprom,
1593 .build_rx_desc = ef1002_build_rx_desc,
1594 .notify_rx_desc = ef1002_notify_rx_desc,
1595 .build_tx_desc = ef1002_build_tx_desc,
1596 .notify_tx_desc = ef1002_notify_tx_desc,
1597 .fetch_event = ef1002_fetch_event,
1598 .mask_irq = ef1002_mask_irq,
1599 .generate_irq = ef1002_generate_irq,
1600 .mac_writel = ef1002_mac_writel,
1601 .mac_readl = ef1002_mac_readl,
1602 .init_mac = ef1002_init_mac,
1603 .mdio_write = ef1002_mdio_write,
1604 .mdio_read = ef1002_mdio_read,
1607 /**************************************************************************
1611 **************************************************************************
1614 /* I/O BAR address register */
1615 #define FCN_IOM_IND_ADR_REG 0x0
1617 /* I/O BAR data register */
1618 #define FCN_IOM_IND_DAT_REG 0x4
1620 /* Interrupt enable register */
1621 #define FCN_INT_EN_REG_KER 0x0010
1622 #define FCN_MEM_PERR_INT_EN_KER_LBN 5
1623 #define FCN_MEM_PERR_INT_EN_KER_WIDTH 1
1624 #define FCN_KER_INT_CHAR_LBN 4
1625 #define FCN_KER_INT_CHAR_WIDTH 1
1626 #define FCN_KER_INT_KER_LBN 3
1627 #define FCN_KER_INT_KER_WIDTH 1
1628 #define FCN_ILL_ADR_ERR_INT_EN_KER_LBN 2
1629 #define FCN_ILL_ADR_ERR_INT_EN_KER_WIDTH 1
1630 #define FCN_SRM_PERR_INT_EN_KER_LBN 1
1631 #define FCN_SRM_PERR_INT_EN_KER_WIDTH 1
1632 #define FCN_DRV_INT_EN_KER_LBN 0
1633 #define FCN_DRV_INT_EN_KER_WIDTH 1
1635 /* Interrupt status register */
1636 #define FCN_INT_ADR_REG_KER 0x0030
1637 #define FCN_INT_ADR_KER_LBN 0
1638 #define FCN_INT_ADR_KER_WIDTH EFAB_DMA_TYPE_WIDTH ( 64 )
1640 /* Interrupt acknowledge register */
1641 #define FCN_INT_ACK_KER_REG 0x0050
1643 /* SPI host command register */
1644 #define FCN_EE_SPI_HCMD_REG_KER 0x0100
1645 #define FCN_EE_SPI_HCMD_CMD_EN_LBN 31
1646 #define FCN_EE_SPI_HCMD_CMD_EN_WIDTH 1
1647 #define FCN_EE_WR_TIMER_ACTIVE_LBN 28
1648 #define FCN_EE_WR_TIMER_ACTIVE_WIDTH 1
1649 #define FCN_EE_SPI_HCMD_SF_SEL_LBN 24
1650 #define FCN_EE_SPI_HCMD_SF_SEL_WIDTH 1
1651 #define FCN_EE_SPI_EEPROM 0
1652 #define FCN_EE_SPI_FLASH 1
1653 #define FCN_EE_SPI_HCMD_DABCNT_LBN 16
1654 #define FCN_EE_SPI_HCMD_DABCNT_WIDTH 5
1655 #define FCN_EE_SPI_HCMD_READ_LBN 15
1656 #define FCN_EE_SPI_HCMD_READ_WIDTH 1
1657 #define FCN_EE_SPI_READ 1
1658 #define FCN_EE_SPI_WRITE 0
1659 #define FCN_EE_SPI_HCMD_DUBCNT_LBN 12
1660 #define FCN_EE_SPI_HCMD_DUBCNT_WIDTH 2
1661 #define FCN_EE_SPI_HCMD_ADBCNT_LBN 8
1662 #define FCN_EE_SPI_HCMD_ADBCNT_WIDTH 2
1663 #define FCN_EE_SPI_HCMD_ENC_LBN 0
1664 #define FCN_EE_SPI_HCMD_ENC_WIDTH 8
1666 /* SPI host address register */
1667 #define FCN_EE_SPI_HADR_REG_KER 0x0110
1668 #define FCN_EE_SPI_HADR_DUBYTE_LBN 24
1669 #define FCN_EE_SPI_HADR_DUBYTE_WIDTH 8
1670 #define FCN_EE_SPI_HADR_ADR_LBN 0
1671 #define FCN_EE_SPI_HADR_ADR_WIDTH 24
1673 /* SPI host data register */
1674 #define FCN_EE_SPI_HDATA_REG_KER 0x0120
1675 #define FCN_EE_SPI_HDATA3_LBN 96
1676 #define FCN_EE_SPI_HDATA3_WIDTH 32
1677 #define FCN_EE_SPI_HDATA2_LBN 64
1678 #define FCN_EE_SPI_HDATA2_WIDTH 32
1679 #define FCN_EE_SPI_HDATA1_LBN 32
1680 #define FCN_EE_SPI_HDATA1_WIDTH 32
1681 #define FCN_EE_SPI_HDATA0_LBN 0
1682 #define FCN_EE_SPI_HDATA0_WIDTH 32
1684 /* GPIO control register */
1685 #define FCN_GPIO_CTL_REG_KER 0x0210
1686 #define FCN_FLASH_PRESENT_LBN 7
1687 #define FCN_FLASH_PRESENT_WIDTH 1
1688 #define FCN_EEPROM_PRESENT_LBN 6
1689 #define FCN_EEPROM_PRESENT_WIDTH 1
1691 /* Global control register */
1692 #define FCN_GLB_CTL_REG_KER 0x0220
1693 #define FCN_EXT_PHY_RST_CTL_LBN 63
1694 #define FCN_EXT_PHY_RST_CTL_WIDTH 1
1695 #define FCN_PCIE_SD_RST_CTL_LBN 61
1696 #define FCN_PCIE_SD_RST_CTL_WIDTH 1
1697 #define FCN_PCIX_RST_CTL_LBN 60
1698 #define FCN_PCIX_RST_CTL_WIDTH 1
1699 #define FCN_RST_EXT_PHY_LBN 31
1700 #define FCN_RST_EXT_PHY_WIDTH 1
1701 #define FCN_INT_RST_DUR_LBN 4
1702 #define FCN_INT_RST_DUR_WIDTH 3
1703 #define FCN_EXT_PHY_RST_DUR_LBN 1
1704 #define FCN_EXT_PHY_RST_DUR_WIDTH 3
1705 #define FCN_SWRST_LBN 0
1706 #define FCN_SWRST_WIDTH 1
1707 #define FCN_INCLUDE_IN_RESET 0
1708 #define FCN_EXCLUDE_FROM_RESET 1
1710 /* Timer table for kernel access */
1711 #define FCN_TIMER_CMD_REG_KER 0x420
1712 #define FCN_TIMER_MODE_LBN 12
1713 #define FCN_TIMER_MODE_WIDTH 2
1714 #define FCN_TIMER_MODE_DIS 0
1715 #define FCN_TIMER_MODE_INT_HLDOFF 1
1716 #define FCN_TIMER_VAL_LBN 0
1717 #define FCN_TIMER_VAL_WIDTH 12
1719 /* SRAM receive descriptor cache configuration register */
1720 #define FCN_SRM_RX_DC_CFG_REG_KER 0x610
1721 #define FCN_SRM_RX_DC_BASE_ADR_LBN 0
1722 #define FCN_SRM_RX_DC_BASE_ADR_WIDTH 21
1724 /* SRAM transmit descriptor cache configuration register */
1725 #define FCN_SRM_TX_DC_CFG_REG_KER 0x620
1726 #define FCN_SRM_TX_DC_BASE_ADR_LBN 0
1727 #define FCN_SRM_TX_DC_BASE_ADR_WIDTH 21
1729 /* Receive filter control register */
1730 #define FCN_RX_FILTER_CTL_REG_KER 0x810
1731 #define FCN_NUM_KER_LBN 24
1732 #define FCN_NUM_KER_WIDTH 2
1734 /* Receive descriptor update register */
1735 #define FCN_RX_DESC_UPD_REG_KER 0x0830
1736 #define FCN_RX_DESC_WPTR_LBN 96
1737 #define FCN_RX_DESC_WPTR_WIDTH 12
1738 #define FCN_RX_DESC_UPD_REG_KER_DWORD ( FCN_RX_DESC_UPD_REG_KER + 12 )
1739 #define FCN_RX_DESC_WPTR_DWORD_LBN 0
1740 #define FCN_RX_DESC_WPTR_DWORD_WIDTH 12
1742 /* Receive descriptor cache configuration register */
1743 #define FCN_RX_DC_CFG_REG_KER 0x840
1744 #define FCN_RX_DC_SIZE_LBN 0
1745 #define FCN_RX_DC_SIZE_WIDTH 2
1747 /* Transmit descriptor update register */
1748 #define FCN_TX_DESC_UPD_REG_KER 0x0a10
1749 #define FCN_TX_DESC_WPTR_LBN 96
1750 #define FCN_TX_DESC_WPTR_WIDTH 12
1751 #define FCN_TX_DESC_UPD_REG_KER_DWORD ( FCN_TX_DESC_UPD_REG_KER + 12 )
1752 #define FCN_TX_DESC_WPTR_DWORD_LBN 0
1753 #define FCN_TX_DESC_WPTR_DWORD_WIDTH 12
1755 /* Transmit descriptor cache configuration register */
1756 #define FCN_TX_DC_CFG_REG_KER 0xa20
1757 #define FCN_TX_DC_SIZE_LBN 0
1758 #define FCN_TX_DC_SIZE_WIDTH 2
1760 /* PHY management transmit data register */
1761 #define FCN_MD_TXD_REG_KER 0xc00
1762 #define FCN_MD_TXD_LBN 0
1763 #define FCN_MD_TXD_WIDTH 16
1765 /* PHY management receive data register */
1766 #define FCN_MD_RXD_REG_KER 0xc10
1767 #define FCN_MD_RXD_LBN 0
1768 #define FCN_MD_RXD_WIDTH 16
1770 /* PHY management configuration & status register */
1771 #define FCN_MD_CS_REG_KER 0xc20
1772 #define FCN_MD_GC_LBN 4
1773 #define FCN_MD_GC_WIDTH 1
1774 #define FCN_MD_RIC_LBN 2
1775 #define FCN_MD_RIC_WIDTH 1
1776 #define FCN_MD_WRC_LBN 0
1777 #define FCN_MD_WRC_WIDTH 1
1779 /* PHY management PHY address register */
1780 #define FCN_MD_PHY_ADR_REG_KER 0xc30
1781 #define FCN_MD_PHY_ADR_LBN 0
1782 #define FCN_MD_PHY_ADR_WIDTH 16
1784 /* PHY management ID register */
1785 #define FCN_MD_ID_REG_KER 0xc40
1786 #define FCN_MD_PRT_ADR_LBN 11
1787 #define FCN_MD_PRT_ADR_WIDTH 5
1788 #define FCN_MD_DEV_ADR_LBN 6
1789 #define FCN_MD_DEV_ADR_WIDTH 5
1791 /* PHY management status & mask register */
1792 #define FCN_MD_STAT_REG_KER 0xc50
1793 #define FCN_MD_BSY_LBN 0
1794 #define FCN_MD_BSY_WIDTH 1
1796 /* Port 0 and 1 MAC control registers */
1797 #define FCN_MAC0_CTRL_REG_KER 0xc80
1798 #define FCN_MAC1_CTRL_REG_KER 0xc90
1799 #define FCN_MAC_XOFF_VAL_LBN 16
1800 #define FCN_MAC_XOFF_VAL_WIDTH 16
1801 #define FCN_MAC_BCAD_ACPT_LBN 4
1802 #define FCN_MAC_BCAD_ACPT_WIDTH 1
1803 #define FCN_MAC_UC_PROM_LBN 3
1804 #define FCN_MAC_UC_PROM_WIDTH 1
1805 #define FCN_MAC_LINK_STATUS_LBN 2
1806 #define FCN_MAC_LINK_STATUS_WIDTH 1
1807 #define FCN_MAC_SPEED_LBN 0
1808 #define FCN_MAC_SPEED_WIDTH 2
1810 /* XGMAC global configuration - port 0*/
1811 #define FCN_XM_GLB_CFG_REG_P0_KER 0x1220
1812 #define FCN_XM_RX_STAT_EN_LBN 11
1813 #define FCN_XM_RX_STAT_EN_WIDTH 1
1814 #define FCN_XM_TX_STAT_EN_LBN 10
1815 #define FCN_XM_TX_STAT_EN_WIDTH 1
1816 #define FCN_XM_CUT_THRU_MODE_LBN 7
1817 #define FCN_XM_CUT_THRU_MODE_WIDTH 1
1818 #define FCN_XM_RX_JUMBO_MODE_LBN 6
1819 #define FCN_XM_RX_JUMBO_MODE_WIDTH 1
1821 /* XGMAC transmit configuration - port 0 */
1822 #define FCN_XM_TX_CFG_REG_P0_KER 0x1230
1823 #define FCN_XM_IPG_LBN 16
1824 #define FCN_XM_IPG_WIDTH 4
1825 #define FCN_XM_WTF_DOES_THIS_DO_LBN 9
1826 #define FCN_XM_WTF_DOES_THIS_DO_WIDTH 1
1827 #define FCN_XM_TXCRC_LBN 8
1828 #define FCN_XM_TXCRC_WIDTH 1
1829 #define FCN_XM_AUTO_PAD_LBN 5
1830 #define FCN_XM_AUTO_PAD_WIDTH 1
1831 #define FCN_XM_TX_PRMBL_LBN 2
1832 #define FCN_XM_TX_PRMBL_WIDTH 1
1833 #define FCN_XM_TXEN_LBN 1
1834 #define FCN_XM_TXEN_WIDTH 1
1836 /* XGMAC receive configuration - port 0 */
1837 #define FCN_XM_RX_CFG_REG_P0_KER 0x1240
1838 #define FCN_XM_PASS_CRC_ERR_LBN 25
1839 #define FCN_XM_PASS_CRC_ERR_WIDTH 1
1840 #define FCN_XM_AUTO_DEPAD_LBN 8
1841 #define FCN_XM_AUTO_DEPAD_WIDTH 1
1842 #define FCN_XM_RXEN_LBN 1
1843 #define FCN_XM_RXEN_WIDTH 1
1845 /* Receive descriptor pointer table */
1846 #define FCN_RX_DESC_PTR_TBL_KER 0x11800
1847 #define FCN_RX_DESCQ_BUF_BASE_ID_LBN 36
1848 #define FCN_RX_DESCQ_BUF_BASE_ID_WIDTH 20
1849 #define FCN_RX_DESCQ_EVQ_ID_LBN 24
1850 #define FCN_RX_DESCQ_EVQ_ID_WIDTH 12
1851 #define FCN_RX_DESCQ_OWNER_ID_LBN 10
1852 #define FCN_RX_DESCQ_OWNER_ID_WIDTH 14
1853 #define FCN_RX_DESCQ_SIZE_LBN 3
1854 #define FCN_RX_DESCQ_SIZE_WIDTH 2
1855 #define FCN_RX_DESCQ_SIZE_4K 3
1856 #define FCN_RX_DESCQ_SIZE_2K 2
1857 #define FCN_RX_DESCQ_SIZE_1K 1
1858 #define FCN_RX_DESCQ_SIZE_512 0
1859 #define FCN_RX_DESCQ_TYPE_LBN 2
1860 #define FCN_RX_DESCQ_TYPE_WIDTH 1
1861 #define FCN_RX_DESCQ_JUMBO_LBN 1
1862 #define FCN_RX_DESCQ_JUMBO_WIDTH 1
1863 #define FCN_RX_DESCQ_EN_LBN 0
1864 #define FCN_RX_DESCQ_EN_WIDTH 1
1866 /* Transmit descriptor pointer table */
1867 #define FCN_TX_DESC_PTR_TBL_KER 0x11900
1868 #define FCN_TX_DESCQ_EN_LBN 88
1869 #define FCN_TX_DESCQ_EN_WIDTH 1
1870 #define FCN_TX_DESCQ_BUF_BASE_ID_LBN 36
1871 #define FCN_TX_DESCQ_BUF_BASE_ID_WIDTH 20
1872 #define FCN_TX_DESCQ_EVQ_ID_LBN 24
1873 #define FCN_TX_DESCQ_EVQ_ID_WIDTH 12
1874 #define FCN_TX_DESCQ_OWNER_ID_LBN 10
1875 #define FCN_TX_DESCQ_OWNER_ID_WIDTH 14
1876 #define FCN_TX_DESCQ_SIZE_LBN 3
1877 #define FCN_TX_DESCQ_SIZE_WIDTH 2
1878 #define FCN_TX_DESCQ_SIZE_4K 3
1879 #define FCN_TX_DESCQ_SIZE_2K 2
1880 #define FCN_TX_DESCQ_SIZE_1K 1
1881 #define FCN_TX_DESCQ_SIZE_512 0
1882 #define FCN_TX_DESCQ_TYPE_LBN 1
1883 #define FCN_TX_DESCQ_TYPE_WIDTH 2
1884 #define FCN_TX_DESCQ_FLUSH_LBN 0
1885 #define FCN_TX_DESCQ_FLUSH_WIDTH 1
1887 /* Event queue pointer */
1888 #define FCN_EVQ_PTR_TBL_KER 0x11a00
1889 #define FCN_EVQ_EN_LBN 23
1890 #define FCN_EVQ_EN_WIDTH 1
1891 #define FCN_EVQ_SIZE_LBN 20
1892 #define FCN_EVQ_SIZE_WIDTH 3
1893 #define FCN_EVQ_SIZE_32K 6
1894 #define FCN_EVQ_SIZE_16K 5
1895 #define FCN_EVQ_SIZE_8K 4
1896 #define FCN_EVQ_SIZE_4K 3
1897 #define FCN_EVQ_SIZE_2K 2
1898 #define FCN_EVQ_SIZE_1K 1
1899 #define FCN_EVQ_SIZE_512 0
1900 #define FCN_EVQ_BUF_BASE_ID_LBN 0
1901 #define FCN_EVQ_BUF_BASE_ID_WIDTH 20
1903 /* Event queue read pointer */
1904 #define FCN_EVQ_RPTR_REG_KER 0x11b00
1905 #define FCN_EVQ_RPTR_LBN 0
1906 #define FCN_EVQ_RPTR_WIDTH 14
1907 #define FCN_EVQ_RPTR_REG_KER_DWORD ( FCN_EVQ_RPTR_REG_KER + 0 )
1908 #define FCN_EVQ_RPTR_DWORD_LBN 0
1909 #define FCN_EVQ_RPTR_DWORD_WIDTH 14
1911 /* Special buffer descriptors */
1912 #define FCN_BUF_FULL_TBL_KER 0x18000
1913 #define FCN_IP_DAT_BUF_SIZE_LBN 50
1914 #define FCN_IP_DAT_BUF_SIZE_WIDTH 1
1915 #define FCN_IP_DAT_BUF_SIZE_8K 1
1916 #define FCN_IP_DAT_BUF_SIZE_4K 0
1917 #define FCN_BUF_ADR_FBUF_LBN 14
1918 #define FCN_BUF_ADR_FBUF_WIDTH 34
1919 #define FCN_BUF_OWNER_ID_FBUF_LBN 0
1920 #define FCN_BUF_OWNER_ID_FBUF_WIDTH 14
1923 #define FALCON_MAC_REGBANK 0xe00
1924 #define FALCON_MAC_REGBANK_SIZE 0x200
1925 #define FALCON_MAC_REG_SIZE 0x10
1927 /** Offset of a MAC register within Falcon */
1928 #define FALCON_MAC_REG( efab, mac_reg ) \
1929 ( FALCON_MAC_REGBANK + \
1930 ( (efab)->port * FALCON_MAC_REGBANK_SIZE ) + \
1931 ( (mac_reg) * FALCON_MAC_REG_SIZE ) )
1932 #define FCN_MAC_DATA_LBN 0
1933 #define FCN_MAC_DATA_WIDTH 32
1935 /* Transmit descriptor */
1936 #define FCN_TX_KER_PORT_LBN 63
1937 #define FCN_TX_KER_PORT_WIDTH 1
1938 #define FCN_TX_KER_BYTE_CNT_LBN 48
1939 #define FCN_TX_KER_BYTE_CNT_WIDTH 14
1940 #define FCN_TX_KER_BUF_ADR_LBN 0
1941 #define FCN_TX_KER_BUF_ADR_WIDTH EFAB_DMA_TYPE_WIDTH ( 46 )
1943 /* Receive descriptor */
1944 #define FCN_RX_KER_BUF_SIZE_LBN 48
1945 #define FCN_RX_KER_BUF_SIZE_WIDTH 14
1946 #define FCN_RX_KER_BUF_ADR_LBN 0
1947 #define FCN_RX_KER_BUF_ADR_WIDTH EFAB_DMA_TYPE_WIDTH ( 46 )
1949 /* Event queue entries */
1950 #define FCN_EV_CODE_LBN 60
1951 #define FCN_EV_CODE_WIDTH 4
1952 #define FCN_RX_IP_EV_DECODE 0
1953 #define FCN_TX_IP_EV_DECODE 2
1954 #define FCN_DRIVER_EV_DECODE 5
1956 /* Receive events */
1957 #define FCN_RX_PORT_LBN 30
1958 #define FCN_RX_PORT_WIDTH 1
1959 #define FCN_RX_EV_BYTE_CNT_LBN 16
1960 #define FCN_RX_EV_BYTE_CNT_WIDTH 14
1961 #define FCN_RX_EV_DESC_PTR_LBN 0
1962 #define FCN_RX_EV_DESC_PTR_WIDTH 12
1964 /* Transmit events */
1965 #define FCN_TX_EV_DESC_PTR_LBN 0
1966 #define FCN_TX_EV_DESC_PTR_WIDTH 12
1968 /* Fixed special buffer numbers to use */
1969 #define FALCON_EVQ_ID 0
1970 #define FALCON_TXD_ID 1
1971 #define FALCON_RXD_ID 2
1973 #if FALCON_USE_IO_BAR
1975 /* Write dword via the I/O BAR */
1976 static inline void _falcon_writel ( struct efab_nic *efab, uint32_t value,
1977 unsigned int reg ) {
1978 outl ( reg, efab->iobase + FCN_IOM_IND_ADR_REG );
1979 outl ( value, efab->iobase + FCN_IOM_IND_DAT_REG );
1982 /* Read dword via the I/O BAR */
1983 static inline uint32_t _falcon_readl ( struct efab_nic *efab,
1984 unsigned int reg ) {
1985 outl ( reg, efab->iobase + FCN_IOM_IND_ADR_REG );
1986 return inl ( efab->iobase + FCN_IOM_IND_DAT_REG );
1989 #else /* FALCON_USE_IO_BAR */
1991 #define _falcon_writel( efab, value, reg ) \
1992 writel ( (value), (efab)->membase + (reg) )
1993 #define _falcon_readl( efab, reg ) readl ( (efab)->membase + (reg) )
1995 #endif /* FALCON_USE_IO_BAR */
1998 * Write to a Falcon register
2001 static inline void falcon_write ( struct efab_nic *efab, efab_oword_t *value,
2002 unsigned int reg ) {
2004 EFAB_REGDUMP ( "Writing register %x with " EFAB_OWORD_FMT "\n",
2005 reg, EFAB_OWORD_VAL ( *value ) );
2007 _falcon_writel ( efab, value->u32[0], reg + 0 );
2008 _falcon_writel ( efab, value->u32[1], reg + 4 );
2009 _falcon_writel ( efab, value->u32[2], reg + 8 );
2010 _falcon_writel ( efab, value->u32[3], reg + 12 );
2015 * Write to Falcon SRAM
2018 static inline void falcon_write_sram ( struct efab_nic *efab,
2019 efab_qword_t *value,
2020 unsigned int index ) {
2021 unsigned int reg = ( FCN_BUF_FULL_TBL_KER +
2022 ( index * sizeof ( *value ) ) );
2024 EFAB_REGDUMP ( "Writing SRAM register %x with " EFAB_QWORD_FMT "\n",
2025 reg, EFAB_QWORD_VAL ( *value ) );
2027 _falcon_writel ( efab, value->u32[0], reg + 0 );
2028 _falcon_writel ( efab, value->u32[1], reg + 4 );
2033 * Write dword to Falcon register that allows partial writes
2036 static inline void falcon_writel ( struct efab_nic *efab, efab_dword_t *value,
2037 unsigned int reg ) {
2038 EFAB_REGDUMP ( "Writing partial register %x with " EFAB_DWORD_FMT "\n",
2039 reg, EFAB_DWORD_VAL ( *value ) );
2040 _falcon_writel ( efab, value->u32[0], reg );
2044 * Read from a Falcon register
2047 static inline void falcon_read ( struct efab_nic *efab, efab_oword_t *value,
2048 unsigned int reg ) {
2049 value->u32[0] = _falcon_readl ( efab, reg + 0 );
2050 value->u32[1] = _falcon_readl ( efab, reg + 4 );
2051 value->u32[2] = _falcon_readl ( efab, reg + 8 );
2052 value->u32[3] = _falcon_readl ( efab, reg + 12 );
2054 EFAB_REGDUMP ( "Read from register %x, got " EFAB_OWORD_FMT "\n",
2055 reg, EFAB_OWORD_VAL ( *value ) );
2059 * Read from Falcon SRAM
2062 static inline void falcon_read_sram ( struct efab_nic *efab,
2063 efab_qword_t *value,
2064 unsigned int index ) {
2065 unsigned int reg = ( FCN_BUF_FULL_TBL_KER +
2066 ( index * sizeof ( *value ) ) );
2068 value->u32[0] = _falcon_readl ( efab, reg + 0 );
2069 value->u32[1] = _falcon_readl ( efab, reg + 4 );
2070 EFAB_REGDUMP ( "Read from SRAM register %x, got " EFAB_QWORD_FMT "\n",
2071 reg, EFAB_QWORD_VAL ( *value ) );
2075 * Read dword from a portion of a Falcon register
2078 static inline void falcon_readl ( struct efab_nic *efab, efab_dword_t *value,
2079 unsigned int reg ) {
2080 value->u32[0] = _falcon_readl ( efab, reg );
2081 EFAB_REGDUMP ( "Read from register %x, got " EFAB_DWORD_FMT "\n",
2082 reg, EFAB_DWORD_VAL ( *value ) );
2086 * Verified write to Falcon SRAM
2089 static inline void falcon_write_sram_verify ( struct efab_nic *efab,
2090 efab_qword_t *value,
2091 unsigned int index ) {
2092 efab_qword_t verify;
2094 falcon_write_sram ( efab, value, index );
2096 falcon_read_sram ( efab, &verify, index );
2097 if ( memcmp ( &verify, value, sizeof ( verify ) ) != 0 ) {
2098 printf ( "SRAM index %x failure: wrote " EFAB_QWORD_FMT
2099 " got " EFAB_QWORD_FMT "\n", index,
2100 EFAB_QWORD_VAL ( *value ),
2101 EFAB_QWORD_VAL ( verify ) );
2109 static void falcon_get_membase ( struct efab_nic *efab ) {
2110 unsigned long membase_phys;
2112 membase_phys = pci_bar_start ( efab->pci, PCI_BASE_ADDRESS_2 );
2113 efab->membase = ioremap ( membase_phys, 0x20000 );
2116 #define FCN_DUMP_REG( efab, _reg ) do { \
2118 falcon_read ( efab, ®, _reg ); \
2119 printf ( #_reg " = " EFAB_OWORD_FMT "\n", \
2120 EFAB_OWORD_VAL ( reg ) ); \
2123 #define FCN_DUMP_MAC_REG( efab, _mac_reg ) do { \
2125 efab->op->mac_readl ( efab, ®, _mac_reg ); \
2126 printf ( #_mac_reg " = " EFAB_DWORD_FMT "\n", \
2127 EFAB_DWORD_VAL ( reg ) ); \
2131 * Dump register contents (for debugging)
2133 * Marked as static inline so that it will not be compiled in if not
2136 static inline void falcon_dump_regs ( struct efab_nic *efab ) {
2137 FCN_DUMP_REG ( efab, FCN_INT_EN_REG_KER );
2138 FCN_DUMP_REG ( efab, FCN_INT_ADR_REG_KER );
2139 FCN_DUMP_REG ( efab, FCN_GLB_CTL_REG_KER );
2140 FCN_DUMP_REG ( efab, FCN_TIMER_CMD_REG_KER );
2141 FCN_DUMP_REG ( efab, FCN_SRM_RX_DC_CFG_REG_KER );
2142 FCN_DUMP_REG ( efab, FCN_SRM_TX_DC_CFG_REG_KER );
2143 FCN_DUMP_REG ( efab, FCN_RX_FILTER_CTL_REG_KER );
2144 FCN_DUMP_REG ( efab, FCN_RX_DC_CFG_REG_KER );
2145 FCN_DUMP_REG ( efab, FCN_TX_DC_CFG_REG_KER );
2146 FCN_DUMP_REG ( efab, FCN_MAC0_CTRL_REG_KER );
2147 FCN_DUMP_REG ( efab, FCN_MAC1_CTRL_REG_KER );
2148 FCN_DUMP_REG ( efab, FCN_XM_GLB_CFG_REG_P0_KER );
2149 FCN_DUMP_REG ( efab, FCN_XM_TX_CFG_REG_P0_KER );
2150 FCN_DUMP_REG ( efab, FCN_XM_RX_CFG_REG_P0_KER );
2151 FCN_DUMP_REG ( efab, FCN_RX_DESC_PTR_TBL_KER );
2152 FCN_DUMP_REG ( efab, FCN_TX_DESC_PTR_TBL_KER );
2153 FCN_DUMP_REG ( efab, FCN_EVQ_PTR_TBL_KER );
2154 FCN_DUMP_MAC_REG ( efab, GM_CFG1_REG_MAC );
2155 FCN_DUMP_MAC_REG ( efab, GM_CFG2_REG_MAC );
2156 FCN_DUMP_MAC_REG ( efab, GM_MAX_FLEN_REG_MAC );
2157 FCN_DUMP_MAC_REG ( efab, GM_MII_MGMT_CFG_REG_MAC );
2158 FCN_DUMP_MAC_REG ( efab, GM_ADR1_REG_MAC );
2159 FCN_DUMP_MAC_REG ( efab, GM_ADR2_REG_MAC );
2160 FCN_DUMP_MAC_REG ( efab, GMF_CFG0_REG_MAC );
2161 FCN_DUMP_MAC_REG ( efab, GMF_CFG1_REG_MAC );
2162 FCN_DUMP_MAC_REG ( efab, GMF_CFG2_REG_MAC );
2163 FCN_DUMP_MAC_REG ( efab, GMF_CFG3_REG_MAC );
2164 FCN_DUMP_MAC_REG ( efab, GMF_CFG4_REG_MAC );
2165 FCN_DUMP_MAC_REG ( efab, GMF_CFG5_REG_MAC );
2169 * Create special buffer
2172 static void falcon_create_special_buffer ( struct efab_nic *efab,
2173 void *addr, unsigned int index ) {
2174 efab_qword_t buf_desc;
2175 unsigned long dma_addr;
2177 memset ( addr, 0, 4096 );
2178 dma_addr = virt_to_bus ( addr );
2179 EFAB_ASSERT ( ( dma_addr & ( EFAB_BUF_ALIGN - 1 ) ) == 0 );
2180 EFAB_POPULATE_QWORD_3 ( buf_desc,
2181 FCN_IP_DAT_BUF_SIZE, FCN_IP_DAT_BUF_SIZE_4K,
2182 FCN_BUF_ADR_FBUF, ( dma_addr >> 12 ),
2183 FCN_BUF_OWNER_ID_FBUF, 0 );
2184 falcon_write_sram_verify ( efab, &buf_desc, index );
2188 * Update event queue read pointer
2191 static void falcon_eventq_read_ack ( struct efab_nic *efab ) {
2194 EFAB_ASSERT ( efab->eventq_read_ptr < EFAB_EVQ_SIZE );
2196 EFAB_POPULATE_DWORD_1 ( reg, FCN_EVQ_RPTR_DWORD,
2197 efab->eventq_read_ptr );
2198 falcon_writel ( efab, ®, FCN_EVQ_RPTR_REG_KER_DWORD );
2205 static int falcon_reset ( struct efab_nic *efab ) {
2206 efab_oword_t glb_ctl_reg_ker;
2208 /* Initiate software reset */
2209 EFAB_POPULATE_OWORD_5 ( glb_ctl_reg_ker,
2210 FCN_EXT_PHY_RST_CTL, FCN_EXCLUDE_FROM_RESET,
2211 FCN_PCIE_SD_RST_CTL, FCN_EXCLUDE_FROM_RESET,
2212 FCN_PCIX_RST_CTL, FCN_EXCLUDE_FROM_RESET,
2213 FCN_INT_RST_DUR, 0x7 /* datasheet */,
2215 falcon_write ( efab, &glb_ctl_reg_ker, FCN_GLB_CTL_REG_KER );
2217 /* Allow 20ms for reset */
2220 /* Check for device reset complete */
2221 falcon_read ( efab, &glb_ctl_reg_ker, FCN_GLB_CTL_REG_KER );
2222 if ( EFAB_OWORD_FIELD ( glb_ctl_reg_ker, FCN_SWRST ) != 0 ) {
2223 printf ( "Reset failed\n" );
2234 static int falcon_init_nic ( struct efab_nic *efab ) {
2236 efab_dword_t timer_cmd;
2238 /* Set up TX and RX descriptor caches in SRAM */
2239 EFAB_POPULATE_OWORD_1 ( reg, FCN_SRM_TX_DC_BASE_ADR,
2240 0x130000 /* recommended in datasheet */ );
2241 falcon_write ( efab, ®, FCN_SRM_TX_DC_CFG_REG_KER );
2242 EFAB_POPULATE_OWORD_1 ( reg, FCN_TX_DC_SIZE, 2 /* 32 descriptors */ );
2243 falcon_write ( efab, ®, FCN_TX_DC_CFG_REG_KER );
2244 EFAB_POPULATE_OWORD_1 ( reg, FCN_SRM_RX_DC_BASE_ADR,
2245 0x100000 /* recommended in datasheet */ );
2246 falcon_write ( efab, ®, FCN_SRM_RX_DC_CFG_REG_KER );
2247 EFAB_POPULATE_OWORD_1 ( reg, FCN_RX_DC_SIZE, 2 /* 32 descriptors */ );
2248 falcon_write ( efab, ®, FCN_RX_DC_CFG_REG_KER );
2250 /* Set number of RSS CPUs */
2251 EFAB_POPULATE_OWORD_1 ( reg, FCN_NUM_KER, 0 );
2252 falcon_write ( efab, ®, FCN_RX_FILTER_CTL_REG_KER );
2256 mentormac_reset ( efab );
2258 /* Set up event queue */
2259 falcon_create_special_buffer ( efab, efab->eventq, FALCON_EVQ_ID );
2260 EFAB_POPULATE_OWORD_3 ( reg,
2262 FCN_EVQ_SIZE, FCN_EVQ_SIZE_512,
2263 FCN_EVQ_BUF_BASE_ID, FALCON_EVQ_ID );
2264 falcon_write ( efab, ®, FCN_EVQ_PTR_TBL_KER );
2267 /* Set timer register */
2268 EFAB_POPULATE_DWORD_2 ( timer_cmd,
2269 FCN_TIMER_MODE, FCN_TIMER_MODE_DIS,
2271 falcon_writel ( efab, &timer_cmd, FCN_TIMER_CMD_REG_KER );
2274 /* Initialise event queue read pointer */
2275 falcon_eventq_read_ack ( efab );
2277 /* Set up TX descriptor ring */
2278 falcon_create_special_buffer ( efab, efab->txd, FALCON_TXD_ID );
2279 EFAB_POPULATE_OWORD_5 ( reg,
2281 FCN_TX_DESCQ_BUF_BASE_ID, FALCON_TXD_ID,
2282 FCN_TX_DESCQ_EVQ_ID, 0,
2283 FCN_TX_DESCQ_SIZE, FCN_TX_DESCQ_SIZE_512,
2284 FCN_TX_DESCQ_TYPE, 0 /* kernel queue */ );
2285 falcon_write ( efab, ®, FCN_TX_DESC_PTR_TBL_KER );
2287 /* Set up RX descriptor ring */
2288 falcon_create_special_buffer ( efab, efab->rxd, FALCON_RXD_ID );
2289 EFAB_POPULATE_OWORD_6 ( reg,
2290 FCN_RX_DESCQ_BUF_BASE_ID, FALCON_RXD_ID,
2291 FCN_RX_DESCQ_EVQ_ID, 0,
2292 FCN_RX_DESCQ_SIZE, FCN_RX_DESCQ_SIZE_512,
2293 FCN_RX_DESCQ_TYPE, 0 /* kernel queue */,
2294 FCN_RX_DESCQ_JUMBO, 1,
2295 FCN_RX_DESCQ_EN, 1 );
2296 falcon_write ( efab, ®, FCN_RX_DESC_PTR_TBL_KER );
2298 /* Program INT_ADR_REG_KER */
2299 EFAB_POPULATE_OWORD_1 ( reg,
2301 virt_to_bus ( &efab->int_ker ) );
2302 falcon_write ( efab, ®, FCN_INT_ADR_REG_KER );
2309 struct efab_spi_device {
2311 unsigned int device_id;
2312 /** Address length (in bytes) */
2313 unsigned int addr_len;
2315 unsigned int read_command;
2319 * Wait for SPI command completion
2322 static int falcon_spi_wait ( struct efab_nic *efab ) {
2329 falcon_read ( efab, ®, FCN_EE_SPI_HCMD_REG_KER );
2330 if ( EFAB_OWORD_FIELD ( reg, FCN_EE_SPI_HCMD_CMD_EN ) == 0 )
2332 } while ( ++count < 1000 );
2333 printf ( "Timed out waiting for SPI\n" );
2341 static int falcon_spi_read ( struct efab_nic *efab,
2342 struct efab_spi_device *spi,
2343 int address, void *data, unsigned int len ) {
2346 /* Program address register */
2347 EFAB_POPULATE_OWORD_1 ( reg, FCN_EE_SPI_HADR_ADR, address );
2348 falcon_write ( efab, ®, FCN_EE_SPI_HADR_REG_KER );
2350 /* Issue read command */
2351 EFAB_POPULATE_OWORD_7 ( reg,
2352 FCN_EE_SPI_HCMD_CMD_EN, 1,
2353 FCN_EE_SPI_HCMD_SF_SEL, spi->device_id,
2354 FCN_EE_SPI_HCMD_DABCNT, len,
2355 FCN_EE_SPI_HCMD_READ, FCN_EE_SPI_READ,
2356 FCN_EE_SPI_HCMD_DUBCNT, 0,
2357 FCN_EE_SPI_HCMD_ADBCNT, spi->addr_len,
2358 FCN_EE_SPI_HCMD_ENC, spi->read_command );
2359 falcon_write ( efab, ®, FCN_EE_SPI_HCMD_REG_KER );
2361 /* Wait for read to complete */
2362 if ( ! falcon_spi_wait ( efab ) )
2366 falcon_read ( efab, ®, FCN_EE_SPI_HDATA_REG_KER );
2367 memcpy ( data, ®, len );
2372 #define SPI_READ_CMD 0x03
2373 #define AT25F1024_ADDR_LEN 3
2374 #define AT25F1024_READ_CMD SPI_READ_CMD
2375 #define MC25XX640_ADDR_LEN 2
2376 #define MC25XX640_READ_CMD SPI_READ_CMD
2378 /** Falcon Flash SPI device */
2379 static struct efab_spi_device falcon_spi_flash = {
2380 .device_id = FCN_EE_SPI_FLASH,
2381 .addr_len = AT25F1024_ADDR_LEN,
2382 .read_command = AT25F1024_READ_CMD,
2385 /** Falcon EEPROM SPI device */
2386 static struct efab_spi_device falcon_spi_large_eeprom = {
2387 .device_id = FCN_EE_SPI_EEPROM,
2388 .addr_len = MC25XX640_ADDR_LEN,
2389 .read_command = MC25XX640_READ_CMD,
2392 /** Offset of MAC address within EEPROM or Flash */
2393 #define FALCON_MAC_ADDRESS_OFFSET(port) ( 0x310 + 0x08 * (port) )
2396 * Read MAC address from EEPROM
2399 static int falcon_read_eeprom ( struct efab_nic *efab ) {
2402 struct efab_spi_device *spi;
2404 /* Determine the SPI device containing the MAC address */
2405 falcon_read ( efab, ®, FCN_GPIO_CTL_REG_KER );
2406 has_flash = EFAB_OWORD_FIELD ( reg, FCN_FLASH_PRESENT );
2407 spi = has_flash ? &falcon_spi_flash : &falcon_spi_large_eeprom;
2409 return falcon_spi_read ( efab, spi,
2410 FALCON_MAC_ADDRESS_OFFSET ( efab->port ),
2411 efab->mac_addr, sizeof ( efab->mac_addr ) );
2414 /** RX descriptor */
2415 typedef efab_qword_t falcon_rx_desc_t;
2418 * Build RX descriptor
2421 static void falcon_build_rx_desc ( struct efab_nic *efab,
2422 struct efab_rx_buf *rx_buf ) {
2423 falcon_rx_desc_t *rxd;
2425 rxd = ( ( falcon_rx_desc_t * ) efab->rxd ) + rx_buf->id;
2426 EFAB_POPULATE_QWORD_2 ( *rxd,
2427 FCN_RX_KER_BUF_SIZE, EFAB_DATA_BUF_SIZE,
2429 virt_to_bus ( rx_buf->addr ) );
2433 * Update RX descriptor write pointer
2436 static void falcon_notify_rx_desc ( struct efab_nic *efab ) {
2439 EFAB_POPULATE_DWORD_1 ( reg, FCN_RX_DESC_WPTR_DWORD,
2440 efab->rx_write_ptr );
2441 falcon_writel ( efab, ®, FCN_RX_DESC_UPD_REG_KER_DWORD );
2444 /** TX descriptor */
2445 typedef efab_qword_t falcon_tx_desc_t;
2448 * Build TX descriptor
2451 static void falcon_build_tx_desc ( struct efab_nic *efab,
2452 struct efab_tx_buf *tx_buf ) {
2453 falcon_rx_desc_t *txd;
2455 txd = ( ( falcon_rx_desc_t * ) efab->txd ) + tx_buf->id;
2456 EFAB_POPULATE_QWORD_3 ( *txd,
2457 FCN_TX_KER_PORT, efab->port,
2458 FCN_TX_KER_BYTE_CNT, tx_buf->len,
2460 virt_to_bus ( tx_buf->addr ) );
2464 * Update TX descriptor write pointer
2467 static void falcon_notify_tx_desc ( struct efab_nic *efab ) {
2470 EFAB_POPULATE_DWORD_1 ( reg, FCN_TX_DESC_WPTR_DWORD,
2471 efab->tx_write_ptr );
2472 falcon_writel ( efab, ®, FCN_TX_DESC_UPD_REG_KER_DWORD );
2476 typedef efab_qword_t falcon_event_t;
2479 * Retrieve event from event queue
2482 static int falcon_fetch_event ( struct efab_nic *efab,
2483 struct efab_event *event ) {
2484 falcon_event_t *evt;
2488 /* Check for event */
2489 evt = ( ( falcon_event_t * ) efab->eventq ) + efab->eventq_read_ptr;
2490 if ( EFAB_QWORD_IS_ZERO ( *evt ) ) {
2495 DBG ( "Event is " EFAB_QWORD_FMT "\n", EFAB_QWORD_VAL ( *evt ) );
2498 ev_code = EFAB_QWORD_FIELD ( *evt, FCN_EV_CODE );
2499 switch ( ev_code ) {
2500 case FCN_TX_IP_EV_DECODE:
2501 event->type = EFAB_EV_TX;
2503 case FCN_RX_IP_EV_DECODE:
2504 event->type = EFAB_EV_RX;
2505 event->rx_id = EFAB_QWORD_FIELD ( *evt, FCN_RX_EV_DESC_PTR );
2506 event->rx_len = EFAB_QWORD_FIELD ( *evt, FCN_RX_EV_BYTE_CNT );
2507 rx_port = EFAB_QWORD_FIELD ( *evt, FCN_RX_PORT );
2508 if ( rx_port != efab->port ) {
2509 /* Ignore packets on the wrong port. We can't
2510 * just set event->type = EFAB_EV_NONE,
2511 * because then the descriptor ring won't get
2517 case FCN_DRIVER_EV_DECODE:
2518 /* Ignore start-of-day events */
2519 event->type = EFAB_EV_NONE;
2522 printf ( "Unknown event type %d\n", ev_code );
2523 event->type = EFAB_EV_NONE;
2526 /* Clear event and any pending interrupts */
2527 EFAB_ZERO_QWORD ( *evt );
2528 falcon_writel ( efab, 0, FCN_INT_ACK_KER_REG );
2531 /* Increment and update event queue read pointer */
2532 efab->eventq_read_ptr = ( ( efab->eventq_read_ptr + 1 )
2534 falcon_eventq_read_ack ( efab );
2540 * Enable/disable/generate interrupt
2543 static inline void falcon_interrupts ( struct efab_nic *efab, int enabled,
2545 efab_oword_t int_en_reg_ker;
2547 EFAB_POPULATE_OWORD_2 ( int_en_reg_ker,
2548 FCN_KER_INT_KER, force,
2549 FCN_DRV_INT_EN_KER, enabled );
2550 falcon_write ( efab, &int_en_reg_ker, FCN_INT_EN_REG_KER );
2554 * Enable/disable interrupts
2557 static void falcon_mask_irq ( struct efab_nic *efab, int enabled ) {
2558 falcon_interrupts ( efab, enabled, 0 );
2560 /* Events won't trigger interrupts until we do this */
2561 falcon_eventq_read_ack ( efab );
2566 * Generate interrupt
2569 static void falcon_generate_irq ( struct efab_nic *efab ) {
2570 falcon_interrupts ( efab, 1, 1 );
2574 * Write dword to a Falcon MAC register
2577 static void falcon_mac_writel ( struct efab_nic *efab,
2578 efab_dword_t *value, unsigned int mac_reg ) {
2581 EFAB_POPULATE_OWORD_1 ( temp, FCN_MAC_DATA,
2582 EFAB_DWORD_FIELD ( *value, FCN_MAC_DATA ) );
2583 falcon_write ( efab, &temp, FALCON_MAC_REG ( efab, mac_reg ) );
2587 * Read dword from a Falcon MAC register
2590 static void falcon_mac_readl ( struct efab_nic *efab, efab_dword_t *value,
2591 unsigned int mac_reg ) {
2594 falcon_read ( efab, &temp, FALCON_MAC_REG ( efab, mac_reg ) );
2595 EFAB_POPULATE_DWORD_1 ( *value, FCN_MAC_DATA,
2596 EFAB_OWORD_FIELD ( temp, FCN_MAC_DATA ) );
2603 static int falcon_init_mac ( struct efab_nic *efab ) {
2604 static struct efab_mentormac_parameters falcon_mentormac_params = {
2605 .gmf_cfgfrth = 0x12,
2606 .gmf_cfgftth = 0x08,
2607 .gmf_cfghwmft = 0x1c,
2614 /* Initialise PHY */
2615 alaska_init ( efab );
2617 /* Initialise MAC */
2618 mentormac_init ( efab, &falcon_mentormac_params );
2620 /* Configure the Falcon MAC wrapper */
2621 EFAB_POPULATE_OWORD_4 ( reg,
2622 FCN_XM_RX_JUMBO_MODE, 0,
2623 FCN_XM_CUT_THRU_MODE, 0,
2624 FCN_XM_TX_STAT_EN, 1,
2625 FCN_XM_RX_STAT_EN, 1);
2626 falcon_write ( efab, ®, FCN_XM_GLB_CFG_REG_P0_KER );
2628 EFAB_POPULATE_OWORD_6 ( reg,
2633 FCN_XM_WTF_DOES_THIS_DO, 1,
2635 falcon_write ( efab, ®, FCN_XM_TX_CFG_REG_P0_KER );
2637 EFAB_POPULATE_OWORD_3 ( reg,
2639 FCN_XM_AUTO_DEPAD, 1,
2640 FCN_XM_PASS_CRC_ERR, 1 );
2641 falcon_write ( efab, ®, FCN_XM_RX_CFG_REG_P0_KER );
2643 #warning "10G support not yet present"
2645 if ( efab->link_options & LPA_10000 ) {
2647 } else if ( efab->link_options & LPA_1000 ) {
2649 } else if ( efab->link_options & LPA_100 ) {
2654 EFAB_POPULATE_OWORD_5 ( reg,
2655 FCN_MAC_XOFF_VAL, 0xffff /* datasheet */,
2656 FCN_MAC_BCAD_ACPT, 1,
2658 FCN_MAC_LINK_STATUS, 1,
2659 FCN_MAC_SPEED, link_speed );
2660 falcon_write ( efab, ®, ( efab->port == 0 ?
2661 FCN_MAC0_CTRL_REG_KER : FCN_MAC1_CTRL_REG_KER ) );
2667 * Wait for GMII access to complete
2670 static int falcon_gmii_wait ( struct efab_nic *efab ) {
2671 efab_oword_t md_stat;
2674 for ( count = 0 ; count < 1000 ; count++ ) {
2676 falcon_read ( efab, &md_stat, FCN_MD_STAT_REG_KER );
2677 if ( EFAB_OWORD_FIELD ( md_stat, FCN_MD_BSY ) == 0 )
2680 printf ( "Timed out waiting for GMII\n" );
2685 static void falcon_mdio_write ( struct efab_nic *efab, int location,
2687 int phy_id = efab->port + 2;
2690 #warning "10G PHY access not yet in place"
2692 EFAB_TRACE ( "Writing GMII %d register %02x with %04x\n",
2693 phy_id, location, value );
2695 /* Check MII not currently being accessed */
2696 if ( ! falcon_gmii_wait ( efab ) )
2699 /* Write the address registers */
2700 EFAB_POPULATE_OWORD_1 ( reg, FCN_MD_PHY_ADR, 0 /* phy_id ? */ );
2701 falcon_write ( efab, ®, FCN_MD_PHY_ADR_REG_KER );
2703 EFAB_POPULATE_OWORD_2 ( reg,
2704 FCN_MD_PRT_ADR, phy_id,
2705 FCN_MD_DEV_ADR, location );
2706 falcon_write ( efab, ®, FCN_MD_ID_REG_KER );
2710 EFAB_POPULATE_OWORD_1 ( reg, FCN_MD_TXD, value );
2711 falcon_write ( efab, ®, FCN_MD_TXD_REG_KER );
2713 EFAB_POPULATE_OWORD_2 ( reg,
2716 falcon_write ( efab, ®, FCN_MD_CS_REG_KER );
2719 /* Wait for data to be written */
2720 falcon_gmii_wait ( efab );
2724 static int falcon_mdio_read ( struct efab_nic *efab, int location ) {
2725 int phy_id = efab->port + 2;
2729 /* Check MII not currently being accessed */
2730 if ( ! falcon_gmii_wait ( efab ) )
2733 /* Write the address registers */
2734 EFAB_POPULATE_OWORD_1 ( reg, FCN_MD_PHY_ADR, 0 /* phy_id ? */ );
2735 falcon_write ( efab, ®, FCN_MD_PHY_ADR_REG_KER );
2737 EFAB_POPULATE_OWORD_2 ( reg,
2738 FCN_MD_PRT_ADR, phy_id,
2739 FCN_MD_DEV_ADR, location );
2740 falcon_write ( efab, ®, FCN_MD_ID_REG_KER );
2743 /* Request data to be read */
2744 EFAB_POPULATE_OWORD_2 ( reg,
2747 falcon_write ( efab, ®, FCN_MD_CS_REG_KER );
2750 /* Wait for data to become available */
2751 falcon_gmii_wait ( efab );
2754 falcon_read ( efab, ®, FCN_MD_RXD_REG_KER );
2755 value = EFAB_OWORD_FIELD ( reg, FCN_MD_RXD );
2757 EFAB_TRACE ( "Read from GMII %d register %02x, got %04x\n",
2758 phy_id, location, value );
2763 static struct efab_operations falcon_operations = {
2764 .get_membase = falcon_get_membase,
2765 .reset = falcon_reset,
2766 .init_nic = falcon_init_nic,
2767 .read_eeprom = falcon_read_eeprom,
2768 .build_rx_desc = falcon_build_rx_desc,
2769 .notify_rx_desc = falcon_notify_rx_desc,
2770 .build_tx_desc = falcon_build_tx_desc,
2771 .notify_tx_desc = falcon_notify_tx_desc,
2772 .fetch_event = falcon_fetch_event,
2773 .mask_irq = falcon_mask_irq,
2774 .generate_irq = falcon_generate_irq,
2775 .mac_writel = falcon_mac_writel,
2776 .mac_readl = falcon_mac_readl,
2777 .init_mac = falcon_init_mac,
2778 .mdio_write = falcon_mdio_write,
2779 .mdio_read = falcon_mdio_read,
2782 /**************************************************************************
2784 * Etherfabric abstraction layer
2786 **************************************************************************
2790 * Push RX buffer to RXD ring
2793 static inline void efab_push_rx_buffer ( struct efab_nic *efab,
2794 struct efab_rx_buf *rx_buf ) {
2795 /* Create RX descriptor */
2796 rx_buf->id = efab->rx_write_ptr;
2797 efab->op->build_rx_desc ( efab, rx_buf );
2799 /* Update RX write pointer */
2800 efab->rx_write_ptr = ( efab->rx_write_ptr + 1 ) % EFAB_RXD_SIZE;
2801 efab->op->notify_rx_desc ( efab );
2803 DBG ( "Added RX id %x\n", rx_buf->id );
2807 * Push TX buffer to TXD ring
2810 static inline void efab_push_tx_buffer ( struct efab_nic *efab,
2811 struct efab_tx_buf *tx_buf ) {
2812 /* Create TX descriptor */
2813 tx_buf->id = efab->tx_write_ptr;
2814 efab->op->build_tx_desc ( efab, tx_buf );
2816 /* Update TX write pointer */
2817 efab->tx_write_ptr = ( efab->tx_write_ptr + 1 ) % EFAB_TXD_SIZE;
2818 efab->op->notify_tx_desc ( efab );
2820 DBG ( "Added TX id %x\n", tx_buf->id );
2824 * Initialise MAC and wait for link up
2827 static int efab_init_mac ( struct efab_nic *efab ) {
2830 /* This can take several seconds */
2831 printf ( "Waiting for link.." );
2835 if ( ! efab->op->init_mac ( efab ) ) {
2836 printf ( "failed\n" );
2839 if ( efab->link_up ) {
2840 /* PHY init printed the message for us */
2844 } while ( ++count < 5 );
2845 printf ( "timed out\n" );
2854 static int efab_init_nic ( struct efab_nic *efab ) {
2857 /* Initialise NIC */
2858 if ( ! efab->op->init_nic ( efab ) )
2861 /* Push RX descriptors */
2862 for ( i = 0 ; i < EFAB_RX_BUFS ; i++ ) {
2863 efab_push_rx_buffer ( efab, &efab->rx_bufs[i] );
2866 /* Read MAC address from EEPROM */
2867 if ( ! efab->op->read_eeprom ( efab ) )
2870 /* Initialise MAC and wait for link up */
2871 if ( ! efab_init_mac ( efab ) )
2877 /**************************************************************************
2879 * Etherboot interface
2881 **************************************************************************
2884 /**************************************************************************
2885 POLL - Wait for a frame
2886 ***************************************************************************/
2887 static int etherfabric_poll ( struct nic *nic, int retrieve ) {
2888 struct efab_nic *efab = nic->priv_data;
2889 struct efab_event event;
2890 static struct efab_rx_buf *rx_buf = NULL;
2893 /* Process the event queue until we hit either a packet
2894 * received event or an empty event slot.
2896 while ( ( rx_buf == NULL ) &&
2897 efab->op->fetch_event ( efab, &event ) ) {
2898 if ( event.type == EFAB_EV_TX ) {
2899 /* TX completed - mark as done */
2900 DBG ( "TX id %x complete\n",
2902 efab->tx_in_progress = 0;
2903 } else if ( event.type == EFAB_EV_RX ) {
2904 /* RX - find corresponding buffer */
2905 for ( i = 0 ; i < EFAB_RX_BUFS ; i++ ) {
2906 if ( efab->rx_bufs[i].id == event.rx_id ) {
2907 rx_buf = &efab->rx_bufs[i];
2908 rx_buf->len = event.rx_len;
2909 DBG ( "RX id %x (len %x) received\n",
2910 rx_buf->id, rx_buf->len );
2915 printf ( "Invalid RX ID %x\n", event.rx_id );
2917 } else if ( event.type == EFAB_EV_NONE ) {
2918 DBG ( "Ignorable event\n" );
2920 DBG ( "Unknown event\n" );
2924 /* If there is no packet, return 0 */
2928 /* If we don't want to retrieve it just yet, return 1 */
2932 /* There seems to be a hardware race. The event can show up
2933 * on the event FIFO before the DMA has completed, so we
2934 * insert a tiny delay. If this proves unreliable, we should
2935 * switch to using event DMA rather than the event FIFO, since
2936 * event DMA ordering is guaranteed.
2940 /* Copy packet contents */
2941 nic->packetlen = rx_buf->len;
2942 memcpy ( nic->packet, rx_buf->addr, nic->packetlen );
2944 /* Give this buffer back to the NIC */
2945 efab_push_rx_buffer ( efab, rx_buf );
2947 /* Prepare to receive next packet */
2953 /**************************************************************************
2954 TRANSMIT - Transmit a frame
2955 ***************************************************************************/
2956 static void etherfabric_transmit ( struct nic *nic, const char *dest,
2957 unsigned int type, unsigned int size,
2958 const char *data ) {
2959 struct efab_nic *efab = nic->priv_data;
2960 unsigned int nstype = htons ( type );
2962 /* We can only transmit one packet at a time; a TX completion
2963 * event must be received before we can transmit the next
2964 * packet. Since there is only one static TX buffer, we don't
2965 * worry unduly about overflow, but we report it anyway.
2967 if ( efab->tx_in_progress ) {
2968 printf ( "TX overflow!\n" );
2971 /* Fill TX buffer, pad to ETH_ZLEN */
2972 memcpy ( efab->tx_buf.addr, dest, ETH_ALEN );
2973 memcpy ( efab->tx_buf.addr + ETH_ALEN, nic->node_addr, ETH_ALEN );
2974 memcpy ( efab->tx_buf.addr + 2 * ETH_ALEN, &nstype, 2 );
2975 memcpy ( efab->tx_buf.addr + ETH_HLEN, data, size );
2977 while ( size < ETH_ZLEN ) {
2978 efab->tx_buf.addr[size++] = '\0';
2980 efab->tx_buf.len = size;
2982 /* Push TX descriptor */
2983 efab_push_tx_buffer ( efab, &efab->tx_buf );
2985 /* There is no way to wait for TX complete (i.e. TX buffer
2986 * available to re-use for the next transmit) without reading
2987 * from the event queue. We therefore simply leave the TX
2988 * buffer marked as "in use" until a TX completion event
2989 * happens to be picked up by a call to etherfabric_poll().
2991 efab->tx_in_progress = 1;
2996 /**************************************************************************
2997 DISABLE - Turn off ethernet interface
2998 ***************************************************************************/
2999 static void etherfabric_disable ( struct dev *dev ) {
3000 struct nic *nic = ( struct nic * ) dev;
3001 struct efab_nic *efab = nic->priv_data;
3003 efab->op->reset ( efab );
3004 if ( efab->membase )
3005 iounmap ( efab->membase );
3008 /**************************************************************************
3009 IRQ - handle interrupts
3010 ***************************************************************************/
3011 static void etherfabric_irq ( struct nic *nic, irq_action_t action ) {
3012 struct efab_nic *efab = nic->priv_data;
3016 efab->op->mask_irq ( efab, 1 );
3019 efab->op->mask_irq ( efab, 0 );
3022 /* Force NIC to generate a receive interrupt */
3023 efab->op->generate_irq ( efab );
3030 /**************************************************************************
3031 PROBE - Look for an adapter, this routine's visible to the outside
3032 ***************************************************************************/
3033 static int etherfabric_probe ( struct dev *dev, struct pci_device *pci ) {
3034 struct nic *nic = ( struct nic * ) dev;
3035 static struct efab_nic efab;
3036 static int nic_port = 1;
3037 struct efab_buffers *buffers;
3040 /* Set up our private data structure */
3041 nic->priv_data = &efab;
3042 memset ( &efab, 0, sizeof ( efab ) );
3043 memset ( &efab_buffers, 0, sizeof ( efab_buffers ) );
3045 /* Hook in appropriate operations table. Do this early. */
3046 if ( pci->dev_id == EF1002_DEVID ) {
3047 efab.op = &ef1002_operations;
3049 efab.op = &falcon_operations;
3052 /* Initialise efab data structure */
3054 buffers = ( ( struct efab_buffers * )
3055 ( ( ( void * ) &efab_buffers ) +
3056 ( - virt_to_bus ( &efab_buffers ) ) % EFAB_BUF_ALIGN ) );
3057 efab.eventq = buffers->eventq;
3058 efab.txd = buffers->txd;
3059 efab.rxd = buffers->rxd;
3060 efab.tx_buf.addr = buffers->tx_buf;
3061 for ( i = 0 ; i < EFAB_RX_BUFS ; i++ ) {
3062 efab.rx_bufs[i].addr = buffers->rx_buf[i];
3065 /* Enable the PCI device */
3066 adjust_pci_device ( pci );
3067 nic->ioaddr = pci->ioaddr & ~3;
3068 nic->irqno = pci->irq;
3070 /* Get iobase/membase */
3071 efab.iobase = nic->ioaddr;
3072 efab.op->get_membase ( &efab );
3074 /* Switch NIC ports (i.e. try different ports on each probe) */
3075 nic_port = 1 - nic_port;
3076 efab.port = nic_port;
3078 /* Initialise hardware */
3079 if ( ! efab_init_nic ( &efab ) )
3081 memcpy ( nic->node_addr, efab.mac_addr, ETH_ALEN );
3084 printf ( "Found EtherFabric %s NIC %!\n", pci->name, nic->node_addr );
3086 /* point to NIC specific routines */
3087 dev->disable = etherfabric_disable;
3088 nic->poll = etherfabric_poll;
3089 nic->transmit = etherfabric_transmit;
3090 nic->irq = etherfabric_irq;
3095 static struct pci_id etherfabric_nics[] = {
3096 PCI_ROM(0x1924, 0xC101, "ef1002", "EtherFabric EF1002"),
3097 PCI_ROM(0x1924, 0x0703, "falcon", "EtherFabric Falcon"),
3100 static struct pci_driver etherfabric_driver __pci_driver = {
3103 .probe = etherfabric_probe,
3104 .ids = etherfabric_nics,
3105 .id_count = sizeof(etherfabric_nics)/sizeof(etherfabric_nics[0]),