pch_gbe_param.c 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499
  1. /*
  2. * Copyright (C) 1999 - 2010 Intel Corporation.
  3. * Copyright (C) 2010 OKI SEMICONDUCTOR Co., LTD.
  4. *
  5. * This code was derived from the Intel e1000e Linux driver.
  6. *
  7. * This program is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License as published by
  9. * the Free Software Foundation; version 2 of the License.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with this program; if not, write to the Free Software
  18. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
  19. */
  20. #include "pch_gbe.h"
  21. #define OPTION_UNSET -1
  22. #define OPTION_DISABLED 0
  23. #define OPTION_ENABLED 1
  24. /**
  25. * TxDescriptors - Transmit Descriptor Count
  26. * @Valid Range: PCH_GBE_MIN_TXD - PCH_GBE_MAX_TXD
  27. * @Default Value: PCH_GBE_DEFAULT_TXD
  28. */
  29. static int TxDescriptors = OPTION_UNSET;
  30. module_param(TxDescriptors, int, 0);
  31. MODULE_PARM_DESC(TxDescriptors, "Number of transmit descriptors");
  32. /**
  33. * RxDescriptors -Receive Descriptor Count
  34. * @Valid Range: PCH_GBE_MIN_RXD - PCH_GBE_MAX_RXD
  35. * @Default Value: PCH_GBE_DEFAULT_RXD
  36. */
  37. static int RxDescriptors = OPTION_UNSET;
  38. module_param(RxDescriptors, int, 0);
  39. MODULE_PARM_DESC(RxDescriptors, "Number of receive descriptors");
  40. /**
  41. * Speed - User Specified Speed Override
  42. * @Valid Range: 0, 10, 100, 1000
  43. * - 0: auto-negotiate at all supported speeds
  44. * - 10: only link at 10 Mbps
  45. * - 100: only link at 100 Mbps
  46. * - 1000: only link at 1000 Mbps
  47. * @Default Value: 0
  48. */
  49. static int Speed = OPTION_UNSET;
  50. module_param(Speed, int, 0);
  51. MODULE_PARM_DESC(Speed, "Speed setting");
  52. /**
  53. * Duplex - User Specified Duplex Override
  54. * @Valid Range: 0-2
  55. * - 0: auto-negotiate for duplex
  56. * - 1: only link at half duplex
  57. * - 2: only link at full duplex
  58. * @Default Value: 0
  59. */
  60. static int Duplex = OPTION_UNSET;
  61. module_param(Duplex, int, 0);
  62. MODULE_PARM_DESC(Duplex, "Duplex setting");
  63. #define HALF_DUPLEX 1
  64. #define FULL_DUPLEX 2
  65. /**
  66. * AutoNeg - Auto-negotiation Advertisement Override
  67. * @Valid Range: 0x01-0x0F, 0x20-0x2F
  68. *
  69. * The AutoNeg value is a bit mask describing which speed and duplex
  70. * combinations should be advertised during auto-negotiation.
  71. * The supported speed and duplex modes are listed below
  72. *
  73. * Bit 7 6 5 4 3 2 1 0
  74. * Speed (Mbps) N/A N/A 1000 N/A 100 100 10 10
  75. * Duplex Full Full Half Full Half
  76. *
  77. * @Default Value: 0x2F (copper)
  78. */
  79. static int AutoNeg = OPTION_UNSET;
  80. module_param(AutoNeg, int, 0);
  81. MODULE_PARM_DESC(AutoNeg, "Advertised auto-negotiation setting");
  82. #define PHY_ADVERTISE_10_HALF 0x0001
  83. #define PHY_ADVERTISE_10_FULL 0x0002
  84. #define PHY_ADVERTISE_100_HALF 0x0004
  85. #define PHY_ADVERTISE_100_FULL 0x0008
  86. #define PHY_ADVERTISE_1000_HALF 0x0010 /* Not used, just FYI */
  87. #define PHY_ADVERTISE_1000_FULL 0x0020
  88. #define PCH_AUTONEG_ADVERTISE_DEFAULT 0x2F
  89. /**
  90. * FlowControl - User Specified Flow Control Override
  91. * @Valid Range: 0-3
  92. * - 0: No Flow Control
  93. * - 1: Rx only, respond to PAUSE frames but do not generate them
  94. * - 2: Tx only, generate PAUSE frames but ignore them on receive
  95. * - 3: Full Flow Control Support
  96. * @Default Value: Read flow control settings from the EEPROM
  97. */
  98. static int FlowControl = OPTION_UNSET;
  99. module_param(FlowControl, int, 0);
  100. MODULE_PARM_DESC(FlowControl, "Flow Control setting");
  101. /*
  102. * XsumRX - Receive Checksum Offload Enable/Disable
  103. * @Valid Range: 0, 1
  104. * - 0: disables all checksum offload
  105. * - 1: enables receive IP/TCP/UDP checksum offload
  106. * @Default Value: PCH_GBE_DEFAULT_RX_CSUM
  107. */
  108. static int XsumRX = OPTION_UNSET;
  109. module_param(XsumRX, int, 0);
  110. MODULE_PARM_DESC(XsumRX, "Disable or enable Receive Checksum offload");
  111. #define PCH_GBE_DEFAULT_RX_CSUM true /* trueorfalse */
  112. /*
  113. * XsumTX - Transmit Checksum Offload Enable/Disable
  114. * @Valid Range: 0, 1
  115. * - 0: disables all checksum offload
  116. * - 1: enables transmit IP/TCP/UDP checksum offload
  117. * @Default Value: PCH_GBE_DEFAULT_TX_CSUM
  118. */
  119. static int XsumTX = OPTION_UNSET;
  120. module_param(XsumTX, int, 0);
  121. MODULE_PARM_DESC(XsumTX, "Disable or enable Transmit Checksum offload");
  122. #define PCH_GBE_DEFAULT_TX_CSUM true /* trueorfalse */
  123. /**
  124. * pch_gbe_option - Force the MAC's flow control settings
  125. * @hw: Pointer to the HW structure
  126. * Returns
  127. * 0: Successful.
  128. * Negative value: Failed.
  129. */
  130. struct pch_gbe_option {
  131. enum { enable_option, range_option, list_option } type;
  132. char *name;
  133. char *err;
  134. int def;
  135. union {
  136. struct { /* range_option info */
  137. int min;
  138. int max;
  139. } r;
  140. struct { /* list_option info */
  141. int nr;
  142. const struct pch_gbe_opt_list { int i; char *str; } *p;
  143. } l;
  144. } arg;
  145. };
  146. static const struct pch_gbe_opt_list speed_list[] = {
  147. { 0, "" },
  148. { SPEED_10, "" },
  149. { SPEED_100, "" },
  150. { SPEED_1000, "" }
  151. };
  152. static const struct pch_gbe_opt_list dplx_list[] = {
  153. { 0, "" },
  154. { HALF_DUPLEX, "" },
  155. { FULL_DUPLEX, "" }
  156. };
  157. static const struct pch_gbe_opt_list an_list[] =
  158. #define AA "AutoNeg advertising "
  159. {{ 0x01, AA "10/HD" },
  160. { 0x02, AA "10/FD" },
  161. { 0x03, AA "10/FD, 10/HD" },
  162. { 0x04, AA "100/HD" },
  163. { 0x05, AA "100/HD, 10/HD" },
  164. { 0x06, AA "100/HD, 10/FD" },
  165. { 0x07, AA "100/HD, 10/FD, 10/HD" },
  166. { 0x08, AA "100/FD" },
  167. { 0x09, AA "100/FD, 10/HD" },
  168. { 0x0a, AA "100/FD, 10/FD" },
  169. { 0x0b, AA "100/FD, 10/FD, 10/HD" },
  170. { 0x0c, AA "100/FD, 100/HD" },
  171. { 0x0d, AA "100/FD, 100/HD, 10/HD" },
  172. { 0x0e, AA "100/FD, 100/HD, 10/FD" },
  173. { 0x0f, AA "100/FD, 100/HD, 10/FD, 10/HD" },
  174. { 0x20, AA "1000/FD" },
  175. { 0x21, AA "1000/FD, 10/HD" },
  176. { 0x22, AA "1000/FD, 10/FD" },
  177. { 0x23, AA "1000/FD, 10/FD, 10/HD" },
  178. { 0x24, AA "1000/FD, 100/HD" },
  179. { 0x25, AA "1000/FD, 100/HD, 10/HD" },
  180. { 0x26, AA "1000/FD, 100/HD, 10/FD" },
  181. { 0x27, AA "1000/FD, 100/HD, 10/FD, 10/HD" },
  182. { 0x28, AA "1000/FD, 100/FD" },
  183. { 0x29, AA "1000/FD, 100/FD, 10/HD" },
  184. { 0x2a, AA "1000/FD, 100/FD, 10/FD" },
  185. { 0x2b, AA "1000/FD, 100/FD, 10/FD, 10/HD" },
  186. { 0x2c, AA "1000/FD, 100/FD, 100/HD" },
  187. { 0x2d, AA "1000/FD, 100/FD, 100/HD, 10/HD" },
  188. { 0x2e, AA "1000/FD, 100/FD, 100/HD, 10/FD" },
  189. { 0x2f, AA "1000/FD, 100/FD, 100/HD, 10/FD, 10/HD" }
  190. };
  191. static const struct pch_gbe_opt_list fc_list[] = {
  192. { PCH_GBE_FC_NONE, "Flow Control Disabled" },
  193. { PCH_GBE_FC_RX_PAUSE, "Flow Control Receive Only" },
  194. { PCH_GBE_FC_TX_PAUSE, "Flow Control Transmit Only" },
  195. { PCH_GBE_FC_FULL, "Flow Control Enabled" }
  196. };
  197. /**
  198. * pch_gbe_validate_option - Validate option
  199. * @value: value
  200. * @opt: option
  201. * @adapter: Board private structure
  202. * Returns
  203. * 0: Successful.
  204. * Negative value: Failed.
  205. */
  206. static int pch_gbe_validate_option(int *value,
  207. const struct pch_gbe_option *opt,
  208. struct pch_gbe_adapter *adapter)
  209. {
  210. if (*value == OPTION_UNSET) {
  211. *value = opt->def;
  212. return 0;
  213. }
  214. switch (opt->type) {
  215. case enable_option:
  216. switch (*value) {
  217. case OPTION_ENABLED:
  218. pr_debug("%s Enabled\n", opt->name);
  219. return 0;
  220. case OPTION_DISABLED:
  221. pr_debug("%s Disabled\n", opt->name);
  222. return 0;
  223. }
  224. break;
  225. case range_option:
  226. if (*value >= opt->arg.r.min && *value <= opt->arg.r.max) {
  227. pr_debug("%s set to %i\n", opt->name, *value);
  228. return 0;
  229. }
  230. break;
  231. case list_option: {
  232. int i;
  233. const struct pch_gbe_opt_list *ent;
  234. for (i = 0; i < opt->arg.l.nr; i++) {
  235. ent = &opt->arg.l.p[i];
  236. if (*value == ent->i) {
  237. if (ent->str[0] != '\0')
  238. pr_debug("%s\n", ent->str);
  239. return 0;
  240. }
  241. }
  242. }
  243. break;
  244. default:
  245. BUG();
  246. }
  247. pr_debug("Invalid %s value specified (%i) %s\n",
  248. opt->name, *value, opt->err);
  249. *value = opt->def;
  250. return -1;
  251. }
  252. /**
  253. * pch_gbe_check_copper_options - Range Checking for Link Options, Copper Version
  254. * @adapter: Board private structure
  255. */
  256. static void pch_gbe_check_copper_options(struct pch_gbe_adapter *adapter)
  257. {
  258. struct pch_gbe_hw *hw = &adapter->hw;
  259. int speed, dplx;
  260. { /* Speed */
  261. static const struct pch_gbe_option opt = {
  262. .type = list_option,
  263. .name = "Speed",
  264. .err = "parameter ignored",
  265. .def = 0,
  266. .arg = { .l = { .nr = (int)ARRAY_SIZE(speed_list),
  267. .p = speed_list } }
  268. };
  269. speed = Speed;
  270. pch_gbe_validate_option(&speed, &opt, adapter);
  271. }
  272. { /* Duplex */
  273. static const struct pch_gbe_option opt = {
  274. .type = list_option,
  275. .name = "Duplex",
  276. .err = "parameter ignored",
  277. .def = 0,
  278. .arg = { .l = { .nr = (int)ARRAY_SIZE(dplx_list),
  279. .p = dplx_list } }
  280. };
  281. dplx = Duplex;
  282. pch_gbe_validate_option(&dplx, &opt, adapter);
  283. }
  284. { /* Autoneg */
  285. static const struct pch_gbe_option opt = {
  286. .type = list_option,
  287. .name = "AutoNeg",
  288. .err = "parameter ignored",
  289. .def = PCH_AUTONEG_ADVERTISE_DEFAULT,
  290. .arg = { .l = { .nr = (int)ARRAY_SIZE(an_list),
  291. .p = an_list} }
  292. };
  293. if (speed || dplx) {
  294. pr_debug("AutoNeg specified along with Speed or Duplex, AutoNeg parameter ignored\n");
  295. hw->phy.autoneg_advertised = opt.def;
  296. } else {
  297. hw->phy.autoneg_advertised = AutoNeg;
  298. pch_gbe_validate_option(
  299. (int *)(&hw->phy.autoneg_advertised),
  300. &opt, adapter);
  301. }
  302. }
  303. switch (speed + dplx) {
  304. case 0:
  305. hw->mac.autoneg = hw->mac.fc_autoneg = 1;
  306. if ((speed || dplx))
  307. pr_debug("Speed and duplex autonegotiation enabled\n");
  308. hw->mac.link_speed = SPEED_10;
  309. hw->mac.link_duplex = DUPLEX_HALF;
  310. break;
  311. case HALF_DUPLEX:
  312. pr_debug("Half Duplex specified without Speed\n");
  313. pr_debug("Using Autonegotiation at Half Duplex only\n");
  314. hw->mac.autoneg = hw->mac.fc_autoneg = 1;
  315. hw->phy.autoneg_advertised = PHY_ADVERTISE_10_HALF |
  316. PHY_ADVERTISE_100_HALF;
  317. hw->mac.link_speed = SPEED_10;
  318. hw->mac.link_duplex = DUPLEX_HALF;
  319. break;
  320. case FULL_DUPLEX:
  321. pr_debug("Full Duplex specified without Speed\n");
  322. pr_debug("Using Autonegotiation at Full Duplex only\n");
  323. hw->mac.autoneg = hw->mac.fc_autoneg = 1;
  324. hw->phy.autoneg_advertised = PHY_ADVERTISE_10_FULL |
  325. PHY_ADVERTISE_100_FULL |
  326. PHY_ADVERTISE_1000_FULL;
  327. hw->mac.link_speed = SPEED_10;
  328. hw->mac.link_duplex = DUPLEX_FULL;
  329. break;
  330. case SPEED_10:
  331. pr_debug("10 Mbps Speed specified without Duplex\n");
  332. pr_debug("Using Autonegotiation at 10 Mbps only\n");
  333. hw->mac.autoneg = hw->mac.fc_autoneg = 1;
  334. hw->phy.autoneg_advertised = PHY_ADVERTISE_10_HALF |
  335. PHY_ADVERTISE_10_FULL;
  336. hw->mac.link_speed = SPEED_10;
  337. hw->mac.link_duplex = DUPLEX_HALF;
  338. break;
  339. case SPEED_10 + HALF_DUPLEX:
  340. pr_debug("Forcing to 10 Mbps Half Duplex\n");
  341. hw->mac.autoneg = hw->mac.fc_autoneg = 0;
  342. hw->phy.autoneg_advertised = 0;
  343. hw->mac.link_speed = SPEED_10;
  344. hw->mac.link_duplex = DUPLEX_HALF;
  345. break;
  346. case SPEED_10 + FULL_DUPLEX:
  347. pr_debug("Forcing to 10 Mbps Full Duplex\n");
  348. hw->mac.autoneg = hw->mac.fc_autoneg = 0;
  349. hw->phy.autoneg_advertised = 0;
  350. hw->mac.link_speed = SPEED_10;
  351. hw->mac.link_duplex = DUPLEX_FULL;
  352. break;
  353. case SPEED_100:
  354. pr_debug("100 Mbps Speed specified without Duplex\n");
  355. pr_debug("Using Autonegotiation at 100 Mbps only\n");
  356. hw->mac.autoneg = hw->mac.fc_autoneg = 1;
  357. hw->phy.autoneg_advertised = PHY_ADVERTISE_100_HALF |
  358. PHY_ADVERTISE_100_FULL;
  359. hw->mac.link_speed = SPEED_100;
  360. hw->mac.link_duplex = DUPLEX_HALF;
  361. break;
  362. case SPEED_100 + HALF_DUPLEX:
  363. pr_debug("Forcing to 100 Mbps Half Duplex\n");
  364. hw->mac.autoneg = hw->mac.fc_autoneg = 0;
  365. hw->phy.autoneg_advertised = 0;
  366. hw->mac.link_speed = SPEED_100;
  367. hw->mac.link_duplex = DUPLEX_HALF;
  368. break;
  369. case SPEED_100 + FULL_DUPLEX:
  370. pr_debug("Forcing to 100 Mbps Full Duplex\n");
  371. hw->mac.autoneg = hw->mac.fc_autoneg = 0;
  372. hw->phy.autoneg_advertised = 0;
  373. hw->mac.link_speed = SPEED_100;
  374. hw->mac.link_duplex = DUPLEX_FULL;
  375. break;
  376. case SPEED_1000:
  377. pr_debug("1000 Mbps Speed specified without Duplex\n");
  378. goto full_duplex_only;
  379. case SPEED_1000 + HALF_DUPLEX:
  380. pr_debug("Half Duplex is not supported at 1000 Mbps\n");
  381. /* fall through */
  382. case SPEED_1000 + FULL_DUPLEX:
  383. full_duplex_only:
  384. pr_debug("Using Autonegotiation at 1000 Mbps Full Duplex only\n");
  385. hw->mac.autoneg = hw->mac.fc_autoneg = 1;
  386. hw->phy.autoneg_advertised = PHY_ADVERTISE_1000_FULL;
  387. hw->mac.link_speed = SPEED_1000;
  388. hw->mac.link_duplex = DUPLEX_FULL;
  389. break;
  390. default:
  391. BUG();
  392. }
  393. }
  394. /**
  395. * pch_gbe_check_options - Range Checking for Command Line Parameters
  396. * @adapter: Board private structure
  397. */
  398. void pch_gbe_check_options(struct pch_gbe_adapter *adapter)
  399. {
  400. struct pch_gbe_hw *hw = &adapter->hw;
  401. { /* Transmit Descriptor Count */
  402. static const struct pch_gbe_option opt = {
  403. .type = range_option,
  404. .name = "Transmit Descriptors",
  405. .err = "using default of "
  406. __MODULE_STRING(PCH_GBE_DEFAULT_TXD),
  407. .def = PCH_GBE_DEFAULT_TXD,
  408. .arg = { .r = { .min = PCH_GBE_MIN_TXD,
  409. .max = PCH_GBE_MAX_TXD } }
  410. };
  411. struct pch_gbe_tx_ring *tx_ring = adapter->tx_ring;
  412. tx_ring->count = TxDescriptors;
  413. pch_gbe_validate_option(&tx_ring->count, &opt, adapter);
  414. tx_ring->count = roundup(tx_ring->count,
  415. PCH_GBE_TX_DESC_MULTIPLE);
  416. }
  417. { /* Receive Descriptor Count */
  418. static const struct pch_gbe_option opt = {
  419. .type = range_option,
  420. .name = "Receive Descriptors",
  421. .err = "using default of "
  422. __MODULE_STRING(PCH_GBE_DEFAULT_RXD),
  423. .def = PCH_GBE_DEFAULT_RXD,
  424. .arg = { .r = { .min = PCH_GBE_MIN_RXD,
  425. .max = PCH_GBE_MAX_RXD } }
  426. };
  427. struct pch_gbe_rx_ring *rx_ring = adapter->rx_ring;
  428. rx_ring->count = RxDescriptors;
  429. pch_gbe_validate_option(&rx_ring->count, &opt, adapter);
  430. rx_ring->count = roundup(rx_ring->count,
  431. PCH_GBE_RX_DESC_MULTIPLE);
  432. }
  433. { /* Checksum Offload Enable/Disable */
  434. static const struct pch_gbe_option opt = {
  435. .type = enable_option,
  436. .name = "Checksum Offload",
  437. .err = "defaulting to Enabled",
  438. .def = PCH_GBE_DEFAULT_RX_CSUM
  439. };
  440. adapter->rx_csum = XsumRX;
  441. pch_gbe_validate_option((int *)(&adapter->rx_csum),
  442. &opt, adapter);
  443. }
  444. { /* Checksum Offload Enable/Disable */
  445. static const struct pch_gbe_option opt = {
  446. .type = enable_option,
  447. .name = "Checksum Offload",
  448. .err = "defaulting to Enabled",
  449. .def = PCH_GBE_DEFAULT_TX_CSUM
  450. };
  451. adapter->tx_csum = XsumTX;
  452. pch_gbe_validate_option((int *)(&adapter->tx_csum),
  453. &opt, adapter);
  454. }
  455. { /* Flow Control */
  456. static const struct pch_gbe_option opt = {
  457. .type = list_option,
  458. .name = "Flow Control",
  459. .err = "reading default settings from EEPROM",
  460. .def = PCH_GBE_FC_DEFAULT,
  461. .arg = { .l = { .nr = (int)ARRAY_SIZE(fc_list),
  462. .p = fc_list } }
  463. };
  464. hw->mac.fc = FlowControl;
  465. pch_gbe_validate_option((int *)(&hw->mac.fc),
  466. &opt, adapter);
  467. }
  468. pch_gbe_check_copper_options(adapter);
  469. }