1 /* $NetBSD: aic7xxx_osm.h,v 1.23 2009/05/12 14:25:17 cegger Exp $ */
4 * NetBSD platform specific driver option settings, data structures,
5 * function declarations and includes.
7 * Copyright (c) 1994-2001 Justin T. Gibbs.
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions, and the following disclaimer,
15 * without modification.
16 * 2. The name of the author may not be used to endorse or promote products
17 * derived from this software without specific prior written permission.
19 * Alternatively, this software may be distributed under the terms of the
20 * GNU Public License ("GPL").
22 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
23 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
25 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR
26 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
27 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
28 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
29 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
31 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
34 * //depot/aic7xxx/freebsd/dev/aic7xxx/aic7xxx_osm.h#14 $
36 * $FreeBSD: /repoman/r/ncvs/src/sys/dev/aic7xxx/aic7xxx_osm.h,v 1.20 2002/12/04 22:51:29 scottl Exp $
39 * Ported from FreeBSD by Pascal Renauld, Network Storage Solutions, Inc. - April 2003
42 #ifndef _AIC7XXX_NETBSD_H_
43 #define _AIC7XXX_NETBSD_H_
45 #include "opt_ahc.h" /* for config options */
47 #include <sys/param.h>
48 #include <sys/kernel.h>
49 #include <sys/systm.h>
50 #include <sys/device.h>
51 #include <sys/malloc.h>
54 #include <sys/scsiio.h>
55 #include <sys/reboot.h>
56 #include <sys/kthread.h>
58 #include <dev/pci/pcireg.h>
59 #include <dev/pci/pcivar.h>
64 #include <dev/scsipi/scsi_all.h>
65 #include <dev/scsipi/scsipi_all.h>
66 #include <dev/scsipi/scsi_message.h>
67 #include <dev/scsipi/scsipi_debug.h>
68 #include <dev/scsipi/scsiconf.h>
69 #include <dev/scsipi/scsi_iu.h>
71 #include <uvm/uvm_extern.h>
73 #ifdef CAM_NEW_TRAN_CODE
74 #define AHC_NEW_TRAN_SETTINGS
75 #endif /* CAM_NEW_TRAN_CODE */
78 /****************************** Platform Macros *******************************/
79 #define SIM_IS_SCSIBUS_B(ahc, sim) \
80 ((sim) == ahc->platform_data->sim_b)
81 #define SIM_CHANNEL(ahc, sim) \
82 (((sim) == ahc->platform_data->sim_b) ? 'B' : 'A')
83 #define SIM_SCSI_ID(ahc, sim) \
84 (((sim) == ahc->platform_data->sim_b) ? ahc->our_id_b : ahc->our_id)
85 #define SIM_PATH(ahc, sim) \
86 (((sim) == ahc->platform_data->sim_b) ? ahc->platform_data->path_b \
87 : ahc->platform_data->path)
88 #define BUILD_SCSIID(ahc, sim, target_id, our_id) \
89 ((((target_id) << TID_SHIFT) & TID) | (our_id))
91 #define SCB_GET_SIM(ahc, scb) \
92 (SCB_GET_CHANNEL(ahc, scb) == 'A' ? (ahc)->platform_data->sim \
93 : (ahc)->platform_data->sim_b)
96 #define offsetof(type, member) ((size_t)(&((type *)0)->member))
98 /************************* Forward Declarations *******************************/
99 typedef pcireg_t ahc_dev_softc_t
;
101 /***************************** Bus Space/DMA **********************************/
102 #define ahc_dma_tag_create(ahc, parent_tag, alignment, boundary, \
103 lowaddr, highaddr, filter, filterarg, \
104 maxsize, nsegments, maxsegsz, flags, \
106 bus_dma_tag_create(parent_tag, alignment, boundary, \
107 lowaddr, highaddr, filter, filterarg, \
108 maxsize, nsegments, maxsegsz, flags, \
111 #define ahc_dma_tag_destroy(ahc, tag) \
112 bus_dma_tag_destroy(tag)
114 #define ahc_dmamem_alloc(ahc, dmat, vaddr, flags, mapp) \
115 bus_dmamem_alloc(dmat, vaddr, flags, mapp)
117 #define ahc_dmamem_free(ahc, dmat, vaddr, map) \
118 bus_dmamem_free(dmat, vaddr, map)
120 #define ahc_dmamap_create(ahc, tag, flags, mapp) \
121 bus_dmamap_create(tag, flags, mapp)
123 #define ahc_dmamap_destroy(ahc, tag, map) \
124 bus_dmamap_destroy(tag, map)
126 #define ahc_dmamap_load(ahc, dmat, map, addr, buflen, callback, \
127 callback_arg, flags) \
128 bus_dmamap_load(dmat, map, addr, buflen, callback, callback_arg, flags)
130 #define ahc_dmamap_unload(ahc, tag, map) \
131 bus_dmamap_unload(tag, map)
133 /* XXX Need to update Bus DMA for partial map syncs */
134 #define ahc_dmamap_sync(ahc, dma_tag, dmamap, offset, len, op) \
135 bus_dmamap_sync(dma_tag, dmamap, offset, len, op)
137 /************************ Tunable Driver Parameters **************************/
139 * The number of DMA segments supported. The sequencer can handle any number
140 * of physically contiguous S/G entrys. To reduce the driver's memory
141 * consumption, we limit the number supported to be sufficient to handle
142 * the largest mapping supported by the kernel, MAXPHYS. Assuming the
143 * transfer is as fragmented as possible and unaligned, this turns out to
144 * be the number of paged sized transfers in MAXPHYS plus an extra element
145 * to handle any unaligned residual. The sequencer fetches SG elements
146 * in cacheline sized chucks, so make the number per-transaction an even
147 * multiple of 16 which should align us on even the largest of cacheline
150 #define AHC_NSEG (roundup(btoc(MAXPHYS) + 1, 16))
152 /* This driver supports target mode */
153 //#define AHC_TARGET_MODE 1
155 /************************** Softc/SCB Platform Data ***************************/
156 struct ahc_platform_data
{
158 * Hooks into the XPT.
162 struct cam_sim
*sim_b
;
163 struct cam_path
*path
;
164 struct cam_path
*path_b
;
169 struct resource
*regs
;
170 struct resource
*irq
;
176 struct scb_platform_data
{
179 /********************************* Byte Order *********************************/
180 #define ahc_htobe16(x) htobe16(x)
181 #define ahc_htobe32(x) htobe32(x)
182 #define ahc_htobe64(x) htobe64(x)
183 #define ahc_htole16(x) htole16(x)
184 #define ahc_htole32(x) htole32(x)
185 #define ahc_htole64(x) htole64(x)
187 #define ahc_be16toh(x) be16toh(x)
188 #define ahc_be32toh(x) be32toh(x)
189 #define ahc_be64toh(x) be64toh(x)
190 #define ahc_le16toh(x) le16toh(x)
191 #define ahc_le32toh(x) le32toh(x)
192 #define ahc_le64toh(x) le64toh(x)
194 /************************** Timer DataStructures ******************************/
195 typedef struct callout ahc_timer_t
;
197 /***************************** Core Includes **********************************/
198 #if AHC_REG_PRETTY_PRINT
199 #define AIC_DEBUG_REGISTERS 1
201 #define AIC_DEBUG_REGISTERS 0
204 #include <dev/ic/aic7xxxvar.h>
206 /***************************** Timer Facilities *******************************/
207 void ahc_timeout(void*);
209 #define ahc_timer_init(x) callout_init(x, 0)
210 #define ahc_timer_stop callout_stop
213 ahc_timer_reset(ahc_timer_t
*timer
, u_int usec
, ahc_callback_t
*func
, void *arg
)
215 callout_reset(timer
, (usec
* hz
)/1000000, func
, arg
);
219 ahc_scb_timer_reset(struct scb
*scb
, u_int usec
)
221 if (!(scb
->xs
->xs_control
& XS_CTL_POLL
)) {
222 callout_reset(&scb
->xs
->xs_callout
,
223 (usec
* hz
)/1000000, ahc_timeout
, scb
);
227 /*************************** Device Access ************************************/
228 #define ahc_inb(ahc, port) \
229 bus_space_read_1((ahc)->tag, (ahc)->bsh, port)
231 #define ahc_outb(ahc, port, value) \
232 bus_space_write_1((ahc)->tag, (ahc)->bsh, port, value)
234 #define ahc_outsb(ahc, port, valp, count) \
235 bus_space_write_multi_1((ahc)->tag, (ahc)->bsh, port, valp, count)
237 #define ahc_insb(ahc, port, valp, count) \
238 bus_space_read_multi_1((ahc)->tag, (ahc)->bsh, port, valp, count)
240 static __inline
void ahc_flush_device_writes(struct ahc_softc
*);
243 ahc_flush_device_writes(struct ahc_softc
*ahc
)
245 /* XXX Is this sufficient for all architectures??? */
246 (void)ahc_inb(ahc
, INTSTAT
);
249 /**************************** Locking Primitives ******************************/
250 /* Lock protecting internal data structures */
251 static __inline
void ahc_lockinit(struct ahc_softc
*);
252 static __inline
void ahc_lock(struct ahc_softc
*, unsigned long *);
253 static __inline
void ahc_unlock(struct ahc_softc
*, unsigned long *);
255 /* Lock held during command completion to the upper layer */
256 static __inline
void ahc_done_lockinit(struct ahc_softc
*);
257 static __inline
void ahc_done_lock(struct ahc_softc
*, unsigned long *);
258 static __inline
void ahc_done_unlock(struct ahc_softc
*, unsigned long *);
260 /* Lock held during ahc_list manipulation and ahc softc frees */
261 static __inline
void ahc_list_lockinit(void);
262 static __inline
void ahc_list_lock(unsigned long *);
263 static __inline
void ahc_list_unlock(unsigned long *);
266 ahc_lockinit(struct ahc_softc
*ahc
)
271 ahc_lock(struct ahc_softc
*ahc
, unsigned long *flags
)
277 ahc_unlock(struct ahc_softc
*ahc
, unsigned long *flags
)
282 /* Lock held during command completion to the upper layer */
284 ahc_done_lockinit(struct ahc_softc
*ahc
)
289 ahc_done_lock(struct ahc_softc
*ahc
, unsigned long *flags
)
294 ahc_done_unlock(struct ahc_softc
*ahc
, unsigned long *flags
)
298 /* Lock held during ahc_list manipulation and ahc softc frees */
300 ahc_list_lockinit(void)
305 ahc_list_lock(unsigned long *flags
)
310 ahc_list_unlock(unsigned long *flags
)
313 /****************************** OS Primitives *********************************/
314 #define ahc_delay DELAY
316 /************************** Transaction Operations ****************************/
317 static __inline
void ahc_set_transaction_status(struct scb
*, uint32_t);
318 static __inline
void ahc_set_scsi_status(struct scb
*, uint32_t);
319 static __inline
uint32_t ahc_get_transaction_status(struct scb
*);
320 static __inline
uint32_t ahc_get_scsi_status(struct scb
*);
321 static __inline
void ahc_set_transaction_tag(struct scb
*, int, u_int
);
322 static __inline u_long
ahc_get_transfer_length(struct scb
*);
323 static __inline
int ahc_get_transfer_dir(struct scb
*);
324 static __inline
void ahc_set_residual(struct scb
*, u_long
);
325 static __inline
void ahc_set_sense_residual(struct scb
*, u_long
);
326 static __inline u_long
ahc_get_residual(struct scb
*);
327 static __inline
int ahc_perform_autosense(struct scb
*);
328 static __inline
uint32_t ahc_get_sense_bufsize(struct ahc_softc
*,
330 static __inline
void ahc_freeze_scb(struct scb
*);
331 static __inline
void ahc_platform_freeze_devq(struct ahc_softc
*, struct scb
*);
332 static __inline
int ahc_platform_abort_scbs(struct ahc_softc
*, int, char,
333 int, u_int
, role_t
, uint32_t);
336 void ahc_set_transaction_status(struct scb
*scb
, uint32_t status
)
338 scb
->xs
->error
= status
;
342 void ahc_set_scsi_status(struct scb
*scb
, uint32_t status
)
344 scb
->xs
->xs_status
= status
;
348 uint32_t ahc_get_transaction_status(struct scb
*scb
)
350 return (scb
->xs
->error
);
354 uint32_t ahc_get_scsi_status(struct scb
*scb
)
356 return (scb
->xs
->xs_status
);
360 void ahc_set_transaction_tag(struct scb
*scb
, int enabled
, u_int type
)
362 scb
->xs
->xs_tag_type
= type
;
366 u_long
ahc_get_transfer_length(struct scb
*scb
)
368 return (scb
->xs
->datalen
);
372 int ahc_get_transfer_dir(struct scb
*scb
)
374 return (scb
->xs
->xs_control
& (XS_CTL_DATA_IN
|XS_CTL_DATA_OUT
));
378 void ahc_set_residual(struct scb
*scb
, u_long resid
)
380 scb
->xs
->resid
= resid
;
384 void ahc_set_sense_residual(struct scb
*scb
, u_long resid
)
387 scb
->io_ctx
->csio
.sense_resid
= resid
;
392 u_long
ahc_get_residual(struct scb
*scb
)
394 return (scb
->xs
->resid
);
398 int ahc_perform_autosense(struct scb
*scb
)
400 return (!(scb
->flags
& SCB_SENSE
));
403 static __inline
uint32_t
404 ahc_get_sense_bufsize(struct ahc_softc
*ahc
, struct scb
*scb
)
406 return (sizeof(struct scsi_sense_data
));
410 ahc_freeze_scb(struct scb
*scb
)
412 struct scsipi_xfer
*xs
= scb
->xs
;
414 if (!(scb
->flags
& SCB_FREEZE_QUEUE
)) {
415 scsipi_periph_freeze(xs
->xs_periph
, 1);
416 scb
->flags
|= SCB_FREEZE_QUEUE
;
421 ahc_platform_freeze_devq(struct ahc_softc
*ahc
, struct scb
*scb
)
426 ahc_platform_abort_scbs(struct ahc_softc
*ahc
, int target
,
427 char channel
, int lun
, u_int tag
,
428 role_t role
, uint32_t status
)
434 ahc_platform_scb_free(struct ahc_softc
*ahc
, struct scb
*scb
)
437 /* What do we do to generically handle driver resource shortages??? */
438 if ((ahc
->flags
& AHC_RESOURCE_SHORTAGE
) != 0
439 && scb
->io_ctx
!= NULL
440 && (scb
->io_ctx
->ccb_h
.status
& CAM_RELEASE_SIMQ
) == 0) {
441 scb
->io_ctx
->ccb_h
.status
|= CAM_RELEASE_SIMQ
;
442 ahc
->flags
&= ~AHC_RESOURCE_SHORTAGE
;
448 /********************************** PCI ***************************************/
449 #ifdef AHC_PCI_CONFIG
450 static __inline
uint32_t ahc_pci_read_config(ahc_dev_softc_t
, int, int);
451 static __inline
void ahc_pci_write_config(ahc_dev_softc_t
, int, uint32_t,
453 static __inline
int ahc_get_pci_function(ahc_dev_softc_t
);
454 static __inline
int ahc_get_pci_slot(ahc_dev_softc_t
);
455 static __inline
int ahc_get_pci_bus(ahc_dev_softc_t
);
457 int ahc_pci_map_registers(struct ahc_softc
*);
458 int ahc_pci_map_int(struct ahc_softc
*);
460 static __inline
uint32_t
461 ahc_pci_read_config(ahc_dev_softc_t pci
, int reg
, int width
)
463 return (pci_read_config(pci
, reg
, width
));
467 ahc_pci_write_config(ahc_dev_softc_t pci
, int reg
, uint32_t value
, int width
)
469 pci_write_config(pci
, reg
, value
, width
);
473 ahc_get_pci_function(ahc_dev_softc_t pci
)
475 return (pci_get_function(pci
));
479 ahc_get_pci_slot(ahc_dev_softc_t pci
)
481 return (pci_get_slot(pci
));
485 ahc_get_pci_bus(ahc_dev_softc_t pci
)
487 return (pci_get_bus(pci
));
498 void ahc_power_state_change(struct ahc_softc
*, ahc_power_state
);
500 /******************************** VL/EISA *************************************/
501 int aic7770_map_registers(struct ahc_softc
*, u_int
);
502 int aic7770_map_int(struct ahc_softc
*, int);
504 /********************************* Debug **************************************/
505 static __inline
void ahc_print_path(struct ahc_softc
*, struct scb
*);
506 static __inline
void ahc_platform_dump_card_state(struct ahc_softc
*);
509 ahc_print_path(struct ahc_softc
*ahc
, struct scb
*scb
)
511 printf("%s:", device_xname(ahc
->sc_dev
));
515 ahc_platform_dump_card_state(struct ahc_softc
*ahc
)
518 /**************************** Transfer Settings *******************************/
519 void ahc_notify_xfer_settings_change(struct ahc_softc
*,
520 struct ahc_devinfo
*);
521 void ahc_platform_set_tags(struct ahc_softc
*, struct ahc_devinfo
*, int);
523 /************************* Initialization/Teardown ****************************/
524 int ahc_platform_alloc(struct ahc_softc
*, void *);
525 void ahc_platform_free(struct ahc_softc
*);
526 int ahc_map_int(struct ahc_softc
*);
527 int ahc_attach(struct ahc_softc
*);
528 int ahc_softc_comp(struct ahc_softc
*, struct ahc_softc
*);
529 int ahc_detach(struct ahc_softc
*, int);
531 /****************************** Interrupts ************************************/
532 void ahc_platform_intr(void *);
533 static __inline
void ahc_platform_flushwork(struct ahc_softc
*);
535 ahc_platform_flushwork(struct ahc_softc
*ahc
)
539 /************************ Misc Function Declarations **************************/
540 void ahc_done(struct ahc_softc
*, struct scb
*);
541 void ahc_send_async(struct ahc_softc
*, char, u_int
, u_int
, ac_code
,
543 #endif /* _AIC7XXX_NETBSD_H_ */