1 // SPDX-License-Identifier: GPL-2.0
2 /*******************************************************************************
4 Intel 10 Gigabit PCI Express Linux driver
5 Copyright(c) 1999 - 2012 Intel Corporation.
8 e1000-devel Mailing List <e1000-devel@lists.sourceforge.net>
9 Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
11 *******************************************************************************/
13 #include "ixgbe_type.h"
14 #include "ixgbe_82599.h"
15 #include "ixgbe_api.h"
16 #include "ixgbe_common.h"
17 #include "ixgbe_phy.h"
19 static s32
ixgbe_setup_copper_link_82599(struct ixgbe_hw
*hw
,
20 ixgbe_link_speed speed
,
22 bool autoneg_wait_to_complete
);
23 static s32
ixgbe_verify_fw_version_82599(struct ixgbe_hw
*hw
);
24 static s32
ixgbe_read_eeprom_82599(struct ixgbe_hw
*hw
,
25 u16 offset
, u16
*data
);
26 static s32
ixgbe_read_eeprom_buffer_82599(struct ixgbe_hw
*hw
, u16 offset
,
27 u16 words
, u16
*data
);
28 static s32
ixgbe_read_i2c_byte_82599(struct ixgbe_hw
*hw
, u8 byte_offset
,
29 u8 dev_addr
, u8
*data
);
30 static s32
ixgbe_write_i2c_byte_82599(struct ixgbe_hw
*hw
, u8 byte_offset
,
31 u8 dev_addr
, u8 data
);
33 void ixgbe_init_mac_link_ops_82599(struct ixgbe_hw
*hw
)
35 struct ixgbe_mac_info
*mac
= &hw
->mac
;
37 /* enable the laser control functions for SFP+ fiber */
38 if (mac
->ops
.get_media_type(hw
) == ixgbe_media_type_fiber
) {
39 mac
->ops
.disable_tx_laser
=
40 &ixgbe_disable_tx_laser_multispeed_fiber
;
41 mac
->ops
.enable_tx_laser
=
42 &ixgbe_enable_tx_laser_multispeed_fiber
;
43 mac
->ops
.flap_tx_laser
= &ixgbe_flap_tx_laser_multispeed_fiber
;
46 mac
->ops
.disable_tx_laser
= NULL
;
47 mac
->ops
.enable_tx_laser
= NULL
;
48 mac
->ops
.flap_tx_laser
= NULL
;
51 if (hw
->phy
.multispeed_fiber
) {
52 /* Set up dual speed SFP+ support */
53 mac
->ops
.setup_link
= &ixgbe_setup_mac_link_multispeed_fiber
;
55 if ((ixgbe_get_media_type(hw
) == ixgbe_media_type_backplane
) &&
56 (hw
->phy
.smart_speed
== ixgbe_smart_speed_auto
||
57 hw
->phy
.smart_speed
== ixgbe_smart_speed_on
) &&
58 !ixgbe_verify_lesm_fw_enabled_82599(hw
)) {
59 mac
->ops
.setup_link
= &ixgbe_setup_mac_link_smartspeed
;
61 mac
->ops
.setup_link
= &ixgbe_setup_mac_link_82599
;
67 * ixgbe_init_phy_ops_82599 - PHY/SFP specific init
68 * @hw: pointer to hardware structure
70 * Initialize any function pointers that were not able to be
71 * set during init_shared_code because the PHY/SFP type was
72 * not known. Perform the SFP init if necessary.
75 s32
ixgbe_init_phy_ops_82599(struct ixgbe_hw
*hw
)
77 struct ixgbe_mac_info
*mac
= &hw
->mac
;
78 struct ixgbe_phy_info
*phy
= &hw
->phy
;
82 if (hw
->device_id
== IXGBE_DEV_ID_82599_QSFP_SF_QP
) {
83 /* Store flag indicating I2C bus access control unit. */
84 hw
->phy
.qsfp_shared_i2c_bus
= TRUE
;
86 /* Initialize access to QSFP+ I2C bus */
87 esdp
= IXGBE_READ_REG(hw
, IXGBE_ESDP
);
88 esdp
|= IXGBE_ESDP_SDP0_DIR
;
89 esdp
&= ~IXGBE_ESDP_SDP1_DIR
;
90 esdp
&= ~IXGBE_ESDP_SDP0
;
91 esdp
&= ~IXGBE_ESDP_SDP0_NATIVE
;
92 esdp
&= ~IXGBE_ESDP_SDP1_NATIVE
;
93 IXGBE_WRITE_REG(hw
, IXGBE_ESDP
, esdp
);
94 IXGBE_WRITE_FLUSH(hw
);
96 phy
->ops
.read_i2c_byte
= &ixgbe_read_i2c_byte_82599
;
97 phy
->ops
.write_i2c_byte
= &ixgbe_write_i2c_byte_82599
;
99 /* Identify the PHY or SFP module */
100 ret_val
= phy
->ops
.identify(hw
);
101 if (ret_val
== IXGBE_ERR_SFP_NOT_SUPPORTED
)
102 goto init_phy_ops_out
;
104 /* Setup function pointers based on detected SFP module and speeds */
105 ixgbe_init_mac_link_ops_82599(hw
);
106 if (hw
->phy
.sfp_type
!= ixgbe_sfp_type_unknown
)
107 hw
->phy
.ops
.reset
= NULL
;
109 /* If copper media, overwrite with copper function pointers */
110 if (mac
->ops
.get_media_type(hw
) == ixgbe_media_type_copper
) {
111 mac
->ops
.setup_link
= &ixgbe_setup_copper_link_82599
;
112 mac
->ops
.get_link_capabilities
=
113 &ixgbe_get_copper_link_capabilities_generic
;
116 /* Set necessary function pointers based on phy type */
117 switch (hw
->phy
.type
) {
119 phy
->ops
.setup_link
= &ixgbe_setup_phy_link_tnx
;
120 phy
->ops
.check_link
= &ixgbe_check_phy_link_tnx
;
121 phy
->ops
.get_firmware_version
=
122 &ixgbe_get_phy_firmware_version_tnx
;
131 s32
ixgbe_setup_sfp_modules_82599(struct ixgbe_hw
*hw
)
136 u16 list_offset
, data_offset
, data_value
;
138 if (hw
->phy
.sfp_type
!= ixgbe_sfp_type_unknown
) {
139 ixgbe_init_mac_link_ops_82599(hw
);
141 hw
->phy
.ops
.reset
= NULL
;
143 ret_val
= ixgbe_get_sfp_init_sequence_offsets(hw
, &list_offset
,
148 /* PHY config will finish before releasing the semaphore */
149 ret_val
= hw
->mac
.ops
.acquire_swfw_sync(hw
,
150 IXGBE_GSSR_MAC_CSR_SM
);
152 ret_val
= IXGBE_ERR_SWFW_SYNC
;
156 hw
->eeprom
.ops
.read(hw
, ++data_offset
, &data_value
);
157 while (data_value
!= 0xffff) {
158 IXGBE_WRITE_REG(hw
, IXGBE_CORECTL
, data_value
);
159 IXGBE_WRITE_FLUSH(hw
);
160 hw
->eeprom
.ops
.read(hw
, ++data_offset
, &data_value
);
163 /* Release the semaphore */
164 hw
->mac
.ops
.release_swfw_sync(hw
, IXGBE_GSSR_MAC_CSR_SM
);
165 /* Delay obtaining semaphore again to allow FW access */
166 msleep(hw
->eeprom
.semaphore_delay
);
168 /* Now restart DSP by setting Restart_AN and clearing LMS */
169 IXGBE_WRITE_REG(hw
, IXGBE_AUTOC
, ((IXGBE_READ_REG(hw
,
170 IXGBE_AUTOC
) & ~IXGBE_AUTOC_LMS_MASK
) |
171 IXGBE_AUTOC_AN_RESTART
));
173 /* Wait for AN to leave state 0 */
174 for (i
= 0; i
< 10; i
++) {
176 reg_anlp1
= IXGBE_READ_REG(hw
, IXGBE_ANLP1
);
177 if (reg_anlp1
& IXGBE_ANLP1_AN_STATE_MASK
)
180 if (!(reg_anlp1
& IXGBE_ANLP1_AN_STATE_MASK
)) {
181 hw_dbg(hw
, "sfp module setup not complete\n");
182 ret_val
= IXGBE_ERR_SFP_SETUP_NOT_COMPLETE
;
186 /* Restart DSP by setting Restart_AN and return to SFI mode */
187 IXGBE_WRITE_REG(hw
, IXGBE_AUTOC
, (IXGBE_READ_REG(hw
,
188 IXGBE_AUTOC
) | IXGBE_AUTOC_LMS_10G_SERIAL
|
189 IXGBE_AUTOC_AN_RESTART
));
197 * ixgbe_init_ops_82599 - Inits func ptrs and MAC type
198 * @hw: pointer to hardware structure
200 * Initialize the function pointers and assign the MAC type for 82599.
201 * Does not touch the hardware.
204 s32
ixgbe_init_ops_82599(struct ixgbe_hw
*hw
)
206 struct ixgbe_mac_info
*mac
= &hw
->mac
;
207 struct ixgbe_phy_info
*phy
= &hw
->phy
;
208 struct ixgbe_eeprom_info
*eeprom
= &hw
->eeprom
;
211 ixgbe_init_phy_ops_generic(hw
);
212 ret_val
= ixgbe_init_ops_generic(hw
);
215 phy
->ops
.identify
= &ixgbe_identify_phy_82599
;
216 phy
->ops
.init
= &ixgbe_init_phy_ops_82599
;
219 mac
->ops
.reset_hw
= &ixgbe_reset_hw_82599
;
220 mac
->ops
.get_media_type
= &ixgbe_get_media_type_82599
;
221 mac
->ops
.get_supported_physical_layer
=
222 &ixgbe_get_supported_physical_layer_82599
;
223 mac
->ops
.disable_sec_rx_path
= &ixgbe_disable_sec_rx_path_generic
;
224 mac
->ops
.enable_sec_rx_path
= &ixgbe_enable_sec_rx_path_generic
;
225 mac
->ops
.enable_rx_dma
= &ixgbe_enable_rx_dma_82599
;
226 mac
->ops
.read_analog_reg8
= &ixgbe_read_analog_reg8_82599
;
227 mac
->ops
.write_analog_reg8
= &ixgbe_write_analog_reg8_82599
;
228 mac
->ops
.start_hw
= &ixgbe_start_hw_82599
;
229 mac
->ops
.get_san_mac_addr
= &ixgbe_get_san_mac_addr_generic
;
230 mac
->ops
.set_san_mac_addr
= &ixgbe_set_san_mac_addr_generic
;
231 mac
->ops
.get_device_caps
= &ixgbe_get_device_caps_generic
;
232 mac
->ops
.get_wwn_prefix
= &ixgbe_get_wwn_prefix_generic
;
233 mac
->ops
.get_fcoe_boot_status
= &ixgbe_get_fcoe_boot_status_generic
;
235 /* RAR, Multicast, VLAN */
236 mac
->ops
.set_vmdq
= &ixgbe_set_vmdq_generic
;
237 mac
->ops
.set_vmdq_san_mac
= &ixgbe_set_vmdq_san_mac_generic
;
238 mac
->ops
.clear_vmdq
= &ixgbe_clear_vmdq_generic
;
239 mac
->ops
.insert_mac_addr
= &ixgbe_insert_mac_addr_generic
;
240 mac
->rar_highwater
= 1;
241 mac
->ops
.set_vfta
= &ixgbe_set_vfta_generic
;
242 mac
->ops
.set_vlvf
= &ixgbe_set_vlvf_generic
;
243 mac
->ops
.clear_vfta
= &ixgbe_clear_vfta_generic
;
244 mac
->ops
.init_uta_tables
= &ixgbe_init_uta_tables_generic
;
245 mac
->ops
.setup_sfp
= &ixgbe_setup_sfp_modules_82599
;
246 mac
->ops
.set_mac_anti_spoofing
= &ixgbe_set_mac_anti_spoofing
;
247 mac
->ops
.set_vlan_anti_spoofing
= &ixgbe_set_vlan_anti_spoofing
;
250 mac
->ops
.get_link_capabilities
= &ixgbe_get_link_capabilities_82599
;
251 mac
->ops
.check_link
= &ixgbe_check_mac_link_generic
;
252 mac
->ops
.setup_rxpba
= &ixgbe_set_rxpba_generic
;
253 ixgbe_init_mac_link_ops_82599(hw
);
255 mac
->mcft_size
= 128;
257 mac
->num_rar_entries
= 128;
258 mac
->rx_pb_size
= 512;
259 mac
->max_tx_queues
= 128;
260 mac
->max_rx_queues
= 128;
261 mac
->max_msix_vectors
= ixgbe_get_pcie_msix_count_generic(hw
);
263 mac
->arc_subsystem_valid
= (IXGBE_READ_REG(hw
, IXGBE_FWSM
) &
264 IXGBE_FWSM_MODE_MASK
) ? true : false;
266 //hw->mbx.ops.init_params = ixgbe_init_mbx_params_pf;
269 eeprom
->ops
.read
= &ixgbe_read_eeprom_82599
;
270 eeprom
->ops
.read_buffer
= &ixgbe_read_eeprom_buffer_82599
;
272 /* Manageability interface */
273 mac
->ops
.set_fw_drv_ver
= &ixgbe_set_fw_drv_ver_generic
;
275 mac
->ops
.get_thermal_sensor_data
=
276 &ixgbe_get_thermal_sensor_data_generic
;
277 mac
->ops
.init_thermal_sensor_thresh
=
278 &ixgbe_init_thermal_sensor_thresh_generic
;
284 * ixgbe_get_link_capabilities_82599 - Determines link capabilities
285 * @hw: pointer to hardware structure
286 * @speed: pointer to link speed
287 * @negotiation: true when autoneg or autotry is enabled
289 * Determines the link capabilities by reading the AUTOC register.
291 s32
ixgbe_get_link_capabilities_82599(struct ixgbe_hw
*hw
,
292 ixgbe_link_speed
*speed
,
298 /* Check if 1G SFP module. */
299 if (hw
->phy
.sfp_type
== ixgbe_sfp_type_1g_cu_core0
||
300 hw
->phy
.sfp_type
== ixgbe_sfp_type_1g_cu_core1
||
301 hw
->phy
.sfp_type
== ixgbe_sfp_type_1g_sx_core0
||
302 hw
->phy
.sfp_type
== ixgbe_sfp_type_1g_sx_core1
) {
303 *speed
= IXGBE_LINK_SPEED_1GB_FULL
;
309 * Determine link capabilities based on the stored value of AUTOC,
310 * which represents EEPROM defaults. If AUTOC value has not
311 * been stored, use the current register values.
313 if (hw
->mac
.orig_link_settings_stored
)
314 autoc
= hw
->mac
.orig_autoc
;
316 autoc
= IXGBE_READ_REG(hw
, IXGBE_AUTOC
);
318 switch (autoc
& IXGBE_AUTOC_LMS_MASK
) {
319 case IXGBE_AUTOC_LMS_1G_LINK_NO_AN
:
320 *speed
= IXGBE_LINK_SPEED_1GB_FULL
;
321 *negotiation
= false;
324 case IXGBE_AUTOC_LMS_10G_LINK_NO_AN
:
325 *speed
= IXGBE_LINK_SPEED_10GB_FULL
;
326 *negotiation
= false;
329 case IXGBE_AUTOC_LMS_1G_AN
:
330 *speed
= IXGBE_LINK_SPEED_1GB_FULL
;
334 case IXGBE_AUTOC_LMS_10G_SERIAL
:
335 *speed
= IXGBE_LINK_SPEED_10GB_FULL
;
336 *negotiation
= false;
339 case IXGBE_AUTOC_LMS_KX4_KX_KR
:
340 case IXGBE_AUTOC_LMS_KX4_KX_KR_1G_AN
:
341 *speed
= IXGBE_LINK_SPEED_UNKNOWN
;
342 if (autoc
& IXGBE_AUTOC_KR_SUPP
)
343 *speed
|= IXGBE_LINK_SPEED_10GB_FULL
;
344 if (autoc
& IXGBE_AUTOC_KX4_SUPP
)
345 *speed
|= IXGBE_LINK_SPEED_10GB_FULL
;
346 if (autoc
& IXGBE_AUTOC_KX_SUPP
)
347 *speed
|= IXGBE_LINK_SPEED_1GB_FULL
;
351 case IXGBE_AUTOC_LMS_KX4_KX_KR_SGMII
:
352 *speed
= IXGBE_LINK_SPEED_100_FULL
;
353 if (autoc
& IXGBE_AUTOC_KR_SUPP
)
354 *speed
|= IXGBE_LINK_SPEED_10GB_FULL
;
355 if (autoc
& IXGBE_AUTOC_KX4_SUPP
)
356 *speed
|= IXGBE_LINK_SPEED_10GB_FULL
;
357 if (autoc
& IXGBE_AUTOC_KX_SUPP
)
358 *speed
|= IXGBE_LINK_SPEED_1GB_FULL
;
362 case IXGBE_AUTOC_LMS_SGMII_1G_100M
:
363 *speed
= IXGBE_LINK_SPEED_1GB_FULL
| IXGBE_LINK_SPEED_100_FULL
;
364 *negotiation
= false;
368 status
= IXGBE_ERR_LINK_SETUP
;
373 if (hw
->phy
.multispeed_fiber
) {
374 *speed
|= IXGBE_LINK_SPEED_10GB_FULL
|
375 IXGBE_LINK_SPEED_1GB_FULL
;
384 * ixgbe_get_media_type_82599 - Get media type
385 * @hw: pointer to hardware structure
387 * Returns the media type (fiber, copper, backplane)
389 enum ixgbe_media_type
ixgbe_get_media_type_82599(struct ixgbe_hw
*hw
)
391 enum ixgbe_media_type media_type
;
393 /* Detect if there is a copper PHY attached. */
394 switch (hw
->phy
.type
) {
395 case ixgbe_phy_cu_unknown
:
397 media_type
= ixgbe_media_type_copper
;
403 switch (hw
->device_id
) {
404 case IXGBE_DEV_ID_82599_KX4
:
405 case IXGBE_DEV_ID_82599_KX4_MEZZ
:
406 case IXGBE_DEV_ID_82599_COMBO_BACKPLANE
:
407 case IXGBE_DEV_ID_82599_KR
:
408 case IXGBE_DEV_ID_82599_BACKPLANE_FCOE
:
409 case IXGBE_DEV_ID_82599_XAUI_LOM
:
410 /* Default device ID is mezzanine card KX/KX4 */
411 media_type
= ixgbe_media_type_backplane
;
413 case IXGBE_DEV_ID_82599_SFP
:
414 case IXGBE_DEV_ID_82599_SFP_FCOE
:
415 case IXGBE_DEV_ID_82599_SFP_EM
:
416 case IXGBE_DEV_ID_82599_SFP_SF2
:
417 case IXGBE_DEV_ID_82599EN_SFP
:
418 media_type
= ixgbe_media_type_fiber
;
420 case IXGBE_DEV_ID_82599_CX4
:
421 media_type
= ixgbe_media_type_cx4
;
423 case IXGBE_DEV_ID_82599_T3_LOM
:
424 media_type
= ixgbe_media_type_copper
;
426 case IXGBE_DEV_ID_82599_LS
:
427 media_type
= ixgbe_media_type_fiber_lco
;
429 case IXGBE_DEV_ID_82599_QSFP_SF_QP
:
430 media_type
= ixgbe_media_type_fiber_qsfp
;
433 media_type
= ixgbe_media_type_unknown
;
441 * ixgbe_start_mac_link_82599 - Setup MAC link settings
442 * @hw: pointer to hardware structure
443 * @autoneg_wait_to_complete: true when waiting for completion is needed
445 * Configures link settings based on values in the ixgbe_hw struct.
446 * Restarts the link. Performs autonegotiation if needed.
448 s32
ixgbe_start_mac_link_82599(struct ixgbe_hw
*hw
,
449 bool autoneg_wait_to_complete
)
457 autoc_reg
= IXGBE_READ_REG(hw
, IXGBE_AUTOC
);
458 autoc_reg
|= IXGBE_AUTOC_AN_RESTART
;
459 IXGBE_WRITE_REG(hw
, IXGBE_AUTOC
, autoc_reg
);
461 /* Only poll for autoneg to complete if specified to do so */
462 if (autoneg_wait_to_complete
) {
463 if ((autoc_reg
& IXGBE_AUTOC_LMS_MASK
) ==
464 IXGBE_AUTOC_LMS_KX4_KX_KR
||
465 (autoc_reg
& IXGBE_AUTOC_LMS_MASK
) ==
466 IXGBE_AUTOC_LMS_KX4_KX_KR_1G_AN
||
467 (autoc_reg
& IXGBE_AUTOC_LMS_MASK
) ==
468 IXGBE_AUTOC_LMS_KX4_KX_KR_SGMII
) {
469 for (i
= 0; i
< IXGBE_AUTO_NEG_TIME
; i
++) {
470 links_reg
= IXGBE_READ_REG(hw
, IXGBE_LINKS
);
471 if (links_reg
& IXGBE_LINKS_KX_AN_COMP
)
475 if (!(links_reg
& IXGBE_LINKS_KX_AN_COMP
)) {
476 status
= IXGBE_ERR_AUTONEG_NOT_COMPLETE
;
477 hw_dbg(hw
, "Autoneg did not complete.\n");
482 /* Add delay to filter out noises during initial link setup */
489 * ixgbe_disable_tx_laser_multispeed_fiber - Disable Tx laser
490 * @hw: pointer to hardware structure
492 * The base drivers may require better control over SFP+ module
493 * PHY states. This includes selectively shutting down the Tx
494 * laser on the PHY, effectively halting physical link.
496 void ixgbe_disable_tx_laser_multispeed_fiber(struct ixgbe_hw
*hw
)
498 u32 esdp_reg
= IXGBE_READ_REG(hw
, IXGBE_ESDP
);
500 /* Disable tx laser; allow 100us to go dark per spec */
501 esdp_reg
|= IXGBE_ESDP_SDP3
;
502 IXGBE_WRITE_REG(hw
, IXGBE_ESDP
, esdp_reg
);
503 IXGBE_WRITE_FLUSH(hw
);
508 * ixgbe_enable_tx_laser_multispeed_fiber - Enable Tx laser
509 * @hw: pointer to hardware structure
511 * The base drivers may require better control over SFP+ module
512 * PHY states. This includes selectively turning on the Tx
513 * laser on the PHY, effectively starting physical link.
515 void ixgbe_enable_tx_laser_multispeed_fiber(struct ixgbe_hw
*hw
)
517 u32 esdp_reg
= IXGBE_READ_REG(hw
, IXGBE_ESDP
);
519 /* Enable tx laser; allow 100ms to light up */
520 esdp_reg
&= ~IXGBE_ESDP_SDP3
;
521 IXGBE_WRITE_REG(hw
, IXGBE_ESDP
, esdp_reg
);
522 IXGBE_WRITE_FLUSH(hw
);
527 * ixgbe_flap_tx_laser_multispeed_fiber - Flap Tx laser
528 * @hw: pointer to hardware structure
530 * When the driver changes the link speeds that it can support,
531 * it sets autotry_restart to true to indicate that we need to
532 * initiate a new autotry session with the link partner. To do
533 * so, we set the speed then disable and re-enable the tx laser, to
534 * alert the link partner that it also needs to restart autotry on its
535 * end. This is consistent with true clause 37 autoneg, which also
536 * involves a loss of signal.
538 void ixgbe_flap_tx_laser_multispeed_fiber(struct ixgbe_hw
*hw
)
540 if (hw
->mac
.autotry_restart
) {
541 ixgbe_disable_tx_laser_multispeed_fiber(hw
);
542 ixgbe_enable_tx_laser_multispeed_fiber(hw
);
543 hw
->mac
.autotry_restart
= false;
548 * ixgbe_setup_mac_link_multispeed_fiber - Set MAC link speed
549 * @hw: pointer to hardware structure
550 * @speed: new link speed
551 * @autoneg: true if autonegotiation enabled
552 * @autoneg_wait_to_complete: true when waiting for completion is needed
554 * Set the link speed in the AUTOC register and restarts link.
556 s32
ixgbe_setup_mac_link_multispeed_fiber(struct ixgbe_hw
*hw
,
557 ixgbe_link_speed speed
, bool autoneg
,
558 bool autoneg_wait_to_complete
)
561 ixgbe_link_speed link_speed
= IXGBE_LINK_SPEED_UNKNOWN
;
562 ixgbe_link_speed highest_link_speed
= IXGBE_LINK_SPEED_UNKNOWN
;
564 u32 esdp_reg
= IXGBE_READ_REG(hw
, IXGBE_ESDP
);
566 bool link_up
= false;
569 /* Mask off requested but non-supported speeds */
570 status
= ixgbe_get_link_capabilities(hw
, &link_speed
, &negotiation
);
577 * Try each speed one by one, highest priority first. We do this in
578 * software because 10gb fiber doesn't support speed autonegotiation.
580 if (speed
& IXGBE_LINK_SPEED_10GB_FULL
) {
582 highest_link_speed
= IXGBE_LINK_SPEED_10GB_FULL
;
584 /* If we already have link at this speed, just jump out */
585 status
= ixgbe_check_link(hw
, &link_speed
, &link_up
, false);
589 if ((link_speed
== IXGBE_LINK_SPEED_10GB_FULL
) && link_up
)
592 /* Set the module link speed */
593 esdp_reg
|= (IXGBE_ESDP_SDP5_DIR
| IXGBE_ESDP_SDP5
);
594 IXGBE_WRITE_REG(hw
, IXGBE_ESDP
, esdp_reg
);
595 IXGBE_WRITE_FLUSH(hw
);
597 /* Allow module to change analog characteristics (1G->10G) */
600 status
= ixgbe_setup_mac_link_82599(hw
,
601 IXGBE_LINK_SPEED_10GB_FULL
,
603 autoneg_wait_to_complete
);
607 /* Flap the tx laser if it has not already been done */
608 ixgbe_flap_tx_laser(hw
);
611 * Wait for the controller to acquire link. Per IEEE 802.3ap,
612 * Section 73.10.2, we may have to wait up to 500ms if KR is
613 * attempted. 82599 uses the same timing for 10g SFI.
615 for (i
= 0; i
< 5; i
++) {
616 /* Wait for the link partner to also set speed */
619 /* If we have link, just jump out */
620 status
= ixgbe_check_link(hw
, &link_speed
,
630 if (speed
& IXGBE_LINK_SPEED_1GB_FULL
) {
632 if (highest_link_speed
== IXGBE_LINK_SPEED_UNKNOWN
)
633 highest_link_speed
= IXGBE_LINK_SPEED_1GB_FULL
;
635 /* If we already have link at this speed, just jump out */
636 status
= ixgbe_check_link(hw
, &link_speed
, &link_up
, false);
640 if ((link_speed
== IXGBE_LINK_SPEED_1GB_FULL
) && link_up
)
643 /* Set the module link speed */
644 esdp_reg
&= ~IXGBE_ESDP_SDP5
;
645 esdp_reg
|= IXGBE_ESDP_SDP5_DIR
;
646 IXGBE_WRITE_REG(hw
, IXGBE_ESDP
, esdp_reg
);
647 IXGBE_WRITE_FLUSH(hw
);
649 /* Allow module to change analog characteristics (10G->1G) */
652 status
= ixgbe_setup_mac_link_82599(hw
,
653 IXGBE_LINK_SPEED_1GB_FULL
,
655 autoneg_wait_to_complete
);
659 /* Flap the tx laser if it has not already been done */
660 ixgbe_flap_tx_laser(hw
);
662 /* Wait for the link partner to also set speed */
665 /* If we have link, just jump out */
666 status
= ixgbe_check_link(hw
, &link_speed
, &link_up
, false);
675 * We didn't get link. Configure back to the highest speed we tried,
676 * (if there was more than one). We call ourselves back with just the
677 * single highest speed that the user requested.
680 status
= ixgbe_setup_mac_link_multispeed_fiber(hw
,
681 highest_link_speed
, autoneg
, autoneg_wait_to_complete
);
684 /* Set autoneg_advertised value based on input link speed */
685 hw
->phy
.autoneg_advertised
= 0;
687 if (speed
& IXGBE_LINK_SPEED_10GB_FULL
)
688 hw
->phy
.autoneg_advertised
|= IXGBE_LINK_SPEED_10GB_FULL
;
690 if (speed
& IXGBE_LINK_SPEED_1GB_FULL
)
691 hw
->phy
.autoneg_advertised
|= IXGBE_LINK_SPEED_1GB_FULL
;
697 * ixgbe_setup_mac_link_smartspeed - Set MAC link speed using SmartSpeed
698 * @hw: pointer to hardware structure
699 * @speed: new link speed
700 * @autoneg: true if autonegotiation enabled
701 * @autoneg_wait_to_complete: true when waiting for completion is needed
703 * Implements the Intel SmartSpeed algorithm.
705 s32
ixgbe_setup_mac_link_smartspeed(struct ixgbe_hw
*hw
,
706 ixgbe_link_speed speed
, bool autoneg
,
707 bool autoneg_wait_to_complete
)
710 ixgbe_link_speed link_speed
= IXGBE_LINK_SPEED_UNKNOWN
;
712 bool link_up
= false;
713 u32 autoc_reg
= IXGBE_READ_REG(hw
, IXGBE_AUTOC
);
715 /* Set autoneg_advertised value based on input link speed */
716 hw
->phy
.autoneg_advertised
= 0;
718 if (speed
& IXGBE_LINK_SPEED_10GB_FULL
)
719 hw
->phy
.autoneg_advertised
|= IXGBE_LINK_SPEED_10GB_FULL
;
721 if (speed
& IXGBE_LINK_SPEED_1GB_FULL
)
722 hw
->phy
.autoneg_advertised
|= IXGBE_LINK_SPEED_1GB_FULL
;
724 if (speed
& IXGBE_LINK_SPEED_100_FULL
)
725 hw
->phy
.autoneg_advertised
|= IXGBE_LINK_SPEED_100_FULL
;
728 * Implement Intel SmartSpeed algorithm. SmartSpeed will reduce the
729 * autoneg advertisement if link is unable to be established at the
730 * highest negotiated rate. This can sometimes happen due to integrity
731 * issues with the physical media connection.
734 /* First, try to get link with full advertisement */
735 hw
->phy
.smart_speed_active
= false;
736 for (j
= 0; j
< IXGBE_SMARTSPEED_MAX_RETRIES
; j
++) {
737 status
= ixgbe_setup_mac_link_82599(hw
, speed
, autoneg
,
738 autoneg_wait_to_complete
);
743 * Wait for the controller to acquire link. Per IEEE 802.3ap,
744 * Section 73.10.2, we may have to wait up to 500ms if KR is
745 * attempted, or 200ms if KX/KX4/BX/BX4 is attempted, per
746 * Table 9 in the AN MAS.
748 for (i
= 0; i
< 5; i
++) {
751 /* If we have link, just jump out */
752 status
= ixgbe_check_link(hw
, &link_speed
, &link_up
,
763 * We didn't get link. If we advertised KR plus one of KX4/KX
764 * (or BX4/BX), then disable KR and try again.
766 if (((autoc_reg
& IXGBE_AUTOC_KR_SUPP
) == 0) ||
767 ((autoc_reg
& IXGBE_AUTOC_KX4_KX_SUPP_MASK
) == 0))
770 /* Turn SmartSpeed on to disable KR support */
771 hw
->phy
.smart_speed_active
= true;
772 status
= ixgbe_setup_mac_link_82599(hw
, speed
, autoneg
,
773 autoneg_wait_to_complete
);
778 * Wait for the controller to acquire link. 600ms will allow for
779 * the AN link_fail_inhibit_timer as well for multiple cycles of
780 * parallel detect, both 10g and 1g. This allows for the maximum
781 * connect attempts as defined in the AN MAS table 73-7.
783 for (i
= 0; i
< 6; i
++) {
786 /* If we have link, just jump out */
787 status
= ixgbe_check_link(hw
, &link_speed
, &link_up
, false);
795 /* We didn't get link. Turn SmartSpeed back off. */
796 hw
->phy
.smart_speed_active
= false;
797 status
= ixgbe_setup_mac_link_82599(hw
, speed
, autoneg
,
798 autoneg_wait_to_complete
);
801 if (link_up
&& (link_speed
== IXGBE_LINK_SPEED_1GB_FULL
))
802 hw_dbg(hw
, "Smartspeed has downgraded the link speed "
803 "from the maximum advertised\n");
808 * ixgbe_setup_mac_link_82599 - Set MAC link speed
809 * @hw: pointer to hardware structure
810 * @speed: new link speed
811 * @autoneg: true if autonegotiation enabled
812 * @autoneg_wait_to_complete: true when waiting for completion is needed
814 * Set the link speed in the AUTOC register and restarts link.
816 s32
ixgbe_setup_mac_link_82599(struct ixgbe_hw
*hw
,
817 ixgbe_link_speed speed
, bool autoneg
,
818 bool autoneg_wait_to_complete
)
821 u32 autoc
= IXGBE_READ_REG(hw
, IXGBE_AUTOC
);
822 u32 autoc2
= IXGBE_READ_REG(hw
, IXGBE_AUTOC2
);
823 u32 start_autoc
= autoc
;
825 u32 link_mode
= autoc
& IXGBE_AUTOC_LMS_MASK
;
826 u32 pma_pmd_1g
= autoc
& IXGBE_AUTOC_1G_PMA_PMD_MASK
;
827 u32 pma_pmd_10g_serial
= autoc2
& IXGBE_AUTOC2_10G_SERIAL_PMA_PMD_MASK
;
830 ixgbe_link_speed link_capabilities
= IXGBE_LINK_SPEED_UNKNOWN
;
832 /* Check to see if speed passed in is supported. */
833 status
= ixgbe_get_link_capabilities(hw
, &link_capabilities
, &autoneg
);
837 speed
&= link_capabilities
;
839 if (speed
== IXGBE_LINK_SPEED_UNKNOWN
) {
840 status
= IXGBE_ERR_LINK_SETUP
;
844 /* Use stored value (EEPROM defaults) of AUTOC to find KR/KX4 support*/
845 if (hw
->mac
.orig_link_settings_stored
)
846 orig_autoc
= hw
->mac
.orig_autoc
;
850 if (link_mode
== IXGBE_AUTOC_LMS_KX4_KX_KR
||
851 link_mode
== IXGBE_AUTOC_LMS_KX4_KX_KR_1G_AN
||
852 link_mode
== IXGBE_AUTOC_LMS_KX4_KX_KR_SGMII
) {
853 /* Set KX4/KX/KR support according to speed requested */
854 autoc
&= ~(IXGBE_AUTOC_KX4_KX_SUPP_MASK
| IXGBE_AUTOC_KR_SUPP
);
855 if (speed
& IXGBE_LINK_SPEED_10GB_FULL
) {
856 if (orig_autoc
& IXGBE_AUTOC_KX4_SUPP
)
857 autoc
|= IXGBE_AUTOC_KX4_SUPP
;
858 if ((orig_autoc
& IXGBE_AUTOC_KR_SUPP
) &&
859 (hw
->phy
.smart_speed_active
== false))
860 autoc
|= IXGBE_AUTOC_KR_SUPP
;
862 if (speed
& IXGBE_LINK_SPEED_1GB_FULL
)
863 autoc
|= IXGBE_AUTOC_KX_SUPP
;
864 } else if ((pma_pmd_1g
== IXGBE_AUTOC_1G_SFI
) &&
865 (link_mode
== IXGBE_AUTOC_LMS_1G_LINK_NO_AN
||
866 link_mode
== IXGBE_AUTOC_LMS_1G_AN
)) {
867 /* Switch from 1G SFI to 10G SFI if requested */
868 if ((speed
== IXGBE_LINK_SPEED_10GB_FULL
) &&
869 (pma_pmd_10g_serial
== IXGBE_AUTOC2_10G_SFI
)) {
870 autoc
&= ~IXGBE_AUTOC_LMS_MASK
;
871 autoc
|= IXGBE_AUTOC_LMS_10G_SERIAL
;
873 } else if ((pma_pmd_10g_serial
== IXGBE_AUTOC2_10G_SFI
) &&
874 (link_mode
== IXGBE_AUTOC_LMS_10G_SERIAL
)) {
875 /* Switch from 10G SFI to 1G SFI if requested */
876 if ((speed
== IXGBE_LINK_SPEED_1GB_FULL
) &&
877 (pma_pmd_1g
== IXGBE_AUTOC_1G_SFI
)) {
878 autoc
&= ~IXGBE_AUTOC_LMS_MASK
;
880 autoc
|= IXGBE_AUTOC_LMS_1G_AN
;
882 autoc
|= IXGBE_AUTOC_LMS_1G_LINK_NO_AN
;
886 if (autoc
!= start_autoc
) {
888 autoc
|= IXGBE_AUTOC_AN_RESTART
;
889 IXGBE_WRITE_REG(hw
, IXGBE_AUTOC
, autoc
);
891 /* Only poll for autoneg to complete if specified to do so */
892 if (autoneg_wait_to_complete
) {
893 if (link_mode
== IXGBE_AUTOC_LMS_KX4_KX_KR
||
894 link_mode
== IXGBE_AUTOC_LMS_KX4_KX_KR_1G_AN
||
895 link_mode
== IXGBE_AUTOC_LMS_KX4_KX_KR_SGMII
) {
896 for (i
= 0; i
< IXGBE_AUTO_NEG_TIME
; i
++) {
898 IXGBE_READ_REG(hw
, IXGBE_LINKS
);
899 if (links_reg
& IXGBE_LINKS_KX_AN_COMP
)
903 if (!(links_reg
& IXGBE_LINKS_KX_AN_COMP
)) {
905 IXGBE_ERR_AUTONEG_NOT_COMPLETE
;
906 hw_dbg(hw
, "Autoneg did not complete.\n");
911 /* Add delay to filter out noises during initial link setup */
920 * ixgbe_setup_copper_link_82599 - Set the PHY autoneg advertised field
921 * @hw: pointer to hardware structure
922 * @speed: new link speed
923 * @autoneg: true if autonegotiation enabled
924 * @autoneg_wait_to_complete: true if waiting is needed to complete
926 * Restarts link on PHY and MAC based on settings passed in.
928 static s32
ixgbe_setup_copper_link_82599(struct ixgbe_hw
*hw
,
929 ixgbe_link_speed speed
,
931 bool autoneg_wait_to_complete
)
935 /* Setup the PHY according to input speed */
936 status
= hw
->phy
.ops
.setup_link_speed(hw
, speed
, autoneg
,
937 autoneg_wait_to_complete
);
939 ixgbe_start_mac_link_82599(hw
, autoneg_wait_to_complete
);
945 * ixgbe_reset_hw_82599 - Perform hardware reset
946 * @hw: pointer to hardware structure
948 * Resets the hardware by resetting the transmit and receive units, masks
949 * and clears all interrupts, perform a PHY reset, and perform a link (MAC)
952 s32
ixgbe_reset_hw_82599(struct ixgbe_hw
*hw
)
954 // ixgbe_link_speed link_speed;
956 // u32 ctrl, i, autoc, autoc2;
957 // bool link_up = false;
960 /* Call adapter stop to disable tx/rx and clear interrupts */
961 status
= hw
->mac
.ops
.stop_adapter(hw
);
965 /* flush pending Tx transactions */
966 ixgbe_clear_tx_pending(hw
);
968 /* PHY ops must be identified and initialized prior to reset */
970 /* Identify PHY and related function pointers */
971 status
= hw
->phy
.ops
.init(hw
);
973 if (status
== IXGBE_ERR_SFP_NOT_SUPPORTED
)
976 /* Setup SFP module if there is one present. */
977 if (hw
->phy
.sfp_setup_needed
) {
978 status
= hw
->mac
.ops
.setup_sfp(hw
);
979 hw
->phy
.sfp_setup_needed
= false;
982 if (status
== IXGBE_ERR_SFP_NOT_SUPPORTED
)
986 if (hw
->phy
.reset_disable
== false && hw
->phy
.ops
.reset
!= NULL
)
987 hw
->phy
.ops
.reset(hw
);
991 * Issue global reset to the MAC. Needs to be SW reset if link is up.
992 * If link reset is used when link is up, it might reset the PHY when
993 * mng is using it. If link is down or the flag to force full link
994 * reset is set, then perform link reset.
996 ctrl
= IXGBE_CTRL_LNK_RST
;
997 if (!hw
->force_full_reset
) {
998 hw
->mac
.ops
.check_link(hw
, &link_speed
, &link_up
, false);
1000 ctrl
= IXGBE_CTRL_RST
;
1003 ctrl
|= IXGBE_READ_REG(hw
, IXGBE_CTRL
);
1004 IXGBE_WRITE_REG(hw
, IXGBE_CTRL
, ctrl
);
1005 IXGBE_WRITE_FLUSH(hw
);
1007 /* Poll for reset bit to self-clear indicating reset is complete */
1008 for (i
= 0; i
< 10; i
++) {
1010 ctrl
= IXGBE_READ_REG(hw
, IXGBE_CTRL
);
1011 if (!(ctrl
& IXGBE_CTRL_RST_MASK
))
1015 if (ctrl
& IXGBE_CTRL_RST_MASK
) {
1016 status
= IXGBE_ERR_RESET_FAILED
;
1017 hw_dbg(hw
, "Reset polling failed to complete.\n");
1023 * Double resets are required for recovery from certain error
1024 * conditions. Between resets, it is necessary to stall to allow time
1025 * for any pending HW events to complete.
1027 if (hw
->mac
.flags
& IXGBE_FLAGS_DOUBLE_RESET_REQUIRED
) {
1028 hw
->mac
.flags
&= ~IXGBE_FLAGS_DOUBLE_RESET_REQUIRED
;
1033 * Store the original AUTOC/AUTOC2 values if they have not been
1034 * stored off yet. Otherwise restore the stored original
1035 * values since the reset operation sets back to defaults.
1037 autoc
= IXGBE_READ_REG(hw
, IXGBE_AUTOC
);
1038 autoc2
= IXGBE_READ_REG(hw
, IXGBE_AUTOC2
);
1039 if (hw
->mac
.orig_link_settings_stored
== false) {
1040 hw
->mac
.orig_autoc
= autoc
;
1041 hw
->mac
.orig_autoc2
= autoc2
;
1042 hw
->mac
.orig_link_settings_stored
= true;
1044 if (autoc
!= hw
->mac
.orig_autoc
)
1045 IXGBE_WRITE_REG(hw
, IXGBE_AUTOC
, (hw
->mac
.orig_autoc
|
1046 IXGBE_AUTOC_AN_RESTART
));
1048 if ((autoc2
& IXGBE_AUTOC2_UPPER_MASK
) !=
1049 (hw
->mac
.orig_autoc2
& IXGBE_AUTOC2_UPPER_MASK
)) {
1050 autoc2
&= ~IXGBE_AUTOC2_UPPER_MASK
;
1051 autoc2
|= (hw
->mac
.orig_autoc2
&
1052 IXGBE_AUTOC2_UPPER_MASK
);
1053 IXGBE_WRITE_REG(hw
, IXGBE_AUTOC2
, autoc2
);
1058 /* Store the permanent mac address */
1059 hw
->mac
.ops
.get_mac_addr(hw
, hw
->mac
.perm_addr
);
1062 * Store MAC address from RAR0, clear receive address registers, and
1063 * clear the multicast table. Also reset num_rar_entries to 128,
1064 * since we modify this value when programming the SAN MAC address.
1066 hw
->mac
.num_rar_entries
= 128;
1067 hw
->mac
.ops
.init_rx_addrs(hw
);
1069 /* Store the permanent SAN mac address */
1070 hw
->mac
.ops
.get_san_mac_addr(hw
, hw
->mac
.san_addr
);
1072 /* Add the SAN MAC address to the RAR only if it's a valid address */
1073 if (ixgbe_validate_mac_addr(hw
->mac
.san_addr
) == 0) {
1074 hw
->mac
.ops
.set_rar(hw
, hw
->mac
.num_rar_entries
- 1,
1075 hw
->mac
.san_addr
, 0, IXGBE_RAH_AV
);
1077 /* Save the SAN MAC RAR index */
1078 hw
->mac
.san_mac_rar_index
= hw
->mac
.num_rar_entries
- 1;
1080 /* Reserve the last RAR for the SAN MAC address */
1081 hw
->mac
.num_rar_entries
--;
1084 /* Store the alternative WWNN/WWPN prefix */
1085 hw
->mac
.ops
.get_wwn_prefix(hw
, &hw
->mac
.wwnn_prefix
,
1086 &hw
->mac
.wwpn_prefix
);
1093 * ixgbe_reinit_fdir_tables_82599 - Reinitialize Flow Director tables.
1094 * @hw: pointer to hardware structure
1096 s32
ixgbe_reinit_fdir_tables_82599(struct ixgbe_hw
*hw
)
1099 u32 fdirctrl
= IXGBE_READ_REG(hw
, IXGBE_FDIRCTRL
);
1100 fdirctrl
&= ~IXGBE_FDIRCTRL_INIT_DONE
;
1103 * Before starting reinitialization process,
1104 * FDIRCMD.CMD must be zero.
1106 for (i
= 0; i
< IXGBE_FDIRCMD_CMD_POLL
; i
++) {
1107 if (!(IXGBE_READ_REG(hw
, IXGBE_FDIRCMD
) &
1108 IXGBE_FDIRCMD_CMD_MASK
))
1112 if (i
>= IXGBE_FDIRCMD_CMD_POLL
) {
1113 hw_dbg(hw
, "Flow Director previous command isn't complete, "
1114 "aborting table re-initialization.\n");
1115 return IXGBE_ERR_FDIR_REINIT_FAILED
;
1118 IXGBE_WRITE_REG(hw
, IXGBE_FDIRFREE
, 0);
1119 IXGBE_WRITE_FLUSH(hw
);
1121 * 82599 adapters flow director init flow cannot be restarted,
1122 * Workaround 82599 silicon errata by performing the following steps
1123 * before re-writing the FDIRCTRL control register with the same value.
1124 * - write 1 to bit 8 of FDIRCMD register &
1125 * - write 0 to bit 8 of FDIRCMD register
1127 IXGBE_WRITE_REG(hw
, IXGBE_FDIRCMD
,
1128 (IXGBE_READ_REG(hw
, IXGBE_FDIRCMD
) |
1129 IXGBE_FDIRCMD_CLEARHT
));
1130 IXGBE_WRITE_FLUSH(hw
);
1131 IXGBE_WRITE_REG(hw
, IXGBE_FDIRCMD
,
1132 (IXGBE_READ_REG(hw
, IXGBE_FDIRCMD
) &
1133 ~IXGBE_FDIRCMD_CLEARHT
));
1134 IXGBE_WRITE_FLUSH(hw
);
1136 * Clear FDIR Hash register to clear any leftover hashes
1137 * waiting to be programmed.
1139 IXGBE_WRITE_REG(hw
, IXGBE_FDIRHASH
, 0x00);
1140 IXGBE_WRITE_FLUSH(hw
);
1142 IXGBE_WRITE_REG(hw
, IXGBE_FDIRCTRL
, fdirctrl
);
1143 IXGBE_WRITE_FLUSH(hw
);
1145 /* Poll init-done after we write FDIRCTRL register */
1146 for (i
= 0; i
< IXGBE_FDIR_INIT_DONE_POLL
; i
++) {
1147 if (IXGBE_READ_REG(hw
, IXGBE_FDIRCTRL
) &
1148 IXGBE_FDIRCTRL_INIT_DONE
)
1152 if (i
>= IXGBE_FDIR_INIT_DONE_POLL
) {
1153 hw_dbg(hw
, "Flow Director Signature poll time exceeded!\n");
1154 return IXGBE_ERR_FDIR_REINIT_FAILED
;
1157 /* Clear FDIR statistics registers (read to clear) */
1158 IXGBE_READ_REG(hw
, IXGBE_FDIRUSTAT
);
1159 IXGBE_READ_REG(hw
, IXGBE_FDIRFSTAT
);
1160 IXGBE_READ_REG(hw
, IXGBE_FDIRMATCH
);
1161 IXGBE_READ_REG(hw
, IXGBE_FDIRMISS
);
1162 IXGBE_READ_REG(hw
, IXGBE_FDIRLEN
);
1168 * ixgbe_fdir_enable_82599 - Initialize Flow Director control registers
1169 * @hw: pointer to hardware structure
1170 * @fdirctrl: value to write to flow director control register
1172 static void ixgbe_fdir_enable_82599(struct ixgbe_hw
*hw
, u32 fdirctrl
)
1176 /* Prime the keys for hashing */
1177 IXGBE_WRITE_REG(hw
, IXGBE_FDIRHKEY
, IXGBE_ATR_BUCKET_HASH_KEY
);
1178 IXGBE_WRITE_REG(hw
, IXGBE_FDIRSKEY
, IXGBE_ATR_SIGNATURE_HASH_KEY
);
1181 * Poll init-done after we write the register. Estimated times:
1182 * 10G: PBALLOC = 11b, timing is 60us
1183 * 1G: PBALLOC = 11b, timing is 600us
1184 * 100M: PBALLOC = 11b, timing is 6ms
1186 * Multiple these timings by 4 if under full Rx load
1188 * So we'll poll for IXGBE_FDIR_INIT_DONE_POLL times, sleeping for
1189 * 1 msec per poll time. If we're at line rate and drop to 100M, then
1190 * this might not finish in our poll time, but we can live with that
1193 IXGBE_WRITE_REG(hw
, IXGBE_FDIRCTRL
, fdirctrl
);
1194 IXGBE_WRITE_FLUSH(hw
);
1195 for (i
= 0; i
< IXGBE_FDIR_INIT_DONE_POLL
; i
++) {
1196 if (IXGBE_READ_REG(hw
, IXGBE_FDIRCTRL
) &
1197 IXGBE_FDIRCTRL_INIT_DONE
)
1202 if (i
>= IXGBE_FDIR_INIT_DONE_POLL
)
1203 hw_dbg(hw
, "Flow Director poll time exceeded!\n");
1207 * ixgbe_init_fdir_signature_82599 - Initialize Flow Director signature filters
1208 * @hw: pointer to hardware structure
1209 * @fdirctrl: value to write to flow director control register, initially
1210 * contains just the value of the Rx packet buffer allocation
1212 s32
ixgbe_init_fdir_signature_82599(struct ixgbe_hw
*hw
, u32 fdirctrl
)
1215 * Continue setup of fdirctrl register bits:
1216 * Move the flexible bytes to use the ethertype - shift 6 words
1217 * Set the maximum length per hash bucket to 0xA filters
1218 * Send interrupt when 64 filters are left
1220 fdirctrl
|= (0x6 << IXGBE_FDIRCTRL_FLEX_SHIFT
) |
1221 (0xA << IXGBE_FDIRCTRL_MAX_LENGTH_SHIFT
) |
1222 (4 << IXGBE_FDIRCTRL_FULL_THRESH_SHIFT
);
1224 /* write hashes and fdirctrl register, poll for completion */
1225 ixgbe_fdir_enable_82599(hw
, fdirctrl
);
1231 * ixgbe_init_fdir_perfect_82599 - Initialize Flow Director perfect filters
1232 * @hw: pointer to hardware structure
1233 * @fdirctrl: value to write to flow director control register, initially
1234 * contains just the value of the Rx packet buffer allocation
1236 s32
ixgbe_init_fdir_perfect_82599(struct ixgbe_hw
*hw
, u32 fdirctrl
)
1239 * Continue setup of fdirctrl register bits:
1240 * Turn perfect match filtering on
1241 * Report hash in RSS field of Rx wb descriptor
1242 * Initialize the drop queue
1243 * Move the flexible bytes to use the ethertype - shift 6 words
1244 * Set the maximum length per hash bucket to 0xA filters
1245 * Send interrupt when 64 (0x4 * 16) filters are left
1247 fdirctrl
|= IXGBE_FDIRCTRL_PERFECT_MATCH
|
1248 IXGBE_FDIRCTRL_REPORT_STATUS
|
1249 (IXGBE_FDIR_DROP_QUEUE
<< IXGBE_FDIRCTRL_DROP_Q_SHIFT
) |
1250 (0x6 << IXGBE_FDIRCTRL_FLEX_SHIFT
) |
1251 (0xA << IXGBE_FDIRCTRL_MAX_LENGTH_SHIFT
) |
1252 (4 << IXGBE_FDIRCTRL_FULL_THRESH_SHIFT
);
1254 /* write hashes and fdirctrl register, poll for completion */
1255 ixgbe_fdir_enable_82599(hw
, fdirctrl
);
1261 * These defines allow us to quickly generate all of the necessary instructions
1262 * in the function below by simply calling out IXGBE_COMPUTE_SIG_HASH_ITERATION
1263 * for values 0 through 15
1265 #define IXGBE_ATR_COMMON_HASH_KEY \
1266 (IXGBE_ATR_BUCKET_HASH_KEY & IXGBE_ATR_SIGNATURE_HASH_KEY)
1267 #define IXGBE_COMPUTE_SIG_HASH_ITERATION(_n) \
1270 if (IXGBE_ATR_COMMON_HASH_KEY & (0x01 << n)) \
1271 common_hash ^= lo_hash_dword >> n; \
1272 else if (IXGBE_ATR_BUCKET_HASH_KEY & (0x01 << n)) \
1273 bucket_hash ^= lo_hash_dword >> n; \
1274 else if (IXGBE_ATR_SIGNATURE_HASH_KEY & (0x01 << n)) \
1275 sig_hash ^= lo_hash_dword << (16 - n); \
1276 if (IXGBE_ATR_COMMON_HASH_KEY & (0x01 << (n + 16))) \
1277 common_hash ^= hi_hash_dword >> n; \
1278 else if (IXGBE_ATR_BUCKET_HASH_KEY & (0x01 << (n + 16))) \
1279 bucket_hash ^= hi_hash_dword >> n; \
1280 else if (IXGBE_ATR_SIGNATURE_HASH_KEY & (0x01 << (n + 16))) \
1281 sig_hash ^= hi_hash_dword << (16 - n); \
1285 * ixgbe_atr_compute_sig_hash_82599 - Compute the signature hash
1286 * @stream: input bitstream to compute the hash on
1288 * This function is almost identical to the function above but contains
1289 * several optomizations such as unwinding all of the loops, letting the
1290 * compiler work out all of the conditional ifs since the keys are static
1291 * defines, and computing two keys at once since the hashed dword stream
1292 * will be the same for both keys.
1294 u32
ixgbe_atr_compute_sig_hash_82599(union ixgbe_atr_hash_dword input
,
1295 union ixgbe_atr_hash_dword common
)
1297 u32 hi_hash_dword
, lo_hash_dword
, flow_vm_vlan
;
1298 u32 sig_hash
= 0, bucket_hash
= 0, common_hash
= 0;
1300 /* record the flow_vm_vlan bits as they are a key part to the hash */
1301 flow_vm_vlan
= IXGBE_NTOHL(input
.dword
);
1303 /* generate common hash dword */
1304 hi_hash_dword
= IXGBE_NTOHL(common
.dword
);
1306 /* low dword is word swapped version of common */
1307 lo_hash_dword
= (hi_hash_dword
>> 16) | (hi_hash_dword
<< 16);
1309 /* apply flow ID/VM pool/VLAN ID bits to hash words */
1310 hi_hash_dword
^= flow_vm_vlan
^ (flow_vm_vlan
>> 16);
1312 /* Process bits 0 and 16 */
1313 IXGBE_COMPUTE_SIG_HASH_ITERATION(0);
1316 * apply flow ID/VM pool/VLAN ID bits to lo hash dword, we had to
1317 * delay this because bit 0 of the stream should not be processed
1318 * so we do not add the vlan until after bit 0 was processed
1320 lo_hash_dword
^= flow_vm_vlan
^ (flow_vm_vlan
<< 16);
1322 /* Process remaining 30 bit of the key */
1323 IXGBE_COMPUTE_SIG_HASH_ITERATION(1);
1324 IXGBE_COMPUTE_SIG_HASH_ITERATION(2);
1325 IXGBE_COMPUTE_SIG_HASH_ITERATION(3);
1326 IXGBE_COMPUTE_SIG_HASH_ITERATION(4);
1327 IXGBE_COMPUTE_SIG_HASH_ITERATION(5);
1328 IXGBE_COMPUTE_SIG_HASH_ITERATION(6);
1329 IXGBE_COMPUTE_SIG_HASH_ITERATION(7);
1330 IXGBE_COMPUTE_SIG_HASH_ITERATION(8);
1331 IXGBE_COMPUTE_SIG_HASH_ITERATION(9);
1332 IXGBE_COMPUTE_SIG_HASH_ITERATION(10);
1333 IXGBE_COMPUTE_SIG_HASH_ITERATION(11);
1334 IXGBE_COMPUTE_SIG_HASH_ITERATION(12);
1335 IXGBE_COMPUTE_SIG_HASH_ITERATION(13);
1336 IXGBE_COMPUTE_SIG_HASH_ITERATION(14);
1337 IXGBE_COMPUTE_SIG_HASH_ITERATION(15);
1339 /* combine common_hash result with signature and bucket hashes */
1340 bucket_hash
^= common_hash
;
1341 bucket_hash
&= IXGBE_ATR_HASH_MASK
;
1343 sig_hash
^= common_hash
<< 16;
1344 sig_hash
&= IXGBE_ATR_HASH_MASK
<< 16;
1346 /* return completed signature hash */
1347 return sig_hash
^ bucket_hash
;
1351 * ixgbe_atr_add_signature_filter_82599 - Adds a signature hash filter
1352 * @hw: pointer to hardware structure
1353 * @input: unique input dword
1354 * @common: compressed common input dword
1355 * @queue: queue index to direct traffic to
1357 s32
ixgbe_fdir_add_signature_filter_82599(struct ixgbe_hw
*hw
,
1358 union ixgbe_atr_hash_dword input
,
1359 union ixgbe_atr_hash_dword common
,
1366 * Get the flow_type in order to program FDIRCMD properly
1367 * lowest 2 bits are FDIRCMD.L4TYPE, third lowest bit is FDIRCMD.IPV6
1369 switch (input
.formatted
.flow_type
) {
1370 case IXGBE_ATR_FLOW_TYPE_TCPV4
:
1371 case IXGBE_ATR_FLOW_TYPE_UDPV4
:
1372 case IXGBE_ATR_FLOW_TYPE_SCTPV4
:
1373 case IXGBE_ATR_FLOW_TYPE_TCPV6
:
1374 case IXGBE_ATR_FLOW_TYPE_UDPV6
:
1375 case IXGBE_ATR_FLOW_TYPE_SCTPV6
:
1378 hw_dbg(hw
, " Error on flow type input\n");
1379 return IXGBE_ERR_CONFIG
;
1382 /* configure FDIRCMD register */
1383 fdircmd
= IXGBE_FDIRCMD_CMD_ADD_FLOW
| IXGBE_FDIRCMD_FILTER_UPDATE
|
1384 IXGBE_FDIRCMD_LAST
| IXGBE_FDIRCMD_QUEUE_EN
;
1385 fdircmd
|= input
.formatted
.flow_type
<< IXGBE_FDIRCMD_FLOW_TYPE_SHIFT
;
1386 fdircmd
|= (u32
)queue
<< IXGBE_FDIRCMD_RX_QUEUE_SHIFT
;
1389 * The lower 32-bits of fdirhashcmd is for FDIRHASH, the upper 32-bits
1390 * is for FDIRCMD. Then do a 64-bit register write from FDIRHASH.
1392 fdirhashcmd
= (u64
)fdircmd
<< 32;
1393 fdirhashcmd
|= ixgbe_atr_compute_sig_hash_82599(input
, common
);
1394 IXGBE_WRITE_REG64(hw
, IXGBE_FDIRHASH
, fdirhashcmd
);
1396 hw_dbg(hw
, "Tx Queue=%x hash=%x\n", queue
, (u32
)fdirhashcmd
);
1401 #define IXGBE_COMPUTE_BKT_HASH_ITERATION(_n) \
1404 if (IXGBE_ATR_BUCKET_HASH_KEY & (0x01 << n)) \
1405 bucket_hash ^= lo_hash_dword >> n; \
1406 if (IXGBE_ATR_BUCKET_HASH_KEY & (0x01 << (n + 16))) \
1407 bucket_hash ^= hi_hash_dword >> n; \
1411 * ixgbe_atr_compute_perfect_hash_82599 - Compute the perfect filter hash
1412 * @atr_input: input bitstream to compute the hash on
1413 * @input_mask: mask for the input bitstream
1415 * This function serves two main purposes. First it applys the input_mask
1416 * to the atr_input resulting in a cleaned up atr_input data stream.
1417 * Secondly it computes the hash and stores it in the bkt_hash field at
1418 * the end of the input byte stream. This way it will be available for
1419 * future use without needing to recompute the hash.
1421 void ixgbe_atr_compute_perfect_hash_82599(union ixgbe_atr_input
*input
,
1422 union ixgbe_atr_input
*input_mask
)
1425 u32 hi_hash_dword
, lo_hash_dword
, flow_vm_vlan
;
1426 u32 bucket_hash
= 0;
1428 /* Apply masks to input data */
1429 input
->dword_stream
[0] &= input_mask
->dword_stream
[0];
1430 input
->dword_stream
[1] &= input_mask
->dword_stream
[1];
1431 input
->dword_stream
[2] &= input_mask
->dword_stream
[2];
1432 input
->dword_stream
[3] &= input_mask
->dword_stream
[3];
1433 input
->dword_stream
[4] &= input_mask
->dword_stream
[4];
1434 input
->dword_stream
[5] &= input_mask
->dword_stream
[5];
1435 input
->dword_stream
[6] &= input_mask
->dword_stream
[6];
1436 input
->dword_stream
[7] &= input_mask
->dword_stream
[7];
1437 input
->dword_stream
[8] &= input_mask
->dword_stream
[8];
1438 input
->dword_stream
[9] &= input_mask
->dword_stream
[9];
1439 input
->dword_stream
[10] &= input_mask
->dword_stream
[10];
1441 /* record the flow_vm_vlan bits as they are a key part to the hash */
1442 flow_vm_vlan
= IXGBE_NTOHL(input
->dword_stream
[0]);
1444 /* generate common hash dword */
1445 hi_hash_dword
= IXGBE_NTOHL(input
->dword_stream
[1] ^
1446 input
->dword_stream
[2] ^
1447 input
->dword_stream
[3] ^
1448 input
->dword_stream
[4] ^
1449 input
->dword_stream
[5] ^
1450 input
->dword_stream
[6] ^
1451 input
->dword_stream
[7] ^
1452 input
->dword_stream
[8] ^
1453 input
->dword_stream
[9] ^
1454 input
->dword_stream
[10]);
1456 /* low dword is word swapped version of common */
1457 lo_hash_dword
= (hi_hash_dword
>> 16) | (hi_hash_dword
<< 16);
1459 /* apply flow ID/VM pool/VLAN ID bits to hash words */
1460 hi_hash_dword
^= flow_vm_vlan
^ (flow_vm_vlan
>> 16);
1462 /* Process bits 0 and 16 */
1463 IXGBE_COMPUTE_BKT_HASH_ITERATION(0);
1466 * apply flow ID/VM pool/VLAN ID bits to lo hash dword, we had to
1467 * delay this because bit 0 of the stream should not be processed
1468 * so we do not add the vlan until after bit 0 was processed
1470 lo_hash_dword
^= flow_vm_vlan
^ (flow_vm_vlan
<< 16);
1472 /* Process remaining 30 bit of the key */
1473 IXGBE_COMPUTE_BKT_HASH_ITERATION(1);
1474 IXGBE_COMPUTE_BKT_HASH_ITERATION(2);
1475 IXGBE_COMPUTE_BKT_HASH_ITERATION(3);
1476 IXGBE_COMPUTE_BKT_HASH_ITERATION(4);
1477 IXGBE_COMPUTE_BKT_HASH_ITERATION(5);
1478 IXGBE_COMPUTE_BKT_HASH_ITERATION(6);
1479 IXGBE_COMPUTE_BKT_HASH_ITERATION(7);
1480 IXGBE_COMPUTE_BKT_HASH_ITERATION(8);
1481 IXGBE_COMPUTE_BKT_HASH_ITERATION(9);
1482 IXGBE_COMPUTE_BKT_HASH_ITERATION(10);
1483 IXGBE_COMPUTE_BKT_HASH_ITERATION(11);
1484 IXGBE_COMPUTE_BKT_HASH_ITERATION(12);
1485 IXGBE_COMPUTE_BKT_HASH_ITERATION(13);
1486 IXGBE_COMPUTE_BKT_HASH_ITERATION(14);
1487 IXGBE_COMPUTE_BKT_HASH_ITERATION(15);
1490 * Limit hash to 13 bits since max bucket count is 8K.
1491 * Store result at the end of the input stream.
1493 input
->formatted
.bkt_hash
= bucket_hash
& 0x1FFF;
1497 * ixgbe_get_fdirtcpm_82599 - generate a tcp port from atr_input_masks
1498 * @input_mask: mask to be bit swapped
1500 * The source and destination port masks for flow director are bit swapped
1501 * in that bit 15 effects bit 0, 14 effects 1, 13, 2 etc. In order to
1502 * generate a correctly swapped value we need to bit swap the mask and that
1503 * is what is accomplished by this function.
1505 static u32
ixgbe_get_fdirtcpm_82599(union ixgbe_atr_input
*input_mask
)
1507 u32 mask
= IXGBE_NTOHS(input_mask
->formatted
.dst_port
);
1508 mask
<<= IXGBE_FDIRTCPM_DPORTM_SHIFT
;
1509 mask
|= IXGBE_NTOHS(input_mask
->formatted
.src_port
);
1510 mask
= ((mask
& 0x55555555) << 1) | ((mask
& 0xAAAAAAAA) >> 1);
1511 mask
= ((mask
& 0x33333333) << 2) | ((mask
& 0xCCCCCCCC) >> 2);
1512 mask
= ((mask
& 0x0F0F0F0F) << 4) | ((mask
& 0xF0F0F0F0) >> 4);
1513 return ((mask
& 0x00FF00FF) << 8) | ((mask
& 0xFF00FF00) >> 8);
1517 * These two macros are meant to address the fact that we have registers
1518 * that are either all or in part big-endian. As a result on big-endian
1519 * systems we will end up byte swapping the value to little-endian before
1520 * it is byte swapped again and written to the hardware in the original
1521 * big-endian format.
1523 #define IXGBE_STORE_AS_BE32(_value) \
1524 (((u32)(_value) >> 24) | (((u32)(_value) & 0x00FF0000) >> 8) | \
1525 (((u32)(_value) & 0x0000FF00) << 8) | ((u32)(_value) << 24))
1527 #define IXGBE_WRITE_REG_BE32(a, reg, value) \
1528 IXGBE_WRITE_REG((a), (reg), IXGBE_STORE_AS_BE32(IXGBE_NTOHL(value)))
1530 #define IXGBE_STORE_AS_BE16(_value) \
1531 IXGBE_NTOHS(((u16)(_value) >> 8) | ((u16)(_value) << 8))
1533 s32
ixgbe_fdir_set_input_mask_82599(struct ixgbe_hw
*hw
,
1534 union ixgbe_atr_input
*input_mask
)
1536 /* mask IPv6 since it is currently not supported */
1537 u32 fdirm
= IXGBE_FDIRM_DIPv6
;
1541 * Program the relevant mask registers. If src/dst_port or src/dst_addr
1542 * are zero, then assume a full mask for that field. Also assume that
1543 * a VLAN of 0 is unspecified, so mask that out as well. L4type
1544 * cannot be masked out in this implementation.
1546 * This also assumes IPv4 only. IPv6 masking isn't supported at this
1550 /* verify bucket hash is cleared on hash generation */
1551 if (input_mask
->formatted
.bkt_hash
)
1552 hw_dbg(hw
, " bucket hash should always be 0 in mask\n");
1554 /* Program FDIRM and verify partial masks */
1555 switch (input_mask
->formatted
.vm_pool
& 0x7F) {
1557 fdirm
|= IXGBE_FDIRM_POOL
;
1561 hw_dbg(hw
, " Error on vm pool mask\n");
1562 return IXGBE_ERR_CONFIG
;
1565 switch (input_mask
->formatted
.flow_type
& IXGBE_ATR_L4TYPE_MASK
) {
1567 fdirm
|= IXGBE_FDIRM_L4P
;
1568 if (input_mask
->formatted
.dst_port
||
1569 input_mask
->formatted
.src_port
) {
1570 hw_dbg(hw
, " Error on src/dst port mask\n");
1571 return IXGBE_ERR_CONFIG
;
1573 case IXGBE_ATR_L4TYPE_MASK
:
1576 hw_dbg(hw
, " Error on flow type mask\n");
1577 return IXGBE_ERR_CONFIG
;
1580 switch (IXGBE_NTOHS(input_mask
->formatted
.vlan_id
) & 0xEFFF) {
1582 /* mask VLAN ID, fall through to mask VLAN priority */
1583 fdirm
|= IXGBE_FDIRM_VLANID
;
1585 /* mask VLAN priority */
1586 fdirm
|= IXGBE_FDIRM_VLANP
;
1589 /* mask VLAN ID only, fall through */
1590 fdirm
|= IXGBE_FDIRM_VLANID
;
1592 /* no VLAN fields masked */
1595 hw_dbg(hw
, " Error on VLAN mask\n");
1596 return IXGBE_ERR_CONFIG
;
1599 switch (input_mask
->formatted
.flex_bytes
& 0xFFFF) {
1601 /* Mask Flex Bytes, fall through */
1602 fdirm
|= IXGBE_FDIRM_FLEX
;
1606 hw_dbg(hw
, " Error on flexible byte mask\n");
1607 return IXGBE_ERR_CONFIG
;
1610 /* Now mask VM pool and destination IPv6 - bits 5 and 2 */
1611 IXGBE_WRITE_REG(hw
, IXGBE_FDIRM
, fdirm
);
1613 /* store the TCP/UDP port masks, bit reversed from port layout */
1614 fdirtcpm
= ixgbe_get_fdirtcpm_82599(input_mask
);
1616 /* write both the same so that UDP and TCP use the same mask */
1617 IXGBE_WRITE_REG(hw
, IXGBE_FDIRTCPM
, ~fdirtcpm
);
1618 IXGBE_WRITE_REG(hw
, IXGBE_FDIRUDPM
, ~fdirtcpm
);
1620 /* store source and destination IP masks (big-enian) */
1621 IXGBE_WRITE_REG_BE32(hw
, IXGBE_FDIRSIP4M
,
1622 ~input_mask
->formatted
.src_ip
[0]);
1623 IXGBE_WRITE_REG_BE32(hw
, IXGBE_FDIRDIP4M
,
1624 ~input_mask
->formatted
.dst_ip
[0]);
1629 s32
ixgbe_fdir_write_perfect_filter_82599(struct ixgbe_hw
*hw
,
1630 union ixgbe_atr_input
*input
,
1631 u16 soft_id
, u8 queue
)
1633 u32 fdirport
, fdirvlan
, fdirhash
, fdircmd
;
1635 /* currently IPv6 is not supported, must be programmed with 0 */
1636 IXGBE_WRITE_REG_BE32(hw
, IXGBE_FDIRSIPv6(0),
1637 input
->formatted
.src_ip
[0]);
1638 IXGBE_WRITE_REG_BE32(hw
, IXGBE_FDIRSIPv6(1),
1639 input
->formatted
.src_ip
[1]);
1640 IXGBE_WRITE_REG_BE32(hw
, IXGBE_FDIRSIPv6(2),
1641 input
->formatted
.src_ip
[2]);
1643 /* record the source address (big-endian) */
1644 IXGBE_WRITE_REG_BE32(hw
, IXGBE_FDIRIPSA
, input
->formatted
.src_ip
[0]);
1646 /* record the first 32 bits of the destination address (big-endian) */
1647 IXGBE_WRITE_REG_BE32(hw
, IXGBE_FDIRIPDA
, input
->formatted
.dst_ip
[0]);
1649 /* record source and destination port (little-endian)*/
1650 fdirport
= IXGBE_NTOHS(input
->formatted
.dst_port
);
1651 fdirport
<<= IXGBE_FDIRPORT_DESTINATION_SHIFT
;
1652 fdirport
|= IXGBE_NTOHS(input
->formatted
.src_port
);
1653 IXGBE_WRITE_REG(hw
, IXGBE_FDIRPORT
, fdirport
);
1655 /* record vlan (little-endian) and flex_bytes(big-endian) */
1656 fdirvlan
= IXGBE_STORE_AS_BE16(input
->formatted
.flex_bytes
);
1657 fdirvlan
<<= IXGBE_FDIRVLAN_FLEX_SHIFT
;
1658 fdirvlan
|= IXGBE_NTOHS(input
->formatted
.vlan_id
);
1659 IXGBE_WRITE_REG(hw
, IXGBE_FDIRVLAN
, fdirvlan
);
1661 /* configure FDIRHASH register */
1662 fdirhash
= input
->formatted
.bkt_hash
;
1663 fdirhash
|= soft_id
<< IXGBE_FDIRHASH_SIG_SW_INDEX_SHIFT
;
1664 IXGBE_WRITE_REG(hw
, IXGBE_FDIRHASH
, fdirhash
);
1667 * flush all previous writes to make certain registers are
1668 * programmed prior to issuing the command
1670 IXGBE_WRITE_FLUSH(hw
);
1672 /* configure FDIRCMD register */
1673 fdircmd
= IXGBE_FDIRCMD_CMD_ADD_FLOW
| IXGBE_FDIRCMD_FILTER_UPDATE
|
1674 IXGBE_FDIRCMD_LAST
| IXGBE_FDIRCMD_QUEUE_EN
;
1675 if (queue
== IXGBE_FDIR_DROP_QUEUE
)
1676 fdircmd
|= IXGBE_FDIRCMD_DROP
;
1677 fdircmd
|= input
->formatted
.flow_type
<< IXGBE_FDIRCMD_FLOW_TYPE_SHIFT
;
1678 fdircmd
|= (u32
)queue
<< IXGBE_FDIRCMD_RX_QUEUE_SHIFT
;
1679 fdircmd
|= (u32
)input
->formatted
.vm_pool
<< IXGBE_FDIRCMD_VT_POOL_SHIFT
;
1681 IXGBE_WRITE_REG(hw
, IXGBE_FDIRCMD
, fdircmd
);
1686 s32
ixgbe_fdir_erase_perfect_filter_82599(struct ixgbe_hw
*hw
,
1687 union ixgbe_atr_input
*input
,
1695 /* configure FDIRHASH register */
1696 fdirhash
= input
->formatted
.bkt_hash
;
1697 fdirhash
|= soft_id
<< IXGBE_FDIRHASH_SIG_SW_INDEX_SHIFT
;
1698 IXGBE_WRITE_REG(hw
, IXGBE_FDIRHASH
, fdirhash
);
1700 /* flush hash to HW */
1701 IXGBE_WRITE_FLUSH(hw
);
1703 /* Query if filter is present */
1704 IXGBE_WRITE_REG(hw
, IXGBE_FDIRCMD
, IXGBE_FDIRCMD_CMD_QUERY_REM_FILT
);
1706 for (retry_count
= 10; retry_count
; retry_count
--) {
1707 /* allow 10us for query to process */
1709 /* verify query completed successfully */
1710 fdircmd
= IXGBE_READ_REG(hw
, IXGBE_FDIRCMD
);
1711 if (!(fdircmd
& IXGBE_FDIRCMD_CMD_MASK
))
1716 err
= IXGBE_ERR_FDIR_REINIT_FAILED
;
1718 /* if filter exists in hardware then remove it */
1719 if (fdircmd
& IXGBE_FDIRCMD_FILTER_VALID
) {
1720 IXGBE_WRITE_REG(hw
, IXGBE_FDIRHASH
, fdirhash
);
1721 IXGBE_WRITE_FLUSH(hw
);
1722 IXGBE_WRITE_REG(hw
, IXGBE_FDIRCMD
,
1723 IXGBE_FDIRCMD_CMD_REMOVE_FLOW
);
1730 * ixgbe_fdir_add_perfect_filter_82599 - Adds a perfect filter
1731 * @hw: pointer to hardware structure
1732 * @input: input bitstream
1733 * @input_mask: mask for the input bitstream
1734 * @soft_id: software index for the filters
1735 * @queue: queue index to direct traffic to
1737 * Note that the caller to this function must lock before calling, since the
1738 * hardware writes must be protected from one another.
1740 s32
ixgbe_fdir_add_perfect_filter_82599(struct ixgbe_hw
*hw
,
1741 union ixgbe_atr_input
*input
,
1742 union ixgbe_atr_input
*input_mask
,
1743 u16 soft_id
, u8 queue
)
1745 s32 err
= IXGBE_ERR_CONFIG
;
1748 * Check flow_type formatting, and bail out before we touch the hardware
1749 * if there's a configuration issue
1751 switch (input
->formatted
.flow_type
) {
1752 case IXGBE_ATR_FLOW_TYPE_IPV4
:
1753 input_mask
->formatted
.flow_type
= IXGBE_ATR_L4TYPE_IPV6_MASK
;
1754 if (input
->formatted
.dst_port
|| input
->formatted
.src_port
) {
1755 hw_dbg(hw
, " Error on src/dst port\n");
1756 return IXGBE_ERR_CONFIG
;
1759 case IXGBE_ATR_FLOW_TYPE_SCTPV4
:
1760 if (input
->formatted
.dst_port
|| input
->formatted
.src_port
) {
1761 hw_dbg(hw
, " Error on src/dst port\n");
1762 return IXGBE_ERR_CONFIG
;
1764 case IXGBE_ATR_FLOW_TYPE_TCPV4
:
1765 case IXGBE_ATR_FLOW_TYPE_UDPV4
:
1766 input_mask
->formatted
.flow_type
= IXGBE_ATR_L4TYPE_IPV6_MASK
|
1767 IXGBE_ATR_L4TYPE_MASK
;
1770 hw_dbg(hw
, " Error on flow type input\n");
1774 /* program input mask into the HW */
1775 err
= ixgbe_fdir_set_input_mask_82599(hw
, input_mask
);
1779 /* apply mask and compute/store hash */
1780 ixgbe_atr_compute_perfect_hash_82599(input
, input_mask
);
1782 /* program filters to filter memory */
1783 return ixgbe_fdir_write_perfect_filter_82599(hw
, input
,
1788 * ixgbe_read_analog_reg8_82599 - Reads 8 bit Omer analog register
1789 * @hw: pointer to hardware structure
1790 * @reg: analog register to read
1793 * Performs read operation to Omer analog register specified.
1795 s32
ixgbe_read_analog_reg8_82599(struct ixgbe_hw
*hw
, u32 reg
, u8
*val
)
1799 IXGBE_WRITE_REG(hw
, IXGBE_CORECTL
, IXGBE_CORECTL_WRITE_CMD
|
1801 IXGBE_WRITE_FLUSH(hw
);
1803 core_ctl
= IXGBE_READ_REG(hw
, IXGBE_CORECTL
);
1804 *val
= (u8
)core_ctl
;
1810 * ixgbe_write_analog_reg8_82599 - Writes 8 bit Omer analog register
1811 * @hw: pointer to hardware structure
1812 * @reg: atlas register to write
1813 * @val: value to write
1815 * Performs write operation to Omer analog register specified.
1817 s32
ixgbe_write_analog_reg8_82599(struct ixgbe_hw
*hw
, u32 reg
, u8 val
)
1821 core_ctl
= (reg
<< 8) | val
;
1822 IXGBE_WRITE_REG(hw
, IXGBE_CORECTL
, core_ctl
);
1823 IXGBE_WRITE_FLUSH(hw
);
1830 * ixgbe_start_hw_82599 - Prepare hardware for Tx/Rx
1831 * @hw: pointer to hardware structure
1833 * Starts the hardware using the generic start_hw function
1834 * and the generation start_hw function.
1835 * Then performs revision-specific operations, if any.
1837 s32
ixgbe_start_hw_82599(struct ixgbe_hw
*hw
)
1841 ret_val
= ixgbe_start_hw_generic(hw
);
1845 ret_val
= ixgbe_start_hw_gen2(hw
);
1849 /* We need to run link autotry after the driver loads */
1850 hw
->mac
.autotry_restart
= true;
1853 ret_val
= ixgbe_verify_fw_version_82599(hw
);
1859 * ixgbe_identify_phy_82599 - Get physical layer module
1860 * @hw: pointer to hardware structure
1862 * Determines the physical layer module found on the current adapter.
1863 * If PHY already detected, maintains current PHY type in hw struct,
1864 * otherwise executes the PHY detection routine.
1866 s32
ixgbe_identify_phy_82599(struct ixgbe_hw
*hw
)
1868 s32 status
= IXGBE_ERR_PHY_ADDR_INVALID
;
1870 /* Detect PHY if not unknown - returns success if already detected. */
1871 status
= ixgbe_identify_phy_generic(hw
);
1873 /* 82599 10GBASE-T requires an external PHY */
1874 if (hw
->mac
.ops
.get_media_type(hw
) == ixgbe_media_type_copper
)
1877 status
= ixgbe_identify_module_generic(hw
);
1880 /* Set PHY type none if no PHY detected */
1881 if (hw
->phy
.type
== ixgbe_phy_unknown
) {
1882 hw
->phy
.type
= ixgbe_phy_none
;
1886 /* Return error if SFP module has been detected but is not supported */
1887 if (hw
->phy
.type
== ixgbe_phy_sfp_unsupported
)
1888 status
= IXGBE_ERR_SFP_NOT_SUPPORTED
;
1895 * ixgbe_get_supported_physical_layer_82599 - Returns physical layer type
1896 * @hw: pointer to hardware structure
1898 * Determines physical layer capabilities of the current configuration.
1900 u32
ixgbe_get_supported_physical_layer_82599(struct ixgbe_hw
*hw
)
1902 u32 physical_layer
= IXGBE_PHYSICAL_LAYER_UNKNOWN
;
1903 u32 autoc
= IXGBE_READ_REG(hw
, IXGBE_AUTOC
);
1904 u32 autoc2
= IXGBE_READ_REG(hw
, IXGBE_AUTOC2
);
1905 u32 pma_pmd_10g_serial
= autoc2
& IXGBE_AUTOC2_10G_SERIAL_PMA_PMD_MASK
;
1906 u32 pma_pmd_10g_parallel
= autoc
& IXGBE_AUTOC_10G_PMA_PMD_MASK
;
1907 u32 pma_pmd_1g
= autoc
& IXGBE_AUTOC_1G_PMA_PMD_MASK
;
1908 u16 ext_ability
= 0;
1909 u8 comp_codes_10g
= 0;
1910 u8 comp_codes_1g
= 0;
1912 hw
->phy
.ops
.identify(hw
);
1914 switch (hw
->phy
.type
) {
1916 case ixgbe_phy_cu_unknown
:
1917 hw
->phy
.ops
.read_reg(hw
, IXGBE_MDIO_PHY_EXT_ABILITY
,
1918 IXGBE_MDIO_PMA_PMD_DEV_TYPE
, &ext_ability
);
1919 if (ext_ability
& IXGBE_MDIO_PHY_10GBASET_ABILITY
)
1920 physical_layer
|= IXGBE_PHYSICAL_LAYER_10GBASE_T
;
1921 if (ext_ability
& IXGBE_MDIO_PHY_1000BASET_ABILITY
)
1922 physical_layer
|= IXGBE_PHYSICAL_LAYER_1000BASE_T
;
1923 if (ext_ability
& IXGBE_MDIO_PHY_100BASETX_ABILITY
)
1924 physical_layer
|= IXGBE_PHYSICAL_LAYER_100BASE_TX
;
1930 switch (autoc
& IXGBE_AUTOC_LMS_MASK
) {
1931 case IXGBE_AUTOC_LMS_1G_AN
:
1932 case IXGBE_AUTOC_LMS_1G_LINK_NO_AN
:
1933 if (pma_pmd_1g
== IXGBE_AUTOC_1G_KX_BX
) {
1934 physical_layer
= IXGBE_PHYSICAL_LAYER_1000BASE_KX
|
1935 IXGBE_PHYSICAL_LAYER_1000BASE_BX
;
1938 /* SFI mode so read SFP module */
1941 case IXGBE_AUTOC_LMS_10G_LINK_NO_AN
:
1942 if (pma_pmd_10g_parallel
== IXGBE_AUTOC_10G_CX4
)
1943 physical_layer
= IXGBE_PHYSICAL_LAYER_10GBASE_CX4
;
1944 else if (pma_pmd_10g_parallel
== IXGBE_AUTOC_10G_KX4
)
1945 physical_layer
= IXGBE_PHYSICAL_LAYER_10GBASE_KX4
;
1946 else if (pma_pmd_10g_parallel
== IXGBE_AUTOC_10G_XAUI
)
1947 physical_layer
= IXGBE_PHYSICAL_LAYER_10GBASE_XAUI
;
1950 case IXGBE_AUTOC_LMS_10G_SERIAL
:
1951 if (pma_pmd_10g_serial
== IXGBE_AUTOC2_10G_KR
) {
1952 physical_layer
= IXGBE_PHYSICAL_LAYER_10GBASE_KR
;
1954 } else if (pma_pmd_10g_serial
== IXGBE_AUTOC2_10G_SFI
)
1957 case IXGBE_AUTOC_LMS_KX4_KX_KR
:
1958 case IXGBE_AUTOC_LMS_KX4_KX_KR_1G_AN
:
1959 if (autoc
& IXGBE_AUTOC_KX_SUPP
)
1960 physical_layer
|= IXGBE_PHYSICAL_LAYER_1000BASE_KX
;
1961 if (autoc
& IXGBE_AUTOC_KX4_SUPP
)
1962 physical_layer
|= IXGBE_PHYSICAL_LAYER_10GBASE_KX4
;
1963 if (autoc
& IXGBE_AUTOC_KR_SUPP
)
1964 physical_layer
|= IXGBE_PHYSICAL_LAYER_10GBASE_KR
;
1973 /* SFP check must be done last since DA modules are sometimes used to
1974 * test KR mode - we need to id KR mode correctly before SFP module.
1975 * Call identify_sfp because the pluggable module may have changed */
1976 hw
->phy
.ops
.identify_sfp(hw
);
1977 if (hw
->phy
.sfp_type
== ixgbe_sfp_type_not_present
)
1980 switch (hw
->phy
.type
) {
1981 case ixgbe_phy_sfp_passive_tyco
:
1982 case ixgbe_phy_sfp_passive_unknown
:
1983 physical_layer
= IXGBE_PHYSICAL_LAYER_SFP_PLUS_CU
;
1985 case ixgbe_phy_sfp_ftl_active
:
1986 case ixgbe_phy_sfp_active_unknown
:
1987 physical_layer
= IXGBE_PHYSICAL_LAYER_SFP_ACTIVE_DA
;
1989 case ixgbe_phy_sfp_avago
:
1990 case ixgbe_phy_sfp_ftl
:
1991 case ixgbe_phy_sfp_intel
:
1992 case ixgbe_phy_sfp_unknown
:
1993 hw
->phy
.ops
.read_i2c_eeprom(hw
,
1994 IXGBE_SFF_1GBE_COMP_CODES
, &comp_codes_1g
);
1995 hw
->phy
.ops
.read_i2c_eeprom(hw
,
1996 IXGBE_SFF_10GBE_COMP_CODES
, &comp_codes_10g
);
1997 if (comp_codes_10g
& IXGBE_SFF_10GBASESR_CAPABLE
)
1998 physical_layer
= IXGBE_PHYSICAL_LAYER_10GBASE_SR
;
1999 else if (comp_codes_10g
& IXGBE_SFF_10GBASELR_CAPABLE
)
2000 physical_layer
= IXGBE_PHYSICAL_LAYER_10GBASE_LR
;
2001 else if (comp_codes_1g
& IXGBE_SFF_1GBASET_CAPABLE
)
2002 physical_layer
= IXGBE_PHYSICAL_LAYER_1000BASE_T
;
2003 else if (comp_codes_1g
& IXGBE_SFF_1GBASESX_CAPABLE
)
2004 physical_layer
= IXGBE_PHYSICAL_LAYER_1000BASE_SX
;
2011 return physical_layer
;
2015 * ixgbe_enable_rx_dma_82599 - Enable the Rx DMA unit on 82599
2016 * @hw: pointer to hardware structure
2017 * @regval: register value to write to RXCTRL
2019 * Enables the Rx DMA unit for 82599
2021 s32
ixgbe_enable_rx_dma_82599(struct ixgbe_hw
*hw
, u32 regval
)
2025 * Workaround for 82599 silicon errata when enabling the Rx datapath.
2026 * If traffic is incoming before we enable the Rx unit, it could hang
2027 * the Rx DMA unit. Therefore, make sure the security engine is
2028 * completely disabled prior to enabling the Rx unit.
2031 hw
->mac
.ops
.disable_sec_rx_path(hw
);
2033 IXGBE_WRITE_REG(hw
, IXGBE_RXCTRL
, regval
);
2035 hw
->mac
.ops
.enable_sec_rx_path(hw
);
2041 * ixgbe_verify_fw_version_82599 - verify fw version for 82599
2042 * @hw: pointer to hardware structure
2044 * Verifies that installed the firmware version is 0.6 or higher
2045 * for SFI devices. All 82599 SFI devices should have version 0.6 or higher.
2047 * Returns IXGBE_ERR_EEPROM_VERSION if the FW is not present or
2048 * if the FW version is not supported.
2050 static s32
ixgbe_verify_fw_version_82599(struct ixgbe_hw
*hw
)
2052 s32 status
= IXGBE_ERR_EEPROM_VERSION
;
2053 u16 fw_offset
, fw_ptp_cfg_offset
;
2056 /* firmware check is only necessary for SFI devices */
2057 if (hw
->phy
.media_type
!= ixgbe_media_type_fiber
) {
2059 goto fw_version_out
;
2062 /* get the offset to the Firmware Module block */
2063 hw
->eeprom
.ops
.read(hw
, IXGBE_FW_PTR
, &fw_offset
);
2065 if ((fw_offset
== 0) || (fw_offset
== 0xFFFF))
2066 goto fw_version_out
;
2068 /* get the offset to the Pass Through Patch Configuration block */
2069 hw
->eeprom
.ops
.read(hw
, (fw_offset
+
2070 IXGBE_FW_PASSTHROUGH_PATCH_CONFIG_PTR
),
2071 &fw_ptp_cfg_offset
);
2073 if ((fw_ptp_cfg_offset
== 0) || (fw_ptp_cfg_offset
== 0xFFFF))
2074 goto fw_version_out
;
2076 /* get the firmware version */
2077 hw
->eeprom
.ops
.read(hw
, (fw_ptp_cfg_offset
+
2078 IXGBE_FW_PATCH_VERSION_4
), &fw_version
);
2080 if (fw_version
> 0x5)
2088 * ixgbe_verify_lesm_fw_enabled_82599 - Checks LESM FW module state.
2089 * @hw: pointer to hardware structure
2091 * Returns true if the LESM FW module is present and enabled. Otherwise
2092 * returns false. Smart Speed must be disabled if LESM FW module is enabled.
2094 bool ixgbe_verify_lesm_fw_enabled_82599(struct ixgbe_hw
*hw
)
2096 bool lesm_enabled
= false;
2097 u16 fw_offset
, fw_lesm_param_offset
, fw_lesm_state
;
2100 /* get the offset to the Firmware Module block */
2101 status
= hw
->eeprom
.ops
.read(hw
, IXGBE_FW_PTR
, &fw_offset
);
2103 if ((status
!= 0) ||
2104 (fw_offset
== 0) || (fw_offset
== 0xFFFF))
2107 /* get the offset to the LESM Parameters block */
2108 status
= hw
->eeprom
.ops
.read(hw
, (fw_offset
+
2109 IXGBE_FW_LESM_PARAMETERS_PTR
),
2110 &fw_lesm_param_offset
);
2112 if ((status
!= 0) ||
2113 (fw_lesm_param_offset
== 0) || (fw_lesm_param_offset
== 0xFFFF))
2116 /* get the lesm state word */
2117 status
= hw
->eeprom
.ops
.read(hw
, (fw_lesm_param_offset
+
2118 IXGBE_FW_LESM_STATE_1
),
2121 if ((status
== 0) &&
2122 (fw_lesm_state
& IXGBE_FW_LESM_STATE_ENABLED
))
2123 lesm_enabled
= true;
2126 return lesm_enabled
;
2130 * ixgbe_read_eeprom_buffer_82599 - Read EEPROM word(s) using
2131 * fastest available method
2133 * @hw: pointer to hardware structure
2134 * @offset: offset of word in EEPROM to read
2135 * @words: number of words
2136 * @data: word(s) read from the EEPROM
2138 * Retrieves 16 bit word(s) read from EEPROM
2140 static s32
ixgbe_read_eeprom_buffer_82599(struct ixgbe_hw
*hw
, u16 offset
,
2141 u16 words
, u16
*data
)
2143 struct ixgbe_eeprom_info
*eeprom
= &hw
->eeprom
;
2144 s32 ret_val
= IXGBE_ERR_CONFIG
;
2147 * If EEPROM is detected and can be addressed using 14 bits,
2148 * use EERD otherwise use bit bang
2150 if ((eeprom
->type
== ixgbe_eeprom_spi
) &&
2151 (offset
+ (words
- 1) <= IXGBE_EERD_MAX_ADDR
))
2152 ret_val
= ixgbe_read_eerd_buffer_generic(hw
, offset
, words
,
2155 ret_val
= ixgbe_read_eeprom_buffer_bit_bang_generic(hw
, offset
,
2163 * ixgbe_read_eeprom_82599 - Read EEPROM word using
2164 * fastest available method
2166 * @hw: pointer to hardware structure
2167 * @offset: offset of word in the EEPROM to read
2168 * @data: word read from the EEPROM
2170 * Reads a 16 bit word from the EEPROM
2172 static s32
ixgbe_read_eeprom_82599(struct ixgbe_hw
*hw
,
2173 u16 offset
, u16
*data
)
2175 struct ixgbe_eeprom_info
*eeprom
= &hw
->eeprom
;
2176 s32 ret_val
= IXGBE_ERR_CONFIG
;
2179 * If EEPROM is detected and can be addressed using 14 bits,
2180 * use EERD otherwise use bit bang
2182 if ((eeprom
->type
== ixgbe_eeprom_spi
) &&
2183 (offset
<= IXGBE_EERD_MAX_ADDR
))
2184 ret_val
= ixgbe_read_eerd_generic(hw
, offset
, data
);
2186 ret_val
= ixgbe_read_eeprom_bit_bang_generic(hw
, offset
, data
);
2192 * ixgbe_read_i2c_byte_82599 - Reads 8 bit word over I2C
2193 * @hw: pointer to hardware structure
2194 * @byte_offset: byte offset to read
2197 * Performs byte read operation to SFP module's EEPROM over I2C interface at
2198 * a specified device address.
2200 static s32
ixgbe_read_i2c_byte_82599(struct ixgbe_hw
*hw
, u8 byte_offset
,
2201 u8 dev_addr
, u8
*data
)
2207 if (hw
->phy
.qsfp_shared_i2c_bus
== TRUE
) {
2208 /* Acquire I2C bus ownership. */
2209 esdp
= IXGBE_READ_REG(hw
, IXGBE_ESDP
);
2210 esdp
|= IXGBE_ESDP_SDP0
;
2211 IXGBE_WRITE_REG(hw
, IXGBE_ESDP
, esdp
);
2212 IXGBE_WRITE_FLUSH(hw
);
2215 esdp
= IXGBE_READ_REG(hw
, IXGBE_ESDP
);
2216 if (esdp
& IXGBE_ESDP_SDP1
)
2224 hw_dbg(hw
, "Driver can't access resource,"
2225 " acquiring I2C bus timeout.\n");
2226 status
= IXGBE_ERR_I2C
;
2227 goto release_i2c_access
;
2231 status
= ixgbe_read_i2c_byte_generic(hw
, byte_offset
, dev_addr
, data
);
2235 if (hw
->phy
.qsfp_shared_i2c_bus
== TRUE
) {
2236 /* Release I2C bus ownership. */
2237 esdp
= IXGBE_READ_REG(hw
, IXGBE_ESDP
);
2238 esdp
&= ~IXGBE_ESDP_SDP0
;
2239 IXGBE_WRITE_REG(hw
, IXGBE_ESDP
, esdp
);
2240 IXGBE_WRITE_FLUSH(hw
);
2247 * ixgbe_write_i2c_byte_82599 - Writes 8 bit word over I2C
2248 * @hw: pointer to hardware structure
2249 * @byte_offset: byte offset to write
2250 * @data: value to write
2252 * Performs byte write operation to SFP module's EEPROM over I2C interface at
2253 * a specified device address.
2255 static s32
ixgbe_write_i2c_byte_82599(struct ixgbe_hw
*hw
, u8 byte_offset
,
2256 u8 dev_addr
, u8 data
)
2262 if (hw
->phy
.qsfp_shared_i2c_bus
== TRUE
) {
2263 /* Acquire I2C bus ownership. */
2264 esdp
= IXGBE_READ_REG(hw
, IXGBE_ESDP
);
2265 esdp
|= IXGBE_ESDP_SDP0
;
2266 IXGBE_WRITE_REG(hw
, IXGBE_ESDP
, esdp
);
2267 IXGBE_WRITE_FLUSH(hw
);
2270 esdp
= IXGBE_READ_REG(hw
, IXGBE_ESDP
);
2271 if (esdp
& IXGBE_ESDP_SDP1
)
2279 hw_dbg(hw
, "Driver can't access resource,"
2280 " acquiring I2C bus timeout.\n");
2281 status
= IXGBE_ERR_I2C
;
2282 goto release_i2c_access
;
2286 status
= ixgbe_write_i2c_byte_generic(hw
, byte_offset
, dev_addr
, data
);
2290 if (hw
->phy
.qsfp_shared_i2c_bus
== TRUE
) {
2291 /* Release I2C bus ownership. */
2292 esdp
= IXGBE_READ_REG(hw
, IXGBE_ESDP
);
2293 esdp
&= ~IXGBE_ESDP_SDP0
;
2294 IXGBE_WRITE_REG(hw
, IXGBE_ESDP
, esdp
);
2295 IXGBE_WRITE_FLUSH(hw
);