atl1e_param.c 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269
  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 __devinitdata 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 __devinit atl1e_validate_option(int *value, struct atl1e_option *opt, struct atl1e_adapter *adapter)
  104. {
  105. if (*value == OPTION_UNSET) {
  106. *value = opt->def;
  107. return 0;
  108. }
  109. switch (opt->type) {
  110. case enable_option:
  111. switch (*value) {
  112. case OPTION_ENABLED:
  113. netdev_info(adapter->netdev,
  114. "%s Enabled\n", opt->name);
  115. return 0;
  116. case OPTION_DISABLED:
  117. netdev_info(adapter->netdev,
  118. "%s Disabled\n", opt->name);
  119. return 0;
  120. }
  121. break;
  122. case range_option:
  123. if (*value >= opt->arg.r.min && *value <= opt->arg.r.max) {
  124. netdev_info(adapter->netdev, "%s set to %i\n",
  125. opt->name, *value);
  126. return 0;
  127. }
  128. break;
  129. case list_option:{
  130. int i;
  131. struct atl1e_opt_list *ent;
  132. for (i = 0; i < opt->arg.l.nr; i++) {
  133. ent = &opt->arg.l.p[i];
  134. if (*value == ent->i) {
  135. if (ent->str[0] != '\0')
  136. netdev_info(adapter->netdev,
  137. "%s\n", ent->str);
  138. return 0;
  139. }
  140. }
  141. break;
  142. }
  143. default:
  144. BUG();
  145. }
  146. netdev_info(adapter->netdev, "Invalid %s specified (%i) %s\n",
  147. opt->name, *value, opt->err);
  148. *value = opt->def;
  149. return -1;
  150. }
  151. /*
  152. * atl1e_check_options - Range Checking for Command Line Parameters
  153. * @adapter: board private structure
  154. *
  155. * This routine checks all command line parameters for valid user
  156. * input. If an invalid value is given, or if no user specified
  157. * value exists, a default value is used. The final value is stored
  158. * in a variable in the adapter structure.
  159. */
  160. void __devinit atl1e_check_options(struct atl1e_adapter *adapter)
  161. {
  162. int bd = adapter->bd_number;
  163. if (bd >= ATL1E_MAX_NIC) {
  164. netdev_notice(adapter->netdev,
  165. "no configuration for board #%i\n", bd);
  166. netdev_notice(adapter->netdev,
  167. "Using defaults for all values\n");
  168. }
  169. { /* Transmit Ring Size */
  170. struct atl1e_option opt = {
  171. .type = range_option,
  172. .name = "Transmit Ddescription Count",
  173. .err = "using default of "
  174. __MODULE_STRING(ATL1E_DEFAULT_TX_DESC_CNT),
  175. .def = ATL1E_DEFAULT_TX_DESC_CNT,
  176. .arg = { .r = { .min = ATL1E_MIN_TX_DESC_CNT,
  177. .max = ATL1E_MAX_TX_DESC_CNT} }
  178. };
  179. int val;
  180. if (num_tx_desc_cnt > bd) {
  181. val = tx_desc_cnt[bd];
  182. atl1e_validate_option(&val, &opt, adapter);
  183. adapter->tx_ring.count = (u16) val & 0xFFFC;
  184. } else
  185. adapter->tx_ring.count = (u16)opt.def;
  186. }
  187. { /* Receive Memory Block Count */
  188. struct atl1e_option opt = {
  189. .type = range_option,
  190. .name = "Memory size of rx buffer(KB)",
  191. .err = "using default of "
  192. __MODULE_STRING(ATL1E_DEFAULT_RX_MEM_SIZE),
  193. .def = ATL1E_DEFAULT_RX_MEM_SIZE,
  194. .arg = { .r = { .min = ATL1E_MIN_RX_MEM_SIZE,
  195. .max = ATL1E_MAX_RX_MEM_SIZE} }
  196. };
  197. int val;
  198. if (num_rx_mem_size > bd) {
  199. val = rx_mem_size[bd];
  200. atl1e_validate_option(&val, &opt, adapter);
  201. adapter->rx_ring.page_size = (u32)val * 1024;
  202. } else {
  203. adapter->rx_ring.page_size = (u32)opt.def * 1024;
  204. }
  205. }
  206. { /* Interrupt Moderate Timer */
  207. struct atl1e_option opt = {
  208. .type = range_option,
  209. .name = "Interrupt Moderate Timer",
  210. .err = "using default of "
  211. __MODULE_STRING(INT_MOD_DEFAULT_CNT),
  212. .def = INT_MOD_DEFAULT_CNT,
  213. .arg = { .r = { .min = INT_MOD_MIN_CNT,
  214. .max = INT_MOD_MAX_CNT} }
  215. } ;
  216. int val;
  217. if (num_int_mod_timer > bd) {
  218. val = int_mod_timer[bd];
  219. atl1e_validate_option(&val, &opt, adapter);
  220. adapter->hw.imt = (u16) val;
  221. } else
  222. adapter->hw.imt = (u16)(opt.def);
  223. }
  224. { /* MediaType */
  225. struct atl1e_option opt = {
  226. .type = range_option,
  227. .name = "Speed/Duplex Selection",
  228. .err = "using default of "
  229. __MODULE_STRING(MEDIA_TYPE_AUTO_SENSOR),
  230. .def = MEDIA_TYPE_AUTO_SENSOR,
  231. .arg = { .r = { .min = MEDIA_TYPE_AUTO_SENSOR,
  232. .max = MEDIA_TYPE_10M_HALF} }
  233. } ;
  234. int val;
  235. if (num_media_type > bd) {
  236. val = media_type[bd];
  237. atl1e_validate_option(&val, &opt, adapter);
  238. adapter->hw.media_type = (u16) val;
  239. } else
  240. adapter->hw.media_type = (u16)(opt.def);
  241. }
  242. }