param.c 13 KB

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