e1000_82575.c 79 KB

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