ixgb_hw.c 37 KB

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