param.c 13 KB

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