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