aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/net/e1000
diff options
context:
space:
mode:
authorAuke Kok <auke-jan.h.kok@intel.com>2006-06-27 12:06:59 -0400
committerAuke Kok <juke-jan.h.kok@intel.com>2006-06-27 12:06:59 -0400
commit17231712ab89fa085bc235ef19c1e6e0c163e4fc (patch)
tree0d1a97d85030591379d8cad0a5dafbf6855b24f6 /drivers/net/e1000
parent864c4e45ec6d1bfe16a14d887d5baad201419aba (diff)
e1000: rework module param code with uninitialized values
We can take uninitialized values into account which minimizes code and allows us to simplify the parameter checking code greatly. Signed-off-by: Jesse Brandeburg <jesse.brandeburg@intel.com> Signed-off-by: Auke Kok <auke-jan.h.kok@intel.com>
Diffstat (limited to 'drivers/net/e1000')
-rw-r--r--drivers/net/e1000/e1000_param.c167
1 files changed, 61 insertions, 106 deletions
diff --git a/drivers/net/e1000/e1000_param.c b/drivers/net/e1000/e1000_param.c
index a8d9295b0779..bd6c040b3cfb 100644
--- a/drivers/net/e1000/e1000_param.c
+++ b/drivers/net/e1000/e1000_param.c
@@ -45,6 +45,16 @@
45 */ 45 */
46 46
47#define E1000_PARAM_INIT { [0 ... E1000_MAX_NIC] = OPTION_UNSET } 47#define E1000_PARAM_INIT { [0 ... E1000_MAX_NIC] = OPTION_UNSET }
48/* Module Parameters are always initialized to -1, so that the driver
49 * can tell the difference between no user specified value or the
50 * user asking for the default value.
51 * The true default values are loaded in when e1000_check_options is called.
52 *
53 * This is a GCC extension to ANSI C.
54 * See the item "Labeled Elements in Initializers" in the section
55 * "Extensions to the C Language Family" of the GCC documentation.
56 */
57
48#define E1000_PARAM(X, desc) \ 58#define E1000_PARAM(X, desc) \
49 static int __devinitdata X[E1000_MAX_NIC+1] = E1000_PARAM_INIT; \ 59 static int __devinitdata X[E1000_MAX_NIC+1] = E1000_PARAM_INIT; \
50 static int num_##X = 0; \ 60 static int num_##X = 0; \
@@ -305,6 +315,7 @@ e1000_check_options(struct e1000_adapter *adapter)
305 DPRINTK(PROBE, NOTICE, 315 DPRINTK(PROBE, NOTICE,
306 "Warning: no configuration for board #%i\n", bd); 316 "Warning: no configuration for board #%i\n", bd);
307 DPRINTK(PROBE, NOTICE, "Using defaults for all values\n"); 317 DPRINTK(PROBE, NOTICE, "Using defaults for all values\n");
318 bd = E1000_MAX_NIC;
308 } 319 }
309 320
310 { /* Transmit Descriptor Count */ 321 { /* Transmit Descriptor Count */
@@ -322,14 +333,9 @@ e1000_check_options(struct e1000_adapter *adapter)
322 opt.arg.r.max = mac_type < e1000_82544 ? 333 opt.arg.r.max = mac_type < e1000_82544 ?
323 E1000_MAX_TXD : E1000_MAX_82544_TXD; 334 E1000_MAX_TXD : E1000_MAX_82544_TXD;
324 335
325 if (num_TxDescriptors > bd) { 336 tx_ring->count = TxDescriptors[bd];
326 tx_ring->count = TxDescriptors[bd]; 337 e1000_validate_option(&tx_ring->count, &opt, adapter);
327 e1000_validate_option(&tx_ring->count, &opt, adapter); 338 E1000_ROUNDUP(tx_ring->count, REQ_TX_DESCRIPTOR_MULTIPLE);
328 E1000_ROUNDUP(tx_ring->count,
329 REQ_TX_DESCRIPTOR_MULTIPLE);
330 } else {
331 tx_ring->count = opt.def;
332 }
333 for (i = 0; i < adapter->num_tx_queues; i++) 339 for (i = 0; i < adapter->num_tx_queues; i++)
334 tx_ring[i].count = tx_ring->count; 340 tx_ring[i].count = tx_ring->count;
335 } 341 }
@@ -348,14 +354,9 @@ e1000_check_options(struct e1000_adapter *adapter)
348 opt.arg.r.max = mac_type < e1000_82544 ? E1000_MAX_RXD : 354 opt.arg.r.max = mac_type < e1000_82544 ? E1000_MAX_RXD :
349 E1000_MAX_82544_RXD; 355 E1000_MAX_82544_RXD;
350 356
351 if (num_RxDescriptors > bd) { 357 rx_ring->count = RxDescriptors[bd];
352 rx_ring->count = RxDescriptors[bd]; 358 e1000_validate_option(&rx_ring->count, &opt, adapter);
353 e1000_validate_option(&rx_ring->count, &opt, adapter); 359 E1000_ROUNDUP(rx_ring->count, REQ_RX_DESCRIPTOR_MULTIPLE);
354 E1000_ROUNDUP(rx_ring->count,
355 REQ_RX_DESCRIPTOR_MULTIPLE);
356 } else {
357 rx_ring->count = opt.def;
358 }
359 for (i = 0; i < adapter->num_rx_queues; i++) 360 for (i = 0; i < adapter->num_rx_queues; i++)
360 rx_ring[i].count = rx_ring->count; 361 rx_ring[i].count = rx_ring->count;
361 } 362 }
@@ -367,13 +368,9 @@ e1000_check_options(struct e1000_adapter *adapter)
367 .def = OPTION_ENABLED 368 .def = OPTION_ENABLED
368 }; 369 };
369 370
370 if (num_XsumRX > bd) { 371 int rx_csum = XsumRX[bd];
371 int rx_csum = XsumRX[bd]; 372 e1000_validate_option(&rx_csum, &opt, adapter);
372 e1000_validate_option(&rx_csum, &opt, adapter); 373 adapter->rx_csum = rx_csum;
373 adapter->rx_csum = rx_csum;
374 } else {
375 adapter->rx_csum = opt.def;
376 }
377 } 374 }
378 { /* Flow Control */ 375 { /* Flow Control */
379 376
@@ -393,13 +390,9 @@ e1000_check_options(struct e1000_adapter *adapter)
393 .p = fc_list }} 390 .p = fc_list }}
394 }; 391 };
395 392
396 if (num_FlowControl > bd) { 393 int fc = FlowControl[bd];
397 int fc = FlowControl[bd]; 394 e1000_validate_option(&fc, &opt, adapter);
398 e1000_validate_option(&fc, &opt, adapter); 395 adapter->hw.fc = adapter->hw.original_fc = fc;
399 adapter->hw.fc = adapter->hw.original_fc = fc;
400 } else {
401 adapter->hw.fc = adapter->hw.original_fc = opt.def;
402 }
403 } 396 }
404 { /* Transmit Interrupt Delay */ 397 { /* Transmit Interrupt Delay */
405 struct e1000_option opt = { 398 struct e1000_option opt = {
@@ -411,13 +404,8 @@ e1000_check_options(struct e1000_adapter *adapter)
411 .max = MAX_TXDELAY }} 404 .max = MAX_TXDELAY }}
412 }; 405 };
413 406
414 if (num_TxIntDelay > bd) { 407 adapter->tx_int_delay = TxIntDelay[bd];
415 adapter->tx_int_delay = TxIntDelay[bd]; 408 e1000_validate_option(&adapter->tx_int_delay, &opt, adapter);
416 e1000_validate_option(&adapter->tx_int_delay, &opt,
417 adapter);
418 } else {
419 adapter->tx_int_delay = opt.def;
420 }
421 } 409 }
422 { /* Transmit Absolute Interrupt Delay */ 410 { /* Transmit Absolute Interrupt Delay */
423 struct e1000_option opt = { 411 struct e1000_option opt = {
@@ -429,13 +417,9 @@ e1000_check_options(struct e1000_adapter *adapter)
429 .max = MAX_TXABSDELAY }} 417 .max = MAX_TXABSDELAY }}
430 }; 418 };
431 419
432 if (num_TxAbsIntDelay > bd) { 420 adapter->tx_abs_int_delay = TxAbsIntDelay[bd];
433 adapter->tx_abs_int_delay = TxAbsIntDelay[bd]; 421 e1000_validate_option(&adapter->tx_abs_int_delay, &opt,
434 e1000_validate_option(&adapter->tx_abs_int_delay, &opt, 422 adapter);
435 adapter);
436 } else {
437 adapter->tx_abs_int_delay = opt.def;
438 }
439 } 423 }
440 { /* Receive Interrupt Delay */ 424 { /* Receive Interrupt Delay */
441 struct e1000_option opt = { 425 struct e1000_option opt = {
@@ -447,13 +431,8 @@ e1000_check_options(struct e1000_adapter *adapter)
447 .max = MAX_RXDELAY }} 431 .max = MAX_RXDELAY }}
448 }; 432 };
449 433
450 if (num_RxIntDelay > bd) { 434 adapter->rx_int_delay = RxIntDelay[bd];
451 adapter->rx_int_delay = RxIntDelay[bd]; 435 e1000_validate_option(&adapter->rx_int_delay, &opt, adapter);
452 e1000_validate_option(&adapter->rx_int_delay, &opt,
453 adapter);
454 } else {
455 adapter->rx_int_delay = opt.def;
456 }
457 } 436 }
458 { /* Receive Absolute Interrupt Delay */ 437 { /* Receive Absolute Interrupt Delay */
459 struct e1000_option opt = { 438 struct e1000_option opt = {
@@ -465,13 +444,9 @@ e1000_check_options(struct e1000_adapter *adapter)
465 .max = MAX_RXABSDELAY }} 444 .max = MAX_RXABSDELAY }}
466 }; 445 };
467 446
468 if (num_RxAbsIntDelay > bd) { 447 adapter->rx_abs_int_delay = RxAbsIntDelay[bd];
469 adapter->rx_abs_int_delay = RxAbsIntDelay[bd]; 448 e1000_validate_option(&adapter->rx_abs_int_delay, &opt,
470 e1000_validate_option(&adapter->rx_abs_int_delay, &opt, 449 adapter);
471 adapter);
472 } else {
473 adapter->rx_abs_int_delay = opt.def;
474 }
475 } 450 }
476 { /* Interrupt Throttling Rate */ 451 { /* Interrupt Throttling Rate */
477 struct e1000_option opt = { 452 struct e1000_option opt = {
@@ -483,24 +458,18 @@ e1000_check_options(struct e1000_adapter *adapter)
483 .max = MAX_ITR }} 458 .max = MAX_ITR }}
484 }; 459 };
485 460
486 if (num_InterruptThrottleRate > bd) { 461 adapter->itr = InterruptThrottleRate[bd];
487 adapter->itr = InterruptThrottleRate[bd]; 462 switch (adapter->itr) {
488 switch (adapter->itr) { 463 case 0:
489 case 0: 464 DPRINTK(PROBE, INFO, "%s turned off\n", opt.name);
490 DPRINTK(PROBE, INFO, "%s turned off\n", 465 break;
491 opt.name); 466 case 1:
492 break; 467 DPRINTK(PROBE, INFO, "%s set to dynamic mode\n",
493 case 1: 468 opt.name);
494 DPRINTK(PROBE, INFO, "%s set to dynamic mode\n", 469 break;
495 opt.name); 470 default:
496 break; 471 e1000_validate_option(&adapter->itr, &opt, adapter);
497 default: 472 break;
498 e1000_validate_option(&adapter->itr, &opt,
499 adapter);
500 break;
501 }
502 } else {
503 adapter->itr = opt.def;
504 } 473 }
505 } 474 }
506 { /* Smart Power Down */ 475 { /* Smart Power Down */
@@ -511,13 +480,9 @@ e1000_check_options(struct e1000_adapter *adapter)
511 .def = OPTION_DISABLED 480 .def = OPTION_DISABLED
512 }; 481 };
513 482
514 if (num_SmartPowerDownEnable > bd) { 483 int spd = SmartPowerDownEnable[bd];
515 int spd = SmartPowerDownEnable[bd]; 484 e1000_validate_option(&spd, &opt, adapter);
516 e1000_validate_option(&spd, &opt, adapter); 485 adapter->smart_power_down = spd;
517 adapter->smart_power_down = spd;
518 } else {
519 adapter->smart_power_down = opt.def;
520 }
521 } 486 }
522 487
523 switch (adapter->hw.media_type) { 488 switch (adapter->hw.media_type) {
@@ -544,17 +509,18 @@ static void __devinit
544e1000_check_fiber_options(struct e1000_adapter *adapter) 509e1000_check_fiber_options(struct e1000_adapter *adapter)
545{ 510{
546 int bd = adapter->bd_number; 511 int bd = adapter->bd_number;
547 if (num_Speed > bd) { 512 bd = bd > E1000_MAX_NIC ? E1000_MAX_NIC : bd;
513 if ((Speed[bd] != OPTION_UNSET)) {
548 DPRINTK(PROBE, INFO, "Speed not valid for fiber adapters, " 514 DPRINTK(PROBE, INFO, "Speed not valid for fiber adapters, "
549 "parameter ignored\n"); 515 "parameter ignored\n");
550 } 516 }
551 517
552 if (num_Duplex > bd) { 518 if ((Duplex[bd] != OPTION_UNSET)) {
553 DPRINTK(PROBE, INFO, "Duplex not valid for fiber adapters, " 519 DPRINTK(PROBE, INFO, "Duplex not valid for fiber adapters, "
554 "parameter ignored\n"); 520 "parameter ignored\n");
555 } 521 }
556 522
557 if ((num_AutoNeg > bd) && (AutoNeg[bd] != 0x20)) { 523 if ((AutoNeg[bd] != OPTION_UNSET) && (AutoNeg[bd] != 0x20)) {
558 DPRINTK(PROBE, INFO, "AutoNeg other than 1000/Full is " 524 DPRINTK(PROBE, INFO, "AutoNeg other than 1000/Full is "
559 "not valid for fiber adapters, " 525 "not valid for fiber adapters, "
560 "parameter ignored\n"); 526 "parameter ignored\n");
@@ -573,6 +539,7 @@ e1000_check_copper_options(struct e1000_adapter *adapter)
573{ 539{
574 int speed, dplx, an; 540 int speed, dplx, an;
575 int bd = adapter->bd_number; 541 int bd = adapter->bd_number;
542 bd = bd > E1000_MAX_NIC ? E1000_MAX_NIC : bd;
576 543
577 { /* Speed */ 544 { /* Speed */
578 struct e1000_opt_list speed_list[] = {{ 0, "" }, 545 struct e1000_opt_list speed_list[] = {{ 0, "" },
@@ -589,12 +556,8 @@ e1000_check_copper_options(struct e1000_adapter *adapter)
589 .p = speed_list }} 556 .p = speed_list }}
590 }; 557 };
591 558
592 if (num_Speed > bd) { 559 speed = Speed[bd];
593 speed = Speed[bd]; 560 e1000_validate_option(&speed, &opt, adapter);
594 e1000_validate_option(&speed, &opt, adapter);
595 } else {
596 speed = opt.def;
597 }
598 } 561 }
599 { /* Duplex */ 562 { /* Duplex */
600 struct e1000_opt_list dplx_list[] = {{ 0, "" }, 563 struct e1000_opt_list dplx_list[] = {{ 0, "" },
@@ -616,15 +579,11 @@ e1000_check_copper_options(struct e1000_adapter *adapter)
616 "Speed/Duplex/AutoNeg parameter ignored.\n"); 579 "Speed/Duplex/AutoNeg parameter ignored.\n");
617 return; 580 return;
618 } 581 }
619 if (num_Duplex > bd) { 582 dplx = Duplex[bd];
620 dplx = Duplex[bd]; 583 e1000_validate_option(&dplx, &opt, adapter);
621 e1000_validate_option(&dplx, &opt, adapter);
622 } else {
623 dplx = opt.def;
624 }
625 } 584 }
626 585
627 if ((num_AutoNeg > bd) && (speed != 0 || dplx != 0)) { 586 if (AutoNeg[bd] != OPTION_UNSET && (speed != 0 || dplx != 0)) {
628 DPRINTK(PROBE, INFO, 587 DPRINTK(PROBE, INFO,
629 "AutoNeg specified along with Speed or Duplex, " 588 "AutoNeg specified along with Speed or Duplex, "
630 "parameter ignored\n"); 589 "parameter ignored\n");
@@ -673,19 +632,15 @@ e1000_check_copper_options(struct e1000_adapter *adapter)
673 .p = an_list }} 632 .p = an_list }}
674 }; 633 };
675 634
676 if (num_AutoNeg > bd) { 635 an = AutoNeg[bd];
677 an = AutoNeg[bd]; 636 e1000_validate_option(&an, &opt, adapter);
678 e1000_validate_option(&an, &opt, adapter);
679 } else {
680 an = opt.def;
681 }
682 adapter->hw.autoneg_advertised = an; 637 adapter->hw.autoneg_advertised = an;
683 } 638 }
684 639
685 switch (speed + dplx) { 640 switch (speed + dplx) {
686 case 0: 641 case 0:
687 adapter->hw.autoneg = adapter->fc_autoneg = 1; 642 adapter->hw.autoneg = adapter->fc_autoneg = 1;
688 if ((num_Speed > bd) && (speed != 0 || dplx != 0)) 643 if (Speed[bd] != OPTION_UNSET || Duplex[bd] != OPTION_UNSET)
689 DPRINTK(PROBE, INFO, 644 DPRINTK(PROBE, INFO,
690 "Speed and duplex autonegotiation enabled\n"); 645 "Speed and duplex autonegotiation enabled\n");
691 break; 646 break;