e1000_82575.c 76 KB

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