ixgbe_82598.c 38 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311
  1. /*******************************************************************************
  2. Intel 10 Gigabit PCI Express Linux driver
  3. Copyright(c) 1999 - 2011 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. #define IXGBE_82598_RX_PB_SIZE 512
  31. static s32 ixgbe_setup_copper_link_82598(struct ixgbe_hw *hw,
  32. ixgbe_link_speed speed,
  33. bool autoneg,
  34. bool autoneg_wait_to_complete);
  35. static s32 ixgbe_read_i2c_eeprom_82598(struct ixgbe_hw *hw, u8 byte_offset,
  36. u8 *eeprom_data);
  37. /**
  38. * ixgbe_set_pcie_completion_timeout - set pci-e completion timeout
  39. * @hw: pointer to the HW structure
  40. *
  41. * The defaults for 82598 should be in the range of 50us to 50ms,
  42. * however the hardware default for these parts is 500us to 1ms which is less
  43. * than the 10ms recommended by the pci-e spec. To address this we need to
  44. * increase the value to either 10ms to 250ms for capability version 1 config,
  45. * or 16ms to 55ms for version 2.
  46. **/
  47. static void ixgbe_set_pcie_completion_timeout(struct ixgbe_hw *hw)
  48. {
  49. struct ixgbe_adapter *adapter = hw->back;
  50. u32 gcr = IXGBE_READ_REG(hw, IXGBE_GCR);
  51. u16 pcie_devctl2;
  52. /* only take action if timeout value is defaulted to 0 */
  53. if (gcr & IXGBE_GCR_CMPL_TMOUT_MASK)
  54. goto out;
  55. /*
  56. * if capababilities version is type 1 we can write the
  57. * timeout of 10ms to 250ms through the GCR register
  58. */
  59. if (!(gcr & IXGBE_GCR_CAP_VER2)) {
  60. gcr |= IXGBE_GCR_CMPL_TMOUT_10ms;
  61. goto out;
  62. }
  63. /*
  64. * for version 2 capabilities we need to write the config space
  65. * directly in order to set the completion timeout value for
  66. * 16ms to 55ms
  67. */
  68. pci_read_config_word(adapter->pdev,
  69. IXGBE_PCI_DEVICE_CONTROL2, &pcie_devctl2);
  70. pcie_devctl2 |= IXGBE_PCI_DEVICE_CONTROL2_16ms;
  71. pci_write_config_word(adapter->pdev,
  72. IXGBE_PCI_DEVICE_CONTROL2, pcie_devctl2);
  73. out:
  74. /* disable completion timeout resend */
  75. gcr &= ~IXGBE_GCR_CMPL_TMOUT_RESEND;
  76. IXGBE_WRITE_REG(hw, IXGBE_GCR, gcr);
  77. }
  78. /**
  79. * ixgbe_get_pcie_msix_count_82598 - Gets MSI-X vector count
  80. * @hw: pointer to hardware structure
  81. *
  82. * Read PCIe configuration space, and get the MSI-X vector count from
  83. * the capabilities table.
  84. **/
  85. static u16 ixgbe_get_pcie_msix_count_82598(struct ixgbe_hw *hw)
  86. {
  87. struct ixgbe_adapter *adapter = hw->back;
  88. u16 msix_count;
  89. pci_read_config_word(adapter->pdev, IXGBE_PCIE_MSIX_82598_CAPS,
  90. &msix_count);
  91. msix_count &= IXGBE_PCIE_MSIX_TBL_SZ_MASK;
  92. /* MSI-X count is zero-based in HW, so increment to give proper value */
  93. msix_count++;
  94. return msix_count;
  95. }
  96. /**
  97. */
  98. static s32 ixgbe_get_invariants_82598(struct ixgbe_hw *hw)
  99. {
  100. struct ixgbe_mac_info *mac = &hw->mac;
  101. /* Call PHY identify routine to get the phy type */
  102. ixgbe_identify_phy_generic(hw);
  103. mac->mcft_size = IXGBE_82598_MC_TBL_SIZE;
  104. mac->vft_size = IXGBE_82598_VFT_TBL_SIZE;
  105. mac->num_rar_entries = IXGBE_82598_RAR_ENTRIES;
  106. mac->max_rx_queues = IXGBE_82598_MAX_RX_QUEUES;
  107. mac->max_tx_queues = IXGBE_82598_MAX_TX_QUEUES;
  108. mac->max_msix_vectors = ixgbe_get_pcie_msix_count_82598(hw);
  109. return 0;
  110. }
  111. /**
  112. * ixgbe_init_phy_ops_82598 - PHY/SFP specific init
  113. * @hw: pointer to hardware structure
  114. *
  115. * Initialize any function pointers that were not able to be
  116. * set during get_invariants because the PHY/SFP type was
  117. * not known. Perform the SFP init if necessary.
  118. *
  119. **/
  120. static s32 ixgbe_init_phy_ops_82598(struct ixgbe_hw *hw)
  121. {
  122. struct ixgbe_mac_info *mac = &hw->mac;
  123. struct ixgbe_phy_info *phy = &hw->phy;
  124. s32 ret_val = 0;
  125. u16 list_offset, data_offset;
  126. /* Identify the PHY */
  127. phy->ops.identify(hw);
  128. /* Overwrite the link function pointers if copper PHY */
  129. if (mac->ops.get_media_type(hw) == ixgbe_media_type_copper) {
  130. mac->ops.setup_link = &ixgbe_setup_copper_link_82598;
  131. mac->ops.get_link_capabilities =
  132. &ixgbe_get_copper_link_capabilities_generic;
  133. }
  134. switch (hw->phy.type) {
  135. case ixgbe_phy_tn:
  136. phy->ops.setup_link = &ixgbe_setup_phy_link_tnx;
  137. phy->ops.check_link = &ixgbe_check_phy_link_tnx;
  138. phy->ops.get_firmware_version =
  139. &ixgbe_get_phy_firmware_version_tnx;
  140. break;
  141. case ixgbe_phy_nl:
  142. phy->ops.reset = &ixgbe_reset_phy_nl;
  143. /* Call SFP+ identify routine to get the SFP+ module type */
  144. ret_val = phy->ops.identify_sfp(hw);
  145. if (ret_val != 0)
  146. goto out;
  147. else if (hw->phy.sfp_type == ixgbe_sfp_type_unknown) {
  148. ret_val = IXGBE_ERR_SFP_NOT_SUPPORTED;
  149. goto out;
  150. }
  151. /* Check to see if SFP+ module is supported */
  152. ret_val = ixgbe_get_sfp_init_sequence_offsets(hw,
  153. &list_offset,
  154. &data_offset);
  155. if (ret_val != 0) {
  156. ret_val = IXGBE_ERR_SFP_NOT_SUPPORTED;
  157. goto out;
  158. }
  159. break;
  160. default:
  161. break;
  162. }
  163. out:
  164. return ret_val;
  165. }
  166. /**
  167. * ixgbe_start_hw_82598 - Prepare hardware for Tx/Rx
  168. * @hw: pointer to hardware structure
  169. *
  170. * Starts the hardware using the generic start_hw function.
  171. * Disables relaxed ordering Then set pcie completion timeout
  172. *
  173. **/
  174. static s32 ixgbe_start_hw_82598(struct ixgbe_hw *hw)
  175. {
  176. u32 regval;
  177. u32 i;
  178. s32 ret_val = 0;
  179. ret_val = ixgbe_start_hw_generic(hw);
  180. /* Disable relaxed ordering */
  181. for (i = 0; ((i < hw->mac.max_tx_queues) &&
  182. (i < IXGBE_DCA_MAX_QUEUES_82598)); i++) {
  183. regval = IXGBE_READ_REG(hw, IXGBE_DCA_TXCTRL(i));
  184. regval &= ~IXGBE_DCA_TXCTRL_TX_WB_RO_EN;
  185. IXGBE_WRITE_REG(hw, IXGBE_DCA_TXCTRL(i), regval);
  186. }
  187. for (i = 0; ((i < hw->mac.max_rx_queues) &&
  188. (i < IXGBE_DCA_MAX_QUEUES_82598)); i++) {
  189. regval = IXGBE_READ_REG(hw, IXGBE_DCA_RXCTRL(i));
  190. regval &= ~(IXGBE_DCA_RXCTRL_DESC_WRO_EN |
  191. IXGBE_DCA_RXCTRL_DESC_HSRO_EN);
  192. IXGBE_WRITE_REG(hw, IXGBE_DCA_RXCTRL(i), regval);
  193. }
  194. hw->mac.rx_pb_size = IXGBE_82598_RX_PB_SIZE;
  195. /* set the completion timeout for interface */
  196. if (ret_val == 0)
  197. ixgbe_set_pcie_completion_timeout(hw);
  198. return ret_val;
  199. }
  200. /**
  201. * ixgbe_get_link_capabilities_82598 - Determines link capabilities
  202. * @hw: pointer to hardware structure
  203. * @speed: pointer to link speed
  204. * @autoneg: boolean auto-negotiation value
  205. *
  206. * Determines the link capabilities by reading the AUTOC register.
  207. **/
  208. static s32 ixgbe_get_link_capabilities_82598(struct ixgbe_hw *hw,
  209. ixgbe_link_speed *speed,
  210. bool *autoneg)
  211. {
  212. s32 status = 0;
  213. u32 autoc = 0;
  214. /*
  215. * Determine link capabilities based on the stored value of AUTOC,
  216. * which represents EEPROM defaults. If AUTOC value has not been
  217. * stored, use the current register value.
  218. */
  219. if (hw->mac.orig_link_settings_stored)
  220. autoc = hw->mac.orig_autoc;
  221. else
  222. autoc = IXGBE_READ_REG(hw, IXGBE_AUTOC);
  223. switch (autoc & IXGBE_AUTOC_LMS_MASK) {
  224. case IXGBE_AUTOC_LMS_1G_LINK_NO_AN:
  225. *speed = IXGBE_LINK_SPEED_1GB_FULL;
  226. *autoneg = false;
  227. break;
  228. case IXGBE_AUTOC_LMS_10G_LINK_NO_AN:
  229. *speed = IXGBE_LINK_SPEED_10GB_FULL;
  230. *autoneg = false;
  231. break;
  232. case IXGBE_AUTOC_LMS_1G_AN:
  233. *speed = IXGBE_LINK_SPEED_1GB_FULL;
  234. *autoneg = true;
  235. break;
  236. case IXGBE_AUTOC_LMS_KX4_AN:
  237. case IXGBE_AUTOC_LMS_KX4_AN_1G_AN:
  238. *speed = IXGBE_LINK_SPEED_UNKNOWN;
  239. if (autoc & IXGBE_AUTOC_KX4_SUPP)
  240. *speed |= IXGBE_LINK_SPEED_10GB_FULL;
  241. if (autoc & IXGBE_AUTOC_KX_SUPP)
  242. *speed |= IXGBE_LINK_SPEED_1GB_FULL;
  243. *autoneg = true;
  244. break;
  245. default:
  246. status = IXGBE_ERR_LINK_SETUP;
  247. break;
  248. }
  249. return status;
  250. }
  251. /**
  252. * ixgbe_get_media_type_82598 - Determines media type
  253. * @hw: pointer to hardware structure
  254. *
  255. * Returns the media type (fiber, copper, backplane)
  256. **/
  257. static enum ixgbe_media_type ixgbe_get_media_type_82598(struct ixgbe_hw *hw)
  258. {
  259. enum ixgbe_media_type media_type;
  260. /* Detect if there is a copper PHY attached. */
  261. switch (hw->phy.type) {
  262. case ixgbe_phy_cu_unknown:
  263. case ixgbe_phy_tn:
  264. case ixgbe_phy_aq:
  265. media_type = ixgbe_media_type_copper;
  266. goto out;
  267. default:
  268. break;
  269. }
  270. /* Media type for I82598 is based on device ID */
  271. switch (hw->device_id) {
  272. case IXGBE_DEV_ID_82598:
  273. case IXGBE_DEV_ID_82598_BX:
  274. /* Default device ID is mezzanine card KX/KX4 */
  275. media_type = ixgbe_media_type_backplane;
  276. break;
  277. case IXGBE_DEV_ID_82598AF_DUAL_PORT:
  278. case IXGBE_DEV_ID_82598AF_SINGLE_PORT:
  279. case IXGBE_DEV_ID_82598_DA_DUAL_PORT:
  280. case IXGBE_DEV_ID_82598_SR_DUAL_PORT_EM:
  281. case IXGBE_DEV_ID_82598EB_XF_LR:
  282. case IXGBE_DEV_ID_82598EB_SFP_LOM:
  283. media_type = ixgbe_media_type_fiber;
  284. break;
  285. case IXGBE_DEV_ID_82598EB_CX4:
  286. case IXGBE_DEV_ID_82598_CX4_DUAL_PORT:
  287. media_type = ixgbe_media_type_cx4;
  288. break;
  289. case IXGBE_DEV_ID_82598AT:
  290. case IXGBE_DEV_ID_82598AT2:
  291. media_type = ixgbe_media_type_copper;
  292. break;
  293. default:
  294. media_type = ixgbe_media_type_unknown;
  295. break;
  296. }
  297. out:
  298. return media_type;
  299. }
  300. /**
  301. * ixgbe_fc_enable_82598 - Enable flow control
  302. * @hw: pointer to hardware structure
  303. * @packetbuf_num: packet buffer number (0-7)
  304. *
  305. * Enable flow control according to the current settings.
  306. **/
  307. static s32 ixgbe_fc_enable_82598(struct ixgbe_hw *hw, s32 packetbuf_num)
  308. {
  309. s32 ret_val = 0;
  310. u32 fctrl_reg;
  311. u32 rmcs_reg;
  312. u32 reg;
  313. u32 rx_pba_size;
  314. u32 link_speed = 0;
  315. bool link_up;
  316. #ifdef CONFIG_DCB
  317. if (hw->fc.requested_mode == ixgbe_fc_pfc)
  318. goto out;
  319. #endif /* CONFIG_DCB */
  320. /*
  321. * On 82598 having Rx FC on causes resets while doing 1G
  322. * so if it's on turn it off once we know link_speed. For
  323. * more details see 82598 Specification update.
  324. */
  325. hw->mac.ops.check_link(hw, &link_speed, &link_up, false);
  326. if (link_up && link_speed == IXGBE_LINK_SPEED_1GB_FULL) {
  327. switch (hw->fc.requested_mode) {
  328. case ixgbe_fc_full:
  329. hw->fc.requested_mode = ixgbe_fc_tx_pause;
  330. break;
  331. case ixgbe_fc_rx_pause:
  332. hw->fc.requested_mode = ixgbe_fc_none;
  333. break;
  334. default:
  335. /* no change */
  336. break;
  337. }
  338. }
  339. /* Negotiate the fc mode to use */
  340. ret_val = ixgbe_fc_autoneg(hw);
  341. if (ret_val == IXGBE_ERR_FLOW_CONTROL)
  342. goto out;
  343. /* Disable any previous flow control settings */
  344. fctrl_reg = IXGBE_READ_REG(hw, IXGBE_FCTRL);
  345. fctrl_reg &= ~(IXGBE_FCTRL_RFCE | IXGBE_FCTRL_RPFCE);
  346. rmcs_reg = IXGBE_READ_REG(hw, IXGBE_RMCS);
  347. rmcs_reg &= ~(IXGBE_RMCS_TFCE_PRIORITY | IXGBE_RMCS_TFCE_802_3X);
  348. /*
  349. * The possible values of fc.current_mode are:
  350. * 0: Flow control is completely disabled
  351. * 1: Rx flow control is enabled (we can receive pause frames,
  352. * but not send pause frames).
  353. * 2: Tx flow control is enabled (we can send pause frames but
  354. * we do not support receiving pause frames).
  355. * 3: Both Rx and Tx flow control (symmetric) are enabled.
  356. #ifdef CONFIG_DCB
  357. * 4: Priority Flow Control is enabled.
  358. #endif
  359. * other: Invalid.
  360. */
  361. switch (hw->fc.current_mode) {
  362. case ixgbe_fc_none:
  363. /*
  364. * Flow control is disabled by software override or autoneg.
  365. * The code below will actually disable it in the HW.
  366. */
  367. break;
  368. case ixgbe_fc_rx_pause:
  369. /*
  370. * Rx Flow control is enabled and Tx Flow control is
  371. * disabled by software override. Since there really
  372. * isn't a way to advertise that we are capable of RX
  373. * Pause ONLY, we will advertise that we support both
  374. * symmetric and asymmetric Rx PAUSE. Later, we will
  375. * disable the adapter's ability to send PAUSE frames.
  376. */
  377. fctrl_reg |= IXGBE_FCTRL_RFCE;
  378. break;
  379. case ixgbe_fc_tx_pause:
  380. /*
  381. * Tx Flow control is enabled, and Rx Flow control is
  382. * disabled by software override.
  383. */
  384. rmcs_reg |= IXGBE_RMCS_TFCE_802_3X;
  385. break;
  386. case ixgbe_fc_full:
  387. /* Flow control (both Rx and Tx) is enabled by SW override. */
  388. fctrl_reg |= IXGBE_FCTRL_RFCE;
  389. rmcs_reg |= IXGBE_RMCS_TFCE_802_3X;
  390. break;
  391. #ifdef CONFIG_DCB
  392. case ixgbe_fc_pfc:
  393. goto out;
  394. break;
  395. #endif /* CONFIG_DCB */
  396. default:
  397. hw_dbg(hw, "Flow control param set incorrectly\n");
  398. ret_val = IXGBE_ERR_CONFIG;
  399. goto out;
  400. break;
  401. }
  402. /* Set 802.3x based flow control settings. */
  403. fctrl_reg |= IXGBE_FCTRL_DPF;
  404. IXGBE_WRITE_REG(hw, IXGBE_FCTRL, fctrl_reg);
  405. IXGBE_WRITE_REG(hw, IXGBE_RMCS, rmcs_reg);
  406. /* Set up and enable Rx high/low water mark thresholds, enable XON. */
  407. if (hw->fc.current_mode & ixgbe_fc_tx_pause) {
  408. rx_pba_size = IXGBE_READ_REG(hw, IXGBE_RXPBSIZE(packetbuf_num));
  409. rx_pba_size >>= IXGBE_RXPBSIZE_SHIFT;
  410. reg = (rx_pba_size - hw->fc.low_water) << 6;
  411. if (hw->fc.send_xon)
  412. reg |= IXGBE_FCRTL_XONE;
  413. IXGBE_WRITE_REG(hw, IXGBE_FCRTL(packetbuf_num), reg);
  414. reg = (rx_pba_size - hw->fc.high_water) << 6;
  415. reg |= IXGBE_FCRTH_FCEN;
  416. IXGBE_WRITE_REG(hw, IXGBE_FCRTH(packetbuf_num), reg);
  417. }
  418. /* Configure pause time (2 TCs per register) */
  419. reg = IXGBE_READ_REG(hw, IXGBE_FCTTV(packetbuf_num / 2));
  420. if ((packetbuf_num & 1) == 0)
  421. reg = (reg & 0xFFFF0000) | hw->fc.pause_time;
  422. else
  423. reg = (reg & 0x0000FFFF) | (hw->fc.pause_time << 16);
  424. IXGBE_WRITE_REG(hw, IXGBE_FCTTV(packetbuf_num / 2), reg);
  425. IXGBE_WRITE_REG(hw, IXGBE_FCRTV, (hw->fc.pause_time >> 1));
  426. out:
  427. return ret_val;
  428. }
  429. /**
  430. * ixgbe_start_mac_link_82598 - Configures MAC link settings
  431. * @hw: pointer to hardware structure
  432. *
  433. * Configures link settings based on values in the ixgbe_hw struct.
  434. * Restarts the link. Performs autonegotiation if needed.
  435. **/
  436. static s32 ixgbe_start_mac_link_82598(struct ixgbe_hw *hw,
  437. bool autoneg_wait_to_complete)
  438. {
  439. u32 autoc_reg;
  440. u32 links_reg;
  441. u32 i;
  442. s32 status = 0;
  443. /* Restart link */
  444. autoc_reg = IXGBE_READ_REG(hw, IXGBE_AUTOC);
  445. autoc_reg |= IXGBE_AUTOC_AN_RESTART;
  446. IXGBE_WRITE_REG(hw, IXGBE_AUTOC, autoc_reg);
  447. /* Only poll for autoneg to complete if specified to do so */
  448. if (autoneg_wait_to_complete) {
  449. if ((autoc_reg & IXGBE_AUTOC_LMS_MASK) ==
  450. IXGBE_AUTOC_LMS_KX4_AN ||
  451. (autoc_reg & IXGBE_AUTOC_LMS_MASK) ==
  452. IXGBE_AUTOC_LMS_KX4_AN_1G_AN) {
  453. links_reg = 0; /* Just in case Autoneg time = 0 */
  454. for (i = 0; i < IXGBE_AUTO_NEG_TIME; i++) {
  455. links_reg = IXGBE_READ_REG(hw, IXGBE_LINKS);
  456. if (links_reg & IXGBE_LINKS_KX_AN_COMP)
  457. break;
  458. msleep(100);
  459. }
  460. if (!(links_reg & IXGBE_LINKS_KX_AN_COMP)) {
  461. status = IXGBE_ERR_AUTONEG_NOT_COMPLETE;
  462. hw_dbg(hw, "Autonegotiation did not complete.\n");
  463. }
  464. }
  465. }
  466. /* Add delay to filter out noises during initial link setup */
  467. msleep(50);
  468. return status;
  469. }
  470. /**
  471. * ixgbe_validate_link_ready - Function looks for phy link
  472. * @hw: pointer to hardware structure
  473. *
  474. * Function indicates success when phy link is available. If phy is not ready
  475. * within 5 seconds of MAC indicating link, the function returns error.
  476. **/
  477. static s32 ixgbe_validate_link_ready(struct ixgbe_hw *hw)
  478. {
  479. u32 timeout;
  480. u16 an_reg;
  481. if (hw->device_id != IXGBE_DEV_ID_82598AT2)
  482. return 0;
  483. for (timeout = 0;
  484. timeout < IXGBE_VALIDATE_LINK_READY_TIMEOUT; timeout++) {
  485. hw->phy.ops.read_reg(hw, MDIO_STAT1, MDIO_MMD_AN, &an_reg);
  486. if ((an_reg & MDIO_AN_STAT1_COMPLETE) &&
  487. (an_reg & MDIO_STAT1_LSTATUS))
  488. break;
  489. msleep(100);
  490. }
  491. if (timeout == IXGBE_VALIDATE_LINK_READY_TIMEOUT) {
  492. hw_dbg(hw, "Link was indicated but link is down\n");
  493. return IXGBE_ERR_LINK_SETUP;
  494. }
  495. return 0;
  496. }
  497. /**
  498. * ixgbe_check_mac_link_82598 - Get link/speed status
  499. * @hw: pointer to hardware structure
  500. * @speed: pointer to link speed
  501. * @link_up: true is link is up, false otherwise
  502. * @link_up_wait_to_complete: bool used to wait for link up or not
  503. *
  504. * Reads the links register to determine if link is up and the current speed
  505. **/
  506. static s32 ixgbe_check_mac_link_82598(struct ixgbe_hw *hw,
  507. ixgbe_link_speed *speed, bool *link_up,
  508. bool link_up_wait_to_complete)
  509. {
  510. u32 links_reg;
  511. u32 i;
  512. u16 link_reg, adapt_comp_reg;
  513. /*
  514. * SERDES PHY requires us to read link status from register 0xC79F.
  515. * Bit 0 set indicates link is up/ready; clear indicates link down.
  516. * 0xC00C is read to check that the XAUI lanes are active. Bit 0
  517. * clear indicates active; set indicates inactive.
  518. */
  519. if (hw->phy.type == ixgbe_phy_nl) {
  520. hw->phy.ops.read_reg(hw, 0xC79F, MDIO_MMD_PMAPMD, &link_reg);
  521. hw->phy.ops.read_reg(hw, 0xC79F, MDIO_MMD_PMAPMD, &link_reg);
  522. hw->phy.ops.read_reg(hw, 0xC00C, MDIO_MMD_PMAPMD,
  523. &adapt_comp_reg);
  524. if (link_up_wait_to_complete) {
  525. for (i = 0; i < IXGBE_LINK_UP_TIME; i++) {
  526. if ((link_reg & 1) &&
  527. ((adapt_comp_reg & 1) == 0)) {
  528. *link_up = true;
  529. break;
  530. } else {
  531. *link_up = false;
  532. }
  533. msleep(100);
  534. hw->phy.ops.read_reg(hw, 0xC79F,
  535. MDIO_MMD_PMAPMD,
  536. &link_reg);
  537. hw->phy.ops.read_reg(hw, 0xC00C,
  538. MDIO_MMD_PMAPMD,
  539. &adapt_comp_reg);
  540. }
  541. } else {
  542. if ((link_reg & 1) && ((adapt_comp_reg & 1) == 0))
  543. *link_up = true;
  544. else
  545. *link_up = false;
  546. }
  547. if (*link_up == false)
  548. goto out;
  549. }
  550. links_reg = IXGBE_READ_REG(hw, IXGBE_LINKS);
  551. if (link_up_wait_to_complete) {
  552. for (i = 0; i < IXGBE_LINK_UP_TIME; i++) {
  553. if (links_reg & IXGBE_LINKS_UP) {
  554. *link_up = true;
  555. break;
  556. } else {
  557. *link_up = false;
  558. }
  559. msleep(100);
  560. links_reg = IXGBE_READ_REG(hw, IXGBE_LINKS);
  561. }
  562. } else {
  563. if (links_reg & IXGBE_LINKS_UP)
  564. *link_up = true;
  565. else
  566. *link_up = false;
  567. }
  568. if (links_reg & IXGBE_LINKS_SPEED)
  569. *speed = IXGBE_LINK_SPEED_10GB_FULL;
  570. else
  571. *speed = IXGBE_LINK_SPEED_1GB_FULL;
  572. if ((hw->device_id == IXGBE_DEV_ID_82598AT2) && (*link_up == true) &&
  573. (ixgbe_validate_link_ready(hw) != 0))
  574. *link_up = false;
  575. /* if link is down, zero out the current_mode */
  576. if (*link_up == false) {
  577. hw->fc.current_mode = ixgbe_fc_none;
  578. hw->fc.fc_was_autonegged = false;
  579. }
  580. out:
  581. return 0;
  582. }
  583. /**
  584. * ixgbe_setup_mac_link_82598 - Set MAC link speed
  585. * @hw: pointer to hardware structure
  586. * @speed: new link speed
  587. * @autoneg: true if auto-negotiation enabled
  588. * @autoneg_wait_to_complete: true when waiting for completion is needed
  589. *
  590. * Set the link speed in the AUTOC register and restarts link.
  591. **/
  592. static s32 ixgbe_setup_mac_link_82598(struct ixgbe_hw *hw,
  593. ixgbe_link_speed speed, bool autoneg,
  594. bool autoneg_wait_to_complete)
  595. {
  596. s32 status = 0;
  597. ixgbe_link_speed link_capabilities = IXGBE_LINK_SPEED_UNKNOWN;
  598. u32 curr_autoc = IXGBE_READ_REG(hw, IXGBE_AUTOC);
  599. u32 autoc = curr_autoc;
  600. u32 link_mode = autoc & IXGBE_AUTOC_LMS_MASK;
  601. /* Check to see if speed passed in is supported. */
  602. ixgbe_get_link_capabilities_82598(hw, &link_capabilities, &autoneg);
  603. speed &= link_capabilities;
  604. if (speed == IXGBE_LINK_SPEED_UNKNOWN)
  605. status = IXGBE_ERR_LINK_SETUP;
  606. /* Set KX4/KX support according to speed requested */
  607. else if (link_mode == IXGBE_AUTOC_LMS_KX4_AN ||
  608. link_mode == IXGBE_AUTOC_LMS_KX4_AN_1G_AN) {
  609. autoc &= ~IXGBE_AUTOC_KX4_KX_SUPP_MASK;
  610. if (speed & IXGBE_LINK_SPEED_10GB_FULL)
  611. autoc |= IXGBE_AUTOC_KX4_SUPP;
  612. if (speed & IXGBE_LINK_SPEED_1GB_FULL)
  613. autoc |= IXGBE_AUTOC_KX_SUPP;
  614. if (autoc != curr_autoc)
  615. IXGBE_WRITE_REG(hw, IXGBE_AUTOC, autoc);
  616. }
  617. if (status == 0) {
  618. /*
  619. * Setup and restart the link based on the new values in
  620. * ixgbe_hw This will write the AUTOC register based on the new
  621. * stored values
  622. */
  623. status = ixgbe_start_mac_link_82598(hw,
  624. autoneg_wait_to_complete);
  625. }
  626. return status;
  627. }
  628. /**
  629. * ixgbe_setup_copper_link_82598 - Set the PHY autoneg advertised field
  630. * @hw: pointer to hardware structure
  631. * @speed: new link speed
  632. * @autoneg: true if autonegotiation enabled
  633. * @autoneg_wait_to_complete: true if waiting is needed to complete
  634. *
  635. * Sets the link speed in the AUTOC register in the MAC and restarts link.
  636. **/
  637. static s32 ixgbe_setup_copper_link_82598(struct ixgbe_hw *hw,
  638. ixgbe_link_speed speed,
  639. bool autoneg,
  640. bool autoneg_wait_to_complete)
  641. {
  642. s32 status;
  643. /* Setup the PHY according to input speed */
  644. status = hw->phy.ops.setup_link_speed(hw, speed, autoneg,
  645. autoneg_wait_to_complete);
  646. /* Set up MAC */
  647. ixgbe_start_mac_link_82598(hw, autoneg_wait_to_complete);
  648. return status;
  649. }
  650. /**
  651. * ixgbe_reset_hw_82598 - Performs hardware reset
  652. * @hw: pointer to hardware structure
  653. *
  654. * Resets the hardware by resetting the transmit and receive units, masks and
  655. * clears all interrupts, performing a PHY reset, and performing a link (MAC)
  656. * reset.
  657. **/
  658. static s32 ixgbe_reset_hw_82598(struct ixgbe_hw *hw)
  659. {
  660. s32 status = 0;
  661. s32 phy_status = 0;
  662. u32 ctrl;
  663. u32 gheccr;
  664. u32 i;
  665. u32 autoc;
  666. u8 analog_val;
  667. /* Call adapter stop to disable tx/rx and clear interrupts */
  668. hw->mac.ops.stop_adapter(hw);
  669. /*
  670. * Power up the Atlas Tx lanes if they are currently powered down.
  671. * Atlas Tx lanes are powered down for MAC loopback tests, but
  672. * they are not automatically restored on reset.
  673. */
  674. hw->mac.ops.read_analog_reg8(hw, IXGBE_ATLAS_PDN_LPBK, &analog_val);
  675. if (analog_val & IXGBE_ATLAS_PDN_TX_REG_EN) {
  676. /* Enable Tx Atlas so packets can be transmitted again */
  677. hw->mac.ops.read_analog_reg8(hw, IXGBE_ATLAS_PDN_LPBK,
  678. &analog_val);
  679. analog_val &= ~IXGBE_ATLAS_PDN_TX_REG_EN;
  680. hw->mac.ops.write_analog_reg8(hw, IXGBE_ATLAS_PDN_LPBK,
  681. analog_val);
  682. hw->mac.ops.read_analog_reg8(hw, IXGBE_ATLAS_PDN_10G,
  683. &analog_val);
  684. analog_val &= ~IXGBE_ATLAS_PDN_TX_10G_QL_ALL;
  685. hw->mac.ops.write_analog_reg8(hw, IXGBE_ATLAS_PDN_10G,
  686. analog_val);
  687. hw->mac.ops.read_analog_reg8(hw, IXGBE_ATLAS_PDN_1G,
  688. &analog_val);
  689. analog_val &= ~IXGBE_ATLAS_PDN_TX_1G_QL_ALL;
  690. hw->mac.ops.write_analog_reg8(hw, IXGBE_ATLAS_PDN_1G,
  691. analog_val);
  692. hw->mac.ops.read_analog_reg8(hw, IXGBE_ATLAS_PDN_AN,
  693. &analog_val);
  694. analog_val &= ~IXGBE_ATLAS_PDN_TX_AN_QL_ALL;
  695. hw->mac.ops.write_analog_reg8(hw, IXGBE_ATLAS_PDN_AN,
  696. analog_val);
  697. }
  698. /* Reset PHY */
  699. if (hw->phy.reset_disable == false) {
  700. /* PHY ops must be identified and initialized prior to reset */
  701. /* Init PHY and function pointers, perform SFP setup */
  702. phy_status = hw->phy.ops.init(hw);
  703. if (phy_status == IXGBE_ERR_SFP_NOT_SUPPORTED)
  704. goto reset_hw_out;
  705. else if (phy_status == IXGBE_ERR_SFP_NOT_PRESENT)
  706. goto no_phy_reset;
  707. hw->phy.ops.reset(hw);
  708. }
  709. no_phy_reset:
  710. /*
  711. * Prevent the PCI-E bus from from hanging by disabling PCI-E master
  712. * access and verify no pending requests before reset
  713. */
  714. ixgbe_disable_pcie_master(hw);
  715. mac_reset_top:
  716. /*
  717. * Issue global reset to the MAC. This needs to be a SW reset.
  718. * If link reset is used, it might reset the MAC when mng is using it
  719. */
  720. ctrl = IXGBE_READ_REG(hw, IXGBE_CTRL);
  721. IXGBE_WRITE_REG(hw, IXGBE_CTRL, (ctrl | IXGBE_CTRL_RST));
  722. IXGBE_WRITE_FLUSH(hw);
  723. /* Poll for reset bit to self-clear indicating reset is complete */
  724. for (i = 0; i < 10; i++) {
  725. udelay(1);
  726. ctrl = IXGBE_READ_REG(hw, IXGBE_CTRL);
  727. if (!(ctrl & IXGBE_CTRL_RST))
  728. break;
  729. }
  730. if (ctrl & IXGBE_CTRL_RST) {
  731. status = IXGBE_ERR_RESET_FAILED;
  732. hw_dbg(hw, "Reset polling failed to complete.\n");
  733. }
  734. /*
  735. * Double resets are required for recovery from certain error
  736. * conditions. Between resets, it is necessary to stall to allow time
  737. * for any pending HW events to complete. We use 1usec since that is
  738. * what is needed for ixgbe_disable_pcie_master(). The second reset
  739. * then clears out any effects of those events.
  740. */
  741. if (hw->mac.flags & IXGBE_FLAGS_DOUBLE_RESET_REQUIRED) {
  742. hw->mac.flags &= ~IXGBE_FLAGS_DOUBLE_RESET_REQUIRED;
  743. udelay(1);
  744. goto mac_reset_top;
  745. }
  746. msleep(50);
  747. gheccr = IXGBE_READ_REG(hw, IXGBE_GHECCR);
  748. gheccr &= ~((1 << 21) | (1 << 18) | (1 << 9) | (1 << 6));
  749. IXGBE_WRITE_REG(hw, IXGBE_GHECCR, gheccr);
  750. /*
  751. * Store the original AUTOC value if it has not been
  752. * stored off yet. Otherwise restore the stored original
  753. * AUTOC value since the reset operation sets back to deaults.
  754. */
  755. autoc = IXGBE_READ_REG(hw, IXGBE_AUTOC);
  756. if (hw->mac.orig_link_settings_stored == false) {
  757. hw->mac.orig_autoc = autoc;
  758. hw->mac.orig_link_settings_stored = true;
  759. } else if (autoc != hw->mac.orig_autoc) {
  760. IXGBE_WRITE_REG(hw, IXGBE_AUTOC, hw->mac.orig_autoc);
  761. }
  762. /* Store the permanent mac address */
  763. hw->mac.ops.get_mac_addr(hw, hw->mac.perm_addr);
  764. /*
  765. * Store MAC address from RAR0, clear receive address registers, and
  766. * clear the multicast table
  767. */
  768. hw->mac.ops.init_rx_addrs(hw);
  769. reset_hw_out:
  770. if (phy_status)
  771. status = phy_status;
  772. return status;
  773. }
  774. /**
  775. * ixgbe_set_vmdq_82598 - Associate a VMDq set index with a rx address
  776. * @hw: pointer to hardware struct
  777. * @rar: receive address register index to associate with a VMDq index
  778. * @vmdq: VMDq set index
  779. **/
  780. static s32 ixgbe_set_vmdq_82598(struct ixgbe_hw *hw, u32 rar, u32 vmdq)
  781. {
  782. u32 rar_high;
  783. u32 rar_entries = hw->mac.num_rar_entries;
  784. /* Make sure we are using a valid rar index range */
  785. if (rar >= rar_entries) {
  786. hw_dbg(hw, "RAR index %d is out of range.\n", rar);
  787. return IXGBE_ERR_INVALID_ARGUMENT;
  788. }
  789. rar_high = IXGBE_READ_REG(hw, IXGBE_RAH(rar));
  790. rar_high &= ~IXGBE_RAH_VIND_MASK;
  791. rar_high |= ((vmdq << IXGBE_RAH_VIND_SHIFT) & IXGBE_RAH_VIND_MASK);
  792. IXGBE_WRITE_REG(hw, IXGBE_RAH(rar), rar_high);
  793. return 0;
  794. }
  795. /**
  796. * ixgbe_clear_vmdq_82598 - Disassociate a VMDq set index from an rx address
  797. * @hw: pointer to hardware struct
  798. * @rar: receive address register index to associate with a VMDq index
  799. * @vmdq: VMDq clear index (not used in 82598, but elsewhere)
  800. **/
  801. static s32 ixgbe_clear_vmdq_82598(struct ixgbe_hw *hw, u32 rar, u32 vmdq)
  802. {
  803. u32 rar_high;
  804. u32 rar_entries = hw->mac.num_rar_entries;
  805. /* Make sure we are using a valid rar index range */
  806. if (rar >= rar_entries) {
  807. hw_dbg(hw, "RAR index %d is out of range.\n", rar);
  808. return IXGBE_ERR_INVALID_ARGUMENT;
  809. }
  810. rar_high = IXGBE_READ_REG(hw, IXGBE_RAH(rar));
  811. if (rar_high & IXGBE_RAH_VIND_MASK) {
  812. rar_high &= ~IXGBE_RAH_VIND_MASK;
  813. IXGBE_WRITE_REG(hw, IXGBE_RAH(rar), rar_high);
  814. }
  815. return 0;
  816. }
  817. /**
  818. * ixgbe_set_vfta_82598 - Set VLAN filter table
  819. * @hw: pointer to hardware structure
  820. * @vlan: VLAN id to write to VLAN filter
  821. * @vind: VMDq output index that maps queue to VLAN id in VFTA
  822. * @vlan_on: boolean flag to turn on/off VLAN in VFTA
  823. *
  824. * Turn on/off specified VLAN in the VLAN filter table.
  825. **/
  826. static s32 ixgbe_set_vfta_82598(struct ixgbe_hw *hw, u32 vlan, u32 vind,
  827. bool vlan_on)
  828. {
  829. u32 regindex;
  830. u32 bitindex;
  831. u32 bits;
  832. u32 vftabyte;
  833. if (vlan > 4095)
  834. return IXGBE_ERR_PARAM;
  835. /* Determine 32-bit word position in array */
  836. regindex = (vlan >> 5) & 0x7F; /* upper seven bits */
  837. /* Determine the location of the (VMD) queue index */
  838. vftabyte = ((vlan >> 3) & 0x03); /* bits (4:3) indicating byte array */
  839. bitindex = (vlan & 0x7) << 2; /* lower 3 bits indicate nibble */
  840. /* Set the nibble for VMD queue index */
  841. bits = IXGBE_READ_REG(hw, IXGBE_VFTAVIND(vftabyte, regindex));
  842. bits &= (~(0x0F << bitindex));
  843. bits |= (vind << bitindex);
  844. IXGBE_WRITE_REG(hw, IXGBE_VFTAVIND(vftabyte, regindex), bits);
  845. /* Determine the location of the bit for this VLAN id */
  846. bitindex = vlan & 0x1F; /* lower five bits */
  847. bits = IXGBE_READ_REG(hw, IXGBE_VFTA(regindex));
  848. if (vlan_on)
  849. /* Turn on this VLAN id */
  850. bits |= (1 << bitindex);
  851. else
  852. /* Turn off this VLAN id */
  853. bits &= ~(1 << bitindex);
  854. IXGBE_WRITE_REG(hw, IXGBE_VFTA(regindex), bits);
  855. return 0;
  856. }
  857. /**
  858. * ixgbe_clear_vfta_82598 - Clear VLAN filter table
  859. * @hw: pointer to hardware structure
  860. *
  861. * Clears the VLAN filer table, and the VMDq index associated with the filter
  862. **/
  863. static s32 ixgbe_clear_vfta_82598(struct ixgbe_hw *hw)
  864. {
  865. u32 offset;
  866. u32 vlanbyte;
  867. for (offset = 0; offset < hw->mac.vft_size; offset++)
  868. IXGBE_WRITE_REG(hw, IXGBE_VFTA(offset), 0);
  869. for (vlanbyte = 0; vlanbyte < 4; vlanbyte++)
  870. for (offset = 0; offset < hw->mac.vft_size; offset++)
  871. IXGBE_WRITE_REG(hw, IXGBE_VFTAVIND(vlanbyte, offset),
  872. 0);
  873. return 0;
  874. }
  875. /**
  876. * ixgbe_read_analog_reg8_82598 - Reads 8 bit Atlas analog register
  877. * @hw: pointer to hardware structure
  878. * @reg: analog register to read
  879. * @val: read value
  880. *
  881. * Performs read operation to Atlas analog register specified.
  882. **/
  883. static s32 ixgbe_read_analog_reg8_82598(struct ixgbe_hw *hw, u32 reg, u8 *val)
  884. {
  885. u32 atlas_ctl;
  886. IXGBE_WRITE_REG(hw, IXGBE_ATLASCTL,
  887. IXGBE_ATLASCTL_WRITE_CMD | (reg << 8));
  888. IXGBE_WRITE_FLUSH(hw);
  889. udelay(10);
  890. atlas_ctl = IXGBE_READ_REG(hw, IXGBE_ATLASCTL);
  891. *val = (u8)atlas_ctl;
  892. return 0;
  893. }
  894. /**
  895. * ixgbe_write_analog_reg8_82598 - Writes 8 bit Atlas analog register
  896. * @hw: pointer to hardware structure
  897. * @reg: atlas register to write
  898. * @val: value to write
  899. *
  900. * Performs write operation to Atlas analog register specified.
  901. **/
  902. static s32 ixgbe_write_analog_reg8_82598(struct ixgbe_hw *hw, u32 reg, u8 val)
  903. {
  904. u32 atlas_ctl;
  905. atlas_ctl = (reg << 8) | val;
  906. IXGBE_WRITE_REG(hw, IXGBE_ATLASCTL, atlas_ctl);
  907. IXGBE_WRITE_FLUSH(hw);
  908. udelay(10);
  909. return 0;
  910. }
  911. /**
  912. * ixgbe_read_i2c_eeprom_82598 - Reads 8 bit word over I2C interface.
  913. * @hw: pointer to hardware structure
  914. * @byte_offset: EEPROM byte offset to read
  915. * @eeprom_data: value read
  916. *
  917. * Performs 8 byte read operation to SFP module's EEPROM over I2C interface.
  918. **/
  919. static s32 ixgbe_read_i2c_eeprom_82598(struct ixgbe_hw *hw, u8 byte_offset,
  920. u8 *eeprom_data)
  921. {
  922. s32 status = 0;
  923. u16 sfp_addr = 0;
  924. u16 sfp_data = 0;
  925. u16 sfp_stat = 0;
  926. u32 i;
  927. if (hw->phy.type == ixgbe_phy_nl) {
  928. /*
  929. * phy SDA/SCL registers are at addresses 0xC30A to
  930. * 0xC30D. These registers are used to talk to the SFP+
  931. * module's EEPROM through the SDA/SCL (I2C) interface.
  932. */
  933. sfp_addr = (IXGBE_I2C_EEPROM_DEV_ADDR << 8) + byte_offset;
  934. sfp_addr = (sfp_addr | IXGBE_I2C_EEPROM_READ_MASK);
  935. hw->phy.ops.write_reg(hw,
  936. IXGBE_MDIO_PMA_PMD_SDA_SCL_ADDR,
  937. MDIO_MMD_PMAPMD,
  938. sfp_addr);
  939. /* Poll status */
  940. for (i = 0; i < 100; i++) {
  941. hw->phy.ops.read_reg(hw,
  942. IXGBE_MDIO_PMA_PMD_SDA_SCL_STAT,
  943. MDIO_MMD_PMAPMD,
  944. &sfp_stat);
  945. sfp_stat = sfp_stat & IXGBE_I2C_EEPROM_STATUS_MASK;
  946. if (sfp_stat != IXGBE_I2C_EEPROM_STATUS_IN_PROGRESS)
  947. break;
  948. usleep_range(10000, 20000);
  949. }
  950. if (sfp_stat != IXGBE_I2C_EEPROM_STATUS_PASS) {
  951. hw_dbg(hw, "EEPROM read did not pass.\n");
  952. status = IXGBE_ERR_SFP_NOT_PRESENT;
  953. goto out;
  954. }
  955. /* Read data */
  956. hw->phy.ops.read_reg(hw, IXGBE_MDIO_PMA_PMD_SDA_SCL_DATA,
  957. MDIO_MMD_PMAPMD, &sfp_data);
  958. *eeprom_data = (u8)(sfp_data >> 8);
  959. } else {
  960. status = IXGBE_ERR_PHY;
  961. goto out;
  962. }
  963. out:
  964. return status;
  965. }
  966. /**
  967. * ixgbe_get_supported_physical_layer_82598 - Returns physical layer type
  968. * @hw: pointer to hardware structure
  969. *
  970. * Determines physical layer capabilities of the current configuration.
  971. **/
  972. static u32 ixgbe_get_supported_physical_layer_82598(struct ixgbe_hw *hw)
  973. {
  974. u32 physical_layer = IXGBE_PHYSICAL_LAYER_UNKNOWN;
  975. u32 autoc = IXGBE_READ_REG(hw, IXGBE_AUTOC);
  976. u32 pma_pmd_10g = autoc & IXGBE_AUTOC_10G_PMA_PMD_MASK;
  977. u32 pma_pmd_1g = autoc & IXGBE_AUTOC_1G_PMA_PMD_MASK;
  978. u16 ext_ability = 0;
  979. hw->phy.ops.identify(hw);
  980. /* Copper PHY must be checked before AUTOC LMS to determine correct
  981. * physical layer because 10GBase-T PHYs use LMS = KX4/KX */
  982. switch (hw->phy.type) {
  983. case ixgbe_phy_tn:
  984. case ixgbe_phy_aq:
  985. case ixgbe_phy_cu_unknown:
  986. hw->phy.ops.read_reg(hw, MDIO_PMA_EXTABLE,
  987. MDIO_MMD_PMAPMD, &ext_ability);
  988. if (ext_ability & MDIO_PMA_EXTABLE_10GBT)
  989. physical_layer |= IXGBE_PHYSICAL_LAYER_10GBASE_T;
  990. if (ext_ability & MDIO_PMA_EXTABLE_1000BT)
  991. physical_layer |= IXGBE_PHYSICAL_LAYER_1000BASE_T;
  992. if (ext_ability & MDIO_PMA_EXTABLE_100BTX)
  993. physical_layer |= IXGBE_PHYSICAL_LAYER_100BASE_TX;
  994. goto out;
  995. default:
  996. break;
  997. }
  998. switch (autoc & IXGBE_AUTOC_LMS_MASK) {
  999. case IXGBE_AUTOC_LMS_1G_AN:
  1000. case IXGBE_AUTOC_LMS_1G_LINK_NO_AN:
  1001. if (pma_pmd_1g == IXGBE_AUTOC_1G_KX)
  1002. physical_layer = IXGBE_PHYSICAL_LAYER_1000BASE_KX;
  1003. else
  1004. physical_layer = IXGBE_PHYSICAL_LAYER_1000BASE_BX;
  1005. break;
  1006. case IXGBE_AUTOC_LMS_10G_LINK_NO_AN:
  1007. if (pma_pmd_10g == IXGBE_AUTOC_10G_CX4)
  1008. physical_layer = IXGBE_PHYSICAL_LAYER_10GBASE_CX4;
  1009. else if (pma_pmd_10g == IXGBE_AUTOC_10G_KX4)
  1010. physical_layer = IXGBE_PHYSICAL_LAYER_10GBASE_KX4;
  1011. else /* XAUI */
  1012. physical_layer = IXGBE_PHYSICAL_LAYER_UNKNOWN;
  1013. break;
  1014. case IXGBE_AUTOC_LMS_KX4_AN:
  1015. case IXGBE_AUTOC_LMS_KX4_AN_1G_AN:
  1016. if (autoc & IXGBE_AUTOC_KX_SUPP)
  1017. physical_layer |= IXGBE_PHYSICAL_LAYER_1000BASE_KX;
  1018. if (autoc & IXGBE_AUTOC_KX4_SUPP)
  1019. physical_layer |= IXGBE_PHYSICAL_LAYER_10GBASE_KX4;
  1020. break;
  1021. default:
  1022. break;
  1023. }
  1024. if (hw->phy.type == ixgbe_phy_nl) {
  1025. hw->phy.ops.identify_sfp(hw);
  1026. switch (hw->phy.sfp_type) {
  1027. case ixgbe_sfp_type_da_cu:
  1028. physical_layer = IXGBE_PHYSICAL_LAYER_SFP_PLUS_CU;
  1029. break;
  1030. case ixgbe_sfp_type_sr:
  1031. physical_layer = IXGBE_PHYSICAL_LAYER_10GBASE_SR;
  1032. break;
  1033. case ixgbe_sfp_type_lr:
  1034. physical_layer = IXGBE_PHYSICAL_LAYER_10GBASE_LR;
  1035. break;
  1036. default:
  1037. physical_layer = IXGBE_PHYSICAL_LAYER_UNKNOWN;
  1038. break;
  1039. }
  1040. }
  1041. switch (hw->device_id) {
  1042. case IXGBE_DEV_ID_82598_DA_DUAL_PORT:
  1043. physical_layer = IXGBE_PHYSICAL_LAYER_SFP_PLUS_CU;
  1044. break;
  1045. case IXGBE_DEV_ID_82598AF_DUAL_PORT:
  1046. case IXGBE_DEV_ID_82598AF_SINGLE_PORT:
  1047. case IXGBE_DEV_ID_82598_SR_DUAL_PORT_EM:
  1048. physical_layer = IXGBE_PHYSICAL_LAYER_10GBASE_SR;
  1049. break;
  1050. case IXGBE_DEV_ID_82598EB_XF_LR:
  1051. physical_layer = IXGBE_PHYSICAL_LAYER_10GBASE_LR;
  1052. break;
  1053. default:
  1054. break;
  1055. }
  1056. out:
  1057. return physical_layer;
  1058. }
  1059. /**
  1060. * ixgbe_set_lan_id_multi_port_pcie_82598 - Set LAN id for PCIe multiple
  1061. * port devices.
  1062. * @hw: pointer to the HW structure
  1063. *
  1064. * Calls common function and corrects issue with some single port devices
  1065. * that enable LAN1 but not LAN0.
  1066. **/
  1067. static void ixgbe_set_lan_id_multi_port_pcie_82598(struct ixgbe_hw *hw)
  1068. {
  1069. struct ixgbe_bus_info *bus = &hw->bus;
  1070. u16 pci_gen = 0;
  1071. u16 pci_ctrl2 = 0;
  1072. ixgbe_set_lan_id_multi_port_pcie(hw);
  1073. /* check if LAN0 is disabled */
  1074. hw->eeprom.ops.read(hw, IXGBE_PCIE_GENERAL_PTR, &pci_gen);
  1075. if ((pci_gen != 0) && (pci_gen != 0xFFFF)) {
  1076. hw->eeprom.ops.read(hw, pci_gen + IXGBE_PCIE_CTRL2, &pci_ctrl2);
  1077. /* if LAN0 is completely disabled force function to 0 */
  1078. if ((pci_ctrl2 & IXGBE_PCIE_CTRL2_LAN_DISABLE) &&
  1079. !(pci_ctrl2 & IXGBE_PCIE_CTRL2_DISABLE_SELECT) &&
  1080. !(pci_ctrl2 & IXGBE_PCIE_CTRL2_DUMMY_ENABLE)) {
  1081. bus->func = 0;
  1082. }
  1083. }
  1084. }
  1085. static struct ixgbe_mac_operations mac_ops_82598 = {
  1086. .init_hw = &ixgbe_init_hw_generic,
  1087. .reset_hw = &ixgbe_reset_hw_82598,
  1088. .start_hw = &ixgbe_start_hw_82598,
  1089. .clear_hw_cntrs = &ixgbe_clear_hw_cntrs_generic,
  1090. .get_media_type = &ixgbe_get_media_type_82598,
  1091. .get_supported_physical_layer = &ixgbe_get_supported_physical_layer_82598,
  1092. .enable_rx_dma = &ixgbe_enable_rx_dma_generic,
  1093. .get_mac_addr = &ixgbe_get_mac_addr_generic,
  1094. .stop_adapter = &ixgbe_stop_adapter_generic,
  1095. .get_bus_info = &ixgbe_get_bus_info_generic,
  1096. .set_lan_id = &ixgbe_set_lan_id_multi_port_pcie_82598,
  1097. .read_analog_reg8 = &ixgbe_read_analog_reg8_82598,
  1098. .write_analog_reg8 = &ixgbe_write_analog_reg8_82598,
  1099. .setup_link = &ixgbe_setup_mac_link_82598,
  1100. .check_link = &ixgbe_check_mac_link_82598,
  1101. .get_link_capabilities = &ixgbe_get_link_capabilities_82598,
  1102. .led_on = &ixgbe_led_on_generic,
  1103. .led_off = &ixgbe_led_off_generic,
  1104. .blink_led_start = &ixgbe_blink_led_start_generic,
  1105. .blink_led_stop = &ixgbe_blink_led_stop_generic,
  1106. .set_rar = &ixgbe_set_rar_generic,
  1107. .clear_rar = &ixgbe_clear_rar_generic,
  1108. .set_vmdq = &ixgbe_set_vmdq_82598,
  1109. .clear_vmdq = &ixgbe_clear_vmdq_82598,
  1110. .init_rx_addrs = &ixgbe_init_rx_addrs_generic,
  1111. .update_mc_addr_list = &ixgbe_update_mc_addr_list_generic,
  1112. .enable_mc = &ixgbe_enable_mc_generic,
  1113. .disable_mc = &ixgbe_disable_mc_generic,
  1114. .clear_vfta = &ixgbe_clear_vfta_82598,
  1115. .set_vfta = &ixgbe_set_vfta_82598,
  1116. .fc_enable = &ixgbe_fc_enable_82598,
  1117. .acquire_swfw_sync = &ixgbe_acquire_swfw_sync,
  1118. .release_swfw_sync = &ixgbe_release_swfw_sync,
  1119. };
  1120. static struct ixgbe_eeprom_operations eeprom_ops_82598 = {
  1121. .init_params = &ixgbe_init_eeprom_params_generic,
  1122. .read = &ixgbe_read_eerd_generic,
  1123. .read_buffer = &ixgbe_read_eerd_buffer_generic,
  1124. .calc_checksum = &ixgbe_calc_eeprom_checksum_generic,
  1125. .validate_checksum = &ixgbe_validate_eeprom_checksum_generic,
  1126. .update_checksum = &ixgbe_update_eeprom_checksum_generic,
  1127. };
  1128. static struct ixgbe_phy_operations phy_ops_82598 = {
  1129. .identify = &ixgbe_identify_phy_generic,
  1130. .identify_sfp = &ixgbe_identify_sfp_module_generic,
  1131. .init = &ixgbe_init_phy_ops_82598,
  1132. .reset = &ixgbe_reset_phy_generic,
  1133. .read_reg = &ixgbe_read_phy_reg_generic,
  1134. .write_reg = &ixgbe_write_phy_reg_generic,
  1135. .setup_link = &ixgbe_setup_phy_link_generic,
  1136. .setup_link_speed = &ixgbe_setup_phy_link_speed_generic,
  1137. .read_i2c_eeprom = &ixgbe_read_i2c_eeprom_82598,
  1138. .check_overtemp = &ixgbe_tn_check_overtemp,
  1139. };
  1140. struct ixgbe_info ixgbe_82598_info = {
  1141. .mac = ixgbe_mac_82598EB,
  1142. .get_invariants = &ixgbe_get_invariants_82598,
  1143. .mac_ops = &mac_ops_82598,
  1144. .eeprom_ops = &eeprom_ops_82598,
  1145. .phy_ops = &phy_ops_82598,
  1146. };