freebsd-dev/sys/dev/mfi/mfi_debug.c
Steven Hartland 08c89430bd Fixes queuing issues where mfi_release_command blindly sets the cm_flags = 0
without first removing the command from the relavent queue.

This was causing panics in the queue functions which check to ensure a command
is not on another queue.

Fixed some cases where the error from mfi_mapcmd was lost and where the command
was never released / dequeued in error cases.

Ensure that all failures to mfi_mapcmd are logged.

Fixed possible null pointer exception in mfi_aen_setup if mfi_get_log_state
failed.

Fixed mfi_parse_entries & mfi_aen_setup not returning possible errors.

Corrected MFI_DUMP_CMDS calls with invalid vars SC vs sc.

Commands which have timed out now set cm_error to ETIMEDOUT and call
mfi_complete which prevents them getting stuck in the busy queue forever.

Fixed possible use of NULL pointer in mfi_tbolt_get_cmd.

Changed output formats to be more easily recognisable when debugging.

Optimised mfi_cmd_pool_tbolt cleanup.

Made information about driver limiting commands always display as for modern
cards this can be severe.

Fixed mfi_tbolt_alloc_cmd out of memory case which previously didnt return an
error.

Added malloc checks for request_desc_pool including free when subsiquent errors
are detected.

Fixed overflow error in SIMD reply descriptor check.

Fixed tbolt_cmd leak in mfi_build_and_issue_cmd if there's an error during IO
build.

Elimintated double checks on sc->mfi_aen_cm & sc->mfi_map_sync_cm in
mfi_shutdown.

Move local hdr calculation after error check in mfi_aen_complete.

Fixed wakeup on NULL in mfi_aen_complete.

Fixed mfi_aen_cm cleanup in mfi_process_fw_state_chg_isr not checking if it was
NULL.

Changed mfi_alloc_commands to error if bus_dmamap_create fails. Previously we
would try to continue with the number of allocated commands but lots of places
in the driver assume sc->mfi_max_fw_cmds is whats available so its unsafe to do
this without lots of changes.

Removed mfi_total_cmds as its no longer used due the above change.

Corrected mfi_tbolt_alloc_cmd to return ENOMEM where appropriate.

Fixed timeouts actually firing at double what they should.

Setting hw.mfi.max_cmds=-1 now configures to use the controller max.

A few style (9) fixes e.g. braced single line conditions and double blank lines

Cleaned up queuing macros

Removed invalid queuing tests for multiple queues

Trap and deal with errors when doing sends in mfi_data_cb

Refactored frame sending into one method with error checking of the return
code so we can ensure commands aren't left on the queue after error. This
ensures that mfi_mapcmd & mfi_data_cb leave the queue in a valid state.

Refactored how commands are cleaned up, mfi_release_command now ensures
that all queues and command state is maintained in a consistent state.

Prevent NULL pointer use in mfi_tbolt_complete_cmd

Fixed use of NULL sc->mfi_map_sync_cm in wakeup

Added defines to help with output of mfi_cmd and header flags.

Fixed mfi_tbolt_init_MFI_queue invalidating cm_index of the acquired mfi_cmd.

Reset now reinitialises sync map as well as AEN.

Fixed possible use of NULL pointer in mfi_build_and_issue_cmd

Fixed mfi_tbolt_init_MFI_queue call to mfi_process_fw_state_chg_isr causing
panic on failure.

Ensure that tbolt cards always initialise next_host_reply_index and
free_host_reply_index (based off mfi_max_fw_cmds) on both startup and
reset as per the linux driver.

Fixed mfi_tbolt_complete_cmd not acknowledging unknown commands so
it didn't clear the controller.

Prevent locks from being dropped and re-acquired in the following functions
which was allowing multiple threads to enter critical methods such as
mfi_tbolt_complete_cmd & mfi_process_fw_state_chg_isr:-
* mfi_tbolt_init_MFI_queue
* mfi_aen_complete / mfi_aen_register
* mfi_tbolt_sync_map_info
* mfi_get_log_state
* mfi_parse_entries

The locking for these functions was promoting to higher level methods. This
also fixed MFI_LINUX_SET_AEN_2 which was already acquiring the lock, so would
have paniced for recursive lock.

This also required changing malloc of ld_sync in mfi_tbolt_sync_map_info to
M_NOWAIT which can hence now fail but this was already expected as its return
was being tested.

