ixgbe_82599.c 78 KB

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