1 /*******************************************************************************
3 Copyright (c) 2013 - 2014, Intel Corporation
6 Redistribution and use in source and binary forms, with or without
7 modification, are permitted provided that the following conditions are met:
9 1. Redistributions of source code must retain the above copyright notice,
10 this list of conditions and the following disclaimer.
12 2. Redistributions in binary form must reproduce the above copyright
13 notice, this list of conditions and the following disclaimer in the
14 documentation and/or other materials provided with the distribution.
16 3. Neither the name of the Intel Corporation nor the names of its
17 contributors may be used to endorse or promote products derived from
18 this software without specific prior written permission.
20 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23 ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
24 LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
25 CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
26 SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
27 INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
28 CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
29 ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
30 POSSIBILITY OF SUCH DAMAGE.
32 ***************************************************************************/
34 #include "i40e_diag.h"
35 #include "i40e_prototype.h"
38 * i40e_diag_set_loopback
39 * @hw: pointer to the hw struct
40 * @mode: loopback mode
42 * Set chosen loopback mode
44 enum i40e_status_code i40e_diag_set_loopback(struct i40e_hw *hw,
45 enum i40e_lb_mode mode)
47 enum i40e_status_code ret_code = I40E_SUCCESS;
49 if (i40e_aq_set_lb_modes(hw, mode, NULL))
50 ret_code = I40E_ERR_DIAG_TEST_FAILED;
56 * i40e_diag_reg_pattern_test
57 * @hw: pointer to the hw struct
58 * @reg: reg to be tested
59 * @mask: bits to be touched
61 static enum i40e_status_code i40e_diag_reg_pattern_test(struct i40e_hw *hw,
64 const u32 patterns[] = {0x5A5A5A5A, 0xA5A5A5A5, 0x00000000, 0xFFFFFFFF};
65 u32 pat, val, orig_val;
68 orig_val = rd32(hw, reg);
69 for (i = 0; i < ARRAY_SIZE(patterns); i++) {
71 wr32(hw, reg, (pat & mask));
73 if ((val & mask) != (pat & mask)) {
75 i40e_debug(hw, I40E_DEBUG_DIAG,
76 "%s: reg pattern test failed - reg 0x%08x pat 0x%08x val 0x%08x\n",
77 __func__, reg, pat, val);
79 return I40E_ERR_DIAG_TEST_FAILED;
83 wr32(hw, reg, orig_val);
85 if (val != orig_val) {
87 i40e_debug(hw, I40E_DEBUG_DIAG,
88 "%s: reg restore test failed - reg 0x%08x orig_val 0x%08x val 0x%08x\n",
89 __func__, reg, orig_val, val);
91 return I40E_ERR_DIAG_TEST_FAILED;
97 struct i40e_diag_reg_test_info i40e_reg_list[] = {
98 /* offset mask elements stride */
99 {I40E_QTX_CTL(0), 0x0000FFBF, 1, I40E_QTX_CTL(1) - I40E_QTX_CTL(0)},
100 {I40E_PFINT_ITR0(0), 0x00000FFF, 3, I40E_PFINT_ITR0(1) - I40E_PFINT_ITR0(0)},
101 {I40E_PFINT_ITRN(0, 0), 0x00000FFF, 1, I40E_PFINT_ITRN(0, 1) - I40E_PFINT_ITRN(0, 0)},
102 {I40E_PFINT_ITRN(1, 0), 0x00000FFF, 1, I40E_PFINT_ITRN(1, 1) - I40E_PFINT_ITRN(1, 0)},
103 {I40E_PFINT_ITRN(2, 0), 0x00000FFF, 1, I40E_PFINT_ITRN(2, 1) - I40E_PFINT_ITRN(2, 0)},
104 {I40E_PFINT_STAT_CTL0, 0x0000000C, 1, 0},
105 {I40E_PFINT_LNKLST0, 0x00001FFF, 1, 0},
106 {I40E_PFINT_LNKLSTN(0), 0x000007FF, 1, I40E_PFINT_LNKLSTN(1) - I40E_PFINT_LNKLSTN(0)},
107 {I40E_QINT_TQCTL(0), 0x000000FF, 1, I40E_QINT_TQCTL(1) - I40E_QINT_TQCTL(0)},
108 {I40E_QINT_RQCTL(0), 0x000000FF, 1, I40E_QINT_RQCTL(1) - I40E_QINT_RQCTL(0)},
109 {I40E_PFINT_ICR0_ENA, 0xF7F20000, 1, 0},
115 * @hw: pointer to the hw struct
117 * Perform registers diagnostic test
119 enum i40e_status_code i40e_diag_reg_test(struct i40e_hw *hw)
121 enum i40e_status_code ret_code = I40E_SUCCESS;
125 for (i = 0; i40e_reg_list[i].offset != 0 &&
126 ret_code == I40E_SUCCESS; i++) {
128 /* set actual reg range for dynamically allocated resources */
129 if (i40e_reg_list[i].offset == I40E_QTX_CTL(0) &&
130 hw->func_caps.num_tx_qp != 0)
131 i40e_reg_list[i].elements = hw->func_caps.num_tx_qp;
132 if ((i40e_reg_list[i].offset == I40E_PFINT_ITRN(0, 0) ||
133 i40e_reg_list[i].offset == I40E_PFINT_ITRN(1, 0) ||
134 i40e_reg_list[i].offset == I40E_PFINT_ITRN(2, 0) ||
135 i40e_reg_list[i].offset == I40E_QINT_TQCTL(0) ||
136 i40e_reg_list[i].offset == I40E_QINT_RQCTL(0)) &&
137 hw->func_caps.num_msix_vectors != 0)
138 i40e_reg_list[i].elements =
139 hw->func_caps.num_msix_vectors - 1;
141 /* test register access */
142 mask = i40e_reg_list[i].mask;
143 for (j = 0; j < i40e_reg_list[i].elements &&
144 ret_code == I40E_SUCCESS; j++) {
145 reg = i40e_reg_list[i].offset
146 + (j * i40e_reg_list[i].stride);
147 ret_code = i40e_diag_reg_pattern_test(hw, reg, mask);
155 * i40e_diag_eeprom_test
156 * @hw: pointer to the hw struct
158 * Perform EEPROM diagnostic test
160 enum i40e_status_code i40e_diag_eeprom_test(struct i40e_hw *hw)
162 enum i40e_status_code ret_code;
165 /* read NVM control word and if NVM valid, validate EEPROM checksum*/
166 ret_code = i40e_read_nvm_word(hw, I40E_SR_NVM_CONTROL_WORD, ®_val);
167 if ((ret_code == I40E_SUCCESS) &&
168 ((reg_val & I40E_SR_CONTROL_WORD_1_MASK) ==
169 (0x01 << I40E_SR_CONTROL_WORD_1_SHIFT))) {
170 ret_code = i40e_validate_nvm_checksum(hw, NULL);
172 ret_code = I40E_ERR_DIAG_TEST_FAILED;
179 * i40e_diag_fw_alive_test
180 * @hw: pointer to the hw struct
182 * Perform FW alive diagnostic test
184 enum i40e_status_code i40e_diag_fw_alive_test(struct i40e_hw *hw)
186 UNREFERENCED_1PARAMETER(hw);