pch_gbe_param.c 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505
  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. #include <linux/module.h> /* for __MODULE_STRING */
  22. #define OPTION_UNSET -1
  23. #define OPTION_DISABLED 0
  24. #define OPTION_ENABLED 1
  25. /**
  26. * TxDescriptors - Transmit Descriptor Count
  27. * @Valid Range: PCH_GBE_MIN_TXD - PCH_GBE_MAX_TXD
  28. * @Default Value: PCH_GBE_DEFAULT_TXD
  29. */
  30. static int TxDescriptors = OPTION_UNSET;
  31. module_param(TxDescriptors, int, 0);
  32. MODULE_PARM_DESC(TxDescriptors, "Number of transmit descriptors");
  33. /**
  34. * RxDescriptors -Receive Descriptor Count
  35. * @Valid Range: PCH_GBE_MIN_RXD - PCH_GBE_MAX_RXD
  36. * @Default Value: PCH_GBE_DEFAULT_RXD
  37. */
  38. static int RxDescriptors = OPTION_UNSET;
  39. module_param(RxDescriptors, int, 0);
  40. MODULE_PARM_DESC(RxDescriptors, "Number of receive descriptors");
  41. /**
  42. * Speed - User Specified Speed Override
  43. * @Valid Range: 0, 10, 100, 1000
  44. * - 0: auto-negotiate at all supported speeds
  45. * - 10: only link at 10 Mbps
  46. * - 100: only link at 100 Mbps
  47. * - 1000: only link at 1000 Mbps
  48. * @Default Value: 0
  49. */
  50. static int Speed = OPTION_UNSET;
  51. module_param(Speed, int, 0);
  52. MODULE_PARM_DESC(Speed, "Speed setting");
  53. /**
  54. * Duplex - User Specified Duplex Override
  55. * @Valid Range: 0-2
  56. * - 0: auto-negotiate for duplex
  57. * - 1: only link at half duplex
  58. * - 2: only link at full duplex
  59. * @Default Value: 0
  60. */
  61. static int Duplex = OPTION_UNSET;
  62. module_param(Duplex, int, 0);
  63. MODULE_PARM_DESC(Duplex, "Duplex setting");
  64. #define HALF_DUPLEX 1
  65. #define FULL_DUPLEX 2
  66. /**
  67. * AutoNeg - Auto-negotiation Advertisement Override
  68. * @Valid Range: 0x01-0x0F, 0x20-0x2F
  69. *
  70. * The AutoNeg value is a bit mask describing which speed and duplex
  71. * combinations should be advertised during auto-negotiation.
  72. * The supported speed and duplex modes are listed below
  73. *
  74. * Bit 7 6 5 4 3 2 1 0
  75. * Speed (Mbps) N/A N/A 1000 N/A 100 100 10 10
  76. * Duplex Full Full Half Full Half
  77. *
  78. * @Default Value: 0x2F (copper)
  79. */
  80. static int AutoNeg = OPTION_UNSET;
  81. module_param(AutoNeg, int, 0);
  82. MODULE_PARM_DESC(AutoNeg, "Advertised auto-negotiation setting");
  83. #define PHY_ADVERTISE_10_HALF 0x0001
  84. #define PHY_ADVERTISE_10_FULL 0x0002
  85. #define PHY_ADVERTISE_100_HALF 0x0004
  86. #define PHY_ADVERTISE_100_FULL 0x0008
  87. #define PHY_ADVERTISE_1000_HALF 0x0010 /* Not used, just FYI */
  88. #define PHY_ADVERTISE_1000_FULL 0x0020
  89. #define PCH_AUTONEG_ADVERTISE_DEFAULT 0x2F
  90. /**
  91. * FlowControl - User Specified Flow Control Override
  92. * @Valid Range: 0-3
  93. * - 0: No Flow Control
  94. * - 1: Rx only, respond to PAUSE frames but do not generate them
  95. * - 2: Tx only, generate PAUSE frames but ignore them on receive
  96. * - 3: Full Flow Control Support
  97. * @Default Value: Read flow control settings from the EEPROM
  98. */
  99. static int FlowControl = OPTION_UNSET;
  100. module_param(FlowControl, int, 0);
  101. MODULE_PARM_DESC(FlowControl, "Flow Control setting");
  102. /*
  103. * XsumRX - Receive Checksum Offload Enable/Disable
  104. * @Valid Range: 0, 1
  105. * - 0: disables all checksum offload
  106. * - 1: enables receive IP/TCP/UDP checksum offload
  107. * @Default Value: PCH_GBE_DEFAULT_RX_CSUM
  108. */
  109. static int XsumRX = OPTION_UNSET;
  110. module_param(XsumRX, int, 0);
  111. MODULE_PARM_DESC(XsumRX, "Disable or enable Receive Checksum offload");
  112. #define PCH_GBE_DEFAULT_RX_CSUM true /* trueorfalse */
  113. /*
  114. * XsumTX - Transmit Checksum Offload Enable/Disable
  115. * @Valid Range: 0, 1
  116. * - 0: disables all checksum offload
  117. * - 1: enables transmit IP/TCP/UDP checksum offload
  118. * @Default Value: PCH_GBE_DEFAULT_TX_CSUM
  119. */
  120. static int XsumTX = OPTION_UNSET;
  121. module_param(XsumTX, int, 0);
  122. MODULE_PARM_DESC(XsumTX, "Disable or enable Transmit Checksum offload");
  123. #define PCH_GBE_DEFAULT_TX_CSUM true /* trueorfalse */
  124. /**
  125. * pch_gbe_option - Force the MAC's flow control settings
  126. * @hw: Pointer to the HW structure
  127. * Returns:
  128. * 0: Successful.
  129. * Negative value: Failed.
  130. */
  131. struct pch_gbe_option {
  132. enum { enable_option, range_option, list_option } type;
  133. char *name;
  134. char *err;
  135. int def;
  136. union {
  137. struct { /* range_option info */
  138. int min;
  139. int max;
  140. } r;
  141. struct { /* list_option info */
  142. int nr;
  143. const struct pch_gbe_opt_list { int i; char *str; } *p;
  144. } l;
  145. } arg;
  146. };
  147. static const struct pch_gbe_opt_list speed_list[] = {
  148. { 0, "" },
  149. { SPEED_10, "" },
  150. { SPEED_100, "" },
  151. { SPEED_1000, "" }
  152. };
  153. static const struct pch_gbe_opt_list dplx_list[] = {
  154. { 0, "" },
  155. { HALF_DUPLEX, "" },
  156. { FULL_DUPLEX, "" }
  157. };
  158. static const struct pch_gbe_opt_list an_list[] =
  159. #define AA "AutoNeg advertising "
  160. {{ 0x01, AA "10/HD" },
  161. { 0x02, AA "10/FD" },
  162. { 0x03, AA "10/FD, 10/HD" },
  163. { 0x04, AA "100/HD" },
  164. { 0x05, AA "100/HD, 10/HD" },
  165. { 0x06, AA "100/HD, 10/FD" },
  166. { 0x07, AA "100/HD, 10/FD, 10/HD" },
  167. { 0x08, AA "100/FD" },
  168. { 0x09, AA "100/FD, 10/HD" },
  169. { 0x0a, AA "100/FD, 10/FD" },
  170. { 0x0b, AA "100/FD, 10/FD, 10/HD" },
  171. { 0x0c, AA "100/FD, 100/HD" },
  172. { 0x0d, AA "100/FD, 100/HD, 10/HD" },
  173. { 0x0e, AA "100/FD, 100/HD, 10/FD" },
  174. { 0x0f, AA "100/FD, 100/HD, 10/FD, 10/HD" },
  175. { 0x20, AA "1000/FD" },
  176. { 0x21, AA "1000/FD, 10/HD" },
  177. { 0x22, AA "1000/FD, 10/FD" },
  178. { 0x23, AA "1000/FD, 10/FD, 10/HD" },
  179. { 0x24, AA "1000/FD, 100/HD" },
  180. { 0x25, AA "1000/FD, 100/HD, 10/HD" },
  181. { 0x26, AA "1000/FD, 100/HD, 10/FD" },
  182. { 0x27, AA "1000/FD, 100/HD, 10/FD, 10/HD" },
  183. { 0x28, AA "1000/FD, 100/FD" },
  184. { 0x29, AA "1000/FD, 100/FD, 10/HD" },
  185. { 0x2a, AA "1000/FD, 100/FD, 10/FD" },
  186. { 0x2b, AA "1000/FD, 100/FD, 10/FD, 10/HD" },
  187. { 0x2c, AA "1000/FD, 100/FD, 100/HD" },
  188. { 0x2d, AA "1000/FD, 100/FD, 100/HD, 10/HD" },
  189. { 0x2e, AA "1000/FD, 100/FD, 100/HD, 10/FD" },
  190. { 0x2f, AA "1000/FD, 100/FD, 100/HD, 10/FD, 10/HD" }
  191. };
  192. static const struct pch_gbe_opt_list fc_list[] = {
  193. { PCH_GBE_FC_NONE, "Flow Control Disabled" },
  194. { PCH_GBE_FC_RX_PAUSE, "Flow Control Receive Only" },
  195. { PCH_GBE_FC_TX_PAUSE, "Flow Control Transmit Only" },
  196. { PCH_GBE_FC_FULL, "Flow Control Enabled" }
  197. };
  198. /**
  199. * pch_gbe_validate_option - Validate option
  200. * @value: value
  201. * @opt: option
  202. * @adapter: Board private structure
  203. * Returns:
  204. * 0: Successful.
  205. * Negative value: Failed.
  206. */
  207. static int pch_gbe_validate_option(int *value,
  208. const struct pch_gbe_option *opt,
  209. struct pch_gbe_adapter *adapter)
  210. {
  211. if (*value == OPTION_UNSET) {
  212. *value = opt->def;
  213. return 0;
  214. }
  215. switch (opt->type) {
  216. case enable_option:
  217. switch (*value) {
  218. case OPTION_ENABLED:
  219. pr_debug("%s Enabled\n", opt->name);
  220. return 0;
  221. case OPTION_DISABLED:
  222. pr_debug("%s Disabled\n", opt->name);
  223. return 0;
  224. }
  225. break;
  226. case range_option:
  227. if (*value >= opt->arg.r.min && *value <= opt->arg.r.max) {
  228. pr_debug("%s set to %i\n", opt->name, *value);
  229. return 0;
  230. }
  231. break;
  232. case list_option: {
  233. int i;
  234. const struct pch_gbe_opt_list *ent;
  235. for (i = 0; i < opt->arg.l.nr; i++) {
  236. ent = &opt->arg.l.p[i];
  237. if (*value == ent->i) {
  238. if (ent->str[0] != '\0')
  239. pr_debug("%s\n", ent->str);
  240. return 0;
  241. }
  242. }
  243. }
  244. break;
  245. default:
  246. BUG();
  247. }
  248. pr_debug("Invalid %s value specified (%i) %s\n",
  249. opt->name, *value, opt->err);
  250. *value = opt->def;
  251. return -1;
  252. }
  253. /**
  254. * pch_gbe_check_copper_options - Range Checking for Link Options, Copper Version
  255. * @adapter: Board private structure
  256. */
  257. static void pch_gbe_check_copper_options(struct pch_gbe_adapter *adapter)
  258. {
  259. struct pch_gbe_hw *hw = &adapter->hw;
  260. int speed, dplx;
  261. { /* Speed */
  262. static const struct pch_gbe_option opt = {
  263. .type = list_option,
  264. .name = "Speed",
  265. .err = "parameter ignored",
  266. .def = 0,
  267. .arg = { .l = { .nr = (int)ARRAY_SIZE(speed_list),
  268. .p = speed_list } }
  269. };
  270. speed = Speed;
  271. pch_gbe_validate_option(&speed, &opt, adapter);
  272. }
  273. { /* Duplex */
  274. static const struct pch_gbe_option opt = {
  275. .type = list_option,
  276. .name = "Duplex",
  277. .err = "parameter ignored",
  278. .def = 0,
  279. .arg = { .l = { .nr = (int)ARRAY_SIZE(dplx_list),
  280. .p = dplx_list } }
  281. };
  282. dplx = Duplex;
  283. pch_gbe_validate_option(&dplx, &opt, adapter);
  284. }
  285. { /* Autoneg */
  286. static const struct pch_gbe_option opt = {
  287. .type = list_option,
  288. .name = "AutoNeg",
  289. .err = "parameter ignored",
  290. .def = PCH_AUTONEG_ADVERTISE_DEFAULT,
  291. .arg = { .l = { .nr = (int)ARRAY_SIZE(an_list),
  292. .p = an_list} }
  293. };
  294. if (speed || dplx) {
  295. pr_debug("AutoNeg specified along with Speed or Duplex, AutoNeg parameter ignored\n");
  296. hw->phy.autoneg_advertised = opt.def;
  297. } else {
  298. int tmp = AutoNeg;
  299. pch_gbe_validate_option(&tmp, &opt, adapter);
  300. hw->phy.autoneg_advertised = tmp;
  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. struct net_device *dev = adapter->netdev;
  402. int val;
  403. { /* Transmit Descriptor Count */
  404. static const struct pch_gbe_option opt = {
  405. .type = range_option,
  406. .name = "Transmit Descriptors",
  407. .err = "using default of "
  408. __MODULE_STRING(PCH_GBE_DEFAULT_TXD),
  409. .def = PCH_GBE_DEFAULT_TXD,
  410. .arg = { .r = { .min = PCH_GBE_MIN_TXD,
  411. .max = PCH_GBE_MAX_TXD } }
  412. };
  413. struct pch_gbe_tx_ring *tx_ring = adapter->tx_ring;
  414. tx_ring->count = TxDescriptors;
  415. pch_gbe_validate_option(&tx_ring->count, &opt, adapter);
  416. tx_ring->count = roundup(tx_ring->count,
  417. PCH_GBE_TX_DESC_MULTIPLE);
  418. }
  419. { /* Receive Descriptor Count */
  420. static const struct pch_gbe_option opt = {
  421. .type = range_option,
  422. .name = "Receive Descriptors",
  423. .err = "using default of "
  424. __MODULE_STRING(PCH_GBE_DEFAULT_RXD),
  425. .def = PCH_GBE_DEFAULT_RXD,
  426. .arg = { .r = { .min = PCH_GBE_MIN_RXD,
  427. .max = PCH_GBE_MAX_RXD } }
  428. };
  429. struct pch_gbe_rx_ring *rx_ring = adapter->rx_ring;
  430. rx_ring->count = RxDescriptors;
  431. pch_gbe_validate_option(&rx_ring->count, &opt, adapter);
  432. rx_ring->count = roundup(rx_ring->count,
  433. PCH_GBE_RX_DESC_MULTIPLE);
  434. }
  435. { /* Checksum Offload Enable/Disable */
  436. static const struct pch_gbe_option opt = {
  437. .type = enable_option,
  438. .name = "Checksum Offload",
  439. .err = "defaulting to Enabled",
  440. .def = PCH_GBE_DEFAULT_RX_CSUM
  441. };
  442. val = XsumRX;
  443. pch_gbe_validate_option(&val, &opt, adapter);
  444. if (!val)
  445. dev->features &= ~NETIF_F_RXCSUM;
  446. }
  447. { /* Checksum Offload Enable/Disable */
  448. static const struct pch_gbe_option opt = {
  449. .type = enable_option,
  450. .name = "Checksum Offload",
  451. .err = "defaulting to Enabled",
  452. .def = PCH_GBE_DEFAULT_TX_CSUM
  453. };
  454. val = XsumTX;
  455. pch_gbe_validate_option(&val, &opt, adapter);
  456. if (!val)
  457. dev->features &= ~NETIF_F_ALL_CSUM;
  458. }
  459. { /* Flow Control */
  460. static const struct pch_gbe_option opt = {
  461. .type = list_option,
  462. .name = "Flow Control",
  463. .err = "reading default settings from EEPROM",
  464. .def = PCH_GBE_FC_DEFAULT,
  465. .arg = { .l = { .nr = (int)ARRAY_SIZE(fc_list),
  466. .p = fc_list } }
  467. };
  468. int tmp = FlowControl;
  469. pch_gbe_validate_option(&tmp, &opt, adapter);
  470. hw->mac.fc = tmp;
  471. }
  472. pch_gbe_check_copper_options(adapter);
  473. }