Deleted Added
full compact
scsi_target.c (58934) scsi_target.c (59249)
1/*
2 * Implementation of a simple Target Mode SCSI Proccessor Target driver for CAM.
3 *
4 * Copyright (c) 1998, 1999 Justin T. Gibbs.
5 * All rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions

--- 11 unchanged lines hidden (view full) ---

20 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26 * SUCH DAMAGE.
27 *
1/*
2 * Implementation of a simple Target Mode SCSI Proccessor Target driver for CAM.
3 *
4 * Copyright (c) 1998, 1999 Justin T. Gibbs.
5 * All rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions

--- 11 unchanged lines hidden (view full) ---

20 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26 * SUCH DAMAGE.
27 *
28 * $FreeBSD: head/sys/cam/scsi/scsi_target.c 58934 2000-04-02 15:24:56Z phk $
28 * $FreeBSD: head/sys/cam/scsi/scsi_target.c 59249 2000-04-15 05:54:02Z phk $
29 */
30#include <stddef.h> /* For offsetof */
31
32#include <sys/param.h>
33#include <sys/queue.h>
34#include <sys/systm.h>
35#include <sys/kernel.h>
36#include <sys/types.h>

--- 82 unchanged lines hidden (view full) ---

119 * consume.
120 */
121 struct ccb_queue unknown_atio_queue;
122
123 /*
124 * Userland buffers for SEND commands waiting for
125 * SEND ATIOs to be queued by an initiator.
126 */
29 */
30#include <stddef.h> /* For offsetof */
31
32#include <sys/param.h>
33#include <sys/queue.h>
34#include <sys/systm.h>
35#include <sys/kernel.h>
36#include <sys/types.h>

--- 82 unchanged lines hidden (view full) ---

119 * consume.
120 */
121 struct ccb_queue unknown_atio_queue;
122
123 /*
124 * Userland buffers for SEND commands waiting for
125 * SEND ATIOs to be queued by an initiator.
126 */
127 struct buf_queue_head snd_buf_queue;
127 struct bio_queue_head snd_bio_queue;
128
129 /*
130 * Userland buffers for RCV commands waiting for
131 * RCV ATIOs to be queued by an initiator.
132 */
128
129 /*
130 * Userland buffers for RCV commands waiting for
131 * RCV ATIOs to be queued by an initiator.
132 */
133 struct buf_queue_head rcv_buf_queue;
133 struct bio_queue_head rcv_bio_queue;
134 struct devstat device_stats;
135 dev_t targ_dev;
136 struct selinfo snd_select;
137 struct selinfo rcv_select;
138 targ_state state;
139 targ_flags flags;
140 targ_exception exceptions;
141 u_int init_level;

--- 5 unchanged lines hidden (view full) ---

147};
148
149struct targ_cmd_desc {
150 struct ccb_accept_tio* atio_link;
151 u_int data_resid; /* How much left to transfer */
152 u_int data_increment;/* Amount to send before next disconnect */
153 void* data; /* The data. Can be from backing_store or not */
154 void* backing_store;/* Backing store allocated for this descriptor*/
134 struct devstat device_stats;
135 dev_t targ_dev;
136 struct selinfo snd_select;
137 struct selinfo rcv_select;
138 targ_state state;
139 targ_flags flags;
140 targ_exception exceptions;
141 u_int init_level;

--- 5 unchanged lines hidden (view full) ---

147};
148
149struct targ_cmd_desc {
150 struct ccb_accept_tio* atio_link;
151 u_int data_resid; /* How much left to transfer */
152 u_int data_increment;/* Amount to send before next disconnect */
153 void* data; /* The data. Can be from backing_store or not */
154 void* backing_store;/* Backing store allocated for this descriptor*/
155 struct buf *bp; /* Buffer for this transfer */
155 struct bio *bp; /* Buffer for this transfer */
156 u_int max_size; /* Size of backing_store */
157 u_int32_t timeout;
158 u_int8_t status; /* Status to return to initiator */
159};
160
161static d_open_t targopen;
162static d_close_t targclose;
163static d_read_t targread;

