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 FILE_LICENCE ( GPL_ANY );
30 #include <ipxe/malloc.h>
31 #include <ipxe/ethernet.h>
32 #include <ipxe/iobuf.h>
33 #include <ipxe/netdevice.h>
34 #include <ipxe/timer.h>
36 #include "etherfabric.h"
37 #include "etherfabric_nic.h"
39 /**************************************************************************
41 * Constants and macros
43 **************************************************************************
46 #define EFAB_REGDUMP(...)
47 #define EFAB_TRACE(...) DBGP(__VA_ARGS__)
49 // printf() is not allowed within drivers. Use DBG() instead.
50 #define EFAB_LOG(...) DBG(__VA_ARGS__)
51 #define EFAB_ERR(...) DBG(__VA_ARGS__)
53 #define FALCON_USE_IO_BAR 0
58 /**************************************************************************
60 * Hardware data structures and sizing
62 **************************************************************************
64 extern int __invalid_queue_size;
65 #define FQS(_prefix, _x) \
66 ( ( (_x) == 512 ) ? _prefix ## _SIZE_512 : \
67 ( ( (_x) == 1024 ) ? _prefix ## _SIZE_1K : \
68 ( ( (_x) == 2048 ) ? _prefix ## _SIZE_2K : \
69 ( ( (_x) == 4096) ? _prefix ## _SIZE_4K : \
70 __invalid_queue_size ) ) ) )
73 #define EFAB_MAX_FRAME_LEN(mtu) \
74 ( ( ( ( mtu ) + 4/* FCS */ ) + 7 ) & ~7 )
76 /**************************************************************************
80 **************************************************************************
83 static void falcon_mdio_write (struct efab_nic *efab, int device,
84 int location, int value );
85 static int falcon_mdio_read ( struct efab_nic *efab, int device, int location );
88 #define GMII_PSSR 0x11 /* PHY-specific status register */
90 /* Pseudo extensions to the link partner ability register */
91 #define LPA_EF_1000FULL 0x00020000
92 #define LPA_EF_1000HALF 0x00010000
93 #define LPA_EF_10000FULL 0x00040000
94 #define LPA_EF_10000HALF 0x00080000
96 #define LPA_EF_1000 ( LPA_EF_1000FULL | LPA_EF_1000HALF )
97 #define LPA_EF_10000 ( LPA_EF_10000FULL | LPA_EF_10000HALF )
98 #define LPA_EF_DUPLEX ( LPA_10FULL | LPA_100FULL | LPA_EF_1000FULL | \
101 /* Mask of bits not associated with speed or duplexity. */
102 #define LPA_OTHER ~( LPA_10FULL | LPA_10HALF | LPA_100FULL | \
103 LPA_100HALF | LPA_EF_1000FULL | LPA_EF_1000HALF )
105 /* PHY-specific status register */
106 #define PSSR_LSTATUS 0x0400 /* Bit 10 - link status */
109 * Retrieve GMII autonegotiation advertised abilities
113 gmii_autoneg_advertised ( struct efab_nic *efab )
115 unsigned int mii_advertise;
116 unsigned int gmii_advertise;
118 /* Extended bits are in bits 8 and 9 of MII_CTRL1000 */
119 mii_advertise = falcon_mdio_read ( efab, 0, MII_ADVERTISE );
120 gmii_advertise = ( ( falcon_mdio_read ( efab, 0, MII_CTRL1000 ) >> 8 )
122 return ( ( gmii_advertise << 16 ) | mii_advertise );
126 * Retrieve GMII autonegotiation link partner abilities
130 gmii_autoneg_lpa ( struct efab_nic *efab )
132 unsigned int mii_lpa;
133 unsigned int gmii_lpa;
135 /* Extended bits are in bits 10 and 11 of MII_STAT1000 */
136 mii_lpa = falcon_mdio_read ( efab, 0, MII_LPA );
137 gmii_lpa = ( falcon_mdio_read ( efab, 0, MII_STAT1000 ) >> 10 ) & 0x03;
138 return ( ( gmii_lpa << 16 ) | mii_lpa );
142 * Calculate GMII autonegotiated link technology
146 gmii_nway_result ( unsigned int negotiated )
148 unsigned int other_bits;
150 /* Mask out the speed and duplexity bits */
151 other_bits = negotiated & LPA_OTHER;
153 if ( negotiated & LPA_EF_1000FULL )
154 return ( other_bits | LPA_EF_1000FULL );
155 else if ( negotiated & LPA_EF_1000HALF )
156 return ( other_bits | LPA_EF_1000HALF );
157 else if ( negotiated & LPA_100FULL )
158 return ( other_bits | LPA_100FULL );
159 else if ( negotiated & LPA_100BASE4 )
160 return ( other_bits | LPA_100BASE4 );
161 else if ( negotiated & LPA_100HALF )
162 return ( other_bits | LPA_100HALF );
163 else if ( negotiated & LPA_10FULL )
164 return ( other_bits | LPA_10FULL );
165 else return ( other_bits | LPA_10HALF );
169 * Check GMII PHY link status
173 gmii_link_ok ( struct efab_nic *efab )
178 /* BMSR is latching - it returns "link down" if the link has
179 * been down at any point since the last read. To get a
180 * real-time status, we therefore read the register twice and
181 * use the result of the second read.
183 (void) falcon_mdio_read ( efab, 0, MII_BMSR );
184 status = falcon_mdio_read ( efab, 0, MII_BMSR );
186 /* Read the PHY-specific Status Register. This is
187 * non-latching, so we need do only a single read.
189 phy_status = falcon_mdio_read ( efab, 0, GMII_PSSR );
191 return ( ( status & BMSR_LSTATUS ) && ( phy_status & PSSR_LSTATUS ) );
194 /**************************************************************************
198 **************************************************************************
201 /* Numbering of the MDIO Manageable Devices (MMDs) */
202 /* Physical Medium Attachment/ Physical Medium Dependent sublayer */
203 #define MDIO_MMD_PMAPMD (1)
204 /* WAN Interface Sublayer */
205 #define MDIO_MMD_WIS (2)
206 /* Physical Coding Sublayer */
207 #define MDIO_MMD_PCS (3)
208 /* PHY Extender Sublayer */
209 #define MDIO_MMD_PHYXS (4)
210 /* Extender Sublayer */
211 #define MDIO_MMD_DTEXS (5)
212 /* Transmission convergence */
213 #define MDIO_MMD_TC (6)
214 /* Auto negotiation */
215 #define MDIO_MMD_AN (7)
217 /* Generic register locations */
218 #define MDIO_MMDREG_CTRL1 (0)
219 #define MDIO_MMDREG_STAT1 (1)
220 #define MDIO_MMDREG_DEVS0 (5)
221 #define MDIO_MMDREG_STAT2 (8)
223 /* Bits in MMDREG_CTRL1 */
225 #define MDIO_MMDREG_CTRL1_RESET_LBN (15)
226 #define MDIO_MMDREG_CTRL1_RESET_WIDTH (1)
228 /* Bits in MMDREG_STAT1 */
229 #define MDIO_MMDREG_STAT1_FAULT_LBN (7)
230 #define MDIO_MMDREG_STAT1_FAULT_WIDTH (1)
233 #define MDIO_MMDREG_STAT1_LINK_LBN (2)
234 #define MDIO_MMDREG_STAT1_LINK_WIDTH (1)
236 /* Bits in MMDREG_DEVS0. */
237 #define DEV_PRESENT_BIT(_b) (1 << _b)
239 #define MDIO_MMDREG_DEVS0_DTEXS DEV_PRESENT_BIT(MDIO_MMD_DTEXS)
240 #define MDIO_MMDREG_DEVS0_PHYXS DEV_PRESENT_BIT(MDIO_MMD_PHYXS)
241 #define MDIO_MMDREG_DEVS0_PCS DEV_PRESENT_BIT(MDIO_MMD_PCS)
242 #define MDIO_MMDREG_DEVS0_WIS DEV_PRESENT_BIT(MDIO_MMD_WIS)
243 #define MDIO_MMDREG_DEVS0_PMAPMD DEV_PRESENT_BIT(MDIO_MMD_PMAPMD)
245 #define MDIO_MMDREG_DEVS0_AN DEV_PRESENT_BIT(MDIO_MMD_AN)
247 /* Bits in MMDREG_STAT2 */
248 #define MDIO_MMDREG_STAT2_PRESENT_VAL (2)
249 #define MDIO_MMDREG_STAT2_PRESENT_LBN (14)
250 #define MDIO_MMDREG_STAT2_PRESENT_WIDTH (2)
252 /* PHY XGXS lane state */
253 #define MDIO_PHYXS_LANE_STATE (0x18)
254 #define MDIO_PHYXS_LANE_ALIGNED_LBN (12)
255 #define MDIO_PHYXS_LANE_SYNC0_LBN (0)
256 #define MDIO_PHYXS_LANE_SYNC1_LBN (1)
257 #define MDIO_PHYXS_LANE_SYNC2_LBN (2)
258 #define MDIO_PHYXS_LANE_SYNC3_LBN (3)
260 /* This ought to be ridiculous overkill. We expect it to fail rarely */
261 #define MDIO45_RESET_TRIES 100
262 #define MDIO45_RESET_SPINTIME 10
265 mdio_clause45_wait_reset_mmds ( struct efab_nic* efab )
267 int tries = MDIO45_RESET_TRIES;
271 int mask = efab->phy_op->mmds;
276 int stat = falcon_mdio_read ( efab, mmd,
279 EFAB_ERR("Failed to read status of MMD %d\n",
284 if (stat & (1 << MDIO_MMDREG_CTRL1_RESET_LBN))
285 in_reset |= (1 << mmd);
293 mdelay ( MDIO45_RESET_SPINTIME );
296 EFAB_ERR("Not all MMDs came out of reset in time. MMDs "
297 "still in reset: %x\n", in_reset);
304 mdio_clause45_reset_mmd ( struct efab_nic *efab, int mmd )
306 int tries = MDIO45_RESET_TRIES;
309 falcon_mdio_write ( efab, mmd, MDIO_MMDREG_CTRL1,
310 ( 1 << MDIO_MMDREG_CTRL1_RESET_LBN ) );
312 /* Wait for the reset bit to clear. */
314 mdelay ( MDIO45_RESET_SPINTIME );
316 ctrl = falcon_mdio_read ( efab, mmd, MDIO_MMDREG_CTRL1 );
317 if ( ~ctrl & ( 1 << MDIO_MMDREG_CTRL1_RESET_LBN ) )
321 EFAB_ERR ( "Failed to reset mmd %d\n", mmd );
327 mdio_clause45_links_ok(struct efab_nic *efab )
332 int mmd_mask = efab->phy_op->mmds;
336 /* Double reads because link state is latched, and a
337 * read moves the current state into the register */
338 status = falcon_mdio_read ( efab, mmd,
340 status = falcon_mdio_read ( efab, mmd,
343 good = status & (1 << MDIO_MMDREG_STAT1_LINK_LBN);
346 mmd_mask = (mmd_mask >> 1);
353 mdio_clause45_check_mmds ( struct efab_nic *efab )
356 int devices = falcon_mdio_read ( efab, MDIO_MMD_PHYXS,
358 int mmd_mask = efab->phy_op->mmds;
360 /* Check all the expected MMDs are present */
362 EFAB_ERR ( "Failed to read devices present\n" );
365 if ( ( devices & mmd_mask ) != mmd_mask ) {
366 EFAB_ERR ( "required MMDs not present: got %x, wanted %x\n",
371 /* Check all required MMDs are responding and happy. */
373 if ( mmd_mask & 1 ) {
376 reg.opaque = falcon_mdio_read ( efab, mmd,
378 status = EFAB_DWORD_FIELD ( reg,
379 MDIO_MMDREG_STAT2_PRESENT );
380 if ( status != MDIO_MMDREG_STAT2_PRESENT_VAL ) {
393 /* I/O BAR address register */
394 #define FCN_IOM_IND_ADR_REG 0x0
396 /* I/O BAR data register */
397 #define FCN_IOM_IND_DAT_REG 0x4
399 /* Address region register */
400 #define FCN_ADR_REGION_REG_KER 0x00
401 #define FCN_ADR_REGION0_LBN 0
402 #define FCN_ADR_REGION0_WIDTH 18
403 #define FCN_ADR_REGION1_LBN 32
404 #define FCN_ADR_REGION1_WIDTH 18
405 #define FCN_ADR_REGION2_LBN 64
406 #define FCN_ADR_REGION2_WIDTH 18
407 #define FCN_ADR_REGION3_LBN 96
408 #define FCN_ADR_REGION3_WIDTH 18
410 /* Interrupt enable register */
411 #define FCN_INT_EN_REG_KER 0x0010
412 #define FCN_MEM_PERR_INT_EN_KER_LBN 5
413 #define FCN_MEM_PERR_INT_EN_KER_WIDTH 1
414 #define FCN_KER_INT_CHAR_LBN 4
415 #define FCN_KER_INT_CHAR_WIDTH 1
416 #define FCN_KER_INT_KER_LBN 3
417 #define FCN_KER_INT_KER_WIDTH 1
418 #define FCN_ILL_ADR_ERR_INT_EN_KER_LBN 2
419 #define FCN_ILL_ADR_ERR_INT_EN_KER_WIDTH 1
420 #define FCN_SRM_PERR_INT_EN_KER_LBN 1
421 #define FCN_SRM_PERR_INT_EN_KER_WIDTH 1
422 #define FCN_DRV_INT_EN_KER_LBN 0
423 #define FCN_DRV_INT_EN_KER_WIDTH 1
425 /* Interrupt status register */
426 #define FCN_INT_ADR_REG_KER 0x0030
427 #define FCN_INT_ADR_KER_LBN 0
428 #define FCN_INT_ADR_KER_WIDTH EFAB_DMA_TYPE_WIDTH ( 64 )
430 /* Interrupt status register (B0 only) */
431 #define INT_ISR0_B0 0x90
432 #define INT_ISR1_B0 0xA0
434 /* Interrupt acknowledge register (A0/A1 only) */
435 #define FCN_INT_ACK_KER_REG_A1 0x0050
436 #define INT_ACK_DUMMY_DATA_LBN 0
437 #define INT_ACK_DUMMY_DATA_WIDTH 32
439 /* Interrupt acknowledge work-around register (A0/A1 only )*/
440 #define WORK_AROUND_BROKEN_PCI_READS_REG_KER_A1 0x0070
442 /* Hardware initialisation register */
443 #define FCN_HW_INIT_REG_KER 0x00c0
444 #define FCN_BCSR_TARGET_MASK_LBN 101
445 #define FCN_BCSR_TARGET_MASK_WIDTH 4
447 /* SPI host command register */
448 #define FCN_EE_SPI_HCMD_REG 0x0100
449 #define FCN_EE_SPI_HCMD_CMD_EN_LBN 31
450 #define FCN_EE_SPI_HCMD_CMD_EN_WIDTH 1
451 #define FCN_EE_WR_TIMER_ACTIVE_LBN 28
452 #define FCN_EE_WR_TIMER_ACTIVE_WIDTH 1
453 #define FCN_EE_SPI_HCMD_SF_SEL_LBN 24
454 #define FCN_EE_SPI_HCMD_SF_SEL_WIDTH 1
455 #define FCN_EE_SPI_EEPROM 0
456 #define FCN_EE_SPI_FLASH 1
457 #define FCN_EE_SPI_HCMD_DABCNT_LBN 16
458 #define FCN_EE_SPI_HCMD_DABCNT_WIDTH 5
459 #define FCN_EE_SPI_HCMD_READ_LBN 15
460 #define FCN_EE_SPI_HCMD_READ_WIDTH 1
461 #define FCN_EE_SPI_READ 1
462 #define FCN_EE_SPI_WRITE 0
463 #define FCN_EE_SPI_HCMD_DUBCNT_LBN 12
464 #define FCN_EE_SPI_HCMD_DUBCNT_WIDTH 2
465 #define FCN_EE_SPI_HCMD_ADBCNT_LBN 8
466 #define FCN_EE_SPI_HCMD_ADBCNT_WIDTH 2
467 #define FCN_EE_SPI_HCMD_ENC_LBN 0
468 #define FCN_EE_SPI_HCMD_ENC_WIDTH 8
470 /* SPI host address register */
471 #define FCN_EE_SPI_HADR_REG 0x0110
472 #define FCN_EE_SPI_HADR_DUBYTE_LBN 24
473 #define FCN_EE_SPI_HADR_DUBYTE_WIDTH 8
474 #define FCN_EE_SPI_HADR_ADR_LBN 0
475 #define FCN_EE_SPI_HADR_ADR_WIDTH 24
477 /* SPI host data register */
478 #define FCN_EE_SPI_HDATA_REG 0x0120
479 #define FCN_EE_SPI_HDATA3_LBN 96
480 #define FCN_EE_SPI_HDATA3_WIDTH 32
481 #define FCN_EE_SPI_HDATA2_LBN 64
482 #define FCN_EE_SPI_HDATA2_WIDTH 32
483 #define FCN_EE_SPI_HDATA1_LBN 32
484 #define FCN_EE_SPI_HDATA1_WIDTH 32
485 #define FCN_EE_SPI_HDATA0_LBN 0
486 #define FCN_EE_SPI_HDATA0_WIDTH 32
488 /* VPD Config 0 Register register */
489 #define FCN_EE_VPD_CFG_REG 0x0140
490 #define FCN_EE_VPD_EN_LBN 0
491 #define FCN_EE_VPD_EN_WIDTH 1
492 #define FCN_EE_VPD_EN_AD9_MODE_LBN 1
493 #define FCN_EE_VPD_EN_AD9_MODE_WIDTH 1
494 #define FCN_EE_EE_CLOCK_DIV_LBN 112
495 #define FCN_EE_EE_CLOCK_DIV_WIDTH 7
496 #define FCN_EE_SF_CLOCK_DIV_LBN 120
497 #define FCN_EE_SF_CLOCK_DIV_WIDTH 7
500 /* NIC status register */
501 #define FCN_NIC_STAT_REG 0x0200
502 #define FCN_ONCHIP_SRAM_LBN 16
503 #define FCN_ONCHIP_SRAM_WIDTH 1
504 #define FCN_SF_PRST_LBN 9
505 #define FCN_SF_PRST_WIDTH 1
506 #define FCN_EE_PRST_LBN 8
507 #define FCN_EE_PRST_WIDTH 1
508 #define FCN_EE_STRAP_LBN 7
509 #define FCN_EE_STRAP_WIDTH 1
510 #define FCN_PCI_PCIX_MODE_LBN 4
511 #define FCN_PCI_PCIX_MODE_WIDTH 3
512 #define FCN_PCI_PCIX_MODE_PCI33_DECODE 0
513 #define FCN_PCI_PCIX_MODE_PCI66_DECODE 1
514 #define FCN_PCI_PCIX_MODE_PCIX66_DECODE 5
515 #define FCN_PCI_PCIX_MODE_PCIX100_DECODE 6
516 #define FCN_PCI_PCIX_MODE_PCIX133_DECODE 7
517 #define FCN_STRAP_ISCSI_EN_LBN 3
518 #define FCN_STRAP_ISCSI_EN_WIDTH 1
519 #define FCN_STRAP_PINS_LBN 0
520 #define FCN_STRAP_PINS_WIDTH 3
521 #define FCN_STRAP_10G_LBN 2
522 #define FCN_STRAP_10G_WIDTH 1
523 #define FCN_STRAP_DUAL_PORT_LBN 1
524 #define FCN_STRAP_DUAL_PORT_WIDTH 1
525 #define FCN_STRAP_PCIE_LBN 0
526 #define FCN_STRAP_PCIE_WIDTH 1
528 /* Falcon revisions */
529 #define FALCON_REV_A0 0
530 #define FALCON_REV_A1 1
531 #define FALCON_REV_B0 2
533 /* GPIO control register */
534 #define FCN_GPIO_CTL_REG_KER 0x0210
535 #define FCN_GPIO_CTL_REG_KER 0x0210
537 #define FCN_GPIO3_OEN_LBN 27
538 #define FCN_GPIO3_OEN_WIDTH 1
539 #define FCN_GPIO2_OEN_LBN 26
540 #define FCN_GPIO2_OEN_WIDTH 1
541 #define FCN_GPIO1_OEN_LBN 25
542 #define FCN_GPIO1_OEN_WIDTH 1
543 #define FCN_GPIO0_OEN_LBN 24
544 #define FCN_GPIO0_OEN_WIDTH 1
546 #define FCN_GPIO3_OUT_LBN 19
547 #define FCN_GPIO3_OUT_WIDTH 1
548 #define FCN_GPIO2_OUT_LBN 18
549 #define FCN_GPIO2_OUT_WIDTH 1
550 #define FCN_GPIO1_OUT_LBN 17
551 #define FCN_GPIO1_OUT_WIDTH 1
552 #define FCN_GPIO0_OUT_LBN 16
553 #define FCN_GPIO0_OUT_WIDTH 1
555 #define FCN_GPIO3_IN_LBN 11
556 #define FCN_GPIO3_IN_WIDTH 1
557 #define FCN_GPIO2_IN_LBN 10
558 #define FCN_GPIO2_IN_WIDTH 1
559 #define FCN_GPIO1_IN_LBN 9
560 #define FCN_GPIO1_IN_WIDTH 1
561 #define FCN_GPIO0_IN_LBN 8
562 #define FCN_GPIO0_IN_WIDTH 1
564 #define FCN_FLASH_PRESENT_LBN 7
565 #define FCN_FLASH_PRESENT_WIDTH 1
566 #define FCN_EEPROM_PRESENT_LBN 6
567 #define FCN_EEPROM_PRESENT_WIDTH 1
568 #define FCN_BOOTED_USING_NVDEVICE_LBN 3
569 #define FCN_BOOTED_USING_NVDEVICE_WIDTH 1
571 /* Defines for extra non-volatile storage */
572 #define FCN_NV_MAGIC_NUMBER 0xFA1C
574 /* Global control register */
575 #define FCN_GLB_CTL_REG_KER 0x0220
576 #define FCN_EXT_PHY_RST_CTL_LBN 63
577 #define FCN_EXT_PHY_RST_CTL_WIDTH 1
578 #define FCN_PCIE_SD_RST_CTL_LBN 61
579 #define FCN_PCIE_SD_RST_CTL_WIDTH 1
580 #define FCN_PCIE_STCK_RST_CTL_LBN 59
581 #define FCN_PCIE_STCK_RST_CTL_WIDTH 1
582 #define FCN_PCIE_NSTCK_RST_CTL_LBN 58
583 #define FCN_PCIE_NSTCK_RST_CTL_WIDTH 1
584 #define FCN_PCIE_CORE_RST_CTL_LBN 57
585 #define FCN_PCIE_CORE_RST_CTL_WIDTH 1
586 #define FCN_EE_RST_CTL_LBN 49
587 #define FCN_EE_RST_CTL_WIDTH 1
588 #define FCN_RST_EXT_PHY_LBN 31
589 #define FCN_RST_EXT_PHY_WIDTH 1
590 #define FCN_EXT_PHY_RST_DUR_LBN 1
591 #define FCN_EXT_PHY_RST_DUR_WIDTH 3
592 #define FCN_SWRST_LBN 0
593 #define FCN_SWRST_WIDTH 1
594 #define INCLUDE_IN_RESET 0
595 #define EXCLUDE_FROM_RESET 1
597 /* FPGA build version */
598 #define FCN_ALTERA_BUILD_REG_KER 0x0300
599 #define FCN_VER_MAJOR_LBN 24
600 #define FCN_VER_MAJOR_WIDTH 8
601 #define FCN_VER_MINOR_LBN 16
602 #define FCN_VER_MINOR_WIDTH 8
603 #define FCN_VER_BUILD_LBN 0
604 #define FCN_VER_BUILD_WIDTH 16
605 #define FCN_VER_ALL_LBN 0
606 #define FCN_VER_ALL_WIDTH 32
608 /* Spare EEPROM bits register (flash 0x390) */
609 #define FCN_SPARE_REG_KER 0x310
610 #define FCN_MEM_PERR_EN_TX_DATA_LBN 72
611 #define FCN_MEM_PERR_EN_TX_DATA_WIDTH 2
613 /* Timer table for kernel access */
614 #define FCN_TIMER_CMD_REG_KER 0x420
615 #define FCN_TIMER_MODE_LBN 12
616 #define FCN_TIMER_MODE_WIDTH 2
617 #define FCN_TIMER_MODE_DIS 0
618 #define FCN_TIMER_MODE_INT_HLDOFF 1
619 #define FCN_TIMER_VAL_LBN 0
620 #define FCN_TIMER_VAL_WIDTH 12
622 /* Receive configuration register */
623 #define FCN_RX_CFG_REG_KER 0x800
624 #define FCN_RX_XOFF_EN_LBN 0
625 #define FCN_RX_XOFF_EN_WIDTH 1
627 /* SRAM receive descriptor cache configuration register */
628 #define FCN_SRM_RX_DC_CFG_REG_KER 0x610
629 #define FCN_SRM_RX_DC_BASE_ADR_LBN 0
630 #define FCN_SRM_RX_DC_BASE_ADR_WIDTH 21
632 /* SRAM transmit descriptor cache configuration register */
633 #define FCN_SRM_TX_DC_CFG_REG_KER 0x620
634 #define FCN_SRM_TX_DC_BASE_ADR_LBN 0
635 #define FCN_SRM_TX_DC_BASE_ADR_WIDTH 21
637 /* SRAM configuration register */
638 #define FCN_SRM_CFG_REG_KER 0x630
639 #define FCN_SRAM_OOB_ADR_INTEN_LBN 5
640 #define FCN_SRAM_OOB_ADR_INTEN_WIDTH 1
641 #define FCN_SRAM_OOB_BUF_INTEN_LBN 4
642 #define FCN_SRAM_OOB_BUF_INTEN_WIDTH 1
643 #define FCN_SRAM_OOB_BT_INIT_EN_LBN 3
644 #define FCN_SRAM_OOB_BT_INIT_EN_WIDTH 1
645 #define FCN_SRM_NUM_BANK_LBN 2
646 #define FCN_SRM_NUM_BANK_WIDTH 1
647 #define FCN_SRM_BANK_SIZE_LBN 0
648 #define FCN_SRM_BANK_SIZE_WIDTH 2
649 #define FCN_SRM_NUM_BANKS_AND_BANK_SIZE_LBN 0
650 #define FCN_SRM_NUM_BANKS_AND_BANK_SIZE_WIDTH 3
652 #define FCN_RX_CFG_REG_KER 0x800
653 #define FCN_RX_INGR_EN_B0_LBN 47
654 #define FCN_RX_INGR_EN_B0_WIDTH 1
655 #define FCN_RX_USR_BUF_SIZE_B0_LBN 19
656 #define FCN_RX_USR_BUF_SIZE_B0_WIDTH 9
657 #define FCN_RX_XON_MAC_TH_B0_LBN 10
658 #define FCN_RX_XON_MAC_TH_B0_WIDTH 9
659 #define FCN_RX_XOFF_MAC_TH_B0_LBN 1
660 #define FCN_RX_XOFF_MAC_TH_B0_WIDTH 9
661 #define FCN_RX_XOFF_MAC_EN_B0_LBN 0
662 #define FCN_RX_XOFF_MAC_EN_B0_WIDTH 1
663 #define FCN_RX_USR_BUF_SIZE_A1_LBN 11
664 #define FCN_RX_USR_BUF_SIZE_A1_WIDTH 9
665 #define FCN_RX_XON_MAC_TH_A1_LBN 6
666 #define FCN_RX_XON_MAC_TH_A1_WIDTH 5
667 #define FCN_RX_XOFF_MAC_TH_A1_LBN 1
668 #define FCN_RX_XOFF_MAC_TH_A1_WIDTH 5
669 #define FCN_RX_XOFF_MAC_EN_A1_LBN 0
670 #define FCN_RX_XOFF_MAC_EN_A1_WIDTH 1
672 #define FCN_RX_USR_BUF_SIZE_A1_LBN 11
673 #define FCN_RX_USR_BUF_SIZE_A1_WIDTH 9
674 #define FCN_RX_XOFF_MAC_EN_A1_LBN 0
675 #define FCN_RX_XOFF_MAC_EN_A1_WIDTH 1
677 /* Receive filter control register */
678 #define FCN_RX_FILTER_CTL_REG_KER 0x810
679 #define FCN_UDP_FULL_SRCH_LIMIT_LBN 32
680 #define FCN_UDP_FULL_SRCH_LIMIT_WIDTH 8
681 #define FCN_NUM_KER_LBN 24
682 #define FCN_NUM_KER_WIDTH 2
683 #define FCN_UDP_WILD_SRCH_LIMIT_LBN 16
684 #define FCN_UDP_WILD_SRCH_LIMIT_WIDTH 8
685 #define FCN_TCP_WILD_SRCH_LIMIT_LBN 8
686 #define FCN_TCP_WILD_SRCH_LIMIT_WIDTH 8
687 #define FCN_TCP_FULL_SRCH_LIMIT_LBN 0
688 #define FCN_TCP_FULL_SRCH_LIMIT_WIDTH 8
690 /* RX queue flush register */
691 #define FCN_RX_FLUSH_DESCQ_REG_KER 0x0820
692 #define FCN_RX_FLUSH_DESCQ_CMD_LBN 24
693 #define FCN_RX_FLUSH_DESCQ_CMD_WIDTH 1
694 #define FCN_RX_FLUSH_DESCQ_LBN 0
695 #define FCN_RX_FLUSH_DESCQ_WIDTH 12
697 /* Receive descriptor update register */
698 #define FCN_RX_DESC_UPD_REG_KER 0x0830
699 #define FCN_RX_DESC_WPTR_LBN 96
700 #define FCN_RX_DESC_WPTR_WIDTH 12
701 #define FCN_RX_DESC_UPD_REG_KER_DWORD ( FCN_RX_DESC_UPD_REG_KER + 12 )
702 #define FCN_RX_DESC_WPTR_DWORD_LBN 0
703 #define FCN_RX_DESC_WPTR_DWORD_WIDTH 12
705 /* Receive descriptor cache configuration register */
706 #define FCN_RX_DC_CFG_REG_KER 0x840
707 #define FCN_RX_DC_SIZE_LBN 0
708 #define FCN_RX_DC_SIZE_WIDTH 2
710 #define FCN_RX_SELF_RST_REG_KER 0x890
711 #define FCN_RX_ISCSI_DIS_LBN 17
712 #define FCN_RX_ISCSI_DIS_WIDTH 1
713 #define FCN_RX_NODESC_WAIT_DIS_LBN 9
714 #define FCN_RX_NODESC_WAIT_DIS_WIDTH 1
715 #define FCN_RX_RECOVERY_EN_LBN 8
716 #define FCN_RX_RECOVERY_EN_WIDTH 1
718 /* TX queue flush register */
719 #define FCN_TX_FLUSH_DESCQ_REG_KER 0x0a00
720 #define FCN_TX_FLUSH_DESCQ_CMD_LBN 12
721 #define FCN_TX_FLUSH_DESCQ_CMD_WIDTH 1
722 #define FCN_TX_FLUSH_DESCQ_LBN 0
723 #define FCN_TX_FLUSH_DESCQ_WIDTH 12
725 /* Transmit configuration register 2 */
726 #define FCN_TX_CFG2_REG_KER 0xa80
727 #define FCN_TX_DIS_NON_IP_EV_LBN 17
728 #define FCN_TX_DIS_NON_IP_EV_WIDTH 1
730 /* Transmit descriptor update register */
731 #define FCN_TX_DESC_UPD_REG_KER 0x0a10
732 #define FCN_TX_DESC_WPTR_LBN 96
733 #define FCN_TX_DESC_WPTR_WIDTH 12
734 #define FCN_TX_DESC_UPD_REG_KER_DWORD ( FCN_TX_DESC_UPD_REG_KER + 12 )
735 #define FCN_TX_DESC_WPTR_DWORD_LBN 0
736 #define FCN_TX_DESC_WPTR_DWORD_WIDTH 12
738 /* Transmit descriptor cache configuration register */
739 #define FCN_TX_DC_CFG_REG_KER 0xa20
740 #define FCN_TX_DC_SIZE_LBN 0
741 #define FCN_TX_DC_SIZE_WIDTH 2
743 /* PHY management transmit data register */
744 #define FCN_MD_TXD_REG_KER 0xc00
745 #define FCN_MD_TXD_LBN 0
746 #define FCN_MD_TXD_WIDTH 16
748 /* PHY management receive data register */
749 #define FCN_MD_RXD_REG_KER 0xc10
750 #define FCN_MD_RXD_LBN 0
751 #define FCN_MD_RXD_WIDTH 16
753 /* PHY management configuration & status register */
754 #define FCN_MD_CS_REG_KER 0xc20
755 #define FCN_MD_GC_LBN 4
756 #define FCN_MD_GC_WIDTH 1
757 #define FCN_MD_RIC_LBN 2
758 #define FCN_MD_RIC_WIDTH 1
759 #define FCN_MD_RDC_LBN 1
760 #define FCN_MD_RDC_WIDTH 1
761 #define FCN_MD_WRC_LBN 0
762 #define FCN_MD_WRC_WIDTH 1
764 /* PHY management PHY address register */
765 #define FCN_MD_PHY_ADR_REG_KER 0xc30
766 #define FCN_MD_PHY_ADR_LBN 0
767 #define FCN_MD_PHY_ADR_WIDTH 16
769 /* PHY management ID register */
770 #define FCN_MD_ID_REG_KER 0xc40
771 #define FCN_MD_PRT_ADR_LBN 11
772 #define FCN_MD_PRT_ADR_WIDTH 5
773 #define FCN_MD_DEV_ADR_LBN 6
774 #define FCN_MD_DEV_ADR_WIDTH 5
776 /* PHY management status & mask register */
777 #define FCN_MD_STAT_REG_KER 0xc50
778 #define FCN_MD_PINT_LBN 4
779 #define FCN_MD_PINT_WIDTH 1
780 #define FCN_MD_DONE_LBN 3
781 #define FCN_MD_DONE_WIDTH 1
782 #define FCN_MD_BSERR_LBN 2
783 #define FCN_MD_BSERR_WIDTH 1
784 #define FCN_MD_LNFL_LBN 1
785 #define FCN_MD_LNFL_WIDTH 1
786 #define FCN_MD_BSY_LBN 0
787 #define FCN_MD_BSY_WIDTH 1
789 /* Port 0 and 1 MAC control registers */
790 #define FCN_MAC0_CTRL_REG_KER 0xc80
791 #define FCN_MAC1_CTRL_REG_KER 0xc90
792 #define FCN_MAC_XOFF_VAL_LBN 16
793 #define FCN_MAC_XOFF_VAL_WIDTH 16
794 #define FCN_MAC_BCAD_ACPT_LBN 4
795 #define FCN_MAC_BCAD_ACPT_WIDTH 1
796 #define FCN_MAC_UC_PROM_LBN 3
797 #define FCN_MAC_UC_PROM_WIDTH 1
798 #define FCN_MAC_LINK_STATUS_LBN 2
799 #define FCN_MAC_LINK_STATUS_WIDTH 1
800 #define FCN_MAC_SPEED_LBN 0
801 #define FCN_MAC_SPEED_WIDTH 2
803 /* 10Gig Xaui XGXS Default Values */
804 #define XX_TXDRV_DEQ_DEFAULT 0xe /* deq=.6 */
805 #define XX_TXDRV_DTX_DEFAULT 0x5 /* 1.25 */
806 #define XX_SD_CTL_DRV_DEFAULT 0 /* 20mA */
809 #define FALCON_GMAC_REGBANK 0xe00
810 #define FALCON_GMAC_REGBANK_SIZE 0x200
811 #define FALCON_GMAC_REG_SIZE 0x10
813 /* XGMAC registers */
814 #define FALCON_XMAC_REGBANK 0x1200
815 #define FALCON_XMAC_REGBANK_SIZE 0x200
816 #define FALCON_XMAC_REG_SIZE 0x10
818 /* XGMAC address register low */
819 #define FCN_XM_ADR_LO_REG_MAC 0x00
820 #define FCN_XM_ADR_3_LBN 24
821 #define FCN_XM_ADR_3_WIDTH 8
822 #define FCN_XM_ADR_2_LBN 16
823 #define FCN_XM_ADR_2_WIDTH 8
824 #define FCN_XM_ADR_1_LBN 8
825 #define FCN_XM_ADR_1_WIDTH 8
826 #define FCN_XM_ADR_0_LBN 0
827 #define FCN_XM_ADR_0_WIDTH 8
829 /* XGMAC address register high */
830 #define FCN_XM_ADR_HI_REG_MAC 0x01
831 #define FCN_XM_ADR_5_LBN 8
832 #define FCN_XM_ADR_5_WIDTH 8
833 #define FCN_XM_ADR_4_LBN 0
834 #define FCN_XM_ADR_4_WIDTH 8
836 /* XGMAC global configuration - port 0*/
837 #define FCN_XM_GLB_CFG_REG_MAC 0x02
838 #define FCN_XM_RX_STAT_EN_LBN 11
839 #define FCN_XM_RX_STAT_EN_WIDTH 1
840 #define FCN_XM_TX_STAT_EN_LBN 10
841 #define FCN_XM_TX_STAT_EN_WIDTH 1
842 #define FCN_XM_RX_JUMBO_MODE_LBN 6
843 #define FCN_XM_RX_JUMBO_MODE_WIDTH 1
844 #define FCN_XM_CORE_RST_LBN 0
845 #define FCN_XM_CORE_RST_WIDTH 1
847 /* XGMAC transmit configuration - port 0 */
848 #define FCN_XM_TX_CFG_REG_MAC 0x03
849 #define FCN_XM_IPG_LBN 16
850 #define FCN_XM_IPG_WIDTH 4
851 #define FCN_XM_FCNTL_LBN 10
852 #define FCN_XM_FCNTL_WIDTH 1
853 #define FCN_XM_TXCRC_LBN 8
854 #define FCN_XM_TXCRC_WIDTH 1
855 #define FCN_XM_AUTO_PAD_LBN 5
856 #define FCN_XM_AUTO_PAD_WIDTH 1
857 #define FCN_XM_TX_PRMBL_LBN 2
858 #define FCN_XM_TX_PRMBL_WIDTH 1
859 #define FCN_XM_TXEN_LBN 1
860 #define FCN_XM_TXEN_WIDTH 1
862 /* XGMAC receive configuration - port 0 */
863 #define FCN_XM_RX_CFG_REG_MAC 0x04
864 #define FCN_XM_PASS_CRC_ERR_LBN 25
865 #define FCN_XM_PASS_CRC_ERR_WIDTH 1
866 #define FCN_XM_AUTO_DEPAD_LBN 8
867 #define FCN_XM_AUTO_DEPAD_WIDTH 1
868 #define FCN_XM_RXEN_LBN 1
869 #define FCN_XM_RXEN_WIDTH 1
871 /* XGMAC management interrupt mask register */
872 #define FCN_XM_MGT_INT_MSK_REG_MAC_B0 0x5
873 #define FCN_XM_MSK_PRMBLE_ERR_LBN 2
874 #define FCN_XM_MSK_PRMBLE_ERR_WIDTH 1
875 #define FCN_XM_MSK_RMTFLT_LBN 1
876 #define FCN_XM_MSK_RMTFLT_WIDTH 1
877 #define FCN_XM_MSK_LCLFLT_LBN 0
878 #define FCN_XM_MSK_LCLFLT_WIDTH 1
880 /* XGMAC flow control register */
881 #define FCN_XM_FC_REG_MAC 0x7
882 #define FCN_XM_PAUSE_TIME_LBN 16
883 #define FCN_XM_PAUSE_TIME_WIDTH 16
884 #define FCN_XM_DIS_FCNTL_LBN 0
885 #define FCN_XM_DIS_FCNTL_WIDTH 1
887 /* XGMAC transmit parameter register */
888 #define FCN_XM_TX_PARAM_REG_MAC 0x0d
889 #define FCN_XM_TX_JUMBO_MODE_LBN 31
890 #define FCN_XM_TX_JUMBO_MODE_WIDTH 1
891 #define FCN_XM_MAX_TX_FRM_SIZE_LBN 16
892 #define FCN_XM_MAX_TX_FRM_SIZE_WIDTH 14
893 #define FCN_XM_ACPT_ALL_MCAST_LBN 11
894 #define FCN_XM_ACPT_ALL_MCAST_WIDTH 1
896 /* XGMAC receive parameter register */
897 #define FCN_XM_RX_PARAM_REG_MAC 0x0e
898 #define FCN_XM_MAX_RX_FRM_SIZE_LBN 0
899 #define FCN_XM_MAX_RX_FRM_SIZE_WIDTH 14
901 /* XGMAC management interrupt status register */
902 #define FCN_XM_MGT_INT_REG_MAC_B0 0x0f
903 #define FCN_XM_PRMBLE_ERR 2
904 #define FCN_XM_PRMBLE_WIDTH 1
905 #define FCN_XM_RMTFLT_LBN 1
906 #define FCN_XM_RMTFLT_WIDTH 1
907 #define FCN_XM_LCLFLT_LBN 0
908 #define FCN_XM_LCLFLT_WIDTH 1
910 /* XAUI XGXS core status register */
911 #define FCN_XX_ALIGN_DONE_LBN 20
912 #define FCN_XX_ALIGN_DONE_WIDTH 1
913 #define FCN_XX_CORE_STAT_REG_MAC 0x16
914 #define FCN_XX_SYNC_STAT_LBN 16
915 #define FCN_XX_SYNC_STAT_WIDTH 4
916 #define FCN_XX_SYNC_STAT_DECODE_SYNCED 0xf
917 #define FCN_XX_COMMA_DET_LBN 12
918 #define FCN_XX_COMMA_DET_WIDTH 4
919 #define FCN_XX_COMMA_DET_RESET 0xf
920 #define FCN_XX_CHARERR_LBN 4
921 #define FCN_XX_CHARERR_WIDTH 4
922 #define FCN_XX_CHARERR_RESET 0xf
923 #define FCN_XX_DISPERR_LBN 0
924 #define FCN_XX_DISPERR_WIDTH 4
925 #define FCN_XX_DISPERR_RESET 0xf
927 /* XGXS/XAUI powerdown/reset register */
928 #define FCN_XX_PWR_RST_REG_MAC 0x10
929 #define FCN_XX_PWRDND_EN_LBN 15
930 #define FCN_XX_PWRDND_EN_WIDTH 1
931 #define FCN_XX_PWRDNC_EN_LBN 14
932 #define FCN_XX_PWRDNC_EN_WIDTH 1
933 #define FCN_XX_PWRDNB_EN_LBN 13
934 #define FCN_XX_PWRDNB_EN_WIDTH 1
935 #define FCN_XX_PWRDNA_EN_LBN 12
936 #define FCN_XX_PWRDNA_EN_WIDTH 1
937 #define FCN_XX_RSTPLLCD_EN_LBN 9
938 #define FCN_XX_RSTPLLCD_EN_WIDTH 1
939 #define FCN_XX_RSTPLLAB_EN_LBN 8
940 #define FCN_XX_RSTPLLAB_EN_WIDTH 1
941 #define FCN_XX_RESETD_EN_LBN 7
942 #define FCN_XX_RESETD_EN_WIDTH 1
943 #define FCN_XX_RESETC_EN_LBN 6
944 #define FCN_XX_RESETC_EN_WIDTH 1
945 #define FCN_XX_RESETB_EN_LBN 5
946 #define FCN_XX_RESETB_EN_WIDTH 1
947 #define FCN_XX_RESETA_EN_LBN 4
948 #define FCN_XX_RESETA_EN_WIDTH 1
949 #define FCN_XX_RSTXGXSRX_EN_LBN 2
950 #define FCN_XX_RSTXGXSRX_EN_WIDTH 1
951 #define FCN_XX_RSTXGXSTX_EN_LBN 1
952 #define FCN_XX_RSTXGXSTX_EN_WIDTH 1
953 #define FCN_XX_RST_XX_EN_LBN 0
954 #define FCN_XX_RST_XX_EN_WIDTH 1
957 /* XGXS/XAUI powerdown/reset control register */
958 #define FCN_XX_SD_CTL_REG_MAC 0x11
959 #define FCN_XX_TERMADJ1_LBN 17
960 #define FCN_XX_TERMADJ1_WIDTH 1
961 #define FCN_XX_TERMADJ0_LBN 16
962 #define FCN_XX_TERMADJ0_WIDTH 1
963 #define FCN_XX_HIDRVD_LBN 15
964 #define FCN_XX_HIDRVD_WIDTH 1
965 #define FCN_XX_LODRVD_LBN 14
966 #define FCN_XX_LODRVD_WIDTH 1
967 #define FCN_XX_HIDRVC_LBN 13
968 #define FCN_XX_HIDRVC_WIDTH 1
969 #define FCN_XX_LODRVC_LBN 12
970 #define FCN_XX_LODRVC_WIDTH 1
971 #define FCN_XX_HIDRVB_LBN 11
972 #define FCN_XX_HIDRVB_WIDTH 1
973 #define FCN_XX_LODRVB_LBN 10
974 #define FCN_XX_LODRVB_WIDTH 1
975 #define FCN_XX_HIDRVA_LBN 9
976 #define FCN_XX_HIDRVA_WIDTH 1
977 #define FCN_XX_LODRVA_LBN 8
978 #define FCN_XX_LODRVA_WIDTH 1
979 #define FCN_XX_LPBKD_LBN 3
980 #define FCN_XX_LPBKD_WIDTH 1
981 #define FCN_XX_LPBKC_LBN 2
982 #define FCN_XX_LPBKC_WIDTH 1
983 #define FCN_XX_LPBKB_LBN 1
984 #define FCN_XX_LPBKB_WIDTH 1
985 #define FCN_XX_LPBKA_LBN 0
986 #define FCN_XX_LPBKA_WIDTH 1
988 #define FCN_XX_TXDRV_CTL_REG_MAC 0x12
989 #define FCN_XX_DEQD_LBN 28
990 #define FCN_XX_DEQD_WIDTH 4
991 #define FCN_XX_DEQC_LBN 24
992 #define FCN_XX_DEQC_WIDTH 4
993 #define FCN_XX_DEQB_LBN 20
994 #define FCN_XX_DEQB_WIDTH 4
995 #define FCN_XX_DEQA_LBN 16
996 #define FCN_XX_DEQA_WIDTH 4
997 #define FCN_XX_DTXD_LBN 12
998 #define FCN_XX_DTXD_WIDTH 4
999 #define FCN_XX_DTXC_LBN 8
1000 #define FCN_XX_DTXC_WIDTH 4
1001 #define FCN_XX_DTXB_LBN 4
1002 #define FCN_XX_DTXB_WIDTH 4
1003 #define FCN_XX_DTXA_LBN 0
1004 #define FCN_XX_DTXA_WIDTH 4
1006 /* Receive filter table */
1007 #define FCN_RX_FILTER_TBL0 0xF00000
1009 /* Receive descriptor pointer table */
1010 #define FCN_RX_DESC_PTR_TBL_KER_A1 0x11800
1011 #define FCN_RX_DESC_PTR_TBL_KER_B0 0xF40000
1012 #define FCN_RX_ISCSI_DDIG_EN_LBN 88
1013 #define FCN_RX_ISCSI_DDIG_EN_WIDTH 1
1014 #define FCN_RX_ISCSI_HDIG_EN_LBN 87
1015 #define FCN_RX_ISCSI_HDIG_EN_WIDTH 1
1016 #define FCN_RX_DESCQ_BUF_BASE_ID_LBN 36
1017 #define FCN_RX_DESCQ_BUF_BASE_ID_WIDTH 20
1018 #define FCN_RX_DESCQ_EVQ_ID_LBN 24
1019 #define FCN_RX_DESCQ_EVQ_ID_WIDTH 12
1020 #define FCN_RX_DESCQ_OWNER_ID_LBN 10
1021 #define FCN_RX_DESCQ_OWNER_ID_WIDTH 14
1022 #define FCN_RX_DESCQ_SIZE_LBN 3
1023 #define FCN_RX_DESCQ_SIZE_WIDTH 2
1024 #define FCN_RX_DESCQ_SIZE_4K 3
1025 #define FCN_RX_DESCQ_SIZE_2K 2
1026 #define FCN_RX_DESCQ_SIZE_1K 1
1027 #define FCN_RX_DESCQ_SIZE_512 0
1028 #define FCN_RX_DESCQ_TYPE_LBN 2
1029 #define FCN_RX_DESCQ_TYPE_WIDTH 1
1030 #define FCN_RX_DESCQ_JUMBO_LBN 1
1031 #define FCN_RX_DESCQ_JUMBO_WIDTH 1
1032 #define FCN_RX_DESCQ_EN_LBN 0
1033 #define FCN_RX_DESCQ_EN_WIDTH 1
1035 /* Transmit descriptor pointer table */
1036 #define FCN_TX_DESC_PTR_TBL_KER_A1 0x11900
1037 #define FCN_TX_DESC_PTR_TBL_KER_B0 0xF50000
1038 #define FCN_TX_NON_IP_DROP_DIS_B0_LBN 91
1039 #define FCN_TX_NON_IP_DROP_DIS_B0_WIDTH 1
1040 #define FCN_TX_DESCQ_EN_LBN 88
1041 #define FCN_TX_DESCQ_EN_WIDTH 1
1042 #define FCN_TX_ISCSI_DDIG_EN_LBN 87
1043 #define FCN_TX_ISCSI_DDIG_EN_WIDTH 1
1044 #define FCN_TX_ISCSI_HDIG_EN_LBN 86
1045 #define FCN_TX_ISCSI_HDIG_EN_WIDTH 1
1046 #define FCN_TX_DESCQ_BUF_BASE_ID_LBN 36
1047 #define FCN_TX_DESCQ_BUF_BASE_ID_WIDTH 20
1048 #define FCN_TX_DESCQ_EVQ_ID_LBN 24
1049 #define FCN_TX_DESCQ_EVQ_ID_WIDTH 12
1050 #define FCN_TX_DESCQ_OWNER_ID_LBN 10
1051 #define FCN_TX_DESCQ_OWNER_ID_WIDTH 14
1052 #define FCN_TX_DESCQ_SIZE_LBN 3
1053 #define FCN_TX_DESCQ_SIZE_WIDTH 2
1054 #define FCN_TX_DESCQ_SIZE_4K 3
1055 #define FCN_TX_DESCQ_SIZE_2K 2
1056 #define FCN_TX_DESCQ_SIZE_1K 1
1057 #define FCN_TX_DESCQ_SIZE_512 0
1058 #define FCN_TX_DESCQ_TYPE_LBN 1
1059 #define FCN_TX_DESCQ_TYPE_WIDTH 2
1060 #define FCN_TX_DESCQ_FLUSH_LBN 0
1061 #define FCN_TX_DESCQ_FLUSH_WIDTH 1
1063 /* Event queue pointer */
1064 #define FCN_EVQ_PTR_TBL_KER_A1 0x11a00
1065 #define FCN_EVQ_PTR_TBL_KER_B0 0xf60000
1066 #define FCN_EVQ_EN_LBN 23
1067 #define FCN_EVQ_EN_WIDTH 1
1068 #define FCN_EVQ_SIZE_LBN 20
1069 #define FCN_EVQ_SIZE_WIDTH 3
1070 #define FCN_EVQ_SIZE_32K 6
1071 #define FCN_EVQ_SIZE_16K 5
1072 #define FCN_EVQ_SIZE_8K 4
1073 #define FCN_EVQ_SIZE_4K 3
1074 #define FCN_EVQ_SIZE_2K 2
1075 #define FCN_EVQ_SIZE_1K 1
1076 #define FCN_EVQ_SIZE_512 0
1077 #define FCN_EVQ_BUF_BASE_ID_LBN 0
1078 #define FCN_EVQ_BUF_BASE_ID_WIDTH 20
1080 /* RSS indirection table */
1081 #define FCN_RX_RSS_INDIR_TBL_B0 0xFB0000
1083 /* Event queue read pointer */
1084 #define FCN_EVQ_RPTR_REG_KER_A1 0x11b00
1085 #define FCN_EVQ_RPTR_REG_KER_B0 0xfa0000
1086 #define FCN_EVQ_RPTR_LBN 0
1087 #define FCN_EVQ_RPTR_WIDTH 14
1088 #define FCN_EVQ_RPTR_REG_KER_DWORD_A1 ( FCN_EVQ_RPTR_REG_KER_A1 + 0 )
1089 #define FCN_EVQ_RPTR_REG_KER_DWORD_B0 ( FCN_EVQ_RPTR_REG_KER_B0 + 0 )
1090 #define FCN_EVQ_RPTR_DWORD_LBN 0
1091 #define FCN_EVQ_RPTR_DWORD_WIDTH 14
1093 /* Special buffer descriptors */
1094 #define FCN_BUF_FULL_TBL_KER_A1 0x18000
1095 #define FCN_BUF_FULL_TBL_KER_B0 0x800000
1096 #define FCN_IP_DAT_BUF_SIZE_LBN 50
1097 #define FCN_IP_DAT_BUF_SIZE_WIDTH 1
1098 #define FCN_IP_DAT_BUF_SIZE_8K 1
1099 #define FCN_IP_DAT_BUF_SIZE_4K 0
1100 #define FCN_BUF_ADR_FBUF_LBN 14
1101 #define FCN_BUF_ADR_FBUF_WIDTH 34
1102 #define FCN_BUF_OWNER_ID_FBUF_LBN 0
1103 #define FCN_BUF_OWNER_ID_FBUF_WIDTH 14
1105 /** Offset of a GMAC register within Falcon */
1106 #define FALCON_GMAC_REG( efab, mac_reg ) \
1107 ( FALCON_GMAC_REGBANK + \
1108 ( (mac_reg) * FALCON_GMAC_REG_SIZE ) )
1110 /** Offset of an XMAC register within Falcon */
1111 #define FALCON_XMAC_REG( efab_port, mac_reg ) \
1112 ( FALCON_XMAC_REGBANK + \
1113 ( (mac_reg) * FALCON_XMAC_REG_SIZE ) )
1115 #define FCN_MAC_DATA_LBN 0
1116 #define FCN_MAC_DATA_WIDTH 32
1118 /* Transmit descriptor */
1119 #define FCN_TX_KER_PORT_LBN 63
1120 #define FCN_TX_KER_PORT_WIDTH 1
1121 #define FCN_TX_KER_BYTE_CNT_LBN 48
1122 #define FCN_TX_KER_BYTE_CNT_WIDTH 14
1123 #define FCN_TX_KER_BUF_ADR_LBN 0
1124 #define FCN_TX_KER_BUF_ADR_WIDTH EFAB_DMA_TYPE_WIDTH ( 46 )
1127 /* Receive descriptor */
1128 #define FCN_RX_KER_BUF_SIZE_LBN 48
1129 #define FCN_RX_KER_BUF_SIZE_WIDTH 14
1130 #define FCN_RX_KER_BUF_ADR_LBN 0
1131 #define FCN_RX_KER_BUF_ADR_WIDTH EFAB_DMA_TYPE_WIDTH ( 46 )
1133 /* Event queue entries */
1134 #define FCN_EV_CODE_LBN 60
1135 #define FCN_EV_CODE_WIDTH 4
1136 #define FCN_RX_IP_EV_DECODE 0
1137 #define FCN_TX_IP_EV_DECODE 2
1138 #define FCN_DRIVER_EV_DECODE 5
1140 /* Receive events */
1141 #define FCN_RX_EV_PKT_OK_LBN 56
1142 #define FCN_RX_EV_PKT_OK_WIDTH 1
1143 #define FCN_RX_PORT_LBN 30
1144 #define FCN_RX_PORT_WIDTH 1
1145 #define FCN_RX_EV_BYTE_CNT_LBN 16
1146 #define FCN_RX_EV_BYTE_CNT_WIDTH 14
1147 #define FCN_RX_EV_DESC_PTR_LBN 0
1148 #define FCN_RX_EV_DESC_PTR_WIDTH 12
1150 /* Transmit events */
1151 #define FCN_TX_EV_DESC_PTR_LBN 0
1152 #define FCN_TX_EV_DESC_PTR_WIDTH 12
1154 /*******************************************************************************
1157 * Low-level hardware access
1160 *******************************************************************************/
1162 #define FCN_REVISION_REG(efab, reg) \
1163 ( ( efab->pci_revision == FALCON_REV_B0 ) ? reg ## _B0 : reg ## _A1 )
1165 #define EFAB_SET_OWORD_FIELD_VER(efab, reg, field, val) \
1166 if ( efab->pci_revision == FALCON_REV_B0 ) \
1167 EFAB_SET_OWORD_FIELD ( reg, field ## _B0, val ); \
1169 EFAB_SET_OWORD_FIELD ( reg, field ## _A1, val );
1171 #if FALCON_USE_IO_BAR
1173 /* Write dword via the I/O BAR */
1174 static inline void _falcon_writel ( struct efab_nic *efab, uint32_t value,
1175 unsigned int reg ) {
1176 outl ( reg, efab->iobase + FCN_IOM_IND_ADR_REG );
1177 outl ( value, efab->iobase + FCN_IOM_IND_DAT_REG );
1180 /* Read dword via the I/O BAR */
1181 static inline uint32_t _falcon_readl ( struct efab_nic *efab,
1182 unsigned int reg ) {
1183 outl ( reg, efab->iobase + FCN_IOM_IND_ADR_REG );
1184 return inl ( efab->iobase + FCN_IOM_IND_DAT_REG );
1187 #else /* FALCON_USE_IO_BAR */
1189 #define _falcon_writel( efab, value, reg ) \
1190 writel ( (value), (efab)->membase + (reg) )
1191 #define _falcon_readl( efab, reg ) readl ( (efab)->membase + (reg) )
1193 #endif /* FALCON_USE_IO_BAR */
1196 * Write to a Falcon register
1200 falcon_write ( struct efab_nic *efab, efab_oword_t *value, unsigned int reg )
1203 EFAB_REGDUMP ( "Writing register %x with " EFAB_OWORD_FMT "\n",
1204 reg, EFAB_OWORD_VAL ( *value ) );
1206 _falcon_writel ( efab, value->u32[0], reg + 0 );
1207 _falcon_writel ( efab, value->u32[1], reg + 4 );
1208 _falcon_writel ( efab, value->u32[2], reg + 8 );
1210 _falcon_writel ( efab, value->u32[3], reg + 12 );
1215 * Write to Falcon SRAM
1219 falcon_write_sram ( struct efab_nic *efab, efab_qword_t *value,
1220 unsigned int index )
1222 unsigned int reg = ( FCN_REVISION_REG ( efab, FCN_BUF_FULL_TBL_KER ) +
1223 ( index * sizeof ( *value ) ) );
1225 EFAB_REGDUMP ( "Writing SRAM register %x with " EFAB_QWORD_FMT "\n",
1226 reg, EFAB_QWORD_VAL ( *value ) );
1228 _falcon_writel ( efab, value->u32[0], reg + 0 );
1229 _falcon_writel ( efab, value->u32[1], reg + 4 );
1234 * Write dword to Falcon register that allows partial writes
1238 falcon_writel ( struct efab_nic *efab, efab_dword_t *value, unsigned int reg )
1240 EFAB_REGDUMP ( "Writing partial register %x with " EFAB_DWORD_FMT "\n",
1241 reg, EFAB_DWORD_VAL ( *value ) );
1242 _falcon_writel ( efab, value->u32[0], reg );
1246 * Read from a Falcon register
1250 falcon_read ( struct efab_nic *efab, efab_oword_t *value, unsigned int reg )
1252 value->u32[0] = _falcon_readl ( efab, reg + 0 );
1254 value->u32[1] = _falcon_readl ( efab, reg + 4 );
1255 value->u32[2] = _falcon_readl ( efab, reg + 8 );
1256 value->u32[3] = _falcon_readl ( efab, reg + 12 );
1258 EFAB_REGDUMP ( "Read from register %x, got " EFAB_OWORD_FMT "\n",
1259 reg, EFAB_OWORD_VAL ( *value ) );
1263 * Read from Falcon SRAM
1267 falcon_read_sram ( struct efab_nic *efab, efab_qword_t *value,
1268 unsigned int index )
1270 unsigned int reg = ( FCN_REVISION_REG ( efab, FCN_BUF_FULL_TBL_KER ) +
1271 ( index * sizeof ( *value ) ) );
1273 value->u32[0] = _falcon_readl ( efab, reg + 0 );
1274 value->u32[1] = _falcon_readl ( efab, reg + 4 );
1275 EFAB_REGDUMP ( "Read from SRAM register %x, got " EFAB_QWORD_FMT "\n",
1276 reg, EFAB_QWORD_VAL ( *value ) );
1280 * Read dword from a portion of a Falcon register
1284 falcon_readl ( struct efab_nic *efab, efab_dword_t *value, unsigned int reg )
1286 value->u32[0] = _falcon_readl ( efab, reg );
1287 EFAB_REGDUMP ( "Read from register %x, got " EFAB_DWORD_FMT "\n",
1288 reg, EFAB_DWORD_VAL ( *value ) );
1291 #define FCN_DUMP_REG( efab, _reg ) do { \
1293 falcon_read ( efab, ®, _reg ); \
1294 EFAB_LOG ( #_reg " = " EFAB_OWORD_FMT "\n", \
1295 EFAB_OWORD_VAL ( reg ) ); \
1298 #define FCN_DUMP_MAC_REG( efab, _mac_reg ) do { \
1300 efab->mac_op->mac_readl ( efab, ®, _mac_reg ); \
1301 EFAB_LOG ( #_mac_reg " = " EFAB_DWORD_FMT "\n", \
1302 EFAB_DWORD_VAL ( reg ) ); \
1306 * See if an event is present
1308 * @v event Falcon event structure
1309 * @ret True An event is pending
1310 * @ret False No event is pending
1312 * We check both the high and low dword of the event for all ones. We
1313 * wrote all ones when we cleared the event, and no valid event can
1314 * have all ones in either its high or low dwords. This approach is
1315 * robust against reordering.
1317 * Note that using a single 64-bit comparison is incorrect; even
1318 * though the CPU read will be atomic, the DMA write may not be.
1321 falcon_event_present ( falcon_event_t* event )
1323 return ( ! ( EFAB_DWORD_IS_ALL_ONES ( event->dword[0] ) |
1324 EFAB_DWORD_IS_ALL_ONES ( event->dword[1] ) ) );
1328 falcon_eventq_read_ack ( struct efab_nic *efab, struct efab_ev_queue *ev_queue )
1332 EFAB_POPULATE_DWORD_1 ( reg, FCN_EVQ_RPTR_DWORD, ev_queue->read_ptr );
1333 falcon_writel ( efab, ®,
1334 FCN_REVISION_REG ( efab, FCN_EVQ_RPTR_REG_KER_DWORD ) );
1339 * Dump register contents (for debugging)
1341 * Marked as static inline so that it will not be compiled in if not
1345 falcon_dump_regs ( struct efab_nic *efab )
1347 FCN_DUMP_REG ( efab, FCN_INT_EN_REG_KER );
1348 FCN_DUMP_REG ( efab, FCN_INT_ADR_REG_KER );
1349 FCN_DUMP_REG ( efab, FCN_GLB_CTL_REG_KER );
1350 FCN_DUMP_REG ( efab, FCN_TIMER_CMD_REG_KER );
1351 FCN_DUMP_REG ( efab, FCN_SRM_RX_DC_CFG_REG_KER );
1352 FCN_DUMP_REG ( efab, FCN_SRM_TX_DC_CFG_REG_KER );
1353 FCN_DUMP_REG ( efab, FCN_RX_FILTER_CTL_REG_KER );
1354 FCN_DUMP_REG ( efab, FCN_RX_DC_CFG_REG_KER );
1355 FCN_DUMP_REG ( efab, FCN_TX_DC_CFG_REG_KER );
1356 FCN_DUMP_REG ( efab, FCN_MAC0_CTRL_REG_KER );
1357 FCN_DUMP_REG ( efab, FCN_MAC1_CTRL_REG_KER );
1358 FCN_DUMP_REG ( efab, FCN_REVISION_REG ( efab, FCN_RX_DESC_PTR_TBL_KER ) );
1359 FCN_DUMP_REG ( efab, FCN_REVISION_REG ( efab, FCN_TX_DESC_PTR_TBL_KER ) );
1360 FCN_DUMP_REG ( efab, FCN_REVISION_REG ( efab, FCN_EVQ_PTR_TBL_KER ) );
1361 FCN_DUMP_MAC_REG ( efab, GM_CFG1_REG_MAC );
1362 FCN_DUMP_MAC_REG ( efab, GM_CFG2_REG_MAC );
1363 FCN_DUMP_MAC_REG ( efab, GM_MAX_FLEN_REG_MAC );
1364 FCN_DUMP_MAC_REG ( efab, GM_MII_MGMT_CFG_REG_MAC );
1365 FCN_DUMP_MAC_REG ( efab, GM_ADR1_REG_MAC );
1366 FCN_DUMP_MAC_REG ( efab, GM_ADR2_REG_MAC );
1367 FCN_DUMP_MAC_REG ( efab, GMF_CFG0_REG_MAC );
1368 FCN_DUMP_MAC_REG ( efab, GMF_CFG1_REG_MAC );
1369 FCN_DUMP_MAC_REG ( efab, GMF_CFG2_REG_MAC );
1370 FCN_DUMP_MAC_REG ( efab, GMF_CFG3_REG_MAC );
1371 FCN_DUMP_MAC_REG ( efab, GMF_CFG4_REG_MAC );
1372 FCN_DUMP_MAC_REG ( efab, GMF_CFG5_REG_MAC );
1377 falcon_interrupts ( struct efab_nic *efab, int enabled, int force )
1379 efab_oword_t int_en_reg_ker;
1381 EFAB_POPULATE_OWORD_2 ( int_en_reg_ker,
1382 FCN_KER_INT_KER, force,
1383 FCN_DRV_INT_EN_KER, enabled );
1384 falcon_write ( efab, &int_en_reg_ker, FCN_INT_EN_REG_KER );
1387 /*******************************************************************************
1393 *******************************************************************************/
1396 /** Maximum length for a single SPI transaction */
1397 #define FALCON_SPI_MAX_LEN 16
1400 falcon_spi_wait ( struct efab_nic *efab )
1408 falcon_read ( efab, ®, FCN_EE_SPI_HCMD_REG );
1409 if ( EFAB_OWORD_FIELD ( reg, FCN_EE_SPI_HCMD_CMD_EN ) == 0 )
1411 } while ( ++count < 1000 );
1413 EFAB_ERR ( "Timed out waiting for SPI\n" );
1418 falcon_spi_rw ( struct spi_bus* bus, struct spi_device *device,
1419 unsigned int command, int address,
1420 const void* data_out, void *data_in, size_t len )
1422 struct efab_nic *efab = container_of ( bus, struct efab_nic, spi_bus );
1423 int address_len, rc, device_id, read_cmd;
1426 /* falcon_init_spi_device() should have reduced the block size
1427 * down so this constraint holds */
1428 assert ( len <= FALCON_SPI_MAX_LEN );
1430 /* Is this the FLASH or EEPROM device? */
1431 if ( device == &efab->spi_flash )
1432 device_id = FCN_EE_SPI_FLASH;
1433 else if ( device == &efab->spi_eeprom )
1434 device_id = FCN_EE_SPI_EEPROM;
1436 EFAB_ERR ( "Unknown device %p\n", device );
1440 EFAB_TRACE ( "Executing spi command %d on device %d at %d for %zd bytes\n",
1441 command, device_id, address, len );
1443 /* The bus must be idle */
1444 rc = falcon_spi_wait ( efab );
1450 memcpy ( ®, data_out, len );
1451 falcon_write ( efab, ®, FCN_EE_SPI_HDATA_REG );
1454 /* Program address register */
1455 if ( address >= 0 ) {
1456 EFAB_POPULATE_OWORD_1 ( reg, FCN_EE_SPI_HADR_ADR, address );
1457 falcon_write ( efab, ®, FCN_EE_SPI_HADR_REG );
1461 address_len = ( address >= 0 ) ? device->address_len / 8 : 0;
1462 read_cmd = ( data_in ? FCN_EE_SPI_READ : FCN_EE_SPI_WRITE );
1463 EFAB_POPULATE_OWORD_7 ( reg,
1464 FCN_EE_SPI_HCMD_CMD_EN, 1,
1465 FCN_EE_SPI_HCMD_SF_SEL, device_id,
1466 FCN_EE_SPI_HCMD_DABCNT, len,
1467 FCN_EE_SPI_HCMD_READ, read_cmd,
1468 FCN_EE_SPI_HCMD_DUBCNT, 0,
1469 FCN_EE_SPI_HCMD_ADBCNT, address_len,
1470 FCN_EE_SPI_HCMD_ENC, command );
1471 falcon_write ( efab, ®, FCN_EE_SPI_HCMD_REG );
1473 /* Wait for the command to complete */
1474 rc = falcon_spi_wait ( efab );
1480 falcon_read ( efab, ®, FCN_EE_SPI_HDATA_REG );
1481 memcpy ( data_in, ®, len );
1488 EFAB_ERR ( "Failed SPI command %d to device %d address 0x%x len 0x%zx\n",
1489 command, device_id, address, len );
1494 /*******************************************************************************
1497 * Falcon bit-bashed I2C interface
1500 *******************************************************************************/
1503 falcon_i2c_bit_write ( struct bit_basher *basher, unsigned int bit_id,
1504 unsigned long data )
1506 struct efab_nic *efab = container_of ( basher, struct efab_nic,
1510 falcon_read ( efab, ®, FCN_GPIO_CTL_REG_KER );
1513 EFAB_SET_OWORD_FIELD ( reg, FCN_GPIO0_OEN, ( data ? 0 : 1 ) );
1516 EFAB_SET_OWORD_FIELD ( reg, FCN_GPIO3_OEN, ( data ? 0 : 1 ) );
1519 EFAB_ERR ( "%s bit=%d\n", __func__, bit_id );
1523 falcon_write ( efab, ®, FCN_GPIO_CTL_REG_KER );
1527 falcon_i2c_bit_read ( struct bit_basher *basher, unsigned int bit_id )
1529 struct efab_nic *efab = container_of ( basher, struct efab_nic,
1533 falcon_read ( efab, ®, FCN_GPIO_CTL_REG_KER );
1536 return EFAB_OWORD_FIELD ( reg, FCN_GPIO0_IN );
1539 return EFAB_OWORD_FIELD ( reg, FCN_GPIO3_IN );
1542 EFAB_ERR ( "%s bit=%d\n", __func__, bit_id );
1549 static struct bit_basher_operations falcon_i2c_bit_ops = {
1550 .read = falcon_i2c_bit_read,
1551 .write = falcon_i2c_bit_write,
1555 /*******************************************************************************
1561 *******************************************************************************/
1564 falcon_gmii_wait ( struct efab_nic *efab )
1566 efab_dword_t md_stat;
1569 /* wait up to 10ms */
1570 for (count = 0; count < 1000; count++) {
1571 falcon_readl ( efab, &md_stat, FCN_MD_STAT_REG_KER );
1572 if ( EFAB_DWORD_FIELD ( md_stat, FCN_MD_BSY ) == 0 ) {
1573 if ( EFAB_DWORD_FIELD ( md_stat, FCN_MD_LNFL ) != 0 ||
1574 EFAB_DWORD_FIELD ( md_stat, FCN_MD_BSERR ) != 0 ) {
1575 EFAB_ERR ( "Error from GMII access "
1577 EFAB_DWORD_VAL ( md_stat ));
1585 EFAB_ERR ( "Timed out waiting for GMII\n" );
1590 falcon_mdio_write ( struct efab_nic *efab, int device,
1591 int location, int value )
1595 EFAB_TRACE ( "Writing GMII %d register %02x with %04x\n",
1596 device, location, value );
1598 /* Check MII not currently being accessed */
1599 if ( falcon_gmii_wait ( efab ) )
1602 /* Write the address/ID register */
1603 EFAB_POPULATE_OWORD_1 ( reg, FCN_MD_PHY_ADR, location );
1604 falcon_write ( efab, ®, FCN_MD_PHY_ADR_REG_KER );
1606 if ( efab->phy_10g ) {
1608 EFAB_POPULATE_OWORD_2 ( reg,
1609 FCN_MD_PRT_ADR, efab->phy_addr,
1610 FCN_MD_DEV_ADR, device );
1614 assert ( device == 0 );
1616 EFAB_POPULATE_OWORD_2 ( reg,
1617 FCN_MD_PRT_ADR, efab->phy_addr,
1618 FCN_MD_DEV_ADR, location );
1620 falcon_write ( efab, ®, FCN_MD_ID_REG_KER );
1624 EFAB_POPULATE_OWORD_1 ( reg, FCN_MD_TXD, value );
1625 falcon_write ( efab, ®, FCN_MD_TXD_REG_KER );
1627 EFAB_POPULATE_OWORD_2 ( reg,
1629 FCN_MD_GC, ( efab->phy_10g ? 0 : 1 ) );
1630 falcon_write ( efab, ®, FCN_MD_CS_REG_KER );
1632 /* Wait for data to be written */
1633 if ( falcon_gmii_wait ( efab ) ) {
1634 /* Abort the write operation */
1635 EFAB_POPULATE_OWORD_2 ( reg,
1638 falcon_write ( efab, ®, FCN_MD_CS_REG_KER );
1644 falcon_mdio_read ( struct efab_nic *efab, int device, int location )
1649 /* Check MII not currently being accessed */
1650 if ( falcon_gmii_wait ( efab ) )
1653 if ( efab->phy_10g ) {
1655 EFAB_POPULATE_OWORD_1 ( reg, FCN_MD_PHY_ADR, location );
1656 falcon_write ( efab, ®, FCN_MD_PHY_ADR_REG_KER );
1658 EFAB_POPULATE_OWORD_2 ( reg,
1659 FCN_MD_PRT_ADR, efab->phy_addr,
1660 FCN_MD_DEV_ADR, device );
1661 falcon_write ( efab, ®, FCN_MD_ID_REG_KER);
1663 /* request data to be read */
1664 EFAB_POPULATE_OWORD_2 ( reg,
1670 assert ( device == 0 );
1672 EFAB_POPULATE_OWORD_2 ( reg,
1673 FCN_MD_PRT_ADR, efab->phy_addr,
1674 FCN_MD_DEV_ADR, location );
1675 falcon_write ( efab, ®, FCN_MD_ID_REG_KER );
1677 /* Request data to be read */
1678 EFAB_POPULATE_OWORD_2 ( reg,
1683 falcon_write ( efab, ®, FCN_MD_CS_REG_KER );
1685 /* Wait for data to become available */
1686 if ( falcon_gmii_wait ( efab ) ) {
1687 /* Abort the read operation */
1688 EFAB_POPULATE_OWORD_2 ( reg,
1691 falcon_write ( efab, ®, FCN_MD_CS_REG_KER );
1697 falcon_read ( efab, ®, FCN_MD_RXD_REG_KER );
1698 value = EFAB_OWORD_FIELD ( reg, FCN_MD_RXD );
1701 EFAB_TRACE ( "Read from GMII %d register %02x, got %04x\n",
1702 device, location, value );
1707 /*******************************************************************************
1713 *******************************************************************************/
1716 falcon_reconfigure_mac_wrapper ( struct efab_nic *efab )
1721 if ( efab->link_options & LPA_EF_10000 ) {
1723 } else if ( efab->link_options & LPA_EF_1000 ) {
1725 } else if ( efab->link_options & LPA_100 ) {
1730 EFAB_POPULATE_OWORD_5 ( reg,
1731 FCN_MAC_XOFF_VAL, 0xffff /* datasheet */,
1732 FCN_MAC_BCAD_ACPT, 1,
1734 FCN_MAC_LINK_STATUS, 1,
1735 FCN_MAC_SPEED, link_speed );
1737 falcon_write ( efab, ®, FCN_MAC0_CTRL_REG_KER );
1740 /*******************************************************************************
1746 *******************************************************************************/
1748 /* GMAC configuration register 1 */
1749 #define GM_CFG1_REG_MAC 0x00
1750 #define GM_SW_RST_LBN 31
1751 #define GM_SW_RST_WIDTH 1
1752 #define GM_RX_FC_EN_LBN 5
1753 #define GM_RX_FC_EN_WIDTH 1
1754 #define GM_TX_FC_EN_LBN 4
1755 #define GM_TX_FC_EN_WIDTH 1
1756 #define GM_RX_EN_LBN 2
1757 #define GM_RX_EN_WIDTH 1
1758 #define GM_TX_EN_LBN 0
1759 #define GM_TX_EN_WIDTH 1
1761 /* GMAC configuration register 2 */
1762 #define GM_CFG2_REG_MAC 0x01
1763 #define GM_PAMBL_LEN_LBN 12
1764 #define GM_PAMBL_LEN_WIDTH 4
1765 #define GM_IF_MODE_LBN 8
1766 #define GM_IF_MODE_WIDTH 2
1767 #define GM_PAD_CRC_EN_LBN 2
1768 #define GM_PAD_CRC_EN_WIDTH 1
1770 #define GM_FD_WIDTH 1
1772 /* GMAC maximum frame length register */
1773 #define GM_MAX_FLEN_REG_MAC 0x04
1774 #define GM_MAX_FLEN_LBN 0
1775 #define GM_MAX_FLEN_WIDTH 16
1777 /* GMAC MII management configuration register */
1778 #define GM_MII_MGMT_CFG_REG_MAC 0x08
1779 #define GM_MGMT_CLK_SEL_LBN 0
1780 #define GM_MGMT_CLK_SEL_WIDTH 3
1782 /* GMAC MII management command register */
1783 #define GM_MII_MGMT_CMD_REG_MAC 0x09
1784 #define GM_MGMT_SCAN_CYC_LBN 1
1785 #define GM_MGMT_SCAN_CYC_WIDTH 1
1786 #define GM_MGMT_RD_CYC_LBN 0
1787 #define GM_MGMT_RD_CYC_WIDTH 1
1789 /* GMAC MII management address register */
1790 #define GM_MII_MGMT_ADR_REG_MAC 0x0a
1791 #define GM_MGMT_PHY_ADDR_LBN 8
1792 #define GM_MGMT_PHY_ADDR_WIDTH 5
1793 #define GM_MGMT_REG_ADDR_LBN 0
1794 #define GM_MGMT_REG_ADDR_WIDTH 5
1796 /* GMAC MII management control register */
1797 #define GM_MII_MGMT_CTL_REG_MAC 0x0b
1798 #define GM_MGMT_CTL_LBN 0
1799 #define GM_MGMT_CTL_WIDTH 16
1801 /* GMAC MII management status register */
1802 #define GM_MII_MGMT_STAT_REG_MAC 0x0c
1803 #define GM_MGMT_STAT_LBN 0
1804 #define GM_MGMT_STAT_WIDTH 16
1806 /* GMAC MII management indicators register */
1807 #define GM_MII_MGMT_IND_REG_MAC 0x0d
1808 #define GM_MGMT_BUSY_LBN 0
1809 #define GM_MGMT_BUSY_WIDTH 1
1811 /* GMAC station address register 1 */
1812 #define GM_ADR1_REG_MAC 0x10
1813 #define GM_HWADDR_5_LBN 24
1814 #define GM_HWADDR_5_WIDTH 8
1815 #define GM_HWADDR_4_LBN 16
1816 #define GM_HWADDR_4_WIDTH 8
1817 #define GM_HWADDR_3_LBN 8
1818 #define GM_HWADDR_3_WIDTH 8
1819 #define GM_HWADDR_2_LBN 0
1820 #define GM_HWADDR_2_WIDTH 8
1822 /* GMAC station address register 2 */
1823 #define GM_ADR2_REG_MAC 0x11
1824 #define GM_HWADDR_1_LBN 24
1825 #define GM_HWADDR_1_WIDTH 8
1826 #define GM_HWADDR_0_LBN 16
1827 #define GM_HWADDR_0_WIDTH 8
1829 /* GMAC FIFO configuration register 0 */
1830 #define GMF_CFG0_REG_MAC 0x12
1831 #define GMF_FTFENREQ_LBN 12
1832 #define GMF_FTFENREQ_WIDTH 1
1833 #define GMF_STFENREQ_LBN 11
1834 #define GMF_STFENREQ_WIDTH 1
1835 #define GMF_FRFENREQ_LBN 10
1836 #define GMF_FRFENREQ_WIDTH 1
1837 #define GMF_SRFENREQ_LBN 9
1838 #define GMF_SRFENREQ_WIDTH 1
1839 #define GMF_WTMENREQ_LBN 8
1840 #define GMF_WTMENREQ_WIDTH 1
1842 /* GMAC FIFO configuration register 1 */
1843 #define GMF_CFG1_REG_MAC 0x13
1844 #define GMF_CFGFRTH_LBN 16
1845 #define GMF_CFGFRTH_WIDTH 5
1846 #define GMF_CFGXOFFRTX_LBN 0
1847 #define GMF_CFGXOFFRTX_WIDTH 16
1849 /* GMAC FIFO configuration register 2 */
1850 #define GMF_CFG2_REG_MAC 0x14
1851 #define GMF_CFGHWM_LBN 16
1852 #define GMF_CFGHWM_WIDTH 6
1853 #define GMF_CFGLWM_LBN 0
1854 #define GMF_CFGLWM_WIDTH 6
1856 /* GMAC FIFO configuration register 3 */
1857 #define GMF_CFG3_REG_MAC 0x15
1858 #define GMF_CFGHWMFT_LBN 16
1859 #define GMF_CFGHWMFT_WIDTH 6
1860 #define GMF_CFGFTTH_LBN 0
1861 #define GMF_CFGFTTH_WIDTH 6
1863 /* GMAC FIFO configuration register 4 */
1864 #define GMF_CFG4_REG_MAC 0x16
1865 #define GMF_HSTFLTRFRM_PAUSE_LBN 12
1866 #define GMF_HSTFLTRFRM_PAUSE_WIDTH 12
1868 /* GMAC FIFO configuration register 5 */
1869 #define GMF_CFG5_REG_MAC 0x17
1870 #define GMF_CFGHDPLX_LBN 22
1871 #define GMF_CFGHDPLX_WIDTH 1
1872 #define GMF_CFGBYTMODE_LBN 19
1873 #define GMF_CFGBYTMODE_WIDTH 1
1874 #define GMF_HSTDRPLT64_LBN 18
1875 #define GMF_HSTDRPLT64_WIDTH 1
1876 #define GMF_HSTFLTRFRMDC_PAUSE_LBN 12
1877 #define GMF_HSTFLTRFRMDC_PAUSE_WIDTH 1
1880 falcon_gmac_writel ( struct efab_nic *efab, efab_dword_t *value,
1881 unsigned int mac_reg )
1885 EFAB_POPULATE_OWORD_1 ( temp, FCN_MAC_DATA,
1886 EFAB_DWORD_FIELD ( *value, FCN_MAC_DATA ) );
1887 falcon_write ( efab, &temp, FALCON_GMAC_REG ( efab, mac_reg ) );
1891 falcon_gmac_readl ( struct efab_nic *efab, efab_dword_t *value,
1892 unsigned int mac_reg )
1896 falcon_read ( efab, &temp, FALCON_GMAC_REG ( efab, mac_reg ) );
1897 EFAB_POPULATE_DWORD_1 ( *value, FCN_MAC_DATA,
1898 EFAB_OWORD_FIELD ( temp, FCN_MAC_DATA ) );
1902 mentormac_reset ( struct efab_nic *efab )
1906 /* Take into reset */
1907 EFAB_POPULATE_DWORD_1 ( reg, GM_SW_RST, 1 );
1908 falcon_gmac_writel ( efab, ®, GM_CFG1_REG_MAC );
1911 /* Take out of reset */
1912 EFAB_POPULATE_DWORD_1 ( reg, GM_SW_RST, 0 );
1913 falcon_gmac_writel ( efab, ®, GM_CFG1_REG_MAC );
1916 /* Configure GMII interface so PHY is accessible. Note that
1917 * GMII interface is connected only to port 0, and that on
1918 * Falcon this is a no-op.
1920 EFAB_POPULATE_DWORD_1 ( reg, GM_MGMT_CLK_SEL, 0x4 );
1921 falcon_gmac_writel ( efab, ®, GM_MII_MGMT_CFG_REG_MAC );
1926 mentormac_init ( struct efab_nic *efab )
1928 int pause, if_mode, full_duplex, bytemode, half_duplex;
1931 /* Configuration register 1 */
1932 pause = ( efab->link_options & LPA_PAUSE_CAP ) ? 1 : 0;
1933 if ( ! ( efab->link_options & LPA_EF_DUPLEX ) ) {
1934 /* Half-duplex operation requires TX flow control */
1937 EFAB_POPULATE_DWORD_4 ( reg,
1942 falcon_gmac_writel ( efab, ®, GM_CFG1_REG_MAC );
1945 /* Configuration register 2 */
1946 if_mode = ( efab->link_options & LPA_EF_1000 ) ? 2 : 1;
1947 full_duplex = ( efab->link_options & LPA_EF_DUPLEX ) ? 1 : 0;
1948 EFAB_POPULATE_DWORD_4 ( reg,
1949 GM_IF_MODE, if_mode,
1952 GM_PAMBL_LEN, 0x7 /* ? */ );
1953 falcon_gmac_writel ( efab, ®, GM_CFG2_REG_MAC );
1956 /* Max frame len register */
1957 EFAB_POPULATE_DWORD_1 ( reg, GM_MAX_FLEN,
1958 EFAB_MAX_FRAME_LEN ( ETH_FRAME_LEN ) );
1959 falcon_gmac_writel ( efab, ®, GM_MAX_FLEN_REG_MAC );
1962 /* FIFO configuration register 0 */
1963 EFAB_POPULATE_DWORD_5 ( reg,
1969 falcon_gmac_writel ( efab, ®, GMF_CFG0_REG_MAC );
1972 /* FIFO configuration register 1 */
1973 EFAB_POPULATE_DWORD_2 ( reg,
1975 GMF_CFGXOFFRTX, 0xffff );
1976 falcon_gmac_writel ( efab, ®, GMF_CFG1_REG_MAC );
1979 /* FIFO configuration register 2 */
1980 EFAB_POPULATE_DWORD_2 ( reg,
1983 falcon_gmac_writel ( efab, ®, GMF_CFG2_REG_MAC );
1986 /* FIFO configuration register 3 */
1987 EFAB_POPULATE_DWORD_2 ( reg,
1989 GMF_CFGFTTH, 0x08 );
1990 falcon_gmac_writel ( efab, ®, GMF_CFG3_REG_MAC );
1993 /* FIFO configuration register 4 */
1994 EFAB_POPULATE_DWORD_1 ( reg, GMF_HSTFLTRFRM_PAUSE, 1 );
1995 falcon_gmac_writel ( efab, ®, GMF_CFG4_REG_MAC );
1998 /* FIFO configuration register 5 */
1999 bytemode = ( efab->link_options & LPA_EF_1000 ) ? 1 : 0;
2000 half_duplex = ( efab->link_options & LPA_EF_DUPLEX ) ? 0 : 1;
2001 falcon_gmac_readl ( efab, ®, GMF_CFG5_REG_MAC );
2002 EFAB_SET_DWORD_FIELD ( reg, GMF_CFGBYTMODE, bytemode );
2003 EFAB_SET_DWORD_FIELD ( reg, GMF_CFGHDPLX, half_duplex );
2004 EFAB_SET_DWORD_FIELD ( reg, GMF_HSTDRPLT64, half_duplex );
2005 EFAB_SET_DWORD_FIELD ( reg, GMF_HSTFLTRFRMDC_PAUSE, 0 );
2006 falcon_gmac_writel ( efab, ®, GMF_CFG5_REG_MAC );
2010 EFAB_POPULATE_DWORD_4 ( reg,
2011 GM_HWADDR_5, efab->mac_addr[5],
2012 GM_HWADDR_4, efab->mac_addr[4],
2013 GM_HWADDR_3, efab->mac_addr[3],
2014 GM_HWADDR_2, efab->mac_addr[2] );
2015 falcon_gmac_writel ( efab, ®, GM_ADR1_REG_MAC );
2017 EFAB_POPULATE_DWORD_2 ( reg,
2018 GM_HWADDR_1, efab->mac_addr[1],
2019 GM_HWADDR_0, efab->mac_addr[0] );
2020 falcon_gmac_writel ( efab, ®, GM_ADR2_REG_MAC );
2025 falcon_init_gmac ( struct efab_nic *efab )
2028 mentormac_reset ( efab );
2030 /* Initialise PHY */
2031 efab->phy_op->init ( efab );
2033 /* check the link is up */
2034 if ( !efab->link_up )
2037 /* Initialise MAC */
2038 mentormac_init ( efab );
2040 /* reconfigure the MAC wrapper */
2041 falcon_reconfigure_mac_wrapper ( efab );
2046 static struct efab_mac_operations falcon_gmac_operations = {
2047 .init = falcon_init_gmac,
2051 /*******************************************************************************
2057 *******************************************************************************/
2060 * Write dword to a Falcon XMAC register
2064 falcon_xmac_writel ( struct efab_nic *efab, efab_dword_t *value,
2065 unsigned int mac_reg )
2069 EFAB_POPULATE_OWORD_1 ( temp, FCN_MAC_DATA,
2070 EFAB_DWORD_FIELD ( *value, FCN_MAC_DATA ) );
2071 falcon_write ( efab, &temp,
2072 FALCON_XMAC_REG ( efab, mac_reg ) );
2076 * Read dword from a Falcon XMAC register
2080 falcon_xmac_readl ( struct efab_nic *efab, efab_dword_t *value,
2081 unsigned int mac_reg )
2085 falcon_read ( efab, &temp,
2086 FALCON_XMAC_REG ( efab, mac_reg ) );
2087 EFAB_POPULATE_DWORD_1 ( *value, FCN_MAC_DATA,
2088 EFAB_OWORD_FIELD ( temp, FCN_MAC_DATA ) );
2092 * Configure Falcon XAUI output
2095 falcon_setup_xaui ( struct efab_nic *efab )
2097 efab_dword_t sdctl, txdrv;
2099 falcon_xmac_readl ( efab, &sdctl, FCN_XX_SD_CTL_REG_MAC );
2100 EFAB_SET_DWORD_FIELD ( sdctl, FCN_XX_HIDRVD, XX_SD_CTL_DRV_DEFAULT );
2101 EFAB_SET_DWORD_FIELD ( sdctl, FCN_XX_LODRVD, XX_SD_CTL_DRV_DEFAULT );
2102 EFAB_SET_DWORD_FIELD ( sdctl, FCN_XX_HIDRVC, XX_SD_CTL_DRV_DEFAULT );
2103 EFAB_SET_DWORD_FIELD ( sdctl, FCN_XX_LODRVC, XX_SD_CTL_DRV_DEFAULT );
2104 EFAB_SET_DWORD_FIELD ( sdctl, FCN_XX_HIDRVB, XX_SD_CTL_DRV_DEFAULT );
2105 EFAB_SET_DWORD_FIELD ( sdctl, FCN_XX_LODRVB, XX_SD_CTL_DRV_DEFAULT );
2106 EFAB_SET_DWORD_FIELD ( sdctl, FCN_XX_HIDRVA, XX_SD_CTL_DRV_DEFAULT );
2107 EFAB_SET_DWORD_FIELD ( sdctl, FCN_XX_LODRVA, XX_SD_CTL_DRV_DEFAULT );
2108 falcon_xmac_writel ( efab, &sdctl, FCN_XX_SD_CTL_REG_MAC );
2110 EFAB_POPULATE_DWORD_8 ( txdrv,
2111 FCN_XX_DEQD, XX_TXDRV_DEQ_DEFAULT,
2112 FCN_XX_DEQC, XX_TXDRV_DEQ_DEFAULT,
2113 FCN_XX_DEQB, XX_TXDRV_DEQ_DEFAULT,
2114 FCN_XX_DEQA, XX_TXDRV_DEQ_DEFAULT,
2115 FCN_XX_DTXD, XX_TXDRV_DTX_DEFAULT,
2116 FCN_XX_DTXC, XX_TXDRV_DTX_DEFAULT,
2117 FCN_XX_DTXB, XX_TXDRV_DTX_DEFAULT,
2118 FCN_XX_DTXA, XX_TXDRV_DTX_DEFAULT);
2119 falcon_xmac_writel ( efab, &txdrv, FCN_XX_TXDRV_CTL_REG_MAC);
2123 falcon_xgmii_status ( struct efab_nic *efab )
2127 if ( efab->pci_revision < FALCON_REV_B0 )
2129 /* The ISR latches, so clear it and re-read */
2130 falcon_xmac_readl ( efab, ®, FCN_XM_MGT_INT_REG_MAC_B0 );
2131 falcon_xmac_readl ( efab, ®, FCN_XM_MGT_INT_REG_MAC_B0 );
2133 if ( EFAB_DWORD_FIELD ( reg, FCN_XM_LCLFLT ) ||
2134 EFAB_DWORD_FIELD ( reg, FCN_XM_RMTFLT ) ) {
2135 EFAB_TRACE ( "MGT_INT: "EFAB_DWORD_FMT"\n",
2136 EFAB_DWORD_VAL ( reg ) );
2144 falcon_mask_status_intr ( struct efab_nic *efab, int enable )
2148 if ( efab->pci_revision < FALCON_REV_B0 )
2153 falcon_xmac_readl ( efab, ®, FCN_XM_MGT_INT_REG_MAC_B0 );
2155 EFAB_POPULATE_DWORD_2 ( reg,
2156 FCN_XM_MSK_RMTFLT, !enable,
2157 FCN_XM_MSK_LCLFLT, !enable);
2158 falcon_xmac_readl ( efab, ®, FCN_XM_MGT_INT_MSK_REG_MAC_B0 );
2162 * Reset 10G MAC connected to port
2166 falcon_reset_xmac ( struct efab_nic *efab )
2171 EFAB_POPULATE_DWORD_1 ( reg, FCN_XM_CORE_RST, 1 );
2172 falcon_xmac_writel ( efab, ®, FCN_XM_GLB_CFG_REG_MAC );
2174 for ( count = 0 ; count < 1000 ; count++ ) {
2176 falcon_xmac_readl ( efab, ®,
2177 FCN_XM_GLB_CFG_REG_MAC );
2178 if ( EFAB_DWORD_FIELD ( reg, FCN_XM_CORE_RST ) == 0 )
2186 falcon_reset_xaui ( struct efab_nic *efab )
2194 EFAB_POPULATE_DWORD_1 ( reg, FCN_XX_RST_XX_EN, 1 );
2195 falcon_xmac_writel ( efab, ®, FCN_XX_PWR_RST_REG_MAC );
2197 /* Give some time for the link to establish */
2198 for (count = 0; count < 1000; count++) { /* wait up to 10ms */
2199 falcon_xmac_readl ( efab, ®, FCN_XX_PWR_RST_REG_MAC );
2200 if ( EFAB_DWORD_FIELD ( reg, FCN_XX_RST_XX_EN ) == 0 ) {
2201 falcon_setup_xaui ( efab );
2206 EFAB_ERR ( "timed out waiting for XAUI/XGXS reset\n" );
2211 falcon_xaui_link_ok ( struct efab_nic *efab )
2214 int align_done, lane_status, sync;
2218 /* Read Falcon XAUI side */
2219 if ( efab->is_asic ) {
2220 /* Read link status */
2221 falcon_xmac_readl ( efab, ®, FCN_XX_CORE_STAT_REG_MAC );
2222 align_done = EFAB_DWORD_FIELD ( reg, FCN_XX_ALIGN_DONE );
2224 sync = EFAB_DWORD_FIELD ( reg, FCN_XX_SYNC_STAT );
2225 sync = ( sync == FCN_XX_SYNC_STAT_DECODE_SYNCED );
2227 link_ok = align_done && sync;
2230 /* Clear link status ready for next read */
2231 EFAB_SET_DWORD_FIELD ( reg, FCN_XX_COMMA_DET, FCN_XX_COMMA_DET_RESET );
2232 EFAB_SET_DWORD_FIELD ( reg, FCN_XX_CHARERR, FCN_XX_CHARERR_RESET);
2233 EFAB_SET_DWORD_FIELD ( reg, FCN_XX_DISPERR, FCN_XX_DISPERR_RESET);
2234 falcon_xmac_writel ( efab, ®, FCN_XX_CORE_STAT_REG_MAC );
2236 has_phyxs = ( efab->phy_op->mmds & ( 1 << MDIO_MMD_PHYXS ) );
2237 if ( link_ok && has_phyxs ) {
2238 lane_status = falcon_mdio_read ( efab, MDIO_MMD_PHYXS,
2239 MDIO_PHYXS_LANE_STATE );
2240 link_ok = ( lane_status & ( 1 << MDIO_PHYXS_LANE_ALIGNED_LBN ) );
2243 EFAB_LOG ( "XGXS lane status: %x\n", lane_status );
2254 falcon_reconfigure_xmac ( struct efab_nic *efab )
2259 /* Configure MAC - cut-thru mode is hard wired on */
2260 EFAB_POPULATE_DWORD_3 ( reg,
2261 FCN_XM_RX_JUMBO_MODE, 1,
2262 FCN_XM_TX_STAT_EN, 1,
2263 FCN_XM_RX_STAT_EN, 1);
2264 falcon_xmac_writel ( efab, ®, FCN_XM_GLB_CFG_REG_MAC );
2267 EFAB_POPULATE_DWORD_6 ( reg,
2274 falcon_xmac_writel ( efab, ®, FCN_XM_TX_CFG_REG_MAC );
2277 EFAB_POPULATE_DWORD_4 ( reg,
2279 FCN_XM_AUTO_DEPAD, 0,
2280 FCN_XM_ACPT_ALL_MCAST, 1,
2281 FCN_XM_PASS_CRC_ERR, 1 );
2282 falcon_xmac_writel ( efab, ®, FCN_XM_RX_CFG_REG_MAC );
2284 /* Set frame length */
2285 max_frame_len = EFAB_MAX_FRAME_LEN ( ETH_FRAME_LEN );
2286 EFAB_POPULATE_DWORD_1 ( reg,
2287 FCN_XM_MAX_RX_FRM_SIZE, max_frame_len );
2288 falcon_xmac_writel ( efab, ®, FCN_XM_RX_PARAM_REG_MAC );
2289 EFAB_POPULATE_DWORD_2 ( reg,
2290 FCN_XM_MAX_TX_FRM_SIZE, max_frame_len,
2291 FCN_XM_TX_JUMBO_MODE, 1 );
2292 falcon_xmac_writel ( efab, ®, FCN_XM_TX_PARAM_REG_MAC );
2294 /* Enable flow control receipt */
2295 EFAB_POPULATE_DWORD_2 ( reg,
2296 FCN_XM_PAUSE_TIME, 0xfffe,
2297 FCN_XM_DIS_FCNTL, 0 );
2298 falcon_xmac_writel ( efab, ®, FCN_XM_FC_REG_MAC );
2300 /* Set MAC address */
2301 EFAB_POPULATE_DWORD_4 ( reg,
2302 FCN_XM_ADR_0, efab->mac_addr[0],
2303 FCN_XM_ADR_1, efab->mac_addr[1],
2304 FCN_XM_ADR_2, efab->mac_addr[2],
2305 FCN_XM_ADR_3, efab->mac_addr[3] );
2306 falcon_xmac_writel ( efab, ®, FCN_XM_ADR_LO_REG_MAC );
2307 EFAB_POPULATE_DWORD_2 ( reg,
2308 FCN_XM_ADR_4, efab->mac_addr[4],
2309 FCN_XM_ADR_5, efab->mac_addr[5] );
2310 falcon_xmac_writel ( efab, ®, FCN_XM_ADR_HI_REG_MAC );
2314 falcon_init_xmac ( struct efab_nic *efab )
2318 /* Mask the PHY management interrupt */
2319 falcon_mask_status_intr ( efab, 0 );
2321 /* Initialise the PHY to instantiate the clock. */
2322 rc = efab->phy_op->init ( efab );
2324 EFAB_ERR ( "unable to initialise PHY\n" );
2328 falcon_reset_xaui ( efab );
2330 /* Give the PHY and MAC time to faff */
2333 /* Reset and reconfigure the XMAC */
2334 rc = falcon_reset_xmac ( efab );
2337 falcon_reconfigure_xmac ( efab );
2338 falcon_reconfigure_mac_wrapper ( efab );
2340 * Now wait for the link to come up. This may take a while
2341 * for some slower PHY's.
2343 for (count=0; count<50; count++) {
2346 /* Wait a while for the link to come up. */
2348 if ((count % 5) == 0)
2351 /* Does the PHY think the wire-side link is up? */
2352 link_ok = mdio_clause45_links_ok ( efab );
2353 /* Ensure the XAUI link to the PHY is good */
2355 link_ok = falcon_xaui_link_ok ( efab );
2357 falcon_reset_xaui ( efab );
2360 /* Check fault indication */
2362 link_ok = falcon_xgmii_status ( efab );
2364 efab->link_up = link_ok;
2366 /* unmask the status interrupt */
2367 falcon_mask_status_intr ( efab, 1 );
2372 /* Link failed to come up, but initialisation was fine. */
2380 static struct efab_mac_operations falcon_xmac_operations = {
2381 .init = falcon_init_xmac,
2384 /*******************************************************************************
2390 *******************************************************************************/
2393 falcon_xaui_phy_init ( struct efab_nic *efab )
2395 /* CX4 is always 10000FD only */
2396 efab->link_options = LPA_EF_10000FULL;
2398 /* There is no PHY! */
2402 static struct efab_phy_operations falcon_xaui_phy_ops = {
2403 .init = falcon_xaui_phy_init,
2408 /*******************************************************************************
2414 *******************************************************************************/
2417 * Initialise Alaska PHY
2421 alaska_init ( struct efab_nic *efab )
2423 unsigned int advertised, lpa;
2425 /* Read link up status */
2426 efab->link_up = gmii_link_ok ( efab );
2428 if ( ! efab->link_up )
2431 /* Determine link options from PHY. */
2432 advertised = gmii_autoneg_advertised ( efab );
2433 lpa = gmii_autoneg_lpa ( efab );
2434 efab->link_options = gmii_nway_result ( advertised & lpa );
2439 static struct efab_phy_operations falcon_alaska_phy_ops = {
2440 .init = alaska_init,
2443 /*******************************************************************************
2449 *******************************************************************************/
2451 #define XFP_REQUIRED_DEVS ( MDIO_MMDREG_DEVS0_PCS | \
2452 MDIO_MMDREG_DEVS0_PMAPMD | \
2453 MDIO_MMDREG_DEVS0_PHYXS )
2456 falcon_xfp_phy_init ( struct efab_nic *efab )
2460 /* Optical link is always 10000FD only */
2461 efab->link_options = LPA_EF_10000FULL;
2464 rc = mdio_clause45_reset_mmd ( efab, MDIO_MMD_PHYXS );
2471 static struct efab_phy_operations falcon_xfp_phy_ops = {
2472 .init = falcon_xfp_phy_init,
2473 .mmds = XFP_REQUIRED_DEVS,
2476 /*******************************************************************************
2482 *******************************************************************************/
2484 /* Command register */
2485 #define TXC_GLRGS_GLCMD (0xc004)
2486 #define TXC_GLCMD_LMTSWRST_LBN (14)
2488 /* Amplitude on lanes 0+1, 2+3 */
2489 #define TXC_ALRGS_ATXAMP0 (0xc041)
2490 #define TXC_ALRGS_ATXAMP1 (0xc042)
2491 /* Bit position of value for lane 0+2, 1+3 */
2492 #define TXC_ATXAMP_LANE02_LBN (3)
2493 #define TXC_ATXAMP_LANE13_LBN (11)
2495 #define TXC_ATXAMP_1280_mV (0)
2496 #define TXC_ATXAMP_1200_mV (8)
2497 #define TXC_ATXAMP_1120_mV (12)
2498 #define TXC_ATXAMP_1060_mV (14)
2499 #define TXC_ATXAMP_0820_mV (25)
2500 #define TXC_ATXAMP_0720_mV (26)
2501 #define TXC_ATXAMP_0580_mV (27)
2502 #define TXC_ATXAMP_0440_mV (28)
2504 #define TXC_ATXAMP_0820_BOTH ( (TXC_ATXAMP_0820_mV << TXC_ATXAMP_LANE02_LBN) | \
2505 (TXC_ATXAMP_0820_mV << TXC_ATXAMP_LANE13_LBN) )
2507 #define TXC_ATXAMP_DEFAULT (0x6060) /* From databook */
2509 /* Preemphasis on lanes 0+1, 2+3 */
2510 #define TXC_ALRGS_ATXPRE0 (0xc043)
2511 #define TXC_ALRGS_ATXPRE1 (0xc044)
2513 #define TXC_ATXPRE_NONE (0)
2514 #define TXC_ATXPRE_DEFAULT (0x1010) /* From databook */
2516 #define TXC_REQUIRED_DEVS ( MDIO_MMDREG_DEVS0_PCS | \
2517 MDIO_MMDREG_DEVS0_PMAPMD | \
2518 MDIO_MMDREG_DEVS0_PHYXS )
2521 falcon_txc_logic_reset ( struct efab_nic *efab )
2526 val = falcon_mdio_read ( efab, MDIO_MMD_PCS, TXC_GLRGS_GLCMD );
2527 val |= (1 << TXC_GLCMD_LMTSWRST_LBN);
2528 falcon_mdio_write ( efab, MDIO_MMD_PCS, TXC_GLRGS_GLCMD, val );
2531 val = falcon_mdio_read ( efab, MDIO_MMD_PCS, TXC_GLRGS_GLCMD );
2532 if ( ~val & ( 1 << TXC_GLCMD_LMTSWRST_LBN ) )
2537 EFAB_ERR ( "logic reset failed\n" );
2543 falcon_txc_phy_init ( struct efab_nic *efab )
2547 /* CX4 is always 10000FD only */
2548 efab->link_options = LPA_EF_10000FULL;
2551 rc = mdio_clause45_reset_mmd ( efab, MDIO_MMD_PMAPMD );
2555 rc = mdio_clause45_check_mmds ( efab );
2559 /* Turn amplitude down and preemphasis off on the host side
2560 * (PHY<->MAC) as this is believed less likely to upset falcon
2561 * and no adverse effects have been noted. It probably also
2562 * saves a picowatt or two */
2564 /* Turn off preemphasis */
2565 falcon_mdio_write ( efab, MDIO_MMD_PHYXS, TXC_ALRGS_ATXPRE0,
2567 falcon_mdio_write ( efab, MDIO_MMD_PHYXS, TXC_ALRGS_ATXPRE1,
2570 /* Turn down the amplitude */
2571 falcon_mdio_write ( efab, MDIO_MMD_PHYXS, TXC_ALRGS_ATXAMP0,
2572 TXC_ATXAMP_0820_BOTH );
2573 falcon_mdio_write ( efab, MDIO_MMD_PHYXS, TXC_ALRGS_ATXAMP1,
2574 TXC_ATXAMP_0820_BOTH );
2576 /* Set the line side amplitude and preemphasis to the databook
2577 * defaults as an erratum causes them to be 0 on at least some
2579 falcon_mdio_write ( efab, MDIO_MMD_PMAPMD, TXC_ALRGS_ATXPRE0,
2580 TXC_ATXPRE_DEFAULT );
2581 falcon_mdio_write ( efab, MDIO_MMD_PMAPMD, TXC_ALRGS_ATXPRE1,
2582 TXC_ATXPRE_DEFAULT );
2583 falcon_mdio_write ( efab, MDIO_MMD_PMAPMD, TXC_ALRGS_ATXAMP0,
2584 TXC_ATXAMP_DEFAULT );
2585 falcon_mdio_write ( efab, MDIO_MMD_PMAPMD, TXC_ALRGS_ATXAMP1,
2586 TXC_ATXAMP_DEFAULT );
2588 rc = falcon_txc_logic_reset ( efab );
2600 static struct efab_phy_operations falcon_txc_phy_ops = {
2601 .init = falcon_txc_phy_init,
2602 .mmds = TXC_REQUIRED_DEVS,
2605 /*******************************************************************************
2611 *******************************************************************************/
2614 #define TENXPRESS_REQUIRED_DEVS ( MDIO_MMDREG_DEVS0_PMAPMD | \
2615 MDIO_MMDREG_DEVS0_PCS | \
2616 MDIO_MMDREG_DEVS0_PHYXS )
2618 #define PCS_TEST_SELECT_REG 0xd807 /* PRM 10.5.8 */
2619 #define CLK312_EN_LBN 3
2620 #define CLK312_EN_WIDTH 1
2622 #define PCS_CLOCK_CTRL_REG 0xd801
2623 #define PLL312_RST_N_LBN 2
2625 /* Special Software reset register */
2626 #define PMA_PMD_EXT_CTRL_REG 49152
2627 #define PMA_PMD_EXT_SSR_LBN 15
2629 /* Boot status register */
2630 #define PCS_BOOT_STATUS_REG 0xd000
2631 #define PCS_BOOT_FATAL_ERR_LBN 0
2632 #define PCS_BOOT_PROGRESS_LBN 1
2633 #define PCS_BOOT_PROGRESS_WIDTH 2
2634 #define PCS_BOOT_COMPLETE_LBN 3
2636 #define PCS_SOFT_RST2_REG 0xd806
2637 #define SERDES_RST_N_LBN 13
2638 #define XGXS_RST_N_LBN 12
2641 falcon_tenxpress_check_c11 ( struct efab_nic *efab )
2646 /* Check that the C11 CPU has booted */
2647 for (count=0; count<10; count++) {
2648 boot_stat = falcon_mdio_read ( efab, MDIO_MMD_PCS,
2649 PCS_BOOT_STATUS_REG );
2650 if ( boot_stat & ( 1 << PCS_BOOT_COMPLETE_LBN ) )
2656 EFAB_ERR ( "C11 failed to boot\n" );
2661 falcon_tenxpress_phy_init ( struct efab_nic *efab )
2665 /* 10XPRESS is always 10000FD (at the moment) */
2666 efab->link_options = LPA_EF_10000FULL;
2668 /* Wait for the blocks to come out of reset */
2669 rc = mdio_clause45_wait_reset_mmds ( efab );
2673 rc = mdio_clause45_check_mmds ( efab );
2677 /* Turn on the clock */
2678 reg = (1 << CLK312_EN_LBN);
2679 falcon_mdio_write ( efab, MDIO_MMD_PCS, PCS_TEST_SELECT_REG, reg);
2681 /* Wait 200ms for the PHY to boot */
2684 rc = falcon_tenxpress_check_c11 ( efab );
2696 static struct efab_phy_operations falcon_tenxpress_phy_ops = {
2697 .init = falcon_tenxpress_phy_init,
2698 .mmds = TENXPRESS_REQUIRED_DEVS,
2701 /*******************************************************************************
2707 *******************************************************************************/
2709 /* The PM8358 just presents a DTE XS */
2710 #define PM8358_REQUIRED_DEVS (MDIO_MMDREG_DEVS0_DTEXS)
2712 /* PHY-specific definitions */
2713 /* Master ID and Global Performance Monitor Update */
2714 #define PMC_MASTER_REG (0xd000)
2715 /* Analog Tx Rx settings under software control */
2716 #define PMC_MASTER_ANLG_CTRL (1<< 11)
2718 /* Master Configuration register 2 */
2719 #define PMC_MCONF2_REG (0xd002)
2720 /* Drive Tx off centre of data eye (1) vs. clock edge (0) */
2721 #define PMC_MCONF2_TEDGE (1 << 2)
2722 /* Drive Rx off centre of data eye (1) vs. clock edge (0) */
2723 #define PMC_MCONF2_REDGE (1 << 3)
2725 /* Analog Rx settings */
2726 #define PMC_ANALOG_RX_CFG0 (0xd025)
2727 #define PMC_ANALOG_RX_CFG1 (0xd02d)
2728 #define PMC_ANALOG_RX_CFG2 (0xd035)
2729 #define PMC_ANALOG_RX_CFG3 (0xd03d)
2732 #define PMC_ANALOG_RX_TERM (1 << 15) /* Bit 15 of RX CFG: 0 for 100 ohms float,
2734 #define PMC_ANALOG_RX_EQ_MASK (3 << 8)
2735 #define PMC_ANALOG_RX_EQ_NONE (0 << 8)
2736 #define PMC_ANALOG_RX_EQ_HALF (1 << 8)
2737 #define PMC_ANALOG_RX_EQ_FULL (2 << 8)
2738 #define PMC_ANALOG_RX_EQ_RSVD (3 << 8)
2741 falcon_pm8358_phy_init ( struct efab_nic *efab )
2745 /* This is a XAUI retimer part */
2746 efab->link_options = LPA_EF_10000FULL;
2748 rc = mdio_clause45_reset_mmd ( efab, MDIO_MMDREG_DEVS0_DTEXS );
2752 /* Enable software control of analogue settings */
2753 reg = falcon_mdio_read ( efab, MDIO_MMD_DTEXS, PMC_MASTER_REG );
2754 reg |= PMC_MASTER_ANLG_CTRL;
2755 falcon_mdio_write ( efab, MDIO_MMD_DTEXS, PMC_MASTER_REG, reg );
2757 /* Turn rx eq on for all channels */
2758 for (i=0; i< 3; i++) {
2759 /* The analog CFG registers are evenly spaced 8 apart */
2760 uint16_t addr = PMC_ANALOG_RX_CFG0 + 8*i;
2761 reg = falcon_mdio_read ( efab, MDIO_MMD_DTEXS, addr );
2762 reg = ( reg & ~PMC_ANALOG_RX_EQ_MASK ) | PMC_ANALOG_RX_EQ_FULL;
2763 falcon_mdio_write ( efab, MDIO_MMD_DTEXS, addr, reg );
2766 /* Set TEDGE, clear REDGE */
2767 reg = falcon_mdio_read ( efab, MDIO_MMD_DTEXS, PMC_MCONF2_REG );
2768 reg = ( reg & ~PMC_MCONF2_REDGE) | PMC_MCONF2_TEDGE;
2769 falcon_mdio_write ( efab, MDIO_MMD_DTEXS, PMC_MCONF2_REG, reg );
2774 static struct efab_phy_operations falcon_pm8358_phy_ops = {
2775 .init = falcon_pm8358_phy_init,
2776 .mmds = PM8358_REQUIRED_DEVS,
2779 /*******************************************************************************
2785 *******************************************************************************/
2787 #define MAX_TEMP_THRESH 90
2790 #define PCA9539 0x74
2794 #define P0_CONFIG 0x06
2796 #define P0_EN_1V0X_LBN 0
2797 #define P0_EN_1V0X_WIDTH 1
2798 #define P0_EN_1V2_LBN 1
2799 #define P0_EN_1V2_WIDTH 1
2800 #define P0_EN_2V5_LBN 2
2801 #define P0_EN_2V5_WIDTH 1
2802 #define P0_EN_3V3X_LBN 3
2803 #define P0_EN_3V3X_WIDTH 1
2804 #define P0_EN_5V_LBN 4
2805 #define P0_EN_5V_WIDTH 1
2806 #define P0_X_TRST_LBN 6
2807 #define P0_X_TRST_WIDTH 1
2810 #define P1_CONFIG 0x07
2812 #define P1_AFE_PWD_LBN 0
2813 #define P1_AFE_PWD_WIDTH 1
2814 #define P1_DSP_PWD25_LBN 1
2815 #define P1_DSP_PWD25_WIDTH 1
2816 #define P1_SPARE_LBN 4
2817 #define P1_SPARE_WIDTH 4
2819 /* Temperature Sensor */
2820 #define MAX6647 0x4e
2826 static struct i2c_device i2c_pca9539 = {
2827 .dev_addr = PCA9539,
2833 static struct i2c_device i2c_max6647 = {
2834 .dev_addr = MAX6647,
2840 sfe4001_init ( struct efab_nic *efab )
2842 struct i2c_interface *i2c = &efab->i2c_bb.i2c;
2844 uint8_t in, cfg, out;
2847 EFAB_LOG ( "Initialise SFE4001 board\n" );
2849 /* Ensure XGXS and XAUI SerDes are held in reset */
2850 EFAB_POPULATE_DWORD_7 ( reg,
2851 FCN_XX_PWRDNA_EN, 1,
2852 FCN_XX_PWRDNB_EN, 1,
2853 FCN_XX_RSTPLLAB_EN, 1,
2854 FCN_XX_RESETA_EN, 1,
2855 FCN_XX_RESETB_EN, 1,
2856 FCN_XX_RSTXGXSRX_EN, 1,
2857 FCN_XX_RSTXGXSTX_EN, 1 );
2858 falcon_xmac_writel ( efab, ®, FCN_XX_PWR_RST_REG_MAC);
2861 /* Set DSP over-temperature alert threshold */
2862 cfg = MAX_TEMP_THRESH;
2863 rc = i2c->write ( i2c, &i2c_max6647, WLHO, &cfg, EFAB_BYTE );
2867 /* Read it back and verify */
2868 rc = i2c->read ( i2c, &i2c_max6647, RLHN, &in, EFAB_BYTE );
2872 if ( in != MAX_TEMP_THRESH ) {
2873 EFAB_ERR ( "Unable to verify MAX6647 limit (requested=%d "
2874 "confirmed=%d)\n", cfg, in );
2879 /* Clear any previous over-temperature alert */
2880 rc = i2c->read ( i2c, &i2c_max6647, RSL, &in, EFAB_BYTE );
2884 /* Enable port 0 and 1 outputs on IO expander */
2886 rc = i2c->write ( i2c, &i2c_pca9539, P0_CONFIG, &cfg, EFAB_BYTE );
2889 cfg = 0xff & ~(1 << P1_SPARE_LBN);
2890 rc = i2c->write ( i2c, &i2c_pca9539, P1_CONFIG, &cfg, EFAB_BYTE );
2894 /* Turn all power off then wait 1 sec. This ensures PHY is reset */
2895 out = 0xff & ~((0 << P0_EN_1V2_LBN) | (0 << P0_EN_2V5_LBN) |
2896 (0 << P0_EN_3V3X_LBN) | (0 << P0_EN_5V_LBN) |
2897 (0 << P0_EN_1V0X_LBN));
2899 rc = i2c->write ( i2c, &i2c_pca9539, P0_OUT, &out, EFAB_BYTE );
2905 for (count=0; count<20; count++) {
2906 /* Turn on 1.2V, 2.5V, 3.3V and 5V power rails */
2907 out = 0xff & ~( (1 << P0_EN_1V2_LBN) | (1 << P0_EN_2V5_LBN) |
2908 (1 << P0_EN_3V3X_LBN) | (1 << P0_EN_5V_LBN) |
2909 (1 << P0_X_TRST_LBN) );
2911 rc = i2c->write ( i2c, &i2c_pca9539, P0_OUT, &out, EFAB_BYTE );
2917 /* Turn on the 1V power rail */
2918 out &= ~( 1 << P0_EN_1V0X_LBN );
2919 rc = i2c->write ( i2c, &i2c_pca9539, P0_OUT, &out, EFAB_BYTE );
2923 EFAB_LOG ( "Waiting for power...(attempt %d)\n", count);
2926 /* Check DSP is powered */
2927 rc = i2c->read ( i2c, &i2c_pca9539, P1_IN, &in, EFAB_BYTE );
2931 if ( in & ( 1 << P1_AFE_PWD_LBN ) )
2941 /* Turn off power rails */
2943 (void) i2c->write ( i2c, &i2c_pca9539, P0_OUT, &out, EFAB_BYTE );
2944 /* Disable port 1 outputs on IO expander */
2946 (void) i2c->write ( i2c, &i2c_pca9539, P1_CONFIG, &out, EFAB_BYTE );
2948 /* Disable port 0 outputs */
2950 (void) i2c->write ( i2c, &i2c_pca9539, P1_CONFIG, &out, EFAB_BYTE );
2956 EFAB_ERR ( "Failed initialising SFE4001 board\n" );
2961 sfe4001_fini ( struct efab_nic *efab )
2963 struct i2c_interface *i2c = &efab->i2c_bb.i2c;
2964 uint8_t in, cfg, out;
2966 EFAB_ERR ( "Turning off SFE4001\n" );
2968 /* Turn off all power rails */
2970 (void) i2c->write ( i2c, &i2c_pca9539, P0_OUT, &out, EFAB_BYTE );
2972 /* Disable port 1 outputs on IO expander */
2974 (void) i2c->write ( i2c, &i2c_pca9539, P1_CONFIG, &cfg, EFAB_BYTE );
2976 /* Disable port 0 outputs on IO expander */
2978 (void) i2c->write ( i2c, &i2c_pca9539, P0_CONFIG, &cfg, EFAB_BYTE );
2980 /* Clear any over-temperature alert */
2981 (void) i2c->read ( i2c, &i2c_max6647, RSL, &in, EFAB_BYTE );
2984 struct efab_board_operations sfe4001_ops = {
2985 .init = sfe4001_init,
2986 .fini = sfe4001_fini,
2989 static int sfe4002_init ( struct efab_nic *efab __attribute__((unused)) )
2993 static void sfe4002_fini ( struct efab_nic *efab __attribute__((unused)) )
2997 struct efab_board_operations sfe4002_ops = {
2998 .init = sfe4002_init,
2999 .fini = sfe4002_fini,
3002 static int sfe4003_init ( struct efab_nic *efab __attribute__((unused)) )
3006 static void sfe4003_fini ( struct efab_nic *efab __attribute__((unused)) )
3010 struct efab_board_operations sfe4003_ops = {
3011 .init = sfe4003_init,
3012 .fini = sfe4003_fini,
3015 /*******************************************************************************
3018 * Hardware initialisation
3021 *******************************************************************************/
3024 falcon_free_special_buffer ( void *p )
3026 /* We don't bother cleaning up the buffer table entries -
3027 * we're hardly limited */
3028 free_dma ( p, EFAB_BUF_ALIGN );
3032 falcon_alloc_special_buffer ( struct efab_nic *efab, int bytes,
3033 struct efab_special_buffer *entry )
3037 efab_qword_t buf_desc;
3038 unsigned long dma_addr;
3040 /* Allocate the buffer, aligned on a buffer address boundary */
3041 buffer = malloc_dma ( bytes, EFAB_BUF_ALIGN );
3045 /* Push buffer table entries to back the buffer */
3046 entry->id = efab->buffer_head;
3047 entry->dma_addr = dma_addr = virt_to_bus ( buffer );
3048 assert ( ( dma_addr & ( EFAB_BUF_ALIGN - 1 ) ) == 0 );
3051 while ( remaining > 0 ) {
3052 EFAB_POPULATE_QWORD_3 ( buf_desc,
3053 FCN_IP_DAT_BUF_SIZE, FCN_IP_DAT_BUF_SIZE_4K,
3054 FCN_BUF_ADR_FBUF, ( dma_addr >> 12 ),
3055 FCN_BUF_OWNER_ID_FBUF, 0 );
3057 falcon_write_sram ( efab, &buf_desc, efab->buffer_head );
3059 ++efab->buffer_head;
3060 dma_addr += EFAB_BUF_ALIGN;
3061 remaining -= EFAB_BUF_ALIGN;
3064 EFAB_TRACE ( "Allocated 0x%x bytes at %p backed by buffer table "
3065 "entries 0x%x..0x%x\n", bytes, buffer, entry->id,
3066 efab->buffer_head - 1 );
3072 clear_b0_fpga_memories ( struct efab_nic *efab)
3074 efab_oword_t blanko, temp;
3077 EFAB_ZERO_OWORD ( blanko );
3079 /* Clear the address region register */
3080 EFAB_POPULATE_OWORD_4 ( temp,
3082 FCN_ADR_REGION1, ( 1 << 16 ),
3083 FCN_ADR_REGION2, ( 2 << 16 ),
3084 FCN_ADR_REGION3, ( 3 << 16 ) );
3085 falcon_write ( efab, &temp, FCN_ADR_REGION_REG_KER );
3087 EFAB_TRACE ( "Clearing filter and RSS tables\n" );
3089 for ( offset = FCN_RX_FILTER_TBL0 ;
3090 offset < FCN_RX_RSS_INDIR_TBL_B0+0x800 ;
3092 falcon_write ( efab, &blanko, offset );
3095 EFAB_TRACE ( "Wiping buffer tables\n" );
3097 /* Notice the 8 byte access mode */
3098 for ( offset = 0x2800000 ;
3099 offset < 0x3000000 ;
3101 _falcon_writel ( efab, 0, offset );
3102 _falcon_writel ( efab, 0, offset + 4 );
3108 falcon_reset ( struct efab_nic *efab )
3110 efab_oword_t glb_ctl_reg_ker;
3112 /* Initiate software reset */
3113 EFAB_POPULATE_OWORD_6 ( glb_ctl_reg_ker,
3114 FCN_PCIE_CORE_RST_CTL, EXCLUDE_FROM_RESET,
3115 FCN_PCIE_NSTCK_RST_CTL, EXCLUDE_FROM_RESET,
3116 FCN_PCIE_SD_RST_CTL, EXCLUDE_FROM_RESET,
3117 FCN_EE_RST_CTL, EXCLUDE_FROM_RESET,
3118 FCN_EXT_PHY_RST_DUR, 0x7, /* 10ms */
3121 falcon_write ( efab, &glb_ctl_reg_ker, FCN_GLB_CTL_REG_KER );
3123 /* Allow 50ms for reset */
3126 /* Check for device reset complete */
3127 falcon_read ( efab, &glb_ctl_reg_ker, FCN_GLB_CTL_REG_KER );
3128 if ( EFAB_OWORD_FIELD ( glb_ctl_reg_ker, FCN_SWRST ) != 0 ) {
3129 EFAB_ERR ( "Reset failed\n" );
3133 if ( ( efab->pci_revision == FALCON_REV_B0 ) && !efab->is_asic ) {
3134 clear_b0_fpga_memories ( efab );
3140 /** Offset of MAC address within EEPROM or Flash */
3141 #define FALCON_MAC_ADDRESS_OFFSET 0x310
3144 * Falcon EEPROM structure
3146 #define SF_NV_CONFIG_BASE 0x300
3147 #define SF_NV_CONFIG_EXTRA 0xA0
3149 struct falcon_nv_config_ver2 {
3151 uint8_t port0_phy_addr;
3152 uint8_t port0_phy_type;
3153 uint8_t port1_phy_addr;
3154 uint8_t port1_phy_type;
3155 uint16_t asic_sub_revision;
3156 uint16_t board_revision;
3157 uint8_t mac_location;
3160 struct falcon_nv_extra {
3161 uint16_t magicnumber;
3162 uint16_t structure_version;
3165 struct falcon_nv_config_ver2 ver2;
3169 #define BOARD_TYPE(_rev) (_rev >> 8)
3172 falcon_probe_nic_variant ( struct efab_nic *efab, struct pci_device *pci )
3174 efab_oword_t altera_build, nic_stat;
3179 pci_read_config_byte ( pci, PCI_CLASS_REVISION, &revision );
3180 efab->pci_revision = revision;
3183 falcon_read ( efab, &altera_build, FCN_ALTERA_BUILD_REG_KER );
3184 fpga_version = EFAB_OWORD_FIELD ( altera_build, FCN_VER_ALL );
3185 efab->is_asic = (fpga_version == 0);
3187 /* MAC and PCI type */
3188 falcon_read ( efab, &nic_stat, FCN_NIC_STAT_REG );
3189 if ( efab->pci_revision == FALCON_REV_B0 ) {
3190 efab->phy_10g = EFAB_OWORD_FIELD ( nic_stat, FCN_STRAP_10G );
3192 else if ( efab->is_asic ) {
3193 efab->phy_10g = EFAB_OWORD_FIELD ( nic_stat, FCN_STRAP_10G );
3196 int minor = EFAB_OWORD_FIELD ( altera_build, FCN_VER_MINOR );
3197 efab->phy_10g = ( minor == 0x14 );
3202 falcon_init_spi_device ( struct efab_nic *efab, struct spi_device *spi )
3204 /* Falcon's SPI interface only supports reads/writes of up to 16 bytes.
3205 * Reduce the nvs block size down to satisfy this - which means callers
3206 * should use the nvs_* functions rather than spi_*. */
3207 if ( spi->nvs.block_size > FALCON_SPI_MAX_LEN )
3208 spi->nvs.block_size = FALCON_SPI_MAX_LEN;
3210 spi->bus = &efab->spi_bus;
3215 falcon_probe_spi ( struct efab_nic *efab )
3217 efab_oword_t nic_stat, gpio_ctl, ee_vpd_cfg;
3218 int has_flash, has_eeprom, ad9bit;
3220 falcon_read ( efab, &nic_stat, FCN_NIC_STAT_REG );
3221 falcon_read ( efab, &gpio_ctl, FCN_GPIO_CTL_REG_KER );
3222 falcon_read ( efab, &ee_vpd_cfg, FCN_EE_VPD_CFG_REG );
3224 /* determine if FLASH / EEPROM is present */
3225 if ( ( efab->pci_revision >= FALCON_REV_B0 ) || efab->is_asic ) {
3226 has_flash = EFAB_OWORD_FIELD ( nic_stat, FCN_SF_PRST );
3227 has_eeprom = EFAB_OWORD_FIELD ( nic_stat, FCN_EE_PRST );
3229 has_flash = EFAB_OWORD_FIELD ( gpio_ctl, FCN_FLASH_PRESENT );
3230 has_eeprom = EFAB_OWORD_FIELD ( gpio_ctl, FCN_EEPROM_PRESENT );
3232 ad9bit = EFAB_OWORD_FIELD ( ee_vpd_cfg, FCN_EE_VPD_EN_AD9_MODE );
3234 /* Configure the SPI and I2C bus */
3235 efab->spi_bus.rw = falcon_spi_rw;
3236 init_i2c_bit_basher ( &efab->i2c_bb, &falcon_i2c_bit_ops );
3238 /* Configure the EEPROM SPI device. Generally, an Atmel 25040
3239 * (or similar) is used, but this is only possible if there is also
3240 * a flash device present to store the boot-time chip configuration.
3243 if ( has_flash && ad9bit )
3244 init_at25040 ( &efab->spi_eeprom );
3246 init_mc25xx640 ( &efab->spi_eeprom );
3247 falcon_init_spi_device ( efab, &efab->spi_eeprom );
3250 /* Configure the FLASH SPI device */
3252 init_at25f1024 ( &efab->spi_flash );
3253 falcon_init_spi_device ( efab, &efab->spi_flash );
3256 EFAB_LOG ( "flash is %s, EEPROM is %s%s\n",
3257 ( has_flash ? "present" : "absent" ),
3258 ( has_eeprom ? "present " : "absent" ),
3259 ( has_eeprom ? (ad9bit ? "(9bit)" : "(16bit)") : "") );
3261 /* The device MUST have flash or eeprom */
3262 if ( ! efab->spi ) {
3263 EFAB_ERR ( "Device appears to have no flash or eeprom\n" );
3267 /* If the device has EEPROM attached, then advertise NVO space */
3269 nvo_init ( &efab->nvo, &efab->spi_eeprom.nvs, 0x100, 0xf0,
3270 NULL, &efab->netdev->refcnt );
3277 falcon_probe_nvram ( struct efab_nic *efab )
3279 struct nvs_device *nvs = &efab->spi->nvs;
3280 struct falcon_nv_extra nv;
3281 int rc, board_revision;
3283 /* Read the MAC address */
3284 rc = nvs_read ( nvs, FALCON_MAC_ADDRESS_OFFSET,
3285 efab->mac_addr, ETH_ALEN );
3289 /* Poke through the NVRAM structure for the PHY type. */
3290 rc = nvs_read ( nvs, SF_NV_CONFIG_BASE + SF_NV_CONFIG_EXTRA,
3291 &nv, sizeof ( nv ) );
3295 /* Handle each supported NVRAM version */
3296 if ( ( le16_to_cpu ( nv.magicnumber ) == FCN_NV_MAGIC_NUMBER ) &&
3297 ( le16_to_cpu ( nv.structure_version ) >= 2 ) ) {
3298 struct falcon_nv_config_ver2* ver2 = &nv.ver_specific.ver2;
3300 /* Get the PHY type */
3301 efab->phy_addr = le16_to_cpu ( ver2->port0_phy_addr );
3302 efab->phy_type = le16_to_cpu ( ver2->port0_phy_type );
3303 board_revision = le16_to_cpu ( ver2->board_revision );
3306 EFAB_ERR ( "NVram is not recognised\n" );
3310 efab->board_type = BOARD_TYPE ( board_revision );
3312 EFAB_TRACE ( "Falcon board %d phy %d @ addr %d\n",
3313 efab->board_type, efab->phy_type, efab->phy_addr );
3315 /* Patch in the board operations */
3316 switch ( efab->board_type ) {
3317 case EFAB_BOARD_SFE4001:
3318 efab->board_op = &sfe4001_ops;
3320 case EFAB_BOARD_SFE4002:
3321 efab->board_op = &sfe4002_ops;
3323 case EFAB_BOARD_SFE4003:
3324 efab->board_op = &sfe4003_ops;
3327 EFAB_ERR ( "Unrecognised board type\n" );
3331 /* Patch in MAC operations */
3332 if ( efab->phy_10g )
3333 efab->mac_op = &falcon_xmac_operations;
3335 efab->mac_op = &falcon_gmac_operations;
3337 /* Hook in the PHY ops */
3338 switch ( efab->phy_type ) {
3339 case PHY_TYPE_10XPRESS:
3340 efab->phy_op = &falcon_tenxpress_phy_ops;
3343 efab->phy_op = &falcon_xaui_phy_ops;
3346 efab->phy_op = &falcon_xfp_phy_ops;
3348 case PHY_TYPE_CX4_RTMR:
3349 efab->phy_op = &falcon_txc_phy_ops;
3351 case PHY_TYPE_PM8358:
3352 efab->phy_op = &falcon_pm8358_phy_ops;
3354 case PHY_TYPE_1GIG_ALASKA:
3355 efab->phy_op = &falcon_alaska_phy_ops;
3358 EFAB_ERR ( "Unknown PHY type: %d\n", efab->phy_type );
3366 falcon_init_sram ( struct efab_nic *efab )
3371 /* use card in internal SRAM mode */
3372 falcon_read ( efab, ®, FCN_NIC_STAT_REG );
3373 EFAB_SET_OWORD_FIELD ( reg, FCN_ONCHIP_SRAM, 1 );
3374 falcon_write ( efab, ®, FCN_NIC_STAT_REG );
3376 /* Deactivate any external SRAM that might be present */
3377 EFAB_POPULATE_OWORD_2 ( reg,
3380 falcon_write ( efab, ®, FCN_GPIO_CTL_REG_KER );
3382 /* Initiate SRAM reset */
3383 EFAB_POPULATE_OWORD_2 ( reg,
3384 FCN_SRAM_OOB_BT_INIT_EN, 1,
3385 FCN_SRM_NUM_BANKS_AND_BANK_SIZE, 0 );
3386 falcon_write ( efab, ®, FCN_SRM_CFG_REG_KER );
3388 /* Wait for SRAM reset to complete */
3391 /* SRAM reset is slow; expect around 16ms */
3394 /* Check for reset complete */
3395 falcon_read ( efab, ®, FCN_SRM_CFG_REG_KER );
3396 if ( !EFAB_OWORD_FIELD ( reg, FCN_SRAM_OOB_BT_INIT_EN ) )
3398 } while (++count < 20); /* wait up to 0.4 sec */
3400 EFAB_ERR ( "timed out waiting for SRAM reset\n");
3405 falcon_setup_nic ( struct efab_nic *efab )
3407 efab_dword_t timer_cmd;
3409 int tx_fc, xoff_thresh, xon_thresh;
3411 /* bug5129: Clear the parity enables on the TX data fifos as
3412 * they produce false parity errors because of timing issues
3414 falcon_read ( efab, ®, FCN_SPARE_REG_KER );
3415 EFAB_SET_OWORD_FIELD ( reg, FCN_MEM_PERR_EN_TX_DATA, 0 );
3416 falcon_write ( efab, ®, FCN_SPARE_REG_KER );
3418 /* Set up TX and RX descriptor caches in SRAM */
3419 EFAB_POPULATE_OWORD_1 ( reg, FCN_SRM_TX_DC_BASE_ADR, 0x130000 );
3420 falcon_write ( efab, ®, FCN_SRM_TX_DC_CFG_REG_KER );
3421 EFAB_POPULATE_OWORD_1 ( reg, FCN_TX_DC_SIZE, 1 /* 16 descriptors */ );
3422 falcon_write ( efab, ®, FCN_TX_DC_CFG_REG_KER );
3423 EFAB_POPULATE_OWORD_1 ( reg, FCN_SRM_RX_DC_BASE_ADR, 0x100000 );
3424 falcon_write ( efab, ®, FCN_SRM_RX_DC_CFG_REG_KER );
3425 EFAB_POPULATE_OWORD_1 ( reg, FCN_RX_DC_SIZE, 2 /* 32 descriptors */ );
3426 falcon_write ( efab, ®, FCN_RX_DC_CFG_REG_KER );
3428 /* Set number of RSS CPUs
3429 * bug7244: Increase filter depth to reduce RX_RESET likelihood
3431 EFAB_POPULATE_OWORD_5 ( reg,
3433 FCN_UDP_FULL_SRCH_LIMIT, 8,
3434 FCN_UDP_WILD_SRCH_LIMIT, 8,
3435 FCN_TCP_WILD_SRCH_LIMIT, 8,
3436 FCN_TCP_FULL_SRCH_LIMIT, 8);
3437 falcon_write ( efab, ®, FCN_RX_FILTER_CTL_REG_KER );
3440 /* Setup RX. Wait for descriptor is broken and must
3441 * be disabled. RXDP recovery shouldn't be needed, but is.
3442 * disable ISCSI parsing because we don't need it
3444 falcon_read ( efab, ®, FCN_RX_SELF_RST_REG_KER );
3445 EFAB_SET_OWORD_FIELD ( reg, FCN_RX_NODESC_WAIT_DIS, 1 );
3446 EFAB_SET_OWORD_FIELD ( reg, FCN_RX_RECOVERY_EN, 1 );
3447 EFAB_SET_OWORD_FIELD ( reg, FCN_RX_ISCSI_DIS, 1 );
3448 falcon_write ( efab, ®, FCN_RX_SELF_RST_REG_KER );
3450 /* Determine recommended flow control settings. *
3451 * Flow control is qualified on B0 and A1/1G, not on A1/10G */
3452 if ( efab->pci_revision == FALCON_REV_B0 ) {
3454 xoff_thresh = 54272; /* ~80Kb - 3*max MTU */
3455 xon_thresh = 27648; /* ~3*max MTU */
3457 else if ( !efab->phy_10g ) {
3463 tx_fc = xoff_thresh = xon_thresh = 0;
3466 /* Setup TX and RX */
3467 falcon_read ( efab, ®, FCN_TX_CFG2_REG_KER );
3468 EFAB_SET_OWORD_FIELD ( reg, FCN_TX_DIS_NON_IP_EV, 1 );
3469 falcon_write ( efab, ®, FCN_TX_CFG2_REG_KER );
3471 falcon_read ( efab, ®, FCN_RX_CFG_REG_KER );
3472 EFAB_SET_OWORD_FIELD_VER ( efab, reg, FCN_RX_USR_BUF_SIZE,
3474 if ( efab->pci_revision == FALCON_REV_B0)
3475 EFAB_SET_OWORD_FIELD ( reg, FCN_RX_INGR_EN_B0, 1 );
3476 EFAB_SET_OWORD_FIELD_VER ( efab, reg, FCN_RX_XON_MAC_TH,
3478 EFAB_SET_OWORD_FIELD_VER ( efab, reg, FCN_RX_XOFF_MAC_TH,
3480 EFAB_SET_OWORD_FIELD_VER ( efab, reg, FCN_RX_XOFF_MAC_EN, tx_fc);
3481 falcon_write ( efab, ®, FCN_RX_CFG_REG_KER );
3483 /* Set timer register */
3484 EFAB_POPULATE_DWORD_2 ( timer_cmd,
3485 FCN_TIMER_MODE, FCN_TIMER_MODE_DIS,
3487 falcon_writel ( efab, &timer_cmd, FCN_TIMER_CMD_REG_KER );
3491 falcon_init_resources ( struct efab_nic *efab )
3493 struct efab_ev_queue *ev_queue = &efab->ev_queue;
3494 struct efab_rx_queue *rx_queue = &efab->rx_queue;
3495 struct efab_tx_queue *tx_queue = &efab->tx_queue;
3500 /* Initialise the ptrs */
3501 tx_queue->read_ptr = tx_queue->write_ptr = 0;
3502 rx_queue->read_ptr = rx_queue->write_ptr = 0;
3503 ev_queue->read_ptr = 0;
3505 /* Push the event queue to the hardware */
3506 EFAB_POPULATE_OWORD_3 ( reg,
3508 FCN_EVQ_SIZE, FQS(FCN_EVQ, EFAB_EVQ_SIZE),
3509 FCN_EVQ_BUF_BASE_ID, ev_queue->entry.id );
3510 falcon_write ( efab, ®,
3511 FCN_REVISION_REG ( efab, FCN_EVQ_PTR_TBL_KER ) );
3513 /* Push the tx queue to the hardware */
3514 EFAB_POPULATE_OWORD_8 ( reg,
3516 FCN_TX_ISCSI_DDIG_EN, 0,
3517 FCN_TX_ISCSI_DDIG_EN, 0,
3518 FCN_TX_DESCQ_BUF_BASE_ID, tx_queue->entry.id,
3519 FCN_TX_DESCQ_EVQ_ID, 0,
3520 FCN_TX_DESCQ_SIZE, FQS(FCN_TX_DESCQ, EFAB_TXD_SIZE),
3521 FCN_TX_DESCQ_TYPE, 0 /* kernel queue */,
3522 FCN_TX_NON_IP_DROP_DIS_B0, 1 );
3523 falcon_write ( efab, ®,
3524 FCN_REVISION_REG ( efab, FCN_TX_DESC_PTR_TBL_KER ) );
3526 /* Push the rx queue to the hardware */
3527 jumbo = ( efab->pci_revision == FALCON_REV_B0 ) ? 0 : 1;
3528 EFAB_POPULATE_OWORD_8 ( reg,
3529 FCN_RX_ISCSI_DDIG_EN, 0,
3530 FCN_RX_ISCSI_HDIG_EN, 0,
3531 FCN_RX_DESCQ_BUF_BASE_ID, rx_queue->entry.id,
3532 FCN_RX_DESCQ_EVQ_ID, 0,
3533 FCN_RX_DESCQ_SIZE, FQS(FCN_RX_DESCQ, EFAB_RXD_SIZE),
3534 FCN_RX_DESCQ_TYPE, 0 /* kernel queue */,
3535 FCN_RX_DESCQ_JUMBO, jumbo,
3536 FCN_RX_DESCQ_EN, 1 );
3537 falcon_write ( efab, ®,
3538 FCN_REVISION_REG ( efab, FCN_RX_DESC_PTR_TBL_KER ) );
3540 /* Program INT_ADR_REG_KER */
3541 EFAB_POPULATE_OWORD_1 ( reg,
3542 FCN_INT_ADR_KER, virt_to_bus ( &efab->int_ker ) );
3543 falcon_write ( efab, ®, FCN_INT_ADR_REG_KER );
3545 /* Ack the event queue */
3546 falcon_eventq_read_ack ( efab, ev_queue );
3550 falcon_fini_resources ( struct efab_nic *efab )
3554 /* Disable interrupts */
3555 falcon_interrupts ( efab, 0, 0 );
3557 /* Flush the dma queues */
3558 EFAB_POPULATE_OWORD_2 ( cmd,
3559 FCN_TX_FLUSH_DESCQ_CMD, 1,
3560 FCN_TX_FLUSH_DESCQ, 0 );
3561 falcon_write ( efab, &cmd,
3562 FCN_REVISION_REG ( efab, FCN_TX_DESC_PTR_TBL_KER ) );
3564 EFAB_POPULATE_OWORD_2 ( cmd,
3565 FCN_RX_FLUSH_DESCQ_CMD, 1,
3566 FCN_RX_FLUSH_DESCQ, 0 );
3567 falcon_write ( efab, &cmd,
3568 FCN_REVISION_REG ( efab, FCN_RX_DESC_PTR_TBL_KER ) );
3572 /* Remove descriptor rings from card */
3573 EFAB_ZERO_OWORD ( cmd );
3574 falcon_write ( efab, &cmd,
3575 FCN_REVISION_REG ( efab, FCN_TX_DESC_PTR_TBL_KER ) );
3576 falcon_write ( efab, &cmd,
3577 FCN_REVISION_REG ( efab, FCN_RX_DESC_PTR_TBL_KER ) );
3578 falcon_write ( efab, &cmd,
3579 FCN_REVISION_REG ( efab, FCN_EVQ_PTR_TBL_KER ) );
3582 /*******************************************************************************
3588 *******************************************************************************/
3591 falcon_build_rx_desc ( falcon_rx_desc_t *rxd, struct io_buffer *iob )
3593 EFAB_POPULATE_QWORD_2 ( *rxd,
3594 FCN_RX_KER_BUF_SIZE, EFAB_RX_BUF_SIZE,
3595 FCN_RX_KER_BUF_ADR, virt_to_bus ( iob->data ) );
3599 falcon_notify_rx_desc ( struct efab_nic *efab, struct efab_rx_queue *rx_queue )
3602 int ptr = rx_queue->write_ptr % EFAB_RXD_SIZE;
3604 EFAB_POPULATE_DWORD_1 ( reg, FCN_RX_DESC_WPTR_DWORD, ptr );
3605 falcon_writel ( efab, ®, FCN_RX_DESC_UPD_REG_KER_DWORD );
3609 /*******************************************************************************
3615 *******************************************************************************/
3618 falcon_build_tx_desc ( falcon_tx_desc_t *txd, struct io_buffer *iob )
3620 EFAB_POPULATE_QWORD_2 ( *txd,
3621 FCN_TX_KER_BYTE_CNT, iob_len ( iob ),
3622 FCN_TX_KER_BUF_ADR, virt_to_bus ( iob->data ) );
3626 falcon_notify_tx_desc ( struct efab_nic *efab,
3627 struct efab_tx_queue *tx_queue )
3630 int ptr = tx_queue->write_ptr % EFAB_TXD_SIZE;
3632 EFAB_POPULATE_DWORD_1 ( reg, FCN_TX_DESC_WPTR_DWORD, ptr );
3633 falcon_writel ( efab, ®, FCN_TX_DESC_UPD_REG_KER_DWORD );
3637 /*******************************************************************************
3640 * Software receive interface
3643 *******************************************************************************/
3646 efab_fill_rx_queue ( struct efab_nic *efab,
3647 struct efab_rx_queue *rx_queue )
3649 int fill_level = rx_queue->write_ptr - rx_queue->read_ptr;
3650 int space = EFAB_NUM_RX_DESC - fill_level - 1;
3654 int buf_id = rx_queue->write_ptr % EFAB_NUM_RX_DESC;
3655 int desc_id = rx_queue->write_ptr % EFAB_RXD_SIZE;
3656 struct io_buffer *iob;
3657 falcon_rx_desc_t *rxd;
3659 assert ( rx_queue->buf[buf_id] == NULL );
3660 iob = alloc_iob ( EFAB_RX_BUF_SIZE );
3664 EFAB_TRACE ( "pushing rx_buf[%d] iob %p data %p\n",
3665 buf_id, iob, iob->data );
3667 rx_queue->buf[buf_id] = iob;
3668 rxd = rx_queue->ring + desc_id;
3669 falcon_build_rx_desc ( rxd, iob );
3670 ++rx_queue->write_ptr;
3676 /* Push the ptr to hardware */
3677 falcon_notify_rx_desc ( efab, rx_queue );
3679 fill_level = rx_queue->write_ptr - rx_queue->read_ptr;
3680 EFAB_TRACE ( "pushed %d rx buffers to fill level %d\n",
3681 pushed, fill_level );
3684 if ( fill_level == 0 )
3690 efab_receive ( struct efab_nic *efab, unsigned int id, int len, int drop )
3692 struct efab_rx_queue *rx_queue = &efab->rx_queue;
3693 struct io_buffer *iob;
3694 unsigned int read_ptr = rx_queue->read_ptr % EFAB_RXD_SIZE;
3695 unsigned int buf_ptr = rx_queue->read_ptr % EFAB_NUM_RX_DESC;
3697 assert ( id == read_ptr );
3699 /* Pop this rx buffer out of the software ring */
3700 iob = rx_queue->buf[buf_ptr];
3701 rx_queue->buf[buf_ptr] = NULL;
3703 EFAB_TRACE ( "popping rx_buf[%d] iob %p data %p with %d bytes %s\n",
3704 id, iob, iob->data, len, drop ? "bad" : "ok" );
3706 /* Pass the packet up if required */
3710 iob_put ( iob, len );
3711 netdev_rx ( efab->netdev, iob );
3714 ++rx_queue->read_ptr;
3717 /*******************************************************************************
3720 * Software transmit interface
3723 *******************************************************************************/
3726 efab_transmit ( struct net_device *netdev, struct io_buffer *iob )
3728 struct efab_nic *efab = netdev_priv ( netdev );
3729 struct efab_tx_queue *tx_queue = &efab->tx_queue;
3730 int fill_level, space;
3731 falcon_tx_desc_t *txd;
3734 fill_level = tx_queue->write_ptr - tx_queue->read_ptr;
3735 space = EFAB_TXD_SIZE - fill_level - 1;
3739 /* Save the iobuffer for later completion */
3740 buf_id = tx_queue->write_ptr % EFAB_TXD_SIZE;
3741 assert ( tx_queue->buf[buf_id] == NULL );
3742 tx_queue->buf[buf_id] = iob;
3744 EFAB_TRACE ( "tx_buf[%d] for iob %p data %p len %zd\n",
3745 buf_id, iob, iob->data, iob_len ( iob ) );
3747 /* Form the descriptor, and push it to hardware */
3748 txd = tx_queue->ring + buf_id;
3749 falcon_build_tx_desc ( txd, iob );
3750 ++tx_queue->write_ptr;
3751 falcon_notify_tx_desc ( efab, tx_queue );
3757 efab_transmit_done ( struct efab_nic *efab, int id )
3759 struct efab_tx_queue *tx_queue = &efab->tx_queue;
3760 unsigned int read_ptr, stop;
3762 /* Complete all buffers from read_ptr up to and including id */
3763 read_ptr = tx_queue->read_ptr % EFAB_TXD_SIZE;
3764 stop = ( id + 1 ) % EFAB_TXD_SIZE;
3766 while ( read_ptr != stop ) {
3767 struct io_buffer *iob = tx_queue->buf[read_ptr];
3770 /* Complete the tx buffer */
3772 netdev_tx_complete ( efab->netdev, iob );
3773 tx_queue->buf[read_ptr] = NULL;
3775 ++tx_queue->read_ptr;
3776 read_ptr = tx_queue->read_ptr % EFAB_TXD_SIZE;
3782 /*******************************************************************************
3785 * Hardware event path
3788 *******************************************************************************/
3791 falcon_clear_interrupts ( struct efab_nic *efab )
3795 if ( efab->pci_revision == FALCON_REV_B0 ) {
3797 falcon_readl( efab, ®, INT_ISR0_B0 );
3800 /* write to the INT_ACK register */
3801 EFAB_ZERO_DWORD ( reg );
3802 falcon_writel ( efab, ®, FCN_INT_ACK_KER_REG_A1 );
3804 falcon_readl ( efab, ®,
3805 WORK_AROUND_BROKEN_PCI_READS_REG_KER_A1 );
3810 falcon_handle_event ( struct efab_nic *efab, falcon_event_t *evt )
3812 int ev_code, desc_ptr, len, drop;
3815 ev_code = EFAB_QWORD_FIELD ( *evt, FCN_EV_CODE );
3816 switch ( ev_code ) {
3817 case FCN_TX_IP_EV_DECODE:
3818 desc_ptr = EFAB_QWORD_FIELD ( *evt, FCN_TX_EV_DESC_PTR );
3819 efab_transmit_done ( efab, desc_ptr );
3822 case FCN_RX_IP_EV_DECODE:
3823 desc_ptr = EFAB_QWORD_FIELD ( *evt, FCN_RX_EV_DESC_PTR );
3824 len = EFAB_QWORD_FIELD ( *evt, FCN_RX_EV_BYTE_CNT );
3825 drop = !EFAB_QWORD_FIELD ( *evt, FCN_RX_EV_PKT_OK );
3827 efab_receive ( efab, desc_ptr, len, drop );
3831 EFAB_TRACE ( "Unknown event type %d\n", ev_code );
3836 /*******************************************************************************
3839 * Software (polling) interrupt handler
3842 *******************************************************************************/
3845 efab_poll ( struct net_device *netdev )
3847 struct efab_nic *efab = netdev_priv ( netdev );
3848 struct efab_ev_queue *ev_queue = &efab->ev_queue;
3849 struct efab_rx_queue *rx_queue = &efab->rx_queue;
3850 falcon_event_t *evt;
3852 /* Read the event queue by directly looking for events
3853 * (we don't even bother to read the eventq write ptr) */
3854 evt = ev_queue->ring + ev_queue->read_ptr;
3855 while ( falcon_event_present ( evt ) ) {
3857 EFAB_TRACE ( "Event at index 0x%x address %p is "
3858 EFAB_QWORD_FMT "\n", ev_queue->read_ptr,
3859 evt, EFAB_QWORD_VAL ( *evt ) );
3861 falcon_handle_event ( efab, evt );
3863 /* Clear the event */
3864 EFAB_SET_QWORD ( *evt );
3866 /* Move to the next event. We don't ack the event
3867 * queue until the end */
3868 ev_queue->read_ptr = ( ( ev_queue->read_ptr + 1 ) %
3870 evt = ev_queue->ring + ev_queue->read_ptr;
3873 /* Push more buffers if needed */
3874 (void) efab_fill_rx_queue ( efab, rx_queue );
3876 /* Clear any pending interrupts */
3877 falcon_clear_interrupts ( efab );
3879 /* Ack the event queue */
3880 falcon_eventq_read_ack ( efab, ev_queue );
3884 efab_irq ( struct net_device *netdev, int enable )
3886 struct efab_nic *efab = netdev_priv ( netdev );
3887 struct efab_ev_queue *ev_queue = &efab->ev_queue;
3891 falcon_interrupts ( efab, 0, 0 );
3894 falcon_interrupts ( efab, 1, 0 );
3895 falcon_eventq_read_ack ( efab, ev_queue );
3898 falcon_interrupts ( efab, 1, 1 );
3903 /*******************************************************************************
3906 * Software open/close
3909 *******************************************************************************/
3912 efab_free_resources ( struct efab_nic *efab )
3914 struct efab_ev_queue *ev_queue = &efab->ev_queue;
3915 struct efab_rx_queue *rx_queue = &efab->rx_queue;
3916 struct efab_tx_queue *tx_queue = &efab->tx_queue;
3919 for ( i = 0; i < EFAB_NUM_RX_DESC; i++ ) {
3920 if ( rx_queue->buf[i] )
3921 free_iob ( rx_queue->buf[i] );
3924 for ( i = 0; i < EFAB_TXD_SIZE; i++ ) {
3925 if ( tx_queue->buf[i] )
3926 netdev_tx_complete ( efab->netdev, tx_queue->buf[i] );
3929 if ( rx_queue->ring )
3930 falcon_free_special_buffer ( rx_queue->ring );
3932 if ( tx_queue->ring )
3933 falcon_free_special_buffer ( tx_queue->ring );
3935 if ( ev_queue->ring )
3936 falcon_free_special_buffer ( ev_queue->ring );
3938 memset ( rx_queue, 0, sizeof ( *rx_queue ) );
3939 memset ( tx_queue, 0, sizeof ( *tx_queue ) );
3940 memset ( ev_queue, 0, sizeof ( *ev_queue ) );
3942 /* Ensure subsequent buffer allocations start at id 0 */
3943 efab->buffer_head = 0;
3947 efab_alloc_resources ( struct efab_nic *efab )
3949 struct efab_ev_queue *ev_queue = &efab->ev_queue;
3950 struct efab_rx_queue *rx_queue = &efab->rx_queue;
3951 struct efab_tx_queue *tx_queue = &efab->tx_queue;
3954 /* Allocate the hardware event queue */
3955 bytes = sizeof ( falcon_event_t ) * EFAB_TXD_SIZE;
3956 ev_queue->ring = falcon_alloc_special_buffer ( efab, bytes,
3958 if ( !ev_queue->ring )
3961 /* Initialise the hardware event queue */
3962 memset ( ev_queue->ring, 0xff, bytes );
3964 /* Allocate the hardware tx queue */
3965 bytes = sizeof ( falcon_tx_desc_t ) * EFAB_TXD_SIZE;
3966 tx_queue->ring = falcon_alloc_special_buffer ( efab, bytes,
3968 if ( ! tx_queue->ring )
3971 /* Allocate the hardware rx queue */
3972 bytes = sizeof ( falcon_rx_desc_t ) * EFAB_RXD_SIZE;
3973 rx_queue->ring = falcon_alloc_special_buffer ( efab, bytes,
3975 if ( ! rx_queue->ring )
3981 falcon_free_special_buffer ( tx_queue->ring );
3982 tx_queue->ring = NULL;
3984 falcon_free_special_buffer ( ev_queue->ring );
3985 ev_queue->ring = NULL;
3991 efab_init_mac ( struct efab_nic *efab )
3995 /* This can take several seconds */
3996 EFAB_LOG ( "Waiting for link..\n" );
3997 for ( count=0; count<5; count++ ) {
3998 rc = efab->mac_op->init ( efab );
4000 EFAB_ERR ( "Failed reinitialising MAC, error %s\n",
4005 /* Sleep for 2s to wait for the link to settle, either
4006 * because we want to use it, or because we're about
4007 * to reset the mac anyway
4011 if ( ! efab->link_up ) {
4016 EFAB_LOG ( "\n%dMbps %s-duplex\n",
4017 ( efab->link_options & LPA_EF_10000 ? 10000 :
4018 ( efab->link_options & LPA_EF_1000 ? 1000 :
4019 ( efab->link_options & LPA_100 ? 100 : 10 ) ) ),
4020 ( efab->link_options & LPA_EF_DUPLEX ?
4021 "full" : "half" ) );
4023 /* TODO: Move link state handling to the poll() routine */
4024 netdev_link_up ( efab->netdev );
4028 EFAB_ERR ( "timed initialising MAC\n" );
4033 efab_close ( struct net_device *netdev )
4035 struct efab_nic *efab = netdev_priv ( netdev );
4037 falcon_fini_resources ( efab );
4038 efab_free_resources ( efab );
4039 efab->board_op->fini ( efab );
4040 falcon_reset ( efab );
4044 efab_open ( struct net_device *netdev )
4046 struct efab_nic *efab = netdev_priv ( netdev );
4047 struct efab_rx_queue *rx_queue = &efab->rx_queue;
4050 rc = falcon_reset ( efab );
4054 rc = efab->board_op->init ( efab );
4058 rc = falcon_init_sram ( efab );
4062 /* Configure descriptor caches before pushing hardware queues */
4063 falcon_setup_nic ( efab );
4065 rc = efab_alloc_resources ( efab );
4069 falcon_init_resources ( efab );
4071 /* Push rx buffers */
4072 rc = efab_fill_rx_queue ( efab, rx_queue );
4076 /* Try and bring the interface up */
4077 rc = efab_init_mac ( efab );
4085 efab_free_resources ( efab );
4088 efab->board_op->fini ( efab );
4090 falcon_reset ( efab );
4095 static struct net_device_operations efab_operations = {
4097 .close = efab_close,
4098 .transmit = efab_transmit,
4104 efab_remove ( struct pci_device *pci )
4106 struct net_device *netdev = pci_get_drvdata ( pci );
4107 struct efab_nic *efab = netdev_priv ( netdev );
4109 if ( efab->membase ) {
4110 falcon_reset ( efab );
4112 iounmap ( efab->membase );
4113 efab->membase = NULL;
4116 if ( efab->nvo.nvs ) {
4117 unregister_nvo ( &efab->nvo );
4118 efab->nvo.nvs = NULL;
4121 unregister_netdev ( netdev );
4122 netdev_nullify ( netdev );
4123 netdev_put ( netdev );
4127 efab_probe ( struct pci_device *pci )
4129 struct net_device *netdev;
4130 struct efab_nic *efab;
4131 unsigned long mmio_start, mmio_len;
4134 /* Create the network adapter */
4135 netdev = alloc_etherdev ( sizeof ( struct efab_nic ) );
4141 /* Initialise the network adapter, and initialise private storage */
4142 netdev_init ( netdev, &efab_operations );
4143 pci_set_drvdata ( pci, netdev );
4144 netdev->dev = &pci->dev;
4146 efab = netdev_priv ( netdev );
4147 memset ( efab, 0, sizeof ( *efab ) );
4148 efab->netdev = netdev;
4150 /* Get iobase/membase */
4151 mmio_start = pci_bar_start ( pci, PCI_BASE_ADDRESS_2 );
4152 mmio_len = pci_bar_size ( pci, PCI_BASE_ADDRESS_2 );
4153 efab->membase = ioremap ( mmio_start, mmio_len );
4154 EFAB_TRACE ( "BAR of %lx bytes at phys %lx mapped at %p\n",
4155 mmio_len, mmio_start, efab->membase );
4157 /* Enable the PCI device */
4158 adjust_pci_device ( pci );
4159 efab->iobase = pci->ioaddr & ~3;
4161 /* Determine the NIC variant */
4162 falcon_probe_nic_variant ( efab, pci );
4164 /* Read the SPI interface and determine the MAC address,
4165 * and the board and phy variant. Hook in the op tables */
4166 rc = falcon_probe_spi ( efab );
4169 rc = falcon_probe_nvram ( efab );
4173 memcpy ( netdev->hw_addr, efab->mac_addr, ETH_ALEN );
4175 rc = register_netdev ( netdev );
4178 netdev_link_up ( netdev );
4180 /* Advertise non-volatile storage */
4181 if ( efab->nvo.nvs ) {
4182 rc = register_nvo ( &efab->nvo, netdev_settings ( netdev ) );
4187 EFAB_LOG ( "Found %s EtherFabric %s %s revision %d\n", pci->id->name,
4188 efab->is_asic ? "ASIC" : "FPGA",
4189 efab->phy_10g ? "10G" : "1G",
4190 efab->pci_revision );
4195 unregister_netdev ( netdev );
4199 iounmap ( efab->membase );
4200 efab->membase = NULL;
4201 netdev_put ( netdev );
4207 static struct pci_device_id efab_nics[] = {
4208 PCI_ROM(0x1924, 0x0703, "falcon", "EtherFabric Falcon", 0),
4209 PCI_ROM(0x1924, 0x0710, "falconb0", "EtherFabric FalconB0", 0),
4212 struct pci_driver etherfabric_driver __pci_driver = {
4214 .id_count = sizeof ( efab_nics ) / sizeof ( efab_nics[0] ),
4215 .probe = efab_probe,
4216 .remove = efab_remove,