atl1e_param.c 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270
  1. /*
  2. * Copyright(c) 2007 Atheros Corporation. All rights reserved.
  3. *
  4. * Derived from Intel e1000 driver
  5. * Copyright(c) 1999 - 2005 Intel Corporation. All rights reserved.
  6. *
  7. * This program is free software; you can redistribute it and/or modify it
  8. * under the terms of the GNU General Public License as published by the Free
  9. * Software Foundation; either version 2 of the License, or (at your option)
  10. * any later version.
  11. *
  12. * This program is distributed in the hope that it will be useful, but WITHOUT
  13. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  14. * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
  15. * more details.
  16. *
  17. * You should have received a copy of the GNU General Public License along with
  18. * this program; if not, write to the Free Software Foundation, Inc., 59
  19. * Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  20. */
  21. #include <linux/netdevice.h>
  22. #include "atl1e.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 ATL1E_MAX_NIC 32
  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 ATL1E_PARAM_INIT { [0 ... ATL1E_MAX_NIC] = OPTION_UNSET }
  35. #define ATL1E_PARAM(x, desc) \
  36. static int x[ATL1E_MAX_NIC + 1] = ATL1E_PARAM_INIT; \
  37. static unsigned int num_##x; \
  38. module_param_array_named(x, x, int, &num_##x, 0); \
  39. MODULE_PARM_DESC(x, desc);
  40. /* Transmit Memory count
  41. *
  42. * Valid Range: 64-2048
  43. *
  44. * Default Value: 128
  45. */
  46. #define ATL1E_MIN_TX_DESC_CNT 32
  47. #define ATL1E_MAX_TX_DESC_CNT 1020
  48. #define ATL1E_DEFAULT_TX_DESC_CNT 128
  49. ATL1E_PARAM(tx_desc_cnt, "Transmit description count");
  50. /* Receive Memory Block Count
  51. *
  52. * Valid Range: 16-512
  53. *
  54. * Default Value: 128
  55. */
  56. #define ATL1E_MIN_RX_MEM_SIZE 8 /* 8KB */
  57. #define ATL1E_MAX_RX_MEM_SIZE 1024 /* 1MB */
  58. #define ATL1E_DEFAULT_RX_MEM_SIZE 256 /* 128KB */
  59. ATL1E_PARAM(rx_mem_size, "memory size of rx buffer(KB)");
  60. /* User Specified MediaType Override
  61. *
  62. * Valid Range: 0-5
  63. * - 0 - auto-negotiate at all supported speeds
  64. * - 1 - only link at 100Mbps Full Duplex
  65. * - 2 - only link at 100Mbps Half Duplex
  66. * - 3 - only link at 10Mbps Full Duplex
  67. * - 4 - only link at 10Mbps Half Duplex
  68. * Default Value: 0
  69. */
  70. ATL1E_PARAM(media_type, "MediaType Select");
  71. /* Interrupt Moderate Timer in units of 2 us
  72. *
  73. * Valid Range: 10-65535
  74. *
  75. * Default Value: 45000(90ms)
  76. */
  77. #define INT_MOD_DEFAULT_CNT 100 /* 200us */
  78. #define INT_MOD_MAX_CNT 65000
  79. #define INT_MOD_MIN_CNT 50
  80. ATL1E_PARAM(int_mod_timer, "Interrupt Moderator Timer");
  81. #define AUTONEG_ADV_DEFAULT 0x2F
  82. #define AUTONEG_ADV_MASK 0x2F
  83. #define FLOW_CONTROL_DEFAULT FLOW_CONTROL_FULL
  84. #define FLASH_VENDOR_DEFAULT 0
  85. #define FLASH_VENDOR_MIN 0
  86. #define FLASH_VENDOR_MAX 2
  87. struct atl1e_option {
  88. enum { enable_option, range_option, list_option } type;
  89. char *name;
  90. char *err;
  91. int def;
  92. union {
  93. struct { /* range_option info */
  94. int min;
  95. int max;
  96. } r;
  97. struct { /* list_option info */
  98. int nr;
  99. struct atl1e_opt_list { int i; char *str; } *p;
  100. } l;
  101. } arg;
  102. };
  103. static int atl1e_validate_option(int *value, struct atl1e_option *opt,
  104. struct atl1e_adapter *adapter)
  105. {
  106. if (*value == OPTION_UNSET) {
  107. *value = opt->def;
  108. return 0;
  109. }
  110. switch (opt->type) {
  111. case enable_option:
  112. switch (*value) {
  113. case OPTION_ENABLED:
  114. netdev_info(adapter->netdev,
  115. "%s Enabled\n", opt->name);
  116. return 0;
  117. case OPTION_DISABLED:
  118. netdev_info(adapter->netdev,
  119. "%s Disabled\n", opt->name);
  120. return 0;
  121. }
  122. break;
  123. case range_option:
  124. if (*value >= opt->arg.r.min && *value <= opt->arg.r.max) {
  125. netdev_info(adapter->netdev, "%s set to %i\n",
  126. opt->name, *value);
  127. return 0;
  128. }
  129. break;
  130. case list_option:{
  131. int i;
  132. struct atl1e_opt_list *ent;
  133. for (i = 0; i < opt->arg.l.nr; i++) {
  134. ent = &opt->arg.l.p[i];
  135. if (*value == ent->i) {
  136. if (ent->str[0] != '\0')
  137. netdev_info(adapter->netdev,
  138. "%s\n", ent->str);
  139. return 0;
  140. }
  141. }
  142. break;
  143. }
  144. default:
  145. BUG();
  146. }
  147. netdev_info(adapter->netdev, "Invalid %s specified (%i) %s\n",
  148. opt->name, *value, opt->err);
  149. *value = opt->def;
  150. return -1;
  151. }
  152. /**
  153. * atl1e_check_options - Range Checking for Command Line Parameters
  154. * @adapter: board private structure
  155. *
  156. * This routine checks all command line parameters for valid user
  157. * input. If an invalid value is given, or if no user specified
  158. * value exists, a default value is used. The final value is stored
  159. * in a variable in the adapter structure.
  160. */
  161. void atl1e_check_options(struct atl1e_adapter *adapter)
  162. {
  163. int bd = adapter->bd_number;
  164. if (bd >= ATL1E_MAX_NIC) {
  165. netdev_notice(adapter->netdev,
  166. "no configuration for board #%i\n", bd);
  167. netdev_notice(adapter->netdev,
  168. "Using defaults for all values\n");
  169. }
  170. { /* Transmit Ring Size */
  171. struct atl1e_option opt = {
  172. .type = range_option,
  173. .name = "Transmit Ddescription Count",
  174. .err = "using default of "
  175. __MODULE_STRING(ATL1E_DEFAULT_TX_DESC_CNT),
  176. .def = ATL1E_DEFAULT_TX_DESC_CNT,
  177. .arg = { .r = { .min = ATL1E_MIN_TX_DESC_CNT,
  178. .max = ATL1E_MAX_TX_DESC_CNT} }
  179. };
  180. int val;
  181. if (num_tx_desc_cnt > bd) {
  182. val = tx_desc_cnt[bd];
  183. atl1e_validate_option(&val, &opt, adapter);
  184. adapter->tx_ring.count = (u16) val & 0xFFFC;
  185. } else
  186. adapter->tx_ring.count = (u16)opt.def;
  187. }
  188. { /* Receive Memory Block Count */
  189. struct atl1e_option opt = {
  190. .type = range_option,
  191. .name = "Memory size of rx buffer(KB)",
  192. .err = "using default of "
  193. __MODULE_STRING(ATL1E_DEFAULT_RX_MEM_SIZE),
  194. .def = ATL1E_DEFAULT_RX_MEM_SIZE,
  195. .arg = { .r = { .min = ATL1E_MIN_RX_MEM_SIZE,
  196. .max = ATL1E_MAX_RX_MEM_SIZE} }
  197. };
  198. int val;
  199. if (num_rx_mem_size > bd) {
  200. val = rx_mem_size[bd];
  201. atl1e_validate_option(&val, &opt, adapter);
  202. adapter->rx_ring.page_size = (u32)val * 1024;
  203. } else {
  204. adapter->rx_ring.page_size = (u32)opt.def * 1024;
  205. }
  206. }
  207. { /* Interrupt Moderate Timer */
  208. struct atl1e_option opt = {
  209. .type = range_option,
  210. .name = "Interrupt Moderate Timer",
  211. .err = "using default of "
  212. __MODULE_STRING(INT_MOD_DEFAULT_CNT),
  213. .def = INT_MOD_DEFAULT_CNT,
  214. .arg = { .r = { .min = INT_MOD_MIN_CNT,
  215. .max = INT_MOD_MAX_CNT} }
  216. } ;
  217. int val;
  218. if (num_int_mod_timer > bd) {
  219. val = int_mod_timer[bd];
  220. atl1e_validate_option(&val, &opt, adapter);
  221. adapter->hw.imt = (u16) val;
  222. } else
  223. adapter->hw.imt = (u16)(opt.def);
  224. }
  225. { /* MediaType */
  226. struct atl1e_option opt = {
  227. .type = range_option,
  228. .name = "Speed/Duplex Selection",
  229. .err = "using default of "
  230. __MODULE_STRING(MEDIA_TYPE_AUTO_SENSOR),
  231. .def = MEDIA_TYPE_AUTO_SENSOR,
  232. .arg = { .r = { .min = MEDIA_TYPE_AUTO_SENSOR,
  233. .max = MEDIA_TYPE_10M_HALF} }
  234. } ;
  235. int val;
  236. if (num_media_type > bd) {
  237. val = media_type[bd];
  238. atl1e_validate_option(&val, &opt, adapter);
  239. adapter->hw.media_type = (u16) val;
  240. } else
  241. adapter->hw.media_type = (u16)(opt.def);
  242. }
  243. }