--- 288 unchanged lines hidden (view full) ---

452 }
453
454 bzero(softc, sizeof(*softc));
455 TAILQ_INIT(&softc->pending_queue);
456 TAILQ_INIT(&softc->work_queue);
457 TAILQ_INIT(&softc->snd_ccb_queue);
458 TAILQ_INIT(&softc->rcv_ccb_queue);
459 TAILQ_INIT(&softc->unknown_atio_queue);
156 u_int max_size; /* Size of backing_store */
157 u_int32_t timeout;
158 u_int8_t status; /* Status to return to initiator */
159};
160
161static d_open_t targopen;
162static d_close_t targclose;
163static d_read_t targread;

--- 288 unchanged lines hidden (view full) ---

452 }
453
454 bzero(softc, sizeof(*softc));
455 TAILQ_INIT(&softc->pending_queue);
456 TAILQ_INIT(&softc->work_queue);
457 TAILQ_INIT(&softc->snd_ccb_queue);
458 TAILQ_INIT(&softc->rcv_ccb_queue);
459 TAILQ_INIT(&softc->unknown_atio_queue);
460 bufq_init(&softc->snd_buf_queue);
461 bufq_init(&softc->rcv_buf_queue);
460 bioq_init(&softc->snd_bio_queue);
461 bioq_init(&softc->rcv_bio_queue);
462 softc->accept_tio_list = NULL;
463 SLIST_INIT(&softc->immed_notify_slist);
464 softc->state = TARG_STATE_NORMAL;
465 periph->softc = softc;
466 softc->init_level++;
467
468 cam_extend_set(targperiphs, periph->unit_number, periph);
469

--- 554 unchanged lines hidden (view full) ---

