80003es2lan.c 36 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400
  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, 20000);
  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. return ret_val;
  580. kum_reg_data |= E1000_KMRNCTRLSTA_IBIST_DISABLE;
  581. e1000_write_kmrn_reg_80003es2lan(hw, E1000_KMRNCTRLSTA_INBAND_PARAM,
  582. kum_reg_data);
  583. ret_val = e1000e_get_auto_rd_done(hw);
  584. if (ret_val)
  585. /* We don't want to continue accessing MAC registers. */
  586. return ret_val;
  587. /* Clear any pending interrupt events. */
  588. ew32(IMC, 0xffffffff);
  589. er32(ICR);
  590. return e1000_check_alt_mac_addr_generic(hw);
  591. }
  592. /**
  593. * e1000_init_hw_80003es2lan - Initialize the ESB2 controller
  594. * @hw: pointer to the HW structure
  595. *
  596. * Initialize the hw bits, LED, VFTA, MTA, link and hw counters.
  597. **/
  598. static s32 e1000_init_hw_80003es2lan(struct e1000_hw *hw)
  599. {
  600. struct e1000_mac_info *mac = &hw->mac;
  601. u32 reg_data;
  602. s32 ret_val;
  603. u16 kum_reg_data;
  604. u16 i;
  605. e1000_initialize_hw_bits_80003es2lan(hw);
  606. /* Initialize identification LED */
  607. ret_val = mac->ops.id_led_init(hw);
  608. /* An error is not fatal and we should not stop init due to this */
  609. if (ret_val)
  610. e_dbg("Error initializing identification LED\n");
  611. /* Disabling VLAN filtering */
  612. e_dbg("Initializing the IEEE VLAN\n");
  613. mac->ops.clear_vfta(hw);
  614. /* Setup the receive address. */
  615. e1000e_init_rx_addrs(hw, mac->rar_entry_count);
  616. /* Zero out the Multicast HASH table */
  617. e_dbg("Zeroing the MTA\n");
  618. for (i = 0; i < mac->mta_reg_count; i++)
  619. E1000_WRITE_REG_ARRAY(hw, E1000_MTA, i, 0);
  620. /* Setup link and flow control */
  621. ret_val = mac->ops.setup_link(hw);
  622. if (ret_val)
  623. return ret_val;
  624. /* Disable IBIST slave mode (far-end loopback) */
  625. e1000_read_kmrn_reg_80003es2lan(hw, E1000_KMRNCTRLSTA_INBAND_PARAM,
  626. &kum_reg_data);
  627. kum_reg_data |= E1000_KMRNCTRLSTA_IBIST_DISABLE;
  628. e1000_write_kmrn_reg_80003es2lan(hw, E1000_KMRNCTRLSTA_INBAND_PARAM,
  629. kum_reg_data);
  630. /* Set the transmit descriptor write-back policy */
  631. reg_data = er32(TXDCTL(0));
  632. reg_data = ((reg_data & ~E1000_TXDCTL_WTHRESH) |
  633. E1000_TXDCTL_FULL_TX_DESC_WB | E1000_TXDCTL_COUNT_DESC);
  634. ew32(TXDCTL(0), reg_data);
  635. /* ...for both queues. */
  636. reg_data = er32(TXDCTL(1));
  637. reg_data = ((reg_data & ~E1000_TXDCTL_WTHRESH) |
  638. E1000_TXDCTL_FULL_TX_DESC_WB | E1000_TXDCTL_COUNT_DESC);
  639. ew32(TXDCTL(1), reg_data);
  640. /* Enable retransmit on late collisions */
  641. reg_data = er32(TCTL);
  642. reg_data |= E1000_TCTL_RTLC;
  643. ew32(TCTL, reg_data);
  644. /* Configure Gigabit Carry Extend Padding */
  645. reg_data = er32(TCTL_EXT);
  646. reg_data &= ~E1000_TCTL_EXT_GCEX_MASK;
  647. reg_data |= DEFAULT_TCTL_EXT_GCEX_80003ES2LAN;
  648. ew32(TCTL_EXT, reg_data);
  649. /* Configure Transmit Inter-Packet Gap */
  650. reg_data = er32(TIPG);
  651. reg_data &= ~E1000_TIPG_IPGT_MASK;
  652. reg_data |= DEFAULT_TIPG_IPGT_1000_80003ES2LAN;
  653. ew32(TIPG, reg_data);
  654. reg_data = E1000_READ_REG_ARRAY(hw, E1000_FFLT, 0x0001);
  655. reg_data &= ~0x00100000;
  656. E1000_WRITE_REG_ARRAY(hw, E1000_FFLT, 0x0001, reg_data);
  657. /* default to true to enable the MDIC W/A */
  658. hw->dev_spec.e80003es2lan.mdic_wa_enable = true;
  659. ret_val =
  660. e1000_read_kmrn_reg_80003es2lan(hw, E1000_KMRNCTRLSTA_OFFSET >>
  661. E1000_KMRNCTRLSTA_OFFSET_SHIFT, &i);
  662. if (!ret_val) {
  663. if ((i & E1000_KMRNCTRLSTA_OPMODE_MASK) ==
  664. E1000_KMRNCTRLSTA_OPMODE_INBAND_MDIO)
  665. hw->dev_spec.e80003es2lan.mdic_wa_enable = false;
  666. }
  667. /* Clear all of the statistics registers (clear on read). It is
  668. * important that we do this after we have tried to establish link
  669. * because the symbol error count will increment wildly if there
  670. * is no link.
  671. */
  672. e1000_clear_hw_cntrs_80003es2lan(hw);
  673. return ret_val;
  674. }
  675. /**
  676. * e1000_initialize_hw_bits_80003es2lan - Init hw bits of ESB2
  677. * @hw: pointer to the HW structure
  678. *
  679. * Initializes required hardware-dependent bits needed for normal operation.
  680. **/
  681. static void e1000_initialize_hw_bits_80003es2lan(struct e1000_hw *hw)
  682. {
  683. u32 reg;
  684. /* Transmit Descriptor Control 0 */
  685. reg = er32(TXDCTL(0));
  686. reg |= BIT(22);
  687. ew32(TXDCTL(0), reg);
  688. /* Transmit Descriptor Control 1 */
  689. reg = er32(TXDCTL(1));
  690. reg |= BIT(22);
  691. ew32(TXDCTL(1), reg);
  692. /* Transmit Arbitration Control 0 */
  693. reg = er32(TARC(0));
  694. reg &= ~(0xF << 27); /* 30:27 */
  695. if (hw->phy.media_type != e1000_media_type_copper)
  696. reg &= ~BIT(20);
  697. ew32(TARC(0), reg);
  698. /* Transmit Arbitration Control 1 */
  699. reg = er32(TARC(1));
  700. if (er32(TCTL) & E1000_TCTL_MULR)
  701. reg &= ~BIT(28);
  702. else
  703. reg |= BIT(28);
  704. ew32(TARC(1), reg);
  705. /* Disable IPv6 extension header parsing because some malformed
  706. * IPv6 headers can hang the Rx.
  707. */
  708. reg = er32(RFCTL);
  709. reg |= (E1000_RFCTL_IPV6_EX_DIS | E1000_RFCTL_NEW_IPV6_EXT_DIS);
  710. ew32(RFCTL, reg);
  711. }
  712. /**
  713. * e1000_copper_link_setup_gg82563_80003es2lan - Configure GG82563 Link
  714. * @hw: pointer to the HW structure
  715. *
  716. * Setup some GG82563 PHY registers for obtaining link
  717. **/
  718. static s32 e1000_copper_link_setup_gg82563_80003es2lan(struct e1000_hw *hw)
  719. {
  720. struct e1000_phy_info *phy = &hw->phy;
  721. s32 ret_val;
  722. u32 reg;
  723. u16 data;
  724. ret_val = e1e_rphy(hw, GG82563_PHY_MAC_SPEC_CTRL, &data);
  725. if (ret_val)
  726. return ret_val;
  727. data |= GG82563_MSCR_ASSERT_CRS_ON_TX;
  728. /* Use 25MHz for both link down and 1000Base-T for Tx clock. */
  729. data |= GG82563_MSCR_TX_CLK_1000MBPS_25;
  730. ret_val = e1e_wphy(hw, GG82563_PHY_MAC_SPEC_CTRL, data);
  731. if (ret_val)
  732. return ret_val;
  733. /* Options:
  734. * MDI/MDI-X = 0 (default)
  735. * 0 - Auto for all speeds
  736. * 1 - MDI mode
  737. * 2 - MDI-X mode
  738. * 3 - Auto for 1000Base-T only (MDI-X for 10/100Base-T modes)
  739. */
  740. ret_val = e1e_rphy(hw, GG82563_PHY_SPEC_CTRL, &data);
  741. if (ret_val)
  742. return ret_val;
  743. data &= ~GG82563_PSCR_CROSSOVER_MODE_MASK;
  744. switch (phy->mdix) {
  745. case 1:
  746. data |= GG82563_PSCR_CROSSOVER_MODE_MDI;
  747. break;
  748. case 2:
  749. data |= GG82563_PSCR_CROSSOVER_MODE_MDIX;
  750. break;
  751. case 0:
  752. default:
  753. data |= GG82563_PSCR_CROSSOVER_MODE_AUTO;
  754. break;
  755. }
  756. /* Options:
  757. * disable_polarity_correction = 0 (default)
  758. * Automatic Correction for Reversed Cable Polarity
  759. * 0 - Disabled
  760. * 1 - Enabled
  761. */
  762. data &= ~GG82563_PSCR_POLARITY_REVERSAL_DISABLE;
  763. if (phy->disable_polarity_correction)
  764. data |= GG82563_PSCR_POLARITY_REVERSAL_DISABLE;
  765. ret_val = e1e_wphy(hw, GG82563_PHY_SPEC_CTRL, data);
  766. if (ret_val)
  767. return ret_val;
  768. /* SW Reset the PHY so all changes take effect */
  769. ret_val = hw->phy.ops.commit(hw);
  770. if (ret_val) {
  771. e_dbg("Error Resetting the PHY\n");
  772. return ret_val;
  773. }
  774. /* Bypass Rx and Tx FIFO's */
  775. reg = E1000_KMRNCTRLSTA_OFFSET_FIFO_CTRL;
  776. data = (E1000_KMRNCTRLSTA_FIFO_CTRL_RX_BYPASS |
  777. E1000_KMRNCTRLSTA_FIFO_CTRL_TX_BYPASS);
  778. ret_val = e1000_write_kmrn_reg_80003es2lan(hw, reg, data);
  779. if (ret_val)
  780. return ret_val;
  781. reg = E1000_KMRNCTRLSTA_OFFSET_MAC2PHY_OPMODE;
  782. ret_val = e1000_read_kmrn_reg_80003es2lan(hw, reg, &data);
  783. if (ret_val)
  784. return ret_val;
  785. data |= E1000_KMRNCTRLSTA_OPMODE_E_IDLE;
  786. ret_val = e1000_write_kmrn_reg_80003es2lan(hw, reg, data);
  787. if (ret_val)
  788. return ret_val;
  789. ret_val = e1e_rphy(hw, GG82563_PHY_SPEC_CTRL_2, &data);
  790. if (ret_val)
  791. return ret_val;
  792. data &= ~GG82563_PSCR2_REVERSE_AUTO_NEG;
  793. ret_val = e1e_wphy(hw, GG82563_PHY_SPEC_CTRL_2, data);
  794. if (ret_val)
  795. return ret_val;
  796. reg = er32(CTRL_EXT);
  797. reg &= ~E1000_CTRL_EXT_LINK_MODE_MASK;
  798. ew32(CTRL_EXT, reg);
  799. ret_val = e1e_rphy(hw, GG82563_PHY_PWR_MGMT_CTRL, &data);
  800. if (ret_val)
  801. return ret_val;
  802. /* Do not init these registers when the HW is in IAMT mode, since the
  803. * firmware will have already initialized them. We only initialize
  804. * them if the HW is not in IAMT mode.
  805. */
  806. if (!hw->mac.ops.check_mng_mode(hw)) {
  807. /* Enable Electrical Idle on the PHY */
  808. data |= GG82563_PMCR_ENABLE_ELECTRICAL_IDLE;
  809. ret_val = e1e_wphy(hw, GG82563_PHY_PWR_MGMT_CTRL, data);
  810. if (ret_val)
  811. return ret_val;
  812. ret_val = e1e_rphy(hw, GG82563_PHY_KMRN_MODE_CTRL, &data);
  813. if (ret_val)
  814. return ret_val;
  815. data &= ~GG82563_KMCR_PASS_FALSE_CARRIER;
  816. ret_val = e1e_wphy(hw, GG82563_PHY_KMRN_MODE_CTRL, data);
  817. if (ret_val)
  818. return ret_val;
  819. }
  820. /* Workaround: Disable padding in Kumeran interface in the MAC
  821. * and in the PHY to avoid CRC errors.
  822. */
  823. ret_val = e1e_rphy(hw, GG82563_PHY_INBAND_CTRL, &data);
  824. if (ret_val)
  825. return ret_val;
  826. data |= GG82563_ICR_DIS_PADDING;
  827. ret_val = e1e_wphy(hw, GG82563_PHY_INBAND_CTRL, data);
  828. if (ret_val)
  829. return ret_val;
  830. return 0;
  831. }
  832. /**
  833. * e1000_setup_copper_link_80003es2lan - Setup Copper Link for ESB2
  834. * @hw: pointer to the HW structure
  835. *
  836. * Essentially a wrapper for setting up all things "copper" related.
  837. * This is a function pointer entry point called by the mac module.
  838. **/
  839. static s32 e1000_setup_copper_link_80003es2lan(struct e1000_hw *hw)
  840. {
  841. u32 ctrl;
  842. s32 ret_val;
  843. u16 reg_data;
  844. ctrl = er32(CTRL);
  845. ctrl |= E1000_CTRL_SLU;
  846. ctrl &= ~(E1000_CTRL_FRCSPD | E1000_CTRL_FRCDPX);
  847. ew32(CTRL, ctrl);
  848. /* Set the mac to wait the maximum time between each
  849. * iteration and increase the max iterations when
  850. * polling the phy; this fixes erroneous timeouts at 10Mbps.
  851. */
  852. ret_val = e1000_write_kmrn_reg_80003es2lan(hw, GG82563_REG(0x34, 4),
  853. 0xFFFF);
  854. if (ret_val)
  855. return ret_val;
  856. ret_val = e1000_read_kmrn_reg_80003es2lan(hw, GG82563_REG(0x34, 9),
  857. &reg_data);
  858. if (ret_val)
  859. return ret_val;
  860. reg_data |= 0x3F;
  861. ret_val = e1000_write_kmrn_reg_80003es2lan(hw, GG82563_REG(0x34, 9),
  862. reg_data);
  863. if (ret_val)
  864. return ret_val;
  865. ret_val =
  866. e1000_read_kmrn_reg_80003es2lan(hw,
  867. E1000_KMRNCTRLSTA_OFFSET_INB_CTRL,
  868. &reg_data);
  869. if (ret_val)
  870. return ret_val;
  871. reg_data |= E1000_KMRNCTRLSTA_INB_CTRL_DIS_PADDING;
  872. ret_val =
  873. e1000_write_kmrn_reg_80003es2lan(hw,
  874. E1000_KMRNCTRLSTA_OFFSET_INB_CTRL,
  875. reg_data);
  876. if (ret_val)
  877. return ret_val;
  878. ret_val = e1000_copper_link_setup_gg82563_80003es2lan(hw);
  879. if (ret_val)
  880. return ret_val;
  881. return e1000e_setup_copper_link(hw);
  882. }
  883. /**
  884. * e1000_cfg_on_link_up_80003es2lan - es2 link configuration after link-up
  885. * @hw: pointer to the HW structure
  886. * @duplex: current duplex setting
  887. *
  888. * Configure the KMRN interface by applying last minute quirks for
  889. * 10/100 operation.
  890. **/
  891. static s32 e1000_cfg_on_link_up_80003es2lan(struct e1000_hw *hw)
  892. {
  893. s32 ret_val = 0;
  894. u16 speed;
  895. u16 duplex;
  896. if (hw->phy.media_type == e1000_media_type_copper) {
  897. ret_val = e1000e_get_speed_and_duplex_copper(hw, &speed,
  898. &duplex);
  899. if (ret_val)
  900. return ret_val;
  901. if (speed == SPEED_1000)
  902. ret_val = e1000_cfg_kmrn_1000_80003es2lan(hw);
  903. else
  904. ret_val = e1000_cfg_kmrn_10_100_80003es2lan(hw, duplex);
  905. }
  906. return ret_val;
  907. }
  908. /**
  909. * e1000_cfg_kmrn_10_100_80003es2lan - Apply "quirks" for 10/100 operation
  910. * @hw: pointer to the HW structure
  911. * @duplex: current duplex setting
  912. *
  913. * Configure the KMRN interface by applying last minute quirks for
  914. * 10/100 operation.
  915. **/
  916. static s32 e1000_cfg_kmrn_10_100_80003es2lan(struct e1000_hw *hw, u16 duplex)
  917. {
  918. s32 ret_val;
  919. u32 tipg;
  920. u32 i = 0;
  921. u16 reg_data, reg_data2;
  922. reg_data = E1000_KMRNCTRLSTA_HD_CTRL_10_100_DEFAULT;
  923. ret_val =
  924. e1000_write_kmrn_reg_80003es2lan(hw,
  925. E1000_KMRNCTRLSTA_OFFSET_HD_CTRL,
  926. reg_data);
  927. if (ret_val)
  928. return ret_val;
  929. /* Configure Transmit Inter-Packet Gap */
  930. tipg = er32(TIPG);
  931. tipg &= ~E1000_TIPG_IPGT_MASK;
  932. tipg |= DEFAULT_TIPG_IPGT_10_100_80003ES2LAN;
  933. ew32(TIPG, tipg);
  934. do {
  935. ret_val = e1e_rphy(hw, GG82563_PHY_KMRN_MODE_CTRL, &reg_data);
  936. if (ret_val)
  937. return ret_val;
  938. ret_val = e1e_rphy(hw, GG82563_PHY_KMRN_MODE_CTRL, &reg_data2);
  939. if (ret_val)
  940. return ret_val;
  941. i++;
  942. } while ((reg_data != reg_data2) && (i < GG82563_MAX_KMRN_RETRY));
  943. if (duplex == HALF_DUPLEX)
  944. reg_data |= GG82563_KMCR_PASS_FALSE_CARRIER;
  945. else
  946. reg_data &= ~GG82563_KMCR_PASS_FALSE_CARRIER;
  947. return e1e_wphy(hw, GG82563_PHY_KMRN_MODE_CTRL, reg_data);
  948. }
  949. /**
  950. * e1000_cfg_kmrn_1000_80003es2lan - Apply "quirks" for gigabit operation
  951. * @hw: pointer to the HW structure
  952. *
  953. * Configure the KMRN interface by applying last minute quirks for
  954. * gigabit operation.
  955. **/
  956. static s32 e1000_cfg_kmrn_1000_80003es2lan(struct e1000_hw *hw)
  957. {
  958. s32 ret_val;
  959. u16 reg_data, reg_data2;
  960. u32 tipg;
  961. u32 i = 0;
  962. reg_data = E1000_KMRNCTRLSTA_HD_CTRL_1000_DEFAULT;
  963. ret_val =
  964. e1000_write_kmrn_reg_80003es2lan(hw,
  965. E1000_KMRNCTRLSTA_OFFSET_HD_CTRL,
  966. reg_data);
  967. if (ret_val)
  968. return ret_val;
  969. /* Configure Transmit Inter-Packet Gap */
  970. tipg = er32(TIPG);
  971. tipg &= ~E1000_TIPG_IPGT_MASK;
  972. tipg |= DEFAULT_TIPG_IPGT_1000_80003ES2LAN;
  973. ew32(TIPG, tipg);
  974. do {
  975. ret_val = e1e_rphy(hw, GG82563_PHY_KMRN_MODE_CTRL, &reg_data);
  976. if (ret_val)
  977. return ret_val;
  978. ret_val = e1e_rphy(hw, GG82563_PHY_KMRN_MODE_CTRL, &reg_data2);
  979. if (ret_val)
  980. return ret_val;
  981. i++;
  982. } while ((reg_data != reg_data2) && (i < GG82563_MAX_KMRN_RETRY));
  983. reg_data &= ~GG82563_KMCR_PASS_FALSE_CARRIER;
  984. return e1e_wphy(hw, GG82563_PHY_KMRN_MODE_CTRL, reg_data);
  985. }
  986. /**
  987. * e1000_read_kmrn_reg_80003es2lan - Read kumeran register
  988. * @hw: pointer to the HW structure
  989. * @offset: register offset to be read
  990. * @data: pointer to the read data
  991. *
  992. * Acquire semaphore, then read the PHY register at offset
  993. * using the kumeran interface. The information retrieved is stored in data.
  994. * Release the semaphore before exiting.
  995. **/
  996. static s32 e1000_read_kmrn_reg_80003es2lan(struct e1000_hw *hw, u32 offset,
  997. u16 *data)
  998. {
  999. u32 kmrnctrlsta;
  1000. s32 ret_val;
  1001. ret_val = e1000_acquire_mac_csr_80003es2lan(hw);
  1002. if (ret_val)
  1003. return ret_val;
  1004. kmrnctrlsta = ((offset << E1000_KMRNCTRLSTA_OFFSET_SHIFT) &
  1005. E1000_KMRNCTRLSTA_OFFSET) | E1000_KMRNCTRLSTA_REN;
  1006. ew32(KMRNCTRLSTA, kmrnctrlsta);
  1007. e1e_flush();
  1008. udelay(2);
  1009. kmrnctrlsta = er32(KMRNCTRLSTA);
  1010. *data = (u16)kmrnctrlsta;
  1011. e1000_release_mac_csr_80003es2lan(hw);
  1012. return ret_val;
  1013. }
  1014. /**
  1015. * e1000_write_kmrn_reg_80003es2lan - Write kumeran register
  1016. * @hw: pointer to the HW structure
  1017. * @offset: register offset to write to
  1018. * @data: data to write at register offset
  1019. *
  1020. * Acquire semaphore, then write the data to PHY register
  1021. * at the offset using the kumeran interface. Release semaphore
  1022. * before exiting.
  1023. **/
  1024. static s32 e1000_write_kmrn_reg_80003es2lan(struct e1000_hw *hw, u32 offset,
  1025. u16 data)
  1026. {
  1027. u32 kmrnctrlsta;
  1028. s32 ret_val;
  1029. ret_val = e1000_acquire_mac_csr_80003es2lan(hw);
  1030. if (ret_val)
  1031. return ret_val;
  1032. kmrnctrlsta = ((offset << E1000_KMRNCTRLSTA_OFFSET_SHIFT) &
  1033. E1000_KMRNCTRLSTA_OFFSET) | data;
  1034. ew32(KMRNCTRLSTA, kmrnctrlsta);
  1035. e1e_flush();
  1036. udelay(2);
  1037. e1000_release_mac_csr_80003es2lan(hw);
  1038. return ret_val;
  1039. }
  1040. /**
  1041. * e1000_read_mac_addr_80003es2lan - Read device MAC address
  1042. * @hw: pointer to the HW structure
  1043. **/
  1044. static s32 e1000_read_mac_addr_80003es2lan(struct e1000_hw *hw)
  1045. {
  1046. s32 ret_val;
  1047. /* If there's an alternate MAC address place it in RAR0
  1048. * so that it will override the Si installed default perm
  1049. * address.
  1050. */
  1051. ret_val = e1000_check_alt_mac_addr_generic(hw);
  1052. if (ret_val)
  1053. return ret_val;
  1054. return e1000_read_mac_addr_generic(hw);
  1055. }
  1056. /**
  1057. * e1000_power_down_phy_copper_80003es2lan - Remove link during PHY power down
  1058. * @hw: pointer to the HW structure
  1059. *
  1060. * In the case of a PHY power down to save power, or to turn off link during a
  1061. * driver unload, or wake on lan is not enabled, remove the link.
  1062. **/
  1063. static void e1000_power_down_phy_copper_80003es2lan(struct e1000_hw *hw)
  1064. {
  1065. /* If the management interface is not enabled, then power down */
  1066. if (!(hw->mac.ops.check_mng_mode(hw) ||
  1067. hw->phy.ops.check_reset_block(hw)))
  1068. e1000_power_down_phy_copper(hw);
  1069. }
  1070. /**
  1071. * e1000_clear_hw_cntrs_80003es2lan - Clear device specific hardware counters
  1072. * @hw: pointer to the HW structure
  1073. *
  1074. * Clears the hardware counters by reading the counter registers.
  1075. **/
  1076. static void e1000_clear_hw_cntrs_80003es2lan(struct e1000_hw *hw)
  1077. {
  1078. e1000e_clear_hw_cntrs_base(hw);
  1079. er32(PRC64);
  1080. er32(PRC127);
  1081. er32(PRC255);
  1082. er32(PRC511);
  1083. er32(PRC1023);
  1084. er32(PRC1522);
  1085. er32(PTC64);
  1086. er32(PTC127);
  1087. er32(PTC255);
  1088. er32(PTC511);
  1089. er32(PTC1023);
  1090. er32(PTC1522);
  1091. er32(ALGNERRC);
  1092. er32(RXERRC);
  1093. er32(TNCRS);
  1094. er32(CEXTERR);
  1095. er32(TSCTC);
  1096. er32(TSCTFC);
  1097. er32(MGTPRC);
  1098. er32(MGTPDC);
  1099. er32(MGTPTC);
  1100. er32(IAC);
  1101. er32(ICRXOC);
  1102. er32(ICRXPTC);
  1103. er32(ICRXATC);
  1104. er32(ICTXPTC);
  1105. er32(ICTXATC);
  1106. er32(ICTXQEC);
  1107. er32(ICTXQMTC);
  1108. er32(ICRXDMTC);
  1109. }
  1110. static const struct e1000_mac_operations es2_mac_ops = {
  1111. .read_mac_addr = e1000_read_mac_addr_80003es2lan,
  1112. .id_led_init = e1000e_id_led_init_generic,
  1113. .blink_led = e1000e_blink_led_generic,
  1114. .check_mng_mode = e1000e_check_mng_mode_generic,
  1115. /* check_for_link dependent on media type */
  1116. .cleanup_led = e1000e_cleanup_led_generic,
  1117. .clear_hw_cntrs = e1000_clear_hw_cntrs_80003es2lan,
  1118. .get_bus_info = e1000e_get_bus_info_pcie,
  1119. .set_lan_id = e1000_set_lan_id_multi_port_pcie,
  1120. .get_link_up_info = e1000_get_link_up_info_80003es2lan,
  1121. .led_on = e1000e_led_on_generic,
  1122. .led_off = e1000e_led_off_generic,
  1123. .update_mc_addr_list = e1000e_update_mc_addr_list_generic,
  1124. .write_vfta = e1000_write_vfta_generic,
  1125. .clear_vfta = e1000_clear_vfta_generic,
  1126. .reset_hw = e1000_reset_hw_80003es2lan,
  1127. .init_hw = e1000_init_hw_80003es2lan,
  1128. .setup_link = e1000e_setup_link_generic,
  1129. /* setup_physical_interface dependent on media type */
  1130. .setup_led = e1000e_setup_led_generic,
  1131. .config_collision_dist = e1000e_config_collision_dist_generic,
  1132. .rar_set = e1000e_rar_set_generic,
  1133. .rar_get_count = e1000e_rar_get_count_generic,
  1134. };
  1135. static const struct e1000_phy_operations es2_phy_ops = {
  1136. .acquire = e1000_acquire_phy_80003es2lan,
  1137. .check_polarity = e1000_check_polarity_m88,
  1138. .check_reset_block = e1000e_check_reset_block_generic,
  1139. .commit = e1000e_phy_sw_reset,
  1140. .force_speed_duplex = e1000_phy_force_speed_duplex_80003es2lan,
  1141. .get_cfg_done = e1000_get_cfg_done_80003es2lan,
  1142. .get_cable_length = e1000_get_cable_length_80003es2lan,
  1143. .get_info = e1000e_get_phy_info_m88,
  1144. .read_reg = e1000_read_phy_reg_gg82563_80003es2lan,
  1145. .release = e1000_release_phy_80003es2lan,
  1146. .reset = e1000e_phy_hw_reset_generic,
  1147. .set_d0_lplu_state = NULL,
  1148. .set_d3_lplu_state = e1000e_set_d3_lplu_state,
  1149. .write_reg = e1000_write_phy_reg_gg82563_80003es2lan,
  1150. .cfg_on_link_up = e1000_cfg_on_link_up_80003es2lan,
  1151. };
  1152. static const struct e1000_nvm_operations es2_nvm_ops = {
  1153. .acquire = e1000_acquire_nvm_80003es2lan,
  1154. .read = e1000e_read_nvm_eerd,
  1155. .release = e1000_release_nvm_80003es2lan,
  1156. .reload = e1000e_reload_nvm_generic,
  1157. .update = e1000e_update_nvm_checksum_generic,
  1158. .valid_led_default = e1000e_valid_led_default,
  1159. .validate = e1000e_validate_nvm_checksum_generic,
  1160. .write = e1000_write_nvm_80003es2lan,
  1161. };
  1162. const struct e1000_info e1000_es2_info = {
  1163. .mac = e1000_80003es2lan,
  1164. .flags = FLAG_HAS_HW_VLAN_FILTER
  1165. | FLAG_HAS_JUMBO_FRAMES
  1166. | FLAG_HAS_WOL
  1167. | FLAG_APME_IN_CTRL3
  1168. | FLAG_HAS_CTRLEXT_ON_LOAD
  1169. | FLAG_RX_NEEDS_RESTART /* errata */
  1170. | FLAG_TARC_SET_BIT_ZERO /* errata */
  1171. | FLAG_APME_CHECK_PORT_B
  1172. | FLAG_DISABLE_FC_PAUSE_TIME, /* errata */
  1173. .flags2 = FLAG2_DMA_BURST,
  1174. .pba = 38,
  1175. .max_hw_frame_size = DEFAULT_JUMBO,
  1176. .get_variants = e1000_get_variants_80003es2lan,
  1177. .mac_ops = &es2_mac_ops,
  1178. .phy_ops = &es2_phy_ops,
  1179. .nvm_ops = &es2_nvm_ops,
  1180. };