e1000_82575.c 55 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102
  1. /*******************************************************************************
  2. Intel(R) Gigabit Ethernet Linux driver
  3. Copyright(c) 2007-2012 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. #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
  24. #include <linux/types.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 s32 igb_reset_mdicnfg_82580(struct e1000_hw *hw);
  57. static s32 igb_validate_nvm_checksum_82580(struct e1000_hw *hw);
  58. static s32 igb_update_nvm_checksum_82580(struct e1000_hw *hw);
  59. static s32 igb_validate_nvm_checksum_i350(struct e1000_hw *hw);
  60. static s32 igb_update_nvm_checksum_i350(struct e1000_hw *hw);
  61. static const u16 e1000_82580_rxpbs_table[] =
  62. { 36, 72, 144, 1, 2, 4, 8, 16,
  63. 35, 70, 140 };
  64. #define E1000_82580_RXPBS_TABLE_SIZE \
  65. (sizeof(e1000_82580_rxpbs_table)/sizeof(u16))
  66. /**
  67. * igb_sgmii_uses_mdio_82575 - Determine if I2C pins are for external MDIO
  68. * @hw: pointer to the HW structure
  69. *
  70. * Called to determine if the I2C pins are being used for I2C or as an
  71. * external MDIO interface since the two options are mutually exclusive.
  72. **/
  73. static bool igb_sgmii_uses_mdio_82575(struct e1000_hw *hw)
  74. {
  75. u32 reg = 0;
  76. bool ext_mdio = false;
  77. switch (hw->mac.type) {
  78. case e1000_82575:
  79. case e1000_82576:
  80. reg = rd32(E1000_MDIC);
  81. ext_mdio = !!(reg & E1000_MDIC_DEST);
  82. break;
  83. case e1000_82580:
  84. case e1000_i350:
  85. reg = rd32(E1000_MDICNFG);
  86. ext_mdio = !!(reg & E1000_MDICNFG_EXT_MDIO);
  87. break;
  88. default:
  89. break;
  90. }
  91. return ext_mdio;
  92. }
  93. static s32 igb_get_invariants_82575(struct e1000_hw *hw)
  94. {
  95. struct e1000_phy_info *phy = &hw->phy;
  96. struct e1000_nvm_info *nvm = &hw->nvm;
  97. struct e1000_mac_info *mac = &hw->mac;
  98. struct e1000_dev_spec_82575 * dev_spec = &hw->dev_spec._82575;
  99. u32 eecd;
  100. s32 ret_val;
  101. u16 size;
  102. u32 ctrl_ext = 0;
  103. switch (hw->device_id) {
  104. case E1000_DEV_ID_82575EB_COPPER:
  105. case E1000_DEV_ID_82575EB_FIBER_SERDES:
  106. case E1000_DEV_ID_82575GB_QUAD_COPPER:
  107. mac->type = e1000_82575;
  108. break;
  109. case E1000_DEV_ID_82576:
  110. case E1000_DEV_ID_82576_NS:
  111. case E1000_DEV_ID_82576_NS_SERDES:
  112. case E1000_DEV_ID_82576_FIBER:
  113. case E1000_DEV_ID_82576_SERDES:
  114. case E1000_DEV_ID_82576_QUAD_COPPER:
  115. case E1000_DEV_ID_82576_QUAD_COPPER_ET2:
  116. case E1000_DEV_ID_82576_SERDES_QUAD:
  117. mac->type = e1000_82576;
  118. break;
  119. case E1000_DEV_ID_82580_COPPER:
  120. case E1000_DEV_ID_82580_FIBER:
  121. case E1000_DEV_ID_82580_QUAD_FIBER:
  122. case E1000_DEV_ID_82580_SERDES:
  123. case E1000_DEV_ID_82580_SGMII:
  124. case E1000_DEV_ID_82580_COPPER_DUAL:
  125. case E1000_DEV_ID_DH89XXCC_SGMII:
  126. case E1000_DEV_ID_DH89XXCC_SERDES:
  127. case E1000_DEV_ID_DH89XXCC_BACKPLANE:
  128. case E1000_DEV_ID_DH89XXCC_SFP:
  129. mac->type = e1000_82580;
  130. break;
  131. case E1000_DEV_ID_I350_COPPER:
  132. case E1000_DEV_ID_I350_FIBER:
  133. case E1000_DEV_ID_I350_SERDES:
  134. case E1000_DEV_ID_I350_SGMII:
  135. mac->type = e1000_i350;
  136. break;
  137. default:
  138. return -E1000_ERR_MAC_INIT;
  139. break;
  140. }
  141. /* Set media type */
  142. /*
  143. * The 82575 uses bits 22:23 for link mode. The mode can be changed
  144. * based on the EEPROM. We cannot rely upon device ID. There
  145. * is no distinguishable difference between fiber and internal
  146. * SerDes mode on the 82575. There can be an external PHY attached
  147. * on the SGMII interface. For this, we'll set sgmii_active to true.
  148. */
  149. phy->media_type = e1000_media_type_copper;
  150. dev_spec->sgmii_active = false;
  151. ctrl_ext = rd32(E1000_CTRL_EXT);
  152. switch (ctrl_ext & E1000_CTRL_EXT_LINK_MODE_MASK) {
  153. case E1000_CTRL_EXT_LINK_MODE_SGMII:
  154. dev_spec->sgmii_active = true;
  155. break;
  156. case E1000_CTRL_EXT_LINK_MODE_1000BASE_KX:
  157. case E1000_CTRL_EXT_LINK_MODE_PCIE_SERDES:
  158. hw->phy.media_type = e1000_media_type_internal_serdes;
  159. break;
  160. default:
  161. break;
  162. }
  163. /* Set mta register count */
  164. mac->mta_reg_count = 128;
  165. /* Set rar entry count */
  166. mac->rar_entry_count = E1000_RAR_ENTRIES_82575;
  167. if (mac->type == e1000_82576)
  168. mac->rar_entry_count = E1000_RAR_ENTRIES_82576;
  169. if (mac->type == e1000_82580)
  170. mac->rar_entry_count = E1000_RAR_ENTRIES_82580;
  171. if (mac->type == e1000_i350)
  172. mac->rar_entry_count = E1000_RAR_ENTRIES_I350;
  173. /* reset */
  174. if (mac->type >= e1000_82580)
  175. mac->ops.reset_hw = igb_reset_hw_82580;
  176. else
  177. mac->ops.reset_hw = igb_reset_hw_82575;
  178. /* Set if part includes ASF firmware */
  179. mac->asf_firmware_present = true;
  180. /* Set if manageability features are enabled. */
  181. mac->arc_subsystem_valid =
  182. (rd32(E1000_FWSM) & E1000_FWSM_MODE_MASK)
  183. ? true : false;
  184. /* enable EEE on i350 parts */
  185. if (mac->type == e1000_i350)
  186. dev_spec->eee_disable = false;
  187. else
  188. dev_spec->eee_disable = true;
  189. /* physical interface link setup */
  190. mac->ops.setup_physical_interface =
  191. (hw->phy.media_type == e1000_media_type_copper)
  192. ? igb_setup_copper_link_82575
  193. : igb_setup_serdes_link_82575;
  194. /* NVM initialization */
  195. eecd = rd32(E1000_EECD);
  196. nvm->opcode_bits = 8;
  197. nvm->delay_usec = 1;
  198. switch (nvm->override) {
  199. case e1000_nvm_override_spi_large:
  200. nvm->page_size = 32;
  201. nvm->address_bits = 16;
  202. break;
  203. case e1000_nvm_override_spi_small:
  204. nvm->page_size = 8;
  205. nvm->address_bits = 8;
  206. break;
  207. default:
  208. nvm->page_size = eecd & E1000_EECD_ADDR_BITS ? 32 : 8;
  209. nvm->address_bits = eecd & E1000_EECD_ADDR_BITS ? 16 : 8;
  210. break;
  211. }
  212. nvm->type = e1000_nvm_eeprom_spi;
  213. size = (u16)((eecd & E1000_EECD_SIZE_EX_MASK) >>
  214. E1000_EECD_SIZE_EX_SHIFT);
  215. /*
  216. * Added to a constant, "size" becomes the left-shift value
  217. * for setting word_size.
  218. */
  219. size += NVM_WORD_SIZE_BASE_SHIFT;
  220. /*
  221. * Check for invalid size
  222. */
  223. if ((hw->mac.type == e1000_82576) && (size > 15)) {
  224. pr_notice("The NVM size is not valid, defaulting to 32K\n");
  225. size = 15;
  226. }
  227. nvm->word_size = 1 << size;
  228. if (nvm->word_size == (1 << 15))
  229. nvm->page_size = 128;
  230. /* NVM Function Pointers */
  231. nvm->ops.acquire = igb_acquire_nvm_82575;
  232. if (nvm->word_size < (1 << 15))
  233. nvm->ops.read = igb_read_nvm_eerd;
  234. else
  235. nvm->ops.read = igb_read_nvm_spi;
  236. nvm->ops.release = igb_release_nvm_82575;
  237. switch (hw->mac.type) {
  238. case e1000_82580:
  239. nvm->ops.validate = igb_validate_nvm_checksum_82580;
  240. nvm->ops.update = igb_update_nvm_checksum_82580;
  241. break;
  242. case e1000_i350:
  243. nvm->ops.validate = igb_validate_nvm_checksum_i350;
  244. nvm->ops.update = igb_update_nvm_checksum_i350;
  245. break;
  246. default:
  247. nvm->ops.validate = igb_validate_nvm_checksum;
  248. nvm->ops.update = igb_update_nvm_checksum;
  249. }
  250. nvm->ops.write = igb_write_nvm_spi;
  251. /* if part supports SR-IOV then initialize mailbox parameters */
  252. switch (mac->type) {
  253. case e1000_82576:
  254. case e1000_i350:
  255. igb_init_mbx_params_pf(hw);
  256. break;
  257. default:
  258. break;
  259. }
  260. /* setup PHY parameters */
  261. if (phy->media_type != e1000_media_type_copper) {
  262. phy->type = e1000_phy_none;
  263. return 0;
  264. }
  265. phy->autoneg_mask = AUTONEG_ADVERTISE_SPEED_DEFAULT;
  266. phy->reset_delay_us = 100;
  267. ctrl_ext = rd32(E1000_CTRL_EXT);
  268. /* PHY function pointers */
  269. if (igb_sgmii_active_82575(hw)) {
  270. phy->ops.reset = igb_phy_hw_reset_sgmii_82575;
  271. ctrl_ext |= E1000_CTRL_I2C_ENA;
  272. } else {
  273. phy->ops.reset = igb_phy_hw_reset;
  274. ctrl_ext &= ~E1000_CTRL_I2C_ENA;
  275. }
  276. wr32(E1000_CTRL_EXT, ctrl_ext);
  277. igb_reset_mdicnfg_82580(hw);
  278. if (igb_sgmii_active_82575(hw) && !igb_sgmii_uses_mdio_82575(hw)) {
  279. phy->ops.read_reg = igb_read_phy_reg_sgmii_82575;
  280. phy->ops.write_reg = igb_write_phy_reg_sgmii_82575;
  281. } else if (hw->mac.type >= e1000_82580) {
  282. phy->ops.read_reg = igb_read_phy_reg_82580;
  283. phy->ops.write_reg = igb_write_phy_reg_82580;
  284. } else {
  285. phy->ops.read_reg = igb_read_phy_reg_igp;
  286. phy->ops.write_reg = igb_write_phy_reg_igp;
  287. }
  288. /* set lan id */
  289. hw->bus.func = (rd32(E1000_STATUS) & E1000_STATUS_FUNC_MASK) >>
  290. E1000_STATUS_FUNC_SHIFT;
  291. /* Set phy->phy_addr and phy->id. */
  292. ret_val = igb_get_phy_id_82575(hw);
  293. if (ret_val)
  294. return ret_val;
  295. /* Verify phy id and set remaining function pointers */
  296. switch (phy->id) {
  297. case I347AT4_E_PHY_ID:
  298. case M88E1112_E_PHY_ID:
  299. case M88E1111_I_PHY_ID:
  300. phy->type = e1000_phy_m88;
  301. phy->ops.get_phy_info = igb_get_phy_info_m88;
  302. if (phy->id == I347AT4_E_PHY_ID ||
  303. phy->id == M88E1112_E_PHY_ID)
  304. phy->ops.get_cable_length = igb_get_cable_length_m88_gen2;
  305. else
  306. phy->ops.get_cable_length = igb_get_cable_length_m88;
  307. phy->ops.force_speed_duplex = igb_phy_force_speed_duplex_m88;
  308. break;
  309. case IGP03E1000_E_PHY_ID:
  310. phy->type = e1000_phy_igp_3;
  311. phy->ops.get_phy_info = igb_get_phy_info_igp;
  312. phy->ops.get_cable_length = igb_get_cable_length_igp_2;
  313. phy->ops.force_speed_duplex = igb_phy_force_speed_duplex_igp;
  314. phy->ops.set_d0_lplu_state = igb_set_d0_lplu_state_82575;
  315. phy->ops.set_d3_lplu_state = igb_set_d3_lplu_state;
  316. break;
  317. case I82580_I_PHY_ID:
  318. case I350_I_PHY_ID:
  319. phy->type = e1000_phy_82580;
  320. phy->ops.force_speed_duplex = igb_phy_force_speed_duplex_82580;
  321. phy->ops.get_cable_length = igb_get_cable_length_82580;
  322. phy->ops.get_phy_info = igb_get_phy_info_82580;
  323. break;
  324. default:
  325. return -E1000_ERR_PHY;
  326. }
  327. return 0;
  328. }
  329. /**
  330. * igb_acquire_phy_82575 - Acquire rights to access PHY
  331. * @hw: pointer to the HW structure
  332. *
  333. * Acquire access rights to the correct PHY. This is a
  334. * function pointer entry point called by the api module.
  335. **/
  336. static s32 igb_acquire_phy_82575(struct e1000_hw *hw)
  337. {
  338. u16 mask = E1000_SWFW_PHY0_SM;
  339. if (hw->bus.func == E1000_FUNC_1)
  340. mask = E1000_SWFW_PHY1_SM;
  341. else if (hw->bus.func == E1000_FUNC_2)
  342. mask = E1000_SWFW_PHY2_SM;
  343. else if (hw->bus.func == E1000_FUNC_3)
  344. mask = E1000_SWFW_PHY3_SM;
  345. return igb_acquire_swfw_sync_82575(hw, mask);
  346. }
  347. /**
  348. * igb_release_phy_82575 - Release rights to access PHY
  349. * @hw: pointer to the HW structure
  350. *
  351. * A wrapper to release access rights to the correct PHY. This is a
  352. * function pointer entry point called by the api module.
  353. **/
  354. static void igb_release_phy_82575(struct e1000_hw *hw)
  355. {
  356. u16 mask = E1000_SWFW_PHY0_SM;
  357. if (hw->bus.func == E1000_FUNC_1)
  358. mask = E1000_SWFW_PHY1_SM;
  359. else if (hw->bus.func == E1000_FUNC_2)
  360. mask = E1000_SWFW_PHY2_SM;
  361. else if (hw->bus.func == E1000_FUNC_3)
  362. mask = E1000_SWFW_PHY3_SM;
  363. igb_release_swfw_sync_82575(hw, mask);
  364. }
  365. /**
  366. * igb_read_phy_reg_sgmii_82575 - Read PHY register using sgmii
  367. * @hw: pointer to the HW structure
  368. * @offset: register offset to be read
  369. * @data: pointer to the read data
  370. *
  371. * Reads the PHY register at offset using the serial gigabit media independent
  372. * interface and stores the retrieved information in data.
  373. **/
  374. static s32 igb_read_phy_reg_sgmii_82575(struct e1000_hw *hw, u32 offset,
  375. u16 *data)
  376. {
  377. s32 ret_val = -E1000_ERR_PARAM;
  378. if (offset > E1000_MAX_SGMII_PHY_REG_ADDR) {
  379. hw_dbg("PHY Address %u is out of range\n", offset);
  380. goto out;
  381. }
  382. ret_val = hw->phy.ops.acquire(hw);
  383. if (ret_val)
  384. goto out;
  385. ret_val = igb_read_phy_reg_i2c(hw, offset, data);
  386. hw->phy.ops.release(hw);
  387. out:
  388. return ret_val;
  389. }
  390. /**
  391. * igb_write_phy_reg_sgmii_82575 - Write PHY register using sgmii
  392. * @hw: pointer to the HW structure
  393. * @offset: register offset to write to
  394. * @data: data to write at register offset
  395. *
  396. * Writes the data to PHY register at the offset using the serial gigabit
  397. * media independent interface.
  398. **/
  399. static s32 igb_write_phy_reg_sgmii_82575(struct e1000_hw *hw, u32 offset,
  400. u16 data)
  401. {
  402. s32 ret_val = -E1000_ERR_PARAM;
  403. if (offset > E1000_MAX_SGMII_PHY_REG_ADDR) {
  404. hw_dbg("PHY Address %d is out of range\n", offset);
  405. goto out;
  406. }
  407. ret_val = hw->phy.ops.acquire(hw);
  408. if (ret_val)
  409. goto out;
  410. ret_val = igb_write_phy_reg_i2c(hw, offset, data);
  411. hw->phy.ops.release(hw);
  412. out:
  413. return ret_val;
  414. }
  415. /**
  416. * igb_get_phy_id_82575 - Retrieve PHY addr and id
  417. * @hw: pointer to the HW structure
  418. *
  419. * Retrieves the PHY address and ID for both PHY's which do and do not use
  420. * sgmi interface.
  421. **/
  422. static s32 igb_get_phy_id_82575(struct e1000_hw *hw)
  423. {
  424. struct e1000_phy_info *phy = &hw->phy;
  425. s32 ret_val = 0;
  426. u16 phy_id;
  427. u32 ctrl_ext;
  428. u32 mdic;
  429. /*
  430. * For SGMII PHYs, we try the list of possible addresses until
  431. * we find one that works. For non-SGMII PHYs
  432. * (e.g. integrated copper PHYs), an address of 1 should
  433. * work. The result of this function should mean phy->phy_addr
  434. * and phy->id are set correctly.
  435. */
  436. if (!(igb_sgmii_active_82575(hw))) {
  437. phy->addr = 1;
  438. ret_val = igb_get_phy_id(hw);
  439. goto out;
  440. }
  441. if (igb_sgmii_uses_mdio_82575(hw)) {
  442. switch (hw->mac.type) {
  443. case e1000_82575:
  444. case e1000_82576:
  445. mdic = rd32(E1000_MDIC);
  446. mdic &= E1000_MDIC_PHY_MASK;
  447. phy->addr = mdic >> E1000_MDIC_PHY_SHIFT;
  448. break;
  449. case e1000_82580:
  450. case e1000_i350:
  451. mdic = rd32(E1000_MDICNFG);
  452. mdic &= E1000_MDICNFG_PHY_MASK;
  453. phy->addr = mdic >> E1000_MDICNFG_PHY_SHIFT;
  454. break;
  455. default:
  456. ret_val = -E1000_ERR_PHY;
  457. goto out;
  458. break;
  459. }
  460. ret_val = igb_get_phy_id(hw);
  461. goto out;
  462. }
  463. /* Power on sgmii phy if it is disabled */
  464. ctrl_ext = rd32(E1000_CTRL_EXT);
  465. wr32(E1000_CTRL_EXT, ctrl_ext & ~E1000_CTRL_EXT_SDP3_DATA);
  466. wrfl();
  467. msleep(300);
  468. /*
  469. * The address field in the I2CCMD register is 3 bits and 0 is invalid.
  470. * Therefore, we need to test 1-7
  471. */
  472. for (phy->addr = 1; phy->addr < 8; phy->addr++) {
  473. ret_val = igb_read_phy_reg_sgmii_82575(hw, PHY_ID1, &phy_id);
  474. if (ret_val == 0) {
  475. hw_dbg("Vendor ID 0x%08X read at address %u\n",
  476. phy_id, phy->addr);
  477. /*
  478. * At the time of this writing, The M88 part is
  479. * the only supported SGMII PHY product.
  480. */
  481. if (phy_id == M88_VENDOR)
  482. break;
  483. } else {
  484. hw_dbg("PHY address %u was unreadable\n", phy->addr);
  485. }
  486. }
  487. /* A valid PHY type couldn't be found. */
  488. if (phy->addr == 8) {
  489. phy->addr = 0;
  490. ret_val = -E1000_ERR_PHY;
  491. goto out;
  492. } else {
  493. ret_val = igb_get_phy_id(hw);
  494. }
  495. /* restore previous sfp cage power state */
  496. wr32(E1000_CTRL_EXT, ctrl_ext);
  497. out:
  498. return ret_val;
  499. }
  500. /**
  501. * igb_phy_hw_reset_sgmii_82575 - Performs a PHY reset
  502. * @hw: pointer to the HW structure
  503. *
  504. * Resets the PHY using the serial gigabit media independent interface.
  505. **/
  506. static s32 igb_phy_hw_reset_sgmii_82575(struct e1000_hw *hw)
  507. {
  508. s32 ret_val;
  509. /*
  510. * This isn't a true "hard" reset, but is the only reset
  511. * available to us at this time.
  512. */
  513. hw_dbg("Soft resetting SGMII attached PHY...\n");
  514. /*
  515. * SFP documentation requires the following to configure the SPF module
  516. * to work on SGMII. No further documentation is given.
  517. */
  518. ret_val = hw->phy.ops.write_reg(hw, 0x1B, 0x8084);
  519. if (ret_val)
  520. goto out;
  521. ret_val = igb_phy_sw_reset(hw);
  522. out:
  523. return ret_val;
  524. }
  525. /**
  526. * igb_set_d0_lplu_state_82575 - Set Low Power Linkup D0 state
  527. * @hw: pointer to the HW structure
  528. * @active: true to enable LPLU, false to disable
  529. *
  530. * Sets the LPLU D0 state according to the active flag. When
  531. * activating LPLU this function also disables smart speed
  532. * and vice versa. LPLU will not be activated unless the
  533. * device autonegotiation advertisement meets standards of
  534. * either 10 or 10/100 or 10/100/1000 at all duplexes.
  535. * This is a function pointer entry point only called by
  536. * PHY setup routines.
  537. **/
  538. static s32 igb_set_d0_lplu_state_82575(struct e1000_hw *hw, bool active)
  539. {
  540. struct e1000_phy_info *phy = &hw->phy;
  541. s32 ret_val;
  542. u16 data;
  543. ret_val = phy->ops.read_reg(hw, IGP02E1000_PHY_POWER_MGMT, &data);
  544. if (ret_val)
  545. goto out;
  546. if (active) {
  547. data |= IGP02E1000_PM_D0_LPLU;
  548. ret_val = phy->ops.write_reg(hw, IGP02E1000_PHY_POWER_MGMT,
  549. data);
  550. if (ret_val)
  551. goto out;
  552. /* When LPLU is enabled, we should disable SmartSpeed */
  553. ret_val = phy->ops.read_reg(hw, IGP01E1000_PHY_PORT_CONFIG,
  554. &data);
  555. data &= ~IGP01E1000_PSCFR_SMART_SPEED;
  556. ret_val = phy->ops.write_reg(hw, IGP01E1000_PHY_PORT_CONFIG,
  557. data);
  558. if (ret_val)
  559. goto out;
  560. } else {
  561. data &= ~IGP02E1000_PM_D0_LPLU;
  562. ret_val = phy->ops.write_reg(hw, IGP02E1000_PHY_POWER_MGMT,
  563. data);
  564. /*
  565. * LPLU and SmartSpeed are mutually exclusive. LPLU is used
  566. * during Dx states where the power conservation is most
  567. * important. During driver activity we should enable
  568. * SmartSpeed, so performance is maintained.
  569. */
  570. if (phy->smart_speed == e1000_smart_speed_on) {
  571. ret_val = phy->ops.read_reg(hw,
  572. IGP01E1000_PHY_PORT_CONFIG, &data);
  573. if (ret_val)
  574. goto out;
  575. data |= IGP01E1000_PSCFR_SMART_SPEED;
  576. ret_val = phy->ops.write_reg(hw,
  577. IGP01E1000_PHY_PORT_CONFIG, data);
  578. if (ret_val)
  579. goto out;
  580. } else if (phy->smart_speed == e1000_smart_speed_off) {
  581. ret_val = phy->ops.read_reg(hw,
  582. IGP01E1000_PHY_PORT_CONFIG, &data);
  583. if (ret_val)
  584. goto out;
  585. data &= ~IGP01E1000_PSCFR_SMART_SPEED;
  586. ret_val = phy->ops.write_reg(hw,
  587. IGP01E1000_PHY_PORT_CONFIG, data);
  588. if (ret_val)
  589. goto out;
  590. }
  591. }
  592. out:
  593. return ret_val;
  594. }
  595. /**
  596. * igb_acquire_nvm_82575 - Request for access to EEPROM
  597. * @hw: pointer to the HW structure
  598. *
  599. * Acquire the necessary semaphores for exclusive access to the EEPROM.
  600. * Set the EEPROM access request bit and wait for EEPROM access grant bit.
  601. * Return successful if access grant bit set, else clear the request for
  602. * EEPROM access and return -E1000_ERR_NVM (-1).
  603. **/
  604. static s32 igb_acquire_nvm_82575(struct e1000_hw *hw)
  605. {
  606. s32 ret_val;
  607. ret_val = igb_acquire_swfw_sync_82575(hw, E1000_SWFW_EEP_SM);
  608. if (ret_val)
  609. goto out;
  610. ret_val = igb_acquire_nvm(hw);
  611. if (ret_val)
  612. igb_release_swfw_sync_82575(hw, E1000_SWFW_EEP_SM);
  613. out:
  614. return ret_val;
  615. }
  616. /**
  617. * igb_release_nvm_82575 - Release exclusive access to EEPROM
  618. * @hw: pointer to the HW structure
  619. *
  620. * Stop any current commands to the EEPROM and clear the EEPROM request bit,
  621. * then release the semaphores acquired.
  622. **/
  623. static void igb_release_nvm_82575(struct e1000_hw *hw)
  624. {
  625. igb_release_nvm(hw);
  626. igb_release_swfw_sync_82575(hw, E1000_SWFW_EEP_SM);
  627. }
  628. /**
  629. * igb_acquire_swfw_sync_82575 - Acquire SW/FW semaphore
  630. * @hw: pointer to the HW structure
  631. * @mask: specifies which semaphore to acquire
  632. *
  633. * Acquire the SW/FW semaphore to access the PHY or NVM. The mask
  634. * will also specify which port we're acquiring the lock for.
  635. **/
  636. static s32 igb_acquire_swfw_sync_82575(struct e1000_hw *hw, u16 mask)
  637. {
  638. u32 swfw_sync;
  639. u32 swmask = mask;
  640. u32 fwmask = mask << 16;
  641. s32 ret_val = 0;
  642. s32 i = 0, timeout = 200; /* FIXME: find real value to use here */
  643. while (i < timeout) {
  644. if (igb_get_hw_semaphore(hw)) {
  645. ret_val = -E1000_ERR_SWFW_SYNC;
  646. goto out;
  647. }
  648. swfw_sync = rd32(E1000_SW_FW_SYNC);
  649. if (!(swfw_sync & (fwmask | swmask)))
  650. break;
  651. /*
  652. * Firmware currently using resource (fwmask)
  653. * or other software thread using resource (swmask)
  654. */
  655. igb_put_hw_semaphore(hw);
  656. mdelay(5);
  657. i++;
  658. }
  659. if (i == timeout) {
  660. hw_dbg("Driver can't access resource, SW_FW_SYNC timeout.\n");
  661. ret_val = -E1000_ERR_SWFW_SYNC;
  662. goto out;
  663. }
  664. swfw_sync |= swmask;
  665. wr32(E1000_SW_FW_SYNC, swfw_sync);
  666. igb_put_hw_semaphore(hw);
  667. out:
  668. return ret_val;
  669. }
  670. /**
  671. * igb_release_swfw_sync_82575 - Release SW/FW semaphore
  672. * @hw: pointer to the HW structure
  673. * @mask: specifies which semaphore to acquire
  674. *
  675. * Release the SW/FW semaphore used to access the PHY or NVM. The mask
  676. * will also specify which port we're releasing the lock for.
  677. **/
  678. static void igb_release_swfw_sync_82575(struct e1000_hw *hw, u16 mask)
  679. {
  680. u32 swfw_sync;
  681. while (igb_get_hw_semaphore(hw) != 0);
  682. /* Empty */
  683. swfw_sync = rd32(E1000_SW_FW_SYNC);
  684. swfw_sync &= ~mask;
  685. wr32(E1000_SW_FW_SYNC, swfw_sync);
  686. igb_put_hw_semaphore(hw);
  687. }
  688. /**
  689. * igb_get_cfg_done_82575 - Read config done bit
  690. * @hw: pointer to the HW structure
  691. *
  692. * Read the management control register for the config done bit for
  693. * completion status. NOTE: silicon which is EEPROM-less will fail trying
  694. * to read the config done bit, so an error is *ONLY* logged and returns
  695. * 0. If we were to return with error, EEPROM-less silicon
  696. * would not be able to be reset or change link.
  697. **/
  698. static s32 igb_get_cfg_done_82575(struct e1000_hw *hw)
  699. {
  700. s32 timeout = PHY_CFG_TIMEOUT;
  701. s32 ret_val = 0;
  702. u32 mask = E1000_NVM_CFG_DONE_PORT_0;
  703. if (hw->bus.func == 1)
  704. mask = E1000_NVM_CFG_DONE_PORT_1;
  705. else if (hw->bus.func == E1000_FUNC_2)
  706. mask = E1000_NVM_CFG_DONE_PORT_2;
  707. else if (hw->bus.func == E1000_FUNC_3)
  708. mask = E1000_NVM_CFG_DONE_PORT_3;
  709. while (timeout) {
  710. if (rd32(E1000_EEMNGCTL) & mask)
  711. break;
  712. msleep(1);
  713. timeout--;
  714. }
  715. if (!timeout)
  716. hw_dbg("MNG configuration cycle has not completed.\n");
  717. /* If EEPROM is not marked present, init the PHY manually */
  718. if (((rd32(E1000_EECD) & E1000_EECD_PRES) == 0) &&
  719. (hw->phy.type == e1000_phy_igp_3))
  720. igb_phy_init_script_igp3(hw);
  721. return ret_val;
  722. }
  723. /**
  724. * igb_check_for_link_82575 - Check for link
  725. * @hw: pointer to the HW structure
  726. *
  727. * If sgmii is enabled, then use the pcs register to determine link, otherwise
  728. * use the generic interface for determining link.
  729. **/
  730. static s32 igb_check_for_link_82575(struct e1000_hw *hw)
  731. {
  732. s32 ret_val;
  733. u16 speed, duplex;
  734. if (hw->phy.media_type != e1000_media_type_copper) {
  735. ret_val = igb_get_pcs_speed_and_duplex_82575(hw, &speed,
  736. &duplex);
  737. /*
  738. * Use this flag to determine if link needs to be checked or
  739. * not. If we have link clear the flag so that we do not
  740. * continue to check for link.
  741. */
  742. hw->mac.get_link_status = !hw->mac.serdes_has_link;
  743. } else {
  744. ret_val = igb_check_for_copper_link(hw);
  745. }
  746. return ret_val;
  747. }
  748. /**
  749. * igb_power_up_serdes_link_82575 - Power up the serdes link after shutdown
  750. * @hw: pointer to the HW structure
  751. **/
  752. void igb_power_up_serdes_link_82575(struct e1000_hw *hw)
  753. {
  754. u32 reg;
  755. if ((hw->phy.media_type != e1000_media_type_internal_serdes) &&
  756. !igb_sgmii_active_82575(hw))
  757. return;
  758. /* Enable PCS to turn on link */
  759. reg = rd32(E1000_PCS_CFG0);
  760. reg |= E1000_PCS_CFG_PCS_EN;
  761. wr32(E1000_PCS_CFG0, reg);
  762. /* Power up the laser */
  763. reg = rd32(E1000_CTRL_EXT);
  764. reg &= ~E1000_CTRL_EXT_SDP3_DATA;
  765. wr32(E1000_CTRL_EXT, reg);
  766. /* flush the write to verify completion */
  767. wrfl();
  768. msleep(1);
  769. }
  770. /**
  771. * igb_get_pcs_speed_and_duplex_82575 - Retrieve current speed/duplex
  772. * @hw: pointer to the HW structure
  773. * @speed: stores the current speed
  774. * @duplex: stores the current duplex
  775. *
  776. * Using the physical coding sub-layer (PCS), retrieve the current speed and
  777. * duplex, then store the values in the pointers provided.
  778. **/
  779. static s32 igb_get_pcs_speed_and_duplex_82575(struct e1000_hw *hw, u16 *speed,
  780. u16 *duplex)
  781. {
  782. struct e1000_mac_info *mac = &hw->mac;
  783. u32 pcs;
  784. /* Set up defaults for the return values of this function */
  785. mac->serdes_has_link = false;
  786. *speed = 0;
  787. *duplex = 0;
  788. /*
  789. * Read the PCS Status register for link state. For non-copper mode,
  790. * the status register is not accurate. The PCS status register is
  791. * used instead.
  792. */
  793. pcs = rd32(E1000_PCS_LSTAT);
  794. /*
  795. * The link up bit determines when link is up on autoneg. The sync ok
  796. * gets set once both sides sync up and agree upon link. Stable link
  797. * can be determined by checking for both link up and link sync ok
  798. */
  799. if ((pcs & E1000_PCS_LSTS_LINK_OK) && (pcs & E1000_PCS_LSTS_SYNK_OK)) {
  800. mac->serdes_has_link = true;
  801. /* Detect and store PCS speed */
  802. if (pcs & E1000_PCS_LSTS_SPEED_1000) {
  803. *speed = SPEED_1000;
  804. } else if (pcs & E1000_PCS_LSTS_SPEED_100) {
  805. *speed = SPEED_100;
  806. } else {
  807. *speed = SPEED_10;
  808. }
  809. /* Detect and store PCS duplex */
  810. if (pcs & E1000_PCS_LSTS_DUPLEX_FULL) {
  811. *duplex = FULL_DUPLEX;
  812. } else {
  813. *duplex = HALF_DUPLEX;
  814. }
  815. }
  816. return 0;
  817. }
  818. /**
  819. * igb_shutdown_serdes_link_82575 - Remove link during power down
  820. * @hw: pointer to the HW structure
  821. *
  822. * In the case of fiber serdes, shut down optics and PCS on driver unload
  823. * when management pass thru is not enabled.
  824. **/
  825. void igb_shutdown_serdes_link_82575(struct e1000_hw *hw)
  826. {
  827. u32 reg;
  828. if (hw->phy.media_type != e1000_media_type_internal_serdes &&
  829. igb_sgmii_active_82575(hw))
  830. return;
  831. if (!igb_enable_mng_pass_thru(hw)) {
  832. /* Disable PCS to turn off link */
  833. reg = rd32(E1000_PCS_CFG0);
  834. reg &= ~E1000_PCS_CFG_PCS_EN;
  835. wr32(E1000_PCS_CFG0, reg);
  836. /* shutdown the laser */
  837. reg = rd32(E1000_CTRL_EXT);
  838. reg |= E1000_CTRL_EXT_SDP3_DATA;
  839. wr32(E1000_CTRL_EXT, reg);
  840. /* flush the write to verify completion */
  841. wrfl();
  842. msleep(1);
  843. }
  844. }
  845. /**
  846. * igb_reset_hw_82575 - Reset hardware
  847. * @hw: pointer to the HW structure
  848. *
  849. * This resets the hardware into a known state. This is a
  850. * function pointer entry point called by the api module.
  851. **/
  852. static s32 igb_reset_hw_82575(struct e1000_hw *hw)
  853. {
  854. u32 ctrl, icr;
  855. s32 ret_val;
  856. /*
  857. * Prevent the PCI-E bus from sticking if there is no TLP connection
  858. * on the last TLP read/write transaction when MAC is reset.
  859. */
  860. ret_val = igb_disable_pcie_master(hw);
  861. if (ret_val)
  862. hw_dbg("PCI-E Master disable polling has failed.\n");
  863. /* set the completion timeout for interface */
  864. ret_val = igb_set_pcie_completion_timeout(hw);
  865. if (ret_val) {
  866. hw_dbg("PCI-E Set completion timeout has failed.\n");
  867. }
  868. hw_dbg("Masking off all interrupts\n");
  869. wr32(E1000_IMC, 0xffffffff);
  870. wr32(E1000_RCTL, 0);
  871. wr32(E1000_TCTL, E1000_TCTL_PSP);
  872. wrfl();
  873. msleep(10);
  874. ctrl = rd32(E1000_CTRL);
  875. hw_dbg("Issuing a global reset to MAC\n");
  876. wr32(E1000_CTRL, ctrl | E1000_CTRL_RST);
  877. ret_val = igb_get_auto_rd_done(hw);
  878. if (ret_val) {
  879. /*
  880. * When auto config read does not complete, do not
  881. * return with an error. This can happen in situations
  882. * where there is no eeprom and prevents getting link.
  883. */
  884. hw_dbg("Auto Read Done did not complete\n");
  885. }
  886. /* If EEPROM is not present, run manual init scripts */
  887. if ((rd32(E1000_EECD) & E1000_EECD_PRES) == 0)
  888. igb_reset_init_script_82575(hw);
  889. /* Clear any pending interrupt events. */
  890. wr32(E1000_IMC, 0xffffffff);
  891. icr = rd32(E1000_ICR);
  892. /* Install any alternate MAC address into RAR0 */
  893. ret_val = igb_check_alt_mac_addr(hw);
  894. return ret_val;
  895. }
  896. /**
  897. * igb_init_hw_82575 - Initialize hardware
  898. * @hw: pointer to the HW structure
  899. *
  900. * This inits the hardware readying it for operation.
  901. **/
  902. static s32 igb_init_hw_82575(struct e1000_hw *hw)
  903. {
  904. struct e1000_mac_info *mac = &hw->mac;
  905. s32 ret_val;
  906. u16 i, rar_count = mac->rar_entry_count;
  907. /* Initialize identification LED */
  908. ret_val = igb_id_led_init(hw);
  909. if (ret_val) {
  910. hw_dbg("Error initializing identification LED\n");
  911. /* This is not fatal and we should not stop init due to this */
  912. }
  913. /* Disabling VLAN filtering */
  914. hw_dbg("Initializing the IEEE VLAN\n");
  915. if (hw->mac.type == e1000_i350)
  916. igb_clear_vfta_i350(hw);
  917. else
  918. igb_clear_vfta(hw);
  919. /* Setup the receive address */
  920. igb_init_rx_addrs(hw, rar_count);
  921. /* Zero out the Multicast HASH table */
  922. hw_dbg("Zeroing the MTA\n");
  923. for (i = 0; i < mac->mta_reg_count; i++)
  924. array_wr32(E1000_MTA, i, 0);
  925. /* Zero out the Unicast HASH table */
  926. hw_dbg("Zeroing the UTA\n");
  927. for (i = 0; i < mac->uta_reg_count; i++)
  928. array_wr32(E1000_UTA, i, 0);
  929. /* Setup link and flow control */
  930. ret_val = igb_setup_link(hw);
  931. /*
  932. * Clear all of the statistics registers (clear on read). It is
  933. * important that we do this after we have tried to establish link
  934. * because the symbol error count will increment wildly if there
  935. * is no link.
  936. */
  937. igb_clear_hw_cntrs_82575(hw);
  938. return ret_val;
  939. }
  940. /**
  941. * igb_setup_copper_link_82575 - Configure copper link settings
  942. * @hw: pointer to the HW structure
  943. *
  944. * Configures the link for auto-neg or forced speed and duplex. Then we check
  945. * for link, once link is established calls to configure collision distance
  946. * and flow control are called.
  947. **/
  948. static s32 igb_setup_copper_link_82575(struct e1000_hw *hw)
  949. {
  950. u32 ctrl;
  951. s32 ret_val;
  952. ctrl = rd32(E1000_CTRL);
  953. ctrl |= E1000_CTRL_SLU;
  954. ctrl &= ~(E1000_CTRL_FRCSPD | E1000_CTRL_FRCDPX);
  955. wr32(E1000_CTRL, ctrl);
  956. ret_val = igb_setup_serdes_link_82575(hw);
  957. if (ret_val)
  958. goto out;
  959. if (igb_sgmii_active_82575(hw) && !hw->phy.reset_disable) {
  960. /* allow time for SFP cage time to power up phy */
  961. msleep(300);
  962. ret_val = hw->phy.ops.reset(hw);
  963. if (ret_val) {
  964. hw_dbg("Error resetting the PHY.\n");
  965. goto out;
  966. }
  967. }
  968. switch (hw->phy.type) {
  969. case e1000_phy_m88:
  970. if (hw->phy.id == I347AT4_E_PHY_ID ||
  971. hw->phy.id == M88E1112_E_PHY_ID)
  972. ret_val = igb_copper_link_setup_m88_gen2(hw);
  973. else
  974. ret_val = igb_copper_link_setup_m88(hw);
  975. break;
  976. case e1000_phy_igp_3:
  977. ret_val = igb_copper_link_setup_igp(hw);
  978. break;
  979. case e1000_phy_82580:
  980. ret_val = igb_copper_link_setup_82580(hw);
  981. break;
  982. default:
  983. ret_val = -E1000_ERR_PHY;
  984. break;
  985. }
  986. if (ret_val)
  987. goto out;
  988. ret_val = igb_setup_copper_link(hw);
  989. out:
  990. return ret_val;
  991. }
  992. /**
  993. * igb_setup_serdes_link_82575 - Setup link for serdes
  994. * @hw: pointer to the HW structure
  995. *
  996. * Configure the physical coding sub-layer (PCS) link. The PCS link is
  997. * used on copper connections where the serialized gigabit media independent
  998. * interface (sgmii), or serdes fiber is being used. Configures the link
  999. * for auto-negotiation or forces speed/duplex.
  1000. **/
  1001. static s32 igb_setup_serdes_link_82575(struct e1000_hw *hw)
  1002. {
  1003. u32 ctrl_ext, ctrl_reg, reg;
  1004. bool pcs_autoneg;
  1005. s32 ret_val = E1000_SUCCESS;
  1006. u16 data;
  1007. if ((hw->phy.media_type != e1000_media_type_internal_serdes) &&
  1008. !igb_sgmii_active_82575(hw))
  1009. return ret_val;
  1010. /*
  1011. * On the 82575, SerDes loopback mode persists until it is
  1012. * explicitly turned off or a power cycle is performed. A read to
  1013. * the register does not indicate its status. Therefore, we ensure
  1014. * loopback mode is disabled during initialization.
  1015. */
  1016. wr32(E1000_SCTL, E1000_SCTL_DISABLE_SERDES_LOOPBACK);
  1017. /* power on the sfp cage if present */
  1018. ctrl_ext = rd32(E1000_CTRL_EXT);
  1019. ctrl_ext &= ~E1000_CTRL_EXT_SDP3_DATA;
  1020. wr32(E1000_CTRL_EXT, ctrl_ext);
  1021. ctrl_reg = rd32(E1000_CTRL);
  1022. ctrl_reg |= E1000_CTRL_SLU;
  1023. if (hw->mac.type == e1000_82575 || hw->mac.type == e1000_82576) {
  1024. /* set both sw defined pins */
  1025. ctrl_reg |= E1000_CTRL_SWDPIN0 | E1000_CTRL_SWDPIN1;
  1026. /* Set switch control to serdes energy detect */
  1027. reg = rd32(E1000_CONNSW);
  1028. reg |= E1000_CONNSW_ENRGSRC;
  1029. wr32(E1000_CONNSW, reg);
  1030. }
  1031. reg = rd32(E1000_PCS_LCTL);
  1032. /* default pcs_autoneg to the same setting as mac autoneg */
  1033. pcs_autoneg = hw->mac.autoneg;
  1034. switch (ctrl_ext & E1000_CTRL_EXT_LINK_MODE_MASK) {
  1035. case E1000_CTRL_EXT_LINK_MODE_SGMII:
  1036. /* sgmii mode lets the phy handle forcing speed/duplex */
  1037. pcs_autoneg = true;
  1038. /* autoneg time out should be disabled for SGMII mode */
  1039. reg &= ~(E1000_PCS_LCTL_AN_TIMEOUT);
  1040. break;
  1041. case E1000_CTRL_EXT_LINK_MODE_1000BASE_KX:
  1042. /* disable PCS autoneg and support parallel detect only */
  1043. pcs_autoneg = false;
  1044. default:
  1045. if (hw->mac.type == e1000_82575 ||
  1046. hw->mac.type == e1000_82576) {
  1047. ret_val = hw->nvm.ops.read(hw, NVM_COMPAT, 1, &data);
  1048. if (ret_val) {
  1049. printk(KERN_DEBUG "NVM Read Error\n\n");
  1050. return ret_val;
  1051. }
  1052. if (data & E1000_EEPROM_PCS_AUTONEG_DISABLE_BIT)
  1053. pcs_autoneg = false;
  1054. }
  1055. /*
  1056. * non-SGMII modes only supports a speed of 1000/Full for the
  1057. * link so it is best to just force the MAC and let the pcs
  1058. * link either autoneg or be forced to 1000/Full
  1059. */
  1060. ctrl_reg |= E1000_CTRL_SPD_1000 | E1000_CTRL_FRCSPD |
  1061. E1000_CTRL_FD | E1000_CTRL_FRCDPX;
  1062. /* set speed of 1000/Full if speed/duplex is forced */
  1063. reg |= E1000_PCS_LCTL_FSV_1000 | E1000_PCS_LCTL_FDV_FULL;
  1064. break;
  1065. }
  1066. wr32(E1000_CTRL, ctrl_reg);
  1067. /*
  1068. * New SerDes mode allows for forcing speed or autonegotiating speed
  1069. * at 1gb. Autoneg should be default set by most drivers. This is the
  1070. * mode that will be compatible with older link partners and switches.
  1071. * However, both are supported by the hardware and some drivers/tools.
  1072. */
  1073. reg &= ~(E1000_PCS_LCTL_AN_ENABLE | E1000_PCS_LCTL_FLV_LINK_UP |
  1074. E1000_PCS_LCTL_FSD | E1000_PCS_LCTL_FORCE_LINK);
  1075. /*
  1076. * We force flow control to prevent the CTRL register values from being
  1077. * overwritten by the autonegotiated flow control values
  1078. */
  1079. reg |= E1000_PCS_LCTL_FORCE_FCTRL;
  1080. if (pcs_autoneg) {
  1081. /* Set PCS register for autoneg */
  1082. reg |= E1000_PCS_LCTL_AN_ENABLE | /* Enable Autoneg */
  1083. E1000_PCS_LCTL_AN_RESTART; /* Restart autoneg */
  1084. hw_dbg("Configuring Autoneg:PCS_LCTL=0x%08X\n", reg);
  1085. } else {
  1086. /* Set PCS register for forced link */
  1087. reg |= E1000_PCS_LCTL_FSD; /* Force Speed */
  1088. hw_dbg("Configuring Forced Link:PCS_LCTL=0x%08X\n", reg);
  1089. }
  1090. wr32(E1000_PCS_LCTL, reg);
  1091. if (!igb_sgmii_active_82575(hw))
  1092. igb_force_mac_fc(hw);
  1093. return ret_val;
  1094. }
  1095. /**
  1096. * igb_sgmii_active_82575 - Return sgmii state
  1097. * @hw: pointer to the HW structure
  1098. *
  1099. * 82575 silicon has a serialized gigabit media independent interface (sgmii)
  1100. * which can be enabled for use in the embedded applications. Simply
  1101. * return the current state of the sgmii interface.
  1102. **/
  1103. static bool igb_sgmii_active_82575(struct e1000_hw *hw)
  1104. {
  1105. struct e1000_dev_spec_82575 *dev_spec = &hw->dev_spec._82575;
  1106. return dev_spec->sgmii_active;
  1107. }
  1108. /**
  1109. * igb_reset_init_script_82575 - Inits HW defaults after reset
  1110. * @hw: pointer to the HW structure
  1111. *
  1112. * Inits recommended HW defaults after a reset when there is no EEPROM
  1113. * detected. This is only for the 82575.
  1114. **/
  1115. static s32 igb_reset_init_script_82575(struct e1000_hw *hw)
  1116. {
  1117. if (hw->mac.type == e1000_82575) {
  1118. hw_dbg("Running reset init script for 82575\n");
  1119. /* SerDes configuration via SERDESCTRL */
  1120. igb_write_8bit_ctrl_reg(hw, E1000_SCTL, 0x00, 0x0C);
  1121. igb_write_8bit_ctrl_reg(hw, E1000_SCTL, 0x01, 0x78);
  1122. igb_write_8bit_ctrl_reg(hw, E1000_SCTL, 0x1B, 0x23);
  1123. igb_write_8bit_ctrl_reg(hw, E1000_SCTL, 0x23, 0x15);
  1124. /* CCM configuration via CCMCTL register */
  1125. igb_write_8bit_ctrl_reg(hw, E1000_CCMCTL, 0x14, 0x00);
  1126. igb_write_8bit_ctrl_reg(hw, E1000_CCMCTL, 0x10, 0x00);
  1127. /* PCIe lanes configuration */
  1128. igb_write_8bit_ctrl_reg(hw, E1000_GIOCTL, 0x00, 0xEC);
  1129. igb_write_8bit_ctrl_reg(hw, E1000_GIOCTL, 0x61, 0xDF);
  1130. igb_write_8bit_ctrl_reg(hw, E1000_GIOCTL, 0x34, 0x05);
  1131. igb_write_8bit_ctrl_reg(hw, E1000_GIOCTL, 0x2F, 0x81);
  1132. /* PCIe PLL Configuration */
  1133. igb_write_8bit_ctrl_reg(hw, E1000_SCCTL, 0x02, 0x47);
  1134. igb_write_8bit_ctrl_reg(hw, E1000_SCCTL, 0x14, 0x00);
  1135. igb_write_8bit_ctrl_reg(hw, E1000_SCCTL, 0x10, 0x00);
  1136. }
  1137. return 0;
  1138. }
  1139. /**
  1140. * igb_read_mac_addr_82575 - Read device MAC address
  1141. * @hw: pointer to the HW structure
  1142. **/
  1143. static s32 igb_read_mac_addr_82575(struct e1000_hw *hw)
  1144. {
  1145. s32 ret_val = 0;
  1146. /*
  1147. * If there's an alternate MAC address place it in RAR0
  1148. * so that it will override the Si installed default perm
  1149. * address.
  1150. */
  1151. ret_val = igb_check_alt_mac_addr(hw);
  1152. if (ret_val)
  1153. goto out;
  1154. ret_val = igb_read_mac_addr(hw);
  1155. out:
  1156. return ret_val;
  1157. }
  1158. /**
  1159. * igb_power_down_phy_copper_82575 - Remove link during PHY power down
  1160. * @hw: pointer to the HW structure
  1161. *
  1162. * In the case of a PHY power down to save power, or to turn off link during a
  1163. * driver unload, or wake on lan is not enabled, remove the link.
  1164. **/
  1165. void igb_power_down_phy_copper_82575(struct e1000_hw *hw)
  1166. {
  1167. /* If the management interface is not enabled, then power down */
  1168. if (!(igb_enable_mng_pass_thru(hw) || igb_check_reset_block(hw)))
  1169. igb_power_down_phy_copper(hw);
  1170. }
  1171. /**
  1172. * igb_clear_hw_cntrs_82575 - Clear device specific hardware counters
  1173. * @hw: pointer to the HW structure
  1174. *
  1175. * Clears the hardware counters by reading the counter registers.
  1176. **/
  1177. static void igb_clear_hw_cntrs_82575(struct e1000_hw *hw)
  1178. {
  1179. igb_clear_hw_cntrs_base(hw);
  1180. rd32(E1000_PRC64);
  1181. rd32(E1000_PRC127);
  1182. rd32(E1000_PRC255);
  1183. rd32(E1000_PRC511);
  1184. rd32(E1000_PRC1023);
  1185. rd32(E1000_PRC1522);
  1186. rd32(E1000_PTC64);
  1187. rd32(E1000_PTC127);
  1188. rd32(E1000_PTC255);
  1189. rd32(E1000_PTC511);
  1190. rd32(E1000_PTC1023);
  1191. rd32(E1000_PTC1522);
  1192. rd32(E1000_ALGNERRC);
  1193. rd32(E1000_RXERRC);
  1194. rd32(E1000_TNCRS);
  1195. rd32(E1000_CEXTERR);
  1196. rd32(E1000_TSCTC);
  1197. rd32(E1000_TSCTFC);
  1198. rd32(E1000_MGTPRC);
  1199. rd32(E1000_MGTPDC);
  1200. rd32(E1000_MGTPTC);
  1201. rd32(E1000_IAC);
  1202. rd32(E1000_ICRXOC);
  1203. rd32(E1000_ICRXPTC);
  1204. rd32(E1000_ICRXATC);
  1205. rd32(E1000_ICTXPTC);
  1206. rd32(E1000_ICTXATC);
  1207. rd32(E1000_ICTXQEC);
  1208. rd32(E1000_ICTXQMTC);
  1209. rd32(E1000_ICRXDMTC);
  1210. rd32(E1000_CBTMPC);
  1211. rd32(E1000_HTDPMC);
  1212. rd32(E1000_CBRMPC);
  1213. rd32(E1000_RPTHC);
  1214. rd32(E1000_HGPTC);
  1215. rd32(E1000_HTCBDPC);
  1216. rd32(E1000_HGORCL);
  1217. rd32(E1000_HGORCH);
  1218. rd32(E1000_HGOTCL);
  1219. rd32(E1000_HGOTCH);
  1220. rd32(E1000_LENERRS);
  1221. /* This register should not be read in copper configurations */
  1222. if (hw->phy.media_type == e1000_media_type_internal_serdes ||
  1223. igb_sgmii_active_82575(hw))
  1224. rd32(E1000_SCVPC);
  1225. }
  1226. /**
  1227. * igb_rx_fifo_flush_82575 - Clean rx fifo after RX enable
  1228. * @hw: pointer to the HW structure
  1229. *
  1230. * After rx enable if managability is enabled then there is likely some
  1231. * bad data at the start of the fifo and possibly in the DMA fifo. This
  1232. * function clears the fifos and flushes any packets that came in as rx was
  1233. * being enabled.
  1234. **/
  1235. void igb_rx_fifo_flush_82575(struct e1000_hw *hw)
  1236. {
  1237. u32 rctl, rlpml, rxdctl[4], rfctl, temp_rctl, rx_enabled;
  1238. int i, ms_wait;
  1239. if (hw->mac.type != e1000_82575 ||
  1240. !(rd32(E1000_MANC) & E1000_MANC_RCV_TCO_EN))
  1241. return;
  1242. /* Disable all RX queues */
  1243. for (i = 0; i < 4; i++) {
  1244. rxdctl[i] = rd32(E1000_RXDCTL(i));
  1245. wr32(E1000_RXDCTL(i),
  1246. rxdctl[i] & ~E1000_RXDCTL_QUEUE_ENABLE);
  1247. }
  1248. /* Poll all queues to verify they have shut down */
  1249. for (ms_wait = 0; ms_wait < 10; ms_wait++) {
  1250. msleep(1);
  1251. rx_enabled = 0;
  1252. for (i = 0; i < 4; i++)
  1253. rx_enabled |= rd32(E1000_RXDCTL(i));
  1254. if (!(rx_enabled & E1000_RXDCTL_QUEUE_ENABLE))
  1255. break;
  1256. }
  1257. if (ms_wait == 10)
  1258. hw_dbg("Queue disable timed out after 10ms\n");
  1259. /* Clear RLPML, RCTL.SBP, RFCTL.LEF, and set RCTL.LPE so that all
  1260. * incoming packets are rejected. Set enable and wait 2ms so that
  1261. * any packet that was coming in as RCTL.EN was set is flushed
  1262. */
  1263. rfctl = rd32(E1000_RFCTL);
  1264. wr32(E1000_RFCTL, rfctl & ~E1000_RFCTL_LEF);
  1265. rlpml = rd32(E1000_RLPML);
  1266. wr32(E1000_RLPML, 0);
  1267. rctl = rd32(E1000_RCTL);
  1268. temp_rctl = rctl & ~(E1000_RCTL_EN | E1000_RCTL_SBP);
  1269. temp_rctl |= E1000_RCTL_LPE;
  1270. wr32(E1000_RCTL, temp_rctl);
  1271. wr32(E1000_RCTL, temp_rctl | E1000_RCTL_EN);
  1272. wrfl();
  1273. msleep(2);
  1274. /* Enable RX queues that were previously enabled and restore our
  1275. * previous state
  1276. */
  1277. for (i = 0; i < 4; i++)
  1278. wr32(E1000_RXDCTL(i), rxdctl[i]);
  1279. wr32(E1000_RCTL, rctl);
  1280. wrfl();
  1281. wr32(E1000_RLPML, rlpml);
  1282. wr32(E1000_RFCTL, rfctl);
  1283. /* Flush receive errors generated by workaround */
  1284. rd32(E1000_ROC);
  1285. rd32(E1000_RNBC);
  1286. rd32(E1000_MPC);
  1287. }
  1288. /**
  1289. * igb_set_pcie_completion_timeout - set pci-e completion timeout
  1290. * @hw: pointer to the HW structure
  1291. *
  1292. * The defaults for 82575 and 82576 should be in the range of 50us to 50ms,
  1293. * however the hardware default for these parts is 500us to 1ms which is less
  1294. * than the 10ms recommended by the pci-e spec. To address this we need to
  1295. * increase the value to either 10ms to 200ms for capability version 1 config,
  1296. * or 16ms to 55ms for version 2.
  1297. **/
  1298. static s32 igb_set_pcie_completion_timeout(struct e1000_hw *hw)
  1299. {
  1300. u32 gcr = rd32(E1000_GCR);
  1301. s32 ret_val = 0;
  1302. u16 pcie_devctl2;
  1303. /* only take action if timeout value is defaulted to 0 */
  1304. if (gcr & E1000_GCR_CMPL_TMOUT_MASK)
  1305. goto out;
  1306. /*
  1307. * if capababilities version is type 1 we can write the
  1308. * timeout of 10ms to 200ms through the GCR register
  1309. */
  1310. if (!(gcr & E1000_GCR_CAP_VER2)) {
  1311. gcr |= E1000_GCR_CMPL_TMOUT_10ms;
  1312. goto out;
  1313. }
  1314. /*
  1315. * for version 2 capabilities we need to write the config space
  1316. * directly in order to set the completion timeout value for
  1317. * 16ms to 55ms
  1318. */
  1319. ret_val = igb_read_pcie_cap_reg(hw, PCIE_DEVICE_CONTROL2,
  1320. &pcie_devctl2);
  1321. if (ret_val)
  1322. goto out;
  1323. pcie_devctl2 |= PCIE_DEVICE_CONTROL2_16ms;
  1324. ret_val = igb_write_pcie_cap_reg(hw, PCIE_DEVICE_CONTROL2,
  1325. &pcie_devctl2);
  1326. out:
  1327. /* disable completion timeout resend */
  1328. gcr &= ~E1000_GCR_CMPL_TMOUT_RESEND;
  1329. wr32(E1000_GCR, gcr);
  1330. return ret_val;
  1331. }
  1332. /**
  1333. * igb_vmdq_set_anti_spoofing_pf - enable or disable anti-spoofing
  1334. * @hw: pointer to the hardware struct
  1335. * @enable: state to enter, either enabled or disabled
  1336. * @pf: Physical Function pool - do not set anti-spoofing for the PF
  1337. *
  1338. * enables/disables L2 switch anti-spoofing functionality.
  1339. **/
  1340. void igb_vmdq_set_anti_spoofing_pf(struct e1000_hw *hw, bool enable, int pf)
  1341. {
  1342. u32 dtxswc;
  1343. switch (hw->mac.type) {
  1344. case e1000_82576:
  1345. case e1000_i350:
  1346. dtxswc = rd32(E1000_DTXSWC);
  1347. if (enable) {
  1348. dtxswc |= (E1000_DTXSWC_MAC_SPOOF_MASK |
  1349. E1000_DTXSWC_VLAN_SPOOF_MASK);
  1350. /* The PF can spoof - it has to in order to
  1351. * support emulation mode NICs */
  1352. dtxswc ^= (1 << pf | 1 << (pf + MAX_NUM_VFS));
  1353. } else {
  1354. dtxswc &= ~(E1000_DTXSWC_MAC_SPOOF_MASK |
  1355. E1000_DTXSWC_VLAN_SPOOF_MASK);
  1356. }
  1357. wr32(E1000_DTXSWC, dtxswc);
  1358. break;
  1359. default:
  1360. break;
  1361. }
  1362. }
  1363. /**
  1364. * igb_vmdq_set_loopback_pf - enable or disable vmdq loopback
  1365. * @hw: pointer to the hardware struct
  1366. * @enable: state to enter, either enabled or disabled
  1367. *
  1368. * enables/disables L2 switch loopback functionality.
  1369. **/
  1370. void igb_vmdq_set_loopback_pf(struct e1000_hw *hw, bool enable)
  1371. {
  1372. u32 dtxswc;
  1373. switch (hw->mac.type) {
  1374. case e1000_82576:
  1375. dtxswc = rd32(E1000_DTXSWC);
  1376. if (enable)
  1377. dtxswc |= E1000_DTXSWC_VMDQ_LOOPBACK_EN;
  1378. else
  1379. dtxswc &= ~E1000_DTXSWC_VMDQ_LOOPBACK_EN;
  1380. wr32(E1000_DTXSWC, dtxswc);
  1381. break;
  1382. case e1000_i350:
  1383. dtxswc = rd32(E1000_TXSWC);
  1384. if (enable)
  1385. dtxswc |= E1000_DTXSWC_VMDQ_LOOPBACK_EN;
  1386. else
  1387. dtxswc &= ~E1000_DTXSWC_VMDQ_LOOPBACK_EN;
  1388. wr32(E1000_TXSWC, dtxswc);
  1389. break;
  1390. default:
  1391. /* Currently no other hardware supports loopback */
  1392. break;
  1393. }
  1394. }
  1395. /**
  1396. * igb_vmdq_set_replication_pf - enable or disable vmdq replication
  1397. * @hw: pointer to the hardware struct
  1398. * @enable: state to enter, either enabled or disabled
  1399. *
  1400. * enables/disables replication of packets across multiple pools.
  1401. **/
  1402. void igb_vmdq_set_replication_pf(struct e1000_hw *hw, bool enable)
  1403. {
  1404. u32 vt_ctl = rd32(E1000_VT_CTL);
  1405. if (enable)
  1406. vt_ctl |= E1000_VT_CTL_VM_REPL_EN;
  1407. else
  1408. vt_ctl &= ~E1000_VT_CTL_VM_REPL_EN;
  1409. wr32(E1000_VT_CTL, vt_ctl);
  1410. }
  1411. /**
  1412. * igb_read_phy_reg_82580 - Read 82580 MDI control register
  1413. * @hw: pointer to the HW structure
  1414. * @offset: register offset to be read
  1415. * @data: pointer to the read data
  1416. *
  1417. * Reads the MDI control register in the PHY at offset and stores the
  1418. * information read to data.
  1419. **/
  1420. static s32 igb_read_phy_reg_82580(struct e1000_hw *hw, u32 offset, u16 *data)
  1421. {
  1422. s32 ret_val;
  1423. ret_val = hw->phy.ops.acquire(hw);
  1424. if (ret_val)
  1425. goto out;
  1426. ret_val = igb_read_phy_reg_mdic(hw, offset, data);
  1427. hw->phy.ops.release(hw);
  1428. out:
  1429. return ret_val;
  1430. }
  1431. /**
  1432. * igb_write_phy_reg_82580 - Write 82580 MDI control register
  1433. * @hw: pointer to the HW structure
  1434. * @offset: register offset to write to
  1435. * @data: data to write to register at offset
  1436. *
  1437. * Writes data to MDI control register in the PHY at offset.
  1438. **/
  1439. static s32 igb_write_phy_reg_82580(struct e1000_hw *hw, u32 offset, u16 data)
  1440. {
  1441. s32 ret_val;
  1442. ret_val = hw->phy.ops.acquire(hw);
  1443. if (ret_val)
  1444. goto out;
  1445. ret_val = igb_write_phy_reg_mdic(hw, offset, data);
  1446. hw->phy.ops.release(hw);
  1447. out:
  1448. return ret_val;
  1449. }
  1450. /**
  1451. * igb_reset_mdicnfg_82580 - Reset MDICNFG destination and com_mdio bits
  1452. * @hw: pointer to the HW structure
  1453. *
  1454. * This resets the the MDICNFG.Destination and MDICNFG.Com_MDIO bits based on
  1455. * the values found in the EEPROM. This addresses an issue in which these
  1456. * bits are not restored from EEPROM after reset.
  1457. **/
  1458. static s32 igb_reset_mdicnfg_82580(struct e1000_hw *hw)
  1459. {
  1460. s32 ret_val = 0;
  1461. u32 mdicnfg;
  1462. u16 nvm_data = 0;
  1463. if (hw->mac.type != e1000_82580)
  1464. goto out;
  1465. if (!igb_sgmii_active_82575(hw))
  1466. goto out;
  1467. ret_val = hw->nvm.ops.read(hw, NVM_INIT_CONTROL3_PORT_A +
  1468. NVM_82580_LAN_FUNC_OFFSET(hw->bus.func), 1,
  1469. &nvm_data);
  1470. if (ret_val) {
  1471. hw_dbg("NVM Read Error\n");
  1472. goto out;
  1473. }
  1474. mdicnfg = rd32(E1000_MDICNFG);
  1475. if (nvm_data & NVM_WORD24_EXT_MDIO)
  1476. mdicnfg |= E1000_MDICNFG_EXT_MDIO;
  1477. if (nvm_data & NVM_WORD24_COM_MDIO)
  1478. mdicnfg |= E1000_MDICNFG_COM_MDIO;
  1479. wr32(E1000_MDICNFG, mdicnfg);
  1480. out:
  1481. return ret_val;
  1482. }
  1483. /**
  1484. * igb_reset_hw_82580 - Reset hardware
  1485. * @hw: pointer to the HW structure
  1486. *
  1487. * This resets function or entire device (all ports, etc.)
  1488. * to a known state.
  1489. **/
  1490. static s32 igb_reset_hw_82580(struct e1000_hw *hw)
  1491. {
  1492. s32 ret_val = 0;
  1493. /* BH SW mailbox bit in SW_FW_SYNC */
  1494. u16 swmbsw_mask = E1000_SW_SYNCH_MB;
  1495. u32 ctrl, icr;
  1496. bool global_device_reset = hw->dev_spec._82575.global_device_reset;
  1497. hw->dev_spec._82575.global_device_reset = false;
  1498. /* Get current control state. */
  1499. ctrl = rd32(E1000_CTRL);
  1500. /*
  1501. * Prevent the PCI-E bus from sticking if there is no TLP connection
  1502. * on the last TLP read/write transaction when MAC is reset.
  1503. */
  1504. ret_val = igb_disable_pcie_master(hw);
  1505. if (ret_val)
  1506. hw_dbg("PCI-E Master disable polling has failed.\n");
  1507. hw_dbg("Masking off all interrupts\n");
  1508. wr32(E1000_IMC, 0xffffffff);
  1509. wr32(E1000_RCTL, 0);
  1510. wr32(E1000_TCTL, E1000_TCTL_PSP);
  1511. wrfl();
  1512. msleep(10);
  1513. /* Determine whether or not a global dev reset is requested */
  1514. if (global_device_reset &&
  1515. igb_acquire_swfw_sync_82575(hw, swmbsw_mask))
  1516. global_device_reset = false;
  1517. if (global_device_reset &&
  1518. !(rd32(E1000_STATUS) & E1000_STAT_DEV_RST_SET))
  1519. ctrl |= E1000_CTRL_DEV_RST;
  1520. else
  1521. ctrl |= E1000_CTRL_RST;
  1522. wr32(E1000_CTRL, ctrl);
  1523. wrfl();
  1524. /* Add delay to insure DEV_RST has time to complete */
  1525. if (global_device_reset)
  1526. msleep(5);
  1527. ret_val = igb_get_auto_rd_done(hw);
  1528. if (ret_val) {
  1529. /*
  1530. * When auto config read does not complete, do not
  1531. * return with an error. This can happen in situations
  1532. * where there is no eeprom and prevents getting link.
  1533. */
  1534. hw_dbg("Auto Read Done did not complete\n");
  1535. }
  1536. /* If EEPROM is not present, run manual init scripts */
  1537. if ((rd32(E1000_EECD) & E1000_EECD_PRES) == 0)
  1538. igb_reset_init_script_82575(hw);
  1539. /* clear global device reset status bit */
  1540. wr32(E1000_STATUS, E1000_STAT_DEV_RST_SET);
  1541. /* Clear any pending interrupt events. */
  1542. wr32(E1000_IMC, 0xffffffff);
  1543. icr = rd32(E1000_ICR);
  1544. ret_val = igb_reset_mdicnfg_82580(hw);
  1545. if (ret_val)
  1546. hw_dbg("Could not reset MDICNFG based on EEPROM\n");
  1547. /* Install any alternate MAC address into RAR0 */
  1548. ret_val = igb_check_alt_mac_addr(hw);
  1549. /* Release semaphore */
  1550. if (global_device_reset)
  1551. igb_release_swfw_sync_82575(hw, swmbsw_mask);
  1552. return ret_val;
  1553. }
  1554. /**
  1555. * igb_rxpbs_adjust_82580 - adjust RXPBS value to reflect actual RX PBA size
  1556. * @data: data received by reading RXPBS register
  1557. *
  1558. * The 82580 uses a table based approach for packet buffer allocation sizes.
  1559. * This function converts the retrieved value into the correct table value
  1560. * 0x0 0x1 0x2 0x3 0x4 0x5 0x6 0x7
  1561. * 0x0 36 72 144 1 2 4 8 16
  1562. * 0x8 35 70 140 rsv rsv rsv rsv rsv
  1563. */
  1564. u16 igb_rxpbs_adjust_82580(u32 data)
  1565. {
  1566. u16 ret_val = 0;
  1567. if (data < E1000_82580_RXPBS_TABLE_SIZE)
  1568. ret_val = e1000_82580_rxpbs_table[data];
  1569. return ret_val;
  1570. }
  1571. /**
  1572. * igb_validate_nvm_checksum_with_offset - Validate EEPROM
  1573. * checksum
  1574. * @hw: pointer to the HW structure
  1575. * @offset: offset in words of the checksum protected region
  1576. *
  1577. * Calculates the EEPROM checksum by reading/adding each word of the EEPROM
  1578. * and then verifies that the sum of the EEPROM is equal to 0xBABA.
  1579. **/
  1580. static s32 igb_validate_nvm_checksum_with_offset(struct e1000_hw *hw,
  1581. u16 offset)
  1582. {
  1583. s32 ret_val = 0;
  1584. u16 checksum = 0;
  1585. u16 i, nvm_data;
  1586. for (i = offset; i < ((NVM_CHECKSUM_REG + offset) + 1); i++) {
  1587. ret_val = hw->nvm.ops.read(hw, i, 1, &nvm_data);
  1588. if (ret_val) {
  1589. hw_dbg("NVM Read Error\n");
  1590. goto out;
  1591. }
  1592. checksum += nvm_data;
  1593. }
  1594. if (checksum != (u16) NVM_SUM) {
  1595. hw_dbg("NVM Checksum Invalid\n");
  1596. ret_val = -E1000_ERR_NVM;
  1597. goto out;
  1598. }
  1599. out:
  1600. return ret_val;
  1601. }
  1602. /**
  1603. * igb_update_nvm_checksum_with_offset - Update EEPROM
  1604. * checksum
  1605. * @hw: pointer to the HW structure
  1606. * @offset: offset in words of the checksum protected region
  1607. *
  1608. * Updates the EEPROM checksum by reading/adding each word of the EEPROM
  1609. * up to the checksum. Then calculates the EEPROM checksum and writes the
  1610. * value to the EEPROM.
  1611. **/
  1612. static s32 igb_update_nvm_checksum_with_offset(struct e1000_hw *hw, u16 offset)
  1613. {
  1614. s32 ret_val;
  1615. u16 checksum = 0;
  1616. u16 i, nvm_data;
  1617. for (i = offset; i < (NVM_CHECKSUM_REG + offset); i++) {
  1618. ret_val = hw->nvm.ops.read(hw, i, 1, &nvm_data);
  1619. if (ret_val) {
  1620. hw_dbg("NVM Read Error while updating checksum.\n");
  1621. goto out;
  1622. }
  1623. checksum += nvm_data;
  1624. }
  1625. checksum = (u16) NVM_SUM - checksum;
  1626. ret_val = hw->nvm.ops.write(hw, (NVM_CHECKSUM_REG + offset), 1,
  1627. &checksum);
  1628. if (ret_val)
  1629. hw_dbg("NVM Write Error while updating checksum.\n");
  1630. out:
  1631. return ret_val;
  1632. }
  1633. /**
  1634. * igb_validate_nvm_checksum_82580 - Validate EEPROM checksum
  1635. * @hw: pointer to the HW structure
  1636. *
  1637. * Calculates the EEPROM section checksum by reading/adding each word of
  1638. * the EEPROM and then verifies that the sum of the EEPROM is
  1639. * equal to 0xBABA.
  1640. **/
  1641. static s32 igb_validate_nvm_checksum_82580(struct e1000_hw *hw)
  1642. {
  1643. s32 ret_val = 0;
  1644. u16 eeprom_regions_count = 1;
  1645. u16 j, nvm_data;
  1646. u16 nvm_offset;
  1647. ret_val = hw->nvm.ops.read(hw, NVM_COMPATIBILITY_REG_3, 1, &nvm_data);
  1648. if (ret_val) {
  1649. hw_dbg("NVM Read Error\n");
  1650. goto out;
  1651. }
  1652. if (nvm_data & NVM_COMPATIBILITY_BIT_MASK) {
  1653. /* if checksums compatibility bit is set validate checksums
  1654. * for all 4 ports. */
  1655. eeprom_regions_count = 4;
  1656. }
  1657. for (j = 0; j < eeprom_regions_count; j++) {
  1658. nvm_offset = NVM_82580_LAN_FUNC_OFFSET(j);
  1659. ret_val = igb_validate_nvm_checksum_with_offset(hw,
  1660. nvm_offset);
  1661. if (ret_val != 0)
  1662. goto out;
  1663. }
  1664. out:
  1665. return ret_val;
  1666. }
  1667. /**
  1668. * igb_update_nvm_checksum_82580 - Update EEPROM checksum
  1669. * @hw: pointer to the HW structure
  1670. *
  1671. * Updates the EEPROM section checksums for all 4 ports by reading/adding
  1672. * each word of the EEPROM up to the checksum. Then calculates the EEPROM
  1673. * checksum and writes the value to the EEPROM.
  1674. **/
  1675. static s32 igb_update_nvm_checksum_82580(struct e1000_hw *hw)
  1676. {
  1677. s32 ret_val;
  1678. u16 j, nvm_data;
  1679. u16 nvm_offset;
  1680. ret_val = hw->nvm.ops.read(hw, NVM_COMPATIBILITY_REG_3, 1, &nvm_data);
  1681. if (ret_val) {
  1682. hw_dbg("NVM Read Error while updating checksum"
  1683. " compatibility bit.\n");
  1684. goto out;
  1685. }
  1686. if ((nvm_data & NVM_COMPATIBILITY_BIT_MASK) == 0) {
  1687. /* set compatibility bit to validate checksums appropriately */
  1688. nvm_data = nvm_data | NVM_COMPATIBILITY_BIT_MASK;
  1689. ret_val = hw->nvm.ops.write(hw, NVM_COMPATIBILITY_REG_3, 1,
  1690. &nvm_data);
  1691. if (ret_val) {
  1692. hw_dbg("NVM Write Error while updating checksum"
  1693. " compatibility bit.\n");
  1694. goto out;
  1695. }
  1696. }
  1697. for (j = 0; j < 4; j++) {
  1698. nvm_offset = NVM_82580_LAN_FUNC_OFFSET(j);
  1699. ret_val = igb_update_nvm_checksum_with_offset(hw, nvm_offset);
  1700. if (ret_val)
  1701. goto out;
  1702. }
  1703. out:
  1704. return ret_val;
  1705. }
  1706. /**
  1707. * igb_validate_nvm_checksum_i350 - Validate EEPROM checksum
  1708. * @hw: pointer to the HW structure
  1709. *
  1710. * Calculates the EEPROM section checksum by reading/adding each word of
  1711. * the EEPROM and then verifies that the sum of the EEPROM is
  1712. * equal to 0xBABA.
  1713. **/
  1714. static s32 igb_validate_nvm_checksum_i350(struct e1000_hw *hw)
  1715. {
  1716. s32 ret_val = 0;
  1717. u16 j;
  1718. u16 nvm_offset;
  1719. for (j = 0; j < 4; j++) {
  1720. nvm_offset = NVM_82580_LAN_FUNC_OFFSET(j);
  1721. ret_val = igb_validate_nvm_checksum_with_offset(hw,
  1722. nvm_offset);
  1723. if (ret_val != 0)
  1724. goto out;
  1725. }
  1726. out:
  1727. return ret_val;
  1728. }
  1729. /**
  1730. * igb_update_nvm_checksum_i350 - Update EEPROM checksum
  1731. * @hw: pointer to the HW structure
  1732. *
  1733. * Updates the EEPROM section checksums for all 4 ports by reading/adding
  1734. * each word of the EEPROM up to the checksum. Then calculates the EEPROM
  1735. * checksum and writes the value to the EEPROM.
  1736. **/
  1737. static s32 igb_update_nvm_checksum_i350(struct e1000_hw *hw)
  1738. {
  1739. s32 ret_val = 0;
  1740. u16 j;
  1741. u16 nvm_offset;
  1742. for (j = 0; j < 4; j++) {
  1743. nvm_offset = NVM_82580_LAN_FUNC_OFFSET(j);
  1744. ret_val = igb_update_nvm_checksum_with_offset(hw, nvm_offset);
  1745. if (ret_val != 0)
  1746. goto out;
  1747. }
  1748. out:
  1749. return ret_val;
  1750. }
  1751. /**
  1752. * igb_set_eee_i350 - Enable/disable EEE support
  1753. * @hw: pointer to the HW structure
  1754. *
  1755. * Enable/disable EEE based on setting in dev_spec structure.
  1756. *
  1757. **/
  1758. s32 igb_set_eee_i350(struct e1000_hw *hw)
  1759. {
  1760. s32 ret_val = 0;
  1761. u32 ipcnfg, eeer, ctrl_ext;
  1762. ctrl_ext = rd32(E1000_CTRL_EXT);
  1763. if ((hw->mac.type != e1000_i350) ||
  1764. (ctrl_ext & E1000_CTRL_EXT_LINK_MODE_MASK))
  1765. goto out;
  1766. ipcnfg = rd32(E1000_IPCNFG);
  1767. eeer = rd32(E1000_EEER);
  1768. /* enable or disable per user setting */
  1769. if (!(hw->dev_spec._82575.eee_disable)) {
  1770. ipcnfg |= (E1000_IPCNFG_EEE_1G_AN |
  1771. E1000_IPCNFG_EEE_100M_AN);
  1772. eeer |= (E1000_EEER_TX_LPI_EN |
  1773. E1000_EEER_RX_LPI_EN |
  1774. E1000_EEER_LPI_FC);
  1775. } else {
  1776. ipcnfg &= ~(E1000_IPCNFG_EEE_1G_AN |
  1777. E1000_IPCNFG_EEE_100M_AN);
  1778. eeer &= ~(E1000_EEER_TX_LPI_EN |
  1779. E1000_EEER_RX_LPI_EN |
  1780. E1000_EEER_LPI_FC);
  1781. }
  1782. wr32(E1000_IPCNFG, ipcnfg);
  1783. wr32(E1000_EEER, eeer);
  1784. out:
  1785. return ret_val;
  1786. }
  1787. static struct e1000_mac_operations e1000_mac_ops_82575 = {
  1788. .init_hw = igb_init_hw_82575,
  1789. .check_for_link = igb_check_for_link_82575,
  1790. .rar_set = igb_rar_set,
  1791. .read_mac_addr = igb_read_mac_addr_82575,
  1792. .get_speed_and_duplex = igb_get_speed_and_duplex_copper,
  1793. };
  1794. static struct e1000_phy_operations e1000_phy_ops_82575 = {
  1795. .acquire = igb_acquire_phy_82575,
  1796. .get_cfg_done = igb_get_cfg_done_82575,
  1797. .release = igb_release_phy_82575,
  1798. };
  1799. static struct e1000_nvm_operations e1000_nvm_ops_82575 = {
  1800. .acquire = igb_acquire_nvm_82575,
  1801. .read = igb_read_nvm_eerd,
  1802. .release = igb_release_nvm_82575,
  1803. .write = igb_write_nvm_spi,
  1804. };
  1805. const struct e1000_info e1000_82575_info = {
  1806. .get_invariants = igb_get_invariants_82575,
  1807. .mac_ops = &e1000_mac_ops_82575,
  1808. .phy_ops = &e1000_phy_ops_82575,
  1809. .nvm_ops = &e1000_nvm_ops_82575,
  1810. };