1024 if (periph == NULL)
1025 return (ENXIO);
1026 softc = (struct targ_softc *)periph->softc;
1027
1028 revents = 0;
1029 s = splcam();
1030 if ((poll_events & (POLLOUT | POLLWRNORM)) != 0) {
1031 if (TAILQ_FIRST(&softc->rcv_ccb_queue) != NULL
462 softc->accept_tio_list = NULL;
463 SLIST_INIT(&softc->immed_notify_slist);
464 softc->state = TARG_STATE_NORMAL;
465 periph->softc = softc;
466 softc->init_level++;
467
468 cam_extend_set(targperiphs, periph->unit_number, periph);
469

--- 554 unchanged lines hidden (view full) ---

1024 if (periph == NULL)
1025 return (ENXIO);
1026 softc = (struct targ_softc *)periph->softc;
1027
1028 revents = 0;
1029 s = splcam();
1030 if ((poll_events & (POLLOUT | POLLWRNORM)) != 0) {
1031 if (TAILQ_FIRST(&softc->rcv_ccb_queue) != NULL
1032 && bufq_first(&softc->rcv_buf_queue) == NULL)
1032 && bioq_first(&softc->rcv_bio_queue) == NULL)
1033 revents |= poll_events & (POLLOUT | POLLWRNORM);
1034 }
1035 if ((poll_events & (POLLIN | POLLRDNORM)) != 0) {
1036 if (TAILQ_FIRST(&softc->snd_ccb_queue) != NULL
1033 revents |= poll_events & (POLLOUT | POLLWRNORM);
1034 }
1035 if ((poll_events & (POLLIN | POLLRDNORM)) != 0) {
1036 if (TAILQ_FIRST(&softc->snd_ccb_queue) != NULL
1037 && bufq_first(&softc->snd_buf_queue) == NULL)
1037 && bioq_first(&softc->snd_bio_queue) == NULL)
1038 revents |= poll_events & (POLLIN | POLLRDNORM);
1039 }
1040
1041 if (softc->state != TARG_STATE_NORMAL)
1042 revents |= POLLERR;
1043
1044 if (revents == 0) {
1045 if (poll_events & (POLLOUT | POLLWRNORM))

--- 66 unchanged lines hidden (view full) ---

1112}
1113
1114/*
1115 * Actually translate the requested transfer into one the physical driver
1116 * can understand. The transfer is described by a buf and will include
1117 * only one physical transfer.
1118 */
1119static void
1038 revents |= poll_events & (POLLIN | POLLRDNORM);
1039 }
1040
1041 if (softc->state != TARG_STATE_NORMAL)
1042 revents |= POLLERR;
1043
1044 if (revents == 0) {
1045 if (poll_events & (POLLOUT | POLLWRNORM))

--- 66 unchanged lines hidden (view full) ---

1112}
1113
1114/*
1115 * Actually translate the requested transfer into one the physical driver
1116 * can understand. The transfer is described by a buf and will include
1117 * only one physical transfer.
1118 */
1119static void
1120targstrategy(struct buf *bp)
1120targstrategy(struct bio *bp)
1121{
1122 struct cam_periph *periph;
1123 struct targ_softc *softc;
1124 u_int unit;
1125 int s;
1126
1121{
1122 struct cam_periph *periph;
1123 struct targ_softc *softc;
1124 u_int unit;
1125 int s;
1126
1127 unit = minor(bp->b_dev);
1127 unit = minor(bp->bio_dev);
1128
1129 /* ioctl is the only supported operation of the control device */
1130 if (TARG_IS_CONTROL_DEV(unit)) {
1128
1129 /* ioctl is the only supported operation of the control device */
1130 if (TARG_IS_CONTROL_DEV(unit)) {
1131 bp->b_error = EINVAL;
1131 bp->bio_error = EINVAL;
1132 goto bad;
1133 }
1134
1135 periph = cam_extend_get(targperiphs, unit);
1136 if (periph == NULL) {
1132 goto bad;
1133 }
1134
1135 periph = cam_extend_get(targperiphs, unit);
1136 if (periph == NULL) {
1137 bp->b_error = ENXIO;
1137 bp->bio_error = ENXIO;
1138 goto bad;
1139 }
1140 softc = (struct targ_softc *)periph->softc;
1141
1142 /*
1143 * Mask interrupts so that the device cannot be invalidated until
1144 * after we are in the queue. Otherwise, we might not properly
1145 * clean up one of the buffers.
1146 */
1147 s = splbio();
1148
1149 /*
1150 * If there is an exception pending, error out
1151 */
1152 if (softc->state != TARG_STATE_NORMAL) {
1153 splx(s);
1154 if (softc->state == TARG_STATE_EXCEPTION
1155 && (softc->exceptions & TARG_EXCEPT_DEVICE_INVALID) == 0)
1138 goto bad;
1139 }
1140 softc = (struct targ_softc *)periph->softc;
1141
1142 /*
1143 * Mask interrupts so that the device cannot be invalidated until
1144 * after we are in the queue. Otherwise, we might not properly
1145 * clean up one of the buffers.
1146 */
1147 s = splbio();
1148
1149 /*
1150 * If there is an exception pending, error out
1151 */
1152 if (softc->state != TARG_STATE_NORMAL) {
1153 splx(s);
1154 if (softc->state == TARG_STATE_EXCEPTION
1155 && (softc->exceptions & TARG_EXCEPT_DEVICE_INVALID) == 0)
1156 bp->b_error = EBUSY;
1156 bp->bio_error = EBUSY;
1157 else
1157 else
1158 bp->b_error = ENXIO;
1158 bp->bio_error = ENXIO;
1159 goto bad;
1160 }
1161
1162 /*
1163 * Place it in the queue of buffers available for either
1164 * SEND or RECEIVE commands.
1165 *
1166 */
1159 goto bad;
1160 }
1161
1162 /*
1163 * Place it in the queue of buffers available for either
1164 * SEND or RECEIVE commands.
1165 *
1166 */
1167 bp->b_resid = bp->b_bcount;
1168 if (bp->b_iocmd == BIO_READ) {
1167 bp->bio_resid = bp->bio_bcount;
1168 if (bp->bio_cmd == BIO_READ) {
1169 CAM_DEBUG(periph->path, CAM_DEBUG_PERIPH,
1170 ("Queued a SEND buffer\n"));
1169 CAM_DEBUG(periph->path, CAM_DEBUG_PERIPH,
1170 ("Queued a SEND buffer\n"));
1171 bufq_insert_tail(&softc->snd_buf_queue, bp);
1171 bioq_insert_tail(&softc->snd_bio_queue, bp);
1172 } else {
1173 CAM_DEBUG(periph->path, CAM_DEBUG_PERIPH,
1174 ("Queued a RECEIVE buffer\n"));
1172 } else {
1173 CAM_DEBUG(periph->path, CAM_DEBUG_PERIPH,
1174 ("Queued a RECEIVE buffer\n"));
1175 bufq_insert_tail(&softc->rcv_buf_queue, bp);
1175 bioq_insert_tail(&softc->rcv_bio_queue, bp);
1176 }
1177
1178 splx(s);
1179
1180 /*
1181 * Attempt to use the new buffer to service any pending
1182 * target commands.
1183 */
1184 targrunqueue(periph, softc);
1185
1186 return;
1187bad:
1176 }
1177
1178 splx(s);
1179
1180 /*
1181 * Attempt to use the new buffer to service any pending
1182 * target commands.
1183 */
1184 targrunqueue(periph, softc);
1185
1186 return;
1187bad:
1188 bp->b_ioflags |= BIO_ERROR;
1188 bp->bio_flags |= BIO_ERROR;
1189
1190 /*
1191 * Correctly set the buf to indicate a completed xfer
1192 */
1189
1190 /*
1191 * Correctly set the buf to indicate a completed xfer
1192 */
1193 bp->b_resid = bp->b_bcount;
1193 bp->bio_resid = bp->bio_bcount;
1194 biodone(bp);
1195}
1196
1197static void
1198targrunqueue(struct cam_periph *periph, struct targ_softc *softc)
1199{
1200 struct ccb_queue *pending_queue;
1201 struct ccb_accept_tio *atio;
1194 biodone(bp);
1195}
1196
1197static void
1198targrunqueue(struct cam_periph *periph, struct targ_softc *softc)
1199{
1200 struct ccb_queue *pending_queue;
1201 struct ccb_accept_tio *atio;
1202 struct buf_queue_head *bufq;
1203 struct buf *bp;
1202 struct bio_queue_head *bioq;
1203 struct bio *bp;
1204 struct targ_cmd_desc *desc;
1205 struct ccb_hdr *ccbh;
1206 int s;
1207
1208 s = splbio();
1209 pending_queue = NULL;
1204 struct targ_cmd_desc *desc;
1205 struct ccb_hdr *ccbh;
1206 int s;
1207
1208 s = splbio();
1209 pending_queue = NULL;
1210 bufq = NULL;
1210 bioq = NULL;
1211 ccbh = NULL;
1212 /* Only run one request at a time to maintain data ordering. */
1213 if (softc->state != TARG_STATE_NORMAL
1214 || TAILQ_FIRST(&softc->work_queue) != NULL
1215 || TAILQ_FIRST(&softc->pending_queue) != NULL) {
1216 splx(s);
1217 return;
1218 }
1219
1211 ccbh = NULL;
1212 /* Only run one request at a time to maintain data ordering. */
1213 if (softc->state != TARG_STATE_NORMAL
1214 || TAILQ_FIRST(&softc->work_queue) != NULL
1215 || TAILQ_FIRST(&softc->pending_queue) != NULL) {
1216 splx(s);
1217 return;
1218 }
1219
1220 if (((bp = bufq_first(&softc->snd_buf_queue)) != NULL
1220 if (((bp = bioq_first(&softc->snd_bio_queue)) != NULL
1221 || (softc->flags & TARG_FLAG_SEND_EOF) != 0)
1222 && (ccbh = TAILQ_FIRST(&softc->snd_ccb_queue)) != NULL) {
1223
1224 if (bp == NULL)
1225 softc->flags &= ~TARG_FLAG_SEND_EOF;
1226 else {
1227 CAM_DEBUG(periph->path, CAM_DEBUG_PERIPH,
1228 ("De-Queued a SEND buffer %ld\n",
1221 || (softc->flags & TARG_FLAG_SEND_EOF) != 0)
1222 && (ccbh = TAILQ_FIRST(&softc->snd_ccb_queue)) != NULL) {
1223
1224 if (bp == NULL)
1225 softc->flags &= ~TARG_FLAG_SEND_EOF;
1226 else {
1227 CAM_DEBUG(periph->path, CAM_DEBUG_PERIPH,
1228 ("De-Queued a SEND buffer %ld\n",
1229 bp->b_bcount));
1229 bp->bio_bcount));
1230 }
1230 }
1231 bufq = &softc->snd_buf_queue;
1231 bioq = &softc->snd_bio_queue;
1232 pending_queue = &softc->snd_ccb_queue;
1232 pending_queue = &softc->snd_ccb_queue;
1233 } else if (((bp = bufq_first(&softc->rcv_buf_queue)) != NULL
1233 } else if (((bp = bioq_first(&softc->rcv_bio_queue)) != NULL
1234 || (softc->flags & TARG_FLAG_RECEIVE_EOF) != 0)
1235 && (ccbh = TAILQ_FIRST(&softc->rcv_ccb_queue)) != NULL) {
1236
1237 if (bp == NULL)
1238 softc->flags &= ~TARG_FLAG_RECEIVE_EOF;
1239 else {
1240 CAM_DEBUG(periph->path, CAM_DEBUG_PERIPH,
1241 ("De-Queued a RECEIVE buffer %ld\n",
1234 || (softc->flags & TARG_FLAG_RECEIVE_EOF) != 0)
1235 && (ccbh = TAILQ_FIRST(&softc->rcv_ccb_queue)) != NULL) {
1236
1237 if (bp == NULL)
1238 softc->flags &= ~TARG_FLAG_RECEIVE_EOF;
1239 else {
1240 CAM_DEBUG(periph->path, CAM_DEBUG_PERIPH,
1241 ("De-Queued a RECEIVE buffer %ld\n",
1242 bp->b_bcount));
1242 bp->bio_bcount));
1243 }
1243 }
1244 bufq = &softc->rcv_buf_queue;
1244 bioq = &softc->rcv_bio_queue;
1245 pending_queue = &softc->rcv_ccb_queue;
1246 }
1247
1248 if (pending_queue != NULL) {
1249 /* Process a request */
1250 atio = (struct ccb_accept_tio *)ccbh;
1251 TAILQ_REMOVE(pending_queue, ccbh, periph_links.tqe);
1252 desc = (struct targ_cmd_desc *)atio->ccb_h.ccb_descr;
1253 desc->bp = bp;
1254 if (bp == NULL) {
1255 /* EOF */
1256 desc->data = NULL;
1257 desc->data_increment = 0;
1258 desc->data_resid = 0;
1259 atio->ccb_h.flags &= ~CAM_DIR_MASK;
1260 atio->ccb_h.flags |= CAM_DIR_NONE;
1261 } else {
1245 pending_queue = &softc->rcv_ccb_queue;
1246 }
1247
1248 if (pending_queue != NULL) {
1249 /* Process a request */
1250 atio = (struct ccb_accept_tio *)ccbh;
1251 TAILQ_REMOVE(pending_queue, ccbh, periph_links.tqe);
1252 desc = (struct targ_cmd_desc *)atio->ccb_h.ccb_descr;
1253 desc->bp = bp;
1254 if (bp == NULL) {
1255 /* EOF */
1256 desc->data = NULL;
1257 desc->data_increment = 0;
1258 desc->data_resid = 0;
1259 atio->ccb_h.flags &= ~CAM_DIR_MASK;
1260 atio->ccb_h.flags |= CAM_DIR_NONE;
1261 } else {
1262 bufq_remove(bufq, bp);
1263 desc->data = &bp->b_data[bp->b_bcount - bp->b_resid];
1262 bioq_remove(bioq, bp);
1263 desc->data = &bp->bio_data[bp->bio_bcount - bp->bio_resid];
1264 desc->data_increment =
1264 desc->data_increment =
1265 MIN(desc->data_resid, bp->b_resid);
1265 MIN(desc->data_resid, bp->bio_resid);
1266 desc->data_increment =
1267 MIN(desc->data_increment, 32);
1268 }
1269 CAM_DEBUG(periph->path, CAM_DEBUG_PERIPH,
1270 ("Buffer command: data %x: datacnt %d\n",
1271 (intptr_t)desc->data, desc->data_increment));
1272 TAILQ_INSERT_TAIL(&softc->work_queue, &atio->ccb_h,
1273 periph_links.tqe);

--- 355 unchanged lines hidden (view full) ---

1629 xpt_schedule(periph, /*priority*/1);
1630 break;
1631 }
1632 case XPT_CONT_TARGET_IO:
1633 {
1634 struct ccb_scsiio *csio;
1635 struct ccb_accept_tio *atio;
1636 struct targ_cmd_desc *desc;
1266 desc->data_increment =
1267 MIN(desc->data_increment, 32);
1268 }
1269 CAM_DEBUG(periph->path, CAM_DEBUG_PERIPH,
1270 ("Buffer command: data %x: datacnt %d\n",
1271 (intptr_t)desc->data, desc->data_increment));
1272 TAILQ_INSERT_TAIL(&softc->work_queue, &atio->ccb_h,
1273 periph_links.tqe);

--- 355 unchanged lines hidden (view full) ---

1629 xpt_schedule(periph, /*priority*/1);
1630 break;
1631 }
1632 case XPT_CONT_TARGET_IO:
1633 {
1634 struct ccb_scsiio *csio;
1635 struct ccb_accept_tio *atio;
1636 struct targ_cmd_desc *desc;
1637 struct buf *bp;
1637 struct bio *bp;
1638 int error;
1639
1640 CAM_DEBUG(periph->path, CAM_DEBUG_PERIPH,
1641 ("Received completed CTIO\n"));
1642 csio = &done_ccb->csio;
1643 atio = (struct ccb_accept_tio*)done_ccb->ccb_h.ccb_atio;
1644 desc = (struct targ_cmd_desc *)atio->ccb_h.ccb_descr;
1645

--- 35 unchanged lines hidden (view full) ---

1681 done_ccb->ccb_h.status &= ~CAM_SENT_SENSE;
1682 }
1683 done_ccb->ccb_h.flags &= ~CAM_SEND_SENSE;
1684
1685 desc->data_increment -= csio->resid;
1686 desc->data_resid -= desc->data_increment;
1687 if ((bp = desc->bp) != NULL) {
1688
1638 int error;
1639
1640 CAM_DEBUG(periph->path, CAM_DEBUG_PERIPH,
1641 ("Received completed CTIO\n"));
1642 csio = &done_ccb->csio;
1643 atio = (struct ccb_accept_tio*)done_ccb->ccb_h.ccb_atio;
1644 desc = (struct targ_cmd_desc *)atio->ccb_h.ccb_descr;
1645

--- 35 unchanged lines hidden (view full) ---

1681 done_ccb->ccb_h.status &= ~CAM_SENT_SENSE;
1682 }
1683 done_ccb->ccb_h.flags &= ~CAM_SEND_SENSE;
1684
1685 desc->data_increment -= csio->resid;
1686 desc->data_resid -= desc->data_increment;
1687 if ((bp = desc->bp) != NULL) {
1688
1689 bp->b_resid -= desc->data_increment;
1690 bp->b_error = error;
1689 bp->bio_resid -= desc->data_increment;
1690 bp->bio_error = error;
1691
1692 CAM_DEBUG(periph->path, CAM_DEBUG_PERIPH,
1693 ("Buffer I/O Completed - Resid %ld:%d\n",
1691
1692 CAM_DEBUG(periph->path, CAM_DEBUG_PERIPH,
1693 ("Buffer I/O Completed - Resid %ld:%d\n",
1694 bp->b_resid, desc->data_resid));
1694 bp->bio_resid, desc->data_resid));
1695 /*
1696 * Send the buffer back to the client if
1697 * either the command has completed or all
1698 * buffer space has been consumed.
1699 */
1700 if (desc->data_resid == 0
1695 /*
1696 * Send the buffer back to the client if
1697 * either the command has completed or all
1698 * buffer space has been consumed.
1699 */
1700 if (desc->data_resid == 0
1701 || bp->b_resid == 0
1701 || bp->bio_resid == 0
1702 || error != 0) {
1702 || error != 0) {
1703 if (bp->b_resid != 0)
1703 if (bp->bio_resid != 0)
1704 /* Short transfer */
1704 /* Short transfer */
1705 bp->b_ioflags |= BIO_ERROR;
1705 bp->bio_flags |= BIO_ERROR;
1706
1707 CAM_DEBUG(periph->path, CAM_DEBUG_PERIPH,
1708 ("Completing a buffer\n"));
1709 biodone(bp);
1710 desc->bp = NULL;
1711 }
1712 }
1713

--- 10 unchanged lines hidden (view full) ---

1724 xpt_action((union ccb *)atio);
1725 break;
1726 }
1727
1728 /* Queue us up for another buffer */
1729 if (atio->cdb_io.cdb_bytes[0] == SEND) {
1730 if (desc->bp != NULL)
1731 TAILQ_INSERT_HEAD(
1706
1707 CAM_DEBUG(periph->path, CAM_DEBUG_PERIPH,
1708 ("Completing a buffer\n"));
1709 biodone(bp);
1710 desc->bp = NULL;
1711 }
1712 }
1713

--- 10 unchanged lines hidden (view full) ---

1724 xpt_action((union ccb *)atio);
1725 break;
1726 }
1727
1728 /* Queue us up for another buffer */
1729 if (atio->cdb_io.cdb_bytes[0] == SEND) {
1730 if (desc->bp != NULL)
1731 TAILQ_INSERT_HEAD(
1732 &softc->snd_buf_queue.queue,
1732 &softc->snd_bio_queue.queue,
1733 bp, b_act);
1734 TAILQ_INSERT_HEAD(&softc->snd_ccb_queue,
1735 &atio->ccb_h,
1736 periph_links.tqe);
1737 } else {
1738 if (desc->bp != NULL)
1739 TAILQ_INSERT_HEAD(
1733 bp, b_act);
1734 TAILQ_INSERT_HEAD(&softc->snd_ccb_queue,
1735 &atio->ccb_h,
1736 periph_links.tqe);
1737 } else {
1738 if (desc->bp != NULL)
1739 TAILQ_INSERT_HEAD(
1740 &softc->rcv_buf_queue.queue,
1740 &softc->rcv_bio_queue.queue,
1741 bp, b_act);
1742 TAILQ_INSERT_HEAD(&softc->rcv_ccb_queue,
1743 &atio->ccb_h,
1744 periph_links.tqe);
1745 }
1746 desc->bp = NULL;
1747 targrunqueue(periph, softc);
1748 } else {
1749 if (desc->bp != NULL) {
1741 bp, b_act);
1742 TAILQ_INSERT_HEAD(&softc->rcv_ccb_queue,
1743 &atio->ccb_h,
1744 periph_links.tqe);
1745 }
1746 desc->bp = NULL;
1747 targrunqueue(periph, softc);
1748 } else {
1749 if (desc->bp != NULL) {
1750 bp->b_ioflags |= BIO_ERROR;
1751 bp->b_error = ENXIO;
1750 bp->bio_flags |= BIO_ERROR;
1751 bp->bio_error = ENXIO;
1752 biodone(bp);
1753 }
1754 freedescr(desc);
1755 free(atio, M_DEVBUF);
1756 }
1757 break;
1758 }
1759 case XPT_IMMED_NOTIFY:

