80003es2lan.c 36 KB

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