xref: /openbmc/linux/drivers/net/ethernet/chelsio/cxgb/espi.c (revision 4f2c0a4acffbec01079c28f839422e64ddeff004)
1*a6013785SThomas Gleixner // SPDX-License-Identifier: GPL-2.0-only
2f7917c00SJeff Kirsher /*****************************************************************************
3f7917c00SJeff Kirsher  *                                                                           *
4f7917c00SJeff Kirsher  * File: espi.c                                                              *
5f7917c00SJeff Kirsher  * $Revision: 1.14 $                                                         *
6f7917c00SJeff Kirsher  * $Date: 2005/05/14 00:59:32 $                                              *
7f7917c00SJeff Kirsher  * Description:                                                              *
8f7917c00SJeff Kirsher  *  Ethernet SPI functionality.                                              *
9f7917c00SJeff Kirsher  *  part of the Chelsio 10Gb Ethernet Driver.                                *
10f7917c00SJeff Kirsher  *                                                                           *
11f7917c00SJeff Kirsher  *                                                                           *
12f7917c00SJeff Kirsher  * http://www.chelsio.com                                                    *
13f7917c00SJeff Kirsher  *                                                                           *
14f7917c00SJeff Kirsher  * Copyright (c) 2003 - 2005 Chelsio Communications, Inc.                    *
15f7917c00SJeff Kirsher  * All rights reserved.                                                      *
16f7917c00SJeff Kirsher  *                                                                           *
17f7917c00SJeff Kirsher  * Maintainers: maintainers@chelsio.com                                      *
18f7917c00SJeff Kirsher  *                                                                           *
19f7917c00SJeff Kirsher  * Authors: Dimitrios Michailidis   <dm@chelsio.com>                         *
20f7917c00SJeff Kirsher  *          Tina Yang               <tainay@chelsio.com>                     *
21f7917c00SJeff Kirsher  *          Felix Marti             <felix@chelsio.com>                      *
22f7917c00SJeff Kirsher  *          Scott Bardone           <sbardone@chelsio.com>                   *
23f7917c00SJeff Kirsher  *          Kurt Ottaway            <kottaway@chelsio.com>                   *
24f7917c00SJeff Kirsher  *          Frank DiMambro          <frank@chelsio.com>                      *
25f7917c00SJeff Kirsher  *                                                                           *
26f7917c00SJeff Kirsher  * History:                                                                  *
27f7917c00SJeff Kirsher  *                                                                           *
28f7917c00SJeff Kirsher  ****************************************************************************/
29f7917c00SJeff Kirsher 
30f7917c00SJeff Kirsher #include "common.h"
31f7917c00SJeff Kirsher #include "regs.h"
32f7917c00SJeff Kirsher #include "espi.h"
33f7917c00SJeff Kirsher 
34f7917c00SJeff Kirsher struct peespi {
35f7917c00SJeff Kirsher 	adapter_t *adapter;
36f7917c00SJeff Kirsher 	struct espi_intr_counts intr_cnt;
37f7917c00SJeff Kirsher 	u32 misc_ctrl;
38f7917c00SJeff Kirsher 	spinlock_t lock;
39f7917c00SJeff Kirsher };
40f7917c00SJeff Kirsher 
41f7917c00SJeff Kirsher #define ESPI_INTR_MASK (F_DIP4ERR | F_RXDROP | F_TXDROP | F_RXOVERFLOW | \
42f7917c00SJeff Kirsher 			F_RAMPARITYERR | F_DIP2PARITYERR)
43f7917c00SJeff Kirsher #define MON_MASK  (V_MONITORED_PORT_NUM(3) | F_MONITORED_DIRECTION \
44f7917c00SJeff Kirsher 		   | F_MONITORED_INTERFACE)
45f7917c00SJeff Kirsher 
46f7917c00SJeff Kirsher #define TRICN_CNFG 14
47f7917c00SJeff Kirsher #define TRICN_CMD_READ  0x11
48f7917c00SJeff Kirsher #define TRICN_CMD_WRITE 0x21
49f7917c00SJeff Kirsher #define TRICN_CMD_ATTEMPTS 10
50f7917c00SJeff Kirsher 
tricn_write(adapter_t * adapter,int bundle_addr,int module_addr,int ch_addr,int reg_offset,u32 wr_data)51f7917c00SJeff Kirsher static int tricn_write(adapter_t *adapter, int bundle_addr, int module_addr,
52f7917c00SJeff Kirsher 		       int ch_addr, int reg_offset, u32 wr_data)
53f7917c00SJeff Kirsher {
54f7917c00SJeff Kirsher 	int busy, attempts = TRICN_CMD_ATTEMPTS;
55f7917c00SJeff Kirsher 
56f7917c00SJeff Kirsher 	writel(V_WRITE_DATA(wr_data) |
57f7917c00SJeff Kirsher 	       V_REGISTER_OFFSET(reg_offset) |
58f7917c00SJeff Kirsher 	       V_CHANNEL_ADDR(ch_addr) | V_MODULE_ADDR(module_addr) |
59f7917c00SJeff Kirsher 	       V_BUNDLE_ADDR(bundle_addr) |
60f7917c00SJeff Kirsher 	       V_SPI4_COMMAND(TRICN_CMD_WRITE),
61f7917c00SJeff Kirsher 	       adapter->regs + A_ESPI_CMD_ADDR);
62f7917c00SJeff Kirsher 	writel(0, adapter->regs + A_ESPI_GOSTAT);
63f7917c00SJeff Kirsher 
64f7917c00SJeff Kirsher 	do {
65f7917c00SJeff Kirsher 		busy = readl(adapter->regs + A_ESPI_GOSTAT) & F_ESPI_CMD_BUSY;
66f7917c00SJeff Kirsher 	} while (busy && --attempts);
67f7917c00SJeff Kirsher 
68f7917c00SJeff Kirsher 	if (busy)
69f7917c00SJeff Kirsher 		pr_err("%s: TRICN write timed out\n", adapter->name);
70f7917c00SJeff Kirsher 
71f7917c00SJeff Kirsher 	return busy;
72f7917c00SJeff Kirsher }
73f7917c00SJeff Kirsher 
tricn_init(adapter_t * adapter)74f7917c00SJeff Kirsher static int tricn_init(adapter_t *adapter)
75f7917c00SJeff Kirsher {
76f7917c00SJeff Kirsher 	int i, sme = 1;
77f7917c00SJeff Kirsher 
78f7917c00SJeff Kirsher 	if (!(readl(adapter->regs + A_ESPI_RX_RESET)  & F_RX_CLK_STATUS)) {
79f7917c00SJeff Kirsher 		pr_err("%s: ESPI clock not ready\n", adapter->name);
80f7917c00SJeff Kirsher 		return -1;
81f7917c00SJeff Kirsher 	}
82f7917c00SJeff Kirsher 
83f7917c00SJeff Kirsher 	writel(F_ESPI_RX_CORE_RST, adapter->regs + A_ESPI_RX_RESET);
84f7917c00SJeff Kirsher 
85f7917c00SJeff Kirsher 	if (sme) {
86f7917c00SJeff Kirsher 		tricn_write(adapter, 0, 0, 0, TRICN_CNFG, 0x81);
87f7917c00SJeff Kirsher 		tricn_write(adapter, 0, 1, 0, TRICN_CNFG, 0x81);
88f7917c00SJeff Kirsher 		tricn_write(adapter, 0, 2, 0, TRICN_CNFG, 0x81);
89f7917c00SJeff Kirsher 	}
90f7917c00SJeff Kirsher 	for (i = 1; i <= 8; i++)
91f7917c00SJeff Kirsher 		tricn_write(adapter, 0, 0, i, TRICN_CNFG, 0xf1);
92f7917c00SJeff Kirsher 	for (i = 1; i <= 2; i++)
93f7917c00SJeff Kirsher 		tricn_write(adapter, 0, 1, i, TRICN_CNFG, 0xf1);
94f7917c00SJeff Kirsher 	for (i = 1; i <= 3; i++)
95f7917c00SJeff Kirsher 		tricn_write(adapter, 0, 2, i, TRICN_CNFG, 0xe1);
96f7917c00SJeff Kirsher 	tricn_write(adapter, 0, 2, 4, TRICN_CNFG, 0xf1);
97f7917c00SJeff Kirsher 	tricn_write(adapter, 0, 2, 5, TRICN_CNFG, 0xe1);
98f7917c00SJeff Kirsher 	tricn_write(adapter, 0, 2, 6, TRICN_CNFG, 0xf1);
99f7917c00SJeff Kirsher 	tricn_write(adapter, 0, 2, 7, TRICN_CNFG, 0x80);
100f7917c00SJeff Kirsher 	tricn_write(adapter, 0, 2, 8, TRICN_CNFG, 0xf1);
101f7917c00SJeff Kirsher 
102f7917c00SJeff Kirsher 	writel(F_ESPI_RX_CORE_RST | F_ESPI_RX_LNK_RST,
103f7917c00SJeff Kirsher 	       adapter->regs + A_ESPI_RX_RESET);
104f7917c00SJeff Kirsher 
105f7917c00SJeff Kirsher 	return 0;
106f7917c00SJeff Kirsher }
107f7917c00SJeff Kirsher 
t1_espi_intr_enable(struct peespi * espi)108f7917c00SJeff Kirsher void t1_espi_intr_enable(struct peespi *espi)
109f7917c00SJeff Kirsher {
110f7917c00SJeff Kirsher 	u32 enable, pl_intr = readl(espi->adapter->regs + A_PL_ENABLE);
111f7917c00SJeff Kirsher 
112f7917c00SJeff Kirsher 	/*
113f7917c00SJeff Kirsher 	 * Cannot enable ESPI interrupts on T1B because HW asserts the
114f7917c00SJeff Kirsher 	 * interrupt incorrectly, namely the driver gets ESPI interrupts
115f7917c00SJeff Kirsher 	 * but no data is actually dropped (can verify this reading the ESPI
116f7917c00SJeff Kirsher 	 * drop registers).  Also, once the ESPI interrupt is asserted it
117f7917c00SJeff Kirsher 	 * cannot be cleared (HW bug).
118f7917c00SJeff Kirsher 	 */
119f7917c00SJeff Kirsher 	enable = t1_is_T1B(espi->adapter) ? 0 : ESPI_INTR_MASK;
120f7917c00SJeff Kirsher 	writel(enable, espi->adapter->regs + A_ESPI_INTR_ENABLE);
121f7917c00SJeff Kirsher 	writel(pl_intr | F_PL_INTR_ESPI, espi->adapter->regs + A_PL_ENABLE);
122f7917c00SJeff Kirsher }
123f7917c00SJeff Kirsher 
t1_espi_intr_clear(struct peespi * espi)124f7917c00SJeff Kirsher void t1_espi_intr_clear(struct peespi *espi)
125f7917c00SJeff Kirsher {
126f7917c00SJeff Kirsher 	readl(espi->adapter->regs + A_ESPI_DIP2_ERR_COUNT);
127f7917c00SJeff Kirsher 	writel(0xffffffff, espi->adapter->regs + A_ESPI_INTR_STATUS);
128f7917c00SJeff Kirsher 	writel(F_PL_INTR_ESPI, espi->adapter->regs + A_PL_CAUSE);
129f7917c00SJeff Kirsher }
130f7917c00SJeff Kirsher 
t1_espi_intr_disable(struct peespi * espi)131f7917c00SJeff Kirsher void t1_espi_intr_disable(struct peespi *espi)
132f7917c00SJeff Kirsher {
133f7917c00SJeff Kirsher 	u32 pl_intr = readl(espi->adapter->regs + A_PL_ENABLE);
134f7917c00SJeff Kirsher 
135f7917c00SJeff Kirsher 	writel(0, espi->adapter->regs + A_ESPI_INTR_ENABLE);
136f7917c00SJeff Kirsher 	writel(pl_intr & ~F_PL_INTR_ESPI, espi->adapter->regs + A_PL_ENABLE);
137f7917c00SJeff Kirsher }
138f7917c00SJeff Kirsher 
t1_espi_intr_handler(struct peespi * espi)139f7917c00SJeff Kirsher int t1_espi_intr_handler(struct peespi *espi)
140f7917c00SJeff Kirsher {
141f7917c00SJeff Kirsher 	u32 status = readl(espi->adapter->regs + A_ESPI_INTR_STATUS);
142f7917c00SJeff Kirsher 
143f7917c00SJeff Kirsher 	if (status & F_DIP4ERR)
144f7917c00SJeff Kirsher 		espi->intr_cnt.DIP4_err++;
145f7917c00SJeff Kirsher 	if (status & F_RXDROP)
146f7917c00SJeff Kirsher 		espi->intr_cnt.rx_drops++;
147f7917c00SJeff Kirsher 	if (status & F_TXDROP)
148f7917c00SJeff Kirsher 		espi->intr_cnt.tx_drops++;
149f7917c00SJeff Kirsher 	if (status & F_RXOVERFLOW)
150f7917c00SJeff Kirsher 		espi->intr_cnt.rx_ovflw++;
151f7917c00SJeff Kirsher 	if (status & F_RAMPARITYERR)
152f7917c00SJeff Kirsher 		espi->intr_cnt.parity_err++;
153f7917c00SJeff Kirsher 	if (status & F_DIP2PARITYERR) {
154f7917c00SJeff Kirsher 		espi->intr_cnt.DIP2_parity_err++;
155f7917c00SJeff Kirsher 
156f7917c00SJeff Kirsher 		/*
157f7917c00SJeff Kirsher 		 * Must read the error count to clear the interrupt
158f7917c00SJeff Kirsher 		 * that it causes.
159f7917c00SJeff Kirsher 		 */
160f7917c00SJeff Kirsher 		readl(espi->adapter->regs + A_ESPI_DIP2_ERR_COUNT);
161f7917c00SJeff Kirsher 	}
162f7917c00SJeff Kirsher 
163f7917c00SJeff Kirsher 	/*
164f7917c00SJeff Kirsher 	 * For T1B we need to write 1 to clear ESPI interrupts.  For T2+ we
165f7917c00SJeff Kirsher 	 * write the status as is.
166f7917c00SJeff Kirsher 	 */
167f7917c00SJeff Kirsher 	if (status && t1_is_T1B(espi->adapter))
168f7917c00SJeff Kirsher 		status = 1;
169f7917c00SJeff Kirsher 	writel(status, espi->adapter->regs + A_ESPI_INTR_STATUS);
170f7917c00SJeff Kirsher 	return 0;
171f7917c00SJeff Kirsher }
172f7917c00SJeff Kirsher 
t1_espi_get_intr_counts(struct peespi * espi)173f7917c00SJeff Kirsher const struct espi_intr_counts *t1_espi_get_intr_counts(struct peespi *espi)
174f7917c00SJeff Kirsher {
175f7917c00SJeff Kirsher 	return &espi->intr_cnt;
176f7917c00SJeff Kirsher }
177f7917c00SJeff Kirsher 
espi_setup_for_pm3393(adapter_t * adapter)178f7917c00SJeff Kirsher static void espi_setup_for_pm3393(adapter_t *adapter)
179f7917c00SJeff Kirsher {
180f7917c00SJeff Kirsher 	u32 wmark = t1_is_T1B(adapter) ? 0x4000 : 0x3200;
181f7917c00SJeff Kirsher 
182f7917c00SJeff Kirsher 	writel(0x1f4, adapter->regs + A_ESPI_SCH_TOKEN0);
183f7917c00SJeff Kirsher 	writel(0x1f4, adapter->regs + A_ESPI_SCH_TOKEN1);
184f7917c00SJeff Kirsher 	writel(0x1f4, adapter->regs + A_ESPI_SCH_TOKEN2);
185f7917c00SJeff Kirsher 	writel(0x1f4, adapter->regs + A_ESPI_SCH_TOKEN3);
186f7917c00SJeff Kirsher 	writel(0x100, adapter->regs + A_ESPI_RX_FIFO_ALMOST_EMPTY_WATERMARK);
187f7917c00SJeff Kirsher 	writel(wmark, adapter->regs + A_ESPI_RX_FIFO_ALMOST_FULL_WATERMARK);
188f7917c00SJeff Kirsher 	writel(3, adapter->regs + A_ESPI_CALENDAR_LENGTH);
189f7917c00SJeff Kirsher 	writel(0x08000008, adapter->regs + A_ESPI_TRAIN);
190f7917c00SJeff Kirsher 	writel(V_RX_NPORTS(1) | V_TX_NPORTS(1), adapter->regs + A_PORT_CONFIG);
191f7917c00SJeff Kirsher }
192f7917c00SJeff Kirsher 
espi_setup_for_vsc7321(adapter_t * adapter)193f7917c00SJeff Kirsher static void espi_setup_for_vsc7321(adapter_t *adapter)
194f7917c00SJeff Kirsher {
195f7917c00SJeff Kirsher 	writel(0x1f4, adapter->regs + A_ESPI_SCH_TOKEN0);
196f7917c00SJeff Kirsher 	writel(0x1f401f4, adapter->regs + A_ESPI_SCH_TOKEN1);
197f7917c00SJeff Kirsher 	writel(0x1f4, adapter->regs + A_ESPI_SCH_TOKEN2);
198f7917c00SJeff Kirsher 	writel(0xa00, adapter->regs + A_ESPI_RX_FIFO_ALMOST_FULL_WATERMARK);
199f7917c00SJeff Kirsher 	writel(0x1ff, adapter->regs + A_ESPI_RX_FIFO_ALMOST_EMPTY_WATERMARK);
200f7917c00SJeff Kirsher 	writel(1, adapter->regs + A_ESPI_CALENDAR_LENGTH);
201f7917c00SJeff Kirsher 	writel(V_RX_NPORTS(4) | V_TX_NPORTS(4), adapter->regs + A_PORT_CONFIG);
202f7917c00SJeff Kirsher 
203f7917c00SJeff Kirsher 	writel(0x08000008, adapter->regs + A_ESPI_TRAIN);
204f7917c00SJeff Kirsher }
205f7917c00SJeff Kirsher 
206f7917c00SJeff Kirsher /*
207f7917c00SJeff Kirsher  * Note that T1B requires at least 2 ports for IXF1010 due to a HW bug.
208f7917c00SJeff Kirsher  */
espi_setup_for_ixf1010(adapter_t * adapter,int nports)209f7917c00SJeff Kirsher static void espi_setup_for_ixf1010(adapter_t *adapter, int nports)
210f7917c00SJeff Kirsher {
211f7917c00SJeff Kirsher 	writel(1, adapter->regs + A_ESPI_CALENDAR_LENGTH);
212f7917c00SJeff Kirsher 	if (nports == 4) {
213f7917c00SJeff Kirsher 		if (is_T2(adapter)) {
214f7917c00SJeff Kirsher 			writel(0xf00, adapter->regs + A_ESPI_RX_FIFO_ALMOST_FULL_WATERMARK);
215f7917c00SJeff Kirsher 			writel(0x3c0, adapter->regs + A_ESPI_RX_FIFO_ALMOST_EMPTY_WATERMARK);
216f7917c00SJeff Kirsher 		} else {
217f7917c00SJeff Kirsher 			writel(0x7ff, adapter->regs + A_ESPI_RX_FIFO_ALMOST_FULL_WATERMARK);
218f7917c00SJeff Kirsher 			writel(0x1ff, adapter->regs + A_ESPI_RX_FIFO_ALMOST_EMPTY_WATERMARK);
219f7917c00SJeff Kirsher 		}
220f7917c00SJeff Kirsher 	} else {
221f7917c00SJeff Kirsher 		writel(0x1fff, adapter->regs + A_ESPI_RX_FIFO_ALMOST_FULL_WATERMARK);
222f7917c00SJeff Kirsher 		writel(0x7ff, adapter->regs + A_ESPI_RX_FIFO_ALMOST_EMPTY_WATERMARK);
223f7917c00SJeff Kirsher 	}
224f7917c00SJeff Kirsher 	writel(V_RX_NPORTS(nports) | V_TX_NPORTS(nports), adapter->regs + A_PORT_CONFIG);
225f7917c00SJeff Kirsher 
226f7917c00SJeff Kirsher }
227f7917c00SJeff Kirsher 
t1_espi_init(struct peespi * espi,int mac_type,int nports)228f7917c00SJeff Kirsher int t1_espi_init(struct peespi *espi, int mac_type, int nports)
229f7917c00SJeff Kirsher {
230f7917c00SJeff Kirsher 	u32 status_enable_extra = 0;
231f7917c00SJeff Kirsher 	adapter_t *adapter = espi->adapter;
232f7917c00SJeff Kirsher 
233f7917c00SJeff Kirsher 	/* Disable ESPI training.  MACs that can handle it enable it below. */
234f7917c00SJeff Kirsher 	writel(0, adapter->regs + A_ESPI_TRAIN);
235f7917c00SJeff Kirsher 
236f7917c00SJeff Kirsher 	if (is_T2(adapter)) {
237f7917c00SJeff Kirsher 		writel(V_OUT_OF_SYNC_COUNT(4) |
238f7917c00SJeff Kirsher 		       V_DIP2_PARITY_ERR_THRES(3) |
239f7917c00SJeff Kirsher 		       V_DIP4_THRES(1), adapter->regs + A_ESPI_MISC_CONTROL);
240f7917c00SJeff Kirsher 		writel(nports == 4 ? 0x200040 : 0x1000080,
241f7917c00SJeff Kirsher 		       adapter->regs + A_ESPI_MAXBURST1_MAXBURST2);
242f7917c00SJeff Kirsher 	} else
243f7917c00SJeff Kirsher 		writel(0x800100, adapter->regs + A_ESPI_MAXBURST1_MAXBURST2);
244f7917c00SJeff Kirsher 
245f7917c00SJeff Kirsher 	if (mac_type == CHBT_MAC_PM3393)
246f7917c00SJeff Kirsher 		espi_setup_for_pm3393(adapter);
247f7917c00SJeff Kirsher 	else if (mac_type == CHBT_MAC_VSC7321)
248f7917c00SJeff Kirsher 		espi_setup_for_vsc7321(adapter);
249f7917c00SJeff Kirsher 	else if (mac_type == CHBT_MAC_IXF1010) {
250f7917c00SJeff Kirsher 		status_enable_extra = F_INTEL1010MODE;
251f7917c00SJeff Kirsher 		espi_setup_for_ixf1010(adapter, nports);
252f7917c00SJeff Kirsher 	} else
253f7917c00SJeff Kirsher 		return -1;
254f7917c00SJeff Kirsher 
255f7917c00SJeff Kirsher 	writel(status_enable_extra | F_RXSTATUSENABLE,
256f7917c00SJeff Kirsher 	       adapter->regs + A_ESPI_FIFO_STATUS_ENABLE);
257f7917c00SJeff Kirsher 
258f7917c00SJeff Kirsher 	if (is_T2(adapter)) {
259f7917c00SJeff Kirsher 		tricn_init(adapter);
260f7917c00SJeff Kirsher 		/*
261f7917c00SJeff Kirsher 		 * Always position the control at the 1st port egress IN
262f7917c00SJeff Kirsher 		 * (sop,eop) counter to reduce PIOs for T/N210 workaround.
263f7917c00SJeff Kirsher 		 */
264f7917c00SJeff Kirsher 		espi->misc_ctrl = readl(adapter->regs + A_ESPI_MISC_CONTROL);
265f7917c00SJeff Kirsher 		espi->misc_ctrl &= ~MON_MASK;
266f7917c00SJeff Kirsher 		espi->misc_ctrl |= F_MONITORED_DIRECTION;
267f7917c00SJeff Kirsher 		if (adapter->params.nports == 1)
268f7917c00SJeff Kirsher 			espi->misc_ctrl |= F_MONITORED_INTERFACE;
269f7917c00SJeff Kirsher 		writel(espi->misc_ctrl, adapter->regs + A_ESPI_MISC_CONTROL);
270f7917c00SJeff Kirsher 		spin_lock_init(&espi->lock);
271f7917c00SJeff Kirsher 	}
272f7917c00SJeff Kirsher 
273f7917c00SJeff Kirsher 	return 0;
274f7917c00SJeff Kirsher }
275f7917c00SJeff Kirsher 
t1_espi_destroy(struct peespi * espi)276f7917c00SJeff Kirsher void t1_espi_destroy(struct peespi *espi)
277f7917c00SJeff Kirsher {
278f7917c00SJeff Kirsher 	kfree(espi);
279f7917c00SJeff Kirsher }
280f7917c00SJeff Kirsher 
t1_espi_create(adapter_t * adapter)281f7917c00SJeff Kirsher struct peespi *t1_espi_create(adapter_t *adapter)
282f7917c00SJeff Kirsher {
283f7917c00SJeff Kirsher 	struct peespi *espi = kzalloc(sizeof(*espi), GFP_KERNEL);
284f7917c00SJeff Kirsher 
285f7917c00SJeff Kirsher 	if (espi)
286f7917c00SJeff Kirsher 		espi->adapter = adapter;
287f7917c00SJeff Kirsher 	return espi;
288f7917c00SJeff Kirsher }
289f7917c00SJeff Kirsher 
290f7917c00SJeff Kirsher #if 0
291f7917c00SJeff Kirsher void t1_espi_set_misc_ctrl(adapter_t *adapter, u32 val)
292f7917c00SJeff Kirsher {
293f7917c00SJeff Kirsher 	struct peespi *espi = adapter->espi;
294f7917c00SJeff Kirsher 
295f7917c00SJeff Kirsher 	if (!is_T2(adapter))
296f7917c00SJeff Kirsher 		return;
297f7917c00SJeff Kirsher 	spin_lock(&espi->lock);
298f7917c00SJeff Kirsher 	espi->misc_ctrl = (val & ~MON_MASK) |
299f7917c00SJeff Kirsher 			  (espi->misc_ctrl & MON_MASK);
300f7917c00SJeff Kirsher 	writel(espi->misc_ctrl, adapter->regs + A_ESPI_MISC_CONTROL);
301f7917c00SJeff Kirsher 	spin_unlock(&espi->lock);
302f7917c00SJeff Kirsher }
303f7917c00SJeff Kirsher #endif  /*  0  */
304f7917c00SJeff Kirsher 
t1_espi_get_mon(adapter_t * adapter,u32 addr,u8 wait)305f7917c00SJeff Kirsher u32 t1_espi_get_mon(adapter_t *adapter, u32 addr, u8 wait)
306f7917c00SJeff Kirsher {
307f7917c00SJeff Kirsher 	struct peespi *espi = adapter->espi;
308f7917c00SJeff Kirsher 	u32 sel;
309f7917c00SJeff Kirsher 
310f7917c00SJeff Kirsher 	if (!is_T2(adapter))
311f7917c00SJeff Kirsher 		return 0;
312f7917c00SJeff Kirsher 
313f7917c00SJeff Kirsher 	sel = V_MONITORED_PORT_NUM((addr & 0x3c) >> 2);
314f7917c00SJeff Kirsher 	if (!wait) {
315f7917c00SJeff Kirsher 		if (!spin_trylock(&espi->lock))
316f7917c00SJeff Kirsher 			return 0;
317f7917c00SJeff Kirsher 	} else
318f7917c00SJeff Kirsher 		spin_lock(&espi->lock);
319f7917c00SJeff Kirsher 
320f7917c00SJeff Kirsher 	if ((sel != (espi->misc_ctrl & MON_MASK))) {
321f7917c00SJeff Kirsher 		writel(((espi->misc_ctrl & ~MON_MASK) | sel),
322f7917c00SJeff Kirsher 		       adapter->regs + A_ESPI_MISC_CONTROL);
323f7917c00SJeff Kirsher 		sel = readl(adapter->regs + A_ESPI_SCH_TOKEN3);
324f7917c00SJeff Kirsher 		writel(espi->misc_ctrl, adapter->regs + A_ESPI_MISC_CONTROL);
325f7917c00SJeff Kirsher 	} else
326f7917c00SJeff Kirsher 		sel = readl(adapter->regs + A_ESPI_SCH_TOKEN3);
327f7917c00SJeff Kirsher 	spin_unlock(&espi->lock);
328f7917c00SJeff Kirsher 	return sel;
329f7917c00SJeff Kirsher }
330f7917c00SJeff Kirsher 
331f7917c00SJeff Kirsher /*
332f7917c00SJeff Kirsher  * This function is for T204 only.
333f7917c00SJeff Kirsher  * compare with t1_espi_get_mon(), it reads espiInTxSop[0 ~ 3] in
334f7917c00SJeff Kirsher  * one shot, since there is no per port counter on the out side.
335f7917c00SJeff Kirsher  */
t1_espi_get_mon_t204(adapter_t * adapter,u32 * valp,u8 wait)336f7917c00SJeff Kirsher int t1_espi_get_mon_t204(adapter_t *adapter, u32 *valp, u8 wait)
337f7917c00SJeff Kirsher {
338f7917c00SJeff Kirsher 	struct peespi *espi = adapter->espi;
339f7917c00SJeff Kirsher 	u8 i, nport = (u8)adapter->params.nports;
340f7917c00SJeff Kirsher 
341f7917c00SJeff Kirsher 	if (!wait) {
342f7917c00SJeff Kirsher 		if (!spin_trylock(&espi->lock))
343f7917c00SJeff Kirsher 			return -1;
344f7917c00SJeff Kirsher 	} else
345f7917c00SJeff Kirsher 		spin_lock(&espi->lock);
346f7917c00SJeff Kirsher 
347f7917c00SJeff Kirsher 	if ((espi->misc_ctrl & MON_MASK) != F_MONITORED_DIRECTION) {
348f7917c00SJeff Kirsher 		espi->misc_ctrl = (espi->misc_ctrl & ~MON_MASK) |
349f7917c00SJeff Kirsher 					F_MONITORED_DIRECTION;
350f7917c00SJeff Kirsher 		writel(espi->misc_ctrl, adapter->regs + A_ESPI_MISC_CONTROL);
351f7917c00SJeff Kirsher 	}
352f7917c00SJeff Kirsher 	for (i = 0 ; i < nport; i++, valp++) {
353f7917c00SJeff Kirsher 		if (i) {
354f7917c00SJeff Kirsher 			writel(espi->misc_ctrl | V_MONITORED_PORT_NUM(i),
355f7917c00SJeff Kirsher 			       adapter->regs + A_ESPI_MISC_CONTROL);
356f7917c00SJeff Kirsher 		}
357f7917c00SJeff Kirsher 		*valp = readl(adapter->regs + A_ESPI_SCH_TOKEN3);
358f7917c00SJeff Kirsher 	}
359f7917c00SJeff Kirsher 
360f7917c00SJeff Kirsher 	writel(espi->misc_ctrl, adapter->regs + A_ESPI_MISC_CONTROL);
361f7917c00SJeff Kirsher 	spin_unlock(&espi->lock);
362f7917c00SJeff Kirsher 	return 0;
363f7917c00SJeff Kirsher }
364