e1000_82575.c 55 KB

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