80003es2lan.c 37 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418
  1. /* Intel PRO/1000 Linux driver
  2. * Copyright(c) 1999 - 2015 Intel Corporation.
  3. *
  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. *
  8. * This program is distributed in the hope it will be useful, but WITHOUT
  9. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  10. * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
  11. * more details.
  12. *
  13. * The full GNU General Public License is included in this distribution in
  14. * the file called "COPYING".
  15. *
  16. * Contact Information:
  17. * Linux NICS <linux.nics@intel.com>
  18. * e1000-devel Mailing List <e1000-devel@lists.sourceforge.net>
  19. * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
  20. */
  21. /* 80003ES2LAN Gigabit Ethernet Controller (Copper)
  22. * 80003ES2LAN Gigabit Ethernet Controller (Serdes)
  23. */
  24. #include "e1000.h"
  25. /* A table for the GG82563 cable length where the range is defined
  26. * with a lower bound at "index" and the upper bound at
  27. * "index + 5".
  28. */
  29. static const u16 e1000_gg82563_cable_length_table[] = {
  30. 0, 60, 115, 150, 150, 60, 115, 150, 180, 180, 0xFF
  31. };
  32. #define GG82563_CABLE_LENGTH_TABLE_SIZE \
  33. ARRAY_SIZE(e1000_gg82563_cable_length_table)
  34. static s32 e1000_setup_copper_link_80003es2lan(struct e1000_hw *hw);
  35. static s32 e1000_acquire_swfw_sync_80003es2lan(struct e1000_hw *hw, u16 mask);
  36. static void e1000_release_swfw_sync_80003es2lan(struct e1000_hw *hw, u16 mask);
  37. static void e1000_initialize_hw_bits_80003es2lan(struct e1000_hw *hw);
  38. static void e1000_clear_hw_cntrs_80003es2lan(struct e1000_hw *hw);
  39. static s32 e1000_cfg_kmrn_1000_80003es2lan(struct e1000_hw *hw);
  40. static s32 e1000_cfg_kmrn_10_100_80003es2lan(struct e1000_hw *hw, u16 duplex);
  41. static s32 e1000_read_kmrn_reg_80003es2lan(struct e1000_hw *hw, u32 offset,
  42. u16 *data);
  43. static s32 e1000_write_kmrn_reg_80003es2lan(struct e1000_hw *hw, u32 offset,
  44. u16 data);
  45. static void e1000_power_down_phy_copper_80003es2lan(struct e1000_hw *hw);
  46. /**
  47. * e1000_init_phy_params_80003es2lan - Init ESB2 PHY func ptrs.
  48. * @hw: pointer to the HW structure
  49. **/
  50. static s32 e1000_init_phy_params_80003es2lan(struct e1000_hw *hw)
  51. {
  52. struct e1000_phy_info *phy = &hw->phy;
  53. s32 ret_val;
  54. if (hw->phy.media_type != e1000_media_type_copper) {
  55. phy->type = e1000_phy_none;
  56. return 0;
  57. } else {
  58. phy->ops.power_up = e1000_power_up_phy_copper;
  59. phy->ops.power_down = e1000_power_down_phy_copper_80003es2lan;
  60. }
  61. phy->addr = 1;
  62. phy->autoneg_mask = AUTONEG_ADVERTISE_SPEED_DEFAULT;
  63. phy->reset_delay_us = 100;
  64. phy->type = e1000_phy_gg82563;
  65. /* This can only be done after all function pointers are setup. */
  66. ret_val = e1000e_get_phy_id(hw);
  67. /* Verify phy id */
  68. if (phy->id != GG82563_E_PHY_ID)
  69. return -E1000_ERR_PHY;
  70. return ret_val;
  71. }
  72. /**
  73. * e1000_init_nvm_params_80003es2lan - Init ESB2 NVM func ptrs.
  74. * @hw: pointer to the HW structure
  75. **/
  76. static s32 e1000_init_nvm_params_80003es2lan(struct e1000_hw *hw)
  77. {
  78. struct e1000_nvm_info *nvm = &hw->nvm;
  79. u32 eecd = er32(EECD);
  80. u16 size;
  81. nvm->opcode_bits = 8;
  82. nvm->delay_usec = 1;
  83. switch (nvm->override) {
  84. case e1000_nvm_override_spi_large:
  85. nvm->page_size = 32;
  86. nvm->address_bits = 16;
  87. break;
  88. case e1000_nvm_override_spi_small:
  89. nvm->page_size = 8;
  90. nvm->address_bits = 8;
  91. break;
  92. default:
  93. nvm->page_size = eecd & E1000_EECD_ADDR_BITS ? 32 : 8;
  94. nvm->address_bits = eecd & E1000_EECD_ADDR_BITS ? 16 : 8;
  95. break;
  96. }
  97. nvm->type = e1000_nvm_eeprom_spi;
  98. size = (u16)((eecd & E1000_EECD_SIZE_EX_MASK) >>
  99. E1000_EECD_SIZE_EX_SHIFT);
  100. /* Added to a constant, "size" becomes the left-shift value
  101. * for setting word_size.
  102. */
  103. size += NVM_WORD_SIZE_BASE_SHIFT;
  104. /* EEPROM access above 16k is unsupported */
  105. if (size > 14)
  106. size = 14;
  107. nvm->word_size = 1 << size;
  108. return 0;
  109. }
  110. /**
  111. * e1000_init_mac_params_80003es2lan - Init ESB2 MAC func ptrs.
  112. * @hw: pointer to the HW structure
  113. **/
  114. static s32 e1000_init_mac_params_80003es2lan(struct e1000_hw *hw)
  115. {
  116. struct e1000_mac_info *mac = &hw->mac;
  117. /* Set media type and media-dependent function pointers */
  118. switch (hw->adapter->pdev->device) {
  119. case E1000_DEV_ID_80003ES2LAN_SERDES_DPT:
  120. hw->phy.media_type = e1000_media_type_internal_serdes;
  121. mac->ops.check_for_link = e1000e_check_for_serdes_link;
  122. mac->ops.setup_physical_interface =
  123. e1000e_setup_fiber_serdes_link;
  124. break;
  125. default:
  126. hw->phy.media_type = e1000_media_type_copper;
  127. mac->ops.check_for_link = e1000e_check_for_copper_link;
  128. mac->ops.setup_physical_interface =
  129. e1000_setup_copper_link_80003es2lan;
  130. break;
  131. }
  132. /* Set mta register count */
  133. mac->mta_reg_count = 128;
  134. /* Set rar entry count */
  135. mac->rar_entry_count = E1000_RAR_ENTRIES;
  136. /* FWSM register */
  137. mac->has_fwsm = true;
  138. /* ARC supported; valid only if manageability features are enabled. */
  139. mac->arc_subsystem_valid = !!(er32(FWSM) & E1000_FWSM_MODE_MASK);
  140. /* Adaptive IFS not supported */
  141. mac->adaptive_ifs = false;
  142. /* set lan id for port to determine which phy lock to use */
  143. hw->mac.ops.set_lan_id(hw);
  144. return 0;
  145. }
  146. static s32 e1000_get_variants_80003es2lan(struct e1000_adapter *adapter)
  147. {
  148. struct e1000_hw *hw = &adapter->hw;
  149. s32 rc;
  150. rc = e1000_init_mac_params_80003es2lan(hw);
  151. if (rc)
  152. return rc;
  153. rc = e1000_init_nvm_params_80003es2lan(hw);
  154. if (rc)
  155. return rc;
  156. rc = e1000_init_phy_params_80003es2lan(hw);
  157. if (rc)
  158. return rc;
  159. return 0;
  160. }
  161. /**
  162. * e1000_acquire_phy_80003es2lan - Acquire rights to access PHY
  163. * @hw: pointer to the HW structure
  164. *
  165. * A wrapper to acquire access rights to the correct PHY.
  166. **/
  167. static s32 e1000_acquire_phy_80003es2lan(struct e1000_hw *hw)
  168. {
  169. u16 mask;
  170. mask = hw->bus.func ? E1000_SWFW_PHY1_SM : E1000_SWFW_PHY0_SM;
  171. return e1000_acquire_swfw_sync_80003es2lan(hw, mask);
  172. }
  173. /**
  174. * e1000_release_phy_80003es2lan - Release rights to access PHY
  175. * @hw: pointer to the HW structure
  176. *
  177. * A wrapper to release access rights to the correct PHY.
  178. **/
  179. static void e1000_release_phy_80003es2lan(struct e1000_hw *hw)
  180. {
  181. u16 mask;
  182. mask = hw->bus.func ? E1000_SWFW_PHY1_SM : E1000_SWFW_PHY0_SM;
  183. e1000_release_swfw_sync_80003es2lan(hw, mask);
  184. }
  185. /**
  186. * e1000_acquire_mac_csr_80003es2lan - Acquire right to access Kumeran register
  187. * @hw: pointer to the HW structure
  188. *
  189. * Acquire the semaphore to access the Kumeran interface.
  190. *
  191. **/
  192. static s32 e1000_acquire_mac_csr_80003es2lan(struct e1000_hw *hw)
  193. {
  194. u16 mask;
  195. mask = E1000_SWFW_CSR_SM;
  196. return e1000_acquire_swfw_sync_80003es2lan(hw, mask);
  197. }
  198. /**
  199. * e1000_release_mac_csr_80003es2lan - Release right to access Kumeran Register
  200. * @hw: pointer to the HW structure
  201. *
  202. * Release the semaphore used to access the Kumeran interface
  203. **/
  204. static void e1000_release_mac_csr_80003es2lan(struct e1000_hw *hw)
  205. {
  206. u16 mask;
  207. mask = E1000_SWFW_CSR_SM;
  208. e1000_release_swfw_sync_80003es2lan(hw, mask);
  209. }
  210. /**
  211. * e1000_acquire_nvm_80003es2lan - Acquire rights to access NVM
  212. * @hw: pointer to the HW structure
  213. *
  214. * Acquire the semaphore to access the EEPROM.
  215. **/
  216. static s32 e1000_acquire_nvm_80003es2lan(struct e1000_hw *hw)
  217. {
  218. s32 ret_val;
  219. ret_val = e1000_acquire_swfw_sync_80003es2lan(hw, E1000_SWFW_EEP_SM);
  220. if (ret_val)
  221. return ret_val;
  222. ret_val = e1000e_acquire_nvm(hw);
  223. if (ret_val)
  224. e1000_release_swfw_sync_80003es2lan(hw, E1000_SWFW_EEP_SM);
  225. return ret_val;
  226. }
  227. /**
  228. * e1000_release_nvm_80003es2lan - Relinquish rights to access NVM
  229. * @hw: pointer to the HW structure
  230. *
  231. * Release the semaphore used to access the EEPROM.
  232. **/
  233. static void e1000_release_nvm_80003es2lan(struct e1000_hw *hw)
  234. {
  235. e1000e_release_nvm(hw);
  236. e1000_release_swfw_sync_80003es2lan(hw, E1000_SWFW_EEP_SM);
  237. }
  238. /**
  239. * e1000_acquire_swfw_sync_80003es2lan - Acquire SW/FW semaphore
  240. * @hw: pointer to the HW structure
  241. * @mask: specifies which semaphore to acquire
  242. *
  243. * Acquire the SW/FW semaphore to access the PHY or NVM. The mask
  244. * will also specify which port we're acquiring the lock for.
  245. **/
  246. static s32 e1000_acquire_swfw_sync_80003es2lan(struct e1000_hw *hw, u16 mask)
  247. {
  248. u32 swfw_sync;
  249. u32 swmask = mask;
  250. u32 fwmask = mask << 16;
  251. s32 i = 0;
  252. s32 timeout = 50;
  253. while (i < timeout) {
  254. if (e1000e_get_hw_semaphore(hw))
  255. return -E1000_ERR_SWFW_SYNC;
  256. swfw_sync = er32(SW_FW_SYNC);
  257. if (!(swfw_sync & (fwmask | swmask)))
  258. break;
  259. /* Firmware currently using resource (fwmask)
  260. * or other software thread using resource (swmask)
  261. */
  262. e1000e_put_hw_semaphore(hw);
  263. mdelay(5);
  264. i++;
  265. }
  266. if (i == timeout) {
  267. e_dbg("Driver can't access resource, SW_FW_SYNC timeout.\n");
  268. return -E1000_ERR_SWFW_SYNC;
  269. }
  270. swfw_sync |= swmask;
  271. ew32(SW_FW_SYNC, swfw_sync);
  272. e1000e_put_hw_semaphore(hw);
  273. return 0;
  274. }
  275. /**
  276. * e1000_release_swfw_sync_80003es2lan - Release SW/FW semaphore
  277. * @hw: pointer to the HW structure
  278. * @mask: specifies which semaphore to acquire
  279. *
  280. * Release the SW/FW semaphore used to access the PHY or NVM. The mask
  281. * will also specify which port we're releasing the lock for.
  282. **/
  283. static void e1000_release_swfw_sync_80003es2lan(struct e1000_hw *hw, u16 mask)
  284. {
  285. u32 swfw_sync;
  286. while (e1000e_get_hw_semaphore(hw) != 0)
  287. ; /* Empty */
  288. swfw_sync = er32(SW_FW_SYNC);
  289. swfw_sync &= ~mask;
  290. ew32(SW_FW_SYNC, swfw_sync);
  291. e1000e_put_hw_semaphore(hw);
  292. }
  293. /**
  294. * e1000_read_phy_reg_gg82563_80003es2lan - Read GG82563 PHY register
  295. * @hw: pointer to the HW structure
  296. * @offset: offset of the register to read
  297. * @data: pointer to the data returned from the operation
  298. *
  299. * Read the GG82563 PHY register.
  300. **/
  301. static s32 e1000_read_phy_reg_gg82563_80003es2lan(struct e1000_hw *hw,
  302. u32 offset, u16 *data)
  303. {
  304. s32 ret_val;
  305. u32 page_select;
  306. u16 temp;
  307. ret_val = e1000_acquire_phy_80003es2lan(hw);
  308. if (ret_val)
  309. return ret_val;
  310. /* Select Configuration Page */
  311. if ((offset & MAX_PHY_REG_ADDRESS) < GG82563_MIN_ALT_REG) {
  312. page_select = GG82563_PHY_PAGE_SELECT;
  313. } else {
  314. /* Use Alternative Page Select register to access
  315. * registers 30 and 31
  316. */
  317. page_select = GG82563_PHY_PAGE_SELECT_ALT;
  318. }
  319. temp = (u16)((u16)offset >> GG82563_PAGE_SHIFT);
  320. ret_val = e1000e_write_phy_reg_mdic(hw, page_select, temp);
  321. if (ret_val) {
  322. e1000_release_phy_80003es2lan(hw);
  323. return ret_val;
  324. }
  325. if (hw->dev_spec.e80003es2lan.mdic_wa_enable) {
  326. /* The "ready" bit in the MDIC register may be incorrectly set
  327. * before the device has completed the "Page Select" MDI
  328. * transaction. So we wait 200us after each MDI command...
  329. */
  330. usleep_range(200, 400);
  331. /* ...and verify the command was successful. */
  332. ret_val = e1000e_read_phy_reg_mdic(hw, page_select, &temp);
  333. if (((u16)offset >> GG82563_PAGE_SHIFT) != temp) {
  334. e1000_release_phy_80003es2lan(hw);
  335. return -E1000_ERR_PHY;
  336. }
  337. usleep_range(200, 400);
  338. ret_val = e1000e_read_phy_reg_mdic(hw,
  339. MAX_PHY_REG_ADDRESS & offset,
  340. data);
  341. usleep_range(200, 400);
  342. } else {
  343. ret_val = e1000e_read_phy_reg_mdic(hw,
  344. MAX_PHY_REG_ADDRESS & offset,
  345. data);
  346. }
  347. e1000_release_phy_80003es2lan(hw);
  348. return ret_val;
  349. }
  350. /**
  351. * e1000_write_phy_reg_gg82563_80003es2lan - Write GG82563 PHY register
  352. * @hw: pointer to the HW structure
  353. * @offset: offset of the register to read
  354. * @data: value to write to the register
  355. *
  356. * Write to the GG82563 PHY register.
  357. **/
  358. static s32 e1000_write_phy_reg_gg82563_80003es2lan(struct e1000_hw *hw,
  359. u32 offset, u16 data)
  360. {
  361. s32 ret_val;
  362. u32 page_select;
  363. u16 temp;
  364. ret_val = e1000_acquire_phy_80003es2lan(hw);
  365. if (ret_val)
  366. return ret_val;
  367. /* Select Configuration Page */
  368. if ((offset & MAX_PHY_REG_ADDRESS) < GG82563_MIN_ALT_REG) {
  369. page_select = GG82563_PHY_PAGE_SELECT;
  370. } else {
  371. /* Use Alternative Page Select register to access
  372. * registers 30 and 31
  373. */
  374. page_select = GG82563_PHY_PAGE_SELECT_ALT;
  375. }
  376. temp = (u16)((u16)offset >> GG82563_PAGE_SHIFT);
  377. ret_val = e1000e_write_phy_reg_mdic(hw, page_select, temp);
  378. if (ret_val) {
  379. e1000_release_phy_80003es2lan(hw);
  380. return ret_val;
  381. }
  382. if (hw->dev_spec.e80003es2lan.mdic_wa_enable) {
  383. /* The "ready" bit in the MDIC register may be incorrectly set
  384. * before the device has completed the "Page Select" MDI
  385. * transaction. So we wait 200us after each MDI command...
  386. */
  387. usleep_range(200, 400);
  388. /* ...and verify the command was successful. */
  389. ret_val = e1000e_read_phy_reg_mdic(hw, page_select, &temp);
  390. if (((u16)offset >> GG82563_PAGE_SHIFT) != temp) {
  391. e1000_release_phy_80003es2lan(hw);
  392. return -E1000_ERR_PHY;
  393. }
  394. usleep_range(200, 400);
  395. ret_val = e1000e_write_phy_reg_mdic(hw,
  396. MAX_PHY_REG_ADDRESS &
  397. offset, data);
  398. usleep_range(200, 400);
  399. } else {
  400. ret_val = e1000e_write_phy_reg_mdic(hw,
  401. MAX_PHY_REG_ADDRESS &
  402. offset, data);
  403. }
  404. e1000_release_phy_80003es2lan(hw);
  405. return ret_val;
  406. }
  407. /**
  408. * e1000_write_nvm_80003es2lan - Write to ESB2 NVM
  409. * @hw: pointer to the HW structure
  410. * @offset: offset of the register to read
  411. * @words: number of words to write
  412. * @data: buffer of data to write to the NVM
  413. *
  414. * Write "words" of data to the ESB2 NVM.
  415. **/
  416. static s32 e1000_write_nvm_80003es2lan(struct e1000_hw *hw, u16 offset,
  417. u16 words, u16 *data)
  418. {
  419. return e1000e_write_nvm_spi(hw, offset, words, data);
  420. }
  421. /**
  422. * e1000_get_cfg_done_80003es2lan - Wait for configuration to complete
  423. * @hw: pointer to the HW structure
  424. *
  425. * Wait a specific amount of time for manageability processes to complete.
  426. * This is a function pointer entry point called by the phy module.
  427. **/
  428. static s32 e1000_get_cfg_done_80003es2lan(struct e1000_hw *hw)
  429. {
  430. s32 timeout = PHY_CFG_TIMEOUT;
  431. u32 mask = E1000_NVM_CFG_DONE_PORT_0;
  432. if (hw->bus.func == 1)
  433. mask = E1000_NVM_CFG_DONE_PORT_1;
  434. while (timeout) {
  435. if (er32(EEMNGCTL) & mask)
  436. break;
  437. usleep_range(1000, 2000);
  438. timeout--;
  439. }
  440. if (!timeout) {
  441. e_dbg("MNG configuration cycle has not completed.\n");
  442. return -E1000_ERR_RESET;
  443. }
  444. return 0;
  445. }
  446. /**
  447. * e1000_phy_force_speed_duplex_80003es2lan - Force PHY speed and duplex
  448. * @hw: pointer to the HW structure
  449. *
  450. * Force the speed and duplex settings onto the PHY. This is a
  451. * function pointer entry point called by the phy module.
  452. **/
  453. static s32 e1000_phy_force_speed_duplex_80003es2lan(struct e1000_hw *hw)
  454. {
  455. s32 ret_val;
  456. u16 phy_data;
  457. bool link;
  458. /* Clear Auto-Crossover to force MDI manually. M88E1000 requires MDI
  459. * forced whenever speed and duplex are forced.
  460. */
  461. ret_val = e1e_rphy(hw, M88E1000_PHY_SPEC_CTRL, &phy_data);
  462. if (ret_val)
  463. return ret_val;
  464. phy_data &= ~GG82563_PSCR_CROSSOVER_MODE_AUTO;
  465. ret_val = e1e_wphy(hw, GG82563_PHY_SPEC_CTRL, phy_data);
  466. if (ret_val)
  467. return ret_val;
  468. e_dbg("GG82563 PSCR: %X\n", phy_data);
  469. ret_val = e1e_rphy(hw, MII_BMCR, &phy_data);
  470. if (ret_val)
  471. return ret_val;
  472. e1000e_phy_force_speed_duplex_setup(hw, &phy_data);
  473. /* Reset the phy to commit changes. */
  474. phy_data |= BMCR_RESET;
  475. ret_val = e1e_wphy(hw, MII_BMCR, phy_data);
  476. if (ret_val)
  477. return ret_val;
  478. udelay(1);
  479. if (hw->phy.autoneg_wait_to_complete) {
  480. e_dbg("Waiting for forced speed/duplex link on GG82563 phy.\n");
  481. ret_val = e1000e_phy_has_link_generic(hw, PHY_FORCE_LIMIT,
  482. 100000, &link);
  483. if (ret_val)
  484. return ret_val;
  485. if (!link) {
  486. /* We didn't get link.
  487. * Reset the DSP and cross our fingers.
  488. */
  489. ret_val = e1000e_phy_reset_dsp(hw);
  490. if (ret_val)
  491. return ret_val;
  492. }
  493. /* Try once more */
  494. ret_val = e1000e_phy_has_link_generic(hw, PHY_FORCE_LIMIT,
  495. 100000, &link);
  496. if (ret_val)
  497. return ret_val;
  498. }
  499. ret_val = e1e_rphy(hw, GG82563_PHY_MAC_SPEC_CTRL, &phy_data);
  500. if (ret_val)
  501. return ret_val;
  502. /* Resetting the phy means we need to verify the TX_CLK corresponds
  503. * to the link speed. 10Mbps -> 2.5MHz, else 25MHz.
  504. */
  505. phy_data &= ~GG82563_MSCR_TX_CLK_MASK;
  506. if (hw->mac.forced_speed_duplex & E1000_ALL_10_SPEED)
  507. phy_data |= GG82563_MSCR_TX_CLK_10MBPS_2_5;
  508. else
  509. phy_data |= GG82563_MSCR_TX_CLK_100MBPS_25;
  510. /* In addition, we must re-enable CRS on Tx for both half and full
  511. * duplex.
  512. */
  513. phy_data |= GG82563_MSCR_ASSERT_CRS_ON_TX;
  514. ret_val = e1e_wphy(hw, GG82563_PHY_MAC_SPEC_CTRL, phy_data);
  515. return ret_val;
  516. }
  517. /**
  518. * e1000_get_cable_length_80003es2lan - Set approximate cable length
  519. * @hw: pointer to the HW structure
  520. *
  521. * Find the approximate cable length as measured by the GG82563 PHY.
  522. * This is a function pointer entry point called by the phy module.
  523. **/
  524. static s32 e1000_get_cable_length_80003es2lan(struct e1000_hw *hw)
  525. {
  526. struct e1000_phy_info *phy = &hw->phy;
  527. s32 ret_val;
  528. u16 phy_data, index;
  529. ret_val = e1e_rphy(hw, GG82563_PHY_DSP_DISTANCE, &phy_data);
  530. if (ret_val)
  531. return ret_val;
  532. index = phy_data & GG82563_DSPD_CABLE_LENGTH;
  533. if (index >= GG82563_CABLE_LENGTH_TABLE_SIZE - 5)
  534. return -E1000_ERR_PHY;
  535. phy->min_cable_length = e1000_gg82563_cable_length_table[index];
  536. phy->max_cable_length = e1000_gg82563_cable_length_table[index + 5];
  537. phy->cable_length = (phy->min_cable_length + phy->max_cable_length) / 2;
  538. return 0;
  539. }
  540. /**
  541. * e1000_get_link_up_info_80003es2lan - Report speed and duplex
  542. * @hw: pointer to the HW structure
  543. * @speed: pointer to speed buffer
  544. * @duplex: pointer to duplex buffer
  545. *
  546. * Retrieve the current speed and duplex configuration.
  547. **/
  548. static s32 e1000_get_link_up_info_80003es2lan(struct e1000_hw *hw, u16 *speed,
  549. u16 *duplex)
  550. {
  551. s32 ret_val;
  552. if (hw->phy.media_type == e1000_media_type_copper) {
  553. ret_val = e1000e_get_speed_and_duplex_copper(hw, speed, duplex);
  554. hw->phy.ops.cfg_on_link_up(hw);
  555. } else {
  556. ret_val = e1000e_get_speed_and_duplex_fiber_serdes(hw,
  557. speed,
  558. duplex);
  559. }
  560. return ret_val;
  561. }
  562. /**
  563. * e1000_reset_hw_80003es2lan - Reset the ESB2 controller
  564. * @hw: pointer to the HW structure
  565. *
  566. * Perform a global reset to the ESB2 controller.
  567. **/
  568. static s32 e1000_reset_hw_80003es2lan(struct e1000_hw *hw)
  569. {
  570. u32 ctrl;
  571. s32 ret_val;
  572. u16 kum_reg_data;
  573. /* Prevent the PCI-E bus from sticking if there is no TLP connection
  574. * on the last TLP read/write transaction when MAC is reset.
  575. */
  576. ret_val = e1000e_disable_pcie_master(hw);
  577. if (ret_val)
  578. e_dbg("PCI-E Master disable polling has failed.\n");
  579. e_dbg("Masking off all interrupts\n");
  580. ew32(IMC, 0xffffffff);
  581. ew32(RCTL, 0);
  582. ew32(TCTL, E1000_TCTL_PSP);
  583. e1e_flush();
  584. usleep_range(10000, 20000);
  585. ctrl = er32(CTRL);
  586. ret_val = e1000_acquire_phy_80003es2lan(hw);
  587. if (ret_val)
  588. return ret_val;
  589. e_dbg("Issuing a global reset to MAC\n");
  590. ew32(CTRL, ctrl | E1000_CTRL_RST);
  591. e1000_release_phy_80003es2lan(hw);
  592. /* Disable IBIST slave mode (far-end loopback) */
  593. ret_val =
  594. e1000_read_kmrn_reg_80003es2lan(hw, E1000_KMRNCTRLSTA_INBAND_PARAM,
  595. &kum_reg_data);
  596. if (ret_val)
  597. return ret_val;
  598. kum_reg_data |= E1000_KMRNCTRLSTA_IBIST_DISABLE;
  599. e1000_write_kmrn_reg_80003es2lan(hw, E1000_KMRNCTRLSTA_INBAND_PARAM,
  600. kum_reg_data);
  601. ret_val = e1000e_get_auto_rd_done(hw);
  602. if (ret_val)
  603. /* We don't want to continue accessing MAC registers. */
  604. return ret_val;
  605. /* Clear any pending interrupt events. */
  606. ew32(IMC, 0xffffffff);
  607. er32(ICR);
  608. return e1000_check_alt_mac_addr_generic(hw);
  609. }
  610. /**
  611. * e1000_init_hw_80003es2lan - Initialize the ESB2 controller
  612. * @hw: pointer to the HW structure
  613. *
  614. * Initialize the hw bits, LED, VFTA, MTA, link and hw counters.
  615. **/
  616. static s32 e1000_init_hw_80003es2lan(struct e1000_hw *hw)
  617. {
  618. struct e1000_mac_info *mac = &hw->mac;
  619. u32 reg_data;
  620. s32 ret_val;
  621. u16 kum_reg_data;
  622. u16 i;
  623. e1000_initialize_hw_bits_80003es2lan(hw);
  624. /* Initialize identification LED */
  625. ret_val = mac->ops.id_led_init(hw);
  626. /* An error is not fatal and we should not stop init due to this */
  627. if (ret_val)
  628. e_dbg("Error initializing identification LED\n");
  629. /* Disabling VLAN filtering */
  630. e_dbg("Initializing the IEEE VLAN\n");
  631. mac->ops.clear_vfta(hw);
  632. /* Setup the receive address. */
  633. e1000e_init_rx_addrs(hw, mac->rar_entry_count);
  634. /* Zero out the Multicast HASH table */
  635. e_dbg("Zeroing the MTA\n");
  636. for (i = 0; i < mac->mta_reg_count; i++)
  637. E1000_WRITE_REG_ARRAY(hw, E1000_MTA, i, 0);
  638. /* Setup link and flow control */
  639. ret_val = mac->ops.setup_link(hw);
  640. if (ret_val)
  641. return ret_val;
  642. /* Disable IBIST slave mode (far-end loopback) */
  643. e1000_read_kmrn_reg_80003es2lan(hw, E1000_KMRNCTRLSTA_INBAND_PARAM,
  644. &kum_reg_data);
  645. kum_reg_data |= E1000_KMRNCTRLSTA_IBIST_DISABLE;
  646. e1000_write_kmrn_reg_80003es2lan(hw, E1000_KMRNCTRLSTA_INBAND_PARAM,
  647. kum_reg_data);
  648. /* Set the transmit descriptor write-back policy */
  649. reg_data = er32(TXDCTL(0));
  650. reg_data = ((reg_data & ~E1000_TXDCTL_WTHRESH) |
  651. E1000_TXDCTL_FULL_TX_DESC_WB | E1000_TXDCTL_COUNT_DESC);
  652. ew32(TXDCTL(0), reg_data);
  653. /* ...for both queues. */
  654. reg_data = er32(TXDCTL(1));
  655. reg_data = ((reg_data & ~E1000_TXDCTL_WTHRESH) |
  656. E1000_TXDCTL_FULL_TX_DESC_WB | E1000_TXDCTL_COUNT_DESC);
  657. ew32(TXDCTL(1), reg_data);
  658. /* Enable retransmit on late collisions */
  659. reg_data = er32(TCTL);
  660. reg_data |= E1000_TCTL_RTLC;
  661. ew32(TCTL, reg_data);
  662. /* Configure Gigabit Carry Extend Padding */
  663. reg_data = er32(TCTL_EXT);
  664. reg_data &= ~E1000_TCTL_EXT_GCEX_MASK;
  665. reg_data |= DEFAULT_TCTL_EXT_GCEX_80003ES2LAN;
  666. ew32(TCTL_EXT, reg_data);
  667. /* Configure Transmit Inter-Packet Gap */
  668. reg_data = er32(TIPG);
  669. reg_data &= ~E1000_TIPG_IPGT_MASK;
  670. reg_data |= DEFAULT_TIPG_IPGT_1000_80003ES2LAN;
  671. ew32(TIPG, reg_data);
  672. reg_data = E1000_READ_REG_ARRAY(hw, E1000_FFLT, 0x0001);
  673. reg_data &= ~0x00100000;
  674. E1000_WRITE_REG_ARRAY(hw, E1000_FFLT, 0x0001, reg_data);
  675. /* default to true to enable the MDIC W/A */
  676. hw->dev_spec.e80003es2lan.mdic_wa_enable = true;
  677. ret_val =
  678. e1000_read_kmrn_reg_80003es2lan(hw, E1000_KMRNCTRLSTA_OFFSET >>
  679. E1000_KMRNCTRLSTA_OFFSET_SHIFT, &i);
  680. if (!ret_val) {
  681. if ((i & E1000_KMRNCTRLSTA_OPMODE_MASK) ==
  682. E1000_KMRNCTRLSTA_OPMODE_INBAND_MDIO)
  683. hw->dev_spec.e80003es2lan.mdic_wa_enable = false;
  684. }
  685. /* Clear all of the statistics registers (clear on read). It is
  686. * important that we do this after we have tried to establish link
  687. * because the symbol error count will increment wildly if there
  688. * is no link.
  689. */
  690. e1000_clear_hw_cntrs_80003es2lan(hw);
  691. return ret_val;
  692. }
  693. /**
  694. * e1000_initialize_hw_bits_80003es2lan - Init hw bits of ESB2
  695. * @hw: pointer to the HW structure
  696. *
  697. * Initializes required hardware-dependent bits needed for normal operation.
  698. **/
  699. static void e1000_initialize_hw_bits_80003es2lan(struct e1000_hw *hw)
  700. {
  701. u32 reg;
  702. /* Transmit Descriptor Control 0 */
  703. reg = er32(TXDCTL(0));
  704. reg |= (1 << 22);
  705. ew32(TXDCTL(0), reg);
  706. /* Transmit Descriptor Control 1 */
  707. reg = er32(TXDCTL(1));
  708. reg |= (1 << 22);
  709. ew32(TXDCTL(1), reg);
  710. /* Transmit Arbitration Control 0 */
  711. reg = er32(TARC(0));
  712. reg &= ~(0xF << 27); /* 30:27 */
  713. if (hw->phy.media_type != e1000_media_type_copper)
  714. reg &= ~(1 << 20);
  715. ew32(TARC(0), reg);
  716. /* Transmit Arbitration Control 1 */
  717. reg = er32(TARC(1));
  718. if (er32(TCTL) & E1000_TCTL_MULR)
  719. reg &= ~(1 << 28);
  720. else
  721. reg |= (1 << 28);
  722. ew32(TARC(1), reg);
  723. /* Disable IPv6 extension header parsing because some malformed
  724. * IPv6 headers can hang the Rx.
  725. */
  726. reg = er32(RFCTL);
  727. reg |= (E1000_RFCTL_IPV6_EX_DIS | E1000_RFCTL_NEW_IPV6_EXT_DIS);
  728. ew32(RFCTL, reg);
  729. }
  730. /**
  731. * e1000_copper_link_setup_gg82563_80003es2lan - Configure GG82563 Link
  732. * @hw: pointer to the HW structure
  733. *
  734. * Setup some GG82563 PHY registers for obtaining link
  735. **/
  736. static s32 e1000_copper_link_setup_gg82563_80003es2lan(struct e1000_hw *hw)
  737. {
  738. struct e1000_phy_info *phy = &hw->phy;
  739. s32 ret_val;
  740. u32 reg;
  741. u16 data;
  742. ret_val = e1e_rphy(hw, GG82563_PHY_MAC_SPEC_CTRL, &data);
  743. if (ret_val)
  744. return ret_val;
  745. data |= GG82563_MSCR_ASSERT_CRS_ON_TX;
  746. /* Use 25MHz for both link down and 1000Base-T for Tx clock. */
  747. data |= GG82563_MSCR_TX_CLK_1000MBPS_25;
  748. ret_val = e1e_wphy(hw, GG82563_PHY_MAC_SPEC_CTRL, data);
  749. if (ret_val)
  750. return ret_val;
  751. /* Options:
  752. * MDI/MDI-X = 0 (default)
  753. * 0 - Auto for all speeds
  754. * 1 - MDI mode
  755. * 2 - MDI-X mode
  756. * 3 - Auto for 1000Base-T only (MDI-X for 10/100Base-T modes)
  757. */
  758. ret_val = e1e_rphy(hw, GG82563_PHY_SPEC_CTRL, &data);
  759. if (ret_val)
  760. return ret_val;
  761. data &= ~GG82563_PSCR_CROSSOVER_MODE_MASK;
  762. switch (phy->mdix) {
  763. case 1:
  764. data |= GG82563_PSCR_CROSSOVER_MODE_MDI;
  765. break;
  766. case 2:
  767. data |= GG82563_PSCR_CROSSOVER_MODE_MDIX;
  768. break;
  769. case 0:
  770. default:
  771. data |= GG82563_PSCR_CROSSOVER_MODE_AUTO;
  772. break;
  773. }
  774. /* Options:
  775. * disable_polarity_correction = 0 (default)
  776. * Automatic Correction for Reversed Cable Polarity
  777. * 0 - Disabled
  778. * 1 - Enabled
  779. */
  780. data &= ~GG82563_PSCR_POLARITY_REVERSAL_DISABLE;
  781. if (phy->disable_polarity_correction)
  782. data |= GG82563_PSCR_POLARITY_REVERSAL_DISABLE;
  783. ret_val = e1e_wphy(hw, GG82563_PHY_SPEC_CTRL, data);
  784. if (ret_val)
  785. return ret_val;
  786. /* SW Reset the PHY so all changes take effect */
  787. ret_val = hw->phy.ops.commit(hw);
  788. if (ret_val) {
  789. e_dbg("Error Resetting the PHY\n");
  790. return ret_val;
  791. }
  792. /* Bypass Rx and Tx FIFO's */
  793. reg = E1000_KMRNCTRLSTA_OFFSET_FIFO_CTRL;
  794. data = (E1000_KMRNCTRLSTA_FIFO_CTRL_RX_BYPASS |
  795. E1000_KMRNCTRLSTA_FIFO_CTRL_TX_BYPASS);
  796. ret_val = e1000_write_kmrn_reg_80003es2lan(hw, reg, data);
  797. if (ret_val)
  798. return ret_val;
  799. reg = E1000_KMRNCTRLSTA_OFFSET_MAC2PHY_OPMODE;
  800. ret_val = e1000_read_kmrn_reg_80003es2lan(hw, reg, &data);
  801. if (ret_val)
  802. return ret_val;
  803. data |= E1000_KMRNCTRLSTA_OPMODE_E_IDLE;
  804. ret_val = e1000_write_kmrn_reg_80003es2lan(hw, reg, data);
  805. if (ret_val)
  806. return ret_val;
  807. ret_val = e1e_rphy(hw, GG82563_PHY_SPEC_CTRL_2, &data);
  808. if (ret_val)
  809. return ret_val;
  810. data &= ~GG82563_PSCR2_REVERSE_AUTO_NEG;
  811. ret_val = e1e_wphy(hw, GG82563_PHY_SPEC_CTRL_2, data);
  812. if (ret_val)
  813. return ret_val;
  814. reg = er32(CTRL_EXT);
  815. reg &= ~E1000_CTRL_EXT_LINK_MODE_MASK;
  816. ew32(CTRL_EXT, reg);
  817. ret_val = e1e_rphy(hw, GG82563_PHY_PWR_MGMT_CTRL, &data);
  818. if (ret_val)
  819. return ret_val;
  820. /* Do not init these registers when the HW is in IAMT mode, since the
  821. * firmware will have already initialized them. We only initialize
  822. * them if the HW is not in IAMT mode.
  823. */
  824. if (!hw->mac.ops.check_mng_mode(hw)) {
  825. /* Enable Electrical Idle on the PHY */
  826. data |= GG82563_PMCR_ENABLE_ELECTRICAL_IDLE;
  827. ret_val = e1e_wphy(hw, GG82563_PHY_PWR_MGMT_CTRL, data);
  828. if (ret_val)
  829. return ret_val;
  830. ret_val = e1e_rphy(hw, GG82563_PHY_KMRN_MODE_CTRL, &data);
  831. if (ret_val)
  832. return ret_val;
  833. data &= ~GG82563_KMCR_PASS_FALSE_CARRIER;
  834. ret_val = e1e_wphy(hw, GG82563_PHY_KMRN_MODE_CTRL, data);
  835. if (ret_val)
  836. return ret_val;
  837. }
  838. /* Workaround: Disable padding in Kumeran interface in the MAC
  839. * and in the PHY to avoid CRC errors.
  840. */
  841. ret_val = e1e_rphy(hw, GG82563_PHY_INBAND_CTRL, &data);
  842. if (ret_val)
  843. return ret_val;
  844. data |= GG82563_ICR_DIS_PADDING;
  845. ret_val = e1e_wphy(hw, GG82563_PHY_INBAND_CTRL, data);
  846. if (ret_val)
  847. return ret_val;
  848. return 0;
  849. }
  850. /**
  851. * e1000_setup_copper_link_80003es2lan - Setup Copper Link for ESB2
  852. * @hw: pointer to the HW structure
  853. *
  854. * Essentially a wrapper for setting up all things "copper" related.
  855. * This is a function pointer entry point called by the mac module.
  856. **/
  857. static s32 e1000_setup_copper_link_80003es2lan(struct e1000_hw *hw)
  858. {
  859. u32 ctrl;
  860. s32 ret_val;
  861. u16 reg_data;
  862. ctrl = er32(CTRL);
  863. ctrl |= E1000_CTRL_SLU;
  864. ctrl &= ~(E1000_CTRL_FRCSPD | E1000_CTRL_FRCDPX);
  865. ew32(CTRL, ctrl);
  866. /* Set the mac to wait the maximum time between each
  867. * iteration and increase the max iterations when
  868. * polling the phy; this fixes erroneous timeouts at 10Mbps.
  869. */
  870. ret_val = e1000_write_kmrn_reg_80003es2lan(hw, GG82563_REG(0x34, 4),
  871. 0xFFFF);
  872. if (ret_val)
  873. return ret_val;
  874. ret_val = e1000_read_kmrn_reg_80003es2lan(hw, GG82563_REG(0x34, 9),
  875. &reg_data);
  876. if (ret_val)
  877. return ret_val;
  878. reg_data |= 0x3F;
  879. ret_val = e1000_write_kmrn_reg_80003es2lan(hw, GG82563_REG(0x34, 9),
  880. reg_data);
  881. if (ret_val)
  882. return ret_val;
  883. ret_val =
  884. e1000_read_kmrn_reg_80003es2lan(hw,
  885. E1000_KMRNCTRLSTA_OFFSET_INB_CTRL,
  886. &reg_data);
  887. if (ret_val)
  888. return ret_val;
  889. reg_data |= E1000_KMRNCTRLSTA_INB_CTRL_DIS_PADDING;
  890. ret_val =
  891. e1000_write_kmrn_reg_80003es2lan(hw,
  892. E1000_KMRNCTRLSTA_OFFSET_INB_CTRL,
  893. reg_data);
  894. if (ret_val)
  895. return ret_val;
  896. ret_val = e1000_copper_link_setup_gg82563_80003es2lan(hw);
  897. if (ret_val)
  898. return ret_val;
  899. return e1000e_setup_copper_link(hw);
  900. }
  901. /**
  902. * e1000_cfg_on_link_up_80003es2lan - es2 link configuration after link-up
  903. * @hw: pointer to the HW structure
  904. * @duplex: current duplex setting
  905. *
  906. * Configure the KMRN interface by applying last minute quirks for
  907. * 10/100 operation.
  908. **/
  909. static s32 e1000_cfg_on_link_up_80003es2lan(struct e1000_hw *hw)
  910. {
  911. s32 ret_val = 0;
  912. u16 speed;
  913. u16 duplex;
  914. if (hw->phy.media_type == e1000_media_type_copper) {
  915. ret_val = e1000e_get_speed_and_duplex_copper(hw, &speed,
  916. &duplex);
  917. if (ret_val)
  918. return ret_val;
  919. if (speed == SPEED_1000)
  920. ret_val = e1000_cfg_kmrn_1000_80003es2lan(hw);
  921. else
  922. ret_val = e1000_cfg_kmrn_10_100_80003es2lan(hw, duplex);
  923. }
  924. return ret_val;
  925. }
  926. /**
  927. * e1000_cfg_kmrn_10_100_80003es2lan - Apply "quirks" for 10/100 operation
  928. * @hw: pointer to the HW structure
  929. * @duplex: current duplex setting
  930. *
  931. * Configure the KMRN interface by applying last minute quirks for
  932. * 10/100 operation.
  933. **/
  934. static s32 e1000_cfg_kmrn_10_100_80003es2lan(struct e1000_hw *hw, u16 duplex)
  935. {
  936. s32 ret_val;
  937. u32 tipg;
  938. u32 i = 0;
  939. u16 reg_data, reg_data2;
  940. reg_data = E1000_KMRNCTRLSTA_HD_CTRL_10_100_DEFAULT;
  941. ret_val =
  942. e1000_write_kmrn_reg_80003es2lan(hw,
  943. E1000_KMRNCTRLSTA_OFFSET_HD_CTRL,
  944. reg_data);
  945. if (ret_val)
  946. return ret_val;
  947. /* Configure Transmit Inter-Packet Gap */
  948. tipg = er32(TIPG);
  949. tipg &= ~E1000_TIPG_IPGT_MASK;
  950. tipg |= DEFAULT_TIPG_IPGT_10_100_80003ES2LAN;
  951. ew32(TIPG, tipg);
  952. do {
  953. ret_val = e1e_rphy(hw, GG82563_PHY_KMRN_MODE_CTRL, &reg_data);
  954. if (ret_val)
  955. return ret_val;
  956. ret_val = e1e_rphy(hw, GG82563_PHY_KMRN_MODE_CTRL, &reg_data2);
  957. if (ret_val)
  958. return ret_val;
  959. i++;
  960. } while ((reg_data != reg_data2) && (i < GG82563_MAX_KMRN_RETRY));
  961. if (duplex == HALF_DUPLEX)
  962. reg_data |= GG82563_KMCR_PASS_FALSE_CARRIER;
  963. else
  964. reg_data &= ~GG82563_KMCR_PASS_FALSE_CARRIER;
  965. return e1e_wphy(hw, GG82563_PHY_KMRN_MODE_CTRL, reg_data);
  966. }
  967. /**
  968. * e1000_cfg_kmrn_1000_80003es2lan - Apply "quirks" for gigabit operation
  969. * @hw: pointer to the HW structure
  970. *
  971. * Configure the KMRN interface by applying last minute quirks for
  972. * gigabit operation.
  973. **/
  974. static s32 e1000_cfg_kmrn_1000_80003es2lan(struct e1000_hw *hw)
  975. {
  976. s32 ret_val;
  977. u16 reg_data, reg_data2;
  978. u32 tipg;
  979. u32 i = 0;
  980. reg_data = E1000_KMRNCTRLSTA_HD_CTRL_1000_DEFAULT;
  981. ret_val =
  982. e1000_write_kmrn_reg_80003es2lan(hw,
  983. E1000_KMRNCTRLSTA_OFFSET_HD_CTRL,
  984. reg_data);
  985. if (ret_val)
  986. return ret_val;
  987. /* Configure Transmit Inter-Packet Gap */
  988. tipg = er32(TIPG);
  989. tipg &= ~E1000_TIPG_IPGT_MASK;
  990. tipg |= DEFAULT_TIPG_IPGT_1000_80003ES2LAN;
  991. ew32(TIPG, tipg);
  992. do {
  993. ret_val = e1e_rphy(hw, GG82563_PHY_KMRN_MODE_CTRL, &reg_data);
  994. if (ret_val)
  995. return ret_val;
  996. ret_val = e1e_rphy(hw, GG82563_PHY_KMRN_MODE_CTRL, &reg_data2);
  997. if (ret_val)
  998. return ret_val;
  999. i++;
  1000. } while ((reg_data != reg_data2) && (i < GG82563_MAX_KMRN_RETRY));
  1001. reg_data &= ~GG82563_KMCR_PASS_FALSE_CARRIER;
  1002. return e1e_wphy(hw, GG82563_PHY_KMRN_MODE_CTRL, reg_data);
  1003. }
  1004. /**
  1005. * e1000_read_kmrn_reg_80003es2lan - Read kumeran register
  1006. * @hw: pointer to the HW structure
  1007. * @offset: register offset to be read
  1008. * @data: pointer to the read data
  1009. *
  1010. * Acquire semaphore, then read the PHY register at offset
  1011. * using the kumeran interface. The information retrieved is stored in data.
  1012. * Release the semaphore before exiting.
  1013. **/
  1014. static s32 e1000_read_kmrn_reg_80003es2lan(struct e1000_hw *hw, u32 offset,
  1015. u16 *data)
  1016. {
  1017. u32 kmrnctrlsta;
  1018. s32 ret_val;
  1019. ret_val = e1000_acquire_mac_csr_80003es2lan(hw);
  1020. if (ret_val)
  1021. return ret_val;
  1022. kmrnctrlsta = ((offset << E1000_KMRNCTRLSTA_OFFSET_SHIFT) &
  1023. E1000_KMRNCTRLSTA_OFFSET) | E1000_KMRNCTRLSTA_REN;
  1024. ew32(KMRNCTRLSTA, kmrnctrlsta);
  1025. e1e_flush();
  1026. udelay(2);
  1027. kmrnctrlsta = er32(KMRNCTRLSTA);
  1028. *data = (u16)kmrnctrlsta;
  1029. e1000_release_mac_csr_80003es2lan(hw);
  1030. return ret_val;
  1031. }
  1032. /**
  1033. * e1000_write_kmrn_reg_80003es2lan - Write kumeran register
  1034. * @hw: pointer to the HW structure
  1035. * @offset: register offset to write to
  1036. * @data: data to write at register offset
  1037. *
  1038. * Acquire semaphore, then write the data to PHY register
  1039. * at the offset using the kumeran interface. Release semaphore
  1040. * before exiting.
  1041. **/
  1042. static s32 e1000_write_kmrn_reg_80003es2lan(struct e1000_hw *hw, u32 offset,
  1043. u16 data)
  1044. {
  1045. u32 kmrnctrlsta;
  1046. s32 ret_val;
  1047. ret_val = e1000_acquire_mac_csr_80003es2lan(hw);
  1048. if (ret_val)
  1049. return ret_val;
  1050. kmrnctrlsta = ((offset << E1000_KMRNCTRLSTA_OFFSET_SHIFT) &
  1051. E1000_KMRNCTRLSTA_OFFSET) | data;
  1052. ew32(KMRNCTRLSTA, kmrnctrlsta);
  1053. e1e_flush();
  1054. udelay(2);
  1055. e1000_release_mac_csr_80003es2lan(hw);
  1056. return ret_val;
  1057. }
  1058. /**
  1059. * e1000_read_mac_addr_80003es2lan - Read device MAC address
  1060. * @hw: pointer to the HW structure
  1061. **/
  1062. static s32 e1000_read_mac_addr_80003es2lan(struct e1000_hw *hw)
  1063. {
  1064. s32 ret_val;
  1065. /* If there's an alternate MAC address place it in RAR0
  1066. * so that it will override the Si installed default perm
  1067. * address.
  1068. */
  1069. ret_val = e1000_check_alt_mac_addr_generic(hw);
  1070. if (ret_val)
  1071. return ret_val;
  1072. return e1000_read_mac_addr_generic(hw);
  1073. }
  1074. /**
  1075. * e1000_power_down_phy_copper_80003es2lan - Remove link during PHY power down
  1076. * @hw: pointer to the HW structure
  1077. *
  1078. * In the case of a PHY power down to save power, or to turn off link during a
  1079. * driver unload, or wake on lan is not enabled, remove the link.
  1080. **/
  1081. static void e1000_power_down_phy_copper_80003es2lan(struct e1000_hw *hw)
  1082. {
  1083. /* If the management interface is not enabled, then power down */
  1084. if (!(hw->mac.ops.check_mng_mode(hw) ||
  1085. hw->phy.ops.check_reset_block(hw)))
  1086. e1000_power_down_phy_copper(hw);
  1087. }
  1088. /**
  1089. * e1000_clear_hw_cntrs_80003es2lan - Clear device specific hardware counters
  1090. * @hw: pointer to the HW structure
  1091. *
  1092. * Clears the hardware counters by reading the counter registers.
  1093. **/
  1094. static void e1000_clear_hw_cntrs_80003es2lan(struct e1000_hw *hw)
  1095. {
  1096. e1000e_clear_hw_cntrs_base(hw);
  1097. er32(PRC64);
  1098. er32(PRC127);
  1099. er32(PRC255);
  1100. er32(PRC511);
  1101. er32(PRC1023);
  1102. er32(PRC1522);
  1103. er32(PTC64);
  1104. er32(PTC127);
  1105. er32(PTC255);
  1106. er32(PTC511);
  1107. er32(PTC1023);
  1108. er32(PTC1522);
  1109. er32(ALGNERRC);
  1110. er32(RXERRC);
  1111. er32(TNCRS);
  1112. er32(CEXTERR);
  1113. er32(TSCTC);
  1114. er32(TSCTFC);
  1115. er32(MGTPRC);
  1116. er32(MGTPDC);
  1117. er32(MGTPTC);
  1118. er32(IAC);
  1119. er32(ICRXOC);
  1120. er32(ICRXPTC);
  1121. er32(ICRXATC);
  1122. er32(ICTXPTC);
  1123. er32(ICTXATC);
  1124. er32(ICTXQEC);
  1125. er32(ICTXQMTC);
  1126. er32(ICRXDMTC);
  1127. }
  1128. static const struct e1000_mac_operations es2_mac_ops = {
  1129. .read_mac_addr = e1000_read_mac_addr_80003es2lan,
  1130. .id_led_init = e1000e_id_led_init_generic,
  1131. .blink_led = e1000e_blink_led_generic,
  1132. .check_mng_mode = e1000e_check_mng_mode_generic,
  1133. /* check_for_link dependent on media type */
  1134. .cleanup_led = e1000e_cleanup_led_generic,
  1135. .clear_hw_cntrs = e1000_clear_hw_cntrs_80003es2lan,
  1136. .get_bus_info = e1000e_get_bus_info_pcie,
  1137. .set_lan_id = e1000_set_lan_id_multi_port_pcie,
  1138. .get_link_up_info = e1000_get_link_up_info_80003es2lan,
  1139. .led_on = e1000e_led_on_generic,
  1140. .led_off = e1000e_led_off_generic,
  1141. .update_mc_addr_list = e1000e_update_mc_addr_list_generic,
  1142. .write_vfta = e1000_write_vfta_generic,
  1143. .clear_vfta = e1000_clear_vfta_generic,
  1144. .reset_hw = e1000_reset_hw_80003es2lan,
  1145. .init_hw = e1000_init_hw_80003es2lan,
  1146. .setup_link = e1000e_setup_link_generic,
  1147. /* setup_physical_interface dependent on media type */
  1148. .setup_led = e1000e_setup_led_generic,
  1149. .config_collision_dist = e1000e_config_collision_dist_generic,
  1150. .rar_set = e1000e_rar_set_generic,
  1151. .rar_get_count = e1000e_rar_get_count_generic,
  1152. };
  1153. static const struct e1000_phy_operations es2_phy_ops = {
  1154. .acquire = e1000_acquire_phy_80003es2lan,
  1155. .check_polarity = e1000_check_polarity_m88,
  1156. .check_reset_block = e1000e_check_reset_block_generic,
  1157. .commit = e1000e_phy_sw_reset,
  1158. .force_speed_duplex = e1000_phy_force_speed_duplex_80003es2lan,
  1159. .get_cfg_done = e1000_get_cfg_done_80003es2lan,
  1160. .get_cable_length = e1000_get_cable_length_80003es2lan,
  1161. .get_info = e1000e_get_phy_info_m88,
  1162. .read_reg = e1000_read_phy_reg_gg82563_80003es2lan,
  1163. .release = e1000_release_phy_80003es2lan,
  1164. .reset = e1000e_phy_hw_reset_generic,
  1165. .set_d0_lplu_state = NULL,
  1166. .set_d3_lplu_state = e1000e_set_d3_lplu_state,
  1167. .write_reg = e1000_write_phy_reg_gg82563_80003es2lan,
  1168. .cfg_on_link_up = e1000_cfg_on_link_up_80003es2lan,
  1169. };
  1170. static const struct e1000_nvm_operations es2_nvm_ops = {
  1171. .acquire = e1000_acquire_nvm_80003es2lan,
  1172. .read = e1000e_read_nvm_eerd,
  1173. .release = e1000_release_nvm_80003es2lan,
  1174. .reload = e1000e_reload_nvm_generic,
  1175. .update = e1000e_update_nvm_checksum_generic,
  1176. .valid_led_default = e1000e_valid_led_default,
  1177. .validate = e1000e_validate_nvm_checksum_generic,
  1178. .write = e1000_write_nvm_80003es2lan,
  1179. };
  1180. const struct e1000_info e1000_es2_info = {
  1181. .mac = e1000_80003es2lan,
  1182. .flags = FLAG_HAS_HW_VLAN_FILTER
  1183. | FLAG_HAS_JUMBO_FRAMES
  1184. | FLAG_HAS_WOL
  1185. | FLAG_APME_IN_CTRL3
  1186. | FLAG_HAS_CTRLEXT_ON_LOAD
  1187. | FLAG_RX_NEEDS_RESTART /* errata */
  1188. | FLAG_TARC_SET_BIT_ZERO /* errata */
  1189. | FLAG_APME_CHECK_PORT_B
  1190. | FLAG_DISABLE_FC_PAUSE_TIME, /* errata */
  1191. .flags2 = FLAG2_DMA_BURST,
  1192. .pba = 38,
  1193. .max_hw_frame_size = DEFAULT_JUMBO,
  1194. .get_variants = e1000_get_variants_80003es2lan,
  1195. .mac_ops = &es2_mac_ops,
  1196. .phy_ops = &es2_phy_ops,
  1197. .nvm_ops = &es2_nvm_ops,
  1198. };