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(...)
45 #define EFAB_REGDUMP(...)
47 #define FALCON_USE_IO_BAR 1
50 * EtherFabric constants
55 #define EFAB_VENDID_LEVEL5 0x1924
56 #define FALCON_P_DEVID 0x0703 /* Temporary PCI ID */
57 #define EF1002_DEVID 0xC101
59 /**************************************************************************
63 **************************************************************************
67 * Buffers used for TX, RX and event queue
70 #define EFAB_BUF_ALIGN 4096
71 #define EFAB_DATA_BUF_SIZE 2048
72 #define EFAB_RX_BUFS 16
73 #define EFAB_RXD_SIZE 512
74 #define EFAB_TXD_SIZE 512
75 #define EFAB_EVQ_SIZE 512
80 uint8_t tx_buf[EFAB_DATA_BUF_SIZE];
81 uint8_t rx_buf[EFAB_RX_BUFS][EFAB_DATA_BUF_SIZE];
82 uint8_t padding[EFAB_BUF_ALIGN-1];
84 static struct efab_buffers efab_buffers;
100 /** Etherfabric event type */
101 enum efab_event_type {
107 /** Etherfabric event */
110 enum efab_event_type type;
118 * Etherfabric abstraction layer
122 struct efab_operations {
123 void ( * get_membase ) ( struct efab_nic *efab );
124 int ( * reset ) ( struct efab_nic *efab );
125 int ( * init_nic ) ( struct efab_nic *efab );
126 int ( * read_eeprom ) ( struct efab_nic *efab );
127 void ( * build_rx_desc ) ( struct efab_nic *efab,
128 struct efab_rx_buf *rx_buf );
129 void ( * notify_rx_desc ) ( struct efab_nic *efab );
130 void ( * build_tx_desc ) ( struct efab_nic *efab,
131 struct efab_tx_buf *tx_buf );
132 void ( * notify_tx_desc ) ( struct efab_nic *efab );
133 int ( * fetch_event ) ( struct efab_nic *efab,
134 struct efab_event *event );
135 void ( * mask_irq ) ( struct efab_nic *efab, int enabled );
136 void ( * generate_irq ) ( struct efab_nic *efab );
137 void ( * mac_writel ) ( struct efab_nic *efab, efab_dword_t *value,
138 unsigned int mac_reg );
139 void ( * mac_readl ) ( struct efab_nic *efab, efab_dword_t *value,
140 unsigned int mac_reg );
141 int ( * init_mac ) ( struct efab_nic *efab );
142 void ( * mdio_write ) ( struct efab_nic *efab, int location,
144 int ( * mdio_read ) ( struct efab_nic *efab, int location );
148 * Driver private data structure
154 struct pci_device *pci;
156 /** Operations table */
157 struct efab_operations *op;
166 uint8_t *eventq; /* Falcon only */
167 uint8_t *txd; /* Falcon only */
168 uint8_t *rxd; /* Falcon only */
169 struct efab_tx_buf tx_buf;
170 struct efab_rx_buf rx_bufs[EFAB_RX_BUFS];
172 /** Buffer pointers */
173 unsigned int eventq_read_ptr; /* Falcon only */
174 unsigned int tx_write_ptr;
175 unsigned int rx_write_ptr;
178 /** Port 0/1 on the NIC */
182 uint8_t mac_addr[ETH_ALEN];
183 /** GMII link options */
184 unsigned int link_options;
188 /** INT_REG_KER for Falcon */
189 efab_oword_t int_ker __attribute__ (( aligned ( 16 ) ));
192 struct i2c_bit_basher ef1002_i2c;
193 unsigned long ef1002_i2c_outputs;
194 struct i2c_device ef1002_eeprom;
197 /**************************************************************************
201 **************************************************************************
205 #define MII_BMSR 0x01 /* Basic mode status register */
206 #define MII_ADVERTISE 0x04 /* Advertisement control register */
207 #define MII_LPA 0x05 /* Link partner ability register*/
208 #define GMII_GTCR 0x09 /* 1000BASE-T control register */
209 #define GMII_GTSR 0x0a /* 1000BASE-T status register */
210 #define GMII_PSSR 0x11 /* PHY-specific status register */
212 /* Basic mode status register. */
213 #define BMSR_LSTATUS 0x0004 /* Link status */
215 /* Link partner ability register. */
216 #define LPA_10HALF 0x0020 /* Can do 10mbps half-duplex */
217 #define LPA_10FULL 0x0040 /* Can do 10mbps full-duplex */
218 #define LPA_100HALF 0x0080 /* Can do 100mbps half-duplex */
219 #define LPA_100FULL 0x0100 /* Can do 100mbps full-duplex */
220 #define LPA_100BASE4 0x0200 /* Can do 100mbps 4k packets */
221 #define LPA_PAUSE 0x0400 /* Bit 10 - MAC pause */
223 /* Pseudo extensions to the link partner ability register */
224 #define LPA_1000FULL 0x00020000
225 #define LPA_1000HALF 0x00010000
227 #define LPA_100 (LPA_100FULL | LPA_100HALF | LPA_100BASE4)
228 #define LPA_1000 ( LPA_1000FULL | LPA_1000HALF )
229 #define LPA_DUPLEX ( LPA_10FULL | LPA_100FULL | LPA_1000FULL )
231 /* Mask of bits not associated with speed or duplexity. */
232 #define LPA_OTHER ~( LPA_10FULL | LPA_10HALF | LPA_100FULL | \
233 LPA_100HALF | LPA_1000FULL | LPA_1000HALF )
235 /* PHY-specific status register */
236 #define PSSR_LSTATUS 0x0400 /* Bit 10 - link status */
239 * Retrieve GMII autonegotiation advertised abilities
242 static unsigned int gmii_autoneg_advertised ( struct efab_nic *efab ) {
243 unsigned int mii_advertise;
244 unsigned int gmii_advertise;
246 /* Extended bits are in bits 8 and 9 of GMII_GTCR */
247 mii_advertise = efab->op->mdio_read ( efab, MII_ADVERTISE );
248 gmii_advertise = ( ( efab->op->mdio_read ( efab, GMII_GTCR ) >> 8 )
250 return ( ( gmii_advertise << 16 ) | mii_advertise );
254 * Retrieve GMII autonegotiation link partner abilities
257 static unsigned int gmii_autoneg_lpa ( struct efab_nic *efab ) {
258 unsigned int mii_lpa;
259 unsigned int gmii_lpa;
261 /* Extended bits are in bits 10 and 11 of GMII_GTSR */
262 mii_lpa = efab->op->mdio_read ( efab, MII_LPA );
263 gmii_lpa = ( efab->op->mdio_read ( efab, GMII_GTSR ) >> 10 ) & 0x03;
264 return ( ( gmii_lpa << 16 ) | mii_lpa );
268 * Calculate GMII autonegotiated link technology
271 static unsigned int gmii_nway_result ( unsigned int negotiated ) {
272 unsigned int other_bits;
274 /* Mask out the speed and duplexity bits */
275 other_bits = negotiated & LPA_OTHER;
277 if ( negotiated & LPA_1000FULL )
278 return ( other_bits | LPA_1000FULL );
279 else if ( negotiated & LPA_1000HALF )
280 return ( other_bits | LPA_1000HALF );
281 else if ( negotiated & LPA_100FULL )
282 return ( other_bits | LPA_100FULL );
283 else if ( negotiated & LPA_100BASE4 )
284 return ( other_bits | LPA_100BASE4 );
285 else if ( negotiated & LPA_100HALF )
286 return ( other_bits | LPA_100HALF );
287 else if ( negotiated & LPA_10FULL )
288 return ( other_bits | LPA_10FULL );
289 else return ( other_bits | LPA_10HALF );
293 * Check GMII PHY link status
296 static int gmii_link_ok ( struct efab_nic *efab ) {
300 /* BMSR is latching - it returns "link down" if the link has
301 * been down at any point since the last read. To get a
302 * real-time status, we therefore read the register twice and
303 * use the result of the second read.
305 efab->op->mdio_read ( efab, MII_BMSR );
306 status = efab->op->mdio_read ( efab, MII_BMSR );
308 /* Read the PHY-specific Status Register. This is
309 * non-latching, so we need do only a single read.
311 phy_status = efab->op->mdio_read ( efab, GMII_PSSR );
313 return ( ( status & BMSR_LSTATUS ) && ( phy_status & PSSR_LSTATUS ) );
316 /**************************************************************************
320 **************************************************************************
324 * Initialise Alaska PHY
327 static void alaska_init ( struct efab_nic *efab ) {
328 unsigned int advertised, lpa;
330 /* Read link up status */
331 efab->link_up = gmii_link_ok ( efab );
333 if ( ! efab->link_up )
336 /* Determine link options from PHY. */
337 advertised = gmii_autoneg_advertised ( efab );
338 lpa = gmii_autoneg_lpa ( efab );
339 efab->link_options = gmii_nway_result ( advertised & lpa );
341 printf ( "%dMbps %s-duplex (%04x,%04x)\n",
342 ( efab->link_options & LPA_1000 ? 1000 :
343 ( efab->link_options & LPA_100 ? 100 : 10 ) ),
344 ( efab->link_options & LPA_DUPLEX ? "full" : "half" ),
348 /**************************************************************************
352 **************************************************************************
355 /* GMAC configuration register 1 */
356 #define GM_CFG1_REG_MAC 0x00
357 #define GM_SW_RST_LBN 31
358 #define GM_SW_RST_WIDTH 1
359 #define GM_RX_FC_EN_LBN 5
360 #define GM_RX_FC_EN_WIDTH 1
361 #define GM_TX_FC_EN_LBN 4
362 #define GM_TX_FC_EN_WIDTH 1
363 #define GM_RX_EN_LBN 2
364 #define GM_RX_EN_WIDTH 1
365 #define GM_TX_EN_LBN 0
366 #define GM_TX_EN_WIDTH 1
368 /* GMAC configuration register 2 */
369 #define GM_CFG2_REG_MAC 0x01
370 #define GM_PAMBL_LEN_LBN 12
371 #define GM_PAMBL_LEN_WIDTH 4
372 #define GM_IF_MODE_LBN 8
373 #define GM_IF_MODE_WIDTH 2
374 #define GM_PAD_CRC_EN_LBN 2
375 #define GM_PAD_CRC_EN_WIDTH 1
377 #define GM_FD_WIDTH 1
379 /* GMAC maximum frame length register */
380 #define GM_MAX_FLEN_REG_MAC 0x04
381 #define GM_MAX_FLEN_LBN 0
382 #define GM_MAX_FLEN_WIDTH 16
384 /* GMAC MII management configuration register */
385 #define GM_MII_MGMT_CFG_REG_MAC 0x08
386 #define GM_MGMT_CLK_SEL_LBN 0
387 #define GM_MGMT_CLK_SEL_WIDTH 3
389 /* GMAC MII management command register */
390 #define GM_MII_MGMT_CMD_REG_MAC 0x09
391 #define GM_MGMT_SCAN_CYC_LBN 1
392 #define GM_MGMT_SCAN_CYC_WIDTH 1
393 #define GM_MGMT_RD_CYC_LBN 0
394 #define GM_MGMT_RD_CYC_WIDTH 1
396 /* GMAC MII management address register */
397 #define GM_MII_MGMT_ADR_REG_MAC 0x0a
398 #define GM_MGMT_PHY_ADDR_LBN 8
399 #define GM_MGMT_PHY_ADDR_WIDTH 5
400 #define GM_MGMT_REG_ADDR_LBN 0
401 #define GM_MGMT_REG_ADDR_WIDTH 5
403 /* GMAC MII management control register */
404 #define GM_MII_MGMT_CTL_REG_MAC 0x0b
405 #define GM_MGMT_CTL_LBN 0
406 #define GM_MGMT_CTL_WIDTH 16
408 /* GMAC MII management status register */
409 #define GM_MII_MGMT_STAT_REG_MAC 0x0c
410 #define GM_MGMT_STAT_LBN 0
411 #define GM_MGMT_STAT_WIDTH 16
413 /* GMAC MII management indicators register */
414 #define GM_MII_MGMT_IND_REG_MAC 0x0d
415 #define GM_MGMT_BUSY_LBN 0
416 #define GM_MGMT_BUSY_WIDTH 1
418 /* GMAC station address register 1 */
419 #define GM_ADR1_REG_MAC 0x10
420 #define GM_HWADDR_5_LBN 24
421 #define GM_HWADDR_5_WIDTH 8
422 #define GM_HWADDR_4_LBN 16
423 #define GM_HWADDR_4_WIDTH 8
424 #define GM_HWADDR_3_LBN 8
425 #define GM_HWADDR_3_WIDTH 8
426 #define GM_HWADDR_2_LBN 0
427 #define GM_HWADDR_2_WIDTH 8
429 /* GMAC station address register 2 */
430 #define GM_ADR2_REG_MAC 0x11
431 #define GM_HWADDR_1_LBN 24
432 #define GM_HWADDR_1_WIDTH 8
433 #define GM_HWADDR_0_LBN 16
434 #define GM_HWADDR_0_WIDTH 8
436 /* GMAC FIFO configuration register 0 */
437 #define GMF_CFG0_REG_MAC 0x12
438 #define GMF_FTFENREQ_LBN 12
439 #define GMF_FTFENREQ_WIDTH 1
440 #define GMF_STFENREQ_LBN 11
441 #define GMF_STFENREQ_WIDTH 1
442 #define GMF_FRFENREQ_LBN 10
443 #define GMF_FRFENREQ_WIDTH 1
444 #define GMF_SRFENREQ_LBN 9
445 #define GMF_SRFENREQ_WIDTH 1
446 #define GMF_WTMENREQ_LBN 8
447 #define GMF_WTMENREQ_WIDTH 1
449 /* GMAC FIFO configuration register 1 */
450 #define GMF_CFG1_REG_MAC 0x13
451 #define GMF_CFGFRTH_LBN 16
452 #define GMF_CFGFRTH_WIDTH 5
453 #define GMF_CFGXOFFRTX_LBN 0
454 #define GMF_CFGXOFFRTX_WIDTH 16
456 /* GMAC FIFO configuration register 2 */
457 #define GMF_CFG2_REG_MAC 0x14
458 #define GMF_CFGHWM_LBN 16
459 #define GMF_CFGHWM_WIDTH 6
460 #define GMF_CFGLWM_LBN 0
461 #define GMF_CFGLWM_WIDTH 6
463 /* GMAC FIFO configuration register 3 */
464 #define GMF_CFG3_REG_MAC 0x15
465 #define GMF_CFGHWMFT_LBN 16
466 #define GMF_CFGHWMFT_WIDTH 6
467 #define GMF_CFGFTTH_LBN 0
468 #define GMF_CFGFTTH_WIDTH 6
470 /* GMAC FIFO configuration register 4 */
471 #define GMF_CFG4_REG_MAC 0x16
472 #define GMF_HSTFLTRFRM_PAUSE_LBN 12
473 #define GMF_HSTFLTRFRM_PAUSE_WIDTH 12
475 /* GMAC FIFO configuration register 5 */
476 #define GMF_CFG5_REG_MAC 0x17
477 #define GMF_CFGHDPLX_LBN 22
478 #define GMF_CFGHDPLX_WIDTH 1
479 #define GMF_CFGBYTMODE_LBN 19
480 #define GMF_CFGBYTMODE_WIDTH 1
481 #define GMF_HSTDRPLT64_LBN 18
482 #define GMF_HSTDRPLT64_WIDTH 1
483 #define GMF_HSTFLTRFRMDC_PAUSE_LBN 12
484 #define GMF_HSTFLTRFRMDC_PAUSE_WIDTH 1
486 struct efab_mentormac_parameters {
498 static void mentormac_reset ( struct efab_nic *efab ) {
502 /* Take into reset */
503 EFAB_POPULATE_DWORD_1 ( reg, GM_SW_RST, 1 );
504 efab->op->mac_writel ( efab, ®, GM_CFG1_REG_MAC );
507 /* Take out of reset */
508 EFAB_POPULATE_DWORD_1 ( reg, GM_SW_RST, 0 );
509 efab->op->mac_writel ( efab, ®, GM_CFG1_REG_MAC );
512 /* Mentor MAC connects both PHYs to MAC 0 */
513 save_port = efab->port;
515 /* Configure GMII interface so PHY is accessible. Note that
516 * GMII interface is connected only to port 0, and that on
517 * Falcon this is a no-op.
519 EFAB_POPULATE_DWORD_1 ( reg, GM_MGMT_CLK_SEL, 0x4 );
520 efab->op->mac_writel ( efab, ®, GM_MII_MGMT_CFG_REG_MAC );
522 efab->port = save_port;
526 * Initialise Mentor MAC
529 static void mentormac_init ( struct efab_nic *efab,
530 struct efab_mentormac_parameters *params ) {
531 int pause, if_mode, full_duplex, bytemode, half_duplex;
534 /* Configuration register 1 */
535 pause = ( efab->link_options & LPA_PAUSE ) ? 1 : 0;
536 if ( ! ( efab->link_options & LPA_DUPLEX ) ) {
537 /* Half-duplex operation requires TX flow control */
540 EFAB_POPULATE_DWORD_4 ( reg,
545 efab->op->mac_writel ( efab, ®, GM_CFG1_REG_MAC );
548 /* Configuration register 2 */
549 if_mode = ( efab->link_options & LPA_1000 ) ? 2 : 1;
550 full_duplex = ( efab->link_options & LPA_DUPLEX ) ? 1 : 0;
551 EFAB_POPULATE_DWORD_4 ( reg,
555 GM_PAMBL_LEN, 0x7 /* ? */ );
556 efab->op->mac_writel ( efab, ®, GM_CFG2_REG_MAC );
559 /* Max frame len register */
560 EFAB_POPULATE_DWORD_1 ( reg, GM_MAX_FLEN, ETH_FRAME_LEN + 4 /* FCS */);
561 efab->op->mac_writel ( efab, ®, GM_MAX_FLEN_REG_MAC );
564 /* FIFO configuration register 0 */
565 EFAB_POPULATE_DWORD_5 ( reg,
571 efab->op->mac_writel ( efab, ®, GMF_CFG0_REG_MAC );
574 /* FIFO configuration register 1 */
575 EFAB_POPULATE_DWORD_2 ( reg,
576 GMF_CFGFRTH, params->gmf_cfgfrth,
577 GMF_CFGXOFFRTX, 0xffff );
578 efab->op->mac_writel ( efab, ®, GMF_CFG1_REG_MAC );
581 /* FIFO configuration register 2 */
582 EFAB_POPULATE_DWORD_2 ( reg,
583 GMF_CFGHWM, params->gmf_cfghwm,
584 GMF_CFGLWM, params->gmf_cfglwm );
585 efab->op->mac_writel ( efab, ®, GMF_CFG2_REG_MAC );
588 /* FIFO configuration register 3 */
589 EFAB_POPULATE_DWORD_2 ( reg,
590 GMF_CFGHWMFT, params->gmf_cfghwmft,
591 GMF_CFGFTTH, params->gmf_cfgftth );
592 efab->op->mac_writel ( efab, ®, GMF_CFG3_REG_MAC );
595 /* FIFO configuration register 4 */
596 EFAB_POPULATE_DWORD_1 ( reg, GMF_HSTFLTRFRM_PAUSE, 1 );
597 efab->op->mac_writel ( efab, ®, GMF_CFG4_REG_MAC );
600 /* FIFO configuration register 5 */
601 bytemode = ( efab->link_options & LPA_1000 ) ? 1 : 0;
602 half_duplex = ( efab->link_options & LPA_DUPLEX ) ? 0 : 1;
603 efab->op->mac_readl ( efab, ®, GMF_CFG5_REG_MAC );
604 EFAB_SET_DWORD_FIELD ( reg, GMF_CFGBYTMODE, bytemode );
605 EFAB_SET_DWORD_FIELD ( reg, GMF_CFGHDPLX, half_duplex );
606 EFAB_SET_DWORD_FIELD ( reg, GMF_HSTDRPLT64, half_duplex );
607 EFAB_SET_DWORD_FIELD ( reg, GMF_HSTFLTRFRMDC_PAUSE, 0 );
608 efab->op->mac_writel ( efab, ®, GMF_CFG5_REG_MAC );
612 EFAB_POPULATE_DWORD_4 ( reg,
613 GM_HWADDR_5, efab->mac_addr[5],
614 GM_HWADDR_4, efab->mac_addr[4],
615 GM_HWADDR_3, efab->mac_addr[3],
616 GM_HWADDR_2, efab->mac_addr[2] );
617 efab->op->mac_writel ( efab, ®, GM_ADR1_REG_MAC );
619 EFAB_POPULATE_DWORD_2 ( reg,
620 GM_HWADDR_1, efab->mac_addr[1],
621 GM_HWADDR_0, efab->mac_addr[0] );
622 efab->op->mac_writel ( efab, ®, GM_ADR2_REG_MAC );
627 * Wait for GMII access to complete
630 static int mentormac_gmii_wait ( struct efab_nic *efab ) {
632 efab_dword_t indicator;
634 for ( count = 0 ; count < 1000 ; count++ ) {
636 efab->op->mac_readl ( efab, &indicator,
637 GM_MII_MGMT_IND_REG_MAC );
638 if ( EFAB_DWORD_FIELD ( indicator, GM_MGMT_BUSY ) == 0 )
641 printf ( "Timed out waiting for GMII\n" );
646 * Write a GMII register
649 static void mentormac_mdio_write ( struct efab_nic *efab, int phy_id,
650 int location, int value ) {
654 EFAB_TRACE ( "Writing GMII %d register %02x with %04x\n", phy_id,
657 /* Mentor MAC connects both PHYs to MAC 0 */
658 save_port = efab->port;
661 /* Check MII not currently being accessed */
662 if ( ! mentormac_gmii_wait ( efab ) )
665 /* Write the address register */
666 EFAB_POPULATE_DWORD_2 ( reg,
667 GM_MGMT_PHY_ADDR, phy_id,
668 GM_MGMT_REG_ADDR, location );
669 efab->op->mac_writel ( efab, ®, GM_MII_MGMT_ADR_REG_MAC );
673 EFAB_POPULATE_DWORD_1 ( reg, GM_MGMT_CTL, value );
674 efab->op->mac_writel ( efab, ®, GM_MII_MGMT_CTL_REG_MAC );
676 /* Wait for data to be written */
677 mentormac_gmii_wait ( efab );
680 /* Restore efab->port */
681 efab->port = save_port;
685 * Read a GMII register
688 static int mentormac_mdio_read ( struct efab_nic *efab, int phy_id,
694 /* Mentor MAC connects both PHYs to MAC 0 */
695 save_port = efab->port;
698 /* Check MII not currently being accessed */
699 if ( ! mentormac_gmii_wait ( efab ) )
702 /* Write the address register */
703 EFAB_POPULATE_DWORD_2 ( reg,
704 GM_MGMT_PHY_ADDR, phy_id,
705 GM_MGMT_REG_ADDR, location );
706 efab->op->mac_writel ( efab, ®, GM_MII_MGMT_ADR_REG_MAC );
709 /* Request data to be read */
710 EFAB_POPULATE_DWORD_1 ( reg, GM_MGMT_RD_CYC, 1 );
711 efab->op->mac_writel ( efab, ®, GM_MII_MGMT_CMD_REG_MAC );
713 /* Wait for data to be become available */
714 if ( mentormac_gmii_wait ( efab ) ) {
716 efab->op->mac_readl ( efab, ®, GM_MII_MGMT_STAT_REG_MAC );
717 value = EFAB_DWORD_FIELD ( reg, GM_MGMT_STAT );
718 EFAB_TRACE ( "Read from GMII %d register %02x, got %04x\n",
719 phy_id, location, value );
722 /* Signal completion */
723 EFAB_ZERO_DWORD ( reg );
724 efab->op->mac_writel ( efab, ®, GM_MII_MGMT_CMD_REG_MAC );
728 /* Restore efab->port */
729 efab->port = save_port;
734 /**************************************************************************
738 **************************************************************************
741 /** Control and General Status */
742 #define EF1_CTR_GEN_STATUS0_REG 0x0
743 #define EF1_MASTER_EVENTS_LBN 12
744 #define EF1_MASTER_EVENTS_WIDTH 1
745 #define EF1_TX_ENGINE_EN_LBN 19
746 #define EF1_TX_ENGINE_EN_WIDTH 1
747 #define EF1_RX_ENGINE_EN_LBN 18
748 #define EF1_RX_ENGINE_EN_WIDTH 1
749 #define EF1_TURBO2_LBN 17
750 #define EF1_TURBO2_WIDTH 1
751 #define EF1_TURBO1_LBN 16
752 #define EF1_TURBO1_WIDTH 1
753 #define EF1_TURBO3_LBN 14
754 #define EF1_TURBO3_WIDTH 1
755 #define EF1_LB_RESET_LBN 3
756 #define EF1_LB_RESET_WIDTH 1
757 #define EF1_MAC_RESET_LBN 2
758 #define EF1_MAC_RESET_WIDTH 1
759 #define EF1_CAM_ENABLE_LBN 1
760 #define EF1_CAM_ENABLE_WIDTH 1
763 #define EF1_IRQ_SRC_REG 0x0008
766 #define EF1_IRQ_MASK_REG 0x000c
767 #define EF1_IRQ_PHY1_LBN 11
768 #define EF1_IRQ_PHY1_WIDTH 1
769 #define EF1_IRQ_PHY0_LBN 10
770 #define EF1_IRQ_PHY0_WIDTH 1
771 #define EF1_IRQ_SERR_LBN 7
772 #define EF1_IRQ_SERR_WIDTH 1
773 #define EF1_IRQ_EVQ_LBN 3
774 #define EF1_IRQ_EVQ_WIDTH 1
776 /** Event generation */
777 #define EF1_EVT3_REG 0x38
780 #define EF1_EEPROM_REG 0x40
781 #define EF1_EEPROM_SDA_LBN 31
782 #define EF1_EEPROM_SDA_WIDTH 1
783 #define EF1_EEPROM_SCL_LBN 30
784 #define EF1_EEPROM_SCL_WIDTH 1
785 #define EF1_JTAG_DISCONNECT_LBN 17
786 #define EF1_JTAG_DISCONNECT_WIDTH 1
787 #define EF1_EEPROM_LBN 0
788 #define EF1_EEPROM_WIDTH 32
790 /** Control register 2 */
791 #define EF1_CTL2_REG 0x4c
792 #define EF1_PLL_TRAP_LBN 31
793 #define EF1_PLL_TRAP_WIDTH 1
794 #define EF1_MEM_MAP_4MB_LBN 11
795 #define EF1_MEM_MAP_4MB_WIDTH 1
796 #define EF1_EV_INTR_CLR_WRITE_LBN 6
797 #define EF1_EV_INTR_CLR_WRITE_WIDTH 1
798 #define EF1_BURST_MERGE_LBN 5
799 #define EF1_BURST_MERGE_WIDTH 1
800 #define EF1_CLEAR_NULL_PAD_LBN 4
801 #define EF1_CLEAR_NULL_PAD_WIDTH 1
802 #define EF1_SW_RESET_LBN 2
803 #define EF1_SW_RESET_WIDTH 1
804 #define EF1_INTR_AFTER_EVENT_LBN 1
805 #define EF1_INTR_AFTER_EVENT_WIDTH 1
808 #define EF1_EVENT_FIFO_REG 0x50
810 /** Event FIFO count */
811 #define EF1_EVENT_FIFO_COUNT_REG 0x5c
812 #define EF1_EV_COUNT_LBN 0
813 #define EF1_EV_COUNT_WIDTH 16
815 /** TX DMA control and status */
816 #define EF1_DMA_TX_CSR_REG 0x80
817 #define EF1_DMA_TX_CSR_CHAIN_EN_LBN 8
818 #define EF1_DMA_TX_CSR_CHAIN_EN_WIDTH 1
819 #define EF1_DMA_TX_CSR_ENABLE_LBN 4
820 #define EF1_DMA_TX_CSR_ENABLE_WIDTH 1
821 #define EF1_DMA_TX_CSR_INT_EN_LBN 0
822 #define EF1_DMA_TX_CSR_INT_EN_WIDTH 1
824 /** RX DMA control and status */
825 #define EF1_DMA_RX_CSR_REG 0xa0
826 #define EF1_DMA_RX_ABOVE_1GB_EN_LBN 6
827 #define EF1_DMA_RX_ABOVE_1GB_EN_WIDTH 1
828 #define EF1_DMA_RX_BELOW_1MB_EN_LBN 5
829 #define EF1_DMA_RX_BELOW_1MB_EN_WIDTH 1
830 #define EF1_DMA_RX_CSR_ENABLE_LBN 0
831 #define EF1_DMA_RX_CSR_ENABLE_WIDTH 1
833 /** Level 5 watermark register (in MAC space) */
834 #define EF1_GMF_L5WM_REG_MAC 0x20
835 #define EF1_L5WM_LBN 0
836 #define EF1_L5WM_WIDTH 32
839 #define EF1_GM_MAC_CLK_REG 0x112000
840 #define EF1_GM_PORT0_MAC_CLK_LBN 0
841 #define EF1_GM_PORT0_MAC_CLK_WIDTH 1
842 #define EF1_GM_PORT1_MAC_CLK_LBN 1
843 #define EF1_GM_PORT1_MAC_CLK_WIDTH 1
845 /** TX descriptor FIFO */
846 #define EF1_TX_DESC_FIFO 0x141000
847 #define EF1_TX_KER_EVQ_LBN 80
848 #define EF1_TX_KER_EVQ_WIDTH 12
849 #define EF1_TX_KER_IDX_LBN 64
850 #define EF1_TX_KER_IDX_WIDTH 16
851 #define EF1_TX_KER_MODE_LBN 63
852 #define EF1_TX_KER_MODE_WIDTH 1
853 #define EF1_TX_KER_PORT_LBN 60
854 #define EF1_TX_KER_PORT_WIDTH 1
855 #define EF1_TX_KER_CONT_LBN 56
856 #define EF1_TX_KER_CONT_WIDTH 1
857 #define EF1_TX_KER_BYTE_CNT_LBN 32
858 #define EF1_TX_KER_BYTE_CNT_WIDTH 24
859 #define EF1_TX_KER_BUF_ADR_LBN 0
860 #define EF1_TX_KER_BUF_ADR_WIDTH 32
862 /** TX descriptor FIFO flush */
863 #define EF1_TX_DESC_FIFO_FLUSH 0x141ffc
865 /** RX descriptor FIFO */
866 #define EF1_RX_DESC_FIFO 0x145000
867 #define EF1_RX_KER_EVQ_LBN 48
868 #define EF1_RX_KER_EVQ_WIDTH 12
869 #define EF1_RX_KER_IDX_LBN 32
870 #define EF1_RX_KER_IDX_WIDTH 16
871 #define EF1_RX_KER_BUF_ADR_LBN 0
872 #define EF1_RX_KER_BUF_ADR_WIDTH 32
874 /** RX descriptor FIFO flush */
875 #define EF1_RX_DESC_FIFO_FLUSH 0x145ffc
878 #define EF1_CAM_BASE 0x1c0000
879 #define EF1_CAM_WTF_DOES_THIS_DO_LBN 0
880 #define EF1_CAM_WTF_DOES_THIS_DO_WIDTH 32
882 /** Event queue pointers */
883 #define EF1_EVQ_PTR_BASE 0x260000
884 #define EF1_EVQ_SIZE_LBN 29
885 #define EF1_EVQ_SIZE_WIDTH 2
886 #define EF1_EVQ_SIZE_4K 3
887 #define EF1_EVQ_SIZE_2K 2
888 #define EF1_EVQ_SIZE_1K 1
889 #define EF1_EVQ_SIZE_512 0
890 #define EF1_EVQ_BUF_BASE_ID_LBN 0
891 #define EF1_EVQ_BUF_BASE_ID_WIDTH 29
894 #define EF1002_MAC_REGBANK 0x110000
895 #define EF1002_MAC_REGBANK_SIZE 0x1000
896 #define EF1002_MAC_REG_SIZE 0x08
898 /** Offset of a MAC register within EF1002 */
899 #define EF1002_MAC_REG( efab, mac_reg ) \
900 ( EF1002_MAC_REGBANK + \
901 ( (efab)->port * EF1002_MAC_REGBANK_SIZE ) + \
902 ( (mac_reg) * EF1002_MAC_REG_SIZE ) )
904 /* Event queue entries */
905 #define EF1_EV_CODE_LBN 20
906 #define EF1_EV_CODE_WIDTH 8
907 #define EF1_RX_EV_DECODE 0x01
908 #define EF1_TX_EV_DECODE 0x02
909 #define EF1_TIMER_EV_DECODE 0x0b
910 #define EF1_DRV_GEN_EV_DECODE 0x0f
913 #define EF1_RX_EV_LEN_LBN 48
914 #define EF1_RX_EV_LEN_WIDTH 16
915 #define EF1_RX_EV_PORT_LBN 17
916 #define EF1_RX_EV_PORT_WIDTH 3
917 #define EF1_RX_EV_OK_LBN 16
918 #define EF1_RX_EV_OK_WIDTH 1
919 #define EF1_RX_EV_IDX_LBN 0
920 #define EF1_RX_EV_IDX_WIDTH 16
922 /* Transmit events */
923 #define EF1_TX_EV_PORT_LBN 17
924 #define EF1_TX_EV_PORT_WIDTH 3
925 #define EF1_TX_EV_OK_LBN 16
926 #define EF1_TX_EV_OK_WIDTH 1
927 #define EF1_TX_EV_IDX_LBN 0
928 #define EF1_TX_EV_IDX_WIDTH 16
930 /* I2C ID of the EEPROM */
931 #define EF1_EEPROM_I2C_ID 0x50
933 /* Offset of MAC address within EEPROM */
934 #define EF1_EEPROM_HWADDR_OFFSET 0x0
937 * Write dword to EF1002 register
940 static inline void ef1002_writel ( struct efab_nic *efab, efab_dword_t *value,
942 EFAB_REGDUMP ( "Writing register %x with " EFAB_DWORD_FMT "\n",
943 reg, EFAB_DWORD_VAL ( *value ) );
944 writel ( value->u32[0], efab->membase + reg );
948 * Read dword from an EF1002 register
951 static inline void ef1002_readl ( struct efab_nic *efab, efab_dword_t *value,
953 value->u32[0] = readl ( efab->membase + reg );
954 EFAB_REGDUMP ( "Read from register %x, got " EFAB_DWORD_FMT "\n",
955 reg, EFAB_DWORD_VAL ( *value ) );
959 * Read dword from an EF1002 register, silently
962 static inline void ef1002_readl_silent ( struct efab_nic *efab,
965 value->u32[0] = readl ( efab->membase + reg );
972 static void ef1002_get_membase ( struct efab_nic *efab ) {
973 unsigned long membase_phys;
975 membase_phys = pci_bar_start ( efab->pci, PCI_BASE_ADDRESS_0 );
976 efab->membase = ioremap ( membase_phys, 0x800000 );
979 /** PCI registers to backup/restore over a device reset */
980 static const unsigned int efab_pci_reg_addr[] = {
981 PCI_COMMAND, 0x0c /* PCI_CACHE_LINE_SIZE */,
982 PCI_BASE_ADDRESS_0, PCI_BASE_ADDRESS_1, PCI_BASE_ADDRESS_2,
983 PCI_BASE_ADDRESS_3, PCI_ROM_ADDRESS, PCI_INTERRUPT_LINE,
985 /** Number of registers in efab_pci_reg_addr */
986 #define EFAB_NUM_PCI_REG \
987 ( sizeof ( efab_pci_reg_addr ) / sizeof ( efab_pci_reg_addr[0] ) )
988 /** PCI configuration space backup */
989 struct efab_pci_reg {
990 uint32_t reg[EFAB_NUM_PCI_REG];
994 * I2C interface and EEPROM
998 static unsigned long ef1002_i2c_bits[] = {
999 [I2C_BIT_SCL] = ( 1 << 30 ),
1000 [I2C_BIT_SDA] = ( 1 << 31 ),
1003 static void ef1002_i2c_write_bit ( struct bit_basher *basher,
1004 unsigned int bit_id, unsigned long data ) {
1005 struct efab_nic *efab = container_of ( basher, struct efab_nic,
1006 ef1002_i2c.basher );
1010 mask = ef1002_i2c_bits[bit_id];
1011 efab->ef1002_i2c_outputs &= ~mask;
1012 efab->ef1002_i2c_outputs |= ( data & mask );
1013 EFAB_POPULATE_DWORD_1 ( reg, EF1_EEPROM, efab->ef1002_i2c_outputs );
1014 ef1002_writel ( efab, ®, EF1_EEPROM_REG );
1017 static int ef1002_i2c_read_bit ( struct bit_basher *basher,
1018 unsigned int bit_id ) {
1019 struct efab_nic *efab = container_of ( basher, struct efab_nic,
1020 ef1002_i2c.basher );
1024 mask = ef1002_i2c_bits[bit_id];
1025 ef1002_readl ( efab, ®, EF1_EEPROM_REG );
1026 return ( EFAB_DWORD_FIELD ( reg, EF1_EEPROM ) & mask );
1029 static void ef1002_init_eeprom ( struct efab_nic *efab ) {
1030 efab->ef1002_i2c.basher.write = ef1002_i2c_write_bit;
1031 efab->ef1002_i2c.basher.read = ef1002_i2c_read_bit;
1032 init_i2c_bit_basher ( &efab->ef1002_i2c );
1033 efab->ef1002_eeprom.address = EF1_EEPROM_I2C_ID;
1040 static int ef1002_reset ( struct efab_nic *efab ) {
1041 struct efab_pci_reg pci_reg;
1042 struct pci_device *pci_dev = efab->pci;
1047 /* Back up PCI configuration registers */
1048 for ( i = 0 ; i < EFAB_NUM_PCI_REG ; i++ ) {
1049 pci_read_config_dword ( pci_dev, efab_pci_reg_addr[i],
1053 /* Reset the whole device. */
1054 EFAB_POPULATE_DWORD_1 ( reg, EF1_SW_RESET, 1 );
1055 ef1002_writel ( efab, ®, EF1_CTL2_REG );
1058 /* Restore PCI configuration space */
1059 for ( i = 0 ; i < EFAB_NUM_PCI_REG ; i++ ) {
1060 pci_write_config_dword ( pci_dev, efab_pci_reg_addr[i],
1064 /* Verify PCI configuration space */
1065 for ( i = 0 ; i < EFAB_NUM_PCI_REG ; i++ ) {
1066 pci_read_config_dword ( pci_dev, efab_pci_reg_addr[i], &tmp );
1067 if ( tmp != pci_reg.reg[i] ) {
1068 printf ( "PCI restore failed on register %02x "
1069 "(is %08lx, should be %08lx); reboot\n",
1070 i, tmp, pci_reg.reg[i] );
1075 /* Verify device reset complete */
1076 ef1002_readl ( efab, ®, EF1_CTR_GEN_STATUS0_REG );
1077 if ( EFAB_DWORD_IS_ALL_ONES ( reg ) ) {
1078 printf ( "Reset failed\n" );
1089 static int ef1002_init_nic ( struct efab_nic *efab ) {
1092 /* No idea what CAM is, but the 'datasheet' says that we have
1093 * to write these values in at start of day
1095 EFAB_POPULATE_DWORD_1 ( reg, EF1_CAM_WTF_DOES_THIS_DO, 0x6 );
1096 ef1002_writel ( efab, ®, EF1_CAM_BASE + 0x20018 );
1098 EFAB_POPULATE_DWORD_1 ( reg, EF1_CAM_WTF_DOES_THIS_DO, 0x01000000 );
1099 ef1002_writel ( efab, ®, EF1_CAM_BASE + 0x00018 );
1102 /* General control register 0 */
1103 ef1002_readl ( efab, ®, EF1_CTR_GEN_STATUS0_REG );
1104 EFAB_SET_DWORD_FIELD ( reg, EF1_MASTER_EVENTS, 0 );
1105 EFAB_SET_DWORD_FIELD ( reg, EF1_TX_ENGINE_EN, 0 );
1106 EFAB_SET_DWORD_FIELD ( reg, EF1_RX_ENGINE_EN, 0 );
1107 EFAB_SET_DWORD_FIELD ( reg, EF1_TURBO2, 1 );
1108 EFAB_SET_DWORD_FIELD ( reg, EF1_TURBO1, 1 );
1109 EFAB_SET_DWORD_FIELD ( reg, EF1_TURBO3, 1 );
1110 EFAB_SET_DWORD_FIELD ( reg, EF1_CAM_ENABLE, 1 );
1111 ef1002_writel ( efab, ®, EF1_CTR_GEN_STATUS0_REG );
1114 /* General control register 2 */
1115 ef1002_readl ( efab, ®, EF1_CTL2_REG );
1116 EFAB_SET_DWORD_FIELD ( reg, EF1_PLL_TRAP, 1 );
1117 EFAB_SET_DWORD_FIELD ( reg, EF1_MEM_MAP_4MB, 0 );
1118 EFAB_SET_DWORD_FIELD ( reg, EF1_EV_INTR_CLR_WRITE, 0 );
1119 EFAB_SET_DWORD_FIELD ( reg, EF1_BURST_MERGE, 0 );
1120 EFAB_SET_DWORD_FIELD ( reg, EF1_CLEAR_NULL_PAD, 1 );
1121 EFAB_SET_DWORD_FIELD ( reg, EF1_INTR_AFTER_EVENT, 1 );
1122 ef1002_writel ( efab, ®, EF1_CTL2_REG );
1126 ef1002_readl ( efab, ®, EF1_DMA_RX_CSR_REG );
1127 EFAB_SET_DWORD_FIELD ( reg, EF1_DMA_RX_CSR_ENABLE, 1 );
1128 EFAB_SET_DWORD_FIELD ( reg, EF1_DMA_RX_BELOW_1MB_EN, 1 );
1129 EFAB_SET_DWORD_FIELD ( reg, EF1_DMA_RX_ABOVE_1GB_EN, 1 );
1130 ef1002_writel ( efab, ®, EF1_DMA_RX_CSR_REG );
1134 ef1002_readl ( efab, ®, EF1_DMA_TX_CSR_REG );
1135 EFAB_SET_DWORD_FIELD ( reg, EF1_DMA_TX_CSR_CHAIN_EN, 1 );
1136 EFAB_SET_DWORD_FIELD ( reg, EF1_DMA_TX_CSR_ENABLE, 0 /* ?? */ );
1137 EFAB_SET_DWORD_FIELD ( reg, EF1_DMA_TX_CSR_INT_EN, 0 /* ?? */ );
1138 ef1002_writel ( efab, ®, EF1_DMA_TX_CSR_REG );
1141 /* Disconnect the JTAG chain. Read-modify-write is impossible
1142 * on the I2C control bits, since reading gives the state of
1143 * the line inputs rather than the last written state.
1145 ef1002_readl ( efab, ®, EF1_EEPROM_REG );
1146 EFAB_SET_DWORD_FIELD ( reg, EF1_EEPROM_SDA, 1 );
1147 EFAB_SET_DWORD_FIELD ( reg, EF1_EEPROM_SCL, 1 );
1148 EFAB_SET_DWORD_FIELD ( reg, EF1_JTAG_DISCONNECT, 1 );
1149 ef1002_writel ( efab, ®, EF1_EEPROM_REG );
1152 /* Flush descriptor queues */
1153 EFAB_ZERO_DWORD ( reg );
1154 ef1002_writel ( efab, ®, EF1_RX_DESC_FIFO_FLUSH );
1155 ef1002_writel ( efab, ®, EF1_TX_DESC_FIFO_FLUSH );
1160 mentormac_reset ( efab );
1162 /* Attach I2C bus */
1163 ef1002_init_eeprom ( efab );
1169 * Read MAC address from EEPROM
1172 static int ef1002_read_eeprom ( struct efab_nic *efab ) {
1173 struct i2c_interface *i2c = &efab->ef1002_i2c.i2c;
1174 struct i2c_device *i2cdev = &efab->ef1002_eeprom;
1176 return ( i2c->read ( i2c, i2cdev, EF1_EEPROM_HWADDR_OFFSET,
1177 efab->mac_addr, sizeof ( efab->mac_addr ) ) == 0);
1180 /** RX descriptor */
1181 typedef efab_qword_t ef1002_rx_desc_t;
1184 * Build RX descriptor
1187 static void ef1002_build_rx_desc ( struct efab_nic *efab,
1188 struct efab_rx_buf *rx_buf ) {
1189 ef1002_rx_desc_t rxd;
1191 EFAB_POPULATE_QWORD_3 ( rxd,
1193 EF1_RX_KER_IDX, rx_buf->id,
1195 virt_to_bus ( rx_buf->addr ) );
1196 ef1002_writel ( efab, &rxd.dword[0], EF1_RX_DESC_FIFO + 0 );
1198 ef1002_writel ( efab, &rxd.dword[1], EF1_RX_DESC_FIFO + 4 );
1203 * Update RX descriptor write pointer
1206 static void ef1002_notify_rx_desc ( struct efab_nic *efab __unused ) {
1210 /** TX descriptor */
1211 typedef efab_oword_t ef1002_tx_desc_t;
1214 * Build TX descriptor
1217 static void ef1002_build_tx_desc ( struct efab_nic *efab,
1218 struct efab_tx_buf *tx_buf ) {
1219 ef1002_tx_desc_t txd;
1221 EFAB_POPULATE_OWORD_7 ( txd,
1223 EF1_TX_KER_IDX, tx_buf->id,
1224 EF1_TX_KER_MODE, 0 /* IP mode */,
1225 EF1_TX_KER_PORT, efab->port,
1227 EF1_TX_KER_BYTE_CNT, tx_buf->len,
1229 virt_to_bus ( tx_buf->addr ) );
1231 ef1002_writel ( efab, &txd.dword[0], EF1_TX_DESC_FIFO + 0 );
1232 ef1002_writel ( efab, &txd.dword[1], EF1_TX_DESC_FIFO + 4 );
1234 ef1002_writel ( efab, &txd.dword[2], EF1_TX_DESC_FIFO + 8 );
1239 * Update TX descriptor write pointer
1242 static void ef1002_notify_tx_desc ( struct efab_nic *efab __unused ) {
1247 typedef efab_qword_t ef1002_event_t;
1250 * Retrieve event from event queue
1253 static int ef1002_fetch_event ( struct efab_nic *efab,
1254 struct efab_event *event ) {
1259 /* Check event FIFO depth */
1260 ef1002_readl_silent ( efab, ®, EF1_EVENT_FIFO_COUNT_REG );
1261 words = EFAB_DWORD_FIELD ( reg, EF1_EV_COUNT );
1265 /* Read event data */
1266 ef1002_readl ( efab, ®, EF1_EVENT_FIFO_REG );
1267 DBG ( "Event is " EFAB_DWORD_FMT "\n", EFAB_DWORD_VAL ( reg ) );
1270 ev_code = EFAB_DWORD_FIELD ( reg, EF1_EV_CODE );
1271 switch ( ev_code ) {
1272 case EF1_TX_EV_DECODE:
1273 event->type = EFAB_EV_TX;
1275 case EF1_RX_EV_DECODE:
1276 event->type = EFAB_EV_RX;
1277 event->rx_id = EFAB_DWORD_FIELD ( reg, EF1_RX_EV_IDX );
1278 /* RX len not available via event FIFO */
1279 event->rx_len = ETH_FRAME_LEN;
1281 case EF1_TIMER_EV_DECODE:
1282 /* These are safe to ignore. We seem to get some at
1283 * start of day, presumably due to the timers starting
1284 * up with random contents.
1286 event->type = EFAB_EV_NONE;
1289 printf ( "Unknown event type %d data %08lx\n", ev_code,
1290 EFAB_DWORD_FIELD ( reg, EFAB_DWORD_0 ) );
1291 event->type = EFAB_EV_NONE;
1294 /* Clear any pending interrupts */
1295 ef1002_readl ( efab, ®, EF1_IRQ_SRC_REG );
1301 * Enable/disable interrupts
1304 static void ef1002_mask_irq ( struct efab_nic *efab, int enabled ) {
1305 efab_dword_t irq_mask;
1307 EFAB_POPULATE_DWORD_2 ( irq_mask,
1308 EF1_IRQ_SERR, enabled,
1309 EF1_IRQ_EVQ, enabled );
1310 ef1002_writel ( efab, &irq_mask, EF1_IRQ_MASK_REG );
1314 * Generate interrupt
1317 static void ef1002_generate_irq ( struct efab_nic *efab ) {
1318 ef1002_event_t test_event;
1320 EFAB_POPULATE_QWORD_1 ( test_event,
1321 EF1_EV_CODE, EF1_DRV_GEN_EV_DECODE );
1322 ef1002_writel ( efab, &test_event.dword[0], EF1_EVT3_REG );
1326 * Write dword to an EF1002 MAC register
1329 static void ef1002_mac_writel ( struct efab_nic *efab,
1330 efab_dword_t *value, unsigned int mac_reg ) {
1331 ef1002_writel ( efab, value, EF1002_MAC_REG ( efab, mac_reg ) );
1335 * Read dword from an EF1002 MAC register
1338 static void ef1002_mac_readl ( struct efab_nic *efab,
1339 efab_dword_t *value, unsigned int mac_reg ) {
1340 ef1002_readl ( efab, value, EF1002_MAC_REG ( efab, mac_reg ) );
1347 static int ef1002_init_mac ( struct efab_nic *efab ) {
1348 static struct efab_mentormac_parameters ef1002_mentormac_params = {
1349 .gmf_cfgfrth = 0x13,
1350 .gmf_cfgftth = 0x10,
1351 .gmf_cfghwmft = 0x555,
1356 unsigned int mac_clk;
1358 /* Initialise PHY */
1359 alaska_init ( efab );
1361 /* Initialise MAC */
1362 mentormac_init ( efab, &ef1002_mentormac_params );
1364 /* Write Level 5 watermark register */
1365 EFAB_POPULATE_DWORD_1 ( reg, EF1_L5WM, 0x10040000 );
1366 efab->op->mac_writel ( efab, ®, EF1_GMF_L5WM_REG_MAC );
1369 /* Set MAC clock speed */
1370 ef1002_readl ( efab, ®, EF1_GM_MAC_CLK_REG );
1371 mac_clk = ( efab->link_options & LPA_1000 ) ? 0 : 1;
1372 if ( efab->port == 0 ) {
1373 EFAB_SET_DWORD_FIELD ( reg, EF1_GM_PORT0_MAC_CLK, mac_clk );
1375 EFAB_SET_DWORD_FIELD ( reg, EF1_GM_PORT1_MAC_CLK, mac_clk );
1377 ef1002_writel ( efab, ®, EF1_GM_MAC_CLK_REG );
1384 static void ef1002_mdio_write ( struct efab_nic *efab, int location,
1386 mentormac_mdio_write ( efab, efab->port + 2, location, value );
1390 static int ef1002_mdio_read ( struct efab_nic *efab, int location ) {
1391 return mentormac_mdio_read ( efab, efab->port + 2, location );
1394 static struct efab_operations ef1002_operations = {
1395 .get_membase = ef1002_get_membase,
1396 .reset = ef1002_reset,
1397 .init_nic = ef1002_init_nic,
1398 .read_eeprom = ef1002_read_eeprom,
1399 .build_rx_desc = ef1002_build_rx_desc,
1400 .notify_rx_desc = ef1002_notify_rx_desc,
1401 .build_tx_desc = ef1002_build_tx_desc,
1402 .notify_tx_desc = ef1002_notify_tx_desc,
1403 .fetch_event = ef1002_fetch_event,
1404 .mask_irq = ef1002_mask_irq,
1405 .generate_irq = ef1002_generate_irq,
1406 .mac_writel = ef1002_mac_writel,
1407 .mac_readl = ef1002_mac_readl,
1408 .init_mac = ef1002_init_mac,
1409 .mdio_write = ef1002_mdio_write,
1410 .mdio_read = ef1002_mdio_read,
1413 /**************************************************************************
1417 **************************************************************************
1420 /* I/O BAR address register */
1421 #define FCN_IOM_IND_ADR_REG 0x0
1423 /* I/O BAR data register */
1424 #define FCN_IOM_IND_DAT_REG 0x4
1426 /* Interrupt enable register */
1427 #define FCN_INT_EN_REG_KER 0x0010
1428 #define FCN_MEM_PERR_INT_EN_KER_LBN 5
1429 #define FCN_MEM_PERR_INT_EN_KER_WIDTH 1
1430 #define FCN_KER_INT_CHAR_LBN 4
1431 #define FCN_KER_INT_CHAR_WIDTH 1
1432 #define FCN_KER_INT_KER_LBN 3
1433 #define FCN_KER_INT_KER_WIDTH 1
1434 #define FCN_ILL_ADR_ERR_INT_EN_KER_LBN 2
1435 #define FCN_ILL_ADR_ERR_INT_EN_KER_WIDTH 1
1436 #define FCN_SRM_PERR_INT_EN_KER_LBN 1
1437 #define FCN_SRM_PERR_INT_EN_KER_WIDTH 1
1438 #define FCN_DRV_INT_EN_KER_LBN 0
1439 #define FCN_DRV_INT_EN_KER_WIDTH 1
1441 /* Interrupt status register */
1442 #define FCN_INT_ADR_REG_KER 0x0030
1443 #define FCN_INT_ADR_KER_LBN 0
1444 #define FCN_INT_ADR_KER_WIDTH EFAB_DMA_TYPE_WIDTH ( 64 )
1446 /* Interrupt acknowledge register */
1447 #define FCN_INT_ACK_KER_REG 0x0050
1449 /* SPI host command register */
1450 #define FCN_EE_SPI_HCMD_REG_KER 0x0100
1451 #define FCN_EE_SPI_HCMD_CMD_EN_LBN 31
1452 #define FCN_EE_SPI_HCMD_CMD_EN_WIDTH 1
1453 #define FCN_EE_WR_TIMER_ACTIVE_LBN 28
1454 #define FCN_EE_WR_TIMER_ACTIVE_WIDTH 1
1455 #define FCN_EE_SPI_HCMD_SF_SEL_LBN 24
1456 #define FCN_EE_SPI_HCMD_SF_SEL_WIDTH 1
1457 #define FCN_EE_SPI_EEPROM 0
1458 #define FCN_EE_SPI_FLASH 1
1459 #define FCN_EE_SPI_HCMD_DABCNT_LBN 16
1460 #define FCN_EE_SPI_HCMD_DABCNT_WIDTH 5
1461 #define FCN_EE_SPI_HCMD_READ_LBN 15
1462 #define FCN_EE_SPI_HCMD_READ_WIDTH 1
1463 #define FCN_EE_SPI_READ 1
1464 #define FCN_EE_SPI_WRITE 0
1465 #define FCN_EE_SPI_HCMD_DUBCNT_LBN 12
1466 #define FCN_EE_SPI_HCMD_DUBCNT_WIDTH 2
1467 #define FCN_EE_SPI_HCMD_ADBCNT_LBN 8
1468 #define FCN_EE_SPI_HCMD_ADBCNT_WIDTH 2
1469 #define FCN_EE_SPI_HCMD_ENC_LBN 0
1470 #define FCN_EE_SPI_HCMD_ENC_WIDTH 8
1472 /* SPI host address register */
1473 #define FCN_EE_SPI_HADR_REG_KER 0x0110
1474 #define FCN_EE_SPI_HADR_DUBYTE_LBN 24
1475 #define FCN_EE_SPI_HADR_DUBYTE_WIDTH 8
1476 #define FCN_EE_SPI_HADR_ADR_LBN 0
1477 #define FCN_EE_SPI_HADR_ADR_WIDTH 24
1479 /* SPI host data register */
1480 #define FCN_EE_SPI_HDATA_REG_KER 0x0120
1481 #define FCN_EE_SPI_HDATA3_LBN 96
1482 #define FCN_EE_SPI_HDATA3_WIDTH 32
1483 #define FCN_EE_SPI_HDATA2_LBN 64
1484 #define FCN_EE_SPI_HDATA2_WIDTH 32
1485 #define FCN_EE_SPI_HDATA1_LBN 32
1486 #define FCN_EE_SPI_HDATA1_WIDTH 32
1487 #define FCN_EE_SPI_HDATA0_LBN 0
1488 #define FCN_EE_SPI_HDATA0_WIDTH 32
1490 /* GPIO control register */
1491 #define FCN_GPIO_CTL_REG_KER 0x0210
1492 #define FCN_FLASH_PRESENT_LBN 7
1493 #define FCN_FLASH_PRESENT_WIDTH 1
1494 #define FCN_EEPROM_PRESENT_LBN 6
1495 #define FCN_EEPROM_PRESENT_WIDTH 1
1497 /* Global control register */
1498 #define FCN_GLB_CTL_REG_KER 0x0220
1499 #define FCN_EXT_PHY_RST_CTL_LBN 63
1500 #define FCN_EXT_PHY_RST_CTL_WIDTH 1
1501 #define FCN_PCIE_SD_RST_CTL_LBN 61
1502 #define FCN_PCIE_SD_RST_CTL_WIDTH 1
1503 #define FCN_PCIX_RST_CTL_LBN 60
1504 #define FCN_PCIX_RST_CTL_WIDTH 1
1505 #define FCN_RST_EXT_PHY_LBN 31
1506 #define FCN_RST_EXT_PHY_WIDTH 1
1507 #define FCN_INT_RST_DUR_LBN 4
1508 #define FCN_INT_RST_DUR_WIDTH 3
1509 #define FCN_EXT_PHY_RST_DUR_LBN 1
1510 #define FCN_EXT_PHY_RST_DUR_WIDTH 3
1511 #define FCN_SWRST_LBN 0
1512 #define FCN_SWRST_WIDTH 1
1513 #define FCN_INCLUDE_IN_RESET 0
1514 #define FCN_EXCLUDE_FROM_RESET 1
1516 /* Timer table for kernel access */
1517 #define FCN_TIMER_CMD_REG_KER 0x420
1518 #define FCN_TIMER_MODE_LBN 12
1519 #define FCN_TIMER_MODE_WIDTH 2
1520 #define FCN_TIMER_MODE_DIS 0
1521 #define FCN_TIMER_MODE_INT_HLDOFF 1
1522 #define FCN_TIMER_VAL_LBN 0
1523 #define FCN_TIMER_VAL_WIDTH 12
1525 /* SRAM receive descriptor cache configuration register */
1526 #define FCN_SRM_RX_DC_CFG_REG_KER 0x610
1527 #define FCN_SRM_RX_DC_BASE_ADR_LBN 0
1528 #define FCN_SRM_RX_DC_BASE_ADR_WIDTH 21
1530 /* SRAM transmit descriptor cache configuration register */
1531 #define FCN_SRM_TX_DC_CFG_REG_KER 0x620
1532 #define FCN_SRM_TX_DC_BASE_ADR_LBN 0
1533 #define FCN_SRM_TX_DC_BASE_ADR_WIDTH 21
1535 /* Receive filter control register */
1536 #define FCN_RX_FILTER_CTL_REG_KER 0x810
1537 #define FCN_NUM_KER_LBN 24
1538 #define FCN_NUM_KER_WIDTH 2
1540 /* Receive descriptor update register */
1541 #define FCN_RX_DESC_UPD_REG_KER 0x0830
1542 #define FCN_RX_DESC_WPTR_LBN 96
1543 #define FCN_RX_DESC_WPTR_WIDTH 12
1544 #define FCN_RX_DESC_UPD_REG_KER_DWORD ( FCN_RX_DESC_UPD_REG_KER + 12 )
1545 #define FCN_RX_DESC_WPTR_DWORD_LBN 0
1546 #define FCN_RX_DESC_WPTR_DWORD_WIDTH 12
1548 /* Receive descriptor cache configuration register */
1549 #define FCN_RX_DC_CFG_REG_KER 0x840
1550 #define FCN_RX_DC_SIZE_LBN 0
1551 #define FCN_RX_DC_SIZE_WIDTH 2
1553 /* Transmit descriptor update register */
1554 #define FCN_TX_DESC_UPD_REG_KER 0x0a10
1555 #define FCN_TX_DESC_WPTR_LBN 96
1556 #define FCN_TX_DESC_WPTR_WIDTH 12
1557 #define FCN_TX_DESC_UPD_REG_KER_DWORD ( FCN_TX_DESC_UPD_REG_KER + 12 )
1558 #define FCN_TX_DESC_WPTR_DWORD_LBN 0
1559 #define FCN_TX_DESC_WPTR_DWORD_WIDTH 12
1561 /* Transmit descriptor cache configuration register */
1562 #define FCN_TX_DC_CFG_REG_KER 0xa20
1563 #define FCN_TX_DC_SIZE_LBN 0
1564 #define FCN_TX_DC_SIZE_WIDTH 2
1566 /* PHY management transmit data register */
1567 #define FCN_MD_TXD_REG_KER 0xc00
1568 #define FCN_MD_TXD_LBN 0
1569 #define FCN_MD_TXD_WIDTH 16
1571 /* PHY management receive data register */
1572 #define FCN_MD_RXD_REG_KER 0xc10
1573 #define FCN_MD_RXD_LBN 0
1574 #define FCN_MD_RXD_WIDTH 16
1576 /* PHY management configuration & status register */
1577 #define FCN_MD_CS_REG_KER 0xc20
1578 #define FCN_MD_GC_LBN 4
1579 #define FCN_MD_GC_WIDTH 1
1580 #define FCN_MD_RIC_LBN 2
1581 #define FCN_MD_RIC_WIDTH 1
1582 #define FCN_MD_WRC_LBN 0
1583 #define FCN_MD_WRC_WIDTH 1
1585 /* PHY management PHY address register */
1586 #define FCN_MD_PHY_ADR_REG_KER 0xc30
1587 #define FCN_MD_PHY_ADR_LBN 0
1588 #define FCN_MD_PHY_ADR_WIDTH 16
1590 /* PHY management ID register */
1591 #define FCN_MD_ID_REG_KER 0xc40
1592 #define FCN_MD_PRT_ADR_LBN 11
1593 #define FCN_MD_PRT_ADR_WIDTH 5
1594 #define FCN_MD_DEV_ADR_LBN 6
1595 #define FCN_MD_DEV_ADR_WIDTH 5
1597 /* PHY management status & mask register */
1598 #define FCN_MD_STAT_REG_KER 0xc50
1599 #define FCN_MD_BSY_LBN 0
1600 #define FCN_MD_BSY_WIDTH 1
1602 /* Port 0 and 1 MAC control registers */
1603 #define FCN_MAC0_CTRL_REG_KER 0xc80
1604 #define FCN_MAC1_CTRL_REG_KER 0xc90
1605 #define FCN_MAC_XOFF_VAL_LBN 16
1606 #define FCN_MAC_XOFF_VAL_WIDTH 16
1607 #define FCN_MAC_BCAD_ACPT_LBN 4
1608 #define FCN_MAC_BCAD_ACPT_WIDTH 1
1609 #define FCN_MAC_UC_PROM_LBN 3
1610 #define FCN_MAC_UC_PROM_WIDTH 1
1611 #define FCN_MAC_LINK_STATUS_LBN 2
1612 #define FCN_MAC_LINK_STATUS_WIDTH 1
1613 #define FCN_MAC_SPEED_LBN 0
1614 #define FCN_MAC_SPEED_WIDTH 2
1616 /* XGMAC global configuration - port 0*/
1617 #define FCN_XM_GLB_CFG_REG_P0_KER 0x1220
1618 #define FCN_XM_RX_STAT_EN_LBN 11
1619 #define FCN_XM_RX_STAT_EN_WIDTH 1
1620 #define FCN_XM_TX_STAT_EN_LBN 10
1621 #define FCN_XM_TX_STAT_EN_WIDTH 1
1622 #define FCN_XM_CUT_THRU_MODE_LBN 7
1623 #define FCN_XM_CUT_THRU_MODE_WIDTH 1
1624 #define FCN_XM_RX_JUMBO_MODE_LBN 6
1625 #define FCN_XM_RX_JUMBO_MODE_WIDTH 1
1627 /* XGMAC transmit configuration - port 0 */
1628 #define FCN_XM_TX_CFG_REG_P0_KER 0x1230
1629 #define FCN_XM_IPG_LBN 16
1630 #define FCN_XM_IPG_WIDTH 4
1631 #define FCN_XM_WTF_DOES_THIS_DO_LBN 9
1632 #define FCN_XM_WTF_DOES_THIS_DO_WIDTH 1
1633 #define FCN_XM_TXCRC_LBN 8
1634 #define FCN_XM_TXCRC_WIDTH 1
1635 #define FCN_XM_AUTO_PAD_LBN 5
1636 #define FCN_XM_AUTO_PAD_WIDTH 1
1637 #define FCN_XM_TX_PRMBL_LBN 2
1638 #define FCN_XM_TX_PRMBL_WIDTH 1
1639 #define FCN_XM_TXEN_LBN 1
1640 #define FCN_XM_TXEN_WIDTH 1
1642 /* XGMAC receive configuration - port 0 */
1643 #define FCN_XM_RX_CFG_REG_P0_KER 0x1240
1644 #define FCN_XM_PASS_CRC_ERR_LBN 25
1645 #define FCN_XM_PASS_CRC_ERR_WIDTH 1
1646 #define FCN_XM_AUTO_DEPAD_LBN 8
1647 #define FCN_XM_AUTO_DEPAD_WIDTH 1
1648 #define FCN_XM_RXEN_LBN 1
1649 #define FCN_XM_RXEN_WIDTH 1
1651 /* Receive descriptor pointer table */
1652 #define FCN_RX_DESC_PTR_TBL_KER 0x11800
1653 #define FCN_RX_DESCQ_BUF_BASE_ID_LBN 36
1654 #define FCN_RX_DESCQ_BUF_BASE_ID_WIDTH 20
1655 #define FCN_RX_DESCQ_EVQ_ID_LBN 24
1656 #define FCN_RX_DESCQ_EVQ_ID_WIDTH 12
1657 #define FCN_RX_DESCQ_OWNER_ID_LBN 10
1658 #define FCN_RX_DESCQ_OWNER_ID_WIDTH 14
1659 #define FCN_RX_DESCQ_SIZE_LBN 3
1660 #define FCN_RX_DESCQ_SIZE_WIDTH 2
1661 #define FCN_RX_DESCQ_SIZE_4K 3
1662 #define FCN_RX_DESCQ_SIZE_2K 2
1663 #define FCN_RX_DESCQ_SIZE_1K 1
1664 #define FCN_RX_DESCQ_SIZE_512 0
1665 #define FCN_RX_DESCQ_TYPE_LBN 2
1666 #define FCN_RX_DESCQ_TYPE_WIDTH 1
1667 #define FCN_RX_DESCQ_JUMBO_LBN 1
1668 #define FCN_RX_DESCQ_JUMBO_WIDTH 1
1669 #define FCN_RX_DESCQ_EN_LBN 0
1670 #define FCN_RX_DESCQ_EN_WIDTH 1
1672 /* Transmit descriptor pointer table */
1673 #define FCN_TX_DESC_PTR_TBL_KER 0x11900
1674 #define FCN_TX_DESCQ_EN_LBN 88
1675 #define FCN_TX_DESCQ_EN_WIDTH 1
1676 #define FCN_TX_DESCQ_BUF_BASE_ID_LBN 36
1677 #define FCN_TX_DESCQ_BUF_BASE_ID_WIDTH 20
1678 #define FCN_TX_DESCQ_EVQ_ID_LBN 24
1679 #define FCN_TX_DESCQ_EVQ_ID_WIDTH 12
1680 #define FCN_TX_DESCQ_OWNER_ID_LBN 10
1681 #define FCN_TX_DESCQ_OWNER_ID_WIDTH 14
1682 #define FCN_TX_DESCQ_SIZE_LBN 3
1683 #define FCN_TX_DESCQ_SIZE_WIDTH 2
1684 #define FCN_TX_DESCQ_SIZE_4K 3
1685 #define FCN_TX_DESCQ_SIZE_2K 2
1686 #define FCN_TX_DESCQ_SIZE_1K 1
1687 #define FCN_TX_DESCQ_SIZE_512 0
1688 #define FCN_TX_DESCQ_TYPE_LBN 1
1689 #define FCN_TX_DESCQ_TYPE_WIDTH 2
1690 #define FCN_TX_DESCQ_FLUSH_LBN 0
1691 #define FCN_TX_DESCQ_FLUSH_WIDTH 1
1693 /* Event queue pointer */
1694 #define FCN_EVQ_PTR_TBL_KER 0x11a00
1695 #define FCN_EVQ_EN_LBN 23
1696 #define FCN_EVQ_EN_WIDTH 1
1697 #define FCN_EVQ_SIZE_LBN 20
1698 #define FCN_EVQ_SIZE_WIDTH 3
1699 #define FCN_EVQ_SIZE_32K 6
1700 #define FCN_EVQ_SIZE_16K 5
1701 #define FCN_EVQ_SIZE_8K 4
1702 #define FCN_EVQ_SIZE_4K 3
1703 #define FCN_EVQ_SIZE_2K 2
1704 #define FCN_EVQ_SIZE_1K 1
1705 #define FCN_EVQ_SIZE_512 0
1706 #define FCN_EVQ_BUF_BASE_ID_LBN 0
1707 #define FCN_EVQ_BUF_BASE_ID_WIDTH 20
1709 /* Event queue read pointer */
1710 #define FCN_EVQ_RPTR_REG_KER 0x11b00
1711 #define FCN_EVQ_RPTR_LBN 0
1712 #define FCN_EVQ_RPTR_WIDTH 14
1713 #define FCN_EVQ_RPTR_REG_KER_DWORD ( FCN_EVQ_RPTR_REG_KER + 0 )
1714 #define FCN_EVQ_RPTR_DWORD_LBN 0
1715 #define FCN_EVQ_RPTR_DWORD_WIDTH 14
1717 /* Special buffer descriptors */
1718 #define FCN_BUF_FULL_TBL_KER 0x18000
1719 #define FCN_IP_DAT_BUF_SIZE_LBN 50
1720 #define FCN_IP_DAT_BUF_SIZE_WIDTH 1
1721 #define FCN_IP_DAT_BUF_SIZE_8K 1
1722 #define FCN_IP_DAT_BUF_SIZE_4K 0
1723 #define FCN_BUF_ADR_FBUF_LBN 14
1724 #define FCN_BUF_ADR_FBUF_WIDTH 34
1725 #define FCN_BUF_OWNER_ID_FBUF_LBN 0
1726 #define FCN_BUF_OWNER_ID_FBUF_WIDTH 14
1729 #define FALCON_MAC_REGBANK 0xe00
1730 #define FALCON_MAC_REGBANK_SIZE 0x200
1731 #define FALCON_MAC_REG_SIZE 0x10
1733 /** Offset of a MAC register within Falcon */
1734 #define FALCON_MAC_REG( efab, mac_reg ) \
1735 ( FALCON_MAC_REGBANK + \
1736 ( (efab)->port * FALCON_MAC_REGBANK_SIZE ) + \
1737 ( (mac_reg) * FALCON_MAC_REG_SIZE ) )
1738 #define FCN_MAC_DATA_LBN 0
1739 #define FCN_MAC_DATA_WIDTH 32
1741 /* Transmit descriptor */
1742 #define FCN_TX_KER_PORT_LBN 63
1743 #define FCN_TX_KER_PORT_WIDTH 1
1744 #define FCN_TX_KER_BYTE_CNT_LBN 48
1745 #define FCN_TX_KER_BYTE_CNT_WIDTH 14
1746 #define FCN_TX_KER_BUF_ADR_LBN 0
1747 #define FCN_TX_KER_BUF_ADR_WIDTH EFAB_DMA_TYPE_WIDTH ( 46 )
1749 /* Receive descriptor */
1750 #define FCN_RX_KER_BUF_SIZE_LBN 48
1751 #define FCN_RX_KER_BUF_SIZE_WIDTH 14
1752 #define FCN_RX_KER_BUF_ADR_LBN 0
1753 #define FCN_RX_KER_BUF_ADR_WIDTH EFAB_DMA_TYPE_WIDTH ( 46 )
1755 /* Event queue entries */
1756 #define FCN_EV_CODE_LBN 60
1757 #define FCN_EV_CODE_WIDTH 4
1758 #define FCN_RX_IP_EV_DECODE 0
1759 #define FCN_TX_IP_EV_DECODE 2
1760 #define FCN_DRIVER_EV_DECODE 5
1762 /* Receive events */
1763 #define FCN_RX_PORT_LBN 30
1764 #define FCN_RX_PORT_WIDTH 1
1765 #define FCN_RX_EV_BYTE_CNT_LBN 16
1766 #define FCN_RX_EV_BYTE_CNT_WIDTH 14
1767 #define FCN_RX_EV_DESC_PTR_LBN 0
1768 #define FCN_RX_EV_DESC_PTR_WIDTH 12
1770 /* Transmit events */
1771 #define FCN_TX_EV_DESC_PTR_LBN 0
1772 #define FCN_TX_EV_DESC_PTR_WIDTH 12
1774 /* Fixed special buffer numbers to use */
1775 #define FALCON_EVQ_ID 0
1776 #define FALCON_TXD_ID 1
1777 #define FALCON_RXD_ID 2
1779 #if FALCON_USE_IO_BAR
1781 /* Write dword via the I/O BAR */
1782 static inline void _falcon_writel ( struct efab_nic *efab, uint32_t value,
1783 unsigned int reg ) {
1784 outl ( reg, efab->iobase + FCN_IOM_IND_ADR_REG );
1785 outl ( value, efab->iobase + FCN_IOM_IND_DAT_REG );
1788 /* Read dword via the I/O BAR */
1789 static inline uint32_t _falcon_readl ( struct efab_nic *efab,
1790 unsigned int reg ) {
1791 outl ( reg, efab->iobase + FCN_IOM_IND_ADR_REG );
1792 return inl ( efab->iobase + FCN_IOM_IND_DAT_REG );
1795 #else /* FALCON_USE_IO_BAR */
1797 #define _falcon_writel( efab, value, reg ) \
1798 writel ( (value), (efab)->membase + (reg) )
1799 #define _falcon_readl( efab, reg ) readl ( (efab)->membase + (reg) )
1801 #endif /* FALCON_USE_IO_BAR */
1804 * Write to a Falcon register
1807 static inline void falcon_write ( struct efab_nic *efab, efab_oword_t *value,
1808 unsigned int reg ) {
1810 EFAB_REGDUMP ( "Writing register %x with " EFAB_OWORD_FMT "\n",
1811 reg, EFAB_OWORD_VAL ( *value ) );
1813 _falcon_writel ( efab, value->u32[0], reg + 0 );
1814 _falcon_writel ( efab, value->u32[1], reg + 4 );
1815 _falcon_writel ( efab, value->u32[2], reg + 8 );
1816 _falcon_writel ( efab, value->u32[3], reg + 12 );
1821 * Write to Falcon SRAM
1824 static inline void falcon_write_sram ( struct efab_nic *efab,
1825 efab_qword_t *value,
1826 unsigned int index ) {
1827 unsigned int reg = ( FCN_BUF_FULL_TBL_KER +
1828 ( index * sizeof ( *value ) ) );
1830 EFAB_REGDUMP ( "Writing SRAM register %x with " EFAB_QWORD_FMT "\n",
1831 reg, EFAB_QWORD_VAL ( *value ) );
1833 _falcon_writel ( efab, value->u32[0], reg + 0 );
1834 _falcon_writel ( efab, value->u32[1], reg + 4 );
1839 * Write dword to Falcon register that allows partial writes
1842 static inline void falcon_writel ( struct efab_nic *efab, efab_dword_t *value,
1843 unsigned int reg ) {
1844 EFAB_REGDUMP ( "Writing partial register %x with " EFAB_DWORD_FMT "\n",
1845 reg, EFAB_DWORD_VAL ( *value ) );
1846 _falcon_writel ( efab, value->u32[0], reg );
1850 * Read from a Falcon register
1853 static inline void falcon_read ( struct efab_nic *efab, efab_oword_t *value,
1854 unsigned int reg ) {
1855 value->u32[0] = _falcon_readl ( efab, reg + 0 );
1856 value->u32[1] = _falcon_readl ( efab, reg + 4 );
1857 value->u32[2] = _falcon_readl ( efab, reg + 8 );
1858 value->u32[3] = _falcon_readl ( efab, reg + 12 );
1860 EFAB_REGDUMP ( "Read from register %x, got " EFAB_OWORD_FMT "\n",
1861 reg, EFAB_OWORD_VAL ( *value ) );
1865 * Read from Falcon SRAM
1868 static inline void falcon_read_sram ( struct efab_nic *efab,
1869 efab_qword_t *value,
1870 unsigned int index ) {
1871 unsigned int reg = ( FCN_BUF_FULL_TBL_KER +
1872 ( index * sizeof ( *value ) ) );
1874 value->u32[0] = _falcon_readl ( efab, reg + 0 );
1875 value->u32[1] = _falcon_readl ( efab, reg + 4 );
1876 EFAB_REGDUMP ( "Read from SRAM register %x, got " EFAB_QWORD_FMT "\n",
1877 reg, EFAB_QWORD_VAL ( *value ) );
1881 * Read dword from a portion of a Falcon register
1884 static inline void falcon_readl ( struct efab_nic *efab, efab_dword_t *value,
1885 unsigned int reg ) {
1886 value->u32[0] = _falcon_readl ( efab, reg );
1887 EFAB_REGDUMP ( "Read from register %x, got " EFAB_DWORD_FMT "\n",
1888 reg, EFAB_DWORD_VAL ( *value ) );
1892 * Verified write to Falcon SRAM
1895 static inline void falcon_write_sram_verify ( struct efab_nic *efab,
1896 efab_qword_t *value,
1897 unsigned int index ) {
1898 efab_qword_t verify;
1900 falcon_write_sram ( efab, value, index );
1902 falcon_read_sram ( efab, &verify, index );
1903 if ( memcmp ( &verify, value, sizeof ( verify ) ) != 0 ) {
1904 printf ( "SRAM index %x failure: wrote " EFAB_QWORD_FMT
1905 " got " EFAB_QWORD_FMT "\n", index,
1906 EFAB_QWORD_VAL ( *value ),
1907 EFAB_QWORD_VAL ( verify ) );
1915 static void falcon_get_membase ( struct efab_nic *efab ) {
1916 unsigned long membase_phys;
1918 membase_phys = pci_bar_start ( efab->pci, PCI_BASE_ADDRESS_2 );
1919 efab->membase = ioremap ( membase_phys, 0x20000 );
1922 #define FCN_DUMP_REG( efab, _reg ) do { \
1924 falcon_read ( efab, ®, _reg ); \
1925 printf ( #_reg " = " EFAB_OWORD_FMT "\n", \
1926 EFAB_OWORD_VAL ( reg ) ); \
1929 #define FCN_DUMP_MAC_REG( efab, _mac_reg ) do { \
1931 efab->op->mac_readl ( efab, ®, _mac_reg ); \
1932 printf ( #_mac_reg " = " EFAB_DWORD_FMT "\n", \
1933 EFAB_DWORD_VAL ( reg ) ); \
1937 * Dump register contents (for debugging)
1939 * Marked as static inline so that it will not be compiled in if not
1942 static inline void falcon_dump_regs ( struct efab_nic *efab ) {
1943 FCN_DUMP_REG ( efab, FCN_INT_EN_REG_KER );
1944 FCN_DUMP_REG ( efab, FCN_INT_ADR_REG_KER );
1945 FCN_DUMP_REG ( efab, FCN_GLB_CTL_REG_KER );
1946 FCN_DUMP_REG ( efab, FCN_TIMER_CMD_REG_KER );
1947 FCN_DUMP_REG ( efab, FCN_SRM_RX_DC_CFG_REG_KER );
1948 FCN_DUMP_REG ( efab, FCN_SRM_TX_DC_CFG_REG_KER );
1949 FCN_DUMP_REG ( efab, FCN_RX_FILTER_CTL_REG_KER );
1950 FCN_DUMP_REG ( efab, FCN_RX_DC_CFG_REG_KER );
1951 FCN_DUMP_REG ( efab, FCN_TX_DC_CFG_REG_KER );
1952 FCN_DUMP_REG ( efab, FCN_MAC0_CTRL_REG_KER );
1953 FCN_DUMP_REG ( efab, FCN_MAC1_CTRL_REG_KER );
1954 FCN_DUMP_REG ( efab, FCN_XM_GLB_CFG_REG_P0_KER );
1955 FCN_DUMP_REG ( efab, FCN_XM_TX_CFG_REG_P0_KER );
1956 FCN_DUMP_REG ( efab, FCN_XM_RX_CFG_REG_P0_KER );
1957 FCN_DUMP_REG ( efab, FCN_RX_DESC_PTR_TBL_KER );
1958 FCN_DUMP_REG ( efab, FCN_TX_DESC_PTR_TBL_KER );
1959 FCN_DUMP_REG ( efab, FCN_EVQ_PTR_TBL_KER );
1960 FCN_DUMP_MAC_REG ( efab, GM_CFG1_REG_MAC );
1961 FCN_DUMP_MAC_REG ( efab, GM_CFG2_REG_MAC );
1962 FCN_DUMP_MAC_REG ( efab, GM_MAX_FLEN_REG_MAC );
1963 FCN_DUMP_MAC_REG ( efab, GM_MII_MGMT_CFG_REG_MAC );
1964 FCN_DUMP_MAC_REG ( efab, GM_ADR1_REG_MAC );
1965 FCN_DUMP_MAC_REG ( efab, GM_ADR2_REG_MAC );
1966 FCN_DUMP_MAC_REG ( efab, GMF_CFG0_REG_MAC );
1967 FCN_DUMP_MAC_REG ( efab, GMF_CFG1_REG_MAC );
1968 FCN_DUMP_MAC_REG ( efab, GMF_CFG2_REG_MAC );
1969 FCN_DUMP_MAC_REG ( efab, GMF_CFG3_REG_MAC );
1970 FCN_DUMP_MAC_REG ( efab, GMF_CFG4_REG_MAC );
1971 FCN_DUMP_MAC_REG ( efab, GMF_CFG5_REG_MAC );
1975 * Create special buffer
1978 static void falcon_create_special_buffer ( struct efab_nic *efab,
1979 void *addr, unsigned int index ) {
1980 efab_qword_t buf_desc;
1981 unsigned long dma_addr;
1983 memset ( addr, 0, 4096 );
1984 dma_addr = virt_to_bus ( addr );
1985 EFAB_ASSERT ( ( dma_addr & ( EFAB_BUF_ALIGN - 1 ) ) == 0 );
1986 EFAB_POPULATE_QWORD_3 ( buf_desc,
1987 FCN_IP_DAT_BUF_SIZE, FCN_IP_DAT_BUF_SIZE_4K,
1988 FCN_BUF_ADR_FBUF, ( dma_addr >> 12 ),
1989 FCN_BUF_OWNER_ID_FBUF, 0 );
1990 falcon_write_sram_verify ( efab, &buf_desc, index );
1994 * Update event queue read pointer
1997 static void falcon_eventq_read_ack ( struct efab_nic *efab ) {
2000 EFAB_ASSERT ( efab->eventq_read_ptr < EFAB_EVQ_SIZE );
2002 EFAB_POPULATE_DWORD_1 ( reg, FCN_EVQ_RPTR_DWORD,
2003 efab->eventq_read_ptr );
2004 falcon_writel ( efab, ®, FCN_EVQ_RPTR_REG_KER_DWORD );
2011 static int falcon_reset ( struct efab_nic *efab ) {
2012 efab_oword_t glb_ctl_reg_ker;
2014 /* Initiate software reset */
2015 EFAB_POPULATE_OWORD_5 ( glb_ctl_reg_ker,
2016 FCN_EXT_PHY_RST_CTL, FCN_EXCLUDE_FROM_RESET,
2017 FCN_PCIE_SD_RST_CTL, FCN_EXCLUDE_FROM_RESET,
2018 FCN_PCIX_RST_CTL, FCN_EXCLUDE_FROM_RESET,
2019 FCN_INT_RST_DUR, 0x7 /* datasheet */,
2021 falcon_write ( efab, &glb_ctl_reg_ker, FCN_GLB_CTL_REG_KER );
2023 /* Allow 20ms for reset */
2026 /* Check for device reset complete */
2027 falcon_read ( efab, &glb_ctl_reg_ker, FCN_GLB_CTL_REG_KER );
2028 if ( EFAB_OWORD_FIELD ( glb_ctl_reg_ker, FCN_SWRST ) != 0 ) {
2029 printf ( "Reset failed\n" );
2040 static int falcon_init_nic ( struct efab_nic *efab ) {
2042 efab_dword_t timer_cmd;
2044 /* Set up TX and RX descriptor caches in SRAM */
2045 EFAB_POPULATE_OWORD_1 ( reg, FCN_SRM_TX_DC_BASE_ADR,
2046 0x130000 /* recommended in datasheet */ );
2047 falcon_write ( efab, ®, FCN_SRM_TX_DC_CFG_REG_KER );
2048 EFAB_POPULATE_OWORD_1 ( reg, FCN_TX_DC_SIZE, 2 /* 32 descriptors */ );
2049 falcon_write ( efab, ®, FCN_TX_DC_CFG_REG_KER );
2050 EFAB_POPULATE_OWORD_1 ( reg, FCN_SRM_RX_DC_BASE_ADR,
2051 0x100000 /* recommended in datasheet */ );
2052 falcon_write ( efab, ®, FCN_SRM_RX_DC_CFG_REG_KER );
2053 EFAB_POPULATE_OWORD_1 ( reg, FCN_RX_DC_SIZE, 2 /* 32 descriptors */ );
2054 falcon_write ( efab, ®, FCN_RX_DC_CFG_REG_KER );
2056 /* Set number of RSS CPUs */
2057 EFAB_POPULATE_OWORD_1 ( reg, FCN_NUM_KER, 0 );
2058 falcon_write ( efab, ®, FCN_RX_FILTER_CTL_REG_KER );
2062 mentormac_reset ( efab );
2064 /* Set up event queue */
2065 falcon_create_special_buffer ( efab, efab->eventq, FALCON_EVQ_ID );
2066 EFAB_POPULATE_OWORD_3 ( reg,
2068 FCN_EVQ_SIZE, FCN_EVQ_SIZE_512,
2069 FCN_EVQ_BUF_BASE_ID, FALCON_EVQ_ID );
2070 falcon_write ( efab, ®, FCN_EVQ_PTR_TBL_KER );
2073 /* Set timer register */
2074 EFAB_POPULATE_DWORD_2 ( timer_cmd,
2075 FCN_TIMER_MODE, FCN_TIMER_MODE_DIS,
2077 falcon_writel ( efab, &timer_cmd, FCN_TIMER_CMD_REG_KER );
2080 /* Initialise event queue read pointer */
2081 falcon_eventq_read_ack ( efab );
2083 /* Set up TX descriptor ring */
2084 falcon_create_special_buffer ( efab, efab->txd, FALCON_TXD_ID );
2085 EFAB_POPULATE_OWORD_5 ( reg,
2087 FCN_TX_DESCQ_BUF_BASE_ID, FALCON_TXD_ID,
2088 FCN_TX_DESCQ_EVQ_ID, 0,
2089 FCN_TX_DESCQ_SIZE, FCN_TX_DESCQ_SIZE_512,
2090 FCN_TX_DESCQ_TYPE, 0 /* kernel queue */ );
2091 falcon_write ( efab, ®, FCN_TX_DESC_PTR_TBL_KER );
2093 /* Set up RX descriptor ring */
2094 falcon_create_special_buffer ( efab, efab->rxd, FALCON_RXD_ID );
2095 EFAB_POPULATE_OWORD_6 ( reg,
2096 FCN_RX_DESCQ_BUF_BASE_ID, FALCON_RXD_ID,
2097 FCN_RX_DESCQ_EVQ_ID, 0,
2098 FCN_RX_DESCQ_SIZE, FCN_RX_DESCQ_SIZE_512,
2099 FCN_RX_DESCQ_TYPE, 0 /* kernel queue */,
2100 FCN_RX_DESCQ_JUMBO, 1,
2101 FCN_RX_DESCQ_EN, 1 );
2102 falcon_write ( efab, ®, FCN_RX_DESC_PTR_TBL_KER );
2104 /* Program INT_ADR_REG_KER */
2105 EFAB_POPULATE_OWORD_1 ( reg,
2107 virt_to_bus ( &efab->int_ker ) );
2108 falcon_write ( efab, ®, FCN_INT_ADR_REG_KER );
2115 struct efab_spi_device {
2117 unsigned int device_id;
2118 /** Address length (in bytes) */
2119 unsigned int addr_len;
2121 unsigned int read_command;
2125 * Wait for SPI command completion
2128 static int falcon_spi_wait ( struct efab_nic *efab ) {
2135 falcon_read ( efab, ®, FCN_EE_SPI_HCMD_REG_KER );
2136 if ( EFAB_OWORD_FIELD ( reg, FCN_EE_SPI_HCMD_CMD_EN ) == 0 )
2138 } while ( ++count < 1000 );
2139 printf ( "Timed out waiting for SPI\n" );
2147 static int falcon_spi_read ( struct efab_nic *efab,
2148 struct efab_spi_device *spi,
2149 int address, void *data, unsigned int len ) {
2152 /* Program address register */
2153 EFAB_POPULATE_OWORD_1 ( reg, FCN_EE_SPI_HADR_ADR, address );
2154 falcon_write ( efab, ®, FCN_EE_SPI_HADR_REG_KER );
2156 /* Issue read command */
2157 EFAB_POPULATE_OWORD_7 ( reg,
2158 FCN_EE_SPI_HCMD_CMD_EN, 1,
2159 FCN_EE_SPI_HCMD_SF_SEL, spi->device_id,
2160 FCN_EE_SPI_HCMD_DABCNT, len,
2161 FCN_EE_SPI_HCMD_READ, FCN_EE_SPI_READ,
2162 FCN_EE_SPI_HCMD_DUBCNT, 0,
2163 FCN_EE_SPI_HCMD_ADBCNT, spi->addr_len,
2164 FCN_EE_SPI_HCMD_ENC, spi->read_command );
2165 falcon_write ( efab, ®, FCN_EE_SPI_HCMD_REG_KER );
2167 /* Wait for read to complete */
2168 if ( ! falcon_spi_wait ( efab ) )
2172 falcon_read ( efab, ®, FCN_EE_SPI_HDATA_REG_KER );
2173 memcpy ( data, ®, len );
2178 #define SPI_READ_CMD 0x03
2179 #define AT25F1024_ADDR_LEN 3
2180 #define AT25F1024_READ_CMD SPI_READ_CMD
2181 #define MC25XX640_ADDR_LEN 2
2182 #define MC25XX640_READ_CMD SPI_READ_CMD
2184 /** Falcon Flash SPI device */
2185 static struct efab_spi_device falcon_spi_flash = {
2186 .device_id = FCN_EE_SPI_FLASH,
2187 .addr_len = AT25F1024_ADDR_LEN,
2188 .read_command = AT25F1024_READ_CMD,
2191 /** Falcon EEPROM SPI device */
2192 static struct efab_spi_device falcon_spi_large_eeprom = {
2193 .device_id = FCN_EE_SPI_EEPROM,
2194 .addr_len = MC25XX640_ADDR_LEN,
2195 .read_command = MC25XX640_READ_CMD,
2198 /** Offset of MAC address within EEPROM or Flash */
2199 #define FALCON_MAC_ADDRESS_OFFSET(port) ( 0x310 + 0x08 * (port) )
2202 * Read MAC address from EEPROM
2205 static int falcon_read_eeprom ( struct efab_nic *efab ) {
2208 struct efab_spi_device *spi;
2210 /* Determine the SPI device containing the MAC address */
2211 falcon_read ( efab, ®, FCN_GPIO_CTL_REG_KER );
2212 has_flash = EFAB_OWORD_FIELD ( reg, FCN_FLASH_PRESENT );
2213 spi = has_flash ? &falcon_spi_flash : &falcon_spi_large_eeprom;
2215 return falcon_spi_read ( efab, spi,
2216 FALCON_MAC_ADDRESS_OFFSET ( efab->port ),
2217 efab->mac_addr, sizeof ( efab->mac_addr ) );
2220 /** RX descriptor */
2221 typedef efab_qword_t falcon_rx_desc_t;
2224 * Build RX descriptor
2227 static void falcon_build_rx_desc ( struct efab_nic *efab,
2228 struct efab_rx_buf *rx_buf ) {
2229 falcon_rx_desc_t *rxd;
2231 rxd = ( ( falcon_rx_desc_t * ) efab->rxd ) + rx_buf->id;
2232 EFAB_POPULATE_QWORD_2 ( *rxd,
2233 FCN_RX_KER_BUF_SIZE, EFAB_DATA_BUF_SIZE,
2235 virt_to_bus ( rx_buf->addr ) );
2239 * Update RX descriptor write pointer
2242 static void falcon_notify_rx_desc ( struct efab_nic *efab ) {
2245 EFAB_POPULATE_DWORD_1 ( reg, FCN_RX_DESC_WPTR_DWORD,
2246 efab->rx_write_ptr );
2247 falcon_writel ( efab, ®, FCN_RX_DESC_UPD_REG_KER_DWORD );
2250 /** TX descriptor */
2251 typedef efab_qword_t falcon_tx_desc_t;
2254 * Build TX descriptor
2257 static void falcon_build_tx_desc ( struct efab_nic *efab,
2258 struct efab_tx_buf *tx_buf ) {
2259 falcon_rx_desc_t *txd;
2261 txd = ( ( falcon_rx_desc_t * ) efab->txd ) + tx_buf->id;
2262 EFAB_POPULATE_QWORD_3 ( *txd,
2263 FCN_TX_KER_PORT, efab->port,
2264 FCN_TX_KER_BYTE_CNT, tx_buf->len,
2266 virt_to_bus ( tx_buf->addr ) );
2270 * Update TX descriptor write pointer
2273 static void falcon_notify_tx_desc ( struct efab_nic *efab ) {
2276 EFAB_POPULATE_DWORD_1 ( reg, FCN_TX_DESC_WPTR_DWORD,
2277 efab->tx_write_ptr );
2278 falcon_writel ( efab, ®, FCN_TX_DESC_UPD_REG_KER_DWORD );
2282 typedef efab_qword_t falcon_event_t;
2285 * Retrieve event from event queue
2288 static int falcon_fetch_event ( struct efab_nic *efab,
2289 struct efab_event *event ) {
2290 falcon_event_t *evt;
2294 /* Check for event */
2295 evt = ( ( falcon_event_t * ) efab->eventq ) + efab->eventq_read_ptr;
2296 if ( EFAB_QWORD_IS_ZERO ( *evt ) ) {
2301 DBG ( "Event is " EFAB_QWORD_FMT "\n", EFAB_QWORD_VAL ( *evt ) );
2304 ev_code = EFAB_QWORD_FIELD ( *evt, FCN_EV_CODE );
2305 switch ( ev_code ) {
2306 case FCN_TX_IP_EV_DECODE:
2307 event->type = EFAB_EV_TX;
2309 case FCN_RX_IP_EV_DECODE:
2310 event->type = EFAB_EV_RX;
2311 event->rx_id = EFAB_QWORD_FIELD ( *evt, FCN_RX_EV_DESC_PTR );
2312 event->rx_len = EFAB_QWORD_FIELD ( *evt, FCN_RX_EV_BYTE_CNT );
2313 rx_port = EFAB_QWORD_FIELD ( *evt, FCN_RX_PORT );
2314 if ( rx_port != efab->port ) {
2315 /* Ignore packets on the wrong port. We can't
2316 * just set event->type = EFAB_EV_NONE,
2317 * because then the descriptor ring won't get
2323 case FCN_DRIVER_EV_DECODE:
2324 /* Ignore start-of-day events */
2325 event->type = EFAB_EV_NONE;
2328 printf ( "Unknown event type %d\n", ev_code );
2329 event->type = EFAB_EV_NONE;
2332 /* Clear event and any pending interrupts */
2333 EFAB_ZERO_QWORD ( *evt );
2334 falcon_writel ( efab, 0, FCN_INT_ACK_KER_REG );
2337 /* Increment and update event queue read pointer */
2338 efab->eventq_read_ptr = ( ( efab->eventq_read_ptr + 1 )
2340 falcon_eventq_read_ack ( efab );
2346 * Enable/disable/generate interrupt
2349 static inline void falcon_interrupts ( struct efab_nic *efab, int enabled,
2351 efab_oword_t int_en_reg_ker;
2353 EFAB_POPULATE_OWORD_2 ( int_en_reg_ker,
2354 FCN_KER_INT_KER, force,
2355 FCN_DRV_INT_EN_KER, enabled );
2356 falcon_write ( efab, &int_en_reg_ker, FCN_INT_EN_REG_KER );
2360 * Enable/disable interrupts
2363 static void falcon_mask_irq ( struct efab_nic *efab, int enabled ) {
2364 falcon_interrupts ( efab, enabled, 0 );
2366 /* Events won't trigger interrupts until we do this */
2367 falcon_eventq_read_ack ( efab );
2372 * Generate interrupt
2375 static void falcon_generate_irq ( struct efab_nic *efab ) {
2376 falcon_interrupts ( efab, 1, 1 );
2380 * Write dword to a Falcon MAC register
2383 static void falcon_mac_writel ( struct efab_nic *efab,
2384 efab_dword_t *value, unsigned int mac_reg ) {
2387 EFAB_POPULATE_OWORD_1 ( temp, FCN_MAC_DATA,
2388 EFAB_DWORD_FIELD ( *value, FCN_MAC_DATA ) );
2389 falcon_write ( efab, &temp, FALCON_MAC_REG ( efab, mac_reg ) );
2393 * Read dword from a Falcon MAC register
2396 static void falcon_mac_readl ( struct efab_nic *efab, efab_dword_t *value,
2397 unsigned int mac_reg ) {
2400 falcon_read ( efab, &temp, FALCON_MAC_REG ( efab, mac_reg ) );
2401 EFAB_POPULATE_DWORD_1 ( *value, FCN_MAC_DATA,
2402 EFAB_OWORD_FIELD ( temp, FCN_MAC_DATA ) );
2409 static int falcon_init_mac ( struct efab_nic *efab ) {
2410 static struct efab_mentormac_parameters falcon_mentormac_params = {
2411 .gmf_cfgfrth = 0x12,
2412 .gmf_cfgftth = 0x08,
2413 .gmf_cfghwmft = 0x1c,
2420 /* Initialise PHY */
2421 alaska_init ( efab );
2423 /* Initialise MAC */
2424 mentormac_init ( efab, &falcon_mentormac_params );
2426 /* Configure the Falcon MAC wrapper */
2427 EFAB_POPULATE_OWORD_4 ( reg,
2428 FCN_XM_RX_JUMBO_MODE, 0,
2429 FCN_XM_CUT_THRU_MODE, 0,
2430 FCN_XM_TX_STAT_EN, 1,
2431 FCN_XM_RX_STAT_EN, 1);
2432 falcon_write ( efab, ®, FCN_XM_GLB_CFG_REG_P0_KER );
2434 EFAB_POPULATE_OWORD_6 ( reg,
2439 FCN_XM_WTF_DOES_THIS_DO, 1,
2441 falcon_write ( efab, ®, FCN_XM_TX_CFG_REG_P0_KER );
2443 EFAB_POPULATE_OWORD_3 ( reg,
2445 FCN_XM_AUTO_DEPAD, 1,
2446 FCN_XM_PASS_CRC_ERR, 1 );
2447 falcon_write ( efab, ®, FCN_XM_RX_CFG_REG_P0_KER );
2449 #warning "10G support not yet present"
2451 if ( efab->link_options & LPA_10000 ) {
2453 } else if ( efab->link_options & LPA_1000 ) {
2455 } else if ( efab->link_options & LPA_100 ) {
2460 EFAB_POPULATE_OWORD_5 ( reg,
2461 FCN_MAC_XOFF_VAL, 0xffff /* datasheet */,
2462 FCN_MAC_BCAD_ACPT, 1,
2464 FCN_MAC_LINK_STATUS, 1,
2465 FCN_MAC_SPEED, link_speed );
2466 falcon_write ( efab, ®, ( efab->port == 0 ?
2467 FCN_MAC0_CTRL_REG_KER : FCN_MAC1_CTRL_REG_KER ) );
2473 * Wait for GMII access to complete
2476 static int falcon_gmii_wait ( struct efab_nic *efab ) {
2477 efab_oword_t md_stat;
2480 for ( count = 0 ; count < 1000 ; count++ ) {
2482 falcon_read ( efab, &md_stat, FCN_MD_STAT_REG_KER );
2483 if ( EFAB_OWORD_FIELD ( md_stat, FCN_MD_BSY ) == 0 )
2486 printf ( "Timed out waiting for GMII\n" );
2491 static void falcon_mdio_write ( struct efab_nic *efab, int location,
2493 int phy_id = efab->port + 2;
2496 #warning "10G PHY access not yet in place"
2498 EFAB_TRACE ( "Writing GMII %d register %02x with %04x\n",
2499 phy_id, location, value );
2501 /* Check MII not currently being accessed */
2502 if ( ! falcon_gmii_wait ( efab ) )
2505 /* Write the address registers */
2506 EFAB_POPULATE_OWORD_1 ( reg, FCN_MD_PHY_ADR, 0 /* phy_id ? */ );
2507 falcon_write ( efab, ®, FCN_MD_PHY_ADR_REG_KER );
2509 EFAB_POPULATE_OWORD_2 ( reg,
2510 FCN_MD_PRT_ADR, phy_id,
2511 FCN_MD_DEV_ADR, location );
2512 falcon_write ( efab, ®, FCN_MD_ID_REG_KER );
2516 EFAB_POPULATE_OWORD_1 ( reg, FCN_MD_TXD, value );
2517 falcon_write ( efab, ®, FCN_MD_TXD_REG_KER );
2519 EFAB_POPULATE_OWORD_2 ( reg,
2522 falcon_write ( efab, ®, FCN_MD_CS_REG_KER );
2525 /* Wait for data to be written */
2526 falcon_gmii_wait ( efab );
2530 static int falcon_mdio_read ( struct efab_nic *efab, int location ) {
2531 int phy_id = efab->port + 2;
2535 /* Check MII not currently being accessed */
2536 if ( ! falcon_gmii_wait ( efab ) )
2539 /* Write the address registers */
2540 EFAB_POPULATE_OWORD_1 ( reg, FCN_MD_PHY_ADR, 0 /* phy_id ? */ );
2541 falcon_write ( efab, ®, FCN_MD_PHY_ADR_REG_KER );
2543 EFAB_POPULATE_OWORD_2 ( reg,
2544 FCN_MD_PRT_ADR, phy_id,
2545 FCN_MD_DEV_ADR, location );
2546 falcon_write ( efab, ®, FCN_MD_ID_REG_KER );
2549 /* Request data to be read */
2550 EFAB_POPULATE_OWORD_2 ( reg,
2553 falcon_write ( efab, ®, FCN_MD_CS_REG_KER );
2556 /* Wait for data to become available */
2557 falcon_gmii_wait ( efab );
2560 falcon_read ( efab, ®, FCN_MD_RXD_REG_KER );
2561 value = EFAB_OWORD_FIELD ( reg, FCN_MD_RXD );
2563 EFAB_TRACE ( "Read from GMII %d register %02x, got %04x\n",
2564 phy_id, location, value );
2569 static struct efab_operations falcon_operations = {
2570 .get_membase = falcon_get_membase,
2571 .reset = falcon_reset,
2572 .init_nic = falcon_init_nic,
2573 .read_eeprom = falcon_read_eeprom,
2574 .build_rx_desc = falcon_build_rx_desc,
2575 .notify_rx_desc = falcon_notify_rx_desc,
2576 .build_tx_desc = falcon_build_tx_desc,
2577 .notify_tx_desc = falcon_notify_tx_desc,
2578 .fetch_event = falcon_fetch_event,
2579 .mask_irq = falcon_mask_irq,
2580 .generate_irq = falcon_generate_irq,
2581 .mac_writel = falcon_mac_writel,
2582 .mac_readl = falcon_mac_readl,
2583 .init_mac = falcon_init_mac,
2584 .mdio_write = falcon_mdio_write,
2585 .mdio_read = falcon_mdio_read,
2588 /**************************************************************************
2590 * Etherfabric abstraction layer
2592 **************************************************************************
2596 * Push RX buffer to RXD ring
2599 static inline void efab_push_rx_buffer ( struct efab_nic *efab,
2600 struct efab_rx_buf *rx_buf ) {
2601 /* Create RX descriptor */
2602 rx_buf->id = efab->rx_write_ptr;
2603 efab->op->build_rx_desc ( efab, rx_buf );
2605 /* Update RX write pointer */
2606 efab->rx_write_ptr = ( efab->rx_write_ptr + 1 ) % EFAB_RXD_SIZE;
2607 efab->op->notify_rx_desc ( efab );
2609 DBG ( "Added RX id %x\n", rx_buf->id );
2613 * Push TX buffer to TXD ring
2616 static inline void efab_push_tx_buffer ( struct efab_nic *efab,
2617 struct efab_tx_buf *tx_buf ) {
2618 /* Create TX descriptor */
2619 tx_buf->id = efab->tx_write_ptr;
2620 efab->op->build_tx_desc ( efab, tx_buf );
2622 /* Update TX write pointer */
2623 efab->tx_write_ptr = ( efab->tx_write_ptr + 1 ) % EFAB_TXD_SIZE;
2624 efab->op->notify_tx_desc ( efab );
2626 DBG ( "Added TX id %x\n", tx_buf->id );
2630 * Initialise MAC and wait for link up
2633 static int efab_init_mac ( struct efab_nic *efab ) {
2636 /* This can take several seconds */
2637 printf ( "Waiting for link.." );
2641 if ( ! efab->op->init_mac ( efab ) ) {
2642 printf ( "failed\n" );
2645 if ( efab->link_up ) {
2646 /* PHY init printed the message for us */
2650 } while ( ++count < 5 );
2651 printf ( "timed out\n" );
2660 static int efab_init_nic ( struct efab_nic *efab ) {
2663 /* Initialise NIC */
2664 if ( ! efab->op->init_nic ( efab ) )
2667 /* Push RX descriptors */
2668 for ( i = 0 ; i < EFAB_RX_BUFS ; i++ ) {
2669 efab_push_rx_buffer ( efab, &efab->rx_bufs[i] );
2672 /* Read MAC address from EEPROM */
2673 if ( ! efab->op->read_eeprom ( efab ) )
2675 efab->mac_addr[ETH_ALEN-1] += efab->port;
2677 /* Initialise MAC and wait for link up */
2678 if ( ! efab_init_mac ( efab ) )
2684 /**************************************************************************
2686 * Etherboot interface
2688 **************************************************************************
2691 /**************************************************************************
2692 POLL - Wait for a frame
2693 ***************************************************************************/
2694 static int etherfabric_poll ( struct nic *nic, int retrieve ) {
2695 struct efab_nic *efab = nic->priv_data;
2696 struct efab_event event;
2697 static struct efab_rx_buf *rx_buf = NULL;
2700 /* Process the event queue until we hit either a packet
2701 * received event or an empty event slot.
2703 while ( ( rx_buf == NULL ) &&
2704 efab->op->fetch_event ( efab, &event ) ) {
2705 if ( event.type == EFAB_EV_TX ) {
2706 /* TX completed - mark as done */
2707 DBG ( "TX id %x complete\n",
2709 efab->tx_in_progress = 0;
2710 } else if ( event.type == EFAB_EV_RX ) {
2711 /* RX - find corresponding buffer */
2712 for ( i = 0 ; i < EFAB_RX_BUFS ; i++ ) {
2713 if ( efab->rx_bufs[i].id == event.rx_id ) {
2714 rx_buf = &efab->rx_bufs[i];
2715 rx_buf->len = event.rx_len;
2716 DBG ( "RX id %x (len %x) received\n",
2717 rx_buf->id, rx_buf->len );
2722 printf ( "Invalid RX ID %x\n", event.rx_id );
2724 } else if ( event.type == EFAB_EV_NONE ) {
2725 DBG ( "Ignorable event\n" );
2727 DBG ( "Unknown event\n" );
2731 /* If there is no packet, return 0 */
2735 /* If we don't want to retrieve it just yet, return 1 */
2739 /* There seems to be a hardware race. The event can show up
2740 * on the event FIFO before the DMA has completed, so we
2741 * insert a tiny delay. If this proves unreliable, we should
2742 * switch to using event DMA rather than the event FIFO, since
2743 * event DMA ordering is guaranteed.
2747 /* Copy packet contents */
2748 nic->packetlen = rx_buf->len;
2749 memcpy ( nic->packet, rx_buf->addr, nic->packetlen );
2751 /* Give this buffer back to the NIC */
2752 efab_push_rx_buffer ( efab, rx_buf );
2754 /* Prepare to receive next packet */
2760 /**************************************************************************
2761 TRANSMIT - Transmit a frame
2762 ***************************************************************************/
2763 static void etherfabric_transmit ( struct nic *nic, const char *dest,
2764 unsigned int type, unsigned int size,
2765 const char *data ) {
2766 struct efab_nic *efab = nic->priv_data;
2767 unsigned int nstype = htons ( type );
2769 /* We can only transmit one packet at a time; a TX completion
2770 * event must be received before we can transmit the next
2771 * packet. Since there is only one static TX buffer, we don't
2772 * worry unduly about overflow, but we report it anyway.
2774 if ( efab->tx_in_progress ) {
2775 printf ( "TX overflow!\n" );
2778 /* Fill TX buffer, pad to ETH_ZLEN */
2779 memcpy ( efab->tx_buf.addr, dest, ETH_ALEN );
2780 memcpy ( efab->tx_buf.addr + ETH_ALEN, nic->node_addr, ETH_ALEN );
2781 memcpy ( efab->tx_buf.addr + 2 * ETH_ALEN, &nstype, 2 );
2782 memcpy ( efab->tx_buf.addr + ETH_HLEN, data, size );
2784 while ( size < ETH_ZLEN ) {
2785 efab->tx_buf.addr[size++] = '\0';
2787 efab->tx_buf.len = size;
2789 /* Push TX descriptor */
2790 efab_push_tx_buffer ( efab, &efab->tx_buf );
2792 /* There is no way to wait for TX complete (i.e. TX buffer
2793 * available to re-use for the next transmit) without reading
2794 * from the event queue. We therefore simply leave the TX
2795 * buffer marked as "in use" until a TX completion event
2796 * happens to be picked up by a call to etherfabric_poll().
2798 efab->tx_in_progress = 1;
2803 /**************************************************************************
2804 DISABLE - Turn off ethernet interface
2805 ***************************************************************************/
2806 static void etherfabric_disable ( struct nic *nic ) {
2807 struct efab_nic *efab = nic->priv_data;
2809 efab->op->reset ( efab );
2810 if ( efab->membase )
2811 iounmap ( efab->membase );
2814 /**************************************************************************
2815 IRQ - handle interrupts
2816 ***************************************************************************/
2817 static void etherfabric_irq ( struct nic *nic, irq_action_t action ) {
2818 struct efab_nic *efab = nic->priv_data;
2822 efab->op->mask_irq ( efab, 1 );
2825 efab->op->mask_irq ( efab, 0 );
2828 /* Force NIC to generate a receive interrupt */
2829 efab->op->generate_irq ( efab );
2836 static struct nic_operations etherfabric_operations = {
2837 .connect = dummy_connect,
2838 .poll = etherfabric_poll,
2839 .transmit = etherfabric_transmit,
2840 .irq = etherfabric_irq,
2843 /**************************************************************************
2844 PROBE - Look for an adapter, this routine's visible to the outside
2845 ***************************************************************************/
2846 static int etherfabric_probe ( struct nic *nic, struct pci_device *pci ) {
2847 static struct efab_nic efab;
2848 static int nic_port = 1;
2849 struct efab_buffers *buffers;
2852 /* Set up our private data structure */
2853 nic->priv_data = &efab;
2854 memset ( &efab, 0, sizeof ( efab ) );
2855 memset ( &efab_buffers, 0, sizeof ( efab_buffers ) );
2857 /* Hook in appropriate operations table. Do this early. */
2858 if ( pci->device == EF1002_DEVID ) {
2859 efab.op = &ef1002_operations;
2861 efab.op = &falcon_operations;
2864 /* Initialise efab data structure */
2866 buffers = ( ( struct efab_buffers * )
2867 ( ( ( void * ) &efab_buffers ) +
2868 ( - virt_to_bus ( &efab_buffers ) ) % EFAB_BUF_ALIGN ) );
2869 efab.eventq = buffers->eventq;
2870 efab.txd = buffers->txd;
2871 efab.rxd = buffers->rxd;
2872 efab.tx_buf.addr = buffers->tx_buf;
2873 for ( i = 0 ; i < EFAB_RX_BUFS ; i++ ) {
2874 efab.rx_bufs[i].addr = buffers->rx_buf[i];
2877 /* Enable the PCI device */
2878 adjust_pci_device ( pci );
2879 nic->ioaddr = pci->ioaddr & ~3;
2880 nic->irqno = pci->irq;
2882 /* Get iobase/membase */
2883 efab.iobase = nic->ioaddr;
2884 efab.op->get_membase ( &efab );
2886 /* Switch NIC ports (i.e. try different ports on each probe) */
2887 nic_port = 1 - nic_port;
2888 efab.port = nic_port;
2890 /* Initialise hardware */
2891 if ( ! efab_init_nic ( &efab ) )
2893 memcpy ( nic->node_addr, efab.mac_addr, ETH_ALEN );
2896 printf ( "Found EtherFabric %s NIC %!\n", pci->name, nic->node_addr );
2898 /* point to NIC specific routines */
2899 nic->nic_op = ðerfabric_operations;
2904 static struct pci_device_id etherfabric_nics[] = {
2905 PCI_ROM(0x1924, 0xC101, "ef1002", "EtherFabric EF1002"),
2906 PCI_ROM(0x1924, 0x0703, "falcon", "EtherFabric Falcon"),
2909 PCI_DRIVER ( etherfabric_driver, etherfabric_nics, PCI_NO_CLASS );
2911 DRIVER ( "EFAB", nic_driver, pci_driver, etherfabric_driver,
2912 etherfabric_probe, etherfabric_disable );