18c2ecf20Sopenharmony_ci/*****************************************************************************
28c2ecf20Sopenharmony_ci *                                                                           *
38c2ecf20Sopenharmony_ci * File: pm3393.c                                                            *
48c2ecf20Sopenharmony_ci * $Revision: 1.16 $                                                         *
58c2ecf20Sopenharmony_ci * $Date: 2005/05/14 00:59:32 $                                              *
68c2ecf20Sopenharmony_ci * Description:                                                              *
78c2ecf20Sopenharmony_ci *  PMC/SIERRA (pm3393) MAC-PHY functionality.                               *
88c2ecf20Sopenharmony_ci *  part of the Chelsio 10Gb Ethernet Driver.                                *
98c2ecf20Sopenharmony_ci *                                                                           *
108c2ecf20Sopenharmony_ci * This program is free software; you can redistribute it and/or modify      *
118c2ecf20Sopenharmony_ci * it under the terms of the GNU General Public License, version 2, as       *
128c2ecf20Sopenharmony_ci * published by the Free Software Foundation.                                *
138c2ecf20Sopenharmony_ci *                                                                           *
148c2ecf20Sopenharmony_ci * You should have received a copy of the GNU General Public License along   *
158c2ecf20Sopenharmony_ci * with this program; if not, see <http://www.gnu.org/licenses/>.            *
168c2ecf20Sopenharmony_ci *                                                                           *
178c2ecf20Sopenharmony_ci * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED    *
188c2ecf20Sopenharmony_ci * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF      *
198c2ecf20Sopenharmony_ci * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.                     *
208c2ecf20Sopenharmony_ci *                                                                           *
218c2ecf20Sopenharmony_ci * http://www.chelsio.com                                                    *
228c2ecf20Sopenharmony_ci *                                                                           *
238c2ecf20Sopenharmony_ci * Copyright (c) 2003 - 2005 Chelsio Communications, Inc.                    *
248c2ecf20Sopenharmony_ci * All rights reserved.                                                      *
258c2ecf20Sopenharmony_ci *                                                                           *
268c2ecf20Sopenharmony_ci * Maintainers: maintainers@chelsio.com                                      *
278c2ecf20Sopenharmony_ci *                                                                           *
288c2ecf20Sopenharmony_ci * Authors: Dimitrios Michailidis   <dm@chelsio.com>                         *
298c2ecf20Sopenharmony_ci *          Tina Yang               <tainay@chelsio.com>                     *
308c2ecf20Sopenharmony_ci *          Felix Marti             <felix@chelsio.com>                      *
318c2ecf20Sopenharmony_ci *          Scott Bardone           <sbardone@chelsio.com>                   *
328c2ecf20Sopenharmony_ci *          Kurt Ottaway            <kottaway@chelsio.com>                   *
338c2ecf20Sopenharmony_ci *          Frank DiMambro          <frank@chelsio.com>                      *
348c2ecf20Sopenharmony_ci *                                                                           *
358c2ecf20Sopenharmony_ci * History:                                                                  *
368c2ecf20Sopenharmony_ci *                                                                           *
378c2ecf20Sopenharmony_ci ****************************************************************************/
388c2ecf20Sopenharmony_ci
398c2ecf20Sopenharmony_ci#include "common.h"
408c2ecf20Sopenharmony_ci#include "regs.h"
418c2ecf20Sopenharmony_ci#include "gmac.h"
428c2ecf20Sopenharmony_ci#include "elmer0.h"
438c2ecf20Sopenharmony_ci#include "suni1x10gexp_regs.h"
448c2ecf20Sopenharmony_ci
458c2ecf20Sopenharmony_ci#include <linux/crc32.h>
468c2ecf20Sopenharmony_ci#include <linux/slab.h>
478c2ecf20Sopenharmony_ci
488c2ecf20Sopenharmony_ci#define OFFSET(REG_ADDR)    ((REG_ADDR) << 2)
498c2ecf20Sopenharmony_ci
508c2ecf20Sopenharmony_ci#define IPG 12
518c2ecf20Sopenharmony_ci#define TXXG_CONF1_VAL ((IPG << SUNI1x10GEXP_BITOFF_TXXG_IPGT) | \
528c2ecf20Sopenharmony_ci	SUNI1x10GEXP_BITMSK_TXXG_32BIT_ALIGN | SUNI1x10GEXP_BITMSK_TXXG_CRCEN | \
538c2ecf20Sopenharmony_ci	SUNI1x10GEXP_BITMSK_TXXG_PADEN)
548c2ecf20Sopenharmony_ci#define RXXG_CONF1_VAL (SUNI1x10GEXP_BITMSK_RXXG_PUREP | 0x14 | \
558c2ecf20Sopenharmony_ci	SUNI1x10GEXP_BITMSK_RXXG_FLCHK | SUNI1x10GEXP_BITMSK_RXXG_CRC_STRIP)
568c2ecf20Sopenharmony_ci
578c2ecf20Sopenharmony_ci/* Update statistics every 15 minutes */
588c2ecf20Sopenharmony_ci#define STATS_TICK_SECS (15 * 60)
598c2ecf20Sopenharmony_ci
608c2ecf20Sopenharmony_cienum {                     /* RMON registers */
618c2ecf20Sopenharmony_ci	RxOctetsReceivedOK = SUNI1x10GEXP_REG_MSTAT_COUNTER_1_LOW,
628c2ecf20Sopenharmony_ci	RxUnicastFramesReceivedOK = SUNI1x10GEXP_REG_MSTAT_COUNTER_4_LOW,
638c2ecf20Sopenharmony_ci	RxMulticastFramesReceivedOK = SUNI1x10GEXP_REG_MSTAT_COUNTER_5_LOW,
648c2ecf20Sopenharmony_ci	RxBroadcastFramesReceivedOK = SUNI1x10GEXP_REG_MSTAT_COUNTER_6_LOW,
658c2ecf20Sopenharmony_ci	RxPAUSEMACCtrlFramesReceived = SUNI1x10GEXP_REG_MSTAT_COUNTER_8_LOW,
668c2ecf20Sopenharmony_ci	RxFrameCheckSequenceErrors = SUNI1x10GEXP_REG_MSTAT_COUNTER_10_LOW,
678c2ecf20Sopenharmony_ci	RxFramesLostDueToInternalMACErrors = SUNI1x10GEXP_REG_MSTAT_COUNTER_11_LOW,
688c2ecf20Sopenharmony_ci	RxSymbolErrors = SUNI1x10GEXP_REG_MSTAT_COUNTER_12_LOW,
698c2ecf20Sopenharmony_ci	RxInRangeLengthErrors = SUNI1x10GEXP_REG_MSTAT_COUNTER_13_LOW,
708c2ecf20Sopenharmony_ci	RxFramesTooLongErrors = SUNI1x10GEXP_REG_MSTAT_COUNTER_15_LOW,
718c2ecf20Sopenharmony_ci	RxJabbers = SUNI1x10GEXP_REG_MSTAT_COUNTER_16_LOW,
728c2ecf20Sopenharmony_ci	RxFragments = SUNI1x10GEXP_REG_MSTAT_COUNTER_17_LOW,
738c2ecf20Sopenharmony_ci	RxUndersizedFrames =  SUNI1x10GEXP_REG_MSTAT_COUNTER_18_LOW,
748c2ecf20Sopenharmony_ci	RxJumboFramesReceivedOK = SUNI1x10GEXP_REG_MSTAT_COUNTER_25_LOW,
758c2ecf20Sopenharmony_ci	RxJumboOctetsReceivedOK = SUNI1x10GEXP_REG_MSTAT_COUNTER_26_LOW,
768c2ecf20Sopenharmony_ci
778c2ecf20Sopenharmony_ci	TxOctetsTransmittedOK = SUNI1x10GEXP_REG_MSTAT_COUNTER_33_LOW,
788c2ecf20Sopenharmony_ci	TxFramesLostDueToInternalMACTransmissionError = SUNI1x10GEXP_REG_MSTAT_COUNTER_35_LOW,
798c2ecf20Sopenharmony_ci	TxTransmitSystemError = SUNI1x10GEXP_REG_MSTAT_COUNTER_36_LOW,
808c2ecf20Sopenharmony_ci	TxUnicastFramesTransmittedOK = SUNI1x10GEXP_REG_MSTAT_COUNTER_38_LOW,
818c2ecf20Sopenharmony_ci	TxMulticastFramesTransmittedOK = SUNI1x10GEXP_REG_MSTAT_COUNTER_40_LOW,
828c2ecf20Sopenharmony_ci	TxBroadcastFramesTransmittedOK = SUNI1x10GEXP_REG_MSTAT_COUNTER_42_LOW,
838c2ecf20Sopenharmony_ci	TxPAUSEMACCtrlFramesTransmitted = SUNI1x10GEXP_REG_MSTAT_COUNTER_43_LOW,
848c2ecf20Sopenharmony_ci	TxJumboFramesReceivedOK = SUNI1x10GEXP_REG_MSTAT_COUNTER_51_LOW,
858c2ecf20Sopenharmony_ci	TxJumboOctetsReceivedOK = SUNI1x10GEXP_REG_MSTAT_COUNTER_52_LOW
868c2ecf20Sopenharmony_ci};
878c2ecf20Sopenharmony_ci
888c2ecf20Sopenharmony_cistruct _cmac_instance {
898c2ecf20Sopenharmony_ci	u8 enabled;
908c2ecf20Sopenharmony_ci	u8 fc;
918c2ecf20Sopenharmony_ci	u8 mac_addr[6];
928c2ecf20Sopenharmony_ci};
938c2ecf20Sopenharmony_ci
948c2ecf20Sopenharmony_cistatic int pmread(struct cmac *cmac, u32 reg, u32 * data32)
958c2ecf20Sopenharmony_ci{
968c2ecf20Sopenharmony_ci	t1_tpi_read(cmac->adapter, OFFSET(reg), data32);
978c2ecf20Sopenharmony_ci	return 0;
988c2ecf20Sopenharmony_ci}
998c2ecf20Sopenharmony_ci
1008c2ecf20Sopenharmony_cistatic int pmwrite(struct cmac *cmac, u32 reg, u32 data32)
1018c2ecf20Sopenharmony_ci{
1028c2ecf20Sopenharmony_ci	t1_tpi_write(cmac->adapter, OFFSET(reg), data32);
1038c2ecf20Sopenharmony_ci	return 0;
1048c2ecf20Sopenharmony_ci}
1058c2ecf20Sopenharmony_ci
1068c2ecf20Sopenharmony_ci/* Port reset. */
1078c2ecf20Sopenharmony_cistatic int pm3393_reset(struct cmac *cmac)
1088c2ecf20Sopenharmony_ci{
1098c2ecf20Sopenharmony_ci	return 0;
1108c2ecf20Sopenharmony_ci}
1118c2ecf20Sopenharmony_ci
1128c2ecf20Sopenharmony_ci/*
1138c2ecf20Sopenharmony_ci * Enable interrupts for the PM3393
1148c2ecf20Sopenharmony_ci *
1158c2ecf20Sopenharmony_ci *	1. Enable PM3393 BLOCK interrupts.
1168c2ecf20Sopenharmony_ci *	2. Enable PM3393 Master Interrupt bit(INTE)
1178c2ecf20Sopenharmony_ci *	3. Enable ELMER's PM3393 bit.
1188c2ecf20Sopenharmony_ci *	4. Enable Terminator external interrupt.
1198c2ecf20Sopenharmony_ci */
1208c2ecf20Sopenharmony_cistatic int pm3393_interrupt_enable(struct cmac *cmac)
1218c2ecf20Sopenharmony_ci{
1228c2ecf20Sopenharmony_ci	u32 pl_intr;
1238c2ecf20Sopenharmony_ci
1248c2ecf20Sopenharmony_ci	/* PM3393 - Enabling all hardware block interrupts.
1258c2ecf20Sopenharmony_ci	 */
1268c2ecf20Sopenharmony_ci	pmwrite(cmac, SUNI1x10GEXP_REG_SERDES_3125_INTERRUPT_ENABLE, 0xffff);
1278c2ecf20Sopenharmony_ci	pmwrite(cmac, SUNI1x10GEXP_REG_XRF_INTERRUPT_ENABLE, 0xffff);
1288c2ecf20Sopenharmony_ci	pmwrite(cmac, SUNI1x10GEXP_REG_XRF_DIAG_INTERRUPT_ENABLE, 0xffff);
1298c2ecf20Sopenharmony_ci	pmwrite(cmac, SUNI1x10GEXP_REG_RXOAM_INTERRUPT_ENABLE, 0xffff);
1308c2ecf20Sopenharmony_ci
1318c2ecf20Sopenharmony_ci	/* Don't interrupt on statistics overflow, we are polling */
1328c2ecf20Sopenharmony_ci	pmwrite(cmac, SUNI1x10GEXP_REG_MSTAT_INTERRUPT_MASK_0, 0);
1338c2ecf20Sopenharmony_ci	pmwrite(cmac, SUNI1x10GEXP_REG_MSTAT_INTERRUPT_MASK_1, 0);
1348c2ecf20Sopenharmony_ci	pmwrite(cmac, SUNI1x10GEXP_REG_MSTAT_INTERRUPT_MASK_2, 0);
1358c2ecf20Sopenharmony_ci	pmwrite(cmac, SUNI1x10GEXP_REG_MSTAT_INTERRUPT_MASK_3, 0);
1368c2ecf20Sopenharmony_ci
1378c2ecf20Sopenharmony_ci	pmwrite(cmac, SUNI1x10GEXP_REG_IFLX_FIFO_OVERFLOW_ENABLE, 0xffff);
1388c2ecf20Sopenharmony_ci	pmwrite(cmac, SUNI1x10GEXP_REG_PL4ODP_INTERRUPT_MASK, 0xffff);
1398c2ecf20Sopenharmony_ci	pmwrite(cmac, SUNI1x10GEXP_REG_XTEF_INTERRUPT_ENABLE, 0xffff);
1408c2ecf20Sopenharmony_ci	pmwrite(cmac, SUNI1x10GEXP_REG_TXOAM_INTERRUPT_ENABLE, 0xffff);
1418c2ecf20Sopenharmony_ci	pmwrite(cmac, SUNI1x10GEXP_REG_RXXG_CONFIG_3, 0xffff);
1428c2ecf20Sopenharmony_ci	pmwrite(cmac, SUNI1x10GEXP_REG_PL4IO_LOCK_DETECT_MASK, 0xffff);
1438c2ecf20Sopenharmony_ci	pmwrite(cmac, SUNI1x10GEXP_REG_TXXG_CONFIG_3, 0xffff);
1448c2ecf20Sopenharmony_ci	pmwrite(cmac, SUNI1x10GEXP_REG_PL4IDU_INTERRUPT_MASK, 0xffff);
1458c2ecf20Sopenharmony_ci	pmwrite(cmac, SUNI1x10GEXP_REG_EFLX_FIFO_OVERFLOW_ERROR_ENABLE, 0xffff);
1468c2ecf20Sopenharmony_ci
1478c2ecf20Sopenharmony_ci	/* PM3393 - Global interrupt enable
1488c2ecf20Sopenharmony_ci	 */
1498c2ecf20Sopenharmony_ci	/* TBD XXX Disable for now until we figure out why error interrupts keep asserting. */
1508c2ecf20Sopenharmony_ci	pmwrite(cmac, SUNI1x10GEXP_REG_GLOBAL_INTERRUPT_ENABLE,
1518c2ecf20Sopenharmony_ci		0 /*SUNI1x10GEXP_BITMSK_TOP_INTE */ );
1528c2ecf20Sopenharmony_ci
1538c2ecf20Sopenharmony_ci	/* TERMINATOR - PL_INTERUPTS_EXT */
1548c2ecf20Sopenharmony_ci	pl_intr = readl(cmac->adapter->regs + A_PL_ENABLE);
1558c2ecf20Sopenharmony_ci	pl_intr |= F_PL_INTR_EXT;
1568c2ecf20Sopenharmony_ci	writel(pl_intr, cmac->adapter->regs + A_PL_ENABLE);
1578c2ecf20Sopenharmony_ci	return 0;
1588c2ecf20Sopenharmony_ci}
1598c2ecf20Sopenharmony_ci
1608c2ecf20Sopenharmony_cistatic int pm3393_interrupt_disable(struct cmac *cmac)
1618c2ecf20Sopenharmony_ci{
1628c2ecf20Sopenharmony_ci	u32 elmer;
1638c2ecf20Sopenharmony_ci
1648c2ecf20Sopenharmony_ci	/* PM3393 - Enabling HW interrupt blocks. */
1658c2ecf20Sopenharmony_ci	pmwrite(cmac, SUNI1x10GEXP_REG_SERDES_3125_INTERRUPT_ENABLE, 0);
1668c2ecf20Sopenharmony_ci	pmwrite(cmac, SUNI1x10GEXP_REG_XRF_INTERRUPT_ENABLE, 0);
1678c2ecf20Sopenharmony_ci	pmwrite(cmac, SUNI1x10GEXP_REG_XRF_DIAG_INTERRUPT_ENABLE, 0);
1688c2ecf20Sopenharmony_ci	pmwrite(cmac, SUNI1x10GEXP_REG_RXOAM_INTERRUPT_ENABLE, 0);
1698c2ecf20Sopenharmony_ci	pmwrite(cmac, SUNI1x10GEXP_REG_MSTAT_INTERRUPT_MASK_0, 0);
1708c2ecf20Sopenharmony_ci	pmwrite(cmac, SUNI1x10GEXP_REG_MSTAT_INTERRUPT_MASK_1, 0);
1718c2ecf20Sopenharmony_ci	pmwrite(cmac, SUNI1x10GEXP_REG_MSTAT_INTERRUPT_MASK_2, 0);
1728c2ecf20Sopenharmony_ci	pmwrite(cmac, SUNI1x10GEXP_REG_MSTAT_INTERRUPT_MASK_3, 0);
1738c2ecf20Sopenharmony_ci	pmwrite(cmac, SUNI1x10GEXP_REG_IFLX_FIFO_OVERFLOW_ENABLE, 0);
1748c2ecf20Sopenharmony_ci	pmwrite(cmac, SUNI1x10GEXP_REG_PL4ODP_INTERRUPT_MASK, 0);
1758c2ecf20Sopenharmony_ci	pmwrite(cmac, SUNI1x10GEXP_REG_XTEF_INTERRUPT_ENABLE, 0);
1768c2ecf20Sopenharmony_ci	pmwrite(cmac, SUNI1x10GEXP_REG_TXOAM_INTERRUPT_ENABLE, 0);
1778c2ecf20Sopenharmony_ci	pmwrite(cmac, SUNI1x10GEXP_REG_RXXG_CONFIG_3, 0);
1788c2ecf20Sopenharmony_ci	pmwrite(cmac, SUNI1x10GEXP_REG_PL4IO_LOCK_DETECT_MASK, 0);
1798c2ecf20Sopenharmony_ci	pmwrite(cmac, SUNI1x10GEXP_REG_TXXG_CONFIG_3, 0);
1808c2ecf20Sopenharmony_ci	pmwrite(cmac, SUNI1x10GEXP_REG_PL4IDU_INTERRUPT_MASK, 0);
1818c2ecf20Sopenharmony_ci	pmwrite(cmac, SUNI1x10GEXP_REG_EFLX_FIFO_OVERFLOW_ERROR_ENABLE, 0);
1828c2ecf20Sopenharmony_ci
1838c2ecf20Sopenharmony_ci	/* PM3393 - Global interrupt enable */
1848c2ecf20Sopenharmony_ci	pmwrite(cmac, SUNI1x10GEXP_REG_GLOBAL_INTERRUPT_ENABLE, 0);
1858c2ecf20Sopenharmony_ci
1868c2ecf20Sopenharmony_ci	/* ELMER - External chip interrupts. */
1878c2ecf20Sopenharmony_ci	t1_tpi_read(cmac->adapter, A_ELMER0_INT_ENABLE, &elmer);
1888c2ecf20Sopenharmony_ci	elmer &= ~ELMER0_GP_BIT1;
1898c2ecf20Sopenharmony_ci	t1_tpi_write(cmac->adapter, A_ELMER0_INT_ENABLE, elmer);
1908c2ecf20Sopenharmony_ci
1918c2ecf20Sopenharmony_ci	/* TERMINATOR - PL_INTERUPTS_EXT */
1928c2ecf20Sopenharmony_ci	/* DO NOT DISABLE TERMINATOR's EXTERNAL INTERRUPTS. ANOTHER CHIP
1938c2ecf20Sopenharmony_ci	 * COULD WANT THEM ENABLED. We disable PM3393 at the ELMER level.
1948c2ecf20Sopenharmony_ci	 */
1958c2ecf20Sopenharmony_ci
1968c2ecf20Sopenharmony_ci	return 0;
1978c2ecf20Sopenharmony_ci}
1988c2ecf20Sopenharmony_ci
1998c2ecf20Sopenharmony_cistatic int pm3393_interrupt_clear(struct cmac *cmac)
2008c2ecf20Sopenharmony_ci{
2018c2ecf20Sopenharmony_ci	u32 elmer;
2028c2ecf20Sopenharmony_ci	u32 pl_intr;
2038c2ecf20Sopenharmony_ci	u32 val32;
2048c2ecf20Sopenharmony_ci
2058c2ecf20Sopenharmony_ci	/* PM3393 - Clearing HW interrupt blocks. Note, this assumes
2068c2ecf20Sopenharmony_ci	 *          bit WCIMODE=0 for a clear-on-read.
2078c2ecf20Sopenharmony_ci	 */
2088c2ecf20Sopenharmony_ci	pmread(cmac, SUNI1x10GEXP_REG_SERDES_3125_INTERRUPT_STATUS, &val32);
2098c2ecf20Sopenharmony_ci	pmread(cmac, SUNI1x10GEXP_REG_XRF_INTERRUPT_STATUS, &val32);
2108c2ecf20Sopenharmony_ci	pmread(cmac, SUNI1x10GEXP_REG_XRF_DIAG_INTERRUPT_STATUS, &val32);
2118c2ecf20Sopenharmony_ci	pmread(cmac, SUNI1x10GEXP_REG_RXOAM_INTERRUPT_STATUS, &val32);
2128c2ecf20Sopenharmony_ci	pmread(cmac, SUNI1x10GEXP_REG_PL4ODP_INTERRUPT, &val32);
2138c2ecf20Sopenharmony_ci	pmread(cmac, SUNI1x10GEXP_REG_XTEF_INTERRUPT_STATUS, &val32);
2148c2ecf20Sopenharmony_ci	pmread(cmac, SUNI1x10GEXP_REG_IFLX_FIFO_OVERFLOW_INTERRUPT, &val32);
2158c2ecf20Sopenharmony_ci	pmread(cmac, SUNI1x10GEXP_REG_TXOAM_INTERRUPT_STATUS, &val32);
2168c2ecf20Sopenharmony_ci	pmread(cmac, SUNI1x10GEXP_REG_RXXG_INTERRUPT, &val32);
2178c2ecf20Sopenharmony_ci	pmread(cmac, SUNI1x10GEXP_REG_TXXG_INTERRUPT, &val32);
2188c2ecf20Sopenharmony_ci	pmread(cmac, SUNI1x10GEXP_REG_PL4IDU_INTERRUPT, &val32);
2198c2ecf20Sopenharmony_ci	pmread(cmac, SUNI1x10GEXP_REG_EFLX_FIFO_OVERFLOW_ERROR_INDICATION,
2208c2ecf20Sopenharmony_ci	       &val32);
2218c2ecf20Sopenharmony_ci	pmread(cmac, SUNI1x10GEXP_REG_PL4IO_LOCK_DETECT_STATUS, &val32);
2228c2ecf20Sopenharmony_ci	pmread(cmac, SUNI1x10GEXP_REG_PL4IO_LOCK_DETECT_CHANGE, &val32);
2238c2ecf20Sopenharmony_ci
2248c2ecf20Sopenharmony_ci	/* PM3393 - Global interrupt status
2258c2ecf20Sopenharmony_ci	 */
2268c2ecf20Sopenharmony_ci	pmread(cmac, SUNI1x10GEXP_REG_MASTER_INTERRUPT_STATUS, &val32);
2278c2ecf20Sopenharmony_ci
2288c2ecf20Sopenharmony_ci	/* ELMER - External chip interrupts.
2298c2ecf20Sopenharmony_ci	 */
2308c2ecf20Sopenharmony_ci	t1_tpi_read(cmac->adapter, A_ELMER0_INT_CAUSE, &elmer);
2318c2ecf20Sopenharmony_ci	elmer |= ELMER0_GP_BIT1;
2328c2ecf20Sopenharmony_ci	t1_tpi_write(cmac->adapter, A_ELMER0_INT_CAUSE, elmer);
2338c2ecf20Sopenharmony_ci
2348c2ecf20Sopenharmony_ci	/* TERMINATOR - PL_INTERUPTS_EXT
2358c2ecf20Sopenharmony_ci	 */
2368c2ecf20Sopenharmony_ci	pl_intr = readl(cmac->adapter->regs + A_PL_CAUSE);
2378c2ecf20Sopenharmony_ci	pl_intr |= F_PL_INTR_EXT;
2388c2ecf20Sopenharmony_ci	writel(pl_intr, cmac->adapter->regs + A_PL_CAUSE);
2398c2ecf20Sopenharmony_ci
2408c2ecf20Sopenharmony_ci	return 0;
2418c2ecf20Sopenharmony_ci}
2428c2ecf20Sopenharmony_ci
2438c2ecf20Sopenharmony_ci/* Interrupt handler */
2448c2ecf20Sopenharmony_cistatic int pm3393_interrupt_handler(struct cmac *cmac)
2458c2ecf20Sopenharmony_ci{
2468c2ecf20Sopenharmony_ci	u32 master_intr_status;
2478c2ecf20Sopenharmony_ci
2488c2ecf20Sopenharmony_ci	/* Read the master interrupt status register. */
2498c2ecf20Sopenharmony_ci	pmread(cmac, SUNI1x10GEXP_REG_MASTER_INTERRUPT_STATUS,
2508c2ecf20Sopenharmony_ci	       &master_intr_status);
2518c2ecf20Sopenharmony_ci	if (netif_msg_intr(cmac->adapter))
2528c2ecf20Sopenharmony_ci		dev_dbg(&cmac->adapter->pdev->dev, "PM3393 intr cause 0x%x\n",
2538c2ecf20Sopenharmony_ci			master_intr_status);
2548c2ecf20Sopenharmony_ci
2558c2ecf20Sopenharmony_ci	/* TBD XXX Lets just clear everything for now */
2568c2ecf20Sopenharmony_ci	pm3393_interrupt_clear(cmac);
2578c2ecf20Sopenharmony_ci
2588c2ecf20Sopenharmony_ci	return 0;
2598c2ecf20Sopenharmony_ci}
2608c2ecf20Sopenharmony_ci
2618c2ecf20Sopenharmony_cistatic int pm3393_enable(struct cmac *cmac, int which)
2628c2ecf20Sopenharmony_ci{
2638c2ecf20Sopenharmony_ci	if (which & MAC_DIRECTION_RX)
2648c2ecf20Sopenharmony_ci		pmwrite(cmac, SUNI1x10GEXP_REG_RXXG_CONFIG_1,
2658c2ecf20Sopenharmony_ci			(RXXG_CONF1_VAL | SUNI1x10GEXP_BITMSK_RXXG_RXEN));
2668c2ecf20Sopenharmony_ci
2678c2ecf20Sopenharmony_ci	if (which & MAC_DIRECTION_TX) {
2688c2ecf20Sopenharmony_ci		u32 val = TXXG_CONF1_VAL | SUNI1x10GEXP_BITMSK_TXXG_TXEN0;
2698c2ecf20Sopenharmony_ci
2708c2ecf20Sopenharmony_ci		if (cmac->instance->fc & PAUSE_RX)
2718c2ecf20Sopenharmony_ci			val |= SUNI1x10GEXP_BITMSK_TXXG_FCRX;
2728c2ecf20Sopenharmony_ci		if (cmac->instance->fc & PAUSE_TX)
2738c2ecf20Sopenharmony_ci			val |= SUNI1x10GEXP_BITMSK_TXXG_FCTX;
2748c2ecf20Sopenharmony_ci		pmwrite(cmac, SUNI1x10GEXP_REG_TXXG_CONFIG_1, val);
2758c2ecf20Sopenharmony_ci	}
2768c2ecf20Sopenharmony_ci
2778c2ecf20Sopenharmony_ci	cmac->instance->enabled |= which;
2788c2ecf20Sopenharmony_ci	return 0;
2798c2ecf20Sopenharmony_ci}
2808c2ecf20Sopenharmony_ci
2818c2ecf20Sopenharmony_cistatic int pm3393_enable_port(struct cmac *cmac, int which)
2828c2ecf20Sopenharmony_ci{
2838c2ecf20Sopenharmony_ci	/* Clear port statistics */
2848c2ecf20Sopenharmony_ci	pmwrite(cmac, SUNI1x10GEXP_REG_MSTAT_CONTROL,
2858c2ecf20Sopenharmony_ci		SUNI1x10GEXP_BITMSK_MSTAT_CLEAR);
2868c2ecf20Sopenharmony_ci	udelay(2);
2878c2ecf20Sopenharmony_ci	memset(&cmac->stats, 0, sizeof(struct cmac_statistics));
2888c2ecf20Sopenharmony_ci
2898c2ecf20Sopenharmony_ci	pm3393_enable(cmac, which);
2908c2ecf20Sopenharmony_ci
2918c2ecf20Sopenharmony_ci	/*
2928c2ecf20Sopenharmony_ci	 * XXX This should be done by the PHY and preferably not at all.
2938c2ecf20Sopenharmony_ci	 * The PHY doesn't give us link status indication on its own so have
2948c2ecf20Sopenharmony_ci	 * the link management code query it instead.
2958c2ecf20Sopenharmony_ci	 */
2968c2ecf20Sopenharmony_ci	t1_link_changed(cmac->adapter, 0);
2978c2ecf20Sopenharmony_ci	return 0;
2988c2ecf20Sopenharmony_ci}
2998c2ecf20Sopenharmony_ci
3008c2ecf20Sopenharmony_cistatic int pm3393_disable(struct cmac *cmac, int which)
3018c2ecf20Sopenharmony_ci{
3028c2ecf20Sopenharmony_ci	if (which & MAC_DIRECTION_RX)
3038c2ecf20Sopenharmony_ci		pmwrite(cmac, SUNI1x10GEXP_REG_RXXG_CONFIG_1, RXXG_CONF1_VAL);
3048c2ecf20Sopenharmony_ci	if (which & MAC_DIRECTION_TX)
3058c2ecf20Sopenharmony_ci		pmwrite(cmac, SUNI1x10GEXP_REG_TXXG_CONFIG_1, TXXG_CONF1_VAL);
3068c2ecf20Sopenharmony_ci
3078c2ecf20Sopenharmony_ci	/*
3088c2ecf20Sopenharmony_ci	 * The disable is graceful. Give the PM3393 time.  Can't wait very
3098c2ecf20Sopenharmony_ci	 * long here, we may be holding locks.
3108c2ecf20Sopenharmony_ci	 */
3118c2ecf20Sopenharmony_ci	udelay(20);
3128c2ecf20Sopenharmony_ci
3138c2ecf20Sopenharmony_ci	cmac->instance->enabled &= ~which;
3148c2ecf20Sopenharmony_ci	return 0;
3158c2ecf20Sopenharmony_ci}
3168c2ecf20Sopenharmony_ci
3178c2ecf20Sopenharmony_cistatic int pm3393_loopback_enable(struct cmac *cmac)
3188c2ecf20Sopenharmony_ci{
3198c2ecf20Sopenharmony_ci	return 0;
3208c2ecf20Sopenharmony_ci}
3218c2ecf20Sopenharmony_ci
3228c2ecf20Sopenharmony_cistatic int pm3393_loopback_disable(struct cmac *cmac)
3238c2ecf20Sopenharmony_ci{
3248c2ecf20Sopenharmony_ci	return 0;
3258c2ecf20Sopenharmony_ci}
3268c2ecf20Sopenharmony_ci
3278c2ecf20Sopenharmony_cistatic int pm3393_set_mtu(struct cmac *cmac, int mtu)
3288c2ecf20Sopenharmony_ci{
3298c2ecf20Sopenharmony_ci	int enabled = cmac->instance->enabled;
3308c2ecf20Sopenharmony_ci
3318c2ecf20Sopenharmony_ci	mtu += ETH_HLEN + ETH_FCS_LEN;
3328c2ecf20Sopenharmony_ci
3338c2ecf20Sopenharmony_ci	/* Disable Rx/Tx MAC before configuring it. */
3348c2ecf20Sopenharmony_ci	if (enabled)
3358c2ecf20Sopenharmony_ci		pm3393_disable(cmac, MAC_DIRECTION_RX | MAC_DIRECTION_TX);
3368c2ecf20Sopenharmony_ci
3378c2ecf20Sopenharmony_ci	pmwrite(cmac, SUNI1x10GEXP_REG_RXXG_MAX_FRAME_LENGTH, mtu);
3388c2ecf20Sopenharmony_ci	pmwrite(cmac, SUNI1x10GEXP_REG_TXXG_MAX_FRAME_SIZE, mtu);
3398c2ecf20Sopenharmony_ci
3408c2ecf20Sopenharmony_ci	if (enabled)
3418c2ecf20Sopenharmony_ci		pm3393_enable(cmac, enabled);
3428c2ecf20Sopenharmony_ci	return 0;
3438c2ecf20Sopenharmony_ci}
3448c2ecf20Sopenharmony_ci
3458c2ecf20Sopenharmony_cistatic int pm3393_set_rx_mode(struct cmac *cmac, struct t1_rx_mode *rm)
3468c2ecf20Sopenharmony_ci{
3478c2ecf20Sopenharmony_ci	int enabled = cmac->instance->enabled & MAC_DIRECTION_RX;
3488c2ecf20Sopenharmony_ci	u32 rx_mode;
3498c2ecf20Sopenharmony_ci
3508c2ecf20Sopenharmony_ci	/* Disable MAC RX before reconfiguring it */
3518c2ecf20Sopenharmony_ci	if (enabled)
3528c2ecf20Sopenharmony_ci		pm3393_disable(cmac, MAC_DIRECTION_RX);
3538c2ecf20Sopenharmony_ci
3548c2ecf20Sopenharmony_ci	pmread(cmac, SUNI1x10GEXP_REG_RXXG_ADDRESS_FILTER_CONTROL_2, &rx_mode);
3558c2ecf20Sopenharmony_ci	rx_mode &= ~(SUNI1x10GEXP_BITMSK_RXXG_PMODE |
3568c2ecf20Sopenharmony_ci		     SUNI1x10GEXP_BITMSK_RXXG_MHASH_EN);
3578c2ecf20Sopenharmony_ci	pmwrite(cmac, SUNI1x10GEXP_REG_RXXG_ADDRESS_FILTER_CONTROL_2,
3588c2ecf20Sopenharmony_ci		(u16)rx_mode);
3598c2ecf20Sopenharmony_ci
3608c2ecf20Sopenharmony_ci	if (t1_rx_mode_promisc(rm)) {
3618c2ecf20Sopenharmony_ci		/* Promiscuous mode. */
3628c2ecf20Sopenharmony_ci		rx_mode |= SUNI1x10GEXP_BITMSK_RXXG_PMODE;
3638c2ecf20Sopenharmony_ci	}
3648c2ecf20Sopenharmony_ci	if (t1_rx_mode_allmulti(rm)) {
3658c2ecf20Sopenharmony_ci		/* Accept all multicast. */
3668c2ecf20Sopenharmony_ci		pmwrite(cmac, SUNI1x10GEXP_REG_RXXG_MULTICAST_HASH_LOW, 0xffff);
3678c2ecf20Sopenharmony_ci		pmwrite(cmac, SUNI1x10GEXP_REG_RXXG_MULTICAST_HASH_MIDLOW, 0xffff);
3688c2ecf20Sopenharmony_ci		pmwrite(cmac, SUNI1x10GEXP_REG_RXXG_MULTICAST_HASH_MIDHIGH, 0xffff);
3698c2ecf20Sopenharmony_ci		pmwrite(cmac, SUNI1x10GEXP_REG_RXXG_MULTICAST_HASH_HIGH, 0xffff);
3708c2ecf20Sopenharmony_ci		rx_mode |= SUNI1x10GEXP_BITMSK_RXXG_MHASH_EN;
3718c2ecf20Sopenharmony_ci	} else if (t1_rx_mode_mc_cnt(rm)) {
3728c2ecf20Sopenharmony_ci		/* Accept one or more multicast(s). */
3738c2ecf20Sopenharmony_ci		struct netdev_hw_addr *ha;
3748c2ecf20Sopenharmony_ci		int bit;
3758c2ecf20Sopenharmony_ci		u16 mc_filter[4] = { 0, };
3768c2ecf20Sopenharmony_ci
3778c2ecf20Sopenharmony_ci		netdev_for_each_mc_addr(ha, t1_get_netdev(rm)) {
3788c2ecf20Sopenharmony_ci			/* bit[23:28] */
3798c2ecf20Sopenharmony_ci			bit = (ether_crc(ETH_ALEN, ha->addr) >> 23) & 0x3f;
3808c2ecf20Sopenharmony_ci			mc_filter[bit >> 4] |= 1 << (bit & 0xf);
3818c2ecf20Sopenharmony_ci		}
3828c2ecf20Sopenharmony_ci		pmwrite(cmac, SUNI1x10GEXP_REG_RXXG_MULTICAST_HASH_LOW, mc_filter[0]);
3838c2ecf20Sopenharmony_ci		pmwrite(cmac, SUNI1x10GEXP_REG_RXXG_MULTICAST_HASH_MIDLOW, mc_filter[1]);
3848c2ecf20Sopenharmony_ci		pmwrite(cmac, SUNI1x10GEXP_REG_RXXG_MULTICAST_HASH_MIDHIGH, mc_filter[2]);
3858c2ecf20Sopenharmony_ci		pmwrite(cmac, SUNI1x10GEXP_REG_RXXG_MULTICAST_HASH_HIGH, mc_filter[3]);
3868c2ecf20Sopenharmony_ci		rx_mode |= SUNI1x10GEXP_BITMSK_RXXG_MHASH_EN;
3878c2ecf20Sopenharmony_ci	}
3888c2ecf20Sopenharmony_ci
3898c2ecf20Sopenharmony_ci	pmwrite(cmac, SUNI1x10GEXP_REG_RXXG_ADDRESS_FILTER_CONTROL_2, (u16)rx_mode);
3908c2ecf20Sopenharmony_ci
3918c2ecf20Sopenharmony_ci	if (enabled)
3928c2ecf20Sopenharmony_ci		pm3393_enable(cmac, MAC_DIRECTION_RX);
3938c2ecf20Sopenharmony_ci
3948c2ecf20Sopenharmony_ci	return 0;
3958c2ecf20Sopenharmony_ci}
3968c2ecf20Sopenharmony_ci
3978c2ecf20Sopenharmony_cistatic int pm3393_get_speed_duplex_fc(struct cmac *cmac, int *speed,
3988c2ecf20Sopenharmony_ci				      int *duplex, int *fc)
3998c2ecf20Sopenharmony_ci{
4008c2ecf20Sopenharmony_ci	if (speed)
4018c2ecf20Sopenharmony_ci		*speed = SPEED_10000;
4028c2ecf20Sopenharmony_ci	if (duplex)
4038c2ecf20Sopenharmony_ci		*duplex = DUPLEX_FULL;
4048c2ecf20Sopenharmony_ci	if (fc)
4058c2ecf20Sopenharmony_ci		*fc = cmac->instance->fc;
4068c2ecf20Sopenharmony_ci	return 0;
4078c2ecf20Sopenharmony_ci}
4088c2ecf20Sopenharmony_ci
4098c2ecf20Sopenharmony_cistatic int pm3393_set_speed_duplex_fc(struct cmac *cmac, int speed, int duplex,
4108c2ecf20Sopenharmony_ci				      int fc)
4118c2ecf20Sopenharmony_ci{
4128c2ecf20Sopenharmony_ci	if (speed >= 0 && speed != SPEED_10000)
4138c2ecf20Sopenharmony_ci		return -1;
4148c2ecf20Sopenharmony_ci	if (duplex >= 0 && duplex != DUPLEX_FULL)
4158c2ecf20Sopenharmony_ci		return -1;
4168c2ecf20Sopenharmony_ci	if (fc & ~(PAUSE_TX | PAUSE_RX))
4178c2ecf20Sopenharmony_ci		return -1;
4188c2ecf20Sopenharmony_ci
4198c2ecf20Sopenharmony_ci	if (fc != cmac->instance->fc) {
4208c2ecf20Sopenharmony_ci		cmac->instance->fc = (u8) fc;
4218c2ecf20Sopenharmony_ci		if (cmac->instance->enabled & MAC_DIRECTION_TX)
4228c2ecf20Sopenharmony_ci			pm3393_enable(cmac, MAC_DIRECTION_TX);
4238c2ecf20Sopenharmony_ci	}
4248c2ecf20Sopenharmony_ci	return 0;
4258c2ecf20Sopenharmony_ci}
4268c2ecf20Sopenharmony_ci
4278c2ecf20Sopenharmony_ci#define RMON_UPDATE(mac, name, stat_name) \
4288c2ecf20Sopenharmony_ci{ \
4298c2ecf20Sopenharmony_ci	t1_tpi_read((mac)->adapter, OFFSET(name), &val0);     \
4308c2ecf20Sopenharmony_ci	t1_tpi_read((mac)->adapter, OFFSET((name)+1), &val1); \
4318c2ecf20Sopenharmony_ci	t1_tpi_read((mac)->adapter, OFFSET((name)+2), &val2); \
4328c2ecf20Sopenharmony_ci	(mac)->stats.stat_name = (u64)(val0 & 0xffff) | \
4338c2ecf20Sopenharmony_ci				 ((u64)(val1 & 0xffff) << 16) | \
4348c2ecf20Sopenharmony_ci				 ((u64)(val2 & 0xff) << 32) | \
4358c2ecf20Sopenharmony_ci				 ((mac)->stats.stat_name & \
4368c2ecf20Sopenharmony_ci					0xffffff0000000000ULL); \
4378c2ecf20Sopenharmony_ci	if (ro & \
4388c2ecf20Sopenharmony_ci	    (1ULL << ((name - SUNI1x10GEXP_REG_MSTAT_COUNTER_0_LOW) >> 2))) \
4398c2ecf20Sopenharmony_ci		(mac)->stats.stat_name += 1ULL << 40; \
4408c2ecf20Sopenharmony_ci}
4418c2ecf20Sopenharmony_ci
4428c2ecf20Sopenharmony_cistatic const struct cmac_statistics *pm3393_update_statistics(struct cmac *mac,
4438c2ecf20Sopenharmony_ci							      int flag)
4448c2ecf20Sopenharmony_ci{
4458c2ecf20Sopenharmony_ci	u64	ro;
4468c2ecf20Sopenharmony_ci	u32	val0, val1, val2, val3;
4478c2ecf20Sopenharmony_ci
4488c2ecf20Sopenharmony_ci	/* Snap the counters */
4498c2ecf20Sopenharmony_ci	pmwrite(mac, SUNI1x10GEXP_REG_MSTAT_CONTROL,
4508c2ecf20Sopenharmony_ci		SUNI1x10GEXP_BITMSK_MSTAT_SNAP);
4518c2ecf20Sopenharmony_ci
4528c2ecf20Sopenharmony_ci	/* Counter rollover, clear on read */
4538c2ecf20Sopenharmony_ci	pmread(mac, SUNI1x10GEXP_REG_MSTAT_COUNTER_ROLLOVER_0, &val0);
4548c2ecf20Sopenharmony_ci	pmread(mac, SUNI1x10GEXP_REG_MSTAT_COUNTER_ROLLOVER_1, &val1);
4558c2ecf20Sopenharmony_ci	pmread(mac, SUNI1x10GEXP_REG_MSTAT_COUNTER_ROLLOVER_2, &val2);
4568c2ecf20Sopenharmony_ci	pmread(mac, SUNI1x10GEXP_REG_MSTAT_COUNTER_ROLLOVER_3, &val3);
4578c2ecf20Sopenharmony_ci	ro = ((u64)val0 & 0xffff) | (((u64)val1 & 0xffff) << 16) |
4588c2ecf20Sopenharmony_ci		(((u64)val2 & 0xffff) << 32) | (((u64)val3 & 0xffff) << 48);
4598c2ecf20Sopenharmony_ci
4608c2ecf20Sopenharmony_ci	/* Rx stats */
4618c2ecf20Sopenharmony_ci	RMON_UPDATE(mac, RxOctetsReceivedOK, RxOctetsOK);
4628c2ecf20Sopenharmony_ci	RMON_UPDATE(mac, RxUnicastFramesReceivedOK, RxUnicastFramesOK);
4638c2ecf20Sopenharmony_ci	RMON_UPDATE(mac, RxMulticastFramesReceivedOK, RxMulticastFramesOK);
4648c2ecf20Sopenharmony_ci	RMON_UPDATE(mac, RxBroadcastFramesReceivedOK, RxBroadcastFramesOK);
4658c2ecf20Sopenharmony_ci	RMON_UPDATE(mac, RxPAUSEMACCtrlFramesReceived, RxPauseFrames);
4668c2ecf20Sopenharmony_ci	RMON_UPDATE(mac, RxFrameCheckSequenceErrors, RxFCSErrors);
4678c2ecf20Sopenharmony_ci	RMON_UPDATE(mac, RxFramesLostDueToInternalMACErrors,
4688c2ecf20Sopenharmony_ci				RxInternalMACRcvError);
4698c2ecf20Sopenharmony_ci	RMON_UPDATE(mac, RxSymbolErrors, RxSymbolErrors);
4708c2ecf20Sopenharmony_ci	RMON_UPDATE(mac, RxInRangeLengthErrors, RxInRangeLengthErrors);
4718c2ecf20Sopenharmony_ci	RMON_UPDATE(mac, RxFramesTooLongErrors , RxFrameTooLongErrors);
4728c2ecf20Sopenharmony_ci	RMON_UPDATE(mac, RxJabbers, RxJabberErrors);
4738c2ecf20Sopenharmony_ci	RMON_UPDATE(mac, RxFragments, RxRuntErrors);
4748c2ecf20Sopenharmony_ci	RMON_UPDATE(mac, RxUndersizedFrames, RxRuntErrors);
4758c2ecf20Sopenharmony_ci	RMON_UPDATE(mac, RxJumboFramesReceivedOK, RxJumboFramesOK);
4768c2ecf20Sopenharmony_ci	RMON_UPDATE(mac, RxJumboOctetsReceivedOK, RxJumboOctetsOK);
4778c2ecf20Sopenharmony_ci
4788c2ecf20Sopenharmony_ci	/* Tx stats */
4798c2ecf20Sopenharmony_ci	RMON_UPDATE(mac, TxOctetsTransmittedOK, TxOctetsOK);
4808c2ecf20Sopenharmony_ci	RMON_UPDATE(mac, TxFramesLostDueToInternalMACTransmissionError,
4818c2ecf20Sopenharmony_ci				TxInternalMACXmitError);
4828c2ecf20Sopenharmony_ci	RMON_UPDATE(mac, TxTransmitSystemError, TxFCSErrors);
4838c2ecf20Sopenharmony_ci	RMON_UPDATE(mac, TxUnicastFramesTransmittedOK, TxUnicastFramesOK);
4848c2ecf20Sopenharmony_ci	RMON_UPDATE(mac, TxMulticastFramesTransmittedOK, TxMulticastFramesOK);
4858c2ecf20Sopenharmony_ci	RMON_UPDATE(mac, TxBroadcastFramesTransmittedOK, TxBroadcastFramesOK);
4868c2ecf20Sopenharmony_ci	RMON_UPDATE(mac, TxPAUSEMACCtrlFramesTransmitted, TxPauseFrames);
4878c2ecf20Sopenharmony_ci	RMON_UPDATE(mac, TxJumboFramesReceivedOK, TxJumboFramesOK);
4888c2ecf20Sopenharmony_ci	RMON_UPDATE(mac, TxJumboOctetsReceivedOK, TxJumboOctetsOK);
4898c2ecf20Sopenharmony_ci
4908c2ecf20Sopenharmony_ci	return &mac->stats;
4918c2ecf20Sopenharmony_ci}
4928c2ecf20Sopenharmony_ci
4938c2ecf20Sopenharmony_cistatic int pm3393_macaddress_get(struct cmac *cmac, u8 mac_addr[6])
4948c2ecf20Sopenharmony_ci{
4958c2ecf20Sopenharmony_ci	memcpy(mac_addr, cmac->instance->mac_addr, ETH_ALEN);
4968c2ecf20Sopenharmony_ci	return 0;
4978c2ecf20Sopenharmony_ci}
4988c2ecf20Sopenharmony_ci
4998c2ecf20Sopenharmony_cistatic int pm3393_macaddress_set(struct cmac *cmac, u8 ma[6])
5008c2ecf20Sopenharmony_ci{
5018c2ecf20Sopenharmony_ci	u32 val, lo, mid, hi, enabled = cmac->instance->enabled;
5028c2ecf20Sopenharmony_ci
5038c2ecf20Sopenharmony_ci	/*
5048c2ecf20Sopenharmony_ci	 * MAC addr: 00:07:43:00:13:09
5058c2ecf20Sopenharmony_ci	 *
5068c2ecf20Sopenharmony_ci	 * ma[5] = 0x09
5078c2ecf20Sopenharmony_ci	 * ma[4] = 0x13
5088c2ecf20Sopenharmony_ci	 * ma[3] = 0x00
5098c2ecf20Sopenharmony_ci	 * ma[2] = 0x43
5108c2ecf20Sopenharmony_ci	 * ma[1] = 0x07
5118c2ecf20Sopenharmony_ci	 * ma[0] = 0x00
5128c2ecf20Sopenharmony_ci	 *
5138c2ecf20Sopenharmony_ci	 * The PM3393 requires byte swapping and reverse order entry
5148c2ecf20Sopenharmony_ci	 * when programming MAC addresses:
5158c2ecf20Sopenharmony_ci	 *
5168c2ecf20Sopenharmony_ci	 * low_bits[15:0]    = ma[1]:ma[0]
5178c2ecf20Sopenharmony_ci	 * mid_bits[31:16]   = ma[3]:ma[2]
5188c2ecf20Sopenharmony_ci	 * high_bits[47:32]  = ma[5]:ma[4]
5198c2ecf20Sopenharmony_ci	 */
5208c2ecf20Sopenharmony_ci
5218c2ecf20Sopenharmony_ci	/* Store local copy */
5228c2ecf20Sopenharmony_ci	memcpy(cmac->instance->mac_addr, ma, ETH_ALEN);
5238c2ecf20Sopenharmony_ci
5248c2ecf20Sopenharmony_ci	lo  = ((u32) ma[1] << 8) | (u32) ma[0];
5258c2ecf20Sopenharmony_ci	mid = ((u32) ma[3] << 8) | (u32) ma[2];
5268c2ecf20Sopenharmony_ci	hi  = ((u32) ma[5] << 8) | (u32) ma[4];
5278c2ecf20Sopenharmony_ci
5288c2ecf20Sopenharmony_ci	/* Disable Rx/Tx MAC before configuring it. */
5298c2ecf20Sopenharmony_ci	if (enabled)
5308c2ecf20Sopenharmony_ci		pm3393_disable(cmac, MAC_DIRECTION_RX | MAC_DIRECTION_TX);
5318c2ecf20Sopenharmony_ci
5328c2ecf20Sopenharmony_ci	/* Set RXXG Station Address */
5338c2ecf20Sopenharmony_ci	pmwrite(cmac, SUNI1x10GEXP_REG_RXXG_SA_15_0, lo);
5348c2ecf20Sopenharmony_ci	pmwrite(cmac, SUNI1x10GEXP_REG_RXXG_SA_31_16, mid);
5358c2ecf20Sopenharmony_ci	pmwrite(cmac, SUNI1x10GEXP_REG_RXXG_SA_47_32, hi);
5368c2ecf20Sopenharmony_ci
5378c2ecf20Sopenharmony_ci	/* Set TXXG Station Address */
5388c2ecf20Sopenharmony_ci	pmwrite(cmac, SUNI1x10GEXP_REG_TXXG_SA_15_0, lo);
5398c2ecf20Sopenharmony_ci	pmwrite(cmac, SUNI1x10GEXP_REG_TXXG_SA_31_16, mid);
5408c2ecf20Sopenharmony_ci	pmwrite(cmac, SUNI1x10GEXP_REG_TXXG_SA_47_32, hi);
5418c2ecf20Sopenharmony_ci
5428c2ecf20Sopenharmony_ci	/* Setup Exact Match Filter 1 with our MAC address
5438c2ecf20Sopenharmony_ci	 *
5448c2ecf20Sopenharmony_ci	 * Must disable exact match filter before configuring it.
5458c2ecf20Sopenharmony_ci	 */
5468c2ecf20Sopenharmony_ci	pmread(cmac, SUNI1x10GEXP_REG_RXXG_ADDRESS_FILTER_CONTROL_0, &val);
5478c2ecf20Sopenharmony_ci	val &= 0xff0f;
5488c2ecf20Sopenharmony_ci	pmwrite(cmac, SUNI1x10GEXP_REG_RXXG_ADDRESS_FILTER_CONTROL_0, val);
5498c2ecf20Sopenharmony_ci
5508c2ecf20Sopenharmony_ci	pmwrite(cmac, SUNI1x10GEXP_REG_RXXG_EXACT_MATCH_ADDR_1_LOW, lo);
5518c2ecf20Sopenharmony_ci	pmwrite(cmac, SUNI1x10GEXP_REG_RXXG_EXACT_MATCH_ADDR_1_MID, mid);
5528c2ecf20Sopenharmony_ci	pmwrite(cmac, SUNI1x10GEXP_REG_RXXG_EXACT_MATCH_ADDR_1_HIGH, hi);
5538c2ecf20Sopenharmony_ci
5548c2ecf20Sopenharmony_ci	val |= 0x0090;
5558c2ecf20Sopenharmony_ci	pmwrite(cmac, SUNI1x10GEXP_REG_RXXG_ADDRESS_FILTER_CONTROL_0, val);
5568c2ecf20Sopenharmony_ci
5578c2ecf20Sopenharmony_ci	if (enabled)
5588c2ecf20Sopenharmony_ci		pm3393_enable(cmac, enabled);
5598c2ecf20Sopenharmony_ci	return 0;
5608c2ecf20Sopenharmony_ci}
5618c2ecf20Sopenharmony_ci
5628c2ecf20Sopenharmony_cistatic void pm3393_destroy(struct cmac *cmac)
5638c2ecf20Sopenharmony_ci{
5648c2ecf20Sopenharmony_ci	kfree(cmac);
5658c2ecf20Sopenharmony_ci}
5668c2ecf20Sopenharmony_ci
5678c2ecf20Sopenharmony_cistatic const struct cmac_ops pm3393_ops = {
5688c2ecf20Sopenharmony_ci	.destroy                 = pm3393_destroy,
5698c2ecf20Sopenharmony_ci	.reset                   = pm3393_reset,
5708c2ecf20Sopenharmony_ci	.interrupt_enable        = pm3393_interrupt_enable,
5718c2ecf20Sopenharmony_ci	.interrupt_disable       = pm3393_interrupt_disable,
5728c2ecf20Sopenharmony_ci	.interrupt_clear         = pm3393_interrupt_clear,
5738c2ecf20Sopenharmony_ci	.interrupt_handler       = pm3393_interrupt_handler,
5748c2ecf20Sopenharmony_ci	.enable                  = pm3393_enable_port,
5758c2ecf20Sopenharmony_ci	.disable                 = pm3393_disable,
5768c2ecf20Sopenharmony_ci	.loopback_enable         = pm3393_loopback_enable,
5778c2ecf20Sopenharmony_ci	.loopback_disable        = pm3393_loopback_disable,
5788c2ecf20Sopenharmony_ci	.set_mtu                 = pm3393_set_mtu,
5798c2ecf20Sopenharmony_ci	.set_rx_mode             = pm3393_set_rx_mode,
5808c2ecf20Sopenharmony_ci	.get_speed_duplex_fc     = pm3393_get_speed_duplex_fc,
5818c2ecf20Sopenharmony_ci	.set_speed_duplex_fc     = pm3393_set_speed_duplex_fc,
5828c2ecf20Sopenharmony_ci	.statistics_update       = pm3393_update_statistics,
5838c2ecf20Sopenharmony_ci	.macaddress_get          = pm3393_macaddress_get,
5848c2ecf20Sopenharmony_ci	.macaddress_set          = pm3393_macaddress_set
5858c2ecf20Sopenharmony_ci};
5868c2ecf20Sopenharmony_ci
5878c2ecf20Sopenharmony_cistatic struct cmac *pm3393_mac_create(adapter_t *adapter, int index)
5888c2ecf20Sopenharmony_ci{
5898c2ecf20Sopenharmony_ci	struct cmac *cmac;
5908c2ecf20Sopenharmony_ci
5918c2ecf20Sopenharmony_ci	cmac = kzalloc(sizeof(*cmac) + sizeof(cmac_instance), GFP_KERNEL);
5928c2ecf20Sopenharmony_ci	if (!cmac)
5938c2ecf20Sopenharmony_ci		return NULL;
5948c2ecf20Sopenharmony_ci
5958c2ecf20Sopenharmony_ci	cmac->ops = &pm3393_ops;
5968c2ecf20Sopenharmony_ci	cmac->instance = (cmac_instance *) (cmac + 1);
5978c2ecf20Sopenharmony_ci	cmac->adapter = adapter;
5988c2ecf20Sopenharmony_ci	cmac->instance->fc = PAUSE_TX | PAUSE_RX;
5998c2ecf20Sopenharmony_ci
6008c2ecf20Sopenharmony_ci	t1_tpi_write(adapter, OFFSET(0x0001), 0x00008000);
6018c2ecf20Sopenharmony_ci	t1_tpi_write(adapter, OFFSET(0x0001), 0x00000000);
6028c2ecf20Sopenharmony_ci	t1_tpi_write(adapter, OFFSET(0x2308), 0x00009800);
6038c2ecf20Sopenharmony_ci	t1_tpi_write(adapter, OFFSET(0x2305), 0x00001001);   /* PL4IO Enable */
6048c2ecf20Sopenharmony_ci	t1_tpi_write(adapter, OFFSET(0x2320), 0x00008800);
6058c2ecf20Sopenharmony_ci	t1_tpi_write(adapter, OFFSET(0x2321), 0x00008800);
6068c2ecf20Sopenharmony_ci	t1_tpi_write(adapter, OFFSET(0x2322), 0x00008800);
6078c2ecf20Sopenharmony_ci	t1_tpi_write(adapter, OFFSET(0x2323), 0x00008800);
6088c2ecf20Sopenharmony_ci	t1_tpi_write(adapter, OFFSET(0x2324), 0x00008800);
6098c2ecf20Sopenharmony_ci	t1_tpi_write(adapter, OFFSET(0x2325), 0x00008800);
6108c2ecf20Sopenharmony_ci	t1_tpi_write(adapter, OFFSET(0x2326), 0x00008800);
6118c2ecf20Sopenharmony_ci	t1_tpi_write(adapter, OFFSET(0x2327), 0x00008800);
6128c2ecf20Sopenharmony_ci	t1_tpi_write(adapter, OFFSET(0x2328), 0x00008800);
6138c2ecf20Sopenharmony_ci	t1_tpi_write(adapter, OFFSET(0x2329), 0x00008800);
6148c2ecf20Sopenharmony_ci	t1_tpi_write(adapter, OFFSET(0x232a), 0x00008800);
6158c2ecf20Sopenharmony_ci	t1_tpi_write(adapter, OFFSET(0x232b), 0x00008800);
6168c2ecf20Sopenharmony_ci	t1_tpi_write(adapter, OFFSET(0x232c), 0x00008800);
6178c2ecf20Sopenharmony_ci	t1_tpi_write(adapter, OFFSET(0x232d), 0x00008800);
6188c2ecf20Sopenharmony_ci	t1_tpi_write(adapter, OFFSET(0x232e), 0x00008800);
6198c2ecf20Sopenharmony_ci	t1_tpi_write(adapter, OFFSET(0x232f), 0x00008800);
6208c2ecf20Sopenharmony_ci	t1_tpi_write(adapter, OFFSET(0x230d), 0x00009c00);
6218c2ecf20Sopenharmony_ci	t1_tpi_write(adapter, OFFSET(0x2304), 0x00000202);	/* PL4IO Calendar Repetitions */
6228c2ecf20Sopenharmony_ci
6238c2ecf20Sopenharmony_ci	t1_tpi_write(adapter, OFFSET(0x3200), 0x00008080);	/* EFLX Enable */
6248c2ecf20Sopenharmony_ci	t1_tpi_write(adapter, OFFSET(0x3210), 0x00000000);	/* EFLX Channel Deprovision */
6258c2ecf20Sopenharmony_ci	t1_tpi_write(adapter, OFFSET(0x3203), 0x00000000);	/* EFLX Low Limit */
6268c2ecf20Sopenharmony_ci	t1_tpi_write(adapter, OFFSET(0x3204), 0x00000040);	/* EFLX High Limit */
6278c2ecf20Sopenharmony_ci	t1_tpi_write(adapter, OFFSET(0x3205), 0x000002cc);	/* EFLX Almost Full */
6288c2ecf20Sopenharmony_ci	t1_tpi_write(adapter, OFFSET(0x3206), 0x00000199);	/* EFLX Almost Empty */
6298c2ecf20Sopenharmony_ci	t1_tpi_write(adapter, OFFSET(0x3207), 0x00000240);	/* EFLX Cut Through Threshold */
6308c2ecf20Sopenharmony_ci	t1_tpi_write(adapter, OFFSET(0x3202), 0x00000000);	/* EFLX Indirect Register Update */
6318c2ecf20Sopenharmony_ci	t1_tpi_write(adapter, OFFSET(0x3210), 0x00000001);	/* EFLX Channel Provision */
6328c2ecf20Sopenharmony_ci	t1_tpi_write(adapter, OFFSET(0x3208), 0x0000ffff);	/* EFLX Undocumented */
6338c2ecf20Sopenharmony_ci	t1_tpi_write(adapter, OFFSET(0x320a), 0x0000ffff);	/* EFLX Undocumented */
6348c2ecf20Sopenharmony_ci	t1_tpi_write(adapter, OFFSET(0x320c), 0x0000ffff);	/* EFLX enable overflow interrupt The other bit are undocumented */
6358c2ecf20Sopenharmony_ci	t1_tpi_write(adapter, OFFSET(0x320e), 0x0000ffff);	/* EFLX Undocumented */
6368c2ecf20Sopenharmony_ci
6378c2ecf20Sopenharmony_ci	t1_tpi_write(adapter, OFFSET(0x2200), 0x0000c000);	/* IFLX Configuration - enable */
6388c2ecf20Sopenharmony_ci	t1_tpi_write(adapter, OFFSET(0x2201), 0x00000000);	/* IFLX Channel Deprovision */
6398c2ecf20Sopenharmony_ci	t1_tpi_write(adapter, OFFSET(0x220e), 0x00000000);	/* IFLX Low Limit */
6408c2ecf20Sopenharmony_ci	t1_tpi_write(adapter, OFFSET(0x220f), 0x00000100);	/* IFLX High Limit */
6418c2ecf20Sopenharmony_ci	t1_tpi_write(adapter, OFFSET(0x2210), 0x00000c00);	/* IFLX Almost Full Limit */
6428c2ecf20Sopenharmony_ci	t1_tpi_write(adapter, OFFSET(0x2211), 0x00000599);	/* IFLX Almost Empty Limit */
6438c2ecf20Sopenharmony_ci	t1_tpi_write(adapter, OFFSET(0x220d), 0x00000000);	/* IFLX Indirect Register Update */
6448c2ecf20Sopenharmony_ci	t1_tpi_write(adapter, OFFSET(0x2201), 0x00000001);	/* IFLX Channel Provision */
6458c2ecf20Sopenharmony_ci	t1_tpi_write(adapter, OFFSET(0x2203), 0x0000ffff);	/* IFLX Undocumented */
6468c2ecf20Sopenharmony_ci	t1_tpi_write(adapter, OFFSET(0x2205), 0x0000ffff);	/* IFLX Undocumented */
6478c2ecf20Sopenharmony_ci	t1_tpi_write(adapter, OFFSET(0x2209), 0x0000ffff);	/* IFLX Enable overflow interrupt.  The other bit are undocumented */
6488c2ecf20Sopenharmony_ci
6498c2ecf20Sopenharmony_ci	t1_tpi_write(adapter, OFFSET(0x2241), 0xfffffffe);	/* PL4MOS Undocumented */
6508c2ecf20Sopenharmony_ci	t1_tpi_write(adapter, OFFSET(0x2242), 0x0000ffff);	/* PL4MOS Undocumented */
6518c2ecf20Sopenharmony_ci	t1_tpi_write(adapter, OFFSET(0x2243), 0x00000008);	/* PL4MOS Starving Burst Size */
6528c2ecf20Sopenharmony_ci	t1_tpi_write(adapter, OFFSET(0x2244), 0x00000008);	/* PL4MOS Hungry Burst Size */
6538c2ecf20Sopenharmony_ci	t1_tpi_write(adapter, OFFSET(0x2245), 0x00000008);	/* PL4MOS Transfer Size */
6548c2ecf20Sopenharmony_ci	t1_tpi_write(adapter, OFFSET(0x2240), 0x00000005);	/* PL4MOS Disable */
6558c2ecf20Sopenharmony_ci
6568c2ecf20Sopenharmony_ci	t1_tpi_write(adapter, OFFSET(0x2280), 0x00002103);	/* PL4ODP Training Repeat and SOP rule */
6578c2ecf20Sopenharmony_ci	t1_tpi_write(adapter, OFFSET(0x2284), 0x00000000);	/* PL4ODP MAX_T setting */
6588c2ecf20Sopenharmony_ci
6598c2ecf20Sopenharmony_ci	t1_tpi_write(adapter, OFFSET(0x3280), 0x00000087);	/* PL4IDU Enable data forward, port state machine. Set ALLOW_NON_ZERO_OLB */
6608c2ecf20Sopenharmony_ci	t1_tpi_write(adapter, OFFSET(0x3282), 0x0000001f);	/* PL4IDU Enable Dip4 check error interrupts */
6618c2ecf20Sopenharmony_ci
6628c2ecf20Sopenharmony_ci	t1_tpi_write(adapter, OFFSET(0x3040), 0x0c32);	/* # TXXG Config */
6638c2ecf20Sopenharmony_ci	/* For T1 use timer based Mac flow control. */
6648c2ecf20Sopenharmony_ci	t1_tpi_write(adapter, OFFSET(0x304d), 0x8000);
6658c2ecf20Sopenharmony_ci	t1_tpi_write(adapter, OFFSET(0x2040), 0x059c);	/* # RXXG Config */
6668c2ecf20Sopenharmony_ci	t1_tpi_write(adapter, OFFSET(0x2049), 0x0001);	/* # RXXG Cut Through */
6678c2ecf20Sopenharmony_ci	t1_tpi_write(adapter, OFFSET(0x2070), 0x0000);	/* # Disable promiscuous mode */
6688c2ecf20Sopenharmony_ci
6698c2ecf20Sopenharmony_ci	/* Setup Exact Match Filter 0 to allow broadcast packets.
6708c2ecf20Sopenharmony_ci	 */
6718c2ecf20Sopenharmony_ci	t1_tpi_write(adapter, OFFSET(0x206e), 0x0000);	/* # Disable Match Enable bit */
6728c2ecf20Sopenharmony_ci	t1_tpi_write(adapter, OFFSET(0x204a), 0xffff);	/* # low addr */
6738c2ecf20Sopenharmony_ci	t1_tpi_write(adapter, OFFSET(0x204b), 0xffff);	/* # mid addr */
6748c2ecf20Sopenharmony_ci	t1_tpi_write(adapter, OFFSET(0x204c), 0xffff);	/* # high addr */
6758c2ecf20Sopenharmony_ci	t1_tpi_write(adapter, OFFSET(0x206e), 0x0009);	/* # Enable Match Enable bit */
6768c2ecf20Sopenharmony_ci
6778c2ecf20Sopenharmony_ci	t1_tpi_write(adapter, OFFSET(0x0003), 0x0000);	/* # NO SOP/ PAD_EN setup */
6788c2ecf20Sopenharmony_ci	t1_tpi_write(adapter, OFFSET(0x0100), 0x0ff0);	/* # RXEQB disabled */
6798c2ecf20Sopenharmony_ci	t1_tpi_write(adapter, OFFSET(0x0101), 0x0f0f);	/* # No Preemphasis */
6808c2ecf20Sopenharmony_ci
6818c2ecf20Sopenharmony_ci	return cmac;
6828c2ecf20Sopenharmony_ci}
6838c2ecf20Sopenharmony_ci
6848c2ecf20Sopenharmony_cistatic int pm3393_mac_reset(adapter_t * adapter)
6858c2ecf20Sopenharmony_ci{
6868c2ecf20Sopenharmony_ci	u32 val;
6878c2ecf20Sopenharmony_ci	u32 x;
6888c2ecf20Sopenharmony_ci	u32 is_pl4_reset_finished;
6898c2ecf20Sopenharmony_ci	u32 is_pl4_outof_lock;
6908c2ecf20Sopenharmony_ci	u32 is_xaui_mabc_pll_locked;
6918c2ecf20Sopenharmony_ci	u32 successful_reset;
6928c2ecf20Sopenharmony_ci	int i;
6938c2ecf20Sopenharmony_ci
6948c2ecf20Sopenharmony_ci	/* The following steps are required to properly reset
6958c2ecf20Sopenharmony_ci	 * the PM3393. This information is provided in the
6968c2ecf20Sopenharmony_ci	 * PM3393 datasheet (Issue 2: November 2002)
6978c2ecf20Sopenharmony_ci	 * section 13.1 -- Device Reset.
6988c2ecf20Sopenharmony_ci	 *
6998c2ecf20Sopenharmony_ci	 * The PM3393 has three types of components that are
7008c2ecf20Sopenharmony_ci	 * individually reset:
7018c2ecf20Sopenharmony_ci	 *
7028c2ecf20Sopenharmony_ci	 * DRESETB      - Digital circuitry
7038c2ecf20Sopenharmony_ci	 * PL4_ARESETB  - PL4 analog circuitry
7048c2ecf20Sopenharmony_ci	 * XAUI_ARESETB - XAUI bus analog circuitry
7058c2ecf20Sopenharmony_ci	 *
7068c2ecf20Sopenharmony_ci	 * Steps to reset PM3393 using RSTB pin:
7078c2ecf20Sopenharmony_ci	 *
7088c2ecf20Sopenharmony_ci	 * 1. Assert RSTB pin low ( write 0 )
7098c2ecf20Sopenharmony_ci	 * 2. Wait at least 1ms to initiate a complete initialization of device.
7108c2ecf20Sopenharmony_ci	 * 3. Wait until all external clocks and REFSEL are stable.
7118c2ecf20Sopenharmony_ci	 * 4. Wait minimum of 1ms. (after external clocks and REFEL are stable)
7128c2ecf20Sopenharmony_ci	 * 5. De-assert RSTB ( write 1 )
7138c2ecf20Sopenharmony_ci	 * 6. Wait until internal timers to expires after ~14ms.
7148c2ecf20Sopenharmony_ci	 *    - Allows analog clock synthesizer(PL4CSU) to stabilize to
7158c2ecf20Sopenharmony_ci	 *      selected reference frequency before allowing the digital
7168c2ecf20Sopenharmony_ci	 *      portion of the device to operate.
7178c2ecf20Sopenharmony_ci	 * 7. Wait at least 200us for XAUI interface to stabilize.
7188c2ecf20Sopenharmony_ci	 * 8. Verify the PM3393 came out of reset successfully.
7198c2ecf20Sopenharmony_ci	 *    Set successful reset flag if everything worked else try again
7208c2ecf20Sopenharmony_ci	 *    a few more times.
7218c2ecf20Sopenharmony_ci	 */
7228c2ecf20Sopenharmony_ci
7238c2ecf20Sopenharmony_ci	successful_reset = 0;
7248c2ecf20Sopenharmony_ci	for (i = 0; i < 3 && !successful_reset; i++) {
7258c2ecf20Sopenharmony_ci		/* 1 */
7268c2ecf20Sopenharmony_ci		t1_tpi_read(adapter, A_ELMER0_GPO, &val);
7278c2ecf20Sopenharmony_ci		val &= ~1;
7288c2ecf20Sopenharmony_ci		t1_tpi_write(adapter, A_ELMER0_GPO, val);
7298c2ecf20Sopenharmony_ci
7308c2ecf20Sopenharmony_ci		/* 2 */
7318c2ecf20Sopenharmony_ci		msleep(1);
7328c2ecf20Sopenharmony_ci
7338c2ecf20Sopenharmony_ci		/* 3 */
7348c2ecf20Sopenharmony_ci		msleep(1);
7358c2ecf20Sopenharmony_ci
7368c2ecf20Sopenharmony_ci		/* 4 */
7378c2ecf20Sopenharmony_ci		msleep(2 /*1 extra ms for safety */ );
7388c2ecf20Sopenharmony_ci
7398c2ecf20Sopenharmony_ci		/* 5 */
7408c2ecf20Sopenharmony_ci		val |= 1;
7418c2ecf20Sopenharmony_ci		t1_tpi_write(adapter, A_ELMER0_GPO, val);
7428c2ecf20Sopenharmony_ci
7438c2ecf20Sopenharmony_ci		/* 6 */
7448c2ecf20Sopenharmony_ci		msleep(15 /*1 extra ms for safety */ );
7458c2ecf20Sopenharmony_ci
7468c2ecf20Sopenharmony_ci		/* 7 */
7478c2ecf20Sopenharmony_ci		msleep(1);
7488c2ecf20Sopenharmony_ci
7498c2ecf20Sopenharmony_ci		/* 8 */
7508c2ecf20Sopenharmony_ci
7518c2ecf20Sopenharmony_ci		/* Has PL4 analog block come out of reset correctly? */
7528c2ecf20Sopenharmony_ci		t1_tpi_read(adapter, OFFSET(SUNI1x10GEXP_REG_DEVICE_STATUS), &val);
7538c2ecf20Sopenharmony_ci		is_pl4_reset_finished = (val & SUNI1x10GEXP_BITMSK_TOP_EXPIRED);
7548c2ecf20Sopenharmony_ci
7558c2ecf20Sopenharmony_ci		/* TBD XXX SUNI1x10GEXP_BITMSK_TOP_PL4_IS_DOOL gets locked later in the init sequence
7568c2ecf20Sopenharmony_ci		 *         figure out why? */
7578c2ecf20Sopenharmony_ci
7588c2ecf20Sopenharmony_ci		/* Have all PL4 block clocks locked? */
7598c2ecf20Sopenharmony_ci		x = (SUNI1x10GEXP_BITMSK_TOP_PL4_ID_DOOL
7608c2ecf20Sopenharmony_ci		     /*| SUNI1x10GEXP_BITMSK_TOP_PL4_IS_DOOL */  |
7618c2ecf20Sopenharmony_ci		     SUNI1x10GEXP_BITMSK_TOP_PL4_ID_ROOL |
7628c2ecf20Sopenharmony_ci		     SUNI1x10GEXP_BITMSK_TOP_PL4_IS_ROOL |
7638c2ecf20Sopenharmony_ci		     SUNI1x10GEXP_BITMSK_TOP_PL4_OUT_ROOL);
7648c2ecf20Sopenharmony_ci		is_pl4_outof_lock = (val & x);
7658c2ecf20Sopenharmony_ci
7668c2ecf20Sopenharmony_ci		/* ??? If this fails, might be able to software reset the XAUI part
7678c2ecf20Sopenharmony_ci		 *     and try to recover... thus saving us from doing another HW reset */
7688c2ecf20Sopenharmony_ci		/* Has the XAUI MABC PLL circuitry stablized? */
7698c2ecf20Sopenharmony_ci		is_xaui_mabc_pll_locked =
7708c2ecf20Sopenharmony_ci		    (val & SUNI1x10GEXP_BITMSK_TOP_SXRA_EXPIRED);
7718c2ecf20Sopenharmony_ci
7728c2ecf20Sopenharmony_ci		successful_reset = (is_pl4_reset_finished && !is_pl4_outof_lock
7738c2ecf20Sopenharmony_ci				    && is_xaui_mabc_pll_locked);
7748c2ecf20Sopenharmony_ci
7758c2ecf20Sopenharmony_ci		if (netif_msg_hw(adapter))
7768c2ecf20Sopenharmony_ci			dev_dbg(&adapter->pdev->dev,
7778c2ecf20Sopenharmony_ci				"PM3393 HW reset %d: pl4_reset 0x%x, val 0x%x, "
7788c2ecf20Sopenharmony_ci				"is_pl4_outof_lock 0x%x, xaui_locked 0x%x\n",
7798c2ecf20Sopenharmony_ci				i, is_pl4_reset_finished, val,
7808c2ecf20Sopenharmony_ci				is_pl4_outof_lock, is_xaui_mabc_pll_locked);
7818c2ecf20Sopenharmony_ci	}
7828c2ecf20Sopenharmony_ci	return successful_reset ? 0 : 1;
7838c2ecf20Sopenharmony_ci}
7848c2ecf20Sopenharmony_ci
7858c2ecf20Sopenharmony_ciconst struct gmac t1_pm3393_ops = {
7868c2ecf20Sopenharmony_ci	.stats_update_period = STATS_TICK_SECS,
7878c2ecf20Sopenharmony_ci	.create              = pm3393_mac_create,
7888c2ecf20Sopenharmony_ci	.reset               = pm3393_mac_reset,
7898c2ecf20Sopenharmony_ci};
790