ixgbe_82598.c 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941
  1. /*******************************************************************************
  2. Intel 10 Gigabit PCI Express Linux driver
  3. Copyright(c) 1999 - 2008 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. e1000-devel Mailing List <e1000-devel@lists.sourceforge.net>
  18. Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
  19. *******************************************************************************/
  20. #include <linux/pci.h>
  21. #include <linux/delay.h>
  22. #include <linux/sched.h>
  23. #include "ixgbe.h"
  24. #include "ixgbe_phy.h"
  25. #define IXGBE_82598_MAX_TX_QUEUES 32
  26. #define IXGBE_82598_MAX_RX_QUEUES 64
  27. #define IXGBE_82598_RAR_ENTRIES 16
  28. #define IXGBE_82598_MC_TBL_SIZE 128
  29. #define IXGBE_82598_VFT_TBL_SIZE 128
  30. static s32 ixgbe_get_copper_link_capabilities_82598(struct ixgbe_hw *hw,
  31. ixgbe_link_speed *speed,
  32. bool *autoneg);
  33. static s32 ixgbe_setup_copper_link_82598(struct ixgbe_hw *hw);
  34. static s32 ixgbe_setup_copper_link_speed_82598(struct ixgbe_hw *hw,
  35. ixgbe_link_speed speed,
  36. bool autoneg,
  37. bool autoneg_wait_to_complete);
  38. /**
  39. */
  40. static s32 ixgbe_get_invariants_82598(struct ixgbe_hw *hw)
  41. {
  42. struct ixgbe_mac_info *mac = &hw->mac;
  43. struct ixgbe_phy_info *phy = &hw->phy;
  44. /* Call PHY identify routine to get the phy type */
  45. ixgbe_identify_phy_generic(hw);
  46. /* PHY Init */
  47. switch (phy->type) {
  48. default:
  49. break;
  50. }
  51. if (mac->ops.get_media_type(hw) == ixgbe_media_type_copper) {
  52. mac->ops.setup_link = &ixgbe_setup_copper_link_82598;
  53. mac->ops.setup_link_speed =
  54. &ixgbe_setup_copper_link_speed_82598;
  55. mac->ops.get_link_capabilities =
  56. &ixgbe_get_copper_link_capabilities_82598;
  57. }
  58. mac->mcft_size = IXGBE_82598_MC_TBL_SIZE;
  59. mac->vft_size = IXGBE_82598_VFT_TBL_SIZE;
  60. mac->num_rar_entries = IXGBE_82598_RAR_ENTRIES;
  61. mac->max_rx_queues = IXGBE_82598_MAX_RX_QUEUES;
  62. mac->max_tx_queues = IXGBE_82598_MAX_TX_QUEUES;
  63. return 0;
  64. }
  65. /**
  66. * ixgbe_get_link_capabilities_82598 - Determines link capabilities
  67. * @hw: pointer to hardware structure
  68. * @speed: pointer to link speed
  69. * @autoneg: boolean auto-negotiation value
  70. *
  71. * Determines the link capabilities by reading the AUTOC register.
  72. **/
  73. static s32 ixgbe_get_link_capabilities_82598(struct ixgbe_hw *hw,
  74. ixgbe_link_speed *speed,
  75. bool *autoneg)
  76. {
  77. s32 status = 0;
  78. s32 autoc_reg;
  79. autoc_reg = IXGBE_READ_REG(hw, IXGBE_AUTOC);
  80. if (hw->mac.link_settings_loaded) {
  81. autoc_reg &= ~IXGBE_AUTOC_LMS_ATTACH_TYPE;
  82. autoc_reg &= ~IXGBE_AUTOC_LMS_MASK;
  83. autoc_reg |= hw->mac.link_attach_type;
  84. autoc_reg |= hw->mac.link_mode_select;
  85. }
  86. switch (autoc_reg & IXGBE_AUTOC_LMS_MASK) {
  87. case IXGBE_AUTOC_LMS_1G_LINK_NO_AN:
  88. *speed = IXGBE_LINK_SPEED_1GB_FULL;
  89. *autoneg = false;
  90. break;
  91. case IXGBE_AUTOC_LMS_10G_LINK_NO_AN:
  92. *speed = IXGBE_LINK_SPEED_10GB_FULL;
  93. *autoneg = false;
  94. break;
  95. case IXGBE_AUTOC_LMS_1G_AN:
  96. *speed = IXGBE_LINK_SPEED_1GB_FULL;
  97. *autoneg = true;
  98. break;
  99. case IXGBE_AUTOC_LMS_KX4_AN:
  100. case IXGBE_AUTOC_LMS_KX4_AN_1G_AN:
  101. *speed = IXGBE_LINK_SPEED_UNKNOWN;
  102. if (autoc_reg & IXGBE_AUTOC_KX4_SUPP)
  103. *speed |= IXGBE_LINK_SPEED_10GB_FULL;
  104. if (autoc_reg & IXGBE_AUTOC_KX_SUPP)
  105. *speed |= IXGBE_LINK_SPEED_1GB_FULL;
  106. *autoneg = true;
  107. break;
  108. default:
  109. status = IXGBE_ERR_LINK_SETUP;
  110. break;
  111. }
  112. return status;
  113. }
  114. /**
  115. * ixgbe_get_copper_link_capabilities_82598 - Determines link capabilities
  116. * @hw: pointer to hardware structure
  117. * @speed: pointer to link speed
  118. * @autoneg: boolean auto-negotiation value
  119. *
  120. * Determines the link capabilities by reading the AUTOC register.
  121. **/
  122. s32 ixgbe_get_copper_link_capabilities_82598(struct ixgbe_hw *hw,
  123. ixgbe_link_speed *speed,
  124. bool *autoneg)
  125. {
  126. s32 status = IXGBE_ERR_LINK_SETUP;
  127. u16 speed_ability;
  128. *speed = 0;
  129. *autoneg = true;
  130. status = hw->phy.ops.read_reg(hw, IXGBE_MDIO_PHY_SPEED_ABILITY,
  131. IXGBE_MDIO_PMA_PMD_DEV_TYPE,
  132. &speed_ability);
  133. if (status == 0) {
  134. if (speed_ability & IXGBE_MDIO_PHY_SPEED_10G)
  135. *speed |= IXGBE_LINK_SPEED_10GB_FULL;
  136. if (speed_ability & IXGBE_MDIO_PHY_SPEED_1G)
  137. *speed |= IXGBE_LINK_SPEED_1GB_FULL;
  138. }
  139. return status;
  140. }
  141. /**
  142. * ixgbe_get_media_type_82598 - Determines media type
  143. * @hw: pointer to hardware structure
  144. *
  145. * Returns the media type (fiber, copper, backplane)
  146. **/
  147. static enum ixgbe_media_type ixgbe_get_media_type_82598(struct ixgbe_hw *hw)
  148. {
  149. enum ixgbe_media_type media_type;
  150. /* Media type for I82598 is based on device ID */
  151. switch (hw->device_id) {
  152. case IXGBE_DEV_ID_82598AF_DUAL_PORT:
  153. case IXGBE_DEV_ID_82598AF_SINGLE_PORT:
  154. case IXGBE_DEV_ID_82598EB_CX4:
  155. case IXGBE_DEV_ID_82598_CX4_DUAL_PORT:
  156. case IXGBE_DEV_ID_82598EB_XF_LR:
  157. media_type = ixgbe_media_type_fiber;
  158. break;
  159. default:
  160. media_type = ixgbe_media_type_unknown;
  161. break;
  162. }
  163. return media_type;
  164. }
  165. /**
  166. * ixgbe_setup_fc_82598 - Configure flow control settings
  167. * @hw: pointer to hardware structure
  168. * @packetbuf_num: packet buffer number (0-7)
  169. *
  170. * Configures the flow control settings based on SW configuration. This
  171. * function is used for 802.3x flow control configuration only.
  172. **/
  173. s32 ixgbe_setup_fc_82598(struct ixgbe_hw *hw, s32 packetbuf_num)
  174. {
  175. u32 frctl_reg;
  176. u32 rmcs_reg;
  177. if (packetbuf_num < 0 || packetbuf_num > 7) {
  178. hw_dbg(hw, "Invalid packet buffer number [%d], expected range is"
  179. " 0-7\n", packetbuf_num);
  180. }
  181. frctl_reg = IXGBE_READ_REG(hw, IXGBE_FCTRL);
  182. frctl_reg &= ~(IXGBE_FCTRL_RFCE | IXGBE_FCTRL_RPFCE);
  183. rmcs_reg = IXGBE_READ_REG(hw, IXGBE_RMCS);
  184. rmcs_reg &= ~(IXGBE_RMCS_TFCE_PRIORITY | IXGBE_RMCS_TFCE_802_3X);
  185. /*
  186. * 10 gig parts do not have a word in the EEPROM to determine the
  187. * default flow control setting, so we explicitly set it to full.
  188. */
  189. if (hw->fc.type == ixgbe_fc_default)
  190. hw->fc.type = ixgbe_fc_full;
  191. /*
  192. * We want to save off the original Flow Control configuration just in
  193. * case we get disconnected and then reconnected into a different hub
  194. * or switch with different Flow Control capabilities.
  195. */
  196. hw->fc.original_type = hw->fc.type;
  197. /*
  198. * The possible values of the "flow_control" parameter are:
  199. * 0: Flow control is completely disabled
  200. * 1: Rx flow control is enabled (we can receive pause frames but not
  201. * send pause frames).
  202. * 2: Tx flow control is enabled (we can send pause frames but we do not
  203. * support receiving pause frames)
  204. * 3: Both Rx and Tx flow control (symmetric) are enabled.
  205. * other: Invalid.
  206. */
  207. switch (hw->fc.type) {
  208. case ixgbe_fc_none:
  209. break;
  210. case ixgbe_fc_rx_pause:
  211. /*
  212. * Rx Flow control is enabled,
  213. * and Tx Flow control is disabled.
  214. */
  215. frctl_reg |= IXGBE_FCTRL_RFCE;
  216. break;
  217. case ixgbe_fc_tx_pause:
  218. /*
  219. * Tx Flow control is enabled, and Rx Flow control is disabled,
  220. * by a software over-ride.
  221. */
  222. rmcs_reg |= IXGBE_RMCS_TFCE_802_3X;
  223. break;
  224. case ixgbe_fc_full:
  225. /*
  226. * Flow control (both Rx and Tx) is enabled by a software
  227. * over-ride.
  228. */
  229. frctl_reg |= IXGBE_FCTRL_RFCE;
  230. rmcs_reg |= IXGBE_RMCS_TFCE_802_3X;
  231. break;
  232. default:
  233. /* We should never get here. The value should be 0-3. */
  234. hw_dbg(hw, "Flow control param set incorrectly\n");
  235. break;
  236. }
  237. /* Enable 802.3x based flow control settings. */
  238. IXGBE_WRITE_REG(hw, IXGBE_FCTRL, frctl_reg);
  239. IXGBE_WRITE_REG(hw, IXGBE_RMCS, rmcs_reg);
  240. /*
  241. * Check for invalid software configuration, zeros are completely
  242. * invalid for all parameters used past this point, and if we enable
  243. * flow control with zero water marks, we blast flow control packets.
  244. */
  245. if (!hw->fc.low_water || !hw->fc.high_water || !hw->fc.pause_time) {
  246. hw_dbg(hw, "Flow control structure initialized incorrectly\n");
  247. return IXGBE_ERR_INVALID_LINK_SETTINGS;
  248. }
  249. /*
  250. * We need to set up the Receive Threshold high and low water
  251. * marks as well as (optionally) enabling the transmission of
  252. * XON frames.
  253. */
  254. if (hw->fc.type & ixgbe_fc_tx_pause) {
  255. if (hw->fc.send_xon) {
  256. IXGBE_WRITE_REG(hw, IXGBE_FCRTL(packetbuf_num),
  257. (hw->fc.low_water | IXGBE_FCRTL_XONE));
  258. } else {
  259. IXGBE_WRITE_REG(hw, IXGBE_FCRTL(packetbuf_num),
  260. hw->fc.low_water);
  261. }
  262. IXGBE_WRITE_REG(hw, IXGBE_FCRTH(packetbuf_num),
  263. (hw->fc.high_water)|IXGBE_FCRTH_FCEN);
  264. }
  265. IXGBE_WRITE_REG(hw, IXGBE_FCTTV(0), hw->fc.pause_time);
  266. IXGBE_WRITE_REG(hw, IXGBE_FCRTV, (hw->fc.pause_time >> 1));
  267. return 0;
  268. }
  269. /**
  270. * ixgbe_setup_mac_link_82598 - Configures MAC link settings
  271. * @hw: pointer to hardware structure
  272. *
  273. * Configures link settings based on values in the ixgbe_hw struct.
  274. * Restarts the link. Performs autonegotiation if needed.
  275. **/
  276. static s32 ixgbe_setup_mac_link_82598(struct ixgbe_hw *hw)
  277. {
  278. u32 autoc_reg;
  279. u32 links_reg;
  280. u32 i;
  281. s32 status = 0;
  282. autoc_reg = IXGBE_READ_REG(hw, IXGBE_AUTOC);
  283. if (hw->mac.link_settings_loaded) {
  284. autoc_reg &= ~IXGBE_AUTOC_LMS_ATTACH_TYPE;
  285. autoc_reg &= ~IXGBE_AUTOC_LMS_MASK;
  286. autoc_reg |= hw->mac.link_attach_type;
  287. autoc_reg |= hw->mac.link_mode_select;
  288. IXGBE_WRITE_REG(hw, IXGBE_AUTOC, autoc_reg);
  289. IXGBE_WRITE_FLUSH(hw);
  290. msleep(50);
  291. }
  292. /* Restart link */
  293. autoc_reg |= IXGBE_AUTOC_AN_RESTART;
  294. IXGBE_WRITE_REG(hw, IXGBE_AUTOC, autoc_reg);
  295. /* Only poll for autoneg to complete if specified to do so */
  296. if (hw->phy.autoneg_wait_to_complete) {
  297. if (hw->mac.link_mode_select == IXGBE_AUTOC_LMS_KX4_AN ||
  298. hw->mac.link_mode_select == IXGBE_AUTOC_LMS_KX4_AN_1G_AN) {
  299. links_reg = 0; /* Just in case Autoneg time = 0 */
  300. for (i = 0; i < IXGBE_AUTO_NEG_TIME; i++) {
  301. links_reg = IXGBE_READ_REG(hw, IXGBE_LINKS);
  302. if (links_reg & IXGBE_LINKS_KX_AN_COMP)
  303. break;
  304. msleep(100);
  305. }
  306. if (!(links_reg & IXGBE_LINKS_KX_AN_COMP)) {
  307. status = IXGBE_ERR_AUTONEG_NOT_COMPLETE;
  308. hw_dbg(hw, "Autonegotiation did not complete.\n");
  309. }
  310. }
  311. }
  312. /*
  313. * We want to save off the original Flow Control configuration just in
  314. * case we get disconnected and then reconnected into a different hub
  315. * or switch with different Flow Control capabilities.
  316. */
  317. hw->fc.original_type = hw->fc.type;
  318. ixgbe_setup_fc_82598(hw, 0);
  319. /* Add delay to filter out noises during initial link setup */
  320. msleep(50);
  321. return status;
  322. }
  323. /**
  324. * ixgbe_check_mac_link_82598 - Get link/speed status
  325. * @hw: pointer to hardware structure
  326. * @speed: pointer to link speed
  327. * @link_up: true is link is up, false otherwise
  328. * @link_up_wait_to_complete: bool used to wait for link up or not
  329. *
  330. * Reads the links register to determine if link is up and the current speed
  331. **/
  332. static s32 ixgbe_check_mac_link_82598(struct ixgbe_hw *hw,
  333. ixgbe_link_speed *speed, bool *link_up,
  334. bool link_up_wait_to_complete)
  335. {
  336. u32 links_reg;
  337. u32 i;
  338. links_reg = IXGBE_READ_REG(hw, IXGBE_LINKS);
  339. if (link_up_wait_to_complete) {
  340. for (i = 0; i < IXGBE_LINK_UP_TIME; i++) {
  341. if (links_reg & IXGBE_LINKS_UP) {
  342. *link_up = true;
  343. break;
  344. } else {
  345. *link_up = false;
  346. }
  347. msleep(100);
  348. links_reg = IXGBE_READ_REG(hw, IXGBE_LINKS);
  349. }
  350. } else {
  351. if (links_reg & IXGBE_LINKS_UP)
  352. *link_up = true;
  353. else
  354. *link_up = false;
  355. }
  356. if (links_reg & IXGBE_LINKS_SPEED)
  357. *speed = IXGBE_LINK_SPEED_10GB_FULL;
  358. else
  359. *speed = IXGBE_LINK_SPEED_1GB_FULL;
  360. return 0;
  361. }
  362. /**
  363. * ixgbe_setup_mac_link_speed_82598 - Set MAC link speed
  364. * @hw: pointer to hardware structure
  365. * @speed: new link speed
  366. * @autoneg: true if auto-negotiation enabled
  367. * @autoneg_wait_to_complete: true if waiting is needed to complete
  368. *
  369. * Set the link speed in the AUTOC register and restarts link.
  370. **/
  371. static s32 ixgbe_setup_mac_link_speed_82598(struct ixgbe_hw *hw,
  372. ixgbe_link_speed speed, bool autoneg,
  373. bool autoneg_wait_to_complete)
  374. {
  375. s32 status = 0;
  376. /* If speed is 10G, then check for CX4 or XAUI. */
  377. if ((speed == IXGBE_LINK_SPEED_10GB_FULL) &&
  378. (!(hw->mac.link_attach_type & IXGBE_AUTOC_10G_KX4))) {
  379. hw->mac.link_mode_select = IXGBE_AUTOC_LMS_10G_LINK_NO_AN;
  380. } else if ((speed == IXGBE_LINK_SPEED_1GB_FULL) && (!autoneg)) {
  381. hw->mac.link_mode_select = IXGBE_AUTOC_LMS_1G_LINK_NO_AN;
  382. } else if (autoneg) {
  383. /* BX mode - Autonegotiate 1G */
  384. if (!(hw->mac.link_attach_type & IXGBE_AUTOC_1G_PMA_PMD))
  385. hw->mac.link_mode_select = IXGBE_AUTOC_LMS_1G_AN;
  386. else /* KX/KX4 mode */
  387. hw->mac.link_mode_select = IXGBE_AUTOC_LMS_KX4_AN_1G_AN;
  388. } else {
  389. status = IXGBE_ERR_LINK_SETUP;
  390. }
  391. if (status == 0) {
  392. hw->phy.autoneg_wait_to_complete = autoneg_wait_to_complete;
  393. hw->mac.link_settings_loaded = true;
  394. /*
  395. * Setup and restart the link based on the new values in
  396. * ixgbe_hw This will write the AUTOC register based on the new
  397. * stored values
  398. */
  399. ixgbe_setup_mac_link_82598(hw);
  400. }
  401. return status;
  402. }
  403. /**
  404. * ixgbe_setup_copper_link_82598 - Setup copper link settings
  405. * @hw: pointer to hardware structure
  406. *
  407. * Configures link settings based on values in the ixgbe_hw struct.
  408. * Restarts the link. Performs autonegotiation if needed. Restart
  409. * phy and wait for autonegotiate to finish. Then synchronize the
  410. * MAC and PHY.
  411. **/
  412. static s32 ixgbe_setup_copper_link_82598(struct ixgbe_hw *hw)
  413. {
  414. s32 status;
  415. /* Restart autonegotiation on PHY */
  416. status = hw->phy.ops.setup_link(hw);
  417. /* Set MAC to KX/KX4 autoneg, which defaults to Parallel detection */
  418. hw->mac.link_attach_type = (IXGBE_AUTOC_10G_KX4 | IXGBE_AUTOC_1G_KX);
  419. hw->mac.link_mode_select = IXGBE_AUTOC_LMS_KX4_AN;
  420. /* Set up MAC */
  421. ixgbe_setup_mac_link_82598(hw);
  422. return status;
  423. }
  424. /**
  425. * ixgbe_setup_copper_link_speed_82598 - Set the PHY autoneg advertised field
  426. * @hw: pointer to hardware structure
  427. * @speed: new link speed
  428. * @autoneg: true if autonegotiation enabled
  429. * @autoneg_wait_to_complete: true if waiting is needed to complete
  430. *
  431. * Sets the link speed in the AUTOC register in the MAC and restarts link.
  432. **/
  433. static s32 ixgbe_setup_copper_link_speed_82598(struct ixgbe_hw *hw,
  434. ixgbe_link_speed speed,
  435. bool autoneg,
  436. bool autoneg_wait_to_complete)
  437. {
  438. s32 status;
  439. /* Setup the PHY according to input speed */
  440. status = hw->phy.ops.setup_link_speed(hw, speed, autoneg,
  441. autoneg_wait_to_complete);
  442. /* Set MAC to KX/KX4 autoneg, which defaults to Parallel detection */
  443. hw->mac.link_attach_type = (IXGBE_AUTOC_10G_KX4 | IXGBE_AUTOC_1G_KX);
  444. hw->mac.link_mode_select = IXGBE_AUTOC_LMS_KX4_AN;
  445. /* Set up MAC */
  446. ixgbe_setup_mac_link_82598(hw);
  447. return status;
  448. }
  449. /**
  450. * ixgbe_reset_hw_82598 - Performs hardware reset
  451. * @hw: pointer to hardware structure
  452. *
  453. * Resets the hardware by resetting the transmit and receive units, masks and
  454. * clears all interrupts, performing a PHY reset, and performing a link (MAC)
  455. * reset.
  456. **/
  457. static s32 ixgbe_reset_hw_82598(struct ixgbe_hw *hw)
  458. {
  459. s32 status = 0;
  460. u32 ctrl;
  461. u32 gheccr;
  462. u32 i;
  463. u32 autoc;
  464. u8 analog_val;
  465. /* Call adapter stop to disable tx/rx and clear interrupts */
  466. hw->mac.ops.stop_adapter(hw);
  467. /*
  468. * Power up the Atlas Tx lanes if they are currently powered down.
  469. * Atlas Tx lanes are powered down for MAC loopback tests, but
  470. * they are not automatically restored on reset.
  471. */
  472. hw->mac.ops.read_analog_reg8(hw, IXGBE_ATLAS_PDN_LPBK, &analog_val);
  473. if (analog_val & IXGBE_ATLAS_PDN_TX_REG_EN) {
  474. /* Enable Tx Atlas so packets can be transmitted again */
  475. hw->mac.ops.read_analog_reg8(hw, IXGBE_ATLAS_PDN_LPBK,
  476. &analog_val);
  477. analog_val &= ~IXGBE_ATLAS_PDN_TX_REG_EN;
  478. hw->mac.ops.write_analog_reg8(hw, IXGBE_ATLAS_PDN_LPBK,
  479. analog_val);
  480. hw->mac.ops.read_analog_reg8(hw, IXGBE_ATLAS_PDN_10G,
  481. &analog_val);
  482. analog_val &= ~IXGBE_ATLAS_PDN_TX_10G_QL_ALL;
  483. hw->mac.ops.write_analog_reg8(hw, IXGBE_ATLAS_PDN_10G,
  484. analog_val);
  485. hw->mac.ops.read_analog_reg8(hw, IXGBE_ATLAS_PDN_1G,
  486. &analog_val);
  487. analog_val &= ~IXGBE_ATLAS_PDN_TX_1G_QL_ALL;
  488. hw->mac.ops.write_analog_reg8(hw, IXGBE_ATLAS_PDN_1G,
  489. analog_val);
  490. hw->mac.ops.read_analog_reg8(hw, IXGBE_ATLAS_PDN_AN,
  491. &analog_val);
  492. analog_val &= ~IXGBE_ATLAS_PDN_TX_AN_QL_ALL;
  493. hw->mac.ops.write_analog_reg8(hw, IXGBE_ATLAS_PDN_AN,
  494. analog_val);
  495. }
  496. /* Reset PHY */
  497. if (hw->phy.reset_disable == false)
  498. hw->phy.ops.reset(hw);
  499. /*
  500. * Prevent the PCI-E bus from from hanging by disabling PCI-E master
  501. * access and verify no pending requests before reset
  502. */
  503. if (ixgbe_disable_pcie_master(hw) != 0) {
  504. status = IXGBE_ERR_MASTER_REQUESTS_PENDING;
  505. hw_dbg(hw, "PCI-E Master disable polling has failed.\n");
  506. }
  507. /*
  508. * Issue global reset to the MAC. This needs to be a SW reset.
  509. * If link reset is used, it might reset the MAC when mng is using it
  510. */
  511. ctrl = IXGBE_READ_REG(hw, IXGBE_CTRL);
  512. IXGBE_WRITE_REG(hw, IXGBE_CTRL, (ctrl | IXGBE_CTRL_RST));
  513. IXGBE_WRITE_FLUSH(hw);
  514. /* Poll for reset bit to self-clear indicating reset is complete */
  515. for (i = 0; i < 10; i++) {
  516. udelay(1);
  517. ctrl = IXGBE_READ_REG(hw, IXGBE_CTRL);
  518. if (!(ctrl & IXGBE_CTRL_RST))
  519. break;
  520. }
  521. if (ctrl & IXGBE_CTRL_RST) {
  522. status = IXGBE_ERR_RESET_FAILED;
  523. hw_dbg(hw, "Reset polling failed to complete.\n");
  524. }
  525. msleep(50);
  526. gheccr = IXGBE_READ_REG(hw, IXGBE_GHECCR);
  527. gheccr &= ~((1 << 21) | (1 << 18) | (1 << 9) | (1 << 6));
  528. IXGBE_WRITE_REG(hw, IXGBE_GHECCR, gheccr);
  529. /*
  530. * AUTOC register which stores link settings gets cleared
  531. * and reloaded from EEPROM after reset. We need to restore
  532. * our stored value from init in case SW changed the attach
  533. * type or speed. If this is the first time and link settings
  534. * have not been stored, store default settings from AUTOC.
  535. */
  536. autoc = IXGBE_READ_REG(hw, IXGBE_AUTOC);
  537. if (hw->mac.link_settings_loaded) {
  538. autoc &= ~(IXGBE_AUTOC_LMS_ATTACH_TYPE);
  539. autoc &= ~(IXGBE_AUTOC_LMS_MASK);
  540. autoc |= hw->mac.link_attach_type;
  541. autoc |= hw->mac.link_mode_select;
  542. IXGBE_WRITE_REG(hw, IXGBE_AUTOC, autoc);
  543. } else {
  544. hw->mac.link_attach_type =
  545. (autoc & IXGBE_AUTOC_LMS_ATTACH_TYPE);
  546. hw->mac.link_mode_select = (autoc & IXGBE_AUTOC_LMS_MASK);
  547. hw->mac.link_settings_loaded = true;
  548. }
  549. /* Store the permanent mac address */
  550. hw->mac.ops.get_mac_addr(hw, hw->mac.perm_addr);
  551. return status;
  552. }
  553. /**
  554. * ixgbe_set_vmdq_82598 - Associate a VMDq set index with a rx address
  555. * @hw: pointer to hardware struct
  556. * @rar: receive address register index to associate with a VMDq index
  557. * @vmdq: VMDq set index
  558. **/
  559. s32 ixgbe_set_vmdq_82598(struct ixgbe_hw *hw, u32 rar, u32 vmdq)
  560. {
  561. u32 rar_high;
  562. rar_high = IXGBE_READ_REG(hw, IXGBE_RAH(rar));
  563. rar_high &= ~IXGBE_RAH_VIND_MASK;
  564. rar_high |= ((vmdq << IXGBE_RAH_VIND_SHIFT) & IXGBE_RAH_VIND_MASK);
  565. IXGBE_WRITE_REG(hw, IXGBE_RAH(rar), rar_high);
  566. return 0;
  567. }
  568. /**
  569. * ixgbe_clear_vmdq_82598 - Disassociate a VMDq set index from an rx address
  570. * @hw: pointer to hardware struct
  571. * @rar: receive address register index to associate with a VMDq index
  572. * @vmdq: VMDq clear index (not used in 82598, but elsewhere)
  573. **/
  574. static s32 ixgbe_clear_vmdq_82598(struct ixgbe_hw *hw, u32 rar, u32 vmdq)
  575. {
  576. u32 rar_high;
  577. u32 rar_entries = hw->mac.num_rar_entries;
  578. if (rar < rar_entries) {
  579. rar_high = IXGBE_READ_REG(hw, IXGBE_RAH(rar));
  580. if (rar_high & IXGBE_RAH_VIND_MASK) {
  581. rar_high &= ~IXGBE_RAH_VIND_MASK;
  582. IXGBE_WRITE_REG(hw, IXGBE_RAH(rar), rar_high);
  583. }
  584. } else {
  585. hw_dbg(hw, "RAR index %d is out of range.\n", rar);
  586. }
  587. return 0;
  588. }
  589. /**
  590. * ixgbe_set_vfta_82598 - Set VLAN filter table
  591. * @hw: pointer to hardware structure
  592. * @vlan: VLAN id to write to VLAN filter
  593. * @vind: VMDq output index that maps queue to VLAN id in VFTA
  594. * @vlan_on: boolean flag to turn on/off VLAN in VFTA
  595. *
  596. * Turn on/off specified VLAN in the VLAN filter table.
  597. **/
  598. s32 ixgbe_set_vfta_82598(struct ixgbe_hw *hw, u32 vlan, u32 vind,
  599. bool vlan_on)
  600. {
  601. u32 regindex;
  602. u32 bitindex;
  603. u32 bits;
  604. u32 vftabyte;
  605. if (vlan > 4095)
  606. return IXGBE_ERR_PARAM;
  607. /* Determine 32-bit word position in array */
  608. regindex = (vlan >> 5) & 0x7F; /* upper seven bits */
  609. /* Determine the location of the (VMD) queue index */
  610. vftabyte = ((vlan >> 3) & 0x03); /* bits (4:3) indicating byte array */
  611. bitindex = (vlan & 0x7) << 2; /* lower 3 bits indicate nibble */
  612. /* Set the nibble for VMD queue index */
  613. bits = IXGBE_READ_REG(hw, IXGBE_VFTAVIND(vftabyte, regindex));
  614. bits &= (~(0x0F << bitindex));
  615. bits |= (vind << bitindex);
  616. IXGBE_WRITE_REG(hw, IXGBE_VFTAVIND(vftabyte, regindex), bits);
  617. /* Determine the location of the bit for this VLAN id */
  618. bitindex = vlan & 0x1F; /* lower five bits */
  619. bits = IXGBE_READ_REG(hw, IXGBE_VFTA(regindex));
  620. if (vlan_on)
  621. /* Turn on this VLAN id */
  622. bits |= (1 << bitindex);
  623. else
  624. /* Turn off this VLAN id */
  625. bits &= ~(1 << bitindex);
  626. IXGBE_WRITE_REG(hw, IXGBE_VFTA(regindex), bits);
  627. return 0;
  628. }
  629. /**
  630. * ixgbe_clear_vfta_82598 - Clear VLAN filter table
  631. * @hw: pointer to hardware structure
  632. *
  633. * Clears the VLAN filer table, and the VMDq index associated with the filter
  634. **/
  635. static s32 ixgbe_clear_vfta_82598(struct ixgbe_hw *hw)
  636. {
  637. u32 offset;
  638. u32 vlanbyte;
  639. for (offset = 0; offset < hw->mac.vft_size; offset++)
  640. IXGBE_WRITE_REG(hw, IXGBE_VFTA(offset), 0);
  641. for (vlanbyte = 0; vlanbyte < 4; vlanbyte++)
  642. for (offset = 0; offset < hw->mac.vft_size; offset++)
  643. IXGBE_WRITE_REG(hw, IXGBE_VFTAVIND(vlanbyte, offset),
  644. 0);
  645. return 0;
  646. }
  647. /**
  648. * ixgbe_blink_led_start_82598 - Blink LED based on index.
  649. * @hw: pointer to hardware structure
  650. * @index: led number to blink
  651. **/
  652. static s32 ixgbe_blink_led_start_82598(struct ixgbe_hw *hw, u32 index)
  653. {
  654. ixgbe_link_speed speed = 0;
  655. bool link_up = 0;
  656. u32 autoc_reg = IXGBE_READ_REG(hw, IXGBE_AUTOC);
  657. u32 led_reg = IXGBE_READ_REG(hw, IXGBE_LEDCTL);
  658. /*
  659. * Link must be up to auto-blink the LEDs on the 82598EB MAC;
  660. * force it if link is down.
  661. */
  662. hw->mac.ops.check_link(hw, &speed, &link_up, false);
  663. if (!link_up) {
  664. autoc_reg |= IXGBE_AUTOC_FLU;
  665. IXGBE_WRITE_REG(hw, IXGBE_AUTOC, autoc_reg);
  666. msleep(10);
  667. }
  668. led_reg &= ~IXGBE_LED_MODE_MASK(index);
  669. led_reg |= IXGBE_LED_BLINK(index);
  670. IXGBE_WRITE_REG(hw, IXGBE_LEDCTL, led_reg);
  671. IXGBE_WRITE_FLUSH(hw);
  672. return 0;
  673. }
  674. /**
  675. * ixgbe_blink_led_stop_82598 - Stop blinking LED based on index.
  676. * @hw: pointer to hardware structure
  677. * @index: led number to stop blinking
  678. **/
  679. static s32 ixgbe_blink_led_stop_82598(struct ixgbe_hw *hw, u32 index)
  680. {
  681. u32 autoc_reg = IXGBE_READ_REG(hw, IXGBE_AUTOC);
  682. u32 led_reg = IXGBE_READ_REG(hw, IXGBE_LEDCTL);
  683. autoc_reg &= ~IXGBE_AUTOC_FLU;
  684. autoc_reg |= IXGBE_AUTOC_AN_RESTART;
  685. IXGBE_WRITE_REG(hw, IXGBE_AUTOC, autoc_reg);
  686. led_reg &= ~IXGBE_LED_MODE_MASK(index);
  687. led_reg &= ~IXGBE_LED_BLINK(index);
  688. led_reg |= IXGBE_LED_LINK_ACTIVE << IXGBE_LED_MODE_SHIFT(index);
  689. IXGBE_WRITE_REG(hw, IXGBE_LEDCTL, led_reg);
  690. IXGBE_WRITE_FLUSH(hw);
  691. return 0;
  692. }
  693. /**
  694. * ixgbe_read_analog_reg8_82598 - Reads 8 bit Atlas analog register
  695. * @hw: pointer to hardware structure
  696. * @reg: analog register to read
  697. * @val: read value
  698. *
  699. * Performs read operation to Atlas analog register specified.
  700. **/
  701. s32 ixgbe_read_analog_reg8_82598(struct ixgbe_hw *hw, u32 reg, u8 *val)
  702. {
  703. u32 atlas_ctl;
  704. IXGBE_WRITE_REG(hw, IXGBE_ATLASCTL,
  705. IXGBE_ATLASCTL_WRITE_CMD | (reg << 8));
  706. IXGBE_WRITE_FLUSH(hw);
  707. udelay(10);
  708. atlas_ctl = IXGBE_READ_REG(hw, IXGBE_ATLASCTL);
  709. *val = (u8)atlas_ctl;
  710. return 0;
  711. }
  712. /**
  713. * ixgbe_write_analog_reg8_82598 - Writes 8 bit Atlas analog register
  714. * @hw: pointer to hardware structure
  715. * @reg: atlas register to write
  716. * @val: value to write
  717. *
  718. * Performs write operation to Atlas analog register specified.
  719. **/
  720. s32 ixgbe_write_analog_reg8_82598(struct ixgbe_hw *hw, u32 reg, u8 val)
  721. {
  722. u32 atlas_ctl;
  723. atlas_ctl = (reg << 8) | val;
  724. IXGBE_WRITE_REG(hw, IXGBE_ATLASCTL, atlas_ctl);
  725. IXGBE_WRITE_FLUSH(hw);
  726. udelay(10);
  727. return 0;
  728. }
  729. /**
  730. * ixgbe_get_supported_physical_layer_82598 - Returns physical layer type
  731. * @hw: pointer to hardware structure
  732. *
  733. * Determines physical layer capabilities of the current configuration.
  734. **/
  735. s32 ixgbe_get_supported_physical_layer_82598(struct ixgbe_hw *hw)
  736. {
  737. s32 physical_layer = IXGBE_PHYSICAL_LAYER_UNKNOWN;
  738. switch (hw->device_id) {
  739. case IXGBE_DEV_ID_82598EB_CX4:
  740. case IXGBE_DEV_ID_82598_CX4_DUAL_PORT:
  741. physical_layer = IXGBE_PHYSICAL_LAYER_10GBASE_CX4;
  742. break;
  743. case IXGBE_DEV_ID_82598AF_DUAL_PORT:
  744. case IXGBE_DEV_ID_82598AF_SINGLE_PORT:
  745. physical_layer = IXGBE_PHYSICAL_LAYER_10GBASE_SR;
  746. break;
  747. case IXGBE_DEV_ID_82598EB_XF_LR:
  748. physical_layer = IXGBE_PHYSICAL_LAYER_10GBASE_LR;
  749. break;
  750. default:
  751. physical_layer = IXGBE_PHYSICAL_LAYER_UNKNOWN;
  752. break;
  753. }
  754. return physical_layer;
  755. }
  756. static struct ixgbe_mac_operations mac_ops_82598 = {
  757. .init_hw = &ixgbe_init_hw_generic,
  758. .reset_hw = &ixgbe_reset_hw_82598,
  759. .start_hw = &ixgbe_start_hw_generic,
  760. .clear_hw_cntrs = &ixgbe_clear_hw_cntrs_generic,
  761. .get_media_type = &ixgbe_get_media_type_82598,
  762. .get_supported_physical_layer = &ixgbe_get_supported_physical_layer_82598,
  763. .get_mac_addr = &ixgbe_get_mac_addr_generic,
  764. .stop_adapter = &ixgbe_stop_adapter_generic,
  765. .read_analog_reg8 = &ixgbe_read_analog_reg8_82598,
  766. .write_analog_reg8 = &ixgbe_write_analog_reg8_82598,
  767. .setup_link = &ixgbe_setup_mac_link_82598,
  768. .setup_link_speed = &ixgbe_setup_mac_link_speed_82598,
  769. .check_link = &ixgbe_check_mac_link_82598,
  770. .get_link_capabilities = &ixgbe_get_link_capabilities_82598,
  771. .led_on = &ixgbe_led_on_generic,
  772. .led_off = &ixgbe_led_off_generic,
  773. .blink_led_start = &ixgbe_blink_led_start_82598,
  774. .blink_led_stop = &ixgbe_blink_led_stop_82598,
  775. .set_rar = &ixgbe_set_rar_generic,
  776. .clear_rar = &ixgbe_clear_rar_generic,
  777. .set_vmdq = &ixgbe_set_vmdq_82598,
  778. .clear_vmdq = &ixgbe_clear_vmdq_82598,
  779. .init_rx_addrs = &ixgbe_init_rx_addrs_generic,
  780. .update_uc_addr_list = &ixgbe_update_uc_addr_list_generic,
  781. .update_mc_addr_list = &ixgbe_update_mc_addr_list_generic,
  782. .enable_mc = &ixgbe_enable_mc_generic,
  783. .disable_mc = &ixgbe_disable_mc_generic,
  784. .clear_vfta = &ixgbe_clear_vfta_82598,
  785. .set_vfta = &ixgbe_set_vfta_82598,
  786. .setup_fc = &ixgbe_setup_fc_82598,
  787. };
  788. static struct ixgbe_eeprom_operations eeprom_ops_82598 = {
  789. .init_params = &ixgbe_init_eeprom_params_generic,
  790. .read = &ixgbe_read_eeprom_generic,
  791. .validate_checksum = &ixgbe_validate_eeprom_checksum_generic,
  792. .update_checksum = &ixgbe_update_eeprom_checksum_generic,
  793. };
  794. static struct ixgbe_phy_operations phy_ops_82598 = {
  795. .identify = &ixgbe_identify_phy_generic,
  796. /* .identify_sfp = &ixgbe_identify_sfp_module_generic, */
  797. .reset = &ixgbe_reset_phy_generic,
  798. .read_reg = &ixgbe_read_phy_reg_generic,
  799. .write_reg = &ixgbe_write_phy_reg_generic,
  800. .setup_link = &ixgbe_setup_phy_link_generic,
  801. .setup_link_speed = &ixgbe_setup_phy_link_speed_generic,
  802. };
  803. struct ixgbe_info ixgbe_82598_info = {
  804. .mac = ixgbe_mac_82598EB,
  805. .get_invariants = &ixgbe_get_invariants_82598,
  806. .mac_ops = &mac_ops_82598,
  807. .eeprom_ops = &eeprom_ops_82598,
  808. .phy_ops = &phy_ops_82598,
  809. };