MPSAFE locking for the ahc/ahd drivers using lockmgr locks.
[dragonfly.git] / sys / dev / disk / aic7xxx / aic7xxx_osm.c
index 8181836..c6c1069 100644 (file)
@@ -31,7 +31,7 @@
  * $Id: //depot/aic7xxx/freebsd/dev/aic7xxx/aic7xxx_osm.c#20 $
  *
  * $FreeBSD: src/sys/dev/aic7xxx/aic7xxx_osm.c,v 1.45 2006/09/05 20:28:28 mjacob Exp $
- * $DragonFly: src/sys/dev/disk/aic7xxx/aic7xxx_osm.c,v 1.20 2007/07/11 23:46:58 dillon Exp $
+ * $DragonFly: src/sys/dev/disk/aic7xxx/aic7xxx_osm.c,v 1.21 2008/02/09 18:13:13 pavalos Exp $
  */
 
 #include "aic7xxx_osm.h"
@@ -107,7 +107,7 @@ ahc_map_int(struct ahc_softc *ahc)
 
        /* Hook up our interrupt handler */
        error = bus_setup_intr(ahc->dev_softc, ahc->platform_data->irq,
-                              0, ahc_platform_intr, ahc,
+                              INTR_MPSAFE, ahc_platform_intr, ahc,
                               &ahc->platform_data->ih, NULL);
 
        if (error != 0)
@@ -167,7 +167,7 @@ ahc_attach(struct ahc_softc *ahc)
 
        ahc_controller_info(ahc, ahc_info);
        kprintf("%s\n", ahc_info);
-       ahc_lock();
+       ahc_lock(ahc);
 
        /*
         * Attach secondary channel first if the user has
@@ -267,6 +267,7 @@ fail:
                ahc->platform_data->sim_b = sim2;
                ahc->platform_data->path_b = path2;
        }
+       ahc_unlock(ahc);
 
        if (count != 0) {
                /* We have to wait until after any system dumps... */
@@ -276,7 +277,6 @@ fail:
                ahc_intr_enable(ahc, TRUE);
        }
 
-       ahc_unlock();
        return (count);
 }
 
@@ -289,7 +289,9 @@ ahc_platform_intr(void *arg)
        struct  ahc_softc *ahc;
 
        ahc = (struct ahc_softc *)arg; 
+       ahc_lock(ahc);
        ahc_intr(ahc);
+       ahc_unlock(ahc);
 }
 
 /*
@@ -320,7 +322,7 @@ ahc_done(struct ahc_softc *ahc, struct scb *scb)
                ahc_run_untagged_queue(ahc, untagged_q);
        }
 
-       callout_stop(&ccb->ccb_h.timeout_ch);
+       callout_stop(&scb->io_timer);
 
        if ((ccb->ccb_h.flags & CAM_DIR_MASK) != CAM_DIR_NONE) {
                bus_dmasync_op_t op;
@@ -384,8 +386,8 @@ ahc_done(struct ahc_softc *ahc, struct scb *scb)
                         * so reinstate the timeouts for all other pending
                         * commands.
                         */
-                        LIST_FOREACH(list_scb, &ahc->pending_scbs,
-                                     pending_links) {
+                       LIST_FOREACH(list_scb, &ahc->pending_scbs,
+                                    pending_links) {
 
                                aic_scb_timer_reset(list_scb,
                                                    aic_get_timeout(scb));
@@ -462,13 +464,11 @@ ahc_action(struct cam_sim *sim, union ccb *ccb)
                }
                if (ccb->ccb_h.func_code == XPT_ACCEPT_TARGET_IO) {
 
-                       ahc_lock();
                        SLIST_INSERT_HEAD(&lstate->accept_tios, &ccb->ccb_h,
                                          sim_links.sle);
                        ccb->ccb_h.status = CAM_REQ_INPROG;
                        if ((ahc->flags & AHC_TQINFIFO_BLOCKED) != 0)
                                ahc_run_tqinfifo(ahc, /*paused*/FALSE);
-                       ahc_unlock();
                        break;
                }
 
@@ -498,17 +498,14 @@ ahc_action(struct cam_sim *sim, union ccb *ccb)
                /*
                 * get an scb to use.
                 */
-               ahc_lock();
                if ((scb = ahc_get_scb(ahc)) == NULL) {
        
                        xpt_freeze_simq(sim, /*count*/1);
                        ahc->flags |= AHC_RESOURCE_SHORTAGE;
-                       ahc_unlock();
                        ccb->ccb_h.status = CAM_REQUEUE_REQ;
                        xpt_done(ccb);
                        return;
                }
-               ahc_unlock();
                
                hscb = scb->hscb;
                
@@ -639,8 +636,6 @@ ahc_action(struct cam_sim *sim, union ccb *ccb)
                        break;
                }
                
-               ahc_lock();
-
                if ((spi->valid & CTS_SPI_VALID_DISC) != 0) {
                        if ((spi->flags & CTS_SPI_FLAGS_DISC_ENB) != 0)
                                *discenable |= devinfo.target_mask;
@@ -716,7 +711,6 @@ ahc_action(struct cam_sim *sim, union ccb *ccb)
                                         spi->ppr_options, update_type,
                                         /*paused*/FALSE);
                }
-               ahc_unlock();
                ccb->ccb_h.status = CAM_REQ_CMP;
                xpt_done(ccb);
 #else
@@ -752,8 +746,6 @@ ahc_action(struct cam_sim *sim, union ccb *ccb)
                        break;
                }
                
-               ahc_lock();
-
                if ((cts->valid & CCB_TRANS_DISC_VALID) != 0) {
                        if ((cts->flags & CCB_TRANS_DISC_ENB) != 0)
                                *discenable |= devinfo.target_mask;
@@ -834,7 +826,6 @@ ahc_action(struct cam_sim *sim, union ccb *ccb)
                                         ppr_options, update_type,
                                         /*paused*/FALSE);
                }
