e1000_82575.c 77 KB

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