ixgbe_82599.c 68 KB

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