From patchwork Thu May 16 15:20:07 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ranjan Kumar X-Patchwork-Id: 797633 Received: from mail-pf1-f178.google.com (mail-pf1-f178.google.com [209.85.210.178]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 327321E491 for ; Thu, 16 May 2024 15:23:21 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.178 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715873002; cv=none; b=sboaJ3koPppWDV7DUy6fNBbmAOj64xIefoURJ5Ym+w039JemNsX7fdPbVGxNOzBD/aIlgktz907ppBvY59WuwNHaQAt6M+hz6LSsfROEqdnCOyGEjOzcoZDtd2fTxDmft4jw2KYgBFT+8jWaHKZ7pZbuEVzeWsbfPXPB+CrfMsQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715873002; c=relaxed/simple; bh=tq70WzKwUV8YjAlCXk3Iorq/FUY/lDcwZh3vNx0PyN4=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version:Content-Type; b=i7EGe1GtxPaYVQnRp+Dy4cTIgbd9sdngYeOxwub3HmMCJo0TAwbldk2if725IyPObunW2RUiYZuhiDNu3hpIM8cq8HEBFZgPE0u1KOSqMVU3dCQxoQWf6TQa+1tpG1I1VeOgktnOSBlNSDMNUX5qJm72wJAfhPCkk+sr/LR/UTs= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=broadcom.com; spf=fail smtp.mailfrom=broadcom.com; dkim=pass (1024-bit key) header.d=broadcom.com header.i=@broadcom.com header.b=gSbEP1V+; arc=none smtp.client-ip=209.85.210.178 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=broadcom.com Authentication-Results: smtp.subspace.kernel.org; spf=fail smtp.mailfrom=broadcom.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=broadcom.com header.i=@broadcom.com header.b="gSbEP1V+" Received: by mail-pf1-f178.google.com with SMTP id d2e1a72fcca58-6f472d550cbso316683b3a.1 for ; Thu, 16 May 2024 08:23:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=broadcom.com; s=google; t=1715873000; x=1716477800; darn=vger.kernel.org; h=mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:from:to:cc:subject:date:message-id:reply-to; bh=lJ19t3TfMWThGApJUsiDgNrmXhbHXT7rLnignZ0/Rr0=; b=gSbEP1V+3JsSWBqsO2+Cfyd+a0E2NBcNf6rXpOPfDxmx7j74lDp09MukMyP/ENgM0w Vp/P9y4SgHfmO6j2YP5cD8ne+NTW02CcZMgtpn9QaXpK+bWA4EQXwR95vAarv4H+APaV L0XtAyFCMg1i66i/jGVnmKsleK7RONfm3lNQo= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1715873000; x=1716477800; h=mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=lJ19t3TfMWThGApJUsiDgNrmXhbHXT7rLnignZ0/Rr0=; b=PzsEv2whngJn+gNRfgf8gn93xL8sm49kBtZOySkrHRWNnnWC72sqDGlCaItwGMypya SsZpaA5/v2rmOu4qcF0QJtDmHmqaG1x/wRbF4dQi7BW/WzmnjWmVIA263WfY5EFY094q 2qQ4s0Ppdk2tDYvxsz7kYAlpjSdp36guBFVVnd8bcpSfVbiR8gJg7SAx1BiQm8Gak44F v0KEGRpfjUc4l+oSFPdK/p+GN6ZXfmSlaUGucotesBZ3AiuXSjpwoPn8T1KKIfpe55jP sBHUzfIoLT5Hb/nHgy4VSk+FAAeXCizILkV6i9FiurUbncbn/j9fp6F1r8Le8m0Wb4d4 pbzQ== X-Gm-Message-State: AOJu0Yzd+EGr7bxatwQ6KHO7Kq5c33x3BNsFOp0KIOTstDpN6IXrLIoP QNjBPlO0zok6/CBmrxEUT0VPc4yndomJ/5FOJET1d2EBDrVt1XK0CsR5KY2r6fYZHetKCDB/lLM 8UOin5a+/lN8+VxisKZjF1FoQGTNfDSnQUKSI5n44k2zySLmMzcjIPzIRWzan5tbDpl4f4SuLY0 1dCvi8M7KFyK4z9SoDCV+WdnFzkFleh+6z5mHpkIYGytgPa95d X-Google-Smtp-Source: AGHT+IHtT7cHSB432fkH+45jS0E7kJ7S/0T6ClSJHcucN0y+LWckinDr67YqP1Es7n/FsnK4E6jtuw== X-Received: by 2002:a05:6a20:9f03:b0:1af:d0fe:9094 with SMTP id adf61e73a8af0-1afde085b73mr27913531637.11.1715872999852; Thu, 16 May 2024 08:23:19 -0700 (PDT) Received: from localhost.localdomain ([192.19.234.250]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-6f4d2a83d3dsm13241749b3a.65.2024.05.16.08.23.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 16 May 2024 08:23:18 -0700 (PDT) From: Ranjan Kumar To: linux-scsi@vger.kernel.org, martin.petersen@oracle.com Cc: rajsekhar.chundru@broadcom.com, sathya.prakash@broadcom.com, sumit.saxena@broadcom.com, chandrakanth.patil@broadcom.com, prayas.patel@broadcom.com, Ranjan Kumar , kernel test robot Subject: [PATCH v3 3/6] mpi3mr: Dump driver and dmesg logs into driver diag buffer Date: Thu, 16 May 2024 20:50:07 +0530 Message-Id: <20240516152010.88227-4-ranjan.kumar@broadcom.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20240516152010.88227-1-ranjan.kumar@broadcom.com> References: <20240516152010.88227-1-ranjan.kumar@broadcom.com> Precedence: bulk X-Mailing-List: linux-scsi@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 This patch adds support for collecting the kernel messages based on the driver buffer capture level set in the module parameter and copy the pertinent information to the driver diagnostic buffer posted to the controller. The buffer capture and copy will be executed when the driver detected the controller in the fault state. Reported-by: kernel test robot Closes: https://lore.kernel.org/oe-kbuild-all/202405151829.zc0uNh0u-lkp@intel.com/ Signed-off-by: Sathya Prakash Signed-off-by: Ranjan Kumar --- drivers/scsi/mpi3mr/mpi/mpi30_tool.h | 2 + drivers/scsi/mpi3mr/mpi3mr.h | 5 ++ drivers/scsi/mpi3mr/mpi3mr_fw.c | 124 +++++++++++++++++++++++++++ 3 files changed, 131 insertions(+) diff --git a/drivers/scsi/mpi3mr/mpi/mpi30_tool.h b/drivers/scsi/mpi3mr/mpi/mpi30_tool.h index 495933856006..8b8b6ba00c7b 100644 --- a/drivers/scsi/mpi3mr/mpi/mpi30_tool.h +++ b/drivers/scsi/mpi3mr/mpi/mpi30_tool.h @@ -10,6 +10,8 @@ #define MPI3_DIAG_BUFFER_TYPE_DRIVER (0x10) #define MPI3_DIAG_BUFFER_ACTION_RELEASE (0x01) +#define MPI3_DRIVER_DIAG_BUFFER_HEADER_FLAGS_CIRCULAR_BUF_FORMAT_ASCII (0x00000000) + struct mpi3_diag_buffer_post_request { __le16 host_tag; u8 ioc_use_only02; diff --git a/drivers/scsi/mpi3mr/mpi3mr.h b/drivers/scsi/mpi3mr/mpi3mr.h index dc7e8f461826..b6030a665ec8 100644 --- a/drivers/scsi/mpi3mr/mpi3mr.h +++ b/drivers/scsi/mpi3mr/mpi3mr.h @@ -226,6 +226,10 @@ extern atomic64_t event_counter; #define MPI3MR_WRITE_SAME_MAX_LEN_256_BLKS 256 #define MPI3MR_WRITE_SAME_MAX_LEN_2048_BLKS 2048 +struct mpi3mr_kmsg_dumper { + struct kmsg_dump_iter kdumper; +}; + /* Driver diag buffer levels */ enum mpi3mr_drv_db_level { MRIOC_DRV_DB_DISABLED = 0, @@ -1331,6 +1335,7 @@ struct mpi3mr_ioc { void *drv_diag_buffer; dma_addr_t drv_diag_buffer_dma; u32 drv_diag_buffer_sz; + struct mpi3mr_kmsg_dumper dump; }; /** diff --git a/drivers/scsi/mpi3mr/mpi3mr_fw.c b/drivers/scsi/mpi3mr/mpi3mr_fw.c index 5937054b3cdb..ea489654de81 100644 --- a/drivers/scsi/mpi3mr/mpi3mr_fw.c +++ b/drivers/scsi/mpi3mr/mpi3mr_fw.c @@ -1200,6 +1200,126 @@ static void mpi3mr_alloc_ioctl_dma_memory(struct mpi3mr_ioc *mrioc) mpi3mr_free_ioctl_dma_memory(mrioc); } +/** + * mpi3mr_do_mini_dump - copy system logs associated with mrioc. + * @mrioc: Adapter instance reference + * Read system logs and search for pattern mpi3mr%d and copy the lines + * into driver diag buffer + * + * Return: next available location in driver diag buffer. + */ +static int mpi3mr_do_mini_dump(struct mpi3mr_ioc *mrioc) +{ + int n = 0, lines, pos_mini_dump = 0; + struct mpi3mr_kmsg_dumper dumper; + size_t len; + char buf[201]; + char *mini_start = "<6> Minidump start\n"; + char *mini_end = "<6> Minidump end\n"; + + struct mpi3_driver_buffer_header *drv_buff_header = NULL; + + dumper = mrioc->dump; + + kmsg_dump_rewind(&dumper.kdumper); + while (kmsg_dump_get_line(&dumper.kdumper, 1, NULL, 0, NULL)) + n++; + + lines = n; + kmsg_dump_rewind(&dumper.kdumper); + + drv_buff_header = (struct mpi3_driver_buffer_header *)mrioc->drv_diag_buffer; + drv_buff_header->signature = 0x43495243; + drv_buff_header->logical_buffer_start = 0; + drv_buff_header->circular_buffer_size = + mrioc->drv_diag_buffer_sz - sizeof(struct mpi3_driver_buffer_header); + drv_buff_header->flags = + MPI3_DRIVER_DIAG_BUFFER_HEADER_FLAGS_CIRCULAR_BUF_FORMAT_ASCII; + + if ((pos_mini_dump + strlen(mini_start) + < mrioc->drv_diag_buffer_sz)) { + sprintf((char *)mrioc->drv_diag_buffer + pos_mini_dump, + "%s\n", mini_start); + pos_mini_dump += strlen(mini_start); + } else { + ioc_info(mrioc, "driver diag buffer is full. minidump is not started\n"); + goto out; + } + + while (kmsg_dump_get_line(&dumper.kdumper, 1, buf, sizeof(buf), &len)) { + if (!lines--) + break; + if (strstr(buf, mrioc->name) && + ((pos_mini_dump + len + strlen(mini_end)) + < mrioc->drv_diag_buffer_sz)) { + sprintf((char *)mrioc->drv_diag_buffer + + pos_mini_dump, "%s", buf); + pos_mini_dump += len; + } + } + + if ((pos_mini_dump + strlen(mini_end) + < mrioc->drv_diag_buffer_sz)) { + sprintf((char *)mrioc->drv_diag_buffer + pos_mini_dump, + "%s\n", mini_end); + pos_mini_dump += strlen(mini_end); + } + +out: + drv_buff_header->logical_buffer_end = + pos_mini_dump - sizeof(struct mpi3_driver_buffer_header); + + ioc_info(mrioc, "driver diag buffer base_address(including 4K header) 0x%016llx, end_address 0x%016llx\n", + (unsigned long long)mrioc->drv_diag_buffer_dma, + (unsigned long long)mrioc->drv_diag_buffer_dma + + mrioc->drv_diag_buffer_sz); + ioc_info(mrioc, "logical_buffer end_address 0x%016llx, logical_buffer_end 0x%08x\n", + (unsigned long long)mrioc->drv_diag_buffer_dma + + drv_buff_header->logical_buffer_end, + drv_buff_header->logical_buffer_end); + + return pos_mini_dump; +} + +/** + * mpi3mr_do_dump - copy system logs into driver diag buffer. + * @mrioc: Adapter instance reference + * + * Return: Nothing. + */ +static void mpi3mr_do_dump(struct mpi3mr_ioc *mrioc) +{ + int offset = 0; + size_t dump_size; + struct mpi3_driver_buffer_header *drv_buff_header = NULL; + + if (!mrioc->drv_diag_buffer) + return; + + memset(mrioc->drv_diag_buffer, 0, mrioc->drv_diag_buffer_sz); + + if (drv_db_level == MRIOC_DRV_DB_DISABLED) + return; + + /* Copy controller specific logs */ + offset += mpi3mr_do_mini_dump(mrioc); + if (drv_db_level != MRIOC_DRV_DB_FULL) + return; + + kmsg_dump_rewind(&mrioc->dump.kdumper); + kmsg_dump_get_buffer(&mrioc->dump.kdumper, true, + mrioc->drv_diag_buffer + offset, + mrioc->drv_diag_buffer_sz - offset, &dump_size); + + drv_buff_header = (struct mpi3_driver_buffer_header *) + mrioc->drv_diag_buffer; + drv_buff_header->logical_buffer_end += dump_size; + ioc_info(mrioc, "logical_buffer end_address(0x%016llx), logical_buffer_end(0x%08x)\n", + (unsigned long long)mrioc->drv_diag_buffer_dma + + drv_buff_header->logical_buffer_end, + drv_buff_header->logical_buffer_end); +} + /** * mpi3mr_clear_reset_history - clear reset history * @mrioc: Adapter instance reference @@ -2767,6 +2887,7 @@ static void mpi3mr_watchdog_work(struct work_struct *work) if (!mrioc->diagsave_timeout) { mpi3mr_print_fault_info(mrioc); ioc_warn(mrioc, "diag save in progress\n"); + mpi3mr_do_dump(mrioc); } if ((mrioc->diagsave_timeout++) <= MPI3_SYSIF_DIAG_SAVE_TIMEOUT) goto schedule_work; @@ -5311,6 +5432,9 @@ int mpi3mr_soft_reset_handler(struct mpi3mr_ioc *mrioc, mpi3mr_ioc_disable_intr(mrioc); if (snapdump) { + dprint_reset(mrioc, + "soft_reset_handler: saving snapdump\n"); + mpi3mr_do_dump(mrioc); mpi3mr_set_diagsave(mrioc); retval = mpi3mr_issue_reset(mrioc, MPI3_SYSIF_HOST_DIAG_RESET_ACTION_DIAG_FAULT, reset_reason);