static int ips_send_io_request(ips_command_t *command) { ips_softc_t *sc = command->sc; struct buf *iobuf = command->arg; command->data_dmatag = sc->sg_dmatag; if(bus_dmamap_create(command->data_dmatag, 0, &command->data_dmamap)){ device_printf(sc->dev, "dmamap failed\n"); iobuf->b_flags |= B_ERROR; iobuf->b_error = ENOMEM; ips_insert_free_cmd(sc, command); ipsd_finish(iobuf); return 0; } command->callback = ips_io_request_finish; PRINTF(10, "ips test: : bcount %ld\n", iobuf->b_bcount); bus_dmamap_load(command->data_dmatag, command->data_dmamap, iobuf->b_data, iobuf->b_bcount, ips_io_request_callback, command, 0); return 0; }
/* Below are a series of functions for sending an IO request * to the adapter. The flow order is: start, send, callback, finish. * The caller must have already assembled an iorequest struct to hold * the details of the IO request. */ static void ips_io_request_finish(ips_command_t *command) { struct buf *iobuf = command->arg; if(ips_read_request(iobuf)) { bus_dmamap_sync(command->data_dmatag, command->data_dmamap, BUS_DMASYNC_POSTREAD); } else { bus_dmamap_sync(command->data_dmatag, command->data_dmamap, BUS_DMASYNC_POSTWRITE); } bus_dmamap_unload(command->data_dmatag, command->data_dmamap); bus_dmamap_destroy(command->data_dmatag, command->data_dmamap); if(COMMAND_ERROR(&command->status)){ iobuf->b_flags |=B_ERROR; iobuf->b_error = EIO; } ips_insert_free_cmd(command->sc, command); ipsd_finish(iobuf); }
/* Below are a series of functions for sending an IO request * to the adapter. The flow order is: start, send, callback, finish. * The caller must have already assembled an iorequest struct to hold * the details of the IO request. */ static void ips_io_request_finish(ips_command_t *command) { struct bio *iobuf = command->arg; if(ips_read_request(iobuf)) { bus_dmamap_sync(command->data_dmatag, command->data_dmamap, BUS_DMASYNC_POSTREAD); } else { bus_dmamap_sync(command->data_dmatag, command->data_dmamap, BUS_DMASYNC_POSTWRITE); } bus_dmamap_unload(command->data_dmatag, command->data_dmamap); if(COMMAND_ERROR(command)){ iobuf->bio_flags |=BIO_ERROR; iobuf->bio_error = EIO; printf("ips: io error, status= 0x%x\n", command->status.value); } ips_insert_free_cmd(command->sc, command); ipsd_finish(iobuf); }
static void ips_io_request_callback(void *cmdptr, bus_dma_segment_t *segments,int segnum, int error) { ips_softc_t *sc; ips_command_t *command = cmdptr; ips_sg_element_t *sg_list; ips_io_cmd *command_struct; struct buf *iobuf = command->arg; int i, length = 0; u_int8_t cmdtype; sc = command->sc; if(error){ printf("ips: error = %d in ips_sg_request_callback\n", error); bus_dmamap_unload(command->data_dmatag, command->data_dmamap); bus_dmamap_destroy(command->data_dmatag, command->data_dmamap); iobuf->b_flags |= B_ERROR; iobuf->b_error = ENOMEM; ips_insert_free_cmd(sc, command); ipsd_finish(iobuf); return; } command_struct = (ips_io_cmd *)command->command_buffer; command_struct->id = command->id; command_struct->drivenum = (uintptr_t)iobuf->b_driver1; if(segnum != 1){ if(ips_read_request(iobuf)) cmdtype = IPS_SG_READ_CMD; else cmdtype = IPS_SG_WRITE_CMD; command_struct->segnum = segnum; sg_list = (ips_sg_element_t *)((u_int8_t *) command->command_buffer + IPS_COMMAND_LEN); for(i = 0; i < segnum; i++){ sg_list[i].addr = segments[i].ds_addr; sg_list[i].len = segments[i].ds_len; length += segments[i].ds_len; } command_struct->buffaddr = (u_int32_t)command->command_phys_addr + IPS_COMMAND_LEN; } else { if(ips_read_request(iobuf)) cmdtype = IPS_READ_CMD; else cmdtype = IPS_WRITE_CMD; command_struct->buffaddr = segments[0].ds_addr; length = segments[0].ds_len; } command_struct->command = cmdtype; command_struct->lba = iobuf->b_pblkno; length = (length + IPS_BLKSIZE - 1)/IPS_BLKSIZE; command_struct->length = length; bus_dmamap_sync(sc->command_dmatag, command->command_dmamap, BUS_DMASYNC_PREWRITE); if(ips_read_request(iobuf)) { bus_dmamap_sync(command->data_dmatag, command->data_dmamap, BUS_DMASYNC_PREREAD); } else { bus_dmamap_sync(command->data_dmatag, command->data_dmamap, BUS_DMASYNC_PREWRITE); } PRINTF(10, "ips test: command id: %d segments: %d " "pblkno: %lld length: %d, ds_len: %d\n", command->id, segnum, iobuf->b_pblkno, length, segments[0].ds_len); sc->ips_issue_cmd(command); return; }