/kern_oII/drivers/net/ixgb/ixgb_hw.c

http://omnia2droid.googlecode.com/ · C · 1302 lines · 726 code · 185 blank · 391 comment · 90 complexity · dc47df5a19115398b4d6ef9244c261dc MD5 · raw file

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