ixgbe_82598.c 39 KB

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