Staging: et131x: eliminate write only registry fields
[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 <linux/pci.h>
80 #include <asm/system.h>
81
82 #include <linux/netdevice.h>
83 #include <linux/etherdevice.h>
84 #include <linux/skbuff.h>
85 #include <linux/if_arp.h>
86 #include <linux/ioport.h>
87
88 #include "et1310_phy.h"
89 #include "et1310_pm.h"
90 #include "et1310_jagcore.h"
91
92 #include "et131x_adapter.h"
93 #include "et131x_initpci.h"
94 #include "et131x_config.h"
95
96 #include "et1310_tx.h"
97
98 /* Data for debugging facilities */
99 #ifdef CONFIG_ET131X_DEBUG
100 extern dbg_info_t *et131x_dbginfo;
101 #endif /* CONFIG_ET131X_DEBUG */
102
103 /* Defines for Parameter Default/Min/Max vaules */
104 #define PARM_SPEED_DUPLEX_DEF   0
105 #define PARM_SPEED_DUPLEX_MIN   0
106 #define PARM_SPEED_DUPLEX_MAX   5
107
108 #define PARM_VLAN_TAG_DEF       0
109 #define PARM_VLAN_TAG_MIN       0
110 #define PARM_VLAN_TAG_MAX       4095
111
112 #define PARM_FLOW_CTL_DEF       0
113 #define PARM_FLOW_CTL_MIN       0
114 #define PARM_FLOW_CTL_MAX       3
115
116 #define PARM_WOL_LINK_DEF       3
117 #define PARM_WOL_LINK_MIN       0
118 #define PARM_WOL_LINK_MAX       3
119
120 #define PARM_WOL_MATCH_DEF      7
121 #define PARM_WOL_MATCH_MIN      0
122 #define PARM_WOL_MATCH_MAX      7
123
124 #define PARM_JUMBO_PKT_DEF      1514
125 #define PARM_JUMBO_PKT_MIN      1514
126 #define PARM_JUMBO_PKT_MAX      9216
127
128 #define PARM_PHY_COMA_DEF       0
129 #define PARM_PHY_COMA_MIN       0
130 #define PARM_PHY_COMA_MAX       1
131
132 #define PARM_RX_NUM_BUFS_DEF    4
133 #define PARM_RX_NUM_BUFS_MIN    1
134 #define PARM_RX_NUM_BUFS_MAX    64
135
136 #define PARM_RX_TIME_INT_DEF    10
137 #define PARM_RX_TIME_INT_MIN    2
138 #define PARM_RX_TIME_INT_MAX    320
139
140 #define PARM_TX_NUM_BUFS_DEF    4
141 #define PARM_TX_NUM_BUFS_MIN    1
142 #define PARM_TX_NUM_BUFS_MAX    40
143
144 #define PARM_TX_TIME_INT_DEF    40
145 #define PARM_TX_TIME_INT_MIN    1
146 #define PARM_TX_TIME_INT_MAX    140
147
148 #define PARM_RX_MEM_END_DEF     0x2bc
149 #define PARM_RX_MEM_END_MIN     0
150 #define PARM_RX_MEM_END_MAX     0x3ff
151
152 #define PARM_MAC_STAT_DEF       1
153 #define PARM_MAC_STAT_MIN       0
154 #define PARM_MAC_STAT_MAX       1
155
156 #define PARM_SC_GAIN_DEF        7
157 #define PARM_SC_GAIN_MIN        0
158 #define PARM_SC_GAIN_MAX        7
159
160 #define PARM_PM_WOL_DEF         0
161 #define PARM_PM_WOL_MIN         0
162 #define PARM_PM_WOL_MAX         1
163
164 #define PARM_NMI_DISABLE_DEF    0
165 #define PARM_NMI_DISABLE_MIN    0
166 #define PARM_NMI_DISABLE_MAX    2
167
168 #define PARM_DMA_CACHE_DEF      0
169 #define PARM_DMA_CACHE_MIN      0
170 #define PARM_DMA_CACHE_MAX      15
171
172 #define PARM_PHY_LOOPBK_DEF     0
173 #define PARM_PHY_LOOPBK_MIN     0
174 #define PARM_PHY_LOOPBK_MAX     1
175
176 #define PARM_MAC_ADDRESS_DEF    { 0x00, 0x05, 0x3d, 0x00, 0x02, 0x00 }
177
178 /* Module parameter for disabling NMI
179  * et131x_speed_set :
180  * Set Link speed and dublex manually (0-5)  [0]
181  *  1 : 10Mb   Half-Duplex
182  *  2 : 10Mb   Full-Duplex
183  *  3 : 100Mb  Half-Duplex
184  *  4 : 100Mb  Full-Duplex
185  *  5 : 1000Mb Full-Duplex
186  *  0 : Auto Speed Auto Dublex // default
187  */
188 static u32 et131x_nmi_disable = PARM_NMI_DISABLE_DEF;
189 module_param(et131x_nmi_disable, uint, 0);
190 MODULE_PARM_DESC(et131x_nmi_disable, "Disable NMI (0-2) [0]");
191
192 /* Module parameter for manual speed setting
193  * et131x_nmi_disable :
194  * Disable NMI (0-2) [0]
195  *  0 :
196  *  1 :
197  *  2 :
198  */
199 static u32 et131x_speed_set = PARM_SPEED_DUPLEX_DEF;
200 module_param(et131x_speed_set, uint, 0);
201 MODULE_PARM_DESC(et131x_speed_set,
202                 "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");
203
204 /**
205  * et131x_config_parse
206  * @etdev: pointer to the private adapter struct
207  *
208  * Parses a configuration from some location (module parameters, for example)
209  * into the private adapter struct
210  */
211 void et131x_config_parse(struct et131x_adapter *etdev)
212 {
213         uint8_t macAddrDef[] = PARM_MAC_ADDRESS_DEF;
214
215         DBG_ENTER(et131x_dbginfo);
216
217         /*
218          * The NDIS driver uses the registry to store persistent per-device
219          * configuration, and reads this configuration into the appropriate
220          * elements of the private adapter structure on initialization.
221          * Because Linux has no analog to the registry, use this function to
222          * initialize the private adapter structure with a default
223          * configuration.
224          *
225          * One other possibility is to use a series of module parameters which
226          * can be passed in by the caller when the module is initialized.
227          * However, this implementation does not allow for seperate
228          * configurations in the event multiple devices are present, and hence
229          * will not suffice.
230          *
231          * If another method is derived which addresses this problem, this is
232          * where it should be implemented.
233          */
234
235          /* Set the private adapter struct with default values for the
236           * corresponding parameters
237           */
238         if (et131x_speed_set != PARM_SPEED_DUPLEX_DEF) {
239                 DBG_VERBOSE(et131x_dbginfo, "Speed set manually to : %d \n",
240                             et131x_speed_set);
241                 etdev->SpeedDuplex = et131x_speed_set;
242         } else {
243                 etdev->SpeedDuplex = PARM_SPEED_DUPLEX_DEF;
244         }
245
246         /*  etdev->SpeedDuplex            = PARM_SPEED_DUPLEX_DEF; */
247
248         etdev->RegistryVlanTag = PARM_VLAN_TAG_DEF;
249         etdev->RegistryFlowControl = PARM_FLOW_CTL_DEF;
250         etdev->RegistryJumboPacket = PARM_JUMBO_PKT_DEF;
251         etdev->RegistryPhyComa = PARM_PHY_COMA_DEF;
252         etdev->RegistryRxNumBuffers = PARM_RX_NUM_BUFS_DEF;
253         etdev->RegistryRxTimeInterval = PARM_RX_TIME_INT_DEF;
254         etdev->RegistryTxNumBuffers = PARM_TX_NUM_BUFS_DEF;
255         etdev->RegistryTxTimeInterval = PARM_TX_TIME_INT_DEF;
256         etdev->RegistryRxMemEnd = PARM_RX_MEM_END_DEF;
257         etdev->RegistryMACStat = PARM_MAC_STAT_DEF;
258
259         if (et131x_nmi_disable != PARM_NMI_DISABLE_DEF)
260                 etdev->RegistryNMIDisable = et131x_nmi_disable;
261         else
262                 etdev->RegistryNMIDisable = PARM_NMI_DISABLE_DEF;
263
264         etdev->RegistryPhyLoopbk = PARM_PHY_LOOPBK_DEF;
265
266         /* Set the MAC address to a default */
267         memcpy(etdev->CurrentAddress, macAddrDef, ETH_ALEN);
268         etdev->bOverrideAddress = false;
269
270         DBG_TRACE(et131x_dbginfo,
271                   "Default MAC Address  : %02x:%02x:%02x:%02x:%02x:%02x\n",
272                   etdev->CurrentAddress[0], etdev->CurrentAddress[1],
273                   etdev->CurrentAddress[2], etdev->CurrentAddress[3],
274                   etdev->CurrentAddress[4], etdev->CurrentAddress[5]);
275
276         /* Decode SpeedDuplex
277          *
278          * Set up as if we are auto negotiating always and then change if we
279          * go into force mode
280          */
281         etdev->AiForceSpeed = 0;        /* Auto speed */
282         etdev->AiForceDpx = 0;  /* Auto FDX */
283
284         /* If we are the 10/100 device, and gigabit is somehow requested then
285          * knock it down to 100 full.
286          */
287         if (etdev->pdev->device == ET131X_PCI_DEVICE_ID_FAST &&
288             etdev->SpeedDuplex == 5)
289                 etdev->SpeedDuplex = 4;
290
291         switch (etdev->SpeedDuplex) {
292         case 1:         /* 10Mb   Half-Duplex */
293                 etdev->AiForceSpeed = 10;
294                 etdev->AiForceDpx = 1;
295                 break;
296
297         case 2:         /* 10Mb   Full-Duplex */
298                 etdev->AiForceSpeed = 10;
299                 etdev->AiForceDpx = 2;
300                 break;
301
302         case 3:         /* 100Mb  Half-Duplex */
303                 etdev->AiForceSpeed = 100;
304                 etdev->AiForceDpx = 1;
305                 break;
306
307         case 4:         /* 100Mb  Full-Duplex */
308                 etdev->AiForceSpeed = 100;
309                 etdev->AiForceDpx = 2;
310                 break;
311
312         case 5:         /* 1000Mb Full-Duplex */
313                 etdev->AiForceSpeed = 1000;
314                 etdev->AiForceDpx = 2;
315                 break;
316         }
317
318         DBG_LEAVE(et131x_dbginfo);
319 }