e1000_82575.c 79 KB

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