e1000_82575.c 38 KB

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