ixgbe_82599.c 70 KB

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