e1000_82575.c 44 KB

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