qed: add infrastructure for device self tests.
[cascardo/linux.git] / drivers / net / ethernet / qlogic / qed / qed_selftest.c
1 #include "qed.h"
2 #include "qed_dev_api.h"
3 #include "qed_mcp.h"
4 #include "qed_sp.h"
5
6 int qed_selftest_memory(struct qed_dev *cdev)
7 {
8         int rc = 0, i;
9
10         for_each_hwfn(cdev, i) {
11                 rc = qed_sp_heartbeat_ramrod(&cdev->hwfns[i]);
12                 if (rc)
13                         return rc;
14         }
15
16         return rc;
17 }
18
19 int qed_selftest_interrupt(struct qed_dev *cdev)
20 {
21         int rc = 0, i;
22
23         for_each_hwfn(cdev, i) {
24                 rc = qed_sp_heartbeat_ramrod(&cdev->hwfns[i]);
25                 if (rc)
26                         return rc;
27         }
28
29         return rc;
30 }
31
32 int qed_selftest_register(struct qed_dev *cdev)
33 {
34         struct qed_hwfn *p_hwfn;
35         struct qed_ptt *p_ptt;
36         int rc = 0, i;
37
38         /* although performed by MCP, this test is per engine */
39         for_each_hwfn(cdev, i) {
40                 p_hwfn = &cdev->hwfns[i];
41                 p_ptt = qed_ptt_acquire(p_hwfn);
42                 if (!p_ptt) {
43                         DP_ERR(p_hwfn, "failed to acquire ptt\n");
44                         return -EBUSY;
45                 }
46                 rc = qed_mcp_bist_register_test(p_hwfn, p_ptt);
47                 qed_ptt_release(p_hwfn, p_ptt);
48                 if (rc)
49                         break;
50         }
51
52         return rc;
53 }
54
55 int qed_selftest_clock(struct qed_dev *cdev)
56 {
57         struct qed_hwfn *p_hwfn;
58         struct qed_ptt *p_ptt;
59         int rc = 0, i;
60
61         /* although performed by MCP, this test is per engine */
62         for_each_hwfn(cdev, i) {
63                 p_hwfn = &cdev->hwfns[i];
64                 p_ptt = qed_ptt_acquire(p_hwfn);
65                 if (!p_ptt) {
66                         DP_ERR(p_hwfn, "failed to acquire ptt\n");
67                         return -EBUSY;
68                 }
69                 rc = qed_mcp_bist_clock_test(p_hwfn, p_ptt);
70                 qed_ptt_release(p_hwfn, p_ptt);
71                 if (rc)
72                         break;
73         }
74
75         return rc;
76 }