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 netdev_dbg(adapter->netdev, "%s Enabled\n", opt->name);
242 case OPTION_DISABLED:
243 netdev_dbg(adapter->netdev, "%s Disabled\n", opt->name);
248 if (*value >= opt->arg.r.min && *value <= opt->arg.r.max) {
249 netdev_dbg(adapter->netdev, "%s set to %i\n",
256 const struct pch_gbe_opt_list *ent;
258 for (i = 0; i < opt->arg.l.nr; i++) {
259 ent = &opt->arg.l.p[i];
260 if (*value == ent->i) {
261 if (ent->str[0] != '\0')
262 netdev_dbg(adapter->netdev, "%s\n",
273 netdev_dbg(adapter->netdev, "Invalid %s value specified (%i) %s\n",
274 opt->name, *value, opt->err);
280 * pch_gbe_check_copper_options - Range Checking for Link Options, Copper Version
281 * @adapter: Board private structure
283 static void pch_gbe_check_copper_options(struct pch_gbe_adapter *adapter)
285 struct pch_gbe_hw *hw = &adapter->hw;
289 static const struct pch_gbe_option opt = {
292 .err = "parameter ignored",
294 .arg = { .l = { .nr = (int)ARRAY_SIZE(speed_list),
298 pch_gbe_validate_option(&speed, &opt, adapter);
301 static const struct pch_gbe_option opt = {
304 .err = "parameter ignored",
306 .arg = { .l = { .nr = (int)ARRAY_SIZE(dplx_list),
310 pch_gbe_validate_option(&dplx, &opt, adapter);
314 static const struct pch_gbe_option opt = {
317 .err = "parameter ignored",
318 .def = PCH_AUTONEG_ADVERTISE_DEFAULT,
319 .arg = { .l = { .nr = (int)ARRAY_SIZE(an_list),
323 netdev_dbg(adapter->netdev,
324 "AutoNeg specified along with Speed or Duplex, AutoNeg parameter ignored\n");
325 hw->phy.autoneg_advertised = opt.def;
329 pch_gbe_validate_option(&tmp, &opt, adapter);
330 hw->phy.autoneg_advertised = tmp;
334 switch (speed + dplx) {
336 hw->mac.autoneg = hw->mac.fc_autoneg = 1;
338 netdev_dbg(adapter->netdev,
339 "Speed and duplex autonegotiation enabled\n");
340 hw->mac.link_speed = SPEED_10;
341 hw->mac.link_duplex = DUPLEX_HALF;
344 netdev_dbg(adapter->netdev,
345 "Half Duplex specified without Speed\n");
346 netdev_dbg(adapter->netdev,
347 "Using Autonegotiation at Half Duplex only\n");
348 hw->mac.autoneg = hw->mac.fc_autoneg = 1;
349 hw->phy.autoneg_advertised = PHY_ADVERTISE_10_HALF |
350 PHY_ADVERTISE_100_HALF;
351 hw->mac.link_speed = SPEED_10;
352 hw->mac.link_duplex = DUPLEX_HALF;
355 netdev_dbg(adapter->netdev,
356 "Full Duplex specified without Speed\n");
357 netdev_dbg(adapter->netdev,
358 "Using Autonegotiation at Full Duplex only\n");
359 hw->mac.autoneg = hw->mac.fc_autoneg = 1;
360 hw->phy.autoneg_advertised = PHY_ADVERTISE_10_FULL |
361 PHY_ADVERTISE_100_FULL |
362 PHY_ADVERTISE_1000_FULL;
363 hw->mac.link_speed = SPEED_10;
364 hw->mac.link_duplex = DUPLEX_FULL;
367 netdev_dbg(adapter->netdev,
368 "10 Mbps Speed specified without Duplex\n");
369 netdev_dbg(adapter->netdev,
370 "Using Autonegotiation at 10 Mbps only\n");
371 hw->mac.autoneg = hw->mac.fc_autoneg = 1;
372 hw->phy.autoneg_advertised = PHY_ADVERTISE_10_HALF |
373 PHY_ADVERTISE_10_FULL;
374 hw->mac.link_speed = SPEED_10;
375 hw->mac.link_duplex = DUPLEX_HALF;
377 case SPEED_10 + HALF_DUPLEX:
378 netdev_dbg(adapter->netdev, "Forcing to 10 Mbps Half Duplex\n");
379 hw->mac.autoneg = hw->mac.fc_autoneg = 0;
380 hw->phy.autoneg_advertised = 0;
381 hw->mac.link_speed = SPEED_10;
382 hw->mac.link_duplex = DUPLEX_HALF;
384 case SPEED_10 + FULL_DUPLEX:
385 netdev_dbg(adapter->netdev, "Forcing to 10 Mbps Full Duplex\n");
386 hw->mac.autoneg = hw->mac.fc_autoneg = 0;
387 hw->phy.autoneg_advertised = 0;
388 hw->mac.link_speed = SPEED_10;
389 hw->mac.link_duplex = DUPLEX_FULL;
392 netdev_dbg(adapter->netdev,
393 "100 Mbps Speed specified without Duplex\n");
394 netdev_dbg(adapter->netdev,
395 "Using Autonegotiation at 100 Mbps only\n");
396 hw->mac.autoneg = hw->mac.fc_autoneg = 1;
397 hw->phy.autoneg_advertised = PHY_ADVERTISE_100_HALF |
398 PHY_ADVERTISE_100_FULL;
399 hw->mac.link_speed = SPEED_100;
400 hw->mac.link_duplex = DUPLEX_HALF;
402 case SPEED_100 + HALF_DUPLEX:
403 netdev_dbg(adapter->netdev,
404 "Forcing to 100 Mbps Half Duplex\n");
405 hw->mac.autoneg = hw->mac.fc_autoneg = 0;
406 hw->phy.autoneg_advertised = 0;
407 hw->mac.link_speed = SPEED_100;
408 hw->mac.link_duplex = DUPLEX_HALF;
410 case SPEED_100 + FULL_DUPLEX:
411 netdev_dbg(adapter->netdev,
412 "Forcing to 100 Mbps Full Duplex\n");
413 hw->mac.autoneg = hw->mac.fc_autoneg = 0;
414 hw->phy.autoneg_advertised = 0;
415 hw->mac.link_speed = SPEED_100;
416 hw->mac.link_duplex = DUPLEX_FULL;
419 netdev_dbg(adapter->netdev,
420 "1000 Mbps Speed specified without Duplex\n");
421 goto full_duplex_only;
422 case SPEED_1000 + HALF_DUPLEX:
423 netdev_dbg(adapter->netdev,
424 "Half Duplex is not supported at 1000 Mbps\n");
426 case SPEED_1000 + FULL_DUPLEX:
428 netdev_dbg(adapter->netdev,
429 "Using Autonegotiation at 1000 Mbps Full Duplex only\n");
430 hw->mac.autoneg = hw->mac.fc_autoneg = 1;
431 hw->phy.autoneg_advertised = PHY_ADVERTISE_1000_FULL;
432 hw->mac.link_speed = SPEED_1000;
433 hw->mac.link_duplex = DUPLEX_FULL;
441 * pch_gbe_check_options - Range Checking for Command Line Parameters
442 * @adapter: Board private structure
444 void pch_gbe_check_options(struct pch_gbe_adapter *adapter)
446 struct pch_gbe_hw *hw = &adapter->hw;
447 struct net_device *dev = adapter->netdev;
450 { /* Transmit Descriptor Count */
451 static const struct pch_gbe_option opt = {
452 .type = range_option,
453 .name = "Transmit Descriptors",
454 .err = "using default of "
455 __MODULE_STRING(PCH_GBE_DEFAULT_TXD),
456 .def = PCH_GBE_DEFAULT_TXD,
457 .arg = { .r = { .min = PCH_GBE_MIN_TXD,
458 .max = PCH_GBE_MAX_TXD } }
460 struct pch_gbe_tx_ring *tx_ring = adapter->tx_ring;
461 tx_ring->count = TxDescriptors;
462 pch_gbe_validate_option(&tx_ring->count, &opt, adapter);
463 tx_ring->count = roundup(tx_ring->count,
464 PCH_GBE_TX_DESC_MULTIPLE);
466 { /* Receive Descriptor Count */
467 static const struct pch_gbe_option opt = {
468 .type = range_option,
469 .name = "Receive Descriptors",
470 .err = "using default of "
471 __MODULE_STRING(PCH_GBE_DEFAULT_RXD),
472 .def = PCH_GBE_DEFAULT_RXD,
473 .arg = { .r = { .min = PCH_GBE_MIN_RXD,
474 .max = PCH_GBE_MAX_RXD } }
476 struct pch_gbe_rx_ring *rx_ring = adapter->rx_ring;
477 rx_ring->count = RxDescriptors;
478 pch_gbe_validate_option(&rx_ring->count, &opt, adapter);
479 rx_ring->count = roundup(rx_ring->count,
480 PCH_GBE_RX_DESC_MULTIPLE);
482 { /* Checksum Offload Enable/Disable */
483 static const struct pch_gbe_option opt = {
484 .type = enable_option,
485 .name = "Checksum Offload",
486 .err = "defaulting to Enabled",
487 .def = PCH_GBE_DEFAULT_RX_CSUM
490 pch_gbe_validate_option(&val, &opt, adapter);
492 dev->features &= ~NETIF_F_RXCSUM;
494 { /* Checksum Offload Enable/Disable */
495 static const struct pch_gbe_option opt = {
496 .type = enable_option,
497 .name = "Checksum Offload",
498 .err = "defaulting to Enabled",
499 .def = PCH_GBE_DEFAULT_TX_CSUM
502 pch_gbe_validate_option(&val, &opt, adapter);
504 dev->features &= ~NETIF_F_ALL_CSUM;
507 static const struct pch_gbe_option opt = {
509 .name = "Flow Control",
510 .err = "reading default settings from EEPROM",
511 .def = PCH_GBE_FC_DEFAULT,
512 .arg = { .l = { .nr = (int)ARRAY_SIZE(fc_list),
515 int tmp = FlowControl;
517 pch_gbe_validate_option(&tmp, &opt, adapter);
521 pch_gbe_check_copper_options(adapter);