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);

    BlockConf *conf = &sdev->conf;

    uint64_t pd_size;

    uint16_t sdev_id = ((sdev->id & 0xFF) >> 8) | (lun & 0xFF);

    uint8_t cmdbuf[6];

    SCSIRequest *req;

    size_t len, resid;



    if (!cmd->iov_buf) {

        cmd->iov_buf = g_malloc(dcmd_size);

        memset(cmd->iov_buf, 0, dcmd_size);

        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));

        req = scsi_req_new(sdev, cmd->index, lun, cmdbuf, cmd);

        if (!req) {

            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);

        len = scsi_req_enqueue(req);

        if (len > 0) {

            cmd->iov_size = len;

            scsi_req_continue(req);

        }

        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));

        req = scsi_req_new(sdev, cmd->index, lun, cmdbuf, cmd);

        if (!req) {

            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);

        len = scsi_req_enqueue(req);

        if (len > 0) {

            cmd->iov_size = len;

            scsi_req_continue(req);

        }

        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);

    }



    info->ref.v.device_id = cpu_to_le16(sdev_id);

    info->state.ddf.pd_type = cpu_to_le16(MFI_PD_DDF_TYPE_IN_VD|

                                          MFI_PD_DDF_TYPE_INTF_SAS);

    bdrv_get_geometry(conf->bs, &pd_size);

    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] =

        cpu_to_le64(megasas_get_sata_addr(sdev_id));

    info->connected_port_bitmap = 0x1;

    info->device_speed = 1;

    info->link_speed = 1;

    resid = dma_buf_read(cmd->iov_buf, dcmd_size, &cmd->qsg);

    g_free(cmd->iov_buf);

    cmd->iov_size = dcmd_size - resid;

    cmd->iov_buf = NULL;

    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);

    BlockConf *conf = &sdev->conf;

    uint64_t pd_size;

    uint16_t sdev_id = ((sdev->id & 0xFF) >> 8) | (lun & 0xFF);

    uint8_t cmdbuf[6];

    SCSIRequest *req;

    size_t len, resid;



    if (!cmd->iov_buf) {

        cmd->iov_buf = g_malloc(dcmd_size);

        memset(cmd->iov_buf, 0, dcmd_size);

        info = cmd->iov_buf;

        info->inquiry_data[0] = 0x7f; 

        info->vpd_page83[0] = 0x7f;

        megasas_setup_inquiry(cmdbuf, 0, sizeof(info->inquiry_data));

        req = scsi_req_new(sdev, cmd->index, lun, cmdbuf, cmd);

        if (!req) {

            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);

        len = scsi_req_enqueue(req);

        if (len > 0) {

            cmd->iov_size = len;

            scsi_req_continue(req);

        }

        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));

        req = scsi_req_new(sdev, cmd->index, lun, cmdbuf, cmd);

        if (!req) {

            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);

        len = scsi_req_enqueue(req);

        if (len > 0) {

            cmd->iov_size = len;

            scsi_req_continue(req);

        }

        return MFI_STAT_INVALID_STATUS;

    }

    

    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);

    }



    info->ref.v.device_id = cpu_to_le16(sdev_id);

    info->state.ddf.pd_type = cpu_to_le16(MFI_PD_DDF_TYPE_IN_VD|

                                          MFI_PD_DDF_TYPE_INTF_SAS);

    bdrv_get_geometry(conf->bs, &pd_size);

    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] =

        cpu_to_le64(megasas_get_sata_addr(sdev_id));

    info->connected_port_bitmap = 0x1;

    info->device_speed = 1;

    info->link_speed = 1;

    resid = dma_buf_read(cmd->iov_buf, dcmd_size, &cmd->qsg);

    g_free(cmd->iov_buf);

    cmd->iov_size = dcmd_size - resid;

    cmd->iov_buf = NULL;

    return MFI_STAT_OK;

}

static int FUNC_0(SCSIDevice *VAR_0, int VAR_1,

                                      MegasasCmd *VAR_2)

