ixgb_hw.c 37 KB

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