ixgb_hw.c 37 KB

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