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 #include <gpxe/bitbash.h>
27 #define dma_addr_t unsigned long
28 #include "etherfabric.h"
30 /**************************************************************************
32 * Constants and macros
34 **************************************************************************
37 #define EFAB_ASSERT(x) \
40 DBG ( "ASSERT(%s) failed at %s line %d [%s]\n", #x, \
41 __FILE__, __LINE__, __FUNCTION__ ); \
45 #define EFAB_TRACE(...) DBG ( __VA_ARGS__ )
47 #define EFAB_REGDUMP(...)
49 #define EFAB_LOG(...) printf ( __VA_ARGS__ )
50 #define EFAB_ERR(...) printf ( __VA_ARGS__ )
52 #define FALCON_USE_IO_BAR 1
55 * EtherFabric constants
60 #define EFAB_VENDID_LEVEL5 0x1924
61 #define FALCON_P_DEVID 0x0703 /* Temporary PCI ID */
62 #define EF1002_DEVID 0xC101
64 /**************************************************************************
68 **************************************************************************
72 * Buffers used for TX, RX and event queue
75 #define EFAB_BUF_ALIGN 4096
76 #define EFAB_DATA_BUF_SIZE 2048
77 #define EFAB_RX_BUFS 16
78 #define EFAB_RXD_SIZE 512
79 #define EFAB_TXD_SIZE 512
80 #define EFAB_EVQ_SIZE 512
85 uint8_t tx_buf[EFAB_DATA_BUF_SIZE];
86 uint8_t rx_buf[EFAB_RX_BUFS][EFAB_DATA_BUF_SIZE];
87 uint8_t padding[EFAB_BUF_ALIGN-1];
89 static struct efab_buffers efab_buffers;
105 /** Etherfabric event type */
106 enum efab_event_type {
112 /** Etherfabric event */
115 enum efab_event_type type;
120 /** Packet should be dropped */
125 * Etherfabric abstraction layer
129 struct efab_operations {
130 void ( * get_membase ) ( struct efab_nic *efab );
131 int ( * reset ) ( struct efab_nic *efab );
132 int ( * init_nic ) ( struct efab_nic *efab );
133 int ( * read_eeprom ) ( struct efab_nic *efab );
134 void ( * build_rx_desc ) ( struct efab_nic *efab,
135 struct efab_rx_buf *rx_buf );
136 void ( * notify_rx_desc ) ( struct efab_nic *efab );
137 void ( * build_tx_desc ) ( struct efab_nic *efab,
138 struct efab_tx_buf *tx_buf );
139 void ( * notify_tx_desc ) ( struct efab_nic *efab );
140 int ( * fetch_event ) ( struct efab_nic *efab,
141 struct efab_event *event );
142 void ( * mask_irq ) ( struct efab_nic *efab, int enabled );
143 void ( * generate_irq ) ( struct efab_nic *efab );
144 void ( * mdio_write ) ( struct efab_nic *efab, int location,
146 int ( * mdio_read ) ( struct efab_nic *efab, int location );
149 struct efab_mac_operations {
150 void ( * mac_writel ) ( struct efab_nic *efab, efab_dword_t *value,
151 unsigned int mac_reg );
152 void ( * mac_readl ) ( struct efab_nic *efab, efab_dword_t *value,
153 unsigned int mac_reg );
154 int ( * init ) ( struct efab_nic *efab );
155 int ( * reset ) ( struct efab_nic *efab );
159 * Driver private data structure
165 struct pci_device *pci;
167 /** Operations table */
168 struct efab_operations *op;
170 /** MAC operations table */
171 struct efab_mac_operations *mac_op;
180 uint8_t *eventq; /* Falcon only */
181 uint8_t *txd; /* Falcon only */
182 uint8_t *rxd; /* Falcon only */
183 struct efab_tx_buf tx_buf;
184 struct efab_rx_buf rx_bufs[EFAB_RX_BUFS];
186 /** Buffer pointers */
187 unsigned int eventq_read_ptr; /* Falcon only */
188 unsigned int tx_write_ptr;
189 unsigned int rx_write_ptr;
191 /** Port 0/1 on the NIC */
195 uint8_t mac_addr[ETH_ALEN];
196 /** GMII link options */
197 unsigned int link_options;
201 /* Nic type fields */
208 /** INT_REG_KER for Falcon */
209 efab_oword_t int_ker __attribute__ (( aligned ( 16 ) ));
212 struct i2c_bit_basher ef1002_i2c;
213 unsigned long ef1002_i2c_outputs;
214 struct i2c_device ef1002_eeprom;
218 struct spi_device falcon_flash;
219 struct spi_device falcon_eeprom;
222 /**************************************************************************
226 **************************************************************************
230 #define MII_BMSR 0x01 /* Basic mode status register */
231 #define MII_ADVERTISE 0x04 /* Advertisement control register */
232 #define MII_LPA 0x05 /* Link partner ability register*/
233 #define GMII_GTCR 0x09 /* 1000BASE-T control register */
234 #define GMII_GTSR 0x0a /* 1000BASE-T status register */
235 #define GMII_PSSR 0x11 /* PHY-specific status register */
237 /* Basic mode status register. */
238 #define BMSR_LSTATUS 0x0004 /* Link status */
240 /* Link partner ability register. */
241 #define LPA_10HALF 0x0020 /* Can do 10mbps half-duplex */
242 #define LPA_10FULL 0x0040 /* Can do 10mbps full-duplex */
243 #define LPA_100HALF 0x0080 /* Can do 100mbps half-duplex */
244 #define LPA_100FULL 0x0100 /* Can do 100mbps full-duplex */
245 #define LPA_100BASE4 0x0200 /* Can do 100mbps 4k packets */
246 #define LPA_PAUSE 0x0400 /* Bit 10 - MAC pause */
248 /* Pseudo extensions to the link partner ability register */
249 #define LPA_1000FULL 0x00020000
250 #define LPA_1000HALF 0x00010000
251 #define LPA_10000FULL 0x00040000
252 #define LPA_10000HALF 0x00080000
254 #define LPA_100 (LPA_100FULL | LPA_100HALF | LPA_100BASE4)
255 #define LPA_1000 ( LPA_1000FULL | LPA_1000HALF )
256 #define LPA_10000 ( LPA_10000FULL | LPA_10000HALF )
257 #define LPA_DUPLEX ( LPA_10FULL | LPA_100FULL | LPA_1000FULL )
259 /* Mask of bits not associated with speed or duplexity. */
260 #define LPA_OTHER ~( LPA_10FULL | LPA_10HALF | LPA_100FULL | \
261 LPA_100HALF | LPA_1000FULL | LPA_1000HALF )
263 /* PHY-specific status register */
264 #define PSSR_LSTATUS 0x0400 /* Bit 10 - link status */
267 * Retrieve GMII autonegotiation advertised abilities
270 static unsigned int gmii_autoneg_advertised ( struct efab_nic *efab ) {
271 unsigned int mii_advertise;
272 unsigned int gmii_advertise;
274 /* Extended bits are in bits 8 and 9 of GMII_GTCR */
275 mii_advertise = efab->op->mdio_read ( efab, MII_ADVERTISE );
276 gmii_advertise = ( ( efab->op->mdio_read ( efab, GMII_GTCR ) >> 8 )
278 return ( ( gmii_advertise << 16 ) | mii_advertise );
282 * Retrieve GMII autonegotiation link partner abilities
285 static unsigned int gmii_autoneg_lpa ( struct efab_nic *efab ) {
286 unsigned int mii_lpa;
287 unsigned int gmii_lpa;
289 /* Extended bits are in bits 10 and 11 of GMII_GTSR */
290 mii_lpa = efab->op->mdio_read ( efab, MII_LPA );
291 gmii_lpa = ( efab->op->mdio_read ( efab, GMII_GTSR ) >> 10 ) & 0x03;
292 return ( ( gmii_lpa << 16 ) | mii_lpa );
296 * Calculate GMII autonegotiated link technology
299 static unsigned int gmii_nway_result ( unsigned int negotiated ) {
300 unsigned int other_bits;
302 /* Mask out the speed and duplexity bits */
303 other_bits = negotiated & LPA_OTHER;
305 if ( negotiated & LPA_1000FULL )
306 return ( other_bits | LPA_1000FULL );
307 else if ( negotiated & LPA_1000HALF )
308 return ( other_bits | LPA_1000HALF );
309 else if ( negotiated & LPA_100FULL )
310 return ( other_bits | LPA_100FULL );
311 else if ( negotiated & LPA_100BASE4 )
312 return ( other_bits | LPA_100BASE4 );
313 else if ( negotiated & LPA_100HALF )
314 return ( other_bits | LPA_100HALF );
315 else if ( negotiated & LPA_10FULL )
316 return ( other_bits | LPA_10FULL );
317 else return ( other_bits | LPA_10HALF );
321 * Check GMII PHY link status
324 static int gmii_link_ok ( struct efab_nic *efab ) {
328 /* BMSR is latching - it returns "link down" if the link has
329 * been down at any point since the last read. To get a
330 * real-time status, we therefore read the register twice and
331 * use the result of the second read.
333 efab->op->mdio_read ( efab, MII_BMSR );
334 status = efab->op->mdio_read ( efab, MII_BMSR );
336 /* Read the PHY-specific Status Register. This is
337 * non-latching, so we need do only a single read.
339 phy_status = efab->op->mdio_read ( efab, GMII_PSSR );
341 return ( ( status & BMSR_LSTATUS ) && ( phy_status & PSSR_LSTATUS ) );
344 /**************************************************************************
348 **************************************************************************
352 * Initialise Alaska PHY
355 static void alaska_init ( struct efab_nic *efab ) {
356 unsigned int advertised, lpa;
358 /* Read link up status */
359 efab->link_up = gmii_link_ok ( efab );
361 if ( ! efab->link_up )
364 /* Determine link options from PHY. */
365 advertised = gmii_autoneg_advertised ( efab );
366 lpa = gmii_autoneg_lpa ( efab );
367 efab->link_options = gmii_nway_result ( advertised & lpa );
369 /* print out the link speed */
370 EFAB_LOG ( "%dMbps %s-duplex (%04x,%04x)\n",
371 ( efab->link_options & LPA_10000 ? 1000 :
372 ( efab->link_options & LPA_1000 ? 1000 :
373 ( efab->link_options & LPA_100 ? 100 : 10 ) ) ),
374 ( efab->link_options & LPA_DUPLEX ? "full" : "half" ),
379 /**************************************************************************
383 **************************************************************************
386 /* GMAC configuration register 1 */
387 #define GM_CFG1_REG_MAC 0x00
388 #define GM_SW_RST_LBN 31
389 #define GM_SW_RST_WIDTH 1
390 #define GM_RX_FC_EN_LBN 5
391 #define GM_RX_FC_EN_WIDTH 1
392 #define GM_TX_FC_EN_LBN 4
393 #define GM_TX_FC_EN_WIDTH 1
394 #define GM_RX_EN_LBN 2
395 #define GM_RX_EN_WIDTH 1
396 #define GM_TX_EN_LBN 0
397 #define GM_TX_EN_WIDTH 1
399 /* GMAC configuration register 2 */
400 #define GM_CFG2_REG_MAC 0x01
401 #define GM_PAMBL_LEN_LBN 12
402 #define GM_PAMBL_LEN_WIDTH 4
403 #define GM_IF_MODE_LBN 8
404 #define GM_IF_MODE_WIDTH 2
405 #define GM_PAD_CRC_EN_LBN 2
406 #define GM_PAD_CRC_EN_WIDTH 1
408 #define GM_FD_WIDTH 1
410 /* GMAC maximum frame length register */
411 #define GM_MAX_FLEN_REG_MAC 0x04
412 #define GM_MAX_FLEN_LBN 0
413 #define GM_MAX_FLEN_WIDTH 16
415 /* GMAC MII management configuration register */
416 #define GM_MII_MGMT_CFG_REG_MAC 0x08
417 #define GM_MGMT_CLK_SEL_LBN 0
418 #define GM_MGMT_CLK_SEL_WIDTH 3
420 /* GMAC MII management command register */
421 #define GM_MII_MGMT_CMD_REG_MAC 0x09
422 #define GM_MGMT_SCAN_CYC_LBN 1
423 #define GM_MGMT_SCAN_CYC_WIDTH 1
424 #define GM_MGMT_RD_CYC_LBN 0
425 #define GM_MGMT_RD_CYC_WIDTH 1
427 /* GMAC MII management address register */
428 #define GM_MII_MGMT_ADR_REG_MAC 0x0a
429 #define GM_MGMT_PHY_ADDR_LBN 8
430 #define GM_MGMT_PHY_ADDR_WIDTH 5
431 #define GM_MGMT_REG_ADDR_LBN 0
432 #define GM_MGMT_REG_ADDR_WIDTH 5
434 /* GMAC MII management control register */
435 #define GM_MII_MGMT_CTL_REG_MAC 0x0b
436 #define GM_MGMT_CTL_LBN 0
437 #define GM_MGMT_CTL_WIDTH 16
439 /* GMAC MII management status register */
440 #define GM_MII_MGMT_STAT_REG_MAC 0x0c
441 #define GM_MGMT_STAT_LBN 0
442 #define GM_MGMT_STAT_WIDTH 16
444 /* GMAC MII management indicators register */
445 #define GM_MII_MGMT_IND_REG_MAC 0x0d
446 #define GM_MGMT_BUSY_LBN 0
447 #define GM_MGMT_BUSY_WIDTH 1
449 /* GMAC station address register 1 */
450 #define GM_ADR1_REG_MAC 0x10
451 #define GM_HWADDR_5_LBN 24
452 #define GM_HWADDR_5_WIDTH 8
453 #define GM_HWADDR_4_LBN 16
454 #define GM_HWADDR_4_WIDTH 8
455 #define GM_HWADDR_3_LBN 8
456 #define GM_HWADDR_3_WIDTH 8
457 #define GM_HWADDR_2_LBN 0
458 #define GM_HWADDR_2_WIDTH 8
460 /* GMAC station address register 2 */
461 #define GM_ADR2_REG_MAC 0x11
462 #define GM_HWADDR_1_LBN 24
463 #define GM_HWADDR_1_WIDTH 8
464 #define GM_HWADDR_0_LBN 16
465 #define GM_HWADDR_0_WIDTH 8
467 /* GMAC FIFO configuration register 0 */
468 #define GMF_CFG0_REG_MAC 0x12
469 #define GMF_FTFENREQ_LBN 12
470 #define GMF_FTFENREQ_WIDTH 1
471 #define GMF_STFENREQ_LBN 11
472 #define GMF_STFENREQ_WIDTH 1
473 #define GMF_FRFENREQ_LBN 10
474 #define GMF_FRFENREQ_WIDTH 1
475 #define GMF_SRFENREQ_LBN 9
476 #define GMF_SRFENREQ_WIDTH 1
477 #define GMF_WTMENREQ_LBN 8
478 #define GMF_WTMENREQ_WIDTH 1
480 /* GMAC FIFO configuration register 1 */
481 #define GMF_CFG1_REG_MAC 0x13
482 #define GMF_CFGFRTH_LBN 16
483 #define GMF_CFGFRTH_WIDTH 5
484 #define GMF_CFGXOFFRTX_LBN 0
485 #define GMF_CFGXOFFRTX_WIDTH 16
487 /* GMAC FIFO configuration register 2 */
488 #define GMF_CFG2_REG_MAC 0x14
489 #define GMF_CFGHWM_LBN 16
490 #define GMF_CFGHWM_WIDTH 6
491 #define GMF_CFGLWM_LBN 0
492 #define GMF_CFGLWM_WIDTH 6
494 /* GMAC FIFO configuration register 3 */
495 #define GMF_CFG3_REG_MAC 0x15
496 #define GMF_CFGHWMFT_LBN 16
497 #define GMF_CFGHWMFT_WIDTH 6
498 #define GMF_CFGFTTH_LBN 0
499 #define GMF_CFGFTTH_WIDTH 6
501 /* GMAC FIFO configuration register 4 */
502 #define GMF_CFG4_REG_MAC 0x16
503 #define GMF_HSTFLTRFRM_PAUSE_LBN 12
504 #define GMF_HSTFLTRFRM_PAUSE_WIDTH 12
506 /* GMAC FIFO configuration register 5 */
507 #define GMF_CFG5_REG_MAC 0x17
508 #define GMF_CFGHDPLX_LBN 22
509 #define GMF_CFGHDPLX_WIDTH 1
510 #define GMF_CFGBYTMODE_LBN 19
511 #define GMF_CFGBYTMODE_WIDTH 1
512 #define GMF_HSTDRPLT64_LBN 18
513 #define GMF_HSTDRPLT64_WIDTH 1
514 #define GMF_HSTFLTRFRMDC_PAUSE_LBN 12
515 #define GMF_HSTFLTRFRMDC_PAUSE_WIDTH 1
517 struct efab_mentormac_parameters {
529 static void mentormac_reset ( struct efab_nic *efab ) {
533 /* Take into reset */
534 EFAB_POPULATE_DWORD_1 ( reg, GM_SW_RST, 1 );
535 efab->mac_op->mac_writel ( efab, ®, GM_CFG1_REG_MAC );
538 /* Take out of reset */
539 EFAB_POPULATE_DWORD_1 ( reg, GM_SW_RST, 0 );
540 efab->mac_op->mac_writel ( efab, ®, GM_CFG1_REG_MAC );
543 /* Mentor MAC connects both PHYs to MAC 0 */
544 save_port = efab->port;
546 /* Configure GMII interface so PHY is accessible. Note that
547 * GMII interface is connected only to port 0, and that on
548 * Falcon this is a no-op.
550 EFAB_POPULATE_DWORD_1 ( reg, GM_MGMT_CLK_SEL, 0x4 );
551 efab->mac_op->mac_writel ( efab, ®, GM_MII_MGMT_CFG_REG_MAC );
553 efab->port = save_port;
557 * Initialise Mentor MAC
560 static void mentormac_init ( struct efab_nic *efab,
561 struct efab_mentormac_parameters *params ) {
562 int pause, if_mode, full_duplex, bytemode, half_duplex;
565 /* Configuration register 1 */
566 pause = ( efab->link_options & LPA_PAUSE ) ? 1 : 0;
567 if ( ! ( efab->link_options & LPA_DUPLEX ) ) {
568 /* Half-duplex operation requires TX flow control */
571 EFAB_POPULATE_DWORD_4 ( reg,
576 efab->mac_op->mac_writel ( efab, ®, GM_CFG1_REG_MAC );
579 /* Configuration register 2 */
580 if_mode = ( efab->link_options & LPA_1000 ) ? 2 : 1;
581 full_duplex = ( efab->link_options & LPA_DUPLEX ) ? 1 : 0;
582 EFAB_POPULATE_DWORD_4 ( reg,
586 GM_PAMBL_LEN, 0x7 /* ? */ );
587 efab->mac_op->mac_writel ( efab, ®, GM_CFG2_REG_MAC );
590 /* Max frame len register */
591 EFAB_POPULATE_DWORD_1 ( reg, GM_MAX_FLEN, ETH_FRAME_LEN + 4 /* FCS */);
592 efab->mac_op->mac_writel ( efab, ®, GM_MAX_FLEN_REG_MAC );
595 /* FIFO configuration register 0 */
596 EFAB_POPULATE_DWORD_5 ( reg,
602 efab->mac_op->mac_writel ( efab, ®, GMF_CFG0_REG_MAC );
605 /* FIFO configuration register 1 */
606 EFAB_POPULATE_DWORD_2 ( reg,
607 GMF_CFGFRTH, params->gmf_cfgfrth,
608 GMF_CFGXOFFRTX, 0xffff );
609 efab->mac_op->mac_writel ( efab, ®, GMF_CFG1_REG_MAC );
612 /* FIFO configuration register 2 */
613 EFAB_POPULATE_DWORD_2 ( reg,
614 GMF_CFGHWM, params->gmf_cfghwm,
615 GMF_CFGLWM, params->gmf_cfglwm );
616 efab->mac_op->mac_writel ( efab, ®, GMF_CFG2_REG_MAC );
619 /* FIFO configuration register 3 */
620 EFAB_POPULATE_DWORD_2 ( reg,
621 GMF_CFGHWMFT, params->gmf_cfghwmft,
622 GMF_CFGFTTH, params->gmf_cfgftth );
623 efab->mac_op->mac_writel ( efab, ®, GMF_CFG3_REG_MAC );
626 /* FIFO configuration register 4 */
627 EFAB_POPULATE_DWORD_1 ( reg, GMF_HSTFLTRFRM_PAUSE, 1 );
628 efab->mac_op->mac_writel ( efab, ®, GMF_CFG4_REG_MAC );
631 /* FIFO configuration register 5 */
632 bytemode = ( efab->link_options & LPA_1000 ) ? 1 : 0;
633 half_duplex = ( efab->link_options & LPA_DUPLEX ) ? 0 : 1;
634 efab->mac_op->mac_readl ( efab, ®, GMF_CFG5_REG_MAC );
635 EFAB_SET_DWORD_FIELD ( reg, GMF_CFGBYTMODE, bytemode );
636 EFAB_SET_DWORD_FIELD ( reg, GMF_CFGHDPLX, half_duplex );
637 EFAB_SET_DWORD_FIELD ( reg, GMF_HSTDRPLT64, half_duplex );
638 EFAB_SET_DWORD_FIELD ( reg, GMF_HSTFLTRFRMDC_PAUSE, 0 );
639 efab->mac_op->mac_writel ( efab, ®, GMF_CFG5_REG_MAC );
643 EFAB_POPULATE_DWORD_4 ( reg,
644 GM_HWADDR_5, efab->mac_addr[5],
645 GM_HWADDR_4, efab->mac_addr[4],
646 GM_HWADDR_3, efab->mac_addr[3],
647 GM_HWADDR_2, efab->mac_addr[2] );
648 efab->mac_op->mac_writel ( efab, ®, GM_ADR1_REG_MAC );
650 EFAB_POPULATE_DWORD_2 ( reg,
651 GM_HWADDR_1, efab->mac_addr[1],
652 GM_HWADDR_0, efab->mac_addr[0] );
653 efab->mac_op->mac_writel ( efab, ®, GM_ADR2_REG_MAC );
658 * Wait for GMII access to complete
661 static int mentormac_gmii_wait ( struct efab_nic *efab ) {
663 efab_dword_t indicator;
665 for ( count = 0 ; count < 1000 ; count++ ) {
667 efab->mac_op->mac_readl ( efab, &indicator,
668 GM_MII_MGMT_IND_REG_MAC );
669 if ( EFAB_DWORD_FIELD ( indicator, GM_MGMT_BUSY ) == 0 )
672 EFAB_ERR ( "Timed out waiting for GMII\n" );
677 * Write a GMII register
680 static void mentormac_mdio_write ( struct efab_nic *efab, int phy_id,
681 int location, int value ) {
685 EFAB_TRACE ( "Writing GMII %d register %02x with %04x\n", phy_id,
688 /* Mentor MAC connects both PHYs to MAC 0 */
689 save_port = efab->port;
692 /* Check MII not currently being accessed */
693 if ( ! mentormac_gmii_wait ( efab ) )
696 /* Write the address register */
697 EFAB_POPULATE_DWORD_2 ( reg,
698 GM_MGMT_PHY_ADDR, phy_id,
699 GM_MGMT_REG_ADDR, location );
700 efab->mac_op->mac_writel ( efab, ®, GM_MII_MGMT_ADR_REG_MAC );
704 EFAB_POPULATE_DWORD_1 ( reg, GM_MGMT_CTL, value );
705 efab->mac_op->mac_writel ( efab, ®, GM_MII_MGMT_CTL_REG_MAC );
707 /* Wait for data to be written */
708 mentormac_gmii_wait ( efab );
711 /* Restore efab->port */
712 efab->port = save_port;
716 * Read a GMII register
719 static int mentormac_mdio_read ( struct efab_nic *efab, int phy_id,
725 /* Mentor MAC connects both PHYs to MAC 0 */
726 save_port = efab->port;
729 /* Check MII not currently being accessed */
730 if ( ! mentormac_gmii_wait ( efab ) )
733 /* Write the address register */
734 EFAB_POPULATE_DWORD_2 ( reg,
735 GM_MGMT_PHY_ADDR, phy_id,
736 GM_MGMT_REG_ADDR, location );
737 efab->mac_op->mac_writel ( efab, ®, GM_MII_MGMT_ADR_REG_MAC );
740 /* Request data to be read */
741 EFAB_POPULATE_DWORD_1 ( reg, GM_MGMT_RD_CYC, 1 );
742 efab->mac_op->mac_writel ( efab, ®, GM_MII_MGMT_CMD_REG_MAC );
744 /* Wait for data to be become available */
745 if ( mentormac_gmii_wait ( efab ) ) {
747 efab->mac_op->mac_readl ( efab, ®, GM_MII_MGMT_STAT_REG_MAC );
748 value = EFAB_DWORD_FIELD ( reg, GM_MGMT_STAT );
749 EFAB_TRACE ( "Read from GMII %d register %02x, got %04x\n",
750 phy_id, location, value );
753 /* Signal completion */
754 EFAB_ZERO_DWORD ( reg );
755 efab->mac_op->mac_writel ( efab, ®, GM_MII_MGMT_CMD_REG_MAC );
759 /* Restore efab->port */
760 efab->port = save_port;
765 /**************************************************************************
769 **************************************************************************
772 /** Control and General Status */
773 #define EF1_CTR_GEN_STATUS0_REG 0x0
774 #define EF1_MASTER_EVENTS_LBN 12
775 #define EF1_MASTER_EVENTS_WIDTH 1
776 #define EF1_TX_ENGINE_EN_LBN 19
777 #define EF1_TX_ENGINE_EN_WIDTH 1
778 #define EF1_RX_ENGINE_EN_LBN 18
779 #define EF1_RX_ENGINE_EN_WIDTH 1
780 #define EF1_TURBO2_LBN 17
781 #define EF1_TURBO2_WIDTH 1
782 #define EF1_TURBO1_LBN 16
783 #define EF1_TURBO1_WIDTH 1
784 #define EF1_TURBO3_LBN 14
785 #define EF1_TURBO3_WIDTH 1
786 #define EF1_LB_RESET_LBN 3
787 #define EF1_LB_RESET_WIDTH 1
788 #define EF1_MAC_RESET_LBN 2
789 #define EF1_MAC_RESET_WIDTH 1
790 #define EF1_CAM_ENABLE_LBN 1
791 #define EF1_CAM_ENABLE_WIDTH 1
794 #define EF1_IRQ_SRC_REG 0x0008
797 #define EF1_IRQ_MASK_REG 0x000c
798 #define EF1_IRQ_PHY1_LBN 11
799 #define EF1_IRQ_PHY1_WIDTH 1
800 #define EF1_IRQ_PHY0_LBN 10
801 #define EF1_IRQ_PHY0_WIDTH 1
802 #define EF1_IRQ_SERR_LBN 7
803 #define EF1_IRQ_SERR_WIDTH 1
804 #define EF1_IRQ_EVQ_LBN 3
805 #define EF1_IRQ_EVQ_WIDTH 1
807 /** Event generation */
808 #define EF1_EVT3_REG 0x38
811 #define EF1_EEPROM_REG 0x40
812 #define EF1_EEPROM_SDA_LBN 31
813 #define EF1_EEPROM_SDA_WIDTH 1
814 #define EF1_EEPROM_SCL_LBN 30
815 #define EF1_EEPROM_SCL_WIDTH 1
816 #define EF1_JTAG_DISCONNECT_LBN 17
817 #define EF1_JTAG_DISCONNECT_WIDTH 1
818 #define EF1_EEPROM_LBN 0
819 #define EF1_EEPROM_WIDTH 32
821 /** Control register 2 */
822 #define EF1_CTL2_REG 0x4c
823 #define EF1_PLL_TRAP_LBN 31
824 #define EF1_PLL_TRAP_WIDTH 1
825 #define EF1_MEM_MAP_4MB_LBN 11
826 #define EF1_MEM_MAP_4MB_WIDTH 1
827 #define EF1_EV_INTR_CLR_WRITE_LBN 6
828 #define EF1_EV_INTR_CLR_WRITE_WIDTH 1
829 #define EF1_BURST_MERGE_LBN 5
830 #define EF1_BURST_MERGE_WIDTH 1
831 #define EF1_CLEAR_NULL_PAD_LBN 4
832 #define EF1_CLEAR_NULL_PAD_WIDTH 1
833 #define EF1_SW_RESET_LBN 2
834 #define EF1_SW_RESET_WIDTH 1
835 #define EF1_INTR_AFTER_EVENT_LBN 1
836 #define EF1_INTR_AFTER_EVENT_WIDTH 1
839 #define EF1_EVENT_FIFO_REG 0x50
841 /** Event FIFO count */
842 #define EF1_EVENT_FIFO_COUNT_REG 0x5c
843 #define EF1_EV_COUNT_LBN 0
844 #define EF1_EV_COUNT_WIDTH 16
846 /** TX DMA control and status */
847 #define EF1_DMA_TX_CSR_REG 0x80
848 #define EF1_DMA_TX_CSR_CHAIN_EN_LBN 8
849 #define EF1_DMA_TX_CSR_CHAIN_EN_WIDTH 1
850 #define EF1_DMA_TX_CSR_ENABLE_LBN 4
851 #define EF1_DMA_TX_CSR_ENABLE_WIDTH 1
852 #define EF1_DMA_TX_CSR_INT_EN_LBN 0
853 #define EF1_DMA_TX_CSR_INT_EN_WIDTH 1
855 /** RX DMA control and status */
856 #define EF1_DMA_RX_CSR_REG 0xa0
857 #define EF1_DMA_RX_ABOVE_1GB_EN_LBN 6
858 #define EF1_DMA_RX_ABOVE_1GB_EN_WIDTH 1
859 #define EF1_DMA_RX_BELOW_1MB_EN_LBN 5
860 #define EF1_DMA_RX_BELOW_1MB_EN_WIDTH 1
861 #define EF1_DMA_RX_CSR_ENABLE_LBN 0
862 #define EF1_DMA_RX_CSR_ENABLE_WIDTH 1
864 /** Level 5 watermark register (in MAC space) */
865 #define EF1_GMF_L5WM_REG_MAC 0x20
866 #define EF1_L5WM_LBN 0
867 #define EF1_L5WM_WIDTH 32
870 #define EF1_GM_MAC_CLK_REG 0x112000
871 #define EF1_GM_PORT0_MAC_CLK_LBN 0
872 #define EF1_GM_PORT0_MAC_CLK_WIDTH 1
873 #define EF1_GM_PORT1_MAC_CLK_LBN 1
874 #define EF1_GM_PORT1_MAC_CLK_WIDTH 1
876 /** TX descriptor FIFO */
877 #define EF1_TX_DESC_FIFO 0x141000
878 #define EF1_TX_KER_EVQ_LBN 80
879 #define EF1_TX_KER_EVQ_WIDTH 12
880 #define EF1_TX_KER_IDX_LBN 64
881 #define EF1_TX_KER_IDX_WIDTH 16
882 #define EF1_TX_KER_MODE_LBN 63
883 #define EF1_TX_KER_MODE_WIDTH 1
884 #define EF1_TX_KER_PORT_LBN 60
885 #define EF1_TX_KER_PORT_WIDTH 1
886 #define EF1_TX_KER_CONT_LBN 56
887 #define EF1_TX_KER_CONT_WIDTH 1
888 #define EF1_TX_KER_BYTE_CNT_LBN 32
889 #define EF1_TX_KER_BYTE_CNT_WIDTH 24
890 #define EF1_TX_KER_BUF_ADR_LBN 0
891 #define EF1_TX_KER_BUF_ADR_WIDTH 32
893 /** TX descriptor FIFO flush */
894 #define EF1_TX_DESC_FIFO_FLUSH 0x141ffc
896 /** RX descriptor FIFO */
897 #define EF1_RX_DESC_FIFO 0x145000
898 #define EF1_RX_KER_EVQ_LBN 48
899 #define EF1_RX_KER_EVQ_WIDTH 12
900 #define EF1_RX_KER_IDX_LBN 32
901 #define EF1_RX_KER_IDX_WIDTH 16
902 #define EF1_RX_KER_BUF_ADR_LBN 0
903 #define EF1_RX_KER_BUF_ADR_WIDTH 32
905 /** RX descriptor FIFO flush */
906 #define EF1_RX_DESC_FIFO_FLUSH 0x145ffc
909 #define EF1_CAM_BASE 0x1c0000
910 #define EF1_CAM_WTF_DOES_THIS_DO_LBN 0
911 #define EF1_CAM_WTF_DOES_THIS_DO_WIDTH 32
913 /** Event queue pointers */
914 #define EF1_EVQ_PTR_BASE 0x260000
915 #define EF1_EVQ_SIZE_LBN 29
916 #define EF1_EVQ_SIZE_WIDTH 2
917 #define EF1_EVQ_SIZE_4K 3
918 #define EF1_EVQ_SIZE_2K 2
919 #define EF1_EVQ_SIZE_1K 1
920 #define EF1_EVQ_SIZE_512 0
921 #define EF1_EVQ_BUF_BASE_ID_LBN 0
922 #define EF1_EVQ_BUF_BASE_ID_WIDTH 29
925 #define EF1002_MAC_REGBANK 0x110000
926 #define EF1002_MAC_REGBANK_SIZE 0x1000
927 #define EF1002_MAC_REG_SIZE 0x08
929 /** Offset of a MAC register within EF1002 */
930 #define EF1002_MAC_REG( efab, mac_reg ) \
931 ( EF1002_MAC_REGBANK + \
932 ( (efab)->port * EF1002_MAC_REGBANK_SIZE ) + \
933 ( (mac_reg) * EF1002_MAC_REG_SIZE ) )
935 /* Event queue entries */
936 #define EF1_EV_CODE_LBN 20
937 #define EF1_EV_CODE_WIDTH 8
938 #define EF1_RX_EV_DECODE 0x01
939 #define EF1_TX_EV_DECODE 0x02
940 #define EF1_TIMER_EV_DECODE 0x0b
941 #define EF1_DRV_GEN_EV_DECODE 0x0f
944 #define EF1_RX_EV_LEN_LBN 48
945 #define EF1_RX_EV_LEN_WIDTH 16
946 #define EF1_RX_EV_PORT_LBN 17
947 #define EF1_RX_EV_PORT_WIDTH 3
948 #define EF1_RX_EV_OK_LBN 16
949 #define EF1_RX_EV_OK_WIDTH 1
950 #define EF1_RX_EV_IDX_LBN 0
951 #define EF1_RX_EV_IDX_WIDTH 16
953 /* Transmit events */
954 #define EF1_TX_EV_PORT_LBN 17
955 #define EF1_TX_EV_PORT_WIDTH 3
956 #define EF1_TX_EV_OK_LBN 16
957 #define EF1_TX_EV_OK_WIDTH 1
958 #define EF1_TX_EV_IDX_LBN 0
959 #define EF1_TX_EV_IDX_WIDTH 16
961 /* forward decleration */
962 static struct efab_mac_operations ef1002_mac_operations;
964 /* I2C ID of the EEPROM */
965 #define EF1_EEPROM_I2C_ID 0x50
967 /* Offset of MAC address within EEPROM */
968 #define EF1_EEPROM_HWADDR_OFFSET 0x0
971 * Write dword to EF1002 register
974 static inline void ef1002_writel ( struct efab_nic *efab, efab_dword_t *value,
976 EFAB_REGDUMP ( "Writing register %x with " EFAB_DWORD_FMT "\n",
977 reg, EFAB_DWORD_VAL ( *value ) );
978 writel ( value->u32[0], efab->membase + reg );
982 * Read dword from an EF1002 register
985 static inline void ef1002_readl ( struct efab_nic *efab, efab_dword_t *value,
987 value->u32[0] = readl ( efab->membase + reg );
988 EFAB_REGDUMP ( "Read from register %x, got " EFAB_DWORD_FMT "\n",
989 reg, EFAB_DWORD_VAL ( *value ) );
993 * Read dword from an EF1002 register, silently
996 static inline void ef1002_readl_silent ( struct efab_nic *efab,
999 value->u32[0] = readl ( efab->membase + reg );
1006 static void ef1002_get_membase ( struct efab_nic *efab ) {
1007 unsigned long membase_phys;
1009 membase_phys = pci_bar_start ( efab->pci, PCI_BASE_ADDRESS_0 );
1010 efab->membase = ioremap ( membase_phys, 0x800000 );
1013 /** PCI registers to backup/restore over a device reset */
1014 static const unsigned int efab_pci_reg_addr[] = {
1015 PCI_COMMAND, 0x0c /* PCI_CACHE_LINE_SIZE */,
1016 PCI_BASE_ADDRESS_0, PCI_BASE_ADDRESS_1, PCI_BASE_ADDRESS_2,
1017 PCI_BASE_ADDRESS_3, PCI_ROM_ADDRESS, PCI_INTERRUPT_LINE,
1019 /** Number of registers in efab_pci_reg_addr */
1020 #define EFAB_NUM_PCI_REG \
1021 ( sizeof ( efab_pci_reg_addr ) / sizeof ( efab_pci_reg_addr[0] ) )
1022 /** PCI configuration space backup */
1023 struct efab_pci_reg {
1024 uint32_t reg[EFAB_NUM_PCI_REG];
1028 * I2C interface and EEPROM
1032 static unsigned long ef1002_i2c_bits[] = {
1033 [I2C_BIT_SCL] = ( 1 << 30 ),
1034 [I2C_BIT_SDA] = ( 1 << 31 ),
1037 static void ef1002_i2c_write_bit ( struct bit_basher *basher,
1038 unsigned int bit_id, unsigned long data ) {
1039 struct efab_nic *efab = container_of ( basher, struct efab_nic,
1040 ef1002_i2c.basher );
1044 mask = ef1002_i2c_bits[bit_id];
1045 efab->ef1002_i2c_outputs &= ~mask;
1046 efab->ef1002_i2c_outputs |= ( data & mask );
1047 EFAB_POPULATE_DWORD_1 ( reg, EF1_EEPROM, efab->ef1002_i2c_outputs );
1048 ef1002_writel ( efab, ®, EF1_EEPROM_REG );
1051 static int ef1002_i2c_read_bit ( struct bit_basher *basher,
1052 unsigned int bit_id ) {
1053 struct efab_nic *efab = container_of ( basher, struct efab_nic,
1054 ef1002_i2c.basher );
1058 mask = ef1002_i2c_bits[bit_id];
1059 ef1002_readl ( efab, ®, EF1_EEPROM_REG );
1060 return ( EFAB_DWORD_FIELD ( reg, EF1_EEPROM ) & mask );
1063 static struct bit_basher_operations ef1002_basher_ops = {
1064 .read = ef1002_i2c_read_bit,
1065 .write = ef1002_i2c_write_bit,
1068 static void ef1002_init_eeprom ( struct efab_nic *efab ) {
1069 efab->ef1002_i2c.basher.op = &ef1002_basher_ops;
1070 init_i2c_bit_basher ( &efab->ef1002_i2c );
1071 efab->ef1002_eeprom.address = EF1_EEPROM_I2C_ID;
1078 static int ef1002_reset ( struct efab_nic *efab ) {
1079 struct efab_pci_reg pci_reg;
1080 struct pci_device *pci_dev = efab->pci;
1085 /* Back up PCI configuration registers */
1086 for ( i = 0 ; i < EFAB_NUM_PCI_REG ; i++ ) {
1087 pci_read_config_dword ( pci_dev, efab_pci_reg_addr[i],
1091 /* Reset the whole device. */
1092 EFAB_POPULATE_DWORD_1 ( reg, EF1_SW_RESET, 1 );
1093 ef1002_writel ( efab, ®, EF1_CTL2_REG );
1096 /* Restore PCI configuration space */
1097 for ( i = 0 ; i < EFAB_NUM_PCI_REG ; i++ ) {
1098 pci_write_config_dword ( pci_dev, efab_pci_reg_addr[i],
1102 /* Verify PCI configuration space */
1103 for ( i = 0 ; i < EFAB_NUM_PCI_REG ; i++ ) {
1104 pci_read_config_dword ( pci_dev, efab_pci_reg_addr[i], &tmp );
1105 if ( tmp != pci_reg.reg[i] ) {
1106 EFAB_LOG ( "PCI restore failed on register %02x "
1107 "(is %08lx, should be %08lx); reboot\n",
1108 i, tmp, pci_reg.reg[i] );
1113 /* Verify device reset complete */
1114 ef1002_readl ( efab, ®, EF1_CTR_GEN_STATUS0_REG );
1115 if ( EFAB_DWORD_IS_ALL_ONES ( reg ) ) {
1116 EFAB_ERR ( "Reset failed\n" );
1127 static int ef1002_init_nic ( struct efab_nic *efab ) {
1130 /* patch in the MAC operations */
1131 efab->mac_op = &ef1002_mac_operations;
1133 /* No idea what CAM is, but the 'datasheet' says that we have
1134 * to write these values in at start of day
1136 EFAB_POPULATE_DWORD_1 ( reg, EF1_CAM_WTF_DOES_THIS_DO, 0x6 );
1137 ef1002_writel ( efab, ®, EF1_CAM_BASE + 0x20018 );
1139 EFAB_POPULATE_DWORD_1 ( reg, EF1_CAM_WTF_DOES_THIS_DO, 0x01000000 );
1140 ef1002_writel ( efab, ®, EF1_CAM_BASE + 0x00018 );
1143 /* General control register 0 */
1144 ef1002_readl ( efab, ®, EF1_CTR_GEN_STATUS0_REG );
1145 EFAB_SET_DWORD_FIELD ( reg, EF1_MASTER_EVENTS, 0 );
1146 EFAB_SET_DWORD_FIELD ( reg, EF1_TX_ENGINE_EN, 0 );
1147 EFAB_SET_DWORD_FIELD ( reg, EF1_RX_ENGINE_EN, 0 );
1148 EFAB_SET_DWORD_FIELD ( reg, EF1_TURBO2, 1 );
1149 EFAB_SET_DWORD_FIELD ( reg, EF1_TURBO1, 1 );
1150 EFAB_SET_DWORD_FIELD ( reg, EF1_TURBO3, 1 );
1151 EFAB_SET_DWORD_FIELD ( reg, EF1_CAM_ENABLE, 1 );
1152 ef1002_writel ( efab, ®, EF1_CTR_GEN_STATUS0_REG );
1155 /* General control register 2 */
1156 ef1002_readl ( efab, ®, EF1_CTL2_REG );
1157 EFAB_SET_DWORD_FIELD ( reg, EF1_PLL_TRAP, 1 );
1158 EFAB_SET_DWORD_FIELD ( reg, EF1_MEM_MAP_4MB, 0 );
1159 EFAB_SET_DWORD_FIELD ( reg, EF1_EV_INTR_CLR_WRITE, 0 );
1160 EFAB_SET_DWORD_FIELD ( reg, EF1_BURST_MERGE, 0 );
1161 EFAB_SET_DWORD_FIELD ( reg, EF1_CLEAR_NULL_PAD, 1 );
1162 EFAB_SET_DWORD_FIELD ( reg, EF1_INTR_AFTER_EVENT, 1 );
1163 ef1002_writel ( efab, ®, EF1_CTL2_REG );
1167 ef1002_readl ( efab, ®, EF1_DMA_RX_CSR_REG );
1168 EFAB_SET_DWORD_FIELD ( reg, EF1_DMA_RX_CSR_ENABLE, 1 );
1169 EFAB_SET_DWORD_FIELD ( reg, EF1_DMA_RX_BELOW_1MB_EN, 1 );
1170 EFAB_SET_DWORD_FIELD ( reg, EF1_DMA_RX_ABOVE_1GB_EN, 1 );
1171 ef1002_writel ( efab, ®, EF1_DMA_RX_CSR_REG );
1175 ef1002_readl ( efab, ®, EF1_DMA_TX_CSR_REG );
1176 EFAB_SET_DWORD_FIELD ( reg, EF1_DMA_TX_CSR_CHAIN_EN, 1 );
1177 EFAB_SET_DWORD_FIELD ( reg, EF1_DMA_TX_CSR_ENABLE, 0 /* ?? */ );
1178 EFAB_SET_DWORD_FIELD ( reg, EF1_DMA_TX_CSR_INT_EN, 0 /* ?? */ );
1179 ef1002_writel ( efab, ®, EF1_DMA_TX_CSR_REG );
1182 /* Disconnect the JTAG chain. Read-modify-write is impossible
1183 * on the I2C control bits, since reading gives the state of
1184 * the line inputs rather than the last written state.
1186 ef1002_readl ( efab, ®, EF1_EEPROM_REG );
1187 EFAB_SET_DWORD_FIELD ( reg, EF1_EEPROM_SDA, 1 );
1188 EFAB_SET_DWORD_FIELD ( reg, EF1_EEPROM_SCL, 1 );
1189 EFAB_SET_DWORD_FIELD ( reg, EF1_JTAG_DISCONNECT, 1 );
1190 ef1002_writel ( efab, ®, EF1_EEPROM_REG );
1193 /* Flush descriptor queues */
1194 EFAB_ZERO_DWORD ( reg );
1195 ef1002_writel ( efab, ®, EF1_RX_DESC_FIFO_FLUSH );
1196 ef1002_writel ( efab, ®, EF1_TX_DESC_FIFO_FLUSH );
1201 efab->mac_op->reset ( efab );
1203 /* Attach I2C bus */
1204 ef1002_init_eeprom ( efab );
1210 * Read MAC address from EEPROM
1213 static int ef1002_read_eeprom ( struct efab_nic *efab ) {
1214 struct i2c_interface *i2c = &efab->ef1002_i2c.i2c;
1215 struct i2c_device *i2cdev = &efab->ef1002_eeprom;
1217 return ( i2c->read ( i2c, i2cdev, EF1_EEPROM_HWADDR_OFFSET,
1218 efab->mac_addr, sizeof ( efab->mac_addr ) ) == 0);
1221 /** RX descriptor */
1222 typedef efab_qword_t ef1002_rx_desc_t;
1225 * Build RX descriptor
1228 static void ef1002_build_rx_desc ( struct efab_nic *efab,
1229 struct efab_rx_buf *rx_buf ) {
1230 ef1002_rx_desc_t rxd;
1232 EFAB_POPULATE_QWORD_3 ( rxd,
1234 EF1_RX_KER_IDX, rx_buf->id,
1236 virt_to_bus ( rx_buf->addr ) );
1237 ef1002_writel ( efab, &rxd.dword[0], EF1_RX_DESC_FIFO + 0 );
1239 ef1002_writel ( efab, &rxd.dword[1], EF1_RX_DESC_FIFO + 4 );
1244 * Update RX descriptor write pointer
1247 static void ef1002_notify_rx_desc ( struct efab_nic *efab __unused ) {
1251 /** TX descriptor */
1252 typedef efab_oword_t ef1002_tx_desc_t;
1255 * Build TX descriptor
1258 static void ef1002_build_tx_desc ( struct efab_nic *efab,
1259 struct efab_tx_buf *tx_buf ) {
1260 ef1002_tx_desc_t txd;
1262 EFAB_POPULATE_OWORD_7 ( txd,
1264 EF1_TX_KER_IDX, tx_buf->id,
1265 EF1_TX_KER_MODE, 0 /* IP mode */,
1266 EF1_TX_KER_PORT, efab->port,
1268 EF1_TX_KER_BYTE_CNT, tx_buf->len,
1270 virt_to_bus ( tx_buf->addr ) );
1272 ef1002_writel ( efab, &txd.dword[0], EF1_TX_DESC_FIFO + 0 );
1273 ef1002_writel ( efab, &txd.dword[1], EF1_TX_DESC_FIFO + 4 );
1275 ef1002_writel ( efab, &txd.dword[2], EF1_TX_DESC_FIFO + 8 );
1280 * Update TX descriptor write pointer
1283 static void ef1002_notify_tx_desc ( struct efab_nic *efab __unused ) {
1288 typedef efab_qword_t ef1002_event_t;
1291 * Retrieve event from event queue
1294 static int ef1002_fetch_event ( struct efab_nic *efab,
1295 struct efab_event *event ) {
1300 /* Check event FIFO depth */
1301 ef1002_readl_silent ( efab, ®, EF1_EVENT_FIFO_COUNT_REG );
1302 words = EFAB_DWORD_FIELD ( reg, EF1_EV_COUNT );
1306 /* Read event data */
1307 ef1002_readl ( efab, ®, EF1_EVENT_FIFO_REG );
1308 DBG ( "Event is " EFAB_DWORD_FMT "\n", EFAB_DWORD_VAL ( reg ) );
1311 ev_code = EFAB_DWORD_FIELD ( reg, EF1_EV_CODE );
1313 switch ( ev_code ) {
1314 case EF1_TX_EV_DECODE:
1315 event->type = EFAB_EV_TX;
1317 case EF1_RX_EV_DECODE:
1318 event->type = EFAB_EV_RX;
1319 event->rx_id = EFAB_DWORD_FIELD ( reg, EF1_RX_EV_IDX );
1320 /* RX len not available via event FIFO */
1321 event->rx_len = ETH_FRAME_LEN;
1323 case EF1_TIMER_EV_DECODE:
1324 /* These are safe to ignore. We seem to get some at
1325 * start of day, presumably due to the timers starting
1326 * up with random contents.
1328 event->type = EFAB_EV_NONE;
1331 EFAB_ERR ( "Unknown event type %d\n", ev_code );
1332 event->type = EFAB_EV_NONE;
1335 /* Clear any pending interrupts */
1336 ef1002_readl ( efab, ®, EF1_IRQ_SRC_REG );
1342 * Enable/disable interrupts
1345 static void ef1002_mask_irq ( struct efab_nic *efab, int enabled ) {
1346 efab_dword_t irq_mask;
1348 EFAB_POPULATE_DWORD_2 ( irq_mask,
1349 EF1_IRQ_SERR, enabled,
1350 EF1_IRQ_EVQ, enabled );
1351 ef1002_writel ( efab, &irq_mask, EF1_IRQ_MASK_REG );
1355 * Generate interrupt
1358 static void ef1002_generate_irq ( struct efab_nic *efab ) {
1359 ef1002_event_t test_event;
1361 EFAB_POPULATE_QWORD_1 ( test_event,
1362 EF1_EV_CODE, EF1_DRV_GEN_EV_DECODE );
1363 ef1002_writel ( efab, &test_event.dword[0], EF1_EVT3_REG );
1367 * Write dword to an EF1002 MAC register
1370 static void ef1002_mac_writel ( struct efab_nic *efab,
1371 efab_dword_t *value, unsigned int mac_reg ) {
1372 ef1002_writel ( efab, value, EF1002_MAC_REG ( efab, mac_reg ) );
1376 * Read dword from an EF1002 MAC register
1379 static void ef1002_mac_readl ( struct efab_nic *efab,
1380 efab_dword_t *value, unsigned int mac_reg ) {
1381 ef1002_readl ( efab, value, EF1002_MAC_REG ( efab, mac_reg ) );
1388 static int ef1002_init_mac ( struct efab_nic *efab ) {
1389 static struct efab_mentormac_parameters ef1002_mentormac_params = {
1390 .gmf_cfgfrth = 0x13,
1391 .gmf_cfgftth = 0x10,
1392 .gmf_cfghwmft = 0x555,
1397 unsigned int mac_clk;
1399 /* Initialise PHY */
1400 alaska_init ( efab );
1402 /* Initialise MAC */
1403 mentormac_init ( efab, &ef1002_mentormac_params );
1405 /* Write Level 5 watermark register */
1406 EFAB_POPULATE_DWORD_1 ( reg, EF1_L5WM, 0x10040000 );
1407 efab->mac_op->mac_writel ( efab, ®, EF1_GMF_L5WM_REG_MAC );
1410 /* Set MAC clock speed */
1411 ef1002_readl ( efab, ®, EF1_GM_MAC_CLK_REG );
1412 mac_clk = ( efab->link_options & LPA_1000 ) ? 0 : 1;
1413 if ( efab->port == 0 ) {
1414 EFAB_SET_DWORD_FIELD ( reg, EF1_GM_PORT0_MAC_CLK, mac_clk );
1416 EFAB_SET_DWORD_FIELD ( reg, EF1_GM_PORT1_MAC_CLK, mac_clk );
1418 ef1002_writel ( efab, ®, EF1_GM_MAC_CLK_REG );
1428 static int ef1002_reset_mac ( struct efab_nic *efab ) {
1429 mentormac_reset ( efab );
1434 static void ef1002_mdio_write ( struct efab_nic *efab, int location,
1436 mentormac_mdio_write ( efab, efab->port + 2, location, value );
1440 static int ef1002_mdio_read ( struct efab_nic *efab, int location ) {
1441 return mentormac_mdio_read ( efab, efab->port + 2, location );
1444 static struct efab_operations ef1002_operations = {
1445 .get_membase = ef1002_get_membase,
1446 .reset = ef1002_reset,
1447 .init_nic = ef1002_init_nic,
1448 .read_eeprom = ef1002_read_eeprom,
1449 .build_rx_desc = ef1002_build_rx_desc,
1450 .notify_rx_desc = ef1002_notify_rx_desc,
1451 .build_tx_desc = ef1002_build_tx_desc,
1452 .notify_tx_desc = ef1002_notify_tx_desc,
1453 .fetch_event = ef1002_fetch_event,
1454 .mask_irq = ef1002_mask_irq,
1455 .generate_irq = ef1002_generate_irq,
1456 .mdio_write = ef1002_mdio_write,
1457 .mdio_read = ef1002_mdio_read,
1460 static struct efab_mac_operations ef1002_mac_operations = {
1461 .mac_writel = ef1002_mac_writel,
1462 .mac_readl = ef1002_mac_readl,
1463 .init = ef1002_init_mac,
1464 .reset = ef1002_reset_mac,
1467 /**************************************************************************
1471 **************************************************************************
1474 /* I/O BAR address register */
1475 #define FCN_IOM_IND_ADR_REG 0x0
1477 /* I/O BAR data register */
1478 #define FCN_IOM_IND_DAT_REG 0x4
1480 /* Interrupt enable register */
1481 #define FCN_INT_EN_REG_KER 0x0010
1482 #define FCN_MEM_PERR_INT_EN_KER_LBN 5
1483 #define FCN_MEM_PERR_INT_EN_KER_WIDTH 1
1484 #define FCN_KER_INT_CHAR_LBN 4
1485 #define FCN_KER_INT_CHAR_WIDTH 1
1486 #define FCN_KER_INT_KER_LBN 3
1487 #define FCN_KER_INT_KER_WIDTH 1
1488 #define FCN_ILL_ADR_ERR_INT_EN_KER_LBN 2
1489 #define FCN_ILL_ADR_ERR_INT_EN_KER_WIDTH 1
1490 #define FCN_SRM_PERR_INT_EN_KER_LBN 1
1491 #define FCN_SRM_PERR_INT_EN_KER_WIDTH 1
1492 #define FCN_DRV_INT_EN_KER_LBN 0
1493 #define FCN_DRV_INT_EN_KER_WIDTH 1
1495 /* Interrupt status register */
1496 #define FCN_INT_ADR_REG_KER 0x0030
1497 #define FCN_INT_ADR_KER_LBN 0
1498 #define FCN_INT_ADR_KER_WIDTH EFAB_DMA_TYPE_WIDTH ( 64 )
1500 /* Interrupt acknowledge register */
1501 #define FCN_INT_ACK_KER_REG 0x0050
1503 /* SPI host command register */
1504 #define FCN_EE_SPI_HCMD_REG_KER 0x0100
1505 #define FCN_EE_SPI_HCMD_CMD_EN_LBN 31
1506 #define FCN_EE_SPI_HCMD_CMD_EN_WIDTH 1
1507 #define FCN_EE_WR_TIMER_ACTIVE_LBN 28
1508 #define FCN_EE_WR_TIMER_ACTIVE_WIDTH 1
1509 #define FCN_EE_SPI_HCMD_SF_SEL_LBN 24
1510 #define FCN_EE_SPI_HCMD_SF_SEL_WIDTH 1
1511 #define FCN_EE_SPI_EEPROM 0
1512 #define FCN_EE_SPI_FLASH 1
1513 #define FCN_EE_SPI_HCMD_DABCNT_LBN 16
1514 #define FCN_EE_SPI_HCMD_DABCNT_WIDTH 5
1515 #define FCN_EE_SPI_HCMD_READ_LBN 15
1516 #define FCN_EE_SPI_HCMD_READ_WIDTH 1
1517 #define FCN_EE_SPI_READ 1
1518 #define FCN_EE_SPI_WRITE 0
1519 #define FCN_EE_SPI_HCMD_DUBCNT_LBN 12
1520 #define FCN_EE_SPI_HCMD_DUBCNT_WIDTH 2
1521 #define FCN_EE_SPI_HCMD_ADBCNT_LBN 8
1522 #define FCN_EE_SPI_HCMD_ADBCNT_WIDTH 2
1523 #define FCN_EE_SPI_HCMD_ENC_LBN 0
1524 #define FCN_EE_SPI_HCMD_ENC_WIDTH 8
1526 /* SPI host address register */
1527 #define FCN_EE_SPI_HADR_REG_KER 0x0110
1528 #define FCN_EE_SPI_HADR_DUBYTE_LBN 24
1529 #define FCN_EE_SPI_HADR_DUBYTE_WIDTH 8
1530 #define FCN_EE_SPI_HADR_ADR_LBN 0
1531 #define FCN_EE_SPI_HADR_ADR_WIDTH 24
1533 /* SPI host data register */
1534 #define FCN_EE_SPI_HDATA_REG_KER 0x0120
1535 #define FCN_EE_SPI_HDATA3_LBN 96
1536 #define FCN_EE_SPI_HDATA3_WIDTH 32
1537 #define FCN_EE_SPI_HDATA2_LBN 64
1538 #define FCN_EE_SPI_HDATA2_WIDTH 32
1539 #define FCN_EE_SPI_HDATA1_LBN 32
1540 #define FCN_EE_SPI_HDATA1_WIDTH 32
1541 #define FCN_EE_SPI_HDATA0_LBN 0
1542 #define FCN_EE_SPI_HDATA0_WIDTH 32
1544 /* NIC status register */
1545 #define FCN_NIC_STAT_REG 0x0200
1546 #define ONCHIP_SRAM_LBN 16
1547 #define ONCHIP_SRAM_WIDTH 1
1548 #define SF_PRST_LBN 9
1549 #define SF_PRST_WIDTH 1
1550 #define EE_PRST_LBN 8
1551 #define EE_PRST_WIDTH 1
1552 #define EE_STRAP_LBN 7
1553 #define EE_STRAP_WIDTH 1
1554 #define PCI_PCIX_MODE_LBN 4
1555 #define PCI_PCIX_MODE_WIDTH 3
1556 #define PCI_PCIX_MODE_PCI33_DECODE 0
1557 #define PCI_PCIX_MODE_PCI66_DECODE 1
1558 #define PCI_PCIX_MODE_PCIX66_DECODE 5
1559 #define PCI_PCIX_MODE_PCIX100_DECODE 6
1560 #define PCI_PCIX_MODE_PCIX133_DECODE 7
1561 #define STRAP_ISCSI_EN_LBN 3
1562 #define STRAP_ISCSI_EN_WIDTH 1
1563 #define STRAP_PINS_LBN 0
1564 #define STRAP_PINS_WIDTH 3
1565 /* These bit definitions are extrapolated from the list of numerical
1566 * values for STRAP_PINS. If you want a laugh, read the datasheet's
1567 * definition for when bits 2:0 are set to 7.
1569 #define STRAP_10G_LBN 2
1570 #define STRAP_10G_WIDTH 1
1571 #define STRAP_DUAL_PORT_LBN 1
1572 #define STRAP_DUAL_PORT_WIDTH 1
1573 #define STRAP_PCIE_LBN 0
1574 #define STRAP_PCIE_WIDTH 1
1576 /* GPIO control register */
1577 #define FCN_GPIO_CTL_REG_KER 0x0210
1578 #define FCN_FLASH_PRESENT_LBN 7
1579 #define FCN_FLASH_PRESENT_WIDTH 1
1580 #define FCN_EEPROM_PRESENT_LBN 6
1581 #define FCN_EEPROM_PRESENT_WIDTH 1
1583 /* Global control register */
1584 #define FCN_GLB_CTL_REG_KER 0x0220
1585 #define EXT_PHY_RST_CTL_LBN 63
1586 #define EXT_PHY_RST_CTL_WIDTH 1
1587 #define PCIE_SD_RST_CTL_LBN 61
1588 #define PCIE_SD_RST_CTL_WIDTH 1
1589 #define PCIX_RST_CTL_LBN 60
1590 #define PCIX_RST_CTL_WIDTH 1
1591 #define PCIE_STCK_RST_CTL_LBN 59
1592 #define PCIE_STCK_RST_CTL_WIDTH 1
1593 #define PCIE_NSTCK_RST_CTL_LBN 58
1594 #define PCIE_NSTCK_RST_CTL_WIDTH 1
1595 #define PCIE_CORE_RST_CTL_LBN 57
1596 #define PCIE_CORE_RST_CTL_WIDTH 1
1597 #define EE_RST_CTL_LBN 49
1598 #define EE_RST_CTL_WIDTH 1
1599 #define CS_RST_CTL_LBN 48
1600 #define CS_RST_CTL_WIDTH 1
1601 #define RST_EXT_PHY_LBN 31
1602 #define RST_EXT_PHY_WIDTH 1
1603 #define INT_RST_DUR_LBN 4
1604 #define INT_RST_DUR_WIDTH 3
1605 #define EXT_PHY_RST_DUR_LBN 1
1606 #define EXT_PHY_RST_DUR_WIDTH 3
1608 #define SWRST_WIDTH 1
1609 #define INCLUDE_IN_RESET 0
1610 #define EXCLUDE_FROM_RESET 1
1612 /* FPGA build version */
1613 #define ALTERA_BUILD_REG_KER 0x0300
1614 #define VER_MAJOR_LBN 24
1615 #define VER_MAJOR_WIDTH 8
1616 #define VER_MINOR_LBN 16
1617 #define VER_MINOR_WIDTH 8
1618 #define VER_BUILD_LBN 0
1619 #define VER_BUILD_WIDTH 16
1620 #define VER_ALL_LBN 0
1621 #define VER_ALL_WIDTH 32
1623 /* Timer table for kernel access */
1624 #define FCN_TIMER_CMD_REG_KER 0x420
1625 #define FCN_TIMER_MODE_LBN 12
1626 #define FCN_TIMER_MODE_WIDTH 2
1627 #define FCN_TIMER_MODE_DIS 0
1628 #define FCN_TIMER_MODE_INT_HLDOFF 1
1629 #define FCN_TIMER_VAL_LBN 0
1630 #define FCN_TIMER_VAL_WIDTH 12
1632 /* Receive configuration register */
1633 #define FCN_RX_CFG_REG_KER 0x800
1634 #define FCN_RX_XOFF_EN_LBN 0
1635 #define FCN_RX_XOFF_EN_WIDTH 1
1637 /* SRAM receive descriptor cache configuration register */
1638 #define FCN_SRM_RX_DC_CFG_REG_KER 0x610
1639 #define FCN_SRM_RX_DC_BASE_ADR_LBN 0
1640 #define FCN_SRM_RX_DC_BASE_ADR_WIDTH 21
1642 /* SRAM transmit descriptor cache configuration register */
1643 #define FCN_SRM_TX_DC_CFG_REG_KER 0x620
1644 #define FCN_SRM_TX_DC_BASE_ADR_LBN 0
1645 #define FCN_SRM_TX_DC_BASE_ADR_WIDTH 21
1647 /* Receive filter control register */
1648 #define FCN_RX_FILTER_CTL_REG_KER 0x810
1649 #define FCN_NUM_KER_LBN 24
1650 #define FCN_NUM_KER_WIDTH 2
1652 /* Receive descriptor update register */
1653 #define FCN_RX_DESC_UPD_REG_KER 0x0830
1654 #define FCN_RX_DESC_WPTR_LBN 96
1655 #define FCN_RX_DESC_WPTR_WIDTH 12
1656 #define FCN_RX_DESC_UPD_REG_KER_DWORD ( FCN_RX_DESC_UPD_REG_KER + 12 )
1657 #define FCN_RX_DESC_WPTR_DWORD_LBN 0
1658 #define FCN_RX_DESC_WPTR_DWORD_WIDTH 12
1660 /* Receive descriptor cache configuration register */
1661 #define FCN_RX_DC_CFG_REG_KER 0x840
1662 #define FCN_RX_DC_SIZE_LBN 0
1663 #define FCN_RX_DC_SIZE_WIDTH 2
1665 /* Transmit descriptor update register */
1666 #define FCN_TX_DESC_UPD_REG_KER 0x0a10
1667 #define FCN_TX_DESC_WPTR_LBN 96
1668 #define FCN_TX_DESC_WPTR_WIDTH 12
1669 #define FCN_TX_DESC_UPD_REG_KER_DWORD ( FCN_TX_DESC_UPD_REG_KER + 12 )
1670 #define FCN_TX_DESC_WPTR_DWORD_LBN 0
1671 #define FCN_TX_DESC_WPTR_DWORD_WIDTH 12
1673 /* Transmit descriptor cache configuration register */
1674 #define FCN_TX_DC_CFG_REG_KER 0xa20
1675 #define FCN_TX_DC_SIZE_LBN 0
1676 #define FCN_TX_DC_SIZE_WIDTH 2
1678 /* PHY management transmit data register */
1679 #define FCN_MD_TXD_REG_KER 0xc00
1680 #define FCN_MD_TXD_LBN 0
1681 #define FCN_MD_TXD_WIDTH 16
1683 /* PHY management receive data register */
1684 #define FCN_MD_RXD_REG_KER 0xc10
1685 #define FCN_MD_RXD_LBN 0
1686 #define FCN_MD_RXD_WIDTH 16
1688 /* PHY management configuration & status register */
1689 #define FCN_MD_CS_REG_KER 0xc20
1690 #define FCN_MD_GC_LBN 4
1691 #define FCN_MD_GC_WIDTH 1
1692 #define FCN_MD_RIC_LBN 2
1693 #define FCN_MD_RIC_WIDTH 1
1694 #define FCN_MD_WRC_LBN 0
1695 #define FCN_MD_WRC_WIDTH 1
1697 /* PHY management PHY address register */
1698 #define FCN_MD_PHY_ADR_REG_KER 0xc30
1699 #define FCN_MD_PHY_ADR_LBN 0
1700 #define FCN_MD_PHY_ADR_WIDTH 16
1702 /* PHY management ID register */
1703 #define FCN_MD_ID_REG_KER 0xc40
1704 #define FCN_MD_PRT_ADR_LBN 11
1705 #define FCN_MD_PRT_ADR_WIDTH 5
1706 #define FCN_MD_DEV_ADR_LBN 6
1707 #define FCN_MD_DEV_ADR_WIDTH 5
1709 /* PHY management status & mask register */
1710 #define FCN_MD_STAT_REG_KER 0xc50
1711 #define FCN_MD_BSY_LBN 0
1712 #define FCN_MD_BSY_WIDTH 1
1714 /* Port 0 and 1 MAC control registers */
1715 #define FCN_MAC0_CTRL_REG_KER 0xc80
1716 #define FCN_MAC1_CTRL_REG_KER 0xc90
1717 #define FCN_MAC_XOFF_VAL_LBN 16
1718 #define FCN_MAC_XOFF_VAL_WIDTH 16
1719 #define FCN_MAC_BCAD_ACPT_LBN 4
1720 #define FCN_MAC_BCAD_ACPT_WIDTH 1
1721 #define FCN_MAC_UC_PROM_LBN 3
1722 #define FCN_MAC_UC_PROM_WIDTH 1
1723 #define FCN_MAC_LINK_STATUS_LBN 2
1724 #define FCN_MAC_LINK_STATUS_WIDTH 1
1725 #define FCN_MAC_SPEED_LBN 0
1726 #define FCN_MAC_SPEED_WIDTH 2
1728 /* GMAC registers */
1729 #define FALCON_GMAC_REGBANK 0xe00
1730 #define FALCON_GMAC_REGBANK_SIZE 0x200
1731 #define FALCON_GMAC_REG_SIZE 0x10
1733 /* XGMAC registers */
1734 #define FALCON_XMAC_REGBANK 0x1200
1735 #define FALCON_XMAC_REGBANK_SIZE 0x200
1736 #define FALCON_XMAC_REG_SIZE 0x10
1738 /* XGMAC address register low */
1739 #define FCN_XM_ADR_LO_REG_MAC 0x00
1740 #define FCN_XM_ADR_3_LBN 24
1741 #define FCN_XM_ADR_3_WIDTH 8
1742 #define FCN_XM_ADR_2_LBN 16
1743 #define FCN_XM_ADR_2_WIDTH 8
1744 #define FCN_XM_ADR_1_LBN 8
1745 #define FCN_XM_ADR_1_WIDTH 8
1746 #define FCN_XM_ADR_0_LBN 0
1747 #define FCN_XM_ADR_0_WIDTH 8
1749 /* XGMAC address register high */
1750 #define FCN_XM_ADR_HI_REG_MAC 0x01
1751 #define FCN_XM_ADR_5_LBN 8
1752 #define FCN_XM_ADR_5_WIDTH 8
1753 #define FCN_XM_ADR_4_LBN 0
1754 #define FCN_XM_ADR_4_WIDTH 8
1756 /* XGMAC global configuration - port 0*/
1757 #define FCN_XM_GLB_CFG_REG_MAC 0x02
1758 #define FCN_XM_RX_STAT_EN_LBN 11
1759 #define FCN_XM_RX_STAT_EN_WIDTH 1
1760 #define FCN_XM_TX_STAT_EN_LBN 10
1761 #define FCN_XM_TX_STAT_EN_WIDTH 1
1762 #define FCN_XM_RX_JUMBO_MODE_LBN 6
1763 #define FCN_XM_RX_JUMBO_MODE_WIDTH 1
1764 #define FCN_XM_CORE_RST_LBN 0
1765 #define FCN_XM_CORE_RST_WIDTH 1
1767 /* XGMAC transmit configuration - port 0 */
1768 #define FCN_XM_TX_CFG_REG_MAC 0x03
1769 #define FCN_XM_IPG_LBN 16
1770 #define FCN_XM_IPG_WIDTH 4
1771 #define FCN_XM_FCNTL_LBN 10
1772 #define FCN_XM_FCNTL_WIDTH 1
1773 #define FCN_XM_TXCRC_LBN 8
1774 #define FCN_XM_TXCRC_WIDTH 1
1775 #define FCN_XM_AUTO_PAD_LBN 5
1776 #define FCN_XM_AUTO_PAD_WIDTH 1
1777 #define FCN_XM_TX_PRMBL_LBN 2
1778 #define FCN_XM_TX_PRMBL_WIDTH 1
1779 #define FCN_XM_TXEN_LBN 1
1780 #define FCN_XM_TXEN_WIDTH 1
1782 /* XGMAC receive configuration - port 0 */
1783 #define FCN_XM_RX_CFG_REG_MAC 0x04
1784 #define FCN_XM_PASS_CRC_ERR_LBN 25
1785 #define FCN_XM_PASS_CRC_ERR_WIDTH 1
1786 #define FCN_XM_AUTO_DEPAD_LBN 8
1787 #define FCN_XM_AUTO_DEPAD_WIDTH 1
1788 #define FCN_XM_RXEN_LBN 1
1789 #define FCN_XM_RXEN_WIDTH 1
1791 /* XGMAC transmit parameter register */
1792 #define FCN_XM_TX_PARAM_REG_MAC 0x0d
1793 #define FCN_XM_TX_JUMBO_MODE_LBN 31
1794 #define FCN_XM_TX_JUMBO_MODE_WIDTH 1
1795 #define FCN_XM_MAX_TX_FRM_SIZE_LBN 16
1796 #define FCN_XM_MAX_TX_FRM_SIZE_WIDTH 14
1798 /* XGMAC receive parameter register */
1799 #define FCN_XM_RX_PARAM_REG_MAC 0x0e
1800 #define FCN_XM_MAX_RX_FRM_SIZE_LBN 0
1801 #define FCN_XM_MAX_RX_FRM_SIZE_WIDTH 14
1803 /* XAUI XGXS core status register */
1804 #define FCN_XX_ALIGN_DONE_LBN 20
1805 #define FCN_XX_ALIGN_DONE_WIDTH 1
1806 #define FCN_XX_CORE_STAT_REG_MAC 0x16
1807 #define FCN_XX_SYNC_STAT_LBN 16
1808 #define FCN_XX_SYNC_STAT_WIDTH 4
1809 #define FCN_XX_SYNC_STAT_DECODE_SYNCED 0xf
1810 #define FCN_XX_COMMA_DET_LBN 12
1811 #define FCN_XX_COMMA_DET_WIDTH 4
1812 #define FCN_XX_COMMA_DET_RESET 0xf
1815 /* XGXS/XAUI powerdown/reset register */
1816 #define FCN_XX_PWR_RST_REG_MAC 0x10
1817 #define FCN_XX_RSTXGXSRX_EN_LBN 2
1818 #define FCN_XX_RSTXGXSRX_EN_WIDTH 1
1819 #define FCN_XX_RSTXGXSTX_EN_LBN 1
1820 #define FCN_XX_RSTXGXSTX_EN_WIDTH 1
1821 #define FCN_XX_RST_XX_EN_LBN 0
1822 #define FCN_XX_RST_XX_EN_WIDTH 1
1824 /* Receive descriptor pointer table */
1825 #define FCN_RX_DESC_PTR_TBL_KER 0x11800
1826 #define FCN_RX_DESCQ_BUF_BASE_ID_LBN 36
1827 #define FCN_RX_DESCQ_BUF_BASE_ID_WIDTH 20
1828 #define FCN_RX_DESCQ_EVQ_ID_LBN 24
1829 #define FCN_RX_DESCQ_EVQ_ID_WIDTH 12
1830 #define FCN_RX_DESCQ_OWNER_ID_LBN 10
1831 #define FCN_RX_DESCQ_OWNER_ID_WIDTH 14
1832 #define FCN_RX_DESCQ_SIZE_LBN 3
1833 #define FCN_RX_DESCQ_SIZE_WIDTH 2
1834 #define FCN_RX_DESCQ_SIZE_4K 3
1835 #define FCN_RX_DESCQ_SIZE_2K 2
1836 #define FCN_RX_DESCQ_SIZE_1K 1
1837 #define FCN_RX_DESCQ_SIZE_512 0
1838 #define FCN_RX_DESCQ_TYPE_LBN 2
1839 #define FCN_RX_DESCQ_TYPE_WIDTH 1
1840 #define FCN_RX_DESCQ_JUMBO_LBN 1
1841 #define FCN_RX_DESCQ_JUMBO_WIDTH 1
1842 #define FCN_RX_DESCQ_EN_LBN 0
1843 #define FCN_RX_DESCQ_EN_WIDTH 1
1845 /* Transmit descriptor pointer table */
1846 #define FCN_TX_DESC_PTR_TBL_KER 0x11900
1847 #define FCN_TX_DESCQ_EN_LBN 88
1848 #define FCN_TX_DESCQ_EN_WIDTH 1
1849 #define FCN_TX_DESCQ_BUF_BASE_ID_LBN 36
1850 #define FCN_TX_DESCQ_BUF_BASE_ID_WIDTH 20
1851 #define FCN_TX_DESCQ_EVQ_ID_LBN 24
1852 #define FCN_TX_DESCQ_EVQ_ID_WIDTH 12
1853 #define FCN_TX_DESCQ_OWNER_ID_LBN 10
1854 #define FCN_TX_DESCQ_OWNER_ID_WIDTH 14
1855 #define FCN_TX_DESCQ_SIZE_LBN 3
1856 #define FCN_TX_DESCQ_SIZE_WIDTH 2
1857 #define FCN_TX_DESCQ_SIZE_4K 3
1858 #define FCN_TX_DESCQ_SIZE_2K 2
1859 #define FCN_TX_DESCQ_SIZE_1K 1
1860 #define FCN_TX_DESCQ_SIZE_512 0
1861 #define FCN_TX_DESCQ_TYPE_LBN 1
1862 #define FCN_TX_DESCQ_TYPE_WIDTH 2
1863 #define FCN_TX_DESCQ_FLUSH_LBN 0
1864 #define FCN_TX_DESCQ_FLUSH_WIDTH 1
1866 /* Event queue pointer */
1867 #define FCN_EVQ_PTR_TBL_KER 0x11a00
1868 #define FCN_EVQ_EN_LBN 23
1869 #define FCN_EVQ_EN_WIDTH 1
1870 #define FCN_EVQ_SIZE_LBN 20
1871 #define FCN_EVQ_SIZE_WIDTH 3
1872 #define FCN_EVQ_SIZE_32K 6
1873 #define FCN_EVQ_SIZE_16K 5
1874 #define FCN_EVQ_SIZE_8K 4
1875 #define FCN_EVQ_SIZE_4K 3
1876 #define FCN_EVQ_SIZE_2K 2
1877 #define FCN_EVQ_SIZE_1K 1
1878 #define FCN_EVQ_SIZE_512 0
1879 #define FCN_EVQ_BUF_BASE_ID_LBN 0
1880 #define FCN_EVQ_BUF_BASE_ID_WIDTH 20
1882 /* Event queue read pointer */
1883 #define FCN_EVQ_RPTR_REG_KER 0x11b00
1884 #define FCN_EVQ_RPTR_LBN 0
1885 #define FCN_EVQ_RPTR_WIDTH 14
1886 #define FCN_EVQ_RPTR_REG_KER_DWORD ( FCN_EVQ_RPTR_REG_KER + 0 )
1887 #define FCN_EVQ_RPTR_DWORD_LBN 0
1888 #define FCN_EVQ_RPTR_DWORD_WIDTH 14
1890 /* Special buffer descriptors */
1891 #define FCN_BUF_FULL_TBL_KER 0x18000
1892 #define FCN_IP_DAT_BUF_SIZE_LBN 50
1893 #define FCN_IP_DAT_BUF_SIZE_WIDTH 1
1894 #define FCN_IP_DAT_BUF_SIZE_8K 1
1895 #define FCN_IP_DAT_BUF_SIZE_4K 0
1896 #define FCN_BUF_ADR_FBUF_LBN 14
1897 #define FCN_BUF_ADR_FBUF_WIDTH 34
1898 #define FCN_BUF_OWNER_ID_FBUF_LBN 0
1899 #define FCN_BUF_OWNER_ID_FBUF_WIDTH 14
1901 /** Offset of a GMAC register within Falcon */
1902 #define FALCON_GMAC_REG( efab, mac_reg ) \
1903 ( FALCON_GMAC_REGBANK + \
1904 ( (efab)->port * FALCON_GMAC_REGBANK_SIZE ) + \
1905 ( (mac_reg) * FALCON_GMAC_REG_SIZE ) )
1907 /** Offset of an XMAC register within Falcon */
1908 #define FALCON_XMAC_REG( efab_port, mac_reg ) \
1909 ( FALCON_XMAC_REGBANK + \
1910 ( (efab_port)->port * FALCON_XMAC_REGBANK_SIZE ) + \
1911 ( (mac_reg) * FALCON_XMAC_REG_SIZE ) )
1913 #define FCN_MAC_DATA_LBN 0
1914 #define FCN_MAC_DATA_WIDTH 32
1916 /* Transmit descriptor */
1917 #define FCN_TX_KER_PORT_LBN 63
1918 #define FCN_TX_KER_PORT_WIDTH 1
1919 #define FCN_TX_KER_BYTE_CNT_LBN 48
1920 #define FCN_TX_KER_BYTE_CNT_WIDTH 14
1921 #define FCN_TX_KER_BUF_ADR_LBN 0
1922 #define FCN_TX_KER_BUF_ADR_WIDTH EFAB_DMA_TYPE_WIDTH ( 46 )
1925 /* Receive descriptor */
1926 #define FCN_RX_KER_BUF_SIZE_LBN 48
1927 #define FCN_RX_KER_BUF_SIZE_WIDTH 14
1928 #define FCN_RX_KER_BUF_ADR_LBN 0
1929 #define FCN_RX_KER_BUF_ADR_WIDTH EFAB_DMA_TYPE_WIDTH ( 46 )
1931 /* Event queue entries */
1932 #define FCN_EV_CODE_LBN 60
1933 #define FCN_EV_CODE_WIDTH 4
1934 #define FCN_RX_IP_EV_DECODE 0
1935 #define FCN_TX_IP_EV_DECODE 2
1936 #define FCN_DRIVER_EV_DECODE 5
1938 /* Receive events */
1939 #define FCN_RX_EV_PKT_OK_LBN 56
1940 #define FCN_RX_EV_PKT_OK_WIDTH 1
1941 #define FCN_RX_PORT_LBN 30
1942 #define FCN_RX_PORT_WIDTH 1
1943 #define FCN_RX_EV_BYTE_CNT_LBN 16
1944 #define FCN_RX_EV_BYTE_CNT_WIDTH 14
1945 #define FCN_RX_EV_DESC_PTR_LBN 0
1946 #define FCN_RX_EV_DESC_PTR_WIDTH 12
1948 /* Transmit events */
1949 #define FCN_TX_EV_DESC_PTR_LBN 0
1950 #define FCN_TX_EV_DESC_PTR_WIDTH 12
1952 /* Fixed special buffer numbers to use */
1953 #define FALCON_EVQ_ID 0
1954 #define FALCON_TXD_ID 1
1955 #define FALCON_RXD_ID 2
1957 #if FALCON_USE_IO_BAR
1959 /* Write dword via the I/O BAR */
1960 static inline void _falcon_writel ( struct efab_nic *efab, uint32_t value,
1961 unsigned int reg ) {
1962 outl ( reg, efab->iobase + FCN_IOM_IND_ADR_REG );
1963 outl ( value, efab->iobase + FCN_IOM_IND_DAT_REG );
1966 /* Read dword via the I/O BAR */
1967 static inline uint32_t _falcon_readl ( struct efab_nic *efab,
1968 unsigned int reg ) {
1969 outl ( reg, efab->iobase + FCN_IOM_IND_ADR_REG );
1970 return inl ( efab->iobase + FCN_IOM_IND_DAT_REG );
1973 #else /* FALCON_USE_IO_BAR */
1975 #define _falcon_writel( efab, value, reg ) \
1976 writel ( (value), (efab)->membase + (reg) )
1977 #define _falcon_readl( efab, reg ) readl ( (efab)->membase + (reg) )
1979 #endif /* FALCON_USE_IO_BAR */
1982 * Write to a Falcon register
1985 static inline void falcon_write ( struct efab_nic *efab, efab_oword_t *value,
1986 unsigned int reg ) {
1988 EFAB_REGDUMP ( "Writing register %x with " EFAB_OWORD_FMT "\n",
1989 reg, EFAB_OWORD_VAL ( *value ) );
1991 _falcon_writel ( efab, value->u32[0], reg + 0 );
1992 _falcon_writel ( efab, value->u32[1], reg + 4 );
1993 _falcon_writel ( efab, value->u32[2], reg + 8 );
1994 _falcon_writel ( efab, value->u32[3], reg + 12 );
1999 * Write to Falcon SRAM
2002 static inline void falcon_write_sram ( struct efab_nic *efab,
2003 efab_qword_t *value,
2004 unsigned int index ) {
2005 unsigned int reg = ( FCN_BUF_FULL_TBL_KER +
2006 ( index * sizeof ( *value ) ) );
2008 EFAB_REGDUMP ( "Writing SRAM register %x with " EFAB_QWORD_FMT "\n",
2009 reg, EFAB_QWORD_VAL ( *value ) );
2011 _falcon_writel ( efab, value->u32[0], reg + 0 );
2012 _falcon_writel ( efab, value->u32[1], reg + 4 );
2017 * Write dword to Falcon register that allows partial writes
2020 static inline void falcon_writel ( struct efab_nic *efab, efab_dword_t *value,
2021 unsigned int reg ) {
2022 EFAB_REGDUMP ( "Writing partial register %x with " EFAB_DWORD_FMT "\n",
2023 reg, EFAB_DWORD_VAL ( *value ) );
2024 _falcon_writel ( efab, value->u32[0], reg );
2028 * Read from a Falcon register
2031 static inline void falcon_read ( struct efab_nic *efab, efab_oword_t *value,
2032 unsigned int reg ) {
2033 value->u32[0] = _falcon_readl ( efab, reg + 0 );
2034 value->u32[1] = _falcon_readl ( efab, reg + 4 );
2035 value->u32[2] = _falcon_readl ( efab, reg + 8 );
2036 value->u32[3] = _falcon_readl ( efab, reg + 12 );
2038 EFAB_REGDUMP ( "Read from register %x, got " EFAB_OWORD_FMT "\n",
2039 reg, EFAB_OWORD_VAL ( *value ) );
2043 * Read from Falcon SRAM
2046 static inline void falcon_read_sram ( struct efab_nic *efab,
2047 efab_qword_t *value,
2048 unsigned int index ) {
2049 unsigned int reg = ( FCN_BUF_FULL_TBL_KER +
2050 ( index * sizeof ( *value ) ) );
2052 value->u32[0] = _falcon_readl ( efab, reg + 0 );
2053 value->u32[1] = _falcon_readl ( efab, reg + 4 );
2054 EFAB_REGDUMP ( "Read from SRAM register %x, got " EFAB_QWORD_FMT "\n",
2055 reg, EFAB_QWORD_VAL ( *value ) );
2059 * Read dword from a portion of a Falcon register
2062 static inline void falcon_readl ( struct efab_nic *efab, efab_dword_t *value,
2063 unsigned int reg ) {
2064 value->u32[0] = _falcon_readl ( efab, reg );
2065 EFAB_REGDUMP ( "Read from register %x, got " EFAB_DWORD_FMT "\n",
2066 reg, EFAB_DWORD_VAL ( *value ) );
2070 * Verified write to Falcon SRAM
2073 static inline void falcon_write_sram_verify ( struct efab_nic *efab,
2074 efab_qword_t *value,
2075 unsigned int index ) {
2076 efab_qword_t verify;
2078 falcon_write_sram ( efab, value, index );
2080 falcon_read_sram ( efab, &verify, index );
2081 if ( memcmp ( &verify, value, sizeof ( verify ) ) != 0 ) {
2082 EFAB_ERR ( "SRAM index %x failure: wrote " EFAB_QWORD_FMT
2083 " got " EFAB_QWORD_FMT "\n", index,
2084 EFAB_QWORD_VAL ( *value ),
2085 EFAB_QWORD_VAL ( verify ) );
2093 static void falcon_get_membase ( struct efab_nic *efab ) {
2094 unsigned long membase_phys;
2096 membase_phys = pci_bar_start ( efab->pci, PCI_BASE_ADDRESS_2 );
2097 efab->membase = ioremap ( membase_phys, 0x20000 );
2100 #define FCN_DUMP_REG( efab, _reg ) do { \
2102 falcon_read ( efab, ®, _reg ); \
2103 EFAB_LOG ( #_reg " = " EFAB_OWORD_FMT "\n", \
2104 EFAB_OWORD_VAL ( reg ) ); \
2107 #define FCN_DUMP_MAC_REG( efab, _mac_reg ) do { \
2109 efab->mac_op->mac_readl ( efab, ®, _mac_reg ); \
2110 EFAB_LOG ( #_mac_reg " = " EFAB_DWORD_FMT "\n", \
2111 EFAB_DWORD_VAL ( reg ) ); \
2115 * Dump register contents (for debugging)
2117 * Marked as static inline so that it will not be compiled in if not
2120 static inline void falcon_dump_regs ( struct efab_nic *efab ) {
2121 FCN_DUMP_REG ( efab, FCN_INT_EN_REG_KER );
2122 FCN_DUMP_REG ( efab, FCN_INT_ADR_REG_KER );
2123 FCN_DUMP_REG ( efab, FCN_GLB_CTL_REG_KER );
2124 FCN_DUMP_REG ( efab, FCN_TIMER_CMD_REG_KER );
2125 FCN_DUMP_REG ( efab, FCN_SRM_RX_DC_CFG_REG_KER );
2126 FCN_DUMP_REG ( efab, FCN_SRM_TX_DC_CFG_REG_KER );
2127 FCN_DUMP_REG ( efab, FCN_RX_FILTER_CTL_REG_KER );
2128 FCN_DUMP_REG ( efab, FCN_RX_DC_CFG_REG_KER );
2129 FCN_DUMP_REG ( efab, FCN_TX_DC_CFG_REG_KER );
2130 FCN_DUMP_REG ( efab, FCN_MAC0_CTRL_REG_KER );
2131 FCN_DUMP_REG ( efab, FCN_MAC1_CTRL_REG_KER );
2132 FCN_DUMP_REG ( efab, FCN_RX_DESC_PTR_TBL_KER );
2133 FCN_DUMP_REG ( efab, FCN_TX_DESC_PTR_TBL_KER );
2134 FCN_DUMP_REG ( efab, FCN_EVQ_PTR_TBL_KER );
2135 FCN_DUMP_MAC_REG ( efab, GM_CFG1_REG_MAC );
2136 FCN_DUMP_MAC_REG ( efab, GM_CFG2_REG_MAC );
2137 FCN_DUMP_MAC_REG ( efab, GM_MAX_FLEN_REG_MAC );
2138 FCN_DUMP_MAC_REG ( efab, GM_MII_MGMT_CFG_REG_MAC );
2139 FCN_DUMP_MAC_REG ( efab, GM_ADR1_REG_MAC );
2140 FCN_DUMP_MAC_REG ( efab, GM_ADR2_REG_MAC );
2141 FCN_DUMP_MAC_REG ( efab, GMF_CFG0_REG_MAC );
2142 FCN_DUMP_MAC_REG ( efab, GMF_CFG1_REG_MAC );
2143 FCN_DUMP_MAC_REG ( efab, GMF_CFG2_REG_MAC );
2144 FCN_DUMP_MAC_REG ( efab, GMF_CFG3_REG_MAC );
2145 FCN_DUMP_MAC_REG ( efab, GMF_CFG4_REG_MAC );
2146 FCN_DUMP_MAC_REG ( efab, GMF_CFG5_REG_MAC );
2150 * Create special buffer
2153 static void falcon_create_special_buffer ( struct efab_nic *efab,
2154 void *addr, unsigned int index ) {
2155 efab_qword_t buf_desc;
2156 unsigned long dma_addr;
2158 memset ( addr, 0, 4096 );
2159 dma_addr = virt_to_bus ( addr );
2160 EFAB_ASSERT ( ( dma_addr & ( EFAB_BUF_ALIGN - 1 ) ) == 0 );
2161 EFAB_POPULATE_QWORD_3 ( buf_desc,
2162 FCN_IP_DAT_BUF_SIZE, FCN_IP_DAT_BUF_SIZE_4K,
2163 FCN_BUF_ADR_FBUF, ( dma_addr >> 12 ),
2164 FCN_BUF_OWNER_ID_FBUF, 0 );
2165 falcon_write_sram_verify ( efab, &buf_desc, index );
2169 * Update event queue read pointer
2172 static void falcon_eventq_read_ack ( struct efab_nic *efab ) {
2175 EFAB_ASSERT ( efab->eventq_read_ptr < EFAB_EVQ_SIZE );
2177 EFAB_POPULATE_DWORD_1 ( reg, FCN_EVQ_RPTR_DWORD,
2178 efab->eventq_read_ptr );
2179 falcon_writel ( efab, ®, FCN_EVQ_RPTR_REG_KER_DWORD );
2186 static int falcon_reset ( struct efab_nic *efab ) {
2187 efab_oword_t glb_ctl_reg_ker;
2189 /* Initiate software reset */
2190 EFAB_POPULATE_OWORD_7 ( glb_ctl_reg_ker,
2191 PCIE_CORE_RST_CTL, EXCLUDE_FROM_RESET,
2192 PCIE_NSTCK_RST_CTL, EXCLUDE_FROM_RESET,
2193 PCIE_SD_RST_CTL, EXCLUDE_FROM_RESET,
2194 EE_RST_CTL, EXCLUDE_FROM_RESET,
2195 PCIX_RST_CTL, EXCLUDE_FROM_RESET,
2196 EXT_PHY_RST_DUR, 0x7 /* datasheet recommended */,
2199 falcon_write ( efab, &glb_ctl_reg_ker, FCN_GLB_CTL_REG_KER );
2201 /* Allow 20ms for reset */
2204 /* Check for device reset complete */
2205 falcon_read ( efab, &glb_ctl_reg_ker, FCN_GLB_CTL_REG_KER );
2206 if ( EFAB_OWORD_FIELD ( glb_ctl_reg_ker, SWRST ) != 0 ) {
2207 EFAB_ERR ( "Reset failed\n" );
2215 * Wait for SPI command completion
2218 static int falcon_spi_wait ( struct efab_nic *efab ) {
2225 falcon_read ( efab, ®, FCN_EE_SPI_HCMD_REG_KER );
2226 if ( EFAB_OWORD_FIELD ( reg, FCN_EE_SPI_HCMD_CMD_EN ) == 0 )
2228 } while ( ++count < 1000 );
2229 printf ( "Timed out waiting for SPI\n" );
2234 * Perform SPI read/write
2237 static int falcon_spi_rw ( struct spi_bus *bus, struct spi_device *device,
2238 unsigned int command, int address,
2239 const void *data_out, void *data_in, size_t len ) {
2240 struct efab_nic *efab = container_of ( bus, struct efab_nic, spi );
2243 /* Program address register */
2244 EFAB_POPULATE_OWORD_1 ( reg, FCN_EE_SPI_HADR_ADR, address );
2245 falcon_write ( efab, ®, FCN_EE_SPI_HADR_REG_KER );
2247 /* Program data register, if applicable */
2249 memcpy ( ®, data_out, len );
2250 falcon_write ( efab, ®, FCN_EE_SPI_HDATA_REG_KER );
2254 EFAB_POPULATE_OWORD_7 ( reg,
2255 FCN_EE_SPI_HCMD_CMD_EN, 1,
2256 FCN_EE_SPI_HCMD_SF_SEL, device->slave,
2257 FCN_EE_SPI_HCMD_DABCNT, len,
2258 FCN_EE_SPI_HCMD_READ, ( data_out ?
2259 FCN_EE_SPI_WRITE : FCN_EE_SPI_READ ),
2260 FCN_EE_SPI_HCMD_DUBCNT, 0,
2261 FCN_EE_SPI_HCMD_ADBCNT,
2262 ( device->address_len / 8 ),
2263 FCN_EE_SPI_HCMD_ENC, command );
2264 falcon_write ( efab, ®, FCN_EE_SPI_HCMD_REG_KER );
2266 /* Wait for operation to complete */
2267 if ( ! falcon_spi_wait ( efab ) )
2270 /* Read data, if applicable */
2272 falcon_read ( efab, ®, FCN_EE_SPI_HDATA_REG_KER );
2273 memcpy ( data_in, ®, len );
2280 * Initialise SPI bus and devices
2283 static void falcon_init_spi ( struct efab_nic *efab ) {
2284 /* Initialise SPI bus */
2285 efab->spi.rw = falcon_spi_rw;
2286 efab->falcon_eeprom.bus = &efab->spi;
2287 efab->falcon_eeprom.slave = FCN_EE_SPI_EEPROM;
2288 efab->falcon_flash.bus = &efab->spi;
2289 efab->falcon_flash.slave = FCN_EE_SPI_FLASH;
2291 /* Initialise EEPROM, if present */
2292 if ( efab->has_flash ) {
2293 init_at25f1024 ( &efab->falcon_flash );
2294 init_at25040 ( &efab->falcon_eeprom );
2296 init_mc25xx640 ( &efab->falcon_eeprom );
2297 /* Falcon's SPI interface cannot support a block size
2298 * larger than 16, so forcibly reduce it
2300 efab->falcon_eeprom.nvs.block_size = 16;
2304 /** Offset of MAC address within EEPROM or Flash */
2305 #define FALCON_MAC_ADDRESS_OFFSET(port) ( 0x310 + 0x08 * (port) )
2308 * Read MAC address from EEPROM
2311 static int falcon_read_eeprom ( struct efab_nic *efab ) {
2312 struct nvs_device *nvs;
2314 /* Determine the NVS device containing the MAC address */
2315 nvs = ( efab->has_flash ?
2316 &efab->falcon_flash.nvs : &efab->falcon_eeprom.nvs );
2318 return nvs_read ( nvs, FALCON_MAC_ADDRESS_OFFSET ( efab->port ),
2319 efab->mac_addr, sizeof ( efab->mac_addr ) );
2322 /** RX descriptor */
2323 typedef efab_qword_t falcon_rx_desc_t;
2326 * Build RX descriptor
2329 static void falcon_build_rx_desc ( struct efab_nic *efab,
2330 struct efab_rx_buf *rx_buf ) {
2331 falcon_rx_desc_t *rxd;
2333 rxd = ( ( falcon_rx_desc_t * ) efab->rxd ) + rx_buf->id;
2334 EFAB_POPULATE_QWORD_2 ( *rxd,
2335 FCN_RX_KER_BUF_SIZE, EFAB_DATA_BUF_SIZE,
2337 virt_to_bus ( rx_buf->addr ) );
2341 * Update RX descriptor write pointer
2344 static void falcon_notify_rx_desc ( struct efab_nic *efab ) {
2347 EFAB_POPULATE_DWORD_1 ( reg, FCN_RX_DESC_WPTR_DWORD,
2348 efab->rx_write_ptr );
2349 falcon_writel ( efab, ®, FCN_RX_DESC_UPD_REG_KER_DWORD );
2352 /** TX descriptor */
2353 typedef efab_qword_t falcon_tx_desc_t;
2356 * Build TX descriptor
2359 static void falcon_build_tx_desc ( struct efab_nic *efab,
2360 struct efab_tx_buf *tx_buf ) {
2361 falcon_rx_desc_t *txd;
2363 txd = ( ( falcon_rx_desc_t * ) efab->txd ) + tx_buf->id;
2364 EFAB_POPULATE_QWORD_3 ( *txd,
2365 FCN_TX_KER_PORT, efab->port,
2366 FCN_TX_KER_BYTE_CNT, tx_buf->len,
2368 virt_to_bus ( tx_buf->addr ) );
2372 * Update TX descriptor write pointer
2375 static void falcon_notify_tx_desc ( struct efab_nic *efab ) {
2378 EFAB_POPULATE_DWORD_1 ( reg, FCN_TX_DESC_WPTR_DWORD,
2379 efab->tx_write_ptr );
2380 falcon_writel ( efab, ®, FCN_TX_DESC_UPD_REG_KER_DWORD );
2384 typedef efab_qword_t falcon_event_t;
2387 * See if an event is present
2389 * @v event Falcon event structure
2390 * @ret True An event is pending
2391 * @ret False No event is pending
2393 * We check both the high and low dword of the event for all ones. We
2394 * wrote all ones when we cleared the event, and no valid event can
2395 * have all ones in either its high or low dwords. This approach is
2396 * robust against reordering.
2398 * Note that using a single 64-bit comparison is incorrect; even
2399 * though the CPU read will be atomic, the DMA write may not be.
2401 static inline int falcon_event_present ( falcon_event_t* event ) {
2402 return ( ! ( EFAB_DWORD_IS_ALL_ONES ( event->dword[0] ) |
2403 EFAB_DWORD_IS_ALL_ONES ( event->dword[1] ) ) );
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 ( !falcon_event_present ( evt ) ) {
2423 DBG ( "Event is " EFAB_QWORD_FMT "\n", EFAB_QWORD_VAL ( *evt ) );
2426 ev_code = EFAB_QWORD_FIELD ( *evt, FCN_EV_CODE );
2428 switch ( ev_code ) {
2429 case FCN_TX_IP_EV_DECODE:
2430 event->type = EFAB_EV_TX;
2432 case FCN_RX_IP_EV_DECODE:
2433 event->type = EFAB_EV_RX;
2434 event->rx_id = EFAB_QWORD_FIELD ( *evt, FCN_RX_EV_DESC_PTR );
2435 event->rx_len = EFAB_QWORD_FIELD ( *evt, FCN_RX_EV_BYTE_CNT );
2436 event->drop = !EFAB_QWORD_FIELD ( *evt, FCN_RX_EV_PKT_OK );
2437 rx_port = EFAB_QWORD_FIELD ( *evt, FCN_RX_PORT );
2438 if ( rx_port != efab->port ) {
2439 /* Ignore packets on the wrong port. We can't
2440 * just set event->type = EFAB_EV_NONE,
2441 * because then the descriptor ring won't get
2447 case FCN_DRIVER_EV_DECODE:
2448 /* Ignore start-of-day events */
2449 event->type = EFAB_EV_NONE;
2452 EFAB_ERR ( "Unknown event type %d data %08lx\n", ev_code,
2453 EFAB_DWORD_FIELD ( *evt, EFAB_DWORD_0 ) );
2454 event->type = EFAB_EV_NONE;
2457 /* Clear event and any pending interrupts */
2458 EFAB_SET_QWORD ( *evt );
2459 falcon_writel ( efab, 0, FCN_INT_ACK_KER_REG );
2462 /* Increment and update event queue read pointer */
2463 efab->eventq_read_ptr = ( ( efab->eventq_read_ptr + 1 )
2465 falcon_eventq_read_ack ( efab );
2471 * Enable/disable/generate interrupt
2474 static inline void falcon_interrupts ( struct efab_nic *efab, int enabled,
2476 efab_oword_t int_en_reg_ker;
2478 EFAB_POPULATE_OWORD_2 ( int_en_reg_ker,
2479 FCN_KER_INT_KER, force,
2480 FCN_DRV_INT_EN_KER, enabled );
2481 falcon_write ( efab, &int_en_reg_ker, FCN_INT_EN_REG_KER );
2485 * Enable/disable interrupts
2488 static void falcon_mask_irq ( struct efab_nic *efab, int enabled ) {
2489 falcon_interrupts ( efab, enabled, 0 );
2491 /* Events won't trigger interrupts until we do this */
2492 falcon_eventq_read_ack ( efab );
2497 * Generate interrupt
2500 static void falcon_generate_irq ( struct efab_nic *efab ) {
2501 falcon_interrupts ( efab, 1, 1 );
2506 * Reconfigure MAC wrapper
2509 static void falcon_reconfigure_mac_wrapper ( struct efab_nic *efab ) {
2513 if ( efab->link_options & LPA_10000 ) {
2515 } else if ( efab->link_options & LPA_1000 ) {
2517 } else if ( efab->link_options & LPA_100 ) {
2522 EFAB_POPULATE_OWORD_5 ( reg,
2523 FCN_MAC_XOFF_VAL, 0xffff /* datasheet */,
2524 FCN_MAC_BCAD_ACPT, 1,
2526 FCN_MAC_LINK_STATUS, 1,
2527 FCN_MAC_SPEED, link_speed );
2528 falcon_write ( efab, ®,
2530 FCN_MAC0_CTRL_REG_KER : FCN_MAC1_CTRL_REG_KER ) );
2532 /* Disable flow-control (i.e. never generate pause frames) */
2533 falcon_read ( efab, ®, FCN_RX_CFG_REG_KER );
2534 EFAB_SET_OWORD_FIELD ( reg, FCN_RX_XOFF_EN, 0 );
2535 falcon_write ( efab, ®, FCN_RX_CFG_REG_KER );
2539 * Write dword to a Falcon MAC register
2542 static void falcon_gmac_writel ( struct efab_nic *efab,
2543 efab_dword_t *value, unsigned int mac_reg ) {
2546 EFAB_POPULATE_OWORD_1 ( temp, FCN_MAC_DATA,
2547 EFAB_DWORD_FIELD ( *value, FCN_MAC_DATA ) );
2548 falcon_write ( efab, &temp, FALCON_GMAC_REG ( efab, mac_reg ) );
2552 * Read dword from a Falcon GMAC register
2555 static void falcon_gmac_readl ( struct efab_nic *efab, efab_dword_t *value,
2556 unsigned int mac_reg ) {
2559 falcon_read ( efab, &temp, FALCON_GMAC_REG ( efab, mac_reg ) );
2560 EFAB_POPULATE_DWORD_1 ( *value, FCN_MAC_DATA,
2561 EFAB_OWORD_FIELD ( temp, FCN_MAC_DATA ) );
2565 * Write dword to a Falcon XMAC register
2568 static void falcon_xmac_writel ( struct efab_nic *efab,
2569 efab_dword_t *value, unsigned int mac_reg ) {
2572 EFAB_POPULATE_OWORD_1 ( temp, FCN_MAC_DATA,
2573 EFAB_DWORD_FIELD ( *value, FCN_MAC_DATA ) );
2574 falcon_write ( efab, &temp,
2575 FALCON_XMAC_REG ( efab, mac_reg ) );
2579 * Read dword from a Falcon XMAC register
2582 static void falcon_xmac_readl ( struct efab_nic *efab,
2583 efab_dword_t *value,
2584 unsigned int mac_reg ) {
2587 falcon_read ( efab, &temp,
2588 FALCON_XMAC_REG ( efab, mac_reg ) );
2589 EFAB_POPULATE_DWORD_1 ( *value, FCN_MAC_DATA,
2590 EFAB_OWORD_FIELD ( temp, FCN_MAC_DATA ) );
2597 static int falcon_init_gmac ( struct efab_nic *efab ) {
2598 static struct efab_mentormac_parameters falcon_mentormac_params = {
2599 .gmf_cfgfrth = 0x12,
2600 .gmf_cfgftth = 0x08,
2601 .gmf_cfghwmft = 0x1c,
2606 /* Initialise PHY */
2607 alaska_init ( efab );
2609 /* check the link is up */
2610 if ( !efab->link_up )
2613 /* Initialise MAC */
2614 mentormac_init ( efab, &falcon_mentormac_params );
2616 /* reconfigure the MAC wrapper */
2617 falcon_reconfigure_mac_wrapper ( efab );
2626 static int falcon_reset_gmac ( struct efab_nic *efab ) {
2627 mentormac_reset ( efab );
2632 * Reset XAUI/XGXS block
2635 static int falcon_reset_xaui ( struct efab_nic *efab )
2640 EFAB_POPULATE_DWORD_1 ( reg, FCN_XX_RST_XX_EN, 1 );
2641 efab->mac_op->mac_writel ( efab, ®, FCN_XX_PWR_RST_REG_MAC );
2643 for ( count = 0 ; count < 1000 ; count++ ) {
2645 efab->mac_op->mac_readl ( efab, ®,
2646 FCN_XX_PWR_RST_REG_MAC );
2647 if ( EFAB_DWORD_FIELD ( reg, FCN_XX_RST_XX_EN ) == 0 )
2651 /* an error of some kind */
2656 * Reset 10G MAC connected to port
2659 static int falcon_reset_xmac ( struct efab_nic *efab ) {
2663 EFAB_POPULATE_DWORD_1 ( reg, FCN_XM_CORE_RST, 1 );
2664 efab->mac_op->mac_writel ( efab, ®, FCN_XM_GLB_CFG_REG_MAC );
2666 for ( count = 0 ; count < 1000 ; count++ ) {
2668 efab->mac_op->mac_readl ( efab, ®,
2669 FCN_XM_GLB_CFG_REG_MAC );
2670 if ( EFAB_DWORD_FIELD ( reg, FCN_XM_CORE_RST ) == 0 )
2677 * Get status of 10G link
2680 static int falcon_xaui_link_ok ( struct efab_nic *efab ) {
2686 /* Read link status */
2687 efab->mac_op->mac_readl ( efab, ®, FCN_XX_CORE_STAT_REG_MAC );
2688 align_done = EFAB_DWORD_FIELD ( reg, FCN_XX_ALIGN_DONE );
2689 sync_status = EFAB_DWORD_FIELD ( reg, FCN_XX_SYNC_STAT );
2690 if ( align_done && ( sync_status == FCN_XX_SYNC_STAT_DECODE_SYNCED ) ) {
2694 /* Clear link status ready for next read */
2695 EFAB_SET_DWORD_FIELD ( reg, FCN_XX_COMMA_DET, FCN_XX_COMMA_DET_RESET );
2696 efab->mac_op->mac_writel ( efab, ®, FCN_XX_CORE_STAT_REG_MAC );
2705 static int falcon_init_xmac ( struct efab_nic *efab ) {
2709 if ( !falcon_reset_xmac ( efab ) ) {
2710 EFAB_ERR ( "failed resetting XMAC\n" );
2713 if ( !falcon_reset_xaui ( efab ) ) {
2714 EFAB_ERR ( "failed resetting XAUI\n");
2718 /* CX4 is always 10000FD only */
2719 efab->link_options = LPA_10000FULL;
2722 EFAB_POPULATE_DWORD_3 ( reg,
2723 FCN_XM_RX_JUMBO_MODE, 1,
2724 FCN_XM_TX_STAT_EN, 1,
2725 FCN_XM_RX_STAT_EN, 1);
2726 efab->mac_op->mac_writel ( efab, ®, FCN_XM_GLB_CFG_REG_MAC );
2729 EFAB_POPULATE_DWORD_6 ( reg,
2736 efab->mac_op->mac_writel ( efab, ®, FCN_XM_TX_CFG_REG_MAC );
2739 EFAB_POPULATE_DWORD_3 ( reg,
2741 FCN_XM_AUTO_DEPAD, 1,
2742 FCN_XM_PASS_CRC_ERR, 1 );
2743 efab->mac_op->mac_writel ( efab, ®, FCN_XM_RX_CFG_REG_MAC );
2745 /* Set frame length */
2746 EFAB_POPULATE_DWORD_1 ( reg,
2747 FCN_XM_MAX_RX_FRM_SIZE, ETH_FRAME_LEN );
2748 efab->mac_op->mac_writel ( efab, ®, FCN_XM_RX_PARAM_REG_MAC );
2749 EFAB_POPULATE_DWORD_2 ( reg,
2750 FCN_XM_MAX_TX_FRM_SIZE, ETH_FRAME_LEN,
2751 FCN_XM_TX_JUMBO_MODE, 1 );
2752 efab->mac_op->mac_writel ( efab, ®, FCN_XM_TX_PARAM_REG_MAC );
2754 /* Set MAC address */
2755 EFAB_POPULATE_DWORD_4 ( reg,
2756 FCN_XM_ADR_0, efab->mac_addr[0],
2757 FCN_XM_ADR_1, efab->mac_addr[1],
2758 FCN_XM_ADR_2, efab->mac_addr[2],
2759 FCN_XM_ADR_3, efab->mac_addr[3] );
2760 efab->mac_op->mac_writel ( efab, ®, FCN_XM_ADR_LO_REG_MAC );
2761 EFAB_POPULATE_DWORD_2 ( reg,
2762 FCN_XM_ADR_4, efab->mac_addr[4],
2763 FCN_XM_ADR_5, efab->mac_addr[5] );
2764 efab->mac_op->mac_writel ( efab, ®, FCN_XM_ADR_HI_REG_MAC );
2766 /* Reconfigure MAC wrapper */
2767 falcon_reconfigure_mac_wrapper ( efab );
2770 * Try resetting XAUI on its own waiting for the link
2773 for(count=0; count<5; count++) {
2774 /* Check link status */
2775 efab->link_up = falcon_xaui_link_ok ( efab );
2776 if ( efab->link_up ) {
2778 * Print out a speed message since we don't have a PHY
2780 EFAB_LOG ( "%dMbps %s-duplex\n",
2781 ( efab->link_options & LPA_10000 ? 1000 :
2782 ( efab->link_options & LPA_1000 ? 1000 :
2783 ( efab->link_options & LPA_100 ? 100 : 10 ) ) ),
2784 ( efab->link_options & LPA_DUPLEX ? "full" : "half" ) );
2788 if ( !falcon_reset_xaui ( efab ) ) {
2789 EFAB_ERR ( "failed resetting xaui\n" );
2799 * Wait for GMII access to complete
2802 static int falcon_gmii_wait ( struct efab_nic *efab ) {
2803 efab_oword_t md_stat;
2806 for ( count = 0 ; count < 1000 ; count++ ) {
2808 falcon_read ( efab, &md_stat, FCN_MD_STAT_REG_KER );
2809 if ( EFAB_OWORD_FIELD ( md_stat, FCN_MD_BSY ) == 0 )
2812 EFAB_ERR ( "Timed out waiting for GMII\n" );
2817 static struct efab_mac_operations falcon_xmac_operations = {
2818 .mac_readl = falcon_xmac_readl,
2819 .mac_writel = falcon_xmac_writel,
2820 .init = falcon_init_xmac,
2821 .reset = falcon_reset_xmac,
2824 static struct efab_mac_operations falcon_gmac_operations = {
2825 .mac_readl = falcon_gmac_readl,
2826 .mac_writel = falcon_gmac_writel,
2827 .init = falcon_init_gmac,
2828 .reset = falcon_reset_gmac,
2836 static int falcon_init_nic ( struct efab_nic *efab ) {
2838 efab_dword_t timer_cmd;
2841 /* use card in internal SRAM mode */
2842 falcon_read ( efab, ®, FCN_NIC_STAT_REG );
2843 EFAB_SET_OWORD_FIELD ( reg, ONCHIP_SRAM, 1 );
2844 falcon_write ( efab, ®, FCN_NIC_STAT_REG );
2847 /* identify FPGA/ASIC, and strapping mode */
2848 falcon_read ( efab, ®, ALTERA_BUILD_REG_KER );
2849 version = EFAB_OWORD_FIELD ( reg, VER_ALL );
2850 efab->is_asic = version ? 0 : 1;
2852 if ( efab->is_asic ) {
2853 falcon_read ( efab, ®, FCN_NIC_STAT_REG );
2854 if ( EFAB_OWORD_FIELD ( reg, STRAP_10G ) ) {
2857 if ( EFAB_OWORD_FIELD ( reg, STRAP_DUAL_PORT ) ) {
2862 falcon_read ( efab, ®, ALTERA_BUILD_REG_KER );
2863 minor = EFAB_OWORD_FIELD ( reg, VER_MINOR );
2865 if ( minor == 0x14 ) {
2867 } else if ( minor == 0x13 ) {
2872 EFAB_LOG ( "NIC type: %s %dx%s\n",
2873 efab->is_asic ? "ASIC" : "FPGA",
2874 efab->is_dual ? 2 : 1,
2875 efab->is_10g ? "10G" : "1G" );
2877 /* patch in MAC operations */
2879 efab->mac_op = &falcon_xmac_operations;
2881 efab->mac_op = &falcon_gmac_operations;
2883 if ( !efab->is_dual && ( efab->port == 1 ) ) {
2884 /* device doesn't exist */
2888 /* determine EEPROM / FLASH */
2889 if ( efab->is_asic ) {
2890 falcon_read ( efab, ®, FCN_NIC_STAT_REG );
2891 efab->has_flash = EFAB_OWORD_FIELD ( reg, SF_PRST );
2892 efab->has_eeprom = EFAB_OWORD_FIELD ( reg, EE_PRST );
2894 falcon_read ( efab, ®, FCN_GPIO_CTL_REG_KER );
2895 efab->has_flash = EFAB_OWORD_FIELD ( reg, FCN_FLASH_PRESENT );
2896 efab->has_eeprom = EFAB_OWORD_FIELD ( reg, FCN_EEPROM_PRESENT);
2898 EFAB_LOG ( "flash is %s, EEPROM is %s\n",
2899 ( efab->has_flash ? "present" : "absent" ),
2900 ( efab->has_eeprom ? "present" : "absent" ) );
2901 falcon_init_spi ( efab );
2903 /* Set up TX and RX descriptor caches in SRAM */
2904 EFAB_POPULATE_OWORD_1 ( reg, FCN_SRM_TX_DC_BASE_ADR,
2905 0x130000 /* recommended in datasheet */ );
2906 falcon_write ( efab, ®, FCN_SRM_TX_DC_CFG_REG_KER );
2907 EFAB_POPULATE_OWORD_1 ( reg, FCN_TX_DC_SIZE, 2 /* 32 descriptors */ );
2908 falcon_write ( efab, ®, FCN_TX_DC_CFG_REG_KER );
2909 EFAB_POPULATE_OWORD_1 ( reg, FCN_SRM_RX_DC_BASE_ADR,
2910 0x100000 /* recommended in datasheet */ );
2911 falcon_write ( efab, ®, FCN_SRM_RX_DC_CFG_REG_KER );
2912 EFAB_POPULATE_OWORD_1 ( reg, FCN_RX_DC_SIZE, 2 /* 32 descriptors */ );
2913 falcon_write ( efab, ®, FCN_RX_DC_CFG_REG_KER );
2915 /* Set number of RSS CPUs */
2916 EFAB_POPULATE_OWORD_1 ( reg, FCN_NUM_KER, 0 );
2917 falcon_write ( efab, ®, FCN_RX_FILTER_CTL_REG_KER );
2921 mentormac_reset ( efab );
2923 /* Set up event queue */
2924 falcon_create_special_buffer ( efab, efab->eventq, FALCON_EVQ_ID );
2925 /* Fill eventq with all ones ( empty events ) */
2926 memset(efab->eventq, 0xff, 4096);
2927 /* push eventq to card */
2928 EFAB_POPULATE_OWORD_3 ( reg,
2930 FCN_EVQ_SIZE, FCN_EVQ_SIZE_512,
2931 FCN_EVQ_BUF_BASE_ID, FALCON_EVQ_ID );
2932 falcon_write ( efab, ®, FCN_EVQ_PTR_TBL_KER );
2935 /* Set timer register */
2936 EFAB_POPULATE_DWORD_2 ( timer_cmd,
2937 FCN_TIMER_MODE, FCN_TIMER_MODE_DIS,
2939 falcon_writel ( efab, &timer_cmd, FCN_TIMER_CMD_REG_KER );
2942 /* Initialise event queue read pointer */
2943 falcon_eventq_read_ack ( efab );
2945 /* Set up TX descriptor ring */
2946 falcon_create_special_buffer ( efab, efab->txd, FALCON_TXD_ID );
2947 EFAB_POPULATE_OWORD_5 ( reg,
2949 FCN_TX_DESCQ_BUF_BASE_ID, FALCON_TXD_ID,
2950 FCN_TX_DESCQ_EVQ_ID, 0,
2951 FCN_TX_DESCQ_SIZE, FCN_TX_DESCQ_SIZE_512,
2952 FCN_TX_DESCQ_TYPE, 0 /* kernel queue */ );
2953 falcon_write ( efab, ®, FCN_TX_DESC_PTR_TBL_KER );
2955 /* Set up RX descriptor ring */
2956 falcon_create_special_buffer ( efab, efab->rxd, FALCON_RXD_ID );
2957 EFAB_POPULATE_OWORD_6 ( reg,
2958 FCN_RX_DESCQ_BUF_BASE_ID, FALCON_RXD_ID,
2959 FCN_RX_DESCQ_EVQ_ID, 0,
2960 FCN_RX_DESCQ_SIZE, FCN_RX_DESCQ_SIZE_512,
2961 FCN_RX_DESCQ_TYPE, 0 /* kernel queue */,
2962 FCN_RX_DESCQ_JUMBO, 1,
2963 FCN_RX_DESCQ_EN, 1 );
2964 falcon_write ( efab, ®, FCN_RX_DESC_PTR_TBL_KER );
2966 /* Program INT_ADR_REG_KER */
2967 EFAB_POPULATE_OWORD_1 ( reg,
2969 virt_to_bus ( &efab->int_ker ) );
2970 falcon_write ( efab, ®, FCN_INT_ADR_REG_KER );
2973 /* Register non-volatile storage */
2974 if ( efab->has_eeprom ) {
2976 efab->nvs.op = &falcon_nvs_operations;
2977 efab->nvs.len = 0x100;
2978 if ( nvs_register ( &efab->nvs ) != 0 )
2987 static void falcon_mdio_write ( struct efab_nic *efab, int location,
2989 int phy_id = efab->port + 2;
2992 EFAB_TRACE ( "Writing GMII %d register %02x with %04x\n",
2993 phy_id, location, value );
2995 /* Check MII not currently being accessed */
2996 if ( ! falcon_gmii_wait ( efab ) )
2999 /* Write the address registers */
3000 EFAB_POPULATE_OWORD_1 ( reg, FCN_MD_PHY_ADR, 0 /* phy_id ? */ );
3001 falcon_write ( efab, ®, FCN_MD_PHY_ADR_REG_KER );
3003 EFAB_POPULATE_OWORD_2 ( reg,
3004 FCN_MD_PRT_ADR, phy_id,
3005 FCN_MD_DEV_ADR, location );
3006 falcon_write ( efab, ®, FCN_MD_ID_REG_KER );
3010 EFAB_POPULATE_OWORD_1 ( reg, FCN_MD_TXD, value );
3011 falcon_write ( efab, ®, FCN_MD_TXD_REG_KER );
3013 EFAB_POPULATE_OWORD_2 ( reg,
3016 falcon_write ( efab, ®, FCN_MD_CS_REG_KER );
3019 /* Wait for data to be written */
3020 falcon_gmii_wait ( efab );
3024 static int falcon_mdio_read ( struct efab_nic *efab, int location ) {
3025 int phy_id = efab->port + 2;
3029 /* Check MII not currently being accessed */
3030 if ( ! falcon_gmii_wait ( efab ) )
3033 /* Write the address registers */
3034 EFAB_POPULATE_OWORD_1 ( reg, FCN_MD_PHY_ADR, 0 /* phy_id ? */ );
3035 falcon_write ( efab, ®, FCN_MD_PHY_ADR_REG_KER );
3037 EFAB_POPULATE_OWORD_2 ( reg,
3038 FCN_MD_PRT_ADR, phy_id,
3039 FCN_MD_DEV_ADR, location );
3040 falcon_write ( efab, ®, FCN_MD_ID_REG_KER );
3043 /* Request data to be read */
3044 EFAB_POPULATE_OWORD_2 ( reg,
3047 falcon_write ( efab, ®, FCN_MD_CS_REG_KER );
3050 /* Wait for data to become available */
3051 falcon_gmii_wait ( efab );
3054 falcon_read ( efab, ®, FCN_MD_RXD_REG_KER );
3055 value = EFAB_OWORD_FIELD ( reg, FCN_MD_RXD );
3057 EFAB_TRACE ( "Read from GMII %d register %02x, got %04x\n",
3058 phy_id, location, value );
3063 static struct efab_operations falcon_operations = {
3064 .get_membase = falcon_get_membase,
3065 .reset = falcon_reset,
3066 .init_nic = falcon_init_nic,
3067 .read_eeprom = falcon_read_eeprom,
3068 .build_rx_desc = falcon_build_rx_desc,
3069 .notify_rx_desc = falcon_notify_rx_desc,
3070 .build_tx_desc = falcon_build_tx_desc,
3071 .notify_tx_desc = falcon_notify_tx_desc,
3072 .fetch_event = falcon_fetch_event,
3073 .mask_irq = falcon_mask_irq,
3074 .generate_irq = falcon_generate_irq,
3075 .mdio_write = falcon_mdio_write,
3076 .mdio_read = falcon_mdio_read,
3079 /**************************************************************************
3081 * Etherfabric abstraction layer
3083 **************************************************************************
3087 * Push RX buffer to RXD ring
3090 static inline void efab_push_rx_buffer ( struct efab_nic *efab,
3091 struct efab_rx_buf *rx_buf ) {
3092 /* Create RX descriptor */
3093 rx_buf->id = efab->rx_write_ptr;
3094 efab->op->build_rx_desc ( efab, rx_buf );
3096 /* Update RX write pointer */
3097 efab->rx_write_ptr = ( efab->rx_write_ptr + 1 ) % EFAB_RXD_SIZE;
3098 efab->op->notify_rx_desc ( efab );
3100 DBG ( "Added RX id %x\n", rx_buf->id );
3104 * Push TX buffer to TXD ring
3107 static inline void efab_push_tx_buffer ( struct efab_nic *efab,
3108 struct efab_tx_buf *tx_buf ) {
3109 /* Create TX descriptor */
3110 tx_buf->id = efab->tx_write_ptr;
3111 efab->op->build_tx_desc ( efab, tx_buf );
3113 /* Update TX write pointer */
3114 efab->tx_write_ptr = ( efab->tx_write_ptr + 1 ) % EFAB_TXD_SIZE;
3115 efab->op->notify_tx_desc ( efab );
3117 DBG ( "Added TX id %x\n", tx_buf->id );
3121 * Initialise MAC and wait for link up
3124 static int efab_init_mac ( struct efab_nic *efab ) {
3127 /* This can take several seconds */
3128 EFAB_LOG ( "Waiting for link.." );
3129 for ( count=0; count<5; count++ ) {
3132 if ( ! efab->mac_op->init ( efab ) ) {
3133 EFAB_ERR ( "Failed reinitialising MAC\n" );
3136 if ( efab->link_up ) {
3137 /* PHY init printed the message for us */
3140 EFAB_ERR( "link is down" );
3143 EFAB_ERR ( " timed initialising MAC\n " );
3152 static int efab_init_nic ( struct efab_nic *efab ) {
3155 /* Initialise NIC */
3156 if ( ! efab->op->init_nic ( efab ) )
3159 /* Push RX descriptors */
3160 for ( i = 0 ; i < EFAB_RX_BUFS ; i++ ) {
3161 efab_push_rx_buffer ( efab, &efab->rx_bufs[i] );
3164 /* Read MAC address from EEPROM */
3165 if ( ! efab->op->read_eeprom ( efab ) )
3167 efab->mac_addr[ETH_ALEN-1] += efab->port;
3169 /* Initialise MAC and wait for link up */
3170 if ( ! efab_init_mac ( efab ) )
3176 /**************************************************************************
3178 * Etherboot interface
3180 **************************************************************************
3183 /**************************************************************************
3184 POLL - Wait for a frame
3185 ***************************************************************************/
3186 static int etherfabric_poll ( struct nic *nic, int retrieve ) {
3187 struct efab_nic *efab = nic->priv_data;
3188 struct efab_event event;
3189 static struct efab_rx_buf *rx_buf = NULL;
3192 /* Process the event queue until we hit either a packet
3193 * received event or an empty event slot.
3195 while ( ( rx_buf == NULL ) &&
3196 efab->op->fetch_event ( efab, &event ) ) {
3198 if ( event.type == EFAB_EV_TX ) {
3199 /* TX completed - mark as done */
3200 DBG ( "TX id %x complete\n",
3202 } else if ( event.type == EFAB_EV_RX ) {
3203 /* RX - find corresponding buffer */
3204 for ( i = 0 ; i < EFAB_RX_BUFS ; i++ ) {
3205 if ( efab->rx_bufs[i].id == event.rx_id ) {
3206 rx_buf = &efab->rx_bufs[i];
3207 rx_buf->len = event.rx_len;
3208 DBG ( "RX id %x (len %x) received\n",
3209 rx_buf->id, rx_buf->len );
3214 EFAB_ERR ( "Invalid RX ID %x\n", event.rx_id );
3216 } else if ( event.type == EFAB_EV_NONE ) {
3217 DBG ( "Ignorable event\n" );
3219 DBG ( "Unknown event\n" );
3223 /* If there is no packet, return 0 */
3227 /* drop this event if necessary */
3229 DBG( "discarding RX event\n" );
3233 /* If we don't want to retrieve it just yet, return 1 */
3237 /* There seems to be a hardware race. The event can show up
3238 * on the event FIFO before the DMA has completed, so we
3239 * insert a tiny delay. If this proves unreliable, we should
3240 * switch to using event DMA rather than the event FIFO, since
3241 * event DMA ordering is guaranteed.
3245 /* Copy packet contents */
3246 nic->packetlen = rx_buf->len;
3247 memcpy ( nic->packet, rx_buf->addr, nic->packetlen );
3249 /* Give this buffer back to the NIC */
3250 efab_push_rx_buffer ( efab, rx_buf );
3252 /* Prepare to receive next packet */
3258 /**************************************************************************
3259 TRANSMIT - Transmit a frame
3260 ***************************************************************************/
3261 static void etherfabric_transmit ( struct nic *nic, const char *dest,
3262 unsigned int type, unsigned int size,
3263 const char *data ) {
3264 struct efab_nic *efab = nic->priv_data;
3265 unsigned int nstype = htons ( type );
3267 /* Fill TX buffer, pad to ETH_ZLEN */
3268 memcpy ( efab->tx_buf.addr, dest, ETH_ALEN );
3269 memcpy ( efab->tx_buf.addr + ETH_ALEN, nic->node_addr, ETH_ALEN );
3270 memcpy ( efab->tx_buf.addr + 2 * ETH_ALEN, &nstype, 2 );
3271 memcpy ( efab->tx_buf.addr + ETH_HLEN, data, size );
3273 while ( size < ETH_ZLEN ) {
3274 efab->tx_buf.addr[size++] = '\0';
3276 efab->tx_buf.len = size;
3278 /* Push TX descriptor */
3279 efab_push_tx_buffer ( efab, &efab->tx_buf );
3281 /* Allow enough time for the packet to be transmitted. This
3282 * is a temporary hack until we update to the new driver API.
3289 /**************************************************************************
3290 DISABLE - Turn off ethernet interface
3291 ***************************************************************************/
3292 static void etherfabric_disable ( struct nic *nic ) {
3293 struct efab_nic *efab = nic->priv_data;
3295 efab->op->reset ( efab );
3296 if ( efab->membase )
3297 iounmap ( efab->membase );
3300 /**************************************************************************
3301 IRQ - handle interrupts
3302 ***************************************************************************/
3303 static void etherfabric_irq ( struct nic *nic, irq_action_t action ) {
3304 struct efab_nic *efab = nic->priv_data;
3308 efab->op->mask_irq ( efab, 1 );
3311 efab->op->mask_irq ( efab, 0 );
3314 /* Force NIC to generate a receive interrupt */
3315 efab->op->generate_irq ( efab );
3322 static struct nic_operations etherfabric_operations = {
3323 .connect = dummy_connect,
3324 .poll = etherfabric_poll,
3325 .transmit = etherfabric_transmit,
3326 .irq = etherfabric_irq,
3329 /**************************************************************************
3330 PROBE - Look for an adapter, this routine's visible to the outside
3331 ***************************************************************************/
3332 static int etherfabric_probe ( struct nic *nic, struct pci_device *pci ) {
3333 static struct efab_nic efab;
3334 static int nic_port = 0;
3335 struct efab_buffers *buffers;
3338 /* Set up our private data structure */
3339 nic->priv_data = &efab;
3340 memset ( &efab, 0, sizeof ( efab ) );
3341 memset ( &efab_buffers, 0, sizeof ( efab_buffers ) );
3343 /* Hook in appropriate operations table. Do this early. */
3344 if ( pci->device == EF1002_DEVID ) {
3345 efab.op = &ef1002_operations;
3347 efab.op = &falcon_operations;
3350 /* Initialise efab data structure */
3352 buffers = ( ( struct efab_buffers * )
3353 ( ( ( void * ) &efab_buffers ) +
3354 ( - virt_to_bus ( &efab_buffers ) ) % EFAB_BUF_ALIGN ) );
3355 efab.eventq = buffers->eventq;
3356 efab.txd = buffers->txd;
3357 efab.rxd = buffers->rxd;
3358 efab.tx_buf.addr = buffers->tx_buf;
3359 for ( i = 0 ; i < EFAB_RX_BUFS ; i++ ) {
3360 efab.rx_bufs[i].addr = buffers->rx_buf[i];
3363 /* Enable the PCI device */
3364 adjust_pci_device ( pci );
3365 nic->ioaddr = pci->ioaddr & ~3;
3366 nic->irqno = pci->irq;
3368 /* Get iobase/membase */
3369 efab.iobase = nic->ioaddr;
3370 efab.op->get_membase ( &efab );
3372 /* Switch NIC ports (i.e. try different ports on each probe) */
3373 nic_port = 1 - nic_port;
3374 efab.port = nic_port;
3376 /* Initialise hardware */
3377 if ( ! efab_init_nic ( &efab ) )
3379 memcpy ( nic->node_addr, efab.mac_addr, ETH_ALEN );
3381 /* point to NIC specific routines */
3382 nic->nic_op = ðerfabric_operations;
3387 static struct pci_device_id etherfabric_nics[] = {
3388 PCI_ROM(0x1924, 0xC101, "ef1002", "EtherFabric EF1002"),
3389 PCI_ROM(0x1924, 0x0703, "falcon", "EtherFabric Falcon"),
3392 PCI_DRIVER ( etherfabric_driver, etherfabric_nics, PCI_NO_CLASS );
3394 DRIVER ( "EFAB", nic_driver, pci_driver, etherfabric_driver,
3395 etherfabric_probe, etherfabric_disable );