summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorjhb <jhb@FreeBSD.org>2014-11-13 22:06:57 +0000
committerjhb <jhb@FreeBSD.org>2014-11-13 22:06:57 +0000
commit78a5f1bde1d8df190d62e6db591f7fbbaad8e6bd (patch)
treeefd964ac078cb3a00b84c7927aa5c1cd1713980e
parent1c95a6b2b42a794c0e10a916c8b3d6a2d852a9fe (diff)
downloadFreeBSD-src-78a5f1bde1d8df190d62e6db591f7fbbaad8e6bd.zip
FreeBSD-src-78a5f1bde1d8df190d62e6db591f7fbbaad8e6bd.tar.gz
- Use the existing driver lock in cdevsw methods and remove D_NEEDGIANT.
- Use callout(9) instead of timeout(9). - Use bus_*() instead of bus_space_*(). - Don't check for a NULL softc in attach. Tested by: no one
-rw-r--r--sys/dev/ips/ips.c16
-rw-r--r--sys/dev/ips/ips.h16
-rw-r--r--sys/dev/ips/ips_pci.c22
3 files changed, 21 insertions, 33 deletions
diff --git a/sys/dev/ips/ips.c b/sys/dev/ips/ips.c
index 4de98ce..7ef3ba7 100644
--- a/sys/dev/ips/ips.c
+++ b/sys/dev/ips/ips.c
@@ -41,7 +41,6 @@ MALLOC_DEFINE(M_IPSBUF, "ipsbuf","IPS driver buffer");
static struct cdevsw ips_cdevsw = {
.d_version = D_VERSION,
- .d_flags = D_NEEDGIANT,
.d_open = ips_open,
.d_close = ips_close,
.d_ioctl = ips_ioctl,
@@ -74,14 +73,19 @@ static const char* ips_adapter_name[] = {
static int ips_open(struct cdev *dev, int flags, int fmt, struct thread *td)
{
ips_softc_t *sc = dev->si_drv1;
+ mtx_lock(&sc->queue_mtx);
sc->state |= IPS_DEV_OPEN;
+ mtx_unlock(&sc->queue_mtx);
return 0;
}
static int ips_close(struct cdev *dev, int flags, int fmt, struct thread *td)
{
ips_softc_t *sc = dev->si_drv1;
+
+ mtx_lock(&sc->queue_mtx);
sc->state &= ~IPS_DEV_OPEN;
+ mtx_unlock(&sc->queue_mtx);
return 0;
}
@@ -299,7 +303,7 @@ static void ips_timeout(void *arg)
int i, state = 0;
ips_command_t *command;
- mtx_lock(&sc->queue_mtx);
+ mtx_assert(&sc->queue_mtx, MA_OWNED);
command = &sc->commandarray[0];
for(i = 0; i < sc->max_cmds; i++){
if(!command[i].timeout){
@@ -329,8 +333,7 @@ static void ips_timeout(void *arg)
sc->state &= ~IPS_TIMEOUT;
}
if (sc->state != IPS_OFFLINE)
- sc->timer = timeout(ips_timeout, sc, 10*hz);
- mtx_unlock(&sc->queue_mtx);
+ callout_reset(&sc->timer, 10 * hz, ips_timeout, sc);
}
/* check card and initialize it */
@@ -379,7 +382,6 @@ int ips_adapter_init(ips_softc_t *sc)
can handle */
sc->max_cmds = 1;
ips_cmdqueue_init(sc);
- callout_handle_init(&sc->timer);
if(sc->ips_adapter_reinit(sc, 0))
goto error;
@@ -417,7 +419,7 @@ int ips_adapter_init(ips_softc_t *sc)
S_IRUSR | S_IWUSR, "ips%d", device_get_unit(sc->dev));
sc->device_file->si_drv1 = sc;
ips_diskdev_init(sc);
- sc->timer = timeout(ips_timeout, sc, 10*hz);
+ callout_reset(&sc->timer, 10 * hz, ips_timeout, sc);
return 0;
error:
@@ -492,7 +494,7 @@ int ips_adapter_free(ips_softc_t *sc)
return EBUSY;
}
DEVICE_PRINTF(1, sc->dev, "free\n");
- untimeout(ips_timeout, sc, sc->timer);
+ callout_drain(&sc->timer);
if(sc->sg_dmatag)
bus_dma_tag_destroy(sc->sg_dmatag);
diff --git a/sys/dev/ips/ips.h b/sys/dev/ips/ips.h
index 1b32164..9ae4812 100644
--- a/sys/dev/ips/ips.h
+++ b/sys/dev/ips/ips.h
@@ -56,13 +56,13 @@ MALLOC_DECLARE(M_IPSBUF);
* IPS MACROS
*/
-#define ips_read_1(sc,offset) bus_space_read_1(sc->bustag, sc->bushandle, offset)
-#define ips_read_2(sc,offset) bus_space_read_2(sc->bustag, sc->bushandle, offset)
-#define ips_read_4(sc,offset) bus_space_read_4(sc->bustag, sc->bushandle, offset)
+#define ips_read_1(sc,offset) bus_read_1(sc->iores, offset)
+#define ips_read_2(sc,offset) bus_read_2(sc->iores, offset)
+#define ips_read_4(sc,offset) bus_read_4(sc->iores, offset)
-#define ips_write_1(sc,offset,value) bus_space_write_1(sc->bustag, sc->bushandle, offset, value)
-#define ips_write_2(sc,offset,value) bus_space_write_2(sc->bustag, sc->bushandle, offset, value)
-#define ips_write_4(sc,offset,value) bus_space_write_4(sc->bustag, sc->bushandle, offset, value)
+#define ips_write_1(sc,offset,value) bus_write_1(sc->iores, offset, value)
+#define ips_write_2(sc,offset,value) bus_write_2(sc->iores, offset, value)
+#define ips_write_4(sc,offset,value) bus_write_4(sc->iores, offset, value)
/* this is ugly. It zeros the end elements in an ips_command_t struct starting with the status element */
#define clear_ips_command(command) bzero(&((command)->status), (unsigned long)(&(command)[1])-(unsigned long)&((command)->status))
@@ -122,14 +122,12 @@ typedef struct ips_softc{
int rid;
int irqrid;
void * irqcookie;
- bus_space_tag_t bustag;
- bus_space_handle_t bushandle;
bus_dma_tag_t adapter_dmatag;
bus_dma_tag_t command_dmatag;
bus_dma_tag_t sg_dmatag;
device_t dev;
struct cdev *device_file;
- struct callout_handle timer;
+ struct callout timer;
u_int16_t adapter_type;
ips_adapter_info_t adapter_info;
device_t diskdev[IPS_MAX_NUM_DRIVES];
diff --git a/sys/dev/ips/ips_pci.c b/sys/dev/ips/ips_pci.c
index df917ed..efffb32 100644
--- a/sys/dev/ips/ips_pci.c
+++ b/sys/dev/ips/ips_pci.c
@@ -61,20 +61,12 @@ static int ips_pci_attach(device_t dev)
{
ips_softc_t *sc;
-
- if (resource_disabled(device_get_name(dev), device_get_unit(dev))) {
- device_printf(dev, "device is disabled\n");
- /* but return 0 so the !$)$)*!$*) unit isn't reused */
- return (0);
- }
DEVICE_PRINTF(1, dev, "in attach.\n");
sc = (ips_softc_t *)device_get_softc(dev);
- if(!sc){
- printf("how is sc NULL?!\n");
- return (ENXIO);
- }
- bzero(sc, sizeof(ips_softc_t));
sc->dev = dev;
+ mtx_init(&sc->queue_mtx, "IPS bioqueue lock", NULL, MTX_DEF);
+ sema_init(&sc->cmd_sema, 0, "IPS Command Semaphore");
+ callout_init_mtx(&sc->timer, &sc->queue_mtx, 0);
if(pci_get_device(dev) == IPS_MORPHEUS_DEVICE_ID){
sc->ips_adapter_reinit = ips_morpheus_reinit;
@@ -95,7 +87,7 @@ static int ips_pci_attach(device_t dev)
goto error;
/* make sure busmastering is on */
pci_enable_busmaster(dev);
- /* seting up io space */
+ /* setting up io space */
sc->iores = NULL;
PRINTF(10, "trying MEMIO\n");
if(pci_get_device(dev) == IPS_COPPERHEAD_DEVICE_ID)
@@ -116,8 +108,6 @@ static int ips_pci_attach(device_t dev)
device_printf(dev, "resource allocation failed\n");
return (ENXIO);
}
- sc->bustag = rman_get_bustag(sc->iores);
- sc->bushandle = rman_get_bushandle(sc->iores);
/*allocate an interrupt. when does the irq become active? after leaving attach? */
sc->irqrid = 0;
if(!(sc->irqres = bus_alloc_resource_any(dev, SYS_RES_IRQ,
@@ -144,13 +134,11 @@ static int ips_pci_attach(device_t dev)
/* lockfunc */ NULL,
/* lockarg */ NULL,
&sc->adapter_dmatag) != 0) {
- printf("IPS can't alloc dma tag\n");
+ device_printf(dev, "can't alloc dma tag\n");
goto error;
}
sc->ips_ich.ich_func = ips_intrhook;
sc->ips_ich.ich_arg = sc;
- mtx_init(&sc->queue_mtx, "IPS bioqueue lock", NULL, MTX_DEF);
- sema_init(&sc->cmd_sema, 0, "IPS Command Semaphore");
bioq_init(&sc->queue);
if (config_intrhook_establish(&sc->ips_ich) != 0) {
printf("IPS can't establish configuration hook\n");
OpenPOWER on IntegriCloud