aic79xx_osm.h revision 1.1 1 /* $NetBSD: aic79xx_osm.h,v 1.1 2003/04/21 00:14:52 fvdl Exp $ */
2
3 /*
4 * NetBSD platform specific driver option settings, data structures,
5 * function declarations and includes.
6 *
7 * Copyright (c) 1994-2001 Justin T. Gibbs.
8 * Copyright (c) 2001-2002 Adaptec Inc.
9 * All rights reserved.
10 *
11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions
13 * are met:
14 * 1. Redistributions of source code must retain the above copyright
15 * notice, this list of conditions, and the following disclaimer,
16 * without modification.
17 * 2. The name of the author may not be used to endorse or promote products
18 * derived from this software without specific prior written permission.
19 *
20 * Alternatively, this software may be distributed under the terms of the
21 * GNU Public License ("GPL").
22 *
23 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
24 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
25 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
26 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR
27 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
28 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
29 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
30 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
31 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
32 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
33 * SUCH DAMAGE.
34 *
35 * $NetBSD: aic79xx_osm.h,v 1.1 2003/04/21 00:14:52 fvdl Exp $
36 *
37 * //depot/aic7xxx/freebsd/dev/aic7xxx/aic79xx_osm.h#19 $$NetBSD: aic79xx_osm.h,v 1.1 2003/04/21 00:14:52 fvdl Exp $
38 *
39 * $FreeBSD: src/sys/dev/aic7xxx/aic79xx_osm.h,v 1.8 2002/12/04 22:51:29 scottl Exp $
40 */
41 /*
42 * Ported from FreeBSD by Pascal Renauld, Network Storage Solutions, Inc.
43 * - April 2003
44 */
45
46 #ifndef _AIC79XX_NETBSD_H_
47 #define _AIC79XX_NETBSD_H_
48
49 #include "opt_ahd.h" /* for config options */
50
51 #include <sys/param.h>
52 #include <sys/kernel.h>
53 #include <sys/systm.h>
54 #include <sys/device.h>
55 #include <sys/malloc.h>
56 #include <sys/buf.h>
57 #include <sys/proc.h>
58 #include <sys/scsiio.h>
59 #include <sys/reboot.h>
60 #include <sys/kthread.h>
61
62 #include <dev/pci/pcireg.h>
63 #include <dev/pci/pcivar.h>
64
65 #include <machine/bus.h>
66 #include <machine/intr.h>
67
68 #include <dev/scsipi/scsi_all.h>
69 #include <dev/scsipi/scsipi_all.h>
70 #include <dev/scsipi/scsi_message.h>
71 #include <dev/scsipi/scsipi_debug.h>
72 #include <dev/scsipi/scsiconf.h>
73 #include <dev/scsipi/scsi_iu.h>
74
75 #include <uvm/uvm_extern.h>
76
77
78 /****************************** Platform Macros *******************************/
79 #define SIM_IS_SCSIBUS_B(ahd, sim) \
80 (0)
81 #define SIM_CHANNEL(ahd, sim) \
82 ('A')
83 #define SIM_SCSI_ID(ahd, sim) \
84 (ahd->our_id)
85 #define SIM_PATH(ahd, sim) \
86 (ahd->platform_data->path)
87 #define BUILD_SCSIID(ahd, sim, target_id, our_id) \
88 ((((target_id) << TID_SHIFT) & TID) | (our_id))
89
90
91 #define SCB_GET_SIM(ahd, scb) \
92 ((ahd)->platform_data->sim)
93
94 #ifndef offsetof
95 #define offsetof(type, member) ((size_t)(&((type *)0)->member))
96 #endif
97
98 /************************* Forward Declarations *******************************/
99 typedef pcireg_t ahd_dev_softc_t;
100 /***************************** Bus Space/DMA **********************************/
101 #define ahd_dma_tag_create(ahd, parent_tag, alignment, boundary, \
102 lowaddr, highaddr, filter, filterarg, \
103 maxsize, nsegments, maxsegsz, flags, \
104 dma_tagp) \
105 bus_dma_tag_create(parent_tag, alignment, boundary, \
106 lowaddr, highaddr, filter, filterarg, \
107 maxsize, nsegments, maxsegsz, flags, \
108 dma_tagp)
109
110 #define ahd_dma_tag_destroy(ahd, tag) \
111 bus_dma_tag_destroy(tag)
112
113 #define ahd_dmamem_alloc(ahd, dmat, vaddr, flags, mapp) \
114 bus_dmamem_alloc(dmat, vaddr, flags, mapp)
115
116 #define ahd_dmamem_free(ahd, dmat, vaddr, map) \
117 bus_dmamem_free(dmat, vaddr, map)
118
119 #define ahd_dmamap_create(ahd, tag, flags, mapp) \
120 bus_dmamap_create(tag, flags, mapp)
121
122 #define ahd_dmamap_destroy(ahd, tag, map) \
123 bus_dmamap_destroy(tag, map)
124
125 #define ahd_dmamap_load(ahd, dmat, map, addr, buflen, callback, \
126 callback_arg, flags) \
127 bus_dmamap_load(dmat, map, addr, buflen, callback, callback_arg, flags)
128
129 #define ahd_dmamap_unload(ahd, tag, map) \
130 bus_dmamap_unload(tag, map)
131
132 /* XXX Need to update Bus DMA for partial map syncs */
133 #define ahd_dmamap_sync(ahd, dma_tag, dmamap, offset, len, op) \
134 bus_dmamap_sync(dma_tag, dmamap, offset, len, op)
135
136 /************************ Tunable Driver Parameters **************************/
137 /*
138 * The number of dma segments supported. The sequencer can handle any number
139 * of physically contiguous S/G entrys. To reduce the driver's memory
140 * consumption, we limit the number supported to be sufficient to handle
141 * the largest mapping supported by the kernel, MAXPHYS. Assuming the
142 * transfer is as fragmented as possible and unaligned, this turns out to
143 * be the number of paged sized transfers in MAXPHYS plus an extra element
144 * to handle any unaligned residual. The sequencer fetches SG elements
145 * in cacheline sized chucks, so make the number per-transaction an even
146 * multiple of 16 which should align us on even the largest of cacheline
147 * boundaries.
148 */
149 #define AHD_NSEG (roundup(btoc(MAXPHYS) + 1, 16))
150
151 /* This driver supports target mode */
152 #if NOT_YET
153 #define AHD_TARGET_MODE 1
154 #endif
155
156 /************************** Softc/SCB Platform Data ***************************/
157 struct ahd_platform_data {
158 };
159
160 struct scb_platform_data {
161 };
162
163 /********************************* Byte Order *********************************/
164 #define ahd_htobe16(x) htobe16(x)
165 #define ahd_htobe32(x) htobe32(x)
166 #define ahd_htobe64(x) htobe64(x)
167 #define ahd_htole16(x) htole16(x)
168 #define ahd_htole32(x) htole32(x)
169 #define ahd_htole64(x) htole64(x)
170
171 #define ahd_be16toh(x) be16toh(x)
172 #define ahd_be32toh(x) be32toh(x)
173 #define ahd_be64toh(x) be64toh(x)
174 #define ahd_le16toh(x) le16toh(x)
175 #define ahd_le32toh(x) le32toh(x)
176 #define ahd_le64toh(x) le64toh(x)
177
178 /************************** Timer DataStructures ******************************/
179 typedef struct callout ahd_timer_t;
180
181 /***************************** Core Includes **********************************/
182 #if AHD_REG_PRETTY_PRINT
183 #define AIC_DEBUG_REGISTERS 1
184 #else
185 #define AIC_DEBUG_REGISTERS 0
186 #endif
187 #include <dev/ic/aic79xxvar.h>
188
189 /***************************** Timer Facilities *******************************/
190 void ahd_timeout(void*);
191 #define ahd_timer_init(timer) callout_init(timer)
192 #define ahd_timer_stop callout_stop
193
194 static __inline void
195 ahd_timer_reset(ahd_timer_t *timer, u_int usec, ahd_callback_t *func, void *arg)
196 {
197 callout_reset(timer, (usec * hz)/1000000, func, arg);
198 }
199
200 static __inline void
201 ahd_scb_timer_reset(struct scb *scb, u_int usec)
202 {
203 if (!(scb->xs->xs_control & XS_CTL_POLL)) {
204 callout_reset(&scb->xs->xs_callout,
205 (usec * hz)/1000000, ahd_timeout, scb);
206 }
207 }
208
209 /*************************** Device Access ************************************/
210 #define ahd_inb(ahd, port) \
211 bus_space_read_1((ahd)->tags[(port) >> 8], \
212 (ahd)->bshs[(port) >> 8], (port) & 0xFF)
213
214 #define ahd_outb(ahd, port, value) \
215 bus_space_write_1((ahd)->tags[(port) >> 8], \
216 (ahd)->bshs[(port) >> 8], (port) & 0xFF, value)
217
218 #define ahd_inw_atomic(ahd, port) \
219 ahd_le16toh(bus_space_read_2((ahd)->tags[(port) >> 8], \
220 (ahd)->bshs[(port) >> 8], (port) & 0xFF))
221
222 #define ahd_outw_atomic(ahd, port, value) \
223 bus_space_write_2((ahd)->tags[(port) >> 8], \
224 (ahd)->bshs[(port) >> 8], \
225 (port & 0xFF), ahd_htole16(value))
226
227 #define ahd_outsb(ahd, port, valp, count) \
228 bus_space_write_multi_1((ahd)->tags[(port) >> 8], \
229 (ahd)->bshs[(port) >> 8], \
230 (port & 0xFF), valp, count)
231
232 #define ahd_insb(ahd, port, valp, count) \
233 bus_space_read_multi_1((ahd)->tags[(port) >> 8], \
234 (ahd)->bshs[(port) >> 8], \
235 (port & 0xFF), valp, count)
236
237 static __inline void ahd_flush_device_writes(struct ahd_softc *);
238
239 static __inline void
240 ahd_flush_device_writes(struct ahd_softc *ahd)
241 {
242 /* XXX Is this sufficient for all architectures??? */
243 ahd_inb(ahd, INTSTAT);
244 }
245
246 /**************************** Locking Primitives ******************************/
247 /* Lock protecting internal data structures */
248 static __inline void ahd_lockinit(struct ahd_softc *);
249 static __inline void ahd_lock(struct ahd_softc *, int *flags);
250 static __inline void ahd_unlock(struct ahd_softc *, int *flags);
251
252 /* Lock held during command compeletion to the upper layer */
253 static __inline void ahd_done_lockinit(struct ahd_softc *);
254 static __inline void ahd_done_lock(struct ahd_softc *, unsigned long *flags);
255 static __inline void ahd_done_unlock(struct ahd_softc *, unsigned long *flags);
256
257 /* Lock held during ahd_list manipulation and ahd softc frees */
258 static __inline void ahd_list_lockinit(void);
259 static __inline void ahd_list_lock(unsigned long *flags);
260 static __inline void ahd_list_unlock(unsigned long *flags);
261
262 static __inline void
263 ahd_lockinit(struct ahd_softc *ahd)
264 {
265 }
266
267 static __inline void
268 ahd_lock(struct ahd_softc *ahd, int *flags)
269 {
270 *flags = splbio();
271 }
272
273 static __inline void
274 ahd_unlock(struct ahd_softc *ahd, int *flags)
275 {
276 splx(*flags);
277 }
278
279 /* Lock held during command compeletion to the upper layer */
280 static __inline void
281 ahd_done_lockinit(struct ahd_softc *ahd)
282 {
283 }
284
285 static __inline void
286 ahd_done_lock(struct ahd_softc *ahd, unsigned long *flags)
287 {
288 }
289
290 static __inline void
291 ahd_done_unlock(struct ahd_softc *ahd, unsigned long *flags)
292 {
293 }
294
295 /* Lock held during ahd_list manipulation and ahd softc frees */
296 static __inline void
297 ahd_list_lockinit()
298 {
299 }
300
301 static __inline void
302 ahd_list_lock(unsigned long *flags)
303 {
304 }
305
306 static __inline void
307 ahd_list_unlock(unsigned long *flags)
308 {
309 }
310 /****************************** OS Primitives *********************************/
311 #define ahd_delay DELAY
312
313 /************************** Transaction Operations ****************************/
314 static __inline void ahd_set_transaction_status(struct scb *, uint32_t);
315 static __inline void ahd_set_scsi_status(struct scb *, uint32_t);
316 static __inline void ahd_set_xfer_status(struct scb *, uint32_t);
317 static __inline uint32_t ahd_get_transaction_status(struct scb *);
318 static __inline uint32_t ahd_get_scsi_status(struct scb *);
319 static __inline void ahd_set_transaction_tag(struct scb *, int, u_int);
320 static __inline u_long ahd_get_transfer_length(struct scb *);
321 static __inline int ahd_get_transfer_dir(struct scb *);
322 static __inline void ahd_set_residual(struct scb *, u_long);
323 static __inline void ahd_set_sense_residual(struct scb *, u_long);
324 static __inline u_long ahd_get_residual(struct scb *);
325 static __inline int ahd_perform_autosense(struct scb *);
326 static __inline uint32_t ahd_get_sense_bufsize(struct ahd_softc*, struct scb*);
327 static __inline void ahd_freeze_simq(struct ahd_softc *);
328 static __inline void ahd_release_simq(struct ahd_softc *);
329 static __inline void ahd_freeze_scb(struct scb *scb);
330 static __inline void ahd_platform_freeze_devq(struct ahd_softc *, struct scb *);
331 static __inline int ahd_platform_abort_scbs(struct ahd_softc *ahd, int target,
332 char channel, int lun, u_int tag,
333 role_t role, uint32_t status);
334
335 static __inline
336 void ahd_set_transaction_status(struct scb *scb, uint32_t status)
337 {
338 scb->xs->error = status;
339 }
340
341 static __inline
342 void ahd_set_scsi_status(struct scb *scb, uint32_t status)
343 {
344 scb->xs->xs_status = status;
345 }
346
347 static __inline
348 void ahd_set_xfer_status(struct scb *scb, uint32_t status)
349 {
350 scb->xs->status = status;
351 }
352
353 static __inline
354 uint32_t ahd_get_transaction_status(struct scb *scb)
355 {
356 return (scb->xs->error);
357 }
358
359 static __inline
360 uint32_t ahd_get_scsi_status(struct scb *scb)
361 {
362 return (scb->xs->xs_status);
363 }
364
365 static __inline
366 void ahd_set_transaction_tag(struct scb *scb, int enabled, u_int type)
367 {
368 scb->xs->xs_tag_type = type;
369 }
370
371 static __inline
372 u_long ahd_get_transfer_length(struct scb *scb)
373 {
374 return (scb->xs->datalen);
375 }
376
377 static __inline
378 int ahd_get_transfer_dir(struct scb *scb)
379 {
380 return (scb->xs->xs_control & (XS_CTL_DATA_IN|XS_CTL_DATA_OUT));
381 }
382
383 static __inline
384 void ahd_set_residual(struct scb *scb, u_long resid)
385 {
386 scb->xs->resid = resid;
387 }
388
389
390 static __inline
391 void ahd_set_sense_residual(struct scb *scb, u_long resid)
392 {
393 //scb->xs->sense.scsi_sense.extra_len = resid; /* ??? */
394 }
395
396
397 static __inline
398 u_long ahd_get_residual(struct scb *scb)
399 {
400 return (scb->xs->resid);
401 }
402
403 static __inline
404 int ahd_perform_autosense(struct scb *scb)
405 {
406 return (!(scb->flags & SCB_SENSE));
407 }
408
409 static __inline uint32_t
410 ahd_get_sense_bufsize(struct ahd_softc *ahd, struct scb *scb)
411 {
412 return (sizeof(struct scsipi_sense_data));
413 }
414
415 static __inline void
416 ahd_freeze_simq(struct ahd_softc *ahd)
417 {
418 /* do nothing for now */
419 }
420
421 static __inline void
422 ahd_release_simq(struct ahd_softc *ahd)
423 {
424 /* do nothing for now */
425 }
426
427 static __inline void
428 ahd_freeze_scb(struct scb *scb)
429 {
430 struct scsipi_xfer *xs = scb->xs;
431
432 if (!(scb->flags & SCB_FREEZE_QUEUE)) {
433 scsipi_periph_freeze(xs->xs_periph, 1);
434 scb->flags |= SCB_FREEZE_QUEUE;
435 }
436 }
437
438 static __inline void
439 ahd_platform_freeze_devq(struct ahd_softc *ahd, struct scb *scb)
440 {
441 /* Nothing to do here for NetBSD */
442 }
443
444 static __inline int
445 ahd_platform_abort_scbs(struct ahd_softc *ahd, int target,
446 char channel, int lun, u_int tag,
447 role_t role, uint32_t status)
448 {
449 /* Nothing to do here for NetBSD */
450 return (0);
451 }
452
453 static __inline void
454 ahd_platform_scb_free(struct ahd_softc *ahd, struct scb *scb)
455 {
456 #ifdef _FreeBSD_
457 /* What do we do to generically handle driver resource shortages??? */
458 if ((ahd->flags & AHD_RESOURCE_SHORTAGE) != 0
459 && scb->io_ctx != NULL
460 && (scb->io_ctx->ccb_h.status & CAM_RELEASE_SIMQ) == 0) {
461 scb->io_ctx->ccb_h.status |= CAM_RELEASE_SIMQ;
462 ahd->flags &= ~AHD_RESOURCE_SHORTAGE;
463 }
464 scb->io_ctx = NULL;
465 #endif /* end of modification */
466 }
467
468 /********************************** PCI ***************************************/
469 #if AHD_PCI_CONFIG > 0
470 static __inline uint32_t ahd_pci_read_config(ahd_dev_softc_t pci,
471 int reg, int width);
472 static __inline void ahd_pci_write_config(ahd_dev_softc_t pci,
473 int reg, uint32_t value,
474 int width);
475 static __inline int ahd_get_pci_function(ahd_dev_softc_t);
476 static __inline int ahd_get_pci_slot(ahd_dev_softc_t);
477 static __inline int ahd_get_pci_bus(ahd_dev_softc_t);
478
479 int ahd_pci_map_registers(struct ahd_softc *ahd);
480 int ahd_pci_map_int(struct ahd_softc *ahd);
481
482 static __inline uint32_t
483 ahd_pci_read_config(ahd_dev_softc_t pci, int reg, int width)
484 {
485 return (pci_read_config(pci, reg, width));
486 }
487
488 static __inline void
489 ahd_pci_write_config(ahd_dev_softc_t pci, int reg, uint32_t value, int width)
490 {
491 pci_write_config(pci, reg, value, width);
492 }
493
494 static __inline int
495 ahd_get_pci_function(ahd_dev_softc_t pci)
496 {
497 return (pci_get_function(pci));
498 }
499
500 static __inline int
501 ahd_get_pci_slot(ahd_dev_softc_t pci)
502 {
503 return (pci_get_slot(pci));
504 }
505
506
507 static __inline int
508 ahd_get_pci_bus(ahd_dev_softc_t pci)
509 {
510 return (pci_get_bus(pci));
511 }
512 #endif
513
514 typedef enum
515 {
516 AHD_POWER_STATE_D0,
517 AHD_POWER_STATE_D1,
518 AHD_POWER_STATE_D2,
519 AHD_POWER_STATE_D3
520 } ahd_power_state;
521
522 void ahd_power_state_change(struct ahd_softc *ahd,
523 ahd_power_state new_state);
524
525 /******************************** VL/EISA *************************************/
526 int aic7770_map_registers(struct ahd_softc *ahd);
527 int aic7770_map_int(struct ahd_softc *ahd, int irq);
528
529 /********************************* Debug **************************************/
530 static __inline void ahd_print_path(struct ahd_softc *, struct scb *);
531 static __inline void ahd_platform_dump_card_state(struct ahd_softc *ahd);
532 static __inline void
533 ahd_print_path(struct ahd_softc *ahd, struct scb *scb)
534 {
535 printf("%s:", ahd->sc_dev.dv_xname);
536 }
537
538 static __inline void
539 ahd_platform_dump_card_state(struct ahd_softc *ahd)
540 {
541 /* Nothing to do here for NetBSD */
542 }
543 /**************************** Transfer Settings *******************************/
544 void ahd_notify_xfer_settings_change(struct ahd_softc *,
545 struct ahd_devinfo *);
546 void ahd_platform_set_tags(struct ahd_softc *, struct ahd_devinfo *,
547 ahd_queue_alg);
548
549 /************************* Initialization/Teardown ****************************/
550 int ahd_platform_alloc(struct ahd_softc *ahd, void *platform_arg);
551 void ahd_platform_free(struct ahd_softc *ahd);
552 int ahd_map_int(struct ahd_softc *ahd);
553 int ahd_attach(struct ahd_softc *);
554 int ahd_softc_comp(struct ahd_softc *lahd, struct ahd_softc *rahd);
555 int ahd_detach(struct device *device, int flags);
556 #define ahd_platform_init(arg)
557
558
559 /****************************** Interrupts ************************************/
560 void ahd_platform_intr(void *);
561 static __inline void ahd_platform_flushwork(struct ahd_softc *ahd);
562 static __inline void
563 ahd_platform_flushwork(struct ahd_softc *ahd)
564 {
565 /* Nothing to do here for NetBSD */
566 }
567
568 /************************ Misc Function Declarations **************************/
569 void ahd_done(struct ahd_softc *ahd, struct scb *scb);
570 void ahd_send_async(struct ahd_softc *, char /*channel*/,
571 u_int /*target*/, u_int /*lun*/, u_int /*ac_code*/,
572 void *arg);
573
574 #endif /* _AIC79XX_NETBSD_H_ */
575