[PATCH] A new 10GB Ethernet Driver by Chelsio Communications
[linux-2.6] / drivers / net / chelsio / tp.c
1 /*****************************************************************************
2  *                                                                           *
3  * File: tp.c                                                                *
4  * $Revision: 1.6 $                                                          *
5  * $Date: 2005/03/23 07:15:59 $                                              *
6  * Description:                                                              *
7  *  Core ASIC Management.                                                    *
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   *
15  * with this program; if not, write to the Free Software Foundation, Inc.,   *
16  * 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.                 *
17  *                                                                           *
18  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED    *
19  * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF      *
20  * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.                     *
21  *                                                                           *
22  * http://www.chelsio.com                                                    *
23  *                                                                           *
24  * Copyright (c) 2003 - 2005 Chelsio Communications, Inc.                    *
25  * All rights reserved.                                                      *
26  *                                                                           *
27  * Maintainers: maintainers@chelsio.com                                      *
28  *                                                                           *
29  * Authors: Dimitrios Michailidis   <dm@chelsio.com>                         *
30  *          Tina Yang               <tainay@chelsio.com>                     *
31  *          Felix Marti             <felix@chelsio.com>                      *
32  *          Scott Bardone           <sbardone@chelsio.com>                   *
33  *          Kurt Ottaway            <kottaway@chelsio.com>                   *
34  *          Frank DiMambro          <frank@chelsio.com>                      *
35  *                                                                           *
36  * History:                                                                  *
37  *                                                                           *
38  ****************************************************************************/
39
40 #include "common.h"
41 #include "regs.h"
42 #include "tp.h"
43
44 struct petp {
45         adapter_t *adapter;
46 };
47
48 /* Pause deadlock avoidance parameters */
49 #define DROP_MSEC 16
50 #define DROP_PKTS_CNT  1
51
52
53 static void tp_init(adapter_t *ap, const struct tp_params *p,
54                     unsigned int tp_clk)
55 {
56         if (t1_is_asic(ap)) {
57                 u32 val;
58
59                 val = F_TP_IN_CSPI_CPL | F_TP_IN_CSPI_CHECK_IP_CSUM |
60                       F_TP_IN_CSPI_CHECK_TCP_CSUM | F_TP_IN_ESPI_ETHERNET;
61                 if (!p->pm_size)
62                         val |= F_OFFLOAD_DISABLE;
63                 else
64                         val |= F_TP_IN_ESPI_CHECK_IP_CSUM |
65                                 F_TP_IN_ESPI_CHECK_TCP_CSUM;
66                 t1_write_reg_4(ap, A_TP_IN_CONFIG, val);
67                 t1_write_reg_4(ap, A_TP_OUT_CONFIG, F_TP_OUT_CSPI_CPL |
68                                F_TP_OUT_ESPI_ETHERNET |
69                                F_TP_OUT_ESPI_GENERATE_IP_CSUM |
70                                F_TP_OUT_ESPI_GENERATE_TCP_CSUM);
71                 t1_write_reg_4(ap, A_TP_GLOBAL_CONFIG, V_IP_TTL(64) |
72                                F_PATH_MTU /* IP DF bit */ |
73                                V_5TUPLE_LOOKUP(p->use_5tuple_mode) |
74                                V_SYN_COOKIE_PARAMETER(29));
75
76                 /*
77                  * Enable pause frame deadlock prevention.
78                  */
79                 if (is_T2(ap)) {
80                         u32 drop_ticks = DROP_MSEC * (tp_clk / 1000);
81
82                         t1_write_reg_4(ap, A_TP_TX_DROP_CONFIG,
83                                        F_ENABLE_TX_DROP | F_ENABLE_TX_ERROR |
84                                        V_DROP_TICKS_CNT(drop_ticks) |
85                                        V_NUM_PKTS_DROPPED(DROP_PKTS_CNT));
86                 }
87
88         }
89 }
90
91 void t1_tp_destroy(struct petp *tp)
92 {
93         kfree(tp);
94 }
95
96 struct petp * __devinit t1_tp_create(adapter_t *adapter, struct tp_params *p)
97 {
98         struct petp *tp = kmalloc(sizeof(*tp), GFP_KERNEL);
99         if (!tp)
100                 return NULL;
101         memset(tp, 0, sizeof(*tp));
102         tp->adapter = adapter;
103
104         return tp;
105 }
106
107 void t1_tp_intr_enable(struct petp *tp)
108 {
109         u32 tp_intr = t1_read_reg_4(tp->adapter, A_PL_ENABLE);
110
111         {
112                 /* We don't use any TP interrupts */
113                 t1_write_reg_4(tp->adapter, A_TP_INT_ENABLE, 0);
114                 t1_write_reg_4(tp->adapter, A_PL_ENABLE,
115                                tp_intr | F_PL_INTR_TP);
116         }
117 }
118
119 void t1_tp_intr_disable(struct petp *tp)
120 {
121         u32 tp_intr = t1_read_reg_4(tp->adapter, A_PL_ENABLE);
122
123         {
124                 t1_write_reg_4(tp->adapter, A_TP_INT_ENABLE, 0);
125                 t1_write_reg_4(tp->adapter, A_PL_ENABLE,
126                                tp_intr & ~F_PL_INTR_TP);
127         }
128 }
129
130 void t1_tp_intr_clear(struct petp *tp)
131 {
132         t1_write_reg_4(tp->adapter, A_TP_INT_CAUSE, 0xffffffff);
133         t1_write_reg_4(tp->adapter, A_PL_CAUSE, F_PL_INTR_TP);
134 }
135
136 int t1_tp_intr_handler(struct petp *tp)
137 {
138         u32 cause;
139
140
141         cause = t1_read_reg_4(tp->adapter, A_TP_INT_CAUSE);
142         t1_write_reg_4(tp->adapter, A_TP_INT_CAUSE, cause);
143         return 0;
144 }
145
146 static void set_csum_offload(struct petp *tp, u32 csum_bit, int enable)
147 {
148         u32 val = t1_read_reg_4(tp->adapter, A_TP_GLOBAL_CONFIG);
149
150         if (enable)
151                 val |= csum_bit;
152         else
153                 val &= ~csum_bit;
154         t1_write_reg_4(tp->adapter, A_TP_GLOBAL_CONFIG, val);
155 }
156
157 void t1_tp_set_ip_checksum_offload(struct petp *tp, int enable)
158 {
159         set_csum_offload(tp, F_IP_CSUM, enable);
160 }
161
162 void t1_tp_set_udp_checksum_offload(struct petp *tp, int enable)
163 {
164         set_csum_offload(tp, F_UDP_CSUM, enable);
165 }
166
167 void t1_tp_set_tcp_checksum_offload(struct petp *tp, int enable)
168 {
169         set_csum_offload(tp, F_TCP_CSUM, enable);
170 }
171
172 /*
173  * Initialize TP state.  tp_params contains initial settings for some TP
174  * parameters, particularly the one-time PM and CM settings.
175  */
176 int t1_tp_reset(struct petp *tp, struct tp_params *p, unsigned int tp_clk)
177 {
178         int busy = 0;
179         adapter_t *adapter = tp->adapter;
180
181         tp_init(adapter, p, tp_clk);
182         if (!busy)
183                 t1_write_reg_4(adapter, A_TP_RESET, F_TP_RESET);
184         else
185                 CH_ERR("%s: TP initialization timed out\n",
186                        adapter->name);
187         return busy;
188 }