80003es2lan.c 40 KB

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