]> git.pld-linux.org Git - packages/kernel.git/blob - linux-2.4.24-aic79xxx-20031222.patch
- added description of djurban's branch
[packages/kernel.git] / linux-2.4.24-aic79xxx-20031222.patch
1 diff -urN linux-2.4.24.org/drivers/scsi/aic7xxx/aic7770.c linux-2.4.24/drivers/scsi/aic7xxx/aic7770.c
2 --- linux-2.4.24.org/drivers/scsi/aic7xxx/aic7770.c     2004-01-08 11:57:43.070993176 +0100
3 +++ linux-2.4.24/drivers/scsi/aic7xxx/aic7770.c 2003-12-22 22:46:59.000000000 +0100
4 @@ -37,9 +37,7 @@
5   * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
6   * POSSIBILITY OF SUCH DAMAGES.
7   *
8 - * $Id$
9 - *
10 - * $FreeBSD$
11 + * $Id$
12   */
13  
14  #ifdef __linux__
15 @@ -175,7 +175,7 @@
16         case 15:
17                 break;
18         default:
19 -               printf("aic7770_config: illegal irq setting %d\n", intdef);
20 +               printf("aic7770_config: invalid irq setting %d\n", intdef);
21                 return (ENXIO);
22         }
23  
24 diff -urN linux-2.4.24.org/drivers/scsi/aic7xxx/aic7770_osm.c linux-2.4.24/drivers/scsi/aic7xxx/aic7770_osm.c
25 --- linux-2.4.24.org/drivers/scsi/aic7xxx/aic7770_osm.c 2004-01-08 11:57:43.069993382 +0100
26 +++ linux-2.4.24/drivers/scsi/aic7xxx/aic7770_osm.c     2003-12-22 22:46:59.000000000 +0100
27 @@ -36,7 +36,7 @@
28   * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29   * POSSIBILITY OF SUCH DAMAGES.
30   *
31 - * $Id$
32 + * $Id$
33   */
34  
35  #include "aic7xxx_osm.h"
36 @@ -190,6 +190,7 @@
37                 free(name, M_DEVBUF);
38                 return (ENOMEM);
39         }
40 +       ahc->dev_softc = dev;
41         error = aic7770_config(ahc, entry, eisaBase);
42         if (error != 0) {
43                 ahc->bsh.ioport = 0;
44 @@ -267,12 +268,14 @@
45         if (ahc != NULL) {
46                 u_long s;
47  
48 +               TAILQ_REMOVE(&ahc_tailq, ahc, links);
49 +               ahc_list_unlock(&l);
50                 ahc_lock(ahc, &s);
51                 ahc_intr_enable(ahc, FALSE);
52                 ahc_unlock(ahc, &s);
53                 ahc_free(ahc);
54 -       }
55 -       ahc_list_unlock(&l);
56 +       } else
57 +               ahc_list_unlock(&l);
58  
59         return (0);
60  }
61 diff -urN linux-2.4.24.org/drivers/scsi/aic7xxx/aic79xx_core.c linux-2.4.24/drivers/scsi/aic7xxx/aic79xx_core.c
62 --- linux-2.4.24.org/drivers/scsi/aic7xxx/aic79xx_core.c        2004-01-08 11:57:43.062994829 +0100
63 +++ linux-2.4.24/drivers/scsi/aic7xxx/aic79xx_core.c    2003-12-22 22:46:59.000000000 +0100
64 @@ -37,9 +37,7 @@
65   * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
66   * POSSIBILITY OF SUCH DAMAGES.
67   *
68 - * $Id$
69 - *
70 - * $FreeBSD$
71 + * $Id$
72   */
73  
74  #ifdef __linux__
75 @@ -224,6 +224,14 @@
76  static void            ahd_download_instr(struct ahd_softc *ahd,
77                                            u_int instrptr, uint8_t *dconsts);
78  static int             ahd_probe_stack_size(struct ahd_softc *ahd);
79 +static void            ahd_other_scb_timeout(struct ahd_softc *ahd,
80 +                                             struct scb *scb,
81 +                                             struct scb *other_scb);
82 +static int             ahd_scb_active_in_fifo(struct ahd_softc *ahd,
83 +                                              struct scb *scb);
84 +static void            ahd_run_data_fifo(struct ahd_softc *ahd,
85 +                                         struct scb *scb);
86 +
87  #ifdef AHD_TARGET_MODE
88  static void            ahd_queue_lstate_event(struct ahd_softc *ahd,
89                                                struct ahd_tmode_lstate *lstate,
90 @@ -328,10 +336,7 @@
91         /* Always allow reselection */
92         ahd_outb(ahd, SCSISEQ1,
93                  ahd_inb(ahd, SCSISEQ_TEMPLATE) & (ENSELI|ENRSELI|ENAUTOATNP));
94 -       /* Ensure that no DMA operations are in progress */
95         ahd_set_modes(ahd, AHD_MODE_CCHAN, AHD_MODE_CCHAN);
96 -       ahd_outb(ahd, SCBHCNT, 0);
97 -       ahd_outb(ahd, CCSCBCTL, CCSCBRESET);
98         ahd_outb(ahd, SEQCTL0, FASTMODE|SEQRESET);
99         ahd_unpause(ahd);
100  }
101 @@ -371,31 +376,119 @@
102         u_int           next_scbid;
103  
104         saved_modes = ahd_save_modes(ahd);
105 -       ahd_set_modes(ahd, AHD_MODE_CCHAN, AHD_MODE_CCHAN);
106 +
107 +       /*
108 +        * Flush the good status FIFO for completed packetized commands.
109 +        */
110 +       ahd_set_modes(ahd, AHD_MODE_SCSI, AHD_MODE_SCSI);
111         saved_scbptr = ahd_get_scbptr(ahd);
112 +       while ((ahd_inb(ahd, LQISTAT2) & LQIGSAVAIL) != 0) {
113 +               u_int fifo_mode;
114 +               u_int i;
115 +               
116 +               scbid = ahd_inw(ahd, GSFIFO);
117 +               scb = ahd_lookup_scb(ahd, scbid);
118 +               if (scb == NULL) {
119 +                       printf("%s: Warning - GSFIFO SCB %d invalid\n",
120 +                              ahd_name(ahd), scbid);
121 +                       continue;
122 +               }
123 +               /*
124 +                * Determine if this transaction is still active in
125 +                * any FIFO.  If it is, we must flush that FIFO to
126 +                * the host before completing the  command.
127 +                */
128 +               fifo_mode = 0;
129 +rescan_fifos:
130 +               for (i = 0; i < 2; i++) {
131 +                       /* Toggle to the other mode. */
132 +                       fifo_mode ^= 1;
133 +                       ahd_set_modes(ahd, fifo_mode, fifo_mode);
134 +
135 +                       if (ahd_scb_active_in_fifo(ahd, scb) == 0)
136 +                               continue;
137 +
138 +                       ahd_run_data_fifo(ahd, scb);
139 +
140 +                       /*
141 +                        * Running this FIFO may cause a CFG4DATA for
142 +                        * this same transaction to assert in the other
143 +                        * FIFO or a new snapshot SAVEPTRS interrupt
144 +                        * in this FIFO.  Even running a FIFO may not
145 +                        * clear the transaction if we are still waiting
146 +                        * for data to drain to the host. We must loop
147 +                        * until the transaction is not active in either
148 +                        * FIFO just to be sure.  Reset our loop counter
149 +                        * so we will visit both FIFOs again before
150 +                        * declaring this transaction finished.  We
151 +                        * also delay a bit so that status has a chance
152 +                        * to change before we look at this FIFO again.
153 +                        */
154 +                       aic_delay(200);
155 +                       goto rescan_fifos;
156 +               }
157 +               ahd_set_modes(ahd, AHD_MODE_SCSI, AHD_MODE_SCSI);
158 +               ahd_set_scbptr(ahd, scbid);
159 +               if ((ahd_inb_scbram(ahd, SCB_SGPTR) & SG_LIST_NULL) == 0
160 +                && ((ahd_inb_scbram(ahd, SCB_SGPTR) & SG_FULL_RESID) != 0
161 +                 || (ahd_inb_scbram(ahd, SCB_RESIDUAL_SGPTR)
162 +                     & SG_LIST_NULL) != 0)) {
163 +                       u_int comp_head;
164 +
165 +                       /*
166 +                        * The transfer completed with a residual.
167 +                        * Place this SCB on the complete DMA list
168 +                        * so that we update our in-core copy of the
169 +                        * SCB before completing the command.
170 +                        */
171 +                       ahd_outb(ahd, SCB_SCSI_STATUS, 0);
172 +                       ahd_outb(ahd, SCB_SGPTR,
173 +                                ahd_inb_scbram(ahd, SCB_SGPTR)
174 +                                | SG_STATUS_VALID);
175 +                       ahd_outw(ahd, SCB_TAG, SCB_GET_TAG(scb));
176 +                       comp_head = ahd_inw(ahd, COMPLETE_DMA_SCB_HEAD);
177 +                       ahd_outw(ahd, SCB_NEXT_COMPLETE, comp_head);
178 +                       ahd_outw(ahd, COMPLETE_DMA_SCB_HEAD, SCB_GET_TAG(scb));
179 +               } else
180 +                       ahd_complete_scb(ahd, scb);
181 +       }
182 +       ahd_set_scbptr(ahd, saved_scbptr);
183 +
184 +       /*
185 +        * Setup for command channel portion of flush.
186 +        */
187 +       ahd_set_modes(ahd, AHD_MODE_CCHAN, AHD_MODE_CCHAN);
188  
189         /*
190          * Wait for any inprogress DMA to complete and clear DMA state
191          * if this if for an SCB in the qinfifo.
192          */
193 -       while ((ccscbctl = ahd_inb(ahd, CCSCBCTL) & (CCARREN|CCSCBEN)) != 0) {
194 +       while (((ccscbctl = ahd_inb(ahd, CCSCBCTL)) & (CCARREN|CCSCBEN)) != 0) {
195  
196                 if ((ccscbctl & (CCSCBDIR|CCARREN)) == (CCSCBDIR|CCARREN)) {
197                         if ((ccscbctl & ARRDONE) != 0)
198                                 break;
199                 } else if ((ccscbctl & CCSCBDONE) != 0)
200                         break;
201 -               ahd_delay(200);
202 +               aic_delay(200);
203         }
204 -       if ((ccscbctl & CCSCBDIR) != 0)
205 +       /*
206 +        * We leave the sequencer to cleanup in the case of DMA's to
207 +        * update the qoutfifo.  In all other cases (DMA's to the
208 +        * chip or a push of an SCB from the COMPLETE_DMA_SCB list),
209 +        * we disable the DMA engine so that the sequencer will not
210 +        * attempt to handle the DMA completion.
211 +        */
212 +       if ((ccscbctl & CCSCBDIR) != 0 || (ccscbctl & ARRDONE) != 0)
213                 ahd_outb(ahd, CCSCBCTL, ccscbctl & ~(CCARREN|CCSCBEN));
214  
215         /*
216 -        * Complete any SCBs that just finished being
217 -        * DMA'ed into the qoutfifo.
218 +        * Complete any SCBs that just finished
219 +        * being DMA'ed into the qoutfifo.
220          */
221         ahd_run_qoutfifo(ahd);
222  
223 +       saved_scbptr = ahd_get_scbptr(ahd);
224         /*
225          * Manually update/complete any completed SCBs that are waiting to be
226          * DMA'ed back up to the host.
227 @@ -438,31 +531,272 @@
228                 scbid = next_scbid;
229         }
230         ahd_outw(ahd, COMPLETE_SCB_HEAD, SCB_LIST_NULL);
231 -       ahd_set_scbptr(ahd, saved_scbptr);
232 -
233 -       /*
234 -        * Flush the good status FIFO for compelted packetized commands.
235 -        */
236 -       ahd_set_modes(ahd, AHD_MODE_SCSI, AHD_MODE_SCSI);
237 -       while ((ahd_inb(ahd, LQISTAT2) & LQIGSAVAIL) != 0) {
238 -               scbid = (ahd_inb(ahd, GSFIFO+1) << 8)
239 -                     | ahd_inb(ahd, GSFIFO);
240 -               scb = ahd_lookup_scb(ahd, scbid);
241 -               if (scb == NULL) {
242 -                       printf("%s: Warning - GSFIFO SCB %d invalid\n",
243 -                              ahd_name(ahd), scbid);
244 -                       continue;
245 -               }
246 -               ahd_complete_scb(ahd, scb);
247 -       }
248  
249         /*
250          * Restore state.
251          */
252 +       ahd_set_scbptr(ahd, saved_scbptr);
253         ahd_restore_modes(ahd, saved_modes);
254         ahd->flags |= AHD_UPDATE_PEND_CMDS;
255  }
256  
257 +/*
258 + * Determine if an SCB for a packetized transaction
259 + * is active in a FIFO.
260 + */
261 +static int
262 +ahd_scb_active_in_fifo(struct ahd_softc *ahd, struct scb *scb)
263 +{
264 +
265 +       /*
266 +        * The FIFO is only active for our transaction if
267 +        * the SCBPTR matches the SCB's ID and the firmware
268 +        * has installed a handler for the FIFO or we have
269 +        * a pending SAVEPTRS or CFG4DATA interrupt.
270 +        */
271 +       if (ahd_get_scbptr(ahd) != SCB_GET_TAG(scb)
272 +        || ((ahd_inb(ahd, LONGJMP_ADDR+1) & INVALID_ADDR) != 0
273 +         && (ahd_inb(ahd, SEQINTSRC) & (CFG4DATA|SAVEPTRS)) == 0))
274 +               return (0);
275 +
276 +       return (1);
277 +}
278 +
279 +/*
280 + * Run a data fifo to completion for a transaction we know
281 + * has completed across the SCSI bus (good status has been
282 + * received).  We are already set to the correct FIFO mode
283 + * on entry to this routine.
284 + *
285 + * This function attempts to operate exactly as the firmware
286 + * would when running this FIFO.  Care must be taken to update
287 + * this routine any time the firmware's FIFO algorithm is
288 + * changed.
289 + */
290 +static void
291 +ahd_run_data_fifo(struct ahd_softc *ahd, struct scb *scb)
292 +{
293 +       u_int seqintsrc;
294 +
295 +       seqintsrc = ahd_inb(ahd, SEQINTSRC);
296 +       if ((seqintsrc & CFG4DATA) != 0) {
297 +               uint32_t datacnt;
298 +               uint32_t sgptr;
299 +
300 +               /*
301 +                * Clear full residual flag.
302 +                */
303 +               sgptr = ahd_inl_scbram(ahd, SCB_SGPTR) & ~SG_FULL_RESID;
304 +               ahd_outb(ahd, SCB_SGPTR, sgptr);
305 +
306 +               /*
307 +                * Load datacnt and address.
308 +                */
309 +               datacnt = ahd_inl_scbram(ahd, SCB_DATACNT);
310 +               if ((datacnt & AHD_DMA_LAST_SEG) != 0) {
311 +                       sgptr |= LAST_SEG;
312 +                       ahd_outb(ahd, SG_STATE, 0);
313 +               } else
314 +                       ahd_outb(ahd, SG_STATE, LOADING_NEEDED);
315 +               ahd_outq(ahd, HADDR, ahd_inq_scbram(ahd, SCB_DATAPTR));
316 +               ahd_outl(ahd, HCNT, datacnt & AHD_SG_LEN_MASK);
317 +               ahd_outb(ahd, SG_CACHE_PRE, sgptr);
318 +               ahd_outb(ahd, DFCNTRL, PRELOADEN|SCSIEN|HDMAEN);
319 +
320 +               /*
321 +                * Initialize Residual Fields.
322 +                */
323 +               ahd_outb(ahd, SCB_RESIDUAL_DATACNT+3, datacnt >> 24);
324 +               ahd_outl(ahd, SCB_RESIDUAL_SGPTR, sgptr & SG_PTR_MASK);
325 +
326 +               /*
327 +                * Mark the SCB as having a FIFO in use.
328 +                */
329 +               ahd_outb(ahd, SCB_FIFO_USE_COUNT,
330 +                        ahd_inb_scbram(ahd, SCB_FIFO_USE_COUNT) + 1);
331 +
332 +               /*
333 +                * Install a "fake" handler for this FIFO.
334 +                */
335 +               ahd_outw(ahd, LONGJMP_ADDR, 0);
336 +
337 +               /*
338 +                * Notify the hardware that we have satisfied
339 +                * this sequencer interrupt.
340 +                */
341 +               ahd_outb(ahd, CLRSEQINTSRC, CLRCFG4DATA);
342 +       } else if ((seqintsrc & SAVEPTRS) != 0) {
343 +               uint32_t sgptr;
344 +               uint32_t resid;
345 +
346 +               if ((ahd_inb(ahd, LONGJMP_ADDR+1)&INVALID_ADDR) != 0) {
347 +                       /*
348 +                        * Snapshot Save Pointers.  All that
349 +                        * is necessary to clear the snapshot
350 +                        * is a CLRCHN.
351 +                        */
352 +                       goto clrchn;
353 +               }
354 +
355 +               /*
356 +                * Disable S/G fetch so the DMA engine
357 +                * is available to future users.
358 +                */
359 +               if ((ahd_inb(ahd, SG_STATE) & FETCH_INPROG) != 0)
360 +                       ahd_outb(ahd, CCSGCTL, 0);
361 +               ahd_outb(ahd, SG_STATE, 0);
362 +
363 +               /*
364 +                * Flush the data FIFO.  Strickly only
365 +                * necessary for Rev A parts.
366 +                */
367 +               ahd_outb(ahd, DFCNTRL, ahd_inb(ahd, DFCNTRL) | FIFOFLUSH);
368 +
369 +               /*
370 +                * Calculate residual.
371 +                */
372 +               sgptr = ahd_inl_scbram(ahd, SCB_RESIDUAL_SGPTR);
373 +               resid = ahd_inl(ahd, SHCNT);
374 +               resid |= ahd_inb_scbram(ahd, SCB_RESIDUAL_DATACNT+3) << 24;
375 +               ahd_outl(ahd, SCB_RESIDUAL_DATACNT, resid);
376 +               if ((ahd_inb(ahd, SG_CACHE_SHADOW) & LAST_SEG) == 0) {
377 +                       /*
378 +                        * Must back up to the correct S/G element.
379 +                        * Typically this just means resetting our
380 +                        * low byte to the offset in the SG_CACHE,
381 +                        * but if we wrapped, we have to correct
382 +                        * the other bytes of the sgptr too.
383 +                        */
384 +                       if ((ahd_inb(ahd, SG_CACHE_SHADOW) & 0x80) != 0
385 +                        && (sgptr & 0x80) == 0)
386 +                               sgptr -= 0x100;
387 +                       sgptr &= ~0xFF;
388 +                       sgptr |= ahd_inb(ahd, SG_CACHE_SHADOW)
389 +                              & SG_ADDR_MASK;
390 +                       ahd_outl(ahd, SCB_RESIDUAL_SGPTR, sgptr);
391 +                       ahd_outb(ahd, SCB_RESIDUAL_DATACNT + 3, 0);
392 +               } else if ((resid & AHD_SG_LEN_MASK) == 0) {
393 +                       ahd_outb(ahd, SCB_RESIDUAL_SGPTR,
394 +                                sgptr | SG_LIST_NULL);
395 +               }
396 +               /*
397 +                * Save Pointers.
398 +                */
399 +               ahd_outq(ahd, SCB_DATAPTR, ahd_inq(ahd, SHADDR));
400 +               ahd_outl(ahd, SCB_DATACNT, resid);
401 +               ahd_outl(ahd, SCB_SGPTR, sgptr);
402 +               ahd_outb(ahd, CLRSEQINTSRC, CLRSAVEPTRS);
403 +               ahd_outb(ahd, SEQIMODE,
404 +                        ahd_inb(ahd, SEQIMODE) | ENSAVEPTRS);
405 +               /*
406 +                * If the data is to the SCSI bus, we are
407 +                * done, otherwise wait for FIFOEMP.
408 +                */
409 +               if ((ahd_inb(ahd, DFCNTRL) & DIRECTION) != 0)
410 +                       goto clrchn;
411 +       } else if ((ahd_inb(ahd, SG_STATE) & LOADING_NEEDED) != 0) {
412 +               uint32_t sgptr;
413 +               uint64_t data_addr;
414 +               uint32_t data_len;
415 +               u_int    dfcntrl;
416 +
417 +               /*
418 +                * Disable S/G fetch so the DMA engine
419 +                * is available to future users.  We won't
420 +                * be using the DMA engine to load segments.
421 +                */
422 +               if ((ahd_inb(ahd, SG_STATE) & FETCH_INPROG) != 0) {
423 +                       ahd_outb(ahd, CCSGCTL, 0);
424 +                       ahd_outb(ahd, SG_STATE, LOADING_NEEDED);
425 +               }
426 +
427 +               /*
428 +                * Wait for the DMA engine to notice that the
429 +                * host transfer is enabled and that there is
430 +                * space in the S/G FIFO for new segments before
431 +                * loading more segments.
432 +                */
433 +               if ((ahd_inb(ahd, DFSTATUS) & PRELOAD_AVAIL) != 0
434 +                && (ahd_inb(ahd, DFCNTRL) & HDMAENACK) != 0) {
435 +
436 +                       /*
437 +                        * Determine the offset of the next S/G
438 +                        * element to load.
439 +                        */
440 +                       sgptr = ahd_inl_scbram(ahd, SCB_RESIDUAL_SGPTR);
441 +                       sgptr &= SG_PTR_MASK;
442 +                       if ((ahd->flags & AHD_64BIT_ADDRESSING) != 0) {
443 +                               struct ahd_dma64_seg *sg;
444 +
445 +                               sg = ahd_sg_bus_to_virt(ahd, scb, sgptr);
446 +                               data_addr = sg->addr;
447 +                               data_len = sg->len;
448 +                               sgptr += sizeof(*sg);
449 +                       } else {
450 +                               struct  ahd_dma_seg *sg;
451 +
452 +                               sg = ahd_sg_bus_to_virt(ahd, scb, sgptr);
453 +                               data_addr = sg->len & AHD_SG_HIGH_ADDR_MASK;
454 +                               data_addr <<= 8;
455 +                               data_addr |= sg->addr;
456 +                               data_len = sg->len;
457 +                               sgptr += sizeof(*sg);
458 +                       }
459 +
460 +                       /*
461 +                        * Update residual information.
462 +                        */
463 +                       ahd_outb(ahd, SCB_RESIDUAL_DATACNT+3, data_len >> 24);
464 +                       ahd_outl(ahd, SCB_RESIDUAL_SGPTR, sgptr);
465 +
466 +                       /*
467 +                        * Load the S/G.
468 +                        */
469 +                       if (data_len & AHD_DMA_LAST_SEG) {
470 +                               sgptr |= LAST_SEG;
471 +                               ahd_outb(ahd, SG_STATE, 0);
472 +                       }
473 +                       ahd_outq(ahd, HADDR, data_addr);
474 +                       ahd_outl(ahd, HCNT, data_len & AHD_SG_LEN_MASK);
475 +                       ahd_outb(ahd, SG_CACHE_PRE, sgptr & 0xFF);
476 +
477 +                       /*
478 +                        * Advertise the segment to the hardware.
479 +                        */
480 +                       dfcntrl = ahd_inb(ahd, DFCNTRL)|PRELOADEN|HDMAEN;
481 +                       if ((ahd->features & AHD_NEW_DFCNTRL_OPTS) != 0) {
482 +                               /*
483 +                                * Use SCSIENWRDIS so that SCSIEN
484 +                                * is never modified by this
485 +                                * operation.
486 +                                */
487 +                               dfcntrl |= SCSIENWRDIS;
488 +                       }
489 +                       ahd_outb(ahd, DFCNTRL, dfcntrl);
490 +               }
491 +       } else if ((ahd_inb(ahd, SG_CACHE_SHADOW) & LAST_SEG_DONE) != 0) {
492 +
493 +               /*
494 +                * Transfer completed to the end of SG list
495 +                * and has flushed to the host.
496 +                */
497 +               ahd_outb(ahd, SCB_SGPTR,
498 +                        ahd_inb_scbram(ahd, SCB_SGPTR) | SG_LIST_NULL);
499 +               goto clrchn;
500 +       } else if ((ahd_inb(ahd, DFSTATUS) & FIFOEMP) != 0) {
501 +clrchn:
502 +               /*
503 +                * Clear any handler for this FIFO, decrement
504 +                * the FIFO use count for the SCB, and release
505 +                * the FIFO.
506 +                */
507 +               ahd_outb(ahd, LONGJMP_ADDR + 1, INVALID_ADDR);
508 +               ahd_outb(ahd, SCB_FIFO_USE_COUNT,
509 +                        ahd_inb_scbram(ahd, SCB_FIFO_USE_COUNT) - 1);
510 +               ahd_outb(ahd, DFFSXFRCTL, CLRCHN);
511 +       }
512 +}
513 +
514  void
515  ahd_run_qoutfifo(struct ahd_softc *ahd)
516  {
517 @@ -476,7 +810,7 @@
518         while ((ahd->qoutfifo[ahd->qoutfifonext]
519              & QOUTFIFO_ENTRY_VALID_LE) == ahd->qoutfifonext_valid_tag) {
520  
521 -               scb_index = ahd_le16toh(ahd->qoutfifo[ahd->qoutfifonext]
522 +               scb_index = aic_le16toh(ahd->qoutfifo[ahd->qoutfifonext]
523                                       & ~QOUTFIFO_ENTRY_VALID_LE);
524                 scb = ahd_lookup_scb(ahd, scb_index);
525                 if (scb == NULL) {
526 @@ -556,26 +890,6 @@
527                        ahd_name(ahd), seqintcode);
528  #endif
529         switch (seqintcode) {
530 -       case BAD_SCB_STATUS:
531 -       {
532 -               struct  scb *scb;
533 -               u_int   scbid;
534 -               int     cmds_pending;
535 -
536 -               scbid = ahd_get_scbptr(ahd);
537 -               scb = ahd_lookup_scb(ahd, scbid);
538 -               if (scb != NULL) {
539 -                       ahd_complete_scb(ahd, scb);
540 -               } else {
541 -                       printf("%s: WARNING no command for scb %d "
542 -                              "(bad status)\n", ahd_name(ahd), scbid);
543 -                       ahd_dump_card_state(ahd);
544 -               }
545 -               cmds_pending = ahd_inw(ahd, CMDS_PENDING);
546 -               if (cmds_pending > 0)
547 -                       ahd_outw(ahd, CMDS_PENDING, cmds_pending - 1);
548 -               break;
549 -       }
550         case ENTERING_NONPACK:
551         {
552                 struct  scb *scb;
553 @@ -589,7 +903,7 @@
554                         /*
555                          * Somehow need to know if this
556                          * is from a selection or reselection.
557 -                        * From that, we can termine target
558 +                        * From that, we can determine target
559                          * ID so we at least have an I_T nexus.
560                          */
561                 } else {
562 @@ -740,11 +1054,11 @@
563                         ahd_outb(ahd, SAVED_LUN, 0);
564                         ahd_outb(ahd, SEQ_FLAGS, 0);
565                         ahd_assert_atn(ahd);
566 -                       scb->flags &= ~(SCB_PACKETIZED);
567 +                       scb->flags &= ~SCB_PACKETIZED;
568                         scb->flags |= SCB_ABORT|SCB_CMDPHASE_ABORT;
569                         ahd_freeze_devq(ahd, scb);
570 -                       ahd_set_transaction_status(scb, CAM_REQUEUE_REQ);
571 -                       ahd_freeze_scb(scb);
572 +                       aic_set_transaction_status(scb, CAM_REQUEUE_REQ);
573 +                       aic_freeze_scb(scb);
574  
575                         /*
576                          * Allow the sequencer to continue with
577 @@ -796,7 +1110,8 @@
578                          * attempt to complete this bogus SCB.
579                          */
580                         ahd_outb(ahd, SCB_CONTROL,
581 -                                ahd_inb(ahd, SCB_CONTROL) & ~STATUS_RCVD);
582 +                                ahd_inb_scbram(ahd, SCB_CONTROL)
583 +                                & ~STATUS_RCVD);
584                 }
585                 break;
586         }
587 @@ -991,7 +1306,7 @@
588                                "NumSGs = %d.\n",
589                                ahd_inb(ahd, SEQ_FLAGS) & DPHASE
590                                ? "Have" : "Haven't",
591 -                              ahd_get_transfer_length(scb), scb->sg_count);
592 +                              aic_get_transfer_length(scb), scb->sg_count);
593                         ahd_dump_sglist(scb);
594                 }
595  #endif
596 @@ -1001,8 +1316,8 @@
597                  * target does a command complete.
598                  */
599                 ahd_freeze_devq(ahd, scb);
600 -               ahd_set_transaction_status(scb, CAM_DATA_RUN_ERR);
601 -               ahd_freeze_scb(scb);
602 +               aic_set_transaction_status(scb, CAM_DATA_RUN_ERR);
603 +               aic_freeze_scb(scb);
604                 break;
605         }
606         case MKMSG_FAILED:
607 @@ -1029,7 +1344,7 @@
608                                            ROLE_INITIATOR, /*status*/0,
609                                            SEARCH_REMOVE);
610                 ahd_outb(ahd, SCB_CONTROL,
611 -                        ahd_inb(ahd, SCB_CONTROL) & ~MK_MESSAGE);
612 +                        ahd_inb_scbram(ahd, SCB_CONTROL) & ~MK_MESSAGE);
613                 break;
614         }
615         case TASKMGMT_FUNC_COMPLETE:
616 @@ -1263,7 +1578,7 @@
617                          */
618                         ahd_scb_devinfo(ahd, &devinfo, scb);
619                         ahd_force_renegotiation(ahd, &devinfo);
620 -                       ahd_set_transaction_status(scb, CAM_SEL_TIMEOUT);
621 +                       aic_set_transaction_status(scb, CAM_SEL_TIMEOUT);
622                         ahd_freeze_devq(ahd, scb);
623                 }
624                 ahd_outb(ahd, CLRINT, CLRSCSIINT);
625 @@ -1710,8 +2025,8 @@
626                         }
627                         scb->crc_retry_count++;
628                 } else {
629 -                       ahd_set_transaction_status(scb, CAM_UNCOR_PARITY);
630 -                       ahd_freeze_scb(scb);
631 +                       aic_set_transaction_status(scb, CAM_UNCOR_PARITY);
632 +                       aic_freeze_scb(scb);
633                         ahd_freeze_devq(ahd, scb);
634                 }
635                 /* Return unpausing the sequencer. */
636 @@ -1853,7 +2168,7 @@
637                          && ahd_match_scb(ahd, scb, target, 'A',
638                                           CAM_LUN_WILDCARD, SCB_LIST_NULL,
639                                           ROLE_INITIATOR))
640 -                               ahd_set_transaction_status(scb, CAM_REQ_CMP);
641 +                               aic_set_transaction_status(scb, CAM_REQ_CMP);
642  #endif
643                         ahd_handle_devreset(ahd, &devinfo, CAM_LUN_WILDCARD,
644                                             CAM_BDR_SENT, "Bus Device Reset",
645 @@ -1944,8 +2259,8 @@
646          && ((ahd->msg_flags & MSG_FLAG_EXPECT_PPR_BUSFREE) != 0)) {
647  
648                 ahd_freeze_devq(ahd, scb);
649 -               ahd_set_transaction_status(scb, CAM_REQUEUE_REQ);
650 -               ahd_freeze_scb(scb);
651 +               aic_set_transaction_status(scb, CAM_REQUEUE_REQ);
652 +               aic_freeze_scb(scb);
653                 if ((ahd->msg_flags & MSG_FLAG_IU_REQ_CHANGED) != 0) {
654                         ahd_abort_scbs(ahd, SCB_GET_TARGET(ahd, scb),
655                                        SCB_GET_CHANNEL(ahd, scb),
656 @@ -1989,8 +2304,7 @@
657                        "PRGMCNT == 0x%x\n",
658                        ahd_lookup_phase_entry(lastphase)->phasemsg,
659                        aborted,
660 -                      ahd_inb(ahd, PRGMCNT)
661 -                       | (ahd_inb(ahd, PRGMCNT+1) << 8));
662 +                      ahd_inw(ahd, PRGMCNT));
663                 ahd_dump_card_state(ahd);
664         }
665         /* Always restart the sequencer. */
666 @@ -2034,7 +2348,7 @@
667                 printf("No SCB found during protocol violation\n");
668                 goto proto_violation_reset;
669         } else {
670 -               ahd_set_transaction_status(scb, CAM_SEQUENCE_FAIL);
671 +               aic_set_transaction_status(scb, CAM_SEQUENCE_FAIL);
672                 if ((seq_flags & NO_CDB_SENT) != 0) {
673                         ahd_print_path(ahd, scb);
674                         printf("No or incomplete CDB sent to device.\n");
675 @@ -2153,8 +2467,7 @@
676                 u_int   i;
677  
678                 ahd_set_modes(ahd, AHD_MODE_SCSI, AHD_MODE_SCSI);
679 -               seqaddr = ahd_inb(ahd, CURADDR)
680 -                       | (ahd_inb(ahd, CURADDR+1) << 8);
681 +               seqaddr = ahd_inw(ahd, CURADDR);
682  
683                 cs = ahd->critical_sections;
684                 for (i = 0; i < ahd->num_critical_sections; i++, cs++) {
685 @@ -2198,8 +2511,14 @@
686                         ahd_outb(ahd, LQOMODE0, 0);
687                         ahd_outb(ahd, LQOMODE1, 0);
688                         ahd_set_modes(ahd, AHD_MODE_SCSI, AHD_MODE_SCSI);
689 -                       simode1 = ahd_inb(ahd, SIMODE1);
690 -                       ahd_outb(ahd, SIMODE1, ENBUSFREE);
691 +                       simode1 = ahd_inb(ahd, SIMODE1);
692 +                       /*
693 +                        * We don't clear ENBUSFREE.  Unfortunately
694 +                        * we cannot re-enable busfree detection within
695 +                        * the current connection, so we must leave it
696 +                        * on while single stepping.
697 +                        */
698 +                       ahd_outb(ahd, SIMODE1, simode1 & ENBUSFREE);
699                         ahd_outb(ahd, SEQCTL0, ahd_inb(ahd, SEQCTL0) | STEP);
700                         stepping = TRUE;
701                 }
702 @@ -2207,9 +2526,8 @@
703                 ahd_outb(ahd, CLRINT, CLRSCSIINT);
704                 ahd_set_modes(ahd, ahd->saved_src_mode, ahd->saved_dst_mode);
705                 ahd_outb(ahd, HCNTRL, ahd->unpause);
706 -               do {
707 -                       ahd_delay(200);
708 -               } while (!ahd_is_paused(ahd));
709 +               while (!ahd_is_paused(ahd))
710 +                       aic_delay(200);
711                 ahd_update_modes(ahd);
712         }
713         if (stepping) {
714 @@ -2285,10 +2603,10 @@
715         for (i = 0; i < sizeof(hscb->shared_data.idata.cdb); i++)
716                 printf("%#02x", hscb->shared_data.idata.cdb[i]);
717         printf("        dataptr:%#x%x datacnt:%#x sgptr:%#x tag:%#x\n",
718 -              (uint32_t)((ahd_le64toh(hscb->dataptr) >> 32) & 0xFFFFFFFF),
719 -              (uint32_t)(ahd_le64toh(hscb->dataptr) & 0xFFFFFFFF),
720 -              ahd_le32toh(hscb->datacnt),
721 -              ahd_le32toh(hscb->sgptr),
722 +              (uint32_t)((aic_le64toh(hscb->dataptr) >> 32) & 0xFFFFFFFF),
723 +              (uint32_t)(aic_le64toh(hscb->dataptr) & 0xFFFFFFFF),
724 +              aic_le32toh(hscb->datacnt),
725 +              aic_le32toh(hscb->sgptr),
726                SCB_GET_TAG(scb));
727         ahd_dump_sglist(scb);
728  }
729 @@ -2307,8 +2625,8 @@
730                                 uint64_t addr;
731                                 uint32_t len;
732  
733 -                               addr = ahd_le64toh(sg_list[i].addr);
734 -                               len = ahd_le32toh(sg_list[i].len);
735 +                               addr = aic_le64toh(sg_list[i].addr);
736 +                               len = aic_le32toh(sg_list[i].len);
737                                 printf("sg[%d] - Addr 0x%x%x : Length %d%s\n",
738                                        i,
739                                        (uint32_t)((addr >> 32) & 0xFFFFFFFF),
740 @@ -2324,11 +2642,11 @@
741                         for (i = 0; i < scb->sg_count; i++) {
742                                 uint32_t len;
743  
744 -                               len = ahd_le32toh(sg_list[i].len);
745 +                               len = aic_le32toh(sg_list[i].len);
746                                 printf("sg[%d] - Addr 0x%x%x : Length %d%s\n",
747                                        i,
748 -                                      (len >> 24) & SG_HIGH_ADDR_BITS,
749 -                                      ahd_le32toh(sg_list[i].addr),
750 +                                      (len & AHD_SG_HIGH_ADDR_MASK) >> 24,
751 +                                      aic_le32toh(sg_list[i].addr),
752                                        len & AHD_SG_LEN_MASK,
753                                        len & AHD_DMA_LAST_SEG ? " Last" : "");
754                         }
755 @@ -2870,14 +3188,25 @@
756                 iocell_opts[AHD_PRECOMP_SLEW_INDEX] &= ~AHD_PRECOMP_MASK;
757  
758                 if ((ahd->features & AHD_NEW_IOCELL_OPTS) != 0
759 -                && (ppr_opts & MSG_EXT_PPR_DT_REQ) != 0) {
760 +                && (ppr_opts & MSG_EXT_PPR_DT_REQ) != 0
761 +                && (ppr_opts & MSG_EXT_PPR_IU_REQ) == 0) {
762                         /*
763                          * Slow down our CRC interval to be
764 -                        * compatible with devices that can't
765 -                        * handle a CRC at full speed.
766 +                        * compatible with non-packetized
767 +                        * U160 devices that can't handle a
768 +                        * CRC at full speed.
769                          */
770                         con_opts |= ENSLOWCRC;
771                 }
772 +
773 +               if ((ahd->bugs & AHD_PACED_NEGTABLE_BUG) != 0) {
774 +                       /*
775 +                        * On H2A4, revert to a slower slewrate
776 +                        * on non-paced transfers.
777 +                        */
778 +                       iocell_opts[AHD_PRECOMP_SLEW_INDEX] &=
779 +                           ~AHD_SLEWRATE_MASK;
780 +               }
781         }
782  
783         ahd_outb(ahd, ANNEXCOL, AHD_ANNEXCOL_PRECOMP_SLEW);
784 @@ -2915,7 +3244,7 @@
785  {
786         struct          scb *pending_scb;
787         int             pending_scb_count;
788 -       int             i;
789 +       u_int           scb_tag;
790         int             paused;
791         u_int           saved_scbptr;
792         ahd_mode_state  saved_modes;
793 @@ -2973,17 +3302,14 @@
794         ahd_outb(ahd, SCSISEQ0, ahd_inb(ahd, SCSISEQ0) & ~ENSELO);
795         saved_scbptr = ahd_get_scbptr(ahd);
796         /* Ensure that the hscbs down on the card match the new information */
797 -       for (i = 0; i < ahd->scb_data.maxhscbs; i++) {
798 +       for (scb_tag = 0; scb_tag < ahd->scb_data.maxhscbs; scb_tag++) {
799                 struct  hardware_scb *pending_hscb;
800                 u_int   control;
801 -               u_int   scb_tag;
802  
803 -               ahd_set_scbptr(ahd, i);
804 -               scb_tag = i;
805                 pending_scb = ahd_lookup_scb(ahd, scb_tag);
806                 if (pending_scb == NULL)
807                         continue;
808 -
809 +               ahd_set_scbptr(ahd, scb_tag);
810                 pending_hscb = pending_scb->hscb;
811                 control = ahd_inb_scbram(ahd, SCB_CONTROL);
812                 control &= ~MK_MESSAGE;
813 @@ -3198,7 +3524,7 @@
814                        devinfo->target_mask);
815                 panic("SCB = %d, SCB Control = %x:%x, MSG_OUT = %x "
816                       "SCB flags = %x", SCB_GET_TAG(scb), scb->hscb->control,
817 -                     ahd_inb(ahd, SCB_CONTROL), ahd_inb(ahd, MSG_OUT),
818 +                     ahd_inb_scbram(ahd, SCB_CONTROL), ahd_inb(ahd, MSG_OUT),
819                       scb->flags);
820         }
821  
822 @@ -3737,8 +4063,13 @@
823                 if ((ahd->msg_flags & MSG_FLAG_PACKETIZED) != 0) {
824                         printf("%s: Returning to Idle Loop\n",
825                                ahd_name(ahd));
826 -                       ahd_outb(ahd, LASTPHASE, P_BUSFREE);
827                         ahd_clear_msg_state(ahd);
828 +
829 +                       /*
830 +                        * Perform the equivalent of a clear_target_state.
831 +                        */
832 +                       ahd_outb(ahd, LASTPHASE, P_BUSFREE);
833 +                       ahd_outb(ahd, SEQ_FLAGS, NOT_IDENTIFIED|NO_CDB_SENT);
834                         ahd_outb(ahd, SEQCTL0, FASTMODE|SEQRESET);
835                 } else {
836                         ahd_clear_msg_state(ahd);
837 @@ -4346,7 +4677,7 @@
838                 ahd_outb(ahd, SCB_CONTROL,
839                          ahd_inb_scbram(ahd, SCB_CONTROL) & mask);
840                 scb->hscb->control &= mask;
841 -               ahd_set_transaction_tag(scb, /*enabled*/FALSE,
842 +               aic_set_transaction_tag(scb, /*enabled*/FALSE,
843                                         /*type*/MSG_SIMPLE_TASK);
844                 ahd_outb(ahd, MSG_OUT, MSG_IDENTIFYFLAG);
845                 ahd_assert_atn(ahd);
846 @@ -4404,7 +4735,7 @@
847          * Perhaps add datadir to some spare bits in the hscb?
848          */
849         if ((ahd_inb(ahd, SEQ_FLAGS) & DPHASE) == 0
850 -        || ahd_get_transfer_dir(scb) != CAM_DIR_IN) {
851 +        || aic_get_transfer_dir(scb) != CAM_DIR_IN) {
852                 /*
853                  * Ignore the message if we haven't
854                  * seen an appropriate data phase yet.
855 @@ -4421,7 +4752,8 @@
856  
857                 sgptr = ahd_inb_scbram(ahd, SCB_RESIDUAL_SGPTR);
858                 if ((sgptr & SG_LIST_NULL) != 0
859 -                && (ahd_inb(ahd, SCB_TASK_ATTRIBUTE) & SCB_XFERLEN_ODD) != 0) {
860 +                && (ahd_inb_scbram(ahd, SCB_TASK_ATTRIBUTE)
861 +                    & SCB_XFERLEN_ODD) != 0) {
862                         /*
863                          * If the residual occurred on the last
864                          * transfer and the transfer request was
865 @@ -4458,18 +4790,18 @@
866                                  * to load so we must go back one.
867                                  */
868                                 sg--;
869 -                               sglen = ahd_le32toh(sg->len) & AHD_SG_LEN_MASK;
870 +                               sglen = aic_le32toh(sg->len) & AHD_SG_LEN_MASK;
871                                 if (sg != scb->sg_list
872                                  && sglen < (data_cnt & AHD_SG_LEN_MASK)) {
873  
874                                         sg--;
875 -                                       sglen = ahd_le32toh(sg->len);
876 +                                       sglen = aic_le32toh(sg->len);
877                                         /*
878                                          * Preserve High Address and SG_LIST
879                                          * bits while setting the count to 1.
880                                          */
881                                         data_cnt = 1|(sglen&(~AHD_SG_LEN_MASK));
882 -                                       data_addr = ahd_le64toh(sg->addr)
883 +                                       data_addr = aic_le64toh(sg->addr)
884                                                   + (sglen & AHD_SG_LEN_MASK)
885                                                   - 1;
886  
887 @@ -4491,18 +4823,18 @@
888                                  * to load so we must go back one.
889                                  */
890                                 sg--;
891 -                               sglen = ahd_le32toh(sg->len) & AHD_SG_LEN_MASK;
892 +                               sglen = aic_le32toh(sg->len) & AHD_SG_LEN_MASK;
893                                 if (sg != scb->sg_list
894                                  && sglen < (data_cnt & AHD_SG_LEN_MASK)) {
895  
896                                         sg--;
897 -                                       sglen = ahd_le32toh(sg->len);
898 +                                       sglen = aic_le32toh(sg->len);
899                                         /*
900                                          * Preserve High Address and SG_LIST
901                                          * bits while setting the count to 1.
902                                          */
903                                         data_cnt = 1|(sglen&(~AHD_SG_LEN_MASK));
904 -                                       data_addr = ahd_le32toh(sg->addr)
905 +                                       data_addr = aic_le32toh(sg->addr)
906                                                   + (sglen & AHD_SG_LEN_MASK)
907                                                   - 1;
908  
909 @@ -4522,7 +4854,8 @@
910                          * correct for subsequent data transfers.
911                          */
912                         ahd_outb(ahd, SCB_TASK_ATTRIBUTE,
913 -                           ahd_inb(ahd, SCB_TASK_ATTRIBUTE) ^ SCB_XFERLEN_ODD);
914 +                           ahd_inb_scbram(ahd, SCB_TASK_ATTRIBUTE)
915 +                           ^ SCB_XFERLEN_ODD);
916  
917                         ahd_outl(ahd, SCB_RESIDUAL_SGPTR, sgptr);
918                         ahd_outl(ahd, SCB_RESIDUAL_DATACNT, data_cnt);
919 @@ -4562,9 +4895,8 @@
920          */
921         ahd_outb(ahd, DFFSXFRCTL, CLRCHN);
922         wait = 1000;
923 -       do {
924 -               ahd_delay(100);
925 -       } while (--wait && !(ahd_inb(ahd, MDFFSTAT) & FIFOFREE));
926 +       while (--wait && !(ahd_inb(ahd, MDFFSTAT) & FIFOFREE))
927 +               aic_delay(100);
928         if (wait == 0) {
929                 ahd_print_path(ahd, scb);
930                 printf("ahd_reinitialize_dataptrs: Forcing FIFO free.\n");
931 @@ -4580,10 +4912,7 @@
932          * Determine initial values for data_addr and data_cnt
933          * for resuming the data phase.
934          */
935 -       sgptr = (ahd_inb_scbram(ahd, SCB_RESIDUAL_SGPTR + 3) << 24)
936 -             | (ahd_inb_scbram(ahd, SCB_RESIDUAL_SGPTR + 2) << 16)
937 -             | (ahd_inb_scbram(ahd, SCB_RESIDUAL_SGPTR + 1) << 8)
938 -             | ahd_inb_scbram(ahd, SCB_RESIDUAL_SGPTR);
939 +       sgptr = ahd_inl_scbram(ahd, SCB_RESIDUAL_SGPTR);
940         sgptr &= SG_PTR_MASK;
941  
942         resid = (ahd_inb_scbram(ahd, SCB_RESIDUAL_DATACNT + 2) << 16)
943 @@ -4598,13 +4927,10 @@
944                 /* The residual sg_ptr always points to the next sg */
945                 sg--;
946  
947 -               dataptr = ahd_le64toh(sg->addr)
948 -                       + (ahd_le32toh(sg->len) & AHD_SG_LEN_MASK)
949 +               dataptr = aic_le64toh(sg->addr)
950 +                       + (aic_le32toh(sg->len) & AHD_SG_LEN_MASK)
951                         - resid;
952 -               ahd_outb(ahd, HADDR + 7, dataptr >> 56);
953 -               ahd_outb(ahd, HADDR + 6, dataptr >> 48);
954 -               ahd_outb(ahd, HADDR + 5, dataptr >> 40);
955 -               ahd_outb(ahd, HADDR + 4, dataptr >> 32);
956 +               ahd_outl(ahd, HADDR + 4, dataptr >> 32);
957         } else {
958                 struct   ahd_dma_seg *sg;
959  
960 @@ -4613,16 +4939,13 @@
961                 /* The residual sg_ptr always points to the next sg */
962                 sg--;
963  
964 -               dataptr = ahd_le32toh(sg->addr)
965 -                       + (ahd_le32toh(sg->len) & AHD_SG_LEN_MASK)
966 +               dataptr = aic_le32toh(sg->addr)
967 +                       + (aic_le32toh(sg->len) & AHD_SG_LEN_MASK)
968                         - resid;
969                 ahd_outb(ahd, HADDR + 4,
970 -                        (ahd_le32toh(sg->len) & ~AHD_SG_LEN_MASK) >> 24);
971 +                        (aic_le32toh(sg->len) & ~AHD_SG_LEN_MASK) >> 24);
972         }
973 -       ahd_outb(ahd, HADDR + 3, dataptr >> 24);
974 -       ahd_outb(ahd, HADDR + 2, dataptr >> 16);
975 -       ahd_outb(ahd, HADDR + 1, dataptr >> 8);
976 -       ahd_outb(ahd, HADDR, dataptr);
977 +       ahd_outl(ahd, HADDR, dataptr);
978         ahd_outb(ahd, HCNT + 2, resid >> 16);
979         ahd_outb(ahd, HCNT + 1, resid >> 8);
980         ahd_outb(ahd, HCNT, resid);
981 @@ -4816,8 +5139,8 @@
982         ahd->bugs = AHD_BUGNONE;
983         ahd->flags = AHD_SPCHK_ENB_A|AHD_RESET_BUS_A|AHD_TERM_ENB_A
984                    | AHD_EXTENDED_TRANS_A|AHD_STPWLEVEL_A;
985 -       ahd_timer_init(&ahd->reset_timer);
986 -       ahd_timer_init(&ahd->stat_timer);
987 +       aic_timer_init(&ahd->reset_timer);
988 +       aic_timer_init(&ahd->stat_timer);
989         ahd->int_coalescing_timer = AHD_INT_COALESCING_TIMER_DEFAULT;
990         ahd->int_coalescing_maxcmds = AHD_INT_COALESCING_MAXCMDS_DEFAULT;
991         ahd->int_coalescing_mincmds = AHD_INT_COALESCING_MINCMDS_DEFAULT;
992 @@ -4853,24 +5176,24 @@
993  {
994         struct ahd_softc *list_ahd;
995  
996 -#if AHD_PCI_CONFIG > 0
997 +#if AIC_PCI_CONFIG > 0
998         /*
999          * Second Function PCI devices need to inherit some
1000          * settings from function 0.
1001          */
1002         if ((ahd->features & AHD_MULTI_FUNC) != 0) {
1003                 TAILQ_FOREACH(list_ahd, &ahd_tailq, links) {
1004 -                       ahd_dev_softc_t list_pci;
1005 -                       ahd_dev_softc_t pci;
1006 +                       aic_dev_softc_t list_pci;
1007 +                       aic_dev_softc_t pci;
1008  
1009                         list_pci = list_ahd->dev_softc;
1010                         pci = ahd->dev_softc;
1011 -                       if (ahd_get_pci_slot(list_pci) == ahd_get_pci_slot(pci)
1012 -                        && ahd_get_pci_bus(list_pci) == ahd_get_pci_bus(pci)) {
1013 +                       if (aic_get_pci_slot(list_pci) == aic_get_pci_slot(pci)
1014 +                        && aic_get_pci_bus(list_pci) == aic_get_pci_bus(pci)) {
1015                                 struct ahd_softc *master;
1016                                 struct ahd_softc *slave;
1017  
1018 -                               if (ahd_get_pci_function(list_pci) == 0) {
1019 +                               if (aic_get_pci_function(list_pci) == 0) {
1020                                         master = list_ahd;
1021                                         slave = ahd;
1022                                 } else {
1023 @@ -4935,27 +5258,27 @@
1024  {
1025         int i;
1026  
1027 +       ahd_terminate_recovery_thread(ahd);
1028         switch (ahd->init_level) {
1029         default:
1030         case 5:
1031                 ahd_shutdown(ahd);
1032 -               TAILQ_REMOVE(&ahd_tailq, ahd, links);
1033                 /* FALLTHROUGH */
1034         case 4:
1035 -               ahd_dmamap_unload(ahd, ahd->shared_data_dmat,
1036 -                                 ahd->shared_data_dmamap);
1037 +               aic_dmamap_unload(ahd, ahd->shared_data_dmat,
1038 +                                 ahd->shared_data_map.dmamap);
1039                 /* FALLTHROUGH */
1040         case 3:
1041 -               ahd_dmamem_free(ahd, ahd->shared_data_dmat, ahd->qoutfifo,
1042 -                               ahd->shared_data_dmamap);
1043 -               ahd_dmamap_destroy(ahd, ahd->shared_data_dmat,
1044 -                                  ahd->shared_data_dmamap);
1045 +               aic_dmamem_free(ahd, ahd->shared_data_dmat, ahd->qoutfifo,
1046 +                               ahd->shared_data_map.dmamap);
1047 +               aic_dmamap_destroy(ahd, ahd->shared_data_dmat,
1048 +                                  ahd->shared_data_map.dmamap);
1049                 /* FALLTHROUGH */
1050         case 2:
1051 -               ahd_dma_tag_destroy(ahd, ahd->shared_data_dmat);
1052 +               aic_dma_tag_destroy(ahd, ahd->shared_data_dmat);
1053         case 1:
1054  #ifndef __linux__
1055 -               ahd_dma_tag_destroy(ahd, ahd->buffer_dmat);
1056 +               aic_dma_tag_destroy(ahd, ahd->buffer_dmat);
1057  #endif
1058                 break;
1059         case 0:
1060 @@ -4963,7 +5286,7 @@
1061         }
1062  
1063  #ifndef __linux__
1064 -       ahd_dma_tag_destroy(ahd, ahd->parent_dmat);
1065 +       aic_dma_tag_destroy(ahd, ahd->parent_dmat);
1066  #endif
1067         ahd_platform_free(ahd);
1068         ahd_fini_scbdata(ahd);
1069 @@ -5016,8 +5339,8 @@
1070         /*
1071          * Stop periodic timer callbacks.
1072          */
1073 -       ahd_timer_stop(&ahd->reset_timer);
1074 -       ahd_timer_stop(&ahd->stat_timer);
1075 +       aic_timer_stop(&ahd->reset_timer);
1076 +       aic_timer_stop(&ahd->stat_timer);
1077  
1078         /* This will reset most registers to 0, but not all */
1079         ahd_reset(ahd, /*reinit*/FALSE);
1080 @@ -5049,7 +5372,7 @@
1081         ahd_set_modes(ahd, AHD_MODE_SCSI, AHD_MODE_SCSI);
1082         sxfrctl1 = ahd_inb(ahd, SXFRCTL1);
1083  
1084 -       cmd = ahd_pci_read_config(ahd->dev_softc, PCIR_COMMAND, /*bytes*/2);
1085 +       cmd = aic_pci_read_config(ahd->dev_softc, PCIR_COMMAND, /*bytes*/2);
1086         if ((ahd->bugs & AHD_PCIX_CHIPRST_BUG) != 0) {
1087                 uint32_t mod_cmd;
1088  
1089 @@ -5063,7 +5386,7 @@
1090                  * PERR and SERR responses during the CHIPRST.
1091                  */
1092                 mod_cmd = cmd & ~(PCIM_CMD_PERRESPEN|PCIM_CMD_SERRESPEN);
1093 -               ahd_pci_write_config(ahd->dev_softc, PCIR_COMMAND,
1094 +               aic_pci_write_config(ahd->dev_softc, PCIR_COMMAND,
1095                                      mod_cmd, /*bytes*/2);
1096         }
1097         ahd_outb(ahd, HCNTRL, CHIPRST | ahd->pause);
1098 @@ -5076,7 +5399,7 @@
1099          */
1100         wait = 1000;
1101         do {
1102 -               ahd_delay(1000);
1103 +               aic_delay(1000);
1104         } while (--wait && !(ahd_inb(ahd, HCNTRL) & CHIPRSTACK));
1105  
1106         if (wait == 0) {
1107 @@ -5090,9 +5413,9 @@
1108                  * Clear any latched PCI error status and restore
1109                  * previous SERR and PERR response enables.
1110                  */
1111 -               ahd_pci_write_config(ahd->dev_softc, PCIR_STATUS + 1,
1112 +               aic_pci_write_config(ahd->dev_softc, PCIR_STATUS + 1,
1113                                      0xFF, /*bytes*/1);
1114 -               ahd_pci_write_config(ahd->dev_softc, PCIR_COMMAND,
1115 +               aic_pci_write_config(ahd->dev_softc, PCIR_COMMAND,
1116                                      cmd, /*bytes*/2);
1117         }
1118  
1119 @@ -5219,7 +5542,7 @@
1120          */
1121  
1122         /* DMA tag for our hardware scb structures */
1123 -       if (ahd_dma_tag_create(ahd, ahd->parent_dmat, /*alignment*/1,
1124 +       if (aic_dma_tag_create(ahd, ahd->parent_dmat, /*alignment*/1,
1125                                /*boundary*/BUS_SPACE_MAXADDR_32BIT + 1,
1126                                /*lowaddr*/BUS_SPACE_MAXADDR_32BIT,
1127                                /*highaddr*/BUS_SPACE_MAXADDR,
1128 @@ -5233,7 +5556,7 @@
1129         scb_data->init_level++;
1130  
1131         /* DMA tag for our S/G structures. */
1132 -       if (ahd_dma_tag_create(ahd, ahd->parent_dmat, /*alignment*/8,
1133 +       if (aic_dma_tag_create(ahd, ahd->parent_dmat, /*alignment*/8,
1134                                /*boundary*/BUS_SPACE_MAXADDR_32BIT + 1,
1135                                /*lowaddr*/BUS_SPACE_MAXADDR_32BIT,
1136                                /*highaddr*/BUS_SPACE_MAXADDR,
1137 @@ -5252,7 +5575,7 @@
1138         scb_data->init_level++;
1139  
1140         /* DMA tag for our sense buffers.  We allocate in page sized chunks */
1141 -       if (ahd_dma_tag_create(ahd, ahd->parent_dmat, /*alignment*/1,
1142 +       if (aic_dma_tag_create(ahd, ahd->parent_dmat, /*alignment*/1,
1143                                /*boundary*/BUS_SPACE_MAXADDR_32BIT + 1,
1144                                /*lowaddr*/BUS_SPACE_MAXADDR_32BIT,
1145                                /*highaddr*/BUS_SPACE_MAXADDR,
1146 @@ -5340,13 +5663,13 @@
1147  
1148                 while ((sns_map = SLIST_FIRST(&scb_data->sense_maps)) != NULL) {
1149                         SLIST_REMOVE_HEAD(&scb_data->sense_maps, links);
1150 -                       ahd_dmamap_unload(ahd, scb_data->sense_dmat,
1151 +                       aic_dmamap_unload(ahd, scb_data->sense_dmat,
1152                                           sns_map->dmamap);
1153 -                       ahd_dmamem_free(ahd, scb_data->sense_dmat,
1154 +                       aic_dmamem_free(ahd, scb_data->sense_dmat,
1155                                         sns_map->vaddr, sns_map->dmamap);
1156                         free(sns_map, M_DEVBUF);
1157                 }
1158 -               ahd_dma_tag_destroy(ahd, scb_data->sense_dmat);
1159 +               aic_dma_tag_destroy(ahd, scb_data->sense_dmat);
1160                 /* FALLTHROUGH */
1161         }
1162         case 6:
1163 @@ -5355,13 +5678,13 @@
1164  
1165                 while ((sg_map = SLIST_FIRST(&scb_data->sg_maps)) != NULL) {
1166                         SLIST_REMOVE_HEAD(&scb_data->sg_maps, links);
1167 -                       ahd_dmamap_unload(ahd, scb_data->sg_dmat,
1168 +                       aic_dmamap_unload(ahd, scb_data->sg_dmat,
1169                                           sg_map->dmamap);
1170 -                       ahd_dmamem_free(ahd, scb_data->sg_dmat,
1171 +                       aic_dmamem_free(ahd, scb_data->sg_dmat,
1172                                         sg_map->vaddr, sg_map->dmamap);
1173                         free(sg_map, M_DEVBUF);
1174                 }
1175 -               ahd_dma_tag_destroy(ahd, scb_data->sg_dmat);
1176 +               aic_dma_tag_destroy(ahd, scb_data->sg_dmat);
1177                 /* FALLTHROUGH */
1178         }
1179         case 5:
1180 @@ -5370,13 +5693,13 @@
1181  
1182                 while ((hscb_map = SLIST_FIRST(&scb_data->hscb_maps)) != NULL) {
1183                         SLIST_REMOVE_HEAD(&scb_data->hscb_maps, links);
1184 -                       ahd_dmamap_unload(ahd, scb_data->hscb_dmat,
1185 +                       aic_dmamap_unload(ahd, scb_data->hscb_dmat,
1186                                           hscb_map->dmamap);
1187 -                       ahd_dmamem_free(ahd, scb_data->hscb_dmat,
1188 +                       aic_dmamem_free(ahd, scb_data->hscb_dmat,
1189                                         hscb_map->vaddr, hscb_map->dmamap);
1190                         free(hscb_map, M_DEVBUF);
1191                 }
1192 -               ahd_dma_tag_destroy(ahd, scb_data->hscb_dmat);
1193 +               aic_dma_tag_destroy(ahd, scb_data->hscb_dmat);
1194                 /* FALLTHROUGH */
1195         }
1196         case 4:
1197 @@ -5407,6 +5730,7 @@
1198                 printf("%s: Setting up iocell workaround\n", ahd_name(ahd));
1199  #endif
1200         ahd_restore_modes(ahd, saved_modes);
1201 +       ahd->flags &= ~AHD_HAD_FIRST_SEL;
1202  }
1203  
1204  static void
1205 @@ -5415,6 +5739,8 @@
1206         ahd_mode_state  saved_modes;
1207         u_int           sblkctl;
1208  
1209 +       if ((ahd->flags & AHD_HAD_FIRST_SEL) != 0)
1210 +               return;
1211         saved_modes = ahd_save_modes(ahd);
1212         ahd_set_modes(ahd, AHD_MODE_SCSI, AHD_MODE_SCSI);
1213         sblkctl = ahd_inb(ahd, SBLKCTL);
1214 @@ -5434,6 +5760,7 @@
1215         ahd_outb(ahd, SIMODE0, ahd_inb(ahd, SIMODE0) & ~(ENSELDO|ENSELDI));
1216         ahd_outb(ahd, CLRINT, CLRSCSIINT);
1217         ahd_restore_modes(ahd, saved_modes);
1218 +       ahd->flags |= AHD_HAD_FIRST_SEL;
1219  }
1220  
1221  /*************************** SCB Management ***********************************/
1222 @@ -5577,7 +5904,7 @@
1223                                  scb, links.le);
1224         }
1225  
1226 -       ahd_platform_scb_free(ahd, scb);
1227 +       aic_platform_scb_free(ahd, scb);
1228  }
1229  
1230  void
1231 @@ -5608,7 +5935,7 @@
1232                 offset = (PAGE_SIZE / sizeof(*hscb)) - scb_data->scbs_left;
1233                 hscb_map = SLIST_FIRST(&scb_data->hscb_maps);
1234                 hscb = &((struct hardware_scb *)hscb_map->vaddr)[offset];
1235 -               hscb_busaddr = hscb_map->physaddr + (offset * sizeof(*hscb));
1236 +               hscb_busaddr = hscb_map->busaddr + (offset * sizeof(*hscb));
1237         } else {
1238                 hscb_map = malloc(sizeof(*hscb_map), M_DEVBUF, M_NOWAIT);
1239  
1240 @@ -5616,7 +5943,7 @@
1241                         return;
1242  
1243                 /* Allocate the next batch of hardware SCBs */
1244 -               if (ahd_dmamem_alloc(ahd, scb_data->hscb_dmat,
1245 +               if (aic_dmamem_alloc(ahd, scb_data->hscb_dmat,
1246                                      (void **)&hscb_map->vaddr,
1247                                      BUS_DMA_NOWAIT, &hscb_map->dmamap) != 0) {
1248                         free(hscb_map, M_DEVBUF);
1249 @@ -5625,12 +5952,12 @@
1250  
1251                 SLIST_INSERT_HEAD(&scb_data->hscb_maps, hscb_map, links);
1252  
1253 -               ahd_dmamap_load(ahd, scb_data->hscb_dmat, hscb_map->dmamap,
1254 +               aic_dmamap_load(ahd, scb_data->hscb_dmat, hscb_map->dmamap,
1255                                 hscb_map->vaddr, PAGE_SIZE, ahd_dmamap_cb,
1256 -                               &hscb_map->physaddr, /*flags*/0);
1257 +                               &hscb_map->busaddr, /*flags*/0);
1258  
1259                 hscb = (struct hardware_scb *)hscb_map->vaddr;
1260 -               hscb_busaddr = hscb_map->physaddr;
1261 +               hscb_busaddr = hscb_map->busaddr;
1262                 scb_data->scbs_left = PAGE_SIZE / sizeof(*hscb);
1263         }
1264  
1265 @@ -5641,7 +5968,7 @@
1266                        - scb_data->sgs_left) * ahd_sglist_size(ahd);
1267                 sg_map = SLIST_FIRST(&scb_data->sg_maps);
1268                 segs = sg_map->vaddr + offset;
1269 -               sg_busaddr = sg_map->physaddr + offset;
1270 +               sg_busaddr = sg_map->busaddr + offset;
1271         } else {
1272                 sg_map = malloc(sizeof(*sg_map), M_DEVBUF, M_NOWAIT);
1273  
1274 @@ -5649,7 +5976,7 @@
1275                         return;
1276  
1277                 /* Allocate the next batch of S/G lists */
1278 -               if (ahd_dmamem_alloc(ahd, scb_data->sg_dmat,
1279 +               if (aic_dmamem_alloc(ahd, scb_data->sg_dmat,
1280                                      (void **)&sg_map->vaddr,
1281                                      BUS_DMA_NOWAIT, &sg_map->dmamap) != 0) {
1282                         free(sg_map, M_DEVBUF);
1283 @@ -5658,12 +5985,12 @@
1284  
1285                 SLIST_INSERT_HEAD(&scb_data->sg_maps, sg_map, links);
1286  
1287 -               ahd_dmamap_load(ahd, scb_data->sg_dmat, sg_map->dmamap,
1288 +               aic_dmamap_load(ahd, scb_data->sg_dmat, sg_map->dmamap,
1289                                 sg_map->vaddr, ahd_sglist_allocsize(ahd),
1290 -                               ahd_dmamap_cb, &sg_map->physaddr, /*flags*/0);
1291 +                               ahd_dmamap_cb, &sg_map->busaddr, /*flags*/0);
1292  
1293                 segs = sg_map->vaddr;
1294 -               sg_busaddr = sg_map->physaddr;
1295 +               sg_busaddr = sg_map->busaddr;
1296                 scb_data->sgs_left =
1297                     ahd_sglist_allocsize(ahd) / ahd_sglist_size(ahd);
1298  #ifdef AHD_DEBUG
1299 @@ -5678,7 +6005,7 @@
1300                 offset = PAGE_SIZE - (AHD_SENSE_BUFSIZE * scb_data->sense_left);
1301                 sense_map = SLIST_FIRST(&scb_data->sense_maps);
1302                 sense_data = sense_map->vaddr + offset;
1303 -               sense_busaddr = sense_map->physaddr + offset;
1304 +               sense_busaddr = sense_map->busaddr + offset;
1305         } else {
1306                 sense_map = malloc(sizeof(*sense_map), M_DEVBUF, M_NOWAIT);
1307  
1308 @@ -5686,7 +6013,7 @@
1309                         return;
1310  
1311                 /* Allocate the next batch of sense buffers */
1312 -               if (ahd_dmamem_alloc(ahd, scb_data->sense_dmat,
1313 +               if (aic_dmamem_alloc(ahd, scb_data->sense_dmat,
1314                                      (void **)&sense_map->vaddr,
1315                                      BUS_DMA_NOWAIT, &sense_map->dmamap) != 0) {
1316                         free(sense_map, M_DEVBUF);
1317 @@ -5695,12 +6022,12 @@
1318  
1319                 SLIST_INSERT_HEAD(&scb_data->sense_maps, sense_map, links);
1320  
1321 -               ahd_dmamap_load(ahd, scb_data->sense_dmat, sense_map->dmamap,
1322 +               aic_dmamap_load(ahd, scb_data->sense_dmat, sense_map->dmamap,
1323                                 sense_map->vaddr, PAGE_SIZE, ahd_dmamap_cb,
1324 -                               &sense_map->physaddr, /*flags*/0);
1325 +                               &sense_map->busaddr, /*flags*/0);
1326  
1327                 sense_data = sense_map->vaddr;
1328 -               sense_busaddr = sense_map->physaddr;
1329 +               sense_busaddr = sense_map->busaddr;
1330                 scb_data->sense_left = PAGE_SIZE / AHD_SENSE_BUFSIZE;
1331  #ifdef AHD_DEBUG
1332                 if (ahd_debug & AHD_SHOW_MEMORY)
1333 @@ -5741,7 +6068,7 @@
1334                 next_scb->sense_busaddr = sense_busaddr;
1335                 memset(hscb, 0, sizeof(*hscb));
1336                 next_scb->hscb = hscb;
1337 -               hscb->hscb_busaddr = ahd_htole32(hscb_busaddr);
1338 +               hscb->hscb_busaddr = aic_htole32(hscb_busaddr);
1339  
1340                 /*
1341                  * The sequencer always starts with the second entry.
1342 @@ -5756,7 +6083,7 @@
1343                 next_scb->ahd_softc = ahd;
1344                 next_scb->flags = SCB_FLAG_NONE;
1345  #ifndef __linux__
1346 -               error = ahd_dmamap_create(ahd, ahd->buffer_dmat, /*flags*/0,
1347 +               error = aic_dmamap_create(ahd, ahd->buffer_dmat, /*flags*/0,
1348                                           &next_scb->dmamap);
1349                 if (error != 0) {
1350                         free(next_scb, M_DEVBUF);
1351 @@ -5764,7 +6091,7 @@
1352                         break;
1353                 }
1354  #endif
1355 -               next_scb->hscb->tag = ahd_htole16(scb_data->numscbs);
1356 +               next_scb->hscb->tag = aic_htole16(scb_data->numscbs);
1357                 col_tag = scb_data->numscbs ^ 0x100;
1358                 next_scb->col_scb = ahd_find_scb_by_tag(ahd, col_tag);
1359                 if (next_scb->col_scb != NULL)
1360 @@ -5824,7 +6151,6 @@
1361  int
1362  ahd_init(struct ahd_softc *ahd)
1363  {
1364 -       uint8_t         *base_vaddr;
1365         uint8_t         *next_vaddr;
1366         bus_addr_t       next_baddr;
1367         size_t           driver_data_size;
1368 @@ -5867,7 +6193,7 @@
1369  
1370  #ifndef __linux__
1371         /* DMA tag for mapping buffers into device visible space. */
1372 -       if (ahd_dma_tag_create(ahd, ahd->parent_dmat, /*alignment*/1,
1373 +       if (aic_dma_tag_create(ahd, ahd->parent_dmat, /*alignment*/1,
1374                                /*boundary*/BUS_SPACE_MAXADDR_32BIT + 1,
1375                                /*lowaddr*/ahd->flags & AHD_39BIT_ADDRESSING
1376                                         ? (bus_addr_t)0x7FFFFFFFFFULL
1377 @@ -5898,7 +6224,7 @@
1378                 driver_data_size += AHD_TMODE_CMDS * sizeof(struct target_cmd);
1379         if ((ahd->bugs & AHD_PKT_BITBUCKET_BUG) != 0)
1380                 driver_data_size += PKT_OVERRUN_BUFSIZE;
1381 -       if (ahd_dma_tag_create(ahd, ahd->parent_dmat, /*alignment*/1,
1382 +       if (aic_dma_tag_create(ahd, ahd->parent_dmat, /*alignment*/1,
1383                                /*boundary*/BUS_SPACE_MAXADDR_32BIT + 1,
1384                                /*lowaddr*/BUS_SPACE_MAXADDR_32BIT,
1385                                /*highaddr*/BUS_SPACE_MAXADDR,
1386 @@ -5913,21 +6239,24 @@
1387         ahd->init_level++;
1388  
1389         /* Allocation of driver data */
1390 -       if (ahd_dmamem_alloc(ahd, ahd->shared_data_dmat,
1391 -                            (void **)&base_vaddr,
1392 -                            BUS_DMA_NOWAIT, &ahd->shared_data_dmamap) != 0) {
1393 +       if (aic_dmamem_alloc(ahd, ahd->shared_data_dmat,
1394 +                            (void **)&ahd->shared_data_map.vaddr,
1395 +                            BUS_DMA_NOWAIT,
1396 +                            &ahd->shared_data_map.dmamap) != 0) {
1397                 return (ENOMEM);
1398         }
1399  
1400         ahd->init_level++;
1401  
1402         /* And permanently map it in */
1403 -       ahd_dmamap_load(ahd, ahd->shared_data_dmat, ahd->shared_data_dmamap,
1404 -                       base_vaddr, driver_data_size, ahd_dmamap_cb,
1405 -                       &ahd->shared_data_busaddr, /*flags*/0);
1406 -       ahd->qoutfifo = (uint16_t *)base_vaddr;
1407 +       aic_dmamap_load(ahd, ahd->shared_data_dmat, ahd->shared_data_map.dmamap,
1408 +                       ahd->shared_data_map.vaddr, driver_data_size,
1409 +                       ahd_dmamap_cb, &ahd->shared_data_map.busaddr,
1410 +                       /*flags*/0);
1411 +       ahd->qoutfifo = (uint16_t *)ahd->shared_data_map.vaddr;
1412         next_vaddr = (uint8_t *)&ahd->qoutfifo[AHD_QOUT_SIZE];
1413 -       next_baddr = ahd->shared_data_busaddr + AHD_QOUT_SIZE*sizeof(uint16_t);
1414 +       next_baddr = ahd->shared_data_map.busaddr
1415 +                  + AHD_QOUT_SIZE*sizeof(uint16_t);
1416         if ((ahd->features & AHD_TARGETMODE) != 0) {
1417                 ahd->targetcmds = (struct target_cmd *)next_vaddr;
1418                 next_vaddr += AHD_TMODE_CMDS * sizeof(struct target_cmd);
1419 @@ -5948,7 +6277,8 @@
1420          * specially from the DMA safe memory chunk used for the QOUTFIFO.
1421          */
1422         ahd->next_queued_hscb = (struct hardware_scb *)next_vaddr;
1423 -       ahd->next_queued_hscb->hscb_busaddr = ahd_htole32(next_baddr);
1424 +       ahd->next_queued_hscb_map = &ahd->shared_data_map;
1425 +       ahd->next_queued_hscb->hscb_busaddr = aic_htole32(next_baddr);
1426  
1427         ahd->init_level++;
1428  
1429 @@ -6039,7 +6369,7 @@
1430         }
1431  init_done:
1432         ahd_restart(ahd);
1433 -       ahd_timer_reset(&ahd->stat_timer, AHD_STAT_UPDATE_US,
1434 +       aic_timer_reset(&ahd->stat_timer, AHD_STAT_UPDATE_US,
1435                         ahd_stat_timer, ahd);
1436         return (0);
1437  }
1438 @@ -6100,7 +6430,7 @@
1439         for (wait = 10000;
1440              (ahd_inb(ahd, SBLKCTL) & (ENAB40|ENAB20)) == 0 && wait;
1441              wait--)
1442 -               ahd_delay(100);
1443 +               aic_delay(100);
1444  
1445         /* Clear any false bus resets due to the transceivers settling */
1446         ahd_outb(ahd, CLRSINT1, CLRSCSIRSTI);
1447 @@ -6240,6 +6570,7 @@
1448         ahd_outb(ahd, CLRSINT3, NTRAMPERR|OSRAMPERR);
1449         ahd_outb(ahd, CLRINT, CLRSCSIINT);
1450  
1451 +#if NEEDS_MORE_TESTING
1452         /*
1453          * Always enable abort on incoming L_Qs if this feature is
1454          * supported.  We use this to catch invalid SCB references.
1455 @@ -6247,6 +6578,7 @@
1456         if ((ahd->bugs & AHD_ABORT_LQI_BUG) == 0)
1457                 ahd_outb(ahd, LQCTL1, ABORTPENDING);
1458         else
1459 +#endif
1460                 ahd_outb(ahd, LQCTL1, 0);
1461  
1462         /* All of our queues are empty */
1463 @@ -6296,15 +6628,9 @@
1464         /*
1465          * Tell the sequencer where it can find our arrays in memory.
1466          */
1467 -       busaddr = ahd->shared_data_busaddr;
1468 -       ahd_outb(ahd, SHARED_DATA_ADDR, busaddr & 0xFF);
1469 -       ahd_outb(ahd, SHARED_DATA_ADDR + 1, (busaddr >> 8) & 0xFF);
1470 -       ahd_outb(ahd, SHARED_DATA_ADDR + 2, (busaddr >> 16) & 0xFF);
1471 -       ahd_outb(ahd, SHARED_DATA_ADDR + 3, (busaddr >> 24) & 0xFF);
1472 -       ahd_outb(ahd, QOUTFIFO_NEXT_ADDR, busaddr & 0xFF);
1473 -       ahd_outb(ahd, QOUTFIFO_NEXT_ADDR + 1, (busaddr >> 8) & 0xFF);
1474 -       ahd_outb(ahd, QOUTFIFO_NEXT_ADDR + 2, (busaddr >> 16) & 0xFF);
1475 -       ahd_outb(ahd, QOUTFIFO_NEXT_ADDR + 3, (busaddr >> 24) & 0xFF);
1476 +       busaddr = ahd->shared_data_map.busaddr;
1477 +       ahd_outl(ahd, SHARED_DATA_ADDR, busaddr);
1478 +       ahd_outl(ahd, QOUTFIFO_NEXT_ADDR, busaddr);
1479  
1480         /*
1481          * Setup the allowed SCSI Sequences based on operational mode.
1482 @@ -6352,11 +6678,8 @@
1483         /*
1484          * Tell the sequencer which SCB will be the next one it receives.
1485          */
1486 -       busaddr = ahd_le32toh(ahd->next_queued_hscb->hscb_busaddr);
1487 -       ahd_outb(ahd, NEXT_QUEUED_SCB_ADDR + 0, busaddr & 0xFF);
1488 -       ahd_outb(ahd, NEXT_QUEUED_SCB_ADDR + 1, (busaddr >> 8) & 0xFF);
1489 -       ahd_outb(ahd, NEXT_QUEUED_SCB_ADDR + 2, (busaddr >> 16) & 0xFF);
1490 -       ahd_outb(ahd, NEXT_QUEUED_SCB_ADDR + 3, (busaddr >> 24) & 0xFF);
1491 +       busaddr = aic_le32toh(ahd->next_queued_hscb->hscb_busaddr);
1492 +       ahd_outl(ahd, NEXT_QUEUED_SCB_ADDR, busaddr);
1493  
1494         /*
1495          * Default to coalescing disabled.
1496 @@ -6677,6 +7000,12 @@
1497                 struct scb *waiting_scb;
1498  
1499                 ahd_unpause(ahd);
1500 +               /*
1501 +                * Give the sequencer some time to service
1502 +                * any active selections.
1503 +                */
1504 +               aic_delay(200);
1505 +
1506                 ahd_intr(ahd);
1507                 ahd_pause(ahd);
1508                 ahd_clear_critical_section(ahd);
1509 @@ -6888,11 +7217,8 @@
1510         if (prev_scb == NULL) {
1511                 uint32_t busaddr;
1512  
1513 -               busaddr = ahd_le32toh(scb->hscb->hscb_busaddr);
1514 -               ahd_outb(ahd, NEXT_QUEUED_SCB_ADDR + 0, busaddr & 0xFF);
1515 -               ahd_outb(ahd, NEXT_QUEUED_SCB_ADDR + 1, (busaddr >> 8) & 0xFF);
1516 -               ahd_outb(ahd, NEXT_QUEUED_SCB_ADDR + 2, (busaddr >> 16) & 0xFF);
1517 -               ahd_outb(ahd, NEXT_QUEUED_SCB_ADDR + 3, (busaddr >> 24) & 0xFF);
1518 +               busaddr = aic_le32toh(scb->hscb->hscb_busaddr);
1519 +               ahd_outl(ahd, NEXT_QUEUED_SCB_ADDR, busaddr);
1520         } else {
1521                 prev_scb->hscb->next_hscb_busaddr = scb->hscb->hscb_busaddr;
1522                 ahd_sync_scb(ahd, prev_scb, 
1523 @@ -6998,11 +7324,8 @@
1524          * for removal will be re-added to the queue as we go.
1525          */
1526         ahd->qinfifonext = qinstart;
1527 -       busaddr = ahd_le32toh(ahd->next_queued_hscb->hscb_busaddr);
1528 -       ahd_outb(ahd, NEXT_QUEUED_SCB_ADDR + 0, busaddr & 0xFF);
1529 -       ahd_outb(ahd, NEXT_QUEUED_SCB_ADDR + 1, (busaddr >> 8) & 0xFF);
1530 -       ahd_outb(ahd, NEXT_QUEUED_SCB_ADDR + 2, (busaddr >> 16) & 0xFF);
1531 -       ahd_outb(ahd, NEXT_QUEUED_SCB_ADDR + 3, (busaddr >> 24) & 0xFF);
1532 +       busaddr = aic_le32toh(ahd->next_queued_hscb->hscb_busaddr);
1533 +       ahd_outl(ahd, NEXT_QUEUED_SCB_ADDR, busaddr);
1534  
1535         while (qinpos != qintail) {
1536                 scb = ahd_lookup_scb(ahd, ahd->qinfifo[qinpos]);
1537 @@ -7023,13 +7346,13 @@
1538                                 cam_status ostat;
1539                                 cam_status cstat;
1540  
1541 -                               ostat = ahd_get_transaction_status(scb);
1542 +                               ostat = aic_get_transaction_status(scb);
1543                                 if (ostat == CAM_REQ_INPROG)
1544 -                                       ahd_set_transaction_status(scb,
1545 +                                       aic_set_transaction_status(scb,
1546                                                                    status);
1547 -                               cstat = ahd_get_transaction_status(scb);
1548 +                               cstat = aic_get_transaction_status(scb);
1549                                 if (cstat != CAM_REQ_CMP)
1550 -                                       ahd_freeze_scb(scb);
1551 +                                       aic_freeze_scb(scb);
1552                                 if ((scb->flags & SCB_ACTIVE) == 0)
1553                                         printf("Inactive SCB in qinfifo\n");
1554                                 ahd_done(ahd, scb);
1555 @@ -7165,12 +7488,12 @@
1556                         cam_status ostat;
1557                         cam_status cstat;
1558  
1559 -                       ostat = ahd_get_transaction_status(scb);
1560 +                       ostat = aic_get_transaction_status(scb);
1561                         if (ostat == CAM_REQ_INPROG)
1562 -                               ahd_set_transaction_status(scb, status);
1563 -                       cstat = ahd_get_transaction_status(scb);
1564 +                               aic_set_transaction_status(scb, status);
1565 +                       cstat = aic_get_transaction_status(scb);
1566                         if (cstat != CAM_REQ_CMP)
1567 -                               ahd_freeze_scb(scb);
1568 +                               aic_freeze_scb(scb);
1569                         if ((scb->flags & SCB_ACTIVE) == 0)
1570                                 printf("Inactive SCB in Waiting List\n");
1571                         ahd_done(ahd, scb);
1572 @@ -7361,11 +7684,11 @@
1573                 if (ahd_match_scb(ahd, scbp, target, channel, lun, tag, role)) {
1574                         cam_status ostat;
1575  
1576 -                       ostat = ahd_get_transaction_status(scbp);
1577 +                       ostat = aic_get_transaction_status(scbp);
1578                         if (ostat == CAM_REQ_INPROG)
1579 -                               ahd_set_transaction_status(scbp, status);
1580 -                       if (ahd_get_transaction_status(scbp) != CAM_REQ_CMP)
1581 -                               ahd_freeze_scb(scbp);
1582 +                               aic_set_transaction_status(scbp, status);
1583 +                       if (aic_get_transaction_status(scbp) != CAM_REQ_CMP)
1584 +                               aic_freeze_scb(scbp);
1585                         if ((scbp->flags & SCB_ACTIVE) == 0)
1586                                 printf("Inactive SCB on pending list\n");
1587                         ahd_done(ahd, scbp);
1588 @@ -7387,9 +7710,12 @@
1589         ahd_outb(ahd, SIMODE1, ahd_inb(ahd, SIMODE1) & ~ENSCSIRST);
1590         scsiseq = ahd_inb(ahd, SCSISEQ0) & ~(ENSELO|ENARBO|SCSIRSTO);
1591         ahd_outb(ahd, SCSISEQ0, scsiseq | SCSIRSTO);
1592 -       ahd_delay(AHD_BUSRESET_DELAY);
1593 +       ahd_flush_device_writes(ahd);
1594 +       aic_delay(AHD_BUSRESET_DELAY);
1595         /* Turn off the bus reset */
1596         ahd_outb(ahd, SCSISEQ0, scsiseq);
1597 +       ahd_flush_device_writes(ahd);
1598 +       aic_delay(AHD_BUSRESET_DELAY);
1599         if ((ahd->bugs & AHD_SCSIRST_BUG) != 0) {
1600                 /*
1601                  * 2A Razor #474
1602 @@ -7397,7 +7723,6 @@
1603                  * SCSI bus resets that we initiate, so
1604                  * we must reset the chip.
1605                  */
1606 -               ahd_delay(AHD_BUSRESET_DELAY);
1607                 ahd_reset(ahd, /*reinit*/TRUE);
1608                 ahd_intr_enable(ahd, /*enable*/TRUE);
1609                 AHD_ASSERT_MODES(ahd, AHD_MODE_SCSI_MSK, AHD_MODE_SCSI_MSK);
1610 @@ -7458,7 +7783,7 @@
1611                 ahd_outb(ahd, DFCNTRL,
1612                          ahd_inb(ahd, DFCNTRL) & ~(SCSIEN|HDMAEN));
1613                 while ((ahd_inb(ahd, DFCNTRL) & HDMAENACK) != 0)
1614 -                       ahd_delay(10);
1615 +                       aic_delay(10);
1616                 /*
1617                  * Set CURRFIFO to the now inactive channel.
1618                  */
1619 @@ -7471,7 +7796,7 @@
1620          */
1621         ahd_clear_msg_state(ahd);
1622         ahd_outb(ahd, SIMODE1,
1623 -                ahd_inb(ahd, SIMODE1) & ~(ENBUSFREE|ENSCSIRST|ENBUSFREE));
1624 +                ahd_inb(ahd, SIMODE1) & ~(ENBUSFREE|ENSCSIRST));
1625  
1626         if (initiate_reset)
1627                 ahd_reset_current_bus(ahd);
1628 @@ -7553,8 +7878,8 @@
1629          */
1630         if ((ahd->flags & AHD_RESET_POLL_ACTIVE) == 0) {
1631                 ahd->flags |= AHD_RESET_POLL_ACTIVE;
1632 -               ahd_freeze_simq(ahd);
1633 -               ahd_timer_reset(&ahd->reset_timer, 0, ahd_reset_poll, ahd);
1634 +               aic_freeze_simq(ahd);
1635 +               aic_timer_reset(&ahd->reset_timer, 0, ahd_reset_poll, ahd);
1636         }
1637         return (found);
1638  }
1639 @@ -7582,7 +7907,7 @@
1640         ahd_set_modes(ahd, AHD_MODE_SCSI, AHD_MODE_SCSI);
1641         ahd_outb(ahd, CLRSINT1, CLRSCSIRSTI);
1642         if ((ahd_inb(ahd, SSTAT1) & SCSIRSTI) != 0) {
1643 -               ahd_timer_reset(&ahd->reset_timer, AHD_RESET_POLL_US,
1644 +               aic_timer_reset(&ahd->reset_timer, AHD_RESET_POLL_US,
1645                                 ahd_reset_poll, ahd);
1646                 ahd_unpause(ahd);
1647                 ahd_unlock(ahd, &s);
1648 @@ -7597,7 +7922,7 @@
1649         ahd_unpause(ahd);
1650         ahd->flags &= ~AHD_RESET_POLL_ACTIVE;
1651         ahd_unlock(ahd, &s);
1652 -       ahd_release_simq(ahd);
1653 +       aic_release_simq(ahd);
1654         ahd_list_unlock(&l);
1655  }
1656  
1657 @@ -7640,7 +7965,7 @@
1658         ahd->cmdcmplt_bucket = (ahd->cmdcmplt_bucket+1) & (AHD_STAT_BUCKETS-1);
1659         ahd->cmdcmplt_total -= ahd->cmdcmplt_counts[ahd->cmdcmplt_bucket];
1660         ahd->cmdcmplt_counts[ahd->cmdcmplt_bucket] = 0;
1661 -       ahd_timer_reset(&ahd->stat_timer, AHD_STAT_UPDATE_US,
1662 +       aic_timer_reset(&ahd->stat_timer, AHD_STAT_UPDATE_US,
1663                         ahd_stat_timer, ahd);
1664         ahd_unlock(ahd, &s);
1665         ahd_list_unlock(&l);
1666 @@ -7661,8 +7986,9 @@
1667  void
1668  ahd_handle_scsi_status(struct ahd_softc *ahd, struct scb *scb)
1669  {
1670 -       struct hardware_scb *hscb;
1671 -       u_int  qfreeze_cnt;
1672 +       struct  hardware_scb *hscb;
1673 +       u_int   qfreeze_cnt;
1674 +       int     paused;
1675  
1676         /*
1677          * The sequencer freezes its select-out queue
1678 @@ -7672,9 +7998,16 @@
1679          */
1680         hscb = scb->hscb; 
1681  
1682 +       if (ahd_is_paused(ahd)) {
1683 +               paused = 1;
1684 +       } else {
1685 +               paused = 0;
1686 +               ahd_pause(ahd);
1687 +       }
1688 +
1689         /* Freeze the queue until the client sees the error. */
1690         ahd_freeze_devq(ahd, scb);
1691 -       ahd_freeze_scb(scb);
1692 +       aic_freeze_scb(scb);
1693         qfreeze_cnt = ahd_inw(ahd, QFREEZE_COUNT);
1694         if (qfreeze_cnt == 0) {
1695                 printf("%s: Bad status with 0 qfreeze count!\n", ahd_name(ahd));
1696 @@ -7686,6 +8019,9 @@
1697                 ahd_outb(ahd, SEQ_FLAGS2,
1698                          ahd_inb(ahd, SEQ_FLAGS2) & ~SELECTOUT_QFROZEN);
1699  
1700 +       if (paused == 0)
1701 +               ahd_unpause(ahd);
1702 +
1703         /* Don't want to clobber the original sense code */
1704         if ((scb->flags & SCB_SENSE) != 0) {
1705                 /*
1706 @@ -7693,12 +8029,12 @@
1707                  * a normal command completion.
1708                  */
1709                 scb->flags &= ~SCB_SENSE;
1710 -               ahd_set_transaction_status(scb, CAM_AUTOSENSE_FAIL);
1711 +               aic_set_transaction_status(scb, CAM_AUTOSENSE_FAIL);
1712                 ahd_done(ahd, scb);
1713                 return;
1714         }
1715 -       ahd_set_transaction_status(scb, CAM_SCSI_STATUS_ERROR);
1716 -       ahd_set_scsi_status(scb, hscb->shared_data.istatus.scsi_status);
1717 +       aic_set_transaction_status(scb, CAM_SCSI_STATUS_ERROR);
1718 +       aic_set_scsi_status(scb, hscb->shared_data.istatus.scsi_status);
1719         switch (hscb->shared_data.istatus.scsi_status) {
1720         case STATUS_PKT_SENSE:
1721         {
1722 @@ -7706,7 +8042,7 @@
1723  
1724                 ahd_sync_sense(ahd, scb, BUS_DMASYNC_POSTREAD);
1725                 siu = (struct scsi_status_iu_header *)scb->sense_data;
1726 -               ahd_set_scsi_status(scb, siu->status);
1727 +               aic_set_scsi_status(scb, siu->status);
1728  #ifdef AHD_DEBUG
1729                 if ((ahd_debug & AHD_SHOW_SENSE) != 0) {
1730                         ahd_print_path(ahd, scb);
1731 @@ -7747,7 +8083,7 @@
1732                                 }
1733                         }
1734                         if (siu->status == SCSI_STATUS_OK)
1735 -                               ahd_set_transaction_status(scb,
1736 +                               aic_set_transaction_status(scb,
1737                                                            CAM_REQ_CMP_ERR);
1738                 }
1739                 if ((siu->flags & SIU_SNSVALID) != 0) {
1740 @@ -7777,7 +8113,7 @@
1741                 }
1742  #endif
1743  
1744 -               if (ahd_perform_autosense(scb) == 0)
1745 +               if (aic_perform_autosense(scb) == 0)
1746                         break;
1747  
1748                 ahd_compile_devinfo(&devinfo, SCB_GET_OUR_ID(scb),
1749 @@ -7805,7 +8141,7 @@
1750  #endif
1751                 scb->sg_count = 0;
1752                 sg = ahd_sg_setup(ahd, scb, sg, ahd_get_sense_bufaddr(ahd, scb),
1753 -                                 ahd_get_sense_bufsize(ahd, scb),
1754 +                                 aic_get_sense_bufsize(ahd, scb),
1755                                   /*last*/TRUE);
1756                 sc->opcode = REQUEST_SENSE;
1757                 sc->byte2 = 0;
1758 @@ -7814,7 +8150,7 @@
1759                         sc->byte2 = SCB_GET_LUN(scb) << 5;
1760                 sc->unused[0] = 0;
1761                 sc->unused[1] = 0;
1762 -               sc->length = ahd_get_sense_bufsize(ahd, scb);
1763 +               sc->length = aic_get_sense_bufsize(ahd, scb);
1764                 sc->control = 0;
1765  
1766                 /*
1767 @@ -7834,7 +8170,7 @@
1768                  * errors will be reported before any data
1769                  * phases occur.
1770                  */
1771 -               if (ahd_get_residual(scb) == ahd_get_transfer_length(scb)) {
1772 +               if (aic_get_residual(scb) == aic_get_transfer_length(scb)) {
1773                         ahd_update_neg_request(ahd, &devinfo,
1774                                                tstate, targ_info,
1775                                                AHD_NEG_IF_NON_ASYNC);
1776 @@ -7853,7 +8189,7 @@
1777                  * Ensure we have enough time to actually
1778                  * retrieve the sense.
1779                  */
1780 -               ahd_scb_timer_reset(scb, 5 * 1000000);
1781 +               aic_scb_timer_reset(scb, 5 * 1000000);
1782                 break;
1783         }
1784         case SCSI_STATUS_OK:
1785 @@ -7895,7 +8231,7 @@
1786          */
1787  
1788         hscb = scb->hscb;
1789 -       sgptr = ahd_le32toh(hscb->sgptr);
1790 +       sgptr = aic_le32toh(hscb->sgptr);
1791         if ((sgptr & SG_STATUS_VALID) == 0)
1792                 /* Case 1 */
1793                 return;
1794 @@ -7912,10 +8248,10 @@
1795          * regardless of the role for this SCB.
1796          */
1797         spkt = &hscb->shared_data.istatus;
1798 -       resid_sgptr = ahd_le32toh(spkt->residual_sgptr);
1799 +       resid_sgptr = aic_le32toh(spkt->residual_sgptr);
1800         if ((sgptr & SG_FULL_RESID) != 0) {
1801                 /* Case 3 */
1802 -               resid = ahd_get_transfer_length(scb);
1803 +               resid = aic_get_transfer_length(scb);
1804         } else if ((resid_sgptr & SG_LIST_NULL) != 0) {
1805                 /* Case 4 */
1806                 return;
1807 @@ -7924,8 +8260,8 @@
1808                 printf("data overrun detected Tag == 0x%x.\n",
1809                        SCB_GET_TAG(scb));
1810                 ahd_freeze_devq(ahd, scb);
1811 -               ahd_set_transaction_status(scb, CAM_DATA_RUN_ERR);
1812 -               ahd_freeze_scb(scb);
1813 +               aic_set_transaction_status(scb, CAM_DATA_RUN_ERR);
1814 +               aic_freeze_scb(scb);
1815                 return;
1816         } else if ((resid_sgptr & ~SG_PTR_MASK) != 0) {
1817                 panic("Bogus resid sgptr value 0x%x\n", resid_sgptr);
1818 @@ -7937,7 +8273,7 @@
1819                  * Remainder of the SG where the transfer
1820                  * stopped.  
1821                  */
1822 -               resid = ahd_le32toh(spkt->residual_datacnt) & AHD_SG_LEN_MASK;
1823 +               resid = aic_le32toh(spkt->residual_datacnt) & AHD_SG_LEN_MASK;
1824                 sg = ahd_sg_bus_to_virt(ahd, scb, resid_sgptr & SG_PTR_MASK);
1825  
1826                 /* The residual sg_ptr always points to the next sg */
1827 @@ -7948,15 +8284,15 @@
1828                  * SG segments that are after the SG where
1829                  * the transfer stopped.
1830                  */
1831 -               while ((ahd_le32toh(sg->len) & AHD_DMA_LAST_SEG) == 0) {
1832 +               while ((aic_le32toh(sg->len) & AHD_DMA_LAST_SEG) == 0) {
1833                         sg++;
1834 -                       resid += ahd_le32toh(sg->len) & AHD_SG_LEN_MASK;
1835 +                       resid += aic_le32toh(sg->len) & AHD_SG_LEN_MASK;
1836                 }
1837         }
1838         if ((scb->flags & SCB_SENSE) == 0)
1839 -               ahd_set_residual(scb, resid);
1840 +               aic_set_residual(scb, resid);
1841         else
1842 -               ahd_set_sense_residual(scb, resid);
1843 +               aic_set_sense_residual(scb, resid);
1844  
1845  #ifdef AHD_DEBUG
1846         if ((ahd_debug & AHD_SHOW_MISC) != 0) {
1847 @@ -8068,8 +8404,7 @@
1848         max_prog = 2048;
1849  
1850         ahd_outb(ahd, SEQCTL0, PERRORDIS|FAILDIS|FASTMODE|LOADRAM);
1851 -       ahd_outb(ahd, PRGMCNT, 0);
1852 -       ahd_outb(ahd, PRGMCNT+1, 0);
1853 +       ahd_outw(ahd, PRGMCNT, 0);
1854         for (i = 0; i < max_prog; i++) {
1855                 uint8_t ins_bytes[4];
1856  
1857 @@ -8184,8 +8519,7 @@
1858         downloaded = 0;
1859         skip_addr = 0;
1860         ahd_outb(ahd, SEQCTL0, PERRORDIS|FAILDIS|FASTMODE|LOADRAM);
1861 -       ahd_outb(ahd, PRGMCNT, 0);
1862 -       ahd_outb(ahd, PRGMCNT+1, 0);
1863 +       ahd_outw(ahd, PRGMCNT, 0);
1864  
1865         for (i = 0; i < sizeof(seqprog)/4; i++) {
1866                 if (ahd_check_patch(ahd, &cur_patch, i, &skip_addr) == 0) {
1867 @@ -8314,7 +8648,7 @@
1868         /*
1869          * The firmware is always compiled into a little endian format.
1870          */
1871 -       instr.integer = ahd_le32toh(*(uint32_t*)&seqprog[instrptr * 4]);
1872 +       instr.integer = aic_le32toh(*(uint32_t*)&seqprog[instrptr * 4]);
1873  
1874         fmt1_ins = &instr.format1;
1875         fmt3_ins = NULL;
1876 @@ -8362,7 +8696,7 @@
1877                         instr.format1.parity = 1;
1878  
1879                 /* The sequencer is a little endian cpu */
1880 -               instr.integer = ahd_htole32(instr.integer);
1881 +               instr.integer = aic_htole32(instr.integer);
1882                 ahd_outsb(ahd, SEQRAM, instr.bytes, 4);
1883                 break;
1884         }
1885 @@ -8488,11 +8822,15 @@
1886         printf(">>>>>>>>>>>>>>>>>> Dump Card State Begins <<<<<<<<<<<<<<<<<\n"
1887                "%s: Dumping Card State at program address 0x%x Mode 0x%x\n",
1888                ahd_name(ahd), 
1889 -              ahd_inb(ahd, CURADDR) | (ahd_inb(ahd, CURADDR+1) << 8),
1890 +              ahd_inw(ahd, CURADDR),
1891                ahd_build_mode_state(ahd, ahd->saved_src_mode,
1892                                     ahd->saved_dst_mode));
1893         if (paused)
1894                 printf("Card was paused\n");
1895 +
1896 +       if (ahd_check_cmdcmpltqueues(ahd))
1897 +               printf("Completions are pending\n");
1898 +
1899         /*
1900          * Mode independent registers.
1901          */
1902 @@ -8542,10 +8880,12 @@
1903                 if (i++ > AHD_SCB_MAX)
1904                         break;
1905                 cur_col = printf("\n%3d FIFO_USE[0x%x] ", SCB_GET_TAG(scb),
1906 -                                ahd_inb(ahd, SCB_FIFO_USE_COUNT));
1907 +                                ahd_inb_scbram(ahd, SCB_FIFO_USE_COUNT));
1908                 ahd_set_scbptr(ahd, SCB_GET_TAG(scb));
1909 -               ahd_scb_control_print(ahd_inb(ahd, SCB_CONTROL), &cur_col, 60);
1910 -               ahd_scb_scsiid_print(ahd_inb(ahd, SCB_SCSIID), &cur_col, 60);
1911 +               ahd_scb_control_print(ahd_inb_scbram(ahd, SCB_CONTROL),
1912 +                                     &cur_col, 60);
1913 +               ahd_scb_scsiid_print(ahd_inb_scbram(ahd, SCB_SCSIID),
1914 +                                    &cur_col, 60);
1915         }
1916         printf("\nTotal %d\n", i);
1917  
1918 @@ -8574,7 +8914,7 @@
1919         while (!SCBID_IS_NULL(scb_index) && i++ < AHD_SCB_MAX) {
1920                 ahd_set_scbptr(ahd, scb_index);
1921                 printf("%d ", scb_index);
1922 -               scb_index = ahd_inw(ahd, SCB_NEXT_COMPLETE);
1923 +               scb_index = ahd_inw_scbram(ahd, SCB_NEXT_COMPLETE);
1924         }
1925         printf("\n");
1926  
1927 @@ -8584,7 +8924,7 @@
1928         while (!SCBID_IS_NULL(scb_index) && i++ < AHD_SCB_MAX) {
1929                 ahd_set_scbptr(ahd, scb_index);
1930                 printf("%d ", scb_index);
1931 -               scb_index = ahd_inw(ahd, SCB_NEXT_COMPLETE);
1932 +               scb_index = ahd_inw_scbram(ahd, SCB_NEXT_COMPLETE);
1933         }
1934         printf("\n");
1935  
1936 @@ -8595,7 +8935,7 @@
1937         while (!SCBID_IS_NULL(scb_index) && i++ < AHD_SCB_MAX) {
1938                 ahd_set_scbptr(ahd, scb_index);
1939                 printf("%d ", scb_index);
1940 -               scb_index = ahd_inw(ahd, SCB_NEXT_COMPLETE);
1941 +               scb_index = ahd_inw_scbram(ahd, SCB_NEXT_COMPLETE);
1942         }
1943         printf("\n");
1944         ahd_set_scbptr(ahd, saved_scb_index);
1945 @@ -8674,15 +9014,16 @@
1946                ahd_name(ahd), ahd_inw(ahd, REG0), ahd_inw(ahd, SINDEX),
1947                ahd_inw(ahd, DINDEX));
1948         printf("%s: SCBPTR == 0x%x, SCB_NEXT == 0x%x, SCB_NEXT2 == 0x%x\n",
1949 -              ahd_name(ahd), ahd_get_scbptr(ahd), ahd_inw(ahd, SCB_NEXT),
1950 -              ahd_inw(ahd, SCB_NEXT2));
1951 +              ahd_name(ahd), ahd_get_scbptr(ahd),
1952 +              ahd_inw_scbram(ahd, SCB_NEXT),
1953 +              ahd_inw_scbram(ahd, SCB_NEXT2));
1954         printf("CDB %x %x %x %x %x %x\n",
1955 -              ahd_inb(ahd, SCB_CDB_STORE),
1956 -              ahd_inb(ahd, SCB_CDB_STORE+1),
1957 -              ahd_inb(ahd, SCB_CDB_STORE+2),
1958 -              ahd_inb(ahd, SCB_CDB_STORE+3),
1959 -              ahd_inb(ahd, SCB_CDB_STORE+4),
1960 -              ahd_inb(ahd, SCB_CDB_STORE+5));
1961 +              ahd_inb_scbram(ahd, SCB_CDB_STORE),
1962 +              ahd_inb_scbram(ahd, SCB_CDB_STORE+1),
1963 +              ahd_inb_scbram(ahd, SCB_CDB_STORE+2),
1964 +              ahd_inb_scbram(ahd, SCB_CDB_STORE+3),
1965 +              ahd_inb_scbram(ahd, SCB_CDB_STORE+4),
1966 +              ahd_inb_scbram(ahd, SCB_CDB_STORE+5));
1967         printf("STACK:");
1968         for (i = 0; i < ahd->stack_size; i++) {
1969                 ahd->saved_stack[i] =
1970 @@ -8714,16 +9055,292 @@
1971                 ahd_set_scbptr(ahd, i);
1972                 printf("%3d", i);
1973                 printf("(CTRL 0x%x ID 0x%x N 0x%x N2 0x%x SG 0x%x, RSG 0x%x)\n",
1974 -                      ahd_inb(ahd, SCB_CONTROL),
1975 -                      ahd_inb(ahd, SCB_SCSIID), ahd_inw(ahd, SCB_NEXT),
1976 -                      ahd_inw(ahd, SCB_NEXT2), ahd_inl(ahd, SCB_SGPTR),
1977 -                      ahd_inl(ahd, SCB_RESIDUAL_SGPTR));
1978 +                      ahd_inb_scbram(ahd, SCB_CONTROL),
1979 +                      ahd_inb_scbram(ahd, SCB_SCSIID),
1980 +                      ahd_inw_scbram(ahd, SCB_NEXT),
1981 +                      ahd_inw_scbram(ahd, SCB_NEXT2),
1982 +                      ahd_inl_scbram(ahd, SCB_SGPTR),
1983 +                      ahd_inl_scbram(ahd, SCB_RESIDUAL_SGPTR));
1984         }
1985         printf("\n");
1986         ahd_set_scbptr(ahd, saved_scb_index);
1987         ahd_restore_modes(ahd, saved_modes);
1988  }
1989  
1990 +
1991 +/*************************** Timeout Handling *********************************/
1992 +void
1993 +ahd_timeout(struct scb *scb)
1994 +{
1995 +       struct ahd_softc *ahd;
1996 +
1997 +       ahd = scb->ahd_softc;
1998 +       if ((scb->flags & SCB_ACTIVE) != 0) {
1999 +               if ((scb->flags & SCB_TIMEDOUT) == 0) {
2000 +                       LIST_INSERT_HEAD(&ahd->timedout_scbs, scb,
2001 +                                        timedout_links);
2002 +                       scb->flags |= SCB_TIMEDOUT;
2003 +               }
2004 +               ahd_wakeup_recovery_thread(ahd);
2005 +       }
2006 +}
2007 +
2008 +/*
2009 + * ahd_recover_commands determines if any of the commands that have currently
2010 + * timedout are the root cause for this timeout.  Innocent commands are given
2011 + * a new timeout while we wait for the command executing on the bus to timeout.
2012 + * This routine is invoked from a thread context so we are allowed to sleep.
2013 + * Our lock is not held on entry.
2014 + */
2015 +void
2016 +ahd_recover_commands(struct ahd_softc *ahd)
2017 +{
2018 +       struct  scb *scb;
2019 +       struct  scb *active_scb;
2020 +       long    s;
2021 +       int     found;
2022 +       int     was_paused;
2023 +       u_int   active_scbptr;
2024 +       u_int   last_phase;
2025 +
2026 +       ahd_lock(ahd, &s);
2027 +
2028 +       /*
2029 +        * Pause the controller and manually flush any
2030 +        * commands that have just completed but that our
2031 +        * interrupt handler has yet to see.
2032 +        */
2033 +       was_paused = ahd_is_paused(ahd);
2034 +       ahd_pause_and_flushwork(ahd);
2035 +
2036 +       if (LIST_EMPTY(&ahd->timedout_scbs) != 0) {
2037 +               /*
2038 +                * The timedout commands have already
2039 +                * completed.  This typically means
2040 +                * that either the timeout value was on
2041 +                * the hairy edge of what the device
2042 +                * requires or - more likely - interrupts
2043 +                * are not happening.
2044 +                */
2045 +               printf("%s: Timedout SCBs already complete. "
2046 +                      "Interrupts may not be functioning.\n", ahd_name(ahd));
2047 +               ahd_unpause(ahd);
2048 +               ahd_unlock(ahd, &s);
2049 +               return;
2050 +       }
2051 +
2052 +       printf("%s: Recovery Initiated - Card was %spaused\n", ahd_name(ahd),
2053 +              was_paused ? "" : "not ");
2054 +       ahd_dump_card_state(ahd);
2055 +
2056 +       /*
2057 +        * Determine identity of SCB acting on the bus.
2058 +        * This test only catches non-packetized transactions.
2059 +        * Due to the fleeting nature of packetized operations,
2060 +        * we can't easily determine that a packetized operation
2061 +        * is on the bus.
2062 +        */
2063 +       ahd_set_modes(ahd, AHD_MODE_SCSI, AHD_MODE_SCSI);
2064 +       last_phase = ahd_inb(ahd, LASTPHASE);
2065 +       active_scbptr = ahd_get_scbptr(ahd);
2066 +       active_scb = NULL;
2067 +       if (last_phase != P_BUSFREE
2068 +        || (ahd_inb(ahd, SEQ_FLAGS) & NOT_IDENTIFIED) == 0)
2069 +               active_scb = ahd_lookup_scb(ahd, active_scbptr);
2070 +
2071 +       while ((scb = LIST_FIRST(&ahd->timedout_scbs)) != NULL) {
2072 +               int     target;
2073 +               int     lun;
2074 +               char    channel;
2075 +
2076 +               target = SCB_GET_TARGET(ahd, scb);
2077 +               channel = SCB_GET_CHANNEL(ahd, scb);
2078 +               lun = SCB_GET_LUN(scb);
2079 +
2080 +               ahd_print_path(ahd, scb);
2081 +               printf("SCB 0x%x - timed out\n", scb->hscb->tag);
2082 +
2083 +               if (scb->flags & (SCB_DEVICE_RESET|SCB_ABORT)) {
2084 +                       /*
2085 +                        * Been down this road before.
2086 +                        * Do a full bus reset.
2087 +                        */
2088 +                       aic_set_transaction_status(scb, CAM_CMD_TIMEOUT);
2089 +bus_reset:
2090 +                       found = ahd_reset_channel(ahd, channel,
2091 +                                                 /*Initiate Reset*/TRUE);
2092 +                       printf("%s: Issued Channel %c Bus Reset. "
2093 +                              "%d SCBs aborted\n", ahd_name(ahd), channel,
2094 +                              found);
2095 +                       continue;
2096 +               }
2097 +
2098 +               /*
2099 +                * Remove the command from the timedout list in
2100 +                * preparation for requeing it.
2101 +                */
2102 +               LIST_REMOVE(scb, timedout_links);
2103 +               scb->flags &= ~SCB_TIMEDOUT;
2104 +
2105 +               if (active_scb != NULL) {
2106 +
2107 +                       if (active_scb != scb) {
2108 +                               /*
2109 +                                * If the active SCB is not us, assume that
2110 +                                * the active SCB has a longer timeout than
2111 +                                * the timedout SCB, and wait for the active
2112 +                                * SCB to timeout.
2113 +                                */ 
2114 +                               ahd_other_scb_timeout(ahd, scb, active_scb);
2115 +                               continue;
2116 +                       } 
2117 +
2118 +                       /*
2119 +                        * We're active on the bus, so assert ATN
2120 +                        * and hope that the target responds.
2121 +                        */
2122 +                       ahd_set_recoveryscb(ahd, active_scb);
2123 +                       active_scb->flags |= SCB_RECOVERY_SCB|SCB_DEVICE_RESET;
2124 +                       ahd_outb(ahd, MSG_OUT, HOST_MSG);
2125 +                       ahd_outb(ahd, SCSISIGO, last_phase|ATNO);
2126 +                       ahd_print_path(ahd, active_scb);
2127 +                       printf("BDR message in message buffer\n");
2128 +                       aic_scb_timer_reset(scb, 2 * 1000000);
2129 +                       break;
2130 +               } else if (last_phase != P_BUSFREE
2131 +                       && ahd_inb(ahd, SCSIPHASE) == 0) {
2132 +                       /*
2133 +                        * SCB is not identified, there
2134 +                        * is no pending REQ, and the sequencer
2135 +                        * has not seen a busfree.  Looks like
2136 +                        * a stuck connection waiting to
2137 +                        * go busfree.  Reset the bus.
2138 +                        */
2139 +                       printf("%s: Connection stuck awaiting busfree or "
2140 +                              "Identify Msg.\n", ahd_name(ahd));
2141 +                       goto bus_reset;
2142 +               } else if (ahd_search_qinfifo(ahd, target, channel, lun,
2143 +                                             scb->hscb->tag, ROLE_INITIATOR,
2144 +                                             /*status*/0, SEARCH_COUNT) > 0) {
2145 +
2146 +                       /*
2147 +                        * We haven't even gone out on the bus
2148 +                        * yet, so the timeout must be due to
2149 +                        * some other command.  Reset the timer
2150 +                        * and go on.
2151 +                        */
2152 +                       ahd_other_scb_timeout(ahd, scb, scb);
2153 +               } else {
2154 +                       /*
2155 +                        * This SCB is for a disconnected transaction
2156 +                        * and we haven't found a better candidate on
2157 +                        * the bus to explain this timeout.
2158 +                        */
2159 +                       ahd_set_recoveryscb(ahd, scb);
2160 +
2161 +                       /*
2162 +                        * Actually re-queue this SCB in an attempt
2163 +                        * to select the device before it reconnects.
2164 +                        * In either case (selection or reselection),
2165 +                        * we will now issue a target reset to the
2166 +                        * timed-out device.
2167 +                        *
2168 +                        * Set the MK_MESSAGE control bit indicating
2169 +                        * that we desire to send a message.  We
2170 +                        * also set the disconnected flag since
2171 +                        * in the paging case there is no guarantee
2172 +                        * that our SCB control byte matches the
2173 +                        * version on the card.  We don't want the
2174 +                        * sequencer to abort the command thinking
2175 +                        * an unsolicited reselection occurred.
2176 +                        */
2177 +                       scb->flags |= SCB_DEVICE_RESET;
2178 +                       scb->hscb->cdb_len = 0;
2179 +                       scb->hscb->task_attribute = 0;
2180 +                       scb->hscb->task_management = SIU_TASKMGMT_ABORT_TASK;
2181 +
2182 +                       ahd_set_scbptr(ahd, SCB_GET_TAG(scb));
2183 +                       if ((scb->flags & SCB_PACKETIZED) != 0) {
2184 +                               /*
2185 +                                * Mark the SCB has having an outstanding
2186 +                                * task management function.  Should the command
2187 +                                * complete normally before the task management
2188 +                                * function can be sent, the host will be
2189 +                                * notified to abort our requeued SCB.
2190 +                                */
2191 +                               ahd_outb(ahd, SCB_TASK_MANAGEMENT,
2192 +                                        scb->hscb->task_management);
2193 +                       } else {
2194 +                               /*
2195 +                                * If non-packetized, set the MK_MESSAGE control
2196 +                                * bit indicating that we desire to send a
2197 +                                * message.  We also set the disconnected flag
2198 +                                * since there is no guarantee that our SCB
2199 +                                * control byte matches the version on the
2200 +                                * card.  We don't want the sequencer to abort
2201 +                                * the command thinking an unsolicited
2202 +                                * reselection occurred.
2203 +                                */
2204 +                               scb->hscb->control |= MK_MESSAGE|DISCONNECTED;
2205 +
2206 +                               /*
2207 +                                * The sequencer will never re-reference the
2208 +                                * in-core SCB.  To make sure we are notified
2209 +                                * during reslection, set the MK_MESSAGE flag in
2210 +                                * the card's copy of the SCB.
2211 +                                */
2212 +                               ahd_outb(ahd, SCB_CONTROL,
2213 +                                        ahd_inb(ahd, SCB_CONTROL)|MK_MESSAGE);
2214 +                       }
2215 +
2216 +                       /*
2217 +                        * Clear out any entries in the QINFIFO first
2218 +                        * so we are the next SCB for this target
2219 +                        * to run.
2220 +                        */
2221 +                       ahd_search_qinfifo(ahd, target, channel, lun,
2222 +                                          SCB_LIST_NULL, ROLE_INITIATOR,
2223 +                                          CAM_REQUEUE_REQ, SEARCH_COMPLETE);
2224 +                       ahd_qinfifo_requeue_tail(ahd, scb);
2225 +                       ahd_set_scbptr(ahd, active_scbptr);
2226 +                       ahd_print_path(ahd, scb);
2227 +                       printf("Queuing a BDR SCB\n");
2228 +                       aic_scb_timer_reset(scb, 2 * 1000000);
2229 +                       break;
2230 +               }
2231 +       }
2232 +       
2233 +       /*
2234 +        * Any remaining SCBs were not the "culprit", so remove
2235 +        * them from the timeout list.  The timer for these commands
2236 +        * will be reset once the recovery SCB completes.
2237 +        */
2238 +       while ((scb = LIST_FIRST(&ahd->timedout_scbs)) != NULL) {
2239 +
2240 +               LIST_REMOVE(scb, timedout_links);
2241 +               scb->flags &= ~SCB_TIMEDOUT;
2242 +       }
2243 +
2244 +       ahd_unpause(ahd);
2245 +       ahd_unlock(ahd, &s);
2246 +}
2247 +
2248 +static void
2249 +ahd_other_scb_timeout(struct ahd_softc *ahd, struct scb *scb,
2250 +                     struct scb *other_scb)
2251 +{
2252 +       u_int   newtimeout;
2253 +
2254 +       ahd_print_path(ahd, scb);
2255 +       printf("Other SCB Timeout%s",
2256 +              (scb->flags & SCB_OTHERTCL_TIMEOUT) != 0
2257 +              ? " again\n" : "\n");
2258 +       scb->flags |= SCB_OTHERTCL_TIMEOUT;
2259 +       newtimeout = MAX(aic_get_timeout(other_scb),
2260 +                        aic_get_timeout(scb));
2261 +       aic_scb_timer_reset(scb, newtimeout);
2262 +}
2263 +
2264  /**************************** Flexport Logic **********************************/
2265  /*
2266   * Read count 16bit words from 16bit word address start_addr from the
2267 @@ -8830,9 +9447,9 @@
2268  {
2269         int cnt;
2270  
2271 -       cnt = 20;
2272 +       cnt = 5000;
2273         while ((ahd_inb(ahd, SEESTAT) & (SEEARBACK|SEEBUSY)) != 0 && --cnt)
2274 -               ahd_delay(5);
2275 +               aic_delay(5);
2276  
2277         if (cnt == 0)
2278                 return (ETIMEDOUT);
2279 @@ -8974,7 +9591,7 @@
2280         AHD_ASSERT_MODES(ahd, AHD_MODE_SCSI_MSK, AHD_MODE_SCSI_MSK);
2281         cnt = 1000000 * 2 / 5;
2282         while ((ahd_inb(ahd, BRDCTL) & FLXARBACK) == 0 && --cnt)
2283 -               ahd_delay(5);
2284 +               aic_delay(5);
2285  
2286         if (cnt == 0)
2287                 return (ETIMEDOUT);
2288 @@ -9176,13 +9793,9 @@
2289                         if ((ahd->features & AHD_MULTI_TID) != 0) {
2290                                 u_int targid_mask;
2291  
2292 -                               targid_mask = ahd_inb(ahd, TARGID)
2293 -                                           | (ahd_inb(ahd, TARGID + 1) << 8);
2294 -
2295 +                               targid_mask = ahd_inw(ahd, TARGID);
2296                                 targid_mask |= target_mask;
2297 -                               ahd_outb(ahd, TARGID, targid_mask);
2298 -                               ahd_outb(ahd, TARGID+1, (targid_mask >> 8));
2299 -                               
2300 +                               ahd_outw(ahd, TARGID, targid_mask);
2301                                 ahd_update_scsiid(ahd, targid_mask);
2302                         } else {
2303                                 u_int our_id;
2304 @@ -9296,14 +9909,9 @@
2305                                 if (ahd->features & AHD_MULTI_TID) {
2306                                         u_int targid_mask;
2307  
2308 -                                       targid_mask = ahd_inb(ahd, TARGID)
2309 -                                                   | (ahd_inb(ahd, TARGID + 1)
2310 -                                                      << 8);
2311 -
2312 +                                       targid_mask = ahd_inw(ahd, TARGID);
2313                                         targid_mask &= ~target_mask;
2314 -                                       ahd_outb(ahd, TARGID, targid_mask);
2315 -                                       ahd_outb(ahd, TARGID+1,
2316 -                                                (targid_mask >> 8));
2317 +                                       ahd_outw(ahd, TARGID, targid_mask);
2318                                         ahd_update_scsiid(ahd, targid_mask);
2319                                 }
2320                         }
2321 diff -urN linux-2.4.24.org/drivers/scsi/aic7xxx/aic79xx.h linux-2.4.24/drivers/scsi/aic7xxx/aic79xx.h
2322 --- linux-2.4.24.org/drivers/scsi/aic7xxx/aic79xx.h     2004-01-08 11:57:43.067993795 +0100
2323 +++ linux-2.4.24/drivers/scsi/aic7xxx/aic79xx.h 2003-12-22 22:46:59.000000000 +0100
2324 @@ -37,7 +37,7 @@
2325   * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
2326   * POSSIBILITY OF SUCH DAMAGES.
2327   *
2328 - * $Id$
2329 + * $Id$
2330   *
2331   * $FreeBSD$
2332   */
2333 @@ -74,9 +74,9 @@
2334  #define ALL_TARGETS_MASK 0xFFFF
2335  #define INITIATOR_WILDCARD     (~0)
2336  #define        SCB_LIST_NULL           0xFF00
2337 -#define        SCB_LIST_NULL_LE        (ahd_htole16(SCB_LIST_NULL))
2338 +#define        SCB_LIST_NULL_LE        (aic_htole16(SCB_LIST_NULL))
2339  #define QOUTFIFO_ENTRY_VALID 0x8000
2340 -#define QOUTFIFO_ENTRY_VALID_LE (ahd_htole16(0x8000))
2341 +#define QOUTFIFO_ENTRY_VALID_LE (aic_htole16(0x8000))
2342  #define SCBID_IS_NULL(scbid) (((scbid) & 0xFF00 ) == SCB_LIST_NULL)
2343  
2344  #define SCSIID_TARGET(ahd, scsiid)     \
2345 @@ -118,7 +118,7 @@
2346         ((lun) | ((target) << 8))
2347  
2348  #define SCB_GET_TAG(scb) \
2349 -       ahd_le16toh(scb->hscb->tag)
2350 +       aic_le16toh(scb->hscb->tag)
2351  
2352  #ifndef        AHD_TARGET_MODE
2353  #undef AHD_TMODE_ENABLE
2354 @@ -229,8 +229,10 @@
2355         AHD_RTI                 = 0x04000,/* Retained Training Support */
2356         AHD_NEW_IOCELL_OPTS     = 0x08000,/* More Signal knobs in the IOCELL */
2357         AHD_NEW_DFCNTRL_OPTS    = 0x10000,/* SCSIENWRDIS bit */
2358 +       AHD_FAST_CDB_DELIVERY   = 0x20000,/* CDB acks released to Output Sync */
2359         AHD_REMOVABLE           = 0x00000,/* Hot-Swap supported - None so far*/
2360         AHD_AIC7901_FE          = AHD_FENONE,
2361 +       AHD_AIC7901A_FE         = AHD_FENONE,
2362         AHD_AIC7902_FE          = AHD_MULTI_FUNC
2363  } ahd_feature;
2364  
2365 @@ -372,7 +374,9 @@
2366         AHD_HP_BOARD          = 0x100000,
2367         AHD_RESET_POLL_ACTIVE = 0x200000,
2368         AHD_UPDATE_PEND_CMDS  = 0x400000,
2369 -       AHD_RUNNING_QOUTFIFO  = 0x800000
2370 +       AHD_RUNNING_QOUTFIFO  = 0x800000,
2371 +       AHD_HAD_FIRST_SEL     = 0x1000000,
2372 +       AHD_SHUTDOWN_RECOVERY = 0x2000000 /* Terminate recovery thread. */
2373  } ahd_flag;
2374  
2375  /************************* Hardware  SCB Definition ***************************/
2376 @@ -546,7 +550,7 @@
2377  
2378  struct map_node {
2379         bus_dmamap_t             dmamap;
2380 -       bus_addr_t               physaddr;
2381 +       bus_addr_t               busaddr;
2382         uint8_t                 *vaddr;
2383         SLIST_ENTRY(map_node)    links;
2384  };
2385 @@ -588,12 +592,16 @@
2386         SCB_PKT_SENSE           = 0x02000,
2387         SCB_CMDPHASE_ABORT      = 0x04000,
2388         SCB_ON_COL_LIST         = 0x08000,
2389 -       SCB_SILENT              = 0x10000 /*
2390 +       SCB_SILENT              = 0x10000,/*
2391                                            * Be quiet about transmission type
2392                                            * errors.  They are expected and we
2393                                            * don't want to upset the user.  This
2394                                            * flag is typically used during DV.
2395                                            */
2396 +       SCB_TIMEDOUT            = 0x20000/*
2397 +                                         * SCB has timed out and is on the
2398 +                                         * timedout list.
2399 +                                         */
2400  } scb_flag;
2401  
2402  struct scb {
2403 @@ -610,8 +618,9 @@
2404         } links2;
2405  #define pending_links links2.le
2406  #define collision_links links2.le
2407 +       LIST_ENTRY(scb)           timedout_links;
2408         struct scb               *col_scb;
2409 -       ahd_io_ctx_t              io_ctx;
2410 +       aic_io_ctx_t              io_ctx;
2411         struct ahd_softc         *ahd_softc;
2412         scb_flag                  flags;
2413  #ifndef __linux__
2414 @@ -1059,6 +1068,7 @@
2415         struct scb_data           scb_data;
2416  
2417         struct hardware_scb      *next_queued_hscb;
2418 +       struct map_node          *next_queued_hscb_map;
2419  
2420         /*
2421          * SCBs that have been sent to the controller
2422 @@ -1066,6 +1076,11 @@
2423         LIST_HEAD(, scb)          pending_scbs;
2424  
2425         /*
2426 +        * SCBs whose timeout routine has been called.
2427 +        */
2428 +       LIST_HEAD(, scb)          timedout_scbs;
2429 +
2430 +       /*
2431          * Current register window mode information.
2432          */
2433         ahd_mode                  dst_mode;
2434 @@ -1086,7 +1101,7 @@
2435         /*
2436          * Platform specific device information.
2437          */
2438 -       ahd_dev_softc_t           dev_softc;
2439 +       aic_dev_softc_t           dev_softc;
2440  
2441         /*
2442          * Bus specific device information.
2443 @@ -1116,8 +1131,8 @@
2444         /*
2445          * Timer handles for timer driven callbacks.
2446          */
2447 -       ahd_timer_t               reset_timer;
2448 -       ahd_timer_t               stat_timer;
2449 +       aic_timer_t               reset_timer;
2450 +       aic_timer_t               stat_timer;
2451  
2452         /*
2453          * Statistics.
2454 @@ -1194,8 +1209,7 @@
2455          */
2456         bus_dma_tag_t             parent_dmat;
2457         bus_dma_tag_t             shared_data_dmat;
2458 -       bus_dmamap_t              shared_data_dmamap;
2459 -       bus_addr_t                shared_data_busaddr;
2460 +       struct map_node           shared_data_map;
2461  
2462         /* Information saved through suspend/resume cycles */
2463         struct ahd_suspend_state  suspend_state;
2464 @@ -1296,9 +1310,9 @@
2465  };
2466  
2467  /****************************** PCI Structures ********************************/
2468 -#define AHD_PCI_IOADDR0        PCIR_MAPS       /* I/O BAR*/
2469 -#define AHD_PCI_MEMADDR        (PCIR_MAPS + 4) /* Memory BAR */
2470 -#define AHD_PCI_IOADDR1        (PCIR_MAPS + 12)/* Second I/O BAR */
2471 +#define AHD_PCI_IOADDR0        PCIR_BAR(0)     /* I/O BAR*/
2472 +#define AHD_PCI_MEMADDR        PCIR_BAR(1)     /* Memory BAR */
2473 +#define AHD_PCI_IOADDR1        PCIR_BAR(3)     /* Second I/O BAR */
2474  
2475  typedef int (ahd_device_setup_t)(struct ahd_softc *);
2476  
2477 @@ -1338,7 +1352,7 @@
2478  }
2479  
2480  /***************************** PCI Front End *********************************/
2481 -struct ahd_pci_identity *ahd_find_pci_device(ahd_dev_softc_t);
2482 +struct ahd_pci_identity *ahd_find_pci_device(aic_dev_softc_t);
2483  int                      ahd_pci_config(struct ahd_softc *,
2484                                          struct ahd_pci_identity *);
2485  int    ahd_pci_test_register_access(struct ahd_softc *);
2486 @@ -1430,6 +1444,8 @@
2487                                                struct scb *scb);
2488  void                   ahd_calc_residual(struct ahd_softc *ahd,
2489                                           struct scb *scb);
2490 +void                   ahd_timeout(struct scb *scb);
2491 +void                   ahd_recover_commands(struct ahd_softc *ahd);
2492  /*************************** Utility Functions ********************************/
2493  struct ahd_phase_table_entry*
2494                         ahd_lookup_phase_entry(int phase);
2495 diff -urN linux-2.4.24.org/drivers/scsi/aic7xxx/aic79xx_inline.h linux-2.4.24/drivers/scsi/aic7xxx/aic79xx_inline.h
2496 --- linux-2.4.24.org/drivers/scsi/aic7xxx/aic79xx_inline.h      2004-01-08 11:57:43.058995655 +0100
2497 +++ linux-2.4.24/drivers/scsi/aic7xxx/aic79xx_inline.h  2003-12-22 22:46:59.000000000 +0100
2498 @@ -37,7 +37,7 @@
2499   * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
2500   * POSSIBILITY OF SUCH DAMAGES.
2501   *
2502 - * $Id$
2503 + * $Id$
2504   *
2505   * $FreeBSD$
2506   */
2507 @@ -250,15 +250,15 @@
2508                 struct ahd_dma64_seg *sg;
2509  
2510                 sg = (struct ahd_dma64_seg *)sgptr;
2511 -               sg->addr = ahd_htole64(addr);
2512 -               sg->len = ahd_htole32(len | (last ? AHD_DMA_LAST_SEG : 0));
2513 +               sg->addr = aic_htole64(addr);
2514 +               sg->len = aic_htole32(len | (last ? AHD_DMA_LAST_SEG : 0));
2515                 return (sg + 1);
2516         } else {
2517                 struct ahd_dma_seg *sg;
2518  
2519                 sg = (struct ahd_dma_seg *)sgptr;
2520 -               sg->addr = ahd_htole32(addr & 0xFFFFFFFF);
2521 -               sg->len = ahd_htole32(len | ((addr >> 8) & 0x7F000000)
2522 +               sg->addr = aic_htole32(addr & 0xFFFFFFFF);
2523 +               sg->len = aic_htole32(len | ((addr >> 8) & 0x7F000000)
2524                                     | (last ? AHD_DMA_LAST_SEG : 0));
2525                 return (sg + 1);
2526         }
2527 @@ -273,7 +273,7 @@
2528                 /* XXX what about ACA??  It is type 4, but TAG_TYPE == 0x3. */
2529                 scb->hscb->task_attribute = scb->hscb->control & SCB_TAG_TYPE;
2530         } else {
2531 -               if (ahd_get_transfer_length(scb) & 0x01)
2532 +               if (aic_get_transfer_length(scb) & 0x01)
2533                         scb->hscb->task_attribute = SCB_XFERLEN_ODD;
2534                 else
2535                         scb->hscb->task_attribute = 0;
2536 @@ -282,7 +282,7 @@
2537         if (scb->hscb->cdb_len <= MAX_CDB_LEN_WITH_SENSE_ADDR
2538          || (scb->hscb->cdb_len & SCB_CDB_LEN_PTR) != 0)
2539                 scb->hscb->shared_data.idata.cdb_plus_saddr.sense_addr =
2540 -                   ahd_htole32(scb->sense_busaddr);
2541 +                   aic_htole32(scb->sense_busaddr);
2542  }
2543  
2544  static __inline void
2545 @@ -308,8 +308,8 @@
2546                 if ((ahd->flags & AHD_39BIT_ADDRESSING) != 0) {
2547                         uint64_t high_addr;
2548  
2549 -                       high_addr = ahd_le32toh(sg->len) & 0x7F000000;
2550 -                       scb->hscb->dataptr |= ahd_htole64(high_addr << 8);
2551 +                       high_addr = aic_le32toh(sg->len) & 0x7F000000;
2552 +                       scb->hscb->dataptr |= aic_htole64(high_addr << 8);
2553                 }
2554                 scb->hscb->datacnt = sg->len;
2555         }
2556 @@ -319,13 +319,13 @@
2557          * sequencer will clear as soon as a data transfer
2558          * occurs.
2559          */
2560 -       scb->hscb->sgptr = ahd_htole32(scb->sg_list_busaddr|SG_FULL_RESID);
2561 +       scb->hscb->sgptr = aic_htole32(scb->sg_list_busaddr|SG_FULL_RESID);
2562  }
2563  
2564  static __inline void
2565  ahd_setup_noxfer_scb(struct ahd_softc *ahd, struct scb *scb)
2566  {
2567 -       scb->hscb->sgptr = ahd_htole32(SG_LIST_NULL);
2568 +       scb->hscb->sgptr = aic_htole32(SG_LIST_NULL);
2569         scb->hscb->dataptr = 0;
2570         scb->hscb->datacnt = 0;
2571  }
2572 @@ -383,7 +383,7 @@
2573  static __inline void
2574  ahd_sync_scb(struct ahd_softc *ahd, struct scb *scb, int op)
2575  {
2576 -       ahd_dmamap_sync(ahd, ahd->scb_data.hscb_dmat,
2577 +       aic_dmamap_sync(ahd, ahd->scb_data.hscb_dmat,
2578                         scb->hscb_map->dmamap,
2579                         /*offset*/(uint8_t*)scb->hscb - scb->hscb_map->vaddr,
2580                         /*len*/sizeof(*scb->hscb), op);
2581 @@ -395,7 +395,7 @@
2582         if (scb->sg_count == 0)
2583                 return;
2584  
2585 -       ahd_dmamap_sync(ahd, ahd->scb_data.sg_dmat,
2586 +       aic_dmamap_sync(ahd, ahd->scb_data.sg_dmat,
2587                         scb->sg_map->dmamap,
2588                         /*offset*/scb->sg_list_busaddr - ahd_sg_size(ahd),
2589                         /*len*/ahd_sg_size(ahd) * scb->sg_count, op);
2590 @@ -404,7 +404,7 @@
2591  static __inline void
2592  ahd_sync_sense(struct ahd_softc *ahd, struct scb *scb, int op)
2593  {
2594 -       ahd_dmamap_sync(ahd, ahd->scb_data.sense_dmat,
2595 +       aic_dmamap_sync(ahd, ahd->scb_data.sense_dmat,
2596                         scb->sense_map->dmamap,
2597                         /*offset*/scb->sense_busaddr,
2598                         /*len*/AHD_SENSE_BUFSIZE, op);
2599 @@ -455,6 +455,8 @@
2600  static __inline u_int  ahd_inw_scbram(struct ahd_softc *ahd, u_int offset);
2601  static __inline uint32_t
2602                         ahd_inl_scbram(struct ahd_softc *ahd, u_int offset);
2603 +static __inline uint64_t
2604 +                       ahd_inq_scbram(struct ahd_softc *ahd, u_int offset);
2605  static __inline void   ahd_swap_with_next_hscb(struct ahd_softc *ahd,
2606                                                 struct scb *scb);
2607  static __inline void   ahd_queue_scb(struct ahd_softc *ahd, struct scb *scb);
2608 @@ -470,7 +472,7 @@
2609  {
2610         uint32_t sgptr;
2611  
2612 -       sgptr = ahd_le32toh(scb->hscb->sgptr);
2613 +       sgptr = aic_le32toh(scb->hscb->sgptr);
2614         if ((sgptr & SG_STATUS_VALID) != 0)
2615                 ahd_handle_scb_status(ahd, scb);
2616         else
2617 @@ -486,7 +488,7 @@
2618  {
2619         uint32_t sgptr;
2620  
2621 -       sgptr = ahd_le32toh(scb->hscb->sgptr);
2622 +       sgptr = aic_le32toh(scb->hscb->sgptr);
2623         if ((sgptr & SG_STATUS_VALID) != 0)
2624                 ahd_calc_residual(ahd, scb);
2625  }
2626 @@ -520,12 +522,21 @@
2627  static __inline uint16_t
2628  ahd_inw(struct ahd_softc *ahd, u_int port)
2629  {
2630 +       /*
2631 +        * Read high byte first as some registers increment
2632 +        * or have other side effects when the low byte is
2633 +        * read.
2634 +        */
2635         return ((ahd_inb(ahd, port+1) << 8) | ahd_inb(ahd, port));
2636  }
2637  
2638  static __inline void
2639  ahd_outw(struct ahd_softc *ahd, u_int port, u_int value)
2640  {
2641 +       /*
2642 +        * Write low byte first to accomodate registers
2643 +        * such as PRGMCNT where the order maters.
2644 +        */
2645         ahd_outb(ahd, port, value & 0xFF);
2646         ahd_outb(ahd, port+1, (value >> 8) & 0xFF);
2647  }
2648 @@ -697,10 +708,15 @@
2649  static __inline uint32_t
2650  ahd_inl_scbram(struct ahd_softc *ahd, u_int offset)
2651  {
2652 -       return (ahd_inb_scbram(ahd, offset)
2653 -             | (ahd_inb_scbram(ahd, offset+1) << 8)
2654 -             | (ahd_inb_scbram(ahd, offset+2) << 16)
2655 -             | (ahd_inb_scbram(ahd, offset+3) << 24));
2656 +       return (ahd_inw_scbram(ahd, offset)
2657 +             | (ahd_inw_scbram(ahd, offset+2) << 16));
2658 +}
2659 +
2660 +static __inline uint64_t
2661 +ahd_inq_scbram(struct ahd_softc *ahd, u_int offset)
2662 +{
2663 +       return (ahd_inl_scbram(ahd, offset)
2664 +             | ((uint64_t)ahd_inl_scbram(ahd, offset+4)) << 32);
2665  }
2666  
2667  static __inline struct scb *
2668 @@ -720,7 +736,8 @@
2669  static __inline void
2670  ahd_swap_with_next_hscb(struct ahd_softc *ahd, struct scb *scb)
2671  {
2672 -       struct hardware_scb *q_hscb;
2673 +       struct   hardware_scb *q_hscb;
2674 +       struct   map_node *q_hscb_map;
2675         uint32_t saved_hscb_busaddr;
2676  
2677         /*
2678 @@ -736,6 +753,7 @@
2679          * locate the correct SCB by SCB_TAG.
2680          */
2681         q_hscb = ahd->next_queued_hscb;
2682 +       q_hscb_map = ahd->next_queued_hscb_map;
2683         saved_hscb_busaddr = q_hscb->hscb_busaddr;
2684         memcpy(q_hscb, scb->hscb, sizeof(*scb->hscb));
2685         q_hscb->hscb_busaddr = saved_hscb_busaddr;
2686 @@ -743,7 +761,9 @@
2687  
2688         /* Now swap HSCB pointers. */
2689         ahd->next_queued_hscb = scb->hscb;
2690 +       ahd->next_queued_hscb_map = scb->hscb_map;
2691         scb->hscb = q_hscb;
2692 +       scb->hscb_map = q_hscb_map;
2693  
2694         /* Now define the mapping from tag to SCB in the scbindex */
2695         ahd->scb_data.scbindex[SCB_GET_TAG(scb)] = scb;
2696 @@ -783,13 +803,13 @@
2697         if ((ahd_debug & AHD_SHOW_QUEUE) != 0) {
2698                 uint64_t host_dataptr;
2699  
2700 -               host_dataptr = ahd_le64toh(scb->hscb->dataptr);
2701 +               host_dataptr = aic_le64toh(scb->hscb->dataptr);
2702                 printf("%s: Queueing SCB 0x%x bus addr 0x%x - 0x%x%x/0x%x\n",
2703                        ahd_name(ahd),
2704 -                      SCB_GET_TAG(scb), ahd_le32toh(scb->hscb->hscb_busaddr),
2705 +                      SCB_GET_TAG(scb), aic_le32toh(scb->hscb->hscb_busaddr),
2706                        (u_int)((host_dataptr >> 32) & 0xFFFFFFFF),
2707                        (u_int)(host_dataptr & 0xFFFFFFFF),
2708 -                      ahd_le32toh(scb->hscb->datacnt));
2709 +                      aic_le32toh(scb->hscb->datacnt));
2710         }
2711  #endif
2712         /* Tell the adapter about the newly queued SCB */
2713 @@ -817,8 +837,8 @@
2714  static __inline void
2715  ahd_sync_qoutfifo(struct ahd_softc *ahd, int op)
2716  {
2717 -       ahd_dmamap_sync(ahd, ahd->shared_data_dmat, ahd->shared_data_dmamap,
2718 -                       /*offset*/0, /*len*/AHC_SCB_MAX * sizeof(uint16_t), op);
2719 +       aic_dmamap_sync(ahd, ahd->shared_data_dmat, ahd->shared_data_map.dmamap,
2720 +                       /*offset*/0, /*len*/AHD_SCB_MAX * sizeof(uint16_t), op);
2721  }
2722  
2723  static __inline void
2724 @@ -826,8 +846,8 @@
2725  {
2726  #ifdef AHD_TARGET_MODE
2727         if ((ahd->flags & AHD_TARGETROLE) != 0) {
2728 -               ahd_dmamap_sync(ahd, ahd->shared_data_dmat,
2729 -                               ahd->shared_data_dmamap,
2730 +               aic_dmamap_sync(ahd, ahd->shared_data_dmat,
2731 +                               ahd->shared_data_map.dmamap,
2732                                 ahd_targetcmd_offset(ahd, 0),
2733                                 sizeof(struct target_cmd) * AHD_TMODE_CMDS,
2734                                 op);
2735 @@ -847,7 +867,7 @@
2736         u_int retval;
2737  
2738         retval = 0;
2739 -       ahd_dmamap_sync(ahd, ahd->shared_data_dmat, ahd->shared_data_dmamap,
2740 +       aic_dmamap_sync(ahd, ahd->shared_data_dmat, ahd->shared_data_map.dmamap,
2741                         /*offset*/ahd->qoutfifonext, /*len*/2,
2742                         BUS_DMASYNC_POSTREAD);
2743         if ((ahd->qoutfifo[ahd->qoutfifonext]
2744 @@ -856,8 +876,8 @@
2745  #ifdef AHD_TARGET_MODE
2746         if ((ahd->flags & AHD_TARGETROLE) != 0
2747          && (ahd->flags & AHD_TQINFIFO_BLOCKED) == 0) {
2748 -               ahd_dmamap_sync(ahd, ahd->shared_data_dmat,
2749 -                               ahd->shared_data_dmamap,
2750 +               aic_dmamap_sync(ahd, ahd->shared_data_dmat,
2751 +                               ahd->shared_data_map.dmamap,
2752                                 ahd_targetcmd_offset(ahd, ahd->tqinfifofnext),
2753                                 /*len*/sizeof(struct target_cmd),
2754                                 BUS_DMASYNC_POSTREAD);
2755 diff -urN linux-2.4.24.org/drivers/scsi/aic7xxx/aic79xx_osm.c linux-2.4.24/drivers/scsi/aic7xxx/aic79xx_osm.c
2756 --- linux-2.4.24.org/drivers/scsi/aic7xxx/aic79xx_osm.c 2004-01-08 11:57:43.057995862 +0100
2757 +++ linux-2.4.24/drivers/scsi/aic7xxx/aic79xx_osm.c     2003-12-22 22:46:59.000000000 +0100
2758 @@ -1,7 +1,7 @@
2759  /*
2760   * Adaptec AIC79xx device driver for Linux.
2761   *
2762 - * $Id$
2763 + * $Id$
2764   *
2765   * --------------------------------------------------------------------------
2766   * Copyright (c) 1994-2000 Justin T. Gibbs.
2767 @@ -62,6 +62,16 @@
2768  
2769  #include <linux/mm.h>          /* For fetching system memory size */
2770  
2771 +/************************* Magic SysReq Support *******************************/
2772 +static struct aic_sysrq_key_op ahd_sysrq_op =
2773 +{
2774 +       aic_sysrq_handler,
2775 +       "aic79xxstatedump",
2776 +       "Dump aic79xx controller information to Console"
2777 +};
2778 +
2779 +static int ahd_sysrq_key;
2780 +
2781  /*
2782   * Lock protecting manipulation of the ahd softc list.
2783   */
2784 @@ -425,7 +435,7 @@
2785  static char dummy_buffer[60] = "Please don't trounce on me insmod!!\n";
2786  
2787  MODULE_AUTHOR("Maintainer: Justin T. Gibbs <gibbs@scsiguy.com>");
2788 -MODULE_DESCRIPTION("Adaptec Aic77XX/78XX SCSI Host Bus Adapter driver");
2789 +MODULE_DESCRIPTION("Adaptec Aic790X U320 SCSI Host Bus Adapter driver");
2790  #ifdef MODULE_LICENSE
2791  MODULE_LICENSE("Dual BSD/GPL");
2792  #endif
2793 @@ -466,7 +476,7 @@
2794  #endif
2795  
2796  static void ahd_linux_handle_scsi_status(struct ahd_softc *,
2797 -                                        struct ahd_linux_device *,
2798 +                                        struct aic_linux_device *,
2799                                          struct scb *);
2800  static void ahd_linux_queue_cmd_complete(struct ahd_softc *ahd,
2801                                          Scsi_Cmnd *cmd);
2802 @@ -478,21 +488,20 @@
2803  static void ahd_linux_size_nseg(void);
2804  static void ahd_linux_thread_run_complete_queue(struct ahd_softc *ahd);
2805  static void ahd_linux_start_dv(struct ahd_softc *ahd);
2806 -static void ahd_linux_dv_timeout(struct scsi_cmnd *cmd);
2807  static int  ahd_linux_dv_thread(void *data);
2808  static void ahd_linux_kill_dv_thread(struct ahd_softc *ahd);
2809  static void ahd_linux_dv_target(struct ahd_softc *ahd, u_int target);
2810  static void ahd_linux_dv_transition(struct ahd_softc *ahd,
2811                                     struct scsi_cmnd *cmd,
2812                                     struct ahd_devinfo *devinfo,
2813 -                                   struct ahd_linux_target *targ);
2814 +                                   struct aic_linux_target *targ);
2815  static void ahd_linux_dv_fill_cmd(struct ahd_softc *ahd,
2816                                   struct scsi_cmnd *cmd,
2817                                   struct ahd_devinfo *devinfo);
2818  static void ahd_linux_dv_inq(struct ahd_softc *ahd,
2819                              struct scsi_cmnd *cmd,
2820                              struct ahd_devinfo *devinfo,
2821 -                            struct ahd_linux_target *targ,
2822 +                            struct aic_linux_target *targ,
2823                              u_int request_length);
2824  static void ahd_linux_dv_tur(struct ahd_softc *ahd,
2825                              struct scsi_cmnd *cmd,
2826 @@ -500,19 +509,19 @@
2827  static void ahd_linux_dv_rebd(struct ahd_softc *ahd,
2828                               struct scsi_cmnd *cmd,
2829                               struct ahd_devinfo *devinfo,
2830 -                             struct ahd_linux_target *targ);
2831 +                             struct aic_linux_target *targ);
2832  static void ahd_linux_dv_web(struct ahd_softc *ahd,
2833                              struct scsi_cmnd *cmd,
2834                              struct ahd_devinfo *devinfo,
2835 -                            struct ahd_linux_target *targ);
2836 +                            struct aic_linux_target *targ);
2837  static void ahd_linux_dv_reb(struct ahd_softc *ahd,
2838                              struct scsi_cmnd *cmd,
2839                              struct ahd_devinfo *devinfo,
2840 -                            struct ahd_linux_target *targ);
2841 +                            struct aic_linux_target *targ);
2842  static void ahd_linux_dv_su(struct ahd_softc *ahd,
2843                             struct scsi_cmnd *cmd,
2844                             struct ahd_devinfo *devinfo,
2845 -                           struct ahd_linux_target *targ);
2846 +                           struct aic_linux_target *targ);
2847  static __inline int
2848            ahd_linux_dv_fallback(struct ahd_softc *ahd,
2849                                  struct ahd_devinfo *devinfo);
2850 @@ -520,103 +529,57 @@
2851                               struct ahd_devinfo *devinfo);
2852  static __inline int ahd_linux_dv_fallback(struct ahd_softc *ahd,
2853                                           struct ahd_devinfo *devinfo);
2854 -static void ahd_linux_dv_complete(Scsi_Cmnd *cmd);
2855 -static void ahd_linux_generate_dv_pattern(struct ahd_linux_target *targ);
2856 +static void ahd_linux_generate_dv_pattern(struct aic_linux_target *targ);
2857  static u_int ahd_linux_user_tagdepth(struct ahd_softc *ahd,
2858                                      struct ahd_devinfo *devinfo);
2859  static u_int ahd_linux_user_dv_setting(struct ahd_softc *ahd);
2860  static void ahd_linux_setup_user_rd_strm_settings(struct ahd_softc *ahd);
2861 -static void ahd_linux_device_queue_depth(struct ahd_softc *ahd,
2862 -                                        struct ahd_linux_device *dev);
2863 -static struct ahd_linux_target*        ahd_linux_alloc_target(struct ahd_softc*,
2864 +static void aic_linux_device_queue_depth(struct ahd_softc *ahd,
2865 +                                        struct aic_linux_device *dev);
2866 +static struct aic_linux_target*        ahd_linux_alloc_target(struct ahd_softc*,
2867                                                        u_int, u_int);
2868  static void                    ahd_linux_free_target(struct ahd_softc*,
2869 -                                                     struct ahd_linux_target*);
2870 -static struct ahd_linux_device*        ahd_linux_alloc_device(struct ahd_softc*,
2871 -                                                      struct ahd_linux_target*,
2872 +                                                     struct aic_linux_target*);
2873 +static struct aic_linux_device*        ahd_linux_alloc_device(struct ahd_softc*,
2874 +                                                      struct aic_linux_target*,
2875                                                        u_int);
2876  static void                    ahd_linux_free_device(struct ahd_softc*,
2877 -                                                     struct ahd_linux_device*);
2878 -static void ahd_linux_run_device_queue(struct ahd_softc*,
2879 -                                      struct ahd_linux_device*);
2880 +                                                     struct aic_linux_device*);
2881  static void ahd_linux_setup_tag_info_global(char *p);
2882  static aic_option_callback_t ahd_linux_setup_tag_info;
2883  static aic_option_callback_t ahd_linux_setup_rd_strm_info;
2884  static aic_option_callback_t ahd_linux_setup_dv;
2885  static aic_option_callback_t ahd_linux_setup_iocell_info;
2886  static int ahd_linux_next_unit(void);
2887 -static void ahd_runq_tasklet(unsigned long data);
2888  static int aic79xx_setup(char *c);
2889  
2890  /****************************** Inlines ***************************************/
2891  static __inline void ahd_schedule_completeq(struct ahd_softc *ahd);
2892 -static __inline void ahd_schedule_runq(struct ahd_softc *ahd);
2893 -static __inline void ahd_setup_runq_tasklet(struct ahd_softc *ahd);
2894 -static __inline void ahd_teardown_runq_tasklet(struct ahd_softc *ahd);
2895 -static __inline struct ahd_linux_device*
2896 +static __inline struct aic_linux_device*
2897                      ahd_linux_get_device(struct ahd_softc *ahd, u_int channel,
2898                                           u_int target, u_int lun, int alloc);
2899 -static struct ahd_cmd *ahd_linux_run_complete_queue(struct ahd_softc *ahd);
2900 -static __inline void ahd_linux_check_device_queue(struct ahd_softc *ahd,
2901 -                                                 struct ahd_linux_device *dev);
2902 -static __inline struct ahd_linux_device *
2903 -                    ahd_linux_next_device_to_run(struct ahd_softc *ahd);
2904 -static __inline void ahd_linux_run_device_queues(struct ahd_softc *ahd);
2905  static __inline void ahd_linux_unmap_scb(struct ahd_softc*, struct scb*);
2906 -
2907 -static __inline int ahd_linux_map_seg(struct ahd_softc *ahd, struct scb *scb,
2908 -                                     struct ahd_dma_seg *sg,
2909 -                                     bus_addr_t addr, bus_size_t len);
2910 +static __inline struct ahd_dma_seg*
2911 +                    ahd_linux_sg_setup(struct ahd_softc *ahd, struct scb *scb,
2912 +                                       struct ahd_dma_seg *sg, bus_addr_t addr,
2913 +                                       bus_size_t len, int last_seg);
2914  
2915  static __inline void
2916  ahd_schedule_completeq(struct ahd_softc *ahd)
2917  {
2918 -       if ((ahd->platform_data->flags & AHD_RUN_CMPLT_Q_TIMER) == 0) {
2919 -               ahd->platform_data->flags |= AHD_RUN_CMPLT_Q_TIMER;
2920 +       if ((ahd->platform_data->flags & AIC_RUN_CMPLT_Q_TIMER) == 0) {
2921 +               ahd->platform_data->flags |= AIC_RUN_CMPLT_Q_TIMER;
2922                 ahd->platform_data->completeq_timer.expires = jiffies;
2923                 add_timer(&ahd->platform_data->completeq_timer);
2924         }
2925  }
2926  
2927 -/*
2928 - * Must be called with our lock held.
2929 - */
2930 -static __inline void
2931 -ahd_schedule_runq(struct ahd_softc *ahd)
2932 -{
2933 -#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,0)
2934 -       tasklet_schedule(&ahd->platform_data->runq_tasklet);
2935 -#else
2936 -       /*
2937 -        * Tasklets are not available, so run inline.
2938 -        */
2939 -       ahd_runq_tasklet((unsigned long)ahd);
2940 -#endif
2941 -}
2942 -
2943 -static __inline
2944 -void ahd_setup_runq_tasklet(struct ahd_softc *ahd)
2945 -{
2946 -#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,0)
2947 -       tasklet_init(&ahd->platform_data->runq_tasklet, ahd_runq_tasklet,
2948 -                    (unsigned long)ahd);
2949 -#endif
2950 -}
2951 -
2952 -static __inline void
2953 -ahd_teardown_runq_tasklet(struct ahd_softc *ahd)
2954 -{
2955 -#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,0)
2956 -       tasklet_kill(&ahd->platform_data->runq_tasklet);
2957 -#endif
2958 -}
2959 -
2960 -static __inline struct ahd_linux_device*
2961 +static __inline struct aic_linux_device*
2962  ahd_linux_get_device(struct ahd_softc *ahd, u_int channel, u_int target,
2963                      u_int lun, int alloc)
2964  {
2965 -       struct ahd_linux_target *targ;
2966 -       struct ahd_linux_device *dev;
2967 +       struct aic_linux_target *targ;
2968 +       struct aic_linux_device *dev;
2969         u_int target_offset;
2970  
2971         target_offset = target;
2972 @@ -638,10 +601,10 @@
2973  }
2974  
2975  #define AHD_LINUX_MAX_RETURNED_ERRORS 4
2976 -static struct ahd_cmd *
2977 +static struct aic_cmd *
2978  ahd_linux_run_complete_queue(struct ahd_softc *ahd)
2979  {      
2980 -       struct  ahd_cmd *acmd;
2981 +       struct  aic_cmd *acmd;
2982         u_long  done_flags;
2983         int     with_errors;
2984  
2985 @@ -666,7 +629,7 @@
2986                              acmd, acmd_links.tqe);
2987                 cmd = &acmd_scsi_cmd(acmd);
2988                 cmd->host_scribble = NULL;
2989 -               if (ahd_cmd_get_transaction_status(cmd) != DID_OK
2990 +               if (aic_cmd_get_transaction_status(cmd) != DID_OK
2991                  || (cmd->result & 0xFF) != SCSI_STATUS_OK)
2992                         with_errors++;
2993  
2994 @@ -677,46 +640,6 @@
2995  }
2996  
2997  static __inline void
2998 -ahd_linux_check_device_queue(struct ahd_softc *ahd,
2999 -                            struct ahd_linux_device *dev)
3000 -{
3001 -       if ((dev->flags & AHD_DEV_FREEZE_TIL_EMPTY) != 0
3002 -        && dev->active == 0) {
3003 -               dev->flags &= ~AHD_DEV_FREEZE_TIL_EMPTY;
3004 -               dev->qfrozen--;
3005 -       }
3006 -
3007 -       if (TAILQ_FIRST(&dev->busyq) == NULL
3008 -        || dev->openings == 0 || dev->qfrozen != 0)
3009 -               return;
3010 -
3011 -       ahd_linux_run_device_queue(ahd, dev);
3012 -}
3013 -
3014 -static __inline struct ahd_linux_device *
3015 -ahd_linux_next_device_to_run(struct ahd_softc *ahd)
3016 -{
3017 -       
3018 -       if ((ahd->flags & AHD_RESOURCE_SHORTAGE) != 0
3019 -        || (ahd->platform_data->qfrozen != 0
3020 -         && AHD_DV_SIMQ_FROZEN(ahd) == 0))
3021 -               return (NULL);
3022 -       return (TAILQ_FIRST(&ahd->platform_data->device_runq));
3023 -}
3024 -
3025 -static __inline void
3026 -ahd_linux_run_device_queues(struct ahd_softc *ahd)
3027 -{
3028 -       struct ahd_linux_device *dev;
3029 -
3030 -       while ((dev = ahd_linux_next_device_to_run(ahd)) != NULL) {
3031 -               TAILQ_REMOVE(&ahd->platform_data->device_runq, dev, links);
3032 -               dev->flags &= ~AHD_DEV_ON_RUN_LIST;
3033 -               ahd_linux_check_device_queue(ahd, dev);
3034 -       }
3035 -}
3036 -
3037 -static __inline void
3038  ahd_linux_unmap_scb(struct ahd_softc *ahd, struct scb *scb)
3039  {
3040         Scsi_Cmnd *cmd;
3041 @@ -729,34 +652,22 @@
3042                 struct scatterlist *sg;
3043  
3044                 sg = (struct scatterlist *)cmd->request_buffer;
3045 -               pci_unmap_sg(ahd->dev_softc, sg, cmd->use_sg, direction);
3046 +               aic_unmap_sg(ahd, sg, cmd->use_sg, direction);
3047         } else if (cmd->request_bufflen != 0) {
3048 -               pci_unmap_single(ahd->dev_softc,
3049 +               aic_unmap_single(ahd,
3050                                  scb->platform_data->buf_busaddr,
3051                                  cmd->request_bufflen, direction);
3052         }
3053  }
3054  
3055 -static __inline int
3056 -ahd_linux_map_seg(struct ahd_softc *ahd, struct scb *scb,
3057 -                 struct ahd_dma_seg *sg, bus_addr_t addr, bus_size_t len)
3058 +static __inline struct ahd_dma_seg*
3059 +ahd_linux_sg_setup(struct ahd_softc *ahd, struct scb *scb,
3060 +                  struct ahd_dma_seg *sg, bus_addr_t addr,
3061 +                  bus_size_t len, int last_seg)
3062  {
3063 -       int      consumed;
3064 -
3065 -       if ((scb->sg_count + 1) > AHD_NSEG)
3066 -               panic("Too few segs for dma mapping.  "
3067 -                     "Increase AHD_NSEG\n");
3068 -
3069 -       consumed = 1;
3070 -       sg->addr = ahd_htole32(addr & 0xFFFFFFFF);
3071 +       sg = ahd_sg_setup(ahd, scb, sg, addr, len, last_seg);
3072         scb->platform_data->xfer_len += len;
3073 -
3074 -       if (sizeof(bus_addr_t) > 4
3075 -        && (ahd->flags & AHD_39BIT_ADDRESSING) != 0)
3076 -               len |= (addr >> 8) & AHD_SG_HIGH_ADDR_MASK;
3077 -
3078 -       sg->len = ahd_htole32(len);
3079 -       return (consumed);
3080 +       return (sg);
3081  }
3082  
3083  /******************************** Macros **************************************/
3084 @@ -797,7 +708,7 @@
3085   * number of segments needed for the current transfer.  Since the code that
3086   * sizes the SCSI malloc pool does not take into consideration fragmentation
3087   * of the pool, executing transactions numbering just a fraction of our
3088 - * concurrent transaction limit with SG list lengths aproaching AHC_NSEG will
3089 + * concurrent transaction limit with SG list lengths aproaching AHD_NSEG will
3090   * quickly depleat the SCSI malloc pool of usable space.  Unfortunately, the
3091   * mid-layer does not properly handle this scsi malloc failures for the S/G
3092   * array and the result can be a lockup of the I/O subsystem.  We try to size
3093 @@ -848,6 +759,165 @@
3094  #endif
3095  }
3096  
3097 +/************************** Error Recovery ************************************/
3098 +static int ahd_linux_recovery_thread(void *arg);
3099 +
3100 +static int
3101 +ahd_linux_recovery_thread(void *arg)
3102 +{
3103 +       struct ahd_softc *ahd;
3104 +       u_long s;
3105 +
3106 +       ahd = (struct ahd_softc *)arg;
3107 +
3108 +       /*
3109 +        * Complete thread creation.
3110 +        */
3111 +       lock_kernel();
3112 +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,5,60)
3113 +       /*
3114 +        * Don't care about any signals.
3115 +        */
3116 +       siginitsetinv(&current->blocked, 0);
3117 +
3118 +       daemonize();
3119 +       sprintf(current->comm, "ahd_recovery_%d", ahd->unit);
3120 +#else
3121 +       daemonize("ahd_recovery_%d", ahd->unit);
3122 +#endif
3123 +       unlock_kernel();
3124 +
3125 +       while (1) {
3126 +
3127 +               /*
3128 +                * Use down_interruptible() rather than down() to
3129 +                * avoid inclusion in the load average.
3130 +                */
3131 +               down_interruptible(&ahd->platform_data->recovery_sem);
3132 +
3133 +               ahd_lock(ahd, &s);
3134 +               if ((ahd->flags & AHD_SHUTDOWN_RECOVERY) != 0) {
3135 +                       ahd_unlock(ahd, &s);
3136 +                       break;
3137 +               }
3138 +
3139 +               /*
3140 +                * Don't bother the recovery handler if the
3141 +                * list has been cleared by a previous run
3142 +                * of the handler.  This can happen when
3143 +                * several SCBs timeout before our handler
3144 +                * can run causing our semaphore to be up'ed
3145 +                * repeatedly.  The extra calls need to be
3146 +                * avoided so that the recovery handler doesn't
3147 +                * confuse this case with timeouts occuring
3148 +                * due to interrupts failing to function.
3149 +                */
3150 +               if (LIST_EMPTY(&ahd->timedout_scbs) != 0) {
3151 +                       ahd_unlock(ahd, &s);
3152 +                       continue;
3153 +               }
3154 +
3155 +               ahd_unlock(ahd, &s);
3156 +               ahd_recover_commands(ahd);
3157 +
3158 +               /*
3159 +                * Process any pent up completions.
3160 +                */
3161 +               ahd_lock(ahd, &s);
3162 +               aic_schedule_runq(ahd);
3163 +               ahd_linux_run_complete_queue(ahd);
3164 +               ahd_unlock(ahd, &s);
3165 +       }
3166 +       up(&ahd->platform_data->recovery_ending_sem);
3167 +       return(0);
3168 +}
3169 +
3170 +int
3171 +ahd_spawn_recovery_thread(struct ahd_softc *ahd)
3172 +{
3173 +       ahd->platform_data->recovery_pid =
3174 +           kernel_thread(ahd_linux_recovery_thread, ahd, 0);
3175 +       
3176 +       if (ahd->platform_data->recovery_pid < 0)
3177 +               return (-ahd->platform_data->recovery_pid);
3178 +
3179 +       return (0);
3180 +}
3181 +
3182 +void
3183 +ahd_terminate_recovery_thread(struct ahd_softc *ahd)
3184 +{
3185 +       u_long s;
3186 +
3187 +       ahd_lock(ahd, &s);
3188 +       if (ahd->platform_data->recovery_pid != 0) {
3189 +               ahd->flags |= AHD_SHUTDOWN_RECOVERY;
3190 +               ahd_unlock(ahd, &s);
3191 +               up(&ahd->platform_data->recovery_sem);
3192 +
3193 +               /*
3194 +                * Use the recovery_ending_sem as an indicator that
3195 +                * the dv thread is exiting.  Note that the dv
3196 +                * thread must still return after performing
3197 +                * the up on our semaphore before it has
3198 +                * completely exited this module.  Unfortunately,
3199 +                * there seems to be no easy way to wait for the
3200 +                * exit of a thread for which you are not the
3201 +                * parent (dv threads are parented by init).
3202 +                * Cross your fingers...
3203 +                */
3204 +               down(&ahd->platform_data->recovery_ending_sem);
3205 +
3206 +               /*
3207 +                * Mark the recovery thread as already dead.  This
3208 +                * avoids attempting to kill it a second time.
3209 +                * This is necessary because we must kill the
3210 +                * our threads before calling ahd_free() in the
3211 +                * module shutdown case to avoid bogus locking
3212 +                * in the SCSI mid-layer, but when ahd_free() is
3213 +                * called without killing the DV thread in the
3214 +                * instance detach case, so ahd_platform_free()
3215 +                * calls us again to verify that the DV thread
3216 +                * is dead.
3217 +                */
3218 +               ahd->platform_data->recovery_pid = 0;
3219 +       } else {
3220 +               ahd_unlock(ahd, &s);
3221 +       }
3222 +}
3223 +
3224 +void
3225 +ahd_set_recoveryscb(struct ahd_softc *ahd, struct scb *scb)
3226 +{
3227 +       if ((scb->flags & SCB_RECOVERY_SCB) == 0) {
3228 +               struct scb *list_scb;
3229 +
3230 +               scb->flags |= SCB_RECOVERY_SCB;
3231 +
3232 +               /*
3233 +                * Take all queued, but not sent SCBs out of the equation.
3234 +                * Also ensure that no new commands are queued to us while we
3235 +                * try to fix this problem.
3236 +                */
3237 +               if ((scb->platform_data->flags & AIC_RELEASE_SIMQ) == 0) {
3238 +                       aic_freeze_simq(ahd);
3239 +                       scb->platform_data->flags |= AIC_RELEASE_SIMQ;
3240 +               }
3241 +
3242 +               /*
3243 +                * Go through all of our pending SCBs and remove
3244 +                * any scheduled timeouts for them.  We will reschedule
3245 +                * them after we've successfully fixed this problem.
3246 +                */
3247 +               LIST_FOREACH(list_scb, &ahd->pending_scbs, pending_links) {
3248 +
3249 +                       scsi_delete_timer(list_scb->io_ctx);
3250 +                       list_scb->platform_data->flags &= ~AIC_TIMEOUT_ACTIVE;
3251 +               }
3252 +       }
3253 +}
3254 +
3255 +/********************** Host Template Entry Points ****************************/
3256  /*
3257   * Try to detect an Adaptec 79XX controller.
3258   */
3259 @@ -870,7 +940,7 @@
3260          * that some of our hacks^H^H^H^H^Hassumptions aren't
3261          * violated.
3262          */
3263 -       if (offsetof(struct ahd_cmd_internal, end)
3264 +       if (offsetof(struct aic_cmd_internal, end)
3265           > offsetof(struct scsi_cmnd, host_scribble)) {
3266                 printf("ahd_linux_detect: SCSI data structures changed.\n");
3267                 printf("ahd_linux_detect: Unable to attach\n");
3268 @@ -938,7 +1008,6 @@
3269         struct ahd_softc *ahd;
3270         u_long l;
3271  
3272 -       ahd_list_lock(&l);
3273         if (host != NULL) {
3274  
3275                 /*
3276 @@ -946,17 +1015,20 @@
3277                  * the free directly, but check our
3278                  * list for extra sanity.
3279                  */
3280 +               ahd_list_lock(&l);
3281                 ahd = ahd_find_softc(*(struct ahd_softc **)host->hostdata);
3282                 if (ahd != NULL) {
3283                         u_long s;
3284  
3285 +                       TAILQ_REMOVE(&ahd_tailq, ahd, links);
3286 +                       ahd_list_unlock(&l);
3287                         ahd_lock(ahd, &s);
3288                         ahd_intr_enable(ahd, FALSE);
3289                         ahd_unlock(ahd, &s);
3290                         ahd_free(ahd);
3291 -               }
3292 +               } else
3293 +                       ahd_list_unlock(&l);
3294         }
3295 -       ahd_list_unlock(&l);
3296         return (0);
3297  }
3298  #endif
3299 @@ -996,7 +1068,7 @@
3300  ahd_linux_queue(Scsi_Cmnd * cmd, void (*scsi_done) (Scsi_Cmnd *))
3301  {
3302         struct   ahd_softc *ahd;
3303 -       struct   ahd_linux_device *dev;
3304 +       struct   aic_linux_device *dev;
3305         u_long   flags;
3306  
3307         ahd = *(struct ahd_softc **)cmd->device->host->hostdata;
3308 @@ -1015,9 +1087,9 @@
3309          * perform DV.
3310          */
3311         if (ahd->platform_data->qfrozen != 0
3312 -        && AHD_DV_CMD(cmd) == 0) {
3313 +        && AIC_DV_CMD(cmd) == 0) {
3314  
3315 -               ahd_cmd_set_transaction_status(cmd, CAM_REQUEUE_REQ);
3316 +               aic_cmd_set_transaction_status(cmd, CAM_REQUEUE_REQ);
3317                 ahd_linux_queue_cmd_complete(ahd, cmd);
3318                 ahd_schedule_completeq(ahd);
3319                 ahd_midlayer_entrypoint_unlock(ahd, &flags);
3320 @@ -1027,7 +1099,8 @@
3321                                    cmd->device->id, cmd->device->lun,
3322                                    /*alloc*/TRUE);
3323         if (dev == NULL) {
3324 -               ahd_cmd_set_transaction_status(cmd, CAM_RESRC_UNAVAIL);
3325 +
3326 +               aic_cmd_set_transaction_status(cmd, CAM_RESRC_UNAVAIL);
3327                 ahd_linux_queue_cmd_complete(ahd, cmd);
3328                 ahd_schedule_completeq(ahd);
3329                 ahd_midlayer_entrypoint_unlock(ahd, &flags);
3330 @@ -1035,14 +1108,30 @@
3331                        ahd_name(ahd));
3332                 return (0);
3333         }
3334 -       if (cmd->cmd_len > MAX_CDB_LEN)
3335 -               return (-EINVAL);
3336 +
3337 +       if (cmd->cmd_len > MAX_CDB_LEN) {
3338 +
3339 +               aic_cmd_set_transaction_status(cmd, CAM_REQ_INVALID);
3340 +               ahd_linux_queue_cmd_complete(ahd, cmd);
3341 +               ahd_schedule_completeq(ahd);
3342 +               ahd_midlayer_entrypoint_unlock(ahd, &flags);
3343 +               printf("%s: aic79xx_linux_queue -"
3344 +                      "CDB length of %d exceeds max!\n",
3345 +                      ahd_name(ahd), cmd->cmd_len);
3346 +               return (0);
3347 +       }
3348 +
3349 +       /*
3350 +        * We perform our own timeout handling.
3351 +        */
3352 +       scsi_delete_timer(cmd);
3353 +
3354         cmd->result = CAM_REQ_INPROG << 16;
3355 -       TAILQ_INSERT_TAIL(&dev->busyq, (struct ahd_cmd *)cmd, acmd_links.tqe);
3356 -       if ((dev->flags & AHD_DEV_ON_RUN_LIST) == 0) {
3357 +       TAILQ_INSERT_TAIL(&dev->busyq, (struct aic_cmd *)cmd, acmd_links.tqe);
3358 +       if ((dev->flags & AIC_DEV_ON_RUN_LIST) == 0) {
3359                 TAILQ_INSERT_TAIL(&ahd->platform_data->device_runq, dev, links);
3360 -               dev->flags |= AHD_DEV_ON_RUN_LIST;
3361 -               ahd_linux_run_device_queues(ahd);
3362 +               dev->flags |= AIC_DEV_ON_RUN_LIST;
3363 +               aic_linux_run_device_queues(ahd);
3364         }
3365         ahd_midlayer_entrypoint_unlock(ahd, &flags);
3366         return (0);
3367 @@ -1064,7 +1153,7 @@
3368  ahd_linux_slave_configure(Scsi_Device *device)
3369  {
3370         struct  ahd_softc *ahd;
3371 -       struct  ahd_linux_device *dev;
3372 +       struct  aic_linux_device *dev;
3373         u_long  flags;
3374  
3375         ahd = *((struct ahd_softc **)device->host->hostdata);
3376 @@ -1080,10 +1169,10 @@
3377                                    device->id, device->lun,
3378                                    /*alloc*/TRUE);
3379         if (dev != NULL) {
3380 -               dev->flags &= ~AHD_DEV_UNCONFIGURED;
3381 -               dev->flags |= AHD_DEV_SLAVE_CONFIGURED;
3382 +               dev->flags &= ~AIC_DEV_UNCONFIGURED;
3383 +               dev->flags |= AIC_DEV_SLAVE_CONFIGURED;
3384                 dev->scsi_device = device;
3385 -               ahd_linux_device_queue_depth(ahd, dev);
3386 +               aic_linux_device_queue_depth(ahd, dev);
3387         }
3388         ahd_midlayer_entrypoint_unlock(ahd, &flags);
3389         return (0);
3390 @@ -1093,7 +1182,7 @@
3391  ahd_linux_slave_destroy(Scsi_Device *device)
3392  {
3393         struct  ahd_softc *ahd;
3394 -       struct  ahd_linux_device *dev;
3395 +       struct  aic_linux_device *dev;
3396         u_long  flags;
3397  
3398         ahd = *((struct ahd_softc **)device->host->hostdata);
3399 @@ -1112,11 +1201,10 @@
3400          * the refcounting process.
3401          */
3402         if (dev != NULL
3403 -        && (dev->flags & AHD_DEV_SLAVE_CONFIGURED) != 0) {
3404 -               dev->flags |= AHD_DEV_UNCONFIGURED;
3405 +        && (dev->flags & AIC_DEV_SLAVE_CONFIGURED) != 0) {
3406 +               dev->flags |= AIC_DEV_UNCONFIGURED;
3407                 if (TAILQ_EMPTY(&dev->busyq)
3408 -                && dev->active == 0
3409 -                && (dev->flags & AHD_DEV_TIMER_ACTIVE) == 0)
3410 +                && dev->active == 0)
3411                         ahd_linux_free_device(ahd, dev);
3412         }
3413         ahd_midlayer_entrypoint_unlock(ahd, &flags);
3414 @@ -1156,7 +1244,7 @@
3415                         continue;
3416  
3417                 if (device->host == host) {
3418 -                       struct   ahd_linux_device *dev;
3419 +                       struct   aic_linux_device *dev;
3420  
3421                         /*
3422                          * Since Linux has attached to the device, configure
3423 @@ -1167,13 +1255,13 @@
3424                                                    device->id, device->lun,
3425                                                    /*alloc*/TRUE);
3426                         if (dev != NULL) {
3427 -                               dev->flags &= ~AHD_DEV_UNCONFIGURED;
3428 +                               dev->flags &= ~AIC_DEV_UNCONFIGURED;
3429                                 dev->scsi_device = device;
3430 -                               ahd_linux_device_queue_depth(ahd, dev);
3431 +                               aic_linux_device_queue_depth(ahd, dev);
3432                                 device->queue_depth = dev->openings
3433                                                     + dev->active;
3434 -                               if ((dev->flags & (AHD_DEV_Q_BASIC
3435 -                                               | AHD_DEV_Q_TAGGED)) == 0) {
3436 +                               if ((dev->flags & (AIC_DEV_Q_BASIC
3437 +                                               | AIC_DEV_Q_TAGGED)) == 0) {
3438                                         /*
3439                                          * We allow the OS to queue 2 untagged
3440                                          * transactions to us at any time even
3441 @@ -1262,9 +1350,9 @@
3442  ahd_linux_abort(Scsi_Cmnd *cmd)
3443  {
3444         struct ahd_softc *ahd;
3445 -       struct ahd_cmd *acmd;
3446 -       struct ahd_cmd *list_acmd;
3447 -       struct ahd_linux_device *dev;
3448 +       struct aic_cmd *acmd;
3449 +       struct aic_cmd *list_acmd;
3450 +       struct aic_linux_device *dev;
3451         struct scb *pending_scb;
3452         u_long s;
3453         u_int  saved_scbptr;
3454 @@ -1282,7 +1370,7 @@
3455         paused = FALSE;
3456         wait = FALSE;
3457         ahd = *(struct ahd_softc **)cmd->device->host->hostdata;
3458 -       acmd = (struct ahd_cmd *)cmd;
3459 +       acmd = (struct aic_cmd *)cmd;
3460  
3461         printf("%s:%d:%d:%d: Attempting to abort cmd %p:",
3462                ahd_name(ahd), cmd->device->channel, cmd->device->id,
3463 @@ -1341,6 +1429,17 @@
3464                        cmd->device->lun);
3465                 TAILQ_REMOVE(&dev->busyq, list_acmd, acmd_links.tqe);
3466                 cmd->result = DID_ABORT << 16;
3467 +               /*
3468 +                * The completion handler believes that
3469 +                * commands without active timers running
3470 +                * have lost the race of completing before
3471 +                * their timer expires.  Since commands in
3472 +                * our busy queues do not have timers running,
3473 +                * appease the mid-layer by adding a timer
3474 +                * now.  This timer will be immediately
3475 +                * canceled by the midlayer.
3476 +                */
3477 +               scsi_add_timer(cmd, 60*HZ, aic_linux_midlayer_timeout);
3478                 ahd_linux_queue_cmd_complete(ahd, cmd);
3479                 retval = SUCCESS;
3480                 goto done;
3481 @@ -1516,7 +1615,7 @@
3482                 struct timer_list timer;
3483                 int ret;
3484  
3485 -               pending_scb->platform_data->flags |= AHD_SCB_UP_EH_SEM;
3486 +               pending_scb->platform_data->flags |= AIC_SCB_UP_EH_SEM;
3487                 spin_unlock_irq(&ahd->platform_data->spin_lock);
3488                 init_timer(&timer);
3489                 timer.data = (u_long)pending_scb;
3490 @@ -1533,7 +1632,7 @@
3491                 }
3492                 spin_lock_irq(&ahd->platform_data->spin_lock);
3493         }
3494 -       ahd_schedule_runq(ahd);
3495 +       aic_schedule_runq(ahd);
3496         ahd_linux_run_complete_queue(ahd);
3497         ahd_midlayer_entrypoint_unlock(ahd, &s);
3498         return (retval);
3499 @@ -1554,7 +1653,7 @@
3500  {
3501         struct  ahd_softc *ahd;
3502         struct  scsi_cmnd *recovery_cmd;
3503 -       struct  ahd_linux_device *dev;
3504 +       struct  aic_linux_device *dev;
3505         struct  ahd_initiator_tinfo *tinfo;
3506         struct  ahd_tmode_tstate *tstate;
3507         struct  scb *scb;
3508 @@ -1592,9 +1691,11 @@
3509         recovery_cmd->host_scribble = (char *)scb;
3510         scb->io_ctx = recovery_cmd;
3511         scb->platform_data->dev = dev;
3512 +       scb->platform_data->flags = 0;
3513         scb->sg_count = 0;
3514 -       ahd_set_residual(scb, 0);
3515 -       ahd_set_sense_residual(scb, 0);
3516 +       aic_set_residual(scb, 0);
3517 +       aic_set_sense_residual(scb, 0);
3518 +       scb->platform_data->xfer_len = 0;
3519         hscb = scb->hscb;
3520         hscb->control = 0;
3521         hscb->scsiid = BUILD_SCSIID(ahd, cmd);
3522 @@ -1613,7 +1714,7 @@
3523         LIST_INSERT_HEAD(&ahd->pending_scbs, scb, pending_links);
3524         ahd_queue_scb(ahd, scb);
3525  
3526 -       scb->platform_data->flags |= AHD_SCB_UP_EH_SEM;
3527 +       scb->platform_data->flags |= AIC_SCB_UP_EH_SEM;
3528         spin_unlock_irq(&ahd->platform_data->spin_lock);
3529         init_timer(&timer);
3530         timer.data = (u_long)scb;
3531 @@ -1629,7 +1730,7 @@
3532                 retval = FAILED;
3533         }
3534         spin_lock_irq(&ahd->platform_data->spin_lock);
3535 -       ahd_schedule_runq(ahd);
3536 +       aic_schedule_runq(ahd);
3537         ahd_linux_run_complete_queue(ahd);
3538         ahd_midlayer_entrypoint_unlock(ahd, &s);
3539         printf("%s: Device reset returning 0x%x\n", ahd_name(ahd), retval);
3540 @@ -1665,213 +1766,8 @@
3541         return (SUCCESS);
3542  }
3543  
3544 -Scsi_Host_Template aic79xx_driver_template = {
3545 -       .module                 = THIS_MODULE,
3546 -       .name                   = "aic79xx",
3547 -       .proc_info              = ahd_linux_proc_info,
3548 -       .info                   = ahd_linux_info,
3549 -       .queuecommand           = ahd_linux_queue,
3550 -       .eh_abort_handler       = ahd_linux_abort,
3551 -       .eh_device_reset_handler = ahd_linux_dev_reset,
3552 -       .eh_bus_reset_handler   = ahd_linux_bus_reset,
3553 -#if defined(__i386__)
3554 -       .bios_param             = ahd_linux_biosparam,
3555 -#endif
3556 -       .can_queue              = AHD_MAX_QUEUE,
3557 -       .this_id                = -1,
3558 -       .cmd_per_lun            = 2,
3559 -       .use_clustering         = ENABLE_CLUSTERING,
3560 -#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,7)
3561 -       /*
3562 -        * We can only map 16MB per-SG
3563 -        * so create a sector limit of
3564 -        * "16MB" in 2K sectors.
3565 -        */
3566 -       .max_sectors            = 8192,
3567 -#endif
3568 -#if defined CONFIG_HIGHIO || LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,0)
3569 -#if LINUX_VERSION_CODE < KERNEL_VERSION(2,4,10)
3570 -/* Assume RedHat Distribution with its different HIGHIO conventions. */
3571 -       .can_dma_32             = 1,
3572 -       .single_sg_okay         = 1,
3573 -#else
3574 -       .highmem_io             = 1,
3575 -#endif
3576 -#endif
3577 -#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,0)
3578 -       .slave_alloc            = ahd_linux_slave_alloc,
3579 -       .slave_configure        = ahd_linux_slave_configure,
3580 -       .slave_destroy          = ahd_linux_slave_destroy,
3581 -#else
3582 -       .detect                 = ahd_linux_detect,
3583 -       .release                = ahd_linux_release,
3584 -       .select_queue_depths    = ahd_linux_select_queue_depth,
3585 -       .use_new_eh_code        = 1,
3586 -#endif
3587 -};
3588 -
3589 -/**************************** Tasklet Handler *********************************/
3590 -
3591 -/*
3592 - * In 2.4.X and above, this routine is called from a tasklet,
3593 - * so we must re-acquire our lock prior to executing this code.
3594 - * In all prior kernels, ahd_schedule_runq() calls this routine
3595 - * directly and ahd_schedule_runq() is called with our lock held.
3596 - */
3597 -static void
3598 -ahd_runq_tasklet(unsigned long data)
3599 -{
3600 -       struct ahd_softc* ahd;
3601 -       struct ahd_linux_device *dev;
3602 -#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,0)
3603 -       u_long flags;
3604 -#endif
3605 -
3606 -       ahd = (struct ahd_softc *)data;
3607 -#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,0)
3608 -       ahd_lock(ahd, &flags);
3609 -#endif
3610 -       while ((dev = ahd_linux_next_device_to_run(ahd)) != NULL) {
3611 -       
3612 -               TAILQ_REMOVE(&ahd->platform_data->device_runq, dev, links);
3613 -               dev->flags &= ~AHD_DEV_ON_RUN_LIST;
3614 -               ahd_linux_check_device_queue(ahd, dev);
3615 -#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,0)
3616 -               /* Yeild to our interrupt handler */
3617 -               ahd_unlock(ahd, &flags);
3618 -               ahd_lock(ahd, &flags);
3619 -#endif
3620 -       }
3621 -#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,0)
3622 -       ahd_unlock(ahd, &flags);
3623 -#endif
3624 -}
3625 -
3626 -/******************************** Bus DMA *************************************/
3627 -int
3628 -ahd_dma_tag_create(struct ahd_softc *ahd, bus_dma_tag_t parent,
3629 -                  bus_size_t alignment, bus_size_t boundary,
3630 -                  bus_addr_t lowaddr, bus_addr_t highaddr,
3631 -                  bus_dma_filter_t *filter, void *filterarg,
3632 -                  bus_size_t maxsize, int nsegments,
3633 -                  bus_size_t maxsegsz, int flags, bus_dma_tag_t *ret_tag)
3634 -{
3635 -       bus_dma_tag_t dmat;
3636 -
3637 -       dmat = malloc(sizeof(*dmat), M_DEVBUF, M_NOWAIT);
3638 -       if (dmat == NULL)
3639 -               return (ENOMEM);
3640 -
3641 -       /*
3642 -        * Linux is very simplistic about DMA memory.  For now don't
3643 -        * maintain all specification information.  Once Linux supplies
3644 -        * better facilities for doing these operations, or the
3645 -        * needs of this particular driver change, we might need to do
3646 -        * more here.
3647 -        */
3648 -       dmat->alignment = alignment;
3649 -       dmat->boundary = boundary;
3650 -       dmat->maxsize = maxsize;
3651 -       *ret_tag = dmat;
3652 -       return (0);
3653 -}
3654 -
3655 -void
3656 -ahd_dma_tag_destroy(struct ahd_softc *ahd, bus_dma_tag_t dmat)
3657 -{
3658 -       free(dmat, M_DEVBUF);
3659 -}
3660 -
3661 -int
3662 -ahd_dmamem_alloc(struct ahd_softc *ahd, bus_dma_tag_t dmat, void** vaddr,
3663 -                int flags, bus_dmamap_t *mapp)
3664 -{
3665 -       bus_dmamap_t map;
3666 -
3667 -#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,3,0)
3668 -       map = malloc(sizeof(*map), M_DEVBUF, M_NOWAIT);
3669 -       if (map == NULL)
3670 -               return (ENOMEM);
3671 -       /*
3672 -        * Although we can dma data above 4GB, our
3673 -        * "consistent" memory is below 4GB for
3674 -        * space efficiency reasons (only need a 4byte
3675 -        * address).  For this reason, we have to reset
3676 -        * our dma mask when doing allocations.
3677 -        */
3678 -       if (ahd->dev_softc != NULL)
3679 -               ahd_pci_set_dma_mask(ahd->dev_softc, 0xFFFFFFFF);
3680 -       *vaddr = pci_alloc_consistent(ahd->dev_softc,
3681 -                                     dmat->maxsize, &map->bus_addr);
3682 -       if (ahd->dev_softc != NULL)
3683 -               ahd_pci_set_dma_mask(ahd->dev_softc,
3684 -                                    ahd->platform_data->hw_dma_mask);
3685 -#else /* LINUX_VERSION_CODE < KERNEL_VERSION(2,3,0) */
3686 -       /*
3687 -        * At least in 2.2.14, malloc is a slab allocator so all
3688 -        * allocations are aligned.  We assume for these kernel versions
3689 -        * that all allocations will be bellow 4Gig, physically contiguous,
3690 -        * and accessible via DMA by the controller.
3691 -        */
3692 -       map = NULL; /* No additional information to store */
3693 -       *vaddr = malloc(dmat->maxsize, M_DEVBUF, M_NOWAIT);
3694 -#endif
3695 -       if (*vaddr == NULL)
3696 -               return (ENOMEM);
3697 -       *mapp = map;
3698 -       return(0);
3699 -}
3700 -
3701 -void
3702 -ahd_dmamem_free(struct ahd_softc *ahd, bus_dma_tag_t dmat,
3703 -               void* vaddr, bus_dmamap_t map)
3704 -{
3705 -#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,3,0)
3706 -       pci_free_consistent(ahd->dev_softc, dmat->maxsize,
3707 -                           vaddr, map->bus_addr);
3708 -#else
3709 -       free(vaddr, M_DEVBUF);
3710 -#endif
3711 -}
3712 -
3713 -int
3714 -ahd_dmamap_load(struct ahd_softc *ahd, bus_dma_tag_t dmat, bus_dmamap_t map,
3715 -               void *buf, bus_size_t buflen, bus_dmamap_callback_t *cb,
3716 -               void *cb_arg, int flags)
3717 -{
3718 -       /*
3719 -        * Assume for now that this will only be used during
3720 -        * initialization and not for per-transaction buffer mapping.
3721 -        */
3722 -       bus_dma_segment_t stack_sg;
3723 -
3724 -#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,3,0)
3725 -       stack_sg.ds_addr = map->bus_addr;
3726 -#else
3727 -#define VIRT_TO_BUS(a) (uint32_t)virt_to_bus((void *)(a))
3728 -       stack_sg.ds_addr = VIRT_TO_BUS(buf);
3729 -#endif
3730 -       stack_sg.ds_len = dmat->maxsize;
3731 -       cb(cb_arg, &stack_sg, /*nseg*/1, /*error*/0);
3732 -       return (0);
3733 -}
3734 -
3735 -void
3736 -ahd_dmamap_destroy(struct ahd_softc *ahd, bus_dma_tag_t dmat, bus_dmamap_t map)
3737 -{
3738 -       /*
3739 -        * The map may is NULL in our < 2.3.X implementation.
3740 -        */
3741 -       if (map != NULL)
3742 -               free(map, M_DEVBUF);
3743 -}
3744 -
3745 -int
3746 -ahd_dmamap_unload(struct ahd_softc *ahd, bus_dma_tag_t dmat, bus_dmamap_t map)
3747 -{
3748 -       /* Nothing to do */
3749 -       return (0);
3750 -}
3751 +Scsi_Host_Template aic79xx_driver_template = 
3752 +       AIC_TEMPLATE_INITIALIZER("aic79xx", /*max_sectors*/8192);
3753  
3754  /********************* Platform Dependent Functions ***************************/
3755  /*
3756 @@ -1907,19 +1803,19 @@
3757  
3758         /* Still equal.  Sort by bus/slot/func. */
3759         if (aic79xx_reverse_scan != 0)
3760 -               value = ahd_get_pci_bus(lahd->dev_softc)
3761 -                     - ahd_get_pci_bus(rahd->dev_softc);
3762 +               value = aic_get_pci_bus(lahd->dev_softc)
3763 +                     - aic_get_pci_bus(rahd->dev_softc);
3764         else
3765 -               value = ahd_get_pci_bus(rahd->dev_softc)
3766 -                     - ahd_get_pci_bus(lahd->dev_softc);
3767 +               value = aic_get_pci_bus(rahd->dev_softc)
3768 +                     - aic_get_pci_bus(lahd->dev_softc);
3769         if (value != 0)
3770                 return (value);
3771         if (aic79xx_reverse_scan != 0)
3772 -               value = ahd_get_pci_slot(lahd->dev_softc)
3773 -                     - ahd_get_pci_slot(rahd->dev_softc);
3774 +               value = aic_get_pci_slot(lahd->dev_softc)
3775 +                     - aic_get_pci_slot(rahd->dev_softc);
3776         else
3777 -               value = ahd_get_pci_slot(rahd->dev_softc)
3778 -                     - ahd_get_pci_slot(lahd->dev_softc);
3779 +               value = aic_get_pci_slot(rahd->dev_softc)
3780 +                     - aic_get_pci_slot(lahd->dev_softc);
3781         if (value != 0)
3782                 return (value);
3783  
3784 @@ -2096,9 +1992,16 @@
3785         char    *new_name;
3786         u_long  s;
3787         u_long  target;
3788 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,0)
3789 +       int     error;
3790 +#endif
3791  
3792         template->name = ahd->description;
3793 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,0)
3794 +       host = scsi_host_alloc(template, sizeof(struct ahd_softc *));
3795 +#else
3796         host = scsi_register(template, sizeof(struct ahd_softc *));
3797 +#endif
3798         if (host == NULL)
3799                 return (ENOMEM);
3800  
3801 @@ -2107,8 +2010,12 @@
3802  #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,0)
3803         scsi_assign_lock(host, &ahd->platform_data->spin_lock);
3804  #elif AHD_SCSI_HAS_HOST_LOCK != 0
3805 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,21)
3806 +       host->host_lock = &ahd->platform_data->spin_lock;
3807 +#else
3808         host->lock = &ahd->platform_data->spin_lock;
3809  #endif
3810 +#endif
3811         ahd->platform_data->host = host;
3812         host->can_queue = AHD_MAX_QUEUE;
3813         host->cmd_per_lun = 2;
3814 @@ -2134,13 +2041,20 @@
3815         ahd_linux_setup_user_rd_strm_settings(ahd);
3816         ahd_linux_initialize_scsi_bus(ahd);
3817         ahd_unlock(ahd, &s);
3818 +       ahd_sysrq_key = aic_install_sysrq(&ahd_sysrq_op);
3819 +       ahd_spawn_recovery_thread(ahd);
3820 +       if (ahd->platform_data->recovery_pid < 0) {
3821 +               printf("%s: Failed to create recovery thread, error= %d\n",
3822 +                      ahd_name(ahd), ahd->platform_data->recovery_pid);
3823 +               return (-ahd->platform_data->recovery_pid);
3824 +       }
3825         ahd->platform_data->dv_pid = kernel_thread(ahd_linux_dv_thread, ahd, 0);
3826 -       ahd_lock(ahd, &s);
3827         if (ahd->platform_data->dv_pid < 0) {
3828                 printf("%s: Failed to create DV thread, error= %d\n",
3829                        ahd_name(ahd), ahd->platform_data->dv_pid);
3830                 return (-ahd->platform_data->dv_pid);
3831         }
3832 +       ahd_lock(ahd, &s);
3833         /*
3834          * Initially allocate *all* of our linux target objects
3835          * so that the DV thread will scan them all in parallel
3836 @@ -2160,7 +2074,7 @@
3837                  * It is expected that either an external application
3838                  * or a modified kernel will be used to probe this
3839                  * ID if it is appropriate.  To accommodate these
3840 -                * installations, ahc_linux_alloc_target() will allocate
3841 +                * installations, ahd_linux_alloc_target() will allocate
3842                  * for our ID if asked to do so.
3843                  */
3844                 if (target == ahd->our_id) 
3845 @@ -2173,7 +2087,10 @@
3846         ahd_unlock(ahd, &s);
3847  
3848  #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,0)
3849 -       scsi_add_host(host, &ahd->dev_softc->dev);
3850 +       error = scsi_add_host(host, ahd->dev_softc);
3851 +       if (error != 0)
3852 +               return (-error);
3853 +       scsi_scan_host(host);
3854  #endif
3855         return (0);
3856  }
3857 @@ -2248,17 +2165,6 @@
3858                 ahd_update_neg_request(ahd, &devinfo, tstate,
3859                                        tinfo, AHD_NEG_ALWAYS);
3860         }
3861 -       /* Give the bus some time to recover */
3862 -       if ((ahd->flags & AHD_RESET_BUS_A) != 0) {
3863 -               ahd_freeze_simq(ahd);
3864 -               init_timer(&ahd->platform_data->reset_timer);
3865 -               ahd->platform_data->reset_timer.data = (u_long)ahd;
3866 -               ahd->platform_data->reset_timer.expires =
3867 -                   jiffies + (AIC79XX_RESET_DELAY * HZ)/1000;
3868 -               ahd->platform_data->reset_timer.function =
3869 -                   (ahd_linux_callback_t *)ahd_release_simq;
3870 -               add_timer(&ahd->platform_data->reset_timer);
3871 -       }
3872  }
3873  
3874  int
3875 @@ -2271,24 +2177,32 @@
3876         memset(ahd->platform_data, 0, sizeof(struct ahd_platform_data));
3877         TAILQ_INIT(&ahd->platform_data->completeq);
3878         TAILQ_INIT(&ahd->platform_data->device_runq);
3879 -       ahd->platform_data->irq = AHD_LINUX_NOIRQ;
3880 +       ahd->platform_data->irq = AIC_LINUX_NOIRQ;
3881         ahd->platform_data->hw_dma_mask = 0xFFFFFFFF;
3882         ahd_lockinit(ahd);
3883         ahd_done_lockinit(ahd);
3884 +       init_timer(&ahd->platform_data->bus_settle_timer);
3885 +       ahd->platform_data->bus_settle_timer.data = (u_long)ahd;
3886 +       ahd->platform_data->bus_settle_timer.function =
3887 +           (aic_linux_callback_t *)aic_bus_settle_complete;
3888         init_timer(&ahd->platform_data->completeq_timer);
3889         ahd->platform_data->completeq_timer.data = (u_long)ahd;
3890         ahd->platform_data->completeq_timer.function =
3891 -           (ahd_linux_callback_t *)ahd_linux_thread_run_complete_queue;
3892 +           (aic_linux_callback_t *)ahd_linux_thread_run_complete_queue;
3893  #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,3,0)
3894         init_MUTEX_LOCKED(&ahd->platform_data->eh_sem);
3895         init_MUTEX_LOCKED(&ahd->platform_data->dv_sem);
3896         init_MUTEX_LOCKED(&ahd->platform_data->dv_cmd_sem);
3897 +       init_MUTEX_LOCKED(&ahd->platform_data->recovery_sem);
3898 +       init_MUTEX_LOCKED(&ahd->platform_data->recovery_ending_sem);
3899  #else
3900         ahd->platform_data->eh_sem = MUTEX_LOCKED;
3901         ahd->platform_data->dv_sem = MUTEX_LOCKED;
3902         ahd->platform_data->dv_cmd_sem = MUTEX_LOCKED;
3903 +       ahd->platform_data->recovery_sem = MUTEX_LOCKED;
3904 +       ahd->platform_data->recovery_ending_sem = MUTEX_LOCKED;
3905  #endif
3906 -       ahd_setup_runq_tasklet(ahd);
3907 +       aic_setup_tasklets(ahd);
3908         ahd->seltime = (aic79xx_seltime & 0x3) << 4;
3909         return (0);
3910  }
3911 @@ -2296,19 +2210,22 @@
3912  void
3913  ahd_platform_free(struct ahd_softc *ahd)
3914  {
3915 -       struct ahd_linux_target *targ;
3916 -       struct ahd_linux_device *dev;
3917 +       struct aic_linux_target *targ;
3918 +       struct aic_linux_device *dev;
3919         int i, j;
3920  
3921 +       aic_remove_sysrq(ahd_sysrq_key, &ahd_sysrq_op);
3922         if (ahd->platform_data != NULL) {
3923                 del_timer_sync(&ahd->platform_data->completeq_timer);
3924                 ahd_linux_kill_dv_thread(ahd);
3925 -               ahd_teardown_runq_tasklet(ahd);
3926 +               aic_teardown_tasklets(ahd);
3927                 if (ahd->platform_data->host != NULL) {
3928  #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,0)
3929                         scsi_remove_host(ahd->platform_data->host);
3930 -#endif
3931 +                       scsi_host_put(ahd->platform_data->host);
3932 +#else
3933                         scsi_unregister(ahd->platform_data->host);
3934 +#endif
3935                 }
3936  
3937                 /* destroy all of the device and target objects */
3938 @@ -2322,6 +2239,7 @@
3939                                         if (targ->devices[j] == NULL)
3940                                                 continue;
3941                                         dev = targ->devices[j];
3942 +                                       del_timer_sync(&dev->timer);
3943                                         ahd_linux_free_device(ahd, dev);
3944                                 }
3945                                 /*
3946 @@ -2332,7 +2250,7 @@
3947                         }
3948                 }
3949  
3950 -               if (ahd->platform_data->irq != AHD_LINUX_NOIRQ)
3951 +               if (ahd->platform_data->irq != AIC_LINUX_NOIRQ)
3952                         free_irq(ahd->platform_data->irq, ahd);
3953                 if (ahd->tags[0] == BUS_SPACE_PIO
3954                  && ahd->bshs[0].ioport != 0)
3955 @@ -2400,7 +2318,7 @@
3956  ahd_platform_set_tags(struct ahd_softc *ahd, struct ahd_devinfo *devinfo,
3957                       ahd_queue_alg alg)
3958  {
3959 -       struct ahd_linux_device *dev;
3960 +       struct aic_linux_device *dev;
3961         int was_queuing;
3962         int now_queuing;
3963  
3964 @@ -2409,27 +2327,27 @@
3965                                    devinfo->lun, /*alloc*/FALSE);
3966         if (dev == NULL)
3967                 return;
3968 -       was_queuing = dev->flags & (AHD_DEV_Q_BASIC|AHD_DEV_Q_TAGGED);
3969 +       was_queuing = dev->flags & (AIC_DEV_Q_BASIC|AIC_DEV_Q_TAGGED);
3970         switch (alg) {
3971         default:
3972         case AHD_QUEUE_NONE:
3973                 now_queuing = 0;
3974                 break; 
3975         case AHD_QUEUE_BASIC:
3976 -               now_queuing = AHD_DEV_Q_BASIC;
3977 +               now_queuing = AIC_DEV_Q_BASIC;
3978                 break;
3979         case AHD_QUEUE_TAGGED:
3980 -               now_queuing = AHD_DEV_Q_TAGGED;
3981 +               now_queuing = AIC_DEV_Q_TAGGED;
3982                 break;
3983         }
3984 -       if ((dev->flags & AHD_DEV_FREEZE_TIL_EMPTY) == 0
3985 +       if ((dev->flags & AIC_DEV_FREEZE_TIL_EMPTY) == 0
3986          && (was_queuing != now_queuing)
3987          && (dev->active != 0)) {
3988 -               dev->flags |= AHD_DEV_FREEZE_TIL_EMPTY;
3989 +               dev->flags |= AIC_DEV_FREEZE_TIL_EMPTY;
3990                 dev->qfrozen++;
3991         }
3992  
3993 -       dev->flags &= ~(AHD_DEV_Q_BASIC|AHD_DEV_Q_TAGGED|AHD_DEV_PERIODIC_OTAG);
3994 +       dev->flags &= ~(AIC_DEV_Q_BASIC|AIC_DEV_Q_TAGGED|AIC_DEV_PERIODIC_OTAG);
3995         if (now_queuing) {
3996                 u_int usertags;
3997  
3998 @@ -2449,11 +2367,11 @@
3999                          */
4000                         dev->openings = 1;
4001                 } else if (alg == AHD_QUEUE_TAGGED) {
4002 -                       dev->flags |= AHD_DEV_Q_TAGGED;
4003 +                       dev->flags |= AIC_DEV_Q_TAGGED;
4004                         if (aic79xx_periodic_otag != 0)
4005 -                               dev->flags |= AHD_DEV_PERIODIC_OTAG;
4006 +                               dev->flags |= AIC_DEV_PERIODIC_OTAG;
4007                 } else
4008 -                       dev->flags |= AHD_DEV_Q_BASIC;
4009 +                       dev->flags |= AIC_DEV_Q_BASIC;
4010         } else {
4011                 /* We can only have one opening. */
4012                 dev->maxtags = 0;
4013 @@ -2461,13 +2379,13 @@
4014         }
4015  #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,0)
4016         if (dev->scsi_device != NULL) {
4017 -               switch ((dev->flags & (AHD_DEV_Q_BASIC|AHD_DEV_Q_TAGGED))) {
4018 -               case AHD_DEV_Q_BASIC:
4019 +               switch ((dev->flags & (AIC_DEV_Q_BASIC|AIC_DEV_Q_TAGGED))) {
4020 +               case AIC_DEV_Q_BASIC:
4021                         scsi_adjust_queue_depth(dev->scsi_device,
4022                                                 MSG_SIMPLE_TASK,
4023                                                 dev->openings + dev->active);
4024                         break;
4025 -               case AHD_DEV_Q_TAGGED:
4026 +               case AIC_DEV_Q_TAGGED:
4027                         scsi_adjust_queue_depth(dev->scsi_device,
4028                                                 MSG_ORDERED_TASK,
4029                                                 dev->openings + dev->active);
4030 @@ -2520,9 +2438,9 @@
4031         for (; targ < maxtarg; targ++) {
4032  
4033                 for (; clun < maxlun; clun++) {
4034 -                       struct ahd_linux_device *dev;
4035 -                       struct ahd_busyq *busyq;
4036 -                       struct ahd_cmd *acmd;
4037 +                       struct aic_linux_device *dev;
4038 +                       struct aic_busyq *busyq;
4039 +                       struct aic_cmd *acmd;
4040  
4041                         dev = ahd_linux_get_device(ahd, /*chan*/0, targ,
4042                                                    clun, /*alloc*/FALSE);
4043 @@ -2538,6 +2456,18 @@
4044                                              acmd_links.tqe);
4045                                 count++;
4046                                 cmd->result = status << 16;
4047 +                               /*
4048 +                                * The completion handler believes that
4049 +                                * commands without active timers running
4050 +                                * have lost the race of completing before
4051 +                                * their timer expires.  Since commands in
4052 +                                * our busy queues do not have timers running,
4053 +                                * appease the mid-layer by adding a timer
4054 +                                * now.  This timer will be immediately
4055 +                                * canceled by the midlayer.
4056 +                                */
4057 +                               scsi_add_timer(cmd, 60*HZ,
4058 +                                              aic_linux_midlayer_timeout);
4059                                 ahd_linux_queue_cmd_complete(ahd, cmd);
4060                         }
4061                 }
4062 @@ -2553,7 +2483,7 @@
4063  
4064         ahd_lock(ahd, &flags);
4065         del_timer(&ahd->platform_data->completeq_timer);
4066 -       ahd->platform_data->flags &= ~AHD_RUN_CMPLT_Q_TIMER;
4067 +       ahd->platform_data->flags &= ~AIC_RUN_CMPLT_Q_TIMER;
4068         ahd_linux_run_complete_queue(ahd);
4069         ahd_unlock(ahd, &flags);
4070  }
4071 @@ -2566,14 +2496,23 @@
4072          * Freeze the simq and signal ahd_linux_queue to not let any
4073          * more commands through
4074          */
4075 -       if ((ahd->platform_data->flags & AHD_DV_ACTIVE) == 0) {
4076 +       if ((ahd->platform_data->flags & AIC_DV_ACTIVE) == 0) {
4077  #ifdef AHD_DEBUG
4078                 if (ahd_debug & AHD_SHOW_DV)
4079                         printf("%s: Starting DV\n", ahd_name(ahd));
4080  #endif
4081  
4082 -               ahd->platform_data->flags |= AHD_DV_ACTIVE;
4083 -               ahd_freeze_simq(ahd);
4084 +               ahd->platform_data->flags |= AIC_DV_ACTIVE;
4085 +
4086 +               /*
4087 +                * Prevent upper layer from sending any
4088 +                * commands to us.
4089 +                */
4090 +               aic_freeze_simq(ahd);
4091 +               scsi_block_requests(ahd->platform_data->host);
4092 +               ahd_platform_abort_scbs(ahd, CAM_TARGET_WILDCARD, ALL_CHANNELS,
4093 +                                       CAM_LUN_WILDCARD, SCB_LIST_NULL,
4094 +                                       ROLE_INITIATOR, CAM_REQUEUE_REQ);
4095  
4096                 /* Wake up the DV kthread */
4097                 up(&ahd->platform_data->dv_sem);
4098 @@ -2612,6 +2551,7 @@
4099         unlock_kernel();
4100  
4101         while (1) {
4102 +
4103                 /*
4104                  * Use down_interruptible() rather than down() to
4105                  * avoid inclusion in the load average.
4106 @@ -2620,7 +2560,7 @@
4107  
4108                 /* Check to see if we've been signaled to exit */
4109                 ahd_lock(ahd, &s);
4110 -               if ((ahd->platform_data->flags & AHD_DV_SHUTDOWN) != 0) {
4111 +               if ((ahd->platform_data->flags & AIC_DV_SHUTDOWN) != 0) {
4112                         ahd_unlock(ahd, &s);
4113                         break;
4114                 }
4115 @@ -2637,7 +2577,7 @@
4116                  */
4117                 ahd_lock(ahd, &s);
4118                 while (LIST_FIRST(&ahd->pending_scbs) != NULL) {
4119 -                       ahd->platform_data->flags |= AHD_DV_WAIT_SIMQ_EMPTY;
4120 +                       ahd->platform_data->flags |= AIC_DV_WAIT_SIMQ_EMPTY;
4121                         ahd_unlock(ahd, &s);
4122                         down_interruptible(&ahd->platform_data->dv_sem);
4123                         ahd_lock(ahd, &s);
4124 @@ -2647,8 +2587,8 @@
4125                  * Wait for the SIMQ to be released so that DV is the
4126                  * only reason the queue is frozen.
4127                  */
4128 -               while (AHD_DV_SIMQ_FROZEN(ahd) == 0) {
4129 -                       ahd->platform_data->flags |= AHD_DV_WAIT_SIMQ_RELEASE;
4130 +               while (AIC_DV_SIMQ_FROZEN(ahd) == 0) {
4131 +                       ahd->platform_data->flags |= AIC_DV_WAIT_SIMQ_RELEASE;
4132                         ahd_unlock(ahd, &s);
4133                         down_interruptible(&ahd->platform_data->dv_sem);
4134                         ahd_lock(ahd, &s);
4135 @@ -2659,14 +2599,17 @@
4136                         ahd_linux_dv_target(ahd, target);
4137  
4138                 ahd_lock(ahd, &s);
4139 -               ahd->platform_data->flags &= ~AHD_DV_ACTIVE;
4140 -               ahd_unlock(ahd, &s);
4141 +               ahd->platform_data->flags &= ~AIC_DV_ACTIVE;
4142  
4143                 /*
4144                  * Release the SIMQ so that normal commands are
4145                  * allowed to continue on the bus.
4146                  */
4147 -               ahd_release_simq(ahd);
4148 +               aic_release_simq_locked(ahd);
4149 +
4150 +               ahd_unlock(ahd, &s);
4151 +
4152 +               scsi_unblock_requests(ahd->platform_data->host);
4153         }
4154         up(&ahd->platform_data->eh_sem);
4155         return (0);
4156 @@ -2679,7 +2622,7 @@
4157  
4158         ahd_lock(ahd, &s);
4159         if (ahd->platform_data->dv_pid != 0) {
4160 -               ahd->platform_data->flags |= AHD_DV_SHUTDOWN;
4161 +               ahd->platform_data->flags |= AIC_DV_SHUTDOWN;
4162                 ahd_unlock(ahd, &s);
4163                 up(&ahd->platform_data->dv_sem);
4164  
4165 @@ -2699,10 +2642,10 @@
4166                 /*
4167                  * Mark the dv thread as already dead.  This
4168                  * avoids attempting to kill it a second time.
4169 -                * This is necessary because we must kill the
4170 -                * DV thread before calling ahd_free() in the
4171 +                * This is necessary because we must kill our
4172 +                * threads before calling ahd_free() in the
4173                  * module shutdown case to avoid bogus locking
4174 -                * in the SCSI mid-layer, but we ahd_free() is
4175 +                * in the SCSI mid-layer, but when ahd_free() is
4176                  * called without killing the DV thread in the
4177                  * instance detach case, so ahd_platform_free()
4178                  * calls us again to verify that the DV thread
4179 @@ -2722,10 +2665,10 @@
4180         ahd_set_dv_state(ahd, targ, newstate, __LINE__)
4181  
4182  static __inline void
4183 -ahd_set_dv_state(struct ahd_softc *ahd, struct ahd_linux_target *targ,
4184 -                ahd_dv_state newstate, u_int line)
4185 +ahd_set_dv_state(struct ahd_softc *ahd, struct aic_linux_target *targ,
4186 +                aic_dv_state newstate, u_int line)
4187  {
4188 -       ahd_dv_state oldstate;
4189 +       aic_dv_state oldstate;
4190  
4191         oldstate = targ->dv_state;
4192  #ifdef AHD_DEBUG
4193 @@ -2745,7 +2688,7 @@
4194  ahd_linux_dv_target(struct ahd_softc *ahd, u_int target_offset)
4195  {
4196         struct   ahd_devinfo devinfo;
4197 -       struct   ahd_linux_target *targ;
4198 +       struct   aic_linux_target *targ;
4199         struct   scsi_cmnd *cmd;
4200         struct   scsi_device *scsi_dev;
4201         struct   scsi_sense_data *sense;
4202 @@ -2759,7 +2702,7 @@
4203         echo_size = 0;
4204         ahd_lock(ahd, &s);
4205         targ = ahd->platform_data->targets[target_offset];
4206 -       if (targ == NULL || (targ->flags & AHD_DV_REQUIRED) == 0) {
4207 +       if (targ == NULL || (targ->flags & AIC_DV_REQUIRED) == 0) {
4208                 ahd_unlock(ahd, &s);
4209                 return;
4210         }
4211 @@ -2782,14 +2725,14 @@
4212         scsi_dev->channel = devinfo.channel - 'A';
4213         ahd->platform_data->dv_scsi_dev = scsi_dev;
4214  
4215 -       AHD_SET_DV_STATE(ahd, targ, AHD_DV_STATE_INQ_SHORT_ASYNC);
4216 +       AHD_SET_DV_STATE(ahd, targ, AIC_DV_STATE_INQ_SHORT_ASYNC);
4217  
4218 -       while (targ->dv_state != AHD_DV_STATE_EXIT) {
4219 +       while (targ->dv_state != AIC_DV_STATE_EXIT) {
4220                 timeout = AHD_LINUX_DV_TIMEOUT;
4221                 switch (targ->dv_state) {
4222 -               case AHD_DV_STATE_INQ_SHORT_ASYNC:
4223 -               case AHD_DV_STATE_INQ_ASYNC:
4224 -               case AHD_DV_STATE_INQ_ASYNC_VERIFY:
4225 +               case AIC_DV_STATE_INQ_SHORT_ASYNC:
4226 +               case AIC_DV_STATE_INQ_ASYNC:
4227 +               case AIC_DV_STATE_INQ_ASYNC_VERIFY:
4228                         /*
4229                          * Set things to async narrow to reduce the
4230                          * chance that the INQ will fail.
4231 @@ -2801,36 +2744,36 @@
4232                                       AHD_TRANS_GOAL, /*paused*/FALSE);
4233                         ahd_unlock(ahd, &s);
4234                         timeout = 10 * HZ;
4235 -                       targ->flags &= ~AHD_INQ_VALID;
4236 +                       targ->flags &= ~AIC_INQ_VALID;
4237                         /* FALLTHROUGH */
4238 -               case AHD_DV_STATE_INQ_VERIFY:
4239 +               case AIC_DV_STATE_INQ_VERIFY:
4240                 {
4241                         u_int inq_len;
4242  
4243 -                       if (targ->dv_state == AHD_DV_STATE_INQ_SHORT_ASYNC)
4244 +                       if (targ->dv_state == AIC_DV_STATE_INQ_SHORT_ASYNC)
4245                                 inq_len = AHD_LINUX_DV_INQ_SHORT_LEN;
4246                         else
4247                                 inq_len = targ->inq_data->additional_length + 5;
4248                         ahd_linux_dv_inq(ahd, cmd, &devinfo, targ, inq_len);
4249                         break;
4250                 }
4251 -               case AHD_DV_STATE_TUR:
4252 -               case AHD_DV_STATE_BUSY:
4253 +               case AIC_DV_STATE_TUR:
4254 +               case AIC_DV_STATE_BUSY:
4255                         timeout = 5 * HZ;
4256                         ahd_linux_dv_tur(ahd, cmd, &devinfo);
4257                         break;
4258 -               case AHD_DV_STATE_REBD:
4259 +               case AIC_DV_STATE_REBD:
4260                         ahd_linux_dv_rebd(ahd, cmd, &devinfo, targ);
4261                         break;
4262 -               case AHD_DV_STATE_WEB:
4263 +               case AIC_DV_STATE_WEB:
4264                         ahd_linux_dv_web(ahd, cmd, &devinfo, targ);
4265                         break;
4266  
4267 -               case AHD_DV_STATE_REB:
4268 +               case AIC_DV_STATE_REB:
4269                         ahd_linux_dv_reb(ahd, cmd, &devinfo, targ);
4270                         break;
4271  
4272 -               case AHD_DV_STATE_SU:
4273 +               case AIC_DV_STATE_SU:
4274                         ahd_linux_dv_su(ahd, cmd, &devinfo, targ);
4275                         timeout = 50 * HZ;
4276                         break;
4277 @@ -2842,8 +2785,6 @@
4278                 }
4279  
4280                 /* Queue the command and wait for it to complete */
4281 -               /* Abuse eh_timeout in the scsi_cmnd struct for our purposes */
4282 -               init_timer(&cmd->eh_timeout);
4283  #ifdef AHD_DEBUG
4284                 if ((ahd_debug & AHD_SHOW_MESSAGES) != 0)
4285                         /*
4286 @@ -2853,7 +2794,9 @@
4287                          */
4288                         timeout += HZ;
4289  #endif
4290 -               scsi_add_timer(cmd, timeout, ahd_linux_dv_timeout);
4291 +               init_timer(&cmd->eh_timeout);
4292 +               cmd->timeout_per_command = timeout;
4293 +
4294                 /*
4295                  * In 2.5.X, it is assumed that all calls from the
4296                  * "midlayer" (which we are emulating) will have the
4297 @@ -2872,13 +2815,14 @@
4298                 spin_unlock_irqrestore(&io_request_lock, s);
4299  #endif
4300                 down_interruptible(&ahd->platform_data->dv_cmd_sem);
4301 +
4302                 /*
4303                  * Wait for the SIMQ to be released so that DV is the
4304                  * only reason the queue is frozen.
4305                  */
4306                 ahd_lock(ahd, &s);
4307 -               while (AHD_DV_SIMQ_FROZEN(ahd) == 0) {
4308 -                       ahd->platform_data->flags |= AHD_DV_WAIT_SIMQ_RELEASE;
4309 +               while (AIC_DV_SIMQ_FROZEN(ahd) == 0) {
4310 +                       ahd->platform_data->flags |= AIC_DV_WAIT_SIMQ_RELEASE;
4311                         ahd_unlock(ahd, &s);
4312                         down_interruptible(&ahd->platform_data->dv_sem);
4313                         ahd_lock(ahd, &s);
4314 @@ -2889,7 +2833,7 @@
4315         }
4316  
4317  out:
4318 -       if ((targ->flags & AHD_INQ_VALID) != 0
4319 +       if ((targ->flags & AIC_INQ_VALID) != 0
4320          && ahd_linux_get_device(ahd, devinfo.channel - 'A',
4321                                  devinfo.target, devinfo.lun,
4322                                  /*alloc*/FALSE) == NULL) {
4323 @@ -2900,7 +2844,7 @@
4324                  * parameters found in the inquiry string.
4325                  */
4326                 ahd_linux_filter_inquiry(ahd, &devinfo);
4327 -               if ((targ->flags & (AHD_BASIC_DV|AHD_ENHANCED_DV)) != 0) {
4328 +               if ((targ->flags & (AIC_BASIC_DV|AIC_ENHANCED_DV)) != 0) {
4329                         ahd_print_devinfo(ahd, &devinfo);
4330                         printf("DV failed to configure device.  "
4331                                "Please file a bug report against "
4332 @@ -2925,7 +2869,7 @@
4333                 free(targ->dv_buffer1, M_DEVBUF);
4334                 targ->dv_buffer1 = NULL;
4335         }
4336 -       targ->flags &= ~AHD_DV_REQUIRED;
4337 +       targ->flags &= ~AIC_DV_REQUIRED;
4338         if (targ->refcount == 0)
4339                 ahd_linux_free_target(ahd, targ);
4340         ahd_unlock(ahd, &s);
4341 @@ -2934,13 +2878,13 @@
4342  static void
4343  ahd_linux_dv_transition(struct ahd_softc *ahd, struct scsi_cmnd *cmd,
4344                         struct ahd_devinfo *devinfo,
4345 -                       struct ahd_linux_target *targ)
4346 +                       struct aic_linux_target *targ)
4347  {
4348         u_int32_t status;
4349  
4350         status = aic_error_action(cmd, targ->inq_data,
4351 -                                 ahd_cmd_get_transaction_status(cmd),
4352 -                                 ahd_cmd_get_scsi_status(cmd));
4353 +                                 aic_cmd_get_transaction_status(cmd),
4354 +                                 aic_cmd_get_scsi_status(cmd));
4355  
4356         
4357  #ifdef AHD_DEBUG
4358 @@ -2953,8 +2897,8 @@
4359  #endif
4360  
4361         switch (targ->dv_state) {
4362 -       case AHD_DV_STATE_INQ_SHORT_ASYNC:
4363 -       case AHD_DV_STATE_INQ_ASYNC:
4364 +       case AIC_DV_STATE_INQ_SHORT_ASYNC:
4365 +       case AIC_DV_STATE_INQ_ASYNC:
4366                 switch (status & SS_MASK) {
4367                 case SS_NOP:
4368                 {
4369 @@ -2963,21 +2907,21 @@
4370                 }
4371                 case SS_INQ_REFRESH:
4372                         AHD_SET_DV_STATE(ahd, targ,
4373 -                                        AHD_DV_STATE_INQ_SHORT_ASYNC);
4374 +                                        AIC_DV_STATE_INQ_SHORT_ASYNC);
4375                         break;
4376                 case SS_TUR:
4377                 case SS_RETRY:
4378                         AHD_SET_DV_STATE(ahd, targ, targ->dv_state);
4379 -                       if (ahd_cmd_get_transaction_status(cmd)
4380 +                       if (aic_cmd_get_transaction_status(cmd)
4381                          == CAM_REQUEUE_REQ)
4382                                 targ->dv_state_retry--;
4383                         if ((status & SS_ERRMASK) == EBUSY)
4384 -                               AHD_SET_DV_STATE(ahd, targ, AHD_DV_STATE_BUSY);
4385 +                               AHD_SET_DV_STATE(ahd, targ, AIC_DV_STATE_BUSY);
4386                         if (targ->dv_state_retry < 10)
4387                                 break;
4388                         /* FALLTHROUGH */
4389                 default:
4390 -                       AHD_SET_DV_STATE(ahd, targ, AHD_DV_STATE_EXIT);
4391 +                       AHD_SET_DV_STATE(ahd, targ, AIC_DV_STATE_EXIT);
4392  #ifdef AHD_DEBUG
4393                         if (ahd_debug & AHD_SHOW_DV) {
4394                                 ahd_print_devinfo(ahd, devinfo);
4395 @@ -2987,7 +2931,7 @@
4396                         break;
4397                 }
4398                 break;
4399 -       case AHD_DV_STATE_INQ_ASYNC_VERIFY:
4400 +       case AIC_DV_STATE_INQ_ASYNC_VERIFY:
4401                 switch (status & SS_MASK) {
4402                 case SS_NOP:
4403                 {
4404 @@ -3001,12 +2945,12 @@
4405                                  * Try from the top again.
4406                                  */
4407                                 AHD_SET_DV_STATE(ahd, targ,
4408 -                                                AHD_DV_STATE_INQ_SHORT_ASYNC);
4409 +                                                AIC_DV_STATE_INQ_SHORT_ASYNC);
4410                                 break;
4411                         }
4412  
4413                         AHD_SET_DV_STATE(ahd, targ, targ->dv_state+1);
4414 -                       targ->flags |= AHD_INQ_VALID;
4415 +                       targ->flags |= AIC_INQ_VALID;
4416                         if (ahd_linux_user_dv_setting(ahd) == 0)
4417                                 break;
4418  
4419 @@ -3019,33 +2963,33 @@
4420                         default:
4421                         case SID_SPI_CLOCK_ST:
4422                                 /* Assume only basic DV is supported. */
4423 -                               targ->flags |= AHD_BASIC_DV;
4424 +                               targ->flags |= AIC_BASIC_DV;
4425                                 break;
4426                         case SID_SPI_CLOCK_DT:
4427                         case SID_SPI_CLOCK_DT_ST:
4428 -                               targ->flags |= AHD_ENHANCED_DV;
4429 +                               targ->flags |= AIC_ENHANCED_DV;
4430                                 break;
4431                         }
4432                         break;
4433                 }
4434                 case SS_INQ_REFRESH:
4435                         AHD_SET_DV_STATE(ahd, targ,
4436 -                                        AHD_DV_STATE_INQ_SHORT_ASYNC);
4437 +                                        AIC_DV_STATE_INQ_SHORT_ASYNC);
4438                         break;
4439                 case SS_TUR:
4440                 case SS_RETRY:
4441                         AHD_SET_DV_STATE(ahd, targ, targ->dv_state);
4442 -                       if (ahd_cmd_get_transaction_status(cmd)
4443 +                       if (aic_cmd_get_transaction_status(cmd)
4444                          == CAM_REQUEUE_REQ)
4445                                 targ->dv_state_retry--;
4446  
4447                         if ((status & SS_ERRMASK) == EBUSY)
4448 -                               AHD_SET_DV_STATE(ahd, targ, AHD_DV_STATE_BUSY);
4449 +                               AHD_SET_DV_STATE(ahd, targ, AIC_DV_STATE_BUSY);
4450                         if (targ->dv_state_retry < 10)
4451                                 break;
4452                         /* FALLTHROUGH */
4453                 default:
4454 -                       AHD_SET_DV_STATE(ahd, targ, AHD_DV_STATE_EXIT);
4455 +                       AHD_SET_DV_STATE(ahd, targ, AIC_DV_STATE_EXIT);
4456  #ifdef AHD_DEBUG
4457                         if (ahd_debug & AHD_SHOW_DV) {
4458                                 ahd_print_devinfo(ahd, devinfo);
4459 @@ -3055,14 +2999,14 @@
4460                         break;
4461                 }
4462                 break;
4463 -       case AHD_DV_STATE_INQ_VERIFY:
4464 +       case AIC_DV_STATE_INQ_VERIFY:
4465                 switch (status & SS_MASK) {
4466                 case SS_NOP:
4467                 {
4468  
4469                         if (memcmp(targ->inq_data, targ->dv_buffer,
4470                                    AHD_LINUX_DV_INQ_LEN) == 0) {
4471 -                               AHD_SET_DV_STATE(ahd, targ, AHD_DV_STATE_EXIT);
4472 +                               AHD_SET_DV_STATE(ahd, targ, AIC_DV_STATE_EXIT);
4473                                 break;
4474                         }
4475  
4476 @@ -3084,7 +3028,7 @@
4477  #endif
4478  
4479                         if (ahd_linux_dv_fallback(ahd, devinfo) != 0) {
4480 -                               AHD_SET_DV_STATE(ahd, targ, AHD_DV_STATE_EXIT);
4481 +                               AHD_SET_DV_STATE(ahd, targ, AIC_DV_STATE_EXIT);
4482                                 break;
4483                         }
4484                         /*
4485 @@ -3097,18 +3041,18 @@
4486                 }
4487                 case SS_INQ_REFRESH:
4488                         AHD_SET_DV_STATE(ahd, targ,
4489 -                                        AHD_DV_STATE_INQ_SHORT_ASYNC);
4490 +                                        AIC_DV_STATE_INQ_SHORT_ASYNC);
4491                         break;
4492                 case SS_TUR:
4493                 case SS_RETRY:
4494                         AHD_SET_DV_STATE(ahd, targ, targ->dv_state);
4495 -                       if (ahd_cmd_get_transaction_status(cmd)
4496 +                       if (aic_cmd_get_transaction_status(cmd)
4497                          == CAM_REQUEUE_REQ) {
4498                                 targ->dv_state_retry--;
4499                         } else if ((status & SSQ_FALLBACK) != 0) {
4500                                 if (ahd_linux_dv_fallback(ahd, devinfo) != 0) {
4501                                         AHD_SET_DV_STATE(ahd, targ,
4502 -                                                        AHD_DV_STATE_EXIT);
4503 +                                                        AIC_DV_STATE_EXIT);
4504                                         break;
4505                                 }
4506                                 /*
4507 @@ -3117,12 +3061,12 @@
4508                                  */
4509                                 targ->dv_state_retry = 0;
4510                         } else if ((status & SS_ERRMASK) == EBUSY)
4511 -                               AHD_SET_DV_STATE(ahd, targ, AHD_DV_STATE_BUSY);
4512 +                               AHD_SET_DV_STATE(ahd, targ, AIC_DV_STATE_BUSY);
4513                         if (targ->dv_state_retry < 10)
4514                                 break;
4515                         /* FALLTHROUGH */
4516                 default:
4517 -                       AHD_SET_DV_STATE(ahd, targ, AHD_DV_STATE_EXIT);
4518 +                       AHD_SET_DV_STATE(ahd, targ, AIC_DV_STATE_EXIT);
4519  #ifdef AHD_DEBUG
4520                         if (ahd_debug & AHD_SHOW_DV) {
4521                                 ahd_print_devinfo(ahd, devinfo);
4522 @@ -3133,33 +3077,33 @@
4523                 }
4524                 break;
4525  
4526 -       case AHD_DV_STATE_TUR:
4527 +       case AIC_DV_STATE_TUR:
4528                 switch (status & SS_MASK) {
4529                 case SS_NOP:
4530 -                       if ((targ->flags & AHD_BASIC_DV) != 0) {
4531 +                       if ((targ->flags & AIC_BASIC_DV) != 0) {
4532                                 ahd_linux_filter_inquiry(ahd, devinfo);
4533                                 AHD_SET_DV_STATE(ahd, targ,
4534 -                                                AHD_DV_STATE_INQ_VERIFY);
4535 -                       } else if ((targ->flags & AHD_ENHANCED_DV) != 0) {
4536 -                               AHD_SET_DV_STATE(ahd, targ, AHD_DV_STATE_REBD);
4537 +                                                AIC_DV_STATE_INQ_VERIFY);
4538 +                       } else if ((targ->flags & AIC_ENHANCED_DV) != 0) {
4539 +                               AHD_SET_DV_STATE(ahd, targ, AIC_DV_STATE_REBD);
4540                         } else {
4541 -                               AHD_SET_DV_STATE(ahd, targ, AHD_DV_STATE_EXIT);
4542 +                               AHD_SET_DV_STATE(ahd, targ, AIC_DV_STATE_EXIT);
4543                         }
4544                         break;
4545                 case SS_RETRY:
4546                 case SS_TUR:
4547                         if ((status & SS_ERRMASK) == EBUSY) {
4548 -                               AHD_SET_DV_STATE(ahd, targ, AHD_DV_STATE_BUSY);
4549 +                               AHD_SET_DV_STATE(ahd, targ, AIC_DV_STATE_BUSY);
4550                                 break;
4551                         }
4552                         AHD_SET_DV_STATE(ahd, targ, targ->dv_state);
4553 -                       if (ahd_cmd_get_transaction_status(cmd)
4554 +                       if (aic_cmd_get_transaction_status(cmd)
4555                          == CAM_REQUEUE_REQ) {
4556                                 targ->dv_state_retry--;
4557                         } else if ((status & SSQ_FALLBACK) != 0) {
4558                                 if (ahd_linux_dv_fallback(ahd, devinfo) != 0) {
4559                                         AHD_SET_DV_STATE(ahd, targ,
4560 -                                                        AHD_DV_STATE_EXIT);
4561 +                                                        AIC_DV_STATE_EXIT);
4562                                         break;
4563                                 }
4564                                 /*
4565 @@ -3175,7 +3119,7 @@
4566                                         printf("DV TUR reties exhausted\n");
4567                                 }
4568  #endif
4569 -                               AHD_SET_DV_STATE(ahd, targ, AHD_DV_STATE_EXIT);
4570 +                               AHD_SET_DV_STATE(ahd, targ, AIC_DV_STATE_EXIT);
4571                                 break;
4572                         }
4573                         if (status & SSQ_DELAY)
4574 @@ -3183,25 +3127,25 @@
4575  
4576                         break;
4577                 case SS_START:
4578 -                       AHD_SET_DV_STATE(ahd, targ, AHD_DV_STATE_SU);
4579 +                       AHD_SET_DV_STATE(ahd, targ, AIC_DV_STATE_SU);
4580                         break;
4581                 case SS_INQ_REFRESH:
4582                         AHD_SET_DV_STATE(ahd, targ,
4583 -                                        AHD_DV_STATE_INQ_SHORT_ASYNC);
4584 +                                        AIC_DV_STATE_INQ_SHORT_ASYNC);
4585                         break;
4586                 default:
4587 -                       AHD_SET_DV_STATE(ahd, targ, AHD_DV_STATE_EXIT);
4588 +                       AHD_SET_DV_STATE(ahd, targ, AIC_DV_STATE_EXIT);
4589                         break;
4590                 }
4591                 break;
4592  
4593 -       case AHD_DV_STATE_REBD:
4594 +       case AIC_DV_STATE_REBD:
4595                 switch (status & SS_MASK) {
4596                 case SS_NOP:
4597                 {
4598                         uint32_t echo_size;
4599  
4600 -                       AHD_SET_DV_STATE(ahd, targ, AHD_DV_STATE_WEB);
4601 +                       AHD_SET_DV_STATE(ahd, targ, AIC_DV_STATE_WEB);
4602                         echo_size = scsi_3btoul(&targ->dv_buffer[1]);
4603                         echo_size &= 0x1FFF;
4604  #ifdef AHD_DEBUG
4605 @@ -3211,7 +3155,17 @@
4606                         }
4607  #endif
4608                         if (echo_size == 0) {
4609 -                               AHD_SET_DV_STATE(ahd, targ, AHD_DV_STATE_EXIT);
4610 +                               /*
4611 +                                * Fall back to basic DV.
4612 +                                */
4613 +                               if (bootverbose) {
4614 +                                       ahd_print_devinfo(ahd, devinfo);
4615 +                                       printf("Echo Buffer unavailable.  "
4616 +                                              "Performing basic DV.\n");
4617 +                               }
4618 +                               targ->flags &= ~AIC_ENHANCED_DV;
4619 +                               targ->flags |= AIC_BASIC_DV;
4620 +                               AHD_SET_DV_STATE(ahd, targ, AIC_DV_STATE_TUR);
4621                                 break;
4622                         }
4623  
4624 @@ -3226,11 +3180,11 @@
4625                 }
4626                 case SS_INQ_REFRESH:
4627                         AHD_SET_DV_STATE(ahd, targ,
4628 -                                        AHD_DV_STATE_INQ_SHORT_ASYNC);
4629 +                                        AIC_DV_STATE_INQ_SHORT_ASYNC);
4630                         break;
4631                 case SS_RETRY:
4632                         AHD_SET_DV_STATE(ahd, targ, targ->dv_state);
4633 -                       if (ahd_cmd_get_transaction_status(cmd)
4634 +                       if (aic_cmd_get_transaction_status(cmd)
4635                          == CAM_REQUEUE_REQ)
4636                                 targ->dv_state_retry--;
4637                         if (targ->dv_state_retry <= 10)
4638 @@ -3249,30 +3203,30 @@
4639                          * and try level 1 DV.
4640                          */
4641                         ahd_linux_filter_inquiry(ahd, devinfo);
4642 -                       AHD_SET_DV_STATE(ahd, targ, AHD_DV_STATE_INQ_VERIFY);
4643 +                       AHD_SET_DV_STATE(ahd, targ, AIC_DV_STATE_INQ_VERIFY);
4644                         targ->dv_echo_size = 0;
4645                         break;
4646                 }
4647                 break;
4648  
4649 -       case AHD_DV_STATE_WEB:
4650 +       case AIC_DV_STATE_WEB:
4651                 switch (status & SS_MASK) {
4652                 case SS_NOP:
4653 -                       AHD_SET_DV_STATE(ahd, targ, AHD_DV_STATE_REB);
4654 +                       AHD_SET_DV_STATE(ahd, targ, AIC_DV_STATE_REB);
4655                         break;
4656                 case SS_INQ_REFRESH:
4657                         AHD_SET_DV_STATE(ahd, targ,
4658 -                                        AHD_DV_STATE_INQ_SHORT_ASYNC);
4659 +                                        AIC_DV_STATE_INQ_SHORT_ASYNC);
4660                         break;
4661                 case SS_RETRY:
4662                         AHD_SET_DV_STATE(ahd, targ, targ->dv_state);
4663 -                       if (ahd_cmd_get_transaction_status(cmd)
4664 +                       if (aic_cmd_get_transaction_status(cmd)
4665                          == CAM_REQUEUE_REQ) {
4666                                 targ->dv_state_retry--;
4667                         } else if ((status & SSQ_FALLBACK) != 0) {
4668                                 if (ahd_linux_dv_fallback(ahd, devinfo) != 0) {
4669                                         AHD_SET_DV_STATE(ahd, targ,
4670 -                                                        AHD_DV_STATE_EXIT);
4671 +                                                        AIC_DV_STATE_EXIT);
4672                                         break;
4673                                 }
4674                                 /*
4675 @@ -3291,22 +3245,22 @@
4676                         }
4677  #endif
4678                 default:
4679 -                       AHD_SET_DV_STATE(ahd, targ, AHD_DV_STATE_EXIT);
4680 +                       AHD_SET_DV_STATE(ahd, targ, AIC_DV_STATE_EXIT);
4681                         break;
4682                 }
4683                 break;
4684  
4685 -       case AHD_DV_STATE_REB:
4686 +       case AIC_DV_STATE_REB:
4687                 switch (status & SS_MASK) {
4688                 case SS_NOP:
4689                         if (memcmp(targ->dv_buffer, targ->dv_buffer1,
4690                                    targ->dv_echo_size) != 0) {
4691                                 if (ahd_linux_dv_fallback(ahd, devinfo) != 0)
4692                                         AHD_SET_DV_STATE(ahd, targ,
4693 -                                                        AHD_DV_STATE_EXIT);
4694 +                                                        AIC_DV_STATE_EXIT);
4695                                 else
4696                                         AHD_SET_DV_STATE(ahd, targ,
4697 -                                                        AHD_DV_STATE_WEB);
4698 +                                                        AIC_DV_STATE_WEB);
4699                                 break;
4700                         }
4701                         
4702 @@ -3318,24 +3272,24 @@
4703                                 free(targ->dv_buffer1, M_DEVBUF);
4704                                 targ->dv_buffer1 = NULL;
4705                         }
4706 -                       AHD_SET_DV_STATE(ahd, targ, AHD_DV_STATE_EXIT);
4707 +                       AHD_SET_DV_STATE(ahd, targ, AIC_DV_STATE_EXIT);
4708                         break;
4709                 case SS_INQ_REFRESH:
4710                         AHD_SET_DV_STATE(ahd, targ,
4711 -                                        AHD_DV_STATE_INQ_SHORT_ASYNC);
4712 +                                        AIC_DV_STATE_INQ_SHORT_ASYNC);
4713                         break;
4714                 case SS_RETRY:
4715                         AHD_SET_DV_STATE(ahd, targ, targ->dv_state);
4716 -                       if (ahd_cmd_get_transaction_status(cmd)
4717 +                       if (aic_cmd_get_transaction_status(cmd)
4718                          == CAM_REQUEUE_REQ) {
4719                                 targ->dv_state_retry--;
4720                         } else if ((status & SSQ_FALLBACK) != 0) {
4721                                 if (ahd_linux_dv_fallback(ahd, devinfo) != 0) {
4722                                         AHD_SET_DV_STATE(ahd, targ,
4723 -                                                        AHD_DV_STATE_EXIT);
4724 +                                                        AIC_DV_STATE_EXIT);
4725                                         break;
4726                                 }
4727 -                               AHD_SET_DV_STATE(ahd, targ, AHD_DV_STATE_WEB);
4728 +                               AHD_SET_DV_STATE(ahd, targ, AIC_DV_STATE_WEB);
4729                         }
4730                         if (targ->dv_state_retry <= 10) {
4731                                 if ((status & (SSQ_DELAY_RANDOM|SSQ_DELAY))!= 0)
4732 @@ -3350,35 +3304,35 @@
4733  #endif
4734                         /* FALLTHROUGH */
4735                 default:
4736 -                       AHD_SET_DV_STATE(ahd, targ, AHD_DV_STATE_EXIT);
4737 +                       AHD_SET_DV_STATE(ahd, targ, AIC_DV_STATE_EXIT);
4738                         break;
4739                 }
4740                 break;
4741  
4742 -       case AHD_DV_STATE_SU:
4743 +       case AIC_DV_STATE_SU:
4744                 switch (status & SS_MASK) {
4745                 case SS_NOP:
4746                 case SS_INQ_REFRESH:
4747                         AHD_SET_DV_STATE(ahd, targ,
4748 -                                        AHD_DV_STATE_INQ_SHORT_ASYNC);
4749 +                                        AIC_DV_STATE_INQ_SHORT_ASYNC);
4750                         break;
4751                 default:
4752 -                       AHD_SET_DV_STATE(ahd, targ, AHD_DV_STATE_EXIT);
4753 +                       AHD_SET_DV_STATE(ahd, targ, AIC_DV_STATE_EXIT);
4754                         break;
4755                 }
4756                 break;
4757  
4758 -       case AHD_DV_STATE_BUSY:
4759 +       case AIC_DV_STATE_BUSY:
4760                 switch (status & SS_MASK) {
4761                 case SS_NOP:
4762                 case SS_INQ_REFRESH:
4763                         AHD_SET_DV_STATE(ahd, targ,
4764 -                                        AHD_DV_STATE_INQ_SHORT_ASYNC);
4765 +                                        AIC_DV_STATE_INQ_SHORT_ASYNC);
4766                         break;
4767                 case SS_TUR:
4768                 case SS_RETRY:
4769                         AHD_SET_DV_STATE(ahd, targ, targ->dv_state);
4770 -                       if (ahd_cmd_get_transaction_status(cmd)
4771 +                       if (aic_cmd_get_transaction_status(cmd)
4772                          == CAM_REQUEUE_REQ) {
4773                                 targ->dv_state_retry--;
4774                         } else if (targ->dv_state_retry < 60) {
4775 @@ -3391,11 +3345,11 @@
4776                                         printf("DV BUSY reties exhausted\n");
4777                                 }
4778  #endif
4779 -                               AHD_SET_DV_STATE(ahd, targ, AHD_DV_STATE_EXIT);
4780 +                               AHD_SET_DV_STATE(ahd, targ, AIC_DV_STATE_EXIT);
4781                         }
4782                         break;
4783                 default:
4784 -                       AHD_SET_DV_STATE(ahd, targ, AHD_DV_STATE_EXIT);
4785 +                       AHD_SET_DV_STATE(ahd, targ, AIC_DV_STATE_EXIT);
4786                         break;
4787                 }
4788                 break;
4789 @@ -3403,7 +3357,7 @@
4790         default:
4791                 printf("%s: Invalid DV completion state %d\n", ahd_name(ahd),
4792                        targ->dv_state);
4793 -               AHD_SET_DV_STATE(ahd, targ, AHD_DV_STATE_EXIT);
4794 +               AHD_SET_DV_STATE(ahd, targ, AIC_DV_STATE_EXIT);
4795                 break;
4796         }
4797  }
4798 @@ -3423,7 +3377,7 @@
4799   */
4800  static void
4801  ahd_linux_dv_inq(struct ahd_softc *ahd, struct scsi_cmnd *cmd,
4802 -                struct ahd_devinfo *devinfo, struct ahd_linux_target *targ,
4803 +                struct ahd_devinfo *devinfo, struct aic_linux_target *targ,
4804                  u_int request_length)
4805  {
4806  
4807 @@ -3436,7 +3390,7 @@
4808         if (targ->inq_data == NULL)
4809                 targ->inq_data = malloc(AHD_LINUX_DV_INQ_LEN,
4810                                         M_DEVBUF, M_WAITOK);
4811 -       if (targ->dv_state > AHD_DV_STATE_INQ_ASYNC) {
4812 +       if (targ->dv_state > AIC_DV_STATE_INQ_ASYNC) {
4813                 if (targ->dv_buffer != NULL)
4814                         free(targ->dv_buffer, M_DEVBUF);
4815                 targ->dv_buffer = malloc(AHD_LINUX_DV_INQ_LEN,
4816 @@ -3449,7 +3403,7 @@
4817         cmd->cmnd[0] = INQUIRY;
4818         cmd->cmnd[4] = request_length;
4819         cmd->request_bufflen = request_length;
4820 -       if (targ->dv_state > AHD_DV_STATE_INQ_ASYNC)
4821 +       if (targ->dv_state > AIC_DV_STATE_INQ_ASYNC)
4822                 cmd->request_buffer = targ->dv_buffer;
4823         else
4824                 cmd->request_buffer = targ->inq_data;
4825 @@ -3478,7 +3432,7 @@
4826  
4827  static void
4828  ahd_linux_dv_rebd(struct ahd_softc *ahd, struct scsi_cmnd *cmd,
4829 -                struct ahd_devinfo *devinfo, struct ahd_linux_target *targ)
4830 +                struct ahd_devinfo *devinfo, struct aic_linux_target *targ)
4831  {
4832  
4833  #ifdef AHD_DEBUG
4834 @@ -3503,7 +3457,7 @@
4835  
4836  static void
4837  ahd_linux_dv_web(struct ahd_softc *ahd, struct scsi_cmnd *cmd,
4838 -                struct ahd_devinfo *devinfo, struct ahd_linux_target *targ)
4839 +                struct ahd_devinfo *devinfo, struct aic_linux_target *targ)
4840  {
4841  
4842  #ifdef AHD_DEBUG
4843 @@ -3525,7 +3479,7 @@
4844  
4845  static void
4846  ahd_linux_dv_reb(struct ahd_softc *ahd, struct scsi_cmnd *cmd,
4847 -                struct ahd_devinfo *devinfo, struct ahd_linux_target *targ)
4848 +                struct ahd_devinfo *devinfo, struct aic_linux_target *targ)
4849  {
4850  
4851  #ifdef AHD_DEBUG
4852 @@ -3548,7 +3502,7 @@
4853  static void
4854  ahd_linux_dv_su(struct ahd_softc *ahd, struct scsi_cmnd *cmd,
4855                 struct ahd_devinfo *devinfo,
4856 -               struct ahd_linux_target *targ)
4857 +               struct aic_linux_target *targ)
4858  {
4859         u_int le;
4860  
4861 @@ -3583,7 +3537,7 @@
4862  static int
4863  ahd_linux_fallback(struct ahd_softc *ahd, struct ahd_devinfo *devinfo)
4864  {
4865 -       struct  ahd_linux_target *targ;
4866 +       struct  aic_linux_target *targ;
4867         struct  ahd_initiator_tinfo *tinfo;
4868         struct  ahd_transinfo *goal;
4869         struct  ahd_tmode_tstate *tstate;
4870 @@ -3754,7 +3708,7 @@
4871         return (0);
4872  }
4873  
4874 -static void
4875 +void
4876  ahd_linux_dv_timeout(struct scsi_cmnd *cmd)
4877  {
4878         struct  ahd_softc *ahd;
4879 @@ -3788,29 +3742,18 @@
4880          * error code.
4881          */
4882         if ((scb->flags & SCB_SENSE) != 0)
4883 -               ahd_set_transaction_status(scb, CAM_AUTOSENSE_FAIL);
4884 +               aic_set_transaction_status(scb, CAM_AUTOSENSE_FAIL);
4885         else
4886 -               ahd_set_transaction_status(scb, CAM_CMD_TIMEOUT);
4887 +               aic_set_transaction_status(scb, CAM_CMD_TIMEOUT);
4888         ahd_reset_channel(ahd, cmd->device->channel + 'A', /*initiate*/TRUE);
4889  
4890 -       /*
4891 -        * Add a minimal bus settle delay for devices that are slow to
4892 -        * respond after bus resets.
4893 -        */
4894 -       ahd_freeze_simq(ahd);
4895 -       init_timer(&ahd->platform_data->reset_timer);
4896 -       ahd->platform_data->reset_timer.data = (u_long)ahd;
4897 -       ahd->platform_data->reset_timer.expires = jiffies + HZ / 2;
4898 -       ahd->platform_data->reset_timer.function =
4899 -           (ahd_linux_callback_t *)ahd_release_simq;
4900 -       add_timer(&ahd->platform_data->reset_timer);
4901 -       if (ahd_linux_next_device_to_run(ahd) != NULL)
4902 -               ahd_schedule_runq(ahd);
4903 +       if (aic_linux_next_device_to_run(ahd) != NULL)
4904 +               aic_schedule_runq(ahd);
4905         ahd_linux_run_complete_queue(ahd);
4906         ahd_unlock(ahd, &flags);
4907  }
4908  
4909 -static void
4910 +void
4911  ahd_linux_dv_complete(struct scsi_cmnd *cmd)
4912  {
4913         struct ahd_softc *ahd;
4914 @@ -3832,7 +3775,7 @@
4915  }
4916  
4917  static void
4918 -ahd_linux_generate_dv_pattern(struct ahd_linux_target *targ)
4919 +ahd_linux_generate_dv_pattern(struct aic_linux_target *targ)
4920  {
4921         uint16_t b;
4922         u_int    i;
4923 @@ -3998,8 +3941,8 @@
4924   * Determines the queue depth for a given device.
4925   */
4926  static void
4927 -ahd_linux_device_queue_depth(struct ahd_softc *ahd,
4928 -                            struct ahd_linux_device *dev)
4929 +aic_linux_device_queue_depth(struct ahd_softc *ahd,
4930 +                            struct aic_linux_device *dev)
4931  {
4932         struct  ahd_devinfo devinfo;
4933         u_int   tags;
4934 @@ -4022,10 +3965,10 @@
4935         }
4936  }
4937  
4938 -static void
4939 -ahd_linux_run_device_queue(struct ahd_softc *ahd, struct ahd_linux_device *dev)
4940 +void
4941 +ahd_linux_run_device_queue(struct ahd_softc *ahd, struct aic_linux_device *dev)
4942  {
4943 -       struct   ahd_cmd *acmd;
4944 +       struct   aic_cmd *acmd;
4945         struct   scsi_cmnd *cmd;
4946         struct   scb *scb;
4947         struct   hardware_scb *hscb;
4948 @@ -4034,7 +3977,7 @@
4949         u_int    col_idx;
4950         uint16_t mask;
4951  
4952 -       if ((dev->flags & AHD_DEV_ON_RUN_LIST) != 0)
4953 +       if ((dev->flags & AIC_DEV_ON_RUN_LIST) != 0)
4954                 panic("running device on run list");
4955  
4956         while ((acmd = TAILQ_FIRST(&dev->busyq)) != NULL
4957 @@ -4045,11 +3988,11 @@
4958                  * running is because the whole controller Q is frozen.
4959                  */
4960                 if (ahd->platform_data->qfrozen != 0
4961 -                && AHD_DV_SIMQ_FROZEN(ahd) == 0) {
4962 +                && AIC_DV_SIMQ_FROZEN(ahd) == 0) {
4963  
4964                         TAILQ_INSERT_TAIL(&ahd->platform_data->device_runq,
4965                                           dev, links);
4966 -                       dev->flags |= AHD_DEV_ON_RUN_LIST;
4967 +                       dev->flags |= AIC_DEV_ON_RUN_LIST;
4968                         return;
4969                 }
4970  
4971 @@ -4060,7 +4003,7 @@
4972                  */
4973                 tinfo = ahd_fetch_transinfo(ahd, 'A', ahd->our_id,
4974                                             cmd->device->id, &tstate);
4975 -               if ((dev->flags & (AHD_DEV_Q_TAGGED|AHD_DEV_Q_BASIC)) == 0
4976 +               if ((dev->flags & (AIC_DEV_Q_TAGGED|AIC_DEV_Q_BASIC)) == 0
4977                  || (tinfo->curr.ppr_options & MSG_EXT_PPR_IU_REQ) != 0) {
4978                         col_idx = AHD_NEVER_COL_IDX;
4979                 } else {
4980 @@ -4070,13 +4013,14 @@
4981                 if ((scb = ahd_get_scb(ahd, col_idx)) == NULL) {
4982                         TAILQ_INSERT_TAIL(&ahd->platform_data->device_runq,
4983                                          dev, links);
4984 -                       dev->flags |= AHD_DEV_ON_RUN_LIST;
4985 +                       dev->flags |= AIC_DEV_ON_RUN_LIST;
4986                         ahd->flags |= AHD_RESOURCE_SHORTAGE;
4987                         return;
4988                 }
4989                 TAILQ_REMOVE(&dev->busyq, acmd, acmd_links.tqe);
4990                 scb->io_ctx = cmd;
4991                 scb->platform_data->dev = dev;
4992 +               scb->platform_data->flags = 0;
4993                 hscb = scb->hscb;
4994                 cmd->host_scribble = (char *)scb;
4995  
4996 @@ -4092,7 +4036,7 @@
4997                 if ((ahd->user_discenable & mask) != 0)
4998                         hscb->control |= DISCENB;
4999  
5000 -               if (AHD_DV_CMD(cmd) != 0)
5001 +               if (AIC_DV_CMD(cmd) != 0)
5002                         scb->flags |= SCB_SILENT;
5003  
5004                 if ((tinfo->curr.ppr_options & MSG_EXT_PPR_IU_REQ) != 0)
5005 @@ -4103,7 +4047,7 @@
5006                         scb->hscb->control |= MK_MESSAGE;
5007                 }
5008  
5009 -               if ((dev->flags & (AHD_DEV_Q_TAGGED|AHD_DEV_Q_BASIC)) != 0) {
5010 +               if ((dev->flags & (AIC_DEV_Q_TAGGED|AIC_DEV_Q_BASIC)) != 0) {
5011  #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,0)
5012                         int     msg_bytes;
5013                         uint8_t tag_msgs[2];
5014 @@ -4115,8 +4059,8 @@
5015                                         dev->commands_since_idle_or_otag = 0;
5016                         } else
5017  #endif
5018 -                       if (dev->commands_since_idle_or_otag == AHD_OTAG_THRESH
5019 -                        && (dev->flags & AHD_DEV_Q_TAGGED) != 0) {
5020 +                       if (dev->commands_since_idle_or_otag == AIC_OTAG_THRESH
5021 +                        && (dev->flags & AIC_DEV_Q_TAGGED) != 0) {
5022                                 hscb->control |= MSG_ORDERED_TASK;
5023                                 dev->commands_since_idle_or_otag = 0;
5024                         } else {
5025 @@ -4128,8 +4072,9 @@
5026                 memcpy(hscb->shared_data.idata.cdb, cmd->cmnd, hscb->cdb_len);
5027  
5028                 scb->sg_count = 0;
5029 -               ahd_set_residual(scb, 0);
5030 -               ahd_set_sense_residual(scb, 0);
5031 +               aic_set_residual(scb, 0);
5032 +               aic_set_sense_residual(scb, 0);
5033 +               scb->platform_data->xfer_len = 0;
5034                 if (cmd->use_sg != 0) {
5035                         void    *sg;
5036                         struct   scatterlist *cur_seg;
5037 @@ -4138,18 +4083,15 @@
5038  
5039                         cur_seg = (struct scatterlist *)cmd->request_buffer;
5040                         dir = scsi_to_pci_dma_dir(cmd->sc_data_direction);
5041 -                       nseg = pci_map_sg(ahd->dev_softc, cur_seg,
5042 -                                         cmd->use_sg, dir);
5043 -                       scb->platform_data->xfer_len = 0;
5044 +                       nseg = aic_map_sg(ahd, cur_seg, cmd->use_sg, dir);
5045                         for (sg = scb->sg_list; nseg > 0; nseg--, cur_seg++) {
5046                                 bus_addr_t addr;
5047                                 bus_size_t len;
5048  
5049                                 addr = sg_dma_address(cur_seg);
5050                                 len = sg_dma_len(cur_seg);
5051 -                               scb->platform_data->xfer_len += len;
5052 -                               sg = ahd_sg_setup(ahd, scb, sg, addr, len,
5053 -                                                 /*last*/nseg == 1);
5054 +                               sg = ahd_linux_sg_setup(ahd, scb, sg, addr, len,
5055 +                                                       /*last*/nseg == 1);
5056                         }
5057                 } else if (cmd->request_bufflen != 0) {
5058                         void *sg;
5059 @@ -4158,13 +4100,13 @@
5060  
5061                         sg = scb->sg_list;
5062                         dir = scsi_to_pci_dma_dir(cmd->sc_data_direction);
5063 -                       addr = pci_map_single(ahd->dev_softc,
5064 +                       addr = aic_map_single(ahd,
5065                                               cmd->request_buffer,
5066                                               cmd->request_bufflen, dir);
5067 -                       scb->platform_data->xfer_len = cmd->request_bufflen;
5068                         scb->platform_data->buf_busaddr = addr;
5069 -                       sg = ahd_sg_setup(ahd, scb, sg, addr,
5070 -                                         cmd->request_bufflen, /*last*/TRUE);
5071 +                       sg = ahd_linux_sg_setup(ahd, scb, sg, addr,
5072 +                                               cmd->request_bufflen,
5073 +                                               /*last*/TRUE);
5074                 }
5075  
5076                 LIST_INSERT_HEAD(&ahd->pending_scbs, scb, pending_links);
5077 @@ -4180,9 +4122,10 @@
5078                                 dev->target->cmds_since_error = 0;
5079                 }
5080  
5081 -               if ((dev->flags & AHD_DEV_PERIODIC_OTAG) != 0)
5082 +               if ((dev->flags & AIC_DEV_PERIODIC_OTAG) != 0)
5083                         dev->commands_since_idle_or_otag++;
5084                 scb->flags |= SCB_ACTIVE;
5085 +               aic_scb_timer_start(scb);
5086                 ahd_queue_scb(ahd, scb);
5087         }
5088  }
5089 @@ -4200,8 +4143,8 @@
5090         ahd = (struct ahd_softc *) dev_id;
5091         ahd_lock(ahd, &flags); 
5092         ours = ahd_intr(ahd);
5093 -       if (ahd_linux_next_device_to_run(ahd) != NULL)
5094 -               ahd_schedule_runq(ahd);
5095 +       if (aic_linux_next_device_to_run(ahd) != NULL)
5096 +               aic_schedule_runq(ahd);
5097         ahd_linux_run_complete_queue(ahd);
5098         ahd_unlock(ahd, &flags);
5099         return IRQ_RETVAL(ours);
5100 @@ -4215,10 +4158,10 @@
5101                 ;
5102  }
5103  
5104 -static struct ahd_linux_target*
5105 +static struct aic_linux_target*
5106  ahd_linux_alloc_target(struct ahd_softc *ahd, u_int channel, u_int target)
5107  {
5108 -       struct ahd_linux_target *targ;
5109 +       struct aic_linux_target *targ;
5110  
5111         targ = malloc(sizeof(*targ), M_DEVBUF, M_NOWAIT);
5112         if (targ == NULL)
5113 @@ -4226,14 +4169,14 @@
5114         memset(targ, 0, sizeof(*targ));
5115         targ->channel = channel;
5116         targ->target = target;
5117 -       targ->ahd = ahd;
5118 -       targ->flags = AHD_DV_REQUIRED;
5119 +       targ->softc = ahd;
5120 +       targ->flags = AIC_DV_REQUIRED;
5121         ahd->platform_data->targets[target] = targ;
5122         return (targ);
5123  }
5124  
5125  static void
5126 -ahd_linux_free_target(struct ahd_softc *ahd, struct ahd_linux_target *targ)
5127 +ahd_linux_free_target(struct ahd_softc *ahd, struct aic_linux_target *targ)
5128  {
5129         struct ahd_devinfo devinfo;
5130         struct ahd_initiator_tinfo *tinfo;
5131 @@ -4269,11 +4212,11 @@
5132         free(targ, M_DEVBUF);
5133  }
5134  
5135 -static struct ahd_linux_device*
5136 +static struct aic_linux_device*
5137  ahd_linux_alloc_device(struct ahd_softc *ahd,
5138 -                struct ahd_linux_target *targ, u_int lun)
5139 +                struct aic_linux_target *targ, u_int lun)
5140  {
5141 -       struct ahd_linux_device *dev;
5142 +       struct aic_linux_device *dev;
5143  
5144         dev = malloc(sizeof(*dev), M_DEVBUG, M_NOWAIT);
5145         if (dev == NULL)
5146 @@ -4281,7 +4224,7 @@
5147         memset(dev, 0, sizeof(*dev));
5148         init_timer(&dev->timer);
5149         TAILQ_INIT(&dev->busyq);
5150 -       dev->flags = AHD_DEV_UNCONFIGURED;
5151 +       dev->flags = AIC_DEV_UNCONFIGURED;
5152         dev->lun = lun;
5153         dev->target = targ;
5154  
5155 @@ -4304,9 +4247,9 @@
5156  }
5157  
5158  static void
5159 -ahd_linux_free_device(struct ahd_softc *ahd, struct ahd_linux_device *dev)
5160 +ahd_linux_free_device(struct ahd_softc *ahd, struct aic_linux_device *dev)
5161  {
5162 -       struct ahd_linux_target *targ;
5163 +       struct aic_linux_target *targ;
5164  
5165         del_timer(&dev->timer);
5166         targ = dev->target;
5167 @@ -4314,7 +4257,7 @@
5168         free(dev, M_DEVBUF);
5169         targ->refcount--;
5170         if (targ->refcount == 0
5171 -        && (targ->flags & AHD_DV_REQUIRED) == 0)
5172 +        && (targ->flags & AIC_DV_REQUIRED) == 0)
5173                 ahd_linux_free_target(ahd, targ);
5174  }
5175  
5176 @@ -4326,7 +4269,7 @@
5177         case AC_TRANSFER_NEG:
5178         {
5179                 char    buf[80];
5180 -               struct  ahd_linux_target *targ;
5181 +               struct  aic_linux_target *targ;
5182                 struct  info_str info;
5183                 struct  ahd_initiator_tinfo *tinfo;
5184                 struct  ahd_tmode_tstate *tstate;
5185 @@ -4414,6 +4357,20 @@
5186                                               channel - 'A');
5187                 }
5188  #endif
5189 +               /*
5190 +                * Add a minimal bus settle delay for devices that are slow to
5191 +                * respond after bus resets.
5192 +                */
5193 +               if ((ahd->platform_data->flags & AIC_BUS_SETTLE_TIMER) == 0) {
5194 +                       aic_freeze_simq(ahd);
5195 +                       ahd->platform_data->flags |= AIC_BUS_SETTLE_TIMER;
5196 +                       ahd->platform_data->bus_settle_timer.expires =
5197 +                           jiffies + (AIC79XX_RESET_DELAY * HZ)/1000;
5198 +                       add_timer(&ahd->platform_data->bus_settle_timer);
5199 +               } else {
5200 +                       mod_timer(&ahd->platform_data->bus_settle_timer,
5201 +                                 jiffies + (AIC79XX_RESET_DELAY * HZ)/1000);
5202 +               }
5203                  break;
5204          default:
5205                  panic("ahd_send_async: Unexpected async event");
5206 @@ -4427,14 +4384,18 @@
5207  ahd_done(struct ahd_softc *ahd, struct scb *scb)
5208  {
5209         Scsi_Cmnd *cmd;
5210 -       struct    ahd_linux_device *dev;
5211 +       struct    aic_linux_device *dev;
5212  
5213         if ((scb->flags & SCB_ACTIVE) == 0) {
5214                 printf("SCB %d done'd twice\n", SCB_GET_TAG(scb));
5215                 ahd_dump_card_state(ahd);
5216                 panic("Stopping for safety");
5217         }
5218 +
5219         LIST_REMOVE(scb, pending_links);
5220 +       if ((scb->flags & SCB_TIMEDOUT) != 0)
5221 +               LIST_REMOVE(scb, timedout_links);
5222 +
5223         cmd = scb->io_ctx;
5224         dev = scb->platform_data->dev;
5225         dev->active--;
5226 @@ -4452,11 +4413,11 @@
5227          * the sense buffer looks "sane".
5228          */
5229         cmd->sense_buffer[0] = 0;
5230 -       if (ahd_get_transaction_status(scb) == CAM_REQ_INPROG) {
5231 +       if (aic_get_transaction_status(scb) == CAM_REQ_INPROG) {
5232                 uint32_t amount_xferred;
5233  
5234                 amount_xferred =
5235 -                   ahd_get_transfer_length(scb) - ahd_get_residual(scb);
5236 +                   aic_get_transfer_length(scb) - aic_get_residual(scb);
5237                 if ((scb->flags & SCB_TRANSMISSION_ERROR) != 0) {
5238  #ifdef AHD_DEBUG
5239                         if ((ahd_debug & AHD_SHOW_MISC) != 0) {
5240 @@ -4464,7 +4425,17 @@
5241                                 printf("Set CAM_UNCOR_PARITY\n");
5242                         }
5243  #endif
5244 -                       ahd_set_transaction_status(scb, CAM_UNCOR_PARITY);
5245 +                       aic_set_transaction_status(scb, CAM_UNCOR_PARITY);
5246 +#ifdef AHD_REPORT_UNDERFLOWS
5247 +               /*
5248 +                * This code is disabled by default as some
5249 +                * clients of the SCSI system do not properly
5250 +                * initialize the underflow parameter.  This
5251 +                * results in spurious termination of commands
5252 +                * that complete as expected (e.g. underflow is
5253 +                * allowed as command can return variable amounts
5254 +                * of data.
5255 +                */
5256                 } else if (amount_xferred < scb->io_ctx->underflow) {
5257                         u_int i;
5258  
5259 @@ -4476,30 +4447,31 @@
5260                         ahd_print_path(ahd, scb);
5261                         printf("Saw underflow (%ld of %ld bytes). "
5262                                "Treated as error\n",
5263 -                               ahd_get_residual(scb),
5264 -                               ahd_get_transfer_length(scb));
5265 -                       ahd_set_transaction_status(scb, CAM_DATA_RUN_ERR);
5266 +                               aic_get_residual(scb),
5267 +                               aic_get_transfer_length(scb));
5268 +                       aic_set_transaction_status(scb, CAM_DATA_RUN_ERR);
5269 +#endif
5270                 } else {
5271 -                       ahd_set_transaction_status(scb, CAM_REQ_CMP);
5272 +                       aic_set_transaction_status(scb, CAM_REQ_CMP);
5273                 }
5274 -       } else if (ahd_get_transaction_status(scb) == CAM_SCSI_STATUS_ERROR) {
5275 +       } else if (aic_get_transaction_status(scb) == CAM_SCSI_STATUS_ERROR) {
5276                 ahd_linux_handle_scsi_status(ahd, dev, scb);
5277 -       } else if (ahd_get_transaction_status(scb) == CAM_SEL_TIMEOUT) {
5278 -               dev->flags |= AHD_DEV_UNCONFIGURED;
5279 -               if (AHD_DV_CMD(cmd) == FALSE)
5280 -                       dev->target->flags &= ~AHD_DV_REQUIRED;
5281 +       } else if (aic_get_transaction_status(scb) == CAM_SEL_TIMEOUT) {
5282 +               dev->flags |= AIC_DEV_UNCONFIGURED;
5283 +               if (AIC_DV_CMD(cmd) == FALSE)
5284 +                       dev->target->flags &= ~AIC_DV_REQUIRED;
5285         }
5286         /*
5287          * Start DV for devices that require it assuming the first command
5288          * sent does not result in a selection timeout.
5289          */
5290 -       if (ahd_get_transaction_status(scb) != CAM_SEL_TIMEOUT
5291 -        && (dev->target->flags & AHD_DV_REQUIRED) != 0)
5292 +       if (aic_get_transaction_status(scb) != CAM_SEL_TIMEOUT
5293 +        && (dev->target->flags & AIC_DV_REQUIRED) != 0)
5294                 ahd_linux_start_dv(ahd);
5295  
5296         if (dev->openings == 1
5297 -        && ahd_get_transaction_status(scb) == CAM_REQ_CMP
5298 -        && ahd_get_scsi_status(scb) != SCSI_STATUS_QUEUE_FULL)
5299 +        && aic_get_transaction_status(scb) == CAM_REQ_CMP
5300 +        && aic_get_scsi_status(scb) != SCSI_STATUS_QUEUE_FULL)
5301                 dev->tag_success_count++;
5302         /*
5303          * Some devices deal with temporary internal resource
5304 @@ -4508,7 +4480,7 @@
5305          * back to our previous queue depth.
5306          */
5307         if ((dev->openings + dev->active) < dev->maxtags
5308 -        && dev->tag_success_count > AHD_TAG_SUCCESS_INTERVAL) {
5309 +        && dev->tag_success_count > AIC_TAG_SUCCESS_INTERVAL) {
5310                 dev->tag_success_count = 0;
5311                 dev->openings++;
5312         }
5313 @@ -4517,39 +4489,68 @@
5314                 dev->commands_since_idle_or_otag = 0;
5315  
5316         if (TAILQ_EMPTY(&dev->busyq)) {
5317 -               if ((dev->flags & AHD_DEV_UNCONFIGURED) != 0
5318 -                && dev->active == 0
5319 -                && (dev->flags & AHD_DEV_TIMER_ACTIVE) == 0)
5320 +               if ((dev->flags & AIC_DEV_UNCONFIGURED) != 0
5321 +                && dev->active == 0)
5322                         ahd_linux_free_device(ahd, dev);
5323 -       } else if ((dev->flags & AHD_DEV_ON_RUN_LIST) == 0) {
5324 +       } else if ((dev->flags & AIC_DEV_ON_RUN_LIST) == 0) {
5325                 TAILQ_INSERT_TAIL(&ahd->platform_data->device_runq, dev, links);
5326 -               dev->flags |= AHD_DEV_ON_RUN_LIST;
5327 +               dev->flags |= AIC_DEV_ON_RUN_LIST;
5328         }
5329  
5330         if ((scb->flags & SCB_RECOVERY_SCB) != 0) {
5331                 printf("Recovery SCB completes\n");
5332 -               if (ahd_get_transaction_status(scb) == CAM_BDR_SENT
5333 -                || ahd_get_transaction_status(scb) == CAM_REQ_ABORTED)
5334 -                       ahd_set_transaction_status(scb, CAM_CMD_TIMEOUT);
5335 -               if ((scb->platform_data->flags & AHD_SCB_UP_EH_SEM) != 0) {
5336 -                       scb->platform_data->flags &= ~AHD_SCB_UP_EH_SEM;
5337 +               if (aic_get_transaction_status(scb) == CAM_BDR_SENT
5338 +                || aic_get_transaction_status(scb) == CAM_REQ_ABORTED)
5339 +                       aic_set_transaction_status(scb, CAM_CMD_TIMEOUT);
5340 +               if ((scb->platform_data->flags & AIC_SCB_UP_EH_SEM) != 0) {
5341 +                       scb->platform_data->flags &= ~AIC_SCB_UP_EH_SEM;
5342                         up(&ahd->platform_data->eh_sem);
5343 +               } else {
5344 +                       struct  scb *list_scb;
5345 +
5346 +                       /*
5347 +                        * We were able to complete the command successfully,
5348 +                        * so reinstate the timeouts for all other pending
5349 +                        * commands.
5350 +                        */
5351 +                       LIST_FOREACH(list_scb,
5352 +                                    &ahd->pending_scbs, pending_links) {
5353 +
5354 +                               aic_scb_timer_start(list_scb);
5355 +                       }
5356                 }
5357         }
5358  
5359 +       if ((scb->platform_data->flags & AIC_TIMEOUT_ACTIVE) == 0) {
5360 +               /*
5361 +                * The completion handler believes that
5362 +                * commands without active timers running
5363 +                * have lost the race of completing before
5364 +                * their timer expires.  Since commands in
5365 +                * our busy queues do not have timers running,
5366 +                * appease the mid-layer by adding a timer
5367 +                * now.  This timer will be immediately
5368 +                * canceled by the midlayer.
5369 +                */
5370 +               scsi_add_timer(cmd, 60*HZ, aic_linux_midlayer_timeout);
5371 +       }
5372 +
5373 +       if ((scb->platform_data->flags & AIC_RELEASE_SIMQ) != 0)
5374 +               aic_release_simq_locked(ahd);
5375 +
5376         ahd_free_scb(ahd, scb);
5377         ahd_linux_queue_cmd_complete(ahd, cmd);
5378  
5379 -       if ((ahd->platform_data->flags & AHD_DV_WAIT_SIMQ_EMPTY) != 0
5380 +       if ((ahd->platform_data->flags & AIC_DV_WAIT_SIMQ_EMPTY) != 0
5381          && LIST_FIRST(&ahd->pending_scbs) == NULL) {
5382 -               ahd->platform_data->flags &= ~AHD_DV_WAIT_SIMQ_EMPTY;
5383 +               ahd->platform_data->flags &= ~AIC_DV_WAIT_SIMQ_EMPTY;
5384                 up(&ahd->platform_data->dv_sem);
5385         }
5386  }
5387  
5388  static void
5389  ahd_linux_handle_scsi_status(struct ahd_softc *ahd,
5390 -                            struct ahd_linux_device *dev, struct scb *scb)
5391 +                            struct aic_linux_device *dev, struct scb *scb)
5392  {
5393         struct  ahd_devinfo devinfo;
5394  
5395 @@ -4569,7 +4570,7 @@
5396          * we don't clobber the device with too many
5397          * commands.
5398          */
5399 -       switch (ahd_get_scsi_status(scb)) {
5400 +       switch (aic_get_scsi_status(scb)) {
5401         default:
5402                 break;
5403         case SCSI_STATUS_CHECK_COND:
5404 @@ -4583,13 +4584,15 @@
5405                  */
5406                 cmd = scb->io_ctx;
5407                 if ((scb->flags & (SCB_SENSE|SCB_PKT_SENSE)) != 0) {
5408 -                       struct scsi_status_iu_header *siu;
5409 -                       u_int sense_size;
5410 -                       u_int sense_offset;
5411 +                       struct  scsi_status_iu_header *siu;
5412 +                       struct  scsi_sense_data *sense;
5413 +                       u_int   sense_size;
5414 +                       u_int   sense_offset;
5415 +                       int     error_code, sense_key, asc, ascq;
5416  
5417                         if (scb->flags & SCB_SENSE) {
5418                                 sense_size = MIN(sizeof(struct scsi_sense_data)
5419 -                                              - ahd_get_sense_residual(scb),
5420 +                                              - aic_get_sense_residual(scb),
5421                                                  sizeof(cmd->sense_buffer));
5422                                 sense_offset = 0;
5423                         } else {
5424 @@ -4604,10 +4607,10 @@
5425                                 sense_offset = SIU_SENSE_OFFSET(siu);
5426                         }
5427  
5428 +                       sense = (struct scsi_sense_data *)
5429 +                           (ahd_get_sense_buf(ahd, scb) + sense_offset);
5430                         memset(cmd->sense_buffer, 0, sizeof(cmd->sense_buffer));
5431 -                       memcpy(cmd->sense_buffer,
5432 -                              ahd_get_sense_buf(ahd, scb)
5433 -                              + sense_offset, sense_size);
5434 +                       memcpy(cmd->sense_buffer, sense, sense_size);
5435                         cmd->result |= (DRIVER_SENSE << 24);
5436  
5437  #ifdef AHD_DEBUG
5438 @@ -4624,6 +4627,23 @@
5439                                 printf("\n");
5440                         }
5441  #endif
5442 +                       /*
5443 +                        * If this is not a DV command and the target
5444 +                        * provides some status that makes us believe
5445 +                        * that the target has changed (power on reset,
5446 +                        * etc.) kick off a DV scan to re-validate the
5447 +                        * device.
5448 +                        */
5449 +                       if (AIC_DV_CMD(cmd) != 0)
5450 +                               break;
5451 +
5452 +                       scsi_extract_sense(sense, &error_code,
5453 +                                          &sense_key, &asc, &ascq);
5454 +                       if (error_code == SSD_CURRENT_ERROR
5455 +                        && sense_key == SSD_KEY_UNIT_ATTENTION
5456 +                        && asc == 0x29
5457 +                        && (ascq == 0 || ascq == 1))
5458 +                               dev->target->flags |= AIC_DV_REQUIRED;
5459                 }
5460                 break;
5461         }
5462 @@ -4663,7 +4683,7 @@
5463                                  * this device.
5464                                  */
5465                                 if (dev->last_queuefull_same_count
5466 -                                == AHD_LOCK_TAGS_COUNT) {
5467 +                                == AIC_LOCK_TAGS_COUNT) {
5468                                         dev->maxtags = dev->active;
5469                                         ahd_print_path(ahd, scb);
5470                                         printf("Locking max tag count at %d\n",
5471 @@ -4673,10 +4693,10 @@
5472                                 dev->tags_on_last_queuefull = dev->active;
5473                                 dev->last_queuefull_same_count = 0;
5474                         }
5475 -                       ahd_set_transaction_status(scb, CAM_REQUEUE_REQ);
5476 -                       ahd_set_scsi_status(scb, SCSI_STATUS_OK);
5477 +                       aic_set_transaction_status(scb, CAM_REQUEUE_REQ);
5478 +                       aic_set_scsi_status(scb, SCSI_STATUS_OK);
5479                         ahd_platform_set_tags(ahd, &devinfo,
5480 -                                    (dev->flags & AHD_DEV_Q_BASIC)
5481 +                                    (dev->flags & AIC_DEV_Q_BASIC)
5482                                    ? AHD_QUEUE_BASIC : AHD_QUEUE_TAGGED);
5483                         break;
5484                 }
5485 @@ -4686,9 +4706,9 @@
5486                  */
5487                 dev->openings = 1;
5488                 ahd_platform_set_tags(ahd, &devinfo,
5489 -                            (dev->flags & AHD_DEV_Q_BASIC)
5490 +                            (dev->flags & AIC_DEV_Q_BASIC)
5491                            ? AHD_QUEUE_BASIC : AHD_QUEUE_TAGGED);
5492 -               ahd_set_scsi_status(scb, SCSI_STATUS_BUSY);
5493 +               aic_set_scsi_status(scb, SCSI_STATUS_BUSY);
5494                 /* FALLTHROUGH */
5495         }
5496         case SCSI_STATUS_BUSY:
5497 @@ -4696,13 +4716,13 @@
5498                  * Set a short timer to defer sending commands for
5499                  * a bit since Linux will not delay in this case.
5500                  */
5501 -               if ((dev->flags & AHD_DEV_TIMER_ACTIVE) != 0) {
5502 +               if ((dev->flags & AIC_DEV_TIMER_ACTIVE) != 0) {
5503                         printf("%s:%c:%d: Device Timer still active during "
5504                                "busy processing\n", ahd_name(ahd),
5505                                 dev->target->channel, dev->target->target);
5506                         break;
5507                 }
5508 -               dev->flags |= AHD_DEV_TIMER_ACTIVE;
5509 +               dev->flags |= AIC_DEV_TIMER_ACTIVE;
5510                 dev->qfrozen++;
5511                 init_timer(&dev->timer);
5512                 dev->timer.data = (u_long)dev;
5513 @@ -4728,9 +4748,9 @@
5514          * not guarantee the order that aborted commands will be
5515          * returned to us.
5516          */
5517 -       struct ahd_completeq *completeq;
5518 -       struct ahd_cmd *list_cmd;
5519 -       struct ahd_cmd *acmd;
5520 +       struct aic_completeq *completeq;
5521 +       struct aic_cmd *list_cmd;
5522 +       struct aic_cmd *acmd;
5523  
5524         /*
5525          * Map CAM error codes into Linux Error codes.  We
5526 @@ -4738,13 +4758,13 @@
5527          * full error information available when making
5528          * state change decisions.
5529          */
5530 -       if (AHD_DV_CMD(cmd) == FALSE) {
5531 +       if (AIC_DV_CMD(cmd) == FALSE) {
5532                 uint32_t status;
5533                 u_int new_status;
5534  
5535 -               status = ahd_cmd_get_transaction_status(cmd);
5536 +               status = aic_cmd_get_transaction_status(cmd);
5537                 if (status != CAM_REQ_CMP) {
5538 -                       struct ahd_linux_device *dev;
5539 +                       struct aic_linux_device *dev;
5540                         struct ahd_devinfo devinfo;
5541                         cam_status cam_status;
5542                         uint32_t action;
5543 @@ -4764,8 +4784,8 @@
5544                                             dev->target->channel == 0 ? 'A':'B',
5545                                             ROLE_INITIATOR);
5546  
5547 -                       scsi_status = ahd_cmd_get_scsi_status(cmd);
5548 -                       cam_status = ahd_cmd_get_transaction_status(cmd);
5549 +                       scsi_status = aic_cmd_get_scsi_status(cmd);
5550 +                       cam_status = aic_cmd_get_transaction_status(cmd);
5551                         action = aic_error_action(cmd, dev->target->inq_data,
5552                                                   cam_status, scsi_status);
5553                         if ((action & SSQ_FALLBACK) != 0) {
5554 @@ -4808,7 +4828,17 @@
5555                         new_status = DID_PARITY;
5556                         break;
5557                 case CAM_CMD_TIMEOUT:
5558 -                       new_status = DID_TIME_OUT;
5559 +                       /*
5560 +                        *  Returning DID_TIME_OUT will 
5561 +                        *  wake up the error recovery
5562 +                        *  thread instead of doing the
5563 +                        *  command retry we desire. Since
5564 +                        *  we have already recovered the
5565 +                        *  command, returning DID_ERROR
5566 +                        *  will cause a retry up to the
5567 +                        *  retry limit for this command.
5568 +                        */
5569 +                       new_status = DID_ERROR;
5570                         break;
5571                 case CAM_UA_ABORT:
5572                 case CAM_REQ_CMP_ERR:
5573 @@ -4838,7 +4868,7 @@
5574                         if (cmd->retries > 0)
5575                                 cmd->retries--;
5576                         new_status = DID_OK;
5577 -                       ahd_cmd_set_scsi_status(cmd, SCSI_STATUS_CHECK_COND);
5578 +                       aic_cmd_set_scsi_status(cmd, SCSI_STATUS_CHECK_COND);
5579                         cmd->result |= (DRIVER_SENSE << 24);
5580                         memset(cmd->sense_buffer, 0,
5581                                sizeof(cmd->sense_buffer));
5582 @@ -4852,12 +4882,12 @@
5583                         break;
5584                 }
5585  
5586 -               ahd_cmd_set_transaction_status(cmd, new_status);
5587 +               aic_cmd_set_transaction_status(cmd, new_status);
5588         }
5589  
5590         completeq = &ahd->platform_data->completeq;
5591         list_cmd = TAILQ_FIRST(completeq);
5592 -       acmd = (struct ahd_cmd *)cmd;
5593 +       acmd = (struct aic_cmd *)cmd;
5594         while (list_cmd != NULL
5595             && acmd_scsi_cmd(list_cmd).serial_number
5596              < acmd_scsi_cmd(acmd).serial_number)
5597 @@ -4877,7 +4907,7 @@
5598         struct  ahd_transinfo *goal;
5599         struct  ahd_transinfo *curr;
5600         struct  ahd_tmode_tstate *tstate;
5601 -       struct  ahd_linux_device *dev;
5602 +       struct  aic_linux_device *dev;
5603         u_int   width;
5604         u_int   period;
5605         u_int   offset;
5606 @@ -4899,9 +4929,9 @@
5607         sid = (struct scsi_inquiry_data *)dev->target->inq_data;
5608         if (SID_QUAL(sid) == SID_QUAL_LU_CONNECTED) {
5609  
5610 -               dev->flags &= ~AHD_DEV_UNCONFIGURED;
5611 +               dev->flags &= ~AIC_DEV_UNCONFIGURED;
5612         } else {
5613 -               dev->flags |= AHD_DEV_UNCONFIGURED;
5614 +               dev->flags |= AIC_DEV_UNCONFIGURED;
5615                 return;
5616         }
5617  
5618 @@ -4967,48 +4997,6 @@
5619                          AHD_TRANS_GOAL, /*paused*/FALSE);
5620  }
5621  
5622 -void
5623 -ahd_freeze_simq(struct ahd_softc *ahd)
5624 -{
5625 -       ahd->platform_data->qfrozen++;
5626 -       if (ahd->platform_data->qfrozen == 1) {
5627 -               scsi_block_requests(ahd->platform_data->host);
5628 -               ahd_platform_abort_scbs(ahd, CAM_TARGET_WILDCARD, ALL_CHANNELS,
5629 -                                       CAM_LUN_WILDCARD, SCB_LIST_NULL,
5630 -                                       ROLE_INITIATOR, CAM_REQUEUE_REQ);
5631 -       }
5632 -}
5633 -
5634 -void
5635 -ahd_release_simq(struct ahd_softc *ahd)
5636 -{
5637 -       u_long s;
5638 -       int    unblock_reqs;
5639 -
5640 -       unblock_reqs = 0;
5641 -       ahd_lock(ahd, &s);
5642 -       if (ahd->platform_data->qfrozen > 0)
5643 -               ahd->platform_data->qfrozen--;
5644 -       if (ahd->platform_data->qfrozen == 0) {
5645 -               unblock_reqs = 1;
5646 -       }
5647 -       if (AHD_DV_SIMQ_FROZEN(ahd)
5648 -        && ((ahd->platform_data->flags & AHD_DV_WAIT_SIMQ_RELEASE) != 0)) {
5649 -               ahd->platform_data->flags &= ~AHD_DV_WAIT_SIMQ_RELEASE;
5650 -               up(&ahd->platform_data->dv_sem);
5651 -       }
5652 -       ahd_schedule_runq(ahd);
5653 -       ahd_unlock(ahd, &s);
5654 -       /*
5655 -        * There is still a race here.  The mid-layer
5656 -        * should keep its own freeze count and use
5657 -        * a bottom half handler to run the queues
5658 -        * so we can unblock with our own lock held.
5659 -        */
5660 -       if (unblock_reqs)
5661 -               scsi_unblock_requests(ahd->platform_data->host);
5662 -}
5663 -
5664  static void
5665  ahd_linux_sem_timeout(u_long arg)
5666  {
5667 @@ -5019,8 +5007,8 @@
5668         scb = (struct scb *)arg;
5669         ahd = scb->ahd_softc;
5670         ahd_lock(ahd, &s);
5671 -       if ((scb->platform_data->flags & AHD_SCB_UP_EH_SEM) != 0) {
5672 -               scb->platform_data->flags &= ~AHD_SCB_UP_EH_SEM;
5673 +       if ((scb->platform_data->flags & AIC_SCB_UP_EH_SEM) != 0) {
5674 +               scb->platform_data->flags &= ~AIC_SCB_UP_EH_SEM;
5675                 up(&ahd->platform_data->eh_sem);
5676         }
5677         ahd_unlock(ahd, &s);
5678 @@ -5029,20 +5017,21 @@
5679  static void
5680  ahd_linux_dev_timed_unfreeze(u_long arg)
5681  {
5682 -       struct ahd_linux_device *dev;
5683 +       struct aic_linux_device *dev;
5684         struct ahd_softc *ahd;
5685         u_long s;
5686  
5687 -       dev = (struct ahd_linux_device *)arg;
5688 -       ahd = dev->target->ahd;
5689 +       dev = (struct aic_linux_device *)arg;
5690 +       ahd = dev->target->softc;
5691         ahd_lock(ahd, &s);
5692 -       dev->flags &= ~AHD_DEV_TIMER_ACTIVE;
5693 +       dev->flags &= ~AIC_DEV_TIMER_ACTIVE;
5694         if (dev->qfrozen > 0)
5695                 dev->qfrozen--;
5696         if (dev->qfrozen == 0
5697 -        && (dev->flags & AHD_DEV_ON_RUN_LIST) == 0)
5698 +        && (dev->flags & AIC_DEV_ON_RUN_LIST) == 0)
5699                 ahd_linux_run_device_queue(ahd, dev);
5700 -       if ((dev->flags & AHD_DEV_UNCONFIGURED) != 0
5701 +       if ((dev->flags & AIC_DEV_UNCONFIGURED) != 0
5702 +        && TAILQ_EMPTY(&dev->busyq)
5703          && dev->active == 0)
5704                 ahd_linux_free_device(ahd, dev);
5705         ahd_unlock(ahd, &s);
5706 @@ -5051,17 +5040,26 @@
5707  void
5708  ahd_platform_dump_card_state(struct ahd_softc *ahd)
5709  {
5710 -       struct ahd_linux_device *dev;
5711 +       struct Scsi_Host *host;
5712 +       struct aic_linux_device *dev;
5713         int target;
5714         int maxtarget;
5715         int lun;
5716         int i;
5717  
5718 +       host = ahd->platform_data->host;
5719 +       printf("%s: Host Status: Failed(%d) %s%s%s\n",
5720 +              ahd_name(ahd),
5721 +              host->host_failed,
5722 +              host->eh_active ? "eh_active " : "",
5723 +              host->host_blocked ? "host_blocked " : "",
5724 +              host->host_self_blocked ? "host_self_blocked " : "");
5725 +              
5726         maxtarget = (ahd->features & AHD_WIDE) ? 15 : 7;
5727         for (target = 0; target <=maxtarget; target++) {
5728  
5729                 for (lun = 0; lun < AHD_NUM_LUNS; lun++) {
5730 -                       struct ahd_cmd *acmd;
5731 +                       struct aic_cmd *acmd;
5732  
5733                         dev = ahd_linux_get_device(ahd, 0, target,
5734                                                    lun, /*alloc*/FALSE);
5735 @@ -5100,20 +5098,18 @@
5736  ahd_linux_exit(void)
5737  {
5738         struct ahd_softc *ahd;
5739 -       u_long l;
5740  
5741         /*
5742 -        * Shutdown DV threads before going into the SCSI mid-layer.
5743 +        * Shutdown our threads before going into the SCSI mid-layer.
5744          * This avoids situations where the mid-layer locks the entire
5745          * kernel so that waiting for our DV threads to exit leads
5746          * to deadlock.
5747          */
5748 -       ahd_list_lock(&l);
5749         TAILQ_FOREACH(ahd, &ahd_tailq, links) {
5750  
5751                 ahd_linux_kill_dv_thread(ahd);
5752 +               ahd_terminate_recovery_thread(ahd);
5753         }
5754 -       ahd_list_unlock(&l);
5755  #if LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0)
5756         /*
5757          * In 2.4 we have to unregister from the PCI core _after_
5758 diff -urN linux-2.4.24.org/drivers/scsi/aic7xxx/aic79xx_osm.h linux-2.4.24/drivers/scsi/aic7xxx/aic79xx_osm.h
5759 --- linux-2.4.24.org/drivers/scsi/aic7xxx/aic79xx_osm.h 2004-01-08 11:57:43.054996482 +0100
5760 +++ linux-2.4.24/drivers/scsi/aic7xxx/aic79xx_osm.h     2003-12-23 00:32:11.000000000 +0100
5761 @@ -36,52 +36,22 @@
5762   * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
5763   * POSSIBILITY OF SUCH DAMAGES.
5764   *
5765 - * $Id$
5766 + * $Id$
5767   *
5768   */
5769  #ifndef _AIC79XX_LINUX_H_
5770  #define _AIC79XX_LINUX_H_
5771  
5772 -#include <linux/types.h>
5773 -#include <linux/blk.h>
5774 -#include <linux/blkdev.h>
5775 -#include <linux/delay.h>
5776 -#include <linux/ioport.h>
5777 -#include <linux/pci.h>
5778 -#include <linux/smp_lock.h>
5779  #include <linux/version.h>
5780 -#include <linux/module.h>
5781 -#include <asm/byteorder.h>
5782 -#include <asm/io.h>
5783  
5784  #ifndef KERNEL_VERSION
5785  #define KERNEL_VERSION(x,y,z) (((x)<<16)+((y)<<8)+(z))
5786  #endif
5787  
5788  #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,0)
5789 -#include <linux/interrupt.h> /* For tasklet support. */
5790  #include <linux/config.h>
5791 -#include <linux/slab.h>
5792 -#else
5793 -#include <linux/malloc.h>
5794  #endif
5795  
5796 -/* Core SCSI definitions */
5797 -#define AIC_LIB_PREFIX ahd
5798 -#include "scsi.h"
5799 -#include "hosts.h"
5800 -
5801 -/* Name space conflict with BSD queue macros */
5802 -#ifdef LIST_HEAD
5803 -#undef LIST_HEAD
5804 -#endif
5805 -
5806 -#include "cam.h"
5807 -#include "queue.h"
5808 -#include "scsi_message.h"
5809 -#include "scsi_iu.h"
5810 -#include "aiclib.h"
5811 -
5812  /*********************************** Debugging ********************************/
5813  #ifdef CONFIG_AIC79XX_DEBUG_ENABLE
5814  #ifdef CONFIG_AIC79XX_DEBUG_MASK
5815 @@ -97,188 +67,27 @@
5816  /* No debugging code. */
5817  #endif
5818  
5819 -/********************************** Misc Macros *******************************/
5820 -#define        roundup(x, y)   ((((x)+((y)-1))/(y))*(y))
5821 -#define        powerof2(x)     ((((x)-1)&(x))==0)
5822 -
5823 -/************************* Forward Declarations *******************************/
5824 -struct ahd_softc;
5825 -typedef struct pci_dev *ahd_dev_softc_t;
5826 -typedef Scsi_Cmnd      *ahd_io_ctx_t;
5827 -
5828 -/******************************* Byte Order ***********************************/
5829 -#define ahd_htobe16(x) cpu_to_be16(x)
5830 -#define ahd_htobe32(x) cpu_to_be32(x)
5831 -#define ahd_htobe64(x) cpu_to_be64(x)
5832 -#define ahd_htole16(x) cpu_to_le16(x)
5833 -#define ahd_htole32(x) cpu_to_le32(x)
5834 -#define ahd_htole64(x) cpu_to_le64(x)
5835 -
5836 -#define ahd_be16toh(x) be16_to_cpu(x)
5837 -#define ahd_be32toh(x) be32_to_cpu(x)
5838 -#define ahd_be64toh(x) be64_to_cpu(x)
5839 -#define ahd_le16toh(x) le16_to_cpu(x)
5840 -#define ahd_le32toh(x) le32_to_cpu(x)
5841 -#define ahd_le64toh(x) le64_to_cpu(x)
5842 -
5843 -#ifndef LITTLE_ENDIAN
5844 -#define LITTLE_ENDIAN 1234
5845 -#endif
5846 -
5847 -#ifndef BIG_ENDIAN
5848 -#define BIG_ENDIAN 4321
5849 -#endif
5850 -
5851 -#ifndef BYTE_ORDER
5852 -#if defined(__BIG_ENDIAN)
5853 -#define BYTE_ORDER BIG_ENDIAN
5854 -#endif
5855 -#if defined(__LITTLE_ENDIAN)
5856 -#define BYTE_ORDER LITTLE_ENDIAN
5857 -#endif
5858 -#endif /* BYTE_ORDER */
5859 -
5860 -/************************* Configuration Data *********************************/
5861 -extern uint32_t aic79xx_allow_memio;
5862 -extern int aic79xx_detect_complete;
5863 -extern Scsi_Host_Template aic79xx_driver_template;
5864 -
5865 -/***************************** Bus Space/DMA **********************************/
5866 -
5867 -#if LINUX_VERSION_CODE > KERNEL_VERSION(2,2,17)
5868 -typedef dma_addr_t bus_addr_t;
5869 -#else
5870 -typedef uint32_t bus_addr_t;
5871 -#endif
5872 -typedef uint32_t bus_size_t;
5873 -
5874 -typedef enum {
5875 -       BUS_SPACE_MEMIO,
5876 -       BUS_SPACE_PIO
5877 -} bus_space_tag_t;
5878 -
5879 -typedef union {
5880 -       u_long            ioport;
5881 -       volatile uint8_t *maddr;
5882 -} bus_space_handle_t;
5883 -
5884 -typedef struct bus_dma_segment
5885 -{
5886 -       bus_addr_t      ds_addr;
5887 -       bus_size_t      ds_len;
5888 -} bus_dma_segment_t;
5889 -
5890 -struct ahd_linux_dma_tag
5891 -{
5892 -       bus_size_t      alignment;
5893 -       bus_size_t      boundary;
5894 -       bus_size_t      maxsize;
5895 -};
5896 -typedef struct ahd_linux_dma_tag* bus_dma_tag_t;
5897 -
5898 -struct ahd_linux_dmamap
5899 -{
5900 -       bus_addr_t      bus_addr;
5901 -};
5902 -typedef struct ahd_linux_dmamap* bus_dmamap_t;
5903 -
5904 -typedef int bus_dma_filter_t(void*, bus_addr_t);
5905 -typedef void bus_dmamap_callback_t(void *, bus_dma_segment_t *, int, int);
5906 -
5907 -#define BUS_DMA_WAITOK         0x0
5908 -#define BUS_DMA_NOWAIT         0x1
5909 -#define BUS_DMA_ALLOCNOW       0x2
5910 -#define BUS_DMA_LOAD_SEGS      0x4     /*
5911 -                                        * Argument is an S/G list not
5912 -                                        * a single buffer.
5913 -                                        */
5914 -
5915 -#define BUS_SPACE_MAXADDR      0xFFFFFFFF
5916 -#define BUS_SPACE_MAXADDR_32BIT        0xFFFFFFFF
5917 -#define BUS_SPACE_MAXSIZE_32BIT        0xFFFFFFFF
5918 -
5919 -int    ahd_dma_tag_create(struct ahd_softc *, bus_dma_tag_t /*parent*/,
5920 -                          bus_size_t /*alignment*/, bus_size_t /*boundary*/,
5921 -                          bus_addr_t /*lowaddr*/, bus_addr_t /*highaddr*/,
5922 -                          bus_dma_filter_t*/*filter*/, void */*filterarg*/,
5923 -                          bus_size_t /*maxsize*/, int /*nsegments*/,
5924 -                          bus_size_t /*maxsegsz*/, int /*flags*/,
5925 -                          bus_dma_tag_t */*dma_tagp*/);
5926 -
5927 -void   ahd_dma_tag_destroy(struct ahd_softc *, bus_dma_tag_t /*tag*/);
5928 -
5929 -int    ahd_dmamem_alloc(struct ahd_softc *, bus_dma_tag_t /*dmat*/,
5930 -                        void** /*vaddr*/, int /*flags*/,
5931 -                        bus_dmamap_t* /*mapp*/);
5932 -
5933 -void   ahd_dmamem_free(struct ahd_softc *, bus_dma_tag_t /*dmat*/,
5934 -                       void* /*vaddr*/, bus_dmamap_t /*map*/);
5935 -
5936 -void   ahd_dmamap_destroy(struct ahd_softc *, bus_dma_tag_t /*tag*/,
5937 -                          bus_dmamap_t /*map*/);
5938 -
5939 -int    ahd_dmamap_load(struct ahd_softc *ahd, bus_dma_tag_t /*dmat*/,
5940 -                       bus_dmamap_t /*map*/, void * /*buf*/,
5941 -                       bus_size_t /*buflen*/, bus_dmamap_callback_t *,
5942 -                       void */*callback_arg*/, int /*flags*/);
5943 -
5944 -int    ahd_dmamap_unload(struct ahd_softc *, bus_dma_tag_t, bus_dmamap_t);
5945 -
5946 -/*
5947 - * Operations performed by ahd_dmamap_sync().
5948 - */
5949 -#define BUS_DMASYNC_PREREAD    0x01    /* pre-read synchronization */
5950 -#define BUS_DMASYNC_POSTREAD   0x02    /* post-read synchronization */
5951 -#define BUS_DMASYNC_PREWRITE   0x04    /* pre-write synchronization */
5952 -#define BUS_DMASYNC_POSTWRITE  0x08    /* post-write synchronization */
5953 -
5954 -/*
5955 - * XXX
5956 - * ahd_dmamap_sync is only used on buffers allocated with
5957 - * the pci_alloc_consistent() API.  Although I'm not sure how
5958 - * this works on architectures with a write buffer, Linux does
5959 - * not have an API to sync "coherent" memory.  Perhaps we need
5960 - * to do an mb()?
5961 - */
5962 -#define ahd_dmamap_sync(ahd, dma_tag, dmamap, offset, len, op)
5963 -
5964 -/************************** Timer DataStructures ******************************/
5965 -typedef struct timer_list ahd_timer_t;
5966 -
5967  /********************************** Includes **********************************/
5968 +/* Core SCSI definitions */
5969 +#define AIC_LIB_PREFIX ahd
5970 +#define AIC_CONST_PREFIX AHD
5971 +
5972  #ifdef CONFIG_AIC79XX_REG_PRETTY_PRINT
5973  #define AIC_DEBUG_REGISTERS 1
5974  #else
5975  #define AIC_DEBUG_REGISTERS 0
5976  #endif
5977 -#include "aic79xx.h"
5978 -
5979 -/***************************** Timer Facilities *******************************/
5980 -#define ahd_timer_init init_timer
5981 -#define ahd_timer_stop del_timer_sync
5982 -typedef void ahd_linux_callback_t (u_long);  
5983 -static __inline void ahd_timer_reset(ahd_timer_t *timer, u_int usec,
5984 -                                    ahd_callback_t *func, void *arg);
5985 -static __inline void ahd_scb_timer_reset(struct scb *scb, u_int usec);
5986 -
5987 -static __inline void
5988 -ahd_timer_reset(ahd_timer_t *timer, u_int usec, ahd_callback_t *func, void *arg)
5989 -{
5990 -       struct ahd_softc *ahd;
5991 +#define AIC_CORE_INCLUDE "aic79xx.h"
5992 +#include "aiclib.h"
5993  
5994 -       ahd = (struct ahd_softc *)arg;
5995 -       del_timer(timer);
5996 -       timer->data = (u_long)arg;
5997 -       timer->expires = jiffies + (usec * HZ)/1000000;
5998 -       timer->function = (ahd_linux_callback_t*)func;
5999 -       add_timer(timer);
6000 -}
6001 +/************************* Configuration Data *********************************/
6002 +extern uint32_t aic79xx_allow_memio;
6003 +extern int aic79xx_detect_complete;
6004 +extern Scsi_Host_Template aic79xx_driver_template;
6005  
6006 -static __inline void
6007 -ahd_scb_timer_reset(struct scb *scb, u_int usec)
6008 -{
6009 -       mod_timer(&scb->io_ctx->eh_timeout, jiffies + (usec * HZ)/1000000);
6010 -}
6011 +/***************************** Domain Validation ******************************/
6012 +void ahd_linux_dv_complete(Scsi_Cmnd *cmd);
6013 +void ahd_linux_dv_timeout(struct scsi_cmnd *cmd);
6014  
6015  /***************************** SMP support ************************************/
6016  #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,3,17)
6017 @@ -293,193 +102,7 @@
6018  #define AHD_SCSI_HAS_HOST_LOCK 0
6019  #endif
6020  
6021 -#define AIC79XX_DRIVER_VERSION "1.3.10"
6022 -
6023 -/**************************** Front End Queues ********************************/
6024 -/*
6025 - * Data structure used to cast the Linux struct scsi_cmnd to something
6026 - * that allows us to use the queue macros.  The linux structure has
6027 - * plenty of space to hold the links fields as required by the queue
6028 - * macros, but the queue macors require them to have the correct type.
6029 - */
6030 -struct ahd_cmd_internal {
6031 -       /* Area owned by the Linux scsi layer. */
6032 -       uint8_t private[offsetof(struct scsi_cmnd, SCp.Status)];
6033 -       union {
6034 -               STAILQ_ENTRY(ahd_cmd)   ste;
6035 -               LIST_ENTRY(ahd_cmd)     le;
6036 -               TAILQ_ENTRY(ahd_cmd)    tqe;
6037 -       } links;
6038 -       uint32_t                        end;
6039 -};
6040 -
6041 -struct ahd_cmd {
6042 -       union {
6043 -               struct ahd_cmd_internal icmd;
6044 -               struct scsi_cmnd        scsi_cmd;
6045 -       } un;
6046 -};
6047 -
6048 -#define acmd_icmd(cmd) ((cmd)->un.icmd)
6049 -#define acmd_scsi_cmd(cmd) ((cmd)->un.scsi_cmd)
6050 -#define acmd_links un.icmd.links
6051 -
6052 -/*************************** Device Data Structures ***************************/
6053 -/*
6054 - * A per probed device structure used to deal with some error recovery
6055 - * scenarios that the Linux mid-layer code just doesn't know how to
6056 - * handle.  The structure allocated for a device only becomes persistent
6057 - * after a successfully completed inquiry command to the target when
6058 - * that inquiry data indicates a lun is present.
6059 - */
6060 -TAILQ_HEAD(ahd_busyq, ahd_cmd);
6061 -typedef enum {
6062 -       AHD_DEV_UNCONFIGURED     = 0x01,
6063 -       AHD_DEV_FREEZE_TIL_EMPTY = 0x02, /* Freeze queue until active == 0 */
6064 -       AHD_DEV_TIMER_ACTIVE     = 0x04, /* Our timer is active */
6065 -       AHD_DEV_ON_RUN_LIST      = 0x08, /* Queued to be run later */
6066 -       AHD_DEV_Q_BASIC          = 0x10, /* Allow basic device queuing */
6067 -       AHD_DEV_Q_TAGGED         = 0x20, /* Allow full SCSI2 command queueing */
6068 -       AHD_DEV_PERIODIC_OTAG    = 0x40, /* Send OTAG to prevent starvation */
6069 -       AHD_DEV_SLAVE_CONFIGURED = 0x80  /* slave_configure() has been called */
6070 -} ahd_linux_dev_flags;
6071 -
6072 -struct ahd_linux_target;
6073 -struct ahd_linux_device {
6074 -       TAILQ_ENTRY(ahd_linux_device) links;
6075 -       struct                  ahd_busyq busyq;
6076 -
6077 -       /*
6078 -        * The number of transactions currently
6079 -        * queued to the device.
6080 -        */
6081 -       int                     active;
6082 -
6083 -       /*
6084 -        * The currently allowed number of 
6085 -        * transactions that can be queued to
6086 -        * the device.  Must be signed for
6087 -        * conversion from tagged to untagged
6088 -        * mode where the device may have more
6089 -        * than one outstanding active transaction.
6090 -        */
6091 -       int                     openings;
6092 -
6093 -       /*
6094 -        * A positive count indicates that this
6095 -        * device's queue is halted.
6096 -        */
6097 -       u_int                   qfrozen;
6098 -       
6099 -       /*
6100 -        * Cumulative command counter.
6101 -        */
6102 -       u_long                  commands_issued;
6103 -
6104 -       /*
6105 -        * The number of tagged transactions when
6106 -        * running at our current opening level
6107 -        * that have been successfully received by
6108 -        * this device since the last QUEUE FULL.
6109 -        */
6110 -       u_int                   tag_success_count;
6111 -#define AHD_TAG_SUCCESS_INTERVAL 50
6112 -
6113 -       ahd_linux_dev_flags     flags;
6114 -
6115 -       /*
6116 -        * Per device timer.
6117 -        */
6118 -       struct timer_list       timer;
6119 -
6120 -       /*
6121 -        * The high limit for the tags variable.
6122 -        */
6123 -       u_int                   maxtags;
6124 -
6125 -       /*
6126 -        * The computed number of tags outstanding
6127 -        * at the time of the last QUEUE FULL event.
6128 -        */
6129 -       u_int                   tags_on_last_queuefull;
6130 -
6131 -       /*
6132 -        * How many times we have seen a queue full
6133 -        * with the same number of tags.  This is used
6134 -        * to stop our adaptive queue depth algorithm
6135 -        * on devices with a fixed number of tags.
6136 -        */
6137 -       u_int                   last_queuefull_same_count;
6138 -#define AHD_LOCK_TAGS_COUNT 50
6139 -
6140 -       /*
6141 -        * How many transactions have been queued
6142 -        * without the device going idle.  We use
6143 -        * this statistic to determine when to issue
6144 -        * an ordered tag to prevent transaction
6145 -        * starvation.  This statistic is only updated
6146 -        * if the AHD_DEV_PERIODIC_OTAG flag is set
6147 -        * on this device.
6148 -        */
6149 -       u_int                   commands_since_idle_or_otag;
6150 -#define AHD_OTAG_THRESH        500
6151 -
6152 -       int                     lun;
6153 -       Scsi_Device            *scsi_device;
6154 -       struct                  ahd_linux_target *target;
6155 -};
6156 -
6157 -typedef enum {
6158 -       AHD_DV_REQUIRED          = 0x01,
6159 -       AHD_INQ_VALID            = 0x02,
6160 -       AHD_BASIC_DV             = 0x04,
6161 -       AHD_ENHANCED_DV          = 0x08
6162 -} ahd_linux_targ_flags;
6163 -
6164 -/* DV States */
6165 -typedef enum {
6166 -       AHD_DV_STATE_EXIT = 0,
6167 -       AHD_DV_STATE_INQ_SHORT_ASYNC,
6168 -       AHD_DV_STATE_INQ_ASYNC,
6169 -       AHD_DV_STATE_INQ_ASYNC_VERIFY,
6170 -       AHD_DV_STATE_TUR,
6171 -       AHD_DV_STATE_REBD,
6172 -       AHD_DV_STATE_INQ_VERIFY,
6173 -       AHD_DV_STATE_WEB,
6174 -       AHD_DV_STATE_REB,
6175 -       AHD_DV_STATE_SU,
6176 -       AHD_DV_STATE_BUSY
6177 -} ahd_dv_state;
6178 -
6179 -struct ahd_linux_target {
6180 -       struct ahd_linux_device  *devices[AHD_NUM_LUNS];
6181 -       int                       channel;
6182 -       int                       target;
6183 -       int                       refcount;
6184 -       struct ahd_transinfo      last_tinfo;
6185 -       struct ahd_softc         *ahd;
6186 -       ahd_linux_targ_flags      flags;
6187 -       struct scsi_inquiry_data *inq_data;
6188 -       /*
6189 -        * The next "fallback" period to use for narrow/wide transfers.
6190 -        */
6191 -       uint8_t                   dv_next_narrow_period;
6192 -       uint8_t                   dv_next_wide_period;
6193 -       uint8_t                   dv_max_width;
6194 -       uint8_t                   dv_max_ppr_options;
6195 -       uint8_t                   dv_last_ppr_options;
6196 -       u_int                     dv_echo_size;
6197 -       ahd_dv_state              dv_state;
6198 -       u_int                     dv_state_retry;
6199 -       uint8_t                  *dv_buffer;
6200 -       uint8_t                  *dv_buffer1;
6201 -
6202 -       /*
6203 -        * Cumulative counter of errors.
6204 -        */
6205 -       u_long                  errors_detected;
6206 -       u_long                  cmds_since_error;
6207 -};
6208 +#define AIC79XX_DRIVER_VERSION "2.0.5"
6209  
6210  /********************* Definitions Required by the Core ***********************/
6211  /*
6212 @@ -501,100 +124,21 @@
6213  #define        AHD_NSEG 128
6214  #endif
6215  
6216 -/*
6217 - * Per-SCB OSM storage.
6218 - */
6219 -typedef enum {
6220 -       AHD_SCB_UP_EH_SEM = 0x1
6221 -} ahd_linux_scb_flags;
6222 -
6223 -struct scb_platform_data {
6224 -       struct ahd_linux_device *dev;
6225 -       bus_addr_t               buf_busaddr;
6226 -       uint32_t                 xfer_len;
6227 -#if LINUX_VERSION_CODE < KERNEL_VERSION(2,3,0)
6228 -       uint32_t                 resid;         /* Transfer residual */
6229 -#endif
6230 -       uint32_t                 sense_resid;   /* Auto-Sense residual */
6231 -       ahd_linux_scb_flags      flags;
6232 -};
6233 -
6234 -/*
6235 - * Define a structure used for each host adapter.  All members are
6236 - * aligned on a boundary >= the size of the member to honor the
6237 - * alignment restrictions of the various platforms supported by
6238 - * this driver.
6239 - */
6240 -typedef enum {
6241 -       AHD_DV_WAIT_SIMQ_EMPTY   = 0x01,
6242 -       AHD_DV_WAIT_SIMQ_RELEASE = 0x02,
6243 -       AHD_DV_ACTIVE            = 0x04,
6244 -       AHD_DV_SHUTDOWN          = 0x08,
6245 -       AHD_RUN_CMPLT_Q_TIMER    = 0x10
6246 -} ahd_linux_softc_flags;
6247 -
6248 -TAILQ_HEAD(ahd_completeq, ahd_cmd);
6249 -
6250 -struct ahd_platform_data {
6251 -       /*
6252 -        * Fields accessed from interrupt context.
6253 -        */
6254 -       struct ahd_linux_target *targets[AHD_NUM_TARGETS]; 
6255 -       TAILQ_HEAD(, ahd_linux_device) device_runq;
6256 -       struct ahd_completeq     completeq;
6257 -
6258 -       spinlock_t               spin_lock;
6259 -#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,0)
6260 -       struct tasklet_struct    runq_tasklet;
6261 -#endif
6262 -       u_int                    qfrozen;
6263 -       pid_t                    dv_pid;
6264 -       struct timer_list        completeq_timer;
6265 -       struct timer_list        reset_timer;
6266 -       struct timer_list        stats_timer;
6267 -       struct semaphore         eh_sem;
6268 -       struct semaphore         dv_sem;
6269 -       struct semaphore         dv_cmd_sem;    /* XXX This needs to be in
6270 -                                                * the target struct
6271 -                                                */
6272 -       struct scsi_device      *dv_scsi_dev;
6273 -       struct Scsi_Host        *host;          /* pointer to scsi host */
6274 -#define AHD_LINUX_NOIRQ        ((uint32_t)~0)
6275 -       uint32_t                 irq;           /* IRQ for this adapter */
6276 -       uint32_t                 bios_address;
6277 -       uint32_t                 mem_busaddr;   /* Mem Base Addr */
6278 -       bus_addr_t               hw_dma_mask;
6279 -       ahd_linux_softc_flags    flags;
6280 -};
6281 -
6282 -/************************** OS Utility Wrappers *******************************/
6283 -#define printf printk
6284 -#define M_NOWAIT GFP_ATOMIC
6285 -#define M_WAITOK 0
6286 -#define malloc(size, type, flags) kmalloc(size, flags)
6287 -#define free(ptr, type) kfree(ptr)
6288 -
6289 -static __inline void ahd_delay(long);
6290 -static __inline void
6291 -ahd_delay(long usec)
6292 -{
6293 -       /*
6294 -        * udelay on Linux can have problems for
6295 -        * multi-millisecond waits.  Wait at most
6296 -        * 1024us per call.
6297 -        */
6298 -       while (usec > 0) {
6299 -               udelay(usec % 1024);
6300 -               usec -= 1024;
6301 -       }
6302 -}
6303 -
6304 +/************************** Error Recovery ************************************/
6305 +static __inline void   ahd_wakeup_recovery_thread(struct ahd_softc *ahd); 
6306 +  
6307 +static __inline void
6308 +ahd_wakeup_recovery_thread(struct ahd_softc *ahd)
6309 +{ 
6310 +       up(&ahd->platform_data->recovery_sem);
6311 +}
6312
6313 +int                    ahd_spawn_recovery_thread(struct ahd_softc *ahd);
6314 +void                   ahd_terminate_recovery_thread(struct ahd_softc *ahd);
6315 +void                   ahd_set_recoveryscb(struct ahd_softc *ahd,
6316 +                                           struct scb *scb);
6317  
6318  /***************************** Low Level I/O **********************************/
6319 -#if defined(__powerpc__) || defined(__i386__) || defined(__ia64__)
6320 -#define MMAPIO
6321 -#endif
6322 -
6323  static __inline uint8_t ahd_inb(struct ahd_softc * ahd, long port);
6324  static __inline uint16_t ahd_inw_atomic(struct ahd_softc * ahd, long port);
6325  static __inline void ahd_outb(struct ahd_softc * ahd, long port, uint8_t val);
6326 @@ -604,21 +148,18 @@
6327                                uint8_t *, int count);
6328  static __inline void ahd_insb(struct ahd_softc * ahd, long port,
6329                                uint8_t *, int count);
6330 +static __inline void ahd_flush_device_writes(struct ahd_softc *);
6331  
6332  static __inline uint8_t
6333  ahd_inb(struct ahd_softc * ahd, long port)
6334  {
6335         uint8_t x;
6336 -#ifdef MMAPIO
6337  
6338         if (ahd->tags[0] == BUS_SPACE_MEMIO) {
6339                 x = readb(ahd->bshs[0].maddr + port);
6340         } else {
6341                 x = inb(ahd->bshs[(port) >> 8].ioport + ((port) & 0xFF));
6342         }
6343 -#else
6344 -       x = inb(ahd->bshs[(port) >> 8].ioport + ((port) & 0xFF));
6345 -#endif
6346         mb();
6347         return (x);
6348  }
6349 @@ -627,16 +168,12 @@
6350  ahd_inw_atomic(struct ahd_softc * ahd, long port)
6351  {
6352         uint8_t x;
6353 -#ifdef MMAPIO
6354  
6355         if (ahd->tags[0] == BUS_SPACE_MEMIO) {
6356                 x = readw(ahd->bshs[0].maddr + port);
6357         } else {
6358                 x = inw(ahd->bshs[(port) >> 8].ioport + ((port) & 0xFF));
6359         }
6360 -#else
6361 -       x = inw(ahd->bshs[(port) >> 8].ioport + ((port) & 0xFF));
6362 -#endif
6363         mb();
6364         return (x);
6365  }
6366 @@ -644,30 +181,22 @@
6367  static __inline void
6368  ahd_outb(struct ahd_softc * ahd, long port, uint8_t val)
6369  {
6370 -#ifdef MMAPIO
6371         if (ahd->tags[0] == BUS_SPACE_MEMIO) {
6372                 writeb(val, ahd->bshs[0].maddr + port);
6373         } else {
6374                 outb(val, ahd->bshs[(port) >> 8].ioport + (port & 0xFF));
6375         }
6376 -#else
6377 -       outb(val, ahd->bshs[(port) >> 8].ioport + (port & 0xFF));
6378 -#endif
6379         mb();
6380  }
6381  
6382  static __inline void
6383  ahd_outw_atomic(struct ahd_softc * ahd, long port, uint16_t val)
6384  {
6385 -#ifdef MMAPIO
6386         if (ahd->tags[0] == BUS_SPACE_MEMIO) {
6387                 writew(val, ahd->bshs[0].maddr + port);
6388         } else {
6389                 outw(val, ahd->bshs[(port) >> 8].ioport + (port & 0xFF));
6390         }
6391 -#else
6392 -       outw(val, ahd->bshs[(port) >> 8].ioport + (port & 0xFF));
6393 -#endif
6394         mb();
6395  }
6396  
6397 @@ -699,6 +228,13 @@
6398                 *array++ = ahd_inb(ahd, port);
6399  }
6400  
6401 +static __inline void
6402 +ahd_flush_device_writes(struct ahd_softc *ahd)
6403 +{
6404 +       /* XXX Is this sufficient for all architectures??? */
6405 +       ahd_inb(ahd, INTSTAT);
6406 +}
6407 +
6408  /**************************** Initialization **********************************/
6409  int            ahd_linux_register_host(struct ahd_softc *,
6410                                         Scsi_Host_Template *);
6411 @@ -827,184 +363,16 @@
6412  }
6413  
6414  /******************************* PCI Definitions ******************************/
6415 -/*
6416 - * PCIM_xxx: mask to locate subfield in register
6417 - * PCIR_xxx: config register offset
6418 - * PCIC_xxx: device class
6419 - * PCIS_xxx: device subclass
6420 - * PCIP_xxx: device programming interface
6421 - * PCIV_xxx: PCI vendor ID (only required to fixup ancient devices)
6422 - * PCID_xxx: device ID
6423 - */
6424 -#define PCIR_DEVVENDOR         0x00
6425 -#define PCIR_VENDOR            0x00
6426 -#define PCIR_DEVICE            0x02
6427 -#define PCIR_COMMAND           0x04
6428 -#define PCIM_CMD_PORTEN                0x0001
6429 -#define PCIM_CMD_MEMEN         0x0002
6430 -#define PCIM_CMD_BUSMASTEREN   0x0004
6431 -#define PCIM_CMD_MWRICEN       0x0010
6432 -#define PCIM_CMD_PERRESPEN     0x0040
6433 -#define        PCIM_CMD_SERRESPEN      0x0100
6434 -#define PCIR_STATUS            0x06
6435 -#define PCIR_REVID             0x08
6436 -#define PCIR_PROGIF            0x09
6437 -#define PCIR_SUBCLASS          0x0a
6438 -#define PCIR_CLASS             0x0b
6439 -#define PCIR_CACHELNSZ         0x0c
6440 -#define PCIR_LATTIMER          0x0d
6441 -#define PCIR_HEADERTYPE                0x0e
6442 -#define PCIM_MFDEV             0x80
6443 -#define PCIR_BIST              0x0f
6444 -#define PCIR_CAP_PTR           0x34
6445 -
6446 -/* config registers for header type 0 devices */
6447 -#define PCIR_MAPS      0x10
6448 -#define PCIR_SUBVEND_0 0x2c
6449 -#define PCIR_SUBDEV_0  0x2e
6450 -
6451 -/****************************** PCI-X definitions *****************************/
6452 -#define PCIXR_COMMAND  0x96
6453 -#define PCIXR_DEVADDR  0x98
6454 -#define PCIXM_DEVADDR_FNUM     0x0003  /* Function Number */
6455 -#define PCIXM_DEVADDR_DNUM     0x00F8  /* Device Number */
6456 -#define PCIXM_DEVADDR_BNUM     0xFF00  /* Bus Number */
6457 -#define PCIXR_STATUS   0x9A
6458 -#define PCIXM_STATUS_64BIT     0x0001  /* Active 64bit connection to device. */
6459 -#define PCIXM_STATUS_133CAP    0x0002  /* Device is 133MHz capable */
6460 -#define PCIXM_STATUS_SCDISC    0x0004  /* Split Completion Discarded */
6461 -#define PCIXM_STATUS_UNEXPSC   0x0008  /* Unexpected Split Completion */
6462 -#define PCIXM_STATUS_CMPLEXDEV 0x0010  /* Device Complexity (set == bridge) */
6463 -#define PCIXM_STATUS_MAXMRDBC  0x0060  /* Maximum Burst Read Count */
6464 -#define PCIXM_STATUS_MAXSPLITS 0x0380  /* Maximum Split Transactions */
6465 -#define PCIXM_STATUS_MAXCRDS   0x1C00  /* Maximum Cumulative Read Size */
6466 -#define PCIXM_STATUS_RCVDSCEM  0x2000  /* Received a Split Comp w/Error msg */
6467 -
6468  #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,0)
6469  extern struct pci_driver aic79xx_pci_driver;
6470  #endif
6471  
6472 -typedef enum
6473 -{
6474 -       AHD_POWER_STATE_D0,
6475 -       AHD_POWER_STATE_D1,
6476 -       AHD_POWER_STATE_D2,
6477 -       AHD_POWER_STATE_D3
6478 -} ahd_power_state;
6479 -
6480 -void ahd_power_state_change(struct ahd_softc *ahd,
6481 -                           ahd_power_state new_state);
6482 -
6483  /******************************* PCI Routines *********************************/
6484  int                     ahd_linux_pci_init(void);
6485  void                    ahd_linux_pci_exit(void);
6486  int                     ahd_pci_map_registers(struct ahd_softc *ahd);
6487  int                     ahd_pci_map_int(struct ahd_softc *ahd);
6488  
6489 -static __inline uint32_t ahd_pci_read_config(ahd_dev_softc_t pci,
6490 -                                            int reg, int width);
6491 -
6492 -static __inline uint32_t
6493 -ahd_pci_read_config(ahd_dev_softc_t pci, int reg, int width)
6494 -{
6495 -       switch (width) {
6496 -       case 1:
6497 -       {
6498 -               uint8_t retval;
6499 -
6500 -               pci_read_config_byte(pci, reg, &retval);
6501 -               return (retval);
6502 -       }
6503 -       case 2:
6504 -       {
6505 -               uint16_t retval;
6506 -               pci_read_config_word(pci, reg, &retval);
6507 -               return (retval);
6508 -       }
6509 -       case 4:
6510 -       {
6511 -               uint32_t retval;
6512 -               pci_read_config_dword(pci, reg, &retval);
6513 -               return (retval);
6514 -       }
6515 -       default:
6516 -               panic("ahd_pci_read_config: Read size too big");
6517 -               /* NOTREACHED */
6518 -               return (0);
6519 -       }
6520 -}
6521 -
6522 -static __inline void ahd_pci_write_config(ahd_dev_softc_t pci,
6523 -                                         int reg, uint32_t value,
6524 -                                         int width);
6525 -
6526 -static __inline void
6527 -ahd_pci_write_config(ahd_dev_softc_t pci, int reg, uint32_t value, int width)
6528 -{
6529 -       switch (width) {
6530 -       case 1:
6531 -               pci_write_config_byte(pci, reg, value);
6532 -               break;
6533 -       case 2:
6534 -               pci_write_config_word(pci, reg, value);
6535 -               break;
6536 -       case 4:
6537 -               pci_write_config_dword(pci, reg, value);
6538 -               break;
6539 -       default:
6540 -               panic("ahd_pci_write_config: Write size too big");
6541 -               /* NOTREACHED */
6542 -       }
6543 -}
6544 -
6545 -static __inline int ahd_get_pci_function(ahd_dev_softc_t);
6546 -static __inline int
6547 -ahd_get_pci_function(ahd_dev_softc_t pci)
6548 -{
6549 -       return (PCI_FUNC(pci->devfn));
6550 -}
6551 -
6552 -static __inline int ahd_get_pci_slot(ahd_dev_softc_t);
6553 -static __inline int
6554 -ahd_get_pci_slot(ahd_dev_softc_t pci)
6555 -{
6556 -       return (PCI_SLOT(pci->devfn));
6557 -}
6558 -
6559 -static __inline int ahd_get_pci_bus(ahd_dev_softc_t);
6560 -static __inline int
6561 -ahd_get_pci_bus(ahd_dev_softc_t pci)
6562 -{
6563 -       return (pci->bus->number);
6564 -}
6565 -
6566 -static __inline void ahd_flush_device_writes(struct ahd_softc *);
6567 -static __inline void
6568 -ahd_flush_device_writes(struct ahd_softc *ahd)
6569 -{
6570 -       /* XXX Is this sufficient for all architectures??? */
6571 -       ahd_inb(ahd, INTSTAT);
6572 -}
6573 -
6574 -#if LINUX_VERSION_CODE <= KERNEL_VERSION(2,3,0)
6575 -#define pci_map_sg(pdev, sg_list, nseg, direction) (nseg)
6576 -#define pci_unmap_sg(pdev, sg_list, nseg, direction)
6577 -#define sg_dma_address(sg) (VIRT_TO_BUS((sg)->address))
6578 -#define sg_dma_len(sg) ((sg)->length)
6579 -#define pci_map_single(pdev, buffer, bufflen, direction) \
6580 -       (VIRT_TO_BUS(buffer))
6581 -#define pci_unmap_single(pdev, buffer, buflen, direction)
6582 -#endif
6583 -
6584 -#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,3)
6585 -#define ahd_pci_set_dma_mask pci_set_dma_mask
6586 -#else
6587 -/*
6588 - * Always "return" 0 for success.
6589 - */
6590 -#define ahd_pci_set_dma_mask(dev_softc, mask)  \
6591 -       (((dev_softc)->dma_mask = mask) && 0)
6592 -#endif
6593  /**************************** Proc FS Support *********************************/
6594  #if LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0)
6595  int    ahd_linux_proc_info(char *, char **, off_t, int, int, int);
6596 @@ -1013,203 +381,11 @@
6597                             off_t, int, int);
6598  #endif
6599  
6600 -/*************************** Domain Validation ********************************/
6601 -#define AHD_DV_CMD(cmd) ((cmd)->scsi_done == ahd_linux_dv_complete)
6602 -#define AHD_DV_SIMQ_FROZEN(ahd)                                        \
6603 -       ((((ahd)->platform_data->flags & AHD_DV_ACTIVE) != 0)   \
6604 -        && (ahd)->platform_data->qfrozen == 1)
6605 -
6606  /*********************** Transaction Access Wrappers **************************/
6607 -static __inline void ahd_cmd_set_transaction_status(Scsi_Cmnd *, uint32_t);
6608 -static __inline void ahd_set_transaction_status(struct scb *, uint32_t);
6609 -static __inline void ahd_cmd_set_scsi_status(Scsi_Cmnd *, uint32_t);
6610 -static __inline void ahd_set_scsi_status(struct scb *, uint32_t);
6611 -static __inline uint32_t ahd_cmd_get_transaction_status(Scsi_Cmnd *cmd);
6612 -static __inline uint32_t ahd_get_transaction_status(struct scb *);
6613 -static __inline uint32_t ahd_cmd_get_scsi_status(Scsi_Cmnd *cmd);
6614 -static __inline uint32_t ahd_get_scsi_status(struct scb *);
6615 -static __inline void ahd_set_transaction_tag(struct scb *, int, u_int);
6616 -static __inline u_long ahd_get_transfer_length(struct scb *);
6617 -static __inline int ahd_get_transfer_dir(struct scb *);
6618 -static __inline void ahd_set_residual(struct scb *, u_long);
6619 -static __inline void ahd_set_sense_residual(struct scb *scb, u_long resid);
6620 -static __inline u_long ahd_get_residual(struct scb *);
6621 -static __inline u_long ahd_get_sense_residual(struct scb *);
6622 -static __inline int ahd_perform_autosense(struct scb *);
6623 -static __inline uint32_t ahd_get_sense_bufsize(struct ahd_softc *,
6624 -                                              struct scb *);
6625 -static __inline void ahd_notify_xfer_settings_change(struct ahd_softc *,
6626 -                                                    struct ahd_devinfo *);
6627 -static __inline void ahd_platform_scb_free(struct ahd_softc *ahd,
6628 -                                          struct scb *scb);
6629 -static __inline void ahd_freeze_scb(struct scb *scb);
6630 -
6631 -static __inline
6632 -void ahd_cmd_set_transaction_status(Scsi_Cmnd *cmd, uint32_t status)
6633 -{
6634 -       cmd->result &= ~(CAM_STATUS_MASK << 16);
6635 -       cmd->result |= status << 16;
6636 -}
6637 -
6638 -static __inline
6639 -void ahd_set_transaction_status(struct scb *scb, uint32_t status)
6640 -{
6641 -       ahd_cmd_set_transaction_status(scb->io_ctx,status);
6642 -}
6643 -
6644 -static __inline
6645 -void ahd_cmd_set_scsi_status(Scsi_Cmnd *cmd, uint32_t status)
6646 -{
6647 -       cmd->result &= ~0xFFFF;
6648 -       cmd->result |= status;
6649 -}
6650 -
6651 -static __inline
6652 -void ahd_set_scsi_status(struct scb *scb, uint32_t status)
6653 -{
6654 -       ahd_cmd_set_scsi_status(scb->io_ctx, status);
6655 -}
6656 -
6657 -static __inline
6658 -uint32_t ahd_cmd_get_transaction_status(Scsi_Cmnd *cmd)
6659 -{
6660 -       return ((cmd->result >> 16) & CAM_STATUS_MASK);
6661 -}
6662 -
6663 -static __inline
6664 -uint32_t ahd_get_transaction_status(struct scb *scb)
6665 -{
6666 -       return (ahd_cmd_get_transaction_status(scb->io_ctx));
6667 -}
6668 -
6669 -static __inline
6670 -uint32_t ahd_cmd_get_scsi_status(Scsi_Cmnd *cmd)
6671 -{
6672 -       return (cmd->result & 0xFFFF);
6673 -}
6674 -
6675 -static __inline
6676 -uint32_t ahd_get_scsi_status(struct scb *scb)
6677 -{
6678 -       return (ahd_cmd_get_scsi_status(scb->io_ctx));
6679 -}
6680 -
6681 -static __inline
6682 -void ahd_set_transaction_tag(struct scb *scb, int enabled, u_int type)
6683 -{
6684 -       /*
6685 -        * Nothing to do for linux as the incoming transaction
6686 -        * has no concept of tag/non tagged, etc.
6687 -        */
6688 -}
6689 -
6690 -static __inline
6691 -u_long ahd_get_transfer_length(struct scb *scb)
6692 -{
6693 -       return (scb->platform_data->xfer_len);
6694 -}
6695 -
6696 -static __inline
6697 -int ahd_get_transfer_dir(struct scb *scb)
6698 -{
6699 -#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,3,40)
6700 -       return (scb->io_ctx->sc_data_direction);
6701 -#else
6702 -       if (scb->io_ctx->bufflen == 0)
6703 -               return (CAM_DIR_NONE);
6704 -
6705 -       switch(scb->io_ctx->cmnd[0]) {
6706 -       case 0x08:  /* READ(6)  */
6707 -       case 0x28:  /* READ(10) */
6708 -       case 0xA8:  /* READ(12) */
6709 -               return (CAM_DIR_IN);
6710 -        case 0x0A:  /* WRITE(6)  */
6711 -        case 0x2A:  /* WRITE(10) */
6712 -        case 0xAA:  /* WRITE(12) */
6713 -               return (CAM_DIR_OUT);
6714 -        default:
6715 -               return (CAM_DIR_NONE);
6716 -        }
6717 -#endif
6718 -}
6719 -
6720 -static __inline
6721 -void ahd_set_residual(struct scb *scb, u_long resid)
6722 -{
6723 -#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,3,0)
6724 -       scb->io_ctx->resid = resid;
6725 -#else
6726 -       scb->platform_data->resid = resid;
6727 -#endif
6728 -}
6729 -
6730 -static __inline
6731 -void ahd_set_sense_residual(struct scb *scb, u_long resid)
6732 -{
6733 -       scb->platform_data->sense_resid = resid;
6734 -}
6735 -
6736 -static __inline
6737 -u_long ahd_get_residual(struct scb *scb)
6738 -{
6739 -#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,3,0)
6740 -       return (scb->io_ctx->resid);
6741 -#else
6742 -       return (scb->platform_data->resid);
6743 -#endif
6744 -}
6745 -
6746 -static __inline
6747 -u_long ahd_get_sense_residual(struct scb *scb)
6748 -{
6749 -       return (scb->platform_data->sense_resid);
6750 -}
6751 -
6752 -static __inline
6753 -int ahd_perform_autosense(struct scb *scb)
6754 -{
6755 -       /*
6756 -        * We always perform autosense in Linux.
6757 -        * On other platforms this is set on a
6758 -        * per-transaction basis.
6759 -        */
6760 -       return (1);
6761 -}
6762 -
6763 -static __inline uint32_t
6764 -ahd_get_sense_bufsize(struct ahd_softc *ahd, struct scb *scb)
6765 -{
6766 -       return (sizeof(struct scsi_sense_data));
6767 -}
6768 -
6769 -static __inline void
6770 -ahd_notify_xfer_settings_change(struct ahd_softc *ahd,
6771 -                               struct ahd_devinfo *devinfo)
6772 -{
6773 -       /* Nothing to do here for linux */
6774 -}
6775 -
6776 -static __inline void
6777 -ahd_platform_scb_free(struct ahd_softc *ahd, struct scb *scb)
6778 -{
6779 -       ahd->flags &= ~AHD_RESOURCE_SHORTAGE;
6780 -}
6781 -
6782  int    ahd_platform_alloc(struct ahd_softc *ahd, void *platform_arg);
6783  void   ahd_platform_free(struct ahd_softc *ahd);
6784  void   ahd_platform_init(struct ahd_softc *ahd);
6785  void   ahd_platform_freeze_devq(struct ahd_softc *ahd, struct scb *scb);
6786 -void   ahd_freeze_simq(struct ahd_softc *ahd);
6787 -void   ahd_release_simq(struct ahd_softc *ahd);
6788 -
6789 -static __inline void
6790 -ahd_freeze_scb(struct scb *scb)
6791 -{
6792 -       if ((scb->io_ctx->result & (CAM_DEV_QFRZN << 16)) == 0) {
6793 -                scb->io_ctx->result |= CAM_DEV_QFRZN << 16;
6794 -                scb->platform_data->dev->qfrozen++;
6795 -        }
6796 -}
6797  
6798  void   ahd_platform_set_tags(struct ahd_softc *ahd,
6799                               struct ahd_devinfo *devinfo, ahd_queue_alg);
6800 @@ -1227,9 +403,9 @@
6801  void   ahd_platform_dump_card_state(struct ahd_softc *ahd);
6802  
6803  #ifdef CONFIG_PCI
6804 -#define AHD_PCI_CONFIG 1
6805 +#define AIC_PCI_CONFIG 1
6806  #else
6807 -#define AHD_PCI_CONFIG 0
6808 +#define AIC_PCI_CONFIG 0
6809  #endif
6810  #define bootverbose aic79xx_verbose
6811  extern uint32_t aic79xx_verbose;
6812 diff -urN linux-2.4.24.org/drivers/scsi/aic7xxx/aic79xx_osm_pci.c linux-2.4.24/drivers/scsi/aic7xxx/aic79xx_osm_pci.c
6813 --- linux-2.4.24.org/drivers/scsi/aic7xxx/aic79xx_osm_pci.c     2004-01-08 11:57:43.053996688 +0100
6814 +++ linux-2.4.24/drivers/scsi/aic7xxx/aic79xx_osm_pci.c 2003-12-22 22:46:59.000000000 +0100
6815 @@ -36,12 +36,18 @@
6816   * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
6817   * POSSIBILITY OF SUCH DAMAGES.
6818   *
6819 - * $Id$
6820 + * $Id$
6821   */
6822  
6823  #include "aic79xx_osm.h"
6824  #include "aic79xx_inline.h"
6825  
6826 +/*
6827 + * Include aiclib_pci.c as part of our
6828 + * "module dependencies are hard" work around.
6829 + */
6830 +#include "aiclib_pci.c"
6831 +
6832  #if LINUX_VERSION_CODE < KERNEL_VERSION(2,4,0)
6833  struct pci_device_id
6834  {
6835 @@ -70,10 +76,10 @@
6836  MODULE_DEVICE_TABLE(pci, ahd_linux_pci_id_table);
6837  
6838  struct pci_driver aic79xx_pci_driver = {
6839 -       name:           "aic79xx",
6840 -       probe:          ahd_linux_pci_dev_probe,
6841 -       remove:         ahd_linux_pci_dev_remove,
6842 -       id_table:       ahd_linux_pci_id_table
6843 +       .name           = "aic79xx",
6844 +       .probe          = ahd_linux_pci_dev_probe,
6845 +       .remove         = ahd_linux_pci_dev_remove,
6846 +       .id_table       = ahd_linux_pci_id_table
6847  };
6848  
6849  static void
6850 @@ -92,12 +98,14 @@
6851         if (ahd != NULL) {
6852                 u_long s;
6853  
6854 +               TAILQ_REMOVE(&ahd_tailq, ahd, links);
6855 +               ahd_list_unlock(&l);
6856                 ahd_lock(ahd, &s);
6857                 ahd_intr_enable(ahd, FALSE);
6858                 ahd_unlock(ahd, &s);
6859                 ahd_free(ahd);
6860 -       }
6861 -       ahd_list_unlock(&l);
6862 +       } else
6863 +               ahd_list_unlock(&l);
6864  }
6865  #endif /* !LINUX_VERSION_CODE < KERNEL_VERSION(2,4,0) */
6866  
6867 @@ -106,7 +114,7 @@
6868  {
6869         char             buf[80];
6870         struct           ahd_softc *ahd;
6871 -       ahd_dev_softc_t  pci;
6872 +       aic_dev_softc_t  dev;
6873         struct           ahd_pci_identity *entry;
6874         char            *name;
6875         int              error;
6876 @@ -117,7 +125,7 @@
6877         TAILQ_FOREACH(ahd, &ahd_tailq, links) {
6878                 struct pci_dev *probed_pdev;
6879  
6880 -               probed_pdev = ahd->dev_softc;
6881 +               probed_pdev = aic_pci_dev(ahd);
6882                 if (probed_pdev->bus->number == pdev->bus->number
6883                  && probed_pdev->devfn == pdev->devfn)
6884                         break;
6885 @@ -127,8 +135,8 @@
6886                 return (-ENODEV);
6887         }
6888  
6889 -       pci = pdev;
6890 -       entry = ahd_find_pci_device(pci);
6891 +       dev = aic_pci_dev_to_dev(pdev);
6892 +       entry = ahd_find_pci_device(dev);
6893         if (entry == NULL)
6894                 return (-ENODEV);
6895  
6896 @@ -138,9 +146,9 @@
6897          * common detect routine.
6898          */
6899         sprintf(buf, "ahd_pci:%d:%d:%d",
6900 -               ahd_get_pci_bus(pci),
6901 -               ahd_get_pci_slot(pci),
6902 -               ahd_get_pci_function(pci));
6903 +               aic_get_pci_bus(dev),
6904 +               aic_get_pci_slot(dev),
6905 +               aic_get_pci_function(dev));
6906         name = malloc(strlen(buf) + 1, M_DEVBUF, M_NOWAIT);
6907         if (name == NULL)
6908                 return (-ENOMEM);
6909 @@ -148,6 +156,7 @@
6910         ahd = ahd_alloc(NULL, name);
6911         if (ahd == NULL)
6912                 return (-ENOMEM);
6913 +       ahd->dev_softc = dev;
6914  #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,0)
6915         if (pci_enable_device(pdev)) {
6916                 ahd_free(ahd);
6917 @@ -164,20 +173,19 @@
6918                 mask_64bit = (bus_addr_t)0xFFFFFFFFFFFFFFFFULL;
6919                 mask_39bit = (bus_addr_t)0x7FFFFFFFFFULL;
6920                 if (memsize >= 0x8000000000ULL
6921 -                && ahd_pci_set_dma_mask(pdev, mask_64bit) == 0) {
6922 +                && aic_set_dma_mask(ahd, mask_64bit) == 0) {
6923                         ahd->flags |= AHD_64BIT_ADDRESSING;
6924                         ahd->platform_data->hw_dma_mask = mask_64bit;
6925                 } else if (memsize > 0x80000000
6926 -                       && ahd_pci_set_dma_mask(pdev, mask_39bit) == 0) {
6927 +                       && aic_set_dma_mask(ahd, mask_39bit) == 0) {
6928                         ahd->flags |= AHD_39BIT_ADDRESSING;
6929                         ahd->platform_data->hw_dma_mask = mask_39bit;
6930                 }
6931         } else {
6932 -               ahd_pci_set_dma_mask(pdev, 0xFFFFFFFF);
6933 +               aic_set_dma_mask(ahd, 0xFFFFFFFF);
6934                 ahd->platform_data->hw_dma_mask = 0xFFFFFFFF;
6935         }
6936  #endif
6937 -       ahd->dev_softc = pci;
6938         error = ahd_pci_config(ahd, entry);
6939         if (error != 0) {
6940                 ahd_free(ahd);
6941 @@ -216,10 +224,8 @@
6942         pdev = NULL;
6943         class = PCI_CLASS_STORAGE_SCSI << 8;
6944         while ((pdev = pci_find_class(class, pdev)) != NULL) {
6945 -               ahd_dev_softc_t pci;
6946                 int error;
6947  
6948 -               pci = pdev;
6949                 error = ahd_linux_pci_dev_probe(pdev, /*pci_devid*/NULL);
6950                 if (error == 0)
6951                         found++;
6952 @@ -238,17 +244,18 @@
6953  ahd_linux_pci_reserve_io_regions(struct ahd_softc *ahd, u_long *base,
6954                                  u_long *base2)
6955  {
6956 +
6957  #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,3,0)
6958 -       *base = pci_resource_start(ahd->dev_softc, 0);
6959 +       *base = pci_resource_start(aic_pci_dev(ahd), 0);
6960         /*
6961          * This is really the 3rd bar and should be at index 2,
6962          * but the Linux PCI code doesn't know how to "count" 64bit
6963          * bars.
6964          */
6965 -       *base2 = pci_resource_start(ahd->dev_softc, 3);
6966 +       *base2 = pci_resource_start(aic_pci_dev(ahd), 3);
6967  #else
6968 -       *base = ahd_pci_read_config(ahd->dev_softc, AHD_PCI_IOADDR0, 4);
6969 -       *base2 = ahd_pci_read_config(ahd->dev_softc, AHD_PCI_IOADDR1, 4);
6970 +       *base = aic_pci_read_config(ahd->dev_softc, AHD_PCI_IOADDR0, 4);
6971 +       *base2 = aic_pci_read_config(ahd->dev_softc, AHD_PCI_IOADDR1, 4);
6972         *base &= PCI_BASE_ADDRESS_IO_MASK;
6973         *base2 &= PCI_BASE_ADDRESS_IO_MASK;
6974  #endif
6975 @@ -289,11 +296,11 @@
6976  
6977         error = 0;
6978  #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,3,0)
6979 -       start = pci_resource_start(ahd->dev_softc, 1);
6980 +       start = pci_resource_start(aic_pci_dev(ahd), 1);
6981         base_page = start & PAGE_MASK;
6982         base_offset = start - base_page;
6983  #else
6984 -       start = ahd_pci_read_config(ahd->dev_softc, PCIR_MAPS+4, 4);
6985 +       start = aic_pci_read_config(ahd->dev_softc, PCIR_MAPS+4, 4);
6986         base_offset = start & PCI_BASE_ADDRESS_MEM_MASK;
6987         base_page = base_offset & PAGE_MASK;
6988         base_offset -= base_page;
6989 @@ -330,11 +337,10 @@
6990         /*
6991          * If its allowed, we prefer memory mapped access.
6992          */
6993 -       command = ahd_pci_read_config(ahd->dev_softc, PCIR_COMMAND, 4);
6994 +       command = aic_pci_read_config(ahd->dev_softc, PCIR_COMMAND, 4);
6995         command &= ~(PCIM_CMD_PORTEN|PCIM_CMD_MEMEN);
6996         base = 0;
6997         maddr = NULL;
6998 -#ifdef MMAPIO
6999         error = ahd_linux_pci_reserve_mem_region(ahd, &base, &maddr);
7000         if (error == 0) {
7001                 ahd->platform_data->mem_busaddr = base;
7002 @@ -342,16 +348,16 @@
7003                 ahd->bshs[0].maddr = maddr;
7004                 ahd->tags[1] = BUS_SPACE_MEMIO;
7005                 ahd->bshs[1].maddr = maddr + 0x100;
7006 -               ahd_pci_write_config(ahd->dev_softc, PCIR_COMMAND,
7007 +               aic_pci_write_config(ahd->dev_softc, PCIR_COMMAND,
7008                                      command | PCIM_CMD_MEMEN, 4);
7009  
7010                 if (ahd_pci_test_register_access(ahd) != 0) {
7011  
7012                         printf("aic79xx: PCI Device %d:%d:%d "
7013                                "failed memory mapped test.  Using PIO.\n",
7014 -                              ahd_get_pci_bus(ahd->dev_softc),
7015 -                              ahd_get_pci_slot(ahd->dev_softc),
7016 -                              ahd_get_pci_function(ahd->dev_softc));
7017 +                              aic_get_pci_bus(ahd->dev_softc),
7018 +                              aic_get_pci_slot(ahd->dev_softc),
7019 +                              aic_get_pci_function(ahd->dev_softc));
7020                         iounmap((void *)((u_long)maddr & PAGE_MASK));
7021  #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,0)
7022                         release_mem_region(ahd->platform_data->mem_busaddr,
7023 @@ -364,12 +370,11 @@
7024         } else if (bootverbose) {
7025                 printf("aic79xx: PCI%d:%d:%d MEM region 0x%lx "
7026                        "unavailable. Cannot memory map device.\n",
7027 -                      ahd_get_pci_bus(ahd->dev_softc),
7028 -                      ahd_get_pci_slot(ahd->dev_softc),
7029 -                      ahd_get_pci_function(ahd->dev_softc),
7030 +                      aic_get_pci_bus(ahd->dev_softc),
7031 +                      aic_get_pci_slot(ahd->dev_softc),
7032 +                      aic_get_pci_function(ahd->dev_softc),
7033                        base);
7034         }
7035 -#endif
7036  
7037         if (maddr == NULL) {
7038                 u_long   base2;
7039 @@ -384,13 +389,13 @@
7040                 } else {
7041                         printf("aic79xx: PCI%d:%d:%d IO regions 0x%lx and 0x%lx"
7042                                "unavailable. Cannot map device.\n",
7043 -                              ahd_get_pci_bus(ahd->dev_softc),
7044 -                              ahd_get_pci_slot(ahd->dev_softc),
7045 -                              ahd_get_pci_function(ahd->dev_softc),
7046 +                              aic_get_pci_bus(ahd->dev_softc),
7047 +                              aic_get_pci_slot(ahd->dev_softc),
7048 +                              aic_get_pci_function(ahd->dev_softc),
7049                                base, base2);
7050                 }
7051         }
7052 -       ahd_pci_write_config(ahd->dev_softc, PCIR_COMMAND, command, 4);
7053 +       aic_pci_write_config(ahd->dev_softc, PCIR_COMMAND, command, 4);
7054         return (error);
7055  }
7056  
7057 @@ -399,49 +404,10 @@
7058  {
7059         int error;
7060  
7061 -       error = request_irq(ahd->dev_softc->irq, ahd_linux_isr,
7062 +       error = request_irq(aic_pci_dev(ahd)->irq, ahd_linux_isr,
7063                             SA_SHIRQ, "aic79xx", ahd);
7064         if (error == 0)
7065 -               ahd->platform_data->irq = ahd->dev_softc->irq;
7066 +               ahd->platform_data->irq = aic_pci_dev(ahd)->irq;
7067         
7068         return (-error);
7069  }
7070 -
7071 -void
7072 -ahd_power_state_change(struct ahd_softc *ahd, ahd_power_state new_state)
7073 -{
7074 -#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,0)
7075 -       pci_set_power_state(ahd->dev_softc, new_state);
7076 -#else
7077 -       uint32_t cap;
7078 -       u_int cap_offset;
7079 -
7080 -       /*
7081 -        * Traverse the capability list looking for
7082 -        * the power management capability.
7083 -        */
7084 -       cap = 0;
7085 -       cap_offset = ahd_pci_read_config(ahd->dev_softc,
7086 -                                        PCIR_CAP_PTR, /*bytes*/1);
7087 -       while (cap_offset != 0) {
7088 -
7089 -               cap = ahd_pci_read_config(ahd->dev_softc,
7090 -                                         cap_offset, /*bytes*/4);
7091 -               if ((cap & 0xFF) == 1
7092 -                && ((cap >> 16) & 0x3) > 0) {
7093 -                       uint32_t pm_control;
7094 -
7095 -                       pm_control = ahd_pci_read_config(ahd->dev_softc,
7096 -                                                        cap_offset + 4,
7097 -                                                        /*bytes*/4);
7098 -                       pm_control &= ~0x3;
7099 -                       pm_control |= new_state;
7100 -                       ahd_pci_write_config(ahd->dev_softc,
7101 -                                            cap_offset + 4,
7102 -                                            pm_control, /*bytes*/2);
7103 -                       break;
7104 -               }
7105 -               cap_offset = (cap >> 8) & 0xFF;
7106 -       }
7107 -#endif 
7108 -}
7109 diff -urN linux-2.4.24.org/drivers/scsi/aic7xxx/aic79xx_pci.c linux-2.4.24/drivers/scsi/aic7xxx/aic79xx_pci.c
7110 --- linux-2.4.24.org/drivers/scsi/aic7xxx/aic79xx_pci.c 2004-01-08 11:57:43.051997102 +0100
7111 +++ linux-2.4.24/drivers/scsi/aic7xxx/aic79xx_pci.c     2003-12-22 22:46:59.000000000 +0100
7112 @@ -75,13 +75,13 @@
7113  #define ID_AHA_29320ALP                        0x8017900500449005ull
7114  
7115  #define ID_AIC7901A                    0x801E9005FFFF9005ull
7116 -#define ID_AHA_29320                   0x8012900500429005ull
7117 -#define ID_AHA_29320B                  0x8013900500439005ull
7118  #define ID_AHA_29320LP                 0x8014900500449005ull
7119  
7120  #define ID_AIC7902                     0x801F9005FFFF9005ull
7121  #define ID_AIC7902_B                   0x801D9005FFFF9005ull
7122  #define ID_AHA_39320                   0x8010900500409005ull
7123 +#define ID_AHA_29320                   0x8012900500429005ull
7124 +#define ID_AHA_29320B                  0x8013900500439005ull
7125  #define ID_AHA_39320_B                 0x8015900500409005ull
7126  #define ID_AHA_39320A                  0x8016900500409005ull
7127  #define ID_AHA_39320D                  0x8011900500419005ull
7128 @@ -117,6 +117,7 @@
7129  static ahd_device_setup_t ahd_aic7901_setup;
7130  static ahd_device_setup_t ahd_aic7901A_setup;
7131  static ahd_device_setup_t ahd_aic7902_setup;
7132 +static ahd_device_setup_t ahd_aic790X_setup;
7133  
7134  struct ahd_pci_identity ahd_pci_ident_table [] =
7135  {
7136 @@ -135,24 +136,24 @@
7137         },
7138         /* aic7901A based controllers */
7139         {
7140 -               ID_AHA_29320,
7141 +               ID_AHA_29320LP,
7142                 ID_ALL_MASK,
7143 -               "Adaptec 29320 Ultra320 SCSI adapter",
7144 +               "Adaptec 29320LP Ultra320 SCSI adapter",
7145                 ahd_aic7901A_setup
7146         },
7147 +       /* aic7902 based controllers */ 
7148         {
7149 -               ID_AHA_29320B,
7150 +               ID_AHA_29320,
7151                 ID_ALL_MASK,
7152 -               "Adaptec 29320B Ultra320 SCSI adapter",
7153 -               ahd_aic7901A_setup
7154 +               "Adaptec 29320 Ultra320 SCSI adapter",
7155 +               ahd_aic7902_setup
7156         },
7157         {
7158 -               ID_AHA_29320LP,
7159 +               ID_AHA_29320B,
7160                 ID_ALL_MASK,
7161 -               "Adaptec 29320LP Ultra320 SCSI adapter",
7162 -               ahd_aic7901A_setup
7163 +               "Adaptec 29320B Ultra320 SCSI adapter",
7164 +               ahd_aic7902_setup
7165         },
7166 -       /* aic7902 based controllers */ 
7167         {
7168                 ID_AHA_39320,
7169                 ID_ALL_MASK,
7170 @@ -195,18 +196,6 @@
7171                 "Adaptec (HP OEM) 39320D Ultra320 SCSI adapter",
7172                 ahd_aic7902_setup
7173         },
7174 -       {
7175 -               ID_AHA_29320,
7176 -               ID_ALL_MASK,
7177 -               "Adaptec 29320 Ultra320 SCSI adapter",
7178 -               ahd_aic7902_setup
7179 -       },
7180 -       {
7181 -               ID_AHA_29320B,
7182 -               ID_ALL_MASK,
7183 -               "Adaptec 29320B Ultra320 SCSI adapter",
7184 -               ahd_aic7902_setup
7185 -       },
7186         /* Generic chip probes for devices we don't know 'exactly' */
7187         {
7188                 ID_AIC7901 & ID_DEV_VENDOR_MASK,
7189 @@ -274,7 +263,7 @@
7190  static void    ahd_pci_split_intr(struct ahd_softc *ahd, u_int intstat);
7191  
7192  struct ahd_pci_identity *
7193 -ahd_find_pci_device(ahd_dev_softc_t pci)
7194 +ahd_find_pci_device(aic_dev_softc_t pci)
7195  {
7196         uint64_t  full_id;
7197         uint16_t  device;
7198 @@ -284,10 +273,10 @@
7199         struct    ahd_pci_identity *entry;
7200         u_int     i;
7201  
7202 -       vendor = ahd_pci_read_config(pci, PCIR_DEVVENDOR, /*bytes*/2);
7203 -       device = ahd_pci_read_config(pci, PCIR_DEVICE, /*bytes*/2);
7204 -       subvendor = ahd_pci_read_config(pci, PCIR_SUBVEND_0, /*bytes*/2);
7205 -       subdevice = ahd_pci_read_config(pci, PCIR_SUBDEV_0, /*bytes*/2);
7206 +       vendor = aic_pci_read_config(pci, PCIR_DEVVENDOR, /*bytes*/2);
7207 +       device = aic_pci_read_config(pci, PCIR_DEVICE, /*bytes*/2);
7208 +       subvendor = aic_pci_read_config(pci, PCIR_SUBVEND_0, /*bytes*/2);
7209 +       subdevice = aic_pci_read_config(pci, PCIR_SUBDEV_0, /*bytes*/2);
7210         full_id = ahd_compose_id(device,
7211                                  vendor,
7212                                  subdevice,
7213 @@ -320,7 +309,7 @@
7214         /*
7215          * Record if this is an HP board.
7216          */
7217 -       subvendor = ahd_pci_read_config(ahd->dev_softc,
7218 +       subvendor = aic_pci_read_config(ahd->dev_softc,
7219                                         PCIR_SUBVEND_0, /*bytes*/2);
7220         if (subvendor == SUBID_HP)
7221                 ahd->flags |= AHD_HP_BOARD;
7222 @@ -329,7 +318,7 @@
7223         if (error != 0)
7224                 return (error);
7225         
7226 -       devconfig = ahd_pci_read_config(ahd->dev_softc, DEVCONFIG, /*bytes*/4);
7227 +       devconfig = aic_pci_read_config(ahd->dev_softc, DEVCONFIG, /*bytes*/4);
7228         if ((devconfig & PCIXINITPAT) == PCIXINIT_PCI33_66) {
7229                 ahd->chip |= AHD_PCI;
7230                 /* Disable PCIX workarounds when running in PCI mode. */
7231 @@ -339,7 +328,7 @@
7232         }
7233         ahd->bus_description = pci_bus_modes[PCI_BUS_MODES_INDEX(devconfig)];
7234  
7235 -       ahd_power_state_change(ahd, AHD_POWER_STATE_D0);
7236 +       aic_power_state_change(ahd, AIC_POWER_STATE_D0);
7237  
7238         error = ahd_pci_map_registers(ahd);
7239         if (error != 0)
7240 @@ -357,17 +346,17 @@
7241                 if (bootverbose)
7242                         printf("%s: Enabling 39Bit Addressing\n",
7243                                ahd_name(ahd));
7244 -               devconfig = ahd_pci_read_config(ahd->dev_softc,
7245 +               devconfig = aic_pci_read_config(ahd->dev_softc,
7246                                                 DEVCONFIG, /*bytes*/4);
7247                 devconfig |= DACEN;
7248 -               ahd_pci_write_config(ahd->dev_softc, DEVCONFIG,
7249 +               aic_pci_write_config(ahd->dev_softc, DEVCONFIG,
7250                                      devconfig, /*bytes*/4);
7251         }
7252         
7253         /* Ensure busmastering is enabled */
7254 -       command = ahd_pci_read_config(ahd->dev_softc, PCIR_COMMAND, /*bytes*/2);
7255 +       command = aic_pci_read_config(ahd->dev_softc, PCIR_COMMAND, /*bytes*/2);
7256         command |= PCIM_CMD_BUSMASTEREN;
7257 -       ahd_pci_write_config(ahd->dev_softc, PCIR_COMMAND, command, /*bytes*/2);
7258 +       aic_pci_write_config(ahd->dev_softc, PCIR_COMMAND, command, /*bytes*/2);
7259  
7260         error = ahd_softc_init(ahd);
7261         if (error != 0)
7262 @@ -380,7 +369,7 @@
7263                 return (ENXIO);
7264  
7265         ahd->pci_cachesize =
7266 -           ahd_pci_read_config(ahd->dev_softc, CSIZE_LATTIME,
7267 +           aic_pci_read_config(ahd->dev_softc, CSIZE_LATTIME,
7268                                 /*bytes*/1) & CACHESIZE;
7269         ahd->pci_cachesize *= 4;
7270  
7271 @@ -430,8 +419,8 @@
7272          * Enable PCI error interrupt status, but suppress NMIs
7273          * generated by SERR raised due to target aborts.
7274          */
7275 -       cmd = ahd_pci_read_config(ahd->dev_softc, PCIR_COMMAND, /*bytes*/2);
7276 -       ahd_pci_write_config(ahd->dev_softc, PCIR_COMMAND,
7277 +       cmd = aic_pci_read_config(ahd->dev_softc, PCIR_COMMAND, /*bytes*/2);
7278 +       aic_pci_write_config(ahd->dev_softc, PCIR_COMMAND,
7279                              cmd & ~PCIM_CMD_SERRESPEN, /*bytes*/2);
7280  
7281         /*
7282 @@ -451,8 +440,10 @@
7283          * or read prefetching could be initiated by the
7284          * CPU or host bridge.  Our device does not support
7285          * either, so look for data corruption and/or flaged
7286 -        * PCI errors.
7287 +        * PCI errors.  First pause without causing another
7288 +        * chip reset.
7289          */
7290 +       hcntrl &= ~CHIPRST;
7291         ahd_outb(ahd, HCNTRL, hcntrl|PAUSE);
7292         while (ahd_is_paused(ahd) == 0)
7293                 ;
7294 @@ -461,9 +452,9 @@
7295         ahd_set_modes(ahd, AHD_MODE_CFG, AHD_MODE_CFG);
7296         targpcistat = ahd_inb(ahd, TARGPCISTAT);
7297         ahd_outb(ahd, TARGPCISTAT, targpcistat);
7298 -       pci_status1 = ahd_pci_read_config(ahd->dev_softc,
7299 +       pci_status1 = aic_pci_read_config(ahd->dev_softc,
7300                                           PCIR_STATUS + 1, /*bytes*/1);
7301 -       ahd_pci_write_config(ahd->dev_softc, PCIR_STATUS + 1,
7302 +       aic_pci_write_config(ahd->dev_softc, PCIR_STATUS + 1,
7303                              pci_status1, /*bytes*/1);
7304         ahd_set_modes(ahd, AHD_MODE_SCSI, AHD_MODE_SCSI);
7305         ahd_outb(ahd, CLRINT, CLRPCIINT);
7306 @@ -492,14 +483,14 @@
7307  
7308                 /* Silently clear any latched errors. */
7309                 ahd_outb(ahd, TARGPCISTAT, targpcistat);
7310 -               pci_status1 = ahd_pci_read_config(ahd->dev_softc,
7311 +               pci_status1 = aic_pci_read_config(ahd->dev_softc,
7312                                                   PCIR_STATUS + 1, /*bytes*/1);
7313 -               ahd_pci_write_config(ahd->dev_softc, PCIR_STATUS + 1,
7314 +               aic_pci_write_config(ahd->dev_softc, PCIR_STATUS + 1,
7315                                      pci_status1, /*bytes*/1);
7316                 ahd_outb(ahd, CLRINT, CLRPCIINT);
7317         }
7318         ahd_outb(ahd, SEQCTL0, PERRORDIS|FAILDIS);
7319 -       ahd_pci_write_config(ahd->dev_softc, PCIR_COMMAND, cmd, /*bytes*/2);
7320 +       aic_pci_write_config(ahd->dev_softc, PCIR_COMMAND, cmd, /*bytes*/2);
7321         return (error);
7322  }
7323  
7324 @@ -648,14 +639,14 @@
7325         uint8_t  termctl;
7326         uint32_t devconfig;
7327  
7328 -       devconfig = ahd_pci_read_config(ahd->dev_softc, DEVCONFIG, /*bytes*/4);
7329 +       devconfig = aic_pci_read_config(ahd->dev_softc, DEVCONFIG, /*bytes*/4);
7330         devconfig &= ~STPWLEVEL;
7331         if ((ahd->flags & AHD_STPWLEVEL_A) != 0)
7332                 devconfig |= STPWLEVEL;
7333         if (bootverbose)
7334                 printf("%s: STPWLEVEL is %s\n",
7335                        ahd_name(ahd), (devconfig & STPWLEVEL) ? "on" : "off");
7336 -       ahd_pci_write_config(ahd->dev_softc, DEVCONFIG, devconfig, /*bytes*/4);
7337 +       aic_pci_write_config(ahd->dev_softc, DEVCONFIG, devconfig, /*bytes*/4);
7338   
7339         /* Make sure current sensing is off. */
7340         if ((ahd->flags & AHD_CURRENT_SENSING) != 0) {
7341 @@ -700,6 +691,7 @@
7342          * Now set the termination based on what we found.
7343          */
7344         sxfrctl1 = ahd_inb(ahd, SXFRCTL1) & ~STPWEN;
7345 +       ahd->flags &= ~AHD_TERM_ENB_A;
7346         if ((termctl & FLX_TERMCTL_ENPRILOW) != 0) {
7347                 ahd->flags |= AHD_TERM_ENB_A;
7348                 sxfrctl1 |= STPWEN;
7349 @@ -832,9 +824,9 @@
7350                         }
7351                 }       
7352         }
7353 -       pci_status1 = ahd_pci_read_config(ahd->dev_softc,
7354 +       pci_status1 = aic_pci_read_config(ahd->dev_softc,
7355                                           PCIR_STATUS + 1, /*bytes*/1);
7356 -       ahd_pci_write_config(ahd->dev_softc, PCIR_STATUS + 1,
7357 +       aic_pci_write_config(ahd->dev_softc, PCIR_STATUS + 1,
7358                              pci_status1, /*bytes*/1);
7359         ahd_restore_modes(ahd, saved_modes);
7360         ahd_outb(ahd, CLRINT, CLRPCIINT);
7361 @@ -856,7 +848,7 @@
7362          * Check for splits in all modes.  Modes 0 and 1
7363          * additionally have SG engine splits to look at.
7364          */
7365 -       pcix_status = ahd_pci_read_config(ahd->dev_softc, PCIXR_STATUS,
7366 +       pcix_status = aic_pci_read_config(ahd->dev_softc, PCIXR_STATUS,
7367                                           /*bytes*/2);
7368         printf("%s: PCI Split Interrupt - PCI-X status = 0x%x\n",
7369                ahd_name(ahd), pcix_status);
7370 @@ -905,7 +897,7 @@
7371         /*
7372          * Clear PCI-X status bits.
7373          */
7374 -       ahd_pci_write_config(ahd->dev_softc, PCIXR_STATUS,
7375 +       aic_pci_write_config(ahd->dev_softc, PCIXR_STATUS,
7376                              pcix_status, /*bytes*/2);
7377         ahd_outb(ahd, CLRINT, CLRSPLTINT);
7378         ahd_restore_modes(ahd, saved_modes);
7379 @@ -914,44 +906,44 @@
7380  static int
7381  ahd_aic7901_setup(struct ahd_softc *ahd)
7382  {
7383 -       int error;
7384  
7385 -       error = ahd_aic7902_setup(ahd);
7386 -       if (error != 0)
7387 -               return (error);
7388         ahd->chip = AHD_AIC7901;
7389 -       return (0);
7390 +       ahd->features = AHD_AIC7901_FE;
7391 +       return (ahd_aic790X_setup(ahd));
7392  }
7393  
7394  static int
7395  ahd_aic7901A_setup(struct ahd_softc *ahd)
7396  {
7397 -       int error;
7398  
7399 -       error = ahd_aic7902_setup(ahd);
7400 -       if (error != 0)
7401 -               return (error);
7402         ahd->chip = AHD_AIC7901A;
7403 -       return (0);
7404 +       ahd->features = AHD_AIC7901A_FE;
7405 +       return (ahd_aic790X_setup(ahd));
7406  }
7407  
7408  static int
7409  ahd_aic7902_setup(struct ahd_softc *ahd)
7410  {
7411 -       ahd_dev_softc_t pci;
7412 +       ahd->chip = AHD_AIC7902;
7413 +       ahd->features = AHD_AIC7902_FE;
7414 +       return (ahd_aic790X_setup(ahd));
7415 +}
7416 +
7417 +static int
7418 +ahd_aic790X_setup(struct ahd_softc *ahd)
7419 +{
7420 +       aic_dev_softc_t pci;
7421         u_int rev;
7422  
7423         pci = ahd->dev_softc;
7424 -       rev = ahd_pci_read_config(pci, PCIR_REVID, /*bytes*/1);
7425 +       rev = aic_pci_read_config(pci, PCIR_REVID, /*bytes*/1);
7426         if (rev < ID_AIC7902_PCI_REV_A4) {
7427                 printf("%s: Unable to attach to unsupported chip revision %d\n",
7428                        ahd_name(ahd), rev);
7429 -               ahd_pci_write_config(pci, PCIR_COMMAND, 0, /*bytes*/2);
7430 +               aic_pci_write_config(pci, PCIR_COMMAND, 0, /*bytes*/2);
7431                 return (ENXIO);
7432         }
7433 -       ahd->channel = ahd_get_pci_function(pci) + 'A';
7434 -       ahd->chip = AHD_AIC7902;
7435 -       ahd->features = AHD_AIC7902_FE;
7436 +       ahd->channel = aic_get_pci_function(pci) + 'A';
7437         if (rev < ID_AIC7902_PCI_REV_B0) {
7438                 /*
7439                  * Enable A series workarounds.
7440 @@ -979,9 +971,14 @@
7441                 u_int devconfig1;
7442  
7443                 ahd->features |= AHD_RTI|AHD_NEW_IOCELL_OPTS
7444 -                             |  AHD_NEW_DFCNTRL_OPTS;
7445 -               ahd->bugs |= AHD_LQOOVERRUN_BUG|AHD_ABORT_LQI_BUG
7446 -                         |  AHD_INTCOLLISION_BUG|AHD_EARLY_REQ_BUG;
7447 +                             |  AHD_NEW_DFCNTRL_OPTS|AHD_FAST_CDB_DELIVERY;
7448 +               ahd->bugs |= AHD_LQOOVERRUN_BUG|AHD_EARLY_REQ_BUG;
7449 +
7450 +               /*
7451 +                * Some issues have been resolved in the 7901B.
7452 +                */
7453 +               if ((ahd->features & AHD_MULTI_FUNC) != 0)
7454 +                       ahd->bugs |= AHD_INTCOLLISION_BUG|AHD_ABORT_LQI_BUG;
7455  
7456                 /*
7457                  * IO Cell paramter setup.
7458 @@ -996,10 +993,10 @@
7459                  * XXX - Find out exactly what this does from the hardware
7460                  *       folks!
7461                  */
7462 -               devconfig1 = ahd_pci_read_config(pci, DEVCONFIG1, /*bytes*/1);
7463 -               ahd_pci_write_config(pci, DEVCONFIG1,
7464 +               devconfig1 = aic_pci_read_config(pci, DEVCONFIG1, /*bytes*/1);
7465 +               aic_pci_write_config(pci, DEVCONFIG1,
7466                                      devconfig1|PREQDIS, /*bytes*/1);
7467 -               devconfig1 = ahd_pci_read_config(pci, DEVCONFIG1, /*bytes*/1);
7468 +               devconfig1 = aic_pci_read_config(pci, DEVCONFIG1, /*bytes*/1);
7469         }
7470  
7471         return (0);
7472 diff -urN linux-2.4.24.org/drivers/scsi/aic7xxx/aic79xx_proc.c linux-2.4.24/drivers/scsi/aic7xxx/aic79xx_proc.c
7473 --- linux-2.4.24.org/drivers/scsi/aic7xxx/aic79xx_proc.c        2004-01-08 11:57:43.050997308 +0100
7474 +++ linux-2.4.24/drivers/scsi/aic7xxx/aic79xx_proc.c    2003-12-22 22:46:59.000000000 +0100
7475 @@ -37,7 +37,7 @@
7476   * String handling code courtesy of Gerard Roudier's <groudier@club-internet.fr>
7477   * sym driver.
7478   *
7479 - * $Id$
7480 + * $Id$
7481   */
7482  #include "aic79xx_osm.h"
7483  #include "aic79xx_inline.h"
7484 @@ -49,7 +49,7 @@
7485                                       u_int our_id, char channel,
7486                                       u_int target_id, u_int target_offset);
7487  static void    ahd_dump_device_state(struct info_str *info,
7488 -                                     struct ahd_linux_device *dev);
7489 +                                     struct aic_linux_device *dev);
7490  static int     ahd_proc_write_seeprom(struct ahd_softc *ahd,
7491                                        char *buffer, int length);
7492  
7493 @@ -166,7 +166,7 @@
7494                       u_int our_id, char channel, u_int target_id,
7495                       u_int target_offset)
7496  {
7497 -       struct  ahd_linux_target *targ;
7498 +       struct  aic_linux_target *targ;
7499         struct  ahd_initiator_tinfo *tinfo;
7500         struct  ahd_tmode_tstate *tstate;
7501         int     lun;
7502 @@ -187,7 +187,7 @@
7503         copy_info(info, "\tTransmission Errors %ld\n", targ->errors_detected);
7504  
7505         for (lun = 0; lun < AHD_NUM_LUNS; lun++) {
7506 -               struct ahd_linux_device *dev;
7507 +               struct aic_linux_device *dev;
7508  
7509                 dev = targ->devices[lun];
7510  
7511 @@ -199,7 +199,7 @@
7512  }
7513  
7514  static void
7515 -ahd_dump_device_state(struct info_str *info, struct ahd_linux_device *dev)
7516 +ahd_dump_device_state(struct info_str *info, struct aic_linux_device *dev)
7517  {
7518         copy_info(info, "\tChannel %c Target %d Lun %d Settings\n",
7519                   dev->target->channel + 'A', dev->target->target, dev->lun);
7520 diff -urN linux-2.4.24.org/drivers/scsi/aic7xxx/aic79xx_reg.h linux-2.4.24/drivers/scsi/aic7xxx/aic79xx_reg.h
7521 --- linux-2.4.24.org/drivers/scsi/aic7xxx/aic79xx_reg.h 2004-01-08 11:57:43.049997515 +0100
7522 +++ linux-2.4.24/drivers/scsi/aic7xxx/aic79xx_reg.h     2003-12-23 00:32:11.000000000 +0100
7523 @@ -2,7 +2,7 @@
7524   * DO NOT EDIT - This file is automatically generated
7525   *              from the following source files:
7526   *
7527 - * $Id$
7528 + * $Id$
7529   * $Id$
7530   */
7531  typedef int (ahd_reg_print_t)(u_int, u_int *, u_int);
7532 diff -urN linux-2.4.24.org/drivers/scsi/aic7xxx/aic79xx_reg_print.c linux-2.4.24/drivers/scsi/aic7xxx/aic79xx_reg_print.c
7533 --- linux-2.4.24.org/drivers/scsi/aic7xxx/aic79xx_reg_print.c   2004-01-08 11:57:43.047997928 +0100
7534 +++ linux-2.4.24/drivers/scsi/aic7xxx/aic79xx_reg_print.c       2003-12-23 00:32:11.000000000 +0100
7535 @@ -2,7 +2,7 @@
7536   * DO NOT EDIT - This file is automatically generated
7537   *              from the following source files:
7538   *
7539 - * $Id$
7540 + * $Id$
7541   * $Id$
7542   */
7543  
7544 diff -urN linux-2.4.24.org/drivers/scsi/aic7xxx/aic79xx.seq linux-2.4.24/drivers/scsi/aic7xxx/aic79xx.seq
7545 --- linux-2.4.24.org/drivers/scsi/aic7xxx/aic79xx.seq   2004-01-08 11:57:43.064994415 +0100
7546 +++ linux-2.4.24/drivers/scsi/aic7xxx/aic79xx.seq       2003-12-22 22:46:59.000000000 +0100
7547 @@ -40,7 +40,7 @@
7548   * $FreeBSD$
7549   */
7550  
7551 -VERSION = "$Id$"
7552 +VERSION = "$Id$"
7553  PATCH_ARG_LIST = "struct ahd_softc *ahd"
7554  PREFIX = "ahd_"
7555  
7556 @@ -90,6 +90,13 @@
7557         test    SSTAT2, NONPACKREQ jz . + 2;
7558         call    unexpected_nonpkt_phase_find_ctxt;
7559         if ((ahd->bugs & AHD_FAINT_LED_BUG) != 0) {
7560 +               /*
7561 +                * On Rev A. hardware, the busy LED is only
7562 +                * turned on automaically during selections
7563 +                * and re-selections.  Make the LED status
7564 +                * more useful by forcing it to be on so
7565 +                * long as one of our data FIFOs is active.
7566 +                */
7567                 and     A, FIFO0FREE|FIFO1FREE, DFFSTAT;
7568                 cmp     A, FIFO0FREE|FIFO1FREE jne . + 3;
7569                 and     SBLKCTL, ~DIAGLEDEN|DIAGLEDON;
7570 @@ -101,9 +108,9 @@
7571         call    idle_loop_cchan;
7572         jmp     idle_loop;
7573  
7574 -BEGIN_CRITICAL;
7575  idle_loop_gsfifo:
7576         SET_MODE(M_SCSI, M_SCSI)
7577 +BEGIN_CRITICAL;
7578  idle_loop_gsfifo_in_scsi_mode:
7579         test    LQISTAT2, LQIGSAVAIL jz return;
7580         /*
7581 @@ -152,25 +159,28 @@
7582  
7583  idle_loop_service_fifos:
7584         SET_MODE(M_DFF0, M_DFF0)
7585 +BEGIN_CRITICAL;
7586         test    LONGJMP_ADDR[1], INVALID_ADDR jnz idle_loop_next_fifo;
7587         call    longjmp;
7588 +END_CRITICAL;
7589  idle_loop_next_fifo:
7590         SET_MODE(M_DFF1, M_DFF1)
7591 +BEGIN_CRITICAL;
7592         test    LONGJMP_ADDR[1], INVALID_ADDR jz longjmp;
7593 +END_CRITICAL;
7594  return:
7595         ret;
7596  
7597  idle_loop_cchan:
7598         SET_MODE(M_CCHAN, M_CCHAN)
7599         test    QOFF_CTLSTA, HS_MAILBOX_ACT jz  hs_mailbox_empty;
7600 -       mov     LOCAL_HS_MAILBOX, HS_MAILBOX;
7601         or      QOFF_CTLSTA, HS_MAILBOX_ACT;
7602 +       mov     LOCAL_HS_MAILBOX, HS_MAILBOX;
7603  hs_mailbox_empty:
7604  BEGIN_CRITICAL;
7605         test    CCSCBCTL, CCARREN|CCSCBEN jz scbdma_idle;
7606         test    CCSCBCTL, CCSCBDIR jnz fetch_new_scb_inprog;
7607         test    CCSCBCTL, CCSCBDONE jz return;
7608 -END_CRITICAL;
7609         /* FALLTHROUGH */
7610  scbdma_tohost_done:
7611         test    CCSCBCTL, CCARREN jz fill_qoutfifo_dmadone;
7612 @@ -180,26 +190,18 @@
7613          * bad SCSI status (currently only for underruns), we
7614          * queue the SCB for normal completion.  Otherwise, we
7615          * wait until any select-out activity has halted, and
7616 -        * then notify the host so that the transaction can be
7617 -        * dealt with.
7618 +        * then queue the completion.
7619          */
7620 -       test    SCB_SCSI_STATUS, 0xff jnz scbdma_notify_host;
7621 -       and     CCSCBCTL, ~(CCARREN|CCSCBEN);
7622 -       bmov    COMPLETE_DMA_SCB_HEAD, SCB_NEXT_COMPLETE, 2;
7623 -       bmov    SCB_NEXT_COMPLETE, COMPLETE_SCB_HEAD, 2;
7624 -       bmov    COMPLETE_SCB_HEAD, SCBPTR, 2 ret;
7625 -scbdma_notify_host:
7626 +       test    SCB_SCSI_STATUS, 0xff jz scbdma_queue_completion;
7627         SET_MODE(M_SCSI, M_SCSI)
7628         test    SCSISEQ0, ENSELO jnz return;
7629         test    SSTAT0, (SELDO|SELINGO) jnz return;
7630         SET_MODE(M_CCHAN, M_CCHAN)
7631 -       /*
7632 -        * Remove SCB and notify host.
7633 -        */
7634 +scbdma_queue_completion:
7635         and     CCSCBCTL, ~(CCARREN|CCSCBEN);
7636         bmov    COMPLETE_DMA_SCB_HEAD, SCB_NEXT_COMPLETE, 2;
7637 -       SET_SEQINTCODE(BAD_SCB_STATUS)
7638 -       ret;
7639 +       bmov    SCB_NEXT_COMPLETE, COMPLETE_SCB_HEAD, 2;
7640 +       bmov    COMPLETE_SCB_HEAD, SCBPTR, 2 ret;
7641  fill_qoutfifo_dmadone:
7642         and     CCSCBCTL, ~(CCARREN|CCSCBEN);
7643         call    qoutfifo_updated;
7644 @@ -208,6 +210,7 @@
7645         test    QOFF_CTLSTA, SDSCB_ROLLOVR jz return;
7646         bmov    QOUTFIFO_NEXT_ADDR, SHARED_DATA_ADDR, 4;
7647         xor     QOUTFIFO_ENTRY_VALID_TAG, QOUTFIFO_ENTRY_VALID_TOGGLE ret;
7648 +END_CRITICAL;
7649  
7650  qoutfifo_updated:
7651         /*
7652 @@ -276,7 +279,7 @@
7653          * knows the correct location to store the SCB.
7654          * Set it to zero before processing the SCB.
7655          */
7656 -       mov     SCB_FIFO_USE_COUNT, ALLZEROS;
7657 +       clr     SCB_FIFO_USE_COUNT;
7658         /* Update the next SCB address to download. */
7659         bmov    NEXT_QUEUED_SCB_ADDR, SCB_NEXT_SCB_BUSADDR, 4;
7660         mvi     SCB_NEXT[1], SCB_LIST_NULL;
7661 @@ -490,14 +493,30 @@
7662  SET_SRC_MODE   M_SCSI;
7663  SET_DST_MODE   M_SCSI;
7664  select_in:
7665 +       if ((ahd->bugs & AHD_FAINT_LED_BUG) != 0) {
7666 +               /*
7667 +                * On Rev A. hardware, the busy LED is only
7668 +                * turned on automaically during selections
7669 +                * and re-selections.  Make the LED status
7670 +                * more useful by forcing it to be on from
7671 +                * the point of selection until our idle
7672 +                * loop determines that neither of our FIFOs
7673 +                * are busy.  This handles the non-packetized
7674 +                * case nicely as we will not return to the
7675 +                * idle loop until the busfree at the end of
7676 +                * each transaction.
7677 +                */
7678 +               or      SBLKCTL, DIAGLEDEN|DIAGLEDON;
7679 +       }
7680         if ((ahd->bugs & AHD_BUSFREEREV_BUG) != 0) {
7681                 /*
7682 -                * This exposes a window whereby a
7683 -                * busfree just after a selection will
7684 -                * be missed, but there is no other safe
7685 -                * way to enable busfree detection if
7686 -                * the busfreerev function is broken.
7687 +                * Test to ensure that the bus has not
7688 +                * already gone free prior to clearing
7689 +                * any stale busfree status.  This avoids
7690 +                * a window whereby a busfree just after
7691 +                * a selection could be missed.
7692                  */
7693 +               test    SCSISIGI, BSYI jz . + 2;
7694                 mvi     CLRSINT1,CLRBUSFREE;
7695                 or      SIMODE1, ENBUSFREE;
7696         }
7697 @@ -527,6 +546,21 @@
7698  SET_DST_MODE   M_SCSI;
7699  select_out:
7700  BEGIN_CRITICAL;
7701 +       if ((ahd->bugs & AHD_FAINT_LED_BUG) != 0) {
7702 +               /*
7703 +                * On Rev A. hardware, the busy LED is only
7704 +                * turned on automaically during selections
7705 +                * and re-selections.  Make the LED status
7706 +                * more useful by forcing it to be on from
7707 +                * the point of re-selection until our idle
7708 +                * loop determines that neither of our FIFOs
7709 +                * are busy.  This handles the non-packetized
7710 +                * case nicely as we will not return to the
7711 +                * idle loop until the busfree at the end of
7712 +                * each transaction.
7713 +                */
7714 +               or      SBLKCTL, DIAGLEDEN|DIAGLEDON;
7715 +       }
7716         /* Clear out all SCBs that have been successfully sent. */
7717         if ((ahd->bugs & AHD_SENT_SCB_UPDATE_BUG) != 0) {
7718                 /*
7719 @@ -582,9 +616,6 @@
7720                 bmov    CURRSCB, SCBPTR, 2;
7721  curscb_ww_done:
7722         } else {
7723 -               /*
7724 -                * Untested - Verify with Rev B.
7725 -                */
7726                 bmov    SCBPTR, CURRSCB, 2;
7727         }
7728  
7729 @@ -651,12 +682,13 @@
7730         and     SCSISEQ0, ~ENSELO;
7731         if ((ahd->bugs & AHD_BUSFREEREV_BUG) != 0) {
7732                 /*
7733 -                * This exposes a window whereby a
7734 -                * busfree just after a selection will
7735 -                * be missed, but there is no other safe
7736 -                * way to enable busfree detection if
7737 -                * the busfreerev function is broken.
7738 +                * Test to ensure that the bus has not
7739 +                * already gone free prior to clearing
7740 +                * any stale busfree status.  This avoids
7741 +                * a window whereby a busfree just after
7742 +                * a selection could be missed.
7743                  */
7744 +               test    SCSISIGI, BSYI jz . + 2;
7745                 mvi     CLRSINT1,CLRBUSFREE;
7746                 or      SIMODE1, ENBUSFREE;
7747         }
7748 @@ -729,13 +761,38 @@
7749         mvi     DFCNTRL, SCSIEN;
7750  p_command_xfer:
7751         and     SEQ_FLAGS, ~NO_CDB_SENT;
7752 -       test    DFCNTRL, SCSIEN jnz .;
7753 +       if ((ahd->features & AHD_FAST_CDB_DELIVERY) != 0) {
7754 +               /*
7755 +                * To speed up CDB delivery in Rev B, all CDB acks
7756 +                * are "released" to the output sync as soon as the
7757 +                * command phase starts.  There is only one problem
7758 +                * with this approach.  If the target changes phase
7759 +                * before all data are sent, we have left over acks
7760 +                * that can go out on the bus in a data phase.  Due
7761 +                * to other chip contraints, this only happens if
7762 +                * the target goes to data-in, but if the acks go
7763 +                * out before we can test SDONE, we'll think that
7764 +                * the transfer has completed successfully.  Work
7765 +                * around this by taking advantage of the 400ns or
7766 +                * 800ns dead time between command phase and the REQ
7767 +                * of the new phase.  If the transfer has completed
7768 +                * successfully, SCSIEN should fall *long* before we
7769 +                * see a phase change.  We thus treat any phasemiss
7770 +                * that occurs before SCSIEN falls as an incomplete
7771 +                * transfer.
7772 +                */
7773 +               test    SSTAT1, PHASEMIS jnz p_command_xfer_failed;
7774 +               test    DFCNTRL, SCSIEN jnz . - 1;
7775 +       } else {
7776 +               test    DFCNTRL, SCSIEN jnz .;
7777 +       }
7778         /*
7779          * DMA Channel automatically disabled.
7780          * Don't allow a data phase if the command
7781          * was not fully transferred.
7782          */
7783         test    SSTAT2, SDONE jnz ITloop;
7784 +p_command_xfer_failed:
7785         or      SEQ_FLAGS, NO_CDB_SENT;
7786         jmp     ITloop;
7787  
7788 @@ -1061,8 +1118,10 @@
7789         test    SCB_SGPTR, SG_FULL_RESID jnz upload_scb;/* Never xfered */
7790         test    SCB_RESIDUAL_SGPTR, SG_LIST_NULL jz upload_scb;
7791  complete:
7792 +BEGIN_CRITICAL;
7793         bmov    SCB_NEXT_COMPLETE, COMPLETE_SCB_HEAD, 2;
7794         bmov    COMPLETE_SCB_HEAD, SCBPTR, 2 ret;
7795 +END_CRITICAL;
7796  bad_status:
7797         cmp     SCB_SCSI_STATUS, STATUS_PKT_SENSE je upload_scb;
7798         call    freeze_queue;
7799 @@ -1073,9 +1132,11 @@
7800          * it on the host.
7801          */
7802         bmov    SCB_TAG, SCBPTR, 2;
7803 +BEGIN_CRITICAL;
7804         bmov    SCB_NEXT_COMPLETE, COMPLETE_DMA_SCB_HEAD, 2;
7805         bmov    COMPLETE_DMA_SCB_HEAD, SCBPTR, 2;
7806         or      SCB_SGPTR, SG_STATUS_VALID ret;
7807 +END_CRITICAL;
7808  
7809  /*
7810   * Is it a disconnect message?  Set a flag in the SCB to remind us
7811 @@ -1122,8 +1183,18 @@
7812  await_busfree_clrchn:
7813         mvi     DFFSXFRCTL, CLRCHN;
7814  await_busfree_not_m_dff:
7815 -       call    clear_target_state;
7816 +       /* clear target specific flags */
7817 +       mvi     SEQ_FLAGS, NOT_IDENTIFIED|NO_CDB_SENT;
7818         test    SSTAT1,REQINIT|BUSFREE  jz .;
7819 +       /*
7820 +        * We only set BUSFREE status once either a new
7821 +        * phase has been detected or we are really
7822 +        * BUSFREE.  This allows the driver to know
7823 +        * that we are active on the bus even though
7824 +        * no identified transaction exists should a
7825 +        * timeout occur while awaiting busfree.
7826 +        */
7827 +       mvi     LASTPHASE, P_BUSFREE;
7828         test    SSTAT1, BUSFREE jnz idle_loop;
7829         SET_SEQINTCODE(MISSED_BUSFREE)
7830  
7831 @@ -1178,11 +1249,6 @@
7832         call    allocate_fifo;
7833         jmp     mesgin_done;
7834  
7835 -clear_target_state:
7836 -       mvi     LASTPHASE, P_BUSFREE;
7837 -       /* clear target specific flags */
7838 -       mvi     SEQ_FLAGS, NOT_IDENTIFIED|NO_CDB_SENT ret;
7839 -
7840  phase_lock:     
7841         if ((ahd->bugs & AHD_EARLY_REQ_BUG) != 0) {
7842                 /*
7843 @@ -1634,7 +1700,7 @@
7844                  * savepointer in the current FIFO.  We do this so that
7845                  * a pending CTXTDONE or SAVEPTR is visible in the active
7846                  * FIFO.  This status is the only way we can detect if we
7847 -                * have lost the race (e.g. host paused us) and our attepts
7848 +                * have lost the race (e.g. host paused us) and our attempts
7849                  * to disable the channel occurred after all REQs were
7850                  * already seen and acked (REQINIT never comes true).
7851                  */
7852 @@ -1643,7 +1709,7 @@
7853                 test    DFCNTRL, DIRECTION jz interrupt_return;
7854                 and     DFCNTRL, ~SCSIEN;
7855  snapshot_wait_data_valid:
7856 -               test    SEQINTSRC, (CTXTDONE|SAVEPTRS) jnz snapshot_data_valid;
7857 +               test    SEQINTSRC, (CTXTDONE|SAVEPTRS) jnz interrupt_return;
7858                 test    SSTAT1, REQINIT jz snapshot_wait_data_valid;
7859  snapshot_data_valid:
7860                 or      DFCNTRL, SCSIEN;
7861 @@ -1810,7 +1876,6 @@
7862         dec     SCB_FIFO_USE_COUNT;
7863         test    SCB_CONTROL, STATUS_RCVD jnz pkt_complete_scb_if_fifos_idle;
7864         mvi     DFFSXFRCTL, CLRCHN ret;
7865 -END_CRITICAL;
7866  
7867  /*
7868   * LAST_SEG_DONE status has been seen in the current FIFO.
7869 @@ -1819,7 +1884,6 @@
7870   * Check for overrun and see if we can complete this command.
7871   */
7872  pkt_last_seg_done:
7873 -BEGIN_CRITICAL;
7874         /*
7875          * Mark transfer as completed.
7876          */
7877 @@ -1959,12 +2023,14 @@
7878         test    SSTAT0, SELDO jnz return;
7879         mvi     SCBPTR[1], SCB_LIST_NULL;
7880  unexpected_nonpkt_phase:
7881 -       test    MODE_PTR, ~(MK_MODE(M_DFF1, M_DFF1)) jnz . + 3;
7882 +       test    MODE_PTR, ~(MK_MODE(M_DFF1, M_DFF1))
7883 +               jnz unexpected_nonpkt_mode_cleared;
7884  SET_SRC_MODE   M_DFF0;
7885  SET_DST_MODE   M_DFF0;
7886         or      LONGJMP_ADDR[1], INVALID_ADDR;
7887         dec     SCB_FIFO_USE_COUNT;
7888         mvi     DFFSXFRCTL, CLRCHN;
7889 +unexpected_nonpkt_mode_cleared:
7890         mvi     CLRSINT2, CLRNONPACKREQ;
7891         test    SCSIPHASE, ~(MSG_IN_PHASE|MSG_OUT_PHASE) jnz illegal_phase;
7892         SET_SEQINTCODE(ENTERING_NONPACK)
7893 diff -urN linux-2.4.24.org/drivers/scsi/aic7xxx/aic79xx_seq.h linux-2.4.24/drivers/scsi/aic7xxx/aic79xx_seq.h
7894 --- linux-2.4.24.org/drivers/scsi/aic7xxx/aic79xx_seq.h 2004-01-08 11:57:43.044998548 +0100
7895 +++ linux-2.4.24/drivers/scsi/aic7xxx/aic79xx_seq.h     2003-12-23 00:32:11.000000000 +0100
7896 @@ -2,25 +2,25 @@
7897   * DO NOT EDIT - This file is automatically generated
7898   *              from the following source files:
7899   *
7900 - * $Id$
7901 + * $Id$
7902   * $Id$
7903   */
7904  static uint8_t seqprog[] = {
7905         0xff, 0x02, 0x06, 0x78,
7906 -       0x00, 0xea, 0x50, 0x59,
7907 +       0x00, 0xea, 0x46, 0x59,
7908         0x01, 0xea, 0x04, 0x30,
7909         0xff, 0x04, 0x0c, 0x78,
7910 -       0x19, 0xea, 0x50, 0x59,
7911 +       0x19, 0xea, 0x46, 0x59,
7912         0x19, 0xea, 0x04, 0x00,
7913 -       0x33, 0xea, 0x44, 0x59,
7914 +       0x33, 0xea, 0x3a, 0x59,
7915         0x33, 0xea, 0x00, 0x00,
7916         0x60, 0x3a, 0x1a, 0x68,
7917         0x04, 0x47, 0x1b, 0x68,
7918         0xff, 0x21, 0x1b, 0x70,
7919 -       0x40, 0x4b, 0x92, 0x69,
7920 -       0x00, 0xe2, 0x54, 0x59,
7921 -       0x40, 0x4b, 0x92, 0x69,
7922 -       0x20, 0x4b, 0x82, 0x69,
7923 +       0x40, 0x4b, 0x8c, 0x69,
7924 +       0x00, 0xe2, 0x4a, 0x59,
7925 +       0x40, 0x4b, 0x8c, 0x69,
7926 +       0x20, 0x4b, 0x78, 0x69,
7927         0xfc, 0x42, 0x24, 0x78,
7928         0x10, 0x40, 0x24, 0x78,
7929         0x00, 0xe2, 0xc4, 0x5d,
7930 @@ -35,7 +35,7 @@
7931         0x00, 0xe2, 0x56, 0x58,
7932         0x00, 0xe2, 0x66, 0x58,
7933         0x00, 0xe2, 0x06, 0x40,
7934 -       0x33, 0xea, 0x44, 0x59,
7935 +       0x33, 0xea, 0x3a, 0x59,
7936         0x33, 0xea, 0x00, 0x00,
7937         0x01, 0x52, 0x64, 0x78,
7938         0x02, 0x58, 0x50, 0x31,
7939 @@ -43,62 +43,57 @@
7940         0xff, 0x97, 0x4f, 0x78,
7941         0x50, 0x4b, 0x4a, 0x68,
7942         0xbf, 0x3a, 0x74, 0x08,
7943 -       0x14, 0xea, 0x50, 0x59,
7944 +       0x14, 0xea, 0x46, 0x59,
7945         0x14, 0xea, 0x04, 0x00,
7946         0x08, 0x92, 0x25, 0x03,
7947         0xff, 0x90, 0x3f, 0x68,
7948 -       0x00, 0xe2, 0x56, 0x5b,
7949 +       0x00, 0xe2, 0x58, 0x5b,
7950         0x00, 0xe2, 0x3e, 0x40,
7951 -       0x00, 0xea, 0x44, 0x59,
7952 +       0x00, 0xea, 0x3a, 0x59,
7953         0x01, 0xea, 0x00, 0x30,
7954         0x80, 0xf9, 0x5e, 0x68,
7955 -       0x00, 0xe2, 0x42, 0x59,
7956 -       0x11, 0xea, 0x44, 0x59,
7957 +       0x00, 0xe2, 0x38, 0x59,
7958 +       0x11, 0xea, 0x3a, 0x59,
7959         0x11, 0xea, 0x00, 0x00,
7960 -       0x80, 0xf9, 0x42, 0x79,
7961 +       0x80, 0xf9, 0x38, 0x79,
7962         0xff, 0xea, 0xd4, 0x0d,
7963 -       0x22, 0xea, 0x44, 0x59,
7964 +       0x22, 0xea, 0x3a, 0x59,
7965         0x22, 0xea, 0x00, 0x00,
7966         0x10, 0x16, 0x70, 0x78,
7967 -       0x01, 0x0b, 0xa2, 0x32,
7968         0x10, 0x16, 0x2c, 0x00,
7969 -       0x18, 0xad, 0x00, 0x79,
7970 -       0x04, 0xad, 0xca, 0x68,
7971 +       0x01, 0x0b, 0xa2, 0x32,
7972 +       0x18, 0xad, 0xf6, 0x78,
7973 +       0x04, 0xad, 0xc0, 0x68,
7974         0x80, 0xad, 0x64, 0x78,
7975 -       0x10, 0xad, 0x98, 0x78,
7976 -       0xff, 0x88, 0x83, 0x68,
7977 -       0xe7, 0xad, 0x5a, 0x09,
7978 -       0x02, 0x8c, 0x59, 0x32,
7979 -       0x02, 0x28, 0x19, 0x33,
7980 -       0x02, 0xa8, 0x50, 0x36,
7981 -       0x33, 0xea, 0x44, 0x59,
7982 +       0x10, 0xad, 0x8e, 0x78,
7983 +       0xff, 0x88, 0x87, 0x78,
7984 +       0x33, 0xea, 0x3a, 0x59,
7985         0x33, 0xea, 0x00, 0x00,
7986         0x40, 0x3a, 0x64, 0x68,
7987         0x50, 0x4b, 0x64, 0x68,
7988 -       0x22, 0xea, 0x44, 0x59,
7989 +       0x22, 0xea, 0x3a, 0x59,
7990         0x22, 0xea, 0x00, 0x00,
7991         0xe7, 0xad, 0x5a, 0x09,
7992         0x02, 0x8c, 0x59, 0x32,
7993 -       0x1a, 0xea, 0x50, 0x59,
7994 -       0x1a, 0xea, 0x04, 0x00,
7995 -       0xff, 0xea, 0xd4, 0x0d,
7996 +       0x02, 0x28, 0x19, 0x33,
7997 +       0x02, 0xa8, 0x50, 0x36,
7998         0xe7, 0xad, 0x5a, 0x09,
7999 -       0x00, 0xe2, 0xa6, 0x58,
8000 +       0x00, 0xe2, 0x9c, 0x58,
8001         0xff, 0xea, 0x56, 0x02,
8002         0x04, 0x7c, 0x78, 0x32,
8003         0x20, 0x16, 0x64, 0x78,
8004         0x04, 0x38, 0x79, 0x32,
8005         0x80, 0x37, 0x6f, 0x16,
8006 -       0xff, 0x2d, 0xb5, 0x60,
8007 -       0xff, 0x29, 0xb5, 0x60,
8008 -       0x40, 0x51, 0xc5, 0x78,
8009 -       0xff, 0x4f, 0xb5, 0x68,
8010 +       0xff, 0x2d, 0xab, 0x60,
8011 +       0xff, 0x29, 0xab, 0x60,
8012 +       0x40, 0x51, 0xbb, 0x78,
8013 +       0xff, 0x4f, 0xab, 0x68,
8014         0xff, 0x4d, 0xc1, 0x19,
8015         0x00, 0x4e, 0xd5, 0x19,
8016 -       0x00, 0xe2, 0xc4, 0x50,
8017 +       0x00, 0xe2, 0xba, 0x50,
8018         0x01, 0x4c, 0xc1, 0x31,
8019         0x00, 0x50, 0xd5, 0x19,
8020 -       0x00, 0xe2, 0xc4, 0x48,
8021 +       0x00, 0xe2, 0xba, 0x48,
8022         0x80, 0x18, 0x64, 0x78,
8023         0x02, 0x4a, 0x1d, 0x30,
8024         0x10, 0xea, 0x18, 0x00,
8025 @@ -114,29 +109,29 @@
8026         0x01, 0x4e, 0x9d, 0x1a,
8027         0x00, 0x4f, 0x9f, 0x22,
8028         0x01, 0x94, 0x6d, 0x33,
8029 -       0x01, 0xea, 0x20, 0x33,
8030 +       0xff, 0xea, 0x20, 0x0b,
8031         0x04, 0xac, 0x49, 0x32,
8032         0xff, 0xea, 0x5a, 0x03,
8033         0xff, 0xea, 0x5e, 0x03,
8034         0x01, 0x10, 0xd4, 0x31,
8035 -       0x10, 0x92, 0xf5, 0x68,
8036 +       0x10, 0x92, 0xeb, 0x68,
8037         0x3d, 0x93, 0xc5, 0x29,
8038         0xfe, 0xe2, 0xc4, 0x09,
8039         0x01, 0xea, 0xc6, 0x01,
8040         0x02, 0xe2, 0xc8, 0x31,
8041         0x02, 0xec, 0x50, 0x31,
8042         0x02, 0xa0, 0xda, 0x31,
8043 -       0xff, 0xa9, 0xf4, 0x70,
8044 +       0xff, 0xa9, 0xea, 0x70,
8045         0x02, 0xa0, 0x58, 0x37,
8046 -       0xff, 0x21, 0xfd, 0x70,
8047 +       0xff, 0x21, 0xf3, 0x70,
8048         0x02, 0x22, 0x51, 0x31,
8049         0x02, 0xa0, 0x5c, 0x33,
8050         0x02, 0xa0, 0x44, 0x36,
8051         0x02, 0xa0, 0x40, 0x32,
8052         0x02, 0xa0, 0x44, 0x36,
8053 -       0x04, 0x47, 0x05, 0x69,
8054 -       0x40, 0x16, 0x30, 0x69,
8055 -       0xff, 0x2d, 0x35, 0x61,
8056 +       0x04, 0x47, 0xfb, 0x68,
8057 +       0x40, 0x16, 0x26, 0x69,
8058 +       0xff, 0x2d, 0x2b, 0x61,
8059         0xff, 0x29, 0x65, 0x70,
8060         0x01, 0x37, 0xc1, 0x31,
8061         0x02, 0x28, 0x55, 0x32,
8062 @@ -149,20 +144,20 @@
8063         0x01, 0x50, 0xa1, 0x1a,
8064         0xff, 0x4e, 0x9d, 0x1a,
8065         0xff, 0x4f, 0x9f, 0x22,
8066 -       0xff, 0x8d, 0x29, 0x71,
8067 -       0x80, 0xac, 0x28, 0x71,
8068 -       0x20, 0x16, 0x28, 0x69,
8069 +       0xff, 0x8d, 0x1f, 0x71,
8070 +       0x80, 0xac, 0x1e, 0x71,
8071 +       0x20, 0x16, 0x1e, 0x69,
8072         0x02, 0x8c, 0x51, 0x31,
8073 -       0x00, 0xe2, 0x12, 0x41,
8074 +       0x00, 0xe2, 0x08, 0x41,
8075         0x01, 0xac, 0x08, 0x31,
8076         0x09, 0xea, 0x5a, 0x01,
8077         0x02, 0x8c, 0x51, 0x32,
8078         0xff, 0xea, 0x1a, 0x07,
8079         0x04, 0x24, 0xf9, 0x30,
8080 -       0x1d, 0xea, 0x3a, 0x41,
8081 +       0x1d, 0xea, 0x30, 0x41,
8082         0x02, 0x2c, 0x51, 0x31,
8083         0x04, 0xa8, 0xf9, 0x30,
8084 -       0x19, 0xea, 0x3a, 0x41,
8085 +       0x19, 0xea, 0x30, 0x41,
8086         0x06, 0xea, 0x08, 0x81,
8087         0x01, 0xe2, 0x5a, 0x35,
8088         0x02, 0xf2, 0xf0, 0x35,
8089 @@ -180,25 +175,27 @@
8090         0x02, 0x20, 0xb9, 0x30,
8091         0x02, 0x20, 0x51, 0x31,
8092         0x4c, 0x93, 0xd7, 0x28,
8093 -       0x10, 0x92, 0x63, 0x79,
8094 +       0x10, 0x92, 0x59, 0x79,
8095         0x01, 0x6b, 0xc0, 0x30,
8096         0x02, 0x64, 0xc8, 0x00,
8097         0x40, 0x3a, 0x74, 0x04,
8098         0x00, 0xe2, 0x56, 0x58,
8099 -       0x33, 0xea, 0x44, 0x59,
8100 +       0x33, 0xea, 0x3a, 0x59,
8101         0x33, 0xea, 0x00, 0x00,
8102         0x30, 0x3f, 0xc0, 0x09,
8103 -       0x30, 0xe0, 0x64, 0x61,
8104 -       0x20, 0x3f, 0x7a, 0x69,
8105 -       0x10, 0x3f, 0x64, 0x79,
8106 +       0x30, 0xe0, 0x5a, 0x61,
8107 +       0x20, 0x3f, 0x70, 0x69,
8108 +       0x10, 0x3f, 0x5a, 0x79,
8109         0x02, 0xea, 0x7e, 0x00,
8110 -       0x00, 0xea, 0x44, 0x59,
8111 +       0x00, 0xea, 0x3a, 0x59,
8112         0x01, 0xea, 0x00, 0x30,
8113         0x02, 0x48, 0x51, 0x35,
8114         0x01, 0xea, 0x7e, 0x00,
8115 -       0x11, 0xea, 0x44, 0x59,
8116 +       0x11, 0xea, 0x3a, 0x59,
8117         0x11, 0xea, 0x00, 0x00,
8118         0x02, 0x48, 0x51, 0x35,
8119 +       0xc0, 0x4a, 0x94, 0x00,
8120 +       0x04, 0x41, 0x7e, 0x79,
8121         0x08, 0xea, 0x98, 0x00,
8122         0x08, 0x57, 0xae, 0x00,
8123         0x08, 0x3c, 0x78, 0x00,
8124 @@ -206,11 +203,12 @@
8125         0x0f, 0x67, 0xc0, 0x09,
8126         0x00, 0x34, 0x69, 0x02,
8127         0x20, 0xea, 0x96, 0x00,
8128 -       0x00, 0xe2, 0xf8, 0x41,
8129 -       0x40, 0x3a, 0xae, 0x69,
8130 +       0x00, 0xe2, 0xf6, 0x41,
8131 +       0xc0, 0x4a, 0x94, 0x00,
8132 +       0x40, 0x3a, 0xaa, 0x69,
8133         0x02, 0x55, 0x06, 0x68,
8134 -       0x02, 0x56, 0xae, 0x69,
8135 -       0xff, 0x5b, 0xae, 0x61,
8136 +       0x02, 0x56, 0xaa, 0x69,
8137 +       0xff, 0x5b, 0xaa, 0x61,
8138         0x02, 0x20, 0x51, 0x31,
8139         0x80, 0xea, 0xb2, 0x01,
8140         0x44, 0xea, 0x00, 0x00,
8141 @@ -218,39 +216,40 @@
8142         0x33, 0xea, 0x00, 0x00,
8143         0xff, 0xea, 0xb2, 0x09,
8144         0xff, 0xe0, 0xc0, 0x19,
8145 -       0xff, 0xe0, 0xb0, 0x79,
8146 +       0xff, 0xe0, 0xac, 0x79,
8147         0x02, 0xac, 0x51, 0x31,
8148 -       0x00, 0xe2, 0xa6, 0x41,
8149 +       0x00, 0xe2, 0xa2, 0x41,
8150         0x02, 0x5e, 0x50, 0x31,
8151         0x02, 0xa8, 0xb8, 0x30,
8152         0x02, 0x5c, 0x50, 0x31,
8153 -       0xff, 0xad, 0xc1, 0x71,
8154 +       0xff, 0xad, 0xbd, 0x71,
8155         0x02, 0xac, 0x41, 0x31,
8156         0x02, 0x22, 0x51, 0x31,
8157         0x02, 0xa0, 0x5c, 0x33,
8158         0x02, 0xa0, 0x44, 0x32,
8159 -       0x00, 0xe2, 0xca, 0x41,
8160 -       0x10, 0x92, 0xcb, 0x69,
8161 +       0x00, 0xe2, 0xc6, 0x41,
8162 +       0x10, 0x92, 0xc7, 0x69,
8163         0x3d, 0x93, 0xc9, 0x29,
8164         0x01, 0xe4, 0xc8, 0x01,
8165         0x01, 0xea, 0xca, 0x01,
8166         0xff, 0xea, 0xda, 0x01,
8167         0x02, 0x20, 0x51, 0x31,
8168         0x02, 0xae, 0x41, 0x32,
8169 -       0xff, 0x21, 0xd3, 0x61,
8170 +       0xff, 0x21, 0xcf, 0x61,
8171         0xff, 0xea, 0x46, 0x02,
8172         0x02, 0x5c, 0x50, 0x31,
8173         0x40, 0xea, 0x96, 0x00,
8174         0x02, 0x56, 0xcc, 0x6d,
8175         0x01, 0x55, 0xcc, 0x6d,
8176 -       0x10, 0x92, 0xdf, 0x79,
8177 -       0x10, 0x40, 0xe8, 0x69,
8178 -       0x01, 0x56, 0xe8, 0x79,
8179 +       0x10, 0x92, 0xdb, 0x79,
8180 +       0x10, 0x40, 0xe4, 0x69,
8181 +       0x01, 0x56, 0xe4, 0x79,
8182         0xff, 0x97, 0x07, 0x78,
8183 -       0x13, 0xea, 0x50, 0x59,
8184 +       0x13, 0xea, 0x46, 0x59,
8185         0x13, 0xea, 0x04, 0x00,
8186         0x00, 0xe2, 0x06, 0x40,
8187         0xbf, 0x3a, 0x74, 0x08,
8188 +       0x04, 0x41, 0xea, 0x79,
8189         0x08, 0xea, 0x98, 0x00,
8190         0x08, 0x57, 0xae, 0x00,
8191         0x01, 0x93, 0x69, 0x32,
8192 @@ -261,103 +260,105 @@
8193         0x00, 0xe2, 0xb8, 0x5b,
8194         0x01, 0x36, 0xc1, 0x31,
8195         0x9f, 0xe0, 0x4c, 0x7c,
8196 -       0x80, 0xe0, 0x0c, 0x72,
8197 -       0xa0, 0xe0, 0x44, 0x72,
8198 -       0xc0, 0xe0, 0x3a, 0x72,
8199 -       0xe0, 0xe0, 0x74, 0x72,
8200 -       0x01, 0xea, 0x50, 0x59,
8201 +       0x80, 0xe0, 0x0a, 0x72,
8202 +       0xa0, 0xe0, 0x46, 0x72,
8203 +       0xc0, 0xe0, 0x3c, 0x72,
8204 +       0xe0, 0xe0, 0x76, 0x72,
8205 +       0x01, 0xea, 0x46, 0x59,
8206         0x01, 0xea, 0x04, 0x00,
8207 -       0x00, 0xe2, 0xf8, 0x41,
8208 -       0x80, 0x33, 0x13, 0x7a,
8209 -       0x03, 0xea, 0x50, 0x59,
8210 +       0x00, 0xe2, 0xf6, 0x41,
8211 +       0x80, 0x33, 0x11, 0x7a,
8212 +       0x03, 0xea, 0x46, 0x59,
8213         0x03, 0xea, 0x04, 0x00,
8214 -       0xee, 0x00, 0x1a, 0x6a,
8215 +       0xee, 0x00, 0x18, 0x6a,
8216         0x05, 0xea, 0xb4, 0x00,
8217 -       0x33, 0xea, 0x44, 0x59,
8218 +       0x33, 0xea, 0x3a, 0x59,
8219         0x33, 0xea, 0x00, 0x00,
8220         0x02, 0xa8, 0x90, 0x32,
8221 -       0x00, 0xe2, 0x6a, 0x59,
8222 +       0x00, 0xe2, 0x60, 0x59,
8223         0xef, 0x96, 0xd5, 0x19,
8224 -       0x00, 0xe2, 0x2a, 0x52,
8225 +       0x00, 0xe2, 0x28, 0x52,
8226         0x09, 0x80, 0xe1, 0x30,
8227         0x02, 0xea, 0x36, 0x00,
8228         0xa8, 0xea, 0x32, 0x00,
8229 -       0x00, 0xe2, 0x30, 0x42,
8230 +       0x00, 0xe2, 0x2e, 0x42,
8231         0x01, 0x96, 0xd1, 0x30,
8232         0x10, 0x80, 0x89, 0x31,
8233         0x20, 0xea, 0x32, 0x00,
8234         0xbf, 0x33, 0x67, 0x0a,
8235 -       0x20, 0x19, 0x32, 0x6a,
8236 -       0x02, 0x4d, 0xf8, 0x69,
8237 +       0x10, 0x4c, 0x38, 0x6a,
8238 +       0x20, 0x19, 0x30, 0x6a,
8239 +       0x20, 0x19, 0x34, 0x6a,
8240 +       0x02, 0x4d, 0xf6, 0x69,
8241         0x40, 0x33, 0x67, 0x02,
8242 -       0x00, 0xe2, 0xf8, 0x41,
8243 -       0x80, 0x33, 0xb5, 0x6a,
8244 +       0x00, 0xe2, 0xf6, 0x41,
8245 +       0x80, 0x33, 0xb7, 0x6a,
8246         0x01, 0x44, 0x10, 0x33,
8247         0x08, 0x92, 0x25, 0x03,
8248 -       0x00, 0xe2, 0xf8, 0x41,
8249 +       0x00, 0xe2, 0xf6, 0x41,
8250         0x10, 0xea, 0x80, 0x00,
8251         0x01, 0x31, 0xc5, 0x31,
8252 -       0x80, 0xe2, 0x60, 0x62,
8253 -       0x10, 0x92, 0x85, 0x6a,
8254 +       0x80, 0xe2, 0x62, 0x62,
8255 +       0x10, 0x92, 0x87, 0x6a,
8256         0xc0, 0x94, 0xc5, 0x01,
8257 -       0x40, 0x92, 0x51, 0x6a,
8258 +       0x40, 0x92, 0x53, 0x6a,
8259         0xbf, 0xe2, 0xc4, 0x09,
8260 -       0x20, 0x92, 0x65, 0x7a,
8261 +       0x20, 0x92, 0x67, 0x7a,
8262         0x01, 0xe2, 0x88, 0x30,
8263         0x00, 0xe2, 0xb8, 0x5b,
8264 -       0xa0, 0x36, 0x6d, 0x62,
8265 +       0xa0, 0x36, 0x6f, 0x62,
8266         0x23, 0x92, 0x89, 0x08,
8267         0x00, 0xe2, 0xb8, 0x5b,
8268 -       0xa0, 0x36, 0x6d, 0x62,
8269 -       0x00, 0xa8, 0x64, 0x42,
8270 -       0xff, 0xe2, 0x64, 0x62,
8271 -       0x00, 0xe2, 0x84, 0x42,
8272 +       0xa0, 0x36, 0x6f, 0x62,
8273 +       0x00, 0xa8, 0x66, 0x42,
8274 +       0xff, 0xe2, 0x66, 0x62,
8275 +       0x00, 0xe2, 0x86, 0x42,
8276         0x40, 0xea, 0x98, 0x00,
8277         0x01, 0xe2, 0x88, 0x30,
8278         0x00, 0xe2, 0xb8, 0x5b,
8279 -       0xa0, 0x36, 0x43, 0x72,
8280 +       0xa0, 0x36, 0x45, 0x72,
8281         0x40, 0xea, 0x98, 0x00,
8282         0x01, 0x31, 0x89, 0x32,
8283         0x08, 0xea, 0x62, 0x02,
8284 -       0x00, 0xe2, 0xf8, 0x41,
8285 +       0x00, 0xe2, 0xf6, 0x41,
8286         0xe0, 0xea, 0xd4, 0x5b,
8287 -       0x80, 0xe0, 0xc0, 0x6a,
8288 -       0x04, 0xe0, 0x66, 0x73,
8289 -       0x02, 0xe0, 0x96, 0x73,
8290 -       0x00, 0xea, 0x1e, 0x73,
8291 -       0x03, 0xe0, 0xa6, 0x73,
8292 -       0x23, 0xe0, 0x96, 0x72,
8293 -       0x08, 0xe0, 0xbc, 0x72,
8294 +       0x80, 0xe0, 0xc2, 0x6a,
8295 +       0x04, 0xe0, 0x68, 0x73,
8296 +       0x02, 0xe0, 0x9a, 0x73,
8297 +       0x00, 0xea, 0x20, 0x73,
8298 +       0x03, 0xe0, 0xaa, 0x73,
8299 +       0x23, 0xe0, 0x98, 0x72,
8300 +       0x08, 0xe0, 0xbe, 0x72,
8301         0x00, 0xe2, 0xb8, 0x5b,
8302 -       0x07, 0xea, 0x50, 0x59,
8303 +       0x07, 0xea, 0x46, 0x59,
8304         0x07, 0xea, 0x04, 0x00,
8305 -       0x08, 0x42, 0xf9, 0x71,
8306 -       0x04, 0x42, 0x93, 0x62,
8307 +       0x08, 0x42, 0xf7, 0x71,
8308 +       0x04, 0x42, 0x95, 0x62,
8309         0x01, 0x43, 0x89, 0x30,
8310 -       0x00, 0xe2, 0x84, 0x42,
8311 +       0x00, 0xe2, 0x86, 0x42,
8312         0x01, 0x44, 0xd4, 0x31,
8313 -       0x00, 0xe2, 0x84, 0x42,
8314 +       0x00, 0xe2, 0x86, 0x42,
8315         0x01, 0x00, 0x60, 0x32,
8316 -       0x33, 0xea, 0x44, 0x59,
8317 +       0x33, 0xea, 0x3a, 0x59,
8318         0x33, 0xea, 0x00, 0x00,
8319         0x4c, 0x34, 0xc1, 0x28,
8320         0x01, 0x64, 0xc0, 0x31,
8321 -       0x00, 0x30, 0x45, 0x59,
8322 +       0x00, 0x30, 0x3b, 0x59,
8323         0x01, 0x30, 0x01, 0x30,
8324 -       0x01, 0xe0, 0xba, 0x7a,
8325 +       0x01, 0xe0, 0xbc, 0x7a,
8326         0xa0, 0xea, 0xca, 0x5b,
8327 -       0x01, 0xa0, 0xba, 0x62,
8328 -       0x01, 0x84, 0xaf, 0x7a,
8329 -       0x01, 0x95, 0xbd, 0x6a,
8330 -       0x05, 0xea, 0x50, 0x59,
8331 +       0x01, 0xa0, 0xbc, 0x62,
8332 +       0x01, 0x84, 0xb1, 0x7a,
8333 +       0x01, 0x95, 0xbf, 0x6a,
8334 +       0x05, 0xea, 0x46, 0x59,
8335         0x05, 0xea, 0x04, 0x00,
8336 -       0x00, 0xe2, 0xbc, 0x42,
8337 -       0x03, 0xea, 0x50, 0x59,
8338 +       0x00, 0xe2, 0xbe, 0x42,
8339 +       0x03, 0xea, 0x46, 0x59,
8340         0x03, 0xea, 0x04, 0x00,
8341 -       0x00, 0xe2, 0xbc, 0x42,
8342 +       0x00, 0xe2, 0xbe, 0x42,
8343         0x07, 0xea, 0xdc, 0x5b,
8344         0x01, 0x44, 0xd4, 0x31,
8345 -       0x00, 0xe2, 0xf8, 0x41,
8346 +       0x00, 0xe2, 0xf6, 0x41,
8347         0x3f, 0xe0, 0x6a, 0x0a,
8348         0xc0, 0x34, 0xc1, 0x09,
8349         0x00, 0x35, 0x51, 0x01,
8350 @@ -368,54 +369,54 @@
8351         0x01, 0xea, 0xc6, 0x01,
8352         0x02, 0xe2, 0xc8, 0x31,
8353         0x02, 0xec, 0x40, 0x31,
8354 -       0xff, 0xa1, 0xdc, 0x72,
8355 +       0xff, 0xa1, 0xde, 0x72,
8356         0x02, 0xe8, 0xda, 0x31,
8357         0x02, 0xa0, 0x50, 0x31,
8358 -       0x00, 0xe2, 0xfe, 0x42,
8359 +       0x00, 0xe2, 0x00, 0x43,
8360         0x80, 0x33, 0x67, 0x02,
8361         0x01, 0x44, 0xd4, 0x31,
8362         0x00, 0xe2, 0xb8, 0x5b,
8363         0x01, 0x33, 0x67, 0x02,
8364 -       0xe0, 0x36, 0x19, 0x63,
8365 +       0xe0, 0x36, 0x1b, 0x63,
8366         0x02, 0x33, 0x67, 0x02,
8367 -       0x20, 0x46, 0x12, 0x63,
8368 +       0x20, 0x46, 0x14, 0x63,
8369         0xff, 0xea, 0x52, 0x09,
8370         0xa8, 0xea, 0xca, 0x5b,
8371 -       0x04, 0x92, 0xf9, 0x7a,
8372 +       0x04, 0x92, 0xfb, 0x7a,
8373         0x01, 0x34, 0xc1, 0x31,
8374 -       0x00, 0x93, 0xf9, 0x62,
8375 +       0x00, 0x93, 0xfb, 0x62,
8376         0x01, 0x35, 0xc1, 0x31,
8377 -       0x00, 0x94, 0x03, 0x73,
8378 +       0x00, 0x94, 0x05, 0x73,
8379         0x01, 0xa9, 0x52, 0x11,
8380 -       0xff, 0xa9, 0xee, 0x6a,
8381 -       0x00, 0xe2, 0x12, 0x43,
8382 +       0xff, 0xa9, 0xf0, 0x6a,
8383 +       0x00, 0xe2, 0x14, 0x43,
8384         0x10, 0x33, 0x67, 0x02,
8385 -       0x04, 0x92, 0x13, 0x7b,
8386 +       0x04, 0x92, 0x15, 0x7b,
8387         0xfb, 0x92, 0x25, 0x0b,
8388         0xff, 0xea, 0x66, 0x0a,
8389 -       0x01, 0xa4, 0x0d, 0x6b,
8390 +       0x01, 0xa4, 0x0f, 0x6b,
8391         0x02, 0xa8, 0x90, 0x32,
8392 -       0x00, 0xe2, 0x6a, 0x59,
8393 -       0x10, 0x92, 0xbd, 0x7a,
8394 +       0x00, 0xe2, 0x60, 0x59,
8395 +       0x10, 0x92, 0xbf, 0x7a,
8396         0xff, 0xea, 0xdc, 0x5b,
8397 -       0x00, 0xe2, 0xbc, 0x42,
8398 -       0x04, 0xea, 0x50, 0x59,
8399 +       0x00, 0xe2, 0xbe, 0x42,
8400 +       0x04, 0xea, 0x46, 0x59,
8401         0x04, 0xea, 0x04, 0x00,
8402 -       0x00, 0xe2, 0xbc, 0x42,
8403 -       0x04, 0xea, 0x50, 0x59,
8404 +       0x00, 0xe2, 0xbe, 0x42,
8405 +       0x04, 0xea, 0x46, 0x59,
8406         0x04, 0xea, 0x04, 0x00,
8407 -       0x00, 0xe2, 0xf8, 0x41,
8408 -       0x08, 0x92, 0xb5, 0x7a,
8409 -       0xc0, 0x33, 0x29, 0x7b,
8410 -       0x80, 0x33, 0xb5, 0x6a,
8411 -       0xff, 0x88, 0x29, 0x6b,
8412 -       0x40, 0x33, 0xb5, 0x6a,
8413 -       0x10, 0x92, 0x2f, 0x7b,
8414 -       0x0a, 0xea, 0x50, 0x59,
8415 +       0x00, 0xe2, 0xf6, 0x41,
8416 +       0x08, 0x92, 0xb7, 0x7a,
8417 +       0xc0, 0x33, 0x2b, 0x7b,
8418 +       0x80, 0x33, 0xb7, 0x6a,
8419 +       0xff, 0x88, 0x2b, 0x6b,
8420 +       0x40, 0x33, 0xb7, 0x6a,
8421 +       0x10, 0x92, 0x31, 0x7b,
8422 +       0x0a, 0xea, 0x46, 0x59,
8423         0x0a, 0xea, 0x04, 0x00,
8424 -       0x00, 0xe2, 0x4e, 0x5b,
8425 -       0x00, 0xe2, 0x82, 0x43,
8426 -       0x50, 0x4b, 0x36, 0x6b,
8427 +       0x00, 0xe2, 0x50, 0x5b,
8428 +       0x00, 0xe2, 0x84, 0x43,
8429 +       0x50, 0x4b, 0x38, 0x6b,
8430         0xbf, 0x3a, 0x74, 0x08,
8431         0x01, 0xe0, 0xf4, 0x31,
8432         0xff, 0xea, 0xc0, 0x09,
8433 @@ -425,25 +426,25 @@
8434         0x01, 0xfa, 0xc0, 0x35,
8435         0x02, 0xa8, 0x84, 0x32,
8436         0x02, 0xea, 0xb4, 0x00,
8437 -       0x33, 0xea, 0x44, 0x59,
8438 +       0x33, 0xea, 0x3a, 0x59,
8439         0x33, 0xea, 0x00, 0x00,
8440         0x02, 0x42, 0x51, 0x31,
8441         0xff, 0x90, 0x65, 0x68,
8442 -       0xff, 0x88, 0x5b, 0x6b,
8443 -       0x01, 0xa4, 0x57, 0x6b,
8444 -       0x02, 0xa4, 0x5f, 0x6b,
8445 -       0x01, 0x84, 0x5f, 0x7b,
8446 +       0xff, 0x88, 0x5d, 0x6b,
8447 +       0x01, 0xa4, 0x59, 0x6b,
8448 +       0x02, 0xa4, 0x61, 0x6b,
8449 +       0x01, 0x84, 0x61, 0x7b,
8450         0x02, 0x28, 0x19, 0x33,
8451         0x02, 0xa8, 0x50, 0x36,
8452 -       0xff, 0x88, 0x5f, 0x73,
8453 -       0x00, 0xe2, 0x32, 0x5b,
8454 +       0xff, 0x88, 0x61, 0x73,
8455 +       0x00, 0xe2, 0x34, 0x5b,
8456         0x02, 0xa8, 0x20, 0x33,
8457         0x02, 0x2c, 0x19, 0x33,
8458         0x02, 0xa8, 0x58, 0x32,
8459         0x04, 0xa4, 0x49, 0x07,
8460 -       0xc0, 0x33, 0xb5, 0x6a,
8461 +       0xc0, 0x33, 0xb7, 0x6a,
8462         0x04, 0x92, 0x25, 0x03,
8463 -       0x20, 0x92, 0x83, 0x6b,
8464 +       0x20, 0x92, 0x85, 0x6b,
8465         0x02, 0xa8, 0x40, 0x31,
8466         0xc0, 0x34, 0xc1, 0x09,
8467         0x00, 0x35, 0x51, 0x01,
8468 @@ -458,30 +459,29 @@
8469         0xf7, 0x57, 0xae, 0x08,
8470         0x08, 0xea, 0x98, 0x00,
8471         0x01, 0x44, 0xd4, 0x31,
8472 -       0xee, 0x00, 0x8c, 0x6b,
8473 +       0xee, 0x00, 0x8e, 0x6b,
8474         0x02, 0xea, 0xb4, 0x00,
8475 -       0x00, 0xe2, 0xb4, 0x5b,
8476 -       0x09, 0x4c, 0x8e, 0x7b,
8477 +       0xc0, 0xea, 0x66, 0x02,
8478 +       0x09, 0x4c, 0x90, 0x7b,
8479 +       0x01, 0xea, 0x6c, 0x02,
8480         0x08, 0x4c, 0x06, 0x68,
8481 -       0x0b, 0xea, 0x50, 0x59,
8482 +       0x0b, 0xea, 0x46, 0x59,
8483         0x0b, 0xea, 0x04, 0x00,
8484         0x01, 0x44, 0xd4, 0x31,
8485 -       0x20, 0x33, 0xf9, 0x79,
8486 -       0x00, 0xe2, 0x9e, 0x5b,
8487 -       0x00, 0xe2, 0xf8, 0x41,
8488 -       0x01, 0x84, 0xa3, 0x7b,
8489 +       0x20, 0x33, 0xf7, 0x79,
8490 +       0x00, 0xe2, 0xa2, 0x5b,
8491 +       0x00, 0xe2, 0xf6, 0x41,
8492 +       0x01, 0x84, 0xa7, 0x7b,
8493         0x01, 0xa4, 0x49, 0x07,
8494         0x08, 0x60, 0x30, 0x33,
8495         0x08, 0x80, 0x41, 0x37,
8496         0xdf, 0x33, 0x67, 0x0a,
8497 -       0xee, 0x00, 0xb0, 0x6b,
8498 +       0xee, 0x00, 0xb4, 0x6b,
8499         0x05, 0xea, 0xb4, 0x00,
8500 -       0x33, 0xea, 0x44, 0x59,
8501 +       0x33, 0xea, 0x3a, 0x59,
8502         0x33, 0xea, 0x00, 0x00,
8503 -       0x00, 0xe2, 0x6a, 0x59,
8504 -       0x00, 0xe2, 0xbc, 0x42,
8505 -       0x01, 0xea, 0x6c, 0x02,
8506 -       0xc0, 0xea, 0x66, 0x06,
8507 +       0x00, 0xe2, 0x60, 0x59,
8508 +       0x00, 0xe2, 0xbe, 0x42,
8509         0xff, 0x42, 0xc4, 0x6b,
8510         0x01, 0x41, 0xb8, 0x6b,
8511         0x02, 0x41, 0xb8, 0x7b,
8512 @@ -495,7 +495,7 @@
8513         0xff, 0x42, 0xcc, 0x7b,
8514         0x04, 0x4c, 0xcc, 0x6b,
8515         0xe0, 0x41, 0x6c, 0x0a,
8516 -       0xe0, 0x36, 0xf9, 0x61,
8517 +       0xe0, 0x36, 0xf7, 0x61,
8518         0xff, 0xea, 0xca, 0x09,
8519         0x01, 0xe2, 0xc8, 0x31,
8520         0x01, 0x46, 0xda, 0x35,
8521 @@ -553,30 +553,30 @@
8522         0x80, 0x83, 0x45, 0x6c,
8523         0x02, 0xea, 0x4c, 0x05,
8524         0xff, 0xea, 0x4c, 0x0d,
8525 -       0x00, 0xe2, 0x3e, 0x59,
8526 +       0x00, 0xe2, 0x34, 0x59,
8527         0x02, 0xa6, 0xe6, 0x6b,
8528         0x80, 0xf9, 0xf2, 0x05,
8529         0xc0, 0x33, 0x53, 0x7c,
8530 -       0x03, 0xea, 0x50, 0x59,
8531 +       0x03, 0xea, 0x46, 0x59,
8532         0x03, 0xea, 0x04, 0x00,
8533         0x20, 0x33, 0x77, 0x7c,
8534         0x01, 0x84, 0x5d, 0x6c,
8535 -       0x06, 0xea, 0x50, 0x59,
8536 +       0x06, 0xea, 0x46, 0x59,
8537         0x06, 0xea, 0x04, 0x00,
8538         0x00, 0xe2, 0x7a, 0x44,
8539         0x01, 0x00, 0x60, 0x32,
8540         0xee, 0x00, 0x66, 0x6c,
8541         0x05, 0xea, 0xb4, 0x00,
8542 -       0x33, 0xea, 0x44, 0x59,
8543 +       0x33, 0xea, 0x3a, 0x59,
8544         0x33, 0xea, 0x00, 0x00,
8545         0x80, 0x3d, 0x7a, 0x00,
8546         0xfc, 0x42, 0x68, 0x7c,
8547         0x7f, 0x3d, 0x7a, 0x08,
8548 -       0x00, 0x30, 0x45, 0x59,
8549 +       0x00, 0x30, 0x3b, 0x59,
8550         0x01, 0x30, 0x01, 0x30,
8551 -       0x09, 0xea, 0x50, 0x59,
8552 +       0x09, 0xea, 0x46, 0x59,
8553         0x09, 0xea, 0x04, 0x00,
8554 -       0x00, 0xe2, 0xf8, 0x41,
8555 +       0x00, 0xe2, 0xf6, 0x41,
8556         0x01, 0xa4, 0x5d, 0x6c,
8557         0x00, 0xe2, 0x30, 0x5c,
8558         0x20, 0x33, 0x67, 0x02,
8559 @@ -586,7 +586,7 @@
8560         0x00, 0xe2, 0x56, 0x58,
8561         0x00, 0xe2, 0x66, 0x58,
8562         0x00, 0xe2, 0x3a, 0x58,
8563 -       0x00, 0x30, 0x45, 0x59,
8564 +       0x00, 0x30, 0x3b, 0x59,
8565         0x01, 0x30, 0x01, 0x30,
8566         0x20, 0x19, 0x82, 0x6c,
8567         0x00, 0xe2, 0xb2, 0x5c,
8568 @@ -601,11 +601,11 @@
8569         0x03, 0x42, 0x4c, 0x6c,
8570         0x00, 0xe2, 0xe0, 0x5b,
8571         0x80, 0xf9, 0xf2, 0x01,
8572 -       0x04, 0x33, 0xf9, 0x79,
8573 -       0x00, 0xe2, 0xf8, 0x41,
8574 +       0x04, 0x33, 0xf7, 0x79,
8575 +       0x00, 0xe2, 0xf6, 0x41,
8576         0x08, 0x5d, 0xba, 0x6c,
8577         0x00, 0xe2, 0x56, 0x58,
8578 -       0x00, 0x30, 0x45, 0x59,
8579 +       0x00, 0x30, 0x3b, 0x59,
8580         0x01, 0x30, 0x01, 0x30,
8581         0x02, 0x1b, 0xaa, 0x7c,
8582         0x08, 0x5d, 0xb8, 0x7c,
8583 @@ -619,7 +619,7 @@
8584         0xf8, 0x1b, 0x08, 0x0b,
8585         0xff, 0xea, 0x06, 0x0b,
8586         0x03, 0x68, 0x00, 0x37,
8587 -       0x00, 0xe2, 0xc4, 0x58,
8588 +       0x00, 0xe2, 0xba, 0x58,
8589         0x10, 0xea, 0x18, 0x00,
8590         0xf9, 0xd9, 0xb2, 0x0d,
8591         0x01, 0xd9, 0xb2, 0x05,
8592 @@ -631,7 +631,7 @@
8593         0x11, 0x00, 0x00, 0x10,
8594         0x04, 0x19, 0x08, 0x7d,
8595         0xdf, 0x19, 0x32, 0x08,
8596 -       0x60, 0x5b, 0xe6, 0x6c,
8597 +       0x60, 0x5b, 0x08, 0x6d,
8598         0x01, 0x4c, 0xe2, 0x7c,
8599         0x20, 0x19, 0x32, 0x00,
8600         0x01, 0xd9, 0xb2, 0x05,
8601 @@ -641,7 +641,7 @@
8602         0x08, 0x5b, 0x0a, 0x6d,
8603         0x20, 0x5b, 0xfa, 0x6c,
8604         0x02, 0x5b, 0x2a, 0x6d,
8605 -       0x0e, 0xea, 0x50, 0x59,
8606 +       0x0e, 0xea, 0x46, 0x59,
8607         0x0e, 0xea, 0x04, 0x00,
8608         0x80, 0xf9, 0xea, 0x6c,
8609         0xdf, 0x5c, 0xb8, 0x08,
8610 @@ -651,11 +651,11 @@
8611         0x00, 0xe2, 0x34, 0x5d,
8612         0x01, 0x90, 0x21, 0x1b,
8613         0x01, 0xd9, 0xb2, 0x05,
8614 -       0x00, 0xe2, 0x32, 0x5b,
8615 +       0x00, 0xe2, 0x34, 0x5b,
8616         0xf3, 0x96, 0xd5, 0x19,
8617         0x00, 0xe2, 0x18, 0x55,
8618         0x80, 0x96, 0x19, 0x6d,
8619 -       0x0f, 0xea, 0x50, 0x59,
8620 +       0x0f, 0xea, 0x46, 0x59,
8621         0x0f, 0xea, 0x04, 0x00,
8622         0x00, 0xe2, 0x20, 0x45,
8623         0x04, 0x8c, 0xe1, 0x30,
8624 @@ -663,7 +663,7 @@
8625         0x02, 0xea, 0x36, 0x00,
8626         0xa8, 0xea, 0x32, 0x00,
8627         0xff, 0x97, 0x27, 0x7d,
8628 -       0x14, 0xea, 0x50, 0x59,
8629 +       0x14, 0xea, 0x46, 0x59,
8630         0x14, 0xea, 0x04, 0x00,
8631         0x00, 0xe2, 0x96, 0x5d,
8632         0x01, 0xd9, 0xb2, 0x05,
8633 @@ -673,14 +673,14 @@
8634         0x00, 0xe2, 0x8e, 0x5d,
8635         0x01, 0xd9, 0xb2, 0x05,
8636         0x02, 0xa6, 0x44, 0x7d,
8637 -       0x00, 0xe2, 0x3e, 0x59,
8638 +       0x00, 0xe2, 0x34, 0x59,
8639         0x20, 0x5b, 0x52, 0x6d,
8640         0xfc, 0x42, 0x3e, 0x7d,
8641         0x10, 0x40, 0x40, 0x6d,
8642         0x20, 0x4d, 0x42, 0x7d,
8643         0x08, 0x5d, 0x52, 0x6d,
8644         0x02, 0xa6, 0xe6, 0x6b,
8645 -       0x00, 0xe2, 0x3e, 0x59,
8646 +       0x00, 0xe2, 0x34, 0x59,
8647         0x20, 0x5b, 0x52, 0x6d,
8648         0x01, 0x1b, 0x72, 0x6d,
8649         0xfc, 0x42, 0x4e, 0x7d,
8650 @@ -690,22 +690,22 @@
8651         0x02, 0x19, 0x32, 0x00,
8652         0x01, 0x5b, 0x40, 0x31,
8653         0x00, 0xe2, 0xb2, 0x5c,
8654 -       0x00, 0xe2, 0x9e, 0x5b,
8655 +       0x00, 0xe2, 0xa2, 0x5b,
8656         0x20, 0xea, 0xb6, 0x00,
8657         0x00, 0xe2, 0xe0, 0x5b,
8658         0x20, 0x5c, 0xb8, 0x00,
8659         0x04, 0x19, 0x68, 0x6d,
8660         0x01, 0x1a, 0x68, 0x6d,
8661 -       0x00, 0xe2, 0x3e, 0x59,
8662 +       0x00, 0xe2, 0x34, 0x59,
8663         0x01, 0x1a, 0x64, 0x78,
8664         0x80, 0xf9, 0xf2, 0x01,
8665         0x20, 0xa0, 0xcc, 0x7d,
8666         0xff, 0x90, 0x21, 0x1b,
8667 -       0x08, 0x92, 0x43, 0x6b,
8668 +       0x08, 0x92, 0x45, 0x6b,
8669         0x02, 0xea, 0xb4, 0x04,
8670         0x01, 0xa4, 0x49, 0x03,
8671         0x40, 0x5b, 0x82, 0x6d,
8672 -       0x00, 0xe2, 0x3e, 0x59,
8673 +       0x00, 0xe2, 0x34, 0x59,
8674         0x40, 0x5b, 0x82, 0x6d,
8675         0x04, 0x5d, 0xe6, 0x7d,
8676         0x01, 0x1a, 0xe6, 0x7d,
8677 @@ -715,13 +715,13 @@
8678         0x01, 0x1a, 0xe6, 0x7d,
8679         0x80, 0xf9, 0xf2, 0x01,
8680         0xff, 0x90, 0x21, 0x1b,
8681 -       0x08, 0x92, 0x43, 0x6b,
8682 +       0x08, 0x92, 0x45, 0x6b,
8683         0x02, 0xea, 0xb4, 0x04,
8684 -       0x00, 0xe2, 0x3e, 0x59,
8685 +       0x00, 0xe2, 0x34, 0x59,
8686         0x01, 0x1b, 0x64, 0x78,
8687         0x80, 0xf9, 0xf2, 0x01,
8688         0x02, 0xea, 0xb4, 0x04,
8689 -       0x00, 0xe2, 0x3e, 0x59,
8690 +       0x00, 0xe2, 0x34, 0x59,
8691         0x01, 0x1b, 0xaa, 0x6d,
8692         0x40, 0x5b, 0xb8, 0x7d,
8693         0x01, 0x1b, 0xaa, 0x6d,
8694 @@ -730,13 +730,13 @@
8695         0x80, 0xf9, 0xf2, 0x01,
8696         0xff, 0xea, 0x10, 0x03,
8697         0x08, 0x92, 0x25, 0x03,
8698 -       0x00, 0xe2, 0x42, 0x43,
8699 +       0x00, 0xe2, 0x44, 0x43,
8700         0x01, 0x1a, 0xb4, 0x7d,
8701         0x40, 0x5b, 0xb0, 0x7d,
8702         0x01, 0x1a, 0x9e, 0x6d,
8703         0xfc, 0x42, 0x64, 0x78,
8704         0x01, 0x1a, 0xb8, 0x6d,
8705 -       0x10, 0xea, 0x50, 0x59,
8706 +       0x10, 0xea, 0x46, 0x59,
8707         0x10, 0xea, 0x04, 0x00,
8708         0xfc, 0x42, 0x64, 0x78,
8709         0x10, 0x40, 0xbe, 0x6d,
8710 @@ -748,26 +748,26 @@
8711         0x30, 0xe0, 0x64, 0x60,
8712         0x40, 0x4b, 0x64, 0x68,
8713         0xff, 0xea, 0x52, 0x01,
8714 -       0xee, 0x00, 0xd2, 0x6d,
8715 +       0xee, 0x00, 0xd4, 0x6d,
8716         0x80, 0xf9, 0xf2, 0x01,
8717         0xff, 0x90, 0x21, 0x1b,
8718         0x02, 0xea, 0xb4, 0x00,
8719         0x20, 0xea, 0x9a, 0x00,
8720         0xf3, 0x42, 0xde, 0x6d,
8721 -       0x12, 0xea, 0x50, 0x59,
8722 +       0x12, 0xea, 0x46, 0x59,
8723         0x12, 0xea, 0x04, 0x00,
8724 -       0x00, 0xe2, 0xf8, 0x41,
8725 -       0x0d, 0xea, 0x50, 0x59,
8726 +       0x00, 0xe2, 0xf6, 0x41,
8727 +       0x0d, 0xea, 0x46, 0x59,
8728         0x0d, 0xea, 0x04, 0x00,
8729 -       0x00, 0xe2, 0xf8, 0x41,
8730 +       0x00, 0xe2, 0xf6, 0x41,
8731         0x01, 0x90, 0x21, 0x1b,
8732 -       0x11, 0xea, 0x50, 0x59,
8733 +       0x11, 0xea, 0x46, 0x59,
8734         0x11, 0xea, 0x04, 0x00,
8735 -       0x00, 0xe2, 0x32, 0x5b,
8736 +       0x00, 0xe2, 0x34, 0x5b,
8737         0x08, 0x5a, 0xb4, 0x00,
8738         0x00, 0xe2, 0x0c, 0x5e,
8739         0xa8, 0xea, 0x32, 0x00,
8740 -       0x00, 0xe2, 0x3e, 0x59,
8741 +       0x00, 0xe2, 0x34, 0x59,
8742         0x80, 0x1a, 0xfa, 0x7d,
8743         0x00, 0xe2, 0x0c, 0x5e,
8744         0x80, 0x19, 0x32, 0x00,
8745 @@ -778,7 +778,7 @@
8746         0x40, 0x5b, 0xcc, 0x7d,
8747         0xff, 0x90, 0x21, 0x1b,
8748         0x80, 0xf9, 0xf2, 0x01,
8749 -       0x08, 0x92, 0x43, 0x6b,
8750 +       0x08, 0x92, 0x45, 0x6b,
8751         0x02, 0xea, 0xb4, 0x04,
8752         0x01, 0x38, 0xe1, 0x30,
8753         0x05, 0x39, 0xe3, 0x98,
8754 @@ -794,12 +794,20 @@
8755  };
8756  
8757  typedef int ahd_patch_func_t (struct ahd_softc *ahd);
8758 +static ahd_patch_func_t ahd_patch23_func;
8759 +
8760 +static int
8761 +ahd_patch23_func(struct ahd_softc *ahd)
8762 +{
8763 +       return ((ahd->bugs & AHD_PKT_BITBUCKET_BUG) != 0);
8764 +}
8765 +
8766  static ahd_patch_func_t ahd_patch22_func;
8767  
8768  static int
8769  ahd_patch22_func(struct ahd_softc *ahd)
8770  {
8771 -       return ((ahd->bugs & AHD_PKT_BITBUCKET_BUG) != 0);
8772 +       return ((ahd->bugs & AHD_PKT_BITBUCKET_BUG) == 0);
8773  }
8774  
8775  static ahd_patch_func_t ahd_patch21_func;
8776 @@ -807,7 +815,7 @@
8777  static int
8778  ahd_patch21_func(struct ahd_softc *ahd)
8779  {
8780 -       return ((ahd->bugs & AHD_PKT_BITBUCKET_BUG) == 0);
8781 +       return ((ahd->features & AHD_RTI) == 0);
8782  }
8783  
8784  static ahd_patch_func_t ahd_patch20_func;
8785 @@ -815,7 +823,7 @@
8786  static int
8787  ahd_patch20_func(struct ahd_softc *ahd)
8788  {
8789 -       return ((ahd->features & AHD_RTI) == 0);
8790 +       return ((ahd->flags & AHD_INITIATORROLE) != 0);
8791  }
8792  
8793  static ahd_patch_func_t ahd_patch19_func;
8794 @@ -823,7 +831,7 @@
8795  static int
8796  ahd_patch19_func(struct ahd_softc *ahd)
8797  {
8798 -       return ((ahd->flags & AHD_INITIATORROLE) != 0);
8799 +       return ((ahd->flags & AHD_TARGETROLE) != 0);
8800  }
8801  
8802  static ahd_patch_func_t ahd_patch18_func;
8803 @@ -831,7 +839,7 @@
8804  static int
8805  ahd_patch18_func(struct ahd_softc *ahd)
8806  {
8807 -       return ((ahd->flags & AHD_TARGETROLE) != 0);
8808 +       return ((ahd->bugs & AHD_AUTOFLUSH_BUG) != 0);
8809  }
8810  
8811  static ahd_patch_func_t ahd_patch17_func;
8812 @@ -839,7 +847,7 @@
8813  static int
8814  ahd_patch17_func(struct ahd_softc *ahd)
8815  {
8816 -       return ((ahd->bugs & AHD_AUTOFLUSH_BUG) != 0);
8817 +       return ((ahd->features & AHD_NEW_DFCNTRL_OPTS) != 0);
8818  }
8819  
8820  static ahd_patch_func_t ahd_patch16_func;
8821 @@ -847,7 +855,7 @@
8822  static int
8823  ahd_patch16_func(struct ahd_softc *ahd)
8824  {
8825 -       return ((ahd->features & AHD_NEW_DFCNTRL_OPTS) != 0);
8826 +       return ((ahd->flags & AHD_39BIT_ADDRESSING) != 0);
8827  }
8828  
8829  static ahd_patch_func_t ahd_patch15_func;
8830 @@ -855,7 +863,7 @@
8831  static int
8832  ahd_patch15_func(struct ahd_softc *ahd)
8833  {
8834 -       return ((ahd->flags & AHD_39BIT_ADDRESSING) != 0);
8835 +       return ((ahd->flags & AHD_64BIT_ADDRESSING) != 0);
8836  }
8837  
8838  static ahd_patch_func_t ahd_patch14_func;
8839 @@ -863,7 +871,7 @@
8840  static int
8841  ahd_patch14_func(struct ahd_softc *ahd)
8842  {
8843 -       return ((ahd->flags & AHD_64BIT_ADDRESSING) != 0);
8844 +       return ((ahd->features & AHD_NEW_DFCNTRL_OPTS) == 0);
8845  }
8846  
8847  static ahd_patch_func_t ahd_patch13_func;
8848 @@ -871,7 +879,7 @@
8849  static int
8850  ahd_patch13_func(struct ahd_softc *ahd)
8851  {
8852 -       return ((ahd->features & AHD_NEW_DFCNTRL_OPTS) == 0);
8853 +       return ((ahd->bugs & AHD_REG_SLOW_SETTLE_BUG) != 0);
8854  }
8855  
8856  static ahd_patch_func_t ahd_patch12_func;
8857 @@ -879,7 +887,7 @@
8858  static int
8859  ahd_patch12_func(struct ahd_softc *ahd)
8860  {
8861 -       return ((ahd->bugs & AHD_REG_SLOW_SETTLE_BUG) != 0);
8862 +       return ((ahd->bugs & AHD_EARLY_REQ_BUG) != 0);
8863  }
8864  
8865  static ahd_patch_func_t ahd_patch11_func;
8866 @@ -887,7 +895,7 @@
8867  static int
8868  ahd_patch11_func(struct ahd_softc *ahd)
8869  {
8870 -       return ((ahd->bugs & AHD_EARLY_REQ_BUG) != 0);
8871 +       return ((ahd->bugs & AHD_BUSFREEREV_BUG) == 0);
8872  }
8873  
8874  static ahd_patch_func_t ahd_patch10_func;
8875 @@ -895,7 +903,7 @@
8876  static int
8877  ahd_patch10_func(struct ahd_softc *ahd)
8878  {
8879 -       return ((ahd->bugs & AHD_BUSFREEREV_BUG) == 0);
8880 +       return ((ahd->flags & AHD_SEQUENCER_DEBUG) != 0);
8881  }
8882  
8883  static ahd_patch_func_t ahd_patch9_func;
8884 @@ -903,7 +911,7 @@
8885  static int
8886  ahd_patch9_func(struct ahd_softc *ahd)
8887  {
8888 -       return ((ahd->flags & AHD_SEQUENCER_DEBUG) != 0);
8889 +       return ((ahd->features & AHD_FAST_CDB_DELIVERY) != 0);
8890  }
8891  
8892  static ahd_patch_func_t ahd_patch8_func;
8893 @@ -1003,73 +1011,75 @@
8894         { ahd_patch0_func, 48, 1, 1 },
8895         { ahd_patch2_func, 51, 1, 2 },
8896         { ahd_patch0_func, 52, 1, 1 },
8897 +       { ahd_patch2_func, 61, 1, 2 },
8898 +       { ahd_patch0_func, 62, 1, 1 },
8899         { ahd_patch2_func, 65, 1, 2 },
8900         { ahd_patch0_func, 66, 1, 1 },
8901 -       { ahd_patch2_func, 69, 1, 2 },
8902 -       { ahd_patch0_func, 70, 1, 1 },
8903 -       { ahd_patch1_func, 73, 1, 2 },
8904 -       { ahd_patch0_func, 74, 1, 1 },
8905 -       { ahd_patch4_func, 107, 1, 1 },
8906 -       { ahd_patch2_func, 162, 6, 1 },
8907 -       { ahd_patch1_func, 168, 2, 1 },
8908 -       { ahd_patch5_func, 170, 1, 1 },
8909 -       { ahd_patch2_func, 179, 1, 2 },
8910 -       { ahd_patch0_func, 180, 1, 1 },
8911 -       { ahd_patch6_func, 181, 2, 2 },
8912 -       { ahd_patch0_func, 183, 6, 3 },
8913 -       { ahd_patch2_func, 186, 1, 2 },
8914 -       { ahd_patch0_func, 187, 1, 1 },
8915 -       { ahd_patch2_func, 190, 1, 2 },
8916 -       { ahd_patch0_func, 191, 1, 1 },
8917 -       { ahd_patch7_func, 193, 2, 1 },
8918 -       { ahd_patch5_func, 201, 16, 2 },
8919 -       { ahd_patch0_func, 217, 1, 1 },
8920 -       { ahd_patch8_func, 237, 2, 1 },
8921 -       { ahd_patch1_func, 241, 1, 2 },
8922 -       { ahd_patch0_func, 242, 1, 1 },
8923 -       { ahd_patch7_func, 245, 2, 1 },
8924 -       { ahd_patch1_func, 259, 1, 2 },
8925 -       { ahd_patch0_func, 260, 1, 1 },
8926 -       { ahd_patch1_func, 263, 1, 2 },
8927 -       { ahd_patch0_func, 264, 1, 1 },
8928 -       { ahd_patch2_func, 267, 1, 2 },
8929 -       { ahd_patch0_func, 268, 1, 1 },
8930 -       { ahd_patch1_func, 323, 1, 2 },
8931 -       { ahd_patch0_func, 324, 1, 1 },
8932 -       { ahd_patch2_func, 332, 1, 2 },
8933 -       { ahd_patch0_func, 333, 1, 1 },
8934 -       { ahd_patch2_func, 336, 1, 2 },
8935 -       { ahd_patch0_func, 337, 1, 1 },
8936 -       { ahd_patch1_func, 343, 1, 2 },
8937 -       { ahd_patch0_func, 344, 1, 1 },
8938 -       { ahd_patch1_func, 346, 1, 2 },
8939 -       { ahd_patch0_func, 347, 1, 1 },
8940 -       { ahd_patch9_func, 366, 1, 1 },
8941 -       { ahd_patch9_func, 369, 1, 1 },
8942 -       { ahd_patch9_func, 371, 1, 1 },
8943 -       { ahd_patch9_func, 383, 1, 1 },
8944 -       { ahd_patch1_func, 393, 1, 2 },
8945 -       { ahd_patch0_func, 394, 1, 1 },
8946 -       { ahd_patch1_func, 396, 1, 2 },
8947 -       { ahd_patch0_func, 397, 1, 1 },
8948 -       { ahd_patch1_func, 405, 1, 2 },
8949 -       { ahd_patch0_func, 406, 1, 1 },
8950 -       { ahd_patch2_func, 419, 1, 2 },
8951 -       { ahd_patch0_func, 420, 1, 1 },
8952 -       { ahd_patch10_func, 450, 1, 1 },
8953 -       { ahd_patch1_func, 457, 1, 2 },
8954 -       { ahd_patch0_func, 458, 1, 1 },
8955 -       { ahd_patch2_func, 470, 1, 2 },
8956 -       { ahd_patch0_func, 471, 1, 1 },
8957 -       { ahd_patch11_func, 476, 6, 2 },
8958 +       { ahd_patch4_func, 102, 1, 1 },
8959 +       { ahd_patch2_func, 157, 6, 1 },
8960 +       { ahd_patch1_func, 163, 2, 1 },
8961 +       { ahd_patch5_func, 165, 1, 1 },
8962 +       { ahd_patch2_func, 174, 1, 2 },
8963 +       { ahd_patch0_func, 175, 1, 1 },
8964 +       { ahd_patch6_func, 176, 2, 2 },
8965 +       { ahd_patch0_func, 178, 6, 3 },
8966 +       { ahd_patch2_func, 181, 1, 2 },
8967 +       { ahd_patch0_func, 182, 1, 1 },
8968 +       { ahd_patch2_func, 185, 1, 2 },
8969 +       { ahd_patch0_func, 186, 1, 1 },
8970 +       { ahd_patch3_func, 188, 1, 1 },
8971 +       { ahd_patch7_func, 189, 3, 1 },
8972 +       { ahd_patch3_func, 198, 1, 1 },
8973 +       { ahd_patch5_func, 199, 16, 2 },
8974 +       { ahd_patch0_func, 215, 1, 1 },
8975 +       { ahd_patch8_func, 235, 2, 1 },
8976 +       { ahd_patch1_func, 239, 1, 2 },
8977 +       { ahd_patch0_func, 240, 1, 1 },
8978 +       { ahd_patch7_func, 243, 3, 1 },
8979 +       { ahd_patch1_func, 258, 1, 2 },
8980 +       { ahd_patch0_func, 259, 1, 1 },
8981 +       { ahd_patch1_func, 262, 1, 2 },
8982 +       { ahd_patch0_func, 263, 1, 1 },
8983 +       { ahd_patch2_func, 266, 1, 2 },
8984 +       { ahd_patch0_func, 267, 1, 1 },
8985 +       { ahd_patch9_func, 280, 2, 2 },
8986 +       { ahd_patch0_func, 282, 1, 1 },
8987 +       { ahd_patch1_func, 324, 1, 2 },
8988 +       { ahd_patch0_func, 325, 1, 1 },
8989 +       { ahd_patch2_func, 333, 1, 2 },
8990 +       { ahd_patch0_func, 334, 1, 1 },
8991 +       { ahd_patch2_func, 337, 1, 2 },
8992 +       { ahd_patch0_func, 338, 1, 1 },
8993 +       { ahd_patch1_func, 344, 1, 2 },
8994 +       { ahd_patch0_func, 345, 1, 1 },
8995 +       { ahd_patch1_func, 347, 1, 2 },
8996 +       { ahd_patch0_func, 348, 1, 1 },
8997 +       { ahd_patch10_func, 367, 1, 1 },
8998 +       { ahd_patch10_func, 370, 1, 1 },
8999 +       { ahd_patch10_func, 372, 1, 1 },
9000 +       { ahd_patch10_func, 384, 1, 1 },
9001 +       { ahd_patch1_func, 394, 1, 2 },
9002 +       { ahd_patch0_func, 395, 1, 1 },
9003 +       { ahd_patch1_func, 397, 1, 2 },
9004 +       { ahd_patch0_func, 398, 1, 1 },
9005 +       { ahd_patch1_func, 406, 1, 2 },
9006 +       { ahd_patch0_func, 407, 1, 1 },
9007 +       { ahd_patch2_func, 420, 1, 2 },
9008 +       { ahd_patch0_func, 421, 1, 1 },
9009 +       { ahd_patch11_func, 451, 1, 1 },
9010 +       { ahd_patch1_func, 459, 1, 2 },
9011 +       { ahd_patch0_func, 460, 1, 1 },
9012 +       { ahd_patch2_func, 472, 1, 2 },
9013 +       { ahd_patch0_func, 473, 1, 1 },
9014 +       { ahd_patch12_func, 476, 6, 2 },
9015         { ahd_patch0_func, 482, 1, 1 },
9016 -       { ahd_patch12_func, 505, 1, 1 },
9017 -       { ahd_patch13_func, 514, 1, 1 },
9018 -       { ahd_patch14_func, 515, 1, 2 },
9019 +       { ahd_patch13_func, 505, 1, 1 },
9020 +       { ahd_patch14_func, 514, 1, 1 },
9021 +       { ahd_patch15_func, 515, 1, 2 },
9022         { ahd_patch0_func, 516, 1, 1 },
9023 -       { ahd_patch15_func, 519, 1, 1 },
9024 -       { ahd_patch14_func, 520, 1, 1 },
9025 -       { ahd_patch16_func, 531, 1, 2 },
9026 +       { ahd_patch16_func, 519, 1, 1 },
9027 +       { ahd_patch15_func, 520, 1, 1 },
9028 +       { ahd_patch17_func, 531, 1, 2 },
9029         { ahd_patch0_func, 532, 1, 1 },
9030         { ahd_patch1_func, 551, 1, 2 },
9031         { ahd_patch0_func, 552, 1, 1 },
9032 @@ -1083,25 +1093,25 @@
9033         { ahd_patch0_func, 569, 1, 1 },
9034         { ahd_patch2_func, 580, 1, 2 },
9035         { ahd_patch0_func, 581, 1, 1 },
9036 -       { ahd_patch17_func, 585, 1, 1 },
9037 -       { ahd_patch18_func, 590, 1, 1 },
9038 -       { ahd_patch19_func, 591, 2, 1 },
9039 -       { ahd_patch18_func, 595, 1, 2 },
9040 +       { ahd_patch18_func, 585, 1, 1 },
9041 +       { ahd_patch19_func, 590, 1, 1 },
9042 +       { ahd_patch20_func, 591, 2, 1 },
9043 +       { ahd_patch19_func, 595, 1, 2 },
9044         { ahd_patch0_func, 596, 1, 1 },
9045         { ahd_patch2_func, 599, 1, 2 },
9046         { ahd_patch0_func, 600, 1, 1 },
9047         { ahd_patch2_func, 615, 1, 2 },
9048         { ahd_patch0_func, 616, 1, 1 },
9049 -       { ahd_patch20_func, 617, 14, 1 },
9050 +       { ahd_patch21_func, 617, 14, 1 },
9051         { ahd_patch1_func, 635, 1, 2 },
9052         { ahd_patch0_func, 636, 1, 1 },
9053 -       { ahd_patch20_func, 637, 1, 1 },
9054 +       { ahd_patch21_func, 637, 1, 1 },
9055         { ahd_patch1_func, 649, 1, 2 },
9056         { ahd_patch0_func, 650, 1, 1 },
9057         { ahd_patch1_func, 657, 1, 2 },
9058         { ahd_patch0_func, 658, 1, 1 },
9059 -       { ahd_patch17_func, 681, 1, 1 },
9060 -       { ahd_patch17_func, 719, 1, 1 },
9061 +       { ahd_patch18_func, 681, 1, 1 },
9062 +       { ahd_patch18_func, 719, 1, 1 },
9063         { ahd_patch1_func, 730, 1, 2 },
9064         { ahd_patch0_func, 731, 1, 1 },
9065         { ahd_patch1_func, 748, 1, 2 },
9066 @@ -1110,11 +1120,11 @@
9067         { ahd_patch0_func, 752, 1, 1 },
9068         { ahd_patch1_func, 755, 1, 2 },
9069         { ahd_patch0_func, 756, 1, 1 },
9070 -       { ahd_patch21_func, 758, 1, 2 },
9071 +       { ahd_patch22_func, 758, 1, 2 },
9072         { ahd_patch0_func, 759, 2, 1 },
9073 -       { ahd_patch22_func, 762, 4, 2 },
9074 +       { ahd_patch23_func, 762, 4, 2 },
9075         { ahd_patch0_func, 766, 1, 1 },
9076 -       { ahd_patch22_func, 774, 11, 1 }
9077 +       { ahd_patch23_func, 774, 11, 1 }
9078  };
9079  
9080  static struct cs {
9081 @@ -1123,15 +1133,18 @@
9082  } critical_sections[] = {
9083         { 11, 12 },
9084         { 13, 14 },
9085 -       { 29, 42 },
9086 -       { 56, 59 },
9087 -       { 101, 128 },
9088 -       { 129, 157 },
9089 -       { 159, 162 },
9090 -       { 170, 178 },
9091 -       { 201, 250 },
9092 -       { 681, 697 },
9093 -       { 697, 711 },
9094 +       { 31, 42 },
9095 +       { 45, 47 },
9096 +       { 49, 50 },
9097 +       { 56, 78 },
9098 +       { 96, 123 },
9099 +       { 124, 152 },
9100 +       { 154, 157 },
9101 +       { 165, 173 },
9102 +       { 198, 249 },
9103 +       { 428, 430 },
9104 +       { 433, 436 },
9105 +       { 681, 711 },
9106         { 721, 725 }
9107  };
9108  
9109 diff -urN linux-2.4.24.org/drivers/scsi/aic7xxx/aic7xxx_93cx6.c linux-2.4.24/drivers/scsi/aic7xxx/aic7xxx_93cx6.c
9110 --- linux-2.4.24.org/drivers/scsi/aic7xxx/aic7xxx_93cx6.c       2004-01-08 11:57:43.038999788 +0100
9111 +++ linux-2.4.24/drivers/scsi/aic7xxx/aic7xxx_93cx6.c   2003-12-22 22:46:59.000000000 +0100
9112 @@ -28,9 +28,7 @@
9113   * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
9114   * SUCH DAMAGE.
9115   *
9116 - * $Id$
9117 - *
9118 - * $FreeBSD$
9119 + * $Id$
9120   */
9121  
9122  /*
9123 @@ -64,7 +62,6 @@
9124   *   is preceded by an initial zero (leading 0, followed by 16-bits, MSB
9125   *   first).  The clock cycling from low to high initiates the next data
9126   *   bit to be sent from the chip.
9127 - *
9128   */
9129  
9130  #ifdef __linux__
9131 @@ -81,14 +80,22 @@
9132   * Right now, we only have to read the SEEPROM.  But we make it easier to
9133   * add other 93Cx6 functions.
9134   */
9135 -static struct seeprom_cmd {
9136 +struct seeprom_cmd {
9137         uint8_t len;
9138 -       uint8_t bits[9];
9139 -} seeprom_read = {3, {1, 1, 0}};
9140 +       uint8_t bits[11];
9141 +};
9142  
9143 +/* Short opcodes for the c46 */
9144  static struct seeprom_cmd seeprom_ewen = {9, {1, 0, 0, 1, 1, 0, 0, 0, 0}};
9145  static struct seeprom_cmd seeprom_ewds = {9, {1, 0, 0, 0, 0, 0, 0, 0, 0}};
9146 +
9147 +/* Long opcodes for the C56/C66 */
9148 +static struct seeprom_cmd seeprom_long_ewen = {11, {1, 0, 0, 1, 1, 0, 0, 0, 0}};
9149 +static struct seeprom_cmd seeprom_long_ewds = {11, {1, 0, 0, 0, 0, 0, 0, 0, 0}};
9150 +
9151 +/* Common opcodes */
9152  static struct seeprom_cmd seeprom_write = {3, {1, 0, 1}};
9153 +static struct seeprom_cmd seeprom_read  = {3, {1, 1, 0}};
9154  
9155  /*
9156   * Wait for the SEERDY to go high; about 800 ns.
9157 @@ -222,12 +229,25 @@
9158  ahc_write_seeprom(struct seeprom_descriptor *sd, uint16_t *buf,
9159                   u_int start_addr, u_int count)
9160  {
9161 +       struct seeprom_cmd *ewen, *ewds;
9162         uint16_t v;
9163         uint8_t temp;
9164         int i, k;
9165  
9166         /* Place the chip into write-enable mode */
9167 -       send_seeprom_cmd(sd, &seeprom_ewen);
9168 +       if (sd->sd_chip == C46) {
9169 +               ewen = &seeprom_ewen;
9170 +               ewds = &seeprom_ewds;
9171 +       } else if (sd->sd_chip == C56_66) {
9172 +               ewen = &seeprom_long_ewen;
9173 +               ewds = &seeprom_long_ewds;
9174 +       } else {
9175 +               printf("ahc_write_seeprom: unsupported seeprom type %d\n",
9176 +                      sd->sd_chip);
9177 +               return (0);
9178 +       }
9179 +
9180 +       send_seeprom_cmd(sd, ewen);
9181         reset_seeprom(sd);
9182  
9183         /* Write all requested data out to the seeprom. */
9184 @@ -277,7 +297,7 @@
9185         }
9186  
9187         /* Put the chip back into write-protect mode */
9188 -       send_seeprom_cmd(sd, &seeprom_ewds);
9189 +       send_seeprom_cmd(sd, ewds);
9190         reset_seeprom(sd);
9191  
9192         return (1);
9193 diff -urN linux-2.4.24.org/drivers/scsi/aic7xxx/aic7xxx_core.c linux-2.4.24/drivers/scsi/aic7xxx/aic7xxx_core.c
9194 --- linux-2.4.24.org/drivers/scsi/aic7xxx/aic7xxx_core.c        2004-01-08 11:57:43.037000201 +0100
9195 +++ linux-2.4.24/drivers/scsi/aic7xxx/aic7xxx_core.c    2003-12-22 22:46:59.000000000 +0100
9196 @@ -37,9 +37,7 @@
9197   * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
9198   * POSSIBILITY OF SUCH DAMAGES.
9199   *
9200 - * $Id$
9201 - *
9202 - * $FreeBSD$
9203 + * $Id$
9204   */
9205  
9206  #ifdef __linux__
9207 @@ -320,7 +320,7 @@
9208                          */
9209                         modnext = ahc->qoutfifonext & ~0x3;
9210                         *((uint32_t *)(&ahc->qoutfifo[modnext])) = 0xFFFFFFFFUL;
9211 -                       ahc_dmamap_sync(ahc, ahc->shared_data_dmat,
9212 +                       aic_dmamap_sync(ahc, ahc->shared_data_dmat,
9213                                         ahc->shared_data_dmamap,
9214                                         /*offset*/modnext, /*len*/4,
9215                                         BUS_DMASYNC_PREREAD);
9216 @@ -458,14 +458,14 @@
9217                          * complete.
9218                          */
9219                         scb->flags &= ~SCB_SENSE;
9220 -                       ahc_set_transaction_status(scb, CAM_AUTOSENSE_FAIL);
9221 +                       aic_set_transaction_status(scb, CAM_AUTOSENSE_FAIL);
9222                         break;
9223                 }
9224 -               ahc_set_transaction_status(scb, CAM_SCSI_STATUS_ERROR);
9225 +               aic_set_transaction_status(scb, CAM_SCSI_STATUS_ERROR);
9226                 /* Freeze the queue until the client sees the error. */
9227                 ahc_freeze_devq(ahc, scb);
9228 -               ahc_freeze_scb(scb);
9229 -               ahc_set_scsi_status(scb, hscb->shared_data.status.scsi_status);
9230 +               aic_freeze_scb(scb);
9231 +               aic_set_scsi_status(scb, hscb->shared_data.status.scsi_status);
9232                 switch (hscb->shared_data.status.scsi_status) {
9233                 case SCSI_STATUS_OK:
9234                         printf("%s: Interrupted for staus of 0???\n",
9235 @@ -487,7 +487,7 @@
9236                         }
9237  #endif
9238  
9239 -                       if (ahc_perform_autosense(scb) == 0)
9240 +                       if (aic_perform_autosense(scb) == 0)
9241                                 break;
9242  
9243                         targ_info = ahc_fetch_transinfo(ahc,
9244 @@ -509,12 +509,12 @@
9245                         }
9246  #endif
9247                         sg->addr = ahc_get_sense_bufaddr(ahc, scb);
9248 -                       sg->len = ahc_get_sense_bufsize(ahc, scb);
9249 +                       sg->len = aic_get_sense_bufsize(ahc, scb);
9250                         sg->len |= AHC_DMA_LAST_SEG;
9251  
9252                         /* Fixup byte order */
9253 -                       sg->addr = ahc_htole32(sg->addr);
9254 -                       sg->len = ahc_htole32(sg->len);
9255 +                       sg->addr = aic_htole32(sg->addr);
9256 +                       sg->len = aic_htole32(sg->len);
9257  
9258                         sc->opcode = REQUEST_SENSE;
9259                         sc->byte2 = 0;
9260 @@ -543,8 +543,8 @@
9261                          * errors will be reported before any data
9262                          * phases occur.
9263                          */
9264 -                       if (ahc_get_residual(scb) 
9265 -                        == ahc_get_transfer_length(scb)) {
9266 +                       if (aic_get_residual(scb) 
9267 +                        == aic_get_transfer_length(scb)) {
9268                                 ahc_update_neg_request(ahc, &devinfo,
9269                                                        tstate, targ_info,
9270                                                        AHC_NEG_IF_NON_ASYNC);
9271 @@ -558,7 +558,7 @@
9272                         hscb->dataptr = sg->addr; 
9273                         hscb->datacnt = sg->len;
9274                         hscb->sgptr = scb->sg_list_phys | SG_FULL_RESID;
9275 -                       hscb->sgptr = ahc_htole32(hscb->sgptr);
9276 +                       hscb->sgptr = aic_htole32(hscb->sgptr);
9277                         scb->sg_count = 1;
9278                         scb->flags |= SCB_SENSE;
9279                         ahc_qinfifo_requeue_tail(ahc, scb);
9280 @@ -567,7 +567,7 @@
9281                          * Ensure we have enough time to actually
9282                          * retrieve the sense.
9283                          */
9284 -                       ahc_scb_timer_reset(scb, 5 * 1000000);
9285 +                       aic_scb_timer_reset(scb, 5 * 1000000);
9286                         break;
9287                 }
9288                 default:
9289 @@ -768,7 +768,7 @@
9290                                         if ((ahc_inb(ahc, SCSISIGI)
9291                                           & (CDI|MSGI)) != 0)
9292                                                 break;
9293 -                                       ahc_delay(100);
9294 +                                       aic_delay(100);
9295                                 }
9296                                 ahc_outb(ahc, SXFRCTL1,
9297                                          ahc_inb(ahc, SXFRCTL1) & ~BITBUCKET);
9298 @@ -782,7 +782,7 @@
9299                                         scb_index = ahc_inb(ahc, SCB_TAG);
9300                                         scb = ahc_lookup_scb(ahc, scb_index);
9301                                         if (scb != NULL)
9302 -                                               ahc_set_transaction_status(scb,
9303 +                                               aic_set_transaction_status(scb,
9304                                                     CAM_UNCOR_PARITY);
9305                                         ahc_reset_channel(ahc, devinfo.channel, 
9306                                                           /*init reset*/TRUE);
9307 @@ -820,16 +820,16 @@
9308                 ahc_print_path(ahc, scb);
9309                 printf("%s seen Data Phase.  Length = %ld.  NumSGs = %d.\n",
9310                        ahc_inb(ahc, SEQ_FLAGS) & DPHASE ? "Have" : "Haven't",
9311 -                      ahc_get_transfer_length(scb), scb->sg_count);
9312 +                      aic_get_transfer_length(scb), scb->sg_count);
9313                 if (scb->sg_count > 0) {
9314                         for (i = 0; i < scb->sg_count; i++) {
9315  
9316                                 printf("sg[%d] - Addr 0x%x%x : Length %d\n",
9317                                        i,
9318 -                                      (ahc_le32toh(scb->sg_list[i].len) >> 24
9319 +                                      (aic_le32toh(scb->sg_list[i].len) >> 24
9320                                         & SG_HIGH_ADDR_BITS),
9321 -                                      ahc_le32toh(scb->sg_list[i].addr),
9322 -                                      ahc_le32toh(scb->sg_list[i].len)
9323 +                                      aic_le32toh(scb->sg_list[i].addr),
9324 +                                      aic_le32toh(scb->sg_list[i].len)
9325                                        & AHC_SG_LEN_MASK);
9326                         }
9327                 }
9328 @@ -839,12 +839,12 @@
9329                  */
9330                 ahc_freeze_devq(ahc, scb);
9331                 if ((scb->flags & SCB_SENSE) == 0) {
9332 -                       ahc_set_transaction_status(scb, CAM_DATA_RUN_ERR);
9333 +                       aic_set_transaction_status(scb, CAM_DATA_RUN_ERR);
9334                 } else {
9335                         scb->flags &= ~SCB_SENSE;
9336 -                       ahc_set_transaction_status(scb, CAM_AUTOSENSE_FAIL);
9337 +                       aic_set_transaction_status(scb, CAM_AUTOSENSE_FAIL);
9338                 }
9339 -               ahc_freeze_scb(scb);
9340 +               aic_freeze_scb(scb);
9341  
9342                 if ((ahc->features & AHC_ULTRA2) != 0) {
9343                         /*
9344 @@ -1188,7 +1188,7 @@
9345                          */
9346                         ahc_scb_devinfo(ahc, &devinfo, scb);
9347                         ahc_force_renegotiation(ahc, &devinfo);
9348 -                       ahc_set_transaction_status(scb, CAM_SEL_TIMEOUT);
9349 +                       aic_set_transaction_status(scb, CAM_SEL_TIMEOUT);
9350                         ahc_freeze_devq(ahc, scb);
9351                 }
9352                 ahc_outb(ahc, CLRINT, CLRSCSIINT);
9353 @@ -1270,7 +1270,7 @@
9354                                                   CAM_LUN_WILDCARD,
9355                                                   SCB_LIST_NULL,
9356                                                   ROLE_INITIATOR)) {
9357 -                                       ahc_set_transaction_status(scb, CAM_REQ_CMP);
9358 +                                       aic_set_transaction_status(scb, CAM_REQ_CMP);
9359                                 }
9360  #endif
9361                                 ahc_compile_devinfo(&devinfo,
9362 @@ -1469,7 +1469,7 @@
9363                                  * current connection, so we must
9364                                  * leave it on while single stepping.
9365                                  */
9366 -                               ahc_outb(ahc, SIMODE1, ENBUSFREE);
9367 +                               ahc_outb(ahc, SIMODE1, simode1 & ENBUSFREE);
9368                         else
9369                                 ahc_outb(ahc, SIMODE1, 0);
9370                         ahc_outb(ahc, CLRINT, CLRSCSIINT);
9371 @@ -1482,7 +1482,7 @@
9372                 }
9373                 ahc_outb(ahc, HCNTRL, ahc->unpause);
9374                 while (!ahc_is_paused(ahc))
9375 -                       ahc_delay(200);
9376 +                       aic_delay(200);
9377         }
9378         if (stepping) {
9379                 ahc_outb(ahc, SIMODE0, simode0);
9380 @@ -1530,18 +1530,18 @@
9381         for (i = 0; i < sizeof(hscb->shared_data.cdb); i++)
9382                 printf("%#02x", hscb->shared_data.cdb[i]);
9383         printf("        dataptr:%#x datacnt:%#x sgptr:%#x tag:%#x\n",
9384 -               ahc_le32toh(hscb->dataptr),
9385 -               ahc_le32toh(hscb->datacnt),
9386 -               ahc_le32toh(hscb->sgptr),
9387 +               aic_le32toh(hscb->dataptr),
9388 +               aic_le32toh(hscb->datacnt),
9389 +               aic_le32toh(hscb->sgptr),
9390                 hscb->tag);
9391         if (scb->sg_count > 0) {
9392                 for (i = 0; i < scb->sg_count; i++) {
9393                         printf("sg[%d] - Addr 0x%x%x : Length %d\n",
9394                                i,
9395 -                              (ahc_le32toh(scb->sg_list[i].len) >> 24
9396 +                              (aic_le32toh(scb->sg_list[i].len) >> 24
9397                                 & SG_HIGH_ADDR_BITS),
9398 -                              ahc_le32toh(scb->sg_list[i].addr),
9399 -                              ahc_le32toh(scb->sg_list[i].len));
9400 +                              aic_le32toh(scb->sg_list[i].addr),
9401 +                              aic_le32toh(scb->sg_list[i].len));
9402                 }
9403         }
9404  }
9405 @@ -2575,7 +2575,7 @@
9406                 printf("No SCB found during protocol violation\n");
9407                 goto proto_violation_reset;
9408         } else {
9409 -               ahc_set_transaction_status(scb, CAM_SEQUENCE_FAIL);
9410 +               aic_set_transaction_status(scb, CAM_SEQUENCE_FAIL);
9411                 if ((seq_flags & NO_CDB_SENT) != 0) {
9412                         ahc_print_path(ahc, scb);
9413                         printf("No or incomplete CDB sent to device.\n");
9414 @@ -3513,7 +3513,7 @@
9415                 ahc_outb(ahc, SCB_CONTROL,
9416                          ahc_inb(ahc, SCB_CONTROL) & mask);
9417                 scb->hscb->control &= mask;
9418 -               ahc_set_transaction_tag(scb, /*enabled*/FALSE,
9419 +               aic_set_transaction_tag(scb, /*enabled*/FALSE,
9420                                         /*type*/MSG_SIMPLE_TASK);
9421                 ahc_outb(ahc, MSG_OUT, MSG_IDENTIFYFLAG);
9422                 ahc_assert_atn(ahc);
9423 @@ -3570,7 +3570,7 @@
9424          * Perhaps add datadir to some spare bits in the hscb?
9425          */
9426         if ((ahc_inb(ahc, SEQ_FLAGS) & DPHASE) == 0
9427 -        || ahc_get_transfer_dir(scb) != CAM_DIR_IN) {
9428 +        || aic_get_transfer_dir(scb) != CAM_DIR_IN) {
9429                 /*
9430                  * Ignore the message if we haven't
9431                  * seen an appropriate data phase yet.
9432 @@ -3626,18 +3626,18 @@
9433                          * to load so we must go back one.
9434                          */
9435                         sg--;
9436 -                       sglen = ahc_le32toh(sg->len) & AHC_SG_LEN_MASK;
9437 +                       sglen = aic_le32toh(sg->len) & AHC_SG_LEN_MASK;
9438                         if (sg != scb->sg_list
9439                          && sglen < (data_cnt & AHC_SG_LEN_MASK)) {
9440  
9441                                 sg--;
9442 -                               sglen = ahc_le32toh(sg->len);
9443 +                               sglen = aic_le32toh(sg->len);
9444                                 /*
9445                                  * Preserve High Address and SG_LIST bits
9446                                  * while setting the count to 1.
9447                                  */
9448                                 data_cnt = 1 | (sglen & (~AHC_SG_LEN_MASK));
9449 -                               data_addr = ahc_le32toh(sg->addr)
9450 +                               data_addr = aic_le32toh(sg->addr)
9451                                           + (sglen & AHC_SG_LEN_MASK) - 1;
9452  
9453                                 /*
9454 @@ -3693,8 +3693,8 @@
9455               | (ahc_inb(ahc, SCB_RESIDUAL_DATACNT + 1) << 8)
9456               | ahc_inb(ahc, SCB_RESIDUAL_DATACNT);
9457  
9458 -       dataptr = ahc_le32toh(sg->addr)
9459 -               + (ahc_le32toh(sg->len) & AHC_SG_LEN_MASK)
9460 +       dataptr = aic_le32toh(sg->addr)
9461 +               + (aic_le32toh(sg->len) & AHC_SG_LEN_MASK)
9462                 - resid;
9463         if ((ahc->flags & AHC_39BIT_ADDRESSING) != 0) {
9464                 u_int dscommand1;
9465 @@ -3702,7 +3702,7 @@
9466                 dscommand1 = ahc_inb(ahc, DSCOMMAND1);
9467                 ahc_outb(ahc, DSCOMMAND1, dscommand1 | HADDLDSEL0);
9468                 ahc_outb(ahc, HADDR,
9469 -                        (ahc_le32toh(sg->len) >> 24) & SG_HIGH_ADDR_BITS);
9470 +                        (aic_le32toh(sg->len) >> 24) & SG_HIGH_ADDR_BITS);
9471                 ahc_outb(ahc, DSCOMMAND1, dscommand1);
9472         }
9473         ahc_outb(ahc, HADDR + 3, dataptr >> 24);
9474 @@ -3883,7 +3883,7 @@
9475  {
9476         struct ahc_softc *list_ahc;
9477  
9478 -#if AHC_PCI_CONFIG > 0
9479 +#if AIC_PCI_CONFIG > 0
9480         /*
9481          * Second Function PCI devices need to inherit some
9482          * settings from function 0.
9483 @@ -3891,17 +3891,17 @@
9484         if ((ahc->chip & AHC_BUS_MASK) == AHC_PCI
9485          && (ahc->features & AHC_MULTI_FUNC) != 0) {
9486                 TAILQ_FOREACH(list_ahc, &ahc_tailq, links) {
9487 -                       ahc_dev_softc_t list_pci;
9488 -                       ahc_dev_softc_t pci;
9489 +                       aic_dev_softc_t list_pci;
9490 +                       aic_dev_softc_t pci;
9491  
9492                         list_pci = list_ahc->dev_softc;
9493                         pci = ahc->dev_softc;
9494 -                       if (ahc_get_pci_slot(list_pci) == ahc_get_pci_slot(pci)
9495 -                        && ahc_get_pci_bus(list_pci) == ahc_get_pci_bus(pci)) {
9496 +                       if (aic_get_pci_slot(list_pci) == aic_get_pci_slot(pci)
9497 +                        && aic_get_pci_bus(list_pci) == aic_get_pci_bus(pci)) {
9498                                 struct ahc_softc *master;
9499                                 struct ahc_softc *slave;
9500  
9501 -                               if (ahc_get_pci_function(list_pci) == 0) {
9502 +                               if (aic_get_pci_function(list_pci) == 0) {
9503                                         master = list_ahc;
9504                                         slave = ahc;
9505                                 } else {
9506 @@ -3969,27 +3969,27 @@
9507  {
9508         int i;
9509  
9510 +       ahc_terminate_recovery_thread(ahc);
9511         switch (ahc->init_level) {
9512         default:
9513         case 5:
9514                 ahc_shutdown(ahc);
9515 -               TAILQ_REMOVE(&ahc_tailq, ahc, links);
9516                 /* FALLTHROUGH */
9517         case 4:
9518 -               ahc_dmamap_unload(ahc, ahc->shared_data_dmat,
9519 +               aic_dmamap_unload(ahc, ahc->shared_data_dmat,
9520                                   ahc->shared_data_dmamap);
9521                 /* FALLTHROUGH */
9522         case 3:
9523 -               ahc_dmamem_free(ahc, ahc->shared_data_dmat, ahc->qoutfifo,
9524 +               aic_dmamem_free(ahc, ahc->shared_data_dmat, ahc->qoutfifo,
9525                                 ahc->shared_data_dmamap);
9526 -               ahc_dmamap_destroy(ahc, ahc->shared_data_dmat,
9527 +               aic_dmamap_destroy(ahc, ahc->shared_data_dmat,
9528                                    ahc->shared_data_dmamap);
9529                 /* FALLTHROUGH */
9530         case 2:
9531 -               ahc_dma_tag_destroy(ahc, ahc->shared_data_dmat);
9532 +               aic_dma_tag_destroy(ahc, ahc->shared_data_dmat);
9533         case 1:
9534  #ifndef __linux__
9535 -               ahc_dma_tag_destroy(ahc, ahc->buffer_dmat);
9536 +               aic_dma_tag_destroy(ahc, ahc->buffer_dmat);
9537  #endif
9538                 break;
9539         case 0:
9540 @@ -3997,7 +3997,7 @@
9541         }
9542  
9543  #ifndef __linux__
9544 -       ahc_dma_tag_destroy(ahc, ahc->parent_dmat);
9545 +       aic_dma_tag_destroy(ahc, ahc->parent_dmat);
9546  #endif
9547         ahc_platform_free(ahc);
9548         ahc_fini_scbdata(ahc);
9549 @@ -4079,14 +4079,6 @@
9550          * to disturb the integrity of the bus.
9551          */
9552         ahc_pause(ahc);
9553 -       if ((ahc_inb(ahc, HCNTRL) & CHIPRST) != 0) {
9554 -               /*
9555 -                * The chip has not been initialized since
9556 -                * PCI/EISA/VLB bus reset.  Don't trust
9557 -                * "left over BIOS data".
9558 -                */
9559 -               ahc->flags |= AHC_NO_BIOS_INIT;
9560 -       }
9561         sxfrctl1_b = 0;
9562         if ((ahc->chip & AHC_CHIPID_MASK) == AHC_AIC7770) {
9563                 u_int sblkctl;
9564 @@ -4112,7 +4104,7 @@
9565          */
9566         wait = 1000;
9567         do {
9568 -               ahc_delay(1000);
9569 +               aic_delay(1000);
9570         } while (--wait && !(ahc_inb(ahc, HCNTRL) & CHIPRSTACK));
9571  
9572         if (wait == 0) {
9573 @@ -4292,7 +4284,7 @@
9574          */
9575  
9576         /* DMA tag for our hardware scb structures */
9577 -       if (ahc_dma_tag_create(ahc, ahc->parent_dmat, /*alignment*/1,
9578 +       if (aic_dma_tag_create(ahc, ahc->parent_dmat, /*alignment*/1,
9579                                /*boundary*/BUS_SPACE_MAXADDR_32BIT + 1,
9580                                /*lowaddr*/BUS_SPACE_MAXADDR_32BIT,
9581                                /*highaddr*/BUS_SPACE_MAXADDR,
9582 @@ -4307,7 +4299,7 @@
9583         scb_data->init_level++;
9584  
9585         /* Allocation for our hscbs */
9586 -       if (ahc_dmamem_alloc(ahc, scb_data->hscb_dmat,
9587 +       if (aic_dmamem_alloc(ahc, scb_data->hscb_dmat,
9588                              (void **)&scb_data->hscbs,
9589                              BUS_DMA_NOWAIT, &scb_data->hscb_dmamap) != 0) {
9590                 goto error_exit;
9591 @@ -4316,7 +4308,7 @@
9592         scb_data->init_level++;
9593  
9594         /* And permanently map them */
9595 -       ahc_dmamap_load(ahc, scb_data->hscb_dmat, scb_data->hscb_dmamap,
9596 +       aic_dmamap_load(ahc, scb_data->hscb_dmat, scb_data->hscb_dmamap,
9597                         scb_data->hscbs,
9598                         AHC_SCB_MAX_ALLOC * sizeof(struct hardware_scb),
9599                         ahc_dmamap_cb, &scb_data->hscb_busaddr, /*flags*/0);
9600 @@ -4324,7 +4316,7 @@
9601         scb_data->init_level++;
9602  
9603         /* DMA tag for our sense buffers */
9604 -       if (ahc_dma_tag_create(ahc, ahc->parent_dmat, /*alignment*/1,
9605 +       if (aic_dma_tag_create(ahc, ahc->parent_dmat, /*alignment*/1,
9606                                /*boundary*/BUS_SPACE_MAXADDR_32BIT + 1,
9607                                /*lowaddr*/BUS_SPACE_MAXADDR_32BIT,
9608                                /*highaddr*/BUS_SPACE_MAXADDR,
9609 @@ -4339,7 +4331,7 @@
9610         scb_data->init_level++;
9611  
9612         /* Allocate them */
9613 -       if (ahc_dmamem_alloc(ahc, scb_data->sense_dmat,
9614 +       if (aic_dmamem_alloc(ahc, scb_data->sense_dmat,
9615                              (void **)&scb_data->sense,
9616                              BUS_DMA_NOWAIT, &scb_data->sense_dmamap) != 0) {
9617                 goto error_exit;
9618 @@ -4348,7 +4340,7 @@
9619         scb_data->init_level++;
9620  
9621         /* And permanently map them */
9622 -       ahc_dmamap_load(ahc, scb_data->sense_dmat, scb_data->sense_dmamap,
9623 +       aic_dmamap_load(ahc, scb_data->sense_dmat, scb_data->sense_dmamap,
9624                         scb_data->sense,
9625                         AHC_SCB_MAX_ALLOC * sizeof(struct scsi_sense_data),
9626                         ahc_dmamap_cb, &scb_data->sense_busaddr, /*flags*/0);
9627 @@ -4356,7 +4348,7 @@
9628         scb_data->init_level++;
9629  
9630         /* DMA tag for our S/G structures.  We allocate in page sized chunks */
9631 -       if (ahc_dma_tag_create(ahc, ahc->parent_dmat, /*alignment*/8,
9632 +       if (aic_dma_tag_create(ahc, ahc->parent_dmat, /*alignment*/8,
9633                                /*boundary*/BUS_SPACE_MAXADDR_32BIT + 1,
9634                                /*lowaddr*/BUS_SPACE_MAXADDR_32BIT,
9635                                /*highaddr*/BUS_SPACE_MAXADDR,
9636 @@ -4413,35 +4405,35 @@
9637  
9638                 while ((sg_map = SLIST_FIRST(&scb_data->sg_maps))!= NULL) {
9639                         SLIST_REMOVE_HEAD(&scb_data->sg_maps, links);
9640 -                       ahc_dmamap_unload(ahc, scb_data->sg_dmat,
9641 +                       aic_dmamap_unload(ahc, scb_data->sg_dmat,
9642                                           sg_map->sg_dmamap);
9643 -                       ahc_dmamem_free(ahc, scb_data->sg_dmat,
9644 +                       aic_dmamem_free(ahc, scb_data->sg_dmat,
9645                                         sg_map->sg_vaddr,
9646                                         sg_map->sg_dmamap);
9647                         free(sg_map, M_DEVBUF);
9648                 }
9649 -               ahc_dma_tag_destroy(ahc, scb_data->sg_dmat);
9650 +               aic_dma_tag_destroy(ahc, scb_data->sg_dmat);
9651         }
9652         case 6:
9653 -               ahc_dmamap_unload(ahc, scb_data->sense_dmat,
9654 +               aic_dmamap_unload(ahc, scb_data->sense_dmat,
9655                                   scb_data->sense_dmamap);
9656         case 5:
9657 -               ahc_dmamem_free(ahc, scb_data->sense_dmat, scb_data->sense,
9658 +               aic_dmamem_free(ahc, scb_data->sense_dmat, scb_data->sense,
9659                                 scb_data->sense_dmamap);
9660 -               ahc_dmamap_destroy(ahc, scb_data->sense_dmat,
9661 +               aic_dmamap_destroy(ahc, scb_data->sense_dmat,
9662                                    scb_data->sense_dmamap);
9663         case 4:
9664 -               ahc_dma_tag_destroy(ahc, scb_data->sense_dmat);
9665 +               aic_dma_tag_destroy(ahc, scb_data->sense_dmat);
9666         case 3:
9667 -               ahc_dmamap_unload(ahc, scb_data->hscb_dmat,
9668 +               aic_dmamap_unload(ahc, scb_data->hscb_dmat,
9669                                   scb_data->hscb_dmamap);
9670         case 2:
9671 -               ahc_dmamem_free(ahc, scb_data->hscb_dmat, scb_data->hscbs,
9672 +               aic_dmamem_free(ahc, scb_data->hscb_dmat, scb_data->hscbs,
9673                                 scb_data->hscb_dmamap);
9674 -               ahc_dmamap_destroy(ahc, scb_data->hscb_dmat,
9675 +               aic_dmamap_destroy(ahc, scb_data->hscb_dmat,
9676                                    scb_data->hscb_dmamap);
9677         case 1:
9678 -               ahc_dma_tag_destroy(ahc, scb_data->hscb_dmat);
9679 +               aic_dma_tag_destroy(ahc, scb_data->hscb_dmat);
9680                 break;
9681         case 0:
9682                 break;
9683 @@ -4474,7 +4466,7 @@
9684                 return;
9685  
9686         /* Allocate S/G space for the next batch of SCBS */
9687 -       if (ahc_dmamem_alloc(ahc, scb_data->sg_dmat,
9688 +       if (aic_dmamem_alloc(ahc, scb_data->sg_dmat,
9689                              (void **)&sg_map->sg_vaddr,
9690                              BUS_DMA_NOWAIT, &sg_map->sg_dmamap) != 0) {
9691                 free(sg_map, M_DEVBUF);
9692 @@ -4483,7 +4475,7 @@
9693  
9694         SLIST_INSERT_HEAD(&scb_data->sg_maps, sg_map, links);
9695  
9696 -       ahc_dmamap_load(ahc, scb_data->sg_dmat, sg_map->sg_dmamap,
9697 +       aic_dmamap_load(ahc, scb_data->sg_dmat, sg_map->sg_dmamap,
9698                         sg_map->sg_vaddr, PAGE_SIZE, ahc_dmamap_cb,
9699                         &sg_map->sg_physaddr, /*flags*/0);
9700  
9701 @@ -4510,9 +4502,9 @@
9702                  */
9703                 next_scb->sg_list_phys = physaddr + sizeof(struct ahc_dma_seg);
9704                 next_scb->ahc_softc = ahc;
9705 -               next_scb->flags = SCB_FREE;
9706 +               next_scb->flags = SCB_FLAG_NONE;
9707  #ifndef __linux__
9708 -               error = ahc_dmamap_create(ahc, ahc->buffer_dmat, /*flags*/0,
9709 +               error = aic_dmamap_create(ahc, ahc->buffer_dmat, /*flags*/0,
9710                                           &next_scb->dmamap);
9711                 if (error != 0)
9712                         break;
9713 @@ -4747,7 +4739,7 @@
9714                 for (wait = 5000;
9715                      (ahc_inb(ahc, SBLKCTL) & (ENAB40|ENAB20)) == 0 && wait;
9716                      wait--)
9717 -                       ahc_delay(100);
9718 +                       aic_delay(100);
9719         }
9720         ahc_restart(ahc);
9721         return (0);
9722 @@ -4760,6 +4752,7 @@
9723  ahc_init(struct ahc_softc *ahc)
9724  {
9725         int      max_targ;
9726 +       int      error;
9727         u_int    i;
9728         u_int    scsi_conf;
9729         u_int    ultraenb;
9730 @@ -4817,7 +4810,7 @@
9731  
9732  #ifndef __linux__
9733         /* DMA tag for mapping buffers into device visible space. */
9734 -       if (ahc_dma_tag_create(ahc, ahc->parent_dmat, /*alignment*/1,
9735 +       if (aic_dma_tag_create(ahc, ahc->parent_dmat, /*alignment*/1,
9736                                /*boundary*/BUS_SPACE_MAXADDR_32BIT + 1,
9737                                /*lowaddr*/ahc->flags & AHC_39BIT_ADDRESSING
9738                                         ? (bus_addr_t)0x7FFFFFFFFFULL
9739 @@ -4848,7 +4841,7 @@
9740         if ((ahc->features & AHC_TARGETMODE) != 0)
9741                 driver_data_size += AHC_TMODE_CMDS * sizeof(struct target_cmd)
9742                                  + /*DMA WideOdd Bug Buffer*/1;
9743 -       if (ahc_dma_tag_create(ahc, ahc->parent_dmat, /*alignment*/1,
9744 +       if (aic_dma_tag_create(ahc, ahc->parent_dmat, /*alignment*/1,
9745                                /*boundary*/BUS_SPACE_MAXADDR_32BIT + 1,
9746                                /*lowaddr*/BUS_SPACE_MAXADDR_32BIT,
9747                                /*highaddr*/BUS_SPACE_MAXADDR,
9748 @@ -4863,7 +4856,7 @@
9749         ahc->init_level++;
9750  
9751         /* Allocation of driver data */
9752 -       if (ahc_dmamem_alloc(ahc, ahc->shared_data_dmat,
9753 +       if (aic_dmamem_alloc(ahc, ahc->shared_data_dmat,
9754                              (void **)&ahc->qoutfifo,
9755                              BUS_DMA_NOWAIT, &ahc->shared_data_dmamap) != 0) {
9756                 return (ENOMEM);
9757 @@ -4872,7 +4865,7 @@
9758         ahc->init_level++;
9759  
9760         /* And permanently map it in */
9761 -       ahc_dmamap_load(ahc, ahc->shared_data_dmat, ahc->shared_data_dmamap,
9762 +       aic_dmamap_load(ahc, ahc->shared_data_dmat, ahc->shared_data_dmamap,
9763                         ahc->qoutfifo, driver_data_size, ahc_dmamap_cb,
9764                         &ahc->shared_data_busaddr, /*flags*/0);
9765  
9766 @@ -4915,6 +4908,13 @@
9767                 }
9768         }
9769  
9770 +       /*
9771 +        * Fire up a recovery thread for this controller.
9772 +        */
9773 +       error = ahc_spawn_recovery_thread(ahc);
9774 +       if (error != 0)
9775 +               return (error);
9776 +
9777         if (ahc->scb_data->maxhscbs < AHC_SCB_MAX_ALLOC) {
9778                 ahc->flags |= AHC_PAGESCBS;
9779         } else {
9780 @@ -5112,8 +5112,14 @@
9781         ahc->flags |= AHC_ALL_INTERRUPTS;
9782         paused = FALSE;
9783         do {
9784 -               if (paused)
9785 +               if (paused) {
9786                         ahc_unpause(ahc);
9787 +                       /*
9788 +                        * Give the sequencer some time to service
9789 +                        * any active selections.
9790 +                        */
9791 +                       aic_delay(200);
9792 +               }
9793                 ahc_intr(ahc);
9794                 ahc_pause(ahc);
9795                 paused = TRUE;
9796 @@ -5399,12 +5405,12 @@
9797                                 cam_status ostat;
9798                                 cam_status cstat;
9799  
9800 -                               ostat = ahc_get_transaction_status(scb);
9801 +                               ostat = aic_get_transaction_status(scb);
9802                                 if (ostat == CAM_REQ_INPROG)
9803 -                                       ahc_set_transaction_status(scb, status);
9804 -                               cstat = ahc_get_transaction_status(scb);
9805 +                                       aic_set_transaction_status(scb, status);
9806 +                               cstat = aic_get_transaction_status(scb);
9807                                 if (cstat != CAM_REQ_CMP)
9808 -                                       ahc_freeze_scb(scb);
9809 +                                       aic_freeze_scb(scb);
9810                                 if ((scb->flags & SCB_ACTIVE) == 0)
9811                                         printf("Inactive SCB in qinfifo\n");
9812                                 ahc_done(ahc, scb);
9813 @@ -5511,13 +5517,13 @@
9814                                 cam_status ostat;
9815                                 cam_status cstat;
9816  
9817 -                               ostat = ahc_get_transaction_status(scb);
9818 +                               ostat = aic_get_transaction_status(scb);
9819                                 if (ostat == CAM_REQ_INPROG)
9820 -                                       ahc_set_transaction_status(scb,
9821 +                                       aic_set_transaction_status(scb,
9822                                                                    status);
9823 -                               cstat = ahc_get_transaction_status(scb);
9824 +                               cstat = aic_get_transaction_status(scb);
9825                                 if (cstat != CAM_REQ_CMP)
9826 -                                       ahc_freeze_scb(scb);
9827 +                                       aic_freeze_scb(scb);
9828                                 if ((scb->flags & SCB_ACTIVE) == 0)
9829                                         printf("Inactive SCB in Waiting List\n");
9830                                 ahc_done(ahc, scb);
9831 @@ -5539,7 +5545,7 @@
9832         }
9833         ahc_outb(ahc, SCBPTR, curscbptr);
9834  
9835 -       found += ahc_search_untagged_queues(ahc, /*ahc_io_ctx_t*/NULL, target,
9836 +       found += ahc_search_untagged_queues(ahc, /*aic_io_ctx_t*/NULL, target,
9837                                             channel, lun, status, action);
9838  
9839         if (action == SEARCH_COMPLETE)
9840 @@ -5548,7 +5554,7 @@
9841  }
9842  
9843  int
9844 -ahc_search_untagged_queues(struct ahc_softc *ahc, ahc_io_ctx_t ctx,
9845 +ahc_search_untagged_queues(struct ahc_softc *ahc, aic_io_ctx_t ctx,
9846                            int target, char channel, int lun, uint32_t status,
9847                            ahc_search_action action)
9848  {
9849 @@ -5619,12 +5625,12 @@
9850                                 cam_status ostat;
9851                                 cam_status cstat;
9852  
9853 -                               ostat = ahc_get_transaction_status(scb);
9854 +                               ostat = aic_get_transaction_status(scb);
9855                                 if (ostat == CAM_REQ_INPROG)
9856 -                                       ahc_set_transaction_status(scb, status);
9857 -                               cstat = ahc_get_transaction_status(scb);
9858 +                                       aic_set_transaction_status(scb, status);
9859 +                               cstat = aic_get_transaction_status(scb);
9860                                 if (cstat != CAM_REQ_CMP)
9861 -                                       ahc_freeze_scb(scb);
9862 +                                       aic_freeze_scb(scb);
9863                                 if ((scb->flags & SCB_ACTIVE) == 0)
9864                                         printf("Inactive SCB in untaggedQ\n");
9865                                 ahc_done(ahc, scb);
9866 @@ -5923,11 +5929,11 @@
9867                 if (ahc_match_scb(ahc, scbp, target, channel, lun, tag, role)) {
9868                         cam_status ostat;
9869  
9870 -                       ostat = ahc_get_transaction_status(scbp);
9871 +                       ostat = aic_get_transaction_status(scbp);
9872                         if (ostat == CAM_REQ_INPROG)
9873 -                               ahc_set_transaction_status(scbp, status);
9874 -                       if (ahc_get_transaction_status(scbp) != CAM_REQ_CMP)
9875 -                               ahc_freeze_scb(scbp);
9876 +                               aic_set_transaction_status(scbp, status);
9877 +                       if (aic_get_transaction_status(scbp) != CAM_REQ_CMP)
9878 +                               aic_freeze_scb(scbp);
9879                         if ((scbp->flags & SCB_ACTIVE) == 0)
9880                                 printf("Inactive SCB on pending list\n");
9881                         ahc_done(ahc, scbp);
9882 @@ -5949,7 +5955,7 @@
9883         scsiseq = ahc_inb(ahc, SCSISEQ);
9884         ahc_outb(ahc, SCSISEQ, scsiseq | SCSIRSTO);
9885         ahc_flush_device_writes(ahc);
9886 -       ahc_delay(AHC_BUSRESET_DELAY);
9887 +       aic_delay(AHC_BUSRESET_DELAY);
9888         /* Turn off the bus reset */
9889         ahc_outb(ahc, SCSISEQ, scsiseq & ~SCSIRSTO);
9890  
9891 @@ -6156,7 +6162,7 @@
9892          */
9893  
9894         hscb = scb->hscb;
9895 -       sgptr = ahc_le32toh(hscb->sgptr);
9896 +       sgptr = aic_le32toh(hscb->sgptr);
9897         if ((sgptr & SG_RESID_VALID) == 0)
9898                 /* Case 1 */
9899                 return;
9900 @@ -6167,10 +6173,10 @@
9901                 return;
9902  
9903         spkt = &hscb->shared_data.status;
9904 -       resid_sgptr = ahc_le32toh(spkt->residual_sg_ptr);
9905 +       resid_sgptr = aic_le32toh(spkt->residual_sg_ptr);
9906         if ((sgptr & SG_FULL_RESID) != 0) {
9907                 /* Case 3 */
9908 -               resid = ahc_get_transfer_length(scb);
9909 +               resid = aic_get_transfer_length(scb);
9910         } else if ((resid_sgptr & SG_LIST_NULL) != 0) {
9911                 /* Case 4 */
9912                 return;
9913 @@ -6183,7 +6189,7 @@
9914                  * Remainder of the SG where the transfer
9915                  * stopped.  
9916                  */
9917 -               resid = ahc_le32toh(spkt->residual_datacnt) & AHC_SG_LEN_MASK;
9918 +               resid = aic_le32toh(spkt->residual_datacnt) & AHC_SG_LEN_MASK;
9919                 sg = ahc_sg_bus_to_virt(scb, resid_sgptr & SG_PTR_MASK);
9920  
9921                 /* The residual sg_ptr always points to the next sg */
9922 @@ -6194,15 +6200,15 @@
9923                  * SG segments that are after the SG where
9924                  * the transfer stopped.
9925                  */
9926 -               while ((ahc_le32toh(sg->len) & AHC_DMA_LAST_SEG) == 0) {
9927 +               while ((aic_le32toh(sg->len) & AHC_DMA_LAST_SEG) == 0) {
9928                         sg++;
9929 -                       resid += ahc_le32toh(sg->len) & AHC_SG_LEN_MASK;
9930 +                       resid += aic_le32toh(sg->len) & AHC_SG_LEN_MASK;
9931                 }
9932         }
9933         if ((scb->flags & SCB_SENSE) == 0)
9934 -               ahc_set_residual(scb, resid);
9935 +               aic_set_residual(scb, resid);
9936         else
9937 -               ahc_set_sense_residual(scb, resid);
9938 +               aic_set_sense_residual(scb, resid);
9939  
9940  #ifdef AHC_DEBUG
9941         if ((ahc_debug & AHC_SHOW_MISC) != 0) {
9942 @@ -6482,7 +6488,7 @@
9943         /*
9944          * The firmware is always compiled into a little endian format.
9945          */
9946 -       instr.integer = ahc_le32toh(*(uint32_t*)&seqprog[instrptr * 4]);
9947 +       instr.integer = aic_le32toh(*(uint32_t*)&seqprog[instrptr * 4]);
9948  
9949         fmt1_ins = &instr.format1;
9950         fmt3_ins = NULL;
9951 @@ -6587,7 +6593,7 @@
9952                         }
9953                 }
9954                 /* The sequencer is a little endian cpu */
9955 -               instr.integer = ahc_htole32(instr.integer);
9956 +               instr.integer = aic_htole32(instr.integer);
9957                 ahc_outsb(ahc, SEQRAM, instr.bytes, 4);
9958                 break;
9959         default:
9960 @@ -6827,6 +6833,324 @@
9961                 ahc_unpause(ahc);
9962  }
9963  
9964 +/*************************** Timeout Handling *********************************/
9965 +void
9966 +ahc_timeout(struct scb *scb)
9967 +{
9968 +       struct ahc_softc *ahc;
9969 +
9970 +       ahc = scb->ahc_softc;
9971 +       if ((scb->flags & SCB_ACTIVE) != 0) {
9972 +               if ((scb->flags & SCB_TIMEDOUT) == 0) {
9973 +                       LIST_INSERT_HEAD(&ahc->timedout_scbs, scb,
9974 +                                        timedout_links);
9975 +                       scb->flags |= SCB_TIMEDOUT;
9976 +               }
9977 +               ahc_wakeup_recovery_thread(ahc);
9978 +       }
9979 +}
9980 +
9981 +/*
9982 + * ahc_recover_commands determines if any of the commands that have currently
9983 + * timedout are the root cause for this timeout.  Innocent commands are given
9984 + * a new timeout while we wait for the command executing on the bus to timeout.
9985 + * This routine is invoked from a thread context so we are allowed to sleep.
9986 + * Our lock is not held on entry.
9987 + */
9988 +void
9989 +ahc_recover_commands(struct ahc_softc *ahc)
9990 +{
9991 +       struct  scb *scb;
9992 +       long    s;
9993 +       int     found;
9994 +       int     restart_needed;
9995 +       u_int   last_phase;
9996 +
9997 +       ahc_lock(ahc, &s);
9998 +
9999 +       /*
10000 +        * Pause the controller and manually flush any
10001 +        * commands that have just completed but that our
10002 +        * interrupt handler has yet to see.
10003 +        */
10004 +       ahc_pause_and_flushwork(ahc);
10005 +
10006 +       if (LIST_EMPTY(&ahc->timedout_scbs) != 0) {
10007 +               /*
10008 +                * The timedout commands have already
10009 +                * completed.  This typically means
10010 +                * that either the timeout value was on
10011 +                * the hairy edge of what the device
10012 +                * requires or - more likely - interrupts
10013 +                * are not happening.
10014 +                */
10015 +               printf("%s: Timedout SCBs already complete. "
10016 +                      "Interrupts may not be functioning.\n", ahc_name(ahc));
10017 +               ahc_unpause(ahc);
10018 +               ahc_unlock(ahc, &s);
10019 +               return;
10020 +       }
10021 +
10022 +       restart_needed = 0;
10023 +       printf("%s: Recovery Initiated\n", ahc_name(ahc));
10024 +       ahc_dump_card_state(ahc);
10025 +
10026 +       last_phase = ahc_inb(ahc, LASTPHASE);
10027 +       while ((scb = LIST_FIRST(&ahc->timedout_scbs)) != NULL) {
10028 +               u_int   active_scb_index;
10029 +               u_int   saved_scbptr;
10030 +               int     target;
10031 +               int     lun;
10032 +               int     i;
10033 +               char    channel;
10034 +
10035 +               target = SCB_GET_TARGET(ahc, scb);
10036 +               channel = SCB_GET_CHANNEL(ahc, scb);
10037 +               lun = SCB_GET_LUN(scb);
10038 +
10039 +               ahc_print_path(ahc, scb);
10040 +               printf("SCB 0x%x - timed out\n", scb->hscb->tag);
10041 +               if (scb->sg_count > 0) {
10042 +                       for (i = 0; i < scb->sg_count; i++) {
10043 +                               printf("sg[%d] - Addr 0x%x : Length %d\n",
10044 +                                      i,
10045 +                                      scb->sg_list[i].addr,
10046 +                                      scb->sg_list[i].len & AHC_SG_LEN_MASK);
10047 +                       }
10048 +               }
10049 +               if (scb->flags & (SCB_DEVICE_RESET|SCB_ABORT)) {
10050 +                       /*
10051 +                        * Been down this road before.
10052 +                        * Do a full bus reset.
10053 +                        */
10054 +                       aic_set_transaction_status(scb, CAM_CMD_TIMEOUT);
10055 +bus_reset:
10056 +                       found = ahc_reset_channel(ahc, channel,
10057 +                                                 /*Initiate Reset*/TRUE);
10058 +                       printf("%s: Issued Channel %c Bus Reset. "
10059 +                              "%d SCBs aborted\n", ahc_name(ahc), channel,
10060 +                              found);
10061 +                       continue;
10062 +               }
10063 +
10064 +               /*
10065 +                * Remove the command from the timedout list in
10066 +                * preparation for requeing it.
10067 +                */
10068 +               LIST_REMOVE(scb, timedout_links);
10069 +               scb->flags &= ~SCB_TIMEDOUT;
10070 +
10071 +               /*
10072 +                * If we are a target, transition to bus free and report
10073 +                * the timeout.
10074 +                * 
10075 +                * The target/initiator that is holding up the bus may not
10076 +                * be the same as the one that triggered this timeout
10077 +                * (different commands have different timeout lengths).
10078 +                * If the bus is idle and we are actiing as the initiator
10079 +                * for this request, queue a BDR message to the timed out
10080 +                * target.  Otherwise, if the timed out transaction is
10081 +                * active:
10082 +                *   Initiator transaction:
10083 +                *      Stuff the message buffer with a BDR message and assert
10084 +                *      ATN in the hopes that the target will let go of the bus
10085 +                *      and go to the mesgout phase.  If this fails, we'll
10086 +                *      get another timeout 2 seconds later which will attempt
10087 +                *      a bus reset.
10088 +                *
10089 +                *   Target transaction:
10090 +                *      Transition to BUS FREE and report the error.
10091 +                *      It's good to be the target!
10092 +                */
10093 +               saved_scbptr = ahc_inb(ahc, SCBPTR);
10094 +               active_scb_index = ahc_inb(ahc, SCB_TAG);
10095 +
10096 +               if ((ahc_inb(ahc, SEQ_FLAGS) & NOT_IDENTIFIED) == 0
10097 +                 && (active_scb_index < ahc->scb_data->numscbs)) {
10098 +                       struct scb *active_scb;
10099 +
10100 +                       /*
10101 +                        * If the active SCB is not us, assume that
10102 +                        * the active SCB has a longer timeout than
10103 +                        * the timedout SCB, and wait for the active
10104 +                        * SCB to timeout.
10105 +                        */ 
10106 +                       active_scb = ahc_lookup_scb(ahc, active_scb_index);
10107 +                       if (active_scb != scb) {
10108 +                               u_int   newtimeout;
10109 +
10110 +                               ahc_print_path(ahc, scb);
10111 +                               printf("Other SCB Timeout%s",
10112 +                                      (scb->flags & SCB_OTHERTCL_TIMEOUT) != 0
10113 +                                      ? " again\n" : "\n");
10114 +                               scb->flags |= SCB_OTHERTCL_TIMEOUT;
10115 +                               newtimeout =
10116 +                                   MAX(aic_get_timeout(active_scb),
10117 +                                       aic_get_timeout(scb));
10118 +                               aic_scb_timer_reset(scb, newtimeout);
10119 +                               continue;
10120 +                       } 
10121 +
10122 +                       /* It's us */
10123 +                       if ((scb->flags & SCB_TARGET_SCB) != 0) {
10124 +
10125 +                               /*
10126 +                                * Send back any queued up transactions
10127 +                                * and properly record the error condition.
10128 +                                */
10129 +                               ahc_abort_scbs(ahc, SCB_GET_TARGET(ahc, scb),
10130 +                                              SCB_GET_CHANNEL(ahc, scb),
10131 +                                              SCB_GET_LUN(scb),
10132 +                                              scb->hscb->tag,
10133 +                                              ROLE_TARGET,
10134 +                                              CAM_CMD_TIMEOUT);
10135 +
10136 +                               /* Will clear us from the bus */
10137 +                               restart_needed = 1;
10138 +                               break;
10139 +                       }
10140 +
10141 +                       ahc_set_recoveryscb(ahc, active_scb);
10142 +                       ahc_outb(ahc, MSG_OUT, HOST_MSG);
10143 +                       ahc_outb(ahc, SCSISIGO, last_phase|ATNO);
10144 +                       ahc_print_path(ahc, active_scb);
10145 +                       printf("BDR message in message buffer\n");
10146 +                       active_scb->flags |= SCB_DEVICE_RESET;
10147 +                       aic_scb_timer_reset(scb, 2 * 1000000);
10148 +               } else if (last_phase != P_BUSFREE
10149 +                       && (ahc_inb(ahc, SSTAT1) & REQINIT) == 0) {
10150 +                       /*
10151 +                        * SCB is not identified, there
10152 +                        * is no pending REQ, and the sequencer
10153 +                        * has not seen a busfree.  Looks like
10154 +                        * a stuck connection waiting to
10155 +                        * go busfree.  Reset the bus.
10156 +                        */
10157 +                       printf("%s: Connection stuck awaiting busfree or "
10158 +                              "Identify Msg.\n", ahc_name(ahc));
10159 +                       goto bus_reset;
10160 +               } else {
10161 +                       int      disconnected;
10162 +
10163 +                       if (last_phase != P_BUSFREE
10164 +                        && (ahc_inb(ahc, SSTAT0) & TARGET) != 0) {
10165 +                               /* Hung target selection.  Goto busfree */
10166 +                               printf("%s: Hung target selection\n",
10167 +                                      ahc_name(ahc));
10168 +                               restart_needed = 1;
10169 +                               break;
10170 +                       }
10171 +
10172 +                       /* XXX Shouldn't panic.  Just punt instead? */
10173 +                       if ((scb->flags & SCB_TARGET_SCB) != 0)
10174 +                               panic("Timed-out target SCB but bus idle");
10175 +
10176 +                       if (ahc_search_qinfifo(ahc, target, channel, lun,
10177 +                                              scb->hscb->tag, ROLE_INITIATOR,
10178 +                                              /*status*/0, SEARCH_COUNT) > 0) {
10179 +                               disconnected = FALSE;
10180 +                       } else {
10181 +                               disconnected = TRUE;
10182 +                       }
10183 +
10184 +                       if (disconnected) {
10185 +
10186 +                               ahc_set_recoveryscb(ahc, scb);
10187 +                               /*
10188 +                                * Actually re-queue this SCB in an attempt
10189 +                                * to select the device before it reconnects.
10190 +                                * In either case (selection or reselection),
10191 +                                * we will now issue a target reset to the
10192 +                                * timed-out device.
10193 +                                *
10194 +                                * Set the MK_MESSAGE control bit indicating
10195 +                                * that we desire to send a message.  We
10196 +                                * also set the disconnected flag since
10197 +                                * in the paging case there is no guarantee
10198 +                                * that our SCB control byte matches the
10199 +                                * version on the card.  We don't want the
10200 +                                * sequencer to abort the command thinking
10201 +                                * an unsolicited reselection occurred.
10202 +                                */
10203 +                               scb->hscb->control |= MK_MESSAGE|DISCONNECTED;
10204 +                               scb->flags |= SCB_DEVICE_RESET;
10205 +
10206 +                               /*
10207 +                                * Remove any cached copy of this SCB in the
10208 +                                * disconnected list in preparation for the
10209 +                                * queuing of our abort SCB.  We use the
10210 +                                * same element in the SCB, SCB_NEXT, for
10211 +                                * both the qinfifo and the disconnected list.
10212 +                                */
10213 +                               ahc_search_disc_list(ahc, target, channel,
10214 +                                                    lun, scb->hscb->tag,
10215 +                                                    /*stop_on_first*/TRUE,
10216 +                                                    /*remove*/TRUE,
10217 +                                                    /*save_state*/FALSE);
10218 +
10219 +                               /*
10220 +                                * In the non-paging case, the sequencer will
10221 +                                * never re-reference the in-core SCB.
10222 +                                * To make sure we are notified during
10223 +                                * reslection, set the MK_MESSAGE flag in
10224 +                                * the card's copy of the SCB.
10225 +                                */
10226 +                               if ((ahc->flags & AHC_PAGESCBS) == 0) {
10227 +                                       ahc_outb(ahc, SCBPTR, scb->hscb->tag);
10228 +                                       ahc_outb(ahc, SCB_CONTROL,
10229 +                                                ahc_inb(ahc, SCB_CONTROL)
10230 +                                               | MK_MESSAGE);
10231 +                               }
10232 +
10233 +                               /*
10234 +                                * Clear out any entries in the QINFIFO first
10235 +                                * so we are the next SCB for this target
10236 +                                * to run.
10237 +                                */
10238 +                               ahc_search_qinfifo(ahc,
10239 +                                                  SCB_GET_TARGET(ahc, scb),
10240 +                                                  channel, SCB_GET_LUN(scb),
10241 +                                                  SCB_LIST_NULL,
10242 +                                                  ROLE_INITIATOR,
10243 +                                                  CAM_REQUEUE_REQ,
10244 +                                                  SEARCH_COMPLETE);
10245 +                               ahc_print_path(ahc, scb);
10246 +                               printf("Queuing a BDR SCB\n");
10247 +                               ahc_qinfifo_requeue_tail(ahc, scb);
10248 +                               ahc_outb(ahc, SCBPTR, saved_scbptr);
10249 +                               aic_scb_timer_reset(scb, 2 * 1000000);
10250 +                       } else {
10251 +                               /* Go "immediatly" to the bus reset */
10252 +                               /* This shouldn't happen */
10253 +                               ahc_set_recoveryscb(ahc, scb);
10254 +                               ahc_print_path(ahc, scb);
10255 +                               printf("SCB %d: Immediate reset.  "
10256 +                                       "Flags = 0x%x\n", scb->hscb->tag,
10257 +                                       scb->flags);
10258 +                               goto bus_reset;
10259 +                       }
10260 +               }
10261 +               break;
10262 +       }
10263 +       
10264 +       /*
10265 +        * Any remaining SCBs were not the "culprit", so remove
10266 +        * them from the timeout list.  The timer for these commands
10267 +        * will be reset once the recovery SCB completes.
10268 +        */
10269 +       while ((scb = LIST_FIRST(&ahc->timedout_scbs)) != NULL) {
10270 +
10271 +               LIST_REMOVE(scb, timedout_links);
10272 +               scb->flags &= ~SCB_TIMEDOUT;
10273 +       }
10274 +
10275 +       if (restart_needed)
10276 +               ahc_restart(ahc);
10277 +       else
10278 +               ahc_unpause(ahc);
10279 +       ahc_unlock(ahc, &s);
10280 +}
10281 +
10282  /************************* Target Mode ****************************************/
10283  #ifdef AHC_TARGET_MODE
10284  cam_status
10285 @@ -7305,7 +7629,7 @@
10286                         break;
10287  
10288                 cmd->cmd_valid = 0;
10289 -               ahc_dmamap_sync(ahc, ahc->shared_data_dmat,
10290 +               aic_dmamap_sync(ahc, ahc->shared_data_dmat,
10291                                 ahc->shared_data_dmamap,
10292                                 ahc_targetcmd_offset(ahc, ahc->tqinfifonext),
10293                                 sizeof(struct target_cmd),
10294 @@ -7442,7 +7766,7 @@
10295                        initiator, target, lun, ahc->pending_device);
10296  #endif
10297                 ahc->pending_device = lstate;
10298 -               ahc_freeze_ccb((union ccb *)atio);
10299 +               aic_freeze_ccb((union ccb *)atio);
10300                 atio->ccb_h.flags |= CAM_DIS_DISCONNECT;
10301         }
10302         xpt_done((union ccb*)atio);
10303 diff -urN linux-2.4.24.org/drivers/scsi/aic7xxx/aic7xxx.h linux-2.4.24/drivers/scsi/aic7xxx/aic7xxx.h
10304 --- linux-2.4.24.org/drivers/scsi/aic7xxx/aic7xxx.h     2004-01-08 11:57:43.043998755 +0100
10305 +++ linux-2.4.24/drivers/scsi/aic7xxx/aic7xxx.h 2003-12-22 22:46:59.000000000 +0100
10306 @@ -37,7 +37,7 @@
10307   * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
10308   * POSSIBILITY OF SUCH DAMAGES.
10309   *
10310 - * $Id$
10311 + * $Id$
10312   *
10313   * $FreeBSD$
10314   */
10315 @@ -243,7 +243,7 @@
10316          */
10317         AHC_AIC7850_FE  = AHC_SPIOCAP|AHC_AUTOPAUSE|AHC_TARGETMODE|AHC_ULTRA,
10318         AHC_AIC7860_FE  = AHC_AIC7850_FE,
10319 -       AHC_AIC7870_FE  = AHC_TARGETMODE,
10320 +       AHC_AIC7870_FE  = AHC_TARGETMODE|AHC_AUTOPAUSE,
10321         AHC_AIC7880_FE  = AHC_AIC7870_FE|AHC_ULTRA,
10322         /*
10323          * Although we have space for both the initiator and
10324 @@ -366,7 +366,8 @@
10325         AHC_SCB_CONFIG_USED   = 0x4000000, /* No SEEPROM but SCB2 had info. */
10326         AHC_NO_BIOS_INIT      = 0x8000000, /* No BIOS left over settings. */
10327         AHC_DISABLE_PCI_PERR  = 0x10000000,
10328 -       AHC_HAS_TERM_LOGIC    = 0x20000000
10329 +       AHC_HAS_TERM_LOGIC    = 0x20000000,
10330 +       AHC_SHUTDOWN_RECOVERY = 0x40000000 /* Terminate recovery thread. */
10331  } ahc_flag;
10332  
10333  /************************* Hardware  SCB Definition ***************************/
10334 @@ -411,6 +412,7 @@
10335         uint8_t  initiator_tag;         /* Initiator's transaction tag */
10336  };
10337  
10338 +#define MAX_CDB_LEN 16
10339  struct hardware_scb {
10340  /*0*/  union {
10341                 /*
10342 @@ -530,7 +532,7 @@
10343   * The current state of this SCB.
10344   */
10345  typedef enum {
10346 -       SCB_FREE                = 0x0000,
10347 +       SCB_FLAG_NONE           = 0x0000,
10348         SCB_OTHERTCL_TIMEOUT    = 0x0002,/*
10349                                           * Another device was active
10350                                           * during the first timeout for
10351 @@ -560,12 +562,16 @@
10352                                           * to report the error.
10353                                           */
10354         SCB_TARGET_SCB          = 0x2000,
10355 -       SCB_SILENT              = 0x4000 /*
10356 +       SCB_SILENT              = 0x4000,/*
10357                                           * Be quiet about transmission type
10358                                           * errors.  They are expected and we
10359                                           * don't want to upset the user.  This
10360                                           * flag is typically used during DV.
10361                                           */
10362 +       SCB_TIMEDOUT            = 0x8000 /*
10363 +                                         * SCB has timed out and is on the
10364 +                                         * timedout list.
10365 +                                         */
10366  } scb_flag;
10367  
10368  struct scb {
10369 @@ -575,7 +581,8 @@
10370                 TAILQ_ENTRY(scb)  tqe;
10371         } links;
10372         LIST_ENTRY(scb)           pending_links;
10373 -       ahc_io_ctx_t              io_ctx;
10374 +       LIST_ENTRY(scb)           timedout_links;
10375 +       aic_io_ctx_t              io_ctx;
10376         struct ahc_softc         *ahc_softc;
10377         scb_flag                  flags;
10378  #ifndef __linux__
10379 @@ -929,6 +936,11 @@
10380         LIST_HEAD(, scb)          pending_scbs;
10381  
10382         /*
10383 +        * SCBs whose timeout routine has been called.
10384 +        */
10385 +       LIST_HEAD(, scb)          timedout_scbs;
10386 +
10387 +       /*
10388          * Counting lock for deferring the release of additional
10389          * untagged transactions from the untagged_queues.  When
10390          * the lock is decremented to 0, all queues in the
10391 @@ -958,7 +970,7 @@
10392         /*
10393          * Platform specific device information.
10394          */
10395 -       ahc_dev_softc_t           dev_softc;
10396 +       aic_dev_softc_t           dev_softc;
10397  
10398         /*
10399          * Bus specific device information.
10400 @@ -1135,6 +1147,9 @@
10401  };
10402  
10403  /****************************** PCI Structures ********************************/
10404 +#define        AHC_PCI_IOADDR  PCIR_BAR(0)     /* I/O Address */
10405 +#define        AHC_PCI_MEMADDR PCIR_BAR(1)     /* Mem I/O Address */
10406 +
10407  typedef int (ahc_device_setup_t)(struct ahc_softc *);
10408  
10409  struct ahc_pci_identity {
10410 @@ -1167,7 +1182,7 @@
10411                                      u_int tcl, u_int busyid);
10412  
10413  /***************************** PCI Front End *********************************/
10414 -struct ahc_pci_identity        *ahc_find_pci_device(ahc_dev_softc_t);
10415 +struct ahc_pci_identity        *ahc_find_pci_device(aic_dev_softc_t);
10416  int                     ahc_pci_config(struct ahc_softc *,
10417                                         struct ahc_pci_identity *);
10418  int                     ahc_pci_test_register_access(struct ahc_softc *);
10419 @@ -1231,7 +1246,7 @@
10420                                            role_t role, uint32_t status,
10421                                            ahc_search_action action);
10422  int                    ahc_search_untagged_queues(struct ahc_softc *ahc,
10423 -                                                  ahc_io_ctx_t ctx,
10424 +                                                  aic_io_ctx_t ctx,
10425                                                    int target, char channel,
10426                                                    int lun, uint32_t status,
10427                                                    ahc_search_action action);
10428 @@ -1248,6 +1263,8 @@
10429  void                   ahc_restart(struct ahc_softc *ahc);
10430  void                   ahc_calc_residual(struct ahc_softc *ahc,
10431                                           struct scb *scb);
10432 +void                   ahc_timeout(struct scb *scb);
10433 +void                   ahc_recover_commands(struct ahc_softc *ahc);
10434  /*************************** Utility Functions ********************************/
10435  struct ahc_phase_table_entry*
10436                         ahc_lookup_phase_entry(int phase);
10437 diff -urN linux-2.4.24.org/drivers/scsi/aic7xxx/aic7xxx_inline.h linux-2.4.24/drivers/scsi/aic7xxx/aic7xxx_inline.h
10438 --- linux-2.4.24.org/drivers/scsi/aic7xxx/aic7xxx_inline.h      2004-01-08 11:57:43.033001028 +0100
10439 +++ linux-2.4.24/drivers/scsi/aic7xxx/aic7xxx_inline.h  2003-12-22 22:46:59.000000000 +0100
10440 @@ -37,7 +37,7 @@
10441   * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
10442   * POSSIBILITY OF SUCH DAMAGES.
10443   *
10444 - * $Id$
10445 + * $Id$
10446   *
10447   * $FreeBSD$
10448   */
10449 @@ -196,7 +196,7 @@
10450  static __inline void
10451  ahc_sync_scb(struct ahc_softc *ahc, struct scb *scb, int op)
10452  {
10453 -       ahc_dmamap_sync(ahc, ahc->scb_data->hscb_dmat,
10454 +       aic_dmamap_sync(ahc, ahc->scb_data->hscb_dmat,
10455                         ahc->scb_data->hscb_dmamap,
10456                         /*offset*/(scb->hscb - ahc->hscbs) * sizeof(*scb->hscb),
10457                         /*len*/sizeof(*scb->hscb), op);
10458 @@ -208,7 +208,7 @@
10459         if (scb->sg_count == 0)
10460                 return;
10461  
10462 -       ahc_dmamap_sync(ahc, ahc->scb_data->sg_dmat, scb->sg_map->sg_dmamap,
10463 +       aic_dmamap_sync(ahc, ahc->scb_data->sg_dmat, scb->sg_map->sg_dmamap,
10464                         /*offset*/(scb->sg_list - scb->sg_map->sg_vaddr)
10465                                 * sizeof(struct ahc_dma_seg),
10466                         /*len*/sizeof(struct ahc_dma_seg) * scb->sg_count, op);
10467 @@ -272,7 +272,7 @@
10468  {
10469         uint32_t sgptr;
10470  
10471 -       sgptr = ahc_le32toh(scb->hscb->sgptr);
10472 +       sgptr = aic_le32toh(scb->hscb->sgptr);
10473         if ((sgptr & SG_RESID_VALID) != 0)
10474                 ahc_calc_residual(ahc, scb);
10475  }
10476 @@ -383,13 +383,13 @@
10477         hscb = scb->hscb;
10478         /* Clean up for the next user */
10479         ahc->scb_data->scbindex[hscb->tag] = NULL;
10480 -       scb->flags = SCB_FREE;
10481 +       scb->flags = SCB_FLAG_NONE;
10482         hscb->control = 0;
10483  
10484         SLIST_INSERT_HEAD(&ahc->scb_data->free_scbs, scb, links.sle);
10485  
10486         /* Notify the OSM that a resource is now available. */
10487 -       ahc_platform_scb_free(ahc, scb);
10488 +       aic_platform_scb_free(ahc, scb);
10489  }
10490  
10491  static __inline struct scb *
10492 @@ -427,7 +427,7 @@
10493         memcpy(q_hscb, scb->hscb, sizeof(*scb->hscb));
10494         if ((scb->flags & SCB_CDB32_PTR) != 0) {
10495                 q_hscb->shared_data.cdb_ptr =
10496 -                   ahc_htole32(ahc_hscb_busaddr(ahc, q_hscb->tag)
10497 +                   aic_htole32(ahc_hscb_busaddr(ahc, q_hscb->tag)
10498                               + offsetof(struct hardware_scb, cdb32));
10499         }
10500         q_hscb->tag = saved_tag;
10501 @@ -458,7 +458,7 @@
10502          * Setup data "oddness".
10503          */
10504         scb->hscb->lun &= LID;
10505 -       if (ahc_get_transfer_length(scb) & 0x1)
10506 +       if (aic_get_transfer_length(scb) & 0x1)
10507                 scb->hscb->lun |= SCB_XFERLEN_ODD;
10508  
10509         /*
10510 @@ -512,7 +512,7 @@
10511  static __inline void
10512  ahc_sync_qoutfifo(struct ahc_softc *ahc, int op)
10513  {
10514 -       ahc_dmamap_sync(ahc, ahc->shared_data_dmat, ahc->shared_data_dmamap,
10515 +       aic_dmamap_sync(ahc, ahc->shared_data_dmat, ahc->shared_data_dmamap,
10516                         /*offset*/0, /*len*/256, op);
10517  }
10518  
10519 @@ -521,7 +521,7 @@
10520  {
10521  #ifdef AHC_TARGET_MODE
10522         if ((ahc->flags & AHC_TARGETROLE) != 0) {
10523 -               ahc_dmamap_sync(ahc, ahc->shared_data_dmat,
10524 +               aic_dmamap_sync(ahc, ahc->shared_data_dmat,
10525                                 ahc->shared_data_dmamap,
10526                                 ahc_targetcmd_offset(ahc, 0),
10527                                 sizeof(struct target_cmd) * AHC_TMODE_CMDS,
10528 @@ -542,7 +542,7 @@
10529         u_int retval;
10530  
10531         retval = 0;
10532 -       ahc_dmamap_sync(ahc, ahc->shared_data_dmat, ahc->shared_data_dmamap,
10533 +       aic_dmamap_sync(ahc, ahc->shared_data_dmat, ahc->shared_data_dmamap,
10534                         /*offset*/ahc->qoutfifonext, /*len*/1,
10535                         BUS_DMASYNC_POSTREAD);
10536         if (ahc->qoutfifo[ahc->qoutfifonext] != SCB_LIST_NULL)
10537 @@ -550,7 +550,7 @@
10538  #ifdef AHC_TARGET_MODE
10539         if ((ahc->flags & AHC_TARGETROLE) != 0
10540          && (ahc->flags & AHC_TQINFIFO_BLOCKED) == 0) {
10541 -               ahc_dmamap_sync(ahc, ahc->shared_data_dmat,
10542 +               aic_dmamap_sync(ahc, ahc->shared_data_dmat,
10543                                 ahc->shared_data_dmamap,
10544                                 ahc_targetcmd_offset(ahc, ahc->tqinfifofnext),
10545                                 /*len*/sizeof(struct target_cmd),
10546 @@ -593,7 +593,7 @@
10547         }
10548  
10549         if ((intstat & INT_PEND) == 0) {
10550 -#if AHC_PCI_CONFIG > 0
10551 +#if AIC_PCI_CONFIG > 0
10552                 if (ahc->unsolicited_ints > 500) {
10553                         ahc->unsolicited_ints = 0;
10554                         if ((ahc->chip & AHC_PCI) != 0
10555 diff -urN linux-2.4.24.org/drivers/scsi/aic7xxx/aic7xxx_osm.c linux-2.4.24/drivers/scsi/aic7xxx/aic7xxx_osm.c
10556 --- linux-2.4.24.org/drivers/scsi/aic7xxx/aic7xxx_osm.c 2004-01-08 11:57:43.012005368 +0100
10557 +++ linux-2.4.24/drivers/scsi/aic7xxx/aic7xxx_osm.c     2003-12-22 22:46:59.000000000 +0100
10558 @@ -1,7 +1,7 @@
10559  /*
10560   * Adaptec AIC7xxx device driver for Linux.
10561   *
10562 - * $Id$
10563 + * $Id$
10564   *
10565   * Copyright (c) 1994 John Aycock
10566   *   The University of Calgary Department of Computer Science.
10567 @@ -139,7 +139,16 @@
10568  #endif
10569  
10570  #include <linux/mm.h>          /* For fetching system memory size */
10571 -#include <linux/blk.h>         /* For block_size() */
10572 +
10573 +/************************* Magic SysReq Support *******************************/
10574 +static struct aic_sysrq_key_op ahc_sysrq_op =
10575 +{
10576 +       aic_sysrq_handler,
10577 +       "aic7xxxstatedump",
10578 +       "Dump aic7xxx controller information to Console"
10579 +};
10580 +
10581 +static int ahc_sysrq_key;
10582  
10583  /*
10584   * Lock protecting manipulation of the ahc softc list.
10585 @@ -482,35 +491,32 @@
10586  #endif
10587  
10588  static void ahc_linux_handle_scsi_status(struct ahc_softc *,
10589 -                                        struct ahc_linux_device *,
10590 +                                        struct aic_linux_device *,
10591                                          struct scb *);
10592  static void ahc_linux_queue_cmd_complete(struct ahc_softc *ahc,
10593                                          Scsi_Cmnd *cmd);
10594  static void ahc_linux_filter_inquiry(struct ahc_softc*, struct ahc_devinfo*);
10595  static void ahc_linux_sem_timeout(u_long arg);
10596 -static void ahc_linux_freeze_simq(struct ahc_softc *ahc);
10597 -static void ahc_linux_release_simq(u_long arg);
10598  static void ahc_linux_dev_timed_unfreeze(u_long arg);
10599  static int  ahc_linux_queue_recovery_cmd(Scsi_Cmnd *cmd, scb_flag flag);
10600  static void ahc_linux_initialize_scsi_bus(struct ahc_softc *ahc);
10601  static void ahc_linux_size_nseg(void);
10602  static void ahc_linux_thread_run_complete_queue(struct ahc_softc *ahc);
10603  static void ahc_linux_start_dv(struct ahc_softc *ahc);
10604 -static void ahc_linux_dv_timeout(struct scsi_cmnd *cmd);
10605  static int  ahc_linux_dv_thread(void *data);
10606  static void ahc_linux_kill_dv_thread(struct ahc_softc *ahc);
10607  static void ahc_linux_dv_target(struct ahc_softc *ahc, u_int target);
10608  static void ahc_linux_dv_transition(struct ahc_softc *ahc,
10609                                     struct scsi_cmnd *cmd,
10610                                     struct ahc_devinfo *devinfo,
10611 -                                   struct ahc_linux_target *targ);
10612 +                                   struct aic_linux_target *targ);
10613  static void ahc_linux_dv_fill_cmd(struct ahc_softc *ahc,
10614                                   struct scsi_cmnd *cmd,
10615                                   struct ahc_devinfo *devinfo);
10616  static void ahc_linux_dv_inq(struct ahc_softc *ahc,
10617                              struct scsi_cmnd *cmd,
10618                              struct ahc_devinfo *devinfo,
10619 -                            struct ahc_linux_target *targ,
10620 +                            struct aic_linux_target *targ,
10621                              u_int request_length);
10622  static void ahc_linux_dv_tur(struct ahc_softc *ahc,
10623                              struct scsi_cmnd *cmd,
10624 @@ -518,58 +524,48 @@
10625  static void ahc_linux_dv_rebd(struct ahc_softc *ahc,
10626                               struct scsi_cmnd *cmd,
10627                               struct ahc_devinfo *devinfo,
10628 -                             struct ahc_linux_target *targ);
10629 +                             struct aic_linux_target *targ);
10630  static void ahc_linux_dv_web(struct ahc_softc *ahc,
10631                              struct scsi_cmnd *cmd,
10632                              struct ahc_devinfo *devinfo,
10633 -                            struct ahc_linux_target *targ);
10634 +                            struct aic_linux_target *targ);
10635  static void ahc_linux_dv_reb(struct ahc_softc *ahc,
10636                              struct scsi_cmnd *cmd,
10637                              struct ahc_devinfo *devinfo,
10638 -                            struct ahc_linux_target *targ);
10639 +                            struct aic_linux_target *targ);
10640  static void ahc_linux_dv_su(struct ahc_softc *ahc,
10641                             struct scsi_cmnd *cmd,
10642                             struct ahc_devinfo *devinfo,
10643 -                           struct ahc_linux_target *targ);
10644 +                           struct aic_linux_target *targ);
10645  static int ahc_linux_fallback(struct ahc_softc *ahc,
10646                               struct ahc_devinfo *devinfo);
10647 -static void ahc_linux_dv_complete(Scsi_Cmnd *cmd);
10648 -static void ahc_linux_generate_dv_pattern(struct ahc_linux_target *targ);
10649 +static void ahc_linux_generate_dv_pattern(struct aic_linux_target *targ);
10650  static u_int ahc_linux_user_tagdepth(struct ahc_softc *ahc,
10651                                      struct ahc_devinfo *devinfo);
10652  static u_int ahc_linux_user_dv_setting(struct ahc_softc *ahc);
10653 -static void ahc_linux_device_queue_depth(struct ahc_softc *ahc,
10654 -                                        struct ahc_linux_device *dev);
10655 -static struct ahc_linux_target*        ahc_linux_alloc_target(struct ahc_softc*,
10656 +static void aic_linux_device_queue_depth(struct ahc_softc *ahc,
10657 +                                        struct aic_linux_device *dev);
10658 +static struct aic_linux_target*        ahc_linux_alloc_target(struct ahc_softc*,
10659                                                        u_int, u_int);
10660  static void                    ahc_linux_free_target(struct ahc_softc*,
10661 -                                                     struct ahc_linux_target*);
10662 -static struct ahc_linux_device*        ahc_linux_alloc_device(struct ahc_softc*,
10663 -                                                      struct ahc_linux_target*,
10664 +                                                     struct aic_linux_target*);
10665 +static struct aic_linux_device*        ahc_linux_alloc_device(struct ahc_softc*,
10666 +                                                      struct aic_linux_target*,
10667                                                        u_int);
10668  static void                    ahc_linux_free_device(struct ahc_softc*,
10669 -                                                     struct ahc_linux_device*);
10670 -static void ahc_linux_run_device_queue(struct ahc_softc*,
10671 -                                      struct ahc_linux_device*);
10672 +                                                     struct aic_linux_device*);
10673  static void ahc_linux_setup_tag_info_global(char *p);
10674  static aic_option_callback_t ahc_linux_setup_tag_info;
10675  static aic_option_callback_t ahc_linux_setup_dv;
10676  static int  aic7xxx_setup(char *s);
10677  static int  ahc_linux_next_unit(void);
10678 -static void ahc_runq_tasklet(unsigned long data);
10679 -static struct ahc_cmd *ahc_linux_run_complete_queue(struct ahc_softc *ahc);
10680 +static struct aic_cmd *ahc_linux_run_complete_queue(struct ahc_softc *ahc);
10681  
10682  /********************************* Inlines ************************************/
10683 -static __inline void ahc_schedule_runq(struct ahc_softc *ahc);
10684 -static __inline struct ahc_linux_device*
10685 +static __inline struct aic_linux_device*
10686                      ahc_linux_get_device(struct ahc_softc *ahc, u_int channel,
10687                                           u_int target, u_int lun, int alloc);
10688  static __inline void ahc_schedule_completeq(struct ahc_softc *ahc);
10689 -static __inline void ahc_linux_check_device_queue(struct ahc_softc *ahc,
10690 -                                                 struct ahc_linux_device *dev);
10691 -static __inline struct ahc_linux_device *
10692 -                    ahc_linux_next_device_to_run(struct ahc_softc *ahc);
10693 -static __inline void ahc_linux_run_device_queues(struct ahc_softc *ahc);
10694  static __inline void ahc_linux_unmap_scb(struct ahc_softc*, struct scb*);
10695  
10696  static __inline int ahc_linux_map_seg(struct ahc_softc *ahc, struct scb *scb,
10697 @@ -579,35 +575,19 @@
10698  static __inline void
10699  ahc_schedule_completeq(struct ahc_softc *ahc)
10700  {
10701 -       if ((ahc->platform_data->flags & AHC_RUN_CMPLT_Q_TIMER) == 0) {
10702 -               ahc->platform_data->flags |= AHC_RUN_CMPLT_Q_TIMER;
10703 +       if ((ahc->platform_data->flags & AIC_RUN_CMPLT_Q_TIMER) == 0) {
10704 +               ahc->platform_data->flags |= AIC_RUN_CMPLT_Q_TIMER;
10705                 ahc->platform_data->completeq_timer.expires = jiffies;
10706                 add_timer(&ahc->platform_data->completeq_timer);
10707         }
10708  }
10709  
10710 -/*
10711 - * Must be called with our lock held.
10712 - */
10713 -static __inline void
10714 -ahc_schedule_runq(struct ahc_softc *ahc)
10715 -{
10716 -#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,0)
10717 -       tasklet_schedule(&ahc->platform_data->runq_tasklet);
10718 -#else
10719 -       /*
10720 -        * Tasklets are not available, so run inline.
10721 -        */
10722 -       ahc_runq_tasklet((unsigned long)ahc);
10723 -#endif
10724 -}
10725 -
10726 -static __inline struct ahc_linux_device*
10727 +static __inline struct aic_linux_device*
10728  ahc_linux_get_device(struct ahc_softc *ahc, u_int channel, u_int target,
10729                      u_int lun, int alloc)
10730  {
10731 -       struct ahc_linux_target *targ;
10732 -       struct ahc_linux_device *dev;
10733 +       struct aic_linux_target *targ;
10734 +       struct aic_linux_device *dev;
10735         u_int target_offset;
10736  
10737         target_offset = target;
10738 @@ -629,10 +609,10 @@
10739  }
10740  
10741  #define AHC_LINUX_MAX_RETURNED_ERRORS 4
10742 -static struct ahc_cmd *
10743 +static struct aic_cmd *
10744  ahc_linux_run_complete_queue(struct ahc_softc *ahc)
10745  {
10746 -       struct  ahc_cmd *acmd;
10747 +       struct  aic_cmd *acmd;
10748         u_long  done_flags;
10749         int     with_errors;
10750  
10751 @@ -657,7 +637,7 @@
10752                              acmd, acmd_links.tqe);
10753                 cmd = &acmd_scsi_cmd(acmd);
10754                 cmd->host_scribble = NULL;
10755 -               if (ahc_cmd_get_transaction_status(cmd) != DID_OK
10756 +               if (aic_cmd_get_transaction_status(cmd) != DID_OK
10757                  || (cmd->result & 0xFF) != SCSI_STATUS_OK)
10758                         with_errors++;
10759  
10760 @@ -666,47 +646,6 @@
10761         ahc_done_unlock(ahc, &done_flags);
10762         return (acmd);
10763  }
10764 -
10765 -static __inline void
10766 -ahc_linux_check_device_queue(struct ahc_softc *ahc,
10767 -                            struct ahc_linux_device *dev)
10768 -{
10769 -       if ((dev->flags & AHC_DEV_FREEZE_TIL_EMPTY) != 0
10770 -        && dev->active == 0) {
10771 -               dev->flags &= ~AHC_DEV_FREEZE_TIL_EMPTY;
10772 -               dev->qfrozen--;
10773 -       }
10774 -
10775 -       if (TAILQ_FIRST(&dev->busyq) == NULL
10776 -        || dev->openings == 0 || dev->qfrozen != 0)
10777 -               return;
10778 -
10779 -       ahc_linux_run_device_queue(ahc, dev);
10780 -}
10781 -
10782 -static __inline struct ahc_linux_device *
10783 -ahc_linux_next_device_to_run(struct ahc_softc *ahc)
10784 -{
10785 -       
10786 -       if ((ahc->flags & AHC_RESOURCE_SHORTAGE) != 0
10787 -        || (ahc->platform_data->qfrozen != 0
10788 -         && AHC_DV_SIMQ_FROZEN(ahc) == 0))
10789 -               return (NULL);
10790 -       return (TAILQ_FIRST(&ahc->platform_data->device_runq));
10791 -}
10792 -
10793 -static __inline void
10794 -ahc_linux_run_device_queues(struct ahc_softc *ahc)
10795 -{
10796 -       struct ahc_linux_device *dev;
10797 -
10798 -       while ((dev = ahc_linux_next_device_to_run(ahc)) != NULL) {
10799 -               TAILQ_REMOVE(&ahc->platform_data->device_runq, dev, links);
10800 -               dev->flags &= ~AHC_DEV_ON_RUN_LIST;
10801 -               ahc_linux_check_device_queue(ahc, dev);
10802 -       }
10803 -}
10804 -
10805  static __inline void
10806  ahc_linux_unmap_scb(struct ahc_softc *ahc, struct scb *scb)
10807  {
10808 @@ -718,10 +657,10 @@
10809                 struct scatterlist *sg;
10810  
10811                 sg = (struct scatterlist *)cmd->request_buffer;
10812 -               pci_unmap_sg(ahc->dev_softc, sg, cmd->use_sg,
10813 +               aic_unmap_sg(ahc, sg, cmd->use_sg,
10814                              scsi_to_pci_dma_dir(cmd->sc_data_direction));
10815         } else if (cmd->request_bufflen != 0) {
10816 -               pci_unmap_single(ahc->dev_softc,
10817 +               aic_unmap_single(ahc,
10818                                  scb->platform_data->buf_busaddr,
10819                                  cmd->request_bufflen,
10820                                  scsi_to_pci_dma_dir(cmd->sc_data_direction));
10821 @@ -739,14 +678,14 @@
10822                       "Increase AHC_NSEG\n");
10823  
10824         consumed = 1;
10825 -       sg->addr = ahc_htole32(addr & 0xFFFFFFFF);
10826 +       sg->addr = aic_htole32(addr & 0xFFFFFFFF);
10827         scb->platform_data->xfer_len += len;
10828  
10829         if (sizeof(bus_addr_t) > 4
10830          && (ahc->flags & AHC_39BIT_ADDRESSING) != 0)
10831                 len |= (addr >> 8) & AHC_SG_HIGH_ADDR_MASK;
10832  
10833 -       sg->len = ahc_htole32(len);
10834 +       sg->len = aic_htole32(len);
10835         return (consumed);
10836  }
10837  
10838 @@ -836,6 +775,164 @@
10839  #endif
10840  }
10841  
10842 +/************************** Error Recovery ************************************/
10843 +static int ahc_linux_recovery_thread(void *arg);
10844 +
10845 +static int
10846 +ahc_linux_recovery_thread(void *arg)
10847 +{
10848 +       struct ahc_softc *ahc;
10849 +       u_long s;
10850 +
10851 +       ahc = (struct ahc_softc *)arg;
10852 +
10853 +       /*
10854 +        * Complete thread creation.
10855 +        */
10856 +       lock_kernel();
10857 +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,5,60)
10858 +       /*
10859 +        * Don't care about any signals.
10860 +        */
10861 +       siginitsetinv(&current->blocked, 0);
10862 +
10863 +       daemonize();
10864 +       sprintf(current->comm, "ahc_recovery_%d", ahc->unit);
10865 +#else
10866 +       daemonize("ahc_recovery_%d", ahc->unit);
10867 +#endif
10868 +       unlock_kernel();
10869 +
10870 +       while (1) {
10871 +
10872 +               /*
10873 +                * Use down_interruptible() rather than down() to
10874 +                * avoid inclusion in the load average.
10875 +                */
10876 +               down_interruptible(&ahc->platform_data->recovery_sem);
10877 +
10878 +               ahc_lock(ahc, &s);
10879 +               if ((ahc->flags & AHC_SHUTDOWN_RECOVERY) != 0) {
10880 +                       ahc_unlock(ahc, &s);
10881 +                       break;
10882 +               }
10883 +
10884 +               /*
10885 +                * Don't bother the recovery handler if the
10886 +                * list has been cleared by a previous run
10887 +                * of the handler.  This can happen when
10888 +                * several SCBs timeout before our handler
10889 +                * can run causing our semaphore to be up'ed
10890 +                * repeatedly.  The extra calls need to be
10891 +                * avoided so that the recovery handler doesn't
10892 +                * confuse this case with timeouts occuring
10893 +                * due to interrupts failing to function.
10894 +                */
10895 +               if (LIST_EMPTY(&ahc->timedout_scbs) != 0) {
10896 +                       ahc_unlock(ahc, &s);
10897 +                       continue;
10898 +               }
10899 +               ahc_unlock(ahc, &s);
10900 +               ahc_recover_commands(ahc);
10901 +
10902 +               /*
10903 +                * Process any pent up completions.
10904 +                */
10905 +               ahc_lock(ahc, &s);
10906 +               aic_schedule_runq(ahc);
10907 +               ahc_linux_run_complete_queue(ahc);
10908 +               ahc_unlock(ahc, &s);
10909 +       }
10910 +       up(&ahc->platform_data->recovery_ending_sem);
10911 +       return(0);
10912 +}
10913 +
10914 +int
10915 +ahc_spawn_recovery_thread(struct ahc_softc *ahc)
10916 +{
10917 +       ahc->platform_data->recovery_pid =
10918 +           kernel_thread(ahc_linux_recovery_thread, ahc, 0);
10919 +
10920 +       if (ahc->platform_data->recovery_pid < 0)
10921 +               return (-ahc->platform_data->recovery_pid);
10922 +
10923 +       return (0);
10924 +}
10925 +
10926 +void
10927 +ahc_terminate_recovery_thread(struct ahc_softc *ahc)
10928 +{
10929 +       u_long s;
10930 +
10931 +       ahc_lock(ahc, &s);
10932 +       if (ahc->platform_data->recovery_pid != 0) {
10933 +               ahc->flags |= AHC_SHUTDOWN_RECOVERY;
10934 +               ahc_unlock(ahc, &s);
10935 +               up(&ahc->platform_data->recovery_sem);
10936 +
10937 +               /*
10938 +                * Use the recovery_ending_sem as an indicator that
10939 +                * the dv thread is exiting.  Note that the dv
10940 +                * thread must still return after performing
10941 +                * the up on our semaphore before it has
10942 +                * completely exited this module.  Unfortunately,
10943 +                * there seems to be no easy way to wait for the
10944 +                * exit of a thread for which you are not the
10945 +                * parent (dv threads are parented by init).
10946 +                * Cross your fingers...
10947 +                */
10948 +               down(&ahc->platform_data->recovery_ending_sem);
10949 +
10950 +               /*
10951 +                * Mark the recovery thread as already dead.  This
10952 +                * avoids attempting to kill it a second time.
10953 +                * This is necessary because we must kill the
10954 +                * our threads before calling ahc_free() in the
10955 +                * module shutdown case to avoid bogus locking
10956 +                * in the SCSI mid-layer, but when ahc_free() is
10957 +                * called without killing the DV thread in the
10958 +                * instance detach case, so ahc_platform_free()
10959 +                * calls us again to verify that the DV thread
10960 +                * is dead.
10961 +                */
10962 +               ahc->platform_data->recovery_pid = 0;
10963 +       } else {
10964 +               ahc_unlock(ahc, &s);
10965 +       }
10966 +}
10967 +
10968 +void
10969 +ahc_set_recoveryscb(struct ahc_softc *ahc, struct scb *scb)
10970 +{
10971 +       if ((scb->flags & SCB_RECOVERY_SCB) == 0) {
10972 +               struct scb *list_scb;
10973 +
10974 +               scb->flags |= SCB_RECOVERY_SCB;
10975 +
10976 +               /*
10977 +                * Take all queued, but not sent SCBs out of the equation.
10978 +                * Also ensure that no new commands are queued to us while we
10979 +                * try to fix this problem.
10980 +                */
10981 +               if ((scb->platform_data->flags & AIC_RELEASE_SIMQ) == 0) {
10982 +                       aic_freeze_simq(ahc);
10983 +                       scb->platform_data->flags |= AIC_RELEASE_SIMQ;
10984 +               }
10985 +
10986 +               /*
10987 +                * Go through all of our pending SCBs and remove
10988 +                * any scheduled timeouts for them.  We will reschedule
10989 +                * them after we've successfully fixed this problem.
10990 +                */
10991 +               LIST_FOREACH(list_scb, &ahc->pending_scbs, pending_links) {
10992 +
10993 +                       scsi_delete_timer(list_scb->io_ctx);
10994 +                       list_scb->platform_data->flags &= ~AIC_TIMEOUT_ACTIVE;
10995 +               }
10996 +       }
10997 +}
10998 +
10999 +/************************ Linux Entry Points **********************************/
11000  /*
11001   * Try to detect an Adaptec 7XXX controller.
11002   */
11003 @@ -858,7 +955,7 @@
11004          * that some of our hacks^H^H^H^H^Hassumptions aren't
11005          * violated.
11006          */
11007 -       if (offsetof(struct ahc_cmd_internal, end)
11008 +       if (offsetof(struct aic_cmd_internal, end)
11009           > offsetof(struct scsi_cmnd, host_scribble)) {
11010                 printf("ahc_linux_detect: SCSI data structures changed.\n");
11011                 printf("ahc_linux_detect: Unable to attach\n");
11012 @@ -927,7 +1024,6 @@
11013         struct ahc_softc *ahc;
11014         u_long l;
11015  
11016 -       ahc_list_lock(&l);
11017         if (host != NULL) {
11018  
11019                 /*
11020 @@ -935,17 +1031,20 @@
11021                  * the free directly, but check our
11022                  * list for extra sanity.
11023                  */
11024 +               ahc_list_lock(&l);
11025                 ahc = ahc_find_softc(*(struct ahc_softc **)host->hostdata);
11026                 if (ahc != NULL) {
11027                         u_long s;
11028  
11029 +                       TAILQ_REMOVE(&ahc_tailq, ahc, links);
11030 +                       ahc_list_unlock(&l);
11031                         ahc_lock(ahc, &s);
11032                         ahc_intr_enable(ahc, FALSE);
11033                         ahc_unlock(ahc, &s);
11034                         ahc_free(ahc);
11035 -               }
11036 +               } else
11037 +                       ahc_list_unlock(&l);
11038         }
11039 -       ahc_list_unlock(&l);
11040         return (0);
11041  }
11042  #endif
11043 @@ -985,7 +1084,7 @@
11044  ahc_linux_queue(Scsi_Cmnd * cmd, void (*scsi_done) (Scsi_Cmnd *))
11045  {
11046         struct   ahc_softc *ahc;
11047 -       struct   ahc_linux_device *dev;
11048 +       struct   aic_linux_device *dev;
11049         u_long   flags;
11050  
11051         ahc = *(struct ahc_softc **)cmd->device->host->hostdata;
11052 @@ -1004,9 +1103,9 @@
11053          * perform DV.
11054          */
11055         if (ahc->platform_data->qfrozen != 0
11056 -        && AHC_DV_CMD(cmd) == 0) {
11057 +        && AIC_DV_CMD(cmd) == 0) {
11058  
11059 -               ahc_cmd_set_transaction_status(cmd, CAM_REQUEUE_REQ);
11060 +               aic_cmd_set_transaction_status(cmd, CAM_REQUEUE_REQ);
11061                 ahc_linux_queue_cmd_complete(ahc, cmd);
11062                 ahc_schedule_completeq(ahc);
11063                 ahc_midlayer_entrypoint_unlock(ahc, &flags);
11064 @@ -1015,7 +1114,8 @@
11065         dev = ahc_linux_get_device(ahc, cmd->device->channel, cmd->device->id,
11066                                    cmd->device->lun, /*alloc*/TRUE);
11067         if (dev == NULL) {
11068 -               ahc_cmd_set_transaction_status(cmd, CAM_RESRC_UNAVAIL);
11069 +
11070 +               aic_cmd_set_transaction_status(cmd, CAM_RESRC_UNAVAIL);
11071                 ahc_linux_queue_cmd_complete(ahc, cmd);
11072                 ahc_schedule_completeq(ahc);
11073                 ahc_midlayer_entrypoint_unlock(ahc, &flags);
11074 @@ -1023,12 +1123,30 @@
11075                        ahc_name(ahc));
11076                 return (0);
11077         }
11078 +
11079 +       if (cmd->cmd_len > MAX_CDB_LEN) {
11080 +
11081 +               aic_cmd_set_transaction_status(cmd, CAM_REQ_INVALID);
11082 +               ahc_linux_queue_cmd_complete(ahc, cmd);
11083 +               ahc_schedule_completeq(ahc);
11084 +               ahc_midlayer_entrypoint_unlock(ahc, &flags);
11085 +               printf("%s: aic7xxx_linux_queue -"
11086 +                      "CDB length of %d exceeds max!\n",
11087 +                      ahc_name(ahc), cmd->cmd_len);
11088 +               return (0);
11089 +       }
11090 +
11091 +       /*
11092 +        * We perform our own timeout handling.
11093 +        */
11094 +       scsi_delete_timer(cmd);
11095 +
11096         cmd->result = CAM_REQ_INPROG << 16;
11097 -       TAILQ_INSERT_TAIL(&dev->busyq, (struct ahc_cmd *)cmd, acmd_links.tqe);
11098 -       if ((dev->flags & AHC_DEV_ON_RUN_LIST) == 0) {
11099 +       TAILQ_INSERT_TAIL(&dev->busyq, (struct aic_cmd *)cmd, acmd_links.tqe);
11100 +       if ((dev->flags & AIC_DEV_ON_RUN_LIST) == 0) {
11101                 TAILQ_INSERT_TAIL(&ahc->platform_data->device_runq, dev, links);
11102 -               dev->flags |= AHC_DEV_ON_RUN_LIST;
11103 -               ahc_linux_run_device_queues(ahc);
11104 +               dev->flags |= AIC_DEV_ON_RUN_LIST;
11105 +               aic_linux_run_device_queues(ahc);
11106         }
11107         ahc_midlayer_entrypoint_unlock(ahc, &flags);
11108         return (0);
11109 @@ -1050,7 +1168,7 @@
11110  ahc_linux_slave_configure(Scsi_Device *device)
11111  {
11112         struct  ahc_softc *ahc;
11113 -       struct  ahc_linux_device *dev;
11114 +       struct  aic_linux_device *dev;
11115         u_long  flags;
11116  
11117         ahc = *((struct ahc_softc **)device->host->hostdata);
11118 @@ -1066,9 +1184,9 @@
11119                                    device->id, device->lun,
11120                                    /*alloc*/TRUE);
11121         if (dev != NULL) {
11122 -               dev->flags &= ~AHC_DEV_UNCONFIGURED;
11123 +               dev->flags &= ~AIC_DEV_UNCONFIGURED;
11124                 dev->scsi_device = device;
11125 -               ahc_linux_device_queue_depth(ahc, dev);
11126 +               aic_linux_device_queue_depth(ahc, dev);
11127         }
11128         ahc_midlayer_entrypoint_unlock(ahc, &flags);
11129         return (0);
11130 @@ -1078,7 +1196,7 @@
11131  ahc_linux_slave_destroy(Scsi_Device *device)
11132  {
11133         struct  ahc_softc *ahc;
11134 -       struct  ahc_linux_device *dev;
11135 +       struct  aic_linux_device *dev;
11136         u_long  flags;
11137  
11138         ahc = *((struct ahc_softc **)device->host->hostdata);
11139 @@ -1096,11 +1214,10 @@
11140          * the refcounting process.
11141          */
11142         if (dev != NULL
11143 -        && (dev->flags & AHC_DEV_SLAVE_CONFIGURED) != 0) {
11144 -               dev->flags |= AHC_DEV_UNCONFIGURED;
11145 +        && (dev->flags & AIC_DEV_SLAVE_CONFIGURED) != 0) {
11146 +               dev->flags |= AIC_DEV_UNCONFIGURED;
11147                 if (TAILQ_EMPTY(&dev->busyq)
11148 -                && dev->active == 0
11149 -                && (dev->flags & AHC_DEV_TIMER_ACTIVE) == 0)
11150 +                && dev->active == 0)
11151                         ahc_linux_free_device(ahc, dev);
11152         }
11153         ahc_midlayer_entrypoint_unlock(ahc, &flags);
11154 @@ -1139,7 +1256,7 @@
11155                         continue;
11156  
11157                 if (device->host == host) {
11158 -                       struct   ahc_linux_device *dev;
11159 +                       struct   aic_linux_device *dev;
11160  
11161                         /*
11162                          * Since Linux has attached to the device, configure
11163 @@ -1150,13 +1267,13 @@
11164                                                    device->id, device->lun,
11165                                                    /*alloc*/TRUE);
11166                         if (dev != NULL) {
11167 -                               dev->flags &= ~AHC_DEV_UNCONFIGURED;
11168 +                               dev->flags &= ~AIC_DEV_UNCONFIGURED;
11169                                 dev->scsi_device = device;
11170 -                               ahc_linux_device_queue_depth(ahc, dev);
11171 +                               aic_linux_device_queue_depth(ahc, dev);
11172                                 device->queue_depth = dev->openings
11173                                                     + dev->active;
11174 -                               if ((dev->flags & (AHC_DEV_Q_BASIC
11175 -                                               | AHC_DEV_Q_TAGGED)) == 0) {
11176 +                               if ((dev->flags & (AIC_DEV_Q_BASIC
11177 +                                               | AIC_DEV_Q_TAGGED)) == 0) {
11178                                         /*
11179                                          * We allow the OS to queue 2 untagged
11180                                          * transactions to us at any time even
11181 @@ -1294,87 +1411,8 @@
11182         return SUCCESS;
11183  }
11184  
11185 -Scsi_Host_Template aic7xxx_driver_template = {
11186 -       .module                 = THIS_MODULE,
11187 -       .name                   = "aic7xxx",
11188 -       .proc_info              = ahc_linux_proc_info,
11189 -       .info                   = ahc_linux_info,
11190 -       .queuecommand           = ahc_linux_queue,
11191 -       .eh_abort_handler       = ahc_linux_abort,
11192 -       .eh_device_reset_handler = ahc_linux_dev_reset,
11193 -       .eh_bus_reset_handler   = ahc_linux_bus_reset,
11194 -#if defined(__i386__)
11195 -       .bios_param             = ahc_linux_biosparam,
11196 -#endif
11197 -       .can_queue              = AHC_MAX_QUEUE,
11198 -       .this_id                = -1,
11199 -       .cmd_per_lun            = 2,
11200 -       .use_clustering         = ENABLE_CLUSTERING,
11201 -#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,7)
11202 -       /*
11203 -        * We can only map 16MB per-SG
11204 -        * so create a sector limit of
11205 -        * "16MB" in 2K sectors.
11206 -        */
11207 -       .max_sectors            = 8192,
11208 -#endif
11209 -#if defined CONFIG_HIGHIO || LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,0)
11210 -#if LINUX_VERSION_CODE < KERNEL_VERSION(2,4,10)
11211 -/* Assume RedHat Distribution with its different HIGHIO conventions. */
11212 -       .can_dma_32             = 1,
11213 -       .single_sg_okay         = 1,
11214 -#else
11215 -       .highmem_io             = 1,
11216 -#endif
11217 -#endif
11218 -#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,0)
11219 -       .slave_alloc            = ahc_linux_slave_alloc,
11220 -       .slave_configure        = ahc_linux_slave_configure,
11221 -       .slave_destroy          = ahc_linux_slave_destroy,
11222 -#else
11223 -       .detect                 = ahc_linux_detect,
11224 -       .release                = ahc_linux_release,
11225 -       .select_queue_depths    = ahc_linux_select_queue_depth,
11226 -       .use_new_eh_code        = 1,
11227 -#endif
11228 -};
11229 -
11230 -/**************************** Tasklet Handler *********************************/
11231 -
11232 -/*
11233 - * In 2.4.X and above, this routine is called from a tasklet,
11234 - * so we must re-acquire our lock prior to executing this code.
11235 - * In all prior kernels, ahc_schedule_runq() calls this routine
11236 - * directly and ahc_schedule_runq() is called with our lock held.
11237 - */
11238 -static void
11239 -ahc_runq_tasklet(unsigned long data)
11240 -{
11241 -       struct ahc_softc* ahc;
11242 -       struct ahc_linux_device *dev;
11243 -#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,0)
11244 -       u_long flags;
11245 -#endif
11246 -
11247 -       ahc = (struct ahc_softc *)data;
11248 -#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,0)
11249 -       ahc_lock(ahc, &flags);
11250 -#endif
11251 -       while ((dev = ahc_linux_next_device_to_run(ahc)) != NULL) {
11252 -       
11253 -               TAILQ_REMOVE(&ahc->platform_data->device_runq, dev, links);
11254 -               dev->flags &= ~AHC_DEV_ON_RUN_LIST;
11255 -               ahc_linux_check_device_queue(ahc, dev);
11256 -#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,0)
11257 -               /* Yeild to our interrupt handler */
11258 -               ahc_unlock(ahc, &flags);
11259 -               ahc_lock(ahc, &flags);
11260 -#endif
11261 -       }
11262 -#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,0)
11263 -       ahc_unlock(ahc, &flags);
11264 -#endif
11265 -}
11266 +Scsi_Host_Template aic7xxx_driver_template =
11267 +       AIC_TEMPLATE_INITIALIZER("aic7xxx", /* max_sectors*/8192);
11268  
11269  /******************************** Macros **************************************/
11270  #define BUILD_SCSIID(ahc, cmd)                                             \
11271 @@ -1382,132 +1420,6 @@
11272         | (((cmd)->device->channel == 0) ? (ahc)->our_id : (ahc)->our_id_b) \
11273         | (((cmd)->device->channel == 0) ? 0 : TWIN_CHNLB))
11274  
11275 -/******************************** Bus DMA *************************************/
11276 -int
11277 -ahc_dma_tag_create(struct ahc_softc *ahc, bus_dma_tag_t parent,
11278 -                  bus_size_t alignment, bus_size_t boundary,
11279 -                  bus_addr_t lowaddr, bus_addr_t highaddr,
11280 -                  bus_dma_filter_t *filter, void *filterarg,
11281 -                  bus_size_t maxsize, int nsegments,
11282 -                  bus_size_t maxsegsz, int flags, bus_dma_tag_t *ret_tag)
11283 -{
11284 -       bus_dma_tag_t dmat;
11285 -
11286 -       dmat = malloc(sizeof(*dmat), M_DEVBUF, M_NOWAIT);
11287 -       if (dmat == NULL)
11288 -               return (ENOMEM);
11289 -
11290 -       /*
11291 -        * Linux is very simplistic about DMA memory.  For now don't
11292 -        * maintain all specification information.  Once Linux supplies
11293 -        * better facilities for doing these operations, or the
11294 -        * needs of this particular driver change, we might need to do
11295 -        * more here.
11296 -        */
11297 -       dmat->alignment = alignment;
11298 -       dmat->boundary = boundary;
11299 -       dmat->maxsize = maxsize;
11300 -       *ret_tag = dmat;
11301 -       return (0);
11302 -}
11303 -
11304 -void
11305 -ahc_dma_tag_destroy(struct ahc_softc *ahc, bus_dma_tag_t dmat)
11306 -{
11307 -       free(dmat, M_DEVBUF);
11308 -}
11309 -
11310 -int
11311 -ahc_dmamem_alloc(struct ahc_softc *ahc, bus_dma_tag_t dmat, void** vaddr,
11312 -                int flags, bus_dmamap_t *mapp)
11313 -{
11314 -       bus_dmamap_t map;
11315 -
11316 -#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,3,0)
11317 -       map = malloc(sizeof(*map), M_DEVBUF, M_NOWAIT);
11318 -       if (map == NULL)
11319 -               return (ENOMEM);
11320 -       /*
11321 -        * Although we can dma data above 4GB, our
11322 -        * "consistent" memory is below 4GB for
11323 -        * space efficiency reasons (only need a 4byte
11324 -        * address).  For this reason, we have to reset
11325 -        * our dma mask when doing allocations.
11326 -        */
11327 -       if (ahc->dev_softc != NULL)
11328 -               ahc_pci_set_dma_mask(ahc->dev_softc, 0xFFFFFFFF);
11329 -       *vaddr = pci_alloc_consistent(ahc->dev_softc,
11330 -                                     dmat->maxsize, &map->bus_addr);
11331 -       if (ahc->dev_softc != NULL)
11332 -               ahc_pci_set_dma_mask(ahc->dev_softc,
11333 -                                    ahc->platform_data->hw_dma_mask);
11334 -#else /* LINUX_VERSION_CODE < KERNEL_VERSION(2,3,0) */
11335 -       /*
11336 -        * At least in 2.2.14, malloc is a slab allocator so all
11337 -        * allocations are aligned.  We assume for these kernel versions
11338 -        * that all allocations will be bellow 4Gig, physically contiguous,
11339 -        * and accessible via DMA by the controller.
11340 -        */
11341 -       map = NULL; /* No additional information to store */
11342 -       *vaddr = malloc(dmat->maxsize, M_DEVBUF, M_NOWAIT);
11343 -#endif
11344 -       if (*vaddr == NULL)
11345 -               return (ENOMEM);
11346 -       *mapp = map;
11347 -       return(0);
11348 -}
11349 -
11350 -void
11351 -ahc_dmamem_free(struct ahc_softc *ahc, bus_dma_tag_t dmat,
11352 -               void* vaddr, bus_dmamap_t map)
11353 -{
11354 -#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,3,0)
11355 -       pci_free_consistent(ahc->dev_softc, dmat->maxsize,
11356 -                           vaddr, map->bus_addr);
11357 -#else
11358 -       free(vaddr, M_DEVBUF);
11359 -#endif
11360 -}
11361 -
11362 -int
11363 -ahc_dmamap_load(struct ahc_softc *ahc, bus_dma_tag_t dmat, bus_dmamap_t map,
11364 -               void *buf, bus_size_t buflen, bus_dmamap_callback_t *cb,
11365 -               void *cb_arg, int flags)
11366 -{
11367 -       /*
11368 -        * Assume for now that this will only be used during
11369 -        * initialization and not for per-transaction buffer mapping.
11370 -        */
11371 -       bus_dma_segment_t stack_sg;
11372 -
11373 -#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,3,0)
11374 -       stack_sg.ds_addr = map->bus_addr;
11375 -#else
11376 -#define VIRT_TO_BUS(a) (uint32_t)virt_to_bus((void *)(a))
11377 -       stack_sg.ds_addr = VIRT_TO_BUS(buf);
11378 -#endif
11379 -       stack_sg.ds_len = dmat->maxsize;
11380 -       cb(cb_arg, &stack_sg, /*nseg*/1, /*error*/0);
11381 -       return (0);
11382 -}
11383 -
11384 -void
11385 -ahc_dmamap_destroy(struct ahc_softc *ahc, bus_dma_tag_t dmat, bus_dmamap_t map)
11386 -{
11387 -       /*
11388 -        * The map may is NULL in our < 2.3.X implementation.
11389 -        */
11390 -       if (map != NULL)
11391 -               free(map, M_DEVBUF);
11392 -}
11393 -
11394 -int
11395 -ahc_dmamap_unload(struct ahc_softc *ahc, bus_dma_tag_t dmat, bus_dmamap_t map)
11396 -{
11397 -       /* Nothing to do */
11398 -       return (0);
11399 -}
11400 -
11401  /********************* Platform Dependent Functions ***************************/
11402  /*
11403   * Compare "left hand" softc with "right hand" softc, returning:
11404 @@ -1558,19 +1470,19 @@
11405                 char primary_channel;
11406  
11407                 if (aic7xxx_reverse_scan != 0)
11408 -                       value = ahc_get_pci_bus(lahc->dev_softc)
11409 -                             - ahc_get_pci_bus(rahc->dev_softc);
11410 +                       value = aic_get_pci_bus(lahc->dev_softc)
11411 +                             - aic_get_pci_bus(rahc->dev_softc);
11412                 else
11413 -                       value = ahc_get_pci_bus(rahc->dev_softc)
11414 -                             - ahc_get_pci_bus(lahc->dev_softc);
11415 +                       value = aic_get_pci_bus(rahc->dev_softc)
11416 +                             - aic_get_pci_bus(lahc->dev_softc);
11417                 if (value != 0)
11418                         break;
11419                 if (aic7xxx_reverse_scan != 0)
11420 -                       value = ahc_get_pci_slot(lahc->dev_softc)
11421 -                             - ahc_get_pci_slot(rahc->dev_softc);
11422 +                       value = aic_get_pci_slot(lahc->dev_softc)
11423 +                             - aic_get_pci_slot(rahc->dev_softc);
11424                 else
11425 -                       value = ahc_get_pci_slot(rahc->dev_softc)
11426 -                             - ahc_get_pci_slot(lahc->dev_softc);
11427 +                       value = aic_get_pci_slot(rahc->dev_softc)
11428 +                             - aic_get_pci_slot(lahc->dev_softc);
11429                 if (value != 0)
11430                         break;
11431                 /*
11432 @@ -1730,9 +1642,16 @@
11433         char    *new_name;
11434         u_long   s;
11435         u_int    targ_offset;
11436 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,0)
11437 +       int      error;
11438 +#endif
11439  
11440         template->name = ahc->description;
11441 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,0)
11442 +       host = scsi_host_alloc(template, sizeof(struct ahc_softc *));
11443 +#else
11444         host = scsi_register(template, sizeof(struct ahc_softc *));
11445 +#endif
11446         if (host == NULL)
11447                 return (ENOMEM);
11448  
11449 @@ -1741,8 +1660,12 @@
11450  #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,0)
11451         scsi_assign_lock(host, &ahc->platform_data->spin_lock);
11452  #elif AHC_SCSI_HAS_HOST_LOCK != 0
11453 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,21)
11454 +       host->host_lock = &ahc->platform_data->spin_lock;
11455 +#else
11456         host->lock = &ahc->platform_data->spin_lock;
11457  #endif
11458 +#endif
11459         ahc->platform_data->host = host;
11460         host->can_queue = AHC_MAX_QUEUE;
11461         host->cmd_per_lun = 2;
11462 @@ -1767,13 +1690,20 @@
11463  #endif
11464         ahc_linux_initialize_scsi_bus(ahc);
11465         ahc_unlock(ahc, &s);
11466 +       ahc_sysrq_key = aic_install_sysrq(&ahc_sysrq_op);
11467 +       ahc_spawn_recovery_thread(ahc);
11468 +       if (ahc->platform_data->recovery_pid < 0) {
11469 +               printf("%s: Failed to create recovery thread, error= %d\n",
11470 +                      ahc_name(ahc), ahc->platform_data->recovery_pid);
11471 +               return (-ahc->platform_data->recovery_pid);
11472 +       }
11473         ahc->platform_data->dv_pid = kernel_thread(ahc_linux_dv_thread, ahc, 0);
11474 -       ahc_lock(ahc, &s);
11475         if (ahc->platform_data->dv_pid < 0) {
11476                 printf("%s: Failed to create DV thread, error= %d\n",
11477                        ahc_name(ahc), ahc->platform_data->dv_pid);
11478                 return (-ahc->platform_data->dv_pid);
11479         }
11480 +       ahc_lock(ahc, &s);
11481         /*
11482          * Initially allocate *all* of our linux target objects
11483          * so that the DV thread will scan them all in parallel
11484 @@ -1818,7 +1748,10 @@
11485         ahc_unlock(ahc, &s);
11486  
11487  #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,0)
11488 -       scsi_add_host(host, (ahc->dev_softc ? &ahc->dev_softc->dev : NULL));
11489 +       error = scsi_add_host(host, ahc->dev_softc);
11490 +       if (error != 0)
11491 +               return (-error);
11492 +       scsi_scan_host(host);
11493  #endif
11494         return (0);
11495  }
11496 @@ -1915,17 +1848,6 @@
11497                 ahc_update_neg_request(ahc, &devinfo, tstate,
11498                                        tinfo, AHC_NEG_ALWAYS);
11499         }
11500 -       /* Give the bus some time to recover */
11501 -       if ((ahc->flags & (AHC_RESET_BUS_A|AHC_RESET_BUS_B)) != 0) {
11502 -               ahc_linux_freeze_simq(ahc);
11503 -               init_timer(&ahc->platform_data->reset_timer);
11504 -               ahc->platform_data->reset_timer.data = (u_long)ahc;
11505 -               ahc->platform_data->reset_timer.expires =
11506 -                   jiffies + (AIC7XXX_RESET_DELAY * HZ)/1000;
11507 -               ahc->platform_data->reset_timer.function =
11508 -                   ahc_linux_release_simq;
11509 -               add_timer(&ahc->platform_data->reset_timer);
11510 -       }
11511  }
11512  
11513  int
11514 @@ -1939,27 +1861,32 @@
11515         memset(ahc->platform_data, 0, sizeof(struct ahc_platform_data));
11516         TAILQ_INIT(&ahc->platform_data->completeq);
11517         TAILQ_INIT(&ahc->platform_data->device_runq);
11518 -       ahc->platform_data->irq = AHC_LINUX_NOIRQ;
11519 +       ahc->platform_data->irq = AIC_LINUX_NOIRQ;
11520         ahc->platform_data->hw_dma_mask = 0xFFFFFFFF;
11521         ahc_lockinit(ahc);
11522         ahc_done_lockinit(ahc);
11523 +       init_timer(&ahc->platform_data->bus_settle_timer);
11524 +       ahc->platform_data->bus_settle_timer.data = (u_long)ahc;
11525 +       ahc->platform_data->bus_settle_timer.function =
11526 +           (aic_linux_callback_t *)aic_bus_settle_complete;
11527         init_timer(&ahc->platform_data->completeq_timer);
11528         ahc->platform_data->completeq_timer.data = (u_long)ahc;
11529         ahc->platform_data->completeq_timer.function =
11530 -           (ahc_linux_callback_t *)ahc_linux_thread_run_complete_queue;
11531 +           (aic_linux_callback_t *)ahc_linux_thread_run_complete_queue;
11532  #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,3,0)
11533         init_MUTEX_LOCKED(&ahc->platform_data->eh_sem);
11534         init_MUTEX_LOCKED(&ahc->platform_data->dv_sem);
11535         init_MUTEX_LOCKED(&ahc->platform_data->dv_cmd_sem);
11536 +       init_MUTEX_LOCKED(&ahc->platform_data->recovery_sem);
11537 +       init_MUTEX_LOCKED(&ahc->platform_data->recovery_ending_sem);
11538  #else
11539         ahc->platform_data->eh_sem = MUTEX_LOCKED;
11540         ahc->platform_data->dv_sem = MUTEX_LOCKED;
11541         ahc->platform_data->dv_cmd_sem = MUTEX_LOCKED;
11542 +       ahc->platform_data->recovery_sem = MUTEX_LOCKED;
11543 +       ahc->platform_data->recovery_ending_sem = MUTEX_LOCKED;
11544  #endif
11545 -#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,0)
11546 -       tasklet_init(&ahc->platform_data->runq_tasklet, ahc_runq_tasklet,
11547 -                    (unsigned long)ahc);
11548 -#endif
11549 +       aic_setup_tasklets(ahc);
11550         ahc->seltime = (aic7xxx_seltime & 0x3) << 4;
11551         ahc->seltime_b = (aic7xxx_seltime & 0x3) << 4;
11552         if (aic7xxx_pci_parity == 0)
11553 @@ -1971,21 +1898,22 @@
11554  void
11555  ahc_platform_free(struct ahc_softc *ahc)
11556  {
11557 -       struct ahc_linux_target *targ;
11558 -       struct ahc_linux_device *dev;
11559 +       struct aic_linux_target *targ;
11560 +       struct aic_linux_device *dev;
11561         int i, j;
11562  
11563 +       aic_remove_sysrq(ahc_sysrq_key, &ahc_sysrq_op);
11564         if (ahc->platform_data != NULL) {
11565                 del_timer_sync(&ahc->platform_data->completeq_timer);
11566                 ahc_linux_kill_dv_thread(ahc);
11567 -#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,0)
11568 -               tasklet_kill(&ahc->platform_data->runq_tasklet);
11569 -#endif
11570 +               aic_teardown_tasklets(ahc);
11571                 if (ahc->platform_data->host != NULL) {
11572  #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,0)
11573                         scsi_remove_host(ahc->platform_data->host);
11574 -#endif
11575 +                       scsi_host_put(ahc->platform_data->host);
11576 +#else
11577                         scsi_unregister(ahc->platform_data->host);
11578 +#endif
11579                 }
11580  
11581                 /* destroy all of the device and target objects */
11582 @@ -1999,6 +1927,7 @@
11583                                         if (targ->devices[j] == NULL)
11584                                                 continue;
11585                                         dev = targ->devices[j];
11586 +                                       del_timer_sync(&dev->timer);
11587                                         ahc_linux_free_device(ahc, dev);
11588                                 }
11589                                 /*
11590 @@ -2009,7 +1938,7 @@
11591                         }
11592                 }
11593  
11594 -               if (ahc->platform_data->irq != AHC_LINUX_NOIRQ)
11595 +               if (ahc->platform_data->irq != AIC_LINUX_NOIRQ)
11596                         free_irq(ahc->platform_data->irq, ahc);
11597                 if (ahc->tag == BUS_SPACE_PIO
11598                  && ahc->bsh.ioport != 0)
11599 @@ -2054,7 +1983,7 @@
11600  ahc_platform_set_tags(struct ahc_softc *ahc, struct ahc_devinfo *devinfo,
11601                       ahc_queue_alg alg)
11602  {
11603 -       struct ahc_linux_device *dev;
11604 +       struct aic_linux_device *dev;
11605         int was_queuing;
11606         int now_queuing;
11607  
11608 @@ -2063,27 +1992,27 @@
11609                                    devinfo->lun, /*alloc*/FALSE);
11610         if (dev == NULL)
11611                 return;
11612 -       was_queuing = dev->flags & (AHC_DEV_Q_BASIC|AHC_DEV_Q_TAGGED);
11613 +       was_queuing = dev->flags & (AIC_DEV_Q_BASIC|AIC_DEV_Q_TAGGED);
11614         switch (alg) {
11615         default:
11616         case AHC_QUEUE_NONE:
11617                 now_queuing = 0;
11618                 break; 
11619         case AHC_QUEUE_BASIC:
11620 -               now_queuing = AHC_DEV_Q_BASIC;
11621 +               now_queuing = AIC_DEV_Q_BASIC;
11622                 break;
11623         case AHC_QUEUE_TAGGED:
11624 -               now_queuing = AHC_DEV_Q_TAGGED;
11625 +               now_queuing = AIC_DEV_Q_TAGGED;
11626                 break;
11627         }
11628 -       if ((dev->flags & AHC_DEV_FREEZE_TIL_EMPTY) == 0
11629 +       if ((dev->flags & AIC_DEV_FREEZE_TIL_EMPTY) == 0
11630          && (was_queuing != now_queuing)
11631          && (dev->active != 0)) {
11632 -               dev->flags |= AHC_DEV_FREEZE_TIL_EMPTY;
11633 +               dev->flags |= AIC_DEV_FREEZE_TIL_EMPTY;
11634                 dev->qfrozen++;
11635         }
11636  
11637 -       dev->flags &= ~(AHC_DEV_Q_BASIC|AHC_DEV_Q_TAGGED|AHC_DEV_PERIODIC_OTAG);
11638 +       dev->flags &= ~(AIC_DEV_Q_BASIC|AIC_DEV_Q_TAGGED|AIC_DEV_PERIODIC_OTAG);
11639         if (now_queuing) {
11640                 u_int usertags;
11641  
11642 @@ -2103,11 +2032,11 @@
11643                          */
11644                         dev->openings = 1;
11645                 } else if (alg == AHC_QUEUE_TAGGED) {
11646 -                       dev->flags |= AHC_DEV_Q_TAGGED;
11647 +                       dev->flags |= AIC_DEV_Q_TAGGED;
11648                         if (aic7xxx_periodic_otag != 0)
11649 -                               dev->flags |= AHC_DEV_PERIODIC_OTAG;
11650 +                               dev->flags |= AIC_DEV_PERIODIC_OTAG;
11651                 } else
11652 -                       dev->flags |= AHC_DEV_Q_BASIC;
11653 +                       dev->flags |= AIC_DEV_Q_BASIC;
11654         } else {
11655                 /* We can only have one opening. */
11656                 dev->maxtags = 0;
11657 @@ -2115,13 +2044,13 @@
11658         }
11659  #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,0)
11660         if (dev->scsi_device != NULL) {
11661 -               switch ((dev->flags & (AHC_DEV_Q_BASIC|AHC_DEV_Q_TAGGED))) {
11662 -               case AHC_DEV_Q_BASIC:
11663 +               switch ((dev->flags & (AIC_DEV_Q_BASIC|AIC_DEV_Q_TAGGED))) {
11664 +               case AIC_DEV_Q_BASIC:
11665                         scsi_adjust_queue_depth(dev->scsi_device,
11666                                                 MSG_SIMPLE_TASK,
11667                                                 dev->openings + dev->active);
11668                         break;
11669 -               case AHC_DEV_Q_TAGGED:
11670 +               case AIC_DEV_Q_TAGGED:
11671                         scsi_adjust_queue_depth(dev->scsi_device,
11672                                                 MSG_ORDERED_TASK,
11673                                                 dev->openings + dev->active);
11674 @@ -2185,9 +2114,9 @@
11675                 for (; targ < maxtarg; targ++) {
11676  
11677                         for (; clun < maxlun; clun++) {
11678 -                               struct ahc_linux_device *dev;
11679 -                               struct ahc_busyq *busyq;
11680 -                               struct ahc_cmd *acmd;
11681 +                               struct aic_linux_device *dev;
11682 +                               struct aic_busyq *busyq;
11683 +                               struct aic_cmd *acmd;
11684  
11685                                 dev = ahc_linux_get_device(ahc, chan,
11686                                                            targ, clun,
11687 @@ -2204,6 +2133,20 @@
11688                                                      acmd_links.tqe);
11689                                         count++;
11690                                         cmd->result = status << 16;
11691 +                                       /*
11692 +                                        * The completion handler believes that
11693 +                                        * commands without active timers
11694 +                                        * running have lost the race of
11695 +                                        * completing before their timer
11696 +                                        * expires.  Since commands in our
11697 +                                        * busy queues do not have timers
11698 +                                        * running, appease the mid-layer by
11699 +                                        * adding a timer now.  This timer will
11700 +                                        * be immediately canceled by the
11701 +                                        * midlayer.
11702 +                                        */
11703 +                                       scsi_add_timer(cmd, 60*HZ,
11704 +                                           aic_linux_midlayer_timeout);
11705                                         ahc_linux_queue_cmd_complete(ahc, cmd);
11706                                 }
11707                         }
11708 @@ -2220,7 +2163,7 @@
11709  
11710         ahc_lock(ahc, &flags);
11711         del_timer(&ahc->platform_data->completeq_timer);
11712 -       ahc->platform_data->flags &= ~AHC_RUN_CMPLT_Q_TIMER;
11713 +       ahc->platform_data->flags &= ~AIC_RUN_CMPLT_Q_TIMER;
11714         ahc_linux_run_complete_queue(ahc);
11715         ahc_unlock(ahc, &flags);
11716  }
11717 @@ -2233,14 +2176,23 @@
11718          * Freeze the simq and signal ahc_linux_queue to not let any
11719          * more commands through.
11720          */
11721 -       if ((ahc->platform_data->flags & AHC_DV_ACTIVE) == 0) {
11722 +       if ((ahc->platform_data->flags & AIC_DV_ACTIVE) == 0) {
11723  #ifdef AHC_DEBUG
11724                 if (ahc_debug & AHC_SHOW_DV)
11725                         printf("%s: Waking DV thread\n", ahc_name(ahc));
11726  #endif
11727  
11728 -               ahc->platform_data->flags |= AHC_DV_ACTIVE;
11729 -               ahc_linux_freeze_simq(ahc);
11730 +               ahc->platform_data->flags |= AIC_DV_ACTIVE;
11731 +
11732 +               /*
11733 +                * Prevent upper layer from sending any
11734 +                * commands to us.
11735 +                */
11736 +               aic_freeze_simq(ahc);
11737 +               scsi_block_requests(ahc->platform_data->host);
11738 +               ahc_platform_abort_scbs(ahc, CAM_TARGET_WILDCARD, ALL_CHANNELS,
11739 +                                       CAM_LUN_WILDCARD, SCB_LIST_NULL,
11740 +                                       ROLE_INITIATOR, CAM_REQUEUE_REQ);
11741  
11742                 /* Wake up the DV kthread */
11743                 up(&ahc->platform_data->dv_sem);
11744 @@ -2254,7 +2206,7 @@
11745  
11746         ahc_lock(ahc, &s);
11747         if (ahc->platform_data->dv_pid != 0) {
11748 -               ahc->platform_data->flags |= AHC_DV_SHUTDOWN;
11749 +               ahc->platform_data->flags |= AIC_DV_SHUTDOWN;
11750                 ahc_unlock(ahc, &s);
11751                 up(&ahc->platform_data->dv_sem);
11752  
11753 @@ -2329,7 +2281,7 @@
11754  
11755                 /* Check to see if we've been signaled to exit */
11756                 ahc_lock(ahc, &s);
11757 -               if ((ahc->platform_data->flags & AHC_DV_SHUTDOWN) != 0) {
11758 +               if ((ahc->platform_data->flags & AIC_DV_SHUTDOWN) != 0) {
11759                         ahc_unlock(ahc, &s);
11760                         break;
11761                 }
11762 @@ -2346,7 +2298,7 @@
11763                  */
11764                 ahc_lock(ahc, &s);
11765                 while (LIST_FIRST(&ahc->pending_scbs) != NULL) {
11766 -                       ahc->platform_data->flags |= AHC_DV_WAIT_SIMQ_EMPTY;
11767 +                       ahc->platform_data->flags |= AIC_DV_WAIT_SIMQ_EMPTY;
11768                         ahc_unlock(ahc, &s);
11769                         down_interruptible(&ahc->platform_data->dv_sem);
11770                         ahc_lock(ahc, &s);
11771 @@ -2356,8 +2308,8 @@
11772                  * Wait for the SIMQ to be released so that DV is the
11773                  * only reason the queue is frozen.
11774                  */
11775 -               while (AHC_DV_SIMQ_FROZEN(ahc) == 0) {
11776 -                       ahc->platform_data->flags |= AHC_DV_WAIT_SIMQ_RELEASE;
11777 +               while (AIC_DV_SIMQ_FROZEN(ahc) == 0) {
11778 +                       ahc->platform_data->flags |= AIC_DV_WAIT_SIMQ_RELEASE;
11779                         ahc_unlock(ahc, &s);
11780                         down_interruptible(&ahc->platform_data->dv_sem);
11781                         ahc_lock(ahc, &s);
11782 @@ -2368,14 +2320,16 @@
11783                         ahc_linux_dv_target(ahc, target);
11784  
11785                 ahc_lock(ahc, &s);
11786 -               ahc->platform_data->flags &= ~AHC_DV_ACTIVE;
11787 -               ahc_unlock(ahc, &s);
11788 +               ahc->platform_data->flags &= ~AIC_DV_ACTIVE;
11789  
11790                 /*
11791                  * Release the SIMQ so that normal commands are
11792                  * allowed to continue on the bus.
11793                  */
11794 -               ahc_linux_release_simq((u_long)ahc);
11795 +               aic_release_simq_locked(ahc);
11796 +               ahc_unlock(ahc, &s);
11797 +
11798 +               scsi_unblock_requests(ahc->platform_data->host);
11799         }
11800         up(&ahc->platform_data->eh_sem);
11801         return (0);
11802 @@ -2389,10 +2343,10 @@
11803         ahc_set_dv_state(ahc, targ, newstate, __LINE__)
11804  
11805  static __inline void
11806 -ahc_set_dv_state(struct ahc_softc *ahc, struct ahc_linux_target *targ,
11807 -                ahc_dv_state newstate, u_int line)
11808 +ahc_set_dv_state(struct ahc_softc *ahc, struct aic_linux_target *targ,
11809 +                aic_dv_state newstate, u_int line)
11810  {
11811 -       ahc_dv_state oldstate;
11812 +       aic_dv_state oldstate;
11813  
11814         oldstate = targ->dv_state;
11815  #ifdef AHC_DEBUG
11816 @@ -2412,7 +2366,7 @@
11817  ahc_linux_dv_target(struct ahc_softc *ahc, u_int target_offset)
11818  {
11819         struct   ahc_devinfo devinfo;
11820 -       struct   ahc_linux_target *targ;
11821 +       struct   aic_linux_target *targ;
11822         struct   scsi_cmnd *cmd;
11823         struct   scsi_device *scsi_dev;
11824         struct   scsi_sense_data *sense;
11825 @@ -2426,7 +2380,7 @@
11826         echo_size = 0;
11827         ahc_lock(ahc, &s);
11828         targ = ahc->platform_data->targets[target_offset];
11829 -       if (targ == NULL || (targ->flags & AHC_DV_REQUIRED) == 0) {
11830 +       if (targ == NULL || (targ->flags & AIC_DV_REQUIRED) == 0) {
11831                 ahc_unlock(ahc, &s);
11832                 return;
11833         }
11834 @@ -2451,14 +2405,14 @@
11835         scsi_dev->channel = devinfo.channel - 'A';
11836         ahc->platform_data->dv_scsi_dev = scsi_dev;
11837  
11838 -       AHC_SET_DV_STATE(ahc, targ, AHC_DV_STATE_INQ_SHORT_ASYNC);
11839 +       AHC_SET_DV_STATE(ahc, targ, AIC_DV_STATE_INQ_SHORT_ASYNC);
11840  
11841 -       while (targ->dv_state != AHC_DV_STATE_EXIT) {
11842 +       while (targ->dv_state != AIC_DV_STATE_EXIT) {
11843                 timeout = AHC_LINUX_DV_TIMEOUT;
11844                 switch (targ->dv_state) {
11845 -               case AHC_DV_STATE_INQ_SHORT_ASYNC:
11846 -               case AHC_DV_STATE_INQ_ASYNC:
11847 -               case AHC_DV_STATE_INQ_ASYNC_VERIFY:
11848 +               case AIC_DV_STATE_INQ_SHORT_ASYNC:
11849 +               case AIC_DV_STATE_INQ_ASYNC:
11850 +               case AIC_DV_STATE_INQ_ASYNC_VERIFY:
11851                         /*
11852                          * Set things to async narrow to reduce the
11853                          * chance that the INQ will fail.
11854 @@ -2470,36 +2424,36 @@
11855                                       AHC_TRANS_GOAL, /*paused*/FALSE);
11856                         ahc_unlock(ahc, &s);
11857                         timeout = 10 * HZ;
11858 -                       targ->flags &= ~AHC_INQ_VALID;
11859 +                       targ->flags &= ~AIC_INQ_VALID;
11860                         /* FALLTHROUGH */
11861 -               case AHC_DV_STATE_INQ_VERIFY:
11862 +               case AIC_DV_STATE_INQ_VERIFY:
11863                 {
11864                         u_int inq_len;
11865  
11866 -                       if (targ->dv_state == AHC_DV_STATE_INQ_SHORT_ASYNC)
11867 +                       if (targ->dv_state == AIC_DV_STATE_INQ_SHORT_ASYNC)
11868                                 inq_len = AHC_LINUX_DV_INQ_SHORT_LEN;
11869                         else
11870                                 inq_len = targ->inq_data->additional_length + 5;
11871                         ahc_linux_dv_inq(ahc, cmd, &devinfo, targ, inq_len);
11872                         break;
11873                 }
11874 -               case AHC_DV_STATE_TUR:
11875 -               case AHC_DV_STATE_BUSY:
11876 +               case AIC_DV_STATE_TUR:
11877 +               case AIC_DV_STATE_BUSY:
11878                         timeout = 5 * HZ;
11879                         ahc_linux_dv_tur(ahc, cmd, &devinfo);
11880                         break;
11881 -               case AHC_DV_STATE_REBD:
11882 +               case AIC_DV_STATE_REBD:
11883                         ahc_linux_dv_rebd(ahc, cmd, &devinfo, targ);
11884                         break;
11885 -               case AHC_DV_STATE_WEB:
11886 +               case AIC_DV_STATE_WEB:
11887                         ahc_linux_dv_web(ahc, cmd, &devinfo, targ);
11888                         break;
11889  
11890 -               case AHC_DV_STATE_REB:
11891 +               case AIC_DV_STATE_REB:
11892                         ahc_linux_dv_reb(ahc, cmd, &devinfo, targ);
11893                         break;
11894  
11895 -               case AHC_DV_STATE_SU:
11896 +               case AIC_DV_STATE_SU:
11897                         ahc_linux_dv_su(ahc, cmd, &devinfo, targ);
11898                         timeout = 50 * HZ;
11899                         break;
11900 @@ -2511,8 +2465,6 @@
11901                 }
11902  
11903                 /* Queue the command and wait for it to complete */
11904 -               /* Abuse eh_timeout in the scsi_cmnd struct for our purposes */
11905 -               init_timer(&cmd->eh_timeout);
11906  #ifdef AHC_DEBUG
11907                 if ((ahc_debug & AHC_SHOW_MESSAGES) != 0)
11908                         /*
11909 @@ -2522,7 +2474,9 @@
11910                          */
11911                         timeout += HZ;
11912  #endif
11913 -               scsi_add_timer(cmd, timeout, ahc_linux_dv_timeout);
11914 +               init_timer(&cmd->eh_timeout);
11915 +               cmd->timeout_per_command = timeout;
11916 +
11917                 /*
11918                  * In 2.5.X, it is assumed that all calls from the
11919                  * "midlayer" (which we are emulating) will have the
11920 @@ -2546,8 +2500,8 @@
11921                  * only reason the queue is frozen.
11922                  */
11923                 ahc_lock(ahc, &s);
11924 -               while (AHC_DV_SIMQ_FROZEN(ahc) == 0) {
11925 -                       ahc->platform_data->flags |= AHC_DV_WAIT_SIMQ_RELEASE;
11926 +               while (AIC_DV_SIMQ_FROZEN(ahc) == 0) {
11927 +                       ahc->platform_data->flags |= AIC_DV_WAIT_SIMQ_RELEASE;
11928                         ahc_unlock(ahc, &s);
11929                         down_interruptible(&ahc->platform_data->dv_sem);
11930                         ahc_lock(ahc, &s);
11931 @@ -2558,7 +2512,7 @@
11932         }
11933  
11934  out:
11935 -       if ((targ->flags & AHC_INQ_VALID) != 0
11936 +       if ((targ->flags & AIC_INQ_VALID) != 0
11937          && ahc_linux_get_device(ahc, devinfo.channel - 'A',
11938                                  devinfo.target, devinfo.lun,
11939                                  /*alloc*/FALSE) == NULL) {
11940 @@ -2569,7 +2523,7 @@
11941                  * parameters found in the inquiry string.
11942                  */
11943                 ahc_linux_filter_inquiry(ahc, &devinfo);
11944 -               if ((targ->flags & (AHC_BASIC_DV|AHC_ENHANCED_DV)) != 0) {
11945 +               if ((targ->flags & (AIC_BASIC_DV|AIC_ENHANCED_DV)) != 0) {
11946                         ahc_print_devinfo(ahc, &devinfo);
11947                         printf("DV failed to configure device.  "
11948                                "Please file a bug report against "
11949 @@ -2594,7 +2548,7 @@
11950                 free(targ->dv_buffer1, M_DEVBUF);
11951                 targ->dv_buffer1 = NULL;
11952         }
11953 -       targ->flags &= ~AHC_DV_REQUIRED;
11954 +       targ->flags &= ~AIC_DV_REQUIRED;
11955         if (targ->refcount == 0)
11956                 ahc_linux_free_target(ahc, targ);
11957         ahc_unlock(ahc, &s);
11958 @@ -2603,13 +2557,13 @@
11959  static void
11960  ahc_linux_dv_transition(struct ahc_softc *ahc, struct scsi_cmnd *cmd,
11961                         struct ahc_devinfo *devinfo,
11962 -                       struct ahc_linux_target *targ)
11963 +                       struct aic_linux_target *targ)
11964  {
11965         u_int32_t status;
11966  
11967         status = aic_error_action(cmd, targ->inq_data,
11968 -                                 ahc_cmd_get_transaction_status(cmd),
11969 -                                 ahc_cmd_get_scsi_status(cmd));
11970 +                                 aic_cmd_get_transaction_status(cmd),
11971 +                                 aic_cmd_get_scsi_status(cmd));
11972         
11973  #ifdef AHC_DEBUG
11974         if (ahc_debug & AHC_SHOW_DV) {
11975 @@ -2621,8 +2575,8 @@
11976  #endif
11977  
11978         switch (targ->dv_state) {
11979 -       case AHC_DV_STATE_INQ_SHORT_ASYNC:
11980 -       case AHC_DV_STATE_INQ_ASYNC:
11981 +       case AIC_DV_STATE_INQ_SHORT_ASYNC:
11982 +       case AIC_DV_STATE_INQ_ASYNC:
11983                 switch (status & SS_MASK) {
11984                 case SS_NOP:
11985                 {
11986 @@ -2631,21 +2585,21 @@
11987                 }
11988                 case SS_INQ_REFRESH:
11989                         AHC_SET_DV_STATE(ahc, targ,
11990 -                                        AHC_DV_STATE_INQ_SHORT_ASYNC);
11991 +                                        AIC_DV_STATE_INQ_SHORT_ASYNC);
11992                         break;
11993                 case SS_TUR:
11994                 case SS_RETRY:
11995                         AHC_SET_DV_STATE(ahc, targ, targ->dv_state);
11996 -                       if (ahc_cmd_get_transaction_status(cmd)
11997 +                       if (aic_cmd_get_transaction_status(cmd)
11998                          == CAM_REQUEUE_REQ)
11999                                 targ->dv_state_retry--;
12000                         if ((status & SS_ERRMASK) == EBUSY)
12001 -                               AHC_SET_DV_STATE(ahc, targ, AHC_DV_STATE_BUSY);
12002 +                               AHC_SET_DV_STATE(ahc, targ, AIC_DV_STATE_BUSY);
12003                         if (targ->dv_state_retry < 10)
12004                                 break;
12005                         /* FALLTHROUGH */
12006                 default:
12007 -                       AHC_SET_DV_STATE(ahc, targ, AHC_DV_STATE_EXIT);
12008 +                       AHC_SET_DV_STATE(ahc, targ, AIC_DV_STATE_EXIT);
12009  #ifdef AHC_DEBUG
12010                         if (ahc_debug & AHC_SHOW_DV) {
12011                                 ahc_print_devinfo(ahc, devinfo);
12012 @@ -2655,7 +2609,7 @@
12013                         break;
12014                 }
12015                 break;
12016 -       case AHC_DV_STATE_INQ_ASYNC_VERIFY:
12017 +       case AIC_DV_STATE_INQ_ASYNC_VERIFY:
12018                 switch (status & SS_MASK) {
12019                 case SS_NOP:
12020                 {
12021 @@ -2669,12 +2623,12 @@
12022                                  * Try from the top again.
12023                                  */
12024                                 AHC_SET_DV_STATE(ahc, targ,
12025 -                                                AHC_DV_STATE_INQ_SHORT_ASYNC);
12026 +                                                AIC_DV_STATE_INQ_SHORT_ASYNC);
12027                                 break;
12028                         }
12029  
12030                         AHC_SET_DV_STATE(ahc, targ, targ->dv_state+1);
12031 -                       targ->flags |= AHC_INQ_VALID;
12032 +                       targ->flags |= AIC_INQ_VALID;
12033                         if (ahc_linux_user_dv_setting(ahc) == 0)
12034                                 break;
12035  
12036 @@ -2687,33 +2641,33 @@
12037                         default:
12038                         case SID_SPI_CLOCK_ST:
12039                                 /* Assume only basic DV is supported. */
12040 -                               targ->flags |= AHC_BASIC_DV;
12041 +                               targ->flags |= AIC_BASIC_DV;
12042                                 break;
12043                         case SID_SPI_CLOCK_DT:
12044                         case SID_SPI_CLOCK_DT_ST:
12045 -                               targ->flags |= AHC_ENHANCED_DV;
12046 +                               targ->flags |= AIC_ENHANCED_DV;
12047                                 break;
12048                         }
12049                         break;
12050                 }
12051                 case SS_INQ_REFRESH:
12052                         AHC_SET_DV_STATE(ahc, targ,
12053 -                                        AHC_DV_STATE_INQ_SHORT_ASYNC);
12054 +                                        AIC_DV_STATE_INQ_SHORT_ASYNC);
12055                         break;
12056                 case SS_TUR:
12057                 case SS_RETRY:
12058                         AHC_SET_DV_STATE(ahc, targ, targ->dv_state);
12059 -                       if (ahc_cmd_get_transaction_status(cmd)
12060 +                       if (aic_cmd_get_transaction_status(cmd)
12061                          == CAM_REQUEUE_REQ)
12062                                 targ->dv_state_retry--;
12063  
12064                         if ((status & SS_ERRMASK) == EBUSY)
12065 -                               AHC_SET_DV_STATE(ahc, targ, AHC_DV_STATE_BUSY);
12066 +                               AHC_SET_DV_STATE(ahc, targ, AIC_DV_STATE_BUSY);
12067                         if (targ->dv_state_retry < 10)
12068                                 break;
12069                         /* FALLTHROUGH */
12070                 default:
12071 -                       AHC_SET_DV_STATE(ahc, targ, AHC_DV_STATE_EXIT);
12072 +                       AHC_SET_DV_STATE(ahc, targ, AIC_DV_STATE_EXIT);
12073  #ifdef AHC_DEBUG
12074                         if (ahc_debug & AHC_SHOW_DV) {
12075                                 ahc_print_devinfo(ahc, devinfo);
12076 @@ -2723,14 +2677,14 @@
12077                         break;
12078                 }
12079                 break;
12080 -       case AHC_DV_STATE_INQ_VERIFY:
12081 +       case AIC_DV_STATE_INQ_VERIFY:
12082                 switch (status & SS_MASK) {
12083                 case SS_NOP:
12084                 {
12085  
12086                         if (memcmp(targ->inq_data, targ->dv_buffer,
12087                                    AHC_LINUX_DV_INQ_LEN) == 0) {
12088 -                               AHC_SET_DV_STATE(ahc, targ, AHC_DV_STATE_EXIT);
12089 +                               AHC_SET_DV_STATE(ahc, targ, AIC_DV_STATE_EXIT);
12090                                 break;
12091                         }
12092  #ifdef AHC_DEBUG
12093 @@ -2751,7 +2705,7 @@
12094  #endif
12095  
12096                         if (ahc_linux_fallback(ahc, devinfo) != 0) {
12097 -                               AHC_SET_DV_STATE(ahc, targ, AHC_DV_STATE_EXIT);
12098 +                               AHC_SET_DV_STATE(ahc, targ, AIC_DV_STATE_EXIT);
12099                                 break;
12100                         }
12101                         /*
12102 @@ -2764,18 +2718,18 @@
12103                 }
12104                 case SS_INQ_REFRESH:
12105                         AHC_SET_DV_STATE(ahc, targ,
12106 -                                        AHC_DV_STATE_INQ_SHORT_ASYNC);
12107 +                                        AIC_DV_STATE_INQ_SHORT_ASYNC);
12108                         break;
12109                 case SS_TUR:
12110                 case SS_RETRY:
12111                         AHC_SET_DV_STATE(ahc, targ, targ->dv_state);
12112 -                       if (ahc_cmd_get_transaction_status(cmd)
12113 +                       if (aic_cmd_get_transaction_status(cmd)
12114                          == CAM_REQUEUE_REQ) {
12115                                 targ->dv_state_retry--;
12116                         } else if ((status & SSQ_FALLBACK) != 0) {
12117                                 if (ahc_linux_fallback(ahc, devinfo) != 0) {
12118                                         AHC_SET_DV_STATE(ahc, targ,
12119 -                                                        AHC_DV_STATE_EXIT);
12120 +                                                        AIC_DV_STATE_EXIT);
12121                                         break;
12122                                 }
12123                                 /*
12124 @@ -2784,12 +2738,12 @@
12125                                  */
12126                                 targ->dv_state_retry = 0;
12127                         } else if ((status & SS_ERRMASK) == EBUSY)
12128 -                               AHC_SET_DV_STATE(ahc, targ, AHC_DV_STATE_BUSY);
12129 +                               AHC_SET_DV_STATE(ahc, targ, AIC_DV_STATE_BUSY);
12130                         if (targ->dv_state_retry < 10)
12131                                 break;
12132                         /* FALLTHROUGH */
12133                 default:
12134 -                       AHC_SET_DV_STATE(ahc, targ, AHC_DV_STATE_EXIT);
12135 +                       AHC_SET_DV_STATE(ahc, targ, AIC_DV_STATE_EXIT);
12136  #ifdef AHC_DEBUG
12137                         if (ahc_debug & AHC_SHOW_DV) {
12138                                 ahc_print_devinfo(ahc, devinfo);
12139 @@ -2800,33 +2754,33 @@
12140                 }
12141                 break;
12142  
12143 -       case AHC_DV_STATE_TUR:
12144 +       case AIC_DV_STATE_TUR:
12145                 switch (status & SS_MASK) {
12146                 case SS_NOP:
12147 -                       if ((targ->flags & AHC_BASIC_DV) != 0) {
12148 +                       if ((targ->flags & AIC_BASIC_DV) != 0) {
12149                                 ahc_linux_filter_inquiry(ahc, devinfo);
12150                                 AHC_SET_DV_STATE(ahc, targ,
12151 -                                                AHC_DV_STATE_INQ_VERIFY);
12152 -                       } else if ((targ->flags & AHC_ENHANCED_DV) != 0) {
12153 -                               AHC_SET_DV_STATE(ahc, targ, AHC_DV_STATE_REBD);
12154 +                                                AIC_DV_STATE_INQ_VERIFY);
12155 +                       } else if ((targ->flags & AIC_ENHANCED_DV) != 0) {
12156 +                               AHC_SET_DV_STATE(ahc, targ, AIC_DV_STATE_REBD);
12157                         } else {
12158 -                               AHC_SET_DV_STATE(ahc, targ, AHC_DV_STATE_EXIT);
12159 +                               AHC_SET_DV_STATE(ahc, targ, AIC_DV_STATE_EXIT);
12160                         }
12161                         break;
12162                 case SS_RETRY:
12163                 case SS_TUR:
12164                         if ((status & SS_ERRMASK) == EBUSY) {
12165 -                               AHC_SET_DV_STATE(ahc, targ, AHC_DV_STATE_BUSY);
12166 +                               AHC_SET_DV_STATE(ahc, targ, AIC_DV_STATE_BUSY);
12167                                 break;
12168                         }
12169                         AHC_SET_DV_STATE(ahc, targ, targ->dv_state);
12170 -                       if (ahc_cmd_get_transaction_status(cmd)
12171 +                       if (aic_cmd_get_transaction_status(cmd)
12172                          == CAM_REQUEUE_REQ) {
12173                                 targ->dv_state_retry--;
12174                         } else if ((status & SSQ_FALLBACK) != 0) {
12175                                 if (ahc_linux_fallback(ahc, devinfo) != 0) {
12176                                         AHC_SET_DV_STATE(ahc, targ,
12177 -                                                        AHC_DV_STATE_EXIT);
12178 +                                                        AIC_DV_STATE_EXIT);
12179                                         break;
12180                                 }
12181                                 /*
12182 @@ -2842,7 +2796,7 @@
12183                                         printf("DV TUR reties exhausted\n");
12184                                 }
12185  #endif
12186 -                               AHC_SET_DV_STATE(ahc, targ, AHC_DV_STATE_EXIT);
12187 +                               AHC_SET_DV_STATE(ahc, targ, AIC_DV_STATE_EXIT);
12188                                 break;
12189                         }
12190                         if (status & SSQ_DELAY)
12191 @@ -2850,25 +2804,25 @@
12192  
12193                         break;
12194                 case SS_START:
12195 -                       AHC_SET_DV_STATE(ahc, targ, AHC_DV_STATE_SU);
12196 +                       AHC_SET_DV_STATE(ahc, targ, AIC_DV_STATE_SU);
12197                         break;
12198                 case SS_INQ_REFRESH:
12199                         AHC_SET_DV_STATE(ahc, targ,
12200 -                                        AHC_DV_STATE_INQ_SHORT_ASYNC);
12201 +                                        AIC_DV_STATE_INQ_SHORT_ASYNC);
12202                         break;
12203                 default:
12204 -                       AHC_SET_DV_STATE(ahc, targ, AHC_DV_STATE_EXIT);
12205 +                       AHC_SET_DV_STATE(ahc, targ, AIC_DV_STATE_EXIT);
12206                         break;
12207                 }
12208                 break;
12209  
12210 -       case AHC_DV_STATE_REBD:
12211 +       case AIC_DV_STATE_REBD:
12212                 switch (status & SS_MASK) {
12213                 case SS_NOP:
12214                 {
12215                         uint32_t echo_size;
12216  
12217 -                       AHC_SET_DV_STATE(ahc, targ, AHC_DV_STATE_WEB);
12218 +                       AHC_SET_DV_STATE(ahc, targ, AIC_DV_STATE_WEB);
12219                         echo_size = scsi_3btoul(&targ->dv_buffer[1]);
12220                         echo_size &= 0x1FFF;
12221  #ifdef AHC_DEBUG
12222 @@ -2878,7 +2832,17 @@
12223                         }
12224  #endif
12225                         if (echo_size == 0) {
12226 -                               AHC_SET_DV_STATE(ahc, targ, AHC_DV_STATE_EXIT);
12227 +                               /*
12228 +                                * Fall back to basic DV.
12229 +                                */
12230 +                               if (bootverbose) {
12231 +                                       ahc_print_devinfo(ahc, devinfo);
12232 +                                       printf("Echo Buffer unavailable.  "
12233 +                                              "Performing basic DV.\n");
12234 +                               }
12235 +                               targ->flags &= ~AIC_ENHANCED_DV;
12236 +                               targ->flags |= AIC_BASIC_DV;
12237 +                               AHC_SET_DV_STATE(ahc, targ, AIC_DV_STATE_TUR);
12238                                 break;
12239                         }
12240  
12241 @@ -2893,11 +2857,11 @@
12242                 }
12243                 case SS_INQ_REFRESH:
12244                         AHC_SET_DV_STATE(ahc, targ,
12245 -                                        AHC_DV_STATE_INQ_SHORT_ASYNC);
12246 +                                        AIC_DV_STATE_INQ_SHORT_ASYNC);
12247                         break;
12248                 case SS_RETRY:
12249                         AHC_SET_DV_STATE(ahc, targ, targ->dv_state);
12250 -                       if (ahc_cmd_get_transaction_status(cmd)
12251 +                       if (aic_cmd_get_transaction_status(cmd)
12252                          == CAM_REQUEUE_REQ)
12253                                 targ->dv_state_retry--;
12254                         if (targ->dv_state_retry <= 10)
12255 @@ -2916,30 +2880,30 @@
12256                          * and try level 1 DV.
12257                          */
12258                         ahc_linux_filter_inquiry(ahc, devinfo);
12259 -                       AHC_SET_DV_STATE(ahc, targ, AHC_DV_STATE_INQ_VERIFY);
12260 +                       AHC_SET_DV_STATE(ahc, targ, AIC_DV_STATE_INQ_VERIFY);
12261                         targ->dv_echo_size = 0;
12262                         break;
12263                 }
12264                 break;
12265  
12266 -       case AHC_DV_STATE_WEB:
12267 +       case AIC_DV_STATE_WEB:
12268                 switch (status & SS_MASK) {
12269                 case SS_NOP:
12270 -                       AHC_SET_DV_STATE(ahc, targ, AHC_DV_STATE_REB);
12271 +                       AHC_SET_DV_STATE(ahc, targ, AIC_DV_STATE_REB);
12272                         break;
12273                 case SS_INQ_REFRESH:
12274                         AHC_SET_DV_STATE(ahc, targ,
12275 -                                        AHC_DV_STATE_INQ_SHORT_ASYNC);
12276 +                                        AIC_DV_STATE_INQ_SHORT_ASYNC);
12277                         break;
12278                 case SS_RETRY:
12279                         AHC_SET_DV_STATE(ahc, targ, targ->dv_state);
12280 -                       if (ahc_cmd_get_transaction_status(cmd)
12281 +                       if (aic_cmd_get_transaction_status(cmd)
12282                          == CAM_REQUEUE_REQ) {
12283                                 targ->dv_state_retry--;
12284                         } else if ((status & SSQ_FALLBACK) != 0) {
12285                                 if (ahc_linux_fallback(ahc, devinfo) != 0) {
12286                                         AHC_SET_DV_STATE(ahc, targ,
12287 -                                                        AHC_DV_STATE_EXIT);
12288 +                                                        AIC_DV_STATE_EXIT);
12289                                         break;
12290                                 }
12291                                 /*
12292 @@ -2958,22 +2922,22 @@
12293                         }
12294  #endif
12295                 default:
12296 -                       AHC_SET_DV_STATE(ahc, targ, AHC_DV_STATE_EXIT);
12297 +                       AHC_SET_DV_STATE(ahc, targ, AIC_DV_STATE_EXIT);
12298                         break;
12299                 }
12300                 break;
12301  
12302 -       case AHC_DV_STATE_REB:
12303 +       case AIC_DV_STATE_REB:
12304                 switch (status & SS_MASK) {
12305                 case SS_NOP:
12306                         if (memcmp(targ->dv_buffer, targ->dv_buffer1,
12307                                    targ->dv_echo_size) != 0) {
12308                                 if (ahc_linux_fallback(ahc, devinfo) != 0)
12309                                         AHC_SET_DV_STATE(ahc, targ,
12310 -                                                        AHC_DV_STATE_EXIT);
12311 +                                                        AIC_DV_STATE_EXIT);
12312                                 else
12313                                         AHC_SET_DV_STATE(ahc, targ,
12314 -                                                        AHC_DV_STATE_WEB);
12315 +                                                        AIC_DV_STATE_WEB);
12316                                 break;
12317                         }
12318                         
12319 @@ -2985,24 +2949,24 @@
12320                                 free(targ->dv_buffer1, M_DEVBUF);
12321                                 targ->dv_buffer1 = NULL;
12322                         }
12323 -                       AHC_SET_DV_STATE(ahc, targ, AHC_DV_STATE_EXIT);
12324 +                       AHC_SET_DV_STATE(ahc, targ, AIC_DV_STATE_EXIT);
12325                         break;
12326                 case SS_INQ_REFRESH:
12327                         AHC_SET_DV_STATE(ahc, targ,
12328 -                                        AHC_DV_STATE_INQ_SHORT_ASYNC);
12329 +                                        AIC_DV_STATE_INQ_SHORT_ASYNC);
12330                         break;
12331                 case SS_RETRY:
12332                         AHC_SET_DV_STATE(ahc, targ, targ->dv_state);
12333 -                       if (ahc_cmd_get_transaction_status(cmd)
12334 +                       if (aic_cmd_get_transaction_status(cmd)
12335                          == CAM_REQUEUE_REQ) {
12336                                 targ->dv_state_retry--;
12337                         } else if ((status & SSQ_FALLBACK) != 0) {
12338                                 if (ahc_linux_fallback(ahc, devinfo) != 0) {
12339                                         AHC_SET_DV_STATE(ahc, targ,
12340 -                                                        AHC_DV_STATE_EXIT);
12341 +                                                        AIC_DV_STATE_EXIT);
12342                                         break;
12343                                 }
12344 -                               AHC_SET_DV_STATE(ahc, targ, AHC_DV_STATE_WEB);
12345 +                               AHC_SET_DV_STATE(ahc, targ, AIC_DV_STATE_WEB);
12346                         }
12347                         if (targ->dv_state_retry <= 10) {
12348                                 if ((status & (SSQ_DELAY_RANDOM|SSQ_DELAY))!= 0)
12349 @@ -3017,35 +2981,35 @@
12350  #endif
12351                         /* FALLTHROUGH */
12352                 default:
12353 -                       AHC_SET_DV_STATE(ahc, targ, AHC_DV_STATE_EXIT);
12354 +                       AHC_SET_DV_STATE(ahc, targ, AIC_DV_STATE_EXIT);
12355                         break;
12356                 }
12357                 break;
12358  
12359 -       case AHC_DV_STATE_SU:
12360 +       case AIC_DV_STATE_SU:
12361                 switch (status & SS_MASK) {
12362                 case SS_NOP:
12363                 case SS_INQ_REFRESH:
12364                         AHC_SET_DV_STATE(ahc, targ,
12365 -                                        AHC_DV_STATE_INQ_SHORT_ASYNC);
12366 +                                        AIC_DV_STATE_INQ_SHORT_ASYNC);
12367                         break;
12368                 default:
12369 -                       AHC_SET_DV_STATE(ahc, targ, AHC_DV_STATE_EXIT);
12370 +                       AHC_SET_DV_STATE(ahc, targ, AIC_DV_STATE_EXIT);
12371                         break;
12372                 }
12373                 break;
12374  
12375 -       case AHC_DV_STATE_BUSY:
12376 +       case AIC_DV_STATE_BUSY:
12377                 switch (status & SS_MASK) {
12378                 case SS_NOP:
12379                 case SS_INQ_REFRESH:
12380                         AHC_SET_DV_STATE(ahc, targ,
12381 -                                        AHC_DV_STATE_INQ_SHORT_ASYNC);
12382 +                                        AIC_DV_STATE_INQ_SHORT_ASYNC);
12383                         break;
12384                 case SS_TUR:
12385                 case SS_RETRY:
12386                         AHC_SET_DV_STATE(ahc, targ, targ->dv_state);
12387 -                       if (ahc_cmd_get_transaction_status(cmd)
12388 +                       if (aic_cmd_get_transaction_status(cmd)
12389                          == CAM_REQUEUE_REQ) {
12390                                 targ->dv_state_retry--;
12391                         } else if (targ->dv_state_retry < 60) {
12392 @@ -3058,11 +3022,11 @@
12393                                         printf("DV BUSY reties exhausted\n");
12394                                 }
12395  #endif
12396 -                               AHC_SET_DV_STATE(ahc, targ, AHC_DV_STATE_EXIT);
12397 +                               AHC_SET_DV_STATE(ahc, targ, AIC_DV_STATE_EXIT);
12398                         }
12399                         break;
12400                 default:
12401 -                       AHC_SET_DV_STATE(ahc, targ, AHC_DV_STATE_EXIT);
12402 +                       AHC_SET_DV_STATE(ahc, targ, AIC_DV_STATE_EXIT);
12403                         break;
12404                 }
12405                 break;
12406 @@ -3070,7 +3034,7 @@
12407         default:
12408                 printf("%s: Invalid DV completion state %d\n", ahc_name(ahc),
12409                        targ->dv_state);
12410 -               AHC_SET_DV_STATE(ahc, targ, AHC_DV_STATE_EXIT);
12411 +               AHC_SET_DV_STATE(ahc, targ, AIC_DV_STATE_EXIT);
12412                 break;
12413         }
12414  }
12415 @@ -3090,7 +3054,7 @@
12416   */
12417  static void
12418  ahc_linux_dv_inq(struct ahc_softc *ahc, struct scsi_cmnd *cmd,
12419 -                struct ahc_devinfo *devinfo, struct ahc_linux_target *targ,
12420 +                struct ahc_devinfo *devinfo, struct aic_linux_target *targ,
12421                  u_int request_length)
12422  {
12423  
12424 @@ -3103,7 +3067,7 @@
12425         if (targ->inq_data == NULL)
12426                 targ->inq_data = malloc(AHC_LINUX_DV_INQ_LEN,
12427                                         M_DEVBUF, M_WAITOK);
12428 -       if (targ->dv_state > AHC_DV_STATE_INQ_ASYNC) {
12429 +       if (targ->dv_state > AIC_DV_STATE_INQ_ASYNC) {
12430                 if (targ->dv_buffer != NULL)
12431                         free(targ->dv_buffer, M_DEVBUF);
12432                 targ->dv_buffer = malloc(AHC_LINUX_DV_INQ_LEN,
12433 @@ -3116,7 +3080,7 @@
12434         cmd->cmnd[0] = INQUIRY;
12435         cmd->cmnd[4] = request_length;
12436         cmd->request_bufflen = request_length;
12437 -       if (targ->dv_state > AHC_DV_STATE_INQ_ASYNC)
12438 +       if (targ->dv_state > AIC_DV_STATE_INQ_ASYNC)
12439                 cmd->request_buffer = targ->dv_buffer;
12440         else
12441                 cmd->request_buffer = targ->inq_data;
12442 @@ -3145,7 +3109,7 @@
12443  
12444  static void
12445  ahc_linux_dv_rebd(struct ahc_softc *ahc, struct scsi_cmnd *cmd,
12446 -                struct ahc_devinfo *devinfo, struct ahc_linux_target *targ)
12447 +                struct ahc_devinfo *devinfo, struct aic_linux_target *targ)
12448  {
12449  
12450  #ifdef AHC_DEBUG
12451 @@ -3170,7 +3134,7 @@
12452  
12453  static void
12454  ahc_linux_dv_web(struct ahc_softc *ahc, struct scsi_cmnd *cmd,
12455 -                struct ahc_devinfo *devinfo, struct ahc_linux_target *targ)
12456 +                struct ahc_devinfo *devinfo, struct aic_linux_target *targ)
12457  {
12458  
12459  #ifdef AHC_DEBUG
12460 @@ -3192,7 +3156,7 @@
12461  
12462  static void
12463  ahc_linux_dv_reb(struct ahc_softc *ahc, struct scsi_cmnd *cmd,
12464 -                struct ahc_devinfo *devinfo, struct ahc_linux_target *targ)
12465 +                struct ahc_devinfo *devinfo, struct aic_linux_target *targ)
12466  {
12467  
12468  #ifdef AHC_DEBUG
12469 @@ -3215,7 +3179,7 @@
12470  static void
12471  ahc_linux_dv_su(struct ahc_softc *ahc, struct scsi_cmnd *cmd,
12472                 struct ahc_devinfo *devinfo,
12473 -               struct ahc_linux_target *targ)
12474 +               struct aic_linux_target *targ)
12475  {
12476         u_int le;
12477  
12478 @@ -3237,7 +3201,7 @@
12479  static int
12480  ahc_linux_fallback(struct ahc_softc *ahc, struct ahc_devinfo *devinfo)
12481  {
12482 -       struct  ahc_linux_target *targ;
12483 +       struct  aic_linux_target *targ;
12484         struct  ahc_initiator_tinfo *tinfo;
12485         struct  ahc_transinfo *goal;
12486         struct  ahc_tmode_tstate *tstate;
12487 @@ -3416,7 +3380,7 @@
12488         return (0);
12489  }
12490  
12491 -static void
12492 +void
12493  ahc_linux_dv_timeout(struct scsi_cmnd *cmd)
12494  {
12495         struct  ahc_softc *ahc;
12496 @@ -3450,29 +3414,19 @@
12497          * error code.
12498          */
12499         if ((scb->flags & SCB_SENSE) != 0)
12500 -               ahc_set_transaction_status(scb, CAM_AUTOSENSE_FAIL);
12501 +               aic_set_transaction_status(scb, CAM_AUTOSENSE_FAIL);
12502         else
12503 -               ahc_set_transaction_status(scb, CAM_CMD_TIMEOUT);
12504 +               aic_set_transaction_status(scb, CAM_CMD_TIMEOUT);
12505         ahc_reset_channel(ahc, cmd->device->channel + 'A', /*initiate*/TRUE);
12506  
12507 -       /*
12508 -        * Add a minimal bus settle delay for devices that are slow to
12509 -        * respond after bus resets.
12510 -        */
12511 -       ahc_linux_freeze_simq(ahc);
12512 -       init_timer(&ahc->platform_data->reset_timer);
12513 -       ahc->platform_data->reset_timer.data = (u_long)ahc;
12514 -       ahc->platform_data->reset_timer.expires = jiffies + HZ / 2;
12515 -       ahc->platform_data->reset_timer.function =
12516 -           (ahc_linux_callback_t *)ahc_linux_release_simq;
12517 -       add_timer(&ahc->platform_data->reset_timer);
12518 -       if (ahc_linux_next_device_to_run(ahc) != NULL)
12519 -               ahc_schedule_runq(ahc);
12520 +       if (aic_linux_next_device_to_run(ahc) != NULL)
12521 +               aic_schedule_runq(ahc);
12522 +
12523         ahc_linux_run_complete_queue(ahc);
12524         ahc_unlock(ahc, &flags);
12525  }
12526  
12527 -static void
12528 +void
12529  ahc_linux_dv_complete(struct scsi_cmnd *cmd)
12530  {
12531         struct ahc_softc *ahc;
12532 @@ -3494,7 +3448,7 @@
12533  }
12534  
12535  static void
12536 -ahc_linux_generate_dv_pattern(struct ahc_linux_target *targ)
12537 +ahc_linux_generate_dv_pattern(struct aic_linux_target *targ)
12538  {
12539         uint16_t b;
12540         u_int    i;
12541 @@ -3626,8 +3580,8 @@
12542   * Determines the queue depth for a given device.
12543   */
12544  static void
12545 -ahc_linux_device_queue_depth(struct ahc_softc *ahc,
12546 -                            struct ahc_linux_device *dev)
12547 +aic_linux_device_queue_depth(struct ahc_softc *ahc,
12548 +                            struct aic_linux_device *dev)
12549  {
12550         struct  ahc_devinfo devinfo;
12551         u_int   tags;
12552 @@ -3651,10 +3605,10 @@
12553         }
12554  }
12555  
12556 -static void
12557 -ahc_linux_run_device_queue(struct ahc_softc *ahc, struct ahc_linux_device *dev)
12558 +void
12559 +ahc_linux_run_device_queue(struct ahc_softc *ahc, struct aic_linux_device *dev)
12560  {
12561 -       struct   ahc_cmd *acmd;
12562 +       struct   aic_cmd *acmd;
12563         struct   scsi_cmnd *cmd;
12564         struct   scb *scb;
12565         struct   hardware_scb *hscb;
12566 @@ -3662,7 +3616,7 @@
12567         struct   ahc_tmode_tstate *tstate;
12568         uint16_t mask;
12569  
12570 -       if ((dev->flags & AHC_DEV_ON_RUN_LIST) != 0)
12571 +       if ((dev->flags & AIC_DEV_ON_RUN_LIST) != 0)
12572                 panic("running device on run list");
12573  
12574         while ((acmd = TAILQ_FIRST(&dev->busyq)) != NULL
12575 @@ -3673,10 +3627,10 @@
12576                  * running is because the whole controller Q is frozen.
12577                  */
12578                 if (ahc->platform_data->qfrozen != 0
12579 -                && AHC_DV_SIMQ_FROZEN(ahc) == 0) {
12580 +                && AIC_DV_SIMQ_FROZEN(ahc) == 0) {
12581                         TAILQ_INSERT_TAIL(&ahc->platform_data->device_runq,
12582                                           dev, links);
12583 -                       dev->flags |= AHC_DEV_ON_RUN_LIST;
12584 +                       dev->flags |= AIC_DEV_ON_RUN_LIST;
12585                         return;
12586                 }
12587                 /*
12588 @@ -3685,7 +3639,7 @@
12589                 if ((scb = ahc_get_scb(ahc)) == NULL) {
12590                         TAILQ_INSERT_TAIL(&ahc->platform_data->device_runq,
12591                                          dev, links);
12592 -                       dev->flags |= AHC_DEV_ON_RUN_LIST;
12593 +                       dev->flags |= AIC_DEV_ON_RUN_LIST;
12594                         ahc->flags |= AHC_RESOURCE_SHORTAGE;
12595                         return;
12596                 }
12597 @@ -3693,6 +3647,7 @@
12598                 cmd = &acmd_scsi_cmd(acmd);
12599                 scb->io_ctx = cmd;
12600                 scb->platform_data->dev = dev;
12601 +               scb->platform_data->flags = 0;
12602                 hscb = scb->hscb;
12603                 cmd->host_scribble = (char *)scb;
12604  
12605 @@ -3714,7 +3669,7 @@
12606                 if ((ahc->user_discenable & mask) != 0)
12607                         hscb->control |= DISCENB;
12608  
12609 -               if (AHC_DV_CMD(cmd) != 0)
12610 +               if (AIC_DV_CMD(cmd) != 0)
12611                         scb->flags |= SCB_SILENT;
12612  
12613                 if ((tstate->auto_negotiate & mask) != 0) {
12614 @@ -3722,7 +3677,7 @@
12615                         scb->hscb->control |= MK_MESSAGE;
12616                 }
12617  
12618 -               if ((dev->flags & (AHC_DEV_Q_TAGGED|AHC_DEV_Q_BASIC)) != 0) {
12619 +               if ((dev->flags & (AIC_DEV_Q_TAGGED|AIC_DEV_Q_BASIC)) != 0) {
12620  #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,0)
12621                         int     msg_bytes;
12622                         uint8_t tag_msgs[2];
12623 @@ -3734,8 +3689,8 @@
12624                                         dev->commands_since_idle_or_otag = 0;
12625                         } else
12626  #endif
12627 -                       if (dev->commands_since_idle_or_otag == AHC_OTAG_THRESH
12628 -                        && (dev->flags & AHC_DEV_Q_TAGGED) != 0) {
12629 +                       if (dev->commands_since_idle_or_otag == AIC_OTAG_THRESH
12630 +                        && (dev->flags & AIC_DEV_Q_TAGGED) != 0) {
12631                                 hscb->control |= MSG_ORDERED_TASK;
12632                                 dev->commands_since_idle_or_otag = 0;
12633                         } else {
12634 @@ -3752,8 +3707,8 @@
12635                 }
12636  
12637                 scb->platform_data->xfer_len = 0;
12638 -               ahc_set_residual(scb, 0);
12639 -               ahc_set_sense_residual(scb, 0);
12640 +               aic_set_residual(scb, 0);
12641 +               aic_set_sense_residual(scb, 0);
12642                 scb->sg_count = 0;
12643                 if (cmd->use_sg != 0) {
12644                         struct  ahc_dma_seg *sg;
12645 @@ -3762,7 +3717,7 @@
12646                         int     nseg;
12647  
12648                         cur_seg = (struct scatterlist *)cmd->request_buffer;
12649 -                       nseg = pci_map_sg(ahc->dev_softc, cur_seg, cmd->use_sg,
12650 +                       nseg = aic_map_sg(ahc, cur_seg, cmd->use_sg,
12651                             scsi_to_pci_dma_dir(cmd->sc_data_direction));
12652                         end_seg = cur_seg + nseg;
12653                         /* Copy the segments into the SG list. */
12654 @@ -3785,13 +3740,13 @@
12655                                 cur_seg++;
12656                         }
12657                         sg--;
12658 -                       sg->len |= ahc_htole32(AHC_DMA_LAST_SEG);
12659 +                       sg->len |= aic_htole32(AHC_DMA_LAST_SEG);
12660  
12661                         /*
12662                          * Reset the sg list pointer.
12663                          */
12664                         scb->hscb->sgptr =
12665 -                           ahc_htole32(scb->sg_list_phys | SG_FULL_RESID);
12666 +                           aic_htole32(scb->sg_list_phys | SG_FULL_RESID);
12667  
12668                         /*
12669                          * Copy the first SG into the "current"
12670 @@ -3804,7 +3759,7 @@
12671                         bus_addr_t addr;
12672  
12673                         sg = scb->sg_list;
12674 -                       addr = pci_map_single(ahc->dev_softc,
12675 +                       addr = aic_map_single(ahc,
12676                                cmd->request_buffer,
12677                                cmd->request_bufflen,
12678                                scsi_to_pci_dma_dir(cmd->sc_data_direction));
12679 @@ -3812,13 +3767,13 @@
12680                         scb->sg_count = ahc_linux_map_seg(ahc, scb,
12681                                                           sg, addr,
12682                                                           cmd->request_bufflen);
12683 -                       sg->len |= ahc_htole32(AHC_DMA_LAST_SEG);
12684 +                       sg->len |= aic_htole32(AHC_DMA_LAST_SEG);
12685  
12686                         /*
12687                          * Reset the sg list pointer.
12688                          */
12689                         scb->hscb->sgptr =
12690 -                           ahc_htole32(scb->sg_list_phys | SG_FULL_RESID);
12691 +                           aic_htole32(scb->sg_list_phys | SG_FULL_RESID);
12692  
12693                         /*
12694                          * Copy the first SG into the "current"
12695 @@ -3827,7 +3782,7 @@
12696                         scb->hscb->dataptr = sg->addr;
12697                         scb->hscb->datacnt = sg->len;
12698                 } else {
12699 -                       scb->hscb->sgptr = ahc_htole32(SG_LIST_NULL);
12700 +                       scb->hscb->sgptr = aic_htole32(SG_LIST_NULL);
12701                         scb->hscb->dataptr = 0;
12702                         scb->hscb->datacnt = 0;
12703                         scb->sg_count = 0;
12704 @@ -3838,7 +3793,7 @@
12705                 dev->openings--;
12706                 dev->active++;
12707                 dev->commands_issued++;
12708 -               if ((dev->flags & AHC_DEV_PERIODIC_OTAG) != 0)
12709 +               if ((dev->flags & AIC_DEV_PERIODIC_OTAG) != 0)
12710                         dev->commands_since_idle_or_otag++;
12711  
12712                 /*
12713 @@ -3860,6 +3815,7 @@
12714                                 continue;
12715                 }
12716                 scb->flags |= SCB_ACTIVE;
12717 +               aic_scb_timer_start(scb);
12718                 ahc_queue_scb(ahc, scb);
12719         }
12720  }
12721 @@ -3877,8 +3833,8 @@
12722         ahc = (struct ahc_softc *) dev_id;
12723         ahc_lock(ahc, &flags); 
12724         ours = ahc_intr(ahc);
12725 -       if (ahc_linux_next_device_to_run(ahc) != NULL)
12726 -               ahc_schedule_runq(ahc);
12727 +       if (aic_linux_next_device_to_run(ahc) != NULL)
12728 +               aic_schedule_runq(ahc);
12729         ahc_linux_run_complete_queue(ahc);
12730         ahc_unlock(ahc, &flags);
12731         return IRQ_RETVAL(ours);
12732 @@ -3892,10 +3848,10 @@
12733                 ;
12734  }
12735  
12736 -static struct ahc_linux_target*
12737 +static struct aic_linux_target*
12738  ahc_linux_alloc_target(struct ahc_softc *ahc, u_int channel, u_int target)
12739  {
12740 -       struct ahc_linux_target *targ;
12741 +       struct aic_linux_target *targ;
12742         u_int target_offset;
12743  
12744         target_offset = target;
12745 @@ -3908,14 +3864,14 @@
12746         memset(targ, 0, sizeof(*targ));
12747         targ->channel = channel;
12748         targ->target = target;
12749 -       targ->ahc = ahc;
12750 -       targ->flags = AHC_DV_REQUIRED;
12751 +       targ->softc = ahc;
12752 +       targ->flags = AIC_DV_REQUIRED;
12753         ahc->platform_data->targets[target_offset] = targ;
12754         return (targ);
12755  }
12756  
12757  static void
12758 -ahc_linux_free_target(struct ahc_softc *ahc, struct ahc_linux_target *targ)
12759 +ahc_linux_free_target(struct ahc_softc *ahc, struct aic_linux_target *targ)
12760  {
12761         struct ahc_devinfo devinfo;
12762         struct ahc_initiator_tinfo *tinfo;
12763 @@ -3955,11 +3911,11 @@
12764         free(targ, M_DEVBUF);
12765  }
12766  
12767 -static struct ahc_linux_device*
12768 +static struct aic_linux_device*
12769  ahc_linux_alloc_device(struct ahc_softc *ahc,
12770 -                struct ahc_linux_target *targ, u_int lun)
12771 +                struct aic_linux_target *targ, u_int lun)
12772  {
12773 -       struct ahc_linux_device *dev;
12774 +       struct aic_linux_device *dev;
12775  
12776         dev = malloc(sizeof(*dev), M_DEVBUG, M_NOWAIT);
12777         if (dev == NULL)
12778 @@ -3967,7 +3923,7 @@
12779         memset(dev, 0, sizeof(*dev));
12780         init_timer(&dev->timer);
12781         TAILQ_INIT(&dev->busyq);
12782 -       dev->flags = AHC_DEV_UNCONFIGURED;
12783 +       dev->flags = AIC_DEV_UNCONFIGURED;
12784         dev->lun = lun;
12785         dev->target = targ;
12786  
12787 @@ -3990,17 +3946,17 @@
12788  }
12789  
12790  static void
12791 -ahc_linux_free_device(struct ahc_softc *ahc, struct ahc_linux_device *dev)
12792 +ahc_linux_free_device(struct ahc_softc *ahc, struct aic_linux_device *dev)
12793  {
12794 -       struct ahc_linux_target *targ;
12795 +       struct aic_linux_target *targ;
12796  
12797 -       del_timer_sync(&dev->timer);
12798 +       del_timer(&dev->timer);
12799         targ = dev->target;
12800         targ->devices[dev->lun] = NULL;
12801         free(dev, M_DEVBUF);
12802         targ->refcount--;
12803         if (targ->refcount == 0
12804 -        && (targ->flags & AHC_DV_REQUIRED) == 0)
12805 +        && (targ->flags & AIC_DV_REQUIRED) == 0)
12806                 ahc_linux_free_target(ahc, targ);
12807  }
12808  
12809 @@ -4012,7 +3968,7 @@
12810         case AC_TRANSFER_NEG:
12811         {
12812                 char    buf[80];
12813 -               struct  ahc_linux_target *targ;
12814 +               struct  aic_linux_target *targ;
12815                 struct  info_str info;
12816                 struct  ahc_initiator_tinfo *tinfo;
12817                 struct  ahc_tmode_tstate *tstate;
12818 @@ -4106,6 +4062,20 @@
12819                                               channel - 'A');
12820                 }
12821  #endif
12822 +               /*
12823 +                * Add a minimal bus settle delay for devices that are slow to
12824 +                * respond after bus resets.
12825 +                */
12826 +               if ((ahc->platform_data->flags & AIC_BUS_SETTLE_TIMER) == 0) {
12827 +                       aic_freeze_simq(ahc);
12828 +                       ahc->platform_data->flags |= AIC_BUS_SETTLE_TIMER;
12829 +                       ahc->platform_data->bus_settle_timer.expires =
12830 +                           jiffies + (AIC7XXX_RESET_DELAY * HZ)/1000;
12831 +                       add_timer(&ahc->platform_data->bus_settle_timer);
12832 +               } else {
12833 +                       mod_timer(&ahc->platform_data->bus_settle_timer,
12834 +                                 jiffies + (AIC7XXX_RESET_DELAY * HZ)/1000);
12835 +               }
12836                  break;
12837          default:
12838                  panic("ahc_send_async: Unexpected async event");
12839 @@ -4119,9 +4089,11 @@
12840  ahc_done(struct ahc_softc *ahc, struct scb *scb)
12841  {
12842         Scsi_Cmnd *cmd;
12843 -       struct     ahc_linux_device *dev;
12844 +       struct     aic_linux_device *dev;
12845  
12846         LIST_REMOVE(scb, pending_links);
12847 +       if ((scb->flags & SCB_TIMEDOUT) != 0)
12848 +               LIST_REMOVE(scb, timedout_links);
12849         if ((scb->flags & SCB_UNTAGGEDQ) != 0) {
12850                 struct scb_tailq *untagged_q;
12851                 int target_offset;
12852 @@ -4154,11 +4126,11 @@
12853          * the sense buffer looks "sane".
12854          */
12855         cmd->sense_buffer[0] = 0;
12856 -       if (ahc_get_transaction_status(scb) == CAM_REQ_INPROG) {
12857 +       if (aic_get_transaction_status(scb) == CAM_REQ_INPROG) {
12858                 uint32_t amount_xferred;
12859  
12860                 amount_xferred =
12861 -                   ahc_get_transfer_length(scb) - ahc_get_residual(scb);
12862 +                   aic_get_transfer_length(scb) - aic_get_residual(scb);
12863                 if ((scb->flags & SCB_TRANSMISSION_ERROR) != 0) {
12864  #ifdef AHC_DEBUG
12865                         if ((ahc_debug & AHC_SHOW_MISC) != 0) {
12866 @@ -4166,7 +4138,17 @@
12867                                 printf("Set CAM_UNCOR_PARITY\n");
12868                         }
12869  #endif
12870 -                       ahc_set_transaction_status(scb, CAM_UNCOR_PARITY);
12871 +                       aic_set_transaction_status(scb, CAM_UNCOR_PARITY);
12872 +#ifdef AHC_REPORT_UNDERFLOWS
12873 +               /*
12874 +                * This code is disabled by default as some
12875 +                * clients of the SCSI system do not properly
12876 +                * initialize the underflow parameter.  This
12877 +                * results in spurious termination of commands
12878 +                * that complete as expected (e.g. underflow is
12879 +                * allowed as command can return variable amounts
12880 +                * of data.
12881 +                */
12882                 } else if (amount_xferred < scb->io_ctx->underflow) {
12883                         u_int i;
12884  
12885 @@ -4178,30 +4160,31 @@
12886                         ahc_print_path(ahc, scb);
12887                         printf("Saw underflow (%ld of %ld bytes). "
12888                                "Treated as error\n",
12889 -                               ahc_get_residual(scb),
12890 -                               ahc_get_transfer_length(scb));
12891 -                       ahc_set_transaction_status(scb, CAM_DATA_RUN_ERR);
12892 +                               aic_get_residual(scb),
12893 +                               aic_get_transfer_length(scb));
12894 +                       aic_set_transaction_status(scb, CAM_DATA_RUN_ERR);
12895 +#endif
12896                 } else {
12897 -                       ahc_set_transaction_status(scb, CAM_REQ_CMP);
12898 +                       aic_set_transaction_status(scb, CAM_REQ_CMP);
12899                 }
12900 -       } else if (ahc_get_transaction_status(scb) == CAM_SCSI_STATUS_ERROR) {
12901 +       } else if (aic_get_transaction_status(scb) == CAM_SCSI_STATUS_ERROR) {
12902                 ahc_linux_handle_scsi_status(ahc, dev, scb);
12903 -       } else if (ahc_get_transaction_status(scb) == CAM_SEL_TIMEOUT) {
12904 -               dev->flags |= AHC_DEV_UNCONFIGURED;
12905 -               if (AHC_DV_CMD(cmd) == FALSE)
12906 -                       dev->target->flags &= ~AHC_DV_REQUIRED;
12907 +       } else if (aic_get_transaction_status(scb) == CAM_SEL_TIMEOUT) {
12908 +               dev->flags |= AIC_DEV_UNCONFIGURED;
12909 +               if (AIC_DV_CMD(cmd) == FALSE)
12910 +                       dev->target->flags &= ~AIC_DV_REQUIRED;
12911         }
12912         /*
12913          * Start DV for devices that require it assuming the first command
12914          * sent does not result in a selection timeout.
12915          */
12916 -       if (ahc_get_transaction_status(scb) != CAM_SEL_TIMEOUT
12917 -        && (dev->target->flags & AHC_DV_REQUIRED) != 0)
12918 +       if (aic_get_transaction_status(scb) != CAM_SEL_TIMEOUT
12919 +        && (dev->target->flags & AIC_DV_REQUIRED) != 0)
12920                 ahc_linux_start_dv(ahc);
12921  
12922         if (dev->openings == 1
12923 -        && ahc_get_transaction_status(scb) == CAM_REQ_CMP
12924 -        && ahc_get_scsi_status(scb) != SCSI_STATUS_QUEUE_FULL)
12925 +        && aic_get_transaction_status(scb) == CAM_REQ_CMP
12926 +        && aic_get_scsi_status(scb) != SCSI_STATUS_QUEUE_FULL)
12927                 dev->tag_success_count++;
12928         /*
12929          * Some devices deal with temporary internal resource
12930 @@ -4210,7 +4193,7 @@
12931          * back to our previous queue depth.
12932          */
12933         if ((dev->openings + dev->active) < dev->maxtags
12934 -        && dev->tag_success_count > AHC_TAG_SUCCESS_INTERVAL) {
12935 +        && dev->tag_success_count > AIC_TAG_SUCCESS_INTERVAL) {
12936                 dev->tag_success_count = 0;
12937                 dev->openings++;
12938         }
12939 @@ -4219,32 +4202,61 @@
12940                 dev->commands_since_idle_or_otag = 0;
12941  
12942         if (TAILQ_EMPTY(&dev->busyq)) {
12943 -               if ((dev->flags & AHC_DEV_UNCONFIGURED) != 0
12944 -                && dev->active == 0
12945 -                && (dev->flags & AHC_DEV_TIMER_ACTIVE) == 0)
12946 +               if ((dev->flags & AIC_DEV_UNCONFIGURED) != 0
12947 +                && dev->active == 0)
12948                         ahc_linux_free_device(ahc, dev);
12949 -       } else if ((dev->flags & AHC_DEV_ON_RUN_LIST) == 0) {
12950 +       } else if ((dev->flags & AIC_DEV_ON_RUN_LIST) == 0) {
12951                 TAILQ_INSERT_TAIL(&ahc->platform_data->device_runq, dev, links);
12952 -               dev->flags |= AHC_DEV_ON_RUN_LIST;
12953 +               dev->flags |= AIC_DEV_ON_RUN_LIST;
12954         }
12955  
12956         if ((scb->flags & SCB_RECOVERY_SCB) != 0) {
12957                 printf("Recovery SCB completes\n");
12958 -               if (ahc_get_transaction_status(scb) == CAM_BDR_SENT
12959 -                || ahc_get_transaction_status(scb) == CAM_REQ_ABORTED)
12960 -                       ahc_set_transaction_status(scb, CAM_CMD_TIMEOUT);
12961 -               if ((ahc->platform_data->flags & AHC_UP_EH_SEMAPHORE) != 0) {
12962 -                       ahc->platform_data->flags &= ~AHC_UP_EH_SEMAPHORE;
12963 +               if (aic_get_transaction_status(scb) == CAM_BDR_SENT
12964 +                || aic_get_transaction_status(scb) == CAM_REQ_ABORTED)
12965 +                       aic_set_transaction_status(scb, CAM_CMD_TIMEOUT);
12966 +               if ((scb->platform_data->flags & AIC_SCB_UP_EH_SEM) != 0) {
12967 +                       scb->platform_data->flags &= ~AIC_SCB_UP_EH_SEM;
12968                         up(&ahc->platform_data->eh_sem);
12969 +               } else {
12970 +                       struct  scb *list_scb;
12971 +
12972 +                       /*
12973 +                        * We were able to complete the command successfully,
12974 +                        * so reinstate the timeouts for all other pending
12975 +                        * commands.
12976 +                        */
12977 +                       LIST_FOREACH(list_scb,
12978 +                                    &ahc->pending_scbs, pending_links) {
12979 +
12980 +                               aic_scb_timer_start(list_scb);
12981 +                       }
12982                 }
12983         }
12984  
12985 +       if ((scb->platform_data->flags & AIC_TIMEOUT_ACTIVE) == 0) {
12986 +               /*
12987 +                * The completion handler believes that
12988 +                * commands without active timers running
12989 +                * have lost the race of completing before
12990 +                * their timer expires.  Since commands in
12991 +                * our busy queues do not have timers running,
12992 +                * appease the mid-layer by adding a timer
12993 +                * now.  This timer will be immediately
12994 +                * canceled by the midlayer.
12995 +                */
12996 +               scsi_add_timer(cmd, 60*HZ, aic_linux_midlayer_timeout);
12997 +       }
12998 +
12999 +       if ((scb->platform_data->flags & AIC_RELEASE_SIMQ) != 0)
13000 +               aic_release_simq_locked(ahc);
13001 +
13002         ahc_free_scb(ahc, scb);
13003         ahc_linux_queue_cmd_complete(ahc, cmd);
13004  
13005 -       if ((ahc->platform_data->flags & AHC_DV_WAIT_SIMQ_EMPTY) != 0
13006 +       if ((ahc->platform_data->flags & AIC_DV_WAIT_SIMQ_EMPTY) != 0
13007          && LIST_FIRST(&ahc->pending_scbs) == NULL) {
13008 -               ahc->platform_data->flags &= ~AHC_DV_WAIT_SIMQ_EMPTY;
13009 +               ahc->platform_data->flags &= ~AIC_DV_WAIT_SIMQ_EMPTY;
13010                 up(&ahc->platform_data->dv_sem);
13011         }
13012                 
13013 @@ -4252,7 +4264,7 @@
13014  
13015  static void
13016  ahc_linux_handle_scsi_status(struct ahc_softc *ahc,
13017 -                            struct ahc_linux_device *dev, struct scb *scb)
13018 +                            struct aic_linux_device *dev, struct scb *scb)
13019  {
13020         struct  ahc_devinfo devinfo;
13021  
13022 @@ -4272,7 +4284,7 @@
13023          * we don't clobber the device with too many
13024          * commands.
13025          */
13026 -       switch (ahc_get_scsi_status(scb)) {
13027 +       switch (aic_get_scsi_status(scb)) {
13028         default:
13029                 break;
13030         case SCSI_STATUS_CHECK_COND:
13031 @@ -4286,13 +4298,15 @@
13032                  */
13033                 cmd = scb->io_ctx;
13034                 if (scb->flags & SCB_SENSE) {
13035 -                       u_int sense_size;
13036 +                       struct  scsi_sense_data *sense;
13037 +                       u_int   sense_size;
13038 +                       int     error_code, sense_key, asc, ascq;
13039  
13040 +                       sense = ahc_get_sense_buf(ahc, scb);
13041                         sense_size = MIN(sizeof(struct scsi_sense_data)
13042 -                                      - ahc_get_sense_residual(scb),
13043 +                                      - aic_get_sense_residual(scb),
13044                                          sizeof(cmd->sense_buffer));
13045 -                       memcpy(cmd->sense_buffer,
13046 -                              ahc_get_sense_buf(ahc, scb), sense_size);
13047 +                       memcpy(cmd->sense_buffer, sense, sense_size);
13048                         if (sense_size < sizeof(cmd->sense_buffer))
13049                                 memset(&cmd->sense_buffer[sense_size], 0,
13050                                        sizeof(cmd->sense_buffer) - sense_size);
13051 @@ -4311,6 +4325,23 @@
13052                                 printf("\n");
13053                         }
13054  #endif
13055 +                       /*
13056 +                        * If this is not a DV command and the target
13057 +                        * provides some status that makes us believe
13058 +                        * that the target has changed (power on reset,
13059 +                        * etc.) kick off a DV scan to re-validate the
13060 +                        * device.
13061 +                        */
13062 +                       if (AIC_DV_CMD(cmd) != 0)
13063 +                               break;
13064 +
13065 +                       scsi_extract_sense(sense, &error_code,
13066 +                                          &sense_key, &asc, &ascq);
13067 +                       if (error_code == SSD_CURRENT_ERROR
13068 +                        && sense_key == SSD_KEY_UNIT_ATTENTION
13069 +                        && asc == 0x29
13070 +                        && (ascq == 0 || ascq == 1))
13071 +                               dev->target->flags |= AIC_DV_REQUIRED;
13072                 }
13073                 break;
13074         }
13075 @@ -4347,7 +4378,7 @@
13076                                  * this device.
13077                                  */
13078                                 if (dev->last_queuefull_same_count
13079 -                                == AHC_LOCK_TAGS_COUNT) {
13080 +                                == AIC_LOCK_TAGS_COUNT) {
13081                                         dev->maxtags = dev->active;
13082                                         ahc_print_path(ahc, scb);
13083                                         printf("Locking max tag count at %d\n",
13084 @@ -4357,10 +4388,10 @@
13085                                 dev->tags_on_last_queuefull = dev->active;
13086                                 dev->last_queuefull_same_count = 0;
13087                         }
13088 -                       ahc_set_transaction_status(scb, CAM_REQUEUE_REQ);
13089 -                       ahc_set_scsi_status(scb, SCSI_STATUS_OK);
13090 +                       aic_set_transaction_status(scb, CAM_REQUEUE_REQ);
13091 +                       aic_set_scsi_status(scb, SCSI_STATUS_OK);
13092                         ahc_platform_set_tags(ahc, &devinfo,
13093 -                                    (dev->flags & AHC_DEV_Q_BASIC)
13094 +                                    (dev->flags & AIC_DEV_Q_BASIC)
13095                                    ? AHC_QUEUE_BASIC : AHC_QUEUE_TAGGED);
13096                         break;
13097                 }
13098 @@ -4369,9 +4400,9 @@
13099                  * as if the target returned BUSY SCSI status.
13100                  */
13101                 dev->openings = 1;
13102 -               ahc_set_scsi_status(scb, SCSI_STATUS_BUSY);
13103 +               aic_set_scsi_status(scb, SCSI_STATUS_BUSY);
13104                 ahc_platform_set_tags(ahc, &devinfo,
13105 -                            (dev->flags & AHC_DEV_Q_BASIC)
13106 +                            (dev->flags & AIC_DEV_Q_BASIC)
13107                            ? AHC_QUEUE_BASIC : AHC_QUEUE_TAGGED);
13108                 /* FALLTHROUGH */
13109         }
13110 @@ -4381,13 +4412,13 @@
13111                  * Set a short timer to defer sending commands for
13112                  * a bit since Linux will not delay in this case.
13113                  */
13114 -               if ((dev->flags & AHC_DEV_TIMER_ACTIVE) != 0) {
13115 +               if ((dev->flags & AIC_DEV_TIMER_ACTIVE) != 0) {
13116                         printf("%s:%c:%d: Device Timer still active during "
13117                                "busy processing\n", ahc_name(ahc),
13118                                 dev->target->channel, dev->target->target);
13119                         break;
13120                 }
13121 -               dev->flags |= AHC_DEV_TIMER_ACTIVE;
13122 +               dev->flags |= AIC_DEV_TIMER_ACTIVE;
13123                 dev->qfrozen++;
13124                 init_timer(&dev->timer);
13125                 dev->timer.data = (u_long)dev;
13126 @@ -4414,9 +4445,9 @@
13127          * not guarantee the order that aborted commands will be
13128          * returned to us.
13129          */
13130 -       struct ahc_completeq *completeq;
13131 -       struct ahc_cmd *list_cmd;
13132 -       struct ahc_cmd *acmd;
13133 +       struct aic_completeq *completeq;
13134 +       struct aic_cmd *list_cmd;
13135 +       struct aic_cmd *acmd;
13136  
13137         /*
13138          * Map CAM error codes into Linux Error codes.  We
13139 @@ -4424,10 +4455,10 @@
13140          * full error information available when making
13141          * state change decisions.
13142          */
13143 -       if (AHC_DV_CMD(cmd) == FALSE) {
13144 +       if (AIC_DV_CMD(cmd) == FALSE) {
13145                 u_int new_status;
13146  
13147 -               switch (ahc_cmd_get_transaction_status(cmd)) {
13148 +               switch (aic_cmd_get_transaction_status(cmd)) {
13149                 case CAM_REQ_INPROG:
13150                 case CAM_REQ_CMP:
13151                 case CAM_SCSI_STATUS_ERROR:
13152 @@ -4454,7 +4485,17 @@
13153                         new_status = DID_PARITY;
13154                         break;
13155                 case CAM_CMD_TIMEOUT:
13156 -                       new_status = DID_TIME_OUT;
13157 +                       /*
13158 +                        *  Returning DID_TIME_OUT will 
13159 +                        *  wake up the error recovery
13160 +                        *  thread instead of doing the
13161 +                        *  command retry we desire. Since
13162 +                        *  we have already recovered the
13163 +                        *  command, returning DID_ERROR
13164 +                        *  will cause a retry up to the
13165 +                        *  retry limit for this command.
13166 +                        */
13167 +                       new_status = DID_ERROR;
13168                         break;
13169                 case CAM_UA_ABORT:
13170                 case CAM_REQ_CMP_ERR:
13171 @@ -4484,7 +4525,7 @@
13172                         if (cmd->retries > 0)
13173                                 cmd->retries--;
13174                         new_status = DID_OK;
13175 -                       ahc_cmd_set_scsi_status(cmd, SCSI_STATUS_CHECK_COND);
13176 +                       aic_cmd_set_scsi_status(cmd, SCSI_STATUS_CHECK_COND);
13177                         cmd->result |= (DRIVER_SENSE << 24);
13178                         memset(cmd->sense_buffer, 0,
13179                                sizeof(cmd->sense_buffer));
13180 @@ -4498,12 +4539,12 @@
13181                         break;
13182                 }
13183  
13184 -               ahc_cmd_set_transaction_status(cmd, new_status);
13185 +               aic_cmd_set_transaction_status(cmd, new_status);
13186         }
13187  
13188         completeq = &ahc->platform_data->completeq;
13189         list_cmd = TAILQ_FIRST(completeq);
13190 -       acmd = (struct ahc_cmd *)cmd;
13191 +       acmd = (struct aic_cmd *)cmd;
13192         while (list_cmd != NULL
13193             && acmd_scsi_cmd(list_cmd).serial_number
13194              < acmd_scsi_cmd(acmd).serial_number)
13195 @@ -4524,7 +4565,7 @@
13196         struct  ahc_transinfo *curr;
13197         struct  ahc_tmode_tstate *tstate;
13198         struct  ahc_syncrate *syncrate;
13199 -       struct  ahc_linux_device *dev;
13200 +       struct  aic_linux_device *dev;
13201         u_int   maxsync;
13202         u_int   width;
13203         u_int   period;
13204 @@ -4547,9 +4588,9 @@
13205         sid = (struct scsi_inquiry_data *)dev->target->inq_data;
13206         if (SID_QUAL(sid) == SID_QUAL_LU_CONNECTED) {
13207  
13208 -               dev->flags &= ~AHC_DEV_UNCONFIGURED;
13209 +               dev->flags &= ~AIC_DEV_UNCONFIGURED;
13210         } else {
13211 -               dev->flags |= AHC_DEV_UNCONFIGURED;
13212 +               dev->flags |= AIC_DEV_UNCONFIGURED;
13213                 return;
13214         }
13215  
13216 @@ -4626,82 +4667,38 @@
13217  static void
13218  ahc_linux_sem_timeout(u_long arg)
13219  {
13220 +       struct  scb *scb;
13221         struct  ahc_softc *ahc;
13222         u_long  s;
13223  
13224 -       ahc = (struct ahc_softc *)arg;
13225 -
13226 +       scb = (struct scb *)arg;
13227 +       ahc = scb->ahc_softc;
13228         ahc_lock(ahc, &s);
13229 -       if ((ahc->platform_data->flags & AHC_UP_EH_SEMAPHORE) != 0) {
13230 -               ahc->platform_data->flags &= ~AHC_UP_EH_SEMAPHORE;
13231 +       if ((scb->platform_data->flags & AIC_SCB_UP_EH_SEM) != 0) {
13232 +               scb->platform_data->flags &= ~AIC_SCB_UP_EH_SEM;
13233                 up(&ahc->platform_data->eh_sem);
13234         }
13235         ahc_unlock(ahc, &s);
13236  }
13237  
13238  static void
13239 -ahc_linux_freeze_simq(struct ahc_softc *ahc)
13240 -{
13241 -       ahc->platform_data->qfrozen++;
13242 -       if (ahc->platform_data->qfrozen == 1) {
13243 -               scsi_block_requests(ahc->platform_data->host);
13244 -
13245 -               /* XXX What about Twin channels? */
13246 -               ahc_platform_abort_scbs(ahc, CAM_TARGET_WILDCARD, ALL_CHANNELS,
13247 -                                       CAM_LUN_WILDCARD, SCB_LIST_NULL,
13248 -                                       ROLE_INITIATOR, CAM_REQUEUE_REQ);
13249 -       }
13250 -}
13251 -
13252 -static void
13253 -ahc_linux_release_simq(u_long arg)
13254 -{
13255 -       struct ahc_softc *ahc;
13256 -       u_long s;
13257 -       int    unblock_reqs;
13258 -
13259 -       ahc = (struct ahc_softc *)arg;
13260 -
13261 -       unblock_reqs = 0;
13262 -       ahc_lock(ahc, &s);
13263 -       if (ahc->platform_data->qfrozen > 0)
13264 -               ahc->platform_data->qfrozen--;
13265 -       if (ahc->platform_data->qfrozen == 0)
13266 -               unblock_reqs = 1;
13267 -       if (AHC_DV_SIMQ_FROZEN(ahc)
13268 -        && ((ahc->platform_data->flags & AHC_DV_WAIT_SIMQ_RELEASE) != 0)) {
13269 -               ahc->platform_data->flags &= ~AHC_DV_WAIT_SIMQ_RELEASE;
13270 -               up(&ahc->platform_data->dv_sem);
13271 -       }
13272 -       ahc_schedule_runq(ahc);
13273 -       ahc_unlock(ahc, &s);
13274 -       /*
13275 -        * There is still a race here.  The mid-layer
13276 -        * should keep its own freeze count and use
13277 -        * a bottom half handler to run the queues
13278 -        * so we can unblock with our own lock held.
13279 -        */
13280 -       if (unblock_reqs)
13281 -               scsi_unblock_requests(ahc->platform_data->host);
13282 -}
13283 -
13284 -static void
13285  ahc_linux_dev_timed_unfreeze(u_long arg)
13286  {
13287 -       struct ahc_linux_device *dev;
13288 +       struct aic_linux_device *dev;
13289         struct ahc_softc *ahc;
13290         u_long s;
13291  
13292 -       dev = (struct ahc_linux_device *)arg;
13293 -       ahc = dev->target->ahc;
13294 +       dev = (struct aic_linux_device *)arg;
13295 +       ahc = dev->target->softc;
13296         ahc_lock(ahc, &s);
13297 -       dev->flags &= ~AHC_DEV_TIMER_ACTIVE;
13298 +       dev->flags &= ~AIC_DEV_TIMER_ACTIVE;
13299         if (dev->qfrozen > 0)
13300                 dev->qfrozen--;
13301         if (dev->qfrozen == 0
13302 -        && (dev->flags & AHC_DEV_ON_RUN_LIST) == 0)
13303 +        && (dev->flags & AIC_DEV_ON_RUN_LIST) == 0)
13304                 ahc_linux_run_device_queue(ahc, dev);
13305 -       if (TAILQ_EMPTY(&dev->busyq)
13306 +       if ((dev->flags & AIC_DEV_UNCONFIGURED) != 0
13307 +        && TAILQ_EMPTY(&dev->busyq)
13308          && dev->active == 0)
13309                 ahc_linux_free_device(ahc, dev);
13310         ahc_unlock(ahc, &s);
13311 @@ -4711,9 +4708,9 @@
13312  ahc_linux_queue_recovery_cmd(Scsi_Cmnd *cmd, scb_flag flag)
13313  {
13314         struct ahc_softc *ahc;
13315 -       struct ahc_cmd *acmd;
13316 -       struct ahc_cmd *list_acmd;
13317 -       struct ahc_linux_device *dev;
13318 +       struct aic_cmd *acmd;
13319 +       struct aic_cmd *list_acmd;
13320 +       struct aic_linux_device *dev;
13321         struct scb *pending_scb;
13322         u_long s;
13323         u_int  saved_scbptr;
13324 @@ -4731,7 +4728,7 @@
13325         paused = FALSE;
13326         wait = FALSE;
13327         ahc = *(struct ahc_softc **)cmd->device->host->hostdata;
13328 -       acmd = (struct ahc_cmd *)cmd;
13329 +       acmd = (struct aic_cmd *)cmd;
13330  
13331         printf("%s:%d:%d:%d: Attempting to queue a%s message\n",
13332                ahc_name(ahc), cmd->device->channel,
13333 @@ -4793,13 +4790,24 @@
13334                 if (flag == SCB_ABORT) {
13335                         TAILQ_REMOVE(&dev->busyq, list_acmd, acmd_links.tqe);
13336                         cmd->result = DID_ABORT << 16;
13337 +                       /*
13338 +                        * The completion handler believes that
13339 +                        * commands without active timers running
13340 +                        * have lost the race of completing before
13341 +                        * their timer expires.  Since commands in our
13342 +                        * busy queues do not have timers running,
13343 +                        * appease the mid-layer by adding a timer
13344 +                        * now.  This timer will be immediately
13345 +                        * canceled by the midlayer.
13346 +                        */
13347 +                       scsi_add_timer(cmd, 60*HZ, aic_linux_midlayer_timeout);
13348                         ahc_linux_queue_cmd_complete(ahc, cmd);
13349                         retval = SUCCESS;
13350                         goto done;
13351                 }
13352         }
13353  
13354 -       if ((dev->flags & (AHC_DEV_Q_BASIC|AHC_DEV_Q_TAGGED)) == 0
13355 +       if ((dev->flags & (AIC_DEV_Q_BASIC|AIC_DEV_Q_TAGGED)) == 0
13356          && ahc_search_untagged_queues(ahc, cmd, cmd->device->id,
13357                                        cmd->device->channel + 'A',
13358                                        cmd->device->lun,
13359 @@ -5015,10 +5023,10 @@
13360                 struct timer_list timer;
13361                 int ret;
13362  
13363 -               ahc->platform_data->flags |= AHC_UP_EH_SEMAPHORE;
13364 +               pending_scb->platform_data->flags |= AIC_SCB_UP_EH_SEM;
13365                 spin_unlock_irq(&ahc->platform_data->spin_lock);
13366                 init_timer(&timer);
13367 -               timer.data = (u_long)ahc;
13368 +               timer.data = (u_long)pending_scb;
13369                 timer.expires = jiffies + (5 * HZ);
13370                 timer.function = ahc_linux_sem_timeout;
13371                 add_timer(&timer);
13372 @@ -5032,7 +5040,7 @@
13373                 }
13374                 spin_lock_irq(&ahc->platform_data->spin_lock);
13375         }
13376 -       ahc_schedule_runq(ahc);
13377 +       aic_schedule_runq(ahc);
13378         ahc_linux_run_complete_queue(ahc);
13379         ahc_midlayer_entrypoint_unlock(ahc, &s);
13380         return (retval);
13381 @@ -5041,7 +5049,8 @@
13382  void
13383  ahc_platform_dump_card_state(struct ahc_softc *ahc)
13384  {
13385 -       struct ahc_linux_device *dev;
13386 +       struct Scsi_Host *host;
13387 +       struct aic_linux_device *dev;
13388         int channel;
13389         int maxchannel;
13390         int target;
13391 @@ -5049,6 +5058,14 @@
13392         int lun;
13393         int i;
13394  
13395 +       host = ahc->platform_data->host;
13396 +       printf("%s: Host Status: Failed(%d) %s%s%s\n",
13397 +              ahc_name(ahc),
13398 +              host->host_failed,
13399 +              host->eh_active ? "eh_active " : "",
13400 +              host->host_blocked ? "host_blocked " : "",
13401 +              host->host_self_blocked ? "host_self_blocked " : "");
13402 +              
13403         maxchannel = (ahc->features & AHC_TWIN) ? 1 : 0;
13404         maxtarget = (ahc->features & AHC_WIDE) ? 15 : 7;
13405         for (channel = 0; channel <= maxchannel; channel++) {
13406 @@ -5056,7 +5073,7 @@
13407                 for (target = 0; target <=maxtarget; target++) {
13408  
13409                         for (lun = 0; lun < AHC_NUM_LUNS; lun++) {
13410 -                               struct ahc_cmd *acmd;
13411 +                               struct aic_cmd *acmd;
13412  
13413                                 dev = ahc_linux_get_device(ahc, channel, target,
13414                                                            lun, /*alloc*/FALSE);
13415 @@ -5098,20 +5115,18 @@
13416  ahc_linux_exit(void)
13417  {
13418         struct ahc_softc *ahc;
13419 -       u_long l;
13420  
13421         /*
13422 -        * Shutdown DV threads before going into the SCSI mid-layer.
13423 +        * Shutdown our threads before going into the SCSI mid-layer.
13424          * This avoids situations where the mid-layer locks the entire
13425          * kernel so that waiting for our DV threads to exit leads
13426          * to deadlock.
13427          */
13428 -       ahc_list_lock(&l);
13429         TAILQ_FOREACH(ahc, &ahc_tailq, links) {
13430  
13431                 ahc_linux_kill_dv_thread(ahc);
13432 +               ahc_terminate_recovery_thread(ahc);
13433         }
13434 -       ahc_list_unlock(&l);
13435  
13436  #if LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0)
13437         /*
13438 diff -urN linux-2.4.24.org/drivers/scsi/aic7xxx/aic7xxx_osm.h linux-2.4.24/drivers/scsi/aic7xxx/aic7xxx_osm.h
13439 --- linux-2.4.24.org/drivers/scsi/aic7xxx/aic7xxx_osm.h 2004-01-08 11:57:43.031001441 +0100
13440 +++ linux-2.4.24/drivers/scsi/aic7xxx/aic7xxx_osm.h     2003-12-23 00:31:43.000000000 +0100
13441 @@ -53,51 +53,22 @@
13442   * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
13443   * POSSIBILITY OF SUCH DAMAGES.
13444   *
13445 - * $Id$
13446 + * $Id$
13447   *
13448   */
13449  #ifndef _AIC7XXX_LINUX_H_
13450  #define _AIC7XXX_LINUX_H_
13451  
13452 -#include <linux/types.h>
13453 -#include <linux/blk.h>
13454 -#include <linux/blkdev.h>
13455 -#include <linux/delay.h>
13456 -#include <linux/ioport.h>
13457 -#include <linux/pci.h>
13458 -#include <linux/smp_lock.h>
13459  #include <linux/version.h>
13460 -#include <linux/module.h>
13461 -#include <asm/byteorder.h>
13462 -#include <asm/io.h>
13463  
13464  #ifndef KERNEL_VERSION
13465  #define KERNEL_VERSION(x,y,z) (((x)<<16)+((y)<<8)+(z))
13466  #endif
13467  
13468  #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,0)
13469 -#include <linux/interrupt.h> /* For tasklet support. */
13470  #include <linux/config.h>
13471 -#include <linux/slab.h>
13472 -#else
13473 -#include <linux/malloc.h>
13474  #endif
13475  
13476 -/* Core SCSI definitions */
13477 -#define AIC_LIB_PREFIX ahc
13478 -#include "scsi.h"
13479 -#include "hosts.h"
13480 -
13481 -/* Name space conflict with BSD queue macros */
13482 -#ifdef LIST_HEAD
13483 -#undef LIST_HEAD
13484 -#endif
13485 -
13486 -#include "cam.h"
13487 -#include "queue.h"
13488 -#include "scsi_message.h"
13489 -#include "aiclib.h"
13490 -
13491  /*********************************** Debugging ********************************/
13492  #ifdef CONFIG_AIC7XXX_DEBUG_ENABLE
13493  #ifdef CONFIG_AIC7XXX_DEBUG_MASK
13494 @@ -112,42 +83,18 @@
13495  /* No debugging code. */
13496  #endif
13497  
13498 -/************************* Forward Declarations *******************************/
13499 -struct ahc_softc;
13500 -typedef struct pci_dev *ahc_dev_softc_t;
13501 -typedef Scsi_Cmnd      *ahc_io_ctx_t;
13502 -
13503 -/******************************* Byte Order ***********************************/
13504 -#define ahc_htobe16(x) cpu_to_be16(x)
13505 -#define ahc_htobe32(x) cpu_to_be32(x)
13506 -#define ahc_htobe64(x) cpu_to_be64(x)
13507 -#define ahc_htole16(x) cpu_to_le16(x)
13508 -#define ahc_htole32(x) cpu_to_le32(x)
13509 -#define ahc_htole64(x) cpu_to_le64(x)
13510 -
13511 -#define ahc_be16toh(x) be16_to_cpu(x)
13512 -#define ahc_be32toh(x) be32_to_cpu(x)
13513 -#define ahc_be64toh(x) be64_to_cpu(x)
13514 -#define ahc_le16toh(x) le16_to_cpu(x)
13515 -#define ahc_le32toh(x) le32_to_cpu(x)
13516 -#define ahc_le64toh(x) le64_to_cpu(x)
13517 -
13518 -#ifndef LITTLE_ENDIAN
13519 -#define LITTLE_ENDIAN 1234
13520 -#endif
13521 -
13522 -#ifndef BIG_ENDIAN
13523 -#define BIG_ENDIAN 4321
13524 -#endif
13525 +/********************************** Includes **********************************/
13526 +/* Core SCSI definitions */
13527 +#define AIC_LIB_PREFIX ahc
13528 +#define AIC_CONST_PREFIX AHC
13529  
13530 -#ifndef BYTE_ORDER
13531 -#if defined(__BIG_ENDIAN)
13532 -#define BYTE_ORDER BIG_ENDIAN
13533 -#endif
13534 -#if defined(__LITTLE_ENDIAN)
13535 -#define BYTE_ORDER LITTLE_ENDIAN
13536 +#ifdef CONFIG_AIC7XXX_REG_PRETTY_PRINT
13537 +#define AIC_DEBUG_REGISTERS 1
13538 +#else
13539 +#define AIC_DEBUG_REGISTERS 0
13540  #endif
13541 -#endif /* BYTE_ORDER */
13542 +#define        AIC_CORE_INCLUDE "aic7xxx.h"
13543 +#include "aiclib.h"
13544  
13545  /************************* Configuration Data *********************************/
13546  extern u_int aic7xxx_no_probe;
13547 @@ -155,142 +102,9 @@
13548  extern int aic7xxx_detect_complete;
13549  extern Scsi_Host_Template aic7xxx_driver_template;
13550  
13551 -/***************************** Bus Space/DMA **********************************/
13552 -
13553 -#if LINUX_VERSION_CODE > KERNEL_VERSION(2,2,17)
13554 -typedef dma_addr_t bus_addr_t;
13555 -#else
13556 -typedef uint32_t bus_addr_t;
13557 -#endif
13558 -typedef uint32_t bus_size_t;
13559 -
13560 -typedef enum {
13561 -       BUS_SPACE_MEMIO,
13562 -       BUS_SPACE_PIO
13563 -} bus_space_tag_t;
13564 -
13565 -typedef union {
13566 -       u_long            ioport;
13567 -       volatile uint8_t *maddr;
13568 -} bus_space_handle_t;
13569 -
13570 -typedef struct bus_dma_segment
13571 -{
13572 -       bus_addr_t      ds_addr;
13573 -       bus_size_t      ds_len;
13574 -} bus_dma_segment_t;
13575 -
13576 -struct ahc_linux_dma_tag
13577 -{
13578 -       bus_size_t      alignment;
13579 -       bus_size_t      boundary;
13580 -       bus_size_t      maxsize;
13581 -};
13582 -typedef struct ahc_linux_dma_tag* bus_dma_tag_t;
13583 -
13584 -struct ahc_linux_dmamap
13585 -{
13586 -       bus_addr_t      bus_addr;
13587 -};
13588 -typedef struct ahc_linux_dmamap* bus_dmamap_t;
13589 -
13590 -typedef int bus_dma_filter_t(void*, bus_addr_t);
13591 -typedef void bus_dmamap_callback_t(void *, bus_dma_segment_t *, int, int);
13592 -
13593 -#define BUS_DMA_WAITOK         0x0
13594 -#define BUS_DMA_NOWAIT         0x1
13595 -#define BUS_DMA_ALLOCNOW       0x2
13596 -#define BUS_DMA_LOAD_SEGS      0x4     /*
13597 -                                        * Argument is an S/G list not
13598 -                                        * a single buffer.
13599 -                                        */
13600 -
13601 -#define BUS_SPACE_MAXADDR      0xFFFFFFFF
13602 -#define BUS_SPACE_MAXADDR_32BIT        0xFFFFFFFF
13603 -#define BUS_SPACE_MAXSIZE_32BIT        0xFFFFFFFF
13604 -
13605 -int    ahc_dma_tag_create(struct ahc_softc *, bus_dma_tag_t /*parent*/,
13606 -                          bus_size_t /*alignment*/, bus_size_t /*boundary*/,
13607 -                          bus_addr_t /*lowaddr*/, bus_addr_t /*highaddr*/,
13608 -                          bus_dma_filter_t*/*filter*/, void */*filterarg*/,
13609 -                          bus_size_t /*maxsize*/, int /*nsegments*/,
13610 -                          bus_size_t /*maxsegsz*/, int /*flags*/,
13611 -                          bus_dma_tag_t */*dma_tagp*/);
13612 -
13613 -void   ahc_dma_tag_destroy(struct ahc_softc *, bus_dma_tag_t /*tag*/);
13614 -
13615 -int    ahc_dmamem_alloc(struct ahc_softc *, bus_dma_tag_t /*dmat*/,
13616 -                        void** /*vaddr*/, int /*flags*/,
13617 -                        bus_dmamap_t* /*mapp*/);
13618 -
13619 -void   ahc_dmamem_free(struct ahc_softc *, bus_dma_tag_t /*dmat*/,
13620 -                       void* /*vaddr*/, bus_dmamap_t /*map*/);
13621 -
13622 -void   ahc_dmamap_destroy(struct ahc_softc *, bus_dma_tag_t /*tag*/,
13623 -                          bus_dmamap_t /*map*/);
13624 -
13625 -int    ahc_dmamap_load(struct ahc_softc *ahc, bus_dma_tag_t /*dmat*/,
13626 -                       bus_dmamap_t /*map*/, void * /*buf*/,
13627 -                       bus_size_t /*buflen*/, bus_dmamap_callback_t *,
13628 -                       void */*callback_arg*/, int /*flags*/);
13629 -
13630 -int    ahc_dmamap_unload(struct ahc_softc *, bus_dma_tag_t, bus_dmamap_t);
13631 -
13632 -/*
13633 - * Operations performed by ahc_dmamap_sync().
13634 - */
13635 -#define BUS_DMASYNC_PREREAD    0x01    /* pre-read synchronization */
13636 -#define BUS_DMASYNC_POSTREAD   0x02    /* post-read synchronization */
13637 -#define BUS_DMASYNC_PREWRITE   0x04    /* pre-write synchronization */
13638 -#define BUS_DMASYNC_POSTWRITE  0x08    /* post-write synchronization */
13639 -
13640 -/*
13641 - * XXX
13642 - * ahc_dmamap_sync is only used on buffers allocated with
13643 - * the pci_alloc_consistent() API.  Although I'm not sure how
13644 - * this works on architectures with a write buffer, Linux does
13645 - * not have an API to sync "coherent" memory.  Perhaps we need
13646 - * to do an mb()?
13647 - */
13648 -#define ahc_dmamap_sync(ahc, dma_tag, dmamap, offset, len, op)
13649 -
13650 -/************************** Timer DataStructures ******************************/
13651 -typedef struct timer_list ahc_timer_t;
13652 -
13653 -/********************************** Includes **********************************/
13654 -#ifdef CONFIG_AIC7XXX_REG_PRETTY_PRINT
13655 -#define AIC_DEBUG_REGISTERS 1
13656 -#else
13657 -#define AIC_DEBUG_REGISTERS 0
13658 -#endif
13659 -#include "aic7xxx.h"
13660 -
13661 -/***************************** Timer Facilities *******************************/
13662 -#define ahc_timer_init init_timer
13663 -#define ahc_timer_stop del_timer_sync
13664 -typedef void ahc_linux_callback_t (u_long);  
13665 -static __inline void ahc_timer_reset(ahc_timer_t *timer, int usec,
13666 -                                    ahc_callback_t *func, void *arg);
13667 -static __inline void ahc_scb_timer_reset(struct scb *scb, u_int usec);
13668 -
13669 -static __inline void
13670 -ahc_timer_reset(ahc_timer_t *timer, int usec, ahc_callback_t *func, void *arg)
13671 -{
13672 -       struct ahc_softc *ahc;
13673 -
13674 -       ahc = (struct ahc_softc *)arg;
13675 -       del_timer(timer);
13676 -       timer->data = (u_long)arg;
13677 -       timer->expires = jiffies + (usec * HZ)/1000000;
13678 -       timer->function = (ahc_linux_callback_t*)func;
13679 -       add_timer(timer);
13680 -}
13681 -
13682 -static __inline void
13683 -ahc_scb_timer_reset(struct scb *scb, u_int usec)
13684 -{
13685 -       mod_timer(&scb->io_ctx->eh_timeout, jiffies + (usec * HZ)/1000000);
13686 -}
13687 +/***************************** Domain Validation ******************************/
13688 +void ahc_linux_dv_complete(Scsi_Cmnd *cmd);
13689 +void ahc_linux_dv_timeout(struct scsi_cmnd *cmd);
13690  
13691  /***************************** SMP support ************************************/
13692  #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,3,17)
13693 @@ -305,187 +119,7 @@
13694  #define AHC_SCSI_HAS_HOST_LOCK 0
13695  #endif
13696  
13697 -#define AIC7XXX_DRIVER_VERSION "6.2.36"
13698 -
13699 -/**************************** Front End Queues ********************************/
13700 -/*
13701 - * Data structure used to cast the Linux struct scsi_cmnd to something
13702 - * that allows us to use the queue macros.  The linux structure has
13703 - * plenty of space to hold the links fields as required by the queue
13704 - * macros, but the queue macors require them to have the correct type.
13705 - */
13706 -struct ahc_cmd_internal {
13707 -       /* Area owned by the Linux scsi layer. */
13708 -       uint8_t private[offsetof(struct scsi_cmnd, SCp.Status)];
13709 -       union {
13710 -               STAILQ_ENTRY(ahc_cmd)   ste;
13711 -               LIST_ENTRY(ahc_cmd)     le;
13712 -               TAILQ_ENTRY(ahc_cmd)    tqe;
13713 -       } links;
13714 -       uint32_t                        end;
13715 -};
13716 -
13717 -struct ahc_cmd {
13718 -       union {
13719 -               struct ahc_cmd_internal icmd;
13720 -               struct scsi_cmnd        scsi_cmd;
13721 -       } un;
13722 -};
13723 -
13724 -#define acmd_icmd(cmd) ((cmd)->un.icmd)
13725 -#define acmd_scsi_cmd(cmd) ((cmd)->un.scsi_cmd)
13726 -#define acmd_links un.icmd.links
13727 -
13728 -/*************************** Device Data Structures ***************************/
13729 -/*
13730 - * A per probed device structure used to deal with some error recovery
13731 - * scenarios that the Linux mid-layer code just doesn't know how to
13732 - * handle.  The structure allocated for a device only becomes persistent
13733 - * after a successfully completed inquiry command to the target when
13734 - * that inquiry data indicates a lun is present.
13735 - */
13736 -TAILQ_HEAD(ahc_busyq, ahc_cmd);
13737 -typedef enum {
13738 -       AHC_DEV_UNCONFIGURED     = 0x01,
13739 -       AHC_DEV_FREEZE_TIL_EMPTY = 0x02, /* Freeze queue until active == 0 */
13740 -       AHC_DEV_TIMER_ACTIVE     = 0x04, /* Our timer is active */
13741 -       AHC_DEV_ON_RUN_LIST      = 0x08, /* Queued to be run later */
13742 -       AHC_DEV_Q_BASIC          = 0x10, /* Allow basic device queuing */
13743 -       AHC_DEV_Q_TAGGED         = 0x20, /* Allow full SCSI2 command queueing */
13744 -       AHC_DEV_PERIODIC_OTAG    = 0x40, /* Send OTAG to prevent starvation */
13745 -       AHC_DEV_SLAVE_CONFIGURED = 0x80  /* slave_configure() has been called */
13746 -} ahc_linux_dev_flags;
13747 -
13748 -struct ahc_linux_target;
13749 -struct ahc_linux_device {
13750 -       TAILQ_ENTRY(ahc_linux_device) links;
13751 -       struct          ahc_busyq busyq;
13752 -
13753 -       /*
13754 -        * The number of transactions currently
13755 -        * queued to the device.
13756 -        */
13757 -       int                     active;
13758 -
13759 -       /*
13760 -        * The currently allowed number of 
13761 -        * transactions that can be queued to
13762 -        * the device.  Must be signed for
13763 -        * conversion from tagged to untagged
13764 -        * mode where the device may have more
13765 -        * than one outstanding active transaction.
13766 -        */
13767 -       int                     openings;
13768 -
13769 -       /*
13770 -        * A positive count indicates that this
13771 -        * device's queue is halted.
13772 -        */
13773 -       u_int                   qfrozen;
13774 -       
13775 -       /*
13776 -        * Cumulative command counter.
13777 -        */
13778 -       u_long                  commands_issued;
13779 -
13780 -       /*
13781 -        * The number of tagged transactions when
13782 -        * running at our current opening level
13783 -        * that have been successfully received by
13784 -        * this device since the last QUEUE FULL.
13785 -        */
13786 -       u_int                   tag_success_count;
13787 -#define AHC_TAG_SUCCESS_INTERVAL 50
13788 -
13789 -       ahc_linux_dev_flags     flags;
13790 -
13791 -       /*
13792 -        * Per device timer.
13793 -        */
13794 -       struct timer_list       timer;
13795 -
13796 -       /*
13797 -        * The high limit for the tags variable.
13798 -        */
13799 -       u_int                   maxtags;
13800 -
13801 -       /*
13802 -        * The computed number of tags outstanding
13803 -        * at the time of the last QUEUE FULL event.
13804 -        */
13805 -       u_int                   tags_on_last_queuefull;
13806 -
13807 -       /*
13808 -        * How many times we have seen a queue full
13809 -        * with the same number of tags.  This is used
13810 -        * to stop our adaptive queue depth algorithm
13811 -        * on devices with a fixed number of tags.
13812 -        */
13813 -       u_int                   last_queuefull_same_count;
13814 -#define AHC_LOCK_TAGS_COUNT 50
13815 -
13816 -       /*
13817 -        * How many transactions have been queued
13818 -        * without the device going idle.  We use
13819 -        * this statistic to determine when to issue
13820 -        * an ordered tag to prevent transaction
13821 -        * starvation.  This statistic is only updated
13822 -        * if the AHC_DEV_PERIODIC_OTAG flag is set
13823 -        * on this device.
13824 -        */
13825 -       u_int                   commands_since_idle_or_otag;
13826 -#define AHC_OTAG_THRESH        500
13827 -
13828 -       int                     lun;
13829 -       Scsi_Device            *scsi_device;
13830 -       struct                  ahc_linux_target *target;
13831 -};
13832 -
13833 -typedef enum {
13834 -       AHC_DV_REQUIRED          = 0x01,
13835 -       AHC_INQ_VALID            = 0x02,
13836 -       AHC_BASIC_DV             = 0x04,
13837 -       AHC_ENHANCED_DV          = 0x08
13838 -} ahc_linux_targ_flags;
13839 -
13840 -/* DV States */
13841 -typedef enum {
13842 -       AHC_DV_STATE_EXIT = 0,
13843 -       AHC_DV_STATE_INQ_SHORT_ASYNC,
13844 -       AHC_DV_STATE_INQ_ASYNC,
13845 -       AHC_DV_STATE_INQ_ASYNC_VERIFY,
13846 -       AHC_DV_STATE_TUR,
13847 -       AHC_DV_STATE_REBD,
13848 -       AHC_DV_STATE_INQ_VERIFY,
13849 -       AHC_DV_STATE_WEB,
13850 -       AHC_DV_STATE_REB,
13851 -       AHC_DV_STATE_SU,
13852 -       AHC_DV_STATE_BUSY
13853 -} ahc_dv_state;
13854 -
13855 -struct ahc_linux_target {
13856 -       struct ahc_linux_device  *devices[AHC_NUM_LUNS];
13857 -       int                       channel;
13858 -       int                       target;
13859 -       int                       refcount;
13860 -       struct ahc_transinfo      last_tinfo;
13861 -       struct ahc_softc         *ahc;
13862 -       ahc_linux_targ_flags      flags;
13863 -       struct scsi_inquiry_data *inq_data;
13864 -       /*
13865 -        * The next "fallback" period to use for narrow/wide transfers.
13866 -        */
13867 -       uint8_t                   dv_next_narrow_period;
13868 -       uint8_t                   dv_next_wide_period;
13869 -       uint8_t                   dv_max_width;
13870 -       uint8_t                   dv_max_ppr_options;
13871 -       uint8_t                   dv_last_ppr_options;
13872 -       u_int                     dv_echo_size;
13873 -       ahc_dv_state              dv_state;
13874 -       u_int                     dv_state_retry;
13875 -       char                     *dv_buffer;
13876 -       char                     *dv_buffer1;
13877 -};
13878 +#define AIC7XXX_DRIVER_VERSION "6.3.4"
13879  
13880  /********************* Definitions Required by the Core ***********************/
13881  /*
13882 @@ -507,120 +141,39 @@
13883  #define        AHC_NSEG 128
13884  #endif
13885  
13886 -/*
13887 - * Per-SCB OSM storage.
13888 - */
13889 -typedef enum {
13890 -       AHC_UP_EH_SEMAPHORE = 0x1
13891 -} ahc_linux_scb_flags;
13892 -
13893 -struct scb_platform_data {
13894 -       struct ahc_linux_device *dev;
13895 -       bus_addr_t               buf_busaddr;
13896 -       uint32_t                 xfer_len;
13897 -#if LINUX_VERSION_CODE < KERNEL_VERSION(2,3,0)
13898 -       uint32_t                 resid;         /* Transfer residual */
13899 -#endif
13900 -       uint32_t                 sense_resid;   /* Auto-Sense residual */
13901 -       ahc_linux_scb_flags      flags;
13902 -};
13903 -
13904 -/*
13905 - * Define a structure used for each host adapter.  All members are
13906 - * aligned on a boundary >= the size of the member to honor the
13907 - * alignment restrictions of the various platforms supported by
13908 - * this driver.
13909 - */
13910 -typedef enum {
13911 -       AHC_DV_WAIT_SIMQ_EMPTY   = 0x01,
13912 -       AHC_DV_WAIT_SIMQ_RELEASE = 0x02,
13913 -       AHC_DV_ACTIVE            = 0x04,
13914 -       AHC_DV_SHUTDOWN          = 0x08,
13915 -       AHC_RUN_CMPLT_Q_TIMER    = 0x10
13916 -} ahc_linux_softc_flags;
13917 -
13918 -TAILQ_HEAD(ahc_completeq, ahc_cmd);
13919 -
13920 -struct ahc_platform_data {
13921 -       /*
13922 -        * Fields accessed from interrupt context.
13923 -        */
13924 -       struct ahc_linux_target *targets[AHC_NUM_TARGETS]; 
13925 -       TAILQ_HEAD(, ahc_linux_device) device_runq;
13926 -       struct ahc_completeq     completeq;
13927 -
13928 -       spinlock_t               spin_lock;
13929 -#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,0)
13930 -       struct tasklet_struct    runq_tasklet;
13931 -#endif
13932 -       u_int                    qfrozen;
13933 -       pid_t                    dv_pid;
13934 -       struct timer_list        completeq_timer;
13935 -       struct timer_list        reset_timer;
13936 -       struct semaphore         eh_sem;
13937 -       struct semaphore         dv_sem;
13938 -       struct semaphore         dv_cmd_sem;    /* XXX This needs to be in
13939 -                                                * the target struct
13940 -                                                */
13941 -       struct scsi_device      *dv_scsi_dev;
13942 -       struct Scsi_Host        *host;          /* pointer to scsi host */
13943 -#define AHC_LINUX_NOIRQ        ((uint32_t)~0)
13944 -       uint32_t                 irq;           /* IRQ for this adapter */
13945 -       uint32_t                 bios_address;
13946 -       uint32_t                 mem_busaddr;   /* Mem Base Addr */
13947 -       bus_addr_t               hw_dma_mask;
13948 -       ahc_linux_softc_flags    flags;
13949 -};
13950 -
13951 -/************************** OS Utility Wrappers *******************************/
13952 -#define printf printk
13953 -#define M_NOWAIT GFP_ATOMIC
13954 -#define M_WAITOK 0
13955 -#define malloc(size, type, flags) kmalloc(size, flags)
13956 -#define free(ptr, type) kfree(ptr)
13957 -
13958 -static __inline void ahc_delay(long);
13959 -static __inline void
13960 -ahc_delay(long usec)
13961 -{
13962 -       /*
13963 -        * udelay on Linux can have problems for
13964 -        * multi-millisecond waits.  Wait at most
13965 -        * 1024us per call.
13966 -        */
13967 -       while (usec > 0) {
13968 -               udelay(usec % 1024);
13969 -               usec -= 1024;
13970 -       }
13971 -}
13972 -
13973 +/************************** Error Recovery ************************************/
13974 +static __inline void   ahc_wakeup_recovery_thread(struct ahc_softc *ahc); 
13975 +  
13976 +static __inline void
13977 +ahc_wakeup_recovery_thread(struct ahc_softc *ahc)
13978 +{ 
13979 +       up(&ahc->platform_data->recovery_sem);
13980 +}
13981
13982 +int                    ahc_spawn_recovery_thread(struct ahc_softc *ahc);
13983 +void                   ahc_terminate_recovery_thread(struct ahc_softc *ahc);
13984 +void                   ahc_set_recoveryscb(struct ahc_softc *ahc,
13985 +                                           struct scb *scb);
13986  
13987  /***************************** Low Level I/O **********************************/
13988 -#if defined(__powerpc__) || defined(__i386__) || defined(__ia64__)
13989 -#define MMAPIO
13990 -#endif
13991 -
13992  static __inline uint8_t ahc_inb(struct ahc_softc * ahc, long port);
13993  static __inline void ahc_outb(struct ahc_softc * ahc, long port, uint8_t val);
13994  static __inline void ahc_outsb(struct ahc_softc * ahc, long port,
13995                                uint8_t *, int count);
13996  static __inline void ahc_insb(struct ahc_softc * ahc, long port,
13997                                uint8_t *, int count);
13998 +static __inline void ahc_flush_device_writes(struct ahc_softc *);
13999  
14000  static __inline uint8_t
14001  ahc_inb(struct ahc_softc * ahc, long port)
14002  {
14003         uint8_t x;
14004 -#ifdef MMAPIO
14005  
14006         if (ahc->tag == BUS_SPACE_MEMIO) {
14007                 x = readb(ahc->bsh.maddr + port);
14008         } else {
14009                 x = inb(ahc->bsh.ioport + port);
14010         }
14011 -#else
14012 -       x = inb(ahc->bsh.ioport + port);
14013 -#endif
14014         mb();
14015         return (x);
14016  }
14017 @@ -628,15 +181,11 @@
14018  static __inline void
14019  ahc_outb(struct ahc_softc * ahc, long port, uint8_t val)
14020  {
14021 -#ifdef MMAPIO
14022         if (ahc->tag == BUS_SPACE_MEMIO) {
14023                 writeb(val, ahc->bsh.maddr + port);
14024         } else {
14025                 outb(val, ahc->bsh.ioport + port);
14026         }
14027 -#else
14028 -       outb(val, ahc->bsh.ioport + port);
14029 -#endif
14030         mb();
14031  }
14032  
14033 @@ -668,6 +217,13 @@
14034                 *array++ = ahc_inb(ahc, port);
14035  }
14036  
14037 +static __inline void
14038 +ahc_flush_device_writes(struct ahc_softc *ahc)
14039 +{
14040 +       /* XXX Is this sufficient for all architectures??? */
14041 +       ahc_inb(ahc, INTSTAT);
14042 +}
14043 +
14044  /**************************** Initialization **********************************/
14045  int            ahc_linux_register_host(struct ahc_softc *,
14046                                         Scsi_Host_Template *);
14047 @@ -796,54 +352,10 @@
14048  }
14049  
14050  /******************************* PCI Definitions ******************************/
14051 -/*
14052 - * PCIM_xxx: mask to locate subfield in register
14053 - * PCIR_xxx: config register offset
14054 - * PCIC_xxx: device class
14055 - * PCIS_xxx: device subclass
14056 - * PCIP_xxx: device programming interface
14057 - * PCIV_xxx: PCI vendor ID (only required to fixup ancient devices)
14058 - * PCID_xxx: device ID
14059 - */
14060 -#define PCIR_DEVVENDOR         0x00
14061 -#define PCIR_VENDOR            0x00
14062 -#define PCIR_DEVICE            0x02
14063 -#define PCIR_COMMAND           0x04
14064 -#define PCIM_CMD_PORTEN                0x0001
14065 -#define PCIM_CMD_MEMEN         0x0002
14066 -#define PCIM_CMD_BUSMASTEREN   0x0004
14067 -#define PCIM_CMD_MWRICEN       0x0010
14068 -#define PCIM_CMD_PERRESPEN     0x0040
14069 -#define        PCIM_CMD_SERRESPEN      0x0100
14070 -#define PCIR_STATUS            0x06
14071 -#define PCIR_REVID             0x08
14072 -#define PCIR_PROGIF            0x09
14073 -#define PCIR_SUBCLASS          0x0a
14074 -#define PCIR_CLASS             0x0b
14075 -#define PCIR_CACHELNSZ         0x0c
14076 -#define PCIR_LATTIMER          0x0d
14077 -#define PCIR_HEADERTYPE                0x0e
14078 -#define PCIM_MFDEV             0x80
14079 -#define PCIR_BIST              0x0f
14080 -#define PCIR_CAP_PTR           0x34
14081 -
14082 -/* config registers for header type 0 devices */
14083 -#define PCIR_MAPS      0x10
14084 -#define PCIR_SUBVEND_0 0x2c
14085 -#define PCIR_SUBDEV_0  0x2e
14086 -
14087  #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,0)
14088  extern struct pci_driver aic7xxx_pci_driver;
14089  #endif
14090  
14091 -typedef enum
14092 -{
14093 -       AHC_POWER_STATE_D0,
14094 -       AHC_POWER_STATE_D1,
14095 -       AHC_POWER_STATE_D2,
14096 -       AHC_POWER_STATE_D3
14097 -} ahc_power_state;
14098 -
14099  /**************************** VL/EISA Routines ********************************/
14100  #if (LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0) \
14101    && (defined(__i386__) || defined(__alpha__)) \
14102 @@ -862,118 +374,12 @@
14103  
14104  /******************************* PCI Routines *********************************/
14105  #ifdef CONFIG_PCI
14106 -void                    ahc_power_state_change(struct ahc_softc *ahc,
14107 -                                               ahc_power_state new_state);
14108  int                     ahc_linux_pci_init(void);
14109  void                    ahc_linux_pci_exit(void);
14110  int                     ahc_pci_map_registers(struct ahc_softc *ahc);
14111  int                     ahc_pci_map_int(struct ahc_softc *ahc);
14112 +#endif 
14113  
14114 -static __inline uint32_t ahc_pci_read_config(ahc_dev_softc_t pci,
14115 -                                            int reg, int width);
14116 -
14117 -static __inline uint32_t
14118 -ahc_pci_read_config(ahc_dev_softc_t pci, int reg, int width)
14119 -{
14120 -       switch (width) {
14121 -       case 1:
14122 -       {
14123 -               uint8_t retval;
14124 -
14125 -               pci_read_config_byte(pci, reg, &retval);
14126 -               return (retval);
14127 -       }
14128 -       case 2:
14129 -       {
14130 -               uint16_t retval;
14131 -               pci_read_config_word(pci, reg, &retval);
14132 -               return (retval);
14133 -       }
14134 -       case 4:
14135 -       {
14136 -               uint32_t retval;
14137 -               pci_read_config_dword(pci, reg, &retval);
14138 -               return (retval);
14139 -       }
14140 -       default:
14141 -               panic("ahc_pci_read_config: Read size too big");
14142 -               /* NOTREACHED */
14143 -               return (0);
14144 -       }
14145 -}
14146 -
14147 -static __inline void ahc_pci_write_config(ahc_dev_softc_t pci,
14148 -                                         int reg, uint32_t value,
14149 -                                         int width);
14150 -
14151 -static __inline void
14152 -ahc_pci_write_config(ahc_dev_softc_t pci, int reg, uint32_t value, int width)
14153 -{
14154 -       switch (width) {
14155 -       case 1:
14156 -               pci_write_config_byte(pci, reg, value);
14157 -               break;
14158 -       case 2:
14159 -               pci_write_config_word(pci, reg, value);
14160 -               break;
14161 -       case 4:
14162 -               pci_write_config_dword(pci, reg, value);
14163 -               break;
14164 -       default:
14165 -               panic("ahc_pci_write_config: Write size too big");
14166 -               /* NOTREACHED */
14167 -       }
14168 -}
14169 -
14170 -static __inline int ahc_get_pci_function(ahc_dev_softc_t);
14171 -static __inline int
14172 -ahc_get_pci_function(ahc_dev_softc_t pci)
14173 -{
14174 -       return (PCI_FUNC(pci->devfn));
14175 -}
14176 -
14177 -static __inline int ahc_get_pci_slot(ahc_dev_softc_t);
14178 -static __inline int
14179 -ahc_get_pci_slot(ahc_dev_softc_t pci)
14180 -{
14181 -       return (PCI_SLOT(pci->devfn));
14182 -}
14183 -
14184 -static __inline int ahc_get_pci_bus(ahc_dev_softc_t);
14185 -static __inline int
14186 -ahc_get_pci_bus(ahc_dev_softc_t pci)
14187 -{
14188 -       return (pci->bus->number);
14189 -}
14190 -#endif
14191 -
14192 -static __inline void ahc_flush_device_writes(struct ahc_softc *);
14193 -static __inline void
14194 -ahc_flush_device_writes(struct ahc_softc *ahc)
14195 -{
14196 -       /* XXX Is this sufficient for all architectures??? */
14197 -       ahc_inb(ahc, INTSTAT);
14198 -}
14199 -
14200 -#if LINUX_VERSION_CODE <= KERNEL_VERSION(2,3,0)
14201 -#define pci_map_sg(pdev, sg_list, nseg, direction) (nseg)
14202 -#define pci_unmap_sg(pdev, sg_list, nseg, direction)
14203 -#define sg_dma_address(sg) (VIRT_TO_BUS((sg)->address))
14204 -#define sg_dma_len(sg) ((sg)->length)
14205 -#define pci_map_single(pdev, buffer, bufflen, direction) \
14206 -       (VIRT_TO_BUS(buffer))
14207 -#define pci_unmap_single(pdev, buffer, buflen, direction)
14208 -#endif
14209 -
14210 -#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,3)
14211 -#define ahc_pci_set_dma_mask pci_set_dma_mask
14212 -#else
14213 -/*
14214 - * Always "return" 0 for success.
14215 - */
14216 -#define ahc_pci_set_dma_mask(dev_softc, mask)                          \
14217 -       (((dev_softc)->dma_mask = mask) && 0)
14218 -#endif
14219  /**************************** Proc FS Support *********************************/
14220  #if LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0)
14221  int    ahc_linux_proc_info(char *, char **, off_t, int, int, int);
14222 @@ -989,194 +395,9 @@
14223          && (ahc)->platform_data->qfrozen == 1)
14224  
14225  /*********************** Transaction Access Wrappers *************************/
14226 -static __inline void ahc_cmd_set_transaction_status(Scsi_Cmnd *, uint32_t);
14227 -static __inline void ahc_set_transaction_status(struct scb *, uint32_t);
14228 -static __inline void ahc_cmd_set_scsi_status(Scsi_Cmnd *, uint32_t);
14229 -static __inline void ahc_set_scsi_status(struct scb *, uint32_t);
14230 -static __inline uint32_t ahc_cmd_get_transaction_status(Scsi_Cmnd *cmd);
14231 -static __inline uint32_t ahc_get_transaction_status(struct scb *);
14232 -static __inline uint32_t ahc_cmd_get_scsi_status(Scsi_Cmnd *cmd);
14233 -static __inline uint32_t ahc_get_scsi_status(struct scb *);
14234 -static __inline void ahc_set_transaction_tag(struct scb *, int, u_int);
14235 -static __inline u_long ahc_get_transfer_length(struct scb *);
14236 -static __inline int ahc_get_transfer_dir(struct scb *);
14237 -static __inline void ahc_set_residual(struct scb *, u_long);
14238 -static __inline void ahc_set_sense_residual(struct scb *scb, u_long resid);
14239 -static __inline u_long ahc_get_residual(struct scb *);
14240 -static __inline u_long ahc_get_sense_residual(struct scb *);
14241 -static __inline int ahc_perform_autosense(struct scb *);
14242 -static __inline uint32_t ahc_get_sense_bufsize(struct ahc_softc *,
14243 -                                              struct scb *);
14244 -static __inline void ahc_notify_xfer_settings_change(struct ahc_softc *,
14245 -                                                    struct ahc_devinfo *);
14246 -static __inline void ahc_platform_scb_free(struct ahc_softc *ahc,
14247 -                                          struct scb *scb);
14248 -static __inline void ahc_freeze_scb(struct scb *scb);
14249 -
14250 -static __inline
14251 -void ahc_cmd_set_transaction_status(Scsi_Cmnd *cmd, uint32_t status)
14252 -{
14253 -       cmd->result &= ~(CAM_STATUS_MASK << 16);
14254 -       cmd->result |= status << 16;
14255 -}
14256 -
14257 -static __inline
14258 -void ahc_set_transaction_status(struct scb *scb, uint32_t status)
14259 -{
14260 -       ahc_cmd_set_transaction_status(scb->io_ctx,status);
14261 -}
14262 -
14263 -static __inline
14264 -void ahc_cmd_set_scsi_status(Scsi_Cmnd *cmd, uint32_t status)
14265 -{
14266 -       cmd->result &= ~0xFFFF;
14267 -       cmd->result |= status;
14268 -}
14269 -
14270 -static __inline
14271 -void ahc_set_scsi_status(struct scb *scb, uint32_t status)
14272 -{
14273 -       ahc_cmd_set_scsi_status(scb->io_ctx, status);
14274 -}
14275 -
14276 -static __inline
14277 -uint32_t ahc_cmd_get_transaction_status(Scsi_Cmnd *cmd)
14278 -{
14279 -       return ((cmd->result >> 16) & CAM_STATUS_MASK);
14280 -}
14281 -
14282 -static __inline
14283 -uint32_t ahc_get_transaction_status(struct scb *scb)
14284 -{
14285 -       return (ahc_cmd_get_transaction_status(scb->io_ctx));
14286 -}
14287 -
14288 -static __inline
14289 -uint32_t ahc_cmd_get_scsi_status(Scsi_Cmnd *cmd)
14290 -{
14291 -       return (cmd->result & 0xFFFF);
14292 -}
14293 -
14294 -static __inline
14295 -uint32_t ahc_get_scsi_status(struct scb *scb)
14296 -{
14297 -       return (ahc_cmd_get_scsi_status(scb->io_ctx));
14298 -}
14299 -
14300 -static __inline
14301 -void ahc_set_transaction_tag(struct scb *scb, int enabled, u_int type)
14302 -{
14303 -       /*
14304 -        * Nothing to do for linux as the incoming transaction
14305 -        * has no concept of tag/non tagged, etc.
14306 -        */
14307 -}
14308 -
14309 -static __inline
14310 -u_long ahc_get_transfer_length(struct scb *scb)
14311 -{
14312 -       return (scb->platform_data->xfer_len);
14313 -}
14314 -
14315 -static __inline
14316 -int ahc_get_transfer_dir(struct scb *scb)
14317 -{
14318 -#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,3,40)
14319 -       return (scb->io_ctx->sc_data_direction);
14320 -#else
14321 -       if (scb->io_ctx->bufflen == 0)
14322 -               return (CAM_DIR_NONE);
14323 -
14324 -       switch(scb->io_ctx->cmnd[0]) {
14325 -       case 0x08:  /* READ(6)  */
14326 -       case 0x28:  /* READ(10) */
14327 -       case 0xA8:  /* READ(12) */
14328 -               return (CAM_DIR_IN);
14329 -        case 0x0A:  /* WRITE(6)  */
14330 -        case 0x2A:  /* WRITE(10) */
14331 -        case 0xAA:  /* WRITE(12) */
14332 -               return (CAM_DIR_OUT);
14333 -        default:
14334 -               return (CAM_DIR_NONE);
14335 -        }
14336 -#endif
14337 -}
14338 -
14339 -static __inline
14340 -void ahc_set_residual(struct scb *scb, u_long resid)
14341 -{
14342 -#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,3,0)
14343 -       scb->io_ctx->resid = resid;
14344 -#else
14345 -       scb->platform_data->resid = resid;
14346 -#endif
14347 -}
14348 -
14349 -static __inline
14350 -void ahc_set_sense_residual(struct scb *scb, u_long resid)
14351 -{
14352 -       scb->platform_data->sense_resid = resid;
14353 -}
14354 -
14355 -static __inline
14356 -u_long ahc_get_residual(struct scb *scb)
14357 -{
14358 -#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,3,0)
14359 -       return (scb->io_ctx->resid);
14360 -#else
14361 -       return (scb->platform_data->resid);
14362 -#endif
14363 -}
14364 -
14365 -static __inline
14366 -u_long ahc_get_sense_residual(struct scb *scb)
14367 -{
14368 -       return (scb->platform_data->sense_resid);
14369 -}
14370 -
14371 -static __inline
14372 -int ahc_perform_autosense(struct scb *scb)
14373 -{
14374 -       /*
14375 -        * We always perform autosense in Linux.
14376 -        * On other platforms this is set on a
14377 -        * per-transaction basis.
14378 -        */
14379 -       return (1);
14380 -}
14381 -
14382 -static __inline uint32_t
14383 -ahc_get_sense_bufsize(struct ahc_softc *ahc, struct scb *scb)
14384 -{
14385 -       return (sizeof(struct scsi_sense_data));
14386 -}
14387 -
14388 -static __inline void
14389 -ahc_notify_xfer_settings_change(struct ahc_softc *ahc,
14390 -                               struct ahc_devinfo *devinfo)
14391 -{
14392 -       /* Nothing to do here for linux */
14393 -}
14394 -
14395 -static __inline void
14396 -ahc_platform_scb_free(struct ahc_softc *ahc, struct scb *scb)
14397 -{
14398 -       ahc->flags &= ~AHC_RESOURCE_SHORTAGE;
14399 -}
14400 -
14401  int    ahc_platform_alloc(struct ahc_softc *ahc, void *platform_arg);
14402  void   ahc_platform_free(struct ahc_softc *ahc);
14403  void   ahc_platform_freeze_devq(struct ahc_softc *ahc, struct scb *scb);
14404 -
14405 -static __inline void
14406 -ahc_freeze_scb(struct scb *scb)
14407 -{
14408 -       if ((scb->io_ctx->result & (CAM_DEV_QFRZN << 16)) == 0) {
14409 -                scb->io_ctx->result |= CAM_DEV_QFRZN << 16;
14410 -                scb->platform_data->dev->qfrozen++;
14411 -        }
14412 -}
14413 -
14414  void   ahc_platform_set_tags(struct ahc_softc *ahc,
14415                               struct ahc_devinfo *devinfo, ahc_queue_alg);
14416  int    ahc_platform_abort_scbs(struct ahc_softc *ahc, int target,
14417 @@ -1193,9 +414,9 @@
14418  void   ahc_platform_dump_card_state(struct ahc_softc *ahc);
14419  
14420  #ifdef CONFIG_PCI
14421 -#define AHC_PCI_CONFIG 1
14422 +#define AIC_PCI_CONFIG 1
14423  #else
14424 -#define AHC_PCI_CONFIG 0
14425 +#define AIC_PCI_CONFIG 0
14426  #endif
14427  #define bootverbose aic7xxx_verbose
14428  extern u_int aic7xxx_verbose;
14429 diff -urN linux-2.4.24.org/drivers/scsi/aic7xxx/aic7xxx_osm_pci.c linux-2.4.24/drivers/scsi/aic7xxx/aic7xxx_osm_pci.c
14430 --- linux-2.4.24.org/drivers/scsi/aic7xxx/aic7xxx_osm_pci.c     2004-01-08 11:57:43.029001855 +0100
14431 +++ linux-2.4.24/drivers/scsi/aic7xxx/aic7xxx_osm_pci.c 2003-12-22 22:46:59.000000000 +0100
14432 @@ -36,11 +36,17 @@
14433   * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
14434   * POSSIBILITY OF SUCH DAMAGES.
14435   *
14436 - * $Id$
14437 + * $Id$
14438   */
14439  
14440  #include "aic7xxx_osm.h"
14441  
14442 +/*
14443 + * Include aiclib_pci.c as part of our
14444 + * "module dependencies are hard" work around.
14445 + */
14446 +#include "aiclib_pci.c"
14447 +
14448  #if LINUX_VERSION_CODE < KERNEL_VERSION(2,4,0)
14449  struct pci_device_id
14450  {
14451 @@ -51,11 +57,9 @@
14452                                         const struct pci_device_id *ent);
14453  static int     ahc_linux_pci_reserve_io_region(struct ahc_softc *ahc,
14454                                                 u_long *base);
14455 -#ifdef MMAPIO
14456  static int     ahc_linux_pci_reserve_mem_region(struct ahc_softc *ahc,
14457                                                  u_long *bus_addr,
14458                                                  uint8_t **maddr);
14459 -#endif /* MMAPIO */
14460  #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,0)
14461  static void    ahc_linux_pci_dev_remove(struct pci_dev *pdev);
14462  
14463 @@ -75,10 +79,10 @@
14464  MODULE_DEVICE_TABLE(pci, ahc_linux_pci_id_table);
14465  
14466  struct pci_driver aic7xxx_pci_driver = {
14467 -       name:           "aic7xxx",
14468 -       probe:          ahc_linux_pci_dev_probe,
14469 -       remove:         ahc_linux_pci_dev_remove,
14470 -       id_table:       ahc_linux_pci_id_table
14471 +       .name           = "aic7xxx",
14472 +       .probe          = ahc_linux_pci_dev_probe,
14473 +       .remove         = ahc_linux_pci_dev_remove,
14474 +       .id_table       = ahc_linux_pci_id_table
14475  };
14476  
14477  static void
14478 @@ -97,12 +101,14 @@
14479         if (ahc != NULL) {
14480                 u_long s;
14481  
14482 +               TAILQ_REMOVE(&ahc_tailq, ahc, links);
14483 +               ahc_list_unlock(&l);
14484                 ahc_lock(ahc, &s);
14485                 ahc_intr_enable(ahc, FALSE);
14486                 ahc_unlock(ahc, &s);
14487                 ahc_free(ahc);
14488 -       }
14489 -       ahc_list_unlock(&l);
14490 +       } else
14491 +               ahc_list_unlock(&l);
14492  }
14493  #endif /* !LINUX_VERSION_CODE < KERNEL_VERSION(2,4,0) */
14494  
14495 @@ -112,7 +118,7 @@
14496         char             buf[80];
14497         bus_addr_t       mask_39bit;
14498         struct           ahc_softc *ahc;
14499 -       ahc_dev_softc_t  pci;
14500 +       aic_dev_softc_t  dev;
14501         struct           ahc_pci_identity *entry;
14502         char            *name;
14503         int              error;
14504 @@ -123,7 +129,7 @@
14505         TAILQ_FOREACH(ahc, &ahc_tailq, links) {
14506                 struct pci_dev *probed_pdev;
14507  
14508 -               probed_pdev = ahc->dev_softc;
14509 +               probed_pdev = aic_dev_to_pci_dev(ahc->dev_softc);
14510                 if (probed_pdev->bus->number == pdev->bus->number
14511                  && probed_pdev->devfn == pdev->devfn)
14512                         break;
14513 @@ -133,8 +139,8 @@
14514                 return (-ENODEV);
14515         }
14516  
14517 -       pci = pdev;
14518 -       entry = ahc_find_pci_device(pci);
14519 +       dev = aic_pci_dev_to_dev(pdev);
14520 +       entry = ahc_find_pci_device(dev);
14521         if (entry == NULL)
14522                 return (-ENODEV);
14523  
14524 @@ -144,9 +150,9 @@
14525          * common detect routine.
14526          */
14527         sprintf(buf, "ahc_pci:%d:%d:%d",
14528 -               ahc_get_pci_bus(pci),
14529 -               ahc_get_pci_slot(pci),
14530 -               ahc_get_pci_function(pci));
14531 +               aic_get_pci_bus(dev),
14532 +               aic_get_pci_slot(dev),
14533 +               aic_get_pci_function(dev));
14534         name = malloc(strlen(buf) + 1, M_DEVBUF, M_NOWAIT);
14535         if (name == NULL)
14536                 return (-ENOMEM);
14537 @@ -154,6 +160,8 @@
14538         ahc = ahc_alloc(NULL, name);
14539         if (ahc == NULL)
14540                 return (-ENOMEM);
14541 +       ahc->dev_softc = dev;
14542 +
14543  #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,0)
14544         if (pci_enable_device(pdev)) {
14545                 ahc_free(ahc);
14546 @@ -164,15 +172,14 @@
14547         mask_39bit = (bus_addr_t)0x7FFFFFFFFFULL;
14548         if (sizeof(bus_addr_t) > 4
14549          && ahc_linux_get_memsize() > 0x80000000
14550 -        && ahc_pci_set_dma_mask(pdev, mask_39bit) == 0) {
14551 +        && aic_set_dma_mask(ahc, mask_39bit) == 0) {
14552                 ahc->flags |= AHC_39BIT_ADDRESSING;
14553                 ahc->platform_data->hw_dma_mask = mask_39bit;
14554         } else {
14555 -               ahc_pci_set_dma_mask(pdev, 0xFFFFFFFF);
14556 +               aic_set_dma_mask(ahc, 0xFFFFFFFF);
14557                 ahc->platform_data->hw_dma_mask = 0xFFFFFFFF;
14558         }
14559  #endif
14560 -       ahc->dev_softc = pci;
14561         error = ahc_pci_config(ahc, entry);
14562         if (error != 0) {
14563                 ahc_free(ahc);
14564 @@ -211,10 +218,8 @@
14565         pdev = NULL;
14566         class = PCI_CLASS_STORAGE_SCSI << 8;
14567         while ((pdev = pci_find_class(class, pdev)) != NULL) {
14568 -               ahc_dev_softc_t pci;
14569                 int error;
14570  
14571 -               pci = pdev;
14572                 error = ahc_linux_pci_dev_probe(pdev, /*pci_devid*/NULL);
14573                 if (error == 0)
14574                         found++;
14575 @@ -236,9 +241,9 @@
14576                 return (ENOMEM);
14577  
14578  #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,3,0)
14579 -       *base = pci_resource_start(ahc->dev_softc, 0);
14580 +       *base = pci_resource_start(aic_pci_dev(ahc), 0);
14581  #else
14582 -       *base = ahc_pci_read_config(ahc->dev_softc, PCIR_MAPS, 4);
14583 +       *base = aic_pci_read_config(ahc->dev_softc, PCIR_MAPS, 4);
14584         *base &= PCI_BASE_ADDRESS_IO_MASK;
14585  #endif
14586         if (*base == 0)
14587 @@ -254,7 +259,6 @@
14588         return (0);
14589  }
14590  
14591 -#ifdef MMAPIO
14592  static int
14593  ahc_linux_pci_reserve_mem_region(struct ahc_softc *ahc,
14594                                  u_long *bus_addr,
14595 @@ -267,11 +271,11 @@
14596  
14597         error = 0;
14598  #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,3,0)
14599 -       start = pci_resource_start(ahc->dev_softc, 1);
14600 +       start = pci_resource_start(aic_pci_dev(ahc), 1);
14601         base_page = start & PAGE_MASK;
14602         base_offset = start - base_page;
14603  #else
14604 -       start = ahc_pci_read_config(ahc->dev_softc, PCIR_MAPS+4, 4);
14605 +       start = aic_pci_read_config(ahc->dev_softc, PCIR_MAPS+4, 4);
14606         base_offset = start & PCI_BASE_ADDRESS_MEM_MASK;
14607         base_page = base_offset & PAGE_MASK;
14608         base_offset -= base_page;
14609 @@ -296,7 +300,6 @@
14610                 error = ENOMEM;
14611         return (error);
14612  }
14613 -#endif /* MMAPIO */
14614  
14615  int
14616  ahc_pci_map_registers(struct ahc_softc *ahc)
14617 @@ -309,17 +312,16 @@
14618         /*
14619          * If its allowed, we prefer memory mapped access.
14620          */
14621 -       command = ahc_pci_read_config(ahc->dev_softc, PCIR_COMMAND, 4);
14622 +       command = aic_pci_read_config(ahc->dev_softc, PCIR_COMMAND, 4);
14623         command &= ~(PCIM_CMD_PORTEN|PCIM_CMD_MEMEN);
14624         base = 0;
14625         maddr = NULL;
14626 -#ifdef MMAPIO
14627         error = ahc_linux_pci_reserve_mem_region(ahc, &base, &maddr);
14628         if (error == 0) {
14629                 ahc->platform_data->mem_busaddr = base;
14630                 ahc->tag = BUS_SPACE_MEMIO;
14631                 ahc->bsh.maddr = maddr;
14632 -               ahc_pci_write_config(ahc->dev_softc, PCIR_COMMAND,
14633 +               aic_pci_write_config(ahc->dev_softc, PCIR_COMMAND,
14634                                      command | PCIM_CMD_MEMEN, 4);
14635  
14636                 /*
14637 @@ -330,9 +332,9 @@
14638  
14639                         printf("aic7xxx: PCI Device %d:%d:%d "
14640                                "failed memory mapped test.  Using PIO.\n",
14641 -                              ahc_get_pci_bus(ahc->dev_softc),
14642 -                              ahc_get_pci_slot(ahc->dev_softc),
14643 -                              ahc_get_pci_function(ahc->dev_softc));
14644 +                              aic_get_pci_bus(ahc->dev_softc),
14645 +                              aic_get_pci_slot(ahc->dev_softc),
14646 +                              aic_get_pci_function(ahc->dev_softc));
14647                         iounmap((void *)((u_long)maddr & PAGE_MASK));
14648  #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,0)
14649                         release_mem_region(ahc->platform_data->mem_busaddr,
14650 @@ -345,12 +347,11 @@
14651         } else {
14652                 printf("aic7xxx: PCI%d:%d:%d MEM region 0x%lx "
14653                        "unavailable. Cannot memory map device.\n",
14654 -                      ahc_get_pci_bus(ahc->dev_softc),
14655 -                      ahc_get_pci_slot(ahc->dev_softc),
14656 -                      ahc_get_pci_function(ahc->dev_softc),
14657 +                      aic_get_pci_bus(ahc->dev_softc),
14658 +                      aic_get_pci_slot(ahc->dev_softc),
14659 +                      aic_get_pci_function(ahc->dev_softc),
14660                        base);
14661         }
14662 -#endif /* MMAPIO */
14663  
14664         /*
14665          * We always prefer memory mapped access.
14666 @@ -358,20 +359,20 @@
14667         if (maddr == NULL) {
14668  
14669                 error = ahc_linux_pci_reserve_io_region(ahc, &base);
14670 -               if (error == 0) {
14671 +               if (error == 0 && ahc_pci_test_register_access(ahc) == 0) {
14672                         ahc->tag = BUS_SPACE_PIO;
14673                         ahc->bsh.ioport = base;
14674                         command |= PCIM_CMD_PORTEN;
14675                 } else {
14676                         printf("aic7xxx: PCI%d:%d:%d IO region 0x%lx[0..255] "
14677                                "unavailable. Cannot map device.\n",
14678 -                              ahc_get_pci_bus(ahc->dev_softc),
14679 -                              ahc_get_pci_slot(ahc->dev_softc),
14680 -                              ahc_get_pci_function(ahc->dev_softc),
14681 +                              aic_get_pci_bus(ahc->dev_softc),
14682 +                              aic_get_pci_slot(ahc->dev_softc),
14683 +                              aic_get_pci_function(ahc->dev_softc),
14684                                base);
14685                 }
14686         }
14687 -       ahc_pci_write_config(ahc->dev_softc, PCIR_COMMAND, command, 4);
14688 +       aic_pci_write_config(ahc->dev_softc, PCIR_COMMAND, command, 4);
14689         return (error);
14690  }
14691  
14692 @@ -380,49 +381,10 @@
14693  {
14694         int error;
14695  
14696 -       error = request_irq(ahc->dev_softc->irq, ahc_linux_isr,
14697 +       error = request_irq(aic_pci_dev(ahc)->irq, ahc_linux_isr,
14698                             SA_SHIRQ, "aic7xxx", ahc);
14699         if (error == 0)
14700 -               ahc->platform_data->irq = ahc->dev_softc->irq;
14701 +               ahc->platform_data->irq = aic_pci_dev(ahc)->irq;
14702         
14703         return (-error);
14704  }
14705 -
14706 -void
14707 -ahc_power_state_change(struct ahc_softc *ahc, ahc_power_state new_state)
14708 -{
14709 -#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,0)
14710 -       pci_set_power_state(ahc->dev_softc, new_state);
14711 -#else
14712 -       uint32_t cap;
14713 -       u_int cap_offset;
14714 -
14715 -       /*
14716 -        * Traverse the capability list looking for
14717 -        * the power management capability.
14718 -        */
14719 -       cap = 0;
14720 -       cap_offset = ahc_pci_read_config(ahc->dev_softc,
14721 -                                        PCIR_CAP_PTR, /*bytes*/1);
14722 -       while (cap_offset != 0) {
14723 -
14724 -               cap = ahc_pci_read_config(ahc->dev_softc,
14725 -                                         cap_offset, /*bytes*/4);
14726 -               if ((cap & 0xFF) == 1
14727 -                && ((cap >> 16) & 0x3) > 0) {
14728 -                       uint32_t pm_control;
14729 -
14730 -                       pm_control = ahc_pci_read_config(ahc->dev_softc,
14731 -                                                        cap_offset + 4,
14732 -                                                        /*bytes*/4);
14733 -                       pm_control &= ~0x3;
14734 -                       pm_control |= new_state;
14735 -                       ahc_pci_write_config(ahc->dev_softc,
14736 -                                            cap_offset + 4,
14737 -                                            pm_control, /*bytes*/2);
14738 -                       break;
14739 -               }
14740 -               cap_offset = (cap >> 8) & 0xFF;
14741 -       }
14742 -#endif 
14743 -}
14744 diff -urN linux-2.4.24.org/drivers/scsi/aic7xxx/aic7xxx_pci.c linux-2.4.24/drivers/scsi/aic7xxx/aic7xxx_pci.c
14745 --- linux-2.4.24.org/drivers/scsi/aic7xxx/aic7xxx_pci.c 2004-01-08 11:57:43.028002061 +0100
14746 +++ linux-2.4.24/drivers/scsi/aic7xxx/aic7xxx_pci.c     2003-12-22 22:46:59.000000000 +0100
14747 @@ -39,9 +39,7 @@
14748   * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
14749   * POSSIBILITY OF SUCH DAMAGES.
14750   *
14751 - * $Id$
14752 - *
14753 - * $FreeBSD$
14754 + * $Id$
14755   */
14756  
14757  #ifdef __linux__
14758 @@ -49,14 +47,13 @@
14759  #include "aic7xxx_inline.h"
14760  #include "aic7xxx_93cx6.h"
14761  #else
14762 +
14763 +
14764  #include <dev/aic7xxx/aic7xxx_osm.h>
14765  #include <dev/aic7xxx/aic7xxx_inline.h>
14766  #include <dev/aic7xxx/aic7xxx_93cx6.h>
14767  #endif
14768  
14769 -#define AHC_PCI_IOADDR PCIR_MAPS       /* I/O Address */
14770 -#define AHC_PCI_MEMADDR        (PCIR_MAPS + 4) /* Mem I/O Address */
14771 -
14772  static __inline uint64_t
14773  ahc_compose_id(u_int device, u_int vendor, u_int subdevice, u_int subvendor)
14774  {
14775 @@ -133,6 +130,7 @@
14776  #define ID_AHA_29160C                  0x0080900562209005ull
14777  #define ID_AHA_29160B                  0x00809005E2209005ull
14778  #define ID_AHA_19160B                  0x0081900562A19005ull
14779 +#define ID_AHA_2915_30LP               0x0082900502109005ull
14780  
14781  #define ID_AIC7896                     0x005F9005FFFF9005ull
14782  #define ID_AIC7896_ARO                 0x00539005FFFF9005ull
14783 @@ -470,6 +468,12 @@
14784                 "Adaptec aic7892 Ultra160 SCSI adapter (ARO)",
14785                 ahc_aic7892_setup
14786         },
14787 +       {
14788 +               ID_AHA_2915_30LP,
14789 +               ID_ALL_MASK,
14790 +               "Adaptec 2915/30LP Ultra160 SCSI adapter",
14791 +               ahc_aic7892_setup
14792 +       },
14793         /* aic7895 based controllers */ 
14794         {
14795                 ID_AHA_2940U_DUAL,
14796 @@ -738,7 +742,7 @@
14797  }
14798  
14799  struct ahc_pci_identity *
14800 -ahc_find_pci_device(ahc_dev_softc_t pci)
14801 +ahc_find_pci_device(aic_dev_softc_t pci)
14802  {
14803         uint64_t  full_id;
14804         uint16_t  device;
14805 @@ -748,10 +752,10 @@
14806         struct    ahc_pci_identity *entry;
14807         u_int     i;
14808  
14809 -       vendor = ahc_pci_read_config(pci, PCIR_DEVVENDOR, /*bytes*/2);
14810 -       device = ahc_pci_read_config(pci, PCIR_DEVICE, /*bytes*/2);
14811 -       subvendor = ahc_pci_read_config(pci, PCIR_SUBVEND_0, /*bytes*/2);
14812 -       subdevice = ahc_pci_read_config(pci, PCIR_SUBDEV_0, /*bytes*/2);
14813 +       vendor = aic_pci_read_config(pci, PCIR_DEVVENDOR, /*bytes*/2);
14814 +       device = aic_pci_read_config(pci, PCIR_DEVICE, /*bytes*/2);
14815 +       subvendor = aic_pci_read_config(pci, PCIR_SUBVEND_0, /*bytes*/2);
14816 +       subdevice = aic_pci_read_config(pci, PCIR_SUBDEV_0, /*bytes*/2);
14817         full_id = ahc_compose_id(device, vendor, subdevice, subvendor);
14818  
14819         /*
14820 @@ -761,7 +765,7 @@
14821          * to sanity check it prior to accepting the subdevice
14822          * ID as valid.
14823          */
14824 -       if (ahc_get_pci_function(pci) > 0
14825 +       if (aic_get_pci_function(pci) > 0
14826          && ahc_9005_subdevinfo_valid(vendor, device, subvendor, subdevice)
14827          && SUBID_9005_MFUNCENB(subdevice) == 0)
14828                 return (NULL);
14829 @@ -798,7 +802,7 @@
14830         ahc->chip |= AHC_PCI;
14831         ahc->description = entry->name;
14832  
14833 -       ahc_power_state_change(ahc, AHC_POWER_STATE_D0);
14834 +       aic_power_state_change(ahc, AIC_POWER_STATE_D0);
14835  
14836         error = ahc_pci_map_registers(ahc);
14837         if (error != 0)
14838 @@ -812,7 +816,7 @@
14839          */
14840         ahc_intr_enable(ahc, FALSE);
14841  
14842 -       devconfig = ahc_pci_read_config(ahc->dev_softc, DEVCONFIG, /*bytes*/4);
14843 +       devconfig = aic_pci_read_config(ahc->dev_softc, DEVCONFIG, /*bytes*/4);
14844  
14845         /*
14846          * If we need to support high memory, enable dual
14847 @@ -831,13 +835,13 @@
14848         /* Ensure that pci error generation, a test feature, is disabled. */
14849         devconfig |= PCIERRGENDIS;
14850  
14851 -       ahc_pci_write_config(ahc->dev_softc, DEVCONFIG, devconfig, /*bytes*/4);
14852 +       aic_pci_write_config(ahc->dev_softc, DEVCONFIG, devconfig, /*bytes*/4);
14853  
14854         /* Ensure busmastering is enabled */
14855 -       command = ahc_pci_read_config(ahc->dev_softc, PCIR_COMMAND, /*bytes*/2);
14856 +       command = aic_pci_read_config(ahc->dev_softc, PCIR_COMMAND, /*bytes*/2);
14857         command |= PCIM_CMD_BUSMASTEREN;
14858  
14859 -       ahc_pci_write_config(ahc->dev_softc, PCIR_COMMAND, command, /*bytes*/2);
14860 +       aic_pci_write_config(ahc->dev_softc, PCIR_COMMAND, command, /*bytes*/2);
14861  
14862         /* On all PCI adapters, we allow SCB paging */
14863         ahc->flags |= AHC_PAGESCBS;
14864 @@ -920,14 +924,14 @@
14865         ahc_outb(ahc, DSCOMMAND0, dscommand0);
14866  
14867         ahc->pci_cachesize =
14868 -           ahc_pci_read_config(ahc->dev_softc, CSIZE_LATTIME,
14869 +           aic_pci_read_config(ahc->dev_softc, CSIZE_LATTIME,
14870                                 /*bytes*/1) & CACHESIZE;
14871         ahc->pci_cachesize *= 4;
14872  
14873         if ((ahc->bugs & AHC_PCI_2_1_RETRY_BUG) != 0
14874          && ahc->pci_cachesize == 4) {
14875  
14876 -               ahc_pci_write_config(ahc->dev_softc, CSIZE_LATTIME,
14877 +               aic_pci_write_config(ahc->dev_softc, CSIZE_LATTIME,
14878                                      0, /*bytes*/1);
14879                 ahc->pci_cachesize = 0;
14880         }
14881 @@ -939,7 +943,7 @@
14882         if ((ahc->features & AHC_ULTRA) != 0) {
14883                 uint32_t devconfig;
14884  
14885 -               devconfig = ahc_pci_read_config(ahc->dev_softc,
14886 +               devconfig = aic_pci_read_config(ahc->dev_softc,
14887                                                 DEVCONFIG, /*bytes*/4);
14888                 if ((devconfig & REXTVALID) == 0)
14889                         ahc->features &= ~AHC_ULTRA;
14890 @@ -1005,11 +1009,11 @@
14891          * that occur during runtime and resume events.
14892          */
14893         ahc->bus_softc.pci_softc.devconfig =
14894 -           ahc_pci_read_config(ahc->dev_softc, DEVCONFIG, /*bytes*/4);
14895 +           aic_pci_read_config(ahc->dev_softc, DEVCONFIG, /*bytes*/4);
14896         ahc->bus_softc.pci_softc.command =
14897 -           ahc_pci_read_config(ahc->dev_softc, PCIR_COMMAND, /*bytes*/1);
14898 +           aic_pci_read_config(ahc->dev_softc, PCIR_COMMAND, /*bytes*/1);
14899         ahc->bus_softc.pci_softc.csize_lattime =
14900 -           ahc_pci_read_config(ahc->dev_softc, CSIZE_LATTIME, /*bytes*/1);
14901 +           aic_pci_read_config(ahc->dev_softc, CSIZE_LATTIME, /*bytes*/1);
14902         ahc->bus_softc.pci_softc.dscommand0 = ahc_inb(ahc, DSCOMMAND0);
14903         ahc->bus_softc.pci_softc.dspcistatus = ahc_inb(ahc, DSPCISTATUS);
14904         if ((ahc->features & AHC_DT) != 0) {
14905 @@ -1063,7 +1067,7 @@
14906         uint32_t devconfig;
14907  
14908         chip = ahc->chip & AHC_CHIPID_MASK;
14909 -       devconfig = ahc_pci_read_config(ahc->dev_softc,
14910 +       devconfig = aic_pci_read_config(ahc->dev_softc,
14911                                         DEVCONFIG, /*bytes*/4);
14912         single_user = (devconfig & MPORTMODE) != 0;
14913  
14914 @@ -1101,13 +1105,13 @@
14915                  * Set the SCB Base addr (highest address bit)
14916                  * depending on which channel we are.
14917                  */
14918 -               ahc_outb(ahc, SCBBADDR, ahc_get_pci_function(ahc->dev_softc));
14919 +               ahc_outb(ahc, SCBBADDR, aic_get_pci_function(ahc->dev_softc));
14920         }
14921  
14922         ahc->flags &= ~AHC_LSCBS_ENABLED;
14923         if (large)
14924                 ahc->flags |= AHC_LSCBS_ENABLED;
14925 -       devconfig = ahc_pci_read_config(ahc->dev_softc, DEVCONFIG, /*bytes*/4);
14926 +       devconfig = aic_pci_read_config(ahc->dev_softc, DEVCONFIG, /*bytes*/4);
14927         if ((ahc->features & AHC_ULTRA2) != 0) {
14928                 u_int dscommand0;
14929  
14930 @@ -1140,7 +1144,7 @@
14931         else
14932                 devconfig &= ~EXTSCBPEN;
14933  
14934 -       ahc_pci_write_config(ahc->dev_softc, DEVCONFIG, devconfig, /*bytes*/4);
14935 +       aic_pci_write_config(ahc->dev_softc, DEVCONFIG, devconfig, /*bytes*/4);
14936  }
14937  
14938  /*
14939 @@ -1263,8 +1267,8 @@
14940          * Enable PCI error interrupt status, but suppress NMIs
14941          * generated by SERR raised due to target aborts.
14942          */
14943 -       cmd = ahc_pci_read_config(ahc->dev_softc, PCIR_COMMAND, /*bytes*/2);
14944 -       ahc_pci_write_config(ahc->dev_softc, PCIR_COMMAND,
14945 +       cmd = aic_pci_read_config(ahc->dev_softc, PCIR_COMMAND, /*bytes*/2);
14946 +       aic_pci_write_config(ahc->dev_softc, PCIR_COMMAND,
14947                              cmd & ~PCIM_CMD_SERRESPEN, /*bytes*/2);
14948  
14949         /*
14950 @@ -1276,24 +1280,36 @@
14951          * use for this test.
14952          */
14953         hcntrl = ahc_inb(ahc, HCNTRL);
14954 +
14955         if (hcntrl == 0xFF)
14956                 goto fail;
14957  
14958 +       if ((hcntrl & CHIPRST) != 0) {
14959 +               /*
14960 +                * The chip has not been initialized since
14961 +                * PCI/EISA/VLB bus reset.  Don't trust
14962 +                * "left over BIOS data".
14963 +                */
14964 +               ahc->flags |= AHC_NO_BIOS_INIT;
14965 +       }
14966 +
14967         /*
14968          * Next create a situation where write combining
14969          * or read prefetching could be initiated by the
14970          * CPU or host bridge.  Our device does not support
14971          * either, so look for data corruption and/or flagged
14972 -        * PCI errors.
14973 +        * PCI errors.  First pause without causing another
14974 +        * chip reset.
14975          */
14976 +       hcntrl &= ~CHIPRST;
14977         ahc_outb(ahc, HCNTRL, hcntrl|PAUSE);
14978         while (ahc_is_paused(ahc) == 0)
14979                 ;
14980  
14981         /* Clear any PCI errors that occurred before our driver attached. */
14982 -       status1 = ahc_pci_read_config(ahc->dev_softc,
14983 +       status1 = aic_pci_read_config(ahc->dev_softc,
14984                                       PCIR_STATUS + 1, /*bytes*/1);
14985 -       ahc_pci_write_config(ahc->dev_softc, PCIR_STATUS + 1,
14986 +       aic_pci_write_config(ahc->dev_softc, PCIR_STATUS + 1,
14987                              status1, /*bytes*/1);
14988         ahc_outb(ahc, CLRINT, CLRPARERR);
14989  
14990 @@ -1303,7 +1319,7 @@
14991         if (ahc_inl(ahc, SCB_BASE) != 0x5aa555aa)
14992                 goto fail;
14993  
14994 -       status1 = ahc_pci_read_config(ahc->dev_softc,
14995 +       status1 = aic_pci_read_config(ahc->dev_softc,
14996                                       PCIR_STATUS + 1, /*bytes*/1);
14997         if ((status1 & STA) != 0)
14998                 goto fail;
14999 @@ -1312,13 +1328,13 @@
15000  
15001  fail:
15002         /* Silently clear any latched errors. */
15003 -       status1 = ahc_pci_read_config(ahc->dev_softc,
15004 +       status1 = aic_pci_read_config(ahc->dev_softc,
15005                                       PCIR_STATUS + 1, /*bytes*/1);
15006 -       ahc_pci_write_config(ahc->dev_softc, PCIR_STATUS + 1,
15007 +       aic_pci_write_config(ahc->dev_softc, PCIR_STATUS + 1,
15008                              status1, /*bytes*/1);
15009         ahc_outb(ahc, CLRINT, CLRPARERR);
15010         ahc_outb(ahc, SEQCTL, PERRORDIS|FAILDIS);
15011 -       ahc_pci_write_config(ahc->dev_softc, PCIR_COMMAND, cmd, /*bytes*/2);
15012 +       aic_pci_write_config(ahc->dev_softc, PCIR_COMMAND, cmd, /*bytes*/2);
15013         return (error);
15014  }
15015  
15016 @@ -1388,6 +1404,10 @@
15017                         sd.sd_chip = C56_66;
15018                 }
15019                 ahc_release_seeprom(&sd);
15020 +
15021 +               /* Remember the SEEPROM type for later */
15022 +               if (sd.sd_chip == C56_66)
15023 +                       ahc->flags |= AHC_LARGE_SEEPROM;
15024         }
15025  
15026         if (!have_seeprom) {
15027 @@ -1573,12 +1593,12 @@
15028                 uint32_t devconfig;
15029  
15030                 /* Honor the STPWLEVEL settings */
15031 -               devconfig = ahc_pci_read_config(ahc->dev_softc,
15032 +               devconfig = aic_pci_read_config(ahc->dev_softc,
15033                                                 DEVCONFIG, /*bytes*/4);
15034                 devconfig &= ~STPWLEVEL;
15035                 if ((sc->bios_control & CFSTPWLEVEL) != 0)
15036                         devconfig |= STPWLEVEL;
15037 -               ahc_pci_write_config(ahc->dev_softc, DEVCONFIG,
15038 +               aic_pci_write_config(ahc->dev_softc, DEVCONFIG,
15039                                      devconfig, /*bytes*/4);
15040         }
15041         /* Set SCSICONF info */
15042 @@ -1891,10 +1911,10 @@
15043         ahc_outb(ahc, SPIOCAP, spiocap);
15044         ahc_outb(ahc, BRDCTL, BRDRW|BRDCS);
15045         ahc_flush_device_writes(ahc);
15046 -       ahc_delay(500);
15047 +       aic_delay(500);
15048         ahc_outb(ahc, BRDCTL, 0);
15049         ahc_flush_device_writes(ahc);
15050 -       ahc_delay(500);
15051 +       aic_delay(500);
15052         brdctl = ahc_inb(ahc, BRDCTL);
15053         *internal50_present = (brdctl & BRDDAT5) ? 0 : 1;
15054         *externalcable_present = (brdctl & BRDDAT6) ? 0 : 1;
15055 @@ -1920,7 +1940,7 @@
15056         SEEPROM_OUTB(sd, sd->sd_MS);
15057         wait = 1000;  /* 1 second timeout in msec */
15058         while (--wait && ((SEEPROM_STATUS_INB(sd) & sd->sd_RDY) == 0)) {
15059 -               ahc_delay(1000);  /* delay 1 msec */
15060 +               aic_delay(1000);  /* delay 1 msec */
15061         }
15062         if ((SEEPROM_STATUS_INB(sd) & sd->sd_RDY) == 0) {
15063                 SEEPROM_OUTB(sd, 0); 
15064 @@ -2000,7 +2020,7 @@
15065         if ((error & PCIERRSTAT) == 0)
15066                 return;
15067  
15068 -       status1 = ahc_pci_read_config(ahc->dev_softc,
15069 +       status1 = aic_pci_read_config(ahc->dev_softc,
15070                                       PCIR_STATUS + 1, /*bytes*/1);
15071  
15072         printf("%s: PCI error Interrupt at seqaddr = 0x%x\n",
15073 @@ -2030,7 +2050,7 @@
15074         }
15075  
15076         /* Clear latched errors. */
15077 -       ahc_pci_write_config(ahc->dev_softc, PCIR_STATUS + 1,
15078 +       aic_pci_write_config(ahc->dev_softc, PCIR_STATUS + 1,
15079                              status1, /*bytes*/1);
15080  
15081         if ((status1 & (DPE|SSE|RMA|RTA|STA|DPR)) == 0) {
15082 @@ -2091,7 +2111,7 @@
15083  ahc_pci_resume(struct ahc_softc *ahc)
15084  {
15085  
15086 -       ahc_power_state_change(ahc, AHC_POWER_STATE_D0);
15087 +       aic_power_state_change(ahc, AIC_POWER_STATE_D0);
15088  
15089         /*
15090          * We assume that the OS has restored our register
15091 @@ -2099,11 +2119,11 @@
15092          * that the OS doesn't know about and rely on our chip
15093          * reset handler to handle the rest.
15094          */
15095 -       ahc_pci_write_config(ahc->dev_softc, DEVCONFIG, /*bytes*/4,
15096 +       aic_pci_write_config(ahc->dev_softc, DEVCONFIG, /*bytes*/4,
15097                              ahc->bus_softc.pci_softc.devconfig);
15098 -       ahc_pci_write_config(ahc->dev_softc, PCIR_COMMAND, /*bytes*/1,
15099 +       aic_pci_write_config(ahc->dev_softc, PCIR_COMMAND, /*bytes*/1,
15100                              ahc->bus_softc.pci_softc.command);
15101 -       ahc_pci_write_config(ahc->dev_softc, CSIZE_LATTIME, /*bytes*/1,
15102 +       aic_pci_write_config(ahc->dev_softc, CSIZE_LATTIME, /*bytes*/1,
15103                              ahc->bus_softc.pci_softc.csize_lattime);
15104         if ((ahc->flags & AHC_HAS_TERM_LOGIC) != 0) {
15105                 struct  seeprom_descriptor sd;
15106 @@ -2126,7 +2146,7 @@
15107  static int
15108  ahc_aic785X_setup(struct ahc_softc *ahc)
15109  {
15110 -       ahc_dev_softc_t pci;
15111 +       aic_dev_softc_t pci;
15112         uint8_t rev;
15113  
15114         pci = ahc->dev_softc;
15115 @@ -2134,7 +2154,7 @@
15116         ahc->chip = AHC_AIC7850;
15117         ahc->features = AHC_AIC7850_FE;
15118         ahc->bugs |= AHC_TMODE_WIDEODD_BUG|AHC_CACHETHEN_BUG|AHC_PCI_MWI_BUG;
15119 -       rev = ahc_pci_read_config(pci, PCIR_REVID, /*bytes*/1);
15120 +       rev = aic_pci_read_config(pci, PCIR_REVID, /*bytes*/1);
15121         if (rev >= 1)
15122                 ahc->bugs |= AHC_PCI_2_1_RETRY_BUG;
15123         ahc->instruction_ram_size = 512;
15124 @@ -2144,7 +2164,7 @@
15125  static int
15126  ahc_aic7860_setup(struct ahc_softc *ahc)
15127  {
15128 -       ahc_dev_softc_t pci;
15129 +       aic_dev_softc_t pci;
15130         uint8_t rev;
15131  
15132         pci = ahc->dev_softc;
15133 @@ -2152,7 +2172,7 @@
15134         ahc->chip = AHC_AIC7860;
15135         ahc->features = AHC_AIC7860_FE;
15136         ahc->bugs |= AHC_TMODE_WIDEODD_BUG|AHC_CACHETHEN_BUG|AHC_PCI_MWI_BUG;
15137 -       rev = ahc_pci_read_config(pci, PCIR_REVID, /*bytes*/1);
15138 +       rev = aic_pci_read_config(pci, PCIR_REVID, /*bytes*/1);
15139         if (rev >= 1)
15140                 ahc->bugs |= AHC_PCI_2_1_RETRY_BUG;
15141         ahc->instruction_ram_size = 512;
15142 @@ -2219,7 +2239,7 @@
15143  static int
15144  ahc_aic7880_setup(struct ahc_softc *ahc)
15145  {
15146 -       ahc_dev_softc_t pci;
15147 +       aic_dev_softc_t pci;
15148         uint8_t rev;
15149  
15150         pci = ahc->dev_softc;
15151 @@ -2227,7 +2247,7 @@
15152         ahc->chip = AHC_AIC7880;
15153         ahc->features = AHC_AIC7880_FE;
15154         ahc->bugs |= AHC_TMODE_WIDEODD_BUG;
15155 -       rev = ahc_pci_read_config(pci, PCIR_REVID, /*bytes*/1);
15156 +       rev = aic_pci_read_config(pci, PCIR_REVID, /*bytes*/1);
15157         if (rev >= 1) {
15158                 ahc->bugs |= AHC_PCI_2_1_RETRY_BUG;
15159         } else {
15160 @@ -2270,7 +2290,7 @@
15161  static int
15162  ahc_aic7890_setup(struct ahc_softc *ahc)
15163  {
15164 -       ahc_dev_softc_t pci;
15165 +       aic_dev_softc_t pci;
15166         uint8_t rev;
15167  
15168         pci = ahc->dev_softc;
15169 @@ -2278,7 +2298,7 @@
15170         ahc->chip = AHC_AIC7890;
15171         ahc->features = AHC_AIC7890_FE;
15172         ahc->flags |= AHC_NEWEEPROM_FMT;
15173 -       rev = ahc_pci_read_config(pci, PCIR_REVID, /*bytes*/1);
15174 +       rev = aic_pci_read_config(pci, PCIR_REVID, /*bytes*/1);
15175         if (rev == 0)
15176                 ahc->bugs |= AHC_AUTOFLUSH_BUG|AHC_CACHETHEN_BUG;
15177         ahc->instruction_ram_size = 768;
15178 @@ -2301,15 +2321,15 @@
15179  static int
15180  ahc_aic7895_setup(struct ahc_softc *ahc)
15181  {
15182 -       ahc_dev_softc_t pci;
15183 +       aic_dev_softc_t pci;
15184         uint8_t rev;
15185  
15186         pci = ahc->dev_softc;
15187 -       ahc->channel = ahc_get_pci_function(pci) == 1 ? 'B' : 'A';
15188 +       ahc->channel = aic_get_pci_function(pci) == 1 ? 'B' : 'A';
15189         /*
15190          * The 'C' revision of the aic7895 has a few additional features.
15191          */
15192 -       rev = ahc_pci_read_config(pci, PCIR_REVID, /*bytes*/1);
15193 +       rev = aic_pci_read_config(pci, PCIR_REVID, /*bytes*/1);
15194         if (rev >= 4) {
15195                 ahc->chip = AHC_AIC7895C;
15196                 ahc->features = AHC_AIC7895C_FE;
15197 @@ -2325,9 +2345,9 @@
15198                  * we have.  Disabling MWI reduces performance, so
15199                  * turn it on again.
15200                  */
15201 -               command = ahc_pci_read_config(pci, PCIR_COMMAND, /*bytes*/1);
15202 +               command = aic_pci_read_config(pci, PCIR_COMMAND, /*bytes*/1);
15203                 command |= PCIM_CMD_MWRICEN;
15204 -               ahc_pci_write_config(pci, PCIR_COMMAND, command, /*bytes*/1);
15205 +               aic_pci_write_config(pci, PCIR_COMMAND, command, /*bytes*/1);
15206                 ahc->bugs |= AHC_PCI_MWI_BUG;
15207         }
15208         /*
15209 @@ -2344,10 +2364,10 @@
15210          * Cachesize must also be zero due to stray DAC
15211          * problem when sitting behind some bridges.
15212          */
15213 -       ahc_pci_write_config(pci, CSIZE_LATTIME, 0, /*bytes*/1);
15214 -       devconfig = ahc_pci_read_config(pci, DEVCONFIG, /*bytes*/1);
15215 +       aic_pci_write_config(pci, CSIZE_LATTIME, 0, /*bytes*/1);
15216 +       devconfig = aic_pci_read_config(pci, DEVCONFIG, /*bytes*/1);
15217         devconfig |= MRDCEN;
15218 -       ahc_pci_write_config(pci, DEVCONFIG, devconfig, /*bytes*/1);
15219 +       aic_pci_write_config(pci, DEVCONFIG, devconfig, /*bytes*/1);
15220  #endif
15221         ahc->flags |= AHC_NEWEEPROM_FMT;
15222         ahc->instruction_ram_size = 512;
15223 @@ -2357,10 +2377,10 @@
15224  static int
15225  ahc_aic7896_setup(struct ahc_softc *ahc)
15226  {
15227 -       ahc_dev_softc_t pci;
15228 +       aic_dev_softc_t pci;
15229  
15230         pci = ahc->dev_softc;
15231 -       ahc->channel = ahc_get_pci_function(pci) == 1 ? 'B' : 'A';
15232 +       ahc->channel = aic_get_pci_function(pci) == 1 ? 'B' : 'A';
15233         ahc->chip = AHC_AIC7896;
15234         ahc->features = AHC_AIC7896_FE;
15235         ahc->flags |= AHC_NEWEEPROM_FMT;
15236 @@ -2372,10 +2392,10 @@
15237  static int
15238  ahc_aic7899_setup(struct ahc_softc *ahc)
15239  {
15240 -       ahc_dev_softc_t pci;
15241 +       aic_dev_softc_t pci;
15242  
15243         pci = ahc->dev_softc;
15244 -       ahc->channel = ahc_get_pci_function(pci) == 1 ? 'B' : 'A';
15245 +       ahc->channel = aic_get_pci_function(pci) == 1 ? 'B' : 'A';
15246         ahc->chip = AHC_AIC7899;
15247         ahc->features = AHC_AIC7899_FE;
15248         ahc->flags |= AHC_NEWEEPROM_FMT;
15249 @@ -2406,10 +2426,10 @@
15250  static int
15251  ahc_aha394XX_setup(struct ahc_softc *ahc)
15252  {
15253 -       ahc_dev_softc_t pci;
15254 +       aic_dev_softc_t pci;
15255  
15256         pci = ahc->dev_softc;
15257 -       switch (ahc_get_pci_slot(pci)) {
15258 +       switch (aic_get_pci_slot(pci)) {
15259         case AHC_394X_SLOT_CHANNEL_A:
15260                 ahc->channel = 'A';
15261                 break;
15262 @@ -2419,7 +2439,7 @@
15263         default:
15264                 printf("adapter at unexpected slot %d\n"
15265                        "unable to map to a channel\n",
15266 -                      ahc_get_pci_slot(pci));
15267 +                      aic_get_pci_slot(pci));
15268                 ahc->channel = 'A';
15269         }
15270         return (0);
15271 @@ -2428,10 +2448,10 @@
15272  static int
15273  ahc_aha398XX_setup(struct ahc_softc *ahc)
15274  {
15275 -       ahc_dev_softc_t pci;
15276 +       aic_dev_softc_t pci;
15277  
15278         pci = ahc->dev_softc;
15279 -       switch (ahc_get_pci_slot(pci)) {
15280 +       switch (aic_get_pci_slot(pci)) {
15281         case AHC_398X_SLOT_CHANNEL_A:
15282                 ahc->channel = 'A';
15283                 break;
15284 @@ -2444,7 +2464,7 @@
15285         default:
15286                 printf("adapter at unexpected slot %d\n"
15287                        "unable to map to a channel\n",
15288 -                      ahc_get_pci_slot(pci));
15289 +                      aic_get_pci_slot(pci));
15290                 ahc->channel = 'A';
15291                 break;
15292         }
15293 @@ -2455,10 +2475,10 @@
15294  static int
15295  ahc_aha494XX_setup(struct ahc_softc *ahc)
15296  {
15297 -       ahc_dev_softc_t pci;
15298 +       aic_dev_softc_t pci;
15299  
15300         pci = ahc->dev_softc;
15301 -       switch (ahc_get_pci_slot(pci)) {
15302 +       switch (aic_get_pci_slot(pci)) {
15303         case AHC_494X_SLOT_CHANNEL_A:
15304                 ahc->channel = 'A';
15305                 break;
15306 @@ -2474,7 +2494,7 @@
15307         default:
15308                 printf("adapter at unexpected slot %d\n"
15309                        "unable to map to a channel\n",
15310 -                      ahc_get_pci_slot(pci));
15311 +                      aic_get_pci_slot(pci));
15312                 ahc->channel = 'A';
15313         }
15314         ahc->flags |= AHC_LARGE_SEEPROM;
15315 diff -urN linux-2.4.24.org/drivers/scsi/aic7xxx/aic7xxx_proc.c linux-2.4.24/drivers/scsi/aic7xxx/aic7xxx_proc.c
15316 --- linux-2.4.24.org/drivers/scsi/aic7xxx/aic7xxx_proc.c        2004-01-08 11:57:43.026002475 +0100
15317 +++ linux-2.4.24/drivers/scsi/aic7xxx/aic7xxx_proc.c    2003-12-22 22:46:59.000000000 +0100
15318 @@ -37,7 +37,7 @@
15319   * String handling code courtesy of Gerard Roudier's <groudier@club-internet.fr>
15320   * sym driver.
15321   *
15322 - * $Id$
15323 + * $Id$
15324   */
15325  #include "aic7xxx_osm.h"
15326  #include "aic7xxx_inline.h"
15327 @@ -50,7 +50,7 @@
15328                                       u_int our_id, char channel,
15329                                       u_int target_id, u_int target_offset);
15330  static void    ahc_dump_device_state(struct info_str *info,
15331 -                                     struct ahc_linux_device *dev);
15332 +                                     struct aic_linux_device *dev);
15333  static int     ahc_proc_write_seeprom(struct ahc_softc *ahc,
15334                                        char *buffer, int length);
15335  
15336 @@ -141,7 +141,7 @@
15337                       u_int our_id, char channel, u_int target_id,
15338                       u_int target_offset)
15339  {
15340 -       struct  ahc_linux_target *targ;
15341 +       struct  aic_linux_target *targ;
15342         struct  ahc_initiator_tinfo *tinfo;
15343         struct  ahc_tmode_tstate *tstate;
15344         int     lun;
15345 @@ -163,7 +163,7 @@
15346         ahc_format_transinfo(info, &tinfo->curr);
15347  
15348         for (lun = 0; lun < AHC_NUM_LUNS; lun++) {
15349 -               struct ahc_linux_device *dev;
15350 +               struct aic_linux_device *dev;
15351  
15352                 dev = targ->devices[lun];
15353  
15354 @@ -175,7 +175,7 @@
15355  }
15356  
15357  static void
15358 -ahc_dump_device_state(struct info_str *info, struct ahc_linux_device *dev)
15359 +ahc_dump_device_state(struct info_str *info, struct aic_linux_device *dev)
15360  {
15361         copy_info(info, "\tChannel %c Target %d Lun %d Settings\n",
15362                   dev->target->channel + 'A', dev->target->target, dev->lun);
15363 @@ -204,7 +204,8 @@
15364                 ahc_pause(ahc);
15365  
15366         if (length != sizeof(struct seeprom_config)) {
15367 -               printf("ahc_proc_write_seeprom: incorrect buffer size\n");
15368 +               printf("ahc_proc_write_seeprom: incorrect buffer size %d\n",
15369 +                      length);
15370                 goto done;
15371         }
15372  
15373 @@ -215,7 +216,7 @@
15374         }
15375  
15376         sd.sd_ahc = ahc;
15377 -#if AHC_PCI_CONFIG > 0
15378 +#if AIC_PCI_CONFIG > 0
15379         if ((ahc->chip & AHC_PCI) != 0) {
15380                 sd.sd_control_offset = SEECTL;
15381                 sd.sd_status_offset = SEECTL;
15382 @@ -271,7 +272,7 @@
15383                                   sizeof(struct seeprom_config)/2);
15384                 ahc_read_seeprom(&sd, (uint16_t *)ahc->seep_config,
15385                                  start_addr, sizeof(struct seeprom_config)/2);
15386 -#if AHC_PCI_CONFIG > 0
15387 +#if AIC_PCI_CONFIG > 0
15388                 if ((ahc->chip & AHC_VL) == 0)
15389                         ahc_release_seeprom(&sd);
15390  #endif
15391 diff -urN linux-2.4.24.org/drivers/scsi/aic7xxx/aic7xxx.reg linux-2.4.24/drivers/scsi/aic7xxx/aic7xxx.reg
15392 --- linux-2.4.24.org/drivers/scsi/aic7xxx/aic7xxx.reg   2004-01-08 11:57:43.041999168 +0100
15393 +++ linux-2.4.24/drivers/scsi/aic7xxx/aic7xxx.reg       2003-12-22 22:46:59.000000000 +0100
15394 @@ -39,7 +39,7 @@
15395   *
15396   * $FreeBSD$
15397   */
15398 -VERSION = "$Id$"
15399 +VERSION = "$Id$"
15400  
15401  /*
15402   * This file is processed by the aic7xxx_asm utility for use in assembling
15403 @@ -1306,7 +1306,6 @@
15404          */
15405         MWI_RESIDUAL {
15406                 size            1
15407 -               alias   TARG_IMMEDIATE_SCB
15408         }
15409         /*
15410          * SCBID of the next SCB to be started by the controller.
15411 @@ -1461,6 +1460,7 @@
15412          */
15413         LAST_MSG {
15414                 size            1
15415 +               alias   TARG_IMMEDIATE_SCB
15416         }
15417  
15418         /*
15419 diff -urN linux-2.4.24.org/drivers/scsi/aic7xxx/aic7xxx_reg.h linux-2.4.24/drivers/scsi/aic7xxx/aic7xxx_reg.h
15420 --- linux-2.4.24.org/drivers/scsi/aic7xxx/aic7xxx_reg.h 2004-01-08 11:57:43.024002888 +0100
15421 +++ linux-2.4.24/drivers/scsi/aic7xxx/aic7xxx_reg.h     2003-12-23 00:31:43.000000000 +0100
15422 @@ -2,8 +2,8 @@
15423   * DO NOT EDIT - This file is automatically generated
15424   *              from the following source files:
15425   *
15426 - * $Id$
15427 - * $Id$
15428 + * $Id$
15429 + * $Id$
15430   */
15431  typedef int (ahc_reg_print_t)(u_int, u_int *, u_int);
15432  typedef struct ahc_reg_parse_entry {
15433 @@ -1298,7 +1298,6 @@
15434  #define        CMDSIZE_TABLE_TAIL              0x34
15435  
15436  #define        MWI_RESIDUAL                    0x38
15437 -#define        TARG_IMMEDIATE_SCB              0x38
15438  
15439  #define        NEXT_QUEUED_SCB                 0x39
15440  
15441 @@ -1380,6 +1379,7 @@
15442  #define        RETURN_2                        0x52
15443  
15444  #define        LAST_MSG                        0x53
15445 +#define        TARG_IMMEDIATE_SCB              0x53
15446  
15447  #define        SCSISEQ_TEMPLATE                0x54
15448  #define                ENSELO                  0x40
15449 diff -urN linux-2.4.24.org/drivers/scsi/aic7xxx/aic7xxx_reg_print.c linux-2.4.24/drivers/scsi/aic7xxx/aic7xxx_reg_print.c
15450 --- linux-2.4.24.org/drivers/scsi/aic7xxx/aic7xxx_reg_print.c   2004-01-08 11:57:43.022003301 +0100
15451 +++ linux-2.4.24/drivers/scsi/aic7xxx/aic7xxx_reg_print.c       2003-12-23 00:31:43.000000000 +0100
15452 @@ -2,8 +2,8 @@
15453   * DO NOT EDIT - This file is automatically generated
15454   *              from the following source files:
15455   *
15456 - * $Id$
15457 - * $Id$
15458 + * $Id$
15459 + * $Id$
15460   */
15461  
15462  #include "aic7xxx_osm.h"
15463 diff -urN linux-2.4.24.org/drivers/scsi/aic7xxx/aic7xxx.seq linux-2.4.24/drivers/scsi/aic7xxx/aic7xxx.seq
15464 --- linux-2.4.24.org/drivers/scsi/aic7xxx/aic7xxx.seq   2004-01-08 11:57:43.040999375 +0100
15465 +++ linux-2.4.24/drivers/scsi/aic7xxx/aic7xxx.seq       2003-12-22 22:46:59.000000000 +0100
15466 @@ -40,7 +40,7 @@
15467   * $FreeBSD$
15468   */
15469  
15470 -VERSION = "$Id$"
15471 +VERSION = "$Id$"
15472  PATCH_ARG_LIST = "struct ahc_softc *ahc"
15473  PREFIX = "ahc_"
15474  
15475 @@ -679,6 +679,7 @@
15476                 clr     SCSIBUSL;       /* Prevent bit leakage durint SELTO */
15477         }
15478         and     SXFRCTL0, ~SPIOEN;
15479 +       mvi     SEQ_FLAGS, NOT_IDENTIFIED|NO_CDB_SENT;
15480         test    SSTAT1,REQINIT|BUSFREE  jz .;
15481         test    SSTAT1, BUSFREE jnz poll_for_work;
15482         mvi     MISSED_BUSFREE call set_seqint;
15483 @@ -1097,7 +1098,7 @@
15484                 test    SCB_RESIDUAL_DATACNT[3], SG_LAST_SEG jz dma_mid_sg;
15485                 if ((ahc->flags & AHC_TARGETROLE) != 0) {
15486                         test    SSTAT0, TARGET jz dma_last_sg;
15487 -                       if ((ahc->flags & AHC_TMODE_WIDEODD_BUG) != 0) {
15488 +                       if ((ahc->bugs & AHC_TMODE_WIDEODD_BUG) != 0) {
15489                                 test    DMAPARAMS, DIRECTION jz dma_mid_sg;
15490                         }
15491                 }
15492 diff -urN linux-2.4.24.org/drivers/scsi/aic7xxx/aic7xxx_seq.h linux-2.4.24/drivers/scsi/aic7xxx/aic7xxx_seq.h
15493 --- linux-2.4.24.org/drivers/scsi/aic7xxx/aic7xxx_seq.h 2004-01-08 11:57:43.020003714 +0100
15494 +++ linux-2.4.24/drivers/scsi/aic7xxx/aic7xxx_seq.h     2003-12-23 00:31:43.000000000 +0100
15495 @@ -2,13 +2,13 @@
15496   * DO NOT EDIT - This file is automatically generated
15497   *              from the following source files:
15498   *
15499 - * $Id$
15500 - * $Id$
15501 + * $Id$
15502 + * $Id$
15503   */
15504  static uint8_t seqprog[] = {
15505         0xb2, 0x00, 0x00, 0x08,
15506         0xf7, 0x11, 0x22, 0x08,
15507 -       0x00, 0x65, 0xec, 0x59,
15508 +       0x00, 0x65, 0xee, 0x59,
15509         0xf7, 0x01, 0x02, 0x08,
15510         0xff, 0x6a, 0x24, 0x08,
15511         0x40, 0x00, 0x40, 0x68,
15512 @@ -21,15 +21,15 @@
15513         0x01, 0x4d, 0xc8, 0x30,
15514         0x00, 0x4c, 0x12, 0x70,
15515         0x01, 0x39, 0xa2, 0x30,
15516 -       0x00, 0x6a, 0xc0, 0x5e,
15517 +       0x00, 0x6a, 0xc2, 0x5e,
15518         0x01, 0x51, 0x20, 0x31,
15519         0x01, 0x57, 0xae, 0x00,
15520         0x0d, 0x6a, 0x76, 0x00,
15521 -       0x00, 0x51, 0x12, 0x5e,
15522 +       0x00, 0x51, 0x14, 0x5e,
15523         0x01, 0x51, 0xc8, 0x30,
15524         0x00, 0x39, 0xc8, 0x60,
15525         0x00, 0xbb, 0x30, 0x70,
15526 -       0xc1, 0x6a, 0xd8, 0x5e,
15527 +       0xc1, 0x6a, 0xda, 0x5e,
15528         0x01, 0xbf, 0x72, 0x30,
15529         0x01, 0x40, 0x7e, 0x31,
15530         0x01, 0x90, 0x80, 0x30,
15531 @@ -49,10 +49,10 @@
15532         0x08, 0x6a, 0x78, 0x00,
15533         0x01, 0x50, 0xc8, 0x30,
15534         0xe0, 0x6a, 0xcc, 0x00,
15535 -       0x48, 0x6a, 0xfc, 0x5d,
15536 +       0x48, 0x6a, 0xfe, 0x5d,
15537         0x01, 0x6a, 0xdc, 0x01,
15538         0x88, 0x6a, 0xcc, 0x00,
15539 -       0x48, 0x6a, 0xfc, 0x5d,
15540 +       0x48, 0x6a, 0xfe, 0x5d,
15541         0x01, 0x6a, 0x26, 0x01,
15542         0xf0, 0x19, 0x7a, 0x08,
15543         0x0f, 0x18, 0xc8, 0x08,
15544 @@ -93,7 +93,7 @@
15545         0x00, 0x65, 0x20, 0x41,
15546         0x02, 0x57, 0xae, 0x00,
15547         0x00, 0x65, 0x9e, 0x40,
15548 -       0x61, 0x6a, 0xd8, 0x5e,
15549 +       0x61, 0x6a, 0xda, 0x5e,
15550         0x08, 0x51, 0x20, 0x71,
15551         0x02, 0x0b, 0xb2, 0x78,
15552         0x00, 0x65, 0xae, 0x40,
15553 @@ -106,7 +106,7 @@
15554         0x80, 0x3d, 0x7a, 0x00,
15555         0x20, 0x6a, 0x16, 0x00,
15556         0x00, 0x65, 0xcc, 0x41,
15557 -       0x00, 0x65, 0xb2, 0x5e,
15558 +       0x00, 0x65, 0xb4, 0x5e,
15559         0x00, 0x65, 0x12, 0x40,
15560         0x20, 0x11, 0xd2, 0x68,
15561         0x20, 0x6a, 0x18, 0x00,
15562 @@ -140,27 +140,27 @@
15563         0x80, 0x0b, 0xc4, 0x79,
15564         0x12, 0x01, 0x02, 0x00,
15565         0x01, 0xab, 0xac, 0x30,
15566 -       0xe4, 0x6a, 0x6e, 0x5d,
15567 +       0xe4, 0x6a, 0x70, 0x5d,
15568         0x40, 0x6a, 0x16, 0x00,
15569 -       0x80, 0x3e, 0x84, 0x5d,
15570 +       0x80, 0x3e, 0x86, 0x5d,
15571         0x20, 0xb8, 0x18, 0x79,
15572 -       0x20, 0x6a, 0x84, 0x5d,
15573 -       0x00, 0xab, 0x84, 0x5d,
15574 +       0x20, 0x6a, 0x86, 0x5d,
15575 +       0x00, 0xab, 0x86, 0x5d,
15576         0x01, 0xa9, 0x78, 0x30,
15577         0x10, 0xb8, 0x20, 0x79,
15578 -       0xe4, 0x6a, 0x6e, 0x5d,
15579 +       0xe4, 0x6a, 0x70, 0x5d,
15580         0x00, 0x65, 0xae, 0x40,
15581         0x10, 0x03, 0x3c, 0x69,
15582         0x08, 0x3c, 0x5a, 0x69,
15583         0x04, 0x3c, 0x92, 0x69,
15584         0x02, 0x3c, 0x98, 0x69,
15585         0x01, 0x3c, 0x44, 0x79,
15586 -       0xff, 0x6a, 0x70, 0x00,
15587 +       0xff, 0x6a, 0xa6, 0x00,
15588         0x00, 0x65, 0xa4, 0x59,
15589 -       0x00, 0x6a, 0xc0, 0x5e,
15590 -       0xff, 0x38, 0x30, 0x71,
15591 +       0x00, 0x6a, 0xc2, 0x5e,
15592 +       0xff, 0x53, 0x30, 0x71,
15593         0x0d, 0x6a, 0x76, 0x00,
15594 -       0x00, 0x38, 0x12, 0x5e,
15595 +       0x00, 0x53, 0x14, 0x5e,
15596         0x00, 0x65, 0xea, 0x58,
15597         0x12, 0x01, 0x02, 0x00,
15598         0x00, 0x65, 0x18, 0x41,
15599 @@ -168,10 +168,10 @@
15600         0x00, 0x65, 0xf2, 0x58,
15601         0xfd, 0x57, 0xae, 0x08,
15602         0x00, 0x65, 0xae, 0x40,
15603 -       0xe4, 0x6a, 0x6e, 0x5d,
15604 +       0xe4, 0x6a, 0x70, 0x5d,
15605         0x20, 0x3c, 0x4a, 0x79,
15606 -       0x02, 0x6a, 0x84, 0x5d,
15607 -       0x04, 0x6a, 0x84, 0x5d,
15608 +       0x02, 0x6a, 0x86, 0x5d,
15609 +       0x04, 0x6a, 0x86, 0x5d,
15610         0x01, 0x03, 0x4c, 0x69,
15611         0xf7, 0x11, 0x22, 0x08,
15612         0xff, 0x6a, 0x24, 0x08,
15613 @@ -182,13 +182,13 @@
15614         0x80, 0x86, 0xc8, 0x08,
15615         0x01, 0x4f, 0xc8, 0x30,
15616         0x00, 0x50, 0x6c, 0x61,
15617 -       0xc4, 0x6a, 0x6e, 0x5d,
15618 +       0xc4, 0x6a, 0x70, 0x5d,
15619         0x40, 0x3c, 0x68, 0x79,
15620 -       0x28, 0x6a, 0x84, 0x5d,
15621 +       0x28, 0x6a, 0x86, 0x5d,
15622         0x00, 0x65, 0x4c, 0x41,
15623 -       0x08, 0x6a, 0x84, 0x5d,
15624 +       0x08, 0x6a, 0x86, 0x5d,
15625         0x00, 0x65, 0x4c, 0x41,
15626 -       0x84, 0x6a, 0x6e, 0x5d,
15627 +       0x84, 0x6a, 0x70, 0x5d,
15628         0x00, 0x65, 0xf2, 0x58,
15629         0x01, 0x66, 0xc8, 0x30,
15630         0x01, 0x64, 0xd8, 0x31,
15631 @@ -208,16 +208,16 @@
15632         0xf7, 0x3c, 0x78, 0x08,
15633         0x00, 0x65, 0x20, 0x41,
15634         0x40, 0xaa, 0x7e, 0x10,
15635 -       0x04, 0xaa, 0x6e, 0x5d,
15636 -       0x00, 0x65, 0x56, 0x42,
15637 -       0xc4, 0x6a, 0x6e, 0x5d,
15638 +       0x04, 0xaa, 0x70, 0x5d,
15639 +       0x00, 0x65, 0x58, 0x42,
15640 +       0xc4, 0x6a, 0x70, 0x5d,
15641         0xc0, 0x6a, 0x7e, 0x00,
15642 -       0x00, 0xa8, 0x84, 0x5d,
15643 +       0x00, 0xa8, 0x86, 0x5d,
15644         0xe4, 0x6a, 0x06, 0x00,
15645 -       0x00, 0x6a, 0x84, 0x5d,
15646 +       0x00, 0x6a, 0x86, 0x5d,
15647         0x00, 0x65, 0x4c, 0x41,
15648         0x10, 0x3c, 0xa8, 0x69,
15649 -       0x00, 0xbb, 0x8a, 0x44,
15650 +       0x00, 0xbb, 0x8c, 0x44,
15651         0x18, 0x6a, 0xda, 0x01,
15652         0x01, 0x69, 0xd8, 0x31,
15653         0x1c, 0x6a, 0xd0, 0x01,
15654 @@ -227,31 +227,32 @@
15655         0x01, 0x93, 0x26, 0x01,
15656         0x03, 0x6a, 0x2a, 0x01,
15657         0x01, 0x69, 0x32, 0x31,
15658 -       0x1c, 0x6a, 0xe0, 0x5d,
15659 +       0x1c, 0x6a, 0xe2, 0x5d,
15660         0x0a, 0x93, 0x26, 0x01,
15661 -       0x00, 0x65, 0xa8, 0x5e,
15662 +       0x00, 0x65, 0xaa, 0x5e,
15663         0x01, 0x50, 0xa0, 0x18,
15664         0x02, 0x6a, 0x22, 0x05,
15665         0x1a, 0x01, 0x02, 0x00,
15666         0x80, 0x6a, 0x74, 0x00,
15667         0x40, 0x6a, 0x78, 0x00,
15668         0x40, 0x6a, 0x16, 0x00,
15669 -       0x00, 0x65, 0xd8, 0x5d,
15670 +       0x00, 0x65, 0xda, 0x5d,
15671         0x01, 0x3f, 0xc8, 0x30,
15672 -       0xbf, 0x64, 0x56, 0x7a,
15673 -       0x80, 0x64, 0x9e, 0x73,
15674 -       0xa0, 0x64, 0x00, 0x74,
15675 -       0xc0, 0x64, 0xf4, 0x73,
15676 -       0xe0, 0x64, 0x30, 0x74,
15677 -       0x01, 0x6a, 0xd8, 0x5e,
15678 +       0xbf, 0x64, 0x58, 0x7a,
15679 +       0x80, 0x64, 0xa0, 0x73,
15680 +       0xa0, 0x64, 0x02, 0x74,
15681 +       0xc0, 0x64, 0xf6, 0x73,
15682 +       0xe0, 0x64, 0x32, 0x74,
15683 +       0x01, 0x6a, 0xda, 0x5e,
15684         0x00, 0x65, 0xcc, 0x41,
15685         0xf7, 0x11, 0x22, 0x08,
15686         0x01, 0x06, 0xd4, 0x30,
15687         0xff, 0x6a, 0x24, 0x08,
15688         0xf7, 0x01, 0x02, 0x08,
15689 -       0x09, 0x0c, 0xe6, 0x79,
15690 +       0xc0, 0x6a, 0x78, 0x00,
15691 +       0x09, 0x0c, 0xe8, 0x79,
15692         0x08, 0x0c, 0x04, 0x68,
15693 -       0xb1, 0x6a, 0xd8, 0x5e,
15694 +       0xb1, 0x6a, 0xda, 0x5e,
15695         0xff, 0x6a, 0x26, 0x09,
15696         0x12, 0x01, 0x02, 0x00,
15697         0x02, 0x6a, 0x08, 0x30,
15698 @@ -264,29 +265,29 @@
15699         0x00, 0xa5, 0x4a, 0x21,
15700         0x00, 0xa6, 0x4c, 0x21,
15701         0x00, 0xa7, 0x4e, 0x25,
15702 -       0x08, 0xeb, 0xdc, 0x7e,
15703 -       0x80, 0xeb, 0x06, 0x7a,
15704 +       0x08, 0xeb, 0xde, 0x7e,
15705 +       0x80, 0xeb, 0x08, 0x7a,
15706         0xff, 0x6a, 0xd6, 0x09,
15707 -       0x08, 0xeb, 0x0a, 0x6a,
15708 +       0x08, 0xeb, 0x0c, 0x6a,
15709         0xff, 0x6a, 0xd4, 0x0c,
15710 -       0x80, 0xa3, 0xdc, 0x6e,
15711 -       0x88, 0xeb, 0x20, 0x72,
15712 -       0x08, 0xeb, 0xdc, 0x6e,
15713 -       0x04, 0xea, 0x24, 0xe2,
15714 -       0x08, 0xee, 0xdc, 0x6e,
15715 +       0x80, 0xa3, 0xde, 0x6e,
15716 +       0x88, 0xeb, 0x22, 0x72,
15717 +       0x08, 0xeb, 0xde, 0x6e,
15718 +       0x04, 0xea, 0x26, 0xe2,
15719 +       0x08, 0xee, 0xde, 0x6e,
15720         0x04, 0x6a, 0xd0, 0x81,
15721         0x05, 0xa4, 0xc0, 0x89,
15722         0x03, 0xa5, 0xc2, 0x31,
15723         0x09, 0x6a, 0xd6, 0x05,
15724 -       0x00, 0x65, 0x08, 0x5a,
15725 +       0x00, 0x65, 0x0a, 0x5a,
15726         0x06, 0xa4, 0xd4, 0x89,
15727 -       0x80, 0x94, 0xdc, 0x7e,
15728 +       0x80, 0x94, 0xde, 0x7e,
15729         0x07, 0xe9, 0x10, 0x31,
15730         0x01, 0xe9, 0x46, 0x31,
15731 -       0x00, 0xa3, 0xba, 0x5e,
15732 -       0x00, 0x65, 0xfa, 0x59,
15733 +       0x00, 0xa3, 0xbc, 0x5e,
15734 +       0x00, 0x65, 0xfc, 0x59,
15735         0x01, 0xa4, 0xca, 0x30,
15736 -       0x80, 0xa3, 0x34, 0x7a,
15737 +       0x80, 0xa3, 0x36, 0x7a,
15738         0x02, 0x65, 0xca, 0x00,
15739         0x01, 0x65, 0xf8, 0x31,
15740         0x80, 0x93, 0x26, 0x01,
15741 @@ -294,162 +295,162 @@
15742         0x01, 0x8c, 0xc8, 0x30,
15743         0x00, 0x88, 0xc8, 0x18,
15744         0x02, 0x64, 0xc8, 0x88,
15745 -       0xff, 0x64, 0xdc, 0x7e,
15746 -       0xff, 0x8d, 0x4a, 0x6a,
15747 -       0xff, 0x8e, 0x4a, 0x6a,
15748 +       0xff, 0x64, 0xde, 0x7e,
15749 +       0xff, 0x8d, 0x4c, 0x6a,
15750 +       0xff, 0x8e, 0x4c, 0x6a,
15751         0x03, 0x8c, 0xd4, 0x98,
15752 -       0x00, 0x65, 0xdc, 0x56,
15753 +       0x00, 0x65, 0xde, 0x56,
15754         0x01, 0x64, 0x70, 0x30,
15755         0xff, 0x64, 0xc8, 0x10,
15756         0x01, 0x64, 0xc8, 0x18,
15757         0x00, 0x8c, 0x18, 0x19,
15758         0xff, 0x8d, 0x1a, 0x21,
15759         0xff, 0x8e, 0x1c, 0x25,
15760 -       0xc0, 0x3c, 0x5a, 0x7a,
15761 -       0x21, 0x6a, 0xd8, 0x5e,
15762 +       0xc0, 0x3c, 0x5c, 0x7a,
15763 +       0x21, 0x6a, 0xda, 0x5e,
15764         0xa8, 0x6a, 0x76, 0x00,
15765         0x79, 0x6a, 0x76, 0x00,
15766 -       0x40, 0x3f, 0x62, 0x6a,
15767 +       0x40, 0x3f, 0x64, 0x6a,
15768         0x04, 0x3b, 0x76, 0x00,
15769         0x04, 0x6a, 0xd4, 0x81,
15770 -       0x20, 0x3c, 0x6a, 0x7a,
15771 -       0x51, 0x6a, 0xd8, 0x5e,
15772 -       0x00, 0x65, 0x82, 0x42,
15773 +       0x20, 0x3c, 0x6c, 0x7a,
15774 +       0x51, 0x6a, 0xda, 0x5e,
15775 +       0x00, 0x65, 0x84, 0x42,
15776         0x20, 0x3c, 0x78, 0x00,
15777 -       0x00, 0xb3, 0xba, 0x5e,
15778 +       0x00, 0xb3, 0xbc, 0x5e,
15779         0x07, 0xac, 0x10, 0x31,
15780         0x05, 0xb3, 0x46, 0x31,
15781         0x88, 0x6a, 0xcc, 0x00,
15782 -       0xac, 0x6a, 0xee, 0x5d,
15783 +       0xac, 0x6a, 0xf0, 0x5d,
15784         0xa3, 0x6a, 0xcc, 0x00,
15785 -       0xb3, 0x6a, 0xf2, 0x5d,
15786 -       0x00, 0x65, 0x3a, 0x5a,
15787 +       0xb3, 0x6a, 0xf4, 0x5d,
15788 +       0x00, 0x65, 0x3c, 0x5a,
15789         0xfd, 0xa4, 0x48, 0x09,
15790         0x03, 0x8c, 0x10, 0x30,
15791 -       0x00, 0x65, 0xe6, 0x5d,
15792 -       0x01, 0xa4, 0x94, 0x7a,
15793 +       0x00, 0x65, 0xe8, 0x5d,
15794 +       0x01, 0xa4, 0x96, 0x7a,
15795         0x04, 0x3b, 0x76, 0x08,
15796         0x01, 0x3b, 0x26, 0x31,
15797         0x80, 0x02, 0x04, 0x00,
15798 -       0x10, 0x0c, 0x8a, 0x7a,
15799 -       0x03, 0x9e, 0x8c, 0x6a,
15800 +       0x10, 0x0c, 0x8c, 0x7a,
15801 +       0x03, 0x9e, 0x8e, 0x6a,
15802         0x7f, 0x02, 0x04, 0x08,
15803 -       0x91, 0x6a, 0xd8, 0x5e,
15804 +       0x91, 0x6a, 0xda, 0x5e,
15805         0x00, 0x65, 0xcc, 0x41,
15806         0x01, 0xa4, 0xca, 0x30,
15807 -       0x80, 0xa3, 0x9a, 0x7a,
15808 +       0x80, 0xa3, 0x9c, 0x7a,
15809         0x02, 0x65, 0xca, 0x00,
15810         0x01, 0x65, 0xf8, 0x31,
15811         0x01, 0x3b, 0x26, 0x31,
15812 -       0x00, 0x65, 0x0e, 0x5a,
15813 -       0x01, 0xfc, 0xa8, 0x6a,
15814 -       0x80, 0x0b, 0x9e, 0x6a,
15815 -       0x10, 0x0c, 0x9e, 0x7a,
15816 -       0x20, 0x93, 0x9e, 0x6a,
15817 +       0x00, 0x65, 0x10, 0x5a,
15818 +       0x01, 0xfc, 0xaa, 0x6a,
15819 +       0x80, 0x0b, 0xa0, 0x6a,
15820 +       0x10, 0x0c, 0xa0, 0x7a,
15821 +       0x20, 0x93, 0xa0, 0x6a,
15822         0x02, 0x93, 0x26, 0x01,
15823 -       0x02, 0xfc, 0xb2, 0x7a,
15824 -       0x40, 0x0d, 0xc6, 0x6a,
15825 +       0x02, 0xfc, 0xb4, 0x7a,
15826 +       0x40, 0x0d, 0xc8, 0x6a,
15827         0x01, 0xa4, 0x48, 0x01,
15828 -       0x00, 0x65, 0xc6, 0x42,
15829 -       0x40, 0x0d, 0xb8, 0x6a,
15830 -       0x00, 0x65, 0x0e, 0x5a,
15831 -       0x00, 0x65, 0xaa, 0x42,
15832 -       0x80, 0xfc, 0xc2, 0x7a,
15833 -       0x80, 0xa4, 0xc2, 0x6a,
15834 +       0x00, 0x65, 0xc8, 0x42,
15835 +       0x40, 0x0d, 0xba, 0x6a,
15836 +       0x00, 0x65, 0x10, 0x5a,
15837 +       0x00, 0x65, 0xac, 0x42,
15838 +       0x80, 0xfc, 0xc4, 0x7a,
15839 +       0x80, 0xa4, 0xc4, 0x6a,
15840         0xff, 0xa5, 0x4a, 0x19,
15841         0xff, 0xa6, 0x4c, 0x21,
15842         0xff, 0xa7, 0x4e, 0x21,
15843         0xf8, 0xfc, 0x48, 0x09,
15844         0x7f, 0xa3, 0x46, 0x09,
15845 -       0x04, 0x3b, 0xe2, 0x6a,
15846 +       0x04, 0x3b, 0xe4, 0x6a,
15847         0x02, 0x93, 0x26, 0x01,
15848 -       0x01, 0x94, 0xc8, 0x7a,
15849 -       0x01, 0x94, 0xc8, 0x7a,
15850 -       0x01, 0x94, 0xc8, 0x7a,
15851 -       0x01, 0x94, 0xc8, 0x7a,
15852 -       0x01, 0x94, 0xc8, 0x7a,
15853 -       0x01, 0xa4, 0xe0, 0x7a,
15854 -       0x01, 0xfc, 0xd6, 0x7a,
15855 -       0x01, 0x94, 0xe2, 0x6a,
15856 -       0x01, 0x94, 0xe2, 0x6a,
15857 -       0x01, 0x94, 0xe2, 0x6a,
15858 -       0x00, 0x65, 0x82, 0x42,
15859 -       0x01, 0x94, 0xe0, 0x7a,
15860 -       0x10, 0x94, 0xe2, 0x6a,
15861 +       0x01, 0x94, 0xca, 0x7a,
15862 +       0x01, 0x94, 0xca, 0x7a,
15863 +       0x01, 0x94, 0xca, 0x7a,
15864 +       0x01, 0x94, 0xca, 0x7a,
15865 +       0x01, 0x94, 0xca, 0x7a,
15866 +       0x01, 0xa4, 0xe2, 0x7a,
15867 +       0x01, 0xfc, 0xd8, 0x7a,
15868 +       0x01, 0x94, 0xe4, 0x6a,
15869 +       0x01, 0x94, 0xe4, 0x6a,
15870 +       0x01, 0x94, 0xe4, 0x6a,
15871 +       0x00, 0x65, 0x84, 0x42,
15872 +       0x01, 0x94, 0xe2, 0x7a,
15873 +       0x10, 0x94, 0xe4, 0x6a,
15874         0xd7, 0x93, 0x26, 0x09,
15875 -       0x28, 0x93, 0xe6, 0x6a,
15876 +       0x28, 0x93, 0xe8, 0x6a,
15877         0x01, 0x85, 0x0a, 0x01,
15878 -       0x02, 0xfc, 0xee, 0x6a,
15879 +       0x02, 0xfc, 0xf0, 0x6a,
15880         0x01, 0x14, 0x46, 0x31,
15881         0xff, 0x6a, 0x10, 0x09,
15882         0xfe, 0x85, 0x0a, 0x09,
15883 -       0xff, 0x38, 0xfc, 0x6a,
15884 -       0x80, 0xa3, 0xfc, 0x7a,
15885 -       0x80, 0x0b, 0xfa, 0x7a,
15886 -       0x04, 0x3b, 0xfc, 0x7a,
15887 +       0xff, 0x38, 0xfe, 0x6a,
15888 +       0x80, 0xa3, 0xfe, 0x7a,
15889 +       0x80, 0x0b, 0xfc, 0x7a,
15890 +       0x04, 0x3b, 0xfe, 0x7a,
15891         0xbf, 0x3b, 0x76, 0x08,
15892         0x01, 0x3b, 0x26, 0x31,
15893 -       0x00, 0x65, 0x0e, 0x5a,
15894 -       0x01, 0x0b, 0x0a, 0x6b,
15895 -       0x10, 0x0c, 0xfe, 0x7a,
15896 -       0x04, 0x93, 0x08, 0x6b,
15897 -       0x01, 0x94, 0x06, 0x7b,
15898 -       0x10, 0x94, 0x08, 0x6b,
15899 +       0x00, 0x65, 0x10, 0x5a,
15900 +       0x01, 0x0b, 0x0c, 0x6b,
15901 +       0x10, 0x0c, 0x00, 0x7b,
15902 +       0x04, 0x93, 0x0a, 0x6b,
15903 +       0x01, 0x94, 0x08, 0x7b,
15904 +       0x10, 0x94, 0x0a, 0x6b,
15905         0xc7, 0x93, 0x26, 0x09,
15906         0x01, 0x99, 0xd4, 0x30,
15907 -       0x38, 0x93, 0x0c, 0x6b,
15908 -       0xff, 0x08, 0x5a, 0x6b,
15909 -       0xff, 0x09, 0x5a, 0x6b,
15910 -       0xff, 0x0a, 0x5a, 0x6b,
15911 -       0xff, 0x38, 0x28, 0x7b,
15912 +       0x38, 0x93, 0x0e, 0x6b,
15913 +       0xff, 0x08, 0x5c, 0x6b,
15914 +       0xff, 0x09, 0x5c, 0x6b,
15915 +       0xff, 0x0a, 0x5c, 0x6b,
15916 +       0xff, 0x38, 0x2a, 0x7b,
15917         0x04, 0x14, 0x10, 0x31,
15918         0x01, 0x38, 0x18, 0x31,
15919         0x02, 0x6a, 0x1a, 0x31,
15920         0x88, 0x6a, 0xcc, 0x00,
15921 -       0x14, 0x6a, 0xf4, 0x5d,
15922 -       0x00, 0x38, 0xe0, 0x5d,
15923 +       0x14, 0x6a, 0xf6, 0x5d,
15924 +       0x00, 0x38, 0xe2, 0x5d,
15925         0xff, 0x6a, 0x70, 0x08,
15926 -       0x00, 0x65, 0x54, 0x43,
15927 -       0x80, 0xa3, 0x2e, 0x7b,
15928 +       0x00, 0x65, 0x56, 0x43,
15929 +       0x80, 0xa3, 0x30, 0x7b,
15930         0x01, 0xa4, 0x48, 0x01,
15931 -       0x00, 0x65, 0x5a, 0x43,
15932 -       0x08, 0xeb, 0x34, 0x7b,
15933 -       0x00, 0x65, 0x0e, 0x5a,
15934 -       0x08, 0xeb, 0x30, 0x6b,
15935 +       0x00, 0x65, 0x5c, 0x43,
15936 +       0x08, 0xeb, 0x36, 0x7b,
15937 +       0x00, 0x65, 0x10, 0x5a,
15938 +       0x08, 0xeb, 0x32, 0x6b,
15939         0x07, 0xe9, 0x10, 0x31,
15940         0x01, 0xe9, 0xca, 0x30,
15941         0x01, 0x65, 0x46, 0x31,
15942 -       0x00, 0x6a, 0xba, 0x5e,
15943 +       0x00, 0x6a, 0xbc, 0x5e,
15944         0x88, 0x6a, 0xcc, 0x00,
15945 -       0xa4, 0x6a, 0xf4, 0x5d,
15946 -       0x08, 0x6a, 0xe0, 0x5d,
15947 +       0xa4, 0x6a, 0xf6, 0x5d,
15948 +       0x08, 0x6a, 0xe2, 0x5d,
15949         0x0d, 0x93, 0x26, 0x01,
15950 -       0x00, 0x65, 0xa8, 0x5e,
15951 +       0x00, 0x65, 0xaa, 0x5e,
15952         0x88, 0x6a, 0xcc, 0x00,
15953 -       0x00, 0x65, 0x8a, 0x5e,
15954 +       0x00, 0x65, 0x8c, 0x5e,
15955         0x01, 0x99, 0x46, 0x31,
15956 -       0x00, 0xa3, 0xba, 0x5e,
15957 +       0x00, 0xa3, 0xbc, 0x5e,
15958         0x01, 0x88, 0x10, 0x31,
15959 -       0x00, 0x65, 0x3a, 0x5a,
15960 -       0x00, 0x65, 0xfa, 0x59,
15961 +       0x00, 0x65, 0x3c, 0x5a,
15962 +       0x00, 0x65, 0xfc, 0x59,
15963         0x03, 0x8c, 0x10, 0x30,
15964 -       0x00, 0x65, 0xe6, 0x5d,
15965 -       0x80, 0x0b, 0x82, 0x6a,
15966 -       0x80, 0x0b, 0x62, 0x6b,
15967 -       0x01, 0x0c, 0x5c, 0x7b,
15968 -       0x10, 0x0c, 0x82, 0x7a,
15969 -       0x03, 0x9e, 0x82, 0x6a,
15970 -       0x00, 0x65, 0x04, 0x5a,
15971 -       0x00, 0x6a, 0xba, 0x5e,
15972 -       0x01, 0xa4, 0x82, 0x6b,
15973 -       0xff, 0x38, 0x78, 0x7b,
15974 +       0x00, 0x65, 0xe8, 0x5d,
15975 +       0x80, 0x0b, 0x84, 0x6a,
15976 +       0x80, 0x0b, 0x64, 0x6b,
15977 +       0x01, 0x0c, 0x5e, 0x7b,
15978 +       0x10, 0x0c, 0x84, 0x7a,
15979 +       0x03, 0x9e, 0x84, 0x6a,
15980 +       0x00, 0x65, 0x06, 0x5a,
15981 +       0x00, 0x6a, 0xbc, 0x5e,
15982 +       0x01, 0xa4, 0x84, 0x6b,
15983 +       0xff, 0x38, 0x7a, 0x7b,
15984         0x01, 0x38, 0xc8, 0x30,
15985         0x00, 0x08, 0x40, 0x19,
15986         0xff, 0x6a, 0xc8, 0x08,
15987         0x00, 0x09, 0x42, 0x21,
15988         0x00, 0x0a, 0x44, 0x21,
15989         0xff, 0x6a, 0x70, 0x08,
15990 -       0x00, 0x65, 0x7a, 0x43,
15991 +       0x00, 0x65, 0x7c, 0x43,
15992         0x03, 0x08, 0x40, 0x31,
15993         0x03, 0x08, 0x40, 0x31,
15994         0x01, 0x08, 0x40, 0x31,
15995 @@ -461,16 +462,16 @@
15996         0x04, 0x3c, 0xcc, 0x79,
15997         0xfb, 0x3c, 0x78, 0x08,
15998         0x04, 0x93, 0x20, 0x79,
15999 -       0x01, 0x0c, 0x8e, 0x6b,
16000 +       0x01, 0x0c, 0x90, 0x6b,
16001         0x80, 0xba, 0x20, 0x79,
16002         0x80, 0x04, 0x20, 0x79,
16003 -       0xe4, 0x6a, 0x6e, 0x5d,
16004 -       0x23, 0x6a, 0x84, 0x5d,
16005 -       0x01, 0x6a, 0x84, 0x5d,
16006 +       0xe4, 0x6a, 0x70, 0x5d,
16007 +       0x23, 0x6a, 0x86, 0x5d,
16008 +       0x01, 0x6a, 0x86, 0x5d,
16009         0x00, 0x65, 0x20, 0x41,
16010         0x00, 0x65, 0xcc, 0x41,
16011 -       0x80, 0x3c, 0xa2, 0x7b,
16012 -       0x21, 0x6a, 0xd8, 0x5e,
16013 +       0x80, 0x3c, 0xa4, 0x7b,
16014 +       0x21, 0x6a, 0xda, 0x5e,
16015         0x01, 0xbc, 0x18, 0x31,
16016         0x02, 0x6a, 0x1a, 0x31,
16017         0x02, 0x6a, 0xf8, 0x01,
16018 @@ -480,16 +481,16 @@
16019         0xff, 0x6a, 0x12, 0x08,
16020         0xff, 0x6a, 0x14, 0x08,
16021         0xf3, 0xbc, 0xd4, 0x18,
16022 -       0xa0, 0x6a, 0xc8, 0x53,
16023 +       0xa0, 0x6a, 0xca, 0x53,
16024         0x04, 0xa0, 0x10, 0x31,
16025         0xac, 0x6a, 0x26, 0x01,
16026         0x04, 0xa0, 0x10, 0x31,
16027         0x03, 0x08, 0x18, 0x31,
16028         0x88, 0x6a, 0xcc, 0x00,
16029 -       0xa0, 0x6a, 0xf4, 0x5d,
16030 -       0x00, 0xbc, 0xe0, 0x5d,
16031 +       0xa0, 0x6a, 0xf6, 0x5d,
16032 +       0x00, 0xbc, 0xe2, 0x5d,
16033         0x3d, 0x6a, 0x26, 0x01,
16034 -       0x00, 0x65, 0xe0, 0x43,
16035 +       0x00, 0x65, 0xe2, 0x43,
16036         0xff, 0x6a, 0x10, 0x09,
16037         0xa4, 0x6a, 0x26, 0x01,
16038         0x0c, 0xa0, 0x32, 0x31,
16039 @@ -499,128 +500,128 @@
16040         0x36, 0x6a, 0x26, 0x01,
16041         0x02, 0x93, 0x26, 0x01,
16042         0x35, 0x6a, 0x26, 0x01,
16043 -       0x00, 0x65, 0x9c, 0x5e,
16044 -       0x00, 0x65, 0x9c, 0x5e,
16045 +       0x00, 0x65, 0x9e, 0x5e,
16046 +       0x00, 0x65, 0x9e, 0x5e,
16047         0x02, 0x93, 0x26, 0x01,
16048         0xbf, 0x3c, 0x78, 0x08,
16049 -       0x04, 0x0b, 0xe6, 0x6b,
16050 -       0x10, 0x0c, 0xe2, 0x7b,
16051 -       0x01, 0x03, 0xe6, 0x6b,
16052 -       0x20, 0x93, 0xe8, 0x6b,
16053 -       0x04, 0x0b, 0xee, 0x6b,
16054 +       0x04, 0x0b, 0xe8, 0x6b,
16055 +       0x10, 0x0c, 0xe4, 0x7b,
16056 +       0x01, 0x03, 0xe8, 0x6b,
16057 +       0x20, 0x93, 0xea, 0x6b,
16058 +       0x04, 0x0b, 0xf0, 0x6b,
16059         0x40, 0x3c, 0x78, 0x00,
16060         0xc7, 0x93, 0x26, 0x09,
16061 -       0x38, 0x93, 0xf0, 0x6b,
16062 +       0x38, 0x93, 0xf2, 0x6b,
16063         0x00, 0x65, 0xcc, 0x41,
16064 -       0x80, 0x3c, 0x56, 0x6c,
16065 +       0x80, 0x3c, 0x58, 0x6c,
16066         0x01, 0x06, 0x50, 0x31,
16067         0x80, 0xb8, 0x70, 0x01,
16068         0x00, 0x65, 0xcc, 0x41,
16069         0x10, 0x3f, 0x06, 0x00,
16070         0x10, 0x6a, 0x06, 0x00,
16071         0x01, 0x3a, 0xca, 0x30,
16072 -       0x80, 0x65, 0x1c, 0x64,
16073 -       0x10, 0xb8, 0x40, 0x6c,
16074 +       0x80, 0x65, 0x1e, 0x64,
16075 +       0x10, 0xb8, 0x42, 0x6c,
16076         0xc0, 0x3e, 0xca, 0x00,
16077 -       0x40, 0xb8, 0x0c, 0x6c,
16078 +       0x40, 0xb8, 0x0e, 0x6c,
16079         0xbf, 0x65, 0xca, 0x08,
16080 -       0x20, 0xb8, 0x20, 0x7c,
16081 +       0x20, 0xb8, 0x22, 0x7c,
16082         0x01, 0x65, 0x0c, 0x30,
16083 -       0x00, 0x65, 0xd8, 0x5d,
16084 -       0xa0, 0x3f, 0x28, 0x64,
16085 +       0x00, 0x65, 0xda, 0x5d,
16086 +       0xa0, 0x3f, 0x2a, 0x64,
16087         0x23, 0xb8, 0x0c, 0x08,
16088 -       0x00, 0x65, 0xd8, 0x5d,
16089 -       0xa0, 0x3f, 0x28, 0x64,
16090 -       0x00, 0xbb, 0x20, 0x44,
16091 -       0xff, 0x65, 0x20, 0x64,
16092 -       0x00, 0x65, 0x40, 0x44,
16093 +       0x00, 0x65, 0xda, 0x5d,
16094 +       0xa0, 0x3f, 0x2a, 0x64,
16095 +       0x00, 0xbb, 0x22, 0x44,
16096 +       0xff, 0x65, 0x22, 0x64,
16097 +       0x00, 0x65, 0x42, 0x44,
16098         0x40, 0x6a, 0x18, 0x00,
16099         0x01, 0x65, 0x0c, 0x30,
16100 -       0x00, 0x65, 0xd8, 0x5d,
16101 -       0xa0, 0x3f, 0xfc, 0x73,
16102 +       0x00, 0x65, 0xda, 0x5d,
16103 +       0xa0, 0x3f, 0xfe, 0x73,
16104         0x40, 0x6a, 0x18, 0x00,
16105         0x01, 0x3a, 0xa6, 0x30,
16106         0x08, 0x6a, 0x74, 0x00,
16107         0x00, 0x65, 0xcc, 0x41,
16108 -       0x64, 0x6a, 0x68, 0x5d,
16109 -       0x80, 0x64, 0xd8, 0x6c,
16110 -       0x04, 0x64, 0x9a, 0x74,
16111 -       0x02, 0x64, 0xaa, 0x74,
16112 -       0x00, 0x6a, 0x60, 0x74,
16113 -       0x03, 0x64, 0xc8, 0x74,
16114 -       0x23, 0x64, 0x48, 0x74,
16115 -       0x08, 0x64, 0x5c, 0x74,
16116 -       0x61, 0x6a, 0xd8, 0x5e,
16117 -       0x00, 0x65, 0xd8, 0x5d,
16118 +       0x64, 0x6a, 0x6a, 0x5d,
16119 +       0x80, 0x64, 0xda, 0x6c,
16120 +       0x04, 0x64, 0x9c, 0x74,
16121 +       0x02, 0x64, 0xac, 0x74,
16122 +       0x00, 0x6a, 0x62, 0x74,
16123 +       0x03, 0x64, 0xca, 0x74,
16124 +       0x23, 0x64, 0x4a, 0x74,
16125 +       0x08, 0x64, 0x5e, 0x74,
16126 +       0x61, 0x6a, 0xda, 0x5e,
16127 +       0x00, 0x65, 0xda, 0x5d,
16128         0x08, 0x51, 0xce, 0x71,
16129 -       0x00, 0x65, 0x40, 0x44,
16130 -       0x80, 0x04, 0x5a, 0x7c,
16131 -       0x51, 0x6a, 0x5e, 0x5d,
16132 -       0x01, 0x51, 0x5a, 0x64,
16133 -       0x01, 0xa4, 0x52, 0x7c,
16134 -       0x80, 0xba, 0x5c, 0x6c,
16135 -       0x41, 0x6a, 0xd8, 0x5e,
16136 -       0x00, 0x65, 0x5c, 0x44,
16137 -       0x21, 0x6a, 0xd8, 0x5e,
16138 -       0x00, 0x65, 0x5c, 0x44,
16139 -       0x07, 0x6a, 0x54, 0x5d,
16140 +       0x00, 0x65, 0x42, 0x44,
16141 +       0x80, 0x04, 0x5c, 0x7c,
16142 +       0x51, 0x6a, 0x60, 0x5d,
16143 +       0x01, 0x51, 0x5c, 0x64,
16144 +       0x01, 0xa4, 0x54, 0x7c,
16145 +       0x80, 0xba, 0x5e, 0x6c,
16146 +       0x41, 0x6a, 0xda, 0x5e,
16147 +       0x00, 0x65, 0x5e, 0x44,
16148 +       0x21, 0x6a, 0xda, 0x5e,
16149 +       0x00, 0x65, 0x5e, 0x44,
16150 +       0x07, 0x6a, 0x56, 0x5d,
16151         0x01, 0x06, 0xd4, 0x30,
16152         0x00, 0x65, 0xcc, 0x41,
16153 -       0x80, 0xb8, 0x56, 0x7c,
16154 -       0xc0, 0x3c, 0x6a, 0x7c,
16155 -       0x80, 0x3c, 0x56, 0x6c,
16156 -       0xff, 0xa8, 0x6a, 0x6c,
16157 -       0x40, 0x3c, 0x56, 0x6c,
16158 -       0x10, 0xb8, 0x6e, 0x7c,
16159 -       0xa1, 0x6a, 0xd8, 0x5e,
16160 -       0x01, 0xb4, 0x74, 0x6c,
16161 -       0x02, 0xb4, 0x76, 0x6c,
16162 -       0x01, 0xa4, 0x76, 0x7c,
16163 -       0xff, 0xa8, 0x86, 0x7c,
16164 +       0x80, 0xb8, 0x58, 0x7c,
16165 +       0xc0, 0x3c, 0x6c, 0x7c,
16166 +       0x80, 0x3c, 0x58, 0x6c,
16167 +       0xff, 0xa8, 0x6c, 0x6c,
16168 +       0x40, 0x3c, 0x58, 0x6c,
16169 +       0x10, 0xb8, 0x70, 0x7c,
16170 +       0xa1, 0x6a, 0xda, 0x5e,
16171 +       0x01, 0xb4, 0x76, 0x6c,
16172 +       0x02, 0xb4, 0x78, 0x6c,
16173 +       0x01, 0xa4, 0x78, 0x7c,
16174 +       0xff, 0xa8, 0x88, 0x7c,
16175         0x04, 0xb4, 0x68, 0x01,
16176         0x01, 0x6a, 0x76, 0x00,
16177 -       0x00, 0xbb, 0x12, 0x5e,
16178 -       0xff, 0xa8, 0x86, 0x7c,
16179 -       0x71, 0x6a, 0xd8, 0x5e,
16180 -       0x40, 0x51, 0x86, 0x64,
16181 -       0x00, 0x65, 0xb2, 0x5e,
16182 +       0x00, 0xbb, 0x14, 0x5e,
16183 +       0xff, 0xa8, 0x88, 0x7c,
16184 +       0x71, 0x6a, 0xda, 0x5e,
16185 +       0x40, 0x51, 0x88, 0x64,
16186 +       0x00, 0x65, 0xb4, 0x5e,
16187         0x00, 0x65, 0xde, 0x41,
16188 -       0x00, 0xbb, 0x8a, 0x5c,
16189 +       0x00, 0xbb, 0x8c, 0x5c,
16190         0x00, 0x65, 0xde, 0x41,
16191 -       0x00, 0x65, 0xb2, 0x5e,
16192 +       0x00, 0x65, 0xb4, 0x5e,
16193         0x01, 0x65, 0xa2, 0x30,
16194         0x01, 0xf8, 0xc8, 0x30,
16195         0x01, 0x4e, 0xc8, 0x30,
16196 -       0x00, 0x6a, 0xb6, 0xdd,
16197 -       0x00, 0x51, 0xc8, 0x5d,
16198 +       0x00, 0x6a, 0xb8, 0xdd,
16199 +       0x00, 0x51, 0xca, 0x5d,
16200         0x01, 0x4e, 0x9c, 0x18,
16201         0x02, 0x6a, 0x22, 0x05,
16202 -       0xc0, 0x3c, 0x56, 0x6c,
16203 +       0xc0, 0x3c, 0x58, 0x6c,
16204         0x04, 0xb8, 0x70, 0x01,
16205 -       0x00, 0x65, 0xd4, 0x5e,
16206 +       0x00, 0x65, 0xd6, 0x5e,
16207         0x20, 0xb8, 0xde, 0x69,
16208         0x01, 0xbb, 0xa2, 0x30,
16209         0x3f, 0xba, 0x7c, 0x08,
16210 -       0x00, 0xb9, 0xce, 0x5c,
16211 +       0x00, 0xb9, 0xd0, 0x5c,
16212         0x00, 0x65, 0xde, 0x41,
16213         0x01, 0x06, 0xd4, 0x30,
16214         0x20, 0x3c, 0xcc, 0x79,
16215 -       0x20, 0x3c, 0x5c, 0x7c,
16216 -       0x01, 0xa4, 0xb8, 0x7c,
16217 +       0x20, 0x3c, 0x5e, 0x7c,
16218 +       0x01, 0xa4, 0xba, 0x7c,
16219         0x01, 0xb4, 0x68, 0x01,
16220         0x00, 0x65, 0xcc, 0x41,
16221 -       0x00, 0x65, 0x5c, 0x44,
16222 +       0x00, 0x65, 0x5e, 0x44,
16223         0x04, 0x14, 0x58, 0x31,
16224         0x01, 0x06, 0xd4, 0x30,
16225         0x08, 0xa0, 0x60, 0x31,
16226         0xac, 0x6a, 0xcc, 0x00,
16227 -       0x14, 0x6a, 0xf4, 0x5d,
16228 +       0x14, 0x6a, 0xf6, 0x5d,
16229         0x01, 0x06, 0xd4, 0x30,
16230 -       0xa0, 0x6a, 0xec, 0x5d,
16231 +       0xa0, 0x6a, 0xee, 0x5d,
16232         0x00, 0x65, 0xcc, 0x41,
16233         0xdf, 0x3c, 0x78, 0x08,
16234         0x12, 0x01, 0x02, 0x00,
16235 -       0x00, 0x65, 0x5c, 0x44,
16236 +       0x00, 0x65, 0x5e, 0x44,
16237         0x4c, 0x65, 0xcc, 0x28,
16238         0x01, 0x3e, 0x20, 0x31,
16239         0xd0, 0x66, 0xcc, 0x18,
16240 @@ -631,102 +632,102 @@
16241         0xd0, 0x65, 0xca, 0x18,
16242         0x01, 0x3e, 0x20, 0x31,
16243         0x30, 0x65, 0xd4, 0x18,
16244 -       0x00, 0x65, 0xe6, 0x4c,
16245 +       0x00, 0x65, 0xe8, 0x4c,
16246         0xe1, 0x6a, 0x22, 0x01,
16247         0xff, 0x6a, 0xd4, 0x08,
16248         0x20, 0x65, 0xd4, 0x18,
16249 -       0x00, 0x65, 0xee, 0x54,
16250 +       0x00, 0x65, 0xf0, 0x54,
16251         0xe1, 0x6a, 0x22, 0x01,
16252         0xff, 0x6a, 0xd4, 0x08,
16253         0x20, 0x65, 0xca, 0x18,
16254         0xe0, 0x65, 0xd4, 0x18,
16255 -       0x00, 0x65, 0xf8, 0x4c,
16256 +       0x00, 0x65, 0xfa, 0x4c,
16257         0xe1, 0x6a, 0x22, 0x01,
16258         0xff, 0x6a, 0xd4, 0x08,
16259         0xd0, 0x65, 0xd4, 0x18,
16260 -       0x00, 0x65, 0x00, 0x55,
16261 +       0x00, 0x65, 0x02, 0x55,
16262         0xe1, 0x6a, 0x22, 0x01,
16263         0xff, 0x6a, 0xd4, 0x08,
16264         0x01, 0x6c, 0xa2, 0x30,
16265 -       0xff, 0x51, 0x12, 0x75,
16266 -       0x00, 0x51, 0x8e, 0x5d,
16267 +       0xff, 0x51, 0x14, 0x75,
16268 +       0x00, 0x51, 0x90, 0x5d,
16269         0x01, 0x51, 0x20, 0x31,
16270 -       0x00, 0x65, 0x34, 0x45,
16271 +       0x00, 0x65, 0x36, 0x45,
16272         0x3f, 0xba, 0xc8, 0x08,
16273 -       0x00, 0x3e, 0x34, 0x75,
16274 -       0x00, 0x65, 0xb0, 0x5e,
16275 +       0x00, 0x3e, 0x36, 0x75,
16276 +       0x00, 0x65, 0xb2, 0x5e,
16277         0x80, 0x3c, 0x78, 0x00,
16278         0x01, 0x06, 0xd4, 0x30,
16279 -       0x00, 0x65, 0xd8, 0x5d,
16280 +       0x00, 0x65, 0xda, 0x5d,
16281         0x01, 0x3c, 0x78, 0x00,
16282 -       0xe0, 0x3f, 0x50, 0x65,
16283 +       0xe0, 0x3f, 0x52, 0x65,
16284         0x02, 0x3c, 0x78, 0x00,
16285 -       0x20, 0x12, 0x50, 0x65,
16286 -       0x51, 0x6a, 0x5e, 0x5d,
16287 -       0x00, 0x51, 0x8e, 0x5d,
16288 -       0x51, 0x6a, 0x5e, 0x5d,
16289 +       0x20, 0x12, 0x52, 0x65,
16290 +       0x51, 0x6a, 0x60, 0x5d,
16291 +       0x00, 0x51, 0x90, 0x5d,
16292 +       0x51, 0x6a, 0x60, 0x5d,
16293         0x01, 0x51, 0x20, 0x31,
16294         0x04, 0x3c, 0x78, 0x00,
16295         0x01, 0xb9, 0xc8, 0x30,
16296 -       0x00, 0x3d, 0x4e, 0x65,
16297 +       0x00, 0x3d, 0x50, 0x65,
16298         0x08, 0x3c, 0x78, 0x00,
16299         0x3f, 0xba, 0xc8, 0x08,
16300 -       0x00, 0x3e, 0x4e, 0x65,
16301 +       0x00, 0x3e, 0x50, 0x65,
16302         0x10, 0x3c, 0x78, 0x00,
16303 -       0x04, 0xb8, 0x4e, 0x7d,
16304 +       0x04, 0xb8, 0x50, 0x7d,
16305         0xfb, 0xb8, 0x70, 0x09,
16306 -       0x20, 0xb8, 0x44, 0x6d,
16307 +       0x20, 0xb8, 0x46, 0x6d,
16308         0x01, 0x90, 0xc8, 0x30,
16309         0xff, 0x6a, 0xa2, 0x00,
16310 -       0x00, 0x3d, 0xce, 0x5c,
16311 +       0x00, 0x3d, 0xd0, 0x5c,
16312         0x01, 0x64, 0x20, 0x31,
16313         0xff, 0x6a, 0x78, 0x08,
16314         0x00, 0x65, 0xea, 0x58,
16315 -       0x10, 0xb8, 0x5c, 0x7c,
16316 -       0xff, 0x6a, 0x54, 0x5d,
16317 -       0x00, 0x65, 0x5c, 0x44,
16318 -       0x00, 0x65, 0xb0, 0x5e,
16319 -       0x31, 0x6a, 0xd8, 0x5e,
16320 -       0x00, 0x65, 0x5c, 0x44,
16321 +       0x10, 0xb8, 0x5e, 0x7c,
16322 +       0xff, 0x6a, 0x56, 0x5d,
16323 +       0x00, 0x65, 0x5e, 0x44,
16324 +       0x00, 0x65, 0xb2, 0x5e,
16325 +       0x31, 0x6a, 0xda, 0x5e,
16326 +       0x00, 0x65, 0x5e, 0x44,
16327         0x10, 0x3f, 0x06, 0x00,
16328         0x10, 0x6a, 0x06, 0x00,
16329         0x01, 0x65, 0x74, 0x34,
16330 -       0x81, 0x6a, 0xd8, 0x5e,
16331 -       0x00, 0x65, 0x60, 0x45,
16332 +       0x81, 0x6a, 0xda, 0x5e,
16333 +       0x00, 0x65, 0x62, 0x45,
16334         0x01, 0x06, 0xd4, 0x30,
16335 -       0x01, 0x0c, 0x60, 0x7d,
16336 -       0x04, 0x0c, 0x5a, 0x6d,
16337 +       0x01, 0x0c, 0x62, 0x7d,
16338 +       0x04, 0x0c, 0x5c, 0x6d,
16339         0xe0, 0x03, 0x7e, 0x08,
16340         0xe0, 0x3f, 0xcc, 0x61,
16341         0x01, 0x65, 0xcc, 0x30,
16342         0x01, 0x12, 0xda, 0x34,
16343         0x01, 0x06, 0xd4, 0x34,
16344 -       0x01, 0x03, 0x6e, 0x6d,
16345 +       0x01, 0x03, 0x70, 0x6d,
16346         0x40, 0x03, 0xcc, 0x08,
16347         0x01, 0x65, 0x06, 0x30,
16348         0x40, 0x65, 0xc8, 0x08,
16349 -       0x00, 0x66, 0x7c, 0x75,
16350 -       0x40, 0x65, 0x7c, 0x7d,
16351 -       0x00, 0x65, 0x7c, 0x5d,
16352 +       0x00, 0x66, 0x7e, 0x75,
16353 +       0x40, 0x65, 0x7e, 0x7d,
16354 +       0x00, 0x65, 0x7e, 0x5d,
16355         0xff, 0x6a, 0xd4, 0x08,
16356         0xff, 0x6a, 0xd4, 0x08,
16357         0xff, 0x6a, 0xd4, 0x08,
16358         0xff, 0x6a, 0xd4, 0x0c,
16359         0x08, 0x01, 0x02, 0x00,
16360 -       0x02, 0x0b, 0x86, 0x7d,
16361 +       0x02, 0x0b, 0x88, 0x7d,
16362         0x01, 0x65, 0x0c, 0x30,
16363 -       0x02, 0x0b, 0x8a, 0x7d,
16364 +       0x02, 0x0b, 0x8c, 0x7d,
16365         0xf7, 0x01, 0x02, 0x0c,
16366         0x01, 0x65, 0xc8, 0x30,
16367 -       0xff, 0x41, 0xae, 0x75,
16368 +       0xff, 0x41, 0xb0, 0x75,
16369         0x01, 0x41, 0x20, 0x31,
16370         0xff, 0x6a, 0xa4, 0x00,
16371 -       0x00, 0x65, 0x9e, 0x45,
16372 -       0xff, 0xbf, 0xae, 0x75,
16373 +       0x00, 0x65, 0xa0, 0x45,
16374 +       0xff, 0xbf, 0xb0, 0x75,
16375         0x01, 0x90, 0xa4, 0x30,
16376         0x01, 0xbf, 0x20, 0x31,
16377 -       0x00, 0xbb, 0x98, 0x65,
16378 -       0xff, 0x52, 0xac, 0x75,
16379 +       0x00, 0xbb, 0x9a, 0x65,
16380 +       0xff, 0x52, 0xae, 0x75,
16381         0x01, 0xbf, 0xcc, 0x30,
16382         0x01, 0x90, 0xca, 0x30,
16383         0x01, 0x52, 0x20, 0x31,
16384 @@ -734,28 +735,28 @@
16385         0x01, 0x65, 0x20, 0x35,
16386         0x01, 0xbf, 0x82, 0x34,
16387         0x01, 0x64, 0xa2, 0x30,
16388 -       0x00, 0x6a, 0xc0, 0x5e,
16389 +       0x00, 0x6a, 0xc2, 0x5e,
16390         0x0d, 0x6a, 0x76, 0x00,
16391 -       0x00, 0x51, 0x12, 0x46,
16392 +       0x00, 0x51, 0x14, 0x46,
16393         0x01, 0x65, 0xa4, 0x30,
16394         0xe0, 0x6a, 0xcc, 0x00,
16395 -       0x48, 0x6a, 0x06, 0x5e,
16396 +       0x48, 0x6a, 0x08, 0x5e,
16397         0x01, 0x6a, 0xd0, 0x01,
16398         0x01, 0x6a, 0xdc, 0x05,
16399         0x88, 0x6a, 0xcc, 0x00,
16400 -       0x48, 0x6a, 0x06, 0x5e,
16401 -       0x01, 0x6a, 0xe0, 0x5d,
16402 +       0x48, 0x6a, 0x08, 0x5e,
16403 +       0x01, 0x6a, 0xe2, 0x5d,
16404         0x01, 0x6a, 0x26, 0x05,
16405         0x01, 0x65, 0xd8, 0x31,
16406         0x09, 0xee, 0xdc, 0x01,
16407 -       0x80, 0xee, 0xcc, 0x7d,
16408 +       0x80, 0xee, 0xce, 0x7d,
16409         0xff, 0x6a, 0xdc, 0x0d,
16410         0x01, 0x65, 0x32, 0x31,
16411         0x0a, 0x93, 0x26, 0x01,
16412 -       0x00, 0x65, 0xa8, 0x46,
16413 -       0x81, 0x6a, 0xd8, 0x5e,
16414 -       0x01, 0x0c, 0xd8, 0x7d,
16415 -       0x04, 0x0c, 0xd6, 0x6d,
16416 +       0x00, 0x65, 0xaa, 0x46,
16417 +       0x81, 0x6a, 0xda, 0x5e,
16418 +       0x01, 0x0c, 0xda, 0x7d,
16419 +       0x04, 0x0c, 0xd8, 0x6d,
16420         0xe0, 0x03, 0x06, 0x08,
16421         0xe0, 0x03, 0x7e, 0x0c,
16422         0x01, 0x65, 0x18, 0x31,
16423 @@ -774,7 +775,7 @@
16424         0x01, 0x6c, 0xda, 0x34,
16425         0x3d, 0x64, 0xa4, 0x28,
16426         0x55, 0x64, 0xc8, 0x28,
16427 -       0x00, 0x65, 0x06, 0x46,
16428 +       0x00, 0x65, 0x08, 0x46,
16429         0x2e, 0x64, 0xa4, 0x28,
16430         0x66, 0x64, 0xc8, 0x28,
16431         0x00, 0x6c, 0xda, 0x18,
16432 @@ -785,63 +786,63 @@
16433         0x00, 0x6c, 0xda, 0x24,
16434         0x01, 0x65, 0xc8, 0x30,
16435         0xe0, 0x6a, 0xcc, 0x00,
16436 -       0x44, 0x6a, 0x02, 0x5e,
16437 +       0x44, 0x6a, 0x04, 0x5e,
16438         0x01, 0x90, 0xe2, 0x31,
16439 -       0x04, 0x3b, 0x26, 0x7e,
16440 +       0x04, 0x3b, 0x28, 0x7e,
16441         0x30, 0x6a, 0xd0, 0x01,
16442         0x20, 0x6a, 0xd0, 0x01,
16443         0x1d, 0x6a, 0xdc, 0x01,
16444 -       0xdc, 0xee, 0x22, 0x66,
16445 -       0x00, 0x65, 0x3e, 0x46,
16446 +       0xdc, 0xee, 0x24, 0x66,
16447 +       0x00, 0x65, 0x40, 0x46,
16448         0x20, 0x6a, 0xd0, 0x01,
16449         0x01, 0x6a, 0xdc, 0x01,
16450         0x20, 0xa0, 0xd8, 0x31,
16451         0x09, 0xee, 0xdc, 0x01,
16452 -       0x80, 0xee, 0x2e, 0x7e,
16453 +       0x80, 0xee, 0x30, 0x7e,
16454         0x11, 0x6a, 0xdc, 0x01,
16455 -       0x50, 0xee, 0x32, 0x66,
16456 +       0x50, 0xee, 0x34, 0x66,
16457         0x20, 0x6a, 0xd0, 0x01,
16458         0x09, 0x6a, 0xdc, 0x01,
16459 -       0x88, 0xee, 0x38, 0x66,
16460 +       0x88, 0xee, 0x3a, 0x66,
16461         0x19, 0x6a, 0xdc, 0x01,
16462 -       0xd8, 0xee, 0x3c, 0x66,
16463 +       0xd8, 0xee, 0x3e, 0x66,
16464         0xff, 0x6a, 0xdc, 0x09,
16465 -       0x18, 0xee, 0x40, 0x6e,
16466 +       0x18, 0xee, 0x42, 0x6e,
16467         0xff, 0x6a, 0xd4, 0x0c,
16468         0x88, 0x6a, 0xcc, 0x00,
16469 -       0x44, 0x6a, 0x02, 0x5e,
16470 -       0x20, 0x6a, 0xe0, 0x5d,
16471 +       0x44, 0x6a, 0x04, 0x5e,
16472 +       0x20, 0x6a, 0xe2, 0x5d,
16473         0x01, 0x3b, 0x26, 0x31,
16474 -       0x04, 0x3b, 0x5a, 0x6e,
16475 +       0x04, 0x3b, 0x5c, 0x6e,
16476         0xa0, 0x6a, 0xca, 0x00,
16477         0x20, 0x65, 0xc8, 0x18,
16478 -       0x00, 0x65, 0x98, 0x5e,
16479 -       0x00, 0x65, 0x52, 0x66,
16480 +       0x00, 0x65, 0x9a, 0x5e,
16481 +       0x00, 0x65, 0x54, 0x66,
16482         0x0a, 0x93, 0x26, 0x01,
16483 -       0x00, 0x65, 0xa8, 0x46,
16484 +       0x00, 0x65, 0xaa, 0x46,
16485         0xa0, 0x6a, 0xcc, 0x00,
16486         0xff, 0x6a, 0xc8, 0x08,
16487 -       0x20, 0x94, 0x5e, 0x6e,
16488 -       0x10, 0x94, 0x60, 0x6e,
16489 -       0x08, 0x94, 0x7a, 0x6e,
16490 -       0x08, 0x94, 0x7a, 0x6e,
16491 -       0x08, 0x94, 0x7a, 0x6e,
16492 +       0x20, 0x94, 0x60, 0x6e,
16493 +       0x10, 0x94, 0x62, 0x6e,
16494 +       0x08, 0x94, 0x7c, 0x6e,
16495 +       0x08, 0x94, 0x7c, 0x6e,
16496 +       0x08, 0x94, 0x7c, 0x6e,
16497         0xff, 0x8c, 0xc8, 0x10,
16498         0xc1, 0x64, 0xc8, 0x18,
16499         0xf8, 0x64, 0xc8, 0x08,
16500         0x01, 0x99, 0xda, 0x30,
16501 -       0x00, 0x66, 0x6e, 0x66,
16502 -       0xc0, 0x66, 0xaa, 0x76,
16503 +       0x00, 0x66, 0x70, 0x66,
16504 +       0xc0, 0x66, 0xac, 0x76,
16505         0x60, 0x66, 0xc8, 0x18,
16506         0x3d, 0x64, 0xc8, 0x28,
16507 -       0x00, 0x65, 0x5e, 0x46,
16508 +       0x00, 0x65, 0x60, 0x46,
16509         0xf7, 0x93, 0x26, 0x09,
16510 -       0x08, 0x93, 0x7c, 0x6e,
16511 +       0x08, 0x93, 0x7e, 0x6e,
16512         0x00, 0x62, 0xc4, 0x18,
16513 -       0x00, 0x65, 0xa8, 0x5e,
16514 -       0x00, 0x65, 0x88, 0x5e,
16515 -       0x00, 0x65, 0x88, 0x5e,
16516 -       0x00, 0x65, 0x88, 0x5e,
16517 +       0x00, 0x65, 0xaa, 0x5e,
16518 +       0x00, 0x65, 0x8a, 0x5e,
16519 +       0x00, 0x65, 0x8a, 0x5e,
16520 +       0x00, 0x65, 0x8a, 0x5e,
16521         0x01, 0x99, 0xda, 0x30,
16522         0x01, 0x99, 0xda, 0x30,
16523         0x01, 0x99, 0xda, 0x30,
16524 @@ -858,11 +859,11 @@
16525         0x01, 0x6c, 0x32, 0x31,
16526         0x01, 0x6c, 0x32, 0x31,
16527         0x01, 0x6c, 0x32, 0x35,
16528 -       0x08, 0x94, 0xa8, 0x7e,
16529 +       0x08, 0x94, 0xaa, 0x7e,
16530         0xf7, 0x93, 0x26, 0x09,
16531 -       0x08, 0x93, 0xac, 0x6e,
16532 +       0x08, 0x93, 0xae, 0x6e,
16533         0xff, 0x6a, 0xd4, 0x0c,
16534 -       0x04, 0xb8, 0xd4, 0x6e,
16535 +       0x04, 0xb8, 0xd6, 0x6e,
16536         0x01, 0x42, 0x7e, 0x31,
16537         0xff, 0x6a, 0x76, 0x01,
16538         0x01, 0x90, 0x84, 0x34,
16539 @@ -870,14 +871,14 @@
16540         0x01, 0x85, 0x0a, 0x01,
16541         0x7f, 0x65, 0x10, 0x09,
16542         0xfe, 0x85, 0x0a, 0x0d,
16543 -       0xff, 0x42, 0xd0, 0x66,
16544 -       0xff, 0x41, 0xc8, 0x66,
16545 -       0xd1, 0x6a, 0xd8, 0x5e,
16546 +       0xff, 0x42, 0xd2, 0x66,
16547 +       0xff, 0x41, 0xca, 0x66,
16548 +       0xd1, 0x6a, 0xda, 0x5e,
16549         0xff, 0x6a, 0xca, 0x04,
16550         0x01, 0x41, 0x20, 0x31,
16551         0x01, 0xbf, 0x82, 0x30,
16552         0x01, 0x6a, 0x76, 0x00,
16553 -       0x00, 0xbb, 0x12, 0x46,
16554 +       0x00, 0xbb, 0x14, 0x46,
16555         0x01, 0x42, 0x20, 0x31,
16556         0x01, 0xbf, 0x84, 0x34,
16557         0x01, 0x41, 0x7e, 0x31,
16558 @@ -941,7 +942,7 @@
16559  static int
16560  ahc_patch17_func(struct ahc_softc *ahc)
16561  {
16562 -       return ((ahc->flags & AHC_TMODE_WIDEODD_BUG) != 0);
16563 +       return ((ahc->bugs & AHC_TMODE_WIDEODD_BUG) != 0);
16564  }
16565  
16566  static ahc_patch_func_t ahc_patch16_func;
16567 @@ -1142,152 +1143,152 @@
16568         { ahc_patch0_func, 196, 1, 1 },
16569         { ahc_patch9_func, 212, 6, 2 },
16570         { ahc_patch0_func, 218, 6, 1 },
16571 -       { ahc_patch8_func, 226, 20, 2 },
16572 +       { ahc_patch8_func, 226, 21, 2 },
16573         { ahc_patch1_func, 241, 1, 1 },
16574 -       { ahc_patch1_func, 248, 1, 2 },
16575 -       { ahc_patch0_func, 249, 2, 2 },
16576 -       { ahc_patch11_func, 250, 1, 1 },
16577 -       { ahc_patch9_func, 258, 27, 3 },
16578 -       { ahc_patch1_func, 274, 10, 2 },
16579 -       { ahc_patch13_func, 277, 1, 1 },
16580 -       { ahc_patch14_func, 285, 14, 1 },
16581 -       { ahc_patch1_func, 301, 1, 2 },
16582 -       { ahc_patch0_func, 302, 1, 1 },
16583 -       { ahc_patch9_func, 305, 1, 1 },
16584 -       { ahc_patch13_func, 310, 1, 1 },
16585 -       { ahc_patch9_func, 311, 2, 2 },
16586 -       { ahc_patch0_func, 313, 4, 1 },
16587 -       { ahc_patch14_func, 317, 1, 1 },
16588 -       { ahc_patch15_func, 319, 2, 3 },
16589 -       { ahc_patch9_func, 319, 1, 2 },
16590 -       { ahc_patch0_func, 320, 1, 1 },
16591 -       { ahc_patch6_func, 325, 1, 2 },
16592 -       { ahc_patch0_func, 326, 1, 1 },
16593 -       { ahc_patch1_func, 330, 47, 11 },
16594 -       { ahc_patch6_func, 337, 2, 4 },
16595 -       { ahc_patch7_func, 337, 1, 1 },
16596 -       { ahc_patch8_func, 338, 1, 1 },
16597 -       { ahc_patch0_func, 339, 1, 1 },
16598 -       { ahc_patch16_func, 340, 1, 1 },
16599 -       { ahc_patch6_func, 356, 6, 3 },
16600 -       { ahc_patch16_func, 356, 5, 1 },
16601 -       { ahc_patch0_func, 362, 7, 1 },
16602 -       { ahc_patch13_func, 372, 5, 1 },
16603 -       { ahc_patch0_func, 377, 52, 17 },
16604 -       { ahc_patch14_func, 377, 1, 1 },
16605 -       { ahc_patch7_func, 379, 2, 2 },
16606 -       { ahc_patch17_func, 380, 1, 1 },
16607 -       { ahc_patch9_func, 383, 1, 1 },
16608 -       { ahc_patch18_func, 390, 1, 1 },
16609 -       { ahc_patch14_func, 395, 9, 3 },
16610 -       { ahc_patch9_func, 396, 3, 2 },
16611 -       { ahc_patch0_func, 399, 3, 1 },
16612 -       { ahc_patch9_func, 407, 6, 2 },
16613 -       { ahc_patch0_func, 413, 9, 2 },
16614 -       { ahc_patch13_func, 413, 1, 1 },
16615 -       { ahc_patch13_func, 422, 2, 1 },
16616 -       { ahc_patch14_func, 424, 1, 1 },
16617 -       { ahc_patch9_func, 426, 1, 2 },
16618 -       { ahc_patch0_func, 427, 1, 1 },
16619 -       { ahc_patch7_func, 428, 1, 1 },
16620 +       { ahc_patch1_func, 249, 1, 2 },
16621 +       { ahc_patch0_func, 250, 2, 2 },
16622 +       { ahc_patch11_func, 251, 1, 1 },
16623 +       { ahc_patch9_func, 259, 27, 3 },
16624 +       { ahc_patch1_func, 275, 10, 2 },
16625 +       { ahc_patch13_func, 278, 1, 1 },
16626 +       { ahc_patch14_func, 286, 14, 1 },
16627 +       { ahc_patch1_func, 302, 1, 2 },
16628 +       { ahc_patch0_func, 303, 1, 1 },
16629 +       { ahc_patch9_func, 306, 1, 1 },
16630 +       { ahc_patch13_func, 311, 1, 1 },
16631 +       { ahc_patch9_func, 312, 2, 2 },
16632 +       { ahc_patch0_func, 314, 4, 1 },
16633 +       { ahc_patch14_func, 318, 1, 1 },
16634 +       { ahc_patch15_func, 320, 2, 3 },
16635 +       { ahc_patch9_func, 320, 1, 2 },
16636 +       { ahc_patch0_func, 321, 1, 1 },
16637 +       { ahc_patch6_func, 326, 1, 2 },
16638 +       { ahc_patch0_func, 327, 1, 1 },
16639 +       { ahc_patch1_func, 331, 47, 11 },
16640 +       { ahc_patch6_func, 338, 2, 4 },
16641 +       { ahc_patch7_func, 338, 1, 1 },
16642 +       { ahc_patch8_func, 339, 1, 1 },
16643 +       { ahc_patch0_func, 340, 1, 1 },
16644 +       { ahc_patch16_func, 341, 1, 1 },
16645 +       { ahc_patch6_func, 357, 6, 3 },
16646 +       { ahc_patch16_func, 357, 5, 1 },
16647 +       { ahc_patch0_func, 363, 7, 1 },
16648 +       { ahc_patch13_func, 373, 5, 1 },
16649 +       { ahc_patch0_func, 378, 52, 17 },
16650 +       { ahc_patch14_func, 378, 1, 1 },
16651 +       { ahc_patch7_func, 380, 2, 2 },
16652 +       { ahc_patch17_func, 381, 1, 1 },
16653 +       { ahc_patch9_func, 384, 1, 1 },
16654 +       { ahc_patch18_func, 391, 1, 1 },
16655 +       { ahc_patch14_func, 396, 9, 3 },
16656 +       { ahc_patch9_func, 397, 3, 2 },
16657 +       { ahc_patch0_func, 400, 3, 1 },
16658 +       { ahc_patch9_func, 408, 6, 2 },
16659 +       { ahc_patch0_func, 414, 9, 2 },
16660 +       { ahc_patch13_func, 414, 1, 1 },
16661 +       { ahc_patch13_func, 423, 2, 1 },
16662 +       { ahc_patch14_func, 425, 1, 1 },
16663 +       { ahc_patch9_func, 427, 1, 2 },
16664 +       { ahc_patch0_func, 428, 1, 1 },
16665         { ahc_patch7_func, 429, 1, 1 },
16666 -       { ahc_patch8_func, 430, 3, 3 },
16667 -       { ahc_patch6_func, 431, 1, 2 },
16668 -       { ahc_patch0_func, 432, 1, 1 },
16669 -       { ahc_patch9_func, 433, 1, 1 },
16670 -       { ahc_patch15_func, 434, 1, 2 },
16671 -       { ahc_patch13_func, 434, 1, 1 },
16672 -       { ahc_patch14_func, 436, 9, 4 },
16673 -       { ahc_patch9_func, 436, 1, 1 },
16674 -       { ahc_patch9_func, 443, 2, 1 },
16675 -       { ahc_patch0_func, 445, 4, 3 },
16676 -       { ahc_patch9_func, 445, 1, 2 },
16677 -       { ahc_patch0_func, 446, 3, 1 },
16678 -       { ahc_patch1_func, 450, 2, 1 },
16679 -       { ahc_patch7_func, 452, 10, 2 },
16680 -       { ahc_patch0_func, 462, 1, 1 },
16681 -       { ahc_patch8_func, 463, 118, 22 },
16682 -       { ahc_patch1_func, 465, 3, 2 },
16683 -       { ahc_patch0_func, 468, 5, 3 },
16684 -       { ahc_patch9_func, 468, 2, 2 },
16685 -       { ahc_patch0_func, 470, 3, 1 },
16686 -       { ahc_patch1_func, 475, 2, 2 },
16687 -       { ahc_patch0_func, 477, 6, 3 },
16688 -       { ahc_patch9_func, 477, 2, 2 },
16689 -       { ahc_patch0_func, 479, 3, 1 },
16690 -       { ahc_patch1_func, 485, 2, 2 },
16691 -       { ahc_patch0_func, 487, 9, 7 },
16692 -       { ahc_patch9_func, 487, 5, 6 },
16693 -       { ahc_patch19_func, 487, 1, 2 },
16694 -       { ahc_patch0_func, 488, 1, 1 },
16695 -       { ahc_patch19_func, 490, 1, 2 },
16696 -       { ahc_patch0_func, 491, 1, 1 },
16697 -       { ahc_patch0_func, 492, 4, 1 },
16698 -       { ahc_patch6_func, 497, 3, 2 },
16699 -       { ahc_patch0_func, 500, 1, 1 },
16700 -       { ahc_patch6_func, 510, 1, 2 },
16701 -       { ahc_patch0_func, 511, 1, 1 },
16702 -       { ahc_patch20_func, 548, 7, 1 },
16703 -       { ahc_patch3_func, 583, 1, 2 },
16704 -       { ahc_patch0_func, 584, 1, 1 },
16705 -       { ahc_patch21_func, 587, 1, 1 },
16706 -       { ahc_patch8_func, 589, 106, 33 },
16707 -       { ahc_patch4_func, 591, 1, 1 },
16708 -       { ahc_patch1_func, 597, 2, 2 },
16709 -       { ahc_patch0_func, 599, 1, 1 },
16710 -       { ahc_patch1_func, 602, 1, 2 },
16711 -       { ahc_patch0_func, 603, 1, 1 },
16712 -       { ahc_patch9_func, 604, 3, 3 },
16713 -       { ahc_patch15_func, 605, 1, 1 },
16714 -       { ahc_patch0_func, 607, 4, 1 },
16715 -       { ahc_patch19_func, 616, 2, 2 },
16716 -       { ahc_patch0_func, 618, 1, 1 },
16717 -       { ahc_patch19_func, 622, 10, 3 },
16718 -       { ahc_patch5_func, 624, 8, 1 },
16719 -       { ahc_patch0_func, 632, 9, 2 },
16720 -       { ahc_patch5_func, 633, 8, 1 },
16721 -       { ahc_patch4_func, 643, 1, 2 },
16722 -       { ahc_patch0_func, 644, 1, 1 },
16723 -       { ahc_patch19_func, 645, 1, 2 },
16724 -       { ahc_patch0_func, 646, 3, 2 },
16725 -       { ahc_patch4_func, 648, 1, 1 },
16726 -       { ahc_patch5_func, 649, 1, 1 },
16727 -       { ahc_patch5_func, 652, 1, 1 },
16728 -       { ahc_patch5_func, 654, 1, 1 },
16729 -       { ahc_patch4_func, 656, 2, 2 },
16730 -       { ahc_patch0_func, 658, 2, 1 },
16731 -       { ahc_patch5_func, 660, 1, 1 },
16732 -       { ahc_patch5_func, 663, 1, 1 },
16733 -       { ahc_patch5_func, 666, 1, 1 },
16734 -       { ahc_patch19_func, 670, 1, 1 },
16735 -       { ahc_patch19_func, 673, 1, 1 },
16736 -       { ahc_patch4_func, 679, 1, 1 },
16737 -       { ahc_patch6_func, 682, 1, 2 },
16738 -       { ahc_patch0_func, 683, 1, 1 },
16739 -       { ahc_patch7_func, 695, 16, 1 },
16740 -       { ahc_patch4_func, 711, 20, 1 },
16741 -       { ahc_patch9_func, 732, 4, 2 },
16742 -       { ahc_patch0_func, 736, 4, 1 },
16743 -       { ahc_patch9_func, 740, 4, 2 },
16744 -       { ahc_patch0_func, 744, 3, 1 },
16745 -       { ahc_patch6_func, 750, 1, 1 },
16746 -       { ahc_patch22_func, 752, 14, 1 },
16747 -       { ahc_patch7_func, 766, 3, 1 },
16748 -       { ahc_patch9_func, 778, 24, 8 },
16749 -       { ahc_patch19_func, 782, 1, 2 },
16750 -       { ahc_patch0_func, 783, 1, 1 },
16751 -       { ahc_patch15_func, 788, 4, 2 },
16752 -       { ahc_patch0_func, 792, 7, 3 },
16753 -       { ahc_patch23_func, 792, 5, 2 },
16754 -       { ahc_patch0_func, 797, 2, 1 },
16755 -       { ahc_patch0_func, 802, 42, 3 },
16756 -       { ahc_patch18_func, 814, 18, 2 },
16757 -       { ahc_patch0_func, 832, 1, 1 },
16758 -       { ahc_patch4_func, 856, 1, 1 },
16759 -       { ahc_patch4_func, 857, 3, 2 },
16760 -       { ahc_patch0_func, 860, 1, 1 },
16761 -       { ahc_patch13_func, 861, 3, 1 },
16762 -       { ahc_patch4_func, 864, 12, 1 }
16763 +       { ahc_patch7_func, 430, 1, 1 },
16764 +       { ahc_patch8_func, 431, 3, 3 },
16765 +       { ahc_patch6_func, 432, 1, 2 },
16766 +       { ahc_patch0_func, 433, 1, 1 },
16767 +       { ahc_patch9_func, 434, 1, 1 },
16768 +       { ahc_patch15_func, 435, 1, 2 },
16769 +       { ahc_patch13_func, 435, 1, 1 },
16770 +       { ahc_patch14_func, 437, 9, 4 },
16771 +       { ahc_patch9_func, 437, 1, 1 },
16772 +       { ahc_patch9_func, 444, 2, 1 },
16773 +       { ahc_patch0_func, 446, 4, 3 },
16774 +       { ahc_patch9_func, 446, 1, 2 },
16775 +       { ahc_patch0_func, 447, 3, 1 },
16776 +       { ahc_patch1_func, 451, 2, 1 },
16777 +       { ahc_patch7_func, 453, 10, 2 },
16778 +       { ahc_patch0_func, 463, 1, 1 },
16779 +       { ahc_patch8_func, 464, 118, 22 },
16780 +       { ahc_patch1_func, 466, 3, 2 },
16781 +       { ahc_patch0_func, 469, 5, 3 },
16782 +       { ahc_patch9_func, 469, 2, 2 },
16783 +       { ahc_patch0_func, 471, 3, 1 },
16784 +       { ahc_patch1_func, 476, 2, 2 },
16785 +       { ahc_patch0_func, 478, 6, 3 },
16786 +       { ahc_patch9_func, 478, 2, 2 },
16787 +       { ahc_patch0_func, 480, 3, 1 },
16788 +       { ahc_patch1_func, 486, 2, 2 },
16789 +       { ahc_patch0_func, 488, 9, 7 },
16790 +       { ahc_patch9_func, 488, 5, 6 },
16791 +       { ahc_patch19_func, 488, 1, 2 },
16792 +       { ahc_patch0_func, 489, 1, 1 },
16793 +       { ahc_patch19_func, 491, 1, 2 },
16794 +       { ahc_patch0_func, 492, 1, 1 },
16795 +       { ahc_patch0_func, 493, 4, 1 },
16796 +       { ahc_patch6_func, 498, 3, 2 },
16797 +       { ahc_patch0_func, 501, 1, 1 },
16798 +       { ahc_patch6_func, 511, 1, 2 },
16799 +       { ahc_patch0_func, 512, 1, 1 },
16800 +       { ahc_patch20_func, 549, 7, 1 },
16801 +       { ahc_patch3_func, 584, 1, 2 },
16802 +       { ahc_patch0_func, 585, 1, 1 },
16803 +       { ahc_patch21_func, 588, 1, 1 },
16804 +       { ahc_patch8_func, 590, 106, 33 },
16805 +       { ahc_patch4_func, 592, 1, 1 },
16806 +       { ahc_patch1_func, 598, 2, 2 },
16807 +       { ahc_patch0_func, 600, 1, 1 },
16808 +       { ahc_patch1_func, 603, 1, 2 },
16809 +       { ahc_patch0_func, 604, 1, 1 },
16810 +       { ahc_patch9_func, 605, 3, 3 },
16811 +       { ahc_patch15_func, 606, 1, 1 },
16812 +       { ahc_patch0_func, 608, 4, 1 },
16813 +       { ahc_patch19_func, 617, 2, 2 },
16814 +       { ahc_patch0_func, 619, 1, 1 },
16815 +       { ahc_patch19_func, 623, 10, 3 },
16816 +       { ahc_patch5_func, 625, 8, 1 },
16817 +       { ahc_patch0_func, 633, 9, 2 },
16818 +       { ahc_patch5_func, 634, 8, 1 },
16819 +       { ahc_patch4_func, 644, 1, 2 },
16820 +       { ahc_patch0_func, 645, 1, 1 },
16821 +       { ahc_patch19_func, 646, 1, 2 },
16822 +       { ahc_patch0_func, 647, 3, 2 },
16823 +       { ahc_patch4_func, 649, 1, 1 },
16824 +       { ahc_patch5_func, 650, 1, 1 },
16825 +       { ahc_patch5_func, 653, 1, 1 },
16826 +       { ahc_patch5_func, 655, 1, 1 },
16827 +       { ahc_patch4_func, 657, 2, 2 },
16828 +       { ahc_patch0_func, 659, 2, 1 },
16829 +       { ahc_patch5_func, 661, 1, 1 },
16830 +       { ahc_patch5_func, 664, 1, 1 },
16831 +       { ahc_patch5_func, 667, 1, 1 },
16832 +       { ahc_patch19_func, 671, 1, 1 },
16833 +       { ahc_patch19_func, 674, 1, 1 },
16834 +       { ahc_patch4_func, 680, 1, 1 },
16835 +       { ahc_patch6_func, 683, 1, 2 },
16836 +       { ahc_patch0_func, 684, 1, 1 },
16837 +       { ahc_patch7_func, 696, 16, 1 },
16838 +       { ahc_patch4_func, 712, 20, 1 },
16839 +       { ahc_patch9_func, 733, 4, 2 },
16840 +       { ahc_patch0_func, 737, 4, 1 },
16841 +       { ahc_patch9_func, 741, 4, 2 },
16842 +       { ahc_patch0_func, 745, 3, 1 },
16843 +       { ahc_patch6_func, 751, 1, 1 },
16844 +       { ahc_patch22_func, 753, 14, 1 },
16845 +       { ahc_patch7_func, 767, 3, 1 },
16846 +       { ahc_patch9_func, 779, 24, 8 },
16847 +       { ahc_patch19_func, 783, 1, 2 },
16848 +       { ahc_patch0_func, 784, 1, 1 },
16849 +       { ahc_patch15_func, 789, 4, 2 },
16850 +       { ahc_patch0_func, 793, 7, 3 },
16851 +       { ahc_patch23_func, 793, 5, 2 },
16852 +       { ahc_patch0_func, 798, 2, 1 },
16853 +       { ahc_patch0_func, 803, 42, 3 },
16854 +       { ahc_patch18_func, 815, 18, 2 },
16855 +       { ahc_patch0_func, 833, 1, 1 },
16856 +       { ahc_patch4_func, 857, 1, 1 },
16857 +       { ahc_patch4_func, 858, 3, 2 },
16858 +       { ahc_patch0_func, 861, 1, 1 },
16859 +       { ahc_patch13_func, 862, 3, 1 },
16860 +       { ahc_patch4_func, 865, 12, 1 }
16861  };
16862  
16863  static struct cs {
16864 @@ -1296,11 +1297,11 @@
16865  } critical_sections[] = {
16866         { 11, 18 },
16867         { 21, 30 },
16868 -       { 711, 727 },
16869 -       { 857, 860 },
16870 -       { 864, 870 },
16871 -       { 872, 874 },
16872 -       { 874, 876 }
16873 +       { 712, 728 },
16874 +       { 858, 861 },
16875 +       { 865, 871 },
16876 +       { 873, 875 },
16877 +       { 875, 877 }
16878  };
16879  
16880  static const int num_critical_sections = sizeof(critical_sections)
16881 diff -urN linux-2.4.24.org/drivers/scsi/aic7xxx/aicasm/aicasm.c linux-2.4.24/drivers/scsi/aic7xxx/aicasm/aicasm.c
16882 --- linux-2.4.24.org/drivers/scsi/aic7xxx/aicasm/aicasm.c       2004-01-08 11:57:43.090989043 +0100
16883 +++ linux-2.4.24/drivers/scsi/aic7xxx/aicasm/aicasm.c   2003-12-22 22:46:59.000000000 +0100
16884 @@ -37,7 +37,7 @@
16885   * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
16886   * POSSIBILITY OF SUCH DAMAGES.
16887   *
16888 - * $Id$
16889 + * $Id$
16890   *
16891   * $FreeBSD$
16892   */
16893 @@ -609,10 +609,10 @@
16894  
16895                 while (line < cur_instr->srcline) {
16896                         fgets(buf, sizeof(buf), ifile);
16897 -                               fprintf(listfile, "\t\t%s", buf);
16898 +                               fprintf(listfile, "             \t%s", buf);
16899                                 line++;
16900                 }
16901 -               fprintf(listfile, "%03x %02x%02x%02x%02x", instrptr,
16902 +               fprintf(listfile, "%04x %02x%02x%02x%02x", instrptr,
16903  #if BYTE_ORDER == LITTLE_ENDIAN
16904                         cur_instr->format.bytes[0],
16905                         cur_instr->format.bytes[1],
16906 @@ -624,14 +624,23 @@
16907                         cur_instr->format.bytes[1],
16908                         cur_instr->format.bytes[0]);
16909  #endif
16910 -               fgets(buf, sizeof(buf), ifile);
16911 -               fprintf(listfile, "\t%s", buf);
16912 -               line++;
16913 +               /*
16914 +                * Macro expansions can cause several instructions
16915 +                * to be output for a single source line.  Only
16916 +                * advance the line once in these cases.
16917 +                */
16918 +               if (line == cur_instr->srcline) {
16919 +                       fgets(buf, sizeof(buf), ifile);
16920 +                       fprintf(listfile, "\t%s", buf);
16921 +                       line++;
16922 +               } else {
16923 +                       fprintf(listfile, "\n");
16924 +               }
16925                 instrptr++;
16926         }
16927         /* Dump the remainder of the file */
16928         while(fgets(buf, sizeof(buf), ifile) != NULL)
16929 -               fprintf(listfile, "\t\t%s", buf);
16930 +               fprintf(listfile, "             %s", buf);
16931  
16932         fclose(ifile);
16933  }
16934 diff -urN linux-2.4.24.org/drivers/scsi/aic7xxx/aicasm/aicasm_macro_scan.l linux-2.4.24/drivers/scsi/aic7xxx/aicasm/aicasm_macro_scan.l
16935 --- linux-2.4.24.org/drivers/scsi/aic7xxx/aicasm/aicasm_macro_scan.l    2004-01-08 11:57:43.083990489 +0100
16936 +++ linux-2.4.24/drivers/scsi/aic7xxx/aicasm/aicasm_macro_scan.l        2003-12-22 22:46:59.000000000 +0100
16937 @@ -38,7 +38,7 @@
16938   * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
16939   * POSSIBILITY OF SUCH DAMAGES.
16940   *
16941 - * $Id$
16942 + * $Id$
16943   *
16944   * $FreeBSD$
16945   */
16946 @@ -78,6 +78,7 @@
16947  \n                     {
16948                                 ++yylineno;
16949                         }
16950 +\r                     ;
16951  <ARGLIST>{SPACE}       ;
16952  <ARGLIST>\(            {
16953                                 parren_count++;
16954 diff -urN linux-2.4.24.org/drivers/scsi/aic7xxx/aicasm/aicasm_scan.l linux-2.4.24/drivers/scsi/aic7xxx/aicasm/aicasm_scan.l
16955 --- linux-2.4.24.org/drivers/scsi/aic7xxx/aicasm/aicasm_scan.l  2004-01-08 11:57:43.082990696 +0100
16956 +++ linux-2.4.24/drivers/scsi/aic7xxx/aicasm/aicasm_scan.l      2003-12-22 22:46:59.000000000 +0100
16957 @@ -38,7 +38,7 @@
16958   * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
16959   * POSSIBILITY OF SUCH DAMAGES.
16960   *
16961 - * $Id$
16962 + * $Id$
16963   *
16964   * $FreeBSD$
16965   */
16966 @@ -87,6 +87,7 @@
16967  
16968  %%
16969  \n                     { ++yylineno; }
16970 +\r                     ;
16971  "/*"                   { BEGIN COMMENT;  /* Enter comment eating state */ }
16972  <COMMENT>"/*"          { fprintf(stderr, "Warning! Comment within comment."); }
16973  <COMMENT>\n            { ++yylineno; }
16974 @@ -114,6 +115,7 @@
16975                                 }
16976                         }
16977  <CEXPR>\n              { ++yylineno; }
16978 +<CEXPR>\r              ;
16979  <CEXPR>[^()\n]+        {
16980                                 char *yptr;
16981  
16982 @@ -359,6 +361,7 @@
16983                                 /* Eat escaped newlines. */
16984                                 ++yylineno;
16985                         }
16986 +<MACROBODY>\r          ;
16987  <MACROBODY>\n          {
16988                                 /* Macros end on the first unescaped newline. */
16989                                 BEGIN INITIAL;
16990 @@ -369,10 +372,17 @@
16991                         }
16992  <MACROBODY>{MBODY}     {
16993                                 char *yptr;
16994 +                               char c;
16995  
16996                                 yptr = yytext;
16997 -                               while (*yptr)
16998 -                                       *string_buf_ptr++ = *yptr++;
16999 +                               while (c = *yptr++) {
17000 +                                       /*
17001 +                                        * Strip carriage returns.
17002 +                                        */
17003 +                                       if (c == '\r')
17004 +                                               continue;
17005 +                                       *string_buf_ptr++ = c;
17006 +                               }
17007                         }
17008  {WORD}\(               {
17009                                 char *yptr;
17010 diff -urN linux-2.4.24.org/drivers/scsi/aic7xxx/aicasm/Makefile linux-2.4.24/drivers/scsi/aic7xxx/aicasm/Makefile
17011 --- linux-2.4.24.org/drivers/scsi/aic7xxx/aicasm/Makefile       2004-01-08 11:57:43.091988836 +0100
17012 +++ linux-2.4.24/drivers/scsi/aic7xxx/aicasm/Makefile   2003-12-22 22:46:59.000000000 +0100
17013 @@ -51,11 +49,19 @@
17014  clean:
17015         rm -f $(clean-files)
17016  
17017 +# Create a dependency chain in generated files
17018 +# to avoid concurrent invocations of the single
17019 +# rule that builds them all.
17020 +aicasm_gram.c: aicasm_gram.h
17021  aicasm_gram.c aicasm_gram.h: aicasm_gram.y
17022         $(YACC) $(YFLAGS) -b $(<:.y=) $<
17023         mv $(<:.y=).tab.c $(<:.y=.c)
17024         mv $(<:.y=).tab.h $(<:.y=.h)
17025  
17026 +# Create a dependency chain in generated files
17027 +# to avoid concurrent invocations of the single
17028 +# rule that builds them all.
17029 +aicasm_macro_gram.c: aicasm_macro_gram.h
17030  aicasm_macro_gram.c aicasm_macro_gram.h: aicasm_macro_gram.y
17031         $(YACC) $(YFLAGS) -b $(<:.y=) -p mm $<
17032         mv $(<:.y=).tab.c $(<:.y=.c)
17033 diff -urN linux-2.4.24.org/drivers/scsi/aic7xxx/aiclib.c linux-2.4.24/drivers/scsi/aic7xxx/aiclib.c
17034 --- linux-2.4.24.org/drivers/scsi/aic7xxx/aiclib.c      2004-01-08 11:57:43.018004128 +0100
17035 +++ linux-2.4.24/drivers/scsi/aic7xxx/aiclib.c  2003-12-22 22:46:59.000000000 +0100
17036 @@ -30,17 +30,6 @@
17037   * $Id$
17038   */
17039  
17040 -#include <linux/blk.h>
17041 -#include <linux/blkdev.h>
17042 -#include <linux/delay.h>
17043 -#include <linux/version.h>
17044 -
17045 -/* Core SCSI definitions */
17046 -#include "scsi.h"
17047 -#include "hosts.h"
17048 -#include "aiclib.h"
17049 -#include "cam.h"
17050 -
17051  #ifndef FALSE
17052  #define FALSE   0
17053  #endif /* FALSE */
17054 @@ -1411,3 +1400,336 @@
17055         }
17056         return (opt_arg);
17057  }
17058 +
17059 +/************************* Magic SysReq Support *******************************/
17060 +void
17061 +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0)
17062 +aic_sysrq_handler(int key, struct pt_regs *unused, struct kbd_struct *unused1,
17063 +                 struct tty_struct *unused2)
17064 +#else
17065 +aic_sysrq_handler(int key, struct pt_regs *unused, struct tty_struct *unused2)
17066 +#endif
17067 +{
17068 +#ifdef CONFIG_MAGIC_SYSRQ
17069 +       struct aic_softc *aic;
17070 +       u_long l;
17071 +
17072 +       aic_list_lock(&l);
17073 +
17074 +       TAILQ_FOREACH(aic, &aic_tailq, links) {
17075 +               u_long s;
17076 +
17077 +               aic_lock(aic, &s);
17078 +               aic_dump_card_state(aic);
17079 +               aic_unlock(aic, &s);
17080 +       }
17081 +       aic_list_unlock(&l);
17082 +#endif
17083 +}
17084 +
17085 +int
17086 +aic_install_sysrq(struct aic_sysrq_key_op *key_op)
17087 +{
17088 +#ifdef CONFIG_MAGIC_SYSRQ
17089 +       char *str;
17090 +       int len;
17091 +       int i;
17092 +
17093 +       str = key_op->help_msg;
17094 +       len = strlen(str);
17095 +       for (i = 0; i < len; i++) {
17096 +               int key;
17097 +
17098 +               key = str[i];
17099 +               if (register_sysrq_key(key, key_op) == 0) {
17100 +
17101 +                       if (key >= 'a' && key <= 'z')
17102 +                               str[i] = key + ('A' - 'a');
17103 +                       return (key);
17104 +               }
17105 +       }
17106 +#endif
17107 +       return (0);
17108 +}
17109 +
17110 +void
17111 +aic_remove_sysrq(int key, struct aic_sysrq_key_op *key_op)
17112 +{
17113 +#ifdef CONFIG_MAGIC_SYSRQ
17114 +       unregister_sysrq_key(key, key_op);
17115 +#endif
17116 +}
17117 +
17118 +/******************************** Bus DMA *************************************/
17119 +int
17120 +aic_dma_tag_create(struct aic_softc *aic, bus_dma_tag_t parent,
17121 +                  bus_size_t alignment, bus_size_t boundary,
17122 +                  bus_addr_t lowaddr, bus_addr_t highaddr,
17123 +                  bus_dma_filter_t *filter, void *filterarg,
17124 +                  bus_size_t maxsize, int nsegments,
17125 +                  bus_size_t maxsegsz, int flags, bus_dma_tag_t *ret_tag)
17126 +{
17127 +       bus_dma_tag_t dmat;
17128 +
17129 +       dmat = malloc(sizeof(*dmat), M_DEVBUF, M_NOWAIT);
17130 +       if (dmat == NULL)
17131 +               return (ENOMEM);
17132 +
17133 +       /*
17134 +        * Linux is very simplistic about DMA memory.  For now don't
17135 +        * maintain all specification information.  Once Linux supplies
17136 +        * better facilities for doing these operations, or the
17137 +        * needs of this particular driver change, we might need to do
17138 +        * more here.
17139 +        */
17140 +       dmat->alignment = alignment;
17141 +       dmat->boundary = boundary;
17142 +       dmat->maxsize = maxsize;
17143 +       *ret_tag = dmat;
17144 +       return (0);
17145 +}
17146 +
17147 +void
17148 +aic_dma_tag_destroy(struct aic_softc *aic, bus_dma_tag_t dmat)
17149 +{
17150 +       free(dmat, M_DEVBUF);
17151 +}
17152 +
17153 +int
17154 +aic_dmamem_alloc(struct aic_softc *aic, bus_dma_tag_t dmat, void** vaddr,
17155 +                int flags, bus_dmamap_t *mapp)
17156 +{
17157 +       bus_dmamap_t map;
17158 +
17159 +       map = malloc(sizeof(*map), M_DEVBUF, M_NOWAIT);
17160 +       if (map == NULL)
17161 +               return (ENOMEM);
17162 +       /*
17163 +        * Although we can dma data above 4GB, our
17164 +        * coherent memory is below 4GB for
17165 +        * space efficiency reasons (only need a 4byte
17166 +        * address).  For this reason, we have to reset
17167 +        * our dma mask when doing allocations.
17168 +        */
17169 +       aic_set_dma_mask(aic, 0xFFFFFFFF);
17170 +       *vaddr = aic_alloc_coherent(aic, dmat->maxsize, &map->bus_addr);
17171 +       aic_set_dma_mask(aic, aic->platform_data->hw_dma_mask);
17172 +       if (*vaddr == NULL)
17173 +               return (ENOMEM);
17174 +       *mapp = map;
17175 +       return(0);
17176 +}
17177 +
17178 +void
17179 +aic_dmamem_free(struct aic_softc *aic, bus_dma_tag_t dmat,
17180 +               void* vaddr, bus_dmamap_t map)
17181 +{
17182 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,3,0)
17183 +       aic_free_coherent(aic, dmat->maxsize, vaddr, map->bus_addr);
17184 +#else
17185 +       free(vaddr, M_DEVBUF);
17186 +#endif
17187 +}
17188 +
17189 +int
17190 +aic_dmamap_load(struct aic_softc *aic, bus_dma_tag_t dmat, bus_dmamap_t map,
17191 +               void *buf, bus_size_t buflen, bus_dmamap_callback_t *cb,
17192 +               void *cb_arg, int flags)
17193 +{
17194 +       /*
17195 +        * Assume for now that this will only be used during
17196 +        * initialization and not for per-transaction buffer mapping.
17197 +        */
17198 +       bus_dma_segment_t stack_sg;
17199 +
17200 +       stack_sg.ds_addr = map->bus_addr;
17201 +       stack_sg.ds_len = dmat->maxsize;
17202 +       cb(cb_arg, &stack_sg, /*nseg*/1, /*error*/0);
17203 +       return (0);
17204 +}
17205 +
17206 +void
17207 +aic_dmamap_destroy(struct aic_softc *aic, bus_dma_tag_t dmat, bus_dmamap_t map)
17208 +{
17209 +       free(map, M_DEVBUF);
17210 +}
17211 +
17212 +int
17213 +aic_dmamap_unload(struct aic_softc *aic, bus_dma_tag_t dmat, bus_dmamap_t map)
17214 +{
17215 +       /* Nothing to do */
17216 +       return (0);
17217 +}
17218 +
17219 +/***************************** Queue Handling ********************************/
17220 +/*
17221 + * In 2.4.X and above, this routine is called from a tasklet,
17222 + * so we must re-acquire our lock prior to executing this code.
17223 + * In all prior kernels, aic_schedule_runq() calls this routine
17224 + * directly and aic_schedule_runq() is called with our lock held.
17225 + */
17226 +void
17227 +aic_runq_tasklet(unsigned long data)
17228 +{
17229 +       struct aic_softc* aic;
17230 +       struct aic_linux_device *dev;
17231 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,0)
17232 +       u_long flags;
17233 +#endif
17234 +
17235 +       aic = (struct aic_softc *)data;
17236 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,0)
17237 +       aic_lock(aic, &flags);
17238 +#endif
17239 +       while ((dev = aic_linux_next_device_to_run(aic)) != NULL) {
17240 +       
17241 +               TAILQ_REMOVE(&aic->platform_data->device_runq, dev, links);
17242 +               dev->flags &= ~AIC_DEV_ON_RUN_LIST;
17243 +               aic_linux_check_device_queue(aic, dev);
17244 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,0)
17245 +               /* Yeild to our interrupt handler */
17246 +               aic_unlock(aic, &flags);
17247 +               aic_lock(aic, &flags);
17248 +#endif
17249 +       }
17250 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,0)
17251 +       aic_unlock(aic, &flags);
17252 +#endif
17253 +}
17254 +
17255 +void
17256 +aic_unblock_tasklet(unsigned long data)
17257 +{
17258 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,0)
17259 +       struct aic_softc* aic;
17260 +
17261 +       aic = (struct aic_softc *)data;
17262 +       scsi_unblock_requests(aic->platform_data->host);
17263 +#else
17264 +#error "Fix 2.2.X Kernel Support"
17265 +#endif
17266 +}
17267 +
17268 +void
17269 +aic_bus_settle_complete(u_long data)
17270 +{
17271 +       struct aic_softc *aic;
17272 +       u_long s;
17273 +
17274 +       aic = (struct aic_softc *)data;
17275 +       /*
17276 +        * Guard against our bottom half scheduling another
17277 +        * bus settle delay just as our timer runs.  If this
17278 +        * occurs, do nothing.  The newly scheduled timer will
17279 +        * take care of things.
17280 +        */
17281 +       aic_lock(aic, &s);
17282 +       if (timer_pending(&aic->platform_data->bus_settle_timer) == 0) {
17283 +               aic->platform_data->flags &= ~AIC_BUS_SETTLE_TIMER;
17284 +               aic_release_simq_locked(aic);
17285 +       }
17286 +       aic_unlock(aic, &s);
17287 +}
17288 +
17289 +void
17290 +aic_freeze_simq(struct aic_softc *aic)
17291 +{
17292 +       aic->platform_data->qfrozen++;
17293 +       if (aic->platform_data->qfrozen == 1)
17294 +               scsi_block_requests(aic->platform_data->host);
17295 +}
17296 +
17297 +void
17298 +aic_release_simq(struct aic_softc *aic)
17299 +{
17300 +       u_long s;
17301 +
17302 +       aic_lock(aic, &s);
17303 +       aic_release_simq_locked(aic);
17304 +       aic_unlock(aic, &s);
17305 +}
17306 +
17307 +void
17308 +aic_release_simq_locked(struct aic_softc *aic)
17309 +{
17310 +
17311 +       if (aic->platform_data->qfrozen > 0)
17312 +               aic->platform_data->qfrozen--;
17313 +       if (AIC_DV_SIMQ_FROZEN(aic)
17314 +        && ((aic->platform_data->flags & AIC_DV_WAIT_SIMQ_RELEASE) != 0)) {
17315 +               aic->platform_data->flags &= ~AIC_DV_WAIT_SIMQ_RELEASE;
17316 +               up(&aic->platform_data->dv_sem);
17317 +       }
17318 +       if (aic->platform_data->qfrozen == 0) {
17319 +               aic_schedule_unblock(aic);
17320 +               aic_schedule_runq(aic);
17321 +       }
17322 +}
17323 +
17324 +/***************************** Timer Facilities *******************************/
17325 +void
17326 +aic_platform_timeout(struct scsi_cmnd *cmd)
17327 +{
17328 +
17329 +       if (AIC_DV_CMD(cmd) != 0) {
17330 +
17331 +               aic_linux_dv_timeout(cmd);
17332 +       } else {
17333 +               struct  scb *scb;
17334 +               struct  aic_softc *aic;
17335 +               u_long  s;
17336 +
17337 +               scb = (struct scb *)cmd->host_scribble;
17338 +               aic = scb->aic_softc;
17339 +               aic_lock(aic, &s);
17340 +
17341 +               if (scb == NULL
17342 +                || scb->flags == SCB_FLAG_NONE) {
17343 +                       int done_late;
17344 +
17345 +                       /*
17346 +                        * Handle timeout/completion races.
17347 +                        * If the command is still sitting on
17348 +                        * our completion queue, just re-instate
17349 +                        * the timeout.  If we've already completed
17350 +                        * the command, the function pointer in our
17351 +                        * timer will be cleared and we will need to
17352 +                        * additionally complete it again to the mid-layer.
17353 +                        *
17354 +                        * Since done_late is cleared by adding a
17355 +                        * timer, we must save off its value first.
17356 +                        */
17357 +                       done_late = cmd->eh_timeout.function == NULL;
17358 +                       scsi_add_timer(cmd, 60*HZ, aic_linux_midlayer_timeout);
17359 +                       if (done_late)
17360 +                               cmd->scsi_done(cmd);
17361 +               } else if ((scb->platform_data->flags & AIC_TIMEOUT_ACTIVE)) {
17362 +
17363 +                       /*
17364 +                        * Handle the case of timeouts that expire just
17365 +                        * as we delete timers during recovery by skipping
17366 +                        * SCBs that don't have timers active.
17367 +                        */
17368 +                       scb->platform_data->flags &= ~AIC_TIMEOUT_ACTIVE;
17369 +
17370 +                       /*
17371 +                        * We must clear out the function pointer so that
17372 +                        * scsi_add_timer does not believe that a del_timer
17373 +                        * is required before setting up a new timer for
17374 +                        * this command.
17375 +                        */
17376 +                       scb->io_ctx->eh_timeout.function = NULL;
17377 +                       aic_timeout(scb);
17378 +               }
17379 +               aic_unlock(aic, &s);
17380 +       }
17381 +}
17382 +
17383 +void
17384 +aic_linux_midlayer_timeout(struct scsi_cmnd *cmd)
17385 +{
17386 +       struct aic_softc *aic;
17387 +
17388 +       aic = *(struct aic_softc **)cmd->device->host->hostdata;
17389 +       printf("%s: midlayer_timeout\n", aic_name(aic));
17390 +}
17391 diff -urN linux-2.4.24.org/drivers/scsi/aic7xxx/aiclib.h linux-2.4.24/drivers/scsi/aic7xxx/aiclib.h
17392 --- linux-2.4.24.org/drivers/scsi/aic7xxx/aiclib.h      2004-01-08 11:57:43.017004334 +0100
17393 +++ linux-2.4.24/drivers/scsi/aic7xxx/aiclib.h  2003-12-23 00:31:43.000000000 +0100
17394 @@ -1,4 +1,5 @@
17395  /*
17396 + * SCSI definitions...
17397   * Largely written by Julian Elischer (julian@tfs.com)
17398   * for TRW Financial Systems.
17399   *
17400 @@ -57,6 +58,42 @@
17401  #ifndef        _AICLIB_H
17402  #define _AICLIB_H
17403  
17404 +#include <linux/types.h>
17405 +#include <linux/delay.h>
17406 +#include <linux/ioport.h>
17407 +#include <linux/pci.h>
17408 +#include <linux/smp_lock.h>
17409 +#include <linux/module.h>
17410 +#include <asm/byteorder.h>
17411 +#include <asm/io.h>
17412 +
17413 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,0)
17414 +#include <linux/slab.h>
17415 +#else
17416 +#include <linux/malloc.h>
17417 +#endif
17418 +
17419 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,0)
17420 +#include <linux/interrupt.h> /* For tasklet support. */
17421 +#endif
17422 +
17423 +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0)
17424 +#include <linux/blk.h>
17425 +#endif
17426 +#include <linux/blkdev.h>
17427 +
17428 +#include "scsi.h"
17429 +#include "hosts.h"
17430 +
17431 +/* Name space conflict with BSD queue macros */
17432 +#ifdef LIST_HEAD
17433 +#undef LIST_HEAD
17434 +#endif
17435 +#include "cam.h"
17436 +#include "queue.h"
17437 +#include "scsi_message.h"
17438 +#include "scsi_iu.h"
17439 +
17440  /*
17441   * Linux Interrupt Support.
17442   */
17443 @@ -66,9 +103,731 @@
17444  #endif
17445  
17446  /*
17447 - * SCSI command format
17448 + * Linux Timer Support.
17449 + */
17450 +#define AIC_USECS_PER_JIFFY (1000000/HZ)
17451 +
17452 +/**************************** Module Library Hack *****************************/
17453 +/*
17454 + * What we'd like to do is have a single "scsi library" module that both the
17455 + * aic7xxx and aic79xx drivers could load and depend on.  A cursory examination
17456 + * of implementing module dependencies in Linux (handling the install and
17457 + * initrd cases) does not look promissing.  For now, we just duplicate this
17458 + * code in both drivers using a simple symbol renaming scheme that hides this
17459 + * hack from the drivers.
17460 + */
17461 +#define AIC_LIB_ENTRY_CONCAT(x, prefix)        prefix ## x
17462 +#define        AIC_LIB_ENTRY_EXPAND(x, prefix) AIC_LIB_ENTRY_CONCAT(x, prefix)
17463 +#define AIC_LIB_ENTRY(x)               AIC_LIB_ENTRY_EXPAND(x, AIC_LIB_PREFIX)
17464 +
17465 +#define AIC_CONST_ENTRY(x)             AIC_LIB_ENTRY_EXPAND(x,AIC_CONST_PREFIX)
17466 +
17467 +#define        aic_sense_desc                  AIC_LIB_ENTRY(_sense_desc)
17468 +#define        aic_sense_error_action          AIC_LIB_ENTRY(_sense_error_action)
17469 +#define        aic_error_action                AIC_LIB_ENTRY(_error_action)
17470 +#define        aic_op_desc                     AIC_LIB_ENTRY(_op_desc)
17471 +#define        aic_cdb_string                  AIC_LIB_ENTRY(_cdb_string)
17472 +#define aic_print_inquiry              AIC_LIB_ENTRY(_print_inquiry)
17473 +#define aic_calc_syncsrate             AIC_LIB_ENTRY(_calc_syncrate)
17474 +#define        aic_calc_syncparam              AIC_LIB_ENTRY(_calc_syncparam)
17475 +#define        aic_calc_speed                  AIC_LIB_ENTRY(_calc_speed)
17476 +#define        aic_inquiry_match               AIC_LIB_ENTRY(_inquiry_match)
17477 +#define        aic_static_inquiry_match        AIC_LIB_ENTRY(_static_inquiry_match)
17478 +#define        aic_parse_brace_option          AIC_LIB_ENTRY(_parse_brace_option)
17479 +#define        aic_power_state_change          AIC_LIB_ENTRY(_power_state_change)
17480 +#define        aic_sysrq_handler               AIC_LIB_ENTRY(_sysrq_handler)
17481 +#define        aic_install_sysrq               AIC_LIB_ENTRY(_install_sysrq)
17482 +#define        aic_remove_sysrq                AIC_LIB_ENTRY(_remove_sysrq)
17483 +#define        aic_list_lock                   AIC_LIB_ENTRY(_list_lock)
17484 +#define        aic_list_unlock                 AIC_LIB_ENTRY(_list_unlock)
17485 +#define        aic_lock                        AIC_LIB_ENTRY(_lock)
17486 +#define        aic_unlock                      AIC_LIB_ENTRY(_unlock)
17487 +#define        aic_dump_card_state             AIC_LIB_ENTRY(_dump_card_state)
17488 +#define        aic_linux_dv_complete           AIC_LIB_ENTRY(_linux_dv_complete)
17489 +#define        aic_linux_run_device_queue      AIC_LIB_ENTRY(_linux_run_device_queue)
17490 +#define        aic_linux_dv_timeout            AIC_LIB_ENTRY(_linux_dv_timeout)
17491 +#define        aic_linux_midlayer_timeout      AIC_LIB_ENTRY(_linux_midlayer_timeout)
17492 +#define        aic_freeze_simq                 AIC_LIB_ENTRY(_freeze_simq)
17493 +#define        aic_bus_settle_complete         AIC_LIB_ENTRY(_bus_settle_complete)
17494 +#define        aic_release_simq                AIC_LIB_ENTRY(_release_simq)
17495 +#define        aic_release_simq                AIC_LIB_ENTRY(_release_simq)
17496 +#define        aic_release_simq_locked         AIC_LIB_ENTRY(_release_simq_locked)
17497 +#define        aic_dma_tag_create              AIC_LIB_ENTRY(_dma_tag_create)
17498 +#define        aic_dma_tag_destroy             AIC_LIB_ENTRY(_dma_tag_destroy)
17499 +#define        aic_dmamem_alloc                AIC_LIB_ENTRY(_dmamem_alloc)
17500 +#define        aic_dmamem_free                 AIC_LIB_ENTRY(_dmamem_free)
17501 +#define        aic_dmamap_create               AIC_LIB_ENTRY(_dmamap_create)
17502 +#define        aic_dmamap_destroy              AIC_LIB_ENTRY(_dmamap_destroy)
17503 +#define        aic_dmamap_load                 AIC_LIB_ENTRY(_dmamap_load)
17504 +#define        aic_dmamap_unload               AIC_LIB_ENTRY(_dmamap_unload)
17505 +#define        aic_dmamap_destroy              AIC_LIB_ENTRY(_dmamap_destroy)
17506 +#define        aic_timeout                     AIC_LIB_ENTRY(_timeout)
17507 +#define        aic_runq_tasklet                AIC_LIB_ENTRY(_runq_tasklet)
17508 +#define        aic_unblock_tasklet             AIC_LIB_ENTRY(_unblock_tasklet)
17509 +#define        aic_platform_timeout            AIC_LIB_ENTRY(_platform_timeout)
17510 +#define        aic_name                        AIC_LIB_ENTRY(_name)
17511 +
17512 +#define        aic_tailq                       AIC_LIB_ENTRY(_tailq)
17513 +#define        aic_softc                       AIC_LIB_ENTRY(_softc)
17514 +#define        aic_transinfo                   AIC_LIB_ENTRY(_transinfo)
17515 +#define        aic_platform_data               AIC_LIB_ENTRY(_platform_data)
17516 +#define        aic_devinfo                     AIC_LIB_ENTRY(_devinfo)
17517 +#define        aic_callback_t                  AIC_LIB_ENTRY(_callback_t)
17518 +
17519 +#define        AIC_NUM_LUNS                    AIC_CONST_ENTRY(_NUM_LUNS)
17520 +#define        AIC_NUM_TARGETS                 AIC_CONST_ENTRY(_NUM_TARGETS)
17521 +#define        AIC_RESOURCE_SHORTAGE           AIC_CONST_ENTRY(_RESOURCE_SHORTAGE)
17522 +
17523 +/*************************** Forward Declarations *****************************/
17524 +struct aic_softc;
17525 +
17526 +#if LINUX_VERSION_CODE > KERNEL_VERSION(2,5,0)
17527 +typedef struct device *aic_dev_softc_t;
17528 +#else
17529 +typedef struct pci_dev *aic_dev_softc_t;
17530 +#endif
17531 +typedef Scsi_Cmnd     *aic_io_ctx_t;
17532 +
17533 +/*************************** Timer DataStructures *****************************/
17534 +typedef struct timer_list aic_timer_t;
17535 +
17536 +/***************************** Bus Space/DMA **********************************/
17537 +
17538 +#if LINUX_VERSION_CODE > KERNEL_VERSION(2,2,17)
17539 +typedef dma_addr_t bus_addr_t;
17540 +#else
17541 +typedef uint32_t bus_addr_t;
17542 +#endif
17543 +typedef uint32_t bus_size_t;
17544 +
17545 +typedef enum {
17546 +       BUS_SPACE_MEMIO,
17547 +       BUS_SPACE_PIO
17548 +} bus_space_tag_t;
17549 +
17550 +typedef union {
17551 +       u_long            ioport;
17552 +       volatile uint8_t *maddr;
17553 +} bus_space_handle_t;
17554 +
17555 +typedef struct bus_dma_segment
17556 +{
17557 +       bus_addr_t      ds_addr;
17558 +       bus_size_t      ds_len;
17559 +} bus_dma_segment_t;
17560 +
17561 +struct aic_linux_dma_tag
17562 +{
17563 +       bus_size_t      alignment;
17564 +       bus_size_t      boundary;
17565 +       bus_size_t      maxsize;
17566 +};
17567 +typedef struct aic_linux_dma_tag* bus_dma_tag_t;
17568 +
17569 +struct aic_linux_dmamap
17570 +{
17571 +       bus_addr_t      bus_addr;
17572 +};
17573 +typedef struct aic_linux_dmamap* bus_dmamap_t;
17574 +
17575 +typedef int bus_dma_filter_t(void*, bus_addr_t);
17576 +typedef void bus_dmamap_callback_t(void *, bus_dma_segment_t *, int, int);
17577 +
17578 +#define BUS_DMA_WAITOK         0x0
17579 +#define BUS_DMA_NOWAIT         0x1
17580 +#define BUS_DMA_ALLOCNOW       0x2
17581 +#define BUS_DMA_LOAD_SEGS      0x4     /*
17582 +                                        * Argument is an S/G list not
17583 +                                        * a single buffer.
17584 +                                        */
17585 +
17586 +#define BUS_SPACE_MAXADDR      0xFFFFFFFF
17587 +#define BUS_SPACE_MAXADDR_32BIT        0xFFFFFFFF
17588 +#define BUS_SPACE_MAXSIZE_32BIT        0xFFFFFFFF
17589 +
17590 +int    aic_dma_tag_create(struct aic_softc *, bus_dma_tag_t /*parent*/,
17591 +                          bus_size_t /*alignment*/, bus_size_t /*boundary*/,
17592 +                          bus_addr_t /*lowaddr*/, bus_addr_t /*highaddr*/,
17593 +                          bus_dma_filter_t*/*filter*/, void */*filterarg*/,
17594 +                          bus_size_t /*maxsize*/, int /*nsegments*/,
17595 +                          bus_size_t /*maxsegsz*/, int /*flags*/,
17596 +                          bus_dma_tag_t */*dma_tagp*/);
17597 +
17598 +void   aic_dma_tag_destroy(struct aic_softc *, bus_dma_tag_t /*tag*/);
17599 +
17600 +int    aic_dmamem_alloc(struct aic_softc *, bus_dma_tag_t /*dmat*/,
17601 +                        void** /*vaddr*/, int /*flags*/,
17602 +                        bus_dmamap_t* /*mapp*/);
17603 +
17604 +void   aic_dmamem_free(struct aic_softc *, bus_dma_tag_t /*dmat*/,
17605 +                       void* /*vaddr*/, bus_dmamap_t /*map*/);
17606 +
17607 +void   aic_dmamap_destroy(struct aic_softc *, bus_dma_tag_t /*tag*/,
17608 +                          bus_dmamap_t /*map*/);
17609 +
17610 +int    aic_dmamap_load(struct aic_softc *aic, bus_dma_tag_t /*dmat*/,
17611 +                       bus_dmamap_t /*map*/, void * /*buf*/,
17612 +                       bus_size_t /*buflen*/, bus_dmamap_callback_t *,
17613 +                       void */*callback_arg*/, int /*flags*/);
17614 +
17615 +int    aic_dmamap_unload(struct aic_softc *, bus_dma_tag_t, bus_dmamap_t);
17616 +
17617 +/*
17618 + * Operations performed by aic_dmamap_sync().
17619   */
17620 +#define BUS_DMASYNC_PREREAD    0x01    /* pre-read synchronization */
17621 +#define BUS_DMASYNC_POSTREAD   0x02    /* post-read synchronization */
17622 +#define BUS_DMASYNC_PREWRITE   0x04    /* pre-write synchronization */
17623 +#define BUS_DMASYNC_POSTWRITE  0x08    /* post-write synchronization */
17624 +
17625 +/*
17626 + * XXX
17627 + * aic_dmamap_sync is only used on buffers allocated with
17628 + * the pci_alloc_consistent() API.  Although I'm not sure how
17629 + * this works on architectures with a write buffer, Linux does
17630 + * not have an API to sync "coherent" memory.  Perhaps we need
17631 + * to do an mb()?
17632 + */
17633 +#define aic_dmamap_sync(aic, dma_tag, dmamap, offset, len, op)
17634 +
17635 +/*************************** Linux DMA Wrappers *******************************/
17636 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,0)
17637 +#define        aic_alloc_coherent(aic, size, bus_addr_ptr) \
17638 +       dma_alloc_coherent(aic->dev_softc, size, bus_addr_ptr, /*flag*/0)
17639 +
17640 +#define        aic_free_coherent(aic, size, vaddr, bus_addr) \
17641 +       dma_free_coherent(aic->dev_softc, size, vaddr, bus_addr)
17642 +
17643 +#define        aic_map_single(aic, buf, size, direction) \
17644 +       dma_map_single(aic->dev_softc, buf, size, direction)
17645 +
17646 +#define        aic_unmap_single(aic, busaddr, size, direction) \
17647 +       dma_unmap_single(aic->dev_softc, busaddr, size, direction)
17648 +
17649 +#define        aic_map_sg(aic, sg_list, num_sg, direction) \
17650 +       dma_map_sg(aic->dev_softc, sg_list, num_sg, direction)
17651 +
17652 +#define        aic_unmap_sg(aic, sg_list, num_sg, direction) \
17653 +       dma_unmap_sg(aic->dev_softc, sg_list, num_sg, direction)
17654 +
17655 +#elif LINUX_VERSION_CODE > KERNEL_VERSION(2,3,0)
17656 +
17657 +#define        aic_alloc_coherent(aic, size, bus_addr_ptr) \
17658 +       pci_alloc_consistent(aic->dev_softc, size, bus_addr_ptr)
17659 +
17660 +#define        aic_free_coherent(aic, size, vaddr, bus_addr) \
17661 +       pci_free_consistent(aic->dev_softc, size, vaddr, bus_addr)
17662 +
17663 +#define        aic_map_single(aic, buf, size, direction) \
17664 +       pci_map_single(aic->dev_softc, buf, size, direction)
17665 +
17666 +#define        aic_unmap_single(aic, busaddr, size, direction) \
17667 +       pci_unmap_single(aic->dev_softc, busaddr, size, direction)
17668 +
17669 +#define        aic_map_sg(aic, sg_list, num_sg, direction) \
17670 +       pci_map_sg(aic->dev_softc, sg_list, num_sg, direction)
17671 +
17672 +#define        aic_unmap_sg(aic, sg_list, num_sg, direction) \
17673 +       pci_unmap_sg(aic->dev_softc, sg_list, num_sg, direction)
17674 +
17675 +#else
17676 +
17677 +static __inline void *aic_alloc_coherent(struct aic_softc *aic,
17678 +                                        bus_size_t size, bus_addr_t *baddrp);
17679 +
17680 +/*
17681 + * At least in 2.2.14, malloc is a slab allocator so all
17682 + * allocations are aligned.  We assume for these kernel versions
17683 + * that all allocations will be bellow 4Gig, physically contiguous,
17684 + * and accessible via DMA by the controller.
17685 + */
17686 +static __inline void *
17687 +aic_alloc_coherent(struct aic_softc *aic, bus_size_t size, bus_addr_t *baddrp)
17688 +{
17689 +       void *vaddr;
17690 +
17691 +       vaddr_ = malloc(size, M_DEVBUF, M_NOWAIT);
17692 +       if (vaddr != NULL)
17693 +               *baddrp = virt_to_bus(vaddr);
17694 +       return (vaddr);
17695 +}
17696 +
17697 +#define        aic_free_coherent(aic, size, vaddr, bus_addr) \
17698 +       free(vaddr, M_DEVBUF)
17699 +
17700 +#define aic_map_sg(pdev, sg_list, nseg, direction) (nseg)
17701 +#define aic_unmap_sg(pdev, sg_list, nseg, direction)
17702 +#define aic_map_single(pdev, buffer, bufflen, direction) \
17703 +       (VIRT_TO_BUS(buffer))
17704 +#define aic_unmap_single(pdev, buffer, buflen, direction)
17705 +#define sg_dma_address(sg) (VIRT_TO_BUS((sg)->address))
17706 +#define sg_dma_len(sg) ((sg)->length)
17707 +#endif
17708 +
17709 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,0)
17710 +
17711 +#define aic_set_dma_mask(aic, mask) dma_set_mask(aic->dev_softc, mask)
17712 +
17713 +#elif LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,3)
17714 +
17715 +/*
17716 + * Device softc is NULL for EISA devices.
17717 + */
17718 +#define aic_set_dma_mask(aic, mask)                    \
17719 +       ((aic)->dev_softc == NULL ? 0 : pci_set_dma_mask(aic->dev_softc, mask))
17720 +
17721 +#else
17722 +/*
17723 + * Device softc is NULL for EISA devices.
17724 + * Always "return" 0 for success.
17725 + */
17726 +#define aic_set_dma_mask(aic, mask)                    \
17727 +    (((aic)->dev_softc == NULL)                                \
17728 +     ? 0                                               \
17729 +     : (((aic)->dev_softc->dma_mask = mask) && 0))
17730 +#endif
17731 +
17732 +/************************* Host Template Macros *******************************/
17733 +#if defined CONFIG_HIGHIO
17734 +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,4,10)
17735 +/* Assume RedHat Distribution with its different HIGHIO conventions. */
17736 +#define        AIC_TEMPLATE_DMA_SETTINGS()     \
17737 +       .can_dma_32             = 1,    \
17738 +       .single_sg_okay         = 1,
17739 +#else
17740 +#define        AIC_TEMPLATE_DMA_SETTINGS()     \
17741 +       .highmem_io             = 1,
17742 +#endif
17743 +#else
17744 +#define        AIC_TEMPLATE_DMA_SETTINGS()
17745 +#endif
17746 +
17747 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,7)
17748 +#define        AIC_TEMPLATE_MAX_SECTORS(sectors) \
17749 +       .max_sectors            = (sectors),
17750 +#else
17751 +#define        AIC_TEMPLATE_MAX_SECTORS(sectors)
17752 +#endif
17753 +
17754 +#if defined(__i386__)
17755 +#define        AIC_TEMPLATE_BIOSPARAM() \
17756 +       .bios_param             = AIC_LIB_ENTRY(_linux_biosparam),
17757 +#else
17758 +#define        AIC_TEMPLATE_BIOSPARAM()
17759 +#endif
17760 +
17761 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,0)
17762 +#define        AIC_TEMPLATE_VERSIONED_ENTRIES() \
17763 +       .slave_alloc            = AIC_LIB_ENTRY(_linux_slave_alloc), \
17764 +       .slave_configure        = AIC_LIB_ENTRY(_linux_slave_configure), \
17765 +       .slave_destroy          = AIC_LIB_ENTRY(_linux_slave_destroy)
17766 +#else
17767 +#define        AIC_TEMPLATE_VERSIONED_ENTRIES() \
17768 +       .detect                 = AIC_LIB_ENTRY(_linux_detect), \
17769 +       .release                = AIC_LIB_ENTRY(_linux_release), \
17770 +       .select_queue_depths    = AIC_LIB_ENTRY(_linux_select_queue_depth), \
17771 +       .use_new_eh_code        = 1
17772 +#endif
17773 +
17774 +#define AIC_TEMPLATE_INITIALIZER(NAME, MAX_SECTORS)                    \
17775 +{                                                                      \
17776 +       .module                 = THIS_MODULE,                          \
17777 +       .name                   = NAME,                                 \
17778 +       .proc_info              = AIC_LIB_ENTRY(_linux_proc_info),      \
17779 +       .info                   = AIC_LIB_ENTRY(_linux_info),           \
17780 +       .queuecommand           = AIC_LIB_ENTRY(_linux_queue),          \
17781 +       .eh_abort_handler       = AIC_LIB_ENTRY(_linux_abort),          \
17782 +       .eh_device_reset_handler = AIC_LIB_ENTRY(_linux_dev_reset),     \
17783 +       .eh_bus_reset_handler   = AIC_LIB_ENTRY(_linux_bus_reset),      \
17784 +       .can_queue              = AIC_CONST_ENTRY(_MAX_QUEUE),          \
17785 +       .this_id                = -1,                                   \
17786 +       .cmd_per_lun            = 2,                                    \
17787 +       .use_clustering         = ENABLE_CLUSTERING,                    \
17788 +       AIC_TEMPLATE_MAX_SECTORS(MAX_SECTORS)                           \
17789 +       AIC_TEMPLATE_DMA_SETTINGS()                                     \
17790 +       AIC_TEMPLATE_BIOSPARAM()                                        \
17791 +       AIC_TEMPLATE_VERSIONED_ENTRIES()                                \
17792 +}
17793 +
17794 +/************************** OS Utility Wrappers *******************************/
17795 +#define printf printk
17796 +#define M_NOWAIT GFP_ATOMIC
17797 +#define M_WAITOK 0
17798 +#define malloc(size, type, flags) kmalloc(size, flags)
17799 +#define free(ptr, type) kfree(ptr)
17800 +
17801 +static __inline void aic_delay(long);
17802 +static __inline void
17803 +aic_delay(long usec)
17804 +{
17805 +       /*
17806 +        * udelay on Linux can have problems for
17807 +        * multi-millisecond waits.  Wait at most
17808 +        * 1024us per call.
17809 +        */
17810 +       while (usec > 0) {
17811 +               udelay(usec % 1024);
17812 +               usec -= 1024;
17813 +       }
17814 +}
17815 +
17816 +/********************************** Misc Macros *******************************/
17817 +#define        roundup(x, y)   ((((x)+((y)-1))/(y))*(y))
17818 +#define        powerof2(x)     ((((x)-1)&(x))==0)
17819 +
17820 +/******************************* Byte Order ***********************************/
17821 +#define aic_htobe16(x) cpu_to_be16(x)
17822 +#define aic_htobe32(x) cpu_to_be32(x)
17823 +#define aic_htobe64(x) cpu_to_be64(x)
17824 +#define aic_htole16(x) cpu_to_le16(x)
17825 +#define aic_htole32(x) cpu_to_le32(x)
17826 +#define aic_htole64(x) cpu_to_le64(x)
17827 +
17828 +#define aic_be16toh(x) be16_to_cpu(x)
17829 +#define aic_be32toh(x) be32_to_cpu(x)
17830 +#define aic_be64toh(x) be64_to_cpu(x)
17831 +#define aic_le16toh(x) le16_to_cpu(x)
17832 +#define aic_le32toh(x) le32_to_cpu(x)
17833 +#define aic_le64toh(x) le64_to_cpu(x)
17834 +
17835 +#ifndef LITTLE_ENDIAN
17836 +#define LITTLE_ENDIAN 1234
17837 +#endif
17838 +
17839 +#ifndef BIG_ENDIAN
17840 +#define BIG_ENDIAN 4321
17841 +#endif
17842 +
17843 +#ifndef BYTE_ORDER
17844 +#if defined(__BIG_ENDIAN)
17845 +#define BYTE_ORDER BIG_ENDIAN
17846 +#endif
17847 +#if defined(__LITTLE_ENDIAN)
17848 +#define BYTE_ORDER LITTLE_ENDIAN
17849 +#endif
17850 +#endif /* BYTE_ORDER */
17851 +
17852 +/********************************* Core Includes ******************************/
17853 +#include AIC_CORE_INCLUDE
17854 +
17855 +/**************************** Front End Queues ********************************/
17856 +/*
17857 + * Data structure used to cast the Linux struct scsi_cmnd to something
17858 + * that allows us to use the queue macros.  The linux structure has
17859 + * plenty of space to hold the links fields as required by the queue
17860 + * macros, but the queue macors require them to have the correct type.
17861 + */
17862 +struct aic_cmd_internal {
17863 +       /* Area owned by the Linux scsi layer. */
17864 +       uint8_t private[offsetof(struct scsi_cmnd, SCp.Status)];
17865 +       union {
17866 +               STAILQ_ENTRY(aic_cmd)   ste;
17867 +               LIST_ENTRY(aic_cmd)     le;
17868 +               TAILQ_ENTRY(aic_cmd)    tqe;
17869 +       } links;
17870 +       uint32_t                        end;
17871 +};
17872 +
17873 +struct aic_cmd {
17874 +       union {
17875 +               struct aic_cmd_internal icmd;
17876 +               struct scsi_cmnd        scsi_cmd;
17877 +       } un;
17878 +};
17879 +
17880 +#define acmd_icmd(cmd) ((cmd)->un.icmd)
17881 +#define acmd_scsi_cmd(cmd) ((cmd)->un.scsi_cmd)
17882 +#define acmd_links un.icmd.links
17883 +
17884 +/*************************** Device Data Structures ***************************/
17885 +/*
17886 + * A per probed device structure used to deal with some error recovery
17887 + * scenarios that the Linux mid-layer code just doesn't know how to
17888 + * handle.  The structure allocated for a device only becomes persistent
17889 + * after a successfully completed inquiry command to the target when
17890 + * that inquiry data indicates a lun is present.
17891 + */
17892 +TAILQ_HEAD(aic_busyq, aic_cmd);
17893 +typedef enum {
17894 +       AIC_DEV_UNCONFIGURED     = 0x01,
17895 +       AIC_DEV_FREEZE_TIL_EMPTY = 0x02, /* Freeze queue until active == 0 */
17896 +       AIC_DEV_TIMER_ACTIVE     = 0x04, /* Our timer is active */
17897 +       AIC_DEV_ON_RUN_LIST      = 0x08, /* Queued to be run later */
17898 +       AIC_DEV_Q_BASIC          = 0x10, /* Allow basic device queuing */
17899 +       AIC_DEV_Q_TAGGED         = 0x20, /* Allow full SCSI2 command queueing */
17900 +       AIC_DEV_PERIODIC_OTAG    = 0x40, /* Send OTAG to prevent starvation */
17901 +       AIC_DEV_SLAVE_CONFIGURED = 0x80  /* slave_configure() has been called */
17902 +} aic_linux_dev_flags;
17903 +
17904 +struct aic_linux_target;
17905 +struct aic_linux_device {
17906 +       TAILQ_ENTRY(aic_linux_device) links;
17907 +       struct                  aic_busyq busyq;
17908 +
17909 +       /*
17910 +        * The number of transactions currently
17911 +        * queued to the device.
17912 +        */
17913 +       int                     active;
17914 +
17915 +       /*
17916 +        * The currently allowed number of 
17917 +        * transactions that can be queued to
17918 +        * the device.  Must be signed for
17919 +        * conversion from tagged to untagged
17920 +        * mode where the device may have more
17921 +        * than one outstanding active transaction.
17922 +        */
17923 +       int                     openings;
17924 +
17925 +       /*
17926 +        * A positive count indicates that this
17927 +        * device's queue is halted.
17928 +        */
17929 +       u_int                   qfrozen;
17930 +       
17931 +       /*
17932 +        * Cumulative command counter.
17933 +        */
17934 +       u_long                  commands_issued;
17935 +
17936 +       /*
17937 +        * The number of tagged transactions when
17938 +        * running at our current opening level
17939 +        * that have been successfully received by
17940 +        * this device since the last QUEUE FULL.
17941 +        */
17942 +       u_int                   tag_success_count;
17943 +#define AIC_TAG_SUCCESS_INTERVAL 50
17944 +
17945 +       aic_linux_dev_flags     flags;
17946 +
17947 +       /*
17948 +        * Per device timer.
17949 +        */
17950 +       struct timer_list       timer;
17951 +
17952 +       /*
17953 +        * The high limit for the tags variable.
17954 +        */
17955 +       u_int                   maxtags;
17956 +
17957 +       /*
17958 +        * The computed number of tags outstanding
17959 +        * at the time of the last QUEUE FULL event.
17960 +        */
17961 +       u_int                   tags_on_last_queuefull;
17962 +
17963 +       /*
17964 +        * How many times we have seen a queue full
17965 +        * with the same number of tags.  This is used
17966 +        * to stop our adaptive queue depth algorithm
17967 +        * on devices with a fixed number of tags.
17968 +        */
17969 +       u_int                   last_queuefull_same_count;
17970 +#define AIC_LOCK_TAGS_COUNT 50
17971 +
17972 +       /*
17973 +        * How many transactions have been queued
17974 +        * without the device going idle.  We use
17975 +        * this statistic to determine when to issue
17976 +        * an ordered tag to prevent transaction
17977 +        * starvation.  This statistic is only updated
17978 +        * if the AIC_DEV_PERIODIC_OTAG flag is set
17979 +        * on this device.
17980 +        */
17981 +       u_int                   commands_since_idle_or_otag;
17982 +#define AIC_OTAG_THRESH        500
17983 +
17984 +       int                     lun;
17985 +       Scsi_Device            *scsi_device;
17986 +       struct                  aic_linux_target *target;
17987 +};
17988 +
17989 +typedef enum {
17990 +       AIC_DV_REQUIRED          = 0x01,
17991 +       AIC_INQ_VALID            = 0x02,
17992 +       AIC_BASIC_DV             = 0x04,
17993 +       AIC_ENHANCED_DV          = 0x08
17994 +} aic_linux_targ_flags;
17995 +
17996 +/* DV States */
17997 +typedef enum {
17998 +       AIC_DV_STATE_EXIT = 0,
17999 +       AIC_DV_STATE_INQ_SHORT_ASYNC,
18000 +       AIC_DV_STATE_INQ_ASYNC,
18001 +       AIC_DV_STATE_INQ_ASYNC_VERIFY,
18002 +       AIC_DV_STATE_TUR,
18003 +       AIC_DV_STATE_REBD,
18004 +       AIC_DV_STATE_INQ_VERIFY,
18005 +       AIC_DV_STATE_WEB,
18006 +       AIC_DV_STATE_REB,
18007 +       AIC_DV_STATE_SU,
18008 +       AIC_DV_STATE_BUSY
18009 +} aic_dv_state;
18010 +
18011 +struct aic_linux_target {
18012 +       struct aic_linux_device  *devices[AIC_NUM_LUNS];
18013 +       int                       channel;
18014 +       int                       target;
18015 +       int                       refcount;
18016 +       struct aic_transinfo      last_tinfo;
18017 +       struct aic_softc         *softc;
18018 +       aic_linux_targ_flags      flags;
18019 +       struct scsi_inquiry_data *inq_data;
18020 +       /*
18021 +        * The next "fallback" period to use for narrow/wide transfers.
18022 +        */
18023 +       uint8_t                   dv_next_narrow_period;
18024 +       uint8_t                   dv_next_wide_period;
18025 +       uint8_t                   dv_max_width;
18026 +       uint8_t                   dv_max_ppr_options;
18027 +       uint8_t                   dv_last_ppr_options;
18028 +       u_int                     dv_echo_size;
18029 +       aic_dv_state              dv_state;
18030 +       u_int                     dv_state_retry;
18031 +       uint8_t                  *dv_buffer;
18032 +       uint8_t                  *dv_buffer1;
18033 +
18034 +       /*
18035 +        * Cumulative counter of errors.
18036 +        */
18037 +       u_long                  errors_detected;
18038 +       u_long                  cmds_since_error;
18039 +};
18040 +
18041 +/*************** OSM Dependent Components of Core Datastructures **************/
18042 +/*
18043 + * Per-SCB OSM storage.
18044 + */
18045 +typedef enum {
18046 +       AIC_SCB_UP_EH_SEM       = 0x1,
18047 +       AIC_TIMEOUT_ACTIVE      = 0x2,
18048 +       AIC_RELEASE_SIMQ        = 0x4
18049 +} aic_linux_scb_flags;
18050 +
18051 +struct scb_platform_data {
18052 +       struct aic_linux_device *dev;
18053 +       bus_addr_t               buf_busaddr;
18054 +       uint32_t                 xfer_len;
18055 +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,3,0)
18056 +       uint32_t                 resid;         /* Transfer residual */
18057 +#endif
18058 +       uint32_t                 sense_resid;   /* Auto-Sense residual */
18059 +       aic_linux_scb_flags      flags;
18060 +};
18061 +
18062 +/*
18063 + * Define a structure used for each host adapter.  All members are
18064 + * aligned on a boundary >= the size of the member to honor the
18065 + * alignment restrictions of the various platforms supported by
18066 + * this driver.
18067 + */
18068 +typedef enum {
18069 +       AIC_DV_WAIT_SIMQ_EMPTY   = 0x01,
18070 +       AIC_DV_WAIT_SIMQ_RELEASE = 0x02,
18071 +       AIC_DV_ACTIVE            = 0x04,
18072 +       AIC_DV_SHUTDOWN          = 0x08,
18073 +       AIC_RUN_CMPLT_Q_TIMER    = 0x10,
18074 +       AIC_BUS_SETTLE_TIMER     = 0x20
18075 +} aic_linux_softc_flags;
18076 +
18077 +TAILQ_HEAD(aic_completeq, aic_cmd);
18078 +
18079 +struct aic_platform_data {
18080 +       /*
18081 +        * Fields accessed from interrupt context.
18082 +        */
18083 +       struct aic_linux_target *targets[AIC_NUM_TARGETS]; 
18084 +       TAILQ_HEAD(, aic_linux_device) device_runq;
18085 +       struct aic_completeq     completeq;
18086 +
18087 +       spinlock_t               spin_lock;
18088 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,0)
18089 +       struct tasklet_struct    runq_tasklet;
18090 +       struct tasklet_struct    unblock_tasklet;
18091 +#endif
18092 +       u_int                    qfrozen;
18093 +       pid_t                    dv_pid;
18094 +       pid_t                    recovery_pid;
18095 +       struct timer_list        completeq_timer;
18096 +       struct timer_list        bus_settle_timer;
18097 +       struct timer_list        stats_timer;
18098 +       struct semaphore         eh_sem;
18099 +       struct semaphore         dv_sem;
18100 +       struct semaphore         dv_cmd_sem;
18101 +       struct semaphore         recovery_sem;
18102 +       struct semaphore         recovery_ending_sem;
18103 +       struct scsi_device      *dv_scsi_dev;
18104 +       struct Scsi_Host        *host;          /* pointer to scsi host */
18105 +#define AIC_LINUX_NOIRQ        ((uint32_t)~0)
18106 +       uint32_t                 irq;           /* IRQ for this adapter */
18107 +       uint32_t                 bios_address;
18108 +       uint32_t                 mem_busaddr;   /* Mem Base Addr */
18109 +       bus_addr_t               hw_dma_mask;
18110 +       aic_linux_softc_flags    flags;
18111 +};
18112 +
18113 +/***************************** Timer Facilities *******************************/
18114 +typedef void aic_linux_callback_t (u_long);  
18115 +void aic_platform_timeout(struct scsi_cmnd *);
18116 +void aic_linux_midlayer_timeout(struct scsi_cmnd *);
18117 +
18118 +#define aic_timer_init init_timer
18119 +#define aic_timer_stop del_timer_sync
18120 +static __inline void aic_timer_reset(aic_timer_t *timer, uint32_t usec,
18121 +                                    aic_callback_t *func, void *arg);
18122 +static __inline uint32_t aic_get_timeout(struct scb *);
18123 +static __inline void aic_scb_timer_start(struct scb *scb);
18124 +static __inline void aic_scb_timer_reset(struct scb *scb, uint32_t usec);
18125  
18126 +static __inline void
18127 +aic_timer_reset(aic_timer_t *timer, uint32_t usec,
18128 +               aic_callback_t *func, void *arg)
18129 +{
18130 +       struct aic_softc *aic;
18131 +
18132 +       aic = (struct aic_softc *)arg;
18133 +       del_timer(timer);
18134 +       timer->data = (u_long)arg;
18135 +       timer->expires = jiffies + (usec / AIC_USECS_PER_JIFFY);
18136 +       timer->function = (aic_linux_callback_t*)func;
18137 +       add_timer(timer);
18138 +}
18139 +
18140 +static __inline uint32_t
18141 +aic_get_timeout(struct scb *scb)
18142 +{
18143 +
18144 +       /*
18145 +        * Convert from jiffies to usec.
18146 +        */
18147 +       return (scb->io_ctx->timeout_per_command * AIC_USECS_PER_JIFFY);
18148 +}
18149 +
18150 +static __inline void
18151 +aic_scb_timer_start(struct scb *scb)
18152 +{
18153 +       scb->platform_data->flags |= AIC_TIMEOUT_ACTIVE;
18154 +       scsi_add_timer(scb->io_ctx, scb->io_ctx->timeout_per_command,
18155 +                      aic_platform_timeout);
18156 +}
18157 +
18158 +static __inline void
18159 +aic_scb_timer_reset(struct scb *scb, uint32_t usec)
18160 +{
18161 +       /*
18162 +        * Restore timer data that is clobbered by scsi_delete_timer().
18163 +        */
18164 +       scb->io_ctx->eh_timeout.data = (unsigned long)scb->io_ctx;
18165 +       scb->io_ctx->eh_timeout.function =
18166 +           (void (*)(unsigned long))aic_platform_timeout;
18167 +       scb->platform_data->flags |= AIC_TIMEOUT_ACTIVE;
18168 +       mod_timer(&scb->io_ctx->eh_timeout,
18169 +                 jiffies + (usec / AIC_USECS_PER_JIFFY));
18170 +}
18171 +
18172 +/************************* SCSI command formats *******************************/
18173  /*
18174   * Define dome bits that are in ALL (or a lot of) scsi commands
18175   */
18176 @@ -865,6 +1624,368 @@
18177  
18178  extern const char *scsi_sense_key_text[];
18179  
18180 +/*************************** Domain Validation ********************************/
18181 +#define AIC_DV_CMD(cmd) ((cmd)->scsi_done == aic_linux_dv_complete)
18182 +#define AIC_DV_SIMQ_FROZEN(aic)                                        \
18183 +       ((((aic)->platform_data->flags & AIC_DV_ACTIVE) != 0)   \
18184 +        && (aic)->platform_data->qfrozen == 1)
18185 +
18186 +/*********************** Transaction Access Wrappers **************************/
18187 +static __inline void aic_cmd_set_transaction_status(Scsi_Cmnd *, uint32_t);
18188 +static __inline void aic_set_transaction_status(struct scb *, uint32_t);
18189 +static __inline void aic_cmd_set_scsi_status(Scsi_Cmnd *, uint32_t);
18190 +static __inline void aic_set_scsi_status(struct scb *, uint32_t);
18191 +static __inline uint32_t aic_cmd_get_transaction_status(Scsi_Cmnd *cmd);
18192 +static __inline uint32_t aic_get_transaction_status(struct scb *);
18193 +static __inline uint32_t aic_cmd_get_scsi_status(Scsi_Cmnd *cmd);
18194 +static __inline uint32_t aic_get_scsi_status(struct scb *);
18195 +static __inline void aic_set_transaction_tag(struct scb *, int, u_int);
18196 +static __inline u_long aic_get_transfer_length(struct scb *);
18197 +static __inline int aic_get_transfer_dir(struct scb *);
18198 +static __inline void aic_set_residual(struct scb *, u_long);
18199 +static __inline void aic_set_sense_residual(struct scb *scb, u_long resid);
18200 +static __inline u_long aic_get_residual(struct scb *);
18201 +static __inline u_long aic_get_sense_residual(struct scb *);
18202 +static __inline int aic_perform_autosense(struct scb *);
18203 +static __inline uint32_t aic_get_sense_bufsize(struct aic_softc *,
18204 +                                              struct scb *);
18205 +static __inline void aic_notify_xfer_settings_change(struct aic_softc *,
18206 +                                                    struct aic_devinfo *);
18207 +static __inline void aic_platform_scb_free(struct aic_softc *aic,
18208 +                                          struct scb *scb);
18209 +static __inline void aic_freeze_scb(struct scb *scb);
18210 +
18211 +static __inline
18212 +void aic_cmd_set_transaction_status(Scsi_Cmnd *cmd, uint32_t status)
18213 +{
18214 +       cmd->result &= ~(CAM_STATUS_MASK << 16);
18215 +       cmd->result |= status << 16;
18216 +}
18217 +
18218 +static __inline
18219 +void aic_set_transaction_status(struct scb *scb, uint32_t status)
18220 +{
18221 +       aic_cmd_set_transaction_status(scb->io_ctx,status);
18222 +}
18223 +
18224 +static __inline
18225 +void aic_cmd_set_scsi_status(Scsi_Cmnd *cmd, uint32_t status)
18226 +{
18227 +       cmd->result &= ~0xFFFF;
18228 +       cmd->result |= status;
18229 +}
18230 +
18231 +static __inline
18232 +void aic_set_scsi_status(struct scb *scb, uint32_t status)
18233 +{
18234 +       aic_cmd_set_scsi_status(scb->io_ctx, status);
18235 +}
18236 +
18237 +static __inline
18238 +uint32_t aic_cmd_get_transaction_status(Scsi_Cmnd *cmd)
18239 +{
18240 +       return ((cmd->result >> 16) & CAM_STATUS_MASK);
18241 +}
18242 +
18243 +static __inline
18244 +uint32_t aic_get_transaction_status(struct scb *scb)
18245 +{
18246 +       return (aic_cmd_get_transaction_status(scb->io_ctx));
18247 +}
18248 +
18249 +static __inline
18250 +uint32_t aic_cmd_get_scsi_status(Scsi_Cmnd *cmd)
18251 +{
18252 +       return (cmd->result & 0xFFFF);
18253 +}
18254 +
18255 +static __inline
18256 +uint32_t aic_get_scsi_status(struct scb *scb)
18257 +{
18258 +       return (aic_cmd_get_scsi_status(scb->io_ctx));
18259 +}
18260 +
18261 +static __inline
18262 +void aic_set_transaction_tag(struct scb *scb, int enabled, u_int type)
18263 +{
18264 +       /*
18265 +        * Nothing to do for linux as the incoming transaction
18266 +        * has no concept of tag/non tagged, etc.
18267 +        */
18268 +}
18269 +
18270 +static __inline
18271 +u_long aic_get_transfer_length(struct scb *scb)
18272 +{
18273 +       return (scb->platform_data->xfer_len);
18274 +}
18275 +
18276 +static __inline
18277 +int aic_get_transfer_dir(struct scb *scb)
18278 +{
18279 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,3,40)
18280 +       return (scb->io_ctx->sc_data_direction);
18281 +#else
18282 +       if (scb->io_ctx->bufflen == 0)
18283 +               return (CAM_DIR_NONE);
18284 +
18285 +       switch(scb->io_ctx->cmnd[0]) {
18286 +       case 0x08:  /* READ(6)  */
18287 +       case 0x28:  /* READ(10) */
18288 +       case 0xA8:  /* READ(12) */
18289 +               return (CAM_DIR_IN);
18290 +        case 0x0A:  /* WRITE(6)  */
18291 +        case 0x2A:  /* WRITE(10) */
18292 +        case 0xAA:  /* WRITE(12) */
18293 +               return (CAM_DIR_OUT);
18294 +        default:
18295 +               return (CAM_DIR_NONE);
18296 +        }
18297 +#endif
18298 +}
18299 +
18300 +static __inline
18301 +void aic_set_residual(struct scb *scb, u_long resid)
18302 +{
18303 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,3,0)
18304 +       scb->io_ctx->resid = resid;
18305 +#else
18306 +       scb->platform_data->resid = resid;
18307 +#endif
18308 +}
18309 +
18310 +static __inline
18311 +void aic_set_sense_residual(struct scb *scb, u_long resid)
18312 +{
18313 +       scb->platform_data->sense_resid = resid;
18314 +}
18315 +
18316 +static __inline
18317 +u_long aic_get_residual(struct scb *scb)
18318 +{
18319 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,3,0)
18320 +       return (scb->io_ctx->resid);
18321 +#else
18322 +       return (scb->platform_data->resid);
18323 +#endif
18324 +}
18325 +
18326 +static __inline
18327 +u_long aic_get_sense_residual(struct scb *scb)
18328 +{
18329 +       return (scb->platform_data->sense_resid);
18330 +}
18331 +
18332 +static __inline
18333 +int aic_perform_autosense(struct scb *scb)
18334 +{
18335 +       /*
18336 +        * We always perform autosense in Linux.
18337 +        * On other platforms this is set on a
18338 +        * per-transaction basis.
18339 +        */
18340 +       return (1);
18341 +}
18342 +
18343 +static __inline uint32_t
18344 +aic_get_sense_bufsize(struct aic_softc *aic, struct scb *scb)
18345 +{
18346 +       return (sizeof(struct scsi_sense_data));
18347 +}
18348 +
18349 +static __inline void
18350 +aic_notify_xfer_settings_change(struct aic_softc *aic,
18351 +                               struct aic_devinfo *devinfo)
18352 +{
18353 +       /* Nothing to do here for linux */
18354 +}
18355 +
18356 +static __inline void
18357 +aic_platform_scb_free(struct aic_softc *aic, struct scb *scb)
18358 +{
18359 +       aic->flags &= ~AIC_RESOURCE_SHORTAGE;
18360 +}
18361 +
18362 +static __inline void
18363 +aic_freeze_scb(struct scb *scb)
18364 +{
18365 +       if ((scb->io_ctx->result & (CAM_DEV_QFRZN << 16)) == 0) {
18366 +                scb->io_ctx->result |= CAM_DEV_QFRZN << 16;
18367 +                scb->platform_data->dev->qfrozen++;
18368 +        }
18369 +}
18370 +
18371 +/******************************* PCI Definitions ******************************/
18372 +/*
18373 + * PCIM_xxx: mask to locate subfield in register
18374 + * PCIR_xxx: config register offset
18375 + * PCIC_xxx: device class
18376 + * PCIS_xxx: device subclass
18377 + * PCIP_xxx: device programming interface
18378 + * PCIV_xxx: PCI vendor ID (only required to fixup ancient devices)
18379 + * PCID_xxx: device ID
18380 + */
18381 +#define PCIR_DEVVENDOR         0x00
18382 +#define PCIR_VENDOR            0x00
18383 +#define PCIR_DEVICE            0x02
18384 +#define PCIR_COMMAND           0x04
18385 +#define PCIM_CMD_PORTEN                0x0001
18386 +#define PCIM_CMD_MEMEN         0x0002
18387 +#define PCIM_CMD_BUSMASTEREN   0x0004
18388 +#define PCIM_CMD_MWRICEN       0x0010
18389 +#define PCIM_CMD_PERRESPEN     0x0040
18390 +#define        PCIM_CMD_SERRESPEN      0x0100
18391 +#define PCIR_STATUS            0x06
18392 +#define PCIR_REVID             0x08
18393 +#define PCIR_PROGIF            0x09
18394 +#define PCIR_SUBCLASS          0x0a
18395 +#define PCIR_CLASS             0x0b
18396 +#define PCIR_CACHELNSZ         0x0c
18397 +#define PCIR_LATTIMER          0x0d
18398 +#define PCIR_HEADERTYPE                0x0e
18399 +#define PCIM_MFDEV             0x80
18400 +#define PCIR_BIST              0x0f
18401 +#define PCIR_CAP_PTR           0x34
18402 +
18403 +/* config registers for header type 0 devices */
18404 +#define PCIR_MAPS      0x10
18405 +#define PCIR_BARS      PCIR_MAPS
18406 +#define PCIR_BAR(x)    (PCIR_BARS + (x) * 4)
18407 +#define PCIR_SUBVEND_0 0x2c
18408 +#define PCIR_SUBDEV_0  0x2e
18409 +
18410 +typedef enum
18411 +{
18412 +       AIC_POWER_STATE_D0,
18413 +       AIC_POWER_STATE_D1,
18414 +       AIC_POWER_STATE_D2,
18415 +       AIC_POWER_STATE_D3
18416 +} aic_power_state;
18417 +
18418 +/****************************** PCI-X definitions *****************************/
18419 +#define PCIXR_COMMAND  0x96
18420 +#define PCIXR_DEVADDR  0x98
18421 +#define PCIXM_DEVADDR_FNUM     0x0003  /* Function Number */
18422 +#define PCIXM_DEVADDR_DNUM     0x00F8  /* Device Number */
18423 +#define PCIXM_DEVADDR_BNUM     0xFF00  /* Bus Number */
18424 +#define PCIXR_STATUS   0x9A
18425 +#define PCIXM_STATUS_64BIT     0x0001  /* Active 64bit connection to device. */
18426 +#define PCIXM_STATUS_133CAP    0x0002  /* Device is 133MHz capable */
18427 +#define PCIXM_STATUS_SCDISC    0x0004  /* Split Completion Discarded */
18428 +#define PCIXM_STATUS_UNEXPSC   0x0008  /* Unexpected Split Completion */
18429 +#define PCIXM_STATUS_CMPLEXDEV 0x0010  /* Device Complexity (set == bridge) */
18430 +#define PCIXM_STATUS_MAXMRDBC  0x0060  /* Maximum Burst Read Count */
18431 +#define PCIXM_STATUS_MAXSPLITS 0x0380  /* Maximum Split Transactions */
18432 +#define PCIXM_STATUS_MAXCRDS   0x1C00  /* Maximum Cumulative Read Size */
18433 +#define PCIXM_STATUS_RCVDSCEM  0x2000  /* Received a Split Comp w/Error msg */
18434 +
18435 +/**************************** KObject Wrappers ********************************/
18436 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,0)
18437 +#define        aic_dev_to_pci_dev(dev)         to_pci_dev(dev)
18438 +#define        aic_dev_to_eisa_dev(dev)        to_eisa_dev(dev)
18439 +#define        aic_pci_dev_to_dev(pci)         (&pci->dev)
18440 +#define        aic_eisa_dev_to_dev(eisa)       (&eisa->dev)
18441 +#else
18442 +#define        aic_dev_to_pci_dev(dev)         (dev)
18443 +#define        aic_dev_to_eisa_dev(dev)        (NULL)
18444 +#define        aic_pci_dev_to_dev(pci)         (pci)
18445 +#define        aic_eisa_dev_to_dev(eisa)       (NULL)
18446 +#endif
18447 +
18448 +#define        aic_pci_dev(aic)                aic_dev_to_pci_dev((aic)->dev_softc)
18449 +#define        aic_eisa_dev(aic)               aic_dev_to_eisa_dev((aic)->dev_softc)
18450 +/***************************** PCI Routines ***********************************/
18451 +static __inline uint32_t aic_pci_read_config(aic_dev_softc_t dev,
18452 +                                            int reg, int width);
18453 +static __inline void aic_pci_write_config(aic_dev_softc_t dev,
18454 +                                         int reg, uint32_t value,
18455 +                                         int width);
18456 +static __inline int aic_get_pci_function(aic_dev_softc_t);
18457 +static __inline int aic_get_pci_slot(aic_dev_softc_t);
18458 +static __inline int aic_get_pci_bus(aic_dev_softc_t);
18459 +
18460 +static __inline uint32_t
18461 +aic_pci_read_config(aic_dev_softc_t dev, int reg, int width)
18462 +{
18463 +       struct pci_dev *pci;
18464 +
18465 +       pci = aic_dev_to_pci_dev(dev);
18466 +       switch (width) {
18467 +       case 1:
18468 +       {
18469 +               uint8_t retval;
18470 +
18471 +               pci_read_config_byte(pci, reg, &retval);
18472 +               return (retval);
18473 +       }
18474 +       case 2:
18475 +       {
18476 +               uint16_t retval;
18477 +               pci_read_config_word(pci, reg, &retval);
18478 +               return (retval);
18479 +       }
18480 +       case 4:
18481 +       {
18482 +               uint32_t retval;
18483 +               pci_read_config_dword(pci, reg, &retval);
18484 +               return (retval);
18485 +       }
18486 +       default:
18487 +               panic("aic_pci_read_config: Read size too big");
18488 +               /* NOTREACHED */
18489 +               return (0);
18490 +       }
18491 +}
18492 +
18493 +static __inline void
18494 +aic_pci_write_config(aic_dev_softc_t dev, int reg, uint32_t value, int width)
18495 +{
18496 +       struct pci_dev *pci;
18497 +
18498 +       pci = aic_dev_to_pci_dev(dev);
18499 +       switch (width) {
18500 +       case 1:
18501 +               pci_write_config_byte(pci, reg, value);
18502 +               break;
18503 +       case 2:
18504 +               pci_write_config_word(pci, reg, value);
18505 +               break;
18506 +       case 4:
18507 +               pci_write_config_dword(pci, reg, value);
18508 +               break;
18509 +       default:
18510 +               panic("aic_pci_write_config: Write size too big");
18511 +               /* NOTREACHED */
18512 +       }
18513 +}
18514 +
18515 +static __inline int
18516 +aic_get_pci_function(aic_dev_softc_t dev)
18517 +{
18518 +       struct pci_dev *pci;
18519 +
18520 +       pci = aic_dev_to_pci_dev(dev);
18521 +       return (PCI_FUNC(pci->devfn));
18522 +}
18523 +
18524 +static __inline int
18525 +aic_get_pci_slot(aic_dev_softc_t dev)
18526 +{
18527 +       struct pci_dev *pci;
18528 +
18529 +       pci = aic_dev_to_pci_dev(dev);
18530 +       return (PCI_SLOT(pci->devfn));
18531 +}
18532 +
18533 +static __inline int
18534 +aic_get_pci_bus(aic_dev_softc_t dev)
18535 +{
18536 +       struct pci_dev *pci;
18537 +
18538 +       pci = aic_dev_to_pci_dev(dev);
18539 +       return (pci->bus->number);
18540 +}
18541 +
18542  /************************* Large Disk Handling ********************************/
18543  #if LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0)
18544  static __inline int aic_sector_div(u_long capacity, int heads, int sectors);
18545 @@ -886,34 +2007,31 @@
18546  }
18547  #endif
18548  
18549 -/**************************** Module Library Hack *****************************/
18550 -/*
18551 - * What we'd like to do is have a single "scsi library" module that both the
18552 - * aic7xxx and aic79xx drivers could load and depend on.  A cursory examination
18553 - * of implementing module dependencies in Linux (handling the install and
18554 - * initrd cases) does not look promissing.  For now, we just duplicate this
18555 - * code in both drivers using a simple symbol renaming scheme that hides this
18556 - * hack from the drivers.
18557 - */
18558 -#define AIC_LIB_ENTRY_CONCAT(x, prefix)        prefix ## x
18559 -#define        AIC_LIB_ENTRY_EXPAND(x, prefix) AIC_LIB_ENTRY_CONCAT(x, prefix)
18560 -#define AIC_LIB_ENTRY(x)               AIC_LIB_ENTRY_EXPAND(x, AIC_LIB_PREFIX)
18561 +/************************* Magic SysReq Support *******************************/
18562 +#include <linux/sysrq.h>
18563  
18564 -#define        aic_sense_desc                  AIC_LIB_ENTRY(_sense_desc)
18565 -#define        aic_sense_error_action          AIC_LIB_ENTRY(_sense_error_action)
18566 -#define        aic_error_action                AIC_LIB_ENTRY(_error_action)
18567 -#define        aic_op_desc                     AIC_LIB_ENTRY(_op_desc)
18568 -#define        aic_cdb_string                  AIC_LIB_ENTRY(_cdb_string)
18569 -#define aic_print_inquiry              AIC_LIB_ENTRY(_print_inquiry)
18570 -#define aic_calc_syncsrate             AIC_LIB_ENTRY(_calc_syncrate)
18571 -#define        aic_calc_syncparam              AIC_LIB_ENTRY(_calc_syncparam)
18572 -#define        aic_calc_speed                  AIC_LIB_ENTRY(_calc_speed)
18573 -#define        aic_inquiry_match               AIC_LIB_ENTRY(_inquiry_match)
18574 -#define        aic_static_inquiry_match        AIC_LIB_ENTRY(_static_inquiry_match)
18575 -#define        aic_parse_brace_option          AIC_LIB_ENTRY(_parse_brace_option)
18576 +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0)
18577 +typedef void aic_sysrq_handler_t (int, struct pt_regs *, struct kbd_struct *,
18578 +                                 struct tty_struct *);
18579 +#else
18580 +typedef void aic_sysrq_handler_t (int, struct pt_regs *, struct tty_struct *);
18581 +#endif
18582  
18583 -/******************************************************************************/
18584 +#ifdef CONFIG_MAGIC_SYSRQ
18585 +#define        aic_sysrq_key_op sysrq_key_op
18586 +#else
18587 +struct aic_sysrq_key_op {
18588 +       aic_sysrq_handler_t *handler;
18589 +       char *help_msg;
18590 +       char *action_msg;
18591 +};
18592 +#endif
18593  
18594 +aic_sysrq_handler_t    aic_sysrq_handler;
18595 +int                    aic_install_sysrq(struct aic_sysrq_key_op *);
18596 +void                   aic_remove_sysrq(int key,
18597 +                                        struct aic_sysrq_key_op *key_op);
18598 +/************************ SCSI Library Functions *****************************/
18599  void                   aic_sense_desc(int /*sense_key*/, int /*asc*/,
18600                                        int /*ascq*/, struct scsi_inquiry_data*,
18601                                        const char** /*sense_key_desc*/,
18602 @@ -1043,4 +2161,115 @@
18603         return (rv);
18604  }
18605  
18606 +/******************************* PCI Funcitons ********************************/
18607 +void aic_power_state_change(struct aic_softc *aic, aic_power_state new_state);
18608 +
18609 +/******************************* Queue Handling *******************************/
18610 +void                aic_runq_tasklet(unsigned long data);
18611 +void                aic_unblock_tasklet(unsigned long data);
18612 +void                aic_linux_run_device_queue(struct aic_softc*,
18613 +                                               struct aic_linux_device*);
18614 +void                aic_bus_settle_complete(u_long data);
18615 +void                aic_freeze_simq(struct aic_softc *aic);
18616 +void                aic_release_simq(struct aic_softc *aic);
18617 +void                aic_release_simq_locked(struct aic_softc *aic);
18618 +static __inline void aic_schedule_runq(struct aic_softc *aic);
18619 +static __inline void aic_schedule_unblock(struct aic_softc *aic);
18620 +static __inline struct aic_linux_device *
18621 +                    aic_linux_next_device_to_run(struct aic_softc *aic);
18622 +static __inline void aic_linux_check_device_queue(struct aic_softc *aic,
18623 +                                                 struct aic_linux_device *dev);
18624 +static __inline void aic_linux_run_device_queues(struct aic_softc *aic);
18625 +
18626 +/*
18627 + * Must be called with our lock held.
18628 + */
18629 +static __inline void
18630 +aic_schedule_runq(struct aic_softc *aic)
18631 +{
18632 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,0)
18633 +       tasklet_schedule(&aic->platform_data->runq_tasklet);
18634 +#else
18635 +       /*
18636 +        * Tasklets are not available, so run inline.
18637 +        */
18638 +       aic_runq_tasklet((unsigned long)aic);
18639 +#endif
18640 +}
18641 +
18642 +static __inline void
18643 +aic_schedule_unblock(struct aic_softc *aic)
18644 +{
18645 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,0)
18646 +       tasklet_schedule(&aic->platform_data->unblock_tasklet);
18647 +#else
18648 +#error "Fix 2.2.X Kernel Support"
18649 +#endif
18650 +}
18651 +
18652 +static __inline struct aic_linux_device *
18653 +aic_linux_next_device_to_run(struct aic_softc *aic)
18654 +{
18655 +       
18656 +       if ((aic->flags & AIC_RESOURCE_SHORTAGE) != 0
18657 +        || (aic->platform_data->qfrozen != 0
18658 +         && AIC_DV_SIMQ_FROZEN(aic) == 0))
18659 +               return (NULL);
18660 +       return (TAILQ_FIRST(&aic->platform_data->device_runq));
18661 +}
18662 +
18663 +static __inline void
18664 +aic_linux_check_device_queue(struct aic_softc *aic,
18665 +                            struct aic_linux_device *dev)
18666 +{
18667 +       if ((dev->flags & AIC_DEV_FREEZE_TIL_EMPTY) != 0
18668 +        && dev->active == 0) {
18669 +               dev->flags &= ~AIC_DEV_FREEZE_TIL_EMPTY;
18670 +               dev->qfrozen--;
18671 +       }
18672 +
18673 +       if (TAILQ_FIRST(&dev->busyq) == NULL
18674 +        || dev->openings == 0 || dev->qfrozen != 0)
18675 +               return;
18676 +
18677 +       aic_linux_run_device_queue(aic, dev);
18678 +}
18679 +
18680 +static __inline void
18681 +aic_linux_run_device_queues(struct aic_softc *aic)
18682 +{
18683 +       struct aic_linux_device *dev;
18684 +
18685 +       while ((dev = aic_linux_next_device_to_run(aic)) != NULL) {
18686 +               TAILQ_REMOVE(&aic->platform_data->device_runq, dev, links);
18687 +               dev->flags &= ~AIC_DEV_ON_RUN_LIST;
18688 +               aic_linux_check_device_queue(aic, dev);
18689 +       }
18690 +}
18691 +
18692 +/****************************** Tasklet Support *******************************/
18693 +static __inline void   aic_setup_tasklets(struct aic_softc *aic);
18694 +static __inline void   aic_teardown_tasklets(struct aic_softc *aic);
18695 +
18696 +static __inline void
18697 +aic_setup_tasklets(struct aic_softc *aic)
18698 +{
18699 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,0)
18700 +       tasklet_init(&aic->platform_data->runq_tasklet, aic_runq_tasklet,
18701 +                    (unsigned long)aic);
18702 +       tasklet_init(&aic->platform_data->unblock_tasklet, aic_unblock_tasklet,
18703 +                    (unsigned long)aic);
18704 +#endif
18705 +}
18706 +
18707 +static __inline void
18708 +aic_teardown_tasklets(struct aic_softc *aic)
18709 +{
18710 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,0)
18711 +       tasklet_kill(&aic->platform_data->runq_tasklet);
18712 +       tasklet_kill(&aic->platform_data->unblock_tasklet);
18713 +#endif
18714 +}
18715 +
18716 +
18717  #endif /*_AICLIB_H */
18718 diff -urN linux-2.4.24.org/drivers/scsi/aic7xxx/aiclib_pci.c linux-2.4.24/drivers/scsi/aic7xxx/aiclib_pci.c
18719 --- linux-2.4.24.org/drivers/scsi/aic7xxx/aiclib_pci.c  1970-01-01 01:00:00.000000000 +0100
18720 +++ linux-2.4.24/drivers/scsi/aic7xxx/aiclib_pci.c      2003-12-22 22:46:59.000000000 +0100
18721 @@ -0,0 +1,79 @@
18722 +/*
18723 + * Implementation of Utility functions for PCI controller types.
18724 + *
18725 + * Copyright (c) 2000-2003 Adaptec Inc.
18726 + * All rights reserved.
18727 + *
18728 + * Redistribution and use in source and binary forms, with or without
18729 + * modification, are permitted provided that the following conditions
18730 + * are met:
18731 + * 1. Redistributions of source code must retain the above copyright
18732 + *    notice, this list of conditions, and the following disclaimer,
18733 + *    without modification.
18734 + * 2. Redistributions in binary form must reproduce at minimum a disclaimer
18735 + *    substantially similar to the "NO WARRANTY" disclaimer below
18736 + *    ("Disclaimer") and any redistribution must be conditioned upon
18737 + *    including a substantially similar Disclaimer requirement for further
18738 + *    binary redistribution.
18739 + * 3. Neither the names of the above-listed copyright holders nor the names
18740 + *    of any contributors may be used to endorse or promote products derived
18741 + *    from this software without specific prior written permission.
18742 + *
18743 + * Alternatively, this software may be distributed under the terms of the
18744 + * GNU General Public License ("GPL") version 2 as published by the Free
18745 + * Software Foundation.
18746 + *
18747 + * NO WARRANTY
18748 + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
18749 + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18750 + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
18751 + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
18752 + * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
18753 + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
18754 + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
18755 + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
18756 + * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
18757 + * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
18758 + * POSSIBILITY OF SUCH DAMAGES.
18759 + *
18760 + * $Id$
18761 + */
18762 +
18763 +void
18764 +aic_power_state_change(struct aic_softc *aic, aic_power_state new_state)
18765 +{
18766 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,0)
18767 +       pci_set_power_state(aic_dev_to_pci_dev(aic->dev_softc), new_state);
18768 +#else
18769 +       uint32_t cap;
18770 +       u_int cap_offset;
18771 +
18772 +       /*
18773 +        * Traverse the capability list looking for
18774 +        * the power management capability.
18775 +        */
18776 +       cap = 0;
18777 +       cap_offset = aic_pci_read_config(aic->dev_softc,
18778 +                                        PCIR_CAP_PTR, /*bytes*/1);
18779 +       while (cap_offset != 0) {
18780 +
18781 +               cap = aic_pci_read_config(aic->dev_softc,
18782 +                                         cap_offset, /*bytes*/4);
18783 +               if ((cap & 0xFF) == 1
18784 +                && ((cap >> 16) & 0x3) > 0) {
18785 +                       uint32_t pm_control;
18786 +
18787 +                       pm_control = aic_pci_read_config(aic->dev_softc,
18788 +                                                        cap_offset + 4,
18789 +                                                        /*bytes*/4);
18790 +                       pm_control &= ~0x3;
18791 +                       pm_control |= new_state;
18792 +                       aic_pci_write_config(aic->dev_softc,
18793 +                                            cap_offset + 4,
18794 +                                            pm_control, /*bytes*/2);
18795 +                       break;
18796 +               }
18797 +               cap_offset = (cap >> 8) & 0xFF;
18798 +       }
18799 +#endif 
18800 +}
18801 diff -urN linux-2.4.24.org/drivers/scsi/aic7xxx/Makefile linux-2.4.24/drivers/scsi/aic7xxx/Makefile
18802 --- linux-2.4.24.org/drivers/scsi/aic7xxx/Makefile      2004-01-08 11:57:43.074992349 +0100
18803 +++ linux-2.4.24/drivers/scsi/aic7xxx/Makefile  2003-12-22 22:46:59.000000000 +0100
18804 @@ -64,8 +64,13 @@
18805         $(LD) $(LD_RFLAG) -r -o $@ $(obj-aic79xx)
18806  
18807  ifeq ($(CONFIG_AIC7XXX_BUILD_FIRMWARE),y)
18808 +# Create a dependency chain in generated files
18809 +# to avoid concurrent invocations of the single
18810 +# rule that builds them all.
18811 +aic7xxx_seq.h: aic7xxx_reg.h
18812  aic7xxx_gen = aic7xxx_seq.h aic7xxx_reg.h
18813  ifeq ($(CONFIG_AIC7XXX_REG_PRETTY_PRINT),y)
18814 +aic7xxx_reg.h: aic7xxx_reg_print.c
18815  aic7xxx_gen += aic7xxx_reg_print.c
18816  aic7xxx_asm_cmd = aicasm/aicasm -I. -r aic7xxx_reg.h           \
18817                  -p aic7xxx_reg_print.c -i aic7xxx_osm.h        \
18818 @@ -79,8 +84,13 @@
18819  endif
18820  
18821  ifeq ($(CONFIG_AIC79XX_BUILD_FIRMWARE),y)
18822 +# Create a dependency chain in generated files
18823 +# to avoid concurrent invocations of the single
18824 +# rule that builds them all.
18825 +aic79xx_seq.h: aic79xx_reg.h
18826  aic79xx_gen = aic79xx_seq.h aic79xx_reg.h
18827  ifeq ($(CONFIG_AIC79XX_REG_PRETTY_PRINT),y)
18828 +aic79xx_reg.h: aic79xx_reg_print.c
18829  aic79xx_gen += aic79xx_reg_print.c
18830  aic79xx_asm_cmd = aicasm/aicasm -I. -r aic79xx_reg.h           \
18831                  -p aic79xx_reg_print.c -i aic79xx_osm.h        \
18832 diff -urN linux-2.4.24.org/drivers/scsi/aic7xxx/README.aic79xx linux-2.4.24/drivers/scsi/aic7xxx/README.aic79xx
18833 --- linux-2.4.24.org/drivers/scsi/aic7xxx/README.aic79xx        2004-01-08 11:57:43.072992762 +0100
18834 +++ linux-2.4.24/drivers/scsi/aic7xxx/README.aic79xx    2003-12-22 22:46:59.000000000 +0100
18835 @@ -1,5 +1,5 @@
18836  ====================================================================
18837 -=             Adaptec Ultra320 Family Manager Set v1.3.0           =
18838 +=             Adaptec Ultra320 Family Manager Set v2.0.5           =
18839  =                                                                  =
18840  =                            README for                            =
18841  =                    The Linux Operating System                    =
18842 @@ -19,34 +19,159 @@
18843     The following Adaptec SCSI Host Adapters are supported by this 
18844     driver set. 
18845  
18846 -   Ultra320 Adapters         Description
18847 +   Ultra320 ASIC              Description
18848     ----------------------------------------------------------------
18849 -   Adaptec SCSI Card 39320   Dual Channel 64-bit PCI-X 133MHz to
18850 -                             Ultra320 SCSI Card (one external 
18851 -                             68-pin, two internal 68-pin)
18852 -   Adaptec SCSI Card 39320D  Dual Channel 64-bit PCI-X 133MHz to
18853 -                             Ultra320 SCSI Card (two external VHDC
18854 -                             and one internal 68-pin)
18855 -   Adaptec SCSI Card 39320D  Dual Channel 64-bit PCI-X 133MHz to
18856 -                             Ultra320 SCSI Card (two external VHDC
18857 -                             and one internal 68-pin) based on the
18858 -                             AIC-7902B ASIC
18859 -   Adaptec SCSI Card 29320   Single Channel 64-bit PCI-X 133MHz to
18860 -                             Ultra320 SCSI Card (one external 
18861 -                             68-pin, two internal 68-pin, one
18862 -                             internal 50-pin)
18863 -   Adaptec SCSI Card 29320LP Single Channel 64-bit Low Profile
18864 -                             PCI-X 133MHz to Ultra320 SCSI Card
18865 -                             (One external VHDC, one internal
18866 -                             68-pin)
18867 -   AIC-7901A                 Single Channel 64-bit PCI-X 133MHz to 
18868 -                             Ultra320 SCSI ASIC
18869 -   AIC-7902A4                Dual Channel 64-bit PCI-X 133MHz to 
18870 -                             Ultra320 SCSI ASIC
18871 -   AIC-7902B                 Dual Channel 64-bit PCI-X 133MHz to
18872 -                             Ultra320 SCSI ASIC
18873 -
18874 +   AIC-7901A                  Single Channel 64-bit PCI-X 133MHz to 
18875 +                              Ultra320 SCSI ASIC
18876 +   AIC-7901B                  Single Channel 64-bit PCI-X 133MHz to 
18877 +                              Ultra320 SCSI ASIC with Retained Training
18878 +   AIC-7902A4                 Dual Channel 64-bit PCI-X 133MHz to 
18879 +                              Ultra320 SCSI ASIC
18880 +   AIC-7902B                  Dual Channel 64-bit PCI-X 133MHz to
18881 +                              Ultra320 SCSI ASIC with Retained Training
18882 +
18883 +   Ultra320 Adapters          Description                              ASIC
18884 +   --------------------------------------------------------------------------
18885 +   Adaptec SCSI Card 39320    Dual Channel 64-bit PCI-X 133MHz to   7902A4/7902B
18886 +                              Ultra320 SCSI Card (one external 
18887 +                              68-pin, two internal 68-pin)
18888 +   Adaptec SCSI Card 39320A   Dual Channel 64-bit PCI-X 133MHz to      7902B
18889 +                              Ultra320 SCSI Card (one external 
18890 +                              68-pin, two internal 68-pin)
18891 +   Adaptec SCSI Card 39320D   Dual Channel 64-bit PCI-X 133MHz to      7902A4
18892 +                              Ultra320 SCSI Card (two external VHDC
18893 +                              and one internal 68-pin)
18894 +   Adaptec SCSI Card 39320D   Dual Channel 64-bit PCI-X 133MHz to      7902A4
18895 +                              Ultra320 SCSI Card (two external VHDC
18896 +                              and one internal 68-pin) based on the
18897 +                              AIC-7902B ASIC
18898 +   Adaptec SCSI Card 29320    Single Channel 64-bit PCI-X 133MHz to    7901A
18899 +                              Ultra320 SCSI Card (one external 
18900 +                              68-pin, two internal 68-pin, one
18901 +                              internal 50-pin)
18902 +   Adaptec SCSI Card 29320A   Single Channel 64-bit PCI-X 133MHz to    7901B
18903 +                              Ultra320 SCSI Card (one external 
18904 +                              68-pin, two internal 68-pin, one
18905 +                              internal 50-pin)
18906 +   Adaptec SCSI Card 29320LP  Single Channel 64-bit Low Profile        7901A
18907 +                              PCI-X 133MHz to Ultra320 SCSI Card
18908 +                              (One external VHDC, one internal
18909 +                              68-pin)
18910 +   Adaptec SCSI Card 29320ALP Single Channel 64-bit Low Profile        7901B
18911 +                              PCI-X 133MHz to Ultra320 SCSI Card
18912 +                              (One external VHDC, one internal
18913 +                              68-pin)
18914  2. Version History
18915 +
18916 +   2.0.5 (December 22nd, 2003)
18917 +        - Correct a bug preventing the driver from renegotiating
18918 +          during auto-request operations when a check condition
18919 +          occurred for a zero length command.
18920 +        - Sniff sense information returned by targets for unit
18921 +          attention errors that may indicate that the device has
18922 +          been changed.  If we see such status for non Domain
18923 +          Validation related commands, start a DV scan for the
18924 +          target.  In the past, DV would only occur for hot-plugged
18925 +          devices if no target had been previously probed for a
18926 +          particular ID.  This change guarantees that the DV process
18927 +          will occur even if the user swaps devices without any
18928 +          interveining I/O to tell us that a device has gone missing.
18929 +          The old behavior, among other things, would fail to spin up
18930 +          drives that were hot-plugged since the Linux mid-layer
18931 +          will only spin-up drives on initial attach.
18932 +        - Correct several issues in the rundown of the good status
18933 +          FIFO during error recovery.  The typical failure scenario
18934 +          evidenced by this defect was the loss of several commands
18935 +          under high load when  several queue full conditions occured
18936 +          back to back.
18937 +
18938 +   2.0.4 (November 6th, 2003)
18939 +        - Support the 2.6.0-test9 kernel
18940 +        - Fix rare deadlock caused by using del_timer_sync from within
18941 +          a timer handler.
18942 +
18943 +   2.0.3 (October 21st, 2003)
18944 +        - On 7902A4 hardware, use the slow slew rate for transfer
18945 +          rates slower than U320.  This behavior matches the Windows
18946 +          driver.
18947 +        - Fix some issues with the ahd_flush_qoutfifo() routine.
18948 +        - Add a delay in the loop waiting for selection activity
18949 +          to cease.  Otherwise we may exhaust the loop counter too
18950 +          quickly on fast machines.
18951 +        - Return to processing bad status completions through the
18952 +          qoutfifo.  This reduces the amount of time the controller
18953 +          is paused for these kinds of errors.
18954 +        - Move additional common routines to the aiclib OSM library
18955 +          to reduce code duplication.
18956 +        - Leave removal of softcs from the global list of softcs to
18957 +          the OSM.  This allows us to avoid holding the list_lock during
18958 +          device destruction.
18959 +        - Enforce a bus settle delay for bus resets that the
18960 +          driver initiates.
18961 +        - Fall back to basic DV for U160 devices that lack an
18962 +          echo buffer.
18963 +
18964 +   2.0.2 (September 4th, 2003)
18965 +        - Move additional common routines to the aiclib OSM library
18966 +          to reduce code duplication.
18967 +        - Avoid an inadvertant reset of the controller during the
18968 +          memory mapped I/O test should the controller be left in
18969 +          the reset state prior to driver initialization.  On some
18970 +          systems, this extra reset resulted in a system hang due
18971 +          to a chip access that occurred too soon after reset.
18972 +        - Correct an endian bug in ahd_swap_with_next_hscb.  This
18973 +          corrects strong-arm support.
18974 +        - Reset the bus for transactions that timeout waiting for
18975 +          the bus to go free after a disconnect or command complete
18976 +          message.
18977 +
18978 +   2.0.1 (August 26th, 2003)
18979 +        - Add magic sysrq handler that causes a card dump to be output
18980 +          to the console for each controller.
18981 +        - Avoid waking the mid-layer's error recovery handler during
18982 +          timeout recovery by returning DID_ERROR instead of DID_TIMEOUT
18983 +          for timed-out commands that have been aborted.
18984 +        - Move additional common routines to the aiclib OSM library
18985 +          to reduce code duplication.
18986 +
18987 +   2.0.0 (August 20th, 2003)
18988 +        - Remove MMAPIO definition and allow memory mapped
18989 +          I/O for any platform that supports PCI.
18990 +        - Avoid clearing ENBUSFREE during single stepping to avoid
18991 +          spurious "unexpected busfree while idle" messages.
18992 +        - Correct deadlock in ahd_run_qoutfifo() processing.
18993 +        - Optimize support for the 7901B.
18994 +        - Correct a few cases where an explicit flush of pending
18995 +          register writes was required to ensure acuracy in delays.
18996 +        - Correct problems in manually flushing completed commands
18997 +          on the controller.  The FIFOs are now flushed to ensure
18998 +          that completed commands that are still draining to the
18999 +          host are completed correctly.
19000 +        - Correct incomplete CDB delivery detection on the 790XB.
19001 +        - Ignore the cmd->underflow field since userland applications
19002 +          using the legacy command pass-thru interface do not set
19003 +          it correctly.  Honoring this field led to spurious errors
19004 +          when users used the "scsi_unique_id" program.
19005 +        - Perform timeout recovery within the driver instead of relying
19006 +          on the Linux SCSI mid-layer to perform this function.  The
19007 +          mid-layer does not know the full state of the SCSI bus and
19008 +          is therefore prone to looping for several minutes to effect
19009 +          recovery.  The new scheme recovers within 15 seconds of the
19010 +          failure.
19011 +        - Correct support for manual termination settings.
19012 +        - Increase maximum wait time for serial eeprom writes allowing
19013 +          writes to function correctly.
19014 +
19015 +   1.3.12 (August 11, 2003)
19016 +        - Implement new error recovery thread that supercedes the existing
19017 +          Linux SCSI error recovery code.
19018 +        - Fix termination logic for 29320ALP.
19019 +        - Fix SEEPROM delay to compensate for write ops taking longer.
19020 +
19021 +   1.3.11 (July 11, 2003)
19022 +        - Fix several deadlock issues.
19023 +        - Add 29320ALP and 39320B Id's.
19024 +
19025     1.3.10 (June 3rd, 2003)
19026          - Align the SCB_TAG field on a 16byte boundary.  This avoids
19027            SCB corruption on some PCI-33 busses.
19028 diff -urN linux-2.4.24.org/drivers/scsi/aic7xxx/README.aic7xxx linux-2.4.24/drivers/scsi/aic7xxx/README.aic7xxx
19029 --- linux-2.4.24.org/drivers/scsi/aic7xxx/README.aic7xxx        2004-01-08 11:57:43.071992969 +0100
19030 +++ linux-2.4.24/drivers/scsi/aic7xxx/README.aic7xxx    2003-12-22 22:46:59.000000000 +0100
19031 @@ -1,5 +1,5 @@
19032  ====================================================================
19033 -=    Adaptec Aic7xxx Fast -> Ultra160 Family Manager Set v6.2.28   =
19034 +=    Adaptec Aic7xxx Fast -> Ultra160 Family Manager Set v6.3.4    =
19035  =                            README for                            =
19036  =                     The Linux Operating System                   =
19037  ====================================================================
19038 @@ -131,6 +131,80 @@
19039        SCSI "stub" effects.
19040  
19041  2. Version History
19042 +
19043 +   6.3.4 (December 22nd, 2003)
19044 +        - Provide a better description string for the 2915/30LP.
19045 +        - Sniff sense information returned by targets for unit
19046 +          attention errors that may indicate that the device has
19047 +          been changed.  If we see such status for non Domain
19048 +          Validation related commands, start a DV scan for the
19049 +          target.  In the past, DV would only occur for hot-plugged
19050 +          devices if no target had been previously probed for a
19051 +          particular ID.  This change guarantees that the DV process
19052 +          will occur even if the user swaps devices without any
19053 +          interveining I/O to tell us that a device has gone missing.
19054 +          The old behavior, among other things, would fail to spin up
19055 +          drives that were hot-plugged since the Linux mid-layer
19056 +          will only spin-up drives on initial attach.
19057 +
19058 +   6.3.3 (November 6th, 2003)
19059 +        - Support the 2.6.0-test9 kernel
19060 +        - Fix rare deadlock caused by using del_timer_sync from within
19061 +          a timer handler.
19062 +
19063 +   6.3.2 (October 28th, 2003)
19064 +        - Enforce a bus settle delay for bus resets that the
19065 +          driver initiates.
19066 +        - Fall back to basic DV for U160 devices that lack an
19067 +          echo buffer.
19068 +        - Correctly detect that left over BIOS data has not
19069 +          been initialized when the CHPRST status bit is set
19070 +          during driver initialization.
19071 +
19072 +   6.3.1 (October 21st, 2003)
19073 +        - Fix a compiler error when building with only EISA or PCI
19074 +          support compiled into the kernel.
19075 +        - Add chained dependencies to both the driver and aicasm Makefiles
19076 +          to avoid problems with parallel builds.
19077 +        - Move additional common routines to the aiclib OSM library
19078 +          to reduce code duplication.
19079 +        - Fix a bug in the testing of the AHC_TMODE_WIDEODD_BUG that
19080 +          could cause target mode operations to hang.
19081 +        - Leave removal of softcs from the global list of softcs to
19082 +          the OSM.  This allows us to avoid holding the list_lock during
19083 +          device destruction.
19084 +
19085 +   6.3.0 (September 8th, 2003)
19086 +        - Move additional common routines to the aiclib OSM library
19087 +          to reduce code duplication.
19088 +        - Bump minor number to reflect change in error recovery strategy.
19089 +
19090 +   6.2.38 (August 31st, 2003)
19091 +        - Avoid an inadvertant reset of the controller during the
19092 +          memory mapped I/O test should the controller be left in
19093 +          the reset state prior to driver initialization.  On some
19094 +          systems, this extra reset resulted in a system hang due
19095 +          to a chip access that occurred too soon after reset.
19096 +        - Move additional common routines to the aiclib OSM library
19097 +          to reduce code duplication.
19098 +        - Add magic sysrq handler that causes a card dump to be output
19099 +          to the console for each controller.
19100 +
19101 +   6.2.37 (August 12th, 2003)
19102 +        - Perform timeout recovery within the driver instead of relying
19103 +          on the Linux SCSI mid-layer to perform this function.  The
19104 +          mid-layer does not know the full state of the SCSI bus and
19105 +          is therefore prone to looping for several minutes to effect
19106 +          recovery.  The new scheme recovers within 15 seconds of the
19107 +          failure.
19108 +        - Support writing 93c56/66 SEEPROM on newer cards.
19109 +       - Avoid clearing ENBUSFREE during single stepping to avoid
19110 +          spurious "unexpected busfree while idle" messages.
19111 +        - Enable the use of the "Auto-Access-Pause" feature on the
19112 +          aic7880 and aic7870 chips.  It was disabled due to an
19113 +          oversight.  Using this feature drastically reduces command
19114 +          delivery latency.
19115 +
19116     6.2.36 (June 3rd, 2003)
19117          - Correct code that disables PCI parity error checking.
19118          - Correct and simplify handling of the ignore wide residue
This page took 3.939665 seconds and 3 git commands to generate.