blob: d602637ccc403022313f69f89f0bc99b2230f184 [file] [log] [blame]
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001/*******************************************************************************
2
3 Intel 10 Gigabit PCI Express Linux driver
Mark Rustad37689012016-01-07 10:13:03 -08004 Copyright(c) 1999 - 2016 Intel Corporation.
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00005
6 This program is free software; you can redistribute it and/or modify it
7 under the terms and conditions of the GNU General Public License,
8 version 2, as published by the Free Software Foundation.
9
10 This program is distributed in the hope it will be useful, but WITHOUT
11 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
13 more details.
14
15 You should have received a copy of the GNU General Public License along with
16 this program; if not, write to the Free Software Foundation, Inc.,
17 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
18
19 The full GNU General Public License is included in this distribution in
20 the file called "COPYING".
21
22 Contact Information:
Jacob Kellerb89aae72014-02-22 01:23:50 +000023 Linux NICS <linux.nics@intel.com>
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +000024 e1000-devel Mailing List <e1000-devel@lists.sourceforge.net>
25 Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
26
27*******************************************************************************/
28
29#include <linux/pci.h>
30#include <linux/delay.h>
31#include <linux/sched.h>
32
33#include "ixgbe.h"
34#include "ixgbe_phy.h"
Greg Rose096a58f2010-01-09 02:26:26 +000035#include "ixgbe_mbx.h"
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +000036
37#define IXGBE_82599_MAX_TX_QUEUES 128
38#define IXGBE_82599_MAX_RX_QUEUES 128
39#define IXGBE_82599_RAR_ENTRIES 128
40#define IXGBE_82599_MC_TBL_SIZE 128
41#define IXGBE_82599_VFT_TBL_SIZE 128
John Fastabende09ad232011-04-04 04:29:41 +000042#define IXGBE_82599_RX_PB_SIZE 512
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +000043
Emil Tantilov5d5b7c32010-10-12 22:20:59 +000044static void ixgbe_disable_tx_laser_multispeed_fiber(struct ixgbe_hw *hw);
45static void ixgbe_enable_tx_laser_multispeed_fiber(struct ixgbe_hw *hw);
46static void ixgbe_flap_tx_laser_multispeed_fiber(struct ixgbe_hw *hw);
Mark Rustad6d373a12015-08-08 16:18:28 -070047static void
48ixgbe_set_hard_rate_select_speed(struct ixgbe_hw *, ixgbe_link_speed);
Don Skidmorecd7e1f02009-10-08 15:36:22 +000049static s32 ixgbe_setup_mac_link_smartspeed(struct ixgbe_hw *hw,
Jacob Kellere7cf7452014-04-09 06:03:10 +000050 ixgbe_link_speed speed,
51 bool autoneg_wait_to_complete);
Jacob Kellerf4f10402013-06-25 07:59:23 +000052static void ixgbe_stop_mac_link_on_d3_82599(struct ixgbe_hw *hw);
Emil Tantilov5d5b7c32010-10-12 22:20:59 +000053static s32 ixgbe_start_mac_link_82599(struct ixgbe_hw *hw,
54 bool autoneg_wait_to_complete);
55static s32 ixgbe_setup_mac_link_82599(struct ixgbe_hw *hw,
Jacob Kellere7cf7452014-04-09 06:03:10 +000056 ixgbe_link_speed speed,
57 bool autoneg_wait_to_complete);
Mallikarjuna R Chilakala8620a102009-09-01 13:49:35 +000058static s32 ixgbe_setup_copper_link_82599(struct ixgbe_hw *hw,
Jacob Kellere7cf7452014-04-09 06:03:10 +000059 ixgbe_link_speed speed,
60 bool autoneg_wait_to_complete);
Peter P Waskiewicz Jr794caeb2009-06-04 16:02:24 +000061static s32 ixgbe_verify_fw_version_82599(struct ixgbe_hw *hw);
Don Skidmore8f583322013-07-27 06:25:38 +000062static s32 ixgbe_read_i2c_byte_82599(struct ixgbe_hw *hw, u8 byte_offset,
63 u8 dev_addr, u8 *data);
64static s32 ixgbe_write_i2c_byte_82599(struct ixgbe_hw *hw, u8 byte_offset,
65 u8 dev_addr, u8 data);
Don Skidmore429d6a32014-02-27 20:32:41 -080066static s32 ixgbe_reset_pipeline_82599(struct ixgbe_hw *hw);
67static bool ixgbe_verify_lesm_fw_enabled_82599(struct ixgbe_hw *hw);
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +000068
Don Skidmore7155d052014-02-27 09:03:30 +000069bool ixgbe_mng_enabled(struct ixgbe_hw *hw)
Don Skidmore0b2679d2013-02-21 03:00:04 +000070{
71 u32 fwsm, manc, factps;
72
Don Skidmore9a900ec2015-06-09 17:15:01 -070073 fwsm = IXGBE_READ_REG(hw, IXGBE_FWSM(hw));
Don Skidmore0b2679d2013-02-21 03:00:04 +000074 if ((fwsm & IXGBE_FWSM_MODE_MASK) != IXGBE_FWSM_FW_MODE_PT)
75 return false;
76
77 manc = IXGBE_READ_REG(hw, IXGBE_MANC);
78 if (!(manc & IXGBE_MANC_RCV_TCO_EN))
79 return false;
80
Don Skidmore9a900ec2015-06-09 17:15:01 -070081 factps = IXGBE_READ_REG(hw, IXGBE_FACTPS(hw));
Don Skidmore0b2679d2013-02-21 03:00:04 +000082 if (factps & IXGBE_FACTPS_MNGCG)
83 return false;
84
85 return true;
86}
87
Don Skidmore7b25cdb2009-08-25 04:47:32 +000088static void ixgbe_init_mac_link_ops_82599(struct ixgbe_hw *hw)
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +000089{
90 struct ixgbe_mac_info *mac = &hw->mac;
Don Skidmorec6ecf392010-12-03 03:31:51 +000091
Don Skidmore0b2679d2013-02-21 03:00:04 +000092 /* enable the laser control functions for SFP+ fiber
93 * and MNG not enabled
94 */
95 if ((mac->ops.get_media_type(hw) == ixgbe_media_type_fiber) &&
Don Skidmore7155d052014-02-27 09:03:30 +000096 !ixgbe_mng_enabled(hw)) {
Peter Waskiewicz61fac742010-04-27 00:38:15 +000097 mac->ops.disable_tx_laser =
Jacob Kellere7cf7452014-04-09 06:03:10 +000098 &ixgbe_disable_tx_laser_multispeed_fiber;
Peter Waskiewicz61fac742010-04-27 00:38:15 +000099 mac->ops.enable_tx_laser =
Jacob Kellere7cf7452014-04-09 06:03:10 +0000100 &ixgbe_enable_tx_laser_multispeed_fiber;
Mallikarjuna R Chilakala1097cd12010-03-18 14:34:52 +0000101 mac->ops.flap_tx_laser = &ixgbe_flap_tx_laser_multispeed_fiber;
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +0000102 } else {
Peter Waskiewicz61fac742010-04-27 00:38:15 +0000103 mac->ops.disable_tx_laser = NULL;
104 mac->ops.enable_tx_laser = NULL;
Mallikarjuna R Chilakala1097cd12010-03-18 14:34:52 +0000105 mac->ops.flap_tx_laser = NULL;
Don Skidmorec6ecf392010-12-03 03:31:51 +0000106 }
107
108 if (hw->phy.multispeed_fiber) {
109 /* Set up dual speed SFP+ support */
110 mac->ops.setup_link = &ixgbe_setup_mac_link_multispeed_fiber;
Mark Rustad6d373a12015-08-08 16:18:28 -0700111 mac->ops.setup_mac_link = ixgbe_setup_mac_link_82599;
112 mac->ops.set_rate_select_speed =
113 ixgbe_set_hard_rate_select_speed;
Don Skidmorec6ecf392010-12-03 03:31:51 +0000114 } else {
Don Skidmorecd7e1f02009-10-08 15:36:22 +0000115 if ((mac->ops.get_media_type(hw) ==
116 ixgbe_media_type_backplane) &&
117 (hw->phy.smart_speed == ixgbe_smart_speed_auto ||
Emil Tantilov0fa6d832011-03-18 08:18:32 +0000118 hw->phy.smart_speed == ixgbe_smart_speed_on) &&
119 !ixgbe_verify_lesm_fw_enabled_82599(hw))
Don Skidmorecd7e1f02009-10-08 15:36:22 +0000120 mac->ops.setup_link = &ixgbe_setup_mac_link_smartspeed;
121 else
122 mac->ops.setup_link = &ixgbe_setup_mac_link_82599;
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +0000123 }
124}
125
Don Skidmore7b25cdb2009-08-25 04:47:32 +0000126static s32 ixgbe_setup_sfp_modules_82599(struct ixgbe_hw *hw)
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +0000127{
Mark Rustade90dd262014-07-22 06:51:08 +0000128 s32 ret_val;
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +0000129 u16 list_offset, data_offset, data_value;
130
131 if (hw->phy.sfp_type != ixgbe_sfp_type_unknown) {
132 ixgbe_init_mac_link_ops_82599(hw);
PJ Waskiewicz553b4492009-04-09 22:28:15 +0000133
134 hw->phy.ops.reset = NULL;
135
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +0000136 ret_val = ixgbe_get_sfp_init_sequence_offsets(hw, &list_offset,
Jacob Kellere7cf7452014-04-09 06:03:10 +0000137 &data_offset);
Mark Rustade90dd262014-07-22 06:51:08 +0000138 if (ret_val)
139 return ret_val;
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +0000140
Peter P Waskiewicz Jraa5aec82009-05-19 09:18:34 +0000141 /* PHY config will finish before releasing the semaphore */
Don Skidmore5e655102011-02-25 01:58:04 +0000142 ret_val = hw->mac.ops.acquire_swfw_sync(hw,
Jacob Kellere7cf7452014-04-09 06:03:10 +0000143 IXGBE_GSSR_MAC_CSR_SM);
Mark Rustade90dd262014-07-22 06:51:08 +0000144 if (ret_val)
145 return IXGBE_ERR_SWFW_SYNC;
Peter P Waskiewicz Jraa5aec82009-05-19 09:18:34 +0000146
Mark Rustadbe0c27b2013-05-24 07:31:09 +0000147 if (hw->eeprom.ops.read(hw, ++data_offset, &data_value))
148 goto setup_sfp_err;
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +0000149 while (data_value != 0xffff) {
150 IXGBE_WRITE_REG(hw, IXGBE_CORECTL, data_value);
151 IXGBE_WRITE_FLUSH(hw);
Mark Rustadbe0c27b2013-05-24 07:31:09 +0000152 if (hw->eeprom.ops.read(hw, ++data_offset, &data_value))
153 goto setup_sfp_err;
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +0000154 }
Peter P Waskiewicz Jraa5aec82009-05-19 09:18:34 +0000155
156 /* Release the semaphore */
Emil Tantilov6d980c32011-04-13 04:56:15 +0000157 hw->mac.ops.release_swfw_sync(hw, IXGBE_GSSR_MAC_CSR_SM);
Don Skidmore032b4322011-03-18 09:32:53 +0000158 /*
159 * Delay obtaining semaphore again to allow FW access,
160 * semaphore_delay is in ms usleep_range needs us.
161 */
162 usleep_range(hw->eeprom.semaphore_delay * 1000,
163 hw->eeprom.semaphore_delay * 2000);
Don Skidmorea7f5a5f2010-12-03 13:23:30 +0000164
Don Skidmored7bbcd32012-10-24 06:19:01 +0000165 /* Restart DSP and set SFI mode */
Don Skidmore429d6a32014-02-27 20:32:41 -0800166 ret_val = hw->mac.ops.prot_autoc_write(hw,
167 hw->mac.orig_autoc | IXGBE_AUTOC_LMS_10G_SERIAL,
168 false);
Don Skidmored7bbcd32012-10-24 06:19:01 +0000169
170 if (ret_val) {
171 hw_dbg(hw, " sfp module setup not complete\n");
Mark Rustade90dd262014-07-22 06:51:08 +0000172 return IXGBE_ERR_SFP_SETUP_NOT_COMPLETE;
Don Skidmorea7f5a5f2010-12-03 13:23:30 +0000173 }
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +0000174 }
175
Mark Rustade90dd262014-07-22 06:51:08 +0000176 return 0;
Mark Rustadbe0c27b2013-05-24 07:31:09 +0000177
178setup_sfp_err:
179 /* Release the semaphore */
180 hw->mac.ops.release_swfw_sync(hw, IXGBE_GSSR_MAC_CSR_SM);
181 /* Delay obtaining semaphore again to allow FW access,
182 * semaphore_delay is in ms usleep_range needs us.
183 */
184 usleep_range(hw->eeprom.semaphore_delay * 1000,
185 hw->eeprom.semaphore_delay * 2000);
186 hw_err(hw, "eeprom read at offset %d failed\n", data_offset);
187 return IXGBE_ERR_SFP_SETUP_NOT_COMPLETE;
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +0000188}
189
Don Skidmore429d6a32014-02-27 20:32:41 -0800190/**
191 * prot_autoc_read_82599 - Hides MAC differences needed for AUTOC read
192 * @hw: pointer to hardware structure
193 * @locked: Return the if we locked for this read.
194 * @reg_val: Value we read from AUTOC
195 *
196 * For this part (82599) we need to wrap read-modify-writes with a possible
197 * FW/SW lock. It is assumed this lock will be freed with the next
198 * prot_autoc_write_82599(). Note, that locked can only be true in cases
199 * where this function doesn't return an error.
200 **/
201static s32 prot_autoc_read_82599(struct ixgbe_hw *hw, bool *locked,
202 u32 *reg_val)
203{
204 s32 ret_val;
205
206 *locked = false;
207 /* If LESM is on then we need to hold the SW/FW semaphore. */
208 if (ixgbe_verify_lesm_fw_enabled_82599(hw)) {
209 ret_val = hw->mac.ops.acquire_swfw_sync(hw,
210 IXGBE_GSSR_MAC_CSR_SM);
Don Skidmoref8cf7a02014-03-19 09:16:26 +0000211 if (ret_val)
Don Skidmore429d6a32014-02-27 20:32:41 -0800212 return IXGBE_ERR_SWFW_SYNC;
213
214 *locked = true;
215 }
216
217 *reg_val = IXGBE_READ_REG(hw, IXGBE_AUTOC);
218 return 0;
219}
220
221/**
222 * prot_autoc_write_82599 - Hides MAC differences needed for AUTOC write
223 * @hw: pointer to hardware structure
224 * @reg_val: value to write to AUTOC
225 * @locked: bool to indicate whether the SW/FW lock was already taken by
226 * previous proc_autoc_read_82599.
227 *
228 * This part (82599) may need to hold a the SW/FW lock around all writes to
229 * AUTOC. Likewise after a write we need to do a pipeline reset.
230 **/
231static s32 prot_autoc_write_82599(struct ixgbe_hw *hw, u32 autoc, bool locked)
232{
233 s32 ret_val = 0;
234
Don Skidmorec97506a2014-02-27 20:32:43 -0800235 /* Blocked by MNG FW so bail */
236 if (ixgbe_check_reset_blocked(hw))
237 goto out;
238
Don Skidmore429d6a32014-02-27 20:32:41 -0800239 /* We only need to get the lock if:
240 * - We didn't do it already (in the read part of a read-modify-write)
241 * - LESM is enabled.
242 */
243 if (!locked && ixgbe_verify_lesm_fw_enabled_82599(hw)) {
244 ret_val = hw->mac.ops.acquire_swfw_sync(hw,
245 IXGBE_GSSR_MAC_CSR_SM);
Don Skidmoref8cf7a02014-03-19 09:16:26 +0000246 if (ret_val)
Don Skidmore429d6a32014-02-27 20:32:41 -0800247 return IXGBE_ERR_SWFW_SYNC;
Don Skidmoref8cf7a02014-03-19 09:16:26 +0000248
249 locked = true;
Don Skidmore429d6a32014-02-27 20:32:41 -0800250 }
251
252 IXGBE_WRITE_REG(hw, IXGBE_AUTOC, autoc);
253 ret_val = ixgbe_reset_pipeline_82599(hw);
254
Don Skidmorec97506a2014-02-27 20:32:43 -0800255out:
Don Skidmore429d6a32014-02-27 20:32:41 -0800256 /* Free the SW/FW semaphore as we either grabbed it here or
257 * already had it when this function was called.
258 */
259 if (locked)
260 hw->mac.ops.release_swfw_sync(hw, IXGBE_GSSR_MAC_CSR_SM);
261
262 return ret_val;
263}
264
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +0000265static s32 ixgbe_get_invariants_82599(struct ixgbe_hw *hw)
266{
267 struct ixgbe_mac_info *mac = &hw->mac;
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +0000268
269 ixgbe_init_mac_link_ops_82599(hw);
270
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +0000271 mac->mcft_size = IXGBE_82599_MC_TBL_SIZE;
272 mac->vft_size = IXGBE_82599_VFT_TBL_SIZE;
273 mac->num_rar_entries = IXGBE_82599_RAR_ENTRIES;
Jacob Keller6997d4d2014-02-22 01:23:49 +0000274 mac->rx_pb_size = IXGBE_82599_RX_PB_SIZE;
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +0000275 mac->max_rx_queues = IXGBE_82599_MAX_RX_QUEUES;
276 mac->max_tx_queues = IXGBE_82599_MAX_TX_QUEUES;
Mallikarjuna R Chilakala21ce8492010-05-13 17:33:41 +0000277 mac->max_msix_vectors = ixgbe_get_pcie_msix_count_generic(hw);
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +0000278
PJ Waskiewicz04f165e2009-04-09 22:27:57 +0000279 return 0;
280}
281
282/**
283 * ixgbe_init_phy_ops_82599 - PHY/SFP specific init
284 * @hw: pointer to hardware structure
285 *
286 * Initialize any function pointers that were not able to be
287 * set during get_invariants because the PHY/SFP type was
288 * not known. Perform the SFP init if necessary.
289 *
290 **/
Don Skidmore7b25cdb2009-08-25 04:47:32 +0000291static s32 ixgbe_init_phy_ops_82599(struct ixgbe_hw *hw)
PJ Waskiewicz04f165e2009-04-09 22:27:57 +0000292{
293 struct ixgbe_mac_info *mac = &hw->mac;
294 struct ixgbe_phy_info *phy = &hw->phy;
Mark Rustade90dd262014-07-22 06:51:08 +0000295 s32 ret_val;
Don Skidmore8f583322013-07-27 06:25:38 +0000296 u32 esdp;
297
298 if (hw->device_id == IXGBE_DEV_ID_82599_QSFP_SF_QP) {
299 /* Store flag indicating I2C bus access control unit. */
300 hw->phy.qsfp_shared_i2c_bus = true;
301
302 /* Initialize access to QSFP+ I2C bus */
303 esdp = IXGBE_READ_REG(hw, IXGBE_ESDP);
304 esdp |= IXGBE_ESDP_SDP0_DIR;
305 esdp &= ~IXGBE_ESDP_SDP1_DIR;
306 esdp &= ~IXGBE_ESDP_SDP0;
307 esdp &= ~IXGBE_ESDP_SDP0_NATIVE;
308 esdp &= ~IXGBE_ESDP_SDP1_NATIVE;
309 IXGBE_WRITE_REG(hw, IXGBE_ESDP, esdp);
310 IXGBE_WRITE_FLUSH(hw);
311
312 phy->ops.read_i2c_byte = &ixgbe_read_i2c_byte_82599;
313 phy->ops.write_i2c_byte = &ixgbe_write_i2c_byte_82599;
314 }
PJ Waskiewicz04f165e2009-04-09 22:27:57 +0000315
316 /* Identify the PHY or SFP module */
317 ret_val = phy->ops.identify(hw);
318
319 /* Setup function pointers based on detected SFP module and speeds */
320 ixgbe_init_mac_link_ops_82599(hw);
321
322 /* If copper media, overwrite with copper function pointers */
323 if (mac->ops.get_media_type(hw) == ixgbe_media_type_copper) {
324 mac->ops.setup_link = &ixgbe_setup_copper_link_82599;
PJ Waskiewicz04f165e2009-04-09 22:27:57 +0000325 mac->ops.get_link_capabilities =
Don Skidmorea391f1d2010-11-16 19:27:15 -0800326 &ixgbe_get_copper_link_capabilities_generic;
PJ Waskiewicz04f165e2009-04-09 22:27:57 +0000327 }
328
329 /* Set necessary function pointers based on phy type */
330 switch (hw->phy.type) {
331 case ixgbe_phy_tn:
332 phy->ops.check_link = &ixgbe_check_phy_link_tnx;
Emil Tantilovb57e35b2011-07-28 06:17:04 +0000333 phy->ops.setup_link = &ixgbe_setup_phy_link_tnx;
PJ Waskiewicz04f165e2009-04-09 22:27:57 +0000334 break;
335 default:
336 break;
337 }
338
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +0000339 return ret_val;
340}
341
342/**
343 * ixgbe_get_link_capabilities_82599 - Determines link capabilities
344 * @hw: pointer to hardware structure
345 * @speed: pointer to link speed
Josh Hay3d292262012-12-15 03:28:19 +0000346 * @autoneg: true when autoneg or autotry is enabled
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +0000347 *
348 * Determines the link capabilities by reading the AUTOC register.
349 **/
Don Skidmore7b25cdb2009-08-25 04:47:32 +0000350static s32 ixgbe_get_link_capabilities_82599(struct ixgbe_hw *hw,
Jacob Kellere7cf7452014-04-09 06:03:10 +0000351 ixgbe_link_speed *speed,
Josh Hay3d292262012-12-15 03:28:19 +0000352 bool *autoneg)
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +0000353{
PJ Waskiewicz1eb99d52009-04-09 22:28:33 +0000354 u32 autoc = 0;
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +0000355
Don Skidmorecb836a92010-06-29 18:30:59 +0000356 /* Determine 1G link capabilities off of SFP+ type */
357 if (hw->phy.sfp_type == ixgbe_sfp_type_1g_cu_core0 ||
Jacob Kellera49fda32012-06-08 06:59:09 +0000358 hw->phy.sfp_type == ixgbe_sfp_type_1g_cu_core1 ||
Don Skidmore345be202013-04-11 06:23:34 +0000359 hw->phy.sfp_type == ixgbe_sfp_type_1g_lx_core0 ||
360 hw->phy.sfp_type == ixgbe_sfp_type_1g_lx_core1 ||
Jacob Kellera49fda32012-06-08 06:59:09 +0000361 hw->phy.sfp_type == ixgbe_sfp_type_1g_sx_core0 ||
362 hw->phy.sfp_type == ixgbe_sfp_type_1g_sx_core1) {
Don Skidmorecb836a92010-06-29 18:30:59 +0000363 *speed = IXGBE_LINK_SPEED_1GB_FULL;
Josh Hay3d292262012-12-15 03:28:19 +0000364 *autoneg = true;
Mark Rustade90dd262014-07-22 06:51:08 +0000365 return 0;
Don Skidmorecb836a92010-06-29 18:30:59 +0000366 }
367
PJ Waskiewicz1eb99d52009-04-09 22:28:33 +0000368 /*
369 * Determine link capabilities based on the stored value of AUTOC,
370 * which represents EEPROM defaults. If AUTOC value has not been
371 * stored, use the current register value.
372 */
373 if (hw->mac.orig_link_settings_stored)
374 autoc = hw->mac.orig_autoc;
375 else
376 autoc = IXGBE_READ_REG(hw, IXGBE_AUTOC);
377
378 switch (autoc & IXGBE_AUTOC_LMS_MASK) {
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +0000379 case IXGBE_AUTOC_LMS_1G_LINK_NO_AN:
380 *speed = IXGBE_LINK_SPEED_1GB_FULL;
Josh Hay3d292262012-12-15 03:28:19 +0000381 *autoneg = false;
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +0000382 break;
383
384 case IXGBE_AUTOC_LMS_10G_LINK_NO_AN:
385 *speed = IXGBE_LINK_SPEED_10GB_FULL;
Josh Hay3d292262012-12-15 03:28:19 +0000386 *autoneg = false;
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +0000387 break;
388
389 case IXGBE_AUTOC_LMS_1G_AN:
390 *speed = IXGBE_LINK_SPEED_1GB_FULL;
Josh Hay3d292262012-12-15 03:28:19 +0000391 *autoneg = true;
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +0000392 break;
393
394 case IXGBE_AUTOC_LMS_10G_SERIAL:
395 *speed = IXGBE_LINK_SPEED_10GB_FULL;
Josh Hay3d292262012-12-15 03:28:19 +0000396 *autoneg = false;
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +0000397 break;
398
399 case IXGBE_AUTOC_LMS_KX4_KX_KR:
400 case IXGBE_AUTOC_LMS_KX4_KX_KR_1G_AN:
401 *speed = IXGBE_LINK_SPEED_UNKNOWN;
PJ Waskiewicz1eb99d52009-04-09 22:28:33 +0000402 if (autoc & IXGBE_AUTOC_KR_SUPP)
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +0000403 *speed |= IXGBE_LINK_SPEED_10GB_FULL;
PJ Waskiewicz1eb99d52009-04-09 22:28:33 +0000404 if (autoc & IXGBE_AUTOC_KX4_SUPP)
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +0000405 *speed |= IXGBE_LINK_SPEED_10GB_FULL;
PJ Waskiewicz1eb99d52009-04-09 22:28:33 +0000406 if (autoc & IXGBE_AUTOC_KX_SUPP)
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +0000407 *speed |= IXGBE_LINK_SPEED_1GB_FULL;
Josh Hay3d292262012-12-15 03:28:19 +0000408 *autoneg = true;
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +0000409 break;
410
411 case IXGBE_AUTOC_LMS_KX4_KX_KR_SGMII:
412 *speed = IXGBE_LINK_SPEED_100_FULL;
PJ Waskiewicz1eb99d52009-04-09 22:28:33 +0000413 if (autoc & IXGBE_AUTOC_KR_SUPP)
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +0000414 *speed |= IXGBE_LINK_SPEED_10GB_FULL;
PJ Waskiewicz1eb99d52009-04-09 22:28:33 +0000415 if (autoc & IXGBE_AUTOC_KX4_SUPP)
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +0000416 *speed |= IXGBE_LINK_SPEED_10GB_FULL;
PJ Waskiewicz1eb99d52009-04-09 22:28:33 +0000417 if (autoc & IXGBE_AUTOC_KX_SUPP)
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +0000418 *speed |= IXGBE_LINK_SPEED_1GB_FULL;
Josh Hay3d292262012-12-15 03:28:19 +0000419 *autoneg = true;
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +0000420 break;
421
422 case IXGBE_AUTOC_LMS_SGMII_1G_100M:
423 *speed = IXGBE_LINK_SPEED_1GB_FULL | IXGBE_LINK_SPEED_100_FULL;
Josh Hay3d292262012-12-15 03:28:19 +0000424 *autoneg = false;
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +0000425 break;
426
427 default:
Mark Rustade90dd262014-07-22 06:51:08 +0000428 return IXGBE_ERR_LINK_SETUP;
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +0000429 }
430
431 if (hw->phy.multispeed_fiber) {
432 *speed |= IXGBE_LINK_SPEED_10GB_FULL |
Emil Tantilov61aaf9e2013-08-13 07:22:16 +0000433 IXGBE_LINK_SPEED_1GB_FULL;
434
435 /* QSFP must not enable auto-negotiation */
436 if (hw->phy.media_type == ixgbe_media_type_fiber_qsfp)
437 *autoneg = false;
438 else
439 *autoneg = true;
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +0000440 }
441
Mark Rustade90dd262014-07-22 06:51:08 +0000442 return 0;
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +0000443}
444
445/**
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +0000446 * ixgbe_get_media_type_82599 - Get media type
447 * @hw: pointer to hardware structure
448 *
449 * Returns the media type (fiber, copper, backplane)
450 **/
Don Skidmore7b25cdb2009-08-25 04:47:32 +0000451static enum ixgbe_media_type ixgbe_get_media_type_82599(struct ixgbe_hw *hw)
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +0000452{
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +0000453 /* Detect if there is a copper PHY attached. */
Emil Tantilov21cc5b42011-02-12 10:52:07 +0000454 switch (hw->phy.type) {
455 case ixgbe_phy_cu_unknown:
456 case ixgbe_phy_tn:
Mark Rustade90dd262014-07-22 06:51:08 +0000457 return ixgbe_media_type_copper;
458
Emil Tantilov21cc5b42011-02-12 10:52:07 +0000459 default:
460 break;
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +0000461 }
462
463 switch (hw->device_id) {
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +0000464 case IXGBE_DEV_ID_82599_KX4:
Don Skidmoredbfec662009-10-02 08:58:25 +0000465 case IXGBE_DEV_ID_82599_KX4_MEZZ:
Don Skidmore312eb932009-10-02 08:58:04 +0000466 case IXGBE_DEV_ID_82599_COMBO_BACKPLANE:
Don Skidmore74757d42009-12-08 07:22:23 +0000467 case IXGBE_DEV_ID_82599_KR:
Don Skidmoredbffcb22010-12-03 03:32:34 +0000468 case IXGBE_DEV_ID_82599_BACKPLANE_FCOE:
Peter P Waskiewicz Jr1fcf03e2009-05-17 20:58:04 +0000469 case IXGBE_DEV_ID_82599_XAUI_LOM:
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +0000470 /* Default device ID is mezzanine card KX/KX4 */
Mark Rustade90dd262014-07-22 06:51:08 +0000471 return ixgbe_media_type_backplane;
472
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +0000473 case IXGBE_DEV_ID_82599_SFP:
Don Skidmoredbffcb22010-12-03 03:32:34 +0000474 case IXGBE_DEV_ID_82599_SFP_FCOE:
Don Skidmore38ad1c82009-10-08 15:35:58 +0000475 case IXGBE_DEV_ID_82599_SFP_EM:
Emil Tantilov4c40ef02011-03-24 07:06:02 +0000476 case IXGBE_DEV_ID_82599_SFP_SF2:
Emil Tantilov9e791e42011-11-04 06:43:29 +0000477 case IXGBE_DEV_ID_82599_SFP_SF_QP:
Emil Tantilov7d145282011-09-08 08:30:14 +0000478 case IXGBE_DEV_ID_82599EN_SFP:
Mark Rustade90dd262014-07-22 06:51:08 +0000479 return ixgbe_media_type_fiber;
480
Peter P Waskiewicz Jr8911184f2009-09-14 07:47:49 +0000481 case IXGBE_DEV_ID_82599_CX4:
Mark Rustade90dd262014-07-22 06:51:08 +0000482 return ixgbe_media_type_cx4;
483
Emil Tantilov21cc5b42011-02-12 10:52:07 +0000484 case IXGBE_DEV_ID_82599_T3_LOM:
Mark Rustade90dd262014-07-22 06:51:08 +0000485 return ixgbe_media_type_copper;
486
Don Skidmore4f6290c2011-05-14 06:36:35 +0000487 case IXGBE_DEV_ID_82599_LS:
Mark Rustade90dd262014-07-22 06:51:08 +0000488 return ixgbe_media_type_fiber_lco;
489
Don Skidmore8f583322013-07-27 06:25:38 +0000490 case IXGBE_DEV_ID_82599_QSFP_SF_QP:
Mark Rustade90dd262014-07-22 06:51:08 +0000491 return ixgbe_media_type_fiber_qsfp;
492
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +0000493 default:
Mark Rustade90dd262014-07-22 06:51:08 +0000494 return ixgbe_media_type_unknown;
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +0000495 }
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +0000496}
497
498/**
Jacob Kellerf4f10402013-06-25 07:59:23 +0000499 * ixgbe_stop_mac_link_on_d3_82599 - Disables link on D3
500 * @hw: pointer to hardware structure
501 *
502 * Disables link, should be called during D3 power down sequence.
503 *
Jacob Keller305f8ce2014-02-22 01:23:52 +0000504 **/
Jacob Kellerf4f10402013-06-25 07:59:23 +0000505static void ixgbe_stop_mac_link_on_d3_82599(struct ixgbe_hw *hw)
506{
Don Skidmorebd8069a2015-06-10 20:05:02 -0400507 u32 autoc2_reg;
Jacob Kellerf68bfdb2014-02-22 01:23:54 +0000508 u16 ee_ctrl_2 = 0;
Jacob Kellerf4f10402013-06-25 07:59:23 +0000509
Jacob Kellerf68bfdb2014-02-22 01:23:54 +0000510 hw->eeprom.ops.read(hw, IXGBE_EEPROM_CTRL_2, &ee_ctrl_2);
511
Don Skidmorebd8069a2015-06-10 20:05:02 -0400512 if (!ixgbe_mng_present(hw) && !hw->wol_enabled &&
Jacob Kellerf68bfdb2014-02-22 01:23:54 +0000513 ee_ctrl_2 & IXGBE_EEPROM_CCD_BIT) {
Jacob Kellerf4f10402013-06-25 07:59:23 +0000514 autoc2_reg = IXGBE_READ_REG(hw, IXGBE_AUTOC2);
515 autoc2_reg |= IXGBE_AUTOC2_LINK_DISABLE_ON_D3_MASK;
516 IXGBE_WRITE_REG(hw, IXGBE_AUTOC2, autoc2_reg);
517 }
518}
519
520/**
Mallikarjuna R Chilakala8620a102009-09-01 13:49:35 +0000521 * ixgbe_start_mac_link_82599 - Setup MAC link settings
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +0000522 * @hw: pointer to hardware structure
Mallikarjuna R Chilakala8620a102009-09-01 13:49:35 +0000523 * @autoneg_wait_to_complete: true when waiting for completion is needed
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +0000524 *
525 * Configures link settings based on values in the ixgbe_hw struct.
526 * Restarts the link. Performs autonegotiation if needed.
527 **/
Emil Tantilov5d5b7c32010-10-12 22:20:59 +0000528static s32 ixgbe_start_mac_link_82599(struct ixgbe_hw *hw,
Jacob Kellere7cf7452014-04-09 06:03:10 +0000529 bool autoneg_wait_to_complete)
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +0000530{
531 u32 autoc_reg;
532 u32 links_reg;
533 u32 i;
534 s32 status = 0;
Don Skidmored7bbcd32012-10-24 06:19:01 +0000535 bool got_lock = false;
536
537 if (ixgbe_verify_lesm_fw_enabled_82599(hw)) {
538 status = hw->mac.ops.acquire_swfw_sync(hw,
539 IXGBE_GSSR_MAC_CSR_SM);
540 if (status)
Mark Rustade90dd262014-07-22 06:51:08 +0000541 return status;
Don Skidmored7bbcd32012-10-24 06:19:01 +0000542
543 got_lock = true;
544 }
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +0000545
546 /* Restart link */
Don Skidmored7bbcd32012-10-24 06:19:01 +0000547 ixgbe_reset_pipeline_82599(hw);
548
549 if (got_lock)
550 hw->mac.ops.release_swfw_sync(hw, IXGBE_GSSR_MAC_CSR_SM);
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +0000551
552 /* Only poll for autoneg to complete if specified to do so */
Mallikarjuna R Chilakala8620a102009-09-01 13:49:35 +0000553 if (autoneg_wait_to_complete) {
Don Skidmored7bbcd32012-10-24 06:19:01 +0000554 autoc_reg = IXGBE_READ_REG(hw, IXGBE_AUTOC);
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +0000555 if ((autoc_reg & IXGBE_AUTOC_LMS_MASK) ==
556 IXGBE_AUTOC_LMS_KX4_KX_KR ||
557 (autoc_reg & IXGBE_AUTOC_LMS_MASK) ==
558 IXGBE_AUTOC_LMS_KX4_KX_KR_1G_AN ||
559 (autoc_reg & IXGBE_AUTOC_LMS_MASK) ==
560 IXGBE_AUTOC_LMS_KX4_KX_KR_SGMII) {
561 links_reg = 0; /* Just in case Autoneg time = 0 */
562 for (i = 0; i < IXGBE_AUTO_NEG_TIME; i++) {
563 links_reg = IXGBE_READ_REG(hw, IXGBE_LINKS);
564 if (links_reg & IXGBE_LINKS_KX_AN_COMP)
565 break;
566 msleep(100);
567 }
568 if (!(links_reg & IXGBE_LINKS_KX_AN_COMP)) {
569 status = IXGBE_ERR_AUTONEG_NOT_COMPLETE;
570 hw_dbg(hw, "Autoneg did not complete.\n");
571 }
572 }
573 }
574
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +0000575 /* Add delay to filter out noises during initial link setup */
576 msleep(50);
577
578 return status;
579}
580
Emil Tantilov8c7bea32011-02-19 08:43:44 +0000581/**
582 * ixgbe_disable_tx_laser_multispeed_fiber - Disable Tx laser
583 * @hw: pointer to hardware structure
584 *
585 * The base drivers may require better control over SFP+ module
586 * PHY states. This includes selectively shutting down the Tx
587 * laser on the PHY, effectively halting physical link.
588 **/
Emil Tantilov5d5b7c32010-10-12 22:20:59 +0000589static void ixgbe_disable_tx_laser_multispeed_fiber(struct ixgbe_hw *hw)
Peter Waskiewicz61fac742010-04-27 00:38:15 +0000590{
591 u32 esdp_reg = IXGBE_READ_REG(hw, IXGBE_ESDP);
592
Don Skidmorec97506a2014-02-27 20:32:43 -0800593 /* Blocked by MNG FW so bail */
594 if (ixgbe_check_reset_blocked(hw))
595 return;
596
Peter Waskiewicz61fac742010-04-27 00:38:15 +0000597 /* Disable tx laser; allow 100us to go dark per spec */
598 esdp_reg |= IXGBE_ESDP_SDP3;
599 IXGBE_WRITE_REG(hw, IXGBE_ESDP, esdp_reg);
600 IXGBE_WRITE_FLUSH(hw);
601 udelay(100);
602}
603
604/**
605 * ixgbe_enable_tx_laser_multispeed_fiber - Enable Tx laser
606 * @hw: pointer to hardware structure
607 *
608 * The base drivers may require better control over SFP+ module
609 * PHY states. This includes selectively turning on the Tx
610 * laser on the PHY, effectively starting physical link.
611 **/
Emil Tantilov5d5b7c32010-10-12 22:20:59 +0000612static void ixgbe_enable_tx_laser_multispeed_fiber(struct ixgbe_hw *hw)
Peter Waskiewicz61fac742010-04-27 00:38:15 +0000613{
614 u32 esdp_reg = IXGBE_READ_REG(hw, IXGBE_ESDP);
615
616 /* Enable tx laser; allow 100ms to light up */
617 esdp_reg &= ~IXGBE_ESDP_SDP3;
618 IXGBE_WRITE_REG(hw, IXGBE_ESDP, esdp_reg);
619 IXGBE_WRITE_FLUSH(hw);
620 msleep(100);
621}
622
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +0000623/**
Mallikarjuna R Chilakala1097cd12010-03-18 14:34:52 +0000624 * ixgbe_flap_tx_laser_multispeed_fiber - Flap Tx laser
625 * @hw: pointer to hardware structure
626 *
627 * When the driver changes the link speeds that it can support,
628 * it sets autotry_restart to true to indicate that we need to
629 * initiate a new autotry session with the link partner. To do
630 * so, we set the speed then disable and re-enable the tx laser, to
631 * alert the link partner that it also needs to restart autotry on its
632 * end. This is consistent with true clause 37 autoneg, which also
633 * involves a loss of signal.
634 **/
Emil Tantilov5d5b7c32010-10-12 22:20:59 +0000635static void ixgbe_flap_tx_laser_multispeed_fiber(struct ixgbe_hw *hw)
Mallikarjuna R Chilakala1097cd12010-03-18 14:34:52 +0000636{
Don Skidmorec97506a2014-02-27 20:32:43 -0800637 /* Blocked by MNG FW so bail */
638 if (ixgbe_check_reset_blocked(hw))
639 return;
640
Mallikarjuna R Chilakala1097cd12010-03-18 14:34:52 +0000641 if (hw->mac.autotry_restart) {
Peter Waskiewicz61fac742010-04-27 00:38:15 +0000642 ixgbe_disable_tx_laser_multispeed_fiber(hw);
643 ixgbe_enable_tx_laser_multispeed_fiber(hw);
Mallikarjuna R Chilakala1097cd12010-03-18 14:34:52 +0000644 hw->mac.autotry_restart = false;
645 }
646}
647
648/**
Mark Rustad6d373a12015-08-08 16:18:28 -0700649 * ixgbe_set_hard_rate_select_speed - Set module link speed
650 * @hw: pointer to hardware structure
651 * @speed: link speed to set
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +0000652 *
Mark Rustad6d373a12015-08-08 16:18:28 -0700653 * Set module link speed via RS0/RS1 rate select pins.
654 */
655static void
656ixgbe_set_hard_rate_select_speed(struct ixgbe_hw *hw, ixgbe_link_speed speed)
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +0000657{
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +0000658 u32 esdp_reg = IXGBE_READ_REG(hw, IXGBE_ESDP);
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +0000659
Mark Rustad6d373a12015-08-08 16:18:28 -0700660 switch (speed) {
661 case IXGBE_LINK_SPEED_10GB_FULL:
662 esdp_reg |= (IXGBE_ESDP_SDP5_DIR | IXGBE_ESDP_SDP5);
663 break;
664 case IXGBE_LINK_SPEED_1GB_FULL:
665 esdp_reg &= ~IXGBE_ESDP_SDP5;
666 esdp_reg |= IXGBE_ESDP_SDP5_DIR;
667 break;
668 default:
669 hw_dbg(hw, "Invalid fixed module speed\n");
670 return;
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +0000671 }
672
Mark Rustad6d373a12015-08-08 16:18:28 -0700673 IXGBE_WRITE_REG(hw, IXGBE_ESDP, esdp_reg);
674 IXGBE_WRITE_FLUSH(hw);
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +0000675}
676
677/**
Don Skidmorecd7e1f02009-10-08 15:36:22 +0000678 * ixgbe_setup_mac_link_smartspeed - Set MAC link speed using SmartSpeed
679 * @hw: pointer to hardware structure
680 * @speed: new link speed
Don Skidmorecd7e1f02009-10-08 15:36:22 +0000681 * @autoneg_wait_to_complete: true when waiting for completion is needed
682 *
683 * Implements the Intel SmartSpeed algorithm.
684 **/
685static s32 ixgbe_setup_mac_link_smartspeed(struct ixgbe_hw *hw,
Josh Hayfd0326f2012-12-15 03:28:30 +0000686 ixgbe_link_speed speed,
Don Skidmorecd7e1f02009-10-08 15:36:22 +0000687 bool autoneg_wait_to_complete)
688{
689 s32 status = 0;
Emil Tantilov037c6d02011-02-25 07:49:39 +0000690 ixgbe_link_speed link_speed = IXGBE_LINK_SPEED_UNKNOWN;
Don Skidmorecd7e1f02009-10-08 15:36:22 +0000691 s32 i, j;
692 bool link_up = false;
693 u32 autoc_reg = IXGBE_READ_REG(hw, IXGBE_AUTOC);
Don Skidmorecd7e1f02009-10-08 15:36:22 +0000694
695 /* Set autoneg_advertised value based on input link speed */
696 hw->phy.autoneg_advertised = 0;
697
698 if (speed & IXGBE_LINK_SPEED_10GB_FULL)
699 hw->phy.autoneg_advertised |= IXGBE_LINK_SPEED_10GB_FULL;
700
701 if (speed & IXGBE_LINK_SPEED_1GB_FULL)
702 hw->phy.autoneg_advertised |= IXGBE_LINK_SPEED_1GB_FULL;
703
704 if (speed & IXGBE_LINK_SPEED_100_FULL)
705 hw->phy.autoneg_advertised |= IXGBE_LINK_SPEED_100_FULL;
706
707 /*
708 * Implement Intel SmartSpeed algorithm. SmartSpeed will reduce the
709 * autoneg advertisement if link is unable to be established at the
710 * highest negotiated rate. This can sometimes happen due to integrity
711 * issues with the physical media connection.
712 */
713
714 /* First, try to get link with full advertisement */
715 hw->phy.smart_speed_active = false;
716 for (j = 0; j < IXGBE_SMARTSPEED_MAX_RETRIES; j++) {
Josh Hayfd0326f2012-12-15 03:28:30 +0000717 status = ixgbe_setup_mac_link_82599(hw, speed,
Don Skidmorecd7e1f02009-10-08 15:36:22 +0000718 autoneg_wait_to_complete);
Emil Tantilov037c6d02011-02-25 07:49:39 +0000719 if (status != 0)
Don Skidmorecd7e1f02009-10-08 15:36:22 +0000720 goto out;
721
722 /*
723 * Wait for the controller to acquire link. Per IEEE 802.3ap,
724 * Section 73.10.2, we may have to wait up to 500ms if KR is
725 * attempted, or 200ms if KX/KX4/BX/BX4 is attempted, per
726 * Table 9 in the AN MAS.
727 */
728 for (i = 0; i < 5; i++) {
729 mdelay(100);
730
731 /* If we have link, just jump out */
Emil Tantilov037c6d02011-02-25 07:49:39 +0000732 status = hw->mac.ops.check_link(hw, &link_speed,
733 &link_up, false);
734 if (status != 0)
735 goto out;
736
Don Skidmorecd7e1f02009-10-08 15:36:22 +0000737 if (link_up)
738 goto out;
739 }
740 }
741
742 /*
743 * We didn't get link. If we advertised KR plus one of KX4/KX
744 * (or BX4/BX), then disable KR and try again.
745 */
746 if (((autoc_reg & IXGBE_AUTOC_KR_SUPP) == 0) ||
747 ((autoc_reg & IXGBE_AUTOC_KX4_KX_SUPP_MASK) == 0))
748 goto out;
749
750 /* Turn SmartSpeed on to disable KR support */
751 hw->phy.smart_speed_active = true;
Josh Hayfd0326f2012-12-15 03:28:30 +0000752 status = ixgbe_setup_mac_link_82599(hw, speed,
Don Skidmorecd7e1f02009-10-08 15:36:22 +0000753 autoneg_wait_to_complete);
Emil Tantilov037c6d02011-02-25 07:49:39 +0000754 if (status != 0)
Don Skidmorecd7e1f02009-10-08 15:36:22 +0000755 goto out;
756
757 /*
758 * Wait for the controller to acquire link. 600ms will allow for
759 * the AN link_fail_inhibit_timer as well for multiple cycles of
760 * parallel detect, both 10g and 1g. This allows for the maximum
761 * connect attempts as defined in the AN MAS table 73-7.
762 */
763 for (i = 0; i < 6; i++) {
764 mdelay(100);
765
766 /* If we have link, just jump out */
Emil Tantilov037c6d02011-02-25 07:49:39 +0000767 status = hw->mac.ops.check_link(hw, &link_speed,
768 &link_up, false);
769 if (status != 0)
770 goto out;
771
Don Skidmorecd7e1f02009-10-08 15:36:22 +0000772 if (link_up)
773 goto out;
774 }
775
776 /* We didn't get link. Turn SmartSpeed back off. */
777 hw->phy.smart_speed_active = false;
Josh Hayfd0326f2012-12-15 03:28:30 +0000778 status = ixgbe_setup_mac_link_82599(hw, speed,
Don Skidmorecd7e1f02009-10-08 15:36:22 +0000779 autoneg_wait_to_complete);
780
781out:
Anjali Singhaic4ee6a52010-04-27 11:31:25 +0000782 if (link_up && (link_speed == IXGBE_LINK_SPEED_1GB_FULL))
Jacob Keller305f8ce2014-02-22 01:23:52 +0000783 hw_dbg(hw, "Smartspeed has downgraded the link speed from the maximum advertised\n");
Don Skidmorecd7e1f02009-10-08 15:36:22 +0000784 return status;
785}
786
787/**
Mallikarjuna R Chilakala8620a102009-09-01 13:49:35 +0000788 * ixgbe_setup_mac_link_82599 - Set MAC link speed
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +0000789 * @hw: pointer to hardware structure
790 * @speed: new link speed
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +0000791 * @autoneg_wait_to_complete: true when waiting for completion is needed
792 *
793 * Set the link speed in the AUTOC register and restarts link.
794 **/
Emil Tantilov5d5b7c32010-10-12 22:20:59 +0000795static s32 ixgbe_setup_mac_link_82599(struct ixgbe_hw *hw,
Josh Hayfd0326f2012-12-15 03:28:30 +0000796 ixgbe_link_speed speed,
797 bool autoneg_wait_to_complete)
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +0000798{
Josh Hayfd0326f2012-12-15 03:28:30 +0000799 bool autoneg = false;
Mark Rustade90dd262014-07-22 06:51:08 +0000800 s32 status;
Jacob Kelleree98b572014-02-22 01:23:56 +0000801 u32 pma_pmd_1g, link_mode, links_reg, i;
802 u32 autoc2 = IXGBE_READ_REG(hw, IXGBE_AUTOC2);
803 u32 pma_pmd_10g_serial = autoc2 & IXGBE_AUTOC2_10G_SERIAL_PMA_PMD_MASK;
804 ixgbe_link_speed link_capabilities = IXGBE_LINK_SPEED_UNKNOWN;
805
806 /* holds the value of AUTOC register at this current point in time */
807 u32 current_autoc = IXGBE_READ_REG(hw, IXGBE_AUTOC);
808 /* holds the cached value of AUTOC register */
809 u32 orig_autoc = 0;
810 /* temporary variable used for comparison purposes */
811 u32 autoc = current_autoc;
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +0000812
813 /* Check to see if speed passed in is supported. */
Don Skidmore9cdcf092012-02-17 07:38:13 +0000814 status = hw->mac.ops.get_link_capabilities(hw, &link_capabilities,
815 &autoneg);
Mark Rustade90dd262014-07-22 06:51:08 +0000816 if (status)
817 return status;
Emil Tantilov0b0c2b32011-02-26 06:40:16 +0000818
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +0000819 speed &= link_capabilities;
820
Mark Rustade90dd262014-07-22 06:51:08 +0000821 if (speed == IXGBE_LINK_SPEED_UNKNOWN)
822 return IXGBE_ERR_LINK_SETUP;
Peter P Waskiewicz Jr50ac58b2009-06-04 11:10:53 +0000823
PJ Waskiewicz1eb99d52009-04-09 22:28:33 +0000824 /* Use stored value (EEPROM defaults) of AUTOC to find KR/KX4 support*/
825 if (hw->mac.orig_link_settings_stored)
Jacob Kelleree98b572014-02-22 01:23:56 +0000826 orig_autoc = hw->mac.orig_autoc;
PJ Waskiewicz1eb99d52009-04-09 22:28:33 +0000827 else
Jacob Kelleree98b572014-02-22 01:23:56 +0000828 orig_autoc = autoc;
Emil Tantilov5e82f2f2013-04-12 08:36:42 +0000829
Emil Tantilov5e82f2f2013-04-12 08:36:42 +0000830 link_mode = autoc & IXGBE_AUTOC_LMS_MASK;
831 pma_pmd_1g = autoc & IXGBE_AUTOC_1G_PMA_PMD_MASK;
PJ Waskiewicz1eb99d52009-04-09 22:28:33 +0000832
Peter P Waskiewicz Jr50ac58b2009-06-04 11:10:53 +0000833 if (link_mode == IXGBE_AUTOC_LMS_KX4_KX_KR ||
834 link_mode == IXGBE_AUTOC_LMS_KX4_KX_KR_1G_AN ||
835 link_mode == IXGBE_AUTOC_LMS_KX4_KX_KR_SGMII) {
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +0000836 /* Set KX4/KX/KR support according to speed requested */
837 autoc &= ~(IXGBE_AUTOC_KX4_KX_SUPP_MASK | IXGBE_AUTOC_KR_SUPP);
Emil Tantilov55461dd2012-08-10 07:35:14 +0000838 if (speed & IXGBE_LINK_SPEED_10GB_FULL) {
PJ Waskiewicz1eb99d52009-04-09 22:28:33 +0000839 if (orig_autoc & IXGBE_AUTOC_KX4_SUPP)
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +0000840 autoc |= IXGBE_AUTOC_KX4_SUPP;
Don Skidmorecd7e1f02009-10-08 15:36:22 +0000841 if ((orig_autoc & IXGBE_AUTOC_KR_SUPP) &&
842 (hw->phy.smart_speed_active == false))
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +0000843 autoc |= IXGBE_AUTOC_KR_SUPP;
Emil Tantilov55461dd2012-08-10 07:35:14 +0000844 }
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +0000845 if (speed & IXGBE_LINK_SPEED_1GB_FULL)
846 autoc |= IXGBE_AUTOC_KX_SUPP;
847 } else if ((pma_pmd_1g == IXGBE_AUTOC_1G_SFI) &&
Jacob Kellere7cf7452014-04-09 06:03:10 +0000848 (link_mode == IXGBE_AUTOC_LMS_1G_LINK_NO_AN ||
849 link_mode == IXGBE_AUTOC_LMS_1G_AN)) {
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +0000850 /* Switch from 1G SFI to 10G SFI if requested */
851 if ((speed == IXGBE_LINK_SPEED_10GB_FULL) &&
852 (pma_pmd_10g_serial == IXGBE_AUTOC2_10G_SFI)) {
853 autoc &= ~IXGBE_AUTOC_LMS_MASK;
854 autoc |= IXGBE_AUTOC_LMS_10G_SERIAL;
855 }
856 } else if ((pma_pmd_10g_serial == IXGBE_AUTOC2_10G_SFI) &&
Jacob Kellere7cf7452014-04-09 06:03:10 +0000857 (link_mode == IXGBE_AUTOC_LMS_10G_SERIAL)) {
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +0000858 /* Switch from 10G SFI to 1G SFI if requested */
859 if ((speed == IXGBE_LINK_SPEED_1GB_FULL) &&
860 (pma_pmd_1g == IXGBE_AUTOC_1G_SFI)) {
861 autoc &= ~IXGBE_AUTOC_LMS_MASK;
862 if (autoneg)
863 autoc |= IXGBE_AUTOC_LMS_1G_AN;
864 else
865 autoc |= IXGBE_AUTOC_LMS_1G_LINK_NO_AN;
866 }
867 }
868
Jacob Kelleree98b572014-02-22 01:23:56 +0000869 if (autoc != current_autoc) {
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +0000870 /* Restart link */
Don Skidmore429d6a32014-02-27 20:32:41 -0800871 status = hw->mac.ops.prot_autoc_write(hw, autoc, false);
Don Skidmoref8cf7a02014-03-19 09:16:26 +0000872 if (status)
Mark Rustade90dd262014-07-22 06:51:08 +0000873 return status;
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +0000874
875 /* Only poll for autoneg to complete if specified to do so */
876 if (autoneg_wait_to_complete) {
877 if (link_mode == IXGBE_AUTOC_LMS_KX4_KX_KR ||
878 link_mode == IXGBE_AUTOC_LMS_KX4_KX_KR_1G_AN ||
879 link_mode == IXGBE_AUTOC_LMS_KX4_KX_KR_SGMII) {
880 links_reg = 0; /*Just in case Autoneg time=0*/
881 for (i = 0; i < IXGBE_AUTO_NEG_TIME; i++) {
882 links_reg =
883 IXGBE_READ_REG(hw, IXGBE_LINKS);
884 if (links_reg & IXGBE_LINKS_KX_AN_COMP)
885 break;
886 msleep(100);
887 }
888 if (!(links_reg & IXGBE_LINKS_KX_AN_COMP)) {
889 status =
Jacob Kellere7cf7452014-04-09 06:03:10 +0000890 IXGBE_ERR_AUTONEG_NOT_COMPLETE;
Jacob Keller305f8ce2014-02-22 01:23:52 +0000891 hw_dbg(hw, "Autoneg did not complete.\n");
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +0000892 }
893 }
894 }
895
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +0000896 /* Add delay to filter out noises during initial link setup */
897 msleep(50);
898 }
899
900 return status;
901}
902
903/**
Mallikarjuna R Chilakala8620a102009-09-01 13:49:35 +0000904 * ixgbe_setup_copper_link_82599 - Set the PHY autoneg advertised field
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +0000905 * @hw: pointer to hardware structure
906 * @speed: new link speed
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +0000907 * @autoneg_wait_to_complete: true if waiting is needed to complete
908 *
909 * Restarts link on PHY and MAC based on settings passed in.
910 **/
Mallikarjuna R Chilakala8620a102009-09-01 13:49:35 +0000911static s32 ixgbe_setup_copper_link_82599(struct ixgbe_hw *hw,
Jacob Kellere7cf7452014-04-09 06:03:10 +0000912 ixgbe_link_speed speed,
913 bool autoneg_wait_to_complete)
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +0000914{
915 s32 status;
916
917 /* Setup the PHY according to input speed */
Josh Hay99b76642012-12-15 03:28:24 +0000918 status = hw->phy.ops.setup_link_speed(hw, speed,
Jacob Kellere7cf7452014-04-09 06:03:10 +0000919 autoneg_wait_to_complete);
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +0000920 /* Set up MAC */
Mallikarjuna R Chilakala8620a102009-09-01 13:49:35 +0000921 ixgbe_start_mac_link_82599(hw, autoneg_wait_to_complete);
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +0000922
923 return status;
924}
925
926/**
927 * ixgbe_reset_hw_82599 - Perform hardware reset
928 * @hw: pointer to hardware structure
929 *
930 * Resets the hardware by resetting the transmit and receive units, masks
931 * and clears all interrupts, perform a PHY reset, and perform a link (MAC)
932 * reset.
933 **/
Don Skidmore7b25cdb2009-08-25 04:47:32 +0000934static s32 ixgbe_reset_hw_82599(struct ixgbe_hw *hw)
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +0000935{
Alexander Duyck8132b542011-07-15 07:29:44 +0000936 ixgbe_link_speed link_speed;
937 s32 status;
Don Skidmore429d6a32014-02-27 20:32:41 -0800938 u32 ctrl, i, autoc, autoc2;
Don Skidmore0b2679d2013-02-21 03:00:04 +0000939 u32 curr_lms;
Alexander Duyck8132b542011-07-15 07:29:44 +0000940 bool link_up = false;
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +0000941
942 /* Call adapter stop to disable tx/rx and clear interrupts */
Emil Tantilovff9d1a52011-08-16 04:35:11 +0000943 status = hw->mac.ops.stop_adapter(hw);
Mark Rustade90dd262014-07-22 06:51:08 +0000944 if (status)
945 return status;
Emil Tantilovff9d1a52011-08-16 04:35:11 +0000946
947 /* flush pending Tx transactions */
948 ixgbe_clear_tx_pending(hw);
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +0000949
PJ Waskiewicz553b4492009-04-09 22:28:15 +0000950 /* PHY ops must be identified and initialized prior to reset */
PJ Waskiewicz04f165e2009-04-09 22:27:57 +0000951
Emil Tantilov037c6d02011-02-25 07:49:39 +0000952 /* Identify PHY and related function pointers */
PJ Waskiewicz553b4492009-04-09 22:28:15 +0000953 status = hw->phy.ops.init(hw);
PJ Waskiewicz04f165e2009-04-09 22:27:57 +0000954
PJ Waskiewicz553b4492009-04-09 22:28:15 +0000955 if (status == IXGBE_ERR_SFP_NOT_SUPPORTED)
Mark Rustade90dd262014-07-22 06:51:08 +0000956 return status;
PJ Waskiewicz04f165e2009-04-09 22:27:57 +0000957
PJ Waskiewicz553b4492009-04-09 22:28:15 +0000958 /* Setup SFP module if there is one present. */
959 if (hw->phy.sfp_setup_needed) {
960 status = hw->mac.ops.setup_sfp(hw);
961 hw->phy.sfp_setup_needed = false;
PJ Waskiewicz04f165e2009-04-09 22:27:57 +0000962 }
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +0000963
Emil Tantilov037c6d02011-02-25 07:49:39 +0000964 if (status == IXGBE_ERR_SFP_NOT_SUPPORTED)
Mark Rustade90dd262014-07-22 06:51:08 +0000965 return status;
Emil Tantilov037c6d02011-02-25 07:49:39 +0000966
PJ Waskiewicz553b4492009-04-09 22:28:15 +0000967 /* Reset PHY */
968 if (hw->phy.reset_disable == false && hw->phy.ops.reset != NULL)
969 hw->phy.ops.reset(hw);
970
Emil Tantilov5e82f2f2013-04-12 08:36:42 +0000971 /* remember AUTOC from before we reset */
Don Skidmore429d6a32014-02-27 20:32:41 -0800972 curr_lms = IXGBE_READ_REG(hw, IXGBE_AUTOC) & IXGBE_AUTOC_LMS_MASK;
Don Skidmore0b2679d2013-02-21 03:00:04 +0000973
Emil Tantilova4297dc2011-02-14 08:45:13 +0000974mac_reset_top:
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +0000975 /*
Alexander Duyck8132b542011-07-15 07:29:44 +0000976 * Issue global reset to the MAC. Needs to be SW reset if link is up.
977 * If link reset is used when link is up, it might reset the PHY when
978 * mng is using it. If link is down or the flag to force full link
979 * reset is set, then perform link reset.
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +0000980 */
Alexander Duyck8132b542011-07-15 07:29:44 +0000981 ctrl = IXGBE_CTRL_LNK_RST;
982 if (!hw->force_full_reset) {
983 hw->mac.ops.check_link(hw, &link_speed, &link_up, false);
984 if (link_up)
985 ctrl = IXGBE_CTRL_RST;
986 }
987
988 ctrl |= IXGBE_READ_REG(hw, IXGBE_CTRL);
989 IXGBE_WRITE_REG(hw, IXGBE_CTRL, ctrl);
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +0000990 IXGBE_WRITE_FLUSH(hw);
Mark Rustadefff2e02015-10-27 13:23:14 -0700991 usleep_range(1000, 1200);
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +0000992
993 /* Poll for reset bit to self-clear indicating reset is complete */
994 for (i = 0; i < 10; i++) {
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +0000995 ctrl = IXGBE_READ_REG(hw, IXGBE_CTRL);
Alexander Duyck8132b542011-07-15 07:29:44 +0000996 if (!(ctrl & IXGBE_CTRL_RST_MASK))
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +0000997 break;
Mark Rustadefff2e02015-10-27 13:23:14 -0700998 udelay(1);
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +0000999 }
Alexander Duyck8132b542011-07-15 07:29:44 +00001000
1001 if (ctrl & IXGBE_CTRL_RST_MASK) {
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001002 status = IXGBE_ERR_RESET_FAILED;
1003 hw_dbg(hw, "Reset polling failed to complete.\n");
1004 }
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001005
Alexander Duyck8132b542011-07-15 07:29:44 +00001006 msleep(50);
1007
Emil Tantilova4297dc2011-02-14 08:45:13 +00001008 /*
1009 * Double resets are required for recovery from certain error
1010 * conditions. Between resets, it is necessary to stall to allow time
Alexander Duyck8132b542011-07-15 07:29:44 +00001011 * for any pending HW events to complete.
Emil Tantilova4297dc2011-02-14 08:45:13 +00001012 */
1013 if (hw->mac.flags & IXGBE_FLAGS_DOUBLE_RESET_REQUIRED) {
1014 hw->mac.flags &= ~IXGBE_FLAGS_DOUBLE_RESET_REQUIRED;
Emil Tantilova4297dc2011-02-14 08:45:13 +00001015 goto mac_reset_top;
1016 }
1017
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001018 /*
1019 * Store the original AUTOC/AUTOC2 values if they have not been
1020 * stored off yet. Otherwise restore the stored original
1021 * values since the reset operation sets back to defaults.
1022 */
Don Skidmore429d6a32014-02-27 20:32:41 -08001023 autoc = IXGBE_READ_REG(hw, IXGBE_AUTOC);
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001024 autoc2 = IXGBE_READ_REG(hw, IXGBE_AUTOC2);
Emil Tantilov46d5ced2013-04-12 08:36:47 +00001025
1026 /* Enable link if disabled in NVM */
1027 if (autoc2 & IXGBE_AUTOC2_LINK_DISABLE_MASK) {
1028 autoc2 &= ~IXGBE_AUTOC2_LINK_DISABLE_MASK;
1029 IXGBE_WRITE_REG(hw, IXGBE_AUTOC2, autoc2);
1030 IXGBE_WRITE_FLUSH(hw);
1031 }
1032
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001033 if (hw->mac.orig_link_settings_stored == false) {
Don Skidmore429d6a32014-02-27 20:32:41 -08001034 hw->mac.orig_autoc = autoc;
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001035 hw->mac.orig_autoc2 = autoc2;
1036 hw->mac.orig_link_settings_stored = true;
Jesse Brandeburg4df10462009-03-13 22:15:31 +00001037 } else {
Don Skidmore0b2679d2013-02-21 03:00:04 +00001038
1039 /* If MNG FW is running on a multi-speed device that
1040 * doesn't autoneg with out driver support we need to
1041 * leave LMS in the state it was before we MAC reset.
Don Skidmoreb8f83632013-02-28 08:08:44 +00001042 * Likewise if we support WoL we don't want change the
1043 * LMS state either.
Don Skidmore0b2679d2013-02-21 03:00:04 +00001044 */
Don Skidmore7155d052014-02-27 09:03:30 +00001045 if ((hw->phy.multispeed_fiber && ixgbe_mng_enabled(hw)) ||
Jacob Keller6b92b0b2013-04-13 05:40:37 +00001046 hw->wol_enabled)
Don Skidmore0b2679d2013-02-21 03:00:04 +00001047 hw->mac.orig_autoc =
1048 (hw->mac.orig_autoc & ~IXGBE_AUTOC_LMS_MASK) |
1049 curr_lms;
1050
Don Skidmore429d6a32014-02-27 20:32:41 -08001051 if (autoc != hw->mac.orig_autoc) {
1052 status = hw->mac.ops.prot_autoc_write(hw,
1053 hw->mac.orig_autoc,
1054 false);
Don Skidmoref8cf7a02014-03-19 09:16:26 +00001055 if (status)
Mark Rustade90dd262014-07-22 06:51:08 +00001056 return status;
Don Skidmored7bbcd32012-10-24 06:19:01 +00001057 }
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001058
1059 if ((autoc2 & IXGBE_AUTOC2_UPPER_MASK) !=
1060 (hw->mac.orig_autoc2 & IXGBE_AUTOC2_UPPER_MASK)) {
1061 autoc2 &= ~IXGBE_AUTOC2_UPPER_MASK;
1062 autoc2 |= (hw->mac.orig_autoc2 &
Jacob Kellere7cf7452014-04-09 06:03:10 +00001063 IXGBE_AUTOC2_UPPER_MASK);
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001064 IXGBE_WRITE_REG(hw, IXGBE_AUTOC2, autoc2);
1065 }
1066 }
1067
Emil Tantilov278675d2011-02-19 08:43:49 +00001068 /* Store the permanent mac address */
1069 hw->mac.ops.get_mac_addr(hw, hw->mac.perm_addr);
1070
Waskiewicz Jr, Peter Paca6bee2009-05-17 12:32:48 +00001071 /*
1072 * Store MAC address from RAR0, clear receive address registers, and
1073 * clear the multicast table. Also reset num_rar_entries to 128,
1074 * since we modify this value when programming the SAN MAC address.
1075 */
1076 hw->mac.num_rar_entries = 128;
1077 hw->mac.ops.init_rx_addrs(hw);
1078
PJ Waskiewicz0365e6e2009-05-17 12:32:25 +00001079 /* Store the permanent SAN mac address */
1080 hw->mac.ops.get_san_mac_addr(hw, hw->mac.san_addr);
1081
Waskiewicz Jr, Peter Paca6bee2009-05-17 12:32:48 +00001082 /* Add the SAN MAC address to the RAR only if it's a valid address */
Joe Perchesf8ebc682012-10-24 17:19:02 +00001083 if (is_valid_ether_addr(hw->mac.san_addr)) {
Alexander Duyck7fa7c9d2012-05-05 05:32:52 +00001084 /* Save the SAN MAC RAR index */
1085 hw->mac.san_mac_rar_index = hw->mac.num_rar_entries - 1;
1086
Alexander Duyck6e982ae2015-11-02 17:10:26 -08001087 hw->mac.ops.set_rar(hw, hw->mac.san_mac_rar_index,
1088 hw->mac.san_addr, 0, IXGBE_RAH_AV);
1089
1090 /* clear VMDq pool/queue selection for this RAR */
1091 hw->mac.ops.clear_vmdq(hw, hw->mac.san_mac_rar_index,
1092 IXGBE_CLEAR_VMDQ_ALL);
1093
Waskiewicz Jr, Peter Paca6bee2009-05-17 12:32:48 +00001094 /* Reserve the last RAR for the SAN MAC address */
1095 hw->mac.num_rar_entries--;
1096 }
1097
Yi Zou383ff342009-10-28 18:23:57 +00001098 /* Store the alternative WWNN/WWPN prefix */
1099 hw->mac.ops.get_wwn_prefix(hw, &hw->mac.wwnn_prefix,
Jacob Kellere7cf7452014-04-09 06:03:10 +00001100 &hw->mac.wwpn_prefix);
Yi Zou383ff342009-10-28 18:23:57 +00001101
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001102 return status;
1103}
1104
1105/**
Mark Rustadd490d152015-06-11 11:02:20 -07001106 * ixgbe_fdir_check_cmd_complete - poll to check whether FDIRCMD is complete
1107 * @hw: pointer to hardware structure
1108 * @fdircmd: current value of FDIRCMD register
1109 */
1110static s32 ixgbe_fdir_check_cmd_complete(struct ixgbe_hw *hw, u32 *fdircmd)
1111{
1112 int i;
1113
1114 for (i = 0; i < IXGBE_FDIRCMD_CMD_POLL; i++) {
1115 *fdircmd = IXGBE_READ_REG(hw, IXGBE_FDIRCMD);
1116 if (!(*fdircmd & IXGBE_FDIRCMD_CMD_MASK))
1117 return 0;
1118 udelay(10);
1119 }
1120
1121 return IXGBE_ERR_FDIR_CMD_INCOMPLETE;
1122}
1123
1124/**
Peter P Waskiewicz Jrffff4772009-06-04 16:01:25 +00001125 * ixgbe_reinit_fdir_tables_82599 - Reinitialize Flow Director tables.
1126 * @hw: pointer to hardware structure
1127 **/
1128s32 ixgbe_reinit_fdir_tables_82599(struct ixgbe_hw *hw)
1129{
1130 int i;
1131 u32 fdirctrl = IXGBE_READ_REG(hw, IXGBE_FDIRCTRL);
Mark Rustadd490d152015-06-11 11:02:20 -07001132 u32 fdircmd;
1133 s32 err;
Jacob Keller2b2005d2014-04-09 06:03:12 +00001134
Peter P Waskiewicz Jrffff4772009-06-04 16:01:25 +00001135 fdirctrl &= ~IXGBE_FDIRCTRL_INIT_DONE;
1136
1137 /*
1138 * Before starting reinitialization process,
1139 * FDIRCMD.CMD must be zero.
1140 */
Mark Rustadd490d152015-06-11 11:02:20 -07001141 err = ixgbe_fdir_check_cmd_complete(hw, &fdircmd);
1142 if (err) {
1143 hw_dbg(hw, "Flow Director previous command did not complete, aborting table re-initialization.\n");
1144 return err;
Peter P Waskiewicz Jrffff4772009-06-04 16:01:25 +00001145 }
1146
1147 IXGBE_WRITE_REG(hw, IXGBE_FDIRFREE, 0);
1148 IXGBE_WRITE_FLUSH(hw);
1149 /*
1150 * 82599 adapters flow director init flow cannot be restarted,
1151 * Workaround 82599 silicon errata by performing the following steps
1152 * before re-writing the FDIRCTRL control register with the same value.
1153 * - write 1 to bit 8 of FDIRCMD register &
1154 * - write 0 to bit 8 of FDIRCMD register
1155 */
1156 IXGBE_WRITE_REG(hw, IXGBE_FDIRCMD,
Jacob Kellere7cf7452014-04-09 06:03:10 +00001157 (IXGBE_READ_REG(hw, IXGBE_FDIRCMD) |
1158 IXGBE_FDIRCMD_CLEARHT));
Peter P Waskiewicz Jrffff4772009-06-04 16:01:25 +00001159 IXGBE_WRITE_FLUSH(hw);
1160 IXGBE_WRITE_REG(hw, IXGBE_FDIRCMD,
Jacob Kellere7cf7452014-04-09 06:03:10 +00001161 (IXGBE_READ_REG(hw, IXGBE_FDIRCMD) &
1162 ~IXGBE_FDIRCMD_CLEARHT));
Peter P Waskiewicz Jrffff4772009-06-04 16:01:25 +00001163 IXGBE_WRITE_FLUSH(hw);
1164 /*
1165 * Clear FDIR Hash register to clear any leftover hashes
1166 * waiting to be programmed.
1167 */
1168 IXGBE_WRITE_REG(hw, IXGBE_FDIRHASH, 0x00);
1169 IXGBE_WRITE_FLUSH(hw);
1170
1171 IXGBE_WRITE_REG(hw, IXGBE_FDIRCTRL, fdirctrl);
1172 IXGBE_WRITE_FLUSH(hw);
1173
1174 /* Poll init-done after we write FDIRCTRL register */
1175 for (i = 0; i < IXGBE_FDIR_INIT_DONE_POLL; i++) {
1176 if (IXGBE_READ_REG(hw, IXGBE_FDIRCTRL) &
Jacob Kellere7cf7452014-04-09 06:03:10 +00001177 IXGBE_FDIRCTRL_INIT_DONE)
Peter P Waskiewicz Jrffff4772009-06-04 16:01:25 +00001178 break;
Emil Tantilov4a97df02012-09-20 03:33:51 +00001179 usleep_range(1000, 2000);
Peter P Waskiewicz Jrffff4772009-06-04 16:01:25 +00001180 }
1181 if (i >= IXGBE_FDIR_INIT_DONE_POLL) {
1182 hw_dbg(hw, "Flow Director Signature poll time exceeded!\n");
1183 return IXGBE_ERR_FDIR_REINIT_FAILED;
1184 }
1185
1186 /* Clear FDIR statistics registers (read to clear) */
1187 IXGBE_READ_REG(hw, IXGBE_FDIRUSTAT);
1188 IXGBE_READ_REG(hw, IXGBE_FDIRFSTAT);
1189 IXGBE_READ_REG(hw, IXGBE_FDIRMATCH);
1190 IXGBE_READ_REG(hw, IXGBE_FDIRMISS);
1191 IXGBE_READ_REG(hw, IXGBE_FDIRLEN);
1192
1193 return 0;
1194}
1195
1196/**
Alexander Duyckc04f6ca2011-05-11 07:18:36 +00001197 * ixgbe_fdir_enable_82599 - Initialize Flow Director control registers
1198 * @hw: pointer to hardware structure
1199 * @fdirctrl: value to write to flow director control register
1200 **/
1201static void ixgbe_fdir_enable_82599(struct ixgbe_hw *hw, u32 fdirctrl)
1202{
1203 int i;
Peter P Waskiewicz Jrffff4772009-06-04 16:01:25 +00001204
1205 /* Prime the keys for hashing */
Alexander Duyck905e4a42011-01-06 14:29:57 +00001206 IXGBE_WRITE_REG(hw, IXGBE_FDIRHKEY, IXGBE_ATR_BUCKET_HASH_KEY);
1207 IXGBE_WRITE_REG(hw, IXGBE_FDIRSKEY, IXGBE_ATR_SIGNATURE_HASH_KEY);
Peter P Waskiewicz Jrffff4772009-06-04 16:01:25 +00001208
1209 /*
1210 * Poll init-done after we write the register. Estimated times:
1211 * 10G: PBALLOC = 11b, timing is 60us
1212 * 1G: PBALLOC = 11b, timing is 600us
1213 * 100M: PBALLOC = 11b, timing is 6ms
1214 *
1215 * Multiple these timings by 4 if under full Rx load
1216 *
1217 * So we'll poll for IXGBE_FDIR_INIT_DONE_POLL times, sleeping for
1218 * 1 msec per poll time. If we're at line rate and drop to 100M, then
1219 * this might not finish in our poll time, but we can live with that
1220 * for now.
1221 */
1222 IXGBE_WRITE_REG(hw, IXGBE_FDIRCTRL, fdirctrl);
1223 IXGBE_WRITE_FLUSH(hw);
1224 for (i = 0; i < IXGBE_FDIR_INIT_DONE_POLL; i++) {
1225 if (IXGBE_READ_REG(hw, IXGBE_FDIRCTRL) &
Jacob Kellere7cf7452014-04-09 06:03:10 +00001226 IXGBE_FDIRCTRL_INIT_DONE)
Peter P Waskiewicz Jrffff4772009-06-04 16:01:25 +00001227 break;
Don Skidmore032b4322011-03-18 09:32:53 +00001228 usleep_range(1000, 2000);
Peter P Waskiewicz Jrffff4772009-06-04 16:01:25 +00001229 }
Alexander Duyckc04f6ca2011-05-11 07:18:36 +00001230
Peter P Waskiewicz Jrffff4772009-06-04 16:01:25 +00001231 if (i >= IXGBE_FDIR_INIT_DONE_POLL)
Alexander Duyckc04f6ca2011-05-11 07:18:36 +00001232 hw_dbg(hw, "Flow Director poll time exceeded!\n");
1233}
1234
1235/**
1236 * ixgbe_init_fdir_signature_82599 - Initialize Flow Director signature filters
1237 * @hw: pointer to hardware structure
1238 * @fdirctrl: value to write to flow director control register, initially
1239 * contains just the value of the Rx packet buffer allocation
1240 **/
1241s32 ixgbe_init_fdir_signature_82599(struct ixgbe_hw *hw, u32 fdirctrl)
1242{
Alexander Duyckc04f6ca2011-05-11 07:18:36 +00001243 /*
1244 * Continue setup of fdirctrl register bits:
1245 * Move the flexible bytes to use the ethertype - shift 6 words
1246 * Set the maximum length per hash bucket to 0xA filters
1247 * Send interrupt when 64 filters are left
1248 */
1249 fdirctrl |= (0x6 << IXGBE_FDIRCTRL_FLEX_SHIFT) |
1250 (0xA << IXGBE_FDIRCTRL_MAX_LENGTH_SHIFT) |
1251 (4 << IXGBE_FDIRCTRL_FULL_THRESH_SHIFT);
1252
1253 /* write hashes and fdirctrl register, poll for completion */
1254 ixgbe_fdir_enable_82599(hw, fdirctrl);
Peter P Waskiewicz Jrffff4772009-06-04 16:01:25 +00001255
1256 return 0;
1257}
1258
1259/**
1260 * ixgbe_init_fdir_perfect_82599 - Initialize Flow Director perfect filters
1261 * @hw: pointer to hardware structure
Alexander Duyckc04f6ca2011-05-11 07:18:36 +00001262 * @fdirctrl: value to write to flow director control register, initially
1263 * contains just the value of the Rx packet buffer allocation
Peter P Waskiewicz Jrffff4772009-06-04 16:01:25 +00001264 **/
Alexander Duyckc04f6ca2011-05-11 07:18:36 +00001265s32 ixgbe_init_fdir_perfect_82599(struct ixgbe_hw *hw, u32 fdirctrl)
Peter P Waskiewicz Jrffff4772009-06-04 16:01:25 +00001266{
Peter P Waskiewicz Jrffff4772009-06-04 16:01:25 +00001267 /*
Alexander Duyckc04f6ca2011-05-11 07:18:36 +00001268 * Continue setup of fdirctrl register bits:
1269 * Turn perfect match filtering on
Alexander Duyckc04f6ca2011-05-11 07:18:36 +00001270 * Initialize the drop queue
1271 * Move the flexible bytes to use the ethertype - shift 6 words
1272 * Set the maximum length per hash bucket to 0xA filters
1273 * Send interrupt when 64 (0x4 * 16) filters are left
Peter P Waskiewicz Jrffff4772009-06-04 16:01:25 +00001274 */
Alexander Duyckc04f6ca2011-05-11 07:18:36 +00001275 fdirctrl |= IXGBE_FDIRCTRL_PERFECT_MATCH |
Alexander Duyckc04f6ca2011-05-11 07:18:36 +00001276 (IXGBE_FDIR_DROP_QUEUE << IXGBE_FDIRCTRL_DROP_Q_SHIFT) |
1277 (0x6 << IXGBE_FDIRCTRL_FLEX_SHIFT) |
1278 (0xA << IXGBE_FDIRCTRL_MAX_LENGTH_SHIFT) |
1279 (4 << IXGBE_FDIRCTRL_FULL_THRESH_SHIFT);
Peter P Waskiewicz Jrffff4772009-06-04 16:01:25 +00001280
Alexander Duyckc04f6ca2011-05-11 07:18:36 +00001281 /* write hashes and fdirctrl register, poll for completion */
1282 ixgbe_fdir_enable_82599(hw, fdirctrl);
Peter P Waskiewicz Jrffff4772009-06-04 16:01:25 +00001283
1284 return 0;
1285}
1286
Alexander Duyck69830522011-01-06 14:29:58 +00001287/*
1288 * These defines allow us to quickly generate all of the necessary instructions
1289 * in the function below by simply calling out IXGBE_COMPUTE_SIG_HASH_ITERATION
1290 * for values 0 through 15
1291 */
1292#define IXGBE_ATR_COMMON_HASH_KEY \
1293 (IXGBE_ATR_BUCKET_HASH_KEY & IXGBE_ATR_SIGNATURE_HASH_KEY)
1294#define IXGBE_COMPUTE_SIG_HASH_ITERATION(_n) \
1295do { \
1296 u32 n = (_n); \
Jacob Kellerb4f47a42016-04-13 16:08:22 -07001297 if (IXGBE_ATR_COMMON_HASH_KEY & BIT(n)) \
Alexander Duyck69830522011-01-06 14:29:58 +00001298 common_hash ^= lo_hash_dword >> n; \
Jacob Kellerb4f47a42016-04-13 16:08:22 -07001299 else if (IXGBE_ATR_BUCKET_HASH_KEY & BIT(n)) \
Alexander Duyck69830522011-01-06 14:29:58 +00001300 bucket_hash ^= lo_hash_dword >> n; \
Jacob Kellerb4f47a42016-04-13 16:08:22 -07001301 else if (IXGBE_ATR_SIGNATURE_HASH_KEY & BIT(n)) \
Alexander Duyck69830522011-01-06 14:29:58 +00001302 sig_hash ^= lo_hash_dword << (16 - n); \
Jacob Kellerb4f47a42016-04-13 16:08:22 -07001303 if (IXGBE_ATR_COMMON_HASH_KEY & BIT(n + 16)) \
Alexander Duyck69830522011-01-06 14:29:58 +00001304 common_hash ^= hi_hash_dword >> n; \
Jacob Kellerb4f47a42016-04-13 16:08:22 -07001305 else if (IXGBE_ATR_BUCKET_HASH_KEY & BIT(n + 16)) \
Alexander Duyck69830522011-01-06 14:29:58 +00001306 bucket_hash ^= hi_hash_dword >> n; \
Jacob Kellerb4f47a42016-04-13 16:08:22 -07001307 else if (IXGBE_ATR_SIGNATURE_HASH_KEY & BIT(n + 16)) \
Alexander Duyck69830522011-01-06 14:29:58 +00001308 sig_hash ^= hi_hash_dword << (16 - n); \
Jacob Keller1c420c72014-04-09 06:03:11 +00001309} while (0)
Alexander Duyck69830522011-01-06 14:29:58 +00001310
1311/**
1312 * ixgbe_atr_compute_sig_hash_82599 - Compute the signature hash
1313 * @stream: input bitstream to compute the hash on
1314 *
1315 * This function is almost identical to the function above but contains
1316 * several optomizations such as unwinding all of the loops, letting the
1317 * compiler work out all of the conditional ifs since the keys are static
1318 * defines, and computing two keys at once since the hashed dword stream
1319 * will be the same for both keys.
1320 **/
1321static u32 ixgbe_atr_compute_sig_hash_82599(union ixgbe_atr_hash_dword input,
1322 union ixgbe_atr_hash_dword common)
1323{
1324 u32 hi_hash_dword, lo_hash_dword, flow_vm_vlan;
1325 u32 sig_hash = 0, bucket_hash = 0, common_hash = 0;
1326
1327 /* record the flow_vm_vlan bits as they are a key part to the hash */
1328 flow_vm_vlan = ntohl(input.dword);
1329
1330 /* generate common hash dword */
1331 hi_hash_dword = ntohl(common.dword);
1332
1333 /* low dword is word swapped version of common */
1334 lo_hash_dword = (hi_hash_dword >> 16) | (hi_hash_dword << 16);
1335
1336 /* apply flow ID/VM pool/VLAN ID bits to hash words */
1337 hi_hash_dword ^= flow_vm_vlan ^ (flow_vm_vlan >> 16);
1338
1339 /* Process bits 0 and 16 */
1340 IXGBE_COMPUTE_SIG_HASH_ITERATION(0);
1341
1342 /*
1343 * apply flow ID/VM pool/VLAN ID bits to lo hash dword, we had to
1344 * delay this because bit 0 of the stream should not be processed
1345 * so we do not add the vlan until after bit 0 was processed
1346 */
1347 lo_hash_dword ^= flow_vm_vlan ^ (flow_vm_vlan << 16);
1348
1349 /* Process remaining 30 bit of the key */
1350 IXGBE_COMPUTE_SIG_HASH_ITERATION(1);
1351 IXGBE_COMPUTE_SIG_HASH_ITERATION(2);
1352 IXGBE_COMPUTE_SIG_HASH_ITERATION(3);
1353 IXGBE_COMPUTE_SIG_HASH_ITERATION(4);
1354 IXGBE_COMPUTE_SIG_HASH_ITERATION(5);
1355 IXGBE_COMPUTE_SIG_HASH_ITERATION(6);
1356 IXGBE_COMPUTE_SIG_HASH_ITERATION(7);
1357 IXGBE_COMPUTE_SIG_HASH_ITERATION(8);
1358 IXGBE_COMPUTE_SIG_HASH_ITERATION(9);
1359 IXGBE_COMPUTE_SIG_HASH_ITERATION(10);
1360 IXGBE_COMPUTE_SIG_HASH_ITERATION(11);
1361 IXGBE_COMPUTE_SIG_HASH_ITERATION(12);
1362 IXGBE_COMPUTE_SIG_HASH_ITERATION(13);
1363 IXGBE_COMPUTE_SIG_HASH_ITERATION(14);
1364 IXGBE_COMPUTE_SIG_HASH_ITERATION(15);
1365
1366 /* combine common_hash result with signature and bucket hashes */
1367 bucket_hash ^= common_hash;
1368 bucket_hash &= IXGBE_ATR_HASH_MASK;
1369
1370 sig_hash ^= common_hash << 16;
1371 sig_hash &= IXGBE_ATR_HASH_MASK << 16;
1372
1373 /* return completed signature hash */
1374 return sig_hash ^ bucket_hash;
1375}
1376
Peter P Waskiewicz Jrffff4772009-06-04 16:01:25 +00001377/**
Peter P Waskiewicz Jrffff4772009-06-04 16:01:25 +00001378 * ixgbe_atr_add_signature_filter_82599 - Adds a signature hash filter
1379 * @hw: pointer to hardware structure
Alexander Duyck69830522011-01-06 14:29:58 +00001380 * @input: unique input dword
1381 * @common: compressed common input dword
Peter P Waskiewicz Jrffff4772009-06-04 16:01:25 +00001382 * @queue: queue index to direct traffic to
Mark Rustad67359c32015-06-15 11:33:25 -07001383 *
1384 * Note that the tunnel bit in input must not be set when the hardware
1385 * tunneling support does not exist.
Peter P Waskiewicz Jrffff4772009-06-04 16:01:25 +00001386 **/
1387s32 ixgbe_fdir_add_signature_filter_82599(struct ixgbe_hw *hw,
Jacob Kellere7cf7452014-04-09 06:03:10 +00001388 union ixgbe_atr_hash_dword input,
1389 union ixgbe_atr_hash_dword common,
1390 u8 queue)
Peter P Waskiewicz Jrffff4772009-06-04 16:01:25 +00001391{
Mark Rustad67359c32015-06-15 11:33:25 -07001392 u64 fdirhashcmd;
1393 u8 flow_type;
1394 bool tunnel;
1395 u32 fdircmd;
Peter P Waskiewicz Jrffff4772009-06-04 16:01:25 +00001396
Alexander Duyck905e4a42011-01-06 14:29:57 +00001397 /*
1398 * Get the flow_type in order to program FDIRCMD properly
1399 * lowest 2 bits are FDIRCMD.L4TYPE, third lowest bit is FDIRCMD.IPV6
1400 */
Mark Rustad67359c32015-06-15 11:33:25 -07001401 tunnel = !!(input.formatted.flow_type & IXGBE_ATR_L4TYPE_TUNNEL_MASK);
1402 flow_type = input.formatted.flow_type &
1403 (IXGBE_ATR_L4TYPE_TUNNEL_MASK - 1);
1404 switch (flow_type) {
Alexander Duyck905e4a42011-01-06 14:29:57 +00001405 case IXGBE_ATR_FLOW_TYPE_TCPV4:
1406 case IXGBE_ATR_FLOW_TYPE_UDPV4:
1407 case IXGBE_ATR_FLOW_TYPE_SCTPV4:
1408 case IXGBE_ATR_FLOW_TYPE_TCPV6:
1409 case IXGBE_ATR_FLOW_TYPE_UDPV6:
1410 case IXGBE_ATR_FLOW_TYPE_SCTPV6:
1411 break;
1412 default:
1413 hw_dbg(hw, " Error on flow type input\n");
1414 return IXGBE_ERR_CONFIG;
1415 }
Peter P Waskiewicz Jrffff4772009-06-04 16:01:25 +00001416
Alexander Duyck905e4a42011-01-06 14:29:57 +00001417 /* configure FDIRCMD register */
1418 fdircmd = IXGBE_FDIRCMD_CMD_ADD_FLOW | IXGBE_FDIRCMD_FILTER_UPDATE |
Jacob Kellere7cf7452014-04-09 06:03:10 +00001419 IXGBE_FDIRCMD_LAST | IXGBE_FDIRCMD_QUEUE_EN;
Mark Rustad67359c32015-06-15 11:33:25 -07001420 fdircmd |= (u32)flow_type << IXGBE_FDIRCMD_FLOW_TYPE_SHIFT;
Alexander Duyck905e4a42011-01-06 14:29:57 +00001421 fdircmd |= (u32)queue << IXGBE_FDIRCMD_RX_QUEUE_SHIFT;
Mark Rustad67359c32015-06-15 11:33:25 -07001422 if (tunnel)
1423 fdircmd |= IXGBE_FDIRCMD_TUNNEL_FILTER;
Peter P Waskiewicz Jrffff4772009-06-04 16:01:25 +00001424
1425 /*
1426 * The lower 32-bits of fdirhashcmd is for FDIRHASH, the upper 32-bits
1427 * is for FDIRCMD. Then do a 64-bit register write from FDIRHASH.
1428 */
Alexander Duyck905e4a42011-01-06 14:29:57 +00001429 fdirhashcmd = (u64)fdircmd << 32;
Alexander Duyck69830522011-01-06 14:29:58 +00001430 fdirhashcmd |= ixgbe_atr_compute_sig_hash_82599(input, common);
Peter P Waskiewicz Jrffff4772009-06-04 16:01:25 +00001431 IXGBE_WRITE_REG64(hw, IXGBE_FDIRHASH, fdirhashcmd);
1432
Alexander Duyck69830522011-01-06 14:29:58 +00001433 hw_dbg(hw, "Tx Queue=%x hash=%x\n", queue, (u32)fdirhashcmd);
1434
Peter P Waskiewicz Jrffff4772009-06-04 16:01:25 +00001435 return 0;
1436}
1437
Alexander Duyckc04f6ca2011-05-11 07:18:36 +00001438#define IXGBE_COMPUTE_BKT_HASH_ITERATION(_n) \
1439do { \
1440 u32 n = (_n); \
Jacob Kellerb4f47a42016-04-13 16:08:22 -07001441 if (IXGBE_ATR_BUCKET_HASH_KEY & BIT(n)) \
Alexander Duyckc04f6ca2011-05-11 07:18:36 +00001442 bucket_hash ^= lo_hash_dword >> n; \
Jacob Kellerb4f47a42016-04-13 16:08:22 -07001443 if (IXGBE_ATR_BUCKET_HASH_KEY & BIT(n + 16)) \
Alexander Duyckc04f6ca2011-05-11 07:18:36 +00001444 bucket_hash ^= hi_hash_dword >> n; \
Jacob Keller1c420c72014-04-09 06:03:11 +00001445} while (0)
Alexander Duyckc04f6ca2011-05-11 07:18:36 +00001446
1447/**
1448 * ixgbe_atr_compute_perfect_hash_82599 - Compute the perfect filter hash
1449 * @atr_input: input bitstream to compute the hash on
1450 * @input_mask: mask for the input bitstream
1451 *
Masahiro Yamadaa6ab4ef2017-02-27 14:29:34 -08001452 * This function serves two main purposes. First it applies the input_mask
Alexander Duyckc04f6ca2011-05-11 07:18:36 +00001453 * to the atr_input resulting in a cleaned up atr_input data stream.
1454 * Secondly it computes the hash and stores it in the bkt_hash field at
1455 * the end of the input byte stream. This way it will be available for
1456 * future use without needing to recompute the hash.
1457 **/
1458void ixgbe_atr_compute_perfect_hash_82599(union ixgbe_atr_input *input,
1459 union ixgbe_atr_input *input_mask)
1460{
1461
1462 u32 hi_hash_dword, lo_hash_dword, flow_vm_vlan;
Jacob Keller65ce9dc2014-02-22 01:23:59 +00001463 u32 bucket_hash = 0, hi_dword = 0;
1464 int i;
Alexander Duyckc04f6ca2011-05-11 07:18:36 +00001465
1466 /* Apply masks to input data */
Jacob Keller65ce9dc2014-02-22 01:23:59 +00001467 for (i = 0; i <= 10; i++)
1468 input->dword_stream[i] &= input_mask->dword_stream[i];
Alexander Duyckc04f6ca2011-05-11 07:18:36 +00001469
1470 /* record the flow_vm_vlan bits as they are a key part to the hash */
1471 flow_vm_vlan = ntohl(input->dword_stream[0]);
1472
1473 /* generate common hash dword */
Jacob Keller65ce9dc2014-02-22 01:23:59 +00001474 for (i = 1; i <= 10; i++)
1475 hi_dword ^= input->dword_stream[i];
1476 hi_hash_dword = ntohl(hi_dword);
Alexander Duyckc04f6ca2011-05-11 07:18:36 +00001477
1478 /* low dword is word swapped version of common */
1479 lo_hash_dword = (hi_hash_dword >> 16) | (hi_hash_dword << 16);
1480
1481 /* apply flow ID/VM pool/VLAN ID bits to hash words */
1482 hi_hash_dword ^= flow_vm_vlan ^ (flow_vm_vlan >> 16);
1483
1484 /* Process bits 0 and 16 */
1485 IXGBE_COMPUTE_BKT_HASH_ITERATION(0);
1486
1487 /*
1488 * apply flow ID/VM pool/VLAN ID bits to lo hash dword, we had to
1489 * delay this because bit 0 of the stream should not be processed
1490 * so we do not add the vlan until after bit 0 was processed
1491 */
1492 lo_hash_dword ^= flow_vm_vlan ^ (flow_vm_vlan << 16);
1493
1494 /* Process remaining 30 bit of the key */
Jacob Keller65ce9dc2014-02-22 01:23:59 +00001495 for (i = 1; i <= 15; i++)
1496 IXGBE_COMPUTE_BKT_HASH_ITERATION(i);
Alexander Duyckc04f6ca2011-05-11 07:18:36 +00001497
1498 /*
1499 * Limit hash to 13 bits since max bucket count is 8K.
1500 * Store result at the end of the input stream.
1501 */
1502 input->formatted.bkt_hash = bucket_hash & 0x1FFF;
1503}
1504
Peter P Waskiewicz Jrffff4772009-06-04 16:01:25 +00001505/**
Alexander Duyck45b9f502011-01-06 14:29:59 +00001506 * ixgbe_get_fdirtcpm_82599 - generate a tcp port from atr_input_masks
1507 * @input_mask: mask to be bit swapped
1508 *
1509 * The source and destination port masks for flow director are bit swapped
1510 * in that bit 15 effects bit 0, 14 effects 1, 13, 2 etc. In order to
1511 * generate a correctly swapped value we need to bit swap the mask and that
1512 * is what is accomplished by this function.
1513 **/
Alexander Duyckc04f6ca2011-05-11 07:18:36 +00001514static u32 ixgbe_get_fdirtcpm_82599(union ixgbe_atr_input *input_mask)
Alexander Duyck45b9f502011-01-06 14:29:59 +00001515{
Alexander Duyckc04f6ca2011-05-11 07:18:36 +00001516 u32 mask = ntohs(input_mask->formatted.dst_port);
Jacob Keller2b2005d2014-04-09 06:03:12 +00001517
Alexander Duyck45b9f502011-01-06 14:29:59 +00001518 mask <<= IXGBE_FDIRTCPM_DPORTM_SHIFT;
Alexander Duyckc04f6ca2011-05-11 07:18:36 +00001519 mask |= ntohs(input_mask->formatted.src_port);
Alexander Duyck45b9f502011-01-06 14:29:59 +00001520 mask = ((mask & 0x55555555) << 1) | ((mask & 0xAAAAAAAA) >> 1);
1521 mask = ((mask & 0x33333333) << 2) | ((mask & 0xCCCCCCCC) >> 2);
1522 mask = ((mask & 0x0F0F0F0F) << 4) | ((mask & 0xF0F0F0F0) >> 4);
1523 return ((mask & 0x00FF00FF) << 8) | ((mask & 0xFF00FF00) >> 8);
1524}
1525
1526/*
1527 * These two macros are meant to address the fact that we have registers
1528 * that are either all or in part big-endian. As a result on big-endian
1529 * systems we will end up byte swapping the value to little-endian before
1530 * it is byte swapped again and written to the hardware in the original
1531 * big-endian format.
1532 */
1533#define IXGBE_STORE_AS_BE32(_value) \
1534 (((u32)(_value) >> 24) | (((u32)(_value) & 0x00FF0000) >> 8) | \
1535 (((u32)(_value) & 0x0000FF00) << 8) | ((u32)(_value) << 24))
1536
1537#define IXGBE_WRITE_REG_BE32(a, reg, value) \
1538 IXGBE_WRITE_REG((a), (reg), IXGBE_STORE_AS_BE32(ntohl(value)))
1539
1540#define IXGBE_STORE_AS_BE16(_value) \
Alexander Duyckc04f6ca2011-05-11 07:18:36 +00001541 ntohs(((u16)(_value) >> 8) | ((u16)(_value) << 8))
Alexander Duyck45b9f502011-01-06 14:29:59 +00001542
Alexander Duyckc04f6ca2011-05-11 07:18:36 +00001543s32 ixgbe_fdir_set_input_mask_82599(struct ixgbe_hw *hw,
1544 union ixgbe_atr_input *input_mask)
Peter P Waskiewicz Jrffff4772009-06-04 16:01:25 +00001545{
Alexander Duyckc04f6ca2011-05-11 07:18:36 +00001546 /* mask IPv6 since it is currently not supported */
1547 u32 fdirm = IXGBE_FDIRM_DIPv6;
1548 u32 fdirtcpm;
Peter P Waskiewicz Jrffff4772009-06-04 16:01:25 +00001549
Peter Waskiewicz9a713e72010-02-10 16:07:54 +00001550 /*
Alexander Duyck45b9f502011-01-06 14:29:59 +00001551 * Program the relevant mask registers. If src/dst_port or src/dst_addr
1552 * are zero, then assume a full mask for that field. Also assume that
1553 * a VLAN of 0 is unspecified, so mask that out as well. L4type
1554 * cannot be masked out in this implementation.
Peter Waskiewicz9a713e72010-02-10 16:07:54 +00001555 *
1556 * This also assumes IPv4 only. IPv6 masking isn't supported at this
1557 * point in time.
1558 */
Peter Waskiewicz9a713e72010-02-10 16:07:54 +00001559
Alexander Duyckc04f6ca2011-05-11 07:18:36 +00001560 /* verify bucket hash is cleared on hash generation */
1561 if (input_mask->formatted.bkt_hash)
1562 hw_dbg(hw, " bucket hash should always be 0 in mask\n");
1563
1564 /* Program FDIRM and verify partial masks */
1565 switch (input_mask->formatted.vm_pool & 0x7F) {
1566 case 0x0:
1567 fdirm |= IXGBE_FDIRM_POOL;
1568 case 0x7F:
Peter Waskiewicz9a713e72010-02-10 16:07:54 +00001569 break;
Alexander Duyckc04f6ca2011-05-11 07:18:36 +00001570 default:
1571 hw_dbg(hw, " Error on vm pool mask\n");
1572 return IXGBE_ERR_CONFIG;
1573 }
1574
1575 switch (input_mask->formatted.flow_type & IXGBE_ATR_L4TYPE_MASK) {
1576 case 0x0:
1577 fdirm |= IXGBE_FDIRM_L4P;
1578 if (input_mask->formatted.dst_port ||
1579 input_mask->formatted.src_port) {
1580 hw_dbg(hw, " Error on src/dst port mask\n");
1581 return IXGBE_ERR_CONFIG;
1582 }
1583 case IXGBE_ATR_L4TYPE_MASK:
Alexander Duyck45b9f502011-01-06 14:29:59 +00001584 break;
Alexander Duyckc04f6ca2011-05-11 07:18:36 +00001585 default:
1586 hw_dbg(hw, " Error on flow type mask\n");
1587 return IXGBE_ERR_CONFIG;
1588 }
1589
1590 switch (ntohs(input_mask->formatted.vlan_id) & 0xEFFF) {
Alexander Duyck45b9f502011-01-06 14:29:59 +00001591 case 0x0000:
Tony Nguyen93df9462017-05-31 04:43:47 -07001592 /* mask VLAN ID */
Alexander Duyckc04f6ca2011-05-11 07:18:36 +00001593 fdirm |= IXGBE_FDIRM_VLANID;
Tony Nguyen93df9462017-05-31 04:43:47 -07001594 /* fall through */
Alexander Duyckc04f6ca2011-05-11 07:18:36 +00001595 case 0x0FFF:
1596 /* mask VLAN priority */
1597 fdirm |= IXGBE_FDIRM_VLANP;
1598 break;
1599 case 0xE000:
Tony Nguyen93df9462017-05-31 04:43:47 -07001600 /* mask VLAN ID only */
Alexander Duyckc04f6ca2011-05-11 07:18:36 +00001601 fdirm |= IXGBE_FDIRM_VLANID;
Tony Nguyen93df9462017-05-31 04:43:47 -07001602 /* fall through */
Alexander Duyckc04f6ca2011-05-11 07:18:36 +00001603 case 0xEFFF:
1604 /* no VLAN fields masked */
Peter Waskiewicz9a713e72010-02-10 16:07:54 +00001605 break;
1606 default:
Alexander Duyck45b9f502011-01-06 14:29:59 +00001607 hw_dbg(hw, " Error on VLAN mask\n");
1608 return IXGBE_ERR_CONFIG;
Peter Waskiewicz9a713e72010-02-10 16:07:54 +00001609 }
1610
Alexander Duyckc04f6ca2011-05-11 07:18:36 +00001611 switch (input_mask->formatted.flex_bytes & 0xFFFF) {
1612 case 0x0000:
Tony Nguyen93df9462017-05-31 04:43:47 -07001613 /* Mask Flex Bytes */
Alexander Duyckc04f6ca2011-05-11 07:18:36 +00001614 fdirm |= IXGBE_FDIRM_FLEX;
Tony Nguyen93df9462017-05-31 04:43:47 -07001615 /* fall through */
Alexander Duyckc04f6ca2011-05-11 07:18:36 +00001616 case 0xFFFF:
1617 break;
1618 default:
1619 hw_dbg(hw, " Error on flexible byte mask\n");
1620 return IXGBE_ERR_CONFIG;
Alexander Duyck45b9f502011-01-06 14:29:59 +00001621 }
Peter Waskiewicz9a713e72010-02-10 16:07:54 +00001622
1623 /* Now mask VM pool and destination IPv6 - bits 5 and 2 */
Peter Waskiewicz9a713e72010-02-10 16:07:54 +00001624 IXGBE_WRITE_REG(hw, IXGBE_FDIRM, fdirm);
Peter P Waskiewicz Jrffff4772009-06-04 16:01:25 +00001625
Alexander Duyck45b9f502011-01-06 14:29:59 +00001626 /* store the TCP/UDP port masks, bit reversed from port layout */
Alexander Duyckc04f6ca2011-05-11 07:18:36 +00001627 fdirtcpm = ixgbe_get_fdirtcpm_82599(input_mask);
Alexander Duyck45b9f502011-01-06 14:29:59 +00001628
1629 /* write both the same so that UDP and TCP use the same mask */
1630 IXGBE_WRITE_REG(hw, IXGBE_FDIRTCPM, ~fdirtcpm);
1631 IXGBE_WRITE_REG(hw, IXGBE_FDIRUDPM, ~fdirtcpm);
1632
Don Skidmore55324082015-06-24 17:03:30 -04001633 /* also use it for SCTP */
1634 switch (hw->mac.type) {
1635 case ixgbe_mac_X550:
1636 case ixgbe_mac_X550EM_x:
Mark Rustad49425df2016-04-01 12:18:09 -07001637 case ixgbe_mac_x550em_a:
Don Skidmore55324082015-06-24 17:03:30 -04001638 IXGBE_WRITE_REG(hw, IXGBE_FDIRSCTPM, ~fdirtcpm);
1639 break;
1640 default:
1641 break;
1642 }
1643
Alexander Duyck45b9f502011-01-06 14:29:59 +00001644 /* store source and destination IP masks (big-enian) */
1645 IXGBE_WRITE_REG_BE32(hw, IXGBE_FDIRSIP4M,
Alexander Duyckc04f6ca2011-05-11 07:18:36 +00001646 ~input_mask->formatted.src_ip[0]);
Alexander Duyck45b9f502011-01-06 14:29:59 +00001647 IXGBE_WRITE_REG_BE32(hw, IXGBE_FDIRDIP4M,
Alexander Duyckc04f6ca2011-05-11 07:18:36 +00001648 ~input_mask->formatted.dst_ip[0]);
Alexander Duyck45b9f502011-01-06 14:29:59 +00001649
Alexander Duyckc04f6ca2011-05-11 07:18:36 +00001650 return 0;
1651}
Alexander Duyck45b9f502011-01-06 14:29:59 +00001652
Alexander Duyckc04f6ca2011-05-11 07:18:36 +00001653s32 ixgbe_fdir_write_perfect_filter_82599(struct ixgbe_hw *hw,
1654 union ixgbe_atr_input *input,
1655 u16 soft_id, u8 queue)
1656{
1657 u32 fdirport, fdirvlan, fdirhash, fdircmd;
Mark Rustadd490d152015-06-11 11:02:20 -07001658 s32 err;
Alexander Duyckc04f6ca2011-05-11 07:18:36 +00001659
1660 /* currently IPv6 is not supported, must be programmed with 0 */
1661 IXGBE_WRITE_REG_BE32(hw, IXGBE_FDIRSIPv6(0),
1662 input->formatted.src_ip[0]);
1663 IXGBE_WRITE_REG_BE32(hw, IXGBE_FDIRSIPv6(1),
1664 input->formatted.src_ip[1]);
1665 IXGBE_WRITE_REG_BE32(hw, IXGBE_FDIRSIPv6(2),
1666 input->formatted.src_ip[2]);
1667
1668 /* record the source address (big-endian) */
1669 IXGBE_WRITE_REG_BE32(hw, IXGBE_FDIRIPSA, input->formatted.src_ip[0]);
1670
1671 /* record the first 32 bits of the destination address (big-endian) */
1672 IXGBE_WRITE_REG_BE32(hw, IXGBE_FDIRIPDA, input->formatted.dst_ip[0]);
Alexander Duyck45b9f502011-01-06 14:29:59 +00001673
1674 /* record source and destination port (little-endian)*/
1675 fdirport = ntohs(input->formatted.dst_port);
1676 fdirport <<= IXGBE_FDIRPORT_DESTINATION_SHIFT;
1677 fdirport |= ntohs(input->formatted.src_port);
1678 IXGBE_WRITE_REG(hw, IXGBE_FDIRPORT, fdirport);
1679
Alexander Duyckc04f6ca2011-05-11 07:18:36 +00001680 /* record vlan (little-endian) and flex_bytes(big-endian) */
1681 fdirvlan = IXGBE_STORE_AS_BE16(input->formatted.flex_bytes);
1682 fdirvlan <<= IXGBE_FDIRVLAN_FLEX_SHIFT;
1683 fdirvlan |= ntohs(input->formatted.vlan_id);
1684 IXGBE_WRITE_REG(hw, IXGBE_FDIRVLAN, fdirvlan);
Alexander Duyck45b9f502011-01-06 14:29:59 +00001685
Alexander Duyckc04f6ca2011-05-11 07:18:36 +00001686 /* configure FDIRHASH register */
1687 fdirhash = input->formatted.bkt_hash;
1688 fdirhash |= soft_id << IXGBE_FDIRHASH_SIG_SW_INDEX_SHIFT;
1689 IXGBE_WRITE_REG(hw, IXGBE_FDIRHASH, fdirhash);
1690
1691 /*
1692 * flush all previous writes to make certain registers are
1693 * programmed prior to issuing the command
1694 */
1695 IXGBE_WRITE_FLUSH(hw);
Alexander Duyck45b9f502011-01-06 14:29:59 +00001696
1697 /* configure FDIRCMD register */
1698 fdircmd = IXGBE_FDIRCMD_CMD_ADD_FLOW | IXGBE_FDIRCMD_FILTER_UPDATE |
1699 IXGBE_FDIRCMD_LAST | IXGBE_FDIRCMD_QUEUE_EN;
Alexander Duyckc04f6ca2011-05-11 07:18:36 +00001700 if (queue == IXGBE_FDIR_DROP_QUEUE)
1701 fdircmd |= IXGBE_FDIRCMD_DROP;
Alexander Duyck45b9f502011-01-06 14:29:59 +00001702 fdircmd |= input->formatted.flow_type << IXGBE_FDIRCMD_FLOW_TYPE_SHIFT;
1703 fdircmd |= (u32)queue << IXGBE_FDIRCMD_RX_QUEUE_SHIFT;
Alexander Duyckc04f6ca2011-05-11 07:18:36 +00001704 fdircmd |= (u32)input->formatted.vm_pool << IXGBE_FDIRCMD_VT_POOL_SHIFT;
Alexander Duyck45b9f502011-01-06 14:29:59 +00001705
Peter P Waskiewicz Jrffff4772009-06-04 16:01:25 +00001706 IXGBE_WRITE_REG(hw, IXGBE_FDIRCMD, fdircmd);
Mark Rustadd490d152015-06-11 11:02:20 -07001707 err = ixgbe_fdir_check_cmd_complete(hw, &fdircmd);
1708 if (err) {
1709 hw_dbg(hw, "Flow Director command did not complete!\n");
1710 return err;
1711 }
Peter P Waskiewicz Jrffff4772009-06-04 16:01:25 +00001712
1713 return 0;
1714}
Alexander Duyck45b9f502011-01-06 14:29:59 +00001715
Alexander Duyckc04f6ca2011-05-11 07:18:36 +00001716s32 ixgbe_fdir_erase_perfect_filter_82599(struct ixgbe_hw *hw,
1717 union ixgbe_atr_input *input,
1718 u16 soft_id)
1719{
1720 u32 fdirhash;
Mark Rustadd490d152015-06-11 11:02:20 -07001721 u32 fdircmd;
1722 s32 err;
Alexander Duyckc04f6ca2011-05-11 07:18:36 +00001723
1724 /* configure FDIRHASH register */
1725 fdirhash = input->formatted.bkt_hash;
1726 fdirhash |= soft_id << IXGBE_FDIRHASH_SIG_SW_INDEX_SHIFT;
1727 IXGBE_WRITE_REG(hw, IXGBE_FDIRHASH, fdirhash);
1728
1729 /* flush hash to HW */
1730 IXGBE_WRITE_FLUSH(hw);
1731
1732 /* Query if filter is present */
1733 IXGBE_WRITE_REG(hw, IXGBE_FDIRCMD, IXGBE_FDIRCMD_CMD_QUERY_REM_FILT);
1734
Mark Rustadd490d152015-06-11 11:02:20 -07001735 err = ixgbe_fdir_check_cmd_complete(hw, &fdircmd);
1736 if (err) {
1737 hw_dbg(hw, "Flow Director command did not complete!\n");
1738 return err;
Alexander Duyckc04f6ca2011-05-11 07:18:36 +00001739 }
1740
Alexander Duyckc04f6ca2011-05-11 07:18:36 +00001741 /* if filter exists in hardware then remove it */
1742 if (fdircmd & IXGBE_FDIRCMD_FILTER_VALID) {
1743 IXGBE_WRITE_REG(hw, IXGBE_FDIRHASH, fdirhash);
1744 IXGBE_WRITE_FLUSH(hw);
1745 IXGBE_WRITE_REG(hw, IXGBE_FDIRCMD,
1746 IXGBE_FDIRCMD_CMD_REMOVE_FLOW);
1747 }
1748
Mark Rustadd490d152015-06-11 11:02:20 -07001749 return 0;
Alexander Duyckc04f6ca2011-05-11 07:18:36 +00001750}
1751
Peter P Waskiewicz Jrffff4772009-06-04 16:01:25 +00001752/**
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001753 * ixgbe_read_analog_reg8_82599 - Reads 8 bit Omer analog register
1754 * @hw: pointer to hardware structure
1755 * @reg: analog register to read
1756 * @val: read value
1757 *
1758 * Performs read operation to Omer analog register specified.
1759 **/
Don Skidmore7b25cdb2009-08-25 04:47:32 +00001760static s32 ixgbe_read_analog_reg8_82599(struct ixgbe_hw *hw, u32 reg, u8 *val)
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001761{
1762 u32 core_ctl;
1763
1764 IXGBE_WRITE_REG(hw, IXGBE_CORECTL, IXGBE_CORECTL_WRITE_CMD |
Jacob Kellere7cf7452014-04-09 06:03:10 +00001765 (reg << 8));
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001766 IXGBE_WRITE_FLUSH(hw);
1767 udelay(10);
1768 core_ctl = IXGBE_READ_REG(hw, IXGBE_CORECTL);
1769 *val = (u8)core_ctl;
1770
1771 return 0;
1772}
1773
1774/**
1775 * ixgbe_write_analog_reg8_82599 - Writes 8 bit Omer analog register
1776 * @hw: pointer to hardware structure
1777 * @reg: atlas register to write
1778 * @val: value to write
1779 *
1780 * Performs write operation to Omer analog register specified.
1781 **/
Don Skidmore7b25cdb2009-08-25 04:47:32 +00001782static s32 ixgbe_write_analog_reg8_82599(struct ixgbe_hw *hw, u32 reg, u8 val)
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001783{
1784 u32 core_ctl;
1785
1786 core_ctl = (reg << 8) | val;
1787 IXGBE_WRITE_REG(hw, IXGBE_CORECTL, core_ctl);
1788 IXGBE_WRITE_FLUSH(hw);
1789 udelay(10);
1790
1791 return 0;
1792}
1793
1794/**
1795 * ixgbe_start_hw_82599 - Prepare hardware for Tx/Rx
1796 * @hw: pointer to hardware structure
1797 *
Emil Tantilov7184b7c2011-03-18 08:18:22 +00001798 * Starts the hardware using the generic start_hw function
1799 * and the generation start_hw function.
1800 * Then performs revision-specific operations, if any.
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001801 **/
Don Skidmore7b25cdb2009-08-25 04:47:32 +00001802static s32 ixgbe_start_hw_82599(struct ixgbe_hw *hw)
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001803{
Emil Tantilov7184b7c2011-03-18 08:18:22 +00001804 s32 ret_val = 0;
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001805
Peter P Waskiewicz Jr794caeb2009-06-04 16:02:24 +00001806 ret_val = ixgbe_start_hw_generic(hw);
Mark Rustade90dd262014-07-22 06:51:08 +00001807 if (ret_val)
1808 return ret_val;
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001809
Emil Tantilov7184b7c2011-03-18 08:18:22 +00001810 ret_val = ixgbe_start_hw_gen2(hw);
Mark Rustade90dd262014-07-22 06:51:08 +00001811 if (ret_val)
1812 return ret_val;
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001813
Peter P Waskiewicz Jr50ac58b2009-06-04 11:10:53 +00001814 /* We need to run link autotry after the driver loads */
1815 hw->mac.autotry_restart = true;
1816
Mark Rustade90dd262014-07-22 06:51:08 +00001817 return ixgbe_verify_fw_version_82599(hw);
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001818}
1819
1820/**
1821 * ixgbe_identify_phy_82599 - Get physical layer module
1822 * @hw: pointer to hardware structure
1823 *
1824 * Determines the physical layer module found on the current adapter.
Emil Tantilov21cc5b42011-02-12 10:52:07 +00001825 * If PHY already detected, maintains current PHY type in hw struct,
1826 * otherwise executes the PHY detection routine.
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001827 **/
Emil Tantilovd6cd8e02011-03-16 01:58:20 +00001828static s32 ixgbe_identify_phy_82599(struct ixgbe_hw *hw)
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001829{
Mark Rustade90dd262014-07-22 06:51:08 +00001830 s32 status;
Emil Tantilov21cc5b42011-02-12 10:52:07 +00001831
1832 /* Detect PHY if not unknown - returns success if already detected. */
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001833 status = ixgbe_identify_phy_generic(hw);
Mark Rustade90dd262014-07-22 06:51:08 +00001834 if (status) {
Emil Tantilov21cc5b42011-02-12 10:52:07 +00001835 /* 82599 10GBASE-T requires an external PHY */
1836 if (hw->mac.ops.get_media_type(hw) == ixgbe_media_type_copper)
Mark Rustade90dd262014-07-22 06:51:08 +00001837 return status;
1838 status = ixgbe_identify_module_generic(hw);
Emil Tantilov21cc5b42011-02-12 10:52:07 +00001839 }
1840
1841 /* Set PHY type none if no PHY detected */
1842 if (hw->phy.type == ixgbe_phy_unknown) {
1843 hw->phy.type = ixgbe_phy_none;
1844 status = 0;
1845 }
1846
1847 /* Return error if SFP module has been detected but is not supported */
1848 if (hw->phy.type == ixgbe_phy_sfp_unsupported)
Mark Rustade90dd262014-07-22 06:51:08 +00001849 return IXGBE_ERR_SFP_NOT_SUPPORTED;
Emil Tantilov21cc5b42011-02-12 10:52:07 +00001850
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001851 return status;
1852}
1853
1854/**
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001855 * ixgbe_enable_rx_dma_82599 - Enable the Rx DMA unit on 82599
1856 * @hw: pointer to hardware structure
1857 * @regval: register value to write to RXCTRL
1858 *
1859 * Enables the Rx DMA unit for 82599
1860 **/
Don Skidmore7b25cdb2009-08-25 04:47:32 +00001861static s32 ixgbe_enable_rx_dma_82599(struct ixgbe_hw *hw, u32 regval)
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001862{
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001863 /*
1864 * Workaround for 82599 silicon errata when enabling the Rx datapath.
1865 * If traffic is incoming before we enable the Rx unit, it could hang
1866 * the Rx DMA unit. Therefore, make sure the security engine is
1867 * completely disabled prior to enabling the Rx unit.
1868 */
Atita Shirwaikard2f5e7f2012-02-18 02:58:58 +00001869 hw->mac.ops.disable_rx_buff(hw);
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001870
Don Skidmore1f9ac572015-03-13 13:54:30 -07001871 if (regval & IXGBE_RXCTRL_RXEN)
1872 hw->mac.ops.enable_rx(hw);
1873 else
1874 hw->mac.ops.disable_rx(hw);
Atita Shirwaikard2f5e7f2012-02-18 02:58:58 +00001875
1876 hw->mac.ops.enable_rx_buff(hw);
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00001877
1878 return 0;
1879}
1880
Peter P Waskiewicz Jr04193052009-04-09 22:28:50 +00001881/**
Peter P Waskiewicz Jr794caeb2009-06-04 16:02:24 +00001882 * ixgbe_verify_fw_version_82599 - verify fw version for 82599
1883 * @hw: pointer to hardware structure
1884 *
1885 * Verifies that installed the firmware version is 0.6 or higher
1886 * for SFI devices. All 82599 SFI devices should have version 0.6 or higher.
1887 *
1888 * Returns IXGBE_ERR_EEPROM_VERSION if the FW is not present or
1889 * if the FW version is not supported.
1890 **/
1891static s32 ixgbe_verify_fw_version_82599(struct ixgbe_hw *hw)
1892{
1893 s32 status = IXGBE_ERR_EEPROM_VERSION;
1894 u16 fw_offset, fw_ptp_cfg_offset;
Mark Rustadbe0c27b2013-05-24 07:31:09 +00001895 u16 offset;
Peter P Waskiewicz Jr794caeb2009-06-04 16:02:24 +00001896 u16 fw_version = 0;
1897
1898 /* firmware check is only necessary for SFI devices */
Mark Rustade90dd262014-07-22 06:51:08 +00001899 if (hw->phy.media_type != ixgbe_media_type_fiber)
1900 return 0;
Peter P Waskiewicz Jr794caeb2009-06-04 16:02:24 +00001901
1902 /* get the offset to the Firmware Module block */
Mark Rustadbe0c27b2013-05-24 07:31:09 +00001903 offset = IXGBE_FW_PTR;
1904 if (hw->eeprom.ops.read(hw, offset, &fw_offset))
1905 goto fw_version_err;
Peter P Waskiewicz Jr794caeb2009-06-04 16:02:24 +00001906
Mark Rustade90dd262014-07-22 06:51:08 +00001907 if (fw_offset == 0 || fw_offset == 0xFFFF)
1908 return IXGBE_ERR_EEPROM_VERSION;
Peter P Waskiewicz Jr794caeb2009-06-04 16:02:24 +00001909
1910 /* get the offset to the Pass Through Patch Configuration block */
Mark Rustadbe0c27b2013-05-24 07:31:09 +00001911 offset = fw_offset + IXGBE_FW_PASSTHROUGH_PATCH_CONFIG_PTR;
1912 if (hw->eeprom.ops.read(hw, offset, &fw_ptp_cfg_offset))
1913 goto fw_version_err;
Peter P Waskiewicz Jr794caeb2009-06-04 16:02:24 +00001914
Mark Rustade90dd262014-07-22 06:51:08 +00001915 if (fw_ptp_cfg_offset == 0 || fw_ptp_cfg_offset == 0xFFFF)
1916 return IXGBE_ERR_EEPROM_VERSION;
Peter P Waskiewicz Jr794caeb2009-06-04 16:02:24 +00001917
1918 /* get the firmware version */
Mark Rustadbe0c27b2013-05-24 07:31:09 +00001919 offset = fw_ptp_cfg_offset + IXGBE_FW_PATCH_VERSION_4;
1920 if (hw->eeprom.ops.read(hw, offset, &fw_version))
1921 goto fw_version_err;
Peter P Waskiewicz Jr794caeb2009-06-04 16:02:24 +00001922
1923 if (fw_version > 0x5)
1924 status = 0;
1925
Peter P Waskiewicz Jr794caeb2009-06-04 16:02:24 +00001926 return status;
Mark Rustadbe0c27b2013-05-24 07:31:09 +00001927
1928fw_version_err:
1929 hw_err(hw, "eeprom read at offset %d failed\n", offset);
1930 return IXGBE_ERR_EEPROM_VERSION;
Peter P Waskiewicz Jr794caeb2009-06-04 16:02:24 +00001931}
1932
Emil Tantilov0fa6d832011-03-18 08:18:32 +00001933/**
1934 * ixgbe_verify_lesm_fw_enabled_82599 - Checks LESM FW module state.
1935 * @hw: pointer to hardware structure
1936 *
1937 * Returns true if the LESM FW module is present and enabled. Otherwise
1938 * returns false. Smart Speed must be disabled if LESM FW module is enabled.
1939 **/
Don Skidmore429d6a32014-02-27 20:32:41 -08001940static bool ixgbe_verify_lesm_fw_enabled_82599(struct ixgbe_hw *hw)
Emil Tantilov0fa6d832011-03-18 08:18:32 +00001941{
Emil Tantilov0fa6d832011-03-18 08:18:32 +00001942 u16 fw_offset, fw_lesm_param_offset, fw_lesm_state;
1943 s32 status;
1944
1945 /* get the offset to the Firmware Module block */
1946 status = hw->eeprom.ops.read(hw, IXGBE_FW_PTR, &fw_offset);
1947
Mark Rustade90dd262014-07-22 06:51:08 +00001948 if (status || fw_offset == 0 || fw_offset == 0xFFFF)
1949 return false;
Emil Tantilov0fa6d832011-03-18 08:18:32 +00001950
1951 /* get the offset to the LESM Parameters block */
1952 status = hw->eeprom.ops.read(hw, (fw_offset +
1953 IXGBE_FW_LESM_PARAMETERS_PTR),
1954 &fw_lesm_param_offset);
1955
Mark Rustade90dd262014-07-22 06:51:08 +00001956 if (status ||
1957 fw_lesm_param_offset == 0 || fw_lesm_param_offset == 0xFFFF)
1958 return false;
Emil Tantilov0fa6d832011-03-18 08:18:32 +00001959
1960 /* get the lesm state word */
1961 status = hw->eeprom.ops.read(hw, (fw_lesm_param_offset +
1962 IXGBE_FW_LESM_STATE_1),
1963 &fw_lesm_state);
1964
Mark Rustade90dd262014-07-22 06:51:08 +00001965 if (!status && (fw_lesm_state & IXGBE_FW_LESM_STATE_ENABLED))
1966 return true;
Emil Tantilov0fa6d832011-03-18 08:18:32 +00001967
Mark Rustade90dd262014-07-22 06:51:08 +00001968 return false;
Emil Tantilov0fa6d832011-03-18 08:18:32 +00001969}
1970
Emil Tantilov0665b092011-04-01 08:17:19 +00001971/**
Emil Tantilov68c70052011-04-20 08:49:06 +00001972 * ixgbe_read_eeprom_buffer_82599 - Read EEPROM word(s) using
1973 * fastest available method
1974 *
1975 * @hw: pointer to hardware structure
1976 * @offset: offset of word in EEPROM to read
1977 * @words: number of words
1978 * @data: word(s) read from the EEPROM
1979 *
1980 * Retrieves 16 bit word(s) read from EEPROM
1981 **/
1982static s32 ixgbe_read_eeprom_buffer_82599(struct ixgbe_hw *hw, u16 offset,
1983 u16 words, u16 *data)
1984{
1985 struct ixgbe_eeprom_info *eeprom = &hw->eeprom;
Emil Tantilov68c70052011-04-20 08:49:06 +00001986
Mark Rustade90dd262014-07-22 06:51:08 +00001987 /* If EEPROM is detected and can be addressed using 14 bits,
Emil Tantilov68c70052011-04-20 08:49:06 +00001988 * use EERD otherwise use bit bang
1989 */
Mark Rustade90dd262014-07-22 06:51:08 +00001990 if (eeprom->type == ixgbe_eeprom_spi &&
1991 offset + (words - 1) <= IXGBE_EERD_MAX_ADDR)
1992 return ixgbe_read_eerd_buffer_generic(hw, offset, words, data);
Emil Tantilov68c70052011-04-20 08:49:06 +00001993
Mark Rustade90dd262014-07-22 06:51:08 +00001994 return ixgbe_read_eeprom_buffer_bit_bang_generic(hw, offset, words,
1995 data);
Emil Tantilov68c70052011-04-20 08:49:06 +00001996}
1997
1998/**
Emil Tantilov0665b092011-04-01 08:17:19 +00001999 * ixgbe_read_eeprom_82599 - Read EEPROM word using
2000 * fastest available method
2001 *
2002 * @hw: pointer to hardware structure
2003 * @offset: offset of word in the EEPROM to read
2004 * @data: word read from the EEPROM
2005 *
2006 * Reads a 16 bit word from the EEPROM
2007 **/
2008static s32 ixgbe_read_eeprom_82599(struct ixgbe_hw *hw,
2009 u16 offset, u16 *data)
2010{
2011 struct ixgbe_eeprom_info *eeprom = &hw->eeprom;
Emil Tantilov0665b092011-04-01 08:17:19 +00002012
2013 /*
2014 * If EEPROM is detected and can be addressed using 14 bits,
2015 * use EERD otherwise use bit bang
2016 */
Mark Rustade90dd262014-07-22 06:51:08 +00002017 if (eeprom->type == ixgbe_eeprom_spi && offset <= IXGBE_EERD_MAX_ADDR)
2018 return ixgbe_read_eerd_generic(hw, offset, data);
Emil Tantilov0665b092011-04-01 08:17:19 +00002019
Mark Rustade90dd262014-07-22 06:51:08 +00002020 return ixgbe_read_eeprom_bit_bang_generic(hw, offset, data);
Emil Tantilov0665b092011-04-01 08:17:19 +00002021}
2022
Don Skidmorede52a122012-09-11 06:58:19 +00002023/**
2024 * ixgbe_reset_pipeline_82599 - perform pipeline reset
2025 *
2026 * @hw: pointer to hardware structure
2027 *
2028 * Reset pipeline by asserting Restart_AN together with LMS change to ensure
2029 * full pipeline reset. Note - We must hold the SW/FW semaphore before writing
2030 * to AUTOC, so this function assumes the semaphore is held.
2031 **/
Don Skidmore429d6a32014-02-27 20:32:41 -08002032static s32 ixgbe_reset_pipeline_82599(struct ixgbe_hw *hw)
Don Skidmorede52a122012-09-11 06:58:19 +00002033{
Emil Tantilov46d5ced2013-04-12 08:36:47 +00002034 s32 ret_val;
2035 u32 anlp1_reg = 0;
2036 u32 i, autoc_reg, autoc2_reg;
2037
2038 /* Enable link if disabled in NVM */
2039 autoc2_reg = IXGBE_READ_REG(hw, IXGBE_AUTOC2);
2040 if (autoc2_reg & IXGBE_AUTOC2_LINK_DISABLE_MASK) {
2041 autoc2_reg &= ~IXGBE_AUTOC2_LINK_DISABLE_MASK;
2042 IXGBE_WRITE_REG(hw, IXGBE_AUTOC2, autoc2_reg);
2043 IXGBE_WRITE_FLUSH(hw);
2044 }
Don Skidmorede52a122012-09-11 06:58:19 +00002045
Don Skidmore429d6a32014-02-27 20:32:41 -08002046 autoc_reg = IXGBE_READ_REG(hw, IXGBE_AUTOC);
Don Skidmorede52a122012-09-11 06:58:19 +00002047 autoc_reg |= IXGBE_AUTOC_AN_RESTART;
2048
2049 /* Write AUTOC register with toggled LMS[2] bit and Restart_AN */
Don Skidmore9f4d2782014-02-27 20:32:42 -08002050 IXGBE_WRITE_REG(hw, IXGBE_AUTOC,
2051 autoc_reg ^ (0x4 << IXGBE_AUTOC_LMS_SHIFT));
Don Skidmorede52a122012-09-11 06:58:19 +00002052
2053 /* Wait for AN to leave state 0 */
2054 for (i = 0; i < 10; i++) {
2055 usleep_range(4000, 8000);
2056 anlp1_reg = IXGBE_READ_REG(hw, IXGBE_ANLP1);
2057 if (anlp1_reg & IXGBE_ANLP1_AN_STATE_MASK)
2058 break;
2059 }
2060
2061 if (!(anlp1_reg & IXGBE_ANLP1_AN_STATE_MASK)) {
2062 hw_dbg(hw, "auto negotiation not completed\n");
2063 ret_val = IXGBE_ERR_RESET_FAILED;
2064 goto reset_pipeline_out;
2065 }
2066
2067 ret_val = 0;
2068
2069reset_pipeline_out:
2070 /* Write AUTOC register with original LMS field and Restart_AN */
2071 IXGBE_WRITE_REG(hw, IXGBE_AUTOC, autoc_reg);
2072 IXGBE_WRITE_FLUSH(hw);
2073
2074 return ret_val;
2075}
2076
Don Skidmore8f583322013-07-27 06:25:38 +00002077/**
2078 * ixgbe_read_i2c_byte_82599 - Reads 8 bit word over I2C
2079 * @hw: pointer to hardware structure
2080 * @byte_offset: byte offset to read
2081 * @data: value read
2082 *
2083 * Performs byte read operation to SFP module's EEPROM over I2C interface at
2084 * a specified device address.
2085 **/
2086static s32 ixgbe_read_i2c_byte_82599(struct ixgbe_hw *hw, u8 byte_offset,
2087 u8 dev_addr, u8 *data)
2088{
2089 u32 esdp;
2090 s32 status;
2091 s32 timeout = 200;
2092
2093 if (hw->phy.qsfp_shared_i2c_bus == true) {
2094 /* Acquire I2C bus ownership. */
2095 esdp = IXGBE_READ_REG(hw, IXGBE_ESDP);
2096 esdp |= IXGBE_ESDP_SDP0;
2097 IXGBE_WRITE_REG(hw, IXGBE_ESDP, esdp);
2098 IXGBE_WRITE_FLUSH(hw);
2099
2100 while (timeout) {
2101 esdp = IXGBE_READ_REG(hw, IXGBE_ESDP);
2102 if (esdp & IXGBE_ESDP_SDP1)
2103 break;
2104
2105 usleep_range(5000, 10000);
2106 timeout--;
2107 }
2108
2109 if (!timeout) {
2110 hw_dbg(hw, "Driver can't access resource, acquiring I2C bus timeout.\n");
2111 status = IXGBE_ERR_I2C;
2112 goto release_i2c_access;
2113 }
2114 }
2115
2116 status = ixgbe_read_i2c_byte_generic(hw, byte_offset, dev_addr, data);
2117
2118release_i2c_access:
2119 if (hw->phy.qsfp_shared_i2c_bus == true) {
2120 /* Release I2C bus ownership. */
2121 esdp = IXGBE_READ_REG(hw, IXGBE_ESDP);
2122 esdp &= ~IXGBE_ESDP_SDP0;
2123 IXGBE_WRITE_REG(hw, IXGBE_ESDP, esdp);
2124 IXGBE_WRITE_FLUSH(hw);
2125 }
2126
2127 return status;
2128}
2129
2130/**
2131 * ixgbe_write_i2c_byte_82599 - Writes 8 bit word over I2C
2132 * @hw: pointer to hardware structure
2133 * @byte_offset: byte offset to write
2134 * @data: value to write
2135 *
2136 * Performs byte write operation to SFP module's EEPROM over I2C interface at
2137 * a specified device address.
2138 **/
2139static s32 ixgbe_write_i2c_byte_82599(struct ixgbe_hw *hw, u8 byte_offset,
2140 u8 dev_addr, u8 data)
2141{
2142 u32 esdp;
2143 s32 status;
2144 s32 timeout = 200;
2145
2146 if (hw->phy.qsfp_shared_i2c_bus == true) {
2147 /* Acquire I2C bus ownership. */
2148 esdp = IXGBE_READ_REG(hw, IXGBE_ESDP);
2149 esdp |= IXGBE_ESDP_SDP0;
2150 IXGBE_WRITE_REG(hw, IXGBE_ESDP, esdp);
2151 IXGBE_WRITE_FLUSH(hw);
2152
2153 while (timeout) {
2154 esdp = IXGBE_READ_REG(hw, IXGBE_ESDP);
2155 if (esdp & IXGBE_ESDP_SDP1)
2156 break;
2157
2158 usleep_range(5000, 10000);
2159 timeout--;
2160 }
2161
2162 if (!timeout) {
2163 hw_dbg(hw, "Driver can't access resource, acquiring I2C bus timeout.\n");
2164 status = IXGBE_ERR_I2C;
2165 goto release_i2c_access;
2166 }
2167 }
2168
2169 status = ixgbe_write_i2c_byte_generic(hw, byte_offset, dev_addr, data);
2170
2171release_i2c_access:
2172 if (hw->phy.qsfp_shared_i2c_bus == true) {
2173 /* Release I2C bus ownership. */
2174 esdp = IXGBE_READ_REG(hw, IXGBE_ESDP);
2175 esdp &= ~IXGBE_ESDP_SDP0;
2176 IXGBE_WRITE_REG(hw, IXGBE_ESDP, esdp);
2177 IXGBE_WRITE_FLUSH(hw);
2178 }
2179
2180 return status;
2181}
2182
Mark Rustad37689012016-01-07 10:13:03 -08002183static const struct ixgbe_mac_operations mac_ops_82599 = {
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00002184 .init_hw = &ixgbe_init_hw_generic,
2185 .reset_hw = &ixgbe_reset_hw_82599,
2186 .start_hw = &ixgbe_start_hw_82599,
2187 .clear_hw_cntrs = &ixgbe_clear_hw_cntrs_generic,
2188 .get_media_type = &ixgbe_get_media_type_82599,
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00002189 .enable_rx_dma = &ixgbe_enable_rx_dma_82599,
Atita Shirwaikard2f5e7f2012-02-18 02:58:58 +00002190 .disable_rx_buff = &ixgbe_disable_rx_buff_generic,
2191 .enable_rx_buff = &ixgbe_enable_rx_buff_generic,
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00002192 .get_mac_addr = &ixgbe_get_mac_addr_generic,
Mallikarjuna R Chilakala21ce8492010-05-13 17:33:41 +00002193 .get_san_mac_addr = &ixgbe_get_san_mac_addr_generic,
Emil Tantilovb776d102011-03-31 09:36:18 +00002194 .get_device_caps = &ixgbe_get_device_caps_generic,
Don Skidmorea391f1d2010-11-16 19:27:15 -08002195 .get_wwn_prefix = &ixgbe_get_wwn_prefix_generic,
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00002196 .stop_adapter = &ixgbe_stop_adapter_generic,
2197 .get_bus_info = &ixgbe_get_bus_info_generic,
2198 .set_lan_id = &ixgbe_set_lan_id_multi_port_pcie,
2199 .read_analog_reg8 = &ixgbe_read_analog_reg8_82599,
2200 .write_analog_reg8 = &ixgbe_write_analog_reg8_82599,
Jacob Kellerf4f10402013-06-25 07:59:23 +00002201 .stop_link_on_d3 = &ixgbe_stop_mac_link_on_d3_82599,
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00002202 .setup_link = &ixgbe_setup_mac_link_82599,
John Fastabend80605c652011-05-02 12:34:10 +00002203 .set_rxpba = &ixgbe_set_rxpba_generic,
Mallikarjuna R Chilakala21ce8492010-05-13 17:33:41 +00002204 .check_link = &ixgbe_check_mac_link_generic,
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00002205 .get_link_capabilities = &ixgbe_get_link_capabilities_82599,
2206 .led_on = &ixgbe_led_on_generic,
2207 .led_off = &ixgbe_led_off_generic,
Don Skidmore805cedd2016-10-20 21:42:00 -04002208 .init_led_link_act = ixgbe_init_led_link_act_generic,
PJ Waskiewicz87c12012009-04-08 13:20:31 +00002209 .blink_led_start = &ixgbe_blink_led_start_generic,
2210 .blink_led_stop = &ixgbe_blink_led_stop_generic,
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00002211 .set_rar = &ixgbe_set_rar_generic,
2212 .clear_rar = &ixgbe_clear_rar_generic,
Mallikarjuna R Chilakala21ce8492010-05-13 17:33:41 +00002213 .set_vmdq = &ixgbe_set_vmdq_generic,
Alexander Duyck7fa7c9d2012-05-05 05:32:52 +00002214 .set_vmdq_san_mac = &ixgbe_set_vmdq_san_mac_generic,
Mallikarjuna R Chilakala21ce8492010-05-13 17:33:41 +00002215 .clear_vmdq = &ixgbe_clear_vmdq_generic,
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00002216 .init_rx_addrs = &ixgbe_init_rx_addrs_generic,
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00002217 .update_mc_addr_list = &ixgbe_update_mc_addr_list_generic,
2218 .enable_mc = &ixgbe_enable_mc_generic,
2219 .disable_mc = &ixgbe_disable_mc_generic,
Mallikarjuna R Chilakala21ce8492010-05-13 17:33:41 +00002220 .clear_vfta = &ixgbe_clear_vfta_generic,
2221 .set_vfta = &ixgbe_set_vfta_generic,
2222 .fc_enable = &ixgbe_fc_enable_generic,
Mark Rustadafdc71e2016-01-25 16:32:10 -08002223 .setup_fc = ixgbe_setup_fc_generic,
Don Skidmore29165002016-09-27 14:31:12 -04002224 .fc_autoneg = ixgbe_fc_autoneg,
Emil Tantilov9612de92011-05-07 07:40:20 +00002225 .set_fw_drv_ver = &ixgbe_set_fw_drv_ver_generic,
Mallikarjuna R Chilakala21ce8492010-05-13 17:33:41 +00002226 .init_uta_tables = &ixgbe_init_uta_tables_generic,
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00002227 .setup_sfp = &ixgbe_setup_sfp_modules_82599,
Greg Rosea985b6c32010-11-18 03:02:52 +00002228 .set_mac_anti_spoofing = &ixgbe_set_mac_anti_spoofing,
2229 .set_vlan_anti_spoofing = &ixgbe_set_vlan_anti_spoofing,
Don Skidmore5e655102011-02-25 01:58:04 +00002230 .acquire_swfw_sync = &ixgbe_acquire_swfw_sync,
2231 .release_swfw_sync = &ixgbe_release_swfw_sync,
Don Skidmoredbd15b82016-03-09 16:45:00 -05002232 .init_swfw_sync = NULL,
Don Skidmore3ca8bc62012-04-12 00:33:31 +00002233 .get_thermal_sensor_data = &ixgbe_get_thermal_sensor_data_generic,
2234 .init_thermal_sensor_thresh = &ixgbe_init_thermal_sensor_thresh_generic,
Don Skidmore429d6a32014-02-27 20:32:41 -08002235 .prot_autoc_read = &prot_autoc_read_82599,
2236 .prot_autoc_write = &prot_autoc_write_82599,
Don Skidmore1f9ac572015-03-13 13:54:30 -07002237 .enable_rx = &ixgbe_enable_rx_generic,
2238 .disable_rx = &ixgbe_disable_rx_generic,
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00002239};
2240
Mark Rustad37689012016-01-07 10:13:03 -08002241static const struct ixgbe_eeprom_operations eeprom_ops_82599 = {
Emil Tantilov037c6d02011-02-25 07:49:39 +00002242 .init_params = &ixgbe_init_eeprom_params_generic,
Emil Tantilov0665b092011-04-01 08:17:19 +00002243 .read = &ixgbe_read_eeprom_82599,
Emil Tantilov68c70052011-04-20 08:49:06 +00002244 .read_buffer = &ixgbe_read_eeprom_buffer_82599,
Emil Tantilov037c6d02011-02-25 07:49:39 +00002245 .write = &ixgbe_write_eeprom_generic,
Emil Tantilov68c70052011-04-20 08:49:06 +00002246 .write_buffer = &ixgbe_write_eeprom_buffer_bit_bang_generic,
Emil Tantilov037c6d02011-02-25 07:49:39 +00002247 .calc_checksum = &ixgbe_calc_eeprom_checksum_generic,
2248 .validate_checksum = &ixgbe_validate_eeprom_checksum_generic,
2249 .update_checksum = &ixgbe_update_eeprom_checksum_generic,
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00002250};
2251
Mark Rustad37689012016-01-07 10:13:03 -08002252static const struct ixgbe_phy_operations phy_ops_82599 = {
Emil Tantilov037c6d02011-02-25 07:49:39 +00002253 .identify = &ixgbe_identify_phy_82599,
Don Skidmore8f583322013-07-27 06:25:38 +00002254 .identify_sfp = &ixgbe_identify_module_generic,
Emil Tantilov037c6d02011-02-25 07:49:39 +00002255 .init = &ixgbe_init_phy_ops_82599,
2256 .reset = &ixgbe_reset_phy_generic,
2257 .read_reg = &ixgbe_read_phy_reg_generic,
2258 .write_reg = &ixgbe_write_phy_reg_generic,
2259 .setup_link = &ixgbe_setup_phy_link_generic,
2260 .setup_link_speed = &ixgbe_setup_phy_link_speed_generic,
2261 .read_i2c_byte = &ixgbe_read_i2c_byte_generic,
2262 .write_i2c_byte = &ixgbe_write_i2c_byte_generic,
Emil Tantilov07ce8702012-12-19 07:14:17 +00002263 .read_i2c_sff8472 = &ixgbe_read_i2c_sff8472_generic,
Emil Tantilov037c6d02011-02-25 07:49:39 +00002264 .read_i2c_eeprom = &ixgbe_read_i2c_eeprom_generic,
2265 .write_i2c_eeprom = &ixgbe_write_i2c_eeprom_generic,
2266 .check_overtemp = &ixgbe_tn_check_overtemp,
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00002267};
2268
Mark Rustad37689012016-01-07 10:13:03 -08002269const struct ixgbe_info ixgbe_82599_info = {
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00002270 .mac = ixgbe_mac_82599EB,
2271 .get_invariants = &ixgbe_get_invariants_82599,
2272 .mac_ops = &mac_ops_82599,
2273 .eeprom_ops = &eeprom_ops_82599,
2274 .phy_ops = &phy_ops_82599,
Don Skidmorea391f1d2010-11-16 19:27:15 -08002275 .mbx_ops = &mbx_ops_generic,
Don Skidmore9a900ec2015-06-09 17:15:01 -07002276 .mvals = ixgbe_mvals_8259X,
PJ Waskiewicz11afc1b2009-02-27 15:44:30 +00002277};