{

    struct mfi_pd_info *VAR_3 = VAR_2->iov_buf;

    size_t dcmd_size = sizeof(struct mfi_pd_info);

    BlockConf *conf = &VAR_0->conf;

    uint64_t pd_size;

    uint16_t sdev_id = ((VAR_0->id & 0xFF) >> 8) | (VAR_1 & 0xFF);

    uint8_t cmdbuf[6];

    SCSIRequest *req;

    size_t len, resid;



    if (!VAR_2->iov_buf) {

        VAR_2->iov_buf = g_malloc(dcmd_size);

        memset(VAR_2->iov_buf, 0, dcmd_size);

        VAR_3 = VAR_2->iov_buf;

        VAR_3->inquiry_data[0] = 0x7f; 

        VAR_3->vpd_page83[0] = 0x7f;

        megasas_setup_inquiry(cmdbuf, 0, sizeof(VAR_3->inquiry_data));

        req = scsi_req_new(VAR_0, VAR_2->index, VAR_1, cmdbuf, VAR_2);

        if (!req) {

            trace_megasas_dcmd_req_alloc_failed(VAR_2->index,

                                                "PD get VAR_3 std inquiry");

            g_free(VAR_2->iov_buf);

            VAR_2->iov_buf = NULL;

            return MFI_STAT_FLASH_ALLOC_FAIL;

        }

        trace_megasas_dcmd_internal_submit(VAR_2->index,

                                           "PD get VAR_3 std inquiry", VAR_1);

        len = scsi_req_enqueue(req);

        if (len > 0) {

            VAR_2->iov_size = len;

            scsi_req_continue(req);

        }

        return MFI_STAT_INVALID_STATUS;

    } else if (VAR_3->inquiry_data[0] != 0x7f && VAR_3->vpd_page83[0] == 0x7f) {

        megasas_setup_inquiry(cmdbuf, 0x83, sizeof(VAR_3->vpd_page83));

        req = scsi_req_new(VAR_0, VAR_2->index, VAR_1, cmdbuf, VAR_2);

        if (!req) {

            trace_megasas_dcmd_req_alloc_failed(VAR_2->index,

                                                "PD get VAR_3 vpd inquiry");

            return MFI_STAT_FLASH_ALLOC_FAIL;

        }

        trace_megasas_dcmd_internal_submit(VAR_2->index,

                                           "PD get VAR_3 vpd inquiry", VAR_1);

        len = scsi_req_enqueue(req);

        if (len > 0) {

            VAR_2->iov_size = len;

            scsi_req_continue(req);

        }

        return MFI_STAT_INVALID_STATUS;

    }

    

    if ((VAR_3->inquiry_data[0] >> 5) == 0) {

        if (megasas_is_jbod(VAR_2->state)) {

            VAR_3->fw_state = cpu_to_le16(MFI_PD_STATE_SYSTEM);

        } else {

            VAR_3->fw_state = cpu_to_le16(MFI_PD_STATE_ONLINE);

        }

    } else {

        VAR_3->fw_state = cpu_to_le16(MFI_PD_STATE_OFFLINE);

    }



    VAR_3->ref.v.device_id = cpu_to_le16(sdev_id);

    VAR_3->state.ddf.pd_type = cpu_to_le16(MFI_PD_DDF_TYPE_IN_VD|

                                          MFI_PD_DDF_TYPE_INTF_SAS);

    bdrv_get_geometry(conf->bs, &pd_size);

    VAR_3->raw_size = cpu_to_le64(pd_size);

    VAR_3->non_coerced_size = cpu_to_le64(pd_size);

    VAR_3->coerced_size = cpu_to_le64(pd_size);

    VAR_3->encl_device_id = 0xFFFF;

    VAR_3->slot_number = (VAR_0->id & 0xFF);

    VAR_3->path_info.count = 1;

    VAR_3->path_info.sas_addr[0] =

        cpu_to_le64(megasas_get_sata_addr(sdev_id));

    VAR_3->connected_port_bitmap = 0x1;

    VAR_3->device_speed = 1;

    VAR_3->link_speed = 1;

    resid = dma_buf_read(VAR_2->iov_buf, dcmd_size, &VAR_2->qsg);

    g_free(VAR_2->iov_buf);

    VAR_2->iov_size = dcmd_size - resid;

    VAR_2->iov_buf = NULL;

    return MFI_STAT_OK;

}

