diff options
-rw-r--r-- | sys/cam/cam_periph.c | 7 | ||||
-rw-r--r-- | sys/cam/cam_queue.c | 57 | ||||
-rw-r--r-- | sys/cam/cam_queue.h | 6 | ||||
-rw-r--r-- | sys/cam/cam_xpt.c | 45 |
4 files changed, 67 insertions, 48 deletions
diff --git a/sys/cam/cam_periph.c b/sys/cam/cam_periph.c index 4ba2630..02c8785 100644 --- a/sys/cam/cam_periph.c +++ b/sys/cam/cam_periph.c @@ -26,7 +26,7 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * $Id: cam_periph.c,v 1.10 1999/01/21 08:29:02 dillon Exp $ + * $Id: cam_periph.c,v 1.11 1999/04/06 03:05:36 peter Exp $ */ #include <sys/param.h> @@ -1047,6 +1047,7 @@ cam_periph_error(union ccb *ccb, cam_flags camflags, ccb->ccb_h.retry_count--; error = 0; break; + case CAM_AUTOSENSE_FAIL: case CAM_SCSI_STATUS_ERROR: switch (ccb->csio.scsi_status) { @@ -1354,7 +1355,8 @@ cam_periph_error(union ccb *ccb, cam_flags camflags, err_action); } } else if (ccb->csio.scsi_status == - SCSI_STATUS_CHECK_COND) { + SCSI_STATUS_CHECK_COND + && status != CAM_AUTOSENSE_FAIL) { /* no point in decrementing the retry count */ panic("cam_periph_error: scsi status of " "CHECK COND returned but no sense " @@ -1459,7 +1461,6 @@ cam_periph_error(union ccb *ccb, cam_flags camflags, } break; case CAM_REQ_CMP_ERR: - case CAM_AUTOSENSE_FAIL: case CAM_CMD_TIMEOUT: case CAM_UNEXP_BUSFREE: case CAM_UNCOR_PARITY: diff --git a/sys/cam/cam_queue.c b/sys/cam/cam_queue.c index edebfd5..1262b6e 100644 --- a/sys/cam/cam_queue.c +++ b/sys/cam/cam_queue.c @@ -25,7 +25,7 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * $Id: cam_queue.c,v 1.1 1998/09/15 06:33:23 gibbs Exp $ + * $Id: cam_queue.c,v 1.2 1999/04/07 22:57:48 gibbs Exp $ */ #include <sys/param.h> #include <sys/systm.h> @@ -72,6 +72,11 @@ camq_init(struct camq *camq, int size) printf("camq_init: - cannot malloc array!\n"); return (1); } + /* + * Heap algorithms like everything numbered from 1, so + * offset our pointer into the heap array by one element. + */ + camq->queue_array--; } return (0); } @@ -95,6 +100,11 @@ void camq_fini(struct camq *queue) { if (queue->queue_array != NULL) { + /* + * Heap algorithms like everything numbered from 1, so + * our pointer into the heap array is offset by one element. + */ + queue->queue_array++; free(queue->queue_array, M_DEVBUF); } } @@ -115,20 +125,26 @@ camq_resize(struct camq *queue, int new_size) /* Couldn't satisfy request */ return (CAM_RESRC_UNAVAIL); } + /* + * Heap algorithms like everything numbered from 1, so + * remember that our pointer into the heap array is offset + * by one element. + */ if (queue->queue_array != NULL) { + queue->queue_array++; bcopy(queue->queue_array, new_array, queue->entries * sizeof(cam_pinfo *)); free(queue->queue_array, M_DEVBUF); } - queue->queue_array = new_array; + queue->queue_array = new_array-1; queue->array_size = new_size; return (CAM_REQ_CMP); } /* * camq_insert: Given an array of cam_pinfo* elememnts with - * the Heap(0, num_elements) property and array_size - num_elements >= 1, - * output Heap(0, num_elements+1) including new_entry in the array. + * the Heap(1, num_elements) property and array_size - num_elements >= 1, + * output Heap(1, num_elements+1) including new_entry in the array. */ void camq_insert(struct camq *queue, cam_pinfo *new_entry) @@ -137,17 +153,17 @@ camq_insert(struct camq *queue, cam_pinfo *new_entry) if (queue->entries >= queue->array_size) panic("camq_insert: Attempt to insert into a full queue"); #endif + queue->entries++; queue->queue_array[queue->entries] = new_entry; new_entry->index = queue->entries; if (queue->entries != 0) heap_up(queue->queue_array, queue->entries); - queue->entries++; } /* * camq_remove: Given an array of cam_pinfo* elevements with the - * Heap(0, num_elements) property and an index such that 0 <= index <= - * num_elements, remove that entry and restore the Heap(0, num_elements-1) + * Heap(1, num_elements) property and an index such that 1 <= index <= + * num_elements, remove that entry and restore the Heap(1, num_elements-1) * property. */ cam_pinfo * @@ -155,22 +171,22 @@ camq_remove(struct camq *queue, int index) { cam_pinfo *removed_entry; - if ((queue->entries - index) <= 0) + if (index == 0 || index > queue->entries) return (NULL); removed_entry = queue->queue_array[index]; - queue->entries--; if (queue->entries != index) { queue->queue_array[index] = queue->queue_array[queue->entries]; queue->queue_array[index]->index = index; - heap_down(queue->queue_array, index, queue->entries); + heap_down(queue->queue_array, index, queue->entries - 1); } removed_entry->index = CAM_UNQUEUED_INDEX; + queue->entries--; return (removed_entry); } /* * camq_change_priority: Given an array of cam_pinfo* elements with the - * Heap(0, num_entries) property, an index such that 0 <= index <= num_elements, + * Heap(1, num_entries) property, an index such that 1 <= index <= num_elements, * and an new priority for the element at index, change the priority of * element index and restore the Heap(0, num_elements) property. */ @@ -352,8 +368,8 @@ swap(cam_pinfo **queue_array, int i, int j) /* * heap_up: Given an array of cam_pinfo* elements with the - * Heap(0, new_index-1) property and a new element in location - * new_index, output Heap(0, new_index). + * Heap(1, new_index-1) property and a new element in location + * new_index, output Heap(1, new_index). */ static void heap_up(cam_pinfo **queue_array, int new_index) @@ -363,9 +379,9 @@ heap_up(cam_pinfo **queue_array, int new_index) child = new_index; - while (child != 0) { + while (child != 1) { - parent = (child - 1) >> 1; + parent = child >> 1; if (queue_cmp(queue_array, parent, child) <= 0) break; swap(queue_array, parent, child); @@ -375,8 +391,8 @@ heap_up(cam_pinfo **queue_array, int new_index) /* * heap_down: Given an array of cam_pinfo* elements with the - * Heap(index + 1, num_entries - 1) property with index containing - * an unsorted entry, output Heap(0, num_entries - 1). + * Heap(index + 1, num_entries) property with index containing + * an unsorted entry, output Heap(index, num_entries). */ static void heap_down(cam_pinfo **queue_array, int index, int num_entries) @@ -385,10 +401,10 @@ heap_down(cam_pinfo **queue_array, int index, int num_entries) int parent; parent = index; - child = (parent << 1) + 1; - for (; child < num_entries; child = (parent << 1) + 1) { + child = parent << 1; + for (; child <= num_entries; child = parent << 1) { - if (child + 1 < num_entries) { + if (child < num_entries) { /* child+1 is the right child of parent */ if (queue_cmp(queue_array, child + 1, child) < 0) child++; @@ -400,4 +416,3 @@ heap_down(cam_pinfo **queue_array, int index, int num_entries) parent = child; } } - diff --git a/sys/cam/cam_queue.h b/sys/cam/cam_queue.h index c9135b7..3668525 100644 --- a/sys/cam/cam_queue.h +++ b/sys/cam/cam_queue.h @@ -25,7 +25,7 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * $Id: cam_queue.h,v 1.2 1998/12/15 08:12:03 gibbs Exp $ + * $Id: cam_queue.h,v 1.3 1999/04/07 22:57:48 gibbs Exp $ */ #ifndef _CAM_CAM_QUEUE_H @@ -136,6 +136,10 @@ void camq_insert(struct camq *queue, cam_pinfo *new_entry); * queue order. */ cam_pinfo *camq_remove(struct camq *queue, int index); +#define CAMQ_HEAD 1 /* Head of queue index */ + +/* Index the first element in the heap */ +#define CAMQ_GET_HEAD(camq) ((camq)->queue_array[CAMQ_HEAD]) /* * camq_change_priority: Raise or lower the priority of an entry diff --git a/sys/cam/cam_xpt.c b/sys/cam/cam_xpt.c index 3f1f97e..52428e0 100644 --- a/sys/cam/cam_xpt.c +++ b/sys/cam/cam_xpt.c @@ -26,7 +26,7 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * $Id: cam_xpt.c,v 1.50 1999/04/07 22:57:48 gibbs Exp $ + * $Id: cam_xpt.c,v 1.51 1999/04/17 08:36:03 peter Exp $ */ #include <sys/param.h> #include <sys/systm.h> @@ -755,9 +755,14 @@ xpt_schedule_dev_allocq(struct cam_eb *bus, struct cam_ed *dev) + dev->ccbq.dev_active); dev->flags &= ~CAM_DEV_RESIZE_QUEUE_NEEDED; } + /* + * The priority of a device waiting for CCB resources + * is that of the the highest priority peripheral driver + * enqueued. + */ retval = xpt_schedule_dev(&bus->sim->devq->alloc_queue, &dev->alloc_ccb_entry.pinfo, - dev->drvq.queue_array[0]->priority); + CAMQ_GET_HEAD(&dev->drvq)->priority); } else { retval = 0; } @@ -771,9 +776,15 @@ xpt_schedule_dev_sendq(struct cam_eb *bus, struct cam_ed *dev) int retval; if (dev->ccbq.dev_openings > 0) { - retval = xpt_schedule_dev(&bus->sim->devq->send_queue, - &dev->send_ccb_entry.pinfo, - dev->ccbq.queue.queue_array[0]->priority); + /* + * The priority of a device waiting for controller + * resources is that of the the highest priority CCB + * enqueued. + */ + retval = + xpt_schedule_dev(&bus->sim->devq->send_queue, + &dev->send_ccb_entry.pinfo, + CAMQ_GET_HEAD(&dev->ccbq.queue)->priority); } else { retval = 0; } @@ -2334,7 +2345,7 @@ xptperiphlistmatch(struct ccb_dev_match *cdm) if ((cdm->pos.position_type & CAM_DEV_POS_PDPTR) && (cdm->pos.cookie.pdrv != NULL)) ret = xptpdrvtraverse( - (struct periph_driver **)cdm->pos.cookie.pdrv, + (struct periph_driver **)cdm->pos.cookie.pdrv, xptplistpdrvfunc, cdm); else ret = xptpdrvtraverse(NULL, xptplistpdrvfunc, cdm); @@ -3382,7 +3393,7 @@ xpt_run_dev_allocq(struct cam_eb *bus) struct camq *drvq; qinfo = (struct cam_ed_qinfo *)camq_remove(&devq->alloc_queue, - /*position*/0); + CAMQ_HEAD); device = qinfo->device; CAM_DEBUG_PRINT(CAM_DEBUG_XPT, @@ -3399,14 +3410,7 @@ xpt_run_dev_allocq(struct cam_eb *bus) if ((work_ccb = xpt_get_ccb(device)) != NULL) { devq->alloc_openings--; devq->alloc_active++; - drv = (struct cam_periph*)camq_remove(drvq, - /*pos*/0); - /* Update priority */ - if (drvq->entries > 0) { - qinfo->pinfo.priority = drvq->queue_array[0]->priority; - } else { - qinfo->pinfo.priority = CAM_PRIORITY_NONE; - } + drv = (struct cam_periph*)camq_remove(drvq, CAMQ_HEAD); splx(s); xpt_setup_ccb(&work_ccb->ccb_h, drv->path, drv->pinfo.priority); @@ -3467,7 +3471,7 @@ xpt_run_dev_sendq(struct cam_eb *bus) } qinfo = (struct cam_ed_qinfo *)camq_remove(&devq->send_queue, - /*position*/0); + CAMQ_HEAD); device = qinfo->device; /* @@ -3482,7 +3486,7 @@ xpt_run_dev_sendq(struct cam_eb *bus) CAM_DEBUG_PRINT(CAM_DEBUG_XPT, ("running device %p\n", device)); - work_ccb = cam_ccbq_peek_ccb(&device->ccbq, 0); + work_ccb = cam_ccbq_peek_ccb(&device->ccbq, CAMQ_HEAD); if (work_ccb == NULL) { printf("device on run queue with no ccbs???"); splx(ospl); @@ -3522,13 +3526,8 @@ xpt_run_dev_sendq(struct cam_eb *bus) devq->send_openings--; devq->send_active++; - if (device->ccbq.queue.entries > 0) { - qinfo->pinfo.priority = - device->ccbq.queue.queue_array[0]->priority; + if (device->ccbq.queue.entries > 0) xpt_schedule_dev_sendq(bus, device); - } else { - qinfo->pinfo.priority = CAM_PRIORITY_NONE; - } if (work_ccb && (work_ccb->ccb_h.flags & CAM_DEV_QFREEZE) != 0){ /* |