e1000_82575.c 44 KB

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