static int vscsi_srp_indirect_data(VSCSIState *s, vscsi_req *req,

                                   uint8_t *buf, uint32_t len)

{

    struct srp_direct_buf *td = &req->ind_desc->table_desc;

    struct srp_direct_buf *md = req->cur_desc;

    int rc = 0;

    uint32_t llen, total = 0;



    dprintf("VSCSI: indirect segment 0x%x bytes, td va=0x%llx len=0x%x\n",

            len, (unsigned long long)td->va, td->len);



    /* While we have data ... */

    while (len) {

        /* If we have a descriptor but it's empty, go fetch a new one */

        if (md && md->len == 0) {

            /* More local available, use one */

            if (req->local_desc) {

                md = ++req->cur_desc;

                --req->local_desc;

                --req->total_desc;

                td->va += sizeof(struct srp_direct_buf);

            } else {

                md = req->cur_desc = NULL;

            }

        }

        /* No descriptor at hand, fetch one */

        if (!md) {

            if (!req->total_desc) {

                dprintf("VSCSI:   Out of descriptors !\n");

                break;

            }

            md = req->cur_desc = &req->ext_desc;

            dprintf("VSCSI:   Reading desc from 0x%llx\n",

                    (unsigned long long)td->va);

            rc = spapr_tce_dma_read(&s->vdev, td->va, md,

                                    sizeof(struct srp_direct_buf));

            if (rc) {

                dprintf("VSCSI: tce_dma_read -> %d reading ext_desc\n", rc);

                break;

            }

            vscsi_swap_desc(md);

            td->va += sizeof(struct srp_direct_buf);

            --req->total_desc;

        }

        dprintf("VSCSI:   [desc va=0x%llx,len=0x%x] remaining=0x%x\n",

                (unsigned long long)md->va, md->len, len);



        /* Perform transfer */

        llen = MIN(len, md->len);

        if (req->writing) { /* writing = to device = reading from memory */

            rc = spapr_tce_dma_read(&s->vdev, md->va, buf, llen);

        } else {

            rc = spapr_tce_dma_write(&s->vdev, md->va, buf, llen);

        }

        if (rc) {

            dprintf("VSCSI: tce_dma_r/w(%d) -> %d\n", req->writing, rc);

            break;

        }

        dprintf("VSCSI:     data: %02x %02x %02x %02x...\n",

                buf[0], buf[1], buf[2], buf[3]);



        len -= llen;

        buf += llen;

        total += llen;

        md->va += llen;

        md->len -= llen;

    }

    return rc ? -1 : total;

}

static int vscsi_srp_indirect_data(VSCSIState *s, vscsi_req *req,

                                   uint8_t *buf, uint32_t len)

