e1000_82575.c 39 KB

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