atl1_param.c 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205
  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 "atl1.h"
  26. /*
  27. * This is the only thing that needs to be changed to adjust the
  28. * maximum number of ports that the driver can manage.
  29. */
  30. #define ATL1_MAX_NIC 4
  31. #define OPTION_UNSET -1
  32. #define OPTION_DISABLED 0
  33. #define OPTION_ENABLED 1
  34. #define ATL1_PARAM_INIT { [0 ... ATL1_MAX_NIC] = OPTION_UNSET }
  35. /*
  36. * Interrupt Moderate Timer in units of 2 us
  37. *
  38. * Valid Range: 10-65535
  39. *
  40. * Default Value: 100 (200us)
  41. */
  42. static int __devinitdata int_mod_timer[ATL1_MAX_NIC+1] = ATL1_PARAM_INIT;
  43. static int num_int_mod_timer = 0;
  44. module_param_array_named(int_mod_timer, int_mod_timer, int, &num_int_mod_timer, 0);
  45. MODULE_PARM_DESC(int_mod_timer, "Interrupt moderator timer");
  46. /*
  47. * flash_vendor
  48. *
  49. * Valid Range: 0-2
  50. *
  51. * 0 - Atmel
  52. * 1 - SST
  53. * 2 - ST
  54. *
  55. * Default Value: 0
  56. */
  57. static int __devinitdata flash_vendor[ATL1_MAX_NIC+1] = ATL1_PARAM_INIT;
  58. static int num_flash_vendor = 0;
  59. module_param_array_named(flash_vendor, flash_vendor, int, &num_flash_vendor, 0);
  60. MODULE_PARM_DESC(flash_vendor, "SPI flash vendor");
  61. #define DEFAULT_INT_MOD_CNT 100 /* 200us */
  62. #define MAX_INT_MOD_CNT 65000
  63. #define MIN_INT_MOD_CNT 50
  64. #define FLASH_VENDOR_DEFAULT 0
  65. #define FLASH_VENDOR_MIN 0
  66. #define FLASH_VENDOR_MAX 2
  67. struct atl1_option {
  68. enum { enable_option, range_option, list_option } type;
  69. char *name;
  70. char *err;
  71. int def;
  72. union {
  73. struct { /* range_option info */
  74. int min;
  75. int max;
  76. } r;
  77. struct { /* list_option info */
  78. int nr;
  79. struct atl1_opt_list {
  80. int i;
  81. char *str;
  82. } *p;
  83. } l;
  84. } arg;
  85. };
  86. static int __devinit atl1_validate_option(int *value, struct atl1_option *opt)
  87. {
  88. if (*value == OPTION_UNSET) {
  89. *value = opt->def;
  90. return 0;
  91. }
  92. switch (opt->type) {
  93. case enable_option:
  94. switch (*value) {
  95. case OPTION_ENABLED:
  96. printk(KERN_INFO "%s: %s Enabled\n", atl1_driver_name,
  97. opt->name);
  98. return 0;
  99. case OPTION_DISABLED:
  100. printk(KERN_INFO "%s: %s Disabled\n", atl1_driver_name,
  101. opt->name);
  102. return 0;
  103. }
  104. break;
  105. case range_option:
  106. if (*value >= opt->arg.r.min && *value <= opt->arg.r.max) {
  107. printk(KERN_INFO "%s: %s set to %i\n",
  108. atl1_driver_name, opt->name, *value);
  109. return 0;
  110. }
  111. break;
  112. case list_option:{
  113. int i;
  114. struct atl1_opt_list *ent;
  115. for (i = 0; i < opt->arg.l.nr; i++) {
  116. ent = &opt->arg.l.p[i];
  117. if (*value == ent->i) {
  118. if (ent->str[0] != '\0')
  119. printk(KERN_INFO "%s: %s\n",
  120. atl1_driver_name, ent->str);
  121. return 0;
  122. }
  123. }
  124. }
  125. break;
  126. default:
  127. break;
  128. }
  129. printk(KERN_INFO "%s: invalid %s specified (%i) %s\n",
  130. atl1_driver_name, opt->name, *value, opt->err);
  131. *value = opt->def;
  132. return -1;
  133. }
  134. /*
  135. * atl1_check_options - Range Checking for Command Line Parameters
  136. * @adapter: board private structure
  137. *
  138. * This routine checks all command line parameters for valid user
  139. * input. If an invalid value is given, or if no user specified
  140. * value exists, a default value is used. The final value is stored
  141. * in a variable in the adapter structure.
  142. */
  143. void __devinit atl1_check_options(struct atl1_adapter *adapter)
  144. {
  145. int bd = adapter->bd_number;
  146. if (bd >= ATL1_MAX_NIC) {
  147. printk(KERN_NOTICE "%s: warning: no configuration for board #%i\n",
  148. atl1_driver_name, bd);
  149. printk(KERN_NOTICE "%s: using defaults for all values\n",
  150. atl1_driver_name);
  151. }
  152. { /* Interrupt Moderate Timer */
  153. struct atl1_option opt = {
  154. .type = range_option,
  155. .name = "Interrupt Moderator Timer",
  156. .err = "using default of "
  157. __MODULE_STRING(DEFAULT_INT_MOD_CNT),
  158. .def = DEFAULT_INT_MOD_CNT,
  159. .arg = {.r =
  160. {.min = MIN_INT_MOD_CNT,.max = MAX_INT_MOD_CNT}}
  161. };
  162. int val;
  163. if (num_int_mod_timer > bd) {
  164. val = int_mod_timer[bd];
  165. atl1_validate_option(&val, &opt);
  166. adapter->imt = (u16) val;
  167. } else
  168. adapter->imt = (u16) (opt.def);
  169. }
  170. { /* Flash Vendor */
  171. struct atl1_option opt = {
  172. .type = range_option,
  173. .name = "SPI Flash Vendor",
  174. .err = "using default of "
  175. __MODULE_STRING(FLASH_VENDOR_DEFAULT),
  176. .def = DEFAULT_INT_MOD_CNT,
  177. .arg = {.r =
  178. {.min = FLASH_VENDOR_MIN,.max =
  179. FLASH_VENDOR_MAX}}
  180. };
  181. int val;
  182. if (num_flash_vendor > bd) {
  183. val = flash_vendor[bd];
  184. atl1_validate_option(&val, &opt);
  185. adapter->hw.flash_vendor = (u8) val;
  186. } else
  187. adapter->hw.flash_vendor = (u8) (opt.def);
  188. }
  189. }