ixgbe_82599.c 69 KB

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