2012-05-29 15:51:17 +04:00
|
|
|
/*
|
|
|
|
* QEMU MegaRAID SAS 8708EM2 Host Bus Adapter emulation
|
|
|
|
* Based on the linux driver code at drivers/scsi/megaraid
|
|
|
|
*
|
|
|
|
* Copyright (c) 2009-2012 Hannes Reinecke, SUSE Labs
|
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
2020-10-23 15:44:24 +03:00
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
2012-05-29 15:51:17 +04:00
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library; if not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
2016-01-26 21:17:16 +03:00
|
|
|
#include "qemu/osdep.h"
|
2013-02-04 18:40:22 +04:00
|
|
|
#include "hw/pci/pci.h"
|
2019-08-12 08:23:51 +03:00
|
|
|
#include "hw/qdev-properties.h"
|
2012-12-17 21:20:04 +04:00
|
|
|
#include "sysemu/dma.h"
|
2014-10-07 15:59:18 +04:00
|
|
|
#include "sysemu/block-backend.h"
|
2021-11-29 23:55:05 +03:00
|
|
|
#include "sysemu/rtc.h"
|
2014-04-16 18:44:15 +04:00
|
|
|
#include "hw/pci/msi.h"
|
2013-02-04 18:40:22 +04:00
|
|
|
#include "hw/pci/msix.h"
|
2012-12-17 21:20:00 +04:00
|
|
|
#include "qemu/iov.h"
|
2019-05-23 17:35:07 +03:00
|
|
|
#include "qemu/module.h"
|
2022-02-08 23:08:56 +03:00
|
|
|
#include "qemu/hw-version.h"
|
2013-02-05 20:06:20 +04:00
|
|
|
#include "hw/scsi/scsi.h"
|
2017-08-22 10:23:55 +03:00
|
|
|
#include "scsi/constants.h"
|
2012-05-29 15:51:17 +04:00
|
|
|
#include "trace.h"
|
2016-06-20 09:13:39 +03:00
|
|
|
#include "qapi/error.h"
|
2013-03-18 20:36:02 +04:00
|
|
|
#include "mfi.h"
|
2019-08-12 08:23:45 +03:00
|
|
|
#include "migration/vmstate.h"
|
2020-09-03 23:43:22 +03:00
|
|
|
#include "qom/object.h"
|
2012-05-29 15:51:17 +04:00
|
|
|
|
2014-10-29 15:00:08 +03:00
|
|
|
#define MEGASAS_VERSION_GEN1 "1.70"
|
|
|
|
#define MEGASAS_VERSION_GEN2 "1.80"
|
2012-05-29 15:51:17 +04:00
|
|
|
#define MEGASAS_MAX_FRAMES 2048 /* Firmware limit at 65535 */
|
|
|
|
#define MEGASAS_DEFAULT_FRAMES 1000 /* Windows requires this */
|
2014-10-29 15:00:08 +03:00
|
|
|
#define MEGASAS_GEN2_DEFAULT_FRAMES 1008 /* Windows requires this */
|
2019-12-17 20:34:00 +03:00
|
|
|
#define MEGASAS_MIN_SGE 64
|
2012-05-29 15:51:17 +04:00
|
|
|
#define MEGASAS_MAX_SGE 128 /* Firmware limit */
|
|
|
|
#define MEGASAS_DEFAULT_SGE 80
|
|
|
|
#define MEGASAS_MAX_SECTORS 0xFFFF /* No real limit */
|
|
|
|
#define MEGASAS_MAX_ARRAYS 128
|
|
|
|
|
2012-08-24 14:36:41 +04:00
|
|
|
#define MEGASAS_HBA_SERIAL "QEMU123456"
|
2012-08-01 14:46:50 +04:00
|
|
|
#define NAA_LOCALLY_ASSIGNED_ID 0x3ULL
|
|
|
|
#define IEEE_COMPANY_LOCALLY_ASSIGNED 0x525400
|
|
|
|
|
2012-05-29 15:51:17 +04:00
|
|
|
#define MEGASAS_FLAG_USE_JBOD 0
|
|
|
|
#define MEGASAS_MASK_USE_JBOD (1 << MEGASAS_FLAG_USE_JBOD)
|
2016-06-20 09:13:37 +03:00
|
|
|
#define MEGASAS_FLAG_USE_QUEUE64 1
|
2012-05-29 15:51:17 +04:00
|
|
|
#define MEGASAS_MASK_USE_QUEUE64 (1 << MEGASAS_FLAG_USE_QUEUE64)
|
|
|
|
|
|
|
|
typedef struct MegasasCmd {
|
|
|
|
uint32_t index;
|
|
|
|
uint16_t flags;
|
|
|
|
uint16_t count;
|
|
|
|
uint64_t context;
|
|
|
|
|
2012-10-23 14:30:10 +04:00
|
|
|
hwaddr pa;
|
|
|
|
hwaddr pa_size;
|
2017-06-01 18:18:23 +03:00
|
|
|
uint32_t dcmd_opcode;
|
2012-05-29 15:51:17 +04:00
|
|
|
union mfi_frame *frame;
|
|
|
|
SCSIRequest *req;
|
|
|
|
QEMUSGList qsg;
|
|
|
|
void *iov_buf;
|
|
|
|
size_t iov_size;
|
|
|
|
size_t iov_offset;
|
|
|
|
struct MegasasState *state;
|
|
|
|
} MegasasCmd;
|
|
|
|
|
2020-09-03 23:43:22 +03:00
|
|
|
struct MegasasState {
|
2013-06-30 16:02:53 +04:00
|
|
|
/*< private >*/
|
|
|
|
PCIDevice parent_obj;
|
|
|
|
/*< public >*/
|
|
|
|
|
2012-05-29 15:51:17 +04:00
|
|
|
MemoryRegion mmio_io;
|
|
|
|
MemoryRegion port_io;
|
|
|
|
MemoryRegion queue_io;
|
|
|
|
uint32_t frame_hi;
|
|
|
|
|
2020-05-13 22:25:40 +03:00
|
|
|
uint32_t fw_state;
|
2012-05-29 15:51:17 +04:00
|
|
|
uint32_t fw_sge;
|
|
|
|
uint32_t fw_cmds;
|
|
|
|
uint32_t flags;
|
2020-05-13 22:25:40 +03:00
|
|
|
uint32_t fw_luns;
|
|
|
|
uint32_t intr_mask;
|
|
|
|
uint32_t doorbell;
|
|
|
|
uint32_t busy;
|
|
|
|
uint32_t diag;
|
|
|
|
uint32_t adp_reset;
|
2016-06-20 09:13:37 +03:00
|
|
|
OnOffAuto msi;
|
|
|
|
OnOffAuto msix;
|
2012-05-29 15:51:17 +04:00
|
|
|
|
|
|
|
MegasasCmd *event_cmd;
|
2020-05-13 22:25:40 +03:00
|
|
|
uint16_t event_locale;
|
2012-05-29 15:51:17 +04:00
|
|
|
int event_class;
|
2020-05-13 22:25:40 +03:00
|
|
|
uint32_t event_count;
|
|
|
|
uint32_t shutdown_event;
|
|
|
|
uint32_t boot_event;
|
2012-05-29 15:51:17 +04:00
|
|
|
|
2012-08-01 14:46:50 +04:00
|
|
|
uint64_t sas_addr;
|
2012-08-24 14:36:41 +04:00
|
|
|
char *hba_serial;
|
2012-08-01 14:46:50 +04:00
|
|
|
|
2012-05-29 15:51:17 +04:00
|
|
|
uint64_t reply_queue_pa;
|
|
|
|
void *reply_queue;
|
2020-05-13 22:25:40 +03:00
|
|
|
uint16_t reply_queue_len;
|
2021-12-18 00:43:05 +03:00
|
|
|
uint32_t reply_queue_head;
|
|
|
|
uint32_t reply_queue_tail;
|
2012-05-29 15:51:17 +04:00
|
|
|
uint64_t consumer_pa;
|
|
|
|
uint64_t producer_pa;
|
|
|
|
|
|
|
|
MegasasCmd frames[MEGASAS_MAX_FRAMES];
|
2014-10-29 15:00:15 +03:00
|
|
|
DECLARE_BITMAP(frame_map, MEGASAS_MAX_FRAMES);
|
2012-05-29 15:51:17 +04:00
|
|
|
SCSIBus bus;
|
2020-09-03 23:43:22 +03:00
|
|
|
};
|
|
|
|
typedef struct MegasasState MegasasState;
|
2012-05-29 15:51:17 +04:00
|
|
|
|
2020-09-03 23:43:22 +03:00
|
|
|
struct MegasasBaseClass {
|
2014-10-29 15:00:08 +03:00
|
|
|
PCIDeviceClass parent_class;
|
|
|
|
const char *product_name;
|
|
|
|
const char *product_version;
|
|
|
|
int mmio_bar;
|
|
|
|
int ioport_bar;
|
|
|
|
int osts;
|
2020-09-03 23:43:22 +03:00
|
|
|
};
|
|
|
|
typedef struct MegasasBaseClass MegasasBaseClass;
|
2014-10-29 15:00:08 +03:00
|
|
|
|
|
|
|
#define TYPE_MEGASAS_BASE "megasas-base"
|
|
|
|
#define TYPE_MEGASAS_GEN1 "megasas"
|
|
|
|
#define TYPE_MEGASAS_GEN2 "megasas-gen2"
|
2013-06-24 10:54:15 +04:00
|
|
|
|
2020-09-01 00:07:33 +03:00
|
|
|
DECLARE_OBJ_CHECKERS(MegasasState, MegasasBaseClass,
|
|
|
|
MEGASAS, TYPE_MEGASAS_BASE)
|
2014-10-29 15:00:08 +03:00
|
|
|
|
2013-06-24 10:54:15 +04:00
|
|
|
|
2012-05-29 15:51:17 +04:00
|
|
|
#define MEGASAS_INTR_DISABLED_MASK 0xFFFFFFFF
|
|
|
|
|
|
|
|
static bool megasas_intr_enabled(MegasasState *s)
|
|
|
|
{
|
|
|
|
if ((s->intr_mask & MEGASAS_INTR_DISABLED_MASK) !=
|
|
|
|
MEGASAS_INTR_DISABLED_MASK) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool megasas_use_queue64(MegasasState *s)
|
|
|
|
{
|
|
|
|
return s->flags & MEGASAS_MASK_USE_QUEUE64;
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool megasas_use_msix(MegasasState *s)
|
|
|
|
{
|
2016-06-20 09:13:37 +03:00
|
|
|
return s->msix != ON_OFF_AUTO_OFF;
|
2012-05-29 15:51:17 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
static bool megasas_is_jbod(MegasasState *s)
|
|
|
|
{
|
|
|
|
return s->flags & MEGASAS_MASK_USE_JBOD;
|
|
|
|
}
|
|
|
|
|
2015-03-23 19:15:17 +03:00
|
|
|
static void megasas_frame_set_cmd_status(MegasasState *s,
|
|
|
|
unsigned long frame, uint8_t v)
|
2012-05-29 15:51:17 +04:00
|
|
|
{
|
2015-03-23 19:15:17 +03:00
|
|
|
PCIDevice *pci = &s->parent_obj;
|
2021-12-18 00:39:42 +03:00
|
|
|
stb_pci_dma(pci, frame + offsetof(struct mfi_frame_header, cmd_status),
|
|
|
|
v, MEMTXATTRS_UNSPECIFIED);
|
2012-05-29 15:51:17 +04:00
|
|
|
}
|
|
|
|
|
2015-03-23 19:15:17 +03:00
|
|
|
static void megasas_frame_set_scsi_status(MegasasState *s,
|
|
|
|
unsigned long frame, uint8_t v)
|
2012-05-29 15:51:17 +04:00
|
|
|
{
|
2015-03-23 19:15:17 +03:00
|
|
|
PCIDevice *pci = &s->parent_obj;
|
2021-12-18 00:39:42 +03:00
|
|
|
stb_pci_dma(pci, frame + offsetof(struct mfi_frame_header, scsi_status),
|
|
|
|
v, MEMTXATTRS_UNSPECIFIED);
|
2012-05-29 15:51:17 +04:00
|
|
|
}
|
|
|
|
|
2020-06-15 10:26:29 +03:00
|
|
|
static inline const char *mfi_frame_desc(unsigned int cmd)
|
|
|
|
{
|
|
|
|
static const char *mfi_frame_descs[] = {
|
|
|
|
"MFI init", "LD Read", "LD Write", "LD SCSI", "PD SCSI",
|
|
|
|
"MFI Doorbell", "MFI Abort", "MFI SMP", "MFI Stop"
|
|
|
|
};
|
|
|
|
|
|
|
|
if (cmd < ARRAY_SIZE(mfi_frame_descs)) {
|
|
|
|
return mfi_frame_descs[cmd];
|
|
|
|
}
|
|
|
|
|
|
|
|
return "Unknown";
|
|
|
|
}
|
|
|
|
|
2012-05-29 15:51:17 +04:00
|
|
|
/*
|
|
|
|
* Context is considered opaque, but the HBA firmware is running
|
|
|
|
* in little endian mode. So convert it to little endian, too.
|
|
|
|
*/
|
2015-03-23 19:15:17 +03:00
|
|
|
static uint64_t megasas_frame_get_context(MegasasState *s,
|
|
|
|
unsigned long frame)
|
2012-05-29 15:51:17 +04:00
|
|
|
{
|
2015-03-23 19:15:17 +03:00
|
|
|
PCIDevice *pci = &s->parent_obj;
|
2021-12-18 01:49:30 +03:00
|
|
|
uint64_t val;
|
|
|
|
|
|
|
|
ldq_le_pci_dma(pci, frame + offsetof(struct mfi_frame_header, context),
|
|
|
|
&val, MEMTXATTRS_UNSPECIFIED);
|
|
|
|
|
|
|
|
return val;
|
2012-05-29 15:51:17 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
static bool megasas_frame_is_ieee_sgl(MegasasCmd *cmd)
|
|
|
|
{
|
|
|
|
return cmd->flags & MFI_FRAME_IEEE_SGL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool megasas_frame_is_sgl64(MegasasCmd *cmd)
|
|
|
|
{
|
|
|
|
return cmd->flags & MFI_FRAME_SGL64;
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool megasas_frame_is_sense64(MegasasCmd *cmd)
|
|
|
|
{
|
|
|
|
return cmd->flags & MFI_FRAME_SENSE64;
|
|
|
|
}
|
|
|
|
|
|
|
|
static uint64_t megasas_sgl_get_addr(MegasasCmd *cmd,
|
|
|
|
union mfi_sgl *sgl)
|
|
|
|
{
|
|
|
|
uint64_t addr;
|
|
|
|
|
|
|
|
if (megasas_frame_is_ieee_sgl(cmd)) {
|
|
|
|
addr = le64_to_cpu(sgl->sg_skinny->addr);
|
|
|
|
} else if (megasas_frame_is_sgl64(cmd)) {
|
|
|
|
addr = le64_to_cpu(sgl->sg64->addr);
|
|
|
|
} else {
|
|
|
|
addr = le32_to_cpu(sgl->sg32->addr);
|
|
|
|
}
|
|
|
|
return addr;
|
|
|
|
}
|
|
|
|
|
|
|
|
static uint32_t megasas_sgl_get_len(MegasasCmd *cmd,
|
|
|
|
union mfi_sgl *sgl)
|
|
|
|
{
|
|
|
|
uint32_t len;
|
|
|
|
|
|
|
|
if (megasas_frame_is_ieee_sgl(cmd)) {
|
|
|
|
len = le32_to_cpu(sgl->sg_skinny->len);
|
|
|
|
} else if (megasas_frame_is_sgl64(cmd)) {
|
|
|
|
len = le32_to_cpu(sgl->sg64->len);
|
|
|
|
} else {
|
|
|
|
len = le32_to_cpu(sgl->sg32->len);
|
|
|
|
}
|
|
|
|
return len;
|
|
|
|
}
|
|
|
|
|
|
|
|
static union mfi_sgl *megasas_sgl_next(MegasasCmd *cmd,
|
|
|
|
union mfi_sgl *sgl)
|
|
|
|
{
|
|
|
|
uint8_t *next = (uint8_t *)sgl;
|
|
|
|
|
|
|
|
if (megasas_frame_is_ieee_sgl(cmd)) {
|
|
|
|
next += sizeof(struct mfi_sg_skinny);
|
|
|
|
} else if (megasas_frame_is_sgl64(cmd)) {
|
|
|
|
next += sizeof(struct mfi_sg64);
|
|
|
|
} else {
|
|
|
|
next += sizeof(struct mfi_sg32);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (next >= (uint8_t *)cmd->frame + cmd->pa_size) {
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
return (union mfi_sgl *)next;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void megasas_soft_reset(MegasasState *s);
|
|
|
|
|
|
|
|
static int megasas_map_sgl(MegasasState *s, MegasasCmd *cmd, union mfi_sgl *sgl)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
int iov_count = 0;
|
|
|
|
size_t iov_size = 0;
|
|
|
|
|
|
|
|
cmd->flags = le16_to_cpu(cmd->frame->header.flags);
|
|
|
|
iov_count = cmd->frame->header.sge_count;
|
2020-08-15 17:19:40 +03:00
|
|
|
if (!iov_count || iov_count > MEGASAS_MAX_SGE) {
|
2012-05-29 15:51:17 +04:00
|
|
|
trace_megasas_iovec_sgl_overflow(cmd->index, iov_count,
|
|
|
|
MEGASAS_MAX_SGE);
|
2020-08-15 17:19:39 +03:00
|
|
|
return -1;
|
2012-05-29 15:51:17 +04:00
|
|
|
}
|
2013-06-30 16:02:53 +04:00
|
|
|
pci_dma_sglist_init(&cmd->qsg, PCI_DEVICE(s), iov_count);
|
2012-05-29 15:51:17 +04:00
|
|
|
for (i = 0; i < iov_count; i++) {
|
|
|
|
dma_addr_t iov_pa, iov_size_p;
|
|
|
|
|
|
|
|
if (!sgl) {
|
|
|
|
trace_megasas_iovec_sgl_underflow(cmd->index, i);
|
|
|
|
goto unmap;
|
|
|
|
}
|
|
|
|
iov_pa = megasas_sgl_get_addr(cmd, sgl);
|
|
|
|
iov_size_p = megasas_sgl_get_len(cmd, sgl);
|
|
|
|
if (!iov_pa || !iov_size_p) {
|
|
|
|
trace_megasas_iovec_sgl_invalid(cmd->index, i,
|
|
|
|
iov_pa, iov_size_p);
|
|
|
|
goto unmap;
|
|
|
|
}
|
|
|
|
qemu_sglist_add(&cmd->qsg, iov_pa, iov_size_p);
|
|
|
|
sgl = megasas_sgl_next(cmd, sgl);
|
|
|
|
iov_size += (size_t)iov_size_p;
|
|
|
|
}
|
|
|
|
if (cmd->iov_size > iov_size) {
|
|
|
|
trace_megasas_iovec_overflow(cmd->index, iov_size, cmd->iov_size);
|
2021-11-19 23:11:40 +03:00
|
|
|
goto unmap;
|
2012-05-29 15:51:17 +04:00
|
|
|
} else if (cmd->iov_size < iov_size) {
|
2017-03-13 22:55:19 +03:00
|
|
|
trace_megasas_iovec_underflow(cmd->index, iov_size, cmd->iov_size);
|
2012-05-29 15:51:17 +04:00
|
|
|
}
|
|
|
|
cmd->iov_offset = 0;
|
|
|
|
return 0;
|
|
|
|
unmap:
|
|
|
|
qemu_sglist_destroy(&cmd->qsg);
|
2020-08-15 17:19:39 +03:00
|
|
|
return -1;
|
2012-05-29 15:51:17 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* passthrough sense and io sense are at the same offset
|
|
|
|
*/
|
|
|
|
static int megasas_build_sense(MegasasCmd *cmd, uint8_t *sense_ptr,
|
|
|
|
uint8_t sense_len)
|
|
|
|
{
|
2014-06-13 19:26:13 +04:00
|
|
|
PCIDevice *pcid = PCI_DEVICE(cmd->state);
|
2012-05-29 15:51:17 +04:00
|
|
|
uint32_t pa_hi = 0, pa_lo;
|
2012-10-23 14:30:10 +04:00
|
|
|
hwaddr pa;
|
2017-06-01 18:18:39 +03:00
|
|
|
int frame_sense_len;
|
2012-05-29 15:51:17 +04:00
|
|
|
|
2017-06-01 18:18:39 +03:00
|
|
|
frame_sense_len = cmd->frame->header.sense_len;
|
|
|
|
if (sense_len > frame_sense_len) {
|
|
|
|
sense_len = frame_sense_len;
|
2012-05-29 15:51:17 +04:00
|
|
|
}
|
|
|
|
if (sense_len) {
|
|
|
|
pa_lo = le32_to_cpu(cmd->frame->pass.sense_addr_lo);
|
|
|
|
if (megasas_frame_is_sense64(cmd)) {
|
|
|
|
pa_hi = le32_to_cpu(cmd->frame->pass.sense_addr_hi);
|
|
|
|
}
|
|
|
|
pa = ((uint64_t) pa_hi << 32) | pa_lo;
|
2014-06-13 19:26:13 +04:00
|
|
|
pci_dma_write(pcid, pa, sense_ptr, sense_len);
|
2012-05-29 15:51:17 +04:00
|
|
|
cmd->frame->header.sense_len = sense_len;
|
|
|
|
}
|
|
|
|
return sense_len;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void megasas_write_sense(MegasasCmd *cmd, SCSISense sense)
|
|
|
|
{
|
|
|
|
uint8_t sense_buf[SCSI_SENSE_BUF_SIZE];
|
|
|
|
uint8_t sense_len = 18;
|
|
|
|
|
|
|
|
memset(sense_buf, 0, sense_len);
|
|
|
|
sense_buf[0] = 0xf0;
|
|
|
|
sense_buf[2] = sense.key;
|
|
|
|
sense_buf[7] = 10;
|
|
|
|
sense_buf[12] = sense.asc;
|
|
|
|
sense_buf[13] = sense.ascq;
|
|
|
|
megasas_build_sense(cmd, sense_buf, sense_len);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void megasas_copy_sense(MegasasCmd *cmd)
|
|
|
|
{
|
|
|
|
uint8_t sense_buf[SCSI_SENSE_BUF_SIZE];
|
|
|
|
uint8_t sense_len;
|
|
|
|
|
|
|
|
sense_len = scsi_req_get_sense(cmd->req, sense_buf,
|
|
|
|
SCSI_SENSE_BUF_SIZE);
|
|
|
|
megasas_build_sense(cmd, sense_buf, sense_len);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Format an INQUIRY CDB
|
|
|
|
*/
|
|
|
|
static int megasas_setup_inquiry(uint8_t *cdb, int pg, int len)
|
|
|
|
{
|
|
|
|
memset(cdb, 0, 6);
|
|
|
|
cdb[0] = INQUIRY;
|
|
|
|
if (pg > 0) {
|
|
|
|
cdb[1] = 0x1;
|
|
|
|
cdb[2] = pg;
|
|
|
|
}
|
2021-12-18 14:19:12 +03:00
|
|
|
stw_be_p(&cdb[3], len);
|
2012-05-29 15:51:17 +04:00
|
|
|
return len;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Encode lba and len into a READ_16/WRITE_16 CDB
|
|
|
|
*/
|
|
|
|
static void megasas_encode_lba(uint8_t *cdb, uint64_t lba,
|
|
|
|
uint32_t len, bool is_write)
|
|
|
|
{
|
|
|
|
memset(cdb, 0x0, 16);
|
|
|
|
if (is_write) {
|
|
|
|
cdb[0] = WRITE_16;
|
|
|
|
} else {
|
|
|
|
cdb[0] = READ_16;
|
|
|
|
}
|
2021-12-18 14:19:12 +03:00
|
|
|
stq_be_p(&cdb[2], lba);
|
|
|
|
stl_be_p(&cdb[2 + 8], len);
|
2012-05-29 15:51:17 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Utility functions
|
|
|
|
*/
|
|
|
|
static uint64_t megasas_fw_time(void)
|
|
|
|
{
|
|
|
|
struct tm curtime;
|
|
|
|
|
|
|
|
qemu_get_timedate(&curtime, 0);
|
2016-06-14 00:57:58 +03:00
|
|
|
return ((uint64_t)curtime.tm_sec & 0xff) << 48 |
|
2012-05-29 15:51:17 +04:00
|
|
|
((uint64_t)curtime.tm_min & 0xff) << 40 |
|
|
|
|
((uint64_t)curtime.tm_hour & 0xff) << 32 |
|
|
|
|
((uint64_t)curtime.tm_mday & 0xff) << 24 |
|
|
|
|
((uint64_t)curtime.tm_mon & 0xff) << 16 |
|
|
|
|
((uint64_t)(curtime.tm_year + 1900) & 0xffff);
|
|
|
|
}
|
|
|
|
|
2012-08-01 14:46:50 +04:00
|
|
|
/*
|
|
|
|
* Default disk sata address
|
|
|
|
* 0x1221 is the magic number as
|
|
|
|
* present in real hardware,
|
|
|
|
* so use it here, too.
|
|
|
|
*/
|
|
|
|
static uint64_t megasas_get_sata_addr(uint16_t id)
|
2012-05-29 15:51:17 +04:00
|
|
|
{
|
2012-08-01 14:46:50 +04:00
|
|
|
uint64_t addr = (0x1221ULL << 48);
|
2015-09-30 20:21:10 +03:00
|
|
|
return addr | ((uint64_t)id << 24);
|
2012-05-29 15:51:17 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Frame handling
|
|
|
|
*/
|
|
|
|
static int megasas_next_index(MegasasState *s, int index, int limit)
|
|
|
|
{
|
|
|
|
index++;
|
|
|
|
if (index == limit) {
|
|
|
|
index = 0;
|
|
|
|
}
|
|
|
|
return index;
|
|
|
|
}
|
|
|
|
|
|
|
|
static MegasasCmd *megasas_lookup_frame(MegasasState *s,
|
2012-10-23 14:30:10 +04:00
|
|
|
hwaddr frame)
|
2012-05-29 15:51:17 +04:00
|
|
|
{
|
|
|
|
MegasasCmd *cmd = NULL;
|
|
|
|
int num = 0, index;
|
|
|
|
|
|
|
|
index = s->reply_queue_head;
|
|
|
|
|
2020-05-13 22:25:38 +03:00
|
|
|
while (num < s->fw_cmds && index < MEGASAS_MAX_FRAMES) {
|
2012-05-29 15:51:17 +04:00
|
|
|
if (s->frames[index].pa && s->frames[index].pa == frame) {
|
|
|
|
cmd = &s->frames[index];
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
index = megasas_next_index(s, index, s->fw_cmds);
|
|
|
|
num++;
|
|
|
|
}
|
|
|
|
|
|
|
|
return cmd;
|
|
|
|
}
|
|
|
|
|
2014-10-29 15:00:15 +03:00
|
|
|
static void megasas_unmap_frame(MegasasState *s, MegasasCmd *cmd)
|
2012-05-29 15:51:17 +04:00
|
|
|
{
|
2014-10-29 15:00:15 +03:00
|
|
|
PCIDevice *p = PCI_DEVICE(s);
|
2012-05-29 15:51:17 +04:00
|
|
|
|
2016-09-16 01:36:58 +03:00
|
|
|
if (cmd->pa_size) {
|
|
|
|
pci_dma_unmap(p, cmd->frame, cmd->pa_size, 0, 0);
|
|
|
|
}
|
2014-10-29 15:00:15 +03:00
|
|
|
cmd->frame = NULL;
|
|
|
|
cmd->pa = 0;
|
2016-09-16 01:36:58 +03:00
|
|
|
cmd->pa_size = 0;
|
2018-08-14 17:12:46 +03:00
|
|
|
qemu_sglist_destroy(&cmd->qsg);
|
2014-10-29 15:00:15 +03:00
|
|
|
clear_bit(cmd->index, s->frame_map);
|
2012-05-29 15:51:17 +04:00
|
|
|
}
|
|
|
|
|
2014-10-29 15:00:15 +03:00
|
|
|
/*
|
|
|
|
* This absolutely needs to be locked if
|
|
|
|
* qemu ever goes multithreaded.
|
|
|
|
*/
|
2012-05-29 15:51:17 +04:00
|
|
|
static MegasasCmd *megasas_enqueue_frame(MegasasState *s,
|
2012-10-23 14:30:10 +04:00
|
|
|
hwaddr frame, uint64_t context, int count)
|
2012-05-29 15:51:17 +04:00
|
|
|
{
|
2014-06-13 19:26:13 +04:00
|
|
|
PCIDevice *pcid = PCI_DEVICE(s);
|
2012-05-29 15:51:17 +04:00
|
|
|
MegasasCmd *cmd = NULL;
|
2019-04-04 15:10:15 +03:00
|
|
|
int frame_size = MEGASAS_MAX_SGE * sizeof(union mfi_sgl);
|
2012-10-23 14:30:10 +04:00
|
|
|
hwaddr frame_size_p = frame_size;
|
2014-10-29 15:00:15 +03:00
|
|
|
unsigned long index;
|
2012-05-29 15:51:17 +04:00
|
|
|
|
2014-10-29 15:00:15 +03:00
|
|
|
index = 0;
|
|
|
|
while (index < s->fw_cmds) {
|
|
|
|
index = find_next_zero_bit(s->frame_map, s->fw_cmds, index);
|
|
|
|
if (!s->frames[index].pa)
|
|
|
|
break;
|
|
|
|
/* Busy frame found */
|
|
|
|
trace_megasas_qf_mapped(index);
|
|
|
|
}
|
|
|
|
if (index >= s->fw_cmds) {
|
|
|
|
/* All frames busy */
|
|
|
|
trace_megasas_qf_busy(frame);
|
2012-05-29 15:51:17 +04:00
|
|
|
return NULL;
|
|
|
|
}
|
2014-10-29 15:00:15 +03:00
|
|
|
cmd = &s->frames[index];
|
|
|
|
set_bit(index, s->frame_map);
|
|
|
|
trace_megasas_qf_new(index, frame);
|
|
|
|
|
|
|
|
cmd->pa = frame;
|
|
|
|
/* Map all possible frames */
|
|
|
|
cmd->frame = pci_dma_map(pcid, frame, &frame_size_p, 0);
|
2020-05-13 22:25:39 +03:00
|
|
|
if (!cmd->frame || frame_size_p != frame_size) {
|
2014-10-29 15:00:15 +03:00
|
|
|
trace_megasas_qf_map_failed(cmd->index, (unsigned long)frame);
|
|
|
|
if (cmd->frame) {
|
|
|
|
megasas_unmap_frame(s, cmd);
|
2012-05-29 15:51:17 +04:00
|
|
|
}
|
2014-10-29 15:00:15 +03:00
|
|
|
s->event_count++;
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
cmd->pa_size = frame_size_p;
|
|
|
|
cmd->context = context;
|
|
|
|
if (!megasas_use_queue64(s)) {
|
|
|
|
cmd->context &= (uint64_t)0xFFFFFFFF;
|
2012-05-29 15:51:17 +04:00
|
|
|
}
|
|
|
|
cmd->count = count;
|
2017-06-01 18:18:23 +03:00
|
|
|
cmd->dcmd_opcode = -1;
|
2012-05-29 15:51:17 +04:00
|
|
|
s->busy++;
|
|
|
|
|
2014-10-29 15:00:14 +03:00
|
|
|
if (s->consumer_pa) {
|
2021-12-18 01:49:30 +03:00
|
|
|
ldl_le_pci_dma(pcid, s->consumer_pa, &s->reply_queue_tail,
|
|
|
|
MEMTXATTRS_UNSPECIFIED);
|
2014-10-29 15:00:14 +03:00
|
|
|
}
|
2012-05-29 15:51:17 +04:00
|
|
|
trace_megasas_qf_enqueue(cmd->index, cmd->count, cmd->context,
|
2014-10-29 15:00:14 +03:00
|
|
|
s->reply_queue_head, s->reply_queue_tail, s->busy);
|
2012-05-29 15:51:17 +04:00
|
|
|
|
|
|
|
return cmd;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void megasas_complete_frame(MegasasState *s, uint64_t context)
|
|
|
|
{
|
2021-12-18 00:39:42 +03:00
|
|
|
const MemTxAttrs attrs = MEMTXATTRS_UNSPECIFIED;
|
2013-06-30 16:02:53 +04:00
|
|
|
PCIDevice *pci_dev = PCI_DEVICE(s);
|
2012-05-29 15:51:17 +04:00
|
|
|
int tail, queue_offset;
|
|
|
|
|
|
|
|
/* Decrement busy count */
|
|
|
|
s->busy--;
|
|
|
|
if (s->reply_queue_pa) {
|
|
|
|
/*
|
|
|
|
* Put command on the reply queue.
|
|
|
|
* Context is opaque, but emulation is running in
|
|
|
|
* little endian. So convert it.
|
|
|
|
*/
|
|
|
|
if (megasas_use_queue64(s)) {
|
2014-10-29 15:00:16 +03:00
|
|
|
queue_offset = s->reply_queue_head * sizeof(uint64_t);
|
2021-12-18 00:39:42 +03:00
|
|
|
stq_le_pci_dma(pci_dev, s->reply_queue_pa + queue_offset,
|
|
|
|
context, attrs);
|
2012-05-29 15:51:17 +04:00
|
|
|
} else {
|
2014-10-29 15:00:16 +03:00
|
|
|
queue_offset = s->reply_queue_head * sizeof(uint32_t);
|
2021-12-18 00:39:42 +03:00
|
|
|
stl_le_pci_dma(pci_dev, s->reply_queue_pa + queue_offset,
|
|
|
|
context, attrs);
|
2012-05-29 15:51:17 +04:00
|
|
|
}
|
2021-12-18 01:49:30 +03:00
|
|
|
ldl_le_pci_dma(pci_dev, s->consumer_pa, &s->reply_queue_tail, attrs);
|
2014-10-29 15:00:14 +03:00
|
|
|
trace_megasas_qf_complete(context, s->reply_queue_head,
|
2014-10-29 15:00:16 +03:00
|
|
|
s->reply_queue_tail, s->busy);
|
2012-05-29 15:51:17 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
if (megasas_intr_enabled(s)) {
|
2014-10-29 15:00:16 +03:00
|
|
|
/* Update reply queue pointer */
|
2021-12-18 01:49:30 +03:00
|
|
|
ldl_le_pci_dma(pci_dev, s->consumer_pa, &s->reply_queue_tail, attrs);
|
2014-10-29 15:00:16 +03:00
|
|
|
tail = s->reply_queue_head;
|
|
|
|
s->reply_queue_head = megasas_next_index(s, tail, s->fw_cmds);
|
|
|
|
trace_megasas_qf_update(s->reply_queue_head, s->reply_queue_tail,
|
|
|
|
s->busy);
|
2021-12-18 00:39:42 +03:00
|
|
|
stl_le_pci_dma(pci_dev, s->producer_pa, s->reply_queue_head, attrs);
|
2012-05-29 15:51:17 +04:00
|
|
|
/* Notify HBA */
|
2014-10-29 15:00:16 +03:00
|
|
|
if (msix_enabled(pci_dev)) {
|
|
|
|
trace_megasas_msix_raise(0);
|
|
|
|
msix_notify(pci_dev, 0);
|
|
|
|
} else if (msi_enabled(pci_dev)) {
|
|
|
|
trace_megasas_msi_raise(0);
|
|
|
|
msi_notify(pci_dev, 0);
|
|
|
|
} else {
|
|
|
|
s->doorbell++;
|
|
|
|
if (s->doorbell == 1) {
|
2012-05-29 15:51:17 +04:00
|
|
|
trace_megasas_irq_raise();
|
2013-10-07 11:36:39 +04:00
|
|
|
pci_irq_assert(pci_dev);
|
2012-05-29 15:51:17 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
trace_megasas_qf_complete_noirq(context);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-11-10 18:27:51 +03:00
|
|
|
static void megasas_complete_command(MegasasCmd *cmd)
|
|
|
|
{
|
|
|
|
cmd->iov_size = 0;
|
|
|
|
cmd->iov_offset = 0;
|
|
|
|
|
|
|
|
cmd->req->hba_private = NULL;
|
|
|
|
scsi_req_unref(cmd->req);
|
|
|
|
cmd->req = NULL;
|
|
|
|
|
|
|
|
megasas_unmap_frame(cmd->state, cmd);
|
|
|
|
megasas_complete_frame(cmd->state, cmd->context);
|
|
|
|
}
|
|
|
|
|
2012-05-29 15:51:17 +04:00
|
|
|
static void megasas_reset_frames(MegasasState *s)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
MegasasCmd *cmd;
|
|
|
|
|
|
|
|
for (i = 0; i < s->fw_cmds; i++) {
|
|
|
|
cmd = &s->frames[i];
|
|
|
|
if (cmd->pa) {
|
2014-10-29 15:00:15 +03:00
|
|
|
megasas_unmap_frame(s, cmd);
|
2012-05-29 15:51:17 +04:00
|
|
|
}
|
|
|
|
}
|
2014-10-29 15:00:15 +03:00
|
|
|
bitmap_zero(s->frame_map, MEGASAS_MAX_FRAMES);
|
2012-05-29 15:51:17 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
static void megasas_abort_command(MegasasCmd *cmd)
|
|
|
|
{
|
2016-11-10 18:27:51 +03:00
|
|
|
/* Never abort internal commands. */
|
2017-06-01 18:26:14 +03:00
|
|
|
if (cmd->dcmd_opcode != -1) {
|
|
|
|
return;
|
|
|
|
}
|
2016-11-10 18:27:51 +03:00
|
|
|
if (cmd->req != NULL) {
|
2012-07-12 17:02:29 +04:00
|
|
|
scsi_req_cancel(cmd->req);
|
2012-05-29 15:51:17 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static int megasas_init_firmware(MegasasState *s, MegasasCmd *cmd)
|
|
|
|
{
|
2021-12-18 01:45:06 +03:00
|
|
|
const MemTxAttrs attrs = MEMTXATTRS_UNSPECIFIED;
|
2014-06-13 19:26:13 +04:00
|
|
|
PCIDevice *pcid = PCI_DEVICE(s);
|
2012-05-29 15:51:17 +04:00
|
|
|
uint32_t pa_hi, pa_lo;
|
2014-10-29 15:00:12 +03:00
|
|
|
hwaddr iq_pa, initq_size = sizeof(struct mfi_init_qinfo);
|
|
|
|
struct mfi_init_qinfo *initq = NULL;
|
2012-05-29 15:51:17 +04:00
|
|
|
uint32_t flags;
|
|
|
|
int ret = MFI_STAT_OK;
|
|
|
|
|
2014-10-29 15:00:12 +03:00
|
|
|
if (s->reply_queue_pa) {
|
|
|
|
trace_megasas_initq_mapped(s->reply_queue_pa);
|
|
|
|
goto out;
|
|
|
|
}
|
2012-05-29 15:51:17 +04:00
|
|
|
pa_lo = le32_to_cpu(cmd->frame->init.qinfo_new_addr_lo);
|
|
|
|
pa_hi = le32_to_cpu(cmd->frame->init.qinfo_new_addr_hi);
|
|
|
|
iq_pa = (((uint64_t) pa_hi << 32) | pa_lo);
|
|
|
|
trace_megasas_init_firmware((uint64_t)iq_pa);
|
2014-06-13 19:26:13 +04:00
|
|
|
initq = pci_dma_map(pcid, iq_pa, &initq_size, 0);
|
2012-05-29 15:51:17 +04:00
|
|
|
if (!initq || initq_size != sizeof(*initq)) {
|
|
|
|
trace_megasas_initq_map_failed(cmd->index);
|
|
|
|
s->event_count++;
|
|
|
|
ret = MFI_STAT_MEMORY_NOT_AVAILABLE;
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
s->reply_queue_len = le32_to_cpu(initq->rq_entries) & 0xFFFF;
|
|
|
|
if (s->reply_queue_len > s->fw_cmds) {
|
|
|
|
trace_megasas_initq_mismatch(s->reply_queue_len, s->fw_cmds);
|
|
|
|
s->event_count++;
|
|
|
|
ret = MFI_STAT_INVALID_PARAMETER;
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
pa_lo = le32_to_cpu(initq->rq_addr_lo);
|
|
|
|
pa_hi = le32_to_cpu(initq->rq_addr_hi);
|
|
|
|
s->reply_queue_pa = ((uint64_t) pa_hi << 32) | pa_lo;
|
|
|
|
pa_lo = le32_to_cpu(initq->ci_addr_lo);
|
|
|
|
pa_hi = le32_to_cpu(initq->ci_addr_hi);
|
|
|
|
s->consumer_pa = ((uint64_t) pa_hi << 32) | pa_lo;
|
|
|
|
pa_lo = le32_to_cpu(initq->pi_addr_lo);
|
|
|
|
pa_hi = le32_to_cpu(initq->pi_addr_hi);
|
|
|
|
s->producer_pa = ((uint64_t) pa_hi << 32) | pa_lo;
|
2021-12-18 01:49:30 +03:00
|
|
|
ldl_le_pci_dma(pcid, s->producer_pa, &s->reply_queue_head, attrs);
|
2016-05-25 15:25:10 +03:00
|
|
|
s->reply_queue_head %= MEGASAS_MAX_FRAMES;
|
2021-12-18 01:49:30 +03:00
|
|
|
ldl_le_pci_dma(pcid, s->consumer_pa, &s->reply_queue_tail, attrs);
|
2016-05-25 15:25:10 +03:00
|
|
|
s->reply_queue_tail %= MEGASAS_MAX_FRAMES;
|
2012-05-29 15:51:17 +04:00
|
|
|
flags = le32_to_cpu(initq->flags);
|
|
|
|
if (flags & MFI_QUEUE_FLAG_CONTEXT64) {
|
|
|
|
s->flags |= MEGASAS_MASK_USE_QUEUE64;
|
|
|
|
}
|
|
|
|
trace_megasas_init_queue((unsigned long)s->reply_queue_pa,
|
|
|
|
s->reply_queue_len, s->reply_queue_head,
|
|
|
|
s->reply_queue_tail, flags);
|
|
|
|
megasas_reset_frames(s);
|
|
|
|
s->fw_state = MFI_FWSTATE_OPERATIONAL;
|
|
|
|
out:
|
|
|
|
if (initq) {
|
2014-06-13 19:26:13 +04:00
|
|
|
pci_dma_unmap(pcid, initq, initq_size, 0, 0);
|
2012-05-29 15:51:17 +04:00
|
|
|
}
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int megasas_map_dcmd(MegasasState *s, MegasasCmd *cmd)
|
|
|
|
{
|
|
|
|
dma_addr_t iov_pa, iov_size;
|
2017-06-01 18:18:57 +03:00
|
|
|
int iov_count;
|
2012-05-29 15:51:17 +04:00
|
|
|
|
|
|
|
cmd->flags = le16_to_cpu(cmd->frame->header.flags);
|
2017-06-01 18:18:57 +03:00
|
|
|
iov_count = cmd->frame->header.sge_count;
|
|
|
|
if (!iov_count) {
|
2012-05-29 15:51:17 +04:00
|
|
|
trace_megasas_dcmd_zero_sge(cmd->index);
|
|
|
|
cmd->iov_size = 0;
|
|
|
|
return 0;
|
2017-06-01 18:18:57 +03:00
|
|
|
} else if (iov_count > 1) {
|
|
|
|
trace_megasas_dcmd_invalid_sge(cmd->index, iov_count);
|
2012-05-29 15:51:17 +04:00
|
|
|
cmd->iov_size = 0;
|
2017-01-02 13:03:33 +03:00
|
|
|
return -EINVAL;
|
2012-05-29 15:51:17 +04:00
|
|
|
}
|
|
|
|
iov_pa = megasas_sgl_get_addr(cmd, &cmd->frame->dcmd.sgl);
|
|
|
|
iov_size = megasas_sgl_get_len(cmd, &cmd->frame->dcmd.sgl);
|
2013-06-30 16:02:53 +04:00
|
|
|
pci_dma_sglist_init(&cmd->qsg, PCI_DEVICE(s), 1);
|
2012-05-29 15:51:17 +04:00
|
|
|
qemu_sglist_add(&cmd->qsg, iov_pa, iov_size);
|
|
|
|
cmd->iov_size = iov_size;
|
2017-01-02 13:03:33 +03:00
|
|
|
return 0;
|
2012-05-29 15:51:17 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
static void megasas_finish_dcmd(MegasasCmd *cmd, uint32_t iov_size)
|
|
|
|
{
|
|
|
|
trace_megasas_finish_dcmd(cmd->index, iov_size);
|
|
|
|
|
|
|
|
if (iov_size > cmd->iov_size) {
|
|
|
|
if (megasas_frame_is_ieee_sgl(cmd)) {
|
|
|
|
cmd->frame->dcmd.sgl.sg_skinny->len = cpu_to_le32(iov_size);
|
|
|
|
} else if (megasas_frame_is_sgl64(cmd)) {
|
|
|
|
cmd->frame->dcmd.sgl.sg64->len = cpu_to_le32(iov_size);
|
|
|
|
} else {
|
|
|
|
cmd->frame->dcmd.sgl.sg32->len = cpu_to_le32(iov_size);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static int megasas_ctrl_get_info(MegasasState *s, MegasasCmd *cmd)
|
|
|
|
{
|
2013-06-30 16:02:53 +04:00
|
|
|
PCIDevice *pci_dev = PCI_DEVICE(s);
|
2014-10-29 15:00:08 +03:00
|
|
|
PCIDeviceClass *pci_class = PCI_DEVICE_GET_CLASS(pci_dev);
|
2020-08-25 22:19:58 +03:00
|
|
|
MegasasBaseClass *base_class = MEGASAS_GET_CLASS(s);
|
2012-05-29 15:51:17 +04:00
|
|
|
struct mfi_ctrl_info info;
|
|
|
|
size_t dcmd_size = sizeof(info);
|
|
|
|
BusChild *kid;
|
2014-10-29 15:00:07 +03:00
|
|
|
int num_pd_disks = 0;
|
2021-12-16 11:36:38 +03:00
|
|
|
dma_addr_t residual;
|
2012-05-29 15:51:17 +04:00
|
|
|
|
2015-12-21 12:43:13 +03:00
|
|
|
memset(&info, 0x0, dcmd_size);
|
2012-05-29 15:51:17 +04:00
|
|
|
if (cmd->iov_size < dcmd_size) {
|
|
|
|
trace_megasas_dcmd_invalid_xfer_len(cmd->index, cmd->iov_size,
|
|
|
|
dcmd_size);
|
|
|
|
return MFI_STAT_INVALID_PARAMETER;
|
|
|
|
}
|
|
|
|
|
2014-10-29 15:00:08 +03:00
|
|
|
info.pci.vendor = cpu_to_le16(pci_class->vendor_id);
|
|
|
|
info.pci.device = cpu_to_le16(pci_class->device_id);
|
|
|
|
info.pci.subvendor = cpu_to_le16(pci_class->subsystem_vendor_id);
|
|
|
|
info.pci.subdevice = cpu_to_le16(pci_class->subsystem_id);
|
2012-05-29 15:51:17 +04:00
|
|
|
|
2012-08-01 14:46:50 +04:00
|
|
|
/*
|
|
|
|
* For some reason the firmware supports
|
|
|
|
* only up to 8 device ports.
|
|
|
|
* Despite supporting a far larger number
|
|
|
|
* of devices for the physical devices.
|
|
|
|
* So just display the first 8 devices
|
|
|
|
* in the device port list, independent
|
|
|
|
* of how many logical devices are actually
|
|
|
|
* present.
|
|
|
|
*/
|
|
|
|
info.host.type = MFI_INFO_HOST_PCIE;
|
2012-05-29 15:51:17 +04:00
|
|
|
info.device.type = MFI_INFO_DEV_SAS3G;
|
2012-08-01 14:46:50 +04:00
|
|
|
info.device.port_count = 8;
|
|
|
|
QTAILQ_FOREACH(kid, &s->bus.qbus.children, sibling) {
|
2016-01-06 12:37:46 +03:00
|
|
|
SCSIDevice *sdev = SCSI_DEVICE(kid->child);
|
2014-10-29 15:00:07 +03:00
|
|
|
uint16_t pd_id;
|
2012-08-01 14:46:50 +04:00
|
|
|
|
2014-10-29 15:00:07 +03:00
|
|
|
if (num_pd_disks < 8) {
|
|
|
|
pd_id = ((sdev->id & 0xFF) << 8) | (sdev->lun & 0xFF);
|
|
|
|
info.device.port_addr[num_pd_disks] =
|
|
|
|
cpu_to_le64(megasas_get_sata_addr(pd_id));
|
2012-08-01 14:46:50 +04:00
|
|
|
}
|
2014-10-29 15:00:07 +03:00
|
|
|
num_pd_disks++;
|
2012-08-01 14:46:50 +04:00
|
|
|
}
|
2012-05-29 15:51:17 +04:00
|
|
|
|
2014-10-29 15:00:08 +03:00
|
|
|
memcpy(info.product_name, base_class->product_name, 24);
|
2012-08-24 14:36:41 +04:00
|
|
|
snprintf(info.serial_number, 32, "%s", s->hba_serial);
|
2015-10-30 22:36:09 +03:00
|
|
|
snprintf(info.package_version, 0x60, "%s-QEMU", qemu_hw_version());
|
2012-05-29 15:51:17 +04:00
|
|
|
memcpy(info.image_component[0].name, "APP", 3);
|
2014-10-29 15:00:08 +03:00
|
|
|
snprintf(info.image_component[0].version, 10, "%s-QEMU",
|
|
|
|
base_class->product_version);
|
2014-04-03 17:47:34 +04:00
|
|
|
memcpy(info.image_component[0].build_date, "Apr 1 2014", 11);
|
|
|
|
memcpy(info.image_component[0].build_time, "12:34:56", 8);
|
2012-05-29 15:51:17 +04:00
|
|
|
info.image_component_count = 1;
|
2013-06-30 16:02:53 +04:00
|
|
|
if (pci_dev->has_rom) {
|
2012-05-29 15:51:17 +04:00
|
|
|
uint8_t biosver[32];
|
|
|
|
uint8_t *ptr;
|
|
|
|
|
2013-06-30 16:02:53 +04:00
|
|
|
ptr = memory_region_get_ram_ptr(&pci_dev->rom);
|
2012-05-29 15:51:17 +04:00
|
|
|
memcpy(biosver, ptr + 0x41, 31);
|
2016-06-07 14:14:03 +03:00
|
|
|
biosver[31] = 0;
|
2012-05-29 15:51:17 +04:00
|
|
|
memcpy(info.image_component[1].name, "BIOS", 4);
|
|
|
|
memcpy(info.image_component[1].version, biosver,
|
|
|
|
strlen((const char *)biosver));
|
|
|
|
info.image_component_count++;
|
|
|
|
}
|
|
|
|
info.current_fw_time = cpu_to_le32(megasas_fw_time());
|
|
|
|
info.max_arms = 32;
|
|
|
|
info.max_spans = 8;
|
|
|
|
info.max_arrays = MEGASAS_MAX_ARRAYS;
|
2014-10-29 15:00:07 +03:00
|
|
|
info.max_lds = MFI_MAX_LD;
|
2012-05-29 15:51:17 +04:00
|
|
|
info.max_cmds = cpu_to_le16(s->fw_cmds);
|
|
|
|
info.max_sg_elements = cpu_to_le16(s->fw_sge);
|
|
|
|
info.max_request_size = cpu_to_le32(MEGASAS_MAX_SECTORS);
|
2014-10-29 15:00:07 +03:00
|
|
|
if (!megasas_is_jbod(s))
|
|
|
|
info.lds_present = cpu_to_le16(num_pd_disks);
|
|
|
|
info.pd_present = cpu_to_le16(num_pd_disks);
|
|
|
|
info.pd_disks_present = cpu_to_le16(num_pd_disks);
|
2012-05-29 15:51:17 +04:00
|
|
|
info.hw_present = cpu_to_le32(MFI_INFO_HW_NVRAM |
|
|
|
|
MFI_INFO_HW_MEM |
|
|
|
|
MFI_INFO_HW_FLASH);
|
|
|
|
info.memory_size = cpu_to_le16(512);
|
|
|
|
info.nvram_size = cpu_to_le16(32);
|
|
|
|
info.flash_size = cpu_to_le16(16);
|
|
|
|
info.raid_levels = cpu_to_le32(MFI_INFO_RAID_0);
|
|
|
|
info.adapter_ops = cpu_to_le32(MFI_INFO_AOPS_RBLD_RATE |
|
|
|
|
MFI_INFO_AOPS_SELF_DIAGNOSTIC |
|
|
|
|
MFI_INFO_AOPS_MIXED_ARRAY);
|
|
|
|
info.ld_ops = cpu_to_le32(MFI_INFO_LDOPS_DISK_CACHE_POLICY |
|
|
|
|
MFI_INFO_LDOPS_ACCESS_POLICY |
|
|
|
|
MFI_INFO_LDOPS_IO_POLICY |
|
|
|
|
MFI_INFO_LDOPS_WRITE_POLICY |
|
|
|
|
MFI_INFO_LDOPS_READ_POLICY);
|
|
|
|
info.max_strips_per_io = cpu_to_le16(s->fw_sge);
|
|
|
|
info.stripe_sz_ops.min = 3;
|
2015-03-23 18:29:26 +03:00
|
|
|
info.stripe_sz_ops.max = ctz32(MEGASAS_MAX_SECTORS + 1);
|
2012-05-29 15:51:17 +04:00
|
|
|
info.properties.pred_fail_poll_interval = cpu_to_le16(300);
|
|
|
|
info.properties.intr_throttle_cnt = cpu_to_le16(16);
|
|
|
|
info.properties.intr_throttle_timeout = cpu_to_le16(50);
|
|
|
|
info.properties.rebuild_rate = 30;
|
|
|
|
info.properties.patrol_read_rate = 30;
|
|
|
|
info.properties.bgi_rate = 30;
|
|
|
|
info.properties.cc_rate = 30;
|
|
|
|
info.properties.recon_rate = 30;
|
|
|
|
info.properties.cache_flush_interval = 4;
|
|
|
|
info.properties.spinup_drv_cnt = 2;
|
|
|
|
info.properties.spinup_delay = 6;
|
|
|
|
info.properties.ecc_bucket_size = 15;
|
|
|
|
info.properties.ecc_bucket_leak_rate = cpu_to_le16(1440);
|
|
|
|
info.properties.expose_encl_devices = 1;
|
|
|
|
info.properties.OnOffProperties = cpu_to_le32(MFI_CTRL_PROP_EnableJBOD);
|
|
|
|
info.pd_ops = cpu_to_le32(MFI_INFO_PDOPS_FORCE_ONLINE |
|
|
|
|
MFI_INFO_PDOPS_FORCE_OFFLINE);
|
|
|
|
info.pd_mix_support = cpu_to_le32(MFI_INFO_PDMIX_SAS |
|
|
|
|
MFI_INFO_PDMIX_SATA |
|
|
|
|
MFI_INFO_PDMIX_LD);
|
|
|
|
|
2021-12-16 11:36:38 +03:00
|
|
|
dma_buf_read(&info, dcmd_size, &residual, &cmd->qsg,
|
|
|
|
MEMTXATTRS_UNSPECIFIED);
|
|
|
|
cmd->iov_size -= residual;
|
2012-05-29 15:51:17 +04:00
|
|
|
return MFI_STAT_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int megasas_mfc_get_defaults(MegasasState *s, MegasasCmd *cmd)
|
|
|
|
{
|
|
|
|
struct mfi_defaults info;
|
|
|
|
size_t dcmd_size = sizeof(struct mfi_defaults);
|
2021-12-16 11:36:38 +03:00
|
|
|
dma_addr_t residual;
|
2012-05-29 15:51:17 +04:00
|
|
|
|
|
|
|
memset(&info, 0x0, dcmd_size);
|
|
|
|
if (cmd->iov_size < dcmd_size) {
|
|
|
|
trace_megasas_dcmd_invalid_xfer_len(cmd->index, cmd->iov_size,
|
|
|
|
dcmd_size);
|
|
|
|
return MFI_STAT_INVALID_PARAMETER;
|
|
|
|
}
|
|
|
|
|
2012-08-01 14:46:50 +04:00
|
|
|
info.sas_addr = cpu_to_le64(s->sas_addr);
|
2012-05-29 15:51:17 +04:00
|
|
|
info.stripe_size = 3;
|
|
|
|
info.flush_time = 4;
|
|
|
|
info.background_rate = 30;
|
|
|
|
info.allow_mix_in_enclosure = 1;
|
|
|
|
info.allow_mix_in_ld = 1;
|
|
|
|
info.direct_pd_mapping = 1;
|
|
|
|
/* Enable for BIOS support */
|
|
|
|
info.bios_enumerate_lds = 1;
|
|
|
|
info.disable_ctrl_r = 1;
|
|
|
|
info.expose_enclosure_devices = 1;
|
|
|
|
info.disable_preboot_cli = 1;
|
|
|
|
info.cluster_disable = 1;
|
|
|
|
|
2021-12-16 11:36:38 +03:00
|
|
|
dma_buf_read(&info, dcmd_size, &residual, &cmd->qsg,
|
|
|
|
MEMTXATTRS_UNSPECIFIED);
|
|
|
|
cmd->iov_size -= residual;
|
2012-05-29 15:51:17 +04:00
|
|
|
return MFI_STAT_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int megasas_dcmd_get_bios_info(MegasasState *s, MegasasCmd *cmd)
|
|
|
|
{
|
|
|
|
struct mfi_bios_data info;
|
|
|
|
size_t dcmd_size = sizeof(info);
|
2021-12-16 11:36:38 +03:00
|
|
|
dma_addr_t residual;
|
2012-05-29 15:51:17 +04:00
|
|
|
|
|
|
|
memset(&info, 0x0, dcmd_size);
|
|
|
|
if (cmd->iov_size < dcmd_size) {
|
|
|
|
trace_megasas_dcmd_invalid_xfer_len(cmd->index, cmd->iov_size,
|
|
|
|
dcmd_size);
|
|
|
|
return MFI_STAT_INVALID_PARAMETER;
|
|
|
|
}
|
|
|
|
info.continue_on_error = 1;
|
|
|
|
info.verbose = 1;
|
|
|
|
if (megasas_is_jbod(s)) {
|
|
|
|
info.expose_all_drives = 1;
|
|
|
|
}
|
|
|
|
|
2021-12-16 11:36:38 +03:00
|
|
|
dma_buf_read(&info, dcmd_size, &residual, &cmd->qsg,
|
|
|
|
MEMTXATTRS_UNSPECIFIED);
|
|
|
|
cmd->iov_size -= residual;
|
2012-05-29 15:51:17 +04:00
|
|
|
return MFI_STAT_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int megasas_dcmd_get_fw_time(MegasasState *s, MegasasCmd *cmd)
|
|
|
|
{
|
|
|
|
uint64_t fw_time;
|
|
|
|
size_t dcmd_size = sizeof(fw_time);
|
2021-12-16 11:36:38 +03:00
|
|
|
dma_addr_t residual;
|
2012-05-29 15:51:17 +04:00
|
|
|
|
|
|
|
fw_time = cpu_to_le64(megasas_fw_time());
|
|
|
|
|
2021-12-16 11:36:38 +03:00
|
|
|
dma_buf_read(&fw_time, dcmd_size, &residual, &cmd->qsg,
|
|
|
|
MEMTXATTRS_UNSPECIFIED);
|
|
|
|
cmd->iov_size -= residual;
|
2012-05-29 15:51:17 +04:00
|
|
|
return MFI_STAT_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int megasas_dcmd_set_fw_time(MegasasState *s, MegasasCmd *cmd)
|
|
|
|
{
|
|
|
|
uint64_t fw_time;
|
|
|
|
|
|
|
|
/* This is a dummy; setting of firmware time is not allowed */
|
|
|
|
memcpy(&fw_time, cmd->frame->dcmd.mbox, sizeof(fw_time));
|
|
|
|
|
|
|
|
trace_megasas_dcmd_set_fw_time(cmd->index, fw_time);
|
|
|
|
fw_time = cpu_to_le64(megasas_fw_time());
|
|
|
|
return MFI_STAT_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int megasas_event_info(MegasasState *s, MegasasCmd *cmd)
|
|
|
|
{
|
|
|
|
struct mfi_evt_log_state info;
|
|
|
|
size_t dcmd_size = sizeof(info);
|
2021-12-16 11:36:38 +03:00
|
|
|
dma_addr_t residual;
|
2012-05-29 15:51:17 +04:00
|
|
|
|
|
|
|
memset(&info, 0, dcmd_size);
|
|
|
|
|
|
|
|
info.newest_seq_num = cpu_to_le32(s->event_count);
|
|
|
|
info.shutdown_seq_num = cpu_to_le32(s->shutdown_event);
|
|
|
|
info.boot_seq_num = cpu_to_le32(s->boot_event);
|
|
|
|
|
2021-12-16 11:36:38 +03:00
|
|
|
dma_buf_read(&info, dcmd_size, &residual, &cmd->qsg,
|
|
|
|
MEMTXATTRS_UNSPECIFIED);
|
|
|
|
cmd->iov_size -= residual;
|
2012-05-29 15:51:17 +04:00
|
|
|
return MFI_STAT_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int megasas_event_wait(MegasasState *s, MegasasCmd *cmd)
|
|
|
|
{
|
|
|
|
union mfi_evt event;
|
|
|
|
|
|
|
|
if (cmd->iov_size < sizeof(struct mfi_evt_detail)) {
|
|
|
|
trace_megasas_dcmd_invalid_xfer_len(cmd->index, cmd->iov_size,
|
|
|
|
sizeof(struct mfi_evt_detail));
|
|
|
|
return MFI_STAT_INVALID_PARAMETER;
|
|
|
|
}
|
|
|
|
s->event_count = cpu_to_le32(cmd->frame->dcmd.mbox[0]);
|
|
|
|
event.word = cpu_to_le32(cmd->frame->dcmd.mbox[4]);
|
|
|
|
s->event_locale = event.members.locale;
|
|
|
|
s->event_class = event.members.class;
|
|
|
|
s->event_cmd = cmd;
|
|
|
|
/* Decrease busy count; event frame doesn't count here */
|
|
|
|
s->busy--;
|
|
|
|
cmd->iov_size = sizeof(struct mfi_evt_detail);
|
|
|
|
return MFI_STAT_INVALID_STATUS;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int megasas_dcmd_pd_get_list(MegasasState *s, MegasasCmd *cmd)
|
|
|
|
{
|
|
|
|
struct mfi_pd_list info;
|
|
|
|
size_t dcmd_size = sizeof(info);
|
|
|
|
BusChild *kid;
|
|
|
|
uint32_t offset, dcmd_limit, num_pd_disks = 0, max_pd_disks;
|
2021-12-16 11:36:38 +03:00
|
|
|
dma_addr_t residual;
|
2012-05-29 15:51:17 +04:00
|
|
|
|
|
|
|
memset(&info, 0, dcmd_size);
|
|
|
|
offset = 8;
|
|
|
|
dcmd_limit = offset + sizeof(struct mfi_pd_address);
|
|
|
|
if (cmd->iov_size < dcmd_limit) {
|
|
|
|
trace_megasas_dcmd_invalid_xfer_len(cmd->index, cmd->iov_size,
|
|
|
|
dcmd_limit);
|
|
|
|
return MFI_STAT_INVALID_PARAMETER;
|
|
|
|
}
|
|
|
|
|
|
|
|
max_pd_disks = (cmd->iov_size - offset) / sizeof(struct mfi_pd_address);
|
2014-10-29 15:00:07 +03:00
|
|
|
if (max_pd_disks > MFI_MAX_SYS_PDS) {
|
|
|
|
max_pd_disks = MFI_MAX_SYS_PDS;
|
2012-05-29 15:51:17 +04:00
|
|
|
}
|
|
|
|
QTAILQ_FOREACH(kid, &s->bus.qbus.children, sibling) {
|
2016-01-06 12:37:46 +03:00
|
|
|
SCSIDevice *sdev = SCSI_DEVICE(kid->child);
|
2014-10-29 15:00:07 +03:00
|
|
|
uint16_t pd_id;
|
|
|
|
|
|
|
|
if (num_pd_disks >= max_pd_disks)
|
|
|
|
break;
|
2012-05-29 15:51:17 +04:00
|
|
|
|
2014-10-29 15:00:07 +03:00
|
|
|
pd_id = ((sdev->id & 0xFF) << 8) | (sdev->lun & 0xFF);
|
|
|
|
info.addr[num_pd_disks].device_id = cpu_to_le16(pd_id);
|
2012-05-29 15:51:17 +04:00
|
|
|
info.addr[num_pd_disks].encl_device_id = 0xFFFF;
|
|
|
|
info.addr[num_pd_disks].encl_index = 0;
|
2014-10-29 15:00:07 +03:00
|
|
|
info.addr[num_pd_disks].slot_number = sdev->id & 0xFF;
|
2012-05-29 15:51:17 +04:00
|
|
|
info.addr[num_pd_disks].scsi_dev_type = sdev->type;
|
|
|
|
info.addr[num_pd_disks].connect_port_bitmap = 0x1;
|
|
|
|
info.addr[num_pd_disks].sas_addr[0] =
|
2014-10-29 15:00:07 +03:00
|
|
|
cpu_to_le64(megasas_get_sata_addr(pd_id));
|
2012-05-29 15:51:17 +04:00
|
|
|
num_pd_disks++;
|
|
|
|
offset += sizeof(struct mfi_pd_address);
|
|
|
|
}
|
|
|
|
trace_megasas_dcmd_pd_get_list(cmd->index, num_pd_disks,
|
|
|
|
max_pd_disks, offset);
|
|
|
|
|
|
|
|
info.size = cpu_to_le32(offset);
|
|
|
|
info.count = cpu_to_le32(num_pd_disks);
|
|
|
|
|
2021-12-16 11:36:38 +03:00
|
|
|
dma_buf_read(&info, offset, &residual, &cmd->qsg,
|
|
|
|
MEMTXATTRS_UNSPECIFIED);
|
|
|
|
cmd->iov_size -= residual;
|
2012-05-29 15:51:17 +04:00
|
|
|
return MFI_STAT_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int megasas_dcmd_pd_list_query(MegasasState *s, MegasasCmd *cmd)
|
|
|
|
{
|
|
|
|
uint16_t flags;
|
|
|
|
|
|
|
|
/* mbox0 contains flags */
|
|
|
|
flags = le16_to_cpu(cmd->frame->dcmd.mbox[0]);
|
|
|
|
trace_megasas_dcmd_pd_list_query(cmd->index, flags);
|
|
|
|
if (flags == MR_PD_QUERY_TYPE_ALL ||
|
|
|
|
megasas_is_jbod(s)) {
|
|
|
|
return megasas_dcmd_pd_get_list(s, cmd);
|
|
|
|
}
|
|
|
|
|
|
|
|
return MFI_STAT_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int megasas_pd_get_info_submit(SCSIDevice *sdev, int lun,
|
|
|
|
MegasasCmd *cmd)
|
|
|
|
{
|
|
|
|
struct mfi_pd_info *info = cmd->iov_buf;
|
|
|
|
size_t dcmd_size = sizeof(struct mfi_pd_info);
|
|
|
|
uint64_t pd_size;
|
2014-10-29 15:00:07 +03:00
|
|
|
uint16_t pd_id = ((sdev->id & 0xFF) << 8) | (lun & 0xFF);
|
2012-05-29 15:51:17 +04:00
|
|
|
uint8_t cmdbuf[6];
|
2021-12-31 13:13:34 +03:00
|
|
|
size_t len;
|
2021-12-31 13:33:29 +03:00
|
|
|
dma_addr_t residual;
|
2012-05-29 15:51:17 +04:00
|
|
|
|
|
|
|
if (!cmd->iov_buf) {
|
2014-12-04 16:12:44 +03:00
|
|
|
cmd->iov_buf = g_malloc0(dcmd_size);
|
2012-05-29 15:51:17 +04:00
|
|
|
info = cmd->iov_buf;
|
|
|
|
info->inquiry_data[0] = 0x7f; /* Force PQual 0x3, PType 0x1f */
|
|
|
|
info->vpd_page83[0] = 0x7f;
|
|
|
|
megasas_setup_inquiry(cmdbuf, 0, sizeof(info->inquiry_data));
|
2022-08-17 08:34:58 +03:00
|
|
|
cmd->req = scsi_req_new(sdev, cmd->index, lun, cmdbuf, sizeof(cmdbuf), cmd);
|
2017-06-01 18:26:14 +03:00
|
|
|
if (!cmd->req) {
|
2012-05-29 15:51:17 +04:00
|
|
|
trace_megasas_dcmd_req_alloc_failed(cmd->index,
|
|
|
|
"PD get info std inquiry");
|
|
|
|
g_free(cmd->iov_buf);
|
|
|
|
cmd->iov_buf = NULL;
|
|
|
|
return MFI_STAT_FLASH_ALLOC_FAIL;
|
|
|
|
}
|
|
|
|
trace_megasas_dcmd_internal_submit(cmd->index,
|
|
|
|
"PD get info std inquiry", lun);
|
2017-06-01 18:26:14 +03:00
|
|
|
len = scsi_req_enqueue(cmd->req);
|
2012-05-29 15:51:17 +04:00
|
|
|
if (len > 0) {
|
|
|
|
cmd->iov_size = len;
|
2017-06-01 18:26:14 +03:00
|
|
|
scsi_req_continue(cmd->req);
|
2012-05-29 15:51:17 +04:00
|
|
|
}
|
|
|
|
return MFI_STAT_INVALID_STATUS;
|
|
|
|
} else if (info->inquiry_data[0] != 0x7f && info->vpd_page83[0] == 0x7f) {
|
|
|
|
megasas_setup_inquiry(cmdbuf, 0x83, sizeof(info->vpd_page83));
|
2022-08-17 08:34:58 +03:00
|
|
|
cmd->req = scsi_req_new(sdev, cmd->index, lun, cmdbuf, sizeof(cmdbuf), cmd);
|
2017-06-01 18:26:14 +03:00
|
|
|
if (!cmd->req) {
|
2012-05-29 15:51:17 +04:00
|
|
|
trace_megasas_dcmd_req_alloc_failed(cmd->index,
|
|
|
|
"PD get info vpd inquiry");
|
|
|
|
return MFI_STAT_FLASH_ALLOC_FAIL;
|
|
|
|
}
|
|
|
|
trace_megasas_dcmd_internal_submit(cmd->index,
|
|
|
|
"PD get info vpd inquiry", lun);
|
2017-06-01 18:26:14 +03:00
|
|
|
len = scsi_req_enqueue(cmd->req);
|
2012-05-29 15:51:17 +04:00
|
|
|
if (len > 0) {
|
|
|
|
cmd->iov_size = len;
|
2017-06-01 18:26:14 +03:00
|
|
|
scsi_req_continue(cmd->req);
|
2012-05-29 15:51:17 +04:00
|
|
|
}
|
|
|
|
return MFI_STAT_INVALID_STATUS;
|
|
|
|
}
|
|
|
|
/* Finished, set FW state */
|
|
|
|
if ((info->inquiry_data[0] >> 5) == 0) {
|
|
|
|
if (megasas_is_jbod(cmd->state)) {
|
|
|
|
info->fw_state = cpu_to_le16(MFI_PD_STATE_SYSTEM);
|
|
|
|
} else {
|
|
|
|
info->fw_state = cpu_to_le16(MFI_PD_STATE_ONLINE);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
info->fw_state = cpu_to_le16(MFI_PD_STATE_OFFLINE);
|
|
|
|
}
|
|
|
|
|
2014-10-29 15:00:07 +03:00
|
|
|
info->ref.v.device_id = cpu_to_le16(pd_id);
|
2012-05-29 15:51:17 +04:00
|
|
|
info->state.ddf.pd_type = cpu_to_le16(MFI_PD_DDF_TYPE_IN_VD|
|
|
|
|
MFI_PD_DDF_TYPE_INTF_SAS);
|
2014-10-07 15:59:18 +04:00
|
|
|
blk_get_geometry(sdev->conf.blk, &pd_size);
|
2012-05-29 15:51:17 +04:00
|
|
|
info->raw_size = cpu_to_le64(pd_size);
|
|
|
|
info->non_coerced_size = cpu_to_le64(pd_size);
|
|
|
|
info->coerced_size = cpu_to_le64(pd_size);
|
|
|
|
info->encl_device_id = 0xFFFF;
|
|
|
|
info->slot_number = (sdev->id & 0xFF);
|
|
|
|
info->path_info.count = 1;
|
|
|
|
info->path_info.sas_addr[0] =
|
2014-10-29 15:00:07 +03:00
|
|
|
cpu_to_le64(megasas_get_sata_addr(pd_id));
|
2012-05-29 15:51:17 +04:00
|
|
|
info->connected_port_bitmap = 0x1;
|
|
|
|
info->device_speed = 1;
|
|
|
|
info->link_speed = 1;
|
2021-12-16 11:36:38 +03:00
|
|
|
dma_buf_read(cmd->iov_buf, dcmd_size, &residual, &cmd->qsg,
|
|
|
|
MEMTXATTRS_UNSPECIFIED);
|
|
|
|
cmd->iov_size -= residual;
|
2012-05-29 15:51:17 +04:00
|
|
|
g_free(cmd->iov_buf);
|
2021-12-31 13:13:34 +03:00
|
|
|
cmd->iov_size = dcmd_size - residual;
|
2012-05-29 15:51:17 +04:00
|
|
|
cmd->iov_buf = NULL;
|
|
|
|
return MFI_STAT_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int megasas_dcmd_pd_get_info(MegasasState *s, MegasasCmd *cmd)
|
|
|
|
{
|
|
|
|
size_t dcmd_size = sizeof(struct mfi_pd_info);
|
|
|
|
uint16_t pd_id;
|
2014-10-29 15:00:07 +03:00
|
|
|
uint8_t target_id, lun_id;
|
2012-05-29 15:51:17 +04:00
|
|
|
SCSIDevice *sdev = NULL;
|
|
|
|
int retval = MFI_STAT_DEVICE_NOT_FOUND;
|
|
|
|
|
|
|
|
if (cmd->iov_size < dcmd_size) {
|
|
|
|
return MFI_STAT_INVALID_PARAMETER;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* mbox0 has the ID */
|
|
|
|
pd_id = le16_to_cpu(cmd->frame->dcmd.mbox[0]);
|
2014-10-29 15:00:07 +03:00
|
|
|
target_id = (pd_id >> 8) & 0xFF;
|
|
|
|
lun_id = pd_id & 0xFF;
|
|
|
|
sdev = scsi_device_find(&s->bus, 0, target_id, lun_id);
|
2012-05-29 15:51:17 +04:00
|
|
|
trace_megasas_dcmd_pd_get_info(cmd->index, pd_id);
|
|
|
|
|
|
|
|
if (sdev) {
|
|
|
|
/* Submit inquiry */
|
|
|
|
retval = megasas_pd_get_info_submit(sdev, pd_id, cmd);
|
|
|
|
}
|
|
|
|
|
|
|
|
return retval;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int megasas_dcmd_ld_get_list(MegasasState *s, MegasasCmd *cmd)
|
|
|
|
{
|
|
|
|
struct mfi_ld_list info;
|
2021-12-31 13:13:34 +03:00
|
|
|
size_t dcmd_size = sizeof(info);
|
2021-12-31 13:33:29 +03:00
|
|
|
dma_addr_t residual;
|
2014-10-29 15:00:07 +03:00
|
|
|
uint32_t num_ld_disks = 0, max_ld_disks;
|
2012-05-29 15:51:17 +04:00
|
|
|
uint64_t ld_size;
|
|
|
|
BusChild *kid;
|
|
|
|
|
|
|
|
memset(&info, 0, dcmd_size);
|
2014-10-29 15:00:09 +03:00
|
|
|
if (cmd->iov_size > dcmd_size) {
|
2012-05-29 15:51:17 +04:00
|
|
|
trace_megasas_dcmd_invalid_xfer_len(cmd->index, cmd->iov_size,
|
|
|
|
dcmd_size);
|
|
|
|
return MFI_STAT_INVALID_PARAMETER;
|
|
|
|
}
|
|
|
|
|
2014-10-29 15:00:07 +03:00
|
|
|
max_ld_disks = (cmd->iov_size - 8) / 16;
|
2012-05-29 15:51:17 +04:00
|
|
|
if (megasas_is_jbod(s)) {
|
|
|
|
max_ld_disks = 0;
|
|
|
|
}
|
2014-10-29 15:00:07 +03:00
|
|
|
if (max_ld_disks > MFI_MAX_LD) {
|
|
|
|
max_ld_disks = MFI_MAX_LD;
|
|
|
|
}
|
2012-05-29 15:51:17 +04:00
|
|
|
QTAILQ_FOREACH(kid, &s->bus.qbus.children, sibling) {
|
2016-01-06 12:37:46 +03:00
|
|
|
SCSIDevice *sdev = SCSI_DEVICE(kid->child);
|
2012-05-29 15:51:17 +04:00
|
|
|
|
|
|
|
if (num_ld_disks >= max_ld_disks) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
/* Logical device size is in blocks */
|
2014-10-07 15:59:18 +04:00
|
|
|
blk_get_geometry(sdev->conf.blk, &ld_size);
|
2012-05-29 15:51:17 +04:00
|
|
|
info.ld_list[num_ld_disks].ld.v.target_id = sdev->id;
|
|
|
|
info.ld_list[num_ld_disks].state = MFI_LD_STATE_OPTIMAL;
|
|
|
|
info.ld_list[num_ld_disks].size = cpu_to_le64(ld_size);
|
|
|
|
num_ld_disks++;
|
|
|
|
}
|
|
|
|
info.ld_count = cpu_to_le32(num_ld_disks);
|
|
|
|
trace_megasas_dcmd_ld_get_list(cmd->index, num_ld_disks, max_ld_disks);
|
|
|
|
|
2021-12-16 11:36:38 +03:00
|
|
|
dma_buf_read(&info, dcmd_size, &residual, &cmd->qsg,
|
|
|
|
MEMTXATTRS_UNSPECIFIED);
|
2021-12-31 13:13:34 +03:00
|
|
|
cmd->iov_size = dcmd_size - residual;
|
2012-05-29 15:51:17 +04:00
|
|
|
return MFI_STAT_OK;
|
|
|
|
}
|
|
|
|
|
2014-04-16 18:44:13 +04:00
|
|
|
static int megasas_dcmd_ld_list_query(MegasasState *s, MegasasCmd *cmd)
|
|
|
|
{
|
|
|
|
uint16_t flags;
|
2014-10-29 15:00:05 +03:00
|
|
|
struct mfi_ld_targetid_list info;
|
2021-12-31 13:13:34 +03:00
|
|
|
size_t dcmd_size = sizeof(info);
|
2021-12-31 13:33:29 +03:00
|
|
|
dma_addr_t residual;
|
2014-10-29 15:00:05 +03:00
|
|
|
uint32_t num_ld_disks = 0, max_ld_disks = s->fw_luns;
|
|
|
|
BusChild *kid;
|
2014-04-16 18:44:13 +04:00
|
|
|
|
|
|
|
/* mbox0 contains flags */
|
|
|
|
flags = le16_to_cpu(cmd->frame->dcmd.mbox[0]);
|
|
|
|
trace_megasas_dcmd_ld_list_query(cmd->index, flags);
|
2014-10-29 15:00:05 +03:00
|
|
|
if (flags != MR_LD_QUERY_TYPE_ALL &&
|
|
|
|
flags != MR_LD_QUERY_TYPE_EXPOSED_TO_HOST) {
|
|
|
|
max_ld_disks = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
memset(&info, 0, dcmd_size);
|
|
|
|
if (cmd->iov_size < 12) {
|
|
|
|
trace_megasas_dcmd_invalid_xfer_len(cmd->index, cmd->iov_size,
|
|
|
|
dcmd_size);
|
|
|
|
return MFI_STAT_INVALID_PARAMETER;
|
|
|
|
}
|
|
|
|
dcmd_size = sizeof(uint32_t) * 2 + 3;
|
2014-10-29 15:00:07 +03:00
|
|
|
max_ld_disks = cmd->iov_size - dcmd_size;
|
2014-10-29 15:00:05 +03:00
|
|
|
if (megasas_is_jbod(s)) {
|
|
|
|
max_ld_disks = 0;
|
2014-04-16 18:44:13 +04:00
|
|
|
}
|
2014-10-29 15:00:07 +03:00
|
|
|
if (max_ld_disks > MFI_MAX_LD) {
|
|
|
|
max_ld_disks = MFI_MAX_LD;
|
|
|
|
}
|
2014-10-29 15:00:05 +03:00
|
|
|
QTAILQ_FOREACH(kid, &s->bus.qbus.children, sibling) {
|
2016-01-06 12:37:46 +03:00
|
|
|
SCSIDevice *sdev = SCSI_DEVICE(kid->child);
|
2014-04-16 18:44:13 +04:00
|
|
|
|
2014-10-29 15:00:05 +03:00
|
|
|
if (num_ld_disks >= max_ld_disks) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
info.targetid[num_ld_disks] = sdev->lun;
|
|
|
|
num_ld_disks++;
|
|
|
|
dcmd_size++;
|
|
|
|
}
|
|
|
|
info.ld_count = cpu_to_le32(num_ld_disks);
|
|
|
|
info.size = dcmd_size;
|
|
|
|
trace_megasas_dcmd_ld_get_list(cmd->index, num_ld_disks, max_ld_disks);
|
|
|
|
|
2021-12-16 11:36:38 +03:00
|
|
|
dma_buf_read(&info, dcmd_size, &residual, &cmd->qsg,
|
|
|
|
MEMTXATTRS_UNSPECIFIED);
|
2021-12-31 13:13:34 +03:00
|
|
|
cmd->iov_size = dcmd_size - residual;
|
2014-04-16 18:44:13 +04:00
|
|
|
return MFI_STAT_OK;
|
|
|
|
}
|
|
|
|
|
2012-05-29 15:51:17 +04:00
|
|
|
static int megasas_ld_get_info_submit(SCSIDevice *sdev, int lun,
|
|
|
|
MegasasCmd *cmd)
|
|
|
|
{
|
|
|
|
struct mfi_ld_info *info = cmd->iov_buf;
|
|
|
|
size_t dcmd_size = sizeof(struct mfi_ld_info);
|
|
|
|
uint8_t cdb[6];
|
2021-12-31 13:13:34 +03:00
|
|
|
ssize_t len;
|
2021-12-31 13:33:29 +03:00
|
|
|
dma_addr_t residual;
|
2014-10-29 15:00:07 +03:00
|
|
|
uint16_t sdev_id = ((sdev->id & 0xFF) << 8) | (lun & 0xFF);
|
2012-05-29 15:51:17 +04:00
|
|
|
uint64_t ld_size;
|
|
|
|
|
|
|
|
if (!cmd->iov_buf) {
|
2014-12-04 16:12:44 +03:00
|
|
|
cmd->iov_buf = g_malloc0(dcmd_size);
|
2012-05-29 15:51:17 +04:00
|
|
|
info = cmd->iov_buf;
|
|
|
|
megasas_setup_inquiry(cdb, 0x83, sizeof(info->vpd_page83));
|
2022-08-17 08:34:58 +03:00
|
|
|
cmd->req = scsi_req_new(sdev, cmd->index, lun, cdb, sizeof(cdb), cmd);
|
2017-06-01 18:26:14 +03:00
|
|
|
if (!cmd->req) {
|
2012-05-29 15:51:17 +04:00
|
|
|
trace_megasas_dcmd_req_alloc_failed(cmd->index,
|
|
|
|
"LD get info vpd inquiry");
|
|
|
|
g_free(cmd->iov_buf);
|
|
|
|
cmd->iov_buf = NULL;
|
|
|
|
return MFI_STAT_FLASH_ALLOC_FAIL;
|
|
|
|
}
|
|
|
|
trace_megasas_dcmd_internal_submit(cmd->index,
|
|
|
|
"LD get info vpd inquiry", lun);
|
2017-06-01 18:26:14 +03:00
|
|
|
len = scsi_req_enqueue(cmd->req);
|
2012-05-29 15:51:17 +04:00
|
|
|
if (len > 0) {
|
|
|
|
cmd->iov_size = len;
|
2017-06-01 18:26:14 +03:00
|
|
|
scsi_req_continue(cmd->req);
|
2012-05-29 15:51:17 +04:00
|
|
|
}
|
|
|
|
return MFI_STAT_INVALID_STATUS;
|
|
|
|
}
|
|
|
|
|
|
|
|
info->ld_config.params.state = MFI_LD_STATE_OPTIMAL;
|
|
|
|
info->ld_config.properties.ld.v.target_id = lun;
|
|
|
|
info->ld_config.params.stripe_size = 3;
|
|
|
|
info->ld_config.params.num_drives = 1;
|
|
|
|
info->ld_config.params.is_consistent = 1;
|
|
|
|
/* Logical device size is in blocks */
|
2014-10-07 15:59:18 +04:00
|
|
|
blk_get_geometry(sdev->conf.blk, &ld_size);
|
2012-05-29 15:51:17 +04:00
|
|
|
info->size = cpu_to_le64(ld_size);
|
|
|
|
memset(info->ld_config.span, 0, sizeof(info->ld_config.span));
|
|
|
|
info->ld_config.span[0].start_block = 0;
|
|
|
|
info->ld_config.span[0].num_blocks = info->size;
|
|
|
|
info->ld_config.span[0].array_ref = cpu_to_le16(sdev_id);
|
|
|
|
|
2021-12-16 11:36:38 +03:00
|
|
|
dma_buf_read(cmd->iov_buf, dcmd_size, &residual, &cmd->qsg,
|
|
|
|
MEMTXATTRS_UNSPECIFIED);
|
2012-05-29 15:51:17 +04:00
|
|
|
g_free(cmd->iov_buf);
|
2021-12-31 13:13:34 +03:00
|
|
|
cmd->iov_size = dcmd_size - residual;
|
2012-05-29 15:51:17 +04:00
|
|
|
cmd->iov_buf = NULL;
|
|
|
|
return MFI_STAT_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int megasas_dcmd_ld_get_info(MegasasState *s, MegasasCmd *cmd)
|
|
|
|
{
|
|
|
|
struct mfi_ld_info info;
|
|
|
|
size_t dcmd_size = sizeof(info);
|
|
|
|
uint16_t ld_id;
|
|
|
|
uint32_t max_ld_disks = s->fw_luns;
|
|
|
|
SCSIDevice *sdev = NULL;
|
|
|
|
int retval = MFI_STAT_DEVICE_NOT_FOUND;
|
|
|
|
|
|
|
|
if (cmd->iov_size < dcmd_size) {
|
|
|
|
return MFI_STAT_INVALID_PARAMETER;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* mbox0 has the ID */
|
|
|
|
ld_id = le16_to_cpu(cmd->frame->dcmd.mbox[0]);
|
|
|
|
trace_megasas_dcmd_ld_get_info(cmd->index, ld_id);
|
|
|
|
|
|
|
|
if (megasas_is_jbod(s)) {
|
|
|
|
return MFI_STAT_DEVICE_NOT_FOUND;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (ld_id < max_ld_disks) {
|
|
|
|
sdev = scsi_device_find(&s->bus, 0, ld_id, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (sdev) {
|
|
|
|
retval = megasas_ld_get_info_submit(sdev, ld_id, cmd);
|
|
|
|
}
|
|
|
|
|
|
|
|
return retval;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int megasas_dcmd_cfg_read(MegasasState *s, MegasasCmd *cmd)
|
|
|
|
{
|
2016-05-25 15:11:44 +03:00
|
|
|
uint8_t data[4096] = { 0 };
|
2012-05-29 15:51:17 +04:00
|
|
|
struct mfi_config_data *info;
|
|
|
|
int num_pd_disks = 0, array_offset, ld_offset;
|
|
|
|
BusChild *kid;
|
2021-12-16 11:36:38 +03:00
|
|
|
dma_addr_t residual;
|
2012-05-29 15:51:17 +04:00
|
|
|
|
|
|
|
if (cmd->iov_size > 4096) {
|
|
|
|
return MFI_STAT_INVALID_PARAMETER;
|
|
|
|
}
|
|
|
|
|
|
|
|
QTAILQ_FOREACH(kid, &s->bus.qbus.children, sibling) {
|
|
|
|
num_pd_disks++;
|
|
|
|
}
|
|
|
|
info = (struct mfi_config_data *)&data;
|
|
|
|
/*
|
|
|
|
* Array mapping:
|
|
|
|
* - One array per SCSI device
|
|
|
|
* - One logical drive per SCSI device
|
|
|
|
* spanning the entire device
|
|
|
|
*/
|
|
|
|
info->array_count = num_pd_disks;
|
|
|
|
info->array_size = sizeof(struct mfi_array) * num_pd_disks;
|
|
|
|
info->log_drv_count = num_pd_disks;
|
|
|
|
info->log_drv_size = sizeof(struct mfi_ld_config) * num_pd_disks;
|
|
|
|
info->spares_count = 0;
|
|
|
|
info->spares_size = sizeof(struct mfi_spare);
|
|
|
|
info->size = sizeof(struct mfi_config_data) + info->array_size +
|
|
|
|
info->log_drv_size;
|
|
|
|
if (info->size > 4096) {
|
|
|
|
return MFI_STAT_INVALID_PARAMETER;
|
|
|
|
}
|
|
|
|
|
|
|
|
array_offset = sizeof(struct mfi_config_data);
|
|
|
|
ld_offset = array_offset + sizeof(struct mfi_array) * num_pd_disks;
|
|
|
|
|
|
|
|
QTAILQ_FOREACH(kid, &s->bus.qbus.children, sibling) {
|
2016-01-06 12:37:46 +03:00
|
|
|
SCSIDevice *sdev = SCSI_DEVICE(kid->child);
|
2014-10-29 15:00:07 +03:00
|
|
|
uint16_t sdev_id = ((sdev->id & 0xFF) << 8) | (sdev->lun & 0xFF);
|
2012-05-29 15:51:17 +04:00
|
|
|
struct mfi_array *array;
|
|
|
|
struct mfi_ld_config *ld;
|
|
|
|
uint64_t pd_size;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
array = (struct mfi_array *)(data + array_offset);
|
2014-10-07 15:59:18 +04:00
|
|
|
blk_get_geometry(sdev->conf.blk, &pd_size);
|
2012-05-29 15:51:17 +04:00
|
|
|
array->size = cpu_to_le64(pd_size);
|
|
|
|
array->num_drives = 1;
|
|
|
|
array->array_ref = cpu_to_le16(sdev_id);
|
|
|
|
array->pd[0].ref.v.device_id = cpu_to_le16(sdev_id);
|
|
|
|
array->pd[0].ref.v.seq_num = 0;
|
|
|
|
array->pd[0].fw_state = MFI_PD_STATE_ONLINE;
|
|
|
|
array->pd[0].encl.pd = 0xFF;
|
|
|
|
array->pd[0].encl.slot = (sdev->id & 0xFF);
|
|
|
|
for (i = 1; i < MFI_MAX_ROW_SIZE; i++) {
|
|
|
|
array->pd[i].ref.v.device_id = 0xFFFF;
|
|
|
|
array->pd[i].ref.v.seq_num = 0;
|
|
|
|
array->pd[i].fw_state = MFI_PD_STATE_UNCONFIGURED_GOOD;
|
|
|
|
array->pd[i].encl.pd = 0xFF;
|
|
|
|
array->pd[i].encl.slot = 0xFF;
|
|
|
|
}
|
|
|
|
array_offset += sizeof(struct mfi_array);
|
|
|
|
ld = (struct mfi_ld_config *)(data + ld_offset);
|
|
|
|
memset(ld, 0, sizeof(struct mfi_ld_config));
|
2014-10-29 15:00:07 +03:00
|
|
|
ld->properties.ld.v.target_id = sdev->id;
|
2012-05-29 15:51:17 +04:00
|
|
|
ld->properties.default_cache_policy = MR_LD_CACHE_READ_AHEAD |
|
|
|
|
MR_LD_CACHE_READ_ADAPTIVE;
|
|
|
|
ld->properties.current_cache_policy = MR_LD_CACHE_READ_AHEAD |
|
|
|
|
MR_LD_CACHE_READ_ADAPTIVE;
|
|
|
|
ld->params.state = MFI_LD_STATE_OPTIMAL;
|
|
|
|
ld->params.stripe_size = 3;
|
|
|
|
ld->params.num_drives = 1;
|
|
|
|
ld->params.span_depth = 1;
|
|
|
|
ld->params.is_consistent = 1;
|
|
|
|
ld->span[0].start_block = 0;
|
|
|
|
ld->span[0].num_blocks = cpu_to_le64(pd_size);
|
|
|
|
ld->span[0].array_ref = cpu_to_le16(sdev_id);
|
|
|
|
ld_offset += sizeof(struct mfi_ld_config);
|
|
|
|
}
|
|
|
|
|
2021-12-16 11:36:38 +03:00
|
|
|
dma_buf_read(data, info->size, &residual, &cmd->qsg,
|
|
|
|
MEMTXATTRS_UNSPECIFIED);
|
|
|
|
cmd->iov_size -= residual;
|
2012-05-29 15:51:17 +04:00
|
|
|
return MFI_STAT_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int megasas_dcmd_get_properties(MegasasState *s, MegasasCmd *cmd)
|
|
|
|
{
|
|
|
|
struct mfi_ctrl_props info;
|
|
|
|
size_t dcmd_size = sizeof(info);
|
2021-12-16 11:36:38 +03:00
|
|
|
dma_addr_t residual;
|
2012-05-29 15:51:17 +04:00
|
|
|
|
|
|
|
memset(&info, 0x0, dcmd_size);
|
|
|
|
if (cmd->iov_size < dcmd_size) {
|
|
|
|
trace_megasas_dcmd_invalid_xfer_len(cmd->index, cmd->iov_size,
|
|
|
|
dcmd_size);
|
|
|
|
return MFI_STAT_INVALID_PARAMETER;
|
|
|
|
}
|
|
|
|
info.pred_fail_poll_interval = cpu_to_le16(300);
|
|
|
|
info.intr_throttle_cnt = cpu_to_le16(16);
|
|
|
|
info.intr_throttle_timeout = cpu_to_le16(50);
|
|
|
|
info.rebuild_rate = 30;
|
|
|
|
info.patrol_read_rate = 30;
|
|
|
|
info.bgi_rate = 30;
|
|
|
|
info.cc_rate = 30;
|
|
|
|
info.recon_rate = 30;
|
|
|
|
info.cache_flush_interval = 4;
|
|
|
|
info.spinup_drv_cnt = 2;
|
|
|
|
info.spinup_delay = 6;
|
|
|
|
info.ecc_bucket_size = 15;
|
|
|
|
info.ecc_bucket_leak_rate = cpu_to_le16(1440);
|
|
|
|
info.expose_encl_devices = 1;
|
|
|
|
|
2021-12-16 11:36:38 +03:00
|
|
|
dma_buf_read(&info, dcmd_size, &residual, &cmd->qsg,
|
|
|
|
MEMTXATTRS_UNSPECIFIED);
|
|
|
|
cmd->iov_size -= residual;
|
2012-05-29 15:51:17 +04:00
|
|
|
return MFI_STAT_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int megasas_cache_flush(MegasasState *s, MegasasCmd *cmd)
|
|
|
|
{
|
2014-10-07 15:59:18 +04:00
|
|
|
blk_drain_all();
|
2012-05-29 15:51:17 +04:00
|
|
|
return MFI_STAT_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int megasas_ctrl_shutdown(MegasasState *s, MegasasCmd *cmd)
|
|
|
|
{
|
|
|
|
s->fw_state = MFI_FWSTATE_READY;
|
|
|
|
return MFI_STAT_OK;
|
|
|
|
}
|
|
|
|
|
2014-10-29 15:00:13 +03:00
|
|
|
/* Some implementations use CLUSTER RESET LD to simulate a device reset */
|
2012-05-29 15:51:17 +04:00
|
|
|
static int megasas_cluster_reset_ld(MegasasState *s, MegasasCmd *cmd)
|
|
|
|
{
|
2014-10-29 15:00:13 +03:00
|
|
|
uint16_t target_id;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
/* mbox0 contains the device index */
|
|
|
|
target_id = le16_to_cpu(cmd->frame->dcmd.mbox[0]);
|
|
|
|
trace_megasas_dcmd_reset_ld(cmd->index, target_id);
|
|
|
|
for (i = 0; i < s->fw_cmds; i++) {
|
|
|
|
MegasasCmd *tmp_cmd = &s->frames[i];
|
|
|
|
if (tmp_cmd->req && tmp_cmd->req->dev->id == target_id) {
|
|
|
|
SCSIDevice *d = tmp_cmd->req->dev;
|
2022-10-13 19:06:22 +03:00
|
|
|
device_cold_reset(&d->qdev);
|
2014-10-29 15:00:13 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return MFI_STAT_OK;
|
2012-05-29 15:51:17 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
static int megasas_dcmd_set_properties(MegasasState *s, MegasasCmd *cmd)
|
|
|
|
{
|
2012-07-11 15:35:16 +04:00
|
|
|
struct mfi_ctrl_props info;
|
|
|
|
size_t dcmd_size = sizeof(info);
|
|
|
|
|
|
|
|
if (cmd->iov_size < dcmd_size) {
|
|
|
|
trace_megasas_dcmd_invalid_xfer_len(cmd->index, cmd->iov_size,
|
|
|
|
dcmd_size);
|
|
|
|
return MFI_STAT_INVALID_PARAMETER;
|
|
|
|
}
|
2021-12-16 11:36:38 +03:00
|
|
|
dma_buf_write(&info, dcmd_size, NULL, &cmd->qsg, MEMTXATTRS_UNSPECIFIED);
|
2012-07-11 15:35:16 +04:00
|
|
|
trace_megasas_dcmd_unsupported(cmd->index, cmd->iov_size);
|
2012-05-29 15:51:17 +04:00
|
|
|
return MFI_STAT_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int megasas_dcmd_dummy(MegasasState *s, MegasasCmd *cmd)
|
|
|
|
{
|
|
|
|
trace_megasas_dcmd_dummy(cmd->index, cmd->iov_size);
|
|
|
|
return MFI_STAT_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
static const struct dcmd_cmd_tbl_t {
|
|
|
|
int opcode;
|
|
|
|
const char *desc;
|
|
|
|
int (*func)(MegasasState *s, MegasasCmd *cmd);
|
|
|
|
} dcmd_cmd_tbl[] = {
|
|
|
|
{ MFI_DCMD_CTRL_MFI_HOST_MEM_ALLOC, "CTRL_HOST_MEM_ALLOC",
|
|
|
|
megasas_dcmd_dummy },
|
|
|
|
{ MFI_DCMD_CTRL_GET_INFO, "CTRL_GET_INFO",
|
|
|
|
megasas_ctrl_get_info },
|
|
|
|
{ MFI_DCMD_CTRL_GET_PROPERTIES, "CTRL_GET_PROPERTIES",
|
|
|
|
megasas_dcmd_get_properties },
|
|
|
|
{ MFI_DCMD_CTRL_SET_PROPERTIES, "CTRL_SET_PROPERTIES",
|
|
|
|
megasas_dcmd_set_properties },
|
|
|
|
{ MFI_DCMD_CTRL_ALARM_GET, "CTRL_ALARM_GET",
|
|
|
|
megasas_dcmd_dummy },
|
|
|
|
{ MFI_DCMD_CTRL_ALARM_ENABLE, "CTRL_ALARM_ENABLE",
|
|
|
|
megasas_dcmd_dummy },
|
|
|
|
{ MFI_DCMD_CTRL_ALARM_DISABLE, "CTRL_ALARM_DISABLE",
|
|
|
|
megasas_dcmd_dummy },
|
|
|
|
{ MFI_DCMD_CTRL_ALARM_SILENCE, "CTRL_ALARM_SILENCE",
|
|
|
|
megasas_dcmd_dummy },
|
|
|
|
{ MFI_DCMD_CTRL_ALARM_TEST, "CTRL_ALARM_TEST",
|
|
|
|
megasas_dcmd_dummy },
|
|
|
|
{ MFI_DCMD_CTRL_EVENT_GETINFO, "CTRL_EVENT_GETINFO",
|
|
|
|
megasas_event_info },
|
|
|
|
{ MFI_DCMD_CTRL_EVENT_GET, "CTRL_EVENT_GET",
|
|
|
|
megasas_dcmd_dummy },
|
|
|
|
{ MFI_DCMD_CTRL_EVENT_WAIT, "CTRL_EVENT_WAIT",
|
|
|
|
megasas_event_wait },
|
|
|
|
{ MFI_DCMD_CTRL_SHUTDOWN, "CTRL_SHUTDOWN",
|
|
|
|
megasas_ctrl_shutdown },
|
|
|
|
{ MFI_DCMD_HIBERNATE_STANDBY, "CTRL_STANDBY",
|
|
|
|
megasas_dcmd_dummy },
|
|
|
|
{ MFI_DCMD_CTRL_GET_TIME, "CTRL_GET_TIME",
|
|
|
|
megasas_dcmd_get_fw_time },
|
|
|
|
{ MFI_DCMD_CTRL_SET_TIME, "CTRL_SET_TIME",
|
|
|
|
megasas_dcmd_set_fw_time },
|
|
|
|
{ MFI_DCMD_CTRL_BIOS_DATA_GET, "CTRL_BIOS_DATA_GET",
|
|
|
|
megasas_dcmd_get_bios_info },
|
|
|
|
{ MFI_DCMD_CTRL_FACTORY_DEFAULTS, "CTRL_FACTORY_DEFAULTS",
|
|
|
|
megasas_dcmd_dummy },
|
|
|
|
{ MFI_DCMD_CTRL_MFC_DEFAULTS_GET, "CTRL_MFC_DEFAULTS_GET",
|
|
|
|
megasas_mfc_get_defaults },
|
|
|
|
{ MFI_DCMD_CTRL_MFC_DEFAULTS_SET, "CTRL_MFC_DEFAULTS_SET",
|
|
|
|
megasas_dcmd_dummy },
|
|
|
|
{ MFI_DCMD_CTRL_CACHE_FLUSH, "CTRL_CACHE_FLUSH",
|
|
|
|
megasas_cache_flush },
|
|
|
|
{ MFI_DCMD_PD_GET_LIST, "PD_GET_LIST",
|
|
|
|
megasas_dcmd_pd_get_list },
|
|
|
|
{ MFI_DCMD_PD_LIST_QUERY, "PD_LIST_QUERY",
|
|
|
|
megasas_dcmd_pd_list_query },
|
|
|
|
{ MFI_DCMD_PD_GET_INFO, "PD_GET_INFO",
|
|
|
|
megasas_dcmd_pd_get_info },
|
|
|
|
{ MFI_DCMD_PD_STATE_SET, "PD_STATE_SET",
|
|
|
|
megasas_dcmd_dummy },
|
|
|
|
{ MFI_DCMD_PD_REBUILD, "PD_REBUILD",
|
|
|
|
megasas_dcmd_dummy },
|
|
|
|
{ MFI_DCMD_PD_BLINK, "PD_BLINK",
|
|
|
|
megasas_dcmd_dummy },
|
|
|
|
{ MFI_DCMD_PD_UNBLINK, "PD_UNBLINK",
|
|
|
|
megasas_dcmd_dummy },
|
|
|
|
{ MFI_DCMD_LD_GET_LIST, "LD_GET_LIST",
|
|
|
|
megasas_dcmd_ld_get_list},
|
2014-04-16 18:44:13 +04:00
|
|
|
{ MFI_DCMD_LD_LIST_QUERY, "LD_LIST_QUERY",
|
|
|
|
megasas_dcmd_ld_list_query },
|
2012-05-29 15:51:17 +04:00
|
|
|
{ MFI_DCMD_LD_GET_INFO, "LD_GET_INFO",
|
|
|
|
megasas_dcmd_ld_get_info },
|
|
|
|
{ MFI_DCMD_LD_GET_PROP, "LD_GET_PROP",
|
|
|
|
megasas_dcmd_dummy },
|
|
|
|
{ MFI_DCMD_LD_SET_PROP, "LD_SET_PROP",
|
|
|
|
megasas_dcmd_dummy },
|
|
|
|
{ MFI_DCMD_LD_DELETE, "LD_DELETE",
|
|
|
|
megasas_dcmd_dummy },
|
|
|
|
{ MFI_DCMD_CFG_READ, "CFG_READ",
|
|
|
|
megasas_dcmd_cfg_read },
|
|
|
|
{ MFI_DCMD_CFG_ADD, "CFG_ADD",
|
|
|
|
megasas_dcmd_dummy },
|
|
|
|
{ MFI_DCMD_CFG_CLEAR, "CFG_CLEAR",
|
|
|
|
megasas_dcmd_dummy },
|
|
|
|
{ MFI_DCMD_CFG_FOREIGN_READ, "CFG_FOREIGN_READ",
|
|
|
|
megasas_dcmd_dummy },
|
|
|
|
{ MFI_DCMD_CFG_FOREIGN_IMPORT, "CFG_FOREIGN_IMPORT",
|
|
|
|
megasas_dcmd_dummy },
|
|
|
|
{ MFI_DCMD_BBU_STATUS, "BBU_STATUS",
|
|
|
|
megasas_dcmd_dummy },
|
|
|
|
{ MFI_DCMD_BBU_CAPACITY_INFO, "BBU_CAPACITY_INFO",
|
|
|
|
megasas_dcmd_dummy },
|
|
|
|
{ MFI_DCMD_BBU_DESIGN_INFO, "BBU_DESIGN_INFO",
|
|
|
|
megasas_dcmd_dummy },
|
|
|
|
{ MFI_DCMD_BBU_PROP_GET, "BBU_PROP_GET",
|
|
|
|
megasas_dcmd_dummy },
|
|
|
|
{ MFI_DCMD_CLUSTER, "CLUSTER",
|
|
|
|
megasas_dcmd_dummy },
|
|
|
|
{ MFI_DCMD_CLUSTER_RESET_ALL, "CLUSTER_RESET_ALL",
|
|
|
|
megasas_dcmd_dummy },
|
|
|
|
{ MFI_DCMD_CLUSTER_RESET_LD, "CLUSTER_RESET_LD",
|
|
|
|
megasas_cluster_reset_ld },
|
|
|
|
{ -1, NULL, NULL }
|
|
|
|
};
|
|
|
|
|
|
|
|
static int megasas_handle_dcmd(MegasasState *s, MegasasCmd *cmd)
|
|
|
|
{
|
|
|
|
int retval = 0;
|
2017-01-02 13:03:33 +03:00
|
|
|
size_t len;
|
2012-05-29 15:51:17 +04:00
|
|
|
const struct dcmd_cmd_tbl_t *cmdptr = dcmd_cmd_tbl;
|
|
|
|
|
2017-06-01 18:18:23 +03:00
|
|
|
cmd->dcmd_opcode = le32_to_cpu(cmd->frame->dcmd.opcode);
|
|
|
|
trace_megasas_handle_dcmd(cmd->index, cmd->dcmd_opcode);
|
2017-01-02 13:03:33 +03:00
|
|
|
if (megasas_map_dcmd(s, cmd) < 0) {
|
2012-05-29 15:51:17 +04:00
|
|
|
return MFI_STAT_MEMORY_NOT_AVAILABLE;
|
|
|
|
}
|
2017-06-01 18:18:23 +03:00
|
|
|
while (cmdptr->opcode != -1 && cmdptr->opcode != cmd->dcmd_opcode) {
|
2012-05-29 15:51:17 +04:00
|
|
|
cmdptr++;
|
|
|
|
}
|
2017-01-02 13:03:33 +03:00
|
|
|
len = cmd->iov_size;
|
2012-05-29 15:51:17 +04:00
|
|
|
if (cmdptr->opcode == -1) {
|
2017-06-01 18:18:23 +03:00
|
|
|
trace_megasas_dcmd_unhandled(cmd->index, cmd->dcmd_opcode, len);
|
2012-05-29 15:51:17 +04:00
|
|
|
retval = megasas_dcmd_dummy(s, cmd);
|
|
|
|
} else {
|
|
|
|
trace_megasas_dcmd_enter(cmd->index, cmdptr->desc, len);
|
|
|
|
retval = cmdptr->func(s, cmd);
|
|
|
|
}
|
|
|
|
if (retval != MFI_STAT_INVALID_STATUS) {
|
|
|
|
megasas_finish_dcmd(cmd, len);
|
|
|
|
}
|
|
|
|
return retval;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int megasas_finish_internal_dcmd(MegasasCmd *cmd,
|
2021-12-31 13:33:29 +03:00
|
|
|
SCSIRequest *req, dma_addr_t residual)
|
2012-05-29 15:51:17 +04:00
|
|
|
{
|
|
|
|
int retval = MFI_STAT_OK;
|
|
|
|
int lun = req->lun;
|
|
|
|
|
2017-06-01 18:18:23 +03:00
|
|
|
trace_megasas_dcmd_internal_finish(cmd->index, cmd->dcmd_opcode, lun);
|
2021-12-31 13:13:34 +03:00
|
|
|
cmd->iov_size -= residual;
|
2017-06-01 18:18:23 +03:00
|
|
|
switch (cmd->dcmd_opcode) {
|
2012-05-29 15:51:17 +04:00
|
|
|
case MFI_DCMD_PD_GET_INFO:
|
|
|
|
retval = megasas_pd_get_info_submit(req->dev, lun, cmd);
|
|
|
|
break;
|
|
|
|
case MFI_DCMD_LD_GET_INFO:
|
|
|
|
retval = megasas_ld_get_info_submit(req->dev, lun, cmd);
|
|
|
|
break;
|
|
|
|
default:
|
2017-06-01 18:18:23 +03:00
|
|
|
trace_megasas_dcmd_internal_invalid(cmd->index, cmd->dcmd_opcode);
|
2012-05-29 15:51:17 +04:00
|
|
|
retval = MFI_STAT_INVALID_DCMD;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (retval != MFI_STAT_INVALID_STATUS) {
|
|
|
|
megasas_finish_dcmd(cmd, cmd->iov_size);
|
|
|
|
}
|
|
|
|
return retval;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int megasas_enqueue_req(MegasasCmd *cmd, bool is_write)
|
|
|
|
{
|
|
|
|
int len;
|
|
|
|
|
|
|
|
len = scsi_req_enqueue(cmd->req);
|
|
|
|
if (len < 0) {
|
|
|
|
len = -len;
|
|
|
|
}
|
|
|
|
if (len > 0) {
|
|
|
|
if (len > cmd->iov_size) {
|
|
|
|
if (is_write) {
|
|
|
|
trace_megasas_iov_write_overflow(cmd->index, len,
|
|
|
|
cmd->iov_size);
|
|
|
|
} else {
|
|
|
|
trace_megasas_iov_read_overflow(cmd->index, len,
|
|
|
|
cmd->iov_size);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (len < cmd->iov_size) {
|
|
|
|
if (is_write) {
|
|
|
|
trace_megasas_iov_write_underflow(cmd->index, len,
|
|
|
|
cmd->iov_size);
|
|
|
|
} else {
|
|
|
|
trace_megasas_iov_read_underflow(cmd->index, len,
|
|
|
|
cmd->iov_size);
|
|
|
|
}
|
|
|
|
cmd->iov_size = len;
|
|
|
|
}
|
|
|
|
scsi_req_continue(cmd->req);
|
|
|
|
}
|
|
|
|
return len;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int megasas_handle_scsi(MegasasState *s, MegasasCmd *cmd,
|
2017-06-01 18:23:13 +03:00
|
|
|
int frame_cmd)
|
2012-05-29 15:51:17 +04:00
|
|
|
{
|
|
|
|
uint8_t *cdb;
|
2017-06-01 18:25:03 +03:00
|
|
|
int target_id, lun_id, cdb_len;
|
2012-05-29 15:51:17 +04:00
|
|
|
bool is_write;
|
|
|
|
struct SCSIDevice *sdev = NULL;
|
2017-06-01 18:23:13 +03:00
|
|
|
bool is_logical = (frame_cmd == MFI_CMD_LD_SCSI_IO);
|
2012-05-29 15:51:17 +04:00
|
|
|
|
|
|
|
cdb = cmd->frame->pass.cdb;
|
2017-06-01 18:25:03 +03:00
|
|
|
target_id = cmd->frame->header.target_id;
|
|
|
|
lun_id = cmd->frame->header.lun_id;
|
|
|
|
cdb_len = cmd->frame->header.cdb_len;
|
2012-05-29 15:51:17 +04:00
|
|
|
|
2014-10-29 15:00:07 +03:00
|
|
|
if (is_logical) {
|
2017-06-01 18:25:03 +03:00
|
|
|
if (target_id >= MFI_MAX_LD || lun_id != 0) {
|
2014-10-29 15:00:07 +03:00
|
|
|
trace_megasas_scsi_target_not_present(
|
2020-06-15 10:26:29 +03:00
|
|
|
mfi_frame_desc(frame_cmd), is_logical, target_id, lun_id);
|
2014-10-29 15:00:07 +03:00
|
|
|
return MFI_STAT_DEVICE_NOT_FOUND;
|
|
|
|
}
|
2012-05-29 15:51:17 +04:00
|
|
|
}
|
2017-06-01 18:25:03 +03:00
|
|
|
sdev = scsi_device_find(&s->bus, 0, target_id, lun_id);
|
2014-10-29 15:00:07 +03:00
|
|
|
|
2012-05-29 15:51:17 +04:00
|
|
|
cmd->iov_size = le32_to_cpu(cmd->frame->header.data_len);
|
2020-06-15 10:26:29 +03:00
|
|
|
trace_megasas_handle_scsi(mfi_frame_desc(frame_cmd), is_logical,
|
2017-06-01 18:25:03 +03:00
|
|
|
target_id, lun_id, sdev, cmd->iov_size);
|
2012-05-29 15:51:17 +04:00
|
|
|
|
|
|
|
if (!sdev || (megasas_is_jbod(s) && is_logical)) {
|
|
|
|
trace_megasas_scsi_target_not_present(
|
2020-06-15 10:26:29 +03:00
|
|
|
mfi_frame_desc(frame_cmd), is_logical, target_id, lun_id);
|
2012-05-29 15:51:17 +04:00
|
|
|
return MFI_STAT_DEVICE_NOT_FOUND;
|
|
|
|
}
|
|
|
|
|
2017-06-01 18:25:03 +03:00
|
|
|
if (cdb_len > 16) {
|
2012-05-29 15:51:17 +04:00
|
|
|
trace_megasas_scsi_invalid_cdb_len(
|
2020-06-15 10:26:29 +03:00
|
|
|
mfi_frame_desc(frame_cmd), is_logical,
|
2017-06-01 18:25:03 +03:00
|
|
|
target_id, lun_id, cdb_len);
|
2012-05-29 15:51:17 +04:00
|
|
|
megasas_write_sense(cmd, SENSE_CODE(INVALID_OPCODE));
|
|
|
|
cmd->frame->header.scsi_status = CHECK_CONDITION;
|
|
|
|
s->event_count++;
|
|
|
|
return MFI_STAT_SCSI_DONE_WITH_ERROR;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (megasas_map_sgl(s, cmd, &cmd->frame->pass.sgl)) {
|
|
|
|
megasas_write_sense(cmd, SENSE_CODE(TARGET_FAILURE));
|
|
|
|
cmd->frame->header.scsi_status = CHECK_CONDITION;
|
|
|
|
s->event_count++;
|
|
|
|
return MFI_STAT_SCSI_DONE_WITH_ERROR;
|
|
|
|
}
|
|
|
|
|
2022-08-17 08:34:58 +03:00
|
|
|
cmd->req = scsi_req_new(sdev, cmd->index, lun_id, cdb, cdb_len, cmd);
|
2012-05-29 15:51:17 +04:00
|
|
|
if (!cmd->req) {
|
|
|
|
trace_megasas_scsi_req_alloc_failed(
|
2020-06-15 10:26:29 +03:00
|
|
|
mfi_frame_desc(frame_cmd), target_id, lun_id);
|
2012-05-29 15:51:17 +04:00
|
|
|
megasas_write_sense(cmd, SENSE_CODE(NO_SENSE));
|
|
|
|
cmd->frame->header.scsi_status = BUSY;
|
|
|
|
s->event_count++;
|
|
|
|
return MFI_STAT_SCSI_DONE_WITH_ERROR;
|
|
|
|
}
|
|
|
|
|
|
|
|
is_write = (cmd->req->cmd.mode == SCSI_XFER_TO_DEV);
|
2014-10-29 15:00:14 +03:00
|
|
|
if (cmd->iov_size) {
|
2012-05-29 15:51:17 +04:00
|
|
|
if (is_write) {
|
2014-10-29 15:00:14 +03:00
|
|
|
trace_megasas_scsi_write_start(cmd->index, cmd->iov_size);
|
2012-05-29 15:51:17 +04:00
|
|
|
} else {
|
2014-10-29 15:00:14 +03:00
|
|
|
trace_megasas_scsi_read_start(cmd->index, cmd->iov_size);
|
2012-05-29 15:51:17 +04:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
trace_megasas_scsi_nodata(cmd->index);
|
|
|
|
}
|
2014-10-29 15:00:14 +03:00
|
|
|
megasas_enqueue_req(cmd, is_write);
|
2012-05-29 15:51:17 +04:00
|
|
|
return MFI_STAT_INVALID_STATUS;
|
|
|
|
}
|
|
|
|
|
2017-06-01 18:23:13 +03:00
|
|
|
static int megasas_handle_io(MegasasState *s, MegasasCmd *cmd, int frame_cmd)
|
2012-05-29 15:51:17 +04:00
|
|
|
{
|
|
|
|
uint32_t lba_count, lba_start_hi, lba_start_lo;
|
|
|
|
uint64_t lba_start;
|
2017-06-01 18:23:13 +03:00
|
|
|
bool is_write = (frame_cmd == MFI_CMD_LD_WRITE);
|
2012-05-29 15:51:17 +04:00
|
|
|
uint8_t cdb[16];
|
|
|
|
int len;
|
|
|
|
struct SCSIDevice *sdev = NULL;
|
2017-06-01 18:25:03 +03:00
|
|
|
int target_id, lun_id, cdb_len;
|
2012-05-29 15:51:17 +04:00
|
|
|
|
|
|
|
lba_count = le32_to_cpu(cmd->frame->io.header.data_len);
|
|
|
|
lba_start_lo = le32_to_cpu(cmd->frame->io.lba_lo);
|
|
|
|
lba_start_hi = le32_to_cpu(cmd->frame->io.lba_hi);
|
|
|
|
lba_start = ((uint64_t)lba_start_hi << 32) | lba_start_lo;
|
|
|
|
|
2017-06-01 18:25:03 +03:00
|
|
|
target_id = cmd->frame->header.target_id;
|
|
|
|
lun_id = cmd->frame->header.lun_id;
|
|
|
|
cdb_len = cmd->frame->header.cdb_len;
|
|
|
|
|
|
|
|
if (target_id < MFI_MAX_LD && lun_id == 0) {
|
|
|
|
sdev = scsi_device_find(&s->bus, 0, target_id, lun_id);
|
2012-05-29 15:51:17 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
trace_megasas_handle_io(cmd->index,
|
2020-06-15 10:26:29 +03:00
|
|
|
mfi_frame_desc(frame_cmd), target_id, lun_id,
|
2012-05-29 15:51:17 +04:00
|
|
|
(unsigned long)lba_start, (unsigned long)lba_count);
|
|
|
|
if (!sdev) {
|
|
|
|
trace_megasas_io_target_not_present(cmd->index,
|
2020-06-15 10:26:29 +03:00
|
|
|
mfi_frame_desc(frame_cmd), target_id, lun_id);
|
2012-05-29 15:51:17 +04:00
|
|
|
return MFI_STAT_DEVICE_NOT_FOUND;
|
|
|
|
}
|
|
|
|
|
2017-06-01 18:25:03 +03:00
|
|
|
if (cdb_len > 16) {
|
2012-05-29 15:51:17 +04:00
|
|
|
trace_megasas_scsi_invalid_cdb_len(
|
2020-06-15 10:26:29 +03:00
|
|
|
mfi_frame_desc(frame_cmd), 1, target_id, lun_id, cdb_len);
|
2012-05-29 15:51:17 +04:00
|
|
|
megasas_write_sense(cmd, SENSE_CODE(INVALID_OPCODE));
|
|
|
|
cmd->frame->header.scsi_status = CHECK_CONDITION;
|
|
|
|
s->event_count++;
|
|
|
|
return MFI_STAT_SCSI_DONE_WITH_ERROR;
|
|
|
|
}
|
|
|
|
|
|
|
|
cmd->iov_size = lba_count * sdev->blocksize;
|
|
|
|
if (megasas_map_sgl(s, cmd, &cmd->frame->io.sgl)) {
|
|
|
|
megasas_write_sense(cmd, SENSE_CODE(TARGET_FAILURE));
|
|
|
|
cmd->frame->header.scsi_status = CHECK_CONDITION;
|
|
|
|
s->event_count++;
|
|
|
|
return MFI_STAT_SCSI_DONE_WITH_ERROR;
|
|
|
|
}
|
|
|
|
|
|
|
|
megasas_encode_lba(cdb, lba_start, lba_count, is_write);
|
|
|
|
cmd->req = scsi_req_new(sdev, cmd->index,
|
2022-08-17 08:34:58 +03:00
|
|
|
lun_id, cdb, cdb_len, cmd);
|
2012-05-29 15:51:17 +04:00
|
|
|
if (!cmd->req) {
|
|
|
|
trace_megasas_scsi_req_alloc_failed(
|
2020-06-15 10:26:29 +03:00
|
|
|
mfi_frame_desc(frame_cmd), target_id, lun_id);
|
2012-05-29 15:51:17 +04:00
|
|
|
megasas_write_sense(cmd, SENSE_CODE(NO_SENSE));
|
|
|
|
cmd->frame->header.scsi_status = BUSY;
|
|
|
|
s->event_count++;
|
|
|
|
return MFI_STAT_SCSI_DONE_WITH_ERROR;
|
|
|
|
}
|
|
|
|
len = megasas_enqueue_req(cmd, is_write);
|
|
|
|
if (len > 0) {
|
|
|
|
if (is_write) {
|
|
|
|
trace_megasas_io_write_start(cmd->index, lba_start, lba_count, len);
|
|
|
|
} else {
|
|
|
|
trace_megasas_io_read_start(cmd->index, lba_start, lba_count, len);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return MFI_STAT_INVALID_STATUS;
|
|
|
|
}
|
|
|
|
|
|
|
|
static QEMUSGList *megasas_get_sg_list(SCSIRequest *req)
|
|
|
|
{
|
|
|
|
MegasasCmd *cmd = req->hba_private;
|
|
|
|
|
2017-06-01 18:23:13 +03:00
|
|
|
if (cmd->dcmd_opcode != -1) {
|
2012-05-29 15:51:17 +04:00
|
|
|
return NULL;
|
|
|
|
} else {
|
|
|
|
return &cmd->qsg;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void megasas_xfer_complete(SCSIRequest *req, uint32_t len)
|
|
|
|
{
|
|
|
|
MegasasCmd *cmd = req->hba_private;
|
|
|
|
uint8_t *buf;
|
|
|
|
|
|
|
|
trace_megasas_io_complete(cmd->index, len);
|
|
|
|
|
2017-06-01 18:23:13 +03:00
|
|
|
if (cmd->dcmd_opcode != -1) {
|
2012-05-29 15:51:17 +04:00
|
|
|
scsi_req_continue(req);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
buf = scsi_req_get_buf(req);
|
2017-06-01 18:18:23 +03:00
|
|
|
if (cmd->dcmd_opcode == MFI_DCMD_PD_GET_INFO && cmd->iov_buf) {
|
2012-05-29 15:51:17 +04:00
|
|
|
struct mfi_pd_info *info = cmd->iov_buf;
|
|
|
|
|
|
|
|
if (info->inquiry_data[0] == 0x7f) {
|
|
|
|
memset(info->inquiry_data, 0, sizeof(info->inquiry_data));
|
|
|
|
memcpy(info->inquiry_data, buf, len);
|
|
|
|
} else if (info->vpd_page83[0] == 0x7f) {
|
|
|
|
memset(info->vpd_page83, 0, sizeof(info->vpd_page83));
|
|
|
|
memcpy(info->vpd_page83, buf, len);
|
|
|
|
}
|
|
|
|
scsi_req_continue(req);
|
2017-06-01 18:18:23 +03:00
|
|
|
} else if (cmd->dcmd_opcode == MFI_DCMD_LD_GET_INFO) {
|
2012-05-29 15:51:17 +04:00
|
|
|
struct mfi_ld_info *info = cmd->iov_buf;
|
|
|
|
|
|
|
|
if (cmd->iov_buf) {
|
|
|
|
memcpy(info->vpd_page83, buf, sizeof(info->vpd_page83));
|
|
|
|
scsi_req_continue(req);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-12-31 13:13:34 +03:00
|
|
|
static void megasas_command_complete(SCSIRequest *req, size_t residual)
|
2012-05-29 15:51:17 +04:00
|
|
|
{
|
|
|
|
MegasasCmd *cmd = req->hba_private;
|
|
|
|
uint8_t cmd_status = MFI_STAT_OK;
|
|
|
|
|
2021-12-31 13:13:34 +03:00
|
|
|
trace_megasas_command_complete(cmd->index, req->status, residual);
|
2012-05-29 15:51:17 +04:00
|
|
|
|
2016-11-10 18:27:51 +03:00
|
|
|
if (req->io_canceled) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-06-01 18:26:14 +03:00
|
|
|
if (cmd->dcmd_opcode != -1) {
|
2012-05-29 15:51:17 +04:00
|
|
|
/*
|
|
|
|
* Internal command complete
|
|
|
|
*/
|
2021-12-31 13:13:34 +03:00
|
|
|
cmd_status = megasas_finish_internal_dcmd(cmd, req, residual);
|
2012-05-29 15:51:17 +04:00
|
|
|
if (cmd_status == MFI_STAT_INVALID_STATUS) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
trace_megasas_scsi_complete(cmd->index, req->status,
|
|
|
|
cmd->iov_size, req->cmd.xfer);
|
|
|
|
if (req->status != GOOD) {
|
|
|
|
cmd_status = MFI_STAT_SCSI_DONE_WITH_ERROR;
|
|
|
|
}
|
|
|
|
if (req->status == CHECK_CONDITION) {
|
|
|
|
megasas_copy_sense(cmd);
|
|
|
|
}
|
|
|
|
|
|
|
|
cmd->frame->header.scsi_status = req->status;
|
|
|
|
}
|
|
|
|
cmd->frame->header.cmd_status = cmd_status;
|
2016-11-10 18:27:51 +03:00
|
|
|
megasas_complete_command(cmd);
|
2012-05-29 15:51:17 +04:00
|
|
|
}
|
|
|
|
|
2016-11-10 18:27:51 +03:00
|
|
|
static void megasas_command_cancelled(SCSIRequest *req)
|
2012-05-29 15:51:17 +04:00
|
|
|
{
|
|
|
|
MegasasCmd *cmd = req->hba_private;
|
|
|
|
|
2016-11-10 18:27:51 +03:00
|
|
|
if (!cmd) {
|
|
|
|
return;
|
2012-05-29 15:51:17 +04:00
|
|
|
}
|
2016-11-10 18:27:51 +03:00
|
|
|
cmd->frame->header.cmd_status = MFI_STAT_SCSI_IO_FAILED;
|
|
|
|
megasas_complete_command(cmd);
|
2012-05-29 15:51:17 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
static int megasas_handle_abort(MegasasState *s, MegasasCmd *cmd)
|
|
|
|
{
|
|
|
|
uint64_t abort_ctx = le64_to_cpu(cmd->frame->abort.abort_context);
|
2012-10-23 14:30:10 +04:00
|
|
|
hwaddr abort_addr, addr_hi, addr_lo;
|
2012-05-29 15:51:17 +04:00
|
|
|
MegasasCmd *abort_cmd;
|
|
|
|
|
|
|
|
addr_hi = le32_to_cpu(cmd->frame->abort.abort_mfi_addr_hi);
|
|
|
|
addr_lo = le32_to_cpu(cmd->frame->abort.abort_mfi_addr_lo);
|
|
|
|
abort_addr = ((uint64_t)addr_hi << 32) | addr_lo;
|
|
|
|
|
|
|
|
abort_cmd = megasas_lookup_frame(s, abort_addr);
|
|
|
|
if (!abort_cmd) {
|
|
|
|
trace_megasas_abort_no_cmd(cmd->index, abort_ctx);
|
|
|
|
s->event_count++;
|
|
|
|
return MFI_STAT_OK;
|
|
|
|
}
|
|
|
|
if (!megasas_use_queue64(s)) {
|
|
|
|
abort_ctx &= (uint64_t)0xFFFFFFFF;
|
|
|
|
}
|
|
|
|
if (abort_cmd->context != abort_ctx) {
|
2017-03-13 22:55:19 +03:00
|
|
|
trace_megasas_abort_invalid_context(cmd->index, abort_cmd->context,
|
|
|
|
abort_cmd->index);
|
2012-05-29 15:51:17 +04:00
|
|
|
s->event_count++;
|
|
|
|
return MFI_STAT_ABORT_NOT_POSSIBLE;
|
|
|
|
}
|
|
|
|
trace_megasas_abort_frame(cmd->index, abort_cmd->index);
|
|
|
|
megasas_abort_command(abort_cmd);
|
|
|
|
if (!s->event_cmd || abort_cmd != s->event_cmd) {
|
|
|
|
s->event_cmd = NULL;
|
|
|
|
}
|
|
|
|
s->event_count++;
|
|
|
|
return MFI_STAT_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void megasas_handle_frame(MegasasState *s, uint64_t frame_addr,
|
|
|
|
uint32_t frame_count)
|
|
|
|
{
|
|
|
|
uint8_t frame_status = MFI_STAT_INVALID_CMD;
|
|
|
|
uint64_t frame_context;
|
2017-06-01 18:23:13 +03:00
|
|
|
int frame_cmd;
|
2012-05-29 15:51:17 +04:00
|
|
|
MegasasCmd *cmd;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Always read 64bit context, top bits will be
|
|
|
|
* masked out if required in megasas_enqueue_frame()
|
|
|
|
*/
|
2015-03-23 19:15:17 +03:00
|
|
|
frame_context = megasas_frame_get_context(s, frame_addr);
|
2012-05-29 15:51:17 +04:00
|
|
|
|
|
|
|
cmd = megasas_enqueue_frame(s, frame_addr, frame_context, frame_count);
|
|
|
|
if (!cmd) {
|
|
|
|
/* reply queue full */
|
|
|
|
trace_megasas_frame_busy(frame_addr);
|
2015-03-23 19:15:17 +03:00
|
|
|
megasas_frame_set_scsi_status(s, frame_addr, BUSY);
|
|
|
|
megasas_frame_set_cmd_status(s, frame_addr, MFI_STAT_SCSI_DONE_WITH_ERROR);
|
2012-05-29 15:51:17 +04:00
|
|
|
megasas_complete_frame(s, frame_context);
|
|
|
|
s->event_count++;
|
|
|
|
return;
|
|
|
|
}
|
2017-06-01 18:23:13 +03:00
|
|
|
frame_cmd = cmd->frame->header.frame_cmd;
|
|
|
|
switch (frame_cmd) {
|
2012-05-29 15:51:17 +04:00
|
|
|
case MFI_CMD_INIT:
|
|
|
|
frame_status = megasas_init_firmware(s, cmd);
|
|
|
|
break;
|
|
|
|
case MFI_CMD_DCMD:
|
|
|
|
frame_status = megasas_handle_dcmd(s, cmd);
|
|
|
|
break;
|
|
|
|
case MFI_CMD_ABORT:
|
|
|
|
frame_status = megasas_handle_abort(s, cmd);
|
|
|
|
break;
|
|
|
|
case MFI_CMD_PD_SCSI_IO:
|
|
|
|
case MFI_CMD_LD_SCSI_IO:
|
2017-06-01 18:23:13 +03:00
|
|
|
frame_status = megasas_handle_scsi(s, cmd, frame_cmd);
|
2012-05-29 15:51:17 +04:00
|
|
|
break;
|
|
|
|
case MFI_CMD_LD_READ:
|
|
|
|
case MFI_CMD_LD_WRITE:
|
2017-06-01 18:23:13 +03:00
|
|
|
frame_status = megasas_handle_io(s, cmd, frame_cmd);
|
2012-05-29 15:51:17 +04:00
|
|
|
break;
|
|
|
|
default:
|
2017-06-01 18:23:13 +03:00
|
|
|
trace_megasas_unhandled_frame_cmd(cmd->index, frame_cmd);
|
2012-05-29 15:51:17 +04:00
|
|
|
s->event_count++;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (frame_status != MFI_STAT_INVALID_STATUS) {
|
2016-09-08 18:42:53 +03:00
|
|
|
if (cmd->frame) {
|
|
|
|
cmd->frame->header.cmd_status = frame_status;
|
|
|
|
} else {
|
|
|
|
megasas_frame_set_cmd_status(s, frame_addr, frame_status);
|
|
|
|
}
|
2014-10-29 15:00:15 +03:00
|
|
|
megasas_unmap_frame(s, cmd);
|
2012-05-29 15:51:17 +04:00
|
|
|
megasas_complete_frame(s, cmd->context);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-10-23 14:30:10 +04:00
|
|
|
static uint64_t megasas_mmio_read(void *opaque, hwaddr addr,
|
2012-05-29 15:51:17 +04:00
|
|
|
unsigned size)
|
|
|
|
{
|
|
|
|
MegasasState *s = opaque;
|
2014-10-29 15:00:08 +03:00
|
|
|
PCIDevice *pci_dev = PCI_DEVICE(s);
|
2020-08-25 22:19:58 +03:00
|
|
|
MegasasBaseClass *base_class = MEGASAS_GET_CLASS(s);
|
2012-05-29 15:51:17 +04:00
|
|
|
uint32_t retval = 0;
|
|
|
|
|
|
|
|
switch (addr) {
|
|
|
|
case MFI_IDB:
|
|
|
|
retval = 0;
|
2014-10-29 15:00:10 +03:00
|
|
|
trace_megasas_mmio_readl("MFI_IDB", retval);
|
2012-05-29 15:51:17 +04:00
|
|
|
break;
|
|
|
|
case MFI_OMSG0:
|
|
|
|
case MFI_OSP0:
|
2014-10-29 15:00:08 +03:00
|
|
|
retval = (msix_present(pci_dev) ? MFI_FWSTATE_MSIX_SUPPORTED : 0) |
|
2012-05-29 15:51:17 +04:00
|
|
|
(s->fw_state & MFI_FWSTATE_MASK) |
|
|
|
|
((s->fw_sge & 0xff) << 16) |
|
|
|
|
(s->fw_cmds & 0xFFFF);
|
2014-10-29 15:00:10 +03:00
|
|
|
trace_megasas_mmio_readl(addr == MFI_OMSG0 ? "MFI_OMSG0" : "MFI_OSP0",
|
|
|
|
retval);
|
2012-05-29 15:51:17 +04:00
|
|
|
break;
|
|
|
|
case MFI_OSTS:
|
|
|
|
if (megasas_intr_enabled(s) && s->doorbell) {
|
2014-10-29 15:00:08 +03:00
|
|
|
retval = base_class->osts;
|
2012-05-29 15:51:17 +04:00
|
|
|
}
|
2014-10-29 15:00:10 +03:00
|
|
|
trace_megasas_mmio_readl("MFI_OSTS", retval);
|
2012-05-29 15:51:17 +04:00
|
|
|
break;
|
|
|
|
case MFI_OMSK:
|
|
|
|
retval = s->intr_mask;
|
2014-10-29 15:00:10 +03:00
|
|
|
trace_megasas_mmio_readl("MFI_OMSK", retval);
|
2012-05-29 15:51:17 +04:00
|
|
|
break;
|
|
|
|
case MFI_ODCR0:
|
2014-10-29 15:00:16 +03:00
|
|
|
retval = s->doorbell ? 1 : 0;
|
2014-10-29 15:00:10 +03:00
|
|
|
trace_megasas_mmio_readl("MFI_ODCR0", retval);
|
2012-05-29 15:51:17 +04:00
|
|
|
break;
|
2014-10-29 15:00:08 +03:00
|
|
|
case MFI_DIAG:
|
|
|
|
retval = s->diag;
|
2014-10-29 15:00:10 +03:00
|
|
|
trace_megasas_mmio_readl("MFI_DIAG", retval);
|
2014-10-29 15:00:08 +03:00
|
|
|
break;
|
|
|
|
case MFI_OSP1:
|
|
|
|
retval = 15;
|
2014-10-29 15:00:10 +03:00
|
|
|
trace_megasas_mmio_readl("MFI_OSP1", retval);
|
2014-10-29 15:00:08 +03:00
|
|
|
break;
|
2012-05-29 15:51:17 +04:00
|
|
|
default:
|
|
|
|
trace_megasas_mmio_invalid_readl(addr);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return retval;
|
|
|
|
}
|
|
|
|
|
2014-10-29 15:00:08 +03:00
|
|
|
static int adp_reset_seq[] = {0x00, 0x04, 0x0b, 0x02, 0x07, 0x0d};
|
|
|
|
|
2012-10-23 14:30:10 +04:00
|
|
|
static void megasas_mmio_write(void *opaque, hwaddr addr,
|
2012-05-29 15:51:17 +04:00
|
|
|
uint64_t val, unsigned size)
|
|
|
|
{
|
|
|
|
MegasasState *s = opaque;
|
2013-06-30 16:02:53 +04:00
|
|
|
PCIDevice *pci_dev = PCI_DEVICE(s);
|
2012-05-29 15:51:17 +04:00
|
|
|
uint64_t frame_addr;
|
|
|
|
uint32_t frame_count;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
switch (addr) {
|
|
|
|
case MFI_IDB:
|
2014-10-29 15:00:10 +03:00
|
|
|
trace_megasas_mmio_writel("MFI_IDB", val);
|
2012-05-29 15:51:17 +04:00
|
|
|
if (val & MFI_FWINIT_ABORT) {
|
|
|
|
/* Abort all pending cmds */
|
|
|
|
for (i = 0; i < s->fw_cmds; i++) {
|
|
|
|
megasas_abort_command(&s->frames[i]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (val & MFI_FWINIT_READY) {
|
|
|
|
/* move to FW READY */
|
|
|
|
megasas_soft_reset(s);
|
|
|
|
}
|
|
|
|
if (val & MFI_FWINIT_MFIMODE) {
|
|
|
|
/* discard MFIs */
|
|
|
|
}
|
2014-10-29 15:00:08 +03:00
|
|
|
if (val & MFI_FWINIT_STOP_ADP) {
|
|
|
|
/* Terminal error, stop processing */
|
|
|
|
s->fw_state = MFI_FWSTATE_FAULT;
|
|
|
|
}
|
2012-05-29 15:51:17 +04:00
|
|
|
break;
|
|
|
|
case MFI_OMSK:
|
2014-10-29 15:00:10 +03:00
|
|
|
trace_megasas_mmio_writel("MFI_OMSK", val);
|
2012-05-29 15:51:17 +04:00
|
|
|
s->intr_mask = val;
|
2014-04-16 18:44:15 +04:00
|
|
|
if (!megasas_intr_enabled(s) &&
|
|
|
|
!msi_enabled(pci_dev) &&
|
|
|
|
!msix_enabled(pci_dev)) {
|
2012-05-29 15:51:17 +04:00
|
|
|
trace_megasas_irq_lower();
|
2013-10-07 11:36:39 +04:00
|
|
|
pci_irq_deassert(pci_dev);
|
2012-05-29 15:51:17 +04:00
|
|
|
}
|
|
|
|
if (megasas_intr_enabled(s)) {
|
2014-04-16 18:44:15 +04:00
|
|
|
if (msix_enabled(pci_dev)) {
|
|
|
|
trace_megasas_msix_enabled(0);
|
|
|
|
} else if (msi_enabled(pci_dev)) {
|
|
|
|
trace_megasas_msi_enabled(0);
|
|
|
|
} else {
|
|
|
|
trace_megasas_intr_enabled();
|
|
|
|
}
|
2012-05-29 15:51:17 +04:00
|
|
|
} else {
|
|
|
|
trace_megasas_intr_disabled();
|
2014-10-29 15:00:08 +03:00
|
|
|
megasas_soft_reset(s);
|
2012-05-29 15:51:17 +04:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case MFI_ODCR0:
|
2014-10-29 15:00:10 +03:00
|
|
|
trace_megasas_mmio_writel("MFI_ODCR0", val);
|
2012-05-29 15:51:17 +04:00
|
|
|
s->doorbell = 0;
|
2014-10-29 15:00:16 +03:00
|
|
|
if (megasas_intr_enabled(s)) {
|
|
|
|
if (!msix_enabled(pci_dev) && !msi_enabled(pci_dev)) {
|
2012-05-29 15:51:17 +04:00
|
|
|
trace_megasas_irq_lower();
|
2013-10-07 11:36:39 +04:00
|
|
|
pci_irq_deassert(pci_dev);
|
2012-05-29 15:51:17 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case MFI_IQPH:
|
2014-10-29 15:00:10 +03:00
|
|
|
trace_megasas_mmio_writel("MFI_IQPH", val);
|
2012-05-29 15:51:17 +04:00
|
|
|
/* Received high 32 bits of a 64 bit MFI frame address */
|
|
|
|
s->frame_hi = val;
|
|
|
|
break;
|
|
|
|
case MFI_IQPL:
|
2014-10-29 15:00:10 +03:00
|
|
|
trace_megasas_mmio_writel("MFI_IQPL", val);
|
2012-05-29 15:51:17 +04:00
|
|
|
/* Received low 32 bits of a 64 bit MFI frame address */
|
2014-10-29 15:00:08 +03:00
|
|
|
/* Fallthrough */
|
2012-05-29 15:51:17 +04:00
|
|
|
case MFI_IQP:
|
2014-10-29 15:00:10 +03:00
|
|
|
if (addr == MFI_IQP) {
|
|
|
|
trace_megasas_mmio_writel("MFI_IQP", val);
|
|
|
|
/* Received 64 bit MFI frame address */
|
|
|
|
s->frame_hi = 0;
|
|
|
|
}
|
2012-05-29 15:51:17 +04:00
|
|
|
frame_addr = (val & ~0x1F);
|
|
|
|
/* Add possible 64 bit offset */
|
|
|
|
frame_addr |= ((uint64_t)s->frame_hi << 32);
|
|
|
|
s->frame_hi = 0;
|
|
|
|
frame_count = (val >> 1) & 0xF;
|
|
|
|
megasas_handle_frame(s, frame_addr, frame_count);
|
|
|
|
break;
|
2014-10-29 15:00:08 +03:00
|
|
|
case MFI_SEQ:
|
2014-10-29 15:00:10 +03:00
|
|
|
trace_megasas_mmio_writel("MFI_SEQ", val);
|
2014-10-29 15:00:08 +03:00
|
|
|
/* Magic sequence to start ADP reset */
|
2017-04-24 15:06:34 +03:00
|
|
|
if (adp_reset_seq[s->adp_reset++] == val) {
|
|
|
|
if (s->adp_reset == 6) {
|
|
|
|
s->adp_reset = 0;
|
|
|
|
s->diag = MFI_DIAG_WRITE_ENABLE;
|
|
|
|
}
|
2014-10-29 15:00:08 +03:00
|
|
|
} else {
|
|
|
|
s->adp_reset = 0;
|
|
|
|
s->diag = 0;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case MFI_DIAG:
|
2014-10-29 15:00:10 +03:00
|
|
|
trace_megasas_mmio_writel("MFI_DIAG", val);
|
2014-10-29 15:00:08 +03:00
|
|
|
/* ADP reset */
|
|
|
|
if ((s->diag & MFI_DIAG_WRITE_ENABLE) &&
|
|
|
|
(val & MFI_DIAG_RESET_ADP)) {
|
|
|
|
s->diag |= MFI_DIAG_RESET_ADP;
|
|
|
|
megasas_soft_reset(s);
|
|
|
|
s->adp_reset = 0;
|
|
|
|
s->diag = 0;
|
|
|
|
}
|
|
|
|
break;
|
2012-05-29 15:51:17 +04:00
|
|
|
default:
|
|
|
|
trace_megasas_mmio_invalid_writel(addr, val);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static const MemoryRegionOps megasas_mmio_ops = {
|
|
|
|
.read = megasas_mmio_read,
|
|
|
|
.write = megasas_mmio_write,
|
|
|
|
.endianness = DEVICE_LITTLE_ENDIAN,
|
|
|
|
.impl = {
|
|
|
|
.min_access_size = 8,
|
|
|
|
.max_access_size = 8,
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2012-10-23 14:30:10 +04:00
|
|
|
static uint64_t megasas_port_read(void *opaque, hwaddr addr,
|
2012-05-29 15:51:17 +04:00
|
|
|
unsigned size)
|
|
|
|
{
|
|
|
|
return megasas_mmio_read(opaque, addr & 0xff, size);
|
|
|
|
}
|
|
|
|
|
2012-10-23 14:30:10 +04:00
|
|
|
static void megasas_port_write(void *opaque, hwaddr addr,
|
2012-05-29 15:51:17 +04:00
|
|
|
uint64_t val, unsigned size)
|
|
|
|
{
|
|
|
|
megasas_mmio_write(opaque, addr & 0xff, val, size);
|
|
|
|
}
|
|
|
|
|
|
|
|
static const MemoryRegionOps megasas_port_ops = {
|
|
|
|
.read = megasas_port_read,
|
|
|
|
.write = megasas_port_write,
|
|
|
|
.endianness = DEVICE_LITTLE_ENDIAN,
|
|
|
|
.impl = {
|
|
|
|
.min_access_size = 4,
|
|
|
|
.max_access_size = 4,
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2012-10-23 14:30:10 +04:00
|
|
|
static uint64_t megasas_queue_read(void *opaque, hwaddr addr,
|
2012-05-29 15:51:17 +04:00
|
|
|
unsigned size)
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2015-07-27 11:51:52 +03:00
|
|
|
static void megasas_queue_write(void *opaque, hwaddr addr,
|
|
|
|
uint64_t val, unsigned size)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2012-05-29 15:51:17 +04:00
|
|
|
static const MemoryRegionOps megasas_queue_ops = {
|
|
|
|
.read = megasas_queue_read,
|
2015-07-27 11:51:52 +03:00
|
|
|
.write = megasas_queue_write,
|
2012-05-29 15:51:17 +04:00
|
|
|
.endianness = DEVICE_LITTLE_ENDIAN,
|
|
|
|
.impl = {
|
|
|
|
.min_access_size = 8,
|
|
|
|
.max_access_size = 8,
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
static void megasas_soft_reset(MegasasState *s)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
MegasasCmd *cmd;
|
|
|
|
|
2014-10-29 15:00:11 +03:00
|
|
|
trace_megasas_reset(s->fw_state);
|
2012-05-29 15:51:17 +04:00
|
|
|
for (i = 0; i < s->fw_cmds; i++) {
|
|
|
|
cmd = &s->frames[i];
|
|
|
|
megasas_abort_command(cmd);
|
|
|
|
}
|
2014-10-29 15:00:11 +03:00
|
|
|
if (s->fw_state == MFI_FWSTATE_READY) {
|
|
|
|
BusChild *kid;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* The EFI firmware doesn't handle UA,
|
|
|
|
* so we need to clear the Power On/Reset UA
|
|
|
|
* after the initial reset.
|
|
|
|
*/
|
|
|
|
QTAILQ_FOREACH(kid, &s->bus.qbus.children, sibling) {
|
2016-01-06 12:37:46 +03:00
|
|
|
SCSIDevice *sdev = SCSI_DEVICE(kid->child);
|
2014-10-29 15:00:11 +03:00
|
|
|
|
|
|
|
sdev->unit_attention = SENSE_CODE(NO_SENSE);
|
|
|
|
scsi_device_unit_attention_reported(sdev);
|
|
|
|
}
|
|
|
|
}
|
2012-05-29 15:51:17 +04:00
|
|
|
megasas_reset_frames(s);
|
|
|
|
s->reply_queue_len = s->fw_cmds;
|
|
|
|
s->reply_queue_pa = 0;
|
|
|
|
s->consumer_pa = 0;
|
|
|
|
s->producer_pa = 0;
|
|
|
|
s->fw_state = MFI_FWSTATE_READY;
|
|
|
|
s->doorbell = 0;
|
|
|
|
s->intr_mask = MEGASAS_INTR_DISABLED_MASK;
|
|
|
|
s->frame_hi = 0;
|
|
|
|
s->flags &= ~MEGASAS_MASK_USE_QUEUE64;
|
|
|
|
s->event_count++;
|
|
|
|
s->boot_event = s->event_count;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void megasas_scsi_reset(DeviceState *dev)
|
|
|
|
{
|
2013-06-24 10:54:15 +04:00
|
|
|
MegasasState *s = MEGASAS(dev);
|
2012-05-29 15:51:17 +04:00
|
|
|
|
|
|
|
megasas_soft_reset(s);
|
|
|
|
}
|
|
|
|
|
2014-10-29 15:00:08 +03:00
|
|
|
static const VMStateDescription vmstate_megasas_gen1 = {
|
2012-05-29 15:51:17 +04:00
|
|
|
.name = "megasas",
|
|
|
|
.version_id = 0,
|
|
|
|
.minimum_version_id = 0,
|
2014-04-16 17:32:32 +04:00
|
|
|
.fields = (VMStateField[]) {
|
2013-06-30 16:02:53 +04:00
|
|
|
VMSTATE_PCI_DEVICE(parent_obj, MegasasState),
|
2014-04-16 18:44:14 +04:00
|
|
|
VMSTATE_MSIX(parent_obj, MegasasState),
|
2012-05-29 15:51:17 +04:00
|
|
|
|
2020-05-13 22:25:40 +03:00
|
|
|
VMSTATE_UINT32(fw_state, MegasasState),
|
|
|
|
VMSTATE_UINT32(intr_mask, MegasasState),
|
|
|
|
VMSTATE_UINT32(doorbell, MegasasState),
|
2012-05-29 15:51:17 +04:00
|
|
|
VMSTATE_UINT64(reply_queue_pa, MegasasState),
|
|
|
|
VMSTATE_UINT64(consumer_pa, MegasasState),
|
|
|
|
VMSTATE_UINT64(producer_pa, MegasasState),
|
|
|
|
VMSTATE_END_OF_LIST()
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2014-10-29 15:00:08 +03:00
|
|
|
static const VMStateDescription vmstate_megasas_gen2 = {
|
|
|
|
.name = "megasas-gen2",
|
|
|
|
.version_id = 0,
|
|
|
|
.minimum_version_id = 0,
|
|
|
|
.fields = (VMStateField[]) {
|
2016-12-14 22:58:29 +03:00
|
|
|
VMSTATE_PCI_DEVICE(parent_obj, MegasasState),
|
2014-10-29 15:00:08 +03:00
|
|
|
VMSTATE_MSIX(parent_obj, MegasasState),
|
|
|
|
|
2020-05-13 22:25:40 +03:00
|
|
|
VMSTATE_UINT32(fw_state, MegasasState),
|
|
|
|
VMSTATE_UINT32(intr_mask, MegasasState),
|
|
|
|
VMSTATE_UINT32(doorbell, MegasasState),
|
2014-10-29 15:00:08 +03:00
|
|
|
VMSTATE_UINT64(reply_queue_pa, MegasasState),
|
|
|
|
VMSTATE_UINT64(consumer_pa, MegasasState),
|
|
|
|
VMSTATE_UINT64(producer_pa, MegasasState),
|
|
|
|
VMSTATE_END_OF_LIST()
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2012-07-31 09:54:57 +04:00
|
|
|
static void megasas_scsi_uninit(PCIDevice *d)
|
2012-05-29 15:51:17 +04:00
|
|
|
{
|
2013-06-24 10:54:15 +04:00
|
|
|
MegasasState *s = MEGASAS(d);
|
2012-05-29 15:51:17 +04:00
|
|
|
|
2014-04-16 18:44:15 +04:00
|
|
|
if (megasas_use_msix(s)) {
|
|
|
|
msix_uninit(d, &s->mmio_io, &s->mmio_io);
|
|
|
|
}
|
2016-06-20 09:13:40 +03:00
|
|
|
msi_uninit(d);
|
2012-05-29 15:51:17 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
static const struct SCSIBusInfo megasas_scsi_info = {
|
|
|
|
.tcq = true,
|
|
|
|
.max_target = MFI_MAX_LD,
|
|
|
|
.max_lun = 255,
|
|
|
|
|
|
|
|
.transfer_data = megasas_xfer_complete,
|
|
|
|
.get_sg_list = megasas_get_sg_list,
|
|
|
|
.complete = megasas_command_complete,
|
2016-11-10 18:27:51 +03:00
|
|
|
.cancel = megasas_command_cancelled,
|
2012-05-29 15:51:17 +04:00
|
|
|
};
|
|
|
|
|
2015-03-09 21:17:28 +03:00
|
|
|
static void megasas_scsi_realize(PCIDevice *dev, Error **errp)
|
2012-05-29 15:51:17 +04:00
|
|
|
{
|
2013-06-24 10:54:15 +04:00
|
|
|
MegasasState *s = MEGASAS(dev);
|
2020-08-25 22:19:58 +03:00
|
|
|
MegasasBaseClass *b = MEGASAS_GET_CLASS(s);
|
2012-05-29 15:51:17 +04:00
|
|
|
uint8_t *pci_conf;
|
2019-12-17 20:34:00 +03:00
|
|
|
uint32_t sge;
|
2012-05-29 15:51:17 +04:00
|
|
|
int i, bar_type;
|
2016-06-20 09:13:39 +03:00
|
|
|
Error *err = NULL;
|
|
|
|
int ret;
|
2012-05-29 15:51:17 +04:00
|
|
|
|
2013-06-30 16:02:53 +04:00
|
|
|
pci_conf = dev->config;
|
2012-05-29 15:51:17 +04:00
|
|
|
|
|
|
|
/* PCI latency timer = 0 */
|
|
|
|
pci_conf[PCI_LATENCY_TIMER] = 0;
|
|
|
|
/* Interrupt pin 1 */
|
|
|
|
pci_conf[PCI_INTERRUPT_PIN] = 0x01;
|
|
|
|
|
2016-06-20 09:13:40 +03:00
|
|
|
if (s->msi != ON_OFF_AUTO_OFF) {
|
2016-06-20 09:13:39 +03:00
|
|
|
ret = msi_init(dev, 0x50, 1, true, false, &err);
|
|
|
|
/* Any error other than -ENOTSUP(board's MSI support is broken)
|
|
|
|
* is a programming error */
|
|
|
|
assert(!ret || ret == -ENOTSUP);
|
|
|
|
if (ret && s->msi == ON_OFF_AUTO_ON) {
|
|
|
|
/* Can't satisfy user's explicit msi=on request, fail */
|
|
|
|
error_append_hint(&err, "You have to use msi=auto (default) or "
|
|
|
|
"msi=off with this machine type.\n");
|
|
|
|
error_propagate(errp, err);
|
|
|
|
return;
|
|
|
|
} else if (ret) {
|
|
|
|
/* With msi=auto, we fall back to MSI off silently */
|
|
|
|
s->msi = ON_OFF_AUTO_OFF;
|
|
|
|
error_free(err);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-06-07 05:25:08 +04:00
|
|
|
memory_region_init_io(&s->mmio_io, OBJECT(s), &megasas_mmio_ops, s,
|
2012-05-29 15:51:17 +04:00
|
|
|
"megasas-mmio", 0x4000);
|
2013-06-07 05:25:08 +04:00
|
|
|
memory_region_init_io(&s->port_io, OBJECT(s), &megasas_port_ops, s,
|
2012-05-29 15:51:17 +04:00
|
|
|
"megasas-io", 256);
|
2013-06-07 05:25:08 +04:00
|
|
|
memory_region_init_io(&s->queue_io, OBJECT(s), &megasas_queue_ops, s,
|
2012-05-29 15:51:17 +04:00
|
|
|
"megasas-queue", 0x40000);
|
|
|
|
|
|
|
|
if (megasas_use_msix(s) &&
|
2014-10-29 15:00:08 +03:00
|
|
|
msix_init(dev, 15, &s->mmio_io, b->mmio_bar, 0x2000,
|
2017-01-17 09:18:48 +03:00
|
|
|
&s->mmio_io, b->mmio_bar, 0x3800, 0x68, NULL)) {
|
|
|
|
/* TODO: check msix_init's error, and should fail on msix=on */
|
2016-06-20 09:13:37 +03:00
|
|
|
s->msix = ON_OFF_AUTO_OFF;
|
2012-05-29 15:51:17 +04:00
|
|
|
}
|
2017-01-17 09:18:48 +03:00
|
|
|
|
2014-10-29 15:00:08 +03:00
|
|
|
if (pci_is_express(dev)) {
|
|
|
|
pcie_endpoint_cap_init(dev, 0xa0);
|
|
|
|
}
|
2012-05-29 15:51:17 +04:00
|
|
|
|
|
|
|
bar_type = PCI_BASE_ADDRESS_SPACE_MEMORY | PCI_BASE_ADDRESS_MEM_TYPE_64;
|
2014-10-29 15:00:08 +03:00
|
|
|
pci_register_bar(dev, b->ioport_bar,
|
|
|
|
PCI_BASE_ADDRESS_SPACE_IO, &s->port_io);
|
|
|
|
pci_register_bar(dev, b->mmio_bar, bar_type, &s->mmio_io);
|
2013-06-30 16:02:53 +04:00
|
|
|
pci_register_bar(dev, 3, bar_type, &s->queue_io);
|
2012-05-29 15:51:17 +04:00
|
|
|
|
|
|
|
if (megasas_use_msix(s)) {
|
2013-06-30 16:02:53 +04:00
|
|
|
msix_vector_use(dev, 0);
|
2012-05-29 15:51:17 +04:00
|
|
|
}
|
|
|
|
|
2014-10-29 15:00:11 +03:00
|
|
|
s->fw_state = MFI_FWSTATE_READY;
|
2012-08-01 14:46:50 +04:00
|
|
|
if (!s->sas_addr) {
|
|
|
|
s->sas_addr = ((NAA_LOCALLY_ASSIGNED_ID << 24) |
|
|
|
|
IEEE_COMPANY_LOCALLY_ASSIGNED) << 36;
|
2020-10-11 22:50:01 +03:00
|
|
|
s->sas_addr |= pci_dev_bus_num(dev) << 16;
|
|
|
|
s->sas_addr |= PCI_SLOT(dev->devfn) << 8;
|
2012-08-01 14:46:50 +04:00
|
|
|
s->sas_addr |= PCI_FUNC(dev->devfn);
|
|
|
|
}
|
2012-08-24 14:36:41 +04:00
|
|
|
if (!s->hba_serial) {
|
2014-04-16 18:44:14 +04:00
|
|
|
s->hba_serial = g_strdup(MEGASAS_HBA_SERIAL);
|
2012-08-24 14:36:41 +04:00
|
|
|
}
|
2019-12-17 20:34:00 +03:00
|
|
|
|
|
|
|
sge = s->fw_sge + MFI_PASS_FRAME_SIZE;
|
|
|
|
if (sge < MEGASAS_MIN_SGE) {
|
|
|
|
sge = MEGASAS_MIN_SGE;
|
|
|
|
} else if (sge >= MEGASAS_MAX_SGE) {
|
|
|
|
sge = MEGASAS_MAX_SGE;
|
2012-05-29 15:51:17 +04:00
|
|
|
}
|
2019-12-17 20:34:00 +03:00
|
|
|
s->fw_sge = sge - MFI_PASS_FRAME_SIZE;
|
|
|
|
|
2012-05-29 15:51:17 +04:00
|
|
|
if (s->fw_cmds > MEGASAS_MAX_FRAMES) {
|
|
|
|
s->fw_cmds = MEGASAS_MAX_FRAMES;
|
|
|
|
}
|
|
|
|
trace_megasas_init(s->fw_sge, s->fw_cmds,
|
|
|
|
megasas_is_jbod(s) ? "jbod" : "raid");
|
2014-10-29 15:00:07 +03:00
|
|
|
|
|
|
|
if (megasas_is_jbod(s)) {
|
|
|
|
s->fw_luns = MFI_MAX_SYS_PDS;
|
|
|
|
} else {
|
|
|
|
s->fw_luns = MFI_MAX_LD;
|
|
|
|
}
|
2012-05-29 15:51:17 +04:00
|
|
|
s->producer_pa = 0;
|
|
|
|
s->consumer_pa = 0;
|
|
|
|
for (i = 0; i < s->fw_cmds; i++) {
|
|
|
|
s->frames[i].index = i;
|
|
|
|
s->frames[i].context = -1;
|
|
|
|
s->frames[i].pa = 0;
|
|
|
|
s->frames[i].state = s;
|
|
|
|
}
|
|
|
|
|
2021-09-23 15:11:48 +03:00
|
|
|
scsi_bus_init(&s->bus, sizeof(s->bus), DEVICE(dev), &megasas_scsi_info);
|
2012-05-29 15:51:17 +04:00
|
|
|
}
|
|
|
|
|
2014-10-29 15:00:08 +03:00
|
|
|
static Property megasas_properties_gen1[] = {
|
2012-05-29 15:51:17 +04:00
|
|
|
DEFINE_PROP_UINT32("max_sge", MegasasState, fw_sge,
|
|
|
|
MEGASAS_DEFAULT_SGE),
|
|
|
|
DEFINE_PROP_UINT32("max_cmds", MegasasState, fw_cmds,
|
|
|
|
MEGASAS_DEFAULT_FRAMES),
|
2012-08-24 14:36:41 +04:00
|
|
|
DEFINE_PROP_STRING("hba_serial", MegasasState, hba_serial),
|
2014-02-08 14:01:53 +04:00
|
|
|
DEFINE_PROP_UINT64("sas_address", MegasasState, sas_addr, 0),
|
2016-06-20 09:13:37 +03:00
|
|
|
DEFINE_PROP_ON_OFF_AUTO("msi", MegasasState, msi, ON_OFF_AUTO_AUTO),
|
|
|
|
DEFINE_PROP_ON_OFF_AUTO("msix", MegasasState, msix, ON_OFF_AUTO_AUTO),
|
2012-05-29 15:51:17 +04:00
|
|
|
DEFINE_PROP_BIT("use_jbod", MegasasState, flags,
|
|
|
|
MEGASAS_FLAG_USE_JBOD, false),
|
|
|
|
DEFINE_PROP_END_OF_LIST(),
|
|
|
|
};
|
|
|
|
|
2014-10-29 15:00:08 +03:00
|
|
|
static Property megasas_properties_gen2[] = {
|
|
|
|
DEFINE_PROP_UINT32("max_sge", MegasasState, fw_sge,
|
|
|
|
MEGASAS_DEFAULT_SGE),
|
|
|
|
DEFINE_PROP_UINT32("max_cmds", MegasasState, fw_cmds,
|
|
|
|
MEGASAS_GEN2_DEFAULT_FRAMES),
|
|
|
|
DEFINE_PROP_STRING("hba_serial", MegasasState, hba_serial),
|
|
|
|
DEFINE_PROP_UINT64("sas_address", MegasasState, sas_addr, 0),
|
2016-06-20 09:13:37 +03:00
|
|
|
DEFINE_PROP_ON_OFF_AUTO("msi", MegasasState, msi, ON_OFF_AUTO_AUTO),
|
|
|
|
DEFINE_PROP_ON_OFF_AUTO("msix", MegasasState, msix, ON_OFF_AUTO_AUTO),
|
2014-10-29 15:00:08 +03:00
|
|
|
DEFINE_PROP_BIT("use_jbod", MegasasState, flags,
|
|
|
|
MEGASAS_FLAG_USE_JBOD, false),
|
|
|
|
DEFINE_PROP_END_OF_LIST(),
|
|
|
|
};
|
|
|
|
|
|
|
|
typedef struct MegasasInfo {
|
|
|
|
const char *name;
|
|
|
|
const char *desc;
|
|
|
|
const char *product_name;
|
|
|
|
const char *product_version;
|
|
|
|
uint16_t device_id;
|
|
|
|
uint16_t subsystem_id;
|
|
|
|
int ioport_bar;
|
|
|
|
int mmio_bar;
|
|
|
|
int osts;
|
|
|
|
const VMStateDescription *vmsd;
|
|
|
|
Property *props;
|
2017-09-27 22:56:33 +03:00
|
|
|
InterfaceInfo *interfaces;
|
2014-10-29 15:00:08 +03:00
|
|
|
} MegasasInfo;
|
|
|
|
|
|
|
|
static struct MegasasInfo megasas_devices[] = {
|
|
|
|
{
|
|
|
|
.name = TYPE_MEGASAS_GEN1,
|
|
|
|
.desc = "LSI MegaRAID SAS 1078",
|
|
|
|
.product_name = "LSI MegaRAID SAS 8708EM2",
|
|
|
|
.product_version = MEGASAS_VERSION_GEN1,
|
|
|
|
.device_id = PCI_DEVICE_ID_LSI_SAS1078,
|
|
|
|
.subsystem_id = 0x1013,
|
|
|
|
.ioport_bar = 2,
|
|
|
|
.mmio_bar = 0,
|
|
|
|
.osts = MFI_1078_RM | 1,
|
|
|
|
.vmsd = &vmstate_megasas_gen1,
|
|
|
|
.props = megasas_properties_gen1,
|
2017-09-27 22:56:34 +03:00
|
|
|
.interfaces = (InterfaceInfo[]) {
|
|
|
|
{ INTERFACE_CONVENTIONAL_PCI_DEVICE },
|
|
|
|
{ },
|
|
|
|
},
|
2014-10-29 15:00:08 +03:00
|
|
|
},{
|
|
|
|
.name = TYPE_MEGASAS_GEN2,
|
|
|
|
.desc = "LSI MegaRAID SAS 2108",
|
|
|
|
.product_name = "LSI MegaRAID SAS 9260-8i",
|
|
|
|
.product_version = MEGASAS_VERSION_GEN2,
|
|
|
|
.device_id = PCI_DEVICE_ID_LSI_SAS0079,
|
|
|
|
.subsystem_id = 0x9261,
|
|
|
|
.ioport_bar = 0,
|
|
|
|
.mmio_bar = 1,
|
|
|
|
.osts = MFI_GEN2_RM,
|
|
|
|
.vmsd = &vmstate_megasas_gen2,
|
|
|
|
.props = megasas_properties_gen2,
|
2017-09-27 22:56:33 +03:00
|
|
|
.interfaces = (InterfaceInfo[]) {
|
|
|
|
{ INTERFACE_PCIE_DEVICE },
|
|
|
|
{ }
|
|
|
|
},
|
2014-10-29 15:00:08 +03:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2012-05-29 15:51:17 +04:00
|
|
|
static void megasas_class_init(ObjectClass *oc, void *data)
|
|
|
|
{
|
|
|
|
DeviceClass *dc = DEVICE_CLASS(oc);
|
|
|
|
PCIDeviceClass *pc = PCI_DEVICE_CLASS(oc);
|
2020-08-25 22:19:58 +03:00
|
|
|
MegasasBaseClass *e = MEGASAS_CLASS(oc);
|
2014-10-29 15:00:08 +03:00
|
|
|
const MegasasInfo *info = data;
|
2012-05-29 15:51:17 +04:00
|
|
|
|
2015-03-09 21:17:28 +03:00
|
|
|
pc->realize = megasas_scsi_realize;
|
2012-05-29 15:51:17 +04:00
|
|
|
pc->exit = megasas_scsi_uninit;
|
|
|
|
pc->vendor_id = PCI_VENDOR_ID_LSI_LOGIC;
|
2014-10-29 15:00:08 +03:00
|
|
|
pc->device_id = info->device_id;
|
2012-05-29 15:51:17 +04:00
|
|
|
pc->subsystem_vendor_id = PCI_VENDOR_ID_LSI_LOGIC;
|
2014-10-29 15:00:08 +03:00
|
|
|
pc->subsystem_id = info->subsystem_id;
|
2012-05-29 15:51:17 +04:00
|
|
|
pc->class_id = PCI_CLASS_STORAGE_RAID;
|
2014-10-29 15:00:08 +03:00
|
|
|
e->mmio_bar = info->mmio_bar;
|
|
|
|
e->ioport_bar = info->ioport_bar;
|
|
|
|
e->osts = info->osts;
|
|
|
|
e->product_name = info->product_name;
|
|
|
|
e->product_version = info->product_version;
|
2020-01-10 18:30:32 +03:00
|
|
|
device_class_set_props(dc, info->props);
|
2012-05-29 15:51:17 +04:00
|
|
|
dc->reset = megasas_scsi_reset;
|
2014-10-29 15:00:08 +03:00
|
|
|
dc->vmsd = info->vmsd;
|
2013-07-29 18:17:45 +04:00
|
|
|
set_bit(DEVICE_CATEGORY_STORAGE, dc->categories);
|
2014-10-29 15:00:08 +03:00
|
|
|
dc->desc = info->desc;
|
2012-05-29 15:51:17 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
static const TypeInfo megasas_info = {
|
2014-10-29 15:00:08 +03:00
|
|
|
.name = TYPE_MEGASAS_BASE,
|
2012-05-29 15:51:17 +04:00
|
|
|
.parent = TYPE_PCI_DEVICE,
|
|
|
|
.instance_size = sizeof(MegasasState),
|
2014-10-29 15:00:08 +03:00
|
|
|
.class_size = sizeof(MegasasBaseClass),
|
|
|
|
.abstract = true,
|
2012-05-29 15:51:17 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
static void megasas_register_types(void)
|
|
|
|
{
|
2014-10-29 15:00:08 +03:00
|
|
|
int i;
|
|
|
|
|
2012-05-29 15:51:17 +04:00
|
|
|
type_register_static(&megasas_info);
|
2014-10-29 15:00:08 +03:00
|
|
|
for (i = 0; i < ARRAY_SIZE(megasas_devices); i++) {
|
|
|
|
const MegasasInfo *info = &megasas_devices[i];
|
|
|
|
TypeInfo type_info = {};
|
|
|
|
|
|
|
|
type_info.name = info->name;
|
|
|
|
type_info.parent = TYPE_MEGASAS_BASE;
|
|
|
|
type_info.class_data = (void *)info;
|
|
|
|
type_info.class_init = megasas_class_init;
|
2017-09-27 22:56:33 +03:00
|
|
|
type_info.interfaces = info->interfaces;
|
2014-10-29 15:00:08 +03:00
|
|
|
|
|
|
|
type_register(&type_info);
|
|
|
|
}
|
2012-05-29 15:51:17 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
type_init(megasas_register_types)
|