1 /* QLogic qed NIC Driver
2 * Copyright (c) 2015-2016 QLogic Corporation
4 * This software is available to you under a choice of one of two
5 * licenses. You may choose to be licensed under the terms of the GNU
6 * General Public License (GPL) Version 2, available from the file
7 * COPYING in the main directory of this source tree, or the
8 * OpenIB.org BSD license below:
10 * Redistribution and use in source and binary forms, with or
11 * without modification, are permitted provided that the following
14 * - Redistributions of source code must retain the above
15 * copyright notice, this list of conditions and the following
18 * - Redistributions in binary form must reproduce the above
19 * copyright notice, this list of conditions and the following
20 * disclaimer in the documentation and /or other materials
21 * provided with the distribution.
23 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
24 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
25 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
26 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
27 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
28 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
29 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
33 #include <linux/crc32.h>
35 #include "qed_dev_api.h"
38 #include "qed_selftest.h"
40 int qed_selftest_memory(struct qed_dev *cdev)
44 for_each_hwfn(cdev, i) {
45 rc = qed_sp_heartbeat_ramrod(&cdev->hwfns[i]);
53 int qed_selftest_interrupt(struct qed_dev *cdev)
57 for_each_hwfn(cdev, i) {
58 rc = qed_sp_heartbeat_ramrod(&cdev->hwfns[i]);
66 int qed_selftest_register(struct qed_dev *cdev)
68 struct qed_hwfn *p_hwfn;
69 struct qed_ptt *p_ptt;
72 /* although performed by MCP, this test is per engine */
73 for_each_hwfn(cdev, i) {
74 p_hwfn = &cdev->hwfns[i];
75 p_ptt = qed_ptt_acquire(p_hwfn);
77 DP_ERR(p_hwfn, "failed to acquire ptt\n");
80 rc = qed_mcp_bist_register_test(p_hwfn, p_ptt);
81 qed_ptt_release(p_hwfn, p_ptt);
89 int qed_selftest_clock(struct qed_dev *cdev)
91 struct qed_hwfn *p_hwfn;
92 struct qed_ptt *p_ptt;
95 /* although performed by MCP, this test is per engine */
96 for_each_hwfn(cdev, i) {
97 p_hwfn = &cdev->hwfns[i];
98 p_ptt = qed_ptt_acquire(p_hwfn);
100 DP_ERR(p_hwfn, "failed to acquire ptt\n");
103 rc = qed_mcp_bist_clock_test(p_hwfn, p_ptt);
104 qed_ptt_release(p_hwfn, p_ptt);
112 int qed_selftest_nvram(struct qed_dev *cdev)
114 struct qed_hwfn *p_hwfn = QED_LEADING_HWFN(cdev);
115 struct qed_ptt *p_ptt = qed_ptt_acquire(p_hwfn);
116 u32 num_images, i, j, nvm_crc, calc_crc;
117 struct bist_nvm_image_att image_att;
123 DP_ERR(p_hwfn, "failed to acquire ptt\n");
127 /* Acquire from MFW the amount of available images */
128 rc = qed_mcp_bist_nvm_test_get_num_images(p_hwfn, p_ptt, &num_images);
129 if (rc || !num_images) {
130 DP_ERR(p_hwfn, "Failed getting number of images\n");
134 /* Iterate over images and validate CRC */
135 for (i = 0; i < num_images; i++) {
136 /* This mailbox returns information about the image required for
139 rc = qed_mcp_bist_nvm_test_get_image_att(p_hwfn, p_ptt,
143 "Failed getting image index %d attributes\n",
148 /* After MFW crash dump is collected - the image's CRC stops
151 if (image_att.image_type == NVM_TYPE_MDUMP)
154 DP_VERBOSE(p_hwfn, QED_MSG_SP, "image index %d, size %x\n",
157 /* Allocate a buffer for holding the nvram image */
158 buf = kzalloc(image_att.len, GFP_KERNEL);
164 /* Read image into buffer */
165 rc = qed_mcp_nvm_read(p_hwfn->cdev, image_att.nvm_start_addr,
169 "Failed reading image index %d from nvm.\n", i);
173 /* Convert the buffer into big-endian format (excluding the
174 * closing 4 bytes of CRC).
176 for (j = 0; j < image_att.len - 4; j += 4) {
177 val = cpu_to_be32(*(u32 *)&buf[j]);
178 *(u32 *)&buf[j] = (__force u32)val;
181 /* Calc CRC for the "actual" image buffer, i.e. not including
182 * the last 4 CRC bytes.
184 nvm_crc = *(u32 *)(buf + image_att.len - 4);
185 calc_crc = crc32(0xffffffff, buf, image_att.len - 4);
186 calc_crc = (__force u32)~cpu_to_be32(calc_crc);
187 DP_VERBOSE(p_hwfn, QED_MSG_SP,
188 "nvm crc 0x%x, calc_crc 0x%x\n", nvm_crc, calc_crc);
190 if (calc_crc != nvm_crc) {
195 /* Done with this image; Free to prevent double release
196 * on subsequent failure.
202 qed_ptt_release(p_hwfn, p_ptt);
208 qed_ptt_release(p_hwfn, p_ptt);