e1000_82575.c 67 KB

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