1*3833Sxw161283 /*
2*3833Sxw161283 * CDDL HEADER START
3*3833Sxw161283 *
4*3833Sxw161283 * The contents of this file are subject to the terms of the
5*3833Sxw161283 * Common Development and Distribution License (the "License").
6*3833Sxw161283 * You may not use this file except in compliance with the License.
7*3833Sxw161283 *
8*3833Sxw161283 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9*3833Sxw161283 * or http://www.opensolaris.org/os/licensing.
10*3833Sxw161283 * See the License for the specific language governing permissions
11*3833Sxw161283 * and limitations under the License.
12*3833Sxw161283 *
13*3833Sxw161283 * When distributing Covered Code, include this CDDL HEADER in each
14*3833Sxw161283 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15*3833Sxw161283 * If applicable, add the following below this CDDL HEADER, with the
16*3833Sxw161283 * fields enclosed by brackets "[]" replaced with your own identifying
17*3833Sxw161283 * information: Portions Copyright [yyyy] [name of copyright owner]
18*3833Sxw161283 *
19*3833Sxw161283 * CDDL HEADER END
20*3833Sxw161283 */
21*3833Sxw161283
22*3833Sxw161283 /*
23*3833Sxw161283 * Copyright (C) 2003-2005 Chelsio Communications. All rights reserved.
24*3833Sxw161283 */
25*3833Sxw161283
26*3833Sxw161283 #pragma ident "%Z%%M% %I% %E% SMI" /* ulp.c */
27*3833Sxw161283
28*3833Sxw161283 #include "common.h"
29*3833Sxw161283 #include "regs.h"
30*3833Sxw161283 #include "ulp.h"
31*3833Sxw161283
32*3833Sxw161283 struct peulp {
33*3833Sxw161283 adapter_t *adapter;
34*3833Sxw161283 struct ulp_intr_counts intr_counts;
35*3833Sxw161283 };
36*3833Sxw161283
37*3833Sxw161283 #define ULP_INTR_MASK (F_HREG_PAR_ERR | F_EGRS_DATA_PAR_ERR | \
38*3833Sxw161283 F_INGRS_DATA_PAR_ERR | F_PM_INTR | F_PM_E2C_SYNC_ERR | \
39*3833Sxw161283 F_PM_C2E_SYNC_ERR | F_PM_E2C_EMPTY_ERR | \
40*3833Sxw161283 F_PM_C2E_EMPTY_ERR | V_PM_PAR_ERR(M_PM_PAR_ERR) | \
41*3833Sxw161283 F_PM_E2C_WRT_FULL | F_PM_C2E_WRT_FULL)
42*3833Sxw161283
t1_ulp_intr_enable(struct peulp * ulp)43*3833Sxw161283 void t1_ulp_intr_enable(struct peulp *ulp)
44*3833Sxw161283 {
45*3833Sxw161283 /* Only ASIC boards support PL_ULP block. */
46*3833Sxw161283 if (t1_is_asic(ulp->adapter)) {
47*3833Sxw161283 u32 pl_intr = t1_read_reg_4(ulp->adapter, A_PL_ENABLE);
48*3833Sxw161283
49*3833Sxw161283 t1_write_reg_4(ulp->adapter, A_ULP_INT_ENABLE, ULP_INTR_MASK);
50*3833Sxw161283 t1_write_reg_4(ulp->adapter, A_PL_ENABLE,
51*3833Sxw161283 pl_intr | F_PL_INTR_ULP);
52*3833Sxw161283 }
53*3833Sxw161283 }
54*3833Sxw161283
t1_ulp_intr_clear(struct peulp * ulp)55*3833Sxw161283 void t1_ulp_intr_clear(struct peulp *ulp)
56*3833Sxw161283 {
57*3833Sxw161283 if (t1_is_asic(ulp->adapter)) {
58*3833Sxw161283 t1_write_reg_4(ulp->adapter, A_PL_CAUSE, F_PL_INTR_ULP);
59*3833Sxw161283 t1_write_reg_4(ulp->adapter, A_ULP_INT_CAUSE, 0xffffffff);
60*3833Sxw161283 }
61*3833Sxw161283 }
62*3833Sxw161283
t1_ulp_intr_disable(struct peulp * ulp)63*3833Sxw161283 void t1_ulp_intr_disable(struct peulp *ulp)
64*3833Sxw161283 {
65*3833Sxw161283 if (t1_is_asic(ulp->adapter)) {
66*3833Sxw161283 u32 pl_intr = t1_read_reg_4(ulp->adapter, A_PL_ENABLE);
67*3833Sxw161283
68*3833Sxw161283 t1_write_reg_4(ulp->adapter, A_PL_ENABLE,
69*3833Sxw161283 pl_intr & ~F_PL_INTR_ULP);
70*3833Sxw161283 t1_write_reg_4(ulp->adapter, A_ULP_INT_ENABLE, 0);
71*3833Sxw161283 }
72*3833Sxw161283 }
73*3833Sxw161283
t1_ulp_intr_handler(struct peulp * ulp)74*3833Sxw161283 int t1_ulp_intr_handler(struct peulp *ulp)
75*3833Sxw161283 {
76*3833Sxw161283 u32 cause = t1_read_reg_4(ulp->adapter, A_ULP_INT_CAUSE);
77*3833Sxw161283
78*3833Sxw161283 if (cause & F_HREG_PAR_ERR)
79*3833Sxw161283 ulp->intr_counts.region_table_parity_err++;
80*3833Sxw161283
81*3833Sxw161283 if (cause & F_EGRS_DATA_PAR_ERR)
82*3833Sxw161283 ulp->intr_counts.egress_tp2ulp_data_parity_err++;
83*3833Sxw161283
84*3833Sxw161283 if (cause & F_INGRS_DATA_PAR_ERR)
85*3833Sxw161283 ulp->intr_counts.ingress_tp2ulp_data_parity_err++;
86*3833Sxw161283
87*3833Sxw161283 if (cause & F_PM_INTR)
88*3833Sxw161283 ulp->intr_counts.pm_intr++;
89*3833Sxw161283
90*3833Sxw161283 if (cause & F_PM_E2C_SYNC_ERR)
91*3833Sxw161283 ulp->intr_counts.pm_e2c_cmd_payload_sync_err++;
92*3833Sxw161283
93*3833Sxw161283 if (cause & F_PM_C2E_SYNC_ERR)
94*3833Sxw161283 ulp->intr_counts.pm_c2e_cmd_payload_sync_err++;
95*3833Sxw161283
96*3833Sxw161283 if (cause & F_PM_E2C_EMPTY_ERR)
97*3833Sxw161283 ulp->intr_counts.pm_e2c_fifo_read_empty_err++;
98*3833Sxw161283
99*3833Sxw161283 if (cause & F_PM_C2E_EMPTY_ERR)
100*3833Sxw161283 ulp->intr_counts.pm_c2e_fifo_read_empty_err++;
101*3833Sxw161283
102*3833Sxw161283 if (G_PM_PAR_ERR(cause))
103*3833Sxw161283 ulp->intr_counts.pm_parity_err++;
104*3833Sxw161283
105*3833Sxw161283 if (cause & F_PM_E2C_WRT_FULL)
106*3833Sxw161283 ulp->intr_counts.pm_e2c_fifo_write_full_err++;
107*3833Sxw161283
108*3833Sxw161283 if (cause & F_PM_C2E_WRT_FULL)
109*3833Sxw161283 ulp->intr_counts.pm_c2e_fifo_write_full_err++;
110*3833Sxw161283
111*3833Sxw161283 if (cause & ULP_INTR_MASK)
112*3833Sxw161283 t1_fatal_err(ulp->adapter);
113*3833Sxw161283
114*3833Sxw161283 /* Clear status */
115*3833Sxw161283 t1_write_reg_4(ulp->adapter, A_ULP_INT_CAUSE, cause);
116*3833Sxw161283 return 0;
117*3833Sxw161283 }
118*3833Sxw161283
t1_ulp_init(struct peulp * ulp,unsigned int pm_tx_base)119*3833Sxw161283 int t1_ulp_init(struct peulp *ulp, unsigned int pm_tx_base)
120*3833Sxw161283 {
121*3833Sxw161283 int i;
122*3833Sxw161283 adapter_t *adapter = ulp->adapter;
123*3833Sxw161283
124*3833Sxw161283 /*
125*3833Sxw161283 * Initialize ULP Region Table.
126*3833Sxw161283 *
127*3833Sxw161283 * The region table memory has read enable tied to one, so data is
128*3833Sxw161283 * read out every cycle. The address to this memory is not defined
129*3833Sxw161283 * at reset and gets set first time when first ulp pdu is handled.
130*3833Sxw161283 * So after reset an undefined location is accessed, and since it is
131*3833Sxw161283 * read before any meaningful data is written to it there can be a
132*3833Sxw161283 * parity error.
133*3833Sxw161283 */
134*3833Sxw161283 for (i = 0; i < 256; i++) {
135*3833Sxw161283 t1_write_reg_4(adapter, A_ULP_HREG_INDEX, i);
136*3833Sxw161283 t1_write_reg_4(adapter, A_ULP_HREG_DATA, 0);
137*3833Sxw161283 }
138*3833Sxw161283
139*3833Sxw161283 t1_write_reg_4(adapter, A_ULP_ULIMIT, pm_tx_base);
140*3833Sxw161283 t1_write_reg_4(adapter, A_ULP_TAGMASK, (pm_tx_base << 1) - 1);
141*3833Sxw161283
142*3833Sxw161283 if (!t1_is_T1B(adapter)) {
143*3833Sxw161283 /* region table is not used */
144*3833Sxw161283 t1_write_reg_4(adapter, A_ULP_HREG_INDEX, 0);
145*3833Sxw161283 /* enable page size in pagepod */
146*3833Sxw161283 t1_write_reg_4(adapter, A_ULP_PIO_CTRL, 1);
147*3833Sxw161283 }
148*3833Sxw161283 return 0;
149*3833Sxw161283 }
150*3833Sxw161283
t1_ulp_create(adapter_t * adapter)151*3833Sxw161283 struct peulp *t1_ulp_create(adapter_t *adapter)
152*3833Sxw161283 {
153*3833Sxw161283 struct peulp *ulp = t1_os_malloc_wait_zero(sizeof(*ulp));
154*3833Sxw161283
155*3833Sxw161283 if (ulp)
156*3833Sxw161283 ulp->adapter = adapter;
157*3833Sxw161283 return ulp;
158*3833Sxw161283 }
159*3833Sxw161283
t1_ulp_destroy(struct peulp * ulp)160*3833Sxw161283 void t1_ulp_destroy(struct peulp * ulp)
161*3833Sxw161283 {
162*3833Sxw161283 t1_os_free((void *)ulp, sizeof(*ulp));
163*3833Sxw161283 }
164*3833Sxw161283
t1_ulp_get_intr_counts(struct peulp * ulp)165*3833Sxw161283 const struct ulp_intr_counts *t1_ulp_get_intr_counts(struct peulp *ulp)
166*3833Sxw161283 {
167*3833Sxw161283 return &ulp->intr_counts;
168*3833Sxw161283 }
169