atl1_param.c 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203
  1. /*
  2. * Copyright(c) 2005 - 2006 Attansic Corporation. All rights reserved.
  3. * Copyright(c) 2006 Chris Snook <csnook@redhat.com>
  4. * Copyright(c) 2006 Jay Cliburn <jcliburn@gmail.com>
  5. *
  6. * Derived from Intel e1000 driver
  7. * Copyright(c) 1999 - 2005 Intel Corporation. All rights reserved.
  8. *
  9. * This program is free software; you can redistribute it and/or modify it
  10. * under the terms of the GNU General Public License as published by the Free
  11. * Software Foundation; either version 2 of the License, or (at your option)
  12. * any later version.
  13. *
  14. * This program is distributed in the hope that it will be useful, but WITHOUT
  15. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  16. * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
  17. * more details.
  18. *
  19. * You should have received a copy of the GNU General Public License along with
  20. * this program; if not, write to the Free Software Foundation, Inc., 59
  21. * Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  22. */
  23. #include <linux/types.h>
  24. #include <linux/moduleparam.h>
  25. #include <linux/pci.h>
  26. #include "atl1.h"
  27. /*
  28. * This is the only thing that needs to be changed to adjust the
  29. * maximum number of ports that the driver can manage.
  30. */
  31. #define ATL1_MAX_NIC 4
  32. #define OPTION_UNSET -1
  33. #define OPTION_DISABLED 0
  34. #define OPTION_ENABLED 1
  35. #define ATL1_PARAM_INIT { [0 ... ATL1_MAX_NIC] = OPTION_UNSET }
  36. /*
  37. * Interrupt Moderate Timer in units of 2 us
  38. *
  39. * Valid Range: 10-65535
  40. *
  41. * Default Value: 100 (200us)
  42. */
  43. static int __devinitdata int_mod_timer[ATL1_MAX_NIC+1] = ATL1_PARAM_INIT;
  44. static int num_int_mod_timer = 0;
  45. module_param_array_named(int_mod_timer, int_mod_timer, int, &num_int_mod_timer, 0);
  46. MODULE_PARM_DESC(int_mod_timer, "Interrupt moderator timer");
  47. /*
  48. * flash_vendor
  49. *
  50. * Valid Range: 0-2
  51. *
  52. * 0 - Atmel
  53. * 1 - SST
  54. * 2 - ST
  55. *
  56. * Default Value: 0
  57. */
  58. static int __devinitdata flash_vendor[ATL1_MAX_NIC+1] = ATL1_PARAM_INIT;
  59. static int num_flash_vendor = 0;
  60. module_param_array_named(flash_vendor, flash_vendor, int, &num_flash_vendor, 0);
  61. MODULE_PARM_DESC(flash_vendor, "SPI flash vendor");
  62. #define DEFAULT_INT_MOD_CNT 100 /* 200us */
  63. #define MAX_INT_MOD_CNT 65000
  64. #define MIN_INT_MOD_CNT 50
  65. #define FLASH_VENDOR_DEFAULT 0
  66. #define FLASH_VENDOR_MIN 0
  67. #define FLASH_VENDOR_MAX 2
  68. struct atl1_option {
  69. enum { enable_option, range_option, list_option } type;
  70. char *name;
  71. char *err;
  72. int def;
  73. union {
  74. struct { /* range_option info */
  75. int min;
  76. int max;
  77. } r;
  78. struct { /* list_option info */
  79. int nr;
  80. struct atl1_opt_list {
  81. int i;
  82. char *str;
  83. } *p;
  84. } l;
  85. } arg;
  86. };
  87. static int __devinit atl1_validate_option(int *value, struct atl1_option *opt, struct pci_dev *pdev)
  88. {
  89. if (*value == OPTION_UNSET) {
  90. *value = opt->def;
  91. return 0;
  92. }
  93. switch (opt->type) {
  94. case enable_option:
  95. switch (*value) {
  96. case OPTION_ENABLED:
  97. dev_info(&pdev->dev, "%s enabled\n", opt->name);
  98. return 0;
  99. case OPTION_DISABLED:
  100. dev_info(&pdev->dev, "%s disabled\n", opt->name);
  101. return 0;
  102. }
  103. break;
  104. case range_option:
  105. if (*value >= opt->arg.r.min && *value <= opt->arg.r.max) {
  106. dev_info(&pdev->dev, "%s set to %i\n", opt->name,
  107. *value);
  108. return 0;
  109. }
  110. break;
  111. case list_option:{
  112. int i;
  113. struct atl1_opt_list *ent;
  114. for (i = 0; i < opt->arg.l.nr; i++) {
  115. ent = &opt->arg.l.p[i];
  116. if (*value == ent->i) {
  117. if (ent->str[0] != '\0')
  118. dev_info(&pdev->dev, "%s\n",
  119. ent->str);
  120. return 0;
  121. }
  122. }
  123. }
  124. break;
  125. default:
  126. break;
  127. }
  128. dev_info(&pdev->dev, "invalid %s specified (%i) %s\n",
  129. opt->name, *value, opt->err);
  130. *value = opt->def;
  131. return -1;
  132. }
  133. /*
  134. * atl1_check_options - Range Checking for Command Line Parameters
  135. * @adapter: board private structure
  136. *
  137. * This routine checks all command line parameters for valid user
  138. * input. If an invalid value is given, or if no user specified
  139. * value exists, a default value is used. The final value is stored
  140. * in a variable in the adapter structure.
  141. */
  142. void __devinit atl1_check_options(struct atl1_adapter *adapter)
  143. {
  144. struct pci_dev *pdev = adapter->pdev;
  145. int bd = adapter->bd_number;
  146. if (bd >= ATL1_MAX_NIC) {
  147. dev_notice(&pdev->dev, "no configuration for board#%i\n", bd);
  148. dev_notice(&pdev->dev, "using defaults for all values\n");
  149. }
  150. { /* Interrupt Moderate Timer */
  151. struct atl1_option opt = {
  152. .type = range_option,
  153. .name = "Interrupt Moderator Timer",
  154. .err = "using default of "
  155. __MODULE_STRING(DEFAULT_INT_MOD_CNT),
  156. .def = DEFAULT_INT_MOD_CNT,
  157. .arg = {.r =
  158. {.min = MIN_INT_MOD_CNT,.max = MAX_INT_MOD_CNT}}
  159. };
  160. int val;
  161. if (num_int_mod_timer > bd) {
  162. val = int_mod_timer[bd];
  163. atl1_validate_option(&val, &opt, pdev);
  164. adapter->imt = (u16) val;
  165. } else
  166. adapter->imt = (u16) (opt.def);
  167. }
  168. { /* Flash Vendor */
  169. struct atl1_option opt = {
  170. .type = range_option,
  171. .name = "SPI Flash Vendor",
  172. .err = "using default of "
  173. __MODULE_STRING(FLASH_VENDOR_DEFAULT),
  174. .def = DEFAULT_INT_MOD_CNT,
  175. .arg = {.r =
  176. {.min = FLASH_VENDOR_MIN,.max =
  177. FLASH_VENDOR_MAX}}
  178. };
  179. int val;
  180. if (num_flash_vendor > bd) {
  181. val = flash_vendor[bd];
  182. atl1_validate_option(&val, &opt, pdev);
  183. adapter->hw.flash_vendor = (u8) val;
  184. } else
  185. adapter->hw.flash_vendor = (u8) (opt.def);
  186. }
  187. }