pch_gbe_param.c 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504
  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. hw->phy.autoneg_advertised = AutoNeg;
  299. pch_gbe_validate_option(
  300. (int *)(&hw->phy.autoneg_advertised),
  301. &opt, adapter);
  302. }
  303. }
  304. switch (speed + dplx) {
  305. case 0:
  306. hw->mac.autoneg = hw->mac.fc_autoneg = 1;
  307. if ((speed || dplx))
  308. pr_debug("Speed and duplex autonegotiation enabled\n");
  309. hw->mac.link_speed = SPEED_10;
  310. hw->mac.link_duplex = DUPLEX_HALF;
  311. break;
  312. case HALF_DUPLEX:
  313. pr_debug("Half Duplex specified without Speed\n");
  314. pr_debug("Using Autonegotiation at Half Duplex only\n");
  315. hw->mac.autoneg = hw->mac.fc_autoneg = 1;
  316. hw->phy.autoneg_advertised = PHY_ADVERTISE_10_HALF |
  317. PHY_ADVERTISE_100_HALF;
  318. hw->mac.link_speed = SPEED_10;
  319. hw->mac.link_duplex = DUPLEX_HALF;
  320. break;
  321. case FULL_DUPLEX:
  322. pr_debug("Full Duplex specified without Speed\n");
  323. pr_debug("Using Autonegotiation at Full Duplex only\n");
  324. hw->mac.autoneg = hw->mac.fc_autoneg = 1;
  325. hw->phy.autoneg_advertised = PHY_ADVERTISE_10_FULL |
  326. PHY_ADVERTISE_100_FULL |
  327. PHY_ADVERTISE_1000_FULL;
  328. hw->mac.link_speed = SPEED_10;
  329. hw->mac.link_duplex = DUPLEX_FULL;
  330. break;
  331. case SPEED_10:
  332. pr_debug("10 Mbps Speed specified without Duplex\n");
  333. pr_debug("Using Autonegotiation at 10 Mbps only\n");
  334. hw->mac.autoneg = hw->mac.fc_autoneg = 1;
  335. hw->phy.autoneg_advertised = PHY_ADVERTISE_10_HALF |
  336. PHY_ADVERTISE_10_FULL;
  337. hw->mac.link_speed = SPEED_10;
  338. hw->mac.link_duplex = DUPLEX_HALF;
  339. break;
  340. case SPEED_10 + HALF_DUPLEX:
  341. pr_debug("Forcing to 10 Mbps Half Duplex\n");
  342. hw->mac.autoneg = hw->mac.fc_autoneg = 0;
  343. hw->phy.autoneg_advertised = 0;
  344. hw->mac.link_speed = SPEED_10;
  345. hw->mac.link_duplex = DUPLEX_HALF;
  346. break;
  347. case SPEED_10 + FULL_DUPLEX:
  348. pr_debug("Forcing to 10 Mbps Full Duplex\n");
  349. hw->mac.autoneg = hw->mac.fc_autoneg = 0;
  350. hw->phy.autoneg_advertised = 0;
  351. hw->mac.link_speed = SPEED_10;
  352. hw->mac.link_duplex = DUPLEX_FULL;
  353. break;
  354. case SPEED_100:
  355. pr_debug("100 Mbps Speed specified without Duplex\n");
  356. pr_debug("Using Autonegotiation at 100 Mbps only\n");
  357. hw->mac.autoneg = hw->mac.fc_autoneg = 1;
  358. hw->phy.autoneg_advertised = PHY_ADVERTISE_100_HALF |
  359. PHY_ADVERTISE_100_FULL;
  360. hw->mac.link_speed = SPEED_100;
  361. hw->mac.link_duplex = DUPLEX_HALF;
  362. break;
  363. case SPEED_100 + HALF_DUPLEX:
  364. pr_debug("Forcing to 100 Mbps Half Duplex\n");
  365. hw->mac.autoneg = hw->mac.fc_autoneg = 0;
  366. hw->phy.autoneg_advertised = 0;
  367. hw->mac.link_speed = SPEED_100;
  368. hw->mac.link_duplex = DUPLEX_HALF;
  369. break;
  370. case SPEED_100 + FULL_DUPLEX:
  371. pr_debug("Forcing to 100 Mbps Full Duplex\n");
  372. hw->mac.autoneg = hw->mac.fc_autoneg = 0;
  373. hw->phy.autoneg_advertised = 0;
  374. hw->mac.link_speed = SPEED_100;
  375. hw->mac.link_duplex = DUPLEX_FULL;
  376. break;
  377. case SPEED_1000:
  378. pr_debug("1000 Mbps Speed specified without Duplex\n");
  379. goto full_duplex_only;
  380. case SPEED_1000 + HALF_DUPLEX:
  381. pr_debug("Half Duplex is not supported at 1000 Mbps\n");
  382. /* fall through */
  383. case SPEED_1000 + FULL_DUPLEX:
  384. full_duplex_only:
  385. pr_debug("Using Autonegotiation at 1000 Mbps Full Duplex only\n");
  386. hw->mac.autoneg = hw->mac.fc_autoneg = 1;
  387. hw->phy.autoneg_advertised = PHY_ADVERTISE_1000_FULL;
  388. hw->mac.link_speed = SPEED_1000;
  389. hw->mac.link_duplex = DUPLEX_FULL;
  390. break;
  391. default:
  392. BUG();
  393. }
  394. }
  395. /**
  396. * pch_gbe_check_options - Range Checking for Command Line Parameters
  397. * @adapter: Board private structure
  398. */
  399. void pch_gbe_check_options(struct pch_gbe_adapter *adapter)
  400. {
  401. struct pch_gbe_hw *hw = &adapter->hw;
  402. struct net_device *dev = adapter->netdev;
  403. int val;
  404. { /* Transmit Descriptor Count */
  405. static const struct pch_gbe_option opt = {
  406. .type = range_option,
  407. .name = "Transmit Descriptors",
  408. .err = "using default of "
  409. __MODULE_STRING(PCH_GBE_DEFAULT_TXD),
  410. .def = PCH_GBE_DEFAULT_TXD,
  411. .arg = { .r = { .min = PCH_GBE_MIN_TXD,
  412. .max = PCH_GBE_MAX_TXD } }
  413. };
  414. struct pch_gbe_tx_ring *tx_ring = adapter->tx_ring;
  415. tx_ring->count = TxDescriptors;
  416. pch_gbe_validate_option(&tx_ring->count, &opt, adapter);
  417. tx_ring->count = roundup(tx_ring->count,
  418. PCH_GBE_TX_DESC_MULTIPLE);
  419. }
  420. { /* Receive Descriptor Count */
  421. static const struct pch_gbe_option opt = {
  422. .type = range_option,
  423. .name = "Receive Descriptors",
  424. .err = "using default of "
  425. __MODULE_STRING(PCH_GBE_DEFAULT_RXD),
  426. .def = PCH_GBE_DEFAULT_RXD,
  427. .arg = { .r = { .min = PCH_GBE_MIN_RXD,
  428. .max = PCH_GBE_MAX_RXD } }
  429. };
  430. struct pch_gbe_rx_ring *rx_ring = adapter->rx_ring;
  431. rx_ring->count = RxDescriptors;
  432. pch_gbe_validate_option(&rx_ring->count, &opt, adapter);
  433. rx_ring->count = roundup(rx_ring->count,
  434. PCH_GBE_RX_DESC_MULTIPLE);
  435. }
  436. { /* Checksum Offload Enable/Disable */
  437. static const struct pch_gbe_option opt = {
  438. .type = enable_option,
  439. .name = "Checksum Offload",
  440. .err = "defaulting to Enabled",
  441. .def = PCH_GBE_DEFAULT_RX_CSUM
  442. };
  443. val = XsumRX;
  444. pch_gbe_validate_option(&val, &opt, adapter);
  445. if (!val)
  446. dev->features &= ~NETIF_F_RXCSUM;
  447. }
  448. { /* Checksum Offload Enable/Disable */
  449. static const struct pch_gbe_option opt = {
  450. .type = enable_option,
  451. .name = "Checksum Offload",
  452. .err = "defaulting to Enabled",
  453. .def = PCH_GBE_DEFAULT_TX_CSUM
  454. };
  455. val = XsumTX;
  456. pch_gbe_validate_option(&val, &opt, adapter);
  457. if (!val)
  458. dev->features &= ~NETIF_F_ALL_CSUM;
  459. }
  460. { /* Flow Control */
  461. static const struct pch_gbe_option opt = {
  462. .type = list_option,
  463. .name = "Flow Control",
  464. .err = "reading default settings from EEPROM",
  465. .def = PCH_GBE_FC_DEFAULT,
  466. .arg = { .l = { .nr = (int)ARRAY_SIZE(fc_list),
  467. .p = fc_list } }
  468. };
  469. hw->mac.fc = FlowControl;
  470. pch_gbe_validate_option((int *)(&hw->mac.fc),
  471. &opt, adapter);
  472. }
  473. pch_gbe_check_copper_options(adapter);
  474. }