e1000_82575.c 78 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942
  1. // SPDX-License-Identifier: GPL-2.0
  2. /* Copyright(c) 2007 - 2018 Intel Corporation. */
  3. /* e1000_82575
  4. * e1000_82576
  5. */
  6. #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
  7. #include <linux/types.h>
  8. #include <linux/if_ether.h>
  9. #include <linux/i2c.h>
  10. #include "e1000_mac.h"
  11. #include "e1000_82575.h"
  12. #include "e1000_i210.h"
  13. #include "igb.h"
  14. static s32 igb_get_invariants_82575(struct e1000_hw *);
  15. static s32 igb_acquire_phy_82575(struct e1000_hw *);
  16. static void igb_release_phy_82575(struct e1000_hw *);
  17. static s32 igb_acquire_nvm_82575(struct e1000_hw *);
  18. static void igb_release_nvm_82575(struct e1000_hw *);
  19. static s32 igb_check_for_link_82575(struct e1000_hw *);
  20. static s32 igb_get_cfg_done_82575(struct e1000_hw *);
  21. static s32 igb_init_hw_82575(struct e1000_hw *);
  22. static s32 igb_phy_hw_reset_sgmii_82575(struct e1000_hw *);
  23. static s32 igb_read_phy_reg_sgmii_82575(struct e1000_hw *, u32, u16 *);
  24. static s32 igb_reset_hw_82575(struct e1000_hw *);
  25. static s32 igb_reset_hw_82580(struct e1000_hw *);
  26. static s32 igb_set_d0_lplu_state_82575(struct e1000_hw *, bool);
  27. static s32 igb_set_d0_lplu_state_82580(struct e1000_hw *, bool);
  28. static s32 igb_set_d3_lplu_state_82580(struct e1000_hw *, bool);
  29. static s32 igb_setup_copper_link_82575(struct e1000_hw *);
  30. static s32 igb_setup_serdes_link_82575(struct e1000_hw *);
  31. static s32 igb_write_phy_reg_sgmii_82575(struct e1000_hw *, u32, u16);
  32. static void igb_clear_hw_cntrs_82575(struct e1000_hw *);
  33. static s32 igb_acquire_swfw_sync_82575(struct e1000_hw *, u16);
  34. static s32 igb_get_pcs_speed_and_duplex_82575(struct e1000_hw *, u16 *,
  35. u16 *);
  36. static s32 igb_get_phy_id_82575(struct e1000_hw *);
  37. static void igb_release_swfw_sync_82575(struct e1000_hw *, u16);
  38. static bool igb_sgmii_active_82575(struct e1000_hw *);
  39. static s32 igb_reset_init_script_82575(struct e1000_hw *);
  40. static s32 igb_read_mac_addr_82575(struct e1000_hw *);
  41. static s32 igb_set_pcie_completion_timeout(struct e1000_hw *hw);
  42. static s32 igb_reset_mdicnfg_82580(struct e1000_hw *hw);
  43. static s32 igb_validate_nvm_checksum_82580(struct e1000_hw *hw);
  44. static s32 igb_update_nvm_checksum_82580(struct e1000_hw *hw);
  45. static s32 igb_validate_nvm_checksum_i350(struct e1000_hw *hw);
  46. static s32 igb_update_nvm_checksum_i350(struct e1000_hw *hw);
  47. static const u16 e1000_82580_rxpbs_table[] = {
  48. 36, 72, 144, 1, 2, 4, 8, 16, 35, 70, 140 };
  49. /* Due to a hw errata, if the host tries to configure the VFTA register
  50. * while performing queries from the BMC or DMA, then the VFTA in some
  51. * cases won't be written.
  52. */
  53. /**
  54. * igb_write_vfta_i350 - Write value to VLAN filter table
  55. * @hw: pointer to the HW structure
  56. * @offset: register offset in VLAN filter table
  57. * @value: register value written to VLAN filter table
  58. *
  59. * Writes value at the given offset in the register array which stores
  60. * the VLAN filter table.
  61. **/
  62. static void igb_write_vfta_i350(struct e1000_hw *hw, u32 offset, u32 value)
  63. {
  64. struct igb_adapter *adapter = hw->back;
  65. int i;
  66. for (i = 10; i--;)
  67. array_wr32(E1000_VFTA, offset, value);
  68. wrfl();
  69. adapter->shadow_vfta[offset] = value;
  70. }
  71. /**
  72. * igb_sgmii_uses_mdio_82575 - Determine if I2C pins are for external MDIO
  73. * @hw: pointer to the HW structure
  74. *
  75. * Called to determine if the I2C pins are being used for I2C or as an
  76. * external MDIO interface since the two options are mutually exclusive.
  77. **/
  78. static bool igb_sgmii_uses_mdio_82575(struct e1000_hw *hw)
  79. {
  80. u32 reg = 0;
  81. bool ext_mdio = false;
  82. switch (hw->mac.type) {
  83. case e1000_82575:
  84. case e1000_82576:
  85. reg = rd32(E1000_MDIC);
  86. ext_mdio = !!(reg & E1000_MDIC_DEST);
  87. break;
  88. case e1000_82580:
  89. case e1000_i350:
  90. case e1000_i354:
  91. case e1000_i210:
  92. case e1000_i211:
  93. reg = rd32(E1000_MDICNFG);
  94. ext_mdio = !!(reg & E1000_MDICNFG_EXT_MDIO);
  95. break;
  96. default:
  97. break;
  98. }
  99. return ext_mdio;
  100. }
  101. /**
  102. * igb_check_for_link_media_swap - Check which M88E1112 interface linked
  103. * @hw: pointer to the HW structure
  104. *
  105. * Poll the M88E1112 interfaces to see which interface achieved link.
  106. */
  107. static s32 igb_check_for_link_media_swap(struct e1000_hw *hw)
  108. {
  109. struct e1000_phy_info *phy = &hw->phy;
  110. s32 ret_val;
  111. u16 data;
  112. u8 port = 0;
  113. /* Check the copper medium. */
  114. ret_val = phy->ops.write_reg(hw, E1000_M88E1112_PAGE_ADDR, 0);
  115. if (ret_val)
  116. return ret_val;
  117. ret_val = phy->ops.read_reg(hw, E1000_M88E1112_STATUS, &data);
  118. if (ret_val)
  119. return ret_val;
  120. if (data & E1000_M88E1112_STATUS_LINK)
  121. port = E1000_MEDIA_PORT_COPPER;
  122. /* Check the other medium. */
  123. ret_val = phy->ops.write_reg(hw, E1000_M88E1112_PAGE_ADDR, 1);
  124. if (ret_val)
  125. return ret_val;
  126. ret_val = phy->ops.read_reg(hw, E1000_M88E1112_STATUS, &data);
  127. if (ret_val)
  128. return ret_val;
  129. if (data & E1000_M88E1112_STATUS_LINK)
  130. port = E1000_MEDIA_PORT_OTHER;
  131. /* Determine if a swap needs to happen. */
  132. if (port && (hw->dev_spec._82575.media_port != port)) {
  133. hw->dev_spec._82575.media_port = port;
  134. hw->dev_spec._82575.media_changed = true;
  135. }
  136. if (port == E1000_MEDIA_PORT_COPPER) {
  137. /* reset page to 0 */
  138. ret_val = phy->ops.write_reg(hw, E1000_M88E1112_PAGE_ADDR, 0);
  139. if (ret_val)
  140. return ret_val;
  141. igb_check_for_link_82575(hw);
  142. } else {
  143. igb_check_for_link_82575(hw);
  144. /* reset page to 0 */
  145. ret_val = phy->ops.write_reg(hw, E1000_M88E1112_PAGE_ADDR, 0);
  146. if (ret_val)
  147. return ret_val;
  148. }
  149. return 0;
  150. }
  151. /**
  152. * igb_init_phy_params_82575 - Init PHY func ptrs.
  153. * @hw: pointer to the HW structure
  154. **/
  155. static s32 igb_init_phy_params_82575(struct e1000_hw *hw)
  156. {
  157. struct e1000_phy_info *phy = &hw->phy;
  158. s32 ret_val = 0;
  159. u32 ctrl_ext;
  160. if (hw->phy.media_type != e1000_media_type_copper) {
  161. phy->type = e1000_phy_none;
  162. goto out;
  163. }
  164. phy->autoneg_mask = AUTONEG_ADVERTISE_SPEED_DEFAULT;
  165. phy->reset_delay_us = 100;
  166. ctrl_ext = rd32(E1000_CTRL_EXT);
  167. if (igb_sgmii_active_82575(hw)) {
  168. phy->ops.reset = igb_phy_hw_reset_sgmii_82575;
  169. ctrl_ext |= E1000_CTRL_I2C_ENA;
  170. } else {
  171. phy->ops.reset = igb_phy_hw_reset;
  172. ctrl_ext &= ~E1000_CTRL_I2C_ENA;
  173. }
  174. wr32(E1000_CTRL_EXT, ctrl_ext);
  175. igb_reset_mdicnfg_82580(hw);
  176. if (igb_sgmii_active_82575(hw) && !igb_sgmii_uses_mdio_82575(hw)) {
  177. phy->ops.read_reg = igb_read_phy_reg_sgmii_82575;
  178. phy->ops.write_reg = igb_write_phy_reg_sgmii_82575;
  179. } else {
  180. switch (hw->mac.type) {
  181. case e1000_82580:
  182. case e1000_i350:
  183. case e1000_i354:
  184. case e1000_i210:
  185. case e1000_i211:
  186. phy->ops.read_reg = igb_read_phy_reg_82580;
  187. phy->ops.write_reg = igb_write_phy_reg_82580;
  188. break;
  189. default:
  190. phy->ops.read_reg = igb_read_phy_reg_igp;
  191. phy->ops.write_reg = igb_write_phy_reg_igp;
  192. }
  193. }
  194. /* set lan id */
  195. hw->bus.func = (rd32(E1000_STATUS) & E1000_STATUS_FUNC_MASK) >>
  196. E1000_STATUS_FUNC_SHIFT;
  197. /* Make sure the PHY is in a good state. Several people have reported
  198. * firmware leaving the PHY's page select register set to something
  199. * other than the default of zero, which causes the PHY ID read to
  200. * access something other than the intended register.
  201. */
  202. ret_val = hw->phy.ops.reset(hw);
  203. if (ret_val) {
  204. hw_dbg("Error resetting the PHY.\n");
  205. goto out;
  206. }
  207. /* Set phy->phy_addr and phy->id. */
  208. igb_write_phy_reg_82580(hw, I347AT4_PAGE_SELECT, 0);
  209. ret_val = igb_get_phy_id_82575(hw);
  210. if (ret_val)
  211. return ret_val;
  212. /* Verify phy id and set remaining function pointers */
  213. switch (phy->id) {
  214. case M88E1543_E_PHY_ID:
  215. case M88E1512_E_PHY_ID:
  216. case I347AT4_E_PHY_ID:
  217. case M88E1112_E_PHY_ID:
  218. case M88E1111_I_PHY_ID:
  219. phy->type = e1000_phy_m88;
  220. phy->ops.check_polarity = igb_check_polarity_m88;
  221. phy->ops.get_phy_info = igb_get_phy_info_m88;
  222. if (phy->id != M88E1111_I_PHY_ID)
  223. phy->ops.get_cable_length =
  224. igb_get_cable_length_m88_gen2;
  225. else
  226. phy->ops.get_cable_length = igb_get_cable_length_m88;
  227. phy->ops.force_speed_duplex = igb_phy_force_speed_duplex_m88;
  228. /* Check if this PHY is configured for media swap. */
  229. if (phy->id == M88E1112_E_PHY_ID) {
  230. u16 data;
  231. ret_val = phy->ops.write_reg(hw,
  232. E1000_M88E1112_PAGE_ADDR,
  233. 2);
  234. if (ret_val)
  235. goto out;
  236. ret_val = phy->ops.read_reg(hw,
  237. E1000_M88E1112_MAC_CTRL_1,
  238. &data);
  239. if (ret_val)
  240. goto out;
  241. data = (data & E1000_M88E1112_MAC_CTRL_1_MODE_MASK) >>
  242. E1000_M88E1112_MAC_CTRL_1_MODE_SHIFT;
  243. if (data == E1000_M88E1112_AUTO_COPPER_SGMII ||
  244. data == E1000_M88E1112_AUTO_COPPER_BASEX)
  245. hw->mac.ops.check_for_link =
  246. igb_check_for_link_media_swap;
  247. }
  248. if (phy->id == M88E1512_E_PHY_ID) {
  249. ret_val = igb_initialize_M88E1512_phy(hw);
  250. if (ret_val)
  251. goto out;
  252. }
  253. if (phy->id == M88E1543_E_PHY_ID) {
  254. ret_val = igb_initialize_M88E1543_phy(hw);
  255. if (ret_val)
  256. goto out;
  257. }
  258. break;
  259. case IGP03E1000_E_PHY_ID:
  260. phy->type = e1000_phy_igp_3;
  261. phy->ops.get_phy_info = igb_get_phy_info_igp;
  262. phy->ops.get_cable_length = igb_get_cable_length_igp_2;
  263. phy->ops.force_speed_duplex = igb_phy_force_speed_duplex_igp;
  264. phy->ops.set_d0_lplu_state = igb_set_d0_lplu_state_82575;
  265. phy->ops.set_d3_lplu_state = igb_set_d3_lplu_state;
  266. break;
  267. case I82580_I_PHY_ID:
  268. case I350_I_PHY_ID:
  269. phy->type = e1000_phy_82580;
  270. phy->ops.force_speed_duplex =
  271. igb_phy_force_speed_duplex_82580;
  272. phy->ops.get_cable_length = igb_get_cable_length_82580;
  273. phy->ops.get_phy_info = igb_get_phy_info_82580;
  274. phy->ops.set_d0_lplu_state = igb_set_d0_lplu_state_82580;
  275. phy->ops.set_d3_lplu_state = igb_set_d3_lplu_state_82580;
  276. break;
  277. case I210_I_PHY_ID:
  278. phy->type = e1000_phy_i210;
  279. phy->ops.check_polarity = igb_check_polarity_m88;
  280. phy->ops.get_cfg_done = igb_get_cfg_done_i210;
  281. phy->ops.get_phy_info = igb_get_phy_info_m88;
  282. phy->ops.get_cable_length = igb_get_cable_length_m88_gen2;
  283. phy->ops.set_d0_lplu_state = igb_set_d0_lplu_state_82580;
  284. phy->ops.set_d3_lplu_state = igb_set_d3_lplu_state_82580;
  285. phy->ops.force_speed_duplex = igb_phy_force_speed_duplex_m88;
  286. break;
  287. case BCM54616_E_PHY_ID:
  288. phy->type = e1000_phy_bcm54616;
  289. break;
  290. default:
  291. ret_val = -E1000_ERR_PHY;
  292. goto out;
  293. }
  294. out:
  295. return ret_val;
  296. }
  297. /**
  298. * igb_init_nvm_params_82575 - Init NVM func ptrs.
  299. * @hw: pointer to the HW structure
  300. **/
  301. static s32 igb_init_nvm_params_82575(struct e1000_hw *hw)
  302. {
  303. struct e1000_nvm_info *nvm = &hw->nvm;
  304. u32 eecd = rd32(E1000_EECD);
  305. u16 size;
  306. size = (u16)((eecd & E1000_EECD_SIZE_EX_MASK) >>
  307. E1000_EECD_SIZE_EX_SHIFT);
  308. /* Added to a constant, "size" becomes the left-shift value
  309. * for setting word_size.
  310. */
  311. size += NVM_WORD_SIZE_BASE_SHIFT;
  312. /* Just in case size is out of range, cap it to the largest
  313. * EEPROM size supported
  314. */
  315. if (size > 15)
  316. size = 15;
  317. nvm->word_size = BIT(size);
  318. nvm->opcode_bits = 8;
  319. nvm->delay_usec = 1;
  320. switch (nvm->override) {
  321. case e1000_nvm_override_spi_large:
  322. nvm->page_size = 32;
  323. nvm->address_bits = 16;
  324. break;
  325. case e1000_nvm_override_spi_small:
  326. nvm->page_size = 8;
  327. nvm->address_bits = 8;
  328. break;
  329. default:
  330. nvm->page_size = eecd & E1000_EECD_ADDR_BITS ? 32 : 8;
  331. nvm->address_bits = eecd & E1000_EECD_ADDR_BITS ?
  332. 16 : 8;
  333. break;
  334. }
  335. if (nvm->word_size == BIT(15))
  336. nvm->page_size = 128;
  337. nvm->type = e1000_nvm_eeprom_spi;
  338. /* NVM Function Pointers */
  339. nvm->ops.acquire = igb_acquire_nvm_82575;
  340. nvm->ops.release = igb_release_nvm_82575;
  341. nvm->ops.write = igb_write_nvm_spi;
  342. nvm->ops.validate = igb_validate_nvm_checksum;
  343. nvm->ops.update = igb_update_nvm_checksum;
  344. if (nvm->word_size < BIT(15))
  345. nvm->ops.read = igb_read_nvm_eerd;
  346. else
  347. nvm->ops.read = igb_read_nvm_spi;
  348. /* override generic family function pointers for specific descendants */
  349. switch (hw->mac.type) {
  350. case e1000_82580:
  351. nvm->ops.validate = igb_validate_nvm_checksum_82580;
  352. nvm->ops.update = igb_update_nvm_checksum_82580;
  353. break;
  354. case e1000_i354:
  355. case e1000_i350:
  356. nvm->ops.validate = igb_validate_nvm_checksum_i350;
  357. nvm->ops.update = igb_update_nvm_checksum_i350;
  358. break;
  359. default:
  360. break;
  361. }
  362. return 0;
  363. }
  364. /**
  365. * igb_init_mac_params_82575 - Init MAC func ptrs.
  366. * @hw: pointer to the HW structure
  367. **/
  368. static s32 igb_init_mac_params_82575(struct e1000_hw *hw)
  369. {
  370. struct e1000_mac_info *mac = &hw->mac;
  371. struct e1000_dev_spec_82575 *dev_spec = &hw->dev_spec._82575;
  372. /* Set mta register count */
  373. mac->mta_reg_count = 128;
  374. /* Set uta register count */
  375. mac->uta_reg_count = (hw->mac.type == e1000_82575) ? 0 : 128;
  376. /* Set rar entry count */
  377. switch (mac->type) {
  378. case e1000_82576:
  379. mac->rar_entry_count = E1000_RAR_ENTRIES_82576;
  380. break;
  381. case e1000_82580:
  382. mac->rar_entry_count = E1000_RAR_ENTRIES_82580;
  383. break;
  384. case e1000_i350:
  385. case e1000_i354:
  386. mac->rar_entry_count = E1000_RAR_ENTRIES_I350;
  387. break;
  388. default:
  389. mac->rar_entry_count = E1000_RAR_ENTRIES_82575;
  390. break;
  391. }
  392. /* reset */
  393. if (mac->type >= e1000_82580)
  394. mac->ops.reset_hw = igb_reset_hw_82580;
  395. else
  396. mac->ops.reset_hw = igb_reset_hw_82575;
  397. if (mac->type >= e1000_i210) {
  398. mac->ops.acquire_swfw_sync = igb_acquire_swfw_sync_i210;
  399. mac->ops.release_swfw_sync = igb_release_swfw_sync_i210;
  400. } else {
  401. mac->ops.acquire_swfw_sync = igb_acquire_swfw_sync_82575;
  402. mac->ops.release_swfw_sync = igb_release_swfw_sync_82575;
  403. }
  404. if ((hw->mac.type == e1000_i350) || (hw->mac.type == e1000_i354))
  405. mac->ops.write_vfta = igb_write_vfta_i350;
  406. else
  407. mac->ops.write_vfta = igb_write_vfta;
  408. /* Set if part includes ASF firmware */
  409. mac->asf_firmware_present = true;
  410. /* Set if manageability features are enabled. */
  411. mac->arc_subsystem_valid =
  412. (rd32(E1000_FWSM) & E1000_FWSM_MODE_MASK)
  413. ? true : false;
  414. /* enable EEE on i350 parts and later parts */
  415. if (mac->type >= e1000_i350)
  416. dev_spec->eee_disable = false;
  417. else
  418. dev_spec->eee_disable = true;
  419. /* Allow a single clear of the SW semaphore on I210 and newer */
  420. if (mac->type >= e1000_i210)
  421. dev_spec->clear_semaphore_once = true;
  422. /* physical interface link setup */
  423. mac->ops.setup_physical_interface =
  424. (hw->phy.media_type == e1000_media_type_copper)
  425. ? igb_setup_copper_link_82575
  426. : igb_setup_serdes_link_82575;
  427. if (mac->type == e1000_82580) {
  428. switch (hw->device_id) {
  429. /* feature not supported on these id's */
  430. case E1000_DEV_ID_DH89XXCC_SGMII:
  431. case E1000_DEV_ID_DH89XXCC_SERDES:
  432. case E1000_DEV_ID_DH89XXCC_BACKPLANE:
  433. case E1000_DEV_ID_DH89XXCC_SFP:
  434. break;
  435. default:
  436. hw->dev_spec._82575.mas_capable = true;
  437. break;
  438. }
  439. }
  440. return 0;
  441. }
  442. /**
  443. * igb_set_sfp_media_type_82575 - derives SFP module media type.
  444. * @hw: pointer to the HW structure
  445. *
  446. * The media type is chosen based on SFP module.
  447. * compatibility flags retrieved from SFP ID EEPROM.
  448. **/
  449. static s32 igb_set_sfp_media_type_82575(struct e1000_hw *hw)
  450. {
  451. s32 ret_val = E1000_ERR_CONFIG;
  452. u32 ctrl_ext = 0;
  453. struct e1000_dev_spec_82575 *dev_spec = &hw->dev_spec._82575;
  454. struct e1000_sfp_flags *eth_flags = &dev_spec->eth_flags;
  455. u8 tranceiver_type = 0;
  456. s32 timeout = 3;
  457. /* Turn I2C interface ON and power on sfp cage */
  458. ctrl_ext = rd32(E1000_CTRL_EXT);
  459. ctrl_ext &= ~E1000_CTRL_EXT_SDP3_DATA;
  460. wr32(E1000_CTRL_EXT, ctrl_ext | E1000_CTRL_I2C_ENA);
  461. wrfl();
  462. /* Read SFP module data */
  463. while (timeout) {
  464. ret_val = igb_read_sfp_data_byte(hw,
  465. E1000_I2CCMD_SFP_DATA_ADDR(E1000_SFF_IDENTIFIER_OFFSET),
  466. &tranceiver_type);
  467. if (ret_val == 0)
  468. break;
  469. msleep(100);
  470. timeout--;
  471. }
  472. if (ret_val != 0)
  473. goto out;
  474. ret_val = igb_read_sfp_data_byte(hw,
  475. E1000_I2CCMD_SFP_DATA_ADDR(E1000_SFF_ETH_FLAGS_OFFSET),
  476. (u8 *)eth_flags);
  477. if (ret_val != 0)
  478. goto out;
  479. /* Check if there is some SFP module plugged and powered */
  480. if ((tranceiver_type == E1000_SFF_IDENTIFIER_SFP) ||
  481. (tranceiver_type == E1000_SFF_IDENTIFIER_SFF)) {
  482. dev_spec->module_plugged = true;
  483. if (eth_flags->e1000_base_lx || eth_flags->e1000_base_sx) {
  484. hw->phy.media_type = e1000_media_type_internal_serdes;
  485. } else if (eth_flags->e100_base_fx) {
  486. dev_spec->sgmii_active = true;
  487. hw->phy.media_type = e1000_media_type_internal_serdes;
  488. } else if (eth_flags->e1000_base_t) {
  489. dev_spec->sgmii_active = true;
  490. hw->phy.media_type = e1000_media_type_copper;
  491. } else {
  492. hw->phy.media_type = e1000_media_type_unknown;
  493. hw_dbg("PHY module has not been recognized\n");
  494. goto out;
  495. }
  496. } else {
  497. hw->phy.media_type = e1000_media_type_unknown;
  498. }
  499. ret_val = 0;
  500. out:
  501. /* Restore I2C interface setting */
  502. wr32(E1000_CTRL_EXT, ctrl_ext);
  503. return ret_val;
  504. }
  505. static s32 igb_get_invariants_82575(struct e1000_hw *hw)
  506. {
  507. struct e1000_mac_info *mac = &hw->mac;
  508. struct e1000_dev_spec_82575 *dev_spec = &hw->dev_spec._82575;
  509. s32 ret_val;
  510. u32 ctrl_ext = 0;
  511. u32 link_mode = 0;
  512. switch (hw->device_id) {
  513. case E1000_DEV_ID_82575EB_COPPER:
  514. case E1000_DEV_ID_82575EB_FIBER_SERDES:
  515. case E1000_DEV_ID_82575GB_QUAD_COPPER:
  516. mac->type = e1000_82575;
  517. break;
  518. case E1000_DEV_ID_82576:
  519. case E1000_DEV_ID_82576_NS:
  520. case E1000_DEV_ID_82576_NS_SERDES:
  521. case E1000_DEV_ID_82576_FIBER:
  522. case E1000_DEV_ID_82576_SERDES:
  523. case E1000_DEV_ID_82576_QUAD_COPPER:
  524. case E1000_DEV_ID_82576_QUAD_COPPER_ET2:
  525. case E1000_DEV_ID_82576_SERDES_QUAD:
  526. mac->type = e1000_82576;
  527. break;
  528. case E1000_DEV_ID_82580_COPPER:
  529. case E1000_DEV_ID_82580_FIBER:
  530. case E1000_DEV_ID_82580_QUAD_FIBER:
  531. case E1000_DEV_ID_82580_SERDES:
  532. case E1000_DEV_ID_82580_SGMII:
  533. case E1000_DEV_ID_82580_COPPER_DUAL:
  534. case E1000_DEV_ID_DH89XXCC_SGMII:
  535. case E1000_DEV_ID_DH89XXCC_SERDES:
  536. case E1000_DEV_ID_DH89XXCC_BACKPLANE:
  537. case E1000_DEV_ID_DH89XXCC_SFP:
  538. mac->type = e1000_82580;
  539. break;
  540. case E1000_DEV_ID_I350_COPPER:
  541. case E1000_DEV_ID_I350_FIBER:
  542. case E1000_DEV_ID_I350_SERDES:
  543. case E1000_DEV_ID_I350_SGMII:
  544. mac->type = e1000_i350;
  545. break;
  546. case E1000_DEV_ID_I210_COPPER:
  547. case E1000_DEV_ID_I210_FIBER:
  548. case E1000_DEV_ID_I210_SERDES:
  549. case E1000_DEV_ID_I210_SGMII:
  550. case E1000_DEV_ID_I210_COPPER_FLASHLESS:
  551. case E1000_DEV_ID_I210_SERDES_FLASHLESS:
  552. mac->type = e1000_i210;
  553. break;
  554. case E1000_DEV_ID_I211_COPPER:
  555. mac->type = e1000_i211;
  556. break;
  557. case E1000_DEV_ID_I354_BACKPLANE_1GBPS:
  558. case E1000_DEV_ID_I354_SGMII:
  559. case E1000_DEV_ID_I354_BACKPLANE_2_5GBPS:
  560. mac->type = e1000_i354;
  561. break;
  562. default:
  563. return -E1000_ERR_MAC_INIT;
  564. }
  565. /* Set media type */
  566. /* The 82575 uses bits 22:23 for link mode. The mode can be changed
  567. * based on the EEPROM. We cannot rely upon device ID. There
  568. * is no distinguishable difference between fiber and internal
  569. * SerDes mode on the 82575. There can be an external PHY attached
  570. * on the SGMII interface. For this, we'll set sgmii_active to true.
  571. */
  572. hw->phy.media_type = e1000_media_type_copper;
  573. dev_spec->sgmii_active = false;
  574. dev_spec->module_plugged = false;
  575. ctrl_ext = rd32(E1000_CTRL_EXT);
  576. link_mode = ctrl_ext & E1000_CTRL_EXT_LINK_MODE_MASK;
  577. switch (link_mode) {
  578. case E1000_CTRL_EXT_LINK_MODE_1000BASE_KX:
  579. hw->phy.media_type = e1000_media_type_internal_serdes;
  580. break;
  581. case E1000_CTRL_EXT_LINK_MODE_SGMII:
  582. /* Get phy control interface type set (MDIO vs. I2C)*/
  583. if (igb_sgmii_uses_mdio_82575(hw)) {
  584. hw->phy.media_type = e1000_media_type_copper;
  585. dev_spec->sgmii_active = true;
  586. break;
  587. }
  588. /* fall through for I2C based SGMII */
  589. case E1000_CTRL_EXT_LINK_MODE_PCIE_SERDES:
  590. /* read media type from SFP EEPROM */
  591. ret_val = igb_set_sfp_media_type_82575(hw);
  592. if ((ret_val != 0) ||
  593. (hw->phy.media_type == e1000_media_type_unknown)) {
  594. /* If media type was not identified then return media
  595. * type defined by the CTRL_EXT settings.
  596. */
  597. hw->phy.media_type = e1000_media_type_internal_serdes;
  598. if (link_mode == E1000_CTRL_EXT_LINK_MODE_SGMII) {
  599. hw->phy.media_type = e1000_media_type_copper;
  600. dev_spec->sgmii_active = true;
  601. }
  602. break;
  603. }
  604. /* do not change link mode for 100BaseFX */
  605. if (dev_spec->eth_flags.e100_base_fx)
  606. break;
  607. /* change current link mode setting */
  608. ctrl_ext &= ~E1000_CTRL_EXT_LINK_MODE_MASK;
  609. if (hw->phy.media_type == e1000_media_type_copper)
  610. ctrl_ext |= E1000_CTRL_EXT_LINK_MODE_SGMII;
  611. else
  612. ctrl_ext |= E1000_CTRL_EXT_LINK_MODE_PCIE_SERDES;
  613. wr32(E1000_CTRL_EXT, ctrl_ext);
  614. break;
  615. default:
  616. break;
  617. }
  618. /* mac initialization and operations */
  619. ret_val = igb_init_mac_params_82575(hw);
  620. if (ret_val)
  621. goto out;
  622. /* NVM initialization */
  623. ret_val = igb_init_nvm_params_82575(hw);
  624. switch (hw->mac.type) {
  625. case e1000_i210:
  626. case e1000_i211:
  627. ret_val = igb_init_nvm_params_i210(hw);
  628. break;
  629. default:
  630. break;
  631. }
  632. if (ret_val)
  633. goto out;
  634. /* if part supports SR-IOV then initialize mailbox parameters */
  635. switch (mac->type) {
  636. case e1000_82576:
  637. case e1000_i350:
  638. igb_init_mbx_params_pf(hw);
  639. break;
  640. default:
  641. break;
  642. }
  643. /* setup PHY parameters */
  644. ret_val = igb_init_phy_params_82575(hw);
  645. out:
  646. return ret_val;
  647. }
  648. /**
  649. * igb_acquire_phy_82575 - Acquire rights to access PHY
  650. * @hw: pointer to the HW structure
  651. *
  652. * Acquire access rights to the correct PHY. This is a
  653. * function pointer entry point called by the api module.
  654. **/
  655. static s32 igb_acquire_phy_82575(struct e1000_hw *hw)
  656. {
  657. u16 mask = E1000_SWFW_PHY0_SM;
  658. if (hw->bus.func == E1000_FUNC_1)
  659. mask = E1000_SWFW_PHY1_SM;
  660. else if (hw->bus.func == E1000_FUNC_2)
  661. mask = E1000_SWFW_PHY2_SM;
  662. else if (hw->bus.func == E1000_FUNC_3)
  663. mask = E1000_SWFW_PHY3_SM;
  664. return hw->mac.ops.acquire_swfw_sync(hw, mask);
  665. }
  666. /**
  667. * igb_release_phy_82575 - Release rights to access PHY
  668. * @hw: pointer to the HW structure
  669. *
  670. * A wrapper to release access rights to the correct PHY. This is a
  671. * function pointer entry point called by the api module.
  672. **/
  673. static void igb_release_phy_82575(struct e1000_hw *hw)
  674. {
  675. u16 mask = E1000_SWFW_PHY0_SM;
  676. if (hw->bus.func == E1000_FUNC_1)
  677. mask = E1000_SWFW_PHY1_SM;
  678. else if (hw->bus.func == E1000_FUNC_2)
  679. mask = E1000_SWFW_PHY2_SM;
  680. else if (hw->bus.func == E1000_FUNC_3)
  681. mask = E1000_SWFW_PHY3_SM;
  682. hw->mac.ops.release_swfw_sync(hw, mask);
  683. }
  684. /**
  685. * igb_read_phy_reg_sgmii_82575 - Read PHY register using sgmii
  686. * @hw: pointer to the HW structure
  687. * @offset: register offset to be read
  688. * @data: pointer to the read data
  689. *
  690. * Reads the PHY register at offset using the serial gigabit media independent
  691. * interface and stores the retrieved information in data.
  692. **/
  693. static s32 igb_read_phy_reg_sgmii_82575(struct e1000_hw *hw, u32 offset,
  694. u16 *data)
  695. {
  696. s32 ret_val = -E1000_ERR_PARAM;
  697. if (offset > E1000_MAX_SGMII_PHY_REG_ADDR) {
  698. hw_dbg("PHY Address %u is out of range\n", offset);
  699. goto out;
  700. }
  701. ret_val = hw->phy.ops.acquire(hw);
  702. if (ret_val)
  703. goto out;
  704. ret_val = igb_read_phy_reg_i2c(hw, offset, data);
  705. hw->phy.ops.release(hw);
  706. out:
  707. return ret_val;
  708. }
  709. /**
  710. * igb_write_phy_reg_sgmii_82575 - Write PHY register using sgmii
  711. * @hw: pointer to the HW structure
  712. * @offset: register offset to write to
  713. * @data: data to write at register offset
  714. *
  715. * Writes the data to PHY register at the offset using the serial gigabit
  716. * media independent interface.
  717. **/
  718. static s32 igb_write_phy_reg_sgmii_82575(struct e1000_hw *hw, u32 offset,
  719. u16 data)
  720. {
  721. s32 ret_val = -E1000_ERR_PARAM;
  722. if (offset > E1000_MAX_SGMII_PHY_REG_ADDR) {
  723. hw_dbg("PHY Address %d is out of range\n", offset);
  724. goto out;
  725. }
  726. ret_val = hw->phy.ops.acquire(hw);
  727. if (ret_val)
  728. goto out;
  729. ret_val = igb_write_phy_reg_i2c(hw, offset, data);
  730. hw->phy.ops.release(hw);
  731. out:
  732. return ret_val;
  733. }
  734. /**
  735. * igb_get_phy_id_82575 - Retrieve PHY addr and id
  736. * @hw: pointer to the HW structure
  737. *
  738. * Retrieves the PHY address and ID for both PHY's which do and do not use
  739. * sgmi interface.
  740. **/
  741. static s32 igb_get_phy_id_82575(struct e1000_hw *hw)
  742. {
  743. struct e1000_phy_info *phy = &hw->phy;
  744. s32 ret_val = 0;
  745. u16 phy_id;
  746. u32 ctrl_ext;
  747. u32 mdic;
  748. /* Extra read required for some PHY's on i354 */
  749. if (hw->mac.type == e1000_i354)
  750. igb_get_phy_id(hw);
  751. /* For SGMII PHYs, we try the list of possible addresses until
  752. * we find one that works. For non-SGMII PHYs
  753. * (e.g. integrated copper PHYs), an address of 1 should
  754. * work. The result of this function should mean phy->phy_addr
  755. * and phy->id are set correctly.
  756. */
  757. if (!(igb_sgmii_active_82575(hw))) {
  758. phy->addr = 1;
  759. ret_val = igb_get_phy_id(hw);
  760. goto out;
  761. }
  762. if (igb_sgmii_uses_mdio_82575(hw)) {
  763. switch (hw->mac.type) {
  764. case e1000_82575:
  765. case e1000_82576:
  766. mdic = rd32(E1000_MDIC);
  767. mdic &= E1000_MDIC_PHY_MASK;
  768. phy->addr = mdic >> E1000_MDIC_PHY_SHIFT;
  769. break;
  770. case e1000_82580:
  771. case e1000_i350:
  772. case e1000_i354:
  773. case e1000_i210:
  774. case e1000_i211:
  775. mdic = rd32(E1000_MDICNFG);
  776. mdic &= E1000_MDICNFG_PHY_MASK;
  777. phy->addr = mdic >> E1000_MDICNFG_PHY_SHIFT;
  778. break;
  779. default:
  780. ret_val = -E1000_ERR_PHY;
  781. goto out;
  782. }
  783. ret_val = igb_get_phy_id(hw);
  784. goto out;
  785. }
  786. /* Power on sgmii phy if it is disabled */
  787. ctrl_ext = rd32(E1000_CTRL_EXT);
  788. wr32(E1000_CTRL_EXT, ctrl_ext & ~E1000_CTRL_EXT_SDP3_DATA);
  789. wrfl();
  790. msleep(300);
  791. /* The address field in the I2CCMD register is 3 bits and 0 is invalid.
  792. * Therefore, we need to test 1-7
  793. */
  794. for (phy->addr = 1; phy->addr < 8; phy->addr++) {
  795. ret_val = igb_read_phy_reg_sgmii_82575(hw, PHY_ID1, &phy_id);
  796. if (ret_val == 0) {
  797. hw_dbg("Vendor ID 0x%08X read at address %u\n",
  798. phy_id, phy->addr);
  799. /* At the time of this writing, The M88 part is
  800. * the only supported SGMII PHY product.
  801. */
  802. if (phy_id == M88_VENDOR)
  803. break;
  804. } else {
  805. hw_dbg("PHY address %u was unreadable\n", phy->addr);
  806. }
  807. }
  808. /* A valid PHY type couldn't be found. */
  809. if (phy->addr == 8) {
  810. phy->addr = 0;
  811. ret_val = -E1000_ERR_PHY;
  812. goto out;
  813. } else {
  814. ret_val = igb_get_phy_id(hw);
  815. }
  816. /* restore previous sfp cage power state */
  817. wr32(E1000_CTRL_EXT, ctrl_ext);
  818. out:
  819. return ret_val;
  820. }
  821. /**
  822. * igb_phy_hw_reset_sgmii_82575 - Performs a PHY reset
  823. * @hw: pointer to the HW structure
  824. *
  825. * Resets the PHY using the serial gigabit media independent interface.
  826. **/
  827. static s32 igb_phy_hw_reset_sgmii_82575(struct e1000_hw *hw)
  828. {
  829. struct e1000_phy_info *phy = &hw->phy;
  830. s32 ret_val;
  831. /* This isn't a true "hard" reset, but is the only reset
  832. * available to us at this time.
  833. */
  834. hw_dbg("Soft resetting SGMII attached PHY...\n");
  835. /* SFP documentation requires the following to configure the SPF module
  836. * to work on SGMII. No further documentation is given.
  837. */
  838. ret_val = hw->phy.ops.write_reg(hw, 0x1B, 0x8084);
  839. if (ret_val)
  840. goto out;
  841. ret_val = igb_phy_sw_reset(hw);
  842. if (ret_val)
  843. goto out;
  844. if (phy->id == M88E1512_E_PHY_ID)
  845. ret_val = igb_initialize_M88E1512_phy(hw);
  846. if (phy->id == M88E1543_E_PHY_ID)
  847. ret_val = igb_initialize_M88E1543_phy(hw);
  848. out:
  849. return ret_val;
  850. }
  851. /**
  852. * igb_set_d0_lplu_state_82575 - Set Low Power Linkup D0 state
  853. * @hw: pointer to the HW structure
  854. * @active: true to enable LPLU, false to disable
  855. *
  856. * Sets the LPLU D0 state according to the active flag. When
  857. * activating LPLU this function also disables smart speed
  858. * and vice versa. LPLU will not be activated unless the
  859. * device autonegotiation advertisement meets standards of
  860. * either 10 or 10/100 or 10/100/1000 at all duplexes.
  861. * This is a function pointer entry point only called by
  862. * PHY setup routines.
  863. **/
  864. static s32 igb_set_d0_lplu_state_82575(struct e1000_hw *hw, bool active)
  865. {
  866. struct e1000_phy_info *phy = &hw->phy;
  867. s32 ret_val;
  868. u16 data;
  869. ret_val = phy->ops.read_reg(hw, IGP02E1000_PHY_POWER_MGMT, &data);
  870. if (ret_val)
  871. goto out;
  872. if (active) {
  873. data |= IGP02E1000_PM_D0_LPLU;
  874. ret_val = phy->ops.write_reg(hw, IGP02E1000_PHY_POWER_MGMT,
  875. data);
  876. if (ret_val)
  877. goto out;
  878. /* When LPLU is enabled, we should disable SmartSpeed */
  879. ret_val = phy->ops.read_reg(hw, IGP01E1000_PHY_PORT_CONFIG,
  880. &data);
  881. data &= ~IGP01E1000_PSCFR_SMART_SPEED;
  882. ret_val = phy->ops.write_reg(hw, IGP01E1000_PHY_PORT_CONFIG,
  883. data);
  884. if (ret_val)
  885. goto out;
  886. } else {
  887. data &= ~IGP02E1000_PM_D0_LPLU;
  888. ret_val = phy->ops.write_reg(hw, IGP02E1000_PHY_POWER_MGMT,
  889. data);
  890. /* LPLU and SmartSpeed are mutually exclusive. LPLU is used
  891. * during Dx states where the power conservation is most
  892. * important. During driver activity we should enable
  893. * SmartSpeed, so performance is maintained.
  894. */
  895. if (phy->smart_speed == e1000_smart_speed_on) {
  896. ret_val = phy->ops.read_reg(hw,
  897. IGP01E1000_PHY_PORT_CONFIG, &data);
  898. if (ret_val)
  899. goto out;
  900. data |= IGP01E1000_PSCFR_SMART_SPEED;
  901. ret_val = phy->ops.write_reg(hw,
  902. IGP01E1000_PHY_PORT_CONFIG, data);
  903. if (ret_val)
  904. goto out;
  905. } else if (phy->smart_speed == e1000_smart_speed_off) {
  906. ret_val = phy->ops.read_reg(hw,
  907. IGP01E1000_PHY_PORT_CONFIG, &data);
  908. if (ret_val)
  909. goto out;
  910. data &= ~IGP01E1000_PSCFR_SMART_SPEED;
  911. ret_val = phy->ops.write_reg(hw,
  912. IGP01E1000_PHY_PORT_CONFIG, data);
  913. if (ret_val)
  914. goto out;
  915. }
  916. }
  917. out:
  918. return ret_val;
  919. }
  920. /**
  921. * igb_set_d0_lplu_state_82580 - Set Low Power Linkup D0 state
  922. * @hw: pointer to the HW structure
  923. * @active: true to enable LPLU, false to disable
  924. *
  925. * Sets the LPLU D0 state according to the active flag. When
  926. * activating LPLU this function also disables smart speed
  927. * and vice versa. LPLU will not be activated unless the
  928. * device autonegotiation advertisement meets standards of
  929. * either 10 or 10/100 or 10/100/1000 at all duplexes.
  930. * This is a function pointer entry point only called by
  931. * PHY setup routines.
  932. **/
  933. static s32 igb_set_d0_lplu_state_82580(struct e1000_hw *hw, bool active)
  934. {
  935. struct e1000_phy_info *phy = &hw->phy;
  936. u16 data;
  937. data = rd32(E1000_82580_PHY_POWER_MGMT);
  938. if (active) {
  939. data |= E1000_82580_PM_D0_LPLU;
  940. /* When LPLU is enabled, we should disable SmartSpeed */
  941. data &= ~E1000_82580_PM_SPD;
  942. } else {
  943. data &= ~E1000_82580_PM_D0_LPLU;
  944. /* LPLU and SmartSpeed are mutually exclusive. LPLU is used
  945. * during Dx states where the power conservation is most
  946. * important. During driver activity we should enable
  947. * SmartSpeed, so performance is maintained.
  948. */
  949. if (phy->smart_speed == e1000_smart_speed_on)
  950. data |= E1000_82580_PM_SPD;
  951. else if (phy->smart_speed == e1000_smart_speed_off)
  952. data &= ~E1000_82580_PM_SPD; }
  953. wr32(E1000_82580_PHY_POWER_MGMT, data);
  954. return 0;
  955. }
  956. /**
  957. * igb_set_d3_lplu_state_82580 - Sets low power link up state for D3
  958. * @hw: pointer to the HW structure
  959. * @active: boolean used to enable/disable lplu
  960. *
  961. * Success returns 0, Failure returns 1
  962. *
  963. * The low power link up (lplu) state is set to the power management level D3
  964. * and SmartSpeed is disabled when active is true, else clear lplu for D3
  965. * and enable Smartspeed. LPLU and Smartspeed are mutually exclusive. LPLU
  966. * is used during Dx states where the power conservation is most important.
  967. * During driver activity, SmartSpeed should be enabled so performance is
  968. * maintained.
  969. **/
  970. static s32 igb_set_d3_lplu_state_82580(struct e1000_hw *hw, bool active)
  971. {
  972. struct e1000_phy_info *phy = &hw->phy;
  973. u16 data;
  974. data = rd32(E1000_82580_PHY_POWER_MGMT);
  975. if (!active) {
  976. data &= ~E1000_82580_PM_D3_LPLU;
  977. /* LPLU and SmartSpeed are mutually exclusive. LPLU is used
  978. * during Dx states where the power conservation is most
  979. * important. During driver activity we should enable
  980. * SmartSpeed, so performance is maintained.
  981. */
  982. if (phy->smart_speed == e1000_smart_speed_on)
  983. data |= E1000_82580_PM_SPD;
  984. else if (phy->smart_speed == e1000_smart_speed_off)
  985. data &= ~E1000_82580_PM_SPD;
  986. } else if ((phy->autoneg_advertised == E1000_ALL_SPEED_DUPLEX) ||
  987. (phy->autoneg_advertised == E1000_ALL_NOT_GIG) ||
  988. (phy->autoneg_advertised == E1000_ALL_10_SPEED)) {
  989. data |= E1000_82580_PM_D3_LPLU;
  990. /* When LPLU is enabled, we should disable SmartSpeed */
  991. data &= ~E1000_82580_PM_SPD;
  992. }
  993. wr32(E1000_82580_PHY_POWER_MGMT, data);
  994. return 0;
  995. }
  996. /**
  997. * igb_acquire_nvm_82575 - Request for access to EEPROM
  998. * @hw: pointer to the HW structure
  999. *
  1000. * Acquire the necessary semaphores for exclusive access to the EEPROM.
  1001. * Set the EEPROM access request bit and wait for EEPROM access grant bit.
  1002. * Return successful if access grant bit set, else clear the request for
  1003. * EEPROM access and return -E1000_ERR_NVM (-1).
  1004. **/
  1005. static s32 igb_acquire_nvm_82575(struct e1000_hw *hw)
  1006. {
  1007. s32 ret_val;
  1008. ret_val = hw->mac.ops.acquire_swfw_sync(hw, E1000_SWFW_EEP_SM);
  1009. if (ret_val)
  1010. goto out;
  1011. ret_val = igb_acquire_nvm(hw);
  1012. if (ret_val)
  1013. hw->mac.ops.release_swfw_sync(hw, E1000_SWFW_EEP_SM);
  1014. out:
  1015. return ret_val;
  1016. }
  1017. /**
  1018. * igb_release_nvm_82575 - Release exclusive access to EEPROM
  1019. * @hw: pointer to the HW structure
  1020. *
  1021. * Stop any current commands to the EEPROM and clear the EEPROM request bit,
  1022. * then release the semaphores acquired.
  1023. **/
  1024. static void igb_release_nvm_82575(struct e1000_hw *hw)
  1025. {
  1026. igb_release_nvm(hw);
  1027. hw->mac.ops.release_swfw_sync(hw, E1000_SWFW_EEP_SM);
  1028. }
  1029. /**
  1030. * igb_acquire_swfw_sync_82575 - Acquire SW/FW semaphore
  1031. * @hw: pointer to the HW structure
  1032. * @mask: specifies which semaphore to acquire
  1033. *
  1034. * Acquire the SW/FW semaphore to access the PHY or NVM. The mask
  1035. * will also specify which port we're acquiring the lock for.
  1036. **/
  1037. static s32 igb_acquire_swfw_sync_82575(struct e1000_hw *hw, u16 mask)
  1038. {
  1039. u32 swfw_sync;
  1040. u32 swmask = mask;
  1041. u32 fwmask = mask << 16;
  1042. s32 ret_val = 0;
  1043. s32 i = 0, timeout = 200;
  1044. while (i < timeout) {
  1045. if (igb_get_hw_semaphore(hw)) {
  1046. ret_val = -E1000_ERR_SWFW_SYNC;
  1047. goto out;
  1048. }
  1049. swfw_sync = rd32(E1000_SW_FW_SYNC);
  1050. if (!(swfw_sync & (fwmask | swmask)))
  1051. break;
  1052. /* Firmware currently using resource (fwmask)
  1053. * or other software thread using resource (swmask)
  1054. */
  1055. igb_put_hw_semaphore(hw);
  1056. mdelay(5);
  1057. i++;
  1058. }
  1059. if (i == timeout) {
  1060. hw_dbg("Driver can't access resource, SW_FW_SYNC timeout.\n");
  1061. ret_val = -E1000_ERR_SWFW_SYNC;
  1062. goto out;
  1063. }
  1064. swfw_sync |= swmask;
  1065. wr32(E1000_SW_FW_SYNC, swfw_sync);
  1066. igb_put_hw_semaphore(hw);
  1067. out:
  1068. return ret_val;
  1069. }
  1070. /**
  1071. * igb_release_swfw_sync_82575 - Release SW/FW semaphore
  1072. * @hw: pointer to the HW structure
  1073. * @mask: specifies which semaphore to acquire
  1074. *
  1075. * Release the SW/FW semaphore used to access the PHY or NVM. The mask
  1076. * will also specify which port we're releasing the lock for.
  1077. **/
  1078. static void igb_release_swfw_sync_82575(struct e1000_hw *hw, u16 mask)
  1079. {
  1080. u32 swfw_sync;
  1081. while (igb_get_hw_semaphore(hw) != 0)
  1082. ; /* Empty */
  1083. swfw_sync = rd32(E1000_SW_FW_SYNC);
  1084. swfw_sync &= ~mask;
  1085. wr32(E1000_SW_FW_SYNC, swfw_sync);
  1086. igb_put_hw_semaphore(hw);
  1087. }
  1088. /**
  1089. * igb_get_cfg_done_82575 - Read config done bit
  1090. * @hw: pointer to the HW structure
  1091. *
  1092. * Read the management control register for the config done bit for
  1093. * completion status. NOTE: silicon which is EEPROM-less will fail trying
  1094. * to read the config done bit, so an error is *ONLY* logged and returns
  1095. * 0. If we were to return with error, EEPROM-less silicon
  1096. * would not be able to be reset or change link.
  1097. **/
  1098. static s32 igb_get_cfg_done_82575(struct e1000_hw *hw)
  1099. {
  1100. s32 timeout = PHY_CFG_TIMEOUT;
  1101. u32 mask = E1000_NVM_CFG_DONE_PORT_0;
  1102. if (hw->bus.func == 1)
  1103. mask = E1000_NVM_CFG_DONE_PORT_1;
  1104. else if (hw->bus.func == E1000_FUNC_2)
  1105. mask = E1000_NVM_CFG_DONE_PORT_2;
  1106. else if (hw->bus.func == E1000_FUNC_3)
  1107. mask = E1000_NVM_CFG_DONE_PORT_3;
  1108. while (timeout) {
  1109. if (rd32(E1000_EEMNGCTL) & mask)
  1110. break;
  1111. usleep_range(1000, 2000);
  1112. timeout--;
  1113. }
  1114. if (!timeout)
  1115. hw_dbg("MNG configuration cycle has not completed.\n");
  1116. /* If EEPROM is not marked present, init the PHY manually */
  1117. if (((rd32(E1000_EECD) & E1000_EECD_PRES) == 0) &&
  1118. (hw->phy.type == e1000_phy_igp_3))
  1119. igb_phy_init_script_igp3(hw);
  1120. return 0;
  1121. }
  1122. /**
  1123. * igb_get_link_up_info_82575 - Get link speed/duplex info
  1124. * @hw: pointer to the HW structure
  1125. * @speed: stores the current speed
  1126. * @duplex: stores the current duplex
  1127. *
  1128. * This is a wrapper function, if using the serial gigabit media independent
  1129. * interface, use PCS to retrieve the link speed and duplex information.
  1130. * Otherwise, use the generic function to get the link speed and duplex info.
  1131. **/
  1132. static s32 igb_get_link_up_info_82575(struct e1000_hw *hw, u16 *speed,
  1133. u16 *duplex)
  1134. {
  1135. s32 ret_val;
  1136. if (hw->phy.media_type != e1000_media_type_copper)
  1137. ret_val = igb_get_pcs_speed_and_duplex_82575(hw, speed,
  1138. duplex);
  1139. else
  1140. ret_val = igb_get_speed_and_duplex_copper(hw, speed,
  1141. duplex);
  1142. return ret_val;
  1143. }
  1144. /**
  1145. * igb_check_for_link_82575 - Check for link
  1146. * @hw: pointer to the HW structure
  1147. *
  1148. * If sgmii is enabled, then use the pcs register to determine link, otherwise
  1149. * use the generic interface for determining link.
  1150. **/
  1151. static s32 igb_check_for_link_82575(struct e1000_hw *hw)
  1152. {
  1153. s32 ret_val;
  1154. u16 speed, duplex;
  1155. if (hw->phy.media_type != e1000_media_type_copper) {
  1156. ret_val = igb_get_pcs_speed_and_duplex_82575(hw, &speed,
  1157. &duplex);
  1158. /* Use this flag to determine if link needs to be checked or
  1159. * not. If we have link clear the flag so that we do not
  1160. * continue to check for link.
  1161. */
  1162. hw->mac.get_link_status = !hw->mac.serdes_has_link;
  1163. /* Configure Flow Control now that Auto-Neg has completed.
  1164. * First, we need to restore the desired flow control
  1165. * settings because we may have had to re-autoneg with a
  1166. * different link partner.
  1167. */
  1168. ret_val = igb_config_fc_after_link_up(hw);
  1169. if (ret_val)
  1170. hw_dbg("Error configuring flow control\n");
  1171. } else {
  1172. ret_val = igb_check_for_copper_link(hw);
  1173. }
  1174. return ret_val;
  1175. }
  1176. /**
  1177. * igb_power_up_serdes_link_82575 - Power up the serdes link after shutdown
  1178. * @hw: pointer to the HW structure
  1179. **/
  1180. void igb_power_up_serdes_link_82575(struct e1000_hw *hw)
  1181. {
  1182. u32 reg;
  1183. if ((hw->phy.media_type != e1000_media_type_internal_serdes) &&
  1184. !igb_sgmii_active_82575(hw))
  1185. return;
  1186. /* Enable PCS to turn on link */
  1187. reg = rd32(E1000_PCS_CFG0);
  1188. reg |= E1000_PCS_CFG_PCS_EN;
  1189. wr32(E1000_PCS_CFG0, reg);
  1190. /* Power up the laser */
  1191. reg = rd32(E1000_CTRL_EXT);
  1192. reg &= ~E1000_CTRL_EXT_SDP3_DATA;
  1193. wr32(E1000_CTRL_EXT, reg);
  1194. /* flush the write to verify completion */
  1195. wrfl();
  1196. usleep_range(1000, 2000);
  1197. }
  1198. /**
  1199. * igb_get_pcs_speed_and_duplex_82575 - Retrieve current speed/duplex
  1200. * @hw: pointer to the HW structure
  1201. * @speed: stores the current speed
  1202. * @duplex: stores the current duplex
  1203. *
  1204. * Using the physical coding sub-layer (PCS), retrieve the current speed and
  1205. * duplex, then store the values in the pointers provided.
  1206. **/
  1207. static s32 igb_get_pcs_speed_and_duplex_82575(struct e1000_hw *hw, u16 *speed,
  1208. u16 *duplex)
  1209. {
  1210. struct e1000_mac_info *mac = &hw->mac;
  1211. u32 pcs, status;
  1212. /* Set up defaults for the return values of this function */
  1213. mac->serdes_has_link = false;
  1214. *speed = 0;
  1215. *duplex = 0;
  1216. /* Read the PCS Status register for link state. For non-copper mode,
  1217. * the status register is not accurate. The PCS status register is
  1218. * used instead.
  1219. */
  1220. pcs = rd32(E1000_PCS_LSTAT);
  1221. /* The link up bit determines when link is up on autoneg. The sync ok
  1222. * gets set once both sides sync up and agree upon link. Stable link
  1223. * can be determined by checking for both link up and link sync ok
  1224. */
  1225. if ((pcs & E1000_PCS_LSTS_LINK_OK) && (pcs & E1000_PCS_LSTS_SYNK_OK)) {
  1226. mac->serdes_has_link = true;
  1227. /* Detect and store PCS speed */
  1228. if (pcs & E1000_PCS_LSTS_SPEED_1000)
  1229. *speed = SPEED_1000;
  1230. else if (pcs & E1000_PCS_LSTS_SPEED_100)
  1231. *speed = SPEED_100;
  1232. else
  1233. *speed = SPEED_10;
  1234. /* Detect and store PCS duplex */
  1235. if (pcs & E1000_PCS_LSTS_DUPLEX_FULL)
  1236. *duplex = FULL_DUPLEX;
  1237. else
  1238. *duplex = HALF_DUPLEX;
  1239. /* Check if it is an I354 2.5Gb backplane connection. */
  1240. if (mac->type == e1000_i354) {
  1241. status = rd32(E1000_STATUS);
  1242. if ((status & E1000_STATUS_2P5_SKU) &&
  1243. !(status & E1000_STATUS_2P5_SKU_OVER)) {
  1244. *speed = SPEED_2500;
  1245. *duplex = FULL_DUPLEX;
  1246. hw_dbg("2500 Mbs, ");
  1247. hw_dbg("Full Duplex\n");
  1248. }
  1249. }
  1250. }
  1251. return 0;
  1252. }
  1253. /**
  1254. * igb_shutdown_serdes_link_82575 - Remove link during power down
  1255. * @hw: pointer to the HW structure
  1256. *
  1257. * In the case of fiber serdes, shut down optics and PCS on driver unload
  1258. * when management pass thru is not enabled.
  1259. **/
  1260. void igb_shutdown_serdes_link_82575(struct e1000_hw *hw)
  1261. {
  1262. u32 reg;
  1263. if (hw->phy.media_type != e1000_media_type_internal_serdes &&
  1264. igb_sgmii_active_82575(hw))
  1265. return;
  1266. if (!igb_enable_mng_pass_thru(hw)) {
  1267. /* Disable PCS to turn off link */
  1268. reg = rd32(E1000_PCS_CFG0);
  1269. reg &= ~E1000_PCS_CFG_PCS_EN;
  1270. wr32(E1000_PCS_CFG0, reg);
  1271. /* shutdown the laser */
  1272. reg = rd32(E1000_CTRL_EXT);
  1273. reg |= E1000_CTRL_EXT_SDP3_DATA;
  1274. wr32(E1000_CTRL_EXT, reg);
  1275. /* flush the write to verify completion */
  1276. wrfl();
  1277. usleep_range(1000, 2000);
  1278. }
  1279. }
  1280. /**
  1281. * igb_reset_hw_82575 - Reset hardware
  1282. * @hw: pointer to the HW structure
  1283. *
  1284. * This resets the hardware into a known state. This is a
  1285. * function pointer entry point called by the api module.
  1286. **/
  1287. static s32 igb_reset_hw_82575(struct e1000_hw *hw)
  1288. {
  1289. u32 ctrl;
  1290. s32 ret_val;
  1291. /* Prevent the PCI-E bus from sticking if there is no TLP connection
  1292. * on the last TLP read/write transaction when MAC is reset.
  1293. */
  1294. ret_val = igb_disable_pcie_master(hw);
  1295. if (ret_val)
  1296. hw_dbg("PCI-E Master disable polling has failed.\n");
  1297. /* set the completion timeout for interface */
  1298. ret_val = igb_set_pcie_completion_timeout(hw);
  1299. if (ret_val)
  1300. hw_dbg("PCI-E Set completion timeout has failed.\n");
  1301. hw_dbg("Masking off all interrupts\n");
  1302. wr32(E1000_IMC, 0xffffffff);
  1303. wr32(E1000_RCTL, 0);
  1304. wr32(E1000_TCTL, E1000_TCTL_PSP);
  1305. wrfl();
  1306. usleep_range(10000, 20000);
  1307. ctrl = rd32(E1000_CTRL);
  1308. hw_dbg("Issuing a global reset to MAC\n");
  1309. wr32(E1000_CTRL, ctrl | E1000_CTRL_RST);
  1310. ret_val = igb_get_auto_rd_done(hw);
  1311. if (ret_val) {
  1312. /* When auto config read does not complete, do not
  1313. * return with an error. This can happen in situations
  1314. * where there is no eeprom and prevents getting link.
  1315. */
  1316. hw_dbg("Auto Read Done did not complete\n");
  1317. }
  1318. /* If EEPROM is not present, run manual init scripts */
  1319. if ((rd32(E1000_EECD) & E1000_EECD_PRES) == 0)
  1320. igb_reset_init_script_82575(hw);
  1321. /* Clear any pending interrupt events. */
  1322. wr32(E1000_IMC, 0xffffffff);
  1323. rd32(E1000_ICR);
  1324. /* Install any alternate MAC address into RAR0 */
  1325. ret_val = igb_check_alt_mac_addr(hw);
  1326. return ret_val;
  1327. }
  1328. /**
  1329. * igb_init_hw_82575 - Initialize hardware
  1330. * @hw: pointer to the HW structure
  1331. *
  1332. * This inits the hardware readying it for operation.
  1333. **/
  1334. static s32 igb_init_hw_82575(struct e1000_hw *hw)
  1335. {
  1336. struct e1000_mac_info *mac = &hw->mac;
  1337. s32 ret_val;
  1338. u16 i, rar_count = mac->rar_entry_count;
  1339. if ((hw->mac.type >= e1000_i210) &&
  1340. !(igb_get_flash_presence_i210(hw))) {
  1341. ret_val = igb_pll_workaround_i210(hw);
  1342. if (ret_val)
  1343. return ret_val;
  1344. }
  1345. /* Initialize identification LED */
  1346. ret_val = igb_id_led_init(hw);
  1347. if (ret_val) {
  1348. hw_dbg("Error initializing identification LED\n");
  1349. /* This is not fatal and we should not stop init due to this */
  1350. }
  1351. /* Disabling VLAN filtering */
  1352. hw_dbg("Initializing the IEEE VLAN\n");
  1353. igb_clear_vfta(hw);
  1354. /* Setup the receive address */
  1355. igb_init_rx_addrs(hw, rar_count);
  1356. /* Zero out the Multicast HASH table */
  1357. hw_dbg("Zeroing the MTA\n");
  1358. for (i = 0; i < mac->mta_reg_count; i++)
  1359. array_wr32(E1000_MTA, i, 0);
  1360. /* Zero out the Unicast HASH table */
  1361. hw_dbg("Zeroing the UTA\n");
  1362. for (i = 0; i < mac->uta_reg_count; i++)
  1363. array_wr32(E1000_UTA, i, 0);
  1364. /* Setup link and flow control */
  1365. ret_val = igb_setup_link(hw);
  1366. /* Clear all of the statistics registers (clear on read). It is
  1367. * important that we do this after we have tried to establish link
  1368. * because the symbol error count will increment wildly if there
  1369. * is no link.
  1370. */
  1371. igb_clear_hw_cntrs_82575(hw);
  1372. return ret_val;
  1373. }
  1374. /**
  1375. * igb_setup_copper_link_82575 - Configure copper link settings
  1376. * @hw: pointer to the HW structure
  1377. *
  1378. * Configures the link for auto-neg or forced speed and duplex. Then we check
  1379. * for link, once link is established calls to configure collision distance
  1380. * and flow control are called.
  1381. **/
  1382. static s32 igb_setup_copper_link_82575(struct e1000_hw *hw)
  1383. {
  1384. u32 ctrl;
  1385. s32 ret_val;
  1386. u32 phpm_reg;
  1387. ctrl = rd32(E1000_CTRL);
  1388. ctrl |= E1000_CTRL_SLU;
  1389. ctrl &= ~(E1000_CTRL_FRCSPD | E1000_CTRL_FRCDPX);
  1390. wr32(E1000_CTRL, ctrl);
  1391. /* Clear Go Link Disconnect bit on supported devices */
  1392. switch (hw->mac.type) {
  1393. case e1000_82580:
  1394. case e1000_i350:
  1395. case e1000_i210:
  1396. case e1000_i211:
  1397. phpm_reg = rd32(E1000_82580_PHY_POWER_MGMT);
  1398. phpm_reg &= ~E1000_82580_PM_GO_LINKD;
  1399. wr32(E1000_82580_PHY_POWER_MGMT, phpm_reg);
  1400. break;
  1401. default:
  1402. break;
  1403. }
  1404. ret_val = igb_setup_serdes_link_82575(hw);
  1405. if (ret_val)
  1406. goto out;
  1407. if (igb_sgmii_active_82575(hw) && !hw->phy.reset_disable) {
  1408. /* allow time for SFP cage time to power up phy */
  1409. msleep(300);
  1410. ret_val = hw->phy.ops.reset(hw);
  1411. if (ret_val) {
  1412. hw_dbg("Error resetting the PHY.\n");
  1413. goto out;
  1414. }
  1415. }
  1416. switch (hw->phy.type) {
  1417. case e1000_phy_i210:
  1418. case e1000_phy_m88:
  1419. switch (hw->phy.id) {
  1420. case I347AT4_E_PHY_ID:
  1421. case M88E1112_E_PHY_ID:
  1422. case M88E1543_E_PHY_ID:
  1423. case M88E1512_E_PHY_ID:
  1424. case I210_I_PHY_ID:
  1425. ret_val = igb_copper_link_setup_m88_gen2(hw);
  1426. break;
  1427. default:
  1428. ret_val = igb_copper_link_setup_m88(hw);
  1429. break;
  1430. }
  1431. break;
  1432. case e1000_phy_igp_3:
  1433. ret_val = igb_copper_link_setup_igp(hw);
  1434. break;
  1435. case e1000_phy_82580:
  1436. ret_val = igb_copper_link_setup_82580(hw);
  1437. break;
  1438. case e1000_phy_bcm54616:
  1439. ret_val = 0;
  1440. break;
  1441. default:
  1442. ret_val = -E1000_ERR_PHY;
  1443. break;
  1444. }
  1445. if (ret_val)
  1446. goto out;
  1447. ret_val = igb_setup_copper_link(hw);
  1448. out:
  1449. return ret_val;
  1450. }
  1451. /**
  1452. * igb_setup_serdes_link_82575 - Setup link for serdes
  1453. * @hw: pointer to the HW structure
  1454. *
  1455. * Configure the physical coding sub-layer (PCS) link. The PCS link is
  1456. * used on copper connections where the serialized gigabit media independent
  1457. * interface (sgmii), or serdes fiber is being used. Configures the link
  1458. * for auto-negotiation or forces speed/duplex.
  1459. **/
  1460. static s32 igb_setup_serdes_link_82575(struct e1000_hw *hw)
  1461. {
  1462. u32 ctrl_ext, ctrl_reg, reg, anadv_reg;
  1463. bool pcs_autoneg;
  1464. s32 ret_val = 0;
  1465. u16 data;
  1466. if ((hw->phy.media_type != e1000_media_type_internal_serdes) &&
  1467. !igb_sgmii_active_82575(hw))
  1468. return ret_val;
  1469. /* On the 82575, SerDes loopback mode persists until it is
  1470. * explicitly turned off or a power cycle is performed. A read to
  1471. * the register does not indicate its status. Therefore, we ensure
  1472. * loopback mode is disabled during initialization.
  1473. */
  1474. wr32(E1000_SCTL, E1000_SCTL_DISABLE_SERDES_LOOPBACK);
  1475. /* power on the sfp cage if present and turn on I2C */
  1476. ctrl_ext = rd32(E1000_CTRL_EXT);
  1477. ctrl_ext &= ~E1000_CTRL_EXT_SDP3_DATA;
  1478. ctrl_ext |= E1000_CTRL_I2C_ENA;
  1479. wr32(E1000_CTRL_EXT, ctrl_ext);
  1480. ctrl_reg = rd32(E1000_CTRL);
  1481. ctrl_reg |= E1000_CTRL_SLU;
  1482. if (hw->mac.type == e1000_82575 || hw->mac.type == e1000_82576) {
  1483. /* set both sw defined pins */
  1484. ctrl_reg |= E1000_CTRL_SWDPIN0 | E1000_CTRL_SWDPIN1;
  1485. /* Set switch control to serdes energy detect */
  1486. reg = rd32(E1000_CONNSW);
  1487. reg |= E1000_CONNSW_ENRGSRC;
  1488. wr32(E1000_CONNSW, reg);
  1489. }
  1490. reg = rd32(E1000_PCS_LCTL);
  1491. /* default pcs_autoneg to the same setting as mac autoneg */
  1492. pcs_autoneg = hw->mac.autoneg;
  1493. switch (ctrl_ext & E1000_CTRL_EXT_LINK_MODE_MASK) {
  1494. case E1000_CTRL_EXT_LINK_MODE_SGMII:
  1495. /* sgmii mode lets the phy handle forcing speed/duplex */
  1496. pcs_autoneg = true;
  1497. /* autoneg time out should be disabled for SGMII mode */
  1498. reg &= ~(E1000_PCS_LCTL_AN_TIMEOUT);
  1499. break;
  1500. case E1000_CTRL_EXT_LINK_MODE_1000BASE_KX:
  1501. /* disable PCS autoneg and support parallel detect only */
  1502. pcs_autoneg = false;
  1503. default:
  1504. if (hw->mac.type == e1000_82575 ||
  1505. hw->mac.type == e1000_82576) {
  1506. ret_val = hw->nvm.ops.read(hw, NVM_COMPAT, 1, &data);
  1507. if (ret_val) {
  1508. hw_dbg(KERN_DEBUG "NVM Read Error\n\n");
  1509. return ret_val;
  1510. }
  1511. if (data & E1000_EEPROM_PCS_AUTONEG_DISABLE_BIT)
  1512. pcs_autoneg = false;
  1513. }
  1514. /* non-SGMII modes only supports a speed of 1000/Full for the
  1515. * link so it is best to just force the MAC and let the pcs
  1516. * link either autoneg or be forced to 1000/Full
  1517. */
  1518. ctrl_reg |= E1000_CTRL_SPD_1000 | E1000_CTRL_FRCSPD |
  1519. E1000_CTRL_FD | E1000_CTRL_FRCDPX;
  1520. /* set speed of 1000/Full if speed/duplex is forced */
  1521. reg |= E1000_PCS_LCTL_FSV_1000 | E1000_PCS_LCTL_FDV_FULL;
  1522. break;
  1523. }
  1524. wr32(E1000_CTRL, ctrl_reg);
  1525. /* New SerDes mode allows for forcing speed or autonegotiating speed
  1526. * at 1gb. Autoneg should be default set by most drivers. This is the
  1527. * mode that will be compatible with older link partners and switches.
  1528. * However, both are supported by the hardware and some drivers/tools.
  1529. */
  1530. reg &= ~(E1000_PCS_LCTL_AN_ENABLE | E1000_PCS_LCTL_FLV_LINK_UP |
  1531. E1000_PCS_LCTL_FSD | E1000_PCS_LCTL_FORCE_LINK);
  1532. if (pcs_autoneg) {
  1533. /* Set PCS register for autoneg */
  1534. reg |= E1000_PCS_LCTL_AN_ENABLE | /* Enable Autoneg */
  1535. E1000_PCS_LCTL_AN_RESTART; /* Restart autoneg */
  1536. /* Disable force flow control for autoneg */
  1537. reg &= ~E1000_PCS_LCTL_FORCE_FCTRL;
  1538. /* Configure flow control advertisement for autoneg */
  1539. anadv_reg = rd32(E1000_PCS_ANADV);
  1540. anadv_reg &= ~(E1000_TXCW_ASM_DIR | E1000_TXCW_PAUSE);
  1541. switch (hw->fc.requested_mode) {
  1542. case e1000_fc_full:
  1543. case e1000_fc_rx_pause:
  1544. anadv_reg |= E1000_TXCW_ASM_DIR;
  1545. anadv_reg |= E1000_TXCW_PAUSE;
  1546. break;
  1547. case e1000_fc_tx_pause:
  1548. anadv_reg |= E1000_TXCW_ASM_DIR;
  1549. break;
  1550. default:
  1551. break;
  1552. }
  1553. wr32(E1000_PCS_ANADV, anadv_reg);
  1554. hw_dbg("Configuring Autoneg:PCS_LCTL=0x%08X\n", reg);
  1555. } else {
  1556. /* Set PCS register for forced link */
  1557. reg |= E1000_PCS_LCTL_FSD; /* Force Speed */
  1558. /* Force flow control for forced link */
  1559. reg |= E1000_PCS_LCTL_FORCE_FCTRL;
  1560. hw_dbg("Configuring Forced Link:PCS_LCTL=0x%08X\n", reg);
  1561. }
  1562. wr32(E1000_PCS_LCTL, reg);
  1563. if (!pcs_autoneg && !igb_sgmii_active_82575(hw))
  1564. igb_force_mac_fc(hw);
  1565. return ret_val;
  1566. }
  1567. /**
  1568. * igb_sgmii_active_82575 - Return sgmii state
  1569. * @hw: pointer to the HW structure
  1570. *
  1571. * 82575 silicon has a serialized gigabit media independent interface (sgmii)
  1572. * which can be enabled for use in the embedded applications. Simply
  1573. * return the current state of the sgmii interface.
  1574. **/
  1575. static bool igb_sgmii_active_82575(struct e1000_hw *hw)
  1576. {
  1577. struct e1000_dev_spec_82575 *dev_spec = &hw->dev_spec._82575;
  1578. return dev_spec->sgmii_active;
  1579. }
  1580. /**
  1581. * igb_reset_init_script_82575 - Inits HW defaults after reset
  1582. * @hw: pointer to the HW structure
  1583. *
  1584. * Inits recommended HW defaults after a reset when there is no EEPROM
  1585. * detected. This is only for the 82575.
  1586. **/
  1587. static s32 igb_reset_init_script_82575(struct e1000_hw *hw)
  1588. {
  1589. if (hw->mac.type == e1000_82575) {
  1590. hw_dbg("Running reset init script for 82575\n");
  1591. /* SerDes configuration via SERDESCTRL */
  1592. igb_write_8bit_ctrl_reg(hw, E1000_SCTL, 0x00, 0x0C);
  1593. igb_write_8bit_ctrl_reg(hw, E1000_SCTL, 0x01, 0x78);
  1594. igb_write_8bit_ctrl_reg(hw, E1000_SCTL, 0x1B, 0x23);
  1595. igb_write_8bit_ctrl_reg(hw, E1000_SCTL, 0x23, 0x15);
  1596. /* CCM configuration via CCMCTL register */
  1597. igb_write_8bit_ctrl_reg(hw, E1000_CCMCTL, 0x14, 0x00);
  1598. igb_write_8bit_ctrl_reg(hw, E1000_CCMCTL, 0x10, 0x00);
  1599. /* PCIe lanes configuration */
  1600. igb_write_8bit_ctrl_reg(hw, E1000_GIOCTL, 0x00, 0xEC);
  1601. igb_write_8bit_ctrl_reg(hw, E1000_GIOCTL, 0x61, 0xDF);
  1602. igb_write_8bit_ctrl_reg(hw, E1000_GIOCTL, 0x34, 0x05);
  1603. igb_write_8bit_ctrl_reg(hw, E1000_GIOCTL, 0x2F, 0x81);
  1604. /* PCIe PLL Configuration */
  1605. igb_write_8bit_ctrl_reg(hw, E1000_SCCTL, 0x02, 0x47);
  1606. igb_write_8bit_ctrl_reg(hw, E1000_SCCTL, 0x14, 0x00);
  1607. igb_write_8bit_ctrl_reg(hw, E1000_SCCTL, 0x10, 0x00);
  1608. }
  1609. return 0;
  1610. }
  1611. /**
  1612. * igb_read_mac_addr_82575 - Read device MAC address
  1613. * @hw: pointer to the HW structure
  1614. **/
  1615. static s32 igb_read_mac_addr_82575(struct e1000_hw *hw)
  1616. {
  1617. s32 ret_val = 0;
  1618. /* If there's an alternate MAC address place it in RAR0
  1619. * so that it will override the Si installed default perm
  1620. * address.
  1621. */
  1622. ret_val = igb_check_alt_mac_addr(hw);
  1623. if (ret_val)
  1624. goto out;
  1625. ret_val = igb_read_mac_addr(hw);
  1626. out:
  1627. return ret_val;
  1628. }
  1629. /**
  1630. * igb_power_down_phy_copper_82575 - Remove link during PHY power down
  1631. * @hw: pointer to the HW structure
  1632. *
  1633. * In the case of a PHY power down to save power, or to turn off link during a
  1634. * driver unload, or wake on lan is not enabled, remove the link.
  1635. **/
  1636. void igb_power_down_phy_copper_82575(struct e1000_hw *hw)
  1637. {
  1638. /* If the management interface is not enabled, then power down */
  1639. if (!(igb_enable_mng_pass_thru(hw) || igb_check_reset_block(hw)))
  1640. igb_power_down_phy_copper(hw);
  1641. }
  1642. /**
  1643. * igb_clear_hw_cntrs_82575 - Clear device specific hardware counters
  1644. * @hw: pointer to the HW structure
  1645. *
  1646. * Clears the hardware counters by reading the counter registers.
  1647. **/
  1648. static void igb_clear_hw_cntrs_82575(struct e1000_hw *hw)
  1649. {
  1650. igb_clear_hw_cntrs_base(hw);
  1651. rd32(E1000_PRC64);
  1652. rd32(E1000_PRC127);
  1653. rd32(E1000_PRC255);
  1654. rd32(E1000_PRC511);
  1655. rd32(E1000_PRC1023);
  1656. rd32(E1000_PRC1522);
  1657. rd32(E1000_PTC64);
  1658. rd32(E1000_PTC127);
  1659. rd32(E1000_PTC255);
  1660. rd32(E1000_PTC511);
  1661. rd32(E1000_PTC1023);
  1662. rd32(E1000_PTC1522);
  1663. rd32(E1000_ALGNERRC);
  1664. rd32(E1000_RXERRC);
  1665. rd32(E1000_TNCRS);
  1666. rd32(E1000_CEXTERR);
  1667. rd32(E1000_TSCTC);
  1668. rd32(E1000_TSCTFC);
  1669. rd32(E1000_MGTPRC);
  1670. rd32(E1000_MGTPDC);
  1671. rd32(E1000_MGTPTC);
  1672. rd32(E1000_IAC);
  1673. rd32(E1000_ICRXOC);
  1674. rd32(E1000_ICRXPTC);
  1675. rd32(E1000_ICRXATC);
  1676. rd32(E1000_ICTXPTC);
  1677. rd32(E1000_ICTXATC);
  1678. rd32(E1000_ICTXQEC);
  1679. rd32(E1000_ICTXQMTC);
  1680. rd32(E1000_ICRXDMTC);
  1681. rd32(E1000_CBTMPC);
  1682. rd32(E1000_HTDPMC);
  1683. rd32(E1000_CBRMPC);
  1684. rd32(E1000_RPTHC);
  1685. rd32(E1000_HGPTC);
  1686. rd32(E1000_HTCBDPC);
  1687. rd32(E1000_HGORCL);
  1688. rd32(E1000_HGORCH);
  1689. rd32(E1000_HGOTCL);
  1690. rd32(E1000_HGOTCH);
  1691. rd32(E1000_LENERRS);
  1692. /* This register should not be read in copper configurations */
  1693. if (hw->phy.media_type == e1000_media_type_internal_serdes ||
  1694. igb_sgmii_active_82575(hw))
  1695. rd32(E1000_SCVPC);
  1696. }
  1697. /**
  1698. * igb_rx_fifo_flush_82575 - Clean rx fifo after RX enable
  1699. * @hw: pointer to the HW structure
  1700. *
  1701. * After rx enable if manageability is enabled then there is likely some
  1702. * bad data at the start of the fifo and possibly in the DMA fifo. This
  1703. * function clears the fifos and flushes any packets that came in as rx was
  1704. * being enabled.
  1705. **/
  1706. void igb_rx_fifo_flush_82575(struct e1000_hw *hw)
  1707. {
  1708. u32 rctl, rlpml, rxdctl[4], rfctl, temp_rctl, rx_enabled;
  1709. int i, ms_wait;
  1710. /* disable IPv6 options as per hardware errata */
  1711. rfctl = rd32(E1000_RFCTL);
  1712. rfctl |= E1000_RFCTL_IPV6_EX_DIS;
  1713. wr32(E1000_RFCTL, rfctl);
  1714. if (hw->mac.type != e1000_82575 ||
  1715. !(rd32(E1000_MANC) & E1000_MANC_RCV_TCO_EN))
  1716. return;
  1717. /* Disable all RX queues */
  1718. for (i = 0; i < 4; i++) {
  1719. rxdctl[i] = rd32(E1000_RXDCTL(i));
  1720. wr32(E1000_RXDCTL(i),
  1721. rxdctl[i] & ~E1000_RXDCTL_QUEUE_ENABLE);
  1722. }
  1723. /* Poll all queues to verify they have shut down */
  1724. for (ms_wait = 0; ms_wait < 10; ms_wait++) {
  1725. usleep_range(1000, 2000);
  1726. rx_enabled = 0;
  1727. for (i = 0; i < 4; i++)
  1728. rx_enabled |= rd32(E1000_RXDCTL(i));
  1729. if (!(rx_enabled & E1000_RXDCTL_QUEUE_ENABLE))
  1730. break;
  1731. }
  1732. if (ms_wait == 10)
  1733. hw_dbg("Queue disable timed out after 10ms\n");
  1734. /* Clear RLPML, RCTL.SBP, RFCTL.LEF, and set RCTL.LPE so that all
  1735. * incoming packets are rejected. Set enable and wait 2ms so that
  1736. * any packet that was coming in as RCTL.EN was set is flushed
  1737. */
  1738. wr32(E1000_RFCTL, rfctl & ~E1000_RFCTL_LEF);
  1739. rlpml = rd32(E1000_RLPML);
  1740. wr32(E1000_RLPML, 0);
  1741. rctl = rd32(E1000_RCTL);
  1742. temp_rctl = rctl & ~(E1000_RCTL_EN | E1000_RCTL_SBP);
  1743. temp_rctl |= E1000_RCTL_LPE;
  1744. wr32(E1000_RCTL, temp_rctl);
  1745. wr32(E1000_RCTL, temp_rctl | E1000_RCTL_EN);
  1746. wrfl();
  1747. usleep_range(2000, 3000);
  1748. /* Enable RX queues that were previously enabled and restore our
  1749. * previous state
  1750. */
  1751. for (i = 0; i < 4; i++)
  1752. wr32(E1000_RXDCTL(i), rxdctl[i]);
  1753. wr32(E1000_RCTL, rctl);
  1754. wrfl();
  1755. wr32(E1000_RLPML, rlpml);
  1756. wr32(E1000_RFCTL, rfctl);
  1757. /* Flush receive errors generated by workaround */
  1758. rd32(E1000_ROC);
  1759. rd32(E1000_RNBC);
  1760. rd32(E1000_MPC);
  1761. }
  1762. /**
  1763. * igb_set_pcie_completion_timeout - set pci-e completion timeout
  1764. * @hw: pointer to the HW structure
  1765. *
  1766. * The defaults for 82575 and 82576 should be in the range of 50us to 50ms,
  1767. * however the hardware default for these parts is 500us to 1ms which is less
  1768. * than the 10ms recommended by the pci-e spec. To address this we need to
  1769. * increase the value to either 10ms to 200ms for capability version 1 config,
  1770. * or 16ms to 55ms for version 2.
  1771. **/
  1772. static s32 igb_set_pcie_completion_timeout(struct e1000_hw *hw)
  1773. {
  1774. u32 gcr = rd32(E1000_GCR);
  1775. s32 ret_val = 0;
  1776. u16 pcie_devctl2;
  1777. /* only take action if timeout value is defaulted to 0 */
  1778. if (gcr & E1000_GCR_CMPL_TMOUT_MASK)
  1779. goto out;
  1780. /* if capabilities version is type 1 we can write the
  1781. * timeout of 10ms to 200ms through the GCR register
  1782. */
  1783. if (!(gcr & E1000_GCR_CAP_VER2)) {
  1784. gcr |= E1000_GCR_CMPL_TMOUT_10ms;
  1785. goto out;
  1786. }
  1787. /* for version 2 capabilities we need to write the config space
  1788. * directly in order to set the completion timeout value for
  1789. * 16ms to 55ms
  1790. */
  1791. ret_val = igb_read_pcie_cap_reg(hw, PCIE_DEVICE_CONTROL2,
  1792. &pcie_devctl2);
  1793. if (ret_val)
  1794. goto out;
  1795. pcie_devctl2 |= PCIE_DEVICE_CONTROL2_16ms;
  1796. ret_val = igb_write_pcie_cap_reg(hw, PCIE_DEVICE_CONTROL2,
  1797. &pcie_devctl2);
  1798. out:
  1799. /* disable completion timeout resend */
  1800. gcr &= ~E1000_GCR_CMPL_TMOUT_RESEND;
  1801. wr32(E1000_GCR, gcr);
  1802. return ret_val;
  1803. }
  1804. /**
  1805. * igb_vmdq_set_anti_spoofing_pf - enable or disable anti-spoofing
  1806. * @hw: pointer to the hardware struct
  1807. * @enable: state to enter, either enabled or disabled
  1808. * @pf: Physical Function pool - do not set anti-spoofing for the PF
  1809. *
  1810. * enables/disables L2 switch anti-spoofing functionality.
  1811. **/
  1812. void igb_vmdq_set_anti_spoofing_pf(struct e1000_hw *hw, bool enable, int pf)
  1813. {
  1814. u32 reg_val, reg_offset;
  1815. switch (hw->mac.type) {
  1816. case e1000_82576:
  1817. reg_offset = E1000_DTXSWC;
  1818. break;
  1819. case e1000_i350:
  1820. case e1000_i354:
  1821. reg_offset = E1000_TXSWC;
  1822. break;
  1823. default:
  1824. return;
  1825. }
  1826. reg_val = rd32(reg_offset);
  1827. if (enable) {
  1828. reg_val |= (E1000_DTXSWC_MAC_SPOOF_MASK |
  1829. E1000_DTXSWC_VLAN_SPOOF_MASK);
  1830. /* The PF can spoof - it has to in order to
  1831. * support emulation mode NICs
  1832. */
  1833. reg_val ^= (BIT(pf) | BIT(pf + MAX_NUM_VFS));
  1834. } else {
  1835. reg_val &= ~(E1000_DTXSWC_MAC_SPOOF_MASK |
  1836. E1000_DTXSWC_VLAN_SPOOF_MASK);
  1837. }
  1838. wr32(reg_offset, reg_val);
  1839. }
  1840. /**
  1841. * igb_vmdq_set_loopback_pf - enable or disable vmdq loopback
  1842. * @hw: pointer to the hardware struct
  1843. * @enable: state to enter, either enabled or disabled
  1844. *
  1845. * enables/disables L2 switch loopback functionality.
  1846. **/
  1847. void igb_vmdq_set_loopback_pf(struct e1000_hw *hw, bool enable)
  1848. {
  1849. u32 dtxswc;
  1850. switch (hw->mac.type) {
  1851. case e1000_82576:
  1852. dtxswc = rd32(E1000_DTXSWC);
  1853. if (enable)
  1854. dtxswc |= E1000_DTXSWC_VMDQ_LOOPBACK_EN;
  1855. else
  1856. dtxswc &= ~E1000_DTXSWC_VMDQ_LOOPBACK_EN;
  1857. wr32(E1000_DTXSWC, dtxswc);
  1858. break;
  1859. case e1000_i354:
  1860. case e1000_i350:
  1861. dtxswc = rd32(E1000_TXSWC);
  1862. if (enable)
  1863. dtxswc |= E1000_DTXSWC_VMDQ_LOOPBACK_EN;
  1864. else
  1865. dtxswc &= ~E1000_DTXSWC_VMDQ_LOOPBACK_EN;
  1866. wr32(E1000_TXSWC, dtxswc);
  1867. break;
  1868. default:
  1869. /* Currently no other hardware supports loopback */
  1870. break;
  1871. }
  1872. }
  1873. /**
  1874. * igb_vmdq_set_replication_pf - enable or disable vmdq replication
  1875. * @hw: pointer to the hardware struct
  1876. * @enable: state to enter, either enabled or disabled
  1877. *
  1878. * enables/disables replication of packets across multiple pools.
  1879. **/
  1880. void igb_vmdq_set_replication_pf(struct e1000_hw *hw, bool enable)
  1881. {
  1882. u32 vt_ctl = rd32(E1000_VT_CTL);
  1883. if (enable)
  1884. vt_ctl |= E1000_VT_CTL_VM_REPL_EN;
  1885. else
  1886. vt_ctl &= ~E1000_VT_CTL_VM_REPL_EN;
  1887. wr32(E1000_VT_CTL, vt_ctl);
  1888. }
  1889. /**
  1890. * igb_read_phy_reg_82580 - Read 82580 MDI control register
  1891. * @hw: pointer to the HW structure
  1892. * @offset: register offset to be read
  1893. * @data: pointer to the read data
  1894. *
  1895. * Reads the MDI control register in the PHY at offset and stores the
  1896. * information read to data.
  1897. **/
  1898. s32 igb_read_phy_reg_82580(struct e1000_hw *hw, u32 offset, u16 *data)
  1899. {
  1900. s32 ret_val;
  1901. ret_val = hw->phy.ops.acquire(hw);
  1902. if (ret_val)
  1903. goto out;
  1904. ret_val = igb_read_phy_reg_mdic(hw, offset, data);
  1905. hw->phy.ops.release(hw);
  1906. out:
  1907. return ret_val;
  1908. }
  1909. /**
  1910. * igb_write_phy_reg_82580 - Write 82580 MDI control register
  1911. * @hw: pointer to the HW structure
  1912. * @offset: register offset to write to
  1913. * @data: data to write to register at offset
  1914. *
  1915. * Writes data to MDI control register in the PHY at offset.
  1916. **/
  1917. s32 igb_write_phy_reg_82580(struct e1000_hw *hw, u32 offset, u16 data)
  1918. {
  1919. s32 ret_val;
  1920. ret_val = hw->phy.ops.acquire(hw);
  1921. if (ret_val)
  1922. goto out;
  1923. ret_val = igb_write_phy_reg_mdic(hw, offset, data);
  1924. hw->phy.ops.release(hw);
  1925. out:
  1926. return ret_val;
  1927. }
  1928. /**
  1929. * igb_reset_mdicnfg_82580 - Reset MDICNFG destination and com_mdio bits
  1930. * @hw: pointer to the HW structure
  1931. *
  1932. * This resets the the MDICNFG.Destination and MDICNFG.Com_MDIO bits based on
  1933. * the values found in the EEPROM. This addresses an issue in which these
  1934. * bits are not restored from EEPROM after reset.
  1935. **/
  1936. static s32 igb_reset_mdicnfg_82580(struct e1000_hw *hw)
  1937. {
  1938. s32 ret_val = 0;
  1939. u32 mdicnfg;
  1940. u16 nvm_data = 0;
  1941. if (hw->mac.type != e1000_82580)
  1942. goto out;
  1943. if (!igb_sgmii_active_82575(hw))
  1944. goto out;
  1945. ret_val = hw->nvm.ops.read(hw, NVM_INIT_CONTROL3_PORT_A +
  1946. NVM_82580_LAN_FUNC_OFFSET(hw->bus.func), 1,
  1947. &nvm_data);
  1948. if (ret_val) {
  1949. hw_dbg("NVM Read Error\n");
  1950. goto out;
  1951. }
  1952. mdicnfg = rd32(E1000_MDICNFG);
  1953. if (nvm_data & NVM_WORD24_EXT_MDIO)
  1954. mdicnfg |= E1000_MDICNFG_EXT_MDIO;
  1955. if (nvm_data & NVM_WORD24_COM_MDIO)
  1956. mdicnfg |= E1000_MDICNFG_COM_MDIO;
  1957. wr32(E1000_MDICNFG, mdicnfg);
  1958. out:
  1959. return ret_val;
  1960. }
  1961. /**
  1962. * igb_reset_hw_82580 - Reset hardware
  1963. * @hw: pointer to the HW structure
  1964. *
  1965. * This resets function or entire device (all ports, etc.)
  1966. * to a known state.
  1967. **/
  1968. static s32 igb_reset_hw_82580(struct e1000_hw *hw)
  1969. {
  1970. s32 ret_val = 0;
  1971. /* BH SW mailbox bit in SW_FW_SYNC */
  1972. u16 swmbsw_mask = E1000_SW_SYNCH_MB;
  1973. u32 ctrl;
  1974. bool global_device_reset = hw->dev_spec._82575.global_device_reset;
  1975. hw->dev_spec._82575.global_device_reset = false;
  1976. /* due to hw errata, global device reset doesn't always
  1977. * work on 82580
  1978. */
  1979. if (hw->mac.type == e1000_82580)
  1980. global_device_reset = false;
  1981. /* Get current control state. */
  1982. ctrl = rd32(E1000_CTRL);
  1983. /* Prevent the PCI-E bus from sticking if there is no TLP connection
  1984. * on the last TLP read/write transaction when MAC is reset.
  1985. */
  1986. ret_val = igb_disable_pcie_master(hw);
  1987. if (ret_val)
  1988. hw_dbg("PCI-E Master disable polling has failed.\n");
  1989. hw_dbg("Masking off all interrupts\n");
  1990. wr32(E1000_IMC, 0xffffffff);
  1991. wr32(E1000_RCTL, 0);
  1992. wr32(E1000_TCTL, E1000_TCTL_PSP);
  1993. wrfl();
  1994. usleep_range(10000, 11000);
  1995. /* Determine whether or not a global dev reset is requested */
  1996. if (global_device_reset &&
  1997. hw->mac.ops.acquire_swfw_sync(hw, swmbsw_mask))
  1998. global_device_reset = false;
  1999. if (global_device_reset &&
  2000. !(rd32(E1000_STATUS) & E1000_STAT_DEV_RST_SET))
  2001. ctrl |= E1000_CTRL_DEV_RST;
  2002. else
  2003. ctrl |= E1000_CTRL_RST;
  2004. wr32(E1000_CTRL, ctrl);
  2005. wrfl();
  2006. /* Add delay to insure DEV_RST has time to complete */
  2007. if (global_device_reset)
  2008. usleep_range(5000, 6000);
  2009. ret_val = igb_get_auto_rd_done(hw);
  2010. if (ret_val) {
  2011. /* When auto config read does not complete, do not
  2012. * return with an error. This can happen in situations
  2013. * where there is no eeprom and prevents getting link.
  2014. */
  2015. hw_dbg("Auto Read Done did not complete\n");
  2016. }
  2017. /* clear global device reset status bit */
  2018. wr32(E1000_STATUS, E1000_STAT_DEV_RST_SET);
  2019. /* Clear any pending interrupt events. */
  2020. wr32(E1000_IMC, 0xffffffff);
  2021. rd32(E1000_ICR);
  2022. ret_val = igb_reset_mdicnfg_82580(hw);
  2023. if (ret_val)
  2024. hw_dbg("Could not reset MDICNFG based on EEPROM\n");
  2025. /* Install any alternate MAC address into RAR0 */
  2026. ret_val = igb_check_alt_mac_addr(hw);
  2027. /* Release semaphore */
  2028. if (global_device_reset)
  2029. hw->mac.ops.release_swfw_sync(hw, swmbsw_mask);
  2030. return ret_val;
  2031. }
  2032. /**
  2033. * igb_rxpbs_adjust_82580 - adjust RXPBS value to reflect actual RX PBA size
  2034. * @data: data received by reading RXPBS register
  2035. *
  2036. * The 82580 uses a table based approach for packet buffer allocation sizes.
  2037. * This function converts the retrieved value into the correct table value
  2038. * 0x0 0x1 0x2 0x3 0x4 0x5 0x6 0x7
  2039. * 0x0 36 72 144 1 2 4 8 16
  2040. * 0x8 35 70 140 rsv rsv rsv rsv rsv
  2041. */
  2042. u16 igb_rxpbs_adjust_82580(u32 data)
  2043. {
  2044. u16 ret_val = 0;
  2045. if (data < ARRAY_SIZE(e1000_82580_rxpbs_table))
  2046. ret_val = e1000_82580_rxpbs_table[data];
  2047. return ret_val;
  2048. }
  2049. /**
  2050. * igb_validate_nvm_checksum_with_offset - Validate EEPROM
  2051. * checksum
  2052. * @hw: pointer to the HW structure
  2053. * @offset: offset in words of the checksum protected region
  2054. *
  2055. * Calculates the EEPROM checksum by reading/adding each word of the EEPROM
  2056. * and then verifies that the sum of the EEPROM is equal to 0xBABA.
  2057. **/
  2058. static s32 igb_validate_nvm_checksum_with_offset(struct e1000_hw *hw,
  2059. u16 offset)
  2060. {
  2061. s32 ret_val = 0;
  2062. u16 checksum = 0;
  2063. u16 i, nvm_data;
  2064. for (i = offset; i < ((NVM_CHECKSUM_REG + offset) + 1); i++) {
  2065. ret_val = hw->nvm.ops.read(hw, i, 1, &nvm_data);
  2066. if (ret_val) {
  2067. hw_dbg("NVM Read Error\n");
  2068. goto out;
  2069. }
  2070. checksum += nvm_data;
  2071. }
  2072. if (checksum != (u16) NVM_SUM) {
  2073. hw_dbg("NVM Checksum Invalid\n");
  2074. ret_val = -E1000_ERR_NVM;
  2075. goto out;
  2076. }
  2077. out:
  2078. return ret_val;
  2079. }
  2080. /**
  2081. * igb_update_nvm_checksum_with_offset - Update EEPROM
  2082. * checksum
  2083. * @hw: pointer to the HW structure
  2084. * @offset: offset in words of the checksum protected region
  2085. *
  2086. * Updates the EEPROM checksum by reading/adding each word of the EEPROM
  2087. * up to the checksum. Then calculates the EEPROM checksum and writes the
  2088. * value to the EEPROM.
  2089. **/
  2090. static s32 igb_update_nvm_checksum_with_offset(struct e1000_hw *hw, u16 offset)
  2091. {
  2092. s32 ret_val;
  2093. u16 checksum = 0;
  2094. u16 i, nvm_data;
  2095. for (i = offset; i < (NVM_CHECKSUM_REG + offset); i++) {
  2096. ret_val = hw->nvm.ops.read(hw, i, 1, &nvm_data);
  2097. if (ret_val) {
  2098. hw_dbg("NVM Read Error while updating checksum.\n");
  2099. goto out;
  2100. }
  2101. checksum += nvm_data;
  2102. }
  2103. checksum = (u16) NVM_SUM - checksum;
  2104. ret_val = hw->nvm.ops.write(hw, (NVM_CHECKSUM_REG + offset), 1,
  2105. &checksum);
  2106. if (ret_val)
  2107. hw_dbg("NVM Write Error while updating checksum.\n");
  2108. out:
  2109. return ret_val;
  2110. }
  2111. /**
  2112. * igb_validate_nvm_checksum_82580 - Validate EEPROM checksum
  2113. * @hw: pointer to the HW structure
  2114. *
  2115. * Calculates the EEPROM section checksum by reading/adding each word of
  2116. * the EEPROM and then verifies that the sum of the EEPROM is
  2117. * equal to 0xBABA.
  2118. **/
  2119. static s32 igb_validate_nvm_checksum_82580(struct e1000_hw *hw)
  2120. {
  2121. s32 ret_val = 0;
  2122. u16 eeprom_regions_count = 1;
  2123. u16 j, nvm_data;
  2124. u16 nvm_offset;
  2125. ret_val = hw->nvm.ops.read(hw, NVM_COMPATIBILITY_REG_3, 1, &nvm_data);
  2126. if (ret_val) {
  2127. hw_dbg("NVM Read Error\n");
  2128. goto out;
  2129. }
  2130. if (nvm_data & NVM_COMPATIBILITY_BIT_MASK) {
  2131. /* if checksums compatibility bit is set validate checksums
  2132. * for all 4 ports.
  2133. */
  2134. eeprom_regions_count = 4;
  2135. }
  2136. for (j = 0; j < eeprom_regions_count; j++) {
  2137. nvm_offset = NVM_82580_LAN_FUNC_OFFSET(j);
  2138. ret_val = igb_validate_nvm_checksum_with_offset(hw,
  2139. nvm_offset);
  2140. if (ret_val != 0)
  2141. goto out;
  2142. }
  2143. out:
  2144. return ret_val;
  2145. }
  2146. /**
  2147. * igb_update_nvm_checksum_82580 - Update EEPROM checksum
  2148. * @hw: pointer to the HW structure
  2149. *
  2150. * Updates the EEPROM section checksums for all 4 ports by reading/adding
  2151. * each word of the EEPROM up to the checksum. Then calculates the EEPROM
  2152. * checksum and writes the value to the EEPROM.
  2153. **/
  2154. static s32 igb_update_nvm_checksum_82580(struct e1000_hw *hw)
  2155. {
  2156. s32 ret_val;
  2157. u16 j, nvm_data;
  2158. u16 nvm_offset;
  2159. ret_val = hw->nvm.ops.read(hw, NVM_COMPATIBILITY_REG_3, 1, &nvm_data);
  2160. if (ret_val) {
  2161. hw_dbg("NVM Read Error while updating checksum compatibility bit.\n");
  2162. goto out;
  2163. }
  2164. if ((nvm_data & NVM_COMPATIBILITY_BIT_MASK) == 0) {
  2165. /* set compatibility bit to validate checksums appropriately */
  2166. nvm_data = nvm_data | NVM_COMPATIBILITY_BIT_MASK;
  2167. ret_val = hw->nvm.ops.write(hw, NVM_COMPATIBILITY_REG_3, 1,
  2168. &nvm_data);
  2169. if (ret_val) {
  2170. hw_dbg("NVM Write Error while updating checksum compatibility bit.\n");
  2171. goto out;
  2172. }
  2173. }
  2174. for (j = 0; j < 4; j++) {
  2175. nvm_offset = NVM_82580_LAN_FUNC_OFFSET(j);
  2176. ret_val = igb_update_nvm_checksum_with_offset(hw, nvm_offset);
  2177. if (ret_val)
  2178. goto out;
  2179. }
  2180. out:
  2181. return ret_val;
  2182. }
  2183. /**
  2184. * igb_validate_nvm_checksum_i350 - Validate EEPROM checksum
  2185. * @hw: pointer to the HW structure
  2186. *
  2187. * Calculates the EEPROM section checksum by reading/adding each word of
  2188. * the EEPROM and then verifies that the sum of the EEPROM is
  2189. * equal to 0xBABA.
  2190. **/
  2191. static s32 igb_validate_nvm_checksum_i350(struct e1000_hw *hw)
  2192. {
  2193. s32 ret_val = 0;
  2194. u16 j;
  2195. u16 nvm_offset;
  2196. for (j = 0; j < 4; j++) {
  2197. nvm_offset = NVM_82580_LAN_FUNC_OFFSET(j);
  2198. ret_val = igb_validate_nvm_checksum_with_offset(hw,
  2199. nvm_offset);
  2200. if (ret_val != 0)
  2201. goto out;
  2202. }
  2203. out:
  2204. return ret_val;
  2205. }
  2206. /**
  2207. * igb_update_nvm_checksum_i350 - Update EEPROM checksum
  2208. * @hw: pointer to the HW structure
  2209. *
  2210. * Updates the EEPROM section checksums for all 4 ports by reading/adding
  2211. * each word of the EEPROM up to the checksum. Then calculates the EEPROM
  2212. * checksum and writes the value to the EEPROM.
  2213. **/
  2214. static s32 igb_update_nvm_checksum_i350(struct e1000_hw *hw)
  2215. {
  2216. s32 ret_val = 0;
  2217. u16 j;
  2218. u16 nvm_offset;
  2219. for (j = 0; j < 4; j++) {
  2220. nvm_offset = NVM_82580_LAN_FUNC_OFFSET(j);
  2221. ret_val = igb_update_nvm_checksum_with_offset(hw, nvm_offset);
  2222. if (ret_val != 0)
  2223. goto out;
  2224. }
  2225. out:
  2226. return ret_val;
  2227. }
  2228. /**
  2229. * __igb_access_emi_reg - Read/write EMI register
  2230. * @hw: pointer to the HW structure
  2231. * @addr: EMI address to program
  2232. * @data: pointer to value to read/write from/to the EMI address
  2233. * @read: boolean flag to indicate read or write
  2234. **/
  2235. static s32 __igb_access_emi_reg(struct e1000_hw *hw, u16 address,
  2236. u16 *data, bool read)
  2237. {
  2238. s32 ret_val = 0;
  2239. ret_val = hw->phy.ops.write_reg(hw, E1000_EMIADD, address);
  2240. if (ret_val)
  2241. return ret_val;
  2242. if (read)
  2243. ret_val = hw->phy.ops.read_reg(hw, E1000_EMIDATA, data);
  2244. else
  2245. ret_val = hw->phy.ops.write_reg(hw, E1000_EMIDATA, *data);
  2246. return ret_val;
  2247. }
  2248. /**
  2249. * igb_read_emi_reg - Read Extended Management Interface register
  2250. * @hw: pointer to the HW structure
  2251. * @addr: EMI address to program
  2252. * @data: value to be read from the EMI address
  2253. **/
  2254. s32 igb_read_emi_reg(struct e1000_hw *hw, u16 addr, u16 *data)
  2255. {
  2256. return __igb_access_emi_reg(hw, addr, data, true);
  2257. }
  2258. /**
  2259. * igb_set_eee_i350 - Enable/disable EEE support
  2260. * @hw: pointer to the HW structure
  2261. * @adv1G: boolean flag enabling 1G EEE advertisement
  2262. * @adv100m: boolean flag enabling 100M EEE advertisement
  2263. *
  2264. * Enable/disable EEE based on setting in dev_spec structure.
  2265. *
  2266. **/
  2267. s32 igb_set_eee_i350(struct e1000_hw *hw, bool adv1G, bool adv100M)
  2268. {
  2269. u32 ipcnfg, eeer;
  2270. if ((hw->mac.type < e1000_i350) ||
  2271. (hw->phy.media_type != e1000_media_type_copper))
  2272. goto out;
  2273. ipcnfg = rd32(E1000_IPCNFG);
  2274. eeer = rd32(E1000_EEER);
  2275. /* enable or disable per user setting */
  2276. if (!(hw->dev_spec._82575.eee_disable)) {
  2277. u32 eee_su = rd32(E1000_EEE_SU);
  2278. if (adv100M)
  2279. ipcnfg |= E1000_IPCNFG_EEE_100M_AN;
  2280. else
  2281. ipcnfg &= ~E1000_IPCNFG_EEE_100M_AN;
  2282. if (adv1G)
  2283. ipcnfg |= E1000_IPCNFG_EEE_1G_AN;
  2284. else
  2285. ipcnfg &= ~E1000_IPCNFG_EEE_1G_AN;
  2286. eeer |= (E1000_EEER_TX_LPI_EN | E1000_EEER_RX_LPI_EN |
  2287. E1000_EEER_LPI_FC);
  2288. /* This bit should not be set in normal operation. */
  2289. if (eee_su & E1000_EEE_SU_LPI_CLK_STP)
  2290. hw_dbg("LPI Clock Stop Bit should not be set!\n");
  2291. } else {
  2292. ipcnfg &= ~(E1000_IPCNFG_EEE_1G_AN |
  2293. E1000_IPCNFG_EEE_100M_AN);
  2294. eeer &= ~(E1000_EEER_TX_LPI_EN |
  2295. E1000_EEER_RX_LPI_EN |
  2296. E1000_EEER_LPI_FC);
  2297. }
  2298. wr32(E1000_IPCNFG, ipcnfg);
  2299. wr32(E1000_EEER, eeer);
  2300. rd32(E1000_IPCNFG);
  2301. rd32(E1000_EEER);
  2302. out:
  2303. return 0;
  2304. }
  2305. /**
  2306. * igb_set_eee_i354 - Enable/disable EEE support
  2307. * @hw: pointer to the HW structure
  2308. * @adv1G: boolean flag enabling 1G EEE advertisement
  2309. * @adv100m: boolean flag enabling 100M EEE advertisement
  2310. *
  2311. * Enable/disable EEE legacy mode based on setting in dev_spec structure.
  2312. *
  2313. **/
  2314. s32 igb_set_eee_i354(struct e1000_hw *hw, bool adv1G, bool adv100M)
  2315. {
  2316. struct e1000_phy_info *phy = &hw->phy;
  2317. s32 ret_val = 0;
  2318. u16 phy_data;
  2319. if ((hw->phy.media_type != e1000_media_type_copper) ||
  2320. ((phy->id != M88E1543_E_PHY_ID) &&
  2321. (phy->id != M88E1512_E_PHY_ID)))
  2322. goto out;
  2323. if (!hw->dev_spec._82575.eee_disable) {
  2324. /* Switch to PHY page 18. */
  2325. ret_val = phy->ops.write_reg(hw, E1000_M88E1543_PAGE_ADDR, 18);
  2326. if (ret_val)
  2327. goto out;
  2328. ret_val = phy->ops.read_reg(hw, E1000_M88E1543_EEE_CTRL_1,
  2329. &phy_data);
  2330. if (ret_val)
  2331. goto out;
  2332. phy_data |= E1000_M88E1543_EEE_CTRL_1_MS;
  2333. ret_val = phy->ops.write_reg(hw, E1000_M88E1543_EEE_CTRL_1,
  2334. phy_data);
  2335. if (ret_val)
  2336. goto out;
  2337. /* Return the PHY to page 0. */
  2338. ret_val = phy->ops.write_reg(hw, E1000_M88E1543_PAGE_ADDR, 0);
  2339. if (ret_val)
  2340. goto out;
  2341. /* Turn on EEE advertisement. */
  2342. ret_val = igb_read_xmdio_reg(hw, E1000_EEE_ADV_ADDR_I354,
  2343. E1000_EEE_ADV_DEV_I354,
  2344. &phy_data);
  2345. if (ret_val)
  2346. goto out;
  2347. if (adv100M)
  2348. phy_data |= E1000_EEE_ADV_100_SUPPORTED;
  2349. else
  2350. phy_data &= ~E1000_EEE_ADV_100_SUPPORTED;
  2351. if (adv1G)
  2352. phy_data |= E1000_EEE_ADV_1000_SUPPORTED;
  2353. else
  2354. phy_data &= ~E1000_EEE_ADV_1000_SUPPORTED;
  2355. ret_val = igb_write_xmdio_reg(hw, E1000_EEE_ADV_ADDR_I354,
  2356. E1000_EEE_ADV_DEV_I354,
  2357. phy_data);
  2358. } else {
  2359. /* Turn off EEE advertisement. */
  2360. ret_val = igb_read_xmdio_reg(hw, E1000_EEE_ADV_ADDR_I354,
  2361. E1000_EEE_ADV_DEV_I354,
  2362. &phy_data);
  2363. if (ret_val)
  2364. goto out;
  2365. phy_data &= ~(E1000_EEE_ADV_100_SUPPORTED |
  2366. E1000_EEE_ADV_1000_SUPPORTED);
  2367. ret_val = igb_write_xmdio_reg(hw, E1000_EEE_ADV_ADDR_I354,
  2368. E1000_EEE_ADV_DEV_I354,
  2369. phy_data);
  2370. }
  2371. out:
  2372. return ret_val;
  2373. }
  2374. /**
  2375. * igb_get_eee_status_i354 - Get EEE status
  2376. * @hw: pointer to the HW structure
  2377. * @status: EEE status
  2378. *
  2379. * Get EEE status by guessing based on whether Tx or Rx LPI indications have
  2380. * been received.
  2381. **/
  2382. s32 igb_get_eee_status_i354(struct e1000_hw *hw, bool *status)
  2383. {
  2384. struct e1000_phy_info *phy = &hw->phy;
  2385. s32 ret_val = 0;
  2386. u16 phy_data;
  2387. /* Check if EEE is supported on this device. */
  2388. if ((hw->phy.media_type != e1000_media_type_copper) ||
  2389. ((phy->id != M88E1543_E_PHY_ID) &&
  2390. (phy->id != M88E1512_E_PHY_ID)))
  2391. goto out;
  2392. ret_val = igb_read_xmdio_reg(hw, E1000_PCS_STATUS_ADDR_I354,
  2393. E1000_PCS_STATUS_DEV_I354,
  2394. &phy_data);
  2395. if (ret_val)
  2396. goto out;
  2397. *status = phy_data & (E1000_PCS_STATUS_TX_LPI_RCVD |
  2398. E1000_PCS_STATUS_RX_LPI_RCVD) ? true : false;
  2399. out:
  2400. return ret_val;
  2401. }
  2402. static const u8 e1000_emc_temp_data[4] = {
  2403. E1000_EMC_INTERNAL_DATA,
  2404. E1000_EMC_DIODE1_DATA,
  2405. E1000_EMC_DIODE2_DATA,
  2406. E1000_EMC_DIODE3_DATA
  2407. };
  2408. static const u8 e1000_emc_therm_limit[4] = {
  2409. E1000_EMC_INTERNAL_THERM_LIMIT,
  2410. E1000_EMC_DIODE1_THERM_LIMIT,
  2411. E1000_EMC_DIODE2_THERM_LIMIT,
  2412. E1000_EMC_DIODE3_THERM_LIMIT
  2413. };
  2414. #ifdef CONFIG_IGB_HWMON
  2415. /**
  2416. * igb_get_thermal_sensor_data_generic - Gathers thermal sensor data
  2417. * @hw: pointer to hardware structure
  2418. *
  2419. * Updates the temperatures in mac.thermal_sensor_data
  2420. **/
  2421. static s32 igb_get_thermal_sensor_data_generic(struct e1000_hw *hw)
  2422. {
  2423. u16 ets_offset;
  2424. u16 ets_cfg;
  2425. u16 ets_sensor;
  2426. u8 num_sensors;
  2427. u8 sensor_index;
  2428. u8 sensor_location;
  2429. u8 i;
  2430. struct e1000_thermal_sensor_data *data = &hw->mac.thermal_sensor_data;
  2431. if ((hw->mac.type != e1000_i350) || (hw->bus.func != 0))
  2432. return E1000_NOT_IMPLEMENTED;
  2433. data->sensor[0].temp = (rd32(E1000_THMJT) & 0xFF);
  2434. /* Return the internal sensor only if ETS is unsupported */
  2435. hw->nvm.ops.read(hw, NVM_ETS_CFG, 1, &ets_offset);
  2436. if ((ets_offset == 0x0000) || (ets_offset == 0xFFFF))
  2437. return 0;
  2438. hw->nvm.ops.read(hw, ets_offset, 1, &ets_cfg);
  2439. if (((ets_cfg & NVM_ETS_TYPE_MASK) >> NVM_ETS_TYPE_SHIFT)
  2440. != NVM_ETS_TYPE_EMC)
  2441. return E1000_NOT_IMPLEMENTED;
  2442. num_sensors = (ets_cfg & NVM_ETS_NUM_SENSORS_MASK);
  2443. if (num_sensors > E1000_MAX_SENSORS)
  2444. num_sensors = E1000_MAX_SENSORS;
  2445. for (i = 1; i < num_sensors; i++) {
  2446. hw->nvm.ops.read(hw, (ets_offset + i), 1, &ets_sensor);
  2447. sensor_index = ((ets_sensor & NVM_ETS_DATA_INDEX_MASK) >>
  2448. NVM_ETS_DATA_INDEX_SHIFT);
  2449. sensor_location = ((ets_sensor & NVM_ETS_DATA_LOC_MASK) >>
  2450. NVM_ETS_DATA_LOC_SHIFT);
  2451. if (sensor_location != 0)
  2452. hw->phy.ops.read_i2c_byte(hw,
  2453. e1000_emc_temp_data[sensor_index],
  2454. E1000_I2C_THERMAL_SENSOR_ADDR,
  2455. &data->sensor[i].temp);
  2456. }
  2457. return 0;
  2458. }
  2459. /**
  2460. * igb_init_thermal_sensor_thresh_generic - Sets thermal sensor thresholds
  2461. * @hw: pointer to hardware structure
  2462. *
  2463. * Sets the thermal sensor thresholds according to the NVM map
  2464. * and save off the threshold and location values into mac.thermal_sensor_data
  2465. **/
  2466. static s32 igb_init_thermal_sensor_thresh_generic(struct e1000_hw *hw)
  2467. {
  2468. u16 ets_offset;
  2469. u16 ets_cfg;
  2470. u16 ets_sensor;
  2471. u8 low_thresh_delta;
  2472. u8 num_sensors;
  2473. u8 sensor_index;
  2474. u8 sensor_location;
  2475. u8 therm_limit;
  2476. u8 i;
  2477. struct e1000_thermal_sensor_data *data = &hw->mac.thermal_sensor_data;
  2478. if ((hw->mac.type != e1000_i350) || (hw->bus.func != 0))
  2479. return E1000_NOT_IMPLEMENTED;
  2480. memset(data, 0, sizeof(struct e1000_thermal_sensor_data));
  2481. data->sensor[0].location = 0x1;
  2482. data->sensor[0].caution_thresh =
  2483. (rd32(E1000_THHIGHTC) & 0xFF);
  2484. data->sensor[0].max_op_thresh =
  2485. (rd32(E1000_THLOWTC) & 0xFF);
  2486. /* Return the internal sensor only if ETS is unsupported */
  2487. hw->nvm.ops.read(hw, NVM_ETS_CFG, 1, &ets_offset);
  2488. if ((ets_offset == 0x0000) || (ets_offset == 0xFFFF))
  2489. return 0;
  2490. hw->nvm.ops.read(hw, ets_offset, 1, &ets_cfg);
  2491. if (((ets_cfg & NVM_ETS_TYPE_MASK) >> NVM_ETS_TYPE_SHIFT)
  2492. != NVM_ETS_TYPE_EMC)
  2493. return E1000_NOT_IMPLEMENTED;
  2494. low_thresh_delta = ((ets_cfg & NVM_ETS_LTHRES_DELTA_MASK) >>
  2495. NVM_ETS_LTHRES_DELTA_SHIFT);
  2496. num_sensors = (ets_cfg & NVM_ETS_NUM_SENSORS_MASK);
  2497. for (i = 1; i <= num_sensors; i++) {
  2498. hw->nvm.ops.read(hw, (ets_offset + i), 1, &ets_sensor);
  2499. sensor_index = ((ets_sensor & NVM_ETS_DATA_INDEX_MASK) >>
  2500. NVM_ETS_DATA_INDEX_SHIFT);
  2501. sensor_location = ((ets_sensor & NVM_ETS_DATA_LOC_MASK) >>
  2502. NVM_ETS_DATA_LOC_SHIFT);
  2503. therm_limit = ets_sensor & NVM_ETS_DATA_HTHRESH_MASK;
  2504. hw->phy.ops.write_i2c_byte(hw,
  2505. e1000_emc_therm_limit[sensor_index],
  2506. E1000_I2C_THERMAL_SENSOR_ADDR,
  2507. therm_limit);
  2508. if ((i < E1000_MAX_SENSORS) && (sensor_location != 0)) {
  2509. data->sensor[i].location = sensor_location;
  2510. data->sensor[i].caution_thresh = therm_limit;
  2511. data->sensor[i].max_op_thresh = therm_limit -
  2512. low_thresh_delta;
  2513. }
  2514. }
  2515. return 0;
  2516. }
  2517. #endif
  2518. static struct e1000_mac_operations e1000_mac_ops_82575 = {
  2519. .init_hw = igb_init_hw_82575,
  2520. .check_for_link = igb_check_for_link_82575,
  2521. .rar_set = igb_rar_set,
  2522. .read_mac_addr = igb_read_mac_addr_82575,
  2523. .get_speed_and_duplex = igb_get_link_up_info_82575,
  2524. #ifdef CONFIG_IGB_HWMON
  2525. .get_thermal_sensor_data = igb_get_thermal_sensor_data_generic,
  2526. .init_thermal_sensor_thresh = igb_init_thermal_sensor_thresh_generic,
  2527. #endif
  2528. };
  2529. static const struct e1000_phy_operations e1000_phy_ops_82575 = {
  2530. .acquire = igb_acquire_phy_82575,
  2531. .get_cfg_done = igb_get_cfg_done_82575,
  2532. .release = igb_release_phy_82575,
  2533. .write_i2c_byte = igb_write_i2c_byte,
  2534. .read_i2c_byte = igb_read_i2c_byte,
  2535. };
  2536. static struct e1000_nvm_operations e1000_nvm_ops_82575 = {
  2537. .acquire = igb_acquire_nvm_82575,
  2538. .read = igb_read_nvm_eerd,
  2539. .release = igb_release_nvm_82575,
  2540. .write = igb_write_nvm_spi,
  2541. };
  2542. const struct e1000_info e1000_82575_info = {
  2543. .get_invariants = igb_get_invariants_82575,
  2544. .mac_ops = &e1000_mac_ops_82575,
  2545. .phy_ops = &e1000_phy_ops_82575,
  2546. .nvm_ops = &e1000_nvm_ops_82575,
  2547. };