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 <gpxe/malloc.h>
31 #include <gpxe/ethernet.h>
32 #include <gpxe/iobuf.h>
33 #include <gpxe/netdevice.h>
34 #include <gpxe/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_100 (LPA_100FULL | LPA_100HALF | LPA_100BASE4)
97 #define LPA_EF_1000 ( LPA_EF_1000FULL | LPA_EF_1000HALF )
98 #define LPA_EF_10000 ( LPA_EF_10000FULL | LPA_EF_10000HALF )
99 #define LPA_EF_DUPLEX ( LPA_10FULL | LPA_100FULL | LPA_EF_1000FULL | \
102 /* Mask of bits not associated with speed or duplexity. */
103 #define LPA_OTHER ~( LPA_10FULL | LPA_10HALF | LPA_100FULL | \
104 LPA_100HALF | LPA_EF_1000FULL | LPA_EF_1000HALF )
106 /* PHY-specific status register */
107 #define PSSR_LSTATUS 0x0400 /* Bit 10 - link status */
110 * Retrieve GMII autonegotiation advertised abilities
114 gmii_autoneg_advertised ( struct efab_nic
*efab
)
116 unsigned int mii_advertise
;
117 unsigned int gmii_advertise
;
119 /* Extended bits are in bits 8 and 9 of MII_CTRL1000 */
120 mii_advertise
= falcon_mdio_read ( efab
, 0, MII_ADVERTISE
);
121 gmii_advertise
= ( ( falcon_mdio_read ( efab
, 0, MII_CTRL1000
) >> 8 )
123 return ( ( gmii_advertise
<< 16 ) | mii_advertise
);
127 * Retrieve GMII autonegotiation link partner abilities
131 gmii_autoneg_lpa ( struct efab_nic
*efab
)
133 unsigned int mii_lpa
;
134 unsigned int gmii_lpa
;
136 /* Extended bits are in bits 10 and 11 of MII_STAT1000 */
137 mii_lpa
= falcon_mdio_read ( efab
, 0, MII_LPA
);
138 gmii_lpa
= ( falcon_mdio_read ( efab
, 0, MII_STAT1000
) >> 10 ) & 0x03;
139 return ( ( gmii_lpa
<< 16 ) | mii_lpa
);
143 * Calculate GMII autonegotiated link technology
147 gmii_nway_result ( unsigned int negotiated
)
149 unsigned int other_bits
;
151 /* Mask out the speed and duplexity bits */
152 other_bits
= negotiated
& LPA_OTHER
;
154 if ( negotiated
& LPA_EF_1000FULL
)
155 return ( other_bits
| LPA_EF_1000FULL
);
156 else if ( negotiated
& LPA_EF_1000HALF
)
157 return ( other_bits
| LPA_EF_1000HALF
);
158 else if ( negotiated
& LPA_100FULL
)
159 return ( other_bits
| LPA_100FULL
);
160 else if ( negotiated
& LPA_100BASE4
)
161 return ( other_bits
| LPA_100BASE4
);
162 else if ( negotiated
& LPA_100HALF
)
163 return ( other_bits
| LPA_100HALF
);
164 else if ( negotiated
& LPA_10FULL
)
165 return ( other_bits
| LPA_10FULL
);
166 else return ( other_bits
| LPA_10HALF
);
170 * Check GMII PHY link status
174 gmii_link_ok ( struct efab_nic
*efab
)
179 /* BMSR is latching - it returns "link down" if the link has
180 * been down at any point since the last read. To get a
181 * real-time status, we therefore read the register twice and
182 * use the result of the second read.
184 (void) falcon_mdio_read ( efab
, 0, MII_BMSR
);
185 status
= falcon_mdio_read ( efab
, 0, MII_BMSR
);
187 /* Read the PHY-specific Status Register. This is
188 * non-latching, so we need do only a single read.
190 phy_status
= falcon_mdio_read ( efab
, 0, GMII_PSSR
);
192 return ( ( status
& BMSR_LSTATUS
) && ( phy_status
& PSSR_LSTATUS
) );
195 /**************************************************************************
199 **************************************************************************
202 /* Numbering of the MDIO Manageable Devices (MMDs) */
203 /* Physical Medium Attachment/ Physical Medium Dependent sublayer */
204 #define MDIO_MMD_PMAPMD (1)
205 /* WAN Interface Sublayer */
206 #define MDIO_MMD_WIS (2)
207 /* Physical Coding Sublayer */
208 #define MDIO_MMD_PCS (3)
209 /* PHY Extender Sublayer */
210 #define MDIO_MMD_PHYXS (4)
211 /* Extender Sublayer */
212 #define MDIO_MMD_DTEXS (5)
213 /* Transmission convergence */
214 #define MDIO_MMD_TC (6)
215 /* Auto negotiation */
216 #define MDIO_MMD_AN (7)
218 /* Generic register locations */
219 #define MDIO_MMDREG_CTRL1 (0)
220 #define MDIO_MMDREG_STAT1 (1)
221 #define MDIO_MMDREG_DEVS0 (5)
222 #define MDIO_MMDREG_STAT2 (8)
224 /* Bits in MMDREG_CTRL1 */
226 #define MDIO_MMDREG_CTRL1_RESET_LBN (15)
227 #define MDIO_MMDREG_CTRL1_RESET_WIDTH (1)
229 /* Bits in MMDREG_STAT1 */
230 #define MDIO_MMDREG_STAT1_FAULT_LBN (7)
231 #define MDIO_MMDREG_STAT1_FAULT_WIDTH (1)
234 #define MDIO_MMDREG_STAT1_LINK_LBN (2)
235 #define MDIO_MMDREG_STAT1_LINK_WIDTH (1)
237 /* Bits in MMDREG_DEVS0. */
238 #define DEV_PRESENT_BIT(_b) (1 << _b)
240 #define MDIO_MMDREG_DEVS0_DTEXS DEV_PRESENT_BIT(MDIO_MMD_DTEXS)
241 #define MDIO_MMDREG_DEVS0_PHYXS DEV_PRESENT_BIT(MDIO_MMD_PHYXS)
242 #define MDIO_MMDREG_DEVS0_PCS DEV_PRESENT_BIT(MDIO_MMD_PCS)
243 #define MDIO_MMDREG_DEVS0_WIS DEV_PRESENT_BIT(MDIO_MMD_WIS)
244 #define MDIO_MMDREG_DEVS0_PMAPMD DEV_PRESENT_BIT(MDIO_MMD_PMAPMD)
246 #define MDIO_MMDREG_DEVS0_AN DEV_PRESENT_BIT(MDIO_MMD_AN)
248 /* Bits in MMDREG_STAT2 */
249 #define MDIO_MMDREG_STAT2_PRESENT_VAL (2)
250 #define MDIO_MMDREG_STAT2_PRESENT_LBN (14)
251 #define MDIO_MMDREG_STAT2_PRESENT_WIDTH (2)
253 /* PHY XGXS lane state */
254 #define MDIO_PHYXS_LANE_STATE (0x18)
255 #define MDIO_PHYXS_LANE_ALIGNED_LBN (12)
256 #define MDIO_PHYXS_LANE_SYNC0_LBN (0)
257 #define MDIO_PHYXS_LANE_SYNC1_LBN (1)
258 #define MDIO_PHYXS_LANE_SYNC2_LBN (2)
259 #define MDIO_PHYXS_LANE_SYNC3_LBN (3)
261 /* This ought to be ridiculous overkill. We expect it to fail rarely */
262 #define MDIO45_RESET_TRIES 100
263 #define MDIO45_RESET_SPINTIME 10
266 mdio_clause45_wait_reset_mmds ( struct efab_nic
* efab
)
268 int tries
= MDIO45_RESET_TRIES
;
272 int mask
= efab
->phy_op
->mmds
;
277 int stat
= falcon_mdio_read ( efab
, mmd
,
280 EFAB_ERR("Failed to read status of MMD %d\n",
285 if (stat
& (1 << MDIO_MMDREG_CTRL1_RESET_LBN
))
286 in_reset
|= (1 << mmd
);
294 mdelay ( MDIO45_RESET_SPINTIME
);
297 EFAB_ERR("Not all MMDs came out of reset in time. MMDs "
298 "still in reset: %x\n", in_reset
);
305 mdio_clause45_reset_mmd ( struct efab_nic
*efab
, int mmd
)
307 int tries
= MDIO45_RESET_TRIES
;
310 falcon_mdio_write ( efab
, mmd
, MDIO_MMDREG_CTRL1
,
311 ( 1 << MDIO_MMDREG_CTRL1_RESET_LBN
) );
313 /* Wait for the reset bit to clear. */
315 mdelay ( MDIO45_RESET_SPINTIME
);
317 ctrl
= falcon_mdio_read ( efab
, mmd
, MDIO_MMDREG_CTRL1
);
318 if ( ~ctrl
& ( 1 << MDIO_MMDREG_CTRL1_RESET_LBN
) )
322 EFAB_ERR ( "Failed to reset mmd %d\n", mmd
);
328 mdio_clause45_links_ok(struct efab_nic
*efab
)
333 int mmd_mask
= efab
->phy_op
->mmds
;
337 /* Double reads because link state is latched, and a
338 * read moves the current state into the register */
339 status
= falcon_mdio_read ( efab
, mmd
,
341 status
= falcon_mdio_read ( efab
, mmd
,
344 good
= status
& (1 << MDIO_MMDREG_STAT1_LINK_LBN
);
347 mmd_mask
= (mmd_mask
>> 1);
354 mdio_clause45_check_mmds ( struct efab_nic
*efab
)
357 int devices
= falcon_mdio_read ( efab
, MDIO_MMD_PHYXS
,
359 int mmd_mask
= efab
->phy_op
->mmds
;
361 /* Check all the expected MMDs are present */
363 EFAB_ERR ( "Failed to read devices present\n" );
366 if ( ( devices
& mmd_mask
) != mmd_mask
) {
367 EFAB_ERR ( "required MMDs not present: got %x, wanted %x\n",
372 /* Check all required MMDs are responding and happy. */
374 if ( mmd_mask
& 1 ) {
377 reg
.opaque
= falcon_mdio_read ( efab
, mmd
,
379 status
= EFAB_DWORD_FIELD ( reg
,
380 MDIO_MMDREG_STAT2_PRESENT
);
381 if ( status
!= MDIO_MMDREG_STAT2_PRESENT_VAL
) {
394 /* I/O BAR address register */
395 #define FCN_IOM_IND_ADR_REG 0x0
397 /* I/O BAR data register */
398 #define FCN_IOM_IND_DAT_REG 0x4
400 /* Address region register */
401 #define FCN_ADR_REGION_REG_KER 0x00
402 #define FCN_ADR_REGION0_LBN 0
403 #define FCN_ADR_REGION0_WIDTH 18
404 #define FCN_ADR_REGION1_LBN 32
405 #define FCN_ADR_REGION1_WIDTH 18
406 #define FCN_ADR_REGION2_LBN 64
407 #define FCN_ADR_REGION2_WIDTH 18
408 #define FCN_ADR_REGION3_LBN 96
409 #define FCN_ADR_REGION3_WIDTH 18
411 /* Interrupt enable register */
412 #define FCN_INT_EN_REG_KER 0x0010
413 #define FCN_MEM_PERR_INT_EN_KER_LBN 5
414 #define FCN_MEM_PERR_INT_EN_KER_WIDTH 1
415 #define FCN_KER_INT_CHAR_LBN 4
416 #define FCN_KER_INT_CHAR_WIDTH 1
417 #define FCN_KER_INT_KER_LBN 3
418 #define FCN_KER_INT_KER_WIDTH 1
419 #define FCN_ILL_ADR_ERR_INT_EN_KER_LBN 2
420 #define FCN_ILL_ADR_ERR_INT_EN_KER_WIDTH 1
421 #define FCN_SRM_PERR_INT_EN_KER_LBN 1
422 #define FCN_SRM_PERR_INT_EN_KER_WIDTH 1
423 #define FCN_DRV_INT_EN_KER_LBN 0
424 #define FCN_DRV_INT_EN_KER_WIDTH 1
426 /* Interrupt status register */
427 #define FCN_INT_ADR_REG_KER 0x0030
428 #define FCN_INT_ADR_KER_LBN 0
429 #define FCN_INT_ADR_KER_WIDTH EFAB_DMA_TYPE_WIDTH ( 64 )
431 /* Interrupt status register (B0 only) */
432 #define INT_ISR0_B0 0x90
433 #define INT_ISR1_B0 0xA0
435 /* Interrupt acknowledge register (A0/A1 only) */
436 #define FCN_INT_ACK_KER_REG_A1 0x0050
437 #define INT_ACK_DUMMY_DATA_LBN 0
438 #define INT_ACK_DUMMY_DATA_WIDTH 32
440 /* Interrupt acknowledge work-around register (A0/A1 only )*/
441 #define WORK_AROUND_BROKEN_PCI_READS_REG_KER_A1 0x0070
443 /* Hardware initialisation register */
444 #define FCN_HW_INIT_REG_KER 0x00c0
445 #define FCN_BCSR_TARGET_MASK_LBN 101
446 #define FCN_BCSR_TARGET_MASK_WIDTH 4
448 /* SPI host command register */
449 #define FCN_EE_SPI_HCMD_REG 0x0100
450 #define FCN_EE_SPI_HCMD_CMD_EN_LBN 31
451 #define FCN_EE_SPI_HCMD_CMD_EN_WIDTH 1
452 #define FCN_EE_WR_TIMER_ACTIVE_LBN 28
453 #define FCN_EE_WR_TIMER_ACTIVE_WIDTH 1
454 #define FCN_EE_SPI_HCMD_SF_SEL_LBN 24
455 #define FCN_EE_SPI_HCMD_SF_SEL_WIDTH 1
456 #define FCN_EE_SPI_EEPROM 0
457 #define FCN_EE_SPI_FLASH 1
458 #define FCN_EE_SPI_HCMD_DABCNT_LBN 16
459 #define FCN_EE_SPI_HCMD_DABCNT_WIDTH 5
460 #define FCN_EE_SPI_HCMD_READ_LBN 15
461 #define FCN_EE_SPI_HCMD_READ_WIDTH 1
462 #define FCN_EE_SPI_READ 1
463 #define FCN_EE_SPI_WRITE 0
464 #define FCN_EE_SPI_HCMD_DUBCNT_LBN 12
465 #define FCN_EE_SPI_HCMD_DUBCNT_WIDTH 2
466 #define FCN_EE_SPI_HCMD_ADBCNT_LBN 8
467 #define FCN_EE_SPI_HCMD_ADBCNT_WIDTH 2
468 #define FCN_EE_SPI_HCMD_ENC_LBN 0
469 #define FCN_EE_SPI_HCMD_ENC_WIDTH 8
471 /* SPI host address register */
472 #define FCN_EE_SPI_HADR_REG 0x0110
473 #define FCN_EE_SPI_HADR_DUBYTE_LBN 24
474 #define FCN_EE_SPI_HADR_DUBYTE_WIDTH 8
475 #define FCN_EE_SPI_HADR_ADR_LBN 0
476 #define FCN_EE_SPI_HADR_ADR_WIDTH 24
478 /* SPI host data register */
479 #define FCN_EE_SPI_HDATA_REG 0x0120
480 #define FCN_EE_SPI_HDATA3_LBN 96
481 #define FCN_EE_SPI_HDATA3_WIDTH 32
482 #define FCN_EE_SPI_HDATA2_LBN 64
483 #define FCN_EE_SPI_HDATA2_WIDTH 32
484 #define FCN_EE_SPI_HDATA1_LBN 32
485 #define FCN_EE_SPI_HDATA1_WIDTH 32
486 #define FCN_EE_SPI_HDATA0_LBN 0
487 #define FCN_EE_SPI_HDATA0_WIDTH 32
489 /* VPD Config 0 Register register */
490 #define FCN_EE_VPD_CFG_REG 0x0140
491 #define FCN_EE_VPD_EN_LBN 0
492 #define FCN_EE_VPD_EN_WIDTH 1
493 #define FCN_EE_VPD_EN_AD9_MODE_LBN 1
494 #define FCN_EE_VPD_EN_AD9_MODE_WIDTH 1
495 #define FCN_EE_EE_CLOCK_DIV_LBN 112
496 #define FCN_EE_EE_CLOCK_DIV_WIDTH 7
497 #define FCN_EE_SF_CLOCK_DIV_LBN 120
498 #define FCN_EE_SF_CLOCK_DIV_WIDTH 7
501 /* NIC status register */
502 #define FCN_NIC_STAT_REG 0x0200
503 #define FCN_ONCHIP_SRAM_LBN 16
504 #define FCN_ONCHIP_SRAM_WIDTH 1
505 #define FCN_SF_PRST_LBN 9
506 #define FCN_SF_PRST_WIDTH 1
507 #define FCN_EE_PRST_LBN 8
508 #define FCN_EE_PRST_WIDTH 1
509 #define FCN_EE_STRAP_LBN 7
510 #define FCN_EE_STRAP_WIDTH 1
511 #define FCN_PCI_PCIX_MODE_LBN 4
512 #define FCN_PCI_PCIX_MODE_WIDTH 3
513 #define FCN_PCI_PCIX_MODE_PCI33_DECODE 0
514 #define FCN_PCI_PCIX_MODE_PCI66_DECODE 1
515 #define FCN_PCI_PCIX_MODE_PCIX66_DECODE 5
516 #define FCN_PCI_PCIX_MODE_PCIX100_DECODE 6
517 #define FCN_PCI_PCIX_MODE_PCIX133_DECODE 7
518 #define FCN_STRAP_ISCSI_EN_LBN 3
519 #define FCN_STRAP_ISCSI_EN_WIDTH 1
520 #define FCN_STRAP_PINS_LBN 0
521 #define FCN_STRAP_PINS_WIDTH 3
522 #define FCN_STRAP_10G_LBN 2
523 #define FCN_STRAP_10G_WIDTH 1
524 #define FCN_STRAP_DUAL_PORT_LBN 1
525 #define FCN_STRAP_DUAL_PORT_WIDTH 1
526 #define FCN_STRAP_PCIE_LBN 0
527 #define FCN_STRAP_PCIE_WIDTH 1
529 /* Falcon revisions */
530 #define FALCON_REV_A0 0
531 #define FALCON_REV_A1 1
532 #define FALCON_REV_B0 2
534 /* GPIO control register */
535 #define FCN_GPIO_CTL_REG_KER 0x0210
536 #define FCN_GPIO_CTL_REG_KER 0x0210
538 #define FCN_GPIO3_OEN_LBN 27
539 #define FCN_GPIO3_OEN_WIDTH 1
540 #define FCN_GPIO2_OEN_LBN 26
541 #define FCN_GPIO2_OEN_WIDTH 1
542 #define FCN_GPIO1_OEN_LBN 25
543 #define FCN_GPIO1_OEN_WIDTH 1
544 #define FCN_GPIO0_OEN_LBN 24
545 #define FCN_GPIO0_OEN_WIDTH 1
547 #define FCN_GPIO3_OUT_LBN 19
548 #define FCN_GPIO3_OUT_WIDTH 1
549 #define FCN_GPIO2_OUT_LBN 18
550 #define FCN_GPIO2_OUT_WIDTH 1
551 #define FCN_GPIO1_OUT_LBN 17
552 #define FCN_GPIO1_OUT_WIDTH 1
553 #define FCN_GPIO0_OUT_LBN 16
554 #define FCN_GPIO0_OUT_WIDTH 1
556 #define FCN_GPIO3_IN_LBN 11
557 #define FCN_GPIO3_IN_WIDTH 1
558 #define FCN_GPIO2_IN_LBN 10
559 #define FCN_GPIO2_IN_WIDTH 1
560 #define FCN_GPIO1_IN_LBN 9
561 #define FCN_GPIO1_IN_WIDTH 1
562 #define FCN_GPIO0_IN_LBN 8
563 #define FCN_GPIO0_IN_WIDTH 1
565 #define FCN_FLASH_PRESENT_LBN 7
566 #define FCN_FLASH_PRESENT_WIDTH 1
567 #define FCN_EEPROM_PRESENT_LBN 6
568 #define FCN_EEPROM_PRESENT_WIDTH 1
569 #define FCN_BOOTED_USING_NVDEVICE_LBN 3
570 #define FCN_BOOTED_USING_NVDEVICE_WIDTH 1
572 /* Defines for extra non-volatile storage */
573 #define FCN_NV_MAGIC_NUMBER 0xFA1C
575 /* Global control register */
576 #define FCN_GLB_CTL_REG_KER 0x0220
577 #define FCN_EXT_PHY_RST_CTL_LBN 63
578 #define FCN_EXT_PHY_RST_CTL_WIDTH 1
579 #define FCN_PCIE_SD_RST_CTL_LBN 61
580 #define FCN_PCIE_SD_RST_CTL_WIDTH 1
581 #define FCN_PCIE_STCK_RST_CTL_LBN 59
582 #define FCN_PCIE_STCK_RST_CTL_WIDTH 1
583 #define FCN_PCIE_NSTCK_RST_CTL_LBN 58
584 #define FCN_PCIE_NSTCK_RST_CTL_WIDTH 1
585 #define FCN_PCIE_CORE_RST_CTL_LBN 57
586 #define FCN_PCIE_CORE_RST_CTL_WIDTH 1
587 #define FCN_EE_RST_CTL_LBN 49
588 #define FCN_EE_RST_CTL_WIDTH 1
589 #define FCN_RST_EXT_PHY_LBN 31
590 #define FCN_RST_EXT_PHY_WIDTH 1
591 #define FCN_EXT_PHY_RST_DUR_LBN 1
592 #define FCN_EXT_PHY_RST_DUR_WIDTH 3
593 #define FCN_SWRST_LBN 0
594 #define FCN_SWRST_WIDTH 1
595 #define INCLUDE_IN_RESET 0
596 #define EXCLUDE_FROM_RESET 1
598 /* FPGA build version */
599 #define FCN_ALTERA_BUILD_REG_KER 0x0300
600 #define FCN_VER_MAJOR_LBN 24
601 #define FCN_VER_MAJOR_WIDTH 8
602 #define FCN_VER_MINOR_LBN 16
603 #define FCN_VER_MINOR_WIDTH 8
604 #define FCN_VER_BUILD_LBN 0
605 #define FCN_VER_BUILD_WIDTH 16
606 #define FCN_VER_ALL_LBN 0
607 #define FCN_VER_ALL_WIDTH 32
609 /* Spare EEPROM bits register (flash 0x390) */
610 #define FCN_SPARE_REG_KER 0x310
611 #define FCN_MEM_PERR_EN_TX_DATA_LBN 72
612 #define FCN_MEM_PERR_EN_TX_DATA_WIDTH 2
614 /* Timer table for kernel access */
615 #define FCN_TIMER_CMD_REG_KER 0x420
616 #define FCN_TIMER_MODE_LBN 12
617 #define FCN_TIMER_MODE_WIDTH 2
618 #define FCN_TIMER_MODE_DIS 0
619 #define FCN_TIMER_MODE_INT_HLDOFF 1
620 #define FCN_TIMER_VAL_LBN 0
621 #define FCN_TIMER_VAL_WIDTH 12
623 /* Receive configuration register */
624 #define FCN_RX_CFG_REG_KER 0x800
625 #define FCN_RX_XOFF_EN_LBN 0
626 #define FCN_RX_XOFF_EN_WIDTH 1
628 /* SRAM receive descriptor cache configuration register */
629 #define FCN_SRM_RX_DC_CFG_REG_KER 0x610
630 #define FCN_SRM_RX_DC_BASE_ADR_LBN 0
631 #define FCN_SRM_RX_DC_BASE_ADR_WIDTH 21
633 /* SRAM transmit descriptor cache configuration register */
634 #define FCN_SRM_TX_DC_CFG_REG_KER 0x620
635 #define FCN_SRM_TX_DC_BASE_ADR_LBN 0
636 #define FCN_SRM_TX_DC_BASE_ADR_WIDTH 21
638 /* SRAM configuration register */
639 #define FCN_SRM_CFG_REG_KER 0x630
640 #define FCN_SRAM_OOB_ADR_INTEN_LBN 5
641 #define FCN_SRAM_OOB_ADR_INTEN_WIDTH 1
642 #define FCN_SRAM_OOB_BUF_INTEN_LBN 4
643 #define FCN_SRAM_OOB_BUF_INTEN_WIDTH 1
644 #define FCN_SRAM_OOB_BT_INIT_EN_LBN 3
645 #define FCN_SRAM_OOB_BT_INIT_EN_WIDTH 1
646 #define FCN_SRM_NUM_BANK_LBN 2
647 #define FCN_SRM_NUM_BANK_WIDTH 1
648 #define FCN_SRM_BANK_SIZE_LBN 0
649 #define FCN_SRM_BANK_SIZE_WIDTH 2
650 #define FCN_SRM_NUM_BANKS_AND_BANK_SIZE_LBN 0
651 #define FCN_SRM_NUM_BANKS_AND_BANK_SIZE_WIDTH 3
653 #define FCN_RX_CFG_REG_KER 0x800
654 #define FCN_RX_INGR_EN_B0_LBN 47
655 #define FCN_RX_INGR_EN_B0_WIDTH 1
656 #define FCN_RX_USR_BUF_SIZE_B0_LBN 19
657 #define FCN_RX_USR_BUF_SIZE_B0_WIDTH 9
658 #define FCN_RX_XON_MAC_TH_B0_LBN 10
659 #define FCN_RX_XON_MAC_TH_B0_WIDTH 9
660 #define FCN_RX_XOFF_MAC_TH_B0_LBN 1
661 #define FCN_RX_XOFF_MAC_TH_B0_WIDTH 9
662 #define FCN_RX_XOFF_MAC_EN_B0_LBN 0
663 #define FCN_RX_XOFF_MAC_EN_B0_WIDTH 1
664 #define FCN_RX_USR_BUF_SIZE_A1_LBN 11
665 #define FCN_RX_USR_BUF_SIZE_A1_WIDTH 9
666 #define FCN_RX_XON_MAC_TH_A1_LBN 6
667 #define FCN_RX_XON_MAC_TH_A1_WIDTH 5
668 #define FCN_RX_XOFF_MAC_TH_A1_LBN 1
669 #define FCN_RX_XOFF_MAC_TH_A1_WIDTH 5
670 #define FCN_RX_XOFF_MAC_EN_A1_LBN 0
671 #define FCN_RX_XOFF_MAC_EN_A1_WIDTH 1
673 #define FCN_RX_USR_BUF_SIZE_A1_LBN 11
674 #define FCN_RX_USR_BUF_SIZE_A1_WIDTH 9
675 #define FCN_RX_XOFF_MAC_EN_A1_LBN 0
676 #define FCN_RX_XOFF_MAC_EN_A1_WIDTH 1
678 /* Receive filter control register */
679 #define FCN_RX_FILTER_CTL_REG_KER 0x810
680 #define FCN_UDP_FULL_SRCH_LIMIT_LBN 32
681 #define FCN_UDP_FULL_SRCH_LIMIT_WIDTH 8
682 #define FCN_NUM_KER_LBN 24
683 #define FCN_NUM_KER_WIDTH 2
684 #define FCN_UDP_WILD_SRCH_LIMIT_LBN 16
685 #define FCN_UDP_WILD_SRCH_LIMIT_WIDTH 8
686 #define FCN_TCP_WILD_SRCH_LIMIT_LBN 8
687 #define FCN_TCP_WILD_SRCH_LIMIT_WIDTH 8
688 #define FCN_TCP_FULL_SRCH_LIMIT_LBN 0
689 #define FCN_TCP_FULL_SRCH_LIMIT_WIDTH 8
691 /* RX queue flush register */
692 #define FCN_RX_FLUSH_DESCQ_REG_KER 0x0820
693 #define FCN_RX_FLUSH_DESCQ_CMD_LBN 24
694 #define FCN_RX_FLUSH_DESCQ_CMD_WIDTH 1
695 #define FCN_RX_FLUSH_DESCQ_LBN 0
696 #define FCN_RX_FLUSH_DESCQ_WIDTH 12
698 /* Receive descriptor update register */
699 #define FCN_RX_DESC_UPD_REG_KER 0x0830
700 #define FCN_RX_DESC_WPTR_LBN 96
701 #define FCN_RX_DESC_WPTR_WIDTH 12
702 #define FCN_RX_DESC_UPD_REG_KER_DWORD ( FCN_RX_DESC_UPD_REG_KER + 12 )
703 #define FCN_RX_DESC_WPTR_DWORD_LBN 0
704 #define FCN_RX_DESC_WPTR_DWORD_WIDTH 12
706 /* Receive descriptor cache configuration register */
707 #define FCN_RX_DC_CFG_REG_KER 0x840
708 #define FCN_RX_DC_SIZE_LBN 0
709 #define FCN_RX_DC_SIZE_WIDTH 2
711 #define FCN_RX_SELF_RST_REG_KER 0x890
712 #define FCN_RX_ISCSI_DIS_LBN 17
713 #define FCN_RX_ISCSI_DIS_WIDTH 1
714 #define FCN_RX_NODESC_WAIT_DIS_LBN 9
715 #define FCN_RX_NODESC_WAIT_DIS_WIDTH 1
716 #define FCN_RX_RECOVERY_EN_LBN 8
717 #define FCN_RX_RECOVERY_EN_WIDTH 1
719 /* TX queue flush register */
720 #define FCN_TX_FLUSH_DESCQ_REG_KER 0x0a00
721 #define FCN_TX_FLUSH_DESCQ_CMD_LBN 12
722 #define FCN_TX_FLUSH_DESCQ_CMD_WIDTH 1
723 #define FCN_TX_FLUSH_DESCQ_LBN 0
724 #define FCN_TX_FLUSH_DESCQ_WIDTH 12
726 /* Transmit configuration register 2 */
727 #define FCN_TX_CFG2_REG_KER 0xa80
728 #define FCN_TX_DIS_NON_IP_EV_LBN 17
729 #define FCN_TX_DIS_NON_IP_EV_WIDTH 1
731 /* Transmit descriptor update register */
732 #define FCN_TX_DESC_UPD_REG_KER 0x0a10
733 #define FCN_TX_DESC_WPTR_LBN 96
734 #define FCN_TX_DESC_WPTR_WIDTH 12
735 #define FCN_TX_DESC_UPD_REG_KER_DWORD ( FCN_TX_DESC_UPD_REG_KER + 12 )
736 #define FCN_TX_DESC_WPTR_DWORD_LBN 0
737 #define FCN_TX_DESC_WPTR_DWORD_WIDTH 12
739 /* Transmit descriptor cache configuration register */
740 #define FCN_TX_DC_CFG_REG_KER 0xa20
741 #define FCN_TX_DC_SIZE_LBN 0
742 #define FCN_TX_DC_SIZE_WIDTH 2
744 /* PHY management transmit data register */
745 #define FCN_MD_TXD_REG_KER 0xc00
746 #define FCN_MD_TXD_LBN 0
747 #define FCN_MD_TXD_WIDTH 16
749 /* PHY management receive data register */
750 #define FCN_MD_RXD_REG_KER 0xc10
751 #define FCN_MD_RXD_LBN 0
752 #define FCN_MD_RXD_WIDTH 16
754 /* PHY management configuration & status register */
755 #define FCN_MD_CS_REG_KER 0xc20
756 #define FCN_MD_GC_LBN 4
757 #define FCN_MD_GC_WIDTH 1
758 #define FCN_MD_RIC_LBN 2
759 #define FCN_MD_RIC_WIDTH 1
760 #define FCN_MD_RDC_LBN 1
761 #define FCN_MD_RDC_WIDTH 1
762 #define FCN_MD_WRC_LBN 0
763 #define FCN_MD_WRC_WIDTH 1
765 /* PHY management PHY address register */
766 #define FCN_MD_PHY_ADR_REG_KER 0xc30
767 #define FCN_MD_PHY_ADR_LBN 0
768 #define FCN_MD_PHY_ADR_WIDTH 16
770 /* PHY management ID register */
771 #define FCN_MD_ID_REG_KER 0xc40
772 #define FCN_MD_PRT_ADR_LBN 11
773 #define FCN_MD_PRT_ADR_WIDTH 5
774 #define FCN_MD_DEV_ADR_LBN 6
775 #define FCN_MD_DEV_ADR_WIDTH 5
777 /* PHY management status & mask register */
778 #define FCN_MD_STAT_REG_KER 0xc50
779 #define FCN_MD_PINT_LBN 4
780 #define FCN_MD_PINT_WIDTH 1
781 #define FCN_MD_DONE_LBN 3
782 #define FCN_MD_DONE_WIDTH 1
783 #define FCN_MD_BSERR_LBN 2
784 #define FCN_MD_BSERR_WIDTH 1
785 #define FCN_MD_LNFL_LBN 1
786 #define FCN_MD_LNFL_WIDTH 1
787 #define FCN_MD_BSY_LBN 0
788 #define FCN_MD_BSY_WIDTH 1
790 /* Port 0 and 1 MAC control registers */
791 #define FCN_MAC0_CTRL_REG_KER 0xc80
792 #define FCN_MAC1_CTRL_REG_KER 0xc90
793 #define FCN_MAC_XOFF_VAL_LBN 16
794 #define FCN_MAC_XOFF_VAL_WIDTH 16
795 #define FCN_MAC_BCAD_ACPT_LBN 4
796 #define FCN_MAC_BCAD_ACPT_WIDTH 1
797 #define FCN_MAC_UC_PROM_LBN 3
798 #define FCN_MAC_UC_PROM_WIDTH 1
799 #define FCN_MAC_LINK_STATUS_LBN 2
800 #define FCN_MAC_LINK_STATUS_WIDTH 1
801 #define FCN_MAC_SPEED_LBN 0
802 #define FCN_MAC_SPEED_WIDTH 2
804 /* 10Gig Xaui XGXS Default Values */
805 #define XX_TXDRV_DEQ_DEFAULT 0xe /* deq=.6 */
806 #define XX_TXDRV_DTX_DEFAULT 0x5 /* 1.25 */
807 #define XX_SD_CTL_DRV_DEFAULT 0 /* 20mA */
810 #define FALCON_GMAC_REGBANK 0xe00
811 #define FALCON_GMAC_REGBANK_SIZE 0x200
812 #define FALCON_GMAC_REG_SIZE 0x10
814 /* XGMAC registers */
815 #define FALCON_XMAC_REGBANK 0x1200
816 #define FALCON_XMAC_REGBANK_SIZE 0x200
817 #define FALCON_XMAC_REG_SIZE 0x10
819 /* XGMAC address register low */
820 #define FCN_XM_ADR_LO_REG_MAC 0x00
821 #define FCN_XM_ADR_3_LBN 24
822 #define FCN_XM_ADR_3_WIDTH 8
823 #define FCN_XM_ADR_2_LBN 16
824 #define FCN_XM_ADR_2_WIDTH 8
825 #define FCN_XM_ADR_1_LBN 8
826 #define FCN_XM_ADR_1_WIDTH 8
827 #define FCN_XM_ADR_0_LBN 0
828 #define FCN_XM_ADR_0_WIDTH 8
830 /* XGMAC address register high */
831 #define FCN_XM_ADR_HI_REG_MAC 0x01
832 #define FCN_XM_ADR_5_LBN 8
833 #define FCN_XM_ADR_5_WIDTH 8
834 #define FCN_XM_ADR_4_LBN 0
835 #define FCN_XM_ADR_4_WIDTH 8
837 /* XGMAC global configuration - port 0*/
838 #define FCN_XM_GLB_CFG_REG_MAC 0x02
839 #define FCN_XM_RX_STAT_EN_LBN 11
840 #define FCN_XM_RX_STAT_EN_WIDTH 1
841 #define FCN_XM_TX_STAT_EN_LBN 10
842 #define FCN_XM_TX_STAT_EN_WIDTH 1
843 #define FCN_XM_RX_JUMBO_MODE_LBN 6
844 #define FCN_XM_RX_JUMBO_MODE_WIDTH 1
845 #define FCN_XM_CORE_RST_LBN 0
846 #define FCN_XM_CORE_RST_WIDTH 1
848 /* XGMAC transmit configuration - port 0 */
849 #define FCN_XM_TX_CFG_REG_MAC 0x03
850 #define FCN_XM_IPG_LBN 16
851 #define FCN_XM_IPG_WIDTH 4
852 #define FCN_XM_FCNTL_LBN 10
853 #define FCN_XM_FCNTL_WIDTH 1
854 #define FCN_XM_TXCRC_LBN 8
855 #define FCN_XM_TXCRC_WIDTH 1
856 #define FCN_XM_AUTO_PAD_LBN 5
857 #define FCN_XM_AUTO_PAD_WIDTH 1
858 #define FCN_XM_TX_PRMBL_LBN 2
859 #define FCN_XM_TX_PRMBL_WIDTH 1
860 #define FCN_XM_TXEN_LBN 1
861 #define FCN_XM_TXEN_WIDTH 1
863 /* XGMAC receive configuration - port 0 */
864 #define FCN_XM_RX_CFG_REG_MAC 0x04
865 #define FCN_XM_PASS_CRC_ERR_LBN 25
866 #define FCN_XM_PASS_CRC_ERR_WIDTH 1
867 #define FCN_XM_AUTO_DEPAD_LBN 8
868 #define FCN_XM_AUTO_DEPAD_WIDTH 1
869 #define FCN_XM_RXEN_LBN 1
870 #define FCN_XM_RXEN_WIDTH 1
872 /* XGMAC management interrupt mask register */
873 #define FCN_XM_MGT_INT_MSK_REG_MAC_B0 0x5
874 #define FCN_XM_MSK_PRMBLE_ERR_LBN 2
875 #define FCN_XM_MSK_PRMBLE_ERR_WIDTH 1
876 #define FCN_XM_MSK_RMTFLT_LBN 1
877 #define FCN_XM_MSK_RMTFLT_WIDTH 1
878 #define FCN_XM_MSK_LCLFLT_LBN 0
879 #define FCN_XM_MSK_LCLFLT_WIDTH 1
881 /* XGMAC flow control register */
882 #define FCN_XM_FC_REG_MAC 0x7
883 #define FCN_XM_PAUSE_TIME_LBN 16
884 #define FCN_XM_PAUSE_TIME_WIDTH 16
885 #define FCN_XM_DIS_FCNTL_LBN 0
886 #define FCN_XM_DIS_FCNTL_WIDTH 1
888 /* XGMAC transmit parameter register */
889 #define FCN_XM_TX_PARAM_REG_MAC 0x0d
890 #define FCN_XM_TX_JUMBO_MODE_LBN 31
891 #define FCN_XM_TX_JUMBO_MODE_WIDTH 1
892 #define FCN_XM_MAX_TX_FRM_SIZE_LBN 16
893 #define FCN_XM_MAX_TX_FRM_SIZE_WIDTH 14
894 #define FCN_XM_ACPT_ALL_MCAST_LBN 11
895 #define FCN_XM_ACPT_ALL_MCAST_WIDTH 1
897 /* XGMAC receive parameter register */
898 #define FCN_XM_RX_PARAM_REG_MAC 0x0e
899 #define FCN_XM_MAX_RX_FRM_SIZE_LBN 0
900 #define FCN_XM_MAX_RX_FRM_SIZE_WIDTH 14
902 /* XGMAC management interrupt status register */
903 #define FCN_XM_MGT_INT_REG_MAC_B0 0x0f
904 #define FCN_XM_PRMBLE_ERR 2
905 #define FCN_XM_PRMBLE_WIDTH 1
906 #define FCN_XM_RMTFLT_LBN 1
907 #define FCN_XM_RMTFLT_WIDTH 1
908 #define FCN_XM_LCLFLT_LBN 0
909 #define FCN_XM_LCLFLT_WIDTH 1
911 /* XAUI XGXS core status register */
912 #define FCN_XX_ALIGN_DONE_LBN 20
913 #define FCN_XX_ALIGN_DONE_WIDTH 1
914 #define FCN_XX_CORE_STAT_REG_MAC 0x16
915 #define FCN_XX_SYNC_STAT_LBN 16
916 #define FCN_XX_SYNC_STAT_WIDTH 4
917 #define FCN_XX_SYNC_STAT_DECODE_SYNCED 0xf
918 #define FCN_XX_COMMA_DET_LBN 12
919 #define FCN_XX_COMMA_DET_WIDTH 4
920 #define FCN_XX_COMMA_DET_RESET 0xf
921 #define FCN_XX_CHARERR_LBN 4
922 #define FCN_XX_CHARERR_WIDTH 4
923 #define FCN_XX_CHARERR_RESET 0xf
924 #define FCN_XX_DISPERR_LBN 0
925 #define FCN_XX_DISPERR_WIDTH 4
926 #define FCN_XX_DISPERR_RESET 0xf
928 /* XGXS/XAUI powerdown/reset register */
929 #define FCN_XX_PWR_RST_REG_MAC 0x10
930 #define FCN_XX_PWRDND_EN_LBN 15
931 #define FCN_XX_PWRDND_EN_WIDTH 1
932 #define FCN_XX_PWRDNC_EN_LBN 14
933 #define FCN_XX_PWRDNC_EN_WIDTH 1
934 #define FCN_XX_PWRDNB_EN_LBN 13
935 #define FCN_XX_PWRDNB_EN_WIDTH 1
936 #define FCN_XX_PWRDNA_EN_LBN 12
937 #define FCN_XX_PWRDNA_EN_WIDTH 1
938 #define FCN_XX_RSTPLLCD_EN_LBN 9
939 #define FCN_XX_RSTPLLCD_EN_WIDTH 1
940 #define FCN_XX_RSTPLLAB_EN_LBN 8
941 #define FCN_XX_RSTPLLAB_EN_WIDTH 1
942 #define FCN_XX_RESETD_EN_LBN 7
943 #define FCN_XX_RESETD_EN_WIDTH 1
944 #define FCN_XX_RESETC_EN_LBN 6
945 #define FCN_XX_RESETC_EN_WIDTH 1
946 #define FCN_XX_RESETB_EN_LBN 5
947 #define FCN_XX_RESETB_EN_WIDTH 1
948 #define FCN_XX_RESETA_EN_LBN 4
949 #define FCN_XX_RESETA_EN_WIDTH 1
950 #define FCN_XX_RSTXGXSRX_EN_LBN 2
951 #define FCN_XX_RSTXGXSRX_EN_WIDTH 1
952 #define FCN_XX_RSTXGXSTX_EN_LBN 1
953 #define FCN_XX_RSTXGXSTX_EN_WIDTH 1
954 #define FCN_XX_RST_XX_EN_LBN 0
955 #define FCN_XX_RST_XX_EN_WIDTH 1
958 /* XGXS/XAUI powerdown/reset control register */
959 #define FCN_XX_SD_CTL_REG_MAC 0x11
960 #define FCN_XX_TERMADJ1_LBN 17
961 #define FCN_XX_TERMADJ1_WIDTH 1
962 #define FCN_XX_TERMADJ0_LBN 16
963 #define FCN_XX_TERMADJ0_WIDTH 1
964 #define FCN_XX_HIDRVD_LBN 15
965 #define FCN_XX_HIDRVD_WIDTH 1
966 #define FCN_XX_LODRVD_LBN 14
967 #define FCN_XX_LODRVD_WIDTH 1
968 #define FCN_XX_HIDRVC_LBN 13
969 #define FCN_XX_HIDRVC_WIDTH 1
970 #define FCN_XX_LODRVC_LBN 12
971 #define FCN_XX_LODRVC_WIDTH 1
972 #define FCN_XX_HIDRVB_LBN 11
973 #define FCN_XX_HIDRVB_WIDTH 1
974 #define FCN_XX_LODRVB_LBN 10
975 #define FCN_XX_LODRVB_WIDTH 1
976 #define FCN_XX_HIDRVA_LBN 9
977 #define FCN_XX_HIDRVA_WIDTH 1
978 #define FCN_XX_LODRVA_LBN 8
979 #define FCN_XX_LODRVA_WIDTH 1
980 #define FCN_XX_LPBKD_LBN 3
981 #define FCN_XX_LPBKD_WIDTH 1
982 #define FCN_XX_LPBKC_LBN 2
983 #define FCN_XX_LPBKC_WIDTH 1
984 #define FCN_XX_LPBKB_LBN 1
985 #define FCN_XX_LPBKB_WIDTH 1
986 #define FCN_XX_LPBKA_LBN 0
987 #define FCN_XX_LPBKA_WIDTH 1
989 #define FCN_XX_TXDRV_CTL_REG_MAC 0x12
990 #define FCN_XX_DEQD_LBN 28
991 #define FCN_XX_DEQD_WIDTH 4
992 #define FCN_XX_DEQC_LBN 24
993 #define FCN_XX_DEQC_WIDTH 4
994 #define FCN_XX_DEQB_LBN 20
995 #define FCN_XX_DEQB_WIDTH 4
996 #define FCN_XX_DEQA_LBN 16
997 #define FCN_XX_DEQA_WIDTH 4
998 #define FCN_XX_DTXD_LBN 12
999 #define FCN_XX_DTXD_WIDTH 4
1000 #define FCN_XX_DTXC_LBN 8
1001 #define FCN_XX_DTXC_WIDTH 4
1002 #define FCN_XX_DTXB_LBN 4
1003 #define FCN_XX_DTXB_WIDTH 4
1004 #define FCN_XX_DTXA_LBN 0
1005 #define FCN_XX_DTXA_WIDTH 4
1007 /* Receive filter table */
1008 #define FCN_RX_FILTER_TBL0 0xF00000
1010 /* Receive descriptor pointer table */
1011 #define FCN_RX_DESC_PTR_TBL_KER_A1 0x11800
1012 #define FCN_RX_DESC_PTR_TBL_KER_B0 0xF40000
1013 #define FCN_RX_ISCSI_DDIG_EN_LBN 88
1014 #define FCN_RX_ISCSI_DDIG_EN_WIDTH 1
1015 #define FCN_RX_ISCSI_HDIG_EN_LBN 87
1016 #define FCN_RX_ISCSI_HDIG_EN_WIDTH 1
1017 #define FCN_RX_DESCQ_BUF_BASE_ID_LBN 36
1018 #define FCN_RX_DESCQ_BUF_BASE_ID_WIDTH 20
1019 #define FCN_RX_DESCQ_EVQ_ID_LBN 24
1020 #define FCN_RX_DESCQ_EVQ_ID_WIDTH 12
1021 #define FCN_RX_DESCQ_OWNER_ID_LBN 10
1022 #define FCN_RX_DESCQ_OWNER_ID_WIDTH 14
1023 #define FCN_RX_DESCQ_SIZE_LBN 3
1024 #define FCN_RX_DESCQ_SIZE_WIDTH 2
1025 #define FCN_RX_DESCQ_SIZE_4K 3
1026 #define FCN_RX_DESCQ_SIZE_2K 2
1027 #define FCN_RX_DESCQ_SIZE_1K 1
1028 #define FCN_RX_DESCQ_SIZE_512 0
1029 #define FCN_RX_DESCQ_TYPE_LBN 2
1030 #define FCN_RX_DESCQ_TYPE_WIDTH 1
1031 #define FCN_RX_DESCQ_JUMBO_LBN 1
1032 #define FCN_RX_DESCQ_JUMBO_WIDTH 1
1033 #define FCN_RX_DESCQ_EN_LBN 0
1034 #define FCN_RX_DESCQ_EN_WIDTH 1
1036 /* Transmit descriptor pointer table */
1037 #define FCN_TX_DESC_PTR_TBL_KER_A1 0x11900
1038 #define FCN_TX_DESC_PTR_TBL_KER_B0 0xF50000
1039 #define FCN_TX_NON_IP_DROP_DIS_B0_LBN 91
1040 #define FCN_TX_NON_IP_DROP_DIS_B0_WIDTH 1
1041 #define FCN_TX_DESCQ_EN_LBN 88
1042 #define FCN_TX_DESCQ_EN_WIDTH 1
1043 #define FCN_TX_ISCSI_DDIG_EN_LBN 87
1044 #define FCN_TX_ISCSI_DDIG_EN_WIDTH 1
1045 #define FCN_TX_ISCSI_HDIG_EN_LBN 86
1046 #define FCN_TX_ISCSI_HDIG_EN_WIDTH 1
1047 #define FCN_TX_DESCQ_BUF_BASE_ID_LBN 36
1048 #define FCN_TX_DESCQ_BUF_BASE_ID_WIDTH 20
1049 #define FCN_TX_DESCQ_EVQ_ID_LBN 24
1050 #define FCN_TX_DESCQ_EVQ_ID_WIDTH 12
1051 #define FCN_TX_DESCQ_OWNER_ID_LBN 10
1052 #define FCN_TX_DESCQ_OWNER_ID_WIDTH 14
1053 #define FCN_TX_DESCQ_SIZE_LBN 3
1054 #define FCN_TX_DESCQ_SIZE_WIDTH 2
1055 #define FCN_TX_DESCQ_SIZE_4K 3
1056 #define FCN_TX_DESCQ_SIZE_2K 2
1057 #define FCN_TX_DESCQ_SIZE_1K 1
1058 #define FCN_TX_DESCQ_SIZE_512 0
1059 #define FCN_TX_DESCQ_TYPE_LBN 1
1060 #define FCN_TX_DESCQ_TYPE_WIDTH 2
1061 #define FCN_TX_DESCQ_FLUSH_LBN 0
1062 #define FCN_TX_DESCQ_FLUSH_WIDTH 1
1064 /* Event queue pointer */
1065 #define FCN_EVQ_PTR_TBL_KER_A1 0x11a00
1066 #define FCN_EVQ_PTR_TBL_KER_B0 0xf60000
1067 #define FCN_EVQ_EN_LBN 23
1068 #define FCN_EVQ_EN_WIDTH 1
1069 #define FCN_EVQ_SIZE_LBN 20
1070 #define FCN_EVQ_SIZE_WIDTH 3
1071 #define FCN_EVQ_SIZE_32K 6
1072 #define FCN_EVQ_SIZE_16K 5
1073 #define FCN_EVQ_SIZE_8K 4
1074 #define FCN_EVQ_SIZE_4K 3
1075 #define FCN_EVQ_SIZE_2K 2
1076 #define FCN_EVQ_SIZE_1K 1
1077 #define FCN_EVQ_SIZE_512 0
1078 #define FCN_EVQ_BUF_BASE_ID_LBN 0
1079 #define FCN_EVQ_BUF_BASE_ID_WIDTH 20
1081 /* RSS indirection table */
1082 #define FCN_RX_RSS_INDIR_TBL_B0 0xFB0000
1084 /* Event queue read pointer */
1085 #define FCN_EVQ_RPTR_REG_KER_A1 0x11b00
1086 #define FCN_EVQ_RPTR_REG_KER_B0 0xfa0000
1087 #define FCN_EVQ_RPTR_LBN 0
1088 #define FCN_EVQ_RPTR_WIDTH 14
1089 #define FCN_EVQ_RPTR_REG_KER_DWORD_A1 ( FCN_EVQ_RPTR_REG_KER_A1 + 0 )
1090 #define FCN_EVQ_RPTR_REG_KER_DWORD_B0 ( FCN_EVQ_RPTR_REG_KER_B0 + 0 )
1091 #define FCN_EVQ_RPTR_DWORD_LBN 0
1092 #define FCN_EVQ_RPTR_DWORD_WIDTH 14
1094 /* Special buffer descriptors */
1095 #define FCN_BUF_FULL_TBL_KER_A1 0x18000
1096 #define FCN_BUF_FULL_TBL_KER_B0 0x800000
1097 #define FCN_IP_DAT_BUF_SIZE_LBN 50
1098 #define FCN_IP_DAT_BUF_SIZE_WIDTH 1
1099 #define FCN_IP_DAT_BUF_SIZE_8K 1
1100 #define FCN_IP_DAT_BUF_SIZE_4K 0
1101 #define FCN_BUF_ADR_FBUF_LBN 14
1102 #define FCN_BUF_ADR_FBUF_WIDTH 34
1103 #define FCN_BUF_OWNER_ID_FBUF_LBN 0
1104 #define FCN_BUF_OWNER_ID_FBUF_WIDTH 14
1106 /** Offset of a GMAC register within Falcon */
1107 #define FALCON_GMAC_REG( efab, mac_reg ) \
1108 ( FALCON_GMAC_REGBANK + \
1109 ( (mac_reg) * FALCON_GMAC_REG_SIZE ) )
1111 /** Offset of an XMAC register within Falcon */
1112 #define FALCON_XMAC_REG( efab_port, mac_reg ) \
1113 ( FALCON_XMAC_REGBANK + \
1114 ( (mac_reg) * FALCON_XMAC_REG_SIZE ) )
1116 #define FCN_MAC_DATA_LBN 0
1117 #define FCN_MAC_DATA_WIDTH 32
1119 /* Transmit descriptor */
1120 #define FCN_TX_KER_PORT_LBN 63
1121 #define FCN_TX_KER_PORT_WIDTH 1
1122 #define FCN_TX_KER_BYTE_CNT_LBN 48
1123 #define FCN_TX_KER_BYTE_CNT_WIDTH 14
1124 #define FCN_TX_KER_BUF_ADR_LBN 0
1125 #define FCN_TX_KER_BUF_ADR_WIDTH EFAB_DMA_TYPE_WIDTH ( 46 )
1128 /* Receive descriptor */
1129 #define FCN_RX_KER_BUF_SIZE_LBN 48
1130 #define FCN_RX_KER_BUF_SIZE_WIDTH 14
1131 #define FCN_RX_KER_BUF_ADR_LBN 0
1132 #define FCN_RX_KER_BUF_ADR_WIDTH EFAB_DMA_TYPE_WIDTH ( 46 )
1134 /* Event queue entries */
1135 #define FCN_EV_CODE_LBN 60
1136 #define FCN_EV_CODE_WIDTH 4
1137 #define FCN_RX_IP_EV_DECODE 0
1138 #define FCN_TX_IP_EV_DECODE 2
1139 #define FCN_DRIVER_EV_DECODE 5
1141 /* Receive events */
1142 #define FCN_RX_EV_PKT_OK_LBN 56
1143 #define FCN_RX_EV_PKT_OK_WIDTH 1
1144 #define FCN_RX_PORT_LBN 30
1145 #define FCN_RX_PORT_WIDTH 1
1146 #define FCN_RX_EV_BYTE_CNT_LBN 16
1147 #define FCN_RX_EV_BYTE_CNT_WIDTH 14
1148 #define FCN_RX_EV_DESC_PTR_LBN 0
1149 #define FCN_RX_EV_DESC_PTR_WIDTH 12
1151 /* Transmit events */
1152 #define FCN_TX_EV_DESC_PTR_LBN 0
1153 #define FCN_TX_EV_DESC_PTR_WIDTH 12
1155 /*******************************************************************************
1158 * Low-level hardware access
1161 *******************************************************************************/
1163 #define FCN_REVISION_REG(efab, reg) \
1164 ( ( efab->pci_revision == FALCON_REV_B0 ) ? reg ## _B0 : reg ## _A1 )
1166 #define EFAB_SET_OWORD_FIELD_VER(efab, reg, field, val) \
1167 if ( efab->pci_revision == FALCON_REV_B0 ) \
1168 EFAB_SET_OWORD_FIELD ( reg, field ## _B0, val ); \
1170 EFAB_SET_OWORD_FIELD ( reg, field ## _A1, val );
1172 #if FALCON_USE_IO_BAR
1174 /* Write dword via the I/O BAR */
1175 static inline void _falcon_writel ( struct efab_nic
*efab
, uint32_t value
,
1176 unsigned int reg
) {
1177 outl ( reg
, efab
->iobase
+ FCN_IOM_IND_ADR_REG
);
1178 outl ( value
, efab
->iobase
+ FCN_IOM_IND_DAT_REG
);
1181 /* Read dword via the I/O BAR */
1182 static inline uint32_t _falcon_readl ( struct efab_nic
*efab
,
1183 unsigned int reg
) {
1184 outl ( reg
, efab
->iobase
+ FCN_IOM_IND_ADR_REG
);
1185 return inl ( efab
->iobase
+ FCN_IOM_IND_DAT_REG
);
1188 #else /* FALCON_USE_IO_BAR */
1190 #define _falcon_writel( efab, value, reg ) \
1191 writel ( (value), (efab)->membase + (reg) )
1192 #define _falcon_readl( efab, reg ) readl ( (efab)->membase + (reg) )
1194 #endif /* FALCON_USE_IO_BAR */
1197 * Write to a Falcon register
1201 falcon_write ( struct efab_nic
*efab
, efab_oword_t
*value
, unsigned int reg
)
1204 EFAB_REGDUMP ( "Writing register %x with " EFAB_OWORD_FMT
"\n",
1205 reg
, EFAB_OWORD_VAL ( *value
) );
1207 _falcon_writel ( efab
, value
->u32
[0], reg
+ 0 );
1208 _falcon_writel ( efab
, value
->u32
[1], reg
+ 4 );
1209 _falcon_writel ( efab
, value
->u32
[2], reg
+ 8 );
1211 _falcon_writel ( efab
, value
->u32
[3], reg
+ 12 );
1216 * Write to Falcon SRAM
1220 falcon_write_sram ( struct efab_nic
*efab
, efab_qword_t
*value
,
1221 unsigned int index
)
1223 unsigned int reg
= ( FCN_REVISION_REG ( efab
, FCN_BUF_FULL_TBL_KER
) +
1224 ( index
* sizeof ( *value
) ) );
1226 EFAB_REGDUMP ( "Writing SRAM register %x with " EFAB_QWORD_FMT
"\n",
1227 reg
, EFAB_QWORD_VAL ( *value
) );
1229 _falcon_writel ( efab
, value
->u32
[0], reg
+ 0 );
1230 _falcon_writel ( efab
, value
->u32
[1], reg
+ 4 );
1235 * Write dword to Falcon register that allows partial writes
1239 falcon_writel ( struct efab_nic
*efab
, efab_dword_t
*value
, unsigned int reg
)
1241 EFAB_REGDUMP ( "Writing partial register %x with " EFAB_DWORD_FMT
"\n",
1242 reg
, EFAB_DWORD_VAL ( *value
) );
1243 _falcon_writel ( efab
, value
->u32
[0], reg
);
1247 * Read from a Falcon register
1251 falcon_read ( struct efab_nic
*efab
, efab_oword_t
*value
, unsigned int reg
)
1253 value
->u32
[0] = _falcon_readl ( efab
, reg
+ 0 );
1255 value
->u32
[1] = _falcon_readl ( efab
, reg
+ 4 );
1256 value
->u32
[2] = _falcon_readl ( efab
, reg
+ 8 );
1257 value
->u32
[3] = _falcon_readl ( efab
, reg
+ 12 );
1259 EFAB_REGDUMP ( "Read from register %x, got " EFAB_OWORD_FMT
"\n",
1260 reg
, EFAB_OWORD_VAL ( *value
) );
1264 * Read from Falcon SRAM
1268 falcon_read_sram ( struct efab_nic
*efab
, efab_qword_t
*value
,
1269 unsigned int index
)
1271 unsigned int reg
= ( FCN_REVISION_REG ( efab
, FCN_BUF_FULL_TBL_KER
) +
1272 ( index
* sizeof ( *value
) ) );
1274 value
->u32
[0] = _falcon_readl ( efab
, reg
+ 0 );
1275 value
->u32
[1] = _falcon_readl ( efab
, reg
+ 4 );
1276 EFAB_REGDUMP ( "Read from SRAM register %x, got " EFAB_QWORD_FMT
"\n",
1277 reg
, EFAB_QWORD_VAL ( *value
) );
1281 * Read dword from a portion of a Falcon register
1285 falcon_readl ( struct efab_nic
*efab
, efab_dword_t
*value
, unsigned int reg
)
1287 value
->u32
[0] = _falcon_readl ( efab
, reg
);
1288 EFAB_REGDUMP ( "Read from register %x, got " EFAB_DWORD_FMT
"\n",
1289 reg
, EFAB_DWORD_VAL ( *value
) );
1292 #define FCN_DUMP_REG( efab, _reg ) do { \
1294 falcon_read ( efab, ®, _reg ); \
1295 EFAB_LOG ( #_reg " = " EFAB_OWORD_FMT "\n", \
1296 EFAB_OWORD_VAL ( reg ) ); \
1299 #define FCN_DUMP_MAC_REG( efab, _mac_reg ) do { \
1301 efab->mac_op->mac_readl ( efab, ®, _mac_reg ); \
1302 EFAB_LOG ( #_mac_reg " = " EFAB_DWORD_FMT "\n", \
1303 EFAB_DWORD_VAL ( reg ) ); \
1307 * See if an event is present
1309 * @v event Falcon event structure
1310 * @ret True An event is pending
1311 * @ret False No event is pending
1313 * We check both the high and low dword of the event for all ones. We
1314 * wrote all ones when we cleared the event, and no valid event can
1315 * have all ones in either its high or low dwords. This approach is
1316 * robust against reordering.
1318 * Note that using a single 64-bit comparison is incorrect; even
1319 * though the CPU read will be atomic, the DMA write may not be.
1322 falcon_event_present ( falcon_event_t
* event
)
1324 return ( ! ( EFAB_DWORD_IS_ALL_ONES ( event
->dword
[0] ) |
1325 EFAB_DWORD_IS_ALL_ONES ( event
->dword
[1] ) ) );
1329 falcon_eventq_read_ack ( struct efab_nic
*efab
, struct efab_ev_queue
*ev_queue
)
1333 EFAB_POPULATE_DWORD_1 ( reg
, FCN_EVQ_RPTR_DWORD
, ev_queue
->read_ptr
);
1334 falcon_writel ( efab
, ®
,
1335 FCN_REVISION_REG ( efab
, FCN_EVQ_RPTR_REG_KER_DWORD
) );
1340 * Dump register contents (for debugging)
1342 * Marked as static inline so that it will not be compiled in if not
1346 falcon_dump_regs ( struct efab_nic
*efab
)
1348 FCN_DUMP_REG ( efab
, FCN_INT_EN_REG_KER
);
1349 FCN_DUMP_REG ( efab
, FCN_INT_ADR_REG_KER
);
1350 FCN_DUMP_REG ( efab
, FCN_GLB_CTL_REG_KER
);
1351 FCN_DUMP_REG ( efab
, FCN_TIMER_CMD_REG_KER
);
1352 FCN_DUMP_REG ( efab
, FCN_SRM_RX_DC_CFG_REG_KER
);
1353 FCN_DUMP_REG ( efab
, FCN_SRM_TX_DC_CFG_REG_KER
);
1354 FCN_DUMP_REG ( efab
, FCN_RX_FILTER_CTL_REG_KER
);
1355 FCN_DUMP_REG ( efab
, FCN_RX_DC_CFG_REG_KER
);
1356 FCN_DUMP_REG ( efab
, FCN_TX_DC_CFG_REG_KER
);
1357 FCN_DUMP_REG ( efab
, FCN_MAC0_CTRL_REG_KER
);
1358 FCN_DUMP_REG ( efab
, FCN_MAC1_CTRL_REG_KER
);
1359 FCN_DUMP_REG ( efab
, FCN_REVISION_REG ( efab
, FCN_RX_DESC_PTR_TBL_KER
) );
1360 FCN_DUMP_REG ( efab
, FCN_REVISION_REG ( efab
, FCN_TX_DESC_PTR_TBL_KER
) );
1361 FCN_DUMP_REG ( efab
, FCN_REVISION_REG ( efab
, FCN_EVQ_PTR_TBL_KER
) );
1362 FCN_DUMP_MAC_REG ( efab
, GM_CFG1_REG_MAC
);
1363 FCN_DUMP_MAC_REG ( efab
, GM_CFG2_REG_MAC
);
1364 FCN_DUMP_MAC_REG ( efab
, GM_MAX_FLEN_REG_MAC
);
1365 FCN_DUMP_MAC_REG ( efab
, GM_MII_MGMT_CFG_REG_MAC
);
1366 FCN_DUMP_MAC_REG ( efab
, GM_ADR1_REG_MAC
);
1367 FCN_DUMP_MAC_REG ( efab
, GM_ADR2_REG_MAC
);
1368 FCN_DUMP_MAC_REG ( efab
, GMF_CFG0_REG_MAC
);
1369 FCN_DUMP_MAC_REG ( efab
, GMF_CFG1_REG_MAC
);
1370 FCN_DUMP_MAC_REG ( efab
, GMF_CFG2_REG_MAC
);
1371 FCN_DUMP_MAC_REG ( efab
, GMF_CFG3_REG_MAC
);
1372 FCN_DUMP_MAC_REG ( efab
, GMF_CFG4_REG_MAC
);
1373 FCN_DUMP_MAC_REG ( efab
, GMF_CFG5_REG_MAC
);
1378 falcon_interrupts ( struct efab_nic
*efab
, int enabled
, int force
)
1380 efab_oword_t int_en_reg_ker
;
1382 EFAB_POPULATE_OWORD_2 ( int_en_reg_ker
,
1383 FCN_KER_INT_KER
, force
,
1384 FCN_DRV_INT_EN_KER
, enabled
);
1385 falcon_write ( efab
, &int_en_reg_ker
, FCN_INT_EN_REG_KER
);
1388 /*******************************************************************************
1394 *******************************************************************************/
1397 /** Maximum length for a single SPI transaction */
1398 #define FALCON_SPI_MAX_LEN 16
1401 falcon_spi_wait ( struct efab_nic
*efab
)
1409 falcon_read ( efab
, ®
, FCN_EE_SPI_HCMD_REG
);
1410 if ( EFAB_OWORD_FIELD ( reg
, FCN_EE_SPI_HCMD_CMD_EN
) == 0 )
1412 } while ( ++count
< 1000 );
1414 EFAB_ERR ( "Timed out waiting for SPI\n" );
1419 falcon_spi_rw ( struct spi_bus
* bus
, struct spi_device
*device
,
1420 unsigned int command
, int address
,
1421 const void* data_out
, void *data_in
, size_t len
)
1423 struct efab_nic
*efab
= container_of ( bus
, struct efab_nic
, spi_bus
);
1424 int address_len
, rc
, device_id
, read_cmd
;
1427 /* falcon_init_spi_device() should have reduced the block size
1428 * down so this constraint holds */
1429 assert ( len
<= FALCON_SPI_MAX_LEN
);
1431 /* Is this the FLASH or EEPROM device? */
1432 if ( device
== &efab
->spi_flash
)
1433 device_id
= FCN_EE_SPI_FLASH
;
1434 else if ( device
== &efab
->spi_eeprom
)
1435 device_id
= FCN_EE_SPI_EEPROM
;
1437 EFAB_ERR ( "Unknown device %p\n", device
);
1441 EFAB_TRACE ( "Executing spi command %d on device %d at %d for %zd bytes\n",
1442 command
, device_id
, address
, len
);
1444 /* The bus must be idle */
1445 rc
= falcon_spi_wait ( efab
);
1451 memcpy ( ®
, data_out
, len
);
1452 falcon_write ( efab
, ®
, FCN_EE_SPI_HDATA_REG
);
1455 /* Program address register */
1456 if ( address
>= 0 ) {
1457 EFAB_POPULATE_OWORD_1 ( reg
, FCN_EE_SPI_HADR_ADR
, address
);
1458 falcon_write ( efab
, ®
, FCN_EE_SPI_HADR_REG
);
1462 address_len
= ( address
>= 0 ) ? device
->address_len
/ 8 : 0;
1463 read_cmd
= ( data_in
? FCN_EE_SPI_READ
: FCN_EE_SPI_WRITE
);
1464 EFAB_POPULATE_OWORD_7 ( reg
,
1465 FCN_EE_SPI_HCMD_CMD_EN
, 1,
1466 FCN_EE_SPI_HCMD_SF_SEL
, device_id
,
1467 FCN_EE_SPI_HCMD_DABCNT
, len
,
1468 FCN_EE_SPI_HCMD_READ
, read_cmd
,
1469 FCN_EE_SPI_HCMD_DUBCNT
, 0,
1470 FCN_EE_SPI_HCMD_ADBCNT
, address_len
,
1471 FCN_EE_SPI_HCMD_ENC
, command
);
1472 falcon_write ( efab
, ®
, FCN_EE_SPI_HCMD_REG
);
1474 /* Wait for the command to complete */
1475 rc
= falcon_spi_wait ( efab
);
1481 falcon_read ( efab
, ®
, FCN_EE_SPI_HDATA_REG
);
1482 memcpy ( data_in
, ®
, len
);
1489 EFAB_ERR ( "Failed SPI command %d to device %d address 0x%x len 0x%zx\n",
1490 command
, device_id
, address
, len
);
1495 /** Portion of EEPROM available for non-volatile options */
1496 static struct nvo_fragment falcon_nvo_fragments
[] = {
1501 /*******************************************************************************
1504 * Falcon bit-bashed I2C interface
1507 *******************************************************************************/
1510 falcon_i2c_bit_write ( struct bit_basher
*basher
, unsigned int bit_id
,
1511 unsigned long data
)
1513 struct efab_nic
*efab
= container_of ( basher
, struct efab_nic
,
1517 falcon_read ( efab
, ®
, FCN_GPIO_CTL_REG_KER
);
1520 EFAB_SET_OWORD_FIELD ( reg
, FCN_GPIO0_OEN
, ( data
? 0 : 1 ) );
1523 EFAB_SET_OWORD_FIELD ( reg
, FCN_GPIO3_OEN
, ( data
? 0 : 1 ) );
1526 EFAB_ERR ( "%s bit=%d\n", __func__
, bit_id
);
1530 falcon_write ( efab
, ®
, FCN_GPIO_CTL_REG_KER
);
1534 falcon_i2c_bit_read ( struct bit_basher
*basher
, unsigned int bit_id
)
1536 struct efab_nic
*efab
= container_of ( basher
, struct efab_nic
,
1540 falcon_read ( efab
, ®
, FCN_GPIO_CTL_REG_KER
);
1543 return EFAB_OWORD_FIELD ( reg
, FCN_GPIO0_IN
);
1546 return EFAB_OWORD_FIELD ( reg
, FCN_GPIO3_IN
);
1549 EFAB_ERR ( "%s bit=%d\n", __func__
, bit_id
);
1556 static struct bit_basher_operations falcon_i2c_bit_ops
= {
1557 .read
= falcon_i2c_bit_read
,
1558 .write
= falcon_i2c_bit_write
,
1562 /*******************************************************************************
1568 *******************************************************************************/
1571 falcon_gmii_wait ( struct efab_nic
*efab
)
1573 efab_dword_t md_stat
;
1576 /* wait upto 10ms */
1577 for (count
= 0; count
< 1000; count
++) {
1578 falcon_readl ( efab
, &md_stat
, FCN_MD_STAT_REG_KER
);
1579 if ( EFAB_DWORD_FIELD ( md_stat
, FCN_MD_BSY
) == 0 ) {
1580 if ( EFAB_DWORD_FIELD ( md_stat
, FCN_MD_LNFL
) != 0 ||
1581 EFAB_DWORD_FIELD ( md_stat
, FCN_MD_BSERR
) != 0 ) {
1582 EFAB_ERR ( "Error from GMII access "
1584 EFAB_DWORD_VAL ( md_stat
));
1592 EFAB_ERR ( "Timed out waiting for GMII\n" );
1597 falcon_mdio_write ( struct efab_nic
*efab
, int device
,
1598 int location
, int value
)
1602 EFAB_TRACE ( "Writing GMII %d register %02x with %04x\n",
1603 device
, location
, value
);
1605 /* Check MII not currently being accessed */
1606 if ( falcon_gmii_wait ( efab
) )
1609 /* Write the address/ID register */
1610 EFAB_POPULATE_OWORD_1 ( reg
, FCN_MD_PHY_ADR
, location
);
1611 falcon_write ( efab
, ®
, FCN_MD_PHY_ADR_REG_KER
);
1613 if ( efab
->phy_10g
) {
1615 EFAB_POPULATE_OWORD_2 ( reg
,
1616 FCN_MD_PRT_ADR
, efab
->phy_addr
,
1617 FCN_MD_DEV_ADR
, device
);
1621 assert ( device
== 0 );
1623 EFAB_POPULATE_OWORD_2 ( reg
,
1624 FCN_MD_PRT_ADR
, efab
->phy_addr
,
1625 FCN_MD_DEV_ADR
, location
);
1627 falcon_write ( efab
, ®
, FCN_MD_ID_REG_KER
);
1631 EFAB_POPULATE_OWORD_1 ( reg
, FCN_MD_TXD
, value
);
1632 falcon_write ( efab
, ®
, FCN_MD_TXD_REG_KER
);
1634 EFAB_POPULATE_OWORD_2 ( reg
,
1636 FCN_MD_GC
, ( efab
->phy_10g
? 0 : 1 ) );
1637 falcon_write ( efab
, ®
, FCN_MD_CS_REG_KER
);
1639 /* Wait for data to be written */
1640 if ( falcon_gmii_wait ( efab
) ) {
1641 /* Abort the write operation */
1642 EFAB_POPULATE_OWORD_2 ( reg
,
1645 falcon_write ( efab
, ®
, FCN_MD_CS_REG_KER
);
1651 falcon_mdio_read ( struct efab_nic
*efab
, int device
, int location
)
1656 /* Check MII not currently being accessed */
1657 if ( falcon_gmii_wait ( efab
) )
1660 if ( efab
->phy_10g
) {
1662 EFAB_POPULATE_OWORD_1 ( reg
, FCN_MD_PHY_ADR
, location
);
1663 falcon_write ( efab
, ®
, FCN_MD_PHY_ADR_REG_KER
);
1665 EFAB_POPULATE_OWORD_2 ( reg
,
1666 FCN_MD_PRT_ADR
, efab
->phy_addr
,
1667 FCN_MD_DEV_ADR
, device
);
1668 falcon_write ( efab
, ®
, FCN_MD_ID_REG_KER
);
1670 /* request data to be read */
1671 EFAB_POPULATE_OWORD_2 ( reg
,
1677 assert ( device
== 0 );
1679 EFAB_POPULATE_OWORD_2 ( reg
,
1680 FCN_MD_PRT_ADR
, efab
->phy_addr
,
1681 FCN_MD_DEV_ADR
, location
);
1682 falcon_write ( efab
, ®
, FCN_MD_ID_REG_KER
);
1684 /* Request data to be read */
1685 EFAB_POPULATE_OWORD_2 ( reg
,
1690 falcon_write ( efab
, ®
, FCN_MD_CS_REG_KER
);
1692 /* Wait for data to become available */
1693 if ( falcon_gmii_wait ( efab
) ) {
1694 /* Abort the read operation */
1695 EFAB_POPULATE_OWORD_2 ( reg
,
1698 falcon_write ( efab
, ®
, FCN_MD_CS_REG_KER
);
1704 falcon_read ( efab
, ®
, FCN_MD_RXD_REG_KER
);
1705 value
= EFAB_OWORD_FIELD ( reg
, FCN_MD_RXD
);
1708 EFAB_TRACE ( "Read from GMII %d register %02x, got %04x\n",
1709 device
, location
, value
);
1714 /*******************************************************************************
1720 *******************************************************************************/
1723 falcon_reconfigure_mac_wrapper ( struct efab_nic
*efab
)
1728 if ( efab
->link_options
& LPA_EF_10000
) {
1730 } else if ( efab
->link_options
& LPA_EF_1000
) {
1732 } else if ( efab
->link_options
& LPA_100
) {
1737 EFAB_POPULATE_OWORD_5 ( reg
,
1738 FCN_MAC_XOFF_VAL
, 0xffff /* datasheet */,
1739 FCN_MAC_BCAD_ACPT
, 1,
1741 FCN_MAC_LINK_STATUS
, 1,
1742 FCN_MAC_SPEED
, link_speed
);
1744 falcon_write ( efab
, ®
, FCN_MAC0_CTRL_REG_KER
);
1747 /*******************************************************************************
1753 *******************************************************************************/
1755 /* GMAC configuration register 1 */
1756 #define GM_CFG1_REG_MAC 0x00
1757 #define GM_SW_RST_LBN 31
1758 #define GM_SW_RST_WIDTH 1
1759 #define GM_RX_FC_EN_LBN 5
1760 #define GM_RX_FC_EN_WIDTH 1
1761 #define GM_TX_FC_EN_LBN 4
1762 #define GM_TX_FC_EN_WIDTH 1
1763 #define GM_RX_EN_LBN 2
1764 #define GM_RX_EN_WIDTH 1
1765 #define GM_TX_EN_LBN 0
1766 #define GM_TX_EN_WIDTH 1
1768 /* GMAC configuration register 2 */
1769 #define GM_CFG2_REG_MAC 0x01
1770 #define GM_PAMBL_LEN_LBN 12
1771 #define GM_PAMBL_LEN_WIDTH 4
1772 #define GM_IF_MODE_LBN 8
1773 #define GM_IF_MODE_WIDTH 2
1774 #define GM_PAD_CRC_EN_LBN 2
1775 #define GM_PAD_CRC_EN_WIDTH 1
1777 #define GM_FD_WIDTH 1
1779 /* GMAC maximum frame length register */
1780 #define GM_MAX_FLEN_REG_MAC 0x04
1781 #define GM_MAX_FLEN_LBN 0
1782 #define GM_MAX_FLEN_WIDTH 16
1784 /* GMAC MII management configuration register */
1785 #define GM_MII_MGMT_CFG_REG_MAC 0x08
1786 #define GM_MGMT_CLK_SEL_LBN 0
1787 #define GM_MGMT_CLK_SEL_WIDTH 3
1789 /* GMAC MII management command register */
1790 #define GM_MII_MGMT_CMD_REG_MAC 0x09
1791 #define GM_MGMT_SCAN_CYC_LBN 1
1792 #define GM_MGMT_SCAN_CYC_WIDTH 1
1793 #define GM_MGMT_RD_CYC_LBN 0
1794 #define GM_MGMT_RD_CYC_WIDTH 1
1796 /* GMAC MII management address register */
1797 #define GM_MII_MGMT_ADR_REG_MAC 0x0a
1798 #define GM_MGMT_PHY_ADDR_LBN 8
1799 #define GM_MGMT_PHY_ADDR_WIDTH 5
1800 #define GM_MGMT_REG_ADDR_LBN 0
1801 #define GM_MGMT_REG_ADDR_WIDTH 5
1803 /* GMAC MII management control register */
1804 #define GM_MII_MGMT_CTL_REG_MAC 0x0b
1805 #define GM_MGMT_CTL_LBN 0
1806 #define GM_MGMT_CTL_WIDTH 16
1808 /* GMAC MII management status register */
1809 #define GM_MII_MGMT_STAT_REG_MAC 0x0c
1810 #define GM_MGMT_STAT_LBN 0
1811 #define GM_MGMT_STAT_WIDTH 16
1813 /* GMAC MII management indicators register */
1814 #define GM_MII_MGMT_IND_REG_MAC 0x0d
1815 #define GM_MGMT_BUSY_LBN 0
1816 #define GM_MGMT_BUSY_WIDTH 1
1818 /* GMAC station address register 1 */
1819 #define GM_ADR1_REG_MAC 0x10
1820 #define GM_HWADDR_5_LBN 24
1821 #define GM_HWADDR_5_WIDTH 8
1822 #define GM_HWADDR_4_LBN 16
1823 #define GM_HWADDR_4_WIDTH 8
1824 #define GM_HWADDR_3_LBN 8
1825 #define GM_HWADDR_3_WIDTH 8
1826 #define GM_HWADDR_2_LBN 0
1827 #define GM_HWADDR_2_WIDTH 8
1829 /* GMAC station address register 2 */
1830 #define GM_ADR2_REG_MAC 0x11
1831 #define GM_HWADDR_1_LBN 24
1832 #define GM_HWADDR_1_WIDTH 8
1833 #define GM_HWADDR_0_LBN 16
1834 #define GM_HWADDR_0_WIDTH 8
1836 /* GMAC FIFO configuration register 0 */
1837 #define GMF_CFG0_REG_MAC 0x12
1838 #define GMF_FTFENREQ_LBN 12
1839 #define GMF_FTFENREQ_WIDTH 1
1840 #define GMF_STFENREQ_LBN 11
1841 #define GMF_STFENREQ_WIDTH 1
1842 #define GMF_FRFENREQ_LBN 10
1843 #define GMF_FRFENREQ_WIDTH 1
1844 #define GMF_SRFENREQ_LBN 9
1845 #define GMF_SRFENREQ_WIDTH 1
1846 #define GMF_WTMENREQ_LBN 8
1847 #define GMF_WTMENREQ_WIDTH 1
1849 /* GMAC FIFO configuration register 1 */
1850 #define GMF_CFG1_REG_MAC 0x13
1851 #define GMF_CFGFRTH_LBN 16
1852 #define GMF_CFGFRTH_WIDTH 5
1853 #define GMF_CFGXOFFRTX_LBN 0
1854 #define GMF_CFGXOFFRTX_WIDTH 16
1856 /* GMAC FIFO configuration register 2 */
1857 #define GMF_CFG2_REG_MAC 0x14
1858 #define GMF_CFGHWM_LBN 16
1859 #define GMF_CFGHWM_WIDTH 6
1860 #define GMF_CFGLWM_LBN 0
1861 #define GMF_CFGLWM_WIDTH 6
1863 /* GMAC FIFO configuration register 3 */
1864 #define GMF_CFG3_REG_MAC 0x15
1865 #define GMF_CFGHWMFT_LBN 16
1866 #define GMF_CFGHWMFT_WIDTH 6
1867 #define GMF_CFGFTTH_LBN 0
1868 #define GMF_CFGFTTH_WIDTH 6
1870 /* GMAC FIFO configuration register 4 */
1871 #define GMF_CFG4_REG_MAC 0x16
1872 #define GMF_HSTFLTRFRM_PAUSE_LBN 12
1873 #define GMF_HSTFLTRFRM_PAUSE_WIDTH 12
1875 /* GMAC FIFO configuration register 5 */
1876 #define GMF_CFG5_REG_MAC 0x17
1877 #define GMF_CFGHDPLX_LBN 22
1878 #define GMF_CFGHDPLX_WIDTH 1
1879 #define GMF_CFGBYTMODE_LBN 19
1880 #define GMF_CFGBYTMODE_WIDTH 1
1881 #define GMF_HSTDRPLT64_LBN 18
1882 #define GMF_HSTDRPLT64_WIDTH 1
1883 #define GMF_HSTFLTRFRMDC_PAUSE_LBN 12
1884 #define GMF_HSTFLTRFRMDC_PAUSE_WIDTH 1
1887 falcon_gmac_writel ( struct efab_nic
*efab
, efab_dword_t
*value
,
1888 unsigned int mac_reg
)
1892 EFAB_POPULATE_OWORD_1 ( temp
, FCN_MAC_DATA
,
1893 EFAB_DWORD_FIELD ( *value
, FCN_MAC_DATA
) );
1894 falcon_write ( efab
, &temp
, FALCON_GMAC_REG ( efab
, mac_reg
) );
1898 falcon_gmac_readl ( struct efab_nic
*efab
, efab_dword_t
*value
,
1899 unsigned int mac_reg
)
1903 falcon_read ( efab
, &temp
, FALCON_GMAC_REG ( efab
, mac_reg
) );
1904 EFAB_POPULATE_DWORD_1 ( *value
, FCN_MAC_DATA
,
1905 EFAB_OWORD_FIELD ( temp
, FCN_MAC_DATA
) );
1909 mentormac_reset ( struct efab_nic
*efab
)
1913 /* Take into reset */
1914 EFAB_POPULATE_DWORD_1 ( reg
, GM_SW_RST
, 1 );
1915 falcon_gmac_writel ( efab
, ®
, GM_CFG1_REG_MAC
);
1918 /* Take out of reset */
1919 EFAB_POPULATE_DWORD_1 ( reg
, GM_SW_RST
, 0 );
1920 falcon_gmac_writel ( efab
, ®
, GM_CFG1_REG_MAC
);
1923 /* Configure GMII interface so PHY is accessible. Note that
1924 * GMII interface is connected only to port 0, and that on
1925 * Falcon this is a no-op.
1927 EFAB_POPULATE_DWORD_1 ( reg
, GM_MGMT_CLK_SEL
, 0x4 );
1928 falcon_gmac_writel ( efab
, ®
, GM_MII_MGMT_CFG_REG_MAC
);
1933 mentormac_init ( struct efab_nic
*efab
)
1935 int pause
, if_mode
, full_duplex
, bytemode
, half_duplex
;
1938 /* Configuration register 1 */
1939 pause
= ( efab
->link_options
& LPA_PAUSE_CAP
) ? 1 : 0;
1940 if ( ! ( efab
->link_options
& LPA_EF_DUPLEX
) ) {
1941 /* Half-duplex operation requires TX flow control */
1944 EFAB_POPULATE_DWORD_4 ( reg
,
1949 falcon_gmac_writel ( efab
, ®
, GM_CFG1_REG_MAC
);
1952 /* Configuration register 2 */
1953 if_mode
= ( efab
->link_options
& LPA_EF_1000
) ? 2 : 1;
1954 full_duplex
= ( efab
->link_options
& LPA_EF_DUPLEX
) ? 1 : 0;
1955 EFAB_POPULATE_DWORD_4 ( reg
,
1956 GM_IF_MODE
, if_mode
,
1959 GM_PAMBL_LEN
, 0x7 /* ? */ );
1960 falcon_gmac_writel ( efab
, ®
, GM_CFG2_REG_MAC
);
1963 /* Max frame len register */
1964 EFAB_POPULATE_DWORD_1 ( reg
, GM_MAX_FLEN
,
1965 EFAB_MAX_FRAME_LEN ( ETH_FRAME_LEN
) );
1966 falcon_gmac_writel ( efab
, ®
, GM_MAX_FLEN_REG_MAC
);
1969 /* FIFO configuration register 0 */
1970 EFAB_POPULATE_DWORD_5 ( reg
,
1976 falcon_gmac_writel ( efab
, ®
, GMF_CFG0_REG_MAC
);
1979 /* FIFO configuration register 1 */
1980 EFAB_POPULATE_DWORD_2 ( reg
,
1982 GMF_CFGXOFFRTX
, 0xffff );
1983 falcon_gmac_writel ( efab
, ®
, GMF_CFG1_REG_MAC
);
1986 /* FIFO configuration register 2 */
1987 EFAB_POPULATE_DWORD_2 ( reg
,
1990 falcon_gmac_writel ( efab
, ®
, GMF_CFG2_REG_MAC
);
1993 /* FIFO configuration register 3 */
1994 EFAB_POPULATE_DWORD_2 ( reg
,
1996 GMF_CFGFTTH
, 0x08 );
1997 falcon_gmac_writel ( efab
, ®
, GMF_CFG3_REG_MAC
);
2000 /* FIFO configuration register 4 */
2001 EFAB_POPULATE_DWORD_1 ( reg
, GMF_HSTFLTRFRM_PAUSE
, 1 );
2002 falcon_gmac_writel ( efab
, ®
, GMF_CFG4_REG_MAC
);
2005 /* FIFO configuration register 5 */
2006 bytemode
= ( efab
->link_options
& LPA_EF_1000
) ? 1 : 0;
2007 half_duplex
= ( efab
->link_options
& LPA_EF_DUPLEX
) ? 0 : 1;
2008 falcon_gmac_readl ( efab
, ®
, GMF_CFG5_REG_MAC
);
2009 EFAB_SET_DWORD_FIELD ( reg
, GMF_CFGBYTMODE
, bytemode
);
2010 EFAB_SET_DWORD_FIELD ( reg
, GMF_CFGHDPLX
, half_duplex
);
2011 EFAB_SET_DWORD_FIELD ( reg
, GMF_HSTDRPLT64
, half_duplex
);
2012 EFAB_SET_DWORD_FIELD ( reg
, GMF_HSTFLTRFRMDC_PAUSE
, 0 );
2013 falcon_gmac_writel ( efab
, ®
, GMF_CFG5_REG_MAC
);
2017 EFAB_POPULATE_DWORD_4 ( reg
,
2018 GM_HWADDR_5
, efab
->mac_addr
[5],
2019 GM_HWADDR_4
, efab
->mac_addr
[4],
2020 GM_HWADDR_3
, efab
->mac_addr
[3],
2021 GM_HWADDR_2
, efab
->mac_addr
[2] );
2022 falcon_gmac_writel ( efab
, ®
, GM_ADR1_REG_MAC
);
2024 EFAB_POPULATE_DWORD_2 ( reg
,
2025 GM_HWADDR_1
, efab
->mac_addr
[1],
2026 GM_HWADDR_0
, efab
->mac_addr
[0] );
2027 falcon_gmac_writel ( efab
, ®
, GM_ADR2_REG_MAC
);
2032 falcon_init_gmac ( struct efab_nic
*efab
)
2035 mentormac_reset ( efab
);
2037 /* Initialise PHY */
2038 efab
->phy_op
->init ( efab
);
2040 /* check the link is up */
2041 if ( !efab
->link_up
)
2044 /* Initialise MAC */
2045 mentormac_init ( efab
);
2047 /* reconfigure the MAC wrapper */
2048 falcon_reconfigure_mac_wrapper ( efab
);
2053 static struct efab_mac_operations falcon_gmac_operations
= {
2054 .init
= falcon_init_gmac
,
2058 /*******************************************************************************
2064 *******************************************************************************/
2067 * Write dword to a Falcon XMAC register
2071 falcon_xmac_writel ( struct efab_nic
*efab
, efab_dword_t
*value
,
2072 unsigned int mac_reg
)
2076 EFAB_POPULATE_OWORD_1 ( temp
, FCN_MAC_DATA
,
2077 EFAB_DWORD_FIELD ( *value
, FCN_MAC_DATA
) );
2078 falcon_write ( efab
, &temp
,
2079 FALCON_XMAC_REG ( efab
, mac_reg
) );
2083 * Read dword from a Falcon XMAC register
2087 falcon_xmac_readl ( struct efab_nic
*efab
, efab_dword_t
*value
,
2088 unsigned int mac_reg
)
2092 falcon_read ( efab
, &temp
,
2093 FALCON_XMAC_REG ( efab
, mac_reg
) );
2094 EFAB_POPULATE_DWORD_1 ( *value
, FCN_MAC_DATA
,
2095 EFAB_OWORD_FIELD ( temp
, FCN_MAC_DATA
) );
2099 * Configure Falcon XAUI output
2102 falcon_setup_xaui ( struct efab_nic
*efab
)
2104 efab_dword_t sdctl
, txdrv
;
2106 falcon_xmac_readl ( efab
, &sdctl
, FCN_XX_SD_CTL_REG_MAC
);
2107 EFAB_SET_DWORD_FIELD ( sdctl
, FCN_XX_HIDRVD
, XX_SD_CTL_DRV_DEFAULT
);
2108 EFAB_SET_DWORD_FIELD ( sdctl
, FCN_XX_LODRVD
, XX_SD_CTL_DRV_DEFAULT
);
2109 EFAB_SET_DWORD_FIELD ( sdctl
, FCN_XX_HIDRVC
, XX_SD_CTL_DRV_DEFAULT
);
2110 EFAB_SET_DWORD_FIELD ( sdctl
, FCN_XX_LODRVC
, XX_SD_CTL_DRV_DEFAULT
);
2111 EFAB_SET_DWORD_FIELD ( sdctl
, FCN_XX_HIDRVB
, XX_SD_CTL_DRV_DEFAULT
);
2112 EFAB_SET_DWORD_FIELD ( sdctl
, FCN_XX_LODRVB
, XX_SD_CTL_DRV_DEFAULT
);
2113 EFAB_SET_DWORD_FIELD ( sdctl
, FCN_XX_HIDRVA
, XX_SD_CTL_DRV_DEFAULT
);
2114 EFAB_SET_DWORD_FIELD ( sdctl
, FCN_XX_LODRVA
, XX_SD_CTL_DRV_DEFAULT
);
2115 falcon_xmac_writel ( efab
, &sdctl
, FCN_XX_SD_CTL_REG_MAC
);
2117 EFAB_POPULATE_DWORD_8 ( txdrv
,
2118 FCN_XX_DEQD
, XX_TXDRV_DEQ_DEFAULT
,
2119 FCN_XX_DEQC
, XX_TXDRV_DEQ_DEFAULT
,
2120 FCN_XX_DEQB
, XX_TXDRV_DEQ_DEFAULT
,
2121 FCN_XX_DEQA
, XX_TXDRV_DEQ_DEFAULT
,
2122 FCN_XX_DTXD
, XX_TXDRV_DTX_DEFAULT
,
2123 FCN_XX_DTXC
, XX_TXDRV_DTX_DEFAULT
,
2124 FCN_XX_DTXB
, XX_TXDRV_DTX_DEFAULT
,
2125 FCN_XX_DTXA
, XX_TXDRV_DTX_DEFAULT
);
2126 falcon_xmac_writel ( efab
, &txdrv
, FCN_XX_TXDRV_CTL_REG_MAC
);
2130 falcon_xgmii_status ( struct efab_nic
*efab
)
2134 if ( efab
->pci_revision
< FALCON_REV_B0
)
2136 /* The ISR latches, so clear it and re-read */
2137 falcon_xmac_readl ( efab
, ®
, FCN_XM_MGT_INT_REG_MAC_B0
);
2138 falcon_xmac_readl ( efab
, ®
, FCN_XM_MGT_INT_REG_MAC_B0
);
2140 if ( EFAB_DWORD_FIELD ( reg
, FCN_XM_LCLFLT
) ||
2141 EFAB_DWORD_FIELD ( reg
, FCN_XM_RMTFLT
) ) {
2142 EFAB_TRACE ( "MGT_INT: "EFAB_DWORD_FMT
"\n",
2143 EFAB_DWORD_VAL ( reg
) );
2151 falcon_mask_status_intr ( struct efab_nic
*efab
, int enable
)
2155 if ( efab
->pci_revision
< FALCON_REV_B0
)
2160 falcon_xmac_readl ( efab
, ®
, FCN_XM_MGT_INT_REG_MAC_B0
);
2162 EFAB_POPULATE_DWORD_2 ( reg
,
2163 FCN_XM_MSK_RMTFLT
, !enable
,
2164 FCN_XM_MSK_LCLFLT
, !enable
);
2165 falcon_xmac_readl ( efab
, ®
, FCN_XM_MGT_INT_MSK_REG_MAC_B0
);
2169 * Reset 10G MAC connected to port
2173 falcon_reset_xmac ( struct efab_nic
*efab
)
2178 EFAB_POPULATE_DWORD_1 ( reg
, FCN_XM_CORE_RST
, 1 );
2179 falcon_xmac_writel ( efab
, ®
, FCN_XM_GLB_CFG_REG_MAC
);
2181 for ( count
= 0 ; count
< 1000 ; count
++ ) {
2183 falcon_xmac_readl ( efab
, ®
,
2184 FCN_XM_GLB_CFG_REG_MAC
);
2185 if ( EFAB_DWORD_FIELD ( reg
, FCN_XM_CORE_RST
) == 0 )
2193 falcon_reset_xaui ( struct efab_nic
*efab
)
2201 EFAB_POPULATE_DWORD_1 ( reg
, FCN_XX_RST_XX_EN
, 1 );
2202 falcon_xmac_writel ( efab
, ®
, FCN_XX_PWR_RST_REG_MAC
);
2204 /* Give some time for the link to establish */
2205 for (count
= 0; count
< 1000; count
++) { /* wait upto 10ms */
2206 falcon_xmac_readl ( efab
, ®
, FCN_XX_PWR_RST_REG_MAC
);
2207 if ( EFAB_DWORD_FIELD ( reg
, FCN_XX_RST_XX_EN
) == 0 ) {
2208 falcon_setup_xaui ( efab
);
2213 EFAB_ERR ( "timed out waiting for XAUI/XGXS reset\n" );
2218 falcon_xaui_link_ok ( struct efab_nic
*efab
)
2221 int align_done
, lane_status
, sync
;
2225 /* Read Falcon XAUI side */
2226 if ( efab
->is_asic
) {
2227 /* Read link status */
2228 falcon_xmac_readl ( efab
, ®
, FCN_XX_CORE_STAT_REG_MAC
);
2229 align_done
= EFAB_DWORD_FIELD ( reg
, FCN_XX_ALIGN_DONE
);
2231 sync
= EFAB_DWORD_FIELD ( reg
, FCN_XX_SYNC_STAT
);
2232 sync
= ( sync
== FCN_XX_SYNC_STAT_DECODE_SYNCED
);
2234 link_ok
= align_done
&& sync
;
2237 /* Clear link status ready for next read */
2238 EFAB_SET_DWORD_FIELD ( reg
, FCN_XX_COMMA_DET
, FCN_XX_COMMA_DET_RESET
);
2239 EFAB_SET_DWORD_FIELD ( reg
, FCN_XX_CHARERR
, FCN_XX_CHARERR_RESET
);
2240 EFAB_SET_DWORD_FIELD ( reg
, FCN_XX_DISPERR
, FCN_XX_DISPERR_RESET
);
2241 falcon_xmac_writel ( efab
, ®
, FCN_XX_CORE_STAT_REG_MAC
);
2243 has_phyxs
= ( efab
->phy_op
->mmds
& ( 1 << MDIO_MMD_PHYXS
) );
2244 if ( link_ok
&& has_phyxs
) {
2245 lane_status
= falcon_mdio_read ( efab
, MDIO_MMD_PHYXS
,
2246 MDIO_PHYXS_LANE_STATE
);
2247 link_ok
= ( lane_status
& ( 1 << MDIO_PHYXS_LANE_ALIGNED_LBN
) );
2250 EFAB_LOG ( "XGXS lane status: %x\n", lane_status
);
2261 falcon_reconfigure_xmac ( struct efab_nic
*efab
)
2266 /* Configure MAC - cut-thru mode is hard wired on */
2267 EFAB_POPULATE_DWORD_3 ( reg
,
2268 FCN_XM_RX_JUMBO_MODE
, 1,
2269 FCN_XM_TX_STAT_EN
, 1,
2270 FCN_XM_RX_STAT_EN
, 1);
2271 falcon_xmac_writel ( efab
, ®
, FCN_XM_GLB_CFG_REG_MAC
);
2274 EFAB_POPULATE_DWORD_6 ( reg
,
2281 falcon_xmac_writel ( efab
, ®
, FCN_XM_TX_CFG_REG_MAC
);
2284 EFAB_POPULATE_DWORD_4 ( reg
,
2286 FCN_XM_AUTO_DEPAD
, 0,
2287 FCN_XM_ACPT_ALL_MCAST
, 1,
2288 FCN_XM_PASS_CRC_ERR
, 1 );
2289 falcon_xmac_writel ( efab
, ®
, FCN_XM_RX_CFG_REG_MAC
);
2291 /* Set frame length */
2292 max_frame_len
= EFAB_MAX_FRAME_LEN ( ETH_FRAME_LEN
);
2293 EFAB_POPULATE_DWORD_1 ( reg
,
2294 FCN_XM_MAX_RX_FRM_SIZE
, max_frame_len
);
2295 falcon_xmac_writel ( efab
, ®
, FCN_XM_RX_PARAM_REG_MAC
);
2296 EFAB_POPULATE_DWORD_2 ( reg
,
2297 FCN_XM_MAX_TX_FRM_SIZE
, max_frame_len
,
2298 FCN_XM_TX_JUMBO_MODE
, 1 );
2299 falcon_xmac_writel ( efab
, ®
, FCN_XM_TX_PARAM_REG_MAC
);
2301 /* Enable flow control receipt */
2302 EFAB_POPULATE_DWORD_2 ( reg
,
2303 FCN_XM_PAUSE_TIME
, 0xfffe,
2304 FCN_XM_DIS_FCNTL
, 0 );
2305 falcon_xmac_writel ( efab
, ®
, FCN_XM_FC_REG_MAC
);
2307 /* Set MAC address */
2308 EFAB_POPULATE_DWORD_4 ( reg
,
2309 FCN_XM_ADR_0
, efab
->mac_addr
[0],
2310 FCN_XM_ADR_1
, efab
->mac_addr
[1],
2311 FCN_XM_ADR_2
, efab
->mac_addr
[2],
2312 FCN_XM_ADR_3
, efab
->mac_addr
[3] );
2313 falcon_xmac_writel ( efab
, ®
, FCN_XM_ADR_LO_REG_MAC
);
2314 EFAB_POPULATE_DWORD_2 ( reg
,
2315 FCN_XM_ADR_4
, efab
->mac_addr
[4],
2316 FCN_XM_ADR_5
, efab
->mac_addr
[5] );
2317 falcon_xmac_writel ( efab
, ®
, FCN_XM_ADR_HI_REG_MAC
);
2321 falcon_init_xmac ( struct efab_nic
*efab
)
2325 /* Mask the PHY management interrupt */
2326 falcon_mask_status_intr ( efab
, 0 );
2328 /* Initialise the PHY to instantiate the clock. */
2329 rc
= efab
->phy_op
->init ( efab
);
2331 EFAB_ERR ( "unable to initialise PHY\n" );
2335 falcon_reset_xaui ( efab
);
2337 /* Give the PHY and MAC time to faff */
2340 /* Reset and reconfigure the XMAC */
2341 rc
= falcon_reset_xmac ( efab
);
2344 falcon_reconfigure_xmac ( efab
);
2345 falcon_reconfigure_mac_wrapper ( efab
);
2347 * Now wait for the link to come up. This may take a while
2348 * for some slower PHY's.
2350 for (count
=0; count
<50; count
++) {
2353 /* Wait a while for the link to come up. */
2355 if ((count
% 5) == 0)
2358 /* Does the PHY think the wire-side link is up? */
2359 link_ok
= mdio_clause45_links_ok ( efab
);
2360 /* Ensure the XAUI link to the PHY is good */
2362 link_ok
= falcon_xaui_link_ok ( efab
);
2364 falcon_reset_xaui ( efab
);
2367 /* Check fault indication */
2369 link_ok
= falcon_xgmii_status ( efab
);
2371 efab
->link_up
= link_ok
;
2373 /* unmask the status interrupt */
2374 falcon_mask_status_intr ( efab
, 1 );
2379 /* Link failed to come up, but initialisation was fine. */
2387 static struct efab_mac_operations falcon_xmac_operations
= {
2388 .init
= falcon_init_xmac
,
2391 /*******************************************************************************
2397 *******************************************************************************/
2400 falcon_xaui_phy_init ( struct efab_nic
*efab
)
2402 /* CX4 is always 10000FD only */
2403 efab
->link_options
= LPA_EF_10000FULL
;
2405 /* There is no PHY! */
2409 static struct efab_phy_operations falcon_xaui_phy_ops
= {
2410 .init
= falcon_xaui_phy_init
,
2415 /*******************************************************************************
2421 *******************************************************************************/
2424 * Initialise Alaska PHY
2428 alaska_init ( struct efab_nic
*efab
)
2430 unsigned int advertised
, lpa
;
2432 /* Read link up status */
2433 efab
->link_up
= gmii_link_ok ( efab
);
2435 if ( ! efab
->link_up
)
2438 /* Determine link options from PHY. */
2439 advertised
= gmii_autoneg_advertised ( efab
);
2440 lpa
= gmii_autoneg_lpa ( efab
);
2441 efab
->link_options
= gmii_nway_result ( advertised
& lpa
);
2446 static struct efab_phy_operations falcon_alaska_phy_ops
= {
2447 .init
= alaska_init
,
2450 /*******************************************************************************
2456 *******************************************************************************/
2458 #define XFP_REQUIRED_DEVS ( MDIO_MMDREG_DEVS0_PCS | \
2459 MDIO_MMDREG_DEVS0_PMAPMD | \
2460 MDIO_MMDREG_DEVS0_PHYXS )
2463 falcon_xfp_phy_init ( struct efab_nic
*efab
)
2467 /* Optical link is always 10000FD only */
2468 efab
->link_options
= LPA_EF_10000FULL
;
2471 rc
= mdio_clause45_reset_mmd ( efab
, MDIO_MMD_PHYXS
);
2478 static struct efab_phy_operations falcon_xfp_phy_ops
= {
2479 .init
= falcon_xfp_phy_init
,
2480 .mmds
= XFP_REQUIRED_DEVS
,
2483 /*******************************************************************************
2489 *******************************************************************************/
2491 /* Command register */
2492 #define TXC_GLRGS_GLCMD (0xc004)
2493 #define TXC_GLCMD_LMTSWRST_LBN (14)
2495 /* Amplitude on lanes 0+1, 2+3 */
2496 #define TXC_ALRGS_ATXAMP0 (0xc041)
2497 #define TXC_ALRGS_ATXAMP1 (0xc042)
2498 /* Bit position of value for lane 0+2, 1+3 */
2499 #define TXC_ATXAMP_LANE02_LBN (3)
2500 #define TXC_ATXAMP_LANE13_LBN (11)
2502 #define TXC_ATXAMP_1280_mV (0)
2503 #define TXC_ATXAMP_1200_mV (8)
2504 #define TXC_ATXAMP_1120_mV (12)
2505 #define TXC_ATXAMP_1060_mV (14)
2506 #define TXC_ATXAMP_0820_mV (25)
2507 #define TXC_ATXAMP_0720_mV (26)
2508 #define TXC_ATXAMP_0580_mV (27)
2509 #define TXC_ATXAMP_0440_mV (28)
2511 #define TXC_ATXAMP_0820_BOTH ( (TXC_ATXAMP_0820_mV << TXC_ATXAMP_LANE02_LBN) | \
2512 (TXC_ATXAMP_0820_mV << TXC_ATXAMP_LANE13_LBN) )
2514 #define TXC_ATXAMP_DEFAULT (0x6060) /* From databook */
2516 /* Preemphasis on lanes 0+1, 2+3 */
2517 #define TXC_ALRGS_ATXPRE0 (0xc043)
2518 #define TXC_ALRGS_ATXPRE1 (0xc044)
2520 #define TXC_ATXPRE_NONE (0)
2521 #define TXC_ATXPRE_DEFAULT (0x1010) /* From databook */
2523 #define TXC_REQUIRED_DEVS ( MDIO_MMDREG_DEVS0_PCS | \
2524 MDIO_MMDREG_DEVS0_PMAPMD | \
2525 MDIO_MMDREG_DEVS0_PHYXS )
2528 falcon_txc_logic_reset ( struct efab_nic
*efab
)
2533 val
= falcon_mdio_read ( efab
, MDIO_MMD_PCS
, TXC_GLRGS_GLCMD
);
2534 val
|= (1 << TXC_GLCMD_LMTSWRST_LBN
);
2535 falcon_mdio_write ( efab
, MDIO_MMD_PCS
, TXC_GLRGS_GLCMD
, val
);
2538 val
= falcon_mdio_read ( efab
, MDIO_MMD_PCS
, TXC_GLRGS_GLCMD
);
2539 if ( ~val
& ( 1 << TXC_GLCMD_LMTSWRST_LBN
) )
2544 EFAB_ERR ( "logic reset failed\n" );
2550 falcon_txc_phy_init ( struct efab_nic
*efab
)
2554 /* CX4 is always 10000FD only */
2555 efab
->link_options
= LPA_EF_10000FULL
;
2558 rc
= mdio_clause45_reset_mmd ( efab
, MDIO_MMD_PMAPMD
);
2562 rc
= mdio_clause45_check_mmds ( efab
);
2566 /* Turn amplitude down and preemphasis off on the host side
2567 * (PHY<->MAC) as this is believed less likely to upset falcon
2568 * and no adverse effects have been noted. It probably also
2569 * saves a picowatt or two */
2571 /* Turn off preemphasis */
2572 falcon_mdio_write ( efab
, MDIO_MMD_PHYXS
, TXC_ALRGS_ATXPRE0
,
2574 falcon_mdio_write ( efab
, MDIO_MMD_PHYXS
, TXC_ALRGS_ATXPRE1
,
2577 /* Turn down the amplitude */
2578 falcon_mdio_write ( efab
, MDIO_MMD_PHYXS
, TXC_ALRGS_ATXAMP0
,
2579 TXC_ATXAMP_0820_BOTH
);
2580 falcon_mdio_write ( efab
, MDIO_MMD_PHYXS
, TXC_ALRGS_ATXAMP1
,
2581 TXC_ATXAMP_0820_BOTH
);
2583 /* Set the line side amplitude and preemphasis to the databook
2584 * defaults as an erratum causes them to be 0 on at least some
2586 falcon_mdio_write ( efab
, MDIO_MMD_PMAPMD
, TXC_ALRGS_ATXPRE0
,
2587 TXC_ATXPRE_DEFAULT
);
2588 falcon_mdio_write ( efab
, MDIO_MMD_PMAPMD
, TXC_ALRGS_ATXPRE1
,
2589 TXC_ATXPRE_DEFAULT
);
2590 falcon_mdio_write ( efab
, MDIO_MMD_PMAPMD
, TXC_ALRGS_ATXAMP0
,
2591 TXC_ATXAMP_DEFAULT
);
2592 falcon_mdio_write ( efab
, MDIO_MMD_PMAPMD
, TXC_ALRGS_ATXAMP1
,
2593 TXC_ATXAMP_DEFAULT
);
2595 rc
= falcon_txc_logic_reset ( efab
);
2607 static struct efab_phy_operations falcon_txc_phy_ops
= {
2608 .init
= falcon_txc_phy_init
,
2609 .mmds
= TXC_REQUIRED_DEVS
,
2612 /*******************************************************************************
2618 *******************************************************************************/
2621 #define TENXPRESS_REQUIRED_DEVS ( MDIO_MMDREG_DEVS0_PMAPMD | \
2622 MDIO_MMDREG_DEVS0_PCS | \
2623 MDIO_MMDREG_DEVS0_PHYXS )
2625 #define PCS_TEST_SELECT_REG 0xd807 /* PRM 10.5.8 */
2626 #define CLK312_EN_LBN 3
2627 #define CLK312_EN_WIDTH 1
2629 #define PCS_CLOCK_CTRL_REG 0xd801
2630 #define PLL312_RST_N_LBN 2
2632 /* Special Software reset register */
2633 #define PMA_PMD_EXT_CTRL_REG 49152
2634 #define PMA_PMD_EXT_SSR_LBN 15
2636 /* Boot status register */
2637 #define PCS_BOOT_STATUS_REG 0xd000
2638 #define PCS_BOOT_FATAL_ERR_LBN 0
2639 #define PCS_BOOT_PROGRESS_LBN 1
2640 #define PCS_BOOT_PROGRESS_WIDTH 2
2641 #define PCS_BOOT_COMPLETE_LBN 3
2643 #define PCS_SOFT_RST2_REG 0xd806
2644 #define SERDES_RST_N_LBN 13
2645 #define XGXS_RST_N_LBN 12
2648 falcon_tenxpress_check_c11 ( struct efab_nic
*efab
)
2653 /* Check that the C11 CPU has booted */
2654 for (count
=0; count
<10; count
++) {
2655 boot_stat
= falcon_mdio_read ( efab
, MDIO_MMD_PCS
,
2656 PCS_BOOT_STATUS_REG
);
2657 if ( boot_stat
& ( 1 << PCS_BOOT_COMPLETE_LBN
) )
2663 EFAB_ERR ( "C11 failed to boot\n" );
2668 falcon_tenxpress_phy_init ( struct efab_nic
*efab
)
2672 /* 10XPRESS is always 10000FD (at the moment) */
2673 efab
->link_options
= LPA_EF_10000FULL
;
2675 /* Wait for the blocks to come out of reset */
2676 rc
= mdio_clause45_wait_reset_mmds ( efab
);
2680 rc
= mdio_clause45_check_mmds ( efab
);
2684 /* Turn on the clock */
2685 reg
= (1 << CLK312_EN_LBN
);
2686 falcon_mdio_write ( efab
, MDIO_MMD_PCS
, PCS_TEST_SELECT_REG
, reg
);
2688 /* Wait 200ms for the PHY to boot */
2691 rc
= falcon_tenxpress_check_c11 ( efab
);
2703 static struct efab_phy_operations falcon_tenxpress_phy_ops
= {
2704 .init
= falcon_tenxpress_phy_init
,
2705 .mmds
= TENXPRESS_REQUIRED_DEVS
,
2708 /*******************************************************************************
2714 *******************************************************************************/
2716 /* The PM8358 just presents a DTE XS */
2717 #define PM8358_REQUIRED_DEVS (MDIO_MMDREG_DEVS0_DTEXS)
2719 /* PHY-specific definitions */
2720 /* Master ID and Global Performance Monitor Update */
2721 #define PMC_MASTER_REG (0xd000)
2722 /* Analog Tx Rx settings under software control */
2723 #define PMC_MASTER_ANLG_CTRL (1<< 11)
2725 /* Master Configuration register 2 */
2726 #define PMC_MCONF2_REG (0xd002)
2727 /* Drive Tx off centre of data eye (1) vs. clock edge (0) */
2728 #define PMC_MCONF2_TEDGE (1 << 2)
2729 /* Drive Rx off centre of data eye (1) vs. clock edge (0) */
2730 #define PMC_MCONF2_REDGE (1 << 3)
2732 /* Analog Rx settings */
2733 #define PMC_ANALOG_RX_CFG0 (0xd025)
2734 #define PMC_ANALOG_RX_CFG1 (0xd02d)
2735 #define PMC_ANALOG_RX_CFG2 (0xd035)
2736 #define PMC_ANALOG_RX_CFG3 (0xd03d)
2739 #define PMC_ANALOG_RX_TERM (1 << 15) /* Bit 15 of RX CFG: 0 for 100 ohms float,
2741 #define PMC_ANALOG_RX_EQ_MASK (3 << 8)
2742 #define PMC_ANALOG_RX_EQ_NONE (0 << 8)
2743 #define PMC_ANALOG_RX_EQ_HALF (1 << 8)
2744 #define PMC_ANALOG_RX_EQ_FULL (2 << 8)
2745 #define PMC_ANALOG_RX_EQ_RSVD (3 << 8)
2748 falcon_pm8358_phy_init ( struct efab_nic
*efab
)
2752 /* This is a XAUI retimer part */
2753 efab
->link_options
= LPA_EF_10000FULL
;
2755 rc
= mdio_clause45_reset_mmd ( efab
, MDIO_MMDREG_DEVS0_DTEXS
);
2759 /* Enable software control of analogue settings */
2760 reg
= falcon_mdio_read ( efab
, MDIO_MMD_DTEXS
, PMC_MASTER_REG
);
2761 reg
|= PMC_MASTER_ANLG_CTRL
;
2762 falcon_mdio_write ( efab
, MDIO_MMD_DTEXS
, PMC_MASTER_REG
, reg
);
2764 /* Turn rx eq on for all channels */
2765 for (i
=0; i
< 3; i
++) {
2766 /* The analog CFG registers are evenly spaced 8 apart */
2767 uint16_t addr
= PMC_ANALOG_RX_CFG0
+ 8*i
;
2768 reg
= falcon_mdio_read ( efab
, MDIO_MMD_DTEXS
, addr
);
2769 reg
= ( reg
& ~PMC_ANALOG_RX_EQ_MASK
) | PMC_ANALOG_RX_EQ_FULL
;
2770 falcon_mdio_write ( efab
, MDIO_MMD_DTEXS
, addr
, reg
);
2773 /* Set TEDGE, clear REDGE */
2774 reg
= falcon_mdio_read ( efab
, MDIO_MMD_DTEXS
, PMC_MCONF2_REG
);
2775 reg
= ( reg
& ~PMC_MCONF2_REDGE
) | PMC_MCONF2_TEDGE
;
2776 falcon_mdio_write ( efab
, MDIO_MMD_DTEXS
, PMC_MCONF2_REG
, reg
);
2781 static struct efab_phy_operations falcon_pm8358_phy_ops
= {
2782 .init
= falcon_pm8358_phy_init
,
2783 .mmds
= PM8358_REQUIRED_DEVS
,
2786 /*******************************************************************************
2792 *******************************************************************************/
2794 #define MAX_TEMP_THRESH 90
2797 #define PCA9539 0x74
2801 #define P0_CONFIG 0x06
2803 #define P0_EN_1V0X_LBN 0
2804 #define P0_EN_1V0X_WIDTH 1
2805 #define P0_EN_1V2_LBN 1
2806 #define P0_EN_1V2_WIDTH 1
2807 #define P0_EN_2V5_LBN 2
2808 #define P0_EN_2V5_WIDTH 1
2809 #define P0_EN_3V3X_LBN 3
2810 #define P0_EN_3V3X_WIDTH 1
2811 #define P0_EN_5V_LBN 4
2812 #define P0_EN_5V_WIDTH 1
2813 #define P0_X_TRST_LBN 6
2814 #define P0_X_TRST_WIDTH 1
2817 #define P1_CONFIG 0x07
2819 #define P1_AFE_PWD_LBN 0
2820 #define P1_AFE_PWD_WIDTH 1
2821 #define P1_DSP_PWD25_LBN 1
2822 #define P1_DSP_PWD25_WIDTH 1
2823 #define P1_SPARE_LBN 4
2824 #define P1_SPARE_WIDTH 4
2826 /* Temperature Sensor */
2827 #define MAX6647 0x4e
2833 static struct i2c_device i2c_pca9539
= {
2834 .dev_addr
= PCA9539
,
2840 static struct i2c_device i2c_max6647
= {
2841 .dev_addr
= MAX6647
,
2847 sfe4001_init ( struct efab_nic
*efab
)
2849 struct i2c_interface
*i2c
= &efab
->i2c_bb
.i2c
;
2851 uint8_t in
, cfg
, out
;
2854 EFAB_LOG ( "Initialise SFE4001 board\n" );
2856 /* Ensure XGXS and XAUI SerDes are held in reset */
2857 EFAB_POPULATE_DWORD_7 ( reg
,
2858 FCN_XX_PWRDNA_EN
, 1,
2859 FCN_XX_PWRDNB_EN
, 1,
2860 FCN_XX_RSTPLLAB_EN
, 1,
2861 FCN_XX_RESETA_EN
, 1,
2862 FCN_XX_RESETB_EN
, 1,
2863 FCN_XX_RSTXGXSRX_EN
, 1,
2864 FCN_XX_RSTXGXSTX_EN
, 1 );
2865 falcon_xmac_writel ( efab
, ®
, FCN_XX_PWR_RST_REG_MAC
);
2868 /* Set DSP over-temperature alert threshold */
2869 cfg
= MAX_TEMP_THRESH
;
2870 rc
= i2c
->write ( i2c
, &i2c_max6647
, WLHO
, &cfg
, EFAB_BYTE
);
2874 /* Read it back and verify */
2875 rc
= i2c
->read ( i2c
, &i2c_max6647
, RLHN
, &in
, EFAB_BYTE
);
2879 if ( in
!= MAX_TEMP_THRESH
) {
2880 EFAB_ERR ( "Unable to verify MAX6647 limit (requested=%d "
2881 "confirmed=%d)\n", cfg
, in
);
2886 /* Clear any previous over-temperature alert */
2887 rc
= i2c
->read ( i2c
, &i2c_max6647
, RSL
, &in
, EFAB_BYTE
);
2891 /* Enable port 0 and 1 outputs on IO expander */
2893 rc
= i2c
->write ( i2c
, &i2c_pca9539
, P0_CONFIG
, &cfg
, EFAB_BYTE
);
2896 cfg
= 0xff & ~(1 << P1_SPARE_LBN
);
2897 rc
= i2c
->write ( i2c
, &i2c_pca9539
, P1_CONFIG
, &cfg
, EFAB_BYTE
);
2901 /* Turn all power off then wait 1 sec. This ensures PHY is reset */
2902 out
= 0xff & ~((0 << P0_EN_1V2_LBN
) | (0 << P0_EN_2V5_LBN
) |
2903 (0 << P0_EN_3V3X_LBN
) | (0 << P0_EN_5V_LBN
) |
2904 (0 << P0_EN_1V0X_LBN
));
2906 rc
= i2c
->write ( i2c
, &i2c_pca9539
, P0_OUT
, &out
, EFAB_BYTE
);
2912 for (count
=0; count
<20; count
++) {
2913 /* Turn on 1.2V, 2.5V, 3.3V and 5V power rails */
2914 out
= 0xff & ~( (1 << P0_EN_1V2_LBN
) | (1 << P0_EN_2V5_LBN
) |
2915 (1 << P0_EN_3V3X_LBN
) | (1 << P0_EN_5V_LBN
) |
2916 (1 << P0_X_TRST_LBN
) );
2918 rc
= i2c
->write ( i2c
, &i2c_pca9539
, P0_OUT
, &out
, EFAB_BYTE
);
2924 /* Turn on the 1V power rail */
2925 out
&= ~( 1 << P0_EN_1V0X_LBN
);
2926 rc
= i2c
->write ( i2c
, &i2c_pca9539
, P0_OUT
, &out
, EFAB_BYTE
);
2930 EFAB_LOG ( "Waiting for power...(attempt %d)\n", count
);
2933 /* Check DSP is powered */
2934 rc
= i2c
->read ( i2c
, &i2c_pca9539
, P1_IN
, &in
, EFAB_BYTE
);
2938 if ( in
& ( 1 << P1_AFE_PWD_LBN
) )
2948 /* Turn off power rails */
2950 (void) i2c
->write ( i2c
, &i2c_pca9539
, P0_OUT
, &out
, EFAB_BYTE
);
2951 /* Disable port 1 outputs on IO expander */
2953 (void) i2c
->write ( i2c
, &i2c_pca9539
, P1_CONFIG
, &out
, EFAB_BYTE
);
2955 /* Disable port 0 outputs */
2957 (void) i2c
->write ( i2c
, &i2c_pca9539
, P1_CONFIG
, &out
, EFAB_BYTE
);
2963 EFAB_ERR ( "Failed initialising SFE4001 board\n" );
2968 sfe4001_fini ( struct efab_nic
*efab
)
2970 struct i2c_interface
*i2c
= &efab
->i2c_bb
.i2c
;
2971 uint8_t in
, cfg
, out
;
2973 EFAB_ERR ( "Turning off SFE4001\n" );
2975 /* Turn off all power rails */
2977 (void) i2c
->write ( i2c
, &i2c_pca9539
, P0_OUT
, &out
, EFAB_BYTE
);
2979 /* Disable port 1 outputs on IO expander */
2981 (void) i2c
->write ( i2c
, &i2c_pca9539
, P1_CONFIG
, &cfg
, EFAB_BYTE
);
2983 /* Disable port 0 outputs on IO expander */
2985 (void) i2c
->write ( i2c
, &i2c_pca9539
, P0_CONFIG
, &cfg
, EFAB_BYTE
);
2987 /* Clear any over-temperature alert */
2988 (void) i2c
->read ( i2c
, &i2c_max6647
, RSL
, &in
, EFAB_BYTE
);
2991 struct efab_board_operations sfe4001_ops
= {
2992 .init
= sfe4001_init
,
2993 .fini
= sfe4001_fini
,
2996 static int sfe4002_init ( struct efab_nic
*efab
__attribute__((unused
)) )
3000 static void sfe4002_fini ( struct efab_nic
*efab
__attribute__((unused
)) )
3004 struct efab_board_operations sfe4002_ops
= {
3005 .init
= sfe4002_init
,
3006 .fini
= sfe4002_fini
,
3009 static int sfe4003_init ( struct efab_nic
*efab
__attribute__((unused
)) )
3013 static void sfe4003_fini ( struct efab_nic
*efab
__attribute__((unused
)) )
3017 struct efab_board_operations sfe4003_ops
= {
3018 .init
= sfe4003_init
,
3019 .fini
= sfe4003_fini
,
3022 /*******************************************************************************
3025 * Hardware initialisation
3028 *******************************************************************************/
3031 falcon_free_special_buffer ( void *p
)
3033 /* We don't bother cleaning up the buffer table entries -
3034 * we're hardly limited */
3035 free_dma ( p
, EFAB_BUF_ALIGN
);
3039 falcon_alloc_special_buffer ( struct efab_nic
*efab
, int bytes
,
3040 struct efab_special_buffer
*entry
)
3044 efab_qword_t buf_desc
;
3045 unsigned long dma_addr
;
3047 /* Allocate the buffer, aligned on a buffer address boundary */
3048 buffer
= malloc_dma ( bytes
, EFAB_BUF_ALIGN
);
3052 /* Push buffer table entries to back the buffer */
3053 entry
->id
= efab
->buffer_head
;
3054 entry
->dma_addr
= dma_addr
= virt_to_bus ( buffer
);
3055 assert ( ( dma_addr
& ( EFAB_BUF_ALIGN
- 1 ) ) == 0 );
3058 while ( remaining
> 0 ) {
3059 EFAB_POPULATE_QWORD_3 ( buf_desc
,
3060 FCN_IP_DAT_BUF_SIZE
, FCN_IP_DAT_BUF_SIZE_4K
,
3061 FCN_BUF_ADR_FBUF
, ( dma_addr
>> 12 ),
3062 FCN_BUF_OWNER_ID_FBUF
, 0 );
3064 falcon_write_sram ( efab
, &buf_desc
, efab
->buffer_head
);
3066 ++efab
->buffer_head
;
3067 dma_addr
+= EFAB_BUF_ALIGN
;
3068 remaining
-= EFAB_BUF_ALIGN
;
3071 EFAB_TRACE ( "Allocated 0x%x bytes at %p backed by buffer table "
3072 "entries 0x%x..0x%x\n", bytes
, buffer
, entry
->id
,
3073 efab
->buffer_head
- 1 );
3079 clear_b0_fpga_memories ( struct efab_nic
*efab
)
3081 efab_oword_t blanko
, temp
;
3082 efab_dword_t blankd
;
3085 EFAB_ZERO_OWORD ( blanko
);
3086 EFAB_ZERO_DWORD ( blankd
);
3088 /* Clear the address region register */
3089 EFAB_POPULATE_OWORD_4 ( temp
,
3091 FCN_ADR_REGION1
, ( 1 << 16 ),
3092 FCN_ADR_REGION2
, ( 2 << 16 ),
3093 FCN_ADR_REGION3
, ( 3 << 16 ) );
3094 falcon_write ( efab
, &temp
, FCN_ADR_REGION_REG_KER
);
3096 EFAB_TRACE ( "Clearing filter and RSS tables\n" );
3098 for ( offset
= FCN_RX_FILTER_TBL0
;
3099 offset
< FCN_RX_RSS_INDIR_TBL_B0
+0x800 ;
3101 falcon_write ( efab
, &blanko
, offset
);
3104 EFAB_TRACE ( "Wiping buffer tables\n" );
3106 /* Notice the 8 byte access mode */
3107 for ( offset
= 0x2800000 ;
3108 offset
< 0x3000000 ;
3110 _falcon_writel ( efab
, 0, offset
);
3111 _falcon_writel ( efab
, 0, offset
+ 4 );
3117 falcon_reset ( struct efab_nic
*efab
)
3119 efab_oword_t glb_ctl_reg_ker
;
3121 /* Initiate software reset */
3122 EFAB_POPULATE_OWORD_6 ( glb_ctl_reg_ker
,
3123 FCN_PCIE_CORE_RST_CTL
, EXCLUDE_FROM_RESET
,
3124 FCN_PCIE_NSTCK_RST_CTL
, EXCLUDE_FROM_RESET
,
3125 FCN_PCIE_SD_RST_CTL
, EXCLUDE_FROM_RESET
,
3126 FCN_EE_RST_CTL
, EXCLUDE_FROM_RESET
,
3127 FCN_EXT_PHY_RST_DUR
, 0x7, /* 10ms */
3130 falcon_write ( efab
, &glb_ctl_reg_ker
, FCN_GLB_CTL_REG_KER
);
3132 /* Allow 50ms for reset */
3135 /* Check for device reset complete */
3136 falcon_read ( efab
, &glb_ctl_reg_ker
, FCN_GLB_CTL_REG_KER
);
3137 if ( EFAB_OWORD_FIELD ( glb_ctl_reg_ker
, FCN_SWRST
) != 0 ) {
3138 EFAB_ERR ( "Reset failed\n" );
3142 if ( ( efab
->pci_revision
== FALCON_REV_B0
) && !efab
->is_asic
) {
3143 clear_b0_fpga_memories ( efab
);
3149 /** Offset of MAC address within EEPROM or Flash */
3150 #define FALCON_MAC_ADDRESS_OFFSET 0x310
3153 * Falcon EEPROM structure
3155 #define SF_NV_CONFIG_BASE 0x300
3156 #define SF_NV_CONFIG_EXTRA 0xA0
3158 struct falcon_nv_config_ver2
{
3160 uint8_t port0_phy_addr
;
3161 uint8_t port0_phy_type
;
3162 uint8_t port1_phy_addr
;
3163 uint8_t port1_phy_type
;
3164 uint16_t asic_sub_revision
;
3165 uint16_t board_revision
;
3166 uint8_t mac_location
;
3169 struct falcon_nv_extra
{
3170 uint16_t magicnumber
;
3171 uint16_t structure_version
;
3174 struct falcon_nv_config_ver2 ver2
;
3178 #define BOARD_TYPE(_rev) (_rev >> 8)
3181 falcon_probe_nic_variant ( struct efab_nic
*efab
, struct pci_device
*pci
)
3183 efab_oword_t altera_build
, nic_stat
;
3184 int is_pcie
, fpga_version
;
3188 pci_read_config_byte ( pci
, PCI_CLASS_REVISION
, &revision
);
3189 efab
->pci_revision
= revision
;
3192 falcon_read ( efab
, &altera_build
, FCN_ALTERA_BUILD_REG_KER
);
3193 fpga_version
= EFAB_OWORD_FIELD ( altera_build
, FCN_VER_ALL
);
3194 efab
->is_asic
= (fpga_version
== 0);
3196 /* MAC and PCI type */
3197 falcon_read ( efab
, &nic_stat
, FCN_NIC_STAT_REG
);
3198 if ( efab
->pci_revision
== FALCON_REV_B0
) {
3200 efab
->phy_10g
= EFAB_OWORD_FIELD ( nic_stat
, FCN_STRAP_10G
);
3202 else if ( efab
->is_asic
) {
3203 is_pcie
= EFAB_OWORD_FIELD ( nic_stat
, FCN_STRAP_PCIE
);
3204 efab
->phy_10g
= EFAB_OWORD_FIELD ( nic_stat
, FCN_STRAP_10G
);
3207 int minor
= EFAB_OWORD_FIELD ( altera_build
, FCN_VER_MINOR
);
3209 efab
->phy_10g
= ( minor
== 0x14 );
3214 falcon_init_spi_device ( struct efab_nic
*efab
, struct spi_device
*spi
)
3216 /* Falcon's SPI interface only supports reads/writes of up to 16 bytes.
3217 * Reduce the nvs block size down to satisfy this - which means callers
3218 * should use the nvs_* functions rather than spi_*. */
3219 if ( spi
->nvs
.block_size
> FALCON_SPI_MAX_LEN
)
3220 spi
->nvs
.block_size
= FALCON_SPI_MAX_LEN
;
3222 spi
->bus
= &efab
->spi_bus
;
3227 falcon_probe_spi ( struct efab_nic
*efab
)
3229 efab_oword_t nic_stat
, gpio_ctl
, ee_vpd_cfg
;
3230 int has_flash
, has_eeprom
, ad9bit
;
3232 falcon_read ( efab
, &nic_stat
, FCN_NIC_STAT_REG
);
3233 falcon_read ( efab
, &gpio_ctl
, FCN_GPIO_CTL_REG_KER
);
3234 falcon_read ( efab
, &ee_vpd_cfg
, FCN_EE_VPD_CFG_REG
);
3236 /* determine if FLASH / EEPROM is present */
3237 if ( ( efab
->pci_revision
>= FALCON_REV_B0
) || efab
->is_asic
) {
3238 has_flash
= EFAB_OWORD_FIELD ( nic_stat
, FCN_SF_PRST
);
3239 has_eeprom
= EFAB_OWORD_FIELD ( nic_stat
, FCN_EE_PRST
);
3241 has_flash
= EFAB_OWORD_FIELD ( gpio_ctl
, FCN_FLASH_PRESENT
);
3242 has_eeprom
= EFAB_OWORD_FIELD ( gpio_ctl
, FCN_EEPROM_PRESENT
);
3244 ad9bit
= EFAB_OWORD_FIELD ( ee_vpd_cfg
, FCN_EE_VPD_EN_AD9_MODE
);
3246 /* Configure the SPI and I2C bus */
3247 efab
->spi_bus
.rw
= falcon_spi_rw
;
3248 init_i2c_bit_basher ( &efab
->i2c_bb
, &falcon_i2c_bit_ops
);
3250 /* Configure the EEPROM SPI device. Generally, an Atmel 25040
3251 * (or similar) is used, but this is only possible if there is also
3252 * a flash device present to store the boot-time chip configuration.
3255 if ( has_flash
&& ad9bit
)
3256 init_at25040 ( &efab
->spi_eeprom
);
3258 init_mc25xx640 ( &efab
->spi_eeprom
);
3259 falcon_init_spi_device ( efab
, &efab
->spi_eeprom
);
3262 /* Configure the FLASH SPI device */
3264 init_at25f1024 ( &efab
->spi_flash
);
3265 falcon_init_spi_device ( efab
, &efab
->spi_flash
);
3268 EFAB_LOG ( "flash is %s, EEPROM is %s%s\n",
3269 ( has_flash
? "present" : "absent" ),
3270 ( has_eeprom
? "present " : "absent" ),
3271 ( has_eeprom
? (ad9bit
? "(9bit)" : "(16bit)") : "") );
3273 /* The device MUST have flash or eeprom */
3274 if ( ! efab
->spi
) {
3275 EFAB_ERR ( "Device appears to have no flash or eeprom\n" );
3279 /* If the device has EEPROM attached, then advertise NVO space */
3281 nvo_init ( &efab
->nvo
, &efab
->spi_eeprom
.nvs
, falcon_nvo_fragments
,
3282 &efab
->netdev
->refcnt
);
3288 falcon_probe_nvram ( struct efab_nic
*efab
)
3290 struct nvs_device
*nvs
= &efab
->spi
->nvs
;
3291 struct falcon_nv_extra nv
;
3292 int rc
, board_revision
;
3294 /* Read the MAC address */
3295 rc
= nvs_read ( nvs
, FALCON_MAC_ADDRESS_OFFSET
,
3296 efab
->mac_addr
, ETH_ALEN
);
3300 /* Poke through the NVRAM structure for the PHY type. */
3301 rc
= nvs_read ( nvs
, SF_NV_CONFIG_BASE
+ SF_NV_CONFIG_EXTRA
,
3302 &nv
, sizeof ( nv
) );
3306 /* Handle each supported NVRAM version */
3307 if ( ( le16_to_cpu ( nv
.magicnumber
) == FCN_NV_MAGIC_NUMBER
) &&
3308 ( le16_to_cpu ( nv
.structure_version
) >= 2 ) ) {
3309 struct falcon_nv_config_ver2
* ver2
= &nv
.ver_specific
.ver2
;
3311 /* Get the PHY type */
3312 efab
->phy_addr
= le16_to_cpu ( ver2
->port0_phy_addr
);
3313 efab
->phy_type
= le16_to_cpu ( ver2
->port0_phy_type
);
3314 board_revision
= le16_to_cpu ( ver2
->board_revision
);
3317 EFAB_ERR ( "NVram is not recognised\n" );
3321 efab
->board_type
= BOARD_TYPE ( board_revision
);
3323 EFAB_TRACE ( "Falcon board %d phy %d @ addr %d\n",
3324 efab
->board_type
, efab
->phy_type
, efab
->phy_addr
);
3326 /* Patch in the board operations */
3327 switch ( efab
->board_type
) {
3328 case EFAB_BOARD_SFE4001
:
3329 efab
->board_op
= &sfe4001_ops
;
3331 case EFAB_BOARD_SFE4002
:
3332 efab
->board_op
= &sfe4002_ops
;
3334 case EFAB_BOARD_SFE4003
:
3335 efab
->board_op
= &sfe4003_ops
;
3338 EFAB_ERR ( "Unrecognised board type\n" );
3342 /* Patch in MAC operations */
3343 if ( efab
->phy_10g
)
3344 efab
->mac_op
= &falcon_xmac_operations
;
3346 efab
->mac_op
= &falcon_gmac_operations
;
3348 /* Hook in the PHY ops */
3349 switch ( efab
->phy_type
) {
3350 case PHY_TYPE_10XPRESS
:
3351 efab
->phy_op
= &falcon_tenxpress_phy_ops
;
3354 efab
->phy_op
= &falcon_xaui_phy_ops
;
3357 efab
->phy_op
= &falcon_xfp_phy_ops
;
3359 case PHY_TYPE_CX4_RTMR
:
3360 efab
->phy_op
= &falcon_txc_phy_ops
;
3362 case PHY_TYPE_PM8358
:
3363 efab
->phy_op
= &falcon_pm8358_phy_ops
;
3365 case PHY_TYPE_1GIG_ALASKA
:
3366 efab
->phy_op
= &falcon_alaska_phy_ops
;
3369 EFAB_ERR ( "Unknown PHY type: %d\n", efab
->phy_type
);
3377 falcon_init_sram ( struct efab_nic
*efab
)
3382 /* use card in internal SRAM mode */
3383 falcon_read ( efab
, ®
, FCN_NIC_STAT_REG
);
3384 EFAB_SET_OWORD_FIELD ( reg
, FCN_ONCHIP_SRAM
, 1 );
3385 falcon_write ( efab
, ®
, FCN_NIC_STAT_REG
);
3387 /* Deactivate any external SRAM that might be present */
3388 EFAB_POPULATE_OWORD_2 ( reg
,
3391 falcon_write ( efab
, ®
, FCN_GPIO_CTL_REG_KER
);
3393 /* Initiate SRAM reset */
3394 EFAB_POPULATE_OWORD_2 ( reg
,
3395 FCN_SRAM_OOB_BT_INIT_EN
, 1,
3396 FCN_SRM_NUM_BANKS_AND_BANK_SIZE
, 0 );
3397 falcon_write ( efab
, ®
, FCN_SRM_CFG_REG_KER
);
3399 /* Wait for SRAM reset to complete */
3402 /* SRAM reset is slow; expect around 16ms */
3405 /* Check for reset complete */
3406 falcon_read ( efab
, ®
, FCN_SRM_CFG_REG_KER
);
3407 if ( !EFAB_OWORD_FIELD ( reg
, FCN_SRAM_OOB_BT_INIT_EN
) )
3409 } while (++count
< 20); /* wait upto 0.4 sec */
3411 EFAB_ERR ( "timed out waiting for SRAM reset\n");
3416 falcon_setup_nic ( struct efab_nic
*efab
)
3418 efab_dword_t timer_cmd
;
3420 int tx_fc
, xoff_thresh
, xon_thresh
;
3422 /* bug5129: Clear the parity enables on the TX data fifos as
3423 * they produce false parity errors because of timing issues
3425 falcon_read ( efab
, ®
, FCN_SPARE_REG_KER
);
3426 EFAB_SET_OWORD_FIELD ( reg
, FCN_MEM_PERR_EN_TX_DATA
, 0 );
3427 falcon_write ( efab
, ®
, FCN_SPARE_REG_KER
);
3429 /* Set up TX and RX descriptor caches in SRAM */
3430 EFAB_POPULATE_OWORD_1 ( reg
, FCN_SRM_TX_DC_BASE_ADR
, 0x130000 );
3431 falcon_write ( efab
, ®
, FCN_SRM_TX_DC_CFG_REG_KER
);
3432 EFAB_POPULATE_OWORD_1 ( reg
, FCN_TX_DC_SIZE
, 1 /* 16 descriptors */ );
3433 falcon_write ( efab
, ®
, FCN_TX_DC_CFG_REG_KER
);
3434 EFAB_POPULATE_OWORD_1 ( reg
, FCN_SRM_RX_DC_BASE_ADR
, 0x100000 );
3435 falcon_write ( efab
, ®
, FCN_SRM_RX_DC_CFG_REG_KER
);
3436 EFAB_POPULATE_OWORD_1 ( reg
, FCN_RX_DC_SIZE
, 2 /* 32 descriptors */ );
3437 falcon_write ( efab
, ®
, FCN_RX_DC_CFG_REG_KER
);
3439 /* Set number of RSS CPUs
3440 * bug7244: Increase filter depth to reduce RX_RESET likelyhood
3442 EFAB_POPULATE_OWORD_5 ( reg
,
3444 FCN_UDP_FULL_SRCH_LIMIT
, 8,
3445 FCN_UDP_WILD_SRCH_LIMIT
, 8,
3446 FCN_TCP_WILD_SRCH_LIMIT
, 8,
3447 FCN_TCP_FULL_SRCH_LIMIT
, 8);
3448 falcon_write ( efab
, ®
, FCN_RX_FILTER_CTL_REG_KER
);
3451 /* Setup RX. Wait for descriptor is broken and must
3452 * be disabled. RXDP recovery shouldn't be needed, but is.
3453 * disable ISCSI parsing because we don't need it
3455 falcon_read ( efab
, ®
, FCN_RX_SELF_RST_REG_KER
);
3456 EFAB_SET_OWORD_FIELD ( reg
, FCN_RX_NODESC_WAIT_DIS
, 1 );
3457 EFAB_SET_OWORD_FIELD ( reg
, FCN_RX_RECOVERY_EN
, 1 );
3458 EFAB_SET_OWORD_FIELD ( reg
, FCN_RX_ISCSI_DIS
, 1 );
3459 falcon_write ( efab
, ®
, FCN_RX_SELF_RST_REG_KER
);
3461 /* Determine recommended flow control settings. *
3462 * Flow control is qualified on B0 and A1/1G, not on A1/10G */
3463 if ( efab
->pci_revision
== FALCON_REV_B0
) {
3465 xoff_thresh
= 54272; /* ~80Kb - 3*max MTU */
3466 xon_thresh
= 27648; /* ~3*max MTU */
3468 else if ( !efab
->phy_10g
) {
3474 tx_fc
= xoff_thresh
= xon_thresh
= 0;
3477 /* Setup TX and RX */
3478 falcon_read ( efab
, ®
, FCN_TX_CFG2_REG_KER
);
3479 EFAB_SET_OWORD_FIELD ( reg
, FCN_TX_DIS_NON_IP_EV
, 1 );
3480 falcon_write ( efab
, ®
, FCN_TX_CFG2_REG_KER
);
3482 falcon_read ( efab
, ®
, FCN_RX_CFG_REG_KER
);
3483 EFAB_SET_OWORD_FIELD_VER ( efab
, reg
, FCN_RX_USR_BUF_SIZE
,
3485 if ( efab
->pci_revision
== FALCON_REV_B0
)
3486 EFAB_SET_OWORD_FIELD ( reg
, FCN_RX_INGR_EN_B0
, 1 );
3487 EFAB_SET_OWORD_FIELD_VER ( efab
, reg
, FCN_RX_XON_MAC_TH
,
3489 EFAB_SET_OWORD_FIELD_VER ( efab
, reg
, FCN_RX_XOFF_MAC_TH
,
3491 EFAB_SET_OWORD_FIELD_VER ( efab
, reg
, FCN_RX_XOFF_MAC_EN
, tx_fc
);
3492 falcon_write ( efab
, ®
, FCN_RX_CFG_REG_KER
);
3494 /* Set timer register */
3495 EFAB_POPULATE_DWORD_2 ( timer_cmd
,
3496 FCN_TIMER_MODE
, FCN_TIMER_MODE_DIS
,
3498 falcon_writel ( efab
, &timer_cmd
, FCN_TIMER_CMD_REG_KER
);
3502 falcon_init_resources ( struct efab_nic
*efab
)
3504 struct efab_ev_queue
*ev_queue
= &efab
->ev_queue
;
3505 struct efab_rx_queue
*rx_queue
= &efab
->rx_queue
;
3506 struct efab_tx_queue
*tx_queue
= &efab
->tx_queue
;
3511 /* Initialise the ptrs */
3512 tx_queue
->read_ptr
= tx_queue
->write_ptr
= 0;
3513 rx_queue
->read_ptr
= rx_queue
->write_ptr
= 0;
3514 ev_queue
->read_ptr
= 0;
3516 /* Push the event queue to the hardware */
3517 EFAB_POPULATE_OWORD_3 ( reg
,
3519 FCN_EVQ_SIZE
, FQS(FCN_EVQ
, EFAB_EVQ_SIZE
),
3520 FCN_EVQ_BUF_BASE_ID
, ev_queue
->entry
.id
);
3521 falcon_write ( efab
, ®
,
3522 FCN_REVISION_REG ( efab
, FCN_EVQ_PTR_TBL_KER
) );
3524 /* Push the tx queue to the hardware */
3525 EFAB_POPULATE_OWORD_8 ( reg
,
3527 FCN_TX_ISCSI_DDIG_EN
, 0,
3528 FCN_TX_ISCSI_DDIG_EN
, 0,
3529 FCN_TX_DESCQ_BUF_BASE_ID
, tx_queue
->entry
.id
,
3530 FCN_TX_DESCQ_EVQ_ID
, 0,
3531 FCN_TX_DESCQ_SIZE
, FQS(FCN_TX_DESCQ
, EFAB_TXD_SIZE
),
3532 FCN_TX_DESCQ_TYPE
, 0 /* kernel queue */,
3533 FCN_TX_NON_IP_DROP_DIS_B0
, 1 );
3534 falcon_write ( efab
, ®
,
3535 FCN_REVISION_REG ( efab
, FCN_TX_DESC_PTR_TBL_KER
) );
3537 /* Push the rx queue to the hardware */
3538 jumbo
= ( efab
->pci_revision
== FALCON_REV_B0
) ? 0 : 1;
3539 EFAB_POPULATE_OWORD_8 ( reg
,
3540 FCN_RX_ISCSI_DDIG_EN
, 0,
3541 FCN_RX_ISCSI_HDIG_EN
, 0,
3542 FCN_RX_DESCQ_BUF_BASE_ID
, rx_queue
->entry
.id
,
3543 FCN_RX_DESCQ_EVQ_ID
, 0,
3544 FCN_RX_DESCQ_SIZE
, FQS(FCN_RX_DESCQ
, EFAB_RXD_SIZE
),
3545 FCN_RX_DESCQ_TYPE
, 0 /* kernel queue */,
3546 FCN_RX_DESCQ_JUMBO
, jumbo
,
3547 FCN_RX_DESCQ_EN
, 1 );
3548 falcon_write ( efab
, ®
,
3549 FCN_REVISION_REG ( efab
, FCN_RX_DESC_PTR_TBL_KER
) );
3551 /* Program INT_ADR_REG_KER */
3552 EFAB_POPULATE_OWORD_1 ( reg
,
3553 FCN_INT_ADR_KER
, virt_to_bus ( &efab
->int_ker
) );
3554 falcon_write ( efab
, ®
, FCN_INT_ADR_REG_KER
);
3556 /* Ack the event queue */
3557 falcon_eventq_read_ack ( efab
, ev_queue
);
3561 falcon_fini_resources ( struct efab_nic
*efab
)
3565 /* Disable interrupts */
3566 falcon_interrupts ( efab
, 0, 0 );
3568 /* Flush the dma queues */
3569 EFAB_POPULATE_OWORD_2 ( cmd
,
3570 FCN_TX_FLUSH_DESCQ_CMD
, 1,
3571 FCN_TX_FLUSH_DESCQ
, 0 );
3572 falcon_write ( efab
, &cmd
,
3573 FCN_REVISION_REG ( efab
, FCN_TX_DESC_PTR_TBL_KER
) );
3575 EFAB_POPULATE_OWORD_2 ( cmd
,
3576 FCN_RX_FLUSH_DESCQ_CMD
, 1,
3577 FCN_RX_FLUSH_DESCQ
, 0 );
3578 falcon_write ( efab
, &cmd
,
3579 FCN_REVISION_REG ( efab
, FCN_RX_DESC_PTR_TBL_KER
) );
3583 /* Remove descriptor rings from card */
3584 EFAB_ZERO_OWORD ( cmd
);
3585 falcon_write ( efab
, &cmd
,
3586 FCN_REVISION_REG ( efab
, FCN_TX_DESC_PTR_TBL_KER
) );
3587 falcon_write ( efab
, &cmd
,
3588 FCN_REVISION_REG ( efab
, FCN_RX_DESC_PTR_TBL_KER
) );
3589 falcon_write ( efab
, &cmd
,
3590 FCN_REVISION_REG ( efab
, FCN_EVQ_PTR_TBL_KER
) );
3593 /*******************************************************************************
3599 *******************************************************************************/
3602 falcon_build_rx_desc ( falcon_rx_desc_t
*rxd
, struct io_buffer
*iob
)
3604 EFAB_POPULATE_QWORD_2 ( *rxd
,
3605 FCN_RX_KER_BUF_SIZE
, EFAB_RX_BUF_SIZE
,
3606 FCN_RX_KER_BUF_ADR
, virt_to_bus ( iob
->data
) );
3610 falcon_notify_rx_desc ( struct efab_nic
*efab
, struct efab_rx_queue
*rx_queue
)
3613 int ptr
= rx_queue
->write_ptr
% EFAB_RXD_SIZE
;
3615 EFAB_POPULATE_DWORD_1 ( reg
, FCN_RX_DESC_WPTR_DWORD
, ptr
);
3616 falcon_writel ( efab
, ®
, FCN_RX_DESC_UPD_REG_KER_DWORD
);
3620 /*******************************************************************************
3626 *******************************************************************************/
3629 falcon_build_tx_desc ( falcon_tx_desc_t
*txd
, struct io_buffer
*iob
)
3631 EFAB_POPULATE_QWORD_2 ( *txd
,
3632 FCN_TX_KER_BYTE_CNT
, iob_len ( iob
),
3633 FCN_TX_KER_BUF_ADR
, virt_to_bus ( iob
->data
) );
3637 falcon_notify_tx_desc ( struct efab_nic
*efab
,
3638 struct efab_tx_queue
*tx_queue
)
3641 int ptr
= tx_queue
->write_ptr
% EFAB_TXD_SIZE
;
3643 EFAB_POPULATE_DWORD_1 ( reg
, FCN_TX_DESC_WPTR_DWORD
, ptr
);
3644 falcon_writel ( efab
, ®
, FCN_TX_DESC_UPD_REG_KER_DWORD
);
3648 /*******************************************************************************
3651 * Software receive interface
3654 *******************************************************************************/
3657 efab_fill_rx_queue ( struct efab_nic
*efab
,
3658 struct efab_rx_queue
*rx_queue
)
3660 int fill_level
= rx_queue
->write_ptr
- rx_queue
->read_ptr
;
3661 int space
= EFAB_NUM_RX_DESC
- fill_level
- 1;
3665 int buf_id
= rx_queue
->write_ptr
% EFAB_NUM_RX_DESC
;
3666 int desc_id
= rx_queue
->write_ptr
% EFAB_RXD_SIZE
;
3667 struct io_buffer
*iob
;
3668 falcon_rx_desc_t
*rxd
;
3670 assert ( rx_queue
->buf
[buf_id
] == NULL
);
3671 iob
= alloc_iob ( EFAB_RX_BUF_SIZE
);
3675 EFAB_TRACE ( "pushing rx_buf[%d] iob %p data %p\n",
3676 buf_id
, iob
, iob
->data
);
3678 rx_queue
->buf
[buf_id
] = iob
;
3679 rxd
= rx_queue
->ring
+ desc_id
;
3680 falcon_build_rx_desc ( rxd
, iob
);
3681 ++rx_queue
->write_ptr
;
3687 /* Push the ptr to hardware */
3688 falcon_notify_rx_desc ( efab
, rx_queue
);
3690 fill_level
= rx_queue
->write_ptr
- rx_queue
->read_ptr
;
3691 EFAB_TRACE ( "pushed %d rx buffers to fill level %d\n",
3692 pushed
, fill_level
);
3695 if ( fill_level
== 0 )
3701 efab_receive ( struct efab_nic
*efab
, unsigned int id
, int len
, int drop
)
3703 struct efab_rx_queue
*rx_queue
= &efab
->rx_queue
;
3704 struct io_buffer
*iob
;
3705 unsigned int read_ptr
= rx_queue
->read_ptr
% EFAB_RXD_SIZE
;
3706 unsigned int buf_ptr
= rx_queue
->read_ptr
% EFAB_NUM_RX_DESC
;
3708 assert ( id
== read_ptr
);
3710 /* Pop this rx buffer out of the software ring */
3711 iob
= rx_queue
->buf
[buf_ptr
];
3712 rx_queue
->buf
[buf_ptr
] = NULL
;
3714 EFAB_TRACE ( "popping rx_buf[%d] iob %p data %p with %d bytes %s\n",
3715 id
, iob
, iob
->data
, len
, drop
? "bad" : "ok" );
3717 /* Pass the packet up if required */
3721 iob_put ( iob
, len
);
3722 netdev_rx ( efab
->netdev
, iob
);
3725 ++rx_queue
->read_ptr
;
3728 /*******************************************************************************
3731 * Software transmit interface
3734 *******************************************************************************/
3737 efab_transmit ( struct net_device
*netdev
, struct io_buffer
*iob
)
3739 struct efab_nic
*efab
= netdev_priv ( netdev
);
3740 struct efab_tx_queue
*tx_queue
= &efab
->tx_queue
;
3741 int fill_level
, space
;
3742 falcon_tx_desc_t
*txd
;
3745 fill_level
= tx_queue
->write_ptr
- tx_queue
->read_ptr
;
3746 space
= EFAB_TXD_SIZE
- fill_level
- 1;
3750 /* Save the iobuffer for later completion */
3751 buf_id
= tx_queue
->write_ptr
% EFAB_TXD_SIZE
;
3752 assert ( tx_queue
->buf
[buf_id
] == NULL
);
3753 tx_queue
->buf
[buf_id
] = iob
;
3755 EFAB_TRACE ( "tx_buf[%d] for iob %p data %p len %zd\n",
3756 buf_id
, iob
, iob
->data
, iob_len ( iob
) );
3758 /* Form the descriptor, and push it to hardware */
3759 txd
= tx_queue
->ring
+ buf_id
;
3760 falcon_build_tx_desc ( txd
, iob
);
3761 ++tx_queue
->write_ptr
;
3762 falcon_notify_tx_desc ( efab
, tx_queue
);
3768 efab_transmit_done ( struct efab_nic
*efab
, int id
)
3770 struct efab_tx_queue
*tx_queue
= &efab
->tx_queue
;
3771 unsigned int read_ptr
, stop
;
3773 /* Complete all buffers from read_ptr up to and including id */
3774 read_ptr
= tx_queue
->read_ptr
% EFAB_TXD_SIZE
;
3775 stop
= ( id
+ 1 ) % EFAB_TXD_SIZE
;
3777 while ( read_ptr
!= stop
) {
3778 struct io_buffer
*iob
= tx_queue
->buf
[read_ptr
];
3781 /* Complete the tx buffer */
3783 netdev_tx_complete ( efab
->netdev
, iob
);
3784 tx_queue
->buf
[read_ptr
] = NULL
;
3786 ++tx_queue
->read_ptr
;
3787 read_ptr
= tx_queue
->read_ptr
% EFAB_TXD_SIZE
;
3793 /*******************************************************************************
3796 * Hardware event path
3799 *******************************************************************************/
3802 falcon_clear_interrupts ( struct efab_nic
*efab
)
3806 if ( efab
->pci_revision
== FALCON_REV_B0
) {
3808 falcon_readl( efab
, ®
, INT_ISR0_B0
);
3811 /* write to the INT_ACK register */
3812 falcon_writel ( efab
, 0, FCN_INT_ACK_KER_REG_A1
);
3814 falcon_readl ( efab
, ®
,
3815 WORK_AROUND_BROKEN_PCI_READS_REG_KER_A1
);
3820 falcon_handle_event ( struct efab_nic
*efab
, falcon_event_t
*evt
)
3822 int ev_code
, desc_ptr
, len
, drop
;
3825 ev_code
= EFAB_QWORD_FIELD ( *evt
, FCN_EV_CODE
);
3826 switch ( ev_code
) {
3827 case FCN_TX_IP_EV_DECODE
:
3828 desc_ptr
= EFAB_QWORD_FIELD ( *evt
, FCN_TX_EV_DESC_PTR
);
3829 efab_transmit_done ( efab
, desc_ptr
);
3832 case FCN_RX_IP_EV_DECODE
:
3833 desc_ptr
= EFAB_QWORD_FIELD ( *evt
, FCN_RX_EV_DESC_PTR
);
3834 len
= EFAB_QWORD_FIELD ( *evt
, FCN_RX_EV_BYTE_CNT
);
3835 drop
= !EFAB_QWORD_FIELD ( *evt
, FCN_RX_EV_PKT_OK
);
3837 efab_receive ( efab
, desc_ptr
, len
, drop
);
3841 EFAB_TRACE ( "Unknown event type %d\n", ev_code
);
3846 /*******************************************************************************
3849 * Software (polling) interrupt handler
3852 *******************************************************************************/
3855 efab_poll ( struct net_device
*netdev
)
3857 struct efab_nic
*efab
= netdev_priv ( netdev
);
3858 struct efab_ev_queue
*ev_queue
= &efab
->ev_queue
;
3859 struct efab_rx_queue
*rx_queue
= &efab
->rx_queue
;
3860 falcon_event_t
*evt
;
3862 /* Read the event queue by directly looking for events
3863 * (we don't even bother to read the eventq write ptr) */
3864 evt
= ev_queue
->ring
+ ev_queue
->read_ptr
;
3865 while ( falcon_event_present ( evt
) ) {
3867 EFAB_TRACE ( "Event at index 0x%x address %p is "
3868 EFAB_QWORD_FMT
"\n", ev_queue
->read_ptr
,
3869 evt
, EFAB_QWORD_VAL ( *evt
) );
3871 falcon_handle_event ( efab
, evt
);
3873 /* Clear the event */
3874 EFAB_SET_QWORD ( *evt
);
3876 /* Move to the next event. We don't ack the event
3877 * queue until the end */
3878 ev_queue
->read_ptr
= ( ( ev_queue
->read_ptr
+ 1 ) %
3880 evt
= ev_queue
->ring
+ ev_queue
->read_ptr
;
3883 /* Push more buffers if needed */
3884 (void) efab_fill_rx_queue ( efab
, rx_queue
);
3886 /* Clear any pending interrupts */
3887 falcon_clear_interrupts ( efab
);
3889 /* Ack the event queue */
3890 falcon_eventq_read_ack ( efab
, ev_queue
);
3894 efab_irq ( struct net_device
*netdev
, int enable
)
3896 struct efab_nic
*efab
= netdev_priv ( netdev
);
3897 struct efab_ev_queue
*ev_queue
= &efab
->ev_queue
;
3901 falcon_interrupts ( efab
, 0, 0 );
3904 falcon_interrupts ( efab
, 1, 0 );
3905 falcon_eventq_read_ack ( efab
, ev_queue
);
3908 falcon_interrupts ( efab
, 1, 1 );
3913 /*******************************************************************************
3916 * Software open/close
3919 *******************************************************************************/
3922 efab_free_resources ( struct efab_nic
*efab
)
3924 struct efab_ev_queue
*ev_queue
= &efab
->ev_queue
;
3925 struct efab_rx_queue
*rx_queue
= &efab
->rx_queue
;
3926 struct efab_tx_queue
*tx_queue
= &efab
->tx_queue
;
3929 for ( i
= 0; i
< EFAB_NUM_RX_DESC
; i
++ ) {
3930 if ( rx_queue
->buf
[i
] )
3931 free_iob ( rx_queue
->buf
[i
] );
3934 for ( i
= 0; i
< EFAB_TXD_SIZE
; i
++ ) {
3935 if ( tx_queue
->buf
[i
] )
3936 netdev_tx_complete ( efab
->netdev
, tx_queue
->buf
[i
] );
3939 if ( rx_queue
->ring
)
3940 falcon_free_special_buffer ( rx_queue
->ring
);
3942 if ( tx_queue
->ring
)
3943 falcon_free_special_buffer ( tx_queue
->ring
);
3945 if ( ev_queue
->ring
)
3946 falcon_free_special_buffer ( ev_queue
->ring
);
3948 memset ( rx_queue
, 0, sizeof ( *rx_queue
) );
3949 memset ( tx_queue
, 0, sizeof ( *tx_queue
) );
3950 memset ( ev_queue
, 0, sizeof ( *ev_queue
) );
3952 /* Ensure subsequent buffer allocations start at id 0 */
3953 efab
->buffer_head
= 0;
3957 efab_alloc_resources ( struct efab_nic
*efab
)
3959 struct efab_ev_queue
*ev_queue
= &efab
->ev_queue
;
3960 struct efab_rx_queue
*rx_queue
= &efab
->rx_queue
;
3961 struct efab_tx_queue
*tx_queue
= &efab
->tx_queue
;
3964 /* Allocate the hardware event queue */
3965 bytes
= sizeof ( falcon_event_t
) * EFAB_TXD_SIZE
;
3966 ev_queue
->ring
= falcon_alloc_special_buffer ( efab
, bytes
,
3968 if ( !ev_queue
->ring
)
3971 /* Initialise the hardware event queue */
3972 memset ( ev_queue
->ring
, 0xff, bytes
);
3974 /* Allocate the hardware tx queue */
3975 bytes
= sizeof ( falcon_tx_desc_t
) * EFAB_TXD_SIZE
;
3976 tx_queue
->ring
= falcon_alloc_special_buffer ( efab
, bytes
,
3978 if ( ! tx_queue
->ring
)
3981 /* Allocate the hardware rx queue */
3982 bytes
= sizeof ( falcon_rx_desc_t
) * EFAB_RXD_SIZE
;
3983 rx_queue
->ring
= falcon_alloc_special_buffer ( efab
, bytes
,
3985 if ( ! rx_queue
->ring
)
3991 falcon_free_special_buffer ( tx_queue
->ring
);
3992 tx_queue
->ring
= NULL
;
3994 falcon_free_special_buffer ( ev_queue
->ring
);
3995 ev_queue
->ring
= NULL
;
4001 efab_init_mac ( struct efab_nic
*efab
)
4005 /* This can take several seconds */
4006 EFAB_LOG ( "Waiting for link..\n" );
4007 for ( count
=0; count
<5; count
++ ) {
4008 rc
= efab
->mac_op
->init ( efab
);
4010 EFAB_ERR ( "Failed reinitialising MAC, error %s\n",
4015 /* Sleep for 2s to wait for the link to settle, either
4016 * because we want to use it, or because we're about
4017 * to reset the mac anyway
4021 if ( ! efab
->link_up
) {
4026 EFAB_LOG ( "\n%dMbps %s-duplex\n",
4027 ( efab
->link_options
& LPA_EF_10000
? 10000 :
4028 ( efab
->link_options
& LPA_EF_1000
? 1000 :
4029 ( efab
->link_options
& LPA_100
? 100 : 10 ) ) ),
4030 ( efab
->link_options
& LPA_EF_DUPLEX
?
4031 "full" : "half" ) );
4033 /* TODO: Move link state handling to the poll() routine */
4034 netdev_link_up ( efab
->netdev
);
4038 EFAB_ERR ( "timed initialising MAC\n" );
4043 efab_close ( struct net_device
*netdev
)
4045 struct efab_nic
*efab
= netdev_priv ( netdev
);
4047 falcon_fini_resources ( efab
);
4048 efab_free_resources ( efab
);
4049 efab
->board_op
->fini ( efab
);
4050 falcon_reset ( efab
);
4054 efab_open ( struct net_device
*netdev
)
4056 struct efab_nic
*efab
= netdev_priv ( netdev
);
4057 struct efab_rx_queue
*rx_queue
= &efab
->rx_queue
;
4060 rc
= falcon_reset ( efab
);
4064 rc
= efab
->board_op
->init ( efab
);
4068 rc
= falcon_init_sram ( efab
);
4072 /* Configure descriptor caches before pushing hardware queues */
4073 falcon_setup_nic ( efab
);
4075 rc
= efab_alloc_resources ( efab
);
4079 falcon_init_resources ( efab
);
4081 /* Push rx buffers */
4082 rc
= efab_fill_rx_queue ( efab
, rx_queue
);
4086 /* Try and bring the interface up */
4087 rc
= efab_init_mac ( efab
);
4095 efab_free_resources ( efab
);
4098 efab
->board_op
->fini ( efab
);
4100 falcon_reset ( efab
);
4105 static struct net_device_operations efab_operations
= {
4107 .close
= efab_close
,
4108 .transmit
= efab_transmit
,
4114 efab_remove ( struct pci_device
*pci
)
4116 struct net_device
*netdev
= pci_get_drvdata ( pci
);
4117 struct efab_nic
*efab
= netdev_priv ( netdev
);
4119 if ( efab
->membase
) {
4120 falcon_reset ( efab
);
4122 iounmap ( efab
->membase
);
4123 efab
->membase
= NULL
;
4126 if ( efab
->nvo
.nvs
) {
4127 unregister_nvo ( &efab
->nvo
);
4128 efab
->nvo
.nvs
= NULL
;
4131 unregister_netdev ( netdev
);
4132 netdev_nullify ( netdev
);
4133 netdev_put ( netdev
);
4137 efab_probe ( struct pci_device
*pci
,
4138 const struct pci_device_id
*id
)
4140 struct net_device
*netdev
;
4141 struct efab_nic
*efab
;
4142 unsigned long mmio_start
, mmio_len
;
4145 /* Create the network adapter */
4146 netdev
= alloc_etherdev ( sizeof ( struct efab_nic
) );
4152 /* Initialise the network adapter, and initialise private storage */
4153 netdev_init ( netdev
, &efab_operations
);
4154 pci_set_drvdata ( pci
, netdev
);
4155 netdev
->dev
= &pci
->dev
;
4157 efab
= netdev_priv ( netdev
);
4158 memset ( efab
, 0, sizeof ( *efab
) );
4159 efab
->netdev
= netdev
;
4161 /* Get iobase/membase */
4162 mmio_start
= pci_bar_start ( pci
, PCI_BASE_ADDRESS_2
);
4163 mmio_len
= pci_bar_size ( pci
, PCI_BASE_ADDRESS_2
);
4164 efab
->membase
= ioremap ( mmio_start
, mmio_len
);
4165 EFAB_TRACE ( "BAR of %lx bytes at phys %lx mapped at %p\n",
4166 mmio_len
, mmio_start
, efab
->membase
);
4168 /* Enable the PCI device */
4169 adjust_pci_device ( pci
);
4170 efab
->iobase
= pci
->ioaddr
& ~3;
4172 /* Determine the NIC variant */
4173 falcon_probe_nic_variant ( efab
, pci
);
4175 /* Read the SPI interface and determine the MAC address,
4176 * and the board and phy variant. Hook in the op tables */
4177 rc
= falcon_probe_spi ( efab
);
4180 rc
= falcon_probe_nvram ( efab
);
4184 memcpy ( netdev
->hw_addr
, efab
->mac_addr
, ETH_ALEN
);
4186 netdev_link_up ( netdev
);
4187 rc
= register_netdev ( netdev
);
4191 /* Advertise non-volatile storage */
4192 if ( efab
->nvo
.nvs
) {
4193 rc
= register_nvo ( &efab
->nvo
, netdev_settings ( netdev
) );
4198 EFAB_LOG ( "Found %s EtherFabric %s %s revision %d\n", id
->name
,
4199 efab
->is_asic
? "ASIC" : "FPGA",
4200 efab
->phy_10g
? "10G" : "1G",
4201 efab
->pci_revision
);
4206 unregister_netdev ( netdev
);
4210 iounmap ( efab
->membase
);
4211 efab
->membase
= NULL
;
4212 netdev_put ( netdev
);
4218 static struct pci_device_id efab_nics
[] = {
4219 PCI_ROM(0x1924, 0x0703, "falcon", "EtherFabric Falcon", 0),
4220 PCI_ROM(0x1924, 0x0710, "falconb0", "EtherFabric FalconB0", 0),
4223 struct pci_driver etherfabric_driver __pci_driver
= {
4225 .id_count
= sizeof ( efab_nics
) / sizeof ( efab_nics
[0] ),
4226 .probe
= efab_probe
,
4227 .remove
= efab_remove
,