Skip site navigation (1)Skip section navigation (2)
Date:      Sun, 28 Apr 2013 20:16:00 -0400
From:      Eitan Adler <lists@eitanadler.com>
To:        FreeBSD Hackers <freebsd-hackers@freebsd.org>
Cc:        swildner@dragonflybsd.org
Subject:   sys/dev/hptiop cleanup & bugfix
Message-ID:  <CAF6rxgkK0YBhD9x9OEm15qXoZEYMAOaCBxc4gyt7Nw2gJjOUJw@mail.gmail.com>

next in thread | raw e-mail | index | archive | help
Thoughts?

commit 17adf7957edc9d3512a02bcc3436e2718469002c
Author: Eitan Adler <lists@eitanadler.com>
Date:   Sun Apr 28 20:11:42 2013 -0400

    Remove ancient compatibility cruft.

diff --git a/sys/dev/hptiop/hptiop.c b/sys/dev/hptiop/hptiop.c
index 1191718..8ded436 100644
--- a/sys/dev/hptiop/hptiop.c
+++ b/sys/dev/hptiop/hptiop.c
@@ -30,12 +30,8 @@ __FBSDID("$FreeBSD$");
 #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>
-#endif

 #include <sys/stat.h>
 #include <sys/malloc.h>
@@ -43,11 +39,9 @@ __FBSDID("$FreeBSD$");
 #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>
@@ -62,17 +56,9 @@ __FBSDID("$FreeBSD$");
 #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>
@@ -83,9 +69,6 @@ __FBSDID("$FreeBSD$");
 #include <cam/scsi/scsi_all.h>
 #include <cam/scsi/scsi_message.h>

-#if (__FreeBSD_version < 500043)
-#include <sys/bus_private.h>
-#endif

 #include <dev/hptiop/hptiop.h>

@@ -177,27 +160,11 @@ static struct cdevsw hptiop_cdevsw = {
 	.d_close = hptiop_close,
 	.d_ioctl = hptiop_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
 };

-#if __FreeBSD_version < 503000
-#define hba_from_dev(dev) ((struct hpt_iop_hba *)(dev)->si_drv1)
-#else
 #define hba_from_dev(dev) \
 	((struct hpt_iop_hba *)devclass_get_softc(hptiop_devclass, dev2unit(dev)))
-#endif

 #define BUS_SPACE_WRT4_ITL(offset, value) bus_space_write_4(hba->bar0t,\
 		hba->bar0h, offsetof(struct hpt_iopmu_itl, offset), (value))
@@ -245,9 +212,7 @@ static int hptiop_ioctl(ioctl_dev_t dev, u_long
cmd, caddr_t data,
 	int ret = EFAULT;
 	struct hpt_iop_hba *hba = hba_from_dev(dev);

-#if (__FreeBSD_version >= 500000)
 	mtx_lock(&Giant);
-#endif

 	switch (cmd) {
 	case HPT_DO_IOCONTROL:
@@ -259,9 +224,7 @@ static int hptiop_ioctl(ioctl_dev_t dev, u_long
cmd, caddr_t data,
 		break;
 	}

-#if (__FreeBSD_version >= 500000)
 	mtx_unlock(&Giant);
-#endif

 	return ret;
 }
@@ -1615,21 +1578,15 @@ static int hptiop_internal_memalloc_mv(struct
hpt_iop_hba *hba)
 				1,
 				BUS_SPACE_MAXSIZE_32BIT,
 				BUS_DMA_ALLOCNOW,
-#if __FreeBSD_version > 502000
 				NULL,
 				NULL,
-#endif
 				&hba->ctlcfg_dmat)) {
 		device_printf(hba->pcidev, "alloc ctlcfg_dmat failed\n");
 		return -1;
 	}

 	if (bus_dmamem_alloc(hba->ctlcfg_dmat, (void **)&hba->ctlcfg_ptr,
-#if __FreeBSD_version>501000
 		BUS_DMA_WAITOK | BUS_DMA_COHERENT,
-#else
-		BUS_DMA_WAITOK,
-#endif
 		&hba->ctlcfg_dmamap) != 0) {
 			device_printf(hba->pcidev,
 					"bus_dmamem_alloc failed!\n");
@@ -1678,21 +1635,15 @@ static int
hptiop_internal_memalloc_mvfrey(struct hpt_iop_hba *hba)
 				1,
 				BUS_SPACE_MAXSIZE_32BIT,
 				BUS_DMA_ALLOCNOW,
-#if __FreeBSD_version > 502000
 				NULL,
 				NULL,
-#endif
 				&hba->ctlcfg_dmat)) {
 		device_printf(hba->pcidev, "alloc ctlcfg_dmat failed\n");
 		return -1;
 	}

 	if (bus_dmamem_alloc(hba->ctlcfg_dmat, (void **)&hba->ctlcfg_ptr,
-#if __FreeBSD_version>501000
 		BUS_DMA_WAITOK | BUS_DMA_COHERENT,
-#else
-		BUS_DMA_WAITOK,
-#endif
 		&hba->ctlcfg_dmamap) != 0) {
 			device_printf(hba->pcidev,
 					"bus_dmamem_alloc failed!\n");
@@ -1937,9 +1888,7 @@ static int hptiop_attach(device_t dev)
 		pci_get_bus(dev), pci_get_slot(dev),
 		pci_get_function(dev), hba->ops));

