ixgb_hw.c 38 KB

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