ixgbe_82598.c 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526
  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_TX_QUEUES;
  49. hw->mac.num_tx_queues = IXGBE_82598_MAX_RX_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. media_type = ixgbe_media_type_fiber;
  161. break;
  162. case IXGBE_DEV_ID_82598AT_DUAL_PORT:
  163. media_type = ixgbe_media_type_copper;
  164. break;
  165. default:
  166. media_type = ixgbe_media_type_unknown;
  167. break;
  168. }
  169. return media_type;
  170. }
  171. /**
  172. * ixgbe_setup_mac_link_82598 - Configures MAC link settings
  173. * @hw: pointer to hardware structure
  174. *
  175. * Configures link settings based on values in the ixgbe_hw struct.
  176. * Restarts the link. Performs autonegotiation if needed.
  177. **/
  178. static s32 ixgbe_setup_mac_link_82598(struct ixgbe_hw *hw)
  179. {
  180. u32 autoc_reg;
  181. u32 links_reg;
  182. u32 i;
  183. s32 status = 0;
  184. autoc_reg = IXGBE_READ_REG(hw, IXGBE_AUTOC);
  185. if (hw->mac.link_settings_loaded) {
  186. autoc_reg &= ~IXGBE_AUTOC_LMS_ATTACH_TYPE;
  187. autoc_reg &= ~IXGBE_AUTOC_LMS_MASK;
  188. autoc_reg |= hw->mac.link_attach_type;
  189. autoc_reg |= hw->mac.link_mode_select;
  190. IXGBE_WRITE_REG(hw, IXGBE_AUTOC, autoc_reg);
  191. IXGBE_WRITE_FLUSH(hw);
  192. msleep(50);
  193. }
  194. /* Restart link */
  195. autoc_reg |= IXGBE_AUTOC_AN_RESTART;
  196. IXGBE_WRITE_REG(hw, IXGBE_AUTOC, autoc_reg);
  197. /* Only poll for autoneg to complete if specified to do so */
  198. if (hw->phy.autoneg_wait_to_complete) {
  199. if (hw->mac.link_mode_select == IXGBE_AUTOC_LMS_KX4_AN ||
  200. hw->mac.link_mode_select == IXGBE_AUTOC_LMS_KX4_AN_1G_AN) {
  201. links_reg = 0; /* Just in case Autoneg time = 0 */
  202. for (i = 0; i < IXGBE_AUTO_NEG_TIME; i++) {
  203. links_reg = IXGBE_READ_REG(hw, IXGBE_LINKS);
  204. if (links_reg & IXGBE_LINKS_KX_AN_COMP)
  205. break;
  206. msleep(100);
  207. }
  208. if (!(links_reg & IXGBE_LINKS_KX_AN_COMP)) {
  209. status = IXGBE_ERR_AUTONEG_NOT_COMPLETE;
  210. hw_dbg(hw,
  211. "Autonegotiation did not complete.\n");
  212. }
  213. }
  214. }
  215. /*
  216. * We want to save off the original Flow Control configuration just in
  217. * case we get disconnected and then reconnected into a different hub
  218. * or switch with different Flow Control capabilities.
  219. */
  220. hw->fc.type = hw->fc.original_type;
  221. ixgbe_setup_fc(hw, 0);
  222. /* Add delay to filter out noises during initial link setup */
  223. msleep(50);
  224. return status;
  225. }
  226. /**
  227. * ixgbe_check_mac_link_82598 - Get link/speed status
  228. * @hw: pointer to hardware structure
  229. * @speed: pointer to link speed
  230. * @link_up: true is link is up, false otherwise
  231. *
  232. * Reads the links register to determine if link is up and the current speed
  233. **/
  234. static s32 ixgbe_check_mac_link_82598(struct ixgbe_hw *hw, u32 *speed,
  235. bool *link_up)
  236. {
  237. u32 links_reg;
  238. links_reg = IXGBE_READ_REG(hw, IXGBE_LINKS);
  239. if (links_reg & IXGBE_LINKS_UP)
  240. *link_up = true;
  241. else
  242. *link_up = false;
  243. if (links_reg & IXGBE_LINKS_SPEED)
  244. *speed = IXGBE_LINK_SPEED_10GB_FULL;
  245. else
  246. *speed = IXGBE_LINK_SPEED_1GB_FULL;
  247. return 0;
  248. }
  249. /**
  250. * ixgbe_setup_mac_link_speed_82598 - Set MAC link speed
  251. * @hw: pointer to hardware structure
  252. * @speed: new link speed
  253. * @autoneg: true if auto-negotiation enabled
  254. * @autoneg_wait_to_complete: true if waiting is needed to complete
  255. *
  256. * Set the link speed in the AUTOC register and restarts link.
  257. **/
  258. static s32 ixgbe_setup_mac_link_speed_82598(struct ixgbe_hw *hw,
  259. u32 speed, bool autoneg,
  260. bool autoneg_wait_to_complete)
  261. {
  262. s32 status = 0;
  263. /* If speed is 10G, then check for CX4 or XAUI. */
  264. if ((speed == IXGBE_LINK_SPEED_10GB_FULL) &&
  265. (!(hw->mac.link_attach_type & IXGBE_AUTOC_10G_KX4)))
  266. hw->mac.link_mode_select = IXGBE_AUTOC_LMS_10G_LINK_NO_AN;
  267. else if ((speed == IXGBE_LINK_SPEED_1GB_FULL) && (!autoneg))
  268. hw->mac.link_mode_select = IXGBE_AUTOC_LMS_1G_LINK_NO_AN;
  269. else if (autoneg) {
  270. /* BX mode - Autonegotiate 1G */
  271. if (!(hw->mac.link_attach_type & IXGBE_AUTOC_1G_PMA_PMD))
  272. hw->mac.link_mode_select = IXGBE_AUTOC_LMS_1G_AN;
  273. else /* KX/KX4 mode */
  274. hw->mac.link_mode_select = IXGBE_AUTOC_LMS_KX4_AN_1G_AN;
  275. } else {
  276. status = IXGBE_ERR_LINK_SETUP;
  277. }
  278. if (status == 0) {
  279. hw->phy.autoneg_wait_to_complete = autoneg_wait_to_complete;
  280. hw->mac.link_settings_loaded = true;
  281. /*
  282. * Setup and restart the link based on the new values in
  283. * ixgbe_hw This will write the AUTOC register based on the new
  284. * stored values
  285. */
  286. hw->mac.ops.setup_link(hw);
  287. }
  288. return status;
  289. }
  290. /**
  291. * ixgbe_setup_copper_link_82598 - Setup copper link settings
  292. * @hw: pointer to hardware structure
  293. *
  294. * Configures link settings based on values in the ixgbe_hw struct.
  295. * Restarts the link. Performs autonegotiation if needed. Restart
  296. * phy and wait for autonegotiate to finish. Then synchronize the
  297. * MAC and PHY.
  298. **/
  299. static s32 ixgbe_setup_copper_link_82598(struct ixgbe_hw *hw)
  300. {
  301. s32 status = 0;
  302. /* Restart autonegotiation on PHY */
  303. if (hw->phy.ops.setup_link)
  304. status = hw->phy.ops.setup_link(hw);
  305. /* Set MAC to KX/KX4 autoneg, which defaultis to Parallel detection */
  306. hw->mac.link_attach_type = (IXGBE_AUTOC_10G_KX4 | IXGBE_AUTOC_1G_KX);
  307. hw->mac.link_mode_select = IXGBE_AUTOC_LMS_KX4_AN;
  308. /* Set up MAC */
  309. hw->mac.ops.setup_link(hw);
  310. return status;
  311. }
  312. /**
  313. * ixgbe_setup_copper_link_speed_82598 - Set the PHY autoneg advertised field
  314. * @hw: pointer to hardware structure
  315. * @speed: new link speed
  316. * @autoneg: true if autonegotiation enabled
  317. * @autoneg_wait_to_complete: true if waiting is needed to complete
  318. *
  319. * Sets the link speed in the AUTOC register in the MAC and restarts link.
  320. **/
  321. static s32 ixgbe_setup_copper_link_speed_82598(struct ixgbe_hw *hw, u32 speed,
  322. bool autoneg,
  323. bool autoneg_wait_to_complete)
  324. {
  325. s32 status = 0;
  326. /* Setup the PHY according to input speed */
  327. if (hw->phy.ops.setup_link_speed)
  328. status = hw->phy.ops.setup_link_speed(hw, speed, autoneg,
  329. autoneg_wait_to_complete);
  330. /* Set MAC to KX/KX4 autoneg, which defaults to Parallel detection */
  331. hw->mac.link_attach_type = (IXGBE_AUTOC_10G_KX4 | IXGBE_AUTOC_1G_KX);
  332. hw->mac.link_mode_select = IXGBE_AUTOC_LMS_KX4_AN;
  333. /* Set up MAC */
  334. hw->mac.ops.setup_link(hw);
  335. return status;
  336. }
  337. /**
  338. * ixgbe_reset_hw_82598 - Performs hardware reset
  339. * @hw: pointer to hardware structure
  340. *
  341. * Resets the hardware by reseting the transmit and receive units, masks and
  342. * clears all interrupts, performing a PHY reset, and performing a link (MAC)
  343. * reset.
  344. **/
  345. static s32 ixgbe_reset_hw_82598(struct ixgbe_hw *hw)
  346. {
  347. s32 status = 0;
  348. u32 ctrl;
  349. u32 gheccr;
  350. u32 i;
  351. u32 autoc;
  352. u8 analog_val;
  353. /* Call adapter stop to disable tx/rx and clear interrupts */
  354. ixgbe_stop_adapter(hw);
  355. /*
  356. * Power up the Atlas TX lanes if they are currently powered down.
  357. * Atlas TX lanes are powered down for MAC loopback tests, but
  358. * they are not automatically restored on reset.
  359. */
  360. ixgbe_read_analog_reg8(hw, IXGBE_ATLAS_PDN_LPBK, &analog_val);
  361. if (analog_val & IXGBE_ATLAS_PDN_TX_REG_EN) {
  362. /* Enable TX Atlas so packets can be transmitted again */
  363. ixgbe_read_analog_reg8(hw, IXGBE_ATLAS_PDN_LPBK, &analog_val);
  364. analog_val &= ~IXGBE_ATLAS_PDN_TX_REG_EN;
  365. ixgbe_write_analog_reg8(hw, IXGBE_ATLAS_PDN_LPBK, analog_val);
  366. ixgbe_read_analog_reg8(hw, IXGBE_ATLAS_PDN_10G, &analog_val);
  367. analog_val &= ~IXGBE_ATLAS_PDN_TX_10G_QL_ALL;
  368. ixgbe_write_analog_reg8(hw, IXGBE_ATLAS_PDN_10G, analog_val);
  369. ixgbe_read_analog_reg8(hw, IXGBE_ATLAS_PDN_1G, &analog_val);
  370. analog_val &= ~IXGBE_ATLAS_PDN_TX_1G_QL_ALL;
  371. ixgbe_write_analog_reg8(hw, IXGBE_ATLAS_PDN_1G, analog_val);
  372. ixgbe_read_analog_reg8(hw, IXGBE_ATLAS_PDN_AN, &analog_val);
  373. analog_val &= ~IXGBE_ATLAS_PDN_TX_AN_QL_ALL;
  374. ixgbe_write_analog_reg8(hw, IXGBE_ATLAS_PDN_AN, analog_val);
  375. }
  376. /* Reset PHY */
  377. ixgbe_reset_phy(hw);
  378. /*
  379. * Prevent the PCI-E bus from from hanging by disabling PCI-E master
  380. * access and verify no pending requests before reset
  381. */
  382. if (ixgbe_disable_pcie_master(hw) != 0) {
  383. status = IXGBE_ERR_MASTER_REQUESTS_PENDING;
  384. hw_dbg(hw, "PCI-E Master disable polling has failed.\n");
  385. }
  386. /*
  387. * Issue global reset to the MAC. This needs to be a SW reset.
  388. * If link reset is used, it might reset the MAC when mng is using it
  389. */
  390. ctrl = IXGBE_READ_REG(hw, IXGBE_CTRL);
  391. IXGBE_WRITE_REG(hw, IXGBE_CTRL, (ctrl | IXGBE_CTRL_RST));
  392. IXGBE_WRITE_FLUSH(hw);
  393. /* Poll for reset bit to self-clear indicating reset is complete */
  394. for (i = 0; i < 10; i++) {
  395. udelay(1);
  396. ctrl = IXGBE_READ_REG(hw, IXGBE_CTRL);
  397. if (!(ctrl & IXGBE_CTRL_RST))
  398. break;
  399. }
  400. if (ctrl & IXGBE_CTRL_RST) {
  401. status = IXGBE_ERR_RESET_FAILED;
  402. hw_dbg(hw, "Reset polling failed to complete.\n");
  403. }
  404. msleep(50);
  405. gheccr = IXGBE_READ_REG(hw, IXGBE_GHECCR);
  406. gheccr &= ~((1 << 21) | (1 << 18) | (1 << 9) | (1 << 6));
  407. IXGBE_WRITE_REG(hw, IXGBE_GHECCR, gheccr);
  408. /*
  409. * AUTOC register which stores link settings gets cleared
  410. * and reloaded from EEPROM after reset. We need to restore
  411. * our stored value from init in case SW changed the attach
  412. * type or speed. If this is the first time and link settings
  413. * have not been stored, store default settings from AUTOC.
  414. */
  415. autoc = IXGBE_READ_REG(hw, IXGBE_AUTOC);
  416. if (hw->mac.link_settings_loaded) {
  417. autoc &= ~(IXGBE_AUTOC_LMS_ATTACH_TYPE);
  418. autoc &= ~(IXGBE_AUTOC_LMS_MASK);
  419. autoc |= hw->mac.link_attach_type;
  420. autoc |= hw->mac.link_mode_select;
  421. IXGBE_WRITE_REG(hw, IXGBE_AUTOC, autoc);
  422. } else {
  423. hw->mac.link_attach_type =
  424. (autoc & IXGBE_AUTOC_LMS_ATTACH_TYPE);
  425. hw->mac.link_mode_select = (autoc & IXGBE_AUTOC_LMS_MASK);
  426. hw->mac.link_settings_loaded = true;
  427. }
  428. /* Store the permanent mac address */
  429. ixgbe_get_mac_addr(hw, hw->mac.perm_addr);
  430. return status;
  431. }
  432. static struct ixgbe_mac_operations mac_ops_82598 = {
  433. .reset = &ixgbe_reset_hw_82598,
  434. .get_media_type = &ixgbe_get_media_type_82598,
  435. .setup_link = &ixgbe_setup_mac_link_82598,
  436. .check_link = &ixgbe_check_mac_link_82598,
  437. .setup_link_speed = &ixgbe_setup_mac_link_speed_82598,
  438. .get_link_settings = &ixgbe_get_link_settings_82598,
  439. };
  440. struct ixgbe_info ixgbe_82598_info = {
  441. .mac = ixgbe_mac_82598EB,
  442. .get_invariants = &ixgbe_get_invariants_82598,
  443. .mac_ops = &mac_ops_82598,
  444. };