1 /*******************************************************************************
3 Copyright (c) 2001-2007, Intel Corporation
6 Redistribution and use in source and binary forms, with or without
7 modification, are permitted provided that the following conditions are met:
9 1. Redistributions of source code must retain the above copyright notice,
10 this list of conditions and the following disclaimer.
12 2. Redistributions in binary form must reproduce the above copyright
13 notice, this list of conditions and the following disclaimer in the
14 documentation and/or other materials provided with the distribution.
16 3. Neither the name of the Intel Corporation nor the names of its
17 contributors may be used to endorse or promote products derived from
18 this software without specific prior written permission.
20 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23 ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
24 LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
25 CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
26 SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
27 INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
28 CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
29 ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
30 POSSIBILITY OF SUCH DAMAGE.
32 *******************************************************************************/
35 #include "ixgbe_api.h"
36 #include "ixgbe_common.h"
38 extern s32 ixgbe_init_shared_code_82598(struct ixgbe_hw *hw);
39 extern s32 ixgbe_init_shared_code_phy(struct ixgbe_hw *hw);
42 * ixgbe_init_shared_code - Initialize the shared code
43 * @hw: pointer to hardware structure
45 * This will assign function pointers and assign the MAC type and PHY code.
46 * Does not touch the hardware. This function must be called prior to any
47 * other function in the shared code. The ixgbe_hw structure should be
48 * memset to 0 prior to calling this function. The following fields in
49 * hw structure should be filled in prior to calling this function:
50 * hw_addr, back, device_id, vendor_id, subsystem_device_id,
51 * subsystem_vendor_id, and revision_id
53 s32 ixgbe_init_shared_code(struct ixgbe_hw *hw)
55 s32 status = IXGBE_ERR_DEVICE_NOT_SUPPORTED;
58 * Assign generic function pointers before entering adapter-specific
61 ixgbe_assign_func_pointers_generic(hw);
63 if (hw->vendor_id == IXGBE_INTEL_VENDOR_ID) {
64 switch (hw->device_id) {
65 case IXGBE_DEV_ID_82598:
66 case IXGBE_DEV_ID_82598_FPGA:
67 case IXGBE_DEV_ID_82598AF_SINGLE_PORT:
68 case IXGBE_DEV_ID_82598AF_DUAL_PORT:
69 case IXGBE_DEV_ID_82598AT_DUAL_PORT:
70 status = ixgbe_init_shared_code_82598(hw);
71 status = ixgbe_init_shared_code_phy(hw);
74 status = IXGBE_ERR_DEVICE_NOT_SUPPORTED;
83 * ixgbe_init_hw - Initialize the hardware
84 * @hw: pointer to hardware structure
86 * Initialize the hardware by resetting and then starting the hardware
88 s32 ixgbe_init_hw(struct ixgbe_hw *hw)
90 return ixgbe_call_func(hw, ixgbe_func_init_hw, (hw),
91 IXGBE_NOT_IMPLEMENTED);
95 * ixgbe_reset_hw - Performs a hardware reset
96 * @hw: pointer to hardware structure
98 * Resets the hardware by resetting the transmit and receive units, masks and
99 * clears all interrupts, performs a PHY reset, and performs a MAC reset
101 s32 ixgbe_reset_hw(struct ixgbe_hw *hw)
103 return ixgbe_call_func(hw, ixgbe_func_reset_hw, (hw),
104 IXGBE_NOT_IMPLEMENTED);
108 * ixgbe_start_hw - Prepares hardware for TX/TX
109 * @hw: pointer to hardware structure
111 * Starts the hardware by filling the bus info structure and media type,
112 * clears all on chip counters, initializes receive address registers,
113 * multicast table, VLAN filter table, calls routine to setup link and
114 * flow control settings, and leaves transmit and receive units disabled
117 s32 ixgbe_start_hw(struct ixgbe_hw *hw)
119 return ixgbe_call_func(hw, ixgbe_func_start_hw, (hw),
120 IXGBE_NOT_IMPLEMENTED);
124 * ixgbe_clear_hw_cntrs - Clear hardware counters
125 * @hw: pointer to hardware structure
127 * Clears all hardware statistics counters by reading them from the hardware
128 * Statistics counters are clear on read.
130 s32 ixgbe_clear_hw_cntrs(struct ixgbe_hw *hw)
132 return ixgbe_call_func(hw, ixgbe_func_clear_hw_cntrs, (hw),
133 IXGBE_NOT_IMPLEMENTED);
137 * ixgbe_get_media_type - Get media type
138 * @hw: pointer to hardware structure
140 * Returns the media type (fiber, copper, backplane)
142 enum ixgbe_media_type ixgbe_get_media_type(struct ixgbe_hw *hw)
144 return ixgbe_call_func(hw, ixgbe_func_get_media_type, (hw),
145 ixgbe_media_type_unknown);
149 * ixgbe_get_mac_addr - Get MAC address
150 * @hw: pointer to hardware structure
151 * @mac_addr: Adapter MAC address
153 * Reads the adapter's MAC address from the first Receive Address Register
154 * (RAR0) A reset of the adapter must have been performed prior to calling this
155 * function in order for the MAC address to have been loaded from the EEPROM
158 s32 ixgbe_get_mac_addr(struct ixgbe_hw *hw, u8 *mac_addr)
160 return ixgbe_call_func(hw, ixgbe_func_get_mac_addr,
161 (hw, mac_addr), IXGBE_NOT_IMPLEMENTED);
165 * ixgbe_get_bus_info - Set PCI bus info
166 * @hw: pointer to hardware structure
168 * Sets the PCI bus info (speed, width, type) within the ixgbe_hw structure
170 s32 ixgbe_get_bus_info(struct ixgbe_hw *hw)
172 return ixgbe_call_func(hw, ixgbe_func_get_bus_info, (hw),
173 IXGBE_NOT_IMPLEMENTED);
177 * ixgbe_get_num_of_tx_queues - Get TX queues
178 * @hw: pointer to hardware structure
180 * Returns the number of transmit queues for the given adapter.
182 u32 ixgbe_get_num_of_tx_queues(struct ixgbe_hw *hw)
184 return ixgbe_call_func(hw, ixgbe_func_get_num_of_tx_queues,
189 * ixgbe_get_num_of_rx_queues - Get RX queues
190 * @hw: pointer to hardware structure
192 * Returns the number of receive queues for the given adapter.
194 u32 ixgbe_get_num_of_rx_queues(struct ixgbe_hw *hw)
196 return ixgbe_call_func(hw, ixgbe_func_get_num_of_rx_queues,
201 * ixgbe_stop_adapter - Disable TX/TX units
202 * @hw: pointer to hardware structure
204 * Sets the adapter_stopped flag within ixgbe_hw struct. Clears interrupts,
205 * disables transmit and receive units. The adapter_stopped flag is used by
206 * the shared code and drivers to determine if the adapter is in a stopped
207 * state and should not touch the hardware.
209 s32 ixgbe_stop_adapter(struct ixgbe_hw *hw)
211 return ixgbe_call_func(hw, ixgbe_func_stop_adapter, (hw),
212 IXGBE_NOT_IMPLEMENTED);
216 * ixgbe_identify_phy - Get PHY type
217 * @hw: pointer to hardware structure
219 * Determines the physical layer module found on the current adapter.
221 s32 ixgbe_identify_phy(struct ixgbe_hw *hw)
223 s32 status = IXGBE_SUCCESS;
225 if (hw->phy.type == ixgbe_phy_unknown) {
226 status = ixgbe_call_func(hw,
227 ixgbe_func_identify_phy,
229 IXGBE_NOT_IMPLEMENTED);
236 * ixgbe_reset_phy - Perform a PHY reset
237 * @hw: pointer to hardware structure
239 s32 ixgbe_reset_phy(struct ixgbe_hw *hw)
241 s32 status = IXGBE_SUCCESS;
243 if (hw->phy.type == ixgbe_phy_unknown) {
244 if (ixgbe_identify_phy(hw) != IXGBE_SUCCESS) {
245 status = IXGBE_ERR_PHY;
249 if (status == IXGBE_SUCCESS) {
250 status = ixgbe_call_func(hw,
251 ixgbe_func_reset_phy,
253 IXGBE_NOT_IMPLEMENTED);
259 * ixgbe_read_phy_reg - Read PHY register
260 * @hw: pointer to hardware structure
261 * @reg_addr: 32 bit address of PHY register to read
262 * @phy_data: Pointer to read data from PHY register
264 * Reads a value from a specified PHY register
266 s32 ixgbe_read_phy_reg(struct ixgbe_hw *hw, u32 reg_addr, u32 device_type,
269 s32 status = IXGBE_SUCCESS;
271 if (hw->phy.type == ixgbe_phy_unknown) {
272 if (ixgbe_identify_phy(hw) != IXGBE_SUCCESS) {
273 status = IXGBE_ERR_PHY;
277 if (status == IXGBE_SUCCESS) {
278 status = ixgbe_call_func(hw,
279 ixgbe_func_read_phy_reg,
280 (hw, reg_addr, device_type, phy_data),
281 IXGBE_NOT_IMPLEMENTED);
287 * ixgbe_write_phy_reg - Write PHY register
288 * @hw: pointer to hardware structure
289 * @reg_addr: 32 bit PHY register to write
290 * @phy_data: Data to write to the PHY register
292 * Writes a value to specified PHY register
294 s32 ixgbe_write_phy_reg(struct ixgbe_hw *hw, u32 reg_addr, u32 device_type,
297 s32 status = IXGBE_SUCCESS;
299 if (hw->phy.type == ixgbe_phy_unknown) {
300 if (ixgbe_identify_phy(hw) != IXGBE_SUCCESS) {
301 status = IXGBE_ERR_PHY;
305 if (status == IXGBE_SUCCESS) {
306 status = ixgbe_call_func(hw,
307 ixgbe_func_write_phy_reg,
308 (hw, reg_addr, device_type, phy_data),
309 IXGBE_NOT_IMPLEMENTED);
315 * ixgbe_setup_link - Configure link settings
316 * @hw: pointer to hardware structure
318 * Configures link settings based on values in the ixgbe_hw struct.
319 * Restarts the link. Performs autonegotiation if needed.
321 s32 ixgbe_setup_link(struct ixgbe_hw *hw)
323 return ixgbe_call_func(hw, ixgbe_func_setup_link, (hw),
324 IXGBE_NOT_IMPLEMENTED);
328 * ixgbe_check_link - Get link and speed status
329 * @hw: pointer to hardware structure
331 * Reads the links register to determine if link is up and the current speed
333 s32 ixgbe_check_link(struct ixgbe_hw *hw, ixgbe_link_speed *speed,
336 return ixgbe_call_func(hw, ixgbe_func_check_link, (hw, speed, link_up),
337 IXGBE_NOT_IMPLEMENTED);
341 * ixgbe_setup_link_speed - Set link speed
342 * @hw: pointer to hardware structure
343 * @speed: new link speed
344 * @autoneg: TRUE if autonegotiation enabled
346 * Set the link speed and restarts the link.
348 s32 ixgbe_setup_link_speed(struct ixgbe_hw *hw, ixgbe_link_speed speed,
350 bool autoneg_wait_to_complete)
352 return ixgbe_call_func(hw, ixgbe_func_setup_link_speed, (hw, speed,
353 autoneg, autoneg_wait_to_complete),
354 IXGBE_NOT_IMPLEMENTED);
358 * ixgbe_get_link_settings - Set link settings to default
359 * @hw: pointer to hardware structure
361 * Sets the default link settings based on attach type in the hw struct.
363 s32 ixgbe_get_link_settings(struct ixgbe_hw *hw, ixgbe_link_speed *speed,
366 return ixgbe_call_func(hw, ixgbe_func_get_link_settings, (hw, speed,
367 autoneg), IXGBE_NOT_IMPLEMENTED);
371 * ixgbe_led_on - Turn on LED's
372 * @hw: pointer to hardware structure
373 * @index: led number to turn on
375 * Turns on the software controllable LEDs.
377 s32 ixgbe_led_on(struct ixgbe_hw *hw, u32 index)
379 return ixgbe_call_func(hw, ixgbe_func_led_on, (hw, index),
380 IXGBE_NOT_IMPLEMENTED);
384 * ixgbe_led_off - Turn off LED's
385 * @hw: pointer to hardware structure
386 * @index: led number to turn off
388 * Turns off the software controllable LEDs.
390 s32 ixgbe_led_off(struct ixgbe_hw *hw, u32 index)
392 return ixgbe_call_func(hw, ixgbe_func_led_off, (hw, index),
393 IXGBE_NOT_IMPLEMENTED);
397 * ixgbe_blink_led_start - Blink LED's
398 * @hw: pointer to hardware structure
399 * @index: led number to blink
401 * Blink LED based on index.
403 s32 ixgbe_blink_led_start(struct ixgbe_hw *hw, u32 index)
405 return ixgbe_call_func(hw, ixgbe_func_blink_led_start, (hw, index),
406 IXGBE_NOT_IMPLEMENTED);
410 * ixgbe_blink_led_stop - Stop blinking LED's
411 * @hw: pointer to hardware structure
413 * Stop blinking LED based on index.
415 s32 ixgbe_blink_led_stop(struct ixgbe_hw *hw, u32 index)
417 return ixgbe_call_func(hw, ixgbe_func_blink_led_stop, (hw, index),
418 IXGBE_NOT_IMPLEMENTED);
422 * ixgbe_init_eeprom_params - Initialiaze EEPROM parameters
423 * @hw: pointer to hardware structure
425 * Initializes the EEPROM parameters ixgbe_eeprom_info within the
426 * ixgbe_hw struct in order to set up EEPROM access.
428 s32 ixgbe_init_eeprom_params(struct ixgbe_hw *hw)
430 return ixgbe_call_func(hw, ixgbe_func_init_eeprom_params, (hw),
431 IXGBE_NOT_IMPLEMENTED);
436 * ixgbe_write_eeprom - Write word to EEPROM
437 * @hw: pointer to hardware structure
438 * @offset: offset within the EEPROM to be written to
439 * @data: 16 bit word to be written to the EEPROM
441 * Writes 16 bit value to EEPROM. If ixgbe_eeprom_update_checksum is not
442 * called after this function, the EEPROM will most likely contain an
445 s32 ixgbe_write_eeprom(struct ixgbe_hw *hw, u16 offset, u16 data)
450 * Initialize EEPROM parameters. This will not do anything if the
451 * EEPROM structure has already been initialized
453 ixgbe_init_eeprom_params(hw);
455 /* Check for invalid offset */
456 if (offset >= hw->eeprom.word_size) {
457 status = IXGBE_ERR_EEPROM;
459 status = ixgbe_call_func(hw,
460 ixgbe_func_write_eeprom,
462 IXGBE_NOT_IMPLEMENTED);
469 * ixgbe_read_eeprom - Read word from EEPROM
470 * @hw: pointer to hardware structure
471 * @offset: offset within the EEPROM to be read
472 * @data: read 16 bit value from EEPROM
474 * Reads 16 bit value from EEPROM
476 s32 ixgbe_read_eeprom(struct ixgbe_hw *hw, u16 offset, u16 *data)
481 * Initialize EEPROM parameters. This will not do anything if the
482 * EEPROM structure has already been initialized
484 ixgbe_init_eeprom_params(hw);
486 /* Check for invalid offset */
487 if (offset >= hw->eeprom.word_size) {
488 status = IXGBE_ERR_EEPROM;
490 status = ixgbe_call_func(hw,
491 ixgbe_func_read_eeprom,
493 IXGBE_NOT_IMPLEMENTED);
500 * ixgbe_validate_eeprom_checksum - Validate EEPROM checksum
501 * @hw: pointer to hardware structure
502 * @checksum_val: calculated checksum
504 * Performs checksum calculation and validates the EEPROM checksum
506 s32 ixgbe_validate_eeprom_checksum(struct ixgbe_hw *hw, u16 *checksum_val)
508 return ixgbe_call_func(hw, ixgbe_func_validate_eeprom_checksum,
509 (hw, checksum_val), IXGBE_NOT_IMPLEMENTED);
513 * ixgbe_eeprom_update_checksum - Updates the EEPROM checksum
514 * @hw: pointer to hardware structure
516 s32 ixgbe_update_eeprom_checksum(struct ixgbe_hw *hw)
518 return ixgbe_call_func(hw, ixgbe_func_update_eeprom_checksum, (hw),
519 IXGBE_NOT_IMPLEMENTED);
523 * ixgbe_set_rar - Set RX address register
524 * @hw: pointer to hardware structure
525 * @addr: Address to put into receive address register
526 * @index: Receive address register to write
527 * @vind: Vind to set RAR to
528 * @enable_addr: set flag that address is active
530 * Puts an ethernet address into a receive address register.
532 s32 ixgbe_set_rar(struct ixgbe_hw *hw, u32 index, u8 *addr, u32 vind,
535 return ixgbe_call_func(hw, ixgbe_func_set_rar, (hw, index, addr, vind,
536 enable_addr), IXGBE_NOT_IMPLEMENTED);
540 * ixgbe_init_rx_addrs - Initializes receive address filters.
541 * @hw: pointer to hardware structure
543 * Places the MAC address in receive address register 0 and clears the rest
544 * of the receive addresss registers. Clears the multicast table. Assumes
545 * the receiver is in reset when the routine is called.
547 s32 ixgbe_init_rx_addrs(struct ixgbe_hw *hw)
549 return ixgbe_call_func(hw, ixgbe_func_init_rx_addrs, (hw),
550 IXGBE_NOT_IMPLEMENTED);
554 * ixgbe_get_num_rx_addrs - Returns the number of RAR entries.
555 * @hw: pointer to hardware structure
557 u32 ixgbe_get_num_rx_addrs(struct ixgbe_hw *hw)
559 return ixgbe_call_func(hw, ixgbe_func_get_num_rx_addrs, (hw), 0);
563 * ixgbe_update_mc_addr_list - Updates the MAC's list of multicast addresses
564 * @hw: pointer to hardware structure
565 * @mc_addr_list: the list of new multicast addresses
566 * @mc_addr_count: number of addresses
567 * @pad: number of bytes between addresses in the list
569 * The given list replaces any existing list. Clears the MC addrs from receive
570 * address registers and the multicast table. Uses unsed receive address
571 * registers for the first multicast addresses, and hashes the rest into the
574 s32 ixgbe_update_mc_addr_list(struct ixgbe_hw *hw, u8 *mc_addr_list,
575 u32 mc_addr_count, u32 pad)
577 return ixgbe_call_func(hw, ixgbe_func_update_mc_addr_list, (hw,
578 mc_addr_list, mc_addr_count, pad),
579 IXGBE_NOT_IMPLEMENTED);
583 * ixgbe_enable_mc - Enable multicast address in RAR
584 * @hw: pointer to hardware structure
586 * Enables multicast address in RAR and the use of the multicast hash table.
588 s32 ixgbe_enable_mc(struct ixgbe_hw *hw)
590 return ixgbe_call_func(hw, ixgbe_func_enable_mc, (hw),
591 IXGBE_NOT_IMPLEMENTED);
595 * ixgbe_disable_mc - Disable multicast address in RAR
596 * @hw: pointer to hardware structure
598 * Disables multicast address in RAR and the use of the multicast hash table.
600 s32 ixgbe_disable_mc(struct ixgbe_hw *hw)
602 return ixgbe_call_func(hw, ixgbe_func_disable_mc, (hw),
603 IXGBE_NOT_IMPLEMENTED);
607 * ixgbe_clear_vfta - Clear VLAN filter table
608 * @hw: pointer to hardware structure
610 * Clears the VLAN filer table, and the VMDq index associated with the filter
612 s32 ixgbe_clear_vfta(struct ixgbe_hw *hw)
614 return ixgbe_call_func(hw, ixgbe_func_clear_vfta, (hw),
615 IXGBE_NOT_IMPLEMENTED);
619 * ixgbe_set_vfta - Set VLAN filter table
620 * @hw: pointer to hardware structure
621 * @vlan: VLAN id to write to VLAN filter
622 * @vind: VMDq output index that maps queue to VLAN id in VFTA
623 * @vlan_on: boolean flag to turn on/off VLAN in VFTA
625 * Turn on/off specified VLAN in the VLAN filter table.
627 s32 ixgbe_set_vfta(struct ixgbe_hw *hw, u32 vlan, u32 vind, bool vlan_on)
629 return ixgbe_call_func(hw, ixgbe_func_set_vfta, (hw, vlan, vind,
630 vlan_on), IXGBE_NOT_IMPLEMENTED);
634 * ixgbe_setup_fc - Set flow control
635 * @hw: pointer to hardware structure
636 * @packetbuf_num: packet buffer number (0-7)
638 * Configures the flow control settings based on SW configuration.
640 s32 ixgbe_setup_fc(struct ixgbe_hw *hw, s32 packetbuf_num)
642 return ixgbe_call_func(hw, ixgbe_func_setup_fc, (hw, packetbuf_num),
643 IXGBE_NOT_IMPLEMENTED);