80003es2lan.c 37 KB

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