-               ahc_unlock();
                ccb->ccb_h.status = CAM_REQ_CMP;
                xpt_done(ccb);
 #endif
@@ -844,10 +835,8 @@ ahc_action(struct cam_sim *sim, union ccb *ccb)
        /* Get default/user set transfer settings for the target */
        {
 
-               ahc_lock();
                ahc_get_tran_settings(ahc, SIM_SCSI_ID(ahc, sim),
                                      SIM_CHANNEL(ahc, sim), &ccb->cts);
-               ahc_unlock();
                xpt_done(ccb);
                break;
        }
@@ -866,10 +855,8 @@ ahc_action(struct cam_sim *sim, union ccb *ccb)
        {
                int  found;
                
-               ahc_lock();
                found = ahc_reset_channel(ahc, SIM_CHANNEL(ahc, sim),
                                          /*initiate reset*/TRUE);
-               ahc_unlock();
                if (bootverbose) {
                        xpt_print_path(SIM_PATH(ahc, sim));
                        kprintf("SCSI bus reset delivered. "
@@ -1077,14 +1064,12 @@ ahc_async(void *callback_arg, uint32_t code, struct cam_path *path, void *arg)
                 * Revert to async/narrow transfers
                 * for the next device.
                 */
-               ahc_lock();
                ahc_set_width(ahc, &devinfo, MSG_EXT_WDTR_BUS_8_BIT,
                              AHC_TRANS_GOAL|AHC_TRANS_CUR, /*paused*/FALSE);
                ahc_set_syncrate(ahc, &devinfo, /*syncrate*/NULL,
                                 /*period*/0, /*offset*/0, /*ppr_options*/0,
                                 AHC_TRANS_GOAL|AHC_TRANS_CUR,
                                 /*paused*/FALSE);
-               ahc_unlock();
                break;
        }
        default:
@@ -1114,9 +1099,7 @@ ahc_execute_scb(void *arg, bus_dma_segment_t *dm_segs, int nsegments,
                        aic_set_transaction_status(scb, CAM_REQ_CMP_ERR);
                if (nsegments != 0)
                        bus_dmamap_unload(ahc->buffer_dmat, scb->dmamap);
-               ahc_lock();
                ahc_free_scb(ahc, scb);
-               ahc_unlock();
                xpt_done(ccb);
                return;
        }
@@ -1189,9 +1172,7 @@ ahc_execute_scb(void *arg, bus_dma_segment_t *dm_segs, int nsegments,
                                            CAM_REQ_TOO_BIG);
                                        bus_dmamap_unload(ahc->buffer_dmat,
                                                          scb->dmamap);
-                                       ahc_lock();
                                        ahc_free_scb(ahc, scb);
-                                       ahc_unlock();
                                        xpt_done(ccb);
                                        return;
                                }
@@ -1214,8 +1195,6 @@ ahc_execute_scb(void *arg, bus_dma_segment_t *dm_segs, int nsegments,
        
        scb->sg_count = nsegments;
 
-       ahc_lock();
-
        /*
         * Last time we need to check if this SCB needs to
         * be aborted.
@@ -1224,7 +1203,6 @@ ahc_execute_scb(void *arg, bus_dma_segment_t *dm_segs, int nsegments,
                if (nsegments != 0)
                        bus_dmamap_unload(ahc->buffer_dmat, scb->dmamap);
                ahc_free_scb(ahc, scb);
-               ahc_unlock();
                xpt_done(ccb);
                return;
        }
@@ -1275,7 +1253,6 @@ ahc_execute_scb(void *arg, bus_dma_segment_t *dm_segs, int nsegments,
                TAILQ_INSERT_TAIL(untagged_q, scb, links.tqe);
                scb->flags |= SCB_UNTAGGEDQ;
                if (TAILQ_FIRST(untagged_q) != scb) {
-                       ahc_unlock();
                        return;
                }
        }
@@ -1297,8 +1274,6 @@ ahc_execute_scb(void *arg, bus_dma_segment_t *dm_segs, int nsegments,
        } else {
                ahc_queue_scb(ahc, scb);
        }
-
-       ahc_unlock();
 }
 
 static void
@@ -1330,9 +1305,7 @@ ahc_setup_data(struct ahc_softc *ahc, struct cam_sim *sim,
                         || (ccb_h->flags & CAM_CDB_PHYS) != 0) {
                                aic_set_transaction_status(scb,
                                                           CAM_REQ_INVALID);
-                               ahc_lock();
                                ahc_free_scb(ahc, scb);
-                               ahc_unlock();
                                xpt_done((union ccb *)csio);
                                return;
                        }
@@ -1628,16 +1601,11 @@ ahc_detach(device_t dev)
 
        device_printf(dev, "detaching device\n");
        ahc = device_get_softc(dev);
-       ahc = ahc_find_softc(ahc);
-       if (ahc == NULL) {
-               device_printf(dev, "aic7xxx already detached\n");
-               return (ENOENT);
-       }
+       ahc_lock(ahc);
        TAILQ_REMOVE(&ahc_tailq, ahc, links);
-       ahc_lock();
        ahc_intr_enable(ahc, FALSE);
        bus_teardown_intr(dev, ahc->platform_data->irq, ahc->platform_data->ih);
-       ahc_unlock();
+       ahc_unlock(ahc);
        ahc_free(ahc);
        return (0);
 }
@@ -1674,6 +1642,7 @@ static int
 ahc_modevent(module_t mod, int type, void *data)
 {
        /* XXX Deal with busy status on unload. */
+       /* XXX Deal with unknown events */
        return 0;
 }