-#if __FreeBSD_version >=440000
 	pci_enable_busmaster(dev);
-#endif
 	hba->pcidev = dev;
 	hba->pciunit = unit;

@@ -1951,9 +1900,7 @@ static int hptiop_attach(device_t dev)
 		goto release_pci_res;
 	}

-#if (__FreeBSD_version >= 500000)
 	mtx_init(&hba->lock, "hptioplock", NULL, MTX_DEF);
-#endif

 	if (bus_dma_tag_create(bus_get_dma_tag(dev),/* PCI parent */
 			1,  /* alignment */
@@ -1965,10 +1912,8 @@ static int hptiop_attach(device_t dev)
 			BUS_SPACE_UNRESTRICTED, /* nsegments */
 			BUS_SPACE_MAXSIZE_32BIT,    /* maxsegsize */
 			0,      /* flags */
-#if __FreeBSD_version>502000
 			NULL,   /* lockfunc */
 			NULL,       /* lockfuncarg */
-#endif
 			&hba->parent_dmat   /* tag */))
 	{
 		device_printf(dev, "alloc parent_dmat failed\n");
@@ -2015,10 +1960,8 @@ static int hptiop_attach(device_t dev)
 			hba->max_sg_count,  /* nsegments */
 			0x20000,    /* maxsegsize */
 			BUS_DMA_ALLOCNOW,       /* flags */
-#if __FreeBSD_version>502000
 			busdma_lock_mutex,  /* lockfunc */
 			&hba->lock,     /* lockfuncarg */
-#endif
 			&hba->io_dmat   /* tag */))
 	{
 		device_printf(dev, "alloc io_dmat failed\n");
@@ -2035,10 +1978,8 @@ static int hptiop_attach(device_t dev)
 			1,  /* nsegments */
 			BUS_SPACE_MAXSIZE_32BIT,    /* maxsegsize */
 			0,      /* flags */
-#if __FreeBSD_version>502000
 			NULL,   /* lockfunc */
 			NULL,       /* lockfuncarg */
-#endif
 			&hba->srb_dmat  /* tag */))
 	{
 		device_printf(dev, "alloc srb_dmat failed\n");
@@ -2046,11 +1987,7 @@ static int hptiop_attach(device_t dev)
 	}

 	if (bus_dmamem_alloc(hba->srb_dmat, (void **)&hba->uncached_ptr,
-#if __FreeBSD_version>501000
 			BUS_DMA_WAITOK | BUS_DMA_COHERENT,
-#else
-			BUS_DMA_WAITOK,
-#endif
 			&hba->srb_dmamap) != 0)
 	{
 		device_printf(dev, "srb bus_dmamem_alloc failed!\n");
@@ -2071,23 +2008,14 @@ static int hptiop_attach(device_t dev)
 		goto srb_dmamap_unload;
 	}

-#if __FreeBSD_version <700000
-	hba->sim = cam_sim_alloc(hptiop_action, hptiop_poll, driver_name,
-			hba, unit, hba->max_requests - 1, 1, devq);
-#else
 	hba->sim = cam_sim_alloc(hptiop_action, hptiop_poll, driver_name,
 			hba, unit, &Giant, hba->max_requests - 1, 1, devq);
-#endif
 	if (!hba->sim) {
 		device_printf(dev, "cam_sim_alloc failed\n");
 		cam_simq_free(devq);
 		goto srb_dmamap_unload;
 	}
-#if __FreeBSD_version <700000
-	if (xpt_bus_register(hba->sim, 0) != CAM_SUCCESS)
-#else
 	if (xpt_bus_register(hba->sim, dev, 0) != CAM_SUCCESS)
-#endif
 	{
 		device_printf(dev, "xpt_bus_register failed\n");
 		goto free_cam_sim;
@@ -2124,13 +2052,8 @@ static int hptiop_attach(device_t dev)
 		goto free_hba_path;
 	}

-#if __FreeBSD_version <700000
-	if (bus_setup_intr(hba->pcidev, hba->irq_res, INTR_TYPE_CAM,
-				hptiop_pci_intr, hba, &hba->irq_handle))
-#else
 	if (bus_setup_intr(hba->pcidev, hba->irq_res, INTR_TYPE_CAM,
 				NULL, hptiop_pci_intr, hba, &hba->irq_handle))
-#endif
 	{
 		device_printf(dev, "allocate intr function failed!\n");
 		goto free_irq_resource;
@@ -2149,9 +2072,6 @@ static int hptiop_attach(device_t dev)
 				UID_ROOT, GID_WHEEL /*GID_OPERATOR*/,
 				S_IRUSR | S_IWUSR, "%s%d", driver_name, unit);

