param.c 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530
  1. /*******************************************************************************
  2. Intel PRO/1000 Linux driver
  3. Copyright(c) 1999 - 2013 Intel Corporation.
  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. This program is distributed in the hope it will be useful, but WITHOUT
  8. ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  9. FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
  10. more details.
  11. You should have received a copy of the GNU General Public License along with
  12. this program; if not, write to the Free Software Foundation, Inc.,
  13. 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
  14. The full GNU General Public License is included in this distribution in
  15. the file called "COPYING".
  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 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. }