/drivers/net/ethernet/intel/ixgb/ixgb_param.c

http://github.com/mirrors/linux · C · 444 lines · 295 code · 54 blank · 95 comment · 37 complexity · 2fc14b91c31c088d78ec5f160600517c MD5 · raw file

  1. // SPDX-License-Identifier: GPL-2.0
  2. /* Copyright(c) 1999 - 2008 Intel Corporation. */
  3. #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
  4. #include "ixgb.h"
  5. /* This is the only thing that needs to be changed to adjust the
  6. * maximum number of ports that the driver can manage.
  7. */
  8. #define IXGB_MAX_NIC 8
  9. #define OPTION_UNSET -1
  10. #define OPTION_DISABLED 0
  11. #define OPTION_ENABLED 1
  12. /* All parameters are treated the same, as an integer array of values.
  13. * This macro just reduces the need to repeat the same declaration code
  14. * over and over (plus this helps to avoid typo bugs).
  15. */
  16. #define IXGB_PARAM_INIT { [0 ... IXGB_MAX_NIC] = OPTION_UNSET }
  17. #define IXGB_PARAM(X, desc) \
  18. static int X[IXGB_MAX_NIC+1] \
  19. = IXGB_PARAM_INIT; \
  20. static unsigned int num_##X = 0; \
  21. module_param_array_named(X, X, int, &num_##X, 0); \
  22. MODULE_PARM_DESC(X, desc);
  23. /* Transmit Descriptor Count
  24. *
  25. * Valid Range: 64-4096
  26. *
  27. * Default Value: 256
  28. */
  29. IXGB_PARAM(TxDescriptors, "Number of transmit descriptors");
  30. /* Receive Descriptor Count
  31. *
  32. * Valid Range: 64-4096
  33. *
  34. * Default Value: 1024
  35. */
  36. IXGB_PARAM(RxDescriptors, "Number of receive descriptors");
  37. /* User Specified Flow Control Override
  38. *
  39. * Valid Range: 0-3
  40. * - 0 - No Flow Control
  41. * - 1 - Rx only, respond to PAUSE frames but do not generate them
  42. * - 2 - Tx only, generate PAUSE frames but ignore them on receive
  43. * - 3 - Full Flow Control Support
  44. *
  45. * Default Value: 2 - Tx only (silicon bug avoidance)
  46. */
  47. IXGB_PARAM(FlowControl, "Flow Control setting");
  48. /* XsumRX - Receive Checksum Offload Enable/Disable
  49. *
  50. * Valid Range: 0, 1
  51. * - 0 - disables all checksum offload
  52. * - 1 - enables receive IP/TCP/UDP checksum offload
  53. * on 82597 based NICs
  54. *
  55. * Default Value: 1
  56. */
  57. IXGB_PARAM(XsumRX, "Disable or enable Receive Checksum offload");
  58. /* Transmit Interrupt Delay in units of 0.8192 microseconds
  59. *
  60. * Valid Range: 0-65535
  61. *
  62. * Default Value: 32
  63. */
  64. IXGB_PARAM(TxIntDelay, "Transmit Interrupt Delay");
  65. /* Receive Interrupt Delay in units of 0.8192 microseconds
  66. *
  67. * Valid Range: 0-65535
  68. *
  69. * Default Value: 72
  70. */
  71. IXGB_PARAM(RxIntDelay, "Receive Interrupt Delay");
  72. /* Receive Flow control high threshold (when we send a pause frame)
  73. * (FCRTH)
  74. *
  75. * Valid Range: 1,536 - 262,136 (0x600 - 0x3FFF8, 8 byte granularity)
  76. *
  77. * Default Value: 196,608 (0x30000)
  78. */
  79. IXGB_PARAM(RxFCHighThresh, "Receive Flow Control High Threshold");
  80. /* Receive Flow control low threshold (when we send a resume frame)
  81. * (FCRTL)
  82. *
  83. * Valid Range: 64 - 262,136 (0x40 - 0x3FFF8, 8 byte granularity)
  84. * must be less than high threshold by at least 8 bytes
  85. *
  86. * Default Value: 163,840 (0x28000)
  87. */
  88. IXGB_PARAM(RxFCLowThresh, "Receive Flow Control Low Threshold");
  89. /* Flow control request timeout (how long to pause the link partner's tx)
  90. * (PAP 15:0)
  91. *
  92. * Valid Range: 1 - 65535
  93. *
  94. * Default Value: 65535 (0xffff) (we'll send an xon if we recover)
  95. */
  96. IXGB_PARAM(FCReqTimeout, "Flow Control Request Timeout");
  97. /* Interrupt Delay Enable
  98. *
  99. * Valid Range: 0, 1
  100. *
  101. * - 0 - disables transmit interrupt delay
  102. * - 1 - enables transmmit interrupt delay
  103. *
  104. * Default Value: 1
  105. */
  106. IXGB_PARAM(IntDelayEnable, "Transmit Interrupt Delay Enable");
  107. #define DEFAULT_TIDV 32
  108. #define MAX_TIDV 0xFFFF
  109. #define MIN_TIDV 0
  110. #define DEFAULT_RDTR 72
  111. #define MAX_RDTR 0xFFFF
  112. #define MIN_RDTR 0
  113. #define XSUMRX_DEFAULT OPTION_ENABLED
  114. #define DEFAULT_FCRTL 0x28000
  115. #define DEFAULT_FCRTH 0x30000
  116. #define MIN_FCRTL 0
  117. #define MAX_FCRTL 0x3FFE8
  118. #define MIN_FCRTH 8
  119. #define MAX_FCRTH 0x3FFF0
  120. #define MIN_FCPAUSE 1
  121. #define MAX_FCPAUSE 0xffff
  122. #define DEFAULT_FCPAUSE 0xFFFF /* this may be too long */
  123. struct ixgb_option {
  124. enum { enable_option, range_option, list_option } type;
  125. const char *name;
  126. const char *err;
  127. int def;
  128. union {
  129. struct { /* range_option info */
  130. int min;
  131. int max;
  132. } r;
  133. struct { /* list_option info */
  134. int nr;
  135. const struct ixgb_opt_list {
  136. int i;
  137. const char *str;
  138. } *p;
  139. } l;
  140. } arg;
  141. };
  142. static int
  143. ixgb_validate_option(unsigned int *value, const struct ixgb_option *opt)
  144. {
  145. if (*value == OPTION_UNSET) {
  146. *value = opt->def;
  147. return 0;
  148. }
  149. switch (opt->type) {
  150. case enable_option:
  151. switch (*value) {
  152. case OPTION_ENABLED:
  153. pr_info("%s Enabled\n", opt->name);
  154. return 0;
  155. case OPTION_DISABLED:
  156. pr_info("%s Disabled\n", opt->name);
  157. return 0;
  158. }
  159. break;
  160. case range_option:
  161. if (*value >= opt->arg.r.min && *value <= opt->arg.r.max) {
  162. pr_info("%s set to %i\n", opt->name, *value);
  163. return 0;
  164. }
  165. break;
  166. case list_option: {
  167. int i;
  168. const struct ixgb_opt_list *ent;
  169. for (i = 0; i < opt->arg.l.nr; i++) {
  170. ent = &opt->arg.l.p[i];
  171. if (*value == ent->i) {
  172. if (ent->str[0] != '\0')
  173. pr_info("%s\n", ent->str);
  174. return 0;
  175. }
  176. }
  177. }
  178. break;
  179. default:
  180. BUG();
  181. }
  182. pr_info("Invalid %s specified (%i) %s\n", opt->name, *value, opt->err);
  183. *value = opt->def;
  184. return -1;
  185. }
  186. /**
  187. * ixgb_check_options - Range Checking for Command Line Parameters
  188. * @adapter: board private structure
  189. *
  190. * This routine checks all command line parameters for valid user
  191. * input. If an invalid value is given, or if no user specified
  192. * value exists, a default value is used. The final value is stored
  193. * in a variable in the adapter structure.
  194. **/
  195. void
  196. ixgb_check_options(struct ixgb_adapter *adapter)
  197. {
  198. int bd = adapter->bd_number;
  199. if (bd >= IXGB_MAX_NIC) {
  200. pr_notice("Warning: no configuration for board #%i\n", bd);
  201. pr_notice("Using defaults for all values\n");
  202. }
  203. { /* Transmit Descriptor Count */
  204. static const struct ixgb_option opt = {
  205. .type = range_option,
  206. .name = "Transmit Descriptors",
  207. .err = "using default of " __MODULE_STRING(DEFAULT_TXD),
  208. .def = DEFAULT_TXD,
  209. .arg = { .r = { .min = MIN_TXD,
  210. .max = MAX_TXD}}
  211. };
  212. struct ixgb_desc_ring *tx_ring = &adapter->tx_ring;
  213. if (num_TxDescriptors > bd) {
  214. tx_ring->count = TxDescriptors[bd];
  215. ixgb_validate_option(&tx_ring->count, &opt);
  216. } else {
  217. tx_ring->count = opt.def;
  218. }
  219. tx_ring->count = ALIGN(tx_ring->count, IXGB_REQ_TX_DESCRIPTOR_MULTIPLE);
  220. }
  221. { /* Receive Descriptor Count */
  222. static const struct ixgb_option opt = {
  223. .type = range_option,
  224. .name = "Receive Descriptors",
  225. .err = "using default of " __MODULE_STRING(DEFAULT_RXD),
  226. .def = DEFAULT_RXD,
  227. .arg = { .r = { .min = MIN_RXD,
  228. .max = MAX_RXD}}
  229. };
  230. struct ixgb_desc_ring *rx_ring = &adapter->rx_ring;
  231. if (num_RxDescriptors > bd) {
  232. rx_ring->count = RxDescriptors[bd];
  233. ixgb_validate_option(&rx_ring->count, &opt);
  234. } else {
  235. rx_ring->count = opt.def;
  236. }
  237. rx_ring->count = ALIGN(rx_ring->count, IXGB_REQ_RX_DESCRIPTOR_MULTIPLE);
  238. }
  239. { /* Receive Checksum Offload Enable */
  240. static const struct ixgb_option opt = {
  241. .type = enable_option,
  242. .name = "Receive Checksum Offload",
  243. .err = "defaulting to Enabled",
  244. .def = OPTION_ENABLED
  245. };
  246. if (num_XsumRX > bd) {
  247. unsigned int rx_csum = XsumRX[bd];
  248. ixgb_validate_option(&rx_csum, &opt);
  249. adapter->rx_csum = rx_csum;
  250. } else {
  251. adapter->rx_csum = opt.def;
  252. }
  253. }
  254. { /* Flow Control */
  255. static const struct ixgb_opt_list fc_list[] = {
  256. { ixgb_fc_none, "Flow Control Disabled" },
  257. { ixgb_fc_rx_pause, "Flow Control Receive Only" },
  258. { ixgb_fc_tx_pause, "Flow Control Transmit Only" },
  259. { ixgb_fc_full, "Flow Control Enabled" },
  260. { ixgb_fc_default, "Flow Control Hardware Default" }
  261. };
  262. static const struct ixgb_option opt = {
  263. .type = list_option,
  264. .name = "Flow Control",
  265. .err = "reading default settings from EEPROM",
  266. .def = ixgb_fc_tx_pause,
  267. .arg = { .l = { .nr = ARRAY_SIZE(fc_list),
  268. .p = fc_list }}
  269. };
  270. if (num_FlowControl > bd) {
  271. unsigned int fc = FlowControl[bd];
  272. ixgb_validate_option(&fc, &opt);
  273. adapter->hw.fc.type = fc;
  274. } else {
  275. adapter->hw.fc.type = opt.def;
  276. }
  277. }
  278. { /* Receive Flow Control High Threshold */
  279. static const struct ixgb_option opt = {
  280. .type = range_option,
  281. .name = "Rx Flow Control High Threshold",
  282. .err = "using default of " __MODULE_STRING(DEFAULT_FCRTH),
  283. .def = DEFAULT_FCRTH,
  284. .arg = { .r = { .min = MIN_FCRTH,
  285. .max = MAX_FCRTH}}
  286. };
  287. if (num_RxFCHighThresh > bd) {
  288. adapter->hw.fc.high_water = RxFCHighThresh[bd];
  289. ixgb_validate_option(&adapter->hw.fc.high_water, &opt);
  290. } else {
  291. adapter->hw.fc.high_water = opt.def;
  292. }
  293. if (!(adapter->hw.fc.type & ixgb_fc_tx_pause) )
  294. pr_info("Ignoring RxFCHighThresh when no RxFC\n");
  295. }
  296. { /* Receive Flow Control Low Threshold */
  297. static const struct ixgb_option opt = {
  298. .type = range_option,
  299. .name = "Rx Flow Control Low Threshold",
  300. .err = "using default of " __MODULE_STRING(DEFAULT_FCRTL),
  301. .def = DEFAULT_FCRTL,
  302. .arg = { .r = { .min = MIN_FCRTL,
  303. .max = MAX_FCRTL}}
  304. };
  305. if (num_RxFCLowThresh > bd) {
  306. adapter->hw.fc.low_water = RxFCLowThresh[bd];
  307. ixgb_validate_option(&adapter->hw.fc.low_water, &opt);
  308. } else {
  309. adapter->hw.fc.low_water = opt.def;
  310. }
  311. if (!(adapter->hw.fc.type & ixgb_fc_tx_pause) )
  312. pr_info("Ignoring RxFCLowThresh when no RxFC\n");
  313. }
  314. { /* Flow Control Pause Time Request*/
  315. static const struct ixgb_option opt = {
  316. .type = range_option,
  317. .name = "Flow Control Pause Time Request",
  318. .err = "using default of "__MODULE_STRING(DEFAULT_FCPAUSE),
  319. .def = DEFAULT_FCPAUSE,
  320. .arg = { .r = { .min = MIN_FCPAUSE,
  321. .max = MAX_FCPAUSE}}
  322. };
  323. if (num_FCReqTimeout > bd) {
  324. unsigned int pause_time = FCReqTimeout[bd];
  325. ixgb_validate_option(&pause_time, &opt);
  326. adapter->hw.fc.pause_time = pause_time;
  327. } else {
  328. adapter->hw.fc.pause_time = opt.def;
  329. }
  330. if (!(adapter->hw.fc.type & ixgb_fc_tx_pause) )
  331. pr_info("Ignoring FCReqTimeout when no RxFC\n");
  332. }
  333. /* high low and spacing check for rx flow control thresholds */
  334. if (adapter->hw.fc.type & ixgb_fc_tx_pause) {
  335. /* high must be greater than low */
  336. if (adapter->hw.fc.high_water < (adapter->hw.fc.low_water + 8)) {
  337. /* set defaults */
  338. pr_info("RxFCHighThresh must be >= (RxFCLowThresh + 8), Using Defaults\n");
  339. adapter->hw.fc.high_water = DEFAULT_FCRTH;
  340. adapter->hw.fc.low_water = DEFAULT_FCRTL;
  341. }
  342. }
  343. { /* Receive Interrupt Delay */
  344. static const struct ixgb_option opt = {
  345. .type = range_option,
  346. .name = "Receive Interrupt Delay",
  347. .err = "using default of " __MODULE_STRING(DEFAULT_RDTR),
  348. .def = DEFAULT_RDTR,
  349. .arg = { .r = { .min = MIN_RDTR,
  350. .max = MAX_RDTR}}
  351. };
  352. if (num_RxIntDelay > bd) {
  353. adapter->rx_int_delay = RxIntDelay[bd];
  354. ixgb_validate_option(&adapter->rx_int_delay, &opt);
  355. } else {
  356. adapter->rx_int_delay = opt.def;
  357. }
  358. }
  359. { /* Transmit Interrupt Delay */
  360. static const struct ixgb_option opt = {
  361. .type = range_option,
  362. .name = "Transmit Interrupt Delay",
  363. .err = "using default of " __MODULE_STRING(DEFAULT_TIDV),
  364. .def = DEFAULT_TIDV,
  365. .arg = { .r = { .min = MIN_TIDV,
  366. .max = MAX_TIDV}}
  367. };
  368. if (num_TxIntDelay > bd) {
  369. adapter->tx_int_delay = TxIntDelay[bd];
  370. ixgb_validate_option(&adapter->tx_int_delay, &opt);
  371. } else {
  372. adapter->tx_int_delay = opt.def;
  373. }
  374. }
  375. { /* Transmit Interrupt Delay Enable */
  376. static const struct ixgb_option opt = {
  377. .type = enable_option,
  378. .name = "Tx Interrupt Delay Enable",
  379. .err = "defaulting to Enabled",
  380. .def = OPTION_ENABLED
  381. };
  382. if (num_IntDelayEnable > bd) {
  383. unsigned int ide = IntDelayEnable[bd];
  384. ixgb_validate_option(&ide, &opt);
  385. adapter->tx_int_delay_enable = ide;
  386. } else {
  387. adapter->tx_int_delay_enable = opt.def;
  388. }
  389. }
  390. }