]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - sys/dev/aic7xxx/aic7xxx_osm.h
This commit was generated by cvs2svn to compensate for changes in r103373,
[FreeBSD/FreeBSD.git] / sys / dev / aic7xxx / aic7xxx_osm.h
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: //depot/aic7xxx/freebsd/dev/aic7xxx/aic7xxx_osm.h#10 $
33  *
34  * $FreeBSD$
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 #ifdef AHC_ALLOW_MEMIO
62 #include <machine/bus_memio.h>
63 #endif
64 #endif
65 #include <machine/bus_pio.h>
66 #include <machine/bus.h>
67 #include <machine/endian.h>
68 #include <machine/clock.h>
69 #include <machine/resource.h>
70
71 #include <sys/rman.h>
72
73 #if NPCI > 0
74 #include <pci/pcireg.h>
75 #include <pci/pcivar.h>
76 #endif
77
78 #include <cam/cam.h>
79 #include <cam/cam_ccb.h>
80 #include <cam/cam_debug.h>
81 #include <cam/cam_sim.h>
82 #include <cam/cam_xpt_sim.h>
83
84 #include <cam/scsi/scsi_all.h>
85 #include <cam/scsi/scsi_message.h>
86
87 #ifdef CAM_NEW_TRAN_CODE
88 #define AHC_NEW_TRAN_SETTINGS
89 #endif /* CAM_NEW_TRAN_CODE */
90
91 /****************************** Platform Macros *******************************/
92 #define SIM_IS_SCSIBUS_B(ahc, sim)      \
93         ((sim) == ahc->platform_data->sim_b)
94 #define SIM_CHANNEL(ahc, sim)   \
95         (((sim) == ahc->platform_data->sim_b) ? 'B' : 'A')
96 #define SIM_SCSI_ID(ahc, sim)   \
97         (((sim) == ahc->platform_data->sim_b) ? ahc->our_id_b : ahc->our_id)
98 #define SIM_PATH(ahc, sim)      \
99         (((sim) == ahc->platform_data->sim_b) ? ahc->platform_data->path_b \
100                                               : ahc->platform_data->path)
101 #define BUILD_SCSIID(ahc, sim, target_id, our_id) \
102         ((((target_id) << TID_SHIFT) & TID) | (our_id) \
103         | (SIM_IS_SCSIBUS_B(ahc, sim) ? TWIN_CHNLB : 0))
104
105 #define SCB_GET_SIM(ahc, scb) \
106         (SCB_GET_CHANNEL(ahc, scb) == 'A' ? (ahc)->platform_data->sim \
107                                           : (ahc)->platform_data->sim_b)
108
109 #ifndef offsetof
110 #define offsetof(type, member)  ((size_t)(&((type *)0)->member))
111 #endif
112 /************************* Forward Declarations *******************************/
113 typedef device_t ahc_dev_softc_t;
114 typedef union ccb *ahc_io_ctx_t;
115
116 /***************************** Bus Space/DMA **********************************/
117 #define ahc_dma_tag_create(ahc, parent_tag, alignment, boundary,        \
118                            lowaddr, highaddr, filter, filterarg,        \
119                            maxsize, nsegments, maxsegsz, flags,         \
120                            dma_tagp)                                    \
121         bus_dma_tag_create(parent_tag, alignment, boundary,             \
122                            lowaddr, highaddr, filter, filterarg,        \
123                            maxsize, nsegments, maxsegsz, flags,         \
124                            dma_tagp)
125
126 #define ahc_dma_tag_destroy(ahc, tag)                                   \
127         bus_dma_tag_destroy(tag)
128
129 #define ahc_dmamem_alloc(ahc, dmat, vaddr, flags, mapp)                 \
130         bus_dmamem_alloc(dmat, vaddr, flags, mapp)
131
132 #define ahc_dmamem_free(ahc, dmat, vaddr, map)                          \
133         bus_dmamem_free(dmat, vaddr, map)
134
135 #define ahc_dmamap_create(ahc, tag, flags, mapp)                        \
136         bus_dmamap_create(tag, flags, mapp)
137
138 #define ahc_dmamap_destroy(ahc, tag, map)                               \
139         bus_dmamap_destroy(tag, map)
140
141 #define ahc_dmamap_load(ahc, dmat, map, addr, buflen, callback,         \
142                         callback_arg, flags)                            \
143         bus_dmamap_load(dmat, map, addr, buflen, callback, callback_arg, flags)
144
145 #define ahc_dmamap_unload(ahc, tag, map)                                \
146         bus_dmamap_unload(tag, map)
147
148 /* XXX Need to update Bus DMA for partial map syncs */
149 #define ahc_dmamap_sync(ahc, dma_tag, dmamap, offset, len, op)          \
150         bus_dmamap_sync(dma_tag, dmamap, op)
151
152 /************************ Tunable Driver Parameters  **************************/
153 /*
154  * The number of dma segments supported.  The sequencer can handle any number
155  * of physically contiguous S/G entrys.  To reduce the driver's memory
156  * consumption, we limit the number supported to be sufficient to handle
157  * the largest mapping supported by the kernel, MAXPHYS.  Assuming the
158  * transfer is as fragmented as possible and unaligned, this turns out to
159  * be the number of paged sized transfers in MAXPHYS plus an extra element
160  * to handle any unaligned residual.  The sequencer fetches SG elements
161  * in cacheline sized chucks, so make the number per-transaction an even
162  * multiple of 16 which should align us on even the largest of cacheline
163  * boundaries. 
164  */
165 #define AHC_NSEG (roundup(btoc(MAXPHYS) + 1, 16))
166
167 /* This driver supports target mode */
168 #define AHC_TARGET_MODE 1
169
170 /************************** Softc/SCB Platform Data ***************************/
171 struct ahc_platform_data {
172         /*
173          * Hooks into the XPT.
174          */
175         struct  cam_sim         *sim;
176         struct  cam_sim         *sim_b;
177         struct  cam_path        *path;
178         struct  cam_path        *path_b;
179
180         int                      regs_res_type;
181         int                      regs_res_id;
182         int                      irq_res_type;
183         struct resource         *regs;
184         struct resource         *irq;
185         void                    *ih;
186         eventhandler_tag         eh;
187 };
188
189 struct scb_platform_data {
190 };
191
192 /********************************* Byte Order *********************************/
193 #if __FreeBSD_version >= 500000
194 #define ahc_htobe16(x) htobe16(x)
195 #define ahc_htobe32(x) htobe32(x)
196 #define ahc_htobe64(x) htobe64(x)
197 #define ahc_htole16(x) htole16(x)
198 #define ahc_htole32(x) htole32(x)
199 #define ahc_htole64(x) htole64(x)
200
201 #define ahc_be16toh(x) be16toh(x)
202 #define ahc_be32toh(x) be32toh(x)
203 #define ahc_be64toh(x) be64toh(x)
204 #define ahc_le16toh(x) le16toh(x)
205 #define ahc_le32toh(x) le32toh(x)
206 #define ahc_le64toh(x) le64toh(x)
207 #else
208 #define ahc_htobe16(x) (x)
209 #define ahc_htobe32(x) (x)
210 #define ahc_htobe64(x) (x)
211 #define ahc_htole16(x) (x)
212 #define ahc_htole32(x) (x)
213 #define ahc_htole64(x) (x)
214
215 #define ahc_be16toh(x) (x)
216 #define ahc_be32toh(x) (x)
217 #define ahc_be64toh(x) (x)
218 #define ahc_le16toh(x) (x)
219 #define ahc_le32toh(x) (x)
220 #define ahc_le64toh(x) (x)
221 #endif
222
223 /***************************** Core Includes **********************************/
224 #if AHC_REG_PRETTY_PRINT
225 #define AIC_DEBUG_REGISTERS 1
226 #else
227 #define AIC_DEBUG_REGISTERS 0
228 #endif
229 #include <dev/aic7xxx/aic7xxx.h>
230
231 /*************************** Device Access ************************************/
232 #define ahc_inb(ahc, port)                              \
233         bus_space_read_1((ahc)->tag, (ahc)->bsh, port)
234
235 #define ahc_outb(ahc, port, value)                      \
236         bus_space_write_1((ahc)->tag, (ahc)->bsh, port, value)
237
238 #define ahc_outsb(ahc, port, valp, count)               \
239         bus_space_write_multi_1((ahc)->tag, (ahc)->bsh, port, valp, count)
240
241 #define ahc_insb(ahc, port, valp, count)                \
242         bus_space_read_multi_1((ahc)->tag, (ahc)->bsh, port, valp, count)
243
244 static __inline void ahc_flush_device_writes(struct ahc_softc *);
245
246 static __inline void
247 ahc_flush_device_writes(struct ahc_softc *ahc)
248 {
249         /* XXX Is this sufficient for all architectures??? */
250         ahc_inb(ahc, INTSTAT);
251 }
252
253 /**************************** Locking Primitives ******************************/
254 /* Lock protecting internal data structures */
255 static __inline void ahc_lockinit(struct ahc_softc *);
256 static __inline void ahc_lock(struct ahc_softc *, unsigned long *flags);
257 static __inline void ahc_unlock(struct ahc_softc *, unsigned long *flags);
258
259 /* Lock held during command compeletion to the upper layer */
260 static __inline void ahc_done_lockinit(struct ahc_softc *);
261 static __inline void ahc_done_lock(struct ahc_softc *, unsigned long *flags);
262 static __inline void ahc_done_unlock(struct ahc_softc *, unsigned long *flags);
263
264 /* Lock held during ahc_list manipulation and ahc softc frees */
265 static __inline void ahc_list_lockinit(void);
266 static __inline void ahc_list_lock(unsigned long *flags);
267 static __inline void ahc_list_unlock(unsigned long *flags);
268
269 static __inline void
270 ahc_lockinit(struct ahc_softc *ahc)
271 {
272 }
273
274 static __inline void
275 ahc_lock(struct ahc_softc *ahc, unsigned long *flags)
276 {
277         *flags = splcam();
278 }
279
280 static __inline void
281 ahc_unlock(struct ahc_softc *ahc, unsigned long *flags)
282 {
283         splx(*flags);
284 }
285
286 /* Lock held during command compeletion to the upper layer */
287 static __inline void
288 ahc_done_lockinit(struct ahc_softc *ahc)
289 {
290 }
291
292 static __inline void
293 ahc_done_lock(struct ahc_softc *ahc, unsigned long *flags)
294 {
295 }
296
297 static __inline void
298 ahc_done_unlock(struct ahc_softc *ahc, unsigned long *flags)
299 {
300 }
301
302 /* Lock held during ahc_list manipulation and ahc softc frees */
303 static __inline void
304 ahc_list_lockinit()
305 {
306 }
307
308 static __inline void
309 ahc_list_lock(unsigned long *flags)
310 {
311 }
312
313 static __inline void
314 ahc_list_unlock(unsigned long *flags)
315 {
316 }
317 /****************************** OS Primitives *********************************/
318 #define ahc_delay DELAY
319
320 /************************** Transaction Operations ****************************/
321 static __inline void ahc_set_transaction_status(struct scb *, uint32_t);
322 static __inline void ahc_set_scsi_status(struct scb *, uint32_t);
323 static __inline uint32_t ahc_get_transaction_status(struct scb *);
324 static __inline uint32_t ahc_get_scsi_status(struct scb *);
325 static __inline void ahc_set_transaction_tag(struct scb *, int, u_int);
326 static __inline u_long ahc_get_transfer_length(struct scb *);
327 static __inline int ahc_get_transfer_dir(struct scb *);
328 static __inline void ahc_set_residual(struct scb *, u_long);
329 static __inline void ahc_set_sense_residual(struct scb *, u_long);
330 static __inline u_long ahc_get_residual(struct scb *);
331 static __inline int ahc_perform_autosense(struct scb *);
332 static __inline uint32_t ahc_get_sense_bufsize(struct ahc_softc*, struct scb*);
333 static __inline void ahc_freeze_ccb(union ccb *ccb);
334 static __inline void ahc_freeze_scb(struct scb *scb);
335 static __inline void ahc_platform_freeze_devq(struct ahc_softc *, struct scb *);
336 static __inline int  ahc_platform_abort_scbs(struct ahc_softc *ahc, int target,
337                                              char channel, int lun, u_int tag,
338                                              role_t role, uint32_t status);
339
340 static __inline
341 void ahc_set_transaction_status(struct scb *scb, uint32_t status)
342 {
343         scb->io_ctx->ccb_h.status &= ~CAM_STATUS_MASK;
344         scb->io_ctx->ccb_h.status |= status;
345 }
346
347 static __inline
348 void ahc_set_scsi_status(struct scb *scb, uint32_t status)
349 {
350         scb->io_ctx->csio.scsi_status = status;
351 }
352
353 static __inline
354 uint32_t ahc_get_transaction_status(struct scb *scb)
355 {
356         return (scb->io_ctx->ccb_h.status & CAM_STATUS_MASK);
357 }
358
359 static __inline
360 uint32_t ahc_get_scsi_status(struct scb *scb)
361 {
362         return (scb->io_ctx->csio.scsi_status);
363 }
364
365 static __inline
366 void ahc_set_transaction_tag(struct scb *scb, int enabled, u_int type)
367 {
368         scb->io_ctx->csio.tag_action = type;
369         if (enabled)
370                 scb->io_ctx->ccb_h.flags |= CAM_TAG_ACTION_VALID;
371         else
372                 scb->io_ctx->ccb_h.flags &= ~CAM_TAG_ACTION_VALID;
373 }
374
375 static __inline
376 u_long ahc_get_transfer_length(struct scb *scb)
377 {
378         return (scb->io_ctx->csio.dxfer_len);
379 }
380
381 static __inline
382 int ahc_get_transfer_dir(struct scb *scb)
383 {
384         return (scb->io_ctx->ccb_h.flags & CAM_DIR_MASK);
385 }
386
387 static __inline
388 void ahc_set_residual(struct scb *scb, u_long resid)
389 {
390         scb->io_ctx->csio.resid = resid;
391 }
392
393 static __inline
394 void ahc_set_sense_residual(struct scb *scb, u_long resid)
395 {
396         scb->io_ctx->csio.sense_resid = resid;
397 }
398
399 static __inline
400 u_long ahc_get_residual(struct scb *scb)
401 {
402         return (scb->io_ctx->csio.resid);
403 }
404
405 static __inline
406 int ahc_perform_autosense(struct scb *scb)
407 {
408         return (!(scb->io_ctx->ccb_h.flags & CAM_DIS_AUTOSENSE));
409 }
410
411 static __inline uint32_t
412 ahc_get_sense_bufsize(struct ahc_softc *ahc, struct scb *scb)
413 {
414         return (sizeof(struct scsi_sense_data));
415 }
416
417 static __inline void
418 ahc_freeze_ccb(union ccb *ccb)
419 {
420         if ((ccb->ccb_h.status & CAM_DEV_QFRZN) == 0) {
421                 ccb->ccb_h.status |= CAM_DEV_QFRZN;
422                 xpt_freeze_devq(ccb->ccb_h.path, /*count*/1);
423         }
424 }
425
426 static __inline void
427 ahc_freeze_scb(struct scb *scb)
428 {
429         ahc_freeze_ccb(scb->io_ctx);
430 }
431
432 static __inline void
433 ahc_platform_freeze_devq(struct ahc_softc *ahc, struct scb *scb)
434 {
435         /* Nothing to do here for FreeBSD */
436 }
437
438 static __inline int
439 ahc_platform_abort_scbs(struct ahc_softc *ahc, int target,
440                         char channel, int lun, u_int tag,
441                         role_t role, uint32_t status)
442 {
443         /* Nothing to do here for FreeBSD */
444         return (0);
445 }
446
447 static __inline void
448 ahc_platform_scb_free(struct ahc_softc *ahc, struct scb *scb)
449 {
450         /* What do we do to generically handle driver resource shortages??? */
451         if ((ahc->flags & AHC_RESOURCE_SHORTAGE) != 0
452          && scb->io_ctx != NULL
453          && (scb->io_ctx->ccb_h.status & CAM_RELEASE_SIMQ) == 0) {
454                 scb->io_ctx->ccb_h.status |= CAM_RELEASE_SIMQ;
455                 ahc->flags &= ~AHC_RESOURCE_SHORTAGE;
456         }
457         scb->io_ctx = NULL;
458 }
459
460 /********************************** PCI ***************************************/
461 #ifdef AHC_PCI_CONFIG
462 static __inline uint32_t ahc_pci_read_config(ahc_dev_softc_t pci,
463                                              int reg, int width);
464 static __inline void     ahc_pci_write_config(ahc_dev_softc_t pci,
465                                               int reg, uint32_t value,
466                                               int width);
467 static __inline int      ahc_get_pci_function(ahc_dev_softc_t);
468 static __inline int      ahc_get_pci_slot(ahc_dev_softc_t);
469 static __inline int      ahc_get_pci_bus(ahc_dev_softc_t);
470
471 int                      ahc_pci_map_registers(struct ahc_softc *ahc);
472 int                      ahc_pci_map_int(struct ahc_softc *ahc);
473
474 static __inline uint32_t
475 ahc_pci_read_config(ahc_dev_softc_t pci, int reg, int width)
476 {
477         return (pci_read_config(pci, reg, width));
478 }
479
480 static __inline void
481 ahc_pci_write_config(ahc_dev_softc_t pci, int reg, uint32_t value, int width)
482 {
483         pci_write_config(pci, reg, value, width);
484 }
485
486 static __inline int
487 ahc_get_pci_function(ahc_dev_softc_t pci)
488 {
489         return (pci_get_function(pci));
490 }
491
492 static __inline int
493 ahc_get_pci_slot(ahc_dev_softc_t pci)
494 {
495         return (pci_get_slot(pci));
496 }
497
498 static __inline int
499 ahc_get_pci_bus(ahc_dev_softc_t pci)
500 {
501         return (pci_get_bus(pci));
502 }
503
504 typedef enum
505 {
506         AHC_POWER_STATE_D0,
507         AHC_POWER_STATE_D1,
508         AHC_POWER_STATE_D2,
509         AHC_POWER_STATE_D3
510 } ahc_power_state;
511
512 void ahc_power_state_change(struct ahc_softc *ahc,
513                             ahc_power_state new_state);
514 #endif
515 /******************************** VL/EISA *************************************/
516 int aic7770_map_registers(struct ahc_softc *ahc, u_int port);
517 int aic7770_map_int(struct ahc_softc *ahc, int irq);
518
519 /********************************* Debug **************************************/
520 static __inline void    ahc_print_path(struct ahc_softc *, struct scb *);
521 static __inline void    ahc_platform_dump_card_state(struct ahc_softc *ahc);
522
523 static __inline void
524 ahc_print_path(struct ahc_softc *ahc, struct scb *scb)
525 {
526         xpt_print_path(scb->io_ctx->ccb_h.path);
527 }
528
529 static __inline void
530 ahc_platform_dump_card_state(struct ahc_softc *ahc)
531 {
532         /* Nothing to do here for FreeBSD */
533 }
534 /**************************** Transfer Settings *******************************/
535 void      ahc_notify_xfer_settings_change(struct ahc_softc *,
536                                           struct ahc_devinfo *);
537 void      ahc_platform_set_tags(struct ahc_softc *, struct ahc_devinfo *,
538                                 int /*enable*/);
539
540 /************************* Initialization/Teardown ****************************/
541 int       ahc_platform_alloc(struct ahc_softc *ahc, void *platform_arg);
542 void      ahc_platform_free(struct ahc_softc *ahc);
543 int       ahc_map_int(struct ahc_softc *ahc);
544 int       ahc_attach(struct ahc_softc *);
545 int       ahc_softc_comp(struct ahc_softc *lahc, struct ahc_softc *rahc);
546 int       ahc_detach(device_t);
547
548 /****************************** Interrupts ************************************/
549 void                    ahc_platform_intr(void *);
550 static __inline void    ahc_platform_flushwork(struct ahc_softc *ahc);
551 static __inline void
552 ahc_platform_flushwork(struct ahc_softc *ahc)
553 {
554 }
555
556 /************************ Misc Function Declarations **************************/
557 timeout_t ahc_timeout;
558 void      ahc_done(struct ahc_softc *ahc, struct scb *scb);
559 void      ahc_send_async(struct ahc_softc *, char /*channel*/,
560                          u_int /*target*/, u_int /*lun*/, ac_code, void *arg);
561 #endif  /* _AIC7XXX_FREEBSD_H_ */