--- 42 unchanged lines hidden (view full) ---

1802{
1803 /*
1804 * return all pending buffers with short read/write status so our
1805 * process unblocks, and do a selwakeup on any process queued
1806 * waiting for reads or writes. When the selwakeup is performed,
1807 * the waking process will wakeup, call our poll routine again,
1808 * and pick up the exception.
1809 */
1752 biodone(bp);
1753 }
1754 freedescr(desc);
1755 free(atio, M_DEVBUF);
1756 }
1757 break;
1758 }
1759 case XPT_IMMED_NOTIFY:

--- 42 unchanged lines hidden (view full) ---

1802{
1803 /*
1804 * return all pending buffers with short read/write status so our
1805 * process unblocks, and do a selwakeup on any process queued
1806 * waiting for reads or writes. When the selwakeup is performed,
1807 * the waking process will wakeup, call our poll routine again,
1808 * and pick up the exception.
1809 */
1810 struct buf *bp;
1810 struct bio *bp;
1811
1812 if (softc->state != TARG_STATE_NORMAL)
1813 /* Already either tearing down or in exception state */
1814 return;
1815
1816 softc->state = TARG_STATE_EXCEPTION;
1817
1811
1812 if (softc->state != TARG_STATE_NORMAL)
1813 /* Already either tearing down or in exception state */
1814 return;
1815
1816 softc->state = TARG_STATE_EXCEPTION;
1817
1818 while ((bp = bufq_first(&softc->snd_buf_queue)) != NULL) {
1819 bufq_remove(&softc->snd_buf_queue, bp);
1820 bp->b_ioflags |= BIO_ERROR;
1818 while ((bp = bioq_first(&softc->snd_bio_queue)) != NULL) {
1819 bioq_remove(&softc->snd_bio_queue, bp);
1820 bp->bio_flags |= BIO_ERROR;
1821 biodone(bp);
1822 }
1823
1821 biodone(bp);
1822 }
1823
1824 while ((bp = bufq_first(&softc->rcv_buf_queue)) != NULL) {
1825 bufq_remove(&softc->snd_buf_queue, bp);
1826 bp->b_ioflags |= BIO_ERROR;
1824 while ((bp = bioq_first(&softc->rcv_bio_queue)) != NULL) {
1825 bioq_remove(&softc->snd_bio_queue, bp);
1826 bp->bio_flags |= BIO_ERROR;
1827 biodone(bp);
1828 }
1829
1830 selwakeup(&softc->snd_select);
1831 selwakeup(&softc->rcv_select);
1832}
1833
1834static void

--- 319 unchanged lines hidden (view full) ---

2154 continue;
2155
2156 TAILQ_REMOVE(atio_queue, &atio->ccb_h,
2157 periph_links.tqe);
2158
2159 CAM_DEBUG(periph->path, CAM_DEBUG_PERIPH,
2160 ("Aborting ATIO\n"));
2161 if (desc->bp != NULL) {
1827 biodone(bp);
1828 }
1829
1830 selwakeup(&softc->snd_select);
1831 selwakeup(&softc->rcv_select);
1832}
1833
1834static void

