- 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
This commit is contained in:
John Baldwin 2014-11-13 22:06:57 +00:00
parent 7ff829cb0e
commit 352176c8cb
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=274488
3 changed files with 21 additions and 33 deletions

View File

@ -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);

View File

@ -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];

View File

@ -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");