e1000_82575.c 44 KB

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