param.c 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534
  1. /* Intel PRO/1000 Linux driver
  2. * Copyright(c) 1999 - 2015 Intel Corporation.
  3. *
  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. *
  8. * This program is distributed in the hope it will be useful, but WITHOUT
  9. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  10. * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
  11. * more details.
  12. *
  13. * The full GNU General Public License is included in this distribution in
  14. * the file called "COPYING".
  15. *
  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. /* 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. /* 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 X[E1000_MAX_NIC+1] = E1000_PARAM_INIT; \
  44. static unsigned int num_##X; \
  45. module_param_array_named(X, X, int, &num_##X, 0); \
  46. MODULE_PARM_DESC(X, desc);
  47. /* Transmit Interrupt Delay in units of 1.024 microseconds
  48. * Tx interrupt delay needs to typically be set to something non-zero
  49. *
  50. * Valid Range: 0-65535
  51. */
  52. E1000_PARAM(TxIntDelay, "Transmit Interrupt Delay");
  53. #define DEFAULT_TIDV 8
  54. #define MAX_TXDELAY 0xFFFF
  55. #define MIN_TXDELAY 0
  56. /* Transmit Absolute Interrupt Delay in units of 1.024 microseconds
  57. *
  58. * Valid Range: 0-65535
  59. */
  60. E1000_PARAM(TxAbsIntDelay, "Transmit Absolute Interrupt Delay");
  61. #define DEFAULT_TADV 32
  62. #define MAX_TXABSDELAY 0xFFFF
  63. #define MIN_TXABSDELAY 0
  64. /* Receive Interrupt Delay in units of 1.024 microseconds
  65. * hardware will likely hang if you set this to anything but zero.
  66. *
  67. * Valid Range: 0-65535
  68. */
  69. E1000_PARAM(RxIntDelay, "Receive Interrupt Delay");
  70. #define MAX_RXDELAY 0xFFFF
  71. #define MIN_RXDELAY 0
  72. /* Receive Absolute Interrupt Delay in units of 1.024 microseconds
  73. *
  74. * Valid Range: 0-65535
  75. */
  76. E1000_PARAM(RxAbsIntDelay, "Receive Absolute Interrupt Delay");
  77. #define MAX_RXABSDELAY 0xFFFF
  78. #define MIN_RXABSDELAY 0
  79. /* Interrupt Throttle Rate (interrupts/sec)
  80. *
  81. * Valid Range: 100-100000 or one of: 0=off, 1=dynamic, 3=dynamic conservative
  82. */
  83. E1000_PARAM(InterruptThrottleRate, "Interrupt Throttling Rate");
  84. #define DEFAULT_ITR 3
  85. #define MAX_ITR 100000
  86. #define MIN_ITR 100
  87. /* IntMode (Interrupt Mode)
  88. *
  89. * Valid Range: varies depending on kernel configuration & hardware support
  90. *
  91. * legacy=0, MSI=1, MSI-X=2
  92. *
  93. * When MSI/MSI-X support is enabled in kernel-
  94. * Default Value: 2 (MSI-X) when supported by hardware, 1 (MSI) otherwise
  95. * When MSI/MSI-X support is not enabled in kernel-
  96. * Default Value: 0 (legacy)
  97. *
  98. * When a mode is specified that is not allowed/supported, it will be
  99. * demoted to the most advanced interrupt mode available.
  100. */
  101. E1000_PARAM(IntMode, "Interrupt Mode");
  102. #define MAX_INTMODE 2
  103. #define MIN_INTMODE 0
  104. /* Enable Smart Power Down of the PHY
  105. *
  106. * Valid Range: 0, 1
  107. *
  108. * Default Value: 0 (disabled)
  109. */
  110. E1000_PARAM(SmartPowerDownEnable, "Enable PHY smart power down");
  111. /* Enable Kumeran Lock Loss workaround
  112. *
  113. * Valid Range: 0, 1
  114. *
  115. * Default Value: 1 (enabled)
  116. */
  117. E1000_PARAM(KumeranLockLoss, "Enable Kumeran lock loss workaround");
  118. /* Write Protect NVM
  119. *
  120. * Valid Range: 0, 1
  121. *
  122. * Default Value: 1 (enabled)
  123. */
  124. E1000_PARAM(WriteProtectNVM,
  125. "Write-protect NVM [WARNING: disabling this can lead to corrupted NVM]");
  126. /* Enable CRC Stripping
  127. *
  128. * Valid Range: 0, 1
  129. *
  130. * Default Value: 1 (enabled)
  131. */
  132. E1000_PARAM(CrcStripping,
  133. "Enable CRC Stripping, disable if your BMC needs the CRC");
  134. struct e1000_option {
  135. enum { enable_option, range_option, list_option } type;
  136. const char *name;
  137. const char *err;
  138. int def;
  139. union {
  140. /* range_option info */
  141. struct {
  142. int min;
  143. int max;
  144. } r;
  145. /* list_option info */
  146. struct {
  147. int nr;
  148. struct e1000_opt_list {
  149. int i;
  150. char *str;
  151. } *p;
  152. } l;
  153. } arg;
  154. };
  155. static int e1000_validate_option(unsigned int *value,
  156. const struct e1000_option *opt,
  157. struct e1000_adapter *adapter)
  158. {
  159. if (*value == OPTION_UNSET) {
  160. *value = opt->def;
  161. return 0;
  162. }
  163. switch (opt->type) {
  164. case enable_option:
  165. switch (*value) {
  166. case OPTION_ENABLED:
  167. dev_info(&adapter->pdev->dev, "%s Enabled\n",
  168. opt->name);
  169. return 0;
  170. case OPTION_DISABLED:
  171. dev_info(&adapter->pdev->dev, "%s Disabled\n",
  172. opt->name);
  173. return 0;
  174. }
  175. break;
  176. case range_option:
  177. if (*value >= opt->arg.r.min && *value <= opt->arg.r.max) {
  178. dev_info(&adapter->pdev->dev, "%s set to %i\n",
  179. opt->name, *value);
  180. return 0;
  181. }
  182. break;
  183. case list_option: {
  184. int i;
  185. struct e1000_opt_list *ent;
  186. for (i = 0; i < opt->arg.l.nr; i++) {
  187. ent = &opt->arg.l.p[i];
  188. if (*value == ent->i) {
  189. if (ent->str[0] != '\0')
  190. dev_info(&adapter->pdev->dev, "%s\n",
  191. ent->str);
  192. return 0;
  193. }
  194. }
  195. }
  196. break;
  197. default:
  198. BUG();
  199. }
  200. dev_info(&adapter->pdev->dev, "Invalid %s value specified (%i) %s\n",
  201. opt->name, *value, opt->err);
  202. *value = opt->def;
  203. return -1;
  204. }
  205. /**
  206. * e1000e_check_options - Range Checking for Command Line Parameters
  207. * @adapter: board private structure
  208. *
  209. * This routine checks all command line parameters for valid user
  210. * input. If an invalid value is given, or if no user specified
  211. * value exists, a default value is used. The final value is stored
  212. * in a variable in the adapter structure.
  213. **/
  214. void e1000e_check_options(struct e1000_adapter *adapter)
  215. {
  216. struct e1000_hw *hw = &adapter->hw;
  217. int bd = adapter->bd_number;
  218. if (bd >= E1000_MAX_NIC) {
  219. dev_notice(&adapter->pdev->dev,
  220. "Warning: no configuration for board #%i\n", bd);
  221. dev_notice(&adapter->pdev->dev,
  222. "Using defaults for all values\n");
  223. }
  224. /* Transmit Interrupt Delay */
  225. {
  226. static const struct e1000_option opt = {
  227. .type = range_option,
  228. .name = "Transmit Interrupt Delay",
  229. .err = "using default of "
  230. __MODULE_STRING(DEFAULT_TIDV),
  231. .def = DEFAULT_TIDV,
  232. .arg = { .r = { .min = MIN_TXDELAY,
  233. .max = MAX_TXDELAY } }
  234. };
  235. if (num_TxIntDelay > bd) {
  236. adapter->tx_int_delay = TxIntDelay[bd];
  237. e1000_validate_option(&adapter->tx_int_delay, &opt,
  238. adapter);
  239. } else {
  240. adapter->tx_int_delay = opt.def;
  241. }
  242. }
  243. /* Transmit Absolute Interrupt Delay */
  244. {
  245. static const struct e1000_option opt = {
  246. .type = range_option,
  247. .name = "Transmit Absolute Interrupt Delay",
  248. .err = "using default of "
  249. __MODULE_STRING(DEFAULT_TADV),
  250. .def = DEFAULT_TADV,
  251. .arg = { .r = { .min = MIN_TXABSDELAY,
  252. .max = MAX_TXABSDELAY } }
  253. };
  254. if (num_TxAbsIntDelay > bd) {
  255. adapter->tx_abs_int_delay = TxAbsIntDelay[bd];
  256. e1000_validate_option(&adapter->tx_abs_int_delay, &opt,
  257. adapter);
  258. } else {
  259. adapter->tx_abs_int_delay = opt.def;
  260. }
  261. }
  262. /* Receive Interrupt Delay */
  263. {
  264. static struct e1000_option opt = {
  265. .type = range_option,
  266. .name = "Receive Interrupt Delay",
  267. .err = "using default of "
  268. __MODULE_STRING(DEFAULT_RDTR),
  269. .def = DEFAULT_RDTR,
  270. .arg = { .r = { .min = MIN_RXDELAY,
  271. .max = MAX_RXDELAY } }
  272. };
  273. if (num_RxIntDelay > bd) {
  274. adapter->rx_int_delay = RxIntDelay[bd];
  275. e1000_validate_option(&adapter->rx_int_delay, &opt,
  276. adapter);
  277. } else {
  278. adapter->rx_int_delay = opt.def;
  279. }
  280. }
  281. /* Receive Absolute Interrupt Delay */
  282. {
  283. static const struct e1000_option opt = {
  284. .type = range_option,
  285. .name = "Receive Absolute Interrupt Delay",
  286. .err = "using default of "
  287. __MODULE_STRING(DEFAULT_RADV),
  288. .def = DEFAULT_RADV,
  289. .arg = { .r = { .min = MIN_RXABSDELAY,
  290. .max = MAX_RXABSDELAY } }
  291. };
  292. if (num_RxAbsIntDelay > bd) {
  293. adapter->rx_abs_int_delay = RxAbsIntDelay[bd];
  294. e1000_validate_option(&adapter->rx_abs_int_delay, &opt,
  295. adapter);
  296. } else {
  297. adapter->rx_abs_int_delay = opt.def;
  298. }
  299. }
  300. /* Interrupt Throttling Rate */
  301. {
  302. static const struct e1000_option opt = {
  303. .type = range_option,
  304. .name = "Interrupt Throttling Rate (ints/sec)",
  305. .err = "using default of "
  306. __MODULE_STRING(DEFAULT_ITR),
  307. .def = DEFAULT_ITR,
  308. .arg = { .r = { .min = MIN_ITR,
  309. .max = MAX_ITR } }
  310. };
  311. if (num_InterruptThrottleRate > bd) {
  312. adapter->itr = InterruptThrottleRate[bd];
  313. /* Make sure a message is printed for non-special
  314. * values. And in case of an invalid option, display
  315. * warning, use default and go through itr/itr_setting
  316. * adjustment logic below
  317. */
  318. if ((adapter->itr > 4) &&
  319. e1000_validate_option(&adapter->itr, &opt, adapter))
  320. adapter->itr = opt.def;
  321. } else {
  322. /* If no option specified, use default value and go
  323. * through the logic below to adjust itr/itr_setting
  324. */
  325. adapter->itr = opt.def;
  326. /* Make sure a message is printed for non-special
  327. * default values
  328. */
  329. if (adapter->itr > 4)
  330. dev_info(&adapter->pdev->dev,
  331. "%s set to default %d\n", opt.name,
  332. adapter->itr);
  333. }
  334. adapter->itr_setting = adapter->itr;
  335. switch (adapter->itr) {
  336. case 0:
  337. dev_info(&adapter->pdev->dev, "%s turned off\n",
  338. opt.name);
  339. break;
  340. case 1:
  341. dev_info(&adapter->pdev->dev,
  342. "%s set to dynamic mode\n", opt.name);
  343. adapter->itr = 20000;
  344. break;
  345. case 2:
  346. dev_info(&adapter->pdev->dev,
  347. "%s Invalid mode - setting default\n",
  348. opt.name);
  349. adapter->itr_setting = opt.def;
  350. /* fall-through */
  351. case 3:
  352. dev_info(&adapter->pdev->dev,
  353. "%s set to dynamic conservative mode\n",
  354. opt.name);
  355. adapter->itr = 20000;
  356. break;
  357. case 4:
  358. dev_info(&adapter->pdev->dev,
  359. "%s set to simplified (2000-8000 ints) mode\n",
  360. opt.name);
  361. break;
  362. default:
  363. /* Save the setting, because the dynamic bits
  364. * change itr.
  365. *
  366. * Clear the lower two bits because
  367. * they are used as control.
  368. */
  369. adapter->itr_setting &= ~3;
  370. break;
  371. }
  372. }
  373. /* Interrupt Mode */
  374. {
  375. static struct e1000_option opt = {
  376. .type = range_option,
  377. .name = "Interrupt Mode",
  378. #ifndef CONFIG_PCI_MSI
  379. .err = "defaulting to 0 (legacy)",
  380. .def = E1000E_INT_MODE_LEGACY,
  381. .arg = { .r = { .min = 0,
  382. .max = 0 } }
  383. #endif
  384. };
  385. #ifdef CONFIG_PCI_MSI
  386. if (adapter->flags & FLAG_HAS_MSIX) {
  387. opt.err = kstrdup("defaulting to 2 (MSI-X)",
  388. GFP_KERNEL);
  389. opt.def = E1000E_INT_MODE_MSIX;
  390. opt.arg.r.max = E1000E_INT_MODE_MSIX;
  391. } else {
  392. opt.err = kstrdup("defaulting to 1 (MSI)", GFP_KERNEL);
  393. opt.def = E1000E_INT_MODE_MSI;
  394. opt.arg.r.max = E1000E_INT_MODE_MSI;
  395. }
  396. if (!opt.err) {
  397. dev_err(&adapter->pdev->dev,
  398. "Failed to allocate memory\n");
  399. return;
  400. }
  401. #endif
  402. if (num_IntMode > bd) {
  403. unsigned int int_mode = IntMode[bd];
  404. e1000_validate_option(&int_mode, &opt, adapter);
  405. adapter->int_mode = int_mode;
  406. } else {
  407. adapter->int_mode = opt.def;
  408. }
  409. #ifdef CONFIG_PCI_MSI
  410. kfree(opt.err);
  411. #endif
  412. }
  413. /* Smart Power Down */
  414. {
  415. static const struct e1000_option opt = {
  416. .type = enable_option,
  417. .name = "PHY Smart Power Down",
  418. .err = "defaulting to Disabled",
  419. .def = OPTION_DISABLED
  420. };
  421. if (num_SmartPowerDownEnable > bd) {
  422. unsigned int spd = SmartPowerDownEnable[bd];
  423. e1000_validate_option(&spd, &opt, adapter);
  424. if ((adapter->flags & FLAG_HAS_SMART_POWER_DOWN) && spd)
  425. adapter->flags |= FLAG_SMART_POWER_DOWN;
  426. }
  427. }
  428. /* CRC Stripping */
  429. {
  430. static const struct e1000_option opt = {
  431. .type = enable_option,
  432. .name = "CRC Stripping",
  433. .err = "defaulting to Enabled",
  434. .def = OPTION_ENABLED
  435. };
  436. if (num_CrcStripping > bd) {
  437. unsigned int crc_stripping = CrcStripping[bd];
  438. e1000_validate_option(&crc_stripping, &opt, adapter);
  439. if (crc_stripping == OPTION_ENABLED) {
  440. adapter->flags2 |= FLAG2_CRC_STRIPPING;
  441. adapter->flags2 |= FLAG2_DFLT_CRC_STRIPPING;
  442. }
  443. } else {
  444. adapter->flags2 |= FLAG2_CRC_STRIPPING;
  445. adapter->flags2 |= FLAG2_DFLT_CRC_STRIPPING;
  446. }
  447. }
  448. /* Kumeran Lock Loss Workaround */
  449. {
  450. static const struct e1000_option opt = {
  451. .type = enable_option,
  452. .name = "Kumeran Lock Loss Workaround",
  453. .err = "defaulting to Enabled",
  454. .def = OPTION_ENABLED
  455. };
  456. bool enabled = opt.def;
  457. if (num_KumeranLockLoss > bd) {
  458. unsigned int kmrn_lock_loss = KumeranLockLoss[bd];
  459. e1000_validate_option(&kmrn_lock_loss, &opt, adapter);
  460. enabled = kmrn_lock_loss;
  461. }
  462. if (hw->mac.type == e1000_ich8lan)
  463. e1000e_set_kmrn_lock_loss_workaround_ich8lan(hw,
  464. enabled);
  465. }
  466. /* Write-protect NVM */
  467. {
  468. static const struct e1000_option opt = {
  469. .type = enable_option,
  470. .name = "Write-protect NVM",
  471. .err = "defaulting to Enabled",
  472. .def = OPTION_ENABLED
  473. };
  474. if (adapter->flags & FLAG_IS_ICH) {
  475. if (num_WriteProtectNVM > bd) {
  476. unsigned int write_protect_nvm =
  477. WriteProtectNVM[bd];
  478. e1000_validate_option(&write_protect_nvm, &opt,
  479. adapter);
  480. if (write_protect_nvm)
  481. adapter->flags |= FLAG_READ_ONLY_NVM;
  482. } else {
  483. if (opt.def)
  484. adapter->flags |= FLAG_READ_ONLY_NVM;
  485. }
  486. }
  487. }
  488. }