Staging: et1310: kill pAdapter in favour of a sane name
[safe/jmp/linux-2.6] / drivers / staging / et131x / et131x_config.c
1 /*
2  * Agere Systems Inc.
3  * 10/100/1000 Base-T Ethernet Driver for the ET1301 and ET131x series MACs
4  *
5  * Copyright © 2005 Agere Systems Inc.
6  * All rights reserved.
7  *   http://www.agere.com
8  *
9  *------------------------------------------------------------------------------
10  *
11  * et131x_config.c - Handles parsing of configuration data during
12  *                   initialization.
13  *
14  *------------------------------------------------------------------------------
15  *
16  * SOFTWARE LICENSE
17  *
18  * This software is provided subject to the following terms and conditions,
19  * which you should read carefully before using the software.  Using this
20  * software indicates your acceptance of these terms and conditions.  If you do
21  * not agree with these terms and conditions, do not use the software.
22  *
23  * Copyright © 2005 Agere Systems Inc.
24  * All rights reserved.
25  *
26  * Redistribution and use in source or binary forms, with or without
27  * modifications, are permitted provided that the following conditions are met:
28  *
29  * . Redistributions of source code must retain the above copyright notice, this
30  *    list of conditions and the following Disclaimer as comments in the code as
31  *    well as in the documentation and/or other materials provided with the
32  *    distribution.
33  *
34  * . Redistributions in binary form must reproduce the above copyright notice,
35  *    this list of conditions and the following Disclaimer in the documentation
36  *    and/or other materials provided with the distribution.
37  *
38  * . Neither the name of Agere Systems Inc. nor the names of the contributors
39  *    may be used to endorse or promote products derived from this software
40  *    without specific prior written permission.
41  *
42  * Disclaimer
43  *
44  * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
45  * INCLUDING, BUT NOT LIMITED TO, INFRINGEMENT AND THE IMPLIED WARRANTIES OF
46  * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.  ANY
47  * USE, MODIFICATION OR DISTRIBUTION OF THIS SOFTWARE IS SOLELY AT THE USERS OWN
48  * RISK. IN NO EVENT SHALL AGERE SYSTEMS INC. OR CONTRIBUTORS BE LIABLE FOR ANY
49  * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
50  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
51  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
52  * ON ANY THEORY OF LIABILITY, INCLUDING, BUT NOT LIMITED TO, CONTRACT, STRICT
53  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
54  * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
55  * DAMAGE.
56  *
57  */
58
59 #include "et131x_version.h"
60 #include "et131x_debug.h"
61 #include "et131x_defs.h"
62
63 #include <linux/init.h>
64 #include <linux/module.h>
65 #include <linux/types.h>
66 #include <linux/kernel.h>
67
68 #include <linux/sched.h>
69 #include <linux/ptrace.h>
70 #include <linux/slab.h>
71 #include <linux/ctype.h>
72 #include <linux/string.h>
73 #include <linux/timer.h>
74 #include <linux/interrupt.h>
75 #include <linux/in.h>
76 #include <linux/delay.h>
77 #include <linux/io.h>
78 #include <linux/bitops.h>
79 #include <asm/system.h>
80
81 #include <linux/netdevice.h>
82 #include <linux/etherdevice.h>
83 #include <linux/skbuff.h>
84 #include <linux/if_arp.h>
85 #include <linux/ioport.h>
86
87 #include "et1310_phy.h"
88 #include "et1310_pm.h"
89 #include "et1310_jagcore.h"
90
91 #include "et131x_adapter.h"
92 #include "et131x_initpci.h"
93 #include "et131x_config.h"
94
95 #include "et1310_tx.h"
96
97 /* Data for debugging facilities */
98 #ifdef CONFIG_ET131X_DEBUG
99 extern dbg_info_t *et131x_dbginfo;
100 #endif /* CONFIG_ET131X_DEBUG */
101
102 /* Defines for Parameter Default/Min/Max vaules */
103 #define PARM_SPEED_DUPLEX_DEF   0
104 #define PARM_SPEED_DUPLEX_MIN   0
105 #define PARM_SPEED_DUPLEX_MAX   5
106
107 #define PARM_VLAN_TAG_DEF       0
108 #define PARM_VLAN_TAG_MIN       0
109 #define PARM_VLAN_TAG_MAX       4095
110
111 #define PARM_FLOW_CTL_DEF       0
112 #define PARM_FLOW_CTL_MIN       0
113 #define PARM_FLOW_CTL_MAX       3
114
115 #define PARM_WOL_LINK_DEF       3
116 #define PARM_WOL_LINK_MIN       0
117 #define PARM_WOL_LINK_MAX       3
118
119 #define PARM_WOL_MATCH_DEF      7
120 #define PARM_WOL_MATCH_MIN      0
121 #define PARM_WOL_MATCH_MAX      7
122
123 #define PARM_JUMBO_PKT_DEF      1514
124 #define PARM_JUMBO_PKT_MIN      1514
125 #define PARM_JUMBO_PKT_MAX      9216
126
127 #define PARM_PHY_COMA_DEF       0
128 #define PARM_PHY_COMA_MIN       0
129 #define PARM_PHY_COMA_MAX       1
130
131 #define PARM_RX_NUM_BUFS_DEF    4
132 #define PARM_RX_NUM_BUFS_MIN    1
133 #define PARM_RX_NUM_BUFS_MAX    64
134
135 #define PARM_RX_TIME_INT_DEF    10
136 #define PARM_RX_TIME_INT_MIN    2
137 #define PARM_RX_TIME_INT_MAX    320
138
139 #define PARM_TX_NUM_BUFS_DEF    4
140 #define PARM_TX_NUM_BUFS_MIN    1
141 #define PARM_TX_NUM_BUFS_MAX    40
142
143 #define PARM_TX_TIME_INT_DEF    40
144 #define PARM_TX_TIME_INT_MIN    1
145 #define PARM_TX_TIME_INT_MAX    140
146
147 #define PARM_RX_MEM_END_DEF     0x2bc
148 #define PARM_RX_MEM_END_MIN     0
149 #define PARM_RX_MEM_END_MAX     0x3ff
150
151 #define PARM_MAC_STAT_DEF       1
152 #define PARM_MAC_STAT_MIN       0
153 #define PARM_MAC_STAT_MAX       1
154
155 #define PARM_SC_GAIN_DEF        7
156 #define PARM_SC_GAIN_MIN        0
157 #define PARM_SC_GAIN_MAX        7
158
159 #define PARM_PM_WOL_DEF         0
160 #define PARM_PM_WOL_MIN         0
161 #define PARM_PM_WOL_MAX         1
162
163 #define PARM_NMI_DISABLE_DEF    0
164 #define PARM_NMI_DISABLE_MIN    0
165 #define PARM_NMI_DISABLE_MAX    2
166
167 #define PARM_DMA_CACHE_DEF      0
168 #define PARM_DMA_CACHE_MIN      0
169 #define PARM_DMA_CACHE_MAX      15
170
171 #define PARM_PHY_LOOPBK_DEF     0
172 #define PARM_PHY_LOOPBK_MIN     0
173 #define PARM_PHY_LOOPBK_MAX     1
174
175 #define PARM_MAC_ADDRESS_DEF    { 0x00, 0x05, 0x3d, 0x00, 0x02, 0x00 }
176
177 /* Module parameter for disabling NMI
178  * et131x_speed_set :
179  * Set Link speed and dublex manually (0-5)  [0]
180  *  1 : 10Mb   Half-Duplex
181  *  2 : 10Mb   Full-Duplex
182  *  3 : 100Mb  Half-Duplex
183  *  4 : 100Mb  Full-Duplex
184  *  5 : 1000Mb Full-Duplex
185  *  0 : Auto Speed Auto Dublex // default
186  */
187 static u32 et131x_nmi_disable = PARM_NMI_DISABLE_DEF;
188 module_param(et131x_nmi_disable, uint, 0);
189 MODULE_PARM_DESC(et131x_nmi_disable, "Disable NMI (0-2) [0]");
190
191 /* Module parameter for manual speed setting
192  * et131x_nmi_disable :
193  * Disable NMI (0-2) [0]
194  *  0 :
195  *  1 :
196  *  2 :
197  */
198 static u32 et131x_speed_set = PARM_SPEED_DUPLEX_DEF;
199 module_param(et131x_speed_set, uint, 0);
200 MODULE_PARM_DESC(et131x_speed_set,
201                 "Set Link speed and dublex manually (0-5)  [0] \n  1 : 10Mb   Half-Duplex \n  2 : 10Mb   Full-Duplex \n  3 : 100Mb  Half-Duplex \n  4 : 100Mb  Full-Duplex \n  5 : 1000Mb Full-Duplex \n 0 : Auto Speed Auto Dublex");
202
203 /**
204  * et131x_config_parse
205  * @etdev: pointer to the private adapter struct
206  *
207  * Parses a configuration from some location (module parameters, for example)
208  * into the private adapter struct
209  */
210 void et131x_config_parse(struct et131x_adapter *etdev)
211 {
212         uint8_t macAddrDef[] = PARM_MAC_ADDRESS_DEF;
213
214         DBG_ENTER(et131x_dbginfo);
215
216         /*
217          * The NDIS driver uses the registry to store persistent per-device
218          * configuration, and reads this configuration into the appropriate
219          * elements of the private adapter structure on initialization.
220          * Because Linux has no analog to the registry, use this function to
221          * initialize the private adapter structure with a default
222          * configuration.
223          *
224          * One other possibility is to use a series of module parameters which
225          * can be passed in by the caller when the module is initialized.
226          * However, this implementation does not allow for seperate
227          * configurations in the event multiple devices are present, and hence
228          * will not suffice.
229          *
230          * If another method is derived which addresses this problem, this is
231          * where it should be implemented.
232          */
233
234          /* Set the private adapter struct with default values for the
235           * corresponding parameters
236           */
237         if (et131x_speed_set != PARM_SPEED_DUPLEX_DEF) {
238                 DBG_VERBOSE(et131x_dbginfo, "Speed set manually to : %d \n",
239                             et131x_speed_set);
240                 etdev->SpeedDuplex = et131x_speed_set;
241         } else {
242                 etdev->SpeedDuplex = PARM_SPEED_DUPLEX_DEF;
243         }
244
245         /*  etdev->SpeedDuplex            = PARM_SPEED_DUPLEX_DEF; */
246
247         etdev->RegistryVlanTag = PARM_VLAN_TAG_DEF;
248         etdev->RegistryFlowControl = PARM_FLOW_CTL_DEF;
249         etdev->RegistryWOLLink = PARM_WOL_LINK_DEF;
250         etdev->RegistryWOLMatch = PARM_WOL_MATCH_DEF;
251         etdev->RegistryJumboPacket = PARM_JUMBO_PKT_DEF;
252         etdev->RegistryPhyComa = PARM_PHY_COMA_DEF;
253         etdev->RegistryRxNumBuffers = PARM_RX_NUM_BUFS_DEF;
254         etdev->RegistryRxTimeInterval = PARM_RX_TIME_INT_DEF;
255         etdev->RegistryTxNumBuffers = PARM_TX_NUM_BUFS_DEF;
256         etdev->RegistryTxTimeInterval = PARM_TX_TIME_INT_DEF;
257         etdev->RegistryRxMemEnd = PARM_RX_MEM_END_DEF;
258         etdev->RegistryMACStat = PARM_MAC_STAT_DEF;
259         etdev->RegistrySCGain = PARM_SC_GAIN_DEF;
260         etdev->RegistryPMWOL = PARM_PM_WOL_DEF;
261
262         if (et131x_nmi_disable != PARM_NMI_DISABLE_DEF)
263                 etdev->RegistryNMIDisable = et131x_nmi_disable;
264         else
265                 etdev->RegistryNMIDisable = PARM_NMI_DISABLE_DEF;
266
267         etdev->RegistryDMACache = PARM_DMA_CACHE_DEF;
268         etdev->RegistryPhyLoopbk = PARM_PHY_LOOPBK_DEF;
269
270         /* Set the MAC address to a default */
271         memcpy(etdev->CurrentAddress, macAddrDef, ETH_ALEN);
272         etdev->bOverrideAddress = false;
273
274         DBG_TRACE(et131x_dbginfo,
275                   "Default MAC Address  : %02x:%02x:%02x:%02x:%02x:%02x\n",
276                   etdev->CurrentAddress[0], etdev->CurrentAddress[1],
277                   etdev->CurrentAddress[2], etdev->CurrentAddress[3],
278                   etdev->CurrentAddress[4], etdev->CurrentAddress[5]);
279
280         /* Decode SpeedDuplex
281          *
282          * Set up as if we are auto negotiating always and then change if we
283          * go into force mode
284          */
285         etdev->AiForceSpeed = 0;        /* Auto speed */
286         etdev->AiForceDpx = 0;  /* Auto FDX */
287
288         /* If we are the 10/100 device, and gigabit is somehow requested then
289          * knock it down to 100 full.
290          */
291         if (etdev->DeviceID == ET131X_PCI_DEVICE_ID_FAST &&
292             etdev->SpeedDuplex == 5)
293                 etdev->SpeedDuplex = 4;
294
295         switch (etdev->SpeedDuplex) {
296         case 1:         /* 10Mb   Half-Duplex */
297                 etdev->AiForceSpeed = 10;
298                 etdev->AiForceDpx = 1;
299                 break;
300
301         case 2:         /* 10Mb   Full-Duplex */
302                 etdev->AiForceSpeed = 10;
303                 etdev->AiForceDpx = 2;
304                 break;
305
306         case 3:         /* 100Mb  Half-Duplex */
307                 etdev->AiForceSpeed = 100;
308                 etdev->AiForceDpx = 1;
309                 break;
310
311         case 4:         /* 100Mb  Full-Duplex */
312                 etdev->AiForceSpeed = 100;
313                 etdev->AiForceDpx = 2;
314                 break;
315
316         case 5:         /* 1000Mb Full-Duplex */
317                 etdev->AiForceSpeed = 1000;
318                 etdev->AiForceDpx = 2;
319                 break;
320         }
321
322         DBG_LEAVE(et131x_dbginfo);
323 }