blob: 3e182eee799e64e482b1823e69b179ecef634262 [file] [log] [blame]
Christoph Lameter8199d3a2005-03-30 13:34:31 -08001/*****************************************************************************
2 * *
3 * File: espi.c *
Scott Bardone559fb512005-06-23 01:40:19 -04004 * $Revision: 1.14 $ *
5 * $Date: 2005/05/14 00:59:32 $ *
Christoph Lameter8199d3a2005-03-30 13:34:31 -08006 * Description: *
7 * Ethernet SPI functionality. *
8 * part of the Chelsio 10Gb Ethernet Driver. *
9 * *
10 * This program is free software; you can redistribute it and/or modify *
11 * it under the terms of the GNU General Public License, version 2, as *
12 * published by the Free Software Foundation. *
13 * *
14 * You should have received a copy of the GNU General Public License along *
Jeff Kirsher0ab75ae2013-12-06 06:28:43 -080015 * with this program; if not, see <http://www.gnu.org/licenses/>. *
Christoph Lameter8199d3a2005-03-30 13:34:31 -080016 * *
17 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED *
18 * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF *
19 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. *
20 * *
21 * http://www.chelsio.com *
22 * *
23 * Copyright (c) 2003 - 2005 Chelsio Communications, Inc. *
24 * All rights reserved. *
25 * *
26 * Maintainers: maintainers@chelsio.com *
27 * *
28 * Authors: Dimitrios Michailidis <dm@chelsio.com> *
29 * Tina Yang <tainay@chelsio.com> *
30 * Felix Marti <felix@chelsio.com> *
31 * Scott Bardone <sbardone@chelsio.com> *
32 * Kurt Ottaway <kottaway@chelsio.com> *
33 * Frank DiMambro <frank@chelsio.com> *
34 * *
35 * History: *
36 * *
37 ****************************************************************************/
38
39#include "common.h"
40#include "regs.h"
41#include "espi.h"
42
43struct peespi {
44 adapter_t *adapter;
45 struct espi_intr_counts intr_cnt;
46 u32 misc_ctrl;
47 spinlock_t lock;
48};
49
50#define ESPI_INTR_MASK (F_DIP4ERR | F_RXDROP | F_TXDROP | F_RXOVERFLOW | \
51 F_RAMPARITYERR | F_DIP2PARITYERR)
52#define MON_MASK (V_MONITORED_PORT_NUM(3) | F_MONITORED_DIRECTION \
53 | F_MONITORED_INTERFACE)
54
55#define TRICN_CNFG 14
56#define TRICN_CMD_READ 0x11
57#define TRICN_CMD_WRITE 0x21
58#define TRICN_CMD_ATTEMPTS 10
59
60static int tricn_write(adapter_t *adapter, int bundle_addr, int module_addr,
61 int ch_addr, int reg_offset, u32 wr_data)
62{
63 int busy, attempts = TRICN_CMD_ATTEMPTS;
64
Scott Bardone559fb512005-06-23 01:40:19 -040065 writel(V_WRITE_DATA(wr_data) |
66 V_REGISTER_OFFSET(reg_offset) |
67 V_CHANNEL_ADDR(ch_addr) | V_MODULE_ADDR(module_addr) |
68 V_BUNDLE_ADDR(bundle_addr) |
69 V_SPI4_COMMAND(TRICN_CMD_WRITE),
70 adapter->regs + A_ESPI_CMD_ADDR);
71 writel(0, adapter->regs + A_ESPI_GOSTAT);
Christoph Lameter8199d3a2005-03-30 13:34:31 -080072
73 do {
Scott Bardone559fb512005-06-23 01:40:19 -040074 busy = readl(adapter->regs + A_ESPI_GOSTAT) & F_ESPI_CMD_BUSY;
Christoph Lameter8199d3a2005-03-30 13:34:31 -080075 } while (busy && --attempts);
76
77 if (busy)
Joe Perchesc1f51212010-02-22 16:56:57 +000078 pr_err("%s: TRICN write timed out\n", adapter->name);
Christoph Lameter8199d3a2005-03-30 13:34:31 -080079
80 return busy;
81}
82
Christoph Lameter8199d3a2005-03-30 13:34:31 -080083static int tricn_init(adapter_t *adapter)
84{
Stephen Hemmingerf1d3d382006-12-01 16:36:16 -080085 int i, sme = 1;
Christoph Lameter8199d3a2005-03-30 13:34:31 -080086
Stephen Hemmingerf1d3d382006-12-01 16:36:16 -080087 if (!(readl(adapter->regs + A_ESPI_RX_RESET) & F_RX_CLK_STATUS)) {
Joe Perchesc1f51212010-02-22 16:56:57 +000088 pr_err("%s: ESPI clock not ready\n", adapter->name);
Stephen Hemmingerf1d3d382006-12-01 16:36:16 -080089 return -1;
Christoph Lameter8199d3a2005-03-30 13:34:31 -080090 }
91
Stephen Hemmingerf1d3d382006-12-01 16:36:16 -080092 writel(F_ESPI_RX_CORE_RST, adapter->regs + A_ESPI_RX_RESET);
Christoph Lameter8199d3a2005-03-30 13:34:31 -080093
Stephen Hemmingerf1d3d382006-12-01 16:36:16 -080094 if (sme) {
95 tricn_write(adapter, 0, 0, 0, TRICN_CNFG, 0x81);
96 tricn_write(adapter, 0, 1, 0, TRICN_CNFG, 0x81);
97 tricn_write(adapter, 0, 2, 0, TRICN_CNFG, 0x81);
98 }
99 for (i = 1; i <= 8; i++)
100 tricn_write(adapter, 0, 0, i, TRICN_CNFG, 0xf1);
101 for (i = 1; i <= 2; i++)
102 tricn_write(adapter, 0, 1, i, TRICN_CNFG, 0xf1);
103 for (i = 1; i <= 3; i++)
104 tricn_write(adapter, 0, 2, i, TRICN_CNFG, 0xe1);
105 tricn_write(adapter, 0, 2, 4, TRICN_CNFG, 0xf1);
106 tricn_write(adapter, 0, 2, 5, TRICN_CNFG, 0xe1);
107 tricn_write(adapter, 0, 2, 6, TRICN_CNFG, 0xf1);
108 tricn_write(adapter, 0, 2, 7, TRICN_CNFG, 0x80);
109 tricn_write(adapter, 0, 2, 8, TRICN_CNFG, 0xf1);
110
111 writel(F_ESPI_RX_CORE_RST | F_ESPI_RX_LNK_RST,
112 adapter->regs + A_ESPI_RX_RESET);
Christoph Lameter8199d3a2005-03-30 13:34:31 -0800113
114 return 0;
115}
116
117void t1_espi_intr_enable(struct peespi *espi)
118{
Scott Bardone559fb512005-06-23 01:40:19 -0400119 u32 enable, pl_intr = readl(espi->adapter->regs + A_PL_ENABLE);
Christoph Lameter8199d3a2005-03-30 13:34:31 -0800120
121 /*
122 * Cannot enable ESPI interrupts on T1B because HW asserts the
123 * interrupt incorrectly, namely the driver gets ESPI interrupts
124 * but no data is actually dropped (can verify this reading the ESPI
125 * drop registers). Also, once the ESPI interrupt is asserted it
126 * cannot be cleared (HW bug).
127 */
128 enable = t1_is_T1B(espi->adapter) ? 0 : ESPI_INTR_MASK;
Scott Bardone559fb512005-06-23 01:40:19 -0400129 writel(enable, espi->adapter->regs + A_ESPI_INTR_ENABLE);
130 writel(pl_intr | F_PL_INTR_ESPI, espi->adapter->regs + A_PL_ENABLE);
Christoph Lameter8199d3a2005-03-30 13:34:31 -0800131}
132
133void t1_espi_intr_clear(struct peespi *espi)
134{
Stephen Hemmingerf1d3d382006-12-01 16:36:16 -0800135 readl(espi->adapter->regs + A_ESPI_DIP2_ERR_COUNT);
Scott Bardone559fb512005-06-23 01:40:19 -0400136 writel(0xffffffff, espi->adapter->regs + A_ESPI_INTR_STATUS);
137 writel(F_PL_INTR_ESPI, espi->adapter->regs + A_PL_CAUSE);
Christoph Lameter8199d3a2005-03-30 13:34:31 -0800138}
139
140void t1_espi_intr_disable(struct peespi *espi)
141{
Scott Bardone559fb512005-06-23 01:40:19 -0400142 u32 pl_intr = readl(espi->adapter->regs + A_PL_ENABLE);
Christoph Lameter8199d3a2005-03-30 13:34:31 -0800143
Scott Bardone559fb512005-06-23 01:40:19 -0400144 writel(0, espi->adapter->regs + A_ESPI_INTR_ENABLE);
145 writel(pl_intr & ~F_PL_INTR_ESPI, espi->adapter->regs + A_PL_ENABLE);
Christoph Lameter8199d3a2005-03-30 13:34:31 -0800146}
147
148int t1_espi_intr_handler(struct peespi *espi)
149{
Scott Bardone559fb512005-06-23 01:40:19 -0400150 u32 status = readl(espi->adapter->regs + A_ESPI_INTR_STATUS);
Christoph Lameter8199d3a2005-03-30 13:34:31 -0800151
152 if (status & F_DIP4ERR)
153 espi->intr_cnt.DIP4_err++;
154 if (status & F_RXDROP)
155 espi->intr_cnt.rx_drops++;
156 if (status & F_TXDROP)
157 espi->intr_cnt.tx_drops++;
158 if (status & F_RXOVERFLOW)
159 espi->intr_cnt.rx_ovflw++;
160 if (status & F_RAMPARITYERR)
161 espi->intr_cnt.parity_err++;
162 if (status & F_DIP2PARITYERR) {
163 espi->intr_cnt.DIP2_parity_err++;
164
165 /*
166 * Must read the error count to clear the interrupt
167 * that it causes.
168 */
Stephen Hemmingerf1d3d382006-12-01 16:36:16 -0800169 readl(espi->adapter->regs + A_ESPI_DIP2_ERR_COUNT);
Christoph Lameter8199d3a2005-03-30 13:34:31 -0800170 }
171
172 /*
173 * For T1B we need to write 1 to clear ESPI interrupts. For T2+ we
174 * write the status as is.
175 */
176 if (status && t1_is_T1B(espi->adapter))
177 status = 1;
Scott Bardone559fb512005-06-23 01:40:19 -0400178 writel(status, espi->adapter->regs + A_ESPI_INTR_STATUS);
Christoph Lameter8199d3a2005-03-30 13:34:31 -0800179 return 0;
180}
181
Scott Bardone559fb512005-06-23 01:40:19 -0400182const struct espi_intr_counts *t1_espi_get_intr_counts(struct peespi *espi)
183{
Stephen Hemminger11e5a202006-12-01 16:36:13 -0800184 return &espi->intr_cnt;
Scott Bardone559fb512005-06-23 01:40:19 -0400185}
186
Christoph Lameter8199d3a2005-03-30 13:34:31 -0800187static void espi_setup_for_pm3393(adapter_t *adapter)
188{
189 u32 wmark = t1_is_T1B(adapter) ? 0x4000 : 0x3200;
190
Scott Bardone559fb512005-06-23 01:40:19 -0400191 writel(0x1f4, adapter->regs + A_ESPI_SCH_TOKEN0);
192 writel(0x1f4, adapter->regs + A_ESPI_SCH_TOKEN1);
193 writel(0x1f4, adapter->regs + A_ESPI_SCH_TOKEN2);
194 writel(0x1f4, adapter->regs + A_ESPI_SCH_TOKEN3);
195 writel(0x100, adapter->regs + A_ESPI_RX_FIFO_ALMOST_EMPTY_WATERMARK);
196 writel(wmark, adapter->regs + A_ESPI_RX_FIFO_ALMOST_FULL_WATERMARK);
197 writel(3, adapter->regs + A_ESPI_CALENDAR_LENGTH);
198 writel(0x08000008, adapter->regs + A_ESPI_TRAIN);
199 writel(V_RX_NPORTS(1) | V_TX_NPORTS(1), adapter->regs + A_PORT_CONFIG);
Christoph Lameter8199d3a2005-03-30 13:34:31 -0800200}
201
Stephen Hemmingerf1d3d382006-12-01 16:36:16 -0800202static void espi_setup_for_vsc7321(adapter_t *adapter)
203{
Francois Romieu356bd142006-12-11 23:47:00 +0100204 writel(0x1f4, adapter->regs + A_ESPI_SCH_TOKEN0);
205 writel(0x1f401f4, adapter->regs + A_ESPI_SCH_TOKEN1);
206 writel(0x1f4, adapter->regs + A_ESPI_SCH_TOKEN2);
Stephen Hemmingerf1d3d382006-12-01 16:36:16 -0800207 writel(0xa00, adapter->regs + A_ESPI_RX_FIFO_ALMOST_FULL_WATERMARK);
208 writel(0x1ff, adapter->regs + A_ESPI_RX_FIFO_ALMOST_EMPTY_WATERMARK);
209 writel(1, adapter->regs + A_ESPI_CALENDAR_LENGTH);
210 writel(V_RX_NPORTS(4) | V_TX_NPORTS(4), adapter->regs + A_PORT_CONFIG);
211
212 writel(0x08000008, adapter->regs + A_ESPI_TRAIN);
213}
214
215/*
216 * Note that T1B requires at least 2 ports for IXF1010 due to a HW bug.
217 */
218static void espi_setup_for_ixf1010(adapter_t *adapter, int nports)
219{
220 writel(1, adapter->regs + A_ESPI_CALENDAR_LENGTH);
221 if (nports == 4) {
222 if (is_T2(adapter)) {
223 writel(0xf00, adapter->regs + A_ESPI_RX_FIFO_ALMOST_FULL_WATERMARK);
224 writel(0x3c0, adapter->regs + A_ESPI_RX_FIFO_ALMOST_EMPTY_WATERMARK);
225 } else {
226 writel(0x7ff, adapter->regs + A_ESPI_RX_FIFO_ALMOST_FULL_WATERMARK);
227 writel(0x1ff, adapter->regs + A_ESPI_RX_FIFO_ALMOST_EMPTY_WATERMARK);
228 }
229 } else {
230 writel(0x1fff, adapter->regs + A_ESPI_RX_FIFO_ALMOST_FULL_WATERMARK);
231 writel(0x7ff, adapter->regs + A_ESPI_RX_FIFO_ALMOST_EMPTY_WATERMARK);
232 }
233 writel(V_RX_NPORTS(nports) | V_TX_NPORTS(nports), adapter->regs + A_PORT_CONFIG);
234
235}
236
Christoph Lameter8199d3a2005-03-30 13:34:31 -0800237int t1_espi_init(struct peespi *espi, int mac_type, int nports)
238{
239 u32 status_enable_extra = 0;
240 adapter_t *adapter = espi->adapter;
Christoph Lameter8199d3a2005-03-30 13:34:31 -0800241
242 /* Disable ESPI training. MACs that can handle it enable it below. */
Scott Bardone559fb512005-06-23 01:40:19 -0400243 writel(0, adapter->regs + A_ESPI_TRAIN);
Christoph Lameter8199d3a2005-03-30 13:34:31 -0800244
245 if (is_T2(adapter)) {
Scott Bardone559fb512005-06-23 01:40:19 -0400246 writel(V_OUT_OF_SYNC_COUNT(4) |
247 V_DIP2_PARITY_ERR_THRES(3) |
248 V_DIP4_THRES(1), adapter->regs + A_ESPI_MISC_CONTROL);
Francois Romieu356bd142006-12-11 23:47:00 +0100249 writel(nports == 4 ? 0x200040 : 0x1000080,
Stephen Hemmingerf1d3d382006-12-01 16:36:16 -0800250 adapter->regs + A_ESPI_MAXBURST1_MAXBURST2);
251 } else
Francois Romieu356bd142006-12-11 23:47:00 +0100252 writel(0x800100, adapter->regs + A_ESPI_MAXBURST1_MAXBURST2);
Christoph Lameter8199d3a2005-03-30 13:34:31 -0800253
Stephen Hemmingerf1d3d382006-12-01 16:36:16 -0800254 if (mac_type == CHBT_MAC_PM3393)
Christoph Lameter8199d3a2005-03-30 13:34:31 -0800255 espi_setup_for_pm3393(adapter);
Stephen Hemmingerf1d3d382006-12-01 16:36:16 -0800256 else if (mac_type == CHBT_MAC_VSC7321)
257 espi_setup_for_vsc7321(adapter);
258 else if (mac_type == CHBT_MAC_IXF1010) {
259 status_enable_extra = F_INTEL1010MODE;
260 espi_setup_for_ixf1010(adapter, nports);
261 } else
Christoph Lameter8199d3a2005-03-30 13:34:31 -0800262 return -1;
Christoph Lameter8199d3a2005-03-30 13:34:31 -0800263
Scott Bardone559fb512005-06-23 01:40:19 -0400264 writel(status_enable_extra | F_RXSTATUSENABLE,
265 adapter->regs + A_ESPI_FIFO_STATUS_ENABLE);
Christoph Lameter8199d3a2005-03-30 13:34:31 -0800266
267 if (is_T2(adapter)) {
268 tricn_init(adapter);
269 /*
270 * Always position the control at the 1st port egress IN
271 * (sop,eop) counter to reduce PIOs for T/N210 workaround.
272 */
Stephen Hemmingerf1d3d382006-12-01 16:36:16 -0800273 espi->misc_ctrl = readl(adapter->regs + A_ESPI_MISC_CONTROL);
274 espi->misc_ctrl &= ~MON_MASK;
275 espi->misc_ctrl |= F_MONITORED_DIRECTION;
276 if (adapter->params.nports == 1)
277 espi->misc_ctrl |= F_MONITORED_INTERFACE;
Scott Bardone559fb512005-06-23 01:40:19 -0400278 writel(espi->misc_ctrl, adapter->regs + A_ESPI_MISC_CONTROL);
Christoph Lameter8199d3a2005-03-30 13:34:31 -0800279 spin_lock_init(&espi->lock);
280 }
281
282 return 0;
283}
284
285void t1_espi_destroy(struct peespi *espi)
286{
287 kfree(espi);
288}
289
290struct peespi *t1_espi_create(adapter_t *adapter)
291{
Eric Sesterhenn2d668062006-03-05 01:16:00 +0300292 struct peespi *espi = kzalloc(sizeof(*espi), GFP_KERNEL);
Christoph Lameter8199d3a2005-03-30 13:34:31 -0800293
294 if (espi)
295 espi->adapter = adapter;
296 return espi;
297}
298
Adrian Bunk68d579f2007-11-21 15:02:55 -0800299#if 0
Christoph Lameter8199d3a2005-03-30 13:34:31 -0800300void t1_espi_set_misc_ctrl(adapter_t *adapter, u32 val)
301{
302 struct peespi *espi = adapter->espi;
303
Francois Romieuc697f832006-12-05 22:38:00 +0100304 if (!is_T2(adapter))
305 return;
Christoph Lameter8199d3a2005-03-30 13:34:31 -0800306 spin_lock(&espi->lock);
307 espi->misc_ctrl = (val & ~MON_MASK) |
308 (espi->misc_ctrl & MON_MASK);
Scott Bardone559fb512005-06-23 01:40:19 -0400309 writel(espi->misc_ctrl, adapter->regs + A_ESPI_MISC_CONTROL);
Christoph Lameter8199d3a2005-03-30 13:34:31 -0800310 spin_unlock(&espi->lock);
311}
Adrian Bunk68d579f2007-11-21 15:02:55 -0800312#endif /* 0 */
Christoph Lameter8199d3a2005-03-30 13:34:31 -0800313
314u32 t1_espi_get_mon(adapter_t *adapter, u32 addr, u8 wait)
315{
Scott Bardone559fb512005-06-23 01:40:19 -0400316 struct peespi *espi = adapter->espi;
Stephen Hemmingerf1d3d382006-12-01 16:36:16 -0800317 u32 sel;
Scott Bardone559fb512005-06-23 01:40:19 -0400318
Christoph Lameter8199d3a2005-03-30 13:34:31 -0800319 if (!is_T2(adapter))
320 return 0;
Stephen Hemmingerf1d3d382006-12-01 16:36:16 -0800321
Christoph Lameter8199d3a2005-03-30 13:34:31 -0800322 sel = V_MONITORED_PORT_NUM((addr & 0x3c) >> 2);
323 if (!wait) {
324 if (!spin_trylock(&espi->lock))
325 return 0;
Stephen Hemmingerf1d3d382006-12-01 16:36:16 -0800326 } else
Christoph Lameter8199d3a2005-03-30 13:34:31 -0800327 spin_lock(&espi->lock);
Stephen Hemmingerf1d3d382006-12-01 16:36:16 -0800328
Christoph Lameter8199d3a2005-03-30 13:34:31 -0800329 if ((sel != (espi->misc_ctrl & MON_MASK))) {
Scott Bardone559fb512005-06-23 01:40:19 -0400330 writel(((espi->misc_ctrl & ~MON_MASK) | sel),
331 adapter->regs + A_ESPI_MISC_CONTROL);
332 sel = readl(adapter->regs + A_ESPI_SCH_TOKEN3);
333 writel(espi->misc_ctrl, adapter->regs + A_ESPI_MISC_CONTROL);
Stephen Hemmingerf1d3d382006-12-01 16:36:16 -0800334 } else
Scott Bardone559fb512005-06-23 01:40:19 -0400335 sel = readl(adapter->regs + A_ESPI_SCH_TOKEN3);
Christoph Lameter8199d3a2005-03-30 13:34:31 -0800336 spin_unlock(&espi->lock);
337 return sel;
338}
Stephen Hemmingerf1d3d382006-12-01 16:36:16 -0800339
340/*
341 * This function is for T204 only.
342 * compare with t1_espi_get_mon(), it reads espiInTxSop[0 ~ 3] in
343 * one shot, since there is no per port counter on the out side.
344 */
Francois Romieu356bd142006-12-11 23:47:00 +0100345int t1_espi_get_mon_t204(adapter_t *adapter, u32 *valp, u8 wait)
Stephen Hemmingerf1d3d382006-12-01 16:36:16 -0800346{
Francois Romieu356bd142006-12-11 23:47:00 +0100347 struct peespi *espi = adapter->espi;
Stephen Hemmingerf1d3d382006-12-01 16:36:16 -0800348 u8 i, nport = (u8)adapter->params.nports;
349
Francois Romieu356bd142006-12-11 23:47:00 +0100350 if (!wait) {
351 if (!spin_trylock(&espi->lock))
352 return -1;
353 } else
354 spin_lock(&espi->lock);
Stephen Hemmingerf1d3d382006-12-01 16:36:16 -0800355
Francois Romieu356bd142006-12-11 23:47:00 +0100356 if ((espi->misc_ctrl & MON_MASK) != F_MONITORED_DIRECTION) {
Stephen Hemmingerf1d3d382006-12-01 16:36:16 -0800357 espi->misc_ctrl = (espi->misc_ctrl & ~MON_MASK) |
358 F_MONITORED_DIRECTION;
Francois Romieu356bd142006-12-11 23:47:00 +0100359 writel(espi->misc_ctrl, adapter->regs + A_ESPI_MISC_CONTROL);
360 }
Stephen Hemmingerf1d3d382006-12-01 16:36:16 -0800361 for (i = 0 ; i < nport; i++, valp++) {
362 if (i) {
363 writel(espi->misc_ctrl | V_MONITORED_PORT_NUM(i),
364 adapter->regs + A_ESPI_MISC_CONTROL);
365 }
Francois Romieu356bd142006-12-11 23:47:00 +0100366 *valp = readl(adapter->regs + A_ESPI_SCH_TOKEN3);
367 }
Stephen Hemmingerf1d3d382006-12-01 16:36:16 -0800368
Francois Romieu356bd142006-12-11 23:47:00 +0100369 writel(espi->misc_ctrl, adapter->regs + A_ESPI_MISC_CONTROL);
370 spin_unlock(&espi->lock);
371 return 0;
Stephen Hemmingerf1d3d382006-12-01 16:36:16 -0800372}