param.c 12 KB

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