/drivers/net/ethernet/atheros/atl1e/atl1e_param.c

http://github.com/mirrors/linux · C · 256 lines · 179 code · 26 blank · 51 comment · 17 complexity · 9198cd07b4140ba3c1eb949f672669a7 MD5 · raw file

  1. // SPDX-License-Identifier: GPL-2.0-or-later
  2. /*
  3. * Copyright(c) 2007 Atheros Corporation. All rights reserved.
  4. *
  5. * Derived from Intel e1000 driver
  6. * Copyright(c) 1999 - 2005 Intel Corporation. All rights reserved.
  7. */
  8. #include <linux/netdevice.h>
  9. #include "atl1e.h"
  10. /* This is the only thing that needs to be changed to adjust the
  11. * maximum number of ports that the driver can manage.
  12. */
  13. #define ATL1E_MAX_NIC 32
  14. #define OPTION_UNSET -1
  15. #define OPTION_DISABLED 0
  16. #define OPTION_ENABLED 1
  17. /* All parameters are treated the same, as an integer array of values.
  18. * This macro just reduces the need to repeat the same declaration code
  19. * over and over (plus this helps to avoid typo bugs).
  20. */
  21. #define ATL1E_PARAM_INIT { [0 ... ATL1E_MAX_NIC] = OPTION_UNSET }
  22. #define ATL1E_PARAM(x, desc) \
  23. static int x[ATL1E_MAX_NIC + 1] = ATL1E_PARAM_INIT; \
  24. static unsigned int num_##x; \
  25. module_param_array_named(x, x, int, &num_##x, 0); \
  26. MODULE_PARM_DESC(x, desc);
  27. /* Transmit Memory count
  28. *
  29. * Valid Range: 64-2048
  30. *
  31. * Default Value: 128
  32. */
  33. #define ATL1E_MIN_TX_DESC_CNT 32
  34. #define ATL1E_MAX_TX_DESC_CNT 1020
  35. #define ATL1E_DEFAULT_TX_DESC_CNT 128
  36. ATL1E_PARAM(tx_desc_cnt, "Transmit description count");
  37. /* Receive Memory Block Count
  38. *
  39. * Valid Range: 16-512
  40. *
  41. * Default Value: 128
  42. */
  43. #define ATL1E_MIN_RX_MEM_SIZE 8 /* 8KB */
  44. #define ATL1E_MAX_RX_MEM_SIZE 1024 /* 1MB */
  45. #define ATL1E_DEFAULT_RX_MEM_SIZE 256 /* 128KB */
  46. ATL1E_PARAM(rx_mem_size, "memory size of rx buffer(KB)");
  47. /* User Specified MediaType Override
  48. *
  49. * Valid Range: 0-5
  50. * - 0 - auto-negotiate at all supported speeds
  51. * - 1 - only link at 100Mbps Full Duplex
  52. * - 2 - only link at 100Mbps Half Duplex
  53. * - 3 - only link at 10Mbps Full Duplex
  54. * - 4 - only link at 10Mbps Half Duplex
  55. * Default Value: 0
  56. */
  57. ATL1E_PARAM(media_type, "MediaType Select");
  58. /* Interrupt Moderate Timer in units of 2 us
  59. *
  60. * Valid Range: 10-65535
  61. *
  62. * Default Value: 45000(90ms)
  63. */
  64. #define INT_MOD_DEFAULT_CNT 100 /* 200us */
  65. #define INT_MOD_MAX_CNT 65000
  66. #define INT_MOD_MIN_CNT 50
  67. ATL1E_PARAM(int_mod_timer, "Interrupt Moderator Timer");
  68. #define AUTONEG_ADV_DEFAULT 0x2F
  69. #define AUTONEG_ADV_MASK 0x2F
  70. #define FLOW_CONTROL_DEFAULT FLOW_CONTROL_FULL
  71. #define FLASH_VENDOR_DEFAULT 0
  72. #define FLASH_VENDOR_MIN 0
  73. #define FLASH_VENDOR_MAX 2
  74. struct atl1e_option {
  75. enum { enable_option, range_option, list_option } type;
  76. char *name;
  77. char *err;
  78. int def;
  79. union {
  80. struct { /* range_option info */
  81. int min;
  82. int max;
  83. } r;
  84. struct { /* list_option info */
  85. int nr;
  86. struct atl1e_opt_list { int i; char *str; } *p;
  87. } l;
  88. } arg;
  89. };
  90. static int atl1e_validate_option(int *value, struct atl1e_option *opt,
  91. struct atl1e_adapter *adapter)
  92. {
  93. if (*value == OPTION_UNSET) {
  94. *value = opt->def;
  95. return 0;
  96. }
  97. switch (opt->type) {
  98. case enable_option:
  99. switch (*value) {
  100. case OPTION_ENABLED:
  101. netdev_info(adapter->netdev,
  102. "%s Enabled\n", opt->name);
  103. return 0;
  104. case OPTION_DISABLED:
  105. netdev_info(adapter->netdev,
  106. "%s Disabled\n", opt->name);
  107. return 0;
  108. }
  109. break;
  110. case range_option:
  111. if (*value >= opt->arg.r.min && *value <= opt->arg.r.max) {
  112. netdev_info(adapter->netdev, "%s set to %i\n",
  113. opt->name, *value);
  114. return 0;
  115. }
  116. break;
  117. case list_option:{
  118. int i;
  119. struct atl1e_opt_list *ent;
  120. for (i = 0; i < opt->arg.l.nr; i++) {
  121. ent = &opt->arg.l.p[i];
  122. if (*value == ent->i) {
  123. if (ent->str[0] != '\0')
  124. netdev_info(adapter->netdev,
  125. "%s\n", ent->str);
  126. return 0;
  127. }
  128. }
  129. break;
  130. }
  131. default:
  132. BUG();
  133. }
  134. netdev_info(adapter->netdev, "Invalid %s specified (%i) %s\n",
  135. opt->name, *value, opt->err);
  136. *value = opt->def;
  137. return -1;
  138. }
  139. /**
  140. * atl1e_check_options - Range Checking for Command Line Parameters
  141. * @adapter: board private structure
  142. *
  143. * This routine checks all command line parameters for valid user
  144. * input. If an invalid value is given, or if no user specified
  145. * value exists, a default value is used. The final value is stored
  146. * in a variable in the adapter structure.
  147. */
  148. void atl1e_check_options(struct atl1e_adapter *adapter)
  149. {
  150. int bd = adapter->bd_number;
  151. if (bd >= ATL1E_MAX_NIC) {
  152. netdev_notice(adapter->netdev,
  153. "no configuration for board #%i\n", bd);
  154. netdev_notice(adapter->netdev,
  155. "Using defaults for all values\n");
  156. }
  157. { /* Transmit Ring Size */
  158. struct atl1e_option opt = {
  159. .type = range_option,
  160. .name = "Transmit Ddescription Count",
  161. .err = "using default of "
  162. __MODULE_STRING(ATL1E_DEFAULT_TX_DESC_CNT),
  163. .def = ATL1E_DEFAULT_TX_DESC_CNT,
  164. .arg = { .r = { .min = ATL1E_MIN_TX_DESC_CNT,
  165. .max = ATL1E_MAX_TX_DESC_CNT} }
  166. };
  167. int val;
  168. if (num_tx_desc_cnt > bd) {
  169. val = tx_desc_cnt[bd];
  170. atl1e_validate_option(&val, &opt, adapter);
  171. adapter->tx_ring.count = (u16) val & 0xFFFC;
  172. } else
  173. adapter->tx_ring.count = (u16)opt.def;
  174. }
  175. { /* Receive Memory Block Count */
  176. struct atl1e_option opt = {
  177. .type = range_option,
  178. .name = "Memory size of rx buffer(KB)",
  179. .err = "using default of "
  180. __MODULE_STRING(ATL1E_DEFAULT_RX_MEM_SIZE),
  181. .def = ATL1E_DEFAULT_RX_MEM_SIZE,
  182. .arg = { .r = { .min = ATL1E_MIN_RX_MEM_SIZE,
  183. .max = ATL1E_MAX_RX_MEM_SIZE} }
  184. };
  185. int val;
  186. if (num_rx_mem_size > bd) {
  187. val = rx_mem_size[bd];
  188. atl1e_validate_option(&val, &opt, adapter);
  189. adapter->rx_ring.page_size = (u32)val * 1024;
  190. } else {
  191. adapter->rx_ring.page_size = (u32)opt.def * 1024;
  192. }
  193. }
  194. { /* Interrupt Moderate Timer */
  195. struct atl1e_option opt = {
  196. .type = range_option,
  197. .name = "Interrupt Moderate Timer",
  198. .err = "using default of "
  199. __MODULE_STRING(INT_MOD_DEFAULT_CNT),
  200. .def = INT_MOD_DEFAULT_CNT,
  201. .arg = { .r = { .min = INT_MOD_MIN_CNT,
  202. .max = INT_MOD_MAX_CNT} }
  203. } ;
  204. int val;
  205. if (num_int_mod_timer > bd) {
  206. val = int_mod_timer[bd];
  207. atl1e_validate_option(&val, &opt, adapter);
  208. adapter->hw.imt = (u16) val;
  209. } else
  210. adapter->hw.imt = (u16)(opt.def);
  211. }
  212. { /* MediaType */
  213. struct atl1e_option opt = {
  214. .type = range_option,
  215. .name = "Speed/Duplex Selection",
  216. .err = "using default of "
  217. __MODULE_STRING(MEDIA_TYPE_AUTO_SENSOR),
  218. .def = MEDIA_TYPE_AUTO_SENSOR,
  219. .arg = { .r = { .min = MEDIA_TYPE_AUTO_SENSOR,
  220. .max = MEDIA_TYPE_10M_HALF} }
  221. } ;
  222. int val;
  223. if (num_media_type > bd) {
  224. val = media_type[bd];
  225. atl1e_validate_option(&val, &opt, adapter);
  226. adapter->hw.media_type = (u16) val;
  227. } else
  228. adapter->hw.media_type = (u16)(opt.def);
  229. }
  230. }