static int FUNC_0(SCSIDevice *VAR_0, int VAR_1,
MegasasCmd *VAR_2)
{ struct mfi_pd_info *VAR_3 = VAR_2->iov_buf; size_t dcmd_size = sizeof(struct mfi_pd_info); BlockConf *conf = &VAR_0->conf; uint64_t pd_size; uint16_t sdev_id = ((VAR_0->id & 0xFF) >> 8) | (VAR_1 & 0xFF); uint8_t cmdbuf[6]; SCSIRequest *req; size_t len, resid; if (!VAR_2->iov_buf) { VAR_2->iov_buf = g_malloc(dcmd_size); memset(VAR_2->iov_buf, 0, dcmd_size); VAR_3 = VAR_2->iov_buf; VAR_3->inquiry_data[0] = 0x7f; VAR_3->vpd_page83[0] = 0x7f; megasas_setup_inquiry(cmdbuf, 0, sizeof(VAR_3->inquiry_data)); req = scsi_req_new(VAR_0, VAR_2->index, VAR_1, cmdbuf, VAR_2); if (!req) { trace_megasas_dcmd_req_alloc_failed(VAR_2->index,
"PD get VAR_3 std inquiry"); g_free(VAR_2->iov_buf); VAR_2->iov_buf = NULL; return MFI_STAT_FLASH_ALLOC_FAIL; } trace_megasas_dcmd_internal_submit(VAR_2->index,
"PD get VAR_3 std inquiry", VAR_1); len = scsi_req_enqueue(req); if (len > 0) { VAR_2->iov_size = len; scsi_req_continue(req); } return MFI_STAT_INVALID_STATUS; } else if (VAR_3->inquiry_data[0] != 0x7f && VAR_3->vpd_page83[0] == 0x7f) { megasas_setup_inquiry(cmdbuf, 0x83, sizeof(VAR_3->vpd_page83)); req = scsi_req_new(VAR_0, VAR_2->index, VAR_1, cmdbuf, VAR_2); if (!req) { trace_megasas_dcmd_req_alloc_failed(VAR_2->index,
"PD get VAR_3 vpd inquiry"); return MFI_STAT_FLASH_ALLOC_FAIL; } trace_megasas_dcmd_internal_submit(VAR_2->index,
"PD get VAR_3 vpd inquiry", VAR_1); len = scsi_req_enqueue(req); if (len > 0) { VAR_2->iov_size = len; scsi_req_continue(req); } return MFI_STAT_INVALID_STATUS; } if ((VAR_3->inquiry_data[0] >> 5) == 0) { if (megasas_is_jbod(VAR_2->state)) { VAR_3->fw_state = cpu_to_le16(MFI_PD_STATE_SYSTEM); } else { VAR_3->fw_state = cpu_to_le16(MFI_PD_STATE_ONLINE); } } else { VAR_3->fw_state = cpu_to_le16(MFI_PD_STATE_OFFLINE); } VAR_3->ref.v.device_id = cpu_to_le16(sdev_id); VAR_3->state.ddf.pd_type = cpu_to_le16(MFI_PD_DDF_TYPE_IN_VD|
MFI_PD_DDF_TYPE_INTF_SAS); bdrv_get_geometry(conf->bs, &pd_size); VAR_3->raw_size = cpu_to_le64(pd_size); VAR_3->non_coerced_size = cpu_to_le64(pd_size); VAR_3->coerced_size = cpu_to_le64(pd_size); VAR_3->encl_device_id = 0xFFFF; VAR_3->slot_number = (VAR_0->id & 0xFF); VAR_3->path_info.count = 1; VAR_3->path_info.sas_addr[0] =
cpu_to_le64(megasas_get_sata_addr(sdev_id)); VAR_3->connected_port_bitmap = 0x1; VAR_3->device_speed = 1; VAR_3->link_speed = 1; resid = dma_buf_read(VAR_2->iov_buf, dcmd_size, &VAR_2->qsg); g_free(VAR_2->iov_buf); VAR_2->iov_size = dcmd_size - resid; VAR_2->iov_buf = NULL; return MFI_STAT_OK; }