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>
28 #define dma_addr_t unsigned long
29 #include "etherfabric.h"
31 /**************************************************************************
33 * Constants and macros
35 **************************************************************************
38 #define EFAB_ASSERT(x) \
41 DBG ( "ASSERT(%s) failed at %s line %d [%s]\n", #x, \
42 __FILE__, __LINE__, __FUNCTION__ ); \
46 #define EFAB_TRACE(...) DBG ( __VA_ARGS__ )
48 #define EFAB_REGDUMP(...)
50 #define EFAB_LOG(...) printf ( __VA_ARGS__ )
51 #define EFAB_ERR(...) printf ( __VA_ARGS__ )
53 #define FALCON_USE_IO_BAR 1
56 * EtherFabric constants
61 #define EFAB_VENDID_LEVEL5 0x1924
62 #define FALCON_P_DEVID 0x0703 /* Temporary PCI ID */
63 #define EF1002_DEVID 0xC101
65 /**************************************************************************
69 **************************************************************************
73 * Buffers used for TX, RX and event queue
76 #define EFAB_BUF_ALIGN 4096
77 #define EFAB_DATA_BUF_SIZE 2048
78 #define EFAB_RX_BUFS 16
79 #define EFAB_RXD_SIZE 512
80 #define EFAB_TXD_SIZE 512
81 #define EFAB_EVQ_SIZE 512
86 uint8_t tx_buf[EFAB_DATA_BUF_SIZE];
87 uint8_t rx_buf[EFAB_RX_BUFS][EFAB_DATA_BUF_SIZE];
88 uint8_t padding[EFAB_BUF_ALIGN-1];
90 static struct efab_buffers efab_buffers;
106 /** Etherfabric event type */
107 enum efab_event_type {
113 /** Etherfabric event */
116 enum efab_event_type type;
121 /** Packet should be dropped */
126 * Etherfabric abstraction layer
130 struct efab_operations {
131 void ( * get_membase ) ( struct efab_nic *efab );
132 int ( * reset ) ( struct efab_nic *efab );
133 int ( * init_nic ) ( struct efab_nic *efab );
134 int ( * read_eeprom ) ( struct efab_nic *efab );
135 void ( * build_rx_desc ) ( struct efab_nic *efab,
136 struct efab_rx_buf *rx_buf );
137 void ( * notify_rx_desc ) ( struct efab_nic *efab );
138 void ( * build_tx_desc ) ( struct efab_nic *efab,
139 struct efab_tx_buf *tx_buf );
140 void ( * notify_tx_desc ) ( struct efab_nic *efab );
141 int ( * fetch_event ) ( struct efab_nic *efab,
142 struct efab_event *event );
143 void ( * mask_irq ) ( struct efab_nic *efab, int enabled );
144 void ( * generate_irq ) ( struct efab_nic *efab );
145 void ( * mdio_write ) ( struct efab_nic *efab, int location,
147 int ( * mdio_read ) ( struct efab_nic *efab, int location );
150 struct efab_mac_operations {
151 void ( * mac_writel ) ( struct efab_nic *efab, efab_dword_t *value,
152 unsigned int mac_reg );
153 void ( * mac_readl ) ( struct efab_nic *efab, efab_dword_t *value,
154 unsigned int mac_reg );
155 int ( * init ) ( struct efab_nic *efab );
156 int ( * reset ) ( struct efab_nic *efab );
160 * Driver private data structure
166 struct pci_device *pci;
168 /** Operations table */
169 struct efab_operations *op;
171 /** MAC operations table */
172 struct efab_mac_operations *mac_op;
181 uint8_t *eventq; /* Falcon only */
182 uint8_t *txd; /* Falcon only */
183 uint8_t *rxd; /* Falcon only */
184 struct efab_tx_buf tx_buf;
185 struct efab_rx_buf rx_bufs[EFAB_RX_BUFS];
187 /** Buffer pointers */
188 unsigned int eventq_read_ptr; /* Falcon only */
189 unsigned int tx_write_ptr;
190 unsigned int rx_write_ptr;
192 /** Port 0/1 on the NIC */
196 uint8_t mac_addr[ETH_ALEN];
197 /** GMII link options */
198 unsigned int link_options;
202 /* Nic type fields */
209 /** INT_REG_KER for Falcon */
210 efab_oword_t int_ker __attribute__ (( aligned ( 16 ) ));
213 struct i2c_bit_basher ef1002_i2c;
214 unsigned long ef1002_i2c_outputs;
215 struct i2c_device ef1002_eeprom;
219 struct spi_device falcon_flash;
220 struct spi_device falcon_eeprom;
222 /** Non-volatile options */
223 struct nvo_block nvo;
226 /**************************************************************************
230 **************************************************************************
234 #define MII_BMSR 0x01 /* Basic mode status register */
235 #define MII_ADVERTISE 0x04 /* Advertisement control register */
236 #define MII_LPA 0x05 /* Link partner ability register*/
237 #define GMII_GTCR 0x09 /* 1000BASE-T control register */
238 #define GMII_GTSR 0x0a /* 1000BASE-T status register */
239 #define GMII_PSSR 0x11 /* PHY-specific status register */
241 /* Basic mode status register. */
242 #define BMSR_LSTATUS 0x0004 /* Link status */
244 /* Link partner ability register. */
245 #define LPA_10HALF 0x0020 /* Can do 10mbps half-duplex */
246 #define LPA_10FULL 0x0040 /* Can do 10mbps full-duplex */
247 #define LPA_100HALF 0x0080 /* Can do 100mbps half-duplex */
248 #define LPA_100FULL 0x0100 /* Can do 100mbps full-duplex */
249 #define LPA_100BASE4 0x0200 /* Can do 100mbps 4k packets */
250 #define LPA_PAUSE 0x0400 /* Bit 10 - MAC pause */
252 /* Pseudo extensions to the link partner ability register */
253 #define LPA_1000FULL 0x00020000
254 #define LPA_1000HALF 0x00010000
255 #define LPA_10000FULL 0x00040000
256 #define LPA_10000HALF 0x00080000
258 #define LPA_100 (LPA_100FULL | LPA_100HALF | LPA_100BASE4)
259 #define LPA_1000 ( LPA_1000FULL | LPA_1000HALF )
260 #define LPA_10000 ( LPA_10000FULL | LPA_10000HALF )
261 #define LPA_DUPLEX ( LPA_10FULL | LPA_100FULL | LPA_1000FULL )
263 /* Mask of bits not associated with speed or duplexity. */
264 #define LPA_OTHER ~( LPA_10FULL | LPA_10HALF | LPA_100FULL | \
265 LPA_100HALF | LPA_1000FULL | LPA_1000HALF )
267 /* PHY-specific status register */
268 #define PSSR_LSTATUS 0x0400 /* Bit 10 - link status */
271 * Retrieve GMII autonegotiation advertised abilities
274 static unsigned int gmii_autoneg_advertised ( struct efab_nic *efab ) {
275 unsigned int mii_advertise;
276 unsigned int gmii_advertise;
278 /* Extended bits are in bits 8 and 9 of GMII_GTCR */
279 mii_advertise = efab->op->mdio_read ( efab, MII_ADVERTISE );
280 gmii_advertise = ( ( efab->op->mdio_read ( efab, GMII_GTCR ) >> 8 )
282 return ( ( gmii_advertise << 16 ) | mii_advertise );
286 * Retrieve GMII autonegotiation link partner abilities
289 static unsigned int gmii_autoneg_lpa ( struct efab_nic *efab ) {
290 unsigned int mii_lpa;
291 unsigned int gmii_lpa;
293 /* Extended bits are in bits 10 and 11 of GMII_GTSR */
294 mii_lpa = efab->op->mdio_read ( efab, MII_LPA );
295 gmii_lpa = ( efab->op->mdio_read ( efab, GMII_GTSR ) >> 10 ) & 0x03;
296 return ( ( gmii_lpa << 16 ) | mii_lpa );
300 * Calculate GMII autonegotiated link technology
303 static unsigned int gmii_nway_result ( unsigned int negotiated ) {
304 unsigned int other_bits;
306 /* Mask out the speed and duplexity bits */
307 other_bits = negotiated & LPA_OTHER;
309 if ( negotiated & LPA_1000FULL )
310 return ( other_bits | LPA_1000FULL );
311 else if ( negotiated & LPA_1000HALF )
312 return ( other_bits | LPA_1000HALF );
313 else if ( negotiated & LPA_100FULL )
314 return ( other_bits | LPA_100FULL );
315 else if ( negotiated & LPA_100BASE4 )
316 return ( other_bits | LPA_100BASE4 );
317 else if ( negotiated & LPA_100HALF )
318 return ( other_bits | LPA_100HALF );
319 else if ( negotiated & LPA_10FULL )
320 return ( other_bits | LPA_10FULL );
321 else return ( other_bits | LPA_10HALF );
325 * Check GMII PHY link status
328 static int gmii_link_ok ( struct efab_nic *efab ) {
332 /* BMSR is latching - it returns "link down" if the link has
333 * been down at any point since the last read. To get a
334 * real-time status, we therefore read the register twice and
335 * use the result of the second read.
337 efab->op->mdio_read ( efab, MII_BMSR );
338 status = efab->op->mdio_read ( efab, MII_BMSR );
340 /* Read the PHY-specific Status Register. This is
341 * non-latching, so we need do only a single read.
343 phy_status = efab->op->mdio_read ( efab, GMII_PSSR );
345 return ( ( status & BMSR_LSTATUS ) && ( phy_status & PSSR_LSTATUS ) );
348 /**************************************************************************
352 **************************************************************************
356 * Initialise Alaska PHY
359 static void alaska_init ( struct efab_nic *efab ) {
360 unsigned int advertised, lpa;
362 /* Read link up status */
363 efab->link_up = gmii_link_ok ( efab );
365 if ( ! efab->link_up )
368 /* Determine link options from PHY. */
369 advertised = gmii_autoneg_advertised ( efab );
370 lpa = gmii_autoneg_lpa ( efab );
371 efab->link_options = gmii_nway_result ( advertised & lpa );
373 /* print out the link speed */
374 EFAB_LOG ( "%dMbps %s-duplex (%04x,%04x)\n",
375 ( efab->link_options & LPA_10000 ? 1000 :
376 ( efab->link_options & LPA_1000 ? 1000 :
377 ( efab->link_options & LPA_100 ? 100 : 10 ) ) ),
378 ( efab->link_options & LPA_DUPLEX ? "full" : "half" ),
383 /**************************************************************************
387 **************************************************************************
390 /* GMAC configuration register 1 */
391 #define GM_CFG1_REG_MAC 0x00
392 #define GM_SW_RST_LBN 31
393 #define GM_SW_RST_WIDTH 1
394 #define GM_RX_FC_EN_LBN 5
395 #define GM_RX_FC_EN_WIDTH 1
396 #define GM_TX_FC_EN_LBN 4
397 #define GM_TX_FC_EN_WIDTH 1
398 #define GM_RX_EN_LBN 2
399 #define GM_RX_EN_WIDTH 1
400 #define GM_TX_EN_LBN 0
401 #define GM_TX_EN_WIDTH 1
403 /* GMAC configuration register 2 */
404 #define GM_CFG2_REG_MAC 0x01
405 #define GM_PAMBL_LEN_LBN 12
406 #define GM_PAMBL_LEN_WIDTH 4
407 #define GM_IF_MODE_LBN 8
408 #define GM_IF_MODE_WIDTH 2
409 #define GM_PAD_CRC_EN_LBN 2
410 #define GM_PAD_CRC_EN_WIDTH 1
412 #define GM_FD_WIDTH 1
414 /* GMAC maximum frame length register */
415 #define GM_MAX_FLEN_REG_MAC 0x04
416 #define GM_MAX_FLEN_LBN 0
417 #define GM_MAX_FLEN_WIDTH 16
419 /* GMAC MII management configuration register */
420 #define GM_MII_MGMT_CFG_REG_MAC 0x08
421 #define GM_MGMT_CLK_SEL_LBN 0
422 #define GM_MGMT_CLK_SEL_WIDTH 3
424 /* GMAC MII management command register */
425 #define GM_MII_MGMT_CMD_REG_MAC 0x09
426 #define GM_MGMT_SCAN_CYC_LBN 1
427 #define GM_MGMT_SCAN_CYC_WIDTH 1
428 #define GM_MGMT_RD_CYC_LBN 0
429 #define GM_MGMT_RD_CYC_WIDTH 1
431 /* GMAC MII management address register */
432 #define GM_MII_MGMT_ADR_REG_MAC 0x0a
433 #define GM_MGMT_PHY_ADDR_LBN 8
434 #define GM_MGMT_PHY_ADDR_WIDTH 5
435 #define GM_MGMT_REG_ADDR_LBN 0
436 #define GM_MGMT_REG_ADDR_WIDTH 5
438 /* GMAC MII management control register */
439 #define GM_MII_MGMT_CTL_REG_MAC 0x0b
440 #define GM_MGMT_CTL_LBN 0
441 #define GM_MGMT_CTL_WIDTH 16
443 /* GMAC MII management status register */
444 #define GM_MII_MGMT_STAT_REG_MAC 0x0c
445 #define GM_MGMT_STAT_LBN 0
446 #define GM_MGMT_STAT_WIDTH 16
448 /* GMAC MII management indicators register */
449 #define GM_MII_MGMT_IND_REG_MAC 0x0d
450 #define GM_MGMT_BUSY_LBN 0
451 #define GM_MGMT_BUSY_WIDTH 1
453 /* GMAC station address register 1 */
454 #define GM_ADR1_REG_MAC 0x10
455 #define GM_HWADDR_5_LBN 24
456 #define GM_HWADDR_5_WIDTH 8
457 #define GM_HWADDR_4_LBN 16
458 #define GM_HWADDR_4_WIDTH 8
459 #define GM_HWADDR_3_LBN 8
460 #define GM_HWADDR_3_WIDTH 8
461 #define GM_HWADDR_2_LBN 0
462 #define GM_HWADDR_2_WIDTH 8
464 /* GMAC station address register 2 */
465 #define GM_ADR2_REG_MAC 0x11
466 #define GM_HWADDR_1_LBN 24
467 #define GM_HWADDR_1_WIDTH 8
468 #define GM_HWADDR_0_LBN 16
469 #define GM_HWADDR_0_WIDTH 8
471 /* GMAC FIFO configuration register 0 */
472 #define GMF_CFG0_REG_MAC 0x12
473 #define GMF_FTFENREQ_LBN 12
474 #define GMF_FTFENREQ_WIDTH 1
475 #define GMF_STFENREQ_LBN 11
476 #define GMF_STFENREQ_WIDTH 1
477 #define GMF_FRFENREQ_LBN 10
478 #define GMF_FRFENREQ_WIDTH 1
479 #define GMF_SRFENREQ_LBN 9
480 #define GMF_SRFENREQ_WIDTH 1
481 #define GMF_WTMENREQ_LBN 8
482 #define GMF_WTMENREQ_WIDTH 1
484 /* GMAC FIFO configuration register 1 */
485 #define GMF_CFG1_REG_MAC 0x13
486 #define GMF_CFGFRTH_LBN 16
487 #define GMF_CFGFRTH_WIDTH 5
488 #define GMF_CFGXOFFRTX_LBN 0
489 #define GMF_CFGXOFFRTX_WIDTH 16
491 /* GMAC FIFO configuration register 2 */
492 #define GMF_CFG2_REG_MAC 0x14
493 #define GMF_CFGHWM_LBN 16
494 #define GMF_CFGHWM_WIDTH 6
495 #define GMF_CFGLWM_LBN 0
496 #define GMF_CFGLWM_WIDTH 6
498 /* GMAC FIFO configuration register 3 */
499 #define GMF_CFG3_REG_MAC 0x15
500 #define GMF_CFGHWMFT_LBN 16
501 #define GMF_CFGHWMFT_WIDTH 6
502 #define GMF_CFGFTTH_LBN 0
503 #define GMF_CFGFTTH_WIDTH 6
505 /* GMAC FIFO configuration register 4 */
506 #define GMF_CFG4_REG_MAC 0x16
507 #define GMF_HSTFLTRFRM_PAUSE_LBN 12
508 #define GMF_HSTFLTRFRM_PAUSE_WIDTH 12
510 /* GMAC FIFO configuration register 5 */
511 #define GMF_CFG5_REG_MAC 0x17
512 #define GMF_CFGHDPLX_LBN 22
513 #define GMF_CFGHDPLX_WIDTH 1
514 #define GMF_CFGBYTMODE_LBN 19
515 #define GMF_CFGBYTMODE_WIDTH 1
516 #define GMF_HSTDRPLT64_LBN 18
517 #define GMF_HSTDRPLT64_WIDTH 1
518 #define GMF_HSTFLTRFRMDC_PAUSE_LBN 12
519 #define GMF_HSTFLTRFRMDC_PAUSE_WIDTH 1
521 struct efab_mentormac_parameters {
533 static void mentormac_reset ( struct efab_nic *efab ) {
537 /* Take into reset */
538 EFAB_POPULATE_DWORD_1 ( reg, GM_SW_RST, 1 );
539 efab->mac_op->mac_writel ( efab, ®, GM_CFG1_REG_MAC );
542 /* Take out of reset */
543 EFAB_POPULATE_DWORD_1 ( reg, GM_SW_RST, 0 );
544 efab->mac_op->mac_writel ( efab, ®, GM_CFG1_REG_MAC );
547 /* Mentor MAC connects both PHYs to MAC 0 */
548 save_port = efab->port;
550 /* Configure GMII interface so PHY is accessible. Note that
551 * GMII interface is connected only to port 0, and that on
552 * Falcon this is a no-op.
554 EFAB_POPULATE_DWORD_1 ( reg, GM_MGMT_CLK_SEL, 0x4 );
555 efab->mac_op->mac_writel ( efab, ®, GM_MII_MGMT_CFG_REG_MAC );
557 efab->port = save_port;
561 * Initialise Mentor MAC
564 static void mentormac_init ( struct efab_nic *efab,
565 struct efab_mentormac_parameters *params ) {
566 int pause, if_mode, full_duplex, bytemode, half_duplex;
569 /* Configuration register 1 */
570 pause = ( efab->link_options & LPA_PAUSE ) ? 1 : 0;
571 if ( ! ( efab->link_options & LPA_DUPLEX ) ) {
572 /* Half-duplex operation requires TX flow control */
575 EFAB_POPULATE_DWORD_4 ( reg,
580 efab->mac_op->mac_writel ( efab, ®, GM_CFG1_REG_MAC );
583 /* Configuration register 2 */
584 if_mode = ( efab->link_options & LPA_1000 ) ? 2 : 1;
585 full_duplex = ( efab->link_options & LPA_DUPLEX ) ? 1 : 0;
586 EFAB_POPULATE_DWORD_4 ( reg,
590 GM_PAMBL_LEN, 0x7 /* ? */ );
591 efab->mac_op->mac_writel ( efab, ®, GM_CFG2_REG_MAC );
594 /* Max frame len register */
595 EFAB_POPULATE_DWORD_1 ( reg, GM_MAX_FLEN, ETH_FRAME_LEN + 4 /* FCS */);
596 efab->mac_op->mac_writel ( efab, ®, GM_MAX_FLEN_REG_MAC );
599 /* FIFO configuration register 0 */
600 EFAB_POPULATE_DWORD_5 ( reg,
606 efab->mac_op->mac_writel ( efab, ®, GMF_CFG0_REG_MAC );
609 /* FIFO configuration register 1 */
610 EFAB_POPULATE_DWORD_2 ( reg,
611 GMF_CFGFRTH, params->gmf_cfgfrth,
612 GMF_CFGXOFFRTX, 0xffff );
613 efab->mac_op->mac_writel ( efab, ®, GMF_CFG1_REG_MAC );
616 /* FIFO configuration register 2 */
617 EFAB_POPULATE_DWORD_2 ( reg,
618 GMF_CFGHWM, params->gmf_cfghwm,
619 GMF_CFGLWM, params->gmf_cfglwm );
620 efab->mac_op->mac_writel ( efab, ®, GMF_CFG2_REG_MAC );
623 /* FIFO configuration register 3 */
624 EFAB_POPULATE_DWORD_2 ( reg,
625 GMF_CFGHWMFT, params->gmf_cfghwmft,
626 GMF_CFGFTTH, params->gmf_cfgftth );
627 efab->mac_op->mac_writel ( efab, ®, GMF_CFG3_REG_MAC );
630 /* FIFO configuration register 4 */
631 EFAB_POPULATE_DWORD_1 ( reg, GMF_HSTFLTRFRM_PAUSE, 1 );
632 efab->mac_op->mac_writel ( efab, ®, GMF_CFG4_REG_MAC );
635 /* FIFO configuration register 5 */
636 bytemode = ( efab->link_options & LPA_1000 ) ? 1 : 0;
637 half_duplex = ( efab->link_options & LPA_DUPLEX ) ? 0 : 1;
638 efab->mac_op->mac_readl ( efab, ®, GMF_CFG5_REG_MAC );
639 EFAB_SET_DWORD_FIELD ( reg, GMF_CFGBYTMODE, bytemode );
640 EFAB_SET_DWORD_FIELD ( reg, GMF_CFGHDPLX, half_duplex );
641 EFAB_SET_DWORD_FIELD ( reg, GMF_HSTDRPLT64, half_duplex );
642 EFAB_SET_DWORD_FIELD ( reg, GMF_HSTFLTRFRMDC_PAUSE, 0 );
643 efab->mac_op->mac_writel ( efab, ®, GMF_CFG5_REG_MAC );
647 EFAB_POPULATE_DWORD_4 ( reg,
648 GM_HWADDR_5, efab->mac_addr[5],
649 GM_HWADDR_4, efab->mac_addr[4],
650 GM_HWADDR_3, efab->mac_addr[3],
651 GM_HWADDR_2, efab->mac_addr[2] );
652 efab->mac_op->mac_writel ( efab, ®, GM_ADR1_REG_MAC );
654 EFAB_POPULATE_DWORD_2 ( reg,
655 GM_HWADDR_1, efab->mac_addr[1],
656 GM_HWADDR_0, efab->mac_addr[0] );
657 efab->mac_op->mac_writel ( efab, ®, GM_ADR2_REG_MAC );
662 * Wait for GMII access to complete
665 static int mentormac_gmii_wait ( struct efab_nic *efab ) {
667 efab_dword_t indicator;
669 for ( count = 0 ; count < 1000 ; count++ ) {
671 efab->mac_op->mac_readl ( efab, &indicator,
672 GM_MII_MGMT_IND_REG_MAC );
673 if ( EFAB_DWORD_FIELD ( indicator, GM_MGMT_BUSY ) == 0 )
676 EFAB_ERR ( "Timed out waiting for GMII\n" );
681 * Write a GMII register
684 static void mentormac_mdio_write ( struct efab_nic *efab, int phy_id,
685 int location, int value ) {
689 EFAB_TRACE ( "Writing GMII %d register %02x with %04x\n", phy_id,
692 /* Mentor MAC connects both PHYs to MAC 0 */
693 save_port = efab->port;
696 /* Check MII not currently being accessed */
697 if ( ! mentormac_gmii_wait ( efab ) )
700 /* Write the address register */
701 EFAB_POPULATE_DWORD_2 ( reg,
702 GM_MGMT_PHY_ADDR, phy_id,
703 GM_MGMT_REG_ADDR, location );
704 efab->mac_op->mac_writel ( efab, ®, GM_MII_MGMT_ADR_REG_MAC );
708 EFAB_POPULATE_DWORD_1 ( reg, GM_MGMT_CTL, value );
709 efab->mac_op->mac_writel ( efab, ®, GM_MII_MGMT_CTL_REG_MAC );
711 /* Wait for data to be written */
712 mentormac_gmii_wait ( efab );
715 /* Restore efab->port */
716 efab->port = save_port;
720 * Read a GMII register
723 static int mentormac_mdio_read ( struct efab_nic *efab, int phy_id,
729 /* Mentor MAC connects both PHYs to MAC 0 */
730 save_port = efab->port;
733 /* Check MII not currently being accessed */
734 if ( ! mentormac_gmii_wait ( efab ) )
737 /* Write the address register */
738 EFAB_POPULATE_DWORD_2 ( reg,
739 GM_MGMT_PHY_ADDR, phy_id,
740 GM_MGMT_REG_ADDR, location );
741 efab->mac_op->mac_writel ( efab, ®, GM_MII_MGMT_ADR_REG_MAC );
744 /* Request data to be read */
745 EFAB_POPULATE_DWORD_1 ( reg, GM_MGMT_RD_CYC, 1 );
746 efab->mac_op->mac_writel ( efab, ®, GM_MII_MGMT_CMD_REG_MAC );
748 /* Wait for data to be become available */
749 if ( mentormac_gmii_wait ( efab ) ) {
751 efab->mac_op->mac_readl ( efab, ®, GM_MII_MGMT_STAT_REG_MAC );
752 value = EFAB_DWORD_FIELD ( reg, GM_MGMT_STAT );
753 EFAB_TRACE ( "Read from GMII %d register %02x, got %04x\n",
754 phy_id, location, value );
757 /* Signal completion */
758 EFAB_ZERO_DWORD ( reg );
759 efab->mac_op->mac_writel ( efab, ®, GM_MII_MGMT_CMD_REG_MAC );
763 /* Restore efab->port */
764 efab->port = save_port;
769 /**************************************************************************
773 **************************************************************************
776 /** Control and General Status */
777 #define EF1_CTR_GEN_STATUS0_REG 0x0
778 #define EF1_MASTER_EVENTS_LBN 12
779 #define EF1_MASTER_EVENTS_WIDTH 1
780 #define EF1_TX_ENGINE_EN_LBN 19
781 #define EF1_TX_ENGINE_EN_WIDTH 1
782 #define EF1_RX_ENGINE_EN_LBN 18
783 #define EF1_RX_ENGINE_EN_WIDTH 1
784 #define EF1_TURBO2_LBN 17
785 #define EF1_TURBO2_WIDTH 1
786 #define EF1_TURBO1_LBN 16
787 #define EF1_TURBO1_WIDTH 1
788 #define EF1_TURBO3_LBN 14
789 #define EF1_TURBO3_WIDTH 1
790 #define EF1_LB_RESET_LBN 3
791 #define EF1_LB_RESET_WIDTH 1
792 #define EF1_MAC_RESET_LBN 2
793 #define EF1_MAC_RESET_WIDTH 1
794 #define EF1_CAM_ENABLE_LBN 1
795 #define EF1_CAM_ENABLE_WIDTH 1
798 #define EF1_IRQ_SRC_REG 0x0008
801 #define EF1_IRQ_MASK_REG 0x000c
802 #define EF1_IRQ_PHY1_LBN 11
803 #define EF1_IRQ_PHY1_WIDTH 1
804 #define EF1_IRQ_PHY0_LBN 10
805 #define EF1_IRQ_PHY0_WIDTH 1
806 #define EF1_IRQ_SERR_LBN 7
807 #define EF1_IRQ_SERR_WIDTH 1
808 #define EF1_IRQ_EVQ_LBN 3
809 #define EF1_IRQ_EVQ_WIDTH 1
811 /** Event generation */
812 #define EF1_EVT3_REG 0x38
815 #define EF1_EEPROM_REG 0x40
816 #define EF1_EEPROM_SDA_LBN 31
817 #define EF1_EEPROM_SDA_WIDTH 1
818 #define EF1_EEPROM_SCL_LBN 30
819 #define EF1_EEPROM_SCL_WIDTH 1
820 #define EF1_JTAG_DISCONNECT_LBN 17
821 #define EF1_JTAG_DISCONNECT_WIDTH 1
822 #define EF1_EEPROM_LBN 0
823 #define EF1_EEPROM_WIDTH 32
825 /** Control register 2 */
826 #define EF1_CTL2_REG 0x4c
827 #define EF1_PLL_TRAP_LBN 31
828 #define EF1_PLL_TRAP_WIDTH 1
829 #define EF1_MEM_MAP_4MB_LBN 11
830 #define EF1_MEM_MAP_4MB_WIDTH 1
831 #define EF1_EV_INTR_CLR_WRITE_LBN 6
832 #define EF1_EV_INTR_CLR_WRITE_WIDTH 1
833 #define EF1_BURST_MERGE_LBN 5
834 #define EF1_BURST_MERGE_WIDTH 1
835 #define EF1_CLEAR_NULL_PAD_LBN 4
836 #define EF1_CLEAR_NULL_PAD_WIDTH 1
837 #define EF1_SW_RESET_LBN 2
838 #define EF1_SW_RESET_WIDTH 1
839 #define EF1_INTR_AFTER_EVENT_LBN 1
840 #define EF1_INTR_AFTER_EVENT_WIDTH 1
843 #define EF1_EVENT_FIFO_REG 0x50
845 /** Event FIFO count */
846 #define EF1_EVENT_FIFO_COUNT_REG 0x5c
847 #define EF1_EV_COUNT_LBN 0
848 #define EF1_EV_COUNT_WIDTH 16
850 /** TX DMA control and status */
851 #define EF1_DMA_TX_CSR_REG 0x80
852 #define EF1_DMA_TX_CSR_CHAIN_EN_LBN 8
853 #define EF1_DMA_TX_CSR_CHAIN_EN_WIDTH 1
854 #define EF1_DMA_TX_CSR_ENABLE_LBN 4
855 #define EF1_DMA_TX_CSR_ENABLE_WIDTH 1
856 #define EF1_DMA_TX_CSR_INT_EN_LBN 0
857 #define EF1_DMA_TX_CSR_INT_EN_WIDTH 1
859 /** RX DMA control and status */
860 #define EF1_DMA_RX_CSR_REG 0xa0
861 #define EF1_DMA_RX_ABOVE_1GB_EN_LBN 6
862 #define EF1_DMA_RX_ABOVE_1GB_EN_WIDTH 1
863 #define EF1_DMA_RX_BELOW_1MB_EN_LBN 5
864 #define EF1_DMA_RX_BELOW_1MB_EN_WIDTH 1
865 #define EF1_DMA_RX_CSR_ENABLE_LBN 0
866 #define EF1_DMA_RX_CSR_ENABLE_WIDTH 1
868 /** Level 5 watermark register (in MAC space) */
869 #define EF1_GMF_L5WM_REG_MAC 0x20
870 #define EF1_L5WM_LBN 0
871 #define EF1_L5WM_WIDTH 32
874 #define EF1_GM_MAC_CLK_REG 0x112000
875 #define EF1_GM_PORT0_MAC_CLK_LBN 0
876 #define EF1_GM_PORT0_MAC_CLK_WIDTH 1
877 #define EF1_GM_PORT1_MAC_CLK_LBN 1
878 #define EF1_GM_PORT1_MAC_CLK_WIDTH 1
880 /** TX descriptor FIFO */
881 #define EF1_TX_DESC_FIFO 0x141000
882 #define EF1_TX_KER_EVQ_LBN 80
883 #define EF1_TX_KER_EVQ_WIDTH 12
884 #define EF1_TX_KER_IDX_LBN 64
885 #define EF1_TX_KER_IDX_WIDTH 16
886 #define EF1_TX_KER_MODE_LBN 63
887 #define EF1_TX_KER_MODE_WIDTH 1
888 #define EF1_TX_KER_PORT_LBN 60
889 #define EF1_TX_KER_PORT_WIDTH 1
890 #define EF1_TX_KER_CONT_LBN 56
891 #define EF1_TX_KER_CONT_WIDTH 1
892 #define EF1_TX_KER_BYTE_CNT_LBN 32
893 #define EF1_TX_KER_BYTE_CNT_WIDTH 24
894 #define EF1_TX_KER_BUF_ADR_LBN 0
895 #define EF1_TX_KER_BUF_ADR_WIDTH 32
897 /** TX descriptor FIFO flush */
898 #define EF1_TX_DESC_FIFO_FLUSH 0x141ffc
900 /** RX descriptor FIFO */
901 #define EF1_RX_DESC_FIFO 0x145000
902 #define EF1_RX_KER_EVQ_LBN 48
903 #define EF1_RX_KER_EVQ_WIDTH 12
904 #define EF1_RX_KER_IDX_LBN 32
905 #define EF1_RX_KER_IDX_WIDTH 16
906 #define EF1_RX_KER_BUF_ADR_LBN 0
907 #define EF1_RX_KER_BUF_ADR_WIDTH 32
909 /** RX descriptor FIFO flush */
910 #define EF1_RX_DESC_FIFO_FLUSH 0x145ffc
913 #define EF1_CAM_BASE 0x1c0000
914 #define EF1_CAM_WTF_DOES_THIS_DO_LBN 0
915 #define EF1_CAM_WTF_DOES_THIS_DO_WIDTH 32
917 /** Event queue pointers */
918 #define EF1_EVQ_PTR_BASE 0x260000
919 #define EF1_EVQ_SIZE_LBN 29
920 #define EF1_EVQ_SIZE_WIDTH 2
921 #define EF1_EVQ_SIZE_4K 3
922 #define EF1_EVQ_SIZE_2K 2
923 #define EF1_EVQ_SIZE_1K 1
924 #define EF1_EVQ_SIZE_512 0
925 #define EF1_EVQ_BUF_BASE_ID_LBN 0
926 #define EF1_EVQ_BUF_BASE_ID_WIDTH 29
929 #define EF1002_MAC_REGBANK 0x110000
930 #define EF1002_MAC_REGBANK_SIZE 0x1000
931 #define EF1002_MAC_REG_SIZE 0x08
933 /** Offset of a MAC register within EF1002 */
934 #define EF1002_MAC_REG( efab, mac_reg ) \
935 ( EF1002_MAC_REGBANK + \
936 ( (efab)->port * EF1002_MAC_REGBANK_SIZE ) + \
937 ( (mac_reg) * EF1002_MAC_REG_SIZE ) )
939 /* Event queue entries */
940 #define EF1_EV_CODE_LBN 20
941 #define EF1_EV_CODE_WIDTH 8
942 #define EF1_RX_EV_DECODE 0x01
943 #define EF1_TX_EV_DECODE 0x02
944 #define EF1_TIMER_EV_DECODE 0x0b
945 #define EF1_DRV_GEN_EV_DECODE 0x0f
948 #define EF1_RX_EV_LEN_LBN 48
949 #define EF1_RX_EV_LEN_WIDTH 16
950 #define EF1_RX_EV_PORT_LBN 17
951 #define EF1_RX_EV_PORT_WIDTH 3
952 #define EF1_RX_EV_OK_LBN 16
953 #define EF1_RX_EV_OK_WIDTH 1
954 #define EF1_RX_EV_IDX_LBN 0
955 #define EF1_RX_EV_IDX_WIDTH 16
957 /* Transmit events */
958 #define EF1_TX_EV_PORT_LBN 17
959 #define EF1_TX_EV_PORT_WIDTH 3
960 #define EF1_TX_EV_OK_LBN 16
961 #define EF1_TX_EV_OK_WIDTH 1
962 #define EF1_TX_EV_IDX_LBN 0
963 #define EF1_TX_EV_IDX_WIDTH 16
965 /* forward decleration */
966 static struct efab_mac_operations ef1002_mac_operations;
968 /* I2C ID of the EEPROM */
969 #define EF1_EEPROM_I2C_ID 0x50
971 /* Offset of MAC address within EEPROM */
972 #define EF1_EEPROM_HWADDR_OFFSET 0x0
975 * Write dword to EF1002 register
978 static inline void ef1002_writel ( struct efab_nic *efab, efab_dword_t *value,
980 EFAB_REGDUMP ( "Writing register %x with " EFAB_DWORD_FMT "\n",
981 reg, EFAB_DWORD_VAL ( *value ) );
982 writel ( value->u32[0], efab->membase + reg );
986 * Read dword from an EF1002 register
989 static inline void ef1002_readl ( struct efab_nic *efab, efab_dword_t *value,
991 value->u32[0] = readl ( efab->membase + reg );
992 EFAB_REGDUMP ( "Read from register %x, got " EFAB_DWORD_FMT "\n",
993 reg, EFAB_DWORD_VAL ( *value ) );
997 * Read dword from an EF1002 register, silently
1000 static inline void ef1002_readl_silent ( struct efab_nic *efab,
1001 efab_dword_t *value,
1002 unsigned int reg ) {
1003 value->u32[0] = readl ( efab->membase + reg );
1010 static void ef1002_get_membase ( struct efab_nic *efab ) {
1011 unsigned long membase_phys;
1013 membase_phys = pci_bar_start ( efab->pci, PCI_BASE_ADDRESS_0 );
1014 efab->membase = ioremap ( membase_phys, 0x800000 );
1017 /** PCI registers to backup/restore over a device reset */
1018 static const unsigned int efab_pci_reg_addr[] = {
1019 PCI_COMMAND, 0x0c /* PCI_CACHE_LINE_SIZE */,
1020 PCI_BASE_ADDRESS_0, PCI_BASE_ADDRESS_1, PCI_BASE_ADDRESS_2,
1021 PCI_BASE_ADDRESS_3, PCI_ROM_ADDRESS, PCI_INTERRUPT_LINE,
1023 /** Number of registers in efab_pci_reg_addr */
1024 #define EFAB_NUM_PCI_REG \
1025 ( sizeof ( efab_pci_reg_addr ) / sizeof ( efab_pci_reg_addr[0] ) )
1026 /** PCI configuration space backup */
1027 struct efab_pci_reg {
1028 uint32_t reg[EFAB_NUM_PCI_REG];
1032 * I2C interface and EEPROM
1036 static unsigned long ef1002_i2c_bits[] = {
1037 [I2C_BIT_SCL] = ( 1 << 30 ),
1038 [I2C_BIT_SDA] = ( 1 << 31 ),
1041 static void ef1002_i2c_write_bit ( struct bit_basher *basher,
1042 unsigned int bit_id, unsigned long data ) {
1043 struct efab_nic *efab = container_of ( basher, struct efab_nic,
1044 ef1002_i2c.basher );
1048 mask = ef1002_i2c_bits[bit_id];
1049 efab->ef1002_i2c_outputs &= ~mask;
1050 efab->ef1002_i2c_outputs |= ( data & mask );
1051 EFAB_POPULATE_DWORD_1 ( reg, EF1_EEPROM, efab->ef1002_i2c_outputs );
1052 ef1002_writel ( efab, ®, EF1_EEPROM_REG );
1055 static int ef1002_i2c_read_bit ( struct bit_basher *basher,
1056 unsigned int bit_id ) {
1057 struct efab_nic *efab = container_of ( basher, struct efab_nic,
1058 ef1002_i2c.basher );
1062 mask = ef1002_i2c_bits[bit_id];
1063 ef1002_readl ( efab, ®, EF1_EEPROM_REG );
1064 return ( EFAB_DWORD_FIELD ( reg, EF1_EEPROM ) & mask );
1067 static struct bit_basher_operations ef1002_basher_ops = {
1068 .read = ef1002_i2c_read_bit,
1069 .write = ef1002_i2c_write_bit,
1072 static void ef1002_init_eeprom ( struct efab_nic *efab ) {
1073 efab->ef1002_i2c.basher.op = &ef1002_basher_ops;
1074 init_i2c_bit_basher ( &efab->ef1002_i2c );
1075 efab->ef1002_eeprom.address = EF1_EEPROM_I2C_ID;
1082 static int ef1002_reset ( struct efab_nic *efab ) {
1083 struct efab_pci_reg pci_reg;
1084 struct pci_device *pci_dev = efab->pci;
1089 /* Back up PCI configuration registers */
1090 for ( i = 0 ; i < EFAB_NUM_PCI_REG ; i++ ) {
1091 pci_read_config_dword ( pci_dev, efab_pci_reg_addr[i],
1095 /* Reset the whole device. */
1096 EFAB_POPULATE_DWORD_1 ( reg, EF1_SW_RESET, 1 );
1097 ef1002_writel ( efab, ®, EF1_CTL2_REG );
1100 /* Restore PCI configuration space */
1101 for ( i = 0 ; i < EFAB_NUM_PCI_REG ; i++ ) {
1102 pci_write_config_dword ( pci_dev, efab_pci_reg_addr[i],
1106 /* Verify PCI configuration space */
1107 for ( i = 0 ; i < EFAB_NUM_PCI_REG ; i++ ) {
1108 pci_read_config_dword ( pci_dev, efab_pci_reg_addr[i], &tmp );
1109 if ( tmp != pci_reg.reg[i] ) {
1110 EFAB_LOG ( "PCI restore failed on register %02x "
1111 "(is %08lx, should be %08lx); reboot\n",
1112 i, tmp, pci_reg.reg[i] );
1117 /* Verify device reset complete */
1118 ef1002_readl ( efab, ®, EF1_CTR_GEN_STATUS0_REG );
1119 if ( EFAB_DWORD_IS_ALL_ONES ( reg ) ) {
1120 EFAB_ERR ( "Reset failed\n" );
1131 static int ef1002_init_nic ( struct efab_nic *efab ) {
1134 /* patch in the MAC operations */
1135 efab->mac_op = &ef1002_mac_operations;
1137 /* No idea what CAM is, but the 'datasheet' says that we have
1138 * to write these values in at start of day
1140 EFAB_POPULATE_DWORD_1 ( reg, EF1_CAM_WTF_DOES_THIS_DO, 0x6 );
1141 ef1002_writel ( efab, ®, EF1_CAM_BASE + 0x20018 );
1143 EFAB_POPULATE_DWORD_1 ( reg, EF1_CAM_WTF_DOES_THIS_DO, 0x01000000 );
1144 ef1002_writel ( efab, ®, EF1_CAM_BASE + 0x00018 );
1147 /* General control register 0 */
1148 ef1002_readl ( efab, ®, EF1_CTR_GEN_STATUS0_REG );
1149 EFAB_SET_DWORD_FIELD ( reg, EF1_MASTER_EVENTS, 0 );
1150 EFAB_SET_DWORD_FIELD ( reg, EF1_TX_ENGINE_EN, 0 );
1151 EFAB_SET_DWORD_FIELD ( reg, EF1_RX_ENGINE_EN, 0 );
1152 EFAB_SET_DWORD_FIELD ( reg, EF1_TURBO2, 1 );
1153 EFAB_SET_DWORD_FIELD ( reg, EF1_TURBO1, 1 );
1154 EFAB_SET_DWORD_FIELD ( reg, EF1_TURBO3, 1 );
1155 EFAB_SET_DWORD_FIELD ( reg, EF1_CAM_ENABLE, 1 );
1156 ef1002_writel ( efab, ®, EF1_CTR_GEN_STATUS0_REG );
1159 /* General control register 2 */
1160 ef1002_readl ( efab, ®, EF1_CTL2_REG );
1161 EFAB_SET_DWORD_FIELD ( reg, EF1_PLL_TRAP, 1 );
1162 EFAB_SET_DWORD_FIELD ( reg, EF1_MEM_MAP_4MB, 0 );
1163 EFAB_SET_DWORD_FIELD ( reg, EF1_EV_INTR_CLR_WRITE, 0 );
1164 EFAB_SET_DWORD_FIELD ( reg, EF1_BURST_MERGE, 0 );
1165 EFAB_SET_DWORD_FIELD ( reg, EF1_CLEAR_NULL_PAD, 1 );
1166 EFAB_SET_DWORD_FIELD ( reg, EF1_INTR_AFTER_EVENT, 1 );
1167 ef1002_writel ( efab, ®, EF1_CTL2_REG );
1171 ef1002_readl ( efab, ®, EF1_DMA_RX_CSR_REG );
1172 EFAB_SET_DWORD_FIELD ( reg, EF1_DMA_RX_CSR_ENABLE, 1 );
1173 EFAB_SET_DWORD_FIELD ( reg, EF1_DMA_RX_BELOW_1MB_EN, 1 );
1174 EFAB_SET_DWORD_FIELD ( reg, EF1_DMA_RX_ABOVE_1GB_EN, 1 );
1175 ef1002_writel ( efab, ®, EF1_DMA_RX_CSR_REG );
1179 ef1002_readl ( efab, ®, EF1_DMA_TX_CSR_REG );
1180 EFAB_SET_DWORD_FIELD ( reg, EF1_DMA_TX_CSR_CHAIN_EN, 1 );
1181 EFAB_SET_DWORD_FIELD ( reg, EF1_DMA_TX_CSR_ENABLE, 0 /* ?? */ );
1182 EFAB_SET_DWORD_FIELD ( reg, EF1_DMA_TX_CSR_INT_EN, 0 /* ?? */ );
1183 ef1002_writel ( efab, ®, EF1_DMA_TX_CSR_REG );
1186 /* Disconnect the JTAG chain. Read-modify-write is impossible
1187 * on the I2C control bits, since reading gives the state of
1188 * the line inputs rather than the last written state.
1190 ef1002_readl ( efab, ®, EF1_EEPROM_REG );
1191 EFAB_SET_DWORD_FIELD ( reg, EF1_EEPROM_SDA, 1 );
1192 EFAB_SET_DWORD_FIELD ( reg, EF1_EEPROM_SCL, 1 );
1193 EFAB_SET_DWORD_FIELD ( reg, EF1_JTAG_DISCONNECT, 1 );
1194 ef1002_writel ( efab, ®, EF1_EEPROM_REG );
1197 /* Flush descriptor queues */
1198 EFAB_ZERO_DWORD ( reg );
1199 ef1002_writel ( efab, ®, EF1_RX_DESC_FIFO_FLUSH );
1200 ef1002_writel ( efab, ®, EF1_TX_DESC_FIFO_FLUSH );
1205 efab->mac_op->reset ( efab );
1207 /* Attach I2C bus */
1208 ef1002_init_eeprom ( efab );
1214 * Read MAC address from EEPROM
1217 static int ef1002_read_eeprom ( struct efab_nic *efab ) {
1218 struct i2c_interface *i2c = &efab->ef1002_i2c.i2c;
1219 struct i2c_device *i2cdev = &efab->ef1002_eeprom;
1221 return ( i2c->read ( i2c, i2cdev, EF1_EEPROM_HWADDR_OFFSET,
1222 efab->mac_addr, sizeof ( efab->mac_addr ) ) == 0);
1225 /** RX descriptor */
1226 typedef efab_qword_t ef1002_rx_desc_t;
1229 * Build RX descriptor
1232 static void ef1002_build_rx_desc ( struct efab_nic *efab,
1233 struct efab_rx_buf *rx_buf ) {
1234 ef1002_rx_desc_t rxd;
1236 EFAB_POPULATE_QWORD_3 ( rxd,
1238 EF1_RX_KER_IDX, rx_buf->id,
1240 virt_to_bus ( rx_buf->addr ) );
1241 ef1002_writel ( efab, &rxd.dword[0], EF1_RX_DESC_FIFO + 0 );
1243 ef1002_writel ( efab, &rxd.dword[1], EF1_RX_DESC_FIFO + 4 );
1248 * Update RX descriptor write pointer
1251 static void ef1002_notify_rx_desc ( struct efab_nic *efab __unused ) {
1255 /** TX descriptor */
1256 typedef efab_oword_t ef1002_tx_desc_t;
1259 * Build TX descriptor
1262 static void ef1002_build_tx_desc ( struct efab_nic *efab,
1263 struct efab_tx_buf *tx_buf ) {
1264 ef1002_tx_desc_t txd;
1266 EFAB_POPULATE_OWORD_7 ( txd,
1268 EF1_TX_KER_IDX, tx_buf->id,
1269 EF1_TX_KER_MODE, 0 /* IP mode */,
1270 EF1_TX_KER_PORT, efab->port,
1272 EF1_TX_KER_BYTE_CNT, tx_buf->len,
1274 virt_to_bus ( tx_buf->addr ) );
1276 ef1002_writel ( efab, &txd.dword[0], EF1_TX_DESC_FIFO + 0 );
1277 ef1002_writel ( efab, &txd.dword[1], EF1_TX_DESC_FIFO + 4 );
1279 ef1002_writel ( efab, &txd.dword[2], EF1_TX_DESC_FIFO + 8 );
1284 * Update TX descriptor write pointer
1287 static void ef1002_notify_tx_desc ( struct efab_nic *efab __unused ) {
1292 typedef efab_qword_t ef1002_event_t;
1295 * Retrieve event from event queue
1298 static int ef1002_fetch_event ( struct efab_nic *efab,
1299 struct efab_event *event ) {
1304 /* Check event FIFO depth */
1305 ef1002_readl_silent ( efab, ®, EF1_EVENT_FIFO_COUNT_REG );
1306 words = EFAB_DWORD_FIELD ( reg, EF1_EV_COUNT );
1310 /* Read event data */
1311 ef1002_readl ( efab, ®, EF1_EVENT_FIFO_REG );
1312 DBG ( "Event is " EFAB_DWORD_FMT "\n", EFAB_DWORD_VAL ( reg ) );
1315 ev_code = EFAB_DWORD_FIELD ( reg, EF1_EV_CODE );
1317 switch ( ev_code ) {
1318 case EF1_TX_EV_DECODE:
1319 event->type = EFAB_EV_TX;
1321 case EF1_RX_EV_DECODE:
1322 event->type = EFAB_EV_RX;
1323 event->rx_id = EFAB_DWORD_FIELD ( reg, EF1_RX_EV_IDX );
1324 /* RX len not available via event FIFO */
1325 event->rx_len = ETH_FRAME_LEN;
1327 case EF1_TIMER_EV_DECODE:
1328 /* These are safe to ignore. We seem to get some at
1329 * start of day, presumably due to the timers starting
1330 * up with random contents.
1332 event->type = EFAB_EV_NONE;
1335 EFAB_ERR ( "Unknown event type %d\n", ev_code );
1336 event->type = EFAB_EV_NONE;
1339 /* Clear any pending interrupts */
1340 ef1002_readl ( efab, ®, EF1_IRQ_SRC_REG );
1346 * Enable/disable interrupts
1349 static void ef1002_mask_irq ( struct efab_nic *efab, int enabled ) {
1350 efab_dword_t irq_mask;
1352 EFAB_POPULATE_DWORD_2 ( irq_mask,
1353 EF1_IRQ_SERR, enabled,
1354 EF1_IRQ_EVQ, enabled );
1355 ef1002_writel ( efab, &irq_mask, EF1_IRQ_MASK_REG );
1359 * Generate interrupt
1362 static void ef1002_generate_irq ( struct efab_nic *efab ) {
1363 ef1002_event_t test_event;
1365 EFAB_POPULATE_QWORD_1 ( test_event,
1366 EF1_EV_CODE, EF1_DRV_GEN_EV_DECODE );
1367 ef1002_writel ( efab, &test_event.dword[0], EF1_EVT3_REG );
1371 * Write dword to an EF1002 MAC register
1374 static void ef1002_mac_writel ( struct efab_nic *efab,
1375 efab_dword_t *value, unsigned int mac_reg ) {
1376 ef1002_writel ( efab, value, EF1002_MAC_REG ( efab, mac_reg ) );
1380 * Read dword from an EF1002 MAC register
1383 static void ef1002_mac_readl ( struct efab_nic *efab,
1384 efab_dword_t *value, unsigned int mac_reg ) {
1385 ef1002_readl ( efab, value, EF1002_MAC_REG ( efab, mac_reg ) );
1392 static int ef1002_init_mac ( struct efab_nic *efab ) {
1393 static struct efab_mentormac_parameters ef1002_mentormac_params = {
1394 .gmf_cfgfrth = 0x13,
1395 .gmf_cfgftth = 0x10,
1396 .gmf_cfghwmft = 0x555,
1401 unsigned int mac_clk;
1403 /* Initialise PHY */
1404 alaska_init ( efab );
1406 /* Initialise MAC */
1407 mentormac_init ( efab, &ef1002_mentormac_params );
1409 /* Write Level 5 watermark register */
1410 EFAB_POPULATE_DWORD_1 ( reg, EF1_L5WM, 0x10040000 );
1411 efab->mac_op->mac_writel ( efab, ®, EF1_GMF_L5WM_REG_MAC );
1414 /* Set MAC clock speed */
1415 ef1002_readl ( efab, ®, EF1_GM_MAC_CLK_REG );
1416 mac_clk = ( efab->link_options & LPA_1000 ) ? 0 : 1;
1417 if ( efab->port == 0 ) {
1418 EFAB_SET_DWORD_FIELD ( reg, EF1_GM_PORT0_MAC_CLK, mac_clk );
1420 EFAB_SET_DWORD_FIELD ( reg, EF1_GM_PORT1_MAC_CLK, mac_clk );
1422 ef1002_writel ( efab, ®, EF1_GM_MAC_CLK_REG );
1432 static int ef1002_reset_mac ( struct efab_nic *efab ) {
1433 mentormac_reset ( efab );
1438 static void ef1002_mdio_write ( struct efab_nic *efab, int location,
1440 mentormac_mdio_write ( efab, efab->port + 2, location, value );
1444 static int ef1002_mdio_read ( struct efab_nic *efab, int location ) {
1445 return mentormac_mdio_read ( efab, efab->port + 2, location );
1448 static struct efab_operations ef1002_operations = {
1449 .get_membase = ef1002_get_membase,
1450 .reset = ef1002_reset,
1451 .init_nic = ef1002_init_nic,
1452 .read_eeprom = ef1002_read_eeprom,
1453 .build_rx_desc = ef1002_build_rx_desc,
1454 .notify_rx_desc = ef1002_notify_rx_desc,
1455 .build_tx_desc = ef1002_build_tx_desc,
1456 .notify_tx_desc = ef1002_notify_tx_desc,
1457 .fetch_event = ef1002_fetch_event,
1458 .mask_irq = ef1002_mask_irq,
1459 .generate_irq = ef1002_generate_irq,
1460 .mdio_write = ef1002_mdio_write,
1461 .mdio_read = ef1002_mdio_read,
1464 static struct efab_mac_operations ef1002_mac_operations = {
1465 .mac_writel = ef1002_mac_writel,
1466 .mac_readl = ef1002_mac_readl,
1467 .init = ef1002_init_mac,
1468 .reset = ef1002_reset_mac,
1471 /**************************************************************************
1475 **************************************************************************
1478 /* I/O BAR address register */
1479 #define FCN_IOM_IND_ADR_REG 0x0
1481 /* I/O BAR data register */
1482 #define FCN_IOM_IND_DAT_REG 0x4
1484 /* Interrupt enable register */
1485 #define FCN_INT_EN_REG_KER 0x0010
1486 #define FCN_MEM_PERR_INT_EN_KER_LBN 5
1487 #define FCN_MEM_PERR_INT_EN_KER_WIDTH 1
1488 #define FCN_KER_INT_CHAR_LBN 4
1489 #define FCN_KER_INT_CHAR_WIDTH 1
1490 #define FCN_KER_INT_KER_LBN 3
1491 #define FCN_KER_INT_KER_WIDTH 1
1492 #define FCN_ILL_ADR_ERR_INT_EN_KER_LBN 2
1493 #define FCN_ILL_ADR_ERR_INT_EN_KER_WIDTH 1
1494 #define FCN_SRM_PERR_INT_EN_KER_LBN 1
1495 #define FCN_SRM_PERR_INT_EN_KER_WIDTH 1
1496 #define FCN_DRV_INT_EN_KER_LBN 0
1497 #define FCN_DRV_INT_EN_KER_WIDTH 1
1499 /* Interrupt status register */
1500 #define FCN_INT_ADR_REG_KER 0x0030
1501 #define FCN_INT_ADR_KER_LBN 0
1502 #define FCN_INT_ADR_KER_WIDTH EFAB_DMA_TYPE_WIDTH ( 64 )
1504 /* Interrupt acknowledge register */
1505 #define FCN_INT_ACK_KER_REG 0x0050
1507 /* SPI host command register */
1508 #define FCN_EE_SPI_HCMD_REG_KER 0x0100
1509 #define FCN_EE_SPI_HCMD_CMD_EN_LBN 31
1510 #define FCN_EE_SPI_HCMD_CMD_EN_WIDTH 1
1511 #define FCN_EE_WR_TIMER_ACTIVE_LBN 28
1512 #define FCN_EE_WR_TIMER_ACTIVE_WIDTH 1
1513 #define FCN_EE_SPI_HCMD_SF_SEL_LBN 24
1514 #define FCN_EE_SPI_HCMD_SF_SEL_WIDTH 1
1515 #define FCN_EE_SPI_EEPROM 0
1516 #define FCN_EE_SPI_FLASH 1
1517 #define FCN_EE_SPI_HCMD_DABCNT_LBN 16
1518 #define FCN_EE_SPI_HCMD_DABCNT_WIDTH 5
1519 #define FCN_EE_SPI_HCMD_READ_LBN 15
1520 #define FCN_EE_SPI_HCMD_READ_WIDTH 1
1521 #define FCN_EE_SPI_READ 1
1522 #define FCN_EE_SPI_WRITE 0
1523 #define FCN_EE_SPI_HCMD_DUBCNT_LBN 12
1524 #define FCN_EE_SPI_HCMD_DUBCNT_WIDTH 2
1525 #define FCN_EE_SPI_HCMD_ADBCNT_LBN 8
1526 #define FCN_EE_SPI_HCMD_ADBCNT_WIDTH 2
1527 #define FCN_EE_SPI_HCMD_ENC_LBN 0
1528 #define FCN_EE_SPI_HCMD_ENC_WIDTH 8
1530 /* SPI host address register */
1531 #define FCN_EE_SPI_HADR_REG_KER 0x0110
1532 #define FCN_EE_SPI_HADR_DUBYTE_LBN 24
1533 #define FCN_EE_SPI_HADR_DUBYTE_WIDTH 8
1534 #define FCN_EE_SPI_HADR_ADR_LBN 0
1535 #define FCN_EE_SPI_HADR_ADR_WIDTH 24
1537 /* SPI host data register */
1538 #define FCN_EE_SPI_HDATA_REG_KER 0x0120
1539 #define FCN_EE_SPI_HDATA3_LBN 96
1540 #define FCN_EE_SPI_HDATA3_WIDTH 32
1541 #define FCN_EE_SPI_HDATA2_LBN 64
1542 #define FCN_EE_SPI_HDATA2_WIDTH 32
1543 #define FCN_EE_SPI_HDATA1_LBN 32
1544 #define FCN_EE_SPI_HDATA1_WIDTH 32
1545 #define FCN_EE_SPI_HDATA0_LBN 0
1546 #define FCN_EE_SPI_HDATA0_WIDTH 32
1548 /* NIC status register */
1549 #define FCN_NIC_STAT_REG 0x0200
1550 #define ONCHIP_SRAM_LBN 16
1551 #define ONCHIP_SRAM_WIDTH 1
1552 #define SF_PRST_LBN 9
1553 #define SF_PRST_WIDTH 1
1554 #define EE_PRST_LBN 8
1555 #define EE_PRST_WIDTH 1
1556 #define EE_STRAP_LBN 7
1557 #define EE_STRAP_WIDTH 1
1558 #define PCI_PCIX_MODE_LBN 4
1559 #define PCI_PCIX_MODE_WIDTH 3
1560 #define PCI_PCIX_MODE_PCI33_DECODE 0
1561 #define PCI_PCIX_MODE_PCI66_DECODE 1
1562 #define PCI_PCIX_MODE_PCIX66_DECODE 5
1563 #define PCI_PCIX_MODE_PCIX100_DECODE 6
1564 #define PCI_PCIX_MODE_PCIX133_DECODE 7
1565 #define STRAP_ISCSI_EN_LBN 3
1566 #define STRAP_ISCSI_EN_WIDTH 1
1567 #define STRAP_PINS_LBN 0
1568 #define STRAP_PINS_WIDTH 3
1569 /* These bit definitions are extrapolated from the list of numerical
1570 * values for STRAP_PINS. If you want a laugh, read the datasheet's
1571 * definition for when bits 2:0 are set to 7.
1573 #define STRAP_10G_LBN 2
1574 #define STRAP_10G_WIDTH 1
1575 #define STRAP_DUAL_PORT_LBN 1
1576 #define STRAP_DUAL_PORT_WIDTH 1
1577 #define STRAP_PCIE_LBN 0
1578 #define STRAP_PCIE_WIDTH 1
1580 /* GPIO control register */
1581 #define FCN_GPIO_CTL_REG_KER 0x0210
1582 #define FCN_FLASH_PRESENT_LBN 7
1583 #define FCN_FLASH_PRESENT_WIDTH 1
1584 #define FCN_EEPROM_PRESENT_LBN 6
1585 #define FCN_EEPROM_PRESENT_WIDTH 1
1587 /* Global control register */
1588 #define FCN_GLB_CTL_REG_KER 0x0220
1589 #define EXT_PHY_RST_CTL_LBN 63
1590 #define EXT_PHY_RST_CTL_WIDTH 1
1591 #define PCIE_SD_RST_CTL_LBN 61
1592 #define PCIE_SD_RST_CTL_WIDTH 1
1593 #define PCIX_RST_CTL_LBN 60
1594 #define PCIX_RST_CTL_WIDTH 1
1595 #define PCIE_STCK_RST_CTL_LBN 59
1596 #define PCIE_STCK_RST_CTL_WIDTH 1
1597 #define PCIE_NSTCK_RST_CTL_LBN 58
1598 #define PCIE_NSTCK_RST_CTL_WIDTH 1
1599 #define PCIE_CORE_RST_CTL_LBN 57
1600 #define PCIE_CORE_RST_CTL_WIDTH 1
1601 #define EE_RST_CTL_LBN 49
1602 #define EE_RST_CTL_WIDTH 1
1603 #define CS_RST_CTL_LBN 48
1604 #define CS_RST_CTL_WIDTH 1
1605 #define RST_EXT_PHY_LBN 31
1606 #define RST_EXT_PHY_WIDTH 1
1607 #define INT_RST_DUR_LBN 4
1608 #define INT_RST_DUR_WIDTH 3
1609 #define EXT_PHY_RST_DUR_LBN 1
1610 #define EXT_PHY_RST_DUR_WIDTH 3
1612 #define SWRST_WIDTH 1
1613 #define INCLUDE_IN_RESET 0
1614 #define EXCLUDE_FROM_RESET 1
1616 /* FPGA build version */
1617 #define ALTERA_BUILD_REG_KER 0x0300
1618 #define VER_MAJOR_LBN 24
1619 #define VER_MAJOR_WIDTH 8
1620 #define VER_MINOR_LBN 16
1621 #define VER_MINOR_WIDTH 8
1622 #define VER_BUILD_LBN 0
1623 #define VER_BUILD_WIDTH 16
1624 #define VER_ALL_LBN 0
1625 #define VER_ALL_WIDTH 32
1627 /* Timer table for kernel access */
1628 #define FCN_TIMER_CMD_REG_KER 0x420
1629 #define FCN_TIMER_MODE_LBN 12
1630 #define FCN_TIMER_MODE_WIDTH 2
1631 #define FCN_TIMER_MODE_DIS 0
1632 #define FCN_TIMER_MODE_INT_HLDOFF 1
1633 #define FCN_TIMER_VAL_LBN 0
1634 #define FCN_TIMER_VAL_WIDTH 12
1636 /* Receive configuration register */
1637 #define FCN_RX_CFG_REG_KER 0x800
1638 #define FCN_RX_XOFF_EN_LBN 0
1639 #define FCN_RX_XOFF_EN_WIDTH 1
1641 /* SRAM receive descriptor cache configuration register */
1642 #define FCN_SRM_RX_DC_CFG_REG_KER 0x610
1643 #define FCN_SRM_RX_DC_BASE_ADR_LBN 0
1644 #define FCN_SRM_RX_DC_BASE_ADR_WIDTH 21
1646 /* SRAM transmit descriptor cache configuration register */
1647 #define FCN_SRM_TX_DC_CFG_REG_KER 0x620
1648 #define FCN_SRM_TX_DC_BASE_ADR_LBN 0
1649 #define FCN_SRM_TX_DC_BASE_ADR_WIDTH 21
1651 /* Receive filter control register */
1652 #define FCN_RX_FILTER_CTL_REG_KER 0x810
1653 #define FCN_NUM_KER_LBN 24
1654 #define FCN_NUM_KER_WIDTH 2
1656 /* Receive descriptor update register */
1657 #define FCN_RX_DESC_UPD_REG_KER 0x0830
1658 #define FCN_RX_DESC_WPTR_LBN 96
1659 #define FCN_RX_DESC_WPTR_WIDTH 12
1660 #define FCN_RX_DESC_UPD_REG_KER_DWORD ( FCN_RX_DESC_UPD_REG_KER + 12 )
1661 #define FCN_RX_DESC_WPTR_DWORD_LBN 0
1662 #define FCN_RX_DESC_WPTR_DWORD_WIDTH 12
1664 /* Receive descriptor cache configuration register */
1665 #define FCN_RX_DC_CFG_REG_KER 0x840
1666 #define FCN_RX_DC_SIZE_LBN 0
1667 #define FCN_RX_DC_SIZE_WIDTH 2
1669 /* Transmit descriptor update register */
1670 #define FCN_TX_DESC_UPD_REG_KER 0x0a10
1671 #define FCN_TX_DESC_WPTR_LBN 96
1672 #define FCN_TX_DESC_WPTR_WIDTH 12
1673 #define FCN_TX_DESC_UPD_REG_KER_DWORD ( FCN_TX_DESC_UPD_REG_KER + 12 )
1674 #define FCN_TX_DESC_WPTR_DWORD_LBN 0
1675 #define FCN_TX_DESC_WPTR_DWORD_WIDTH 12
1677 /* Transmit descriptor cache configuration register */
1678 #define FCN_TX_DC_CFG_REG_KER 0xa20
1679 #define FCN_TX_DC_SIZE_LBN 0
1680 #define FCN_TX_DC_SIZE_WIDTH 2
1682 /* PHY management transmit data register */
1683 #define FCN_MD_TXD_REG_KER 0xc00
1684 #define FCN_MD_TXD_LBN 0
1685 #define FCN_MD_TXD_WIDTH 16
1687 /* PHY management receive data register */
1688 #define FCN_MD_RXD_REG_KER 0xc10
1689 #define FCN_MD_RXD_LBN 0
1690 #define FCN_MD_RXD_WIDTH 16
1692 /* PHY management configuration & status register */
1693 #define FCN_MD_CS_REG_KER 0xc20
1694 #define FCN_MD_GC_LBN 4
1695 #define FCN_MD_GC_WIDTH 1
1696 #define FCN_MD_RIC_LBN 2
1697 #define FCN_MD_RIC_WIDTH 1
1698 #define FCN_MD_WRC_LBN 0
1699 #define FCN_MD_WRC_WIDTH 1
1701 /* PHY management PHY address register */
1702 #define FCN_MD_PHY_ADR_REG_KER 0xc30
1703 #define FCN_MD_PHY_ADR_LBN 0
1704 #define FCN_MD_PHY_ADR_WIDTH 16
1706 /* PHY management ID register */
1707 #define FCN_MD_ID_REG_KER 0xc40
1708 #define FCN_MD_PRT_ADR_LBN 11
1709 #define FCN_MD_PRT_ADR_WIDTH 5
1710 #define FCN_MD_DEV_ADR_LBN 6
1711 #define FCN_MD_DEV_ADR_WIDTH 5
1713 /* PHY management status & mask register */
1714 #define FCN_MD_STAT_REG_KER 0xc50
1715 #define FCN_MD_BSY_LBN 0
1716 #define FCN_MD_BSY_WIDTH 1
1718 /* Port 0 and 1 MAC control registers */
1719 #define FCN_MAC0_CTRL_REG_KER 0xc80
1720 #define FCN_MAC1_CTRL_REG_KER 0xc90
1721 #define FCN_MAC_XOFF_VAL_LBN 16
1722 #define FCN_MAC_XOFF_VAL_WIDTH 16
1723 #define FCN_MAC_BCAD_ACPT_LBN 4
1724 #define FCN_MAC_BCAD_ACPT_WIDTH 1
1725 #define FCN_MAC_UC_PROM_LBN 3
1726 #define FCN_MAC_UC_PROM_WIDTH 1
1727 #define FCN_MAC_LINK_STATUS_LBN 2
1728 #define FCN_MAC_LINK_STATUS_WIDTH 1
1729 #define FCN_MAC_SPEED_LBN 0
1730 #define FCN_MAC_SPEED_WIDTH 2
1732 /* GMAC registers */
1733 #define FALCON_GMAC_REGBANK 0xe00
1734 #define FALCON_GMAC_REGBANK_SIZE 0x200
1735 #define FALCON_GMAC_REG_SIZE 0x10
1737 /* XGMAC registers */
1738 #define FALCON_XMAC_REGBANK 0x1200
1739 #define FALCON_XMAC_REGBANK_SIZE 0x200
1740 #define FALCON_XMAC_REG_SIZE 0x10
1742 /* XGMAC address register low */
1743 #define FCN_XM_ADR_LO_REG_MAC 0x00
1744 #define FCN_XM_ADR_3_LBN 24
1745 #define FCN_XM_ADR_3_WIDTH 8
1746 #define FCN_XM_ADR_2_LBN 16
1747 #define FCN_XM_ADR_2_WIDTH 8
1748 #define FCN_XM_ADR_1_LBN 8
1749 #define FCN_XM_ADR_1_WIDTH 8
1750 #define FCN_XM_ADR_0_LBN 0
1751 #define FCN_XM_ADR_0_WIDTH 8
1753 /* XGMAC address register high */
1754 #define FCN_XM_ADR_HI_REG_MAC 0x01
1755 #define FCN_XM_ADR_5_LBN 8
1756 #define FCN_XM_ADR_5_WIDTH 8
1757 #define FCN_XM_ADR_4_LBN 0
1758 #define FCN_XM_ADR_4_WIDTH 8
1760 /* XGMAC global configuration - port 0*/
1761 #define FCN_XM_GLB_CFG_REG_MAC 0x02
1762 #define FCN_XM_RX_STAT_EN_LBN 11
1763 #define FCN_XM_RX_STAT_EN_WIDTH 1
1764 #define FCN_XM_TX_STAT_EN_LBN 10
1765 #define FCN_XM_TX_STAT_EN_WIDTH 1
1766 #define FCN_XM_RX_JUMBO_MODE_LBN 6
1767 #define FCN_XM_RX_JUMBO_MODE_WIDTH 1
1768 #define FCN_XM_CORE_RST_LBN 0
1769 #define FCN_XM_CORE_RST_WIDTH 1
1771 /* XGMAC transmit configuration - port 0 */
1772 #define FCN_XM_TX_CFG_REG_MAC 0x03
1773 #define FCN_XM_IPG_LBN 16
1774 #define FCN_XM_IPG_WIDTH 4
1775 #define FCN_XM_FCNTL_LBN 10
1776 #define FCN_XM_FCNTL_WIDTH 1
1777 #define FCN_XM_TXCRC_LBN 8
1778 #define FCN_XM_TXCRC_WIDTH 1
1779 #define FCN_XM_AUTO_PAD_LBN 5
1780 #define FCN_XM_AUTO_PAD_WIDTH 1
1781 #define FCN_XM_TX_PRMBL_LBN 2
1782 #define FCN_XM_TX_PRMBL_WIDTH 1
1783 #define FCN_XM_TXEN_LBN 1
1784 #define FCN_XM_TXEN_WIDTH 1
1786 /* XGMAC receive configuration - port 0 */
1787 #define FCN_XM_RX_CFG_REG_MAC 0x04
1788 #define FCN_XM_PASS_CRC_ERR_LBN 25
1789 #define FCN_XM_PASS_CRC_ERR_WIDTH 1
1790 #define FCN_XM_AUTO_DEPAD_LBN 8
1791 #define FCN_XM_AUTO_DEPAD_WIDTH 1
1792 #define FCN_XM_RXEN_LBN 1
1793 #define FCN_XM_RXEN_WIDTH 1
1795 /* XGMAC transmit parameter register */
1796 #define FCN_XM_TX_PARAM_REG_MAC 0x0d
1797 #define FCN_XM_TX_JUMBO_MODE_LBN 31
1798 #define FCN_XM_TX_JUMBO_MODE_WIDTH 1
1799 #define FCN_XM_MAX_TX_FRM_SIZE_LBN 16
1800 #define FCN_XM_MAX_TX_FRM_SIZE_WIDTH 14
1802 /* XGMAC receive parameter register */
1803 #define FCN_XM_RX_PARAM_REG_MAC 0x0e
1804 #define FCN_XM_MAX_RX_FRM_SIZE_LBN 0
1805 #define FCN_XM_MAX_RX_FRM_SIZE_WIDTH 14
1807 /* XAUI XGXS core status register */
1808 #define FCN_XX_ALIGN_DONE_LBN 20
1809 #define FCN_XX_ALIGN_DONE_WIDTH 1
1810 #define FCN_XX_CORE_STAT_REG_MAC 0x16
1811 #define FCN_XX_SYNC_STAT_LBN 16
1812 #define FCN_XX_SYNC_STAT_WIDTH 4
1813 #define FCN_XX_SYNC_STAT_DECODE_SYNCED 0xf
1814 #define FCN_XX_COMMA_DET_LBN 12
1815 #define FCN_XX_COMMA_DET_WIDTH 4
1816 #define FCN_XX_COMMA_DET_RESET 0xf
1819 /* XGXS/XAUI powerdown/reset register */
1820 #define FCN_XX_PWR_RST_REG_MAC 0x10
1821 #define FCN_XX_RSTXGXSRX_EN_LBN 2
1822 #define FCN_XX_RSTXGXSRX_EN_WIDTH 1
1823 #define FCN_XX_RSTXGXSTX_EN_LBN 1
1824 #define FCN_XX_RSTXGXSTX_EN_WIDTH 1
1825 #define FCN_XX_RST_XX_EN_LBN 0
1826 #define FCN_XX_RST_XX_EN_WIDTH 1
1828 /* Receive descriptor pointer table */
1829 #define FCN_RX_DESC_PTR_TBL_KER 0x11800
1830 #define FCN_RX_DESCQ_BUF_BASE_ID_LBN 36
1831 #define FCN_RX_DESCQ_BUF_BASE_ID_WIDTH 20
1832 #define FCN_RX_DESCQ_EVQ_ID_LBN 24
1833 #define FCN_RX_DESCQ_EVQ_ID_WIDTH 12
1834 #define FCN_RX_DESCQ_OWNER_ID_LBN 10
1835 #define FCN_RX_DESCQ_OWNER_ID_WIDTH 14
1836 #define FCN_RX_DESCQ_SIZE_LBN 3
1837 #define FCN_RX_DESCQ_SIZE_WIDTH 2
1838 #define FCN_RX_DESCQ_SIZE_4K 3
1839 #define FCN_RX_DESCQ_SIZE_2K 2
1840 #define FCN_RX_DESCQ_SIZE_1K 1
1841 #define FCN_RX_DESCQ_SIZE_512 0
1842 #define FCN_RX_DESCQ_TYPE_LBN 2
1843 #define FCN_RX_DESCQ_TYPE_WIDTH 1
1844 #define FCN_RX_DESCQ_JUMBO_LBN 1
1845 #define FCN_RX_DESCQ_JUMBO_WIDTH 1
1846 #define FCN_RX_DESCQ_EN_LBN 0
1847 #define FCN_RX_DESCQ_EN_WIDTH 1
1849 /* Transmit descriptor pointer table */
1850 #define FCN_TX_DESC_PTR_TBL_KER 0x11900
1851 #define FCN_TX_DESCQ_EN_LBN 88
1852 #define FCN_TX_DESCQ_EN_WIDTH 1
1853 #define FCN_TX_DESCQ_BUF_BASE_ID_LBN 36
1854 #define FCN_TX_DESCQ_BUF_BASE_ID_WIDTH 20
1855 #define FCN_TX_DESCQ_EVQ_ID_LBN 24
1856 #define FCN_TX_DESCQ_EVQ_ID_WIDTH 12
1857 #define FCN_TX_DESCQ_OWNER_ID_LBN 10
1858 #define FCN_TX_DESCQ_OWNER_ID_WIDTH 14
1859 #define FCN_TX_DESCQ_SIZE_LBN 3
1860 #define FCN_TX_DESCQ_SIZE_WIDTH 2
1861 #define FCN_TX_DESCQ_SIZE_4K 3
1862 #define FCN_TX_DESCQ_SIZE_2K 2
1863 #define FCN_TX_DESCQ_SIZE_1K 1
1864 #define FCN_TX_DESCQ_SIZE_512 0
1865 #define FCN_TX_DESCQ_TYPE_LBN 1
1866 #define FCN_TX_DESCQ_TYPE_WIDTH 2
1867 #define FCN_TX_DESCQ_FLUSH_LBN 0
1868 #define FCN_TX_DESCQ_FLUSH_WIDTH 1
1870 /* Event queue pointer */
1871 #define FCN_EVQ_PTR_TBL_KER 0x11a00
1872 #define FCN_EVQ_EN_LBN 23
1873 #define FCN_EVQ_EN_WIDTH 1
1874 #define FCN_EVQ_SIZE_LBN 20
1875 #define FCN_EVQ_SIZE_WIDTH 3
1876 #define FCN_EVQ_SIZE_32K 6
1877 #define FCN_EVQ_SIZE_16K 5
1878 #define FCN_EVQ_SIZE_8K 4
1879 #define FCN_EVQ_SIZE_4K 3
1880 #define FCN_EVQ_SIZE_2K 2
1881 #define FCN_EVQ_SIZE_1K 1
1882 #define FCN_EVQ_SIZE_512 0
1883 #define FCN_EVQ_BUF_BASE_ID_LBN 0
1884 #define FCN_EVQ_BUF_BASE_ID_WIDTH 20
1886 /* Event queue read pointer */
1887 #define FCN_EVQ_RPTR_REG_KER 0x11b00
1888 #define FCN_EVQ_RPTR_LBN 0
1889 #define FCN_EVQ_RPTR_WIDTH 14
1890 #define FCN_EVQ_RPTR_REG_KER_DWORD ( FCN_EVQ_RPTR_REG_KER + 0 )
1891 #define FCN_EVQ_RPTR_DWORD_LBN 0
1892 #define FCN_EVQ_RPTR_DWORD_WIDTH 14
1894 /* Special buffer descriptors */
1895 #define FCN_BUF_FULL_TBL_KER 0x18000
1896 #define FCN_IP_DAT_BUF_SIZE_LBN 50
1897 #define FCN_IP_DAT_BUF_SIZE_WIDTH 1
1898 #define FCN_IP_DAT_BUF_SIZE_8K 1
1899 #define FCN_IP_DAT_BUF_SIZE_4K 0
1900 #define FCN_BUF_ADR_FBUF_LBN 14
1901 #define FCN_BUF_ADR_FBUF_WIDTH 34
1902 #define FCN_BUF_OWNER_ID_FBUF_LBN 0
1903 #define FCN_BUF_OWNER_ID_FBUF_WIDTH 14
1905 /** Offset of a GMAC register within Falcon */
1906 #define FALCON_GMAC_REG( efab, mac_reg ) \
1907 ( FALCON_GMAC_REGBANK + \
1908 ( (efab)->port * FALCON_GMAC_REGBANK_SIZE ) + \
1909 ( (mac_reg) * FALCON_GMAC_REG_SIZE ) )
1911 /** Offset of an XMAC register within Falcon */
1912 #define FALCON_XMAC_REG( efab_port, mac_reg ) \
1913 ( FALCON_XMAC_REGBANK + \
1914 ( (efab_port)->port * FALCON_XMAC_REGBANK_SIZE ) + \
1915 ( (mac_reg) * FALCON_XMAC_REG_SIZE ) )
1917 #define FCN_MAC_DATA_LBN 0
1918 #define FCN_MAC_DATA_WIDTH 32
1920 /* Transmit descriptor */
1921 #define FCN_TX_KER_PORT_LBN 63
1922 #define FCN_TX_KER_PORT_WIDTH 1
1923 #define FCN_TX_KER_BYTE_CNT_LBN 48
1924 #define FCN_TX_KER_BYTE_CNT_WIDTH 14
1925 #define FCN_TX_KER_BUF_ADR_LBN 0
1926 #define FCN_TX_KER_BUF_ADR_WIDTH EFAB_DMA_TYPE_WIDTH ( 46 )
1929 /* Receive descriptor */
1930 #define FCN_RX_KER_BUF_SIZE_LBN 48
1931 #define FCN_RX_KER_BUF_SIZE_WIDTH 14
1932 #define FCN_RX_KER_BUF_ADR_LBN 0
1933 #define FCN_RX_KER_BUF_ADR_WIDTH EFAB_DMA_TYPE_WIDTH ( 46 )
1935 /* Event queue entries */
1936 #define FCN_EV_CODE_LBN 60
1937 #define FCN_EV_CODE_WIDTH 4
1938 #define FCN_RX_IP_EV_DECODE 0
1939 #define FCN_TX_IP_EV_DECODE 2
1940 #define FCN_DRIVER_EV_DECODE 5
1942 /* Receive events */
1943 #define FCN_RX_EV_PKT_OK_LBN 56
1944 #define FCN_RX_EV_PKT_OK_WIDTH 1
1945 #define FCN_RX_PORT_LBN 30
1946 #define FCN_RX_PORT_WIDTH 1
1947 #define FCN_RX_EV_BYTE_CNT_LBN 16
1948 #define FCN_RX_EV_BYTE_CNT_WIDTH 14
1949 #define FCN_RX_EV_DESC_PTR_LBN 0
1950 #define FCN_RX_EV_DESC_PTR_WIDTH 12
1952 /* Transmit events */
1953 #define FCN_TX_EV_DESC_PTR_LBN 0
1954 #define FCN_TX_EV_DESC_PTR_WIDTH 12
1956 /* Fixed special buffer numbers to use */
1957 #define FALCON_EVQ_ID 0
1958 #define FALCON_TXD_ID 1
1959 #define FALCON_RXD_ID 2
1961 #if FALCON_USE_IO_BAR
1963 /* Write dword via the I/O BAR */
1964 static inline void _falcon_writel ( struct efab_nic *efab, uint32_t value,
1965 unsigned int reg ) {
1966 outl ( reg, efab->iobase + FCN_IOM_IND_ADR_REG );
1967 outl ( value, efab->iobase + FCN_IOM_IND_DAT_REG );
1970 /* Read dword via the I/O BAR */
1971 static inline uint32_t _falcon_readl ( struct efab_nic *efab,
1972 unsigned int reg ) {
1973 outl ( reg, efab->iobase + FCN_IOM_IND_ADR_REG );
1974 return inl ( efab->iobase + FCN_IOM_IND_DAT_REG );
1977 #else /* FALCON_USE_IO_BAR */
1979 #define _falcon_writel( efab, value, reg ) \
1980 writel ( (value), (efab)->membase + (reg) )
1981 #define _falcon_readl( efab, reg ) readl ( (efab)->membase + (reg) )
1983 #endif /* FALCON_USE_IO_BAR */
1986 * Write to a Falcon register
1989 static inline void falcon_write ( struct efab_nic *efab, efab_oword_t *value,
1990 unsigned int reg ) {
1992 EFAB_REGDUMP ( "Writing register %x with " EFAB_OWORD_FMT "\n",
1993 reg, EFAB_OWORD_VAL ( *value ) );
1995 _falcon_writel ( efab, value->u32[0], reg + 0 );
1996 _falcon_writel ( efab, value->u32[1], reg + 4 );
1997 _falcon_writel ( efab, value->u32[2], reg + 8 );
1998 _falcon_writel ( efab, value->u32[3], reg + 12 );
2003 * Write to Falcon SRAM
2006 static inline void falcon_write_sram ( struct efab_nic *efab,
2007 efab_qword_t *value,
2008 unsigned int index ) {
2009 unsigned int reg = ( FCN_BUF_FULL_TBL_KER +
2010 ( index * sizeof ( *value ) ) );
2012 EFAB_REGDUMP ( "Writing SRAM register %x with " EFAB_QWORD_FMT "\n",
2013 reg, EFAB_QWORD_VAL ( *value ) );
2015 _falcon_writel ( efab, value->u32[0], reg + 0 );
2016 _falcon_writel ( efab, value->u32[1], reg + 4 );
2021 * Write dword to Falcon register that allows partial writes
2024 static inline void falcon_writel ( struct efab_nic *efab, efab_dword_t *value,
2025 unsigned int reg ) {
2026 EFAB_REGDUMP ( "Writing partial register %x with " EFAB_DWORD_FMT "\n",
2027 reg, EFAB_DWORD_VAL ( *value ) );
2028 _falcon_writel ( efab, value->u32[0], reg );
2032 * Read from a Falcon register
2035 static inline void falcon_read ( struct efab_nic *efab, efab_oword_t *value,
2036 unsigned int reg ) {
2037 value->u32[0] = _falcon_readl ( efab, reg + 0 );
2038 value->u32[1] = _falcon_readl ( efab, reg + 4 );
2039 value->u32[2] = _falcon_readl ( efab, reg + 8 );
2040 value->u32[3] = _falcon_readl ( efab, reg + 12 );
2042 EFAB_REGDUMP ( "Read from register %x, got " EFAB_OWORD_FMT "\n",
2043 reg, EFAB_OWORD_VAL ( *value ) );
2047 * Read from Falcon SRAM
2050 static inline void falcon_read_sram ( struct efab_nic *efab,
2051 efab_qword_t *value,
2052 unsigned int index ) {
2053 unsigned int reg = ( FCN_BUF_FULL_TBL_KER +
2054 ( index * sizeof ( *value ) ) );
2056 value->u32[0] = _falcon_readl ( efab, reg + 0 );
2057 value->u32[1] = _falcon_readl ( efab, reg + 4 );
2058 EFAB_REGDUMP ( "Read from SRAM register %x, got " EFAB_QWORD_FMT "\n",
2059 reg, EFAB_QWORD_VAL ( *value ) );
2063 * Read dword from a portion of a Falcon register
2066 static inline void falcon_readl ( struct efab_nic *efab, efab_dword_t *value,
2067 unsigned int reg ) {
2068 value->u32[0] = _falcon_readl ( efab, reg );
2069 EFAB_REGDUMP ( "Read from register %x, got " EFAB_DWORD_FMT "\n",
2070 reg, EFAB_DWORD_VAL ( *value ) );
2074 * Verified write to Falcon SRAM
2077 static inline void falcon_write_sram_verify ( struct efab_nic *efab,
2078 efab_qword_t *value,
2079 unsigned int index ) {
2080 efab_qword_t verify;
2082 falcon_write_sram ( efab, value, index );
2084 falcon_read_sram ( efab, &verify, index );
2085 if ( memcmp ( &verify, value, sizeof ( verify ) ) != 0 ) {
2086 EFAB_ERR ( "SRAM index %x failure: wrote " EFAB_QWORD_FMT
2087 " got " EFAB_QWORD_FMT "\n", index,
2088 EFAB_QWORD_VAL ( *value ),
2089 EFAB_QWORD_VAL ( verify ) );
2097 static void falcon_get_membase ( struct efab_nic *efab ) {
2098 unsigned long membase_phys;
2100 membase_phys = pci_bar_start ( efab->pci, PCI_BASE_ADDRESS_2 );
2101 efab->membase = ioremap ( membase_phys, 0x20000 );
2104 #define FCN_DUMP_REG( efab, _reg ) do { \
2106 falcon_read ( efab, ®, _reg ); \
2107 EFAB_LOG ( #_reg " = " EFAB_OWORD_FMT "\n", \
2108 EFAB_OWORD_VAL ( reg ) ); \
2111 #define FCN_DUMP_MAC_REG( efab, _mac_reg ) do { \
2113 efab->mac_op->mac_readl ( efab, ®, _mac_reg ); \
2114 EFAB_LOG ( #_mac_reg " = " EFAB_DWORD_FMT "\n", \
2115 EFAB_DWORD_VAL ( reg ) ); \
2119 * Dump register contents (for debugging)
2121 * Marked as static inline so that it will not be compiled in if not
2124 static inline void falcon_dump_regs ( struct efab_nic *efab ) {
2125 FCN_DUMP_REG ( efab, FCN_INT_EN_REG_KER );
2126 FCN_DUMP_REG ( efab, FCN_INT_ADR_REG_KER );
2127 FCN_DUMP_REG ( efab, FCN_GLB_CTL_REG_KER );
2128 FCN_DUMP_REG ( efab, FCN_TIMER_CMD_REG_KER );
2129 FCN_DUMP_REG ( efab, FCN_SRM_RX_DC_CFG_REG_KER );
2130 FCN_DUMP_REG ( efab, FCN_SRM_TX_DC_CFG_REG_KER );
2131 FCN_DUMP_REG ( efab, FCN_RX_FILTER_CTL_REG_KER );
2132 FCN_DUMP_REG ( efab, FCN_RX_DC_CFG_REG_KER );
2133 FCN_DUMP_REG ( efab, FCN_TX_DC_CFG_REG_KER );
2134 FCN_DUMP_REG ( efab, FCN_MAC0_CTRL_REG_KER );
2135 FCN_DUMP_REG ( efab, FCN_MAC1_CTRL_REG_KER );
2136 FCN_DUMP_REG ( efab, FCN_RX_DESC_PTR_TBL_KER );
2137 FCN_DUMP_REG ( efab, FCN_TX_DESC_PTR_TBL_KER );
2138 FCN_DUMP_REG ( efab, FCN_EVQ_PTR_TBL_KER );
2139 FCN_DUMP_MAC_REG ( efab, GM_CFG1_REG_MAC );
2140 FCN_DUMP_MAC_REG ( efab, GM_CFG2_REG_MAC );
2141 FCN_DUMP_MAC_REG ( efab, GM_MAX_FLEN_REG_MAC );
2142 FCN_DUMP_MAC_REG ( efab, GM_MII_MGMT_CFG_REG_MAC );
2143 FCN_DUMP_MAC_REG ( efab, GM_ADR1_REG_MAC );
2144 FCN_DUMP_MAC_REG ( efab, GM_ADR2_REG_MAC );
2145 FCN_DUMP_MAC_REG ( efab, GMF_CFG0_REG_MAC );
2146 FCN_DUMP_MAC_REG ( efab, GMF_CFG1_REG_MAC );
2147 FCN_DUMP_MAC_REG ( efab, GMF_CFG2_REG_MAC );
2148 FCN_DUMP_MAC_REG ( efab, GMF_CFG3_REG_MAC );
2149 FCN_DUMP_MAC_REG ( efab, GMF_CFG4_REG_MAC );
2150 FCN_DUMP_MAC_REG ( efab, GMF_CFG5_REG_MAC );
2154 * Create special buffer
2157 static void falcon_create_special_buffer ( struct efab_nic *efab,
2158 void *addr, unsigned int index ) {
2159 efab_qword_t buf_desc;
2160 unsigned long dma_addr;
2162 memset ( addr, 0, 4096 );
2163 dma_addr = virt_to_bus ( addr );
2164 EFAB_ASSERT ( ( dma_addr & ( EFAB_BUF_ALIGN - 1 ) ) == 0 );
2165 EFAB_POPULATE_QWORD_3 ( buf_desc,
2166 FCN_IP_DAT_BUF_SIZE, FCN_IP_DAT_BUF_SIZE_4K,
2167 FCN_BUF_ADR_FBUF, ( dma_addr >> 12 ),
2168 FCN_BUF_OWNER_ID_FBUF, 0 );
2169 falcon_write_sram_verify ( efab, &buf_desc, index );
2173 * Update event queue read pointer
2176 static void falcon_eventq_read_ack ( struct efab_nic *efab ) {
2179 EFAB_ASSERT ( efab->eventq_read_ptr < EFAB_EVQ_SIZE );
2181 EFAB_POPULATE_DWORD_1 ( reg, FCN_EVQ_RPTR_DWORD,
2182 efab->eventq_read_ptr );
2183 falcon_writel ( efab, ®, FCN_EVQ_RPTR_REG_KER_DWORD );
2190 static int falcon_reset ( struct efab_nic *efab ) {
2191 efab_oword_t glb_ctl_reg_ker;
2193 /* Initiate software reset */
2194 EFAB_POPULATE_OWORD_7 ( glb_ctl_reg_ker,
2195 PCIE_CORE_RST_CTL, EXCLUDE_FROM_RESET,
2196 PCIE_NSTCK_RST_CTL, EXCLUDE_FROM_RESET,
2197 PCIE_SD_RST_CTL, EXCLUDE_FROM_RESET,
2198 EE_RST_CTL, EXCLUDE_FROM_RESET,
2199 PCIX_RST_CTL, EXCLUDE_FROM_RESET,
2200 EXT_PHY_RST_DUR, 0x7 /* datasheet recommended */,
2203 falcon_write ( efab, &glb_ctl_reg_ker, FCN_GLB_CTL_REG_KER );
2205 /* Allow 20ms for reset */
2208 /* Check for device reset complete */
2209 falcon_read ( efab, &glb_ctl_reg_ker, FCN_GLB_CTL_REG_KER );
2210 if ( EFAB_OWORD_FIELD ( glb_ctl_reg_ker, SWRST ) != 0 ) {
2211 EFAB_ERR ( "Reset failed\n" );
2219 * Wait for SPI command completion
2222 static int falcon_spi_wait ( struct efab_nic *efab ) {
2229 falcon_read ( efab, ®, FCN_EE_SPI_HCMD_REG_KER );
2230 if ( EFAB_OWORD_FIELD ( reg, FCN_EE_SPI_HCMD_CMD_EN ) == 0 )
2232 } while ( ++count < 1000 );
2233 printf ( "Timed out waiting for SPI\n" );
2238 * Perform SPI read/write
2241 static int falcon_spi_rw ( struct spi_bus *bus, struct spi_device *device,
2242 unsigned int command, int address,
2243 const void *data_out, void *data_in, size_t len ) {
2244 struct efab_nic *efab = container_of ( bus, struct efab_nic, spi );
2247 /* Program address register */
2248 EFAB_POPULATE_OWORD_1 ( reg, FCN_EE_SPI_HADR_ADR, address );
2249 falcon_write ( efab, ®, FCN_EE_SPI_HADR_REG_KER );
2251 /* Program data register, if applicable */
2253 memcpy ( ®, data_out, len );
2254 falcon_write ( efab, ®, FCN_EE_SPI_HDATA_REG_KER );
2258 EFAB_POPULATE_OWORD_7 ( reg,
2259 FCN_EE_SPI_HCMD_CMD_EN, 1,
2260 FCN_EE_SPI_HCMD_SF_SEL, device->slave,
2261 FCN_EE_SPI_HCMD_DABCNT, len,
2262 FCN_EE_SPI_HCMD_READ, ( data_out ?
2263 FCN_EE_SPI_WRITE : FCN_EE_SPI_READ ),
2264 FCN_EE_SPI_HCMD_DUBCNT, 0,
2265 FCN_EE_SPI_HCMD_ADBCNT,
2266 ( device->address_len / 8 ),
2267 FCN_EE_SPI_HCMD_ENC, command );
2268 falcon_write ( efab, ®, FCN_EE_SPI_HCMD_REG_KER );
2270 /* Wait for operation to complete */
2271 if ( ! falcon_spi_wait ( efab ) )
2274 /* Read data, if applicable */
2276 falcon_read ( efab, ®, FCN_EE_SPI_HDATA_REG_KER );
2277 memcpy ( data_in, ®, len );
2284 * Initialise SPI bus and devices
2287 static void falcon_init_spi ( struct efab_nic *efab ) {
2288 /* Initialise SPI bus */
2289 efab->spi.rw = falcon_spi_rw;
2290 efab->falcon_eeprom.bus = &efab->spi;
2291 efab->falcon_eeprom.slave = FCN_EE_SPI_EEPROM;
2292 efab->falcon_flash.bus = &efab->spi;
2293 efab->falcon_flash.slave = FCN_EE_SPI_FLASH;
2295 /* Initialise EEPROM, if present */
2296 if ( efab->has_flash ) {
2297 init_at25f1024 ( &efab->falcon_flash );
2298 init_at25040 ( &efab->falcon_eeprom );
2300 init_mc25xx640 ( &efab->falcon_eeprom );
2301 /* Falcon's SPI interface cannot support a block size
2302 * larger than 16, so forcibly reduce it
2304 efab->falcon_eeprom.nvs.block_size = 16;
2308 /** Offset of MAC address within EEPROM or Flash */
2309 #define FALCON_MAC_ADDRESS_OFFSET(port) ( 0x310 + 0x08 * (port) )
2311 static struct nvo_fragment falcon_eeprom_fragments[] = {
2317 * Read MAC address from EEPROM
2320 static int falcon_read_eeprom ( struct efab_nic *efab ) {
2321 struct nvs_device *nvs;
2323 /* Determine the NVS device containing the MAC address */
2324 nvs = ( efab->has_flash ?
2325 &efab->falcon_flash.nvs : &efab->falcon_eeprom.nvs );
2327 return ( nvs_read ( nvs, FALCON_MAC_ADDRESS_OFFSET ( efab->port ),
2328 efab->mac_addr, sizeof ( efab->mac_addr ) ) == 0 );
2331 /** RX descriptor */
2332 typedef efab_qword_t falcon_rx_desc_t;
2335 * Build RX descriptor
2338 static void falcon_build_rx_desc ( struct efab_nic *efab,
2339 struct efab_rx_buf *rx_buf ) {
2340 falcon_rx_desc_t *rxd;
2342 rxd = ( ( falcon_rx_desc_t * ) efab->rxd ) + rx_buf->id;
2343 EFAB_POPULATE_QWORD_2 ( *rxd,
2344 FCN_RX_KER_BUF_SIZE, EFAB_DATA_BUF_SIZE,
2346 virt_to_bus ( rx_buf->addr ) );
2350 * Update RX descriptor write pointer
2353 static void falcon_notify_rx_desc ( struct efab_nic *efab ) {
2356 EFAB_POPULATE_DWORD_1 ( reg, FCN_RX_DESC_WPTR_DWORD,
2357 efab->rx_write_ptr );
2358 falcon_writel ( efab, ®, FCN_RX_DESC_UPD_REG_KER_DWORD );
2361 /** TX descriptor */
2362 typedef efab_qword_t falcon_tx_desc_t;
2365 * Build TX descriptor
2368 static void falcon_build_tx_desc ( struct efab_nic *efab,
2369 struct efab_tx_buf *tx_buf ) {
2370 falcon_rx_desc_t *txd;
2372 txd = ( ( falcon_rx_desc_t * ) efab->txd ) + tx_buf->id;
2373 EFAB_POPULATE_QWORD_3 ( *txd,
2374 FCN_TX_KER_PORT, efab->port,
2375 FCN_TX_KER_BYTE_CNT, tx_buf->len,
2377 virt_to_bus ( tx_buf->addr ) );
2381 * Update TX descriptor write pointer
2384 static void falcon_notify_tx_desc ( struct efab_nic *efab ) {
2387 EFAB_POPULATE_DWORD_1 ( reg, FCN_TX_DESC_WPTR_DWORD,
2388 efab->tx_write_ptr );
2389 falcon_writel ( efab, ®, FCN_TX_DESC_UPD_REG_KER_DWORD );
2393 typedef efab_qword_t falcon_event_t;
2396 * See if an event is present
2398 * @v event Falcon event structure
2399 * @ret True An event is pending
2400 * @ret False No event is pending
2402 * We check both the high and low dword of the event for all ones. We
2403 * wrote all ones when we cleared the event, and no valid event can
2404 * have all ones in either its high or low dwords. This approach is
2405 * robust against reordering.
2407 * Note that using a single 64-bit comparison is incorrect; even
2408 * though the CPU read will be atomic, the DMA write may not be.
2410 static inline int falcon_event_present ( falcon_event_t* event ) {
2411 return ( ! ( EFAB_DWORD_IS_ALL_ONES ( event->dword[0] ) |
2412 EFAB_DWORD_IS_ALL_ONES ( event->dword[1] ) ) );
2416 * Retrieve event from event queue
2419 static int falcon_fetch_event ( struct efab_nic *efab,
2420 struct efab_event *event ) {
2421 falcon_event_t *evt;
2425 /* Check for event */
2426 evt = ( ( falcon_event_t * ) efab->eventq ) + efab->eventq_read_ptr;
2427 if ( !falcon_event_present ( evt ) ) {
2432 DBG ( "Event is " EFAB_QWORD_FMT "\n", EFAB_QWORD_VAL ( *evt ) );
2435 ev_code = EFAB_QWORD_FIELD ( *evt, FCN_EV_CODE );
2437 switch ( ev_code ) {
2438 case FCN_TX_IP_EV_DECODE:
2439 event->type = EFAB_EV_TX;
2441 case FCN_RX_IP_EV_DECODE:
2442 event->type = EFAB_EV_RX;
2443 event->rx_id = EFAB_QWORD_FIELD ( *evt, FCN_RX_EV_DESC_PTR );
2444 event->rx_len = EFAB_QWORD_FIELD ( *evt, FCN_RX_EV_BYTE_CNT );
2445 event->drop = !EFAB_QWORD_FIELD ( *evt, FCN_RX_EV_PKT_OK );
2446 rx_port = EFAB_QWORD_FIELD ( *evt, FCN_RX_PORT );
2447 if ( rx_port != efab->port ) {
2448 /* Ignore packets on the wrong port. We can't
2449 * just set event->type = EFAB_EV_NONE,
2450 * because then the descriptor ring won't get
2456 case FCN_DRIVER_EV_DECODE:
2457 /* Ignore start-of-day events */
2458 event->type = EFAB_EV_NONE;
2461 EFAB_ERR ( "Unknown event type %d data %08lx\n", ev_code,
2462 EFAB_DWORD_FIELD ( *evt, EFAB_DWORD_0 ) );
2463 event->type = EFAB_EV_NONE;
2466 /* Clear event and any pending interrupts */
2467 EFAB_SET_QWORD ( *evt );
2468 falcon_writel ( efab, 0, FCN_INT_ACK_KER_REG );
2471 /* Increment and update event queue read pointer */
2472 efab->eventq_read_ptr = ( ( efab->eventq_read_ptr + 1 )
2474 falcon_eventq_read_ack ( efab );
2480 * Enable/disable/generate interrupt
2483 static inline void falcon_interrupts ( struct efab_nic *efab, int enabled,
2485 efab_oword_t int_en_reg_ker;
2487 EFAB_POPULATE_OWORD_2 ( int_en_reg_ker,
2488 FCN_KER_INT_KER, force,
2489 FCN_DRV_INT_EN_KER, enabled );
2490 falcon_write ( efab, &int_en_reg_ker, FCN_INT_EN_REG_KER );
2494 * Enable/disable interrupts
2497 static void falcon_mask_irq ( struct efab_nic *efab, int enabled ) {
2498 falcon_interrupts ( efab, enabled, 0 );
2500 /* Events won't trigger interrupts until we do this */
2501 falcon_eventq_read_ack ( efab );
2506 * Generate interrupt
2509 static void falcon_generate_irq ( struct efab_nic *efab ) {
2510 falcon_interrupts ( efab, 1, 1 );
2515 * Reconfigure MAC wrapper
2518 static void falcon_reconfigure_mac_wrapper ( struct efab_nic *efab ) {
2522 if ( efab->link_options & LPA_10000 ) {
2524 } else if ( efab->link_options & LPA_1000 ) {
2526 } else if ( efab->link_options & LPA_100 ) {
2531 EFAB_POPULATE_OWORD_5 ( reg,
2532 FCN_MAC_XOFF_VAL, 0xffff /* datasheet */,
2533 FCN_MAC_BCAD_ACPT, 1,
2535 FCN_MAC_LINK_STATUS, 1,
2536 FCN_MAC_SPEED, link_speed );
2537 falcon_write ( efab, ®,
2539 FCN_MAC0_CTRL_REG_KER : FCN_MAC1_CTRL_REG_KER ) );
2541 /* Disable flow-control (i.e. never generate pause frames) */
2542 falcon_read ( efab, ®, FCN_RX_CFG_REG_KER );
2543 EFAB_SET_OWORD_FIELD ( reg, FCN_RX_XOFF_EN, 0 );
2544 falcon_write ( efab, ®, FCN_RX_CFG_REG_KER );
2548 * Write dword to a Falcon MAC register
2551 static void falcon_gmac_writel ( struct efab_nic *efab,
2552 efab_dword_t *value, unsigned int mac_reg ) {
2555 EFAB_POPULATE_OWORD_1 ( temp, FCN_MAC_DATA,
2556 EFAB_DWORD_FIELD ( *value, FCN_MAC_DATA ) );
2557 falcon_write ( efab, &temp, FALCON_GMAC_REG ( efab, mac_reg ) );
2561 * Read dword from a Falcon GMAC register
2564 static void falcon_gmac_readl ( struct efab_nic *efab, efab_dword_t *value,
2565 unsigned int mac_reg ) {
2568 falcon_read ( efab, &temp, FALCON_GMAC_REG ( efab, mac_reg ) );
2569 EFAB_POPULATE_DWORD_1 ( *value, FCN_MAC_DATA,
2570 EFAB_OWORD_FIELD ( temp, FCN_MAC_DATA ) );
2574 * Write dword to a Falcon XMAC register
2577 static void falcon_xmac_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,
2584 FALCON_XMAC_REG ( efab, mac_reg ) );
2588 * Read dword from a Falcon XMAC register
2591 static void falcon_xmac_readl ( struct efab_nic *efab,
2592 efab_dword_t *value,
2593 unsigned int mac_reg ) {
2596 falcon_read ( efab, &temp,
2597 FALCON_XMAC_REG ( efab, mac_reg ) );
2598 EFAB_POPULATE_DWORD_1 ( *value, FCN_MAC_DATA,
2599 EFAB_OWORD_FIELD ( temp, FCN_MAC_DATA ) );
2606 static int falcon_init_gmac ( struct efab_nic *efab ) {
2607 static struct efab_mentormac_parameters falcon_mentormac_params = {
2608 .gmf_cfgfrth = 0x12,
2609 .gmf_cfgftth = 0x08,
2610 .gmf_cfghwmft = 0x1c,
2615 /* Initialise PHY */
2616 alaska_init ( efab );
2618 /* check the link is up */
2619 if ( !efab->link_up )
2622 /* Initialise MAC */
2623 mentormac_init ( efab, &falcon_mentormac_params );
2625 /* reconfigure the MAC wrapper */
2626 falcon_reconfigure_mac_wrapper ( efab );
2635 static int falcon_reset_gmac ( struct efab_nic *efab ) {
2636 mentormac_reset ( efab );
2641 * Reset XAUI/XGXS block
2644 static int falcon_reset_xaui ( struct efab_nic *efab )
2649 EFAB_POPULATE_DWORD_1 ( reg, FCN_XX_RST_XX_EN, 1 );
2650 efab->mac_op->mac_writel ( efab, ®, FCN_XX_PWR_RST_REG_MAC );
2652 for ( count = 0 ; count < 1000 ; count++ ) {
2654 efab->mac_op->mac_readl ( efab, ®,
2655 FCN_XX_PWR_RST_REG_MAC );
2656 if ( EFAB_DWORD_FIELD ( reg, FCN_XX_RST_XX_EN ) == 0 )
2660 /* an error of some kind */
2665 * Reset 10G MAC connected to port
2668 static int falcon_reset_xmac ( struct efab_nic *efab ) {
2672 EFAB_POPULATE_DWORD_1 ( reg, FCN_XM_CORE_RST, 1 );
2673 efab->mac_op->mac_writel ( efab, ®, FCN_XM_GLB_CFG_REG_MAC );
2675 for ( count = 0 ; count < 1000 ; count++ ) {
2677 efab->mac_op->mac_readl ( efab, ®,
2678 FCN_XM_GLB_CFG_REG_MAC );
2679 if ( EFAB_DWORD_FIELD ( reg, FCN_XM_CORE_RST ) == 0 )
2686 * Get status of 10G link
2689 static int falcon_xaui_link_ok ( struct efab_nic *efab ) {
2695 /* Read link status */
2696 efab->mac_op->mac_readl ( efab, ®, FCN_XX_CORE_STAT_REG_MAC );
2697 align_done = EFAB_DWORD_FIELD ( reg, FCN_XX_ALIGN_DONE );
2698 sync_status = EFAB_DWORD_FIELD ( reg, FCN_XX_SYNC_STAT );
2699 if ( align_done && ( sync_status == FCN_XX_SYNC_STAT_DECODE_SYNCED ) ) {
2703 /* Clear link status ready for next read */
2704 EFAB_SET_DWORD_FIELD ( reg, FCN_XX_COMMA_DET, FCN_XX_COMMA_DET_RESET );
2705 efab->mac_op->mac_writel ( efab, ®, FCN_XX_CORE_STAT_REG_MAC );
2714 static int falcon_init_xmac ( struct efab_nic *efab ) {
2718 if ( !falcon_reset_xmac ( efab ) ) {
2719 EFAB_ERR ( "failed resetting XMAC\n" );
2722 if ( !falcon_reset_xaui ( efab ) ) {
2723 EFAB_ERR ( "failed resetting XAUI\n");
2727 /* CX4 is always 10000FD only */
2728 efab->link_options = LPA_10000FULL;
2731 EFAB_POPULATE_DWORD_3 ( reg,
2732 FCN_XM_RX_JUMBO_MODE, 1,
2733 FCN_XM_TX_STAT_EN, 1,
2734 FCN_XM_RX_STAT_EN, 1);
2735 efab->mac_op->mac_writel ( efab, ®, FCN_XM_GLB_CFG_REG_MAC );
2738 EFAB_POPULATE_DWORD_6 ( reg,
2745 efab->mac_op->mac_writel ( efab, ®, FCN_XM_TX_CFG_REG_MAC );
2748 EFAB_POPULATE_DWORD_3 ( reg,
2750 FCN_XM_AUTO_DEPAD, 1,
2751 FCN_XM_PASS_CRC_ERR, 1 );
2752 efab->mac_op->mac_writel ( efab, ®, FCN_XM_RX_CFG_REG_MAC );
2754 /* Set frame length */
2755 EFAB_POPULATE_DWORD_1 ( reg,
2756 FCN_XM_MAX_RX_FRM_SIZE, ETH_FRAME_LEN );
2757 efab->mac_op->mac_writel ( efab, ®, FCN_XM_RX_PARAM_REG_MAC );
2758 EFAB_POPULATE_DWORD_2 ( reg,
2759 FCN_XM_MAX_TX_FRM_SIZE, ETH_FRAME_LEN,
2760 FCN_XM_TX_JUMBO_MODE, 1 );
2761 efab->mac_op->mac_writel ( efab, ®, FCN_XM_TX_PARAM_REG_MAC );
2763 /* Set MAC address */
2764 EFAB_POPULATE_DWORD_4 ( reg,
2765 FCN_XM_ADR_0, efab->mac_addr[0],
2766 FCN_XM_ADR_1, efab->mac_addr[1],
2767 FCN_XM_ADR_2, efab->mac_addr[2],
2768 FCN_XM_ADR_3, efab->mac_addr[3] );
2769 efab->mac_op->mac_writel ( efab, ®, FCN_XM_ADR_LO_REG_MAC );
2770 EFAB_POPULATE_DWORD_2 ( reg,
2771 FCN_XM_ADR_4, efab->mac_addr[4],
2772 FCN_XM_ADR_5, efab->mac_addr[5] );
2773 efab->mac_op->mac_writel ( efab, ®, FCN_XM_ADR_HI_REG_MAC );
2775 /* Reconfigure MAC wrapper */
2776 falcon_reconfigure_mac_wrapper ( efab );
2779 * Try resetting XAUI on its own waiting for the link
2782 for(count=0; count<5; count++) {
2783 /* Check link status */
2784 efab->link_up = falcon_xaui_link_ok ( efab );
2785 if ( efab->link_up ) {
2787 * Print out a speed message since we don't have a PHY
2789 EFAB_LOG ( "%dMbps %s-duplex\n",
2790 ( efab->link_options & LPA_10000 ? 1000 :
2791 ( efab->link_options & LPA_1000 ? 1000 :
2792 ( efab->link_options & LPA_100 ? 100 : 10 ) ) ),
2793 ( efab->link_options & LPA_DUPLEX ? "full" : "half" ) );
2797 if ( !falcon_reset_xaui ( efab ) ) {
2798 EFAB_ERR ( "failed resetting xaui\n" );
2808 * Wait for GMII access to complete
2811 static int falcon_gmii_wait ( struct efab_nic *efab ) {
2812 efab_oword_t md_stat;
2815 for ( count = 0 ; count < 1000 ; count++ ) {
2817 falcon_read ( efab, &md_stat, FCN_MD_STAT_REG_KER );
2818 if ( EFAB_OWORD_FIELD ( md_stat, FCN_MD_BSY ) == 0 )
2821 EFAB_ERR ( "Timed out waiting for GMII\n" );
2826 static struct efab_mac_operations falcon_xmac_operations = {
2827 .mac_readl = falcon_xmac_readl,
2828 .mac_writel = falcon_xmac_writel,
2829 .init = falcon_init_xmac,
2830 .reset = falcon_reset_xmac,
2833 static struct efab_mac_operations falcon_gmac_operations = {
2834 .mac_readl = falcon_gmac_readl,
2835 .mac_writel = falcon_gmac_writel,
2836 .init = falcon_init_gmac,
2837 .reset = falcon_reset_gmac,
2845 static int falcon_init_nic ( struct efab_nic *efab ) {
2847 efab_dword_t timer_cmd;
2850 /* use card in internal SRAM mode */
2851 falcon_read ( efab, ®, FCN_NIC_STAT_REG );
2852 EFAB_SET_OWORD_FIELD ( reg, ONCHIP_SRAM, 1 );
2853 falcon_write ( efab, ®, FCN_NIC_STAT_REG );
2856 /* identify FPGA/ASIC, and strapping mode */
2857 falcon_read ( efab, ®, ALTERA_BUILD_REG_KER );
2858 version = EFAB_OWORD_FIELD ( reg, VER_ALL );
2859 efab->is_asic = version ? 0 : 1;
2861 if ( efab->is_asic ) {
2862 falcon_read ( efab, ®, FCN_NIC_STAT_REG );
2863 if ( EFAB_OWORD_FIELD ( reg, STRAP_10G ) ) {
2866 if ( EFAB_OWORD_FIELD ( reg, STRAP_DUAL_PORT ) ) {
2871 falcon_read ( efab, ®, ALTERA_BUILD_REG_KER );
2872 minor = EFAB_OWORD_FIELD ( reg, VER_MINOR );
2874 if ( minor == 0x14 ) {
2876 } else if ( minor == 0x13 ) {
2881 DBG ( "NIC type: %s %dx%s\n",
2882 efab->is_asic ? "ASIC" : "FPGA",
2883 efab->is_dual ? 2 : 1,
2884 efab->is_10g ? "10G" : "1G" );
2886 /* patch in MAC operations */
2888 efab->mac_op = &falcon_xmac_operations;
2890 efab->mac_op = &falcon_gmac_operations;
2892 if ( !efab->is_dual && ( efab->port == 1 ) ) {
2893 /* device doesn't exist */
2897 /* determine EEPROM / FLASH */
2898 if ( efab->is_asic ) {
2899 falcon_read ( efab, ®, FCN_NIC_STAT_REG );
2900 efab->has_flash = EFAB_OWORD_FIELD ( reg, SF_PRST );
2901 efab->has_eeprom = EFAB_OWORD_FIELD ( reg, EE_PRST );
2903 falcon_read ( efab, ®, FCN_GPIO_CTL_REG_KER );
2904 efab->has_flash = EFAB_OWORD_FIELD ( reg, FCN_FLASH_PRESENT );
2905 efab->has_eeprom = EFAB_OWORD_FIELD ( reg, FCN_EEPROM_PRESENT);
2907 DBG ( "flash is %s, EEPROM is %s\n",
2908 ( efab->has_flash ? "present" : "absent" ),
2909 ( efab->has_eeprom ? "present" : "absent" ) );
2910 falcon_init_spi ( efab );
2912 /* Set up TX and RX descriptor caches in SRAM */
2913 EFAB_POPULATE_OWORD_1 ( reg, FCN_SRM_TX_DC_BASE_ADR,
2914 0x130000 /* recommended in datasheet */ );
2915 falcon_write ( efab, ®, FCN_SRM_TX_DC_CFG_REG_KER );
2916 EFAB_POPULATE_OWORD_1 ( reg, FCN_TX_DC_SIZE, 2 /* 32 descriptors */ );
2917 falcon_write ( efab, ®, FCN_TX_DC_CFG_REG_KER );
2918 EFAB_POPULATE_OWORD_1 ( reg, FCN_SRM_RX_DC_BASE_ADR,
2919 0x100000 /* recommended in datasheet */ );
2920 falcon_write ( efab, ®, FCN_SRM_RX_DC_CFG_REG_KER );
2921 EFAB_POPULATE_OWORD_1 ( reg, FCN_RX_DC_SIZE, 2 /* 32 descriptors */ );
2922 falcon_write ( efab, ®, FCN_RX_DC_CFG_REG_KER );
2924 /* Set number of RSS CPUs */
2925 EFAB_POPULATE_OWORD_1 ( reg, FCN_NUM_KER, 0 );
2926 falcon_write ( efab, ®, FCN_RX_FILTER_CTL_REG_KER );
2930 mentormac_reset ( efab );
2932 /* Set up event queue */
2933 falcon_create_special_buffer ( efab, efab->eventq, FALCON_EVQ_ID );
2934 /* Fill eventq with all ones ( empty events ) */
2935 memset(efab->eventq, 0xff, 4096);
2936 /* push eventq to card */
2937 EFAB_POPULATE_OWORD_3 ( reg,
2939 FCN_EVQ_SIZE, FCN_EVQ_SIZE_512,
2940 FCN_EVQ_BUF_BASE_ID, FALCON_EVQ_ID );
2941 falcon_write ( efab, ®, FCN_EVQ_PTR_TBL_KER );
2944 /* Set timer register */
2945 EFAB_POPULATE_DWORD_2 ( timer_cmd,
2946 FCN_TIMER_MODE, FCN_TIMER_MODE_DIS,
2948 falcon_writel ( efab, &timer_cmd, FCN_TIMER_CMD_REG_KER );
2951 /* Initialise event queue read pointer */
2952 falcon_eventq_read_ack ( efab );
2954 /* Set up TX descriptor ring */
2955 falcon_create_special_buffer ( efab, efab->txd, FALCON_TXD_ID );
2956 EFAB_POPULATE_OWORD_5 ( reg,
2958 FCN_TX_DESCQ_BUF_BASE_ID, FALCON_TXD_ID,
2959 FCN_TX_DESCQ_EVQ_ID, 0,
2960 FCN_TX_DESCQ_SIZE, FCN_TX_DESCQ_SIZE_512,
2961 FCN_TX_DESCQ_TYPE, 0 /* kernel queue */ );
2962 falcon_write ( efab, ®, FCN_TX_DESC_PTR_TBL_KER );
2964 /* Set up RX descriptor ring */
2965 falcon_create_special_buffer ( efab, efab->rxd, FALCON_RXD_ID );
2966 EFAB_POPULATE_OWORD_6 ( reg,
2967 FCN_RX_DESCQ_BUF_BASE_ID, FALCON_RXD_ID,
2968 FCN_RX_DESCQ_EVQ_ID, 0,
2969 FCN_RX_DESCQ_SIZE, FCN_RX_DESCQ_SIZE_512,
2970 FCN_RX_DESCQ_TYPE, 0 /* kernel queue */,
2971 FCN_RX_DESCQ_JUMBO, 1,
2972 FCN_RX_DESCQ_EN, 1 );
2973 falcon_write ( efab, ®, FCN_RX_DESC_PTR_TBL_KER );
2975 /* Program INT_ADR_REG_KER */
2976 EFAB_POPULATE_OWORD_1 ( reg,
2978 virt_to_bus ( &efab->int_ker ) );
2979 falcon_write ( efab, ®, FCN_INT_ADR_REG_KER );
2982 /* Register non-volatile storage */
2983 if ( efab->has_eeprom ) {
2984 efab->nvo.nvs = &efab->falcon_eeprom.nvs;
2985 efab->nvo.fragments = falcon_eeprom_fragments;
2986 if ( nvo_register ( &efab->nvo ) != 0 )
2994 static void falcon_mdio_write ( struct efab_nic *efab, int location,
2996 int phy_id = efab->port + 2;
2999 EFAB_TRACE ( "Writing GMII %d register %02x with %04x\n",
3000 phy_id, location, value );
3002 /* Check MII not currently being accessed */
3003 if ( ! falcon_gmii_wait ( efab ) )
3006 /* Write the address registers */
3007 EFAB_POPULATE_OWORD_1 ( reg, FCN_MD_PHY_ADR, 0 /* phy_id ? */ );
3008 falcon_write ( efab, ®, FCN_MD_PHY_ADR_REG_KER );
3010 EFAB_POPULATE_OWORD_2 ( reg,
3011 FCN_MD_PRT_ADR, phy_id,
3012 FCN_MD_DEV_ADR, location );
3013 falcon_write ( efab, ®, FCN_MD_ID_REG_KER );
3017 EFAB_POPULATE_OWORD_1 ( reg, FCN_MD_TXD, value );
3018 falcon_write ( efab, ®, FCN_MD_TXD_REG_KER );
3020 EFAB_POPULATE_OWORD_2 ( reg,
3023 falcon_write ( efab, ®, FCN_MD_CS_REG_KER );
3026 /* Wait for data to be written */
3027 falcon_gmii_wait ( efab );
3031 static int falcon_mdio_read ( struct efab_nic *efab, int location ) {
3032 int phy_id = efab->port + 2;
3036 /* Check MII not currently being accessed */
3037 if ( ! falcon_gmii_wait ( efab ) )
3040 /* Write the address registers */
3041 EFAB_POPULATE_OWORD_1 ( reg, FCN_MD_PHY_ADR, 0 /* phy_id ? */ );
3042 falcon_write ( efab, ®, FCN_MD_PHY_ADR_REG_KER );
3044 EFAB_POPULATE_OWORD_2 ( reg,
3045 FCN_MD_PRT_ADR, phy_id,
3046 FCN_MD_DEV_ADR, location );
3047 falcon_write ( efab, ®, FCN_MD_ID_REG_KER );
3050 /* Request data to be read */
3051 EFAB_POPULATE_OWORD_2 ( reg,
3054 falcon_write ( efab, ®, FCN_MD_CS_REG_KER );
3057 /* Wait for data to become available */
3058 falcon_gmii_wait ( efab );
3061 falcon_read ( efab, ®, FCN_MD_RXD_REG_KER );
3062 value = EFAB_OWORD_FIELD ( reg, FCN_MD_RXD );
3064 EFAB_TRACE ( "Read from GMII %d register %02x, got %04x\n",
3065 phy_id, location, value );
3070 static struct efab_operations falcon_operations = {
3071 .get_membase = falcon_get_membase,
3072 .reset = falcon_reset,
3073 .init_nic = falcon_init_nic,
3074 .read_eeprom = falcon_read_eeprom,
3075 .build_rx_desc = falcon_build_rx_desc,
3076 .notify_rx_desc = falcon_notify_rx_desc,
3077 .build_tx_desc = falcon_build_tx_desc,
3078 .notify_tx_desc = falcon_notify_tx_desc,
3079 .fetch_event = falcon_fetch_event,
3080 .mask_irq = falcon_mask_irq,
3081 .generate_irq = falcon_generate_irq,
3082 .mdio_write = falcon_mdio_write,
3083 .mdio_read = falcon_mdio_read,
3086 /**************************************************************************
3088 * Etherfabric abstraction layer
3090 **************************************************************************
3094 * Push RX buffer to RXD ring
3097 static inline void efab_push_rx_buffer ( struct efab_nic *efab,
3098 struct efab_rx_buf *rx_buf ) {
3099 /* Create RX descriptor */
3100 rx_buf->id = efab->rx_write_ptr;
3101 efab->op->build_rx_desc ( efab, rx_buf );
3103 /* Update RX write pointer */
3104 efab->rx_write_ptr = ( efab->rx_write_ptr + 1 ) % EFAB_RXD_SIZE;
3105 efab->op->notify_rx_desc ( efab );
3107 DBG ( "Added RX id %x\n", rx_buf->id );
3111 * Push TX buffer to TXD ring
3114 static inline void efab_push_tx_buffer ( struct efab_nic *efab,
3115 struct efab_tx_buf *tx_buf ) {
3116 /* Create TX descriptor */
3117 tx_buf->id = efab->tx_write_ptr;
3118 efab->op->build_tx_desc ( efab, tx_buf );
3120 /* Update TX write pointer */
3121 efab->tx_write_ptr = ( efab->tx_write_ptr + 1 ) % EFAB_TXD_SIZE;
3122 efab->op->notify_tx_desc ( efab );
3124 DBG ( "Added TX id %x\n", tx_buf->id );
3128 * Initialise MAC and wait for link up
3131 static int efab_init_mac ( struct efab_nic *efab ) {
3134 /* This can take several seconds */
3135 EFAB_LOG ( "Waiting for link.." );
3136 for ( count=0; count<5; count++ ) {
3139 if ( ! efab->mac_op->init ( efab ) ) {
3140 EFAB_ERR ( "Failed reinitialising MAC\n" );
3143 if ( efab->link_up ) {
3144 /* PHY init printed the message for us */
3147 EFAB_ERR( "link is down" );
3150 EFAB_ERR ( " timed initialising MAC\n " );
3159 static int efab_init_nic ( struct efab_nic *efab ) {
3162 /* Initialise NIC */
3163 if ( ! efab->op->init_nic ( efab ) )
3166 /* Push RX descriptors */
3167 for ( i = 0 ; i < EFAB_RX_BUFS ; i++ ) {
3168 efab_push_rx_buffer ( efab, &efab->rx_bufs[i] );
3171 /* Read MAC address from EEPROM */
3172 if ( ! efab->op->read_eeprom ( efab ) )
3174 efab->mac_addr[ETH_ALEN-1] += efab->port;
3176 /* Initialise MAC and wait for link up */
3177 if ( ! efab_init_mac ( efab ) )
3183 /**************************************************************************
3185 * Etherboot interface
3187 **************************************************************************
3190 /**************************************************************************
3191 POLL - Wait for a frame
3192 ***************************************************************************/
3193 static int etherfabric_poll ( struct nic *nic, int retrieve ) {
3194 struct efab_nic *efab = nic->priv_data;
3195 struct efab_event event;
3196 static struct efab_rx_buf *rx_buf = NULL;
3199 /* Process the event queue until we hit either a packet
3200 * received event or an empty event slot.
3202 while ( ( rx_buf == NULL ) &&
3203 efab->op->fetch_event ( efab, &event ) ) {
3205 if ( event.type == EFAB_EV_TX ) {
3206 /* TX completed - mark as done */
3207 DBG ( "TX id %x complete\n",
3209 } else if ( event.type == EFAB_EV_RX ) {
3210 /* RX - find corresponding buffer */
3211 for ( i = 0 ; i < EFAB_RX_BUFS ; i++ ) {
3212 if ( efab->rx_bufs[i].id == event.rx_id ) {
3213 rx_buf = &efab->rx_bufs[i];
3214 rx_buf->len = event.rx_len;
3215 DBG ( "RX id %x (len %x) received\n",
3216 rx_buf->id, rx_buf->len );
3221 EFAB_ERR ( "Invalid RX ID %x\n", event.rx_id );
3223 } else if ( event.type == EFAB_EV_NONE ) {
3224 DBG ( "Ignorable event\n" );
3226 DBG ( "Unknown event\n" );
3230 /* If there is no packet, return 0 */
3234 /* drop this event if necessary */
3236 DBG( "discarding RX event\n" );
3240 /* If we don't want to retrieve it just yet, return 1 */
3244 /* There seems to be a hardware race. The event can show up
3245 * on the event FIFO before the DMA has completed, so we
3246 * insert a tiny delay. If this proves unreliable, we should
3247 * switch to using event DMA rather than the event FIFO, since
3248 * event DMA ordering is guaranteed.
3252 /* Copy packet contents */
3253 nic->packetlen = rx_buf->len;
3254 memcpy ( nic->packet, rx_buf->addr, nic->packetlen );
3256 /* Give this buffer back to the NIC */
3257 efab_push_rx_buffer ( efab, rx_buf );
3259 /* Prepare to receive next packet */
3265 /**************************************************************************
3266 TRANSMIT - Transmit a frame
3267 ***************************************************************************/
3268 static void etherfabric_transmit ( struct nic *nic, const char *dest,
3269 unsigned int type, unsigned int size,
3270 const char *data ) {
3271 struct efab_nic *efab = nic->priv_data;
3272 unsigned int nstype = htons ( type );
3274 /* Fill TX buffer, pad to ETH_ZLEN */
3275 memcpy ( efab->tx_buf.addr, dest, ETH_ALEN );
3276 memcpy ( efab->tx_buf.addr + ETH_ALEN, nic->node_addr, ETH_ALEN );
3277 memcpy ( efab->tx_buf.addr + 2 * ETH_ALEN, &nstype, 2 );
3278 memcpy ( efab->tx_buf.addr + ETH_HLEN, data, size );
3280 while ( size < ETH_ZLEN ) {
3281 efab->tx_buf.addr[size++] = '\0';
3283 efab->tx_buf.len = size;
3285 /* Push TX descriptor */
3286 efab_push_tx_buffer ( efab, &efab->tx_buf );
3288 /* Allow enough time for the packet to be transmitted. This
3289 * is a temporary hack until we update to the new driver API.
3296 /**************************************************************************
3297 DISABLE - Turn off ethernet interface
3298 ***************************************************************************/
3299 static void etherfabric_disable ( struct nic *nic ) {
3300 struct efab_nic *efab = nic->priv_data;
3302 efab->op->reset ( efab );
3303 if ( efab->membase )
3304 iounmap ( efab->membase );
3307 /**************************************************************************
3308 IRQ - handle interrupts
3309 ***************************************************************************/
3310 static void etherfabric_irq ( struct nic *nic, irq_action_t action ) {
3311 struct efab_nic *efab = nic->priv_data;
3315 efab->op->mask_irq ( efab, 1 );
3318 efab->op->mask_irq ( efab, 0 );
3321 /* Force NIC to generate a receive interrupt */
3322 efab->op->generate_irq ( efab );
3329 static struct nic_operations etherfabric_operations = {
3330 .connect = dummy_connect,
3331 .poll = etherfabric_poll,
3332 .transmit = etherfabric_transmit,
3333 .irq = etherfabric_irq,
3336 /**************************************************************************
3337 PROBE - Look for an adapter, this routine's visible to the outside
3338 ***************************************************************************/
3339 static int etherfabric_probe ( struct nic *nic, struct pci_device *pci ) {
3340 static struct efab_nic efab;
3341 static int nic_port = 0;
3342 struct efab_buffers *buffers;
3345 /* Set up our private data structure */
3346 nic->priv_data = &efab;
3347 memset ( &efab, 0, sizeof ( efab ) );
3348 memset ( &efab_buffers, 0, sizeof ( efab_buffers ) );
3350 /* Hook in appropriate operations table. Do this early. */
3351 if ( pci->device == EF1002_DEVID ) {
3352 efab.op = &ef1002_operations;
3354 efab.op = &falcon_operations;
3357 /* Initialise efab data structure */
3359 buffers = ( ( struct efab_buffers * )
3360 ( ( ( void * ) &efab_buffers ) +
3361 ( - virt_to_bus ( &efab_buffers ) ) % EFAB_BUF_ALIGN ) );
3362 efab.eventq = buffers->eventq;
3363 efab.txd = buffers->txd;
3364 efab.rxd = buffers->rxd;
3365 efab.tx_buf.addr = buffers->tx_buf;
3366 for ( i = 0 ; i < EFAB_RX_BUFS ; i++ ) {
3367 efab.rx_bufs[i].addr = buffers->rx_buf[i];
3370 /* Enable the PCI device */
3371 adjust_pci_device ( pci );
3372 nic->ioaddr = pci->ioaddr & ~3;
3373 nic->irqno = pci->irq;
3375 /* Get iobase/membase */
3376 efab.iobase = nic->ioaddr;
3377 efab.op->get_membase ( &efab );
3379 /* Switch NIC ports (i.e. try different ports on each probe) */
3380 nic_port = 1 - nic_port;
3381 efab.port = nic_port;
3383 /* Initialise hardware */
3384 if ( ! efab_init_nic ( &efab ) )
3386 memcpy ( nic->node_addr, efab.mac_addr, ETH_ALEN );
3388 /* point to NIC specific routines */
3389 nic->nic_op = ðerfabric_operations;
3394 static struct pci_device_id etherfabric_nics[] = {
3395 PCI_ROM(0x1924, 0xC101, "ef1002", "EtherFabric EF1002"),
3396 PCI_ROM(0x1924, 0x0703, "falcon", "EtherFabric Falcon"),
3399 PCI_DRIVER ( etherfabric_driver, etherfabric_nics, PCI_NO_CLASS );
3401 DRIVER ( "EFAB", nic_driver, pci_driver, etherfabric_driver,
3402 etherfabric_probe, etherfabric_disable );