i40e_diag.c 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  1. // SPDX-License-Identifier: GPL-2.0
  2. /*******************************************************************************
  3. *
  4. * Intel Ethernet Controller XL710 Family Linux Driver
  5. * Copyright(c) 2013 - 2014 Intel Corporation.
  6. *
  7. * This program is free software; you can redistribute it and/or modify it
  8. * under the terms and conditions of the GNU General Public License,
  9. * version 2, as published by the Free Software Foundation.
  10. *
  11. * This program is distributed in the hope it will be useful, but WITHOUT
  12. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13. * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
  14. * more details.
  15. *
  16. * You should have received a copy of the GNU General Public License along
  17. * with this program. If not, see <http://www.gnu.org/licenses/>.
  18. *
  19. * The full GNU General Public License is included in this distribution in
  20. * the file called "COPYING".
  21. *
  22. * Contact Information:
  23. * e1000-devel Mailing List <e1000-devel@lists.sourceforge.net>
  24. * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
  25. *
  26. ******************************************************************************/
  27. #include "i40e_diag.h"
  28. #include "i40e_prototype.h"
  29. /**
  30. * i40e_diag_reg_pattern_test
  31. * @hw: pointer to the hw struct
  32. * @reg: reg to be tested
  33. * @mask: bits to be touched
  34. **/
  35. static i40e_status i40e_diag_reg_pattern_test(struct i40e_hw *hw,
  36. u32 reg, u32 mask)
  37. {
  38. static const u32 patterns[] = {
  39. 0x5A5A5A5A, 0xA5A5A5A5, 0x00000000, 0xFFFFFFFF
  40. };
  41. u32 pat, val, orig_val;
  42. int i;
  43. orig_val = rd32(hw, reg);
  44. for (i = 0; i < ARRAY_SIZE(patterns); i++) {
  45. pat = patterns[i];
  46. wr32(hw, reg, (pat & mask));
  47. val = rd32(hw, reg);
  48. if ((val & mask) != (pat & mask)) {
  49. i40e_debug(hw, I40E_DEBUG_DIAG,
  50. "%s: reg pattern test failed - reg 0x%08x pat 0x%08x val 0x%08x\n",
  51. __func__, reg, pat, val);
  52. return I40E_ERR_DIAG_TEST_FAILED;
  53. }
  54. }
  55. wr32(hw, reg, orig_val);
  56. val = rd32(hw, reg);
  57. if (val != orig_val) {
  58. i40e_debug(hw, I40E_DEBUG_DIAG,
  59. "%s: reg restore test failed - reg 0x%08x orig_val 0x%08x val 0x%08x\n",
  60. __func__, reg, orig_val, val);
  61. return I40E_ERR_DIAG_TEST_FAILED;
  62. }
  63. return 0;
  64. }
  65. struct i40e_diag_reg_test_info i40e_reg_list[] = {
  66. /* offset mask elements stride */
  67. {I40E_QTX_CTL(0), 0x0000FFBF, 1,
  68. I40E_QTX_CTL(1) - I40E_QTX_CTL(0)},
  69. {I40E_PFINT_ITR0(0), 0x00000FFF, 3,
  70. I40E_PFINT_ITR0(1) - I40E_PFINT_ITR0(0)},
  71. {I40E_PFINT_ITRN(0, 0), 0x00000FFF, 1,
  72. I40E_PFINT_ITRN(0, 1) - I40E_PFINT_ITRN(0, 0)},
  73. {I40E_PFINT_ITRN(1, 0), 0x00000FFF, 1,
  74. I40E_PFINT_ITRN(1, 1) - I40E_PFINT_ITRN(1, 0)},
  75. {I40E_PFINT_ITRN(2, 0), 0x00000FFF, 1,
  76. I40E_PFINT_ITRN(2, 1) - I40E_PFINT_ITRN(2, 0)},
  77. {I40E_PFINT_STAT_CTL0, 0x0000000C, 1, 0},
  78. {I40E_PFINT_LNKLST0, 0x00001FFF, 1, 0},
  79. {I40E_PFINT_LNKLSTN(0), 0x000007FF, 1,
  80. I40E_PFINT_LNKLSTN(1) - I40E_PFINT_LNKLSTN(0)},
  81. {I40E_QINT_TQCTL(0), 0x000000FF, 1,
  82. I40E_QINT_TQCTL(1) - I40E_QINT_TQCTL(0)},
  83. {I40E_QINT_RQCTL(0), 0x000000FF, 1,
  84. I40E_QINT_RQCTL(1) - I40E_QINT_RQCTL(0)},
  85. {I40E_PFINT_ICR0_ENA, 0xF7F20000, 1, 0},
  86. { 0 }
  87. };
  88. /**
  89. * i40e_diag_reg_test
  90. * @hw: pointer to the hw struct
  91. *
  92. * Perform registers diagnostic test
  93. **/
  94. i40e_status i40e_diag_reg_test(struct i40e_hw *hw)
  95. {
  96. i40e_status ret_code = 0;
  97. u32 reg, mask;
  98. u32 i, j;
  99. for (i = 0; i40e_reg_list[i].offset != 0 &&
  100. !ret_code; i++) {
  101. /* set actual reg range for dynamically allocated resources */
  102. if (i40e_reg_list[i].offset == I40E_QTX_CTL(0) &&
  103. hw->func_caps.num_tx_qp != 0)
  104. i40e_reg_list[i].elements = hw->func_caps.num_tx_qp;
  105. if ((i40e_reg_list[i].offset == I40E_PFINT_ITRN(0, 0) ||
  106. i40e_reg_list[i].offset == I40E_PFINT_ITRN(1, 0) ||
  107. i40e_reg_list[i].offset == I40E_PFINT_ITRN(2, 0) ||
  108. i40e_reg_list[i].offset == I40E_QINT_TQCTL(0) ||
  109. i40e_reg_list[i].offset == I40E_QINT_RQCTL(0)) &&
  110. hw->func_caps.num_msix_vectors != 0)
  111. i40e_reg_list[i].elements =
  112. hw->func_caps.num_msix_vectors - 1;
  113. /* test register access */
  114. mask = i40e_reg_list[i].mask;
  115. for (j = 0; j < i40e_reg_list[i].elements && !ret_code; j++) {
  116. reg = i40e_reg_list[i].offset +
  117. (j * i40e_reg_list[i].stride);
  118. ret_code = i40e_diag_reg_pattern_test(hw, reg, mask);
  119. }
  120. }
  121. return ret_code;
  122. }
  123. /**
  124. * i40e_diag_eeprom_test
  125. * @hw: pointer to the hw struct
  126. *
  127. * Perform EEPROM diagnostic test
  128. **/
  129. i40e_status i40e_diag_eeprom_test(struct i40e_hw *hw)
  130. {
  131. i40e_status ret_code;
  132. u16 reg_val;
  133. /* read NVM control word and if NVM valid, validate EEPROM checksum*/
  134. ret_code = i40e_read_nvm_word(hw, I40E_SR_NVM_CONTROL_WORD, &reg_val);
  135. if (!ret_code &&
  136. ((reg_val & I40E_SR_CONTROL_WORD_1_MASK) ==
  137. BIT(I40E_SR_CONTROL_WORD_1_SHIFT)))
  138. return i40e_validate_nvm_checksum(hw, NULL);
  139. else
  140. return I40E_ERR_DIAG_TEST_FAILED;
  141. }