param.c 14 KB

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