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