es2lan.c 38 KB

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