param.c 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385
  1. /*******************************************************************************
  2. Intel PRO/1000 Linux driver
  3. Copyright(c) 1999 - 2008 Intel Corporation.
  4. This program is free software; you can redistribute it and/or modify it
  5. under the terms and conditions of the GNU General Public License,
  6. version 2, as published by the Free Software Foundation.
  7. This program is distributed in the hope it will be useful, but WITHOUT
  8. ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  9. FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
  10. more details.
  11. You should have received a copy of the GNU General Public License along with
  12. this program; if not, write to the Free Software Foundation, Inc.,
  13. 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
  14. The full GNU General Public License is included in this distribution in
  15. the file called "COPYING".
  16. Contact Information:
  17. Linux NICS <linux.nics@intel.com>
  18. e1000-devel Mailing List <e1000-devel@lists.sourceforge.net>
  19. Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
  20. *******************************************************************************/
  21. #include <linux/netdevice.h>
  22. #include "e1000.h"
  23. /*
  24. * This is the only thing that needs to be changed to adjust the
  25. * maximum number of ports that the driver can manage.
  26. */
  27. #define E1000_MAX_NIC 32
  28. #define OPTION_UNSET -1
  29. #define OPTION_DISABLED 0
  30. #define OPTION_ENABLED 1
  31. #define COPYBREAK_DEFAULT 256
  32. unsigned int copybreak = COPYBREAK_DEFAULT;
  33. module_param(copybreak, uint, 0644);
  34. MODULE_PARM_DESC(copybreak,
  35. "Maximum size of packet that is copied to a new buffer on receive");
  36. /*
  37. * All parameters are treated the same, as an integer array of values.
  38. * This macro just reduces the need to repeat the same declaration code
  39. * over and over (plus this helps to avoid typo bugs).
  40. */
  41. #define E1000_PARAM_INIT { [0 ... E1000_MAX_NIC] = OPTION_UNSET }
  42. #define E1000_PARAM(X, desc) \
  43. static int __devinitdata X[E1000_MAX_NIC+1] \
  44. = E1000_PARAM_INIT; \
  45. static unsigned int num_##X; \
  46. module_param_array_named(X, X, int, &num_##X, 0); \
  47. MODULE_PARM_DESC(X, desc);
  48. /*
  49. * Transmit Interrupt Delay in units of 1.024 microseconds
  50. * Tx interrupt delay needs to typically be set to something non zero
  51. *
  52. * Valid Range: 0-65535
  53. */
  54. E1000_PARAM(TxIntDelay, "Transmit Interrupt Delay");
  55. #define DEFAULT_TIDV 8
  56. #define MAX_TXDELAY 0xFFFF
  57. #define MIN_TXDELAY 0
  58. /*
  59. * Transmit Absolute Interrupt Delay in units of 1.024 microseconds
  60. *
  61. * Valid Range: 0-65535
  62. */
  63. E1000_PARAM(TxAbsIntDelay, "Transmit Absolute Interrupt Delay");
  64. #define DEFAULT_TADV 32
  65. #define MAX_TXABSDELAY 0xFFFF
  66. #define MIN_TXABSDELAY 0
  67. /*
  68. * Receive Interrupt Delay in units of 1.024 microseconds
  69. * hardware will likely hang if you set this to anything but zero.
  70. *
  71. * Valid Range: 0-65535
  72. */
  73. E1000_PARAM(RxIntDelay, "Receive Interrupt Delay");
  74. #define DEFAULT_RDTR 0
  75. #define MAX_RXDELAY 0xFFFF
  76. #define MIN_RXDELAY 0
  77. /*
  78. * Receive Absolute Interrupt Delay in units of 1.024 microseconds
  79. *
  80. * Valid Range: 0-65535
  81. */
  82. E1000_PARAM(RxAbsIntDelay, "Receive Absolute Interrupt Delay");
  83. #define DEFAULT_RADV 8
  84. #define MAX_RXABSDELAY 0xFFFF
  85. #define MIN_RXABSDELAY 0
  86. /*
  87. * Interrupt Throttle Rate (interrupts/sec)
  88. *
  89. * Valid Range: 100-100000 (0=off, 1=dynamic, 3=dynamic conservative)
  90. */
  91. E1000_PARAM(InterruptThrottleRate, "Interrupt Throttling Rate");
  92. #define DEFAULT_ITR 3
  93. #define MAX_ITR 100000
  94. #define MIN_ITR 100
  95. /*
  96. * Enable Smart Power Down of the PHY
  97. *
  98. * Valid Range: 0, 1
  99. *
  100. * Default Value: 0 (disabled)
  101. */
  102. E1000_PARAM(SmartPowerDownEnable, "Enable PHY smart power down");
  103. /*
  104. * Enable Kumeran Lock Loss workaround
  105. *
  106. * Valid Range: 0, 1
  107. *
  108. * Default Value: 1 (enabled)
  109. */
  110. E1000_PARAM(KumeranLockLoss, "Enable Kumeran lock loss workaround");
  111. struct e1000_option {
  112. enum { enable_option, range_option, list_option } type;
  113. const char *name;
  114. const char *err;
  115. int def;
  116. union {
  117. struct { /* range_option info */
  118. int min;
  119. int max;
  120. } r;
  121. struct { /* list_option info */
  122. int nr;
  123. struct e1000_opt_list { int i; char *str; } *p;
  124. } l;
  125. } arg;
  126. };
  127. static int __devinit e1000_validate_option(unsigned int *value,
  128. const struct e1000_option *opt,
  129. struct e1000_adapter *adapter)
  130. {
  131. if (*value == OPTION_UNSET) {
  132. *value = opt->def;
  133. return 0;
  134. }
  135. switch (opt->type) {
  136. case enable_option:
  137. switch (*value) {
  138. case OPTION_ENABLED:
  139. ndev_info(adapter->netdev, "%s Enabled\n", opt->name);
  140. return 0;
  141. case OPTION_DISABLED:
  142. ndev_info(adapter->netdev, "%s Disabled\n", opt->name);
  143. return 0;
  144. }
  145. break;
  146. case range_option:
  147. if (*value >= opt->arg.r.min && *value <= opt->arg.r.max) {
  148. ndev_info(adapter->netdev,
  149. "%s set to %i\n", opt->name, *value);
  150. return 0;
  151. }
  152. break;
  153. case list_option: {
  154. int i;
  155. struct e1000_opt_list *ent;
  156. for (i = 0; i < opt->arg.l.nr; i++) {
  157. ent = &opt->arg.l.p[i];
  158. if (*value == ent->i) {
  159. if (ent->str[0] != '\0')
  160. ndev_info(adapter->netdev, "%s\n",
  161. ent->str);
  162. return 0;
  163. }
  164. }
  165. }
  166. break;
  167. default:
  168. BUG();
  169. }
  170. ndev_info(adapter->netdev, "Invalid %s value specified (%i) %s\n",
  171. opt->name, *value, opt->err);
  172. *value = opt->def;
  173. return -1;
  174. }
  175. /**
  176. * e1000e_check_options - Range Checking for Command Line Parameters
  177. * @adapter: board private structure
  178. *
  179. * This routine checks all command line parameters for valid user
  180. * input. If an invalid value is given, or if no user specified
  181. * value exists, a default value is used. The final value is stored
  182. * in a variable in the adapter structure.
  183. **/
  184. void __devinit e1000e_check_options(struct e1000_adapter *adapter)
  185. {
  186. struct e1000_hw *hw = &adapter->hw;
  187. struct net_device *netdev = adapter->netdev;
  188. int bd = adapter->bd_number;
  189. if (bd >= E1000_MAX_NIC) {
  190. ndev_notice(netdev,
  191. "Warning: no configuration for board #%i\n", bd);
  192. ndev_notice(netdev, "Using defaults for all values\n");
  193. }
  194. { /* Transmit Interrupt Delay */
  195. const struct e1000_option opt = {
  196. .type = range_option,
  197. .name = "Transmit Interrupt Delay",
  198. .err = "using default of "
  199. __MODULE_STRING(DEFAULT_TIDV),
  200. .def = DEFAULT_TIDV,
  201. .arg = { .r = { .min = MIN_TXDELAY,
  202. .max = MAX_TXDELAY } }
  203. };
  204. if (num_TxIntDelay > bd) {
  205. adapter->tx_int_delay = TxIntDelay[bd];
  206. e1000_validate_option(&adapter->tx_int_delay, &opt,
  207. adapter);
  208. } else {
  209. adapter->tx_int_delay = opt.def;
  210. }
  211. }
  212. { /* Transmit Absolute Interrupt Delay */
  213. const struct e1000_option opt = {
  214. .type = range_option,
  215. .name = "Transmit Absolute Interrupt Delay",
  216. .err = "using default of "
  217. __MODULE_STRING(DEFAULT_TADV),
  218. .def = DEFAULT_TADV,
  219. .arg = { .r = { .min = MIN_TXABSDELAY,
  220. .max = MAX_TXABSDELAY } }
  221. };
  222. if (num_TxAbsIntDelay > bd) {
  223. adapter->tx_abs_int_delay = TxAbsIntDelay[bd];
  224. e1000_validate_option(&adapter->tx_abs_int_delay, &opt,
  225. adapter);
  226. } else {
  227. adapter->tx_abs_int_delay = opt.def;
  228. }
  229. }
  230. { /* Receive Interrupt Delay */
  231. struct e1000_option opt = {
  232. .type = range_option,
  233. .name = "Receive Interrupt Delay",
  234. .err = "using default of "
  235. __MODULE_STRING(DEFAULT_RDTR),
  236. .def = DEFAULT_RDTR,
  237. .arg = { .r = { .min = MIN_RXDELAY,
  238. .max = MAX_RXDELAY } }
  239. };
  240. if (num_RxIntDelay > bd) {
  241. adapter->rx_int_delay = RxIntDelay[bd];
  242. e1000_validate_option(&adapter->rx_int_delay, &opt,
  243. adapter);
  244. } else {
  245. adapter->rx_int_delay = opt.def;
  246. }
  247. }
  248. { /* Receive Absolute Interrupt Delay */
  249. const struct e1000_option opt = {
  250. .type = range_option,
  251. .name = "Receive Absolute Interrupt Delay",
  252. .err = "using default of "
  253. __MODULE_STRING(DEFAULT_RADV),
  254. .def = DEFAULT_RADV,
  255. .arg = { .r = { .min = MIN_RXABSDELAY,
  256. .max = MAX_RXABSDELAY } }
  257. };
  258. if (num_RxAbsIntDelay > bd) {
  259. adapter->rx_abs_int_delay = RxAbsIntDelay[bd];
  260. e1000_validate_option(&adapter->rx_abs_int_delay, &opt,
  261. adapter);
  262. } else {
  263. adapter->rx_abs_int_delay = opt.def;
  264. }
  265. }
  266. { /* Interrupt Throttling Rate */
  267. const struct e1000_option opt = {
  268. .type = range_option,
  269. .name = "Interrupt Throttling Rate (ints/sec)",
  270. .err = "using default of "
  271. __MODULE_STRING(DEFAULT_ITR),
  272. .def = DEFAULT_ITR,
  273. .arg = { .r = { .min = MIN_ITR,
  274. .max = MAX_ITR } }
  275. };
  276. if (num_InterruptThrottleRate > bd) {
  277. adapter->itr = InterruptThrottleRate[bd];
  278. switch (adapter->itr) {
  279. case 0:
  280. ndev_info(netdev, "%s turned off\n",
  281. opt.name);
  282. break;
  283. case 1:
  284. ndev_info(netdev,
  285. "%s set to dynamic mode\n",
  286. opt.name);
  287. adapter->itr_setting = adapter->itr;
  288. adapter->itr = 20000;
  289. break;
  290. case 3:
  291. ndev_info(netdev,
  292. "%s set to dynamic conservative mode\n",
  293. opt.name);
  294. adapter->itr_setting = adapter->itr;
  295. adapter->itr = 20000;
  296. break;
  297. default:
  298. e1000_validate_option(&adapter->itr, &opt,
  299. adapter);
  300. /*
  301. * save the setting, because the dynamic bits
  302. * change itr. clear the lower two bits
  303. * because they are used as control
  304. */
  305. adapter->itr_setting = adapter->itr & ~3;
  306. break;
  307. }
  308. } else {
  309. adapter->itr_setting = opt.def;
  310. adapter->itr = 20000;
  311. }
  312. }
  313. { /* Smart Power Down */
  314. const struct e1000_option opt = {
  315. .type = enable_option,
  316. .name = "PHY Smart Power Down",
  317. .err = "defaulting to Disabled",
  318. .def = OPTION_DISABLED
  319. };
  320. if (num_SmartPowerDownEnable > bd) {
  321. unsigned int spd = SmartPowerDownEnable[bd];
  322. e1000_validate_option(&spd, &opt, adapter);
  323. if ((adapter->flags & FLAG_HAS_SMART_POWER_DOWN)
  324. && spd)
  325. adapter->flags |= FLAG_SMART_POWER_DOWN;
  326. }
  327. }
  328. { /* Kumeran Lock Loss Workaround */
  329. const struct e1000_option opt = {
  330. .type = enable_option,
  331. .name = "Kumeran Lock Loss Workaround",
  332. .err = "defaulting to Enabled",
  333. .def = OPTION_ENABLED
  334. };
  335. if (num_KumeranLockLoss > bd) {
  336. unsigned int kmrn_lock_loss = KumeranLockLoss[bd];
  337. e1000_validate_option(&kmrn_lock_loss, &opt, adapter);
  338. if (hw->mac.type == e1000_ich8lan)
  339. e1000e_set_kmrn_lock_loss_workaround_ich8lan(hw,
  340. kmrn_lock_loss);
  341. } else {
  342. if (hw->mac.type == e1000_ich8lan)
  343. e1000e_set_kmrn_lock_loss_workaround_ich8lan(hw,
  344. opt.def);
  345. }
  346. }
  347. }