ixgb_hw.c 38 KB

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