ixgbe_82598.c 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527
  1. /*******************************************************************************
  2. Intel 10 Gigabit PCI Express Linux driver
  3. Copyright(c) 1999 - 2007 Intel Corporation.
  4. This program is free software; you can redistribute it and/or modify it
  5. under the terms and conditions of the GNU General Public License,
  6. version 2, as published by the Free Software Foundation.
  7. This program is distributed in the hope it will be useful, but WITHOUT
  8. ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  9. FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
  10. more details.
  11. You should have received a copy of the GNU General Public License along with
  12. this program; if not, write to the Free Software Foundation, Inc.,
  13. 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
  14. The full GNU General Public License is included in this distribution in
  15. the file called "COPYING".
  16. Contact Information:
  17. Linux NICS <linux.nics@intel.com>
  18. e1000-devel Mailing List <e1000-devel@lists.sourceforge.net>
  19. Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
  20. *******************************************************************************/
  21. #include <linux/pci.h>
  22. #include <linux/delay.h>
  23. #include <linux/sched.h>
  24. #include "ixgbe.h"
  25. #include "ixgbe_phy.h"
  26. #define IXGBE_82598_MAX_TX_QUEUES 32
  27. #define IXGBE_82598_MAX_RX_QUEUES 64
  28. #define IXGBE_82598_RAR_ENTRIES 16
  29. static s32 ixgbe_get_invariants_82598(struct ixgbe_hw *hw);
  30. static s32 ixgbe_get_link_settings_82598(struct ixgbe_hw *hw, u32 *speed,
  31. bool *autoneg);
  32. static s32 ixgbe_get_copper_link_settings_82598(struct ixgbe_hw *hw,
  33. u32 *speed, bool *autoneg);
  34. static enum ixgbe_media_type ixgbe_get_media_type_82598(struct ixgbe_hw *hw);
  35. static s32 ixgbe_setup_mac_link_82598(struct ixgbe_hw *hw);
  36. static s32 ixgbe_check_mac_link_82598(struct ixgbe_hw *hw, u32 *speed,
  37. bool *link_up);
  38. static s32 ixgbe_setup_mac_link_speed_82598(struct ixgbe_hw *hw, u32 speed,
  39. bool autoneg,
  40. bool autoneg_wait_to_complete);
  41. static s32 ixgbe_setup_copper_link_82598(struct ixgbe_hw *hw);
  42. static s32 ixgbe_setup_copper_link_speed_82598(struct ixgbe_hw *hw, u32 speed,
  43. bool autoneg,
  44. bool autoneg_wait_to_complete);
  45. static s32 ixgbe_reset_hw_82598(struct ixgbe_hw *hw);
  46. static s32 ixgbe_get_invariants_82598(struct ixgbe_hw *hw)
  47. {
  48. hw->mac.num_rx_queues = IXGBE_82598_MAX_RX_QUEUES;
  49. hw->mac.num_tx_queues = IXGBE_82598_MAX_TX_QUEUES;
  50. hw->mac.num_rx_addrs = IXGBE_82598_RAR_ENTRIES;
  51. /* PHY ops are filled in by default properly for Fiber only */
  52. if (hw->mac.ops.get_media_type(hw) == ixgbe_media_type_copper) {
  53. hw->mac.ops.setup_link = &ixgbe_setup_copper_link_82598;
  54. hw->mac.ops.setup_link_speed = &ixgbe_setup_copper_link_speed_82598;
  55. hw->mac.ops.get_link_settings =
  56. &ixgbe_get_copper_link_settings_82598;
  57. /* Call PHY identify routine to get the phy type */
  58. ixgbe_identify_phy(hw);
  59. switch (hw->phy.type) {
  60. case ixgbe_phy_tn:
  61. hw->phy.ops.setup_link = &ixgbe_setup_tnx_phy_link;
  62. hw->phy.ops.check_link = &ixgbe_check_tnx_phy_link;
  63. hw->phy.ops.setup_link_speed =
  64. &ixgbe_setup_tnx_phy_link_speed;
  65. break;
  66. default:
  67. break;
  68. }
  69. }
  70. return 0;
  71. }
  72. /**
  73. * ixgbe_get_link_settings_82598 - Determines default link settings
  74. * @hw: pointer to hardware structure
  75. * @speed: pointer to link speed
  76. * @autoneg: boolean auto-negotiation value
  77. *
  78. * Determines the default link settings by reading the AUTOC register.
  79. **/
  80. static s32 ixgbe_get_link_settings_82598(struct ixgbe_hw *hw, u32 *speed,
  81. bool *autoneg)
  82. {
  83. s32 status = 0;
  84. s32 autoc_reg;
  85. autoc_reg = IXGBE_READ_REG(hw, IXGBE_AUTOC);
  86. if (hw->mac.link_settings_loaded) {
  87. autoc_reg &= ~IXGBE_AUTOC_LMS_ATTACH_TYPE;
  88. autoc_reg &= ~IXGBE_AUTOC_LMS_MASK;
  89. autoc_reg |= hw->mac.link_attach_type;
  90. autoc_reg |= hw->mac.link_mode_select;
  91. }
  92. switch (autoc_reg & IXGBE_AUTOC_LMS_MASK) {
  93. case IXGBE_AUTOC_LMS_1G_LINK_NO_AN:
  94. *speed = IXGBE_LINK_SPEED_1GB_FULL;
  95. *autoneg = false;
  96. break;
  97. case IXGBE_AUTOC_LMS_10G_LINK_NO_AN:
  98. *speed = IXGBE_LINK_SPEED_10GB_FULL;
  99. *autoneg = false;
  100. break;
  101. case IXGBE_AUTOC_LMS_1G_AN:
  102. *speed = IXGBE_LINK_SPEED_1GB_FULL;
  103. *autoneg = true;
  104. break;
  105. case IXGBE_AUTOC_LMS_KX4_AN:
  106. case IXGBE_AUTOC_LMS_KX4_AN_1G_AN:
  107. *speed = IXGBE_LINK_SPEED_UNKNOWN;
  108. if (autoc_reg & IXGBE_AUTOC_KX4_SUPP)
  109. *speed |= IXGBE_LINK_SPEED_10GB_FULL;
  110. if (autoc_reg & IXGBE_AUTOC_KX_SUPP)
  111. *speed |= IXGBE_LINK_SPEED_1GB_FULL;
  112. *autoneg = true;
  113. break;
  114. default:
  115. status = IXGBE_ERR_LINK_SETUP;
  116. break;
  117. }
  118. return status;
  119. }
  120. /**
  121. * ixgbe_get_copper_link_settings_82598 - Determines default link settings
  122. * @hw: pointer to hardware structure
  123. * @speed: pointer to link speed
  124. * @autoneg: boolean auto-negotiation value
  125. *
  126. * Determines the default link settings by reading the AUTOC register.
  127. **/
  128. static s32 ixgbe_get_copper_link_settings_82598(struct ixgbe_hw *hw,
  129. u32 *speed, bool *autoneg)
  130. {
  131. s32 status = IXGBE_ERR_LINK_SETUP;
  132. u16 speed_ability;
  133. *speed = 0;
  134. *autoneg = true;
  135. status = ixgbe_read_phy_reg(hw, IXGBE_MDIO_PHY_SPEED_ABILITY,
  136. IXGBE_MDIO_PMA_PMD_DEV_TYPE,
  137. &speed_ability);
  138. if (status == 0) {
  139. if (speed_ability & IXGBE_MDIO_PHY_SPEED_10G)
  140. *speed |= IXGBE_LINK_SPEED_10GB_FULL;
  141. if (speed_ability & IXGBE_MDIO_PHY_SPEED_1G)
  142. *speed |= IXGBE_LINK_SPEED_1GB_FULL;
  143. }
  144. return status;
  145. }
  146. /**
  147. * ixgbe_get_media_type_82598 - Determines media type
  148. * @hw: pointer to hardware structure
  149. *
  150. * Returns the media type (fiber, copper, backplane)
  151. **/
  152. static enum ixgbe_media_type ixgbe_get_media_type_82598(struct ixgbe_hw *hw)
  153. {
  154. enum ixgbe_media_type media_type;
  155. /* Media type for I82598 is based on device ID */
  156. switch (hw->device_id) {
  157. case IXGBE_DEV_ID_82598AF_DUAL_PORT:
  158. case IXGBE_DEV_ID_82598AF_SINGLE_PORT:
  159. case IXGBE_DEV_ID_82598EB_CX4:
  160. case IXGBE_DEV_ID_82598_CX4_DUAL_PORT:
  161. media_type = ixgbe_media_type_fiber;
  162. break;
  163. case IXGBE_DEV_ID_82598AT_DUAL_PORT:
  164. media_type = ixgbe_media_type_copper;
  165. break;
  166. default:
  167. media_type = ixgbe_media_type_unknown;
  168. break;
  169. }
  170. return media_type;
  171. }
  172. /**
  173. * ixgbe_setup_mac_link_82598 - Configures MAC link settings
  174. * @hw: pointer to hardware structure
  175. *
  176. * Configures link settings based on values in the ixgbe_hw struct.
  177. * Restarts the link. Performs autonegotiation if needed.
  178. **/
  179. static s32 ixgbe_setup_mac_link_82598(struct ixgbe_hw *hw)
  180. {
  181. u32 autoc_reg;
  182. u32 links_reg;
  183. u32 i;
  184. s32 status = 0;
  185. autoc_reg = IXGBE_READ_REG(hw, IXGBE_AUTOC);
  186. if (hw->mac.link_settings_loaded) {
  187. autoc_reg &= ~IXGBE_AUTOC_LMS_ATTACH_TYPE;
  188. autoc_reg &= ~IXGBE_AUTOC_LMS_MASK;
  189. autoc_reg |= hw->mac.link_attach_type;
  190. autoc_reg |= hw->mac.link_mode_select;
  191. IXGBE_WRITE_REG(hw, IXGBE_AUTOC, autoc_reg);
  192. IXGBE_WRITE_FLUSH(hw);
  193. msleep(50);
  194. }
  195. /* Restart link */
  196. autoc_reg |= IXGBE_AUTOC_AN_RESTART;
  197. IXGBE_WRITE_REG(hw, IXGBE_AUTOC, autoc_reg);
  198. /* Only poll for autoneg to complete if specified to do so */
  199. if (hw->phy.autoneg_wait_to_complete) {
  200. if (hw->mac.link_mode_select == IXGBE_AUTOC_LMS_KX4_AN ||
  201. hw->mac.link_mode_select == IXGBE_AUTOC_LMS_KX4_AN_1G_AN) {
  202. links_reg = 0; /* Just in case Autoneg time = 0 */
  203. for (i = 0; i < IXGBE_AUTO_NEG_TIME; i++) {
  204. links_reg = IXGBE_READ_REG(hw, IXGBE_LINKS);
  205. if (links_reg & IXGBE_LINKS_KX_AN_COMP)
  206. break;
  207. msleep(100);
  208. }
  209. if (!(links_reg & IXGBE_LINKS_KX_AN_COMP)) {
  210. status = IXGBE_ERR_AUTONEG_NOT_COMPLETE;
  211. hw_dbg(hw,
  212. "Autonegotiation did not complete.\n");
  213. }
  214. }
  215. }
  216. /*
  217. * We want to save off the original Flow Control configuration just in
  218. * case we get disconnected and then reconnected into a different hub
  219. * or switch with different Flow Control capabilities.
  220. */
  221. hw->fc.type = hw->fc.original_type;
  222. ixgbe_setup_fc(hw, 0);
  223. /* Add delay to filter out noises during initial link setup */
  224. msleep(50);
  225. return status;
  226. }
  227. /**
  228. * ixgbe_check_mac_link_82598 - Get link/speed status
  229. * @hw: pointer to hardware structure
  230. * @speed: pointer to link speed
  231. * @link_up: true is link is up, false otherwise
  232. *
  233. * Reads the links register to determine if link is up and the current speed
  234. **/
  235. static s32 ixgbe_check_mac_link_82598(struct ixgbe_hw *hw, u32 *speed,
  236. bool *link_up)
  237. {
  238. u32 links_reg;
  239. links_reg = IXGBE_READ_REG(hw, IXGBE_LINKS);
  240. if (links_reg & IXGBE_LINKS_UP)
  241. *link_up = true;
  242. else
  243. *link_up = false;
  244. if (links_reg & IXGBE_LINKS_SPEED)
  245. *speed = IXGBE_LINK_SPEED_10GB_FULL;
  246. else
  247. *speed = IXGBE_LINK_SPEED_1GB_FULL;
  248. return 0;
  249. }
  250. /**
  251. * ixgbe_setup_mac_link_speed_82598 - Set MAC link speed
  252. * @hw: pointer to hardware structure
  253. * @speed: new link speed
  254. * @autoneg: true if auto-negotiation enabled
  255. * @autoneg_wait_to_complete: true if waiting is needed to complete
  256. *
  257. * Set the link speed in the AUTOC register and restarts link.
  258. **/
  259. static s32 ixgbe_setup_mac_link_speed_82598(struct ixgbe_hw *hw,
  260. u32 speed, bool autoneg,
  261. bool autoneg_wait_to_complete)
  262. {
  263. s32 status = 0;
  264. /* If speed is 10G, then check for CX4 or XAUI. */
  265. if ((speed == IXGBE_LINK_SPEED_10GB_FULL) &&
  266. (!(hw->mac.link_attach_type & IXGBE_AUTOC_10G_KX4)))
  267. hw->mac.link_mode_select = IXGBE_AUTOC_LMS_10G_LINK_NO_AN;
  268. else if ((speed == IXGBE_LINK_SPEED_1GB_FULL) && (!autoneg))
  269. hw->mac.link_mode_select = IXGBE_AUTOC_LMS_1G_LINK_NO_AN;
  270. else if (autoneg) {
  271. /* BX mode - Autonegotiate 1G */
  272. if (!(hw->mac.link_attach_type & IXGBE_AUTOC_1G_PMA_PMD))
  273. hw->mac.link_mode_select = IXGBE_AUTOC_LMS_1G_AN;
  274. else /* KX/KX4 mode */
  275. hw->mac.link_mode_select = IXGBE_AUTOC_LMS_KX4_AN_1G_AN;
  276. } else {
  277. status = IXGBE_ERR_LINK_SETUP;
  278. }
  279. if (status == 0) {
  280. hw->phy.autoneg_wait_to_complete = autoneg_wait_to_complete;
  281. hw->mac.link_settings_loaded = true;
  282. /*
  283. * Setup and restart the link based on the new values in
  284. * ixgbe_hw This will write the AUTOC register based on the new
  285. * stored values
  286. */
  287. hw->mac.ops.setup_link(hw);
  288. }
  289. return status;
  290. }
  291. /**
  292. * ixgbe_setup_copper_link_82598 - Setup copper link settings
  293. * @hw: pointer to hardware structure
  294. *
  295. * Configures link settings based on values in the ixgbe_hw struct.
  296. * Restarts the link. Performs autonegotiation if needed. Restart
  297. * phy and wait for autonegotiate to finish. Then synchronize the
  298. * MAC and PHY.
  299. **/
  300. static s32 ixgbe_setup_copper_link_82598(struct ixgbe_hw *hw)
  301. {
  302. s32 status = 0;
  303. /* Restart autonegotiation on PHY */
  304. if (hw->phy.ops.setup_link)
  305. status = hw->phy.ops.setup_link(hw);
  306. /* Set MAC to KX/KX4 autoneg, which defaultis to Parallel detection */
  307. hw->mac.link_attach_type = (IXGBE_AUTOC_10G_KX4 | IXGBE_AUTOC_1G_KX);
  308. hw->mac.link_mode_select = IXGBE_AUTOC_LMS_KX4_AN;
  309. /* Set up MAC */
  310. hw->mac.ops.setup_link(hw);
  311. return status;
  312. }
  313. /**
  314. * ixgbe_setup_copper_link_speed_82598 - Set the PHY autoneg advertised field
  315. * @hw: pointer to hardware structure
  316. * @speed: new link speed
  317. * @autoneg: true if autonegotiation enabled
  318. * @autoneg_wait_to_complete: true if waiting is needed to complete
  319. *
  320. * Sets the link speed in the AUTOC register in the MAC and restarts link.
  321. **/
  322. static s32 ixgbe_setup_copper_link_speed_82598(struct ixgbe_hw *hw, u32 speed,
  323. bool autoneg,
  324. bool autoneg_wait_to_complete)
  325. {
  326. s32 status = 0;
  327. /* Setup the PHY according to input speed */
  328. if (hw->phy.ops.setup_link_speed)
  329. status = hw->phy.ops.setup_link_speed(hw, speed, autoneg,
  330. autoneg_wait_to_complete);
  331. /* Set MAC to KX/KX4 autoneg, which defaults to Parallel detection */
  332. hw->mac.link_attach_type = (IXGBE_AUTOC_10G_KX4 | IXGBE_AUTOC_1G_KX);
  333. hw->mac.link_mode_select = IXGBE_AUTOC_LMS_KX4_AN;
  334. /* Set up MAC */
  335. hw->mac.ops.setup_link(hw);
  336. return status;
  337. }
  338. /**
  339. * ixgbe_reset_hw_82598 - Performs hardware reset
  340. * @hw: pointer to hardware structure
  341. *
  342. * Resets the hardware by reseting the transmit and receive units, masks and
  343. * clears all interrupts, performing a PHY reset, and performing a link (MAC)
  344. * reset.
  345. **/
  346. static s32 ixgbe_reset_hw_82598(struct ixgbe_hw *hw)
  347. {
  348. s32 status = 0;
  349. u32 ctrl;
  350. u32 gheccr;
  351. u32 i;
  352. u32 autoc;
  353. u8 analog_val;
  354. /* Call adapter stop to disable tx/rx and clear interrupts */
  355. ixgbe_stop_adapter(hw);
  356. /*
  357. * Power up the Atlas TX lanes if they are currently powered down.
  358. * Atlas TX lanes are powered down for MAC loopback tests, but
  359. * they are not automatically restored on reset.
  360. */
  361. ixgbe_read_analog_reg8(hw, IXGBE_ATLAS_PDN_LPBK, &analog_val);
  362. if (analog_val & IXGBE_ATLAS_PDN_TX_REG_EN) {
  363. /* Enable TX Atlas so packets can be transmitted again */
  364. ixgbe_read_analog_reg8(hw, IXGBE_ATLAS_PDN_LPBK, &analog_val);
  365. analog_val &= ~IXGBE_ATLAS_PDN_TX_REG_EN;
  366. ixgbe_write_analog_reg8(hw, IXGBE_ATLAS_PDN_LPBK, analog_val);
  367. ixgbe_read_analog_reg8(hw, IXGBE_ATLAS_PDN_10G, &analog_val);
  368. analog_val &= ~IXGBE_ATLAS_PDN_TX_10G_QL_ALL;
  369. ixgbe_write_analog_reg8(hw, IXGBE_ATLAS_PDN_10G, analog_val);
  370. ixgbe_read_analog_reg8(hw, IXGBE_ATLAS_PDN_1G, &analog_val);
  371. analog_val &= ~IXGBE_ATLAS_PDN_TX_1G_QL_ALL;
  372. ixgbe_write_analog_reg8(hw, IXGBE_ATLAS_PDN_1G, analog_val);
  373. ixgbe_read_analog_reg8(hw, IXGBE_ATLAS_PDN_AN, &analog_val);
  374. analog_val &= ~IXGBE_ATLAS_PDN_TX_AN_QL_ALL;
  375. ixgbe_write_analog_reg8(hw, IXGBE_ATLAS_PDN_AN, analog_val);
  376. }
  377. /* Reset PHY */
  378. ixgbe_reset_phy(hw);
  379. /*
  380. * Prevent the PCI-E bus from from hanging by disabling PCI-E master
  381. * access and verify no pending requests before reset
  382. */
  383. if (ixgbe_disable_pcie_master(hw) != 0) {
  384. status = IXGBE_ERR_MASTER_REQUESTS_PENDING;
  385. hw_dbg(hw, "PCI-E Master disable polling has failed.\n");
  386. }
  387. /*
  388. * Issue global reset to the MAC. This needs to be a SW reset.
  389. * If link reset is used, it might reset the MAC when mng is using it
  390. */
  391. ctrl = IXGBE_READ_REG(hw, IXGBE_CTRL);
  392. IXGBE_WRITE_REG(hw, IXGBE_CTRL, (ctrl | IXGBE_CTRL_RST));
  393. IXGBE_WRITE_FLUSH(hw);
  394. /* Poll for reset bit to self-clear indicating reset is complete */
  395. for (i = 0; i < 10; i++) {
  396. udelay(1);
  397. ctrl = IXGBE_READ_REG(hw, IXGBE_CTRL);
  398. if (!(ctrl & IXGBE_CTRL_RST))
  399. break;
  400. }
  401. if (ctrl & IXGBE_CTRL_RST) {
  402. status = IXGBE_ERR_RESET_FAILED;
  403. hw_dbg(hw, "Reset polling failed to complete.\n");
  404. }
  405. msleep(50);
  406. gheccr = IXGBE_READ_REG(hw, IXGBE_GHECCR);
  407. gheccr &= ~((1 << 21) | (1 << 18) | (1 << 9) | (1 << 6));
  408. IXGBE_WRITE_REG(hw, IXGBE_GHECCR, gheccr);
  409. /*
  410. * AUTOC register which stores link settings gets cleared
  411. * and reloaded from EEPROM after reset. We need to restore
  412. * our stored value from init in case SW changed the attach
  413. * type or speed. If this is the first time and link settings
  414. * have not been stored, store default settings from AUTOC.
  415. */
  416. autoc = IXGBE_READ_REG(hw, IXGBE_AUTOC);
  417. if (hw->mac.link_settings_loaded) {
  418. autoc &= ~(IXGBE_AUTOC_LMS_ATTACH_TYPE);
  419. autoc &= ~(IXGBE_AUTOC_LMS_MASK);
  420. autoc |= hw->mac.link_attach_type;
  421. autoc |= hw->mac.link_mode_select;
  422. IXGBE_WRITE_REG(hw, IXGBE_AUTOC, autoc);
  423. } else {
  424. hw->mac.link_attach_type =
  425. (autoc & IXGBE_AUTOC_LMS_ATTACH_TYPE);
  426. hw->mac.link_mode_select = (autoc & IXGBE_AUTOC_LMS_MASK);
  427. hw->mac.link_settings_loaded = true;
  428. }
  429. /* Store the permanent mac address */
  430. ixgbe_get_mac_addr(hw, hw->mac.perm_addr);
  431. return status;
  432. }
  433. static struct ixgbe_mac_operations mac_ops_82598 = {
  434. .reset = &ixgbe_reset_hw_82598,
  435. .get_media_type = &ixgbe_get_media_type_82598,
  436. .setup_link = &ixgbe_setup_mac_link_82598,
  437. .check_link = &ixgbe_check_mac_link_82598,
  438. .setup_link_speed = &ixgbe_setup_mac_link_speed_82598,
  439. .get_link_settings = &ixgbe_get_link_settings_82598,
  440. };
  441. struct ixgbe_info ixgbe_82598_info = {
  442. .mac = ixgbe_mac_82598EB,
  443. .get_invariants = &ixgbe_get_invariants_82598,
  444. .mac_ops = &mac_ops_82598,
  445. };