Removed the assignment of cm_index in mfi_tbolt_init_MFI_queue which breaks
the world if the cmd returned by mfi_dequeue_free isn't the first cmd.

Fixed locking in mfi_data_cb, this is an async callback from bus_dmamap_load
which could hence be called after the caller has dropped the lock. If we
don't have the lock we aquire it and ensure we unlock before returning.

Fixed locking mfi_comms_init when mfi_dequeue_free fails.

Fixed mfi_build_and_issue_cmd not returning tbolt cmds aquired to the pool
on error.

Fixed mfi_abort not dropping the io lock when mfi_dequeue_free fails.

Added hw.mfi.polled_cmd_timeout sysctl that enables tuning of polled
timeouts. This shouldn't be reduced below 50 seconds as its used for
firmware patching which can take quite some time.

Added hw.mfi.fw_reset_test sysctl which is avaliable when compiled with
MFI_DEBUG and allows the testing of controller reset that was provoking a
large number of the issues encountered here.

Reviewed by:	Doug Ambrisko
Approved by:	pjd (mentor)
MFC after:	1 month
2013-02-27 02:21:10 +00:00

266 lines
6.4 KiB
C

/*-
* Copyright (c) 2006 IronPort Systems
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/
#include <sys/cdefs.h>
__FBSDID("$FreeBSD$");
#include "opt_mfi.h"
#ifdef MFI_DEBUG
#include <sys/param.h>
#include <sys/systm.h>
#include <sys/kernel.h>
#include <sys/conf.h>
#include <sys/bus.h>
#include <sys/bio.h>
#include <sys/lock.h>
#include <sys/mutex.h>
#include <sys/malloc.h>
#include <sys/selinfo.h>
#include <sys/sysctl.h>
#include <sys/taskqueue.h>
#include <sys/uio.h>
#include <machine/resource.h>
#include <machine/bus.h>
#include <vm/vm.h>
#include <vm/pmap.h>
#include <dev/mfi/mfireg.h>
#include <dev/mfi/mfi_ioctl.h>
#include <dev/mfi/mfivar.h>
static void
mfi_print_frame_flags(device_t dev, uint32_t flags)
{
device_printf(dev, "flags=%b\n", flags, MFI_FRAME_FMT);
}
static void
mfi_print_sgl(struct mfi_frame_header *hdr, union mfi_sgl *sgl, int count)
{
int i, columns = 0;
printf("SG List:\n");
for (i = 0; i < count; i++) {
if (hdr->flags & MFI_FRAME_IEEE_SGL) {
printf("0x%lx:%06d ", (u_long)sgl->sg_skinny[i].addr,
sgl->sg_skinny[i].len);
columns += 26;
if (columns > 77) {
printf("\n");
columns = 0;
}
} else if (hdr->flags & MFI_FRAME_SGL64) {
printf("0x%lx:%06d ", (u_long)sgl->sg64[i].addr,
sgl->sg64[i].len);
columns += 26;
if (columns > 77) {
printf("\n");
columns = 0;
}
} else {
printf("0x%x:%06d ", sgl->sg32[i].addr,
sgl->sg32[i].len);
columns += 18;
if (columns > 71) {
printf("\n");
columns = 0;
}
}
}
if (columns != 0)
printf("\n");
}
static void
mfi_print_ldio(struct mfi_softc *sc, device_t dev, struct mfi_command *cm)
{
struct mfi_io_frame *io;
struct mfi_frame_header *hdr;
io = &cm->cm_frame->io;
hdr = &io->header;
device_printf(dev, "cmd=%s target_id=%d sg_count=%d data_len=%d "
"lba=%d\n", (hdr->cmd == MFI_CMD_LD_READ) ? "LD_READ":"LD_WRITE",
hdr->target_id, hdr->sg_count, hdr->data_len, io->lba_lo);
mfi_print_frame_flags(dev, hdr->flags);
mfi_print_sgl(hdr, &io->sgl, hdr->sg_count);
}
static void
mfi_print_dcmd(struct mfi_softc *sc, device_t dev, struct mfi_command *cm)
{
struct mfi_dcmd_frame *dcmd;
struct mfi_frame_header *hdr;
const char *opcode;
dcmd = &cm->cm_frame->dcmd;
hdr = &dcmd->header;
switch (dcmd->opcode) {
case MFI_DCMD_CTRL_GETINFO:
opcode = "CTRL_GETINFO";
break;
case MFI_DCMD_CTRL_FLUSHCACHE:
opcode = "CTRL_FLUSHCACHE";
break;
case MFI_DCMD_CTRL_SHUTDOWN:
opcode = "CTRL_SHUTDOWN";
break;
case MFI_DCMD_CTRL_EVENT_GETINFO:
opcode = "EVENT_GETINFO";
break;
case MFI_DCMD_CTRL_EVENT_GET:
opcode = "EVENT_GET";
break;
case MFI_DCMD_CTRL_EVENT_WAIT:
opcode = "EVENT_WAIT";
break;
case MFI_DCMD_LD_GET_LIST:
opcode = "LD_GET_LIST";
break;
case MFI_DCMD_LD_GET_INFO:
opcode = "LD_GET_INFO";
break;
case MFI_DCMD_LD_GET_PROP:
opcode = "LD_GET_PROP";
break;
case MFI_DCMD_LD_SET_PROP:
opcode = "LD_SET_PROP";
break;
case MFI_DCMD_CLUSTER:
opcode = "CLUSTER";
break;
case MFI_DCMD_CLUSTER_RESET_ALL:
opcode = "CLUSTER_RESET_ALL";
break;
case MFI_DCMD_CLUSTER_RESET_LD:
opcode = "CLUSTER_RESET_LD";
break;
case MFI_DCMD_LD_MAP_GET_INFO:
opcode = "LD_MAP_GET_INFO";
break;
default:
opcode = "UNKNOWN";
break;
}
device_printf(dev, "cmd=MFI_CMD_DCMD opcode=%s data_len=%d\n",
opcode, hdr->data_len);
mfi_print_frame_flags(dev, hdr->flags);
mfi_print_sgl(hdr, &dcmd->sgl, hdr->sg_count);
}
static void
mfi_print_generic_frame(struct mfi_softc *sc, struct mfi_command *cm)
{
hexdump(cm->cm_frame, cm->cm_total_frame_size, NULL, HD_OMIT_CHARS);
}
void
mfi_print_cmd(struct mfi_command *cm)
{
device_t dev;
struct mfi_softc *sc;
sc = cm->cm_sc;
dev = sc->mfi_dev;
device_printf(dev, "cm=%p index=%d total_frame_size=%d "
"extra_frames=%d\n", cm, cm->cm_index, cm->cm_total_frame_size,
cm->cm_extra_frames);
device_printf(dev, "flags=%b\n", cm->cm_flags, MFI_CMD_FLAGS_FMT);
switch (cm->cm_frame->header.cmd) {
case MFI_CMD_DCMD:
mfi_print_dcmd(sc, dev, cm);
break;
case MFI_CMD_LD_READ:
case MFI_CMD_LD_WRITE:
mfi_print_ldio(sc, dev, cm);
break;
default:
mfi_print_generic_frame(sc, cm);
break;
}
return;
}
void
mfi_dump_cmds(struct mfi_softc *sc)
{
int i;
for (i = 0; i < sc->mfi_max_fw_cmds; i++)
mfi_print_generic_frame(sc, &sc->mfi_commands[i]);
}
void
mfi_validate_sg(struct mfi_softc *sc, struct mfi_command *cm,
const char *function, int line)
{
struct mfi_frame_header *hdr;
int i;
uint32_t count = 0, data_len;
hdr = &cm->cm_frame->header;
count = 0;
for (i = 0; i < hdr->sg_count; i++) {
if (hdr->flags & MFI_FRAME_IEEE_SGL)
count += cm->cm_sg->sg_skinny[i].len;
else if (hdr->flags & MFI_FRAME_SGL64)
count += cm->cm_sg->sg64[i].len;
else
count += cm->cm_sg->sg32[i].len;
}
/*
count++;
*/
data_len = hdr->data_len;
switch (hdr->cmd) {
case MFI_CMD_LD_READ:
case MFI_CMD_LD_WRITE:
data_len = data_len * 512;
case MFI_CMD_DCMD:
if (count != data_len) {
device_printf(sc->mfi_dev,
"%s %d COMMAND %p S/G count bad %d %d %d 0x%jx\n",
function, line, cm, count, data_len, cm->cm_len,
(intmax_t)pmap_kextract((vm_offset_t)cm->cm_data));
MFI_PRINT_CMD(cm);
}
}
}
#endif