Deleted Added
full compact
tw_osl_freebsd.c (151897) tw_osl_freebsd.c (152213)
1/*
2 * Copyright (c) 2004-05 Applied Micro Circuits Corporation.
3 * Copyright (c) 2004-05 Vinod Kashyap.
4 * Copyright (c) 2000 Michael Smith
5 * Copyright (c) 2000 BSDi
6 * All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without

--- 12 unchanged lines hidden (view full) ---

21 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27 * SUCH DAMAGE.
28 *
1/*
2 * Copyright (c) 2004-05 Applied Micro Circuits Corporation.
3 * Copyright (c) 2004-05 Vinod Kashyap.
4 * Copyright (c) 2000 Michael Smith
5 * Copyright (c) 2000 BSDi
6 * All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without

--- 12 unchanged lines hidden (view full) ---

21 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27 * SUCH DAMAGE.
28 *
29 * $FreeBSD: head/sys/dev/twa/tw_osl_freebsd.c 151897 2005-10-31 15:41:29Z rwatson $
29 * $FreeBSD: head/sys/dev/twa/tw_osl_freebsd.c 152213 2005-11-08 22:51:43Z vkashyap $
30 */
31
32/*
33 * AMCC'S 3ware driver for 9000 series storage controllers.
34 *
35 * Author: Vinod Kashyap
36 */
37

--- 132 unchanged lines hidden (view full) ---

170
171
172static TW_INT32 twa_probe(device_t dev);
173static TW_INT32 twa_attach(device_t dev);
174static TW_INT32 twa_detach(device_t dev);
175static TW_INT32 twa_shutdown(device_t dev);
176static TW_VOID twa_busdma_lock(TW_VOID *lock_arg, bus_dma_lock_op_t op);
177static TW_VOID twa_pci_intr(TW_VOID *arg);
30 */
31
32/*
33 * AMCC'S 3ware driver for 9000 series storage controllers.
34 *
35 * Author: Vinod Kashyap
36 */
37

--- 132 unchanged lines hidden (view full) ---

170
171
172static TW_INT32 twa_probe(device_t dev);
173static TW_INT32 twa_attach(device_t dev);
174static TW_INT32 twa_detach(device_t dev);
175static TW_INT32 twa_shutdown(device_t dev);
176static TW_VOID twa_busdma_lock(TW_VOID *lock_arg, bus_dma_lock_op_t op);
177static TW_VOID twa_pci_intr(TW_VOID *arg);
178#ifdef TW_OSLI_DEFERRED_INTR_USED
178static TW_VOID twa_deferred_intr(TW_VOID *context, TW_INT32 pending);
179static TW_VOID twa_deferred_intr(TW_VOID *context, TW_INT32 pending);
180#endif /* TW_OSLI_DEFERRED_INTR_USED */
179
180static TW_INT32 tw_osli_alloc_mem(struct twa_softc *sc);
181static TW_VOID tw_osli_free_resources(struct twa_softc *sc);
182
183static TW_VOID twa_map_load_data_callback(TW_VOID *arg,
184 bus_dma_segment_t *segs, TW_INT32 nsegments, TW_INT32 error);
185static TW_VOID twa_map_load_callback(TW_VOID *arg,
186 bus_dma_segment_t *segs, TW_INT32 nsegments, TW_INT32 error);

--- 65 unchanged lines hidden (view full) ---

