e1000: rework module param code with uninitialized values
[pandora-kernel.git] / drivers / net / e1000 / e1000_param.c
1 /*******************************************************************************
2
3   
4   Copyright(c) 1999 - 2006 Intel Corporation. All rights reserved.
5   
6   This program is free software; you can redistribute it and/or modify it 
7   under the terms of the GNU General Public License as published by the Free 
8   Software Foundation; either version 2 of the License, or (at your option) 
9   any later version.
10   
11   This program is distributed in the hope that it will be useful, but WITHOUT 
12   ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 
13   FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for 
14   more details.
15   
16   You should have received a copy of the GNU General Public License along with
17   this program; if not, write to the Free Software Foundation, Inc., 59 
18   Temple Place - Suite 330, Boston, MA  02111-1307, USA.
19   
20   The full GNU General Public License is included in this distribution in the
21   file called LICENSE.
22   
23   Contact Information:
24   Linux NICS <linux.nics@intel.com>
25   e1000-devel Mailing List <e1000-devel@lists.sourceforge.net>
26   Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
27
28 *******************************************************************************/
29
30 #include "e1000.h"
31
32 /* This is the only thing that needs to be changed to adjust the
33  * maximum number of ports that the driver can manage.
34  */
35
36 #define E1000_MAX_NIC 32
37
38 #define OPTION_UNSET   -1
39 #define OPTION_DISABLED 0
40 #define OPTION_ENABLED  1
41
42 /* All parameters are treated the same, as an integer array of values.
43  * This macro just reduces the need to repeat the same declaration code
44  * over and over (plus this helps to avoid typo bugs).
45  */
46
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
58 #define E1000_PARAM(X, desc) \
59         static int __devinitdata X[E1000_MAX_NIC+1] = E1000_PARAM_INIT; \
60         static int num_##X = 0; \
61         module_param_array_named(X, X, int, &num_##X, 0); \
62         MODULE_PARM_DESC(X, desc);
63
64 /* Transmit Descriptor Count
65  *
66  * Valid Range: 80-256 for 82542 and 82543 gigabit ethernet controllers
67  * Valid Range: 80-4096 for 82544 and newer
68  *
69  * Default Value: 256
70  */
71
72 E1000_PARAM(TxDescriptors, "Number of transmit descriptors");
73
74 /* Receive Descriptor Count
75  *
76  * Valid Range: 80-256 for 82542 and 82543 gigabit ethernet controllers
77  * Valid Range: 80-4096 for 82544 and newer
78  *
79  * Default Value: 256
80  */
81
82 E1000_PARAM(RxDescriptors, "Number of receive descriptors");
83
84 /* User Specified Speed Override
85  *
86  * Valid Range: 0, 10, 100, 1000
87  *  - 0    - auto-negotiate at all supported speeds
88  *  - 10   - only link at 10 Mbps
89  *  - 100  - only link at 100 Mbps
90  *  - 1000 - only link at 1000 Mbps
91  *
92  * Default Value: 0
93  */
94
95 E1000_PARAM(Speed, "Speed setting");
96
97 /* User Specified Duplex Override
98  *
99  * Valid Range: 0-2
100  *  - 0 - auto-negotiate for duplex
101  *  - 1 - only link at half duplex
102  *  - 2 - only link at full duplex
103  *
104  * Default Value: 0
105  */
106
107 E1000_PARAM(Duplex, "Duplex setting");
108
109 /* Auto-negotiation Advertisement Override
110  *
111  * Valid Range: 0x01-0x0F, 0x20-0x2F (copper); 0x20 (fiber)
112  *
113  * The AutoNeg value is a bit mask describing which speed and duplex
114  * combinations should be advertised during auto-negotiation.
115  * The supported speed and duplex modes are listed below
116  *
117  * Bit           7     6     5      4      3     2     1      0
118  * Speed (Mbps)  N/A   N/A   1000   N/A    100   100   10     10
119  * Duplex                    Full          Full  Half  Full   Half
120  *
121  * Default Value: 0x2F (copper); 0x20 (fiber)
122  */
123
124 E1000_PARAM(AutoNeg, "Advertised auto-negotiation setting");
125
126 /* User Specified Flow Control Override
127  *
128  * Valid Range: 0-3
129  *  - 0 - No Flow Control
130  *  - 1 - Rx only, respond to PAUSE frames but do not generate them
131  *  - 2 - Tx only, generate PAUSE frames but ignore them on receive
132  *  - 3 - Full Flow Control Support
133  *
134  * Default Value: Read flow control settings from the EEPROM
135  */
136
137 E1000_PARAM(FlowControl, "Flow Control setting");
138
139 /* XsumRX - Receive Checksum Offload Enable/Disable
140  *
141  * Valid Range: 0, 1
142  *  - 0 - disables all checksum offload
143  *  - 1 - enables receive IP/TCP/UDP checksum offload
144  *        on 82543 and newer -based NICs
145  *
146  * Default Value: 1
147  */
148
149 E1000_PARAM(XsumRX, "Disable or enable Receive Checksum offload");
150
151 /* Transmit Interrupt Delay in units of 1.024 microseconds
152  *
153  * Valid Range: 0-65535
154  *
155  * Default Value: 64
156  */
157
158 E1000_PARAM(TxIntDelay, "Transmit Interrupt Delay");
159
160 /* Transmit Absolute Interrupt Delay in units of 1.024 microseconds
161  *
162  * Valid Range: 0-65535
163  *
164  * Default Value: 0
165  */
166
167 E1000_PARAM(TxAbsIntDelay, "Transmit Absolute Interrupt Delay");
168
169 /* Receive Interrupt Delay in units of 1.024 microseconds
170  *
171  * Valid Range: 0-65535
172  *
173  * Default Value: 0
174  */
175
176 E1000_PARAM(RxIntDelay, "Receive Interrupt Delay");
177
178 /* Receive Absolute Interrupt Delay in units of 1.024 microseconds
179  *
180  * Valid Range: 0-65535
181  *
182  * Default Value: 128
183  */
184
185 E1000_PARAM(RxAbsIntDelay, "Receive Absolute Interrupt Delay");
186
187 /* Interrupt Throttle Rate (interrupts/sec)
188  *
189  * Valid Range: 100-100000 (0=off, 1=dynamic)
190  *
191  * Default Value: 8000
192  */
193
194 E1000_PARAM(InterruptThrottleRate, "Interrupt Throttling Rate");
195
196 /* Enable Smart Power Down of the PHY
197  *
198  * Valid Range: 0, 1
199  *
200  * Default Value: 0 (disabled)
201  */
202
203 E1000_PARAM(SmartPowerDownEnable, "Enable PHY smart power down");
204
205 #define AUTONEG_ADV_DEFAULT  0x2F
206 #define AUTONEG_ADV_MASK     0x2F
207 #define FLOW_CONTROL_DEFAULT FLOW_CONTROL_FULL
208
209 #define DEFAULT_RDTR                   0
210 #define MAX_RXDELAY               0xFFFF
211 #define MIN_RXDELAY                    0
212
213 #define DEFAULT_RADV                 128
214 #define MAX_RXABSDELAY            0xFFFF
215 #define MIN_RXABSDELAY                 0
216
217 #define DEFAULT_TIDV                  64
218 #define MAX_TXDELAY               0xFFFF
219 #define MIN_TXDELAY                    0
220
221 #define DEFAULT_TADV                  64
222 #define MAX_TXABSDELAY            0xFFFF
223 #define MIN_TXABSDELAY                 0
224
225 #define DEFAULT_ITR                 8000
226 #define MAX_ITR                   100000
227 #define MIN_ITR                      100
228
229 struct e1000_option {
230         enum { enable_option, range_option, list_option } type;
231         char *name;
232         char *err;
233         int  def;
234         union {
235                 struct { /* range_option info */
236                         int min;
237                         int max;
238                 } r;
239                 struct { /* list_option info */
240                         int nr;
241                         struct e1000_opt_list { int i; char *str; } *p;
242                 } l;
243         } arg;
244 };
245
246 static int __devinit
247 e1000_validate_option(int *value, struct e1000_option *opt,
248                 struct e1000_adapter *adapter)
249 {
250         if (*value == OPTION_UNSET) {
251                 *value = opt->def;
252                 return 0;
253         }
254
255         switch (opt->type) {
256         case enable_option:
257                 switch (*value) {
258                 case OPTION_ENABLED:
259                         DPRINTK(PROBE, INFO, "%s Enabled\n", opt->name);
260                         return 0;
261                 case OPTION_DISABLED:
262                         DPRINTK(PROBE, INFO, "%s Disabled\n", opt->name);
263                         return 0;
264                 }
265                 break;
266         case range_option:
267                 if (*value >= opt->arg.r.min && *value <= opt->arg.r.max) {
268                         DPRINTK(PROBE, INFO,
269                                         "%s set to %i\n", opt->name, *value);
270                         return 0;
271                 }
272                 break;
273         case list_option: {
274                 int i;
275                 struct e1000_opt_list *ent;
276
277                 for (i = 0; i < opt->arg.l.nr; i++) {
278                         ent = &opt->arg.l.p[i];
279                         if (*value == ent->i) {
280                                 if (ent->str[0] != '\0')
281                                         DPRINTK(PROBE, INFO, "%s\n", ent->str);
282                                 return 0;
283                         }
284                 }
285         }
286                 break;
287         default:
288                 BUG();
289         }
290
291         DPRINTK(PROBE, INFO, "Invalid %s value specified (%i) %s\n",
292                opt->name, *value, opt->err);
293         *value = opt->def;
294         return -1;
295 }
296
297 static void e1000_check_fiber_options(struct e1000_adapter *adapter);
298 static void e1000_check_copper_options(struct e1000_adapter *adapter);
299
300 /**
301  * e1000_check_options - Range Checking for Command Line Parameters
302  * @adapter: board private structure
303  *
304  * This routine checks all command line parameters for valid user
305  * input.  If an invalid value is given, or if no user specified
306  * value exists, a default value is used.  The final value is stored
307  * in a variable in the adapter structure.
308  **/
309
310 void __devinit
311 e1000_check_options(struct e1000_adapter *adapter)
312 {
313         int bd = adapter->bd_number;
314         if (bd >= E1000_MAX_NIC) {
315                 DPRINTK(PROBE, NOTICE,
316                        "Warning: no configuration for board #%i\n", bd);
317                 DPRINTK(PROBE, NOTICE, "Using defaults for all values\n");
318                 bd = E1000_MAX_NIC;
319         }
320
321         { /* Transmit Descriptor Count */
322                 struct e1000_option opt = {
323                         .type = range_option,
324                         .name = "Transmit Descriptors",
325                         .err  = "using default of "
326                                 __MODULE_STRING(E1000_DEFAULT_TXD),
327                         .def  = E1000_DEFAULT_TXD,
328                         .arg  = { .r = { .min = E1000_MIN_TXD }}
329                 };
330                 struct e1000_tx_ring *tx_ring = adapter->tx_ring;
331                 int i;
332                 e1000_mac_type mac_type = adapter->hw.mac_type;
333                 opt.arg.r.max = mac_type < e1000_82544 ?
334                         E1000_MAX_TXD : E1000_MAX_82544_TXD;
335
336                 tx_ring->count = TxDescriptors[bd];
337                 e1000_validate_option(&tx_ring->count, &opt, adapter);
338                 E1000_ROUNDUP(tx_ring->count, REQ_TX_DESCRIPTOR_MULTIPLE);
339                 for (i = 0; i < adapter->num_tx_queues; i++)
340                         tx_ring[i].count = tx_ring->count;
341         }
342         { /* Receive Descriptor Count */
343                 struct e1000_option opt = {
344                         .type = range_option,
345                         .name = "Receive Descriptors",
346                         .err  = "using default of "
347                                 __MODULE_STRING(E1000_DEFAULT_RXD),
348                         .def  = E1000_DEFAULT_RXD,
349                         .arg  = { .r = { .min = E1000_MIN_RXD }}
350                 };
351                 struct e1000_rx_ring *rx_ring = adapter->rx_ring;
352                 int i;
353                 e1000_mac_type mac_type = adapter->hw.mac_type;
354                 opt.arg.r.max = mac_type < e1000_82544 ? E1000_MAX_RXD :
355                         E1000_MAX_82544_RXD;
356
357                 rx_ring->count = RxDescriptors[bd];
358                 e1000_validate_option(&rx_ring->count, &opt, adapter);
359                 E1000_ROUNDUP(rx_ring->count, REQ_RX_DESCRIPTOR_MULTIPLE);
360                 for (i = 0; i < adapter->num_rx_queues; i++)
361                         rx_ring[i].count = rx_ring->count;
362         }
363         { /* Checksum Offload Enable/Disable */
364                 struct e1000_option opt = {
365                         .type = enable_option,
366                         .name = "Checksum Offload",
367                         .err  = "defaulting to Enabled",
368                         .def  = OPTION_ENABLED
369                 };
370
371                 int rx_csum = XsumRX[bd];
372                 e1000_validate_option(&rx_csum, &opt, adapter);
373                 adapter->rx_csum = rx_csum;
374         }
375         { /* Flow Control */
376
377                 struct e1000_opt_list fc_list[] =
378                         {{ e1000_fc_none,    "Flow Control Disabled" },
379                          { e1000_fc_rx_pause,"Flow Control Receive Only" },
380                          { e1000_fc_tx_pause,"Flow Control Transmit Only" },
381                          { e1000_fc_full,    "Flow Control Enabled" },
382                          { e1000_fc_default, "Flow Control Hardware Default" }};
383
384                 struct e1000_option opt = {
385                         .type = list_option,
386                         .name = "Flow Control",
387                         .err  = "reading default settings from EEPROM",
388                         .def  = e1000_fc_default,
389                         .arg  = { .l = { .nr = ARRAY_SIZE(fc_list),
390                                          .p = fc_list }}
391                 };
392
393                 int fc = FlowControl[bd];
394                 e1000_validate_option(&fc, &opt, adapter);
395                 adapter->hw.fc = adapter->hw.original_fc = fc;
396         }
397         { /* Transmit Interrupt Delay */
398                 struct e1000_option opt = {
399                         .type = range_option,
400                         .name = "Transmit Interrupt Delay",
401                         .err  = "using default of " __MODULE_STRING(DEFAULT_TIDV),
402                         .def  = DEFAULT_TIDV,
403                         .arg  = { .r = { .min = MIN_TXDELAY,
404                                          .max = MAX_TXDELAY }}
405                 };
406
407                 adapter->tx_int_delay = TxIntDelay[bd];
408                 e1000_validate_option(&adapter->tx_int_delay, &opt, adapter);
409         }
410         { /* Transmit Absolute Interrupt Delay */
411                 struct e1000_option opt = {
412                         .type = range_option,
413                         .name = "Transmit Absolute Interrupt Delay",
414                         .err  = "using default of " __MODULE_STRING(DEFAULT_TADV),
415                         .def  = DEFAULT_TADV,
416                         .arg  = { .r = { .min = MIN_TXABSDELAY,
417                                          .max = MAX_TXABSDELAY }}
418                 };
419
420                 adapter->tx_abs_int_delay = TxAbsIntDelay[bd];
421                 e1000_validate_option(&adapter->tx_abs_int_delay, &opt,
422                                       adapter);
423         }
424         { /* Receive Interrupt Delay */
425                 struct e1000_option opt = {
426                         .type = range_option,
427                         .name = "Receive Interrupt Delay",
428                         .err  = "using default of " __MODULE_STRING(DEFAULT_RDTR),
429                         .def  = DEFAULT_RDTR,
430                         .arg  = { .r = { .min = MIN_RXDELAY,
431                                          .max = MAX_RXDELAY }}
432                 };
433
434                 adapter->rx_int_delay = RxIntDelay[bd];
435                 e1000_validate_option(&adapter->rx_int_delay, &opt, adapter);
436         }
437         { /* Receive Absolute Interrupt Delay */
438                 struct e1000_option opt = {
439                         .type = range_option,
440                         .name = "Receive Absolute Interrupt Delay",
441                         .err  = "using default of " __MODULE_STRING(DEFAULT_RADV),
442                         .def  = DEFAULT_RADV,
443                         .arg  = { .r = { .min = MIN_RXABSDELAY,
444                                          .max = MAX_RXABSDELAY }}
445                 };
446
447                 adapter->rx_abs_int_delay = RxAbsIntDelay[bd];
448                 e1000_validate_option(&adapter->rx_abs_int_delay, &opt,
449                                       adapter);
450         }
451         { /* Interrupt Throttling Rate */
452                 struct e1000_option opt = {
453                         .type = range_option,
454                         .name = "Interrupt Throttling Rate (ints/sec)",
455                         .err  = "using default of " __MODULE_STRING(DEFAULT_ITR),
456                         .def  = DEFAULT_ITR,
457                         .arg  = { .r = { .min = MIN_ITR,
458                                          .max = MAX_ITR }}
459                 };
460
461                 adapter->itr = InterruptThrottleRate[bd];
462                 switch (adapter->itr) {
463                 case 0:
464                         DPRINTK(PROBE, INFO, "%s turned off\n", opt.name);
465                         break;
466                 case 1:
467                         DPRINTK(PROBE, INFO, "%s set to dynamic mode\n",
468                                 opt.name);
469                         break;
470                 default:
471                         e1000_validate_option(&adapter->itr, &opt, adapter);
472                         break;
473                 }
474         }
475         { /* Smart Power Down */
476                 struct e1000_option opt = {
477                         .type = enable_option,
478                         .name = "PHY Smart Power Down",
479                         .err  = "defaulting to Disabled",
480                         .def  = OPTION_DISABLED
481                 };
482
483                 int spd = SmartPowerDownEnable[bd];
484                 e1000_validate_option(&spd, &opt, adapter);
485                 adapter->smart_power_down = spd;
486         }
487
488         switch (adapter->hw.media_type) {
489         case e1000_media_type_fiber:
490         case e1000_media_type_internal_serdes:
491                 e1000_check_fiber_options(adapter);
492                 break;
493         case e1000_media_type_copper:
494                 e1000_check_copper_options(adapter);
495                 break;
496         default:
497                 BUG();
498         }
499 }
500
501 /**
502  * e1000_check_fiber_options - Range Checking for Link Options, Fiber Version
503  * @adapter: board private structure
504  *
505  * Handles speed and duplex options on fiber adapters
506  **/
507
508 static void __devinit
509 e1000_check_fiber_options(struct e1000_adapter *adapter)
510 {
511         int bd = adapter->bd_number;
512         bd = bd > E1000_MAX_NIC ? E1000_MAX_NIC : bd;
513         if ((Speed[bd] != OPTION_UNSET)) {
514                 DPRINTK(PROBE, INFO, "Speed not valid for fiber adapters, "
515                        "parameter ignored\n");
516         }
517
518         if ((Duplex[bd] != OPTION_UNSET)) {
519                 DPRINTK(PROBE, INFO, "Duplex not valid for fiber adapters, "
520                        "parameter ignored\n");
521         }
522
523         if ((AutoNeg[bd] != OPTION_UNSET) && (AutoNeg[bd] != 0x20)) {
524                 DPRINTK(PROBE, INFO, "AutoNeg other than 1000/Full is "
525                                  "not valid for fiber adapters, "
526                                  "parameter ignored\n");
527         }
528 }
529
530 /**
531  * e1000_check_copper_options - Range Checking for Link Options, Copper Version
532  * @adapter: board private structure
533  *
534  * Handles speed and duplex options on copper adapters
535  **/
536
537 static void __devinit
538 e1000_check_copper_options(struct e1000_adapter *adapter)
539 {
540         int speed, dplx, an;
541         int bd = adapter->bd_number;
542         bd = bd > E1000_MAX_NIC ? E1000_MAX_NIC : bd;
543
544         { /* Speed */
545                 struct e1000_opt_list speed_list[] = {{          0, "" },
546                                                       {   SPEED_10, "" },
547                                                       {  SPEED_100, "" },
548                                                       { SPEED_1000, "" }};
549
550                 struct e1000_option opt = {
551                         .type = list_option,
552                         .name = "Speed",
553                         .err  = "parameter ignored",
554                         .def  = 0,
555                         .arg  = { .l = { .nr = ARRAY_SIZE(speed_list),
556                                          .p = speed_list }}
557                 };
558
559                 speed = Speed[bd];
560                 e1000_validate_option(&speed, &opt, adapter);
561         }
562         { /* Duplex */
563                 struct e1000_opt_list dplx_list[] = {{           0, "" },
564                                                      { HALF_DUPLEX, "" },
565                                                      { FULL_DUPLEX, "" }};
566
567                 struct e1000_option opt = {
568                         .type = list_option,
569                         .name = "Duplex",
570                         .err  = "parameter ignored",
571                         .def  = 0,
572                         .arg  = { .l = { .nr = ARRAY_SIZE(dplx_list),
573                                          .p = dplx_list }}
574                 };
575
576                 if (e1000_check_phy_reset_block(&adapter->hw)) {
577                         DPRINTK(PROBE, INFO,
578                                 "Link active due to SoL/IDER Session. "
579                                 "Speed/Duplex/AutoNeg parameter ignored.\n");
580                         return;
581                 }
582                 dplx = Duplex[bd];
583                 e1000_validate_option(&dplx, &opt, adapter);
584         }
585
586         if (AutoNeg[bd] != OPTION_UNSET && (speed != 0 || dplx != 0)) {
587                 DPRINTK(PROBE, INFO,
588                        "AutoNeg specified along with Speed or Duplex, "
589                        "parameter ignored\n");
590                 adapter->hw.autoneg_advertised = AUTONEG_ADV_DEFAULT;
591         } else { /* Autoneg */
592                 struct e1000_opt_list an_list[] =
593                         #define AA "AutoNeg advertising "
594                         {{ 0x01, AA "10/HD" },
595                          { 0x02, AA "10/FD" },
596                          { 0x03, AA "10/FD, 10/HD" },
597                          { 0x04, AA "100/HD" },
598                          { 0x05, AA "100/HD, 10/HD" },
599                          { 0x06, AA "100/HD, 10/FD" },
600                          { 0x07, AA "100/HD, 10/FD, 10/HD" },
601                          { 0x08, AA "100/FD" },
602                          { 0x09, AA "100/FD, 10/HD" },
603                          { 0x0a, AA "100/FD, 10/FD" },
604                          { 0x0b, AA "100/FD, 10/FD, 10/HD" },
605                          { 0x0c, AA "100/FD, 100/HD" },
606                          { 0x0d, AA "100/FD, 100/HD, 10/HD" },
607                          { 0x0e, AA "100/FD, 100/HD, 10/FD" },
608                          { 0x0f, AA "100/FD, 100/HD, 10/FD, 10/HD" },
609                          { 0x20, AA "1000/FD" },
610                          { 0x21, AA "1000/FD, 10/HD" },
611                          { 0x22, AA "1000/FD, 10/FD" },
612                          { 0x23, AA "1000/FD, 10/FD, 10/HD" },
613                          { 0x24, AA "1000/FD, 100/HD" },
614                          { 0x25, AA "1000/FD, 100/HD, 10/HD" },
615                          { 0x26, AA "1000/FD, 100/HD, 10/FD" },
616                          { 0x27, AA "1000/FD, 100/HD, 10/FD, 10/HD" },
617                          { 0x28, AA "1000/FD, 100/FD" },
618                          { 0x29, AA "1000/FD, 100/FD, 10/HD" },
619                          { 0x2a, AA "1000/FD, 100/FD, 10/FD" },
620                          { 0x2b, AA "1000/FD, 100/FD, 10/FD, 10/HD" },
621                          { 0x2c, AA "1000/FD, 100/FD, 100/HD" },
622                          { 0x2d, AA "1000/FD, 100/FD, 100/HD, 10/HD" },
623                          { 0x2e, AA "1000/FD, 100/FD, 100/HD, 10/FD" },
624                          { 0x2f, AA "1000/FD, 100/FD, 100/HD, 10/FD, 10/HD" }};
625
626                 struct e1000_option opt = {
627                         .type = list_option,
628                         .name = "AutoNeg",
629                         .err  = "parameter ignored",
630                         .def  = AUTONEG_ADV_DEFAULT,
631                         .arg  = { .l = { .nr = ARRAY_SIZE(an_list),
632                                          .p = an_list }}
633                 };
634
635                 an = AutoNeg[bd];
636                 e1000_validate_option(&an, &opt, adapter);
637                 adapter->hw.autoneg_advertised = an;
638         }
639
640         switch (speed + dplx) {
641         case 0:
642                 adapter->hw.autoneg = adapter->fc_autoneg = 1;
643                 if (Speed[bd] != OPTION_UNSET || Duplex[bd] != OPTION_UNSET)
644                         DPRINTK(PROBE, INFO,
645                                "Speed and duplex autonegotiation enabled\n");
646                 break;
647         case HALF_DUPLEX:
648                 DPRINTK(PROBE, INFO, "Half Duplex specified without Speed\n");
649                 DPRINTK(PROBE, INFO, "Using Autonegotiation at "
650                         "Half Duplex only\n");
651                 adapter->hw.autoneg = adapter->fc_autoneg = 1;
652                 adapter->hw.autoneg_advertised = ADVERTISE_10_HALF |
653                                                  ADVERTISE_100_HALF;
654                 break;
655         case FULL_DUPLEX:
656                 DPRINTK(PROBE, INFO, "Full Duplex specified without Speed\n");
657                 DPRINTK(PROBE, INFO, "Using Autonegotiation at "
658                         "Full Duplex only\n");
659                 adapter->hw.autoneg = adapter->fc_autoneg = 1;
660                 adapter->hw.autoneg_advertised = ADVERTISE_10_FULL |
661                                                  ADVERTISE_100_FULL |
662                                                  ADVERTISE_1000_FULL;
663                 break;
664         case SPEED_10:
665                 DPRINTK(PROBE, INFO, "10 Mbps Speed specified "
666                         "without Duplex\n");
667                 DPRINTK(PROBE, INFO, "Using Autonegotiation at 10 Mbps only\n");
668                 adapter->hw.autoneg = adapter->fc_autoneg = 1;
669                 adapter->hw.autoneg_advertised = ADVERTISE_10_HALF |
670                                                  ADVERTISE_10_FULL;
671                 break;
672         case SPEED_10 + HALF_DUPLEX:
673                 DPRINTK(PROBE, INFO, "Forcing to 10 Mbps Half Duplex\n");
674                 adapter->hw.autoneg = adapter->fc_autoneg = 0;
675                 adapter->hw.forced_speed_duplex = e1000_10_half;
676                 adapter->hw.autoneg_advertised = 0;
677                 break;
678         case SPEED_10 + FULL_DUPLEX:
679                 DPRINTK(PROBE, INFO, "Forcing to 10 Mbps Full Duplex\n");
680                 adapter->hw.autoneg = adapter->fc_autoneg = 0;
681                 adapter->hw.forced_speed_duplex = e1000_10_full;
682                 adapter->hw.autoneg_advertised = 0;
683                 break;
684         case SPEED_100:
685                 DPRINTK(PROBE, INFO, "100 Mbps Speed specified "
686                         "without Duplex\n");
687                 DPRINTK(PROBE, INFO, "Using Autonegotiation at "
688                         "100 Mbps only\n");
689                 adapter->hw.autoneg = adapter->fc_autoneg = 1;
690                 adapter->hw.autoneg_advertised = ADVERTISE_100_HALF |
691                                                  ADVERTISE_100_FULL;
692                 break;
693         case SPEED_100 + HALF_DUPLEX:
694                 DPRINTK(PROBE, INFO, "Forcing to 100 Mbps Half Duplex\n");
695                 adapter->hw.autoneg = adapter->fc_autoneg = 0;
696                 adapter->hw.forced_speed_duplex = e1000_100_half;
697                 adapter->hw.autoneg_advertised = 0;
698                 break;
699         case SPEED_100 + FULL_DUPLEX:
700                 DPRINTK(PROBE, INFO, "Forcing to 100 Mbps Full Duplex\n");
701                 adapter->hw.autoneg = adapter->fc_autoneg = 0;
702                 adapter->hw.forced_speed_duplex = e1000_100_full;
703                 adapter->hw.autoneg_advertised = 0;
704                 break;
705         case SPEED_1000:
706                 DPRINTK(PROBE, INFO, "1000 Mbps Speed specified without "
707                         "Duplex\n");
708                 DPRINTK(PROBE, INFO,
709                         "Using Autonegotiation at 1000 Mbps "
710                         "Full Duplex only\n");
711                 adapter->hw.autoneg = adapter->fc_autoneg = 1;
712                 adapter->hw.autoneg_advertised = ADVERTISE_1000_FULL;
713                 break;
714         case SPEED_1000 + HALF_DUPLEX:
715                 DPRINTK(PROBE, INFO,
716                         "Half Duplex is not supported at 1000 Mbps\n");
717                 DPRINTK(PROBE, INFO,
718                         "Using Autonegotiation at 1000 Mbps "
719                         "Full Duplex only\n");
720                 adapter->hw.autoneg = adapter->fc_autoneg = 1;
721                 adapter->hw.autoneg_advertised = ADVERTISE_1000_FULL;
722                 break;
723         case SPEED_1000 + FULL_DUPLEX:
724                 DPRINTK(PROBE, INFO,
725                        "Using Autonegotiation at 1000 Mbps Full Duplex only\n");
726                 adapter->hw.autoneg = adapter->fc_autoneg = 1;
727                 adapter->hw.autoneg_advertised = ADVERTISE_1000_FULL;
728                 break;
729         default:
730                 BUG();
731         }
732
733         /* Speed, AutoNeg and MDI/MDI-X must all play nice */
734         if (e1000_validate_mdi_setting(&(adapter->hw)) < 0) {
735                 DPRINTK(PROBE, INFO,
736                         "Speed, AutoNeg and MDI-X specifications are "
737                         "incompatible. Setting MDI-X to a compatible value.\n");
738         }
739 }
740