ixgbe_82598.c 36 KB

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