ixgb_param.c 12 KB

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