ixgbe_82599.c 68 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269
  1. /*******************************************************************************
  2. Intel 10 Gigabit PCI Express Linux driver
  3. Copyright(c) 1999 - 2015 Intel Corporation.
  4. This program is free software; you can redistribute it and/or modify it
  5. under the terms and conditions of the GNU General Public License,
  6. version 2, as published by the Free Software Foundation.
  7. This program is distributed in the hope it will be useful, but WITHOUT
  8. ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  9. FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
  10. more details.
  11. You should have received a copy of the GNU General Public License along with
  12. this program; if not, write to the Free Software Foundation, Inc.,
  13. 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
  14. The full GNU General Public License is included in this distribution in
  15. the file called "COPYING".
  16. Contact Information:
  17. Linux NICS <linux.nics@intel.com>
  18. e1000-devel Mailing List <e1000-devel@lists.sourceforge.net>
  19. Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
  20. *******************************************************************************/
  21. #include <linux/pci.h>
  22. #include <linux/delay.h>
  23. #include <linux/sched.h>
  24. #include "ixgbe.h"
  25. #include "ixgbe_phy.h"
  26. #include "ixgbe_mbx.h"
  27. #define IXGBE_82599_MAX_TX_QUEUES 128
  28. #define IXGBE_82599_MAX_RX_QUEUES 128
  29. #define IXGBE_82599_RAR_ENTRIES 128
  30. #define IXGBE_82599_MC_TBL_SIZE 128
  31. #define IXGBE_82599_VFT_TBL_SIZE 128
  32. #define IXGBE_82599_RX_PB_SIZE 512
  33. static void ixgbe_disable_tx_laser_multispeed_fiber(struct ixgbe_hw *hw);
  34. static void ixgbe_enable_tx_laser_multispeed_fiber(struct ixgbe_hw *hw);
  35. static void ixgbe_flap_tx_laser_multispeed_fiber(struct ixgbe_hw *hw);
  36. static void
  37. ixgbe_set_hard_rate_select_speed(struct ixgbe_hw *, ixgbe_link_speed);
  38. static s32 ixgbe_setup_mac_link_smartspeed(struct ixgbe_hw *hw,
  39. ixgbe_link_speed speed,
  40. bool autoneg_wait_to_complete);
  41. static void ixgbe_stop_mac_link_on_d3_82599(struct ixgbe_hw *hw);
  42. static s32 ixgbe_start_mac_link_82599(struct ixgbe_hw *hw,
  43. bool autoneg_wait_to_complete);
  44. static s32 ixgbe_setup_mac_link_82599(struct ixgbe_hw *hw,
  45. ixgbe_link_speed speed,
  46. bool autoneg_wait_to_complete);
  47. static s32 ixgbe_setup_copper_link_82599(struct ixgbe_hw *hw,
  48. ixgbe_link_speed speed,
  49. bool autoneg_wait_to_complete);
  50. static s32 ixgbe_verify_fw_version_82599(struct ixgbe_hw *hw);
  51. static s32 ixgbe_read_i2c_byte_82599(struct ixgbe_hw *hw, u8 byte_offset,
  52. u8 dev_addr, u8 *data);
  53. static s32 ixgbe_write_i2c_byte_82599(struct ixgbe_hw *hw, u8 byte_offset,
  54. u8 dev_addr, u8 data);
  55. static s32 ixgbe_reset_pipeline_82599(struct ixgbe_hw *hw);
  56. static bool ixgbe_verify_lesm_fw_enabled_82599(struct ixgbe_hw *hw);
  57. bool ixgbe_mng_enabled(struct ixgbe_hw *hw)
  58. {
  59. u32 fwsm, manc, factps;
  60. fwsm = IXGBE_READ_REG(hw, IXGBE_FWSM(hw));
  61. if ((fwsm & IXGBE_FWSM_MODE_MASK) != IXGBE_FWSM_FW_MODE_PT)
  62. return false;
  63. manc = IXGBE_READ_REG(hw, IXGBE_MANC);
  64. if (!(manc & IXGBE_MANC_RCV_TCO_EN))
  65. return false;
  66. factps = IXGBE_READ_REG(hw, IXGBE_FACTPS(hw));
  67. if (factps & IXGBE_FACTPS_MNGCG)
  68. return false;
  69. return true;
  70. }
  71. static void ixgbe_init_mac_link_ops_82599(struct ixgbe_hw *hw)
  72. {
  73. struct ixgbe_mac_info *mac = &hw->mac;
  74. /* enable the laser control functions for SFP+ fiber
  75. * and MNG not enabled
  76. */
  77. if ((mac->ops.get_media_type(hw) == ixgbe_media_type_fiber) &&
  78. !ixgbe_mng_enabled(hw)) {
  79. mac->ops.disable_tx_laser =
  80. &ixgbe_disable_tx_laser_multispeed_fiber;
  81. mac->ops.enable_tx_laser =
  82. &ixgbe_enable_tx_laser_multispeed_fiber;
  83. mac->ops.flap_tx_laser = &ixgbe_flap_tx_laser_multispeed_fiber;
  84. } else {
  85. mac->ops.disable_tx_laser = NULL;
  86. mac->ops.enable_tx_laser = NULL;
  87. mac->ops.flap_tx_laser = NULL;
  88. }
  89. if (hw->phy.multispeed_fiber) {
  90. /* Set up dual speed SFP+ support */
  91. mac->ops.setup_link = &ixgbe_setup_mac_link_multispeed_fiber;
  92. mac->ops.setup_mac_link = ixgbe_setup_mac_link_82599;
  93. mac->ops.set_rate_select_speed =
  94. ixgbe_set_hard_rate_select_speed;
  95. } else {
  96. if ((mac->ops.get_media_type(hw) ==
  97. ixgbe_media_type_backplane) &&
  98. (hw->phy.smart_speed == ixgbe_smart_speed_auto ||
  99. hw->phy.smart_speed == ixgbe_smart_speed_on) &&
  100. !ixgbe_verify_lesm_fw_enabled_82599(hw))
  101. mac->ops.setup_link = &ixgbe_setup_mac_link_smartspeed;
  102. else
  103. mac->ops.setup_link = &ixgbe_setup_mac_link_82599;
  104. }
  105. }
  106. static s32 ixgbe_setup_sfp_modules_82599(struct ixgbe_hw *hw)
  107. {
  108. s32 ret_val;
  109. u16 list_offset, data_offset, data_value;
  110. if (hw->phy.sfp_type != ixgbe_sfp_type_unknown) {
  111. ixgbe_init_mac_link_ops_82599(hw);
  112. hw->phy.ops.reset = NULL;
  113. ret_val = ixgbe_get_sfp_init_sequence_offsets(hw, &list_offset,
  114. &data_offset);
  115. if (ret_val)
  116. return ret_val;
  117. /* PHY config will finish before releasing the semaphore */
  118. ret_val = hw->mac.ops.acquire_swfw_sync(hw,
  119. IXGBE_GSSR_MAC_CSR_SM);
  120. if (ret_val)
  121. return IXGBE_ERR_SWFW_SYNC;
  122. if (hw->eeprom.ops.read(hw, ++data_offset, &data_value))
  123. goto setup_sfp_err;
  124. while (data_value != 0xffff) {
  125. IXGBE_WRITE_REG(hw, IXGBE_CORECTL, data_value);
  126. IXGBE_WRITE_FLUSH(hw);
  127. if (hw->eeprom.ops.read(hw, ++data_offset, &data_value))
  128. goto setup_sfp_err;
  129. }
  130. /* Release the semaphore */
  131. hw->mac.ops.release_swfw_sync(hw, IXGBE_GSSR_MAC_CSR_SM);
  132. /*
  133. * Delay obtaining semaphore again to allow FW access,
  134. * semaphore_delay is in ms usleep_range needs us.
  135. */
  136. usleep_range(hw->eeprom.semaphore_delay * 1000,
  137. hw->eeprom.semaphore_delay * 2000);
  138. /* Restart DSP and set SFI mode */
  139. ret_val = hw->mac.ops.prot_autoc_write(hw,
  140. hw->mac.orig_autoc | IXGBE_AUTOC_LMS_10G_SERIAL,
  141. false);
  142. if (ret_val) {
  143. hw_dbg(hw, " sfp module setup not complete\n");
  144. return IXGBE_ERR_SFP_SETUP_NOT_COMPLETE;
  145. }
  146. }
  147. return 0;
  148. setup_sfp_err:
  149. /* Release the semaphore */
  150. hw->mac.ops.release_swfw_sync(hw, IXGBE_GSSR_MAC_CSR_SM);
  151. /* Delay obtaining semaphore again to allow FW access,
  152. * semaphore_delay is in ms usleep_range needs us.
  153. */
  154. usleep_range(hw->eeprom.semaphore_delay * 1000,
  155. hw->eeprom.semaphore_delay * 2000);
  156. hw_err(hw, "eeprom read at offset %d failed\n", data_offset);
  157. return IXGBE_ERR_SFP_SETUP_NOT_COMPLETE;
  158. }
  159. /**
  160. * prot_autoc_read_82599 - Hides MAC differences needed for AUTOC read
  161. * @hw: pointer to hardware structure
  162. * @locked: Return the if we locked for this read.
  163. * @reg_val: Value we read from AUTOC
  164. *
  165. * For this part (82599) we need to wrap read-modify-writes with a possible
  166. * FW/SW lock. It is assumed this lock will be freed with the next
  167. * prot_autoc_write_82599(). Note, that locked can only be true in cases
  168. * where this function doesn't return an error.
  169. **/
  170. static s32 prot_autoc_read_82599(struct ixgbe_hw *hw, bool *locked,
  171. u32 *reg_val)
  172. {
  173. s32 ret_val;
  174. *locked = false;
  175. /* If LESM is on then we need to hold the SW/FW semaphore. */
  176. if (ixgbe_verify_lesm_fw_enabled_82599(hw)) {
  177. ret_val = hw->mac.ops.acquire_swfw_sync(hw,
  178. IXGBE_GSSR_MAC_CSR_SM);
  179. if (ret_val)
  180. return IXGBE_ERR_SWFW_SYNC;
  181. *locked = true;
  182. }
  183. *reg_val = IXGBE_READ_REG(hw, IXGBE_AUTOC);
  184. return 0;
  185. }
  186. /**
  187. * prot_autoc_write_82599 - Hides MAC differences needed for AUTOC write
  188. * @hw: pointer to hardware structure
  189. * @reg_val: value to write to AUTOC
  190. * @locked: bool to indicate whether the SW/FW lock was already taken by
  191. * previous proc_autoc_read_82599.
  192. *
  193. * This part (82599) may need to hold a the SW/FW lock around all writes to
  194. * AUTOC. Likewise after a write we need to do a pipeline reset.
  195. **/
  196. static s32 prot_autoc_write_82599(struct ixgbe_hw *hw, u32 autoc, bool locked)
  197. {
  198. s32 ret_val = 0;
  199. /* Blocked by MNG FW so bail */
  200. if (ixgbe_check_reset_blocked(hw))
  201. goto out;
  202. /* We only need to get the lock if:
  203. * - We didn't do it already (in the read part of a read-modify-write)
  204. * - LESM is enabled.
  205. */
  206. if (!locked && ixgbe_verify_lesm_fw_enabled_82599(hw)) {
  207. ret_val = hw->mac.ops.acquire_swfw_sync(hw,
  208. IXGBE_GSSR_MAC_CSR_SM);
  209. if (ret_val)
  210. return IXGBE_ERR_SWFW_SYNC;
  211. locked = true;
  212. }
  213. IXGBE_WRITE_REG(hw, IXGBE_AUTOC, autoc);
  214. ret_val = ixgbe_reset_pipeline_82599(hw);
  215. out:
  216. /* Free the SW/FW semaphore as we either grabbed it here or
  217. * already had it when this function was called.
  218. */
  219. if (locked)
  220. hw->mac.ops.release_swfw_sync(hw, IXGBE_GSSR_MAC_CSR_SM);
  221. return ret_val;
  222. }
  223. static s32 ixgbe_get_invariants_82599(struct ixgbe_hw *hw)
  224. {
  225. struct ixgbe_mac_info *mac = &hw->mac;
  226. ixgbe_init_mac_link_ops_82599(hw);
  227. mac->mcft_size = IXGBE_82599_MC_TBL_SIZE;
  228. mac->vft_size = IXGBE_82599_VFT_TBL_SIZE;
  229. mac->num_rar_entries = IXGBE_82599_RAR_ENTRIES;
  230. mac->rx_pb_size = IXGBE_82599_RX_PB_SIZE;
  231. mac->max_rx_queues = IXGBE_82599_MAX_RX_QUEUES;
  232. mac->max_tx_queues = IXGBE_82599_MAX_TX_QUEUES;
  233. mac->max_msix_vectors = ixgbe_get_pcie_msix_count_generic(hw);
  234. return 0;
  235. }
  236. /**
  237. * ixgbe_init_phy_ops_82599 - PHY/SFP specific init
  238. * @hw: pointer to hardware structure
  239. *
  240. * Initialize any function pointers that were not able to be
  241. * set during get_invariants because the PHY/SFP type was
  242. * not known. Perform the SFP init if necessary.
  243. *
  244. **/
  245. static s32 ixgbe_init_phy_ops_82599(struct ixgbe_hw *hw)
  246. {
  247. struct ixgbe_mac_info *mac = &hw->mac;
  248. struct ixgbe_phy_info *phy = &hw->phy;
  249. s32 ret_val;
  250. u32 esdp;
  251. if (hw->device_id == IXGBE_DEV_ID_82599_QSFP_SF_QP) {
  252. /* Store flag indicating I2C bus access control unit. */
  253. hw->phy.qsfp_shared_i2c_bus = true;
  254. /* Initialize access to QSFP+ I2C bus */
  255. esdp = IXGBE_READ_REG(hw, IXGBE_ESDP);
  256. esdp |= IXGBE_ESDP_SDP0_DIR;
  257. esdp &= ~IXGBE_ESDP_SDP1_DIR;
  258. esdp &= ~IXGBE_ESDP_SDP0;
  259. esdp &= ~IXGBE_ESDP_SDP0_NATIVE;
  260. esdp &= ~IXGBE_ESDP_SDP1_NATIVE;
  261. IXGBE_WRITE_REG(hw, IXGBE_ESDP, esdp);
  262. IXGBE_WRITE_FLUSH(hw);
  263. phy->ops.read_i2c_byte = &ixgbe_read_i2c_byte_82599;
  264. phy->ops.write_i2c_byte = &ixgbe_write_i2c_byte_82599;
  265. }
  266. /* Identify the PHY or SFP module */
  267. ret_val = phy->ops.identify(hw);
  268. /* Setup function pointers based on detected SFP module and speeds */
  269. ixgbe_init_mac_link_ops_82599(hw);
  270. /* If copper media, overwrite with copper function pointers */
  271. if (mac->ops.get_media_type(hw) == ixgbe_media_type_copper) {
  272. mac->ops.setup_link = &ixgbe_setup_copper_link_82599;
  273. mac->ops.get_link_capabilities =
  274. &ixgbe_get_copper_link_capabilities_generic;
  275. }
  276. /* Set necessary function pointers based on phy type */
  277. switch (hw->phy.type) {
  278. case ixgbe_phy_tn:
  279. phy->ops.check_link = &ixgbe_check_phy_link_tnx;
  280. phy->ops.setup_link = &ixgbe_setup_phy_link_tnx;
  281. phy->ops.get_firmware_version =
  282. &ixgbe_get_phy_firmware_version_tnx;
  283. break;
  284. default:
  285. break;
  286. }
  287. return ret_val;
  288. }
  289. /**
  290. * ixgbe_get_link_capabilities_82599 - Determines link capabilities
  291. * @hw: pointer to hardware structure
  292. * @speed: pointer to link speed
  293. * @autoneg: true when autoneg or autotry is enabled
  294. *
  295. * Determines the link capabilities by reading the AUTOC register.
  296. **/
  297. static s32 ixgbe_get_link_capabilities_82599(struct ixgbe_hw *hw,
  298. ixgbe_link_speed *speed,
  299. bool *autoneg)
  300. {
  301. u32 autoc = 0;
  302. /* Determine 1G link capabilities off of SFP+ type */
  303. if (hw->phy.sfp_type == ixgbe_sfp_type_1g_cu_core0 ||
  304. hw->phy.sfp_type == ixgbe_sfp_type_1g_cu_core1 ||
  305. hw->phy.sfp_type == ixgbe_sfp_type_1g_lx_core0 ||
  306. hw->phy.sfp_type == ixgbe_sfp_type_1g_lx_core1 ||
  307. hw->phy.sfp_type == ixgbe_sfp_type_1g_sx_core0 ||
  308. hw->phy.sfp_type == ixgbe_sfp_type_1g_sx_core1) {
  309. *speed = IXGBE_LINK_SPEED_1GB_FULL;
  310. *autoneg = true;
  311. return 0;
  312. }
  313. /*
  314. * Determine link capabilities based on the stored value of AUTOC,
  315. * which represents EEPROM defaults. If AUTOC value has not been
  316. * stored, use the current register value.
  317. */
  318. if (hw->mac.orig_link_settings_stored)
  319. autoc = hw->mac.orig_autoc;
  320. else
  321. autoc = IXGBE_READ_REG(hw, IXGBE_AUTOC);
  322. switch (autoc & IXGBE_AUTOC_LMS_MASK) {
  323. case IXGBE_AUTOC_LMS_1G_LINK_NO_AN:
  324. *speed = IXGBE_LINK_SPEED_1GB_FULL;
  325. *autoneg = false;
  326. break;
  327. case IXGBE_AUTOC_LMS_10G_LINK_NO_AN:
  328. *speed = IXGBE_LINK_SPEED_10GB_FULL;
  329. *autoneg = false;
  330. break;
  331. case IXGBE_AUTOC_LMS_1G_AN:
  332. *speed = IXGBE_LINK_SPEED_1GB_FULL;
  333. *autoneg = true;
  334. break;
  335. case IXGBE_AUTOC_LMS_10G_SERIAL:
  336. *speed = IXGBE_LINK_SPEED_10GB_FULL;
  337. *autoneg = false;
  338. break;
  339. case IXGBE_AUTOC_LMS_KX4_KX_KR:
  340. case IXGBE_AUTOC_LMS_KX4_KX_KR_1G_AN:
  341. *speed = IXGBE_LINK_SPEED_UNKNOWN;
  342. if (autoc & IXGBE_AUTOC_KR_SUPP)
  343. *speed |= IXGBE_LINK_SPEED_10GB_FULL;
  344. if (autoc & IXGBE_AUTOC_KX4_SUPP)
  345. *speed |= IXGBE_LINK_SPEED_10GB_FULL;
  346. if (autoc & IXGBE_AUTOC_KX_SUPP)
  347. *speed |= IXGBE_LINK_SPEED_1GB_FULL;
  348. *autoneg = true;
  349. break;
  350. case IXGBE_AUTOC_LMS_KX4_KX_KR_SGMII:
  351. *speed = IXGBE_LINK_SPEED_100_FULL;
  352. if (autoc & IXGBE_AUTOC_KR_SUPP)
  353. *speed |= IXGBE_LINK_SPEED_10GB_FULL;
  354. if (autoc & IXGBE_AUTOC_KX4_SUPP)
  355. *speed |= IXGBE_LINK_SPEED_10GB_FULL;
  356. if (autoc & IXGBE_AUTOC_KX_SUPP)
  357. *speed |= IXGBE_LINK_SPEED_1GB_FULL;
  358. *autoneg = true;
  359. break;
  360. case IXGBE_AUTOC_LMS_SGMII_1G_100M:
  361. *speed = IXGBE_LINK_SPEED_1GB_FULL | IXGBE_LINK_SPEED_100_FULL;
  362. *autoneg = false;
  363. break;
  364. default:
  365. return IXGBE_ERR_LINK_SETUP;
  366. }
  367. if (hw->phy.multispeed_fiber) {
  368. *speed |= IXGBE_LINK_SPEED_10GB_FULL |
  369. IXGBE_LINK_SPEED_1GB_FULL;
  370. /* QSFP must not enable auto-negotiation */
  371. if (hw->phy.media_type == ixgbe_media_type_fiber_qsfp)
  372. *autoneg = false;
  373. else
  374. *autoneg = true;
  375. }
  376. return 0;
  377. }
  378. /**
  379. * ixgbe_get_media_type_82599 - Get media type
  380. * @hw: pointer to hardware structure
  381. *
  382. * Returns the media type (fiber, copper, backplane)
  383. **/
  384. static enum ixgbe_media_type ixgbe_get_media_type_82599(struct ixgbe_hw *hw)
  385. {
  386. /* Detect if there is a copper PHY attached. */
  387. switch (hw->phy.type) {
  388. case ixgbe_phy_cu_unknown:
  389. case ixgbe_phy_tn:
  390. return ixgbe_media_type_copper;
  391. default:
  392. break;
  393. }
  394. switch (hw->device_id) {
  395. case IXGBE_DEV_ID_82599_KX4:
  396. case IXGBE_DEV_ID_82599_KX4_MEZZ:
  397. case IXGBE_DEV_ID_82599_COMBO_BACKPLANE:
  398. case IXGBE_DEV_ID_82599_KR:
  399. case IXGBE_DEV_ID_82599_BACKPLANE_FCOE:
  400. case IXGBE_DEV_ID_82599_XAUI_LOM:
  401. /* Default device ID is mezzanine card KX/KX4 */
  402. return ixgbe_media_type_backplane;
  403. case IXGBE_DEV_ID_82599_SFP:
  404. case IXGBE_DEV_ID_82599_SFP_FCOE:
  405. case IXGBE_DEV_ID_82599_SFP_EM:
  406. case IXGBE_DEV_ID_82599_SFP_SF2:
  407. case IXGBE_DEV_ID_82599_SFP_SF_QP:
  408. case IXGBE_DEV_ID_82599EN_SFP:
  409. return ixgbe_media_type_fiber;
  410. case IXGBE_DEV_ID_82599_CX4:
  411. return ixgbe_media_type_cx4;
  412. case IXGBE_DEV_ID_82599_T3_LOM:
  413. return ixgbe_media_type_copper;
  414. case IXGBE_DEV_ID_82599_LS:
  415. return ixgbe_media_type_fiber_lco;
  416. case IXGBE_DEV_ID_82599_QSFP_SF_QP:
  417. return ixgbe_media_type_fiber_qsfp;
  418. default:
  419. return ixgbe_media_type_unknown;
  420. }
  421. }
  422. /**
  423. * ixgbe_stop_mac_link_on_d3_82599 - Disables link on D3
  424. * @hw: pointer to hardware structure
  425. *
  426. * Disables link, should be called during D3 power down sequence.
  427. *
  428. **/
  429. static void ixgbe_stop_mac_link_on_d3_82599(struct ixgbe_hw *hw)
  430. {
  431. u32 autoc2_reg;
  432. u16 ee_ctrl_2 = 0;
  433. hw->eeprom.ops.read(hw, IXGBE_EEPROM_CTRL_2, &ee_ctrl_2);
  434. if (!ixgbe_mng_present(hw) && !hw->wol_enabled &&
  435. ee_ctrl_2 & IXGBE_EEPROM_CCD_BIT) {
  436. autoc2_reg = IXGBE_READ_REG(hw, IXGBE_AUTOC2);
  437. autoc2_reg |= IXGBE_AUTOC2_LINK_DISABLE_ON_D3_MASK;
  438. IXGBE_WRITE_REG(hw, IXGBE_AUTOC2, autoc2_reg);
  439. }
  440. }
  441. /**
  442. * ixgbe_start_mac_link_82599 - Setup MAC link settings
  443. * @hw: pointer to hardware structure
  444. * @autoneg_wait_to_complete: true when waiting for completion is needed
  445. *
  446. * Configures link settings based on values in the ixgbe_hw struct.
  447. * Restarts the link. Performs autonegotiation if needed.
  448. **/
  449. static s32 ixgbe_start_mac_link_82599(struct ixgbe_hw *hw,
  450. bool autoneg_wait_to_complete)
  451. {
  452. u32 autoc_reg;
  453. u32 links_reg;
  454. u32 i;
  455. s32 status = 0;
  456. bool got_lock = false;
  457. if (ixgbe_verify_lesm_fw_enabled_82599(hw)) {
  458. status = hw->mac.ops.acquire_swfw_sync(hw,
  459. IXGBE_GSSR_MAC_CSR_SM);
  460. if (status)
  461. return status;
  462. got_lock = true;
  463. }
  464. /* Restart link */
  465. ixgbe_reset_pipeline_82599(hw);
  466. if (got_lock)
  467. hw->mac.ops.release_swfw_sync(hw, IXGBE_GSSR_MAC_CSR_SM);
  468. /* Only poll for autoneg to complete if specified to do so */
  469. if (autoneg_wait_to_complete) {
  470. autoc_reg = IXGBE_READ_REG(hw, IXGBE_AUTOC);
  471. if ((autoc_reg & IXGBE_AUTOC_LMS_MASK) ==
  472. IXGBE_AUTOC_LMS_KX4_KX_KR ||
  473. (autoc_reg & IXGBE_AUTOC_LMS_MASK) ==
  474. IXGBE_AUTOC_LMS_KX4_KX_KR_1G_AN ||
  475. (autoc_reg & IXGBE_AUTOC_LMS_MASK) ==
  476. IXGBE_AUTOC_LMS_KX4_KX_KR_SGMII) {
  477. links_reg = 0; /* Just in case Autoneg time = 0 */
  478. for (i = 0; i < IXGBE_AUTO_NEG_TIME; i++) {
  479. links_reg = IXGBE_READ_REG(hw, IXGBE_LINKS);
  480. if (links_reg & IXGBE_LINKS_KX_AN_COMP)
  481. break;
  482. msleep(100);
  483. }
  484. if (!(links_reg & IXGBE_LINKS_KX_AN_COMP)) {
  485. status = IXGBE_ERR_AUTONEG_NOT_COMPLETE;
  486. hw_dbg(hw, "Autoneg did not complete.\n");
  487. }
  488. }
  489. }
  490. /* Add delay to filter out noises during initial link setup */
  491. msleep(50);
  492. return status;
  493. }
  494. /**
  495. * ixgbe_disable_tx_laser_multispeed_fiber - Disable Tx laser
  496. * @hw: pointer to hardware structure
  497. *
  498. * The base drivers may require better control over SFP+ module
  499. * PHY states. This includes selectively shutting down the Tx
  500. * laser on the PHY, effectively halting physical link.
  501. **/
  502. static void ixgbe_disable_tx_laser_multispeed_fiber(struct ixgbe_hw *hw)
  503. {
  504. u32 esdp_reg = IXGBE_READ_REG(hw, IXGBE_ESDP);
  505. /* Blocked by MNG FW so bail */
  506. if (ixgbe_check_reset_blocked(hw))
  507. return;
  508. /* Disable tx laser; allow 100us to go dark per spec */
  509. esdp_reg |= IXGBE_ESDP_SDP3;
  510. IXGBE_WRITE_REG(hw, IXGBE_ESDP, esdp_reg);
  511. IXGBE_WRITE_FLUSH(hw);
  512. udelay(100);
  513. }
  514. /**
  515. * ixgbe_enable_tx_laser_multispeed_fiber - Enable Tx laser
  516. * @hw: pointer to hardware structure
  517. *
  518. * The base drivers may require better control over SFP+ module
  519. * PHY states. This includes selectively turning on the Tx
  520. * laser on the PHY, effectively starting physical link.
  521. **/
  522. static void ixgbe_enable_tx_laser_multispeed_fiber(struct ixgbe_hw *hw)
  523. {
  524. u32 esdp_reg = IXGBE_READ_REG(hw, IXGBE_ESDP);
  525. /* Enable tx laser; allow 100ms to light up */
  526. esdp_reg &= ~IXGBE_ESDP_SDP3;
  527. IXGBE_WRITE_REG(hw, IXGBE_ESDP, esdp_reg);
  528. IXGBE_WRITE_FLUSH(hw);
  529. msleep(100);
  530. }
  531. /**
  532. * ixgbe_flap_tx_laser_multispeed_fiber - Flap Tx laser
  533. * @hw: pointer to hardware structure
  534. *
  535. * When the driver changes the link speeds that it can support,
  536. * it sets autotry_restart to true to indicate that we need to
  537. * initiate a new autotry session with the link partner. To do
  538. * so, we set the speed then disable and re-enable the tx laser, to
  539. * alert the link partner that it also needs to restart autotry on its
  540. * end. This is consistent with true clause 37 autoneg, which also
  541. * involves a loss of signal.
  542. **/
  543. static void ixgbe_flap_tx_laser_multispeed_fiber(struct ixgbe_hw *hw)
  544. {
  545. /* Blocked by MNG FW so bail */
  546. if (ixgbe_check_reset_blocked(hw))
  547. return;
  548. if (hw->mac.autotry_restart) {
  549. ixgbe_disable_tx_laser_multispeed_fiber(hw);
  550. ixgbe_enable_tx_laser_multispeed_fiber(hw);
  551. hw->mac.autotry_restart = false;
  552. }
  553. }
  554. /**
  555. * ixgbe_set_hard_rate_select_speed - Set module link speed
  556. * @hw: pointer to hardware structure
  557. * @speed: link speed to set
  558. *
  559. * Set module link speed via RS0/RS1 rate select pins.
  560. */
  561. static void
  562. ixgbe_set_hard_rate_select_speed(struct ixgbe_hw *hw, ixgbe_link_speed speed)
  563. {
  564. u32 esdp_reg = IXGBE_READ_REG(hw, IXGBE_ESDP);
  565. switch (speed) {
  566. case IXGBE_LINK_SPEED_10GB_FULL:
  567. esdp_reg |= (IXGBE_ESDP_SDP5_DIR | IXGBE_ESDP_SDP5);
  568. break;
  569. case IXGBE_LINK_SPEED_1GB_FULL:
  570. esdp_reg &= ~IXGBE_ESDP_SDP5;
  571. esdp_reg |= IXGBE_ESDP_SDP5_DIR;
  572. break;
  573. default:
  574. hw_dbg(hw, "Invalid fixed module speed\n");
  575. return;
  576. }
  577. IXGBE_WRITE_REG(hw, IXGBE_ESDP, esdp_reg);
  578. IXGBE_WRITE_FLUSH(hw);
  579. }
  580. /**
  581. * ixgbe_setup_mac_link_smartspeed - Set MAC link speed using SmartSpeed
  582. * @hw: pointer to hardware structure
  583. * @speed: new link speed
  584. * @autoneg_wait_to_complete: true when waiting for completion is needed
  585. *
  586. * Implements the Intel SmartSpeed algorithm.
  587. **/
  588. static s32 ixgbe_setup_mac_link_smartspeed(struct ixgbe_hw *hw,
  589. ixgbe_link_speed speed,
  590. bool autoneg_wait_to_complete)
  591. {
  592. s32 status = 0;
  593. ixgbe_link_speed link_speed = IXGBE_LINK_SPEED_UNKNOWN;
  594. s32 i, j;
  595. bool link_up = false;
  596. u32 autoc_reg = IXGBE_READ_REG(hw, IXGBE_AUTOC);
  597. /* Set autoneg_advertised value based on input link speed */
  598. hw->phy.autoneg_advertised = 0;
  599. if (speed & IXGBE_LINK_SPEED_10GB_FULL)
  600. hw->phy.autoneg_advertised |= IXGBE_LINK_SPEED_10GB_FULL;
  601. if (speed & IXGBE_LINK_SPEED_1GB_FULL)
  602. hw->phy.autoneg_advertised |= IXGBE_LINK_SPEED_1GB_FULL;
  603. if (speed & IXGBE_LINK_SPEED_100_FULL)
  604. hw->phy.autoneg_advertised |= IXGBE_LINK_SPEED_100_FULL;
  605. /*
  606. * Implement Intel SmartSpeed algorithm. SmartSpeed will reduce the
  607. * autoneg advertisement if link is unable to be established at the
  608. * highest negotiated rate. This can sometimes happen due to integrity
  609. * issues with the physical media connection.
  610. */
  611. /* First, try to get link with full advertisement */
  612. hw->phy.smart_speed_active = false;
  613. for (j = 0; j < IXGBE_SMARTSPEED_MAX_RETRIES; j++) {
  614. status = ixgbe_setup_mac_link_82599(hw, speed,
  615. autoneg_wait_to_complete);
  616. if (status != 0)
  617. goto out;
  618. /*
  619. * Wait for the controller to acquire link. Per IEEE 802.3ap,
  620. * Section 73.10.2, we may have to wait up to 500ms if KR is
  621. * attempted, or 200ms if KX/KX4/BX/BX4 is attempted, per
  622. * Table 9 in the AN MAS.
  623. */
  624. for (i = 0; i < 5; i++) {
  625. mdelay(100);
  626. /* If we have link, just jump out */
  627. status = hw->mac.ops.check_link(hw, &link_speed,
  628. &link_up, false);
  629. if (status != 0)
  630. goto out;
  631. if (link_up)
  632. goto out;
  633. }
  634. }
  635. /*
  636. * We didn't get link. If we advertised KR plus one of KX4/KX
  637. * (or BX4/BX), then disable KR and try again.
  638. */
  639. if (((autoc_reg & IXGBE_AUTOC_KR_SUPP) == 0) ||
  640. ((autoc_reg & IXGBE_AUTOC_KX4_KX_SUPP_MASK) == 0))
  641. goto out;
  642. /* Turn SmartSpeed on to disable KR support */
  643. hw->phy.smart_speed_active = true;
  644. status = ixgbe_setup_mac_link_82599(hw, speed,
  645. autoneg_wait_to_complete);
  646. if (status != 0)
  647. goto out;
  648. /*
  649. * Wait for the controller to acquire link. 600ms will allow for
  650. * the AN link_fail_inhibit_timer as well for multiple cycles of
  651. * parallel detect, both 10g and 1g. This allows for the maximum
  652. * connect attempts as defined in the AN MAS table 73-7.
  653. */
  654. for (i = 0; i < 6; i++) {
  655. mdelay(100);
  656. /* If we have link, just jump out */
  657. status = hw->mac.ops.check_link(hw, &link_speed,
  658. &link_up, false);
  659. if (status != 0)
  660. goto out;
  661. if (link_up)
  662. goto out;
  663. }
  664. /* We didn't get link. Turn SmartSpeed back off. */
  665. hw->phy.smart_speed_active = false;
  666. status = ixgbe_setup_mac_link_82599(hw, speed,
  667. autoneg_wait_to_complete);
  668. out:
  669. if (link_up && (link_speed == IXGBE_LINK_SPEED_1GB_FULL))
  670. hw_dbg(hw, "Smartspeed has downgraded the link speed from the maximum advertised\n");
  671. return status;
  672. }
  673. /**
  674. * ixgbe_setup_mac_link_82599 - Set MAC link speed
  675. * @hw: pointer to hardware structure
  676. * @speed: new link speed
  677. * @autoneg_wait_to_complete: true when waiting for completion is needed
  678. *
  679. * Set the link speed in the AUTOC register and restarts link.
  680. **/
  681. static s32 ixgbe_setup_mac_link_82599(struct ixgbe_hw *hw,
  682. ixgbe_link_speed speed,
  683. bool autoneg_wait_to_complete)
  684. {
  685. bool autoneg = false;
  686. s32 status;
  687. u32 pma_pmd_1g, link_mode, links_reg, i;
  688. u32 autoc2 = IXGBE_READ_REG(hw, IXGBE_AUTOC2);
  689. u32 pma_pmd_10g_serial = autoc2 & IXGBE_AUTOC2_10G_SERIAL_PMA_PMD_MASK;
  690. ixgbe_link_speed link_capabilities = IXGBE_LINK_SPEED_UNKNOWN;
  691. /* holds the value of AUTOC register at this current point in time */
  692. u32 current_autoc = IXGBE_READ_REG(hw, IXGBE_AUTOC);
  693. /* holds the cached value of AUTOC register */
  694. u32 orig_autoc = 0;
  695. /* temporary variable used for comparison purposes */
  696. u32 autoc = current_autoc;
  697. /* Check to see if speed passed in is supported. */
  698. status = hw->mac.ops.get_link_capabilities(hw, &link_capabilities,
  699. &autoneg);
  700. if (status)
  701. return status;
  702. speed &= link_capabilities;
  703. if (speed == IXGBE_LINK_SPEED_UNKNOWN)
  704. return IXGBE_ERR_LINK_SETUP;
  705. /* Use stored value (EEPROM defaults) of AUTOC to find KR/KX4 support*/
  706. if (hw->mac.orig_link_settings_stored)
  707. orig_autoc = hw->mac.orig_autoc;
  708. else
  709. orig_autoc = autoc;
  710. link_mode = autoc & IXGBE_AUTOC_LMS_MASK;
  711. pma_pmd_1g = autoc & IXGBE_AUTOC_1G_PMA_PMD_MASK;
  712. if (link_mode == IXGBE_AUTOC_LMS_KX4_KX_KR ||
  713. link_mode == IXGBE_AUTOC_LMS_KX4_KX_KR_1G_AN ||
  714. link_mode == IXGBE_AUTOC_LMS_KX4_KX_KR_SGMII) {
  715. /* Set KX4/KX/KR support according to speed requested */
  716. autoc &= ~(IXGBE_AUTOC_KX4_KX_SUPP_MASK | IXGBE_AUTOC_KR_SUPP);
  717. if (speed & IXGBE_LINK_SPEED_10GB_FULL) {
  718. if (orig_autoc & IXGBE_AUTOC_KX4_SUPP)
  719. autoc |= IXGBE_AUTOC_KX4_SUPP;
  720. if ((orig_autoc & IXGBE_AUTOC_KR_SUPP) &&
  721. (hw->phy.smart_speed_active == false))
  722. autoc |= IXGBE_AUTOC_KR_SUPP;
  723. }
  724. if (speed & IXGBE_LINK_SPEED_1GB_FULL)
  725. autoc |= IXGBE_AUTOC_KX_SUPP;
  726. } else if ((pma_pmd_1g == IXGBE_AUTOC_1G_SFI) &&
  727. (link_mode == IXGBE_AUTOC_LMS_1G_LINK_NO_AN ||
  728. link_mode == IXGBE_AUTOC_LMS_1G_AN)) {
  729. /* Switch from 1G SFI to 10G SFI if requested */
  730. if ((speed == IXGBE_LINK_SPEED_10GB_FULL) &&
  731. (pma_pmd_10g_serial == IXGBE_AUTOC2_10G_SFI)) {
  732. autoc &= ~IXGBE_AUTOC_LMS_MASK;
  733. autoc |= IXGBE_AUTOC_LMS_10G_SERIAL;
  734. }
  735. } else if ((pma_pmd_10g_serial == IXGBE_AUTOC2_10G_SFI) &&
  736. (link_mode == IXGBE_AUTOC_LMS_10G_SERIAL)) {
  737. /* Switch from 10G SFI to 1G SFI if requested */
  738. if ((speed == IXGBE_LINK_SPEED_1GB_FULL) &&
  739. (pma_pmd_1g == IXGBE_AUTOC_1G_SFI)) {
  740. autoc &= ~IXGBE_AUTOC_LMS_MASK;
  741. if (autoneg)
  742. autoc |= IXGBE_AUTOC_LMS_1G_AN;
  743. else
  744. autoc |= IXGBE_AUTOC_LMS_1G_LINK_NO_AN;
  745. }
  746. }
  747. if (autoc != current_autoc) {
  748. /* Restart link */
  749. status = hw->mac.ops.prot_autoc_write(hw, autoc, false);
  750. if (status)
  751. return status;
  752. /* Only poll for autoneg to complete if specified to do so */
  753. if (autoneg_wait_to_complete) {
  754. if (link_mode == IXGBE_AUTOC_LMS_KX4_KX_KR ||
  755. link_mode == IXGBE_AUTOC_LMS_KX4_KX_KR_1G_AN ||
  756. link_mode == IXGBE_AUTOC_LMS_KX4_KX_KR_SGMII) {
  757. links_reg = 0; /*Just in case Autoneg time=0*/
  758. for (i = 0; i < IXGBE_AUTO_NEG_TIME; i++) {
  759. links_reg =
  760. IXGBE_READ_REG(hw, IXGBE_LINKS);
  761. if (links_reg & IXGBE_LINKS_KX_AN_COMP)
  762. break;
  763. msleep(100);
  764. }
  765. if (!(links_reg & IXGBE_LINKS_KX_AN_COMP)) {
  766. status =
  767. IXGBE_ERR_AUTONEG_NOT_COMPLETE;
  768. hw_dbg(hw, "Autoneg did not complete.\n");
  769. }
  770. }
  771. }
  772. /* Add delay to filter out noises during initial link setup */
  773. msleep(50);
  774. }
  775. return status;
  776. }
  777. /**
  778. * ixgbe_setup_copper_link_82599 - Set the PHY autoneg advertised field
  779. * @hw: pointer to hardware structure
  780. * @speed: new link speed
  781. * @autoneg_wait_to_complete: true if waiting is needed to complete
  782. *
  783. * Restarts link on PHY and MAC based on settings passed in.
  784. **/
  785. static s32 ixgbe_setup_copper_link_82599(struct ixgbe_hw *hw,
  786. ixgbe_link_speed speed,
  787. bool autoneg_wait_to_complete)
  788. {
  789. s32 status;
  790. /* Setup the PHY according to input speed */
  791. status = hw->phy.ops.setup_link_speed(hw, speed,
  792. autoneg_wait_to_complete);
  793. /* Set up MAC */
  794. ixgbe_start_mac_link_82599(hw, autoneg_wait_to_complete);
  795. return status;
  796. }
  797. /**
  798. * ixgbe_reset_hw_82599 - Perform hardware reset
  799. * @hw: pointer to hardware structure
  800. *
  801. * Resets the hardware by resetting the transmit and receive units, masks
  802. * and clears all interrupts, perform a PHY reset, and perform a link (MAC)
  803. * reset.
  804. **/
  805. static s32 ixgbe_reset_hw_82599(struct ixgbe_hw *hw)
  806. {
  807. ixgbe_link_speed link_speed;
  808. s32 status;
  809. u32 ctrl, i, autoc, autoc2;
  810. u32 curr_lms;
  811. bool link_up = false;
  812. /* Call adapter stop to disable tx/rx and clear interrupts */
  813. status = hw->mac.ops.stop_adapter(hw);
  814. if (status)
  815. return status;
  816. /* flush pending Tx transactions */
  817. ixgbe_clear_tx_pending(hw);
  818. /* PHY ops must be identified and initialized prior to reset */
  819. /* Identify PHY and related function pointers */
  820. status = hw->phy.ops.init(hw);
  821. if (status == IXGBE_ERR_SFP_NOT_SUPPORTED)
  822. return status;
  823. /* Setup SFP module if there is one present. */
  824. if (hw->phy.sfp_setup_needed) {
  825. status = hw->mac.ops.setup_sfp(hw);
  826. hw->phy.sfp_setup_needed = false;
  827. }
  828. if (status == IXGBE_ERR_SFP_NOT_SUPPORTED)
  829. return status;
  830. /* Reset PHY */
  831. if (hw->phy.reset_disable == false && hw->phy.ops.reset != NULL)
  832. hw->phy.ops.reset(hw);
  833. /* remember AUTOC from before we reset */
  834. curr_lms = IXGBE_READ_REG(hw, IXGBE_AUTOC) & IXGBE_AUTOC_LMS_MASK;
  835. mac_reset_top:
  836. /*
  837. * Issue global reset to the MAC. Needs to be SW reset if link is up.
  838. * If link reset is used when link is up, it might reset the PHY when
  839. * mng is using it. If link is down or the flag to force full link
  840. * reset is set, then perform link reset.
  841. */
  842. ctrl = IXGBE_CTRL_LNK_RST;
  843. if (!hw->force_full_reset) {
  844. hw->mac.ops.check_link(hw, &link_speed, &link_up, false);
  845. if (link_up)
  846. ctrl = IXGBE_CTRL_RST;
  847. }
  848. ctrl |= IXGBE_READ_REG(hw, IXGBE_CTRL);
  849. IXGBE_WRITE_REG(hw, IXGBE_CTRL, ctrl);
  850. IXGBE_WRITE_FLUSH(hw);
  851. /* Poll for reset bit to self-clear indicating reset is complete */
  852. for (i = 0; i < 10; i++) {
  853. udelay(1);
  854. ctrl = IXGBE_READ_REG(hw, IXGBE_CTRL);
  855. if (!(ctrl & IXGBE_CTRL_RST_MASK))
  856. break;
  857. }
  858. if (ctrl & IXGBE_CTRL_RST_MASK) {
  859. status = IXGBE_ERR_RESET_FAILED;
  860. hw_dbg(hw, "Reset polling failed to complete.\n");
  861. }
  862. msleep(50);
  863. /*
  864. * Double resets are required for recovery from certain error
  865. * conditions. Between resets, it is necessary to stall to allow time
  866. * for any pending HW events to complete.
  867. */
  868. if (hw->mac.flags & IXGBE_FLAGS_DOUBLE_RESET_REQUIRED) {
  869. hw->mac.flags &= ~IXGBE_FLAGS_DOUBLE_RESET_REQUIRED;
  870. goto mac_reset_top;
  871. }
  872. /*
  873. * Store the original AUTOC/AUTOC2 values if they have not been
  874. * stored off yet. Otherwise restore the stored original
  875. * values since the reset operation sets back to defaults.
  876. */
  877. autoc = IXGBE_READ_REG(hw, IXGBE_AUTOC);
  878. autoc2 = IXGBE_READ_REG(hw, IXGBE_AUTOC2);
  879. /* Enable link if disabled in NVM */
  880. if (autoc2 & IXGBE_AUTOC2_LINK_DISABLE_MASK) {
  881. autoc2 &= ~IXGBE_AUTOC2_LINK_DISABLE_MASK;
  882. IXGBE_WRITE_REG(hw, IXGBE_AUTOC2, autoc2);
  883. IXGBE_WRITE_FLUSH(hw);
  884. }
  885. if (hw->mac.orig_link_settings_stored == false) {
  886. hw->mac.orig_autoc = autoc;
  887. hw->mac.orig_autoc2 = autoc2;
  888. hw->mac.orig_link_settings_stored = true;
  889. } else {
  890. /* If MNG FW is running on a multi-speed device that
  891. * doesn't autoneg with out driver support we need to
  892. * leave LMS in the state it was before we MAC reset.
  893. * Likewise if we support WoL we don't want change the
  894. * LMS state either.
  895. */
  896. if ((hw->phy.multispeed_fiber && ixgbe_mng_enabled(hw)) ||
  897. hw->wol_enabled)
  898. hw->mac.orig_autoc =
  899. (hw->mac.orig_autoc & ~IXGBE_AUTOC_LMS_MASK) |
  900. curr_lms;
  901. if (autoc != hw->mac.orig_autoc) {
  902. status = hw->mac.ops.prot_autoc_write(hw,
  903. hw->mac.orig_autoc,
  904. false);
  905. if (status)
  906. return status;
  907. }
  908. if ((autoc2 & IXGBE_AUTOC2_UPPER_MASK) !=
  909. (hw->mac.orig_autoc2 & IXGBE_AUTOC2_UPPER_MASK)) {
  910. autoc2 &= ~IXGBE_AUTOC2_UPPER_MASK;
  911. autoc2 |= (hw->mac.orig_autoc2 &
  912. IXGBE_AUTOC2_UPPER_MASK);
  913. IXGBE_WRITE_REG(hw, IXGBE_AUTOC2, autoc2);
  914. }
  915. }
  916. /* Store the permanent mac address */
  917. hw->mac.ops.get_mac_addr(hw, hw->mac.perm_addr);
  918. /*
  919. * Store MAC address from RAR0, clear receive address registers, and
  920. * clear the multicast table. Also reset num_rar_entries to 128,
  921. * since we modify this value when programming the SAN MAC address.
  922. */
  923. hw->mac.num_rar_entries = 128;
  924. hw->mac.ops.init_rx_addrs(hw);
  925. /* Store the permanent SAN mac address */
  926. hw->mac.ops.get_san_mac_addr(hw, hw->mac.san_addr);
  927. /* Add the SAN MAC address to the RAR only if it's a valid address */
  928. if (is_valid_ether_addr(hw->mac.san_addr)) {
  929. hw->mac.ops.set_rar(hw, hw->mac.num_rar_entries - 1,
  930. hw->mac.san_addr, 0, IXGBE_RAH_AV);
  931. /* Save the SAN MAC RAR index */
  932. hw->mac.san_mac_rar_index = hw->mac.num_rar_entries - 1;
  933. /* Reserve the last RAR for the SAN MAC address */
  934. hw->mac.num_rar_entries--;
  935. }
  936. /* Store the alternative WWNN/WWPN prefix */
  937. hw->mac.ops.get_wwn_prefix(hw, &hw->mac.wwnn_prefix,
  938. &hw->mac.wwpn_prefix);
  939. return status;
  940. }
  941. /**
  942. * ixgbe_fdir_check_cmd_complete - poll to check whether FDIRCMD is complete
  943. * @hw: pointer to hardware structure
  944. * @fdircmd: current value of FDIRCMD register
  945. */
  946. static s32 ixgbe_fdir_check_cmd_complete(struct ixgbe_hw *hw, u32 *fdircmd)
  947. {
  948. int i;
  949. for (i = 0; i < IXGBE_FDIRCMD_CMD_POLL; i++) {
  950. *fdircmd = IXGBE_READ_REG(hw, IXGBE_FDIRCMD);
  951. if (!(*fdircmd & IXGBE_FDIRCMD_CMD_MASK))
  952. return 0;
  953. udelay(10);
  954. }
  955. return IXGBE_ERR_FDIR_CMD_INCOMPLETE;
  956. }
  957. /**
  958. * ixgbe_reinit_fdir_tables_82599 - Reinitialize Flow Director tables.
  959. * @hw: pointer to hardware structure
  960. **/
  961. s32 ixgbe_reinit_fdir_tables_82599(struct ixgbe_hw *hw)
  962. {
  963. int i;
  964. u32 fdirctrl = IXGBE_READ_REG(hw, IXGBE_FDIRCTRL);
  965. u32 fdircmd;
  966. s32 err;
  967. fdirctrl &= ~IXGBE_FDIRCTRL_INIT_DONE;
  968. /*
  969. * Before starting reinitialization process,
  970. * FDIRCMD.CMD must be zero.
  971. */
  972. err = ixgbe_fdir_check_cmd_complete(hw, &fdircmd);
  973. if (err) {
  974. hw_dbg(hw, "Flow Director previous command did not complete, aborting table re-initialization.\n");
  975. return err;
  976. }
  977. IXGBE_WRITE_REG(hw, IXGBE_FDIRFREE, 0);
  978. IXGBE_WRITE_FLUSH(hw);
  979. /*
  980. * 82599 adapters flow director init flow cannot be restarted,
  981. * Workaround 82599 silicon errata by performing the following steps
  982. * before re-writing the FDIRCTRL control register with the same value.
  983. * - write 1 to bit 8 of FDIRCMD register &
  984. * - write 0 to bit 8 of FDIRCMD register
  985. */
  986. IXGBE_WRITE_REG(hw, IXGBE_FDIRCMD,
  987. (IXGBE_READ_REG(hw, IXGBE_FDIRCMD) |
  988. IXGBE_FDIRCMD_CLEARHT));
  989. IXGBE_WRITE_FLUSH(hw);
  990. IXGBE_WRITE_REG(hw, IXGBE_FDIRCMD,
  991. (IXGBE_READ_REG(hw, IXGBE_FDIRCMD) &
  992. ~IXGBE_FDIRCMD_CLEARHT));
  993. IXGBE_WRITE_FLUSH(hw);
  994. /*
  995. * Clear FDIR Hash register to clear any leftover hashes
  996. * waiting to be programmed.
  997. */
  998. IXGBE_WRITE_REG(hw, IXGBE_FDIRHASH, 0x00);
  999. IXGBE_WRITE_FLUSH(hw);
  1000. IXGBE_WRITE_REG(hw, IXGBE_FDIRCTRL, fdirctrl);
  1001. IXGBE_WRITE_FLUSH(hw);
  1002. /* Poll init-done after we write FDIRCTRL register */
  1003. for (i = 0; i < IXGBE_FDIR_INIT_DONE_POLL; i++) {
  1004. if (IXGBE_READ_REG(hw, IXGBE_FDIRCTRL) &
  1005. IXGBE_FDIRCTRL_INIT_DONE)
  1006. break;
  1007. usleep_range(1000, 2000);
  1008. }
  1009. if (i >= IXGBE_FDIR_INIT_DONE_POLL) {
  1010. hw_dbg(hw, "Flow Director Signature poll time exceeded!\n");
  1011. return IXGBE_ERR_FDIR_REINIT_FAILED;
  1012. }
  1013. /* Clear FDIR statistics registers (read to clear) */
  1014. IXGBE_READ_REG(hw, IXGBE_FDIRUSTAT);
  1015. IXGBE_READ_REG(hw, IXGBE_FDIRFSTAT);
  1016. IXGBE_READ_REG(hw, IXGBE_FDIRMATCH);
  1017. IXGBE_READ_REG(hw, IXGBE_FDIRMISS);
  1018. IXGBE_READ_REG(hw, IXGBE_FDIRLEN);
  1019. return 0;
  1020. }
  1021. /**
  1022. * ixgbe_fdir_enable_82599 - Initialize Flow Director control registers
  1023. * @hw: pointer to hardware structure
  1024. * @fdirctrl: value to write to flow director control register
  1025. **/
  1026. static void ixgbe_fdir_enable_82599(struct ixgbe_hw *hw, u32 fdirctrl)
  1027. {
  1028. int i;
  1029. /* Prime the keys for hashing */
  1030. IXGBE_WRITE_REG(hw, IXGBE_FDIRHKEY, IXGBE_ATR_BUCKET_HASH_KEY);
  1031. IXGBE_WRITE_REG(hw, IXGBE_FDIRSKEY, IXGBE_ATR_SIGNATURE_HASH_KEY);
  1032. /*
  1033. * Poll init-done after we write the register. Estimated times:
  1034. * 10G: PBALLOC = 11b, timing is 60us
  1035. * 1G: PBALLOC = 11b, timing is 600us
  1036. * 100M: PBALLOC = 11b, timing is 6ms
  1037. *
  1038. * Multiple these timings by 4 if under full Rx load
  1039. *
  1040. * So we'll poll for IXGBE_FDIR_INIT_DONE_POLL times, sleeping for
  1041. * 1 msec per poll time. If we're at line rate and drop to 100M, then
  1042. * this might not finish in our poll time, but we can live with that
  1043. * for now.
  1044. */
  1045. IXGBE_WRITE_REG(hw, IXGBE_FDIRCTRL, fdirctrl);
  1046. IXGBE_WRITE_FLUSH(hw);
  1047. for (i = 0; i < IXGBE_FDIR_INIT_DONE_POLL; i++) {
  1048. if (IXGBE_READ_REG(hw, IXGBE_FDIRCTRL) &
  1049. IXGBE_FDIRCTRL_INIT_DONE)
  1050. break;
  1051. usleep_range(1000, 2000);
  1052. }
  1053. if (i >= IXGBE_FDIR_INIT_DONE_POLL)
  1054. hw_dbg(hw, "Flow Director poll time exceeded!\n");
  1055. }
  1056. /**
  1057. * ixgbe_init_fdir_signature_82599 - Initialize Flow Director signature filters
  1058. * @hw: pointer to hardware structure
  1059. * @fdirctrl: value to write to flow director control register, initially
  1060. * contains just the value of the Rx packet buffer allocation
  1061. **/
  1062. s32 ixgbe_init_fdir_signature_82599(struct ixgbe_hw *hw, u32 fdirctrl)
  1063. {
  1064. /*
  1065. * Continue setup of fdirctrl register bits:
  1066. * Move the flexible bytes to use the ethertype - shift 6 words
  1067. * Set the maximum length per hash bucket to 0xA filters
  1068. * Send interrupt when 64 filters are left
  1069. */
  1070. fdirctrl |= (0x6 << IXGBE_FDIRCTRL_FLEX_SHIFT) |
  1071. (0xA << IXGBE_FDIRCTRL_MAX_LENGTH_SHIFT) |
  1072. (4 << IXGBE_FDIRCTRL_FULL_THRESH_SHIFT);
  1073. /* write hashes and fdirctrl register, poll for completion */
  1074. ixgbe_fdir_enable_82599(hw, fdirctrl);
  1075. return 0;
  1076. }
  1077. /**
  1078. * ixgbe_init_fdir_perfect_82599 - Initialize Flow Director perfect filters
  1079. * @hw: pointer to hardware structure
  1080. * @fdirctrl: value to write to flow director control register, initially
  1081. * contains just the value of the Rx packet buffer allocation
  1082. **/
  1083. s32 ixgbe_init_fdir_perfect_82599(struct ixgbe_hw *hw, u32 fdirctrl)
  1084. {
  1085. /*
  1086. * Continue setup of fdirctrl register bits:
  1087. * Turn perfect match filtering on
  1088. * Initialize the drop queue
  1089. * Move the flexible bytes to use the ethertype - shift 6 words
  1090. * Set the maximum length per hash bucket to 0xA filters
  1091. * Send interrupt when 64 (0x4 * 16) filters are left
  1092. */
  1093. fdirctrl |= IXGBE_FDIRCTRL_PERFECT_MATCH |
  1094. (IXGBE_FDIR_DROP_QUEUE << IXGBE_FDIRCTRL_DROP_Q_SHIFT) |
  1095. (0x6 << IXGBE_FDIRCTRL_FLEX_SHIFT) |
  1096. (0xA << IXGBE_FDIRCTRL_MAX_LENGTH_SHIFT) |
  1097. (4 << IXGBE_FDIRCTRL_FULL_THRESH_SHIFT);
  1098. /* write hashes and fdirctrl register, poll for completion */
  1099. ixgbe_fdir_enable_82599(hw, fdirctrl);
  1100. return 0;
  1101. }
  1102. /*
  1103. * These defines allow us to quickly generate all of the necessary instructions
  1104. * in the function below by simply calling out IXGBE_COMPUTE_SIG_HASH_ITERATION
  1105. * for values 0 through 15
  1106. */
  1107. #define IXGBE_ATR_COMMON_HASH_KEY \
  1108. (IXGBE_ATR_BUCKET_HASH_KEY & IXGBE_ATR_SIGNATURE_HASH_KEY)
  1109. #define IXGBE_COMPUTE_SIG_HASH_ITERATION(_n) \
  1110. do { \
  1111. u32 n = (_n); \
  1112. if (IXGBE_ATR_COMMON_HASH_KEY & (0x01 << n)) \
  1113. common_hash ^= lo_hash_dword >> n; \
  1114. else if (IXGBE_ATR_BUCKET_HASH_KEY & (0x01 << n)) \
  1115. bucket_hash ^= lo_hash_dword >> n; \
  1116. else if (IXGBE_ATR_SIGNATURE_HASH_KEY & (0x01 << n)) \
  1117. sig_hash ^= lo_hash_dword << (16 - n); \
  1118. if (IXGBE_ATR_COMMON_HASH_KEY & (0x01 << (n + 16))) \
  1119. common_hash ^= hi_hash_dword >> n; \
  1120. else if (IXGBE_ATR_BUCKET_HASH_KEY & (0x01 << (n + 16))) \
  1121. bucket_hash ^= hi_hash_dword >> n; \
  1122. else if (IXGBE_ATR_SIGNATURE_HASH_KEY & (0x01 << (n + 16))) \
  1123. sig_hash ^= hi_hash_dword << (16 - n); \
  1124. } while (0)
  1125. /**
  1126. * ixgbe_atr_compute_sig_hash_82599 - Compute the signature hash
  1127. * @stream: input bitstream to compute the hash on
  1128. *
  1129. * This function is almost identical to the function above but contains
  1130. * several optomizations such as unwinding all of the loops, letting the
  1131. * compiler work out all of the conditional ifs since the keys are static
  1132. * defines, and computing two keys at once since the hashed dword stream
  1133. * will be the same for both keys.
  1134. **/
  1135. static u32 ixgbe_atr_compute_sig_hash_82599(union ixgbe_atr_hash_dword input,
  1136. union ixgbe_atr_hash_dword common)
  1137. {
  1138. u32 hi_hash_dword, lo_hash_dword, flow_vm_vlan;
  1139. u32 sig_hash = 0, bucket_hash = 0, common_hash = 0;
  1140. /* record the flow_vm_vlan bits as they are a key part to the hash */
  1141. flow_vm_vlan = ntohl(input.dword);
  1142. /* generate common hash dword */
  1143. hi_hash_dword = ntohl(common.dword);
  1144. /* low dword is word swapped version of common */
  1145. lo_hash_dword = (hi_hash_dword >> 16) | (hi_hash_dword << 16);
  1146. /* apply flow ID/VM pool/VLAN ID bits to hash words */
  1147. hi_hash_dword ^= flow_vm_vlan ^ (flow_vm_vlan >> 16);
  1148. /* Process bits 0 and 16 */
  1149. IXGBE_COMPUTE_SIG_HASH_ITERATION(0);
  1150. /*
  1151. * apply flow ID/VM pool/VLAN ID bits to lo hash dword, we had to
  1152. * delay this because bit 0 of the stream should not be processed
  1153. * so we do not add the vlan until after bit 0 was processed
  1154. */
  1155. lo_hash_dword ^= flow_vm_vlan ^ (flow_vm_vlan << 16);
  1156. /* Process remaining 30 bit of the key */
  1157. IXGBE_COMPUTE_SIG_HASH_ITERATION(1);
  1158. IXGBE_COMPUTE_SIG_HASH_ITERATION(2);
  1159. IXGBE_COMPUTE_SIG_HASH_ITERATION(3);
  1160. IXGBE_COMPUTE_SIG_HASH_ITERATION(4);
  1161. IXGBE_COMPUTE_SIG_HASH_ITERATION(5);
  1162. IXGBE_COMPUTE_SIG_HASH_ITERATION(6);
  1163. IXGBE_COMPUTE_SIG_HASH_ITERATION(7);
  1164. IXGBE_COMPUTE_SIG_HASH_ITERATION(8);
  1165. IXGBE_COMPUTE_SIG_HASH_ITERATION(9);
  1166. IXGBE_COMPUTE_SIG_HASH_ITERATION(10);
  1167. IXGBE_COMPUTE_SIG_HASH_ITERATION(11);
  1168. IXGBE_COMPUTE_SIG_HASH_ITERATION(12);
  1169. IXGBE_COMPUTE_SIG_HASH_ITERATION(13);
  1170. IXGBE_COMPUTE_SIG_HASH_ITERATION(14);
  1171. IXGBE_COMPUTE_SIG_HASH_ITERATION(15);
  1172. /* combine common_hash result with signature and bucket hashes */
  1173. bucket_hash ^= common_hash;
  1174. bucket_hash &= IXGBE_ATR_HASH_MASK;
  1175. sig_hash ^= common_hash << 16;
  1176. sig_hash &= IXGBE_ATR_HASH_MASK << 16;
  1177. /* return completed signature hash */
  1178. return sig_hash ^ bucket_hash;
  1179. }
  1180. /**
  1181. * ixgbe_atr_add_signature_filter_82599 - Adds a signature hash filter
  1182. * @hw: pointer to hardware structure
  1183. * @input: unique input dword
  1184. * @common: compressed common input dword
  1185. * @queue: queue index to direct traffic to
  1186. *
  1187. * Note that the tunnel bit in input must not be set when the hardware
  1188. * tunneling support does not exist.
  1189. **/
  1190. s32 ixgbe_fdir_add_signature_filter_82599(struct ixgbe_hw *hw,
  1191. union ixgbe_atr_hash_dword input,
  1192. union ixgbe_atr_hash_dword common,
  1193. u8 queue)
  1194. {
  1195. u64 fdirhashcmd;
  1196. u8 flow_type;
  1197. bool tunnel;
  1198. u32 fdircmd;
  1199. /*
  1200. * Get the flow_type in order to program FDIRCMD properly
  1201. * lowest 2 bits are FDIRCMD.L4TYPE, third lowest bit is FDIRCMD.IPV6
  1202. */
  1203. tunnel = !!(input.formatted.flow_type & IXGBE_ATR_L4TYPE_TUNNEL_MASK);
  1204. flow_type = input.formatted.flow_type &
  1205. (IXGBE_ATR_L4TYPE_TUNNEL_MASK - 1);
  1206. switch (flow_type) {
  1207. case IXGBE_ATR_FLOW_TYPE_TCPV4:
  1208. case IXGBE_ATR_FLOW_TYPE_UDPV4:
  1209. case IXGBE_ATR_FLOW_TYPE_SCTPV4:
  1210. case IXGBE_ATR_FLOW_TYPE_TCPV6:
  1211. case IXGBE_ATR_FLOW_TYPE_UDPV6:
  1212. case IXGBE_ATR_FLOW_TYPE_SCTPV6:
  1213. break;
  1214. default:
  1215. hw_dbg(hw, " Error on flow type input\n");
  1216. return IXGBE_ERR_CONFIG;
  1217. }
  1218. /* configure FDIRCMD register */
  1219. fdircmd = IXGBE_FDIRCMD_CMD_ADD_FLOW | IXGBE_FDIRCMD_FILTER_UPDATE |
  1220. IXGBE_FDIRCMD_LAST | IXGBE_FDIRCMD_QUEUE_EN;
  1221. fdircmd |= (u32)flow_type << IXGBE_FDIRCMD_FLOW_TYPE_SHIFT;
  1222. fdircmd |= (u32)queue << IXGBE_FDIRCMD_RX_QUEUE_SHIFT;
  1223. if (tunnel)
  1224. fdircmd |= IXGBE_FDIRCMD_TUNNEL_FILTER;
  1225. /*
  1226. * The lower 32-bits of fdirhashcmd is for FDIRHASH, the upper 32-bits
  1227. * is for FDIRCMD. Then do a 64-bit register write from FDIRHASH.
  1228. */
  1229. fdirhashcmd = (u64)fdircmd << 32;
  1230. fdirhashcmd |= ixgbe_atr_compute_sig_hash_82599(input, common);
  1231. IXGBE_WRITE_REG64(hw, IXGBE_FDIRHASH, fdirhashcmd);
  1232. hw_dbg(hw, "Tx Queue=%x hash=%x\n", queue, (u32)fdirhashcmd);
  1233. return 0;
  1234. }
  1235. #define IXGBE_COMPUTE_BKT_HASH_ITERATION(_n) \
  1236. do { \
  1237. u32 n = (_n); \
  1238. if (IXGBE_ATR_BUCKET_HASH_KEY & (0x01 << n)) \
  1239. bucket_hash ^= lo_hash_dword >> n; \
  1240. if (IXGBE_ATR_BUCKET_HASH_KEY & (0x01 << (n + 16))) \
  1241. bucket_hash ^= hi_hash_dword >> n; \
  1242. } while (0)
  1243. /**
  1244. * ixgbe_atr_compute_perfect_hash_82599 - Compute the perfect filter hash
  1245. * @atr_input: input bitstream to compute the hash on
  1246. * @input_mask: mask for the input bitstream
  1247. *
  1248. * This function serves two main purposes. First it applys the input_mask
  1249. * to the atr_input resulting in a cleaned up atr_input data stream.
  1250. * Secondly it computes the hash and stores it in the bkt_hash field at
  1251. * the end of the input byte stream. This way it will be available for
  1252. * future use without needing to recompute the hash.
  1253. **/
  1254. void ixgbe_atr_compute_perfect_hash_82599(union ixgbe_atr_input *input,
  1255. union ixgbe_atr_input *input_mask)
  1256. {
  1257. u32 hi_hash_dword, lo_hash_dword, flow_vm_vlan;
  1258. u32 bucket_hash = 0, hi_dword = 0;
  1259. int i;
  1260. /* Apply masks to input data */
  1261. for (i = 0; i <= 10; i++)
  1262. input->dword_stream[i] &= input_mask->dword_stream[i];
  1263. /* record the flow_vm_vlan bits as they are a key part to the hash */
  1264. flow_vm_vlan = ntohl(input->dword_stream[0]);
  1265. /* generate common hash dword */
  1266. for (i = 1; i <= 10; i++)
  1267. hi_dword ^= input->dword_stream[i];
  1268. hi_hash_dword = ntohl(hi_dword);
  1269. /* low dword is word swapped version of common */
  1270. lo_hash_dword = (hi_hash_dword >> 16) | (hi_hash_dword << 16);
  1271. /* apply flow ID/VM pool/VLAN ID bits to hash words */
  1272. hi_hash_dword ^= flow_vm_vlan ^ (flow_vm_vlan >> 16);
  1273. /* Process bits 0 and 16 */
  1274. IXGBE_COMPUTE_BKT_HASH_ITERATION(0);
  1275. /*
  1276. * apply flow ID/VM pool/VLAN ID bits to lo hash dword, we had to
  1277. * delay this because bit 0 of the stream should not be processed
  1278. * so we do not add the vlan until after bit 0 was processed
  1279. */
  1280. lo_hash_dword ^= flow_vm_vlan ^ (flow_vm_vlan << 16);
  1281. /* Process remaining 30 bit of the key */
  1282. for (i = 1; i <= 15; i++)
  1283. IXGBE_COMPUTE_BKT_HASH_ITERATION(i);
  1284. /*
  1285. * Limit hash to 13 bits since max bucket count is 8K.
  1286. * Store result at the end of the input stream.
  1287. */
  1288. input->formatted.bkt_hash = bucket_hash & 0x1FFF;
  1289. }
  1290. /**
  1291. * ixgbe_get_fdirtcpm_82599 - generate a tcp port from atr_input_masks
  1292. * @input_mask: mask to be bit swapped
  1293. *
  1294. * The source and destination port masks for flow director are bit swapped
  1295. * in that bit 15 effects bit 0, 14 effects 1, 13, 2 etc. In order to
  1296. * generate a correctly swapped value we need to bit swap the mask and that
  1297. * is what is accomplished by this function.
  1298. **/
  1299. static u32 ixgbe_get_fdirtcpm_82599(union ixgbe_atr_input *input_mask)
  1300. {
  1301. u32 mask = ntohs(input_mask->formatted.dst_port);
  1302. mask <<= IXGBE_FDIRTCPM_DPORTM_SHIFT;
  1303. mask |= ntohs(input_mask->formatted.src_port);
  1304. mask = ((mask & 0x55555555) << 1) | ((mask & 0xAAAAAAAA) >> 1);
  1305. mask = ((mask & 0x33333333) << 2) | ((mask & 0xCCCCCCCC) >> 2);
  1306. mask = ((mask & 0x0F0F0F0F) << 4) | ((mask & 0xF0F0F0F0) >> 4);
  1307. return ((mask & 0x00FF00FF) << 8) | ((mask & 0xFF00FF00) >> 8);
  1308. }
  1309. /*
  1310. * These two macros are meant to address the fact that we have registers
  1311. * that are either all or in part big-endian. As a result on big-endian
  1312. * systems we will end up byte swapping the value to little-endian before
  1313. * it is byte swapped again and written to the hardware in the original
  1314. * big-endian format.
  1315. */
  1316. #define IXGBE_STORE_AS_BE32(_value) \
  1317. (((u32)(_value) >> 24) | (((u32)(_value) & 0x00FF0000) >> 8) | \
  1318. (((u32)(_value) & 0x0000FF00) << 8) | ((u32)(_value) << 24))
  1319. #define IXGBE_WRITE_REG_BE32(a, reg, value) \
  1320. IXGBE_WRITE_REG((a), (reg), IXGBE_STORE_AS_BE32(ntohl(value)))
  1321. #define IXGBE_STORE_AS_BE16(_value) \
  1322. ntohs(((u16)(_value) >> 8) | ((u16)(_value) << 8))
  1323. s32 ixgbe_fdir_set_input_mask_82599(struct ixgbe_hw *hw,
  1324. union ixgbe_atr_input *input_mask)
  1325. {
  1326. /* mask IPv6 since it is currently not supported */
  1327. u32 fdirm = IXGBE_FDIRM_DIPv6;
  1328. u32 fdirtcpm;
  1329. /*
  1330. * Program the relevant mask registers. If src/dst_port or src/dst_addr
  1331. * are zero, then assume a full mask for that field. Also assume that
  1332. * a VLAN of 0 is unspecified, so mask that out as well. L4type
  1333. * cannot be masked out in this implementation.
  1334. *
  1335. * This also assumes IPv4 only. IPv6 masking isn't supported at this
  1336. * point in time.
  1337. */
  1338. /* verify bucket hash is cleared on hash generation */
  1339. if (input_mask->formatted.bkt_hash)
  1340. hw_dbg(hw, " bucket hash should always be 0 in mask\n");
  1341. /* Program FDIRM and verify partial masks */
  1342. switch (input_mask->formatted.vm_pool & 0x7F) {
  1343. case 0x0:
  1344. fdirm |= IXGBE_FDIRM_POOL;
  1345. case 0x7F:
  1346. break;
  1347. default:
  1348. hw_dbg(hw, " Error on vm pool mask\n");
  1349. return IXGBE_ERR_CONFIG;
  1350. }
  1351. switch (input_mask->formatted.flow_type & IXGBE_ATR_L4TYPE_MASK) {
  1352. case 0x0:
  1353. fdirm |= IXGBE_FDIRM_L4P;
  1354. if (input_mask->formatted.dst_port ||
  1355. input_mask->formatted.src_port) {
  1356. hw_dbg(hw, " Error on src/dst port mask\n");
  1357. return IXGBE_ERR_CONFIG;
  1358. }
  1359. case IXGBE_ATR_L4TYPE_MASK:
  1360. break;
  1361. default:
  1362. hw_dbg(hw, " Error on flow type mask\n");
  1363. return IXGBE_ERR_CONFIG;
  1364. }
  1365. switch (ntohs(input_mask->formatted.vlan_id) & 0xEFFF) {
  1366. case 0x0000:
  1367. /* mask VLAN ID, fall through to mask VLAN priority */
  1368. fdirm |= IXGBE_FDIRM_VLANID;
  1369. case 0x0FFF:
  1370. /* mask VLAN priority */
  1371. fdirm |= IXGBE_FDIRM_VLANP;
  1372. break;
  1373. case 0xE000:
  1374. /* mask VLAN ID only, fall through */
  1375. fdirm |= IXGBE_FDIRM_VLANID;
  1376. case 0xEFFF:
  1377. /* no VLAN fields masked */
  1378. break;
  1379. default:
  1380. hw_dbg(hw, " Error on VLAN mask\n");
  1381. return IXGBE_ERR_CONFIG;
  1382. }
  1383. switch (input_mask->formatted.flex_bytes & 0xFFFF) {
  1384. case 0x0000:
  1385. /* Mask Flex Bytes, fall through */
  1386. fdirm |= IXGBE_FDIRM_FLEX;
  1387. case 0xFFFF:
  1388. break;
  1389. default:
  1390. hw_dbg(hw, " Error on flexible byte mask\n");
  1391. return IXGBE_ERR_CONFIG;
  1392. }
  1393. /* Now mask VM pool and destination IPv6 - bits 5 and 2 */
  1394. IXGBE_WRITE_REG(hw, IXGBE_FDIRM, fdirm);
  1395. /* store the TCP/UDP port masks, bit reversed from port layout */
  1396. fdirtcpm = ixgbe_get_fdirtcpm_82599(input_mask);
  1397. /* write both the same so that UDP and TCP use the same mask */
  1398. IXGBE_WRITE_REG(hw, IXGBE_FDIRTCPM, ~fdirtcpm);
  1399. IXGBE_WRITE_REG(hw, IXGBE_FDIRUDPM, ~fdirtcpm);
  1400. /* also use it for SCTP */
  1401. switch (hw->mac.type) {
  1402. case ixgbe_mac_X550:
  1403. case ixgbe_mac_X550EM_x:
  1404. IXGBE_WRITE_REG(hw, IXGBE_FDIRSCTPM, ~fdirtcpm);
  1405. break;
  1406. default:
  1407. break;
  1408. }
  1409. /* store source and destination IP masks (big-enian) */
  1410. IXGBE_WRITE_REG_BE32(hw, IXGBE_FDIRSIP4M,
  1411. ~input_mask->formatted.src_ip[0]);
  1412. IXGBE_WRITE_REG_BE32(hw, IXGBE_FDIRDIP4M,
  1413. ~input_mask->formatted.dst_ip[0]);
  1414. return 0;
  1415. }
  1416. s32 ixgbe_fdir_write_perfect_filter_82599(struct ixgbe_hw *hw,
  1417. union ixgbe_atr_input *input,
  1418. u16 soft_id, u8 queue)
  1419. {
  1420. u32 fdirport, fdirvlan, fdirhash, fdircmd;
  1421. s32 err;
  1422. /* currently IPv6 is not supported, must be programmed with 0 */
  1423. IXGBE_WRITE_REG_BE32(hw, IXGBE_FDIRSIPv6(0),
  1424. input->formatted.src_ip[0]);
  1425. IXGBE_WRITE_REG_BE32(hw, IXGBE_FDIRSIPv6(1),
  1426. input->formatted.src_ip[1]);
  1427. IXGBE_WRITE_REG_BE32(hw, IXGBE_FDIRSIPv6(2),
  1428. input->formatted.src_ip[2]);
  1429. /* record the source address (big-endian) */
  1430. IXGBE_WRITE_REG_BE32(hw, IXGBE_FDIRIPSA, input->formatted.src_ip[0]);
  1431. /* record the first 32 bits of the destination address (big-endian) */
  1432. IXGBE_WRITE_REG_BE32(hw, IXGBE_FDIRIPDA, input->formatted.dst_ip[0]);
  1433. /* record source and destination port (little-endian)*/
  1434. fdirport = ntohs(input->formatted.dst_port);
  1435. fdirport <<= IXGBE_FDIRPORT_DESTINATION_SHIFT;
  1436. fdirport |= ntohs(input->formatted.src_port);
  1437. IXGBE_WRITE_REG(hw, IXGBE_FDIRPORT, fdirport);
  1438. /* record vlan (little-endian) and flex_bytes(big-endian) */
  1439. fdirvlan = IXGBE_STORE_AS_BE16(input->formatted.flex_bytes);
  1440. fdirvlan <<= IXGBE_FDIRVLAN_FLEX_SHIFT;
  1441. fdirvlan |= ntohs(input->formatted.vlan_id);
  1442. IXGBE_WRITE_REG(hw, IXGBE_FDIRVLAN, fdirvlan);
  1443. /* configure FDIRHASH register */
  1444. fdirhash = input->formatted.bkt_hash;
  1445. fdirhash |= soft_id << IXGBE_FDIRHASH_SIG_SW_INDEX_SHIFT;
  1446. IXGBE_WRITE_REG(hw, IXGBE_FDIRHASH, fdirhash);
  1447. /*
  1448. * flush all previous writes to make certain registers are
  1449. * programmed prior to issuing the command
  1450. */
  1451. IXGBE_WRITE_FLUSH(hw);
  1452. /* configure FDIRCMD register */
  1453. fdircmd = IXGBE_FDIRCMD_CMD_ADD_FLOW | IXGBE_FDIRCMD_FILTER_UPDATE |
  1454. IXGBE_FDIRCMD_LAST | IXGBE_FDIRCMD_QUEUE_EN;
  1455. if (queue == IXGBE_FDIR_DROP_QUEUE)
  1456. fdircmd |= IXGBE_FDIRCMD_DROP;
  1457. fdircmd |= input->formatted.flow_type << IXGBE_FDIRCMD_FLOW_TYPE_SHIFT;
  1458. fdircmd |= (u32)queue << IXGBE_FDIRCMD_RX_QUEUE_SHIFT;
  1459. fdircmd |= (u32)input->formatted.vm_pool << IXGBE_FDIRCMD_VT_POOL_SHIFT;
  1460. IXGBE_WRITE_REG(hw, IXGBE_FDIRCMD, fdircmd);
  1461. err = ixgbe_fdir_check_cmd_complete(hw, &fdircmd);
  1462. if (err) {
  1463. hw_dbg(hw, "Flow Director command did not complete!\n");
  1464. return err;
  1465. }
  1466. return 0;
  1467. }
  1468. s32 ixgbe_fdir_erase_perfect_filter_82599(struct ixgbe_hw *hw,
  1469. union ixgbe_atr_input *input,
  1470. u16 soft_id)
  1471. {
  1472. u32 fdirhash;
  1473. u32 fdircmd;
  1474. s32 err;
  1475. /* configure FDIRHASH register */
  1476. fdirhash = input->formatted.bkt_hash;
  1477. fdirhash |= soft_id << IXGBE_FDIRHASH_SIG_SW_INDEX_SHIFT;
  1478. IXGBE_WRITE_REG(hw, IXGBE_FDIRHASH, fdirhash);
  1479. /* flush hash to HW */
  1480. IXGBE_WRITE_FLUSH(hw);
  1481. /* Query if filter is present */
  1482. IXGBE_WRITE_REG(hw, IXGBE_FDIRCMD, IXGBE_FDIRCMD_CMD_QUERY_REM_FILT);
  1483. err = ixgbe_fdir_check_cmd_complete(hw, &fdircmd);
  1484. if (err) {
  1485. hw_dbg(hw, "Flow Director command did not complete!\n");
  1486. return err;
  1487. }
  1488. /* if filter exists in hardware then remove it */
  1489. if (fdircmd & IXGBE_FDIRCMD_FILTER_VALID) {
  1490. IXGBE_WRITE_REG(hw, IXGBE_FDIRHASH, fdirhash);
  1491. IXGBE_WRITE_FLUSH(hw);
  1492. IXGBE_WRITE_REG(hw, IXGBE_FDIRCMD,
  1493. IXGBE_FDIRCMD_CMD_REMOVE_FLOW);
  1494. }
  1495. return 0;
  1496. }
  1497. /**
  1498. * ixgbe_read_analog_reg8_82599 - Reads 8 bit Omer analog register
  1499. * @hw: pointer to hardware structure
  1500. * @reg: analog register to read
  1501. * @val: read value
  1502. *
  1503. * Performs read operation to Omer analog register specified.
  1504. **/
  1505. static s32 ixgbe_read_analog_reg8_82599(struct ixgbe_hw *hw, u32 reg, u8 *val)
  1506. {
  1507. u32 core_ctl;
  1508. IXGBE_WRITE_REG(hw, IXGBE_CORECTL, IXGBE_CORECTL_WRITE_CMD |
  1509. (reg << 8));
  1510. IXGBE_WRITE_FLUSH(hw);
  1511. udelay(10);
  1512. core_ctl = IXGBE_READ_REG(hw, IXGBE_CORECTL);
  1513. *val = (u8)core_ctl;
  1514. return 0;
  1515. }
  1516. /**
  1517. * ixgbe_write_analog_reg8_82599 - Writes 8 bit Omer analog register
  1518. * @hw: pointer to hardware structure
  1519. * @reg: atlas register to write
  1520. * @val: value to write
  1521. *
  1522. * Performs write operation to Omer analog register specified.
  1523. **/
  1524. static s32 ixgbe_write_analog_reg8_82599(struct ixgbe_hw *hw, u32 reg, u8 val)
  1525. {
  1526. u32 core_ctl;
  1527. core_ctl = (reg << 8) | val;
  1528. IXGBE_WRITE_REG(hw, IXGBE_CORECTL, core_ctl);
  1529. IXGBE_WRITE_FLUSH(hw);
  1530. udelay(10);
  1531. return 0;
  1532. }
  1533. /**
  1534. * ixgbe_start_hw_82599 - Prepare hardware for Tx/Rx
  1535. * @hw: pointer to hardware structure
  1536. *
  1537. * Starts the hardware using the generic start_hw function
  1538. * and the generation start_hw function.
  1539. * Then performs revision-specific operations, if any.
  1540. **/
  1541. static s32 ixgbe_start_hw_82599(struct ixgbe_hw *hw)
  1542. {
  1543. s32 ret_val = 0;
  1544. ret_val = ixgbe_start_hw_generic(hw);
  1545. if (ret_val)
  1546. return ret_val;
  1547. ret_val = ixgbe_start_hw_gen2(hw);
  1548. if (ret_val)
  1549. return ret_val;
  1550. /* We need to run link autotry after the driver loads */
  1551. hw->mac.autotry_restart = true;
  1552. if (ret_val)
  1553. return ret_val;
  1554. return ixgbe_verify_fw_version_82599(hw);
  1555. }
  1556. /**
  1557. * ixgbe_identify_phy_82599 - Get physical layer module
  1558. * @hw: pointer to hardware structure
  1559. *
  1560. * Determines the physical layer module found on the current adapter.
  1561. * If PHY already detected, maintains current PHY type in hw struct,
  1562. * otherwise executes the PHY detection routine.
  1563. **/
  1564. static s32 ixgbe_identify_phy_82599(struct ixgbe_hw *hw)
  1565. {
  1566. s32 status;
  1567. /* Detect PHY if not unknown - returns success if already detected. */
  1568. status = ixgbe_identify_phy_generic(hw);
  1569. if (status) {
  1570. /* 82599 10GBASE-T requires an external PHY */
  1571. if (hw->mac.ops.get_media_type(hw) == ixgbe_media_type_copper)
  1572. return status;
  1573. status = ixgbe_identify_module_generic(hw);
  1574. }
  1575. /* Set PHY type none if no PHY detected */
  1576. if (hw->phy.type == ixgbe_phy_unknown) {
  1577. hw->phy.type = ixgbe_phy_none;
  1578. status = 0;
  1579. }
  1580. /* Return error if SFP module has been detected but is not supported */
  1581. if (hw->phy.type == ixgbe_phy_sfp_unsupported)
  1582. return IXGBE_ERR_SFP_NOT_SUPPORTED;
  1583. return status;
  1584. }
  1585. /**
  1586. * ixgbe_enable_rx_dma_82599 - Enable the Rx DMA unit on 82599
  1587. * @hw: pointer to hardware structure
  1588. * @regval: register value to write to RXCTRL
  1589. *
  1590. * Enables the Rx DMA unit for 82599
  1591. **/
  1592. static s32 ixgbe_enable_rx_dma_82599(struct ixgbe_hw *hw, u32 regval)
  1593. {
  1594. /*
  1595. * Workaround for 82599 silicon errata when enabling the Rx datapath.
  1596. * If traffic is incoming before we enable the Rx unit, it could hang
  1597. * the Rx DMA unit. Therefore, make sure the security engine is
  1598. * completely disabled prior to enabling the Rx unit.
  1599. */
  1600. hw->mac.ops.disable_rx_buff(hw);
  1601. if (regval & IXGBE_RXCTRL_RXEN)
  1602. hw->mac.ops.enable_rx(hw);
  1603. else
  1604. hw->mac.ops.disable_rx(hw);
  1605. hw->mac.ops.enable_rx_buff(hw);
  1606. return 0;
  1607. }
  1608. /**
  1609. * ixgbe_verify_fw_version_82599 - verify fw version for 82599
  1610. * @hw: pointer to hardware structure
  1611. *
  1612. * Verifies that installed the firmware version is 0.6 or higher
  1613. * for SFI devices. All 82599 SFI devices should have version 0.6 or higher.
  1614. *
  1615. * Returns IXGBE_ERR_EEPROM_VERSION if the FW is not present or
  1616. * if the FW version is not supported.
  1617. **/
  1618. static s32 ixgbe_verify_fw_version_82599(struct ixgbe_hw *hw)
  1619. {
  1620. s32 status = IXGBE_ERR_EEPROM_VERSION;
  1621. u16 fw_offset, fw_ptp_cfg_offset;
  1622. u16 offset;
  1623. u16 fw_version = 0;
  1624. /* firmware check is only necessary for SFI devices */
  1625. if (hw->phy.media_type != ixgbe_media_type_fiber)
  1626. return 0;
  1627. /* get the offset to the Firmware Module block */
  1628. offset = IXGBE_FW_PTR;
  1629. if (hw->eeprom.ops.read(hw, offset, &fw_offset))
  1630. goto fw_version_err;
  1631. if (fw_offset == 0 || fw_offset == 0xFFFF)
  1632. return IXGBE_ERR_EEPROM_VERSION;
  1633. /* get the offset to the Pass Through Patch Configuration block */
  1634. offset = fw_offset + IXGBE_FW_PASSTHROUGH_PATCH_CONFIG_PTR;
  1635. if (hw->eeprom.ops.read(hw, offset, &fw_ptp_cfg_offset))
  1636. goto fw_version_err;
  1637. if (fw_ptp_cfg_offset == 0 || fw_ptp_cfg_offset == 0xFFFF)
  1638. return IXGBE_ERR_EEPROM_VERSION;
  1639. /* get the firmware version */
  1640. offset = fw_ptp_cfg_offset + IXGBE_FW_PATCH_VERSION_4;
  1641. if (hw->eeprom.ops.read(hw, offset, &fw_version))
  1642. goto fw_version_err;
  1643. if (fw_version > 0x5)
  1644. status = 0;
  1645. return status;
  1646. fw_version_err:
  1647. hw_err(hw, "eeprom read at offset %d failed\n", offset);
  1648. return IXGBE_ERR_EEPROM_VERSION;
  1649. }
  1650. /**
  1651. * ixgbe_verify_lesm_fw_enabled_82599 - Checks LESM FW module state.
  1652. * @hw: pointer to hardware structure
  1653. *
  1654. * Returns true if the LESM FW module is present and enabled. Otherwise
  1655. * returns false. Smart Speed must be disabled if LESM FW module is enabled.
  1656. **/
  1657. static bool ixgbe_verify_lesm_fw_enabled_82599(struct ixgbe_hw *hw)
  1658. {
  1659. u16 fw_offset, fw_lesm_param_offset, fw_lesm_state;
  1660. s32 status;
  1661. /* get the offset to the Firmware Module block */
  1662. status = hw->eeprom.ops.read(hw, IXGBE_FW_PTR, &fw_offset);
  1663. if (status || fw_offset == 0 || fw_offset == 0xFFFF)
  1664. return false;
  1665. /* get the offset to the LESM Parameters block */
  1666. status = hw->eeprom.ops.read(hw, (fw_offset +
  1667. IXGBE_FW_LESM_PARAMETERS_PTR),
  1668. &fw_lesm_param_offset);
  1669. if (status ||
  1670. fw_lesm_param_offset == 0 || fw_lesm_param_offset == 0xFFFF)
  1671. return false;
  1672. /* get the lesm state word */
  1673. status = hw->eeprom.ops.read(hw, (fw_lesm_param_offset +
  1674. IXGBE_FW_LESM_STATE_1),
  1675. &fw_lesm_state);
  1676. if (!status && (fw_lesm_state & IXGBE_FW_LESM_STATE_ENABLED))
  1677. return true;
  1678. return false;
  1679. }
  1680. /**
  1681. * ixgbe_read_eeprom_buffer_82599 - Read EEPROM word(s) using
  1682. * fastest available method
  1683. *
  1684. * @hw: pointer to hardware structure
  1685. * @offset: offset of word in EEPROM to read
  1686. * @words: number of words
  1687. * @data: word(s) read from the EEPROM
  1688. *
  1689. * Retrieves 16 bit word(s) read from EEPROM
  1690. **/
  1691. static s32 ixgbe_read_eeprom_buffer_82599(struct ixgbe_hw *hw, u16 offset,
  1692. u16 words, u16 *data)
  1693. {
  1694. struct ixgbe_eeprom_info *eeprom = &hw->eeprom;
  1695. /* If EEPROM is detected and can be addressed using 14 bits,
  1696. * use EERD otherwise use bit bang
  1697. */
  1698. if (eeprom->type == ixgbe_eeprom_spi &&
  1699. offset + (words - 1) <= IXGBE_EERD_MAX_ADDR)
  1700. return ixgbe_read_eerd_buffer_generic(hw, offset, words, data);
  1701. return ixgbe_read_eeprom_buffer_bit_bang_generic(hw, offset, words,
  1702. data);
  1703. }
  1704. /**
  1705. * ixgbe_read_eeprom_82599 - Read EEPROM word using
  1706. * fastest available method
  1707. *
  1708. * @hw: pointer to hardware structure
  1709. * @offset: offset of word in the EEPROM to read
  1710. * @data: word read from the EEPROM
  1711. *
  1712. * Reads a 16 bit word from the EEPROM
  1713. **/
  1714. static s32 ixgbe_read_eeprom_82599(struct ixgbe_hw *hw,
  1715. u16 offset, u16 *data)
  1716. {
  1717. struct ixgbe_eeprom_info *eeprom = &hw->eeprom;
  1718. /*
  1719. * If EEPROM is detected and can be addressed using 14 bits,
  1720. * use EERD otherwise use bit bang
  1721. */
  1722. if (eeprom->type == ixgbe_eeprom_spi && offset <= IXGBE_EERD_MAX_ADDR)
  1723. return ixgbe_read_eerd_generic(hw, offset, data);
  1724. return ixgbe_read_eeprom_bit_bang_generic(hw, offset, data);
  1725. }
  1726. /**
  1727. * ixgbe_reset_pipeline_82599 - perform pipeline reset
  1728. *
  1729. * @hw: pointer to hardware structure
  1730. *
  1731. * Reset pipeline by asserting Restart_AN together with LMS change to ensure
  1732. * full pipeline reset. Note - We must hold the SW/FW semaphore before writing
  1733. * to AUTOC, so this function assumes the semaphore is held.
  1734. **/
  1735. static s32 ixgbe_reset_pipeline_82599(struct ixgbe_hw *hw)
  1736. {
  1737. s32 ret_val;
  1738. u32 anlp1_reg = 0;
  1739. u32 i, autoc_reg, autoc2_reg;
  1740. /* Enable link if disabled in NVM */
  1741. autoc2_reg = IXGBE_READ_REG(hw, IXGBE_AUTOC2);
  1742. if (autoc2_reg & IXGBE_AUTOC2_LINK_DISABLE_MASK) {
  1743. autoc2_reg &= ~IXGBE_AUTOC2_LINK_DISABLE_MASK;
  1744. IXGBE_WRITE_REG(hw, IXGBE_AUTOC2, autoc2_reg);
  1745. IXGBE_WRITE_FLUSH(hw);
  1746. }
  1747. autoc_reg = IXGBE_READ_REG(hw, IXGBE_AUTOC);
  1748. autoc_reg |= IXGBE_AUTOC_AN_RESTART;
  1749. /* Write AUTOC register with toggled LMS[2] bit and Restart_AN */
  1750. IXGBE_WRITE_REG(hw, IXGBE_AUTOC,
  1751. autoc_reg ^ (0x4 << IXGBE_AUTOC_LMS_SHIFT));
  1752. /* Wait for AN to leave state 0 */
  1753. for (i = 0; i < 10; i++) {
  1754. usleep_range(4000, 8000);
  1755. anlp1_reg = IXGBE_READ_REG(hw, IXGBE_ANLP1);
  1756. if (anlp1_reg & IXGBE_ANLP1_AN_STATE_MASK)
  1757. break;
  1758. }
  1759. if (!(anlp1_reg & IXGBE_ANLP1_AN_STATE_MASK)) {
  1760. hw_dbg(hw, "auto negotiation not completed\n");
  1761. ret_val = IXGBE_ERR_RESET_FAILED;
  1762. goto reset_pipeline_out;
  1763. }
  1764. ret_val = 0;
  1765. reset_pipeline_out:
  1766. /* Write AUTOC register with original LMS field and Restart_AN */
  1767. IXGBE_WRITE_REG(hw, IXGBE_AUTOC, autoc_reg);
  1768. IXGBE_WRITE_FLUSH(hw);
  1769. return ret_val;
  1770. }
  1771. /**
  1772. * ixgbe_read_i2c_byte_82599 - Reads 8 bit word over I2C
  1773. * @hw: pointer to hardware structure
  1774. * @byte_offset: byte offset to read
  1775. * @data: value read
  1776. *
  1777. * Performs byte read operation to SFP module's EEPROM over I2C interface at
  1778. * a specified device address.
  1779. **/
  1780. static s32 ixgbe_read_i2c_byte_82599(struct ixgbe_hw *hw, u8 byte_offset,
  1781. u8 dev_addr, u8 *data)
  1782. {
  1783. u32 esdp;
  1784. s32 status;
  1785. s32 timeout = 200;
  1786. if (hw->phy.qsfp_shared_i2c_bus == true) {
  1787. /* Acquire I2C bus ownership. */
  1788. esdp = IXGBE_READ_REG(hw, IXGBE_ESDP);
  1789. esdp |= IXGBE_ESDP_SDP0;
  1790. IXGBE_WRITE_REG(hw, IXGBE_ESDP, esdp);
  1791. IXGBE_WRITE_FLUSH(hw);
  1792. while (timeout) {
  1793. esdp = IXGBE_READ_REG(hw, IXGBE_ESDP);
  1794. if (esdp & IXGBE_ESDP_SDP1)
  1795. break;
  1796. usleep_range(5000, 10000);
  1797. timeout--;
  1798. }
  1799. if (!timeout) {
  1800. hw_dbg(hw, "Driver can't access resource, acquiring I2C bus timeout.\n");
  1801. status = IXGBE_ERR_I2C;
  1802. goto release_i2c_access;
  1803. }
  1804. }
  1805. status = ixgbe_read_i2c_byte_generic(hw, byte_offset, dev_addr, data);
  1806. release_i2c_access:
  1807. if (hw->phy.qsfp_shared_i2c_bus == true) {
  1808. /* Release I2C bus ownership. */
  1809. esdp = IXGBE_READ_REG(hw, IXGBE_ESDP);
  1810. esdp &= ~IXGBE_ESDP_SDP0;
  1811. IXGBE_WRITE_REG(hw, IXGBE_ESDP, esdp);
  1812. IXGBE_WRITE_FLUSH(hw);
  1813. }
  1814. return status;
  1815. }
  1816. /**
  1817. * ixgbe_write_i2c_byte_82599 - Writes 8 bit word over I2C
  1818. * @hw: pointer to hardware structure
  1819. * @byte_offset: byte offset to write
  1820. * @data: value to write
  1821. *
  1822. * Performs byte write operation to SFP module's EEPROM over I2C interface at
  1823. * a specified device address.
  1824. **/
  1825. static s32 ixgbe_write_i2c_byte_82599(struct ixgbe_hw *hw, u8 byte_offset,
  1826. u8 dev_addr, u8 data)
  1827. {
  1828. u32 esdp;
  1829. s32 status;
  1830. s32 timeout = 200;
  1831. if (hw->phy.qsfp_shared_i2c_bus == true) {
  1832. /* Acquire I2C bus ownership. */
  1833. esdp = IXGBE_READ_REG(hw, IXGBE_ESDP);
  1834. esdp |= IXGBE_ESDP_SDP0;
  1835. IXGBE_WRITE_REG(hw, IXGBE_ESDP, esdp);
  1836. IXGBE_WRITE_FLUSH(hw);
  1837. while (timeout) {
  1838. esdp = IXGBE_READ_REG(hw, IXGBE_ESDP);
  1839. if (esdp & IXGBE_ESDP_SDP1)
  1840. break;
  1841. usleep_range(5000, 10000);
  1842. timeout--;
  1843. }
  1844. if (!timeout) {
  1845. hw_dbg(hw, "Driver can't access resource, acquiring I2C bus timeout.\n");
  1846. status = IXGBE_ERR_I2C;
  1847. goto release_i2c_access;
  1848. }
  1849. }
  1850. status = ixgbe_write_i2c_byte_generic(hw, byte_offset, dev_addr, data);
  1851. release_i2c_access:
  1852. if (hw->phy.qsfp_shared_i2c_bus == true) {
  1853. /* Release I2C bus ownership. */
  1854. esdp = IXGBE_READ_REG(hw, IXGBE_ESDP);
  1855. esdp &= ~IXGBE_ESDP_SDP0;
  1856. IXGBE_WRITE_REG(hw, IXGBE_ESDP, esdp);
  1857. IXGBE_WRITE_FLUSH(hw);
  1858. }
  1859. return status;
  1860. }
  1861. static struct ixgbe_mac_operations mac_ops_82599 = {
  1862. .init_hw = &ixgbe_init_hw_generic,
  1863. .reset_hw = &ixgbe_reset_hw_82599,
  1864. .start_hw = &ixgbe_start_hw_82599,
  1865. .clear_hw_cntrs = &ixgbe_clear_hw_cntrs_generic,
  1866. .get_media_type = &ixgbe_get_media_type_82599,
  1867. .enable_rx_dma = &ixgbe_enable_rx_dma_82599,
  1868. .disable_rx_buff = &ixgbe_disable_rx_buff_generic,
  1869. .enable_rx_buff = &ixgbe_enable_rx_buff_generic,
  1870. .get_mac_addr = &ixgbe_get_mac_addr_generic,
  1871. .get_san_mac_addr = &ixgbe_get_san_mac_addr_generic,
  1872. .get_device_caps = &ixgbe_get_device_caps_generic,
  1873. .get_wwn_prefix = &ixgbe_get_wwn_prefix_generic,
  1874. .stop_adapter = &ixgbe_stop_adapter_generic,
  1875. .get_bus_info = &ixgbe_get_bus_info_generic,
  1876. .set_lan_id = &ixgbe_set_lan_id_multi_port_pcie,
  1877. .read_analog_reg8 = &ixgbe_read_analog_reg8_82599,
  1878. .write_analog_reg8 = &ixgbe_write_analog_reg8_82599,
  1879. .stop_link_on_d3 = &ixgbe_stop_mac_link_on_d3_82599,
  1880. .setup_link = &ixgbe_setup_mac_link_82599,
  1881. .set_rxpba = &ixgbe_set_rxpba_generic,
  1882. .check_link = &ixgbe_check_mac_link_generic,
  1883. .get_link_capabilities = &ixgbe_get_link_capabilities_82599,
  1884. .led_on = &ixgbe_led_on_generic,
  1885. .led_off = &ixgbe_led_off_generic,
  1886. .blink_led_start = &ixgbe_blink_led_start_generic,
  1887. .blink_led_stop = &ixgbe_blink_led_stop_generic,
  1888. .set_rar = &ixgbe_set_rar_generic,
  1889. .clear_rar = &ixgbe_clear_rar_generic,
  1890. .set_vmdq = &ixgbe_set_vmdq_generic,
  1891. .set_vmdq_san_mac = &ixgbe_set_vmdq_san_mac_generic,
  1892. .clear_vmdq = &ixgbe_clear_vmdq_generic,
  1893. .init_rx_addrs = &ixgbe_init_rx_addrs_generic,
  1894. .update_mc_addr_list = &ixgbe_update_mc_addr_list_generic,
  1895. .enable_mc = &ixgbe_enable_mc_generic,
  1896. .disable_mc = &ixgbe_disable_mc_generic,
  1897. .clear_vfta = &ixgbe_clear_vfta_generic,
  1898. .set_vfta = &ixgbe_set_vfta_generic,
  1899. .fc_enable = &ixgbe_fc_enable_generic,
  1900. .set_fw_drv_ver = &ixgbe_set_fw_drv_ver_generic,
  1901. .init_uta_tables = &ixgbe_init_uta_tables_generic,
  1902. .setup_sfp = &ixgbe_setup_sfp_modules_82599,
  1903. .set_mac_anti_spoofing = &ixgbe_set_mac_anti_spoofing,
  1904. .set_vlan_anti_spoofing = &ixgbe_set_vlan_anti_spoofing,
  1905. .acquire_swfw_sync = &ixgbe_acquire_swfw_sync,
  1906. .release_swfw_sync = &ixgbe_release_swfw_sync,
  1907. .get_thermal_sensor_data = &ixgbe_get_thermal_sensor_data_generic,
  1908. .init_thermal_sensor_thresh = &ixgbe_init_thermal_sensor_thresh_generic,
  1909. .prot_autoc_read = &prot_autoc_read_82599,
  1910. .prot_autoc_write = &prot_autoc_write_82599,
  1911. .enable_rx = &ixgbe_enable_rx_generic,
  1912. .disable_rx = &ixgbe_disable_rx_generic,
  1913. };
  1914. static struct ixgbe_eeprom_operations eeprom_ops_82599 = {
  1915. .init_params = &ixgbe_init_eeprom_params_generic,
  1916. .read = &ixgbe_read_eeprom_82599,
  1917. .read_buffer = &ixgbe_read_eeprom_buffer_82599,
  1918. .write = &ixgbe_write_eeprom_generic,
  1919. .write_buffer = &ixgbe_write_eeprom_buffer_bit_bang_generic,
  1920. .calc_checksum = &ixgbe_calc_eeprom_checksum_generic,
  1921. .validate_checksum = &ixgbe_validate_eeprom_checksum_generic,
  1922. .update_checksum = &ixgbe_update_eeprom_checksum_generic,
  1923. };
  1924. static struct ixgbe_phy_operations phy_ops_82599 = {
  1925. .identify = &ixgbe_identify_phy_82599,
  1926. .identify_sfp = &ixgbe_identify_module_generic,
  1927. .init = &ixgbe_init_phy_ops_82599,
  1928. .reset = &ixgbe_reset_phy_generic,
  1929. .read_reg = &ixgbe_read_phy_reg_generic,
  1930. .write_reg = &ixgbe_write_phy_reg_generic,
  1931. .setup_link = &ixgbe_setup_phy_link_generic,
  1932. .setup_link_speed = &ixgbe_setup_phy_link_speed_generic,
  1933. .read_i2c_byte = &ixgbe_read_i2c_byte_generic,
  1934. .write_i2c_byte = &ixgbe_write_i2c_byte_generic,
  1935. .read_i2c_sff8472 = &ixgbe_read_i2c_sff8472_generic,
  1936. .read_i2c_eeprom = &ixgbe_read_i2c_eeprom_generic,
  1937. .write_i2c_eeprom = &ixgbe_write_i2c_eeprom_generic,
  1938. .check_overtemp = &ixgbe_tn_check_overtemp,
  1939. };
  1940. struct ixgbe_info ixgbe_82599_info = {
  1941. .mac = ixgbe_mac_82599EB,
  1942. .get_invariants = &ixgbe_get_invariants_82599,
  1943. .mac_ops = &mac_ops_82599,
  1944. .eeprom_ops = &eeprom_ops_82599,
  1945. .phy_ops = &phy_ops_82599,
  1946. .mbx_ops = &mbx_ops_generic,
  1947. .mvals = ixgbe_mvals_8259X,
  1948. };