e1000_82575.c 79 KB

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