Deleted Added
full compact
aic7xxx_osm.h (117126) aic7xxx_osm.h (119277)
1/*
2 * FreeBSD platform specific driver option settings, data structures,
3 * function declarations and includes.
4 *
5 * Copyright (c) 1994-2001 Justin T. Gibbs.
6 * All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 * 1. Redistributions of source code must retain the above copyright
12 * notice, this list of conditions, and the following disclaimer,
13 * without modification.
14 * 2. The name of the author may not be used to endorse or promote products
15 * derived from this software without specific prior written permission.
16 *
17 * Alternatively, this software may be distributed under the terms of the
18 * GNU Public License ("GPL").
19 *
20 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
21 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR
24 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
26 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
27 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
29 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
30 * SUCH DAMAGE.
31 *
1/*
2 * FreeBSD platform specific driver option settings, data structures,
3 * function declarations and includes.
4 *
5 * Copyright (c) 1994-2001 Justin T. Gibbs.
6 * All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 * 1. Redistributions of source code must retain the above copyright
12 * notice, this list of conditions, and the following disclaimer,
13 * without modification.
14 * 2. The name of the author may not be used to endorse or promote products
15 * derived from this software without specific prior written permission.
16 *
17 * Alternatively, this software may be distributed under the terms of the
18 * GNU Public License ("GPL").
19 *
20 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
21 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR
24 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
26 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
27 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
29 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
30 * SUCH DAMAGE.
31 *
32 * $Id: aic7xxx_osm.h,v 1.22 2003/06/10 03:25:24 gibbs Exp $
32 * $Id: aic7xxx_osm.h,v 1.23 2003/07/01 15:51:52 scottl Exp $
33 *
33 *
34 * $FreeBSD: head/sys/dev/aic7xxx/aic7xxx_osm.h 117126 2003-07-01 15:52:06Z scottl $
34 * $FreeBSD: head/sys/dev/aic7xxx/aic7xxx_osm.h 119277 2003-08-22 05:54:52Z imp $
35 */
36
37#ifndef _AIC7XXX_FREEBSD_H_
38#define _AIC7XXX_FREEBSD_H_
39
40#include <opt_aic7xxx.h> /* for config options */
41
42#include <sys/param.h>
43#include <sys/systm.h>
44#include <sys/bus.h> /* For device_t */
45#if __FreeBSD_version >= 500000
46#include <sys/endian.h>
47#endif
48#include <sys/eventhandler.h>
49#include <sys/kernel.h>
50#include <sys/malloc.h>
51#include <sys/queue.h>
52
53#if __FreeBSD_version < 500000
54#include <pci.h>
55#else
56#define NPCI 1
57#endif
58
59#if NPCI > 0
60#define AHC_PCI_CONFIG 1
61#include <machine/bus_memio.h>
62#endif
63#include <machine/bus_pio.h>
64#include <machine/bus.h>
65#include <machine/endian.h>
66#include <machine/clock.h>
67#include <machine/resource.h>
68
69#include <sys/rman.h>
70
71#if NPCI > 0
35 */
36
37#ifndef _AIC7XXX_FREEBSD_H_
38#define _AIC7XXX_FREEBSD_H_
39
40#include <opt_aic7xxx.h> /* for config options */
41
42#include <sys/param.h>
43#include <sys/systm.h>
44#include <sys/bus.h> /* For device_t */
45#if __FreeBSD_version >= 500000
46#include <sys/endian.h>
47#endif
48#include <sys/eventhandler.h>
49#include <sys/kernel.h>
50#include <sys/malloc.h>
51#include <sys/queue.h>
52
53#if __FreeBSD_version < 500000
54#include <pci.h>
55#else
56#define NPCI 1
57#endif
58
59#if NPCI > 0
60#define AHC_PCI_CONFIG 1
61#include <machine/bus_memio.h>
62#endif
63#include <machine/bus_pio.h>
64#include <machine/bus.h>
65#include <machine/endian.h>
66#include <machine/clock.h>
67#include <machine/resource.h>
68
69#include <sys/rman.h>
70
71#if NPCI > 0
72#if __FreeBSD_version < 500000
72#include <pci/pcireg.h>
73#include <pci/pcivar.h>
73#include <pci/pcireg.h>
74#include <pci/pcivar.h>
75#else
76#include <dev/pci/pcireg.h>
77#include <dev/pci/pcivar.h>
74#endif
78#endif
79#endif
75
76#include <cam/cam.h>
77#include <cam/cam_ccb.h>
78#include <cam/cam_debug.h>
79#include <cam/cam_sim.h>
80#include <cam/cam_xpt_sim.h>
81
82#include <cam/scsi/scsi_all.h>
83#include <cam/scsi/scsi_message.h>
84
85#ifdef CAM_NEW_TRAN_CODE
86#define AHC_NEW_TRAN_SETTINGS
87#endif /* CAM_NEW_TRAN_CODE */
88
89/*************************** Attachment Bookkeeping ***************************/
90extern devclass_t ahc_devclass;
91
92/****************************** Platform Macros *******************************/
93#define SIM_IS_SCSIBUS_B(ahc, sim) \
94 ((sim) == ahc->platform_data->sim_b)
95#define SIM_CHANNEL(ahc, sim) \
96 (((sim) == ahc->platform_data->sim_b) ? 'B' : 'A')
97#define SIM_SCSI_ID(ahc, sim) \
98 (((sim) == ahc->platform_data->sim_b) ? ahc->our_id_b : ahc->our_id)
99#define SIM_PATH(ahc, sim) \
100 (((sim) == ahc->platform_data->sim_b) ? ahc->platform_data->path_b \
101 : ahc->platform_data->path)
102#define BUILD_SCSIID(ahc, sim, target_id, our_id) \
103 ((((target_id) << TID_SHIFT) & TID) | (our_id) \
104 | (SIM_IS_SCSIBUS_B(ahc, sim) ? TWIN_CHNLB : 0))
105
106#define SCB_GET_SIM(ahc, scb) \
107 (SCB_GET_CHANNEL(ahc, scb) == 'A' ? (ahc)->platform_data->sim \
108 : (ahc)->platform_data->sim_b)
109
110#ifndef offsetof
111#define offsetof(type, member) ((size_t)(&((type *)0)->member))
112#endif
113/************************* Forward Declarations *******************************/
114typedef device_t ahc_dev_softc_t;
115typedef union ccb *ahc_io_ctx_t;
116
117/***************************** Bus Space/DMA **********************************/
118#define ahc_dma_tag_create(ahc, parent_tag, alignment, boundary, \
119 lowaddr, highaddr, filter, filterarg, \
120 maxsize, nsegments, maxsegsz, flags, \
121 dma_tagp) \
122 bus_dma_tag_create(parent_tag, alignment, boundary, \
123 lowaddr, highaddr, filter, filterarg, \
124 maxsize, nsegments, maxsegsz, flags, \
125 busdma_lock_mutex, &Giant, dma_tagp)
126
127#define ahc_dma_tag_destroy(ahc, tag) \
128 bus_dma_tag_destroy(tag)
129
130#define ahc_dmamem_alloc(ahc, dmat, vaddr, flags, mapp) \
131 bus_dmamem_alloc(dmat, vaddr, flags, mapp)
132
133#define ahc_dmamem_free(ahc, dmat, vaddr, map) \
134 bus_dmamem_free(dmat, vaddr, map)
135
136#define ahc_dmamap_create(ahc, tag, flags, mapp) \
137 bus_dmamap_create(tag, flags, mapp)
138
139#define ahc_dmamap_destroy(ahc, tag, map) \
140 bus_dmamap_destroy(tag, map)
141
142#define ahc_dmamap_load(ahc, dmat, map, addr, buflen, callback, \
143 callback_arg, flags) \
144 bus_dmamap_load(dmat, map, addr, buflen, callback, callback_arg, flags)
145
146#define ahc_dmamap_unload(ahc, tag, map) \
147 bus_dmamap_unload(tag, map)
148
149/* XXX Need to update Bus DMA for partial map syncs */
150#define ahc_dmamap_sync(ahc, dma_tag, dmamap, offset, len, op) \
151 bus_dmamap_sync(dma_tag, dmamap, op)
152
153/************************ Tunable Driver Parameters **************************/
154/*
155 * The number of dma segments supported. The sequencer can handle any number
156 * of physically contiguous S/G entrys. To reduce the driver's memory
157 * consumption, we limit the number supported to be sufficient to handle
158 * the largest mapping supported by the kernel, MAXPHYS. Assuming the
159 * transfer is as fragmented as possible and unaligned, this turns out to
160 * be the number of paged sized transfers in MAXPHYS plus an extra element
161 * to handle any unaligned residual. The sequencer fetches SG elements
162 * in cacheline sized chucks, so make the number per-transaction an even
163 * multiple of 16 which should align us on even the largest of cacheline
164 * boundaries.
165 */
166#define AHC_NSEG (roundup(btoc(MAXPHYS) + 1, 16))
167
168/* This driver supports target mode */
169#define AHC_TARGET_MODE 1
170
171/************************** Softc/SCB Platform Data ***************************/
172struct ahc_platform_data {
173 /*
174 * Hooks into the XPT.
175 */
176 struct cam_sim *sim;
177 struct cam_sim *sim_b;
178 struct cam_path *path;
179 struct cam_path *path_b;
180
181 int regs_res_type;
182 int regs_res_id;
183 int irq_res_type;
184 struct resource *regs;
185 struct resource *irq;
186 void *ih;
187 eventhandler_tag eh;
188};
189
190struct scb_platform_data {
191};
192
193/********************************* Byte Order *********************************/
194#if __FreeBSD_version >= 500000
195#define ahc_htobe16(x) htobe16(x)
196#define ahc_htobe32(x) htobe32(x)
197#define ahc_htobe64(x) htobe64(x)
198#define ahc_htole16(x) htole16(x)
199#define ahc_htole32(x) htole32(x)
200#define ahc_htole64(x) htole64(x)
201
202#define ahc_be16toh(x) be16toh(x)
203#define ahc_be32toh(x) be32toh(x)
204#define ahc_be64toh(x) be64toh(x)
205#define ahc_le16toh(x) le16toh(x)
206#define ahc_le32toh(x) le32toh(x)
207#define ahc_le64toh(x) le64toh(x)
208#else
209#define ahc_htobe16(x) (x)
210#define ahc_htobe32(x) (x)
211#define ahc_htobe64(x) (x)
212#define ahc_htole16(x) (x)
213#define ahc_htole32(x) (x)
214#define ahc_htole64(x) (x)
215
216#define ahc_be16toh(x) (x)
217#define ahc_be32toh(x) (x)
218#define ahc_be64toh(x) (x)
219#define ahc_le16toh(x) (x)
220#define ahc_le32toh(x) (x)
221#define ahc_le64toh(x) (x)
222#endif
223
224/************************** Timer DataStructures ******************************/
225typedef struct callout ahc_timer_t;
226
227/***************************** Core Includes **********************************/
228#if AHC_REG_PRETTY_PRINT
229#define AIC_DEBUG_REGISTERS 1
230#else
231#define AIC_DEBUG_REGISTERS 0
232#endif
233#include <dev/aic7xxx/aic7xxx.h>
234
235/***************************** Timer Facilities *******************************/
236timeout_t ahc_timeout;
237
238#if __FreeBSD_version >= 500000
239#define ahc_timer_init(timer) callout_init(timer, /*mpsafe*/0)
240#else
241#define ahc_timer_init callout_init
242#endif
243#define ahc_timer_stop callout_stop
244
245static __inline void
246ahc_timer_reset(ahc_timer_t *timer, u_int usec, ahc_callback_t *func, void *arg)
247{
248 callout_reset(timer, (usec * hz)/1000000, func, arg);
249}
250
251static __inline void
252ahc_scb_timer_reset(struct scb *scb, u_int usec)
253{
254 untimeout(ahc_timeout, (caddr_t)scb, scb->io_ctx->ccb_h.timeout_ch);
255 scb->io_ctx->ccb_h.timeout_ch =
256 timeout(ahc_timeout, scb, (usec * hz)/1000000);
257}
258
259/*************************** Device Access ************************************/
260#define ahc_inb(ahc, port) \
261 bus_space_read_1((ahc)->tag, (ahc)->bsh, port)
262
263#define ahc_outb(ahc, port, value) \
264 bus_space_write_1((ahc)->tag, (ahc)->bsh, port, value)
265
266#define ahc_outsb(ahc, port, valp, count) \
267 bus_space_write_multi_1((ahc)->tag, (ahc)->bsh, port, valp, count)
268
269#define ahc_insb(ahc, port, valp, count) \
270 bus_space_read_multi_1((ahc)->tag, (ahc)->bsh, port, valp, count)
271
272static __inline void ahc_flush_device_writes(struct ahc_softc *);
273
274static __inline void
275ahc_flush_device_writes(struct ahc_softc *ahc)
276{
277 /* XXX Is this sufficient for all architectures??? */
278 ahc_inb(ahc, INTSTAT);
279}
280
281/**************************** Locking Primitives ******************************/
282/* Lock protecting internal data structures */
283static __inline void ahc_lockinit(struct ahc_softc *);
284static __inline void ahc_lock(struct ahc_softc *, unsigned long *flags);
285static __inline void ahc_unlock(struct ahc_softc *, unsigned long *flags);
286
287/* Lock held during command compeletion to the upper layer */
288static __inline void ahc_done_lockinit(struct ahc_softc *);
289static __inline void ahc_done_lock(struct ahc_softc *, unsigned long *flags);
290static __inline void ahc_done_unlock(struct ahc_softc *, unsigned long *flags);
291
292/* Lock held during ahc_list manipulation and ahc softc frees */
293static __inline void ahc_list_lockinit(void);
294static __inline void ahc_list_lock(unsigned long *flags);
295static __inline void ahc_list_unlock(unsigned long *flags);
296
297static __inline void
298ahc_lockinit(struct ahc_softc *ahc)
299{
300}
301
302static __inline void
303ahc_lock(struct ahc_softc *ahc, unsigned long *flags)
304{
305 *flags = splcam();
306}
307
308static __inline void
309ahc_unlock(struct ahc_softc *ahc, unsigned long *flags)
310{
311 splx(*flags);
312}
313
314/* Lock held during command compeletion to the upper layer */
315static __inline void
316ahc_done_lockinit(struct ahc_softc *ahc)
317{
318}
319
320static __inline void
321ahc_done_lock(struct ahc_softc *ahc, unsigned long *flags)
322{
323}
324
325static __inline void
326ahc_done_unlock(struct ahc_softc *ahc, unsigned long *flags)
327{
328}
329
330/* Lock held during ahc_list manipulation and ahc softc frees */
331static __inline void
332ahc_list_lockinit(void)
333{
334}
335
336static __inline void
337ahc_list_lock(unsigned long *flags)
338{
339}
340
341static __inline void
342ahc_list_unlock(unsigned long *flags)
343{
344}
345/****************************** OS Primitives *********************************/
346#define ahc_delay DELAY
347
348/************************** Transaction Operations ****************************/
349static __inline void ahc_set_transaction_status(struct scb *, uint32_t);
350static __inline void ahc_set_scsi_status(struct scb *, uint32_t);
351static __inline uint32_t ahc_get_transaction_status(struct scb *);
352static __inline uint32_t ahc_get_scsi_status(struct scb *);
353static __inline void ahc_set_transaction_tag(struct scb *, int, u_int);
354static __inline u_long ahc_get_transfer_length(struct scb *);
355static __inline int ahc_get_transfer_dir(struct scb *);
356static __inline void ahc_set_residual(struct scb *, u_long);
357static __inline void ahc_set_sense_residual(struct scb *, u_long);
358static __inline u_long ahc_get_residual(struct scb *);
359static __inline int ahc_perform_autosense(struct scb *);
360static __inline uint32_t ahc_get_sense_bufsize(struct ahc_softc*, struct scb*);
361static __inline void ahc_freeze_ccb(union ccb *ccb);
362static __inline void ahc_freeze_scb(struct scb *scb);
363static __inline void ahc_platform_freeze_devq(struct ahc_softc *, struct scb *);
364static __inline int ahc_platform_abort_scbs(struct ahc_softc *ahc, int target,
365 char channel, int lun, u_int tag,
366 role_t role, uint32_t status);
367
368static __inline
369void ahc_set_transaction_status(struct scb *scb, uint32_t status)
370{
371 scb->io_ctx->ccb_h.status &= ~CAM_STATUS_MASK;
372 scb->io_ctx->ccb_h.status |= status;
373}
374
375static __inline
376void ahc_set_scsi_status(struct scb *scb, uint32_t status)
377{
378 scb->io_ctx->csio.scsi_status = status;
379}
380
381static __inline
382uint32_t ahc_get_transaction_status(struct scb *scb)
383{
384 return (scb->io_ctx->ccb_h.status & CAM_STATUS_MASK);
385}
386
387static __inline
388uint32_t ahc_get_scsi_status(struct scb *scb)
389{
390 return (scb->io_ctx->csio.scsi_status);
391}
392
393static __inline
394void ahc_set_transaction_tag(struct scb *scb, int enabled, u_int type)
395{
396 scb->io_ctx->csio.tag_action = type;
397 if (enabled)
398 scb->io_ctx->ccb_h.flags |= CAM_TAG_ACTION_VALID;
399 else
400 scb->io_ctx->ccb_h.flags &= ~CAM_TAG_ACTION_VALID;
401}
402
403static __inline
404u_long ahc_get_transfer_length(struct scb *scb)
405{
406 return (scb->io_ctx->csio.dxfer_len);
407}
408
409static __inline
410int ahc_get_transfer_dir(struct scb *scb)
411{
412 return (scb->io_ctx->ccb_h.flags & CAM_DIR_MASK);
413}
414
415static __inline
416void ahc_set_residual(struct scb *scb, u_long resid)
417{
418 scb->io_ctx->csio.resid = resid;
419}
420
421static __inline
422void ahc_set_sense_residual(struct scb *scb, u_long resid)
423{
424 scb->io_ctx->csio.sense_resid = resid;
425}
426
427static __inline
428u_long ahc_get_residual(struct scb *scb)
429{
430 return (scb->io_ctx->csio.resid);
431}
432
433static __inline
434int ahc_perform_autosense(struct scb *scb)
435{
436 return (!(scb->io_ctx->ccb_h.flags & CAM_DIS_AUTOSENSE));
437}
438
439static __inline uint32_t
440ahc_get_sense_bufsize(struct ahc_softc *ahc, struct scb *scb)
441{
442 return (sizeof(struct scsi_sense_data));
443}
444
445static __inline void
446ahc_freeze_ccb(union ccb *ccb)
447{
448 if ((ccb->ccb_h.status & CAM_DEV_QFRZN) == 0) {
449 ccb->ccb_h.status |= CAM_DEV_QFRZN;
450 xpt_freeze_devq(ccb->ccb_h.path, /*count*/1);
451 }
452}
453
454static __inline void
455ahc_freeze_scb(struct scb *scb)
456{
457 ahc_freeze_ccb(scb->io_ctx);
458}
459
460static __inline void
461ahc_platform_freeze_devq(struct ahc_softc *ahc, struct scb *scb)
462{
463 /* Nothing to do here for FreeBSD */
464}
465
466static __inline int
467ahc_platform_abort_scbs(struct ahc_softc *ahc, int target,
468 char channel, int lun, u_int tag,
469 role_t role, uint32_t status)
470{
471 /* Nothing to do here for FreeBSD */
472 return (0);
473}
474
475static __inline void
476ahc_platform_scb_free(struct ahc_softc *ahc, struct scb *scb)
477{
478 /* What do we do to generically handle driver resource shortages??? */
479 if ((ahc->flags & AHC_RESOURCE_SHORTAGE) != 0
480 && scb->io_ctx != NULL
481 && (scb->io_ctx->ccb_h.status & CAM_RELEASE_SIMQ) == 0) {
482 scb->io_ctx->ccb_h.status |= CAM_RELEASE_SIMQ;
483 ahc->flags &= ~AHC_RESOURCE_SHORTAGE;
484 }
485 scb->io_ctx = NULL;
486}
487
488/********************************** PCI ***************************************/
489#ifdef AHC_PCI_CONFIG
490static __inline uint32_t ahc_pci_read_config(ahc_dev_softc_t pci,
491 int reg, int width);
492static __inline void ahc_pci_write_config(ahc_dev_softc_t pci,
493 int reg, uint32_t value,
494 int width);
495static __inline int ahc_get_pci_function(ahc_dev_softc_t);
496static __inline int ahc_get_pci_slot(ahc_dev_softc_t);
497static __inline int ahc_get_pci_bus(ahc_dev_softc_t);
498
499int ahc_pci_map_registers(struct ahc_softc *ahc);
500int ahc_pci_map_int(struct ahc_softc *ahc);
501
502static __inline uint32_t
503ahc_pci_read_config(ahc_dev_softc_t pci, int reg, int width)
504{
505 return (pci_read_config(pci, reg, width));
506}
507
508static __inline void
509ahc_pci_write_config(ahc_dev_softc_t pci, int reg, uint32_t value, int width)
510{
511 pci_write_config(pci, reg, value, width);
512}
513
514static __inline int
515ahc_get_pci_function(ahc_dev_softc_t pci)
516{
517 return (pci_get_function(pci));
518}
519
520static __inline int
521ahc_get_pci_slot(ahc_dev_softc_t pci)
522{
523 return (pci_get_slot(pci));
524}
525
526static __inline int
527ahc_get_pci_bus(ahc_dev_softc_t pci)
528{
529 return (pci_get_bus(pci));
530}
531
532typedef enum
533{
534 AHC_POWER_STATE_D0,
535 AHC_POWER_STATE_D1,
536 AHC_POWER_STATE_D2,
537 AHC_POWER_STATE_D3
538} ahc_power_state;
539
540void ahc_power_state_change(struct ahc_softc *ahc,
541 ahc_power_state new_state);
542#endif
543/******************************** VL/EISA *************************************/
544int aic7770_map_registers(struct ahc_softc *ahc, u_int port);
545int aic7770_map_int(struct ahc_softc *ahc, int irq);
546
547/********************************* Debug **************************************/
548static __inline void ahc_print_path(struct ahc_softc *, struct scb *);
549static __inline void ahc_platform_dump_card_state(struct ahc_softc *ahc);
550
551static __inline void
552ahc_print_path(struct ahc_softc *ahc, struct scb *scb)
553{
554 xpt_print_path(scb->io_ctx->ccb_h.path);
555}
556
557static __inline void
558ahc_platform_dump_card_state(struct ahc_softc *ahc)
559{
560 /* Nothing to do here for FreeBSD */
561}
562/**************************** Transfer Settings *******************************/
563void ahc_notify_xfer_settings_change(struct ahc_softc *,
564 struct ahc_devinfo *);
565void ahc_platform_set_tags(struct ahc_softc *, struct ahc_devinfo *,
566 int /*enable*/);
567
568/************************* Initialization/Teardown ****************************/
569int ahc_platform_alloc(struct ahc_softc *ahc, void *platform_arg);
570void ahc_platform_free(struct ahc_softc *ahc);
571int ahc_map_int(struct ahc_softc *ahc);
572int ahc_attach(struct ahc_softc *);
573int ahc_softc_comp(struct ahc_softc *lahc, struct ahc_softc *rahc);
574int ahc_detach(device_t);
575
576/****************************** Interrupts ************************************/
577void ahc_platform_intr(void *);
578static __inline void ahc_platform_flushwork(struct ahc_softc *ahc);
579static __inline void
580ahc_platform_flushwork(struct ahc_softc *ahc)
581{
582}
583
584/************************ Misc Function Declarations **************************/
585void ahc_done(struct ahc_softc *ahc, struct scb *scb);
586void ahc_send_async(struct ahc_softc *, char /*channel*/,
587 u_int /*target*/, u_int /*lun*/, ac_code, void *arg);
588#endif /* _AIC7XXX_FREEBSD_H_ */
80
81#include <cam/cam.h>
82#include <cam/cam_ccb.h>
83#include <cam/cam_debug.h>
84#include <cam/cam_sim.h>
85#include <cam/cam_xpt_sim.h>
86
87#include <cam/scsi/scsi_all.h>
88#include <cam/scsi/scsi_message.h>
89
90#ifdef CAM_NEW_TRAN_CODE
91#define AHC_NEW_TRAN_SETTINGS
92#endif /* CAM_NEW_TRAN_CODE */
93
94/*************************** Attachment Bookkeeping ***************************/
95extern devclass_t ahc_devclass;
96
97/****************************** Platform Macros *******************************/
98#define SIM_IS_SCSIBUS_B(ahc, sim) \
99 ((sim) == ahc->platform_data->sim_b)
100#define SIM_CHANNEL(ahc, sim) \
101 (((sim) == ahc->platform_data->sim_b) ? 'B' : 'A')
102#define SIM_SCSI_ID(ahc, sim) \
103 (((sim) == ahc->platform_data->sim_b) ? ahc->our_id_b : ahc->our_id)
104#define SIM_PATH(ahc, sim) \
105 (((sim) == ahc->platform_data->sim_b) ? ahc->platform_data->path_b \
106 : ahc->platform_data->path)
107#define BUILD_SCSIID(ahc, sim, target_id, our_id) \
108 ((((target_id) << TID_SHIFT) & TID) | (our_id) \
109 | (SIM_IS_SCSIBUS_B(ahc, sim) ? TWIN_CHNLB : 0))
110
111#define SCB_GET_SIM(ahc, scb) \
112 (SCB_GET_CHANNEL(ahc, scb) == 'A' ? (ahc)->platform_data->sim \
113 : (ahc)->platform_data->sim_b)
114
115#ifndef offsetof
116#define offsetof(type, member) ((size_t)(&((type *)0)->member))
117#endif
118/************************* Forward Declarations *******************************/
119typedef device_t ahc_dev_softc_t;
120typedef union ccb *ahc_io_ctx_t;
121
122/***************************** Bus Space/DMA **********************************/
123#define ahc_dma_tag_create(ahc, parent_tag, alignment, boundary, \
124 lowaddr, highaddr, filter, filterarg, \
125 maxsize, nsegments, maxsegsz, flags, \
126 dma_tagp) \
127 bus_dma_tag_create(parent_tag, alignment, boundary, \
128 lowaddr, highaddr, filter, filterarg, \
129 maxsize, nsegments, maxsegsz, flags, \
130 busdma_lock_mutex, &Giant, dma_tagp)
131
132#define ahc_dma_tag_destroy(ahc, tag) \
133 bus_dma_tag_destroy(tag)
134
135#define ahc_dmamem_alloc(ahc, dmat, vaddr, flags, mapp) \
136 bus_dmamem_alloc(dmat, vaddr, flags, mapp)
137
138#define ahc_dmamem_free(ahc, dmat, vaddr, map) \
139 bus_dmamem_free(dmat, vaddr, map)
140
141#define ahc_dmamap_create(ahc, tag, flags, mapp) \
142 bus_dmamap_create(tag, flags, mapp)
143
144#define ahc_dmamap_destroy(ahc, tag, map) \
145 bus_dmamap_destroy(tag, map)
146
147#define ahc_dmamap_load(ahc, dmat, map, addr, buflen, callback, \
148 callback_arg, flags) \
149 bus_dmamap_load(dmat, map, addr, buflen, callback, callback_arg, flags)
150
151#define ahc_dmamap_unload(ahc, tag, map) \
152 bus_dmamap_unload(tag, map)
153
154/* XXX Need to update Bus DMA for partial map syncs */
155#define ahc_dmamap_sync(ahc, dma_tag, dmamap, offset, len, op) \
156 bus_dmamap_sync(dma_tag, dmamap, op)
157
158/************************ Tunable Driver Parameters **************************/
159/*
160 * The number of dma segments supported. The sequencer can handle any number
161 * of physically contiguous S/G entrys. To reduce the driver's memory
162 * consumption, we limit the number supported to be sufficient to handle
163 * the largest mapping supported by the kernel, MAXPHYS. Assuming the
164 * transfer is as fragmented as possible and unaligned, this turns out to
165 * be the number of paged sized transfers in MAXPHYS plus an extra element
166 * to handle any unaligned residual. The sequencer fetches SG elements
167 * in cacheline sized chucks, so make the number per-transaction an even
168 * multiple of 16 which should align us on even the largest of cacheline
169 * boundaries.
170 */
171#define AHC_NSEG (roundup(btoc(MAXPHYS) + 1, 16))
172
173/* This driver supports target mode */
174#define AHC_TARGET_MODE 1
175
176/************************** Softc/SCB Platform Data ***************************/
177struct ahc_platform_data {
178 /*
179 * Hooks into the XPT.
180 */
181 struct cam_sim *sim;
182 struct cam_sim *sim_b;
183 struct cam_path *path;
184 struct cam_path *path_b;
185
186 int regs_res_type;
187 int regs_res_id;
188 int irq_res_type;
189 struct resource *regs;
190 struct resource *irq;
191 void *ih;
192 eventhandler_tag eh;
193};
194
195struct scb_platform_data {
196};
197
198/********************************* Byte Order *********************************/
199#if __FreeBSD_version >= 500000
200#define ahc_htobe16(x) htobe16(x)
201#define ahc_htobe32(x) htobe32(x)
202#define ahc_htobe64(x) htobe64(x)
203#define ahc_htole16(x) htole16(x)
204#define ahc_htole32(x) htole32(x)
205#define ahc_htole64(x) htole64(x)
206
207#define ahc_be16toh(x) be16toh(x)
208#define ahc_be32toh(x) be32toh(x)
209#define ahc_be64toh(x) be64toh(x)
210#define ahc_le16toh(x) le16toh(x)
211#define ahc_le32toh(x) le32toh(x)
212#define ahc_le64toh(x) le64toh(x)
213#else
214#define ahc_htobe16(x) (x)
215#define ahc_htobe32(x) (x)
216#define ahc_htobe64(x) (x)
217#define ahc_htole16(x) (x)
218#define ahc_htole32(x) (x)
219#define ahc_htole64(x) (x)
220
221#define ahc_be16toh(x) (x)
222#define ahc_be32toh(x) (x)
223#define ahc_be64toh(x) (x)
224#define ahc_le16toh(x) (x)
225#define ahc_le32toh(x) (x)
226#define ahc_le64toh(x) (x)
227#endif
228
229/************************** Timer DataStructures ******************************/
230typedef struct callout ahc_timer_t;
231
232/***************************** Core Includes **********************************/
233#if AHC_REG_PRETTY_PRINT
234#define AIC_DEBUG_REGISTERS 1
235#else
236#define AIC_DEBUG_REGISTERS 0
237#endif
238#include <dev/aic7xxx/aic7xxx.h>
239
240/***************************** Timer Facilities *******************************/
241timeout_t ahc_timeout;
242
243#if __FreeBSD_version >= 500000
244#define ahc_timer_init(timer) callout_init(timer, /*mpsafe*/0)
245#else
246#define ahc_timer_init callout_init
247#endif
248#define ahc_timer_stop callout_stop
249
250static __inline void
251ahc_timer_reset(ahc_timer_t *timer, u_int usec, ahc_callback_t *func, void *arg)
252{
253 callout_reset(timer, (usec * hz)/1000000, func, arg);
254}
255
256static __inline void
257ahc_scb_timer_reset(struct scb *scb, u_int usec)
258{
259 untimeout(ahc_timeout, (caddr_t)scb, scb->io_ctx->ccb_h.timeout_ch);
260 scb->io_ctx->ccb_h.timeout_ch =
261 timeout(ahc_timeout, scb, (usec * hz)/1000000);
262}
263
264/*************************** Device Access ************************************/
265#define ahc_inb(ahc, port) \
266 bus_space_read_1((ahc)->tag, (ahc)->bsh, port)
267
268#define ahc_outb(ahc, port, value) \
269 bus_space_write_1((ahc)->tag, (ahc)->bsh, port, value)
270
271#define ahc_outsb(ahc, port, valp, count) \
272 bus_space_write_multi_1((ahc)->tag, (ahc)->bsh, port, valp, count)
273
274#define ahc_insb(ahc, port, valp, count) \
275 bus_space_read_multi_1((ahc)->tag, (ahc)->bsh, port, valp, count)
276
277static __inline void ahc_flush_device_writes(struct ahc_softc *);
278
279static __inline void
280ahc_flush_device_writes(struct ahc_softc *ahc)
281{
282 /* XXX Is this sufficient for all architectures??? */
283 ahc_inb(ahc, INTSTAT);
284}
285
286/**************************** Locking Primitives ******************************/
287/* Lock protecting internal data structures */
288static __inline void ahc_lockinit(struct ahc_softc *);
289static __inline void ahc_lock(struct ahc_softc *, unsigned long *flags);
290static __inline void ahc_unlock(struct ahc_softc *, unsigned long *flags);
291
292/* Lock held during command compeletion to the upper layer */
293static __inline void ahc_done_lockinit(struct ahc_softc *);
294static __inline void ahc_done_lock(struct ahc_softc *, unsigned long *flags);
295static __inline void ahc_done_unlock(struct ahc_softc *, unsigned long *flags);
296
297/* Lock held during ahc_list manipulation and ahc softc frees */
298static __inline void ahc_list_lockinit(void);
299static __inline void ahc_list_lock(unsigned long *flags);
300static __inline void ahc_list_unlock(unsigned long *flags);
301
302static __inline void
303ahc_lockinit(struct ahc_softc *ahc)
304{
305}
306
307static __inline void
308ahc_lock(struct ahc_softc *ahc, unsigned long *flags)
309{
310 *flags = splcam();
311}
312
313static __inline void
314ahc_unlock(struct ahc_softc *ahc, unsigned long *flags)
315{
316 splx(*flags);
317}
318
319/* Lock held during command compeletion to the upper layer */
320static __inline void
321ahc_done_lockinit(struct ahc_softc *ahc)
322{
323}
324
325static __inline void
326ahc_done_lock(struct ahc_softc *ahc, unsigned long *flags)
327{
328}
329
330static __inline void
331ahc_done_unlock(struct ahc_softc *ahc, unsigned long *flags)
332{
333}
334
335/* Lock held during ahc_list manipulation and ahc softc frees */
336static __inline void
337ahc_list_lockinit(void)
338{
339}
340
341static __inline void
342ahc_list_lock(unsigned long *flags)
343{
344}
345
346static __inline void
347ahc_list_unlock(unsigned long *flags)
348{
349}
350/****************************** OS Primitives *********************************/
351#define ahc_delay DELAY
352
353/************************** Transaction Operations ****************************/
354static __inline void ahc_set_transaction_status(struct scb *, uint32_t);
355static __inline void ahc_set_scsi_status(struct scb *, uint32_t);
356static __inline uint32_t ahc_get_transaction_status(struct scb *);
357static __inline uint32_t ahc_get_scsi_status(struct scb *);
358static __inline void ahc_set_transaction_tag(struct scb *, int, u_int);
359static __inline u_long ahc_get_transfer_length(struct scb *);
360static __inline int ahc_get_transfer_dir(struct scb *);
361static __inline void ahc_set_residual(struct scb *, u_long);
362static __inline void ahc_set_sense_residual(struct scb *, u_long);
363static __inline u_long ahc_get_residual(struct scb *);
364static __inline int ahc_perform_autosense(struct scb *);
365static __inline uint32_t ahc_get_sense_bufsize(struct ahc_softc*, struct scb*);
366static __inline void ahc_freeze_ccb(union ccb *ccb);
367static __inline void ahc_freeze_scb(struct scb *scb);
368static __inline void ahc_platform_freeze_devq(struct ahc_softc *, struct scb *);
369static __inline int ahc_platform_abort_scbs(struct ahc_softc *ahc, int target,
370 char channel, int lun, u_int tag,
371 role_t role, uint32_t status);
372
373static __inline
374void ahc_set_transaction_status(struct scb *scb, uint32_t status)
375{
376 scb->io_ctx->ccb_h.status &= ~CAM_STATUS_MASK;
377 scb->io_ctx->ccb_h.status |= status;
378}
379
380static __inline
381void ahc_set_scsi_status(struct scb *scb, uint32_t status)
382{
383 scb->io_ctx->csio.scsi_status = status;
384}
385
386static __inline
387uint32_t ahc_get_transaction_status(struct scb *scb)
388{
389 return (scb->io_ctx->ccb_h.status & CAM_STATUS_MASK);
390}
391
392static __inline
393uint32_t ahc_get_scsi_status(struct scb *scb)
394{
395 return (scb->io_ctx->csio.scsi_status);
396}
397
398static __inline
399void ahc_set_transaction_tag(struct scb *scb, int enabled, u_int type)
400{
401 scb->io_ctx->csio.tag_action = type;
402 if (enabled)
403 scb->io_ctx->ccb_h.flags |= CAM_TAG_ACTION_VALID;
404 else
405 scb->io_ctx->ccb_h.flags &= ~CAM_TAG_ACTION_VALID;
406}
407
408static __inline
409u_long ahc_get_transfer_length(struct scb *scb)
410{
411 return (scb->io_ctx->csio.dxfer_len);
412}
413
414static __inline
415int ahc_get_transfer_dir(struct scb *scb)
416{
417 return (scb->io_ctx->ccb_h.flags & CAM_DIR_MASK);
418}
419
420static __inline
421void ahc_set_residual(struct scb *scb, u_long resid)
422{
423 scb->io_ctx->csio.resid = resid;
424}
425
426static __inline
427void ahc_set_sense_residual(struct scb *scb, u_long resid)
428{
429 scb->io_ctx->csio.sense_resid = resid;
430}
431
432static __inline
433u_long ahc_get_residual(struct scb *scb)
434{
435 return (scb->io_ctx->csio.resid);
436}
437
438static __inline
439int ahc_perform_autosense(struct scb *scb)
440{
441 return (!(scb->io_ctx->ccb_h.flags & CAM_DIS_AUTOSENSE));
442}
443
444static __inline uint32_t
445ahc_get_sense_bufsize(struct ahc_softc *ahc, struct scb *scb)
446{
447 return (sizeof(struct scsi_sense_data));
448}
449
450static __inline void
451ahc_freeze_ccb(union ccb *ccb)
452{
453 if ((ccb->ccb_h.status & CAM_DEV_QFRZN) == 0) {
454 ccb->ccb_h.status |= CAM_DEV_QFRZN;
455 xpt_freeze_devq(ccb->ccb_h.path, /*count*/1);
456 }
457}
458
459static __inline void
460ahc_freeze_scb(struct scb *scb)
461{
462 ahc_freeze_ccb(scb->io_ctx);
463}
464
465static __inline void
466ahc_platform_freeze_devq(struct ahc_softc *ahc, struct scb *scb)
467{
468 /* Nothing to do here for FreeBSD */
469}
470
471static __inline int
472ahc_platform_abort_scbs(struct ahc_softc *ahc, int target,
473 char channel, int lun, u_int tag,
474 role_t role, uint32_t status)
475{
476 /* Nothing to do here for FreeBSD */
477 return (0);
478}
479
480static __inline void
481ahc_platform_scb_free(struct ahc_softc *ahc, struct scb *scb)
482{
483 /* What do we do to generically handle driver resource shortages??? */
484 if ((ahc->flags & AHC_RESOURCE_SHORTAGE) != 0
485 && scb->io_ctx != NULL
486 && (scb->io_ctx->ccb_h.status & CAM_RELEASE_SIMQ) == 0) {
487 scb->io_ctx->ccb_h.status |= CAM_RELEASE_SIMQ;
488 ahc->flags &= ~AHC_RESOURCE_SHORTAGE;
489 }
490 scb->io_ctx = NULL;
491}
492
493/********************************** PCI ***************************************/
494#ifdef AHC_PCI_CONFIG
495static __inline uint32_t ahc_pci_read_config(ahc_dev_softc_t pci,
496 int reg, int width);
497static __inline void ahc_pci_write_config(ahc_dev_softc_t pci,
498 int reg, uint32_t value,
499 int width);
500static __inline int ahc_get_pci_function(ahc_dev_softc_t);
501static __inline int ahc_get_pci_slot(ahc_dev_softc_t);
502static __inline int ahc_get_pci_bus(ahc_dev_softc_t);
503
504int ahc_pci_map_registers(struct ahc_softc *ahc);
505int ahc_pci_map_int(struct ahc_softc *ahc);
506
507static __inline uint32_t
508ahc_pci_read_config(ahc_dev_softc_t pci, int reg, int width)
509{
510 return (pci_read_config(pci, reg, width));
511}
512
513static __inline void
514ahc_pci_write_config(ahc_dev_softc_t pci, int reg, uint32_t value, int width)
515{
516 pci_write_config(pci, reg, value, width);
517}
518
519static __inline int
520ahc_get_pci_function(ahc_dev_softc_t pci)
521{
522 return (pci_get_function(pci));
523}
524
525static __inline int
526ahc_get_pci_slot(ahc_dev_softc_t pci)
527{
528 return (pci_get_slot(pci));
529}
530
531static __inline int
532ahc_get_pci_bus(ahc_dev_softc_t pci)
533{
534 return (pci_get_bus(pci));
535}
536
537typedef enum
538{
539 AHC_POWER_STATE_D0,
540 AHC_POWER_STATE_D1,
541 AHC_POWER_STATE_D2,
542 AHC_POWER_STATE_D3
543} ahc_power_state;
544
545void ahc_power_state_change(struct ahc_softc *ahc,
546 ahc_power_state new_state);
547#endif
548/******************************** VL/EISA *************************************/
549int aic7770_map_registers(struct ahc_softc *ahc, u_int port);
550int aic7770_map_int(struct ahc_softc *ahc, int irq);
551
552/********************************* Debug **************************************/
553static __inline void ahc_print_path(struct ahc_softc *, struct scb *);
554static __inline void ahc_platform_dump_card_state(struct ahc_softc *ahc);
555
556static __inline void
557ahc_print_path(struct ahc_softc *ahc, struct scb *scb)
558{
559 xpt_print_path(scb->io_ctx->ccb_h.path);
560}
561
562static __inline void
563ahc_platform_dump_card_state(struct ahc_softc *ahc)
564{
565 /* Nothing to do here for FreeBSD */
566}
567/**************************** Transfer Settings *******************************/
568void ahc_notify_xfer_settings_change(struct ahc_softc *,
569 struct ahc_devinfo *);
570void ahc_platform_set_tags(struct ahc_softc *, struct ahc_devinfo *,
571 int /*enable*/);
572
573/************************* Initialization/Teardown ****************************/
574int ahc_platform_alloc(struct ahc_softc *ahc, void *platform_arg);
575void ahc_platform_free(struct ahc_softc *ahc);
576int ahc_map_int(struct ahc_softc *ahc);
577int ahc_attach(struct ahc_softc *);
578int ahc_softc_comp(struct ahc_softc *lahc, struct ahc_softc *rahc);
579int ahc_detach(device_t);
580
581/****************************** Interrupts ************************************/
582void ahc_platform_intr(void *);
583static __inline void ahc_platform_flushwork(struct ahc_softc *ahc);
584static __inline void
585ahc_platform_flushwork(struct ahc_softc *ahc)
586{
587}
588
589/************************ Misc Function Declarations **************************/
590void ahc_done(struct ahc_softc *ahc, struct scb *scb);
591void ahc_send_async(struct ahc_softc *, char /*channel*/,
592 u_int /*target*/, u_int /*lun*/, ac_code, void *arg);
593#endif /* _AIC7XXX_FREEBSD_H_ */