pch_gbe_param.c 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521
  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, see <http://www.gnu.org/licenses/>.
  18. */
  19. #include "pch_gbe.h"
  20. #include <linux/module.h> /* for __MODULE_STRING */
  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. netdev_dbg(adapter->netdev, "%s Enabled\n", opt->name);
  219. return 0;
  220. case OPTION_DISABLED:
  221. netdev_dbg(adapter->netdev, "%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. netdev_dbg(adapter->netdev, "%s set to %i\n",
  228. 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. netdev_dbg(adapter->netdev, "%s\n",
  240. ent->str);
  241. return 0;
  242. }
  243. }
  244. }
  245. break;
  246. default:
  247. BUG();
  248. }
  249. netdev_dbg(adapter->netdev, "Invalid %s value specified (%i) %s\n",
  250. opt->name, *value, opt->err);
  251. *value = opt->def;
  252. return -1;
  253. }
  254. /**
  255. * pch_gbe_check_copper_options - Range Checking for Link Options, Copper Version
  256. * @adapter: Board private structure
  257. */
  258. static void pch_gbe_check_copper_options(struct pch_gbe_adapter *adapter)
  259. {
  260. struct pch_gbe_hw *hw = &adapter->hw;
  261. int speed, dplx;
  262. { /* Speed */
  263. static const struct pch_gbe_option opt = {
  264. .type = list_option,
  265. .name = "Speed",
  266. .err = "parameter ignored",
  267. .def = 0,
  268. .arg = { .l = { .nr = (int)ARRAY_SIZE(speed_list),
  269. .p = speed_list } }
  270. };
  271. speed = Speed;
  272. pch_gbe_validate_option(&speed, &opt, adapter);
  273. }
  274. { /* Duplex */
  275. static const struct pch_gbe_option opt = {
  276. .type = list_option,
  277. .name = "Duplex",
  278. .err = "parameter ignored",
  279. .def = 0,
  280. .arg = { .l = { .nr = (int)ARRAY_SIZE(dplx_list),
  281. .p = dplx_list } }
  282. };
  283. dplx = Duplex;
  284. pch_gbe_validate_option(&dplx, &opt, adapter);
  285. }
  286. { /* Autoneg */
  287. static const struct pch_gbe_option opt = {
  288. .type = list_option,
  289. .name = "AutoNeg",
  290. .err = "parameter ignored",
  291. .def = PCH_AUTONEG_ADVERTISE_DEFAULT,
  292. .arg = { .l = { .nr = (int)ARRAY_SIZE(an_list),
  293. .p = an_list} }
  294. };
  295. if (speed || dplx) {
  296. netdev_dbg(adapter->netdev,
  297. "AutoNeg specified along with Speed or Duplex, AutoNeg parameter ignored\n");
  298. hw->phy.autoneg_advertised = opt.def;
  299. } else {
  300. int tmp = AutoNeg;
  301. pch_gbe_validate_option(&tmp, &opt, adapter);
  302. hw->phy.autoneg_advertised = tmp;
  303. }
  304. }
  305. switch (speed + dplx) {
  306. case 0:
  307. hw->mac.autoneg = hw->mac.fc_autoneg = 1;
  308. if ((speed || dplx))
  309. netdev_dbg(adapter->netdev,
  310. "Speed and duplex autonegotiation enabled\n");
  311. hw->mac.link_speed = SPEED_10;
  312. hw->mac.link_duplex = DUPLEX_HALF;
  313. break;
  314. case HALF_DUPLEX:
  315. netdev_dbg(adapter->netdev,
  316. "Half Duplex specified without Speed\n");
  317. netdev_dbg(adapter->netdev,
  318. "Using Autonegotiation at Half Duplex only\n");
  319. hw->mac.autoneg = hw->mac.fc_autoneg = 1;
  320. hw->phy.autoneg_advertised = PHY_ADVERTISE_10_HALF |
  321. PHY_ADVERTISE_100_HALF;
  322. hw->mac.link_speed = SPEED_10;
  323. hw->mac.link_duplex = DUPLEX_HALF;
  324. break;
  325. case FULL_DUPLEX:
  326. netdev_dbg(adapter->netdev,
  327. "Full Duplex specified without Speed\n");
  328. netdev_dbg(adapter->netdev,
  329. "Using Autonegotiation at Full Duplex only\n");
  330. hw->mac.autoneg = hw->mac.fc_autoneg = 1;
  331. hw->phy.autoneg_advertised = PHY_ADVERTISE_10_FULL |
  332. PHY_ADVERTISE_100_FULL |
  333. PHY_ADVERTISE_1000_FULL;
  334. hw->mac.link_speed = SPEED_10;
  335. hw->mac.link_duplex = DUPLEX_FULL;
  336. break;
  337. case SPEED_10:
  338. netdev_dbg(adapter->netdev,
  339. "10 Mbps Speed specified without Duplex\n");
  340. netdev_dbg(adapter->netdev,
  341. "Using Autonegotiation at 10 Mbps only\n");
  342. hw->mac.autoneg = hw->mac.fc_autoneg = 1;
  343. hw->phy.autoneg_advertised = PHY_ADVERTISE_10_HALF |
  344. PHY_ADVERTISE_10_FULL;
  345. hw->mac.link_speed = SPEED_10;
  346. hw->mac.link_duplex = DUPLEX_HALF;
  347. break;
  348. case SPEED_10 + HALF_DUPLEX:
  349. netdev_dbg(adapter->netdev, "Forcing to 10 Mbps Half Duplex\n");
  350. hw->mac.autoneg = hw->mac.fc_autoneg = 0;
  351. hw->phy.autoneg_advertised = 0;
  352. hw->mac.link_speed = SPEED_10;
  353. hw->mac.link_duplex = DUPLEX_HALF;
  354. break;
  355. case SPEED_10 + FULL_DUPLEX:
  356. netdev_dbg(adapter->netdev, "Forcing to 10 Mbps Full Duplex\n");
  357. hw->mac.autoneg = hw->mac.fc_autoneg = 0;
  358. hw->phy.autoneg_advertised = 0;
  359. hw->mac.link_speed = SPEED_10;
  360. hw->mac.link_duplex = DUPLEX_FULL;
  361. break;
  362. case SPEED_100:
  363. netdev_dbg(adapter->netdev,
  364. "100 Mbps Speed specified without Duplex\n");
  365. netdev_dbg(adapter->netdev,
  366. "Using Autonegotiation at 100 Mbps only\n");
  367. hw->mac.autoneg = hw->mac.fc_autoneg = 1;
  368. hw->phy.autoneg_advertised = PHY_ADVERTISE_100_HALF |
  369. PHY_ADVERTISE_100_FULL;
  370. hw->mac.link_speed = SPEED_100;
  371. hw->mac.link_duplex = DUPLEX_HALF;
  372. break;
  373. case SPEED_100 + HALF_DUPLEX:
  374. netdev_dbg(adapter->netdev,
  375. "Forcing to 100 Mbps Half Duplex\n");
  376. hw->mac.autoneg = hw->mac.fc_autoneg = 0;
  377. hw->phy.autoneg_advertised = 0;
  378. hw->mac.link_speed = SPEED_100;
  379. hw->mac.link_duplex = DUPLEX_HALF;
  380. break;
  381. case SPEED_100 + FULL_DUPLEX:
  382. netdev_dbg(adapter->netdev,
  383. "Forcing to 100 Mbps Full Duplex\n");
  384. hw->mac.autoneg = hw->mac.fc_autoneg = 0;
  385. hw->phy.autoneg_advertised = 0;
  386. hw->mac.link_speed = SPEED_100;
  387. hw->mac.link_duplex = DUPLEX_FULL;
  388. break;
  389. case SPEED_1000:
  390. netdev_dbg(adapter->netdev,
  391. "1000 Mbps Speed specified without Duplex\n");
  392. goto full_duplex_only;
  393. case SPEED_1000 + HALF_DUPLEX:
  394. netdev_dbg(adapter->netdev,
  395. "Half Duplex is not supported at 1000 Mbps\n");
  396. /* fall through */
  397. case SPEED_1000 + FULL_DUPLEX:
  398. full_duplex_only:
  399. netdev_dbg(adapter->netdev,
  400. "Using Autonegotiation at 1000 Mbps Full Duplex only\n");
  401. hw->mac.autoneg = hw->mac.fc_autoneg = 1;
  402. hw->phy.autoneg_advertised = PHY_ADVERTISE_1000_FULL;
  403. hw->mac.link_speed = SPEED_1000;
  404. hw->mac.link_duplex = DUPLEX_FULL;
  405. break;
  406. default:
  407. BUG();
  408. }
  409. }
  410. /**
  411. * pch_gbe_check_options - Range Checking for Command Line Parameters
  412. * @adapter: Board private structure
  413. */
  414. void pch_gbe_check_options(struct pch_gbe_adapter *adapter)
  415. {
  416. struct pch_gbe_hw *hw = &adapter->hw;
  417. struct net_device *dev = adapter->netdev;
  418. int val;
  419. { /* Transmit Descriptor Count */
  420. static const struct pch_gbe_option opt = {
  421. .type = range_option,
  422. .name = "Transmit Descriptors",
  423. .err = "using default of "
  424. __MODULE_STRING(PCH_GBE_DEFAULT_TXD),
  425. .def = PCH_GBE_DEFAULT_TXD,
  426. .arg = { .r = { .min = PCH_GBE_MIN_TXD,
  427. .max = PCH_GBE_MAX_TXD } }
  428. };
  429. struct pch_gbe_tx_ring *tx_ring = adapter->tx_ring;
  430. tx_ring->count = TxDescriptors;
  431. pch_gbe_validate_option(&tx_ring->count, &opt, adapter);
  432. tx_ring->count = roundup(tx_ring->count,
  433. PCH_GBE_TX_DESC_MULTIPLE);
  434. }
  435. { /* Receive Descriptor Count */
  436. static const struct pch_gbe_option opt = {
  437. .type = range_option,
  438. .name = "Receive Descriptors",
  439. .err = "using default of "
  440. __MODULE_STRING(PCH_GBE_DEFAULT_RXD),
  441. .def = PCH_GBE_DEFAULT_RXD,
  442. .arg = { .r = { .min = PCH_GBE_MIN_RXD,
  443. .max = PCH_GBE_MAX_RXD } }
  444. };
  445. struct pch_gbe_rx_ring *rx_ring = adapter->rx_ring;
  446. rx_ring->count = RxDescriptors;
  447. pch_gbe_validate_option(&rx_ring->count, &opt, adapter);
  448. rx_ring->count = roundup(rx_ring->count,
  449. PCH_GBE_RX_DESC_MULTIPLE);
  450. }
  451. { /* Checksum Offload Enable/Disable */
  452. static const struct pch_gbe_option opt = {
  453. .type = enable_option,
  454. .name = "Checksum Offload",
  455. .err = "defaulting to Enabled",
  456. .def = PCH_GBE_DEFAULT_RX_CSUM
  457. };
  458. val = XsumRX;
  459. pch_gbe_validate_option(&val, &opt, adapter);
  460. if (!val)
  461. dev->features &= ~NETIF_F_RXCSUM;
  462. }
  463. { /* Checksum Offload Enable/Disable */
  464. static const struct pch_gbe_option opt = {
  465. .type = enable_option,
  466. .name = "Checksum Offload",
  467. .err = "defaulting to Enabled",
  468. .def = PCH_GBE_DEFAULT_TX_CSUM
  469. };
  470. val = XsumTX;
  471. pch_gbe_validate_option(&val, &opt, adapter);
  472. if (!val)
  473. dev->features &= ~NETIF_F_ALL_CSUM;
  474. }
  475. { /* Flow Control */
  476. static const struct pch_gbe_option opt = {
  477. .type = list_option,
  478. .name = "Flow Control",
  479. .err = "reading default settings from EEPROM",
  480. .def = PCH_GBE_FC_DEFAULT,
  481. .arg = { .l = { .nr = (int)ARRAY_SIZE(fc_list),
  482. .p = fc_list } }
  483. };
  484. int tmp = FlowControl;
  485. pch_gbe_validate_option(&tmp, &opt, adapter);
  486. hw->mac.fc = tmp;
  487. }
  488. pch_gbe_check_copper_options(adapter);
  489. }