atl1e_param.c 7.1 KB

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