ixgb_hw.c 37 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238
  1. // SPDX-License-Identifier: GPL-2.0
  2. /* Copyright(c) 1999 - 2008 Intel Corporation. */
  3. /* ixgb_hw.c
  4. * Shared functions for accessing and configuring the adapter
  5. */
  6. #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
  7. #include <linux/pci_ids.h>
  8. #include "ixgb_hw.h"
  9. #include "ixgb_ids.h"
  10. #include <linux/etherdevice.h>
  11. /* Local function prototypes */
  12. static u32 ixgb_hash_mc_addr(struct ixgb_hw *hw, u8 * mc_addr);
  13. static void ixgb_mta_set(struct ixgb_hw *hw, u32 hash_value);
  14. static void ixgb_get_bus_info(struct ixgb_hw *hw);
  15. static bool ixgb_link_reset(struct ixgb_hw *hw);
  16. static void ixgb_optics_reset(struct ixgb_hw *hw);
  17. static void ixgb_optics_reset_bcm(struct ixgb_hw *hw);
  18. static ixgb_phy_type ixgb_identify_phy(struct ixgb_hw *hw);
  19. static void ixgb_clear_hw_cntrs(struct ixgb_hw *hw);
  20. static void ixgb_clear_vfta(struct ixgb_hw *hw);
  21. static void ixgb_init_rx_addrs(struct ixgb_hw *hw);
  22. static u16 ixgb_read_phy_reg(struct ixgb_hw *hw,
  23. u32 reg_address,
  24. u32 phy_address,
  25. u32 device_type);
  26. static bool ixgb_setup_fc(struct ixgb_hw *hw);
  27. static bool mac_addr_valid(u8 *mac_addr);
  28. static u32 ixgb_mac_reset(struct ixgb_hw *hw)
  29. {
  30. u32 ctrl_reg;
  31. ctrl_reg = IXGB_CTRL0_RST |
  32. IXGB_CTRL0_SDP3_DIR | /* All pins are Output=1 */
  33. IXGB_CTRL0_SDP2_DIR |
  34. IXGB_CTRL0_SDP1_DIR |
  35. IXGB_CTRL0_SDP0_DIR |
  36. IXGB_CTRL0_SDP3 | /* Initial value 1101 */
  37. IXGB_CTRL0_SDP2 |
  38. IXGB_CTRL0_SDP0;
  39. #ifdef HP_ZX1
  40. /* Workaround for 82597EX reset errata */
  41. IXGB_WRITE_REG_IO(hw, CTRL0, ctrl_reg);
  42. #else
  43. IXGB_WRITE_REG(hw, CTRL0, ctrl_reg);
  44. #endif
  45. /* Delay a few ms just to allow the reset to complete */
  46. msleep(IXGB_DELAY_AFTER_RESET);
  47. ctrl_reg = IXGB_READ_REG(hw, CTRL0);
  48. #ifdef DBG
  49. /* Make sure the self-clearing global reset bit did self clear */
  50. ASSERT(!(ctrl_reg & IXGB_CTRL0_RST));
  51. #endif
  52. if (hw->subsystem_vendor_id == PCI_VENDOR_ID_SUN) {
  53. ctrl_reg = /* Enable interrupt from XFP and SerDes */
  54. IXGB_CTRL1_GPI0_EN |
  55. IXGB_CTRL1_SDP6_DIR |
  56. IXGB_CTRL1_SDP7_DIR |
  57. IXGB_CTRL1_SDP6 |
  58. IXGB_CTRL1_SDP7;
  59. IXGB_WRITE_REG(hw, CTRL1, ctrl_reg);
  60. ixgb_optics_reset_bcm(hw);
  61. }
  62. if (hw->phy_type == ixgb_phy_type_txn17401)
  63. ixgb_optics_reset(hw);
  64. return ctrl_reg;
  65. }
  66. /******************************************************************************
  67. * Reset the transmit and receive units; mask and clear all interrupts.
  68. *
  69. * hw - Struct containing variables accessed by shared code
  70. *****************************************************************************/
  71. bool
  72. ixgb_adapter_stop(struct ixgb_hw *hw)
  73. {
  74. u32 ctrl_reg;
  75. u32 icr_reg;
  76. ENTER();
  77. /* If we are stopped or resetting exit gracefully and wait to be
  78. * started again before accessing the hardware.
  79. */
  80. if (hw->adapter_stopped) {
  81. pr_debug("Exiting because the adapter is already stopped!!!\n");
  82. return false;
  83. }
  84. /* Set the Adapter Stopped flag so other driver functions stop
  85. * touching the Hardware.
  86. */
  87. hw->adapter_stopped = true;
  88. /* Clear interrupt mask to stop board from generating interrupts */
  89. pr_debug("Masking off all interrupts\n");
  90. IXGB_WRITE_REG(hw, IMC, 0xFFFFFFFF);
  91. /* Disable the Transmit and Receive units. Then delay to allow
  92. * any pending transactions to complete before we hit the MAC with
  93. * the global reset.
  94. */
  95. IXGB_WRITE_REG(hw, RCTL, IXGB_READ_REG(hw, RCTL) & ~IXGB_RCTL_RXEN);
  96. IXGB_WRITE_REG(hw, TCTL, IXGB_READ_REG(hw, TCTL) & ~IXGB_TCTL_TXEN);
  97. IXGB_WRITE_FLUSH(hw);
  98. msleep(IXGB_DELAY_BEFORE_RESET);
  99. /* Issue a global reset to the MAC. This will reset the chip's
  100. * transmit, receive, DMA, and link units. It will not effect
  101. * the current PCI configuration. The global reset bit is self-
  102. * clearing, and should clear within a microsecond.
  103. */
  104. pr_debug("Issuing a global reset to MAC\n");
  105. ctrl_reg = ixgb_mac_reset(hw);
  106. /* Clear interrupt mask to stop board from generating interrupts */
  107. pr_debug("Masking off all interrupts\n");
  108. IXGB_WRITE_REG(hw, IMC, 0xffffffff);
  109. /* Clear any pending interrupt events. */
  110. icr_reg = IXGB_READ_REG(hw, ICR);
  111. return ctrl_reg & IXGB_CTRL0_RST;
  112. }
  113. /******************************************************************************
  114. * Identifies the vendor of the optics module on the adapter. The SR adapters
  115. * support two different types of XPAK optics, so it is necessary to determine
  116. * which optics are present before applying any optics-specific workarounds.
  117. *
  118. * hw - Struct containing variables accessed by shared code.
  119. *
  120. * Returns: the vendor of the XPAK optics module.
  121. *****************************************************************************/
  122. static ixgb_xpak_vendor
  123. ixgb_identify_xpak_vendor(struct ixgb_hw *hw)
  124. {
  125. u32 i;
  126. u16 vendor_name[5];
  127. ixgb_xpak_vendor xpak_vendor;
  128. ENTER();
  129. /* Read the first few bytes of the vendor string from the XPAK NVR
  130. * registers. These are standard XENPAK/XPAK registers, so all XPAK
  131. * devices should implement them. */
  132. for (i = 0; i < 5; i++) {
  133. vendor_name[i] = ixgb_read_phy_reg(hw,
  134. MDIO_PMA_PMD_XPAK_VENDOR_NAME
  135. + i, IXGB_PHY_ADDRESS,
  136. MDIO_MMD_PMAPMD);
  137. }
  138. /* Determine the actual vendor */
  139. if (vendor_name[0] == 'I' &&
  140. vendor_name[1] == 'N' &&
  141. vendor_name[2] == 'T' &&
  142. vendor_name[3] == 'E' && vendor_name[4] == 'L') {
  143. xpak_vendor = ixgb_xpak_vendor_intel;
  144. } else {
  145. xpak_vendor = ixgb_xpak_vendor_infineon;
  146. }
  147. return xpak_vendor;
  148. }
  149. /******************************************************************************
  150. * Determine the physical layer module on the adapter.
  151. *
  152. * hw - Struct containing variables accessed by shared code. The device_id
  153. * field must be (correctly) populated before calling this routine.
  154. *
  155. * Returns: the phy type of the adapter.
  156. *****************************************************************************/
  157. static ixgb_phy_type
  158. ixgb_identify_phy(struct ixgb_hw *hw)
  159. {
  160. ixgb_phy_type phy_type;
  161. ixgb_xpak_vendor xpak_vendor;
  162. ENTER();
  163. /* Infer the transceiver/phy type from the device id */
  164. switch (hw->device_id) {
  165. case IXGB_DEVICE_ID_82597EX:
  166. pr_debug("Identified TXN17401 optics\n");
  167. phy_type = ixgb_phy_type_txn17401;
  168. break;
  169. case IXGB_DEVICE_ID_82597EX_SR:
  170. /* The SR adapters carry two different types of XPAK optics
  171. * modules; read the vendor identifier to determine the exact
  172. * type of optics. */
  173. xpak_vendor = ixgb_identify_xpak_vendor(hw);
  174. if (xpak_vendor == ixgb_xpak_vendor_intel) {
  175. pr_debug("Identified TXN17201 optics\n");
  176. phy_type = ixgb_phy_type_txn17201;
  177. } else {
  178. pr_debug("Identified G6005 optics\n");
  179. phy_type = ixgb_phy_type_g6005;
  180. }
  181. break;
  182. case IXGB_DEVICE_ID_82597EX_LR:
  183. pr_debug("Identified G6104 optics\n");
  184. phy_type = ixgb_phy_type_g6104;
  185. break;
  186. case IXGB_DEVICE_ID_82597EX_CX4:
  187. pr_debug("Identified CX4\n");
  188. xpak_vendor = ixgb_identify_xpak_vendor(hw);
  189. if (xpak_vendor == ixgb_xpak_vendor_intel) {
  190. pr_debug("Identified TXN17201 optics\n");
  191. phy_type = ixgb_phy_type_txn17201;
  192. } else {
  193. pr_debug("Identified G6005 optics\n");
  194. phy_type = ixgb_phy_type_g6005;
  195. }
  196. break;
  197. default:
  198. pr_debug("Unknown physical layer module\n");
  199. phy_type = ixgb_phy_type_unknown;
  200. break;
  201. }
  202. /* update phy type for sun specific board */
  203. if (hw->subsystem_vendor_id == PCI_VENDOR_ID_SUN)
  204. phy_type = ixgb_phy_type_bcm;
  205. return phy_type;
  206. }
  207. /******************************************************************************
  208. * Performs basic configuration of the adapter.
  209. *
  210. * hw - Struct containing variables accessed by shared code
  211. *
  212. * Resets the controller.
  213. * Reads and validates the EEPROM.
  214. * Initializes the receive address registers.
  215. * Initializes the multicast table.
  216. * Clears all on-chip counters.
  217. * Calls routine to setup flow control settings.
  218. * Leaves the transmit and receive units disabled and uninitialized.
  219. *
  220. * Returns:
  221. * true if successful,
  222. * false if unrecoverable problems were encountered.
  223. *****************************************************************************/
  224. bool
  225. ixgb_init_hw(struct ixgb_hw *hw)
  226. {
  227. u32 i;
  228. u32 ctrl_reg;
  229. bool status;
  230. ENTER();
  231. /* Issue a global reset to the MAC. This will reset the chip's
  232. * transmit, receive, DMA, and link units. It will not effect
  233. * the current PCI configuration. The global reset bit is self-
  234. * clearing, and should clear within a microsecond.
  235. */
  236. pr_debug("Issuing a global reset to MAC\n");
  237. ctrl_reg = ixgb_mac_reset(hw);
  238. pr_debug("Issuing an EE reset to MAC\n");
  239. #ifdef HP_ZX1
  240. /* Workaround for 82597EX reset errata */
  241. IXGB_WRITE_REG_IO(hw, CTRL1, IXGB_CTRL1_EE_RST);
  242. #else
  243. IXGB_WRITE_REG(hw, CTRL1, IXGB_CTRL1_EE_RST);
  244. #endif
  245. /* Delay a few ms just to allow the reset to complete */
  246. msleep(IXGB_DELAY_AFTER_EE_RESET);
  247. if (!ixgb_get_eeprom_data(hw))
  248. return false;
  249. /* Use the device id to determine the type of phy/transceiver. */
  250. hw->device_id = ixgb_get_ee_device_id(hw);
  251. hw->phy_type = ixgb_identify_phy(hw);
  252. /* Setup the receive addresses.
  253. * Receive Address Registers (RARs 0 - 15).
  254. */
  255. ixgb_init_rx_addrs(hw);
  256. /*
  257. * Check that a valid MAC address has been set.
  258. * If it is not valid, we fail hardware init.
  259. */
  260. if (!mac_addr_valid(hw->curr_mac_addr)) {
  261. pr_debug("MAC address invalid after ixgb_init_rx_addrs\n");
  262. return(false);
  263. }
  264. /* tell the routines in this file they can access hardware again */
  265. hw->adapter_stopped = false;
  266. /* Fill in the bus_info structure */
  267. ixgb_get_bus_info(hw);
  268. /* Zero out the Multicast HASH table */
  269. pr_debug("Zeroing the MTA\n");
  270. for (i = 0; i < IXGB_MC_TBL_SIZE; i++)
  271. IXGB_WRITE_REG_ARRAY(hw, MTA, i, 0);
  272. /* Zero out the VLAN Filter Table Array */
  273. ixgb_clear_vfta(hw);
  274. /* Zero all of the hardware counters */
  275. ixgb_clear_hw_cntrs(hw);
  276. /* Call a subroutine to setup flow control. */
  277. status = ixgb_setup_fc(hw);
  278. /* 82597EX errata: Call check-for-link in case lane deskew is locked */
  279. ixgb_check_for_link(hw);
  280. return status;
  281. }
  282. /******************************************************************************
  283. * Initializes receive address filters.
  284. *
  285. * hw - Struct containing variables accessed by shared code
  286. *
  287. * Places the MAC address in receive address register 0 and clears the rest
  288. * of the receive address registers. Clears the multicast table. Assumes
  289. * the receiver is in reset when the routine is called.
  290. *****************************************************************************/
  291. static void
  292. ixgb_init_rx_addrs(struct ixgb_hw *hw)
  293. {
  294. u32 i;
  295. ENTER();
  296. /*
  297. * If the current mac address is valid, assume it is a software override
  298. * to the permanent address.
  299. * Otherwise, use the permanent address from the eeprom.
  300. */
  301. if (!mac_addr_valid(hw->curr_mac_addr)) {
  302. /* Get the MAC address from the eeprom for later reference */
  303. ixgb_get_ee_mac_addr(hw, hw->curr_mac_addr);
  304. pr_debug("Keeping Permanent MAC Addr = %pM\n",
  305. hw->curr_mac_addr);
  306. } else {
  307. /* Setup the receive address. */
  308. pr_debug("Overriding MAC Address in RAR[0]\n");
  309. pr_debug("New MAC Addr = %pM\n", hw->curr_mac_addr);
  310. ixgb_rar_set(hw, hw->curr_mac_addr, 0);
  311. }
  312. /* Zero out the other 15 receive addresses. */
  313. pr_debug("Clearing RAR[1-15]\n");
  314. for (i = 1; i < IXGB_RAR_ENTRIES; i++) {
  315. /* Write high reg first to disable the AV bit first */
  316. IXGB_WRITE_REG_ARRAY(hw, RA, ((i << 1) + 1), 0);
  317. IXGB_WRITE_REG_ARRAY(hw, RA, (i << 1), 0);
  318. }
  319. }
  320. /******************************************************************************
  321. * Updates the MAC's list of multicast addresses.
  322. *
  323. * hw - Struct containing variables accessed by shared code
  324. * mc_addr_list - the list of new multicast addresses
  325. * mc_addr_count - number of addresses
  326. * pad - number of bytes between addresses in the list
  327. *
  328. * The given list replaces any existing list. Clears the last 15 receive
  329. * address registers and the multicast table. Uses receive address registers
  330. * for the first 15 multicast addresses, and hashes the rest into the
  331. * multicast table.
  332. *****************************************************************************/
  333. void
  334. ixgb_mc_addr_list_update(struct ixgb_hw *hw,
  335. u8 *mc_addr_list,
  336. u32 mc_addr_count,
  337. u32 pad)
  338. {
  339. u32 hash_value;
  340. u32 i;
  341. u32 rar_used_count = 1; /* RAR[0] is used for our MAC address */
  342. u8 *mca;
  343. ENTER();
  344. /* Set the new number of MC addresses that we are being requested to use. */
  345. hw->num_mc_addrs = mc_addr_count;
  346. /* Clear RAR[1-15] */
  347. pr_debug("Clearing RAR[1-15]\n");
  348. for (i = rar_used_count; i < IXGB_RAR_ENTRIES; i++) {
  349. IXGB_WRITE_REG_ARRAY(hw, RA, (i << 1), 0);
  350. IXGB_WRITE_REG_ARRAY(hw, RA, ((i << 1) + 1), 0);
  351. }
  352. /* Clear the MTA */
  353. pr_debug("Clearing MTA\n");
  354. for (i = 0; i < IXGB_MC_TBL_SIZE; i++)
  355. IXGB_WRITE_REG_ARRAY(hw, MTA, i, 0);
  356. /* Add the new addresses */
  357. mca = mc_addr_list;
  358. for (i = 0; i < mc_addr_count; i++) {
  359. pr_debug("Adding the multicast addresses:\n");
  360. pr_debug("MC Addr #%d = %pM\n", i, mca);
  361. /* Place this multicast address in the RAR if there is room, *
  362. * else put it in the MTA
  363. */
  364. if (rar_used_count < IXGB_RAR_ENTRIES) {
  365. ixgb_rar_set(hw, mca, rar_used_count);
  366. pr_debug("Added a multicast address to RAR[%d]\n", i);
  367. rar_used_count++;
  368. } else {
  369. hash_value = ixgb_hash_mc_addr(hw, mca);
  370. pr_debug("Hash value = 0x%03X\n", hash_value);
  371. ixgb_mta_set(hw, hash_value);
  372. }
  373. mca += ETH_ALEN + pad;
  374. }
  375. pr_debug("MC Update Complete\n");
  376. }
  377. /******************************************************************************
  378. * Hashes an address to determine its location in the multicast table
  379. *
  380. * hw - Struct containing variables accessed by shared code
  381. * mc_addr - the multicast address to hash
  382. *
  383. * Returns:
  384. * The hash value
  385. *****************************************************************************/
  386. static u32
  387. ixgb_hash_mc_addr(struct ixgb_hw *hw,
  388. u8 *mc_addr)
  389. {
  390. u32 hash_value = 0;
  391. ENTER();
  392. /* The portion of the address that is used for the hash table is
  393. * determined by the mc_filter_type setting.
  394. */
  395. switch (hw->mc_filter_type) {
  396. /* [0] [1] [2] [3] [4] [5]
  397. * 01 AA 00 12 34 56
  398. * LSB MSB - According to H/W docs */
  399. case 0:
  400. /* [47:36] i.e. 0x563 for above example address */
  401. hash_value =
  402. ((mc_addr[4] >> 4) | (((u16) mc_addr[5]) << 4));
  403. break;
  404. case 1: /* [46:35] i.e. 0xAC6 for above example address */
  405. hash_value =
  406. ((mc_addr[4] >> 3) | (((u16) mc_addr[5]) << 5));
  407. break;
  408. case 2: /* [45:34] i.e. 0x5D8 for above example address */
  409. hash_value =
  410. ((mc_addr[4] >> 2) | (((u16) mc_addr[5]) << 6));
  411. break;
  412. case 3: /* [43:32] i.e. 0x634 for above example address */
  413. hash_value = ((mc_addr[4]) | (((u16) mc_addr[5]) << 8));
  414. break;
  415. default:
  416. /* Invalid mc_filter_type, what should we do? */
  417. pr_debug("MC filter type param set incorrectly\n");
  418. ASSERT(0);
  419. break;
  420. }
  421. hash_value &= 0xFFF;
  422. return hash_value;
  423. }
  424. /******************************************************************************
  425. * Sets the bit in the multicast table corresponding to the hash value.
  426. *
  427. * hw - Struct containing variables accessed by shared code
  428. * hash_value - Multicast address hash value
  429. *****************************************************************************/
  430. static void
  431. ixgb_mta_set(struct ixgb_hw *hw,
  432. u32 hash_value)
  433. {
  434. u32 hash_bit, hash_reg;
  435. u32 mta_reg;
  436. /* The MTA is a register array of 128 32-bit registers.
  437. * It is treated like an array of 4096 bits. We want to set
  438. * bit BitArray[hash_value]. So we figure out what register
  439. * the bit is in, read it, OR in the new bit, then write
  440. * back the new value. The register is determined by the
  441. * upper 7 bits of the hash value and the bit within that
  442. * register are determined by the lower 5 bits of the value.
  443. */
  444. hash_reg = (hash_value >> 5) & 0x7F;
  445. hash_bit = hash_value & 0x1F;
  446. mta_reg = IXGB_READ_REG_ARRAY(hw, MTA, hash_reg);
  447. mta_reg |= (1 << hash_bit);
  448. IXGB_WRITE_REG_ARRAY(hw, MTA, hash_reg, mta_reg);
  449. }
  450. /******************************************************************************
  451. * Puts an ethernet address into a receive address register.
  452. *
  453. * hw - Struct containing variables accessed by shared code
  454. * addr - Address to put into receive address register
  455. * index - Receive address register to write
  456. *****************************************************************************/
  457. void
  458. ixgb_rar_set(struct ixgb_hw *hw,
  459. u8 *addr,
  460. u32 index)
  461. {
  462. u32 rar_low, rar_high;
  463. ENTER();
  464. /* HW expects these in little endian so we reverse the byte order
  465. * from network order (big endian) to little endian
  466. */
  467. rar_low = ((u32) addr[0] |
  468. ((u32)addr[1] << 8) |
  469. ((u32)addr[2] << 16) |
  470. ((u32)addr[3] << 24));
  471. rar_high = ((u32) addr[4] |
  472. ((u32)addr[5] << 8) |
  473. IXGB_RAH_AV);
  474. IXGB_WRITE_REG_ARRAY(hw, RA, (index << 1), rar_low);
  475. IXGB_WRITE_REG_ARRAY(hw, RA, ((index << 1) + 1), rar_high);
  476. }
  477. /******************************************************************************
  478. * Writes a value to the specified offset in the VLAN filter table.
  479. *
  480. * hw - Struct containing variables accessed by shared code
  481. * offset - Offset in VLAN filer table to write
  482. * value - Value to write into VLAN filter table
  483. *****************************************************************************/
  484. void
  485. ixgb_write_vfta(struct ixgb_hw *hw,
  486. u32 offset,
  487. u32 value)
  488. {
  489. IXGB_WRITE_REG_ARRAY(hw, VFTA, offset, value);
  490. }
  491. /******************************************************************************
  492. * Clears the VLAN filer table
  493. *
  494. * hw - Struct containing variables accessed by shared code
  495. *****************************************************************************/
  496. static void
  497. ixgb_clear_vfta(struct ixgb_hw *hw)
  498. {
  499. u32 offset;
  500. for (offset = 0; offset < IXGB_VLAN_FILTER_TBL_SIZE; offset++)
  501. IXGB_WRITE_REG_ARRAY(hw, VFTA, offset, 0);
  502. }
  503. /******************************************************************************
  504. * Configures the flow control settings based on SW configuration.
  505. *
  506. * hw - Struct containing variables accessed by shared code
  507. *****************************************************************************/
  508. static bool
  509. ixgb_setup_fc(struct ixgb_hw *hw)
  510. {
  511. u32 ctrl_reg;
  512. u32 pap_reg = 0; /* by default, assume no pause time */
  513. bool status = true;
  514. ENTER();
  515. /* Get the current control reg 0 settings */
  516. ctrl_reg = IXGB_READ_REG(hw, CTRL0);
  517. /* Clear the Receive Pause Enable and Transmit Pause Enable bits */
  518. ctrl_reg &= ~(IXGB_CTRL0_RPE | IXGB_CTRL0_TPE);
  519. /* The possible values of the "flow_control" parameter are:
  520. * 0: Flow control is completely disabled
  521. * 1: Rx flow control is enabled (we can receive pause frames
  522. * but not send pause frames).
  523. * 2: Tx flow control is enabled (we can send pause frames
  524. * but we do not support receiving pause frames).
  525. * 3: Both Rx and TX flow control (symmetric) are enabled.
  526. * other: Invalid.
  527. */
  528. switch (hw->fc.type) {
  529. case ixgb_fc_none: /* 0 */
  530. /* Set CMDC bit to disable Rx Flow control */
  531. ctrl_reg |= (IXGB_CTRL0_CMDC);
  532. break;
  533. case ixgb_fc_rx_pause: /* 1 */
  534. /* RX Flow control is enabled, and TX Flow control is
  535. * disabled.
  536. */
  537. ctrl_reg |= (IXGB_CTRL0_RPE);
  538. break;
  539. case ixgb_fc_tx_pause: /* 2 */
  540. /* TX Flow control is enabled, and RX Flow control is
  541. * disabled, by a software over-ride.
  542. */
  543. ctrl_reg |= (IXGB_CTRL0_TPE);
  544. pap_reg = hw->fc.pause_time;
  545. break;
  546. case ixgb_fc_full: /* 3 */
  547. /* Flow control (both RX and TX) is enabled by a software
  548. * over-ride.
  549. */
  550. ctrl_reg |= (IXGB_CTRL0_RPE | IXGB_CTRL0_TPE);
  551. pap_reg = hw->fc.pause_time;
  552. break;
  553. default:
  554. /* We should never get here. The value should be 0-3. */
  555. pr_debug("Flow control param set incorrectly\n");
  556. ASSERT(0);
  557. break;
  558. }
  559. /* Write the new settings */
  560. IXGB_WRITE_REG(hw, CTRL0, ctrl_reg);
  561. if (pap_reg != 0)
  562. IXGB_WRITE_REG(hw, PAP, pap_reg);
  563. /* Set the flow control receive threshold registers. Normally,
  564. * these registers will be set to a default threshold that may be
  565. * adjusted later by the driver's runtime code. However, if the
  566. * ability to transmit pause frames in not enabled, then these
  567. * registers will be set to 0.
  568. */
  569. if (!(hw->fc.type & ixgb_fc_tx_pause)) {
  570. IXGB_WRITE_REG(hw, FCRTL, 0);
  571. IXGB_WRITE_REG(hw, FCRTH, 0);
  572. } else {
  573. /* We need to set up the Receive Threshold high and low water
  574. * marks as well as (optionally) enabling the transmission of XON
  575. * frames. */
  576. if (hw->fc.send_xon) {
  577. IXGB_WRITE_REG(hw, FCRTL,
  578. (hw->fc.low_water | IXGB_FCRTL_XONE));
  579. } else {
  580. IXGB_WRITE_REG(hw, FCRTL, hw->fc.low_water);
  581. }
  582. IXGB_WRITE_REG(hw, FCRTH, hw->fc.high_water);
  583. }
  584. return status;
  585. }
  586. /******************************************************************************
  587. * Reads a word from a device over the Management Data Interface (MDI) bus.
  588. * This interface is used to manage Physical layer devices.
  589. *
  590. * hw - Struct containing variables accessed by hw code
  591. * reg_address - Offset of device register being read.
  592. * phy_address - Address of device on MDI.
  593. *
  594. * Returns: Data word (16 bits) from MDI device.
  595. *
  596. * The 82597EX has support for several MDI access methods. This routine
  597. * uses the new protocol MDI Single Command and Address Operation.
  598. * This requires that first an address cycle command is sent, followed by a
  599. * read command.
  600. *****************************************************************************/
  601. static u16
  602. ixgb_read_phy_reg(struct ixgb_hw *hw,
  603. u32 reg_address,
  604. u32 phy_address,
  605. u32 device_type)
  606. {
  607. u32 i;
  608. u32 data;
  609. u32 command = 0;
  610. ASSERT(reg_address <= IXGB_MAX_PHY_REG_ADDRESS);
  611. ASSERT(phy_address <= IXGB_MAX_PHY_ADDRESS);
  612. ASSERT(device_type <= IXGB_MAX_PHY_DEV_TYPE);
  613. /* Setup and write the address cycle command */
  614. command = ((reg_address << IXGB_MSCA_NP_ADDR_SHIFT) |
  615. (device_type << IXGB_MSCA_DEV_TYPE_SHIFT) |
  616. (phy_address << IXGB_MSCA_PHY_ADDR_SHIFT) |
  617. (IXGB_MSCA_ADDR_CYCLE | IXGB_MSCA_MDI_COMMAND));
  618. IXGB_WRITE_REG(hw, MSCA, command);
  619. /**************************************************************
  620. ** Check every 10 usec to see if the address cycle completed
  621. ** The COMMAND bit will clear when the operation is complete.
  622. ** This may take as long as 64 usecs (we'll wait 100 usecs max)
  623. ** from the CPU Write to the Ready bit assertion.
  624. **************************************************************/
  625. for (i = 0; i < 10; i++)
  626. {
  627. udelay(10);
  628. command = IXGB_READ_REG(hw, MSCA);
  629. if ((command & IXGB_MSCA_MDI_COMMAND) == 0)
  630. break;
  631. }
  632. ASSERT((command & IXGB_MSCA_MDI_COMMAND) == 0);
  633. /* Address cycle complete, setup and write the read command */
  634. command = ((reg_address << IXGB_MSCA_NP_ADDR_SHIFT) |
  635. (device_type << IXGB_MSCA_DEV_TYPE_SHIFT) |
  636. (phy_address << IXGB_MSCA_PHY_ADDR_SHIFT) |
  637. (IXGB_MSCA_READ | IXGB_MSCA_MDI_COMMAND));
  638. IXGB_WRITE_REG(hw, MSCA, command);
  639. /**************************************************************
  640. ** Check every 10 usec to see if the read command completed
  641. ** The COMMAND bit will clear when the operation is complete.
  642. ** The read may take as long as 64 usecs (we'll wait 100 usecs max)
  643. ** from the CPU Write to the Ready bit assertion.
  644. **************************************************************/
  645. for (i = 0; i < 10; i++)
  646. {
  647. udelay(10);
  648. command = IXGB_READ_REG(hw, MSCA);
  649. if ((command & IXGB_MSCA_MDI_COMMAND) == 0)
  650. break;
  651. }
  652. ASSERT((command & IXGB_MSCA_MDI_COMMAND) == 0);
  653. /* Operation is complete, get the data from the MDIO Read/Write Data
  654. * register and return.
  655. */
  656. data = IXGB_READ_REG(hw, MSRWD);
  657. data >>= IXGB_MSRWD_READ_DATA_SHIFT;
  658. return((u16) data);
  659. }
  660. /******************************************************************************
  661. * Writes a word to a device over the Management Data Interface (MDI) bus.
  662. * This interface is used to manage Physical layer devices.
  663. *
  664. * hw - Struct containing variables accessed by hw code
  665. * reg_address - Offset of device register being read.
  666. * phy_address - Address of device on MDI.
  667. * device_type - Also known as the Device ID or DID.
  668. * data - 16-bit value to be written
  669. *
  670. * Returns: void.
  671. *
  672. * The 82597EX has support for several MDI access methods. This routine
  673. * uses the new protocol MDI Single Command and Address Operation.
  674. * This requires that first an address cycle command is sent, followed by a
  675. * write command.
  676. *****************************************************************************/
  677. static void
  678. ixgb_write_phy_reg(struct ixgb_hw *hw,
  679. u32 reg_address,
  680. u32 phy_address,
  681. u32 device_type,
  682. u16 data)
  683. {
  684. u32 i;
  685. u32 command = 0;
  686. ASSERT(reg_address <= IXGB_MAX_PHY_REG_ADDRESS);
  687. ASSERT(phy_address <= IXGB_MAX_PHY_ADDRESS);
  688. ASSERT(device_type <= IXGB_MAX_PHY_DEV_TYPE);
  689. /* Put the data in the MDIO Read/Write Data register */
  690. IXGB_WRITE_REG(hw, MSRWD, (u32)data);
  691. /* Setup and write the address cycle command */
  692. command = ((reg_address << IXGB_MSCA_NP_ADDR_SHIFT) |
  693. (device_type << IXGB_MSCA_DEV_TYPE_SHIFT) |
  694. (phy_address << IXGB_MSCA_PHY_ADDR_SHIFT) |
  695. (IXGB_MSCA_ADDR_CYCLE | IXGB_MSCA_MDI_COMMAND));
  696. IXGB_WRITE_REG(hw, MSCA, command);
  697. /**************************************************************
  698. ** Check every 10 usec to see if the address cycle completed
  699. ** The COMMAND bit will clear when the operation is complete.
  700. ** This may take as long as 64 usecs (we'll wait 100 usecs max)
  701. ** from the CPU Write to the Ready bit assertion.
  702. **************************************************************/
  703. for (i = 0; i < 10; i++)
  704. {
  705. udelay(10);
  706. command = IXGB_READ_REG(hw, MSCA);
  707. if ((command & IXGB_MSCA_MDI_COMMAND) == 0)
  708. break;
  709. }
  710. ASSERT((command & IXGB_MSCA_MDI_COMMAND) == 0);
  711. /* Address cycle complete, setup and write the write command */
  712. command = ((reg_address << IXGB_MSCA_NP_ADDR_SHIFT) |
  713. (device_type << IXGB_MSCA_DEV_TYPE_SHIFT) |
  714. (phy_address << IXGB_MSCA_PHY_ADDR_SHIFT) |
  715. (IXGB_MSCA_WRITE | IXGB_MSCA_MDI_COMMAND));
  716. IXGB_WRITE_REG(hw, MSCA, command);
  717. /**************************************************************
  718. ** Check every 10 usec to see if the read command completed
  719. ** The COMMAND bit will clear when the operation is complete.
  720. ** The write may take as long as 64 usecs (we'll wait 100 usecs max)
  721. ** from the CPU Write to the Ready bit assertion.
  722. **************************************************************/
  723. for (i = 0; i < 10; i++)
  724. {
  725. udelay(10);
  726. command = IXGB_READ_REG(hw, MSCA);
  727. if ((command & IXGB_MSCA_MDI_COMMAND) == 0)
  728. break;
  729. }
  730. ASSERT((command & IXGB_MSCA_MDI_COMMAND) == 0);
  731. /* Operation is complete, return. */
  732. }
  733. /******************************************************************************
  734. * Checks to see if the link status of the hardware has changed.
  735. *
  736. * hw - Struct containing variables accessed by hw code
  737. *
  738. * Called by any function that needs to check the link status of the adapter.
  739. *****************************************************************************/
  740. void
  741. ixgb_check_for_link(struct ixgb_hw *hw)
  742. {
  743. u32 status_reg;
  744. u32 xpcss_reg;
  745. ENTER();
  746. xpcss_reg = IXGB_READ_REG(hw, XPCSS);
  747. status_reg = IXGB_READ_REG(hw, STATUS);
  748. if ((xpcss_reg & IXGB_XPCSS_ALIGN_STATUS) &&
  749. (status_reg & IXGB_STATUS_LU)) {
  750. hw->link_up = true;
  751. } else if (!(xpcss_reg & IXGB_XPCSS_ALIGN_STATUS) &&
  752. (status_reg & IXGB_STATUS_LU)) {
  753. pr_debug("XPCSS Not Aligned while Status:LU is set\n");
  754. hw->link_up = ixgb_link_reset(hw);
  755. } else {
  756. /*
  757. * 82597EX errata. Since the lane deskew problem may prevent
  758. * link, reset the link before reporting link down.
  759. */
  760. hw->link_up = ixgb_link_reset(hw);
  761. }
  762. /* Anything else for 10 Gig?? */
  763. }
  764. /******************************************************************************
  765. * Check for a bad link condition that may have occurred.
  766. * The indication is that the RFC / LFC registers may be incrementing
  767. * continually. A full adapter reset is required to recover.
  768. *
  769. * hw - Struct containing variables accessed by hw code
  770. *
  771. * Called by any function that needs to check the link status of the adapter.
  772. *****************************************************************************/
  773. bool ixgb_check_for_bad_link(struct ixgb_hw *hw)
  774. {
  775. u32 newLFC, newRFC;
  776. bool bad_link_returncode = false;
  777. if (hw->phy_type == ixgb_phy_type_txn17401) {
  778. newLFC = IXGB_READ_REG(hw, LFC);
  779. newRFC = IXGB_READ_REG(hw, RFC);
  780. if ((hw->lastLFC + 250 < newLFC)
  781. || (hw->lastRFC + 250 < newRFC)) {
  782. pr_debug("BAD LINK! too many LFC/RFC since last check\n");
  783. bad_link_returncode = true;
  784. }
  785. hw->lastLFC = newLFC;
  786. hw->lastRFC = newRFC;
  787. }
  788. return bad_link_returncode;
  789. }
  790. /******************************************************************************
  791. * Clears all hardware statistics counters.
  792. *
  793. * hw - Struct containing variables accessed by shared code
  794. *****************************************************************************/
  795. static void
  796. ixgb_clear_hw_cntrs(struct ixgb_hw *hw)
  797. {
  798. volatile u32 temp_reg;
  799. ENTER();
  800. /* if we are stopped or resetting exit gracefully */
  801. if (hw->adapter_stopped) {
  802. pr_debug("Exiting because the adapter is stopped!!!\n");
  803. return;
  804. }
  805. temp_reg = IXGB_READ_REG(hw, TPRL);
  806. temp_reg = IXGB_READ_REG(hw, TPRH);
  807. temp_reg = IXGB_READ_REG(hw, GPRCL);
  808. temp_reg = IXGB_READ_REG(hw, GPRCH);
  809. temp_reg = IXGB_READ_REG(hw, BPRCL);
  810. temp_reg = IXGB_READ_REG(hw, BPRCH);
  811. temp_reg = IXGB_READ_REG(hw, MPRCL);
  812. temp_reg = IXGB_READ_REG(hw, MPRCH);
  813. temp_reg = IXGB_READ_REG(hw, UPRCL);
  814. temp_reg = IXGB_READ_REG(hw, UPRCH);
  815. temp_reg = IXGB_READ_REG(hw, VPRCL);
  816. temp_reg = IXGB_READ_REG(hw, VPRCH);
  817. temp_reg = IXGB_READ_REG(hw, JPRCL);
  818. temp_reg = IXGB_READ_REG(hw, JPRCH);
  819. temp_reg = IXGB_READ_REG(hw, GORCL);
  820. temp_reg = IXGB_READ_REG(hw, GORCH);
  821. temp_reg = IXGB_READ_REG(hw, TORL);
  822. temp_reg = IXGB_READ_REG(hw, TORH);
  823. temp_reg = IXGB_READ_REG(hw, RNBC);
  824. temp_reg = IXGB_READ_REG(hw, RUC);
  825. temp_reg = IXGB_READ_REG(hw, ROC);
  826. temp_reg = IXGB_READ_REG(hw, RLEC);
  827. temp_reg = IXGB_READ_REG(hw, CRCERRS);
  828. temp_reg = IXGB_READ_REG(hw, ICBC);
  829. temp_reg = IXGB_READ_REG(hw, ECBC);
  830. temp_reg = IXGB_READ_REG(hw, MPC);
  831. temp_reg = IXGB_READ_REG(hw, TPTL);
  832. temp_reg = IXGB_READ_REG(hw, TPTH);
  833. temp_reg = IXGB_READ_REG(hw, GPTCL);
  834. temp_reg = IXGB_READ_REG(hw, GPTCH);
  835. temp_reg = IXGB_READ_REG(hw, BPTCL);
  836. temp_reg = IXGB_READ_REG(hw, BPTCH);
  837. temp_reg = IXGB_READ_REG(hw, MPTCL);
  838. temp_reg = IXGB_READ_REG(hw, MPTCH);
  839. temp_reg = IXGB_READ_REG(hw, UPTCL);
  840. temp_reg = IXGB_READ_REG(hw, UPTCH);
  841. temp_reg = IXGB_READ_REG(hw, VPTCL);
  842. temp_reg = IXGB_READ_REG(hw, VPTCH);
  843. temp_reg = IXGB_READ_REG(hw, JPTCL);
  844. temp_reg = IXGB_READ_REG(hw, JPTCH);
  845. temp_reg = IXGB_READ_REG(hw, GOTCL);
  846. temp_reg = IXGB_READ_REG(hw, GOTCH);
  847. temp_reg = IXGB_READ_REG(hw, TOTL);
  848. temp_reg = IXGB_READ_REG(hw, TOTH);
  849. temp_reg = IXGB_READ_REG(hw, DC);
  850. temp_reg = IXGB_READ_REG(hw, PLT64C);
  851. temp_reg = IXGB_READ_REG(hw, TSCTC);
  852. temp_reg = IXGB_READ_REG(hw, TSCTFC);
  853. temp_reg = IXGB_READ_REG(hw, IBIC);
  854. temp_reg = IXGB_READ_REG(hw, RFC);
  855. temp_reg = IXGB_READ_REG(hw, LFC);
  856. temp_reg = IXGB_READ_REG(hw, PFRC);
  857. temp_reg = IXGB_READ_REG(hw, PFTC);
  858. temp_reg = IXGB_READ_REG(hw, MCFRC);
  859. temp_reg = IXGB_READ_REG(hw, MCFTC);
  860. temp_reg = IXGB_READ_REG(hw, XONRXC);
  861. temp_reg = IXGB_READ_REG(hw, XONTXC);
  862. temp_reg = IXGB_READ_REG(hw, XOFFRXC);
  863. temp_reg = IXGB_READ_REG(hw, XOFFTXC);
  864. temp_reg = IXGB_READ_REG(hw, RJC);
  865. }
  866. /******************************************************************************
  867. * Turns on the software controllable LED
  868. *
  869. * hw - Struct containing variables accessed by shared code
  870. *****************************************************************************/
  871. void
  872. ixgb_led_on(struct ixgb_hw *hw)
  873. {
  874. u32 ctrl0_reg = IXGB_READ_REG(hw, CTRL0);
  875. /* To turn on the LED, clear software-definable pin 0 (SDP0). */
  876. ctrl0_reg &= ~IXGB_CTRL0_SDP0;
  877. IXGB_WRITE_REG(hw, CTRL0, ctrl0_reg);
  878. }
  879. /******************************************************************************
  880. * Turns off the software controllable LED
  881. *
  882. * hw - Struct containing variables accessed by shared code
  883. *****************************************************************************/
  884. void
  885. ixgb_led_off(struct ixgb_hw *hw)
  886. {
  887. u32 ctrl0_reg = IXGB_READ_REG(hw, CTRL0);
  888. /* To turn off the LED, set software-definable pin 0 (SDP0). */
  889. ctrl0_reg |= IXGB_CTRL0_SDP0;
  890. IXGB_WRITE_REG(hw, CTRL0, ctrl0_reg);
  891. }
  892. /******************************************************************************
  893. * Gets the current PCI bus type, speed, and width of the hardware
  894. *
  895. * hw - Struct containing variables accessed by shared code
  896. *****************************************************************************/
  897. static void
  898. ixgb_get_bus_info(struct ixgb_hw *hw)
  899. {
  900. u32 status_reg;
  901. status_reg = IXGB_READ_REG(hw, STATUS);
  902. hw->bus.type = (status_reg & IXGB_STATUS_PCIX_MODE) ?
  903. ixgb_bus_type_pcix : ixgb_bus_type_pci;
  904. if (hw->bus.type == ixgb_bus_type_pci) {
  905. hw->bus.speed = (status_reg & IXGB_STATUS_PCI_SPD) ?
  906. ixgb_bus_speed_66 : ixgb_bus_speed_33;
  907. } else {
  908. switch (status_reg & IXGB_STATUS_PCIX_SPD_MASK) {
  909. case IXGB_STATUS_PCIX_SPD_66:
  910. hw->bus.speed = ixgb_bus_speed_66;
  911. break;
  912. case IXGB_STATUS_PCIX_SPD_100:
  913. hw->bus.speed = ixgb_bus_speed_100;
  914. break;
  915. case IXGB_STATUS_PCIX_SPD_133:
  916. hw->bus.speed = ixgb_bus_speed_133;
  917. break;
  918. default:
  919. hw->bus.speed = ixgb_bus_speed_reserved;
  920. break;
  921. }
  922. }
  923. hw->bus.width = (status_reg & IXGB_STATUS_BUS64) ?
  924. ixgb_bus_width_64 : ixgb_bus_width_32;
  925. }
  926. /******************************************************************************
  927. * Tests a MAC address to ensure it is a valid Individual Address
  928. *
  929. * mac_addr - pointer to MAC address.
  930. *
  931. *****************************************************************************/
  932. static bool
  933. mac_addr_valid(u8 *mac_addr)
  934. {
  935. bool is_valid = true;
  936. ENTER();
  937. /* Make sure it is not a multicast address */
  938. if (is_multicast_ether_addr(mac_addr)) {
  939. pr_debug("MAC address is multicast\n");
  940. is_valid = false;
  941. }
  942. /* Not a broadcast address */
  943. else if (is_broadcast_ether_addr(mac_addr)) {
  944. pr_debug("MAC address is broadcast\n");
  945. is_valid = false;
  946. }
  947. /* Reject the zero address */
  948. else if (is_zero_ether_addr(mac_addr)) {
  949. pr_debug("MAC address is all zeros\n");
  950. is_valid = false;
  951. }
  952. return is_valid;
  953. }
  954. /******************************************************************************
  955. * Resets the 10GbE link. Waits the settle time and returns the state of
  956. * the link.
  957. *
  958. * hw - Struct containing variables accessed by shared code
  959. *****************************************************************************/
  960. static bool
  961. ixgb_link_reset(struct ixgb_hw *hw)
  962. {
  963. bool link_status = false;
  964. u8 wait_retries = MAX_RESET_ITERATIONS;
  965. u8 lrst_retries = MAX_RESET_ITERATIONS;
  966. do {
  967. /* Reset the link */
  968. IXGB_WRITE_REG(hw, CTRL0,
  969. IXGB_READ_REG(hw, CTRL0) | IXGB_CTRL0_LRST);
  970. /* Wait for link-up and lane re-alignment */
  971. do {
  972. udelay(IXGB_DELAY_USECS_AFTER_LINK_RESET);
  973. link_status =
  974. ((IXGB_READ_REG(hw, STATUS) & IXGB_STATUS_LU)
  975. && (IXGB_READ_REG(hw, XPCSS) &
  976. IXGB_XPCSS_ALIGN_STATUS)) ? true : false;
  977. } while (!link_status && --wait_retries);
  978. } while (!link_status && --lrst_retries);
  979. return link_status;
  980. }
  981. /******************************************************************************
  982. * Resets the 10GbE optics module.
  983. *
  984. * hw - Struct containing variables accessed by shared code
  985. *****************************************************************************/
  986. static void
  987. ixgb_optics_reset(struct ixgb_hw *hw)
  988. {
  989. if (hw->phy_type == ixgb_phy_type_txn17401) {
  990. u16 mdio_reg;
  991. ixgb_write_phy_reg(hw,
  992. MDIO_CTRL1,
  993. IXGB_PHY_ADDRESS,
  994. MDIO_MMD_PMAPMD,
  995. MDIO_CTRL1_RESET);
  996. mdio_reg = ixgb_read_phy_reg(hw,
  997. MDIO_CTRL1,
  998. IXGB_PHY_ADDRESS,
  999. MDIO_MMD_PMAPMD);
  1000. }
  1001. }
  1002. /******************************************************************************
  1003. * Resets the 10GbE optics module for Sun variant NIC.
  1004. *
  1005. * hw - Struct containing variables accessed by shared code
  1006. *****************************************************************************/
  1007. #define IXGB_BCM8704_USER_PMD_TX_CTRL_REG 0xC803
  1008. #define IXGB_BCM8704_USER_PMD_TX_CTRL_REG_VAL 0x0164
  1009. #define IXGB_BCM8704_USER_CTRL_REG 0xC800
  1010. #define IXGB_BCM8704_USER_CTRL_REG_VAL 0x7FBF
  1011. #define IXGB_BCM8704_USER_DEV3_ADDR 0x0003
  1012. #define IXGB_SUN_PHY_ADDRESS 0x0000
  1013. #define IXGB_SUN_PHY_RESET_DELAY 305
  1014. static void
  1015. ixgb_optics_reset_bcm(struct ixgb_hw *hw)
  1016. {
  1017. u32 ctrl = IXGB_READ_REG(hw, CTRL0);
  1018. ctrl &= ~IXGB_CTRL0_SDP2;
  1019. ctrl |= IXGB_CTRL0_SDP3;
  1020. IXGB_WRITE_REG(hw, CTRL0, ctrl);
  1021. IXGB_WRITE_FLUSH(hw);
  1022. /* SerDes needs extra delay */
  1023. msleep(IXGB_SUN_PHY_RESET_DELAY);
  1024. /* Broadcom 7408L configuration */
  1025. /* Reference clock config */
  1026. ixgb_write_phy_reg(hw,
  1027. IXGB_BCM8704_USER_PMD_TX_CTRL_REG,
  1028. IXGB_SUN_PHY_ADDRESS,
  1029. IXGB_BCM8704_USER_DEV3_ADDR,
  1030. IXGB_BCM8704_USER_PMD_TX_CTRL_REG_VAL);
  1031. /* we must read the registers twice */
  1032. ixgb_read_phy_reg(hw,
  1033. IXGB_BCM8704_USER_PMD_TX_CTRL_REG,
  1034. IXGB_SUN_PHY_ADDRESS,
  1035. IXGB_BCM8704_USER_DEV3_ADDR);
  1036. ixgb_read_phy_reg(hw,
  1037. IXGB_BCM8704_USER_PMD_TX_CTRL_REG,
  1038. IXGB_SUN_PHY_ADDRESS,
  1039. IXGB_BCM8704_USER_DEV3_ADDR);
  1040. ixgb_write_phy_reg(hw,
  1041. IXGB_BCM8704_USER_CTRL_REG,
  1042. IXGB_SUN_PHY_ADDRESS,
  1043. IXGB_BCM8704_USER_DEV3_ADDR,
  1044. IXGB_BCM8704_USER_CTRL_REG_VAL);
  1045. ixgb_read_phy_reg(hw,
  1046. IXGB_BCM8704_USER_CTRL_REG,
  1047. IXGB_SUN_PHY_ADDRESS,
  1048. IXGB_BCM8704_USER_DEV3_ADDR);
  1049. ixgb_read_phy_reg(hw,
  1050. IXGB_BCM8704_USER_CTRL_REG,
  1051. IXGB_SUN_PHY_ADDRESS,
  1052. IXGB_BCM8704_USER_DEV3_ADDR);
  1053. /* SerDes needs extra delay */
  1054. msleep(IXGB_SUN_PHY_RESET_DELAY);
  1055. }