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 );
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_LB_RESET_LBN 3
750 #define EF1_LB_RESET_WIDTH 1
751 #define EF1_MAC_RESET_LBN 2
752 #define EF1_MAC_RESET_WIDTH 1
753 #define EF1_CAM_ENABLE_LBN 1
754 #define EF1_CAM_ENABLE_WIDTH 1
757 #define EF1_IRQ_SRC_REG 0x0008
760 #define EF1_IRQ_MASK_REG 0x000c
761 #define EF1_IRQ_PHY1_LBN 11
762 #define EF1_IRQ_PHY1_WIDTH 1
763 #define EF1_IRQ_PHY0_LBN 10
764 #define EF1_IRQ_PHY0_WIDTH 1
765 #define EF1_IRQ_SERR_LBN 7
766 #define EF1_IRQ_SERR_WIDTH 1
767 #define EF1_IRQ_EVQ_LBN 3
768 #define EF1_IRQ_EVQ_WIDTH 1
770 /** Event generation */
771 #define EF1_EVT3_REG 0x38
774 #define EF1_EEPROM_REG 0x40
775 #define EF1_EEPROM_SDA_LBN 31
776 #define EF1_EEPROM_SDA_WIDTH 1
777 #define EF1_EEPROM_SCL_LBN 30
778 #define EF1_EEPROM_SCL_WIDTH 1
779 #define EF1_JTAG_DISCONNECT_LBN 17
780 #define EF1_JTAG_DISCONNECT_WIDTH 1
781 #define EF1_EEPROM_LBN 0
782 #define EF1_EEPROM_WIDTH 32
784 /** Control register 2 */
785 #define EF1_CTL2_REG 0x4c
786 #define EF1_PLL_TRAP_LBN 31
787 #define EF1_PLL_TRAP_WIDTH 1
788 #define EF1_MEM_MAP_4MB_LBN 11
789 #define EF1_MEM_MAP_4MB_WIDTH 1
790 #define EF1_EV_INTR_CLR_WRITE_LBN 6
791 #define EF1_EV_INTR_CLR_WRITE_WIDTH 1
792 #define EF1_BURST_MERGE_LBN 5
793 #define EF1_BURST_MERGE_WIDTH 1
794 #define EF1_CLEAR_NULL_PAD_LBN 4
795 #define EF1_CLEAR_NULL_PAD_WIDTH 1
796 #define EF1_SW_RESET_LBN 2
797 #define EF1_SW_RESET_WIDTH 1
798 #define EF1_INTR_AFTER_EVENT_LBN 1
799 #define EF1_INTR_AFTER_EVENT_WIDTH 1
802 #define EF1_EVENT_FIFO_REG 0x50
804 /** Event FIFO count */
805 #define EF1_EVENT_FIFO_COUNT_REG 0x5c
806 #define EF1_EV_COUNT_LBN 0
807 #define EF1_EV_COUNT_WIDTH 16
809 /** TX DMA control and status */
810 #define EF1_DMA_TX_CSR_REG 0x80
811 #define EF1_DMA_TX_CSR_CHAIN_EN_LBN 8
812 #define EF1_DMA_TX_CSR_CHAIN_EN_WIDTH 1
813 #define EF1_DMA_TX_CSR_ENABLE_LBN 4
814 #define EF1_DMA_TX_CSR_ENABLE_WIDTH 1
815 #define EF1_DMA_TX_CSR_INT_EN_LBN 0
816 #define EF1_DMA_TX_CSR_INT_EN_WIDTH 1
818 /** RX DMA control and status */
819 #define EF1_DMA_RX_CSR_REG 0xa0
820 #define EF1_DMA_RX_ABOVE_1GB_EN_LBN 6
821 #define EF1_DMA_RX_ABOVE_1GB_EN_WIDTH 1
822 #define EF1_DMA_RX_BELOW_1MB_EN_LBN 5
823 #define EF1_DMA_RX_BELOW_1MB_EN_WIDTH 1
824 #define EF1_DMA_RX_CSR_ENABLE_LBN 0
825 #define EF1_DMA_RX_CSR_ENABLE_WIDTH 1
827 /** Level 5 watermark register (in MAC space) */
828 #define EF1_GMF_L5WM_REG_MAC 0x20
829 #define EF1_L5WM_LBN 0
830 #define EF1_L5WM_WIDTH 32
833 #define EF1_GM_MAC_CLK_REG 0x112000
834 #define EF1_GM_PORT0_MAC_CLK_LBN 0
835 #define EF1_GM_PORT0_MAC_CLK_WIDTH 1
836 #define EF1_GM_PORT1_MAC_CLK_LBN 1
837 #define EF1_GM_PORT1_MAC_CLK_WIDTH 1
839 /** TX descriptor FIFO */
840 #define EF1_TX_DESC_FIFO 0x141000
841 #define EF1_TX_KER_EVQ_LBN 80
842 #define EF1_TX_KER_EVQ_WIDTH 12
843 #define EF1_TX_KER_IDX_LBN 64
844 #define EF1_TX_KER_IDX_WIDTH 16
845 #define EF1_TX_KER_MODE_LBN 63
846 #define EF1_TX_KER_MODE_WIDTH 1
847 #define EF1_TX_KER_PORT_LBN 60
848 #define EF1_TX_KER_PORT_WIDTH 1
849 #define EF1_TX_KER_CONT_LBN 56
850 #define EF1_TX_KER_CONT_WIDTH 1
851 #define EF1_TX_KER_BYTE_CNT_LBN 32
852 #define EF1_TX_KER_BYTE_CNT_WIDTH 24
853 #define EF1_TX_KER_BUF_ADR_LBN 0
854 #define EF1_TX_KER_BUF_ADR_WIDTH 32
856 /** TX descriptor FIFO flush */
857 #define EF1_TX_DESC_FIFO_FLUSH 0x141ffc
859 /** RX descriptor FIFO */
860 #define EF1_RX_DESC_FIFO 0x145000
861 #define EF1_RX_KER_EVQ_LBN 48
862 #define EF1_RX_KER_EVQ_WIDTH 12
863 #define EF1_RX_KER_IDX_LBN 32
864 #define EF1_RX_KER_IDX_WIDTH 16
865 #define EF1_RX_KER_BUF_ADR_LBN 0
866 #define EF1_RX_KER_BUF_ADR_WIDTH 32
868 /** RX descriptor FIFO flush */
869 #define EF1_RX_DESC_FIFO_FLUSH 0x145ffc
872 #define EF1_CAM_BASE 0x1c0000
873 #define EF1_CAM_WTF_DOES_THIS_DO_LBN 0
874 #define EF1_CAM_WTF_DOES_THIS_DO_WIDTH 32
876 /** Event queue pointers */
877 #define EF1_EVQ_PTR_BASE 0x260000
878 #define EF1_EVQ_SIZE_LBN 29
879 #define EF1_EVQ_SIZE_WIDTH 2
880 #define EF1_EVQ_SIZE_4K 3
881 #define EF1_EVQ_SIZE_2K 2
882 #define EF1_EVQ_SIZE_1K 1
883 #define EF1_EVQ_SIZE_512 0
884 #define EF1_EVQ_BUF_BASE_ID_LBN 0
885 #define EF1_EVQ_BUF_BASE_ID_WIDTH 29
888 #define EF1002_MAC_REGBANK 0x110000
889 #define EF1002_MAC_REGBANK_SIZE 0x1000
890 #define EF1002_MAC_REG_SIZE 0x08
892 /** Offset of a MAC register within EF1002 */
893 #define EF1002_MAC_REG( efab, mac_reg ) \
894 ( EF1002_MAC_REGBANK + \
895 ( (efab)->port * EF1002_MAC_REGBANK_SIZE ) + \
896 ( (mac_reg) * EF1002_MAC_REG_SIZE ) )
898 /* Event queue entries */
899 #define EF1_EV_CODE_LBN 20
900 #define EF1_EV_CODE_WIDTH 8
901 #define EF1_RX_EV_DECODE 0x01
902 #define EF1_TX_EV_DECODE 0x02
903 #define EF1_DRV_GEN_EV_DECODE 0x0f
906 #define EF1_RX_EV_LEN_LBN 48
907 #define EF1_RX_EV_LEN_WIDTH 16
908 #define EF1_RX_EV_PORT_LBN 17
909 #define EF1_RX_EV_PORT_WIDTH 3
910 #define EF1_RX_EV_OK_LBN 16
911 #define EF1_RX_EV_OK_WIDTH 1
912 #define EF1_RX_EV_IDX_LBN 0
913 #define EF1_RX_EV_IDX_WIDTH 16
915 /* Transmit events */
916 #define EF1_TX_EV_PORT_LBN 17
917 #define EF1_TX_EV_PORT_WIDTH 3
918 #define EF1_TX_EV_OK_LBN 16
919 #define EF1_TX_EV_OK_WIDTH 1
920 #define EF1_TX_EV_IDX_LBN 0
921 #define EF1_TX_EV_IDX_WIDTH 16
923 /* I2C ID of the EEPROM */
924 #define EF1_EEPROM_I2C_ID 0x50
926 /* Offset of MAC address within EEPROM */
927 #define EF1_EEPROM_HWADDR_OFFSET 0x0
930 * Write dword to EF1002 register
933 static inline void ef1002_writel ( struct efab_nic *efab, efab_dword_t *value,
935 EFAB_REGDUMP ( "Writing register %x with " EFAB_DWORD_FMT "\n",
936 reg, EFAB_DWORD_VAL ( *value ) );
937 writel ( value->u32[0], efab->membase + reg );
941 * Read dword from an EF1002 register
944 static inline void ef1002_readl ( struct efab_nic *efab, efab_dword_t *value,
946 value->u32[0] = readl ( efab->membase + reg );
947 EFAB_REGDUMP ( "Read from register %x, got " EFAB_DWORD_FMT "\n",
948 reg, EFAB_DWORD_VAL ( *value ) );
952 * Read dword from an EF1002 register, silently
955 static inline void ef1002_readl_silent ( struct efab_nic *efab,
958 value->u32[0] = readl ( efab->membase + reg );
965 static void ef1002_get_membase ( struct efab_nic *efab ) {
966 unsigned long membase_phys;
968 membase_phys = pci_bar_start ( efab->pci, PCI_BASE_ADDRESS_0 );
969 efab->membase = ioremap ( membase_phys, 0x800000 );
972 /** PCI registers to backup/restore over a device reset */
973 static const unsigned int efab_pci_reg_addr[] = {
974 PCI_COMMAND, 0x0c /* PCI_CACHE_LINE_SIZE */,
975 PCI_BASE_ADDRESS_0, PCI_BASE_ADDRESS_1, PCI_BASE_ADDRESS_2,
976 PCI_BASE_ADDRESS_3, PCI_ROM_ADDRESS, PCI_INTERRUPT_LINE,
978 /** Number of registers in efab_pci_reg_addr */
979 #define EFAB_NUM_PCI_REG \
980 ( sizeof ( efab_pci_reg_addr ) / sizeof ( efab_pci_reg_addr[0] ) )
981 /** PCI configuration space backup */
982 struct efab_pci_reg {
983 uint32_t reg[EFAB_NUM_PCI_REG];
987 * I2C interface and EEPROM
991 static unsigned long ef1002_i2c_bits[] = {
992 [I2C_BIT_SCL] = ( 1 << 30 ),
993 [I2C_BIT_SDA] = ( 1 << 31 ),
996 static void ef1002_i2c_write_bit ( struct bit_basher *basher,
997 unsigned int bit_id, unsigned long data ) {
998 struct efab_nic *efab = container_of ( basher, struct efab_nic,
1003 mask = ef1002_i2c_bits[bit_id];
1004 efab->ef1002_i2c_outputs &= ~mask;
1005 efab->ef1002_i2c_outputs |= ( data & mask );
1006 EFAB_POPULATE_DWORD_1 ( reg, EF1_EEPROM, efab->ef1002_i2c_outputs );
1007 ef1002_writel ( efab, ®, EF1_EEPROM_REG );
1010 static int ef1002_i2c_read_bit ( struct bit_basher *basher,
1011 unsigned int bit_id ) {
1012 struct efab_nic *efab = container_of ( basher, struct efab_nic,
1013 ef1002_i2c.basher );
1017 mask = ef1002_i2c_bits[bit_id];
1018 ef1002_readl ( efab, ®, EF1_EEPROM_REG );
1019 return ( EFAB_DWORD_FIELD ( reg, EF1_EEPROM ) & mask );
1022 static void ef1002_init_eeprom ( struct efab_nic *efab ) {
1023 efab->ef1002_i2c.basher.write = ef1002_i2c_write_bit;
1024 efab->ef1002_i2c.basher.read = ef1002_i2c_read_bit;
1025 init_i2c_bit_basher ( &efab->ef1002_i2c );
1026 efab->ef1002_eeprom.address = EF1_EEPROM_I2C_ID;
1033 static int ef1002_reset ( struct efab_nic *efab ) {
1034 struct efab_pci_reg pci_reg;
1035 struct pci_device *pci_dev = efab->pci;
1040 /* Back up PCI configuration registers */
1041 for ( i = 0 ; i < EFAB_NUM_PCI_REG ; i++ ) {
1042 pci_read_config_dword ( pci_dev, efab_pci_reg_addr[i],
1046 /* Reset the whole device. */
1047 EFAB_POPULATE_DWORD_1 ( reg, EF1_SW_RESET, 1 );
1048 ef1002_writel ( efab, ®, EF1_CTL2_REG );
1051 /* Restore PCI configuration space */
1052 for ( i = 0 ; i < EFAB_NUM_PCI_REG ; i++ ) {
1053 pci_write_config_dword ( pci_dev, efab_pci_reg_addr[i],
1057 /* Verify PCI configuration space */
1058 for ( i = 0 ; i < EFAB_NUM_PCI_REG ; i++ ) {
1059 pci_read_config_dword ( pci_dev, efab_pci_reg_addr[i], &tmp );
1060 if ( tmp != pci_reg.reg[i] ) {
1061 printf ( "PCI restore failed on register %02x "
1062 "(is %08lx, should be %08lx); reboot\n",
1063 i, tmp, pci_reg.reg[i] );
1068 /* Verify device reset complete */
1069 ef1002_readl ( efab, ®, EF1_CTR_GEN_STATUS0_REG );
1070 if ( EFAB_DWORD_IS_ALL_ONES ( reg ) ) {
1071 printf ( "Reset failed\n" );
1082 static int ef1002_init_nic ( struct efab_nic *efab ) {
1085 /* No idea what CAM is, but the 'datasheet' says that we have
1086 * to write these values in at start of day
1088 EFAB_POPULATE_DWORD_1 ( reg, EF1_CAM_WTF_DOES_THIS_DO, 0x6 );
1089 ef1002_writel ( efab, ®, EF1_CAM_BASE + 0x20018 );
1091 EFAB_POPULATE_DWORD_1 ( reg, EF1_CAM_WTF_DOES_THIS_DO, 0x01000000 );
1092 ef1002_writel ( efab, ®, EF1_CAM_BASE + 0x00018 );
1095 /* General control register 0 */
1096 ef1002_readl ( efab, ®, EF1_CTR_GEN_STATUS0_REG );
1097 EFAB_SET_DWORD_FIELD ( reg, EF1_MASTER_EVENTS, 0 );
1098 EFAB_SET_DWORD_FIELD ( reg, EF1_TX_ENGINE_EN, 0 );
1099 EFAB_SET_DWORD_FIELD ( reg, EF1_RX_ENGINE_EN, 0 );
1100 EFAB_SET_DWORD_FIELD ( reg, EF1_CAM_ENABLE, 1 );
1101 ef1002_writel ( efab, ®, EF1_CTR_GEN_STATUS0_REG );
1104 /* General control register 2 */
1105 ef1002_readl ( efab, ®, EF1_CTL2_REG );
1106 EFAB_SET_DWORD_FIELD ( reg, EF1_PLL_TRAP, 1 );
1107 EFAB_SET_DWORD_FIELD ( reg, EF1_MEM_MAP_4MB, 0 );
1108 EFAB_SET_DWORD_FIELD ( reg, EF1_EV_INTR_CLR_WRITE, 0 );
1109 EFAB_SET_DWORD_FIELD ( reg, EF1_BURST_MERGE, 0 );
1110 EFAB_SET_DWORD_FIELD ( reg, EF1_CLEAR_NULL_PAD, 1 );
1111 EFAB_SET_DWORD_FIELD ( reg, EF1_INTR_AFTER_EVENT, 1 );
1112 ef1002_writel ( efab, ®, EF1_CTL2_REG );
1116 ef1002_readl ( efab, ®, EF1_DMA_RX_CSR_REG );
1117 EFAB_SET_DWORD_FIELD ( reg, EF1_DMA_RX_CSR_ENABLE, 1 );
1118 EFAB_SET_DWORD_FIELD ( reg, EF1_DMA_RX_BELOW_1MB_EN, 1 );
1119 EFAB_SET_DWORD_FIELD ( reg, EF1_DMA_RX_ABOVE_1GB_EN, 1 );
1120 ef1002_writel ( efab, ®, EF1_DMA_RX_CSR_REG );
1124 ef1002_readl ( efab, ®, EF1_DMA_TX_CSR_REG );
1125 EFAB_SET_DWORD_FIELD ( reg, EF1_DMA_TX_CSR_CHAIN_EN, 1 );
1126 EFAB_SET_DWORD_FIELD ( reg, EF1_DMA_TX_CSR_ENABLE, 0 /* ?? */ );
1127 EFAB_SET_DWORD_FIELD ( reg, EF1_DMA_TX_CSR_INT_EN, 0 /* ?? */ );
1128 ef1002_writel ( efab, ®, EF1_DMA_TX_CSR_REG );
1131 /* Disconnect the JTAG chain. Read-modify-write is impossible
1132 * on the I2C control bits, since reading gives the state of
1133 * the line inputs rather than the last written state.
1135 ef1002_readl ( efab, ®, EF1_EEPROM_REG );
1136 EFAB_SET_DWORD_FIELD ( reg, EF1_EEPROM_SDA, 1 );
1137 EFAB_SET_DWORD_FIELD ( reg, EF1_EEPROM_SCL, 1 );
1138 EFAB_SET_DWORD_FIELD ( reg, EF1_JTAG_DISCONNECT, 1 );
1139 ef1002_writel ( efab, ®, EF1_EEPROM_REG );
1142 /* Flush descriptor queues */
1143 EFAB_ZERO_DWORD ( reg );
1144 ef1002_writel ( efab, ®, EF1_RX_DESC_FIFO_FLUSH );
1145 ef1002_writel ( efab, ®, EF1_TX_DESC_FIFO_FLUSH );
1150 mentormac_reset ( efab );
1152 /* Attach I2C bus */
1153 ef1002_init_eeprom ( efab );
1159 * Read MAC address from EEPROM
1162 static int ef1002_read_eeprom ( struct efab_nic *efab ) {
1163 struct i2c_interface *i2c = &efab->ef1002_i2c.i2c;
1164 struct i2c_device *i2cdev = &efab->ef1002_eeprom;
1166 return ( i2c->read ( i2c, i2cdev, EF1_EEPROM_HWADDR_OFFSET,
1167 efab->mac_addr, sizeof ( efab->mac_addr ) ) == 0);
1170 /** RX descriptor */
1171 typedef efab_qword_t ef1002_rx_desc_t;
1174 * Build RX descriptor
1177 static void ef1002_build_rx_desc ( struct efab_nic *efab,
1178 struct efab_rx_buf *rx_buf ) {
1179 ef1002_rx_desc_t rxd;
1181 EFAB_POPULATE_QWORD_3 ( rxd,
1183 EF1_RX_KER_IDX, rx_buf->id,
1185 virt_to_bus ( rx_buf->addr ) );
1186 ef1002_writel ( efab, &rxd.dword[0], EF1_RX_DESC_FIFO + 0 );
1187 ef1002_writel ( efab, &rxd.dword[1], EF1_RX_DESC_FIFO + 4 );
1192 * Update RX descriptor write pointer
1195 static void ef1002_notify_rx_desc ( struct efab_nic *efab __unused ) {
1199 /** TX descriptor */
1200 typedef efab_oword_t ef1002_tx_desc_t;
1203 * Build TX descriptor
1206 static void ef1002_build_tx_desc ( struct efab_nic *efab,
1207 struct efab_tx_buf *tx_buf ) {
1208 ef1002_tx_desc_t txd;
1210 EFAB_POPULATE_OWORD_7 ( txd,
1212 EF1_TX_KER_IDX, tx_buf->id,
1213 EF1_TX_KER_MODE, 0 /* IP mode */,
1214 EF1_TX_KER_PORT, efab->port,
1216 EF1_TX_KER_BYTE_CNT, tx_buf->len,
1218 virt_to_bus ( tx_buf->addr ) );
1220 ef1002_writel ( efab, &txd.dword[0], EF1_TX_DESC_FIFO + 0 );
1221 ef1002_writel ( efab, &txd.dword[1], EF1_TX_DESC_FIFO + 4 );
1222 ef1002_writel ( efab, &txd.dword[2], EF1_TX_DESC_FIFO + 8 );
1227 * Update TX descriptor write pointer
1230 static void ef1002_notify_tx_desc ( struct efab_nic *efab __unused ) {
1235 typedef efab_qword_t ef1002_event_t;
1238 * Retrieve event from event queue
1241 static int ef1002_fetch_event ( struct efab_nic *efab,
1242 struct efab_event *event ) {
1247 /* Check event FIFO depth */
1248 ef1002_readl_silent ( efab, ®, EF1_EVENT_FIFO_COUNT_REG );
1249 words = EFAB_DWORD_FIELD ( reg, EF1_EV_COUNT );
1253 /* Read event data */
1254 ef1002_readl ( efab, ®, EF1_EVENT_FIFO_REG );
1255 DBG ( "Event is " EFAB_DWORD_FMT "\n", EFAB_DWORD_VAL ( reg ) );
1258 ev_code = EFAB_DWORD_FIELD ( reg, EF1_EV_CODE );
1259 switch ( ev_code ) {
1260 case EF1_TX_EV_DECODE:
1261 event->type = EFAB_EV_TX;
1263 case EF1_RX_EV_DECODE:
1264 event->type = EFAB_EV_RX;
1265 event->rx_id = EFAB_DWORD_FIELD ( reg, EF1_RX_EV_IDX );
1266 /* RX len not available via event FIFO */
1267 event->rx_len = ETH_FRAME_LEN;
1270 printf ( "Unknown event type %d data %08lx\n", ev_code,
1271 EFAB_DWORD_FIELD ( reg, EFAB_DWORD_0 ) );
1272 event->type = EFAB_EV_NONE;
1275 /* Clear any pending interrupts */
1276 ef1002_readl ( efab, ®, EF1_IRQ_SRC_REG );
1282 * Enable/disable interrupts
1285 static void ef1002_mask_irq ( struct efab_nic *efab, int enabled ) {
1286 efab_dword_t irq_mask;
1288 EFAB_POPULATE_DWORD_2 ( irq_mask,
1289 EF1_IRQ_SERR, enabled,
1290 EF1_IRQ_EVQ, enabled );
1291 ef1002_writel ( efab, &irq_mask, EF1_IRQ_MASK_REG );
1295 * Generate interrupt
1298 static void ef1002_generate_irq ( struct efab_nic *efab ) {
1299 ef1002_event_t test_event;
1301 EFAB_POPULATE_QWORD_1 ( test_event,
1302 EF1_EV_CODE, EF1_DRV_GEN_EV_DECODE );
1303 ef1002_writel ( efab, &test_event.dword[0], EF1_EVT3_REG );
1307 * Write dword to an EF1002 MAC register
1310 static void ef1002_mac_writel ( struct efab_nic *efab,
1311 efab_dword_t *value, unsigned int mac_reg ) {
1312 ef1002_writel ( efab, value, EF1002_MAC_REG ( efab, mac_reg ) );
1316 * Read dword from an EF1002 MAC register
1319 static void ef1002_mac_readl ( struct efab_nic *efab,
1320 efab_dword_t *value, unsigned int mac_reg ) {
1321 ef1002_readl ( efab, value, EF1002_MAC_REG ( efab, mac_reg ) );
1328 static int ef1002_init_mac ( struct efab_nic *efab ) {
1329 static struct efab_mentormac_parameters ef1002_mentormac_params = {
1330 .gmf_cfgfrth = 0x13,
1331 .gmf_cfgftth = 0x10,
1332 .gmf_cfghwmft = 0x555,
1337 unsigned int mac_clk;
1339 /* Initialise PHY */
1340 alaska_init ( efab );
1342 /* Initialise MAC */
1343 mentormac_init ( efab, &ef1002_mentormac_params );
1345 /* Write Level 5 watermark register */
1346 EFAB_POPULATE_DWORD_1 ( reg, EF1_L5WM, 0x10040000 );
1347 efab->op->mac_writel ( efab, ®, EF1_GMF_L5WM_REG_MAC );
1350 /* Set MAC clock speed */
1351 ef1002_readl ( efab, ®, EF1_GM_MAC_CLK_REG );
1352 mac_clk = ( efab->link_options & LPA_1000 ) ? 0 : 1;
1353 if ( efab->port == 0 ) {
1354 EFAB_SET_DWORD_FIELD ( reg, EF1_GM_PORT0_MAC_CLK, mac_clk );
1356 EFAB_SET_DWORD_FIELD ( reg, EF1_GM_PORT1_MAC_CLK, mac_clk );
1358 ef1002_writel ( efab, ®, EF1_GM_MAC_CLK_REG );
1365 static void ef1002_mdio_write ( struct efab_nic *efab, int location,
1367 mentormac_mdio_write ( efab, efab->port + 2, location, value );
1371 static int ef1002_mdio_read ( struct efab_nic *efab, int location ) {
1372 return mentormac_mdio_read ( efab, efab->port + 2, location );
1375 static struct efab_operations ef1002_operations = {
1376 .get_membase = ef1002_get_membase,
1377 .reset = ef1002_reset,
1378 .init_nic = ef1002_init_nic,
1379 .read_eeprom = ef1002_read_eeprom,
1380 .build_rx_desc = ef1002_build_rx_desc,
1381 .notify_rx_desc = ef1002_notify_rx_desc,
1382 .build_tx_desc = ef1002_build_tx_desc,
1383 .notify_tx_desc = ef1002_notify_tx_desc,
1384 .fetch_event = ef1002_fetch_event,
1385 .mask_irq = ef1002_mask_irq,
1386 .generate_irq = ef1002_generate_irq,
1387 .mac_writel = ef1002_mac_writel,
1388 .mac_readl = ef1002_mac_readl,
1389 .init_mac = ef1002_init_mac,
1390 .mdio_write = ef1002_mdio_write,
1391 .mdio_read = ef1002_mdio_read,
1394 /**************************************************************************
1398 **************************************************************************
1401 /* I/O BAR address register */
1402 #define FCN_IOM_IND_ADR_REG 0x0
1404 /* I/O BAR data register */
1405 #define FCN_IOM_IND_DAT_REG 0x4
1407 /* Interrupt enable register */
1408 #define FCN_INT_EN_REG_KER 0x0010
1409 #define FCN_MEM_PERR_INT_EN_KER_LBN 5
1410 #define FCN_MEM_PERR_INT_EN_KER_WIDTH 1
1411 #define FCN_KER_INT_CHAR_LBN 4
1412 #define FCN_KER_INT_CHAR_WIDTH 1
1413 #define FCN_KER_INT_KER_LBN 3
1414 #define FCN_KER_INT_KER_WIDTH 1
1415 #define FCN_ILL_ADR_ERR_INT_EN_KER_LBN 2
1416 #define FCN_ILL_ADR_ERR_INT_EN_KER_WIDTH 1
1417 #define FCN_SRM_PERR_INT_EN_KER_LBN 1
1418 #define FCN_SRM_PERR_INT_EN_KER_WIDTH 1
1419 #define FCN_DRV_INT_EN_KER_LBN 0
1420 #define FCN_DRV_INT_EN_KER_WIDTH 1
1422 /* Interrupt status register */
1423 #define FCN_INT_ADR_REG_KER 0x0030
1424 #define FCN_INT_ADR_KER_LBN 0
1425 #define FCN_INT_ADR_KER_WIDTH EFAB_DMA_TYPE_WIDTH ( 64 )
1427 /* Interrupt acknowledge register */
1428 #define FCN_INT_ACK_KER_REG 0x0050
1430 /* SPI host command register */
1431 #define FCN_EE_SPI_HCMD_REG_KER 0x0100
1432 #define FCN_EE_SPI_HCMD_CMD_EN_LBN 31
1433 #define FCN_EE_SPI_HCMD_CMD_EN_WIDTH 1
1434 #define FCN_EE_WR_TIMER_ACTIVE_LBN 28
1435 #define FCN_EE_WR_TIMER_ACTIVE_WIDTH 1
1436 #define FCN_EE_SPI_HCMD_SF_SEL_LBN 24
1437 #define FCN_EE_SPI_HCMD_SF_SEL_WIDTH 1
1438 #define FCN_EE_SPI_EEPROM 0
1439 #define FCN_EE_SPI_FLASH 1
1440 #define FCN_EE_SPI_HCMD_DABCNT_LBN 16
1441 #define FCN_EE_SPI_HCMD_DABCNT_WIDTH 5
1442 #define FCN_EE_SPI_HCMD_READ_LBN 15
1443 #define FCN_EE_SPI_HCMD_READ_WIDTH 1
1444 #define FCN_EE_SPI_READ 1
1445 #define FCN_EE_SPI_WRITE 0
1446 #define FCN_EE_SPI_HCMD_DUBCNT_LBN 12
1447 #define FCN_EE_SPI_HCMD_DUBCNT_WIDTH 2
1448 #define FCN_EE_SPI_HCMD_ADBCNT_LBN 8
1449 #define FCN_EE_SPI_HCMD_ADBCNT_WIDTH 2
1450 #define FCN_EE_SPI_HCMD_ENC_LBN 0
1451 #define FCN_EE_SPI_HCMD_ENC_WIDTH 8
1453 /* SPI host address register */
1454 #define FCN_EE_SPI_HADR_REG_KER 0x0110
1455 #define FCN_EE_SPI_HADR_DUBYTE_LBN 24
1456 #define FCN_EE_SPI_HADR_DUBYTE_WIDTH 8
1457 #define FCN_EE_SPI_HADR_ADR_LBN 0
1458 #define FCN_EE_SPI_HADR_ADR_WIDTH 24
1460 /* SPI host data register */
1461 #define FCN_EE_SPI_HDATA_REG_KER 0x0120
1462 #define FCN_EE_SPI_HDATA3_LBN 96
1463 #define FCN_EE_SPI_HDATA3_WIDTH 32
1464 #define FCN_EE_SPI_HDATA2_LBN 64
1465 #define FCN_EE_SPI_HDATA2_WIDTH 32
1466 #define FCN_EE_SPI_HDATA1_LBN 32
1467 #define FCN_EE_SPI_HDATA1_WIDTH 32
1468 #define FCN_EE_SPI_HDATA0_LBN 0
1469 #define FCN_EE_SPI_HDATA0_WIDTH 32
1471 /* GPIO control register */
1472 #define FCN_GPIO_CTL_REG_KER 0x0210
1473 #define FCN_FLASH_PRESENT_LBN 7
1474 #define FCN_FLASH_PRESENT_WIDTH 1
1475 #define FCN_EEPROM_PRESENT_LBN 6
1476 #define FCN_EEPROM_PRESENT_WIDTH 1
1478 /* Global control register */
1479 #define FCN_GLB_CTL_REG_KER 0x0220
1480 #define FCN_EXT_PHY_RST_CTL_LBN 63
1481 #define FCN_EXT_PHY_RST_CTL_WIDTH 1
1482 #define FCN_PCIE_SD_RST_CTL_LBN 61
1483 #define FCN_PCIE_SD_RST_CTL_WIDTH 1
1484 #define FCN_PCIX_RST_CTL_LBN 60
1485 #define FCN_PCIX_RST_CTL_WIDTH 1
1486 #define FCN_RST_EXT_PHY_LBN 31
1487 #define FCN_RST_EXT_PHY_WIDTH 1
1488 #define FCN_INT_RST_DUR_LBN 4
1489 #define FCN_INT_RST_DUR_WIDTH 3
1490 #define FCN_EXT_PHY_RST_DUR_LBN 1
1491 #define FCN_EXT_PHY_RST_DUR_WIDTH 3
1492 #define FCN_SWRST_LBN 0
1493 #define FCN_SWRST_WIDTH 1
1494 #define FCN_INCLUDE_IN_RESET 0
1495 #define FCN_EXCLUDE_FROM_RESET 1
1497 /* Timer table for kernel access */
1498 #define FCN_TIMER_CMD_REG_KER 0x420
1499 #define FCN_TIMER_MODE_LBN 12
1500 #define FCN_TIMER_MODE_WIDTH 2
1501 #define FCN_TIMER_MODE_DIS 0
1502 #define FCN_TIMER_MODE_INT_HLDOFF 1
1503 #define FCN_TIMER_VAL_LBN 0
1504 #define FCN_TIMER_VAL_WIDTH 12
1506 /* SRAM receive descriptor cache configuration register */
1507 #define FCN_SRM_RX_DC_CFG_REG_KER 0x610
1508 #define FCN_SRM_RX_DC_BASE_ADR_LBN 0
1509 #define FCN_SRM_RX_DC_BASE_ADR_WIDTH 21
1511 /* SRAM transmit descriptor cache configuration register */
1512 #define FCN_SRM_TX_DC_CFG_REG_KER 0x620
1513 #define FCN_SRM_TX_DC_BASE_ADR_LBN 0
1514 #define FCN_SRM_TX_DC_BASE_ADR_WIDTH 21
1516 /* Receive filter control register */
1517 #define FCN_RX_FILTER_CTL_REG_KER 0x810
1518 #define FCN_NUM_KER_LBN 24
1519 #define FCN_NUM_KER_WIDTH 2
1521 /* Receive descriptor update register */
1522 #define FCN_RX_DESC_UPD_REG_KER 0x0830
1523 #define FCN_RX_DESC_WPTR_LBN 96
1524 #define FCN_RX_DESC_WPTR_WIDTH 12
1525 #define FCN_RX_DESC_UPD_REG_KER_DWORD ( FCN_RX_DESC_UPD_REG_KER + 12 )
1526 #define FCN_RX_DESC_WPTR_DWORD_LBN 0
1527 #define FCN_RX_DESC_WPTR_DWORD_WIDTH 12
1529 /* Receive descriptor cache configuration register */
1530 #define FCN_RX_DC_CFG_REG_KER 0x840
1531 #define FCN_RX_DC_SIZE_LBN 0
1532 #define FCN_RX_DC_SIZE_WIDTH 2
1534 /* Transmit descriptor update register */
1535 #define FCN_TX_DESC_UPD_REG_KER 0x0a10
1536 #define FCN_TX_DESC_WPTR_LBN 96
1537 #define FCN_TX_DESC_WPTR_WIDTH 12
1538 #define FCN_TX_DESC_UPD_REG_KER_DWORD ( FCN_TX_DESC_UPD_REG_KER + 12 )
1539 #define FCN_TX_DESC_WPTR_DWORD_LBN 0
1540 #define FCN_TX_DESC_WPTR_DWORD_WIDTH 12
1542 /* Transmit descriptor cache configuration register */
1543 #define FCN_TX_DC_CFG_REG_KER 0xa20
1544 #define FCN_TX_DC_SIZE_LBN 0
1545 #define FCN_TX_DC_SIZE_WIDTH 2
1547 /* PHY management transmit data register */
1548 #define FCN_MD_TXD_REG_KER 0xc00
1549 #define FCN_MD_TXD_LBN 0
1550 #define FCN_MD_TXD_WIDTH 16
1552 /* PHY management receive data register */
1553 #define FCN_MD_RXD_REG_KER 0xc10
1554 #define FCN_MD_RXD_LBN 0
1555 #define FCN_MD_RXD_WIDTH 16
1557 /* PHY management configuration & status register */
1558 #define FCN_MD_CS_REG_KER 0xc20
1559 #define FCN_MD_GC_LBN 4
1560 #define FCN_MD_GC_WIDTH 1
1561 #define FCN_MD_RIC_LBN 2
1562 #define FCN_MD_RIC_WIDTH 1
1563 #define FCN_MD_WRC_LBN 0
1564 #define FCN_MD_WRC_WIDTH 1
1566 /* PHY management PHY address register */
1567 #define FCN_MD_PHY_ADR_REG_KER 0xc30
1568 #define FCN_MD_PHY_ADR_LBN 0
1569 #define FCN_MD_PHY_ADR_WIDTH 16
1571 /* PHY management ID register */
1572 #define FCN_MD_ID_REG_KER 0xc40
1573 #define FCN_MD_PRT_ADR_LBN 11
1574 #define FCN_MD_PRT_ADR_WIDTH 5
1575 #define FCN_MD_DEV_ADR_LBN 6
1576 #define FCN_MD_DEV_ADR_WIDTH 5
1578 /* PHY management status & mask register */
1579 #define FCN_MD_STAT_REG_KER 0xc50
1580 #define FCN_MD_BSY_LBN 0
1581 #define FCN_MD_BSY_WIDTH 1
1583 /* Port 0 and 1 MAC control registers */
1584 #define FCN_MAC0_CTRL_REG_KER 0xc80
1585 #define FCN_MAC1_CTRL_REG_KER 0xc90
1586 #define FCN_MAC_XOFF_VAL_LBN 16
1587 #define FCN_MAC_XOFF_VAL_WIDTH 16
1588 #define FCN_MAC_BCAD_ACPT_LBN 4
1589 #define FCN_MAC_BCAD_ACPT_WIDTH 1
1590 #define FCN_MAC_UC_PROM_LBN 3
1591 #define FCN_MAC_UC_PROM_WIDTH 1
1592 #define FCN_MAC_LINK_STATUS_LBN 2
1593 #define FCN_MAC_LINK_STATUS_WIDTH 1
1594 #define FCN_MAC_SPEED_LBN 0
1595 #define FCN_MAC_SPEED_WIDTH 2
1597 /* XGMAC global configuration - port 0*/
1598 #define FCN_XM_GLB_CFG_REG_P0_KER 0x1220
1599 #define FCN_XM_RX_STAT_EN_LBN 11
1600 #define FCN_XM_RX_STAT_EN_WIDTH 1
1601 #define FCN_XM_TX_STAT_EN_LBN 10
1602 #define FCN_XM_TX_STAT_EN_WIDTH 1
1603 #define FCN_XM_CUT_THRU_MODE_LBN 7
1604 #define FCN_XM_CUT_THRU_MODE_WIDTH 1
1605 #define FCN_XM_RX_JUMBO_MODE_LBN 6
1606 #define FCN_XM_RX_JUMBO_MODE_WIDTH 1
1608 /* XGMAC transmit configuration - port 0 */
1609 #define FCN_XM_TX_CFG_REG_P0_KER 0x1230
1610 #define FCN_XM_IPG_LBN 16
1611 #define FCN_XM_IPG_WIDTH 4
1612 #define FCN_XM_WTF_DOES_THIS_DO_LBN 9
1613 #define FCN_XM_WTF_DOES_THIS_DO_WIDTH 1
1614 #define FCN_XM_TXCRC_LBN 8
1615 #define FCN_XM_TXCRC_WIDTH 1
1616 #define FCN_XM_AUTO_PAD_LBN 5
1617 #define FCN_XM_AUTO_PAD_WIDTH 1
1618 #define FCN_XM_TX_PRMBL_LBN 2
1619 #define FCN_XM_TX_PRMBL_WIDTH 1
1620 #define FCN_XM_TXEN_LBN 1
1621 #define FCN_XM_TXEN_WIDTH 1
1623 /* XGMAC receive configuration - port 0 */
1624 #define FCN_XM_RX_CFG_REG_P0_KER 0x1240
1625 #define FCN_XM_PASS_CRC_ERR_LBN 25
1626 #define FCN_XM_PASS_CRC_ERR_WIDTH 1
1627 #define FCN_XM_AUTO_DEPAD_LBN 8
1628 #define FCN_XM_AUTO_DEPAD_WIDTH 1
1629 #define FCN_XM_RXEN_LBN 1
1630 #define FCN_XM_RXEN_WIDTH 1
1632 /* Receive descriptor pointer table */
1633 #define FCN_RX_DESC_PTR_TBL_KER 0x11800
1634 #define FCN_RX_DESCQ_BUF_BASE_ID_LBN 36
1635 #define FCN_RX_DESCQ_BUF_BASE_ID_WIDTH 20
1636 #define FCN_RX_DESCQ_EVQ_ID_LBN 24
1637 #define FCN_RX_DESCQ_EVQ_ID_WIDTH 12
1638 #define FCN_RX_DESCQ_OWNER_ID_LBN 10
1639 #define FCN_RX_DESCQ_OWNER_ID_WIDTH 14
1640 #define FCN_RX_DESCQ_SIZE_LBN 3
1641 #define FCN_RX_DESCQ_SIZE_WIDTH 2
1642 #define FCN_RX_DESCQ_SIZE_4K 3
1643 #define FCN_RX_DESCQ_SIZE_2K 2
1644 #define FCN_RX_DESCQ_SIZE_1K 1
1645 #define FCN_RX_DESCQ_SIZE_512 0
1646 #define FCN_RX_DESCQ_TYPE_LBN 2
1647 #define FCN_RX_DESCQ_TYPE_WIDTH 1
1648 #define FCN_RX_DESCQ_JUMBO_LBN 1
1649 #define FCN_RX_DESCQ_JUMBO_WIDTH 1
1650 #define FCN_RX_DESCQ_EN_LBN 0
1651 #define FCN_RX_DESCQ_EN_WIDTH 1
1653 /* Transmit descriptor pointer table */
1654 #define FCN_TX_DESC_PTR_TBL_KER 0x11900
1655 #define FCN_TX_DESCQ_EN_LBN 88
1656 #define FCN_TX_DESCQ_EN_WIDTH 1
1657 #define FCN_TX_DESCQ_BUF_BASE_ID_LBN 36
1658 #define FCN_TX_DESCQ_BUF_BASE_ID_WIDTH 20
1659 #define FCN_TX_DESCQ_EVQ_ID_LBN 24
1660 #define FCN_TX_DESCQ_EVQ_ID_WIDTH 12
1661 #define FCN_TX_DESCQ_OWNER_ID_LBN 10
1662 #define FCN_TX_DESCQ_OWNER_ID_WIDTH 14
1663 #define FCN_TX_DESCQ_SIZE_LBN 3
1664 #define FCN_TX_DESCQ_SIZE_WIDTH 2
1665 #define FCN_TX_DESCQ_SIZE_4K 3
1666 #define FCN_TX_DESCQ_SIZE_2K 2
1667 #define FCN_TX_DESCQ_SIZE_1K 1
1668 #define FCN_TX_DESCQ_SIZE_512 0
1669 #define FCN_TX_DESCQ_TYPE_LBN 1
1670 #define FCN_TX_DESCQ_TYPE_WIDTH 2
1671 #define FCN_TX_DESCQ_FLUSH_LBN 0
1672 #define FCN_TX_DESCQ_FLUSH_WIDTH 1
1674 /* Event queue pointer */
1675 #define FCN_EVQ_PTR_TBL_KER 0x11a00
1676 #define FCN_EVQ_EN_LBN 23
1677 #define FCN_EVQ_EN_WIDTH 1
1678 #define FCN_EVQ_SIZE_LBN 20
1679 #define FCN_EVQ_SIZE_WIDTH 3
1680 #define FCN_EVQ_SIZE_32K 6
1681 #define FCN_EVQ_SIZE_16K 5
1682 #define FCN_EVQ_SIZE_8K 4
1683 #define FCN_EVQ_SIZE_4K 3
1684 #define FCN_EVQ_SIZE_2K 2
1685 #define FCN_EVQ_SIZE_1K 1
1686 #define FCN_EVQ_SIZE_512 0
1687 #define FCN_EVQ_BUF_BASE_ID_LBN 0
1688 #define FCN_EVQ_BUF_BASE_ID_WIDTH 20
1690 /* Event queue read pointer */
1691 #define FCN_EVQ_RPTR_REG_KER 0x11b00
1692 #define FCN_EVQ_RPTR_LBN 0
1693 #define FCN_EVQ_RPTR_WIDTH 14
1694 #define FCN_EVQ_RPTR_REG_KER_DWORD ( FCN_EVQ_RPTR_REG_KER + 0 )
1695 #define FCN_EVQ_RPTR_DWORD_LBN 0
1696 #define FCN_EVQ_RPTR_DWORD_WIDTH 14
1698 /* Special buffer descriptors */
1699 #define FCN_BUF_FULL_TBL_KER 0x18000
1700 #define FCN_IP_DAT_BUF_SIZE_LBN 50
1701 #define FCN_IP_DAT_BUF_SIZE_WIDTH 1
1702 #define FCN_IP_DAT_BUF_SIZE_8K 1
1703 #define FCN_IP_DAT_BUF_SIZE_4K 0
1704 #define FCN_BUF_ADR_FBUF_LBN 14
1705 #define FCN_BUF_ADR_FBUF_WIDTH 34
1706 #define FCN_BUF_OWNER_ID_FBUF_LBN 0
1707 #define FCN_BUF_OWNER_ID_FBUF_WIDTH 14
1710 #define FALCON_MAC_REGBANK 0xe00
1711 #define FALCON_MAC_REGBANK_SIZE 0x200
1712 #define FALCON_MAC_REG_SIZE 0x10
1714 /** Offset of a MAC register within Falcon */
1715 #define FALCON_MAC_REG( efab, mac_reg ) \
1716 ( FALCON_MAC_REGBANK + \
1717 ( (efab)->port * FALCON_MAC_REGBANK_SIZE ) + \
1718 ( (mac_reg) * FALCON_MAC_REG_SIZE ) )
1719 #define FCN_MAC_DATA_LBN 0
1720 #define FCN_MAC_DATA_WIDTH 32
1722 /* Transmit descriptor */
1723 #define FCN_TX_KER_PORT_LBN 63
1724 #define FCN_TX_KER_PORT_WIDTH 1
1725 #define FCN_TX_KER_BYTE_CNT_LBN 48
1726 #define FCN_TX_KER_BYTE_CNT_WIDTH 14
1727 #define FCN_TX_KER_BUF_ADR_LBN 0
1728 #define FCN_TX_KER_BUF_ADR_WIDTH EFAB_DMA_TYPE_WIDTH ( 46 )
1730 /* Receive descriptor */
1731 #define FCN_RX_KER_BUF_SIZE_LBN 48
1732 #define FCN_RX_KER_BUF_SIZE_WIDTH 14
1733 #define FCN_RX_KER_BUF_ADR_LBN 0
1734 #define FCN_RX_KER_BUF_ADR_WIDTH EFAB_DMA_TYPE_WIDTH ( 46 )
1736 /* Event queue entries */
1737 #define FCN_EV_CODE_LBN 60
1738 #define FCN_EV_CODE_WIDTH 4
1739 #define FCN_RX_IP_EV_DECODE 0
1740 #define FCN_TX_IP_EV_DECODE 2
1741 #define FCN_DRIVER_EV_DECODE 5
1743 /* Receive events */
1744 #define FCN_RX_PORT_LBN 30
1745 #define FCN_RX_PORT_WIDTH 1
1746 #define FCN_RX_EV_BYTE_CNT_LBN 16
1747 #define FCN_RX_EV_BYTE_CNT_WIDTH 14
1748 #define FCN_RX_EV_DESC_PTR_LBN 0
1749 #define FCN_RX_EV_DESC_PTR_WIDTH 12
1751 /* Transmit events */
1752 #define FCN_TX_EV_DESC_PTR_LBN 0
1753 #define FCN_TX_EV_DESC_PTR_WIDTH 12
1755 /* Fixed special buffer numbers to use */
1756 #define FALCON_EVQ_ID 0
1757 #define FALCON_TXD_ID 1
1758 #define FALCON_RXD_ID 2
1760 #if FALCON_USE_IO_BAR
1762 /* Write dword via the I/O BAR */
1763 static inline void _falcon_writel ( struct efab_nic *efab, uint32_t value,
1764 unsigned int reg ) {
1765 outl ( reg, efab->iobase + FCN_IOM_IND_ADR_REG );
1766 outl ( value, efab->iobase + FCN_IOM_IND_DAT_REG );
1769 /* Read dword via the I/O BAR */
1770 static inline uint32_t _falcon_readl ( struct efab_nic *efab,
1771 unsigned int reg ) {
1772 outl ( reg, efab->iobase + FCN_IOM_IND_ADR_REG );
1773 return inl ( efab->iobase + FCN_IOM_IND_DAT_REG );
1776 #else /* FALCON_USE_IO_BAR */
1778 #define _falcon_writel( efab, value, reg ) \
1779 writel ( (value), (efab)->membase + (reg) )
1780 #define _falcon_readl( efab, reg ) readl ( (efab)->membase + (reg) )
1782 #endif /* FALCON_USE_IO_BAR */
1785 * Write to a Falcon register
1788 static inline void falcon_write ( struct efab_nic *efab, efab_oword_t *value,
1789 unsigned int reg ) {
1791 EFAB_REGDUMP ( "Writing register %x with " EFAB_OWORD_FMT "\n",
1792 reg, EFAB_OWORD_VAL ( *value ) );
1794 _falcon_writel ( efab, value->u32[0], reg + 0 );
1795 _falcon_writel ( efab, value->u32[1], reg + 4 );
1796 _falcon_writel ( efab, value->u32[2], reg + 8 );
1797 _falcon_writel ( efab, value->u32[3], reg + 12 );
1802 * Write to Falcon SRAM
1805 static inline void falcon_write_sram ( struct efab_nic *efab,
1806 efab_qword_t *value,
1807 unsigned int index ) {
1808 unsigned int reg = ( FCN_BUF_FULL_TBL_KER +
1809 ( index * sizeof ( *value ) ) );
1811 EFAB_REGDUMP ( "Writing SRAM register %x with " EFAB_QWORD_FMT "\n",
1812 reg, EFAB_QWORD_VAL ( *value ) );
1814 _falcon_writel ( efab, value->u32[0], reg + 0 );
1815 _falcon_writel ( efab, value->u32[1], reg + 4 );
1820 * Write dword to Falcon register that allows partial writes
1823 static inline void falcon_writel ( struct efab_nic *efab, efab_dword_t *value,
1824 unsigned int reg ) {
1825 EFAB_REGDUMP ( "Writing partial register %x with " EFAB_DWORD_FMT "\n",
1826 reg, EFAB_DWORD_VAL ( *value ) );
1827 _falcon_writel ( efab, value->u32[0], reg );
1831 * Read from a Falcon register
1834 static inline void falcon_read ( struct efab_nic *efab, efab_oword_t *value,
1835 unsigned int reg ) {
1836 value->u32[0] = _falcon_readl ( efab, reg + 0 );
1837 value->u32[1] = _falcon_readl ( efab, reg + 4 );
1838 value->u32[2] = _falcon_readl ( efab, reg + 8 );
1839 value->u32[3] = _falcon_readl ( efab, reg + 12 );
1841 EFAB_REGDUMP ( "Read from register %x, got " EFAB_OWORD_FMT "\n",
1842 reg, EFAB_OWORD_VAL ( *value ) );
1846 * Read from Falcon SRAM
1849 static inline void falcon_read_sram ( struct efab_nic *efab,
1850 efab_qword_t *value,
1851 unsigned int index ) {
1852 unsigned int reg = ( FCN_BUF_FULL_TBL_KER +
1853 ( index * sizeof ( *value ) ) );
1855 value->u32[0] = _falcon_readl ( efab, reg + 0 );
1856 value->u32[1] = _falcon_readl ( efab, reg + 4 );
1857 EFAB_REGDUMP ( "Read from SRAM register %x, got " EFAB_QWORD_FMT "\n",
1858 reg, EFAB_QWORD_VAL ( *value ) );
1862 * Read dword from a portion of a Falcon register
1865 static inline void falcon_readl ( struct efab_nic *efab, efab_dword_t *value,
1866 unsigned int reg ) {
1867 value->u32[0] = _falcon_readl ( efab, reg );
1868 EFAB_REGDUMP ( "Read from register %x, got " EFAB_DWORD_FMT "\n",
1869 reg, EFAB_DWORD_VAL ( *value ) );
1873 * Verified write to Falcon SRAM
1876 static inline void falcon_write_sram_verify ( struct efab_nic *efab,
1877 efab_qword_t *value,
1878 unsigned int index ) {
1879 efab_qword_t verify;
1881 falcon_write_sram ( efab, value, index );
1883 falcon_read_sram ( efab, &verify, index );
1884 if ( memcmp ( &verify, value, sizeof ( verify ) ) != 0 ) {
1885 printf ( "SRAM index %x failure: wrote " EFAB_QWORD_FMT
1886 " got " EFAB_QWORD_FMT "\n", index,
1887 EFAB_QWORD_VAL ( *value ),
1888 EFAB_QWORD_VAL ( verify ) );
1896 static void falcon_get_membase ( struct efab_nic *efab ) {
1897 unsigned long membase_phys;
1899 membase_phys = pci_bar_start ( efab->pci, PCI_BASE_ADDRESS_2 );
1900 efab->membase = ioremap ( membase_phys, 0x20000 );
1903 #define FCN_DUMP_REG( efab, _reg ) do { \
1905 falcon_read ( efab, ®, _reg ); \
1906 printf ( #_reg " = " EFAB_OWORD_FMT "\n", \
1907 EFAB_OWORD_VAL ( reg ) ); \
1910 #define FCN_DUMP_MAC_REG( efab, _mac_reg ) do { \
1912 efab->op->mac_readl ( efab, ®, _mac_reg ); \
1913 printf ( #_mac_reg " = " EFAB_DWORD_FMT "\n", \
1914 EFAB_DWORD_VAL ( reg ) ); \
1918 * Dump register contents (for debugging)
1920 * Marked as static inline so that it will not be compiled in if not
1923 static inline void falcon_dump_regs ( struct efab_nic *efab ) {
1924 FCN_DUMP_REG ( efab, FCN_INT_EN_REG_KER );
1925 FCN_DUMP_REG ( efab, FCN_INT_ADR_REG_KER );
1926 FCN_DUMP_REG ( efab, FCN_GLB_CTL_REG_KER );
1927 FCN_DUMP_REG ( efab, FCN_TIMER_CMD_REG_KER );
1928 FCN_DUMP_REG ( efab, FCN_SRM_RX_DC_CFG_REG_KER );
1929 FCN_DUMP_REG ( efab, FCN_SRM_TX_DC_CFG_REG_KER );
1930 FCN_DUMP_REG ( efab, FCN_RX_FILTER_CTL_REG_KER );
1931 FCN_DUMP_REG ( efab, FCN_RX_DC_CFG_REG_KER );
1932 FCN_DUMP_REG ( efab, FCN_TX_DC_CFG_REG_KER );
1933 FCN_DUMP_REG ( efab, FCN_MAC0_CTRL_REG_KER );
1934 FCN_DUMP_REG ( efab, FCN_MAC1_CTRL_REG_KER );
1935 FCN_DUMP_REG ( efab, FCN_XM_GLB_CFG_REG_P0_KER );
1936 FCN_DUMP_REG ( efab, FCN_XM_TX_CFG_REG_P0_KER );
1937 FCN_DUMP_REG ( efab, FCN_XM_RX_CFG_REG_P0_KER );
1938 FCN_DUMP_REG ( efab, FCN_RX_DESC_PTR_TBL_KER );
1939 FCN_DUMP_REG ( efab, FCN_TX_DESC_PTR_TBL_KER );
1940 FCN_DUMP_REG ( efab, FCN_EVQ_PTR_TBL_KER );
1941 FCN_DUMP_MAC_REG ( efab, GM_CFG1_REG_MAC );
1942 FCN_DUMP_MAC_REG ( efab, GM_CFG2_REG_MAC );
1943 FCN_DUMP_MAC_REG ( efab, GM_MAX_FLEN_REG_MAC );
1944 FCN_DUMP_MAC_REG ( efab, GM_MII_MGMT_CFG_REG_MAC );
1945 FCN_DUMP_MAC_REG ( efab, GM_ADR1_REG_MAC );
1946 FCN_DUMP_MAC_REG ( efab, GM_ADR2_REG_MAC );
1947 FCN_DUMP_MAC_REG ( efab, GMF_CFG0_REG_MAC );
1948 FCN_DUMP_MAC_REG ( efab, GMF_CFG1_REG_MAC );
1949 FCN_DUMP_MAC_REG ( efab, GMF_CFG2_REG_MAC );
1950 FCN_DUMP_MAC_REG ( efab, GMF_CFG3_REG_MAC );
1951 FCN_DUMP_MAC_REG ( efab, GMF_CFG4_REG_MAC );
1952 FCN_DUMP_MAC_REG ( efab, GMF_CFG5_REG_MAC );
1956 * Create special buffer
1959 static void falcon_create_special_buffer ( struct efab_nic *efab,
1960 void *addr, unsigned int index ) {
1961 efab_qword_t buf_desc;
1962 unsigned long dma_addr;
1964 memset ( addr, 0, 4096 );
1965 dma_addr = virt_to_bus ( addr );
1966 EFAB_ASSERT ( ( dma_addr & ( EFAB_BUF_ALIGN - 1 ) ) == 0 );
1967 EFAB_POPULATE_QWORD_3 ( buf_desc,
1968 FCN_IP_DAT_BUF_SIZE, FCN_IP_DAT_BUF_SIZE_4K,
1969 FCN_BUF_ADR_FBUF, ( dma_addr >> 12 ),
1970 FCN_BUF_OWNER_ID_FBUF, 0 );
1971 falcon_write_sram_verify ( efab, &buf_desc, index );
1975 * Update event queue read pointer
1978 static void falcon_eventq_read_ack ( struct efab_nic *efab ) {
1981 EFAB_ASSERT ( efab->eventq_read_ptr < EFAB_EVQ_SIZE );
1983 EFAB_POPULATE_DWORD_1 ( reg, FCN_EVQ_RPTR_DWORD,
1984 efab->eventq_read_ptr );
1985 falcon_writel ( efab, ®, FCN_EVQ_RPTR_REG_KER_DWORD );
1992 static int falcon_reset ( struct efab_nic *efab ) {
1993 efab_oword_t glb_ctl_reg_ker;
1995 /* Initiate software reset */
1996 EFAB_POPULATE_OWORD_5 ( glb_ctl_reg_ker,
1997 FCN_EXT_PHY_RST_CTL, FCN_EXCLUDE_FROM_RESET,
1998 FCN_PCIE_SD_RST_CTL, FCN_EXCLUDE_FROM_RESET,
1999 FCN_PCIX_RST_CTL, FCN_EXCLUDE_FROM_RESET,
2000 FCN_INT_RST_DUR, 0x7 /* datasheet */,
2002 falcon_write ( efab, &glb_ctl_reg_ker, FCN_GLB_CTL_REG_KER );
2004 /* Allow 20ms for reset */
2007 /* Check for device reset complete */
2008 falcon_read ( efab, &glb_ctl_reg_ker, FCN_GLB_CTL_REG_KER );
2009 if ( EFAB_OWORD_FIELD ( glb_ctl_reg_ker, FCN_SWRST ) != 0 ) {
2010 printf ( "Reset failed\n" );
2021 static int falcon_init_nic ( struct efab_nic *efab ) {
2023 efab_dword_t timer_cmd;
2025 /* Set up TX and RX descriptor caches in SRAM */
2026 EFAB_POPULATE_OWORD_1 ( reg, FCN_SRM_TX_DC_BASE_ADR,
2027 0x130000 /* recommended in datasheet */ );
2028 falcon_write ( efab, ®, FCN_SRM_TX_DC_CFG_REG_KER );
2029 EFAB_POPULATE_OWORD_1 ( reg, FCN_TX_DC_SIZE, 2 /* 32 descriptors */ );
2030 falcon_write ( efab, ®, FCN_TX_DC_CFG_REG_KER );
2031 EFAB_POPULATE_OWORD_1 ( reg, FCN_SRM_RX_DC_BASE_ADR,
2032 0x100000 /* recommended in datasheet */ );
2033 falcon_write ( efab, ®, FCN_SRM_RX_DC_CFG_REG_KER );
2034 EFAB_POPULATE_OWORD_1 ( reg, FCN_RX_DC_SIZE, 2 /* 32 descriptors */ );
2035 falcon_write ( efab, ®, FCN_RX_DC_CFG_REG_KER );
2037 /* Set number of RSS CPUs */
2038 EFAB_POPULATE_OWORD_1 ( reg, FCN_NUM_KER, 0 );
2039 falcon_write ( efab, ®, FCN_RX_FILTER_CTL_REG_KER );
2043 mentormac_reset ( efab );
2045 /* Set up event queue */
2046 falcon_create_special_buffer ( efab, efab->eventq, FALCON_EVQ_ID );
2047 EFAB_POPULATE_OWORD_3 ( reg,
2049 FCN_EVQ_SIZE, FCN_EVQ_SIZE_512,
2050 FCN_EVQ_BUF_BASE_ID, FALCON_EVQ_ID );
2051 falcon_write ( efab, ®, FCN_EVQ_PTR_TBL_KER );
2054 /* Set timer register */
2055 EFAB_POPULATE_DWORD_2 ( timer_cmd,
2056 FCN_TIMER_MODE, FCN_TIMER_MODE_DIS,
2058 falcon_writel ( efab, &timer_cmd, FCN_TIMER_CMD_REG_KER );
2061 /* Initialise event queue read pointer */
2062 falcon_eventq_read_ack ( efab );
2064 /* Set up TX descriptor ring */
2065 falcon_create_special_buffer ( efab, efab->txd, FALCON_TXD_ID );
2066 EFAB_POPULATE_OWORD_5 ( reg,
2068 FCN_TX_DESCQ_BUF_BASE_ID, FALCON_TXD_ID,
2069 FCN_TX_DESCQ_EVQ_ID, 0,
2070 FCN_TX_DESCQ_SIZE, FCN_TX_DESCQ_SIZE_512,
2071 FCN_TX_DESCQ_TYPE, 0 /* kernel queue */ );
2072 falcon_write ( efab, ®, FCN_TX_DESC_PTR_TBL_KER );
2074 /* Set up RX descriptor ring */
2075 falcon_create_special_buffer ( efab, efab->rxd, FALCON_RXD_ID );
2076 EFAB_POPULATE_OWORD_6 ( reg,
2077 FCN_RX_DESCQ_BUF_BASE_ID, FALCON_RXD_ID,
2078 FCN_RX_DESCQ_EVQ_ID, 0,
2079 FCN_RX_DESCQ_SIZE, FCN_RX_DESCQ_SIZE_512,
2080 FCN_RX_DESCQ_TYPE, 0 /* kernel queue */,
2081 FCN_RX_DESCQ_JUMBO, 1,
2082 FCN_RX_DESCQ_EN, 1 );
2083 falcon_write ( efab, ®, FCN_RX_DESC_PTR_TBL_KER );
2085 /* Program INT_ADR_REG_KER */
2086 EFAB_POPULATE_OWORD_1 ( reg,
2088 virt_to_bus ( &efab->int_ker ) );
2089 falcon_write ( efab, ®, FCN_INT_ADR_REG_KER );
2096 struct efab_spi_device {
2098 unsigned int device_id;
2099 /** Address length (in bytes) */
2100 unsigned int addr_len;
2102 unsigned int read_command;
2106 * Wait for SPI command completion
2109 static int falcon_spi_wait ( struct efab_nic *efab ) {
2116 falcon_read ( efab, ®, FCN_EE_SPI_HCMD_REG_KER );
2117 if ( EFAB_OWORD_FIELD ( reg, FCN_EE_SPI_HCMD_CMD_EN ) == 0 )
2119 } while ( ++count < 1000 );
2120 printf ( "Timed out waiting for SPI\n" );
2128 static int falcon_spi_read ( struct efab_nic *efab,
2129 struct efab_spi_device *spi,
2130 int address, void *data, unsigned int len ) {
2133 /* Program address register */
2134 EFAB_POPULATE_OWORD_1 ( reg, FCN_EE_SPI_HADR_ADR, address );
2135 falcon_write ( efab, ®, FCN_EE_SPI_HADR_REG_KER );
2137 /* Issue read command */
2138 EFAB_POPULATE_OWORD_7 ( reg,
2139 FCN_EE_SPI_HCMD_CMD_EN, 1,
2140 FCN_EE_SPI_HCMD_SF_SEL, spi->device_id,
2141 FCN_EE_SPI_HCMD_DABCNT, len,
2142 FCN_EE_SPI_HCMD_READ, FCN_EE_SPI_READ,
2143 FCN_EE_SPI_HCMD_DUBCNT, 0,
2144 FCN_EE_SPI_HCMD_ADBCNT, spi->addr_len,
2145 FCN_EE_SPI_HCMD_ENC, spi->read_command );
2146 falcon_write ( efab, ®, FCN_EE_SPI_HCMD_REG_KER );
2148 /* Wait for read to complete */
2149 if ( ! falcon_spi_wait ( efab ) )
2153 falcon_read ( efab, ®, FCN_EE_SPI_HDATA_REG_KER );
2154 memcpy ( data, ®, len );
2159 #define SPI_READ_CMD 0x03
2160 #define AT25F1024_ADDR_LEN 3
2161 #define AT25F1024_READ_CMD SPI_READ_CMD
2162 #define MC25XX640_ADDR_LEN 2
2163 #define MC25XX640_READ_CMD SPI_READ_CMD
2165 /** Falcon Flash SPI device */
2166 static struct efab_spi_device falcon_spi_flash = {
2167 .device_id = FCN_EE_SPI_FLASH,
2168 .addr_len = AT25F1024_ADDR_LEN,
2169 .read_command = AT25F1024_READ_CMD,
2172 /** Falcon EEPROM SPI device */
2173 static struct efab_spi_device falcon_spi_large_eeprom = {
2174 .device_id = FCN_EE_SPI_EEPROM,
2175 .addr_len = MC25XX640_ADDR_LEN,
2176 .read_command = MC25XX640_READ_CMD,
2179 /** Offset of MAC address within EEPROM or Flash */
2180 #define FALCON_MAC_ADDRESS_OFFSET(port) ( 0x310 + 0x08 * (port) )
2183 * Read MAC address from EEPROM
2186 static int falcon_read_eeprom ( struct efab_nic *efab ) {
2189 struct efab_spi_device *spi;
2191 /* Determine the SPI device containing the MAC address */
2192 falcon_read ( efab, ®, FCN_GPIO_CTL_REG_KER );
2193 has_flash = EFAB_OWORD_FIELD ( reg, FCN_FLASH_PRESENT );
2194 spi = has_flash ? &falcon_spi_flash : &falcon_spi_large_eeprom;
2196 return falcon_spi_read ( efab, spi,
2197 FALCON_MAC_ADDRESS_OFFSET ( efab->port ),
2198 efab->mac_addr, sizeof ( efab->mac_addr ) );
2201 /** RX descriptor */
2202 typedef efab_qword_t falcon_rx_desc_t;
2205 * Build RX descriptor
2208 static void falcon_build_rx_desc ( struct efab_nic *efab,
2209 struct efab_rx_buf *rx_buf ) {
2210 falcon_rx_desc_t *rxd;
2212 rxd = ( ( falcon_rx_desc_t * ) efab->rxd ) + rx_buf->id;
2213 EFAB_POPULATE_QWORD_2 ( *rxd,
2214 FCN_RX_KER_BUF_SIZE, EFAB_DATA_BUF_SIZE,
2216 virt_to_bus ( rx_buf->addr ) );
2220 * Update RX descriptor write pointer
2223 static void falcon_notify_rx_desc ( struct efab_nic *efab ) {
2226 EFAB_POPULATE_DWORD_1 ( reg, FCN_RX_DESC_WPTR_DWORD,
2227 efab->rx_write_ptr );
2228 falcon_writel ( efab, ®, FCN_RX_DESC_UPD_REG_KER_DWORD );
2231 /** TX descriptor */
2232 typedef efab_qword_t falcon_tx_desc_t;
2235 * Build TX descriptor
2238 static void falcon_build_tx_desc ( struct efab_nic *efab,
2239 struct efab_tx_buf *tx_buf ) {
2240 falcon_rx_desc_t *txd;
2242 txd = ( ( falcon_rx_desc_t * ) efab->txd ) + tx_buf->id;
2243 EFAB_POPULATE_QWORD_3 ( *txd,
2244 FCN_TX_KER_PORT, efab->port,
2245 FCN_TX_KER_BYTE_CNT, tx_buf->len,
2247 virt_to_bus ( tx_buf->addr ) );
2251 * Update TX descriptor write pointer
2254 static void falcon_notify_tx_desc ( struct efab_nic *efab ) {
2257 EFAB_POPULATE_DWORD_1 ( reg, FCN_TX_DESC_WPTR_DWORD,
2258 efab->tx_write_ptr );
2259 falcon_writel ( efab, ®, FCN_TX_DESC_UPD_REG_KER_DWORD );
2263 typedef efab_qword_t falcon_event_t;
2266 * Retrieve event from event queue
2269 static int falcon_fetch_event ( struct efab_nic *efab,
2270 struct efab_event *event ) {
2271 falcon_event_t *evt;
2275 /* Check for event */
2276 evt = ( ( falcon_event_t * ) efab->eventq ) + efab->eventq_read_ptr;
2277 if ( EFAB_QWORD_IS_ZERO ( *evt ) ) {
2282 DBG ( "Event is " EFAB_QWORD_FMT "\n", EFAB_QWORD_VAL ( *evt ) );
2285 ev_code = EFAB_QWORD_FIELD ( *evt, FCN_EV_CODE );
2286 switch ( ev_code ) {
2287 case FCN_TX_IP_EV_DECODE:
2288 event->type = EFAB_EV_TX;
2290 case FCN_RX_IP_EV_DECODE:
2291 event->type = EFAB_EV_RX;
2292 event->rx_id = EFAB_QWORD_FIELD ( *evt, FCN_RX_EV_DESC_PTR );
2293 event->rx_len = EFAB_QWORD_FIELD ( *evt, FCN_RX_EV_BYTE_CNT );
2294 rx_port = EFAB_QWORD_FIELD ( *evt, FCN_RX_PORT );
2295 if ( rx_port != efab->port ) {
2296 /* Ignore packets on the wrong port. We can't
2297 * just set event->type = EFAB_EV_NONE,
2298 * because then the descriptor ring won't get
2304 case FCN_DRIVER_EV_DECODE:
2305 /* Ignore start-of-day events */
2306 event->type = EFAB_EV_NONE;
2309 printf ( "Unknown event type %d\n", ev_code );
2310 event->type = EFAB_EV_NONE;
2313 /* Clear event and any pending interrupts */
2314 EFAB_ZERO_QWORD ( *evt );
2315 falcon_writel ( efab, 0, FCN_INT_ACK_KER_REG );
2318 /* Increment and update event queue read pointer */
2319 efab->eventq_read_ptr = ( ( efab->eventq_read_ptr + 1 )
2321 falcon_eventq_read_ack ( efab );
2327 * Enable/disable/generate interrupt
2330 static inline void falcon_interrupts ( struct efab_nic *efab, int enabled,
2332 efab_oword_t int_en_reg_ker;
2334 EFAB_POPULATE_OWORD_2 ( int_en_reg_ker,
2335 FCN_KER_INT_KER, force,
2336 FCN_DRV_INT_EN_KER, enabled );
2337 falcon_write ( efab, &int_en_reg_ker, FCN_INT_EN_REG_KER );
2341 * Enable/disable interrupts
2344 static void falcon_mask_irq ( struct efab_nic *efab, int enabled ) {
2345 falcon_interrupts ( efab, enabled, 0 );
2347 /* Events won't trigger interrupts until we do this */
2348 falcon_eventq_read_ack ( efab );
2353 * Generate interrupt
2356 static void falcon_generate_irq ( struct efab_nic *efab ) {
2357 falcon_interrupts ( efab, 1, 1 );
2361 * Write dword to a Falcon MAC register
2364 static void falcon_mac_writel ( struct efab_nic *efab,
2365 efab_dword_t *value, unsigned int mac_reg ) {
2368 EFAB_POPULATE_OWORD_1 ( temp, FCN_MAC_DATA,
2369 EFAB_DWORD_FIELD ( *value, FCN_MAC_DATA ) );
2370 falcon_write ( efab, &temp, FALCON_MAC_REG ( efab, mac_reg ) );
2374 * Read dword from a Falcon MAC register
2377 static void falcon_mac_readl ( struct efab_nic *efab, efab_dword_t *value,
2378 unsigned int mac_reg ) {
2381 falcon_read ( efab, &temp, FALCON_MAC_REG ( efab, mac_reg ) );
2382 EFAB_POPULATE_DWORD_1 ( *value, FCN_MAC_DATA,
2383 EFAB_OWORD_FIELD ( temp, FCN_MAC_DATA ) );
2390 static int falcon_init_mac ( struct efab_nic *efab ) {
2391 static struct efab_mentormac_parameters falcon_mentormac_params = {
2392 .gmf_cfgfrth = 0x12,
2393 .gmf_cfgftth = 0x08,
2394 .gmf_cfghwmft = 0x1c,
2401 /* Initialise PHY */
2402 alaska_init ( efab );
2404 /* Initialise MAC */
2405 mentormac_init ( efab, &falcon_mentormac_params );
2407 /* Configure the Falcon MAC wrapper */
2408 EFAB_POPULATE_OWORD_4 ( reg,
2409 FCN_XM_RX_JUMBO_MODE, 0,
2410 FCN_XM_CUT_THRU_MODE, 0,
2411 FCN_XM_TX_STAT_EN, 1,
2412 FCN_XM_RX_STAT_EN, 1);
2413 falcon_write ( efab, ®, FCN_XM_GLB_CFG_REG_P0_KER );
2415 EFAB_POPULATE_OWORD_6 ( reg,
2420 FCN_XM_WTF_DOES_THIS_DO, 1,
2422 falcon_write ( efab, ®, FCN_XM_TX_CFG_REG_P0_KER );
2424 EFAB_POPULATE_OWORD_3 ( reg,
2426 FCN_XM_AUTO_DEPAD, 1,
2427 FCN_XM_PASS_CRC_ERR, 1 );
2428 falcon_write ( efab, ®, FCN_XM_RX_CFG_REG_P0_KER );
2430 #warning "10G support not yet present"
2432 if ( efab->link_options & LPA_10000 ) {
2434 } else if ( efab->link_options & LPA_1000 ) {
2436 } else if ( efab->link_options & LPA_100 ) {
2441 EFAB_POPULATE_OWORD_5 ( reg,
2442 FCN_MAC_XOFF_VAL, 0xffff /* datasheet */,
2443 FCN_MAC_BCAD_ACPT, 1,
2445 FCN_MAC_LINK_STATUS, 1,
2446 FCN_MAC_SPEED, link_speed );
2447 falcon_write ( efab, ®, ( efab->port == 0 ?
2448 FCN_MAC0_CTRL_REG_KER : FCN_MAC1_CTRL_REG_KER ) );
2454 * Wait for GMII access to complete
2457 static int falcon_gmii_wait ( struct efab_nic *efab ) {
2458 efab_oword_t md_stat;
2461 for ( count = 0 ; count < 1000 ; count++ ) {
2463 falcon_read ( efab, &md_stat, FCN_MD_STAT_REG_KER );
2464 if ( EFAB_OWORD_FIELD ( md_stat, FCN_MD_BSY ) == 0 )
2467 printf ( "Timed out waiting for GMII\n" );
2472 static void falcon_mdio_write ( struct efab_nic *efab, int location,
2474 int phy_id = efab->port + 2;
2477 #warning "10G PHY access not yet in place"
2479 EFAB_TRACE ( "Writing GMII %d register %02x with %04x\n",
2480 phy_id, location, value );
2482 /* Check MII not currently being accessed */
2483 if ( ! falcon_gmii_wait ( efab ) )
2486 /* Write the address registers */
2487 EFAB_POPULATE_OWORD_1 ( reg, FCN_MD_PHY_ADR, 0 /* phy_id ? */ );
2488 falcon_write ( efab, ®, FCN_MD_PHY_ADR_REG_KER );
2490 EFAB_POPULATE_OWORD_2 ( reg,
2491 FCN_MD_PRT_ADR, phy_id,
2492 FCN_MD_DEV_ADR, location );
2493 falcon_write ( efab, ®, FCN_MD_ID_REG_KER );
2497 EFAB_POPULATE_OWORD_1 ( reg, FCN_MD_TXD, value );
2498 falcon_write ( efab, ®, FCN_MD_TXD_REG_KER );
2500 EFAB_POPULATE_OWORD_2 ( reg,
2503 falcon_write ( efab, ®, FCN_MD_CS_REG_KER );
2506 /* Wait for data to be written */
2507 falcon_gmii_wait ( efab );
2511 static int falcon_mdio_read ( struct efab_nic *efab, int location ) {
2512 int phy_id = efab->port + 2;
2516 /* Check MII not currently being accessed */
2517 if ( ! falcon_gmii_wait ( efab ) )
2520 /* Write the address registers */
2521 EFAB_POPULATE_OWORD_1 ( reg, FCN_MD_PHY_ADR, 0 /* phy_id ? */ );
2522 falcon_write ( efab, ®, FCN_MD_PHY_ADR_REG_KER );
2524 EFAB_POPULATE_OWORD_2 ( reg,
2525 FCN_MD_PRT_ADR, phy_id,
2526 FCN_MD_DEV_ADR, location );
2527 falcon_write ( efab, ®, FCN_MD_ID_REG_KER );
2530 /* Request data to be read */
2531 EFAB_POPULATE_OWORD_2 ( reg,
2534 falcon_write ( efab, ®, FCN_MD_CS_REG_KER );
2537 /* Wait for data to become available */
2538 falcon_gmii_wait ( efab );
2541 falcon_read ( efab, ®, FCN_MD_RXD_REG_KER );
2542 value = EFAB_OWORD_FIELD ( reg, FCN_MD_RXD );
2544 EFAB_TRACE ( "Read from GMII %d register %02x, got %04x\n",
2545 phy_id, location, value );
2550 static struct efab_operations falcon_operations = {
2551 .get_membase = falcon_get_membase,
2552 .reset = falcon_reset,
2553 .init_nic = falcon_init_nic,
2554 .read_eeprom = falcon_read_eeprom,
2555 .build_rx_desc = falcon_build_rx_desc,
2556 .notify_rx_desc = falcon_notify_rx_desc,
2557 .build_tx_desc = falcon_build_tx_desc,
2558 .notify_tx_desc = falcon_notify_tx_desc,
2559 .fetch_event = falcon_fetch_event,
2560 .mask_irq = falcon_mask_irq,
2561 .generate_irq = falcon_generate_irq,
2562 .mac_writel = falcon_mac_writel,
2563 .mac_readl = falcon_mac_readl,
2564 .init_mac = falcon_init_mac,
2565 .mdio_write = falcon_mdio_write,
2566 .mdio_read = falcon_mdio_read,
2569 /**************************************************************************
2571 * Etherfabric abstraction layer
2573 **************************************************************************
2577 * Push RX buffer to RXD ring
2580 static inline void efab_push_rx_buffer ( struct efab_nic *efab,
2581 struct efab_rx_buf *rx_buf ) {
2582 /* Create RX descriptor */
2583 rx_buf->id = efab->rx_write_ptr;
2584 efab->op->build_rx_desc ( efab, rx_buf );
2586 /* Update RX write pointer */
2587 efab->rx_write_ptr = ( efab->rx_write_ptr + 1 ) % EFAB_RXD_SIZE;
2588 efab->op->notify_rx_desc ( efab );
2590 DBG ( "Added RX id %x\n", rx_buf->id );
2594 * Push TX buffer to TXD ring
2597 static inline void efab_push_tx_buffer ( struct efab_nic *efab,
2598 struct efab_tx_buf *tx_buf ) {
2599 /* Create TX descriptor */
2600 tx_buf->id = efab->tx_write_ptr;
2601 efab->op->build_tx_desc ( efab, tx_buf );
2603 /* Update TX write pointer */
2604 efab->tx_write_ptr = ( efab->tx_write_ptr + 1 ) % EFAB_TXD_SIZE;
2605 efab->op->notify_tx_desc ( efab );
2607 DBG ( "Added TX id %x\n", tx_buf->id );
2611 * Initialise MAC and wait for link up
2614 static int efab_init_mac ( struct efab_nic *efab ) {
2617 /* This can take several seconds */
2618 printf ( "Waiting for link.." );
2622 if ( ! efab->op->init_mac ( efab ) ) {
2623 printf ( "failed\n" );
2626 if ( efab->link_up ) {
2627 /* PHY init printed the message for us */
2631 } while ( ++count < 5 );
2632 printf ( "timed out\n" );
2641 static int efab_init_nic ( struct efab_nic *efab ) {
2644 /* Initialise NIC */
2645 if ( ! efab->op->init_nic ( efab ) )
2648 /* Push RX descriptors */
2649 for ( i = 0 ; i < EFAB_RX_BUFS ; i++ ) {
2650 efab_push_rx_buffer ( efab, &efab->rx_bufs[i] );
2653 /* Read MAC address from EEPROM */
2654 if ( ! efab->op->read_eeprom ( efab ) )
2656 efab->mac_addr[ETH_ALEN-1] += efab->port;
2658 /* Initialise MAC and wait for link up */
2659 if ( ! efab_init_mac ( efab ) )
2665 /**************************************************************************
2667 * Etherboot interface
2669 **************************************************************************
2672 /**************************************************************************
2673 POLL - Wait for a frame
2674 ***************************************************************************/
2675 static int etherfabric_poll ( struct nic *nic, int retrieve ) {
2676 struct efab_nic *efab = nic->priv_data;
2677 struct efab_event event;
2678 static struct efab_rx_buf *rx_buf = NULL;
2681 /* Process the event queue until we hit either a packet
2682 * received event or an empty event slot.
2684 while ( ( rx_buf == NULL ) &&
2685 efab->op->fetch_event ( efab, &event ) ) {
2686 if ( event.type == EFAB_EV_TX ) {
2687 /* TX completed - mark as done */
2688 DBG ( "TX id %x complete\n",
2690 efab->tx_in_progress = 0;
2691 } else if ( event.type == EFAB_EV_RX ) {
2692 /* RX - find corresponding buffer */
2693 for ( i = 0 ; i < EFAB_RX_BUFS ; i++ ) {
2694 if ( efab->rx_bufs[i].id == event.rx_id ) {
2695 rx_buf = &efab->rx_bufs[i];
2696 rx_buf->len = event.rx_len;
2697 DBG ( "RX id %x (len %x) received\n",
2698 rx_buf->id, rx_buf->len );
2703 printf ( "Invalid RX ID %x\n", event.rx_id );
2705 } else if ( event.type == EFAB_EV_NONE ) {
2706 DBG ( "Ignorable event\n" );
2708 DBG ( "Unknown event\n" );
2712 /* If there is no packet, return 0 */
2716 /* If we don't want to retrieve it just yet, return 1 */
2720 /* Copy packet contents */
2721 nic->packetlen = rx_buf->len;
2722 memcpy ( nic->packet, rx_buf->addr, nic->packetlen );
2724 /* Give this buffer back to the NIC */
2725 efab_push_rx_buffer ( efab, rx_buf );
2727 /* Prepare to receive next packet */
2733 /**************************************************************************
2734 TRANSMIT - Transmit a frame
2735 ***************************************************************************/
2736 static void etherfabric_transmit ( struct nic *nic, const char *dest,
2737 unsigned int type, unsigned int size,
2738 const char *data ) {
2739 struct efab_nic *efab = nic->priv_data;
2740 unsigned int nstype = htons ( type );
2742 /* We can only transmit one packet at a time; a TX completion
2743 * event must be received before we can transmit the next
2744 * packet. Since there is only one static TX buffer, we don't
2745 * worry unduly about overflow, but we report it anyway.
2747 if ( efab->tx_in_progress ) {
2748 printf ( "TX overflow!\n" );
2751 /* Fill TX buffer, pad to ETH_ZLEN */
2752 memcpy ( efab->tx_buf.addr, dest, ETH_ALEN );
2753 memcpy ( efab->tx_buf.addr + ETH_ALEN, nic->node_addr, ETH_ALEN );
2754 memcpy ( efab->tx_buf.addr + 2 * ETH_ALEN, &nstype, 2 );
2755 memcpy ( efab->tx_buf.addr + ETH_HLEN, data, size );
2757 while ( size < ETH_ZLEN ) {
2758 efab->tx_buf.addr[size++] = '\0';
2760 efab->tx_buf.len = size;
2762 /* Push TX descriptor */
2763 efab_push_tx_buffer ( efab, &efab->tx_buf );
2765 /* There is no way to wait for TX complete (i.e. TX buffer
2766 * available to re-use for the next transmit) without reading
2767 * from the event queue. We therefore simply leave the TX
2768 * buffer marked as "in use" until a TX completion event
2769 * happens to be picked up by a call to etherfabric_poll().
2771 efab->tx_in_progress = 1;
2776 /**************************************************************************
2777 DISABLE - Turn off ethernet interface
2778 ***************************************************************************/
2779 static void etherfabric_disable ( struct nic *nic ) {
2780 struct efab_nic *efab = nic->priv_data;
2782 efab->op->reset ( efab );
2783 if ( efab->membase )
2784 iounmap ( efab->membase );
2787 /**************************************************************************
2788 IRQ - handle interrupts
2789 ***************************************************************************/
2790 static void etherfabric_irq ( struct nic *nic, irq_action_t action ) {
2791 struct efab_nic *efab = nic->priv_data;
2795 efab->op->mask_irq ( efab, 1 );
2798 efab->op->mask_irq ( efab, 0 );
2801 /* Force NIC to generate a receive interrupt */
2802 efab->op->generate_irq ( efab );
2809 static struct nic_operations etherfabric_operations = {
2810 .connect = dummy_connect,
2811 .poll = etherfabric_poll,
2812 .transmit = etherfabric_transmit,
2813 .irq = etherfabric_irq,
2816 /**************************************************************************
2817 PROBE - Look for an adapter, this routine's visible to the outside
2818 ***************************************************************************/
2819 static int etherfabric_probe ( struct nic *nic, struct pci_device *pci ) {
2820 static struct efab_nic efab;
2821 static int nic_port = 1;
2822 struct efab_buffers *buffers;
2825 /* Set up our private data structure */
2826 nic->priv_data = &efab;
2827 memset ( &efab, 0, sizeof ( efab ) );
2828 memset ( &efab_buffers, 0, sizeof ( efab_buffers ) );
2830 /* Hook in appropriate operations table. Do this early. */
2831 if ( pci->device == EF1002_DEVID ) {
2832 efab.op = &ef1002_operations;
2834 efab.op = &falcon_operations;
2837 /* Initialise efab data structure */
2839 buffers = ( ( struct efab_buffers * )
2840 ( ( ( void * ) &efab_buffers ) +
2841 ( - virt_to_bus ( &efab_buffers ) ) % EFAB_BUF_ALIGN ) );
2842 efab.eventq = buffers->eventq;
2843 efab.txd = buffers->txd;
2844 efab.rxd = buffers->rxd;
2845 efab.tx_buf.addr = buffers->tx_buf;
2846 for ( i = 0 ; i < EFAB_RX_BUFS ; i++ ) {
2847 efab.rx_bufs[i].addr = buffers->rx_buf[i];
2850 /* Enable the PCI device */
2851 adjust_pci_device ( pci );
2852 nic->ioaddr = pci->ioaddr & ~3;
2853 nic->irqno = pci->irq;
2855 /* Get iobase/membase */
2856 efab.iobase = nic->ioaddr;
2857 efab.op->get_membase ( &efab );
2859 /* Switch NIC ports (i.e. try different ports on each probe) */
2860 nic_port = 1 - nic_port;
2861 efab.port = nic_port;
2863 /* Initialise hardware */
2864 if ( ! efab_init_nic ( &efab ) )
2866 memcpy ( nic->node_addr, efab.mac_addr, ETH_ALEN );
2869 printf ( "Found EtherFabric %s NIC %!\n", pci->name, nic->node_addr );
2871 /* point to NIC specific routines */
2872 nic->nic_op = ðerfabric_operations;
2877 static struct pci_device_id etherfabric_nics[] = {
2878 PCI_ROM(0x1924, 0xC101, "ef1002", "EtherFabric EF1002"),
2879 PCI_ROM(0x1924, 0x0703, "falcon", "EtherFabric Falcon"),
2882 PCI_DRIVER ( etherfabric_driver, etherfabric_nics, PCI_NO_CLASS );
2884 DRIVER ( "EFAB", nic_driver, pci_driver, etherfabric_driver,
2885 etherfabric_probe, etherfabric_disable );