ixgbe_82599.c 67 KB

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