162306a36Sopenharmony_ci// SPDX-License-Identifier: GPL-2.0-only 262306a36Sopenharmony_ci/***************************************************************************** 362306a36Sopenharmony_ci * * 462306a36Sopenharmony_ci * File: pm3393.c * 562306a36Sopenharmony_ci * $Revision: 1.16 $ * 662306a36Sopenharmony_ci * $Date: 2005/05/14 00:59:32 $ * 762306a36Sopenharmony_ci * Description: * 862306a36Sopenharmony_ci * PMC/SIERRA (pm3393) MAC-PHY functionality. * 962306a36Sopenharmony_ci * part of the Chelsio 10Gb Ethernet Driver. * 1062306a36Sopenharmony_ci * * 1162306a36Sopenharmony_ci * * 1262306a36Sopenharmony_ci * http://www.chelsio.com * 1362306a36Sopenharmony_ci * * 1462306a36Sopenharmony_ci * Copyright (c) 2003 - 2005 Chelsio Communications, Inc. * 1562306a36Sopenharmony_ci * All rights reserved. * 1662306a36Sopenharmony_ci * * 1762306a36Sopenharmony_ci * Maintainers: maintainers@chelsio.com * 1862306a36Sopenharmony_ci * * 1962306a36Sopenharmony_ci * Authors: Dimitrios Michailidis <dm@chelsio.com> * 2062306a36Sopenharmony_ci * Tina Yang <tainay@chelsio.com> * 2162306a36Sopenharmony_ci * Felix Marti <felix@chelsio.com> * 2262306a36Sopenharmony_ci * Scott Bardone <sbardone@chelsio.com> * 2362306a36Sopenharmony_ci * Kurt Ottaway <kottaway@chelsio.com> * 2462306a36Sopenharmony_ci * Frank DiMambro <frank@chelsio.com> * 2562306a36Sopenharmony_ci * * 2662306a36Sopenharmony_ci * History: * 2762306a36Sopenharmony_ci * * 2862306a36Sopenharmony_ci ****************************************************************************/ 2962306a36Sopenharmony_ci 3062306a36Sopenharmony_ci#include "common.h" 3162306a36Sopenharmony_ci#include "regs.h" 3262306a36Sopenharmony_ci#include "gmac.h" 3362306a36Sopenharmony_ci#include "elmer0.h" 3462306a36Sopenharmony_ci#include "suni1x10gexp_regs.h" 3562306a36Sopenharmony_ci 3662306a36Sopenharmony_ci#include <linux/crc32.h> 3762306a36Sopenharmony_ci#include <linux/slab.h> 3862306a36Sopenharmony_ci 3962306a36Sopenharmony_ci#define OFFSET(REG_ADDR) ((REG_ADDR) << 2) 4062306a36Sopenharmony_ci 4162306a36Sopenharmony_ci#define IPG 12 4262306a36Sopenharmony_ci#define TXXG_CONF1_VAL ((IPG << SUNI1x10GEXP_BITOFF_TXXG_IPGT) | \ 4362306a36Sopenharmony_ci SUNI1x10GEXP_BITMSK_TXXG_32BIT_ALIGN | SUNI1x10GEXP_BITMSK_TXXG_CRCEN | \ 4462306a36Sopenharmony_ci SUNI1x10GEXP_BITMSK_TXXG_PADEN) 4562306a36Sopenharmony_ci#define RXXG_CONF1_VAL (SUNI1x10GEXP_BITMSK_RXXG_PUREP | 0x14 | \ 4662306a36Sopenharmony_ci SUNI1x10GEXP_BITMSK_RXXG_FLCHK | SUNI1x10GEXP_BITMSK_RXXG_CRC_STRIP) 4762306a36Sopenharmony_ci 4862306a36Sopenharmony_ci/* Update statistics every 15 minutes */ 4962306a36Sopenharmony_ci#define STATS_TICK_SECS (15 * 60) 5062306a36Sopenharmony_ci 5162306a36Sopenharmony_cienum { /* RMON registers */ 5262306a36Sopenharmony_ci RxOctetsReceivedOK = SUNI1x10GEXP_REG_MSTAT_COUNTER_1_LOW, 5362306a36Sopenharmony_ci RxUnicastFramesReceivedOK = SUNI1x10GEXP_REG_MSTAT_COUNTER_4_LOW, 5462306a36Sopenharmony_ci RxMulticastFramesReceivedOK = SUNI1x10GEXP_REG_MSTAT_COUNTER_5_LOW, 5562306a36Sopenharmony_ci RxBroadcastFramesReceivedOK = SUNI1x10GEXP_REG_MSTAT_COUNTER_6_LOW, 5662306a36Sopenharmony_ci RxPAUSEMACCtrlFramesReceived = SUNI1x10GEXP_REG_MSTAT_COUNTER_8_LOW, 5762306a36Sopenharmony_ci RxFrameCheckSequenceErrors = SUNI1x10GEXP_REG_MSTAT_COUNTER_10_LOW, 5862306a36Sopenharmony_ci RxFramesLostDueToInternalMACErrors = SUNI1x10GEXP_REG_MSTAT_COUNTER_11_LOW, 5962306a36Sopenharmony_ci RxSymbolErrors = SUNI1x10GEXP_REG_MSTAT_COUNTER_12_LOW, 6062306a36Sopenharmony_ci RxInRangeLengthErrors = SUNI1x10GEXP_REG_MSTAT_COUNTER_13_LOW, 6162306a36Sopenharmony_ci RxFramesTooLongErrors = SUNI1x10GEXP_REG_MSTAT_COUNTER_15_LOW, 6262306a36Sopenharmony_ci RxJabbers = SUNI1x10GEXP_REG_MSTAT_COUNTER_16_LOW, 6362306a36Sopenharmony_ci RxFragments = SUNI1x10GEXP_REG_MSTAT_COUNTER_17_LOW, 6462306a36Sopenharmony_ci RxUndersizedFrames = SUNI1x10GEXP_REG_MSTAT_COUNTER_18_LOW, 6562306a36Sopenharmony_ci RxJumboFramesReceivedOK = SUNI1x10GEXP_REG_MSTAT_COUNTER_25_LOW, 6662306a36Sopenharmony_ci RxJumboOctetsReceivedOK = SUNI1x10GEXP_REG_MSTAT_COUNTER_26_LOW, 6762306a36Sopenharmony_ci 6862306a36Sopenharmony_ci TxOctetsTransmittedOK = SUNI1x10GEXP_REG_MSTAT_COUNTER_33_LOW, 6962306a36Sopenharmony_ci TxFramesLostDueToInternalMACTransmissionError = SUNI1x10GEXP_REG_MSTAT_COUNTER_35_LOW, 7062306a36Sopenharmony_ci TxTransmitSystemError = SUNI1x10GEXP_REG_MSTAT_COUNTER_36_LOW, 7162306a36Sopenharmony_ci TxUnicastFramesTransmittedOK = SUNI1x10GEXP_REG_MSTAT_COUNTER_38_LOW, 7262306a36Sopenharmony_ci TxMulticastFramesTransmittedOK = SUNI1x10GEXP_REG_MSTAT_COUNTER_40_LOW, 7362306a36Sopenharmony_ci TxBroadcastFramesTransmittedOK = SUNI1x10GEXP_REG_MSTAT_COUNTER_42_LOW, 7462306a36Sopenharmony_ci TxPAUSEMACCtrlFramesTransmitted = SUNI1x10GEXP_REG_MSTAT_COUNTER_43_LOW, 7562306a36Sopenharmony_ci TxJumboFramesReceivedOK = SUNI1x10GEXP_REG_MSTAT_COUNTER_51_LOW, 7662306a36Sopenharmony_ci TxJumboOctetsReceivedOK = SUNI1x10GEXP_REG_MSTAT_COUNTER_52_LOW 7762306a36Sopenharmony_ci}; 7862306a36Sopenharmony_ci 7962306a36Sopenharmony_cistruct _cmac_instance { 8062306a36Sopenharmony_ci u8 enabled; 8162306a36Sopenharmony_ci u8 fc; 8262306a36Sopenharmony_ci u8 mac_addr[6]; 8362306a36Sopenharmony_ci}; 8462306a36Sopenharmony_ci 8562306a36Sopenharmony_cistatic int pmread(struct cmac *cmac, u32 reg, u32 * data32) 8662306a36Sopenharmony_ci{ 8762306a36Sopenharmony_ci t1_tpi_read(cmac->adapter, OFFSET(reg), data32); 8862306a36Sopenharmony_ci return 0; 8962306a36Sopenharmony_ci} 9062306a36Sopenharmony_ci 9162306a36Sopenharmony_cistatic int pmwrite(struct cmac *cmac, u32 reg, u32 data32) 9262306a36Sopenharmony_ci{ 9362306a36Sopenharmony_ci t1_tpi_write(cmac->adapter, OFFSET(reg), data32); 9462306a36Sopenharmony_ci return 0; 9562306a36Sopenharmony_ci} 9662306a36Sopenharmony_ci 9762306a36Sopenharmony_ci/* Port reset. */ 9862306a36Sopenharmony_cistatic int pm3393_reset(struct cmac *cmac) 9962306a36Sopenharmony_ci{ 10062306a36Sopenharmony_ci return 0; 10162306a36Sopenharmony_ci} 10262306a36Sopenharmony_ci 10362306a36Sopenharmony_ci/* 10462306a36Sopenharmony_ci * Enable interrupts for the PM3393 10562306a36Sopenharmony_ci * 10662306a36Sopenharmony_ci * 1. Enable PM3393 BLOCK interrupts. 10762306a36Sopenharmony_ci * 2. Enable PM3393 Master Interrupt bit(INTE) 10862306a36Sopenharmony_ci * 3. Enable ELMER's PM3393 bit. 10962306a36Sopenharmony_ci * 4. Enable Terminator external interrupt. 11062306a36Sopenharmony_ci */ 11162306a36Sopenharmony_cistatic int pm3393_interrupt_enable(struct cmac *cmac) 11262306a36Sopenharmony_ci{ 11362306a36Sopenharmony_ci u32 pl_intr; 11462306a36Sopenharmony_ci 11562306a36Sopenharmony_ci /* PM3393 - Enabling all hardware block interrupts. 11662306a36Sopenharmony_ci */ 11762306a36Sopenharmony_ci pmwrite(cmac, SUNI1x10GEXP_REG_SERDES_3125_INTERRUPT_ENABLE, 0xffff); 11862306a36Sopenharmony_ci pmwrite(cmac, SUNI1x10GEXP_REG_XRF_INTERRUPT_ENABLE, 0xffff); 11962306a36Sopenharmony_ci pmwrite(cmac, SUNI1x10GEXP_REG_XRF_DIAG_INTERRUPT_ENABLE, 0xffff); 12062306a36Sopenharmony_ci pmwrite(cmac, SUNI1x10GEXP_REG_RXOAM_INTERRUPT_ENABLE, 0xffff); 12162306a36Sopenharmony_ci 12262306a36Sopenharmony_ci /* Don't interrupt on statistics overflow, we are polling */ 12362306a36Sopenharmony_ci pmwrite(cmac, SUNI1x10GEXP_REG_MSTAT_INTERRUPT_MASK_0, 0); 12462306a36Sopenharmony_ci pmwrite(cmac, SUNI1x10GEXP_REG_MSTAT_INTERRUPT_MASK_1, 0); 12562306a36Sopenharmony_ci pmwrite(cmac, SUNI1x10GEXP_REG_MSTAT_INTERRUPT_MASK_2, 0); 12662306a36Sopenharmony_ci pmwrite(cmac, SUNI1x10GEXP_REG_MSTAT_INTERRUPT_MASK_3, 0); 12762306a36Sopenharmony_ci 12862306a36Sopenharmony_ci pmwrite(cmac, SUNI1x10GEXP_REG_IFLX_FIFO_OVERFLOW_ENABLE, 0xffff); 12962306a36Sopenharmony_ci pmwrite(cmac, SUNI1x10GEXP_REG_PL4ODP_INTERRUPT_MASK, 0xffff); 13062306a36Sopenharmony_ci pmwrite(cmac, SUNI1x10GEXP_REG_XTEF_INTERRUPT_ENABLE, 0xffff); 13162306a36Sopenharmony_ci pmwrite(cmac, SUNI1x10GEXP_REG_TXOAM_INTERRUPT_ENABLE, 0xffff); 13262306a36Sopenharmony_ci pmwrite(cmac, SUNI1x10GEXP_REG_RXXG_CONFIG_3, 0xffff); 13362306a36Sopenharmony_ci pmwrite(cmac, SUNI1x10GEXP_REG_PL4IO_LOCK_DETECT_MASK, 0xffff); 13462306a36Sopenharmony_ci pmwrite(cmac, SUNI1x10GEXP_REG_TXXG_CONFIG_3, 0xffff); 13562306a36Sopenharmony_ci pmwrite(cmac, SUNI1x10GEXP_REG_PL4IDU_INTERRUPT_MASK, 0xffff); 13662306a36Sopenharmony_ci pmwrite(cmac, SUNI1x10GEXP_REG_EFLX_FIFO_OVERFLOW_ERROR_ENABLE, 0xffff); 13762306a36Sopenharmony_ci 13862306a36Sopenharmony_ci /* PM3393 - Global interrupt enable 13962306a36Sopenharmony_ci */ 14062306a36Sopenharmony_ci /* TBD XXX Disable for now until we figure out why error interrupts keep asserting. */ 14162306a36Sopenharmony_ci pmwrite(cmac, SUNI1x10GEXP_REG_GLOBAL_INTERRUPT_ENABLE, 14262306a36Sopenharmony_ci 0 /*SUNI1x10GEXP_BITMSK_TOP_INTE */ ); 14362306a36Sopenharmony_ci 14462306a36Sopenharmony_ci /* TERMINATOR - PL_INTERUPTS_EXT */ 14562306a36Sopenharmony_ci pl_intr = readl(cmac->adapter->regs + A_PL_ENABLE); 14662306a36Sopenharmony_ci pl_intr |= F_PL_INTR_EXT; 14762306a36Sopenharmony_ci writel(pl_intr, cmac->adapter->regs + A_PL_ENABLE); 14862306a36Sopenharmony_ci return 0; 14962306a36Sopenharmony_ci} 15062306a36Sopenharmony_ci 15162306a36Sopenharmony_cistatic int pm3393_interrupt_disable(struct cmac *cmac) 15262306a36Sopenharmony_ci{ 15362306a36Sopenharmony_ci u32 elmer; 15462306a36Sopenharmony_ci 15562306a36Sopenharmony_ci /* PM3393 - Enabling HW interrupt blocks. */ 15662306a36Sopenharmony_ci pmwrite(cmac, SUNI1x10GEXP_REG_SERDES_3125_INTERRUPT_ENABLE, 0); 15762306a36Sopenharmony_ci pmwrite(cmac, SUNI1x10GEXP_REG_XRF_INTERRUPT_ENABLE, 0); 15862306a36Sopenharmony_ci pmwrite(cmac, SUNI1x10GEXP_REG_XRF_DIAG_INTERRUPT_ENABLE, 0); 15962306a36Sopenharmony_ci pmwrite(cmac, SUNI1x10GEXP_REG_RXOAM_INTERRUPT_ENABLE, 0); 16062306a36Sopenharmony_ci pmwrite(cmac, SUNI1x10GEXP_REG_MSTAT_INTERRUPT_MASK_0, 0); 16162306a36Sopenharmony_ci pmwrite(cmac, SUNI1x10GEXP_REG_MSTAT_INTERRUPT_MASK_1, 0); 16262306a36Sopenharmony_ci pmwrite(cmac, SUNI1x10GEXP_REG_MSTAT_INTERRUPT_MASK_2, 0); 16362306a36Sopenharmony_ci pmwrite(cmac, SUNI1x10GEXP_REG_MSTAT_INTERRUPT_MASK_3, 0); 16462306a36Sopenharmony_ci pmwrite(cmac, SUNI1x10GEXP_REG_IFLX_FIFO_OVERFLOW_ENABLE, 0); 16562306a36Sopenharmony_ci pmwrite(cmac, SUNI1x10GEXP_REG_PL4ODP_INTERRUPT_MASK, 0); 16662306a36Sopenharmony_ci pmwrite(cmac, SUNI1x10GEXP_REG_XTEF_INTERRUPT_ENABLE, 0); 16762306a36Sopenharmony_ci pmwrite(cmac, SUNI1x10GEXP_REG_TXOAM_INTERRUPT_ENABLE, 0); 16862306a36Sopenharmony_ci pmwrite(cmac, SUNI1x10GEXP_REG_RXXG_CONFIG_3, 0); 16962306a36Sopenharmony_ci pmwrite(cmac, SUNI1x10GEXP_REG_PL4IO_LOCK_DETECT_MASK, 0); 17062306a36Sopenharmony_ci pmwrite(cmac, SUNI1x10GEXP_REG_TXXG_CONFIG_3, 0); 17162306a36Sopenharmony_ci pmwrite(cmac, SUNI1x10GEXP_REG_PL4IDU_INTERRUPT_MASK, 0); 17262306a36Sopenharmony_ci pmwrite(cmac, SUNI1x10GEXP_REG_EFLX_FIFO_OVERFLOW_ERROR_ENABLE, 0); 17362306a36Sopenharmony_ci 17462306a36Sopenharmony_ci /* PM3393 - Global interrupt enable */ 17562306a36Sopenharmony_ci pmwrite(cmac, SUNI1x10GEXP_REG_GLOBAL_INTERRUPT_ENABLE, 0); 17662306a36Sopenharmony_ci 17762306a36Sopenharmony_ci /* ELMER - External chip interrupts. */ 17862306a36Sopenharmony_ci t1_tpi_read(cmac->adapter, A_ELMER0_INT_ENABLE, &elmer); 17962306a36Sopenharmony_ci elmer &= ~ELMER0_GP_BIT1; 18062306a36Sopenharmony_ci t1_tpi_write(cmac->adapter, A_ELMER0_INT_ENABLE, elmer); 18162306a36Sopenharmony_ci 18262306a36Sopenharmony_ci /* TERMINATOR - PL_INTERUPTS_EXT */ 18362306a36Sopenharmony_ci /* DO NOT DISABLE TERMINATOR's EXTERNAL INTERRUPTS. ANOTHER CHIP 18462306a36Sopenharmony_ci * COULD WANT THEM ENABLED. We disable PM3393 at the ELMER level. 18562306a36Sopenharmony_ci */ 18662306a36Sopenharmony_ci 18762306a36Sopenharmony_ci return 0; 18862306a36Sopenharmony_ci} 18962306a36Sopenharmony_ci 19062306a36Sopenharmony_cistatic int pm3393_interrupt_clear(struct cmac *cmac) 19162306a36Sopenharmony_ci{ 19262306a36Sopenharmony_ci u32 elmer; 19362306a36Sopenharmony_ci u32 pl_intr; 19462306a36Sopenharmony_ci u32 val32; 19562306a36Sopenharmony_ci 19662306a36Sopenharmony_ci /* PM3393 - Clearing HW interrupt blocks. Note, this assumes 19762306a36Sopenharmony_ci * bit WCIMODE=0 for a clear-on-read. 19862306a36Sopenharmony_ci */ 19962306a36Sopenharmony_ci pmread(cmac, SUNI1x10GEXP_REG_SERDES_3125_INTERRUPT_STATUS, &val32); 20062306a36Sopenharmony_ci pmread(cmac, SUNI1x10GEXP_REG_XRF_INTERRUPT_STATUS, &val32); 20162306a36Sopenharmony_ci pmread(cmac, SUNI1x10GEXP_REG_XRF_DIAG_INTERRUPT_STATUS, &val32); 20262306a36Sopenharmony_ci pmread(cmac, SUNI1x10GEXP_REG_RXOAM_INTERRUPT_STATUS, &val32); 20362306a36Sopenharmony_ci pmread(cmac, SUNI1x10GEXP_REG_PL4ODP_INTERRUPT, &val32); 20462306a36Sopenharmony_ci pmread(cmac, SUNI1x10GEXP_REG_XTEF_INTERRUPT_STATUS, &val32); 20562306a36Sopenharmony_ci pmread(cmac, SUNI1x10GEXP_REG_IFLX_FIFO_OVERFLOW_INTERRUPT, &val32); 20662306a36Sopenharmony_ci pmread(cmac, SUNI1x10GEXP_REG_TXOAM_INTERRUPT_STATUS, &val32); 20762306a36Sopenharmony_ci pmread(cmac, SUNI1x10GEXP_REG_RXXG_INTERRUPT, &val32); 20862306a36Sopenharmony_ci pmread(cmac, SUNI1x10GEXP_REG_TXXG_INTERRUPT, &val32); 20962306a36Sopenharmony_ci pmread(cmac, SUNI1x10GEXP_REG_PL4IDU_INTERRUPT, &val32); 21062306a36Sopenharmony_ci pmread(cmac, SUNI1x10GEXP_REG_EFLX_FIFO_OVERFLOW_ERROR_INDICATION, 21162306a36Sopenharmony_ci &val32); 21262306a36Sopenharmony_ci pmread(cmac, SUNI1x10GEXP_REG_PL4IO_LOCK_DETECT_STATUS, &val32); 21362306a36Sopenharmony_ci pmread(cmac, SUNI1x10GEXP_REG_PL4IO_LOCK_DETECT_CHANGE, &val32); 21462306a36Sopenharmony_ci 21562306a36Sopenharmony_ci /* PM3393 - Global interrupt status 21662306a36Sopenharmony_ci */ 21762306a36Sopenharmony_ci pmread(cmac, SUNI1x10GEXP_REG_MASTER_INTERRUPT_STATUS, &val32); 21862306a36Sopenharmony_ci 21962306a36Sopenharmony_ci /* ELMER - External chip interrupts. 22062306a36Sopenharmony_ci */ 22162306a36Sopenharmony_ci t1_tpi_read(cmac->adapter, A_ELMER0_INT_CAUSE, &elmer); 22262306a36Sopenharmony_ci elmer |= ELMER0_GP_BIT1; 22362306a36Sopenharmony_ci t1_tpi_write(cmac->adapter, A_ELMER0_INT_CAUSE, elmer); 22462306a36Sopenharmony_ci 22562306a36Sopenharmony_ci /* TERMINATOR - PL_INTERUPTS_EXT 22662306a36Sopenharmony_ci */ 22762306a36Sopenharmony_ci pl_intr = readl(cmac->adapter->regs + A_PL_CAUSE); 22862306a36Sopenharmony_ci pl_intr |= F_PL_INTR_EXT; 22962306a36Sopenharmony_ci writel(pl_intr, cmac->adapter->regs + A_PL_CAUSE); 23062306a36Sopenharmony_ci 23162306a36Sopenharmony_ci return 0; 23262306a36Sopenharmony_ci} 23362306a36Sopenharmony_ci 23462306a36Sopenharmony_ci/* Interrupt handler */ 23562306a36Sopenharmony_cistatic int pm3393_interrupt_handler(struct cmac *cmac) 23662306a36Sopenharmony_ci{ 23762306a36Sopenharmony_ci u32 master_intr_status; 23862306a36Sopenharmony_ci 23962306a36Sopenharmony_ci /* Read the master interrupt status register. */ 24062306a36Sopenharmony_ci pmread(cmac, SUNI1x10GEXP_REG_MASTER_INTERRUPT_STATUS, 24162306a36Sopenharmony_ci &master_intr_status); 24262306a36Sopenharmony_ci if (netif_msg_intr(cmac->adapter)) 24362306a36Sopenharmony_ci dev_dbg(&cmac->adapter->pdev->dev, "PM3393 intr cause 0x%x\n", 24462306a36Sopenharmony_ci master_intr_status); 24562306a36Sopenharmony_ci 24662306a36Sopenharmony_ci /* TBD XXX Lets just clear everything for now */ 24762306a36Sopenharmony_ci pm3393_interrupt_clear(cmac); 24862306a36Sopenharmony_ci 24962306a36Sopenharmony_ci return 0; 25062306a36Sopenharmony_ci} 25162306a36Sopenharmony_ci 25262306a36Sopenharmony_cistatic int pm3393_enable(struct cmac *cmac, int which) 25362306a36Sopenharmony_ci{ 25462306a36Sopenharmony_ci if (which & MAC_DIRECTION_RX) 25562306a36Sopenharmony_ci pmwrite(cmac, SUNI1x10GEXP_REG_RXXG_CONFIG_1, 25662306a36Sopenharmony_ci (RXXG_CONF1_VAL | SUNI1x10GEXP_BITMSK_RXXG_RXEN)); 25762306a36Sopenharmony_ci 25862306a36Sopenharmony_ci if (which & MAC_DIRECTION_TX) { 25962306a36Sopenharmony_ci u32 val = TXXG_CONF1_VAL | SUNI1x10GEXP_BITMSK_TXXG_TXEN0; 26062306a36Sopenharmony_ci 26162306a36Sopenharmony_ci if (cmac->instance->fc & PAUSE_RX) 26262306a36Sopenharmony_ci val |= SUNI1x10GEXP_BITMSK_TXXG_FCRX; 26362306a36Sopenharmony_ci if (cmac->instance->fc & PAUSE_TX) 26462306a36Sopenharmony_ci val |= SUNI1x10GEXP_BITMSK_TXXG_FCTX; 26562306a36Sopenharmony_ci pmwrite(cmac, SUNI1x10GEXP_REG_TXXG_CONFIG_1, val); 26662306a36Sopenharmony_ci } 26762306a36Sopenharmony_ci 26862306a36Sopenharmony_ci cmac->instance->enabled |= which; 26962306a36Sopenharmony_ci return 0; 27062306a36Sopenharmony_ci} 27162306a36Sopenharmony_ci 27262306a36Sopenharmony_cistatic int pm3393_enable_port(struct cmac *cmac, int which) 27362306a36Sopenharmony_ci{ 27462306a36Sopenharmony_ci /* Clear port statistics */ 27562306a36Sopenharmony_ci pmwrite(cmac, SUNI1x10GEXP_REG_MSTAT_CONTROL, 27662306a36Sopenharmony_ci SUNI1x10GEXP_BITMSK_MSTAT_CLEAR); 27762306a36Sopenharmony_ci udelay(2); 27862306a36Sopenharmony_ci memset(&cmac->stats, 0, sizeof(struct cmac_statistics)); 27962306a36Sopenharmony_ci 28062306a36Sopenharmony_ci pm3393_enable(cmac, which); 28162306a36Sopenharmony_ci 28262306a36Sopenharmony_ci /* 28362306a36Sopenharmony_ci * XXX This should be done by the PHY and preferably not at all. 28462306a36Sopenharmony_ci * The PHY doesn't give us link status indication on its own so have 28562306a36Sopenharmony_ci * the link management code query it instead. 28662306a36Sopenharmony_ci */ 28762306a36Sopenharmony_ci t1_link_changed(cmac->adapter, 0); 28862306a36Sopenharmony_ci return 0; 28962306a36Sopenharmony_ci} 29062306a36Sopenharmony_ci 29162306a36Sopenharmony_cistatic int pm3393_disable(struct cmac *cmac, int which) 29262306a36Sopenharmony_ci{ 29362306a36Sopenharmony_ci if (which & MAC_DIRECTION_RX) 29462306a36Sopenharmony_ci pmwrite(cmac, SUNI1x10GEXP_REG_RXXG_CONFIG_1, RXXG_CONF1_VAL); 29562306a36Sopenharmony_ci if (which & MAC_DIRECTION_TX) 29662306a36Sopenharmony_ci pmwrite(cmac, SUNI1x10GEXP_REG_TXXG_CONFIG_1, TXXG_CONF1_VAL); 29762306a36Sopenharmony_ci 29862306a36Sopenharmony_ci /* 29962306a36Sopenharmony_ci * The disable is graceful. Give the PM3393 time. Can't wait very 30062306a36Sopenharmony_ci * long here, we may be holding locks. 30162306a36Sopenharmony_ci */ 30262306a36Sopenharmony_ci udelay(20); 30362306a36Sopenharmony_ci 30462306a36Sopenharmony_ci cmac->instance->enabled &= ~which; 30562306a36Sopenharmony_ci return 0; 30662306a36Sopenharmony_ci} 30762306a36Sopenharmony_ci 30862306a36Sopenharmony_cistatic int pm3393_loopback_enable(struct cmac *cmac) 30962306a36Sopenharmony_ci{ 31062306a36Sopenharmony_ci return 0; 31162306a36Sopenharmony_ci} 31262306a36Sopenharmony_ci 31362306a36Sopenharmony_cistatic int pm3393_loopback_disable(struct cmac *cmac) 31462306a36Sopenharmony_ci{ 31562306a36Sopenharmony_ci return 0; 31662306a36Sopenharmony_ci} 31762306a36Sopenharmony_ci 31862306a36Sopenharmony_cistatic int pm3393_set_mtu(struct cmac *cmac, int mtu) 31962306a36Sopenharmony_ci{ 32062306a36Sopenharmony_ci int enabled = cmac->instance->enabled; 32162306a36Sopenharmony_ci 32262306a36Sopenharmony_ci mtu += ETH_HLEN + ETH_FCS_LEN; 32362306a36Sopenharmony_ci 32462306a36Sopenharmony_ci /* Disable Rx/Tx MAC before configuring it. */ 32562306a36Sopenharmony_ci if (enabled) 32662306a36Sopenharmony_ci pm3393_disable(cmac, MAC_DIRECTION_RX | MAC_DIRECTION_TX); 32762306a36Sopenharmony_ci 32862306a36Sopenharmony_ci pmwrite(cmac, SUNI1x10GEXP_REG_RXXG_MAX_FRAME_LENGTH, mtu); 32962306a36Sopenharmony_ci pmwrite(cmac, SUNI1x10GEXP_REG_TXXG_MAX_FRAME_SIZE, mtu); 33062306a36Sopenharmony_ci 33162306a36Sopenharmony_ci if (enabled) 33262306a36Sopenharmony_ci pm3393_enable(cmac, enabled); 33362306a36Sopenharmony_ci return 0; 33462306a36Sopenharmony_ci} 33562306a36Sopenharmony_ci 33662306a36Sopenharmony_cistatic int pm3393_set_rx_mode(struct cmac *cmac, struct t1_rx_mode *rm) 33762306a36Sopenharmony_ci{ 33862306a36Sopenharmony_ci int enabled = cmac->instance->enabled & MAC_DIRECTION_RX; 33962306a36Sopenharmony_ci u32 rx_mode; 34062306a36Sopenharmony_ci 34162306a36Sopenharmony_ci /* Disable MAC RX before reconfiguring it */ 34262306a36Sopenharmony_ci if (enabled) 34362306a36Sopenharmony_ci pm3393_disable(cmac, MAC_DIRECTION_RX); 34462306a36Sopenharmony_ci 34562306a36Sopenharmony_ci pmread(cmac, SUNI1x10GEXP_REG_RXXG_ADDRESS_FILTER_CONTROL_2, &rx_mode); 34662306a36Sopenharmony_ci rx_mode &= ~(SUNI1x10GEXP_BITMSK_RXXG_PMODE | 34762306a36Sopenharmony_ci SUNI1x10GEXP_BITMSK_RXXG_MHASH_EN); 34862306a36Sopenharmony_ci pmwrite(cmac, SUNI1x10GEXP_REG_RXXG_ADDRESS_FILTER_CONTROL_2, 34962306a36Sopenharmony_ci (u16)rx_mode); 35062306a36Sopenharmony_ci 35162306a36Sopenharmony_ci if (t1_rx_mode_promisc(rm)) { 35262306a36Sopenharmony_ci /* Promiscuous mode. */ 35362306a36Sopenharmony_ci rx_mode |= SUNI1x10GEXP_BITMSK_RXXG_PMODE; 35462306a36Sopenharmony_ci } 35562306a36Sopenharmony_ci if (t1_rx_mode_allmulti(rm)) { 35662306a36Sopenharmony_ci /* Accept all multicast. */ 35762306a36Sopenharmony_ci pmwrite(cmac, SUNI1x10GEXP_REG_RXXG_MULTICAST_HASH_LOW, 0xffff); 35862306a36Sopenharmony_ci pmwrite(cmac, SUNI1x10GEXP_REG_RXXG_MULTICAST_HASH_MIDLOW, 0xffff); 35962306a36Sopenharmony_ci pmwrite(cmac, SUNI1x10GEXP_REG_RXXG_MULTICAST_HASH_MIDHIGH, 0xffff); 36062306a36Sopenharmony_ci pmwrite(cmac, SUNI1x10GEXP_REG_RXXG_MULTICAST_HASH_HIGH, 0xffff); 36162306a36Sopenharmony_ci rx_mode |= SUNI1x10GEXP_BITMSK_RXXG_MHASH_EN; 36262306a36Sopenharmony_ci } else if (t1_rx_mode_mc_cnt(rm)) { 36362306a36Sopenharmony_ci /* Accept one or more multicast(s). */ 36462306a36Sopenharmony_ci struct netdev_hw_addr *ha; 36562306a36Sopenharmony_ci int bit; 36662306a36Sopenharmony_ci u16 mc_filter[4] = { 0, }; 36762306a36Sopenharmony_ci 36862306a36Sopenharmony_ci netdev_for_each_mc_addr(ha, t1_get_netdev(rm)) { 36962306a36Sopenharmony_ci /* bit[23:28] */ 37062306a36Sopenharmony_ci bit = (ether_crc(ETH_ALEN, ha->addr) >> 23) & 0x3f; 37162306a36Sopenharmony_ci mc_filter[bit >> 4] |= 1 << (bit & 0xf); 37262306a36Sopenharmony_ci } 37362306a36Sopenharmony_ci pmwrite(cmac, SUNI1x10GEXP_REG_RXXG_MULTICAST_HASH_LOW, mc_filter[0]); 37462306a36Sopenharmony_ci pmwrite(cmac, SUNI1x10GEXP_REG_RXXG_MULTICAST_HASH_MIDLOW, mc_filter[1]); 37562306a36Sopenharmony_ci pmwrite(cmac, SUNI1x10GEXP_REG_RXXG_MULTICAST_HASH_MIDHIGH, mc_filter[2]); 37662306a36Sopenharmony_ci pmwrite(cmac, SUNI1x10GEXP_REG_RXXG_MULTICAST_HASH_HIGH, mc_filter[3]); 37762306a36Sopenharmony_ci rx_mode |= SUNI1x10GEXP_BITMSK_RXXG_MHASH_EN; 37862306a36Sopenharmony_ci } 37962306a36Sopenharmony_ci 38062306a36Sopenharmony_ci pmwrite(cmac, SUNI1x10GEXP_REG_RXXG_ADDRESS_FILTER_CONTROL_2, (u16)rx_mode); 38162306a36Sopenharmony_ci 38262306a36Sopenharmony_ci if (enabled) 38362306a36Sopenharmony_ci pm3393_enable(cmac, MAC_DIRECTION_RX); 38462306a36Sopenharmony_ci 38562306a36Sopenharmony_ci return 0; 38662306a36Sopenharmony_ci} 38762306a36Sopenharmony_ci 38862306a36Sopenharmony_cistatic int pm3393_get_speed_duplex_fc(struct cmac *cmac, int *speed, 38962306a36Sopenharmony_ci int *duplex, int *fc) 39062306a36Sopenharmony_ci{ 39162306a36Sopenharmony_ci if (speed) 39262306a36Sopenharmony_ci *speed = SPEED_10000; 39362306a36Sopenharmony_ci if (duplex) 39462306a36Sopenharmony_ci *duplex = DUPLEX_FULL; 39562306a36Sopenharmony_ci if (fc) 39662306a36Sopenharmony_ci *fc = cmac->instance->fc; 39762306a36Sopenharmony_ci return 0; 39862306a36Sopenharmony_ci} 39962306a36Sopenharmony_ci 40062306a36Sopenharmony_cistatic int pm3393_set_speed_duplex_fc(struct cmac *cmac, int speed, int duplex, 40162306a36Sopenharmony_ci int fc) 40262306a36Sopenharmony_ci{ 40362306a36Sopenharmony_ci if (speed >= 0 && speed != SPEED_10000) 40462306a36Sopenharmony_ci return -1; 40562306a36Sopenharmony_ci if (duplex >= 0 && duplex != DUPLEX_FULL) 40662306a36Sopenharmony_ci return -1; 40762306a36Sopenharmony_ci if (fc & ~(PAUSE_TX | PAUSE_RX)) 40862306a36Sopenharmony_ci return -1; 40962306a36Sopenharmony_ci 41062306a36Sopenharmony_ci if (fc != cmac->instance->fc) { 41162306a36Sopenharmony_ci cmac->instance->fc = (u8) fc; 41262306a36Sopenharmony_ci if (cmac->instance->enabled & MAC_DIRECTION_TX) 41362306a36Sopenharmony_ci pm3393_enable(cmac, MAC_DIRECTION_TX); 41462306a36Sopenharmony_ci } 41562306a36Sopenharmony_ci return 0; 41662306a36Sopenharmony_ci} 41762306a36Sopenharmony_ci 41862306a36Sopenharmony_ci#define RMON_UPDATE(mac, name, stat_name) \ 41962306a36Sopenharmony_ci{ \ 42062306a36Sopenharmony_ci t1_tpi_read((mac)->adapter, OFFSET(name), &val0); \ 42162306a36Sopenharmony_ci t1_tpi_read((mac)->adapter, OFFSET((name)+1), &val1); \ 42262306a36Sopenharmony_ci t1_tpi_read((mac)->adapter, OFFSET((name)+2), &val2); \ 42362306a36Sopenharmony_ci (mac)->stats.stat_name = (u64)(val0 & 0xffff) | \ 42462306a36Sopenharmony_ci ((u64)(val1 & 0xffff) << 16) | \ 42562306a36Sopenharmony_ci ((u64)(val2 & 0xff) << 32) | \ 42662306a36Sopenharmony_ci ((mac)->stats.stat_name & \ 42762306a36Sopenharmony_ci 0xffffff0000000000ULL); \ 42862306a36Sopenharmony_ci if (ro & \ 42962306a36Sopenharmony_ci (1ULL << ((name - SUNI1x10GEXP_REG_MSTAT_COUNTER_0_LOW) >> 2))) \ 43062306a36Sopenharmony_ci (mac)->stats.stat_name += 1ULL << 40; \ 43162306a36Sopenharmony_ci} 43262306a36Sopenharmony_ci 43362306a36Sopenharmony_cistatic const struct cmac_statistics *pm3393_update_statistics(struct cmac *mac, 43462306a36Sopenharmony_ci int flag) 43562306a36Sopenharmony_ci{ 43662306a36Sopenharmony_ci u64 ro; 43762306a36Sopenharmony_ci u32 val0, val1, val2, val3; 43862306a36Sopenharmony_ci 43962306a36Sopenharmony_ci /* Snap the counters */ 44062306a36Sopenharmony_ci pmwrite(mac, SUNI1x10GEXP_REG_MSTAT_CONTROL, 44162306a36Sopenharmony_ci SUNI1x10GEXP_BITMSK_MSTAT_SNAP); 44262306a36Sopenharmony_ci 44362306a36Sopenharmony_ci /* Counter rollover, clear on read */ 44462306a36Sopenharmony_ci pmread(mac, SUNI1x10GEXP_REG_MSTAT_COUNTER_ROLLOVER_0, &val0); 44562306a36Sopenharmony_ci pmread(mac, SUNI1x10GEXP_REG_MSTAT_COUNTER_ROLLOVER_1, &val1); 44662306a36Sopenharmony_ci pmread(mac, SUNI1x10GEXP_REG_MSTAT_COUNTER_ROLLOVER_2, &val2); 44762306a36Sopenharmony_ci pmread(mac, SUNI1x10GEXP_REG_MSTAT_COUNTER_ROLLOVER_3, &val3); 44862306a36Sopenharmony_ci ro = ((u64)val0 & 0xffff) | (((u64)val1 & 0xffff) << 16) | 44962306a36Sopenharmony_ci (((u64)val2 & 0xffff) << 32) | (((u64)val3 & 0xffff) << 48); 45062306a36Sopenharmony_ci 45162306a36Sopenharmony_ci /* Rx stats */ 45262306a36Sopenharmony_ci RMON_UPDATE(mac, RxOctetsReceivedOK, RxOctetsOK); 45362306a36Sopenharmony_ci RMON_UPDATE(mac, RxUnicastFramesReceivedOK, RxUnicastFramesOK); 45462306a36Sopenharmony_ci RMON_UPDATE(mac, RxMulticastFramesReceivedOK, RxMulticastFramesOK); 45562306a36Sopenharmony_ci RMON_UPDATE(mac, RxBroadcastFramesReceivedOK, RxBroadcastFramesOK); 45662306a36Sopenharmony_ci RMON_UPDATE(mac, RxPAUSEMACCtrlFramesReceived, RxPauseFrames); 45762306a36Sopenharmony_ci RMON_UPDATE(mac, RxFrameCheckSequenceErrors, RxFCSErrors); 45862306a36Sopenharmony_ci RMON_UPDATE(mac, RxFramesLostDueToInternalMACErrors, 45962306a36Sopenharmony_ci RxInternalMACRcvError); 46062306a36Sopenharmony_ci RMON_UPDATE(mac, RxSymbolErrors, RxSymbolErrors); 46162306a36Sopenharmony_ci RMON_UPDATE(mac, RxInRangeLengthErrors, RxInRangeLengthErrors); 46262306a36Sopenharmony_ci RMON_UPDATE(mac, RxFramesTooLongErrors , RxFrameTooLongErrors); 46362306a36Sopenharmony_ci RMON_UPDATE(mac, RxJabbers, RxJabberErrors); 46462306a36Sopenharmony_ci RMON_UPDATE(mac, RxFragments, RxRuntErrors); 46562306a36Sopenharmony_ci RMON_UPDATE(mac, RxUndersizedFrames, RxRuntErrors); 46662306a36Sopenharmony_ci RMON_UPDATE(mac, RxJumboFramesReceivedOK, RxJumboFramesOK); 46762306a36Sopenharmony_ci RMON_UPDATE(mac, RxJumboOctetsReceivedOK, RxJumboOctetsOK); 46862306a36Sopenharmony_ci 46962306a36Sopenharmony_ci /* Tx stats */ 47062306a36Sopenharmony_ci RMON_UPDATE(mac, TxOctetsTransmittedOK, TxOctetsOK); 47162306a36Sopenharmony_ci RMON_UPDATE(mac, TxFramesLostDueToInternalMACTransmissionError, 47262306a36Sopenharmony_ci TxInternalMACXmitError); 47362306a36Sopenharmony_ci RMON_UPDATE(mac, TxTransmitSystemError, TxFCSErrors); 47462306a36Sopenharmony_ci RMON_UPDATE(mac, TxUnicastFramesTransmittedOK, TxUnicastFramesOK); 47562306a36Sopenharmony_ci RMON_UPDATE(mac, TxMulticastFramesTransmittedOK, TxMulticastFramesOK); 47662306a36Sopenharmony_ci RMON_UPDATE(mac, TxBroadcastFramesTransmittedOK, TxBroadcastFramesOK); 47762306a36Sopenharmony_ci RMON_UPDATE(mac, TxPAUSEMACCtrlFramesTransmitted, TxPauseFrames); 47862306a36Sopenharmony_ci RMON_UPDATE(mac, TxJumboFramesReceivedOK, TxJumboFramesOK); 47962306a36Sopenharmony_ci RMON_UPDATE(mac, TxJumboOctetsReceivedOK, TxJumboOctetsOK); 48062306a36Sopenharmony_ci 48162306a36Sopenharmony_ci return &mac->stats; 48262306a36Sopenharmony_ci} 48362306a36Sopenharmony_ci 48462306a36Sopenharmony_cistatic int pm3393_macaddress_get(struct cmac *cmac, u8 mac_addr[6]) 48562306a36Sopenharmony_ci{ 48662306a36Sopenharmony_ci memcpy(mac_addr, cmac->instance->mac_addr, ETH_ALEN); 48762306a36Sopenharmony_ci return 0; 48862306a36Sopenharmony_ci} 48962306a36Sopenharmony_ci 49062306a36Sopenharmony_cistatic int pm3393_macaddress_set(struct cmac *cmac, const u8 ma[6]) 49162306a36Sopenharmony_ci{ 49262306a36Sopenharmony_ci u32 val, lo, mid, hi, enabled = cmac->instance->enabled; 49362306a36Sopenharmony_ci 49462306a36Sopenharmony_ci /* 49562306a36Sopenharmony_ci * MAC addr: 00:07:43:00:13:09 49662306a36Sopenharmony_ci * 49762306a36Sopenharmony_ci * ma[5] = 0x09 49862306a36Sopenharmony_ci * ma[4] = 0x13 49962306a36Sopenharmony_ci * ma[3] = 0x00 50062306a36Sopenharmony_ci * ma[2] = 0x43 50162306a36Sopenharmony_ci * ma[1] = 0x07 50262306a36Sopenharmony_ci * ma[0] = 0x00 50362306a36Sopenharmony_ci * 50462306a36Sopenharmony_ci * The PM3393 requires byte swapping and reverse order entry 50562306a36Sopenharmony_ci * when programming MAC addresses: 50662306a36Sopenharmony_ci * 50762306a36Sopenharmony_ci * low_bits[15:0] = ma[1]:ma[0] 50862306a36Sopenharmony_ci * mid_bits[31:16] = ma[3]:ma[2] 50962306a36Sopenharmony_ci * high_bits[47:32] = ma[5]:ma[4] 51062306a36Sopenharmony_ci */ 51162306a36Sopenharmony_ci 51262306a36Sopenharmony_ci /* Store local copy */ 51362306a36Sopenharmony_ci memcpy(cmac->instance->mac_addr, ma, ETH_ALEN); 51462306a36Sopenharmony_ci 51562306a36Sopenharmony_ci lo = ((u32) ma[1] << 8) | (u32) ma[0]; 51662306a36Sopenharmony_ci mid = ((u32) ma[3] << 8) | (u32) ma[2]; 51762306a36Sopenharmony_ci hi = ((u32) ma[5] << 8) | (u32) ma[4]; 51862306a36Sopenharmony_ci 51962306a36Sopenharmony_ci /* Disable Rx/Tx MAC before configuring it. */ 52062306a36Sopenharmony_ci if (enabled) 52162306a36Sopenharmony_ci pm3393_disable(cmac, MAC_DIRECTION_RX | MAC_DIRECTION_TX); 52262306a36Sopenharmony_ci 52362306a36Sopenharmony_ci /* Set RXXG Station Address */ 52462306a36Sopenharmony_ci pmwrite(cmac, SUNI1x10GEXP_REG_RXXG_SA_15_0, lo); 52562306a36Sopenharmony_ci pmwrite(cmac, SUNI1x10GEXP_REG_RXXG_SA_31_16, mid); 52662306a36Sopenharmony_ci pmwrite(cmac, SUNI1x10GEXP_REG_RXXG_SA_47_32, hi); 52762306a36Sopenharmony_ci 52862306a36Sopenharmony_ci /* Set TXXG Station Address */ 52962306a36Sopenharmony_ci pmwrite(cmac, SUNI1x10GEXP_REG_TXXG_SA_15_0, lo); 53062306a36Sopenharmony_ci pmwrite(cmac, SUNI1x10GEXP_REG_TXXG_SA_31_16, mid); 53162306a36Sopenharmony_ci pmwrite(cmac, SUNI1x10GEXP_REG_TXXG_SA_47_32, hi); 53262306a36Sopenharmony_ci 53362306a36Sopenharmony_ci /* Setup Exact Match Filter 1 with our MAC address 53462306a36Sopenharmony_ci * 53562306a36Sopenharmony_ci * Must disable exact match filter before configuring it. 53662306a36Sopenharmony_ci */ 53762306a36Sopenharmony_ci pmread(cmac, SUNI1x10GEXP_REG_RXXG_ADDRESS_FILTER_CONTROL_0, &val); 53862306a36Sopenharmony_ci val &= 0xff0f; 53962306a36Sopenharmony_ci pmwrite(cmac, SUNI1x10GEXP_REG_RXXG_ADDRESS_FILTER_CONTROL_0, val); 54062306a36Sopenharmony_ci 54162306a36Sopenharmony_ci pmwrite(cmac, SUNI1x10GEXP_REG_RXXG_EXACT_MATCH_ADDR_1_LOW, lo); 54262306a36Sopenharmony_ci pmwrite(cmac, SUNI1x10GEXP_REG_RXXG_EXACT_MATCH_ADDR_1_MID, mid); 54362306a36Sopenharmony_ci pmwrite(cmac, SUNI1x10GEXP_REG_RXXG_EXACT_MATCH_ADDR_1_HIGH, hi); 54462306a36Sopenharmony_ci 54562306a36Sopenharmony_ci val |= 0x0090; 54662306a36Sopenharmony_ci pmwrite(cmac, SUNI1x10GEXP_REG_RXXG_ADDRESS_FILTER_CONTROL_0, val); 54762306a36Sopenharmony_ci 54862306a36Sopenharmony_ci if (enabled) 54962306a36Sopenharmony_ci pm3393_enable(cmac, enabled); 55062306a36Sopenharmony_ci return 0; 55162306a36Sopenharmony_ci} 55262306a36Sopenharmony_ci 55362306a36Sopenharmony_cistatic void pm3393_destroy(struct cmac *cmac) 55462306a36Sopenharmony_ci{ 55562306a36Sopenharmony_ci kfree(cmac); 55662306a36Sopenharmony_ci} 55762306a36Sopenharmony_ci 55862306a36Sopenharmony_cistatic const struct cmac_ops pm3393_ops = { 55962306a36Sopenharmony_ci .destroy = pm3393_destroy, 56062306a36Sopenharmony_ci .reset = pm3393_reset, 56162306a36Sopenharmony_ci .interrupt_enable = pm3393_interrupt_enable, 56262306a36Sopenharmony_ci .interrupt_disable = pm3393_interrupt_disable, 56362306a36Sopenharmony_ci .interrupt_clear = pm3393_interrupt_clear, 56462306a36Sopenharmony_ci .interrupt_handler = pm3393_interrupt_handler, 56562306a36Sopenharmony_ci .enable = pm3393_enable_port, 56662306a36Sopenharmony_ci .disable = pm3393_disable, 56762306a36Sopenharmony_ci .loopback_enable = pm3393_loopback_enable, 56862306a36Sopenharmony_ci .loopback_disable = pm3393_loopback_disable, 56962306a36Sopenharmony_ci .set_mtu = pm3393_set_mtu, 57062306a36Sopenharmony_ci .set_rx_mode = pm3393_set_rx_mode, 57162306a36Sopenharmony_ci .get_speed_duplex_fc = pm3393_get_speed_duplex_fc, 57262306a36Sopenharmony_ci .set_speed_duplex_fc = pm3393_set_speed_duplex_fc, 57362306a36Sopenharmony_ci .statistics_update = pm3393_update_statistics, 57462306a36Sopenharmony_ci .macaddress_get = pm3393_macaddress_get, 57562306a36Sopenharmony_ci .macaddress_set = pm3393_macaddress_set 57662306a36Sopenharmony_ci}; 57762306a36Sopenharmony_ci 57862306a36Sopenharmony_cistatic struct cmac *pm3393_mac_create(adapter_t *adapter, int index) 57962306a36Sopenharmony_ci{ 58062306a36Sopenharmony_ci struct cmac *cmac; 58162306a36Sopenharmony_ci 58262306a36Sopenharmony_ci cmac = kzalloc(sizeof(*cmac) + sizeof(cmac_instance), GFP_KERNEL); 58362306a36Sopenharmony_ci if (!cmac) 58462306a36Sopenharmony_ci return NULL; 58562306a36Sopenharmony_ci 58662306a36Sopenharmony_ci cmac->ops = &pm3393_ops; 58762306a36Sopenharmony_ci cmac->instance = (cmac_instance *) (cmac + 1); 58862306a36Sopenharmony_ci cmac->adapter = adapter; 58962306a36Sopenharmony_ci cmac->instance->fc = PAUSE_TX | PAUSE_RX; 59062306a36Sopenharmony_ci 59162306a36Sopenharmony_ci t1_tpi_write(adapter, OFFSET(0x0001), 0x00008000); 59262306a36Sopenharmony_ci t1_tpi_write(adapter, OFFSET(0x0001), 0x00000000); 59362306a36Sopenharmony_ci t1_tpi_write(adapter, OFFSET(0x2308), 0x00009800); 59462306a36Sopenharmony_ci t1_tpi_write(adapter, OFFSET(0x2305), 0x00001001); /* PL4IO Enable */ 59562306a36Sopenharmony_ci t1_tpi_write(adapter, OFFSET(0x2320), 0x00008800); 59662306a36Sopenharmony_ci t1_tpi_write(adapter, OFFSET(0x2321), 0x00008800); 59762306a36Sopenharmony_ci t1_tpi_write(adapter, OFFSET(0x2322), 0x00008800); 59862306a36Sopenharmony_ci t1_tpi_write(adapter, OFFSET(0x2323), 0x00008800); 59962306a36Sopenharmony_ci t1_tpi_write(adapter, OFFSET(0x2324), 0x00008800); 60062306a36Sopenharmony_ci t1_tpi_write(adapter, OFFSET(0x2325), 0x00008800); 60162306a36Sopenharmony_ci t1_tpi_write(adapter, OFFSET(0x2326), 0x00008800); 60262306a36Sopenharmony_ci t1_tpi_write(adapter, OFFSET(0x2327), 0x00008800); 60362306a36Sopenharmony_ci t1_tpi_write(adapter, OFFSET(0x2328), 0x00008800); 60462306a36Sopenharmony_ci t1_tpi_write(adapter, OFFSET(0x2329), 0x00008800); 60562306a36Sopenharmony_ci t1_tpi_write(adapter, OFFSET(0x232a), 0x00008800); 60662306a36Sopenharmony_ci t1_tpi_write(adapter, OFFSET(0x232b), 0x00008800); 60762306a36Sopenharmony_ci t1_tpi_write(adapter, OFFSET(0x232c), 0x00008800); 60862306a36Sopenharmony_ci t1_tpi_write(adapter, OFFSET(0x232d), 0x00008800); 60962306a36Sopenharmony_ci t1_tpi_write(adapter, OFFSET(0x232e), 0x00008800); 61062306a36Sopenharmony_ci t1_tpi_write(adapter, OFFSET(0x232f), 0x00008800); 61162306a36Sopenharmony_ci t1_tpi_write(adapter, OFFSET(0x230d), 0x00009c00); 61262306a36Sopenharmony_ci t1_tpi_write(adapter, OFFSET(0x2304), 0x00000202); /* PL4IO Calendar Repetitions */ 61362306a36Sopenharmony_ci 61462306a36Sopenharmony_ci t1_tpi_write(adapter, OFFSET(0x3200), 0x00008080); /* EFLX Enable */ 61562306a36Sopenharmony_ci t1_tpi_write(adapter, OFFSET(0x3210), 0x00000000); /* EFLX Channel Deprovision */ 61662306a36Sopenharmony_ci t1_tpi_write(adapter, OFFSET(0x3203), 0x00000000); /* EFLX Low Limit */ 61762306a36Sopenharmony_ci t1_tpi_write(adapter, OFFSET(0x3204), 0x00000040); /* EFLX High Limit */ 61862306a36Sopenharmony_ci t1_tpi_write(adapter, OFFSET(0x3205), 0x000002cc); /* EFLX Almost Full */ 61962306a36Sopenharmony_ci t1_tpi_write(adapter, OFFSET(0x3206), 0x00000199); /* EFLX Almost Empty */ 62062306a36Sopenharmony_ci t1_tpi_write(adapter, OFFSET(0x3207), 0x00000240); /* EFLX Cut Through Threshold */ 62162306a36Sopenharmony_ci t1_tpi_write(adapter, OFFSET(0x3202), 0x00000000); /* EFLX Indirect Register Update */ 62262306a36Sopenharmony_ci t1_tpi_write(adapter, OFFSET(0x3210), 0x00000001); /* EFLX Channel Provision */ 62362306a36Sopenharmony_ci t1_tpi_write(adapter, OFFSET(0x3208), 0x0000ffff); /* EFLX Undocumented */ 62462306a36Sopenharmony_ci t1_tpi_write(adapter, OFFSET(0x320a), 0x0000ffff); /* EFLX Undocumented */ 62562306a36Sopenharmony_ci t1_tpi_write(adapter, OFFSET(0x320c), 0x0000ffff); /* EFLX enable overflow interrupt The other bit are undocumented */ 62662306a36Sopenharmony_ci t1_tpi_write(adapter, OFFSET(0x320e), 0x0000ffff); /* EFLX Undocumented */ 62762306a36Sopenharmony_ci 62862306a36Sopenharmony_ci t1_tpi_write(adapter, OFFSET(0x2200), 0x0000c000); /* IFLX Configuration - enable */ 62962306a36Sopenharmony_ci t1_tpi_write(adapter, OFFSET(0x2201), 0x00000000); /* IFLX Channel Deprovision */ 63062306a36Sopenharmony_ci t1_tpi_write(adapter, OFFSET(0x220e), 0x00000000); /* IFLX Low Limit */ 63162306a36Sopenharmony_ci t1_tpi_write(adapter, OFFSET(0x220f), 0x00000100); /* IFLX High Limit */ 63262306a36Sopenharmony_ci t1_tpi_write(adapter, OFFSET(0x2210), 0x00000c00); /* IFLX Almost Full Limit */ 63362306a36Sopenharmony_ci t1_tpi_write(adapter, OFFSET(0x2211), 0x00000599); /* IFLX Almost Empty Limit */ 63462306a36Sopenharmony_ci t1_tpi_write(adapter, OFFSET(0x220d), 0x00000000); /* IFLX Indirect Register Update */ 63562306a36Sopenharmony_ci t1_tpi_write(adapter, OFFSET(0x2201), 0x00000001); /* IFLX Channel Provision */ 63662306a36Sopenharmony_ci t1_tpi_write(adapter, OFFSET(0x2203), 0x0000ffff); /* IFLX Undocumented */ 63762306a36Sopenharmony_ci t1_tpi_write(adapter, OFFSET(0x2205), 0x0000ffff); /* IFLX Undocumented */ 63862306a36Sopenharmony_ci t1_tpi_write(adapter, OFFSET(0x2209), 0x0000ffff); /* IFLX Enable overflow interrupt. The other bit are undocumented */ 63962306a36Sopenharmony_ci 64062306a36Sopenharmony_ci t1_tpi_write(adapter, OFFSET(0x2241), 0xfffffffe); /* PL4MOS Undocumented */ 64162306a36Sopenharmony_ci t1_tpi_write(adapter, OFFSET(0x2242), 0x0000ffff); /* PL4MOS Undocumented */ 64262306a36Sopenharmony_ci t1_tpi_write(adapter, OFFSET(0x2243), 0x00000008); /* PL4MOS Starving Burst Size */ 64362306a36Sopenharmony_ci t1_tpi_write(adapter, OFFSET(0x2244), 0x00000008); /* PL4MOS Hungry Burst Size */ 64462306a36Sopenharmony_ci t1_tpi_write(adapter, OFFSET(0x2245), 0x00000008); /* PL4MOS Transfer Size */ 64562306a36Sopenharmony_ci t1_tpi_write(adapter, OFFSET(0x2240), 0x00000005); /* PL4MOS Disable */ 64662306a36Sopenharmony_ci 64762306a36Sopenharmony_ci t1_tpi_write(adapter, OFFSET(0x2280), 0x00002103); /* PL4ODP Training Repeat and SOP rule */ 64862306a36Sopenharmony_ci t1_tpi_write(adapter, OFFSET(0x2284), 0x00000000); /* PL4ODP MAX_T setting */ 64962306a36Sopenharmony_ci 65062306a36Sopenharmony_ci t1_tpi_write(adapter, OFFSET(0x3280), 0x00000087); /* PL4IDU Enable data forward, port state machine. Set ALLOW_NON_ZERO_OLB */ 65162306a36Sopenharmony_ci t1_tpi_write(adapter, OFFSET(0x3282), 0x0000001f); /* PL4IDU Enable Dip4 check error interrupts */ 65262306a36Sopenharmony_ci 65362306a36Sopenharmony_ci t1_tpi_write(adapter, OFFSET(0x3040), 0x0c32); /* # TXXG Config */ 65462306a36Sopenharmony_ci /* For T1 use timer based Mac flow control. */ 65562306a36Sopenharmony_ci t1_tpi_write(adapter, OFFSET(0x304d), 0x8000); 65662306a36Sopenharmony_ci t1_tpi_write(adapter, OFFSET(0x2040), 0x059c); /* # RXXG Config */ 65762306a36Sopenharmony_ci t1_tpi_write(adapter, OFFSET(0x2049), 0x0001); /* # RXXG Cut Through */ 65862306a36Sopenharmony_ci t1_tpi_write(adapter, OFFSET(0x2070), 0x0000); /* # Disable promiscuous mode */ 65962306a36Sopenharmony_ci 66062306a36Sopenharmony_ci /* Setup Exact Match Filter 0 to allow broadcast packets. 66162306a36Sopenharmony_ci */ 66262306a36Sopenharmony_ci t1_tpi_write(adapter, OFFSET(0x206e), 0x0000); /* # Disable Match Enable bit */ 66362306a36Sopenharmony_ci t1_tpi_write(adapter, OFFSET(0x204a), 0xffff); /* # low addr */ 66462306a36Sopenharmony_ci t1_tpi_write(adapter, OFFSET(0x204b), 0xffff); /* # mid addr */ 66562306a36Sopenharmony_ci t1_tpi_write(adapter, OFFSET(0x204c), 0xffff); /* # high addr */ 66662306a36Sopenharmony_ci t1_tpi_write(adapter, OFFSET(0x206e), 0x0009); /* # Enable Match Enable bit */ 66762306a36Sopenharmony_ci 66862306a36Sopenharmony_ci t1_tpi_write(adapter, OFFSET(0x0003), 0x0000); /* # NO SOP/ PAD_EN setup */ 66962306a36Sopenharmony_ci t1_tpi_write(adapter, OFFSET(0x0100), 0x0ff0); /* # RXEQB disabled */ 67062306a36Sopenharmony_ci t1_tpi_write(adapter, OFFSET(0x0101), 0x0f0f); /* # No Preemphasis */ 67162306a36Sopenharmony_ci 67262306a36Sopenharmony_ci return cmac; 67362306a36Sopenharmony_ci} 67462306a36Sopenharmony_ci 67562306a36Sopenharmony_cistatic int pm3393_mac_reset(adapter_t * adapter) 67662306a36Sopenharmony_ci{ 67762306a36Sopenharmony_ci u32 val; 67862306a36Sopenharmony_ci u32 x; 67962306a36Sopenharmony_ci u32 is_pl4_reset_finished; 68062306a36Sopenharmony_ci u32 is_pl4_outof_lock; 68162306a36Sopenharmony_ci u32 is_xaui_mabc_pll_locked; 68262306a36Sopenharmony_ci u32 successful_reset; 68362306a36Sopenharmony_ci int i; 68462306a36Sopenharmony_ci 68562306a36Sopenharmony_ci /* The following steps are required to properly reset 68662306a36Sopenharmony_ci * the PM3393. This information is provided in the 68762306a36Sopenharmony_ci * PM3393 datasheet (Issue 2: November 2002) 68862306a36Sopenharmony_ci * section 13.1 -- Device Reset. 68962306a36Sopenharmony_ci * 69062306a36Sopenharmony_ci * The PM3393 has three types of components that are 69162306a36Sopenharmony_ci * individually reset: 69262306a36Sopenharmony_ci * 69362306a36Sopenharmony_ci * DRESETB - Digital circuitry 69462306a36Sopenharmony_ci * PL4_ARESETB - PL4 analog circuitry 69562306a36Sopenharmony_ci * XAUI_ARESETB - XAUI bus analog circuitry 69662306a36Sopenharmony_ci * 69762306a36Sopenharmony_ci * Steps to reset PM3393 using RSTB pin: 69862306a36Sopenharmony_ci * 69962306a36Sopenharmony_ci * 1. Assert RSTB pin low ( write 0 ) 70062306a36Sopenharmony_ci * 2. Wait at least 1ms to initiate a complete initialization of device. 70162306a36Sopenharmony_ci * 3. Wait until all external clocks and REFSEL are stable. 70262306a36Sopenharmony_ci * 4. Wait minimum of 1ms. (after external clocks and REFEL are stable) 70362306a36Sopenharmony_ci * 5. De-assert RSTB ( write 1 ) 70462306a36Sopenharmony_ci * 6. Wait until internal timers to expires after ~14ms. 70562306a36Sopenharmony_ci * - Allows analog clock synthesizer(PL4CSU) to stabilize to 70662306a36Sopenharmony_ci * selected reference frequency before allowing the digital 70762306a36Sopenharmony_ci * portion of the device to operate. 70862306a36Sopenharmony_ci * 7. Wait at least 200us for XAUI interface to stabilize. 70962306a36Sopenharmony_ci * 8. Verify the PM3393 came out of reset successfully. 71062306a36Sopenharmony_ci * Set successful reset flag if everything worked else try again 71162306a36Sopenharmony_ci * a few more times. 71262306a36Sopenharmony_ci */ 71362306a36Sopenharmony_ci 71462306a36Sopenharmony_ci successful_reset = 0; 71562306a36Sopenharmony_ci for (i = 0; i < 3 && !successful_reset; i++) { 71662306a36Sopenharmony_ci /* 1 */ 71762306a36Sopenharmony_ci t1_tpi_read(adapter, A_ELMER0_GPO, &val); 71862306a36Sopenharmony_ci val &= ~1; 71962306a36Sopenharmony_ci t1_tpi_write(adapter, A_ELMER0_GPO, val); 72062306a36Sopenharmony_ci 72162306a36Sopenharmony_ci /* 2 */ 72262306a36Sopenharmony_ci msleep(1); 72362306a36Sopenharmony_ci 72462306a36Sopenharmony_ci /* 3 */ 72562306a36Sopenharmony_ci msleep(1); 72662306a36Sopenharmony_ci 72762306a36Sopenharmony_ci /* 4 */ 72862306a36Sopenharmony_ci msleep(2 /*1 extra ms for safety */ ); 72962306a36Sopenharmony_ci 73062306a36Sopenharmony_ci /* 5 */ 73162306a36Sopenharmony_ci val |= 1; 73262306a36Sopenharmony_ci t1_tpi_write(adapter, A_ELMER0_GPO, val); 73362306a36Sopenharmony_ci 73462306a36Sopenharmony_ci /* 6 */ 73562306a36Sopenharmony_ci msleep(15 /*1 extra ms for safety */ ); 73662306a36Sopenharmony_ci 73762306a36Sopenharmony_ci /* 7 */ 73862306a36Sopenharmony_ci msleep(1); 73962306a36Sopenharmony_ci 74062306a36Sopenharmony_ci /* 8 */ 74162306a36Sopenharmony_ci 74262306a36Sopenharmony_ci /* Has PL4 analog block come out of reset correctly? */ 74362306a36Sopenharmony_ci t1_tpi_read(adapter, OFFSET(SUNI1x10GEXP_REG_DEVICE_STATUS), &val); 74462306a36Sopenharmony_ci is_pl4_reset_finished = (val & SUNI1x10GEXP_BITMSK_TOP_EXPIRED); 74562306a36Sopenharmony_ci 74662306a36Sopenharmony_ci /* TBD XXX SUNI1x10GEXP_BITMSK_TOP_PL4_IS_DOOL gets locked later in the init sequence 74762306a36Sopenharmony_ci * figure out why? */ 74862306a36Sopenharmony_ci 74962306a36Sopenharmony_ci /* Have all PL4 block clocks locked? */ 75062306a36Sopenharmony_ci x = (SUNI1x10GEXP_BITMSK_TOP_PL4_ID_DOOL 75162306a36Sopenharmony_ci /*| SUNI1x10GEXP_BITMSK_TOP_PL4_IS_DOOL */ | 75262306a36Sopenharmony_ci SUNI1x10GEXP_BITMSK_TOP_PL4_ID_ROOL | 75362306a36Sopenharmony_ci SUNI1x10GEXP_BITMSK_TOP_PL4_IS_ROOL | 75462306a36Sopenharmony_ci SUNI1x10GEXP_BITMSK_TOP_PL4_OUT_ROOL); 75562306a36Sopenharmony_ci is_pl4_outof_lock = (val & x); 75662306a36Sopenharmony_ci 75762306a36Sopenharmony_ci /* ??? If this fails, might be able to software reset the XAUI part 75862306a36Sopenharmony_ci * and try to recover... thus saving us from doing another HW reset */ 75962306a36Sopenharmony_ci /* Has the XAUI MABC PLL circuitry stablized? */ 76062306a36Sopenharmony_ci is_xaui_mabc_pll_locked = 76162306a36Sopenharmony_ci (val & SUNI1x10GEXP_BITMSK_TOP_SXRA_EXPIRED); 76262306a36Sopenharmony_ci 76362306a36Sopenharmony_ci successful_reset = (is_pl4_reset_finished && !is_pl4_outof_lock 76462306a36Sopenharmony_ci && is_xaui_mabc_pll_locked); 76562306a36Sopenharmony_ci 76662306a36Sopenharmony_ci if (netif_msg_hw(adapter)) 76762306a36Sopenharmony_ci dev_dbg(&adapter->pdev->dev, 76862306a36Sopenharmony_ci "PM3393 HW reset %d: pl4_reset 0x%x, val 0x%x, " 76962306a36Sopenharmony_ci "is_pl4_outof_lock 0x%x, xaui_locked 0x%x\n", 77062306a36Sopenharmony_ci i, is_pl4_reset_finished, val, 77162306a36Sopenharmony_ci is_pl4_outof_lock, is_xaui_mabc_pll_locked); 77262306a36Sopenharmony_ci } 77362306a36Sopenharmony_ci return successful_reset ? 0 : 1; 77462306a36Sopenharmony_ci} 77562306a36Sopenharmony_ci 77662306a36Sopenharmony_ciconst struct gmac t1_pm3393_ops = { 77762306a36Sopenharmony_ci .stats_update_period = STATS_TICK_SECS, 77862306a36Sopenharmony_ci .create = pm3393_mac_create, 77962306a36Sopenharmony_ci .reset = pm3393_mac_reset, 78062306a36Sopenharmony_ci}; 781