ixgbe_82599.c 68 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176
  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. hw->mac.ops.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.setup_link = &ixgbe_setup_phy_link_tnx;
  183. phy->ops.get_firmware_version =
  184. &ixgbe_get_phy_firmware_version_tnx;
  185. break;
  186. default:
  187. break;
  188. }
  189. return ret_val;
  190. }
  191. /**
  192. * ixgbe_get_link_capabilities_82599 - Determines link capabilities
  193. * @hw: pointer to hardware structure
  194. * @speed: pointer to link speed
  195. * @negotiation: true when autoneg or autotry is enabled
  196. *
  197. * Determines the link capabilities by reading the AUTOC register.
  198. **/
  199. static s32 ixgbe_get_link_capabilities_82599(struct ixgbe_hw *hw,
  200. ixgbe_link_speed *speed,
  201. bool *negotiation)
  202. {
  203. s32 status = 0;
  204. u32 autoc = 0;
  205. /* Determine 1G link capabilities off of SFP+ type */
  206. if (hw->phy.sfp_type == ixgbe_sfp_type_1g_cu_core0 ||
  207. hw->phy.sfp_type == ixgbe_sfp_type_1g_cu_core1) {
  208. *speed = IXGBE_LINK_SPEED_1GB_FULL;
  209. *negotiation = true;
  210. goto out;
  211. }
  212. /*
  213. * Determine link capabilities based on the stored value of AUTOC,
  214. * which represents EEPROM defaults. If AUTOC value has not been
  215. * stored, use the current register value.
  216. */
  217. if (hw->mac.orig_link_settings_stored)
  218. autoc = hw->mac.orig_autoc;
  219. else
  220. autoc = IXGBE_READ_REG(hw, IXGBE_AUTOC);
  221. switch (autoc & IXGBE_AUTOC_LMS_MASK) {
  222. case IXGBE_AUTOC_LMS_1G_LINK_NO_AN:
  223. *speed = IXGBE_LINK_SPEED_1GB_FULL;
  224. *negotiation = false;
  225. break;
  226. case IXGBE_AUTOC_LMS_10G_LINK_NO_AN:
  227. *speed = IXGBE_LINK_SPEED_10GB_FULL;
  228. *negotiation = false;
  229. break;
  230. case IXGBE_AUTOC_LMS_1G_AN:
  231. *speed = IXGBE_LINK_SPEED_1GB_FULL;
  232. *negotiation = true;
  233. break;
  234. case IXGBE_AUTOC_LMS_10G_SERIAL:
  235. *speed = IXGBE_LINK_SPEED_10GB_FULL;
  236. *negotiation = false;
  237. break;
  238. case IXGBE_AUTOC_LMS_KX4_KX_KR:
  239. case IXGBE_AUTOC_LMS_KX4_KX_KR_1G_AN:
  240. *speed = IXGBE_LINK_SPEED_UNKNOWN;
  241. if (autoc & IXGBE_AUTOC_KR_SUPP)
  242. *speed |= IXGBE_LINK_SPEED_10GB_FULL;
  243. if (autoc & IXGBE_AUTOC_KX4_SUPP)
  244. *speed |= IXGBE_LINK_SPEED_10GB_FULL;
  245. if (autoc & IXGBE_AUTOC_KX_SUPP)
  246. *speed |= IXGBE_LINK_SPEED_1GB_FULL;
  247. *negotiation = true;
  248. break;
  249. case IXGBE_AUTOC_LMS_KX4_KX_KR_SGMII:
  250. *speed = IXGBE_LINK_SPEED_100_FULL;
  251. if (autoc & IXGBE_AUTOC_KR_SUPP)
  252. *speed |= IXGBE_LINK_SPEED_10GB_FULL;
  253. if (autoc & IXGBE_AUTOC_KX4_SUPP)
  254. *speed |= IXGBE_LINK_SPEED_10GB_FULL;
  255. if (autoc & IXGBE_AUTOC_KX_SUPP)
  256. *speed |= IXGBE_LINK_SPEED_1GB_FULL;
  257. *negotiation = true;
  258. break;
  259. case IXGBE_AUTOC_LMS_SGMII_1G_100M:
  260. *speed = IXGBE_LINK_SPEED_1GB_FULL | IXGBE_LINK_SPEED_100_FULL;
  261. *negotiation = false;
  262. break;
  263. default:
  264. status = IXGBE_ERR_LINK_SETUP;
  265. goto out;
  266. break;
  267. }
  268. if (hw->phy.multispeed_fiber) {
  269. *speed |= IXGBE_LINK_SPEED_10GB_FULL |
  270. IXGBE_LINK_SPEED_1GB_FULL;
  271. *negotiation = true;
  272. }
  273. out:
  274. return status;
  275. }
  276. /**
  277. * ixgbe_get_media_type_82599 - Get media type
  278. * @hw: pointer to hardware structure
  279. *
  280. * Returns the media type (fiber, copper, backplane)
  281. **/
  282. static enum ixgbe_media_type ixgbe_get_media_type_82599(struct ixgbe_hw *hw)
  283. {
  284. enum ixgbe_media_type media_type;
  285. /* Detect if there is a copper PHY attached. */
  286. switch (hw->phy.type) {
  287. case ixgbe_phy_cu_unknown:
  288. case ixgbe_phy_tn:
  289. media_type = ixgbe_media_type_copper;
  290. goto out;
  291. default:
  292. break;
  293. }
  294. switch (hw->device_id) {
  295. case IXGBE_DEV_ID_82599_KX4:
  296. case IXGBE_DEV_ID_82599_KX4_MEZZ:
  297. case IXGBE_DEV_ID_82599_COMBO_BACKPLANE:
  298. case IXGBE_DEV_ID_82599_KR:
  299. case IXGBE_DEV_ID_82599_BACKPLANE_FCOE:
  300. case IXGBE_DEV_ID_82599_XAUI_LOM:
  301. /* Default device ID is mezzanine card KX/KX4 */
  302. media_type = ixgbe_media_type_backplane;
  303. break;
  304. case IXGBE_DEV_ID_82599_SFP:
  305. case IXGBE_DEV_ID_82599_SFP_FCOE:
  306. case IXGBE_DEV_ID_82599_SFP_EM:
  307. case IXGBE_DEV_ID_82599_SFP_SF2:
  308. case IXGBE_DEV_ID_82599EN_SFP:
  309. media_type = ixgbe_media_type_fiber;
  310. break;
  311. case IXGBE_DEV_ID_82599_CX4:
  312. media_type = ixgbe_media_type_cx4;
  313. break;
  314. case IXGBE_DEV_ID_82599_T3_LOM:
  315. media_type = ixgbe_media_type_copper;
  316. break;
  317. case IXGBE_DEV_ID_82599_LS:
  318. media_type = ixgbe_media_type_fiber_lco;
  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. static 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. ixgbe_link_speed link_speed;
  784. s32 status;
  785. u32 ctrl, i, autoc, autoc2;
  786. bool link_up = false;
  787. /* Call adapter stop to disable tx/rx and clear interrupts */
  788. status = hw->mac.ops.stop_adapter(hw);
  789. if (status != 0)
  790. goto reset_hw_out;
  791. /* flush pending Tx transactions */
  792. ixgbe_clear_tx_pending(hw);
  793. /* PHY ops must be identified and initialized prior to reset */
  794. /* Identify PHY and related function pointers */
  795. status = hw->phy.ops.init(hw);
  796. if (status == IXGBE_ERR_SFP_NOT_SUPPORTED)
  797. goto reset_hw_out;
  798. /* Setup SFP module if there is one present. */
  799. if (hw->phy.sfp_setup_needed) {
  800. status = hw->mac.ops.setup_sfp(hw);
  801. hw->phy.sfp_setup_needed = false;
  802. }
  803. if (status == IXGBE_ERR_SFP_NOT_SUPPORTED)
  804. goto reset_hw_out;
  805. /* Reset PHY */
  806. if (hw->phy.reset_disable == false && hw->phy.ops.reset != NULL)
  807. hw->phy.ops.reset(hw);
  808. mac_reset_top:
  809. /*
  810. * Issue global reset to the MAC. Needs to be SW reset if link is up.
  811. * If link reset is used when link is up, it might reset the PHY when
  812. * mng is using it. If link is down or the flag to force full link
  813. * reset is set, then perform link reset.
  814. */
  815. ctrl = IXGBE_CTRL_LNK_RST;
  816. if (!hw->force_full_reset) {
  817. hw->mac.ops.check_link(hw, &link_speed, &link_up, false);
  818. if (link_up)
  819. ctrl = IXGBE_CTRL_RST;
  820. }
  821. ctrl |= IXGBE_READ_REG(hw, IXGBE_CTRL);
  822. IXGBE_WRITE_REG(hw, IXGBE_CTRL, ctrl);
  823. IXGBE_WRITE_FLUSH(hw);
  824. /* Poll for reset bit to self-clear indicating reset is complete */
  825. for (i = 0; i < 10; i++) {
  826. udelay(1);
  827. ctrl = IXGBE_READ_REG(hw, IXGBE_CTRL);
  828. if (!(ctrl & IXGBE_CTRL_RST_MASK))
  829. break;
  830. }
  831. if (ctrl & IXGBE_CTRL_RST_MASK) {
  832. status = IXGBE_ERR_RESET_FAILED;
  833. hw_dbg(hw, "Reset polling failed to complete.\n");
  834. }
  835. msleep(50);
  836. /*
  837. * Double resets are required for recovery from certain error
  838. * conditions. Between resets, it is necessary to stall to allow time
  839. * for any pending HW events to complete.
  840. */
  841. if (hw->mac.flags & IXGBE_FLAGS_DOUBLE_RESET_REQUIRED) {
  842. hw->mac.flags &= ~IXGBE_FLAGS_DOUBLE_RESET_REQUIRED;
  843. goto mac_reset_top;
  844. }
  845. /*
  846. * Store the original AUTOC/AUTOC2 values if they have not been
  847. * stored off yet. Otherwise restore the stored original
  848. * values since the reset operation sets back to defaults.
  849. */
  850. autoc = IXGBE_READ_REG(hw, IXGBE_AUTOC);
  851. autoc2 = IXGBE_READ_REG(hw, IXGBE_AUTOC2);
  852. if (hw->mac.orig_link_settings_stored == false) {
  853. hw->mac.orig_autoc = autoc;
  854. hw->mac.orig_autoc2 = autoc2;
  855. hw->mac.orig_link_settings_stored = true;
  856. } else {
  857. if (autoc != hw->mac.orig_autoc)
  858. IXGBE_WRITE_REG(hw, IXGBE_AUTOC, (hw->mac.orig_autoc |
  859. IXGBE_AUTOC_AN_RESTART));
  860. if ((autoc2 & IXGBE_AUTOC2_UPPER_MASK) !=
  861. (hw->mac.orig_autoc2 & IXGBE_AUTOC2_UPPER_MASK)) {
  862. autoc2 &= ~IXGBE_AUTOC2_UPPER_MASK;
  863. autoc2 |= (hw->mac.orig_autoc2 &
  864. IXGBE_AUTOC2_UPPER_MASK);
  865. IXGBE_WRITE_REG(hw, IXGBE_AUTOC2, autoc2);
  866. }
  867. }
  868. /* Store the permanent mac address */
  869. hw->mac.ops.get_mac_addr(hw, hw->mac.perm_addr);
  870. /*
  871. * Store MAC address from RAR0, clear receive address registers, and
  872. * clear the multicast table. Also reset num_rar_entries to 128,
  873. * since we modify this value when programming the SAN MAC address.
  874. */
  875. hw->mac.num_rar_entries = 128;
  876. hw->mac.ops.init_rx_addrs(hw);
  877. /* Store the permanent SAN mac address */
  878. hw->mac.ops.get_san_mac_addr(hw, hw->mac.san_addr);
  879. /* Add the SAN MAC address to the RAR only if it's a valid address */
  880. if (ixgbe_validate_mac_addr(hw->mac.san_addr) == 0) {
  881. hw->mac.ops.set_rar(hw, hw->mac.num_rar_entries - 1,
  882. hw->mac.san_addr, 0, IXGBE_RAH_AV);
  883. /* Reserve the last RAR for the SAN MAC address */
  884. hw->mac.num_rar_entries--;
  885. }
  886. /* Store the alternative WWNN/WWPN prefix */
  887. hw->mac.ops.get_wwn_prefix(hw, &hw->mac.wwnn_prefix,
  888. &hw->mac.wwpn_prefix);
  889. reset_hw_out:
  890. return status;
  891. }
  892. /**
  893. * ixgbe_reinit_fdir_tables_82599 - Reinitialize Flow Director tables.
  894. * @hw: pointer to hardware structure
  895. **/
  896. s32 ixgbe_reinit_fdir_tables_82599(struct ixgbe_hw *hw)
  897. {
  898. int i;
  899. u32 fdirctrl = IXGBE_READ_REG(hw, IXGBE_FDIRCTRL);
  900. fdirctrl &= ~IXGBE_FDIRCTRL_INIT_DONE;
  901. /*
  902. * Before starting reinitialization process,
  903. * FDIRCMD.CMD must be zero.
  904. */
  905. for (i = 0; i < IXGBE_FDIRCMD_CMD_POLL; i++) {
  906. if (!(IXGBE_READ_REG(hw, IXGBE_FDIRCMD) &
  907. IXGBE_FDIRCMD_CMD_MASK))
  908. break;
  909. udelay(10);
  910. }
  911. if (i >= IXGBE_FDIRCMD_CMD_POLL) {
  912. hw_dbg(hw, "Flow Director previous command isn't complete, "
  913. "aborting table re-initialization.\n");
  914. return IXGBE_ERR_FDIR_REINIT_FAILED;
  915. }
  916. IXGBE_WRITE_REG(hw, IXGBE_FDIRFREE, 0);
  917. IXGBE_WRITE_FLUSH(hw);
  918. /*
  919. * 82599 adapters flow director init flow cannot be restarted,
  920. * Workaround 82599 silicon errata by performing the following steps
  921. * before re-writing the FDIRCTRL control register with the same value.
  922. * - write 1 to bit 8 of FDIRCMD register &
  923. * - write 0 to bit 8 of FDIRCMD register
  924. */
  925. IXGBE_WRITE_REG(hw, IXGBE_FDIRCMD,
  926. (IXGBE_READ_REG(hw, IXGBE_FDIRCMD) |
  927. IXGBE_FDIRCMD_CLEARHT));
  928. IXGBE_WRITE_FLUSH(hw);
  929. IXGBE_WRITE_REG(hw, IXGBE_FDIRCMD,
  930. (IXGBE_READ_REG(hw, IXGBE_FDIRCMD) &
  931. ~IXGBE_FDIRCMD_CLEARHT));
  932. IXGBE_WRITE_FLUSH(hw);
  933. /*
  934. * Clear FDIR Hash register to clear any leftover hashes
  935. * waiting to be programmed.
  936. */
  937. IXGBE_WRITE_REG(hw, IXGBE_FDIRHASH, 0x00);
  938. IXGBE_WRITE_FLUSH(hw);
  939. IXGBE_WRITE_REG(hw, IXGBE_FDIRCTRL, fdirctrl);
  940. IXGBE_WRITE_FLUSH(hw);
  941. /* Poll init-done after we write FDIRCTRL register */
  942. for (i = 0; i < IXGBE_FDIR_INIT_DONE_POLL; i++) {
  943. if (IXGBE_READ_REG(hw, IXGBE_FDIRCTRL) &
  944. IXGBE_FDIRCTRL_INIT_DONE)
  945. break;
  946. udelay(10);
  947. }
  948. if (i >= IXGBE_FDIR_INIT_DONE_POLL) {
  949. hw_dbg(hw, "Flow Director Signature poll time exceeded!\n");
  950. return IXGBE_ERR_FDIR_REINIT_FAILED;
  951. }
  952. /* Clear FDIR statistics registers (read to clear) */
  953. IXGBE_READ_REG(hw, IXGBE_FDIRUSTAT);
  954. IXGBE_READ_REG(hw, IXGBE_FDIRFSTAT);
  955. IXGBE_READ_REG(hw, IXGBE_FDIRMATCH);
  956. IXGBE_READ_REG(hw, IXGBE_FDIRMISS);
  957. IXGBE_READ_REG(hw, IXGBE_FDIRLEN);
  958. return 0;
  959. }
  960. /**
  961. * ixgbe_fdir_enable_82599 - Initialize Flow Director control registers
  962. * @hw: pointer to hardware structure
  963. * @fdirctrl: value to write to flow director control register
  964. **/
  965. static void ixgbe_fdir_enable_82599(struct ixgbe_hw *hw, u32 fdirctrl)
  966. {
  967. int i;
  968. /* Prime the keys for hashing */
  969. IXGBE_WRITE_REG(hw, IXGBE_FDIRHKEY, IXGBE_ATR_BUCKET_HASH_KEY);
  970. IXGBE_WRITE_REG(hw, IXGBE_FDIRSKEY, IXGBE_ATR_SIGNATURE_HASH_KEY);
  971. /*
  972. * Poll init-done after we write the register. Estimated times:
  973. * 10G: PBALLOC = 11b, timing is 60us
  974. * 1G: PBALLOC = 11b, timing is 600us
  975. * 100M: PBALLOC = 11b, timing is 6ms
  976. *
  977. * Multiple these timings by 4 if under full Rx load
  978. *
  979. * So we'll poll for IXGBE_FDIR_INIT_DONE_POLL times, sleeping for
  980. * 1 msec per poll time. If we're at line rate and drop to 100M, then
  981. * this might not finish in our poll time, but we can live with that
  982. * for now.
  983. */
  984. IXGBE_WRITE_REG(hw, IXGBE_FDIRCTRL, fdirctrl);
  985. IXGBE_WRITE_FLUSH(hw);
  986. for (i = 0; i < IXGBE_FDIR_INIT_DONE_POLL; i++) {
  987. if (IXGBE_READ_REG(hw, IXGBE_FDIRCTRL) &
  988. IXGBE_FDIRCTRL_INIT_DONE)
  989. break;
  990. usleep_range(1000, 2000);
  991. }
  992. if (i >= IXGBE_FDIR_INIT_DONE_POLL)
  993. hw_dbg(hw, "Flow Director poll time exceeded!\n");
  994. }
  995. /**
  996. * ixgbe_init_fdir_signature_82599 - Initialize Flow Director signature filters
  997. * @hw: pointer to hardware structure
  998. * @fdirctrl: value to write to flow director control register, initially
  999. * contains just the value of the Rx packet buffer allocation
  1000. **/
  1001. s32 ixgbe_init_fdir_signature_82599(struct ixgbe_hw *hw, u32 fdirctrl)
  1002. {
  1003. /*
  1004. * Continue setup of fdirctrl register bits:
  1005. * Move the flexible bytes to use the ethertype - shift 6 words
  1006. * Set the maximum length per hash bucket to 0xA filters
  1007. * Send interrupt when 64 filters are left
  1008. */
  1009. fdirctrl |= (0x6 << IXGBE_FDIRCTRL_FLEX_SHIFT) |
  1010. (0xA << IXGBE_FDIRCTRL_MAX_LENGTH_SHIFT) |
  1011. (4 << IXGBE_FDIRCTRL_FULL_THRESH_SHIFT);
  1012. /* write hashes and fdirctrl register, poll for completion */
  1013. ixgbe_fdir_enable_82599(hw, fdirctrl);
  1014. return 0;
  1015. }
  1016. /**
  1017. * ixgbe_init_fdir_perfect_82599 - Initialize Flow Director perfect filters
  1018. * @hw: pointer to hardware structure
  1019. * @fdirctrl: value to write to flow director control register, initially
  1020. * contains just the value of the Rx packet buffer allocation
  1021. **/
  1022. s32 ixgbe_init_fdir_perfect_82599(struct ixgbe_hw *hw, u32 fdirctrl)
  1023. {
  1024. /*
  1025. * Continue setup of fdirctrl register bits:
  1026. * Turn perfect match filtering on
  1027. * Report hash in RSS field of Rx wb descriptor
  1028. * Initialize the drop queue
  1029. * Move the flexible bytes to use the ethertype - shift 6 words
  1030. * Set the maximum length per hash bucket to 0xA filters
  1031. * Send interrupt when 64 (0x4 * 16) filters are left
  1032. */
  1033. fdirctrl |= IXGBE_FDIRCTRL_PERFECT_MATCH |
  1034. IXGBE_FDIRCTRL_REPORT_STATUS |
  1035. (IXGBE_FDIR_DROP_QUEUE << IXGBE_FDIRCTRL_DROP_Q_SHIFT) |
  1036. (0x6 << IXGBE_FDIRCTRL_FLEX_SHIFT) |
  1037. (0xA << IXGBE_FDIRCTRL_MAX_LENGTH_SHIFT) |
  1038. (4 << IXGBE_FDIRCTRL_FULL_THRESH_SHIFT);
  1039. /* write hashes and fdirctrl register, poll for completion */
  1040. ixgbe_fdir_enable_82599(hw, fdirctrl);
  1041. return 0;
  1042. }
  1043. /*
  1044. * These defines allow us to quickly generate all of the necessary instructions
  1045. * in the function below by simply calling out IXGBE_COMPUTE_SIG_HASH_ITERATION
  1046. * for values 0 through 15
  1047. */
  1048. #define IXGBE_ATR_COMMON_HASH_KEY \
  1049. (IXGBE_ATR_BUCKET_HASH_KEY & IXGBE_ATR_SIGNATURE_HASH_KEY)
  1050. #define IXGBE_COMPUTE_SIG_HASH_ITERATION(_n) \
  1051. do { \
  1052. u32 n = (_n); \
  1053. if (IXGBE_ATR_COMMON_HASH_KEY & (0x01 << n)) \
  1054. common_hash ^= lo_hash_dword >> n; \
  1055. else if (IXGBE_ATR_BUCKET_HASH_KEY & (0x01 << n)) \
  1056. bucket_hash ^= lo_hash_dword >> n; \
  1057. else if (IXGBE_ATR_SIGNATURE_HASH_KEY & (0x01 << n)) \
  1058. sig_hash ^= lo_hash_dword << (16 - n); \
  1059. if (IXGBE_ATR_COMMON_HASH_KEY & (0x01 << (n + 16))) \
  1060. common_hash ^= hi_hash_dword >> n; \
  1061. else if (IXGBE_ATR_BUCKET_HASH_KEY & (0x01 << (n + 16))) \
  1062. bucket_hash ^= hi_hash_dword >> n; \
  1063. else if (IXGBE_ATR_SIGNATURE_HASH_KEY & (0x01 << (n + 16))) \
  1064. sig_hash ^= hi_hash_dword << (16 - n); \
  1065. } while (0);
  1066. /**
  1067. * ixgbe_atr_compute_sig_hash_82599 - Compute the signature hash
  1068. * @stream: input bitstream to compute the hash on
  1069. *
  1070. * This function is almost identical to the function above but contains
  1071. * several optomizations such as unwinding all of the loops, letting the
  1072. * compiler work out all of the conditional ifs since the keys are static
  1073. * defines, and computing two keys at once since the hashed dword stream
  1074. * will be the same for both keys.
  1075. **/
  1076. static u32 ixgbe_atr_compute_sig_hash_82599(union ixgbe_atr_hash_dword input,
  1077. union ixgbe_atr_hash_dword common)
  1078. {
  1079. u32 hi_hash_dword, lo_hash_dword, flow_vm_vlan;
  1080. u32 sig_hash = 0, bucket_hash = 0, common_hash = 0;
  1081. /* record the flow_vm_vlan bits as they are a key part to the hash */
  1082. flow_vm_vlan = ntohl(input.dword);
  1083. /* generate common hash dword */
  1084. hi_hash_dword = ntohl(common.dword);
  1085. /* low dword is word swapped version of common */
  1086. lo_hash_dword = (hi_hash_dword >> 16) | (hi_hash_dword << 16);
  1087. /* apply flow ID/VM pool/VLAN ID bits to hash words */
  1088. hi_hash_dword ^= flow_vm_vlan ^ (flow_vm_vlan >> 16);
  1089. /* Process bits 0 and 16 */
  1090. IXGBE_COMPUTE_SIG_HASH_ITERATION(0);
  1091. /*
  1092. * apply flow ID/VM pool/VLAN ID bits to lo hash dword, we had to
  1093. * delay this because bit 0 of the stream should not be processed
  1094. * so we do not add the vlan until after bit 0 was processed
  1095. */
  1096. lo_hash_dword ^= flow_vm_vlan ^ (flow_vm_vlan << 16);
  1097. /* Process remaining 30 bit of the key */
  1098. IXGBE_COMPUTE_SIG_HASH_ITERATION(1);
  1099. IXGBE_COMPUTE_SIG_HASH_ITERATION(2);
  1100. IXGBE_COMPUTE_SIG_HASH_ITERATION(3);
  1101. IXGBE_COMPUTE_SIG_HASH_ITERATION(4);
  1102. IXGBE_COMPUTE_SIG_HASH_ITERATION(5);
  1103. IXGBE_COMPUTE_SIG_HASH_ITERATION(6);
  1104. IXGBE_COMPUTE_SIG_HASH_ITERATION(7);
  1105. IXGBE_COMPUTE_SIG_HASH_ITERATION(8);
  1106. IXGBE_COMPUTE_SIG_HASH_ITERATION(9);
  1107. IXGBE_COMPUTE_SIG_HASH_ITERATION(10);
  1108. IXGBE_COMPUTE_SIG_HASH_ITERATION(11);
  1109. IXGBE_COMPUTE_SIG_HASH_ITERATION(12);
  1110. IXGBE_COMPUTE_SIG_HASH_ITERATION(13);
  1111. IXGBE_COMPUTE_SIG_HASH_ITERATION(14);
  1112. IXGBE_COMPUTE_SIG_HASH_ITERATION(15);
  1113. /* combine common_hash result with signature and bucket hashes */
  1114. bucket_hash ^= common_hash;
  1115. bucket_hash &= IXGBE_ATR_HASH_MASK;
  1116. sig_hash ^= common_hash << 16;
  1117. sig_hash &= IXGBE_ATR_HASH_MASK << 16;
  1118. /* return completed signature hash */
  1119. return sig_hash ^ bucket_hash;
  1120. }
  1121. /**
  1122. * ixgbe_atr_add_signature_filter_82599 - Adds a signature hash filter
  1123. * @hw: pointer to hardware structure
  1124. * @input: unique input dword
  1125. * @common: compressed common input dword
  1126. * @queue: queue index to direct traffic to
  1127. **/
  1128. s32 ixgbe_fdir_add_signature_filter_82599(struct ixgbe_hw *hw,
  1129. union ixgbe_atr_hash_dword input,
  1130. union ixgbe_atr_hash_dword common,
  1131. u8 queue)
  1132. {
  1133. u64 fdirhashcmd;
  1134. u32 fdircmd;
  1135. /*
  1136. * Get the flow_type in order to program FDIRCMD properly
  1137. * lowest 2 bits are FDIRCMD.L4TYPE, third lowest bit is FDIRCMD.IPV6
  1138. */
  1139. switch (input.formatted.flow_type) {
  1140. case IXGBE_ATR_FLOW_TYPE_TCPV4:
  1141. case IXGBE_ATR_FLOW_TYPE_UDPV4:
  1142. case IXGBE_ATR_FLOW_TYPE_SCTPV4:
  1143. case IXGBE_ATR_FLOW_TYPE_TCPV6:
  1144. case IXGBE_ATR_FLOW_TYPE_UDPV6:
  1145. case IXGBE_ATR_FLOW_TYPE_SCTPV6:
  1146. break;
  1147. default:
  1148. hw_dbg(hw, " Error on flow type input\n");
  1149. return IXGBE_ERR_CONFIG;
  1150. }
  1151. /* configure FDIRCMD register */
  1152. fdircmd = IXGBE_FDIRCMD_CMD_ADD_FLOW | IXGBE_FDIRCMD_FILTER_UPDATE |
  1153. IXGBE_FDIRCMD_LAST | IXGBE_FDIRCMD_QUEUE_EN;
  1154. fdircmd |= input.formatted.flow_type << IXGBE_FDIRCMD_FLOW_TYPE_SHIFT;
  1155. fdircmd |= (u32)queue << IXGBE_FDIRCMD_RX_QUEUE_SHIFT;
  1156. /*
  1157. * The lower 32-bits of fdirhashcmd is for FDIRHASH, the upper 32-bits
  1158. * is for FDIRCMD. Then do a 64-bit register write from FDIRHASH.
  1159. */
  1160. fdirhashcmd = (u64)fdircmd << 32;
  1161. fdirhashcmd |= ixgbe_atr_compute_sig_hash_82599(input, common);
  1162. IXGBE_WRITE_REG64(hw, IXGBE_FDIRHASH, fdirhashcmd);
  1163. hw_dbg(hw, "Tx Queue=%x hash=%x\n", queue, (u32)fdirhashcmd);
  1164. return 0;
  1165. }
  1166. #define IXGBE_COMPUTE_BKT_HASH_ITERATION(_n) \
  1167. do { \
  1168. u32 n = (_n); \
  1169. if (IXGBE_ATR_BUCKET_HASH_KEY & (0x01 << n)) \
  1170. bucket_hash ^= lo_hash_dword >> n; \
  1171. if (IXGBE_ATR_BUCKET_HASH_KEY & (0x01 << (n + 16))) \
  1172. bucket_hash ^= hi_hash_dword >> n; \
  1173. } while (0);
  1174. /**
  1175. * ixgbe_atr_compute_perfect_hash_82599 - Compute the perfect filter hash
  1176. * @atr_input: input bitstream to compute the hash on
  1177. * @input_mask: mask for the input bitstream
  1178. *
  1179. * This function serves two main purposes. First it applys the input_mask
  1180. * to the atr_input resulting in a cleaned up atr_input data stream.
  1181. * Secondly it computes the hash and stores it in the bkt_hash field at
  1182. * the end of the input byte stream. This way it will be available for
  1183. * future use without needing to recompute the hash.
  1184. **/
  1185. void ixgbe_atr_compute_perfect_hash_82599(union ixgbe_atr_input *input,
  1186. union ixgbe_atr_input *input_mask)
  1187. {
  1188. u32 hi_hash_dword, lo_hash_dword, flow_vm_vlan;
  1189. u32 bucket_hash = 0;
  1190. /* Apply masks to input data */
  1191. input->dword_stream[0] &= input_mask->dword_stream[0];
  1192. input->dword_stream[1] &= input_mask->dword_stream[1];
  1193. input->dword_stream[2] &= input_mask->dword_stream[2];
  1194. input->dword_stream[3] &= input_mask->dword_stream[3];
  1195. input->dword_stream[4] &= input_mask->dword_stream[4];
  1196. input->dword_stream[5] &= input_mask->dword_stream[5];
  1197. input->dword_stream[6] &= input_mask->dword_stream[6];
  1198. input->dword_stream[7] &= input_mask->dword_stream[7];
  1199. input->dword_stream[8] &= input_mask->dword_stream[8];
  1200. input->dword_stream[9] &= input_mask->dword_stream[9];
  1201. input->dword_stream[10] &= input_mask->dword_stream[10];
  1202. /* record the flow_vm_vlan bits as they are a key part to the hash */
  1203. flow_vm_vlan = ntohl(input->dword_stream[0]);
  1204. /* generate common hash dword */
  1205. hi_hash_dword = ntohl(input->dword_stream[1] ^
  1206. input->dword_stream[2] ^
  1207. input->dword_stream[3] ^
  1208. input->dword_stream[4] ^
  1209. input->dword_stream[5] ^
  1210. input->dword_stream[6] ^
  1211. input->dword_stream[7] ^
  1212. input->dword_stream[8] ^
  1213. input->dword_stream[9] ^
  1214. input->dword_stream[10]);
  1215. /* low dword is word swapped version of common */
  1216. lo_hash_dword = (hi_hash_dword >> 16) | (hi_hash_dword << 16);
  1217. /* apply flow ID/VM pool/VLAN ID bits to hash words */
  1218. hi_hash_dword ^= flow_vm_vlan ^ (flow_vm_vlan >> 16);
  1219. /* Process bits 0 and 16 */
  1220. IXGBE_COMPUTE_BKT_HASH_ITERATION(0);
  1221. /*
  1222. * apply flow ID/VM pool/VLAN ID bits to lo hash dword, we had to
  1223. * delay this because bit 0 of the stream should not be processed
  1224. * so we do not add the vlan until after bit 0 was processed
  1225. */
  1226. lo_hash_dword ^= flow_vm_vlan ^ (flow_vm_vlan << 16);
  1227. /* Process remaining 30 bit of the key */
  1228. IXGBE_COMPUTE_BKT_HASH_ITERATION(1);
  1229. IXGBE_COMPUTE_BKT_HASH_ITERATION(2);
  1230. IXGBE_COMPUTE_BKT_HASH_ITERATION(3);
  1231. IXGBE_COMPUTE_BKT_HASH_ITERATION(4);
  1232. IXGBE_COMPUTE_BKT_HASH_ITERATION(5);
  1233. IXGBE_COMPUTE_BKT_HASH_ITERATION(6);
  1234. IXGBE_COMPUTE_BKT_HASH_ITERATION(7);
  1235. IXGBE_COMPUTE_BKT_HASH_ITERATION(8);
  1236. IXGBE_COMPUTE_BKT_HASH_ITERATION(9);
  1237. IXGBE_COMPUTE_BKT_HASH_ITERATION(10);
  1238. IXGBE_COMPUTE_BKT_HASH_ITERATION(11);
  1239. IXGBE_COMPUTE_BKT_HASH_ITERATION(12);
  1240. IXGBE_COMPUTE_BKT_HASH_ITERATION(13);
  1241. IXGBE_COMPUTE_BKT_HASH_ITERATION(14);
  1242. IXGBE_COMPUTE_BKT_HASH_ITERATION(15);
  1243. /*
  1244. * Limit hash to 13 bits since max bucket count is 8K.
  1245. * Store result at the end of the input stream.
  1246. */
  1247. input->formatted.bkt_hash = bucket_hash & 0x1FFF;
  1248. }
  1249. /**
  1250. * ixgbe_get_fdirtcpm_82599 - generate a tcp port from atr_input_masks
  1251. * @input_mask: mask to be bit swapped
  1252. *
  1253. * The source and destination port masks for flow director are bit swapped
  1254. * in that bit 15 effects bit 0, 14 effects 1, 13, 2 etc. In order to
  1255. * generate a correctly swapped value we need to bit swap the mask and that
  1256. * is what is accomplished by this function.
  1257. **/
  1258. static u32 ixgbe_get_fdirtcpm_82599(union ixgbe_atr_input *input_mask)
  1259. {
  1260. u32 mask = ntohs(input_mask->formatted.dst_port);
  1261. mask <<= IXGBE_FDIRTCPM_DPORTM_SHIFT;
  1262. mask |= ntohs(input_mask->formatted.src_port);
  1263. mask = ((mask & 0x55555555) << 1) | ((mask & 0xAAAAAAAA) >> 1);
  1264. mask = ((mask & 0x33333333) << 2) | ((mask & 0xCCCCCCCC) >> 2);
  1265. mask = ((mask & 0x0F0F0F0F) << 4) | ((mask & 0xF0F0F0F0) >> 4);
  1266. return ((mask & 0x00FF00FF) << 8) | ((mask & 0xFF00FF00) >> 8);
  1267. }
  1268. /*
  1269. * These two macros are meant to address the fact that we have registers
  1270. * that are either all or in part big-endian. As a result on big-endian
  1271. * systems we will end up byte swapping the value to little-endian before
  1272. * it is byte swapped again and written to the hardware in the original
  1273. * big-endian format.
  1274. */
  1275. #define IXGBE_STORE_AS_BE32(_value) \
  1276. (((u32)(_value) >> 24) | (((u32)(_value) & 0x00FF0000) >> 8) | \
  1277. (((u32)(_value) & 0x0000FF00) << 8) | ((u32)(_value) << 24))
  1278. #define IXGBE_WRITE_REG_BE32(a, reg, value) \
  1279. IXGBE_WRITE_REG((a), (reg), IXGBE_STORE_AS_BE32(ntohl(value)))
  1280. #define IXGBE_STORE_AS_BE16(_value) \
  1281. ntohs(((u16)(_value) >> 8) | ((u16)(_value) << 8))
  1282. s32 ixgbe_fdir_set_input_mask_82599(struct ixgbe_hw *hw,
  1283. union ixgbe_atr_input *input_mask)
  1284. {
  1285. /* mask IPv6 since it is currently not supported */
  1286. u32 fdirm = IXGBE_FDIRM_DIPv6;
  1287. u32 fdirtcpm;
  1288. /*
  1289. * Program the relevant mask registers. If src/dst_port or src/dst_addr
  1290. * are zero, then assume a full mask for that field. Also assume that
  1291. * a VLAN of 0 is unspecified, so mask that out as well. L4type
  1292. * cannot be masked out in this implementation.
  1293. *
  1294. * This also assumes IPv4 only. IPv6 masking isn't supported at this
  1295. * point in time.
  1296. */
  1297. /* verify bucket hash is cleared on hash generation */
  1298. if (input_mask->formatted.bkt_hash)
  1299. hw_dbg(hw, " bucket hash should always be 0 in mask\n");
  1300. /* Program FDIRM and verify partial masks */
  1301. switch (input_mask->formatted.vm_pool & 0x7F) {
  1302. case 0x0:
  1303. fdirm |= IXGBE_FDIRM_POOL;
  1304. case 0x7F:
  1305. break;
  1306. default:
  1307. hw_dbg(hw, " Error on vm pool mask\n");
  1308. return IXGBE_ERR_CONFIG;
  1309. }
  1310. switch (input_mask->formatted.flow_type & IXGBE_ATR_L4TYPE_MASK) {
  1311. case 0x0:
  1312. fdirm |= IXGBE_FDIRM_L4P;
  1313. if (input_mask->formatted.dst_port ||
  1314. input_mask->formatted.src_port) {
  1315. hw_dbg(hw, " Error on src/dst port mask\n");
  1316. return IXGBE_ERR_CONFIG;
  1317. }
  1318. case IXGBE_ATR_L4TYPE_MASK:
  1319. break;
  1320. default:
  1321. hw_dbg(hw, " Error on flow type mask\n");
  1322. return IXGBE_ERR_CONFIG;
  1323. }
  1324. switch (ntohs(input_mask->formatted.vlan_id) & 0xEFFF) {
  1325. case 0x0000:
  1326. /* mask VLAN ID, fall through to mask VLAN priority */
  1327. fdirm |= IXGBE_FDIRM_VLANID;
  1328. case 0x0FFF:
  1329. /* mask VLAN priority */
  1330. fdirm |= IXGBE_FDIRM_VLANP;
  1331. break;
  1332. case 0xE000:
  1333. /* mask VLAN ID only, fall through */
  1334. fdirm |= IXGBE_FDIRM_VLANID;
  1335. case 0xEFFF:
  1336. /* no VLAN fields masked */
  1337. break;
  1338. default:
  1339. hw_dbg(hw, " Error on VLAN mask\n");
  1340. return IXGBE_ERR_CONFIG;
  1341. }
  1342. switch (input_mask->formatted.flex_bytes & 0xFFFF) {
  1343. case 0x0000:
  1344. /* Mask Flex Bytes, fall through */
  1345. fdirm |= IXGBE_FDIRM_FLEX;
  1346. case 0xFFFF:
  1347. break;
  1348. default:
  1349. hw_dbg(hw, " Error on flexible byte mask\n");
  1350. return IXGBE_ERR_CONFIG;
  1351. }
  1352. /* Now mask VM pool and destination IPv6 - bits 5 and 2 */
  1353. IXGBE_WRITE_REG(hw, IXGBE_FDIRM, fdirm);
  1354. /* store the TCP/UDP port masks, bit reversed from port layout */
  1355. fdirtcpm = ixgbe_get_fdirtcpm_82599(input_mask);
  1356. /* write both the same so that UDP and TCP use the same mask */
  1357. IXGBE_WRITE_REG(hw, IXGBE_FDIRTCPM, ~fdirtcpm);
  1358. IXGBE_WRITE_REG(hw, IXGBE_FDIRUDPM, ~fdirtcpm);
  1359. /* store source and destination IP masks (big-enian) */
  1360. IXGBE_WRITE_REG_BE32(hw, IXGBE_FDIRSIP4M,
  1361. ~input_mask->formatted.src_ip[0]);
  1362. IXGBE_WRITE_REG_BE32(hw, IXGBE_FDIRDIP4M,
  1363. ~input_mask->formatted.dst_ip[0]);
  1364. return 0;
  1365. }
  1366. s32 ixgbe_fdir_write_perfect_filter_82599(struct ixgbe_hw *hw,
  1367. union ixgbe_atr_input *input,
  1368. u16 soft_id, u8 queue)
  1369. {
  1370. u32 fdirport, fdirvlan, fdirhash, fdircmd;
  1371. /* currently IPv6 is not supported, must be programmed with 0 */
  1372. IXGBE_WRITE_REG_BE32(hw, IXGBE_FDIRSIPv6(0),
  1373. input->formatted.src_ip[0]);
  1374. IXGBE_WRITE_REG_BE32(hw, IXGBE_FDIRSIPv6(1),
  1375. input->formatted.src_ip[1]);
  1376. IXGBE_WRITE_REG_BE32(hw, IXGBE_FDIRSIPv6(2),
  1377. input->formatted.src_ip[2]);
  1378. /* record the source address (big-endian) */
  1379. IXGBE_WRITE_REG_BE32(hw, IXGBE_FDIRIPSA, input->formatted.src_ip[0]);
  1380. /* record the first 32 bits of the destination address (big-endian) */
  1381. IXGBE_WRITE_REG_BE32(hw, IXGBE_FDIRIPDA, input->formatted.dst_ip[0]);
  1382. /* record source and destination port (little-endian)*/
  1383. fdirport = ntohs(input->formatted.dst_port);
  1384. fdirport <<= IXGBE_FDIRPORT_DESTINATION_SHIFT;
  1385. fdirport |= ntohs(input->formatted.src_port);
  1386. IXGBE_WRITE_REG(hw, IXGBE_FDIRPORT, fdirport);
  1387. /* record vlan (little-endian) and flex_bytes(big-endian) */
  1388. fdirvlan = IXGBE_STORE_AS_BE16(input->formatted.flex_bytes);
  1389. fdirvlan <<= IXGBE_FDIRVLAN_FLEX_SHIFT;
  1390. fdirvlan |= ntohs(input->formatted.vlan_id);
  1391. IXGBE_WRITE_REG(hw, IXGBE_FDIRVLAN, fdirvlan);
  1392. /* configure FDIRHASH register */
  1393. fdirhash = input->formatted.bkt_hash;
  1394. fdirhash |= soft_id << IXGBE_FDIRHASH_SIG_SW_INDEX_SHIFT;
  1395. IXGBE_WRITE_REG(hw, IXGBE_FDIRHASH, fdirhash);
  1396. /*
  1397. * flush all previous writes to make certain registers are
  1398. * programmed prior to issuing the command
  1399. */
  1400. IXGBE_WRITE_FLUSH(hw);
  1401. /* configure FDIRCMD register */
  1402. fdircmd = IXGBE_FDIRCMD_CMD_ADD_FLOW | IXGBE_FDIRCMD_FILTER_UPDATE |
  1403. IXGBE_FDIRCMD_LAST | IXGBE_FDIRCMD_QUEUE_EN;
  1404. if (queue == IXGBE_FDIR_DROP_QUEUE)
  1405. fdircmd |= IXGBE_FDIRCMD_DROP;
  1406. fdircmd |= input->formatted.flow_type << IXGBE_FDIRCMD_FLOW_TYPE_SHIFT;
  1407. fdircmd |= (u32)queue << IXGBE_FDIRCMD_RX_QUEUE_SHIFT;
  1408. fdircmd |= (u32)input->formatted.vm_pool << IXGBE_FDIRCMD_VT_POOL_SHIFT;
  1409. IXGBE_WRITE_REG(hw, IXGBE_FDIRCMD, fdircmd);
  1410. return 0;
  1411. }
  1412. s32 ixgbe_fdir_erase_perfect_filter_82599(struct ixgbe_hw *hw,
  1413. union ixgbe_atr_input *input,
  1414. u16 soft_id)
  1415. {
  1416. u32 fdirhash;
  1417. u32 fdircmd = 0;
  1418. u32 retry_count;
  1419. s32 err = 0;
  1420. /* configure FDIRHASH register */
  1421. fdirhash = input->formatted.bkt_hash;
  1422. fdirhash |= soft_id << IXGBE_FDIRHASH_SIG_SW_INDEX_SHIFT;
  1423. IXGBE_WRITE_REG(hw, IXGBE_FDIRHASH, fdirhash);
  1424. /* flush hash to HW */
  1425. IXGBE_WRITE_FLUSH(hw);
  1426. /* Query if filter is present */
  1427. IXGBE_WRITE_REG(hw, IXGBE_FDIRCMD, IXGBE_FDIRCMD_CMD_QUERY_REM_FILT);
  1428. for (retry_count = 10; retry_count; retry_count--) {
  1429. /* allow 10us for query to process */
  1430. udelay(10);
  1431. /* verify query completed successfully */
  1432. fdircmd = IXGBE_READ_REG(hw, IXGBE_FDIRCMD);
  1433. if (!(fdircmd & IXGBE_FDIRCMD_CMD_MASK))
  1434. break;
  1435. }
  1436. if (!retry_count)
  1437. err = IXGBE_ERR_FDIR_REINIT_FAILED;
  1438. /* if filter exists in hardware then remove it */
  1439. if (fdircmd & IXGBE_FDIRCMD_FILTER_VALID) {
  1440. IXGBE_WRITE_REG(hw, IXGBE_FDIRHASH, fdirhash);
  1441. IXGBE_WRITE_FLUSH(hw);
  1442. IXGBE_WRITE_REG(hw, IXGBE_FDIRCMD,
  1443. IXGBE_FDIRCMD_CMD_REMOVE_FLOW);
  1444. }
  1445. return err;
  1446. }
  1447. /**
  1448. * ixgbe_read_analog_reg8_82599 - Reads 8 bit Omer analog register
  1449. * @hw: pointer to hardware structure
  1450. * @reg: analog register to read
  1451. * @val: read value
  1452. *
  1453. * Performs read operation to Omer analog register specified.
  1454. **/
  1455. static s32 ixgbe_read_analog_reg8_82599(struct ixgbe_hw *hw, u32 reg, u8 *val)
  1456. {
  1457. u32 core_ctl;
  1458. IXGBE_WRITE_REG(hw, IXGBE_CORECTL, IXGBE_CORECTL_WRITE_CMD |
  1459. (reg << 8));
  1460. IXGBE_WRITE_FLUSH(hw);
  1461. udelay(10);
  1462. core_ctl = IXGBE_READ_REG(hw, IXGBE_CORECTL);
  1463. *val = (u8)core_ctl;
  1464. return 0;
  1465. }
  1466. /**
  1467. * ixgbe_write_analog_reg8_82599 - Writes 8 bit Omer analog register
  1468. * @hw: pointer to hardware structure
  1469. * @reg: atlas register to write
  1470. * @val: value to write
  1471. *
  1472. * Performs write operation to Omer analog register specified.
  1473. **/
  1474. static s32 ixgbe_write_analog_reg8_82599(struct ixgbe_hw *hw, u32 reg, u8 val)
  1475. {
  1476. u32 core_ctl;
  1477. core_ctl = (reg << 8) | val;
  1478. IXGBE_WRITE_REG(hw, IXGBE_CORECTL, core_ctl);
  1479. IXGBE_WRITE_FLUSH(hw);
  1480. udelay(10);
  1481. return 0;
  1482. }
  1483. /**
  1484. * ixgbe_start_hw_82599 - Prepare hardware for Tx/Rx
  1485. * @hw: pointer to hardware structure
  1486. *
  1487. * Starts the hardware using the generic start_hw function
  1488. * and the generation start_hw function.
  1489. * Then performs revision-specific operations, if any.
  1490. **/
  1491. static s32 ixgbe_start_hw_82599(struct ixgbe_hw *hw)
  1492. {
  1493. s32 ret_val = 0;
  1494. ret_val = ixgbe_start_hw_generic(hw);
  1495. if (ret_val != 0)
  1496. goto out;
  1497. ret_val = ixgbe_start_hw_gen2(hw);
  1498. if (ret_val != 0)
  1499. goto out;
  1500. /* We need to run link autotry after the driver loads */
  1501. hw->mac.autotry_restart = true;
  1502. hw->mac.rx_pb_size = IXGBE_82599_RX_PB_SIZE;
  1503. if (ret_val == 0)
  1504. ret_val = ixgbe_verify_fw_version_82599(hw);
  1505. out:
  1506. return ret_val;
  1507. }
  1508. /**
  1509. * ixgbe_identify_phy_82599 - Get physical layer module
  1510. * @hw: pointer to hardware structure
  1511. *
  1512. * Determines the physical layer module found on the current adapter.
  1513. * If PHY already detected, maintains current PHY type in hw struct,
  1514. * otherwise executes the PHY detection routine.
  1515. **/
  1516. static s32 ixgbe_identify_phy_82599(struct ixgbe_hw *hw)
  1517. {
  1518. s32 status = IXGBE_ERR_PHY_ADDR_INVALID;
  1519. /* Detect PHY if not unknown - returns success if already detected. */
  1520. status = ixgbe_identify_phy_generic(hw);
  1521. if (status != 0) {
  1522. /* 82599 10GBASE-T requires an external PHY */
  1523. if (hw->mac.ops.get_media_type(hw) == ixgbe_media_type_copper)
  1524. goto out;
  1525. else
  1526. status = ixgbe_identify_sfp_module_generic(hw);
  1527. }
  1528. /* Set PHY type none if no PHY detected */
  1529. if (hw->phy.type == ixgbe_phy_unknown) {
  1530. hw->phy.type = ixgbe_phy_none;
  1531. status = 0;
  1532. }
  1533. /* Return error if SFP module has been detected but is not supported */
  1534. if (hw->phy.type == ixgbe_phy_sfp_unsupported)
  1535. status = IXGBE_ERR_SFP_NOT_SUPPORTED;
  1536. out:
  1537. return status;
  1538. }
  1539. /**
  1540. * ixgbe_get_supported_physical_layer_82599 - Returns physical layer type
  1541. * @hw: pointer to hardware structure
  1542. *
  1543. * Determines physical layer capabilities of the current configuration.
  1544. **/
  1545. static u32 ixgbe_get_supported_physical_layer_82599(struct ixgbe_hw *hw)
  1546. {
  1547. u32 physical_layer = IXGBE_PHYSICAL_LAYER_UNKNOWN;
  1548. u32 autoc = IXGBE_READ_REG(hw, IXGBE_AUTOC);
  1549. u32 autoc2 = IXGBE_READ_REG(hw, IXGBE_AUTOC2);
  1550. u32 pma_pmd_10g_serial = autoc2 & IXGBE_AUTOC2_10G_SERIAL_PMA_PMD_MASK;
  1551. u32 pma_pmd_10g_parallel = autoc & IXGBE_AUTOC_10G_PMA_PMD_MASK;
  1552. u32 pma_pmd_1g = autoc & IXGBE_AUTOC_1G_PMA_PMD_MASK;
  1553. u16 ext_ability = 0;
  1554. u8 comp_codes_10g = 0;
  1555. u8 comp_codes_1g = 0;
  1556. hw->phy.ops.identify(hw);
  1557. switch (hw->phy.type) {
  1558. case ixgbe_phy_tn:
  1559. case ixgbe_phy_cu_unknown:
  1560. hw->phy.ops.read_reg(hw, MDIO_PMA_EXTABLE, MDIO_MMD_PMAPMD,
  1561. &ext_ability);
  1562. if (ext_ability & MDIO_PMA_EXTABLE_10GBT)
  1563. physical_layer |= IXGBE_PHYSICAL_LAYER_10GBASE_T;
  1564. if (ext_ability & MDIO_PMA_EXTABLE_1000BT)
  1565. physical_layer |= IXGBE_PHYSICAL_LAYER_1000BASE_T;
  1566. if (ext_ability & MDIO_PMA_EXTABLE_100BTX)
  1567. physical_layer |= IXGBE_PHYSICAL_LAYER_100BASE_TX;
  1568. goto out;
  1569. default:
  1570. break;
  1571. }
  1572. switch (autoc & IXGBE_AUTOC_LMS_MASK) {
  1573. case IXGBE_AUTOC_LMS_1G_AN:
  1574. case IXGBE_AUTOC_LMS_1G_LINK_NO_AN:
  1575. if (pma_pmd_1g == IXGBE_AUTOC_1G_KX_BX) {
  1576. physical_layer = IXGBE_PHYSICAL_LAYER_1000BASE_KX |
  1577. IXGBE_PHYSICAL_LAYER_1000BASE_BX;
  1578. goto out;
  1579. } else
  1580. /* SFI mode so read SFP module */
  1581. goto sfp_check;
  1582. break;
  1583. case IXGBE_AUTOC_LMS_10G_LINK_NO_AN:
  1584. if (pma_pmd_10g_parallel == IXGBE_AUTOC_10G_CX4)
  1585. physical_layer = IXGBE_PHYSICAL_LAYER_10GBASE_CX4;
  1586. else if (pma_pmd_10g_parallel == IXGBE_AUTOC_10G_KX4)
  1587. physical_layer = IXGBE_PHYSICAL_LAYER_10GBASE_KX4;
  1588. else if (pma_pmd_10g_parallel == IXGBE_AUTOC_10G_XAUI)
  1589. physical_layer = IXGBE_PHYSICAL_LAYER_10GBASE_XAUI;
  1590. goto out;
  1591. break;
  1592. case IXGBE_AUTOC_LMS_10G_SERIAL:
  1593. if (pma_pmd_10g_serial == IXGBE_AUTOC2_10G_KR) {
  1594. physical_layer = IXGBE_PHYSICAL_LAYER_10GBASE_KR;
  1595. goto out;
  1596. } else if (pma_pmd_10g_serial == IXGBE_AUTOC2_10G_SFI)
  1597. goto sfp_check;
  1598. break;
  1599. case IXGBE_AUTOC_LMS_KX4_KX_KR:
  1600. case IXGBE_AUTOC_LMS_KX4_KX_KR_1G_AN:
  1601. if (autoc & IXGBE_AUTOC_KX_SUPP)
  1602. physical_layer |= IXGBE_PHYSICAL_LAYER_1000BASE_KX;
  1603. if (autoc & IXGBE_AUTOC_KX4_SUPP)
  1604. physical_layer |= IXGBE_PHYSICAL_LAYER_10GBASE_KX4;
  1605. if (autoc & IXGBE_AUTOC_KR_SUPP)
  1606. physical_layer |= IXGBE_PHYSICAL_LAYER_10GBASE_KR;
  1607. goto out;
  1608. break;
  1609. default:
  1610. goto out;
  1611. break;
  1612. }
  1613. sfp_check:
  1614. /* SFP check must be done last since DA modules are sometimes used to
  1615. * test KR mode - we need to id KR mode correctly before SFP module.
  1616. * Call identify_sfp because the pluggable module may have changed */
  1617. hw->phy.ops.identify_sfp(hw);
  1618. if (hw->phy.sfp_type == ixgbe_sfp_type_not_present)
  1619. goto out;
  1620. switch (hw->phy.type) {
  1621. case ixgbe_phy_sfp_passive_tyco:
  1622. case ixgbe_phy_sfp_passive_unknown:
  1623. physical_layer = IXGBE_PHYSICAL_LAYER_SFP_PLUS_CU;
  1624. break;
  1625. case ixgbe_phy_sfp_ftl_active:
  1626. case ixgbe_phy_sfp_active_unknown:
  1627. physical_layer = IXGBE_PHYSICAL_LAYER_SFP_ACTIVE_DA;
  1628. break;
  1629. case ixgbe_phy_sfp_avago:
  1630. case ixgbe_phy_sfp_ftl:
  1631. case ixgbe_phy_sfp_intel:
  1632. case ixgbe_phy_sfp_unknown:
  1633. hw->phy.ops.read_i2c_eeprom(hw,
  1634. IXGBE_SFF_1GBE_COMP_CODES, &comp_codes_1g);
  1635. hw->phy.ops.read_i2c_eeprom(hw,
  1636. IXGBE_SFF_10GBE_COMP_CODES, &comp_codes_10g);
  1637. if (comp_codes_10g & IXGBE_SFF_10GBASESR_CAPABLE)
  1638. physical_layer = IXGBE_PHYSICAL_LAYER_10GBASE_SR;
  1639. else if (comp_codes_10g & IXGBE_SFF_10GBASELR_CAPABLE)
  1640. physical_layer = IXGBE_PHYSICAL_LAYER_10GBASE_LR;
  1641. else if (comp_codes_1g & IXGBE_SFF_1GBASET_CAPABLE)
  1642. physical_layer = IXGBE_PHYSICAL_LAYER_1000BASE_T;
  1643. break;
  1644. default:
  1645. break;
  1646. }
  1647. out:
  1648. return physical_layer;
  1649. }
  1650. /**
  1651. * ixgbe_enable_rx_dma_82599 - Enable the Rx DMA unit on 82599
  1652. * @hw: pointer to hardware structure
  1653. * @regval: register value to write to RXCTRL
  1654. *
  1655. * Enables the Rx DMA unit for 82599
  1656. **/
  1657. static s32 ixgbe_enable_rx_dma_82599(struct ixgbe_hw *hw, u32 regval)
  1658. {
  1659. #define IXGBE_MAX_SECRX_POLL 30
  1660. int i;
  1661. int secrxreg;
  1662. /*
  1663. * Workaround for 82599 silicon errata when enabling the Rx datapath.
  1664. * If traffic is incoming before we enable the Rx unit, it could hang
  1665. * the Rx DMA unit. Therefore, make sure the security engine is
  1666. * completely disabled prior to enabling the Rx unit.
  1667. */
  1668. secrxreg = IXGBE_READ_REG(hw, IXGBE_SECRXCTRL);
  1669. secrxreg |= IXGBE_SECRXCTRL_RX_DIS;
  1670. IXGBE_WRITE_REG(hw, IXGBE_SECRXCTRL, secrxreg);
  1671. for (i = 0; i < IXGBE_MAX_SECRX_POLL; i++) {
  1672. secrxreg = IXGBE_READ_REG(hw, IXGBE_SECRXSTAT);
  1673. if (secrxreg & IXGBE_SECRXSTAT_SECRX_RDY)
  1674. break;
  1675. else
  1676. /* Use interrupt-safe sleep just in case */
  1677. udelay(10);
  1678. }
  1679. /* For informational purposes only */
  1680. if (i >= IXGBE_MAX_SECRX_POLL)
  1681. hw_dbg(hw, "Rx unit being enabled before security "
  1682. "path fully disabled. Continuing with init.\n");
  1683. IXGBE_WRITE_REG(hw, IXGBE_RXCTRL, regval);
  1684. secrxreg = IXGBE_READ_REG(hw, IXGBE_SECRXCTRL);
  1685. secrxreg &= ~IXGBE_SECRXCTRL_RX_DIS;
  1686. IXGBE_WRITE_REG(hw, IXGBE_SECRXCTRL, secrxreg);
  1687. IXGBE_WRITE_FLUSH(hw);
  1688. return 0;
  1689. }
  1690. /**
  1691. * ixgbe_verify_fw_version_82599 - verify fw version for 82599
  1692. * @hw: pointer to hardware structure
  1693. *
  1694. * Verifies that installed the firmware version is 0.6 or higher
  1695. * for SFI devices. All 82599 SFI devices should have version 0.6 or higher.
  1696. *
  1697. * Returns IXGBE_ERR_EEPROM_VERSION if the FW is not present or
  1698. * if the FW version is not supported.
  1699. **/
  1700. static s32 ixgbe_verify_fw_version_82599(struct ixgbe_hw *hw)
  1701. {
  1702. s32 status = IXGBE_ERR_EEPROM_VERSION;
  1703. u16 fw_offset, fw_ptp_cfg_offset;
  1704. u16 fw_version = 0;
  1705. /* firmware check is only necessary for SFI devices */
  1706. if (hw->phy.media_type != ixgbe_media_type_fiber) {
  1707. status = 0;
  1708. goto fw_version_out;
  1709. }
  1710. /* get the offset to the Firmware Module block */
  1711. hw->eeprom.ops.read(hw, IXGBE_FW_PTR, &fw_offset);
  1712. if ((fw_offset == 0) || (fw_offset == 0xFFFF))
  1713. goto fw_version_out;
  1714. /* get the offset to the Pass Through Patch Configuration block */
  1715. hw->eeprom.ops.read(hw, (fw_offset +
  1716. IXGBE_FW_PASSTHROUGH_PATCH_CONFIG_PTR),
  1717. &fw_ptp_cfg_offset);
  1718. if ((fw_ptp_cfg_offset == 0) || (fw_ptp_cfg_offset == 0xFFFF))
  1719. goto fw_version_out;
  1720. /* get the firmware version */
  1721. hw->eeprom.ops.read(hw, (fw_ptp_cfg_offset +
  1722. IXGBE_FW_PATCH_VERSION_4),
  1723. &fw_version);
  1724. if (fw_version > 0x5)
  1725. status = 0;
  1726. fw_version_out:
  1727. return status;
  1728. }
  1729. /**
  1730. * ixgbe_verify_lesm_fw_enabled_82599 - Checks LESM FW module state.
  1731. * @hw: pointer to hardware structure
  1732. *
  1733. * Returns true if the LESM FW module is present and enabled. Otherwise
  1734. * returns false. Smart Speed must be disabled if LESM FW module is enabled.
  1735. **/
  1736. static bool ixgbe_verify_lesm_fw_enabled_82599(struct ixgbe_hw *hw)
  1737. {
  1738. bool lesm_enabled = false;
  1739. u16 fw_offset, fw_lesm_param_offset, fw_lesm_state;
  1740. s32 status;
  1741. /* get the offset to the Firmware Module block */
  1742. status = hw->eeprom.ops.read(hw, IXGBE_FW_PTR, &fw_offset);
  1743. if ((status != 0) ||
  1744. (fw_offset == 0) || (fw_offset == 0xFFFF))
  1745. goto out;
  1746. /* get the offset to the LESM Parameters block */
  1747. status = hw->eeprom.ops.read(hw, (fw_offset +
  1748. IXGBE_FW_LESM_PARAMETERS_PTR),
  1749. &fw_lesm_param_offset);
  1750. if ((status != 0) ||
  1751. (fw_lesm_param_offset == 0) || (fw_lesm_param_offset == 0xFFFF))
  1752. goto out;
  1753. /* get the lesm state word */
  1754. status = hw->eeprom.ops.read(hw, (fw_lesm_param_offset +
  1755. IXGBE_FW_LESM_STATE_1),
  1756. &fw_lesm_state);
  1757. if ((status == 0) &&
  1758. (fw_lesm_state & IXGBE_FW_LESM_STATE_ENABLED))
  1759. lesm_enabled = true;
  1760. out:
  1761. return lesm_enabled;
  1762. }
  1763. /**
  1764. * ixgbe_read_eeprom_buffer_82599 - Read EEPROM word(s) using
  1765. * fastest available method
  1766. *
  1767. * @hw: pointer to hardware structure
  1768. * @offset: offset of word in EEPROM to read
  1769. * @words: number of words
  1770. * @data: word(s) read from the EEPROM
  1771. *
  1772. * Retrieves 16 bit word(s) read from EEPROM
  1773. **/
  1774. static s32 ixgbe_read_eeprom_buffer_82599(struct ixgbe_hw *hw, u16 offset,
  1775. u16 words, u16 *data)
  1776. {
  1777. struct ixgbe_eeprom_info *eeprom = &hw->eeprom;
  1778. s32 ret_val = IXGBE_ERR_CONFIG;
  1779. /*
  1780. * If EEPROM is detected and can be addressed using 14 bits,
  1781. * use EERD otherwise use bit bang
  1782. */
  1783. if ((eeprom->type == ixgbe_eeprom_spi) &&
  1784. (offset + (words - 1) <= IXGBE_EERD_MAX_ADDR))
  1785. ret_val = ixgbe_read_eerd_buffer_generic(hw, offset, words,
  1786. data);
  1787. else
  1788. ret_val = ixgbe_read_eeprom_buffer_bit_bang_generic(hw, offset,
  1789. words,
  1790. data);
  1791. return ret_val;
  1792. }
  1793. /**
  1794. * ixgbe_read_eeprom_82599 - Read EEPROM word using
  1795. * fastest available method
  1796. *
  1797. * @hw: pointer to hardware structure
  1798. * @offset: offset of word in the EEPROM to read
  1799. * @data: word read from the EEPROM
  1800. *
  1801. * Reads a 16 bit word from the EEPROM
  1802. **/
  1803. static s32 ixgbe_read_eeprom_82599(struct ixgbe_hw *hw,
  1804. u16 offset, u16 *data)
  1805. {
  1806. struct ixgbe_eeprom_info *eeprom = &hw->eeprom;
  1807. s32 ret_val = IXGBE_ERR_CONFIG;
  1808. /*
  1809. * If EEPROM is detected and can be addressed using 14 bits,
  1810. * use EERD otherwise use bit bang
  1811. */
  1812. if ((eeprom->type == ixgbe_eeprom_spi) &&
  1813. (offset <= IXGBE_EERD_MAX_ADDR))
  1814. ret_val = ixgbe_read_eerd_generic(hw, offset, data);
  1815. else
  1816. ret_val = ixgbe_read_eeprom_bit_bang_generic(hw, offset, data);
  1817. return ret_val;
  1818. }
  1819. static struct ixgbe_mac_operations mac_ops_82599 = {
  1820. .init_hw = &ixgbe_init_hw_generic,
  1821. .reset_hw = &ixgbe_reset_hw_82599,
  1822. .start_hw = &ixgbe_start_hw_82599,
  1823. .clear_hw_cntrs = &ixgbe_clear_hw_cntrs_generic,
  1824. .get_media_type = &ixgbe_get_media_type_82599,
  1825. .get_supported_physical_layer = &ixgbe_get_supported_physical_layer_82599,
  1826. .enable_rx_dma = &ixgbe_enable_rx_dma_82599,
  1827. .get_mac_addr = &ixgbe_get_mac_addr_generic,
  1828. .get_san_mac_addr = &ixgbe_get_san_mac_addr_generic,
  1829. .get_device_caps = &ixgbe_get_device_caps_generic,
  1830. .get_wwn_prefix = &ixgbe_get_wwn_prefix_generic,
  1831. .stop_adapter = &ixgbe_stop_adapter_generic,
  1832. .get_bus_info = &ixgbe_get_bus_info_generic,
  1833. .set_lan_id = &ixgbe_set_lan_id_multi_port_pcie,
  1834. .read_analog_reg8 = &ixgbe_read_analog_reg8_82599,
  1835. .write_analog_reg8 = &ixgbe_write_analog_reg8_82599,
  1836. .setup_link = &ixgbe_setup_mac_link_82599,
  1837. .set_rxpba = &ixgbe_set_rxpba_generic,
  1838. .check_link = &ixgbe_check_mac_link_generic,
  1839. .get_link_capabilities = &ixgbe_get_link_capabilities_82599,
  1840. .led_on = &ixgbe_led_on_generic,
  1841. .led_off = &ixgbe_led_off_generic,
  1842. .blink_led_start = &ixgbe_blink_led_start_generic,
  1843. .blink_led_stop = &ixgbe_blink_led_stop_generic,
  1844. .set_rar = &ixgbe_set_rar_generic,
  1845. .clear_rar = &ixgbe_clear_rar_generic,
  1846. .set_vmdq = &ixgbe_set_vmdq_generic,
  1847. .clear_vmdq = &ixgbe_clear_vmdq_generic,
  1848. .init_rx_addrs = &ixgbe_init_rx_addrs_generic,
  1849. .update_mc_addr_list = &ixgbe_update_mc_addr_list_generic,
  1850. .enable_mc = &ixgbe_enable_mc_generic,
  1851. .disable_mc = &ixgbe_disable_mc_generic,
  1852. .clear_vfta = &ixgbe_clear_vfta_generic,
  1853. .set_vfta = &ixgbe_set_vfta_generic,
  1854. .fc_enable = &ixgbe_fc_enable_generic,
  1855. .set_fw_drv_ver = &ixgbe_set_fw_drv_ver_generic,
  1856. .init_uta_tables = &ixgbe_init_uta_tables_generic,
  1857. .setup_sfp = &ixgbe_setup_sfp_modules_82599,
  1858. .set_mac_anti_spoofing = &ixgbe_set_mac_anti_spoofing,
  1859. .set_vlan_anti_spoofing = &ixgbe_set_vlan_anti_spoofing,
  1860. .acquire_swfw_sync = &ixgbe_acquire_swfw_sync,
  1861. .release_swfw_sync = &ixgbe_release_swfw_sync,
  1862. };
  1863. static struct ixgbe_eeprom_operations eeprom_ops_82599 = {
  1864. .init_params = &ixgbe_init_eeprom_params_generic,
  1865. .read = &ixgbe_read_eeprom_82599,
  1866. .read_buffer = &ixgbe_read_eeprom_buffer_82599,
  1867. .write = &ixgbe_write_eeprom_generic,
  1868. .write_buffer = &ixgbe_write_eeprom_buffer_bit_bang_generic,
  1869. .calc_checksum = &ixgbe_calc_eeprom_checksum_generic,
  1870. .validate_checksum = &ixgbe_validate_eeprom_checksum_generic,
  1871. .update_checksum = &ixgbe_update_eeprom_checksum_generic,
  1872. };
  1873. static struct ixgbe_phy_operations phy_ops_82599 = {
  1874. .identify = &ixgbe_identify_phy_82599,
  1875. .identify_sfp = &ixgbe_identify_sfp_module_generic,
  1876. .init = &ixgbe_init_phy_ops_82599,
  1877. .reset = &ixgbe_reset_phy_generic,
  1878. .read_reg = &ixgbe_read_phy_reg_generic,
  1879. .write_reg = &ixgbe_write_phy_reg_generic,
  1880. .setup_link = &ixgbe_setup_phy_link_generic,
  1881. .setup_link_speed = &ixgbe_setup_phy_link_speed_generic,
  1882. .read_i2c_byte = &ixgbe_read_i2c_byte_generic,
  1883. .write_i2c_byte = &ixgbe_write_i2c_byte_generic,
  1884. .read_i2c_eeprom = &ixgbe_read_i2c_eeprom_generic,
  1885. .write_i2c_eeprom = &ixgbe_write_i2c_eeprom_generic,
  1886. .check_overtemp = &ixgbe_tn_check_overtemp,
  1887. };
  1888. struct ixgbe_info ixgbe_82599_info = {
  1889. .mac = ixgbe_mac_82599EB,
  1890. .get_invariants = &ixgbe_get_invariants_82599,
  1891. .mac_ops = &mac_ops_82599,
  1892. .eeprom_ops = &eeprom_ops_82599,
  1893. .phy_ops = &phy_ops_82599,
  1894. .mbx_ops = &mbx_ops_generic,
  1895. };