252 * Return value: 0 -- success
253 * non-zero-- failure
254 */
255static TW_INT32
256twa_attach(device_t dev)
257{
258 struct twa_softc *sc = device_get_softc(dev);
259 TW_UINT32 command;
181
182static TW_INT32 tw_osli_alloc_mem(struct twa_softc *sc);
183static TW_VOID tw_osli_free_resources(struct twa_softc *sc);
184
185static TW_VOID twa_map_load_data_callback(TW_VOID *arg,
186 bus_dma_segment_t *segs, TW_INT32 nsegments, TW_INT32 error);
187static TW_VOID twa_map_load_callback(TW_VOID *arg,
188 bus_dma_segment_t *segs, TW_INT32 nsegments, TW_INT32 error);

--- 65 unchanged lines hidden (view full) ---

254 * Return value: 0 -- success
255 * non-zero-- failure
256 */
257static TW_INT32
258twa_attach(device_t dev)
259{
260 struct twa_softc *sc = device_get_softc(dev);
261 TW_UINT32 command;
262 TW_INT32 bar_num;
263 TW_INT32 bar0_offset;
264 TW_INT32 bar_size;
260 TW_INT32 error;
261
262 tw_osli_dbg_dprintf(3, sc, "entered");
263
264 sc->ctlr_handle.osl_ctlr_ctxt = sc;
265
266 /* Initialize the softc structure. */
267 sc->bus_dev = dev;
265 TW_INT32 error;
266
267 tw_osli_dbg_dprintf(3, sc, "entered");
268
269 sc->ctlr_handle.osl_ctlr_ctxt = sc;
270
271 /* Initialize the softc structure. */
272 sc->bus_dev = dev;
273 sc->device_id = pci_get_device(dev);
268
269 /* Initialize the mutexes right here. */
270 sc->io_lock = &(sc->io_lock_handle);
271 mtx_init(sc->io_lock, "tw_osl_io_lock", NULL, MTX_SPIN);
272 sc->q_lock = &(sc->q_lock_handle);
273 mtx_init(sc->q_lock, "tw_osl_q_lock", NULL, MTX_SPIN);
274
275 sysctl_ctx_init(&sc->sysctl_ctxt);

--- 26 unchanged lines hidden (view full) ---

302 return(ENXIO);
303 }
304
305 /* Force the busmaster enable bit on, in case the BIOS forgot. */
306 command |= PCIM_CMD_BUSMASTEREN;
307 pci_write_config(dev, PCIR_COMMAND, command, 2);
308
309 /* Allocate the PCI register window. */
274
275 /* Initialize the mutexes right here. */
276 sc->io_lock = &(sc->io_lock_handle);
277 mtx_init(sc->io_lock, "tw_osl_io_lock", NULL, MTX_SPIN);
278 sc->q_lock = &(sc->q_lock_handle);
279 mtx_init(sc->q_lock, "tw_osl_q_lock", NULL, MTX_SPIN);
280
281 sysctl_ctx_init(&sc->sysctl_ctxt);

--- 26 unchanged lines hidden (view full) ---

308 return(ENXIO);
309 }
310
311 /* Force the busmaster enable bit on, in case the BIOS forgot. */
312 command |= PCIM_CMD_BUSMASTEREN;
313 pci_write_config(dev, PCIR_COMMAND, command, 2);
314
315 /* Allocate the PCI register window. */
310 sc->reg_res_id = PCIR_BARS;
311 if ((sc->reg_res = bus_alloc_resource(dev, SYS_RES_IOPORT,
316 if ((error = tw_cl_get_pci_bar_info(sc->device_id, TW_CL_BAR_TYPE_MEM,
317 &bar_num, &bar0_offset, &bar_size))) {
318 tw_osli_printf(sc, "error = %d",
319 TW_CL_SEVERITY_ERROR_STRING,
320 TW_CL_MESSAGE_SOURCE_FREEBSD_DRIVER,
321 0x201F,
322 "Can't get PCI BAR info",
323 error);
324 tw_osli_free_resources(sc);
325 return(error);
326 }
327 sc->reg_res_id = PCIR_BARS + bar0_offset;
328 if ((sc->reg_res = bus_alloc_resource(dev, SYS_RES_MEMORY,
312 &(sc->reg_res_id), 0, ~0, 1, RF_ACTIVE))
313 == NULL) {
314 tw_osli_printf(sc, "error = %d",
315 TW_CL_SEVERITY_ERROR_STRING,
316 TW_CL_MESSAGE_SOURCE_FREEBSD_DRIVER,
317 0x2002,
318 "Can't allocate register window",
319 ENXIO);

--- 13 unchanged lines hidden (view full) ---

333 TW_CL_MESSAGE_SOURCE_FREEBSD_DRIVER,
334 0x2003,
335 "Can't allocate interrupt",
336 ENXIO);
337 tw_osli_free_resources(sc);
338 return(ENXIO);
339 }
340 if ((error = bus_setup_intr(sc->bus_dev, sc->irq_res,
329 &(sc->reg_res_id), 0, ~0, 1, RF_ACTIVE))
330 == NULL) {
331 tw_osli_printf(sc, "error = %d",
332 TW_CL_SEVERITY_ERROR_STRING,
333 TW_CL_MESSAGE_SOURCE_FREEBSD_DRIVER,
334 0x2002,
335 "Can't allocate register window",
336 ENXIO);

--- 13 unchanged lines hidden (view full) ---

350 TW_CL_MESSAGE_SOURCE_FREEBSD_DRIVER,
351 0x2003,
352 "Can't allocate interrupt",
353 ENXIO);
354 tw_osli_free_resources(sc);
355 return(ENXIO);
356 }
357 if ((error = bus_setup_intr(sc->bus_dev, sc->irq_res,
341 ((mp_ncpus > 1) ? (INTR_MPSAFE | INTR_FAST) : 0) |
342 INTR_TYPE_CAM,
358 ((mp_ncpus > 1) ? (INTR_MPSAFE
359#ifdef TW_OSLI_DEFERRED_INTR_USED
360 | INTR_FAST
361#endif /* TW_OSLI_DEFERRED_INTR_USED */
362 ) : 0) | INTR_TYPE_CAM,
343 twa_pci_intr, sc, &sc->intr_handle))) {
344 tw_osli_printf(sc, "error = %d",
345 TW_CL_SEVERITY_ERROR_STRING,
346 TW_CL_MESSAGE_SOURCE_FREEBSD_DRIVER,
347 0x2004,
348 "Can't set up interrupt",
349 error);
350 tw_osli_free_resources(sc);
351 return(error);
352 }
353
363 twa_pci_intr, sc, &sc->intr_handle))) {
364 tw_osli_printf(sc, "error = %d",
365 TW_CL_SEVERITY_ERROR_STRING,
366 TW_CL_MESSAGE_SOURCE_FREEBSD_DRIVER,
367 0x2004,
368 "Can't set up interrupt",
369 error);
370 tw_osli_free_resources(sc);
371 return(error);
372 }
373
374#ifdef TW_OSLI_DEFERRED_INTR_USED
354 TASK_INIT(&sc->deferred_intr_callback, 0, twa_deferred_intr, sc);
375 TASK_INIT(&sc->deferred_intr_callback, 0, twa_deferred_intr, sc);
376#endif /* TW_OSLI_DEFERRED_INTR_USED */
355
356 if ((error = tw_osli_alloc_mem(sc))) {
357 tw_osli_printf(sc, "error = %d",
358 TW_CL_SEVERITY_ERROR_STRING,
359 TW_CL_MESSAGE_SOURCE_FREEBSD_DRIVER,
360 0x2005,
361 "Memory allocation failure",
362 error);
363 tw_osli_free_resources(sc);
364 return(error);
365 }
366
367 /* Initialize the Common Layer for this controller. */
377
378 if ((error = tw_osli_alloc_mem(sc))) {
379 tw_osli_printf(sc, "error = %d",
380 TW_CL_SEVERITY_ERROR_STRING,
381 TW_CL_MESSAGE_SOURCE_FREEBSD_DRIVER,
382 0x2005,
383 "Memory allocation failure",
384 error);
385 tw_osli_free_resources(sc);
386 return(error);
387 }
388
389 /* Initialize the Common Layer for this controller. */
368 if ((error = tw_cl_init_ctlr(&sc->ctlr_handle, sc->flags,
390 if ((error = tw_cl_init_ctlr(&sc->ctlr_handle, sc->flags, sc->device_id,
369 TW_OSLI_MAX_NUM_IOS, TW_OSLI_MAX_NUM_AENS,
370 sc->non_dma_mem, sc->dma_mem,
371 sc->dma_mem_phys
372#ifdef TW_OSL_FLASH_FIRMWARE
373 , sc->flash_dma_mem, sc->flash_dma_mem_phys
374#endif /* TW_OSL_FLASH_FIRMWARE */
375 ))) {
376 tw_osli_printf(sc, "error = %d",

--- 72 unchanged lines hidden (view full) ---

449
450 tw_osli_dbg_dprintf(3, sc, "entered");
451
452 sc->flags |= (sizeof(bus_addr_t) == 8) ? TW_CL_64BIT_ADDRESSES : 0;
453 sc->flags |= (sizeof(bus_size_t) == 8) ? TW_CL_64BIT_SG_LENGTH : 0;
454#ifdef TW_OSL_FLASH_FIRMWARE
455 sc->flags |= TW_CL_FLASH_FIRMWARE;
456#endif /* TW_OSL_FLASH_FIRMWARE */
391 TW_OSLI_MAX_NUM_IOS, TW_OSLI_MAX_NUM_AENS,
392 sc->non_dma_mem, sc->dma_mem,
393 sc->dma_mem_phys
394#ifdef TW_OSL_FLASH_FIRMWARE
395 , sc->flash_dma_mem, sc->flash_dma_mem_phys
396#endif /* TW_OSL_FLASH_FIRMWARE */
397 ))) {
398 tw_osli_printf(sc, "error = %d",

--- 72 unchanged lines hidden (view full) ---

471
472 tw_osli_dbg_dprintf(3, sc, "entered");
473
474 sc->flags |= (sizeof(bus_addr_t) == 8) ? TW_CL_64BIT_ADDRESSES : 0;
475 sc->flags |= (sizeof(bus_size_t) == 8) ? TW_CL_64BIT_SG_LENGTH : 0;
476#ifdef TW_OSL_FLASH_FIRMWARE
477 sc->flags |= TW_CL_FLASH_FIRMWARE;
478#endif /* TW_OSL_FLASH_FIRMWARE */
479#ifdef TW_OSLI_DEFERRED_INTR_USED
480 sc->flags |= TW_CL_DEFERRED_INTR_USED;
481#endif /* TW_OSLI_DEFERRED_INTR_USED */
457
458 max_sg_elements = (sizeof(bus_addr_t) == 8) ?
459 TW_CL_MAX_64BIT_SG_ELEMENTS : TW_CL_MAX_32BIT_SG_ELEMENTS;
460
461 if ((error = tw_cl_get_mem_requirements(&sc->ctlr_handle, sc->flags,
482
483 max_sg_elements = (sizeof(bus_addr_t) == 8) ?
484 TW_CL_MAX_64BIT_SG_ELEMENTS : TW_CL_MAX_32BIT_SG_ELEMENTS;
485
486 if ((error = tw_cl_get_mem_requirements(&sc->ctlr_handle, sc->flags,
462 TW_OSLI_MAX_NUM_IOS, TW_OSLI_MAX_NUM_AENS,
487 sc->device_id, TW_OSLI_MAX_NUM_IOS, TW_OSLI_MAX_NUM_AENS,
463 &(sc->alignment), &(sc->sg_size_factor),
464 &non_dma_mem_size, &dma_mem_size
465#ifdef TW_OSL_FLASH_FIRMWARE
466 , &flash_dma_mem_size
467#endif /* TW_OSL_FLASH_FIRMWARE */
468#ifdef TW_OSL_DMA_MEM_ALLOC_PER_REQUEST
469 , &per_req_dma_mem_size
470#endif /* TW_OSL_DMA_MEM_ALLOC_PER_REQUEST */

--- 281 unchanged lines hidden (view full) ---

752 while ((req = tw_osli_req_q_remove_head(sc, TW_OSLI_FREE_Q)) !=
753 NULL)
754 if ((error = bus_dmamap_destroy(sc->dma_tag,
755 req->dma_map)))
756 tw_osli_dbg_dprintf(1, sc,
757 "dmamap_destroy(dma) returned %d",
758 error);
759
488 &(sc->alignment), &(sc->sg_size_factor),
489 &non_dma_mem_size, &dma_mem_size
490#ifdef TW_OSL_FLASH_FIRMWARE
491 , &flash_dma_mem_size
492#endif /* TW_OSL_FLASH_FIRMWARE */
493#ifdef TW_OSL_DMA_MEM_ALLOC_PER_REQUEST
494 , &per_req_dma_mem_size
495#endif /* TW_OSL_DMA_MEM_ALLOC_PER_REQUEST */

--- 281 unchanged lines hidden (view full) ---

777 while ((req = tw_osli_req_q_remove_head(sc, TW_OSLI_FREE_Q)) !=
778 NULL)
779 if ((error = bus_dmamap_destroy(sc->dma_tag,
780 req->dma_map)))
781 tw_osli_dbg_dprintf(1, sc,
782 "dmamap_destroy(dma) returned %d",
783 error);
784
760 if ((error = bus_dmamap_destroy(sc->ioctl_tag, sc->ioctl_map)))
761 tw_osli_dbg_dprintf(1, sc,
762 "dmamap_destroy(ioctl) returned %d", error);
785 if ((sc->ioctl_tag) && (sc->ioctl_map))
786 if ((error = bus_dmamap_destroy(sc->ioctl_tag, sc->ioctl_map)))
787 tw_osli_dbg_dprintf(1, sc,
788 "dmamap_destroy(ioctl) returned %d", error);
763
764 /* Free all memory allocated so far. */
765 if (sc->req_ctxt_buf)
766 free(sc->req_ctxt_buf, TW_OSLI_MALLOC_CLASS);
767
768 if (sc->non_dma_mem)
769 free(sc->non_dma_mem, TW_OSLI_MALLOC_CLASS);
770

--- 51 unchanged lines hidden (view full) ---

822 SYS_RES_IRQ, sc->irq_res_id, sc->irq_res)))
823 tw_osli_dbg_dprintf(1, sc,
824 "release_resource(irq) returned %d", error);
825
826
827 /* Release the register window mapping. */
828 if (sc->reg_res != NULL)
829 if ((error = bus_release_resource(sc->bus_dev,
789
790 /* Free all memory allocated so far. */
791 if (sc->req_ctxt_buf)
792 free(sc->req_ctxt_buf, TW_OSLI_MALLOC_CLASS);
793
794 if (sc->non_dma_mem)
795 free(sc->non_dma_mem, TW_OSLI_MALLOC_CLASS);
796

--- 51 unchanged lines hidden (view full) ---

848 SYS_RES_IRQ, sc->irq_res_id, sc->irq_res)))
849 tw_osli_dbg_dprintf(1, sc,
850 "release_resource(irq) returned %d", error);
851
852
853 /* Release the register window mapping. */
854 if (sc->reg_res != NULL)
855 if ((error = bus_release_resource(sc->bus_dev,
830 SYS_RES_IOPORT, sc->reg_res_id, sc->reg_res)))
856 SYS_RES_MEMORY, sc->reg_res_id, sc->reg_res)))
831 tw_osli_dbg_dprintf(1, sc,
832 "release_resource(io) returned %d", error);
833
834
835 /* Destroy the control device. */
836 if (sc->ctrl_dev != (struct cdev *)NULL)
837 destroy_dev(sc->ctrl_dev);
838

--- 121 unchanged lines hidden (view full) ---

960 */
961static TW_VOID
962twa_pci_intr(TW_VOID *arg)
963{
964 struct twa_softc *sc = (struct twa_softc *)arg;
965
966 tw_osli_dbg_dprintf(10, sc, "entered");
967 if (tw_cl_interrupt(&(sc->ctlr_handle)))
857 tw_osli_dbg_dprintf(1, sc,
858 "release_resource(io) returned %d", error);
859
860
861 /* Destroy the control device. */
862 if (sc->ctrl_dev != (struct cdev *)NULL)
863 destroy_dev(sc->ctrl_dev);
864

--- 121 unchanged lines hidden (view full) ---

986 */
987static TW_VOID
988twa_pci_intr(TW_VOID *arg)
989{
990 struct twa_softc *sc = (struct twa_softc *)arg;
991
992 tw_osli_dbg_dprintf(10, sc, "entered");
993 if (tw_cl_interrupt(&(sc->ctlr_handle)))
994#ifdef TW_OSLI_DEFERRED_INTR_USED
968 taskqueue_enqueue_fast(taskqueue_fast,
969 &(sc->deferred_intr_callback));
995 taskqueue_enqueue_fast(taskqueue_fast,
996 &(sc->deferred_intr_callback));
997#else /* TW_OSLI_DEFERRED_INTR_USED */
998 tw_cl_deferred_interrupt(&(sc->ctlr_handle));
999#endif /* TW_OSLI_DEFERRED_INTR_USED */
970}
971
972
973
1000}
1001
1002
1003
1004#ifdef TW_OSLI_DEFERRED_INTR_USED
1005
974/*
975 * Function name: twa_deferred_intr
976 * Description: Deferred interrupt handler.
977 *
978 * Input: context -- ptr to OSL internal ctlr context
979 * pending -- not used
980 * Output: None
981 * Return value: None
982 */
983static TW_VOID
984twa_deferred_intr(TW_VOID *context, TW_INT32 pending)
985{
986 struct twa_softc *sc = (struct twa_softc *)context;
987
988 tw_osli_dbg_dprintf(10, sc, "entered");
989
990 tw_cl_deferred_interrupt(&(sc->ctlr_handle));
991}
992
1006/*
1007 * Function name: twa_deferred_intr
1008 * Description: Deferred interrupt handler.
1009 *
1010 * Input: context -- ptr to OSL internal ctlr context
1011 * pending -- not used
1012 * Output: None
1013 * Return value: None
1014 */
1015static TW_VOID
1016twa_deferred_intr(TW_VOID *context, TW_INT32 pending)
1017{
1018 struct twa_softc *sc = (struct twa_softc *)context;
1019
1020 tw_osli_dbg_dprintf(10, sc, "entered");
1021
1022 tw_cl_deferred_interrupt(&(sc->ctlr_handle));
1023}
1024
1025#endif /* TW_OSLI_DEFERRED_INTR_USED */
993
994
1026
1027
1028
995/*
996 * Function name: tw_osli_fw_passthru
997 * Description: Builds a fw passthru cmd pkt, and submits it to CL.
998 *
999 * Input: sc -- ptr to OSL internal ctlr context
1000 * buf -- ptr to ioctl pkt understood by CL
1001 * Output: None
1002 * Return value: 0 -- success

--- 725 unchanged lines hidden (view full) ---

1728 for (i = 0; (sc = devclass_get_softc(twa_devclass, i)) != NULL; i++) {
1729 sc->q_stats[TW_OSLI_FREE_Q].max_len = 0;
1730 sc->q_stats[TW_OSLI_BUSY_Q].max_len = 0;
1731 tw_cl_reset_stats(&sc->ctlr_handle);
1732 }
1733}
1734
1735#endif /* TW_OSL_DEBUG */
1029/*
1030 * Function name: tw_osli_fw_passthru
1031 * Description: Builds a fw passthru cmd pkt, and submits it to CL.
1032 *
1033 * Input: sc -- ptr to OSL internal ctlr context
1034 * buf -- ptr to ioctl pkt understood by CL
1035 * Output: None
1036 * Return value: 0 -- success

--- 725 unchanged lines hidden (view full) ---

1762 for (i = 0; (sc = devclass_get_softc(twa_devclass, i)) != NULL; i++) {
1763 sc->q_stats[TW_OSLI_FREE_Q].max_len = 0;
1764 sc->q_stats[TW_OSLI_BUSY_Q].max_len = 0;
1765 tw_cl_reset_stats(&sc->ctlr_handle);
1766 }
1767}
1768
1769#endif /* TW_OSL_DEBUG */
1736
1737
1738
1739#ifdef TW_OSL_DEBUG
1740
1741/*
1742 * Function name: tw_osl_dbg_printf
1743 * Description: Prints passed info (prefixed by ctlr name)to syslog
1744 *
1745 * Input: ctlr_handle -- controller handle
1746 * fmt -- format string for the arguments to follow
1747 * ... -- variable number of arguments, to be printed
1748 * based on the fmt string
1749 * Output: None
1750 * Return value: Number of bytes printed
1751 */
1752TW_INT32
1753tw_osl_dbg_printf(struct tw_cl_ctlr_handle *ctlr_handle,
1754 const TW_INT8 *fmt, ...)
1755{
1756 va_list args;
1757 TW_INT32 bytes_printed;
1758
1759 bytes_printed = device_print_prettyname(((struct twa_softc *)
1760 (ctlr_handle->osl_ctlr_ctxt))->bus_dev);
1761 va_start(args, fmt);
1762 bytes_printed += vprintf(fmt, args);
1763 va_end(args);
1764 return(bytes_printed);
1765}
1766
1767#endif /* TW_OSL_DEBUG */
1768
1769
1770
1771/*
1772 * Function name: tw_osl_notify_event
1773 * Description: Prints passed event info (prefixed by ctlr name)
1774 * to syslog
1775 *
1776 * Input: ctlr_handle -- controller handle
1777 * event -- ptr to a packet describing the event/error
1778 * Output: None
1779 * Return value: None
1780 */
1781TW_VOID
1782tw_osl_notify_event(struct tw_cl_ctlr_handle *ctlr_handle,
1783 struct tw_cl_event_packet *event)
1784{
1785 struct twa_softc *sc =
1786 (struct twa_softc *)(ctlr_handle->osl_ctlr_ctxt);
1787
1788 twa_printf(sc, "%s: (0x%02X: 0x%04X): %s: %s\n",
1789 event->severity_str,
1790 event->event_src,
1791 event->aen_code,
1792 event->parameter_data +
1793 strlen(event->parameter_data) + 1,
1794 event->parameter_data);
1795}
1796
1797
1798
1799/*
1800 * Function name: tw_osl_read_reg
1801 * Description: Reads a register on the controller
1802 *
1803 * Input: ctlr_handle -- controller handle
1804 * offset -- offset from Base Address
1805 * size -- # of bytes to read
1806 * Output: None
1807 * Return value: Value read
1808 */
1809TW_UINT32
1810tw_osl_read_reg(struct tw_cl_ctlr_handle *ctlr_handle,
1811 TW_INT32 offset, TW_INT32 size)
1812{
1813 bus_space_tag_t bus_tag =
1814 ((struct twa_softc *)(ctlr_handle->osl_ctlr_ctxt))->bus_tag;
1815 bus_space_handle_t bus_handle =
1816 ((struct twa_softc *)(ctlr_handle->osl_ctlr_ctxt))->bus_handle;
1817
1818 if (size == 4)
1819 return((TW_UINT32)bus_space_read_4(bus_tag, bus_handle,
1820 offset));
1821 else if (size == 2)
1822 return((TW_UINT32)bus_space_read_2(bus_tag, bus_handle,
1823 offset));
1824 else
1825 return((TW_UINT32)bus_space_read_1(bus_tag, bus_handle,
1826 offset));
1827}
1828
1829
1830
1831/*
1832 * Function name: tw_osl_write_reg
1833 * Description: Writes to a register on the controller
1834 *
1835 * Input: ctlr_handle -- controller handle
1836 * offset -- offset from Base Address
1837 * value -- value to write
1838 * size -- # of bytes to write
1839 * Output: None
1840 * Return value: None
1841 */
1842TW_VOID
1843tw_osl_write_reg(struct tw_cl_ctlr_handle *ctlr_handle,
1844 TW_INT32 offset, TW_INT32 value, TW_INT32 size)
1845{
1846 bus_space_tag_t bus_tag =
1847 ((struct twa_softc *)(ctlr_handle->osl_ctlr_ctxt))->bus_tag;
1848 bus_space_handle_t bus_handle =
1849 ((struct twa_softc *)(ctlr_handle->osl_ctlr_ctxt))->bus_handle;
1850
1851 if (size == 4)
1852 bus_space_write_4(bus_tag, bus_handle, offset, value);
1853 else if (size == 2)
1854 bus_space_write_2(bus_tag, bus_handle, offset, (TW_INT16)value);
1855 else
1856 bus_space_write_1(bus_tag, bus_handle, offset, (TW_INT8)value);
1857}
1858
1859
1860#ifdef TW_OSL_PCI_CONFIG_ACCESSIBLE
1861
1862/*
1863 * Function name: tw_osl_read_pci_config
1864 * Description: Reads from the PCI config space.
1865 *
1866 * Input: sc -- ptr to per ctlr structure
1867 * offset -- register offset
1868 * size -- # of bytes to be read
1869 * Output: None
1870 * Return value: Value read
1871 */
1872TW_UINT32
1873tw_osl_read_pci_config(struct tw_cl_ctlr_handle *ctlr_handle,
1874 TW_INT32 offset, TW_INT32 size)
1875{
1876 struct twa_softc *sc =
1877 (struct twa_softc *)(ctlr_handle->osl_ctlr_ctxt);
1878
1879 tw_osli_dbg_dprintf(1, sc, "entered");
1880 return(pci_read_config(sc->bus_dev, offset, size));
1881}
1882
1883/*
1884 * Function name: tw_osl_write_pci_config
1885 * Description: Writes to the PCI config space.
1886 *
1887 * Input: sc -- ptr to per ctlr structure
1888 * offset -- register offset
1889 * value -- value to write
1890 * size -- # of bytes to be written
1891 * Output: None
1892 * Return value: None
1893 */
1894TW_VOID
1895tw_osl_write_pci_config(struct tw_cl_ctlr_handle *ctlr_handle,
1896 TW_INT32 offset, TW_INT32 value, TW_INT32 size)
1897{
1898 struct twa_softc *sc =
1899 (struct twa_softc *)(ctlr_handle->osl_ctlr_ctxt);
1900
1901 tw_osli_dbg_dprintf(1, sc, "entered");
1902 pci_write_config(sc->bus_dev, offset/*PCIR_STATUS*/, value, size);
1903}
1904
1905#endif /* TW_OSL_PCI_CONFIG_ACCESSIBLE */
1906
1907
1908
1909/*
1910 * Function name: tw_osl_get_local_time
1911 * Description: Gets the local time
1912 *
1913 * Input: None
1914 * Output: None
1915 * Return value: local time
1916 */
1917TW_TIME
1918tw_osl_get_local_time()
1919{
1920 return(time_second - (tz_minuteswest * 60) -
1921 (wall_cmos_clock ? adjkerntz : 0));
1922}
1923
1924
1925
1926/*
1927 * Function name: tw_osl_delay
1928 * Description: Spin for the specified time
1929 *
1930 * Input: usecs -- micro-seconds to spin
1931 * Output: None
1932 * Return value: None
1933 */
1934TW_VOID
1935tw_osl_delay(TW_INT32 usecs)
1936{
1937 DELAY(usecs);
1938}
1939
1940
1941
1942#ifdef TW_OSL_CAN_SLEEP
1943
1944/*
1945 * Function name: tw_osl_sleep
1946 * Description: Sleep for the specified time, or until woken up
1947 *
1948 * Input: ctlr_handle -- controller handle
1949 * sleep_handle -- handle to sleep on
1950 * timeout -- time period (in ms) to sleep
1951 * Output: None
1952 * Return value: 0 -- successfully woken up
1953 * EWOULDBLOCK -- time out
1954 * ERESTART -- woken up by a signal
1955 */
1956TW_INT32
1957tw_osl_sleep(struct tw_cl_ctlr_handle *ctlr_handle,
1958 TW_SLEEP_HANDLE *sleep_handle, TW_INT32 timeout)
1959{
1960 return(tsleep((TW_VOID *)sleep_handle, PRIBIO, NULL, timeout));
1961}
1962
1963
1964
1965/*
1966 * Function name: tw_osl_wakeup
1967 * Description: Wake up a sleeping process
1968 *
1969 * Input: ctlr_handle -- controller handle
1970 * sleep_handle -- handle of sleeping process to be
1971 woken up
1972 * Output: None
1973 * Return value: None
1974 */
1975TW_VOID
1976tw_osl_wakeup(struct tw_cl_ctlr_handle *ctlr_handle,
1977 TW_SLEEP_HANDLE *sleep_handle)
1978{
1979 wakeup_one(sleep_handle);
1980}
1981
1982#endif /* TW_OSL_CAN_SLEEP */
1983