param.c 14 KB

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