Linux Kernel  3.7.1
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
pch_gbe_param.c
Go to the documentation of this file.
1 /*
2  * Copyright (C) 1999 - 2010 Intel Corporation.
3  * Copyright (C) 2010 OKI SEMICONDUCTOR Co., LTD.
4  *
5  * This code was derived from the Intel e1000e Linux driver.
6  *
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.
10  *
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.
15  *
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.
19  */
20 
21 #include "pch_gbe.h"
22 #include <linux/module.h> /* for __MODULE_STRING */
23 
24 #define OPTION_UNSET -1
25 #define OPTION_DISABLED 0
26 #define OPTION_ENABLED 1
27 
33 static int TxDescriptors = OPTION_UNSET;
34 module_param(TxDescriptors, int, 0);
35 MODULE_PARM_DESC(TxDescriptors, "Number of transmit descriptors");
36 
42 static int RxDescriptors = OPTION_UNSET;
43 module_param(RxDescriptors, int, 0);
44 MODULE_PARM_DESC(RxDescriptors, "Number of receive descriptors");
45 
55 static int Speed = OPTION_UNSET;
56 module_param(Speed, int, 0);
57 MODULE_PARM_DESC(Speed, "Speed setting");
58 
67 static int Duplex = OPTION_UNSET;
68 module_param(Duplex, int, 0);
69 MODULE_PARM_DESC(Duplex, "Duplex setting");
70 
71 #define HALF_DUPLEX 1
72 #define FULL_DUPLEX 2
73 
88 static int AutoNeg = OPTION_UNSET;
89 module_param(AutoNeg, int, 0);
90 MODULE_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 /* Not used, just FYI */
97 #define PHY_ADVERTISE_1000_FULL 0x0020
98 #define PCH_AUTONEG_ADVERTISE_DEFAULT 0x2F
99 
109 static int FlowControl = OPTION_UNSET;
110 module_param(FlowControl, int, 0);
111 MODULE_PARM_DESC(FlowControl, "Flow Control setting");
112 
113 /*
114  * XsumRX - Receive Checksum Offload Enable/Disable
115  * @Valid Range: 0, 1
116  * - 0: disables all checksum offload
117  * - 1: enables receive IP/TCP/UDP checksum offload
118  * @Default Value: PCH_GBE_DEFAULT_RX_CSUM
119  */
120 static int XsumRX = OPTION_UNSET;
121 module_param(XsumRX, int, 0);
122 MODULE_PARM_DESC(XsumRX, "Disable or enable Receive Checksum offload");
123 
124 #define PCH_GBE_DEFAULT_RX_CSUM true /* trueorfalse */
125 
126 /*
127  * XsumTX - Transmit Checksum Offload Enable/Disable
128  * @Valid Range: 0, 1
129  * - 0: disables all checksum offload
130  * - 1: enables transmit IP/TCP/UDP checksum offload
131  * @Default Value: PCH_GBE_DEFAULT_TX_CSUM
132  */
133 static int XsumTX = OPTION_UNSET;
134 module_param(XsumTX, int, 0);
135 MODULE_PARM_DESC(XsumTX, "Disable or enable Transmit Checksum offload");
136 
137 #define PCH_GBE_DEFAULT_TX_CSUM true /* trueorfalse */
138 
148  char *name;
149  char *err;
150  int def;
151  union {
152  struct { /* range_option info */
153  int min;
154  int max;
155  } r;
156  struct { /* list_option info */
157  int nr;
158  const struct pch_gbe_opt_list { int i; char *str; } *p;
159  } l;
160  } arg;
161 };
162 
163 static const struct pch_gbe_opt_list speed_list[] = {
164  { 0, "" },
165  { SPEED_10, "" },
166  { SPEED_100, "" },
167  { SPEED_1000, "" }
168 };
169 
170 static const struct pch_gbe_opt_list dplx_list[] = {
171  { 0, "" },
172  { HALF_DUPLEX, "" },
173  { FULL_DUPLEX, "" }
174 };
175 
176 static 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 
211 static 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 
227 static 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 
281 static 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  { /* Speed */
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  { /* Duplex */
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  { /* Autoneg */
312  static const struct pch_gbe_option opt = {
313  .type = list_option,
314  .name = "AutoNeg",
315  .err = "parameter ignored",
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 |
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 |
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 |
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 |
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  /* fall through */
410  case SPEED_1000 + FULL_DUPLEX:
411 full_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 
428 {
429  struct pch_gbe_hw *hw = &adapter->hw;
430  struct net_device *dev = adapter->netdev;
431  int val;
432 
433  { /* Transmit Descriptor Count */
434  static const struct pch_gbe_option opt = {
435  .type = range_option,
436  .name = "Transmit Descriptors",
437  .err = "using default of "
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,
448  }
449  { /* Receive Descriptor Count */
450  static const struct pch_gbe_option opt = {
451  .type = range_option,
452  .name = "Receive Descriptors",
453  .err = "using default of "
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,
464  }
465  { /* Checksum Offload Enable/Disable */
466  static const struct pch_gbe_option opt = {
467  .type = enable_option,
468  .name = "Checksum Offload",
469  .err = "defaulting to Enabled",
471  };
472  val = XsumRX;
473  pch_gbe_validate_option(&val, &opt, adapter);
474  if (!val)
475  dev->features &= ~NETIF_F_RXCSUM;
476  }
477  { /* Checksum Offload Enable/Disable */
478  static const struct pch_gbe_option opt = {
479  .type = enable_option,
480  .name = "Checksum Offload",
481  .err = "defaulting to Enabled",
483  };
484  val = XsumTX;
485  pch_gbe_validate_option(&val, &opt, adapter);
486  if (!val)
487  dev->features &= ~NETIF_F_ALL_CSUM;
488  }
489  { /* Flow Control */
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 }