--- 319 unchanged lines hidden (view full) ---

2154 continue;
2155
2156 TAILQ_REMOVE(atio_queue, &atio->ccb_h,
2157 periph_links.tqe);
2158
2159 CAM_DEBUG(periph->path, CAM_DEBUG_PERIPH,
2160 ("Aborting ATIO\n"));
2161 if (desc->bp != NULL) {
2162 desc->bp->b_ioflags |= BIO_ERROR;
2162 desc->bp->bio_flags |= BIO_ERROR;
2163 if (softc->state != TARG_STATE_TEARDOWN)
2163 if (softc->state != TARG_STATE_TEARDOWN)
2164 desc->bp->b_error = errno;
2164 desc->bp->bio_error = errno;
2165 else
2165 else
2166 desc->bp->b_error = ENXIO;
2166 desc->bp->bio_error = ENXIO;
2167 biodone(desc->bp);
2168 desc->bp = NULL;
2169 }
2170 if (softc->state == TARG_STATE_TEARDOWN) {
2171 freedescr(desc);
2172 free(atio, M_DEVBUF);
2173 } else {
2174 /* Return the ATIO back to the controller */

--- 38 unchanged lines hidden ---
2167 biodone(desc->bp);
2168 desc->bp = NULL;
2169 }
2170 if (softc->state == TARG_STATE_TEARDOWN) {
2171 freedescr(desc);
2172 free(atio, M_DEVBUF);
2173 } else {
2174 /* Return the ATIO back to the controller */

--- 38 unchanged lines hidden ---