2 * Copyright (c) 2021 Broadcom. All rights reserved.
3 * The term "Broadcom" refers to Broadcom Limited and/or its subsidiaries.
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met:
8 * 1. Redistributions of source code must retain the above copyright notice,
9 * this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright notice,
12 * this list of conditions and the following disclaimer in the documentation
13 * and/or other materials provided with the distribution.
15 * 3. Neither the name of the copyright holder nor the names of its contributors
16 * may be used to endorse or promote products derived from this software
17 * without specific prior written permission.
19 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
20 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
23 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 * POSSIBILITY OF SUCH DAMAGE.
34 #include "ocs_gendump.h"
36 /* Reset all the functions associated with a bus/dev */
38 ocs_gen_dump_reset(uint8_t bus, uint8_t dev)
44 while ((ocs = ocs_get_instance(index++)) != NULL) {
45 uint8_t ocs_bus, ocs_dev, ocs_func;
48 ocs_get_bus_dev_func(ocs, &ocs_bus, &ocs_dev, &ocs_func);
50 if (!(ocs_bus == bus && ocs_dev == dev))
53 if (ocs_hw_reset(&ocs->hw, OCS_HW_RESET_FUNCTION)) {
54 ocs_log_test(ocs, "failed to reset port\n");
59 ocs_log_debug(ocs, "successfully reset port\n");
60 while ((domain = ocs_list_get_head(&ocs->domain_list)) != NULL) {
61 ocs_log_debug(ocs, "free domain %p\n", domain);
62 ocs_domain_force_free(domain);
64 /* now initialize hw so user can read the dump in */
65 if (ocs_hw_init(&ocs->hw)) {
66 ocs_log_err(ocs, "failed to initialize hw\n");
69 ocs_log_debug(ocs, "successfully initialized hw\n");
76 ocs_gen_dump(ocs_t *ocs)
78 uint32_t reset_required;
81 uint8_t bus, dev, func;
83 int index = 0, port_index = 0;
85 uint8_t nxt_bus, nxt_dev, nxt_func;
86 uint8_t prev_port_state[OCS_MAX_HBA_PORTS] = {0,};
87 ocs_xport_stats_t link_status;
89 ocs_get_bus_dev_func(ocs, &bus, &dev, &func);
91 /* Drop link on all ports belongs to this HBA*/
92 while ((nxt_ocs = ocs_get_instance(index++)) != NULL) {
93 ocs_get_bus_dev_func(nxt_ocs, &nxt_bus, &nxt_dev, &nxt_func);
95 if (!(bus == nxt_bus && dev == nxt_dev))
98 if ((port_index >= OCS_MAX_HBA_PORTS))
101 /* Check current link status and save for future use */
102 if (ocs_xport_status(nxt_ocs->xport, OCS_XPORT_PORT_STATUS,
103 &link_status) == 0) {
104 if (link_status.value == OCS_XPORT_PORT_ONLINE) {
105 prev_port_state[port_index] = 1;
106 ocs_xport_control(nxt_ocs->xport,
107 OCS_XPORT_PORT_OFFLINE);
109 prev_port_state[port_index] = 0;
115 /* Wait until all ports have quiesced */
116 for (index = 0; (nxt_ocs = ocs_get_instance(index++)) != NULL; ) {
119 ocs_xport_stats_t status;
121 ocs_xport_status(nxt_ocs->xport, OCS_XPORT_IS_QUIESCED,
124 ocs_log_debug(nxt_ocs, "port quiesced\n");
130 if (ms_waited > 60000) {
131 ocs_log_test(nxt_ocs,
132 "timed out waiting for port to quiesce\n");
139 if (ocs_hw_raise_ue(&ocs->hw, 1) == OCS_HW_RTN_SUCCESS) {
141 /* Wait for dump to complete */
142 ocs_log_debug(ocs, "Dump requested, wait for completion.\n");
146 while ((!dump_ready) && (ms_waited < 30000)) {
147 ocs_hw_get(&ocs->hw, OCS_HW_DUMP_READY, &dump_ready);
153 ocs_log_test(ocs, "Failed to see dump after 30 secs\n");
156 ocs_log_debug(ocs, "sucessfully generated dump\n");
160 ocs_hw_get(&ocs->hw, OCS_HW_RESET_REQUIRED, &reset_required);
161 ocs_log_debug(ocs, "reset required=%d\n", reset_required);
162 if (reset_required) {
163 if (ocs_gen_dump_reset(bus, dev) == 0) {
164 ocs_log_debug(ocs, "all devices reset\n");
166 ocs_log_test(ocs, "all devices NOT reset\n");
170 ocs_log_test(ocs, "dump request to hw failed\n");
174 index = port_index = 0;
176 /* Bring links on each HBA port to previous state*/
177 while ((nxt_ocs = ocs_get_instance(index++)) != NULL) {
178 ocs_get_bus_dev_func(nxt_ocs, &nxt_bus, &nxt_dev, &nxt_func);
179 if (port_index > OCS_MAX_HBA_PORTS) {
180 ocs_log_err(NULL, "port index(%d) out of boundary\n",
185 if ((bus == nxt_bus) && (dev == nxt_dev) &&
186 prev_port_state[port_index++]) {
187 ocs_xport_control(nxt_ocs->xport, OCS_XPORT_PORT_ONLINE);
195 ocs_fdb_dump(ocs_t *ocs)
204 if (ocs_hw_raise_ue(&ocs->hw, FDB) == OCS_HW_RTN_SUCCESS) {
206 /* Wait for dump to complete */
207 ocs_log_debug(ocs, "Dump requested, wait for completion.\n");
211 while ((!(dump_ready == FDB)) && (ms_waited < 10000)) {
212 ocs_hw_get(&ocs->hw, OCS_HW_DUMP_READY, &dump_ready);
218 ocs_log_err(ocs, "Failed to see dump after 10 secs\n");
222 ocs_log_debug(ocs, "sucessfully generated dump\n");
225 ocs_log_err(ocs, "dump request to hw failed\n");
233 * @brief Create a Lancer dump into a memory buffer
235 * This function creates a DMA buffer to hold a Lancer dump,
236 * sets the dump location to point to that buffer, then calls
237 * ocs_gen_dump to cause a dump to be transferred to the buffer.
238 * After the dump is complete it copies the dump to the provided
241 * @param ocs Pointer to ocs structure
242 * @param buf User space buffer in which to store the dump
243 * @param buflen Length of the user buffer in bytes
245 * @return Returns 0 on success, non-zero on error.
248 ocs_dump_to_host(ocs_t *ocs, void *buf, uint32_t buflen)
251 uint32_t i, num_buffers;
252 ocs_dma_t *dump_buffers;
253 uint32_t rem_bytes, offset;
256 ocs_log_test(ocs, "zero buffer length is invalid\n");
260 num_buffers = ((buflen + OCS_MAX_DMA_ALLOC - 1) / OCS_MAX_DMA_ALLOC);
262 dump_buffers = ocs_malloc(ocs, sizeof(ocs_dma_t) * num_buffers,
263 OCS_M_ZERO | OCS_M_NOWAIT);
264 if (dump_buffers == NULL) {
265 ocs_log_err(ocs, "Failed to dump buffers\n");
269 /* Allocate a DMA buffers to hold the dump */
271 for (i = 0; i < num_buffers; i++) {
272 uint32_t num_bytes = MIN(rem_bytes, OCS_MAX_DMA_ALLOC);
274 rc = ocs_dma_alloc(ocs, &dump_buffers[i], num_bytes,
275 OCS_MIN_DMA_ALIGNMENT);
277 ocs_log_err(ocs, "Failed to allocate dump buffer\n");
279 /* Free any previously allocated buffers */
280 goto free_and_return;
282 rem_bytes -= num_bytes;
285 rc = ocs_hw_set_dump_location(&ocs->hw, num_buffers, dump_buffers, 0);
287 ocs_log_test(ocs, "ocs_hw_set_dump_location failed\n");
288 goto free_and_return;
291 /* Generate the dump */
292 rc = ocs_gen_dump(ocs);
294 ocs_log_test(ocs, "ocs_gen_dump failed\n");
295 goto free_and_return;
298 /* Copy the dump from the DMA buffer into the user buffer */
300 for (i = 0; i < num_buffers; i++) {
301 if (ocs_copy_to_user((uint8_t*)buf + offset,
302 dump_buffers[i].virt, dump_buffers[i].size)) {
303 ocs_log_test(ocs, "ocs_copy_to_user failed\n");
306 offset += dump_buffers[i].size;
310 /* Free the DMA buffer and return */
311 for (i = 0; i < num_buffers; i++) {
312 ocs_dma_free(ocs, &dump_buffers[i]);
314 ocs_free(ocs, dump_buffers, sizeof(ocs_dma_t) * num_buffers);
319 ocs_function_speciic_dump(ocs_t *ocs, void *buf, uint32_t buflen)
322 uint32_t i, num_buffers;
323 ocs_dma_t *dump_buffers;
324 uint32_t rem_bytes, offset;
327 ocs_log_err(ocs, "zero buffer length is invalid\n");
331 num_buffers = ((buflen + OCS_MAX_DMA_ALLOC - 1) / OCS_MAX_DMA_ALLOC);
333 dump_buffers = ocs_malloc(ocs, sizeof(ocs_dma_t) * num_buffers,
334 OCS_M_ZERO | OCS_M_NOWAIT);
335 if (dump_buffers == NULL) {
336 ocs_log_err(ocs, "Failed to allocate dump buffers\n");
340 /* Allocate a DMA buffers to hold the dump */
342 for (i = 0; i < num_buffers; i++) {
343 uint32_t num_bytes = MIN(rem_bytes, OCS_MAX_DMA_ALLOC);
344 rc = ocs_dma_alloc(ocs, &dump_buffers[i], num_bytes,
345 OCS_MIN_DMA_ALIGNMENT);
347 ocs_log_err(ocs, "Failed to allocate dma buffer\n");
349 /* Free any previously allocated buffers */
350 goto free_and_return;
352 rem_bytes -= num_bytes;
355 /* register buffers for function spcific dump */
356 rc = ocs_hw_set_dump_location(&ocs->hw, num_buffers, dump_buffers, 1);
358 ocs_log_err(ocs, "ocs_hw_set_dump_location failed\n");
359 goto free_and_return;
362 /* Invoke dump by setting fdd=1 and ip=1 in sliport_control register */
363 rc = ocs_fdb_dump(ocs);
365 ocs_log_err(ocs, "ocs_gen_dump failed\n");
366 goto free_and_return;
369 /* Copy the dump from the DMA buffer into the user buffer */
371 for (i = 0; i < num_buffers; i++) {
372 if (ocs_copy_to_user((uint8_t*)buf + offset,
373 dump_buffers[i].virt, dump_buffers[i].size)) {
374 ocs_log_err(ocs, "ocs_copy_to_user failed\n");
377 offset += dump_buffers[i].size;
381 /* Free the DMA buffer and return */
382 for (i = 0; i < num_buffers; i++) {
383 ocs_dma_free(ocs, &dump_buffers[i]);
385 ocs_free(ocs, dump_buffers, sizeof(ocs_dma_t) * num_buffers);