Change the kernel dev_t, representing a pointer to a specinfo structure,
[dragonfly.git] / sys / bus / cam / scsi / scsi_pass.c
index 1e73fc2..4084f39 100644 (file)
@@ -25,7 +25,7 @@
  * SUCH DAMAGE.
  *
  * $FreeBSD: src/sys/cam/scsi/scsi_pass.c,v 1.19 2000/01/17 06:27:37 mjacob Exp $
- * $DragonFly: src/sys/bus/cam/scsi/scsi_pass.c,v 1.13 2005/06/02 20:40:31 dillon Exp $
+ * $DragonFly: src/sys/bus/cam/scsi/scsi_pass.c,v 1.18 2006/09/10 01:26:32 dillon Exp $
  */
 
 #include <sys/param.h>
@@ -73,13 +73,13 @@ typedef enum {
 } pass_ccb_types;
 
 #define ccb_type       ppriv_field0
-#define ccb_bp         ppriv_ptr1
+#define ccb_bio                ppriv_ptr1
 
 struct pass_softc {
        pass_state      state;
        pass_flags      flags;
        u_int8_t        pd_type;
-       struct          buf_queue_head buf_queue;
+       struct          bio_queue_head bio_queue;
        union ccb       saved_ccb;
        struct devstat  device_stats;
 };
@@ -113,23 +113,14 @@ static struct periph_driver passdriver =
 
 DATA_SET(periphdriver_set, passdriver);
 
-static struct cdevsw pass_cdevsw = {
-       /* name */      "pass",
-       /* maj */       PASS_CDEV_MAJOR,
-       /* flags */     0,
-       /* port */      NULL,
-       /* clone */     NULL,
-
-       /* open */      passopen,
-       /* close */     passclose,
-       /* read */      physread,
-       /* write */     physwrite,
-       /* ioctl */     passioctl,
-       /* poll */      nopoll,
-       /* mmap */      nommap,
-       /* strategy */  passstrategy,
-       /* dump */      nodump,
-       /* psize */     nopsize
+static struct dev_ops pass_ops = {
+       { "pass", PASS_CDEV_MAJOR, 0 },
+       .d_open =       passopen,
+       .d_close =      passclose,
+       .d_read =       physread,
+       .d_write =      physwrite,
+       .d_ioctl =      passioctl,
+       .d_strategy =   passstrategy,
 };
 
 static struct extend_array *passperiphs;
@@ -181,6 +172,7 @@ passoninvalidate(struct cam_periph *periph)
 {
        struct pass_softc *softc;
        struct buf *q_bp;
+       struct bio *q_bio;
        struct ccb_setasync csa;
 
        softc = (struct pass_softc *)periph->softc;
@@ -209,12 +201,13 @@ passoninvalidate(struct cam_periph *periph)
         * XXX Handle any transactions queued to the card
         *     with XPT_ABORT_CCB.
         */
-       while ((q_bp = bufq_first(&softc->buf_queue)) != NULL){
-               bufq_remove(&softc->buf_queue, q_bp);
+       while ((q_bio = bioq_first(&softc->bio_queue)) != NULL){
+               bioq_remove(&softc->bio_queue, q_bio);
+               q_bp = q_bio->bio_buf;
                q_bp->b_resid = q_bp->b_bcount;
                q_bp->b_error = ENXIO;
                q_bp->b_flags |= B_ERROR;
-               biodone(q_bp);
+               biodone(q_bio);
        }
        crit_exit();
 
@@ -240,8 +233,8 @@ passcleanup(struct cam_periph *periph)
                xpt_print_path(periph->path);
                printf("removing device entry\n");
        }
-       cdevsw_remove(&pass_cdevsw, -1, periph->unit_number);
-       free(softc, M_DEVBUF);
+       dev_ops_remove(&pass_ops, -1, periph->unit_number);
+       kfree(softc, M_DEVBUF);
 }
 
 static void
@@ -301,10 +294,10 @@ passregister(struct cam_periph *periph, void *arg)
                return(CAM_REQ_CMP_ERR);
        }
 
-       softc = malloc(sizeof(*softc), M_DEVBUF, M_INTWAIT | M_ZERO);
+       softc = kmalloc(sizeof(*softc), M_DEVBUF, M_INTWAIT | M_ZERO);
        softc->state = PASS_STATE_NORMAL;
        softc->pd_type = SID_TYPE(&cgd->inq_data);
