ixgb_hw.c 37 KB

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