-#if __FreeBSD_version < 503000
-	hba->ioctl_dev->si_drv1 = hba;
-#endif

 	return 0;

@@ -2419,15 +2339,7 @@ scsi_done:
 		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:
diff --git a/sys/dev/hptiop/hptiop.h b/sys/dev/hptiop/hptiop.h
index 0c8de3c..8683620 100644
--- a/sys/dev/hptiop/hptiop.h
+++ b/sys/dev/hptiop/hptiop.h
@@ -333,17 +333,9 @@ struct hpt_iop_ioctl_param {
 #define HPT_IOCTL_FLAG_OPEN 1
 #define HPT_CTL_CODE_BSD_TO_IOP(x) ((x)-0xff00)

-#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

 struct hpt_iop_hba {
 	struct hptiop_adapter_ops *ops;
@@ -425,11 +417,7 @@ struct hpt_iop_hba {
 	struct cam_sim        *sim;
 	struct cam_path       *path;
 	void                  *req;
-#if (__FreeBSD_version >= 500000)
 	struct mtx            lock;
-#else
-	int                   hpt_splx;
-#endif
 #define HPT_IOCTL_FLAG_OPEN     1
 	u_int32_t             flag;
 	struct hpt_iop_srb* srb[HPT_SRB_MAX_QUEUE_SIZE];
@@ -474,19 +462,8 @@ struct hpt_iop_srb {
 	int                  index;
 };

-#if __FreeBSD_version >= 500000
 #define hptiop_lock_adapter(hba)   mtx_lock(&(hba)->lock)
 #define hptiop_unlock_adapter(hba) mtx_unlock(&(hba)->lock)
-#else
-static __inline void hptiop_lock_adapter(struct hpt_iop_hba *hba)
-{
-	hba->hpt_splx = splcam();
-}
-static __inline void hptiop_unlock_adapter(struct hpt_iop_hba *hba)
-{
-	splx(hba->hpt_splx);
-}
-#endif

 #define HPT_OSM_TIMEOUT (20*hz)  /* timeout value for OS commands */

@@ -499,24 +476,12 @@ static  __inline int hptiop_sleep(struct
hpt_iop_hba *hba, void *ident,

 	int retval;

-#if __FreeBSD_version >= 500000
 	retval = msleep(ident, &hba->lock, priority, wmesg, timo);
-#else
-	asleep(ident, priority, wmesg, timo);
-	hptiop_unlock_adapter(hba);
-	retval = await(priority, timo);
-	hptiop_lock_adapter(hba);
-#endif

 	return retval;

 }

-#if __FreeBSD_version < 501000
-#define READ_16             0x88
-#define WRITE_16            0x8a
-#define SERVICE_ACTION_IN   0x9e
-#endif

 #define HPT_DEV_MAJOR   200
 commit 6c2ededb884cf00fc9ebd5787175b4915a9d2ad1
Author: Eitan Adler <lists@eitanadler.com>
Date:   Sun Apr 28 20:07:36 2013 -0400

    Add missing braces

    Reviewed by:	swildner@dragonflybsd.org

diff --git a/sys/dev/hptiop/hptiop.c b/sys/dev/hptiop/hptiop.c
index d7a17c8..1191718 100644
--- a/sys/dev/hptiop/hptiop.c
+++ b/sys/dev/hptiop/hptiop.c
@@ -1642,10 +1642,11 @@ static int hptiop_internal_memalloc_mv(struct
hpt_iop_hba *hba)
 			MVIOP_IOCTLCFG_SIZE,
 			hptiop_mv_map_ctlcfg, hba, 0)) {
 		device_printf(hba->pcidev, "bus_dmamap_load failed!\n");
-		if (hba->ctlcfg_dmat)
+		if (hba->ctlcfg_dmat) {
 			bus_dmamem_free(hba->ctlcfg_dmat,
 				hba->ctlcfg_ptr, hba->ctlcfg_dmamap);
 			bus_dma_tag_destroy(hba->ctlcfg_dmat);
+		}
 		return -1;
 	}

@@ -1704,10 +1705,11 @@ static int
hptiop_internal_memalloc_mvfrey(struct hpt_iop_hba *hba)
 			hba->u.mvfrey.internal_mem_size,
 			hptiop_mvfrey_map_ctlcfg, hba, 0)) {
 		device_printf(hba->pcidev, "bus_dmamap_load failed!\n");
-		if (hba->ctlcfg_dmat)
+		if (hba->ctlcfg_dmat) {
 			bus_dmamem_free(hba->ctlcfg_dmat,
 				hba->ctlcfg_ptr, hba->ctlcfg_dmamap);
 			bus_dma_tag_destroy(hba->ctlcfg_dmat);
+		}
 		return -1;
 	}



-- 
Eitan Adler



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?CAF6rxgkK0YBhD9x9OEm15qXoZEYMAOaCBxc4gyt7Nw2gJjOUJw>