e1000_82575.c 78 KB

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