e1000_82575.c 74 KB

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