param.c 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473
  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 <linux/pci.h>
  23. #include "e1000.h"
  24. /*
  25. * This is the only thing that needs to be changed to adjust the
  26. * maximum number of ports that the driver can manage.
  27. */
  28. #define E1000_MAX_NIC 32
  29. #define OPTION_UNSET -1
  30. #define OPTION_DISABLED 0
  31. #define OPTION_ENABLED 1
  32. #define COPYBREAK_DEFAULT 256
  33. unsigned int copybreak = COPYBREAK_DEFAULT;
  34. module_param(copybreak, uint, 0644);
  35. MODULE_PARM_DESC(copybreak,
  36. "Maximum size of packet that is copied to a new buffer on receive");
  37. /*
  38. * All parameters are treated the same, as an integer array of values.
  39. * This macro just reduces the need to repeat the same declaration code
  40. * over and over (plus this helps to avoid typo bugs).
  41. */
  42. #define E1000_PARAM_INIT { [0 ... E1000_MAX_NIC] = OPTION_UNSET }
  43. #define E1000_PARAM(X, desc) \
  44. static int __devinitdata X[E1000_MAX_NIC+1] \
  45. = E1000_PARAM_INIT; \
  46. static unsigned int num_##X; \
  47. module_param_array_named(X, X, int, &num_##X, 0); \
  48. MODULE_PARM_DESC(X, desc);
  49. /*
  50. * Transmit Interrupt Delay in units of 1.024 microseconds
  51. * Tx interrupt delay needs to typically be set to something non zero
  52. *
  53. * Valid Range: 0-65535
  54. */
  55. E1000_PARAM(TxIntDelay, "Transmit Interrupt Delay");
  56. #define DEFAULT_TIDV 8
  57. #define MAX_TXDELAY 0xFFFF
  58. #define MIN_TXDELAY 0
  59. /*
  60. * Transmit Absolute Interrupt Delay in units of 1.024 microseconds
  61. *
  62. * Valid Range: 0-65535
  63. */
  64. E1000_PARAM(TxAbsIntDelay, "Transmit Absolute Interrupt Delay");
  65. #define DEFAULT_TADV 32
  66. #define MAX_TXABSDELAY 0xFFFF
  67. #define MIN_TXABSDELAY 0
  68. /*
  69. * Receive Interrupt Delay in units of 1.024 microseconds
  70. * hardware will likely hang if you set this to anything but zero.
  71. *
  72. * Valid Range: 0-65535
  73. */
  74. E1000_PARAM(RxIntDelay, "Receive Interrupt Delay");
  75. #define DEFAULT_RDTR 0
  76. #define MAX_RXDELAY 0xFFFF
  77. #define MIN_RXDELAY 0
  78. /*
  79. * Receive Absolute Interrupt Delay in units of 1.024 microseconds
  80. *
  81. * Valid Range: 0-65535
  82. */
  83. E1000_PARAM(RxAbsIntDelay, "Receive Absolute Interrupt Delay");
  84. #define DEFAULT_RADV 8
  85. #define MAX_RXABSDELAY 0xFFFF
  86. #define MIN_RXABSDELAY 0
  87. /*
  88. * Interrupt Throttle Rate (interrupts/sec)
  89. *
  90. * Valid Range: 100-100000 (0=off, 1=dynamic, 3=dynamic conservative)
  91. */
  92. E1000_PARAM(InterruptThrottleRate, "Interrupt Throttling Rate");
  93. #define DEFAULT_ITR 3
  94. #define MAX_ITR 100000
  95. #define MIN_ITR 100
  96. /* IntMode (Interrupt Mode)
  97. *
  98. * Valid Range: 0 - 2
  99. *
  100. * Default Value: 2 (MSI-X)
  101. */
  102. E1000_PARAM(IntMode, "Interrupt Mode");
  103. #define MAX_INTMODE 2
  104. #define MIN_INTMODE 0
  105. /*
  106. * Enable Smart Power Down of the PHY
  107. *
  108. * Valid Range: 0, 1
  109. *
  110. * Default Value: 0 (disabled)
  111. */
  112. E1000_PARAM(SmartPowerDownEnable, "Enable PHY smart power down");
  113. /*
  114. * Enable Kumeran Lock Loss workaround
  115. *
  116. * Valid Range: 0, 1
  117. *
  118. * Default Value: 1 (enabled)
  119. */
  120. E1000_PARAM(KumeranLockLoss, "Enable Kumeran lock loss workaround");
  121. /*
  122. * Write Protect NVM
  123. *
  124. * Valid Range: 0, 1
  125. *
  126. * Default Value: 1 (enabled)
  127. */
  128. E1000_PARAM(WriteProtectNVM, "Write-protect NVM [WARNING: disabling this can lead to corrupted NVM]");
  129. /*
  130. * Enable CRC Stripping
  131. *
  132. * Valid Range: 0, 1
  133. *
  134. * Default Value: 1 (enabled)
  135. */
  136. E1000_PARAM(CrcStripping, "Enable CRC Stripping, disable if your BMC needs " \
  137. "the CRC");
  138. struct e1000_option {
  139. enum { enable_option, range_option, list_option } type;
  140. const char *name;
  141. const char *err;
  142. int def;
  143. union {
  144. struct { /* range_option info */
  145. int min;
  146. int max;
  147. } r;
  148. struct { /* list_option info */
  149. int nr;
  150. struct e1000_opt_list { int i; char *str; } *p;
  151. } l;
  152. } arg;
  153. };
  154. static int __devinit e1000_validate_option(unsigned int *value,
  155. const struct e1000_option *opt,
  156. struct e1000_adapter *adapter)
  157. {
  158. if (*value == OPTION_UNSET) {
  159. *value = opt->def;
  160. return 0;
  161. }
  162. switch (opt->type) {
  163. case enable_option:
  164. switch (*value) {
  165. case OPTION_ENABLED:
  166. e_info("%s Enabled\n", opt->name);
  167. return 0;
  168. case OPTION_DISABLED:
  169. e_info("%s Disabled\n", opt->name);
  170. return 0;
  171. }
  172. break;
  173. case range_option:
  174. if (*value >= opt->arg.r.min && *value <= opt->arg.r.max) {
  175. e_info("%s set to %i\n", opt->name, *value);
  176. return 0;
  177. }
  178. break;
  179. case list_option: {
  180. int i;
  181. struct e1000_opt_list *ent;
  182. for (i = 0; i < opt->arg.l.nr; i++) {
  183. ent = &opt->arg.l.p[i];
  184. if (*value == ent->i) {
  185. if (ent->str[0] != '\0')
  186. e_info("%s\n", ent->str);
  187. return 0;
  188. }
  189. }
  190. }
  191. break;
  192. default:
  193. BUG();
  194. }
  195. e_info("Invalid %s value specified (%i) %s\n", opt->name, *value,
  196. opt->err);
  197. *value = opt->def;
  198. return -1;
  199. }
  200. /**
  201. * e1000e_check_options - Range Checking for Command Line Parameters
  202. * @adapter: board private structure
  203. *
  204. * This routine checks all command line parameters for valid user
  205. * input. If an invalid value is given, or if no user specified
  206. * value exists, a default value is used. The final value is stored
  207. * in a variable in the adapter structure.
  208. **/
  209. void __devinit e1000e_check_options(struct e1000_adapter *adapter)
  210. {
  211. struct e1000_hw *hw = &adapter->hw;
  212. int bd = adapter->bd_number;
  213. if (bd >= E1000_MAX_NIC) {
  214. e_notice("Warning: no configuration for board #%i\n", bd);
  215. e_notice("Using defaults for all values\n");
  216. }
  217. { /* Transmit Interrupt Delay */
  218. const struct e1000_option opt = {
  219. .type = range_option,
  220. .name = "Transmit Interrupt Delay",
  221. .err = "using default of "
  222. __MODULE_STRING(DEFAULT_TIDV),
  223. .def = DEFAULT_TIDV,
  224. .arg = { .r = { .min = MIN_TXDELAY,
  225. .max = MAX_TXDELAY } }
  226. };
  227. if (num_TxIntDelay > bd) {
  228. adapter->tx_int_delay = TxIntDelay[bd];
  229. e1000_validate_option(&adapter->tx_int_delay, &opt,
  230. adapter);
  231. } else {
  232. adapter->tx_int_delay = opt.def;
  233. }
  234. }
  235. { /* Transmit Absolute Interrupt Delay */
  236. const struct e1000_option opt = {
  237. .type = range_option,
  238. .name = "Transmit Absolute Interrupt Delay",
  239. .err = "using default of "
  240. __MODULE_STRING(DEFAULT_TADV),
  241. .def = DEFAULT_TADV,
  242. .arg = { .r = { .min = MIN_TXABSDELAY,
  243. .max = MAX_TXABSDELAY } }
  244. };
  245. if (num_TxAbsIntDelay > bd) {
  246. adapter->tx_abs_int_delay = TxAbsIntDelay[bd];
  247. e1000_validate_option(&adapter->tx_abs_int_delay, &opt,
  248. adapter);
  249. } else {
  250. adapter->tx_abs_int_delay = opt.def;
  251. }
  252. }
  253. { /* Receive Interrupt Delay */
  254. struct e1000_option opt = {
  255. .type = range_option,
  256. .name = "Receive Interrupt Delay",
  257. .err = "using default of "
  258. __MODULE_STRING(DEFAULT_RDTR),
  259. .def = DEFAULT_RDTR,
  260. .arg = { .r = { .min = MIN_RXDELAY,
  261. .max = MAX_RXDELAY } }
  262. };
  263. if (num_RxIntDelay > bd) {
  264. adapter->rx_int_delay = RxIntDelay[bd];
  265. e1000_validate_option(&adapter->rx_int_delay, &opt,
  266. adapter);
  267. } else {
  268. adapter->rx_int_delay = opt.def;
  269. }
  270. }
  271. { /* Receive Absolute Interrupt Delay */
  272. const struct e1000_option opt = {
  273. .type = range_option,
  274. .name = "Receive Absolute Interrupt Delay",
  275. .err = "using default of "
  276. __MODULE_STRING(DEFAULT_RADV),
  277. .def = DEFAULT_RADV,
  278. .arg = { .r = { .min = MIN_RXABSDELAY,
  279. .max = MAX_RXABSDELAY } }
  280. };
  281. if (num_RxAbsIntDelay > bd) {
  282. adapter->rx_abs_int_delay = RxAbsIntDelay[bd];
  283. e1000_validate_option(&adapter->rx_abs_int_delay, &opt,
  284. adapter);
  285. } else {
  286. adapter->rx_abs_int_delay = opt.def;
  287. }
  288. }
  289. { /* Interrupt Throttling Rate */
  290. const struct e1000_option opt = {
  291. .type = range_option,
  292. .name = "Interrupt Throttling Rate (ints/sec)",
  293. .err = "using default of "
  294. __MODULE_STRING(DEFAULT_ITR),
  295. .def = DEFAULT_ITR,
  296. .arg = { .r = { .min = MIN_ITR,
  297. .max = MAX_ITR } }
  298. };
  299. if (num_InterruptThrottleRate > bd) {
  300. adapter->itr = InterruptThrottleRate[bd];
  301. switch (adapter->itr) {
  302. case 0:
  303. e_info("%s turned off\n", opt.name);
  304. break;
  305. case 1:
  306. e_info("%s set to dynamic mode\n", opt.name);
  307. adapter->itr_setting = adapter->itr;
  308. adapter->itr = 20000;
  309. break;
  310. case 3:
  311. e_info("%s set to dynamic conservative mode\n",
  312. opt.name);
  313. adapter->itr_setting = adapter->itr;
  314. adapter->itr = 20000;
  315. break;
  316. default:
  317. /*
  318. * Save the setting, because the dynamic bits
  319. * change itr.
  320. */
  321. if (e1000_validate_option(&adapter->itr, &opt,
  322. adapter) &&
  323. (adapter->itr == 3)) {
  324. /*
  325. * In case of invalid user value,
  326. * default to conservative mode.
  327. */
  328. adapter->itr_setting = adapter->itr;
  329. adapter->itr = 20000;
  330. } else {
  331. /*
  332. * Clear the lower two bits because
  333. * they are used as control.
  334. */
  335. adapter->itr_setting =
  336. adapter->itr & ~3;
  337. }
  338. break;
  339. }
  340. } else {
  341. adapter->itr_setting = opt.def;
  342. adapter->itr = 20000;
  343. }
  344. }
  345. { /* Interrupt Mode */
  346. struct e1000_option opt = {
  347. .type = range_option,
  348. .name = "Interrupt Mode",
  349. .err = "defaulting to 2 (MSI-X)",
  350. .def = E1000E_INT_MODE_MSIX,
  351. .arg = { .r = { .min = MIN_INTMODE,
  352. .max = MAX_INTMODE } }
  353. };
  354. if (num_IntMode > bd) {
  355. unsigned int int_mode = IntMode[bd];
  356. e1000_validate_option(&int_mode, &opt, adapter);
  357. adapter->int_mode = int_mode;
  358. } else {
  359. adapter->int_mode = opt.def;
  360. }
  361. }
  362. { /* Smart Power Down */
  363. const struct e1000_option opt = {
  364. .type = enable_option,
  365. .name = "PHY Smart Power Down",
  366. .err = "defaulting to Disabled",
  367. .def = OPTION_DISABLED
  368. };
  369. if (num_SmartPowerDownEnable > bd) {
  370. unsigned int spd = SmartPowerDownEnable[bd];
  371. e1000_validate_option(&spd, &opt, adapter);
  372. if ((adapter->flags & FLAG_HAS_SMART_POWER_DOWN)
  373. && spd)
  374. adapter->flags |= FLAG_SMART_POWER_DOWN;
  375. }
  376. }
  377. { /* CRC Stripping */
  378. const struct e1000_option opt = {
  379. .type = enable_option,
  380. .name = "CRC Stripping",
  381. .err = "defaulting to enabled",
  382. .def = OPTION_ENABLED
  383. };
  384. if (num_CrcStripping > bd) {
  385. unsigned int crc_stripping = CrcStripping[bd];
  386. e1000_validate_option(&crc_stripping, &opt, adapter);
  387. if (crc_stripping == OPTION_ENABLED)
  388. adapter->flags2 |= FLAG2_CRC_STRIPPING;
  389. }
  390. }
  391. { /* Kumeran Lock Loss Workaround */
  392. const struct e1000_option opt = {
  393. .type = enable_option,
  394. .name = "Kumeran Lock Loss Workaround",
  395. .err = "defaulting to Enabled",
  396. .def = OPTION_ENABLED
  397. };
  398. if (num_KumeranLockLoss > bd) {
  399. unsigned int kmrn_lock_loss = KumeranLockLoss[bd];
  400. e1000_validate_option(&kmrn_lock_loss, &opt, adapter);
  401. if (hw->mac.type == e1000_ich8lan)
  402. e1000e_set_kmrn_lock_loss_workaround_ich8lan(hw,
  403. kmrn_lock_loss);
  404. } else {
  405. if (hw->mac.type == e1000_ich8lan)
  406. e1000e_set_kmrn_lock_loss_workaround_ich8lan(hw,
  407. opt.def);
  408. }
  409. }
  410. { /* Write-protect NVM */
  411. const struct e1000_option opt = {
  412. .type = enable_option,
  413. .name = "Write-protect NVM",
  414. .err = "defaulting to Enabled",
  415. .def = OPTION_ENABLED
  416. };
  417. if (adapter->flags & FLAG_IS_ICH) {
  418. if (num_WriteProtectNVM > bd) {
  419. unsigned int write_protect_nvm = WriteProtectNVM[bd];
  420. e1000_validate_option(&write_protect_nvm, &opt,
  421. adapter);
  422. if (write_protect_nvm)
  423. adapter->flags |= FLAG_READ_ONLY_NVM;
  424. } else {
  425. if (opt.def)
  426. adapter->flags |= FLAG_READ_ONLY_NVM;
  427. }
  428. }
  429. }
  430. }