80003es2lan.c 36 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401
  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. };