2 * Copyright (C) 1999 - 2010 Intel Corporation.
3 * Copyright (C) 2010 OKI SEMICONDUCTOR Co., LTD.
5 * This code was derived from the Intel e1000e Linux driver.
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; version 2 of the License.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
22 #include <linux/module.h> /* for __MODULE_STRING */
24 #define OPTION_UNSET -1
25 #define OPTION_DISABLED 0
26 #define OPTION_ENABLED 1
29 * TxDescriptors - Transmit Descriptor Count
30 * @Valid Range: PCH_GBE_MIN_TXD - PCH_GBE_MAX_TXD
31 * @Default Value: PCH_GBE_DEFAULT_TXD
33 static int TxDescriptors
= OPTION_UNSET
;
34 module_param(TxDescriptors
, int, 0);
35 MODULE_PARM_DESC(TxDescriptors
, "Number of transmit descriptors");
38 * RxDescriptors -Receive Descriptor Count
39 * @Valid Range: PCH_GBE_MIN_RXD - PCH_GBE_MAX_RXD
40 * @Default Value: PCH_GBE_DEFAULT_RXD
42 static int RxDescriptors
= OPTION_UNSET
;
43 module_param(RxDescriptors
, int, 0);
44 MODULE_PARM_DESC(RxDescriptors
, "Number of receive descriptors");
47 * Speed - User Specified Speed Override
48 * @Valid Range: 0, 10, 100, 1000
49 * - 0: auto-negotiate at all supported speeds
50 * - 10: only link at 10 Mbps
51 * - 100: only link at 100 Mbps
52 * - 1000: only link at 1000 Mbps
55 static int Speed
= OPTION_UNSET
;
56 module_param(Speed
, int, 0);
57 MODULE_PARM_DESC(Speed
, "Speed setting");
60 * Duplex - User Specified Duplex Override
62 * - 0: auto-negotiate for duplex
63 * - 1: only link at half duplex
64 * - 2: only link at full duplex
67 static int Duplex
= OPTION_UNSET
;
68 module_param(Duplex
, int, 0);
69 MODULE_PARM_DESC(Duplex
, "Duplex setting");
75 * AutoNeg - Auto-negotiation Advertisement Override
76 * @Valid Range: 0x01-0x0F, 0x20-0x2F
78 * The AutoNeg value is a bit mask describing which speed and duplex
79 * combinations should be advertised during auto-negotiation.
80 * The supported speed and duplex modes are listed below
83 * Speed (Mbps) N/A N/A 1000 N/A 100 100 10 10
84 * Duplex Full Full Half Full Half
86 * @Default Value: 0x2F (copper)
88 static int AutoNeg
= OPTION_UNSET
;
89 module_param(AutoNeg
, int, 0);
90 MODULE_PARM_DESC(AutoNeg
, "Advertised auto-negotiation setting");
92 #define PHY_ADVERTISE_10_HALF 0x0001
93 #define PHY_ADVERTISE_10_FULL 0x0002
94 #define PHY_ADVERTISE_100_HALF 0x0004
95 #define PHY_ADVERTISE_100_FULL 0x0008
96 #define PHY_ADVERTISE_1000_HALF 0x0010 /* Not used, just FYI */
97 #define PHY_ADVERTISE_1000_FULL 0x0020
98 #define PCH_AUTONEG_ADVERTISE_DEFAULT 0x2F
101 * FlowControl - User Specified Flow Control Override
103 * - 0: No Flow Control
104 * - 1: Rx only, respond to PAUSE frames but do not generate them
105 * - 2: Tx only, generate PAUSE frames but ignore them on receive
106 * - 3: Full Flow Control Support
107 * @Default Value: Read flow control settings from the EEPROM
109 static int FlowControl
= OPTION_UNSET
;
110 module_param(FlowControl
, int, 0);
111 MODULE_PARM_DESC(FlowControl
, "Flow Control setting");
114 * XsumRX - Receive Checksum Offload Enable/Disable
116 * - 0: disables all checksum offload
117 * - 1: enables receive IP/TCP/UDP checksum offload
118 * @Default Value: PCH_GBE_DEFAULT_RX_CSUM
120 static int XsumRX
= OPTION_UNSET
;
121 module_param(XsumRX
, int, 0);
122 MODULE_PARM_DESC(XsumRX
, "Disable or enable Receive Checksum offload");
124 #define PCH_GBE_DEFAULT_RX_CSUM true /* trueorfalse */
127 * XsumTX - Transmit Checksum Offload Enable/Disable
129 * - 0: disables all checksum offload
130 * - 1: enables transmit IP/TCP/UDP checksum offload
131 * @Default Value: PCH_GBE_DEFAULT_TX_CSUM
133 static int XsumTX
= OPTION_UNSET
;
134 module_param(XsumTX
, int, 0);
135 MODULE_PARM_DESC(XsumTX
, "Disable or enable Transmit Checksum offload");
137 #define PCH_GBE_DEFAULT_TX_CSUM true /* trueorfalse */
140 * pch_gbe_option - Force the MAC's flow control settings
141 * @hw: Pointer to the HW structure
144 * Negative value: Failed.
146 struct pch_gbe_option
{
147 enum { enable_option
, range_option
, list_option
} type
;
152 struct { /* range_option info */
156 struct { /* list_option info */
158 const struct pch_gbe_opt_list
{ int i
; char *str
; } *p
;
163 static const struct pch_gbe_opt_list speed_list
[] = {
170 static const struct pch_gbe_opt_list dplx_list
[] = {
176 static const struct pch_gbe_opt_list an_list
[] =
177 #define AA "AutoNeg advertising "
178 {{ 0x01, AA
"10/HD" },
179 { 0x02, AA
"10/FD" },
180 { 0x03, AA
"10/FD, 10/HD" },
181 { 0x04, AA
"100/HD" },
182 { 0x05, AA
"100/HD, 10/HD" },
183 { 0x06, AA
"100/HD, 10/FD" },
184 { 0x07, AA
"100/HD, 10/FD, 10/HD" },
185 { 0x08, AA
"100/FD" },
186 { 0x09, AA
"100/FD, 10/HD" },
187 { 0x0a, AA
"100/FD, 10/FD" },
188 { 0x0b, AA
"100/FD, 10/FD, 10/HD" },
189 { 0x0c, AA
"100/FD, 100/HD" },
190 { 0x0d, AA
"100/FD, 100/HD, 10/HD" },
191 { 0x0e, AA
"100/FD, 100/HD, 10/FD" },
192 { 0x0f, AA
"100/FD, 100/HD, 10/FD, 10/HD" },
193 { 0x20, AA
"1000/FD" },
194 { 0x21, AA
"1000/FD, 10/HD" },
195 { 0x22, AA
"1000/FD, 10/FD" },
196 { 0x23, AA
"1000/FD, 10/FD, 10/HD" },
197 { 0x24, AA
"1000/FD, 100/HD" },
198 { 0x25, AA
"1000/FD, 100/HD, 10/HD" },
199 { 0x26, AA
"1000/FD, 100/HD, 10/FD" },
200 { 0x27, AA
"1000/FD, 100/HD, 10/FD, 10/HD" },
201 { 0x28, AA
"1000/FD, 100/FD" },
202 { 0x29, AA
"1000/FD, 100/FD, 10/HD" },
203 { 0x2a, AA
"1000/FD, 100/FD, 10/FD" },
204 { 0x2b, AA
"1000/FD, 100/FD, 10/FD, 10/HD" },
205 { 0x2c, AA
"1000/FD, 100/FD, 100/HD" },
206 { 0x2d, AA
"1000/FD, 100/FD, 100/HD, 10/HD" },
207 { 0x2e, AA
"1000/FD, 100/FD, 100/HD, 10/FD" },
208 { 0x2f, AA
"1000/FD, 100/FD, 100/HD, 10/FD, 10/HD" }
211 static const struct pch_gbe_opt_list fc_list
[] = {
212 { PCH_GBE_FC_NONE
, "Flow Control Disabled" },
213 { PCH_GBE_FC_RX_PAUSE
, "Flow Control Receive Only" },
214 { PCH_GBE_FC_TX_PAUSE
, "Flow Control Transmit Only" },
215 { PCH_GBE_FC_FULL
, "Flow Control Enabled" }
219 * pch_gbe_validate_option - Validate option
222 * @adapter: Board private structure
225 * Negative value: Failed.
227 static int pch_gbe_validate_option(int *value
,
228 const struct pch_gbe_option
*opt
,
229 struct pch_gbe_adapter
*adapter
)
231 if (*value
== OPTION_UNSET
) {
240 pr_debug("%s Enabled\n", opt
->name
);
242 case OPTION_DISABLED
:
243 pr_debug("%s Disabled\n", opt
->name
);
248 if (*value
>= opt
->arg
.r
.min
&& *value
<= opt
->arg
.r
.max
) {
249 pr_debug("%s set to %i\n", opt
->name
, *value
);
255 const struct pch_gbe_opt_list
*ent
;
257 for (i
= 0; i
< opt
->arg
.l
.nr
; i
++) {
258 ent
= &opt
->arg
.l
.p
[i
];
259 if (*value
== ent
->i
) {
260 if (ent
->str
[0] != '\0')
261 pr_debug("%s\n", ent
->str
);
271 pr_debug("Invalid %s value specified (%i) %s\n",
272 opt
->name
, *value
, opt
->err
);
278 * pch_gbe_check_copper_options - Range Checking for Link Options, Copper Version
279 * @adapter: Board private structure
281 static void pch_gbe_check_copper_options(struct pch_gbe_adapter
*adapter
)
283 struct pch_gbe_hw
*hw
= &adapter
->hw
;
287 static const struct pch_gbe_option opt
= {
290 .err
= "parameter ignored",
292 .arg
= { .l
= { .nr
= (int)ARRAY_SIZE(speed_list
),
296 pch_gbe_validate_option(&speed
, &opt
, adapter
);
299 static const struct pch_gbe_option opt
= {
302 .err
= "parameter ignored",
304 .arg
= { .l
= { .nr
= (int)ARRAY_SIZE(dplx_list
),
308 pch_gbe_validate_option(&dplx
, &opt
, adapter
);
312 static const struct pch_gbe_option opt
= {
315 .err
= "parameter ignored",
316 .def
= PCH_AUTONEG_ADVERTISE_DEFAULT
,
317 .arg
= { .l
= { .nr
= (int)ARRAY_SIZE(an_list
),
321 pr_debug("AutoNeg specified along with Speed or Duplex, AutoNeg parameter ignored\n");
322 hw
->phy
.autoneg_advertised
= opt
.def
;
326 pch_gbe_validate_option(&tmp
, &opt
, adapter
);
327 hw
->phy
.autoneg_advertised
= tmp
;
331 switch (speed
+ dplx
) {
333 hw
->mac
.autoneg
= hw
->mac
.fc_autoneg
= 1;
335 pr_debug("Speed and duplex autonegotiation enabled\n");
336 hw
->mac
.link_speed
= SPEED_10
;
337 hw
->mac
.link_duplex
= DUPLEX_HALF
;
340 pr_debug("Half Duplex specified without Speed\n");
341 pr_debug("Using Autonegotiation at Half Duplex only\n");
342 hw
->mac
.autoneg
= hw
->mac
.fc_autoneg
= 1;
343 hw
->phy
.autoneg_advertised
= PHY_ADVERTISE_10_HALF
|
344 PHY_ADVERTISE_100_HALF
;
345 hw
->mac
.link_speed
= SPEED_10
;
346 hw
->mac
.link_duplex
= DUPLEX_HALF
;
349 pr_debug("Full Duplex specified without Speed\n");
350 pr_debug("Using Autonegotiation at Full Duplex only\n");
351 hw
->mac
.autoneg
= hw
->mac
.fc_autoneg
= 1;
352 hw
->phy
.autoneg_advertised
= PHY_ADVERTISE_10_FULL
|
353 PHY_ADVERTISE_100_FULL
|
354 PHY_ADVERTISE_1000_FULL
;
355 hw
->mac
.link_speed
= SPEED_10
;
356 hw
->mac
.link_duplex
= DUPLEX_FULL
;
359 pr_debug("10 Mbps Speed specified without Duplex\n");
360 pr_debug("Using Autonegotiation at 10 Mbps only\n");
361 hw
->mac
.autoneg
= hw
->mac
.fc_autoneg
= 1;
362 hw
->phy
.autoneg_advertised
= PHY_ADVERTISE_10_HALF
|
363 PHY_ADVERTISE_10_FULL
;
364 hw
->mac
.link_speed
= SPEED_10
;
365 hw
->mac
.link_duplex
= DUPLEX_HALF
;
367 case SPEED_10
+ HALF_DUPLEX
:
368 pr_debug("Forcing to 10 Mbps Half Duplex\n");
369 hw
->mac
.autoneg
= hw
->mac
.fc_autoneg
= 0;
370 hw
->phy
.autoneg_advertised
= 0;
371 hw
->mac
.link_speed
= SPEED_10
;
372 hw
->mac
.link_duplex
= DUPLEX_HALF
;
374 case SPEED_10
+ FULL_DUPLEX
:
375 pr_debug("Forcing to 10 Mbps Full Duplex\n");
376 hw
->mac
.autoneg
= hw
->mac
.fc_autoneg
= 0;
377 hw
->phy
.autoneg_advertised
= 0;
378 hw
->mac
.link_speed
= SPEED_10
;
379 hw
->mac
.link_duplex
= DUPLEX_FULL
;
382 pr_debug("100 Mbps Speed specified without Duplex\n");
383 pr_debug("Using Autonegotiation at 100 Mbps only\n");
384 hw
->mac
.autoneg
= hw
->mac
.fc_autoneg
= 1;
385 hw
->phy
.autoneg_advertised
= PHY_ADVERTISE_100_HALF
|
386 PHY_ADVERTISE_100_FULL
;
387 hw
->mac
.link_speed
= SPEED_100
;
388 hw
->mac
.link_duplex
= DUPLEX_HALF
;
390 case SPEED_100
+ HALF_DUPLEX
:
391 pr_debug("Forcing to 100 Mbps Half Duplex\n");
392 hw
->mac
.autoneg
= hw
->mac
.fc_autoneg
= 0;
393 hw
->phy
.autoneg_advertised
= 0;
394 hw
->mac
.link_speed
= SPEED_100
;
395 hw
->mac
.link_duplex
= DUPLEX_HALF
;
397 case SPEED_100
+ FULL_DUPLEX
:
398 pr_debug("Forcing to 100 Mbps Full Duplex\n");
399 hw
->mac
.autoneg
= hw
->mac
.fc_autoneg
= 0;
400 hw
->phy
.autoneg_advertised
= 0;
401 hw
->mac
.link_speed
= SPEED_100
;
402 hw
->mac
.link_duplex
= DUPLEX_FULL
;
405 pr_debug("1000 Mbps Speed specified without Duplex\n");
406 goto full_duplex_only
;
407 case SPEED_1000
+ HALF_DUPLEX
:
408 pr_debug("Half Duplex is not supported at 1000 Mbps\n");
410 case SPEED_1000
+ FULL_DUPLEX
:
412 pr_debug("Using Autonegotiation at 1000 Mbps Full Duplex only\n");
413 hw
->mac
.autoneg
= hw
->mac
.fc_autoneg
= 1;
414 hw
->phy
.autoneg_advertised
= PHY_ADVERTISE_1000_FULL
;
415 hw
->mac
.link_speed
= SPEED_1000
;
416 hw
->mac
.link_duplex
= DUPLEX_FULL
;
424 * pch_gbe_check_options - Range Checking for Command Line Parameters
425 * @adapter: Board private structure
427 void pch_gbe_check_options(struct pch_gbe_adapter
*adapter
)
429 struct pch_gbe_hw
*hw
= &adapter
->hw
;
430 struct net_device
*dev
= adapter
->netdev
;
433 { /* Transmit Descriptor Count */
434 static const struct pch_gbe_option opt
= {
435 .type
= range_option
,
436 .name
= "Transmit Descriptors",
437 .err
= "using default of "
438 __MODULE_STRING(PCH_GBE_DEFAULT_TXD
),
439 .def
= PCH_GBE_DEFAULT_TXD
,
440 .arg
= { .r
= { .min
= PCH_GBE_MIN_TXD
,
441 .max
= PCH_GBE_MAX_TXD
} }
443 struct pch_gbe_tx_ring
*tx_ring
= adapter
->tx_ring
;
444 tx_ring
->count
= TxDescriptors
;
445 pch_gbe_validate_option(&tx_ring
->count
, &opt
, adapter
);
446 tx_ring
->count
= roundup(tx_ring
->count
,
447 PCH_GBE_TX_DESC_MULTIPLE
);
449 { /* Receive Descriptor Count */
450 static const struct pch_gbe_option opt
= {
451 .type
= range_option
,
452 .name
= "Receive Descriptors",
453 .err
= "using default of "
454 __MODULE_STRING(PCH_GBE_DEFAULT_RXD
),
455 .def
= PCH_GBE_DEFAULT_RXD
,
456 .arg
= { .r
= { .min
= PCH_GBE_MIN_RXD
,
457 .max
= PCH_GBE_MAX_RXD
} }
459 struct pch_gbe_rx_ring
*rx_ring
= adapter
->rx_ring
;
460 rx_ring
->count
= RxDescriptors
;
461 pch_gbe_validate_option(&rx_ring
->count
, &opt
, adapter
);
462 rx_ring
->count
= roundup(rx_ring
->count
,
463 PCH_GBE_RX_DESC_MULTIPLE
);
465 { /* Checksum Offload Enable/Disable */
466 static const struct pch_gbe_option opt
= {
467 .type
= enable_option
,
468 .name
= "Checksum Offload",
469 .err
= "defaulting to Enabled",
470 .def
= PCH_GBE_DEFAULT_RX_CSUM
473 pch_gbe_validate_option(&val
, &opt
, adapter
);
475 dev
->features
&= ~NETIF_F_RXCSUM
;
477 { /* Checksum Offload Enable/Disable */
478 static const struct pch_gbe_option opt
= {
479 .type
= enable_option
,
480 .name
= "Checksum Offload",
481 .err
= "defaulting to Enabled",
482 .def
= PCH_GBE_DEFAULT_TX_CSUM
485 pch_gbe_validate_option(&val
, &opt
, adapter
);
487 dev
->features
&= ~NETIF_F_ALL_CSUM
;
490 static const struct pch_gbe_option opt
= {
492 .name
= "Flow Control",
493 .err
= "reading default settings from EEPROM",
494 .def
= PCH_GBE_FC_DEFAULT
,
495 .arg
= { .l
= { .nr
= (int)ARRAY_SIZE(fc_list
),
498 int tmp
= FlowControl
;
500 pch_gbe_validate_option(&tmp
, &opt
, adapter
);
504 pch_gbe_check_copper_options(adapter
);