e1000_82575.c 63 KB

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