ips.c (126080) | ips.c (126364) |
---|---|
1/*- 2 * Written by: David Jeffery 3 * Copyright (c) 2002 Adaptec Inc. 4 * All rights reserved. 5 * 6 * Redistribution and use in source and binary forms, with or without 7 * modification, are permitted provided that the following conditions 8 * are met: --- 12 unchanged lines hidden (view full) --- 21 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 22 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 23 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 24 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 25 * SUCH DAMAGE. 26 */ 27 28#include <sys/cdefs.h> | 1/*- 2 * Written by: David Jeffery 3 * Copyright (c) 2002 Adaptec Inc. 4 * All rights reserved. 5 * 6 * Redistribution and use in source and binary forms, with or without 7 * modification, are permitted provided that the following conditions 8 * are met: --- 12 unchanged lines hidden (view full) --- 21 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 22 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 23 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 24 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 25 * SUCH DAMAGE. 26 */ 27 28#include <sys/cdefs.h> |
29__FBSDID("$FreeBSD: head/sys/dev/ips/ips.c 126080 2004-02-21 21:10:55Z phk $"); | 29__FBSDID("$FreeBSD: head/sys/dev/ips/ips.c 126364 2004-02-28 19:14:41Z scottl $"); |
30 31#include <dev/ips/ips.h> 32#include <sys/stat.h> 33#include <sys/time.h> 34#include <machine/clock.h> 35 36static d_open_t ips_open; 37static d_close_t ips_close; --- 59 unchanged lines hidden (view full) --- 97 command->command_phys_addr = segments[0].ds_addr; 98 99} 100 101/* is locking needed? what locking guarentees are there on removal? */ 102static __inline__ int ips_cmdqueue_free(ips_softc_t *sc) 103{ 104 int i, error = -1; | 30 31#include <dev/ips/ips.h> 32#include <sys/stat.h> 33#include <sys/time.h> 34#include <machine/clock.h> 35 36static d_open_t ips_open; 37static d_close_t ips_close; --- 59 unchanged lines hidden (view full) --- 97 command->command_phys_addr = segments[0].ds_addr; 98 99} 100 101/* is locking needed? what locking guarentees are there on removal? */ 102static __inline__ int ips_cmdqueue_free(ips_softc_t *sc) 103{ 104 int i, error = -1; |
105 intrmask_t mask = splbio(); | 105 ips_command_t *command; 106 intrmask_t mask; 107 108 mask = splbio(); |
106 if(!sc->used_commands){ 107 for(i = 0; i < sc->max_cmds; i++){ | 109 if(!sc->used_commands){ 110 for(i = 0; i < sc->max_cmds; i++){ |
108 if(!(sc->commandarray[i].command_phys_addr)) | 111 112 command = &sc->commandarray[i]; 113 sema_destroy(&command->cmd_sema); 114 115 if(command->command_phys_addr == 0) |
109 continue; 110 bus_dmamap_unload(sc->command_dmatag, | 116 continue; 117 bus_dmamap_unload(sc->command_dmatag, |
111 sc->commandarray[i].command_dmamap); | 118 command->command_dmamap); |
112 bus_dmamem_free(sc->command_dmatag, | 119 bus_dmamem_free(sc->command_dmatag, |
113 sc->commandarray[i].command_buffer, 114 sc->commandarray[i].command_dmamap); | 120 command->command_buffer, 121 command->command_dmamap); |
115 } 116 error = 0; 117 sc->state |= IPS_OFFLINE; 118 } 119 splx(mask); 120 return error; 121} 122 123/* places all ips command structs on the free command queue. No locking as if someone else tries 124 * to access this during init, we have bigger problems */ 125static __inline__ int ips_cmdqueue_init(ips_softc_t *sc) 126{ 127 int i; 128 ips_command_t *command; 129 SLIST_INIT(&sc->free_cmd_list); 130 STAILQ_INIT(&sc->cmd_wait_list); 131 for(i = 0; i < sc->max_cmds; i++){ | 122 } 123 error = 0; 124 sc->state |= IPS_OFFLINE; 125 } 126 splx(mask); 127 return error; 128} 129 130/* places all ips command structs on the free command queue. No locking as if someone else tries 131 * to access this during init, we have bigger problems */ 132static __inline__ int ips_cmdqueue_init(ips_softc_t *sc) 133{ 134 int i; 135 ips_command_t *command; 136 SLIST_INIT(&sc->free_cmd_list); 137 STAILQ_INIT(&sc->cmd_wait_list); 138 for(i = 0; i < sc->max_cmds; i++){ |
132 sc->commandarray[i].id = i; 133 sc->commandarray[i].sc = sc; 134 SLIST_INSERT_HEAD(&sc->free_cmd_list, &sc->commandarray[i], 135 next); 136 } 137 for(i = 0; i < sc->max_cmds; i++){ | |
138 command = &sc->commandarray[i]; | 139 command = &sc->commandarray[i]; |
140 command->id = i; 141 command->sc = sc; 142 |
|
139 if(bus_dmamem_alloc(sc->command_dmatag,&command->command_buffer, 140 BUS_DMA_NOWAIT, &command->command_dmamap)) 141 goto error; 142 bus_dmamap_load(sc->command_dmatag, command->command_dmamap, 143 command->command_buffer,IPS_COMMAND_LEN, 144 ips_cmd_dmaload, command, BUS_DMA_NOWAIT); 145 if(!command->command_phys_addr){ 146 bus_dmamem_free(sc->command_dmatag, 147 command->command_buffer, command->command_dmamap); 148 goto error; 149 } | 143 if(bus_dmamem_alloc(sc->command_dmatag,&command->command_buffer, 144 BUS_DMA_NOWAIT, &command->command_dmamap)) 145 goto error; 146 bus_dmamap_load(sc->command_dmatag, command->command_dmamap, 147 command->command_buffer,IPS_COMMAND_LEN, 148 ips_cmd_dmaload, command, BUS_DMA_NOWAIT); 149 if(!command->command_phys_addr){ 150 bus_dmamem_free(sc->command_dmatag, 151 command->command_buffer, command->command_dmamap); 152 goto error; 153 } |
154 155 sema_init(&command->cmd_sema, 0, "IPS Command Semaphore"); 156 SLIST_INSERT_HEAD(&sc->free_cmd_list, command, next); |
|
150 } 151 sc->state &= ~IPS_OFFLINE; 152 return 0; 153error: | 157 } 158 sc->state &= ~IPS_OFFLINE; 159 return 0; 160error: |
154 ips_cmdqueue_free(sc); 155 return ENOMEM; | 161 ips_cmdqueue_free(sc); 162 return ENOMEM; |
156} 157 158static int ips_add_waiting_command(ips_softc_t *sc, int (*callback)(ips_command_t *), void *data, unsigned long flags) 159{ 160 intrmask_t mask; 161 ips_command_t *command; 162 ips_wait_list_t *waiter; 163 unsigned long memflags = 0; --- 85 unchanged lines hidden (view full) --- 249 return callback(command); 250} 251 252/* adds a command back to the free command queue */ 253void ips_insert_free_cmd(ips_softc_t *sc, ips_command_t *command) 254{ 255 intrmask_t mask; 256 mask = splbio(); | 163} 164 165static int ips_add_waiting_command(ips_softc_t *sc, int (*callback)(ips_command_t *), void *data, unsigned long flags) 166{ 167 intrmask_t mask; 168 ips_command_t *command; 169 ips_wait_list_t *waiter; 170 unsigned long memflags = 0; --- 85 unchanged lines hidden (view full) --- 256 return callback(command); 257} 258 259/* adds a command back to the free command queue */ 260void ips_insert_free_cmd(ips_softc_t *sc, ips_command_t *command) 261{ 262 intrmask_t mask; 263 mask = splbio(); |
264 265 if (sema_value(&command->cmd_sema) != 0) 266 panic("ips: command returned non-zero semaphore"); 267 |
|
257 SLIST_INSERT_HEAD(&sc->free_cmd_list, command, next); 258 (sc->used_commands)--; 259 splx(mask); 260 if(!(sc->state & IPS_TIMEOUT)) 261 ips_run_waiting_command(sc); 262} 263static const char* ips_diskdev_statename(u_int8_t state) 264{ --- 105 unchanged lines hidden (view full) --- 370 splx(mask); 371} 372 373/* check card and initialize it */ 374int ips_adapter_init(ips_softc_t *sc) 375{ 376 int i; 377 DEVICE_PRINTF(1,sc->dev, "initializing\n"); | 268 SLIST_INSERT_HEAD(&sc->free_cmd_list, command, next); 269 (sc->used_commands)--; 270 splx(mask); 271 if(!(sc->state & IPS_TIMEOUT)) 272 ips_run_waiting_command(sc); 273} 274static const char* ips_diskdev_statename(u_int8_t state) 275{ --- 105 unchanged lines hidden (view full) --- 381 splx(mask); 382} 383 384/* check card and initialize it */ 385int ips_adapter_init(ips_softc_t *sc) 386{ 387 int i; 388 DEVICE_PRINTF(1,sc->dev, "initializing\n"); |
389 |
|
378 if (bus_dma_tag_create( /* parent */ sc->adapter_dmatag, 379 /* alignemnt */ 1, 380 /* boundary */ 0, 381 /* lowaddr */ BUS_SPACE_MAXADDR_32BIT, 382 /* highaddr */ BUS_SPACE_MAXADDR, 383 /* filter */ NULL, 384 /* filterarg */ NULL, 385 /* maxsize */ IPS_COMMAND_LEN + --- 29 unchanged lines hidden (view full) --- 415 can handle */ 416 sc->max_cmds = 1; 417 ips_cmdqueue_init(sc); 418 callout_handle_init(&sc->timer); 419 420 if(sc->ips_adapter_reinit(sc, 0)) 421 goto error; 422 | 390 if (bus_dma_tag_create( /* parent */ sc->adapter_dmatag, 391 /* alignemnt */ 1, 392 /* boundary */ 0, 393 /* lowaddr */ BUS_SPACE_MAXADDR_32BIT, 394 /* highaddr */ BUS_SPACE_MAXADDR, 395 /* filter */ NULL, 396 /* filterarg */ NULL, 397 /* maxsize */ IPS_COMMAND_LEN + --- 29 unchanged lines hidden (view full) --- 427 can handle */ 428 sc->max_cmds = 1; 429 ips_cmdqueue_init(sc); 430 callout_handle_init(&sc->timer); 431 432 if(sc->ips_adapter_reinit(sc, 0)) 433 goto error; 434 |
423 mtx_init(&sc->cmd_mtx, "ips command mutex", NULL, MTX_DEF); 424 | |
425 /* initialize ffdc values */ 426 microtime(&sc->ffdc_resettime); 427 sc->ffdc_resetcount = 1; 428 if ((i = ips_ffdc_reset(sc)) != 0) { 429 device_printf(sc->dev, "failed to send ffdc reset to device (%d)\n", i); 430 goto error; 431 } 432 if ((i = ips_get_adapter_info(sc)) != 0) { --- 96 unchanged lines hidden (view full) --- 529 device_printf(sc->dev, 530 "trying to exit when command queue is not empty!\n"); 531 return EBUSY; 532 } 533 DEVICE_PRINTF(1, sc->dev, "free\n"); 534 mask = splbio(); 535 untimeout(ips_timeout, sc, sc->timer); 536 splx(mask); | 435 /* initialize ffdc values */ 436 microtime(&sc->ffdc_resettime); 437 sc->ffdc_resetcount = 1; 438 if ((i = ips_ffdc_reset(sc)) != 0) { 439 device_printf(sc->dev, "failed to send ffdc reset to device (%d)\n", i); 440 goto error; 441 } 442 if ((i = ips_get_adapter_info(sc)) != 0) { --- 96 unchanged lines hidden (view full) --- 539 device_printf(sc->dev, 540 "trying to exit when command queue is not empty!\n"); 541 return EBUSY; 542 } 543 DEVICE_PRINTF(1, sc->dev, "free\n"); 544 mask = splbio(); 545 untimeout(ips_timeout, sc, sc->timer); 546 splx(mask); |
537 if (mtx_initialized(&sc->cmd_mtx)) 538 mtx_destroy(&sc->cmd_mtx); | |
539 540 if(sc->sg_dmatag) 541 bus_dma_tag_destroy(sc->sg_dmatag); 542 if(sc->command_dmatag) 543 bus_dma_tag_destroy(sc->command_dmatag); 544 if(sc->device_file) 545 destroy_dev(sc->device_file); 546 return 0; --- 225 unchanged lines hidden --- | 547 548 if(sc->sg_dmatag) 549 bus_dma_tag_destroy(sc->sg_dmatag); 550 if(sc->command_dmatag) 551 bus_dma_tag_destroy(sc->command_dmatag); 552 if(sc->device_file) 553 destroy_dev(sc->device_file); 554 return 0; --- 225 unchanged lines hidden --- |