ixgb_hw.c 38 KB

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