-static inline struct bio *idescsi_kmalloc_bio (int count)
-{
- struct bio *bh, *bhp, *first_bh;
-
- if ((first_bh = bhp = bh = bio_alloc(GFP_ATOMIC, 1)) == NULL)
- goto abort;
- bio_init(bh);
- bh->bi_vcnt = 1;
- while (--count) {
- if ((bh = bio_alloc(GFP_ATOMIC, 1)) == NULL)
- goto abort;
- bio_init(bh);
- bh->bi_vcnt = 1;
- bhp->bi_next = bh;
- bhp = bh;
- bh->bi_next = NULL;
- }
- return first_bh;
-abort:
- idescsi_free_bio (first_bh);
- return NULL;
-}
-
-static inline int idescsi_set_direction (idescsi_pc_t *pc)
-{
- switch (pc->c[0]) {
- case READ_6: case READ_10: case READ_12:
- clear_bit (PC_WRITING, &pc->flags);
- return 0;
- case WRITE_6: case WRITE_10: case WRITE_12:
- set_bit (PC_WRITING, &pc->flags);
- return 0;
- default:
- return 1;
- }
-}
-
-static inline struct bio *idescsi_dma_bio(ide_drive_t *drive, idescsi_pc_t *pc)
-{
- struct bio *bh = NULL, *first_bh = NULL;
- int segments = pc->scsi_cmd->use_sg;
- struct scatterlist *sg = pc->scsi_cmd->request_buffer;
-
- if (!drive->using_dma || !pc->request_transfer || pc->request_transfer % 1024)
- return NULL;
- if (idescsi_set_direction(pc))
- return NULL;
- if (segments) {
- if ((first_bh = bh = idescsi_kmalloc_bio (segments)) == NULL)
- return NULL;
-#if IDESCSI_DEBUG_LOG
- printk ("ide-scsi: %s: building DMA table, %d segments, %dkB total\n", drive->name, segments, pc->request_transfer >> 10);
-#endif /* IDESCSI_DEBUG_LOG */
- while (segments--) {
- bh->bi_io_vec[0].bv_page = sg->page;
- bh->bi_io_vec[0].bv_len = sg->length;
- bh->bi_io_vec[0].bv_offset = sg->offset;
- bh->bi_size = sg->length;
- bh = bh->bi_next;
- sg++;
- }
- } else {
- if ((first_bh = bh = idescsi_kmalloc_bio (1)) == NULL)
- return NULL;
-#if IDESCSI_DEBUG_LOG
- printk ("ide-scsi: %s: building DMA table for a single buffer (%dkB)\n", drive->name, pc->request_transfer >> 10);
-#endif /* IDESCSI_DEBUG_LOG */
- bh->bi_io_vec[0].bv_page = virt_to_page(pc->scsi_cmd->request_buffer);
- bh->bi_io_vec[0].bv_offset = offset_in_page(pc->scsi_cmd->request_buffer);
- bh->bi_io_vec[0].bv_len = pc->request_transfer;
- bh->bi_size = pc->request_transfer;
- }
- return first_bh;
-}
-
-static inline int should_transform(ide_drive_t *drive, Scsi_Cmnd *cmd)