80003es2lan.c 36 KB

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