i40e_diag.c 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. // SPDX-License-Identifier: GPL-2.0
  2. /* Copyright(c) 2013 - 2018 Intel Corporation. */
  3. #include "i40e_diag.h"
  4. #include "i40e_prototype.h"
  5. /**
  6. * i40e_diag_reg_pattern_test
  7. * @hw: pointer to the hw struct
  8. * @reg: reg to be tested
  9. * @mask: bits to be touched
  10. **/
  11. static i40e_status i40e_diag_reg_pattern_test(struct i40e_hw *hw,
  12. u32 reg, u32 mask)
  13. {
  14. static const u32 patterns[] = {
  15. 0x5A5A5A5A, 0xA5A5A5A5, 0x00000000, 0xFFFFFFFF
  16. };
  17. u32 pat, val, orig_val;
  18. int i;
  19. orig_val = rd32(hw, reg);
  20. for (i = 0; i < ARRAY_SIZE(patterns); i++) {
  21. pat = patterns[i];
  22. wr32(hw, reg, (pat & mask));
  23. val = rd32(hw, reg);
  24. if ((val & mask) != (pat & mask)) {
  25. i40e_debug(hw, I40E_DEBUG_DIAG,
  26. "%s: reg pattern test failed - reg 0x%08x pat 0x%08x val 0x%08x\n",
  27. __func__, reg, pat, val);
  28. return I40E_ERR_DIAG_TEST_FAILED;
  29. }
  30. }
  31. wr32(hw, reg, orig_val);
  32. val = rd32(hw, reg);
  33. if (val != orig_val) {
  34. i40e_debug(hw, I40E_DEBUG_DIAG,
  35. "%s: reg restore test failed - reg 0x%08x orig_val 0x%08x val 0x%08x\n",
  36. __func__, reg, orig_val, val);
  37. return I40E_ERR_DIAG_TEST_FAILED;
  38. }
  39. return 0;
  40. }
  41. struct i40e_diag_reg_test_info i40e_reg_list[] = {
  42. /* offset mask elements stride */
  43. {I40E_QTX_CTL(0), 0x0000FFBF, 1,
  44. I40E_QTX_CTL(1) - I40E_QTX_CTL(0)},
  45. {I40E_PFINT_ITR0(0), 0x00000FFF, 3,
  46. I40E_PFINT_ITR0(1) - I40E_PFINT_ITR0(0)},
  47. {I40E_PFINT_ITRN(0, 0), 0x00000FFF, 1,
  48. I40E_PFINT_ITRN(0, 1) - I40E_PFINT_ITRN(0, 0)},
  49. {I40E_PFINT_ITRN(1, 0), 0x00000FFF, 1,
  50. I40E_PFINT_ITRN(1, 1) - I40E_PFINT_ITRN(1, 0)},
  51. {I40E_PFINT_ITRN(2, 0), 0x00000FFF, 1,
  52. I40E_PFINT_ITRN(2, 1) - I40E_PFINT_ITRN(2, 0)},
  53. {I40E_PFINT_STAT_CTL0, 0x0000000C, 1, 0},
  54. {I40E_PFINT_LNKLST0, 0x00001FFF, 1, 0},
  55. {I40E_PFINT_LNKLSTN(0), 0x000007FF, 1,
  56. I40E_PFINT_LNKLSTN(1) - I40E_PFINT_LNKLSTN(0)},
  57. {I40E_QINT_TQCTL(0), 0x000000FF, 1,
  58. I40E_QINT_TQCTL(1) - I40E_QINT_TQCTL(0)},
  59. {I40E_QINT_RQCTL(0), 0x000000FF, 1,
  60. I40E_QINT_RQCTL(1) - I40E_QINT_RQCTL(0)},
  61. {I40E_PFINT_ICR0_ENA, 0xF7F20000, 1, 0},
  62. { 0 }
  63. };
  64. /**
  65. * i40e_diag_reg_test
  66. * @hw: pointer to the hw struct
  67. *
  68. * Perform registers diagnostic test
  69. **/
  70. i40e_status i40e_diag_reg_test(struct i40e_hw *hw)
  71. {
  72. i40e_status ret_code = 0;
  73. u32 reg, mask;
  74. u32 i, j;
  75. for (i = 0; i40e_reg_list[i].offset != 0 &&
  76. !ret_code; i++) {
  77. /* set actual reg range for dynamically allocated resources */
  78. if (i40e_reg_list[i].offset == I40E_QTX_CTL(0) &&
  79. hw->func_caps.num_tx_qp != 0)
  80. i40e_reg_list[i].elements = hw->func_caps.num_tx_qp;
  81. if ((i40e_reg_list[i].offset == I40E_PFINT_ITRN(0, 0) ||
  82. i40e_reg_list[i].offset == I40E_PFINT_ITRN(1, 0) ||
  83. i40e_reg_list[i].offset == I40E_PFINT_ITRN(2, 0) ||
  84. i40e_reg_list[i].offset == I40E_QINT_TQCTL(0) ||
  85. i40e_reg_list[i].offset == I40E_QINT_RQCTL(0)) &&
  86. hw->func_caps.num_msix_vectors != 0)
  87. i40e_reg_list[i].elements =
  88. hw->func_caps.num_msix_vectors - 1;
  89. /* test register access */
  90. mask = i40e_reg_list[i].mask;
  91. for (j = 0; j < i40e_reg_list[i].elements && !ret_code; j++) {
  92. reg = i40e_reg_list[i].offset +
  93. (j * i40e_reg_list[i].stride);
  94. ret_code = i40e_diag_reg_pattern_test(hw, reg, mask);
  95. }
  96. }
  97. return ret_code;
  98. }
  99. /**
  100. * i40e_diag_eeprom_test
  101. * @hw: pointer to the hw struct
  102. *
  103. * Perform EEPROM diagnostic test
  104. **/
  105. i40e_status i40e_diag_eeprom_test(struct i40e_hw *hw)
  106. {
  107. i40e_status ret_code;
  108. u16 reg_val;
  109. /* read NVM control word and if NVM valid, validate EEPROM checksum*/
  110. ret_code = i40e_read_nvm_word(hw, I40E_SR_NVM_CONTROL_WORD, &reg_val);
  111. if (!ret_code &&
  112. ((reg_val & I40E_SR_CONTROL_WORD_1_MASK) ==
  113. BIT(I40E_SR_CONTROL_WORD_1_SHIFT)))
  114. return i40e_validate_nvm_checksum(hw, NULL);
  115. else
  116. return I40E_ERR_DIAG_TEST_FAILED;
  117. }