2 * Copyright(c) 2007 Atheros Corporation. All rights reserved.
4 * Derived from Intel e1000 driver
5 * Copyright(c) 1999 - 2005 Intel Corporation. All rights reserved.
7 * This program is free software; you can redistribute it and/or modify it
8 * under the terms of the GNU General Public License as published by the Free
9 * Software Foundation; either version 2 of the License, or (at your option)
12 * This program is distributed in the hope that it will be useful, but WITHOUT
13 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
17 * You should have received a copy of the GNU General Public License along with
18 * this program; if not, write to the Free Software Foundation, Inc., 59
19 * Temple Place - Suite 330, Boston, MA 02111-1307, USA.
22 #include <linux/netdevice.h>
26 /* This is the only thing that needs to be changed to adjust the
27 * maximum number of ports that the driver can manage.
30 #define ATL1E_MAX_NIC 32
32 #define OPTION_UNSET -1
33 #define OPTION_DISABLED 0
34 #define OPTION_ENABLED 1
36 /* All parameters are treated the same, as an integer array of values.
37 * This macro just reduces the need to repeat the same declaration code
38 * over and over (plus this helps to avoid typo bugs).
40 #define ATL1E_PARAM_INIT { [0 ... ATL1E_MAX_NIC] = OPTION_UNSET }
42 #define ATL1E_PARAM(x, desc) \
43 static int __devinitdata x[ATL1E_MAX_NIC + 1] = ATL1E_PARAM_INIT; \
44 static unsigned int num_##x; \
45 module_param_array_named(x, x, int, &num_##x, 0); \
46 MODULE_PARM_DESC(x, desc);
48 /* Transmit Memory count
50 * Valid Range: 64-2048
54 #define ATL1E_MIN_TX_DESC_CNT 32
55 #define ATL1E_MAX_TX_DESC_CNT 1020
56 #define ATL1E_DEFAULT_TX_DESC_CNT 128
57 ATL1E_PARAM(tx_desc_cnt, "Transmit description count");
59 /* Receive Memory Block Count
65 #define ATL1E_MIN_RX_MEM_SIZE 8 /* 8KB */
66 #define ATL1E_MAX_RX_MEM_SIZE 1024 /* 1MB */
67 #define ATL1E_DEFAULT_RX_MEM_SIZE 256 /* 128KB */
68 ATL1E_PARAM(rx_mem_size, "memory size of rx buffer(KB)");
70 /* User Specified MediaType Override
73 * - 0 - auto-negotiate at all supported speeds
74 * - 1 - only link at 100Mbps Full Duplex
75 * - 2 - only link at 100Mbps Half Duplex
76 * - 3 - only link at 10Mbps Full Duplex
77 * - 4 - only link at 10Mbps Half Duplex
81 ATL1E_PARAM(media_type, "MediaType Select");
83 /* Interrupt Moderate Timer in units of 2 us
85 * Valid Range: 10-65535
87 * Default Value: 45000(90ms)
89 #define INT_MOD_DEFAULT_CNT 100 /* 200us */
90 #define INT_MOD_MAX_CNT 65000
91 #define INT_MOD_MIN_CNT 50
92 ATL1E_PARAM(int_mod_timer, "Interrupt Moderator Timer");
94 #define AUTONEG_ADV_DEFAULT 0x2F
95 #define AUTONEG_ADV_MASK 0x2F
96 #define FLOW_CONTROL_DEFAULT FLOW_CONTROL_FULL
98 #define FLASH_VENDOR_DEFAULT 0
99 #define FLASH_VENDOR_MIN 0
100 #define FLASH_VENDOR_MAX 2
102 struct atl1e_option {
103 enum { enable_option, range_option, list_option } type;
108 struct { /* range_option info */
112 struct { /* list_option info */
114 struct atl1e_opt_list { int i; char *str; } *p;
119 static int __devinit atl1e_validate_option(int *value, struct atl1e_option *opt, struct pci_dev *pdev)
121 if (*value == OPTION_UNSET) {
130 dev_info(&pdev->dev, "%s Enabled\n", opt->name);
132 case OPTION_DISABLED:
133 dev_info(&pdev->dev, "%s Disabled\n", opt->name);
138 if (*value >= opt->arg.r.min && *value <= opt->arg.r.max) {
139 dev_info(&pdev->dev, "%s set to %i\n", opt->name, *value);
145 struct atl1e_opt_list *ent;
147 for (i = 0; i < opt->arg.l.nr; i++) {
148 ent = &opt->arg.l.p[i];
149 if (*value == ent->i) {
150 if (ent->str[0] != '\0')
151 dev_info(&pdev->dev, "%s\n",
162 dev_info(&pdev->dev, "Invalid %s specified (%i) %s\n",
163 opt->name, *value, opt->err);
169 * atl1e_check_options - Range Checking for Command Line Parameters
170 * @adapter: board private structure
172 * This routine checks all command line parameters for valid user
173 * input. If an invalid value is given, or if no user specified
174 * value exists, a default value is used. The final value is stored
175 * in a variable in the adapter structure.
177 void __devinit atl1e_check_options(struct atl1e_adapter *adapter)
179 struct pci_dev *pdev = adapter->pdev;
180 int bd = adapter->bd_number;
181 if (bd >= ATL1E_MAX_NIC) {
182 dev_notice(&pdev->dev, "no configuration for board #%i\n", bd);
183 dev_notice(&pdev->dev, "Using defaults for all values\n");
186 { /* Transmit Ring Size */
187 struct atl1e_option opt = {
188 .type = range_option,
189 .name = "Transmit Ddescription Count",
190 .err = "using default of "
191 __MODULE_STRING(ATL1E_DEFAULT_TX_DESC_CNT),
192 .def = ATL1E_DEFAULT_TX_DESC_CNT,
193 .arg = { .r = { .min = ATL1E_MIN_TX_DESC_CNT,
194 .max = ATL1E_MAX_TX_DESC_CNT} }
197 if (num_tx_desc_cnt > bd) {
198 val = tx_desc_cnt[bd];
199 atl1e_validate_option(&val, &opt, pdev);
200 adapter->tx_ring.count = (u16) val & 0xFFFC;
202 adapter->tx_ring.count = (u16)opt.def;
205 { /* Receive Memory Block Count */
206 struct atl1e_option opt = {
207 .type = range_option,
208 .name = "Memory size of rx buffer(KB)",
209 .err = "using default of "
210 __MODULE_STRING(ATL1E_DEFAULT_RX_MEM_SIZE),
211 .def = ATL1E_DEFAULT_RX_MEM_SIZE,
212 .arg = { .r = { .min = ATL1E_MIN_RX_MEM_SIZE,
213 .max = ATL1E_MAX_RX_MEM_SIZE} }
216 if (num_rx_mem_size > bd) {
217 val = rx_mem_size[bd];
218 atl1e_validate_option(&val, &opt, pdev);
219 adapter->rx_ring.page_size = (u32)val * 1024;
221 adapter->rx_ring.page_size = (u32)opt.def * 1024;
225 { /* Interrupt Moderate Timer */
226 struct atl1e_option opt = {
227 .type = range_option,
228 .name = "Interrupt Moderate Timer",
229 .err = "using default of "
230 __MODULE_STRING(INT_MOD_DEFAULT_CNT),
231 .def = INT_MOD_DEFAULT_CNT,
232 .arg = { .r = { .min = INT_MOD_MIN_CNT,
233 .max = INT_MOD_MAX_CNT} }
236 if (num_int_mod_timer > bd) {
237 val = int_mod_timer[bd];
238 atl1e_validate_option(&val, &opt, pdev);
239 adapter->hw.imt = (u16) val;
241 adapter->hw.imt = (u16)(opt.def);
245 struct atl1e_option opt = {
246 .type = range_option,
247 .name = "Speed/Duplex Selection",
248 .err = "using default of "
249 __MODULE_STRING(MEDIA_TYPE_AUTO_SENSOR),
250 .def = MEDIA_TYPE_AUTO_SENSOR,
251 .arg = { .r = { .min = MEDIA_TYPE_AUTO_SENSOR,
252 .max = MEDIA_TYPE_10M_HALF} }
255 if (num_media_type > bd) {
256 val = media_type[bd];
257 atl1e_validate_option(&val, &opt, pdev);
258 adapter->hw.media_type = (u16) val;
260 adapter->hw.media_type = (u16)(opt.def);