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 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 atl1e_validate_option(int *value
, struct atl1e_option
*opt
,
120 struct atl1e_adapter
*adapter
)
122 if (*value
== OPTION_UNSET
) {
131 netdev_info(adapter
->netdev
,
132 "%s Enabled\n", opt
->name
);
134 case OPTION_DISABLED
:
135 netdev_info(adapter
->netdev
,
136 "%s Disabled\n", opt
->name
);
141 if (*value
>= opt
->arg
.r
.min
&& *value
<= opt
->arg
.r
.max
) {
142 netdev_info(adapter
->netdev
, "%s set to %i\n",
149 struct atl1e_opt_list
*ent
;
151 for (i
= 0; i
< opt
->arg
.l
.nr
; i
++) {
152 ent
= &opt
->arg
.l
.p
[i
];
153 if (*value
== ent
->i
) {
154 if (ent
->str
[0] != '\0')
155 netdev_info(adapter
->netdev
,
166 netdev_info(adapter
->netdev
, "Invalid %s specified (%i) %s\n",
167 opt
->name
, *value
, opt
->err
);
173 * atl1e_check_options - Range Checking for Command Line Parameters
174 * @adapter: board private structure
176 * This routine checks all command line parameters for valid user
177 * input. If an invalid value is given, or if no user specified
178 * value exists, a default value is used. The final value is stored
179 * in a variable in the adapter structure.
181 void atl1e_check_options(struct atl1e_adapter
*adapter
)
183 int bd
= adapter
->bd_number
;
185 if (bd
>= ATL1E_MAX_NIC
) {
186 netdev_notice(adapter
->netdev
,
187 "no configuration for board #%i\n", bd
);
188 netdev_notice(adapter
->netdev
,
189 "Using defaults for all values\n");
192 { /* Transmit Ring Size */
193 struct atl1e_option opt
= {
194 .type
= range_option
,
195 .name
= "Transmit Ddescription Count",
196 .err
= "using default of "
197 __MODULE_STRING(ATL1E_DEFAULT_TX_DESC_CNT
),
198 .def
= ATL1E_DEFAULT_TX_DESC_CNT
,
199 .arg
= { .r
= { .min
= ATL1E_MIN_TX_DESC_CNT
,
200 .max
= ATL1E_MAX_TX_DESC_CNT
} }
203 if (num_tx_desc_cnt
> bd
) {
204 val
= tx_desc_cnt
[bd
];
205 atl1e_validate_option(&val
, &opt
, adapter
);
206 adapter
->tx_ring
.count
= (u16
) val
& 0xFFFC;
208 adapter
->tx_ring
.count
= (u16
)opt
.def
;
211 { /* Receive Memory Block Count */
212 struct atl1e_option opt
= {
213 .type
= range_option
,
214 .name
= "Memory size of rx buffer(KB)",
215 .err
= "using default of "
216 __MODULE_STRING(ATL1E_DEFAULT_RX_MEM_SIZE
),
217 .def
= ATL1E_DEFAULT_RX_MEM_SIZE
,
218 .arg
= { .r
= { .min
= ATL1E_MIN_RX_MEM_SIZE
,
219 .max
= ATL1E_MAX_RX_MEM_SIZE
} }
222 if (num_rx_mem_size
> bd
) {
223 val
= rx_mem_size
[bd
];
224 atl1e_validate_option(&val
, &opt
, adapter
);
225 adapter
->rx_ring
.page_size
= (u32
)val
* 1024;
227 adapter
->rx_ring
.page_size
= (u32
)opt
.def
* 1024;
231 { /* Interrupt Moderate Timer */
232 struct atl1e_option opt
= {
233 .type
= range_option
,
234 .name
= "Interrupt Moderate Timer",
235 .err
= "using default of "
236 __MODULE_STRING(INT_MOD_DEFAULT_CNT
),
237 .def
= INT_MOD_DEFAULT_CNT
,
238 .arg
= { .r
= { .min
= INT_MOD_MIN_CNT
,
239 .max
= INT_MOD_MAX_CNT
} }
242 if (num_int_mod_timer
> bd
) {
243 val
= int_mod_timer
[bd
];
244 atl1e_validate_option(&val
, &opt
, adapter
);
245 adapter
->hw
.imt
= (u16
) val
;
247 adapter
->hw
.imt
= (u16
)(opt
.def
);
251 struct atl1e_option opt
= {
252 .type
= range_option
,
253 .name
= "Speed/Duplex Selection",
254 .err
= "using default of "
255 __MODULE_STRING(MEDIA_TYPE_AUTO_SENSOR
),
256 .def
= MEDIA_TYPE_AUTO_SENSOR
,
257 .arg
= { .r
= { .min
= MEDIA_TYPE_AUTO_SENSOR
,
258 .max
= MEDIA_TYPE_10M_HALF
} }
261 if (num_media_type
> bd
) {
262 val
= media_type
[bd
];
263 atl1e_validate_option(&val
, &opt
, adapter
);
264 adapter
->hw
.media_type
= (u16
) val
;
266 adapter
->hw
.media_type
= (u16
)(opt
.def
);