ixgb_hw.c 37 KB

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