ixgbe_82599.c 69 KB

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