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.
23 #define OPTION_UNSET -1
24 #define OPTION_DISABLED 0
25 #define OPTION_ENABLED 1
28 * TxDescriptors - Transmit Descriptor Count
29 * @Valid Range: PCH_GBE_MIN_TXD - PCH_GBE_MAX_TXD
30 * @Default Value: PCH_GBE_DEFAULT_TXD
32 static int TxDescriptors
= OPTION_UNSET
;
33 module_param(TxDescriptors
, int, 0);
34 MODULE_PARM_DESC(TxDescriptors
, "Number of transmit descriptors");
37 * RxDescriptors -Receive Descriptor Count
38 * @Valid Range: PCH_GBE_MIN_RXD - PCH_GBE_MAX_RXD
39 * @Default Value: PCH_GBE_DEFAULT_RXD
41 static int RxDescriptors
= OPTION_UNSET
;
42 module_param(RxDescriptors
, int, 0);
43 MODULE_PARM_DESC(RxDescriptors
, "Number of receive descriptors");
46 * Speed - User Specified Speed Override
47 * @Valid Range: 0, 10, 100, 1000
48 * - 0: auto-negotiate at all supported speeds
49 * - 10: only link at 10 Mbps
50 * - 100: only link at 100 Mbps
51 * - 1000: only link at 1000 Mbps
54 static int Speed
= OPTION_UNSET
;
55 module_param(Speed
, int, 0);
56 MODULE_PARM_DESC(Speed
, "Speed setting");
59 * Duplex - User Specified Duplex Override
61 * - 0: auto-negotiate for duplex
62 * - 1: only link at half duplex
63 * - 2: only link at full duplex
66 static int Duplex
= OPTION_UNSET
;
67 module_param(Duplex
, int, 0);
68 MODULE_PARM_DESC(Duplex
, "Duplex setting");
74 * AutoNeg - Auto-negotiation Advertisement Override
75 * @Valid Range: 0x01-0x0F, 0x20-0x2F
77 * The AutoNeg value is a bit mask describing which speed and duplex
78 * combinations should be advertised during auto-negotiation.
79 * The supported speed and duplex modes are listed below
82 * Speed (Mbps) N/A N/A 1000 N/A 100 100 10 10
83 * Duplex Full Full Half Full Half
85 * @Default Value: 0x2F (copper)
87 static int AutoNeg
= OPTION_UNSET
;
88 module_param(AutoNeg
, int, 0);
89 MODULE_PARM_DESC(AutoNeg
, "Advertised auto-negotiation setting");
91 #define PHY_ADVERTISE_10_HALF 0x0001
92 #define PHY_ADVERTISE_10_FULL 0x0002
93 #define PHY_ADVERTISE_100_HALF 0x0004
94 #define PHY_ADVERTISE_100_FULL 0x0008
95 #define PHY_ADVERTISE_1000_HALF 0x0010 /* Not used, just FYI */
96 #define PHY_ADVERTISE_1000_FULL 0x0020
97 #define PCH_AUTONEG_ADVERTISE_DEFAULT 0x2F
100 * FlowControl - User Specified Flow Control Override
102 * - 0: No Flow Control
103 * - 1: Rx only, respond to PAUSE frames but do not generate them
104 * - 2: Tx only, generate PAUSE frames but ignore them on receive
105 * - 3: Full Flow Control Support
106 * @Default Value: Read flow control settings from the EEPROM
108 static int FlowControl
= OPTION_UNSET
;
109 module_param(FlowControl
, int, 0);
110 MODULE_PARM_DESC(FlowControl
, "Flow Control setting");
113 * XsumRX - Receive Checksum Offload Enable/Disable
115 * - 0: disables all checksum offload
116 * - 1: enables receive IP/TCP/UDP checksum offload
117 * @Default Value: PCH_GBE_DEFAULT_RX_CSUM
119 static int XsumRX
= OPTION_UNSET
;
120 module_param(XsumRX
, int, 0);
121 MODULE_PARM_DESC(XsumRX
, "Disable or enable Receive Checksum offload");
123 #define PCH_GBE_DEFAULT_RX_CSUM true /* trueorfalse */
126 * XsumTX - Transmit Checksum Offload Enable/Disable
128 * - 0: disables all checksum offload
129 * - 1: enables transmit IP/TCP/UDP checksum offload
130 * @Default Value: PCH_GBE_DEFAULT_TX_CSUM
132 static int XsumTX
= OPTION_UNSET
;
133 module_param(XsumTX
, int, 0);
134 MODULE_PARM_DESC(XsumTX
, "Disable or enable Transmit Checksum offload");
136 #define PCH_GBE_DEFAULT_TX_CSUM true /* trueorfalse */
139 * pch_gbe_option - Force the MAC's flow control settings
140 * @hw: Pointer to the HW structure
143 * Negative value: Failed.
145 struct pch_gbe_option
{
146 enum { enable_option
, range_option
, list_option
} type
;
151 struct { /* range_option info */
155 struct { /* list_option info */
157 const struct pch_gbe_opt_list
{ int i
; char *str
; } *p
;
162 static const struct pch_gbe_opt_list speed_list
[] = {
169 static const struct pch_gbe_opt_list dplx_list
[] = {
175 static const struct pch_gbe_opt_list an_list
[] =
176 #define AA "AutoNeg advertising "
177 {{ 0x01, AA
"10/HD" },
178 { 0x02, AA
"10/FD" },
179 { 0x03, AA
"10/FD, 10/HD" },
180 { 0x04, AA
"100/HD" },
181 { 0x05, AA
"100/HD, 10/HD" },
182 { 0x06, AA
"100/HD, 10/FD" },
183 { 0x07, AA
"100/HD, 10/FD, 10/HD" },
184 { 0x08, AA
"100/FD" },
185 { 0x09, AA
"100/FD, 10/HD" },
186 { 0x0a, AA
"100/FD, 10/FD" },
187 { 0x0b, AA
"100/FD, 10/FD, 10/HD" },
188 { 0x0c, AA
"100/FD, 100/HD" },
189 { 0x0d, AA
"100/FD, 100/HD, 10/HD" },
190 { 0x0e, AA
"100/FD, 100/HD, 10/FD" },
191 { 0x0f, AA
"100/FD, 100/HD, 10/FD, 10/HD" },
192 { 0x20, AA
"1000/FD" },
193 { 0x21, AA
"1000/FD, 10/HD" },
194 { 0x22, AA
"1000/FD, 10/FD" },
195 { 0x23, AA
"1000/FD, 10/FD, 10/HD" },
196 { 0x24, AA
"1000/FD, 100/HD" },
197 { 0x25, AA
"1000/FD, 100/HD, 10/HD" },
198 { 0x26, AA
"1000/FD, 100/HD, 10/FD" },
199 { 0x27, AA
"1000/FD, 100/HD, 10/FD, 10/HD" },
200 { 0x28, AA
"1000/FD, 100/FD" },
201 { 0x29, AA
"1000/FD, 100/FD, 10/HD" },
202 { 0x2a, AA
"1000/FD, 100/FD, 10/FD" },
203 { 0x2b, AA
"1000/FD, 100/FD, 10/FD, 10/HD" },
204 { 0x2c, AA
"1000/FD, 100/FD, 100/HD" },
205 { 0x2d, AA
"1000/FD, 100/FD, 100/HD, 10/HD" },
206 { 0x2e, AA
"1000/FD, 100/FD, 100/HD, 10/FD" },
207 { 0x2f, AA
"1000/FD, 100/FD, 100/HD, 10/FD, 10/HD" }
210 static const struct pch_gbe_opt_list fc_list
[] = {
211 { PCH_GBE_FC_NONE
, "Flow Control Disabled" },
212 { PCH_GBE_FC_RX_PAUSE
, "Flow Control Receive Only" },
213 { PCH_GBE_FC_TX_PAUSE
, "Flow Control Transmit Only" },
214 { PCH_GBE_FC_FULL
, "Flow Control Enabled" }
218 * pch_gbe_validate_option - Validate option
221 * @adapter: Board private structure
224 * Negative value: Failed.
226 static int pch_gbe_validate_option(int *value
,
227 const struct pch_gbe_option
*opt
,
228 struct pch_gbe_adapter
*adapter
)
230 if (*value
== OPTION_UNSET
) {
239 pr_debug("%s Enabled\n", opt
->name
);
241 case OPTION_DISABLED
:
242 pr_debug("%s Disabled\n", opt
->name
);
247 if (*value
>= opt
->arg
.r
.min
&& *value
<= opt
->arg
.r
.max
) {
248 pr_debug("%s set to %i\n", opt
->name
, *value
);
254 const struct pch_gbe_opt_list
*ent
;
256 for (i
= 0; i
< opt
->arg
.l
.nr
; i
++) {
257 ent
= &opt
->arg
.l
.p
[i
];
258 if (*value
== ent
->i
) {
259 if (ent
->str
[0] != '\0')
260 pr_debug("%s\n", ent
->str
);
270 pr_debug("Invalid %s value specified (%i) %s\n",
271 opt
->name
, *value
, opt
->err
);
277 * pch_gbe_check_copper_options - Range Checking for Link Options, Copper Version
278 * @adapter: Board private structure
280 static void pch_gbe_check_copper_options(struct pch_gbe_adapter
*adapter
)
282 struct pch_gbe_hw
*hw
= &adapter
->hw
;
286 static const struct pch_gbe_option opt
= {
289 .err
= "parameter ignored",
291 .arg
= { .l
= { .nr
= (int)ARRAY_SIZE(speed_list
),
295 pch_gbe_validate_option(&speed
, &opt
, adapter
);
298 static const struct pch_gbe_option opt
= {
301 .err
= "parameter ignored",
303 .arg
= { .l
= { .nr
= (int)ARRAY_SIZE(dplx_list
),
307 pch_gbe_validate_option(&dplx
, &opt
, adapter
);
311 static const struct pch_gbe_option opt
= {
314 .err
= "parameter ignored",
315 .def
= PCH_AUTONEG_ADVERTISE_DEFAULT
,
316 .arg
= { .l
= { .nr
= (int)ARRAY_SIZE(an_list
),
320 pr_debug("AutoNeg specified along with Speed or Duplex, AutoNeg parameter ignored\n");
321 hw
->phy
.autoneg_advertised
= opt
.def
;
323 hw
->phy
.autoneg_advertised
= AutoNeg
;
324 pch_gbe_validate_option(
325 (int *)(&hw
->phy
.autoneg_advertised
),
330 switch (speed
+ dplx
) {
332 hw
->mac
.autoneg
= hw
->mac
.fc_autoneg
= 1;
334 pr_debug("Speed and duplex autonegotiation enabled\n");
335 hw
->mac
.link_speed
= SPEED_10
;
336 hw
->mac
.link_duplex
= DUPLEX_HALF
;
339 pr_debug("Half Duplex specified without Speed\n");
340 pr_debug("Using Autonegotiation at Half Duplex only\n");
341 hw
->mac
.autoneg
= hw
->mac
.fc_autoneg
= 1;
342 hw
->phy
.autoneg_advertised
= PHY_ADVERTISE_10_HALF
|
343 PHY_ADVERTISE_100_HALF
;
344 hw
->mac
.link_speed
= SPEED_10
;
345 hw
->mac
.link_duplex
= DUPLEX_HALF
;
348 pr_debug("Full Duplex specified without Speed\n");
349 pr_debug("Using Autonegotiation at Full Duplex only\n");
350 hw
->mac
.autoneg
= hw
->mac
.fc_autoneg
= 1;
351 hw
->phy
.autoneg_advertised
= PHY_ADVERTISE_10_FULL
|
352 PHY_ADVERTISE_100_FULL
|
353 PHY_ADVERTISE_1000_FULL
;
354 hw
->mac
.link_speed
= SPEED_10
;
355 hw
->mac
.link_duplex
= DUPLEX_FULL
;
358 pr_debug("10 Mbps Speed specified without Duplex\n");
359 pr_debug("Using Autonegotiation at 10 Mbps only\n");
360 hw
->mac
.autoneg
= hw
->mac
.fc_autoneg
= 1;
361 hw
->phy
.autoneg_advertised
= PHY_ADVERTISE_10_HALF
|
362 PHY_ADVERTISE_10_FULL
;
363 hw
->mac
.link_speed
= SPEED_10
;
364 hw
->mac
.link_duplex
= DUPLEX_HALF
;
366 case SPEED_10
+ HALF_DUPLEX
:
367 pr_debug("Forcing to 10 Mbps Half Duplex\n");
368 hw
->mac
.autoneg
= hw
->mac
.fc_autoneg
= 0;
369 hw
->phy
.autoneg_advertised
= 0;
370 hw
->mac
.link_speed
= SPEED_10
;
371 hw
->mac
.link_duplex
= DUPLEX_HALF
;
373 case SPEED_10
+ FULL_DUPLEX
:
374 pr_debug("Forcing to 10 Mbps Full Duplex\n");
375 hw
->mac
.autoneg
= hw
->mac
.fc_autoneg
= 0;
376 hw
->phy
.autoneg_advertised
= 0;
377 hw
->mac
.link_speed
= SPEED_10
;
378 hw
->mac
.link_duplex
= DUPLEX_FULL
;
381 pr_debug("100 Mbps Speed specified without Duplex\n");
382 pr_debug("Using Autonegotiation at 100 Mbps only\n");
383 hw
->mac
.autoneg
= hw
->mac
.fc_autoneg
= 1;
384 hw
->phy
.autoneg_advertised
= PHY_ADVERTISE_100_HALF
|
385 PHY_ADVERTISE_100_FULL
;
386 hw
->mac
.link_speed
= SPEED_100
;
387 hw
->mac
.link_duplex
= DUPLEX_HALF
;
389 case SPEED_100
+ HALF_DUPLEX
:
390 pr_debug("Forcing to 100 Mbps Half Duplex\n");
391 hw
->mac
.autoneg
= hw
->mac
.fc_autoneg
= 0;
392 hw
->phy
.autoneg_advertised
= 0;
393 hw
->mac
.link_speed
= SPEED_100
;
394 hw
->mac
.link_duplex
= DUPLEX_HALF
;
396 case SPEED_100
+ FULL_DUPLEX
:
397 pr_debug("Forcing to 100 Mbps Full Duplex\n");
398 hw
->mac
.autoneg
= hw
->mac
.fc_autoneg
= 0;
399 hw
->phy
.autoneg_advertised
= 0;
400 hw
->mac
.link_speed
= SPEED_100
;
401 hw
->mac
.link_duplex
= DUPLEX_FULL
;
404 pr_debug("1000 Mbps Speed specified without Duplex\n");
405 goto full_duplex_only
;
406 case SPEED_1000
+ HALF_DUPLEX
:
407 pr_debug("Half Duplex is not supported at 1000 Mbps\n");
409 case SPEED_1000
+ FULL_DUPLEX
:
411 pr_debug("Using Autonegotiation at 1000 Mbps Full Duplex only\n");
412 hw
->mac
.autoneg
= hw
->mac
.fc_autoneg
= 1;
413 hw
->phy
.autoneg_advertised
= PHY_ADVERTISE_1000_FULL
;
414 hw
->mac
.link_speed
= SPEED_1000
;
415 hw
->mac
.link_duplex
= DUPLEX_FULL
;
423 * pch_gbe_check_options - Range Checking for Command Line Parameters
424 * @adapter: Board private structure
426 void pch_gbe_check_options(struct pch_gbe_adapter
*adapter
)
428 struct pch_gbe_hw
*hw
= &adapter
->hw
;
429 struct net_device
*dev
= adapter
->netdev
;
432 { /* Transmit Descriptor Count */
433 static const struct pch_gbe_option opt
= {
434 .type
= range_option
,
435 .name
= "Transmit Descriptors",
436 .err
= "using default of "
437 __MODULE_STRING(PCH_GBE_DEFAULT_TXD
),
438 .def
= PCH_GBE_DEFAULT_TXD
,
439 .arg
= { .r
= { .min
= PCH_GBE_MIN_TXD
,
440 .max
= PCH_GBE_MAX_TXD
} }
442 struct pch_gbe_tx_ring
*tx_ring
= adapter
->tx_ring
;
443 tx_ring
->count
= TxDescriptors
;
444 pch_gbe_validate_option(&tx_ring
->count
, &opt
, adapter
);
445 tx_ring
->count
= roundup(tx_ring
->count
,
446 PCH_GBE_TX_DESC_MULTIPLE
);
448 { /* Receive Descriptor Count */
449 static const struct pch_gbe_option opt
= {
450 .type
= range_option
,
451 .name
= "Receive Descriptors",
452 .err
= "using default of "
453 __MODULE_STRING(PCH_GBE_DEFAULT_RXD
),
454 .def
= PCH_GBE_DEFAULT_RXD
,
455 .arg
= { .r
= { .min
= PCH_GBE_MIN_RXD
,
456 .max
= PCH_GBE_MAX_RXD
} }
458 struct pch_gbe_rx_ring
*rx_ring
= adapter
->rx_ring
;
459 rx_ring
->count
= RxDescriptors
;
460 pch_gbe_validate_option(&rx_ring
->count
, &opt
, adapter
);
461 rx_ring
->count
= roundup(rx_ring
->count
,
462 PCH_GBE_RX_DESC_MULTIPLE
);
464 { /* Checksum Offload Enable/Disable */
465 static const struct pch_gbe_option opt
= {
466 .type
= enable_option
,
467 .name
= "Checksum Offload",
468 .err
= "defaulting to Enabled",
469 .def
= PCH_GBE_DEFAULT_RX_CSUM
472 pch_gbe_validate_option(&val
, &opt
, adapter
);
474 dev
->features
&= ~NETIF_F_RXCSUM
;
476 { /* Checksum Offload Enable/Disable */
477 static const struct pch_gbe_option opt
= {
478 .type
= enable_option
,
479 .name
= "Checksum Offload",
480 .err
= "defaulting to Enabled",
481 .def
= PCH_GBE_DEFAULT_TX_CSUM
484 pch_gbe_validate_option(&val
, &opt
, adapter
);
486 dev
->features
&= ~NETIF_F_ALL_CSUM
;
489 static const struct pch_gbe_option opt
= {
491 .name
= "Flow Control",
492 .err
= "reading default settings from EEPROM",
493 .def
= PCH_GBE_FC_DEFAULT
,
494 .arg
= { .l
= { .nr
= (int)ARRAY_SIZE(fc_list
),
497 hw
->mac
.fc
= FlowControl
;
498 pch_gbe_validate_option((int *)(&hw
->mac
.fc
),
502 pch_gbe_check_copper_options(adapter
);