Staging: hv: mousevsc: Cleanup and properly implement reportdesc_callback()
[zen-stable.git] / drivers / net / pch_gbe / pch_gbe_param.c
blob5b5d90a47e29419eef6cb207066403e37e855efc
1 /*
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.
21 #include "pch_gbe.h"
23 #define OPTION_UNSET -1
24 #define OPTION_DISABLED 0
25 #define OPTION_ENABLED 1
27 /**
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");
36 /**
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");
45 /**
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
52 * @Default Value: 0
54 static int Speed = OPTION_UNSET;
55 module_param(Speed, int, 0);
56 MODULE_PARM_DESC(Speed, "Speed setting");
58 /**
59 * Duplex - User Specified Duplex Override
60 * @Valid Range: 0-2
61 * - 0: auto-negotiate for duplex
62 * - 1: only link at half duplex
63 * - 2: only link at full duplex
64 * @Default Value: 0
66 static int Duplex = OPTION_UNSET;
67 module_param(Duplex, int, 0);
68 MODULE_PARM_DESC(Duplex, "Duplex setting");
70 #define HALF_DUPLEX 1
71 #define FULL_DUPLEX 2
73 /**
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
81 * Bit 7 6 5 4 3 2 1 0
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
99 /**
100 * FlowControl - User Specified Flow Control Override
101 * @Valid Range: 0-3
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
114 * @Valid Range: 0, 1
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
127 * @Valid Range: 0, 1
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
141 * Returns
142 * 0: Successful.
143 * Negative value: Failed.
145 struct pch_gbe_option {
146 enum { enable_option, range_option, list_option } type;
147 char *name;
148 char *err;
149 int def;
150 union {
151 struct { /* range_option info */
152 int min;
153 int max;
154 } r;
155 struct { /* list_option info */
156 int nr;
157 const struct pch_gbe_opt_list { int i; char *str; } *p;
158 } l;
159 } arg;
162 static const struct pch_gbe_opt_list speed_list[] = {
163 { 0, "" },
164 { SPEED_10, "" },
165 { SPEED_100, "" },
166 { SPEED_1000, "" }
169 static const struct pch_gbe_opt_list dplx_list[] = {
170 { 0, "" },
171 { HALF_DUPLEX, "" },
172 { FULL_DUPLEX, "" }
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
219 * @value: value
220 * @opt: option
221 * @adapter: Board private structure
222 * Returns
223 * 0: Successful.
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) {
231 *value = opt->def;
232 return 0;
235 switch (opt->type) {
236 case enable_option:
237 switch (*value) {
238 case OPTION_ENABLED:
239 pr_debug("%s Enabled\n", opt->name);
240 return 0;
241 case OPTION_DISABLED:
242 pr_debug("%s Disabled\n", opt->name);
243 return 0;
245 break;
246 case range_option:
247 if (*value >= opt->arg.r.min && *value <= opt->arg.r.max) {
248 pr_debug("%s set to %i\n", opt->name, *value);
249 return 0;
251 break;
252 case list_option: {
253 int i;
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);
261 return 0;
265 break;
266 default:
267 BUG();
270 pr_debug("Invalid %s value specified (%i) %s\n",
271 opt->name, *value, opt->err);
272 *value = opt->def;
273 return -1;
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;
283 int speed, dplx;
285 { /* Speed */
286 static const struct pch_gbe_option opt = {
287 .type = list_option,
288 .name = "Speed",
289 .err = "parameter ignored",
290 .def = 0,
291 .arg = { .l = { .nr = (int)ARRAY_SIZE(speed_list),
292 .p = speed_list } }
294 speed = Speed;
295 pch_gbe_validate_option(&speed, &opt, adapter);
297 { /* Duplex */
298 static const struct pch_gbe_option opt = {
299 .type = list_option,
300 .name = "Duplex",
301 .err = "parameter ignored",
302 .def = 0,
303 .arg = { .l = { .nr = (int)ARRAY_SIZE(dplx_list),
304 .p = dplx_list } }
306 dplx = Duplex;
307 pch_gbe_validate_option(&dplx, &opt, adapter);
310 { /* Autoneg */
311 static const struct pch_gbe_option opt = {
312 .type = list_option,
313 .name = "AutoNeg",
314 .err = "parameter ignored",
315 .def = PCH_AUTONEG_ADVERTISE_DEFAULT,
316 .arg = { .l = { .nr = (int)ARRAY_SIZE(an_list),
317 .p = an_list} }
319 if (speed || dplx) {
320 pr_debug("AutoNeg specified along with Speed or Duplex, AutoNeg parameter ignored\n");
321 hw->phy.autoneg_advertised = opt.def;
322 } else {
323 hw->phy.autoneg_advertised = AutoNeg;
324 pch_gbe_validate_option(
325 (int *)(&hw->phy.autoneg_advertised),
326 &opt, adapter);
330 switch (speed + dplx) {
331 case 0:
332 hw->mac.autoneg = hw->mac.fc_autoneg = 1;
333 if ((speed || dplx))
334 pr_debug("Speed and duplex autonegotiation enabled\n");
335 hw->mac.link_speed = SPEED_10;
336 hw->mac.link_duplex = DUPLEX_HALF;
337 break;
338 case HALF_DUPLEX:
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;
346 break;
347 case FULL_DUPLEX:
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;
356 break;
357 case SPEED_10:
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;
365 break;
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;
372 break;
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;
379 break;
380 case SPEED_100:
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;
388 break;
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;
395 break;
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;
402 break;
403 case SPEED_1000:
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");
408 /* fall through */
409 case SPEED_1000 + FULL_DUPLEX:
410 full_duplex_only:
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;
416 break;
417 default:
418 BUG();
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;
430 int val;
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
471 val = XsumRX;
472 pch_gbe_validate_option(&val, &opt, adapter);
473 if (!val)
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
483 val = XsumTX;
484 pch_gbe_validate_option(&val, &opt, adapter);
485 if (!val)
486 dev->features &= ~NETIF_F_ALL_CSUM;
488 { /* Flow Control */
489 static const struct pch_gbe_option opt = {
490 .type = list_option,
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),
495 .p = fc_list } }
497 hw->mac.fc = FlowControl;
498 pch_gbe_validate_option((int *)(&hw->mac.fc),
499 &opt, adapter);
502 pch_gbe_check_copper_options(adapter);