e1000_82575.c 40 KB

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