e1000_82575.c 41 KB

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