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, see <http://www.gnu.org/licenses/>.
21 #include <linux/module.h> /* for __MODULE_STRING */
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 netdev_dbg(adapter
->netdev
, "%s Enabled\n", opt
->name
);
241 case OPTION_DISABLED
:
242 netdev_dbg(adapter
->netdev
, "%s Disabled\n", opt
->name
);
247 if (*value
>= opt
->arg
.r
.min
&& *value
<= opt
->arg
.r
.max
) {
248 netdev_dbg(adapter
->netdev
, "%s set to %i\n",
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 netdev_dbg(adapter
->netdev
, "%s\n",
272 netdev_dbg(adapter
->netdev
, "Invalid %s value specified (%i) %s\n",
273 opt
->name
, *value
, opt
->err
);
279 * pch_gbe_check_copper_options - Range Checking for Link Options, Copper Version
280 * @adapter: Board private structure
282 static void pch_gbe_check_copper_options(struct pch_gbe_adapter
*adapter
)
284 struct pch_gbe_hw
*hw
= &adapter
->hw
;
288 static const struct pch_gbe_option opt
= {
291 .err
= "parameter ignored",
293 .arg
= { .l
= { .nr
= (int)ARRAY_SIZE(speed_list
),
297 pch_gbe_validate_option(&speed
, &opt
, adapter
);
300 static const struct pch_gbe_option opt
= {
303 .err
= "parameter ignored",
305 .arg
= { .l
= { .nr
= (int)ARRAY_SIZE(dplx_list
),
309 pch_gbe_validate_option(&dplx
, &opt
, adapter
);
313 static const struct pch_gbe_option opt
= {
316 .err
= "parameter ignored",
317 .def
= PCH_AUTONEG_ADVERTISE_DEFAULT
,
318 .arg
= { .l
= { .nr
= (int)ARRAY_SIZE(an_list
),
322 netdev_dbg(adapter
->netdev
,
323 "AutoNeg specified along with Speed or Duplex, AutoNeg parameter ignored\n");
324 hw
->phy
.autoneg_advertised
= opt
.def
;
328 pch_gbe_validate_option(&tmp
, &opt
, adapter
);
329 hw
->phy
.autoneg_advertised
= tmp
;
333 switch (speed
+ dplx
) {
335 hw
->mac
.autoneg
= hw
->mac
.fc_autoneg
= 1;
337 netdev_dbg(adapter
->netdev
,
338 "Speed and duplex autonegotiation enabled\n");
339 hw
->mac
.link_speed
= SPEED_10
;
340 hw
->mac
.link_duplex
= DUPLEX_HALF
;
343 netdev_dbg(adapter
->netdev
,
344 "Half Duplex specified without Speed\n");
345 netdev_dbg(adapter
->netdev
,
346 "Using Autonegotiation at Half Duplex only\n");
347 hw
->mac
.autoneg
= hw
->mac
.fc_autoneg
= 1;
348 hw
->phy
.autoneg_advertised
= PHY_ADVERTISE_10_HALF
|
349 PHY_ADVERTISE_100_HALF
;
350 hw
->mac
.link_speed
= SPEED_10
;
351 hw
->mac
.link_duplex
= DUPLEX_HALF
;
354 netdev_dbg(adapter
->netdev
,
355 "Full Duplex specified without Speed\n");
356 netdev_dbg(adapter
->netdev
,
357 "Using Autonegotiation at Full Duplex only\n");
358 hw
->mac
.autoneg
= hw
->mac
.fc_autoneg
= 1;
359 hw
->phy
.autoneg_advertised
= PHY_ADVERTISE_10_FULL
|
360 PHY_ADVERTISE_100_FULL
|
361 PHY_ADVERTISE_1000_FULL
;
362 hw
->mac
.link_speed
= SPEED_10
;
363 hw
->mac
.link_duplex
= DUPLEX_FULL
;
366 netdev_dbg(adapter
->netdev
,
367 "10 Mbps Speed specified without Duplex\n");
368 netdev_dbg(adapter
->netdev
,
369 "Using Autonegotiation at 10 Mbps only\n");
370 hw
->mac
.autoneg
= hw
->mac
.fc_autoneg
= 1;
371 hw
->phy
.autoneg_advertised
= PHY_ADVERTISE_10_HALF
|
372 PHY_ADVERTISE_10_FULL
;
373 hw
->mac
.link_speed
= SPEED_10
;
374 hw
->mac
.link_duplex
= DUPLEX_HALF
;
376 case SPEED_10
+ HALF_DUPLEX
:
377 netdev_dbg(adapter
->netdev
, "Forcing to 10 Mbps Half Duplex\n");
378 hw
->mac
.autoneg
= hw
->mac
.fc_autoneg
= 0;
379 hw
->phy
.autoneg_advertised
= 0;
380 hw
->mac
.link_speed
= SPEED_10
;
381 hw
->mac
.link_duplex
= DUPLEX_HALF
;
383 case SPEED_10
+ FULL_DUPLEX
:
384 netdev_dbg(adapter
->netdev
, "Forcing to 10 Mbps Full Duplex\n");
385 hw
->mac
.autoneg
= hw
->mac
.fc_autoneg
= 0;
386 hw
->phy
.autoneg_advertised
= 0;
387 hw
->mac
.link_speed
= SPEED_10
;
388 hw
->mac
.link_duplex
= DUPLEX_FULL
;
391 netdev_dbg(adapter
->netdev
,
392 "100 Mbps Speed specified without Duplex\n");
393 netdev_dbg(adapter
->netdev
,
394 "Using Autonegotiation at 100 Mbps only\n");
395 hw
->mac
.autoneg
= hw
->mac
.fc_autoneg
= 1;
396 hw
->phy
.autoneg_advertised
= PHY_ADVERTISE_100_HALF
|
397 PHY_ADVERTISE_100_FULL
;
398 hw
->mac
.link_speed
= SPEED_100
;
399 hw
->mac
.link_duplex
= DUPLEX_HALF
;
401 case SPEED_100
+ HALF_DUPLEX
:
402 netdev_dbg(adapter
->netdev
,
403 "Forcing to 100 Mbps Half Duplex\n");
404 hw
->mac
.autoneg
= hw
->mac
.fc_autoneg
= 0;
405 hw
->phy
.autoneg_advertised
= 0;
406 hw
->mac
.link_speed
= SPEED_100
;
407 hw
->mac
.link_duplex
= DUPLEX_HALF
;
409 case SPEED_100
+ FULL_DUPLEX
:
410 netdev_dbg(adapter
->netdev
,
411 "Forcing to 100 Mbps Full Duplex\n");
412 hw
->mac
.autoneg
= hw
->mac
.fc_autoneg
= 0;
413 hw
->phy
.autoneg_advertised
= 0;
414 hw
->mac
.link_speed
= SPEED_100
;
415 hw
->mac
.link_duplex
= DUPLEX_FULL
;
418 netdev_dbg(adapter
->netdev
,
419 "1000 Mbps Speed specified without Duplex\n");
420 goto full_duplex_only
;
421 case SPEED_1000
+ HALF_DUPLEX
:
422 netdev_dbg(adapter
->netdev
,
423 "Half Duplex is not supported at 1000 Mbps\n");
425 case SPEED_1000
+ FULL_DUPLEX
:
427 netdev_dbg(adapter
->netdev
,
428 "Using Autonegotiation at 1000 Mbps Full Duplex only\n");
429 hw
->mac
.autoneg
= hw
->mac
.fc_autoneg
= 1;
430 hw
->phy
.autoneg_advertised
= PHY_ADVERTISE_1000_FULL
;
431 hw
->mac
.link_speed
= SPEED_1000
;
432 hw
->mac
.link_duplex
= DUPLEX_FULL
;
440 * pch_gbe_check_options - Range Checking for Command Line Parameters
441 * @adapter: Board private structure
443 void pch_gbe_check_options(struct pch_gbe_adapter
*adapter
)
445 struct pch_gbe_hw
*hw
= &adapter
->hw
;
446 struct net_device
*dev
= adapter
->netdev
;
449 { /* Transmit Descriptor Count */
450 static const struct pch_gbe_option opt
= {
451 .type
= range_option
,
452 .name
= "Transmit Descriptors",
453 .err
= "using default of "
454 __MODULE_STRING(PCH_GBE_DEFAULT_TXD
),
455 .def
= PCH_GBE_DEFAULT_TXD
,
456 .arg
= { .r
= { .min
= PCH_GBE_MIN_TXD
,
457 .max
= PCH_GBE_MAX_TXD
} }
459 struct pch_gbe_tx_ring
*tx_ring
= adapter
->tx_ring
;
460 tx_ring
->count
= TxDescriptors
;
461 pch_gbe_validate_option(&tx_ring
->count
, &opt
, adapter
);
462 tx_ring
->count
= roundup(tx_ring
->count
,
463 PCH_GBE_TX_DESC_MULTIPLE
);
465 { /* Receive Descriptor Count */
466 static const struct pch_gbe_option opt
= {
467 .type
= range_option
,
468 .name
= "Receive Descriptors",
469 .err
= "using default of "
470 __MODULE_STRING(PCH_GBE_DEFAULT_RXD
),
471 .def
= PCH_GBE_DEFAULT_RXD
,
472 .arg
= { .r
= { .min
= PCH_GBE_MIN_RXD
,
473 .max
= PCH_GBE_MAX_RXD
} }
475 struct pch_gbe_rx_ring
*rx_ring
= adapter
->rx_ring
;
476 rx_ring
->count
= RxDescriptors
;
477 pch_gbe_validate_option(&rx_ring
->count
, &opt
, adapter
);
478 rx_ring
->count
= roundup(rx_ring
->count
,
479 PCH_GBE_RX_DESC_MULTIPLE
);
481 { /* Checksum Offload Enable/Disable */
482 static const struct pch_gbe_option opt
= {
483 .type
= enable_option
,
484 .name
= "Checksum Offload",
485 .err
= "defaulting to Enabled",
486 .def
= PCH_GBE_DEFAULT_RX_CSUM
489 pch_gbe_validate_option(&val
, &opt
, adapter
);
491 dev
->features
&= ~NETIF_F_RXCSUM
;
493 { /* Checksum Offload Enable/Disable */
494 static const struct pch_gbe_option opt
= {
495 .type
= enable_option
,
496 .name
= "Checksum Offload",
497 .err
= "defaulting to Enabled",
498 .def
= PCH_GBE_DEFAULT_TX_CSUM
501 pch_gbe_validate_option(&val
, &opt
, adapter
);
503 dev
->features
&= ~NETIF_F_CSUM_MASK
;
506 static const struct pch_gbe_option opt
= {
508 .name
= "Flow Control",
509 .err
= "reading default settings from EEPROM",
510 .def
= PCH_GBE_FC_DEFAULT
,
511 .arg
= { .l
= { .nr
= (int)ARRAY_SIZE(fc_list
),
514 int tmp
= FlowControl
;
516 pch_gbe_validate_option(&tmp
, &opt
, adapter
);
520 pch_gbe_check_copper_options(adapter
);