80003es2lan.c 37 KB

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