ixgbe_82599.c 70 KB

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