From owner-svn-src-head@FreeBSD.ORG Thu Nov 13 22:06:58 2014 Return-Path: Delivered-To: svn-src-head@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [8.8.178.115]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id DEDE4143; Thu, 13 Nov 2014 22:06:58 +0000 (UTC) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:1900:2254:2068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id CB8A3D1A; Thu, 13 Nov 2014 22:06:58 +0000 (UTC) Received: from svn.freebsd.org ([127.0.1.70]) by svn.freebsd.org (8.14.9/8.14.9) with ESMTP id sADM6w3F007485; Thu, 13 Nov 2014 22:06:58 GMT (envelope-from jhb@FreeBSD.org) Received: (from jhb@localhost) by svn.freebsd.org (8.14.9/8.14.9/Submit) id sADM6wGR007482; Thu, 13 Nov 2014 22:06:58 GMT (envelope-from jhb@FreeBSD.org) Message-Id: <201411132206.sADM6wGR007482@svn.freebsd.org> X-Authentication-Warning: svn.freebsd.org: jhb set sender to jhb@FreeBSD.org using -f From: John Baldwin Date: Thu, 13 Nov 2014 22:06:58 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r274488 - head/sys/dev/ips X-SVN-Group: head MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.18-1 Precedence: list List-Id: SVN commit messages for the src tree for head/-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 13 Nov 2014 22:06:59 -0000 Author: jhb Date: Thu Nov 13 22:06:57 2014 New Revision: 274488 URL: https://svnweb.freebsd.org/changeset/base/274488 Log: - 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 Modified: head/sys/dev/ips/ips.c head/sys/dev/ips/ips.h head/sys/dev/ips/ips_pci.c Modified: head/sys/dev/ips/ips.c ============================================================================== --- head/sys/dev/ips/ips.c Thu Nov 13 22:00:18 2014 (r274487) +++ head/sys/dev/ips/ips.c Thu Nov 13 22:06:57 2014 (r274488) @@ -41,7 +41,6 @@ MALLOC_DEFINE(M_IPSBUF, "ipsbuf","IPS dr 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); Modified: head/sys/dev/ips/ips.h ============================================================================== --- head/sys/dev/ips/ips.h Thu Nov 13 22:00:18 2014 (r274487) +++ head/sys/dev/ips/ips.h Thu Nov 13 22:06:57 2014 (r274488) @@ -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_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_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_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]; Modified: head/sys/dev/ips/ips_pci.c ============================================================================== --- head/sys/dev/ips/ips_pci.c Thu Nov 13 22:00:18 2014 (r274487) +++ head/sys/dev/ips/ips_pci.c Thu Nov 13 22:06:57 2014 (r274488) @@ -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");