80003es2lan.c 40 KB

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