1dee1ad47SJeff Kirsher /*******************************************************************************
2dee1ad47SJeff Kirsher 
3dee1ad47SJeff Kirsher   Intel 10 Gigabit PCI Express Linux driver
4434c5e39SDon Skidmore   Copyright(c) 1999 - 2013 Intel Corporation.
5dee1ad47SJeff Kirsher 
6dee1ad47SJeff Kirsher   This program is free software; you can redistribute it and/or modify it
7dee1ad47SJeff Kirsher   under the terms and conditions of the GNU General Public License,
8dee1ad47SJeff Kirsher   version 2, as published by the Free Software Foundation.
9dee1ad47SJeff Kirsher 
10dee1ad47SJeff Kirsher   This program is distributed in the hope it will be useful, but WITHOUT
11dee1ad47SJeff Kirsher   ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12dee1ad47SJeff Kirsher   FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
13dee1ad47SJeff Kirsher   more details.
14dee1ad47SJeff Kirsher 
15dee1ad47SJeff Kirsher   You should have received a copy of the GNU General Public License along with
16dee1ad47SJeff Kirsher   this program; if not, write to the Free Software Foundation, Inc.,
17dee1ad47SJeff Kirsher   51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
18dee1ad47SJeff Kirsher 
19dee1ad47SJeff Kirsher   The full GNU General Public License is included in this distribution in
20dee1ad47SJeff Kirsher   the file called "COPYING".
21dee1ad47SJeff Kirsher 
22dee1ad47SJeff Kirsher   Contact Information:
23dee1ad47SJeff Kirsher   e1000-devel Mailing List <e1000-devel@lists.sourceforge.net>
24dee1ad47SJeff Kirsher   Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
25dee1ad47SJeff Kirsher 
26dee1ad47SJeff Kirsher *******************************************************************************/
27dee1ad47SJeff Kirsher 
28dee1ad47SJeff Kirsher #ifndef _IXGBE_COMMON_H_
29dee1ad47SJeff Kirsher #define _IXGBE_COMMON_H_
30dee1ad47SJeff Kirsher 
31dee1ad47SJeff Kirsher #include "ixgbe_type.h"
32dee1ad47SJeff Kirsher #include "ixgbe.h"
33dee1ad47SJeff Kirsher 
3471161302SEmil Tantilov u16 ixgbe_get_pcie_msix_count_generic(struct ixgbe_hw *hw);
35dee1ad47SJeff Kirsher s32 ixgbe_init_ops_generic(struct ixgbe_hw *hw);
36dee1ad47SJeff Kirsher s32 ixgbe_init_hw_generic(struct ixgbe_hw *hw);
37dee1ad47SJeff Kirsher s32 ixgbe_start_hw_generic(struct ixgbe_hw *hw);
38dee1ad47SJeff Kirsher s32 ixgbe_start_hw_gen2(struct ixgbe_hw *hw);
39dee1ad47SJeff Kirsher s32 ixgbe_clear_hw_cntrs_generic(struct ixgbe_hw *hw);
40dee1ad47SJeff Kirsher s32 ixgbe_read_pba_string_generic(struct ixgbe_hw *hw, u8 *pba_num,
41dee1ad47SJeff Kirsher                                   u32 pba_num_size);
42dee1ad47SJeff Kirsher s32 ixgbe_get_mac_addr_generic(struct ixgbe_hw *hw, u8 *mac_addr);
43ef1889d5SJacob Keller enum ixgbe_bus_width ixgbe_convert_bus_width(u16 link_status);
44ef1889d5SJacob Keller enum ixgbe_bus_speed ixgbe_convert_bus_speed(u16 link_status);
45dee1ad47SJeff Kirsher s32 ixgbe_get_bus_info_generic(struct ixgbe_hw *hw);
46dee1ad47SJeff Kirsher void ixgbe_set_lan_id_multi_port_pcie(struct ixgbe_hw *hw);
47dee1ad47SJeff Kirsher s32 ixgbe_stop_adapter_generic(struct ixgbe_hw *hw);
48dee1ad47SJeff Kirsher 
49dee1ad47SJeff Kirsher s32 ixgbe_led_on_generic(struct ixgbe_hw *hw, u32 index);
50dee1ad47SJeff Kirsher s32 ixgbe_led_off_generic(struct ixgbe_hw *hw, u32 index);
51dee1ad47SJeff Kirsher 
52dee1ad47SJeff Kirsher s32 ixgbe_init_eeprom_params_generic(struct ixgbe_hw *hw);
53dee1ad47SJeff Kirsher s32 ixgbe_write_eeprom_generic(struct ixgbe_hw *hw, u16 offset, u16 data);
54dee1ad47SJeff Kirsher s32 ixgbe_write_eeprom_buffer_bit_bang_generic(struct ixgbe_hw *hw, u16 offset,
55dee1ad47SJeff Kirsher 					       u16 words, u16 *data);
56dee1ad47SJeff Kirsher s32 ixgbe_read_eerd_generic(struct ixgbe_hw *hw, u16 offset, u16 *data);
57dee1ad47SJeff Kirsher s32 ixgbe_read_eerd_buffer_generic(struct ixgbe_hw *hw, u16 offset,
58dee1ad47SJeff Kirsher 				   u16 words, u16 *data);
59dee1ad47SJeff Kirsher s32 ixgbe_write_eewr_generic(struct ixgbe_hw *hw, u16 offset, u16 data);
60dee1ad47SJeff Kirsher s32 ixgbe_write_eewr_buffer_generic(struct ixgbe_hw *hw, u16 offset,
61dee1ad47SJeff Kirsher 				    u16 words, u16 *data);
62dee1ad47SJeff Kirsher s32 ixgbe_read_eeprom_bit_bang_generic(struct ixgbe_hw *hw, u16 offset,
63dee1ad47SJeff Kirsher                                        u16 *data);
64dee1ad47SJeff Kirsher s32 ixgbe_read_eeprom_buffer_bit_bang_generic(struct ixgbe_hw *hw, u16 offset,
65dee1ad47SJeff Kirsher 					      u16 words, u16 *data);
66dee1ad47SJeff Kirsher u16 ixgbe_calc_eeprom_checksum_generic(struct ixgbe_hw *hw);
67dee1ad47SJeff Kirsher s32 ixgbe_validate_eeprom_checksum_generic(struct ixgbe_hw *hw,
68dee1ad47SJeff Kirsher                                            u16 *checksum_val);
69dee1ad47SJeff Kirsher s32 ixgbe_update_eeprom_checksum_generic(struct ixgbe_hw *hw);
70dee1ad47SJeff Kirsher 
71dee1ad47SJeff Kirsher s32 ixgbe_set_rar_generic(struct ixgbe_hw *hw, u32 index, u8 *addr, u32 vmdq,
72dee1ad47SJeff Kirsher                           u32 enable_addr);
73dee1ad47SJeff Kirsher s32 ixgbe_clear_rar_generic(struct ixgbe_hw *hw, u32 index);
74dee1ad47SJeff Kirsher s32 ixgbe_init_rx_addrs_generic(struct ixgbe_hw *hw);
75dee1ad47SJeff Kirsher s32 ixgbe_update_mc_addr_list_generic(struct ixgbe_hw *hw,
76dee1ad47SJeff Kirsher 				      struct net_device *netdev);
77dee1ad47SJeff Kirsher s32 ixgbe_enable_mc_generic(struct ixgbe_hw *hw);
78dee1ad47SJeff Kirsher s32 ixgbe_disable_mc_generic(struct ixgbe_hw *hw);
79d2f5e7f3SAtita Shirwaikar s32 ixgbe_disable_rx_buff_generic(struct ixgbe_hw *hw);
80d2f5e7f3SAtita Shirwaikar s32 ixgbe_enable_rx_buff_generic(struct ixgbe_hw *hw);
81dee1ad47SJeff Kirsher s32 ixgbe_enable_rx_dma_generic(struct ixgbe_hw *hw, u32 regval);
82041441d0SAlexander Duyck s32 ixgbe_fc_enable_generic(struct ixgbe_hw *hw);
8373d80953SDon Skidmore bool ixgbe_device_supports_autoneg_fc(struct ixgbe_hw *hw);
84786e9a5fSAlexander Duyck void ixgbe_fc_autoneg(struct ixgbe_hw *hw);
85dee1ad47SJeff Kirsher 
86dee1ad47SJeff Kirsher s32 ixgbe_acquire_swfw_sync(struct ixgbe_hw *hw, u16 mask);
87dee1ad47SJeff Kirsher void ixgbe_release_swfw_sync(struct ixgbe_hw *hw, u16 mask);
88dee1ad47SJeff Kirsher s32 ixgbe_get_san_mac_addr_generic(struct ixgbe_hw *hw, u8 *san_mac_addr);
89dee1ad47SJeff Kirsher s32 ixgbe_set_vmdq_generic(struct ixgbe_hw *hw, u32 rar, u32 vmdq);
907fa7c9dcSAlexander Duyck s32 ixgbe_set_vmdq_san_mac_generic(struct ixgbe_hw *hw, u32 vmdq);
91dee1ad47SJeff Kirsher s32 ixgbe_clear_vmdq_generic(struct ixgbe_hw *hw, u32 rar, u32 vmdq);
92dee1ad47SJeff Kirsher s32 ixgbe_init_uta_tables_generic(struct ixgbe_hw *hw);
93dee1ad47SJeff Kirsher s32 ixgbe_set_vfta_generic(struct ixgbe_hw *hw, u32 vlan,
94dee1ad47SJeff Kirsher                            u32 vind, bool vlan_on);
95dee1ad47SJeff Kirsher s32 ixgbe_clear_vfta_generic(struct ixgbe_hw *hw);
96dee1ad47SJeff Kirsher s32 ixgbe_check_mac_link_generic(struct ixgbe_hw *hw,
97dee1ad47SJeff Kirsher                                  ixgbe_link_speed *speed,
98dee1ad47SJeff Kirsher                                  bool *link_up, bool link_up_wait_to_complete);
99dee1ad47SJeff Kirsher s32 ixgbe_get_wwn_prefix_generic(struct ixgbe_hw *hw, u16 *wwnn_prefix,
100dee1ad47SJeff Kirsher                                  u16 *wwpn_prefix);
101429d6a3bSDon Skidmore 
102429d6a3bSDon Skidmore s32 prot_autoc_read_generic(struct ixgbe_hw *hw, bool *, u32 *reg_val);
103429d6a3bSDon Skidmore s32 prot_autoc_write_generic(struct ixgbe_hw *hw, u32 reg_val, bool locked);
104429d6a3bSDon Skidmore 
105dee1ad47SJeff Kirsher s32 ixgbe_blink_led_start_generic(struct ixgbe_hw *hw, u32 index);
106dee1ad47SJeff Kirsher s32 ixgbe_blink_led_stop_generic(struct ixgbe_hw *hw, u32 index);
107dee1ad47SJeff Kirsher void ixgbe_set_mac_anti_spoofing(struct ixgbe_hw *hw, bool enable, int pf);
108dee1ad47SJeff Kirsher void ixgbe_set_vlan_anti_spoofing(struct ixgbe_hw *hw, bool enable, int vf);
109dee1ad47SJeff Kirsher s32 ixgbe_get_device_caps_generic(struct ixgbe_hw *hw, u16 *device_caps);
110dee1ad47SJeff Kirsher s32 ixgbe_set_fw_drv_ver_generic(struct ixgbe_hw *hw, u8 maj, u8 min,
111dee1ad47SJeff Kirsher 				 u8 build, u8 ver);
112ff9d1a5aSEmil Tantilov void ixgbe_clear_tx_pending(struct ixgbe_hw *hw);
113dee1ad47SJeff Kirsher 
114dee1ad47SJeff Kirsher void ixgbe_set_rxpba_generic(struct ixgbe_hw *hw, int num_pb,
115dee1ad47SJeff Kirsher 			     u32 headroom, int strategy);
116dee1ad47SJeff Kirsher 
117e1ea9158SDon Skidmore #define IXGBE_I2C_THERMAL_SENSOR_ADDR	0xF8
118e1ea9158SDon Skidmore #define IXGBE_EMC_INTERNAL_DATA		0x00
119e1ea9158SDon Skidmore #define IXGBE_EMC_INTERNAL_THERM_LIMIT	0x20
120e1ea9158SDon Skidmore #define IXGBE_EMC_DIODE1_DATA		0x01
121e1ea9158SDon Skidmore #define IXGBE_EMC_DIODE1_THERM_LIMIT	0x19
122e1ea9158SDon Skidmore #define IXGBE_EMC_DIODE2_DATA		0x23
123e1ea9158SDon Skidmore #define IXGBE_EMC_DIODE2_THERM_LIMIT	0x1A
124e1ea9158SDon Skidmore #define IXGBE_EMC_DIODE3_DATA		0x2A
125e1ea9158SDon Skidmore #define IXGBE_EMC_DIODE3_THERM_LIMIT	0x30
126e1ea9158SDon Skidmore 
127e1ea9158SDon Skidmore s32 ixgbe_get_thermal_sensor_data_generic(struct ixgbe_hw *hw);
128e1ea9158SDon Skidmore s32 ixgbe_init_thermal_sensor_thresh_generic(struct ixgbe_hw *hw);
129e1ea9158SDon Skidmore 
1302a1a091cSMark Rustad #define IXGBE_FAILED_READ_REG 0xffffffffU
1312a1a091cSMark Rustad 
1322a1a091cSMark Rustad static inline bool ixgbe_removed(void __iomem *addr)
1332a1a091cSMark Rustad {
1342a1a091cSMark Rustad 	return unlikely(!addr);
1352a1a091cSMark Rustad }
1362a1a091cSMark Rustad 
1372a1a091cSMark Rustad void ixgbe_check_remove(struct ixgbe_hw *hw, u32 reg);
1382a1a091cSMark Rustad 
13984227bcdSMark Rustad static inline void ixgbe_write_reg(struct ixgbe_hw *hw, u32 reg, u32 value)
14084227bcdSMark Rustad {
141b12babd4SMark Rustad 	u8 __iomem *reg_addr = ACCESS_ONCE(hw->hw_addr);
142b12babd4SMark Rustad 
143b12babd4SMark Rustad 	if (ixgbe_removed(reg_addr))
144b12babd4SMark Rustad 		return;
145b12babd4SMark Rustad 	writel(value, reg_addr + reg);
14684227bcdSMark Rustad }
14784227bcdSMark Rustad #define IXGBE_WRITE_REG(a, reg, value) ixgbe_write_reg((a), (reg), (value))
148dee1ad47SJeff Kirsher 
149dee1ad47SJeff Kirsher #ifndef writeq
15084227bcdSMark Rustad #define writeq writeq
15184227bcdSMark Rustad static inline void writeq(u64 val, void __iomem *addr)
15284227bcdSMark Rustad {
15384227bcdSMark Rustad 	writel((u32)val, addr);
15484227bcdSMark Rustad 	writel((u32)(val >> 32), addr + 4);
15584227bcdSMark Rustad }
156dee1ad47SJeff Kirsher #endif
157dee1ad47SJeff Kirsher 
15884227bcdSMark Rustad static inline void ixgbe_write_reg64(struct ixgbe_hw *hw, u32 reg, u64 value)
15984227bcdSMark Rustad {
160b12babd4SMark Rustad 	u8 __iomem *reg_addr = ACCESS_ONCE(hw->hw_addr);
161b12babd4SMark Rustad 
162b12babd4SMark Rustad 	if (ixgbe_removed(reg_addr))
163b12babd4SMark Rustad 		return;
164b12babd4SMark Rustad 	writeq(value, reg_addr + reg);
16584227bcdSMark Rustad }
16684227bcdSMark Rustad #define IXGBE_WRITE_REG64(a, reg, value) ixgbe_write_reg64((a), (reg), (value))
167dee1ad47SJeff Kirsher 
16884227bcdSMark Rustad static inline u32 ixgbe_read_reg(struct ixgbe_hw *hw, u32 reg)
16984227bcdSMark Rustad {
1702a1a091cSMark Rustad 	u8 __iomem *reg_addr = ACCESS_ONCE(hw->hw_addr);
1712a1a091cSMark Rustad 	u32 value;
1722a1a091cSMark Rustad 
1732a1a091cSMark Rustad 	if (ixgbe_removed(reg_addr))
1742a1a091cSMark Rustad 		return IXGBE_FAILED_READ_REG;
1752a1a091cSMark Rustad 	value = readl(reg_addr + reg);
1762a1a091cSMark Rustad 	if (unlikely(value == IXGBE_FAILED_READ_REG))
1772a1a091cSMark Rustad 		ixgbe_check_remove(hw, reg);
1782a1a091cSMark Rustad 	return value;
17984227bcdSMark Rustad }
18084227bcdSMark Rustad #define IXGBE_READ_REG(a, reg) ixgbe_read_reg((a), (reg))
181dee1ad47SJeff Kirsher 
18284227bcdSMark Rustad #define IXGBE_WRITE_REG_ARRAY(a, reg, offset, value) \
18384227bcdSMark Rustad 		ixgbe_write_reg((a), (reg) + ((offset) << 2), (value))
184dee1ad47SJeff Kirsher 
18584227bcdSMark Rustad #define IXGBE_READ_REG_ARRAY(a, reg, offset) \
18684227bcdSMark Rustad 		ixgbe_read_reg((a), (reg) + ((offset) << 2))
187dee1ad47SJeff Kirsher 
18884227bcdSMark Rustad #define IXGBE_WRITE_FLUSH(a) ixgbe_read_reg((a), IXGBE_STATUS)
189dee1ad47SJeff Kirsher 
190be0c27b4SMark Rustad #define ixgbe_hw_to_netdev(hw) (((struct ixgbe_adapter *)(hw)->back)->netdev)
191be0c27b4SMark Rustad 
192dee1ad47SJeff Kirsher #define hw_dbg(hw, format, arg...) \
193be0c27b4SMark Rustad 	netdev_dbg(ixgbe_hw_to_netdev(hw), format, ## arg)
194be0c27b4SMark Rustad #define hw_err(hw, format, arg...) \
195be0c27b4SMark Rustad 	netdev_err(ixgbe_hw_to_netdev(hw), format, ## arg)
196dee1ad47SJeff Kirsher #define e_dev_info(format, arg...) \
197dee1ad47SJeff Kirsher 	dev_info(&adapter->pdev->dev, format, ## arg)
198dee1ad47SJeff Kirsher #define e_dev_warn(format, arg...) \
199dee1ad47SJeff Kirsher 	dev_warn(&adapter->pdev->dev, format, ## arg)
200dee1ad47SJeff Kirsher #define e_dev_err(format, arg...) \
201dee1ad47SJeff Kirsher 	dev_err(&adapter->pdev->dev, format, ## arg)
202dee1ad47SJeff Kirsher #define e_dev_notice(format, arg...) \
203dee1ad47SJeff Kirsher 	dev_notice(&adapter->pdev->dev, format, ## arg)
204dee1ad47SJeff Kirsher #define e_info(msglvl, format, arg...) \
205dee1ad47SJeff Kirsher 	netif_info(adapter, msglvl, adapter->netdev, format, ## arg)
206dee1ad47SJeff Kirsher #define e_err(msglvl, format, arg...) \
207dee1ad47SJeff Kirsher 	netif_err(adapter, msglvl, adapter->netdev, format, ## arg)
208dee1ad47SJeff Kirsher #define e_warn(msglvl, format, arg...) \
209dee1ad47SJeff Kirsher 	netif_warn(adapter, msglvl, adapter->netdev, format, ## arg)
210dee1ad47SJeff Kirsher #define e_crit(msglvl, format, arg...) \
211dee1ad47SJeff Kirsher 	netif_crit(adapter, msglvl, adapter->netdev, format, ## arg)
212dee1ad47SJeff Kirsher #endif /* IXGBE_COMMON */
213