diff options
Diffstat (limited to 'sys/dev')
-rw-r--r-- | sys/dev/hptrr/hptrr_os_bsd.c | 6 | ||||
-rw-r--r-- | sys/dev/hptrr/hptrr_osm_bsd.c | 165 | ||||
-rw-r--r-- | sys/dev/hptrr/os_bsd.h | 64 |
3 files changed, 59 insertions, 176 deletions
diff --git a/sys/dev/hptrr/hptrr_os_bsd.c b/sys/dev/hptrr/hptrr_os_bsd.c index 5cb81da..cc65d49 100644 --- a/sys/dev/hptrr/hptrr_os_bsd.c +++ b/sys/dev/hptrr/hptrr_os_bsd.c @@ -220,9 +220,9 @@ void os_request_timer(void * osext, HPT_U32 interval) PVBUS_EXT vbus_ext = osext; HPT_ASSERT(vbus_ext->ext_type==EXT_TYPE_VBUS); - - untimeout(os_timer_for_ldm, vbus_ext, vbus_ext->timer); - vbus_ext->timer = timeout(os_timer_for_ldm, vbus_ext, interval * hz / 1000000); + + callout_reset(&vbus_ext->timer, interval * hz / 1000000, + os_timer_for_ldm, vbus_ext); } HPT_TIME os_query_time(void) diff --git a/sys/dev/hptrr/hptrr_osm_bsd.c b/sys/dev/hptrr/hptrr_osm_bsd.c index 25785c9..ad7d79e 100644 --- a/sys/dev/hptrr/hptrr_osm_bsd.c +++ b/sys/dev/hptrr/hptrr_osm_bsd.c @@ -39,32 +39,38 @@ __FBSDID("$FreeBSD$"); static int attach_generic = 0; TUNABLE_INT("hw.hptrr.attach_generic", &attach_generic); -static int hpt_probe(device_t dev) +static HIM *hpt_match(device_t dev) { PCI_ID pci_id; - HIM *him; int i; - PHBA hba; + HIM *him; /* Some of supported chips are used not only by HPT. */ if (pci_get_vendor(dev) != 0x1103 && !attach_generic) - return (ENXIO); + return (NULL); for (him = him_list; him; him = him->next) { for (i=0; him->get_supported_device_id(i, &pci_id); i++) { if ((pci_get_vendor(dev) == pci_id.vid) && (pci_get_device(dev) == pci_id.did)){ - KdPrint(("hpt_probe: adapter at PCI %d:%d:%d, IRQ %d", - pci_get_bus(dev), pci_get_slot(dev), pci_get_function(dev), pci_get_irq(dev) - )); - device_set_desc(dev, him->name); - hba = (PHBA)device_get_softc(dev); - memset(hba, 0, sizeof(HBA)); - hba->ext_type = EXT_TYPE_HBA; - hba->ldm_adapter.him = him; - return (BUS_PROBE_DEFAULT); + return (him); } } } + return (NULL); +} + +static int hpt_probe(device_t dev) +{ + HIM *him; + + him = hpt_match(dev); + if (him != NULL) { + KdPrint(("hpt_probe: adapter at PCI %d:%d:%d, IRQ %d", + pci_get_bus(dev), pci_get_slot(dev), pci_get_function(dev), pci_get_irq(dev) + )); + device_set_desc(dev, him->name); + return (BUS_PROBE_DEFAULT); + } return (ENXIO); } @@ -72,17 +78,19 @@ static int hpt_probe(device_t dev) static int hpt_attach(device_t dev) { PHBA hba = (PHBA)device_get_softc(dev); - HIM *him = hba->ldm_adapter.him; + HIM *him; PCI_ID pci_id; HPT_UINT size; PVBUS vbus; PVBUS_EXT vbus_ext; KdPrint(("hpt_attach(%d/%d/%d)", pci_get_bus(dev), pci_get_slot(dev), pci_get_function(dev))); - -#if __FreeBSD_version >=440000 + + him = hpt_match(dev); + hba->ext_type = EXT_TYPE_HBA; + hba->ldm_adapter.him = him; + pci_enable_busmaster(dev); -#endif pci_id.vid = pci_get_vendor(dev); pci_id.did = pci_get_device(dev); @@ -90,8 +98,6 @@ static int hpt_attach(device_t dev) size = him->get_adapter_size(&pci_id); hba->ldm_adapter.him_handle = malloc(size, M_DEVBUF, M_WAITOK); - if (!hba->ldm_adapter.him_handle) - return ENXIO; hba->pcidev = dev; hba->pciaddr.tree = 0; @@ -101,7 +107,7 @@ static int hpt_attach(device_t dev) if (!him->create_adapter(&pci_id, hba->pciaddr, hba->ldm_adapter.him_handle, hba)) { free(hba->ldm_adapter.him_handle, M_DEVBUF); - return -1; + return ENXIO; } os_printk("adapter at PCI %d:%d:%d, IRQ %d", @@ -109,12 +115,8 @@ static int hpt_attach(device_t dev) if (!ldm_register_adapter(&hba->ldm_adapter)) { size = ldm_get_vbus_size(); - vbus_ext = malloc(sizeof(VBUS_EXT) + size, M_DEVBUF, M_WAITOK); - if (!vbus_ext) { - free(hba->ldm_adapter.him_handle, M_DEVBUF); - return -1; - } - memset(vbus_ext, 0, sizeof(VBUS_EXT)); + vbus_ext = malloc(sizeof(VBUS_EXT) + size, M_DEVBUF, M_WAITOK | + M_ZERO); vbus_ext->ext_type = EXT_TYPE_VBUS; ldm_create_vbus((PVBUS)vbus_ext->vbus, vbus_ext); ldm_register_adapter(&hba->ldm_adapter); @@ -295,7 +297,7 @@ static int hpt_flush_vdev(PVBUS_EXT vbus_ext, PVDEV vd) KdPrint(("flusing dev %p", vd)); - hpt_lock_vbus(vbus_ext); + hpt_assert_vbus_locked(vbus_ext); if (mIsArray(vd->type) && vd->u.array.transform) count = MAX(vd->u.array.transform->source->cmds_per_request, @@ -306,7 +308,6 @@ static int hpt_flush_vdev(PVBUS_EXT vbus_ext, PVDEV vd) pCmd = ldm_alloc_cmds(vd->vbus, count); if (!pCmd) { - hpt_unlock_vbus(vbus_ext); return -1; } @@ -332,8 +333,6 @@ static int hpt_flush_vdev(PVBUS_EXT vbus_ext, PVDEV vd) ldm_free_cmds(pCmd); - hpt_unlock_vbus(vbus_ext); - return result; } @@ -348,6 +347,7 @@ static void hpt_shutdown_vbus(PVBUS_EXT vbus_ext, int howto) /* stop all ctl tasks and disable the worker taskqueue */ hpt_stop_tasks(vbus_ext); + hpt_lock_vbus(vbus_ext); vbus_ext->worker.ta_context = 0; /* flush devices */ @@ -360,7 +360,6 @@ static void hpt_shutdown_vbus(PVBUS_EXT vbus_ext, int howto) } } - hpt_lock_vbus(vbus_ext); ldm_shutdown(vbus); hpt_unlock_vbus(vbus_ext); @@ -376,6 +375,8 @@ static void hpt_shutdown_vbus(PVBUS_EXT vbus_ext, int howto) free(hba->ldm_adapter.him_handle, M_DEVBUF); } + callout_drain(&vbus_ext->timer); + mtx_destroy(&vbus_ext->lock); free(vbus_ext, M_DEVBUF); KdPrint(("hpt_shutdown_vbus done")); } @@ -439,8 +440,8 @@ static void os_cmddone(PCOMMAND pCmd) union ccb *ccb = ext->ccb; KdPrint(("os_cmddone(%p, %d)", pCmd, pCmd->Result)); - - untimeout(hpt_timeout, pCmd, ext->timeout_ch); + + callout_stop(&ext->timeout); switch(pCmd->Result) { case RETURN_SUCCESS: @@ -528,7 +529,7 @@ static void hpt_io_dmamap_callback(void *arg, bus_dma_segment_t *segs, int nsegs BUS_DMASYNC_PREWRITE); } } - ext->timeout_ch = timeout(hpt_timeout, pCmd, HPT_OSM_TIMEOUT); + callout_reset(&ext->timeout, HPT_OSM_TIMEOUT, hpt_timeout, pCmd); ldm_queue_cmd(pCmd); } @@ -745,18 +746,15 @@ static void hpt_action(struct cam_sim *sim, union ccb *ccb) KdPrint(("hpt_action(fn=%d, id=%d)", ccb->ccb_h.func_code, ccb->ccb_h.target_id)); + hpt_assert_vbus_locked(vbus_ext); switch (ccb->ccb_h.func_code) { case XPT_SCSI_IO: - hpt_lock_vbus(vbus_ext); hpt_scsi_io(vbus_ext, ccb); - hpt_unlock_vbus(vbus_ext); return; case XPT_RESET_BUS: - hpt_lock_vbus(vbus_ext); ldm_reset_vbus((PVBUS)vbus_ext->vbus); - hpt_unlock_vbus(vbus_ext); break; case XPT_GET_TRAN_SETTINGS: @@ -765,14 +763,7 @@ static void hpt_action(struct cam_sim *sim, union ccb *ccb) break; case XPT_CALC_GEOMETRY: -#if __FreeBSD_version >= 500000 cam_calc_geometry(&ccb->ccg, 1); -#else - ccb->ccg.heads = 255; - ccb->ccg.secs_per_track = 63; - ccb->ccg.cylinders = ccb->ccg.volume_size / (ccb->ccg.heads * ccb->ccg.secs_per_track); - ccb->ccb_h.status = CAM_REQ_CMP; -#endif break; case XPT_PATH_INQ: @@ -821,7 +812,9 @@ static void hpt_pci_intr(void *arg) static void hpt_poll(struct cam_sim *sim) { - hpt_pci_intr(cam_sim_softc(sim)); + PVBUS_EXT vbus_ext = cam_sim_softc(sim); + hpt_assert_vbus_locked(vbus_ext); + ldm_intr((PVBUS)vbus_ext->vbus); } static void hpt_async(void * callback_arg, u_int32_t code, struct cam_path * path, void * arg) @@ -970,19 +963,7 @@ static struct cdevsw hpt_cdevsw = { .d_close = hpt_close, .d_ioctl = hpt_ioctl, .d_name = driver_name, -#if __FreeBSD_version>=503000 .d_version = D_VERSION, -#endif -#if (__FreeBSD_version>=503000 && __FreeBSD_version<600034) - .d_flags = D_NEEDGIANT, -#endif -#if __FreeBSD_version<600034 -#if __FreeBSD_version>501000 - .d_maj = MAJOR_AUTO, -#else - .d_maj = HPT_DEV_MAJOR, -#endif -#endif }; static struct intr_config_hook hpt_ich; @@ -1019,7 +1000,8 @@ static void hpt_final_init(void *dummy) /* initializing hardware */ ldm_for_each_vbus(vbus, vbus_ext) { /* make timer available here */ - callout_handle_init(&vbus_ext->timer); + mtx_init(&vbus_ext->lock, "hptsleeplock", NULL, MTX_DEF); + callout_init_mtx(&vbus_ext->timer, &vbus_ext->lock, 0); if (hpt_init_vbus(vbus_ext)) { os_printk("fail to initialize hardware"); break; /* FIXME */ @@ -1031,9 +1013,6 @@ static void hpt_final_init(void *dummy) struct cam_devq *devq; struct ccb_setasync ccb; -#if (__FreeBSD_version >= 500000) - mtx_init(&vbus_ext->lock, "hptsleeplock", NULL, MTX_DEF); -#endif if (bus_dma_tag_create(NULL,/* parent */ 4, /* alignment */ BUS_SPACE_MAXADDR_32BIT+1, /* boundary */ @@ -1044,10 +1023,8 @@ static void hpt_final_init(void *dummy) os_max_sg_descriptors, /* nsegments */ 0x10000, /* maxsegsize */ BUS_DMA_WAITOK, /* flags */ -#if __FreeBSD_version>502000 busdma_lock_mutex, /* lockfunc */ &vbus_ext->lock, /* lockfuncarg */ -#endif &vbus_ext->io_dmat /* tag */)) { return ; @@ -1067,7 +1044,7 @@ static void hpt_final_init(void *dummy) os_printk("Can't create dma map(%d)", i); return ; } - callout_handle_init(&ext->timeout_ch); + callout_init_mtx(&ext->timeout, &vbus_ext->lock, 0); } if ((devq = cam_simq_alloc(os_max_queue_comm)) == NULL) { @@ -1075,13 +1052,9 @@ static void hpt_final_init(void *dummy) return ; } -#if __FreeBSD_version > 700025 vbus_ext->sim = cam_sim_alloc(hpt_action, hpt_poll, driver_name, - vbus_ext, 0, &Giant, os_max_queue_comm, /*tagged*/8, devq); -#else - vbus_ext->sim = cam_sim_alloc(hpt_action, hpt_poll, driver_name, - vbus_ext, 0, os_max_queue_comm, /*tagged*/8, devq); -#endif + vbus_ext, 0, &vbus_ext->lock, os_max_queue_comm, + /*tagged*/8, devq); if (!vbus_ext->sim) { os_printk("cam_sim_alloc failed"); @@ -1089,13 +1062,11 @@ static void hpt_final_init(void *dummy) return ; } -#if __FreeBSD_version > 700044 + hpt_lock_vbus(vbus_ext); if (xpt_bus_register(vbus_ext->sim, NULL, 0) != CAM_SUCCESS) { -#else - if (xpt_bus_register(vbus_ext->sim, 0) != CAM_SUCCESS) { -#endif os_printk("xpt_bus_register failed"); cam_sim_free(vbus_ext->sim, /*free devq*/ TRUE); + hpt_unlock_vbus(vbus_ext); vbus_ext->sim = NULL; return ; } @@ -1107,9 +1078,11 @@ static void hpt_final_init(void *dummy) os_printk("xpt_create_path failed"); xpt_bus_deregister(cam_sim_path(vbus_ext->sim)); cam_sim_free(vbus_ext->sim, /*free_devq*/TRUE); + hpt_unlock_vbus(vbus_ext); vbus_ext->sim = NULL; return ; } + hpt_unlock_vbus(vbus_ext); xpt_setup_ccb(&ccb.ccb_h, vbus_ext->path, /*priority*/5); ccb.ccb_h.func_code = XPT_SASYNC_CB; @@ -1127,12 +1100,8 @@ static void hpt_final_init(void *dummy) return ; } - if (bus_setup_intr(hba->pcidev, hba->irq_res, INTR_TYPE_CAM, -#if __FreeBSD_version > 700025 + if (bus_setup_intr(hba->pcidev, hba->irq_res, INTR_TYPE_CAM | INTR_MPSAFE, NULL, hpt_pci_intr, vbus_ext, &hba->irq_handle)) -#else - hpt_pci_intr, vbus_ext, &hba->irq_handle)) -#endif { os_printk("can't set up interrupt"); return ; @@ -1156,7 +1125,7 @@ static void hpt_final_init(void *dummy) S_IRUSR | S_IWUSR, "%s", driver_name); } -#if defined(KLD_MODULE) && (__FreeBSD_version >= 503000) +#if defined(KLD_MODULE) typedef struct driverlink *driverlink_t; struct driverlink { @@ -1248,29 +1217,17 @@ __DRIVER_MODULE(TARGETNAME, pci, hpt_pci_driver, hpt_devclass, 0, 0); __MODULE_VERSION(TARGETNAME, 1); __MODULE_DEPEND(TARGETNAME, cam, 1, 1, 1); -#if __FreeBSD_version>503000 -typedef struct cdev * ioctl_dev_t; -#else -typedef dev_t ioctl_dev_t; -#endif - -#if __FreeBSD_version >= 500000 -typedef struct thread * ioctl_thread_t; -#else -typedef struct proc * ioctl_thread_t; -#endif - -static int hpt_open(ioctl_dev_t dev, int flags, int devtype, ioctl_thread_t td) +static int hpt_open(struct cdev *dev, int flags, int devtype, struct thread *td) { return 0; } -static int hpt_close(ioctl_dev_t dev, int flags, int devtype, ioctl_thread_t td) +static int hpt_close(struct cdev *dev, int flags, int devtype, struct thread *td) { return 0; } -static int hpt_ioctl(ioctl_dev_t dev, u_long cmd, caddr_t data, int fflag, ioctl_thread_t td) +static int hpt_ioctl(struct cdev *dev, u_long cmd, caddr_t data, int fflag, struct thread *td) { PHPT_IOCTL_PARAM piop=(PHPT_IOCTL_PARAM)data; IOCTL_ARG ioctl_args; @@ -1309,16 +1266,8 @@ static int hpt_ioctl(ioctl_dev_t dev, u_long cmd, caddr_t data, int fflag, ioctl goto invalid; } -#if (__FreeBSD_version >= 500000) - mtx_lock(&Giant); -#endif - hpt_do_ioctl(&ioctl_args); -#if (__FreeBSD_version >= 500000) - mtx_unlock(&Giant); -#endif - if (ioctl_args.result==HPT_IOCTL_RESULT_OK) { if (piop->nOutBufferSize) { if (copyout(ioctl_args.lpOutBuffer, @@ -1359,10 +1308,6 @@ static int hpt_rescan_bus(void) PVBUS vbus; PVBUS_EXT vbus_ext; -#if (__FreeBSD_version >= 500000) - mtx_lock(&Giant); -#endif - ldm_for_each_vbus(vbus, vbus_ext) { if ((ccb = xpt_alloc_ccb()) == NULL) return(ENOMEM); @@ -1375,9 +1320,5 @@ static int hpt_rescan_bus(void) xpt_rescan(ccb); } -#if (__FreeBSD_version >= 500000) - mtx_unlock(&Giant); -#endif - return(0); } diff --git a/sys/dev/hptrr/os_bsd.h b/sys/dev/hptrr/os_bsd.h index 1c6760e..4f8abb5 100644 --- a/sys/dev/hptrr/os_bsd.h +++ b/sys/dev/hptrr/os_bsd.h @@ -42,12 +42,8 @@ #include <sys/param.h> #include <sys/types.h> #include <sys/cons.h> -#if (__FreeBSD_version >= 500000) #include <sys/time.h> #include <sys/systm.h> -#else -#include <machine/clock.h> /*to support DELAY function under 4.x BSD versions*/ -#endif #include <sys/stat.h> #include <sys/malloc.h> @@ -55,11 +51,9 @@ #include <sys/libkern.h> #include <sys/kernel.h> -#if (__FreeBSD_version >= 500000) #include <sys/kthread.h> #include <sys/mutex.h> #include <sys/module.h> -#endif #include <sys/eventhandler.h> #include <sys/bus.h> @@ -74,17 +68,8 @@ #include <vm/vm.h> #include <vm/pmap.h> -#if (__FreeBSD_version >= 500000) #include <dev/pci/pcireg.h> #include <dev/pci/pcivar.h> -#else -#include <pci/pcivar.h> -#include <pci/pcireg.h> -#endif - -#if (__FreeBSD_version <= 500043) -#include <sys/devicestat.h> -#endif #include <cam/cam.h> #include <cam/cam_ccb.h> @@ -95,9 +80,6 @@ #include <cam/scsi/scsi_all.h> #include <cam/scsi/scsi_message.h> -#if (__FreeBSD_version < 500043) -#include <sys/bus_private.h> -#endif typedef struct _INQUIRYDATA { @@ -174,7 +156,7 @@ typedef struct _os_cmdext { struct _os_cmdext *next; union ccb *ccb; bus_dmamap_t dma_map; - struct callout_handle timeout_ch; + struct callout timeout; SG psg[os_max_sg_descriptors]; } OS_CMDEXT, *POS_CMDEXT; @@ -188,11 +170,7 @@ typedef struct _vbus_ext { struct cam_sim *sim; /* sim for this vbus */ struct cam_path *path; /* peripheral, path, tgt, lun with this vbus */ -#if (__FreeBSD_version >= 500000) struct mtx lock; /* general purpose lock */ -#else - int hpt_splx; -#endif bus_dma_tag_t io_dmat; /* I/O buffer DMA tag */ POS_CMDEXT cmdext_list; @@ -200,7 +178,7 @@ typedef struct _vbus_ext { OSM_TASK *tasks; struct task worker; - struct callout_handle timer; + struct callout timer; eventhandler_tag shutdown_eh; @@ -209,19 +187,9 @@ typedef struct _vbus_ext { } VBUS_EXT, *PVBUS_EXT; -#if __FreeBSD_version >= 500000 #define hpt_lock_vbus(vbus_ext) mtx_lock(&(vbus_ext)->lock) #define hpt_unlock_vbus(vbus_ext) mtx_unlock(&(vbus_ext)->lock) -#else -static __inline void hpt_lock_vbus(PVBUS_EXT vbus_ext) -{ - vbus_ext->hpt_splx = splcam(); -} -static __inline void hpt_unlock_vbus(PVBUS_EXT vbus_ext) -{ - splx(vbus_ext->hpt_splx); -} -#endif +#define hpt_assert_vbus_locked(vbus_ext) mtx_assert(&(vbus_ext)->lock, MA_OWNED) #define HPT_OSM_TIMEOUT (20*hz) /* timeout value for OS commands */ @@ -230,35 +198,9 @@ static __inline void hpt_unlock_vbus(PVBUS_EXT vbus_ext) #define HPT_SCAN_BUS _IO('H', 1) -#if __FreeBSD_version >= 501000 -#define TASK_ENQUEUE(task) taskqueue_enqueue(taskqueue_swi_giant,(task)); -#else #define TASK_ENQUEUE(task) taskqueue_enqueue(taskqueue_swi,(task)); -#endif -#if __FreeBSD_version >= 500000 static __inline int hpt_sleep(PVBUS_EXT vbus_ext, void *ident, int priority, const char *wmesg, int timo) { return msleep(ident, &vbus_ext->lock, priority, wmesg, timo); } -#else -static __inline int hpt_sleep(PVBUS_EXT vbus_ext, void *ident, int priority, const char *wmesg, int timo) -{ - int retval = 0; - - asleep(ident, priority, wmesg, timo); - hpt_unlock_vbus(vbus_ext); - retval = await(priority, timo); - hpt_lock_vbus(vbus_ext); - - return retval; -} -#endif - -#if __FreeBSD_version < 501000 -#define READ_16 0x88 -#define WRITE_16 0x8a -#define SERVICE_ACTION_IN 0x9e -#endif - -#define HPT_DEV_MAJOR 200 |