{

    struct srp_direct_buf *td = &req->ind_desc->table_desc;

    struct srp_direct_buf *md = req->cur_desc;

    int rc = 0;

    uint32_t llen, total = 0;



    dprintf("VSCSI: indirect segment 0x%x bytes, td va=0x%llx len=0x%x\n",

            len, (unsigned long long)td->va, td->len);



    

    while (len) {

        

        if (md && md->len == 0) {

            

            if (req->local_desc) {

                md = ++req->cur_desc;

                --req->local_desc;

                --req->total_desc;

                td->va += sizeof(struct srp_direct_buf);

            } else {

                md = req->cur_desc = NULL;

            }

        }

        

        if (!md) {

            if (!req->total_desc) {

                dprintf("VSCSI:   Out of descriptors !\n");

                break;

            }

            md = req->cur_desc = &req->ext_desc;

            dprintf("VSCSI:   Reading desc from 0x%llx\n",

                    (unsigned long long)td->va);

            rc = spapr_tce_dma_read(&s->vdev, td->va, md,

                                    sizeof(struct srp_direct_buf));

            if (rc) {

                dprintf("VSCSI: tce_dma_read -> %d reading ext_desc\n", rc);

                break;

            }

            vscsi_swap_desc(md);

            td->va += sizeof(struct srp_direct_buf);

            --req->total_desc;

        }

        dprintf("VSCSI:   [desc va=0x%llx,len=0x%x] remaining=0x%x\n",

                (unsigned long long)md->va, md->len, len);



        

        llen = MIN(len, md->len);

        if (req->writing) { 

            rc = spapr_tce_dma_read(&s->vdev, md->va, buf, llen);

        } else {

            rc = spapr_tce_dma_write(&s->vdev, md->va, buf, llen);

        }

        if (rc) {

            dprintf("VSCSI: tce_dma_r/w(%d) -> %d\n", req->writing, rc);

            break;

        }

        dprintf("VSCSI:     data: %02x %02x %02x %02x...\n",

                buf[0], buf[1], buf[2], buf[3]);



        len -= llen;

        buf += llen;

        total += llen;

        md->va += llen;

        md->len -= llen;

    }

    return rc ? -1 : total;

}

            rc = spapr_tce_dma_read(&s->vdev, md->va, buf, llen);             rc = spapr_tce_dma_write(&s->vdev, md->va, buf, llen);             rc = spapr_tce_dma_read(&s->vdev, td->va, md,                 dprintf("VSCSI: tce_dma_read -> %d reading ext_desc\n", rc);             rc = spapr_tce_dma_read(&s->vdev, md->va, buf, llen);             rc = spapr_tce_dma_write(&s->vdev, md->va, buf, llen);             dprintf("VSCSI: tce_dma_r/w(%d) -> %d\n", req->writing, rc);
static int FUNC_0(VSCSIState *VAR_0, vscsi_req *VAR_1,

                                   uint8_t *VAR_2, uint32_t VAR_3)

{

    struct srp_direct_buf *VAR_4 = &VAR_1->ind_desc->table_desc;

    struct srp_direct_buf *VAR_5 = VAR_1->cur_desc;

    int VAR_6 = 0;

    uint32_t llen, total = 0;



    dprintf("VSCSI: indirect segment 0x%x bytes, VAR_4 va=0x%llx VAR_3=0x%x\n",

            VAR_3, (unsigned long long)VAR_4->va, VAR_4->VAR_3);



    

    while (VAR_3) {

        

        if (VAR_5 && VAR_5->VAR_3 == 0) {

            

            if (VAR_1->local_desc) {

                VAR_5 = ++VAR_1->cur_desc;

                --VAR_1->local_desc;

                --VAR_1->total_desc;

                VAR_4->va += sizeof(struct srp_direct_buf);

            } else {

                VAR_5 = VAR_1->cur_desc = NULL;

            }

        }

        

        if (!VAR_5) {

            if (!VAR_1->total_desc) {

                dprintf("VSCSI:   Out of descriptors !\n");

                break;

            }

            VAR_5 = VAR_1->cur_desc = &VAR_1->ext_desc;

            dprintf("VSCSI:   Reading desc from 0x%llx\n",

                    (unsigned long long)VAR_4->va);

            VAR_6 = spapr_tce_dma_read(&VAR_0->vdev, VAR_4->va, VAR_5,

                                    sizeof(struct srp_direct_buf));

            if (VAR_6) {

                dprintf("VSCSI: tce_dma_read -> %d reading ext_desc\n", VAR_6);

                break;

            }

            vscsi_swap_desc(VAR_5);

            VAR_4->va += sizeof(struct srp_direct_buf);

            --VAR_1->total_desc;

        }

        dprintf("VSCSI:   [desc va=0x%llx,VAR_3=0x%x] remaining=0x%x\n",

                (unsigned long long)VAR_5->va, VAR_5->VAR_3, VAR_3);



        

        llen = MIN(VAR_3, VAR_5->VAR_3);

        if (VAR_1->writing) { 

            VAR_6 = spapr_tce_dma_read(&VAR_0->vdev, VAR_5->va, VAR_2, llen);

        } else {

            VAR_6 = spapr_tce_dma_write(&VAR_0->vdev, VAR_5->va, VAR_2, llen);

        }

        if (VAR_6) {

            dprintf("VSCSI: tce_dma_r/w(%d) -> %d\n", VAR_1->writing, VAR_6);

            break;

        }

        dprintf("VSCSI:     data: %02x %02x %02x %02x...\n",

                VAR_2[0], VAR_2[1], VAR_2[2], VAR_2[3]);



        VAR_3 -= llen;

        VAR_2 += llen;

        total += llen;

        VAR_5->va += llen;

        VAR_5->VAR_3 -= llen;

    }

    return VAR_6 ? -1 : total;

}

static int FUNC_0(VSCSIState *VAR_0, vscsi_req *VAR_1,
uint8_t *VAR_2, uint32_t VAR_3)
{ struct srp_direct_buf *VAR_4 = &VAR_1->ind_desc->table_desc; struct srp_direct_buf *VAR_5 = VAR_1->cur_desc; int VAR_6 = 0; uint32_t llen, total = 0; dprintf("VSCSI: indirect segment 0x%x bytes, VAR_4 va=0x%llx VAR_3=0x%x\n",
VAR_3, (unsigned long long)VAR_4->va, VAR_4->VAR_3); while (VAR_3) { if (VAR_5 && VAR_5->VAR_3 == 0) { if (VAR_1->local_desc) { VAR_5 = ++VAR_1->cur_desc; --VAR_1->local_desc; --VAR_1->total_desc; VAR_4->va += sizeof(struct srp_direct_buf); } else { VAR_5 = VAR_1->cur_desc = NULL; } } if (!VAR_5) { if (!VAR_1->total_desc) { dprintf("VSCSI:   Out of descriptors !\n"); break; } VAR_5 = VAR_1->cur_desc = &VAR_1->ext_desc; dprintf("VSCSI:   Reading desc from 0x%llx\n",
(unsigned long long)VAR_4->va); VAR_6 = spapr_tce_dma_read(&VAR_0->vdev, VAR_4->va, VAR_5,
sizeof(struct srp_direct_buf)); if (VAR_6) { dprintf("VSCSI: tce_dma_read -> %d reading ext_desc\n", VAR_6); break; } vscsi_swap_desc(VAR_5); VAR_4->va += sizeof(struct srp_direct_buf); --VAR_1->total_desc; } dprintf("VSCSI:   [desc va=0x%llx,VAR_3=0x%x] remaining=0x%x\n",
(unsigned long long)VAR_5->va, VAR_5->VAR_3, VAR_3); llen = MIN(VAR_3, VAR_5->VAR_3); if (VAR_1->writing) { VAR_6 = spapr_tce_dma_read(&VAR_0->vdev, VAR_5->va, VAR_2, llen); } else { VAR_6 = spapr_tce_dma_write(&VAR_0->vdev, VAR_5->va, VAR_2, llen); } if (VAR_6) { dprintf("VSCSI: tce_dma_r/w(%d) -> %d\n", VAR_1->writing, VAR_6); break; } dprintf("VSCSI:     data: %02x %02x %02x %02x...\n",
VAR_2[0], VAR_2[1], VAR_2[2], VAR_2[3]); VAR_3 -= llen; VAR_2 += llen; total += llen; VAR_5->va += llen; VAR_5->VAR_3 -= llen; } return VAR_6 ? -1 : total; }