-       bufq_init(&softc->buf_queue);
+       bioq_init(&softc->bio_queue);
 
        periph->softc = softc;
 
@@ -322,8 +315,8 @@ passregister(struct cam_periph *periph, void *arg)
                          DEVSTAT_PRIORITY_PASS);
 
        /* Register the device */
-       cdevsw_add(&pass_cdevsw, -1, periph->unit_number);
-       make_dev(&pass_cdevsw, periph->unit_number, UID_ROOT,
+       dev_ops_add(&pass_ops, -1, periph->unit_number);
+       make_dev(&pass_ops, periph->unit_number, UID_ROOT,
                  GID_OPERATOR, 0600, "%s%d", periph->periph_name,
                  periph->unit_number);
 
@@ -345,8 +338,9 @@ passregister(struct cam_periph *periph, void *arg)
 }
 
 static int
-passopen(dev_t dev, int flags, int fmt, struct thread *td)
+passopen(struct dev_open_args *ap)
 {
+       cdev_t dev = ap->a_head.a_dev;
        struct cam_periph *periph;
        struct pass_softc *softc;
        int unit, error;
@@ -381,7 +375,7 @@ passopen(dev_t dev, int flags, int fmt, struct thread *td)
        /*
         * Only allow read-write access.
         */
-       if (((flags & FWRITE) == 0) || ((flags & FREAD) == 0)) {
+       if (((ap->a_oflags & FWRITE) == 0) || ((ap->a_oflags & FREAD) == 0)) {
                crit_exit();
                return(EPERM);
        }
@@ -389,7 +383,7 @@ passopen(dev_t dev, int flags, int fmt, struct thread *td)
        /*
         * We don't allow nonblocking access.
         */
-       if ((flags & O_NONBLOCK) != 0) {
+       if ((ap->a_oflags & O_NONBLOCK) != 0) {
                xpt_print_path(periph->path);
                printf("can't do nonblocking accesss\n");
                crit_exit();
@@ -415,8 +409,9 @@ passopen(dev_t dev, int flags, int fmt, struct thread *td)
 }
 
 static int
-passclose(dev_t dev, int flag, int fmt, struct thread *td)
+passclose(struct dev_close_args *ap)
 {
+       cdev_t dev = ap->a_head.a_dev;
        struct  cam_periph *periph;
        struct  pass_softc *softc;
        int     unit, error;
@@ -447,9 +442,12 @@ passclose(dev_t dev, int flag, int fmt, struct thread *td)
  * can understand.  The transfer is described by a buf and will include
  * only one physical transfer.
  */
-static void
-passstrategy(struct buf *bp)
+static int
+passstrategy(struct dev_strategy_args *ap)
 {
+       cdev_t dev = ap->a_head.a_dev;
+       struct bio *bio = ap->a_bio;
+       struct buf *bp = bio->bio_buf;
        struct cam_periph *periph;
        struct pass_softc *softc;
        u_int  unit;
@@ -462,9 +460,9 @@ passstrategy(struct buf *bp)
        bp->b_error = EINVAL;
        goto bad;
 
-       /* unit = dkunit(bp->b_dev); */
+       /* unit = dkunit(dev); */
        /* XXX KDM fix this */
-       unit = minor(bp->b_dev) & 0xff;
+       unit = minor(dev) & 0xff;
 
        periph = cam_extend_get(passperiphs, unit);
        if (periph == NULL) {
@@ -477,7 +475,7 @@ passstrategy(struct buf *bp)
         * Odd number of bytes or negative offset
         */
        /* valid request?  */
-       if (bp->b_blkno < 0) {
+       if (bio->bio_offset < 0) {
                bp->b_error = EINVAL;
                goto bad;
         }
@@ -488,7 +486,7 @@ passstrategy(struct buf *bp)
         * clean up one of the buffers.
         */
        crit_enter();
-       bufq_insert_tail(&softc->buf_queue, bp);
+       bioq_insert_tail(&softc->bio_queue, bio);
        crit_exit();
        
        /*
@@ -496,7 +494,7 @@ passstrategy(struct buf *bp)
         */
        xpt_schedule(periph, /* XXX priority */1);
 
-       return;
+       return(0);
 bad:
        bp->b_flags |= B_ERROR;
 
@@ -504,8 +502,8 @@ bad:
         * Correctly set the buf to indicate a completed xfer
         */
        bp->b_resid = bp->b_bcount;
-       biodone(bp);
-       return;
+       biodone(bio);
+       return(0);
 }
 
 static void
@@ -519,9 +517,10 @@ passstart(struct cam_periph *periph, union ccb *start_ccb)
        case PASS_STATE_NORMAL:
        {
                struct buf *bp;
+               struct bio *bio;
 
                crit_enter();
-               bp = bufq_first(&softc->buf_queue);
+               bio = bioq_first(&softc->bio_queue);
                if (periph->immediate_priority <= periph->pinfo.priority) {
                        start_ccb->ccb_h.ccb_type = PASS_CCB_WAITING;                   
                        SLIST_INSERT_HEAD(&periph->ccb_list, &start_ccb->ccb_h,
@@ -529,12 +528,13 @@ passstart(struct cam_periph *periph, union ccb *start_ccb)
                        periph->immediate_priority = CAM_PRIORITY_NONE;
                        crit_exit();
                        wakeup(&periph->ccb_list);
-               } else if (bp == NULL) {
+               } else if (bio == NULL) {
                        crit_exit();
                        xpt_release_ccb(start_ccb);
                } else {
 
-                       bufq_remove(&softc->buf_queue, bp);
+                       bioq_remove(&softc->bio_queue, bio);
+                       bp = bio->bio_buf;
 
                        devstat_start_transaction(&softc->device_stats);
 
@@ -549,14 +549,14 @@ passstart(struct cam_periph *periph, union ccb *start_ccb)
                        bp->b_error = EIO;
                        bp->b_flags |= B_ERROR;
                        bp->b_resid = bp->b_bcount;
-                       biodone(bp);
-                       bp = bufq_first(&softc->buf_queue);
+                       biodone(bio);
+                       bio = bioq_first(&softc->bio_queue);
                        crit_exit();
   
                        xpt_action(start_ccb);
 
                }
-               if (bp != NULL) {
+               if (bio != NULL) {
                        /* Have more work to do, so ensure we stay scheduled */
                        xpt_schedule(periph, /* XXX priority */1);
                }
@@ -575,6 +575,7 @@ passdone(struct cam_periph *periph, union ccb *done_ccb)
        switch (csio->ccb_h.ccb_type) {
        case PASS_CCB_BUFFER_IO:
        {
+               struct bio              *bio;
                struct buf              *bp;
                cam_status              status;
                u_int8_t                scsi_status;
@@ -582,7 +583,9 @@ passdone(struct cam_periph *periph, union ccb *done_ccb)
 
                status = done_ccb->ccb_h.status;
                scsi_status = done_ccb->csio.scsi_status;
-               bp = (struct buf *)done_ccb->ccb_h.ccb_bp;
+               bio = (struct bio *)done_ccb->ccb_h.ccb_bio;
+               bp = bio->bio_buf;
+
                /* XXX handle errors */
                if (!(((status & CAM_STATUS_MASK) == CAM_REQ_CMP)
                  && (scsi_status == SCSI_STATUS_OK))) {
@@ -612,7 +615,7 @@ passdone(struct cam_periph *periph, union ccb *done_ccb)
                        ds_flags = DEVSTAT_NO_DATA;
 
                devstat_end_transaction_buf(&softc->device_stats, bp);
-               biodone(bp);
+               biodone(bio);
                break;
        }
        case PASS_CCB_WAITING:
@@ -626,8 +629,10 @@ passdone(struct cam_periph *periph, union ccb *done_ccb)
 }
 
 static int
-passioctl(dev_t dev, u_long cmd, caddr_t addr, int flag, struct thread *td)
+passioctl(struct dev_ioctl_args *ap)
 {
+       cdev_t dev = ap->a_head.a_dev;
+       caddr_t addr = ap->a_data;
        struct  cam_periph *periph;
        struct  pass_softc *softc;
        u_int8_t unit;
@@ -647,7 +652,7 @@ passioctl(dev_t dev, u_long cmd, caddr_t addr, int flag, struct thread *td)
 
        error = 0;
 
-       switch (cmd) {
+       switch (ap->a_cmd) {
 
        case CAMIOCOMMAND:
        {
@@ -706,7 +711,7 @@ passioctl(dev_t dev, u_long cmd, caddr_t addr, int flag, struct thread *td)
                break;
        }
        default:
-               error = cam_periph_ioctl(periph, cmd, addr, passerror);
+               error = cam_periph_ioctl(periph, ap->a_cmd, addr, passerror);
                break;
        }