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"
22 #include <gpxe/bitbash.h>
25 #define dma_addr_t unsigned long
26 #include "etherfabric.h"
28 /**************************************************************************
30 * Constants and macros
32 **************************************************************************
35 #define EFAB_ASSERT(x) \
38 DBG ( "ASSERT(%s) failed at %s line %d [%s]\n", #x, \
39 __FILE__, __LINE__, __FUNCTION__ ); \
43 #define EFAB_TRACE(...) DBG ( __VA_ARGS__ )
45 #define EFAB_REGDUMP(...)
47 #define EFAB_LOG(...) printf ( __VA_ARGS__ )
48 #define EFAB_ERR(...) printf ( __VA_ARGS__ )
50 #define FALCON_USE_IO_BAR 1
53 * EtherFabric constants
58 #define EFAB_VENDID_LEVEL5 0x1924
59 #define FALCON_P_DEVID 0x0703 /* Temporary PCI ID */
60 #define EF1002_DEVID 0xC101
62 /**************************************************************************
66 **************************************************************************
70 * Buffers used for TX, RX and event queue
73 #define EFAB_BUF_ALIGN 4096
74 #define EFAB_DATA_BUF_SIZE 2048
75 #define EFAB_RX_BUFS 16
76 #define EFAB_RXD_SIZE 512
77 #define EFAB_TXD_SIZE 512
78 #define EFAB_EVQ_SIZE 512
83 uint8_t tx_buf[EFAB_DATA_BUF_SIZE];
84 uint8_t rx_buf[EFAB_RX_BUFS][EFAB_DATA_BUF_SIZE];
85 uint8_t padding[EFAB_BUF_ALIGN-1];
87 static struct efab_buffers efab_buffers;
103 /** Etherfabric event type */
104 enum efab_event_type {
110 /** Etherfabric event */
113 enum efab_event_type type;
118 /** Packet should be dropped */
123 * Etherfabric abstraction layer
127 struct efab_operations {
128 void ( * get_membase ) ( struct efab_nic *efab );
129 int ( * reset ) ( struct efab_nic *efab );
130 int ( * init_nic ) ( struct efab_nic *efab );
131 int ( * read_eeprom ) ( struct efab_nic *efab );
132 void ( * build_rx_desc ) ( struct efab_nic *efab,
133 struct efab_rx_buf *rx_buf );
134 void ( * notify_rx_desc ) ( struct efab_nic *efab );
135 void ( * build_tx_desc ) ( struct efab_nic *efab,
136 struct efab_tx_buf *tx_buf );
137 void ( * notify_tx_desc ) ( struct efab_nic *efab );
138 int ( * fetch_event ) ( struct efab_nic *efab,
139 struct efab_event *event );
140 void ( * mask_irq ) ( struct efab_nic *efab, int enabled );
141 void ( * generate_irq ) ( struct efab_nic *efab );
142 void ( * mdio_write ) ( struct efab_nic *efab, int location,
144 int ( * mdio_read ) ( struct efab_nic *efab, int location );
147 struct efab_mac_operations {
148 void ( * mac_writel ) ( struct efab_nic *efab, efab_dword_t *value,
149 unsigned int mac_reg );
150 void ( * mac_readl ) ( struct efab_nic *efab, efab_dword_t *value,
151 unsigned int mac_reg );
152 int ( * init ) ( struct efab_nic *efab );
153 int ( * reset ) ( struct efab_nic *efab );
157 * Driver private data structure
163 struct pci_device *pci;
165 /** Operations table */
166 struct efab_operations *op;
168 /** MAC operations table */
169 struct efab_mac_operations *mac_op;
178 uint8_t *eventq; /* Falcon only */
179 uint8_t *txd; /* Falcon only */
180 uint8_t *rxd; /* Falcon only */
181 struct efab_tx_buf tx_buf;
182 struct efab_rx_buf rx_bufs[EFAB_RX_BUFS];
184 /** Buffer pointers */
185 unsigned int eventq_read_ptr; /* Falcon only */
186 unsigned int tx_write_ptr;
187 unsigned int rx_write_ptr;
189 /** Port 0/1 on the NIC */
193 uint8_t mac_addr[ETH_ALEN];
194 /** GMII link options */
195 unsigned int link_options;
199 /* Nic type fields */
206 /** INT_REG_KER for Falcon */
207 efab_oword_t int_ker __attribute__ (( aligned ( 16 ) ));
210 struct i2c_bit_basher ef1002_i2c;
211 unsigned long ef1002_i2c_outputs;
212 struct i2c_device ef1002_eeprom;
215 /**************************************************************************
219 **************************************************************************
223 #define MII_BMSR 0x01 /* Basic mode status register */
224 #define MII_ADVERTISE 0x04 /* Advertisement control register */
225 #define MII_LPA 0x05 /* Link partner ability register*/
226 #define GMII_GTCR 0x09 /* 1000BASE-T control register */
227 #define GMII_GTSR 0x0a /* 1000BASE-T status register */
228 #define GMII_PSSR 0x11 /* PHY-specific status register */
230 /* Basic mode status register. */
231 #define BMSR_LSTATUS 0x0004 /* Link status */
233 /* Link partner ability register. */
234 #define LPA_10HALF 0x0020 /* Can do 10mbps half-duplex */
235 #define LPA_10FULL 0x0040 /* Can do 10mbps full-duplex */
236 #define LPA_100HALF 0x0080 /* Can do 100mbps half-duplex */
237 #define LPA_100FULL 0x0100 /* Can do 100mbps full-duplex */
238 #define LPA_100BASE4 0x0200 /* Can do 100mbps 4k packets */
239 #define LPA_PAUSE 0x0400 /* Bit 10 - MAC pause */
241 /* Pseudo extensions to the link partner ability register */
242 #define LPA_1000FULL 0x00020000
243 #define LPA_1000HALF 0x00010000
244 #define LPA_10000FULL 0x00040000
245 #define LPA_10000HALF 0x00080000
247 #define LPA_100 (LPA_100FULL | LPA_100HALF | LPA_100BASE4)
248 #define LPA_1000 ( LPA_1000FULL | LPA_1000HALF )
249 #define LPA_10000 ( LPA_10000FULL | LPA_10000HALF )
250 #define LPA_DUPLEX ( LPA_10FULL | LPA_100FULL | LPA_1000FULL )
252 /* Mask of bits not associated with speed or duplexity. */
253 #define LPA_OTHER ~( LPA_10FULL | LPA_10HALF | LPA_100FULL | \
254 LPA_100HALF | LPA_1000FULL | LPA_1000HALF )
256 /* PHY-specific status register */
257 #define PSSR_LSTATUS 0x0400 /* Bit 10 - link status */
260 * Retrieve GMII autonegotiation advertised abilities
263 static unsigned int gmii_autoneg_advertised ( struct efab_nic *efab ) {
264 unsigned int mii_advertise;
265 unsigned int gmii_advertise;
267 /* Extended bits are in bits 8 and 9 of GMII_GTCR */
268 mii_advertise = efab->op->mdio_read ( efab, MII_ADVERTISE );
269 gmii_advertise = ( ( efab->op->mdio_read ( efab, GMII_GTCR ) >> 8 )
271 return ( ( gmii_advertise << 16 ) | mii_advertise );
275 * Retrieve GMII autonegotiation link partner abilities
278 static unsigned int gmii_autoneg_lpa ( struct efab_nic *efab ) {
279 unsigned int mii_lpa;
280 unsigned int gmii_lpa;
282 /* Extended bits are in bits 10 and 11 of GMII_GTSR */
283 mii_lpa = efab->op->mdio_read ( efab, MII_LPA );
284 gmii_lpa = ( efab->op->mdio_read ( efab, GMII_GTSR ) >> 10 ) & 0x03;
285 return ( ( gmii_lpa << 16 ) | mii_lpa );
289 * Calculate GMII autonegotiated link technology
292 static unsigned int gmii_nway_result ( unsigned int negotiated ) {
293 unsigned int other_bits;
295 /* Mask out the speed and duplexity bits */
296 other_bits = negotiated & LPA_OTHER;
298 if ( negotiated & LPA_1000FULL )
299 return ( other_bits | LPA_1000FULL );
300 else if ( negotiated & LPA_1000HALF )
301 return ( other_bits | LPA_1000HALF );
302 else if ( negotiated & LPA_100FULL )
303 return ( other_bits | LPA_100FULL );
304 else if ( negotiated & LPA_100BASE4 )
305 return ( other_bits | LPA_100BASE4 );
306 else if ( negotiated & LPA_100HALF )
307 return ( other_bits | LPA_100HALF );
308 else if ( negotiated & LPA_10FULL )
309 return ( other_bits | LPA_10FULL );
310 else return ( other_bits | LPA_10HALF );
314 * Check GMII PHY link status
317 static int gmii_link_ok ( struct efab_nic *efab ) {
321 /* BMSR is latching - it returns "link down" if the link has
322 * been down at any point since the last read. To get a
323 * real-time status, we therefore read the register twice and
324 * use the result of the second read.
326 efab->op->mdio_read ( efab, MII_BMSR );
327 status = efab->op->mdio_read ( efab, MII_BMSR );
329 /* Read the PHY-specific Status Register. This is
330 * non-latching, so we need do only a single read.
332 phy_status = efab->op->mdio_read ( efab, GMII_PSSR );
334 return ( ( status & BMSR_LSTATUS ) && ( phy_status & PSSR_LSTATUS ) );
337 /**************************************************************************
341 **************************************************************************
345 * Initialise Alaska PHY
348 static void alaska_init ( struct efab_nic *efab ) {
349 unsigned int advertised, lpa;
351 /* Read link up status */
352 efab->link_up = gmii_link_ok ( efab );
354 if ( ! efab->link_up )
357 /* Determine link options from PHY. */
358 advertised = gmii_autoneg_advertised ( efab );
359 lpa = gmii_autoneg_lpa ( efab );
360 efab->link_options = gmii_nway_result ( advertised & lpa );
362 /* print out the link speed */
363 EFAB_LOG ( "%dMbps %s-duplex (%04x,%04x)\n",
364 ( efab->link_options & LPA_10000 ? 1000 :
365 ( efab->link_options & LPA_1000 ? 1000 :
366 ( efab->link_options & LPA_100 ? 100 : 10 ) ) ),
367 ( efab->link_options & LPA_DUPLEX ? "full" : "half" ),
372 /**************************************************************************
376 **************************************************************************
379 /* GMAC configuration register 1 */
380 #define GM_CFG1_REG_MAC 0x00
381 #define GM_SW_RST_LBN 31
382 #define GM_SW_RST_WIDTH 1
383 #define GM_RX_FC_EN_LBN 5
384 #define GM_RX_FC_EN_WIDTH 1
385 #define GM_TX_FC_EN_LBN 4
386 #define GM_TX_FC_EN_WIDTH 1
387 #define GM_RX_EN_LBN 2
388 #define GM_RX_EN_WIDTH 1
389 #define GM_TX_EN_LBN 0
390 #define GM_TX_EN_WIDTH 1
392 /* GMAC configuration register 2 */
393 #define GM_CFG2_REG_MAC 0x01
394 #define GM_PAMBL_LEN_LBN 12
395 #define GM_PAMBL_LEN_WIDTH 4
396 #define GM_IF_MODE_LBN 8
397 #define GM_IF_MODE_WIDTH 2
398 #define GM_PAD_CRC_EN_LBN 2
399 #define GM_PAD_CRC_EN_WIDTH 1
401 #define GM_FD_WIDTH 1
403 /* GMAC maximum frame length register */
404 #define GM_MAX_FLEN_REG_MAC 0x04
405 #define GM_MAX_FLEN_LBN 0
406 #define GM_MAX_FLEN_WIDTH 16
408 /* GMAC MII management configuration register */
409 #define GM_MII_MGMT_CFG_REG_MAC 0x08
410 #define GM_MGMT_CLK_SEL_LBN 0
411 #define GM_MGMT_CLK_SEL_WIDTH 3
413 /* GMAC MII management command register */
414 #define GM_MII_MGMT_CMD_REG_MAC 0x09
415 #define GM_MGMT_SCAN_CYC_LBN 1
416 #define GM_MGMT_SCAN_CYC_WIDTH 1
417 #define GM_MGMT_RD_CYC_LBN 0
418 #define GM_MGMT_RD_CYC_WIDTH 1
420 /* GMAC MII management address register */
421 #define GM_MII_MGMT_ADR_REG_MAC 0x0a
422 #define GM_MGMT_PHY_ADDR_LBN 8
423 #define GM_MGMT_PHY_ADDR_WIDTH 5
424 #define GM_MGMT_REG_ADDR_LBN 0
425 #define GM_MGMT_REG_ADDR_WIDTH 5
427 /* GMAC MII management control register */
428 #define GM_MII_MGMT_CTL_REG_MAC 0x0b
429 #define GM_MGMT_CTL_LBN 0
430 #define GM_MGMT_CTL_WIDTH 16
432 /* GMAC MII management status register */
433 #define GM_MII_MGMT_STAT_REG_MAC 0x0c
434 #define GM_MGMT_STAT_LBN 0
435 #define GM_MGMT_STAT_WIDTH 16
437 /* GMAC MII management indicators register */
438 #define GM_MII_MGMT_IND_REG_MAC 0x0d
439 #define GM_MGMT_BUSY_LBN 0
440 #define GM_MGMT_BUSY_WIDTH 1
442 /* GMAC station address register 1 */
443 #define GM_ADR1_REG_MAC 0x10
444 #define GM_HWADDR_5_LBN 24
445 #define GM_HWADDR_5_WIDTH 8
446 #define GM_HWADDR_4_LBN 16
447 #define GM_HWADDR_4_WIDTH 8
448 #define GM_HWADDR_3_LBN 8
449 #define GM_HWADDR_3_WIDTH 8
450 #define GM_HWADDR_2_LBN 0
451 #define GM_HWADDR_2_WIDTH 8
453 /* GMAC station address register 2 */
454 #define GM_ADR2_REG_MAC 0x11
455 #define GM_HWADDR_1_LBN 24
456 #define GM_HWADDR_1_WIDTH 8
457 #define GM_HWADDR_0_LBN 16
458 #define GM_HWADDR_0_WIDTH 8
460 /* GMAC FIFO configuration register 0 */
461 #define GMF_CFG0_REG_MAC 0x12
462 #define GMF_FTFENREQ_LBN 12
463 #define GMF_FTFENREQ_WIDTH 1
464 #define GMF_STFENREQ_LBN 11
465 #define GMF_STFENREQ_WIDTH 1
466 #define GMF_FRFENREQ_LBN 10
467 #define GMF_FRFENREQ_WIDTH 1
468 #define GMF_SRFENREQ_LBN 9
469 #define GMF_SRFENREQ_WIDTH 1
470 #define GMF_WTMENREQ_LBN 8
471 #define GMF_WTMENREQ_WIDTH 1
473 /* GMAC FIFO configuration register 1 */
474 #define GMF_CFG1_REG_MAC 0x13
475 #define GMF_CFGFRTH_LBN 16
476 #define GMF_CFGFRTH_WIDTH 5
477 #define GMF_CFGXOFFRTX_LBN 0
478 #define GMF_CFGXOFFRTX_WIDTH 16
480 /* GMAC FIFO configuration register 2 */
481 #define GMF_CFG2_REG_MAC 0x14
482 #define GMF_CFGHWM_LBN 16
483 #define GMF_CFGHWM_WIDTH 6
484 #define GMF_CFGLWM_LBN 0
485 #define GMF_CFGLWM_WIDTH 6
487 /* GMAC FIFO configuration register 3 */
488 #define GMF_CFG3_REG_MAC 0x15
489 #define GMF_CFGHWMFT_LBN 16
490 #define GMF_CFGHWMFT_WIDTH 6
491 #define GMF_CFGFTTH_LBN 0
492 #define GMF_CFGFTTH_WIDTH 6
494 /* GMAC FIFO configuration register 4 */
495 #define GMF_CFG4_REG_MAC 0x16
496 #define GMF_HSTFLTRFRM_PAUSE_LBN 12
497 #define GMF_HSTFLTRFRM_PAUSE_WIDTH 12
499 /* GMAC FIFO configuration register 5 */
500 #define GMF_CFG5_REG_MAC 0x17
501 #define GMF_CFGHDPLX_LBN 22
502 #define GMF_CFGHDPLX_WIDTH 1
503 #define GMF_CFGBYTMODE_LBN 19
504 #define GMF_CFGBYTMODE_WIDTH 1
505 #define GMF_HSTDRPLT64_LBN 18
506 #define GMF_HSTDRPLT64_WIDTH 1
507 #define GMF_HSTFLTRFRMDC_PAUSE_LBN 12
508 #define GMF_HSTFLTRFRMDC_PAUSE_WIDTH 1
510 struct efab_mentormac_parameters {
522 static void mentormac_reset ( struct efab_nic *efab ) {
526 /* Take into reset */
527 EFAB_POPULATE_DWORD_1 ( reg, GM_SW_RST, 1 );
528 efab->mac_op->mac_writel ( efab, ®, GM_CFG1_REG_MAC );
531 /* Take out of reset */
532 EFAB_POPULATE_DWORD_1 ( reg, GM_SW_RST, 0 );
533 efab->mac_op->mac_writel ( efab, ®, GM_CFG1_REG_MAC );
536 /* Mentor MAC connects both PHYs to MAC 0 */
537 save_port = efab->port;
539 /* Configure GMII interface so PHY is accessible. Note that
540 * GMII interface is connected only to port 0, and that on
541 * Falcon this is a no-op.
543 EFAB_POPULATE_DWORD_1 ( reg, GM_MGMT_CLK_SEL, 0x4 );
544 efab->mac_op->mac_writel ( efab, ®, GM_MII_MGMT_CFG_REG_MAC );
546 efab->port = save_port;
550 * Initialise Mentor MAC
553 static void mentormac_init ( struct efab_nic *efab,
554 struct efab_mentormac_parameters *params ) {
555 int pause, if_mode, full_duplex, bytemode, half_duplex;
558 /* Configuration register 1 */
559 pause = ( efab->link_options & LPA_PAUSE ) ? 1 : 0;
560 if ( ! ( efab->link_options & LPA_DUPLEX ) ) {
561 /* Half-duplex operation requires TX flow control */
564 EFAB_POPULATE_DWORD_4 ( reg,
569 efab->mac_op->mac_writel ( efab, ®, GM_CFG1_REG_MAC );
572 /* Configuration register 2 */
573 if_mode = ( efab->link_options & LPA_1000 ) ? 2 : 1;
574 full_duplex = ( efab->link_options & LPA_DUPLEX ) ? 1 : 0;
575 EFAB_POPULATE_DWORD_4 ( reg,
579 GM_PAMBL_LEN, 0x7 /* ? */ );
580 efab->mac_op->mac_writel ( efab, ®, GM_CFG2_REG_MAC );
583 /* Max frame len register */
584 EFAB_POPULATE_DWORD_1 ( reg, GM_MAX_FLEN, ETH_FRAME_LEN + 4 /* FCS */);
585 efab->mac_op->mac_writel ( efab, ®, GM_MAX_FLEN_REG_MAC );
588 /* FIFO configuration register 0 */
589 EFAB_POPULATE_DWORD_5 ( reg,
595 efab->mac_op->mac_writel ( efab, ®, GMF_CFG0_REG_MAC );
598 /* FIFO configuration register 1 */
599 EFAB_POPULATE_DWORD_2 ( reg,
600 GMF_CFGFRTH, params->gmf_cfgfrth,
601 GMF_CFGXOFFRTX, 0xffff );
602 efab->mac_op->mac_writel ( efab, ®, GMF_CFG1_REG_MAC );
605 /* FIFO configuration register 2 */
606 EFAB_POPULATE_DWORD_2 ( reg,
607 GMF_CFGHWM, params->gmf_cfghwm,
608 GMF_CFGLWM, params->gmf_cfglwm );
609 efab->mac_op->mac_writel ( efab, ®, GMF_CFG2_REG_MAC );
612 /* FIFO configuration register 3 */
613 EFAB_POPULATE_DWORD_2 ( reg,
614 GMF_CFGHWMFT, params->gmf_cfghwmft,
615 GMF_CFGFTTH, params->gmf_cfgftth );
616 efab->mac_op->mac_writel ( efab, ®, GMF_CFG3_REG_MAC );
619 /* FIFO configuration register 4 */
620 EFAB_POPULATE_DWORD_1 ( reg, GMF_HSTFLTRFRM_PAUSE, 1 );
621 efab->mac_op->mac_writel ( efab, ®, GMF_CFG4_REG_MAC );
624 /* FIFO configuration register 5 */
625 bytemode = ( efab->link_options & LPA_1000 ) ? 1 : 0;
626 half_duplex = ( efab->link_options & LPA_DUPLEX ) ? 0 : 1;
627 efab->mac_op->mac_readl ( efab, ®, GMF_CFG5_REG_MAC );
628 EFAB_SET_DWORD_FIELD ( reg, GMF_CFGBYTMODE, bytemode );
629 EFAB_SET_DWORD_FIELD ( reg, GMF_CFGHDPLX, half_duplex );
630 EFAB_SET_DWORD_FIELD ( reg, GMF_HSTDRPLT64, half_duplex );
631 EFAB_SET_DWORD_FIELD ( reg, GMF_HSTFLTRFRMDC_PAUSE, 0 );
632 efab->mac_op->mac_writel ( efab, ®, GMF_CFG5_REG_MAC );
636 EFAB_POPULATE_DWORD_4 ( reg,
637 GM_HWADDR_5, efab->mac_addr[5],
638 GM_HWADDR_4, efab->mac_addr[4],
639 GM_HWADDR_3, efab->mac_addr[3],
640 GM_HWADDR_2, efab->mac_addr[2] );
641 efab->mac_op->mac_writel ( efab, ®, GM_ADR1_REG_MAC );
643 EFAB_POPULATE_DWORD_2 ( reg,
644 GM_HWADDR_1, efab->mac_addr[1],
645 GM_HWADDR_0, efab->mac_addr[0] );
646 efab->mac_op->mac_writel ( efab, ®, GM_ADR2_REG_MAC );
651 * Wait for GMII access to complete
654 static int mentormac_gmii_wait ( struct efab_nic *efab ) {
656 efab_dword_t indicator;
658 for ( count = 0 ; count < 1000 ; count++ ) {
660 efab->mac_op->mac_readl ( efab, &indicator,
661 GM_MII_MGMT_IND_REG_MAC );
662 if ( EFAB_DWORD_FIELD ( indicator, GM_MGMT_BUSY ) == 0 )
665 EFAB_ERR ( "Timed out waiting for GMII\n" );
670 * Write a GMII register
673 static void mentormac_mdio_write ( struct efab_nic *efab, int phy_id,
674 int location, int value ) {
678 EFAB_TRACE ( "Writing GMII %d register %02x with %04x\n", phy_id,
681 /* Mentor MAC connects both PHYs to MAC 0 */
682 save_port = efab->port;
685 /* Check MII not currently being accessed */
686 if ( ! mentormac_gmii_wait ( efab ) )
689 /* Write the address register */
690 EFAB_POPULATE_DWORD_2 ( reg,
691 GM_MGMT_PHY_ADDR, phy_id,
692 GM_MGMT_REG_ADDR, location );
693 efab->mac_op->mac_writel ( efab, ®, GM_MII_MGMT_ADR_REG_MAC );
697 EFAB_POPULATE_DWORD_1 ( reg, GM_MGMT_CTL, value );
698 efab->mac_op->mac_writel ( efab, ®, GM_MII_MGMT_CTL_REG_MAC );
700 /* Wait for data to be written */
701 mentormac_gmii_wait ( efab );
704 /* Restore efab->port */
705 efab->port = save_port;
709 * Read a GMII register
712 static int mentormac_mdio_read ( struct efab_nic *efab, int phy_id,
718 /* Mentor MAC connects both PHYs to MAC 0 */
719 save_port = efab->port;
722 /* Check MII not currently being accessed */
723 if ( ! mentormac_gmii_wait ( efab ) )
726 /* Write the address register */
727 EFAB_POPULATE_DWORD_2 ( reg,
728 GM_MGMT_PHY_ADDR, phy_id,
729 GM_MGMT_REG_ADDR, location );
730 efab->mac_op->mac_writel ( efab, ®, GM_MII_MGMT_ADR_REG_MAC );
733 /* Request data to be read */
734 EFAB_POPULATE_DWORD_1 ( reg, GM_MGMT_RD_CYC, 1 );
735 efab->mac_op->mac_writel ( efab, ®, GM_MII_MGMT_CMD_REG_MAC );
737 /* Wait for data to be become available */
738 if ( mentormac_gmii_wait ( efab ) ) {
740 efab->mac_op->mac_readl ( efab, ®, GM_MII_MGMT_STAT_REG_MAC );
741 value = EFAB_DWORD_FIELD ( reg, GM_MGMT_STAT );
742 EFAB_TRACE ( "Read from GMII %d register %02x, got %04x\n",
743 phy_id, location, value );
746 /* Signal completion */
747 EFAB_ZERO_DWORD ( reg );
748 efab->mac_op->mac_writel ( efab, ®, GM_MII_MGMT_CMD_REG_MAC );
752 /* Restore efab->port */
753 efab->port = save_port;
758 /**************************************************************************
762 **************************************************************************
765 /** Control and General Status */
766 #define EF1_CTR_GEN_STATUS0_REG 0x0
767 #define EF1_MASTER_EVENTS_LBN 12
768 #define EF1_MASTER_EVENTS_WIDTH 1
769 #define EF1_TX_ENGINE_EN_LBN 19
770 #define EF1_TX_ENGINE_EN_WIDTH 1
771 #define EF1_RX_ENGINE_EN_LBN 18
772 #define EF1_RX_ENGINE_EN_WIDTH 1
773 #define EF1_TURBO2_LBN 17
774 #define EF1_TURBO2_WIDTH 1
775 #define EF1_TURBO1_LBN 16
776 #define EF1_TURBO1_WIDTH 1
777 #define EF1_TURBO3_LBN 14
778 #define EF1_TURBO3_WIDTH 1
779 #define EF1_LB_RESET_LBN 3
780 #define EF1_LB_RESET_WIDTH 1
781 #define EF1_MAC_RESET_LBN 2
782 #define EF1_MAC_RESET_WIDTH 1
783 #define EF1_CAM_ENABLE_LBN 1
784 #define EF1_CAM_ENABLE_WIDTH 1
787 #define EF1_IRQ_SRC_REG 0x0008
790 #define EF1_IRQ_MASK_REG 0x000c
791 #define EF1_IRQ_PHY1_LBN 11
792 #define EF1_IRQ_PHY1_WIDTH 1
793 #define EF1_IRQ_PHY0_LBN 10
794 #define EF1_IRQ_PHY0_WIDTH 1
795 #define EF1_IRQ_SERR_LBN 7
796 #define EF1_IRQ_SERR_WIDTH 1
797 #define EF1_IRQ_EVQ_LBN 3
798 #define EF1_IRQ_EVQ_WIDTH 1
800 /** Event generation */
801 #define EF1_EVT3_REG 0x38
804 #define EF1_EEPROM_REG 0x40
805 #define EF1_EEPROM_SDA_LBN 31
806 #define EF1_EEPROM_SDA_WIDTH 1
807 #define EF1_EEPROM_SCL_LBN 30
808 #define EF1_EEPROM_SCL_WIDTH 1
809 #define EF1_JTAG_DISCONNECT_LBN 17
810 #define EF1_JTAG_DISCONNECT_WIDTH 1
811 #define EF1_EEPROM_LBN 0
812 #define EF1_EEPROM_WIDTH 32
814 /** Control register 2 */
815 #define EF1_CTL2_REG 0x4c
816 #define EF1_PLL_TRAP_LBN 31
817 #define EF1_PLL_TRAP_WIDTH 1
818 #define EF1_MEM_MAP_4MB_LBN 11
819 #define EF1_MEM_MAP_4MB_WIDTH 1
820 #define EF1_EV_INTR_CLR_WRITE_LBN 6
821 #define EF1_EV_INTR_CLR_WRITE_WIDTH 1
822 #define EF1_BURST_MERGE_LBN 5
823 #define EF1_BURST_MERGE_WIDTH 1
824 #define EF1_CLEAR_NULL_PAD_LBN 4
825 #define EF1_CLEAR_NULL_PAD_WIDTH 1
826 #define EF1_SW_RESET_LBN 2
827 #define EF1_SW_RESET_WIDTH 1
828 #define EF1_INTR_AFTER_EVENT_LBN 1
829 #define EF1_INTR_AFTER_EVENT_WIDTH 1
832 #define EF1_EVENT_FIFO_REG 0x50
834 /** Event FIFO count */
835 #define EF1_EVENT_FIFO_COUNT_REG 0x5c
836 #define EF1_EV_COUNT_LBN 0
837 #define EF1_EV_COUNT_WIDTH 16
839 /** TX DMA control and status */
840 #define EF1_DMA_TX_CSR_REG 0x80
841 #define EF1_DMA_TX_CSR_CHAIN_EN_LBN 8
842 #define EF1_DMA_TX_CSR_CHAIN_EN_WIDTH 1
843 #define EF1_DMA_TX_CSR_ENABLE_LBN 4
844 #define EF1_DMA_TX_CSR_ENABLE_WIDTH 1
845 #define EF1_DMA_TX_CSR_INT_EN_LBN 0
846 #define EF1_DMA_TX_CSR_INT_EN_WIDTH 1
848 /** RX DMA control and status */
849 #define EF1_DMA_RX_CSR_REG 0xa0
850 #define EF1_DMA_RX_ABOVE_1GB_EN_LBN 6
851 #define EF1_DMA_RX_ABOVE_1GB_EN_WIDTH 1
852 #define EF1_DMA_RX_BELOW_1MB_EN_LBN 5
853 #define EF1_DMA_RX_BELOW_1MB_EN_WIDTH 1
854 #define EF1_DMA_RX_CSR_ENABLE_LBN 0
855 #define EF1_DMA_RX_CSR_ENABLE_WIDTH 1
857 /** Level 5 watermark register (in MAC space) */
858 #define EF1_GMF_L5WM_REG_MAC 0x20
859 #define EF1_L5WM_LBN 0
860 #define EF1_L5WM_WIDTH 32
863 #define EF1_GM_MAC_CLK_REG 0x112000
864 #define EF1_GM_PORT0_MAC_CLK_LBN 0
865 #define EF1_GM_PORT0_MAC_CLK_WIDTH 1
866 #define EF1_GM_PORT1_MAC_CLK_LBN 1
867 #define EF1_GM_PORT1_MAC_CLK_WIDTH 1
869 /** TX descriptor FIFO */
870 #define EF1_TX_DESC_FIFO 0x141000
871 #define EF1_TX_KER_EVQ_LBN 80
872 #define EF1_TX_KER_EVQ_WIDTH 12
873 #define EF1_TX_KER_IDX_LBN 64
874 #define EF1_TX_KER_IDX_WIDTH 16
875 #define EF1_TX_KER_MODE_LBN 63
876 #define EF1_TX_KER_MODE_WIDTH 1
877 #define EF1_TX_KER_PORT_LBN 60
878 #define EF1_TX_KER_PORT_WIDTH 1
879 #define EF1_TX_KER_CONT_LBN 56
880 #define EF1_TX_KER_CONT_WIDTH 1
881 #define EF1_TX_KER_BYTE_CNT_LBN 32
882 #define EF1_TX_KER_BYTE_CNT_WIDTH 24
883 #define EF1_TX_KER_BUF_ADR_LBN 0
884 #define EF1_TX_KER_BUF_ADR_WIDTH 32
886 /** TX descriptor FIFO flush */
887 #define EF1_TX_DESC_FIFO_FLUSH 0x141ffc
889 /** RX descriptor FIFO */
890 #define EF1_RX_DESC_FIFO 0x145000
891 #define EF1_RX_KER_EVQ_LBN 48
892 #define EF1_RX_KER_EVQ_WIDTH 12
893 #define EF1_RX_KER_IDX_LBN 32
894 #define EF1_RX_KER_IDX_WIDTH 16
895 #define EF1_RX_KER_BUF_ADR_LBN 0
896 #define EF1_RX_KER_BUF_ADR_WIDTH 32
898 /** RX descriptor FIFO flush */
899 #define EF1_RX_DESC_FIFO_FLUSH 0x145ffc
902 #define EF1_CAM_BASE 0x1c0000
903 #define EF1_CAM_WTF_DOES_THIS_DO_LBN 0
904 #define EF1_CAM_WTF_DOES_THIS_DO_WIDTH 32
906 /** Event queue pointers */
907 #define EF1_EVQ_PTR_BASE 0x260000
908 #define EF1_EVQ_SIZE_LBN 29
909 #define EF1_EVQ_SIZE_WIDTH 2
910 #define EF1_EVQ_SIZE_4K 3
911 #define EF1_EVQ_SIZE_2K 2
912 #define EF1_EVQ_SIZE_1K 1
913 #define EF1_EVQ_SIZE_512 0
914 #define EF1_EVQ_BUF_BASE_ID_LBN 0
915 #define EF1_EVQ_BUF_BASE_ID_WIDTH 29
918 #define EF1002_MAC_REGBANK 0x110000
919 #define EF1002_MAC_REGBANK_SIZE 0x1000
920 #define EF1002_MAC_REG_SIZE 0x08
922 /** Offset of a MAC register within EF1002 */
923 #define EF1002_MAC_REG( efab, mac_reg ) \
924 ( EF1002_MAC_REGBANK + \
925 ( (efab)->port * EF1002_MAC_REGBANK_SIZE ) + \
926 ( (mac_reg) * EF1002_MAC_REG_SIZE ) )
928 /* Event queue entries */
929 #define EF1_EV_CODE_LBN 20
930 #define EF1_EV_CODE_WIDTH 8
931 #define EF1_RX_EV_DECODE 0x01
932 #define EF1_TX_EV_DECODE 0x02
933 #define EF1_TIMER_EV_DECODE 0x0b
934 #define EF1_DRV_GEN_EV_DECODE 0x0f
937 #define EF1_RX_EV_LEN_LBN 48
938 #define EF1_RX_EV_LEN_WIDTH 16
939 #define EF1_RX_EV_PORT_LBN 17
940 #define EF1_RX_EV_PORT_WIDTH 3
941 #define EF1_RX_EV_OK_LBN 16
942 #define EF1_RX_EV_OK_WIDTH 1
943 #define EF1_RX_EV_IDX_LBN 0
944 #define EF1_RX_EV_IDX_WIDTH 16
946 /* Transmit events */
947 #define EF1_TX_EV_PORT_LBN 17
948 #define EF1_TX_EV_PORT_WIDTH 3
949 #define EF1_TX_EV_OK_LBN 16
950 #define EF1_TX_EV_OK_WIDTH 1
951 #define EF1_TX_EV_IDX_LBN 0
952 #define EF1_TX_EV_IDX_WIDTH 16
954 /* forward decleration */
955 static struct efab_mac_operations ef1002_mac_operations;
957 /* I2C ID of the EEPROM */
958 #define EF1_EEPROM_I2C_ID 0x50
960 /* Offset of MAC address within EEPROM */
961 #define EF1_EEPROM_HWADDR_OFFSET 0x0
964 * Write dword to EF1002 register
967 static inline void ef1002_writel ( struct efab_nic *efab, efab_dword_t *value,
969 EFAB_REGDUMP ( "Writing register %x with " EFAB_DWORD_FMT "\n",
970 reg, EFAB_DWORD_VAL ( *value ) );
971 writel ( value->u32[0], efab->membase + reg );
975 * Read dword from an EF1002 register
978 static inline void ef1002_readl ( struct efab_nic *efab, efab_dword_t *value,
980 value->u32[0] = readl ( efab->membase + reg );
981 EFAB_REGDUMP ( "Read from register %x, got " EFAB_DWORD_FMT "\n",
982 reg, EFAB_DWORD_VAL ( *value ) );
986 * Read dword from an EF1002 register, silently
989 static inline void ef1002_readl_silent ( struct efab_nic *efab,
992 value->u32[0] = readl ( efab->membase + reg );
999 static void ef1002_get_membase ( struct efab_nic *efab ) {
1000 unsigned long membase_phys;
1002 membase_phys = pci_bar_start ( efab->pci, PCI_BASE_ADDRESS_0 );
1003 efab->membase = ioremap ( membase_phys, 0x800000 );
1006 /** PCI registers to backup/restore over a device reset */
1007 static const unsigned int efab_pci_reg_addr[] = {
1008 PCI_COMMAND, 0x0c /* PCI_CACHE_LINE_SIZE */,
1009 PCI_BASE_ADDRESS_0, PCI_BASE_ADDRESS_1, PCI_BASE_ADDRESS_2,
1010 PCI_BASE_ADDRESS_3, PCI_ROM_ADDRESS, PCI_INTERRUPT_LINE,
1012 /** Number of registers in efab_pci_reg_addr */
1013 #define EFAB_NUM_PCI_REG \
1014 ( sizeof ( efab_pci_reg_addr ) / sizeof ( efab_pci_reg_addr[0] ) )
1015 /** PCI configuration space backup */
1016 struct efab_pci_reg {
1017 uint32_t reg[EFAB_NUM_PCI_REG];
1021 * I2C interface and EEPROM
1025 static unsigned long ef1002_i2c_bits[] = {
1026 [I2C_BIT_SCL] = ( 1 << 30 ),
1027 [I2C_BIT_SDA] = ( 1 << 31 ),
1030 static void ef1002_i2c_write_bit ( struct bit_basher *basher,
1031 unsigned int bit_id, unsigned long data ) {
1032 struct efab_nic *efab = container_of ( basher, struct efab_nic,
1033 ef1002_i2c.basher );
1037 mask = ef1002_i2c_bits[bit_id];
1038 efab->ef1002_i2c_outputs &= ~mask;
1039 efab->ef1002_i2c_outputs |= ( data & mask );
1040 EFAB_POPULATE_DWORD_1 ( reg, EF1_EEPROM, efab->ef1002_i2c_outputs );
1041 ef1002_writel ( efab, ®, EF1_EEPROM_REG );
1044 static int ef1002_i2c_read_bit ( struct bit_basher *basher,
1045 unsigned int bit_id ) {
1046 struct efab_nic *efab = container_of ( basher, struct efab_nic,
1047 ef1002_i2c.basher );
1051 mask = ef1002_i2c_bits[bit_id];
1052 ef1002_readl ( efab, ®, EF1_EEPROM_REG );
1053 return ( EFAB_DWORD_FIELD ( reg, EF1_EEPROM ) & mask );
1056 static void ef1002_init_eeprom ( struct efab_nic *efab ) {
1057 efab->ef1002_i2c.basher.write = ef1002_i2c_write_bit;
1058 efab->ef1002_i2c.basher.read = ef1002_i2c_read_bit;
1059 init_i2c_bit_basher ( &efab->ef1002_i2c );
1060 efab->ef1002_eeprom.address = EF1_EEPROM_I2C_ID;
1067 static int ef1002_reset ( struct efab_nic *efab ) {
1068 struct efab_pci_reg pci_reg;
1069 struct pci_device *pci_dev = efab->pci;
1074 /* Back up PCI configuration registers */
1075 for ( i = 0 ; i < EFAB_NUM_PCI_REG ; i++ ) {
1076 pci_read_config_dword ( pci_dev, efab_pci_reg_addr[i],
1080 /* Reset the whole device. */
1081 EFAB_POPULATE_DWORD_1 ( reg, EF1_SW_RESET, 1 );
1082 ef1002_writel ( efab, ®, EF1_CTL2_REG );
1085 /* Restore PCI configuration space */
1086 for ( i = 0 ; i < EFAB_NUM_PCI_REG ; i++ ) {
1087 pci_write_config_dword ( pci_dev, efab_pci_reg_addr[i],
1091 /* Verify PCI configuration space */
1092 for ( i = 0 ; i < EFAB_NUM_PCI_REG ; i++ ) {
1093 pci_read_config_dword ( pci_dev, efab_pci_reg_addr[i], &tmp );
1094 if ( tmp != pci_reg.reg[i] ) {
1095 EFAB_LOG ( "PCI restore failed on register %02x "
1096 "(is %08lx, should be %08lx); reboot\n",
1097 i, tmp, pci_reg.reg[i] );
1102 /* Verify device reset complete */
1103 ef1002_readl ( efab, ®, EF1_CTR_GEN_STATUS0_REG );
1104 if ( EFAB_DWORD_IS_ALL_ONES ( reg ) ) {
1105 EFAB_ERR ( "Reset failed\n" );
1116 static int ef1002_init_nic ( struct efab_nic *efab ) {
1119 /* patch in the MAC operations */
1120 efab->mac_op = &ef1002_mac_operations;
1122 /* No idea what CAM is, but the 'datasheet' says that we have
1123 * to write these values in at start of day
1125 EFAB_POPULATE_DWORD_1 ( reg, EF1_CAM_WTF_DOES_THIS_DO, 0x6 );
1126 ef1002_writel ( efab, ®, EF1_CAM_BASE + 0x20018 );
1128 EFAB_POPULATE_DWORD_1 ( reg, EF1_CAM_WTF_DOES_THIS_DO, 0x01000000 );
1129 ef1002_writel ( efab, ®, EF1_CAM_BASE + 0x00018 );
1132 /* General control register 0 */
1133 ef1002_readl ( efab, ®, EF1_CTR_GEN_STATUS0_REG );
1134 EFAB_SET_DWORD_FIELD ( reg, EF1_MASTER_EVENTS, 0 );
1135 EFAB_SET_DWORD_FIELD ( reg, EF1_TX_ENGINE_EN, 0 );
1136 EFAB_SET_DWORD_FIELD ( reg, EF1_RX_ENGINE_EN, 0 );
1137 EFAB_SET_DWORD_FIELD ( reg, EF1_TURBO2, 1 );
1138 EFAB_SET_DWORD_FIELD ( reg, EF1_TURBO1, 1 );
1139 EFAB_SET_DWORD_FIELD ( reg, EF1_TURBO3, 1 );
1140 EFAB_SET_DWORD_FIELD ( reg, EF1_CAM_ENABLE, 1 );
1141 ef1002_writel ( efab, ®, EF1_CTR_GEN_STATUS0_REG );
1144 /* General control register 2 */
1145 ef1002_readl ( efab, ®, EF1_CTL2_REG );
1146 EFAB_SET_DWORD_FIELD ( reg, EF1_PLL_TRAP, 1 );
1147 EFAB_SET_DWORD_FIELD ( reg, EF1_MEM_MAP_4MB, 0 );
1148 EFAB_SET_DWORD_FIELD ( reg, EF1_EV_INTR_CLR_WRITE, 0 );
1149 EFAB_SET_DWORD_FIELD ( reg, EF1_BURST_MERGE, 0 );
1150 EFAB_SET_DWORD_FIELD ( reg, EF1_CLEAR_NULL_PAD, 1 );
1151 EFAB_SET_DWORD_FIELD ( reg, EF1_INTR_AFTER_EVENT, 1 );
1152 ef1002_writel ( efab, ®, EF1_CTL2_REG );
1156 ef1002_readl ( efab, ®, EF1_DMA_RX_CSR_REG );
1157 EFAB_SET_DWORD_FIELD ( reg, EF1_DMA_RX_CSR_ENABLE, 1 );
1158 EFAB_SET_DWORD_FIELD ( reg, EF1_DMA_RX_BELOW_1MB_EN, 1 );
1159 EFAB_SET_DWORD_FIELD ( reg, EF1_DMA_RX_ABOVE_1GB_EN, 1 );
1160 ef1002_writel ( efab, ®, EF1_DMA_RX_CSR_REG );
1164 ef1002_readl ( efab, ®, EF1_DMA_TX_CSR_REG );
1165 EFAB_SET_DWORD_FIELD ( reg, EF1_DMA_TX_CSR_CHAIN_EN, 1 );
1166 EFAB_SET_DWORD_FIELD ( reg, EF1_DMA_TX_CSR_ENABLE, 0 /* ?? */ );
1167 EFAB_SET_DWORD_FIELD ( reg, EF1_DMA_TX_CSR_INT_EN, 0 /* ?? */ );
1168 ef1002_writel ( efab, ®, EF1_DMA_TX_CSR_REG );
1171 /* Disconnect the JTAG chain. Read-modify-write is impossible
1172 * on the I2C control bits, since reading gives the state of
1173 * the line inputs rather than the last written state.
1175 ef1002_readl ( efab, ®, EF1_EEPROM_REG );
1176 EFAB_SET_DWORD_FIELD ( reg, EF1_EEPROM_SDA, 1 );
1177 EFAB_SET_DWORD_FIELD ( reg, EF1_EEPROM_SCL, 1 );
1178 EFAB_SET_DWORD_FIELD ( reg, EF1_JTAG_DISCONNECT, 1 );
1179 ef1002_writel ( efab, ®, EF1_EEPROM_REG );
1182 /* Flush descriptor queues */
1183 EFAB_ZERO_DWORD ( reg );
1184 ef1002_writel ( efab, ®, EF1_RX_DESC_FIFO_FLUSH );
1185 ef1002_writel ( efab, ®, EF1_TX_DESC_FIFO_FLUSH );
1190 efab->mac_op->reset ( efab );
1192 /* Attach I2C bus */
1193 ef1002_init_eeprom ( efab );
1199 * Read MAC address from EEPROM
1202 static int ef1002_read_eeprom ( struct efab_nic *efab ) {
1203 struct i2c_interface *i2c = &efab->ef1002_i2c.i2c;
1204 struct i2c_device *i2cdev = &efab->ef1002_eeprom;
1206 return ( i2c->read ( i2c, i2cdev, EF1_EEPROM_HWADDR_OFFSET,
1207 efab->mac_addr, sizeof ( efab->mac_addr ) ) == 0);
1210 /** RX descriptor */
1211 typedef efab_qword_t ef1002_rx_desc_t;
1214 * Build RX descriptor
1217 static void ef1002_build_rx_desc ( struct efab_nic *efab,
1218 struct efab_rx_buf *rx_buf ) {
1219 ef1002_rx_desc_t rxd;
1221 EFAB_POPULATE_QWORD_3 ( rxd,
1223 EF1_RX_KER_IDX, rx_buf->id,
1225 virt_to_bus ( rx_buf->addr ) );
1226 ef1002_writel ( efab, &rxd.dword[0], EF1_RX_DESC_FIFO + 0 );
1228 ef1002_writel ( efab, &rxd.dword[1], EF1_RX_DESC_FIFO + 4 );
1233 * Update RX descriptor write pointer
1236 static void ef1002_notify_rx_desc ( struct efab_nic *efab __unused ) {
1240 /** TX descriptor */
1241 typedef efab_oword_t ef1002_tx_desc_t;
1244 * Build TX descriptor
1247 static void ef1002_build_tx_desc ( struct efab_nic *efab,
1248 struct efab_tx_buf *tx_buf ) {
1249 ef1002_tx_desc_t txd;
1251 EFAB_POPULATE_OWORD_7 ( txd,
1253 EF1_TX_KER_IDX, tx_buf->id,
1254 EF1_TX_KER_MODE, 0 /* IP mode */,
1255 EF1_TX_KER_PORT, efab->port,
1257 EF1_TX_KER_BYTE_CNT, tx_buf->len,
1259 virt_to_bus ( tx_buf->addr ) );
1261 ef1002_writel ( efab, &txd.dword[0], EF1_TX_DESC_FIFO + 0 );
1262 ef1002_writel ( efab, &txd.dword[1], EF1_TX_DESC_FIFO + 4 );
1264 ef1002_writel ( efab, &txd.dword[2], EF1_TX_DESC_FIFO + 8 );
1269 * Update TX descriptor write pointer
1272 static void ef1002_notify_tx_desc ( struct efab_nic *efab __unused ) {
1277 typedef efab_qword_t ef1002_event_t;
1280 * Retrieve event from event queue
1283 static int ef1002_fetch_event ( struct efab_nic *efab,
1284 struct efab_event *event ) {
1289 /* Check event FIFO depth */
1290 ef1002_readl_silent ( efab, ®, EF1_EVENT_FIFO_COUNT_REG );
1291 words = EFAB_DWORD_FIELD ( reg, EF1_EV_COUNT );
1295 /* Read event data */
1296 ef1002_readl ( efab, ®, EF1_EVENT_FIFO_REG );
1297 DBG ( "Event is " EFAB_DWORD_FMT "\n", EFAB_DWORD_VAL ( reg ) );
1300 ev_code = EFAB_DWORD_FIELD ( reg, EF1_EV_CODE );
1302 switch ( ev_code ) {
1303 case EF1_TX_EV_DECODE:
1304 event->type = EFAB_EV_TX;
1306 case EF1_RX_EV_DECODE:
1307 event->type = EFAB_EV_RX;
1308 event->rx_id = EFAB_DWORD_FIELD ( reg, EF1_RX_EV_IDX );
1309 /* RX len not available via event FIFO */
1310 event->rx_len = ETH_FRAME_LEN;
1312 case EF1_TIMER_EV_DECODE:
1313 /* These are safe to ignore. We seem to get some at
1314 * start of day, presumably due to the timers starting
1315 * up with random contents.
1317 event->type = EFAB_EV_NONE;
1320 EFAB_ERR ( "Unknown event type %d\n", ev_code );
1321 event->type = EFAB_EV_NONE;
1324 /* Clear any pending interrupts */
1325 ef1002_readl ( efab, ®, EF1_IRQ_SRC_REG );
1331 * Enable/disable interrupts
1334 static void ef1002_mask_irq ( struct efab_nic *efab, int enabled ) {
1335 efab_dword_t irq_mask;
1337 EFAB_POPULATE_DWORD_2 ( irq_mask,
1338 EF1_IRQ_SERR, enabled,
1339 EF1_IRQ_EVQ, enabled );
1340 ef1002_writel ( efab, &irq_mask, EF1_IRQ_MASK_REG );
1344 * Generate interrupt
1347 static void ef1002_generate_irq ( struct efab_nic *efab ) {
1348 ef1002_event_t test_event;
1350 EFAB_POPULATE_QWORD_1 ( test_event,
1351 EF1_EV_CODE, EF1_DRV_GEN_EV_DECODE );
1352 ef1002_writel ( efab, &test_event.dword[0], EF1_EVT3_REG );
1356 * Write dword to an EF1002 MAC register
1359 static void ef1002_mac_writel ( struct efab_nic *efab,
1360 efab_dword_t *value, unsigned int mac_reg ) {
1361 ef1002_writel ( efab, value, EF1002_MAC_REG ( efab, mac_reg ) );
1365 * Read dword from an EF1002 MAC register
1368 static void ef1002_mac_readl ( struct efab_nic *efab,
1369 efab_dword_t *value, unsigned int mac_reg ) {
1370 ef1002_readl ( efab, value, EF1002_MAC_REG ( efab, mac_reg ) );
1377 static int ef1002_init_mac ( struct efab_nic *efab ) {
1378 static struct efab_mentormac_parameters ef1002_mentormac_params = {
1379 .gmf_cfgfrth = 0x13,
1380 .gmf_cfgftth = 0x10,
1381 .gmf_cfghwmft = 0x555,
1386 unsigned int mac_clk;
1388 /* Initialise PHY */
1389 alaska_init ( efab );
1391 /* Initialise MAC */
1392 mentormac_init ( efab, &ef1002_mentormac_params );
1394 /* Write Level 5 watermark register */
1395 EFAB_POPULATE_DWORD_1 ( reg, EF1_L5WM, 0x10040000 );
1396 efab->mac_op->mac_writel ( efab, ®, EF1_GMF_L5WM_REG_MAC );
1399 /* Set MAC clock speed */
1400 ef1002_readl ( efab, ®, EF1_GM_MAC_CLK_REG );
1401 mac_clk = ( efab->link_options & LPA_1000 ) ? 0 : 1;
1402 if ( efab->port == 0 ) {
1403 EFAB_SET_DWORD_FIELD ( reg, EF1_GM_PORT0_MAC_CLK, mac_clk );
1405 EFAB_SET_DWORD_FIELD ( reg, EF1_GM_PORT1_MAC_CLK, mac_clk );
1407 ef1002_writel ( efab, ®, EF1_GM_MAC_CLK_REG );
1417 static int ef1002_reset_mac ( struct efab_nic *efab ) {
1418 mentormac_reset ( efab );
1423 static void ef1002_mdio_write ( struct efab_nic *efab, int location,
1425 mentormac_mdio_write ( efab, efab->port + 2, location, value );
1429 static int ef1002_mdio_read ( struct efab_nic *efab, int location ) {
1430 return mentormac_mdio_read ( efab, efab->port + 2, location );
1433 static struct efab_operations ef1002_operations = {
1434 .get_membase = ef1002_get_membase,
1435 .reset = ef1002_reset,
1436 .init_nic = ef1002_init_nic,
1437 .read_eeprom = ef1002_read_eeprom,
1438 .build_rx_desc = ef1002_build_rx_desc,
1439 .notify_rx_desc = ef1002_notify_rx_desc,
1440 .build_tx_desc = ef1002_build_tx_desc,
1441 .notify_tx_desc = ef1002_notify_tx_desc,
1442 .fetch_event = ef1002_fetch_event,
1443 .mask_irq = ef1002_mask_irq,
1444 .generate_irq = ef1002_generate_irq,
1445 .mdio_write = ef1002_mdio_write,
1446 .mdio_read = ef1002_mdio_read,
1449 static struct efab_mac_operations ef1002_mac_operations = {
1450 .mac_writel = ef1002_mac_writel,
1451 .mac_readl = ef1002_mac_readl,
1452 .init = ef1002_init_mac,
1453 .reset = ef1002_reset_mac,
1456 /**************************************************************************
1460 **************************************************************************
1463 /* I/O BAR address register */
1464 #define FCN_IOM_IND_ADR_REG 0x0
1466 /* I/O BAR data register */
1467 #define FCN_IOM_IND_DAT_REG 0x4
1469 /* Interrupt enable register */
1470 #define FCN_INT_EN_REG_KER 0x0010
1471 #define FCN_MEM_PERR_INT_EN_KER_LBN 5
1472 #define FCN_MEM_PERR_INT_EN_KER_WIDTH 1
1473 #define FCN_KER_INT_CHAR_LBN 4
1474 #define FCN_KER_INT_CHAR_WIDTH 1
1475 #define FCN_KER_INT_KER_LBN 3
1476 #define FCN_KER_INT_KER_WIDTH 1
1477 #define FCN_ILL_ADR_ERR_INT_EN_KER_LBN 2
1478 #define FCN_ILL_ADR_ERR_INT_EN_KER_WIDTH 1
1479 #define FCN_SRM_PERR_INT_EN_KER_LBN 1
1480 #define FCN_SRM_PERR_INT_EN_KER_WIDTH 1
1481 #define FCN_DRV_INT_EN_KER_LBN 0
1482 #define FCN_DRV_INT_EN_KER_WIDTH 1
1484 /* Interrupt status register */
1485 #define FCN_INT_ADR_REG_KER 0x0030
1486 #define FCN_INT_ADR_KER_LBN 0
1487 #define FCN_INT_ADR_KER_WIDTH EFAB_DMA_TYPE_WIDTH ( 64 )
1489 /* Interrupt acknowledge register */
1490 #define FCN_INT_ACK_KER_REG 0x0050
1492 /* SPI host command register */
1493 #define FCN_EE_SPI_HCMD_REG_KER 0x0100
1494 #define FCN_EE_SPI_HCMD_CMD_EN_LBN 31
1495 #define FCN_EE_SPI_HCMD_CMD_EN_WIDTH 1
1496 #define FCN_EE_WR_TIMER_ACTIVE_LBN 28
1497 #define FCN_EE_WR_TIMER_ACTIVE_WIDTH 1
1498 #define FCN_EE_SPI_HCMD_SF_SEL_LBN 24
1499 #define FCN_EE_SPI_HCMD_SF_SEL_WIDTH 1
1500 #define FCN_EE_SPI_EEPROM 0
1501 #define FCN_EE_SPI_FLASH 1
1502 #define FCN_EE_SPI_HCMD_DABCNT_LBN 16
1503 #define FCN_EE_SPI_HCMD_DABCNT_WIDTH 5
1504 #define FCN_EE_SPI_HCMD_READ_LBN 15
1505 #define FCN_EE_SPI_HCMD_READ_WIDTH 1
1506 #define FCN_EE_SPI_READ 1
1507 #define FCN_EE_SPI_WRITE 0
1508 #define FCN_EE_SPI_HCMD_DUBCNT_LBN 12
1509 #define FCN_EE_SPI_HCMD_DUBCNT_WIDTH 2
1510 #define FCN_EE_SPI_HCMD_ADBCNT_LBN 8
1511 #define FCN_EE_SPI_HCMD_ADBCNT_WIDTH 2
1512 #define FCN_EE_SPI_HCMD_ENC_LBN 0
1513 #define FCN_EE_SPI_HCMD_ENC_WIDTH 8
1515 /* SPI host address register */
1516 #define FCN_EE_SPI_HADR_REG_KER 0x0110
1517 #define FCN_EE_SPI_HADR_DUBYTE_LBN 24
1518 #define FCN_EE_SPI_HADR_DUBYTE_WIDTH 8
1519 #define FCN_EE_SPI_HADR_ADR_LBN 0
1520 #define FCN_EE_SPI_HADR_ADR_WIDTH 24
1522 /* SPI host data register */
1523 #define FCN_EE_SPI_HDATA_REG_KER 0x0120
1524 #define FCN_EE_SPI_HDATA3_LBN 96
1525 #define FCN_EE_SPI_HDATA3_WIDTH 32
1526 #define FCN_EE_SPI_HDATA2_LBN 64
1527 #define FCN_EE_SPI_HDATA2_WIDTH 32
1528 #define FCN_EE_SPI_HDATA1_LBN 32
1529 #define FCN_EE_SPI_HDATA1_WIDTH 32
1530 #define FCN_EE_SPI_HDATA0_LBN 0
1531 #define FCN_EE_SPI_HDATA0_WIDTH 32
1533 /* NIC status register */
1534 #define FCN_NIC_STAT_REG 0x0200
1535 #define ONCHIP_SRAM_LBN 16
1536 #define ONCHIP_SRAM_WIDTH 1
1537 #define SF_PRST_LBN 9
1538 #define SF_PRST_WIDTH 1
1539 #define EE_PRST_LBN 8
1540 #define EE_PRST_WIDTH 1
1541 #define EE_STRAP_LBN 7
1542 #define EE_STRAP_WIDTH 1
1543 #define PCI_PCIX_MODE_LBN 4
1544 #define PCI_PCIX_MODE_WIDTH 3
1545 #define PCI_PCIX_MODE_PCI33_DECODE 0
1546 #define PCI_PCIX_MODE_PCI66_DECODE 1
1547 #define PCI_PCIX_MODE_PCIX66_DECODE 5
1548 #define PCI_PCIX_MODE_PCIX100_DECODE 6
1549 #define PCI_PCIX_MODE_PCIX133_DECODE 7
1550 #define STRAP_ISCSI_EN_LBN 3
1551 #define STRAP_ISCSI_EN_WIDTH 1
1552 #define STRAP_PINS_LBN 0
1553 #define STRAP_PINS_WIDTH 3
1554 /* These bit definitions are extrapolated from the list of numerical
1555 * values for STRAP_PINS. If you want a laugh, read the datasheet's
1556 * definition for when bits 2:0 are set to 7.
1558 #define STRAP_10G_LBN 2
1559 #define STRAP_10G_WIDTH 1
1560 #define STRAP_DUAL_PORT_LBN 1
1561 #define STRAP_DUAL_PORT_WIDTH 1
1562 #define STRAP_PCIE_LBN 0
1563 #define STRAP_PCIE_WIDTH 1
1565 /* GPIO control register */
1566 #define FCN_GPIO_CTL_REG_KER 0x0210
1567 #define FCN_FLASH_PRESENT_LBN 7
1568 #define FCN_FLASH_PRESENT_WIDTH 1
1569 #define FCN_EEPROM_PRESENT_LBN 6
1570 #define FCN_EEPROM_PRESENT_WIDTH 1
1572 /* Global control register */
1573 #define FCN_GLB_CTL_REG_KER 0x0220
1574 #define EXT_PHY_RST_CTL_LBN 63
1575 #define EXT_PHY_RST_CTL_WIDTH 1
1576 #define PCIE_SD_RST_CTL_LBN 61
1577 #define PCIE_SD_RST_CTL_WIDTH 1
1578 #define PCIX_RST_CTL_LBN 60
1579 #define PCIX_RST_CTL_WIDTH 1
1580 #define PCIE_STCK_RST_CTL_LBN 59
1581 #define PCIE_STCK_RST_CTL_WIDTH 1
1582 #define PCIE_NSTCK_RST_CTL_LBN 58
1583 #define PCIE_NSTCK_RST_CTL_WIDTH 1
1584 #define PCIE_CORE_RST_CTL_LBN 57
1585 #define PCIE_CORE_RST_CTL_WIDTH 1
1586 #define EE_RST_CTL_LBN 49
1587 #define EE_RST_CTL_WIDTH 1
1588 #define CS_RST_CTL_LBN 48
1589 #define CS_RST_CTL_WIDTH 1
1590 #define RST_EXT_PHY_LBN 31
1591 #define RST_EXT_PHY_WIDTH 1
1592 #define INT_RST_DUR_LBN 4
1593 #define INT_RST_DUR_WIDTH 3
1594 #define EXT_PHY_RST_DUR_LBN 1
1595 #define EXT_PHY_RST_DUR_WIDTH 3
1597 #define SWRST_WIDTH 1
1598 #define INCLUDE_IN_RESET 0
1599 #define EXCLUDE_FROM_RESET 1
1601 /* FPGA build version */
1602 #define ALTERA_BUILD_REG_KER 0x0300
1603 #define VER_MAJOR_LBN 24
1604 #define VER_MAJOR_WIDTH 8
1605 #define VER_MINOR_LBN 16
1606 #define VER_MINOR_WIDTH 8
1607 #define VER_BUILD_LBN 0
1608 #define VER_BUILD_WIDTH 16
1609 #define VER_ALL_LBN 0
1610 #define VER_ALL_WIDTH 32
1612 /* Timer table for kernel access */
1613 #define FCN_TIMER_CMD_REG_KER 0x420
1614 #define FCN_TIMER_MODE_LBN 12
1615 #define FCN_TIMER_MODE_WIDTH 2
1616 #define FCN_TIMER_MODE_DIS 0
1617 #define FCN_TIMER_MODE_INT_HLDOFF 1
1618 #define FCN_TIMER_VAL_LBN 0
1619 #define FCN_TIMER_VAL_WIDTH 12
1621 /* Receive configuration register */
1622 #define FCN_RX_CFG_REG_KER 0x800
1623 #define FCN_RX_XOFF_EN_LBN 0
1624 #define FCN_RX_XOFF_EN_WIDTH 1
1626 /* SRAM receive descriptor cache configuration register */
1627 #define FCN_SRM_RX_DC_CFG_REG_KER 0x610
1628 #define FCN_SRM_RX_DC_BASE_ADR_LBN 0
1629 #define FCN_SRM_RX_DC_BASE_ADR_WIDTH 21
1631 /* SRAM transmit descriptor cache configuration register */
1632 #define FCN_SRM_TX_DC_CFG_REG_KER 0x620
1633 #define FCN_SRM_TX_DC_BASE_ADR_LBN 0
1634 #define FCN_SRM_TX_DC_BASE_ADR_WIDTH 21
1636 /* Receive filter control register */
1637 #define FCN_RX_FILTER_CTL_REG_KER 0x810
1638 #define FCN_NUM_KER_LBN 24
1639 #define FCN_NUM_KER_WIDTH 2
1641 /* Receive descriptor update register */
1642 #define FCN_RX_DESC_UPD_REG_KER 0x0830
1643 #define FCN_RX_DESC_WPTR_LBN 96
1644 #define FCN_RX_DESC_WPTR_WIDTH 12
1645 #define FCN_RX_DESC_UPD_REG_KER_DWORD ( FCN_RX_DESC_UPD_REG_KER + 12 )
1646 #define FCN_RX_DESC_WPTR_DWORD_LBN 0
1647 #define FCN_RX_DESC_WPTR_DWORD_WIDTH 12
1649 /* Receive descriptor cache configuration register */
1650 #define FCN_RX_DC_CFG_REG_KER 0x840
1651 #define FCN_RX_DC_SIZE_LBN 0
1652 #define FCN_RX_DC_SIZE_WIDTH 2
1654 /* Transmit descriptor update register */
1655 #define FCN_TX_DESC_UPD_REG_KER 0x0a10
1656 #define FCN_TX_DESC_WPTR_LBN 96
1657 #define FCN_TX_DESC_WPTR_WIDTH 12
1658 #define FCN_TX_DESC_UPD_REG_KER_DWORD ( FCN_TX_DESC_UPD_REG_KER + 12 )
1659 #define FCN_TX_DESC_WPTR_DWORD_LBN 0
1660 #define FCN_TX_DESC_WPTR_DWORD_WIDTH 12
1662 /* Transmit descriptor cache configuration register */
1663 #define FCN_TX_DC_CFG_REG_KER 0xa20
1664 #define FCN_TX_DC_SIZE_LBN 0
1665 #define FCN_TX_DC_SIZE_WIDTH 2
1667 /* PHY management transmit data register */
1668 #define FCN_MD_TXD_REG_KER 0xc00
1669 #define FCN_MD_TXD_LBN 0
1670 #define FCN_MD_TXD_WIDTH 16
1672 /* PHY management receive data register */
1673 #define FCN_MD_RXD_REG_KER 0xc10
1674 #define FCN_MD_RXD_LBN 0
1675 #define FCN_MD_RXD_WIDTH 16
1677 /* PHY management configuration & status register */
1678 #define FCN_MD_CS_REG_KER 0xc20
1679 #define FCN_MD_GC_LBN 4
1680 #define FCN_MD_GC_WIDTH 1
1681 #define FCN_MD_RIC_LBN 2
1682 #define FCN_MD_RIC_WIDTH 1
1683 #define FCN_MD_WRC_LBN 0
1684 #define FCN_MD_WRC_WIDTH 1
1686 /* PHY management PHY address register */
1687 #define FCN_MD_PHY_ADR_REG_KER 0xc30
1688 #define FCN_MD_PHY_ADR_LBN 0
1689 #define FCN_MD_PHY_ADR_WIDTH 16
1691 /* PHY management ID register */
1692 #define FCN_MD_ID_REG_KER 0xc40
1693 #define FCN_MD_PRT_ADR_LBN 11
1694 #define FCN_MD_PRT_ADR_WIDTH 5
1695 #define FCN_MD_DEV_ADR_LBN 6
1696 #define FCN_MD_DEV_ADR_WIDTH 5
1698 /* PHY management status & mask register */
1699 #define FCN_MD_STAT_REG_KER 0xc50
1700 #define FCN_MD_BSY_LBN 0
1701 #define FCN_MD_BSY_WIDTH 1
1703 /* Port 0 and 1 MAC control registers */
1704 #define FCN_MAC0_CTRL_REG_KER 0xc80
1705 #define FCN_MAC1_CTRL_REG_KER 0xc90
1706 #define FCN_MAC_XOFF_VAL_LBN 16
1707 #define FCN_MAC_XOFF_VAL_WIDTH 16
1708 #define FCN_MAC_BCAD_ACPT_LBN 4
1709 #define FCN_MAC_BCAD_ACPT_WIDTH 1
1710 #define FCN_MAC_UC_PROM_LBN 3
1711 #define FCN_MAC_UC_PROM_WIDTH 1
1712 #define FCN_MAC_LINK_STATUS_LBN 2
1713 #define FCN_MAC_LINK_STATUS_WIDTH 1
1714 #define FCN_MAC_SPEED_LBN 0
1715 #define FCN_MAC_SPEED_WIDTH 2
1717 /* GMAC registers */
1718 #define FALCON_GMAC_REGBANK 0xe00
1719 #define FALCON_GMAC_REGBANK_SIZE 0x200
1720 #define FALCON_GMAC_REG_SIZE 0x10
1722 /* XGMAC registers */
1723 #define FALCON_XMAC_REGBANK 0x1200
1724 #define FALCON_XMAC_REGBANK_SIZE 0x200
1725 #define FALCON_XMAC_REG_SIZE 0x10
1727 /* XGMAC address register low */
1728 #define FCN_XM_ADR_LO_REG_MAC 0x00
1729 #define FCN_XM_ADR_3_LBN 24
1730 #define FCN_XM_ADR_3_WIDTH 8
1731 #define FCN_XM_ADR_2_LBN 16
1732 #define FCN_XM_ADR_2_WIDTH 8
1733 #define FCN_XM_ADR_1_LBN 8
1734 #define FCN_XM_ADR_1_WIDTH 8
1735 #define FCN_XM_ADR_0_LBN 0
1736 #define FCN_XM_ADR_0_WIDTH 8
1738 /* XGMAC address register high */
1739 #define FCN_XM_ADR_HI_REG_MAC 0x01
1740 #define FCN_XM_ADR_5_LBN 8
1741 #define FCN_XM_ADR_5_WIDTH 8
1742 #define FCN_XM_ADR_4_LBN 0
1743 #define FCN_XM_ADR_4_WIDTH 8
1745 /* XGMAC global configuration - port 0*/
1746 #define FCN_XM_GLB_CFG_REG_MAC 0x02
1747 #define FCN_XM_RX_STAT_EN_LBN 11
1748 #define FCN_XM_RX_STAT_EN_WIDTH 1
1749 #define FCN_XM_TX_STAT_EN_LBN 10
1750 #define FCN_XM_TX_STAT_EN_WIDTH 1
1751 #define FCN_XM_RX_JUMBO_MODE_LBN 6
1752 #define FCN_XM_RX_JUMBO_MODE_WIDTH 1
1753 #define FCN_XM_CORE_RST_LBN 0
1754 #define FCN_XM_CORE_RST_WIDTH 1
1756 /* XGMAC transmit configuration - port 0 */
1757 #define FCN_XM_TX_CFG_REG_MAC 0x03
1758 #define FCN_XM_IPG_LBN 16
1759 #define FCN_XM_IPG_WIDTH 4
1760 #define FCN_XM_FCNTL_LBN 10
1761 #define FCN_XM_FCNTL_WIDTH 1
1762 #define FCN_XM_TXCRC_LBN 8
1763 #define FCN_XM_TXCRC_WIDTH 1
1764 #define FCN_XM_AUTO_PAD_LBN 5
1765 #define FCN_XM_AUTO_PAD_WIDTH 1
1766 #define FCN_XM_TX_PRMBL_LBN 2
1767 #define FCN_XM_TX_PRMBL_WIDTH 1
1768 #define FCN_XM_TXEN_LBN 1
1769 #define FCN_XM_TXEN_WIDTH 1
1771 /* XGMAC receive configuration - port 0 */
1772 #define FCN_XM_RX_CFG_REG_MAC 0x04
1773 #define FCN_XM_PASS_CRC_ERR_LBN 25
1774 #define FCN_XM_PASS_CRC_ERR_WIDTH 1
1775 #define FCN_XM_AUTO_DEPAD_LBN 8
1776 #define FCN_XM_AUTO_DEPAD_WIDTH 1
1777 #define FCN_XM_RXEN_LBN 1
1778 #define FCN_XM_RXEN_WIDTH 1
1780 /* XGMAC transmit parameter register */
1781 #define FCN_XM_TX_PARAM_REG_MAC 0x0d
1782 #define FCN_XM_TX_JUMBO_MODE_LBN 31
1783 #define FCN_XM_TX_JUMBO_MODE_WIDTH 1
1784 #define FCN_XM_MAX_TX_FRM_SIZE_LBN 16
1785 #define FCN_XM_MAX_TX_FRM_SIZE_WIDTH 14
1787 /* XGMAC receive parameter register */
1788 #define FCN_XM_RX_PARAM_REG_MAC 0x0e
1789 #define FCN_XM_MAX_RX_FRM_SIZE_LBN 0
1790 #define FCN_XM_MAX_RX_FRM_SIZE_WIDTH 14
1792 /* XAUI XGXS core status register */
1793 #define FCN_XX_ALIGN_DONE_LBN 20
1794 #define FCN_XX_ALIGN_DONE_WIDTH 1
1795 #define FCN_XX_CORE_STAT_REG_MAC 0x16
1796 #define FCN_XX_SYNC_STAT_LBN 16
1797 #define FCN_XX_SYNC_STAT_WIDTH 4
1798 #define FCN_XX_SYNC_STAT_DECODE_SYNCED 0xf
1799 #define FCN_XX_COMMA_DET_LBN 12
1800 #define FCN_XX_COMMA_DET_WIDTH 4
1801 #define FCN_XX_COMMA_DET_RESET 0xf
1804 /* XGXS/XAUI powerdown/reset register */
1805 #define FCN_XX_PWR_RST_REG_MAC 0x10
1806 #define FCN_XX_RSTXGXSRX_EN_LBN 2
1807 #define FCN_XX_RSTXGXSRX_EN_WIDTH 1
1808 #define FCN_XX_RSTXGXSTX_EN_LBN 1
1809 #define FCN_XX_RSTXGXSTX_EN_WIDTH 1
1810 #define FCN_XX_RST_XX_EN_LBN 0
1811 #define FCN_XX_RST_XX_EN_WIDTH 1
1813 /* Receive descriptor pointer table */
1814 #define FCN_RX_DESC_PTR_TBL_KER 0x11800
1815 #define FCN_RX_DESCQ_BUF_BASE_ID_LBN 36
1816 #define FCN_RX_DESCQ_BUF_BASE_ID_WIDTH 20
1817 #define FCN_RX_DESCQ_EVQ_ID_LBN 24
1818 #define FCN_RX_DESCQ_EVQ_ID_WIDTH 12
1819 #define FCN_RX_DESCQ_OWNER_ID_LBN 10
1820 #define FCN_RX_DESCQ_OWNER_ID_WIDTH 14
1821 #define FCN_RX_DESCQ_SIZE_LBN 3
1822 #define FCN_RX_DESCQ_SIZE_WIDTH 2
1823 #define FCN_RX_DESCQ_SIZE_4K 3
1824 #define FCN_RX_DESCQ_SIZE_2K 2
1825 #define FCN_RX_DESCQ_SIZE_1K 1
1826 #define FCN_RX_DESCQ_SIZE_512 0
1827 #define FCN_RX_DESCQ_TYPE_LBN 2
1828 #define FCN_RX_DESCQ_TYPE_WIDTH 1
1829 #define FCN_RX_DESCQ_JUMBO_LBN 1
1830 #define FCN_RX_DESCQ_JUMBO_WIDTH 1
1831 #define FCN_RX_DESCQ_EN_LBN 0
1832 #define FCN_RX_DESCQ_EN_WIDTH 1
1834 /* Transmit descriptor pointer table */
1835 #define FCN_TX_DESC_PTR_TBL_KER 0x11900
1836 #define FCN_TX_DESCQ_EN_LBN 88
1837 #define FCN_TX_DESCQ_EN_WIDTH 1
1838 #define FCN_TX_DESCQ_BUF_BASE_ID_LBN 36
1839 #define FCN_TX_DESCQ_BUF_BASE_ID_WIDTH 20
1840 #define FCN_TX_DESCQ_EVQ_ID_LBN 24
1841 #define FCN_TX_DESCQ_EVQ_ID_WIDTH 12
1842 #define FCN_TX_DESCQ_OWNER_ID_LBN 10
1843 #define FCN_TX_DESCQ_OWNER_ID_WIDTH 14
1844 #define FCN_TX_DESCQ_SIZE_LBN 3
1845 #define FCN_TX_DESCQ_SIZE_WIDTH 2
1846 #define FCN_TX_DESCQ_SIZE_4K 3
1847 #define FCN_TX_DESCQ_SIZE_2K 2
1848 #define FCN_TX_DESCQ_SIZE_1K 1
1849 #define FCN_TX_DESCQ_SIZE_512 0
1850 #define FCN_TX_DESCQ_TYPE_LBN 1
1851 #define FCN_TX_DESCQ_TYPE_WIDTH 2
1852 #define FCN_TX_DESCQ_FLUSH_LBN 0
1853 #define FCN_TX_DESCQ_FLUSH_WIDTH 1
1855 /* Event queue pointer */
1856 #define FCN_EVQ_PTR_TBL_KER 0x11a00
1857 #define FCN_EVQ_EN_LBN 23
1858 #define FCN_EVQ_EN_WIDTH 1
1859 #define FCN_EVQ_SIZE_LBN 20
1860 #define FCN_EVQ_SIZE_WIDTH 3
1861 #define FCN_EVQ_SIZE_32K 6
1862 #define FCN_EVQ_SIZE_16K 5
1863 #define FCN_EVQ_SIZE_8K 4
1864 #define FCN_EVQ_SIZE_4K 3
1865 #define FCN_EVQ_SIZE_2K 2
1866 #define FCN_EVQ_SIZE_1K 1
1867 #define FCN_EVQ_SIZE_512 0
1868 #define FCN_EVQ_BUF_BASE_ID_LBN 0
1869 #define FCN_EVQ_BUF_BASE_ID_WIDTH 20
1871 /* Event queue read pointer */
1872 #define FCN_EVQ_RPTR_REG_KER 0x11b00
1873 #define FCN_EVQ_RPTR_LBN 0
1874 #define FCN_EVQ_RPTR_WIDTH 14
1875 #define FCN_EVQ_RPTR_REG_KER_DWORD ( FCN_EVQ_RPTR_REG_KER + 0 )
1876 #define FCN_EVQ_RPTR_DWORD_LBN 0
1877 #define FCN_EVQ_RPTR_DWORD_WIDTH 14
1879 /* Special buffer descriptors */
1880 #define FCN_BUF_FULL_TBL_KER 0x18000
1881 #define FCN_IP_DAT_BUF_SIZE_LBN 50
1882 #define FCN_IP_DAT_BUF_SIZE_WIDTH 1
1883 #define FCN_IP_DAT_BUF_SIZE_8K 1
1884 #define FCN_IP_DAT_BUF_SIZE_4K 0
1885 #define FCN_BUF_ADR_FBUF_LBN 14
1886 #define FCN_BUF_ADR_FBUF_WIDTH 34
1887 #define FCN_BUF_OWNER_ID_FBUF_LBN 0
1888 #define FCN_BUF_OWNER_ID_FBUF_WIDTH 14
1890 /** Offset of a GMAC register within Falcon */
1891 #define FALCON_GMAC_REG( efab, mac_reg ) \
1892 ( FALCON_GMAC_REGBANK + \
1893 ( (efab)->port * FALCON_GMAC_REGBANK_SIZE ) + \
1894 ( (mac_reg) * FALCON_GMAC_REG_SIZE ) )
1896 /** Offset of an XMAC register within Falcon */
1897 #define FALCON_XMAC_REG( efab_port, mac_reg ) \
1898 ( FALCON_XMAC_REGBANK + \
1899 ( (efab_port)->port * FALCON_XMAC_REGBANK_SIZE ) + \
1900 ( (mac_reg) * FALCON_XMAC_REG_SIZE ) )
1902 #define FCN_MAC_DATA_LBN 0
1903 #define FCN_MAC_DATA_WIDTH 32
1905 /* Transmit descriptor */
1906 #define FCN_TX_KER_PORT_LBN 63
1907 #define FCN_TX_KER_PORT_WIDTH 1
1908 #define FCN_TX_KER_BYTE_CNT_LBN 48
1909 #define FCN_TX_KER_BYTE_CNT_WIDTH 14
1910 #define FCN_TX_KER_BUF_ADR_LBN 0
1911 #define FCN_TX_KER_BUF_ADR_WIDTH EFAB_DMA_TYPE_WIDTH ( 46 )
1914 /* Receive descriptor */
1915 #define FCN_RX_KER_BUF_SIZE_LBN 48
1916 #define FCN_RX_KER_BUF_SIZE_WIDTH 14
1917 #define FCN_RX_KER_BUF_ADR_LBN 0
1918 #define FCN_RX_KER_BUF_ADR_WIDTH EFAB_DMA_TYPE_WIDTH ( 46 )
1920 /* Event queue entries */
1921 #define FCN_EV_CODE_LBN 60
1922 #define FCN_EV_CODE_WIDTH 4
1923 #define FCN_RX_IP_EV_DECODE 0
1924 #define FCN_TX_IP_EV_DECODE 2
1925 #define FCN_DRIVER_EV_DECODE 5
1927 /* Receive events */
1928 #define FCN_RX_EV_PKT_OK_LBN 56
1929 #define FCN_RX_EV_PKT_OK_WIDTH 1
1930 #define FCN_RX_PORT_LBN 30
1931 #define FCN_RX_PORT_WIDTH 1
1932 #define FCN_RX_EV_BYTE_CNT_LBN 16
1933 #define FCN_RX_EV_BYTE_CNT_WIDTH 14
1934 #define FCN_RX_EV_DESC_PTR_LBN 0
1935 #define FCN_RX_EV_DESC_PTR_WIDTH 12
1937 /* Transmit events */
1938 #define FCN_TX_EV_DESC_PTR_LBN 0
1939 #define FCN_TX_EV_DESC_PTR_WIDTH 12
1941 /* Fixed special buffer numbers to use */
1942 #define FALCON_EVQ_ID 0
1943 #define FALCON_TXD_ID 1
1944 #define FALCON_RXD_ID 2
1946 #if FALCON_USE_IO_BAR
1948 /* Write dword via the I/O BAR */
1949 static inline void _falcon_writel ( struct efab_nic *efab, uint32_t value,
1950 unsigned int reg ) {
1951 outl ( reg, efab->iobase + FCN_IOM_IND_ADR_REG );
1952 outl ( value, efab->iobase + FCN_IOM_IND_DAT_REG );
1955 /* Read dword via the I/O BAR */
1956 static inline uint32_t _falcon_readl ( struct efab_nic *efab,
1957 unsigned int reg ) {
1958 outl ( reg, efab->iobase + FCN_IOM_IND_ADR_REG );
1959 return inl ( efab->iobase + FCN_IOM_IND_DAT_REG );
1962 #else /* FALCON_USE_IO_BAR */
1964 #define _falcon_writel( efab, value, reg ) \
1965 writel ( (value), (efab)->membase + (reg) )
1966 #define _falcon_readl( efab, reg ) readl ( (efab)->membase + (reg) )
1968 #endif /* FALCON_USE_IO_BAR */
1971 * Write to a Falcon register
1974 static inline void falcon_write ( struct efab_nic *efab, efab_oword_t *value,
1975 unsigned int reg ) {
1977 EFAB_REGDUMP ( "Writing register %x with " EFAB_OWORD_FMT "\n",
1978 reg, EFAB_OWORD_VAL ( *value ) );
1980 _falcon_writel ( efab, value->u32[0], reg + 0 );
1981 _falcon_writel ( efab, value->u32[1], reg + 4 );
1982 _falcon_writel ( efab, value->u32[2], reg + 8 );
1983 _falcon_writel ( efab, value->u32[3], reg + 12 );
1988 * Write to Falcon SRAM
1991 static inline void falcon_write_sram ( struct efab_nic *efab,
1992 efab_qword_t *value,
1993 unsigned int index ) {
1994 unsigned int reg = ( FCN_BUF_FULL_TBL_KER +
1995 ( index * sizeof ( *value ) ) );
1997 EFAB_REGDUMP ( "Writing SRAM register %x with " EFAB_QWORD_FMT "\n",
1998 reg, EFAB_QWORD_VAL ( *value ) );
2000 _falcon_writel ( efab, value->u32[0], reg + 0 );
2001 _falcon_writel ( efab, value->u32[1], reg + 4 );
2006 * Write dword to Falcon register that allows partial writes
2009 static inline void falcon_writel ( struct efab_nic *efab, efab_dword_t *value,
2010 unsigned int reg ) {
2011 EFAB_REGDUMP ( "Writing partial register %x with " EFAB_DWORD_FMT "\n",
2012 reg, EFAB_DWORD_VAL ( *value ) );
2013 _falcon_writel ( efab, value->u32[0], reg );
2017 * Read from a Falcon register
2020 static inline void falcon_read ( struct efab_nic *efab, efab_oword_t *value,
2021 unsigned int reg ) {
2022 value->u32[0] = _falcon_readl ( efab, reg + 0 );
2023 value->u32[1] = _falcon_readl ( efab, reg + 4 );
2024 value->u32[2] = _falcon_readl ( efab, reg + 8 );
2025 value->u32[3] = _falcon_readl ( efab, reg + 12 );
2027 EFAB_REGDUMP ( "Read from register %x, got " EFAB_OWORD_FMT "\n",
2028 reg, EFAB_OWORD_VAL ( *value ) );
2032 * Read from Falcon SRAM
2035 static inline void falcon_read_sram ( struct efab_nic *efab,
2036 efab_qword_t *value,
2037 unsigned int index ) {
2038 unsigned int reg = ( FCN_BUF_FULL_TBL_KER +
2039 ( index * sizeof ( *value ) ) );
2041 value->u32[0] = _falcon_readl ( efab, reg + 0 );
2042 value->u32[1] = _falcon_readl ( efab, reg + 4 );
2043 EFAB_REGDUMP ( "Read from SRAM register %x, got " EFAB_QWORD_FMT "\n",
2044 reg, EFAB_QWORD_VAL ( *value ) );
2048 * Read dword from a portion of a Falcon register
2051 static inline void falcon_readl ( struct efab_nic *efab, efab_dword_t *value,
2052 unsigned int reg ) {
2053 value->u32[0] = _falcon_readl ( efab, reg );
2054 EFAB_REGDUMP ( "Read from register %x, got " EFAB_DWORD_FMT "\n",
2055 reg, EFAB_DWORD_VAL ( *value ) );
2059 * Verified write to Falcon SRAM
2062 static inline void falcon_write_sram_verify ( struct efab_nic *efab,
2063 efab_qword_t *value,
2064 unsigned int index ) {
2065 efab_qword_t verify;
2067 falcon_write_sram ( efab, value, index );
2069 falcon_read_sram ( efab, &verify, index );
2070 if ( memcmp ( &verify, value, sizeof ( verify ) ) != 0 ) {
2071 EFAB_ERR ( "SRAM index %x failure: wrote " EFAB_QWORD_FMT
2072 " got " EFAB_QWORD_FMT "\n", index,
2073 EFAB_QWORD_VAL ( *value ),
2074 EFAB_QWORD_VAL ( verify ) );
2082 static void falcon_get_membase ( struct efab_nic *efab ) {
2083 unsigned long membase_phys;
2085 membase_phys = pci_bar_start ( efab->pci, PCI_BASE_ADDRESS_2 );
2086 efab->membase = ioremap ( membase_phys, 0x20000 );
2089 #define FCN_DUMP_REG( efab, _reg ) do { \
2091 falcon_read ( efab, ®, _reg ); \
2092 EFAB_LOG ( #_reg " = " EFAB_OWORD_FMT "\n", \
2093 EFAB_OWORD_VAL ( reg ) ); \
2096 #define FCN_DUMP_MAC_REG( efab, _mac_reg ) do { \
2098 efab->mac_op->mac_readl ( efab, ®, _mac_reg ); \
2099 EFAB_LOG ( #_mac_reg " = " EFAB_DWORD_FMT "\n", \
2100 EFAB_DWORD_VAL ( reg ) ); \
2104 * Dump register contents (for debugging)
2106 * Marked as static inline so that it will not be compiled in if not
2109 static inline void falcon_dump_regs ( struct efab_nic *efab ) {
2110 FCN_DUMP_REG ( efab, FCN_INT_EN_REG_KER );
2111 FCN_DUMP_REG ( efab, FCN_INT_ADR_REG_KER );
2112 FCN_DUMP_REG ( efab, FCN_GLB_CTL_REG_KER );
2113 FCN_DUMP_REG ( efab, FCN_TIMER_CMD_REG_KER );
2114 FCN_DUMP_REG ( efab, FCN_SRM_RX_DC_CFG_REG_KER );
2115 FCN_DUMP_REG ( efab, FCN_SRM_TX_DC_CFG_REG_KER );
2116 FCN_DUMP_REG ( efab, FCN_RX_FILTER_CTL_REG_KER );
2117 FCN_DUMP_REG ( efab, FCN_RX_DC_CFG_REG_KER );
2118 FCN_DUMP_REG ( efab, FCN_TX_DC_CFG_REG_KER );
2119 FCN_DUMP_REG ( efab, FCN_MAC0_CTRL_REG_KER );
2120 FCN_DUMP_REG ( efab, FCN_MAC1_CTRL_REG_KER );
2121 FCN_DUMP_REG ( efab, FCN_RX_DESC_PTR_TBL_KER );
2122 FCN_DUMP_REG ( efab, FCN_TX_DESC_PTR_TBL_KER );
2123 FCN_DUMP_REG ( efab, FCN_EVQ_PTR_TBL_KER );
2124 FCN_DUMP_MAC_REG ( efab, GM_CFG1_REG_MAC );
2125 FCN_DUMP_MAC_REG ( efab, GM_CFG2_REG_MAC );
2126 FCN_DUMP_MAC_REG ( efab, GM_MAX_FLEN_REG_MAC );
2127 FCN_DUMP_MAC_REG ( efab, GM_MII_MGMT_CFG_REG_MAC );
2128 FCN_DUMP_MAC_REG ( efab, GM_ADR1_REG_MAC );
2129 FCN_DUMP_MAC_REG ( efab, GM_ADR2_REG_MAC );
2130 FCN_DUMP_MAC_REG ( efab, GMF_CFG0_REG_MAC );
2131 FCN_DUMP_MAC_REG ( efab, GMF_CFG1_REG_MAC );
2132 FCN_DUMP_MAC_REG ( efab, GMF_CFG2_REG_MAC );
2133 FCN_DUMP_MAC_REG ( efab, GMF_CFG3_REG_MAC );
2134 FCN_DUMP_MAC_REG ( efab, GMF_CFG4_REG_MAC );
2135 FCN_DUMP_MAC_REG ( efab, GMF_CFG5_REG_MAC );
2139 * Create special buffer
2142 static void falcon_create_special_buffer ( struct efab_nic *efab,
2143 void *addr, unsigned int index ) {
2144 efab_qword_t buf_desc;
2145 unsigned long dma_addr;
2147 memset ( addr, 0, 4096 );
2148 dma_addr = virt_to_bus ( addr );
2149 EFAB_ASSERT ( ( dma_addr & ( EFAB_BUF_ALIGN - 1 ) ) == 0 );
2150 EFAB_POPULATE_QWORD_3 ( buf_desc,
2151 FCN_IP_DAT_BUF_SIZE, FCN_IP_DAT_BUF_SIZE_4K,
2152 FCN_BUF_ADR_FBUF, ( dma_addr >> 12 ),
2153 FCN_BUF_OWNER_ID_FBUF, 0 );
2154 falcon_write_sram_verify ( efab, &buf_desc, index );
2158 * Update event queue read pointer
2161 static void falcon_eventq_read_ack ( struct efab_nic *efab ) {
2164 EFAB_ASSERT ( efab->eventq_read_ptr < EFAB_EVQ_SIZE );
2166 EFAB_POPULATE_DWORD_1 ( reg, FCN_EVQ_RPTR_DWORD,
2167 efab->eventq_read_ptr );
2168 falcon_writel ( efab, ®, FCN_EVQ_RPTR_REG_KER_DWORD );
2175 static int falcon_reset ( struct efab_nic *efab ) {
2176 efab_oword_t glb_ctl_reg_ker;
2178 /* Initiate software reset */
2179 EFAB_POPULATE_OWORD_7 ( glb_ctl_reg_ker,
2180 PCIE_CORE_RST_CTL, EXCLUDE_FROM_RESET,
2181 PCIE_NSTCK_RST_CTL, EXCLUDE_FROM_RESET,
2182 PCIE_SD_RST_CTL, EXCLUDE_FROM_RESET,
2183 EE_RST_CTL, EXCLUDE_FROM_RESET,
2184 PCIX_RST_CTL, EXCLUDE_FROM_RESET,
2185 EXT_PHY_RST_DUR, 0x7 /* datasheet recommended */,
2188 falcon_write ( efab, &glb_ctl_reg_ker, FCN_GLB_CTL_REG_KER );
2190 /* Allow 20ms for reset */
2193 /* Check for device reset complete */
2194 falcon_read ( efab, &glb_ctl_reg_ker, FCN_GLB_CTL_REG_KER );
2195 if ( EFAB_OWORD_FIELD ( glb_ctl_reg_ker, SWRST ) != 0 ) {
2196 EFAB_ERR ( "Reset failed\n" );
2204 struct efab_spi_device {
2206 unsigned int device_id;
2207 /** Address length (in bytes) */
2208 unsigned int addr_len;
2210 unsigned int read_command;
2214 * Wait for SPI command completion
2217 static int falcon_spi_wait ( struct efab_nic *efab ) {
2224 falcon_read ( efab, ®, FCN_EE_SPI_HCMD_REG_KER );
2225 if ( EFAB_OWORD_FIELD ( reg, FCN_EE_SPI_HCMD_CMD_EN ) == 0 )
2227 } while ( ++count < 1000 );
2228 printf ( "Timed out waiting for SPI\n" );
2236 static int falcon_spi_read ( struct efab_nic *efab,
2237 struct efab_spi_device *spi,
2238 int address, void *data, unsigned int len ) {
2241 /* Program address register */
2242 EFAB_POPULATE_OWORD_1 ( reg, FCN_EE_SPI_HADR_ADR, address );
2243 falcon_write ( efab, ®, FCN_EE_SPI_HADR_REG_KER );
2245 /* Issue read command */
2246 EFAB_POPULATE_OWORD_7 ( reg,
2247 FCN_EE_SPI_HCMD_CMD_EN, 1,
2248 FCN_EE_SPI_HCMD_SF_SEL, spi->device_id,
2249 FCN_EE_SPI_HCMD_DABCNT, len,
2250 FCN_EE_SPI_HCMD_READ, FCN_EE_SPI_READ,
2251 FCN_EE_SPI_HCMD_DUBCNT, 0,
2252 FCN_EE_SPI_HCMD_ADBCNT, spi->addr_len,
2253 FCN_EE_SPI_HCMD_ENC, spi->read_command );
2254 falcon_write ( efab, ®, FCN_EE_SPI_HCMD_REG_KER );
2256 /* Wait for read to complete */
2257 if ( ! falcon_spi_wait ( efab ) )
2261 falcon_read ( efab, ®, FCN_EE_SPI_HDATA_REG_KER );
2262 memcpy ( data, ®, len );
2267 #define SPI_READ_CMD 0x03
2268 #define AT25F1024_ADDR_LEN 3
2269 #define AT25F1024_READ_CMD SPI_READ_CMD
2270 #define MC25XX640_ADDR_LEN 2
2271 #define MC25XX640_READ_CMD SPI_READ_CMD
2273 /** Falcon Flash SPI device */
2274 static struct efab_spi_device falcon_spi_flash = {
2275 .device_id = FCN_EE_SPI_FLASH,
2276 .addr_len = AT25F1024_ADDR_LEN,
2277 .read_command = AT25F1024_READ_CMD,
2280 /** Falcon EEPROM SPI device */
2281 static struct efab_spi_device falcon_spi_large_eeprom = {
2282 .device_id = FCN_EE_SPI_EEPROM,
2283 .addr_len = MC25XX640_ADDR_LEN,
2284 .read_command = MC25XX640_READ_CMD,
2287 /** Offset of MAC address within EEPROM or Flash */
2288 #define FALCON_MAC_ADDRESS_OFFSET(port) ( 0x310 + 0x08 * (port) )
2291 * Read MAC address from EEPROM
2294 static int falcon_read_eeprom ( struct efab_nic *efab ) {
2295 struct efab_spi_device *spi;
2297 /* Determine the SPI device containing the MAC address */
2298 spi = efab->has_flash ? &falcon_spi_flash : &falcon_spi_large_eeprom;
2299 return falcon_spi_read ( efab, spi,
2300 FALCON_MAC_ADDRESS_OFFSET ( efab->port ),
2301 efab->mac_addr, sizeof ( efab->mac_addr ) );
2304 /** RX descriptor */
2305 typedef efab_qword_t falcon_rx_desc_t;
2308 * Build RX descriptor
2311 static void falcon_build_rx_desc ( struct efab_nic *efab,
2312 struct efab_rx_buf *rx_buf ) {
2313 falcon_rx_desc_t *rxd;
2315 rxd = ( ( falcon_rx_desc_t * ) efab->rxd ) + rx_buf->id;
2316 EFAB_POPULATE_QWORD_2 ( *rxd,
2317 FCN_RX_KER_BUF_SIZE, EFAB_DATA_BUF_SIZE,
2319 virt_to_bus ( rx_buf->addr ) );
2323 * Update RX descriptor write pointer
2326 static void falcon_notify_rx_desc ( struct efab_nic *efab ) {
2329 EFAB_POPULATE_DWORD_1 ( reg, FCN_RX_DESC_WPTR_DWORD,
2330 efab->rx_write_ptr );
2331 falcon_writel ( efab, ®, FCN_RX_DESC_UPD_REG_KER_DWORD );
2334 /** TX descriptor */
2335 typedef efab_qword_t falcon_tx_desc_t;
2338 * Build TX descriptor
2341 static void falcon_build_tx_desc ( struct efab_nic *efab,
2342 struct efab_tx_buf *tx_buf ) {
2343 falcon_rx_desc_t *txd;
2345 txd = ( ( falcon_rx_desc_t * ) efab->txd ) + tx_buf->id;
2346 EFAB_POPULATE_QWORD_3 ( *txd,
2347 FCN_TX_KER_PORT, efab->port,
2348 FCN_TX_KER_BYTE_CNT, tx_buf->len,
2350 virt_to_bus ( tx_buf->addr ) );
2354 * Update TX descriptor write pointer
2357 static void falcon_notify_tx_desc ( struct efab_nic *efab ) {
2360 EFAB_POPULATE_DWORD_1 ( reg, FCN_TX_DESC_WPTR_DWORD,
2361 efab->tx_write_ptr );
2362 falcon_writel ( efab, ®, FCN_TX_DESC_UPD_REG_KER_DWORD );
2366 typedef efab_qword_t falcon_event_t;
2369 * See if an event is present
2371 * @v event Falcon event structure
2372 * @ret True An event is pending
2373 * @ret False No event is pending
2375 * We check both the high and low dword of the event for all ones. We
2376 * wrote all ones when we cleared the event, and no valid event can
2377 * have all ones in either its high or low dwords. This approach is
2378 * robust against reordering.
2380 * Note that using a single 64-bit comparison is incorrect; even
2381 * though the CPU read will be atomic, the DMA write may not be.
2383 static inline int falcon_event_present ( falcon_event_t* event ) {
2384 return ( ! ( EFAB_DWORD_IS_ALL_ONES ( event->dword[0] ) |
2385 EFAB_DWORD_IS_ALL_ONES ( event->dword[1] ) ) );
2389 * Retrieve event from event queue
2392 static int falcon_fetch_event ( struct efab_nic *efab,
2393 struct efab_event *event ) {
2394 falcon_event_t *evt;
2398 /* Check for event */
2399 evt = ( ( falcon_event_t * ) efab->eventq ) + efab->eventq_read_ptr;
2400 if ( !falcon_event_present ( evt ) ) {
2405 DBG ( "Event is " EFAB_QWORD_FMT "\n", EFAB_QWORD_VAL ( *evt ) );
2408 ev_code = EFAB_QWORD_FIELD ( *evt, FCN_EV_CODE );
2410 switch ( ev_code ) {
2411 case FCN_TX_IP_EV_DECODE:
2412 event->type = EFAB_EV_TX;
2414 case FCN_RX_IP_EV_DECODE:
2415 event->type = EFAB_EV_RX;
2416 event->rx_id = EFAB_QWORD_FIELD ( *evt, FCN_RX_EV_DESC_PTR );
2417 event->rx_len = EFAB_QWORD_FIELD ( *evt, FCN_RX_EV_BYTE_CNT );
2418 event->drop = !EFAB_QWORD_FIELD ( *evt, FCN_RX_EV_PKT_OK );
2419 rx_port = EFAB_QWORD_FIELD ( *evt, FCN_RX_PORT );
2420 if ( rx_port != efab->port ) {
2421 /* Ignore packets on the wrong port. We can't
2422 * just set event->type = EFAB_EV_NONE,
2423 * because then the descriptor ring won't get
2429 case FCN_DRIVER_EV_DECODE:
2430 /* Ignore start-of-day events */
2431 event->type = EFAB_EV_NONE;
2434 EFAB_ERR ( "Unknown event type %d data %08lx\n", ev_code,
2435 EFAB_DWORD_FIELD ( *evt, EFAB_DWORD_0 ) );
2436 event->type = EFAB_EV_NONE;
2439 /* Clear event and any pending interrupts */
2440 EFAB_SET_QWORD ( *evt );
2441 falcon_writel ( efab, 0, FCN_INT_ACK_KER_REG );
2444 /* Increment and update event queue read pointer */
2445 efab->eventq_read_ptr = ( ( efab->eventq_read_ptr + 1 )
2447 falcon_eventq_read_ack ( efab );
2453 * Enable/disable/generate interrupt
2456 static inline void falcon_interrupts ( struct efab_nic *efab, int enabled,
2458 efab_oword_t int_en_reg_ker;
2460 EFAB_POPULATE_OWORD_2 ( int_en_reg_ker,
2461 FCN_KER_INT_KER, force,
2462 FCN_DRV_INT_EN_KER, enabled );
2463 falcon_write ( efab, &int_en_reg_ker, FCN_INT_EN_REG_KER );
2467 * Enable/disable interrupts
2470 static void falcon_mask_irq ( struct efab_nic *efab, int enabled ) {
2471 falcon_interrupts ( efab, enabled, 0 );
2473 /* Events won't trigger interrupts until we do this */
2474 falcon_eventq_read_ack ( efab );
2479 * Generate interrupt
2482 static void falcon_generate_irq ( struct efab_nic *efab ) {
2483 falcon_interrupts ( efab, 1, 1 );
2488 * Reconfigure MAC wrapper
2491 static void falcon_reconfigure_mac_wrapper ( struct efab_nic *efab ) {
2495 if ( efab->link_options & LPA_10000 ) {
2497 } else if ( efab->link_options & LPA_1000 ) {
2499 } else if ( efab->link_options & LPA_100 ) {
2504 EFAB_POPULATE_OWORD_5 ( reg,
2505 FCN_MAC_XOFF_VAL, 0xffff /* datasheet */,
2506 FCN_MAC_BCAD_ACPT, 1,
2508 FCN_MAC_LINK_STATUS, 1,
2509 FCN_MAC_SPEED, link_speed );
2510 falcon_write ( efab, ®,
2512 FCN_MAC0_CTRL_REG_KER : FCN_MAC1_CTRL_REG_KER ) );
2514 /* Disable flow-control (i.e. never generate pause frames) */
2515 falcon_read ( efab, ®, FCN_RX_CFG_REG_KER );
2516 EFAB_SET_OWORD_FIELD ( reg, FCN_RX_XOFF_EN, 0 );
2517 falcon_write ( efab, ®, FCN_RX_CFG_REG_KER );
2521 * Write dword to a Falcon MAC register
2524 static void falcon_gmac_writel ( struct efab_nic *efab,
2525 efab_dword_t *value, unsigned int mac_reg ) {
2528 EFAB_POPULATE_OWORD_1 ( temp, FCN_MAC_DATA,
2529 EFAB_DWORD_FIELD ( *value, FCN_MAC_DATA ) );
2530 falcon_write ( efab, &temp, FALCON_GMAC_REG ( efab, mac_reg ) );
2534 * Read dword from a Falcon GMAC register
2537 static void falcon_gmac_readl ( struct efab_nic *efab, efab_dword_t *value,
2538 unsigned int mac_reg ) {
2541 falcon_read ( efab, &temp, FALCON_GMAC_REG ( efab, mac_reg ) );
2542 EFAB_POPULATE_DWORD_1 ( *value, FCN_MAC_DATA,
2543 EFAB_OWORD_FIELD ( temp, FCN_MAC_DATA ) );
2547 * Write dword to a Falcon XMAC register
2550 static void falcon_xmac_writel ( struct efab_nic *efab,
2551 efab_dword_t *value, unsigned int mac_reg ) {
2554 EFAB_POPULATE_OWORD_1 ( temp, FCN_MAC_DATA,
2555 EFAB_DWORD_FIELD ( *value, FCN_MAC_DATA ) );
2556 falcon_write ( efab, &temp,
2557 FALCON_XMAC_REG ( efab, mac_reg ) );
2561 * Read dword from a Falcon XMAC register
2564 static void falcon_xmac_readl ( struct efab_nic *efab,
2565 efab_dword_t *value,
2566 unsigned int mac_reg ) {
2569 falcon_read ( efab, &temp,
2570 FALCON_XMAC_REG ( efab, mac_reg ) );
2571 EFAB_POPULATE_DWORD_1 ( *value, FCN_MAC_DATA,
2572 EFAB_OWORD_FIELD ( temp, FCN_MAC_DATA ) );
2579 static int falcon_init_gmac ( struct efab_nic *efab ) {
2580 static struct efab_mentormac_parameters falcon_mentormac_params = {
2581 .gmf_cfgfrth = 0x12,
2582 .gmf_cfgftth = 0x08,
2583 .gmf_cfghwmft = 0x1c,
2588 /* Initialise PHY */
2589 alaska_init ( efab );
2591 /* check the link is up */
2592 if ( !efab->link_up )
2595 /* Initialise MAC */
2596 mentormac_init ( efab, &falcon_mentormac_params );
2598 /* reconfigure the MAC wrapper */
2599 falcon_reconfigure_mac_wrapper ( efab );
2608 static int falcon_reset_gmac ( struct efab_nic *efab ) {
2609 mentormac_reset ( efab );
2614 * Reset XAUI/XGXS block
2617 static int falcon_reset_xaui ( struct efab_nic *efab )
2622 EFAB_POPULATE_DWORD_1 ( reg, FCN_XX_RST_XX_EN, 1 );
2623 efab->mac_op->mac_writel ( efab, ®, FCN_XX_PWR_RST_REG_MAC );
2625 for ( count = 0 ; count < 1000 ; count++ ) {
2627 efab->mac_op->mac_readl ( efab, ®,
2628 FCN_XX_PWR_RST_REG_MAC );
2629 if ( EFAB_DWORD_FIELD ( reg, FCN_XX_RST_XX_EN ) == 0 )
2633 /* an error of some kind */
2638 * Reset 10G MAC connected to port
2641 static int falcon_reset_xmac ( struct efab_nic *efab ) {
2645 EFAB_POPULATE_DWORD_1 ( reg, FCN_XM_CORE_RST, 1 );
2646 efab->mac_op->mac_writel ( efab, ®, FCN_XM_GLB_CFG_REG_MAC );
2648 for ( count = 0 ; count < 1000 ; count++ ) {
2650 efab->mac_op->mac_readl ( efab, ®,
2651 FCN_XM_GLB_CFG_REG_MAC );
2652 if ( EFAB_DWORD_FIELD ( reg, FCN_XM_CORE_RST ) == 0 )
2659 * Get status of 10G link
2662 static int falcon_xaui_link_ok ( struct efab_nic *efab ) {
2668 /* Read link status */
2669 efab->mac_op->mac_readl ( efab, ®, FCN_XX_CORE_STAT_REG_MAC );
2670 align_done = EFAB_DWORD_FIELD ( reg, FCN_XX_ALIGN_DONE );
2671 sync_status = EFAB_DWORD_FIELD ( reg, FCN_XX_SYNC_STAT );
2672 if ( align_done && ( sync_status == FCN_XX_SYNC_STAT_DECODE_SYNCED ) ) {
2676 /* Clear link status ready for next read */
2677 EFAB_SET_DWORD_FIELD ( reg, FCN_XX_COMMA_DET, FCN_XX_COMMA_DET_RESET );
2678 efab->mac_op->mac_writel ( efab, ®, FCN_XX_CORE_STAT_REG_MAC );
2687 static int falcon_init_xmac ( struct efab_nic *efab ) {
2691 if ( !falcon_reset_xmac ( efab ) ) {
2692 EFAB_ERR ( "failed resetting XMAC\n" );
2695 if ( !falcon_reset_xaui ( efab ) ) {
2696 EFAB_ERR ( "failed resetting XAUI\n");
2700 /* CX4 is always 10000FD only */
2701 efab->link_options = LPA_10000FULL;
2704 EFAB_POPULATE_DWORD_3 ( reg,
2705 FCN_XM_RX_JUMBO_MODE, 1,
2706 FCN_XM_TX_STAT_EN, 1,
2707 FCN_XM_RX_STAT_EN, 1);
2708 efab->mac_op->mac_writel ( efab, ®, FCN_XM_GLB_CFG_REG_MAC );
2711 EFAB_POPULATE_DWORD_6 ( reg,
2718 efab->mac_op->mac_writel ( efab, ®, FCN_XM_TX_CFG_REG_MAC );
2721 EFAB_POPULATE_DWORD_3 ( reg,
2723 FCN_XM_AUTO_DEPAD, 1,
2724 FCN_XM_PASS_CRC_ERR, 1 );
2725 efab->mac_op->mac_writel ( efab, ®, FCN_XM_RX_CFG_REG_MAC );
2727 /* Set frame length */
2728 EFAB_POPULATE_DWORD_1 ( reg,
2729 FCN_XM_MAX_RX_FRM_SIZE, ETH_FRAME_LEN );
2730 efab->mac_op->mac_writel ( efab, ®, FCN_XM_RX_PARAM_REG_MAC );
2731 EFAB_POPULATE_DWORD_2 ( reg,
2732 FCN_XM_MAX_TX_FRM_SIZE, ETH_FRAME_LEN,
2733 FCN_XM_TX_JUMBO_MODE, 1 );
2734 efab->mac_op->mac_writel ( efab, ®, FCN_XM_TX_PARAM_REG_MAC );
2736 /* Set MAC address */
2737 EFAB_POPULATE_DWORD_4 ( reg,
2738 FCN_XM_ADR_0, efab->mac_addr[0],
2739 FCN_XM_ADR_1, efab->mac_addr[1],
2740 FCN_XM_ADR_2, efab->mac_addr[2],
2741 FCN_XM_ADR_3, efab->mac_addr[3] );
2742 efab->mac_op->mac_writel ( efab, ®, FCN_XM_ADR_LO_REG_MAC );
2743 EFAB_POPULATE_DWORD_2 ( reg,
2744 FCN_XM_ADR_4, efab->mac_addr[4],
2745 FCN_XM_ADR_5, efab->mac_addr[5] );
2746 efab->mac_op->mac_writel ( efab, ®, FCN_XM_ADR_HI_REG_MAC );
2748 /* Reconfigure MAC wrapper */
2749 falcon_reconfigure_mac_wrapper ( efab );
2752 * Try resetting XAUI on its own waiting for the link
2755 for(count=0; count<5; count++) {
2756 /* Check link status */
2757 efab->link_up = falcon_xaui_link_ok ( efab );
2758 if ( efab->link_up ) {
2760 * Print out a speed message since we don't have a PHY
2762 EFAB_LOG ( "%dMbps %s-duplex\n",
2763 ( efab->link_options & LPA_10000 ? 1000 :
2764 ( efab->link_options & LPA_1000 ? 1000 :
2765 ( efab->link_options & LPA_100 ? 100 : 10 ) ) ),
2766 ( efab->link_options & LPA_DUPLEX ? "full" : "half" ) );
2770 if ( !falcon_reset_xaui ( efab ) ) {
2771 EFAB_ERR ( "failed resetting xaui\n" );
2781 * Wait for GMII access to complete
2784 static int falcon_gmii_wait ( struct efab_nic *efab ) {
2785 efab_oword_t md_stat;
2788 for ( count = 0 ; count < 1000 ; count++ ) {
2790 falcon_read ( efab, &md_stat, FCN_MD_STAT_REG_KER );
2791 if ( EFAB_OWORD_FIELD ( md_stat, FCN_MD_BSY ) == 0 )
2794 EFAB_ERR ( "Timed out waiting for GMII\n" );
2799 static struct efab_mac_operations falcon_xmac_operations = {
2800 .mac_readl = falcon_xmac_readl,
2801 .mac_writel = falcon_xmac_writel,
2802 .init = falcon_init_xmac,
2803 .reset = falcon_reset_xmac,
2806 static struct efab_mac_operations falcon_gmac_operations = {
2807 .mac_readl = falcon_gmac_readl,
2808 .mac_writel = falcon_gmac_writel,
2809 .init = falcon_init_gmac,
2810 .reset = falcon_reset_gmac,
2818 static int falcon_init_nic ( struct efab_nic *efab ) {
2820 efab_dword_t timer_cmd;
2823 /* use card in internal SRAM mode */
2824 falcon_read ( efab, ®, FCN_NIC_STAT_REG );
2825 EFAB_SET_OWORD_FIELD ( reg, ONCHIP_SRAM, 1 );
2826 falcon_write ( efab, ®, FCN_NIC_STAT_REG );
2829 /* identify FPGA/ASIC, and strapping mode */
2830 falcon_read ( efab, ®, ALTERA_BUILD_REG_KER );
2831 version = EFAB_OWORD_FIELD ( reg, VER_ALL );
2832 efab->is_asic = version ? 0 : 1;
2834 if ( efab->is_asic ) {
2835 falcon_read ( efab, ®, FCN_NIC_STAT_REG );
2836 if ( EFAB_OWORD_FIELD ( reg, STRAP_10G ) ) {
2839 if ( EFAB_OWORD_FIELD ( reg, STRAP_DUAL_PORT ) ) {
2844 falcon_read ( efab, ®, ALTERA_BUILD_REG_KER );
2845 minor = EFAB_OWORD_FIELD ( reg, VER_MINOR );
2847 if ( minor == 0x14 ) {
2849 } else if ( minor == 0x13 ) {
2854 EFAB_LOG ( "NIC type: %s %dx%s\n",
2855 efab->is_asic ? "ASIC" : "FPGA",
2856 efab->is_dual ? 2 : 1,
2857 efab->is_10g ? "10G" : "1G" );
2859 /* patch in MAC operations */
2861 efab->mac_op = &falcon_xmac_operations;
2863 efab->mac_op = &falcon_gmac_operations;
2865 if ( !efab->is_dual && ( efab->port == 1 ) ) {
2866 /* device doesn't exist */
2870 /* determine EEPROM / FLASH */
2871 if ( efab->is_asic ) {
2872 falcon_read ( efab, ®, FCN_NIC_STAT_REG );
2873 efab->has_flash = EFAB_OWORD_FIELD ( reg, SF_PRST );
2874 efab->has_eeprom = EFAB_OWORD_FIELD ( reg, EE_PRST );
2876 falcon_read ( efab, ®, FCN_GPIO_CTL_REG_KER );
2877 efab->has_flash = EFAB_OWORD_FIELD ( reg, FCN_FLASH_PRESENT );
2878 efab->has_eeprom = EFAB_OWORD_FIELD ( reg, FCN_EEPROM_PRESENT );
2881 EFAB_LOG ( "flash is %s, EEPROM is %s\n",
2882 ( efab->has_flash ? "present" : "absent" ),
2883 ( efab->has_eeprom ? "present" : "absent" ) );
2885 /* Set up TX and RX descriptor caches in SRAM */
2886 EFAB_POPULATE_OWORD_1 ( reg, FCN_SRM_TX_DC_BASE_ADR,
2887 0x130000 /* recommended in datasheet */ );
2888 falcon_write ( efab, ®, FCN_SRM_TX_DC_CFG_REG_KER );
2889 EFAB_POPULATE_OWORD_1 ( reg, FCN_TX_DC_SIZE, 2 /* 32 descriptors */ );
2890 falcon_write ( efab, ®, FCN_TX_DC_CFG_REG_KER );
2891 EFAB_POPULATE_OWORD_1 ( reg, FCN_SRM_RX_DC_BASE_ADR,
2892 0x100000 /* recommended in datasheet */ );
2893 falcon_write ( efab, ®, FCN_SRM_RX_DC_CFG_REG_KER );
2894 EFAB_POPULATE_OWORD_1 ( reg, FCN_RX_DC_SIZE, 2 /* 32 descriptors */ );
2895 falcon_write ( efab, ®, FCN_RX_DC_CFG_REG_KER );
2897 /* Set number of RSS CPUs */
2898 EFAB_POPULATE_OWORD_1 ( reg, FCN_NUM_KER, 0 );
2899 falcon_write ( efab, ®, FCN_RX_FILTER_CTL_REG_KER );
2903 mentormac_reset ( efab );
2905 /* Set up event queue */
2906 falcon_create_special_buffer ( efab, efab->eventq, FALCON_EVQ_ID );
2907 /* Fill eventq with all ones ( empty events ) */
2908 memset(efab->eventq, 0xff, 4096);
2909 /* push eventq to card */
2910 EFAB_POPULATE_OWORD_3 ( reg,
2912 FCN_EVQ_SIZE, FCN_EVQ_SIZE_512,
2913 FCN_EVQ_BUF_BASE_ID, FALCON_EVQ_ID );
2914 falcon_write ( efab, ®, FCN_EVQ_PTR_TBL_KER );
2917 /* Set timer register */
2918 EFAB_POPULATE_DWORD_2 ( timer_cmd,
2919 FCN_TIMER_MODE, FCN_TIMER_MODE_DIS,
2921 falcon_writel ( efab, &timer_cmd, FCN_TIMER_CMD_REG_KER );
2924 /* Initialise event queue read pointer */
2925 falcon_eventq_read_ack ( efab );
2927 /* Set up TX descriptor ring */
2928 falcon_create_special_buffer ( efab, efab->txd, FALCON_TXD_ID );
2929 EFAB_POPULATE_OWORD_5 ( reg,
2931 FCN_TX_DESCQ_BUF_BASE_ID, FALCON_TXD_ID,
2932 FCN_TX_DESCQ_EVQ_ID, 0,
2933 FCN_TX_DESCQ_SIZE, FCN_TX_DESCQ_SIZE_512,
2934 FCN_TX_DESCQ_TYPE, 0 /* kernel queue */ );
2935 falcon_write ( efab, ®, FCN_TX_DESC_PTR_TBL_KER );
2937 /* Set up RX descriptor ring */
2938 falcon_create_special_buffer ( efab, efab->rxd, FALCON_RXD_ID );
2939 EFAB_POPULATE_OWORD_6 ( reg,
2940 FCN_RX_DESCQ_BUF_BASE_ID, FALCON_RXD_ID,
2941 FCN_RX_DESCQ_EVQ_ID, 0,
2942 FCN_RX_DESCQ_SIZE, FCN_RX_DESCQ_SIZE_512,
2943 FCN_RX_DESCQ_TYPE, 0 /* kernel queue */,
2944 FCN_RX_DESCQ_JUMBO, 1,
2945 FCN_RX_DESCQ_EN, 1 );
2946 falcon_write ( efab, ®, FCN_RX_DESC_PTR_TBL_KER );
2948 /* Program INT_ADR_REG_KER */
2949 EFAB_POPULATE_OWORD_1 ( reg,
2951 virt_to_bus ( &efab->int_ker ) );
2952 falcon_write ( efab, ®, FCN_INT_ADR_REG_KER );
2959 static void falcon_mdio_write ( struct efab_nic *efab, int location,
2961 int phy_id = efab->port + 2;
2964 EFAB_TRACE ( "Writing GMII %d register %02x with %04x\n",
2965 phy_id, location, value );
2967 /* Check MII not currently being accessed */
2968 if ( ! falcon_gmii_wait ( efab ) )
2971 /* Write the address registers */
2972 EFAB_POPULATE_OWORD_1 ( reg, FCN_MD_PHY_ADR, 0 /* phy_id ? */ );
2973 falcon_write ( efab, ®, FCN_MD_PHY_ADR_REG_KER );
2975 EFAB_POPULATE_OWORD_2 ( reg,
2976 FCN_MD_PRT_ADR, phy_id,
2977 FCN_MD_DEV_ADR, location );
2978 falcon_write ( efab, ®, FCN_MD_ID_REG_KER );
2982 EFAB_POPULATE_OWORD_1 ( reg, FCN_MD_TXD, value );
2983 falcon_write ( efab, ®, FCN_MD_TXD_REG_KER );
2985 EFAB_POPULATE_OWORD_2 ( reg,
2988 falcon_write ( efab, ®, FCN_MD_CS_REG_KER );
2991 /* Wait for data to be written */
2992 falcon_gmii_wait ( efab );
2996 static int falcon_mdio_read ( struct efab_nic *efab, int location ) {
2997 int phy_id = efab->port + 2;
3001 /* Check MII not currently being accessed */
3002 if ( ! falcon_gmii_wait ( efab ) )
3005 /* Write the address registers */
3006 EFAB_POPULATE_OWORD_1 ( reg, FCN_MD_PHY_ADR, 0 /* phy_id ? */ );
3007 falcon_write ( efab, ®, FCN_MD_PHY_ADR_REG_KER );
3009 EFAB_POPULATE_OWORD_2 ( reg,
3010 FCN_MD_PRT_ADR, phy_id,
3011 FCN_MD_DEV_ADR, location );
3012 falcon_write ( efab, ®, FCN_MD_ID_REG_KER );
3015 /* Request data to be read */
3016 EFAB_POPULATE_OWORD_2 ( reg,
3019 falcon_write ( efab, ®, FCN_MD_CS_REG_KER );
3022 /* Wait for data to become available */
3023 falcon_gmii_wait ( efab );
3026 falcon_read ( efab, ®, FCN_MD_RXD_REG_KER );
3027 value = EFAB_OWORD_FIELD ( reg, FCN_MD_RXD );
3029 EFAB_TRACE ( "Read from GMII %d register %02x, got %04x\n",
3030 phy_id, location, value );
3035 static struct efab_operations falcon_operations = {
3036 .get_membase = falcon_get_membase,
3037 .reset = falcon_reset,
3038 .init_nic = falcon_init_nic,
3039 .read_eeprom = falcon_read_eeprom,
3040 .build_rx_desc = falcon_build_rx_desc,
3041 .notify_rx_desc = falcon_notify_rx_desc,
3042 .build_tx_desc = falcon_build_tx_desc,
3043 .notify_tx_desc = falcon_notify_tx_desc,
3044 .fetch_event = falcon_fetch_event,
3045 .mask_irq = falcon_mask_irq,
3046 .generate_irq = falcon_generate_irq,
3047 .mdio_write = falcon_mdio_write,
3048 .mdio_read = falcon_mdio_read,
3051 /**************************************************************************
3053 * Etherfabric abstraction layer
3055 **************************************************************************
3059 * Push RX buffer to RXD ring
3062 static inline void efab_push_rx_buffer ( struct efab_nic *efab,
3063 struct efab_rx_buf *rx_buf ) {
3064 /* Create RX descriptor */
3065 rx_buf->id = efab->rx_write_ptr;
3066 efab->op->build_rx_desc ( efab, rx_buf );
3068 /* Update RX write pointer */
3069 efab->rx_write_ptr = ( efab->rx_write_ptr + 1 ) % EFAB_RXD_SIZE;
3070 efab->op->notify_rx_desc ( efab );
3072 DBG ( "Added RX id %x\n", rx_buf->id );
3076 * Push TX buffer to TXD ring
3079 static inline void efab_push_tx_buffer ( struct efab_nic *efab,
3080 struct efab_tx_buf *tx_buf ) {
3081 /* Create TX descriptor */
3082 tx_buf->id = efab->tx_write_ptr;
3083 efab->op->build_tx_desc ( efab, tx_buf );
3085 /* Update TX write pointer */
3086 efab->tx_write_ptr = ( efab->tx_write_ptr + 1 ) % EFAB_TXD_SIZE;
3087 efab->op->notify_tx_desc ( efab );
3089 DBG ( "Added TX id %x\n", tx_buf->id );
3093 * Initialise MAC and wait for link up
3096 static int efab_init_mac ( struct efab_nic *efab ) {
3099 /* This can take several seconds */
3100 EFAB_LOG ( "Waiting for link.." );
3101 for ( count=0; count<5; count++ ) {
3104 if ( ! efab->mac_op->init ( efab ) ) {
3105 EFAB_ERR ( "Failed reinitialising MAC\n" );
3108 if ( efab->link_up ) {
3109 /* PHY init printed the message for us */
3112 EFAB_ERR( "link is down" );
3115 EFAB_ERR ( " timed initialising MAC\n " );
3124 static int efab_init_nic ( struct efab_nic *efab ) {
3127 /* Initialise NIC */
3128 if ( ! efab->op->init_nic ( efab ) )
3131 /* Push RX descriptors */
3132 for ( i = 0 ; i < EFAB_RX_BUFS ; i++ ) {
3133 efab_push_rx_buffer ( efab, &efab->rx_bufs[i] );
3136 /* Read MAC address from EEPROM */
3137 if ( ! efab->op->read_eeprom ( efab ) )
3139 efab->mac_addr[ETH_ALEN-1] += efab->port;
3141 /* Initialise MAC and wait for link up */
3142 if ( ! efab_init_mac ( efab ) )
3148 /**************************************************************************
3150 * Etherboot interface
3152 **************************************************************************
3155 /**************************************************************************
3156 POLL - Wait for a frame
3157 ***************************************************************************/
3158 static int etherfabric_poll ( struct nic *nic, int retrieve ) {
3159 struct efab_nic *efab = nic->priv_data;
3160 struct efab_event event;
3161 static struct efab_rx_buf *rx_buf = NULL;
3164 /* Process the event queue until we hit either a packet
3165 * received event or an empty event slot.
3167 while ( ( rx_buf == NULL ) &&
3168 efab->op->fetch_event ( efab, &event ) ) {
3170 if ( event.type == EFAB_EV_TX ) {
3171 /* TX completed - mark as done */
3172 DBG ( "TX id %x complete\n",
3174 } else if ( event.type == EFAB_EV_RX ) {
3175 /* RX - find corresponding buffer */
3176 for ( i = 0 ; i < EFAB_RX_BUFS ; i++ ) {
3177 if ( efab->rx_bufs[i].id == event.rx_id ) {
3178 rx_buf = &efab->rx_bufs[i];
3179 rx_buf->len = event.rx_len;
3180 DBG ( "RX id %x (len %x) received\n",
3181 rx_buf->id, rx_buf->len );
3186 EFAB_ERR ( "Invalid RX ID %x\n", event.rx_id );
3188 } else if ( event.type == EFAB_EV_NONE ) {
3189 DBG ( "Ignorable event\n" );
3191 DBG ( "Unknown event\n" );
3195 /* If there is no packet, return 0 */
3199 /* drop this event if necessary */
3201 DBG( "discarding RX event\n" );
3205 /* If we don't want to retrieve it just yet, return 1 */
3209 /* There seems to be a hardware race. The event can show up
3210 * on the event FIFO before the DMA has completed, so we
3211 * insert a tiny delay. If this proves unreliable, we should
3212 * switch to using event DMA rather than the event FIFO, since
3213 * event DMA ordering is guaranteed.
3217 /* Copy packet contents */
3218 nic->packetlen = rx_buf->len;
3219 memcpy ( nic->packet, rx_buf->addr, nic->packetlen );
3221 /* Give this buffer back to the NIC */
3222 efab_push_rx_buffer ( efab, rx_buf );
3224 /* Prepare to receive next packet */
3230 /**************************************************************************
3231 TRANSMIT - Transmit a frame
3232 ***************************************************************************/
3233 static void etherfabric_transmit ( struct nic *nic, const char *dest,
3234 unsigned int type, unsigned int size,
3235 const char *data ) {
3236 struct efab_nic *efab = nic->priv_data;
3237 unsigned int nstype = htons ( type );
3239 /* Fill TX buffer, pad to ETH_ZLEN */
3240 memcpy ( efab->tx_buf.addr, dest, ETH_ALEN );
3241 memcpy ( efab->tx_buf.addr + ETH_ALEN, nic->node_addr, ETH_ALEN );
3242 memcpy ( efab->tx_buf.addr + 2 * ETH_ALEN, &nstype, 2 );
3243 memcpy ( efab->tx_buf.addr + ETH_HLEN, data, size );
3245 while ( size < ETH_ZLEN ) {
3246 efab->tx_buf.addr[size++] = '\0';
3248 efab->tx_buf.len = size;
3250 /* Push TX descriptor */
3251 efab_push_tx_buffer ( efab, &efab->tx_buf );
3253 /* Allow enough time for the packet to be transmitted. This
3254 * is a temporary hack until we update to the new driver API.
3261 /**************************************************************************
3262 DISABLE - Turn off ethernet interface
3263 ***************************************************************************/
3264 static void etherfabric_disable ( struct nic *nic ) {
3265 struct efab_nic *efab = nic->priv_data;
3267 efab->op->reset ( efab );
3268 if ( efab->membase )
3269 iounmap ( efab->membase );
3272 /**************************************************************************
3273 IRQ - handle interrupts
3274 ***************************************************************************/
3275 static void etherfabric_irq ( struct nic *nic, irq_action_t action ) {
3276 struct efab_nic *efab = nic->priv_data;
3280 efab->op->mask_irq ( efab, 1 );
3283 efab->op->mask_irq ( efab, 0 );
3286 /* Force NIC to generate a receive interrupt */
3287 efab->op->generate_irq ( efab );
3294 static struct nic_operations etherfabric_operations = {
3295 .connect = dummy_connect,
3296 .poll = etherfabric_poll,
3297 .transmit = etherfabric_transmit,
3298 .irq = etherfabric_irq,
3301 /**************************************************************************
3302 PROBE - Look for an adapter, this routine's visible to the outside
3303 ***************************************************************************/
3304 static int etherfabric_probe ( struct nic *nic, struct pci_device *pci ) {
3305 static struct efab_nic efab;
3306 static int nic_port = 1;
3307 struct efab_buffers *buffers;
3310 /* Set up our private data structure */
3311 nic->priv_data = &efab;
3312 memset ( &efab, 0, sizeof ( efab ) );
3313 memset ( &efab_buffers, 0, sizeof ( efab_buffers ) );
3315 /* Hook in appropriate operations table. Do this early. */
3316 if ( pci->device == EF1002_DEVID ) {
3317 efab.op = &ef1002_operations;
3319 efab.op = &falcon_operations;
3322 /* Initialise efab data structure */
3324 buffers = ( ( struct efab_buffers * )
3325 ( ( ( void * ) &efab_buffers ) +
3326 ( - virt_to_bus ( &efab_buffers ) ) % EFAB_BUF_ALIGN ) );
3327 efab.eventq = buffers->eventq;
3328 efab.txd = buffers->txd;
3329 efab.rxd = buffers->rxd;
3330 efab.tx_buf.addr = buffers->tx_buf;
3331 for ( i = 0 ; i < EFAB_RX_BUFS ; i++ ) {
3332 efab.rx_bufs[i].addr = buffers->rx_buf[i];
3335 /* Enable the PCI device */
3336 adjust_pci_device ( pci );
3337 nic->ioaddr = pci->ioaddr & ~3;
3338 nic->irqno = pci->irq;
3340 /* Get iobase/membase */
3341 efab.iobase = nic->ioaddr;
3342 efab.op->get_membase ( &efab );
3344 /* Switch NIC ports (i.e. try different ports on each probe) */
3345 nic_port = 1 - nic_port;
3346 efab.port = nic_port;
3348 /* Initialise hardware */
3349 if ( ! efab_init_nic ( &efab ) )
3351 memcpy ( nic->node_addr, efab.mac_addr, ETH_ALEN );
3353 /* point to NIC specific routines */
3354 nic->nic_op = ðerfabric_operations;
3359 static struct pci_device_id etherfabric_nics[] = {
3360 PCI_ROM(0x1924, 0xC101, "ef1002", "EtherFabric EF1002"),
3361 PCI_ROM(0x1924, 0x0703, "falcon", "EtherFabric Falcon"),
3364 PCI_DRIVER ( etherfabric_driver, etherfabric_nics, PCI_NO_CLASS );
3366 DRIVER ( "EFAB", nic_driver, pci_driver, etherfabric_driver,
3367 etherfabric_probe, etherfabric_disable );