1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21#include "pch_gbe.h"
22#include <linux/module.h>
23
24#define OPTION_UNSET -1
25#define OPTION_DISABLED 0
26#define OPTION_ENABLED 1
27
28
29
30
31
32
33static int TxDescriptors = OPTION_UNSET;
34module_param(TxDescriptors, int, 0);
35MODULE_PARM_DESC(TxDescriptors, "Number of transmit descriptors");
36
37
38
39
40
41
42static int RxDescriptors = OPTION_UNSET;
43module_param(RxDescriptors, int, 0);
44MODULE_PARM_DESC(RxDescriptors, "Number of receive descriptors");
45
46
47
48
49
50
51
52
53
54
55static int Speed = OPTION_UNSET;
56module_param(Speed, int, 0);
57MODULE_PARM_DESC(Speed, "Speed setting");
58
59
60
61
62
63
64
65
66
67static int Duplex = OPTION_UNSET;
68module_param(Duplex, int, 0);
69MODULE_PARM_DESC(Duplex, "Duplex setting");
70
71#define HALF_DUPLEX 1
72#define FULL_DUPLEX 2
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88static int AutoNeg = OPTION_UNSET;
89module_param(AutoNeg, int, 0);
90MODULE_PARM_DESC(AutoNeg, "Advertised auto-negotiation setting");
91
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
97#define PHY_ADVERTISE_1000_FULL 0x0020
98#define PCH_AUTONEG_ADVERTISE_DEFAULT 0x2F
99
100
101
102
103
104
105
106
107
108
109static int FlowControl = OPTION_UNSET;
110module_param(FlowControl, int, 0);
111MODULE_PARM_DESC(FlowControl, "Flow Control setting");
112
113
114
115
116
117
118
119
120static int XsumRX = OPTION_UNSET;
121module_param(XsumRX, int, 0);
122MODULE_PARM_DESC(XsumRX, "Disable or enable Receive Checksum offload");
123
124#define PCH_GBE_DEFAULT_RX_CSUM true
125
126
127
128
129
130
131
132
133static int XsumTX = OPTION_UNSET;
134module_param(XsumTX, int, 0);
135MODULE_PARM_DESC(XsumTX, "Disable or enable Transmit Checksum offload");
136
137#define PCH_GBE_DEFAULT_TX_CSUM true
138
139
140
141
142
143
144
145
146struct pch_gbe_option {
147 enum { enable_option, range_option, list_option } type;
148 char *name;
149 char *err;
150 int def;
151 union {
152 struct {
153 int min;
154 int max;
155 } r;
156 struct {
157 int nr;
158 const struct pch_gbe_opt_list { int i; char *str; } *p;
159 } l;
160 } arg;
161};
162
163static const struct pch_gbe_opt_list speed_list[] = {
164 { 0, "" },
165 { SPEED_10, "" },
166 { SPEED_100, "" },
167 { SPEED_1000, "" }
168};
169
170static const struct pch_gbe_opt_list dplx_list[] = {
171 { 0, "" },
172 { HALF_DUPLEX, "" },
173 { FULL_DUPLEX, "" }
174};
175
176static 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" }
209};
210
211static 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" }
216};
217
218
219
220
221
222
223
224
225
226
227static int pch_gbe_validate_option(int *value,
228 const struct pch_gbe_option *opt,
229 struct pch_gbe_adapter *adapter)
230{
231 if (*value == OPTION_UNSET) {
232 *value = opt->def;
233 return 0;
234 }
235
236 switch (opt->type) {
237 case enable_option:
238 switch (*value) {
239 case OPTION_ENABLED:
240 pr_debug("%s Enabled\n", opt->name);
241 return 0;
242 case OPTION_DISABLED:
243 pr_debug("%s Disabled\n", opt->name);
244 return 0;
245 }
246 break;
247 case range_option:
248 if (*value >= opt->arg.r.min && *value <= opt->arg.r.max) {
249 pr_debug("%s set to %i\n", opt->name, *value);
250 return 0;
251 }
252 break;
253 case list_option: {
254 int i;
255 const struct pch_gbe_opt_list *ent;
256
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 pr_debug("%s\n", ent->str);
262 return 0;
263 }
264 }
265 }
266 break;
267 default:
268 BUG();
269 }
270
271 pr_debug("Invalid %s value specified (%i) %s\n",
272 opt->name, *value, opt->err);
273 *value = opt->def;
274 return -1;
275}
276
277
278
279
280
281static void pch_gbe_check_copper_options(struct pch_gbe_adapter *adapter)
282{
283 struct pch_gbe_hw *hw = &adapter->hw;
284 int speed, dplx;
285
286 {
287 static const struct pch_gbe_option opt = {
288 .type = list_option,
289 .name = "Speed",
290 .err = "parameter ignored",
291 .def = 0,
292 .arg = { .l = { .nr = (int)ARRAY_SIZE(speed_list),
293 .p = speed_list } }
294 };
295 speed = Speed;
296 pch_gbe_validate_option(&speed, &opt, adapter);
297 }
298 {
299 static const struct pch_gbe_option opt = {
300 .type = list_option,
301 .name = "Duplex",
302 .err = "parameter ignored",
303 .def = 0,
304 .arg = { .l = { .nr = (int)ARRAY_SIZE(dplx_list),
305 .p = dplx_list } }
306 };
307 dplx = Duplex;
308 pch_gbe_validate_option(&dplx, &opt, adapter);
309 }
310
311 {
312 static const struct pch_gbe_option opt = {
313 .type = list_option,
314 .name = "AutoNeg",
315 .err = "parameter ignored",
316 .def = PCH_AUTONEG_ADVERTISE_DEFAULT,
317 .arg = { .l = { .nr = (int)ARRAY_SIZE(an_list),
318 .p = an_list} }
319 };
320 if (speed || dplx) {
321 pr_debug("AutoNeg specified along with Speed or Duplex, AutoNeg parameter ignored\n");
322 hw->phy.autoneg_advertised = opt.def;
323 } else {
324 int tmp = AutoNeg;
325
326 pch_gbe_validate_option(&tmp, &opt, adapter);
327 hw->phy.autoneg_advertised = tmp;
328 }
329 }
330
331 switch (speed + dplx) {
332 case 0:
333 hw->mac.autoneg = hw->mac.fc_autoneg = 1;
334 if ((speed || dplx))
335 pr_debug("Speed and duplex autonegotiation enabled\n");
336 hw->mac.link_speed = SPEED_10;
337 hw->mac.link_duplex = DUPLEX_HALF;
338 break;
339 case HALF_DUPLEX:
340 pr_debug("Half Duplex specified without Speed\n");
341 pr_debug("Using Autonegotiation at Half Duplex only\n");
342 hw->mac.autoneg = hw->mac.fc_autoneg = 1;
343 hw->phy.autoneg_advertised = PHY_ADVERTISE_10_HALF |
344 PHY_ADVERTISE_100_HALF;
345 hw->mac.link_speed = SPEED_10;
346 hw->mac.link_duplex = DUPLEX_HALF;
347 break;
348 case FULL_DUPLEX:
349 pr_debug("Full Duplex specified without Speed\n");
350 pr_debug("Using Autonegotiation at Full Duplex only\n");
351 hw->mac.autoneg = hw->mac.fc_autoneg = 1;
352 hw->phy.autoneg_advertised = PHY_ADVERTISE_10_FULL |
353 PHY_ADVERTISE_100_FULL |
354 PHY_ADVERTISE_1000_FULL;
355 hw->mac.link_speed = SPEED_10;
356 hw->mac.link_duplex = DUPLEX_FULL;
357 break;
358 case SPEED_10:
359 pr_debug("10 Mbps Speed specified without Duplex\n");
360 pr_debug("Using Autonegotiation at 10 Mbps only\n");
361 hw->mac.autoneg = hw->mac.fc_autoneg = 1;
362 hw->phy.autoneg_advertised = PHY_ADVERTISE_10_HALF |
363 PHY_ADVERTISE_10_FULL;
364 hw->mac.link_speed = SPEED_10;
365 hw->mac.link_duplex = DUPLEX_HALF;
366 break;
367 case SPEED_10 + HALF_DUPLEX:
368 pr_debug("Forcing to 10 Mbps Half Duplex\n");
369 hw->mac.autoneg = hw->mac.fc_autoneg = 0;
370 hw->phy.autoneg_advertised = 0;
371 hw->mac.link_speed = SPEED_10;
372 hw->mac.link_duplex = DUPLEX_HALF;
373 break;
374 case SPEED_10 + FULL_DUPLEX:
375 pr_debug("Forcing to 10 Mbps Full Duplex\n");
376 hw->mac.autoneg = hw->mac.fc_autoneg = 0;
377 hw->phy.autoneg_advertised = 0;
378 hw->mac.link_speed = SPEED_10;
379 hw->mac.link_duplex = DUPLEX_FULL;
380 break;
381 case SPEED_100:
382 pr_debug("100 Mbps Speed specified without Duplex\n");
383 pr_debug("Using Autonegotiation at 100 Mbps only\n");
384 hw->mac.autoneg = hw->mac.fc_autoneg = 1;
385 hw->phy.autoneg_advertised = PHY_ADVERTISE_100_HALF |
386 PHY_ADVERTISE_100_FULL;
387 hw->mac.link_speed = SPEED_100;
388 hw->mac.link_duplex = DUPLEX_HALF;
389 break;
390 case SPEED_100 + HALF_DUPLEX:
391 pr_debug("Forcing to 100 Mbps Half Duplex\n");
392 hw->mac.autoneg = hw->mac.fc_autoneg = 0;
393 hw->phy.autoneg_advertised = 0;
394 hw->mac.link_speed = SPEED_100;
395 hw->mac.link_duplex = DUPLEX_HALF;
396 break;
397 case SPEED_100 + FULL_DUPLEX:
398 pr_debug("Forcing to 100 Mbps Full Duplex\n");
399 hw->mac.autoneg = hw->mac.fc_autoneg = 0;
400 hw->phy.autoneg_advertised = 0;
401 hw->mac.link_speed = SPEED_100;
402 hw->mac.link_duplex = DUPLEX_FULL;
403 break;
404 case SPEED_1000:
405 pr_debug("1000 Mbps Speed specified without Duplex\n");
406 goto full_duplex_only;
407 case SPEED_1000 + HALF_DUPLEX:
408 pr_debug("Half Duplex is not supported at 1000 Mbps\n");
409
410 case SPEED_1000 + FULL_DUPLEX:
411full_duplex_only:
412 pr_debug("Using Autonegotiation at 1000 Mbps Full Duplex only\n");
413 hw->mac.autoneg = hw->mac.fc_autoneg = 1;
414 hw->phy.autoneg_advertised = PHY_ADVERTISE_1000_FULL;
415 hw->mac.link_speed = SPEED_1000;
416 hw->mac.link_duplex = DUPLEX_FULL;
417 break;
418 default:
419 BUG();
420 }
421}
422
423
424
425
426
427void pch_gbe_check_options(struct pch_gbe_adapter *adapter)
428{
429 struct pch_gbe_hw *hw = &adapter->hw;
430 struct net_device *dev = adapter->netdev;
431 int val;
432
433 {
434 static const struct pch_gbe_option opt = {
435 .type = range_option,
436 .name = "Transmit Descriptors",
437 .err = "using default of "
438 __MODULE_STRING(PCH_GBE_DEFAULT_TXD),
439 .def = PCH_GBE_DEFAULT_TXD,
440 .arg = { .r = { .min = PCH_GBE_MIN_TXD,
441 .max = PCH_GBE_MAX_TXD } }
442 };
443 struct pch_gbe_tx_ring *tx_ring = adapter->tx_ring;
444 tx_ring->count = TxDescriptors;
445 pch_gbe_validate_option(&tx_ring->count, &opt, adapter);
446 tx_ring->count = roundup(tx_ring->count,
447 PCH_GBE_TX_DESC_MULTIPLE);
448 }
449 {
450 static const struct pch_gbe_option opt = {
451 .type = range_option,
452 .name = "Receive Descriptors",
453 .err = "using default of "
454 __MODULE_STRING(PCH_GBE_DEFAULT_RXD),
455 .def = PCH_GBE_DEFAULT_RXD,
456 .arg = { .r = { .min = PCH_GBE_MIN_RXD,
457 .max = PCH_GBE_MAX_RXD } }
458 };
459 struct pch_gbe_rx_ring *rx_ring = adapter->rx_ring;
460 rx_ring->count = RxDescriptors;
461 pch_gbe_validate_option(&rx_ring->count, &opt, adapter);
462 rx_ring->count = roundup(rx_ring->count,
463 PCH_GBE_RX_DESC_MULTIPLE);
464 }
465 {
466 static const struct pch_gbe_option opt = {
467 .type = enable_option,
468 .name = "Checksum Offload",
469 .err = "defaulting to Enabled",
470 .def = PCH_GBE_DEFAULT_RX_CSUM
471 };
472 val = XsumRX;
473 pch_gbe_validate_option(&val, &opt, adapter);
474 if (!val)
475 dev->features &= ~NETIF_F_RXCSUM;
476 }
477 {
478 static const struct pch_gbe_option opt = {
479 .type = enable_option,
480 .name = "Checksum Offload",
481 .err = "defaulting to Enabled",
482 .def = PCH_GBE_DEFAULT_TX_CSUM
483 };
484 val = XsumTX;
485 pch_gbe_validate_option(&val, &opt, adapter);
486 if (!val)
487 dev->features &= ~NETIF_F_ALL_CSUM;
488 }
489 {
490 static const struct pch_gbe_option opt = {
491 .type = list_option,
492 .name = "Flow Control",
493 .err = "reading default settings from EEPROM",
494 .def = PCH_GBE_FC_DEFAULT,
495 .arg = { .l = { .nr = (int)ARRAY_SIZE(fc_list),
496 .p = fc_list } }
497 };
498 int tmp = FlowControl;
499
500 pch_gbe_validate_option(&tmp, &opt, adapter);
501 hw->mac.fc = tmp;
502 }
503
504 pch_gbe_check_copper_options(adapter);
505}
506