aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/net/chelsio/tp.c
blob: 9ad5c539fd28ebb22b67b950c0d28a6be8a20110 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
/*****************************************************************************
 *                                                                           *
 * File: tp.c                                                                *
 * $Revision: 1.6 $                                                          *
 * $Date: 2005/03/23 07:15:59 $                                              *
 * Description:                                                              *
 *  Core ASIC Management.                                                    *
 *  part of the Chelsio 10Gb Ethernet Driver.                                *
 *                                                                           *
 * This program is free software; you can redistribute it and/or modify      *
 * it under the terms of the GNU General Public License, version 2, as       *
 * published by the Free Software Foundation.                                *
 *                                                                           *
 * You should have received a copy of the GNU General Public License along   *
 * with this program; if not, write to the Free Software Foundation, Inc.,   *
 * 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.                 *
 *                                                                           *
 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED    *
 * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF      *
 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.                     *
 *                                                                           *
 * http://www.chelsio.com                                                    *
 *                                                                           *
 * Copyright (c) 2003 - 2005 Chelsio Communications, Inc.                    *
 * All rights reserved.                                                      *
 *                                                                           *
 * Maintainers: maintainers@chelsio.com                                      *
 *                                                                           *
 * Authors: Dimitrios Michailidis   <dm@chelsio.com>                         *
 *          Tina Yang               <tainay@chelsio.com>                     *
 *          Felix Marti             <felix@chelsio.com>                      *
 *          Scott Bardone           <sbardone@chelsio.com>                   *
 *          Kurt Ottaway            <kottaway@chelsio.com>                   *
 *          Frank DiMambro          <frank@chelsio.com>                      *
 *                                                                           *
 * History:                                                                  *
 *                                                                           *
 ****************************************************************************/

#include "common.h"
#include "regs.h"
#include "tp.h"

struct petp {
	adapter_t *adapter;
};

/* Pause deadlock avoidance parameters */
#define DROP_MSEC 16
#define DROP_PKTS_CNT  1


static void tp_init(adapter_t *ap, const struct tp_params *p,
		    unsigned int tp_clk)
{
	if (t1_is_asic(ap)) {
		u32 val;

		val = F_TP_IN_CSPI_CPL | F_TP_IN_CSPI_CHECK_IP_CSUM |
		      F_TP_IN_CSPI_CHECK_TCP_CSUM | F_TP_IN_ESPI_ETHERNET;
		if (!p->pm_size)
			val |= F_OFFLOAD_DISABLE;
		else
			val |= F_TP_IN_ESPI_CHECK_IP_CSUM |
				F_TP_IN_ESPI_CHECK_TCP_CSUM;
		t1_write_reg_4(ap, A_TP_IN_CONFIG, val);
		t1_write_reg_4(ap, A_TP_OUT_CONFIG, F_TP_OUT_CSPI_CPL |
			       F_TP_OUT_ESPI_ETHERNET |
			       F_TP_OUT_ESPI_GENERATE_IP_CSUM |
			       F_TP_OUT_ESPI_GENERATE_TCP_CSUM);
		t1_write_reg_4(ap, A_TP_GLOBAL_CONFIG, V_IP_TTL(64) |
			       F_PATH_MTU /* IP DF bit */ |
			       V_5TUPLE_LOOKUP(p->use_5tuple_mode) |
			       V_SYN_COOKIE_PARAMETER(29));

		/*
		 * Enable pause frame deadlock prevention.
		 */
		if (is_T2(ap)) {
			u32 drop_ticks = DROP_MSEC * (tp_clk / 1000);

			t1_write_reg_4(ap, A_TP_TX_DROP_CONFIG,
				       F_ENABLE_TX_DROP | F_ENABLE_TX_ERROR |
				       V_DROP_TICKS_CNT(drop_ticks) |
				       V_NUM_PKTS_DROPPED(DROP_PKTS_CNT));
		}

	}
}

void t1_tp_destroy(struct petp *tp)
{
	kfree(tp);
}

struct petp * __devinit t1_tp_create(adapter_t *adapter, struct tp_params *p)
{
	struct petp *tp = kmalloc(sizeof(*tp), GFP_KERNEL);
	if (!tp)
		return NULL;
	memset(tp, 0, sizeof(*tp));
	tp->adapter = adapter;

	return tp;
}

void t1_tp_intr_enable(struct petp *tp)
{
	u32 tp_intr = t1_read_reg_4(tp->adapter, A_PL_ENABLE);

	{
		/* We don't use any TP interrupts */
		t1_write_reg_4(tp->adapter, A_TP_INT_ENABLE, 0);
		t1_write_reg_4(tp->adapter, A_PL_ENABLE,
			       tp_intr | F_PL_INTR_TP);
	}
}

void t1_tp_intr_disable(struct petp *tp)
{
	u32 tp_intr = t1_read_reg_4(tp->adapter, A_PL_ENABLE);

	{
		t1_write_reg_4(tp->adapter, A_TP_INT_ENABLE, 0);
		t1_write_reg_4(tp->adapter, A_PL_ENABLE,
			       tp_intr & ~F_PL_INTR_TP);
	}
}

void t1_tp_intr_clear(struct petp *tp)
{
	t1_write_reg_4(tp->adapter, A_TP_INT_CAUSE, 0xffffffff);
	t1_write_reg_4(tp->adapter, A_PL_CAUSE, F_PL_INTR_TP);
}

int t1_tp_intr_handler(struct petp *tp)
{
	u32 cause;


	cause = t1_read_reg_4(tp->adapter, A_TP_INT_CAUSE);
	t1_write_reg_4(tp->adapter, A_TP_INT_CAUSE, cause);
	return 0;
}

static void set_csum_offload(struct petp *tp, u32 csum_bit, int enable)
{
	u32 val = t1_read_reg_4(tp->adapter, A_TP_GLOBAL_CONFIG);

	if (enable)
		val |= csum_bit;
	else
		val &= ~csum_bit;
	t1_write_reg_4(tp->adapter, A_TP_GLOBAL_CONFIG, val);
}

void t1_tp_set_ip_checksum_offload(struct petp *tp, int enable)
{
	set_csum_offload(tp, F_IP_CSUM, enable);
}

void t1_tp_set_udp_checksum_offload(struct petp *tp, int enable)
{
	set_csum_offload(tp, F_UDP_CSUM, enable);
}

void t1_tp_set_tcp_checksum_offload(struct petp *tp, int enable)
{
	set_csum_offload(tp, F_TCP_CSUM, enable);
}

/*
 * Initialize TP state.  tp_params contains initial settings for some TP
 * parameters, particularly the one-time PM and CM settings.
 */
int t1_tp_reset(struct petp *tp, struct tp_params *p, unsigned int tp_clk)
{
	int busy = 0;
	adapter_t *adapter = tp->adapter;

	tp_init(adapter, p, tp_clk);
	if (!busy)
		t1_write_reg_4(adapter, A_TP_RESET, F_TP_RESET);
	else
		CH_ERR("%s: TP initialization timed out\n",
		       adapter->name);
	return busy;
}