da2b042628958fba2e4371891dec9cad045e9b8c
[linux-2.6.git] / drivers / scsi / advansys.c
1 #define ASC_VERSION "3.3K"    /* AdvanSys Driver Version */
2
3 /*
4  * advansys.c - Linux Host Driver for AdvanSys SCSI Adapters
5  *
6  * Copyright (c) 1995-2000 Advanced System Products, Inc.
7  * Copyright (c) 2000-2001 ConnectCom Solutions, Inc.
8  * All Rights Reserved.
9  *
10  * Redistribution and use in source and binary forms, with or without
11  * modification, are permitted provided that redistributions of source
12  * code retain the above copyright notice and this comment without
13  * modification.
14  *
15  * As of March 8, 2000 Advanced System Products, Inc. (AdvanSys)
16  * changed its name to ConnectCom Solutions, Inc.
17  *
18  */
19
20 /*
21
22   Documentation for the AdvanSys Driver
23
24   A. Linux Kernels Supported by this Driver
25   B. Adapters Supported by this Driver
26   C. Linux source files modified by AdvanSys Driver
27   D. Source Comments
28   E. Driver Compile Time Options and Debugging
29   F. Driver LILO Option
30   G. Tests to run before releasing new driver
31   H. Release History
32   I. Known Problems/Fix List
33   J. Credits (Chronological Order)
34
35   A. Linux Kernels Supported by this Driver
36
37      This driver has been tested in the following Linux kernels: v2.2.18
38      v2.4.0. The driver is supported on v2.2 and v2.4 kernels and on x86,
39      alpha, and PowerPC platforms.
40
41   B. Adapters Supported by this Driver
42
43      AdvanSys (Advanced System Products, Inc.) manufactures the following
44      RISC-based, Bus-Mastering, Fast (10 Mhz) and Ultra (20 Mhz) Narrow
45      (8-bit transfer) SCSI Host Adapters for the ISA, EISA, VL, and PCI
46      buses and RISC-based, Bus-Mastering, Ultra (20 Mhz) Wide (16-bit
47      transfer) SCSI Host Adapters for the PCI bus.
48
49      The CDB counts below indicate the number of SCSI CDB (Command
50      Descriptor Block) requests that can be stored in the RISC chip
51      cache and board LRAM. A CDB is a single SCSI command. The driver
52      detect routine will display the number of CDBs available for each
53      adapter detected. The number of CDBs used by the driver can be
54      lowered in the BIOS by changing the 'Host Queue Size' adapter setting.
55
56      Laptop Products:
57         ABP-480 - Bus-Master CardBus (16 CDB) (2.4 kernel and greater)
58
59      Connectivity Products:
60         ABP510/5150 - Bus-Master ISA (240 CDB)
61         ABP5140 - Bus-Master ISA PnP (16 CDB)
62         ABP5142 - Bus-Master ISA PnP with floppy (16 CDB)
63         ABP902/3902 - Bus-Master PCI (16 CDB)
64         ABP3905 - Bus-Master PCI (16 CDB)
65         ABP915 - Bus-Master PCI (16 CDB)
66         ABP920 - Bus-Master PCI (16 CDB)
67         ABP3922 - Bus-Master PCI (16 CDB)
68         ABP3925 - Bus-Master PCI (16 CDB)
69         ABP930 - Bus-Master PCI (16 CDB)
70         ABP930U - Bus-Master PCI Ultra (16 CDB)
71         ABP930UA - Bus-Master PCI Ultra (16 CDB)
72         ABP960 - Bus-Master PCI MAC/PC (16 CDB)
73         ABP960U - Bus-Master PCI MAC/PC Ultra (16 CDB)
74
75      Single Channel Products:
76         ABP542 - Bus-Master ISA with floppy (240 CDB)
77         ABP742 - Bus-Master EISA (240 CDB)
78         ABP842 - Bus-Master VL (240 CDB)
79         ABP940 - Bus-Master PCI (240 CDB)
80         ABP940U - Bus-Master PCI Ultra (240 CDB)
81         ABP940UA/3940UA - Bus-Master PCI Ultra (240 CDB)
82         ABP970 - Bus-Master PCI MAC/PC (240 CDB)
83         ABP970U - Bus-Master PCI MAC/PC Ultra (240 CDB)
84         ABP3960UA - Bus-Master PCI MAC/PC Ultra (240 CDB)
85         ABP940UW/3940UW - Bus-Master PCI Ultra-Wide (253 CDB)
86         ABP970UW - Bus-Master PCI MAC/PC Ultra-Wide (253 CDB)
87         ABP3940U2W - Bus-Master PCI LVD/Ultra2-Wide (253 CDB)
88
89      Multi-Channel Products:
90         ABP752 - Dual Channel Bus-Master EISA (240 CDB Per Channel)
91         ABP852 - Dual Channel Bus-Master VL (240 CDB Per Channel)
92         ABP950 - Dual Channel Bus-Master PCI (240 CDB Per Channel)
93         ABP950UW - Dual Channel Bus-Master PCI Ultra-Wide (253 CDB Per Channel)
94         ABP980 - Four Channel Bus-Master PCI (240 CDB Per Channel)
95         ABP980U - Four Channel Bus-Master PCI Ultra (240 CDB Per Channel)
96         ABP980UA/3980UA - Four Channel Bus-Master PCI Ultra (16 CDB Per Chan.)
97         ABP3950U2W - Bus-Master PCI LVD/Ultra2-Wide and Ultra-Wide (253 CDB)
98         ABP3950U3W - Bus-Master PCI Dual LVD2/Ultra3-Wide (253 CDB)
99
100   C. Linux source files modified by AdvanSys Driver
101
102      This section for historical purposes documents the changes
103      originally made to the Linux kernel source to add the advansys
104      driver. As Linux has changed some of these files have also
105      been modified.
106
107      1. linux/arch/i386/config.in:
108
109           bool 'AdvanSys SCSI support' CONFIG_SCSI_ADVANSYS y
110
111      2. linux/drivers/scsi/hosts.c:
112
113           #ifdef CONFIG_SCSI_ADVANSYS
114           #include "advansys.h"
115           #endif
116
117         and after "static struct scsi_host_template builtin_scsi_hosts[] =":
118
119           #ifdef CONFIG_SCSI_ADVANSYS
120           ADVANSYS,
121           #endif
122
123      3. linux/drivers/scsi/Makefile:
124
125           ifdef CONFIG_SCSI_ADVANSYS
126           SCSI_SRCS := $(SCSI_SRCS) advansys.c
127           SCSI_OBJS := $(SCSI_OBJS) advansys.o
128           else
129           SCSI_MODULE_OBJS := $(SCSI_MODULE_OBJS) advansys.o
130           endif
131
132      4. linux/init/main.c:
133
134           extern void advansys_setup(char *str, int *ints);
135
136         and add the following lines to the bootsetups[] array.
137
138           #ifdef CONFIG_SCSI_ADVANSYS
139              { "advansys=", advansys_setup },
140           #endif
141
142   D. Source Comments
143
144      1. Use tab stops set to 4 for the source files. For vi use 'se tabstops=4'.
145
146      2. This driver should be maintained in multiple files. But to make
147         it easier to include with Linux and to follow Linux conventions,
148         the whole driver is maintained in the source files advansys.h and
149         advansys.c. In this file logical sections of the driver begin with
150         a comment that contains '---'. The following are the logical sections
151         of the driver below.
152
153            --- Linux Version
154            --- Linux Include File
155            --- Driver Options
156            --- Debugging Header
157            --- Asc Library Constants and Macros
158            --- Adv Library Constants and Macros
159            --- Driver Constants and Macros
160            --- Driver Structures
161            --- Driver Data
162            --- Driver Function Prototypes
163            --- Linux 'struct scsi_host_template' and advansys_setup() Functions
164            --- Loadable Driver Support
165            --- Miscellaneous Driver Functions
166            --- Functions Required by the Asc Library
167            --- Functions Required by the Adv Library
168            --- Tracing and Debugging Functions
169            --- Asc Library Functions
170            --- Adv Library Functions
171
172      3. The string 'XXX' is used to flag code that needs to be re-written
173         or that contains a problem that needs to be addressed.
174
175      4. I have stripped comments from and reformatted the source for the
176         Asc Library and Adv Library to reduce the size of this file. This
177         source can be found under the following headings. The Asc Library
178         is used to support Narrow Boards. The Adv Library is used to
179         support Wide Boards.
180
181            --- Asc Library Constants and Macros
182            --- Adv Library Constants and Macros
183            --- Asc Library Functions
184            --- Adv Library Functions
185
186   E. Driver Compile Time Options and Debugging
187
188      In this source file the following constants can be defined. They are
189      defined in the source below. Both of these options are enabled by
190      default.
191
192      1. ADVANSYS_ASSERT - Enable driver assertions (Def: Enabled)
193
194         Enabling this option adds assertion logic statements to the
195         driver. If an assertion fails a message will be displayed to
196         the console, but the system will continue to operate. Any
197         assertions encountered should be reported to the person
198         responsible for the driver. Assertion statements may proactively
199         detect problems with the driver and facilitate fixing these
200         problems. Enabling assertions will add a small overhead to the
201         execution of the driver.
202
203      2. ADVANSYS_DEBUG - Enable driver debugging (Def: Disabled)
204
205         Enabling this option adds tracing functions to the driver and
206         the ability to set a driver tracing level at boot time. This
207         option will also export symbols not required outside the driver to
208         the kernel name space. This option is very useful for debugging
209         the driver, but it will add to the size of the driver execution
210         image and add overhead to the execution of the driver.
211
212         The amount of debugging output can be controlled with the global
213         variable 'asc_dbglvl'. The higher the number the more output. By
214         default the debug level is 0.
215
216         If the driver is loaded at boot time and the LILO Driver Option
217         is included in the system, the debug level can be changed by
218         specifying a 5th (ASC_NUM_IOPORT_PROBE + 1) I/O Port. The
219         first three hex digits of the pseudo I/O Port must be set to
220         'deb' and the fourth hex digit specifies the debug level: 0 - F.
221         The following command line will look for an adapter at 0x330
222         and set the debug level to 2.
223
224            linux advansys=0x330,0,0,0,0xdeb2
225
226         If the driver is built as a loadable module this variable can be
227         defined when the driver is loaded. The following insmod command
228         will set the debug level to one.
229
230            insmod advansys.o asc_dbglvl=1
231
232         Debugging Message Levels:
233            0: Errors Only
234            1: High-Level Tracing
235            2-N: Verbose Tracing
236
237         To enable debug output to console, please make sure that:
238
239         a. System and kernel logging is enabled (syslogd, klogd running).
240         b. Kernel messages are routed to console output. Check
241            /etc/syslog.conf for an entry similar to this:
242
243                 kern.*                  /dev/console
244
245         c. klogd is started with the appropriate -c parameter
246            (e.g. klogd -c 8)
247
248         This will cause printk() messages to be be displayed on the
249         current console. Refer to the klogd(8) and syslogd(8) man pages
250         for details.
251
252         Alternatively you can enable printk() to console with this
253         program. However, this is not the 'official' way to do this.
254         Debug output is logged in /var/log/messages.
255
256           main()
257           {
258                   syscall(103, 7, 0, 0);
259           }
260
261         Increasing LOG_BUF_LEN in kernel/printk.c to something like
262         40960 allows more debug messages to be buffered in the kernel
263         and written to the console or log file.
264
265      3. ADVANSYS_STATS - Enable statistics (Def: Enabled >= v1.3.0)
266
267         Enabling this option adds statistics collection and display
268         through /proc to the driver. The information is useful for
269         monitoring driver and device performance. It will add to the
270         size of the driver execution image and add minor overhead to
271         the execution of the driver.
272
273         Statistics are maintained on a per adapter basis. Driver entry
274         point call counts and transfer size counts are maintained.
275         Statistics are only available for kernels greater than or equal
276         to v1.3.0 with the CONFIG_PROC_FS (/proc) file system configured.
277
278         AdvanSys SCSI adapter files have the following path name format:
279
280            /proc/scsi/advansys/[0-(ASC_NUM_BOARD_SUPPORTED-1)]
281
282         This information can be displayed with cat. For example:
283
284            cat /proc/scsi/advansys/0
285
286         When ADVANSYS_STATS is not defined the AdvanSys /proc files only
287         contain adapter and device configuration information.
288
289   F. Driver LILO Option
290
291      If init/main.c is modified as described in the 'Directions for Adding
292      the AdvanSys Driver to Linux' section (B.4.) above, the driver will
293      recognize the 'advansys' LILO command line and /etc/lilo.conf option.
294      This option can be used to either disable I/O port scanning or to limit
295      scanning to 1 - 4 I/O ports. Regardless of the option setting EISA and
296      PCI boards will still be searched for and detected. This option only
297      affects searching for ISA and VL boards.
298
299      Examples:
300        1. Eliminate I/O port scanning:
301             boot: linux advansys=
302               or
303             boot: linux advansys=0x0
304        2. Limit I/O port scanning to one I/O port:
305             boot: linux advansys=0x110
306        3. Limit I/O port scanning to four I/O ports:
307             boot: linux advansys=0x110,0x210,0x230,0x330
308
309      For a loadable module the same effect can be achieved by setting
310      the 'asc_iopflag' variable and 'asc_ioport' array when loading
311      the driver, e.g.
312
313            insmod advansys.o asc_iopflag=1 asc_ioport=0x110,0x330
314
315      If ADVANSYS_DEBUG is defined a 5th (ASC_NUM_IOPORT_PROBE + 1)
316      I/O Port may be added to specify the driver debug level. Refer to
317      the 'Driver Compile Time Options and Debugging' section above for
318      more information.
319
320   G. Tests to run before releasing new driver
321
322      1. In the supported kernels verify there are no warning or compile
323         errors when the kernel is built as both a driver and as a module
324         and with the following options:
325
326         ADVANSYS_DEBUG - enabled and disabled
327         CONFIG_SMP - enabled and disabled
328         CONFIG_PROC_FS - enabled and disabled
329
330      2. Run tests on an x86, alpha, and PowerPC with at least one narrow
331         card and one wide card attached to a hard disk and CD-ROM drive:
332         fdisk, mkfs, fsck, bonnie, copy/compare test from the
333         CD-ROM to the hard drive.
334
335   H. Release History
336
337      BETA-1.0 (12/23/95):
338          First Release
339
340      BETA-1.1 (12/28/95):
341          1. Prevent advansys_detect() from being called twice.
342          2. Add LILO 0xdeb[0-f] option to set 'asc_dbglvl'.
343
344      1.2 (1/12/96):
345          1. Prevent re-entrancy in the interrupt handler which
346             resulted in the driver hanging Linux.
347          2. Fix problem that prevented ABP-940 cards from being
348             recognized on some PCI motherboards.
349          3. Add support for the ABP-5140 PnP ISA card.
350          4. Fix check condition return status.
351          5. Add conditionally compiled code for Linux v1.3.X.
352
353      1.3 (2/23/96):
354          1. Fix problem in advansys_biosparam() that resulted in the
355             wrong drive geometry being returned for drives > 1GB with
356             extended translation enabled.
357          2. Add additional tracing during device initialization.
358          3. Change code that only applies to ISA PnP adapter.
359          4. Eliminate 'make dep' warning.
360          5. Try to fix problem with handling resets by increasing their
361             timeout value.
362
363      1.4 (5/8/96):
364          1. Change definitions to eliminate conflicts with other subsystems.
365          2. Add versioning code for the shared interrupt changes.
366          3. Eliminate problem in asc_rmqueue() with iterating after removing
367             a request.
368          4. Remove reset request loop problem from the "Known Problems or
369             Issues" section. This problem was isolated and fixed in the
370             mid-level SCSI driver.
371
372      1.5 (8/8/96):
373          1. Add support for ABP-940U (PCI Ultra) adapter.
374          2. Add support for IRQ sharing by setting the SA_SHIRQ flag for
375             request_irq and supplying a dev_id pointer to both request_irq()
376             and free_irq().
377          3. In AscSearchIOPortAddr11() restore a call to check_region() which
378             should be used before I/O port probing.
379          4. Fix bug in asc_prt_hex() which resulted in the displaying
380             the wrong data.
381          5. Incorporate miscellaneous Asc Library bug fixes and new microcode.
382          6. Change driver versioning to be specific to each Linux sub-level.
383          7. Change statistics gathering to be per adapter instead of global
384             to the driver.
385          8. Add more information and statistics to the adapter /proc file:
386             /proc/scsi/advansys[0...].
387          9. Remove 'cmd_per_lun' from the "Known Problems or Issues" list.
388             This problem has been addressed with the SCSI mid-level changes
389             made in v1.3.89. The advansys_select_queue_depths() function
390             was added for the v1.3.89 changes.
391
392      1.6 (9/10/96):
393          1. Incorporate miscellaneous Asc Library bug fixes and new microcode.
394
395      1.7 (9/25/96):
396          1. Enable clustering and optimize the setting of the maximum number
397             of scatter gather elements for any particular board. Clustering
398             increases CPU utilization, but results in a relatively larger
399             increase in I/O throughput.
400          2. Improve the performance of the request queuing functions by
401             adding a last pointer to the queue structure.
402          3. Correct problems with reset and abort request handling that
403             could have hung or crashed Linux.
404          4. Add more information to the adapter /proc file:
405             /proc/scsi/advansys[0...].
406          5. Remove the request timeout issue form the driver issues list.
407          6. Miscellaneous documentation additions and changes.
408
409      1.8 (10/4/96):
410          1. Make changes to handle the new v2.1.0 kernel memory mapping
411             in which a kernel virtual address may not be equivalent to its
412             bus or DMA memory address.
413          2. Change abort and reset request handling to make it yet even
414             more robust.
415          3. Try to mitigate request starvation by sending ordered requests
416             to heavily loaded, tag queuing enabled devices.
417          4. Maintain statistics on request response time.
418          5. Add request response time statistics and other information to
419             the adapter /proc file: /proc/scsi/advansys[0...].
420
421      1.9 (10/21/96):
422          1. Add conditionally compiled code (ASC_QUEUE_FLOW_CONTROL) to
423             make use of mid-level SCSI driver device queue depth flow
424             control mechanism. This will eliminate aborts caused by a
425             device being unable to keep up with requests and eliminate
426             repeat busy or QUEUE FULL status returned by a device.
427          2. Incorporate miscellaneous Asc Library bug fixes.
428          3. To allow the driver to work in kernels with broken module
429             support set 'cmd_per_lun' if the driver is compiled as a
430             module. This change affects kernels v1.3.89 to present.
431          4. Remove PCI BIOS address from the driver banner. The PCI BIOS
432             is relocated by the motherboard BIOS and its new address can
433             not be determined by the driver.
434          5. Add mid-level SCSI queue depth information to the adapter
435             /proc file: /proc/scsi/advansys[0...].
436
437      2.0 (11/14/96):
438          1. Change allocation of global structures used for device
439             initialization to guarantee they are in DMA-able memory.
440             Previously when the driver was loaded as a module these
441             structures might not have been in DMA-able memory, causing
442             device initialization to fail.
443
444      2.1 (12/30/96):
445          1. In advansys_reset(), if the request is a synchronous reset
446             request, even if the request serial number has changed, then
447             complete the request.
448          2. Add Asc Library bug fixes including new microcode.
449          3. Clear inquiry buffer before using it.
450          4. Correct ifdef typo.
451
452      2.2 (1/15/97):
453          1. Add Asc Library bug fixes including new microcode.
454          2. Add synchronous data transfer rate information to the
455             adapter /proc file: /proc/scsi/advansys[0...].
456          3. Change ADVANSYS_DEBUG to be disabled by default. This
457             will reduce the size of the driver image, eliminate execution
458             overhead, and remove unneeded symbols from the kernel symbol
459             space that were previously added by the driver.
460          4. Add new compile-time option ADVANSYS_ASSERT for assertion
461             code that used to be defined within ADVANSYS_DEBUG. This
462             option is enabled by default.
463
464      2.8 (5/26/97):
465          1. Change version number to 2.8 to synchronize the Linux driver
466             version numbering with other AdvanSys drivers.
467          2. Reformat source files without tabs to present the same view
468             of the file to everyone regardless of the editor tab setting
469             being used.
470          3. Add Asc Library bug fixes.
471
472      3.1A (1/8/98):
473          1. Change version number to 3.1 to indicate that support for
474             Ultra-Wide adapters (ABP-940UW) is included in this release.
475          2. Add Asc Library (Narrow Board) bug fixes.
476          3. Report an underrun condition with the host status byte set
477             to DID_UNDERRUN. Currently DID_UNDERRUN is defined to 0 which
478             causes the underrun condition to be ignored. When Linux defines
479             its own DID_UNDERRUN the constant defined in this file can be
480             removed.
481          4. Add patch to AscWaitTixISRDone().
482          5. Add support for up to 16 different AdvanSys host adapter SCSI
483             channels in one system. This allows four cards with four channels
484             to be used in one system.
485
486      3.1B (1/9/98):
487          1. Handle that PCI register base addresses are not always page
488             aligned even though ioremap() requires that the address argument
489             be page aligned.
490
491      3.1C (1/10/98):
492          1. Update latest BIOS version checked for from the /proc file.
493          2. Don't set microcode SDTR variable at initialization. Instead
494             wait until device capabilities have been detected from an Inquiry
495             command.
496
497      3.1D (1/21/98):
498          1. Improve performance when the driver is compiled as module by
499             allowing up to 64 scatter-gather elements instead of 8.
500
501      3.1E (5/1/98):
502          1. Set time delay in AscWaitTixISRDone() to 1000 ms.
503          2. Include SMP locking changes.
504          3. For v2.1.93 and newer kernels use CONFIG_PCI and new PCI BIOS
505             access functions.
506          4. Update board serial number printing.
507          5. Try allocating an IRQ both with and without the SA_INTERRUPT
508             flag set to allow IRQ sharing with drivers that do not set
509             the SA_INTERRUPT flag. Also display a more descriptive error
510             message if request_irq() fails.
511          6. Update to latest Asc and Adv Libraries.
512
513      3.2A (7/22/99):
514          1. Update Adv Library to 4.16 which includes support for
515             the ASC38C0800 (Ultra2/LVD) IC.
516
517      3.2B (8/23/99):
518          1. Correct PCI compile time option for v2.1.93 and greater
519             kernels, advansys_info() string, and debug compile time
520             option.
521          2. Correct DvcSleepMilliSecond() for v2.1.0 and greater
522             kernels. This caused an LVD detection/BIST problem problem
523             among other things.
524          3. Sort PCI cards by PCI Bus, Slot, Function ascending order
525             to be consistent with the BIOS.
526          4. Update to Asc Library S121 and Adv Library 5.2.
527
528      3.2C (8/24/99):
529          1. Correct PCI card detection bug introduced in 3.2B that
530             prevented PCI cards from being detected in kernels older
531             than v2.1.93.
532
533      3.2D (8/26/99):
534          1. Correct /proc device synchronous speed information display.
535             Also when re-negotiation is pending for a target device
536             note this condition with an * and footnote.
537          2. Correct initialization problem with Ultra-Wide cards that
538             have a pre-3.2 BIOS. A microcode variable changed locations
539             in 3.2 and greater BIOSes which caused WDTR to be attempted
540             erroneously with drives that don't support WDTR.
541
542      3.2E (8/30/99):
543          1. Fix compile error caused by v2.3.13 PCI structure change.
544          2. Remove field from ASCEEP_CONFIG that resulted in an EEPROM
545             checksum error for ISA cards.
546          3. Remove ASC_QUEUE_FLOW_CONTROL conditional code. The mid-level
547             SCSI changes that it depended on were never included in Linux.
548
549      3.2F (9/3/99):
550          1. Handle new initial function code added in v2.3.16 for all
551             driver versions.
552
553      3.2G (9/8/99):
554          1. Fix PCI board detection in v2.3.13 and greater kernels.
555          2. Fix comiple errors in v2.3.X with debugging enabled.
556
557      3.2H (9/13/99):
558          1. Add 64-bit address, long support for Alpha and UltraSPARC.
559             The driver has been verified to work on an Alpha system.
560          2. Add partial byte order handling support for Power PC and
561             other big-endian platforms. This support has not yet been
562             completed or verified.
563          3. For wide boards replace block zeroing of request and
564             scatter-gather structures with individual field initialization
565             to improve performance.
566          4. Correct and clarify ROM BIOS version detection.
567
568      3.2I (10/8/99):
569          1. Update to Adv Library 5.4.
570          2. Add v2.3.19 underrun reporting to asc_isr_callback() and
571             adv_isr_callback().  Remove DID_UNDERRUN constant and other
572             no longer needed code that previously documented the lack
573             of underrun handling.
574
575      3.2J (10/14/99):
576          1. Eliminate compile errors for v2.0 and earlier kernels.
577
578      3.2K (11/15/99):
579          1. Correct debug compile error in asc_prt_adv_scsi_req_q().
580          2. Update Adv Library to 5.5.
581          3. Add ifdef handling for /proc changes added in v2.3.28.
582          4. Increase Wide board scatter-gather list maximum length to
583             255 when the driver is compiled into the kernel.
584
585      3.2L (11/18/99):
586          1. Fix bug in adv_get_sglist() that caused an assertion failure
587             at line 7475. The reqp->sgblkp pointer must be initialized
588             to NULL in adv_get_sglist().
589
590      3.2M (11/29/99):
591          1. Really fix bug in adv_get_sglist().
592          2. Incorporate v2.3.29 changes into driver.
593
594      3.2N (4/1/00):
595          1. Add CONFIG_ISA ifdef code.
596          2. Include advansys_interrupts_enabled name change patch.
597          3. For >= v2.3.28 use new SCSI error handling with new function
598             advansys_eh_bus_reset(). Don't include an abort function
599             because of base library limitations.
600          4. For >= v2.3.28 use per board lock instead of io_request_lock.
601          5. For >= v2.3.28 eliminate advansys_command() and
602             advansys_command_done().
603          6. Add some changes for PowerPC (Big Endian) support, but it isn't
604             working yet.
605          7. Fix "nonexistent resource free" problem that occurred on a module
606             unload for boards with an I/O space >= 255. The 'n_io_port' field
607             is only one byte and can not be used to hold an ioport length more
608             than 255.
609
610      3.3A (4/4/00):
611          1. Update to Adv Library 5.8.
612          2. For wide cards add support for CDBs up to 16 bytes.
613          3. Eliminate warnings when CONFIG_PROC_FS is not defined.
614
615      3.3B (5/1/00):
616          1. Support for PowerPC (Big Endian) wide cards. Narrow cards
617             still need work.
618          2. Change bitfields to shift and mask access for endian
619             portability.
620
621      3.3C (10/13/00):
622          1. Update for latest 2.4 kernel.
623          2. Test ABP-480 CardBus support in 2.4 kernel - works!
624          3. Update to Asc Library S123.
625          4. Update to Adv Library 5.12.
626
627      3.3D (11/22/00):
628          1. Update for latest 2.4 kernel.
629          2. Create patches for 2.2 and 2.4 kernels.
630
631      3.3E (1/9/01):
632          1. Now that 2.4 is released remove ifdef code for kernel versions
633             less than 2.2. The driver is now only supported in kernels 2.2,
634             2.4, and greater.
635          2. Add code to release and acquire the io_request_lock in
636             the driver entrypoint functions: advansys_detect and
637             advansys_queuecommand. In kernel 2.4 the SCSI mid-level driver
638             still holds the io_request_lock on entry to SCSI low-level drivers.
639             This was supposed to be removed before 2.4 was released but never
640             happened. When the mid-level SCSI driver is changed all references
641             to the io_request_lock should be removed from the driver.
642          3. Simplify error handling by removing advansys_abort(),
643             AscAbortSRB(), AscResetDevice(). SCSI bus reset requests are
644             now handled by resetting the SCSI bus and fully re-initializing
645             the chip. This simple method of error recovery has proven to work
646             most reliably after attempts at different methods. Also now only
647             support the "new" error handling method and remove the obsolete
648             error handling interface.
649          4. Fix debug build errors.
650
651      3.3F (1/24/01):
652          1. Merge with ConnectCom version from Andy Kellner which
653             updates Adv Library to 5.14.
654          2. Make PowerPC (Big Endian) work for narrow cards and
655             fix problems writing EEPROM for wide cards.
656          3. Remove interrupts_enabled assertion function.
657
658      3.3G (2/16/01):
659          1. Return an error from narrow boards if passed a 16 byte
660             CDB. The wide board can already handle 16 byte CDBs.
661
662      3.3GJ (4/15/02):
663          1. hacks for lk 2.5 series (D. Gilbert)
664
665      3.3GJD (10/14/02):
666          1. change select_queue_depths to slave_configure
667          2. make cmd_per_lun be sane again
668
669      3.3K [2004/06/24]:
670          1. continuing cleanup for lk 2.6 series
671          2. Fix problem in lk 2.6.7-bk2 that broke PCI wide cards
672          3. Fix problem that oopsed ISA cards
673
674   I. Known Problems/Fix List (XXX)
675
676      1. Need to add memory mapping workaround. Test the memory mapping.
677         If it doesn't work revert to I/O port access. Can a test be done
678         safely?
679      2. Handle an interrupt not working. Keep an interrupt counter in
680         the interrupt handler. In the timeout function if the interrupt
681         has not occurred then print a message and run in polled mode.
682      3. Allow bus type scanning order to be changed.
683      4. Need to add support for target mode commands, cf. CAM XPT.
684
685   J. Credits (Chronological Order)
686
687      Bob Frey <bfrey@turbolinux.com.cn> wrote the AdvanSys SCSI driver
688      and maintained it up to 3.3F. He continues to answer questions
689      and help maintain the driver.
690
691      Nathan Hartwell <mage@cdc3.cdc.net> provided the directions and
692      basis for the Linux v1.3.X changes which were included in the
693      1.2 release.
694
695      Thomas E Zerucha <zerucha@shell.portal.com> pointed out a bug
696      in advansys_biosparam() which was fixed in the 1.3 release.
697
698      Erik Ratcliffe <erik@caldera.com> has done testing of the
699      AdvanSys driver in the Caldera releases.
700
701      Rik van Riel <H.H.vanRiel@fys.ruu.nl> provided a patch to
702      AscWaitTixISRDone() which he found necessary to make the
703      driver work with a SCSI-1 disk.
704
705      Mark Moran <mmoran@mmoran.com> has helped test Ultra-Wide
706      support in the 3.1A driver.
707
708      Doug Gilbert <dgilbert@interlog.com> has made changes and
709      suggestions to improve the driver and done a lot of testing.
710
711      Ken Mort <ken@mort.net> reported a DEBUG compile bug fixed
712      in 3.2K.
713
714      Tom Rini <trini@kernel.crashing.org> provided the CONFIG_ISA
715      patch and helped with PowerPC wide and narrow board support.
716
717      Philip Blundell <philb@gnu.org> provided an
718      advansys_interrupts_enabled patch.
719
720      Dave Jones <dave@denial.force9.co.uk> reported the compiler
721      warnings generated when CONFIG_PROC_FS was not defined in
722      the 3.2M driver.
723
724      Jerry Quinn <jlquinn@us.ibm.com> fixed PowerPC support (endian
725      problems) for wide cards.
726
727      Bryan Henderson <bryanh@giraffe-data.com> helped debug narrow
728      card error handling.
729
730      Manuel Veloso <veloso@pobox.com> worked hard on PowerPC narrow
731      board support and fixed a bug in AscGetEEPConfig().
732
733      Arnaldo Carvalho de Melo <acme@conectiva.com.br> made
734      save_flags/restore_flags changes.
735
736      Andy Kellner <AKellner@connectcom.net> continues the Advansys SCSI
737      driver development for ConnectCom (Version > 3.3F).
738
739   K. ConnectCom (AdvanSys) Contact Information
740
741      Mail:                   ConnectCom Solutions, Inc.
742                              1150 Ringwood Court
743                              San Jose, CA 95131
744      Operator/Sales:         1-408-383-9400
745      FAX:                    1-408-383-9612
746      Tech Support:           1-408-467-2930
747      Tech Support E-Mail:    linux@connectcom.net
748      FTP Site:               ftp.connectcom.net (login: anonymous)
749      Web Site:               http://www.connectcom.net
750
751 */
752
753 /*
754  * --- Linux Include Files
755  */
756
757 #include <linux/config.h>
758 #include <linux/module.h>
759
760 #if defined(CONFIG_X86) && !defined(CONFIG_ISA)
761 #define CONFIG_ISA
762 #endif /* CONFIG_X86 && !CONFIG_ISA */
763
764 #include <linux/string.h>
765 #include <linux/kernel.h>
766 #include <linux/types.h>
767 #include <linux/ioport.h>
768 #include <linux/interrupt.h>
769 #include <linux/delay.h>
770 #include <linux/slab.h>
771 #include <linux/mm.h>
772 #include <linux/proc_fs.h>
773 #include <linux/init.h>
774 #include <linux/blkdev.h>
775 #include <linux/stat.h>
776 #include <linux/spinlock.h>
777 #include <linux/dma-mapping.h>
778
779 #include <asm/io.h>
780 #include <asm/system.h>
781 #include <asm/dma.h>
782
783 /* FIXME: (by jejb@steeleye.com) This warning is present for two
784  * reasons:
785  *
786  * 1) This driver badly needs converting to the correct driver model
787  *    probing API
788  *
789  * 2) Although all of the necessary command mapping places have the
790  * appropriate dma_map.. APIs, the driver still processes its internal
791  * queue using bus_to_virt() and virt_to_bus() which are illegal under
792  * the API.  The entire queue processing structure will need to be
793  * altered to fix this.
794  */
795 #warning this driver is still not properly converted to the DMA API
796
797 #include <scsi/scsi_cmnd.h>
798 #include <scsi/scsi_device.h>
799 #include <scsi/scsi_tcq.h>
800 #include <scsi/scsi.h>
801 #include <scsi/scsi_host.h>
802 #include "advansys.h"
803 #ifdef CONFIG_PCI
804 #include <linux/pci.h>
805 #endif /* CONFIG_PCI */
806
807
808 /*
809  * --- Driver Options
810  */
811
812 /* Enable driver assertions. */
813 #define ADVANSYS_ASSERT
814
815 /* Enable driver /proc statistics. */
816 #define ADVANSYS_STATS
817
818 /* Enable driver tracing. */
819 /* #define ADVANSYS_DEBUG */
820
821
822 /*
823  * --- Debugging Header
824  */
825
826 #ifdef ADVANSYS_DEBUG
827 #define STATIC
828 #else /* ADVANSYS_DEBUG */
829 #define STATIC static
830 #endif /* ADVANSYS_DEBUG */
831
832
833 /*
834  * --- Asc Library Constants and Macros
835  */
836
837 #define ASC_LIB_VERSION_MAJOR  1
838 #define ASC_LIB_VERSION_MINOR  24
839 #define ASC_LIB_SERIAL_NUMBER  123
840
841 /*
842  * Portable Data Types
843  *
844  * Any instance where a 32-bit long or pointer type is assumed
845  * for precision or HW defined structures, the following define
846  * types must be used. In Linux the char, short, and int types
847  * are all consistent at 8, 16, and 32 bits respectively. Pointers
848  * and long types are 64 bits on Alpha and UltraSPARC.
849  */
850 #define ASC_PADDR __u32         /* Physical/Bus address data type. */
851 #define ASC_VADDR __u32         /* Virtual address data type. */
852 #define ASC_DCNT  __u32         /* Unsigned Data count type. */
853 #define ASC_SDCNT __s32         /* Signed Data count type. */
854
855 /*
856  * These macros are used to convert a virtual address to a
857  * 32-bit value. This currently can be used on Linux Alpha
858  * which uses 64-bit virtual address but a 32-bit bus address.
859  * This is likely to break in the future, but doing this now
860  * will give us time to change the HW and FW to handle 64-bit
861  * addresses.
862  */
863 #define ASC_VADDR_TO_U32   virt_to_bus
864 #define ASC_U32_TO_VADDR   bus_to_virt
865
866 typedef unsigned char uchar;
867
868 #ifndef TRUE
869 #define TRUE     (1)
870 #endif
871 #ifndef FALSE
872 #define FALSE    (0)
873 #endif
874
875 #define EOF      (-1)
876 #define ERR      (-1)
877 #define UW_ERR   (uint)(0xFFFF)
878 #define isodd_word(val)   ((((uint)val) & (uint)0x0001) != 0)
879 #define AscPCIConfigVendorIDRegister      0x0000
880 #define AscPCIConfigDeviceIDRegister      0x0002
881 #define AscPCIConfigCommandRegister       0x0004
882 #define AscPCIConfigStatusRegister        0x0006
883 #define AscPCIConfigRevisionIDRegister    0x0008
884 #define AscPCIConfigCacheSize             0x000C
885 #define AscPCIConfigLatencyTimer          0x000D
886 #define AscPCIIOBaseRegister              0x0010
887 #define AscPCICmdRegBits_IOMemBusMaster   0x0007
888 #define ASC_PCI_ID2BUS(id)    ((id) & 0xFF)
889 #define ASC_PCI_ID2DEV(id)    (((id) >> 11) & 0x1F)
890 #define ASC_PCI_ID2FUNC(id)   (((id) >> 8) & 0x7)
891 #define ASC_PCI_MKID(bus, dev, func) ((((dev) & 0x1F) << 11) | (((func) & 0x7) << 8) | ((bus) & 0xFF))
892 #define ASC_PCI_REVISION_3150             0x02
893 #define ASC_PCI_REVISION_3050             0x03
894
895 #define  ASC_DVCLIB_CALL_DONE     (1)
896 #define  ASC_DVCLIB_CALL_FAILED   (0)
897 #define  ASC_DVCLIB_CALL_ERROR    (-1)
898
899 #define PCI_VENDOR_ID_ASP               0x10cd
900 #define PCI_DEVICE_ID_ASP_1200A         0x1100
901 #define PCI_DEVICE_ID_ASP_ABP940        0x1200
902 #define PCI_DEVICE_ID_ASP_ABP940U       0x1300
903 #define PCI_DEVICE_ID_ASP_ABP940UW      0x2300
904 #define PCI_DEVICE_ID_38C0800_REV1      0x2500
905 #define PCI_DEVICE_ID_38C1600_REV1      0x2700
906
907 /*
908  * Enable CC_VERY_LONG_SG_LIST to support up to 64K element SG lists.
909  * The SRB structure will have to be changed and the ASC_SRB2SCSIQ()
910  * macro re-defined to be able to obtain a ASC_SCSI_Q pointer from the
911  * SRB structure.
912  */
913 #define CC_VERY_LONG_SG_LIST 0
914 #define ASC_SRB2SCSIQ(srb_ptr)  (srb_ptr)
915
916 #define PortAddr                 unsigned short    /* port address size  */
917 #define inp(port)                inb(port)
918 #define outp(port, byte)         outb((byte), (port))
919
920 #define inpw(port)               inw(port)
921 #define outpw(port, word)        outw((word), (port))
922
923 #define ASC_MAX_SG_QUEUE    7
924 #define ASC_MAX_SG_LIST     255
925
926 #define ASC_CS_TYPE  unsigned short
927
928 #define ASC_IS_ISA          (0x0001)
929 #define ASC_IS_ISAPNP       (0x0081)
930 #define ASC_IS_EISA         (0x0002)
931 #define ASC_IS_PCI          (0x0004)
932 #define ASC_IS_PCI_ULTRA    (0x0104)
933 #define ASC_IS_PCMCIA       (0x0008)
934 #define ASC_IS_MCA          (0x0020)
935 #define ASC_IS_VL           (0x0040)
936 #define ASC_ISA_PNP_PORT_ADDR  (0x279)
937 #define ASC_ISA_PNP_PORT_WRITE (ASC_ISA_PNP_PORT_ADDR+0x800)
938 #define ASC_IS_WIDESCSI_16  (0x0100)
939 #define ASC_IS_WIDESCSI_32  (0x0200)
940 #define ASC_IS_BIG_ENDIAN   (0x8000)
941 #define ASC_CHIP_MIN_VER_VL      (0x01)
942 #define ASC_CHIP_MAX_VER_VL      (0x07)
943 #define ASC_CHIP_MIN_VER_PCI     (0x09)
944 #define ASC_CHIP_MAX_VER_PCI     (0x0F)
945 #define ASC_CHIP_VER_PCI_BIT     (0x08)
946 #define ASC_CHIP_MIN_VER_ISA     (0x11)
947 #define ASC_CHIP_MIN_VER_ISA_PNP (0x21)
948 #define ASC_CHIP_MAX_VER_ISA     (0x27)
949 #define ASC_CHIP_VER_ISA_BIT     (0x30)
950 #define ASC_CHIP_VER_ISAPNP_BIT  (0x20)
951 #define ASC_CHIP_VER_ASYN_BUG    (0x21)
952 #define ASC_CHIP_VER_PCI             0x08
953 #define ASC_CHIP_VER_PCI_ULTRA_3150  (ASC_CHIP_VER_PCI | 0x02)
954 #define ASC_CHIP_VER_PCI_ULTRA_3050  (ASC_CHIP_VER_PCI | 0x03)
955 #define ASC_CHIP_MIN_VER_EISA (0x41)
956 #define ASC_CHIP_MAX_VER_EISA (0x47)
957 #define ASC_CHIP_VER_EISA_BIT (0x40)
958 #define ASC_CHIP_LATEST_VER_EISA   ((ASC_CHIP_MIN_VER_EISA - 1) + 3)
959 #define ASC_MAX_LIB_SUPPORTED_ISA_CHIP_VER   0x21
960 #define ASC_MAX_LIB_SUPPORTED_PCI_CHIP_VER   0x0A
961 #define ASC_MAX_VL_DMA_ADDR     (0x07FFFFFFL)
962 #define ASC_MAX_VL_DMA_COUNT    (0x07FFFFFFL)
963 #define ASC_MAX_PCI_DMA_ADDR    (0xFFFFFFFFL)
964 #define ASC_MAX_PCI_DMA_COUNT   (0xFFFFFFFFL)
965 #define ASC_MAX_ISA_DMA_ADDR    (0x00FFFFFFL)
966 #define ASC_MAX_ISA_DMA_COUNT   (0x00FFFFFFL)
967 #define ASC_MAX_EISA_DMA_ADDR   (0x07FFFFFFL)
968 #define ASC_MAX_EISA_DMA_COUNT  (0x07FFFFFFL)
969
970 #define ASC_SCSI_ID_BITS  3
971 #define ASC_SCSI_TIX_TYPE     uchar
972 #define ASC_ALL_DEVICE_BIT_SET  0xFF
973 #define ASC_SCSI_BIT_ID_TYPE  uchar
974 #define ASC_MAX_TID       7
975 #define ASC_MAX_LUN       7
976 #define ASC_SCSI_WIDTH_BIT_SET  0xFF
977 #define ASC_MAX_SENSE_LEN   32
978 #define ASC_MIN_SENSE_LEN   14
979 #define ASC_MAX_CDB_LEN     12
980 #define ASC_SCSI_RESET_HOLD_TIME_US  60
981
982 #define ADV_INQ_CLOCKING_ST_ONLY    0x0
983 #define ADV_INQ_CLOCKING_DT_ONLY    0x1
984 #define ADV_INQ_CLOCKING_ST_AND_DT  0x3
985
986 /*
987  * Inquiry SPC-2 SPI Byte 1 EVPD (Enable Vital Product Data)
988  * and CmdDt (Command Support Data) field bit definitions.
989  */
990 #define ADV_INQ_RTN_VPD_AND_CMDDT           0x3
991 #define ADV_INQ_RTN_CMDDT_FOR_OP_CODE       0x2
992 #define ADV_INQ_RTN_VPD_FOR_PG_CODE         0x1
993 #define ADV_INQ_RTN_STD_INQUIRY_DATA        0x0
994
995 #define ASC_SCSIDIR_NOCHK    0x00
996 #define ASC_SCSIDIR_T2H      0x08
997 #define ASC_SCSIDIR_H2T      0x10
998 #define ASC_SCSIDIR_NODATA   0x18
999 #define SCSI_ASC_NOMEDIA          0x3A
1000 #define ASC_SRB_HOST(x)  ((uchar)((uchar)(x) >> 4))
1001 #define ASC_SRB_TID(x)   ((uchar)((uchar)(x) & (uchar)0x0F))
1002 #define ASC_SRB_LUN(x)   ((uchar)((uint)(x) >> 13))
1003 #define PUT_CDB1(x)   ((uchar)((uint)(x) >> 8))
1004 #define MS_CMD_DONE    0x00
1005 #define MS_EXTEND      0x01
1006 #define MS_SDTR_LEN    0x03
1007 #define MS_SDTR_CODE   0x01
1008 #define MS_WDTR_LEN    0x02
1009 #define MS_WDTR_CODE   0x03
1010 #define MS_MDP_LEN    0x05
1011 #define MS_MDP_CODE   0x00
1012
1013 /*
1014  * Inquiry data structure and bitfield macros
1015  *
1016  * Only quantities of more than 1 bit are shifted, since the others are
1017  * just tested for true or false. C bitfields aren't portable between big
1018  * and little-endian platforms so they are not used.
1019  */
1020
1021 #define ASC_INQ_DVC_TYPE(inq)       ((inq)->periph & 0x1f)
1022 #define ASC_INQ_QUALIFIER(inq)      (((inq)->periph & 0xe0) >> 5)
1023 #define ASC_INQ_DVC_TYPE_MOD(inq)   ((inq)->devtype & 0x7f)
1024 #define ASC_INQ_REMOVABLE(inq)      ((inq)->devtype & 0x80)
1025 #define ASC_INQ_ANSI_VER(inq)       ((inq)->ver & 0x07)
1026 #define ASC_INQ_ECMA_VER(inq)       (((inq)->ver & 0x38) >> 3)
1027 #define ASC_INQ_ISO_VER(inq)        (((inq)->ver & 0xc0) >> 6)
1028 #define ASC_INQ_RESPONSE_FMT(inq)   ((inq)->byte3 & 0x0f)
1029 #define ASC_INQ_TERM_IO(inq)        ((inq)->byte3 & 0x40)
1030 #define ASC_INQ_ASYNC_NOTIF(inq)    ((inq)->byte3 & 0x80)
1031 #define ASC_INQ_SOFT_RESET(inq)     ((inq)->flags & 0x01)
1032 #define ASC_INQ_CMD_QUEUE(inq)      ((inq)->flags & 0x02)
1033 #define ASC_INQ_LINK_CMD(inq)       ((inq)->flags & 0x08)
1034 #define ASC_INQ_SYNC(inq)           ((inq)->flags & 0x10)
1035 #define ASC_INQ_WIDE16(inq)         ((inq)->flags & 0x20)
1036 #define ASC_INQ_WIDE32(inq)         ((inq)->flags & 0x40)
1037 #define ASC_INQ_REL_ADDR(inq)       ((inq)->flags & 0x80)
1038 #define ASC_INQ_INFO_UNIT(inq)      ((inq)->info & 0x01)
1039 #define ASC_INQ_QUICK_ARB(inq)      ((inq)->info & 0x02)
1040 #define ASC_INQ_CLOCKING(inq)       (((inq)->info & 0x0c) >> 2)
1041
1042 typedef struct {
1043     uchar               periph;
1044     uchar               devtype;
1045     uchar               ver;
1046     uchar               byte3;
1047     uchar               add_len;
1048     uchar               res1;
1049     uchar               res2;
1050     uchar               flags;
1051     uchar               vendor_id[8];
1052     uchar               product_id[16];
1053     uchar               product_rev_level[4];
1054 } ASC_SCSI_INQUIRY;
1055
1056 #define ASC_SG_LIST_PER_Q   7
1057 #define QS_FREE        0x00
1058 #define QS_READY       0x01
1059 #define QS_DISC1       0x02
1060 #define QS_DISC2       0x04
1061 #define QS_BUSY        0x08
1062 #define QS_ABORTED     0x40
1063 #define QS_DONE        0x80
1064 #define QC_NO_CALLBACK   0x01
1065 #define QC_SG_SWAP_QUEUE 0x02
1066 #define QC_SG_HEAD       0x04
1067 #define QC_DATA_IN       0x08
1068 #define QC_DATA_OUT      0x10
1069 #define QC_URGENT        0x20
1070 #define QC_MSG_OUT       0x40
1071 #define QC_REQ_SENSE     0x80
1072 #define QCSG_SG_XFER_LIST  0x02
1073 #define QCSG_SG_XFER_MORE  0x04
1074 #define QCSG_SG_XFER_END   0x08
1075 #define QD_IN_PROGRESS       0x00
1076 #define QD_NO_ERROR          0x01
1077 #define QD_ABORTED_BY_HOST   0x02
1078 #define QD_WITH_ERROR        0x04
1079 #define QD_INVALID_REQUEST   0x80
1080 #define QD_INVALID_HOST_NUM  0x81
1081 #define QD_INVALID_DEVICE    0x82
1082 #define QD_ERR_INTERNAL      0xFF
1083 #define QHSTA_NO_ERROR               0x00
1084 #define QHSTA_M_SEL_TIMEOUT          0x11
1085 #define QHSTA_M_DATA_OVER_RUN        0x12
1086 #define QHSTA_M_DATA_UNDER_RUN       0x12
1087 #define QHSTA_M_UNEXPECTED_BUS_FREE  0x13
1088 #define QHSTA_M_BAD_BUS_PHASE_SEQ    0x14
1089 #define QHSTA_D_QDONE_SG_LIST_CORRUPTED 0x21
1090 #define QHSTA_D_ASC_DVC_ERROR_CODE_SET  0x22
1091 #define QHSTA_D_HOST_ABORT_FAILED       0x23
1092 #define QHSTA_D_EXE_SCSI_Q_FAILED       0x24
1093 #define QHSTA_D_EXE_SCSI_Q_BUSY_TIMEOUT 0x25
1094 #define QHSTA_D_ASPI_NO_BUF_POOL        0x26
1095 #define QHSTA_M_WTM_TIMEOUT         0x41
1096 #define QHSTA_M_BAD_CMPL_STATUS_IN  0x42
1097 #define QHSTA_M_NO_AUTO_REQ_SENSE   0x43
1098 #define QHSTA_M_AUTO_REQ_SENSE_FAIL 0x44
1099 #define QHSTA_M_TARGET_STATUS_BUSY  0x45
1100 #define QHSTA_M_BAD_TAG_CODE        0x46
1101 #define QHSTA_M_BAD_QUEUE_FULL_OR_BUSY  0x47
1102 #define QHSTA_M_HUNG_REQ_SCSI_BUS_RESET 0x48
1103 #define QHSTA_D_LRAM_CMP_ERROR        0x81
1104 #define QHSTA_M_MICRO_CODE_ERROR_HALT 0xA1
1105 #define ASC_FLAG_SCSIQ_REQ        0x01
1106 #define ASC_FLAG_BIOS_SCSIQ_REQ   0x02
1107 #define ASC_FLAG_BIOS_ASYNC_IO    0x04
1108 #define ASC_FLAG_SRB_LINEAR_ADDR  0x08
1109 #define ASC_FLAG_WIN16            0x10
1110 #define ASC_FLAG_WIN32            0x20
1111 #define ASC_FLAG_ISA_OVER_16MB    0x40
1112 #define ASC_FLAG_DOS_VM_CALLBACK  0x80
1113 #define ASC_TAG_FLAG_EXTRA_BYTES               0x10
1114 #define ASC_TAG_FLAG_DISABLE_DISCONNECT        0x04
1115 #define ASC_TAG_FLAG_DISABLE_ASYN_USE_SYN_FIX  0x08
1116 #define ASC_TAG_FLAG_DISABLE_CHK_COND_INT_HOST 0x40
1117 #define ASC_SCSIQ_CPY_BEG              4
1118 #define ASC_SCSIQ_SGHD_CPY_BEG         2
1119 #define ASC_SCSIQ_B_FWD                0
1120 #define ASC_SCSIQ_B_BWD                1
1121 #define ASC_SCSIQ_B_STATUS             2
1122 #define ASC_SCSIQ_B_QNO                3
1123 #define ASC_SCSIQ_B_CNTL               4
1124 #define ASC_SCSIQ_B_SG_QUEUE_CNT       5
1125 #define ASC_SCSIQ_D_DATA_ADDR          8
1126 #define ASC_SCSIQ_D_DATA_CNT          12
1127 #define ASC_SCSIQ_B_SENSE_LEN         20
1128 #define ASC_SCSIQ_DONE_INFO_BEG       22
1129 #define ASC_SCSIQ_D_SRBPTR            22
1130 #define ASC_SCSIQ_B_TARGET_IX         26
1131 #define ASC_SCSIQ_B_CDB_LEN           28
1132 #define ASC_SCSIQ_B_TAG_CODE          29
1133 #define ASC_SCSIQ_W_VM_ID             30
1134 #define ASC_SCSIQ_DONE_STATUS         32
1135 #define ASC_SCSIQ_HOST_STATUS         33
1136 #define ASC_SCSIQ_SCSI_STATUS         34
1137 #define ASC_SCSIQ_CDB_BEG             36
1138 #define ASC_SCSIQ_DW_REMAIN_XFER_ADDR 56
1139 #define ASC_SCSIQ_DW_REMAIN_XFER_CNT  60
1140 #define ASC_SCSIQ_B_FIRST_SG_WK_QP    48
1141 #define ASC_SCSIQ_B_SG_WK_QP          49
1142 #define ASC_SCSIQ_B_SG_WK_IX          50
1143 #define ASC_SCSIQ_W_ALT_DC1           52
1144 #define ASC_SCSIQ_B_LIST_CNT          6
1145 #define ASC_SCSIQ_B_CUR_LIST_CNT      7
1146 #define ASC_SGQ_B_SG_CNTL             4
1147 #define ASC_SGQ_B_SG_HEAD_QP          5
1148 #define ASC_SGQ_B_SG_LIST_CNT         6
1149 #define ASC_SGQ_B_SG_CUR_LIST_CNT     7
1150 #define ASC_SGQ_LIST_BEG              8
1151 #define ASC_DEF_SCSI1_QNG    4
1152 #define ASC_MAX_SCSI1_QNG    4
1153 #define ASC_DEF_SCSI2_QNG    16
1154 #define ASC_MAX_SCSI2_QNG    32
1155 #define ASC_TAG_CODE_MASK    0x23
1156 #define ASC_STOP_REQ_RISC_STOP      0x01
1157 #define ASC_STOP_ACK_RISC_STOP      0x03
1158 #define ASC_STOP_CLEAN_UP_BUSY_Q    0x10
1159 #define ASC_STOP_CLEAN_UP_DISC_Q    0x20
1160 #define ASC_STOP_HOST_REQ_RISC_HALT 0x40
1161 #define ASC_TIDLUN_TO_IX(tid, lun)  (ASC_SCSI_TIX_TYPE)((tid) + ((lun)<<ASC_SCSI_ID_BITS))
1162 #define ASC_TID_TO_TARGET_ID(tid)   (ASC_SCSI_BIT_ID_TYPE)(0x01 << (tid))
1163 #define ASC_TIX_TO_TARGET_ID(tix)   (0x01 << ((tix) & ASC_MAX_TID))
1164 #define ASC_TIX_TO_TID(tix)         ((tix) & ASC_MAX_TID)
1165 #define ASC_TID_TO_TIX(tid)         ((tid) & ASC_MAX_TID)
1166 #define ASC_TIX_TO_LUN(tix)         (((tix) >> ASC_SCSI_ID_BITS) & ASC_MAX_LUN)
1167 #define ASC_QNO_TO_QADDR(q_no)      ((ASC_QADR_BEG)+((int)(q_no) << 6))
1168
1169 typedef struct asc_scsiq_1 {
1170     uchar               status;
1171     uchar               q_no;
1172     uchar               cntl;
1173     uchar               sg_queue_cnt;
1174     uchar               target_id;
1175     uchar               target_lun;
1176     ASC_PADDR           data_addr;
1177     ASC_DCNT            data_cnt;
1178     ASC_PADDR           sense_addr;
1179     uchar               sense_len;
1180     uchar               extra_bytes;
1181 } ASC_SCSIQ_1;
1182
1183 typedef struct asc_scsiq_2 {
1184     ASC_VADDR           srb_ptr;
1185     uchar               target_ix;
1186     uchar               flag;
1187     uchar               cdb_len;
1188     uchar               tag_code;
1189     ushort              vm_id;
1190 } ASC_SCSIQ_2;
1191
1192 typedef struct asc_scsiq_3 {
1193     uchar               done_stat;
1194     uchar               host_stat;
1195     uchar               scsi_stat;
1196     uchar               scsi_msg;
1197 } ASC_SCSIQ_3;
1198
1199 typedef struct asc_scsiq_4 {
1200     uchar               cdb[ASC_MAX_CDB_LEN];
1201     uchar               y_first_sg_list_qp;
1202     uchar               y_working_sg_qp;
1203     uchar               y_working_sg_ix;
1204     uchar               y_res;
1205     ushort              x_req_count;
1206     ushort              x_reconnect_rtn;
1207     ASC_PADDR           x_saved_data_addr;
1208     ASC_DCNT            x_saved_data_cnt;
1209 } ASC_SCSIQ_4;
1210
1211 typedef struct asc_q_done_info {
1212     ASC_SCSIQ_2         d2;
1213     ASC_SCSIQ_3         d3;
1214     uchar               q_status;
1215     uchar               q_no;
1216     uchar               cntl;
1217     uchar               sense_len;
1218     uchar               extra_bytes;
1219     uchar               res;
1220     ASC_DCNT            remain_bytes;
1221 } ASC_QDONE_INFO;
1222
1223 typedef struct asc_sg_list {
1224     ASC_PADDR           addr;
1225     ASC_DCNT            bytes;
1226 } ASC_SG_LIST;
1227
1228 typedef struct asc_sg_head {
1229     ushort              entry_cnt;
1230     ushort              queue_cnt;
1231     ushort              entry_to_copy;
1232     ushort              res;
1233     ASC_SG_LIST         sg_list[ASC_MAX_SG_LIST];
1234 } ASC_SG_HEAD;
1235
1236 #define ASC_MIN_SG_LIST   2
1237
1238 typedef struct asc_min_sg_head {
1239     ushort              entry_cnt;
1240     ushort              queue_cnt;
1241     ushort              entry_to_copy;
1242     ushort              res;
1243     ASC_SG_LIST         sg_list[ASC_MIN_SG_LIST];
1244 } ASC_MIN_SG_HEAD;
1245
1246 #define QCX_SORT        (0x0001)
1247 #define QCX_COALEASE    (0x0002)
1248
1249 typedef struct asc_scsi_q {
1250     ASC_SCSIQ_1         q1;
1251     ASC_SCSIQ_2         q2;
1252     uchar               *cdbptr;
1253     ASC_SG_HEAD         *sg_head;
1254     ushort              remain_sg_entry_cnt;
1255     ushort              next_sg_index;
1256 } ASC_SCSI_Q;
1257
1258 typedef struct asc_scsi_req_q {
1259     ASC_SCSIQ_1         r1;
1260     ASC_SCSIQ_2         r2;
1261     uchar               *cdbptr;
1262     ASC_SG_HEAD         *sg_head;
1263     uchar               *sense_ptr;
1264     ASC_SCSIQ_3         r3;
1265     uchar               cdb[ASC_MAX_CDB_LEN];
1266     uchar               sense[ASC_MIN_SENSE_LEN];
1267 } ASC_SCSI_REQ_Q;
1268
1269 typedef struct asc_scsi_bios_req_q {
1270     ASC_SCSIQ_1         r1;
1271     ASC_SCSIQ_2         r2;
1272     uchar               *cdbptr;
1273     ASC_SG_HEAD         *sg_head;
1274     uchar               *sense_ptr;
1275     ASC_SCSIQ_3         r3;
1276     uchar               cdb[ASC_MAX_CDB_LEN];
1277     uchar               sense[ASC_MIN_SENSE_LEN];
1278 } ASC_SCSI_BIOS_REQ_Q;
1279
1280 typedef struct asc_risc_q {
1281     uchar               fwd;
1282     uchar               bwd;
1283     ASC_SCSIQ_1         i1;
1284     ASC_SCSIQ_2         i2;
1285     ASC_SCSIQ_3         i3;
1286     ASC_SCSIQ_4         i4;
1287 } ASC_RISC_Q;
1288
1289 typedef struct asc_sg_list_q {
1290     uchar               seq_no;
1291     uchar               q_no;
1292     uchar               cntl;
1293     uchar               sg_head_qp;
1294     uchar               sg_list_cnt;
1295     uchar               sg_cur_list_cnt;
1296 } ASC_SG_LIST_Q;
1297
1298 typedef struct asc_risc_sg_list_q {
1299     uchar               fwd;
1300     uchar               bwd;
1301     ASC_SG_LIST_Q       sg;
1302     ASC_SG_LIST         sg_list[7];
1303 } ASC_RISC_SG_LIST_Q;
1304
1305 #define ASC_EXE_SCSI_IO_MAX_IDLE_LOOP  0x1000000UL
1306 #define ASC_EXE_SCSI_IO_MAX_WAIT_LOOP  1024
1307 #define ASCQ_ERR_NO_ERROR             0
1308 #define ASCQ_ERR_IO_NOT_FOUND         1
1309 #define ASCQ_ERR_LOCAL_MEM            2
1310 #define ASCQ_ERR_CHKSUM               3
1311 #define ASCQ_ERR_START_CHIP           4
1312 #define ASCQ_ERR_INT_TARGET_ID        5
1313 #define ASCQ_ERR_INT_LOCAL_MEM        6
1314 #define ASCQ_ERR_HALT_RISC            7
1315 #define ASCQ_ERR_GET_ASPI_ENTRY       8
1316 #define ASCQ_ERR_CLOSE_ASPI           9
1317 #define ASCQ_ERR_HOST_INQUIRY         0x0A
1318 #define ASCQ_ERR_SAVED_SRB_BAD        0x0B
1319 #define ASCQ_ERR_QCNTL_SG_LIST        0x0C
1320 #define ASCQ_ERR_Q_STATUS             0x0D
1321 #define ASCQ_ERR_WR_SCSIQ             0x0E
1322 #define ASCQ_ERR_PC_ADDR              0x0F
1323 #define ASCQ_ERR_SYN_OFFSET           0x10
1324 #define ASCQ_ERR_SYN_XFER_TIME        0x11
1325 #define ASCQ_ERR_LOCK_DMA             0x12
1326 #define ASCQ_ERR_UNLOCK_DMA           0x13
1327 #define ASCQ_ERR_VDS_CHK_INSTALL      0x14
1328 #define ASCQ_ERR_MICRO_CODE_HALT      0x15
1329 #define ASCQ_ERR_SET_LRAM_ADDR        0x16
1330 #define ASCQ_ERR_CUR_QNG              0x17
1331 #define ASCQ_ERR_SG_Q_LINKS           0x18
1332 #define ASCQ_ERR_SCSIQ_PTR            0x19
1333 #define ASCQ_ERR_ISR_RE_ENTRY         0x1A
1334 #define ASCQ_ERR_CRITICAL_RE_ENTRY    0x1B
1335 #define ASCQ_ERR_ISR_ON_CRITICAL      0x1C
1336 #define ASCQ_ERR_SG_LIST_ODD_ADDRESS  0x1D
1337 #define ASCQ_ERR_XFER_ADDRESS_TOO_BIG 0x1E
1338 #define ASCQ_ERR_SCSIQ_NULL_PTR       0x1F
1339 #define ASCQ_ERR_SCSIQ_BAD_NEXT_PTR   0x20
1340 #define ASCQ_ERR_GET_NUM_OF_FREE_Q    0x21
1341 #define ASCQ_ERR_SEND_SCSI_Q          0x22
1342 #define ASCQ_ERR_HOST_REQ_RISC_HALT   0x23
1343 #define ASCQ_ERR_RESET_SDTR           0x24
1344
1345 /*
1346  * Warning code values are set in ASC_DVC_VAR  'warn_code'.
1347  */
1348 #define ASC_WARN_NO_ERROR             0x0000
1349 #define ASC_WARN_IO_PORT_ROTATE       0x0001
1350 #define ASC_WARN_EEPROM_CHKSUM        0x0002
1351 #define ASC_WARN_IRQ_MODIFIED         0x0004
1352 #define ASC_WARN_AUTO_CONFIG          0x0008
1353 #define ASC_WARN_CMD_QNG_CONFLICT     0x0010
1354 #define ASC_WARN_EEPROM_RECOVER       0x0020
1355 #define ASC_WARN_CFG_MSW_RECOVER      0x0040
1356 #define ASC_WARN_SET_PCI_CONFIG_SPACE 0x0080
1357
1358 /*
1359  * Error code values are set in ASC_DVC_VAR  'err_code'.
1360  */
1361 #define ASC_IERR_WRITE_EEPROM         0x0001
1362 #define ASC_IERR_MCODE_CHKSUM         0x0002
1363 #define ASC_IERR_SET_PC_ADDR          0x0004
1364 #define ASC_IERR_START_STOP_CHIP      0x0008
1365 #define ASC_IERR_IRQ_NO               0x0010
1366 #define ASC_IERR_SET_IRQ_NO           0x0020
1367 #define ASC_IERR_CHIP_VERSION         0x0040
1368 #define ASC_IERR_SET_SCSI_ID          0x0080
1369 #define ASC_IERR_GET_PHY_ADDR         0x0100
1370 #define ASC_IERR_BAD_SIGNATURE        0x0200
1371 #define ASC_IERR_NO_BUS_TYPE          0x0400
1372 #define ASC_IERR_SCAM                 0x0800
1373 #define ASC_IERR_SET_SDTR             0x1000
1374 #define ASC_IERR_RW_LRAM              0x8000
1375
1376 #define ASC_DEF_IRQ_NO  10
1377 #define ASC_MAX_IRQ_NO  15
1378 #define ASC_MIN_IRQ_NO  10
1379 #define ASC_MIN_REMAIN_Q        (0x02)
1380 #define ASC_DEF_MAX_TOTAL_QNG   (0xF0)
1381 #define ASC_MIN_TAG_Q_PER_DVC   (0x04)
1382 #define ASC_DEF_TAG_Q_PER_DVC   (0x04)
1383 #define ASC_MIN_FREE_Q        ASC_MIN_REMAIN_Q
1384 #define ASC_MIN_TOTAL_QNG     ((ASC_MAX_SG_QUEUE)+(ASC_MIN_FREE_Q))
1385 #define ASC_MAX_TOTAL_QNG 240
1386 #define ASC_MAX_PCI_ULTRA_INRAM_TOTAL_QNG 16
1387 #define ASC_MAX_PCI_ULTRA_INRAM_TAG_QNG   8
1388 #define ASC_MAX_PCI_INRAM_TOTAL_QNG  20
1389 #define ASC_MAX_INRAM_TAG_QNG   16
1390 #define ASC_IOADR_TABLE_MAX_IX  11
1391 #define ASC_IOADR_GAP   0x10
1392 #define ASC_SEARCH_IOP_GAP 0x10
1393 #define ASC_MIN_IOP_ADDR   (PortAddr)0x0100
1394 #define ASC_MAX_IOP_ADDR   (PortAddr)0x3F0
1395 #define ASC_IOADR_1     (PortAddr)0x0110
1396 #define ASC_IOADR_2     (PortAddr)0x0130
1397 #define ASC_IOADR_3     (PortAddr)0x0150
1398 #define ASC_IOADR_4     (PortAddr)0x0190
1399 #define ASC_IOADR_5     (PortAddr)0x0210
1400 #define ASC_IOADR_6     (PortAddr)0x0230
1401 #define ASC_IOADR_7     (PortAddr)0x0250
1402 #define ASC_IOADR_8     (PortAddr)0x0330
1403 #define ASC_IOADR_DEF   ASC_IOADR_8
1404 #define ASC_LIB_SCSIQ_WK_SP        256
1405 #define ASC_MAX_SYN_XFER_NO        16
1406 #define ASC_SYN_MAX_OFFSET         0x0F
1407 #define ASC_DEF_SDTR_OFFSET        0x0F
1408 #define ASC_DEF_SDTR_INDEX         0x00
1409 #define ASC_SDTR_ULTRA_PCI_10MB_INDEX  0x02
1410 #define SYN_XFER_NS_0  25
1411 #define SYN_XFER_NS_1  30
1412 #define SYN_XFER_NS_2  35
1413 #define SYN_XFER_NS_3  40
1414 #define SYN_XFER_NS_4  50
1415 #define SYN_XFER_NS_5  60
1416 #define SYN_XFER_NS_6  70
1417 #define SYN_XFER_NS_7  85
1418 #define SYN_ULTRA_XFER_NS_0    12
1419 #define SYN_ULTRA_XFER_NS_1    19
1420 #define SYN_ULTRA_XFER_NS_2    25
1421 #define SYN_ULTRA_XFER_NS_3    32
1422 #define SYN_ULTRA_XFER_NS_4    38
1423 #define SYN_ULTRA_XFER_NS_5    44
1424 #define SYN_ULTRA_XFER_NS_6    50
1425 #define SYN_ULTRA_XFER_NS_7    57
1426 #define SYN_ULTRA_XFER_NS_8    63
1427 #define SYN_ULTRA_XFER_NS_9    69
1428 #define SYN_ULTRA_XFER_NS_10   75
1429 #define SYN_ULTRA_XFER_NS_11   82
1430 #define SYN_ULTRA_XFER_NS_12   88
1431 #define SYN_ULTRA_XFER_NS_13   94
1432 #define SYN_ULTRA_XFER_NS_14  100
1433 #define SYN_ULTRA_XFER_NS_15  107
1434
1435 typedef struct ext_msg {
1436     uchar               msg_type;
1437     uchar               msg_len;
1438     uchar               msg_req;
1439     union {
1440         struct {
1441             uchar               sdtr_xfer_period;
1442             uchar               sdtr_req_ack_offset;
1443         } sdtr;
1444         struct {
1445             uchar               wdtr_width;
1446         } wdtr;
1447         struct {
1448             uchar               mdp_b3;
1449             uchar               mdp_b2;
1450             uchar               mdp_b1;
1451             uchar               mdp_b0;
1452         } mdp;
1453     } u_ext_msg;
1454     uchar               res;
1455 } EXT_MSG;
1456
1457 #define xfer_period     u_ext_msg.sdtr.sdtr_xfer_period
1458 #define req_ack_offset  u_ext_msg.sdtr.sdtr_req_ack_offset
1459 #define wdtr_width      u_ext_msg.wdtr.wdtr_width
1460 #define mdp_b3          u_ext_msg.mdp_b3
1461 #define mdp_b2          u_ext_msg.mdp_b2
1462 #define mdp_b1          u_ext_msg.mdp_b1
1463 #define mdp_b0          u_ext_msg.mdp_b0
1464
1465 typedef struct asc_dvc_cfg {
1466     ASC_SCSI_BIT_ID_TYPE can_tagged_qng;
1467     ASC_SCSI_BIT_ID_TYPE cmd_qng_enabled;
1468     ASC_SCSI_BIT_ID_TYPE disc_enable;
1469     ASC_SCSI_BIT_ID_TYPE sdtr_enable;
1470     uchar               chip_scsi_id;
1471     uchar               isa_dma_speed;
1472     uchar               isa_dma_channel;
1473     uchar               chip_version;
1474     ushort              lib_serial_no;
1475     ushort              lib_version;
1476     ushort              mcode_date;
1477     ushort              mcode_version;
1478     uchar               max_tag_qng[ASC_MAX_TID + 1];
1479     uchar               *overrun_buf;
1480     uchar               sdtr_period_offset[ASC_MAX_TID + 1];
1481     ushort              pci_slot_info;
1482     uchar               adapter_info[6];
1483     struct device       *dev;
1484 } ASC_DVC_CFG;
1485
1486 #define ASC_DEF_DVC_CNTL       0xFFFF
1487 #define ASC_DEF_CHIP_SCSI_ID   7
1488 #define ASC_DEF_ISA_DMA_SPEED  4
1489 #define ASC_INIT_STATE_NULL          0x0000
1490 #define ASC_INIT_STATE_BEG_GET_CFG   0x0001
1491 #define ASC_INIT_STATE_END_GET_CFG   0x0002
1492 #define ASC_INIT_STATE_BEG_SET_CFG   0x0004
1493 #define ASC_INIT_STATE_END_SET_CFG   0x0008
1494 #define ASC_INIT_STATE_BEG_LOAD_MC   0x0010
1495 #define ASC_INIT_STATE_END_LOAD_MC   0x0020
1496 #define ASC_INIT_STATE_BEG_INQUIRY   0x0040
1497 #define ASC_INIT_STATE_END_INQUIRY   0x0080
1498 #define ASC_INIT_RESET_SCSI_DONE     0x0100
1499 #define ASC_INIT_STATE_WITHOUT_EEP   0x8000
1500 #define ASC_BUG_FIX_IF_NOT_DWB       0x0001
1501 #define ASC_BUG_FIX_ASYN_USE_SYN     0x0002
1502 #define ASYN_SDTR_DATA_FIX_PCI_REV_AB 0x41
1503 #define ASC_MIN_TAGGED_CMD  7
1504 #define ASC_MAX_SCSI_RESET_WAIT      30
1505
1506 struct asc_dvc_var;     /* Forward Declaration. */
1507
1508 typedef void (* ASC_ISR_CALLBACK)(struct asc_dvc_var *, ASC_QDONE_INFO *);
1509 typedef int (* ASC_EXE_CALLBACK)(struct asc_dvc_var *, ASC_SCSI_Q *);
1510
1511 typedef struct asc_dvc_var {
1512     PortAddr            iop_base;
1513     ushort              err_code;
1514     ushort              dvc_cntl;
1515     ushort              bug_fix_cntl;
1516     ushort              bus_type;
1517     ASC_ISR_CALLBACK    isr_callback;
1518     ASC_EXE_CALLBACK    exe_callback;
1519     ASC_SCSI_BIT_ID_TYPE init_sdtr;
1520     ASC_SCSI_BIT_ID_TYPE sdtr_done;
1521     ASC_SCSI_BIT_ID_TYPE use_tagged_qng;
1522     ASC_SCSI_BIT_ID_TYPE unit_not_ready;
1523     ASC_SCSI_BIT_ID_TYPE queue_full_or_busy;
1524     ASC_SCSI_BIT_ID_TYPE start_motor;
1525     uchar               scsi_reset_wait;
1526     uchar               chip_no;
1527     char                is_in_int;
1528     uchar               max_total_qng;
1529     uchar               cur_total_qng;
1530     uchar               in_critical_cnt;
1531     uchar               irq_no;
1532     uchar               last_q_shortage;
1533     ushort              init_state;
1534     uchar               cur_dvc_qng[ASC_MAX_TID + 1];
1535     uchar               max_dvc_qng[ASC_MAX_TID + 1];
1536     ASC_SCSI_Q  *scsiq_busy_head[ASC_MAX_TID + 1];
1537     ASC_SCSI_Q  *scsiq_busy_tail[ASC_MAX_TID + 1];
1538     uchar               sdtr_period_tbl[ASC_MAX_SYN_XFER_NO];
1539     ASC_DVC_CFG *cfg;
1540     ASC_SCSI_BIT_ID_TYPE pci_fix_asyn_xfer_always;
1541     char                redo_scam;
1542     ushort              res2;
1543     uchar               dos_int13_table[ASC_MAX_TID + 1];
1544     ASC_DCNT            max_dma_count;
1545     ASC_SCSI_BIT_ID_TYPE no_scam;
1546     ASC_SCSI_BIT_ID_TYPE pci_fix_asyn_xfer;
1547     uchar               max_sdtr_index;
1548     uchar               host_init_sdtr_index;
1549     struct asc_board    *drv_ptr;
1550     ASC_DCNT            uc_break;
1551 } ASC_DVC_VAR;
1552
1553 typedef struct asc_dvc_inq_info {
1554     uchar               type[ASC_MAX_TID + 1][ASC_MAX_LUN + 1];
1555 } ASC_DVC_INQ_INFO;
1556
1557 typedef struct asc_cap_info {
1558     ASC_DCNT            lba;
1559     ASC_DCNT            blk_size;
1560 } ASC_CAP_INFO;
1561
1562 typedef struct asc_cap_info_array {
1563     ASC_CAP_INFO        cap_info[ASC_MAX_TID + 1][ASC_MAX_LUN + 1];
1564 } ASC_CAP_INFO_ARRAY;
1565
1566 #define ASC_MCNTL_NO_SEL_TIMEOUT  (ushort)0x0001
1567 #define ASC_MCNTL_NULL_TARGET     (ushort)0x0002
1568 #define ASC_CNTL_INITIATOR         (ushort)0x0001
1569 #define ASC_CNTL_BIOS_GT_1GB       (ushort)0x0002
1570 #define ASC_CNTL_BIOS_GT_2_DISK    (ushort)0x0004
1571 #define ASC_CNTL_BIOS_REMOVABLE    (ushort)0x0008
1572 #define ASC_CNTL_NO_SCAM           (ushort)0x0010
1573 #define ASC_CNTL_INT_MULTI_Q       (ushort)0x0080
1574 #define ASC_CNTL_NO_LUN_SUPPORT    (ushort)0x0040
1575 #define ASC_CNTL_NO_VERIFY_COPY    (ushort)0x0100
1576 #define ASC_CNTL_RESET_SCSI        (ushort)0x0200
1577 #define ASC_CNTL_INIT_INQUIRY      (ushort)0x0400
1578 #define ASC_CNTL_INIT_VERBOSE      (ushort)0x0800
1579 #define ASC_CNTL_SCSI_PARITY       (ushort)0x1000
1580 #define ASC_CNTL_BURST_MODE        (ushort)0x2000
1581 #define ASC_CNTL_SDTR_ENABLE_ULTRA (ushort)0x4000
1582 #define ASC_EEP_DVC_CFG_BEG_VL    2
1583 #define ASC_EEP_MAX_DVC_ADDR_VL   15
1584 #define ASC_EEP_DVC_CFG_BEG      32
1585 #define ASC_EEP_MAX_DVC_ADDR     45
1586 #define ASC_EEP_DEFINED_WORDS    10
1587 #define ASC_EEP_MAX_ADDR         63
1588 #define ASC_EEP_RES_WORDS         0
1589 #define ASC_EEP_MAX_RETRY        20
1590 #define ASC_MAX_INIT_BUSY_RETRY   8
1591 #define ASC_EEP_ISA_PNP_WSIZE    16
1592
1593 /*
1594  * These macros keep the chip SCSI id and ISA DMA speed
1595  * bitfields in board order. C bitfields aren't portable
1596  * between big and little-endian platforms so they are
1597  * not used.
1598  */
1599
1600 #define ASC_EEP_GET_CHIP_ID(cfg)    ((cfg)->id_speed & 0x0f)
1601 #define ASC_EEP_GET_DMA_SPD(cfg)    (((cfg)->id_speed & 0xf0) >> 4)
1602 #define ASC_EEP_SET_CHIP_ID(cfg, sid) \
1603    ((cfg)->id_speed = ((cfg)->id_speed & 0xf0) | ((sid) & ASC_MAX_TID))
1604 #define ASC_EEP_SET_DMA_SPD(cfg, spd) \
1605    ((cfg)->id_speed = ((cfg)->id_speed & 0x0f) | ((spd) & 0x0f) << 4)
1606
1607 typedef struct asceep_config {
1608     ushort              cfg_lsw;
1609     ushort              cfg_msw;
1610     uchar               init_sdtr;
1611     uchar               disc_enable;
1612     uchar               use_cmd_qng;
1613     uchar               start_motor;
1614     uchar               max_total_qng;
1615     uchar               max_tag_qng;
1616     uchar               bios_scan;
1617     uchar               power_up_wait;
1618     uchar               no_scam;
1619     uchar               id_speed; /* low order 4 bits is chip scsi id */
1620                                   /* high order 4 bits is isa dma speed */
1621     uchar               dos_int13_table[ASC_MAX_TID + 1];
1622     uchar               adapter_info[6];
1623     ushort              cntl;
1624     ushort              chksum;
1625 } ASCEEP_CONFIG;
1626
1627 #define ASC_PCI_CFG_LSW_SCSI_PARITY  0x0800
1628 #define ASC_PCI_CFG_LSW_BURST_MODE   0x0080
1629 #define ASC_PCI_CFG_LSW_INTR_ABLE    0x0020
1630
1631 #define ASC_EEP_CMD_READ          0x80
1632 #define ASC_EEP_CMD_WRITE         0x40
1633 #define ASC_EEP_CMD_WRITE_ABLE    0x30
1634 #define ASC_EEP_CMD_WRITE_DISABLE 0x00
1635 #define ASC_OVERRUN_BSIZE  0x00000048UL
1636 #define ASC_CTRL_BREAK_ONCE        0x0001
1637 #define ASC_CTRL_BREAK_STAY_IDLE   0x0002
1638 #define ASCV_MSGOUT_BEG         0x0000
1639 #define ASCV_MSGOUT_SDTR_PERIOD (ASCV_MSGOUT_BEG+3)
1640 #define ASCV_MSGOUT_SDTR_OFFSET (ASCV_MSGOUT_BEG+4)
1641 #define ASCV_BREAK_SAVED_CODE   (ushort)0x0006
1642 #define ASCV_MSGIN_BEG          (ASCV_MSGOUT_BEG+8)
1643 #define ASCV_MSGIN_SDTR_PERIOD  (ASCV_MSGIN_BEG+3)
1644 #define ASCV_MSGIN_SDTR_OFFSET  (ASCV_MSGIN_BEG+4)
1645 #define ASCV_SDTR_DATA_BEG      (ASCV_MSGIN_BEG+8)
1646 #define ASCV_SDTR_DONE_BEG      (ASCV_SDTR_DATA_BEG+8)
1647 #define ASCV_MAX_DVC_QNG_BEG    (ushort)0x0020
1648 #define ASCV_BREAK_ADDR           (ushort)0x0028
1649 #define ASCV_BREAK_NOTIFY_COUNT   (ushort)0x002A
1650 #define ASCV_BREAK_CONTROL        (ushort)0x002C
1651 #define ASCV_BREAK_HIT_COUNT      (ushort)0x002E
1652
1653 #define ASCV_ASCDVC_ERR_CODE_W  (ushort)0x0030
1654 #define ASCV_MCODE_CHKSUM_W   (ushort)0x0032
1655 #define ASCV_MCODE_SIZE_W     (ushort)0x0034
1656 #define ASCV_STOP_CODE_B      (ushort)0x0036
1657 #define ASCV_DVC_ERR_CODE_B   (ushort)0x0037
1658 #define ASCV_OVERRUN_PADDR_D  (ushort)0x0038
1659 #define ASCV_OVERRUN_BSIZE_D  (ushort)0x003C
1660 #define ASCV_HALTCODE_W       (ushort)0x0040
1661 #define ASCV_CHKSUM_W         (ushort)0x0042
1662 #define ASCV_MC_DATE_W        (ushort)0x0044
1663 #define ASCV_MC_VER_W         (ushort)0x0046
1664 #define ASCV_NEXTRDY_B        (ushort)0x0048
1665 #define ASCV_DONENEXT_B       (ushort)0x0049
1666 #define ASCV_USE_TAGGED_QNG_B (ushort)0x004A
1667 #define ASCV_SCSIBUSY_B       (ushort)0x004B
1668 #define ASCV_Q_DONE_IN_PROGRESS_B  (ushort)0x004C
1669 #define ASCV_CURCDB_B         (ushort)0x004D
1670 #define ASCV_RCLUN_B          (ushort)0x004E
1671 #define ASCV_BUSY_QHEAD_B     (ushort)0x004F
1672 #define ASCV_DISC1_QHEAD_B    (ushort)0x0050
1673 #define ASCV_DISC_ENABLE_B    (ushort)0x0052
1674 #define ASCV_CAN_TAGGED_QNG_B (ushort)0x0053
1675 #define ASCV_HOSTSCSI_ID_B    (ushort)0x0055
1676 #define ASCV_MCODE_CNTL_B     (ushort)0x0056
1677 #define ASCV_NULL_TARGET_B    (ushort)0x0057
1678 #define ASCV_FREE_Q_HEAD_W    (ushort)0x0058
1679 #define ASCV_DONE_Q_TAIL_W    (ushort)0x005A
1680 #define ASCV_FREE_Q_HEAD_B    (ushort)(ASCV_FREE_Q_HEAD_W+1)
1681 #define ASCV_DONE_Q_TAIL_B    (ushort)(ASCV_DONE_Q_TAIL_W+1)
1682 #define ASCV_HOST_FLAG_B      (ushort)0x005D
1683 #define ASCV_TOTAL_READY_Q_B  (ushort)0x0064
1684 #define ASCV_VER_SERIAL_B     (ushort)0x0065
1685 #define ASCV_HALTCODE_SAVED_W (ushort)0x0066
1686 #define ASCV_WTM_FLAG_B       (ushort)0x0068
1687 #define ASCV_RISC_FLAG_B      (ushort)0x006A
1688 #define ASCV_REQ_SG_LIST_QP   (ushort)0x006B
1689 #define ASC_HOST_FLAG_IN_ISR        0x01
1690 #define ASC_HOST_FLAG_ACK_INT       0x02
1691 #define ASC_RISC_FLAG_GEN_INT      0x01
1692 #define ASC_RISC_FLAG_REQ_SG_LIST  0x02
1693 #define IOP_CTRL         (0x0F)
1694 #define IOP_STATUS       (0x0E)
1695 #define IOP_INT_ACK      IOP_STATUS
1696 #define IOP_REG_IFC      (0x0D)
1697 #define IOP_SYN_OFFSET    (0x0B)
1698 #define IOP_EXTRA_CONTROL (0x0D)
1699 #define IOP_REG_PC        (0x0C)
1700 #define IOP_RAM_ADDR      (0x0A)
1701 #define IOP_RAM_DATA      (0x08)
1702 #define IOP_EEP_DATA      (0x06)
1703 #define IOP_EEP_CMD       (0x07)
1704 #define IOP_VERSION       (0x03)
1705 #define IOP_CONFIG_HIGH   (0x04)
1706 #define IOP_CONFIG_LOW    (0x02)
1707 #define IOP_SIG_BYTE      (0x01)
1708 #define IOP_SIG_WORD      (0x00)
1709 #define IOP_REG_DC1      (0x0E)
1710 #define IOP_REG_DC0      (0x0C)
1711 #define IOP_REG_SB       (0x0B)
1712 #define IOP_REG_DA1      (0x0A)
1713 #define IOP_REG_DA0      (0x08)
1714 #define IOP_REG_SC       (0x09)
1715 #define IOP_DMA_SPEED    (0x07)
1716 #define IOP_REG_FLAG     (0x07)
1717 #define IOP_FIFO_H       (0x06)
1718 #define IOP_FIFO_L       (0x04)
1719 #define IOP_REG_ID       (0x05)
1720 #define IOP_REG_QP       (0x03)
1721 #define IOP_REG_IH       (0x02)
1722 #define IOP_REG_IX       (0x01)
1723 #define IOP_REG_AX       (0x00)
1724 #define IFC_REG_LOCK      (0x00)
1725 #define IFC_REG_UNLOCK    (0x09)
1726 #define IFC_WR_EN_FILTER  (0x10)
1727 #define IFC_RD_NO_EEPROM  (0x10)
1728 #define IFC_SLEW_RATE     (0x20)
1729 #define IFC_ACT_NEG       (0x40)
1730 #define IFC_INP_FILTER    (0x80)
1731 #define IFC_INIT_DEFAULT  (IFC_ACT_NEG | IFC_REG_UNLOCK)
1732 #define SC_SEL   (uchar)(0x80)
1733 #define SC_BSY   (uchar)(0x40)
1734 #define SC_ACK   (uchar)(0x20)
1735 #define SC_REQ   (uchar)(0x10)
1736 #define SC_ATN   (uchar)(0x08)
1737 #define SC_IO    (uchar)(0x04)
1738 #define SC_CD    (uchar)(0x02)
1739 #define SC_MSG   (uchar)(0x01)
1740 #define SEC_SCSI_CTL         (uchar)(0x80)
1741 #define SEC_ACTIVE_NEGATE    (uchar)(0x40)
1742 #define SEC_SLEW_RATE        (uchar)(0x20)
1743 #define SEC_ENABLE_FILTER    (uchar)(0x10)
1744 #define ASC_HALT_EXTMSG_IN     (ushort)0x8000
1745 #define ASC_HALT_CHK_CONDITION (ushort)0x8100
1746 #define ASC_HALT_SS_QUEUE_FULL (ushort)0x8200
1747 #define ASC_HALT_DISABLE_ASYN_USE_SYN_FIX  (ushort)0x8300
1748 #define ASC_HALT_ENABLE_ASYN_USE_SYN_FIX   (ushort)0x8400
1749 #define ASC_HALT_SDTR_REJECTED (ushort)0x4000
1750 #define ASC_HALT_HOST_COPY_SG_LIST_TO_RISC ( ushort )0x2000
1751 #define ASC_MAX_QNO        0xF8
1752 #define ASC_DATA_SEC_BEG   (ushort)0x0080
1753 #define ASC_DATA_SEC_END   (ushort)0x0080
1754 #define ASC_CODE_SEC_BEG   (ushort)0x0080
1755 #define ASC_CODE_SEC_END   (ushort)0x0080
1756 #define ASC_QADR_BEG       (0x4000)
1757 #define ASC_QADR_USED      (ushort)(ASC_MAX_QNO * 64)
1758 #define ASC_QADR_END       (ushort)0x7FFF
1759 #define ASC_QLAST_ADR      (ushort)0x7FC0
1760 #define ASC_QBLK_SIZE      0x40
1761 #define ASC_BIOS_DATA_QBEG 0xF8
1762 #define ASC_MIN_ACTIVE_QNO 0x01
1763 #define ASC_QLINK_END      0xFF
1764 #define ASC_EEPROM_WORDS   0x10
1765 #define ASC_MAX_MGS_LEN    0x10
1766 #define ASC_BIOS_ADDR_DEF  0xDC00
1767 #define ASC_BIOS_SIZE      0x3800
1768 #define ASC_BIOS_RAM_OFF   0x3800
1769 #define ASC_BIOS_RAM_SIZE  0x800
1770 #define ASC_BIOS_MIN_ADDR  0xC000
1771 #define ASC_BIOS_MAX_ADDR  0xEC00
1772 #define ASC_BIOS_BANK_SIZE 0x0400
1773 #define ASC_MCODE_START_ADDR  0x0080
1774 #define ASC_CFG0_HOST_INT_ON    0x0020
1775 #define ASC_CFG0_BIOS_ON        0x0040
1776 #define ASC_CFG0_VERA_BURST_ON  0x0080
1777 #define ASC_CFG0_SCSI_PARITY_ON 0x0800
1778 #define ASC_CFG1_SCSI_TARGET_ON 0x0080
1779 #define ASC_CFG1_LRAM_8BITS_ON  0x0800
1780 #define ASC_CFG_MSW_CLR_MASK    0x3080
1781 #define CSW_TEST1             (ASC_CS_TYPE)0x8000
1782 #define CSW_AUTO_CONFIG       (ASC_CS_TYPE)0x4000
1783 #define CSW_RESERVED1         (ASC_CS_TYPE)0x2000
1784 #define CSW_IRQ_WRITTEN       (ASC_CS_TYPE)0x1000
1785 #define CSW_33MHZ_SELECTED    (ASC_CS_TYPE)0x0800
1786 #define CSW_TEST2             (ASC_CS_TYPE)0x0400
1787 #define CSW_TEST3             (ASC_CS_TYPE)0x0200
1788 #define CSW_RESERVED2         (ASC_CS_TYPE)0x0100
1789 #define CSW_DMA_DONE          (ASC_CS_TYPE)0x0080
1790 #define CSW_FIFO_RDY          (ASC_CS_TYPE)0x0040
1791 #define CSW_EEP_READ_DONE     (ASC_CS_TYPE)0x0020
1792 #define CSW_HALTED            (ASC_CS_TYPE)0x0010
1793 #define CSW_SCSI_RESET_ACTIVE (ASC_CS_TYPE)0x0008
1794 #define CSW_PARITY_ERR        (ASC_CS_TYPE)0x0004
1795 #define CSW_SCSI_RESET_LATCH  (ASC_CS_TYPE)0x0002
1796 #define CSW_INT_PENDING       (ASC_CS_TYPE)0x0001
1797 #define CIW_CLR_SCSI_RESET_INT (ASC_CS_TYPE)0x1000
1798 #define CIW_INT_ACK      (ASC_CS_TYPE)0x0100
1799 #define CIW_TEST1        (ASC_CS_TYPE)0x0200
1800 #define CIW_TEST2        (ASC_CS_TYPE)0x0400
1801 #define CIW_SEL_33MHZ    (ASC_CS_TYPE)0x0800
1802 #define CIW_IRQ_ACT      (ASC_CS_TYPE)0x1000
1803 #define CC_CHIP_RESET   (uchar)0x80
1804 #define CC_SCSI_RESET   (uchar)0x40
1805 #define CC_HALT         (uchar)0x20
1806 #define CC_SINGLE_STEP  (uchar)0x10
1807 #define CC_DMA_ABLE     (uchar)0x08
1808 #define CC_TEST         (uchar)0x04
1809 #define CC_BANK_ONE     (uchar)0x02
1810 #define CC_DIAG         (uchar)0x01
1811 #define ASC_1000_ID0W      0x04C1
1812 #define ASC_1000_ID0W_FIX  0x00C1
1813 #define ASC_1000_ID1B      0x25
1814 #define ASC_EISA_BIG_IOP_GAP   (0x1C30-0x0C50)
1815 #define ASC_EISA_SMALL_IOP_GAP (0x0020)
1816 #define ASC_EISA_MIN_IOP_ADDR  (0x0C30)
1817 #define ASC_EISA_MAX_IOP_ADDR  (0xFC50)
1818 #define ASC_EISA_REV_IOP_MASK  (0x0C83)
1819 #define ASC_EISA_PID_IOP_MASK  (0x0C80)
1820 #define ASC_EISA_CFG_IOP_MASK  (0x0C86)
1821 #define ASC_GET_EISA_SLOT(iop)  (PortAddr)((iop) & 0xF000)
1822 #define ASC_EISA_ID_740    0x01745004UL
1823 #define ASC_EISA_ID_750    0x01755004UL
1824 #define INS_HALTINT        (ushort)0x6281
1825 #define INS_HALT           (ushort)0x6280
1826 #define INS_SINT           (ushort)0x6200
1827 #define INS_RFLAG_WTM      (ushort)0x7380
1828 #define ASC_MC_SAVE_CODE_WSIZE  0x500
1829 #define ASC_MC_SAVE_DATA_WSIZE  0x40
1830
1831 typedef struct asc_mc_saved {
1832     ushort              data[ASC_MC_SAVE_DATA_WSIZE];
1833     ushort              code[ASC_MC_SAVE_CODE_WSIZE];
1834 } ASC_MC_SAVED;
1835
1836 #define AscGetQDoneInProgress(port)         AscReadLramByte((port), ASCV_Q_DONE_IN_PROGRESS_B)
1837 #define AscPutQDoneInProgress(port, val)    AscWriteLramByte((port), ASCV_Q_DONE_IN_PROGRESS_B, val)
1838 #define AscGetVarFreeQHead(port)            AscReadLramWord((port), ASCV_FREE_Q_HEAD_W)
1839 #define AscGetVarDoneQTail(port)            AscReadLramWord((port), ASCV_DONE_Q_TAIL_W)
1840 #define AscPutVarFreeQHead(port, val)       AscWriteLramWord((port), ASCV_FREE_Q_HEAD_W, val)
1841 #define AscPutVarDoneQTail(port, val)       AscWriteLramWord((port), ASCV_DONE_Q_TAIL_W, val)
1842 #define AscGetRiscVarFreeQHead(port)        AscReadLramByte((port), ASCV_NEXTRDY_B)
1843 #define AscGetRiscVarDoneQTail(port)        AscReadLramByte((port), ASCV_DONENEXT_B)
1844 #define AscPutRiscVarFreeQHead(port, val)   AscWriteLramByte((port), ASCV_NEXTRDY_B, val)
1845 #define AscPutRiscVarDoneQTail(port, val)   AscWriteLramByte((port), ASCV_DONENEXT_B, val)
1846 #define AscPutMCodeSDTRDoneAtID(port, id, data)  AscWriteLramByte((port), (ushort)((ushort)ASCV_SDTR_DONE_BEG+(ushort)id), (data));
1847 #define AscGetMCodeSDTRDoneAtID(port, id)        AscReadLramByte((port), (ushort)((ushort)ASCV_SDTR_DONE_BEG+(ushort)id));
1848 #define AscPutMCodeInitSDTRAtID(port, id, data)  AscWriteLramByte((port), (ushort)((ushort)ASCV_SDTR_DATA_BEG+(ushort)id), data);
1849 #define AscGetMCodeInitSDTRAtID(port, id)        AscReadLramByte((port), (ushort)((ushort)ASCV_SDTR_DATA_BEG+(ushort)id));
1850 #define AscSynIndexToPeriod(index)        (uchar)(asc_dvc->sdtr_period_tbl[ (index) ])
1851 #define AscGetChipSignatureByte(port)     (uchar)inp((port)+IOP_SIG_BYTE)
1852 #define AscGetChipSignatureWord(port)     (ushort)inpw((port)+IOP_SIG_WORD)
1853 #define AscGetChipVerNo(port)             (uchar)inp((port)+IOP_VERSION)
1854 #define AscGetChipCfgLsw(port)            (ushort)inpw((port)+IOP_CONFIG_LOW)
1855 #define AscGetChipCfgMsw(port)            (ushort)inpw((port)+IOP_CONFIG_HIGH)
1856 #define AscSetChipCfgLsw(port, data)      outpw((port)+IOP_CONFIG_LOW, data)
1857 #define AscSetChipCfgMsw(port, data)      outpw((port)+IOP_CONFIG_HIGH, data)
1858 #define AscGetChipEEPCmd(port)            (uchar)inp((port)+IOP_EEP_CMD)
1859 #define AscSetChipEEPCmd(port, data)      outp((port)+IOP_EEP_CMD, data)
1860 #define AscGetChipEEPData(port)           (ushort)inpw((port)+IOP_EEP_DATA)
1861 #define AscSetChipEEPData(port, data)     outpw((port)+IOP_EEP_DATA, data)
1862 #define AscGetChipLramAddr(port)          (ushort)inpw((PortAddr)((port)+IOP_RAM_ADDR))
1863 #define AscSetChipLramAddr(port, addr)    outpw((PortAddr)((port)+IOP_RAM_ADDR), addr)
1864 #define AscGetChipLramData(port)          (ushort)inpw((port)+IOP_RAM_DATA)
1865 #define AscSetChipLramData(port, data)    outpw((port)+IOP_RAM_DATA, data)
1866 #define AscGetChipIFC(port)               (uchar)inp((port)+IOP_REG_IFC)
1867 #define AscSetChipIFC(port, data)          outp((port)+IOP_REG_IFC, data)
1868 #define AscGetChipStatus(port)            (ASC_CS_TYPE)inpw((port)+IOP_STATUS)
1869 #define AscSetChipStatus(port, cs_val)    outpw((port)+IOP_STATUS, cs_val)
1870 #define AscGetChipControl(port)           (uchar)inp((port)+IOP_CTRL)
1871 #define AscSetChipControl(port, cc_val)   outp((port)+IOP_CTRL, cc_val)
1872 #define AscGetChipSyn(port)               (uchar)inp((port)+IOP_SYN_OFFSET)
1873 #define AscSetChipSyn(port, data)         outp((port)+IOP_SYN_OFFSET, data)
1874 #define AscSetPCAddr(port, data)          outpw((port)+IOP_REG_PC, data)
1875 #define AscGetPCAddr(port)                (ushort)inpw((port)+IOP_REG_PC)
1876 #define AscIsIntPending(port)             (AscGetChipStatus(port) & (CSW_INT_PENDING | CSW_SCSI_RESET_LATCH))
1877 #define AscGetChipScsiID(port)            ((AscGetChipCfgLsw(port) >> 8) & ASC_MAX_TID)
1878 #define AscGetExtraControl(port)          (uchar)inp((port)+IOP_EXTRA_CONTROL)
1879 #define AscSetExtraControl(port, data)    outp((port)+IOP_EXTRA_CONTROL, data)
1880 #define AscReadChipAX(port)               (ushort)inpw((port)+IOP_REG_AX)
1881 #define AscWriteChipAX(port, data)        outpw((port)+IOP_REG_AX, data)
1882 #define AscReadChipIX(port)               (uchar)inp((port)+IOP_REG_IX)
1883 #define AscWriteChipIX(port, data)        outp((port)+IOP_REG_IX, data)
1884 #define AscReadChipIH(port)               (ushort)inpw((port)+IOP_REG_IH)
1885 #define AscWriteChipIH(port, data)        outpw((port)+IOP_REG_IH, data)
1886 #define AscReadChipQP(port)               (uchar)inp((port)+IOP_REG_QP)
1887 #define AscWriteChipQP(port, data)        outp((port)+IOP_REG_QP, data)
1888 #define AscReadChipFIFO_L(port)           (ushort)inpw((port)+IOP_REG_FIFO_L)
1889 #define AscWriteChipFIFO_L(port, data)    outpw((port)+IOP_REG_FIFO_L, data)
1890 #define AscReadChipFIFO_H(port)           (ushort)inpw((port)+IOP_REG_FIFO_H)
1891 #define AscWriteChipFIFO_H(port, data)    outpw((port)+IOP_REG_FIFO_H, data)
1892 #define AscReadChipDmaSpeed(port)         (uchar)inp((port)+IOP_DMA_SPEED)
1893 #define AscWriteChipDmaSpeed(port, data)  outp((port)+IOP_DMA_SPEED, data)
1894 #define AscReadChipDA0(port)              (ushort)inpw((port)+IOP_REG_DA0)
1895 #define AscWriteChipDA0(port)             outpw((port)+IOP_REG_DA0, data)
1896 #define AscReadChipDA1(port)              (ushort)inpw((port)+IOP_REG_DA1)
1897 #define AscWriteChipDA1(port)             outpw((port)+IOP_REG_DA1, data)
1898 #define AscReadChipDC0(port)              (ushort)inpw((port)+IOP_REG_DC0)
1899 #define AscWriteChipDC0(port)             outpw((port)+IOP_REG_DC0, data)
1900 #define AscReadChipDC1(port)              (ushort)inpw((port)+IOP_REG_DC1)
1901 #define AscWriteChipDC1(port)             outpw((port)+IOP_REG_DC1, data)
1902 #define AscReadChipDvcID(port)            (uchar)inp((port)+IOP_REG_ID)
1903 #define AscWriteChipDvcID(port, data)     outp((port)+IOP_REG_ID, data)
1904
1905 STATIC int       AscWriteEEPCmdReg(PortAddr iop_base, uchar cmd_reg);
1906 STATIC int       AscWriteEEPDataReg(PortAddr iop_base, ushort data_reg);
1907 STATIC void      AscWaitEEPRead(void);
1908 STATIC void      AscWaitEEPWrite(void);
1909 STATIC ushort    AscReadEEPWord(PortAddr, uchar);
1910 STATIC ushort    AscWriteEEPWord(PortAddr, uchar, ushort);
1911 STATIC ushort    AscGetEEPConfig(PortAddr, ASCEEP_CONFIG *, ushort);
1912 STATIC int       AscSetEEPConfigOnce(PortAddr, ASCEEP_CONFIG *, ushort);
1913 STATIC int       AscSetEEPConfig(PortAddr, ASCEEP_CONFIG *, ushort);
1914 STATIC int       AscStartChip(PortAddr);
1915 STATIC int       AscStopChip(PortAddr);
1916 STATIC void      AscSetChipIH(PortAddr, ushort);
1917 STATIC int       AscIsChipHalted(PortAddr);
1918 STATIC void      AscAckInterrupt(PortAddr);
1919 STATIC void      AscDisableInterrupt(PortAddr);
1920 STATIC void      AscEnableInterrupt(PortAddr);
1921 STATIC void      AscSetBank(PortAddr, uchar);
1922 STATIC int       AscResetChipAndScsiBus(ASC_DVC_VAR *);
1923 #ifdef CONFIG_ISA
1924 STATIC ushort    AscGetIsaDmaChannel(PortAddr);
1925 STATIC ushort    AscSetIsaDmaChannel(PortAddr, ushort);
1926 STATIC uchar     AscSetIsaDmaSpeed(PortAddr, uchar);
1927 STATIC uchar     AscGetIsaDmaSpeed(PortAddr);
1928 #endif /* CONFIG_ISA */
1929 STATIC uchar     AscReadLramByte(PortAddr, ushort);
1930 STATIC ushort    AscReadLramWord(PortAddr, ushort);
1931 #if CC_VERY_LONG_SG_LIST
1932 STATIC ASC_DCNT  AscReadLramDWord(PortAddr, ushort);
1933 #endif /* CC_VERY_LONG_SG_LIST */
1934 STATIC void      AscWriteLramWord(PortAddr, ushort, ushort);
1935 STATIC void      AscWriteLramByte(PortAddr, ushort, uchar);
1936 STATIC ASC_DCNT  AscMemSumLramWord(PortAddr, ushort, int);
1937 STATIC void      AscMemWordSetLram(PortAddr, ushort, ushort, int);
1938 STATIC void      AscMemWordCopyPtrToLram(PortAddr, ushort, uchar *, int);
1939 STATIC void      AscMemDWordCopyPtrToLram(PortAddr, ushort, uchar *, int);
1940 STATIC void      AscMemWordCopyPtrFromLram(PortAddr, ushort, uchar *, int);
1941 STATIC ushort    AscInitAscDvcVar(ASC_DVC_VAR *);
1942 STATIC ushort    AscInitFromEEP(ASC_DVC_VAR *);
1943 STATIC ushort    AscInitFromAscDvcVar(ASC_DVC_VAR *);
1944 STATIC ushort    AscInitMicroCodeVar(ASC_DVC_VAR *);
1945 STATIC int       AscTestExternalLram(ASC_DVC_VAR *);
1946 STATIC uchar     AscMsgOutSDTR(ASC_DVC_VAR *, uchar, uchar);
1947 STATIC uchar     AscCalSDTRData(ASC_DVC_VAR *, uchar, uchar);
1948 STATIC void      AscSetChipSDTR(PortAddr, uchar, uchar);
1949 STATIC uchar     AscGetSynPeriodIndex(ASC_DVC_VAR *, uchar);
1950 STATIC uchar     AscAllocFreeQueue(PortAddr, uchar);
1951 STATIC uchar     AscAllocMultipleFreeQueue(PortAddr, uchar, uchar);
1952 STATIC int       AscHostReqRiscHalt(PortAddr);
1953 STATIC int       AscStopQueueExe(PortAddr);
1954 STATIC int       AscSendScsiQueue(ASC_DVC_VAR *,
1955                     ASC_SCSI_Q * scsiq,
1956                     uchar n_q_required);
1957 STATIC int       AscPutReadyQueue(ASC_DVC_VAR *,
1958                     ASC_SCSI_Q *, uchar);
1959 STATIC int       AscPutReadySgListQueue(ASC_DVC_VAR *,
1960                     ASC_SCSI_Q *, uchar);
1961 STATIC int       AscSetChipSynRegAtID(PortAddr, uchar, uchar);
1962 STATIC int       AscSetRunChipSynRegAtID(PortAddr, uchar, uchar);
1963 STATIC ushort    AscInitLram(ASC_DVC_VAR *);
1964 STATIC ushort    AscInitQLinkVar(ASC_DVC_VAR *);
1965 STATIC int       AscSetLibErrorCode(ASC_DVC_VAR *, ushort);
1966 STATIC int       AscIsrChipHalted(ASC_DVC_VAR *);
1967 STATIC uchar     _AscCopyLramScsiDoneQ(PortAddr, ushort,
1968                     ASC_QDONE_INFO *, ASC_DCNT);
1969 STATIC int       AscIsrQDone(ASC_DVC_VAR *);
1970 STATIC int       AscCompareString(uchar *, uchar *, int);
1971 #ifdef CONFIG_ISA
1972 STATIC ushort    AscGetEisaChipCfg(PortAddr);
1973 STATIC ASC_DCNT  AscGetEisaProductID(PortAddr);
1974 STATIC PortAddr  AscSearchIOPortAddrEISA(PortAddr);
1975 STATIC PortAddr  AscSearchIOPortAddr11(PortAddr);
1976 STATIC PortAddr  AscSearchIOPortAddr(PortAddr, ushort);
1977 STATIC void      AscSetISAPNPWaitForKey(void);
1978 #endif /* CONFIG_ISA */
1979 STATIC uchar     AscGetChipScsiCtrl(PortAddr);
1980 STATIC uchar     AscSetChipScsiID(PortAddr, uchar);
1981 STATIC uchar     AscGetChipVersion(PortAddr, ushort);
1982 STATIC ushort    AscGetChipBusType(PortAddr);
1983 STATIC ASC_DCNT  AscLoadMicroCode(PortAddr, ushort, uchar *, ushort);
1984 STATIC int       AscFindSignature(PortAddr);
1985 STATIC void      AscToggleIRQAct(PortAddr);
1986 STATIC uchar     AscGetChipIRQ(PortAddr, ushort);
1987 STATIC uchar     AscSetChipIRQ(PortAddr, uchar, ushort);
1988 STATIC ushort    AscGetChipBiosAddress(PortAddr, ushort);
1989 STATIC inline ulong DvcEnterCritical(void);
1990 STATIC inline void DvcLeaveCritical(ulong);
1991 #ifdef CONFIG_PCI
1992 STATIC uchar     DvcReadPCIConfigByte(ASC_DVC_VAR *, ushort);
1993 STATIC void      DvcWritePCIConfigByte(ASC_DVC_VAR *,
1994                     ushort, uchar);
1995 #endif /* CONFIG_PCI */
1996 STATIC ushort      AscGetChipBiosAddress(PortAddr, ushort);
1997 STATIC void      DvcSleepMilliSecond(ASC_DCNT);
1998 STATIC void      DvcDelayNanoSecond(ASC_DVC_VAR *, ASC_DCNT);
1999 STATIC void      DvcPutScsiQ(PortAddr, ushort, uchar *, int);
2000 STATIC void      DvcGetQinfo(PortAddr, ushort, uchar *, int);
2001 STATIC ushort    AscInitGetConfig(ASC_DVC_VAR *);
2002 STATIC ushort    AscInitSetConfig(ASC_DVC_VAR *);
2003 STATIC ushort    AscInitAsc1000Driver(ASC_DVC_VAR *);
2004 STATIC void      AscAsyncFix(ASC_DVC_VAR *, uchar,
2005                     ASC_SCSI_INQUIRY *);
2006 STATIC int       AscTagQueuingSafe(ASC_SCSI_INQUIRY *);
2007 STATIC void      AscInquiryHandling(ASC_DVC_VAR *,
2008                     uchar, ASC_SCSI_INQUIRY *);
2009 STATIC int       AscExeScsiQueue(ASC_DVC_VAR *, ASC_SCSI_Q *);
2010 STATIC int       AscISR(ASC_DVC_VAR *);
2011 STATIC uint      AscGetNumOfFreeQueue(ASC_DVC_VAR *, uchar,
2012                     uchar);
2013 STATIC int       AscSgListToQueue(int);
2014 #ifdef CONFIG_ISA
2015 STATIC void      AscEnableIsaDma(uchar);
2016 #endif /* CONFIG_ISA */
2017 STATIC ASC_DCNT  AscGetMaxDmaCount(ushort);
2018
2019
2020 /*
2021  * --- Adv Library Constants and Macros
2022  */
2023
2024 #define ADV_LIB_VERSION_MAJOR  5
2025 #define ADV_LIB_VERSION_MINOR  14
2026
2027 /*
2028  * Define Adv Library required special types.
2029  */
2030
2031 /*
2032  * Portable Data Types
2033  *
2034  * Any instance where a 32-bit long or pointer type is assumed
2035  * for precision or HW defined structures, the following define
2036  * types must be used. In Linux the char, short, and int types
2037  * are all consistent at 8, 16, and 32 bits respectively. Pointers
2038  * and long types are 64 bits on Alpha and UltraSPARC.
2039  */
2040 #define ADV_PADDR __u32         /* Physical address data type. */
2041 #define ADV_VADDR __u32         /* Virtual address data type. */
2042 #define ADV_DCNT  __u32         /* Unsigned Data count type. */
2043 #define ADV_SDCNT __s32         /* Signed Data count type. */
2044
2045 /*
2046  * These macros are used to convert a virtual address to a
2047  * 32-bit value. This currently can be used on Linux Alpha
2048  * which uses 64-bit virtual address but a 32-bit bus address.
2049  * This is likely to break in the future, but doing this now
2050  * will give us time to change the HW and FW to handle 64-bit
2051  * addresses.
2052  */
2053 #define ADV_VADDR_TO_U32   virt_to_bus
2054 #define ADV_U32_TO_VADDR   bus_to_virt
2055
2056 #define AdvPortAddr  void __iomem *     /* Virtual memory address size */
2057
2058 /*
2059  * Define Adv Library required memory access macros.
2060  */
2061 #define ADV_MEM_READB(addr) readb(addr)
2062 #define ADV_MEM_READW(addr) readw(addr)
2063 #define ADV_MEM_WRITEB(addr, byte) writeb(byte, addr)
2064 #define ADV_MEM_WRITEW(addr, word) writew(word, addr)
2065 #define ADV_MEM_WRITEDW(addr, dword) writel(dword, addr)
2066
2067 #define ADV_CARRIER_COUNT (ASC_DEF_MAX_HOST_QNG + 15)
2068
2069 /*
2070  * For wide  boards a CDB length maximum of 16 bytes
2071  * is supported.
2072  */
2073 #define ADV_MAX_CDB_LEN     16
2074
2075 /*
2076  * Define total number of simultaneous maximum element scatter-gather
2077  * request blocks per wide adapter. ASC_DEF_MAX_HOST_QNG (253) is the
2078  * maximum number of outstanding commands per wide host adapter. Each
2079  * command uses one or more ADV_SG_BLOCK each with 15 scatter-gather
2080  * elements. Allow each command to have at least one ADV_SG_BLOCK structure.
2081  * This allows about 15 commands to have the maximum 17 ADV_SG_BLOCK
2082  * structures or 255 scatter-gather elements.
2083  *
2084  */
2085 #define ADV_TOT_SG_BLOCK        ASC_DEF_MAX_HOST_QNG
2086
2087 /*
2088  * Define Adv Library required maximum number of scatter-gather
2089  * elements per request.
2090  */
2091 #define ADV_MAX_SG_LIST         255
2092
2093 /* Number of SG blocks needed. */
2094 #define ADV_NUM_SG_BLOCK \
2095     ((ADV_MAX_SG_LIST + (NO_OF_SG_PER_BLOCK - 1))/NO_OF_SG_PER_BLOCK)
2096
2097 /* Total contiguous memory needed for SG blocks. */
2098 #define ADV_SG_TOTAL_MEM_SIZE \
2099     (sizeof(ADV_SG_BLOCK) *  ADV_NUM_SG_BLOCK)
2100
2101 #define ADV_PAGE_SIZE PAGE_SIZE
2102
2103 #define ADV_NUM_PAGE_CROSSING \
2104     ((ADV_SG_TOTAL_MEM_SIZE + (ADV_PAGE_SIZE - 1))/ADV_PAGE_SIZE)
2105
2106 #define ADV_EEP_DVC_CFG_BEGIN           (0x00)
2107 #define ADV_EEP_DVC_CFG_END             (0x15)
2108 #define ADV_EEP_DVC_CTL_BEGIN           (0x16)  /* location of OEM name */
2109 #define ADV_EEP_MAX_WORD_ADDR           (0x1E)
2110
2111 #define ADV_EEP_DELAY_MS                100
2112
2113 #define ADV_EEPROM_BIG_ENDIAN          0x8000   /* EEPROM Bit 15 */
2114 #define ADV_EEPROM_BIOS_ENABLE         0x4000   /* EEPROM Bit 14 */
2115 /*
2116  * For the ASC3550 Bit 13 is Termination Polarity control bit.
2117  * For later ICs Bit 13 controls whether the CIS (Card Information
2118  * Service Section) is loaded from EEPROM.
2119  */
2120 #define ADV_EEPROM_TERM_POL            0x2000   /* EEPROM Bit 13 */
2121 #define ADV_EEPROM_CIS_LD              0x2000   /* EEPROM Bit 13 */
2122 /*
2123  * ASC38C1600 Bit 11
2124  *
2125  * If EEPROM Bit 11 is 0 for Function 0, then Function 0 will specify
2126  * INT A in the PCI Configuration Space Int Pin field. If it is 1, then
2127  * Function 0 will specify INT B.
2128  *
2129  * If EEPROM Bit 11 is 0 for Function 1, then Function 1 will specify
2130  * INT B in the PCI Configuration Space Int Pin field. If it is 1, then
2131  * Function 1 will specify INT A.
2132  */
2133 #define ADV_EEPROM_INTAB               0x0800   /* EEPROM Bit 11 */
2134
2135 typedef struct adveep_3550_config
2136 {
2137                                 /* Word Offset, Description */
2138
2139   ushort cfg_lsw;               /* 00 power up initialization */
2140                                 /*  bit 13 set - Term Polarity Control */
2141                                 /*  bit 14 set - BIOS Enable */
2142                                 /*  bit 15 set - Big Endian Mode */
2143   ushort cfg_msw;               /* 01 unused      */
2144   ushort disc_enable;           /* 02 disconnect enable */
2145   ushort wdtr_able;             /* 03 Wide DTR able */
2146   ushort sdtr_able;             /* 04 Synchronous DTR able */
2147   ushort start_motor;           /* 05 send start up motor */
2148   ushort tagqng_able;           /* 06 tag queuing able */
2149   ushort bios_scan;             /* 07 BIOS device control */
2150   ushort scam_tolerant;         /* 08 no scam */
2151
2152   uchar  adapter_scsi_id;       /* 09 Host Adapter ID */
2153   uchar  bios_boot_delay;       /*    power up wait */
2154
2155   uchar  scsi_reset_delay;      /* 10 reset delay */
2156   uchar  bios_id_lun;           /*    first boot device scsi id & lun */
2157                                 /*    high nibble is lun */
2158                                 /*    low nibble is scsi id */
2159
2160   uchar  termination;           /* 11 0 - automatic */
2161                                 /*    1 - low off / high off */
2162                                 /*    2 - low off / high on */
2163                                 /*    3 - low on  / high on */
2164                                 /*    There is no low on  / high off */
2165
2166   uchar  reserved1;             /*    reserved byte (not used) */
2167
2168   ushort bios_ctrl;             /* 12 BIOS control bits */
2169                                 /*  bit 0  BIOS don't act as initiator. */
2170                                 /*  bit 1  BIOS > 1 GB support */
2171                                 /*  bit 2  BIOS > 2 Disk Support */
2172                                 /*  bit 3  BIOS don't support removables */
2173                                 /*  bit 4  BIOS support bootable CD */
2174                                 /*  bit 5  BIOS scan enabled */
2175                                 /*  bit 6  BIOS support multiple LUNs */
2176                                 /*  bit 7  BIOS display of message */
2177                                 /*  bit 8  SCAM disabled */
2178                                 /*  bit 9  Reset SCSI bus during init. */
2179                                 /*  bit 10 */
2180                                 /*  bit 11 No verbose initialization. */
2181                                 /*  bit 12 SCSI parity enabled */
2182                                 /*  bit 13 */
2183                                 /*  bit 14 */
2184                                 /*  bit 15 */
2185   ushort  ultra_able;           /* 13 ULTRA speed able */
2186   ushort  reserved2;            /* 14 reserved */
2187   uchar   max_host_qng;         /* 15 maximum host queuing */
2188   uchar   max_dvc_qng;          /*    maximum per device queuing */
2189   ushort  dvc_cntl;             /* 16 control bit for driver */
2190   ushort  bug_fix;              /* 17 control bit for bug fix */
2191   ushort  serial_number_word1;  /* 18 Board serial number word 1 */
2192   ushort  serial_number_word2;  /* 19 Board serial number word 2 */
2193   ushort  serial_number_word3;  /* 20 Board serial number word 3 */
2194   ushort  check_sum;            /* 21 EEP check sum */
2195   uchar   oem_name[16];         /* 22 OEM name */
2196   ushort  dvc_err_code;         /* 30 last device driver error code */
2197   ushort  adv_err_code;         /* 31 last uc and Adv Lib error code */
2198   ushort  adv_err_addr;         /* 32 last uc error address */
2199   ushort  saved_dvc_err_code;   /* 33 saved last dev. driver error code   */
2200   ushort  saved_adv_err_code;   /* 34 saved last uc and Adv Lib error code */
2201   ushort  saved_adv_err_addr;   /* 35 saved last uc error address         */
2202   ushort  num_of_err;           /* 36 number of error */
2203 } ADVEEP_3550_CONFIG;
2204
2205 typedef struct adveep_38C0800_config
2206 {
2207                                 /* Word Offset, Description */
2208
2209   ushort cfg_lsw;               /* 00 power up initialization */
2210                                 /*  bit 13 set - Load CIS */
2211                                 /*  bit 14 set - BIOS Enable */
2212                                 /*  bit 15 set - Big Endian Mode */
2213   ushort cfg_msw;               /* 01 unused      */
2214   ushort disc_enable;           /* 02 disconnect enable */
2215   ushort wdtr_able;             /* 03 Wide DTR able */
2216   ushort sdtr_speed1;           /* 04 SDTR Speed TID 0-3 */
2217   ushort start_motor;           /* 05 send start up motor */
2218   ushort tagqng_able;           /* 06 tag queuing able */
2219   ushort bios_scan;             /* 07 BIOS device control */
2220   ushort scam_tolerant;         /* 08 no scam */
2221
2222   uchar  adapter_scsi_id;       /* 09 Host Adapter ID */
2223   uchar  bios_boot_delay;       /*    power up wait */
2224
2225   uchar  scsi_reset_delay;      /* 10 reset delay */
2226   uchar  bios_id_lun;           /*    first boot device scsi id & lun */
2227                                 /*    high nibble is lun */
2228                                 /*    low nibble is scsi id */
2229
2230   uchar  termination_se;        /* 11 0 - automatic */
2231                                 /*    1 - low off / high off */
2232                                 /*    2 - low off / high on */
2233                                 /*    3 - low on  / high on */
2234                                 /*    There is no low on  / high off */
2235
2236   uchar  termination_lvd;       /* 11 0 - automatic */
2237                                 /*    1 - low off / high off */
2238                                 /*    2 - low off / high on */
2239                                 /*    3 - low on  / high on */
2240                                 /*    There is no low on  / high off */
2241
2242   ushort bios_ctrl;             /* 12 BIOS control bits */
2243                                 /*  bit 0  BIOS don't act as initiator. */
2244                                 /*  bit 1  BIOS > 1 GB support */
2245                                 /*  bit 2  BIOS > 2 Disk Support */
2246                                 /*  bit 3  BIOS don't support removables */
2247                                 /*  bit 4  BIOS support bootable CD */
2248                                 /*  bit 5  BIOS scan enabled */
2249                                 /*  bit 6  BIOS support multiple LUNs */
2250                                 /*  bit 7  BIOS display of message */
2251                                 /*  bit 8  SCAM disabled */
2252                                 /*  bit 9  Reset SCSI bus during init. */
2253                                 /*  bit 10 */
2254                                 /*  bit 11 No verbose initialization. */
2255                                 /*  bit 12 SCSI parity enabled */
2256                                 /*  bit 13 */
2257                                 /*  bit 14 */
2258                                 /*  bit 15 */
2259   ushort  sdtr_speed2;          /* 13 SDTR speed TID 4-7 */
2260   ushort  sdtr_speed3;          /* 14 SDTR speed TID 8-11 */
2261   uchar   max_host_qng;         /* 15 maximum host queueing */
2262   uchar   max_dvc_qng;          /*    maximum per device queuing */
2263   ushort  dvc_cntl;             /* 16 control bit for driver */
2264   ushort  sdtr_speed4;          /* 17 SDTR speed 4 TID 12-15 */
2265   ushort  serial_number_word1;  /* 18 Board serial number word 1 */
2266   ushort  serial_number_word2;  /* 19 Board serial number word 2 */
2267   ushort  serial_number_word3;  /* 20 Board serial number word 3 */
2268   ushort  check_sum;            /* 21 EEP check sum */
2269   uchar   oem_name[16];         /* 22 OEM name */
2270   ushort  dvc_err_code;         /* 30 last device driver error code */
2271   ushort  adv_err_code;         /* 31 last uc and Adv Lib error code */
2272   ushort  adv_err_addr;         /* 32 last uc error address */
2273   ushort  saved_dvc_err_code;   /* 33 saved last dev. driver error code   */
2274   ushort  saved_adv_err_code;   /* 34 saved last uc and Adv Lib error code */
2275   ushort  saved_adv_err_addr;   /* 35 saved last uc error address         */
2276   ushort  reserved36;           /* 36 reserved */
2277   ushort  reserved37;           /* 37 reserved */
2278   ushort  reserved38;           /* 38 reserved */
2279   ushort  reserved39;           /* 39 reserved */
2280   ushort  reserved40;           /* 40 reserved */
2281   ushort  reserved41;           /* 41 reserved */
2282   ushort  reserved42;           /* 42 reserved */
2283   ushort  reserved43;           /* 43 reserved */
2284   ushort  reserved44;           /* 44 reserved */
2285   ushort  reserved45;           /* 45 reserved */
2286   ushort  reserved46;           /* 46 reserved */
2287   ushort  reserved47;           /* 47 reserved */
2288   ushort  reserved48;           /* 48 reserved */
2289   ushort  reserved49;           /* 49 reserved */
2290   ushort  reserved50;           /* 50 reserved */
2291   ushort  reserved51;           /* 51 reserved */
2292   ushort  reserved52;           /* 52 reserved */
2293   ushort  reserved53;           /* 53 reserved */
2294   ushort  reserved54;           /* 54 reserved */
2295   ushort  reserved55;           /* 55 reserved */
2296   ushort  cisptr_lsw;           /* 56 CIS PTR LSW */
2297   ushort  cisprt_msw;           /* 57 CIS PTR MSW */
2298   ushort  subsysvid;            /* 58 SubSystem Vendor ID */
2299   ushort  subsysid;             /* 59 SubSystem ID */
2300   ushort  reserved60;           /* 60 reserved */
2301   ushort  reserved61;           /* 61 reserved */
2302   ushort  reserved62;           /* 62 reserved */
2303   ushort  reserved63;           /* 63 reserved */
2304 } ADVEEP_38C0800_CONFIG;
2305
2306 typedef struct adveep_38C1600_config
2307 {
2308                                 /* Word Offset, Description */
2309
2310   ushort cfg_lsw;               /* 00 power up initialization */
2311                                 /*  bit 11 set - Func. 0 INTB, Func. 1 INTA */
2312                                 /*       clear - Func. 0 INTA, Func. 1 INTB */
2313                                 /*  bit 13 set - Load CIS */
2314                                 /*  bit 14 set - BIOS Enable */
2315                                 /*  bit 15 set - Big Endian Mode */
2316   ushort cfg_msw;               /* 01 unused */
2317   ushort disc_enable;           /* 02 disconnect enable */
2318   ushort wdtr_able;             /* 03 Wide DTR able */
2319   ushort sdtr_speed1;           /* 04 SDTR Speed TID 0-3 */
2320   ushort start_motor;           /* 05 send start up motor */
2321   ushort tagqng_able;           /* 06 tag queuing able */
2322   ushort bios_scan;             /* 07 BIOS device control */
2323   ushort scam_tolerant;         /* 08 no scam */
2324
2325   uchar  adapter_scsi_id;       /* 09 Host Adapter ID */
2326   uchar  bios_boot_delay;       /*    power up wait */
2327
2328   uchar  scsi_reset_delay;      /* 10 reset delay */
2329   uchar  bios_id_lun;           /*    first boot device scsi id & lun */
2330                                 /*    high nibble is lun */
2331                                 /*    low nibble is scsi id */
2332
2333   uchar  termination_se;        /* 11 0 - automatic */
2334                                 /*    1 - low off / high off */
2335                                 /*    2 - low off / high on */
2336                                 /*    3 - low on  / high on */
2337                                 /*    There is no low on  / high off */
2338
2339   uchar  termination_lvd;       /* 11 0 - automatic */
2340                                 /*    1 - low off / high off */
2341                                 /*    2 - low off / high on */
2342                                 /*    3 - low on  / high on */
2343                                 /*    There is no low on  / high off */
2344
2345   ushort bios_ctrl;             /* 12 BIOS control bits */
2346                                 /*  bit 0  BIOS don't act as initiator. */
2347                                 /*  bit 1  BIOS > 1 GB support */
2348                                 /*  bit 2  BIOS > 2 Disk Support */
2349                                 /*  bit 3  BIOS don't support removables */
2350                                 /*  bit 4  BIOS support bootable CD */
2351                                 /*  bit 5  BIOS scan enabled */
2352                                 /*  bit 6  BIOS support multiple LUNs */
2353                                 /*  bit 7  BIOS display of message */
2354                                 /*  bit 8  SCAM disabled */
2355                                 /*  bit 9  Reset SCSI bus during init. */
2356                                 /*  bit 10 Basic Integrity Checking disabled */
2357                                 /*  bit 11 No verbose initialization. */
2358                                 /*  bit 12 SCSI parity enabled */
2359                                 /*  bit 13 AIPP (Asyn. Info. Ph. Prot.) dis. */
2360                                 /*  bit 14 */
2361                                 /*  bit 15 */
2362   ushort  sdtr_speed2;          /* 13 SDTR speed TID 4-7 */
2363   ushort  sdtr_speed3;          /* 14 SDTR speed TID 8-11 */
2364   uchar   max_host_qng;         /* 15 maximum host queueing */
2365   uchar   max_dvc_qng;          /*    maximum per device queuing */
2366   ushort  dvc_cntl;             /* 16 control bit for driver */
2367   ushort  sdtr_speed4;          /* 17 SDTR speed 4 TID 12-15 */
2368   ushort  serial_number_word1;  /* 18 Board serial number word 1 */
2369   ushort  serial_number_word2;  /* 19 Board serial number word 2 */
2370   ushort  serial_number_word3;  /* 20 Board serial number word 3 */
2371   ushort  check_sum;            /* 21 EEP check sum */
2372   uchar   oem_name[16];         /* 22 OEM name */
2373   ushort  dvc_err_code;         /* 30 last device driver error code */
2374   ushort  adv_err_code;         /* 31 last uc and Adv Lib error code */
2375   ushort  adv_err_addr;         /* 32 last uc error address */
2376   ushort  saved_dvc_err_code;   /* 33 saved last dev. driver error code   */
2377   ushort  saved_adv_err_code;   /* 34 saved last uc and Adv Lib error code */
2378   ushort  saved_adv_err_addr;   /* 35 saved last uc error address         */
2379   ushort  reserved36;           /* 36 reserved */
2380   ushort  reserved37;           /* 37 reserved */
2381   ushort  reserved38;           /* 38 reserved */
2382   ushort  reserved39;           /* 39 reserved */
2383   ushort  reserved40;           /* 40 reserved */
2384   ushort  reserved41;           /* 41 reserved */
2385   ushort  reserved42;           /* 42 reserved */
2386   ushort  reserved43;           /* 43 reserved */
2387   ushort  reserved44;           /* 44 reserved */
2388   ushort  reserved45;           /* 45 reserved */
2389   ushort  reserved46;           /* 46 reserved */
2390   ushort  reserved47;           /* 47 reserved */
2391   ushort  reserved48;           /* 48 reserved */
2392   ushort  reserved49;           /* 49 reserved */
2393   ushort  reserved50;           /* 50 reserved */
2394   ushort  reserved51;           /* 51 reserved */
2395   ushort  reserved52;           /* 52 reserved */
2396   ushort  reserved53;           /* 53 reserved */
2397   ushort  reserved54;           /* 54 reserved */
2398   ushort  reserved55;           /* 55 reserved */
2399   ushort  cisptr_lsw;           /* 56 CIS PTR LSW */
2400   ushort  cisprt_msw;           /* 57 CIS PTR MSW */
2401   ushort  subsysvid;            /* 58 SubSystem Vendor ID */
2402   ushort  subsysid;             /* 59 SubSystem ID */
2403   ushort  reserved60;           /* 60 reserved */
2404   ushort  reserved61;           /* 61 reserved */
2405   ushort  reserved62;           /* 62 reserved */
2406   ushort  reserved63;           /* 63 reserved */
2407 } ADVEEP_38C1600_CONFIG;
2408
2409 /*
2410  * EEPROM Commands
2411  */
2412 #define ASC_EEP_CMD_DONE             0x0200
2413 #define ASC_EEP_CMD_DONE_ERR         0x0001
2414
2415 /* cfg_word */
2416 #define EEP_CFG_WORD_BIG_ENDIAN      0x8000
2417
2418 /* bios_ctrl */
2419 #define BIOS_CTRL_BIOS               0x0001
2420 #define BIOS_CTRL_EXTENDED_XLAT      0x0002
2421 #define BIOS_CTRL_GT_2_DISK          0x0004
2422 #define BIOS_CTRL_BIOS_REMOVABLE     0x0008
2423 #define BIOS_CTRL_BOOTABLE_CD        0x0010
2424 #define BIOS_CTRL_MULTIPLE_LUN       0x0040
2425 #define BIOS_CTRL_DISPLAY_MSG        0x0080
2426 #define BIOS_CTRL_NO_SCAM            0x0100
2427 #define BIOS_CTRL_RESET_SCSI_BUS     0x0200
2428 #define BIOS_CTRL_INIT_VERBOSE       0x0800
2429 #define BIOS_CTRL_SCSI_PARITY        0x1000
2430 #define BIOS_CTRL_AIPP_DIS           0x2000
2431
2432 #define ADV_3550_MEMSIZE   0x2000       /* 8 KB Internal Memory */
2433 #define ADV_3550_IOLEN     0x40         /* I/O Port Range in bytes */
2434
2435 #define ADV_38C0800_MEMSIZE  0x4000     /* 16 KB Internal Memory */
2436 #define ADV_38C0800_IOLEN    0x100      /* I/O Port Range in bytes */
2437
2438 /*
2439  * XXX - Since ASC38C1600 Rev.3 has a local RAM failure issue, there is
2440  * a special 16K Adv Library and Microcode version. After the issue is
2441  * resolved, should restore 32K support.
2442  *
2443  * #define ADV_38C1600_MEMSIZE  0x8000L   * 32 KB Internal Memory *
2444  */
2445 #define ADV_38C1600_MEMSIZE  0x4000   /* 16 KB Internal Memory */
2446 #define ADV_38C1600_IOLEN    0x100     /* I/O Port Range 256 bytes */
2447 #define ADV_38C1600_MEMLEN   0x1000    /* Memory Range 4KB bytes */
2448
2449 /*
2450  * Byte I/O register address from base of 'iop_base'.
2451  */
2452 #define IOPB_INTR_STATUS_REG    0x00
2453 #define IOPB_CHIP_ID_1          0x01
2454 #define IOPB_INTR_ENABLES       0x02
2455 #define IOPB_CHIP_TYPE_REV      0x03
2456 #define IOPB_RES_ADDR_4         0x04
2457 #define IOPB_RES_ADDR_5         0x05
2458 #define IOPB_RAM_DATA           0x06
2459 #define IOPB_RES_ADDR_7         0x07
2460 #define IOPB_FLAG_REG           0x08
2461 #define IOPB_RES_ADDR_9         0x09
2462 #define IOPB_RISC_CSR           0x0A
2463 #define IOPB_RES_ADDR_B         0x0B
2464 #define IOPB_RES_ADDR_C         0x0C
2465 #define IOPB_RES_ADDR_D         0x0D
2466 #define IOPB_SOFT_OVER_WR       0x0E
2467 #define IOPB_RES_ADDR_F         0x0F
2468 #define IOPB_MEM_CFG            0x10
2469 #define IOPB_RES_ADDR_11        0x11
2470 #define IOPB_GPIO_DATA          0x12
2471 #define IOPB_RES_ADDR_13        0x13
2472 #define IOPB_FLASH_PAGE         0x14
2473 #define IOPB_RES_ADDR_15        0x15
2474 #define IOPB_GPIO_CNTL          0x16
2475 #define IOPB_RES_ADDR_17        0x17
2476 #define IOPB_FLASH_DATA         0x18
2477 #define IOPB_RES_ADDR_19        0x19
2478 #define IOPB_RES_ADDR_1A        0x1A
2479 #define IOPB_RES_ADDR_1B        0x1B
2480 #define IOPB_RES_ADDR_1C        0x1C
2481 #define IOPB_RES_ADDR_1D        0x1D
2482 #define IOPB_RES_ADDR_1E        0x1E
2483 #define IOPB_RES_ADDR_1F        0x1F
2484 #define IOPB_DMA_CFG0           0x20
2485 #define IOPB_DMA_CFG1           0x21
2486 #define IOPB_TICKLE             0x22
2487 #define IOPB_DMA_REG_WR         0x23
2488 #define IOPB_SDMA_STATUS        0x24
2489 #define IOPB_SCSI_BYTE_CNT      0x25
2490 #define IOPB_HOST_BYTE_CNT      0x26
2491 #define IOPB_BYTE_LEFT_TO_XFER  0x27
2492 #define IOPB_BYTE_TO_XFER_0     0x28
2493 #define IOPB_BYTE_TO_XFER_1     0x29
2494 #define IOPB_BYTE_TO_XFER_2     0x2A
2495 #define IOPB_BYTE_TO_XFER_3     0x2B
2496 #define IOPB_ACC_GRP            0x2C
2497 #define IOPB_RES_ADDR_2D        0x2D
2498 #define IOPB_DEV_ID             0x2E
2499 #define IOPB_RES_ADDR_2F        0x2F
2500 #define IOPB_SCSI_DATA          0x30
2501 #define IOPB_RES_ADDR_31        0x31
2502 #define IOPB_RES_ADDR_32        0x32
2503 #define IOPB_SCSI_DATA_HSHK     0x33
2504 #define IOPB_SCSI_CTRL          0x34
2505 #define IOPB_RES_ADDR_35        0x35
2506 #define IOPB_RES_ADDR_36        0x36
2507 #define IOPB_RES_ADDR_37        0x37
2508 #define IOPB_RAM_BIST           0x38
2509 #define IOPB_PLL_TEST           0x39
2510 #define IOPB_PCI_INT_CFG        0x3A
2511 #define IOPB_RES_ADDR_3B        0x3B
2512 #define IOPB_RFIFO_CNT          0x3C
2513 #define IOPB_RES_ADDR_3D        0x3D
2514 #define IOPB_RES_ADDR_3E        0x3E
2515 #define IOPB_RES_ADDR_3F        0x3F
2516
2517 /*
2518  * Word I/O register address from base of 'iop_base'.
2519  */
2520 #define IOPW_CHIP_ID_0          0x00  /* CID0  */
2521 #define IOPW_CTRL_REG           0x02  /* CC    */
2522 #define IOPW_RAM_ADDR           0x04  /* LA    */
2523 #define IOPW_RAM_DATA           0x06  /* LD    */
2524 #define IOPW_RES_ADDR_08        0x08
2525 #define IOPW_RISC_CSR           0x0A  /* CSR   */
2526 #define IOPW_SCSI_CFG0          0x0C  /* CFG0  */
2527 #define IOPW_SCSI_CFG1          0x0E  /* CFG1  */
2528 #define IOPW_RES_ADDR_10        0x10
2529 #define IOPW_SEL_MASK           0x12  /* SM    */
2530 #define IOPW_RES_ADDR_14        0x14
2531 #define IOPW_FLASH_ADDR         0x16  /* FA    */
2532 #define IOPW_RES_ADDR_18        0x18
2533 #define IOPW_EE_CMD             0x1A  /* EC    */
2534 #define IOPW_EE_DATA            0x1C  /* ED    */
2535 #define IOPW_SFIFO_CNT          0x1E  /* SFC   */
2536 #define IOPW_RES_ADDR_20        0x20
2537 #define IOPW_Q_BASE             0x22  /* QB    */
2538 #define IOPW_QP                 0x24  /* QP    */
2539 #define IOPW_IX                 0x26  /* IX    */
2540 #define IOPW_SP                 0x28  /* SP    */
2541 #define IOPW_PC                 0x2A  /* PC    */
2542 #define IOPW_RES_ADDR_2C        0x2C
2543 #define IOPW_RES_ADDR_2E        0x2E
2544 #define IOPW_SCSI_DATA          0x30  /* SD    */
2545 #define IOPW_SCSI_DATA_HSHK     0x32  /* SDH   */
2546 #define IOPW_SCSI_CTRL          0x34  /* SC    */
2547 #define IOPW_HSHK_CFG           0x36  /* HCFG  */
2548 #define IOPW_SXFR_STATUS        0x36  /* SXS   */
2549 #define IOPW_SXFR_CNTL          0x38  /* SXL   */
2550 #define IOPW_SXFR_CNTH          0x3A  /* SXH   */
2551 #define IOPW_RES_ADDR_3C        0x3C
2552 #define IOPW_RFIFO_DATA         0x3E  /* RFD   */
2553
2554 /*
2555  * Doubleword I/O register address from base of 'iop_base'.
2556  */
2557 #define IOPDW_RES_ADDR_0         0x00
2558 #define IOPDW_RAM_DATA           0x04
2559 #define IOPDW_RES_ADDR_8         0x08
2560 #define IOPDW_RES_ADDR_C         0x0C
2561 #define IOPDW_RES_ADDR_10        0x10
2562 #define IOPDW_COMMA              0x14
2563 #define IOPDW_COMMB              0x18
2564 #define IOPDW_RES_ADDR_1C        0x1C
2565 #define IOPDW_SDMA_ADDR0         0x20
2566 #define IOPDW_SDMA_ADDR1         0x24
2567 #define IOPDW_SDMA_COUNT         0x28
2568 #define IOPDW_SDMA_ERROR         0x2C
2569 #define IOPDW_RDMA_ADDR0         0x30
2570 #define IOPDW_RDMA_ADDR1         0x34
2571 #define IOPDW_RDMA_COUNT         0x38
2572 #define IOPDW_RDMA_ERROR         0x3C
2573
2574 #define ADV_CHIP_ID_BYTE         0x25
2575 #define ADV_CHIP_ID_WORD         0x04C1
2576
2577 #define ADV_SC_SCSI_BUS_RESET    0x2000
2578
2579 #define ADV_INTR_ENABLE_HOST_INTR                   0x01
2580 #define ADV_INTR_ENABLE_SEL_INTR                    0x02
2581 #define ADV_INTR_ENABLE_DPR_INTR                    0x04
2582 #define ADV_INTR_ENABLE_RTA_INTR                    0x08
2583 #define ADV_INTR_ENABLE_RMA_INTR                    0x10
2584 #define ADV_INTR_ENABLE_RST_INTR                    0x20
2585 #define ADV_INTR_ENABLE_DPE_INTR                    0x40
2586 #define ADV_INTR_ENABLE_GLOBAL_INTR                 0x80
2587
2588 #define ADV_INTR_STATUS_INTRA            0x01
2589 #define ADV_INTR_STATUS_INTRB            0x02
2590 #define ADV_INTR_STATUS_INTRC            0x04
2591
2592 #define ADV_RISC_CSR_STOP           (0x0000)
2593 #define ADV_RISC_TEST_COND          (0x2000)
2594 #define ADV_RISC_CSR_RUN            (0x4000)
2595 #define ADV_RISC_CSR_SINGLE_STEP    (0x8000)
2596
2597 #define ADV_CTRL_REG_HOST_INTR      0x0100
2598 #define ADV_CTRL_REG_SEL_INTR       0x0200
2599 #define ADV_CTRL_REG_DPR_INTR       0x0400
2600 #define ADV_CTRL_REG_RTA_INTR       0x0800
2601 #define ADV_CTRL_REG_RMA_INTR       0x1000
2602 #define ADV_CTRL_REG_RES_BIT14      0x2000
2603 #define ADV_CTRL_REG_DPE_INTR       0x4000
2604 #define ADV_CTRL_REG_POWER_DONE     0x8000
2605 #define ADV_CTRL_REG_ANY_INTR       0xFF00
2606
2607 #define ADV_CTRL_REG_CMD_RESET             0x00C6
2608 #define ADV_CTRL_REG_CMD_WR_IO_REG         0x00C5
2609 #define ADV_CTRL_REG_CMD_RD_IO_REG         0x00C4
2610 #define ADV_CTRL_REG_CMD_WR_PCI_CFG_SPACE  0x00C3
2611 #define ADV_CTRL_REG_CMD_RD_PCI_CFG_SPACE  0x00C2
2612
2613 #define ADV_TICKLE_NOP                      0x00
2614 #define ADV_TICKLE_A                        0x01
2615 #define ADV_TICKLE_B                        0x02
2616 #define ADV_TICKLE_C                        0x03
2617
2618 #define ADV_SCSI_CTRL_RSTOUT        0x2000
2619
2620 #define AdvIsIntPending(port) \
2621     (AdvReadWordRegister(port, IOPW_CTRL_REG) & ADV_CTRL_REG_HOST_INTR)
2622
2623 /*
2624  * SCSI_CFG0 Register bit definitions
2625  */
2626 #define TIMER_MODEAB    0xC000  /* Watchdog, Second, and Select. Timer Ctrl. */
2627 #define PARITY_EN       0x2000  /* Enable SCSI Parity Error detection */
2628 #define EVEN_PARITY     0x1000  /* Select Even Parity */
2629 #define WD_LONG         0x0800  /* Watchdog Interval, 1: 57 min, 0: 13 sec */
2630 #define QUEUE_128       0x0400  /* Queue Size, 1: 128 byte, 0: 64 byte */
2631 #define PRIM_MODE       0x0100  /* Primitive SCSI mode */
2632 #define SCAM_EN         0x0080  /* Enable SCAM selection */
2633 #define SEL_TMO_LONG    0x0040  /* Sel/Resel Timeout, 1: 400 ms, 0: 1.6 ms */
2634 #define CFRM_ID         0x0020  /* SCAM id sel. confirm., 1: fast, 0: 6.4 ms */
2635 #define OUR_ID_EN       0x0010  /* Enable OUR_ID bits */
2636 #define OUR_ID          0x000F  /* SCSI ID */
2637
2638 /*
2639  * SCSI_CFG1 Register bit definitions
2640  */
2641 #define BIG_ENDIAN      0x8000  /* Enable Big Endian Mode MIO:15, EEP:15 */
2642 #define TERM_POL        0x2000  /* Terminator Polarity Ctrl. MIO:13, EEP:13 */
2643 #define SLEW_RATE       0x1000  /* SCSI output buffer slew rate */
2644 #define FILTER_SEL      0x0C00  /* Filter Period Selection */
2645 #define  FLTR_DISABLE    0x0000  /* Input Filtering Disabled */
2646 #define  FLTR_11_TO_20NS 0x0800  /* Input Filtering 11ns to 20ns */
2647 #define  FLTR_21_TO_39NS 0x0C00  /* Input Filtering 21ns to 39ns */
2648 #define ACTIVE_DBL      0x0200  /* Disable Active Negation */
2649 #define DIFF_MODE       0x0100  /* SCSI differential Mode (Read-Only) */
2650 #define DIFF_SENSE      0x0080  /* 1: No SE cables, 0: SE cable (Read-Only) */
2651 #define TERM_CTL_SEL    0x0040  /* Enable TERM_CTL_H and TERM_CTL_L */
2652 #define TERM_CTL        0x0030  /* External SCSI Termination Bits */
2653 #define  TERM_CTL_H      0x0020  /* Enable External SCSI Upper Termination */
2654 #define  TERM_CTL_L      0x0010  /* Enable External SCSI Lower Termination */
2655 #define CABLE_DETECT    0x000F  /* External SCSI Cable Connection Status */
2656
2657 /*
2658  * Addendum for ASC-38C0800 Chip
2659  *
2660  * The ASC-38C1600 Chip uses the same definitions except that the
2661  * bus mode override bits [12:10] have been moved to byte register
2662  * offset 0xE (IOPB_SOFT_OVER_WR) bits [12:10]. The [12:10] bits in
2663  * SCSI_CFG1 are read-only and always available. Bit 14 (DIS_TERM_DRV)
2664  * is not needed. The [12:10] bits in IOPB_SOFT_OVER_WR are write-only.
2665  * Also each ASC-38C1600 function or channel uses only cable bits [5:4]
2666  * and [1:0]. Bits [14], [7:6], [3:2] are unused.
2667  */
2668 #define DIS_TERM_DRV    0x4000  /* 1: Read c_det[3:0], 0: cannot read */
2669 #define HVD_LVD_SE      0x1C00  /* Device Detect Bits */
2670 #define  HVD             0x1000  /* HVD Device Detect */
2671 #define  LVD             0x0800  /* LVD Device Detect */
2672 #define  SE              0x0400  /* SE Device Detect */
2673 #define TERM_LVD        0x00C0  /* LVD Termination Bits */
2674 #define  TERM_LVD_HI     0x0080  /* Enable LVD Upper Termination */
2675 #define  TERM_LVD_LO     0x0040  /* Enable LVD Lower Termination */
2676 #define TERM_SE         0x0030  /* SE Termination Bits */
2677 #define  TERM_SE_HI      0x0020  /* Enable SE Upper Termination */
2678 #define  TERM_SE_LO      0x0010  /* Enable SE Lower Termination */
2679 #define C_DET_LVD       0x000C  /* LVD Cable Detect Bits */
2680 #define  C_DET3          0x0008  /* Cable Detect for LVD External Wide */
2681 #define  C_DET2          0x0004  /* Cable Detect for LVD Internal Wide */
2682 #define C_DET_SE        0x0003  /* SE Cable Detect Bits */
2683 #define  C_DET1          0x0002  /* Cable Detect for SE Internal Wide */
2684 #define  C_DET0          0x0001  /* Cable Detect for SE Internal Narrow */
2685
2686
2687 #define CABLE_ILLEGAL_A 0x7
2688     /* x 0 0 0  | on  on | Illegal (all 3 connectors are used) */
2689
2690 #define CABLE_ILLEGAL_B 0xB
2691     /* 0 x 0 0  | on  on | Illegal (all 3 connectors are used) */
2692
2693 /*
2694  * MEM_CFG Register bit definitions
2695  */
2696 #define BIOS_EN         0x40    /* BIOS Enable MIO:14,EEP:14 */
2697 #define FAST_EE_CLK     0x20    /* Diagnostic Bit */
2698 #define RAM_SZ          0x1C    /* Specify size of RAM to RISC */
2699 #define  RAM_SZ_2KB      0x00    /* 2 KB */
2700 #define  RAM_SZ_4KB      0x04    /* 4 KB */
2701 #define  RAM_SZ_8KB      0x08    /* 8 KB */
2702 #define  RAM_SZ_16KB     0x0C    /* 16 KB */
2703 #define  RAM_SZ_32KB     0x10    /* 32 KB */
2704 #define  RAM_SZ_64KB     0x14    /* 64 KB */
2705
2706 /*
2707  * DMA_CFG0 Register bit definitions
2708  *
2709  * This register is only accessible to the host.
2710  */
2711 #define BC_THRESH_ENB   0x80    /* PCI DMA Start Conditions */
2712 #define FIFO_THRESH     0x70    /* PCI DMA FIFO Threshold */
2713 #define  FIFO_THRESH_16B  0x00   /* 16 bytes */
2714 #define  FIFO_THRESH_32B  0x20   /* 32 bytes */
2715 #define  FIFO_THRESH_48B  0x30   /* 48 bytes */
2716 #define  FIFO_THRESH_64B  0x40   /* 64 bytes */
2717 #define  FIFO_THRESH_80B  0x50   /* 80 bytes (default) */
2718 #define  FIFO_THRESH_96B  0x60   /* 96 bytes */
2719 #define  FIFO_THRESH_112B 0x70   /* 112 bytes */
2720 #define START_CTL       0x0C    /* DMA start conditions */
2721 #define  START_CTL_TH    0x00    /* Wait threshold level (default) */
2722 #define  START_CTL_ID    0x04    /* Wait SDMA/SBUS idle */
2723 #define  START_CTL_THID  0x08    /* Wait threshold and SDMA/SBUS idle */
2724 #define  START_CTL_EMFU  0x0C    /* Wait SDMA FIFO empty/full */
2725 #define READ_CMD        0x03    /* Memory Read Method */
2726 #define  READ_CMD_MR     0x00    /* Memory Read */
2727 #define  READ_CMD_MRL    0x02    /* Memory Read Long */
2728 #define  READ_CMD_MRM    0x03    /* Memory Read Multiple (default) */
2729
2730 /*
2731  * ASC-38C0800 RAM BIST Register bit definitions
2732  */
2733 #define RAM_TEST_MODE         0x80
2734 #define PRE_TEST_MODE         0x40
2735 #define NORMAL_MODE           0x00
2736 #define RAM_TEST_DONE         0x10
2737 #define RAM_TEST_STATUS       0x0F
2738 #define  RAM_TEST_HOST_ERROR   0x08
2739 #define  RAM_TEST_INTRAM_ERROR 0x04
2740 #define  RAM_TEST_RISC_ERROR   0x02
2741 #define  RAM_TEST_SCSI_ERROR   0x01
2742 #define  RAM_TEST_SUCCESS      0x00
2743 #define PRE_TEST_VALUE        0x05
2744 #define NORMAL_VALUE          0x00
2745
2746 /*
2747  * ASC38C1600 Definitions
2748  *
2749  * IOPB_PCI_INT_CFG Bit Field Definitions
2750  */
2751
2752 #define INTAB_LD        0x80    /* Value loaded from EEPROM Bit 11. */
2753
2754 /*
2755  * Bit 1 can be set to change the interrupt for the Function to operate in
2756  * Totem Pole mode. By default Bit 1 is 0 and the interrupt operates in
2757  * Open Drain mode. Both functions of the ASC38C1600 must be set to the same
2758  * mode, otherwise the operating mode is undefined.
2759  */
2760 #define TOTEMPOLE       0x02
2761
2762 /*
2763  * Bit 0 can be used to change the Int Pin for the Function. The value is
2764  * 0 by default for both Functions with Function 0 using INT A and Function
2765  * B using INT B. For Function 0 if set, INT B is used. For Function 1 if set,
2766  * INT A is used.
2767  *
2768  * EEPROM Word 0 Bit 11 for each Function may change the initial Int Pin
2769  * value specified in the PCI Configuration Space.
2770  */
2771 #define INTAB           0x01
2772
2773 /* a_advlib.h */
2774
2775 /*
2776  * Adv Library Status Definitions
2777  */
2778 #define ADV_TRUE        1
2779 #define ADV_FALSE       0
2780 #define ADV_NOERROR     1
2781 #define ADV_SUCCESS     1
2782 #define ADV_BUSY        0
2783 #define ADV_ERROR       (-1)
2784
2785
2786 /*
2787  * ADV_DVC_VAR 'warn_code' values
2788  */
2789 #define ASC_WARN_BUSRESET_ERROR         0x0001 /* SCSI Bus Reset error */
2790 #define ASC_WARN_EEPROM_CHKSUM          0x0002 /* EEP check sum error */
2791 #define ASC_WARN_EEPROM_TERMINATION     0x0004 /* EEP termination bad field */
2792 #define ASC_WARN_SET_PCI_CONFIG_SPACE   0x0080 /* PCI config space set error */
2793 #define ASC_WARN_ERROR                  0xFFFF /* ADV_ERROR return */
2794
2795 #define ADV_MAX_TID                     15 /* max. target identifier */
2796 #define ADV_MAX_LUN                     7  /* max. logical unit number */
2797
2798 /*
2799  * Error code values are set in ADV_DVC_VAR 'err_code'.
2800  */
2801 #define ASC_IERR_WRITE_EEPROM       0x0001 /* write EEPROM error */
2802 #define ASC_IERR_MCODE_CHKSUM       0x0002 /* micro code check sum error */
2803 #define ASC_IERR_NO_CARRIER         0x0004 /* No more carrier memory. */
2804 #define ASC_IERR_START_STOP_CHIP    0x0008 /* start/stop chip failed */
2805 #define ASC_IERR_CHIP_VERSION       0x0040 /* wrong chip version */
2806 #define ASC_IERR_SET_SCSI_ID        0x0080 /* set SCSI ID failed */
2807 #define ASC_IERR_HVD_DEVICE         0x0100 /* HVD attached to LVD connector. */
2808 #define ASC_IERR_BAD_SIGNATURE      0x0200 /* signature not found */
2809 #define ASC_IERR_ILLEGAL_CONNECTION 0x0400 /* Illegal cable connection */
2810 #define ASC_IERR_SINGLE_END_DEVICE  0x0800 /* Single-end used w/differential */
2811 #define ASC_IERR_REVERSED_CABLE     0x1000 /* Narrow flat cable reversed */
2812 #define ASC_IERR_BIST_PRE_TEST      0x2000 /* BIST pre-test error */
2813 #define ASC_IERR_BIST_RAM_TEST      0x4000 /* BIST RAM test error */
2814 #define ASC_IERR_BAD_CHIPTYPE       0x8000 /* Invalid 'chip_type' setting. */
2815
2816 /*
2817  * Fixed locations of microcode operating variables.
2818  */
2819 #define ASC_MC_CODE_BEGIN_ADDR          0x0028 /* microcode start address */
2820 #define ASC_MC_CODE_END_ADDR            0x002A /* microcode end address */
2821 #define ASC_MC_CODE_CHK_SUM             0x002C /* microcode code checksum */
2822 #define ASC_MC_VERSION_DATE             0x0038 /* microcode version */
2823 #define ASC_MC_VERSION_NUM              0x003A /* microcode number */
2824 #define ASC_MC_BIOSMEM                  0x0040 /* BIOS RISC Memory Start */
2825 #define ASC_MC_BIOSLEN                  0x0050 /* BIOS RISC Memory Length */
2826 #define ASC_MC_BIOS_SIGNATURE           0x0058 /* BIOS Signature 0x55AA */
2827 #define ASC_MC_BIOS_VERSION             0x005A /* BIOS Version (2 bytes) */
2828 #define ASC_MC_SDTR_SPEED1              0x0090 /* SDTR Speed for TID 0-3 */
2829 #define ASC_MC_SDTR_SPEED2              0x0092 /* SDTR Speed for TID 4-7 */
2830 #define ASC_MC_SDTR_SPEED3              0x0094 /* SDTR Speed for TID 8-11 */
2831 #define ASC_MC_SDTR_SPEED4              0x0096 /* SDTR Speed for TID 12-15 */
2832 #define ASC_MC_CHIP_TYPE                0x009A
2833 #define ASC_MC_INTRB_CODE               0x009B
2834 #define ASC_MC_WDTR_ABLE                0x009C
2835 #define ASC_MC_SDTR_ABLE                0x009E
2836 #define ASC_MC_TAGQNG_ABLE              0x00A0
2837 #define ASC_MC_DISC_ENABLE              0x00A2
2838 #define ASC_MC_IDLE_CMD_STATUS          0x00A4
2839 #define ASC_MC_IDLE_CMD                 0x00A6
2840 #define ASC_MC_IDLE_CMD_PARAMETER       0x00A8
2841 #define ASC_MC_DEFAULT_SCSI_CFG0        0x00AC
2842 #define ASC_MC_DEFAULT_SCSI_CFG1        0x00AE
2843 #define ASC_MC_DEFAULT_MEM_CFG          0x00B0
2844 #define ASC_MC_DEFAULT_SEL_MASK         0x00B2
2845 #define ASC_MC_SDTR_DONE                0x00B6
2846 #define ASC_MC_NUMBER_OF_QUEUED_CMD     0x00C0
2847 #define ASC_MC_NUMBER_OF_MAX_CMD        0x00D0
2848 #define ASC_MC_DEVICE_HSHK_CFG_TABLE    0x0100
2849 #define ASC_MC_CONTROL_FLAG             0x0122 /* Microcode control flag. */
2850 #define ASC_MC_WDTR_DONE                0x0124
2851 #define ASC_MC_CAM_MODE_MASK            0x015E /* CAM mode TID bitmask. */
2852 #define ASC_MC_ICQ                      0x0160
2853 #define ASC_MC_IRQ                      0x0164
2854 #define ASC_MC_PPR_ABLE                 0x017A
2855
2856 /*
2857  * BIOS LRAM variable absolute offsets.
2858  */
2859 #define BIOS_CODESEG    0x54
2860 #define BIOS_CODELEN    0x56
2861 #define BIOS_SIGNATURE  0x58
2862 #define BIOS_VERSION    0x5A
2863
2864 /*
2865  * Microcode Control Flags
2866  *
2867  * Flags set by the Adv Library in RISC variable 'control_flag' (0x122)
2868  * and handled by the microcode.
2869  */
2870 #define CONTROL_FLAG_IGNORE_PERR        0x0001 /* Ignore DMA Parity Errors */
2871 #define CONTROL_FLAG_ENABLE_AIPP        0x0002 /* Enabled AIPP checking. */
2872
2873 /*
2874  * ASC_MC_DEVICE_HSHK_CFG_TABLE microcode table or HSHK_CFG register format
2875  */
2876 #define HSHK_CFG_WIDE_XFR       0x8000
2877 #define HSHK_CFG_RATE           0x0F00
2878 #define HSHK_CFG_OFFSET         0x001F
2879
2880 #define ASC_DEF_MAX_HOST_QNG    0xFD /* Max. number of host commands (253) */
2881 #define ASC_DEF_MIN_HOST_QNG    0x10 /* Min. number of host commands (16) */
2882 #define ASC_DEF_MAX_DVC_QNG     0x3F /* Max. number commands per device (63) */
2883 #define ASC_DEF_MIN_DVC_QNG     0x04 /* Min. number commands per device (4) */
2884
2885 #define ASC_QC_DATA_CHECK  0x01 /* Require ASC_QC_DATA_OUT set or clear. */
2886 #define ASC_QC_DATA_OUT    0x02 /* Data out DMA transfer. */
2887 #define ASC_QC_START_MOTOR 0x04 /* Send auto-start motor before request. */
2888 #define ASC_QC_NO_OVERRUN  0x08 /* Don't report overrun. */
2889 #define ASC_QC_FREEZE_TIDQ 0x10 /* Freeze TID queue after request. XXX TBD */
2890
2891 #define ASC_QSC_NO_DISC     0x01 /* Don't allow disconnect for request. */
2892 #define ASC_QSC_NO_TAGMSG   0x02 /* Don't allow tag queuing for request. */
2893 #define ASC_QSC_NO_SYNC     0x04 /* Don't use Synch. transfer on request. */
2894 #define ASC_QSC_NO_WIDE     0x08 /* Don't use Wide transfer on request. */
2895 #define ASC_QSC_REDO_DTR    0x10 /* Renegotiate WDTR/SDTR before request. */
2896 /*
2897  * Note: If a Tag Message is to be sent and neither ASC_QSC_HEAD_TAG or
2898  * ASC_QSC_ORDERED_TAG is set, then a Simple Tag Message (0x20) is used.
2899  */
2900 #define ASC_QSC_HEAD_TAG    0x40 /* Use Head Tag Message (0x21). */
2901 #define ASC_QSC_ORDERED_TAG 0x80 /* Use Ordered Tag Message (0x22). */
2902
2903 /*
2904  * All fields here are accessed by the board microcode and need to be
2905  * little-endian.
2906  */
2907 typedef struct adv_carr_t
2908 {
2909     ADV_VADDR   carr_va;       /* Carrier Virtual Address */
2910     ADV_PADDR   carr_pa;       /* Carrier Physical Address */
2911     ADV_VADDR   areq_vpa;      /* ASC_SCSI_REQ_Q Virtual or Physical Address */
2912     /*
2913      * next_vpa [31:4]            Carrier Virtual or Physical Next Pointer
2914      *
2915      * next_vpa [3:1]             Reserved Bits
2916      * next_vpa [0]               Done Flag set in Response Queue.
2917      */
2918     ADV_VADDR   next_vpa;
2919 } ADV_CARR_T;
2920
2921 /*
2922  * Mask used to eliminate low 4 bits of carrier 'next_vpa' field.
2923  */
2924 #define ASC_NEXT_VPA_MASK       0xFFFFFFF0
2925
2926 #define ASC_RQ_DONE             0x00000001
2927 #define ASC_RQ_GOOD             0x00000002
2928 #define ASC_CQ_STOPPER          0x00000000
2929
2930 #define ASC_GET_CARRP(carrp) ((carrp) & ASC_NEXT_VPA_MASK)
2931
2932 #define ADV_CARRIER_NUM_PAGE_CROSSING \
2933     (((ADV_CARRIER_COUNT * sizeof(ADV_CARR_T)) + \
2934         (ADV_PAGE_SIZE - 1))/ADV_PAGE_SIZE)
2935
2936 #define ADV_CARRIER_BUFSIZE \
2937     ((ADV_CARRIER_COUNT + ADV_CARRIER_NUM_PAGE_CROSSING) * sizeof(ADV_CARR_T))
2938
2939 /*
2940  * ASC_SCSI_REQ_Q 'a_flag' definitions
2941  *
2942  * The Adv Library should limit use to the lower nibble (4 bits) of
2943  * a_flag. Drivers are free to use the upper nibble (4 bits) of a_flag.
2944  */
2945 #define ADV_POLL_REQUEST                0x01   /* poll for request completion */
2946 #define ADV_SCSIQ_DONE                  0x02   /* request done */
2947 #define ADV_DONT_RETRY                  0x08   /* don't do retry */
2948
2949 #define ADV_CHIP_ASC3550          0x01   /* Ultra-Wide IC */
2950 #define ADV_CHIP_ASC38C0800       0x02   /* Ultra2-Wide/LVD IC */
2951 #define ADV_CHIP_ASC38C1600       0x03   /* Ultra3-Wide/LVD2 IC */
2952
2953 /*
2954  * Adapter temporary configuration structure
2955  *
2956  * This structure can be discarded after initialization. Don't add
2957  * fields here needed after initialization.
2958  *
2959  * Field naming convention:
2960  *
2961  *  *_enable indicates the field enables or disables a feature. The
2962  *  value of the field is never reset.
2963  */
2964 typedef struct adv_dvc_cfg {
2965   ushort disc_enable;       /* enable disconnection */
2966   uchar  chip_version;      /* chip version */
2967   uchar  termination;       /* Term. Ctrl. bits 6-5 of SCSI_CFG1 register */
2968   ushort lib_version;       /* Adv Library version number */
2969   ushort control_flag;      /* Microcode Control Flag */
2970   ushort mcode_date;        /* Microcode date */
2971   ushort mcode_version;     /* Microcode version */
2972   ushort pci_slot_info;     /* high byte device/function number */
2973                             /* bits 7-3 device num., bits 2-0 function num. */
2974                             /* low byte bus num. */
2975   ushort serial1;           /* EEPROM serial number word 1 */
2976   ushort serial2;           /* EEPROM serial number word 2 */
2977   ushort serial3;           /* EEPROM serial number word 3 */
2978   struct device *dev;  /* pointer to the pci dev structure for this board */
2979 } ADV_DVC_CFG;
2980
2981 struct adv_dvc_var;
2982 struct adv_scsi_req_q;
2983
2984 typedef void (* ADV_ISR_CALLBACK)
2985     (struct adv_dvc_var *, struct adv_scsi_req_q *);
2986
2987 typedef void (* ADV_ASYNC_CALLBACK)
2988     (struct adv_dvc_var *, uchar);
2989
2990 /*
2991  * Adapter operation variable structure.
2992  *
2993  * One structure is required per host adapter.
2994  *
2995  * Field naming convention:
2996  *
2997  *  *_able indicates both whether a feature should be enabled or disabled
2998  *  and whether a device isi capable of the feature. At initialization
2999  *  this field may be set, but later if a device is found to be incapable
3000  *  of the feature, the field is cleared.
3001  */
3002 typedef struct adv_dvc_var {
3003   AdvPortAddr iop_base;   /* I/O port address */
3004   ushort err_code;        /* fatal error code */
3005   ushort bios_ctrl;       /* BIOS control word, EEPROM word 12 */
3006   ADV_ISR_CALLBACK isr_callback;
3007   ADV_ASYNC_CALLBACK async_callback;
3008   ushort wdtr_able;       /* try WDTR for a device */
3009   ushort sdtr_able;       /* try SDTR for a device */
3010   ushort ultra_able;      /* try SDTR Ultra speed for a device */
3011   ushort sdtr_speed1;     /* EEPROM SDTR Speed for TID 0-3   */
3012   ushort sdtr_speed2;     /* EEPROM SDTR Speed for TID 4-7   */
3013   ushort sdtr_speed3;     /* EEPROM SDTR Speed for TID 8-11  */
3014   ushort sdtr_speed4;     /* EEPROM SDTR Speed for TID 12-15 */
3015   ushort tagqng_able;     /* try tagged queuing with a device */
3016   ushort ppr_able;        /* PPR message capable per TID bitmask. */
3017   uchar  max_dvc_qng;     /* maximum number of tagged commands per device */
3018   ushort start_motor;     /* start motor command allowed */
3019   uchar  scsi_reset_wait; /* delay in seconds after scsi bus reset */
3020   uchar  chip_no;         /* should be assigned by caller */
3021   uchar  max_host_qng;    /* maximum number of Q'ed command allowed */
3022   uchar  irq_no;          /* IRQ number */
3023   ushort no_scam;         /* scam_tolerant of EEPROM */
3024   struct asc_board *drv_ptr; /* driver pointer to private structure */
3025   uchar  chip_scsi_id;    /* chip SCSI target ID */
3026   uchar  chip_type;
3027   uchar  bist_err_code;
3028   ADV_CARR_T *carrier_buf;
3029   ADV_CARR_T *carr_freelist; /* Carrier free list. */
3030   ADV_CARR_T *icq_sp;  /* Initiator command queue stopper pointer. */
3031   ADV_CARR_T *irq_sp;  /* Initiator response queue stopper pointer. */
3032   ushort carr_pending_cnt;    /* Count of pending carriers. */
3033  /*
3034   * Note: The following fields will not be used after initialization. The
3035   * driver may discard the buffer after initialization is done.
3036   */
3037   ADV_DVC_CFG *cfg; /* temporary configuration structure  */
3038 } ADV_DVC_VAR;
3039
3040 #define NO_OF_SG_PER_BLOCK              15
3041
3042 typedef struct asc_sg_block {
3043     uchar reserved1;
3044     uchar reserved2;
3045     uchar reserved3;
3046     uchar sg_cnt;                     /* Valid entries in block. */
3047     ADV_PADDR sg_ptr;                 /* Pointer to next sg block. */
3048     struct  {
3049         ADV_PADDR sg_addr;                  /* SG element address. */
3050         ADV_DCNT  sg_count;                 /* SG element count. */
3051     } sg_list[NO_OF_SG_PER_BLOCK];
3052 } ADV_SG_BLOCK;
3053
3054 /*
3055  * ADV_SCSI_REQ_Q - microcode request structure
3056  *
3057  * All fields in this structure up to byte 60 are used by the microcode.
3058  * The microcode makes assumptions about the size and ordering of fields
3059  * in this structure. Do not change the structure definition here without
3060  * coordinating the change with the microcode.
3061  *
3062  * All fields accessed by microcode must be maintained in little_endian
3063  * order.
3064  */
3065 typedef struct adv_scsi_req_q {
3066     uchar       cntl;           /* Ucode flags and state (ASC_MC_QC_*). */
3067     uchar       target_cmd;
3068     uchar       target_id;      /* Device target identifier. */
3069     uchar       target_lun;     /* Device target logical unit number. */
3070     ADV_PADDR   data_addr;      /* Data buffer physical address. */
3071     ADV_DCNT    data_cnt;       /* Data count. Ucode sets to residual. */
3072     ADV_PADDR   sense_addr;
3073     ADV_PADDR   carr_pa;
3074     uchar       mflag;
3075     uchar       sense_len;
3076     uchar       cdb_len;        /* SCSI CDB length. Must <= 16 bytes. */
3077     uchar       scsi_cntl;
3078     uchar       done_status;    /* Completion status. */
3079     uchar       scsi_status;    /* SCSI status byte. */
3080     uchar       host_status;    /* Ucode host status. */
3081     uchar       sg_working_ix;
3082     uchar       cdb[12];        /* SCSI CDB bytes 0-11. */
3083     ADV_PADDR   sg_real_addr;   /* SG list physical address. */
3084     ADV_PADDR   scsiq_rptr;
3085     uchar       cdb16[4];       /* SCSI CDB bytes 12-15. */
3086     ADV_VADDR   scsiq_ptr;
3087     ADV_VADDR   carr_va;
3088     /*
3089      * End of microcode structure - 60 bytes. The rest of the structure
3090      * is used by the Adv Library and ignored by the microcode.
3091      */
3092     ADV_VADDR   srb_ptr;
3093     ADV_SG_BLOCK *sg_list_ptr; /* SG list virtual address. */
3094     char        *vdata_addr;   /* Data buffer virtual address. */
3095     uchar       a_flag;
3096     uchar       pad[2];        /* Pad out to a word boundary. */
3097 } ADV_SCSI_REQ_Q;
3098
3099 /*
3100  * Microcode idle loop commands
3101  */
3102 #define IDLE_CMD_COMPLETED           0
3103 #define IDLE_CMD_STOP_CHIP           0x0001
3104 #define IDLE_CMD_STOP_CHIP_SEND_INT  0x0002
3105 #define IDLE_CMD_SEND_INT            0x0004
3106 #define IDLE_CMD_ABORT               0x0008
3107 #define IDLE_CMD_DEVICE_RESET        0x0010
3108 #define IDLE_CMD_SCSI_RESET_START    0x0020 /* Assert SCSI Bus Reset */
3109 #define IDLE_CMD_SCSI_RESET_END      0x0040 /* Deassert SCSI Bus Reset */
3110 #define IDLE_CMD_SCSIREQ             0x0080
3111
3112 #define IDLE_CMD_STATUS_SUCCESS      0x0001
3113 #define IDLE_CMD_STATUS_FAILURE      0x0002
3114
3115 /*
3116  * AdvSendIdleCmd() flag definitions.
3117  */
3118 #define ADV_NOWAIT     0x01
3119
3120 /*
3121  * Wait loop time out values.
3122  */
3123 #define SCSI_WAIT_10_SEC             10UL    /* 10 seconds */
3124 #define SCSI_WAIT_100_MSEC           100UL   /* 100 milliseconds */
3125 #define SCSI_US_PER_MSEC             1000    /* microseconds per millisecond */
3126 #define SCSI_MS_PER_SEC              1000UL  /* milliseconds per second */
3127 #define SCSI_MAX_RETRY               10      /* retry count */
3128
3129 #define ADV_ASYNC_RDMA_FAILURE          0x01 /* Fatal RDMA failure. */
3130 #define ADV_ASYNC_SCSI_BUS_RESET_DET    0x02 /* Detected SCSI Bus Reset. */
3131 #define ADV_ASYNC_CARRIER_READY_FAILURE 0x03 /* Carrier Ready failure. */
3132 #define ADV_RDMA_IN_CARR_AND_Q_INVALID  0x04 /* RDMAed-in data invalid. */
3133
3134
3135 #define ADV_HOST_SCSI_BUS_RESET      0x80 /* Host Initiated SCSI Bus Reset. */
3136
3137 /*
3138  * Device drivers must define the following functions.
3139  */
3140 STATIC inline ulong DvcEnterCritical(void);
3141 STATIC inline void  DvcLeaveCritical(ulong);
3142 STATIC void  DvcSleepMilliSecond(ADV_DCNT);
3143 STATIC uchar DvcAdvReadPCIConfigByte(ADV_DVC_VAR *, ushort);
3144 STATIC void  DvcAdvWritePCIConfigByte(ADV_DVC_VAR *, ushort, uchar);
3145 STATIC ADV_PADDR DvcGetPhyAddr(ADV_DVC_VAR *, ADV_SCSI_REQ_Q *,
3146                 uchar *, ASC_SDCNT *, int);
3147 STATIC void  DvcDelayMicroSecond(ADV_DVC_VAR *, ushort);
3148
3149 /*
3150  * Adv Library functions available to drivers.
3151  */
3152 STATIC int     AdvExeScsiQueue(ADV_DVC_VAR *, ADV_SCSI_REQ_Q *);
3153 STATIC int     AdvISR(ADV_DVC_VAR *);
3154 STATIC int     AdvInitGetConfig(ADV_DVC_VAR *);
3155 STATIC int     AdvInitAsc3550Driver(ADV_DVC_VAR *);
3156 STATIC int     AdvInitAsc38C0800Driver(ADV_DVC_VAR *);
3157 STATIC int     AdvInitAsc38C1600Driver(ADV_DVC_VAR *);
3158 STATIC int     AdvResetChipAndSB(ADV_DVC_VAR *);
3159 STATIC int     AdvResetSB(ADV_DVC_VAR *asc_dvc);
3160
3161 /*
3162  * Internal Adv Library functions.
3163  */
3164 STATIC int    AdvSendIdleCmd(ADV_DVC_VAR *, ushort, ADV_DCNT);
3165 STATIC void   AdvInquiryHandling(ADV_DVC_VAR *, ADV_SCSI_REQ_Q *);
3166 STATIC int    AdvInitFrom3550EEP(ADV_DVC_VAR *);
3167 STATIC int    AdvInitFrom38C0800EEP(ADV_DVC_VAR *);
3168 STATIC int    AdvInitFrom38C1600EEP(ADV_DVC_VAR *);
3169 STATIC ushort AdvGet3550EEPConfig(AdvPortAddr, ADVEEP_3550_CONFIG *);
3170 STATIC void   AdvSet3550EEPConfig(AdvPortAddr, ADVEEP_3550_CONFIG *);
3171 STATIC ushort AdvGet38C0800EEPConfig(AdvPortAddr, ADVEEP_38C0800_CONFIG *);
3172 STATIC void   AdvSet38C0800EEPConfig(AdvPortAddr, ADVEEP_38C0800_CONFIG *);
3173 STATIC ushort AdvGet38C1600EEPConfig(AdvPortAddr, ADVEEP_38C1600_CONFIG *);
3174 STATIC void   AdvSet38C1600EEPConfig(AdvPortAddr, ADVEEP_38C1600_CONFIG *);
3175 STATIC void   AdvWaitEEPCmd(AdvPortAddr);
3176 STATIC ushort AdvReadEEPWord(AdvPortAddr, int);
3177
3178 /*
3179  * PCI Bus Definitions
3180  */
3181 #define AscPCICmdRegBits_BusMastering     0x0007
3182 #define AscPCICmdRegBits_ParErrRespCtrl   0x0040
3183
3184 /* Read byte from a register. */
3185 #define AdvReadByteRegister(iop_base, reg_off) \
3186      (ADV_MEM_READB((iop_base) + (reg_off)))
3187
3188 /* Write byte to a register. */
3189 #define AdvWriteByteRegister(iop_base, reg_off, byte) \
3190      (ADV_MEM_WRITEB((iop_base) + (reg_off), (byte)))
3191
3192 /* Read word (2 bytes) from a register. */
3193 #define AdvReadWordRegister(iop_base, reg_off) \
3194      (ADV_MEM_READW((iop_base) + (reg_off)))
3195
3196 /* Write word (2 bytes) to a register. */
3197 #define AdvWriteWordRegister(iop_base, reg_off, word) \
3198      (ADV_MEM_WRITEW((iop_base) + (reg_off), (word)))
3199
3200 /* Write dword (4 bytes) to a register. */
3201 #define AdvWriteDWordRegister(iop_base, reg_off, dword) \
3202      (ADV_MEM_WRITEDW((iop_base) + (reg_off), (dword)))
3203
3204 /* Read byte from LRAM. */
3205 #define AdvReadByteLram(iop_base, addr, byte) \
3206 do { \
3207     ADV_MEM_WRITEW((iop_base) + IOPW_RAM_ADDR, (addr)); \
3208     (byte) = ADV_MEM_READB((iop_base) + IOPB_RAM_DATA); \
3209 } while (0)
3210
3211 /* Write byte to LRAM. */
3212 #define AdvWriteByteLram(iop_base, addr, byte) \
3213     (ADV_MEM_WRITEW((iop_base) + IOPW_RAM_ADDR, (addr)), \
3214      ADV_MEM_WRITEB((iop_base) + IOPB_RAM_DATA, (byte)))
3215
3216 /* Read word (2 bytes) from LRAM. */
3217 #define AdvReadWordLram(iop_base, addr, word) \
3218 do { \
3219     ADV_MEM_WRITEW((iop_base) + IOPW_RAM_ADDR, (addr)); \
3220     (word) = (ADV_MEM_READW((iop_base) + IOPW_RAM_DATA)); \
3221 } while (0)
3222
3223 /* Write word (2 bytes) to LRAM. */
3224 #define AdvWriteWordLram(iop_base, addr, word) \
3225     (ADV_MEM_WRITEW((iop_base) + IOPW_RAM_ADDR, (addr)), \
3226      ADV_MEM_WRITEW((iop_base) + IOPW_RAM_DATA, (word)))
3227
3228 /* Write little-endian double word (4 bytes) to LRAM */
3229 /* Because of unspecified C language ordering don't use auto-increment. */
3230 #define AdvWriteDWordLramNoSwap(iop_base, addr, dword) \
3231     ((ADV_MEM_WRITEW((iop_base) + IOPW_RAM_ADDR, (addr)), \
3232       ADV_MEM_WRITEW((iop_base) + IOPW_RAM_DATA, \
3233                      cpu_to_le16((ushort) ((dword) & 0xFFFF)))), \
3234      (ADV_MEM_WRITEW((iop_base) + IOPW_RAM_ADDR, (addr) + 2), \
3235       ADV_MEM_WRITEW((iop_base) + IOPW_RAM_DATA, \
3236                      cpu_to_le16((ushort) ((dword >> 16) & 0xFFFF)))))
3237
3238 /* Read word (2 bytes) from LRAM assuming that the address is already set. */
3239 #define AdvReadWordAutoIncLram(iop_base) \
3240      (ADV_MEM_READW((iop_base) + IOPW_RAM_DATA))
3241
3242 /* Write word (2 bytes) to LRAM assuming that the address is already set. */
3243 #define AdvWriteWordAutoIncLram(iop_base, word) \
3244      (ADV_MEM_WRITEW((iop_base) + IOPW_RAM_DATA, (word)))
3245
3246
3247 /*
3248  * Define macro to check for Condor signature.
3249  *
3250  * Evaluate to ADV_TRUE if a Condor chip is found the specified port
3251  * address 'iop_base'. Otherwise evalue to ADV_FALSE.
3252  */
3253 #define AdvFindSignature(iop_base) \
3254     (((AdvReadByteRegister((iop_base), IOPB_CHIP_ID_1) == \
3255     ADV_CHIP_ID_BYTE) && \
3256      (AdvReadWordRegister((iop_base), IOPW_CHIP_ID_0) == \
3257     ADV_CHIP_ID_WORD)) ?  ADV_TRUE : ADV_FALSE)
3258
3259 /*
3260  * Define macro to Return the version number of the chip at 'iop_base'.
3261  *
3262  * The second parameter 'bus_type' is currently unused.
3263  */
3264 #define AdvGetChipVersion(iop_base, bus_type) \
3265     AdvReadByteRegister((iop_base), IOPB_CHIP_TYPE_REV)
3266
3267 /*
3268  * Abort an SRB in the chip's RISC Memory. The 'srb_ptr' argument must
3269  * match the ASC_SCSI_REQ_Q 'srb_ptr' field.
3270  *
3271  * If the request has not yet been sent to the device it will simply be
3272  * aborted from RISC memory. If the request is disconnected it will be
3273  * aborted on reselection by sending an Abort Message to the target ID.
3274  *
3275  * Return value:
3276  *      ADV_TRUE(1) - Queue was successfully aborted.
3277  *      ADV_FALSE(0) - Queue was not found on the active queue list.
3278  */
3279 #define AdvAbortQueue(asc_dvc, scsiq) \
3280         AdvSendIdleCmd((asc_dvc), (ushort) IDLE_CMD_ABORT, \
3281                        (ADV_DCNT) (scsiq))
3282
3283 /*
3284  * Send a Bus Device Reset Message to the specified target ID.
3285  *
3286  * All outstanding commands will be purged if sending the
3287  * Bus Device Reset Message is successful.
3288  *
3289  * Return Value:
3290  *      ADV_TRUE(1) - All requests on the target are purged.
3291  *      ADV_FALSE(0) - Couldn't issue Bus Device Reset Message; Requests
3292  *                     are not purged.
3293  */
3294 #define AdvResetDevice(asc_dvc, target_id) \
3295         AdvSendIdleCmd((asc_dvc), (ushort) IDLE_CMD_DEVICE_RESET, \
3296                     (ADV_DCNT) (target_id))
3297
3298 /*
3299  * SCSI Wide Type definition.
3300  */
3301 #define ADV_SCSI_BIT_ID_TYPE   ushort
3302
3303 /*
3304  * AdvInitScsiTarget() 'cntl_flag' options.
3305  */
3306 #define ADV_SCAN_LUN           0x01
3307 #define ADV_CAPINFO_NOLUN      0x02
3308
3309 /*
3310  * Convert target id to target id bit mask.
3311  */
3312 #define ADV_TID_TO_TIDMASK(tid)   (0x01 << ((tid) & ADV_MAX_TID))
3313
3314 /*
3315  * ASC_SCSI_REQ_Q 'done_status' and 'host_status' return values.
3316  */
3317
3318 #define QD_NO_STATUS         0x00       /* Request not completed yet. */
3319 #define QD_NO_ERROR          0x01
3320 #define QD_ABORTED_BY_HOST   0x02
3321 #define QD_WITH_ERROR        0x04
3322
3323 #define QHSTA_NO_ERROR              0x00
3324 #define QHSTA_M_SEL_TIMEOUT         0x11
3325 #define QHSTA_M_DATA_OVER_RUN       0x12
3326 #define QHSTA_M_UNEXPECTED_BUS_FREE 0x13
3327 #define QHSTA_M_QUEUE_ABORTED       0x15
3328 #define QHSTA_M_SXFR_SDMA_ERR       0x16 /* SXFR_STATUS SCSI DMA Error */
3329 #define QHSTA_M_SXFR_SXFR_PERR      0x17 /* SXFR_STATUS SCSI Bus Parity Error */
3330 #define QHSTA_M_RDMA_PERR           0x18 /* RISC PCI DMA parity error */
3331 #define QHSTA_M_SXFR_OFF_UFLW       0x19 /* SXFR_STATUS Offset Underflow */
3332 #define QHSTA_M_SXFR_OFF_OFLW       0x20 /* SXFR_STATUS Offset Overflow */
3333 #define QHSTA_M_SXFR_WD_TMO         0x21 /* SXFR_STATUS Watchdog Timeout */
3334 #define QHSTA_M_SXFR_DESELECTED     0x22 /* SXFR_STATUS Deselected */
3335 /* Note: QHSTA_M_SXFR_XFR_OFLW is identical to QHSTA_M_DATA_OVER_RUN. */
3336 #define QHSTA_M_SXFR_XFR_OFLW       0x12 /* SXFR_STATUS Transfer Overflow */
3337 #define QHSTA_M_SXFR_XFR_PH_ERR     0x24 /* SXFR_STATUS Transfer Phase Error */
3338 #define QHSTA_M_SXFR_UNKNOWN_ERROR  0x25 /* SXFR_STATUS Unknown Error */
3339 #define QHSTA_M_SCSI_BUS_RESET      0x30 /* Request aborted from SBR */
3340 #define QHSTA_M_SCSI_BUS_RESET_UNSOL 0x31 /* Request aborted from unsol. SBR */
3341 #define QHSTA_M_BUS_DEVICE_RESET    0x32 /* Request aborted from BDR */
3342 #define QHSTA_M_DIRECTION_ERR       0x35 /* Data Phase mismatch */
3343 #define QHSTA_M_DIRECTION_ERR_HUNG  0x36 /* Data Phase mismatch and bus hang */
3344 #define QHSTA_M_WTM_TIMEOUT         0x41
3345 #define QHSTA_M_BAD_CMPL_STATUS_IN  0x42
3346 #define QHSTA_M_NO_AUTO_REQ_SENSE   0x43
3347 #define QHSTA_M_AUTO_REQ_SENSE_FAIL 0x44
3348 #define QHSTA_M_INVALID_DEVICE      0x45 /* Bad target ID */
3349 #define QHSTA_M_FROZEN_TIDQ         0x46 /* TID Queue frozen. */
3350 #define QHSTA_M_SGBACKUP_ERROR      0x47 /* Scatter-Gather backup error */
3351
3352
3353 /*
3354  * Default EEPROM Configuration structure defined in a_init.c.
3355  */
3356 static ADVEEP_3550_CONFIG Default_3550_EEPROM_Config;
3357 static ADVEEP_38C0800_CONFIG Default_38C0800_EEPROM_Config;
3358 static ADVEEP_38C1600_CONFIG Default_38C1600_EEPROM_Config;
3359
3360 /*
3361  * DvcGetPhyAddr() flag arguments
3362  */
3363 #define ADV_IS_SCSIQ_FLAG       0x01 /* 'addr' is ASC_SCSI_REQ_Q pointer */
3364 #define ADV_ASCGETSGLIST_VADDR  0x02 /* 'addr' is AscGetSGList() virtual addr */
3365 #define ADV_IS_SENSE_FLAG       0x04 /* 'addr' is sense virtual pointer */
3366 #define ADV_IS_DATA_FLAG        0x08 /* 'addr' is data virtual pointer */
3367 #define ADV_IS_SGLIST_FLAG      0x10 /* 'addr' is sglist virtual pointer */
3368 #define ADV_IS_CARRIER_FLAG     0x20 /* 'addr' is ADV_CARR_T pointer */
3369
3370 /* Return the address that is aligned at the next doubleword >= to 'addr'. */
3371 #define ADV_8BALIGN(addr)      (((ulong) (addr) + 0x7) & ~0x7)
3372 #define ADV_16BALIGN(addr)     (((ulong) (addr) + 0xF) & ~0xF)
3373 #define ADV_32BALIGN(addr)     (((ulong) (addr) + 0x1F) & ~0x1F)
3374
3375 /*
3376  * Total contiguous memory needed for driver SG blocks.
3377  *
3378  * ADV_MAX_SG_LIST must be defined by a driver. It is the maximum
3379  * number of scatter-gather elements the driver supports in a
3380  * single request.
3381  */
3382
3383 #define ADV_SG_LIST_MAX_BYTE_SIZE \
3384          (sizeof(ADV_SG_BLOCK) * \
3385           ((ADV_MAX_SG_LIST + (NO_OF_SG_PER_BLOCK - 1))/NO_OF_SG_PER_BLOCK))
3386
3387 /*
3388  * Inquiry data structure and bitfield macros
3389  *
3390  * Using bitfields to access the subchar data isn't portable across
3391  * endianness, so instead mask and shift. Only quantities of more
3392  * than 1 bit are shifted, since the others are just tested for true
3393  * or false.
3394  */
3395
3396 #define ADV_INQ_DVC_TYPE(inq)       ((inq)->periph & 0x1f)
3397 #define ADV_INQ_QUALIFIER(inq)      (((inq)->periph & 0xe0) >> 5)
3398 #define ADV_INQ_DVC_TYPE_MOD(inq)   ((inq)->devtype & 0x7f)
3399 #define ADV_INQ_REMOVABLE(inq)      ((inq)->devtype & 0x80)
3400 #define ADV_INQ_ANSI_VER(inq)       ((inq)->ver & 0x07)
3401 #define ADV_INQ_ECMA_VER(inq)       (((inq)->ver & 0x38) >> 3)
3402 #define ADV_INQ_ISO_VER(inq)        (((inq)->ver & 0xc0) >> 6)
3403 #define ADV_INQ_RESPONSE_FMT(inq)   ((inq)->byte3 & 0x0f)
3404 #define ADV_INQ_TERM_IO(inq)        ((inq)->byte3 & 0x40)
3405 #define ADV_INQ_ASYNC_NOTIF(inq)    ((inq)->byte3 & 0x80)
3406 #define ADV_INQ_SOFT_RESET(inq)     ((inq)->flags & 0x01)
3407 #define ADV_INQ_CMD_QUEUE(inq)      ((inq)->flags & 0x02)
3408 #define ADV_INQ_LINK_CMD(inq)       ((inq)->flags & 0x08)
3409 #define ADV_INQ_SYNC(inq)           ((inq)->flags & 0x10)
3410 #define ADV_INQ_WIDE16(inq)         ((inq)->flags & 0x20)
3411 #define ADV_INQ_WIDE32(inq)         ((inq)->flags & 0x40)
3412 #define ADV_INQ_REL_ADDR(inq)       ((inq)->flags & 0x80)
3413 #define ADV_INQ_INFO_UNIT(inq)      ((inq)->info & 0x01)
3414 #define ADV_INQ_QUICK_ARB(inq)      ((inq)->info & 0x02)
3415 #define ADV_INQ_CLOCKING(inq)       (((inq)->info & 0x0c) >> 2)
3416
3417 typedef struct {
3418   uchar periph;                 /* peripheral device type [0:4] */
3419                                 /* peripheral qualifier [5:7] */
3420   uchar devtype;                /* device type modifier (for SCSI I) [0:6] */
3421                                 /* RMB - removable medium bit [7] */
3422   uchar ver;                    /* ANSI approved version [0:2] */
3423                                 /* ECMA version [3:5] */
3424                                 /* ISO version [6:7] */
3425   uchar byte3;                  /* response data format [0:3] */
3426                                 /* 0 SCSI 1 */
3427                                 /* 1 CCS */
3428                                 /* 2 SCSI-2 */
3429                                 /* 3-F reserved */
3430                                 /* reserved [4:5] */
3431                                 /* terminate I/O process bit (see 5.6.22) [6] */
3432                                 /* asynch. event notification (processor) [7] */
3433   uchar add_len;                /* additional length */
3434   uchar res1;                   /* reserved */
3435   uchar res2;                   /* reserved */
3436   uchar flags;                  /* soft reset implemented [0] */
3437                                 /* command queuing [1] */
3438                                 /* reserved [2] */
3439                                 /* linked command for this logical unit [3] */
3440                                 /* synchronous data transfer [4] */
3441                                 /* wide bus 16 bit data transfer [5] */
3442                                 /* wide bus 32 bit data transfer [6] */
3443                                 /* relative addressing mode [7] */
3444   uchar vendor_id[8];           /* vendor identification */
3445   uchar product_id[16];         /* product identification */
3446   uchar product_rev_level[4];   /* product revision level */
3447   uchar vendor_specific[20];    /* vendor specific */
3448   uchar info;                   /* information unit supported [0] */
3449                                 /* quick arbitrate supported [1] */
3450                                 /* clocking field [2:3] */
3451                                 /* reserved [4:7] */
3452   uchar res3;                   /* reserved */
3453 } ADV_SCSI_INQUIRY; /* 58 bytes */
3454
3455
3456 /*
3457  * --- Driver Constants and Macros
3458  */
3459
3460 #define ASC_NUM_BOARD_SUPPORTED 16
3461 #define ASC_NUM_IOPORT_PROBE    4
3462 #define ASC_NUM_BUS             4
3463
3464 /* Reference Scsi_Host hostdata */
3465 #define ASC_BOARDP(host) ((asc_board_t *) &((host)->hostdata))
3466
3467 /* asc_board_t flags */
3468 #define ASC_HOST_IN_RESET       0x01
3469 #define ASC_IS_WIDE_BOARD       0x04    /* AdvanSys Wide Board */
3470 #define ASC_SELECT_QUEUE_DEPTHS 0x08
3471
3472 #define ASC_NARROW_BOARD(boardp) (((boardp)->flags & ASC_IS_WIDE_BOARD) == 0)
3473 #define ASC_WIDE_BOARD(boardp)   ((boardp)->flags & ASC_IS_WIDE_BOARD)
3474
3475 #define NO_ISA_DMA              0xff        /* No ISA DMA Channel Used */
3476
3477 #define ASC_INFO_SIZE           128            /* advansys_info() line size */
3478
3479 #ifdef CONFIG_PROC_FS
3480 /* /proc/scsi/advansys/[0...] related definitions */
3481 #define ASC_PRTBUF_SIZE         2048
3482 #define ASC_PRTLINE_SIZE        160
3483
3484 #define ASC_PRT_NEXT() \
3485     if (cp) { \
3486         totlen += len; \
3487         leftlen -= len; \
3488         if (leftlen == 0) { \
3489             return totlen; \
3490         } \
3491         cp += len; \
3492     }
3493 #endif /* CONFIG_PROC_FS */
3494
3495 /* Asc Library return codes */
3496 #define ASC_TRUE        1
3497 #define ASC_FALSE       0
3498 #define ASC_NOERROR     1
3499 #define ASC_BUSY        0
3500 #define ASC_ERROR       (-1)
3501
3502 /* struct scsi_cmnd function return codes */
3503 #define STATUS_BYTE(byte)   (byte)
3504 #define MSG_BYTE(byte)      ((byte) << 8)
3505 #define HOST_BYTE(byte)     ((byte) << 16)
3506 #define DRIVER_BYTE(byte)   ((byte) << 24)
3507
3508 /*
3509  * The following definitions and macros are OS independent interfaces to
3510  * the queue functions:
3511  *  REQ - SCSI request structure
3512  *  REQP - pointer to SCSI request structure
3513  *  REQPTID(reqp) - reqp's target id
3514  *  REQPNEXT(reqp) - reqp's next pointer
3515  *  REQPNEXTP(reqp) - pointer to reqp's next pointer
3516  *  REQPTIME(reqp) - reqp's time stamp value
3517  *  REQTIMESTAMP() - system time stamp value
3518  */
3519 typedef struct scsi_cmnd     REQ, *REQP;
3520 #define REQPNEXT(reqp)       ((REQP) ((reqp)->host_scribble))
3521 #define REQPNEXTP(reqp)      ((REQP *) &((reqp)->host_scribble))
3522 #define REQPTID(reqp)        ((reqp)->device->id)
3523 #define REQPTIME(reqp)       ((reqp)->SCp.this_residual)
3524 #define REQTIMESTAMP()       (jiffies)
3525
3526 #define REQTIMESTAT(function, ascq, reqp, tid) \
3527 { \
3528     /*
3529      * If the request time stamp is less than the system time stamp, then \
3530      * maybe the system time stamp wrapped. Set the request time to zero.\
3531      */ \
3532     if (REQPTIME(reqp) <= REQTIMESTAMP()) { \
3533         REQPTIME(reqp) = REQTIMESTAMP() - REQPTIME(reqp); \
3534     } else { \
3535         /* Indicate an error occurred with the assertion. */ \
3536         ASC_ASSERT(REQPTIME(reqp) <= REQTIMESTAMP()); \
3537         REQPTIME(reqp) = 0; \
3538     } \
3539     /* Handle first minimum time case without external initialization. */ \
3540     if (((ascq)->q_tot_cnt[tid] == 1) ||  \
3541         (REQPTIME(reqp) < (ascq)->q_min_tim[tid])) { \
3542             (ascq)->q_min_tim[tid] = REQPTIME(reqp); \
3543             ASC_DBG3(1, "%s: new q_min_tim[%d] %u\n", \
3544                 (function), (tid), (ascq)->q_min_tim[tid]); \
3545         } \
3546     if (REQPTIME(reqp) > (ascq)->q_max_tim[tid]) { \
3547         (ascq)->q_max_tim[tid] = REQPTIME(reqp); \
3548         ASC_DBG3(1, "%s: new q_max_tim[%d] %u\n", \
3549             (function), tid, (ascq)->q_max_tim[tid]); \
3550     } \
3551     (ascq)->q_tot_tim[tid] += REQPTIME(reqp); \
3552     /* Reset the time stamp field. */ \
3553     REQPTIME(reqp) = 0; \
3554 }
3555
3556 /* asc_enqueue() flags */
3557 #define ASC_FRONT       1
3558 #define ASC_BACK        2
3559
3560 /* asc_dequeue_list() argument */
3561 #define ASC_TID_ALL        (-1)
3562
3563 /* Return non-zero, if the queue is empty. */
3564 #define ASC_QUEUE_EMPTY(ascq)    ((ascq)->q_tidmask == 0)
3565
3566 #define PCI_MAX_SLOT            0x1F
3567 #define PCI_MAX_BUS             0xFF
3568 #define PCI_IOADDRESS_MASK      0xFFFE
3569 #define ASC_PCI_DEVICE_ID_CNT   6       /* PCI Device ID count. */
3570
3571 #ifndef ADVANSYS_STATS
3572 #define ASC_STATS(shp, counter)
3573 #define ASC_STATS_ADD(shp, counter, count)
3574 #else /* ADVANSYS_STATS */
3575 #define ASC_STATS(shp, counter) \
3576     (ASC_BOARDP(shp)->asc_stats.counter++)
3577
3578 #define ASC_STATS_ADD(shp, counter, count) \
3579     (ASC_BOARDP(shp)->asc_stats.counter += (count))
3580 #endif /* ADVANSYS_STATS */
3581
3582 #define ASC_CEILING(val, unit) (((val) + ((unit) - 1))/(unit))
3583
3584 /* If the result wraps when calculating tenths, return 0. */
3585 #define ASC_TENTHS(num, den) \
3586     (((10 * ((num)/(den))) > (((num) * 10)/(den))) ? \
3587     0 : ((((num) * 10)/(den)) - (10 * ((num)/(den)))))
3588
3589 /*
3590  * Display a message to the console.
3591  */
3592 #define ASC_PRINT(s) \
3593     { \
3594         printk("advansys: "); \
3595         printk(s); \
3596     }
3597
3598 #define ASC_PRINT1(s, a1) \
3599     { \
3600         printk("advansys: "); \
3601         printk((s), (a1)); \
3602     }
3603
3604 #define ASC_PRINT2(s, a1, a2) \
3605     { \
3606         printk("advansys: "); \
3607         printk((s), (a1), (a2)); \
3608     }
3609
3610 #define ASC_PRINT3(s, a1, a2, a3) \
3611     { \
3612         printk("advansys: "); \
3613         printk((s), (a1), (a2), (a3)); \
3614     }
3615
3616 #define ASC_PRINT4(s, a1, a2, a3, a4) \
3617     { \
3618         printk("advansys: "); \
3619         printk((s), (a1), (a2), (a3), (a4)); \
3620     }
3621
3622
3623 #ifndef ADVANSYS_DEBUG
3624
3625 #define ASC_DBG(lvl, s)
3626 #define ASC_DBG1(lvl, s, a1)
3627 #define ASC_DBG2(lvl, s, a1, a2)
3628 #define ASC_DBG3(lvl, s, a1, a2, a3)
3629 #define ASC_DBG4(lvl, s, a1, a2, a3, a4)
3630 #define ASC_DBG_PRT_SCSI_HOST(lvl, s)
3631 #define ASC_DBG_PRT_SCSI_CMND(lvl, s)
3632 #define ASC_DBG_PRT_ASC_SCSI_Q(lvl, scsiqp)
3633 #define ASC_DBG_PRT_ADV_SCSI_REQ_Q(lvl, scsiqp)
3634 #define ASC_DBG_PRT_ASC_QDONE_INFO(lvl, qdone)
3635 #define ADV_DBG_PRT_ADV_SCSI_REQ_Q(lvl, scsiqp)
3636 #define ASC_DBG_PRT_HEX(lvl, name, start, length)
3637 #define ASC_DBG_PRT_CDB(lvl, cdb, len)
3638 #define ASC_DBG_PRT_SENSE(lvl, sense, len)
3639 #define ASC_DBG_PRT_INQUIRY(lvl, inq, len)
3640
3641 #else /* ADVANSYS_DEBUG */
3642
3643 /*
3644  * Debugging Message Levels:
3645  * 0: Errors Only
3646  * 1: High-Level Tracing
3647  * 2-N: Verbose Tracing
3648  */
3649
3650 #define ASC_DBG(lvl, s) \
3651     { \
3652         if (asc_dbglvl >= (lvl)) { \
3653             printk(s); \
3654         } \
3655     }
3656
3657 #define ASC_DBG1(lvl, s, a1) \
3658     { \
3659         if (asc_dbglvl >= (lvl)) { \
3660             printk((s), (a1)); \
3661         } \
3662     }
3663
3664 #define ASC_DBG2(lvl, s, a1, a2) \
3665     { \
3666         if (asc_dbglvl >= (lvl)) { \
3667             printk((s), (a1), (a2)); \
3668         } \
3669     }
3670
3671 #define ASC_DBG3(lvl, s, a1, a2, a3) \
3672     { \
3673         if (asc_dbglvl >= (lvl)) { \
3674             printk((s), (a1), (a2), (a3)); \
3675         } \
3676     }
3677
3678 #define ASC_DBG4(lvl, s, a1, a2, a3, a4) \
3679     { \
3680         if (asc_dbglvl >= (lvl)) { \
3681             printk((s), (a1), (a2), (a3), (a4)); \
3682         } \
3683     }
3684
3685 #define ASC_DBG_PRT_SCSI_HOST(lvl, s) \
3686     { \
3687         if (asc_dbglvl >= (lvl)) { \
3688             asc_prt_scsi_host(s); \
3689         } \
3690     }
3691
3692 #define ASC_DBG_PRT_SCSI_CMND(lvl, s) \
3693     { \
3694         if (asc_dbglvl >= (lvl)) { \
3695             asc_prt_scsi_cmnd(s); \
3696         } \
3697     }
3698
3699 #define ASC_DBG_PRT_ASC_SCSI_Q(lvl, scsiqp) \
3700     { \
3701         if (asc_dbglvl >= (lvl)) { \
3702             asc_prt_asc_scsi_q(scsiqp); \
3703         } \
3704     }
3705
3706 #define ASC_DBG_PRT_ASC_QDONE_INFO(lvl, qdone) \
3707     { \
3708         if (asc_dbglvl >= (lvl)) { \
3709             asc_prt_asc_qdone_info(qdone); \
3710         } \
3711     }
3712
3713 #define ASC_DBG_PRT_ADV_SCSI_REQ_Q(lvl, scsiqp) \
3714     { \
3715         if (asc_dbglvl >= (lvl)) { \
3716             asc_prt_adv_scsi_req_q(scsiqp); \
3717         } \
3718     }
3719
3720 #define ASC_DBG_PRT_HEX(lvl, name, start, length) \
3721     { \
3722         if (asc_dbglvl >= (lvl)) { \
3723             asc_prt_hex((name), (start), (length)); \
3724         } \
3725     }
3726
3727 #define ASC_DBG_PRT_CDB(lvl, cdb, len) \
3728         ASC_DBG_PRT_HEX((lvl), "CDB", (uchar *) (cdb), (len));
3729
3730 #define ASC_DBG_PRT_SENSE(lvl, sense, len) \
3731         ASC_DBG_PRT_HEX((lvl), "SENSE", (uchar *) (sense), (len));
3732
3733 #define ASC_DBG_PRT_INQUIRY(lvl, inq, len) \
3734         ASC_DBG_PRT_HEX((lvl), "INQUIRY", (uchar *) (inq), (len));
3735 #endif /* ADVANSYS_DEBUG */
3736
3737 #ifndef ADVANSYS_ASSERT
3738 #define ASC_ASSERT(a)
3739 #else /* ADVANSYS_ASSERT */
3740
3741 #define ASC_ASSERT(a) \
3742     { \
3743         if (!(a)) { \
3744             printk("ASC_ASSERT() Failure: file %s, line %d\n", \
3745                 __FILE__, __LINE__); \
3746         } \
3747     }
3748
3749 #endif /* ADVANSYS_ASSERT */
3750
3751
3752 /*
3753  * --- Driver Structures
3754  */
3755
3756 #ifdef ADVANSYS_STATS
3757
3758 /* Per board statistics structure */
3759 struct asc_stats {
3760     /* Driver Entrypoint Statistics */
3761     ADV_DCNT queuecommand;    /* # calls to advansys_queuecommand() */
3762     ADV_DCNT reset;           /* # calls to advansys_eh_bus_reset() */
3763     ADV_DCNT biosparam;       /* # calls to advansys_biosparam() */
3764     ADV_DCNT interrupt;       /* # advansys_interrupt() calls */
3765     ADV_DCNT callback;        /* # calls to asc/adv_isr_callback() */
3766     ADV_DCNT done;            /* # calls to request's scsi_done function */
3767     ADV_DCNT build_error;     /* # asc/adv_build_req() ASC_ERROR returns. */
3768     ADV_DCNT adv_build_noreq; /* # adv_build_req() adv_req_t alloc. fail. */
3769     ADV_DCNT adv_build_nosg;  /* # adv_build_req() adv_sgblk_t alloc. fail. */
3770     /* AscExeScsiQueue()/AdvExeScsiQueue() Statistics */
3771     ADV_DCNT exe_noerror;     /* # ASC_NOERROR returns. */
3772     ADV_DCNT exe_busy;        /* # ASC_BUSY returns. */
3773     ADV_DCNT exe_error;       /* # ASC_ERROR returns. */
3774     ADV_DCNT exe_unknown;     /* # unknown returns. */
3775     /* Data Transfer Statistics */
3776     ADV_DCNT cont_cnt;        /* # non-scatter-gather I/O requests received */
3777     ADV_DCNT cont_xfer;       /* # contiguous transfer 512-bytes */
3778     ADV_DCNT sg_cnt;          /* # scatter-gather I/O requests received */
3779     ADV_DCNT sg_elem;         /* # scatter-gather elements */
3780     ADV_DCNT sg_xfer;         /* # scatter-gather transfer 512-bytes */
3781 };
3782 #endif /* ADVANSYS_STATS */
3783
3784 /*
3785  * Request queuing structure
3786  */
3787 typedef struct asc_queue {
3788     ADV_SCSI_BIT_ID_TYPE  q_tidmask;                /* queue mask */
3789     REQP                  q_first[ADV_MAX_TID+1];   /* first queued request */
3790     REQP                  q_last[ADV_MAX_TID+1];    /* last queued request */
3791 #ifdef ADVANSYS_STATS
3792     short                 q_cur_cnt[ADV_MAX_TID+1]; /* current queue count */
3793     short                 q_max_cnt[ADV_MAX_TID+1]; /* maximum queue count */
3794     ADV_DCNT              q_tot_cnt[ADV_MAX_TID+1]; /* total enqueue count */
3795     ADV_DCNT              q_tot_tim[ADV_MAX_TID+1]; /* total time queued */
3796     ushort                q_max_tim[ADV_MAX_TID+1]; /* maximum time queued */
3797     ushort                q_min_tim[ADV_MAX_TID+1]; /* minimum time queued */
3798 #endif /* ADVANSYS_STATS */
3799 } asc_queue_t;
3800
3801 /*
3802  * Adv Library Request Structures
3803  *
3804  * The following two structures are used to process Wide Board requests.
3805  *
3806  * The ADV_SCSI_REQ_Q structure in adv_req_t is passed to the Adv Library
3807  * and microcode with the ADV_SCSI_REQ_Q field 'srb_ptr' pointing to the
3808  * adv_req_t. The adv_req_t structure 'cmndp' field in turn points to the
3809  * Mid-Level SCSI request structure.
3810  *
3811  * Zero or more ADV_SG_BLOCK are used with each ADV_SCSI_REQ_Q. Each
3812  * ADV_SG_BLOCK structure holds 15 scatter-gather elements. Under Linux
3813  * up to 255 scatter-gather elements may be used per request or
3814  * ADV_SCSI_REQ_Q.
3815  *
3816  * Both structures must be 32 byte aligned.
3817  */
3818 typedef struct adv_sgblk {
3819     ADV_SG_BLOCK        sg_block;     /* Sgblock structure. */
3820     uchar               align[32];    /* Sgblock structure padding. */
3821     struct adv_sgblk    *next_sgblkp; /* Next scatter-gather structure. */
3822 } adv_sgblk_t;
3823
3824 typedef struct adv_req {
3825     ADV_SCSI_REQ_Q      scsi_req_q;   /* Adv Library request structure. */
3826     uchar               align[32];    /* Request structure padding. */
3827     struct scsi_cmnd    *cmndp;       /* Mid-Level SCSI command pointer. */
3828     adv_sgblk_t         *sgblkp;      /* Adv Library scatter-gather pointer. */
3829     struct adv_req      *next_reqp;   /* Next Request Structure. */
3830 } adv_req_t;
3831
3832 /*
3833  * Structure allocated for each board.
3834  *
3835  * This structure is allocated by scsi_register() at the end
3836  * of the 'Scsi_Host' structure starting at the 'hostdata'
3837  * field. It is guaranteed to be allocated from DMA-able memory.
3838  */
3839 typedef struct asc_board {
3840     int                  id;                    /* Board Id */
3841     uint                 flags;                 /* Board flags */
3842     union {
3843         ASC_DVC_VAR      asc_dvc_var;           /* Narrow board */
3844         ADV_DVC_VAR      adv_dvc_var;           /* Wide board */
3845     } dvc_var;
3846     union {
3847         ASC_DVC_CFG      asc_dvc_cfg;           /* Narrow board */
3848         ADV_DVC_CFG      adv_dvc_cfg;           /* Wide board */
3849     } dvc_cfg;
3850     ushort               asc_n_io_port;         /* Number I/O ports. */
3851     asc_queue_t          active;                /* Active command queue */
3852     asc_queue_t          waiting;               /* Waiting command queue */
3853     asc_queue_t          done;                  /* Done command queue */
3854     ADV_SCSI_BIT_ID_TYPE init_tidmask;          /* Target init./valid mask */
3855     struct scsi_device  *device[ADV_MAX_TID+1]; /* Mid-Level Scsi Device */
3856     ushort               reqcnt[ADV_MAX_TID+1]; /* Starvation request count */
3857     ADV_SCSI_BIT_ID_TYPE queue_full;            /* Queue full mask */
3858     ushort               queue_full_cnt[ADV_MAX_TID+1]; /* Queue full count */
3859     union {
3860         ASCEEP_CONFIG         asc_eep;          /* Narrow EEPROM config. */
3861         ADVEEP_3550_CONFIG    adv_3550_eep;     /* 3550 EEPROM config. */
3862         ADVEEP_38C0800_CONFIG adv_38C0800_eep;  /* 38C0800 EEPROM config. */
3863         ADVEEP_38C1600_CONFIG adv_38C1600_eep;  /* 38C1600 EEPROM config. */
3864     } eep_config;
3865     ulong                last_reset;            /* Saved last reset time */
3866     spinlock_t lock;                            /* Board spinlock */
3867 #ifdef CONFIG_PROC_FS
3868     /* /proc/scsi/advansys/[0...] */
3869     char                 *prtbuf;               /* /proc print buffer */
3870 #endif /* CONFIG_PROC_FS */
3871 #ifdef ADVANSYS_STATS
3872     struct asc_stats     asc_stats;             /* Board statistics */
3873 #endif /* ADVANSYS_STATS */
3874     /*
3875      * The following fields are used only for Narrow Boards.
3876      */
3877     /* The following three structures must be in DMA-able memory. */
3878     ASC_SCSI_REQ_Q       scsireqq;
3879     ASC_CAP_INFO         cap_info;
3880     ASC_SCSI_INQUIRY     inquiry;
3881     uchar                sdtr_data[ASC_MAX_TID+1]; /* SDTR information */
3882     /*
3883      * The following fields are used only for Wide Boards.
3884      */
3885     void                 *ioremap_addr;         /* I/O Memory remap address. */
3886     ushort               ioport;                /* I/O Port address. */
3887     ADV_CARR_T           *orig_carrp;           /* ADV_CARR_T memory block. */
3888     adv_req_t            *orig_reqp;            /* adv_req_t memory block. */
3889     adv_req_t            *adv_reqp;             /* Request structures. */
3890     adv_sgblk_t          *adv_sgblkp;           /* Scatter-gather structures. */
3891     ushort               bios_signature;        /* BIOS Signature. */
3892     ushort               bios_version;          /* BIOS Version. */
3893     ushort               bios_codeseg;          /* BIOS Code Segment. */
3894     ushort               bios_codelen;          /* BIOS Code Segment Length. */
3895 } asc_board_t;
3896
3897 /*
3898  * PCI configuration structures
3899  */
3900 typedef struct _PCI_DATA_
3901 {
3902     uchar    type;
3903     uchar    bus;
3904     uchar    slot;
3905     uchar    func;
3906     uchar    offset;
3907 } PCI_DATA;
3908
3909 typedef struct _PCI_DEVICE_
3910 {
3911     ushort   vendorID;
3912     ushort   deviceID;
3913     ushort   slotNumber;
3914     ushort   slotFound;
3915     uchar    busNumber;
3916     uchar    maxBusNumber;
3917     uchar    devFunc;
3918     ushort   startSlot;
3919     ushort   endSlot;
3920     uchar    bridge;
3921     uchar    type;
3922 } PCI_DEVICE;
3923
3924 typedef struct _PCI_CONFIG_SPACE_
3925 {
3926     ushort   vendorID;
3927     ushort   deviceID;
3928     ushort   command;
3929     ushort   status;
3930     uchar    revision;
3931     uchar    classCode[3];
3932     uchar    cacheSize;
3933     uchar    latencyTimer;
3934     uchar    headerType;
3935     uchar    bist;
3936     ADV_PADDR baseAddress[6];
3937     ushort   reserved[4];
3938     ADV_PADDR optionRomAddr;
3939     ushort   reserved2[4];
3940     uchar    irqLine;
3941     uchar    irqPin;
3942     uchar    minGnt;
3943     uchar    maxLatency;
3944 } PCI_CONFIG_SPACE;
3945
3946
3947 /*
3948  * --- Driver Data
3949  */
3950
3951 /* Note: All driver global data should be initialized. */
3952
3953 /* Number of boards detected in system. */
3954 STATIC int asc_board_count = 0;
3955 STATIC struct Scsi_Host    *asc_host[ASC_NUM_BOARD_SUPPORTED] = { 0 };
3956
3957 /* Overrun buffer used by all narrow boards. */
3958 STATIC uchar overrun_buf[ASC_OVERRUN_BSIZE] = { 0 };
3959
3960 /*
3961  * Global structures required to issue a command.
3962  */
3963 STATIC ASC_SCSI_Q asc_scsi_q = { { 0 } };
3964 STATIC ASC_SG_HEAD asc_sg_head = { 0 };
3965
3966 /* List of supported bus types. */
3967 STATIC ushort asc_bus[ASC_NUM_BUS] __initdata = {
3968     ASC_IS_ISA,
3969     ASC_IS_VL,
3970     ASC_IS_EISA,
3971     ASC_IS_PCI,
3972 };
3973
3974 /*
3975  * Used with the LILO 'advansys' option to eliminate or
3976  * limit I/O port probing at boot time, cf. advansys_setup().
3977  */
3978 STATIC int asc_iopflag = ASC_FALSE;
3979 STATIC int asc_ioport[ASC_NUM_IOPORT_PROBE] = { 0, 0, 0, 0 };
3980
3981 #ifdef ADVANSYS_DEBUG
3982 STATIC char *
3983 asc_bus_name[ASC_NUM_BUS] = {
3984     "ASC_IS_ISA",
3985     "ASC_IS_VL",
3986     "ASC_IS_EISA",
3987     "ASC_IS_PCI",
3988 };
3989
3990 STATIC int          asc_dbglvl = 3;
3991 #endif /* ADVANSYS_DEBUG */
3992
3993 /* Declaration for Asc Library internal data referenced by driver. */
3994 STATIC PortAddr     _asc_def_iop_base[];
3995
3996
3997 /*
3998  * --- Driver Function Prototypes
3999  *
4000  * advansys.h contains function prototypes for functions global to Linux.
4001  */
4002
4003 STATIC irqreturn_t advansys_interrupt(int, void *, struct pt_regs *);
4004 STATIC int        advansys_slave_configure(struct scsi_device *);
4005 STATIC void       asc_scsi_done_list(struct scsi_cmnd *);
4006 STATIC int        asc_execute_scsi_cmnd(struct scsi_cmnd *);
4007 STATIC int        asc_build_req(asc_board_t *, struct scsi_cmnd *);
4008 STATIC int        adv_build_req(asc_board_t *, struct scsi_cmnd *, ADV_SCSI_REQ_Q **);
4009 STATIC int        adv_get_sglist(asc_board_t *, adv_req_t *, struct scsi_cmnd *, int);
4010 STATIC void       asc_isr_callback(ASC_DVC_VAR *, ASC_QDONE_INFO *);
4011 STATIC void       adv_isr_callback(ADV_DVC_VAR *, ADV_SCSI_REQ_Q *);
4012 STATIC void       adv_async_callback(ADV_DVC_VAR *, uchar);
4013 STATIC void       asc_enqueue(asc_queue_t *, REQP, int);
4014 STATIC REQP       asc_dequeue(asc_queue_t *, int);
4015 STATIC REQP       asc_dequeue_list(asc_queue_t *, REQP *, int);
4016 STATIC int        asc_rmqueue(asc_queue_t *, REQP);
4017 STATIC void       asc_execute_queue(asc_queue_t *);
4018 #ifdef CONFIG_PROC_FS
4019 STATIC int        asc_proc_copy(off_t, off_t, char *, int , char *, int);
4020 STATIC int        asc_prt_board_devices(struct Scsi_Host *, char *, int);
4021 STATIC int        asc_prt_adv_bios(struct Scsi_Host *, char *, int);
4022 STATIC int        asc_get_eeprom_string(ushort *serialnum, uchar *cp);
4023 STATIC int        asc_prt_asc_board_eeprom(struct Scsi_Host *, char *, int);
4024 STATIC int        asc_prt_adv_board_eeprom(struct Scsi_Host *, char *, int);
4025 STATIC int        asc_prt_driver_conf(struct Scsi_Host *, char *, int);
4026 STATIC int        asc_prt_asc_board_info(struct Scsi_Host *, char *, int);
4027 STATIC int        asc_prt_adv_board_info(struct Scsi_Host *, char *, int);
4028 STATIC int        asc_prt_line(char *, int, char *fmt, ...);
4029 #endif /* CONFIG_PROC_FS */
4030
4031 /* Declaration for Asc Library internal functions referenced by driver. */
4032 STATIC int          AscFindSignature(PortAddr);
4033 STATIC ushort       AscGetEEPConfig(PortAddr, ASCEEP_CONFIG *, ushort);
4034
4035 /* Statistics function prototypes. */
4036 #ifdef ADVANSYS_STATS
4037 #ifdef CONFIG_PROC_FS
4038 STATIC int          asc_prt_board_stats(struct Scsi_Host *, char *, int);
4039 STATIC int          asc_prt_target_stats(struct Scsi_Host *, int, char *, int);
4040 #endif /* CONFIG_PROC_FS */
4041 #endif /* ADVANSYS_STATS */
4042
4043 /* Debug function prototypes. */
4044 #ifdef ADVANSYS_DEBUG
4045 STATIC void         asc_prt_scsi_host(struct Scsi_Host *);
4046 STATIC void         asc_prt_scsi_cmnd(struct scsi_cmnd *);
4047 STATIC void         asc_prt_asc_dvc_cfg(ASC_DVC_CFG *);
4048 STATIC void         asc_prt_asc_dvc_var(ASC_DVC_VAR *);
4049 STATIC void         asc_prt_asc_scsi_q(ASC_SCSI_Q *);
4050 STATIC void         asc_prt_asc_qdone_info(ASC_QDONE_INFO *);
4051 STATIC void         asc_prt_adv_dvc_cfg(ADV_DVC_CFG *);
4052 STATIC void         asc_prt_adv_dvc_var(ADV_DVC_VAR *);
4053 STATIC void         asc_prt_adv_scsi_req_q(ADV_SCSI_REQ_Q *);
4054 STATIC void         asc_prt_adv_sgblock(int, ADV_SG_BLOCK *);
4055 STATIC void         asc_prt_hex(char *f, uchar *, int);
4056 #endif /* ADVANSYS_DEBUG */
4057
4058
4059 /*
4060  * --- Linux 'struct scsi_host_template' and advansys_setup() Functions
4061  */
4062
4063 #ifdef CONFIG_PROC_FS
4064 /*
4065  * advansys_proc_info() - /proc/scsi/advansys/[0-(ASC_NUM_BOARD_SUPPORTED-1)]
4066  *
4067  * *buffer: I/O buffer
4068  * **start: if inout == FALSE pointer into buffer where user read should start
4069  * offset: current offset into a /proc/scsi/advansys/[0...] file
4070  * length: length of buffer
4071  * hostno: Scsi_Host host_no
4072  * inout: TRUE - user is writing; FALSE - user is reading
4073  *
4074  * Return the number of bytes read from or written to a
4075  * /proc/scsi/advansys/[0...] file.
4076  *
4077  * Note: This function uses the per board buffer 'prtbuf' which is
4078  * allocated when the board is initialized in advansys_detect(). The
4079  * buffer is ASC_PRTBUF_SIZE bytes. The function asc_proc_copy() is
4080  * used to write to the buffer. The way asc_proc_copy() is written
4081  * if 'prtbuf' is too small it will not be overwritten. Instead the
4082  * user just won't get all the available statistics.
4083  */
4084 int
4085 advansys_proc_info(struct Scsi_Host *shost, char *buffer, char **start,
4086                 off_t offset, int length, int inout)
4087 {
4088     struct Scsi_Host    *shp;
4089     asc_board_t         *boardp;
4090     int                 i;
4091     char                *cp;
4092     int                 cplen;
4093     int                 cnt;
4094     int                 totcnt;
4095     int                 leftlen;
4096     char                *curbuf;
4097     off_t               advoffset;
4098 #ifdef ADVANSYS_STATS
4099     int                 tgt_id;
4100 #endif /* ADVANSYS_STATS */
4101
4102     ASC_DBG(1, "advansys_proc_info: begin\n");
4103
4104     /*
4105      * User write not supported.
4106      */
4107     if (inout == TRUE) {
4108         return(-ENOSYS);
4109     }
4110
4111     /*
4112      * User read of /proc/scsi/advansys/[0...] file.
4113      */
4114
4115     /* Find the specified board. */
4116     for (i = 0; i < asc_board_count; i++) {
4117         if (asc_host[i]->host_no == shost->host_no) {
4118             break;
4119         }
4120     }
4121     if (i == asc_board_count) {
4122         return(-ENOENT);
4123     }
4124
4125     shp = asc_host[i];
4126     boardp = ASC_BOARDP(shp);
4127
4128     /* Copy read data starting at the beginning of the buffer. */
4129     *start = buffer;
4130     curbuf = buffer;
4131     advoffset = 0;
4132     totcnt = 0;
4133     leftlen = length;
4134
4135     /*
4136      * Get board configuration information.
4137      *
4138      * advansys_info() returns the board string from its own static buffer.
4139      */
4140     cp = (char *) advansys_info(shp);
4141     strcat(cp, "\n");
4142     cplen = strlen(cp);
4143     /* Copy board information. */
4144     cnt = asc_proc_copy(advoffset, offset, curbuf, leftlen, cp, cplen);
4145     totcnt += cnt;
4146     leftlen -= cnt;
4147     if (leftlen == 0) {
4148         ASC_DBG1(1, "advansys_proc_info: totcnt %d\n", totcnt);
4149         return totcnt;
4150     }
4151     advoffset += cplen;
4152     curbuf += cnt;
4153
4154     /*
4155      * Display Wide Board BIOS Information.
4156      */
4157     if (ASC_WIDE_BOARD(boardp)) {
4158         cp = boardp->prtbuf;
4159         cplen = asc_prt_adv_bios(shp, cp, ASC_PRTBUF_SIZE);
4160         ASC_ASSERT(cplen < ASC_PRTBUF_SIZE);
4161         cnt = asc_proc_copy(advoffset, offset, curbuf, leftlen, cp, cplen);
4162         totcnt += cnt;
4163         leftlen -= cnt;
4164         if (leftlen == 0) {
4165             ASC_DBG1(1, "advansys_proc_info: totcnt %d\n", totcnt);
4166             return totcnt;
4167         }
4168         advoffset += cplen;
4169         curbuf += cnt;
4170     }
4171
4172     /*
4173      * Display driver information for each device attached to the board.
4174      */
4175     cp = boardp->prtbuf;
4176     cplen = asc_prt_board_devices(shp, cp, ASC_PRTBUF_SIZE);
4177     ASC_ASSERT(cplen < ASC_PRTBUF_SIZE);
4178     cnt = asc_proc_copy(advoffset, offset, curbuf, leftlen, cp, cplen);
4179     totcnt += cnt;
4180     leftlen -= cnt;
4181     if (leftlen == 0) {
4182         ASC_DBG1(1, "advansys_proc_info: totcnt %d\n", totcnt);
4183         return totcnt;
4184     }
4185     advoffset += cplen;
4186     curbuf += cnt;
4187
4188     /*
4189      * Display EEPROM configuration for the board.
4190      */
4191     cp = boardp->prtbuf;
4192     if (ASC_NARROW_BOARD(boardp)) {
4193         cplen = asc_prt_asc_board_eeprom(shp, cp, ASC_PRTBUF_SIZE);
4194     } else {
4195         cplen = asc_prt_adv_board_eeprom(shp, cp, ASC_PRTBUF_SIZE);
4196     }
4197     ASC_ASSERT(cplen < ASC_PRTBUF_SIZE);
4198     cnt = asc_proc_copy(advoffset, offset, curbuf, leftlen, cp, cplen);
4199     totcnt += cnt;
4200     leftlen -= cnt;
4201     if (leftlen == 0) {
4202         ASC_DBG1(1, "advansys_proc_info: totcnt %d\n", totcnt);
4203         return totcnt;
4204     }
4205     advoffset += cplen;
4206     curbuf += cnt;
4207
4208     /*
4209      * Display driver configuration and information for the board.
4210      */
4211     cp = boardp->prtbuf;
4212     cplen = asc_prt_driver_conf(shp, cp, ASC_PRTBUF_SIZE);
4213     ASC_ASSERT(cplen < ASC_PRTBUF_SIZE);
4214     cnt = asc_proc_copy(advoffset, offset, curbuf, leftlen, cp, cplen);
4215     totcnt += cnt;
4216     leftlen -= cnt;
4217     if (leftlen == 0) {
4218         ASC_DBG1(1, "advansys_proc_info: totcnt %d\n", totcnt);
4219         return totcnt;
4220     }
4221     advoffset += cplen;
4222     curbuf += cnt;
4223
4224 #ifdef ADVANSYS_STATS
4225     /*
4226      * Display driver statistics for the board.
4227      */
4228     cp = boardp->prtbuf;
4229     cplen = asc_prt_board_stats(shp, cp, ASC_PRTBUF_SIZE);
4230     ASC_ASSERT(cplen <= ASC_PRTBUF_SIZE);
4231     cnt = asc_proc_copy(advoffset, offset, curbuf, leftlen, cp, cplen);
4232     totcnt += cnt;
4233     leftlen -= cnt;
4234     if (leftlen == 0) {
4235         ASC_DBG1(1, "advansys_proc_info: totcnt %d\n", totcnt);
4236         return totcnt;
4237     }
4238     advoffset += cplen;
4239     curbuf += cnt;
4240
4241     /*
4242      * Display driver statistics for each target.
4243      */
4244     for (tgt_id = 0; tgt_id <= ADV_MAX_TID; tgt_id++) {
4245       cp = boardp->prtbuf;
4246       cplen = asc_prt_target_stats(shp, tgt_id, cp, ASC_PRTBUF_SIZE);
4247       ASC_ASSERT(cplen <= ASC_PRTBUF_SIZE);
4248       cnt = asc_proc_copy(advoffset, offset, curbuf, leftlen, cp, cplen);
4249       totcnt += cnt;
4250       leftlen -= cnt;
4251       if (leftlen == 0) {
4252         ASC_DBG1(1, "advansys_proc_info: totcnt %d\n", totcnt);
4253         return totcnt;
4254       }
4255       advoffset += cplen;
4256       curbuf += cnt;
4257     }
4258 #endif /* ADVANSYS_STATS */
4259
4260     /*
4261      * Display Asc Library dynamic configuration information
4262      * for the board.
4263      */
4264     cp = boardp->prtbuf;
4265     if (ASC_NARROW_BOARD(boardp)) {
4266         cplen = asc_prt_asc_board_info(shp, cp, ASC_PRTBUF_SIZE);
4267     } else {
4268         cplen = asc_prt_adv_board_info(shp, cp, ASC_PRTBUF_SIZE);
4269     }
4270     ASC_ASSERT(cplen < ASC_PRTBUF_SIZE);
4271     cnt = asc_proc_copy(advoffset, offset, curbuf, leftlen, cp, cplen);
4272     totcnt += cnt;
4273     leftlen -= cnt;
4274     if (leftlen == 0) {
4275         ASC_DBG1(1, "advansys_proc_info: totcnt %d\n", totcnt);
4276         return totcnt;
4277     }
4278     advoffset += cplen;
4279     curbuf += cnt;
4280
4281     ASC_DBG1(1, "advansys_proc_info: totcnt %d\n", totcnt);
4282
4283     return totcnt;
4284 }
4285 #endif /* CONFIG_PROC_FS */
4286
4287 /*
4288  * advansys_detect()
4289  *
4290  * Detect function for AdvanSys adapters.
4291  *
4292  * Argument is a pointer to the host driver's scsi_hosts entry.
4293  *
4294  * Return number of adapters found.
4295  *
4296  * Note: Because this function is called during system initialization
4297  * it must not call SCSI mid-level functions including scsi_malloc()
4298  * and scsi_free().
4299  */
4300 int __init
4301 advansys_detect(struct scsi_host_template *tpnt)
4302 {
4303     static int          detect_called = ASC_FALSE;
4304     int                 iop;
4305     int                 bus;
4306     struct Scsi_Host    *shp = NULL;
4307     asc_board_t         *boardp = NULL;
4308     ASC_DVC_VAR         *asc_dvc_varp = NULL;
4309     ADV_DVC_VAR         *adv_dvc_varp = NULL;
4310     adv_sgblk_t         *sgp = NULL;
4311     int                 ioport = 0;
4312     int                 share_irq = FALSE;
4313     int                 iolen = 0;
4314     struct device       *dev = NULL;
4315 #ifdef CONFIG_PCI
4316     int                 pci_init_search = 0;
4317     struct pci_dev      *pci_devicep[ASC_NUM_BOARD_SUPPORTED];
4318     int                 pci_card_cnt_max = 0;
4319     int                 pci_card_cnt = 0;
4320     struct pci_dev      *pci_devp = NULL;
4321     int                 pci_device_id_cnt = 0;
4322     unsigned int        pci_device_id[ASC_PCI_DEVICE_ID_CNT] = {
4323                                     PCI_DEVICE_ID_ASP_1200A,
4324                                     PCI_DEVICE_ID_ASP_ABP940,
4325                                     PCI_DEVICE_ID_ASP_ABP940U,
4326                                     PCI_DEVICE_ID_ASP_ABP940UW,
4327                                     PCI_DEVICE_ID_38C0800_REV1,
4328                                     PCI_DEVICE_ID_38C1600_REV1
4329                         };
4330     ADV_PADDR           pci_memory_address;
4331 #endif /* CONFIG_PCI */
4332     int                 warn_code, err_code;
4333     int                 ret;
4334
4335     if (detect_called == ASC_FALSE) {
4336         detect_called = ASC_TRUE;
4337     } else {
4338         printk("AdvanSys SCSI: advansys_detect() multiple calls ignored\n");
4339         return 0;
4340     }
4341
4342     ASC_DBG(1, "advansys_detect: begin\n");
4343
4344     asc_board_count = 0;
4345
4346     /*
4347      * If I/O port probing has been modified, then verify and
4348      * clean-up the 'asc_ioport' list.
4349      */
4350     if (asc_iopflag == ASC_TRUE) {
4351         for (ioport = 0; ioport < ASC_NUM_IOPORT_PROBE; ioport++) {
4352             ASC_DBG2(1, "advansys_detect: asc_ioport[%d] 0x%x\n",
4353                 ioport, asc_ioport[ioport]);
4354             if (asc_ioport[ioport] != 0) {
4355                 for (iop = 0; iop < ASC_IOADR_TABLE_MAX_IX; iop++) {
4356                     if (_asc_def_iop_base[iop] == asc_ioport[ioport]) {
4357                         break;
4358                     }
4359                 }
4360                 if (iop == ASC_IOADR_TABLE_MAX_IX) {
4361                     printk(
4362 "AdvanSys SCSI: specified I/O Port 0x%X is invalid\n",
4363                         asc_ioport[ioport]);
4364                     asc_ioport[ioport] = 0;
4365                 }
4366             }
4367         }
4368         ioport = 0;
4369     }
4370
4371     for (bus = 0; bus < ASC_NUM_BUS; bus++) {
4372
4373         ASC_DBG2(1, "advansys_detect: bus search type %d (%s)\n",
4374             bus, asc_bus_name[bus]);
4375         iop = 0;
4376
4377         while (asc_board_count < ASC_NUM_BOARD_SUPPORTED) {
4378
4379             ASC_DBG1(2, "advansys_detect: asc_board_count %d\n",
4380                 asc_board_count);
4381
4382             switch (asc_bus[bus]) {
4383             case ASC_IS_ISA:
4384             case ASC_IS_VL:
4385 #ifdef CONFIG_ISA
4386                 if (asc_iopflag == ASC_FALSE) {
4387                     iop = AscSearchIOPortAddr(iop, asc_bus[bus]);
4388                 } else {
4389                     /*
4390                      * ISA and VL I/O port scanning has either been
4391                      * eliminated or limited to selected ports on
4392                      * the LILO command line, /etc/lilo.conf, or
4393                      * by setting variables when the module was loaded.
4394                      */
4395                     ASC_DBG(1, "advansys_detect: I/O port scanning modified\n");
4396                 ioport_try_again:
4397                     iop = 0;
4398                     for (; ioport < ASC_NUM_IOPORT_PROBE; ioport++) {
4399                         if ((iop = asc_ioport[ioport]) != 0) {
4400                             break;
4401                         }
4402                     }
4403                     if (iop) {
4404                         ASC_DBG1(1,
4405                                 "advansys_detect: probing I/O port 0x%x...\n",
4406                             iop);
4407                         if (check_region(iop, ASC_IOADR_GAP) != 0) {
4408                             printk(
4409 "AdvanSys SCSI: specified I/O Port 0x%X is busy\n", iop);
4410                             /* Don't try this I/O port twice. */
4411                             asc_ioport[ioport] = 0;
4412                             goto ioport_try_again;
4413                         } else if (AscFindSignature(iop) == ASC_FALSE) {
4414                             printk(
4415 "AdvanSys SCSI: specified I/O Port 0x%X has no adapter\n", iop);
4416                             /* Don't try this I/O port twice. */
4417                             asc_ioport[ioport] = 0;
4418                             goto ioport_try_again;
4419                         } else {
4420                             /*
4421                              * If this isn't an ISA board, then it must be
4422                              * a VL board. If currently looking an ISA
4423                              * board is being looked for then try for
4424                              * another ISA board in 'asc_ioport'.
4425                              */
4426                             if (asc_bus[bus] == ASC_IS_ISA &&
4427                                 (AscGetChipVersion(iop, ASC_IS_ISA) &
4428                                  ASC_CHIP_VER_ISA_BIT) == 0) {
4429                                  /*
4430                                   * Don't clear 'asc_ioport[ioport]'. Try
4431                                   * this board again for VL. Increment
4432                                   * 'ioport' past this board.
4433                                   */
4434                                  ioport++;
4435                                  goto ioport_try_again;
4436                             }
4437                         }
4438                         /*
4439                          * This board appears good, don't try the I/O port
4440                          * again by clearing its value. Increment 'ioport'
4441                          * for the next iteration.
4442                          */
4443                         asc_ioport[ioport++] = 0;
4444                     }
4445                 }
4446 #endif /* CONFIG_ISA */
4447                 break;
4448
4449             case ASC_IS_EISA:
4450 #ifdef CONFIG_ISA
4451                 iop = AscSearchIOPortAddr(iop, asc_bus[bus]);
4452 #endif /* CONFIG_ISA */
4453                 break;
4454
4455             case ASC_IS_PCI:
4456 #ifdef CONFIG_PCI
4457                 if (pci_init_search == 0) {
4458                     int i, j;
4459
4460                     pci_init_search = 1;
4461
4462                     /* Find all PCI cards. */
4463                     while (pci_device_id_cnt < ASC_PCI_DEVICE_ID_CNT) {
4464                         if ((pci_devp = pci_find_device(PCI_VENDOR_ID_ASP,
4465                             pci_device_id[pci_device_id_cnt], pci_devp)) ==
4466                             NULL) {
4467                             pci_device_id_cnt++;
4468                         } else {
4469                             if (pci_enable_device(pci_devp) == 0) {
4470                                 pci_devicep[pci_card_cnt_max++] = pci_devp;
4471                             }
4472                         }
4473                     }
4474
4475                     /*
4476                      * Sort PCI cards in ascending order by PCI Bus, Slot,
4477                      * and Device Number.
4478                      */
4479                     for (i = 0; i < pci_card_cnt_max - 1; i++)
4480                     {
4481                         for (j = i + 1; j < pci_card_cnt_max; j++) {
4482                             if ((pci_devicep[j]->bus->number <
4483                                  pci_devicep[i]->bus->number) ||
4484                                 ((pci_devicep[j]->bus->number ==
4485                                   pci_devicep[i]->bus->number) &&
4486                                   (pci_devicep[j]->devfn <
4487                                    pci_devicep[i]->devfn))) {
4488                                 pci_devp = pci_devicep[i];
4489                                 pci_devicep[i] = pci_devicep[j];
4490                                 pci_devicep[j] = pci_devp;
4491                             }
4492                         }
4493                     }
4494
4495                     pci_card_cnt = 0;
4496                 } else {
4497                     pci_card_cnt++;
4498                 }
4499
4500                 if (pci_card_cnt == pci_card_cnt_max) {
4501                     iop = 0;
4502                 } else {
4503                     pci_devp = pci_devicep[pci_card_cnt];
4504
4505                     ASC_DBG2(2,
4506                         "advansys_detect: devfn %d, bus number %d\n",
4507                         pci_devp->devfn, pci_devp->bus->number);
4508                     iop = pci_resource_start(pci_devp, 0);
4509                     ASC_DBG2(1,
4510                         "advansys_detect: vendorID %X, deviceID %X\n",
4511                         pci_devp->vendor, pci_devp->device);
4512                     ASC_DBG2(2, "advansys_detect: iop %X, irqLine %d\n",
4513                         iop, pci_devp->irq);
4514                 }
4515                 if(pci_devp)
4516                     dev = &pci_devp->dev;
4517
4518 #endif /* CONFIG_PCI */
4519                 break;
4520
4521             default:
4522                 ASC_PRINT1("advansys_detect: unknown bus type: %d\n",
4523                     asc_bus[bus]);
4524                 break;
4525             }
4526             ASC_DBG1(1, "advansys_detect: iop 0x%x\n", iop);
4527
4528             /*
4529              * Adapter not found, try next bus type.
4530              */
4531             if (iop == 0) {
4532                 break;
4533             }
4534
4535             /*
4536              * Adapter found.
4537              *
4538              * Register the adapter, get its configuration, and
4539              * initialize it.
4540              */
4541             ASC_DBG(2, "advansys_detect: scsi_register()\n");
4542             shp = scsi_register(tpnt, sizeof(asc_board_t));
4543
4544             if (shp == NULL) {
4545                 continue;
4546             }
4547
4548             /* Save a pointer to the Scsi_Host of each board found. */
4549             asc_host[asc_board_count++] = shp;
4550
4551             /* Initialize private per board data */
4552             boardp = ASC_BOARDP(shp);
4553             memset(boardp, 0, sizeof(asc_board_t));
4554             boardp->id = asc_board_count - 1;
4555
4556             /* Initialize spinlock. */
4557             spin_lock_init(&boardp->lock);
4558
4559             /*
4560              * Handle both narrow and wide boards.
4561              *
4562              * If a Wide board was detected, set the board structure
4563              * wide board flag. Set-up the board structure based on
4564              * the board type.
4565              */
4566 #ifdef CONFIG_PCI
4567             if (asc_bus[bus] == ASC_IS_PCI &&
4568                 (pci_devp->device == PCI_DEVICE_ID_ASP_ABP940UW ||
4569                  pci_devp->device == PCI_DEVICE_ID_38C0800_REV1 ||
4570                  pci_devp->device == PCI_DEVICE_ID_38C1600_REV1))
4571             {
4572                 boardp->flags |= ASC_IS_WIDE_BOARD;
4573             }
4574 #endif /* CONFIG_PCI */
4575
4576             if (ASC_NARROW_BOARD(boardp)) {
4577                 ASC_DBG(1, "advansys_detect: narrow board\n");
4578                 asc_dvc_varp = &boardp->dvc_var.asc_dvc_var;
4579                 asc_dvc_varp->bus_type = asc_bus[bus];
4580                 asc_dvc_varp->drv_ptr = boardp;
4581                 asc_dvc_varp->cfg = &boardp->dvc_cfg.asc_dvc_cfg;
4582                 asc_dvc_varp->cfg->overrun_buf = &overrun_buf[0];
4583                 asc_dvc_varp->iop_base = iop;
4584                 asc_dvc_varp->isr_callback = asc_isr_callback;
4585             } else {
4586                 ASC_DBG(1, "advansys_detect: wide board\n");
4587                 adv_dvc_varp = &boardp->dvc_var.adv_dvc_var;
4588                 adv_dvc_varp->drv_ptr = boardp;
4589                 adv_dvc_varp->cfg = &boardp->dvc_cfg.adv_dvc_cfg;
4590                 adv_dvc_varp->isr_callback = adv_isr_callback;
4591                 adv_dvc_varp->async_callback = adv_async_callback;
4592 #ifdef CONFIG_PCI
4593                 if (pci_devp->device == PCI_DEVICE_ID_ASP_ABP940UW)
4594                 {
4595                     ASC_DBG(1, "advansys_detect: ASC-3550\n");
4596                     adv_dvc_varp->chip_type = ADV_CHIP_ASC3550;
4597                 } else if (pci_devp->device == PCI_DEVICE_ID_38C0800_REV1)
4598                 {
4599                     ASC_DBG(1, "advansys_detect: ASC-38C0800\n");
4600                     adv_dvc_varp->chip_type = ADV_CHIP_ASC38C0800;
4601                 } else
4602                 {
4603                     ASC_DBG(1, "advansys_detect: ASC-38C1600\n");
4604                     adv_dvc_varp->chip_type = ADV_CHIP_ASC38C1600;
4605                 }
4606 #endif /* CONFIG_PCI */
4607
4608                 /*
4609                  * Map the board's registers into virtual memory for
4610                  * PCI slave access. Only memory accesses are used to
4611                  * access the board's registers.
4612                  *
4613                  * Note: The PCI register base address is not always
4614                  * page aligned, but the address passed to ioremap()
4615                  * must be page aligned. It is guaranteed that the
4616                  * PCI register base address will not cross a page
4617                  * boundary.
4618                  */
4619                 if (adv_dvc_varp->chip_type == ADV_CHIP_ASC3550)
4620                 {
4621                     iolen = ADV_3550_IOLEN;
4622                 } else if (adv_dvc_varp->chip_type == ADV_CHIP_ASC38C0800)
4623                 {
4624                     iolen = ADV_38C0800_IOLEN;
4625                 } else
4626                 {
4627                     iolen = ADV_38C1600_IOLEN;
4628                 }
4629 #ifdef CONFIG_PCI
4630                 pci_memory_address = pci_resource_start(pci_devp, 1);
4631                 ASC_DBG1(1, "advansys_detect: pci_memory_address: 0x%lx\n",
4632                     (ulong) pci_memory_address);
4633                 if ((boardp->ioremap_addr =
4634                     ioremap(pci_memory_address & PAGE_MASK,
4635                          PAGE_SIZE)) == 0) {
4636                    ASC_PRINT3(
4637 "advansys_detect: board %d: ioremap(%x, %d) returned NULL\n",
4638                        boardp->id, pci_memory_address, iolen);
4639                    scsi_unregister(shp);
4640                    asc_board_count--;
4641                    continue;
4642                 }
4643                 ASC_DBG1(1, "advansys_detect: ioremap_addr: 0x%lx\n",
4644                     (ulong) boardp->ioremap_addr);
4645                 adv_dvc_varp->iop_base = (AdvPortAddr)
4646                     (boardp->ioremap_addr +
4647                      (pci_memory_address - (pci_memory_address & PAGE_MASK)));
4648                 ASC_DBG1(1, "advansys_detect: iop_base: 0x%lx\n",
4649                     adv_dvc_varp->iop_base);
4650 #endif /* CONFIG_PCI */
4651
4652                 /*
4653                  * Even though it isn't used to access wide boards, other
4654                  * than for the debug line below, save I/O Port address so
4655                  * that it can be reported.
4656                  */
4657                 boardp->ioport = iop;
4658
4659                 ASC_DBG2(1,
4660 "advansys_detect: iopb_chip_id_1 0x%x, iopw_chip_id_0 0x%x\n",
4661                     (ushort) inp(iop + 1), (ushort) inpw(iop));
4662             }
4663
4664 #ifdef CONFIG_PROC_FS
4665             /*
4666              * Allocate buffer for printing information from
4667              * /proc/scsi/advansys/[0...].
4668              */
4669             if ((boardp->prtbuf =
4670                 kmalloc(ASC_PRTBUF_SIZE, GFP_ATOMIC)) == NULL) {
4671                 ASC_PRINT3(
4672 "advansys_detect: board %d: kmalloc(%d, %d) returned NULL\n",
4673                     boardp->id, ASC_PRTBUF_SIZE, GFP_ATOMIC);
4674                 scsi_unregister(shp);
4675                 asc_board_count--;
4676                 continue;
4677             }
4678 #endif /* CONFIG_PROC_FS */
4679
4680             if (ASC_NARROW_BOARD(boardp)) {
4681                 asc_dvc_varp->cfg->dev = dev;
4682                 /*
4683                  * Set the board bus type and PCI IRQ before
4684                  * calling AscInitGetConfig().
4685                  */
4686                 switch (asc_dvc_varp->bus_type) {
4687 #ifdef CONFIG_ISA
4688                 case ASC_IS_ISA:
4689                     shp->unchecked_isa_dma = TRUE;
4690                     share_irq = FALSE;
4691                     break;
4692                 case ASC_IS_VL:
4693                     shp->unchecked_isa_dma = FALSE;
4694                     share_irq = FALSE;
4695                     break;
4696                 case ASC_IS_EISA:
4697                     shp->unchecked_isa_dma = FALSE;
4698                     share_irq = TRUE;
4699                     break;
4700 #endif /* CONFIG_ISA */
4701 #ifdef CONFIG_PCI
4702                 case ASC_IS_PCI:
4703                     shp->irq = asc_dvc_varp->irq_no = pci_devp->irq;
4704                     asc_dvc_varp->cfg->pci_slot_info =
4705                         ASC_PCI_MKID(pci_devp->bus->number,
4706                             PCI_SLOT(pci_devp->devfn),
4707                             PCI_FUNC(pci_devp->devfn));
4708                     shp->unchecked_isa_dma = FALSE;
4709                     share_irq = TRUE;
4710                     break;
4711 #endif /* CONFIG_PCI */
4712                 default:
4713                     ASC_PRINT2(
4714 "advansys_detect: board %d: unknown adapter type: %d\n",
4715                         boardp->id, asc_dvc_varp->bus_type);
4716                     shp->unchecked_isa_dma = TRUE;
4717                     share_irq = FALSE;
4718                     break;
4719                 }
4720             } else {
4721                 adv_dvc_varp->cfg->dev = dev;
4722                 /*
4723                  * For Wide boards set PCI information before calling
4724                  * AdvInitGetConfig().
4725                  */
4726 #ifdef CONFIG_PCI
4727                 shp->irq = adv_dvc_varp->irq_no = pci_devp->irq;
4728                 adv_dvc_varp->cfg->pci_slot_info =
4729                     ASC_PCI_MKID(pci_devp->bus->number,
4730                         PCI_SLOT(pci_devp->devfn),
4731                         PCI_FUNC(pci_devp->devfn));
4732                 shp->unchecked_isa_dma = FALSE;
4733                 share_irq = TRUE;
4734 #endif /* CONFIG_PCI */
4735             }
4736
4737             /*
4738              * Read the board configuration.
4739              */
4740             if (ASC_NARROW_BOARD(boardp)) {
4741                  /*
4742                   * NOTE: AscInitGetConfig() may change the board's
4743                   * bus_type value. The asc_bus[bus] value should no
4744                   * longer be used. If the bus_type field must be
4745                   * referenced only use the bit-wise AND operator "&".
4746                   */
4747                 ASC_DBG(2, "advansys_detect: AscInitGetConfig()\n");
4748                 switch(ret = AscInitGetConfig(asc_dvc_varp)) {
4749                 case 0:    /* No error */
4750                     break;
4751                 case ASC_WARN_IO_PORT_ROTATE:
4752                     ASC_PRINT1(
4753 "AscInitGetConfig: board %d: I/O port address modified\n",
4754                         boardp->id);
4755                     break;
4756                 case ASC_WARN_AUTO_CONFIG:
4757                     ASC_PRINT1(
4758 "AscInitGetConfig: board %d: I/O port increment switch enabled\n",
4759                         boardp->id);
4760                     break;
4761                 case ASC_WARN_EEPROM_CHKSUM:
4762                     ASC_PRINT1(
4763 "AscInitGetConfig: board %d: EEPROM checksum error\n",
4764                         boardp->id);
4765                     break;
4766                 case ASC_WARN_IRQ_MODIFIED:
4767                     ASC_PRINT1(
4768 "AscInitGetConfig: board %d: IRQ modified\n",
4769                         boardp->id);
4770                     break;
4771                 case ASC_WARN_CMD_QNG_CONFLICT:
4772                     ASC_PRINT1(
4773 "AscInitGetConfig: board %d: tag queuing enabled w/o disconnects\n",
4774                         boardp->id);
4775                     break;
4776                 default:
4777                     ASC_PRINT2(
4778 "AscInitGetConfig: board %d: unknown warning: 0x%x\n",
4779                         boardp->id, ret);
4780                     break;
4781                 }
4782                 if ((err_code = asc_dvc_varp->err_code) != 0) {
4783                     ASC_PRINT3(
4784 "AscInitGetConfig: board %d error: init_state 0x%x, err_code 0x%x\n",
4785                         boardp->id, asc_dvc_varp->init_state,
4786                         asc_dvc_varp->err_code);
4787                 }
4788             } else {
4789                 ASC_DBG(2, "advansys_detect: AdvInitGetConfig()\n");
4790                 if ((ret = AdvInitGetConfig(adv_dvc_varp)) != 0) {
4791                     ASC_PRINT2("AdvInitGetConfig: board %d: warning: 0x%x\n",
4792                         boardp->id, ret);
4793                 }
4794                 if ((err_code = adv_dvc_varp->err_code) != 0) {
4795                     ASC_PRINT2(
4796 "AdvInitGetConfig: board %d error: err_code 0x%x\n",
4797                         boardp->id, adv_dvc_varp->err_code);
4798                 }
4799             }
4800
4801             if (err_code != 0) {
4802 #ifdef CONFIG_PROC_FS
4803                 kfree(boardp->prtbuf);
4804 #endif /* CONFIG_PROC_FS */
4805                 scsi_unregister(shp);
4806                 asc_board_count--;
4807                 continue;
4808             }
4809
4810             /*
4811              * Save the EEPROM configuration so that it can be displayed
4812              * from /proc/scsi/advansys/[0...].
4813              */
4814             if (ASC_NARROW_BOARD(boardp)) {
4815
4816                 ASCEEP_CONFIG *ep;
4817
4818                 /*
4819                  * Set the adapter's target id bit in the 'init_tidmask' field.
4820                  */
4821                 boardp->init_tidmask |=
4822                     ADV_TID_TO_TIDMASK(asc_dvc_varp->cfg->chip_scsi_id);
4823
4824                 /*
4825                  * Save EEPROM settings for the board.
4826                  */
4827                 ep = &boardp->eep_config.asc_eep;
4828
4829                 ep->init_sdtr = asc_dvc_varp->cfg->sdtr_enable;
4830                 ep->disc_enable = asc_dvc_varp->cfg->disc_enable;
4831                 ep->use_cmd_qng = asc_dvc_varp->cfg->cmd_qng_enabled;
4832                 ASC_EEP_SET_DMA_SPD(ep, asc_dvc_varp->cfg->isa_dma_speed);
4833                 ep->start_motor = asc_dvc_varp->start_motor;
4834                 ep->cntl = asc_dvc_varp->dvc_cntl;
4835                 ep->no_scam = asc_dvc_varp->no_scam;
4836                 ep->max_total_qng = asc_dvc_varp->max_total_qng;
4837                 ASC_EEP_SET_CHIP_ID(ep, asc_dvc_varp->cfg->chip_scsi_id);
4838                 /* 'max_tag_qng' is set to the same value for every device. */
4839                 ep->max_tag_qng = asc_dvc_varp->cfg->max_tag_qng[0];
4840                 ep->adapter_info[0] = asc_dvc_varp->cfg->adapter_info[0];
4841                 ep->adapter_info[1] = asc_dvc_varp->cfg->adapter_info[1];
4842                 ep->adapter_info[2] = asc_dvc_varp->cfg->adapter_info[2];
4843                 ep->adapter_info[3] = asc_dvc_varp->cfg->adapter_info[3];
4844                 ep->adapter_info[4] = asc_dvc_varp->cfg->adapter_info[4];
4845                 ep->adapter_info[5] = asc_dvc_varp->cfg->adapter_info[5];
4846
4847                /*
4848                 * Modify board configuration.
4849                 */
4850                 ASC_DBG(2, "advansys_detect: AscInitSetConfig()\n");
4851                 switch (ret = AscInitSetConfig(asc_dvc_varp)) {
4852                 case 0:    /* No error. */
4853                     break;
4854                 case ASC_WARN_IO_PORT_ROTATE:
4855                     ASC_PRINT1(
4856 "AscInitSetConfig: board %d: I/O port address modified\n",
4857                         boardp->id);
4858                     break;
4859                 case ASC_WARN_AUTO_CONFIG:
4860                     ASC_PRINT1(
4861 "AscInitSetConfig: board %d: I/O port increment switch enabled\n",
4862                         boardp->id);
4863                     break;
4864                 case ASC_WARN_EEPROM_CHKSUM:
4865                     ASC_PRINT1(
4866 "AscInitSetConfig: board %d: EEPROM checksum error\n",
4867                         boardp->id);
4868                     break;
4869                 case ASC_WARN_IRQ_MODIFIED:
4870                     ASC_PRINT1(
4871 "AscInitSetConfig: board %d: IRQ modified\n",
4872                         boardp->id);
4873                     break;
4874                 case ASC_WARN_CMD_QNG_CONFLICT:
4875                     ASC_PRINT1(
4876 "AscInitSetConfig: board %d: tag queuing w/o disconnects\n",
4877                         boardp->id);
4878                     break;
4879                 default:
4880                     ASC_PRINT2(
4881 "AscInitSetConfig: board %d: unknown warning: 0x%x\n",
4882                         boardp->id, ret);
4883                     break;
4884                 }
4885                 if (asc_dvc_varp->err_code != 0) {
4886                     ASC_PRINT3(
4887 "AscInitSetConfig: board %d error: init_state 0x%x, err_code 0x%x\n",
4888                         boardp->id, asc_dvc_varp->init_state,
4889                         asc_dvc_varp->err_code);
4890 #ifdef CONFIG_PROC_FS
4891                     kfree(boardp->prtbuf);
4892 #endif /* CONFIG_PROC_FS */
4893                     scsi_unregister(shp);
4894                     asc_board_count--;
4895                     continue;
4896                 }
4897
4898                 /*
4899                  * Finish initializing the 'Scsi_Host' structure.
4900                  */
4901                 /* AscInitSetConfig() will set the IRQ for non-PCI boards. */
4902                 if ((asc_dvc_varp->bus_type & ASC_IS_PCI) == 0) {
4903                     shp->irq = asc_dvc_varp->irq_no;
4904                 }
4905             } else {
4906                 ADVEEP_3550_CONFIG      *ep_3550;
4907                 ADVEEP_38C0800_CONFIG   *ep_38C0800;
4908                 ADVEEP_38C1600_CONFIG   *ep_38C1600;
4909
4910                 /*
4911                  * Save Wide EEP Configuration Information.
4912                  */
4913                 if (adv_dvc_varp->chip_type == ADV_CHIP_ASC3550)
4914                 {
4915                     ep_3550 = &boardp->eep_config.adv_3550_eep;
4916
4917                     ep_3550->adapter_scsi_id = adv_dvc_varp->chip_scsi_id;
4918                     ep_3550->max_host_qng = adv_dvc_varp->max_host_qng;
4919                     ep_3550->max_dvc_qng = adv_dvc_varp->max_dvc_qng;
4920                     ep_3550->termination = adv_dvc_varp->cfg->termination;
4921                     ep_3550->disc_enable = adv_dvc_varp->cfg->disc_enable;
4922                     ep_3550->bios_ctrl = adv_dvc_varp->bios_ctrl;
4923                     ep_3550->wdtr_able = adv_dvc_varp->wdtr_able;
4924                     ep_3550->sdtr_able = adv_dvc_varp->sdtr_able;
4925                     ep_3550->ultra_able = adv_dvc_varp->ultra_able;
4926                     ep_3550->tagqng_able = adv_dvc_varp->tagqng_able;
4927                     ep_3550->start_motor = adv_dvc_varp->start_motor;
4928                     ep_3550->scsi_reset_delay = adv_dvc_varp->scsi_reset_wait;
4929                     ep_3550->serial_number_word1 =
4930                         adv_dvc_varp->cfg->serial1;
4931                     ep_3550->serial_number_word2 =
4932                         adv_dvc_varp->cfg->serial2;
4933                     ep_3550->serial_number_word3 =
4934                         adv_dvc_varp->cfg->serial3;
4935                 } else if (adv_dvc_varp->chip_type == ADV_CHIP_ASC38C0800)
4936                 {
4937                     ep_38C0800 = &boardp->eep_config.adv_38C0800_eep;
4938
4939                     ep_38C0800->adapter_scsi_id = adv_dvc_varp->chip_scsi_id;
4940                     ep_38C0800->max_host_qng = adv_dvc_varp->max_host_qng;
4941                     ep_38C0800->max_dvc_qng = adv_dvc_varp->max_dvc_qng;
4942                     ep_38C0800->termination_lvd =
4943                         adv_dvc_varp->cfg->termination;
4944                     ep_38C0800->disc_enable = adv_dvc_varp->cfg->disc_enable;
4945                     ep_38C0800->bios_ctrl = adv_dvc_varp->bios_ctrl;
4946                     ep_38C0800->wdtr_able = adv_dvc_varp->wdtr_able;
4947                     ep_38C0800->tagqng_able = adv_dvc_varp->tagqng_able;
4948                     ep_38C0800->sdtr_speed1 = adv_dvc_varp->sdtr_speed1;
4949                     ep_38C0800->sdtr_speed2 = adv_dvc_varp->sdtr_speed2;
4950                     ep_38C0800->sdtr_speed3 = adv_dvc_varp->sdtr_speed3;
4951                     ep_38C0800->sdtr_speed4 = adv_dvc_varp->sdtr_speed4;
4952                     ep_38C0800->tagqng_able = adv_dvc_varp->tagqng_able;
4953                     ep_38C0800->start_motor = adv_dvc_varp->start_motor;
4954                     ep_38C0800->scsi_reset_delay =
4955                         adv_dvc_varp->scsi_reset_wait;
4956                     ep_38C0800->serial_number_word1 =
4957                         adv_dvc_varp->cfg->serial1;
4958                     ep_38C0800->serial_number_word2 =
4959                         adv_dvc_varp->cfg->serial2;
4960                     ep_38C0800->serial_number_word3 =
4961                         adv_dvc_varp->cfg->serial3;
4962                 } else
4963                 {
4964                     ep_38C1600 = &boardp->eep_config.adv_38C1600_eep;
4965
4966                     ep_38C1600->adapter_scsi_id = adv_dvc_varp->chip_scsi_id;
4967                     ep_38C1600->max_host_qng = adv_dvc_varp->max_host_qng;
4968                     ep_38C1600->max_dvc_qng = adv_dvc_varp->max_dvc_qng;
4969                     ep_38C1600->termination_lvd =
4970                         adv_dvc_varp->cfg->termination;
4971                     ep_38C1600->disc_enable = adv_dvc_varp->cfg->disc_enable;
4972                     ep_38C1600->bios_ctrl = adv_dvc_varp->bios_ctrl;
4973                     ep_38C1600->wdtr_able = adv_dvc_varp->wdtr_able;
4974                     ep_38C1600->tagqng_able = adv_dvc_varp->tagqng_able;
4975                     ep_38C1600->sdtr_speed1 = adv_dvc_varp->sdtr_speed1;
4976                     ep_38C1600->sdtr_speed2 = adv_dvc_varp->sdtr_speed2;
4977                     ep_38C1600->sdtr_speed3 = adv_dvc_varp->sdtr_speed3;
4978                     ep_38C1600->sdtr_speed4 = adv_dvc_varp->sdtr_speed4;
4979                     ep_38C1600->tagqng_able = adv_dvc_varp->tagqng_able;
4980                     ep_38C1600->start_motor = adv_dvc_varp->start_motor;
4981                     ep_38C1600->scsi_reset_delay =
4982                         adv_dvc_varp->scsi_reset_wait;
4983                     ep_38C1600->serial_number_word1 =
4984                         adv_dvc_varp->cfg->serial1;
4985                     ep_38C1600->serial_number_word2 =
4986                         adv_dvc_varp->cfg->serial2;
4987                     ep_38C1600->serial_number_word3 =
4988                         adv_dvc_varp->cfg->serial3;
4989                 }
4990
4991                 /*
4992                  * Set the adapter's target id bit in the 'init_tidmask' field.
4993                  */
4994                 boardp->init_tidmask |=
4995                     ADV_TID_TO_TIDMASK(adv_dvc_varp->chip_scsi_id);
4996
4997                 /*
4998                  * Finish initializing the 'Scsi_Host' structure.
4999                  */
5000                 shp->irq = adv_dvc_varp->irq_no;
5001             }
5002
5003             /*
5004              * Channels are numbered beginning with 0. For AdvanSys one host
5005              * structure supports one channel. Multi-channel boards have a
5006              * separate host structure for each channel.
5007              */
5008             shp->max_channel = 0;
5009             if (ASC_NARROW_BOARD(boardp)) {
5010                 shp->max_id = ASC_MAX_TID + 1;
5011                 shp->max_lun = ASC_MAX_LUN + 1;
5012
5013                 shp->io_port = asc_dvc_varp->iop_base;
5014                 boardp->asc_n_io_port = ASC_IOADR_GAP;
5015                 shp->this_id = asc_dvc_varp->cfg->chip_scsi_id;
5016
5017                 /* Set maximum number of queues the adapter can handle. */
5018                 shp->can_queue = asc_dvc_varp->max_total_qng;
5019             } else {
5020                 shp->max_id = ADV_MAX_TID + 1;
5021                 shp->max_lun = ADV_MAX_LUN + 1;
5022
5023                 /*
5024                  * Save the I/O Port address and length even though
5025                  * I/O ports are not used to access Wide boards.
5026                  * Instead the Wide boards are accessed with
5027                  * PCI Memory Mapped I/O.
5028                  */
5029                 shp->io_port = iop;
5030                 boardp->asc_n_io_port = iolen;
5031
5032                 shp->this_id = adv_dvc_varp->chip_scsi_id;
5033
5034                 /* Set maximum number of queues the adapter can handle. */
5035                 shp->can_queue = adv_dvc_varp->max_host_qng;
5036             }
5037
5038             /*
5039              * 'n_io_port' currently is one byte.
5040              *
5041              * Set a value to 'n_io_port', but never referenced it because
5042              * it may be truncated.
5043              */
5044             shp->n_io_port = boardp->asc_n_io_port <= 255 ?
5045                 boardp->asc_n_io_port : 255;
5046
5047             /*
5048              * Following v1.3.89, 'cmd_per_lun' is no longer needed
5049              * and should be set to zero.
5050              *
5051              * But because of a bug introduced in v1.3.89 if the driver is
5052              * compiled as a module and 'cmd_per_lun' is zero, the Mid-Level
5053              * SCSI function 'allocate_device' will panic. To allow the driver
5054              * to work as a module in these kernels set 'cmd_per_lun' to 1.
5055              *
5056              * Note: This is wrong.  cmd_per_lun should be set to the depth
5057              * you want on untagged devices always.
5058 #ifdef MODULE
5059              */
5060             shp->cmd_per_lun = 1;
5061 /* #else
5062             shp->cmd_per_lun = 0;
5063 #endif */
5064
5065             /*
5066              * Set the maximum number of scatter-gather elements the
5067              * adapter can handle.
5068              */
5069             if (ASC_NARROW_BOARD(boardp)) {
5070                 /*
5071                  * Allow two commands with 'sg_tablesize' scatter-gather
5072                  * elements to be executed simultaneously. This value is
5073                  * the theoretical hardware limit. It may be decreased
5074                  * below.
5075                  */
5076                 shp->sg_tablesize =
5077                     (((asc_dvc_varp->max_total_qng - 2) / 2) *
5078                     ASC_SG_LIST_PER_Q) + 1;
5079             } else {
5080                 shp->sg_tablesize = ADV_MAX_SG_LIST;
5081             }
5082
5083             /*
5084              * The value of 'sg_tablesize' can not exceed the SCSI
5085              * mid-level driver definition of SG_ALL. SG_ALL also
5086              * must not be exceeded, because it is used to define the
5087              * size of the scatter-gather table in 'struct asc_sg_head'.
5088              */
5089             if (shp->sg_tablesize > SG_ALL) {
5090                 shp->sg_tablesize = SG_ALL;
5091             }
5092
5093             ASC_DBG1(1, "advansys_detect: sg_tablesize: %d\n",
5094                 shp->sg_tablesize);
5095
5096             /* BIOS start address. */
5097             if (ASC_NARROW_BOARD(boardp)) {
5098                 shp->base =
5099                         ((ulong) AscGetChipBiosAddress(
5100                             asc_dvc_varp->iop_base,
5101                             asc_dvc_varp->bus_type));
5102             } else {
5103                 /*
5104                  * Fill-in BIOS board variables. The Wide BIOS saves
5105                  * information in LRAM that is used by the driver.
5106                  */
5107                 AdvReadWordLram(adv_dvc_varp->iop_base, BIOS_SIGNATURE,
5108                     boardp->bios_signature);
5109                 AdvReadWordLram(adv_dvc_varp->iop_base, BIOS_VERSION,
5110                     boardp->bios_version);
5111                 AdvReadWordLram(adv_dvc_varp->iop_base, BIOS_CODESEG,
5112                     boardp->bios_codeseg);
5113                 AdvReadWordLram(adv_dvc_varp->iop_base, BIOS_CODELEN,
5114                     boardp->bios_codelen);
5115
5116                 ASC_DBG2(1,
5117                     "advansys_detect: bios_signature 0x%x, bios_version 0x%x\n",
5118                     boardp->bios_signature, boardp->bios_version);
5119
5120                 ASC_DBG2(1,
5121                     "advansys_detect: bios_codeseg 0x%x, bios_codelen 0x%x\n",
5122                     boardp->bios_codeseg, boardp->bios_codelen);
5123
5124                 /*
5125                  * If the BIOS saved a valid signature, then fill in
5126                  * the BIOS code segment base address.
5127                  */
5128                 if (boardp->bios_signature == 0x55AA) {
5129                     /*
5130                      * Convert x86 realmode code segment to a linear
5131                      * address by shifting left 4.
5132                      */
5133                     shp->base = ((ulong) boardp->bios_codeseg << 4);
5134                 } else {
5135                     shp->base = 0;
5136                 }
5137             }
5138
5139             /*
5140              * Register Board Resources - I/O Port, DMA, IRQ
5141              */
5142
5143             /*
5144              * Register I/O port range.
5145              *
5146              * For Wide boards the I/O ports are not used to access
5147              * the board, but request the region anyway.
5148              *
5149              * 'shp->n_io_port' is not referenced, because it may be truncated.
5150              */
5151             ASC_DBG2(2,
5152                 "advansys_detect: request_region port 0x%lx, len 0x%x\n",
5153                 (ulong) shp->io_port, boardp->asc_n_io_port);
5154             if (request_region(shp->io_port, boardp->asc_n_io_port,
5155                                "advansys") == NULL) {
5156                 ASC_PRINT3(
5157 "advansys_detect: board %d: request_region() failed, port 0x%lx, len 0x%x\n",
5158                     boardp->id, (ulong) shp->io_port, boardp->asc_n_io_port);
5159 #ifdef CONFIG_PROC_FS
5160                 kfree(boardp->prtbuf);
5161 #endif /* CONFIG_PROC_FS */
5162                 scsi_unregister(shp);
5163                 asc_board_count--;
5164                 continue;
5165             }
5166
5167             /* Register DMA Channel for Narrow boards. */
5168             shp->dma_channel = NO_ISA_DMA; /* Default to no ISA DMA. */
5169 #ifdef CONFIG_ISA
5170             if (ASC_NARROW_BOARD(boardp)) {
5171                 /* Register DMA channel for ISA bus. */
5172                 if (asc_dvc_varp->bus_type & ASC_IS_ISA) {
5173                     shp->dma_channel = asc_dvc_varp->cfg->isa_dma_channel;
5174                     if ((ret =
5175                          request_dma(shp->dma_channel, "advansys")) != 0) {
5176                         ASC_PRINT3(
5177 "advansys_detect: board %d: request_dma() %d failed %d\n",
5178                             boardp->id, shp->dma_channel, ret);
5179                         release_region(shp->io_port, boardp->asc_n_io_port);
5180 #ifdef CONFIG_PROC_FS
5181                         kfree(boardp->prtbuf);
5182 #endif /* CONFIG_PROC_FS */
5183                         scsi_unregister(shp);
5184                         asc_board_count--;
5185                         continue;
5186                     }
5187                     AscEnableIsaDma(shp->dma_channel);
5188                 }
5189             }
5190 #endif /* CONFIG_ISA */
5191
5192             /* Register IRQ Number. */
5193             ASC_DBG1(2, "advansys_detect: request_irq() %d\n", shp->irq);
5194            /*
5195             * If request_irq() fails with the SA_INTERRUPT flag set,
5196             * then try again without the SA_INTERRUPT flag set. This
5197             * allows IRQ sharing to work even with other drivers that
5198             * do not set the SA_INTERRUPT flag.
5199             *
5200             * If SA_INTERRUPT is not set, then interrupts are enabled
5201             * before the driver interrupt function is called.
5202             */
5203             if (((ret = request_irq(shp->irq, advansys_interrupt,
5204                             SA_INTERRUPT | (share_irq == TRUE ? SA_SHIRQ : 0),
5205                             "advansys", boardp)) != 0) &&
5206                 ((ret = request_irq(shp->irq, advansys_interrupt,
5207                             (share_irq == TRUE ? SA_SHIRQ : 0),
5208                             "advansys", boardp)) != 0))
5209             {
5210                 if (ret == -EBUSY) {
5211                     ASC_PRINT2(
5212 "advansys_detect: board %d: request_irq(): IRQ 0x%x already in use.\n",
5213                         boardp->id, shp->irq);
5214                 } else if (ret == -EINVAL) {
5215                     ASC_PRINT2(
5216 "advansys_detect: board %d: request_irq(): IRQ 0x%x not valid.\n",
5217                         boardp->id, shp->irq);
5218                 } else {
5219                     ASC_PRINT3(
5220 "advansys_detect: board %d: request_irq(): IRQ 0x%x failed with %d\n",
5221                         boardp->id, shp->irq, ret);
5222                 }
5223                 release_region(shp->io_port, boardp->asc_n_io_port);
5224                 iounmap(boardp->ioremap_addr);
5225                 if (shp->dma_channel != NO_ISA_DMA) {
5226                     free_dma(shp->dma_channel);
5227                 }
5228 #ifdef CONFIG_PROC_FS
5229                 kfree(boardp->prtbuf);
5230 #endif /* CONFIG_PROC_FS */
5231                 scsi_unregister(shp);
5232                 asc_board_count--;
5233                 continue;
5234             }
5235
5236             /*
5237              * Initialize board RISC chip and enable interrupts.
5238              */
5239             if (ASC_NARROW_BOARD(boardp)) {
5240                 ASC_DBG(2, "advansys_detect: AscInitAsc1000Driver()\n");
5241                 warn_code = AscInitAsc1000Driver(asc_dvc_varp);
5242                 err_code = asc_dvc_varp->err_code;
5243
5244                 if (warn_code || err_code) {
5245                     ASC_PRINT4(
5246 "advansys_detect: board %d error: init_state 0x%x, warn 0x%x, error 0x%x\n",
5247                         boardp->id, asc_dvc_varp->init_state,
5248                         warn_code, err_code);
5249                 }
5250             } else {
5251                 ADV_CARR_T      *carrp;
5252                 int             req_cnt = 0;
5253                 adv_req_t       *reqp = NULL;
5254                 int             sg_cnt = 0;
5255
5256                 /*
5257                  * Allocate buffer carrier structures. The total size
5258                  * is about 4 KB, so allocate all at once.
5259                  */
5260                 carrp =
5261                     (ADV_CARR_T *) kmalloc(ADV_CARRIER_BUFSIZE, GFP_ATOMIC);
5262                 ASC_DBG1(1, "advansys_detect: carrp 0x%lx\n", (ulong) carrp);
5263
5264                 if (carrp == NULL) {
5265                     goto kmalloc_error;
5266                 }
5267
5268                 /*
5269                  * Allocate up to 'max_host_qng' request structures for
5270                  * the Wide board. The total size is about 16 KB, so
5271                  * allocate all at once. If the allocation fails decrement
5272                  * and try again.
5273                  */
5274                 for (req_cnt = adv_dvc_varp->max_host_qng;
5275                     req_cnt > 0; req_cnt--) {
5276
5277                     reqp = (adv_req_t *)
5278                         kmalloc(sizeof(adv_req_t) * req_cnt, GFP_ATOMIC);
5279
5280                     ASC_DBG3(1,
5281                         "advansys_detect: reqp 0x%lx, req_cnt %d, bytes %lu\n",
5282                         (ulong) reqp, req_cnt,
5283                         (ulong) sizeof(adv_req_t) * req_cnt);
5284
5285                     if (reqp != NULL) {
5286                         break;
5287                     }
5288                 }
5289                 if (reqp == NULL)
5290                 {
5291                     goto kmalloc_error;
5292                 }
5293
5294                 /*
5295                  * Allocate up to ADV_TOT_SG_BLOCK request structures for
5296                  * the Wide board. Each structure is about 136 bytes.
5297                  */
5298                 boardp->adv_sgblkp = NULL;
5299                 for (sg_cnt = 0; sg_cnt < ADV_TOT_SG_BLOCK; sg_cnt++) {
5300
5301                     sgp = (adv_sgblk_t *)
5302                         kmalloc(sizeof(adv_sgblk_t), GFP_ATOMIC);
5303
5304                     if (sgp == NULL) {
5305                         break;
5306                     }
5307
5308                     sgp->next_sgblkp = boardp->adv_sgblkp;
5309                     boardp->adv_sgblkp = sgp;
5310
5311                 }
5312                 ASC_DBG3(1,
5313                     "advansys_detect: sg_cnt %d * %u = %u bytes\n",
5314                     sg_cnt, sizeof(adv_sgblk_t),
5315                     (unsigned) (sizeof(adv_sgblk_t) * sg_cnt));
5316
5317                 /*
5318                  * If no request structures or scatter-gather structures could
5319                  * be allocated, then return an error. Otherwise continue with
5320                  * initialization.
5321                  */
5322     kmalloc_error:
5323                 if (carrp == NULL)
5324                 {
5325                     ASC_PRINT1(
5326 "advansys_detect: board %d error: failed to kmalloc() carrier buffer.\n",
5327                         boardp->id);
5328                     err_code = ADV_ERROR;
5329                 } else if (reqp == NULL) {
5330                     kfree(carrp);
5331                     ASC_PRINT1(
5332 "advansys_detect: board %d error: failed to kmalloc() adv_req_t buffer.\n",
5333                         boardp->id);
5334                     err_code = ADV_ERROR;
5335                 } else if (boardp->adv_sgblkp == NULL) {
5336                     kfree(carrp);
5337                     kfree(reqp);
5338                     ASC_PRINT1(
5339 "advansys_detect: board %d error: failed to kmalloc() adv_sgblk_t buffers.\n",
5340                         boardp->id);
5341                     err_code = ADV_ERROR;
5342                 } else {
5343
5344                     /* Save carrier buffer pointer. */
5345                     boardp->orig_carrp = carrp;
5346
5347                     /*
5348                      * Save original pointer for kfree() in case the
5349                      * driver is built as a module and can be unloaded.
5350                      */
5351                     boardp->orig_reqp = reqp;
5352
5353                     adv_dvc_varp->carrier_buf = carrp;
5354
5355                     /*
5356                      * Point 'adv_reqp' to the request structures and
5357                      * link them together.
5358                      */
5359                     req_cnt--;
5360                     reqp[req_cnt].next_reqp = NULL;
5361                     for (; req_cnt > 0; req_cnt--) {
5362                         reqp[req_cnt - 1].next_reqp = &reqp[req_cnt];
5363                     }
5364                     boardp->adv_reqp = &reqp[0];
5365
5366                     if (adv_dvc_varp->chip_type == ADV_CHIP_ASC3550)
5367                     {
5368                         ASC_DBG(2,
5369                             "advansys_detect: AdvInitAsc3550Driver()\n");
5370                         warn_code = AdvInitAsc3550Driver(adv_dvc_varp);
5371                     } else if (adv_dvc_varp->chip_type == ADV_CHIP_ASC38C0800) {
5372                         ASC_DBG(2,
5373                             "advansys_detect: AdvInitAsc38C0800Driver()\n");
5374                         warn_code = AdvInitAsc38C0800Driver(adv_dvc_varp);
5375                     } else {
5376                         ASC_DBG(2,
5377                             "advansys_detect: AdvInitAsc38C1600Driver()\n");
5378                         warn_code = AdvInitAsc38C1600Driver(adv_dvc_varp);
5379                     }
5380                     err_code = adv_dvc_varp->err_code;
5381
5382                     if (warn_code || err_code) {
5383                         ASC_PRINT3(
5384 "advansys_detect: board %d error: warn 0x%x, error 0x%x\n",
5385                             boardp->id, warn_code, err_code);
5386                     }
5387                 }
5388             }
5389
5390             if (err_code != 0) {
5391                 release_region(shp->io_port, boardp->asc_n_io_port);
5392                 if (ASC_WIDE_BOARD(boardp)) {
5393                     iounmap(boardp->ioremap_addr);
5394                     kfree(boardp->orig_carrp);
5395                     boardp->orig_carrp = NULL;
5396                     if (boardp->orig_reqp) {
5397                         kfree(boardp->orig_reqp);
5398                         boardp->orig_reqp = boardp->adv_reqp = NULL;
5399                     }
5400                     while ((sgp = boardp->adv_sgblkp) != NULL)
5401                     {
5402                         boardp->adv_sgblkp = sgp->next_sgblkp;
5403                         kfree(sgp);
5404                     }
5405                 }
5406                 if (shp->dma_channel != NO_ISA_DMA) {
5407                     free_dma(shp->dma_channel);
5408                 }
5409 #ifdef CONFIG_PROC_FS
5410                 kfree(boardp->prtbuf);
5411 #endif /* CONFIG_PROC_FS */
5412                 free_irq(shp->irq, boardp);
5413                 scsi_unregister(shp);
5414                 asc_board_count--;
5415                 continue;
5416             }
5417             ASC_DBG_PRT_SCSI_HOST(2, shp);
5418         }
5419     }
5420
5421     ASC_DBG1(1, "advansys_detect: done: asc_board_count %d\n", asc_board_count);
5422     return asc_board_count;
5423 }
5424
5425 /*
5426  * advansys_release()
5427  *
5428  * Release resources allocated for a single AdvanSys adapter.
5429  */
5430 int
5431 advansys_release(struct Scsi_Host *shp)
5432 {
5433     asc_board_t    *boardp;
5434
5435     ASC_DBG(1, "advansys_release: begin\n");
5436     boardp = ASC_BOARDP(shp);
5437     free_irq(shp->irq, boardp);
5438     if (shp->dma_channel != NO_ISA_DMA) {
5439         ASC_DBG(1, "advansys_release: free_dma()\n");
5440         free_dma(shp->dma_channel);
5441     }
5442     release_region(shp->io_port, boardp->asc_n_io_port);
5443     if (ASC_WIDE_BOARD(boardp)) {
5444         adv_sgblk_t    *sgp = NULL;
5445
5446         iounmap(boardp->ioremap_addr);
5447         kfree(boardp->orig_carrp);
5448         boardp->orig_carrp = NULL;
5449         if (boardp->orig_reqp) {
5450             kfree(boardp->orig_reqp);
5451             boardp->orig_reqp = boardp->adv_reqp = NULL;
5452         }
5453         while ((sgp = boardp->adv_sgblkp) != NULL)
5454         {
5455             boardp->adv_sgblkp = sgp->next_sgblkp;
5456             kfree(sgp);
5457         }
5458     }
5459 #ifdef CONFIG_PROC_FS
5460     ASC_ASSERT(boardp->prtbuf != NULL);
5461     kfree(boardp->prtbuf);
5462 #endif /* CONFIG_PROC_FS */
5463     scsi_unregister(shp);
5464     ASC_DBG(1, "advansys_release: end\n");
5465     return 0;
5466 }
5467
5468 /*
5469  * advansys_info()
5470  *
5471  * Return suitable for printing on the console with the argument
5472  * adapter's configuration information.
5473  *
5474  * Note: The information line should not exceed ASC_INFO_SIZE bytes,
5475  * otherwise the static 'info' array will be overrun.
5476  */
5477 const char *
5478 advansys_info(struct Scsi_Host *shp)
5479 {
5480     static char     info[ASC_INFO_SIZE];
5481     asc_board_t     *boardp;
5482     ASC_DVC_VAR     *asc_dvc_varp;
5483     ADV_DVC_VAR     *adv_dvc_varp;
5484     char            *busname;
5485     int             iolen;
5486     char            *widename = NULL;
5487
5488     boardp = ASC_BOARDP(shp);
5489     if (ASC_NARROW_BOARD(boardp)) {
5490         asc_dvc_varp = &boardp->dvc_var.asc_dvc_var;
5491         ASC_DBG(1, "advansys_info: begin\n");
5492         if (asc_dvc_varp->bus_type & ASC_IS_ISA) {
5493             if ((asc_dvc_varp->bus_type & ASC_IS_ISAPNP) == ASC_IS_ISAPNP) {
5494                 busname = "ISA PnP";
5495             } else {
5496                 busname = "ISA";
5497             }
5498             /* Don't reference 'shp->n_io_port'; It may be truncated. */
5499             sprintf(info,
5500 "AdvanSys SCSI %s: %s: IO 0x%lX-0x%lX, IRQ 0x%X, DMA 0x%X",
5501                 ASC_VERSION, busname,
5502                 (ulong) shp->io_port,
5503                 (ulong) shp->io_port + boardp->asc_n_io_port - 1,
5504                 shp->irq, shp->dma_channel);
5505         } else {
5506             if (asc_dvc_varp->bus_type & ASC_IS_VL) {
5507                 busname = "VL";
5508             } else if (asc_dvc_varp->bus_type & ASC_IS_EISA) {
5509                 busname = "EISA";
5510             } else if (asc_dvc_varp->bus_type & ASC_IS_PCI) {
5511                 if ((asc_dvc_varp->bus_type & ASC_IS_PCI_ULTRA)
5512                     == ASC_IS_PCI_ULTRA) {
5513                     busname = "PCI Ultra";
5514                 } else {
5515                     busname = "PCI";
5516                 }
5517             } else {
5518                 busname = "?";
5519                 ASC_PRINT2( "advansys_info: board %d: unknown bus type %d\n",
5520                     boardp->id, asc_dvc_varp->bus_type);
5521             }
5522             /* Don't reference 'shp->n_io_port'; It may be truncated. */
5523             sprintf(info,
5524                 "AdvanSys SCSI %s: %s: IO 0x%lX-0x%lX, IRQ 0x%X",
5525                 ASC_VERSION, busname,
5526                 (ulong) shp->io_port,
5527                 (ulong) shp->io_port + boardp->asc_n_io_port - 1,
5528                 shp->irq);
5529         }
5530     } else {
5531         /*
5532          * Wide Adapter Information
5533          *
5534          * Memory-mapped I/O is used instead of I/O space to access
5535          * the adapter, but display the I/O Port range. The Memory
5536          * I/O address is displayed through the driver /proc file.
5537          */
5538         adv_dvc_varp = &boardp->dvc_var.adv_dvc_var;
5539         if (adv_dvc_varp->chip_type == ADV_CHIP_ASC3550)
5540         {
5541             iolen = ADV_3550_IOLEN;
5542             widename = "Ultra-Wide";
5543         } else if (adv_dvc_varp->chip_type == ADV_CHIP_ASC38C0800)
5544         {
5545             iolen = ADV_38C0800_IOLEN;
5546             widename = "Ultra2-Wide";
5547         } else
5548         {
5549             iolen = ADV_38C1600_IOLEN;
5550             widename = "Ultra3-Wide";
5551         }
5552         sprintf(info, "AdvanSys SCSI %s: PCI %s: PCIMEM 0x%lX-0x%lX, IRQ 0x%X",
5553             ASC_VERSION,
5554             widename,
5555             (ulong) adv_dvc_varp->iop_base,
5556             (ulong) adv_dvc_varp->iop_base + iolen - 1,
5557             shp->irq);
5558     }
5559     ASC_ASSERT(strlen(info) < ASC_INFO_SIZE);
5560     ASC_DBG(1, "advansys_info: end\n");
5561     return info;
5562 }
5563
5564 /*
5565  * advansys_queuecommand() - interrupt-driven I/O entrypoint.
5566  *
5567  * This function always returns 0. Command return status is saved
5568  * in the 'scp' result field.
5569  */
5570 int
5571 advansys_queuecommand(struct scsi_cmnd *scp, void (*done)(struct scsi_cmnd *))
5572 {
5573     struct Scsi_Host    *shp;
5574     asc_board_t         *boardp;
5575     ulong               flags;
5576     struct scsi_cmnd           *done_scp;
5577
5578     shp = scp->device->host;
5579     boardp = ASC_BOARDP(shp);
5580     ASC_STATS(shp, queuecommand);
5581
5582     /* host_lock taken by mid-level prior to call but need to protect */
5583     /* against own ISR */
5584     spin_lock_irqsave(&boardp->lock, flags);
5585
5586     /*
5587      * Block new commands while handling a reset or abort request.
5588      */
5589     if (boardp->flags & ASC_HOST_IN_RESET) {
5590         ASC_DBG1(1,
5591             "advansys_queuecommand: scp 0x%lx blocked for reset request\n",
5592             (ulong) scp);
5593         scp->result = HOST_BYTE(DID_RESET);
5594
5595         /*
5596          * Add blocked requests to the board's 'done' queue. The queued
5597          * requests will be completed at the end of the abort or reset
5598          * handling.
5599          */
5600         asc_enqueue(&boardp->done, scp, ASC_BACK);
5601         spin_unlock_irqrestore(&boardp->lock, flags);
5602         return 0;
5603     }
5604
5605     /*
5606      * Attempt to execute any waiting commands for the board.
5607      */
5608     if (!ASC_QUEUE_EMPTY(&boardp->waiting)) {
5609         ASC_DBG(1,
5610             "advansys_queuecommand: before asc_execute_queue() waiting\n");
5611         asc_execute_queue(&boardp->waiting);
5612     }
5613
5614     /*
5615      * Save the function pointer to Linux mid-level 'done' function
5616      * and attempt to execute the command.
5617      *
5618      * If ASC_NOERROR is returned the request has been added to the
5619      * board's 'active' queue and will be completed by the interrupt
5620      * handler.
5621      *
5622      * If ASC_BUSY is returned add the request to the board's per
5623      * target waiting list. This is the first time the request has
5624      * been tried. Add it to the back of the waiting list. It will be
5625      * retried later.
5626      *
5627      * If an error occurred, the request will have been placed on the
5628      * board's 'done' queue and must be completed before returning.
5629      */
5630     scp->scsi_done = done;
5631     switch (asc_execute_scsi_cmnd(scp)) {
5632     case ASC_NOERROR:
5633         break;
5634     case ASC_BUSY:
5635         asc_enqueue(&boardp->waiting, scp, ASC_BACK);
5636         break;
5637     case ASC_ERROR:
5638     default:
5639         done_scp = asc_dequeue_list(&boardp->done, NULL, ASC_TID_ALL);
5640         /* Interrupts could be enabled here. */
5641         asc_scsi_done_list(done_scp);
5642         break;
5643     }
5644     spin_unlock_irqrestore(&boardp->lock, flags);
5645
5646     return 0;
5647 }
5648
5649 /*
5650  * advansys_reset()
5651  *
5652  * Reset the bus associated with the command 'scp'.
5653  *
5654  * This function runs its own thread. Interrupts must be blocked but
5655  * sleeping is allowed and no locking other than for host structures is
5656  * required. Returns SUCCESS or FAILED.
5657  */
5658 int
5659 advansys_reset(struct scsi_cmnd *scp)
5660 {
5661     struct Scsi_Host     *shp;
5662     asc_board_t          *boardp;
5663     ASC_DVC_VAR          *asc_dvc_varp;
5664     ADV_DVC_VAR          *adv_dvc_varp;
5665     ulong                flags;
5666     struct scsi_cmnd            *done_scp = NULL, *last_scp = NULL;
5667     struct scsi_cmnd            *tscp, *new_last_scp;
5668     int                  status;
5669     int                  ret = SUCCESS;
5670
5671     ASC_DBG1(1, "advansys_reset: 0x%lx\n", (ulong) scp);
5672
5673 #ifdef ADVANSYS_STATS
5674     if (scp->device->host != NULL) {
5675         ASC_STATS(scp->device->host, reset);
5676     }
5677 #endif /* ADVANSYS_STATS */
5678
5679     if ((shp = scp->device->host) == NULL) {
5680         scp->result = HOST_BYTE(DID_ERROR);
5681         return FAILED;
5682     }
5683
5684     boardp = ASC_BOARDP(shp);
5685
5686     ASC_PRINT1("advansys_reset: board %d: SCSI bus reset started...\n",
5687         boardp->id);
5688     /*
5689      * Check for re-entrancy.
5690      */
5691     spin_lock_irqsave(&boardp->lock, flags);
5692     if (boardp->flags & ASC_HOST_IN_RESET) {
5693         spin_unlock_irqrestore(&boardp->lock, flags);
5694         return FAILED;
5695     }
5696     boardp->flags |= ASC_HOST_IN_RESET;
5697     spin_unlock_irqrestore(&boardp->lock, flags);
5698
5699     if (ASC_NARROW_BOARD(boardp)) {
5700         /*
5701          * Narrow Board
5702          */
5703         asc_dvc_varp = &boardp->dvc_var.asc_dvc_var;
5704
5705         /*
5706          * Reset the chip and SCSI bus.
5707          */
5708         ASC_DBG(1, "advansys_reset: before AscInitAsc1000Driver()\n");
5709         status = AscInitAsc1000Driver(asc_dvc_varp);
5710
5711         /* Refer to ASC_IERR_* defintions for meaning of 'err_code'. */
5712         if (asc_dvc_varp->err_code) {
5713             ASC_PRINT2(
5714                 "advansys_reset: board %d: SCSI bus reset error: 0x%x\n",
5715                 boardp->id, asc_dvc_varp->err_code);
5716             ret = FAILED;
5717         } else if (status) {
5718             ASC_PRINT2(
5719                 "advansys_reset: board %d: SCSI bus reset warning: 0x%x\n",
5720                 boardp->id, status);
5721         } else {
5722             ASC_PRINT1(
5723                 "advansys_reset: board %d: SCSI bus reset successful.\n",
5724                 boardp->id);
5725         }
5726
5727         ASC_DBG(1, "advansys_reset: after AscInitAsc1000Driver()\n");
5728         spin_lock_irqsave(&boardp->lock, flags);
5729
5730     } else {
5731         /*
5732          * Wide Board
5733          *
5734          * If the suggest reset bus flags are set, then reset the bus.
5735          * Otherwise only reset the device.
5736          */
5737         adv_dvc_varp = &boardp->dvc_var.adv_dvc_var;
5738
5739         /*
5740          * Reset the target's SCSI bus.
5741          */
5742         ASC_DBG(1, "advansys_reset: before AdvResetChipAndSB()\n");
5743         switch (AdvResetChipAndSB(adv_dvc_varp)) {
5744         case ASC_TRUE:
5745             ASC_PRINT1("advansys_reset: board %d: SCSI bus reset successful.\n",
5746                 boardp->id);
5747             break;
5748         case ASC_FALSE:
5749         default:
5750             ASC_PRINT1("advansys_reset: board %d: SCSI bus reset error.\n",
5751                 boardp->id);
5752             ret = FAILED;
5753             break;
5754         }
5755         spin_lock_irqsave(&boardp->lock, flags);
5756         (void) AdvISR(adv_dvc_varp);
5757     }
5758     /* Board lock is held. */
5759
5760     /*
5761      * Dequeue all board 'done' requests. A pointer to the last request
5762      * is returned in 'last_scp'.
5763      */
5764     done_scp = asc_dequeue_list(&boardp->done, &last_scp, ASC_TID_ALL);
5765
5766     /*
5767      * Dequeue all board 'active' requests for all devices and set
5768      * the request status to DID_RESET. A pointer to the last request
5769      * is returned in 'last_scp'.
5770      */
5771     if (done_scp == NULL) {
5772         done_scp = asc_dequeue_list(&boardp->active, &last_scp, ASC_TID_ALL);
5773         for (tscp = done_scp; tscp; tscp = REQPNEXT(tscp)) {
5774             tscp->result = HOST_BYTE(DID_RESET);
5775         }
5776     } else {
5777         /* Append to 'done_scp' at the end with 'last_scp'. */
5778         ASC_ASSERT(last_scp != NULL);
5779         last_scp->host_scribble = (unsigned char *)asc_dequeue_list(
5780                         &boardp->active, &new_last_scp, ASC_TID_ALL);
5781         if (new_last_scp != NULL) {
5782             ASC_ASSERT(REQPNEXT(last_scp) != NULL);
5783             for (tscp = REQPNEXT(last_scp); tscp; tscp = REQPNEXT(tscp)) {
5784                 tscp->result = HOST_BYTE(DID_RESET);
5785             }
5786             last_scp = new_last_scp;
5787         }
5788     }
5789
5790     /*
5791      * Dequeue all 'waiting' requests and set the request status
5792      * to DID_RESET.
5793      */
5794     if (done_scp == NULL) {
5795         done_scp = asc_dequeue_list(&boardp->waiting, &last_scp, ASC_TID_ALL);
5796         for (tscp = done_scp; tscp; tscp = REQPNEXT(tscp)) {
5797             tscp->result = HOST_BYTE(DID_RESET);
5798         }
5799     } else {
5800         /* Append to 'done_scp' at the end with 'last_scp'. */
5801         ASC_ASSERT(last_scp != NULL);
5802         last_scp->host_scribble = (unsigned char *)asc_dequeue_list(
5803                         &boardp->waiting, &new_last_scp, ASC_TID_ALL);
5804         if (new_last_scp != NULL) {
5805             ASC_ASSERT(REQPNEXT(last_scp) != NULL);
5806             for (tscp = REQPNEXT(last_scp); tscp; tscp = REQPNEXT(tscp)) {
5807                 tscp->result = HOST_BYTE(DID_RESET);
5808             }
5809             last_scp = new_last_scp;
5810         }
5811     }
5812
5813     /* Save the time of the most recently completed reset. */
5814     boardp->last_reset = jiffies;
5815
5816     /* Clear reset flag. */
5817     boardp->flags &= ~ASC_HOST_IN_RESET;
5818     spin_unlock_irqrestore(&boardp->lock, flags);
5819
5820     /*
5821      * Complete all the 'done_scp' requests.
5822      */
5823     if (done_scp != NULL) {
5824         asc_scsi_done_list(done_scp);
5825     }
5826
5827     ASC_DBG1(1, "advansys_reset: ret %d\n", ret);
5828
5829     return ret;
5830 }
5831
5832 /*
5833  * advansys_biosparam()
5834  *
5835  * Translate disk drive geometry if the "BIOS greater than 1 GB"
5836  * support is enabled for a drive.
5837  *
5838  * ip (information pointer) is an int array with the following definition:
5839  * ip[0]: heads
5840  * ip[1]: sectors
5841  * ip[2]: cylinders
5842  */
5843 int
5844 advansys_biosparam(struct scsi_device *sdev, struct block_device *bdev,
5845                 sector_t capacity, int ip[])
5846 {
5847     asc_board_t     *boardp;
5848
5849     ASC_DBG(1, "advansys_biosparam: begin\n");
5850     ASC_STATS(sdev->host, biosparam);
5851     boardp = ASC_BOARDP(sdev->host);
5852     if (ASC_NARROW_BOARD(boardp)) {
5853         if ((boardp->dvc_var.asc_dvc_var.dvc_cntl &
5854              ASC_CNTL_BIOS_GT_1GB) && capacity > 0x200000) {
5855                 ip[0] = 255;
5856                 ip[1] = 63;
5857         } else {
5858                 ip[0] = 64;
5859                 ip[1] = 32;
5860         }
5861     } else {
5862         if ((boardp->dvc_var.adv_dvc_var.bios_ctrl &
5863              BIOS_CTRL_EXTENDED_XLAT) && capacity > 0x200000) {
5864                 ip[0] = 255;
5865                 ip[1] = 63;
5866         } else {
5867                 ip[0] = 64;
5868                 ip[1] = 32;
5869         }
5870     }
5871     ip[2] = (unsigned long)capacity / (ip[0] * ip[1]);
5872     ASC_DBG(1, "advansys_biosparam: end\n");
5873     return 0;
5874 }
5875
5876 /*
5877  * advansys_setup()
5878  *
5879  * This function is called from init/main.c at boot time.
5880  * It it passed LILO parameters that can be set from the
5881  * LILO command line or in /etc/lilo.conf.
5882  *
5883  * It is used by the AdvanSys driver to either disable I/O
5884  * port scanning or to limit scanning to 1 - 4 I/O ports.
5885  * Regardless of the option setting EISA and PCI boards
5886  * will still be searched for and detected. This option
5887  * only affects searching for ISA and VL boards.
5888  *
5889  * If ADVANSYS_DEBUG is defined the driver debug level may
5890  * be set using the 5th (ASC_NUM_IOPORT_PROBE + 1) I/O Port.
5891  *
5892  * Examples:
5893  * 1. Eliminate I/O port scanning:
5894  *         boot: linux advansys=
5895  *       or
5896  *         boot: linux advansys=0x0
5897  * 2. Limit I/O port scanning to one I/O port:
5898  *        boot: linux advansys=0x110
5899  * 3. Limit I/O port scanning to four I/O ports:
5900  *        boot: linux advansys=0x110,0x210,0x230,0x330
5901  * 4. If ADVANSYS_DEBUG, limit I/O port scanning to four I/O ports and
5902  *    set the driver debug level to 2.
5903  *        boot: linux advansys=0x110,0x210,0x230,0x330,0xdeb2
5904  *
5905  * ints[0] - number of arguments
5906  * ints[1] - first argument
5907  * ints[2] - second argument
5908  * ...
5909  */
5910 void __init
5911 advansys_setup(char *str, int *ints)
5912 {
5913     int    i;
5914
5915     if (asc_iopflag == ASC_TRUE) {
5916         printk("AdvanSys SCSI: 'advansys' LILO option may appear only once\n");
5917         return;
5918     }
5919
5920     asc_iopflag = ASC_TRUE;
5921
5922     if (ints[0] > ASC_NUM_IOPORT_PROBE) {
5923 #ifdef ADVANSYS_DEBUG
5924         if ((ints[0] == ASC_NUM_IOPORT_PROBE + 1) &&
5925             (ints[ASC_NUM_IOPORT_PROBE + 1] >> 4 == 0xdeb)) {
5926             asc_dbglvl = ints[ASC_NUM_IOPORT_PROBE + 1] & 0xf;
5927         } else {
5928 #endif /* ADVANSYS_DEBUG */
5929             printk("AdvanSys SCSI: only %d I/O ports accepted\n",
5930                 ASC_NUM_IOPORT_PROBE);
5931 #ifdef ADVANSYS_DEBUG
5932         }
5933 #endif /* ADVANSYS_DEBUG */
5934     }
5935
5936 #ifdef ADVANSYS_DEBUG
5937     ASC_DBG1(1, "advansys_setup: ints[0] %d\n", ints[0]);
5938     for (i = 1; i < ints[0]; i++) {
5939         ASC_DBG2(1, " ints[%d] 0x%x", i, ints[i]);
5940     }
5941     ASC_DBG(1, "\n");
5942 #endif /* ADVANSYS_DEBUG */
5943
5944     for (i = 1; i <= ints[0] && i <= ASC_NUM_IOPORT_PROBE; i++) {
5945         asc_ioport[i-1] = ints[i];
5946         ASC_DBG2(1, "advansys_setup: asc_ioport[%d] 0x%x\n",
5947             i - 1, asc_ioport[i-1]);
5948     }
5949 }
5950
5951
5952 /*
5953  * --- Loadable Driver Support
5954  */
5955
5956 static struct scsi_host_template driver_template = {
5957     .proc_name                  = "advansys",
5958 #ifdef CONFIG_PROC_FS
5959     .proc_info                  = advansys_proc_info,
5960 #endif
5961     .name                       = "advansys",
5962     .detect                     = advansys_detect, 
5963     .release                    = advansys_release,
5964     .info                       = advansys_info,
5965     .queuecommand               = advansys_queuecommand,
5966     .eh_bus_reset_handler       = advansys_reset,
5967     .bios_param                 = advansys_biosparam,
5968     .slave_configure            = advansys_slave_configure,
5969     /*
5970      * Because the driver may control an ISA adapter 'unchecked_isa_dma'
5971      * must be set. The flag will be cleared in advansys_detect for non-ISA
5972      * adapters. Refer to the comment in scsi_module.c for more information.
5973      */
5974     .unchecked_isa_dma          = 1,
5975     /*
5976      * All adapters controlled by this driver are capable of large
5977      * scatter-gather lists. According to the mid-level SCSI documentation
5978      * this obviates any performance gain provided by setting
5979      * 'use_clustering'. But empirically while CPU utilization is increased
5980      * by enabling clustering, I/O throughput increases as well.
5981      */
5982     .use_clustering             = ENABLE_CLUSTERING,
5983 };
5984 #include "scsi_module.c"
5985
5986
5987 /*
5988  * --- Miscellaneous Driver Functions
5989  */
5990
5991 /*
5992  * First-level interrupt handler.
5993  *
5994  * 'dev_id' is a pointer to the interrupting adapter's asc_board_t. Because
5995  * all boards are currently checked for interrupts on each interrupt, 'dev_id'
5996  * is not referenced. 'dev_id' could be used to identify an interrupt passed
5997  * to the AdvanSys driver which is for a device sharing an interrupt with
5998  * an AdvanSys adapter.
5999  */
6000 STATIC irqreturn_t
6001 advansys_interrupt(int irq, void *dev_id, struct pt_regs *regs)
6002 {
6003     ulong           flags;
6004     int             i;
6005     asc_board_t     *boardp;
6006     struct scsi_cmnd       *done_scp = NULL, *last_scp = NULL;
6007     struct scsi_cmnd       *new_last_scp;
6008     struct Scsi_Host *shp;
6009
6010     ASC_DBG(1, "advansys_interrupt: begin\n");
6011
6012     /*
6013      * Check for interrupts on all boards.
6014      * AscISR() will call asc_isr_callback().
6015      */
6016     for (i = 0; i < asc_board_count; i++) {
6017         shp = asc_host[i];
6018         boardp = ASC_BOARDP(shp);
6019         ASC_DBG2(2, "advansys_interrupt: i %d, boardp 0x%lx\n",
6020             i, (ulong) boardp);
6021         spin_lock_irqsave(&boardp->lock, flags);
6022         if (ASC_NARROW_BOARD(boardp)) {
6023             /*
6024              * Narrow Board
6025              */
6026             if (AscIsIntPending(shp->io_port)) {
6027                 ASC_STATS(shp, interrupt);
6028                 ASC_DBG(1, "advansys_interrupt: before AscISR()\n");
6029                 AscISR(&boardp->dvc_var.asc_dvc_var);
6030             }
6031         } else {
6032             /*
6033              * Wide Board
6034              */
6035             ASC_DBG(1, "advansys_interrupt: before AdvISR()\n");
6036             if (AdvISR(&boardp->dvc_var.adv_dvc_var)) {
6037                 ASC_STATS(shp, interrupt);
6038             }
6039         }
6040
6041         /*
6042          * Start waiting requests and create a list of completed requests.
6043          *
6044          * If a reset request is being performed for the board, the reset
6045          * handler will complete pending requests after it has completed.
6046          */
6047         if ((boardp->flags & ASC_HOST_IN_RESET) == 0) {
6048             ASC_DBG2(1, "advansys_interrupt: done_scp 0x%lx, last_scp 0x%lx\n",
6049                 (ulong) done_scp, (ulong) last_scp);
6050
6051             /* Start any waiting commands for the board. */
6052             if (!ASC_QUEUE_EMPTY(&boardp->waiting)) {
6053                 ASC_DBG(1, "advansys_interrupt: before asc_execute_queue()\n");
6054                 asc_execute_queue(&boardp->waiting);
6055             }
6056
6057              /*
6058               * Add to the list of requests that must be completed.
6059               *
6060               * 'done_scp' will always be NULL on the first iteration
6061               * of this loop. 'last_scp' is set at the same time as
6062               * 'done_scp'.
6063               */
6064             if (done_scp == NULL) {
6065                 done_scp = asc_dequeue_list(&boardp->done, &last_scp,
6066                     ASC_TID_ALL);
6067             } else {
6068                 ASC_ASSERT(last_scp != NULL);
6069                 last_scp->host_scribble = (unsigned char *)asc_dequeue_list(
6070                         &boardp->done, &new_last_scp, ASC_TID_ALL);
6071                 if (new_last_scp != NULL) {
6072                     ASC_ASSERT(REQPNEXT(last_scp) != NULL);
6073                     last_scp = new_last_scp;
6074                 }
6075             }
6076         }
6077         spin_unlock_irqrestore(&boardp->lock, flags);
6078     }
6079
6080     /*
6081      * If interrupts were enabled on entry, then they
6082      * are now enabled here.
6083      *
6084      * Complete all requests on the done list.
6085      */
6086
6087     asc_scsi_done_list(done_scp);
6088
6089     ASC_DBG(1, "advansys_interrupt: end\n");
6090     return IRQ_HANDLED;
6091 }
6092
6093 /*
6094  * Set the number of commands to queue per device for the
6095  * specified host adapter.
6096  */
6097 STATIC int
6098 advansys_slave_configure(struct scsi_device *device)
6099 {
6100     asc_board_t        *boardp;
6101
6102     boardp = ASC_BOARDP(device->host);
6103     boardp->flags |= ASC_SELECT_QUEUE_DEPTHS;
6104     /*
6105      * Save a pointer to the device and set its initial/maximum
6106      * queue depth.  Only save the pointer for a lun0 dev though.
6107      */
6108     if(device->lun == 0)
6109         boardp->device[device->id] = device;
6110     if(device->tagged_supported) {
6111         if (ASC_NARROW_BOARD(boardp)) {
6112             scsi_adjust_queue_depth(device, MSG_ORDERED_TAG,
6113                 boardp->dvc_var.asc_dvc_var.max_dvc_qng[device->id]);
6114         } else {
6115             scsi_adjust_queue_depth(device, MSG_ORDERED_TAG,
6116                 boardp->dvc_var.adv_dvc_var.max_dvc_qng);
6117         }
6118     } else {
6119         scsi_adjust_queue_depth(device, 0, device->host->cmd_per_lun);
6120     }
6121     ASC_DBG4(1, "advansys_slave_configure: device 0x%lx, boardp 0x%lx, id %d, depth %d\n",
6122             (ulong) device, (ulong) boardp, device->id, device->queue_depth);
6123     return 0;
6124 }
6125
6126 /*
6127  * Complete all requests on the singly linked list pointed
6128  * to by 'scp'.
6129  *
6130  * Interrupts can be enabled on entry.
6131  */
6132 STATIC void
6133 asc_scsi_done_list(struct scsi_cmnd *scp)
6134 {
6135     struct scsi_cmnd    *tscp;
6136
6137     ASC_DBG(2, "asc_scsi_done_list: begin\n");
6138     while (scp != NULL) {
6139         asc_board_t *boardp;
6140         struct device *dev;
6141
6142         ASC_DBG1(3, "asc_scsi_done_list: scp 0x%lx\n", (ulong) scp);
6143         tscp = REQPNEXT(scp);
6144         scp->host_scribble = NULL;
6145
6146         boardp = ASC_BOARDP(scp->device->host);
6147
6148         if (ASC_NARROW_BOARD(boardp))
6149             dev = boardp->dvc_cfg.asc_dvc_cfg.dev;
6150         else
6151             dev = boardp->dvc_cfg.adv_dvc_cfg.dev;
6152
6153         if (scp->use_sg)
6154             dma_unmap_sg(dev, (struct scatterlist *)scp->request_buffer,
6155                          scp->use_sg, scp->sc_data_direction);
6156         else if (scp->request_bufflen)
6157             dma_unmap_single(dev, scp->SCp.dma_handle,
6158                              scp->request_bufflen, scp->sc_data_direction);
6159
6160         ASC_STATS(scp->device->host, done);
6161         ASC_ASSERT(scp->scsi_done != NULL);
6162
6163         scp->scsi_done(scp);
6164
6165         scp = tscp;
6166     }
6167     ASC_DBG(2, "asc_scsi_done_list: done\n");
6168     return;
6169 }
6170
6171 /*
6172  * Execute a single 'Scsi_Cmnd'.
6173  *
6174  * The function 'done' is called when the request has been completed.
6175  *
6176  * Scsi_Cmnd:
6177  *
6178  *  host - board controlling device
6179  *  device - device to send command
6180  *  target - target of device
6181  *  lun - lun of device
6182  *  cmd_len - length of SCSI CDB
6183  *  cmnd - buffer for SCSI 8, 10, or 12 byte CDB
6184  *  use_sg - if non-zero indicates scatter-gather request with use_sg elements
6185  *
6186  *  if (use_sg == 0) {
6187  *    request_buffer - buffer address for request
6188  *    request_bufflen - length of request buffer
6189  *  } else {
6190  *    request_buffer - pointer to scatterlist structure
6191  *  }
6192  *
6193  *  sense_buffer - sense command buffer
6194  *
6195  *  result (4 bytes of an int):
6196  *    Byte Meaning
6197  *    0 SCSI Status Byte Code
6198  *    1 SCSI One Byte Message Code
6199  *    2 Host Error Code
6200  *    3 Mid-Level Error Code
6201  *
6202  *  host driver fields:
6203  *    SCp - Scsi_Pointer used for command processing status
6204  *    scsi_done - used to save caller's done function
6205  *    host_scribble - used for pointer to another struct scsi_cmnd
6206  *
6207  * If this function returns ASC_NOERROR the request has been enqueued
6208  * on the board's 'active' queue and will be completed from the
6209  * interrupt handler.
6210  *
6211  * If this function returns ASC_NOERROR the request has been enqueued
6212  * on the board's 'done' queue and must be completed by the caller.
6213  *
6214  * If ASC_BUSY is returned the request will be enqueued by the
6215  * caller on the target's waiting queue and re-tried later.
6216  */
6217 STATIC int
6218 asc_execute_scsi_cmnd(struct scsi_cmnd *scp)
6219 {
6220     asc_board_t        *boardp;
6221     ASC_DVC_VAR        *asc_dvc_varp;
6222     ADV_DVC_VAR        *adv_dvc_varp;
6223     ADV_SCSI_REQ_Q     *adv_scsiqp;
6224     struct scsi_device *device;
6225     int                ret;
6226
6227     ASC_DBG2(1, "asc_execute_scsi_cmnd: scp 0x%lx, done 0x%lx\n",
6228         (ulong) scp, (ulong) scp->scsi_done);
6229
6230     boardp = ASC_BOARDP(scp->device->host);
6231     device = boardp->device[scp->device->id];
6232
6233     if (ASC_NARROW_BOARD(boardp)) {
6234         /*
6235          * Build and execute Narrow Board request.
6236          */
6237
6238         asc_dvc_varp = &boardp->dvc_var.asc_dvc_var;
6239
6240         /*
6241          * Build Asc Library request structure using the
6242          * global structures 'asc_scsi_req' and 'asc_sg_head'.
6243          *
6244          * If an error is returned, then the request has been
6245          * queued on the board done queue. It will be completed
6246          * by the caller.
6247          *
6248          * asc_build_req() can not return ASC_BUSY.
6249          */
6250         if (asc_build_req(boardp, scp) == ASC_ERROR) {
6251             ASC_STATS(scp->device->host, build_error);
6252             return ASC_ERROR;
6253         }
6254
6255         /*
6256          * Execute the command. If there is no error, add the command
6257          * to the active queue.
6258          */
6259         switch (ret = AscExeScsiQueue(asc_dvc_varp, &asc_scsi_q)) {
6260         case ASC_NOERROR:
6261             ASC_STATS(scp->device->host, exe_noerror);
6262             /*
6263              * Increment monotonically increasing per device successful
6264              * request counter. Wrapping doesn't matter.
6265              */
6266             boardp->reqcnt[scp->device->id]++;
6267             asc_enqueue(&boardp->active, scp, ASC_BACK);
6268             ASC_DBG(1,
6269                 "asc_execute_scsi_cmnd: AscExeScsiQueue(), ASC_NOERROR\n");
6270             break;
6271         case ASC_BUSY:
6272             /*
6273              * Caller will enqueue request on the target's waiting queue
6274              * and retry later.
6275              */
6276             ASC_STATS(scp->device->host, exe_busy);
6277             break;
6278         case ASC_ERROR:
6279             ASC_PRINT2(
6280 "asc_execute_scsi_cmnd: board %d: AscExeScsiQueue() ASC_ERROR, err_code 0x%x\n",
6281                 boardp->id, asc_dvc_varp->err_code);
6282             ASC_STATS(scp->device->host, exe_error);
6283             scp->result = HOST_BYTE(DID_ERROR);
6284             asc_enqueue(&boardp->done, scp, ASC_BACK);
6285             break;
6286         default:
6287             ASC_PRINT2(
6288 "asc_execute_scsi_cmnd: board %d: AscExeScsiQueue() unknown, err_code 0x%x\n",
6289                 boardp->id, asc_dvc_varp->err_code);
6290             ASC_STATS(scp->device->host, exe_unknown);
6291             scp->result = HOST_BYTE(DID_ERROR);
6292             asc_enqueue(&boardp->done, scp, ASC_BACK);
6293             break;
6294         }
6295     } else {
6296         /*
6297          * Build and execute Wide Board request.
6298          */
6299         adv_dvc_varp = &boardp->dvc_var.adv_dvc_var;
6300
6301         /*
6302          * Build and get a pointer to an Adv Library request structure.
6303          *
6304          * If the request is successfully built then send it below,
6305          * otherwise return with an error.
6306          */
6307         switch (adv_build_req(boardp, scp, &adv_scsiqp)) {
6308         case ASC_NOERROR:
6309             ASC_DBG(3, "asc_execute_scsi_cmnd: adv_build_req ASC_NOERROR\n");
6310             break;
6311         case ASC_BUSY:
6312             ASC_DBG(1, "asc_execute_scsi_cmnd: adv_build_req ASC_BUSY\n");
6313             /*
6314              * If busy is returned the request has not been enqueued.
6315              * It will be enqueued by the caller on the target's waiting
6316              * queue and retried later.
6317              *
6318              * The asc_stats fields 'adv_build_noreq' and 'adv_build_nosg'
6319              * count wide board busy conditions. They are updated in
6320              * adv_build_req and adv_get_sglist, respectively.
6321              */
6322             return ASC_BUSY;
6323         case ASC_ERROR:
6324              /* 
6325               * If an error is returned, then the request has been
6326               * queued on the board done queue. It will be completed
6327               * by the caller.
6328               */
6329         default:
6330             ASC_DBG(1, "asc_execute_scsi_cmnd: adv_build_req ASC_ERROR\n");
6331             ASC_STATS(scp->device->host, build_error);
6332             return ASC_ERROR;
6333         }
6334
6335         /*
6336          * Execute the command. If there is no error, add the command
6337          * to the active queue.
6338          */
6339         switch (ret = AdvExeScsiQueue(adv_dvc_varp, adv_scsiqp)) {
6340         case ASC_NOERROR:
6341             ASC_STATS(scp->device->host, exe_noerror);
6342             /*
6343              * Increment monotonically increasing per device successful
6344              * request counter. Wrapping doesn't matter.
6345              */
6346             boardp->reqcnt[scp->device->id]++;
6347             asc_enqueue(&boardp->active, scp, ASC_BACK);
6348             ASC_DBG(1,
6349                 "asc_execute_scsi_cmnd: AdvExeScsiQueue(), ASC_NOERROR\n");
6350             break;
6351         case ASC_BUSY:
6352             /*
6353              * Caller will enqueue request on the target's waiting queue
6354              * and retry later.
6355              */
6356             ASC_STATS(scp->device->host, exe_busy);
6357             break;
6358         case ASC_ERROR:
6359             ASC_PRINT2(
6360 "asc_execute_scsi_cmnd: board %d: AdvExeScsiQueue() ASC_ERROR, err_code 0x%x\n",
6361                 boardp->id, adv_dvc_varp->err_code);
6362             ASC_STATS(scp->device->host, exe_error);
6363             scp->result = HOST_BYTE(DID_ERROR);
6364             asc_enqueue(&boardp->done, scp, ASC_BACK);
6365             break;
6366         default:
6367             ASC_PRINT2(
6368 "asc_execute_scsi_cmnd: board %d: AdvExeScsiQueue() unknown, err_code 0x%x\n",
6369                 boardp->id, adv_dvc_varp->err_code);
6370             ASC_STATS(scp->device->host, exe_unknown);
6371             scp->result = HOST_BYTE(DID_ERROR);
6372             asc_enqueue(&boardp->done, scp, ASC_BACK);
6373             break;
6374         }
6375     }
6376
6377     ASC_DBG(1, "asc_execute_scsi_cmnd: end\n");
6378     return ret;
6379 }
6380
6381 /*
6382  * Build a request structure for the Asc Library (Narrow Board).
6383  *
6384  * The global structures 'asc_scsi_q' and 'asc_sg_head' are
6385  * used to build the request.
6386  *
6387  * If an error occurs, then queue the request on the board done
6388  * queue and return ASC_ERROR.
6389  */
6390 STATIC int
6391 asc_build_req(asc_board_t *boardp, struct scsi_cmnd *scp)
6392 {
6393     struct device *dev = boardp->dvc_cfg.asc_dvc_cfg.dev;
6394
6395     /*
6396      * Mutually exclusive access is required to 'asc_scsi_q' and
6397      * 'asc_sg_head' until after the request is started.
6398      */
6399     memset(&asc_scsi_q, 0, sizeof(ASC_SCSI_Q));
6400
6401     /*
6402      * Point the ASC_SCSI_Q to the 'struct scsi_cmnd'.
6403      */
6404     asc_scsi_q.q2.srb_ptr = ASC_VADDR_TO_U32(scp);
6405
6406     /*
6407      * Build the ASC_SCSI_Q request.
6408      *
6409      * For narrow boards a CDB length maximum of 12 bytes
6410      * is supported.
6411      */
6412     if (scp->cmd_len > ASC_MAX_CDB_LEN) {
6413         ASC_PRINT3(
6414 "asc_build_req: board %d: cmd_len %d > ASC_MAX_CDB_LEN  %d\n",
6415             boardp->id, scp->cmd_len, ASC_MAX_CDB_LEN);
6416         scp->result = HOST_BYTE(DID_ERROR);
6417         asc_enqueue(&boardp->done, scp, ASC_BACK);
6418         return ASC_ERROR;
6419     }
6420     asc_scsi_q.cdbptr = &scp->cmnd[0];
6421     asc_scsi_q.q2.cdb_len = scp->cmd_len;
6422     asc_scsi_q.q1.target_id = ASC_TID_TO_TARGET_ID(scp->device->id);
6423     asc_scsi_q.q1.target_lun = scp->device->lun;
6424     asc_scsi_q.q2.target_ix = ASC_TIDLUN_TO_IX(scp->device->id, scp->device->lun);
6425     asc_scsi_q.q1.sense_addr = cpu_to_le32(virt_to_bus(&scp->sense_buffer[0]));
6426     asc_scsi_q.q1.sense_len = sizeof(scp->sense_buffer);
6427
6428     /*
6429      * If there are any outstanding requests for the current target,
6430      * then every 255th request send an ORDERED request. This heuristic
6431      * tries to retain the benefit of request sorting while preventing
6432      * request starvation. 255 is the max number of tags or pending commands
6433      * a device may have outstanding.
6434      *
6435      * The request count is incremented below for every successfully
6436      * started request.
6437      *
6438      */
6439     if ((boardp->dvc_var.asc_dvc_var.cur_dvc_qng[scp->device->id] > 0) &&
6440         (boardp->reqcnt[scp->device->id] % 255) == 0) {
6441         asc_scsi_q.q2.tag_code = MSG_ORDERED_TAG;
6442     } else {
6443         asc_scsi_q.q2.tag_code = MSG_SIMPLE_TAG;
6444     }
6445
6446     /*
6447      * Build ASC_SCSI_Q for a contiguous buffer or a scatter-gather
6448      * buffer command.
6449      */
6450     if (scp->use_sg == 0) {
6451         /*
6452          * CDB request of single contiguous buffer.
6453          */
6454         ASC_STATS(scp->device->host, cont_cnt);
6455         scp->SCp.dma_handle = scp->request_bufflen ?
6456             dma_map_single(dev, scp->request_buffer,
6457                            scp->request_bufflen, scp->sc_data_direction) : 0;
6458         asc_scsi_q.q1.data_addr = cpu_to_le32(scp->SCp.dma_handle);
6459         asc_scsi_q.q1.data_cnt = cpu_to_le32(scp->request_bufflen);
6460         ASC_STATS_ADD(scp->device->host, cont_xfer,
6461                       ASC_CEILING(scp->request_bufflen, 512));
6462         asc_scsi_q.q1.sg_queue_cnt = 0;
6463         asc_scsi_q.sg_head = NULL;
6464     } else {
6465         /*
6466          * CDB scatter-gather request list.
6467          */
6468         int                     sgcnt;
6469         int                     use_sg;
6470         struct scatterlist      *slp;
6471
6472         slp = (struct scatterlist *)scp->request_buffer;
6473         use_sg = dma_map_sg(dev, slp, scp->use_sg, scp->sc_data_direction);
6474
6475         if (use_sg > scp->device->host->sg_tablesize) {
6476             ASC_PRINT3(
6477 "asc_build_req: board %d: use_sg %d > sg_tablesize %d\n",
6478                 boardp->id, use_sg, scp->device->host->sg_tablesize);
6479             dma_unmap_sg(dev, slp, scp->use_sg, scp->sc_data_direction);
6480             scp->result = HOST_BYTE(DID_ERROR);
6481             asc_enqueue(&boardp->done, scp, ASC_BACK);
6482             return ASC_ERROR;
6483         }
6484
6485         ASC_STATS(scp->device->host, sg_cnt);
6486
6487         /*
6488          * Use global ASC_SG_HEAD structure and set the ASC_SCSI_Q
6489          * structure to point to it.
6490          */
6491         memset(&asc_sg_head, 0, sizeof(ASC_SG_HEAD));
6492
6493         asc_scsi_q.q1.cntl |= QC_SG_HEAD;
6494         asc_scsi_q.sg_head = &asc_sg_head;
6495         asc_scsi_q.q1.data_cnt = 0;
6496         asc_scsi_q.q1.data_addr = 0;
6497         /* This is a byte value, otherwise it would need to be swapped. */
6498         asc_sg_head.entry_cnt = asc_scsi_q.q1.sg_queue_cnt = use_sg;
6499         ASC_STATS_ADD(scp->device->host, sg_elem, asc_sg_head.entry_cnt);
6500
6501         /*
6502          * Convert scatter-gather list into ASC_SG_HEAD list.
6503          */
6504         for (sgcnt = 0; sgcnt < use_sg; sgcnt++, slp++) {
6505             asc_sg_head.sg_list[sgcnt].addr = cpu_to_le32(sg_dma_address(slp));
6506             asc_sg_head.sg_list[sgcnt].bytes = cpu_to_le32(sg_dma_len(slp));
6507             ASC_STATS_ADD(scp->device->host, sg_xfer, ASC_CEILING(sg_dma_len(slp), 512));
6508         }
6509     }
6510
6511     ASC_DBG_PRT_ASC_SCSI_Q(2, &asc_scsi_q);
6512     ASC_DBG_PRT_CDB(1, scp->cmnd, scp->cmd_len);
6513
6514     return ASC_NOERROR;
6515 }
6516
6517 /*
6518  * Build a request structure for the Adv Library (Wide Board).
6519  *
6520  * If an adv_req_t can not be allocated to issue the request,
6521  * then return ASC_BUSY. If an error occurs, then return ASC_ERROR.
6522  *
6523  * Multi-byte fields in the ASC_SCSI_REQ_Q that are used by the
6524  * microcode for DMA addresses or math operations are byte swapped
6525  * to little-endian order.
6526  */
6527 STATIC int
6528 adv_build_req(asc_board_t *boardp, struct scsi_cmnd *scp,
6529     ADV_SCSI_REQ_Q **adv_scsiqpp)
6530 {
6531     adv_req_t           *reqp;
6532     ADV_SCSI_REQ_Q      *scsiqp;
6533     int                 i;
6534     int                 ret;
6535     struct device       *dev = boardp->dvc_cfg.adv_dvc_cfg.dev;
6536
6537     /*
6538      * Allocate an adv_req_t structure from the board to execute
6539      * the command.
6540      */
6541     if (boardp->adv_reqp == NULL) {
6542         ASC_DBG(1, "adv_build_req: no free adv_req_t\n");
6543         ASC_STATS(scp->device->host, adv_build_noreq);
6544         return ASC_BUSY;
6545     } else {
6546         reqp = boardp->adv_reqp;
6547         boardp->adv_reqp = reqp->next_reqp;
6548         reqp->next_reqp = NULL;
6549     }
6550
6551     /*
6552      * Get 32-byte aligned ADV_SCSI_REQ_Q and ADV_SG_BLOCK pointers.
6553      */
6554     scsiqp = (ADV_SCSI_REQ_Q *) ADV_32BALIGN(&reqp->scsi_req_q);
6555
6556     /*
6557      * Initialize the structure.
6558      */
6559     scsiqp->cntl = scsiqp->scsi_cntl = scsiqp->done_status = 0;
6560
6561     /*
6562      * Set the ADV_SCSI_REQ_Q 'srb_ptr' to point to the adv_req_t structure.
6563      */
6564     scsiqp->srb_ptr = ASC_VADDR_TO_U32(reqp);
6565
6566     /*
6567      * Set the adv_req_t 'cmndp' to point to the struct scsi_cmnd structure.
6568      */
6569     reqp->cmndp = scp;
6570
6571     /*
6572      * Build the ADV_SCSI_REQ_Q request.
6573      */
6574
6575     /*
6576      * Set CDB length and copy it to the request structure.
6577      * For wide  boards a CDB length maximum of 16 bytes
6578      * is supported.
6579      */
6580     if (scp->cmd_len > ADV_MAX_CDB_LEN) {
6581         ASC_PRINT3(
6582 "adv_build_req: board %d: cmd_len %d > ADV_MAX_CDB_LEN  %d\n",
6583             boardp->id, scp->cmd_len, ADV_MAX_CDB_LEN);
6584         scp->result = HOST_BYTE(DID_ERROR);
6585         asc_enqueue(&boardp->done, scp, ASC_BACK);
6586         return ASC_ERROR;
6587     }
6588     scsiqp->cdb_len = scp->cmd_len;
6589     /* Copy first 12 CDB bytes to cdb[]. */
6590     for (i = 0; i < scp->cmd_len && i < 12; i++) {
6591         scsiqp->cdb[i] = scp->cmnd[i];
6592     }
6593     /* Copy last 4 CDB bytes, if present, to cdb16[]. */
6594     for (; i < scp->cmd_len; i++) {
6595         scsiqp->cdb16[i - 12] = scp->cmnd[i];
6596     }
6597
6598     scsiqp->target_id = scp->device->id;
6599     scsiqp->target_lun = scp->device->lun;
6600
6601     scsiqp->sense_addr = cpu_to_le32(virt_to_bus(&scp->sense_buffer[0]));
6602     scsiqp->sense_len = sizeof(scp->sense_buffer);
6603
6604     /*
6605      * Build ADV_SCSI_REQ_Q for a contiguous buffer or a scatter-gather
6606      * buffer command.
6607      */
6608
6609     scsiqp->data_cnt = cpu_to_le32(scp->request_bufflen);
6610     scsiqp->vdata_addr = scp->request_buffer;
6611     scsiqp->data_addr = cpu_to_le32(virt_to_bus(scp->request_buffer));
6612
6613     if (scp->use_sg == 0) {
6614         /*
6615          * CDB request of single contiguous buffer.
6616          */
6617         reqp->sgblkp = NULL;
6618         scsiqp->data_cnt = cpu_to_le32(scp->request_bufflen);
6619         if (scp->request_bufflen) {
6620             scsiqp->vdata_addr = scp->request_buffer;
6621             scp->SCp.dma_handle =
6622                 dma_map_single(dev, scp->request_buffer,
6623                                scp->request_bufflen, scp->sc_data_direction);
6624         } else {
6625             scsiqp->vdata_addr = 0;
6626             scp->SCp.dma_handle = 0;
6627         }
6628         scsiqp->data_addr = cpu_to_le32(scp->SCp.dma_handle);
6629         scsiqp->sg_list_ptr = NULL;
6630         scsiqp->sg_real_addr = 0;
6631         ASC_STATS(scp->device->host, cont_cnt);
6632         ASC_STATS_ADD(scp->device->host, cont_xfer,
6633                       ASC_CEILING(scp->request_bufflen, 512));
6634     } else {
6635         /*
6636          * CDB scatter-gather request list.
6637          */
6638         struct scatterlist *slp;
6639         int use_sg;
6640
6641         slp = (struct scatterlist *)scp->request_buffer;
6642         use_sg = dma_map_sg(dev, slp, scp->use_sg, scp->sc_data_direction);
6643
6644         if (use_sg > ADV_MAX_SG_LIST) {
6645             ASC_PRINT3(
6646 "adv_build_req: board %d: use_sg %d > ADV_MAX_SG_LIST %d\n",
6647                 boardp->id, use_sg, scp->device->host->sg_tablesize);
6648             dma_unmap_sg(dev, slp, scp->use_sg, scp->sc_data_direction);
6649             scp->result = HOST_BYTE(DID_ERROR);
6650             asc_enqueue(&boardp->done, scp, ASC_BACK);
6651
6652             /*
6653              * Free the 'adv_req_t' structure by adding it back to the
6654              * board free list.
6655              */
6656             reqp->next_reqp = boardp->adv_reqp;
6657             boardp->adv_reqp = reqp;
6658
6659             return ASC_ERROR;
6660         }
6661
6662         if ((ret = adv_get_sglist(boardp, reqp, scp, use_sg)) != ADV_SUCCESS) {
6663             /*
6664              * Free the adv_req_t structure by adding it back to the
6665              * board free list.
6666              */
6667             reqp->next_reqp = boardp->adv_reqp;
6668             boardp->adv_reqp = reqp;
6669
6670             return ret;
6671         }
6672
6673         ASC_STATS(scp->device->host, sg_cnt);
6674         ASC_STATS_ADD(scp->device->host, sg_elem, use_sg);
6675     }
6676
6677     ASC_DBG_PRT_ADV_SCSI_REQ_Q(2, scsiqp);
6678     ASC_DBG_PRT_CDB(1, scp->cmnd, scp->cmd_len);
6679
6680     *adv_scsiqpp = scsiqp;
6681
6682     return ASC_NOERROR;
6683 }
6684
6685 /*
6686  * Build scatter-gather list for Adv Library (Wide Board).
6687  *
6688  * Additional ADV_SG_BLOCK structures will need to be allocated
6689  * if the total number of scatter-gather elements exceeds
6690  * NO_OF_SG_PER_BLOCK (15). The ADV_SG_BLOCK structures are
6691  * assumed to be physically contiguous.
6692  *
6693  * Return:
6694  *      ADV_SUCCESS(1) - SG List successfully created
6695  *      ADV_ERROR(-1) - SG List creation failed
6696  */
6697 STATIC int
6698 adv_get_sglist(asc_board_t *boardp, adv_req_t *reqp, struct scsi_cmnd *scp, int use_sg)
6699 {
6700     adv_sgblk_t         *sgblkp;
6701     ADV_SCSI_REQ_Q      *scsiqp;
6702     struct scatterlist  *slp;
6703     int                 sg_elem_cnt;
6704     ADV_SG_BLOCK        *sg_block, *prev_sg_block;
6705     ADV_PADDR           sg_block_paddr;
6706     int                 i;
6707
6708     scsiqp = (ADV_SCSI_REQ_Q *) ADV_32BALIGN(&reqp->scsi_req_q);
6709     slp = (struct scatterlist *) scp->request_buffer;
6710     sg_elem_cnt = use_sg;
6711     prev_sg_block = NULL;
6712     reqp->sgblkp = NULL;
6713
6714     do
6715     {
6716         /*
6717          * Allocate a 'adv_sgblk_t' structure from the board free
6718          * list. One 'adv_sgblk_t' structure holds NO_OF_SG_PER_BLOCK
6719          * (15) scatter-gather elements.
6720          */
6721         if ((sgblkp = boardp->adv_sgblkp) == NULL) {
6722             ASC_DBG(1, "adv_get_sglist: no free adv_sgblk_t\n");
6723             ASC_STATS(scp->device->host, adv_build_nosg);
6724
6725             /*
6726              * Allocation failed. Free 'adv_sgblk_t' structures already
6727              * allocated for the request.
6728              */
6729             while ((sgblkp = reqp->sgblkp) != NULL)
6730             {
6731                 /* Remove 'sgblkp' from the request list. */
6732                 reqp->sgblkp = sgblkp->next_sgblkp;
6733
6734                 /* Add 'sgblkp' to the board free list. */
6735                 sgblkp->next_sgblkp = boardp->adv_sgblkp;
6736                 boardp->adv_sgblkp = sgblkp;
6737             }
6738             return ASC_BUSY;
6739         } else {
6740             /* Complete 'adv_sgblk_t' board allocation. */
6741             boardp->adv_sgblkp = sgblkp->next_sgblkp;
6742             sgblkp->next_sgblkp = NULL;
6743
6744             /*
6745              * Get 8 byte aligned virtual and physical addresses for
6746              * the allocated ADV_SG_BLOCK structure.
6747              */
6748             sg_block = (ADV_SG_BLOCK *) ADV_8BALIGN(&sgblkp->sg_block);
6749             sg_block_paddr = virt_to_bus(sg_block);
6750
6751             /*
6752              * Check if this is the first 'adv_sgblk_t' for the request.
6753              */
6754             if (reqp->sgblkp == NULL)
6755             {
6756                 /* Request's first scatter-gather block. */
6757                 reqp->sgblkp = sgblkp;
6758
6759                 /*
6760                  * Set ADV_SCSI_REQ_T ADV_SG_BLOCK virtual and physical
6761                  * address pointers.
6762                  */
6763                 scsiqp->sg_list_ptr = sg_block;
6764                 scsiqp->sg_real_addr = cpu_to_le32(sg_block_paddr);
6765             } else
6766             {
6767                 /* Request's second or later scatter-gather block. */
6768                 sgblkp->next_sgblkp = reqp->sgblkp;
6769                 reqp->sgblkp = sgblkp;
6770
6771                 /*
6772                  * Point the previous ADV_SG_BLOCK structure to
6773                  * the newly allocated ADV_SG_BLOCK structure.
6774                  */
6775                 ASC_ASSERT(prev_sg_block != NULL);
6776                 prev_sg_block->sg_ptr = cpu_to_le32(sg_block_paddr);
6777             }
6778         }
6779
6780         for (i = 0; i < NO_OF_SG_PER_BLOCK; i++)
6781         {
6782             sg_block->sg_list[i].sg_addr = cpu_to_le32(sg_dma_address(slp));
6783             sg_block->sg_list[i].sg_count = cpu_to_le32(sg_dma_len(slp));
6784             ASC_STATS_ADD(scp->device->host, sg_xfer, ASC_CEILING(sg_dma_len(slp), 512));
6785
6786             if (--sg_elem_cnt == 0)
6787             {   /* Last ADV_SG_BLOCK and scatter-gather entry. */
6788                 sg_block->sg_cnt = i + 1;
6789                 sg_block->sg_ptr = 0L;    /* Last ADV_SG_BLOCK in list. */
6790                 return ADV_SUCCESS;
6791             }
6792             slp++;
6793         }
6794         sg_block->sg_cnt = NO_OF_SG_PER_BLOCK;
6795         prev_sg_block = sg_block;
6796     }
6797     while (1);
6798     /* NOTREACHED */
6799 }
6800
6801 /*
6802  * asc_isr_callback() - Second Level Interrupt Handler called by AscISR().
6803  *
6804  * Interrupt callback function for the Narrow SCSI Asc Library.
6805  */
6806 STATIC void
6807 asc_isr_callback(ASC_DVC_VAR *asc_dvc_varp, ASC_QDONE_INFO *qdonep)
6808 {
6809     asc_board_t         *boardp;
6810     struct scsi_cmnd           *scp;
6811     struct Scsi_Host    *shp;
6812     int                 i;
6813
6814     ASC_DBG2(1, "asc_isr_callback: asc_dvc_varp 0x%lx, qdonep 0x%lx\n",
6815         (ulong) asc_dvc_varp, (ulong) qdonep);
6816     ASC_DBG_PRT_ASC_QDONE_INFO(2, qdonep);
6817
6818     /*
6819      * Get the struct scsi_cmnd structure and Scsi_Host structure for the
6820      * command that has been completed.
6821      */
6822     scp = (struct scsi_cmnd *) ASC_U32_TO_VADDR(qdonep->d2.srb_ptr);
6823     ASC_DBG1(1, "asc_isr_callback: scp 0x%lx\n", (ulong) scp);
6824
6825     if (scp == NULL) {
6826         ASC_PRINT("asc_isr_callback: scp is NULL\n");
6827         return;
6828     }
6829     ASC_DBG_PRT_CDB(2, scp->cmnd, scp->cmd_len);
6830
6831     /*
6832      * If the request's host pointer is not valid, display a
6833      * message and return.
6834      */
6835     shp = scp->device->host;
6836     for (i = 0; i < asc_board_count; i++) {
6837         if (asc_host[i] == shp) {
6838             break;
6839         }
6840     }
6841     if (i == asc_board_count) {
6842         ASC_PRINT2(
6843             "asc_isr_callback: scp 0x%lx has bad host pointer, host 0x%lx\n",
6844             (ulong) scp, (ulong) shp);
6845         return;
6846     }
6847
6848     ASC_STATS(shp, callback);
6849     ASC_DBG1(1, "asc_isr_callback: shp 0x%lx\n", (ulong) shp);
6850
6851     /*
6852      * If the request isn't found on the active queue, it may
6853      * have been removed to handle a reset request.
6854      * Display a message and return.
6855      */
6856     boardp = ASC_BOARDP(shp);
6857     ASC_ASSERT(asc_dvc_varp == &boardp->dvc_var.asc_dvc_var);
6858     if (asc_rmqueue(&boardp->active, scp) == ASC_FALSE) {
6859         ASC_PRINT2(
6860             "asc_isr_callback: board %d: scp 0x%lx not on active queue\n",
6861             boardp->id, (ulong) scp);
6862         return;
6863     }
6864
6865     /*
6866      * 'qdonep' contains the command's ending status.
6867      */
6868     switch (qdonep->d3.done_stat) {
6869     case QD_NO_ERROR:
6870         ASC_DBG(2, "asc_isr_callback: QD_NO_ERROR\n");
6871         scp->result = 0;
6872
6873         /*
6874          * If an INQUIRY command completed successfully, then call
6875          * the AscInquiryHandling() function to set-up the device.
6876          */
6877         if (scp->cmnd[0] == INQUIRY && scp->device->lun == 0 &&
6878             (scp->request_bufflen - qdonep->remain_bytes) >= 8)
6879         {
6880             AscInquiryHandling(asc_dvc_varp, scp->device->id & 0x7,
6881                 (ASC_SCSI_INQUIRY *) scp->request_buffer);
6882         }
6883
6884         /*
6885          * Check for an underrun condition.
6886          *
6887          * If there was no error and an underrun condition, then
6888          * then return the number of underrun bytes.
6889          */
6890         if (scp->request_bufflen != 0 && qdonep->remain_bytes != 0 &&
6891             qdonep->remain_bytes <= scp->request_bufflen) {
6892             ASC_DBG1(1, "asc_isr_callback: underrun condition %u bytes\n",
6893             (unsigned) qdonep->remain_bytes);
6894             scp->resid = qdonep->remain_bytes;
6895         }
6896         break;
6897
6898     case QD_WITH_ERROR:
6899         ASC_DBG(2, "asc_isr_callback: QD_WITH_ERROR\n");
6900         switch (qdonep->d3.host_stat) {
6901         case QHSTA_NO_ERROR:
6902             if (qdonep->d3.scsi_stat == SAM_STAT_CHECK_CONDITION) {
6903                 ASC_DBG(2, "asc_isr_callback: SAM_STAT_CHECK_CONDITION\n");
6904                 ASC_DBG_PRT_SENSE(2, scp->sense_buffer,
6905                     sizeof(scp->sense_buffer));
6906                 /*
6907                  * Note: The 'status_byte()' macro used by target drivers
6908                  * defined in scsi.h shifts the status byte returned by
6909                  * host drivers right by 1 bit. This is why target drivers
6910                  * also use right shifted status byte definitions. For
6911                  * instance target drivers use CHECK_CONDITION, defined to
6912                  * 0x1, instead of the SCSI defined check condition value
6913                  * of 0x2. Host drivers are supposed to return the status
6914                  * byte as it is defined by SCSI.
6915                  */
6916                 scp->result = DRIVER_BYTE(DRIVER_SENSE) |
6917                     STATUS_BYTE(qdonep->d3.scsi_stat);
6918             } else {
6919                 scp->result = STATUS_BYTE(qdonep->d3.scsi_stat);
6920             }
6921             break;
6922
6923         default:
6924             /* QHSTA error occurred */
6925             ASC_DBG1(1, "asc_isr_callback: host_stat 0x%x\n",
6926                 qdonep->d3.host_stat);
6927             scp->result = HOST_BYTE(DID_BAD_TARGET);
6928             break;
6929         }
6930         break;
6931
6932     case QD_ABORTED_BY_HOST:
6933         ASC_DBG(1, "asc_isr_callback: QD_ABORTED_BY_HOST\n");
6934         scp->result = HOST_BYTE(DID_ABORT) | MSG_BYTE(qdonep->d3.scsi_msg) |
6935                 STATUS_BYTE(qdonep->d3.scsi_stat);
6936         break;
6937
6938     default:
6939         ASC_DBG1(1, "asc_isr_callback: done_stat 0x%x\n", qdonep->d3.done_stat);
6940         scp->result = HOST_BYTE(DID_ERROR) | MSG_BYTE(qdonep->d3.scsi_msg) |
6941                 STATUS_BYTE(qdonep->d3.scsi_stat);
6942         break;
6943     }
6944
6945     /*
6946      * If the 'init_tidmask' bit isn't already set for the target and the
6947      * current request finished normally, then set the bit for the target
6948      * to indicate that a device is present.
6949      */
6950     if ((boardp->init_tidmask & ADV_TID_TO_TIDMASK(scp->device->id)) == 0 &&
6951         qdonep->d3.done_stat == QD_NO_ERROR &&
6952         qdonep->d3.host_stat == QHSTA_NO_ERROR) {
6953         boardp->init_tidmask |= ADV_TID_TO_TIDMASK(scp->device->id);
6954     }
6955
6956     /*
6957      * Because interrupts may be enabled by the 'struct scsi_cmnd' done
6958      * function, add the command to the end of the board's done queue.
6959      * The done function for the command will be called from
6960      * advansys_interrupt().
6961      */
6962     asc_enqueue(&boardp->done, scp, ASC_BACK);
6963
6964     return;
6965 }
6966
6967 /*
6968  * adv_isr_callback() - Second Level Interrupt Handler called by AdvISR().
6969  *
6970  * Callback function for the Wide SCSI Adv Library.
6971  */
6972 STATIC void
6973 adv_isr_callback(ADV_DVC_VAR *adv_dvc_varp, ADV_SCSI_REQ_Q *scsiqp)
6974 {
6975     asc_board_t         *boardp;
6976     adv_req_t           *reqp;
6977     adv_sgblk_t         *sgblkp;
6978     struct scsi_cmnd           *scp;
6979     struct Scsi_Host    *shp;
6980     int                 i;
6981     ADV_DCNT            resid_cnt;
6982
6983
6984     ASC_DBG2(1, "adv_isr_callback: adv_dvc_varp 0x%lx, scsiqp 0x%lx\n",
6985         (ulong) adv_dvc_varp, (ulong) scsiqp);
6986     ASC_DBG_PRT_ADV_SCSI_REQ_Q(2, scsiqp);
6987
6988     /*
6989      * Get the adv_req_t structure for the command that has been
6990      * completed. The adv_req_t structure actually contains the
6991      * completed ADV_SCSI_REQ_Q structure.
6992      */
6993     reqp = (adv_req_t *) ADV_U32_TO_VADDR(scsiqp->srb_ptr);
6994     ASC_DBG1(1, "adv_isr_callback: reqp 0x%lx\n", (ulong) reqp);
6995     if (reqp == NULL) {
6996         ASC_PRINT("adv_isr_callback: reqp is NULL\n");
6997         return;
6998     }
6999
7000     /*
7001      * Get the struct scsi_cmnd structure and Scsi_Host structure for the
7002      * command that has been completed.
7003      *
7004      * Note: The adv_req_t request structure and adv_sgblk_t structure,
7005      * if any, are dropped, because a board structure pointer can not be
7006      * determined.
7007      */
7008     scp = reqp->cmndp;
7009     ASC_DBG1(1, "adv_isr_callback: scp 0x%lx\n", (ulong) scp);
7010     if (scp == NULL) {
7011         ASC_PRINT("adv_isr_callback: scp is NULL; adv_req_t dropped.\n");
7012         return;
7013     }
7014     ASC_DBG_PRT_CDB(2, scp->cmnd, scp->cmd_len);
7015
7016     /*
7017      * If the request's host pointer is not valid, display a message
7018      * and return.
7019      */
7020     shp = scp->device->host;
7021     for (i = 0; i < asc_board_count; i++) {
7022         if (asc_host[i] == shp) {
7023             break;
7024         }
7025     }
7026     /*
7027      * Note: If the host structure is not found, the adv_req_t request
7028      * structure and adv_sgblk_t structure, if any, is dropped.
7029      */
7030     if (i == asc_board_count) {
7031         ASC_PRINT2(
7032             "adv_isr_callback: scp 0x%lx has bad host pointer, host 0x%lx\n",
7033             (ulong) scp, (ulong) shp);
7034         return;
7035     }
7036
7037     ASC_STATS(shp, callback);
7038     ASC_DBG1(1, "adv_isr_callback: shp 0x%lx\n", (ulong) shp);
7039
7040     /*
7041      * If the request isn't found on the active queue, it may have been
7042      * removed to handle a reset request. Display a message and return.
7043      *
7044      * Note: Because the structure may still be in use don't attempt
7045      * to free the adv_req_t and adv_sgblk_t, if any, structures.
7046      */
7047     boardp = ASC_BOARDP(shp);
7048     ASC_ASSERT(adv_dvc_varp == &boardp->dvc_var.adv_dvc_var);
7049     if (asc_rmqueue(&boardp->active, scp) == ASC_FALSE) {
7050         ASC_PRINT2(
7051             "adv_isr_callback: board %d: scp 0x%lx not on active queue\n",
7052             boardp->id, (ulong) scp);
7053         return;
7054     }
7055
7056     /*
7057      * 'done_status' contains the command's ending status.
7058      */
7059     switch (scsiqp->done_status) {
7060     case QD_NO_ERROR:
7061         ASC_DBG(2, "adv_isr_callback: QD_NO_ERROR\n");
7062         scp->result = 0;
7063
7064         /*
7065          * Check for an underrun condition.
7066          *
7067          * If there was no error and an underrun condition, then
7068          * then return the number of underrun bytes.
7069          */
7070         resid_cnt = le32_to_cpu(scsiqp->data_cnt);
7071         if (scp->request_bufflen != 0 && resid_cnt != 0 &&
7072             resid_cnt <= scp->request_bufflen) {
7073             ASC_DBG1(1, "adv_isr_callback: underrun condition %lu bytes\n",
7074                 (ulong) resid_cnt);
7075             scp->resid = resid_cnt;
7076         }
7077         break;
7078
7079     case QD_WITH_ERROR:
7080         ASC_DBG(2, "adv_isr_callback: QD_WITH_ERROR\n");
7081         switch (scsiqp->host_status) {
7082         case QHSTA_NO_ERROR:
7083             if (scsiqp->scsi_status == SAM_STAT_CHECK_CONDITION) {
7084                 ASC_DBG(2, "adv_isr_callback: SAM_STAT_CHECK_CONDITION\n");
7085                 ASC_DBG_PRT_SENSE(2, scp->sense_buffer,
7086                     sizeof(scp->sense_buffer));
7087                 /*
7088                  * Note: The 'status_byte()' macro used by target drivers
7089                  * defined in scsi.h shifts the status byte returned by
7090                  * host drivers right by 1 bit. This is why target drivers
7091                  * also use right shifted status byte definitions. For
7092                  * instance target drivers use CHECK_CONDITION, defined to
7093                  * 0x1, instead of the SCSI defined check condition value
7094                  * of 0x2. Host drivers are supposed to return the status
7095                  * byte as it is defined by SCSI.
7096                  */
7097                 scp->result = DRIVER_BYTE(DRIVER_SENSE) |
7098                     STATUS_BYTE(scsiqp->scsi_status);
7099             } else {
7100                 scp->result = STATUS_BYTE(scsiqp->scsi_status);
7101             }
7102             break;
7103
7104         default:
7105             /* Some other QHSTA error occurred. */
7106             ASC_DBG1(1, "adv_isr_callback: host_status 0x%x\n",
7107                 scsiqp->host_status);
7108             scp->result = HOST_BYTE(DID_BAD_TARGET);
7109             break;
7110         }
7111         break;
7112
7113     case QD_ABORTED_BY_HOST:
7114         ASC_DBG(1, "adv_isr_callback: QD_ABORTED_BY_HOST\n");
7115         scp->result = HOST_BYTE(DID_ABORT) | STATUS_BYTE(scsiqp->scsi_status);
7116         break;
7117
7118     default:
7119         ASC_DBG1(1, "adv_isr_callback: done_status 0x%x\n", scsiqp->done_status);
7120         scp->result = HOST_BYTE(DID_ERROR) | STATUS_BYTE(scsiqp->scsi_status);
7121         break;
7122     }
7123
7124     /*
7125      * If the 'init_tidmask' bit isn't already set for the target and the
7126      * current request finished normally, then set the bit for the target
7127      * to indicate that a device is present.
7128      */
7129     if ((boardp->init_tidmask & ADV_TID_TO_TIDMASK(scp->device->id)) == 0 &&
7130         scsiqp->done_status == QD_NO_ERROR &&
7131         scsiqp->host_status == QHSTA_NO_ERROR) {
7132         boardp->init_tidmask |= ADV_TID_TO_TIDMASK(scp->device->id);
7133     }
7134
7135     /*
7136      * Because interrupts may be enabled by the 'struct scsi_cmnd' done
7137      * function, add the command to the end of the board's done queue.
7138      * The done function for the command will be called from
7139      * advansys_interrupt().
7140      */
7141     asc_enqueue(&boardp->done, scp, ASC_BACK);
7142
7143     /*
7144      * Free all 'adv_sgblk_t' structures allocated for the request.
7145      */
7146     while ((sgblkp = reqp->sgblkp) != NULL)
7147     {
7148         /* Remove 'sgblkp' from the request list. */
7149         reqp->sgblkp = sgblkp->next_sgblkp;
7150
7151         /* Add 'sgblkp' to the board free list. */
7152         sgblkp->next_sgblkp = boardp->adv_sgblkp;
7153         boardp->adv_sgblkp = sgblkp;
7154     }
7155
7156     /*
7157      * Free the adv_req_t structure used with the command by adding
7158      * it back to the board free list.
7159      */
7160     reqp->next_reqp = boardp->adv_reqp;
7161     boardp->adv_reqp = reqp;
7162
7163     ASC_DBG(1, "adv_isr_callback: done\n");
7164
7165     return;
7166 }
7167
7168 /*
7169  * adv_async_callback() - Adv Library asynchronous event callback function.
7170  */
7171 STATIC void
7172 adv_async_callback(ADV_DVC_VAR *adv_dvc_varp, uchar code)
7173 {
7174     switch (code)
7175     {
7176     case ADV_ASYNC_SCSI_BUS_RESET_DET:
7177         /*
7178          * The firmware detected a SCSI Bus reset.
7179          */
7180         ASC_DBG(0, "adv_async_callback: ADV_ASYNC_SCSI_BUS_RESET_DET\n");
7181         break;
7182
7183     case ADV_ASYNC_RDMA_FAILURE:
7184         /*
7185          * Handle RDMA failure by resetting the SCSI Bus and
7186          * possibly the chip if it is unresponsive. Log the error
7187          * with a unique code.
7188          */
7189         ASC_DBG(0, "adv_async_callback: ADV_ASYNC_RDMA_FAILURE\n");
7190         AdvResetChipAndSB(adv_dvc_varp);
7191         break;
7192
7193     case ADV_HOST_SCSI_BUS_RESET:
7194         /*
7195          * Host generated SCSI bus reset occurred.
7196          */
7197         ASC_DBG(0, "adv_async_callback: ADV_HOST_SCSI_BUS_RESET\n");
7198         break;
7199
7200     default:
7201         ASC_DBG1(0, "DvcAsyncCallBack: unknown code 0x%x\n", code);
7202         break;
7203     }
7204 }
7205
7206 /*
7207  * Add a 'REQP' to the end of specified queue. Set 'tidmask'
7208  * to indicate a command is queued for the device.
7209  *
7210  * 'flag' may be either ASC_FRONT or ASC_BACK.
7211  *
7212  * 'REQPNEXT(reqp)' returns reqp's next pointer.
7213  */
7214 STATIC void
7215 asc_enqueue(asc_queue_t *ascq, REQP reqp, int flag)
7216 {
7217     int        tid;
7218
7219     ASC_DBG3(3, "asc_enqueue: ascq 0x%lx, reqp 0x%lx, flag %d\n",
7220         (ulong) ascq, (ulong) reqp, flag);
7221     ASC_ASSERT(reqp != NULL);
7222     ASC_ASSERT(flag == ASC_FRONT || flag == ASC_BACK);
7223     tid = REQPTID(reqp);
7224     ASC_ASSERT(tid >= 0 && tid <= ADV_MAX_TID);
7225     if (flag == ASC_FRONT) {
7226         reqp->host_scribble = (unsigned char *)ascq->q_first[tid];
7227         ascq->q_first[tid] = reqp;
7228         /* If the queue was empty, set the last pointer. */
7229         if (ascq->q_last[tid] == NULL) {
7230             ascq->q_last[tid] = reqp;
7231         }
7232     } else { /* ASC_BACK */
7233         if (ascq->q_last[tid] != NULL) {
7234             ascq->q_last[tid]->host_scribble = (unsigned char *)reqp;
7235         }
7236         ascq->q_last[tid] = reqp;
7237         reqp->host_scribble = NULL;
7238         /* If the queue was empty, set the first pointer. */
7239         if (ascq->q_first[tid] == NULL) {
7240             ascq->q_first[tid] = reqp;
7241         }
7242     }
7243     /* The queue has at least one entry, set its bit. */
7244     ascq->q_tidmask |= ADV_TID_TO_TIDMASK(tid);
7245 #ifdef ADVANSYS_STATS
7246     /* Maintain request queue statistics. */
7247     ascq->q_tot_cnt[tid]++;
7248     ascq->q_cur_cnt[tid]++;
7249     if (ascq->q_cur_cnt[tid] > ascq->q_max_cnt[tid]) {
7250         ascq->q_max_cnt[tid] = ascq->q_cur_cnt[tid];
7251         ASC_DBG2(2, "asc_enqueue: new q_max_cnt[%d] %d\n",
7252             tid, ascq->q_max_cnt[tid]);
7253     }
7254     REQPTIME(reqp) = REQTIMESTAMP();
7255 #endif /* ADVANSYS_STATS */
7256     ASC_DBG1(3, "asc_enqueue: reqp 0x%lx\n", (ulong) reqp);
7257     return;
7258 }
7259
7260 /*
7261  * Return first queued 'REQP' on the specified queue for
7262  * the specified target device. Clear the 'tidmask' bit for
7263  * the device if no more commands are left queued for it.
7264  *
7265  * 'REQPNEXT(reqp)' returns reqp's next pointer.
7266  */
7267 STATIC REQP
7268 asc_dequeue(asc_queue_t *ascq, int tid)
7269 {
7270     REQP    reqp;
7271
7272     ASC_DBG2(3, "asc_dequeue: ascq 0x%lx, tid %d\n", (ulong) ascq, tid);
7273     ASC_ASSERT(tid >= 0 && tid <= ADV_MAX_TID);
7274     if ((reqp = ascq->q_first[tid]) != NULL) {
7275         ASC_ASSERT(ascq->q_tidmask & ADV_TID_TO_TIDMASK(tid));
7276         ascq->q_first[tid] = REQPNEXT(reqp);
7277         /* If the queue is empty, clear its bit and the last pointer. */
7278         if (ascq->q_first[tid] == NULL) {
7279             ascq->q_tidmask &= ~ADV_TID_TO_TIDMASK(tid);
7280             ASC_ASSERT(ascq->q_last[tid] == reqp);
7281             ascq->q_last[tid] = NULL;
7282         }
7283 #ifdef ADVANSYS_STATS
7284         /* Maintain request queue statistics. */
7285         ascq->q_cur_cnt[tid]--;
7286         ASC_ASSERT(ascq->q_cur_cnt[tid] >= 0);
7287         REQTIMESTAT("asc_dequeue", ascq, reqp, tid);
7288 #endif /* ADVANSYS_STATS */
7289     }
7290     ASC_DBG1(3, "asc_dequeue: reqp 0x%lx\n", (ulong) reqp);
7291     return reqp;
7292 }
7293
7294 /*
7295  * Return a pointer to a singly linked list of all the requests queued
7296  * for 'tid' on the 'asc_queue_t' pointed to by 'ascq'.
7297  *
7298  * If 'lastpp' is not NULL, '*lastpp' will be set to point to the
7299  * the last request returned in the singly linked list.
7300  *
7301  * 'tid' should either be a valid target id or if it is ASC_TID_ALL,
7302  * then all queued requests are concatenated into one list and
7303  * returned.
7304  *
7305  * Note: If 'lastpp' is used to append a new list to the end of
7306  * an old list, only change the old list last pointer if '*lastpp'
7307  * (or the function return value) is not NULL, i.e. use a temporary
7308  * variable for 'lastpp' and check its value after the function return
7309  * before assigning it to the list last pointer.
7310  *
7311  * Unfortunately collecting queuing time statistics adds overhead to
7312  * the function that isn't inherent to the function's algorithm.
7313  */
7314 STATIC REQP
7315 asc_dequeue_list(asc_queue_t *ascq, REQP *lastpp, int tid)
7316 {
7317     REQP    firstp, lastp;
7318     int     i;
7319
7320     ASC_DBG2(3, "asc_dequeue_list: ascq 0x%lx, tid %d\n", (ulong) ascq, tid);
7321     ASC_ASSERT((tid == ASC_TID_ALL) || (tid >= 0 && tid <= ADV_MAX_TID));
7322
7323     /*
7324      * If 'tid' is not ASC_TID_ALL, return requests only for
7325      * the specified 'tid'. If 'tid' is ASC_TID_ALL, return all
7326      * requests for all tids.
7327      */
7328     if (tid != ASC_TID_ALL) {
7329         /* Return all requests for the specified 'tid'. */
7330         if ((ascq->q_tidmask & ADV_TID_TO_TIDMASK(tid)) == 0) {
7331             /* List is empty; Set first and last return pointers to NULL. */
7332             firstp = lastp = NULL;
7333         } else {
7334             firstp = ascq->q_first[tid];
7335             lastp = ascq->q_last[tid];
7336             ascq->q_first[tid] = ascq->q_last[tid] = NULL;
7337             ascq->q_tidmask &= ~ADV_TID_TO_TIDMASK(tid);
7338 #ifdef ADVANSYS_STATS
7339             {
7340                 REQP reqp;
7341                 ascq->q_cur_cnt[tid] = 0;
7342                 for (reqp = firstp; reqp; reqp = REQPNEXT(reqp)) {
7343                     REQTIMESTAT("asc_dequeue_list", ascq, reqp, tid);
7344                 }
7345             }
7346 #endif /* ADVANSYS_STATS */
7347         }
7348     } else {
7349         /* Return all requests for all tids. */
7350         firstp = lastp = NULL;
7351         for (i = 0; i <= ADV_MAX_TID; i++) {
7352             if (ascq->q_tidmask & ADV_TID_TO_TIDMASK(i)) {
7353                 if (firstp == NULL) {
7354                     firstp = ascq->q_first[i];
7355                     lastp = ascq->q_last[i];
7356                 } else {
7357                     ASC_ASSERT(lastp != NULL);
7358                     lastp->host_scribble = (unsigned char *)ascq->q_first[i];
7359                     lastp = ascq->q_last[i];
7360                 }
7361                 ascq->q_first[i] = ascq->q_last[i] = NULL;
7362                 ascq->q_tidmask &= ~ADV_TID_TO_TIDMASK(i);
7363 #ifdef ADVANSYS_STATS
7364                 ascq->q_cur_cnt[i] = 0;
7365 #endif /* ADVANSYS_STATS */
7366             }
7367         }
7368 #ifdef ADVANSYS_STATS
7369         {
7370             REQP reqp;
7371             for (reqp = firstp; reqp; reqp = REQPNEXT(reqp)) {
7372                 REQTIMESTAT("asc_dequeue_list", ascq, reqp, reqp->device->id);
7373             }
7374         }
7375 #endif /* ADVANSYS_STATS */
7376     }
7377     if (lastpp) {
7378         *lastpp = lastp;
7379     }
7380     ASC_DBG1(3, "asc_dequeue_list: firstp 0x%lx\n", (ulong) firstp);
7381     return firstp;
7382 }
7383
7384 /*
7385  * Remove the specified 'REQP' from the specified queue for
7386  * the specified target device. Clear the 'tidmask' bit for the
7387  * device if no more commands are left queued for it.
7388  *
7389  * 'REQPNEXT(reqp)' returns reqp's the next pointer.
7390  *
7391  * Return ASC_TRUE if the command was found and removed,
7392  * otherwise return ASC_FALSE.
7393  */
7394 STATIC int
7395 asc_rmqueue(asc_queue_t *ascq, REQP reqp)
7396 {
7397     REQP        currp, prevp;
7398     int         tid;
7399     int         ret = ASC_FALSE;
7400
7401     ASC_DBG2(3, "asc_rmqueue: ascq 0x%lx, reqp 0x%lx\n",
7402         (ulong) ascq, (ulong) reqp);
7403     ASC_ASSERT(reqp != NULL);
7404
7405     tid = REQPTID(reqp);
7406     ASC_ASSERT(tid >= 0 && tid <= ADV_MAX_TID);
7407
7408     /*
7409      * Handle the common case of 'reqp' being the first
7410      * entry on the queue.
7411      */
7412     if (reqp == ascq->q_first[tid]) {
7413         ret = ASC_TRUE;
7414         ascq->q_first[tid] = REQPNEXT(reqp);
7415         /* If the queue is now empty, clear its bit and the last pointer. */
7416         if (ascq->q_first[tid] == NULL) {
7417             ascq->q_tidmask &= ~ADV_TID_TO_TIDMASK(tid);
7418             ASC_ASSERT(ascq->q_last[tid] == reqp);
7419             ascq->q_last[tid] = NULL;
7420         }
7421     } else if (ascq->q_first[tid] != NULL) {
7422         ASC_ASSERT(ascq->q_last[tid] != NULL);
7423         /*
7424          * Because the case of 'reqp' being the first entry has been
7425          * handled above and it is known the queue is not empty, if
7426          * 'reqp' is found on the queue it is guaranteed the queue will
7427          * not become empty and that 'q_first[tid]' will not be changed.
7428          *
7429          * Set 'prevp' to the first entry, 'currp' to the second entry,
7430          * and search for 'reqp'.
7431          */
7432         for (prevp = ascq->q_first[tid], currp = REQPNEXT(prevp);
7433              currp; prevp = currp, currp = REQPNEXT(currp)) {
7434             if (currp == reqp) {
7435                 ret = ASC_TRUE;
7436                 prevp->host_scribble = (unsigned char *)REQPNEXT(currp);
7437                 reqp->host_scribble = NULL;
7438                 if (ascq->q_last[tid] == reqp) {
7439                     ascq->q_last[tid] = prevp;
7440                 }
7441                 break;
7442             }
7443         }
7444     }
7445 #ifdef ADVANSYS_STATS
7446     /* Maintain request queue statistics. */
7447     if (ret == ASC_TRUE) {
7448         ascq->q_cur_cnt[tid]--;
7449         REQTIMESTAT("asc_rmqueue", ascq, reqp, tid);
7450     }
7451     ASC_ASSERT(ascq->q_cur_cnt[tid] >= 0);
7452 #endif /* ADVANSYS_STATS */
7453     ASC_DBG2(3, "asc_rmqueue: reqp 0x%lx, ret %d\n", (ulong) reqp, ret);
7454     return ret;
7455 }
7456
7457 /*
7458  * Execute as many queued requests as possible for the specified queue.
7459  *
7460  * Calls asc_execute_scsi_cmnd() to execute a REQP/struct scsi_cmnd.
7461  */
7462 STATIC void
7463 asc_execute_queue(asc_queue_t *ascq)
7464 {
7465     ADV_SCSI_BIT_ID_TYPE    scan_tidmask;
7466     REQP                    reqp;
7467     int                     i;
7468
7469     ASC_DBG1(1, "asc_execute_queue: ascq 0x%lx\n", (ulong) ascq);
7470     /*
7471      * Execute queued commands for devices attached to
7472      * the current board in round-robin fashion.
7473      */
7474     scan_tidmask = ascq->q_tidmask;
7475     do {
7476         for (i = 0; i <= ADV_MAX_TID; i++) {
7477             if (scan_tidmask & ADV_TID_TO_TIDMASK(i)) {
7478                 if ((reqp = asc_dequeue(ascq, i)) == NULL) {
7479                     scan_tidmask &= ~ADV_TID_TO_TIDMASK(i);
7480                 } else if (asc_execute_scsi_cmnd((struct scsi_cmnd *) reqp)
7481                             == ASC_BUSY) {
7482                     scan_tidmask &= ~ADV_TID_TO_TIDMASK(i);
7483                     /*
7484                      * The request returned ASC_BUSY. Enqueue at the front of
7485                      * target's waiting list to maintain correct ordering.
7486                      */
7487                     asc_enqueue(ascq, reqp, ASC_FRONT);
7488                 }
7489             }
7490         }
7491     } while (scan_tidmask);
7492     return;
7493 }
7494
7495 #ifdef CONFIG_PROC_FS
7496 /*
7497  * asc_prt_board_devices()
7498  *
7499  * Print driver information for devices attached to the board.
7500  *
7501  * Note: no single line should be greater than ASC_PRTLINE_SIZE,
7502  * cf. asc_prt_line().
7503  *
7504  * Return the number of characters copied into 'cp'. No more than
7505  * 'cplen' characters will be copied to 'cp'.
7506  */
7507 STATIC int
7508 asc_prt_board_devices(struct Scsi_Host *shp, char *cp, int cplen)
7509 {
7510     asc_board_t        *boardp;
7511     int                leftlen;
7512     int                totlen;
7513     int                len;
7514     int                chip_scsi_id;
7515     int                i;
7516
7517     boardp = ASC_BOARDP(shp);
7518     leftlen = cplen;
7519     totlen = len = 0;
7520
7521     len = asc_prt_line(cp, leftlen,
7522 "\nDevice Information for AdvanSys SCSI Host %d:\n", shp->host_no);
7523     ASC_PRT_NEXT();
7524
7525     if (ASC_NARROW_BOARD(boardp)) {
7526         chip_scsi_id = boardp->dvc_cfg.asc_dvc_cfg.chip_scsi_id;
7527     } else {
7528         chip_scsi_id = boardp->dvc_var.adv_dvc_var.chip_scsi_id;
7529     }
7530
7531     len = asc_prt_line(cp, leftlen, "Target IDs Detected:");
7532     ASC_PRT_NEXT();
7533     for (i = 0; i <= ADV_MAX_TID; i++) {
7534         if (boardp->init_tidmask & ADV_TID_TO_TIDMASK(i)) {
7535             len = asc_prt_line(cp, leftlen, " %X,", i);
7536             ASC_PRT_NEXT();
7537         }
7538     }
7539     len = asc_prt_line(cp, leftlen, " (%X=Host Adapter)\n", chip_scsi_id);
7540     ASC_PRT_NEXT();
7541
7542     return totlen;
7543 }
7544
7545 /*
7546  * Display Wide Board BIOS Information.
7547  */
7548 STATIC int
7549 asc_prt_adv_bios(struct Scsi_Host *shp, char *cp, int cplen)
7550 {
7551     asc_board_t        *boardp;
7552     int                leftlen;
7553     int                totlen;
7554     int                len;
7555     ushort             major, minor, letter;
7556
7557     boardp = ASC_BOARDP(shp);
7558     leftlen = cplen;
7559     totlen = len = 0;
7560
7561     len = asc_prt_line(cp, leftlen, "\nROM BIOS Version: ");
7562     ASC_PRT_NEXT();
7563
7564     /*
7565      * If the BIOS saved a valid signature, then fill in
7566      * the BIOS code segment base address.
7567      */
7568     if (boardp->bios_signature != 0x55AA) {
7569         len = asc_prt_line(cp, leftlen, "Disabled or Pre-3.1\n");
7570         ASC_PRT_NEXT();
7571         len = asc_prt_line(cp, leftlen,
7572 "BIOS either disabled or Pre-3.1. If it is pre-3.1, then a newer version\n");
7573         ASC_PRT_NEXT();
7574         len = asc_prt_line(cp, leftlen,
7575 "can be found at the ConnectCom FTP site: ftp://ftp.connectcom.net/pub\n");
7576         ASC_PRT_NEXT();
7577     } else {
7578         major = (boardp->bios_version >> 12) & 0xF;
7579         minor = (boardp->bios_version >> 8) & 0xF;
7580         letter = (boardp->bios_version & 0xFF);
7581
7582         len = asc_prt_line(cp, leftlen, "%d.%d%c\n",
7583             major, minor, letter >= 26 ? '?' : letter + 'A');
7584         ASC_PRT_NEXT();
7585
7586         /*
7587          * Current available ROM BIOS release is 3.1I for UW
7588          * and 3.2I for U2W. This code doesn't differentiate
7589          * UW and U2W boards.
7590          */
7591         if (major < 3 || (major <= 3 && minor < 1) ||
7592             (major <= 3 && minor <= 1 && letter < ('I'- 'A'))) {
7593             len = asc_prt_line(cp, leftlen,
7594 "Newer version of ROM BIOS is available at the ConnectCom FTP site:\n");
7595             ASC_PRT_NEXT();
7596             len = asc_prt_line(cp, leftlen,
7597 "ftp://ftp.connectcom.net/pub\n");
7598             ASC_PRT_NEXT();
7599         }
7600     }
7601
7602     return totlen;
7603 }
7604
7605 /*
7606  * Add serial number to information bar if signature AAh
7607  * is found in at bit 15-9 (7 bits) of word 1.
7608  *
7609  * Serial Number consists fo 12 alpha-numeric digits.
7610  *
7611  *       1 - Product type (A,B,C,D..)  Word0: 15-13 (3 bits)
7612  *       2 - MFG Location (A,B,C,D..)  Word0: 12-10 (3 bits)
7613  *     3-4 - Product ID (0-99)         Word0: 9-0 (10 bits)
7614  *       5 - Product revision (A-J)    Word0:  "         "
7615  *
7616  *           Signature                 Word1: 15-9 (7 bits)
7617  *       6 - Year (0-9)                Word1: 8-6 (3 bits) & Word2: 15 (1 bit)
7618  *     7-8 - Week of the year (1-52)   Word1: 5-0 (6 bits)
7619  *
7620  *    9-12 - Serial Number (A001-Z999) Word2: 14-0 (15 bits)
7621  *
7622  * Note 1: Only production cards will have a serial number.
7623  *
7624  * Note 2: Signature is most significant 7 bits (0xFE).
7625  *
7626  * Returns ASC_TRUE if serial number found, otherwise returns ASC_FALSE.
7627  */
7628 STATIC int
7629 asc_get_eeprom_string(ushort *serialnum, uchar *cp)
7630 {
7631     ushort      w, num;
7632
7633     if ((serialnum[1] & 0xFE00) != ((ushort) 0xAA << 8)) {
7634         return ASC_FALSE;
7635     } else {
7636         /*
7637          * First word - 6 digits.
7638          */
7639         w = serialnum[0];
7640
7641         /* Product type - 1st digit. */
7642         if ((*cp = 'A' + ((w & 0xE000) >> 13)) == 'H') {
7643             /* Product type is P=Prototype */
7644             *cp += 0x8;
7645         }
7646         cp++;
7647
7648         /* Manufacturing location - 2nd digit. */
7649         *cp++ = 'A' + ((w & 0x1C00) >> 10);
7650
7651         /* Product ID - 3rd, 4th digits. */
7652         num = w & 0x3FF;
7653         *cp++ = '0' + (num / 100);
7654         num %= 100;
7655         *cp++ = '0' + (num / 10);
7656
7657         /* Product revision - 5th digit. */
7658         *cp++ = 'A' + (num % 10);
7659
7660         /*
7661          * Second word
7662          */
7663         w = serialnum[1];
7664
7665         /*
7666          * Year - 6th digit.
7667          *
7668          * If bit 15 of third word is set, then the
7669          * last digit of the year is greater than 7.
7670          */
7671         if (serialnum[2] & 0x8000) {
7672             *cp++ = '8' + ((w & 0x1C0) >> 6);
7673         } else {
7674             *cp++ = '0' + ((w & 0x1C0) >> 6);
7675         }
7676
7677         /* Week of year - 7th, 8th digits. */
7678         num = w & 0x003F;
7679         *cp++ = '0' + num / 10;
7680         num %= 10;
7681         *cp++ = '0' + num;
7682
7683         /*
7684          * Third word
7685          */
7686         w = serialnum[2] & 0x7FFF;
7687
7688         /* Serial number - 9th digit. */
7689         *cp++ = 'A' + (w / 1000);
7690
7691         /* 10th, 11th, 12th digits. */
7692         num = w % 1000;
7693         *cp++ = '0' + num / 100;
7694         num %= 100;
7695         *cp++ = '0' + num / 10;
7696         num %= 10;
7697         *cp++ = '0' + num;
7698
7699         *cp = '\0';     /* Null Terminate the string. */
7700         return ASC_TRUE;
7701     }
7702 }
7703
7704 /*
7705  * asc_prt_asc_board_eeprom()
7706  *
7707  * Print board EEPROM configuration.
7708  *
7709  * Note: no single line should be greater than ASC_PRTLINE_SIZE,
7710  * cf. asc_prt_line().
7711  *
7712  * Return the number of characters copied into 'cp'. No more than
7713  * 'cplen' characters will be copied to 'cp'.
7714  */
7715 STATIC int
7716 asc_prt_asc_board_eeprom(struct Scsi_Host *shp, char *cp, int cplen)
7717 {
7718     asc_board_t        *boardp;
7719     ASC_DVC_VAR        *asc_dvc_varp;
7720     int                leftlen;
7721     int                totlen;
7722     int                len;
7723     ASCEEP_CONFIG      *ep;
7724     int                i;
7725 #ifdef CONFIG_ISA
7726     int                isa_dma_speed[] = { 10, 8, 7, 6, 5, 4, 3, 2 };
7727 #endif /* CONFIG_ISA */
7728     uchar              serialstr[13];
7729
7730     boardp = ASC_BOARDP(shp);
7731     asc_dvc_varp = &boardp->dvc_var.asc_dvc_var;
7732     ep = &boardp->eep_config.asc_eep;
7733
7734     leftlen = cplen;
7735     totlen = len = 0;
7736
7737     len = asc_prt_line(cp, leftlen,
7738 "\nEEPROM Settings for AdvanSys SCSI Host %d:\n", shp->host_no);
7739     ASC_PRT_NEXT();
7740
7741     if (asc_get_eeprom_string((ushort *) &ep->adapter_info[0], serialstr) ==
7742         ASC_TRUE) {
7743         len = asc_prt_line(cp, leftlen, " Serial Number: %s\n", serialstr);
7744         ASC_PRT_NEXT();
7745     } else {
7746         if (ep->adapter_info[5] == 0xBB) {
7747             len = asc_prt_line(cp, leftlen,
7748                 " Default Settings Used for EEPROM-less Adapter.\n");
7749             ASC_PRT_NEXT();
7750         } else {
7751             len = asc_prt_line(cp, leftlen,
7752                 " Serial Number Signature Not Present.\n");
7753             ASC_PRT_NEXT();
7754         }
7755     }
7756
7757     len = asc_prt_line(cp, leftlen,
7758 " Host SCSI ID: %u, Host Queue Size: %u, Device Queue Size: %u\n",
7759         ASC_EEP_GET_CHIP_ID(ep), ep->max_total_qng, ep->max_tag_qng);
7760     ASC_PRT_NEXT();
7761
7762     len = asc_prt_line(cp, leftlen,
7763 " cntl 0x%x, no_scam 0x%x\n",
7764         ep->cntl, ep->no_scam);
7765     ASC_PRT_NEXT();
7766
7767     len = asc_prt_line(cp, leftlen,
7768 " Target ID:           ");
7769     ASC_PRT_NEXT();
7770     for (i = 0; i <= ASC_MAX_TID; i++) {
7771         len = asc_prt_line(cp, leftlen, " %d", i);
7772         ASC_PRT_NEXT();
7773     }
7774     len = asc_prt_line(cp, leftlen, "\n");
7775     ASC_PRT_NEXT();
7776
7777     len = asc_prt_line(cp, leftlen,
7778 " Disconnects:         ");
7779     ASC_PRT_NEXT();
7780     for (i = 0; i <= ASC_MAX_TID; i++) {
7781         len = asc_prt_line(cp, leftlen, " %c",
7782             (ep->disc_enable & ADV_TID_TO_TIDMASK(i)) ? 'Y' : 'N');
7783         ASC_PRT_NEXT();
7784     }
7785     len = asc_prt_line(cp, leftlen, "\n");
7786     ASC_PRT_NEXT();
7787
7788     len = asc_prt_line(cp, leftlen,
7789 " Command Queuing:     ");
7790     ASC_PRT_NEXT();
7791     for (i = 0; i <= ASC_MAX_TID; i++) {
7792         len = asc_prt_line(cp, leftlen, " %c",
7793             (ep->use_cmd_qng & ADV_TID_TO_TIDMASK(i)) ? 'Y' : 'N');
7794         ASC_PRT_NEXT();
7795     }
7796     len = asc_prt_line(cp, leftlen, "\n");
7797     ASC_PRT_NEXT();
7798
7799     len = asc_prt_line(cp, leftlen,
7800 " Start Motor:         ");
7801     ASC_PRT_NEXT();
7802     for (i = 0; i <= ASC_MAX_TID; i++) {
7803         len = asc_prt_line(cp, leftlen, " %c",
7804             (ep->start_motor & ADV_TID_TO_TIDMASK(i)) ? 'Y' : 'N');
7805         ASC_PRT_NEXT();
7806     }
7807     len = asc_prt_line(cp, leftlen, "\n");
7808     ASC_PRT_NEXT();
7809
7810     len = asc_prt_line(cp, leftlen,
7811 " Synchronous Transfer:");
7812     ASC_PRT_NEXT();
7813     for (i = 0; i <= ASC_MAX_TID; i++) {
7814         len = asc_prt_line(cp, leftlen, " %c",
7815             (ep->init_sdtr & ADV_TID_TO_TIDMASK(i)) ? 'Y' : 'N');
7816         ASC_PRT_NEXT();
7817     }
7818     len = asc_prt_line(cp, leftlen, "\n");
7819     ASC_PRT_NEXT();
7820
7821 #ifdef CONFIG_ISA
7822     if (asc_dvc_varp->bus_type & ASC_IS_ISA) {
7823         len = asc_prt_line(cp, leftlen,
7824 " Host ISA DMA speed:   %d MB/S\n",
7825             isa_dma_speed[ASC_EEP_GET_DMA_SPD(ep)]);
7826         ASC_PRT_NEXT();
7827     }
7828 #endif /* CONFIG_ISA */
7829
7830      return totlen;
7831 }
7832
7833 /*
7834  * asc_prt_adv_board_eeprom()
7835  *
7836  * Print board EEPROM configuration.
7837  *
7838  * Note: no single line should be greater than ASC_PRTLINE_SIZE,
7839  * cf. asc_prt_line().
7840  *
7841  * Return the number of characters copied into 'cp'. No more than
7842  * 'cplen' characters will be copied to 'cp'.
7843  */
7844 STATIC int
7845 asc_prt_adv_board_eeprom(struct Scsi_Host *shp, char *cp, int cplen)
7846 {
7847     asc_board_t                 *boardp;
7848     ADV_DVC_VAR                 *adv_dvc_varp;
7849     int                         leftlen;
7850     int                         totlen;
7851     int                         len;
7852     int                         i;
7853     char                        *termstr;
7854     uchar                       serialstr[13];
7855     ADVEEP_3550_CONFIG          *ep_3550 = NULL;
7856     ADVEEP_38C0800_CONFIG       *ep_38C0800 = NULL;
7857     ADVEEP_38C1600_CONFIG       *ep_38C1600 = NULL;
7858     ushort                      word;
7859     ushort                      *wordp;
7860     ushort                      sdtr_speed = 0;
7861
7862     boardp = ASC_BOARDP(shp);
7863     adv_dvc_varp = &boardp->dvc_var.adv_dvc_var;
7864     if (adv_dvc_varp->chip_type == ADV_CHIP_ASC3550)
7865     {
7866         ep_3550 = &boardp->eep_config.adv_3550_eep;
7867     } else if (adv_dvc_varp->chip_type == ADV_CHIP_ASC38C0800)
7868     {
7869         ep_38C0800 = &boardp->eep_config.adv_38C0800_eep;
7870     } else
7871     {
7872         ep_38C1600 = &boardp->eep_config.adv_38C1600_eep;
7873     }
7874
7875     leftlen = cplen;
7876     totlen = len = 0;
7877
7878     len = asc_prt_line(cp, leftlen,
7879 "\nEEPROM Settings for AdvanSys SCSI Host %d:\n", shp->host_no);
7880     ASC_PRT_NEXT();
7881
7882     if (adv_dvc_varp->chip_type == ADV_CHIP_ASC3550)
7883     {
7884         wordp = &ep_3550->serial_number_word1;
7885     } else if (adv_dvc_varp->chip_type == ADV_CHIP_ASC38C0800)
7886     {
7887         wordp = &ep_38C0800->serial_number_word1;
7888     } else
7889     {
7890         wordp = &ep_38C1600->serial_number_word1;
7891     }
7892
7893     if (asc_get_eeprom_string(wordp, serialstr) == ASC_TRUE) {
7894         len = asc_prt_line(cp, leftlen, " Serial Number: %s\n", serialstr);
7895         ASC_PRT_NEXT();
7896     } else {
7897         len = asc_prt_line(cp, leftlen,
7898             " Serial Number Signature Not Present.\n");
7899         ASC_PRT_NEXT();
7900     }
7901
7902     if (adv_dvc_varp->chip_type == ADV_CHIP_ASC3550)
7903     {
7904         len = asc_prt_line(cp, leftlen,
7905 " Host SCSI ID: %u, Host Queue Size: %u, Device Queue Size: %u\n",
7906             ep_3550->adapter_scsi_id, ep_3550->max_host_qng,
7907             ep_3550->max_dvc_qng);
7908         ASC_PRT_NEXT();
7909     } else if (adv_dvc_varp->chip_type == ADV_CHIP_ASC38C0800)
7910     {
7911         len = asc_prt_line(cp, leftlen,
7912 " Host SCSI ID: %u, Host Queue Size: %u, Device Queue Size: %u\n",
7913             ep_38C0800->adapter_scsi_id, ep_38C0800->max_host_qng,
7914             ep_38C0800->max_dvc_qng);
7915         ASC_PRT_NEXT();
7916     } else
7917     {
7918         len = asc_prt_line(cp, leftlen,
7919 " Host SCSI ID: %u, Host Queue Size: %u, Device Queue Size: %u\n",
7920             ep_38C1600->adapter_scsi_id, ep_38C1600->max_host_qng,
7921             ep_38C1600->max_dvc_qng);
7922         ASC_PRT_NEXT();
7923     }
7924     if (adv_dvc_varp->chip_type == ADV_CHIP_ASC3550)
7925     {
7926         word = ep_3550->termination;
7927     } else if (adv_dvc_varp->chip_type == ADV_CHIP_ASC38C0800)
7928     {
7929         word = ep_38C0800->termination_lvd;
7930     } else
7931     {
7932         word = ep_38C1600->termination_lvd;
7933     }
7934     switch (word) {
7935         case 1:
7936             termstr = "Low Off/High Off";
7937             break;
7938         case 2:
7939             termstr = "Low Off/High On";
7940             break;
7941         case 3:
7942             termstr = "Low On/High On";
7943             break;
7944         default:
7945         case 0:
7946             termstr = "Automatic";
7947             break;
7948     }
7949
7950     if (adv_dvc_varp->chip_type == ADV_CHIP_ASC3550)
7951     {
7952         len = asc_prt_line(cp, leftlen,
7953 " termination: %u (%s), bios_ctrl: 0x%x\n",
7954             ep_3550->termination, termstr, ep_3550->bios_ctrl);
7955         ASC_PRT_NEXT();
7956     } else if (adv_dvc_varp->chip_type == ADV_CHIP_ASC38C0800)
7957     {
7958         len = asc_prt_line(cp, leftlen,
7959 " termination: %u (%s), bios_ctrl: 0x%x\n",
7960             ep_38C0800->termination_lvd, termstr, ep_38C0800->bios_ctrl);
7961         ASC_PRT_NEXT();
7962     } else
7963     {
7964         len = asc_prt_line(cp, leftlen,
7965 " termination: %u (%s), bios_ctrl: 0x%x\n",
7966             ep_38C1600->termination_lvd, termstr, ep_38C1600->bios_ctrl);
7967         ASC_PRT_NEXT();
7968     }
7969
7970     len = asc_prt_line(cp, leftlen,
7971 " Target ID:           ");
7972     ASC_PRT_NEXT();
7973     for (i = 0; i <= ADV_MAX_TID; i++) {
7974         len = asc_prt_line(cp, leftlen, " %X", i);
7975         ASC_PRT_NEXT();
7976     }
7977     len = asc_prt_line(cp, leftlen, "\n");
7978     ASC_PRT_NEXT();
7979
7980     if (adv_dvc_varp->chip_type == ADV_CHIP_ASC3550)
7981     {
7982         word = ep_3550->disc_enable;
7983     } else if (adv_dvc_varp->chip_type == ADV_CHIP_ASC38C0800)
7984     {
7985         word = ep_38C0800->disc_enable;
7986     } else
7987     {
7988         word = ep_38C1600->disc_enable;
7989     }
7990     len = asc_prt_line(cp, leftlen,
7991 " Disconnects:         ");
7992     ASC_PRT_NEXT();
7993     for (i = 0; i <= ADV_MAX_TID; i++) {
7994         len = asc_prt_line(cp, leftlen, " %c",
7995             (word & ADV_TID_TO_TIDMASK(i)) ? 'Y' : 'N');
7996         ASC_PRT_NEXT();
7997     }
7998     len = asc_prt_line(cp, leftlen, "\n");
7999     ASC_PRT_NEXT();
8000
8001     if (adv_dvc_varp->chip_type == ADV_CHIP_ASC3550)
8002     {
8003         word = ep_3550->tagqng_able;
8004     } else if (adv_dvc_varp->chip_type == ADV_CHIP_ASC38C0800)
8005     {
8006         word = ep_38C0800->tagqng_able;
8007     } else
8008     {
8009         word = ep_38C1600->tagqng_able;
8010     }
8011     len = asc_prt_line(cp, leftlen,
8012 " Command Queuing:     ");
8013     ASC_PRT_NEXT();
8014     for (i = 0; i <= ADV_MAX_TID; i++) {
8015         len = asc_prt_line(cp, leftlen, " %c",
8016             (word & ADV_TID_TO_TIDMASK(i)) ? 'Y' : 'N');
8017         ASC_PRT_NEXT();
8018     }
8019     len = asc_prt_line(cp, leftlen, "\n");
8020     ASC_PRT_NEXT();
8021
8022     if (adv_dvc_varp->chip_type == ADV_CHIP_ASC3550)
8023     {
8024         word = ep_3550->start_motor;
8025     } else if (adv_dvc_varp->chip_type == ADV_CHIP_ASC38C0800)
8026     {
8027         word = ep_38C0800->start_motor;
8028     } else
8029     {
8030         word = ep_38C1600->start_motor;
8031     }
8032     len = asc_prt_line(cp, leftlen,
8033 " Start Motor:         ");
8034     ASC_PRT_NEXT();
8035     for (i = 0; i <= ADV_MAX_TID; i++) {
8036         len = asc_prt_line(cp, leftlen, " %c",
8037             (word & ADV_TID_TO_TIDMASK(i)) ? 'Y' : 'N');
8038         ASC_PRT_NEXT();
8039     }
8040     len = asc_prt_line(cp, leftlen, "\n");
8041     ASC_PRT_NEXT();
8042
8043     if (adv_dvc_varp->chip_type == ADV_CHIP_ASC3550)
8044     {
8045         len = asc_prt_line(cp, leftlen,
8046 " Synchronous Transfer:");
8047         ASC_PRT_NEXT();
8048         for (i = 0; i <= ADV_MAX_TID; i++) {
8049             len = asc_prt_line(cp, leftlen, " %c",
8050                 (ep_3550->sdtr_able & ADV_TID_TO_TIDMASK(i)) ? 'Y' : 'N');
8051             ASC_PRT_NEXT();
8052         }
8053         len = asc_prt_line(cp, leftlen, "\n");
8054         ASC_PRT_NEXT();
8055     }
8056
8057     if (adv_dvc_varp->chip_type == ADV_CHIP_ASC3550)
8058     {
8059         len = asc_prt_line(cp, leftlen,
8060 " Ultra Transfer:      ");
8061     ASC_PRT_NEXT();
8062         for (i = 0; i <= ADV_MAX_TID; i++) {
8063             len = asc_prt_line(cp, leftlen, " %c",
8064                 (ep_3550->ultra_able & ADV_TID_TO_TIDMASK(i)) ? 'Y' : 'N');
8065             ASC_PRT_NEXT();
8066         }
8067         len = asc_prt_line(cp, leftlen, "\n");
8068         ASC_PRT_NEXT();
8069     }
8070
8071     if (adv_dvc_varp->chip_type == ADV_CHIP_ASC3550)
8072     {
8073         word = ep_3550->wdtr_able;
8074     } else if (adv_dvc_varp->chip_type == ADV_CHIP_ASC38C0800)
8075     {
8076         word = ep_38C0800->wdtr_able;
8077     } else
8078     {
8079         word = ep_38C1600->wdtr_able;
8080     }
8081     len = asc_prt_line(cp, leftlen,
8082 " Wide Transfer:       ");
8083     ASC_PRT_NEXT();
8084     for (i = 0; i <= ADV_MAX_TID; i++) {
8085         len = asc_prt_line(cp, leftlen, " %c",
8086             (word & ADV_TID_TO_TIDMASK(i)) ? 'Y' : 'N');
8087         ASC_PRT_NEXT();
8088     }
8089     len = asc_prt_line(cp, leftlen, "\n");
8090     ASC_PRT_NEXT();
8091
8092     if (adv_dvc_varp->chip_type == ADV_CHIP_ASC38C0800 ||
8093         adv_dvc_varp->chip_type == ADV_CHIP_ASC38C1600)
8094     {
8095         len = asc_prt_line(cp, leftlen,
8096 " Synchronous Transfer Speed (Mhz):\n  ");
8097         ASC_PRT_NEXT();
8098         for (i = 0; i <= ADV_MAX_TID; i++) {
8099             char *speed_str;
8100
8101             if (i == 0)
8102             {
8103                 sdtr_speed = adv_dvc_varp->sdtr_speed1;
8104             } else if (i == 4)
8105             {
8106                 sdtr_speed = adv_dvc_varp->sdtr_speed2;
8107             } else if (i == 8)
8108             {
8109                 sdtr_speed = adv_dvc_varp->sdtr_speed3;
8110             } else if (i == 12)
8111             {
8112                 sdtr_speed = adv_dvc_varp->sdtr_speed4;
8113             }
8114             switch (sdtr_speed & ADV_MAX_TID)
8115             {
8116                 case 0:  speed_str = "Off"; break;
8117                 case 1:  speed_str = "  5"; break;
8118                 case 2:  speed_str = " 10"; break;
8119                 case 3:  speed_str = " 20"; break;
8120                 case 4:  speed_str = " 40"; break;
8121                 case 5:  speed_str = " 80"; break;
8122                 default: speed_str = "Unk"; break;
8123             }
8124             len = asc_prt_line(cp, leftlen, "%X:%s ", i, speed_str);
8125             ASC_PRT_NEXT();
8126             if (i == 7)
8127             {
8128                 len = asc_prt_line(cp, leftlen, "\n  ");
8129                 ASC_PRT_NEXT();
8130             }
8131             sdtr_speed >>= 4;
8132         }
8133         len = asc_prt_line(cp, leftlen, "\n");
8134         ASC_PRT_NEXT();
8135     }
8136
8137     return totlen;
8138 }
8139
8140 /*
8141  * asc_prt_driver_conf()
8142  *
8143  * Note: no single line should be greater than ASC_PRTLINE_SIZE,
8144  * cf. asc_prt_line().
8145  *
8146  * Return the number of characters copied into 'cp'. No more than
8147  * 'cplen' characters will be copied to 'cp'.
8148  */
8149 STATIC int
8150 asc_prt_driver_conf(struct Scsi_Host *shp, char *cp, int cplen)
8151 {
8152     asc_board_t            *boardp;
8153     int                    leftlen;
8154     int                    totlen;
8155     int                    len;
8156     int                    chip_scsi_id;
8157
8158     boardp = ASC_BOARDP(shp);
8159
8160     leftlen = cplen;
8161     totlen = len = 0;
8162
8163     len = asc_prt_line(cp, leftlen,
8164 "\nLinux Driver Configuration and Information for AdvanSys SCSI Host %d:\n",
8165         shp->host_no);
8166     ASC_PRT_NEXT();
8167
8168     len = asc_prt_line(cp, leftlen,
8169 " host_busy %u, last_reset %u, max_id %u, max_lun %u, max_channel %u\n",
8170         shp->host_busy, shp->last_reset, shp->max_id, shp->max_lun,
8171         shp->max_channel);
8172     ASC_PRT_NEXT();
8173
8174     len = asc_prt_line(cp, leftlen,
8175 " unique_id %d, can_queue %d, this_id %d, sg_tablesize %u, cmd_per_lun %u\n",
8176         shp->unique_id, shp->can_queue, shp->this_id, shp->sg_tablesize,
8177         shp->cmd_per_lun);
8178     ASC_PRT_NEXT();
8179
8180     len = asc_prt_line(cp, leftlen,
8181 " unchecked_isa_dma %d, use_clustering %d\n",
8182         shp->unchecked_isa_dma, shp->use_clustering);
8183     ASC_PRT_NEXT();
8184
8185     len = asc_prt_line(cp, leftlen,
8186 " flags 0x%x, last_reset 0x%x, jiffies 0x%x, asc_n_io_port 0x%x\n",
8187         boardp->flags, boardp->last_reset, jiffies, boardp->asc_n_io_port);
8188     ASC_PRT_NEXT();
8189
8190      /* 'shp->n_io_port' may be truncated because it is only one byte. */
8191     len = asc_prt_line(cp, leftlen,
8192 " io_port 0x%x, n_io_port 0x%x\n",
8193         shp->io_port, shp->n_io_port);
8194     ASC_PRT_NEXT();
8195
8196     if (ASC_NARROW_BOARD(boardp)) {
8197         chip_scsi_id = boardp->dvc_cfg.asc_dvc_cfg.chip_scsi_id;
8198     } else {
8199         chip_scsi_id = boardp->dvc_var.adv_dvc_var.chip_scsi_id;
8200     }
8201
8202     return totlen;
8203 }
8204
8205 /*
8206  * asc_prt_asc_board_info()
8207  *
8208  * Print dynamic board configuration information.
8209  *
8210  * Note: no single line should be greater than ASC_PRTLINE_SIZE,
8211  * cf. asc_prt_line().
8212  *
8213  * Return the number of characters copied into 'cp'. No more than
8214  * 'cplen' characters will be copied to 'cp'.
8215  */
8216 STATIC int
8217 asc_prt_asc_board_info(struct Scsi_Host *shp, char *cp, int cplen)
8218 {
8219     asc_board_t            *boardp;
8220     int                    chip_scsi_id;
8221     int                    leftlen;
8222     int                    totlen;
8223     int                    len;
8224     ASC_DVC_VAR            *v;
8225     ASC_DVC_CFG            *c;
8226     int                    i;
8227     int                    renegotiate = 0;
8228
8229     boardp = ASC_BOARDP(shp);
8230     v = &boardp->dvc_var.asc_dvc_var;
8231     c = &boardp->dvc_cfg.asc_dvc_cfg;
8232     chip_scsi_id = c->chip_scsi_id;
8233
8234     leftlen = cplen;
8235     totlen = len = 0;
8236
8237     len = asc_prt_line(cp, leftlen,
8238 "\nAsc Library Configuration and Statistics for AdvanSys SCSI Host %d:\n",
8239     shp->host_no);
8240     ASC_PRT_NEXT();
8241
8242     len = asc_prt_line(cp, leftlen,
8243 " chip_version %u, lib_version 0x%x, lib_serial_no %u, mcode_date 0x%x\n",
8244         c->chip_version, c->lib_version, c->lib_serial_no, c->mcode_date);
8245     ASC_PRT_NEXT();
8246
8247     len = asc_prt_line(cp, leftlen,
8248 " mcode_version 0x%x, err_code %u\n",
8249          c->mcode_version, v->err_code);
8250     ASC_PRT_NEXT();
8251
8252     /* Current number of commands waiting for the host. */
8253     len = asc_prt_line(cp, leftlen,
8254 " Total Command Pending: %d\n", v->cur_total_qng);
8255     ASC_PRT_NEXT();
8256
8257     len = asc_prt_line(cp, leftlen,
8258 " Command Queuing:");
8259     ASC_PRT_NEXT();
8260     for (i = 0; i <= ASC_MAX_TID; i++) {
8261         if ((chip_scsi_id == i) ||
8262             ((boardp->init_tidmask & ADV_TID_TO_TIDMASK(i)) == 0)) {
8263             continue;
8264         }
8265         len = asc_prt_line(cp, leftlen, " %X:%c",
8266             i, (v->use_tagged_qng & ADV_TID_TO_TIDMASK(i)) ? 'Y' : 'N');
8267         ASC_PRT_NEXT();
8268     }
8269     len = asc_prt_line(cp, leftlen, "\n");
8270     ASC_PRT_NEXT();
8271
8272     /* Current number of commands waiting for a device. */
8273     len = asc_prt_line(cp, leftlen,
8274 " Command Queue Pending:");
8275     ASC_PRT_NEXT();
8276     for (i = 0; i <= ASC_MAX_TID; i++) {
8277         if ((chip_scsi_id == i) ||
8278             ((boardp->init_tidmask & ADV_TID_TO_TIDMASK(i)) == 0)) {
8279             continue;
8280         }
8281         len = asc_prt_line(cp, leftlen, " %X:%u", i, v->cur_dvc_qng[i]);
8282         ASC_PRT_NEXT();
8283     }
8284     len = asc_prt_line(cp, leftlen, "\n");
8285     ASC_PRT_NEXT();
8286
8287     /* Current limit on number of commands that can be sent to a device. */
8288     len = asc_prt_line(cp, leftlen,
8289 " Command Queue Limit:");
8290     ASC_PRT_NEXT();
8291     for (i = 0; i <= ASC_MAX_TID; i++) {
8292         if ((chip_scsi_id == i) ||
8293             ((boardp->init_tidmask & ADV_TID_TO_TIDMASK(i)) == 0)) {
8294             continue;
8295         }
8296         len = asc_prt_line(cp, leftlen, " %X:%u", i, v->max_dvc_qng[i]);
8297         ASC_PRT_NEXT();
8298     }
8299     len = asc_prt_line(cp, leftlen, "\n");
8300     ASC_PRT_NEXT();
8301
8302     /* Indicate whether the device has returned queue full status. */
8303     len = asc_prt_line(cp, leftlen,
8304 " Command Queue Full:");
8305     ASC_PRT_NEXT();
8306     for (i = 0; i <= ASC_MAX_TID; i++) {
8307         if ((chip_scsi_id == i) ||
8308             ((boardp->init_tidmask & ADV_TID_TO_TIDMASK(i)) == 0)) {
8309             continue;
8310         }
8311         if (boardp->queue_full & ADV_TID_TO_TIDMASK(i)) {
8312             len = asc_prt_line(cp, leftlen, " %X:Y-%d",
8313                 i, boardp->queue_full_cnt[i]);
8314         } else {
8315             len = asc_prt_line(cp, leftlen, " %X:N", i);
8316         }
8317         ASC_PRT_NEXT();
8318     }
8319     len = asc_prt_line(cp, leftlen, "\n");
8320     ASC_PRT_NEXT();
8321
8322     len = asc_prt_line(cp, leftlen,
8323 " Synchronous Transfer:");
8324     ASC_PRT_NEXT();
8325     for (i = 0; i <= ASC_MAX_TID; i++) {
8326         if ((chip_scsi_id == i) ||
8327             ((boardp->init_tidmask & ADV_TID_TO_TIDMASK(i)) == 0)) {
8328             continue;
8329         }
8330         len = asc_prt_line(cp, leftlen, " %X:%c",
8331             i, (v->sdtr_done & ADV_TID_TO_TIDMASK(i)) ? 'Y' : 'N');
8332         ASC_PRT_NEXT();
8333     }
8334     len = asc_prt_line(cp, leftlen, "\n");
8335     ASC_PRT_NEXT();
8336
8337     for (i = 0; i <= ASC_MAX_TID; i++) {
8338         uchar syn_period_ix;
8339
8340         if ((chip_scsi_id == i) ||
8341             ((boardp->init_tidmask & ADV_TID_TO_TIDMASK(i)) == 0) ||
8342             ((v->init_sdtr & ADV_TID_TO_TIDMASK(i)) == 0)) {
8343             continue;
8344         }
8345
8346         len = asc_prt_line(cp, leftlen, "  %X:", i);
8347         ASC_PRT_NEXT();
8348
8349         if ((boardp->sdtr_data[i] & ASC_SYN_MAX_OFFSET) == 0)
8350         {
8351             len = asc_prt_line(cp, leftlen, " Asynchronous");
8352             ASC_PRT_NEXT();
8353         } else
8354         {
8355             syn_period_ix =
8356                 (boardp->sdtr_data[i] >> 4) & (v->max_sdtr_index - 1);
8357
8358             len = asc_prt_line(cp, leftlen,
8359                 " Transfer Period Factor: %d (%d.%d Mhz),",
8360                 v->sdtr_period_tbl[syn_period_ix],
8361                 250 / v->sdtr_period_tbl[syn_period_ix],
8362                 ASC_TENTHS(250, v->sdtr_period_tbl[syn_period_ix]));
8363             ASC_PRT_NEXT();
8364
8365             len = asc_prt_line(cp, leftlen, " REQ/ACK Offset: %d",
8366                 boardp->sdtr_data[i] & ASC_SYN_MAX_OFFSET);
8367             ASC_PRT_NEXT();
8368         }
8369
8370         if ((v->sdtr_done & ADV_TID_TO_TIDMASK(i)) == 0) {
8371             len = asc_prt_line(cp, leftlen, "*\n");
8372             renegotiate = 1;
8373         } else
8374         {
8375             len = asc_prt_line(cp, leftlen, "\n");
8376         }
8377         ASC_PRT_NEXT();
8378     }
8379
8380     if (renegotiate)
8381     {
8382         len = asc_prt_line(cp, leftlen,
8383             " * = Re-negotiation pending before next command.\n");
8384         ASC_PRT_NEXT();
8385     }
8386
8387     return totlen;
8388 }
8389
8390 /*
8391  * asc_prt_adv_board_info()
8392  *
8393  * Print dynamic board configuration information.
8394  *
8395  * Note: no single line should be greater than ASC_PRTLINE_SIZE,
8396  * cf. asc_prt_line().
8397  *
8398  * Return the number of characters copied into 'cp'. No more than
8399  * 'cplen' characters will be copied to 'cp'.
8400  */
8401 STATIC int
8402 asc_prt_adv_board_info(struct Scsi_Host *shp, char *cp, int cplen)
8403 {
8404     asc_board_t            *boardp;
8405     int                    leftlen;
8406     int                    totlen;
8407     int                    len;
8408     int                    i;
8409     ADV_DVC_VAR            *v;
8410     ADV_DVC_CFG            *c;
8411     AdvPortAddr            iop_base;
8412     ushort                 chip_scsi_id;
8413     ushort                 lramword;
8414     uchar                  lrambyte;
8415     ushort                 tagqng_able;
8416     ushort                 sdtr_able, wdtr_able;
8417     ushort                 wdtr_done, sdtr_done;
8418     ushort                 period = 0;
8419     int                    renegotiate = 0;
8420
8421     boardp = ASC_BOARDP(shp);
8422     v = &boardp->dvc_var.adv_dvc_var;
8423     c = &boardp->dvc_cfg.adv_dvc_cfg;
8424     iop_base = v->iop_base;
8425     chip_scsi_id = v->chip_scsi_id;
8426
8427     leftlen = cplen;
8428     totlen = len = 0;
8429
8430     len = asc_prt_line(cp, leftlen,
8431 "\nAdv Library Configuration and Statistics for AdvanSys SCSI Host %d:\n",
8432     shp->host_no);
8433     ASC_PRT_NEXT();
8434
8435     len = asc_prt_line(cp, leftlen,
8436 " iop_base 0x%lx, cable_detect: %X, err_code %u\n",
8437          v->iop_base,
8438          AdvReadWordRegister(iop_base, IOPW_SCSI_CFG1) & CABLE_DETECT,
8439          v->err_code);
8440     ASC_PRT_NEXT();
8441
8442     len = asc_prt_line(cp, leftlen,
8443 " chip_version %u, lib_version 0x%x, mcode_date 0x%x, mcode_version 0x%x\n",
8444         c->chip_version, c->lib_version, c->mcode_date, c->mcode_version);
8445     ASC_PRT_NEXT();
8446
8447     AdvReadWordLram(iop_base, ASC_MC_TAGQNG_ABLE, tagqng_able);
8448     len = asc_prt_line(cp, leftlen,
8449 " Queuing Enabled:");
8450     ASC_PRT_NEXT();
8451     for (i = 0; i <= ADV_MAX_TID; i++) {
8452         if ((chip_scsi_id == i) ||
8453             ((boardp->init_tidmask & ADV_TID_TO_TIDMASK(i)) == 0)) {
8454             continue;
8455         }
8456
8457         len = asc_prt_line(cp, leftlen, " %X:%c",
8458             i, (tagqng_able & ADV_TID_TO_TIDMASK(i)) ? 'Y' : 'N');
8459         ASC_PRT_NEXT();
8460     }
8461     len = asc_prt_line(cp, leftlen, "\n");
8462     ASC_PRT_NEXT();
8463
8464     len = asc_prt_line(cp, leftlen,
8465 " Queue Limit:");
8466     ASC_PRT_NEXT();
8467     for (i = 0; i <= ADV_MAX_TID; i++) {
8468         if ((chip_scsi_id == i) ||
8469             ((boardp->init_tidmask & ADV_TID_TO_TIDMASK(i)) == 0)) {
8470             continue;
8471         }
8472
8473         AdvReadByteLram(iop_base, ASC_MC_NUMBER_OF_MAX_CMD + i, lrambyte);
8474
8475         len = asc_prt_line(cp, leftlen, " %X:%d", i, lrambyte);
8476         ASC_PRT_NEXT();
8477     }
8478     len = asc_prt_line(cp, leftlen, "\n");
8479     ASC_PRT_NEXT();
8480
8481     len = asc_prt_line(cp, leftlen,
8482 " Command Pending:");
8483     ASC_PRT_NEXT();
8484     for (i = 0; i <= ADV_MAX_TID; i++) {
8485         if ((chip_scsi_id == i) ||
8486             ((boardp->init_tidmask & ADV_TID_TO_TIDMASK(i)) == 0)) {
8487             continue;
8488         }
8489
8490         AdvReadByteLram(iop_base, ASC_MC_NUMBER_OF_QUEUED_CMD + i, lrambyte);
8491
8492         len = asc_prt_line(cp, leftlen, " %X:%d", i, lrambyte);
8493         ASC_PRT_NEXT();
8494     }
8495     len = asc_prt_line(cp, leftlen, "\n");
8496     ASC_PRT_NEXT();
8497
8498     AdvReadWordLram(iop_base, ASC_MC_WDTR_ABLE, wdtr_able);
8499     len = asc_prt_line(cp, leftlen,
8500 " Wide Enabled:");
8501     ASC_PRT_NEXT();
8502     for (i = 0; i <= ADV_MAX_TID; i++) {
8503         if ((chip_scsi_id == i) ||
8504             ((boardp->init_tidmask & ADV_TID_TO_TIDMASK(i)) == 0)) {
8505             continue;
8506         }
8507
8508         len = asc_prt_line(cp, leftlen, " %X:%c",
8509             i, (wdtr_able & ADV_TID_TO_TIDMASK(i)) ? 'Y' : 'N');
8510         ASC_PRT_NEXT();
8511     }
8512     len = asc_prt_line(cp, leftlen, "\n");
8513     ASC_PRT_NEXT();
8514
8515     AdvReadWordLram(iop_base, ASC_MC_WDTR_DONE, wdtr_done);
8516     len = asc_prt_line(cp, leftlen,
8517 " Transfer Bit Width:");
8518     ASC_PRT_NEXT();
8519     for (i = 0; i <= ADV_MAX_TID; i++) {
8520         if ((chip_scsi_id == i) ||
8521             ((boardp->init_tidmask & ADV_TID_TO_TIDMASK(i)) == 0)) {
8522             continue;
8523         }
8524
8525         AdvReadWordLram(iop_base, ASC_MC_DEVICE_HSHK_CFG_TABLE + (2 * i),
8526             lramword);
8527
8528         len = asc_prt_line(cp, leftlen, " %X:%d",
8529             i, (lramword & 0x8000) ? 16 : 8);
8530         ASC_PRT_NEXT();
8531
8532         if ((wdtr_able & ADV_TID_TO_TIDMASK(i)) &&
8533             (wdtr_done & ADV_TID_TO_TIDMASK(i)) == 0) {
8534             len = asc_prt_line(cp, leftlen, "*");
8535             ASC_PRT_NEXT();
8536             renegotiate = 1;
8537         }
8538     }
8539     len = asc_prt_line(cp, leftlen, "\n");
8540     ASC_PRT_NEXT();
8541
8542     AdvReadWordLram(iop_base, ASC_MC_SDTR_ABLE, sdtr_able);
8543     len = asc_prt_line(cp, leftlen,
8544 " Synchronous Enabled:");
8545     ASC_PRT_NEXT();
8546     for (i = 0; i <= ADV_MAX_TID; i++) {
8547         if ((chip_scsi_id == i) ||
8548             ((boardp->init_tidmask & ADV_TID_TO_TIDMASK(i)) == 0)) {
8549             continue;
8550         }
8551
8552         len = asc_prt_line(cp, leftlen, " %X:%c",
8553             i, (sdtr_able & ADV_TID_TO_TIDMASK(i)) ? 'Y' : 'N');
8554         ASC_PRT_NEXT();
8555     }
8556     len = asc_prt_line(cp, leftlen, "\n");
8557     ASC_PRT_NEXT();
8558
8559     AdvReadWordLram(iop_base, ASC_MC_SDTR_DONE, sdtr_done);
8560     for (i = 0; i <= ADV_MAX_TID; i++) {
8561
8562         AdvReadWordLram(iop_base, ASC_MC_DEVICE_HSHK_CFG_TABLE + (2 * i),
8563             lramword);
8564         lramword &= ~0x8000;
8565
8566         if ((chip_scsi_id == i) ||
8567             ((boardp->init_tidmask & ADV_TID_TO_TIDMASK(i)) == 0) ||
8568             ((sdtr_able & ADV_TID_TO_TIDMASK(i)) == 0)) {
8569             continue;
8570         }
8571
8572         len = asc_prt_line(cp, leftlen, "  %X:", i);
8573         ASC_PRT_NEXT();
8574
8575         if ((lramword & 0x1F) == 0) /* Check for REQ/ACK Offset 0. */
8576         {
8577             len = asc_prt_line(cp, leftlen, " Asynchronous");
8578             ASC_PRT_NEXT();
8579         } else
8580         {
8581             len = asc_prt_line(cp, leftlen, " Transfer Period Factor: ");
8582             ASC_PRT_NEXT();
8583
8584             if ((lramword & 0x1F00) == 0x1100) /* 80 Mhz */
8585             {
8586                 len = asc_prt_line(cp, leftlen, "9 (80.0 Mhz),");
8587                 ASC_PRT_NEXT();
8588             } else if ((lramword & 0x1F00) == 0x1000) /* 40 Mhz */
8589             {
8590                 len = asc_prt_line(cp, leftlen, "10 (40.0 Mhz),");
8591                 ASC_PRT_NEXT();
8592             } else /* 20 Mhz or below. */
8593             {
8594                 period = (((lramword >> 8) * 25) + 50)/4;
8595
8596                 if (period == 0) /* Should never happen. */
8597                 {
8598                     len = asc_prt_line(cp, leftlen, "%d (? Mhz), ");
8599                     ASC_PRT_NEXT();
8600                 } else
8601                 {
8602                     len = asc_prt_line(cp, leftlen,
8603                         "%d (%d.%d Mhz),",
8604                         period, 250/period, ASC_TENTHS(250, period));
8605                     ASC_PRT_NEXT();
8606                 }
8607             }
8608
8609             len = asc_prt_line(cp, leftlen, " REQ/ACK Offset: %d",
8610                 lramword & 0x1F);
8611             ASC_PRT_NEXT();
8612         }
8613
8614         if ((sdtr_done & ADV_TID_TO_TIDMASK(i)) == 0) {
8615             len = asc_prt_line(cp, leftlen, "*\n");
8616             renegotiate = 1;
8617         } else
8618         {
8619             len = asc_prt_line(cp, leftlen, "\n");
8620         }
8621         ASC_PRT_NEXT();
8622     }
8623
8624     if (renegotiate)
8625     {
8626         len = asc_prt_line(cp, leftlen,
8627             " * = Re-negotiation pending before next command.\n");
8628         ASC_PRT_NEXT();
8629     }
8630
8631     return totlen;
8632 }
8633
8634 /*
8635  * asc_proc_copy()
8636  *
8637  * Copy proc information to a read buffer taking into account the current
8638  * read offset in the file and the remaining space in the read buffer.
8639  */
8640 STATIC int
8641 asc_proc_copy(off_t advoffset, off_t offset, char *curbuf, int leftlen,
8642               char *cp, int cplen)
8643 {
8644     int cnt = 0;
8645
8646     ASC_DBG3(2, "asc_proc_copy: offset %d, advoffset %d, cplen %d\n",
8647             (unsigned) offset, (unsigned) advoffset, cplen);
8648     if (offset <= advoffset) {
8649         /* Read offset below current offset, copy everything. */
8650         cnt = min(cplen, leftlen);
8651         ASC_DBG3(2, "asc_proc_copy: curbuf 0x%lx, cp 0x%lx, cnt %d\n",
8652                 (ulong) curbuf, (ulong) cp, cnt);
8653         memcpy(curbuf, cp, cnt);
8654     } else if (offset < advoffset + cplen) {
8655         /* Read offset within current range, partial copy. */
8656         cnt = (advoffset + cplen) - offset;
8657         cp = (cp + cplen) - cnt;
8658         cnt = min(cnt, leftlen);
8659         ASC_DBG3(2, "asc_proc_copy: curbuf 0x%lx, cp 0x%lx, cnt %d\n",
8660                 (ulong) curbuf, (ulong) cp, cnt);
8661         memcpy(curbuf, cp, cnt);
8662     }
8663     return cnt;
8664 }
8665
8666 /*
8667  * asc_prt_line()
8668  *
8669  * If 'cp' is NULL print to the console, otherwise print to a buffer.
8670  *
8671  * Return 0 if printing to the console, otherwise return the number of
8672  * bytes written to the buffer.
8673  *
8674  * Note: If any single line is greater than ASC_PRTLINE_SIZE bytes the stack
8675  * will be corrupted. 's[]' is defined to be ASC_PRTLINE_SIZE bytes.
8676  */
8677 STATIC int
8678 asc_prt_line(char *buf, int buflen, char *fmt, ...)
8679 {
8680     va_list        args;
8681     int            ret;
8682     char           s[ASC_PRTLINE_SIZE];
8683
8684     va_start(args, fmt);
8685     ret = vsprintf(s, fmt, args);
8686     ASC_ASSERT(ret < ASC_PRTLINE_SIZE);
8687     if (buf == NULL) {
8688         (void) printk(s);
8689         ret = 0;
8690     } else {
8691         ret = min(buflen, ret);
8692         memcpy(buf, s, ret);
8693     }
8694     va_end(args);
8695     return ret;
8696 }
8697 #endif /* CONFIG_PROC_FS */
8698
8699
8700 /*
8701  * --- Functions Required by the Asc Library
8702  */
8703
8704 /*
8705  * Delay for 'n' milliseconds. Don't use the 'jiffies'
8706  * global variable which is incremented once every 5 ms
8707  * from a timer interrupt, because this function may be
8708  * called when interrupts are disabled.
8709  */
8710 STATIC void
8711 DvcSleepMilliSecond(ADV_DCNT n)
8712 {
8713     ASC_DBG1(4, "DvcSleepMilliSecond: %lu\n", (ulong) n);
8714     mdelay(n);
8715 }
8716
8717 /*
8718  * Currently and inline noop but leave as a placeholder.
8719  * Leave DvcEnterCritical() as a noop placeholder.
8720  */
8721 STATIC inline ulong
8722 DvcEnterCritical(void)
8723 {
8724     return 0;
8725 }
8726
8727 /*
8728  * Critical sections are all protected by the board spinlock.
8729  * Leave DvcLeaveCritical() as a noop placeholder.
8730  */
8731 STATIC inline void
8732 DvcLeaveCritical(ulong flags)
8733 {
8734     return;
8735 }
8736
8737 /*
8738  * void
8739  * DvcPutScsiQ(PortAddr iop_base, ushort s_addr, uchar *outbuf, int words)
8740  *
8741  * Calling/Exit State:
8742  *    none
8743  *
8744  * Description:
8745  *     Output an ASC_SCSI_Q structure to the chip
8746  */
8747 STATIC void
8748 DvcPutScsiQ(PortAddr iop_base, ushort s_addr, uchar *outbuf, int words)
8749 {
8750     int    i;
8751
8752     ASC_DBG_PRT_HEX(2, "DvcPutScsiQ", outbuf, 2 * words);
8753     AscSetChipLramAddr(iop_base, s_addr);
8754     for (i = 0; i < 2 * words; i += 2) {
8755         if (i == 4 || i == 20) {
8756             continue;
8757         }
8758         outpw(iop_base + IOP_RAM_DATA,
8759             ((ushort) outbuf[i + 1] << 8) | outbuf[i]);
8760     }
8761 }
8762
8763 /*
8764  * void
8765  * DvcGetQinfo(PortAddr iop_base, ushort s_addr, uchar *inbuf, int words)
8766  *
8767  * Calling/Exit State:
8768  *    none
8769  *
8770  * Description:
8771  *     Input an ASC_QDONE_INFO structure from the chip
8772  */
8773 STATIC void
8774 DvcGetQinfo(PortAddr iop_base, ushort s_addr, uchar *inbuf, int words)
8775 {
8776     int    i;
8777     ushort word;
8778
8779     AscSetChipLramAddr(iop_base, s_addr);
8780     for (i = 0; i < 2 * words; i += 2) {
8781         if (i == 10) {
8782             continue;
8783         }
8784         word = inpw(iop_base + IOP_RAM_DATA);
8785         inbuf[i] = word & 0xff;
8786         inbuf[i + 1] = (word >> 8) & 0xff;
8787     }
8788     ASC_DBG_PRT_HEX(2, "DvcGetQinfo", inbuf, 2 * words);
8789 }
8790
8791 /*
8792  * Read a PCI configuration byte.
8793  */
8794 STATIC uchar __init
8795 DvcReadPCIConfigByte(
8796         ASC_DVC_VAR *asc_dvc,
8797         ushort offset)
8798 {
8799 #ifdef CONFIG_PCI
8800     uchar byte_data;
8801     pci_read_config_byte(to_pci_dev(asc_dvc->cfg->dev), offset, &byte_data);
8802     return byte_data;
8803 #else /* !defined(CONFIG_PCI) */
8804     return 0;
8805 #endif /* !defined(CONFIG_PCI) */
8806 }
8807
8808 /*
8809  * Write a PCI configuration byte.
8810  */
8811 STATIC void __init
8812 DvcWritePCIConfigByte(
8813         ASC_DVC_VAR *asc_dvc,
8814         ushort offset,
8815         uchar  byte_data)
8816 {
8817 #ifdef CONFIG_PCI
8818     pci_write_config_byte(to_pci_dev(asc_dvc->cfg->dev), offset, byte_data);
8819 #endif /* CONFIG_PCI */
8820 }
8821
8822 /*
8823  * Return the BIOS address of the adapter at the specified
8824  * I/O port and with the specified bus type.
8825  */
8826 STATIC ushort __init
8827 AscGetChipBiosAddress(
8828         PortAddr iop_base,
8829         ushort bus_type)
8830 {
8831     ushort  cfg_lsw;
8832     ushort  bios_addr;
8833
8834     /*
8835      * The PCI BIOS is re-located by the motherboard BIOS. Because
8836      * of this the driver can not determine where a PCI BIOS is
8837      * loaded and executes.
8838      */
8839     if (bus_type & ASC_IS_PCI)
8840     {
8841         return(0);
8842     }
8843
8844 #ifdef CONFIG_ISA
8845     if((bus_type & ASC_IS_EISA) != 0)
8846     {
8847         cfg_lsw = AscGetEisaChipCfg(iop_base);
8848         cfg_lsw &= 0x000F;
8849         bios_addr = (ushort)(ASC_BIOS_MIN_ADDR  +
8850                                 (cfg_lsw * ASC_BIOS_BANK_SIZE));
8851         return(bios_addr);
8852     }/* if */
8853 #endif /* CONFIG_ISA */
8854
8855     cfg_lsw = AscGetChipCfgLsw(iop_base);
8856
8857     /*
8858     *  ISA PnP uses the top bit as the 32K BIOS flag
8859     */
8860     if (bus_type == ASC_IS_ISAPNP)
8861     {
8862         cfg_lsw &= 0x7FFF;
8863     }/* if */
8864
8865     bios_addr = (ushort)(((cfg_lsw >> 12) * ASC_BIOS_BANK_SIZE) +
8866             ASC_BIOS_MIN_ADDR);
8867     return(bios_addr);
8868 }
8869
8870
8871 /*
8872  * --- Functions Required by the Adv Library
8873  */
8874
8875 /*
8876  * DvcGetPhyAddr()
8877  *
8878  * Return the physical address of 'vaddr' and set '*lenp' to the
8879  * number of physically contiguous bytes that follow 'vaddr'.
8880  * 'flag' indicates the type of structure whose physical address
8881  * is being translated.
8882  *
8883  * Note: Because Linux currently doesn't page the kernel and all
8884  * kernel buffers are physically contiguous, leave '*lenp' unchanged.
8885  */
8886 ADV_PADDR
8887 DvcGetPhyAddr(ADV_DVC_VAR *asc_dvc, ADV_SCSI_REQ_Q *scsiq,
8888         uchar *vaddr, ADV_SDCNT *lenp, int flag)
8889 {
8890     ADV_PADDR           paddr;
8891
8892     paddr = virt_to_bus(vaddr);
8893
8894     ASC_DBG4(4,
8895         "DvcGetPhyAddr: vaddr 0x%lx, lenp 0x%lx *lenp %lu, paddr 0x%lx\n",
8896         (ulong) vaddr, (ulong) lenp, (ulong) *((ulong *) lenp), (ulong) paddr);
8897
8898     return paddr;
8899 }
8900
8901 /*
8902  * Read a PCI configuration byte.
8903  */
8904 STATIC uchar __init
8905 DvcAdvReadPCIConfigByte(
8906         ADV_DVC_VAR *asc_dvc,
8907         ushort offset)
8908 {
8909 #ifdef CONFIG_PCI
8910     uchar byte_data;
8911     pci_read_config_byte(to_pci_dev(asc_dvc->cfg->dev), offset, &byte_data);
8912     return byte_data;
8913 #else /* CONFIG_PCI */
8914     return 0;
8915 #endif /* CONFIG_PCI */
8916 }
8917
8918 /*
8919  * Write a PCI configuration byte.
8920  */
8921 STATIC void __init
8922 DvcAdvWritePCIConfigByte(
8923         ADV_DVC_VAR *asc_dvc,
8924         ushort offset,
8925         uchar  byte_data)
8926 {
8927 #ifdef CONFIG_PCI
8928     pci_write_config_byte(to_pci_dev(asc_dvc->cfg->dev), offset, byte_data);
8929 #else /* CONFIG_PCI */
8930     return;
8931 #endif /* CONFIG_PCI */
8932 }
8933
8934 /*
8935  * --- Tracing and Debugging Functions
8936  */
8937
8938 #ifdef ADVANSYS_STATS
8939 #ifdef CONFIG_PROC_FS
8940 /*
8941  * asc_prt_board_stats()
8942  *
8943  * Note: no single line should be greater than ASC_PRTLINE_SIZE,
8944  * cf. asc_prt_line().
8945  *
8946  * Return the number of characters copied into 'cp'. No more than
8947  * 'cplen' characters will be copied to 'cp'.
8948  */
8949 STATIC int
8950 asc_prt_board_stats(struct Scsi_Host *shp, char *cp, int cplen)
8951 {
8952     int                    leftlen;
8953     int                    totlen;
8954     int                    len;
8955     struct asc_stats       *s;
8956     asc_board_t            *boardp;
8957
8958     leftlen = cplen;
8959     totlen = len = 0;
8960
8961     boardp = ASC_BOARDP(shp);
8962     s = &boardp->asc_stats;
8963
8964     len = asc_prt_line(cp, leftlen,
8965 "\nLinux Driver Statistics for AdvanSys SCSI Host %d:\n", shp->host_no);
8966     ASC_PRT_NEXT();
8967
8968     len = asc_prt_line(cp, leftlen,
8969 " queuecommand %lu, reset %lu, biosparam %lu, interrupt %lu\n",
8970         s->queuecommand, s->reset, s->biosparam, s->interrupt);
8971     ASC_PRT_NEXT();
8972
8973     len = asc_prt_line(cp, leftlen,
8974 " callback %lu, done %lu, build_error %lu, build_noreq %lu, build_nosg %lu\n",
8975         s->callback, s->done, s->build_error, s->adv_build_noreq,
8976         s->adv_build_nosg);
8977     ASC_PRT_NEXT();
8978
8979     len = asc_prt_line(cp, leftlen,
8980 " exe_noerror %lu, exe_busy %lu, exe_error %lu, exe_unknown %lu\n",
8981         s->exe_noerror, s->exe_busy, s->exe_error, s->exe_unknown);
8982     ASC_PRT_NEXT();
8983
8984     /*
8985      * Display data transfer statistics.
8986      */
8987     if (s->cont_cnt > 0) {
8988         len = asc_prt_line(cp, leftlen, " cont_cnt %lu, ", s->cont_cnt);
8989         ASC_PRT_NEXT();
8990
8991         len = asc_prt_line(cp, leftlen, "cont_xfer %lu.%01lu kb ",
8992                     s->cont_xfer/2,
8993                     ASC_TENTHS(s->cont_xfer, 2));
8994         ASC_PRT_NEXT();
8995
8996         /* Contiguous transfer average size */
8997         len = asc_prt_line(cp, leftlen, "avg_xfer %lu.%01lu kb\n",
8998                     (s->cont_xfer/2)/s->cont_cnt,
8999                     ASC_TENTHS((s->cont_xfer/2), s->cont_cnt));
9000         ASC_PRT_NEXT();
9001     }
9002
9003     if (s->sg_cnt > 0) {
9004
9005         len = asc_prt_line(cp, leftlen, " sg_cnt %lu, sg_elem %lu, ",
9006                     s->sg_cnt, s->sg_elem);
9007         ASC_PRT_NEXT();
9008
9009         len = asc_prt_line(cp, leftlen, "sg_xfer %lu.%01lu kb\n",
9010                     s->sg_xfer/2,
9011                     ASC_TENTHS(s->sg_xfer, 2));
9012         ASC_PRT_NEXT();
9013
9014         /* Scatter gather transfer statistics */
9015         len = asc_prt_line(cp, leftlen, " avg_num_elem %lu.%01lu, ",
9016                     s->sg_elem/s->sg_cnt,
9017                     ASC_TENTHS(s->sg_elem, s->sg_cnt));
9018         ASC_PRT_NEXT();
9019
9020         len = asc_prt_line(cp, leftlen, "avg_elem_size %lu.%01lu kb, ",
9021                     (s->sg_xfer/2)/s->sg_elem,
9022                     ASC_TENTHS((s->sg_xfer/2), s->sg_elem));
9023         ASC_PRT_NEXT();
9024
9025         len = asc_prt_line(cp, leftlen, "avg_xfer_size %lu.%01lu kb\n",
9026                     (s->sg_xfer/2)/s->sg_cnt,
9027                     ASC_TENTHS((s->sg_xfer/2), s->sg_cnt));
9028         ASC_PRT_NEXT();
9029     }
9030
9031     /*
9032      * Display request queuing statistics.
9033      */
9034     len = asc_prt_line(cp, leftlen,
9035 " Active and Waiting Request Queues (Time Unit: %d HZ):\n", HZ);
9036     ASC_PRT_NEXT();
9037
9038
9039      return totlen;
9040 }
9041
9042 /*
9043  * asc_prt_target_stats()
9044  *
9045  * Note: no single line should be greater than ASC_PRTLINE_SIZE,
9046  * cf. asc_prt_line().
9047  *
9048  * This is separated from asc_prt_board_stats because a full set
9049  * of targets will overflow ASC_PRTBUF_SIZE.
9050  *
9051  * Return the number of characters copied into 'cp'. No more than
9052  * 'cplen' characters will be copied to 'cp'.
9053  */
9054 STATIC int
9055 asc_prt_target_stats(struct Scsi_Host *shp, int tgt_id, char *cp, int cplen)
9056 {
9057     int                    leftlen;
9058     int                    totlen;
9059     int                    len;
9060     struct asc_stats       *s;
9061     ushort                 chip_scsi_id;
9062     asc_board_t            *boardp;
9063     asc_queue_t            *active;
9064     asc_queue_t            *waiting;
9065
9066     leftlen = cplen;
9067     totlen = len = 0;
9068
9069     boardp = ASC_BOARDP(shp);
9070     s = &boardp->asc_stats;
9071
9072     active = &ASC_BOARDP(shp)->active;
9073     waiting = &ASC_BOARDP(shp)->waiting;
9074
9075     if (ASC_NARROW_BOARD(boardp)) {
9076         chip_scsi_id = boardp->dvc_cfg.asc_dvc_cfg.chip_scsi_id;
9077     } else {
9078         chip_scsi_id = boardp->dvc_var.adv_dvc_var.chip_scsi_id;
9079     }
9080
9081     if ((chip_scsi_id == tgt_id) ||
9082         ((boardp->init_tidmask & ADV_TID_TO_TIDMASK(tgt_id)) == 0)) {
9083         return 0;
9084     }
9085
9086     do {
9087         if (active->q_tot_cnt[tgt_id] > 0 || waiting->q_tot_cnt[tgt_id] > 0) {
9088             len = asc_prt_line(cp, leftlen, " target %d\n", tgt_id);
9089             ASC_PRT_NEXT();
9090
9091             len = asc_prt_line(cp, leftlen,
9092 "   active: cnt [cur %d, max %d, tot %u], time [min %d, max %d, avg %lu.%01lu]\n",
9093                 active->q_cur_cnt[tgt_id], active->q_max_cnt[tgt_id],
9094                 active->q_tot_cnt[tgt_id],
9095                 active->q_min_tim[tgt_id], active->q_max_tim[tgt_id],
9096                 (active->q_tot_cnt[tgt_id] == 0) ? 0 :
9097                 (active->q_tot_tim[tgt_id]/active->q_tot_cnt[tgt_id]),
9098                 (active->q_tot_cnt[tgt_id] == 0) ? 0 :
9099                 ASC_TENTHS(active->q_tot_tim[tgt_id],
9100                 active->q_tot_cnt[tgt_id]));
9101              ASC_PRT_NEXT();
9102
9103              len = asc_prt_line(cp, leftlen,
9104 "   waiting: cnt [cur %d, max %d, tot %u], time [min %u, max %u, avg %lu.%01lu]\n",
9105                 waiting->q_cur_cnt[tgt_id], waiting->q_max_cnt[tgt_id],
9106                 waiting->q_tot_cnt[tgt_id],
9107                 waiting->q_min_tim[tgt_id], waiting->q_max_tim[tgt_id],
9108                 (waiting->q_tot_cnt[tgt_id] == 0) ? 0 :
9109                 (waiting->q_tot_tim[tgt_id]/waiting->q_tot_cnt[tgt_id]),
9110                 (waiting->q_tot_cnt[tgt_id] == 0) ? 0 :
9111                 ASC_TENTHS(waiting->q_tot_tim[tgt_id],
9112                 waiting->q_tot_cnt[tgt_id]));
9113              ASC_PRT_NEXT();
9114         }
9115     } while (0);
9116
9117      return totlen;
9118 }
9119 #endif /* CONFIG_PROC_FS */
9120 #endif /* ADVANSYS_STATS */
9121
9122 #ifdef ADVANSYS_DEBUG
9123 /*
9124  * asc_prt_scsi_host()
9125  */
9126 STATIC void
9127 asc_prt_scsi_host(struct Scsi_Host *s)
9128 {
9129     asc_board_t         *boardp;
9130
9131     boardp = ASC_BOARDP(s);
9132
9133     printk("Scsi_Host at addr 0x%lx\n", (ulong) s);
9134     printk(
9135 " host_busy %u, host_no %d, last_reset %d,\n",
9136         s->host_busy, s->host_no,
9137         (unsigned) s->last_reset);
9138
9139     printk(
9140 " base 0x%lx, io_port 0x%lx, n_io_port %u, irq 0x%x,\n",
9141         (ulong) s->base, (ulong) s->io_port, s->n_io_port, s->irq);
9142
9143     printk(
9144 " dma_channel %d, this_id %d, can_queue %d,\n",
9145         s->dma_channel, s->this_id, s->can_queue);
9146
9147     printk(
9148 " cmd_per_lun %d, sg_tablesize %d, unchecked_isa_dma %d\n",
9149         s->cmd_per_lun, s->sg_tablesize, s->unchecked_isa_dma);
9150
9151     if (ASC_NARROW_BOARD(boardp)) {
9152         asc_prt_asc_dvc_var(&ASC_BOARDP(s)->dvc_var.asc_dvc_var);
9153         asc_prt_asc_dvc_cfg(&ASC_BOARDP(s)->dvc_cfg.asc_dvc_cfg);
9154     } else {
9155         asc_prt_adv_dvc_var(&ASC_BOARDP(s)->dvc_var.adv_dvc_var);
9156         asc_prt_adv_dvc_cfg(&ASC_BOARDP(s)->dvc_cfg.adv_dvc_cfg);
9157     }
9158 }
9159
9160 /*
9161  * asc_prt_scsi_cmnd()
9162  */
9163 STATIC void
9164 asc_prt_scsi_cmnd(struct scsi_cmnd *s)
9165 {
9166     printk("struct scsi_cmnd at addr 0x%lx\n", (ulong) s);
9167
9168     printk(
9169 " host 0x%lx, device 0x%lx, target %u, lun %u, channel %u,\n",
9170         (ulong) s->device->host, (ulong) s->device, s->device->id, s->device->lun,
9171         s->device->channel);
9172
9173     asc_prt_hex(" CDB", s->cmnd, s->cmd_len);
9174
9175     printk (
9176 "sc_data_direction %u, resid %d\n",
9177         s->sc_data_direction, s->resid);
9178
9179     printk(
9180 " use_sg %u, sglist_len %u\n",
9181         s->use_sg, s->sglist_len);
9182
9183     printk(
9184 " serial_number 0x%x, retries %d, allowed %d\n",
9185         (unsigned) s->serial_number, s->retries, s->allowed);
9186
9187     printk(
9188 " timeout_per_command %d\n",
9189         s->timeout_per_command);
9190
9191     printk(
9192 " scsi_done 0x%lx, done 0x%lx, host_scribble 0x%lx, result 0x%x\n",
9193         (ulong) s->scsi_done, (ulong) s->done,
9194         (ulong) s->host_scribble, s->result);
9195
9196     printk(
9197 " tag %u, pid %u\n",
9198         (unsigned) s->tag, (unsigned) s->pid);
9199 }
9200
9201 /*
9202  * asc_prt_asc_dvc_var()
9203  */
9204 STATIC void
9205 asc_prt_asc_dvc_var(ASC_DVC_VAR *h)
9206 {
9207     printk("ASC_DVC_VAR at addr 0x%lx\n", (ulong) h);
9208
9209     printk(
9210 " iop_base 0x%x, err_code 0x%x, dvc_cntl 0x%x, bug_fix_cntl %d,\n",
9211         h->iop_base, h->err_code, h->dvc_cntl, h->bug_fix_cntl);
9212
9213     printk(
9214 " bus_type %d, isr_callback 0x%lx, exe_callback 0x%lx, init_sdtr 0x%x,\n",
9215         h->bus_type, (ulong) h->isr_callback, (ulong) h->exe_callback,
9216         (unsigned) h->init_sdtr);
9217
9218     printk(
9219 " sdtr_done 0x%x, use_tagged_qng 0x%x, unit_not_ready 0x%x, chip_no 0x%x,\n",
9220         (unsigned) h->sdtr_done, (unsigned) h->use_tagged_qng,
9221         (unsigned) h->unit_not_ready, (unsigned) h->chip_no);
9222
9223     printk(
9224 " queue_full_or_busy 0x%x, start_motor 0x%x, scsi_reset_wait %u,\n",
9225         (unsigned) h->queue_full_or_busy, (unsigned) h->start_motor,
9226         (unsigned) h->scsi_reset_wait);
9227
9228     printk(
9229 " is_in_int %u, max_total_qng %u, cur_total_qng %u, in_critical_cnt %u,\n",
9230         (unsigned) h->is_in_int, (unsigned) h->max_total_qng,
9231         (unsigned) h->cur_total_qng, (unsigned) h->in_critical_cnt);
9232
9233     printk(
9234 " last_q_shortage %u, init_state 0x%x, no_scam 0x%x, pci_fix_asyn_xfer 0x%x,\n",
9235         (unsigned) h->last_q_shortage, (unsigned) h->init_state,
9236         (unsigned) h->no_scam, (unsigned) h->pci_fix_asyn_xfer);
9237
9238     printk(
9239 " cfg 0x%lx, irq_no 0x%x\n",
9240         (ulong) h->cfg, (unsigned) h->irq_no);
9241 }
9242
9243 /*
9244  * asc_prt_asc_dvc_cfg()
9245  */
9246 STATIC void
9247 asc_prt_asc_dvc_cfg(ASC_DVC_CFG *h)
9248 {
9249     printk("ASC_DVC_CFG at addr 0x%lx\n", (ulong) h);
9250
9251     printk(
9252 " can_tagged_qng 0x%x, cmd_qng_enabled 0x%x,\n",
9253             h->can_tagged_qng, h->cmd_qng_enabled);
9254     printk(
9255 " disc_enable 0x%x, sdtr_enable 0x%x,\n",
9256             h->disc_enable, h->sdtr_enable);
9257
9258     printk(
9259 " chip_scsi_id %d, isa_dma_speed %d, isa_dma_channel %d, chip_version %d,\n",
9260              h->chip_scsi_id, h->isa_dma_speed, h->isa_dma_channel,
9261              h->chip_version);
9262
9263     printk(
9264 " pci_device_id %d, lib_serial_no %u, lib_version %u, mcode_date 0x%x,\n",
9265            to_pci_dev(h->dev)->device, h->lib_serial_no, h->lib_version,
9266            h->mcode_date);
9267
9268     printk(
9269 " mcode_version %d, overrun_buf 0x%lx\n",
9270             h->mcode_version, (ulong) h->overrun_buf);
9271 }
9272
9273 /*
9274  * asc_prt_asc_scsi_q()
9275  */
9276 STATIC void
9277 asc_prt_asc_scsi_q(ASC_SCSI_Q *q)
9278 {
9279     ASC_SG_HEAD    *sgp;
9280     int i;
9281
9282     printk("ASC_SCSI_Q at addr 0x%lx\n", (ulong) q);
9283
9284     printk(
9285 " target_ix 0x%x, target_lun %u, srb_ptr 0x%lx, tag_code 0x%x,\n",
9286             q->q2.target_ix, q->q1.target_lun,
9287             (ulong) q->q2.srb_ptr, q->q2.tag_code);
9288
9289     printk(
9290 " data_addr 0x%lx, data_cnt %lu, sense_addr 0x%lx, sense_len %u,\n",
9291             (ulong) le32_to_cpu(q->q1.data_addr),
9292             (ulong) le32_to_cpu(q->q1.data_cnt),
9293             (ulong) le32_to_cpu(q->q1.sense_addr), q->q1.sense_len);
9294
9295     printk(
9296 " cdbptr 0x%lx, cdb_len %u, sg_head 0x%lx, sg_queue_cnt %u\n",
9297             (ulong) q->cdbptr, q->q2.cdb_len,
9298             (ulong) q->sg_head, q->q1.sg_queue_cnt);
9299
9300     if (q->sg_head) {
9301         sgp = q->sg_head;
9302         printk("ASC_SG_HEAD at addr 0x%lx\n", (ulong) sgp);
9303         printk(" entry_cnt %u, queue_cnt %u\n", sgp->entry_cnt, sgp->queue_cnt);
9304         for (i = 0; i < sgp->entry_cnt; i++) {
9305             printk(" [%u]: addr 0x%lx, bytes %lu\n",
9306                 i, (ulong) le32_to_cpu(sgp->sg_list[i].addr),
9307                 (ulong) le32_to_cpu(sgp->sg_list[i].bytes));
9308         }
9309
9310     }
9311 }
9312
9313 /*
9314  * asc_prt_asc_qdone_info()
9315  */
9316 STATIC void
9317 asc_prt_asc_qdone_info(ASC_QDONE_INFO *q)
9318 {
9319     printk("ASC_QDONE_INFO at addr 0x%lx\n", (ulong) q);
9320     printk(
9321 " srb_ptr 0x%lx, target_ix %u, cdb_len %u, tag_code %u,\n",
9322             (ulong) q->d2.srb_ptr, q->d2.target_ix, q->d2.cdb_len,
9323             q->d2.tag_code);
9324     printk(
9325 " done_stat 0x%x, host_stat 0x%x, scsi_stat 0x%x, scsi_msg 0x%x\n",
9326             q->d3.done_stat, q->d3.host_stat, q->d3.scsi_stat, q->d3.scsi_msg);
9327 }
9328
9329 /*
9330  * asc_prt_adv_dvc_var()
9331  *
9332  * Display an ADV_DVC_VAR structure.
9333  */
9334 STATIC void
9335 asc_prt_adv_dvc_var(ADV_DVC_VAR *h)
9336 {
9337     printk(" ADV_DVC_VAR at addr 0x%lx\n", (ulong) h);
9338
9339     printk(
9340 "  iop_base 0x%lx, err_code 0x%x, ultra_able 0x%x\n",
9341         (ulong) h->iop_base, h->err_code, (unsigned) h->ultra_able);
9342
9343     printk(
9344 "  isr_callback 0x%lx, sdtr_able 0x%x, wdtr_able 0x%x\n",
9345         (ulong) h->isr_callback, (unsigned) h->sdtr_able,
9346         (unsigned) h->wdtr_able);
9347
9348     printk(
9349 "  start_motor 0x%x, scsi_reset_wait 0x%x, irq_no 0x%x,\n",
9350         (unsigned) h->start_motor,
9351         (unsigned) h->scsi_reset_wait, (unsigned) h->irq_no);
9352
9353     printk(
9354 "  max_host_qng %u, max_dvc_qng %u, carr_freelist 0x%lxn\n",
9355         (unsigned) h->max_host_qng, (unsigned) h->max_dvc_qng,
9356         (ulong) h->carr_freelist);
9357
9358     printk(
9359 "  icq_sp 0x%lx, irq_sp 0x%lx\n",
9360         (ulong) h->icq_sp, (ulong) h->irq_sp);
9361
9362     printk(
9363 "  no_scam 0x%x, tagqng_able 0x%x\n",
9364         (unsigned) h->no_scam, (unsigned) h->tagqng_able);
9365
9366     printk(
9367 "  chip_scsi_id 0x%x, cfg 0x%lx\n",
9368         (unsigned) h->chip_scsi_id, (ulong) h->cfg);
9369 }
9370
9371 /*
9372  * asc_prt_adv_dvc_cfg()
9373  *
9374  * Display an ADV_DVC_CFG structure.
9375  */
9376 STATIC void
9377 asc_prt_adv_dvc_cfg(ADV_DVC_CFG *h)
9378 {
9379     printk(" ADV_DVC_CFG at addr 0x%lx\n", (ulong) h);
9380
9381     printk(
9382 "  disc_enable 0x%x, termination 0x%x\n",
9383         h->disc_enable, h->termination);
9384
9385     printk(
9386 "  chip_version 0x%x, mcode_date 0x%x\n",
9387         h->chip_version, h->mcode_date);
9388
9389     printk(
9390 "  mcode_version 0x%x, pci_device_id 0x%x, lib_version %u\n",
9391        h->mcode_version, to_pci_dev(h->dev)->device, h->lib_version);
9392
9393     printk(
9394 "  control_flag 0x%x, pci_slot_info 0x%x\n",
9395        h->control_flag, h->pci_slot_info);
9396 }
9397
9398 /*
9399  * asc_prt_adv_scsi_req_q()
9400  *
9401  * Display an ADV_SCSI_REQ_Q structure.
9402  */
9403 STATIC void
9404 asc_prt_adv_scsi_req_q(ADV_SCSI_REQ_Q *q)
9405 {
9406     int                 sg_blk_cnt;
9407     struct asc_sg_block *sg_ptr;
9408
9409     printk("ADV_SCSI_REQ_Q at addr 0x%lx\n", (ulong) q);
9410
9411     printk(
9412 "  target_id %u, target_lun %u, srb_ptr 0x%lx, a_flag 0x%x\n",
9413             q->target_id, q->target_lun, (ulong) q->srb_ptr, q->a_flag);
9414
9415     printk("  cntl 0x%x, data_addr 0x%lx, vdata_addr 0x%lx\n",
9416             q->cntl, (ulong) le32_to_cpu(q->data_addr), (ulong) q->vdata_addr);
9417
9418     printk(
9419 "  data_cnt %lu, sense_addr 0x%lx, sense_len %u,\n",
9420             (ulong) le32_to_cpu(q->data_cnt),
9421             (ulong) le32_to_cpu(q->sense_addr), q->sense_len);
9422
9423     printk(
9424 "  cdb_len %u, done_status 0x%x, host_status 0x%x, scsi_status 0x%x\n",
9425             q->cdb_len, q->done_status, q->host_status, q->scsi_status);
9426
9427     printk(
9428 "  sg_working_ix 0x%x, target_cmd %u\n",
9429             q->sg_working_ix, q->target_cmd);
9430
9431     printk(
9432 "  scsiq_rptr 0x%lx, sg_real_addr 0x%lx, sg_list_ptr 0x%lx\n",
9433             (ulong) le32_to_cpu(q->scsiq_rptr),
9434             (ulong) le32_to_cpu(q->sg_real_addr), (ulong) q->sg_list_ptr);
9435
9436     /* Display the request's ADV_SG_BLOCK structures. */
9437     if (q->sg_list_ptr != NULL)
9438     {
9439         sg_blk_cnt = 0;
9440         while (1) {
9441             /*
9442              * 'sg_ptr' is a physical address. Convert it to a virtual
9443              * address by indexing 'sg_blk_cnt' into the virtual address
9444              * array 'sg_list_ptr'.
9445              *
9446              * XXX - Assumes all SG physical blocks are virtually contiguous.
9447              */
9448             sg_ptr = &(((ADV_SG_BLOCK *) (q->sg_list_ptr))[sg_blk_cnt]);
9449             asc_prt_adv_sgblock(sg_blk_cnt, sg_ptr);
9450             if (sg_ptr->sg_ptr == 0)
9451             {
9452                 break;
9453             }
9454             sg_blk_cnt++;
9455         }
9456     }
9457 }
9458
9459 /*
9460  * asc_prt_adv_sgblock()
9461  *
9462  * Display an ADV_SG_BLOCK structure.
9463  */
9464 STATIC void
9465 asc_prt_adv_sgblock(int sgblockno, ADV_SG_BLOCK *b)
9466 {
9467     int i;
9468
9469     printk(" ASC_SG_BLOCK at addr 0x%lx (sgblockno %d)\n",
9470         (ulong) b, sgblockno);
9471     printk("  sg_cnt %u, sg_ptr 0x%lx\n",
9472         b->sg_cnt, (ulong) le32_to_cpu(b->sg_ptr));
9473     ASC_ASSERT(b->sg_cnt <= NO_OF_SG_PER_BLOCK);
9474     if (b->sg_ptr != 0)
9475     {
9476         ASC_ASSERT(b->sg_cnt == NO_OF_SG_PER_BLOCK);
9477     }
9478     for (i = 0; i < b->sg_cnt; i++) {
9479         printk("  [%u]: sg_addr 0x%lx, sg_count 0x%lx\n",
9480             i, (ulong) b->sg_list[i].sg_addr, (ulong) b->sg_list[i].sg_count);
9481     }
9482 }
9483
9484 /*
9485  * asc_prt_hex()
9486  *
9487  * Print hexadecimal output in 4 byte groupings 32 bytes
9488  * or 8 double-words per line.
9489  */
9490 STATIC void
9491 asc_prt_hex(char *f, uchar *s, int l)
9492 {
9493     int            i;
9494     int            j;
9495     int            k;
9496     int            m;
9497
9498     printk("%s: (%d bytes)\n", f, l);
9499
9500     for (i = 0; i < l; i += 32) {
9501
9502         /* Display a maximum of 8 double-words per line. */
9503         if ((k = (l - i) / 4) >= 8) {
9504             k = 8;
9505             m = 0;
9506         } else {
9507             m = (l - i) % 4;
9508         }
9509
9510         for (j = 0; j < k; j++) {
9511             printk(" %2.2X%2.2X%2.2X%2.2X",
9512                 (unsigned) s[i+(j*4)], (unsigned) s[i+(j*4)+1],
9513                 (unsigned) s[i+(j*4)+2], (unsigned) s[i+(j*4)+3]);
9514         }
9515
9516         switch (m) {
9517         case 0:
9518         default:
9519             break;
9520         case 1:
9521             printk(" %2.2X",
9522                 (unsigned) s[i+(j*4)]);
9523             break;
9524         case 2:
9525             printk(" %2.2X%2.2X",
9526                 (unsigned) s[i+(j*4)],
9527                 (unsigned) s[i+(j*4)+1]);
9528             break;
9529         case 3:
9530             printk(" %2.2X%2.2X%2.2X",
9531                 (unsigned) s[i+(j*4)+1],
9532                 (unsigned) s[i+(j*4)+2],
9533                 (unsigned) s[i+(j*4)+3]);
9534             break;
9535         }
9536
9537         printk("\n");
9538     }
9539 }
9540 #endif /* ADVANSYS_DEBUG */
9541
9542 /*
9543  * --- Asc Library Functions
9544  */
9545
9546 STATIC ushort __init
9547 AscGetEisaChipCfg(
9548                      PortAddr iop_base)
9549 {
9550     PortAddr            eisa_cfg_iop;
9551
9552     eisa_cfg_iop = (PortAddr) ASC_GET_EISA_SLOT(iop_base) |
9553       (PortAddr) (ASC_EISA_CFG_IOP_MASK);
9554     return (inpw(eisa_cfg_iop));
9555 }
9556
9557 STATIC uchar __init
9558 AscSetChipScsiID(
9559                     PortAddr iop_base,
9560                     uchar new_host_id
9561 )
9562 {
9563     ushort              cfg_lsw;
9564
9565     if (AscGetChipScsiID(iop_base) == new_host_id) {
9566         return (new_host_id);
9567     }
9568     cfg_lsw = AscGetChipCfgLsw(iop_base);
9569     cfg_lsw &= 0xF8FF;
9570     cfg_lsw |= (ushort) ((new_host_id & ASC_MAX_TID) << 8);
9571     AscSetChipCfgLsw(iop_base, cfg_lsw);
9572     return (AscGetChipScsiID(iop_base));
9573 }
9574
9575 STATIC uchar __init
9576 AscGetChipScsiCtrl(
9577                 PortAddr iop_base)
9578 {
9579     uchar               sc;
9580
9581     AscSetBank(iop_base, 1);
9582     sc = inp(iop_base + IOP_REG_SC);
9583     AscSetBank(iop_base, 0);
9584     return (sc);
9585 }
9586
9587 STATIC uchar __init
9588 AscGetChipVersion(
9589                      PortAddr iop_base,
9590                      ushort bus_type
9591 )
9592 {
9593     if ((bus_type & ASC_IS_EISA) != 0) {
9594         PortAddr            eisa_iop;
9595         uchar               revision;
9596         eisa_iop = (PortAddr) ASC_GET_EISA_SLOT(iop_base) |
9597           (PortAddr) ASC_EISA_REV_IOP_MASK;
9598         revision = inp(eisa_iop);
9599         return ((uchar) ((ASC_CHIP_MIN_VER_EISA - 1) + revision));
9600     }
9601     return (AscGetChipVerNo(iop_base));
9602 }
9603
9604 STATIC ushort __init
9605 AscGetChipBusType(
9606                      PortAddr iop_base)
9607 {
9608     ushort              chip_ver;
9609
9610     chip_ver = AscGetChipVerNo(iop_base);
9611     if (
9612            (chip_ver >= ASC_CHIP_MIN_VER_VL)
9613            && (chip_ver <= ASC_CHIP_MAX_VER_VL)
9614 ) {
9615         if (
9616                ((iop_base & 0x0C30) == 0x0C30)
9617                || ((iop_base & 0x0C50) == 0x0C50)
9618 ) {
9619             return (ASC_IS_EISA);
9620         }
9621         return (ASC_IS_VL);
9622     }
9623     if ((chip_ver >= ASC_CHIP_MIN_VER_ISA) &&
9624         (chip_ver <= ASC_CHIP_MAX_VER_ISA)) {
9625         if (chip_ver >= ASC_CHIP_MIN_VER_ISA_PNP) {
9626             return (ASC_IS_ISAPNP);
9627         }
9628         return (ASC_IS_ISA);
9629     } else if ((chip_ver >= ASC_CHIP_MIN_VER_PCI) &&
9630                (chip_ver <= ASC_CHIP_MAX_VER_PCI)) {
9631         return (ASC_IS_PCI);
9632     }
9633     return (0);
9634 }
9635
9636 STATIC ASC_DCNT
9637 AscLoadMicroCode(
9638                     PortAddr iop_base,
9639                     ushort s_addr,
9640                     uchar *mcode_buf,
9641                     ushort mcode_size
9642 )
9643 {
9644     ASC_DCNT            chksum;
9645     ushort              mcode_word_size;
9646     ushort              mcode_chksum;
9647
9648     /* Write the microcode buffer starting at LRAM address 0. */
9649     mcode_word_size = (ushort) (mcode_size >> 1);
9650     AscMemWordSetLram(iop_base, s_addr, 0, mcode_word_size);
9651     AscMemWordCopyPtrToLram(iop_base, s_addr, mcode_buf, mcode_word_size);
9652
9653     chksum = AscMemSumLramWord(iop_base, s_addr, mcode_word_size);
9654     ASC_DBG1(1, "AscLoadMicroCode: chksum 0x%lx\n", (ulong) chksum);
9655     mcode_chksum = (ushort) AscMemSumLramWord(iop_base,
9656           (ushort) ASC_CODE_SEC_BEG,
9657           (ushort) ((mcode_size - s_addr - (ushort) ASC_CODE_SEC_BEG) / 2));
9658     ASC_DBG1(1, "AscLoadMicroCode: mcode_chksum 0x%lx\n",
9659         (ulong) mcode_chksum);
9660     AscWriteLramWord(iop_base, ASCV_MCODE_CHKSUM_W, mcode_chksum);
9661     AscWriteLramWord(iop_base, ASCV_MCODE_SIZE_W, mcode_size);
9662     return (chksum);
9663 }
9664
9665 STATIC int
9666 AscFindSignature(
9667                     PortAddr iop_base
9668 )
9669 {
9670     ushort              sig_word;
9671
9672     ASC_DBG2(1, "AscFindSignature: AscGetChipSignatureByte(0x%x) 0x%x\n",
9673         iop_base, AscGetChipSignatureByte(iop_base));
9674     if (AscGetChipSignatureByte(iop_base) == (uchar) ASC_1000_ID1B) {
9675         ASC_DBG2(1, "AscFindSignature: AscGetChipSignatureWord(0x%x) 0x%x\n",
9676             iop_base, AscGetChipSignatureWord(iop_base));
9677         sig_word = AscGetChipSignatureWord(iop_base);
9678         if ((sig_word == (ushort) ASC_1000_ID0W) ||
9679             (sig_word == (ushort) ASC_1000_ID0W_FIX)) {
9680             return (1);
9681         }
9682     }
9683     return (0);
9684 }
9685
9686 STATIC PortAddr _asc_def_iop_base[ASC_IOADR_TABLE_MAX_IX] __initdata =
9687 {
9688     0x100, ASC_IOADR_1, 0x120, ASC_IOADR_2, 0x140, ASC_IOADR_3, ASC_IOADR_4,
9689     ASC_IOADR_5, ASC_IOADR_6, ASC_IOADR_7, ASC_IOADR_8
9690 };
9691
9692 #ifdef CONFIG_ISA
9693 STATIC uchar _isa_pnp_inited __initdata = 0;
9694
9695 STATIC PortAddr __init
9696 AscSearchIOPortAddr(
9697                        PortAddr iop_beg,
9698                        ushort bus_type)
9699 {
9700     if (bus_type & ASC_IS_VL) {
9701         while ((iop_beg = AscSearchIOPortAddr11(iop_beg)) != 0) {
9702             if (AscGetChipVersion(iop_beg, bus_type) <= ASC_CHIP_MAX_VER_VL) {
9703                 return (iop_beg);
9704             }
9705         }
9706         return (0);
9707     }
9708     if (bus_type & ASC_IS_ISA) {
9709         if (_isa_pnp_inited == 0) {
9710             AscSetISAPNPWaitForKey();
9711             _isa_pnp_inited++;
9712         }
9713         while ((iop_beg = AscSearchIOPortAddr11(iop_beg)) != 0) {
9714             if ((AscGetChipVersion(iop_beg, bus_type) & ASC_CHIP_VER_ISA_BIT) != 0) {
9715                 return (iop_beg);
9716             }
9717         }
9718         return (0);
9719     }
9720     if (bus_type & ASC_IS_EISA) {
9721         if ((iop_beg = AscSearchIOPortAddrEISA(iop_beg)) != 0) {
9722             return (iop_beg);
9723         }
9724         return (0);
9725     }
9726     return (0);
9727 }
9728
9729 STATIC PortAddr __init
9730 AscSearchIOPortAddr11(
9731                          PortAddr s_addr
9732 )
9733 {
9734     int                 i;
9735     PortAddr            iop_base;
9736
9737     for (i = 0; i < ASC_IOADR_TABLE_MAX_IX; i++) {
9738         if (_asc_def_iop_base[i] > s_addr) {
9739             break;
9740         }
9741     }
9742     for (; i < ASC_IOADR_TABLE_MAX_IX; i++) {
9743         iop_base = _asc_def_iop_base[i];
9744         if (check_region(iop_base, ASC_IOADR_GAP) != 0) {
9745             ASC_DBG1(1,
9746                "AscSearchIOPortAddr11: check_region() failed I/O port 0x%x\n",
9747                      iop_base);
9748             continue;
9749         }
9750         ASC_DBG1(1, "AscSearchIOPortAddr11: probing I/O port 0x%x\n", iop_base);
9751         if (AscFindSignature(iop_base)) {
9752             return (iop_base);
9753         }
9754     }
9755     return (0);
9756 }
9757
9758 STATIC void __init
9759 AscSetISAPNPWaitForKey(void)
9760 {
9761     outp(ASC_ISA_PNP_PORT_ADDR, 0x02);
9762     outp(ASC_ISA_PNP_PORT_WRITE, 0x02);
9763     return;
9764 }
9765 #endif /* CONFIG_ISA */
9766
9767 STATIC void __init
9768 AscToggleIRQAct(
9769                    PortAddr iop_base
9770 )
9771 {
9772     AscSetChipStatus(iop_base, CIW_IRQ_ACT);
9773     AscSetChipStatus(iop_base, 0);
9774     return;
9775 }
9776
9777 STATIC uchar __init
9778 AscGetChipIRQ(
9779                  PortAddr iop_base,
9780                  ushort bus_type)
9781 {
9782     ushort              cfg_lsw;
9783     uchar               chip_irq;
9784
9785     if ((bus_type & ASC_IS_EISA) != 0) {
9786         cfg_lsw = AscGetEisaChipCfg(iop_base);
9787         chip_irq = (uchar) (((cfg_lsw >> 8) & 0x07) + 10);
9788         if ((chip_irq == 13) || (chip_irq > 15)) {
9789             return (0);
9790         }
9791         return (chip_irq);
9792     }
9793     if ((bus_type & ASC_IS_VL) != 0) {
9794         cfg_lsw = AscGetChipCfgLsw(iop_base);
9795         chip_irq = (uchar) (((cfg_lsw >> 2) & 0x07));
9796         if ((chip_irq == 0) ||
9797             (chip_irq == 4) ||
9798             (chip_irq == 7)) {
9799             return (0);
9800         }
9801         return ((uchar) (chip_irq + (ASC_MIN_IRQ_NO - 1)));
9802     }
9803     cfg_lsw = AscGetChipCfgLsw(iop_base);
9804     chip_irq = (uchar) (((cfg_lsw >> 2) & 0x03));
9805     if (chip_irq == 3)
9806         chip_irq += (uchar) 2;
9807     return ((uchar) (chip_irq + ASC_MIN_IRQ_NO));
9808 }
9809
9810 STATIC uchar __init
9811 AscSetChipIRQ(
9812                  PortAddr iop_base,
9813                  uchar irq_no,
9814                  ushort bus_type)
9815 {
9816     ushort              cfg_lsw;
9817
9818     if ((bus_type & ASC_IS_VL) != 0) {
9819         if (irq_no != 0) {
9820             if ((irq_no < ASC_MIN_IRQ_NO) || (irq_no > ASC_MAX_IRQ_NO)) {
9821                 irq_no = 0;
9822             } else {
9823                 irq_no -= (uchar) ((ASC_MIN_IRQ_NO - 1));
9824             }
9825         }
9826         cfg_lsw = (ushort) (AscGetChipCfgLsw(iop_base) & 0xFFE3);
9827         cfg_lsw |= (ushort) 0x0010;
9828         AscSetChipCfgLsw(iop_base, cfg_lsw);
9829         AscToggleIRQAct(iop_base);
9830         cfg_lsw = (ushort) (AscGetChipCfgLsw(iop_base) & 0xFFE0);
9831         cfg_lsw |= (ushort) ((irq_no & 0x07) << 2);
9832         AscSetChipCfgLsw(iop_base, cfg_lsw);
9833         AscToggleIRQAct(iop_base);
9834         return (AscGetChipIRQ(iop_base, bus_type));
9835     }
9836     if ((bus_type & (ASC_IS_ISA)) != 0) {
9837         if (irq_no == 15)
9838             irq_no -= (uchar) 2;
9839         irq_no -= (uchar) ASC_MIN_IRQ_NO;
9840         cfg_lsw = (ushort) (AscGetChipCfgLsw(iop_base) & 0xFFF3);
9841         cfg_lsw |= (ushort) ((irq_no & 0x03) << 2);
9842         AscSetChipCfgLsw(iop_base, cfg_lsw);
9843         return (AscGetChipIRQ(iop_base, bus_type));
9844     }
9845     return (0);
9846 }
9847
9848 #ifdef CONFIG_ISA
9849 STATIC void __init
9850 AscEnableIsaDma(
9851                    uchar dma_channel)
9852 {
9853     if (dma_channel < 4) {
9854         outp(0x000B, (ushort) (0xC0 | dma_channel));
9855         outp(0x000A, dma_channel);
9856     } else if (dma_channel < 8) {
9857         outp(0x00D6, (ushort) (0xC0 | (dma_channel - 4)));
9858         outp(0x00D4, (ushort) (dma_channel - 4));
9859     }
9860     return;
9861 }
9862 #endif /* CONFIG_ISA */
9863
9864 STATIC int
9865 AscIsrChipHalted(
9866                     ASC_DVC_VAR *asc_dvc
9867 )
9868 {
9869     EXT_MSG             ext_msg;
9870     EXT_MSG             out_msg;
9871     ushort              halt_q_addr;
9872     int                 sdtr_accept;
9873     ushort              int_halt_code;
9874     ASC_SCSI_BIT_ID_TYPE scsi_busy;
9875     ASC_SCSI_BIT_ID_TYPE target_id;
9876     PortAddr            iop_base;
9877     uchar               tag_code;
9878     uchar               q_status;
9879     uchar               halt_qp;
9880     uchar               sdtr_data;
9881     uchar               target_ix;
9882     uchar               q_cntl, tid_no;
9883     uchar               cur_dvc_qng;
9884     uchar               asyn_sdtr;
9885     uchar               scsi_status;
9886     asc_board_t         *boardp;
9887
9888     ASC_ASSERT(asc_dvc->drv_ptr != NULL);
9889     boardp = asc_dvc->drv_ptr;
9890
9891     iop_base = asc_dvc->iop_base;
9892     int_halt_code = AscReadLramWord(iop_base, ASCV_HALTCODE_W);
9893
9894     halt_qp = AscReadLramByte(iop_base, ASCV_CURCDB_B);
9895     halt_q_addr = ASC_QNO_TO_QADDR(halt_qp);
9896     target_ix = AscReadLramByte(iop_base,
9897                    (ushort) (halt_q_addr + (ushort) ASC_SCSIQ_B_TARGET_IX));
9898     q_cntl = AscReadLramByte(iop_base,
9899                         (ushort) (halt_q_addr + (ushort) ASC_SCSIQ_B_CNTL));
9900     tid_no = ASC_TIX_TO_TID(target_ix);
9901     target_id = (uchar) ASC_TID_TO_TARGET_ID(tid_no);
9902     if (asc_dvc->pci_fix_asyn_xfer & target_id) {
9903         asyn_sdtr = ASYN_SDTR_DATA_FIX_PCI_REV_AB;
9904     } else {
9905         asyn_sdtr = 0;
9906     }
9907     if (int_halt_code == ASC_HALT_DISABLE_ASYN_USE_SYN_FIX) {
9908         if (asc_dvc->pci_fix_asyn_xfer & target_id) {
9909             AscSetChipSDTR(iop_base, 0, tid_no);
9910             boardp->sdtr_data[tid_no] = 0;
9911         }
9912         AscWriteLramWord(iop_base, ASCV_HALTCODE_W, 0);
9913         return (0);
9914     } else if (int_halt_code == ASC_HALT_ENABLE_ASYN_USE_SYN_FIX) {
9915         if (asc_dvc->pci_fix_asyn_xfer & target_id) {
9916             AscSetChipSDTR(iop_base, asyn_sdtr, tid_no);
9917             boardp->sdtr_data[tid_no] = asyn_sdtr;
9918         }
9919         AscWriteLramWord(iop_base, ASCV_HALTCODE_W, 0);
9920         return (0);
9921     } else if (int_halt_code == ASC_HALT_EXTMSG_IN) {
9922
9923         AscMemWordCopyPtrFromLram(iop_base,
9924                                ASCV_MSGIN_BEG,
9925                                (uchar *) &ext_msg,
9926                                sizeof(EXT_MSG) >> 1);
9927
9928         if (ext_msg.msg_type == MS_EXTEND &&
9929             ext_msg.msg_req == MS_SDTR_CODE &&
9930             ext_msg.msg_len == MS_SDTR_LEN) {
9931             sdtr_accept = TRUE;
9932             if ((ext_msg.req_ack_offset > ASC_SYN_MAX_OFFSET)) {
9933
9934                 sdtr_accept = FALSE;
9935                 ext_msg.req_ack_offset = ASC_SYN_MAX_OFFSET;
9936             }
9937             if ((ext_msg.xfer_period <
9938                  asc_dvc->sdtr_period_tbl[asc_dvc->host_init_sdtr_index]) ||
9939                 (ext_msg.xfer_period >
9940                  asc_dvc->sdtr_period_tbl[asc_dvc->max_sdtr_index])) {
9941                 sdtr_accept = FALSE;
9942                 ext_msg.xfer_period =
9943                     asc_dvc->sdtr_period_tbl[asc_dvc->host_init_sdtr_index];
9944             }
9945             if (sdtr_accept) {
9946                 sdtr_data = AscCalSDTRData(asc_dvc, ext_msg.xfer_period,
9947                                            ext_msg.req_ack_offset);
9948                 if ((sdtr_data == 0xFF)) {
9949
9950                     q_cntl |= QC_MSG_OUT;
9951                     asc_dvc->init_sdtr &= ~target_id;
9952                     asc_dvc->sdtr_done &= ~target_id;
9953                     AscSetChipSDTR(iop_base, asyn_sdtr, tid_no);
9954                     boardp->sdtr_data[tid_no] = asyn_sdtr;
9955                 }
9956             }
9957             if (ext_msg.req_ack_offset == 0) {
9958
9959                 q_cntl &= ~QC_MSG_OUT;
9960                 asc_dvc->init_sdtr &= ~target_id;
9961                 asc_dvc->sdtr_done &= ~target_id;
9962                 AscSetChipSDTR(iop_base, asyn_sdtr, tid_no);
9963             } else {
9964                 if (sdtr_accept && (q_cntl & QC_MSG_OUT)) {
9965
9966                     q_cntl &= ~QC_MSG_OUT;
9967                     asc_dvc->sdtr_done |= target_id;
9968                     asc_dvc->init_sdtr |= target_id;
9969                     asc_dvc->pci_fix_asyn_xfer &= ~target_id;
9970                     sdtr_data = AscCalSDTRData(asc_dvc, ext_msg.xfer_period,
9971                                                ext_msg.req_ack_offset);
9972                     AscSetChipSDTR(iop_base, sdtr_data, tid_no);
9973                     boardp->sdtr_data[tid_no] = sdtr_data;
9974                 } else {
9975
9976                     q_cntl |= QC_MSG_OUT;
9977                     AscMsgOutSDTR(asc_dvc,
9978                                   ext_msg.xfer_period,
9979                                   ext_msg.req_ack_offset);
9980                     asc_dvc->pci_fix_asyn_xfer &= ~target_id;
9981                     sdtr_data = AscCalSDTRData(asc_dvc, ext_msg.xfer_period,
9982                                                ext_msg.req_ack_offset);
9983                     AscSetChipSDTR(iop_base, sdtr_data, tid_no);
9984                     boardp->sdtr_data[tid_no] = sdtr_data;
9985                     asc_dvc->sdtr_done |= target_id;
9986                     asc_dvc->init_sdtr |= target_id;
9987                 }
9988             }
9989
9990             AscWriteLramByte(iop_base,
9991                          (ushort) (halt_q_addr + (ushort) ASC_SCSIQ_B_CNTL),
9992                              q_cntl);
9993             AscWriteLramWord(iop_base, ASCV_HALTCODE_W, 0);
9994             return (0);
9995         } else if (ext_msg.msg_type == MS_EXTEND &&
9996                    ext_msg.msg_req == MS_WDTR_CODE &&
9997                    ext_msg.msg_len == MS_WDTR_LEN) {
9998
9999             ext_msg.wdtr_width = 0;
10000             AscMemWordCopyPtrToLram(iop_base,
10001                                  ASCV_MSGOUT_BEG,
10002                                  (uchar *) &ext_msg,
10003                                  sizeof(EXT_MSG) >> 1);
10004             q_cntl |= QC_MSG_OUT;
10005             AscWriteLramByte(iop_base,
10006                          (ushort) (halt_q_addr + (ushort) ASC_SCSIQ_B_CNTL),
10007                              q_cntl);
10008             AscWriteLramWord(iop_base, ASCV_HALTCODE_W, 0);
10009             return (0);
10010         } else {
10011
10012             ext_msg.msg_type = MESSAGE_REJECT;
10013             AscMemWordCopyPtrToLram(iop_base,
10014                                  ASCV_MSGOUT_BEG,
10015                                  (uchar *) &ext_msg,
10016                                  sizeof(EXT_MSG) >> 1);
10017             q_cntl |= QC_MSG_OUT;
10018             AscWriteLramByte(iop_base,
10019                          (ushort) (halt_q_addr + (ushort) ASC_SCSIQ_B_CNTL),
10020                              q_cntl);
10021             AscWriteLramWord(iop_base, ASCV_HALTCODE_W, 0);
10022             return (0);
10023         }
10024     } else if (int_halt_code == ASC_HALT_CHK_CONDITION) {
10025
10026         q_cntl |= QC_REQ_SENSE;
10027
10028         if ((asc_dvc->init_sdtr & target_id) != 0) {
10029
10030             asc_dvc->sdtr_done &= ~target_id;
10031
10032             sdtr_data = AscGetMCodeInitSDTRAtID(iop_base, tid_no);
10033             q_cntl |= QC_MSG_OUT;
10034             AscMsgOutSDTR(asc_dvc,
10035                           asc_dvc->sdtr_period_tbl[(sdtr_data >> 4) &
10036                            (uchar) (asc_dvc->max_sdtr_index - 1)],
10037                           (uchar) (sdtr_data & (uchar) ASC_SYN_MAX_OFFSET));
10038         }
10039
10040         AscWriteLramByte(iop_base,
10041                          (ushort) (halt_q_addr + (ushort) ASC_SCSIQ_B_CNTL),
10042                          q_cntl);
10043
10044         tag_code = AscReadLramByte(iop_base,
10045                     (ushort) (halt_q_addr + (ushort) ASC_SCSIQ_B_TAG_CODE));
10046         tag_code &= 0xDC;
10047         if (
10048                (asc_dvc->pci_fix_asyn_xfer & target_id)
10049                && !(asc_dvc->pci_fix_asyn_xfer_always & target_id)
10050 ) {
10051
10052             tag_code |= (ASC_TAG_FLAG_DISABLE_DISCONNECT
10053                          | ASC_TAG_FLAG_DISABLE_ASYN_USE_SYN_FIX);
10054
10055         }
10056         AscWriteLramByte(iop_base,
10057                      (ushort) (halt_q_addr + (ushort) ASC_SCSIQ_B_TAG_CODE),
10058                          tag_code);
10059
10060         q_status = AscReadLramByte(iop_base,
10061                       (ushort) (halt_q_addr + (ushort) ASC_SCSIQ_B_STATUS));
10062         q_status |= (QS_READY | QS_BUSY);
10063         AscWriteLramByte(iop_base,
10064                        (ushort) (halt_q_addr + (ushort) ASC_SCSIQ_B_STATUS),
10065                          q_status);
10066
10067         scsi_busy = AscReadLramByte(iop_base,
10068                                     (ushort) ASCV_SCSIBUSY_B);
10069         scsi_busy &= ~target_id;
10070         AscWriteLramByte(iop_base, (ushort) ASCV_SCSIBUSY_B, scsi_busy);
10071
10072         AscWriteLramWord(iop_base, ASCV_HALTCODE_W, 0);
10073         return (0);
10074     } else if (int_halt_code == ASC_HALT_SDTR_REJECTED) {
10075
10076         AscMemWordCopyPtrFromLram(iop_base,
10077                                ASCV_MSGOUT_BEG,
10078                                (uchar *) &out_msg,
10079                                sizeof(EXT_MSG) >> 1);
10080
10081         if ((out_msg.msg_type == MS_EXTEND) &&
10082             (out_msg.msg_len == MS_SDTR_LEN) &&
10083             (out_msg.msg_req == MS_SDTR_CODE)) {
10084
10085             asc_dvc->init_sdtr &= ~target_id;
10086             asc_dvc->sdtr_done &= ~target_id;
10087             AscSetChipSDTR(iop_base, asyn_sdtr, tid_no);
10088             boardp->sdtr_data[tid_no] = asyn_sdtr;
10089         }
10090         q_cntl &= ~QC_MSG_OUT;
10091         AscWriteLramByte(iop_base,
10092                          (ushort) (halt_q_addr + (ushort) ASC_SCSIQ_B_CNTL),
10093                          q_cntl);
10094         AscWriteLramWord(iop_base, ASCV_HALTCODE_W, 0);
10095         return (0);
10096     } else if (int_halt_code == ASC_HALT_SS_QUEUE_FULL) {
10097
10098         scsi_status = AscReadLramByte(iop_base,
10099           (ushort) ((ushort) halt_q_addr + (ushort) ASC_SCSIQ_SCSI_STATUS));
10100         cur_dvc_qng = AscReadLramByte(iop_base,
10101                      (ushort) ((ushort) ASC_QADR_BEG + (ushort) target_ix));
10102         if ((cur_dvc_qng > 0) &&
10103             (asc_dvc->cur_dvc_qng[tid_no] > 0)) {
10104
10105             scsi_busy = AscReadLramByte(iop_base,
10106                                         (ushort) ASCV_SCSIBUSY_B);
10107             scsi_busy |= target_id;
10108             AscWriteLramByte(iop_base,
10109                              (ushort) ASCV_SCSIBUSY_B, scsi_busy);
10110             asc_dvc->queue_full_or_busy |= target_id;
10111
10112             if (scsi_status == SAM_STAT_TASK_SET_FULL) {
10113                 if (cur_dvc_qng > ASC_MIN_TAGGED_CMD) {
10114                     cur_dvc_qng -= 1;
10115                     asc_dvc->max_dvc_qng[tid_no] = cur_dvc_qng;
10116
10117                     AscWriteLramByte(iop_base,
10118                           (ushort) ((ushort) ASCV_MAX_DVC_QNG_BEG +
10119                            (ushort) tid_no),
10120                           cur_dvc_qng);
10121
10122                     /*
10123                      * Set the device queue depth to the number of
10124                      * active requests when the QUEUE FULL condition
10125                      * was encountered.
10126                      */
10127                     boardp->queue_full |= target_id;
10128                     boardp->queue_full_cnt[tid_no] = cur_dvc_qng;
10129                 }
10130             }
10131         }
10132         AscWriteLramWord(iop_base, ASCV_HALTCODE_W, 0);
10133         return (0);
10134     }
10135 #if CC_VERY_LONG_SG_LIST
10136     else if (int_halt_code == ASC_HALT_HOST_COPY_SG_LIST_TO_RISC)
10137     {
10138         uchar              q_no;
10139         ushort             q_addr;
10140         uchar              sg_wk_q_no;
10141         uchar              first_sg_wk_q_no;
10142         ASC_SCSI_Q         *scsiq; /* Ptr to driver request. */
10143         ASC_SG_HEAD        *sg_head; /* Ptr to driver SG request. */
10144         ASC_SG_LIST_Q      scsi_sg_q; /* Structure written to queue. */
10145         ushort             sg_list_dwords;
10146         ushort             sg_entry_cnt;
10147         uchar              next_qp;
10148         int                i;
10149
10150         q_no = AscReadLramByte(iop_base, (ushort) ASCV_REQ_SG_LIST_QP);
10151         if (q_no == ASC_QLINK_END)
10152         {
10153             return(0);
10154         }
10155
10156         q_addr = ASC_QNO_TO_QADDR(q_no);
10157
10158         /*
10159          * Convert the request's SRB pointer to a host ASC_SCSI_REQ
10160          * structure pointer using a macro provided by the driver.
10161          * The ASC_SCSI_REQ pointer provides a pointer to the
10162          * host ASC_SG_HEAD structure.
10163          */
10164         /* Read request's SRB pointer. */
10165         scsiq = (ASC_SCSI_Q *)
10166            ASC_SRB2SCSIQ(
10167                ASC_U32_TO_VADDR(AscReadLramDWord(iop_base,
10168                (ushort) (q_addr + ASC_SCSIQ_D_SRBPTR))));
10169
10170         /*
10171          * Get request's first and working SG queue.
10172          */
10173         sg_wk_q_no = AscReadLramByte(iop_base,
10174             (ushort) (q_addr + ASC_SCSIQ_B_SG_WK_QP));
10175
10176         first_sg_wk_q_no = AscReadLramByte(iop_base,
10177             (ushort) (q_addr + ASC_SCSIQ_B_FIRST_SG_WK_QP));
10178
10179         /*
10180          * Reset request's working SG queue back to the
10181          * first SG queue.
10182          */
10183         AscWriteLramByte(iop_base,
10184             (ushort) (q_addr + (ushort) ASC_SCSIQ_B_SG_WK_QP),
10185             first_sg_wk_q_no);
10186
10187         sg_head = scsiq->sg_head;
10188
10189         /*
10190          * Set sg_entry_cnt to the number of SG elements
10191          * that will be completed on this interrupt.
10192          *
10193          * Note: The allocated SG queues contain ASC_MAX_SG_LIST - 1
10194          * SG elements. The data_cnt and data_addr fields which
10195          * add 1 to the SG element capacity are not used when
10196          * restarting SG handling after a halt.
10197          */
10198         if (scsiq->remain_sg_entry_cnt > (ASC_MAX_SG_LIST - 1))
10199         {
10200              sg_entry_cnt = ASC_MAX_SG_LIST - 1;
10201
10202              /*
10203               * Keep track of remaining number of SG elements that will
10204               * need to be handled on the next interrupt.
10205               */
10206              scsiq->remain_sg_entry_cnt -= (ASC_MAX_SG_LIST - 1);
10207         } else
10208         {
10209              sg_entry_cnt = scsiq->remain_sg_entry_cnt;
10210              scsiq->remain_sg_entry_cnt = 0;
10211         }
10212
10213         /*
10214          * Copy SG elements into the list of allocated SG queues.
10215          *
10216          * Last index completed is saved in scsiq->next_sg_index.
10217          */
10218         next_qp = first_sg_wk_q_no;
10219         q_addr = ASC_QNO_TO_QADDR(next_qp);
10220         scsi_sg_q.sg_head_qp = q_no;
10221         scsi_sg_q.cntl = QCSG_SG_XFER_LIST;
10222         for( i = 0; i < sg_head->queue_cnt; i++)
10223         {
10224              scsi_sg_q.seq_no = i + 1;
10225              if (sg_entry_cnt > ASC_SG_LIST_PER_Q)
10226              {
10227                  sg_list_dwords = (uchar) (ASC_SG_LIST_PER_Q * 2);
10228                  sg_entry_cnt -= ASC_SG_LIST_PER_Q;
10229                  /*
10230                   * After very first SG queue RISC FW uses next
10231                   * SG queue first element then checks sg_list_cnt
10232                   * against zero and then decrements, so set
10233                   * sg_list_cnt 1 less than number of SG elements
10234                   * in each SG queue.
10235                   */
10236                  scsi_sg_q.sg_list_cnt = ASC_SG_LIST_PER_Q - 1;
10237                  scsi_sg_q.sg_cur_list_cnt = ASC_SG_LIST_PER_Q - 1;
10238              } else {
10239                  /*
10240                   * This is the last SG queue in the list of
10241                   * allocated SG queues. If there are more
10242                   * SG elements than will fit in the allocated
10243                   * queues, then set the QCSG_SG_XFER_MORE flag.
10244                   */
10245                  if (scsiq->remain_sg_entry_cnt != 0)
10246                  {
10247                      scsi_sg_q.cntl |= QCSG_SG_XFER_MORE;
10248                  } else
10249                  {
10250                      scsi_sg_q.cntl |= QCSG_SG_XFER_END;
10251                  }
10252                  /* equals sg_entry_cnt * 2 */
10253                  sg_list_dwords = sg_entry_cnt << 1;
10254                  scsi_sg_q.sg_list_cnt = sg_entry_cnt - 1;
10255                  scsi_sg_q.sg_cur_list_cnt = sg_entry_cnt - 1;
10256                  sg_entry_cnt = 0;
10257              }
10258
10259              scsi_sg_q.q_no = next_qp;
10260              AscMemWordCopyPtrToLram(iop_base,
10261                           q_addr + ASC_SCSIQ_SGHD_CPY_BEG,
10262                           (uchar *) &scsi_sg_q,
10263                           sizeof(ASC_SG_LIST_Q) >> 1);
10264
10265              AscMemDWordCopyPtrToLram(iop_base,
10266                           q_addr + ASC_SGQ_LIST_BEG,
10267                           (uchar *) &sg_head->sg_list[scsiq->next_sg_index],
10268                           sg_list_dwords);
10269
10270              scsiq->next_sg_index += ASC_SG_LIST_PER_Q;
10271
10272              /*
10273               * If the just completed SG queue contained the
10274               * last SG element, then no more SG queues need
10275               * to be written.
10276               */
10277              if (scsi_sg_q.cntl & QCSG_SG_XFER_END)
10278              {
10279                  break;
10280              }
10281
10282              next_qp = AscReadLramByte( iop_base,
10283                           ( ushort )( q_addr+ASC_SCSIQ_B_FWD ) );
10284              q_addr = ASC_QNO_TO_QADDR( next_qp );
10285         }
10286
10287         /*
10288          * Clear the halt condition so the RISC will be restarted
10289          * after the return.
10290          */
10291         AscWriteLramWord(iop_base, ASCV_HALTCODE_W, 0);
10292         return(0);
10293     }
10294 #endif /* CC_VERY_LONG_SG_LIST */
10295     return (0);
10296 }
10297
10298 STATIC uchar
10299 _AscCopyLramScsiDoneQ(
10300                          PortAddr iop_base,
10301                          ushort q_addr,
10302                          ASC_QDONE_INFO * scsiq,
10303                          ASC_DCNT max_dma_count
10304 )
10305 {
10306     ushort              _val;
10307     uchar               sg_queue_cnt;
10308
10309     DvcGetQinfo(iop_base,
10310                 q_addr + ASC_SCSIQ_DONE_INFO_BEG,
10311                 (uchar *) scsiq,
10312                 (sizeof (ASC_SCSIQ_2) + sizeof (ASC_SCSIQ_3)) / 2);
10313
10314     _val = AscReadLramWord(iop_base,
10315                            (ushort) (q_addr + (ushort) ASC_SCSIQ_B_STATUS));
10316     scsiq->q_status = (uchar) _val;
10317     scsiq->q_no = (uchar) (_val >> 8);
10318     _val = AscReadLramWord(iop_base,
10319                            (ushort) (q_addr + (ushort) ASC_SCSIQ_B_CNTL));
10320     scsiq->cntl = (uchar) _val;
10321     sg_queue_cnt = (uchar) (_val >> 8);
10322     _val = AscReadLramWord(iop_base,
10323                         (ushort) (q_addr + (ushort) ASC_SCSIQ_B_SENSE_LEN));
10324     scsiq->sense_len = (uchar) _val;
10325     scsiq->extra_bytes = (uchar) (_val >> 8);
10326
10327     /*
10328      * Read high word of remain bytes from alternate location.
10329      */
10330     scsiq->remain_bytes = (((ADV_DCNT) AscReadLramWord( iop_base,
10331                       (ushort) (q_addr+ (ushort) ASC_SCSIQ_W_ALT_DC1))) << 16);
10332     /*
10333      * Read low word of remain bytes from original location.
10334      */
10335     scsiq->remain_bytes += AscReadLramWord(iop_base,
10336         (ushort) (q_addr+ (ushort) ASC_SCSIQ_DW_REMAIN_XFER_CNT));
10337
10338     scsiq->remain_bytes &= max_dma_count;
10339     return (sg_queue_cnt);
10340 }
10341
10342 STATIC int
10343 AscIsrQDone(
10344                ASC_DVC_VAR *asc_dvc
10345 )
10346 {
10347     uchar               next_qp;
10348     uchar               n_q_used;
10349     uchar               sg_list_qp;
10350     uchar               sg_queue_cnt;
10351     uchar               q_cnt;
10352     uchar               done_q_tail;
10353     uchar               tid_no;
10354     ASC_SCSI_BIT_ID_TYPE scsi_busy;
10355     ASC_SCSI_BIT_ID_TYPE target_id;
10356     PortAddr            iop_base;
10357     ushort              q_addr;
10358     ushort              sg_q_addr;
10359     uchar               cur_target_qng;
10360     ASC_QDONE_INFO      scsiq_buf;
10361     ASC_QDONE_INFO *scsiq;
10362     int                 false_overrun;
10363     ASC_ISR_CALLBACK    asc_isr_callback;
10364
10365     iop_base = asc_dvc->iop_base;
10366     asc_isr_callback = asc_dvc->isr_callback;
10367     n_q_used = 1;
10368     scsiq = (ASC_QDONE_INFO *) & scsiq_buf;
10369     done_q_tail = (uchar) AscGetVarDoneQTail(iop_base);
10370     q_addr = ASC_QNO_TO_QADDR(done_q_tail);
10371     next_qp = AscReadLramByte(iop_base,
10372                               (ushort) (q_addr + (ushort) ASC_SCSIQ_B_FWD));
10373     if (next_qp != ASC_QLINK_END) {
10374         AscPutVarDoneQTail(iop_base, next_qp);
10375         q_addr = ASC_QNO_TO_QADDR(next_qp);
10376         sg_queue_cnt = _AscCopyLramScsiDoneQ(iop_base, q_addr, scsiq,
10377             asc_dvc->max_dma_count);
10378         AscWriteLramByte(iop_base,
10379                          (ushort) (q_addr + (ushort) ASC_SCSIQ_B_STATUS),
10380              (uchar) (scsiq->q_status & (uchar) ~ (QS_READY | QS_ABORTED)));
10381         tid_no = ASC_TIX_TO_TID(scsiq->d2.target_ix);
10382         target_id = ASC_TIX_TO_TARGET_ID(scsiq->d2.target_ix);
10383         if ((scsiq->cntl & QC_SG_HEAD) != 0) {
10384             sg_q_addr = q_addr;
10385             sg_list_qp = next_qp;
10386             for (q_cnt = 0; q_cnt < sg_queue_cnt; q_cnt++) {
10387                 sg_list_qp = AscReadLramByte(iop_base,
10388                            (ushort) (sg_q_addr + (ushort) ASC_SCSIQ_B_FWD));
10389                 sg_q_addr = ASC_QNO_TO_QADDR(sg_list_qp);
10390                 if (sg_list_qp == ASC_QLINK_END) {
10391                     AscSetLibErrorCode(asc_dvc, ASCQ_ERR_SG_Q_LINKS);
10392                     scsiq->d3.done_stat = QD_WITH_ERROR;
10393                     scsiq->d3.host_stat = QHSTA_D_QDONE_SG_LIST_CORRUPTED;
10394                     goto FATAL_ERR_QDONE;
10395                 }
10396                 AscWriteLramByte(iop_base,
10397                          (ushort) (sg_q_addr + (ushort) ASC_SCSIQ_B_STATUS),
10398                                  QS_FREE);
10399             }
10400             n_q_used = sg_queue_cnt + 1;
10401             AscPutVarDoneQTail(iop_base, sg_list_qp);
10402         }
10403         if (asc_dvc->queue_full_or_busy & target_id) {
10404             cur_target_qng = AscReadLramByte(iop_base,
10405             (ushort) ((ushort) ASC_QADR_BEG + (ushort) scsiq->d2.target_ix));
10406             if (cur_target_qng < asc_dvc->max_dvc_qng[tid_no]) {
10407                 scsi_busy = AscReadLramByte(iop_base,
10408                                             (ushort) ASCV_SCSIBUSY_B);
10409                 scsi_busy &= ~target_id;
10410                 AscWriteLramByte(iop_base,
10411                                  (ushort) ASCV_SCSIBUSY_B, scsi_busy);
10412                 asc_dvc->queue_full_or_busy &= ~target_id;
10413             }
10414         }
10415         if (asc_dvc->cur_total_qng >= n_q_used) {
10416             asc_dvc->cur_total_qng -= n_q_used;
10417             if (asc_dvc->cur_dvc_qng[tid_no] != 0) {
10418                 asc_dvc->cur_dvc_qng[tid_no]--;
10419             }
10420         } else {
10421             AscSetLibErrorCode(asc_dvc, ASCQ_ERR_CUR_QNG);
10422             scsiq->d3.done_stat = QD_WITH_ERROR;
10423             goto FATAL_ERR_QDONE;
10424         }
10425         if ((scsiq->d2.srb_ptr == 0UL) ||
10426             ((scsiq->q_status & QS_ABORTED) != 0)) {
10427             return (0x11);
10428         } else if (scsiq->q_status == QS_DONE) {
10429             false_overrun = FALSE;
10430             if (scsiq->extra_bytes != 0) {
10431                 scsiq->remain_bytes += (ADV_DCNT) scsiq->extra_bytes;
10432             }
10433             if (scsiq->d3.done_stat == QD_WITH_ERROR) {
10434                 if (scsiq->d3.host_stat == QHSTA_M_DATA_OVER_RUN) {
10435                     if ((scsiq->cntl & (QC_DATA_IN | QC_DATA_OUT)) == 0) {
10436                         scsiq->d3.done_stat = QD_NO_ERROR;
10437                         scsiq->d3.host_stat = QHSTA_NO_ERROR;
10438                     } else if (false_overrun) {
10439                         scsiq->d3.done_stat = QD_NO_ERROR;
10440                         scsiq->d3.host_stat = QHSTA_NO_ERROR;
10441                     }
10442                 } else if (scsiq->d3.host_stat ==
10443                            QHSTA_M_HUNG_REQ_SCSI_BUS_RESET) {
10444                     AscStopChip(iop_base);
10445                     AscSetChipControl(iop_base,
10446                         (uchar) (CC_SCSI_RESET | CC_HALT));
10447                     DvcDelayNanoSecond(asc_dvc, 60000);
10448                     AscSetChipControl(iop_base, CC_HALT);
10449                     AscSetChipStatus(iop_base, CIW_CLR_SCSI_RESET_INT);
10450                     AscSetChipStatus(iop_base, 0);
10451                     AscSetChipControl(iop_base, 0);
10452                 }
10453             }
10454             if ((scsiq->cntl & QC_NO_CALLBACK) == 0) {
10455                 (*asc_isr_callback) (asc_dvc, scsiq);
10456             } else {
10457                 if ((AscReadLramByte(iop_base,
10458                           (ushort) (q_addr + (ushort) ASC_SCSIQ_CDB_BEG)) ==
10459                      START_STOP)) {
10460                     asc_dvc->unit_not_ready &= ~target_id;
10461                     if (scsiq->d3.done_stat != QD_NO_ERROR) {
10462                         asc_dvc->start_motor &= ~target_id;
10463                     }
10464                 }
10465             }
10466             return (1);
10467         } else {
10468             AscSetLibErrorCode(asc_dvc, ASCQ_ERR_Q_STATUS);
10469           FATAL_ERR_QDONE:
10470             if ((scsiq->cntl & QC_NO_CALLBACK) == 0) {
10471                 (*asc_isr_callback) (asc_dvc, scsiq);
10472             }
10473             return (0x80);
10474         }
10475     }
10476     return (0);
10477 }
10478
10479 STATIC int
10480 AscISR(
10481           ASC_DVC_VAR *asc_dvc
10482 )
10483 {
10484     ASC_CS_TYPE         chipstat;
10485     PortAddr            iop_base;
10486     ushort              saved_ram_addr;
10487     uchar               ctrl_reg;
10488     uchar               saved_ctrl_reg;
10489     int                 int_pending;
10490     int                 status;
10491     uchar               host_flag;
10492
10493     iop_base = asc_dvc->iop_base;
10494     int_pending = FALSE;
10495
10496     if (AscIsIntPending(iop_base) == 0)
10497     {
10498         return int_pending;
10499     }
10500
10501     if (((asc_dvc->init_state & ASC_INIT_STATE_END_LOAD_MC) == 0)
10502         || (asc_dvc->isr_callback == 0)
10503 ) {
10504         return (ERR);
10505     }
10506     if (asc_dvc->in_critical_cnt != 0) {
10507         AscSetLibErrorCode(asc_dvc, ASCQ_ERR_ISR_ON_CRITICAL);
10508         return (ERR);
10509     }
10510     if (asc_dvc->is_in_int) {
10511         AscSetLibErrorCode(asc_dvc, ASCQ_ERR_ISR_RE_ENTRY);
10512         return (ERR);
10513     }
10514     asc_dvc->is_in_int = TRUE;
10515     ctrl_reg = AscGetChipControl(iop_base);
10516     saved_ctrl_reg = ctrl_reg & (~(CC_SCSI_RESET | CC_CHIP_RESET |
10517                                    CC_SINGLE_STEP | CC_DIAG | CC_TEST));
10518     chipstat = AscGetChipStatus(iop_base);
10519     if (chipstat & CSW_SCSI_RESET_LATCH) {
10520         if (!(asc_dvc->bus_type & (ASC_IS_VL | ASC_IS_EISA))) {
10521             int i = 10;
10522             int_pending = TRUE;
10523             asc_dvc->sdtr_done = 0;
10524             saved_ctrl_reg &= (uchar) (~CC_HALT);
10525             while ((AscGetChipStatus(iop_base) & CSW_SCSI_RESET_ACTIVE) &&
10526                    (i-- > 0))
10527             {
10528                   DvcSleepMilliSecond(100);
10529             }
10530             AscSetChipControl(iop_base, (CC_CHIP_RESET | CC_HALT));
10531             AscSetChipControl(iop_base, CC_HALT);
10532             AscSetChipStatus(iop_base, CIW_CLR_SCSI_RESET_INT);
10533             AscSetChipStatus(iop_base, 0);
10534             chipstat = AscGetChipStatus(iop_base);
10535         }
10536     }
10537     saved_ram_addr = AscGetChipLramAddr(iop_base);
10538     host_flag = AscReadLramByte(iop_base,
10539         ASCV_HOST_FLAG_B) & (uchar) (~ASC_HOST_FLAG_IN_ISR);
10540     AscWriteLramByte(iop_base, ASCV_HOST_FLAG_B,
10541                      (uchar) (host_flag | (uchar) ASC_HOST_FLAG_IN_ISR));
10542     if ((chipstat & CSW_INT_PENDING)
10543         || (int_pending)
10544 ) {
10545         AscAckInterrupt(iop_base);
10546         int_pending = TRUE;
10547         if ((chipstat & CSW_HALTED) &&
10548             (ctrl_reg & CC_SINGLE_STEP)) {
10549             if (AscIsrChipHalted(asc_dvc) == ERR) {
10550                 goto ISR_REPORT_QDONE_FATAL_ERROR;
10551             } else {
10552                 saved_ctrl_reg &= (uchar) (~CC_HALT);
10553             }
10554         } else {
10555           ISR_REPORT_QDONE_FATAL_ERROR:
10556             if ((asc_dvc->dvc_cntl & ASC_CNTL_INT_MULTI_Q) != 0) {
10557                 while (((status = AscIsrQDone(asc_dvc)) & 0x01) != 0) {
10558                 }
10559             } else {
10560                 do {
10561                     if ((status = AscIsrQDone(asc_dvc)) == 1) {
10562                         break;
10563                     }
10564                 } while (status == 0x11);
10565             }
10566             if ((status & 0x80) != 0)
10567                 int_pending = ERR;
10568         }
10569     }
10570     AscWriteLramByte(iop_base, ASCV_HOST_FLAG_B, host_flag);
10571     AscSetChipLramAddr(iop_base, saved_ram_addr);
10572     AscSetChipControl(iop_base, saved_ctrl_reg);
10573     asc_dvc->is_in_int = FALSE;
10574     return (int_pending);
10575 }
10576
10577 /* Microcode buffer is kept after initialization for error recovery. */
10578 STATIC uchar _asc_mcode_buf[] =
10579 {
10580   0x01,  0x03,  0x01,  0x19,  0x0F,  0x00,  0x00,  0x00,  0x00,  0x00,  0x00,  0x00,  0x00,  0x00,  0x00,  0x00,
10581   0x0F,  0x0F,  0x0F,  0x0F,  0x0F,  0x0F,  0x0F,  0x0F,  0x00,  0x00,  0x00,  0x00,  0x00,  0x00,  0x00,  0x00,
10582   0x00,  0x00,  0x00,  0x00,  0x00,  0x00,  0x00,  0x00,  0x00,  0x00,  0x00,  0x00,  0x00,  0x00,  0x00,  0x00,
10583   0x00,  0x00,  0x00,  0x00,  0x00,  0x00,  0x00,  0x00,  0x00,  0x00,  0x00,  0x00,  0x00,  0x00,  0x00,  0x00,
10584   0x00,  0x00,  0x00,  0x00,  0xC3,  0x12,  0x0D,  0x05,  0x01,  0x00,  0x00,  0x00,  0x00,  0xFF,  0x00,  0x00,
10585   0x00,  0x00,  0x00,  0x00,  0xFF,  0x80,  0xFF,  0xFF,  0x01,  0x00,  0x00,  0x00,  0x00,  0x00,  0x00,  0x00,
10586   0x00,  0x00,  0x00,  0x23,  0x00,  0x00,  0x00,  0x00,  0x00,  0x07,  0x00,  0xFF,  0x00,  0x00,  0x00,  0x00,
10587   0xFF,  0xFF,  0xFF,  0x00,  0x00,  0x00,  0x00,  0x00,  0x00,  0x00,  0xE4,  0x88,  0x00,  0x00,  0x00,  0x00,
10588   0x80,  0x73,  0x48,  0x04,  0x36,  0x00,  0x00,  0xA2,  0xC2,  0x00,  0x80,  0x73,  0x03,  0x23,  0x36,  0x40,
10589   0xB6,  0x00,  0x36,  0x00,  0x05,  0xD6,  0x0C,  0xD2,  0x12,  0xDA,  0x00,  0xA2,  0xC2,  0x00,  0x92,  0x80,
10590   0x1E,  0x98,  0x50,  0x00,  0xF5,  0x00,  0x48,  0x98,  0xDF,  0x23,  0x36,  0x60,  0xB6,  0x00,  0x92,  0x80,
10591   0x4F,  0x00,  0xF5,  0x00,  0x48,  0x98,  0xEF,  0x23,  0x36,  0x60,  0xB6,  0x00,  0x92,  0x80,  0x80,  0x62,
10592   0x92,  0x80,  0x00,  0x46,  0x15,  0xEE,  0x13,  0xEA,  0x02,  0x01,  0x09,  0xD8,  0xCD,  0x04,  0x4D,  0x00,
10593   0x00,  0xA3,  0xD6,  0x00,  0xA6,  0x97,  0x7F,  0x23,  0x04,  0x61,  0x84,  0x01,  0xE6,  0x84,  0xD2,  0xC1,
10594   0x80,  0x73,  0xCD,  0x04,  0x4D,  0x00,  0x00,  0xA3,  0xDA,  0x01,  0xA6,  0x97,  0xC6,  0x81,  0xC2,  0x88,
10595   0x80,  0x73,  0x80,  0x77,  0x00,  0x01,  0x01,  0xA1,  0xFE,  0x00,  0x4F,  0x00,  0x84,  0x97,  0x07,  0xA6,
10596   0x08,  0x01,  0x00,  0x33,  0x03,  0x00,  0xC2,  0x88,  0x03,  0x03,  0x01,  0xDE,  0xC2,  0x88,  0xCE,  0x00,
10597   0x69,  0x60,  0xCE,  0x00,  0x02,  0x03,  0x4A,  0x60,  0x00,  0xA2,  0x78,  0x01,  0x80,  0x63,  0x07,  0xA6,
10598   0x24,  0x01,  0x78,  0x81,  0x03,  0x03,  0x80,  0x63,  0xE2,  0x00,  0x07,  0xA6,  0x34,  0x01,  0x00,  0x33,
10599   0x04,  0x00,  0xC2,  0x88,  0x03,  0x07,  0x02,  0x01,  0x04,  0xCA,  0x0D,  0x23,  0x68,  0x98,  0x4D,  0x04,
10600   0x04,  0x85,  0x05,  0xD8,  0x0D,  0x23,  0x68,  0x98,  0xCD,  0x04,  0x15,  0x23,  0xF8,  0x88,  0xFB,  0x23,
10601   0x02,  0x61,  0x82,  0x01,  0x80,  0x63,  0x02,  0x03,  0x06,  0xA3,  0x62,  0x01,  0x00,  0x33,  0x0A,  0x00,
10602   0xC2,  0x88,  0x4E,  0x00,  0x07,  0xA3,  0x6E,  0x01,  0x00,  0x33,  0x0B,  0x00,  0xC2,  0x88,  0xCD,  0x04,
10603   0x36,  0x2D,  0x00,  0x33,  0x1A,  0x00,  0xC2,  0x88,  0x50,  0x04,  0x88,  0x81,  0x06,  0xAB,  0x82,  0x01,
10604   0x88,  0x81,  0x4E,  0x00,  0x07,  0xA3,  0x92,  0x01,  0x50,  0x00,  0x00,  0xA3,  0x3C,  0x01,  0x00,  0x05,
10605   0x7C,  0x81,  0x46,  0x97,  0x02,  0x01,  0x05,  0xC6,  0x04,  0x23,  0xA0,  0x01,  0x15,  0x23,  0xA1,  0x01,
10606   0xBE,  0x81,  0xFD,  0x23,  0x02,  0x61,  0x82,  0x01,  0x0A,  0xDA,  0x4A,  0x00,  0x06,  0x61,  0x00,  0xA0,
10607   0xB4,  0x01,  0x80,  0x63,  0xCD,  0x04,  0x36,  0x2D,  0x00,  0x33,  0x1B,  0x00,  0xC2,  0x88,  0x06,  0x23,
10608   0x68,  0x98,  0xCD,  0x04,  0xE6,  0x84,  0x06,  0x01,  0x00,  0xA2,  0xD4,  0x01,  0x57,  0x60,  0x00,  0xA0,
10609   0xDA,  0x01,  0xE6,  0x84,  0x80,  0x23,  0xA0,  0x01,  0xE6,  0x84,  0x80,  0x73,  0x4B,  0x00,  0x06,  0x61,
10610   0x00,  0xA2,  0x00,  0x02,  0x04,  0x01,  0x0C,  0xDE,  0x02,  0x01,  0x03,  0xCC,  0x4F,  0x00,  0x84,  0x97,
10611   0xFC,  0x81,  0x08,  0x23,  0x02,  0x41,  0x82,  0x01,  0x4F,  0x00,  0x62,  0x97,  0x48,  0x04,  0x84,  0x80,
10612   0xF0,  0x97,  0x00,  0x46,  0x56,  0x00,  0x03,  0xC0,  0x01,  0x23,  0xE8,  0x00,  0x81,  0x73,  0x06,  0x29,
10613   0x03,  0x42,  0x06,  0xE2,  0x03,  0xEE,  0x6B,  0xEB,  0x11,  0x23,  0xF8,  0x88,  0x04,  0x98,  0xF0,  0x80,
10614   0x80,  0x73,  0x80,  0x77,  0x07,  0xA4,  0x2A,  0x02,  0x7C,  0x95,  0x06,  0xA6,  0x34,  0x02,  0x03,  0xA6,
10615   0x4C,  0x04,  0x46,  0x82,  0x04,  0x01,  0x03,  0xD8,  0xB4,  0x98,  0x6A,  0x96,  0x46,  0x82,  0xFE,  0x95,
10616   0x80,  0x67,  0x83,  0x03,  0x80,  0x63,  0xB6,  0x2D,  0x02,  0xA6,  0x6C,  0x02,  0x07,  0xA6,  0x5A,  0x02,
10617   0x06,  0xA6,  0x5E,  0x02,  0x03,  0xA6,  0x62,  0x02,  0xC2,  0x88,  0x7C,  0x95,  0x48,  0x82,  0x60,  0x96,
10618   0x48,  0x82,  0x04,  0x23,  0xA0,  0x01,  0x14,  0x23,  0xA1,  0x01,  0x3C,  0x84,  0x04,  0x01,  0x0C,  0xDC,
10619   0xE0,  0x23,  0x25,  0x61,  0xEF,  0x00,  0x14,  0x01,  0x4F,  0x04,  0xA8,  0x01,  0x6F,  0x00,  0xA5,  0x01,
10620   0x03,  0x23,  0xA4,  0x01,  0x06,  0x23,  0x9C,  0x01,  0x24,  0x2B,  0x1C,  0x01,  0x02,  0xA6,  0xAA,  0x02,
10621   0x07,  0xA6,  0x5A,  0x02,  0x06,  0xA6,  0x5E,  0x02,  0x03,  0xA6,  0x20,  0x04,  0x01,  0xA6,  0xB4,  0x02,
10622   0x00,  0xA6,  0xB4,  0x02,  0x00,  0x33,  0x12,  0x00,  0xC2,  0x88,  0x00,  0x0E,  0x80,  0x63,  0x00,  0x43,
10623   0x00,  0xA0,  0x8C,  0x02,  0x4D,  0x04,  0x04,  0x01,  0x0B,  0xDC,  0xE7,  0x23,  0x04,  0x61,  0x84,  0x01,
10624   0x10,  0x31,  0x12,  0x35,  0x14,  0x01,  0xEC,  0x00,  0x6C,  0x38,  0x00,  0x3F,  0x00,  0x00,  0xEA,  0x82,
10625   0x18,  0x23,  0x04,  0x61,  0x18,  0xA0,  0xE2,  0x02,  0x04,  0x01,  0xA2,  0xC8,  0x00,  0x33,  0x1F,  0x00,
10626   0xC2,  0x88,  0x08,  0x31,  0x0A,  0x35,  0x0C,  0x39,  0x0E,  0x3D,  0x7E,  0x98,  0xB6,  0x2D,  0x01,  0xA6,
10627   0x14,  0x03,  0x00,  0xA6,  0x14,  0x03,  0x07,  0xA6,  0x0C,  0x03,  0x06,  0xA6,  0x10,  0x03,  0x03,  0xA6,
10628   0x20,  0x04,  0x02,  0xA6,  0x6C,  0x02,  0x00,  0x33,  0x33,  0x00,  0xC2,  0x88,  0x7C,  0x95,  0xEE,  0x82,
10629   0x60,  0x96,  0xEE,  0x82,  0x82,  0x98,  0x80,  0x42,  0x7E,  0x98,  0x64,  0xE4,  0x04,  0x01,  0x2D,  0xC8,
10630   0x31,  0x05,  0x07,  0x01,  0x00,  0xA2,  0x54,  0x03,  0x00,  0x43,  0x87,  0x01,  0x05,  0x05,  0x86,  0x98,
10631   0x7E,  0x98,  0x00,  0xA6,  0x16,  0x03,  0x07,  0xA6,  0x4C,  0x03,  0x03,  0xA6,  0x3C,  0x04,  0x06,  0xA6,
10632   0x50,  0x03,  0x01,  0xA6,  0x16,  0x03,  0x00,  0x33,  0x25,  0x00,  0xC2,  0x88,  0x7C,  0x95,  0x32,  0x83,
10633   0x60,  0x96,  0x32,  0x83,  0x04,  0x01,  0x10,  0xCE,  0x07,  0xC8,  0x05,  0x05,  0xEB,  0x04,  0x00,  0x33,
10634   0x00,  0x20,  0xC0,  0x20,  0x81,  0x62,  0x72,  0x83,  0x00,  0x01,  0x05,  0x05,  0xFF,  0xA2,  0x7A,  0x03,
10635   0xB1,  0x01,  0x08,  0x23,  0xB2,  0x01,  0x2E,  0x83,  0x05,  0x05,  0x15,  0x01,  0x00,  0xA2,  0x9A,  0x03,
10636   0xEC,  0x00,  0x6E,  0x00,  0x95,  0x01,  0x6C,  0x38,  0x00,  0x3F,  0x00,  0x00,  0x01,  0xA6,  0x96,  0x03,
10637   0x00,  0xA6,  0x96,  0x03,  0x10,  0x84,  0x80,  0x42,  0x7E,  0x98,  0x01,  0xA6,  0xA4,  0x03,  0x00,  0xA6,
10638   0xBC,  0x03,  0x10,  0x84,  0xA8,  0x98,  0x80,  0x42,  0x01,  0xA6,  0xA4,  0x03,  0x07,  0xA6,  0xB2,  0x03,
10639   0xD4,  0x83,  0x7C,  0x95,  0xA8,  0x83,  0x00,  0x33,  0x2F,  0x00,  0xC2,  0x88,  0xA8,  0x98,  0x80,  0x42,
10640   0x00,  0xA6,  0xBC,  0x03,  0x07,  0xA6,  0xCA,  0x03,  0xD4,  0x83,  0x7C,  0x95,  0xC0,  0x83,  0x00,  0x33,
10641   0x26,  0x00,  0xC2,  0x88,  0x38,  0x2B,  0x80,  0x32,  0x80,  0x36,  0x04,  0x23,  0xA0,  0x01,  0x12,  0x23,
10642   0xA1,  0x01,  0x10,  0x84,  0x07,  0xF0,  0x06,  0xA4,  0xF4,  0x03,  0x80,  0x6B,  0x80,  0x67,  0x05,  0x23,
10643   0x83,  0x03,  0x80,  0x63,  0x03,  0xA6,  0x0E,  0x04,  0x07,  0xA6,  0x06,  0x04,  0x06,  0xA6,  0x0A,  0x04,
10644   0x00,  0x33,  0x17,  0x00,  0xC2,  0x88,  0x7C,  0x95,  0xF4,  0x83,  0x60,  0x96,  0xF4,  0x83,  0x20,  0x84,
10645   0x07,  0xF0,  0x06,  0xA4,  0x20,  0x04,  0x80,  0x6B,  0x80,  0x67,  0x05,  0x23,  0x83,  0x03,  0x80,  0x63,
10646   0xB6,  0x2D,  0x03,  0xA6,  0x3C,  0x04,  0x07,  0xA6,  0x34,  0x04,  0x06,  0xA6,  0x38,  0x04,  0x00,  0x33,
10647   0x30,  0x00,  0xC2,  0x88,  0x7C,  0x95,  0x20,  0x84,  0x60,  0x96,  0x20,  0x84,  0x1D,  0x01,  0x06,  0xCC,
10648   0x00,  0x33,  0x00,  0x84,  0xC0,  0x20,  0x00,  0x23,  0xEA,  0x00,  0x81,  0x62,  0xA2,  0x0D,  0x80,  0x63,
10649   0x07,  0xA6,  0x5A,  0x04,  0x00,  0x33,  0x18,  0x00,  0xC2,  0x88,  0x03,  0x03,  0x80,  0x63,  0xA3,  0x01,
10650   0x07,  0xA4,  0x64,  0x04,  0x23,  0x01,  0x00,  0xA2,  0x86,  0x04,  0x0A,  0xA0,  0x76,  0x04,  0xE0,  0x00,
10651   0x00,  0x33,  0x1D,  0x00,  0xC2,  0x88,  0x0B,  0xA0,  0x82,  0x04,  0xE0,  0x00,  0x00,  0x33,  0x1E,  0x00,
10652   0xC2,  0x88,  0x42,  0x23,  0xF8,  0x88,  0x00,  0x23,  0x22,  0xA3,  0xE6,  0x04,  0x08,  0x23,  0x22,  0xA3,
10653   0xA2,  0x04,  0x28,  0x23,  0x22,  0xA3,  0xAE,  0x04,  0x02,  0x23,  0x22,  0xA3,  0xC4,  0x04,  0x42,  0x23,
10654   0xF8,  0x88,  0x4A,  0x00,  0x06,  0x61,  0x00,  0xA0,  0xAE,  0x04,  0x45,  0x23,  0xF8,  0x88,  0x04,  0x98,
10655   0x00,  0xA2,  0xC0,  0x04,  0xB4,  0x98,  0x00,  0x33,  0x00,  0x82,  0xC0,  0x20,  0x81,  0x62,  0xE8,  0x81,
10656   0x47,  0x23,  0xF8,  0x88,  0x04,  0x01,  0x0B,  0xDE,  0x04,  0x98,  0xB4,  0x98,  0x00,  0x33,  0x00,  0x81,
10657   0xC0,  0x20,  0x81,  0x62,  0x14,  0x01,  0x00,  0xA0,  0x00,  0x02,  0x43,  0x23,  0xF8,  0x88,  0x04,  0x23,
10658   0xA0,  0x01,  0x44,  0x23,  0xA1,  0x01,  0x80,  0x73,  0x4D,  0x00,  0x03,  0xA3,  0xF4,  0x04,  0x00,  0x33,
10659   0x27,  0x00,  0xC2,  0x88,  0x04,  0x01,  0x04,  0xDC,  0x02,  0x23,  0xA2,  0x01,  0x04,  0x23,  0xA0,  0x01,
10660   0x04,  0x98,  0x26,  0x95,  0x4B,  0x00,  0xF6,  0x00,  0x4F,  0x04,  0x4F,  0x00,  0x00,  0xA3,  0x22,  0x05,
10661   0x00,  0x05,  0x76,  0x00,  0x06,  0x61,  0x00,  0xA2,  0x1C,  0x05,  0x0A,  0x85,  0x46,  0x97,  0xCD,  0x04,
10662   0x24,  0x85,  0x48,  0x04,  0x84,  0x80,  0x02,  0x01,  0x03,  0xDA,  0x80,  0x23,  0x82,  0x01,  0x34,  0x85,
10663   0x02,  0x23,  0xA0,  0x01,  0x4A,  0x00,  0x06,  0x61,  0x00,  0xA2,  0x40,  0x05,  0x1D,  0x01,  0x04,  0xD6,
10664   0xFF,  0x23,  0x86,  0x41,  0x4B,  0x60,  0xCB,  0x00,  0xFF,  0x23,  0x80,  0x01,  0x49,  0x00,  0x81,  0x01,
10665   0x04,  0x01,  0x02,  0xC8,  0x30,  0x01,  0x80,  0x01,  0xF7,  0x04,  0x03,  0x01,  0x49,  0x04,  0x80,  0x01,
10666   0xC9,  0x00,  0x00,  0x05,  0x00,  0x01,  0xFF,  0xA0,  0x60,  0x05,  0x77,  0x04,  0x01,  0x23,  0xEA,  0x00,
10667   0x5D,  0x00,  0xFE,  0xC7,  0x00,  0x62,  0x00,  0x23,  0xEA,  0x00,  0x00,  0x63,  0x07,  0xA4,  0xF8,  0x05,
10668   0x03,  0x03,  0x02,  0xA0,  0x8E,  0x05,  0xF4,  0x85,  0x00,  0x33,  0x2D,  0x00,  0xC2,  0x88,  0x04,  0xA0,
10669   0xB8,  0x05,  0x80,  0x63,  0x00,  0x23,  0xDF,  0x00,  0x4A,  0x00,  0x06,  0x61,  0x00,  0xA2,  0xA4,  0x05,
10670   0x1D,  0x01,  0x06,  0xD6,  0x02,  0x23,  0x02,  0x41,  0x82,  0x01,  0x50,  0x00,  0x62,  0x97,  0x04,  0x85,
10671   0x04,  0x23,  0x02,  0x41,  0x82,  0x01,  0x04,  0x85,  0x08,  0xA0,  0xBE,  0x05,  0xF4,  0x85,  0x03,  0xA0,
10672   0xC4,  0x05,  0xF4,  0x85,  0x01,  0xA0,  0xCE,  0x05,  0x88,  0x00,  0x80,  0x63,  0xCC,  0x86,  0x07,  0xA0,
10673   0xEE,  0x05,  0x5F,  0x00,  0x00,  0x2B,  0xDF,  0x08,  0x00,  0xA2,  0xE6,  0x05,  0x80,  0x67,  0x80,  0x63,
10674   0x01,  0xA2,  0x7A,  0x06,  0x7C,  0x85,  0x06,  0x23,  0x68,  0x98,  0x48,  0x23,  0xF8,  0x88,  0x07,  0x23,
10675   0x80,  0x00,  0x06,  0x87,  0x80,  0x63,  0x7C,  0x85,  0x00,  0x23,  0xDF,  0x00,  0x00,  0x63,  0x4A,  0x00,
10676   0x06,  0x61,  0x00,  0xA2,  0x36,  0x06,  0x1D,  0x01,  0x16,  0xD4,  0xC0,  0x23,  0x07,  0x41,  0x83,  0x03,
10677   0x80,  0x63,  0x06,  0xA6,  0x1C,  0x06,  0x00,  0x33,  0x37,  0x00,  0xC2,  0x88,  0x1D,  0x01,  0x01,  0xD6,
10678   0x20,  0x23,  0x63,  0x60,  0x83,  0x03,  0x80,  0x63,  0x02,  0x23,  0xDF,  0x00,  0x07,  0xA6,  0x7C,  0x05,
10679   0xEF,  0x04,  0x6F,  0x00,  0x00,  0x63,  0x4B,  0x00,  0x06,  0x41,  0xCB,  0x00,  0x52,  0x00,  0x06,  0x61,
10680   0x00,  0xA2,  0x4E,  0x06,  0x1D,  0x01,  0x03,  0xCA,  0xC0,  0x23,  0x07,  0x41,  0x00,  0x63,  0x1D,  0x01,
10681   0x04,  0xCC,  0x00,  0x33,  0x00,  0x83,  0xC0,  0x20,  0x81,  0x62,  0x80,  0x23,  0x07,  0x41,  0x00,  0x63,
10682   0x80,  0x67,  0x08,  0x23,  0x83,  0x03,  0x80,  0x63,  0x00,  0x63,  0x01,  0x23,  0xDF,  0x00,  0x06,  0xA6,
10683   0x84,  0x06,  0x07,  0xA6,  0x7C,  0x05,  0x80,  0x67,  0x80,  0x63,  0x00,  0x33,  0x00,  0x40,  0xC0,  0x20,
10684   0x81,  0x62,  0x00,  0x63,  0x00,  0x00,  0xFE,  0x95,  0x83,  0x03,  0x80,  0x63,  0x06,  0xA6,  0x94,  0x06,
10685   0x07,  0xA6,  0x7C,  0x05,  0x00,  0x00,  0x01,  0xA0,  0x14,  0x07,  0x00,  0x2B,  0x40,  0x0E,  0x80,  0x63,
10686   0x01,  0x00,  0x06,  0xA6,  0xAA,  0x06,  0x07,  0xA6,  0x7C,  0x05,  0x40,  0x0E,  0x80,  0x63,  0x00,  0x43,
10687   0x00,  0xA0,  0xA2,  0x06,  0x06,  0xA6,  0xBC,  0x06,  0x07,  0xA6,  0x7C,  0x05,  0x80,  0x67,  0x40,  0x0E,
10688   0x80,  0x63,  0x07,  0xA6,  0x7C,  0x05,  0x00,  0x23,  0xDF,  0x00,  0x00,  0x63,  0x07,  0xA6,  0xD6,  0x06,
10689   0x00,  0x33,  0x2A,  0x00,  0xC2,  0x88,  0x03,  0x03,  0x80,  0x63,  0x89,  0x00,  0x0A,  0x2B,  0x07,  0xA6,
10690   0xE8,  0x06,  0x00,  0x33,  0x29,  0x00,  0xC2,  0x88,  0x00,  0x43,  0x00,  0xA2,  0xF4,  0x06,  0xC0,  0x0E,
10691   0x80,  0x63,  0xDE,  0x86,  0xC0,  0x0E,  0x00,  0x33,  0x00,  0x80,  0xC0,  0x20,  0x81,  0x62,  0x04,  0x01,
10692   0x02,  0xDA,  0x80,  0x63,  0x7C,  0x85,  0x80,  0x7B,  0x80,  0x63,  0x06,  0xA6,  0x8C,  0x06,  0x00,  0x33,
10693   0x2C,  0x00,  0xC2,  0x88,  0x0C,  0xA2,  0x2E,  0x07,  0xFE,  0x95,  0x83,  0x03,  0x80,  0x63,  0x06,  0xA6,
10694   0x2C,  0x07,  0x07,  0xA6,  0x7C,  0x05,  0x00,  0x33,  0x3D,  0x00,  0xC2,  0x88,  0x00,  0x00,  0x80,  0x67,
10695   0x83,  0x03,  0x80,  0x63,  0x0C,  0xA0,  0x44,  0x07,  0x07,  0xA6,  0x7C,  0x05,  0xBF,  0x23,  0x04,  0x61,
10696   0x84,  0x01,  0xE6,  0x84,  0x00,  0x63,  0xF0,  0x04,  0x01,  0x01,  0xF1,  0x00,  0x00,  0x01,  0xF2,  0x00,
10697   0x01,  0x05,  0x80,  0x01,  0x72,  0x04,  0x71,  0x00,  0x81,  0x01,  0x70,  0x04,  0x80,  0x05,  0x81,  0x05,
10698   0x00,  0x63,  0xF0,  0x04,  0xF2,  0x00,  0x72,  0x04,  0x01,  0x01,  0xF1,  0x00,  0x70,  0x00,  0x81,  0x01,
10699   0x70,  0x04,  0x71,  0x00,  0x81,  0x01,  0x72,  0x00,  0x80,  0x01,  0x71,  0x04,  0x70,  0x00,  0x80,  0x01,
10700   0x70,  0x04,  0x00,  0x63,  0xF0,  0x04,  0xF2,  0x00,  0x72,  0x04,  0x00,  0x01,  0xF1,  0x00,  0x70,  0x00,
10701   0x80,  0x01,  0x70,  0x04,  0x71,  0x00,  0x80,  0x01,  0x72,  0x00,  0x81,  0x01,  0x71,  0x04,  0x70,  0x00,
10702   0x81,  0x01,  0x70,  0x04,  0x00,  0x63,  0x00,  0x23,  0xB3,  0x01,  0x83,  0x05,  0xA3,  0x01,  0xA2,  0x01,
10703   0xA1,  0x01,  0x01,  0x23,  0xA0,  0x01,  0x00,  0x01,  0xC8,  0x00,  0x03,  0xA1,  0xC4,  0x07,  0x00,  0x33,
10704   0x07,  0x00,  0xC2,  0x88,  0x80,  0x05,  0x81,  0x05,  0x04,  0x01,  0x11,  0xC8,  0x48,  0x00,  0xB0,  0x01,
10705   0xB1,  0x01,  0x08,  0x23,  0xB2,  0x01,  0x05,  0x01,  0x48,  0x04,  0x00,  0x43,  0x00,  0xA2,  0xE4,  0x07,
10706   0x00,  0x05,  0xDA,  0x87,  0x00,  0x01,  0xC8,  0x00,  0xFF,  0x23,  0x80,  0x01,  0x05,  0x05,  0x00,  0x63,
10707   0xF7,  0x04,  0x1A,  0x09,  0xF6,  0x08,  0x6E,  0x04,  0x00,  0x02,  0x80,  0x43,  0x76,  0x08,  0x80,  0x02,
10708   0x77,  0x04,  0x00,  0x63,  0xF7,  0x04,  0x1A,  0x09,  0xF6,  0x08,  0x6E,  0x04,  0x00,  0x02,  0x00,  0xA0,
10709   0x14,  0x08,  0x16,  0x88,  0x00,  0x43,  0x76,  0x08,  0x80,  0x02,  0x77,  0x04,  0x00,  0x63,  0xF3,  0x04,
10710   0x00,  0x23,  0xF4,  0x00,  0x74,  0x00,  0x80,  0x43,  0xF4,  0x00,  0xCF,  0x40,  0x00,  0xA2,  0x44,  0x08,
10711   0x74,  0x04,  0x02,  0x01,  0xF7,  0xC9,  0xF6,  0xD9,  0x00,  0x01,  0x01,  0xA1,  0x24,  0x08,  0x04,  0x98,
10712   0x26,  0x95,  0x24,  0x88,  0x73,  0x04,  0x00,  0x63,  0xF3,  0x04,  0x75,  0x04,  0x5A,  0x88,  0x02,  0x01,
10713   0x04,  0xD8,  0x46,  0x97,  0x04,  0x98,  0x26,  0x95,  0x4A,  0x88,  0x75,  0x00,  0x00,  0xA3,  0x64,  0x08,
10714   0x00,  0x05,  0x4E,  0x88,  0x73,  0x04,  0x00,  0x63,  0x80,  0x7B,  0x80,  0x63,  0x06,  0xA6,  0x76,  0x08,
10715   0x00,  0x33,  0x3E,  0x00,  0xC2,  0x88,  0x80,  0x67,  0x83,  0x03,  0x80,  0x63,  0x00,  0x63,  0x38,  0x2B,
10716   0x9C,  0x88,  0x38,  0x2B,  0x92,  0x88,  0x32,  0x09,  0x31,  0x05,  0x92,  0x98,  0x05,  0x05,  0xB2,  0x09,
10717   0x00,  0x63,  0x00,  0x32,  0x00,  0x36,  0x00,  0x3A,  0x00,  0x3E,  0x00,  0x63,  0x80,  0x32,  0x80,  0x36,
10718   0x80,  0x3A,  0x80,  0x3E,  0xB4,  0x3D,  0x00,  0x63,  0x38,  0x2B,  0x40,  0x32,  0x40,  0x36,  0x40,  0x3A,
10719   0x40,  0x3E,  0x00,  0x63,  0x5A,  0x20,  0xC9,  0x40,  0x00,  0xA0,  0xB4,  0x08,  0x5D,  0x00,  0xFE,  0xC3,
10720   0x00,  0x63,  0x80,  0x73,  0xE6,  0x20,  0x02,  0x23,  0xE8,  0x00,  0x82,  0x73,  0xFF,  0xFD,  0x80,  0x73,
10721   0x13,  0x23,  0xF8,  0x88,  0x66,  0x20,  0xC0,  0x20,  0x04,  0x23,  0xA0,  0x01,  0xA1,  0x23,  0xA1,  0x01,
10722   0x81,  0x62,  0xE2,  0x88,  0x80,  0x73,  0x80,  0x77,  0x68,  0x00,  0x00,  0xA2,  0x80,  0x00,  0x03,  0xC2,
10723   0xF1,  0xC7,  0x41,  0x23,  0xF8,  0x88,  0x11,  0x23,  0xA1,  0x01,  0x04,  0x23,  0xA0,  0x01,  0xE6,  0x84,
10724 };
10725
10726 STATIC ushort _asc_mcode_size = sizeof(_asc_mcode_buf);
10727 STATIC ADV_DCNT _asc_mcode_chksum = 0x012C453FUL;
10728
10729 #define ASC_SYN_OFFSET_ONE_DISABLE_LIST  16
10730 STATIC uchar _syn_offset_one_disable_cmd[ASC_SYN_OFFSET_ONE_DISABLE_LIST] =
10731 {
10732     INQUIRY,
10733     REQUEST_SENSE,
10734     READ_CAPACITY,
10735     READ_TOC,
10736     MODE_SELECT,
10737     MODE_SENSE,
10738     MODE_SELECT_10,
10739     MODE_SENSE_10,
10740     0xFF,
10741     0xFF,
10742     0xFF,
10743     0xFF,
10744     0xFF,
10745     0xFF,
10746     0xFF,
10747     0xFF
10748 };
10749
10750 STATIC int
10751 AscExeScsiQueue(
10752                    ASC_DVC_VAR *asc_dvc,
10753                    ASC_SCSI_Q *scsiq
10754 )
10755 {
10756     PortAddr            iop_base;
10757     ulong               last_int_level;
10758     int                 sta;
10759     int                 n_q_required;
10760     int                 disable_syn_offset_one_fix;
10761     int                 i;
10762     ASC_PADDR           addr;
10763     ASC_EXE_CALLBACK    asc_exe_callback;
10764     ushort              sg_entry_cnt = 0;
10765     ushort              sg_entry_cnt_minus_one = 0;
10766     uchar               target_ix;
10767     uchar               tid_no;
10768     uchar               sdtr_data;
10769     uchar               extra_bytes;
10770     uchar               scsi_cmd;
10771     uchar               disable_cmd;
10772     ASC_SG_HEAD         *sg_head;
10773     ASC_DCNT            data_cnt;
10774
10775     iop_base = asc_dvc->iop_base;
10776     sg_head = scsiq->sg_head;
10777     asc_exe_callback = asc_dvc->exe_callback;
10778     if (asc_dvc->err_code != 0)
10779         return (ERR);
10780     if (scsiq == (ASC_SCSI_Q *) 0L) {
10781         AscSetLibErrorCode(asc_dvc, ASCQ_ERR_SCSIQ_NULL_PTR);
10782         return (ERR);
10783     }
10784     scsiq->q1.q_no = 0;
10785     if ((scsiq->q2.tag_code & ASC_TAG_FLAG_EXTRA_BYTES) == 0) {
10786         scsiq->q1.extra_bytes = 0;
10787     }
10788     sta = 0;
10789     target_ix = scsiq->q2.target_ix;
10790     tid_no = ASC_TIX_TO_TID(target_ix);
10791     n_q_required = 1;
10792     if (scsiq->cdbptr[0] == REQUEST_SENSE) {
10793         if ((asc_dvc->init_sdtr & scsiq->q1.target_id) != 0) {
10794             asc_dvc->sdtr_done &= ~scsiq->q1.target_id;
10795             sdtr_data = AscGetMCodeInitSDTRAtID(iop_base, tid_no);
10796             AscMsgOutSDTR(asc_dvc,
10797                           asc_dvc->sdtr_period_tbl[(sdtr_data >> 4) &
10798                           (uchar) (asc_dvc->max_sdtr_index - 1)],
10799                           (uchar) (sdtr_data & (uchar) ASC_SYN_MAX_OFFSET));
10800             scsiq->q1.cntl |= (QC_MSG_OUT | QC_URGENT);
10801         }
10802     }
10803     last_int_level = DvcEnterCritical();
10804     if (asc_dvc->in_critical_cnt != 0) {
10805         DvcLeaveCritical(last_int_level);
10806         AscSetLibErrorCode(asc_dvc, ASCQ_ERR_CRITICAL_RE_ENTRY);
10807         return (ERR);
10808     }
10809     asc_dvc->in_critical_cnt++;
10810     if ((scsiq->q1.cntl & QC_SG_HEAD) != 0) {
10811         if ((sg_entry_cnt = sg_head->entry_cnt) == 0) {
10812             asc_dvc->in_critical_cnt--;
10813             DvcLeaveCritical(last_int_level);
10814             return (ERR);
10815         }
10816 #if !CC_VERY_LONG_SG_LIST
10817         if (sg_entry_cnt > ASC_MAX_SG_LIST)
10818         {
10819             asc_dvc->in_critical_cnt--;
10820             DvcLeaveCritical(last_int_level);
10821             return(ERR);
10822         }
10823 #endif /* !CC_VERY_LONG_SG_LIST */
10824         if (sg_entry_cnt == 1) {
10825             scsiq->q1.data_addr = (ADV_PADDR) sg_head->sg_list[0].addr;
10826             scsiq->q1.data_cnt = (ADV_DCNT) sg_head->sg_list[0].bytes;
10827             scsiq->q1.cntl &= ~(QC_SG_HEAD | QC_SG_SWAP_QUEUE);
10828         }
10829         sg_entry_cnt_minus_one = sg_entry_cnt - 1;
10830     }
10831     scsi_cmd = scsiq->cdbptr[0];
10832     disable_syn_offset_one_fix = FALSE;
10833     if ((asc_dvc->pci_fix_asyn_xfer & scsiq->q1.target_id) &&
10834         !(asc_dvc->pci_fix_asyn_xfer_always & scsiq->q1.target_id)) {
10835         if (scsiq->q1.cntl & QC_SG_HEAD) {
10836             data_cnt = 0;
10837             for (i = 0; i < sg_entry_cnt; i++) {
10838                 data_cnt += (ADV_DCNT) le32_to_cpu(sg_head->sg_list[i].bytes);
10839             }
10840         } else {
10841             data_cnt = le32_to_cpu(scsiq->q1.data_cnt);
10842         }
10843         if (data_cnt != 0UL) {
10844             if (data_cnt < 512UL) {
10845                 disable_syn_offset_one_fix = TRUE;
10846             } else {
10847                 for (i = 0; i < ASC_SYN_OFFSET_ONE_DISABLE_LIST; i++) {
10848                     disable_cmd = _syn_offset_one_disable_cmd[i];
10849                     if (disable_cmd == 0xFF) {
10850                         break;
10851                     }
10852                     if (scsi_cmd == disable_cmd) {
10853                         disable_syn_offset_one_fix = TRUE;
10854                         break;
10855                     }
10856                 }
10857             }
10858         }
10859     }
10860     if (disable_syn_offset_one_fix) {
10861         scsiq->q2.tag_code &= ~MSG_SIMPLE_TAG;
10862         scsiq->q2.tag_code |= (ASC_TAG_FLAG_DISABLE_ASYN_USE_SYN_FIX |
10863                                ASC_TAG_FLAG_DISABLE_DISCONNECT);
10864     } else {
10865         scsiq->q2.tag_code &= 0x27;
10866     }
10867     if ((scsiq->q1.cntl & QC_SG_HEAD) != 0) {
10868         if (asc_dvc->bug_fix_cntl) {
10869             if (asc_dvc->bug_fix_cntl & ASC_BUG_FIX_IF_NOT_DWB) {
10870                 if ((scsi_cmd == READ_6) ||
10871                     (scsi_cmd == READ_10)) {
10872                     addr =
10873                         (ADV_PADDR) le32_to_cpu(
10874                             sg_head->sg_list[sg_entry_cnt_minus_one].addr) +
10875                         (ADV_DCNT) le32_to_cpu(
10876                             sg_head->sg_list[sg_entry_cnt_minus_one].bytes);
10877                     extra_bytes = (uchar) ((ushort) addr & 0x0003);
10878                     if ((extra_bytes != 0) &&
10879                         ((scsiq->q2.tag_code & ASC_TAG_FLAG_EXTRA_BYTES)
10880                          == 0)) {
10881                         scsiq->q2.tag_code |= ASC_TAG_FLAG_EXTRA_BYTES;
10882                         scsiq->q1.extra_bytes = extra_bytes;
10883                         data_cnt = le32_to_cpu(
10884                             sg_head->sg_list[sg_entry_cnt_minus_one].bytes);
10885                         data_cnt -= (ASC_DCNT) extra_bytes;
10886                         sg_head->sg_list[sg_entry_cnt_minus_one].bytes =
10887                             cpu_to_le32(data_cnt);
10888                     }
10889                 }
10890             }
10891         }
10892         sg_head->entry_to_copy = sg_head->entry_cnt;
10893 #if CC_VERY_LONG_SG_LIST
10894         /*
10895          * Set the sg_entry_cnt to the maximum possible. The rest of
10896          * the SG elements will be copied when the RISC completes the
10897          * SG elements that fit and halts.
10898          */
10899         if (sg_entry_cnt > ASC_MAX_SG_LIST)
10900         {
10901              sg_entry_cnt = ASC_MAX_SG_LIST;
10902         }
10903 #endif /* CC_VERY_LONG_SG_LIST */
10904         n_q_required = AscSgListToQueue(sg_entry_cnt);
10905         if ((AscGetNumOfFreeQueue(asc_dvc, target_ix, n_q_required) >=
10906             (uint) n_q_required) || ((scsiq->q1.cntl & QC_URGENT) != 0)) {
10907             if ((sta = AscSendScsiQueue(asc_dvc, scsiq,
10908                                         n_q_required)) == 1) {
10909                 asc_dvc->in_critical_cnt--;
10910                 if (asc_exe_callback != 0) {
10911                     (*asc_exe_callback) (asc_dvc, scsiq);
10912                 }
10913                 DvcLeaveCritical(last_int_level);
10914                 return (sta);
10915             }
10916         }
10917     } else {
10918         if (asc_dvc->bug_fix_cntl) {
10919             if (asc_dvc->bug_fix_cntl & ASC_BUG_FIX_IF_NOT_DWB) {
10920                 if ((scsi_cmd == READ_6) ||
10921                     (scsi_cmd == READ_10)) {
10922                     addr = le32_to_cpu(scsiq->q1.data_addr) +
10923                         le32_to_cpu(scsiq->q1.data_cnt);
10924                     extra_bytes = (uchar) ((ushort) addr & 0x0003);
10925                     if ((extra_bytes != 0) &&
10926                         ((scsiq->q2.tag_code & ASC_TAG_FLAG_EXTRA_BYTES)
10927                           == 0)) {
10928                         data_cnt = le32_to_cpu(scsiq->q1.data_cnt);
10929                         if (((ushort) data_cnt & 0x01FF) == 0) {
10930                             scsiq->q2.tag_code |= ASC_TAG_FLAG_EXTRA_BYTES;
10931                             data_cnt -= (ASC_DCNT) extra_bytes;
10932                             scsiq->q1.data_cnt = cpu_to_le32(data_cnt);
10933                             scsiq->q1.extra_bytes = extra_bytes;
10934                         }
10935                     }
10936                 }
10937             }
10938         }
10939         n_q_required = 1;
10940         if ((AscGetNumOfFreeQueue(asc_dvc, target_ix, 1) >= 1) ||
10941             ((scsiq->q1.cntl & QC_URGENT) != 0)) {
10942             if ((sta = AscSendScsiQueue(asc_dvc, scsiq,
10943                                         n_q_required)) == 1) {
10944                 asc_dvc->in_critical_cnt--;
10945                 if (asc_exe_callback != 0) {
10946                     (*asc_exe_callback) (asc_dvc, scsiq);
10947                 }
10948                 DvcLeaveCritical(last_int_level);
10949                 return (sta);
10950             }
10951         }
10952     }
10953     asc_dvc->in_critical_cnt--;
10954     DvcLeaveCritical(last_int_level);
10955     return (sta);
10956 }
10957
10958 STATIC int
10959 AscSendScsiQueue(
10960                     ASC_DVC_VAR *asc_dvc,
10961                     ASC_SCSI_Q *scsiq,
10962                     uchar n_q_required
10963 )
10964 {
10965     PortAddr            iop_base;
10966     uchar               free_q_head;
10967     uchar               next_qp;
10968     uchar               tid_no;
10969     uchar               target_ix;
10970     int                 sta;
10971
10972     iop_base = asc_dvc->iop_base;
10973     target_ix = scsiq->q2.target_ix;
10974     tid_no = ASC_TIX_TO_TID(target_ix);
10975     sta = 0;
10976     free_q_head = (uchar) AscGetVarFreeQHead(iop_base);
10977     if (n_q_required > 1) {
10978         if ((next_qp = AscAllocMultipleFreeQueue(iop_base,
10979                                        free_q_head, (uchar) (n_q_required)))
10980             != (uchar) ASC_QLINK_END) {
10981             asc_dvc->last_q_shortage = 0;
10982             scsiq->sg_head->queue_cnt = n_q_required - 1;
10983             scsiq->q1.q_no = free_q_head;
10984             if ((sta = AscPutReadySgListQueue(asc_dvc, scsiq,
10985                                               free_q_head)) == 1) {
10986                 AscPutVarFreeQHead(iop_base, next_qp);
10987                 asc_dvc->cur_total_qng += (uchar) (n_q_required);
10988                 asc_dvc->cur_dvc_qng[tid_no]++;
10989             }
10990             return (sta);
10991         }
10992     } else if (n_q_required == 1) {
10993         if ((next_qp = AscAllocFreeQueue(iop_base,
10994                                          free_q_head)) != ASC_QLINK_END) {
10995             scsiq->q1.q_no = free_q_head;
10996             if ((sta = AscPutReadyQueue(asc_dvc, scsiq,
10997                                         free_q_head)) == 1) {
10998                 AscPutVarFreeQHead(iop_base, next_qp);
10999                 asc_dvc->cur_total_qng++;
11000                 asc_dvc->cur_dvc_qng[tid_no]++;
11001             }
11002             return (sta);
11003         }
11004     }
11005     return (sta);
11006 }
11007
11008 STATIC int
11009 AscSgListToQueue(
11010                     int sg_list
11011 )
11012 {
11013     int                 n_sg_list_qs;
11014
11015     n_sg_list_qs = ((sg_list - 1) / ASC_SG_LIST_PER_Q);
11016     if (((sg_list - 1) % ASC_SG_LIST_PER_Q) != 0)
11017         n_sg_list_qs++;
11018     return (n_sg_list_qs + 1);
11019 }
11020
11021
11022 STATIC uint
11023 AscGetNumOfFreeQueue(
11024                         ASC_DVC_VAR *asc_dvc,
11025                         uchar target_ix,
11026                         uchar n_qs
11027 )
11028 {
11029     uint                cur_used_qs;
11030     uint                cur_free_qs;
11031     ASC_SCSI_BIT_ID_TYPE target_id;
11032     uchar               tid_no;
11033
11034     target_id = ASC_TIX_TO_TARGET_ID(target_ix);
11035     tid_no = ASC_TIX_TO_TID(target_ix);
11036     if ((asc_dvc->unit_not_ready & target_id) ||
11037         (asc_dvc->queue_full_or_busy & target_id)) {
11038         return (0);
11039     }
11040     if (n_qs == 1) {
11041         cur_used_qs = (uint) asc_dvc->cur_total_qng +
11042           (uint) asc_dvc->last_q_shortage +
11043           (uint) ASC_MIN_FREE_Q;
11044     } else {
11045         cur_used_qs = (uint) asc_dvc->cur_total_qng +
11046           (uint) ASC_MIN_FREE_Q;
11047     }
11048     if ((uint) (cur_used_qs + n_qs) <= (uint) asc_dvc->max_total_qng) {
11049         cur_free_qs = (uint) asc_dvc->max_total_qng - cur_used_qs;
11050         if (asc_dvc->cur_dvc_qng[tid_no] >=
11051             asc_dvc->max_dvc_qng[tid_no]) {
11052             return (0);
11053         }
11054         return (cur_free_qs);
11055     }
11056     if (n_qs > 1) {
11057         if ((n_qs > asc_dvc->last_q_shortage) && (n_qs <= (asc_dvc->max_total_qng - ASC_MIN_FREE_Q))) {
11058             asc_dvc->last_q_shortage = n_qs;
11059         }
11060     }
11061     return (0);
11062 }
11063
11064 STATIC int
11065 AscPutReadyQueue(
11066                     ASC_DVC_VAR *asc_dvc,
11067                     ASC_SCSI_Q *scsiq,
11068                     uchar q_no
11069 )
11070 {
11071     ushort              q_addr;
11072     uchar               tid_no;
11073     uchar               sdtr_data;
11074     uchar               syn_period_ix;
11075     uchar               syn_offset;
11076     PortAddr            iop_base;
11077
11078     iop_base = asc_dvc->iop_base;
11079     if (((asc_dvc->init_sdtr & scsiq->q1.target_id) != 0) &&
11080         ((asc_dvc->sdtr_done & scsiq->q1.target_id) == 0)) {
11081         tid_no = ASC_TIX_TO_TID(scsiq->q2.target_ix);
11082         sdtr_data = AscGetMCodeInitSDTRAtID(iop_base, tid_no);
11083         syn_period_ix = (sdtr_data >> 4) & (asc_dvc->max_sdtr_index - 1);
11084         syn_offset = sdtr_data & ASC_SYN_MAX_OFFSET;
11085         AscMsgOutSDTR(asc_dvc,
11086                       asc_dvc->sdtr_period_tbl[syn_period_ix],
11087                       syn_offset);
11088         scsiq->q1.cntl |= QC_MSG_OUT;
11089     }
11090     q_addr = ASC_QNO_TO_QADDR(q_no);
11091     if ((scsiq->q1.target_id & asc_dvc->use_tagged_qng) == 0) {
11092         scsiq->q2.tag_code &= ~MSG_SIMPLE_TAG ;
11093     }
11094     scsiq->q1.status = QS_FREE;
11095     AscMemWordCopyPtrToLram(iop_base,
11096                          q_addr + ASC_SCSIQ_CDB_BEG,
11097                          (uchar *) scsiq->cdbptr,
11098                          scsiq->q2.cdb_len >> 1);
11099
11100     DvcPutScsiQ(iop_base,
11101                 q_addr + ASC_SCSIQ_CPY_BEG,
11102                 (uchar *) &scsiq->q1.cntl,
11103                 ((sizeof(ASC_SCSIQ_1) + sizeof(ASC_SCSIQ_2)) / 2) - 1);
11104     AscWriteLramWord(iop_base,
11105                      (ushort) (q_addr + (ushort) ASC_SCSIQ_B_STATUS),
11106              (ushort) (((ushort) scsiq->q1.q_no << 8) | (ushort) QS_READY));
11107     return (1);
11108 }
11109
11110 STATIC int
11111 AscPutReadySgListQueue(
11112                           ASC_DVC_VAR *asc_dvc,
11113                           ASC_SCSI_Q *scsiq,
11114                           uchar q_no
11115 )
11116 {
11117     int                 sta;
11118     int                 i;
11119     ASC_SG_HEAD *sg_head;
11120     ASC_SG_LIST_Q       scsi_sg_q;
11121     ASC_DCNT            saved_data_addr;
11122     ASC_DCNT            saved_data_cnt;
11123     PortAddr            iop_base;
11124     ushort              sg_list_dwords;
11125     ushort              sg_index;
11126     ushort              sg_entry_cnt;
11127     ushort              q_addr;
11128     uchar               next_qp;
11129
11130     iop_base = asc_dvc->iop_base;
11131     sg_head = scsiq->sg_head;
11132     saved_data_addr = scsiq->q1.data_addr;
11133     saved_data_cnt = scsiq->q1.data_cnt;
11134     scsiq->q1.data_addr = (ASC_PADDR) sg_head->sg_list[0].addr;
11135     scsiq->q1.data_cnt = (ASC_DCNT) sg_head->sg_list[0].bytes;
11136 #if CC_VERY_LONG_SG_LIST
11137     /*
11138      * If sg_head->entry_cnt is greater than ASC_MAX_SG_LIST
11139      * then not all SG elements will fit in the allocated queues.
11140      * The rest of the SG elements will be copied when the RISC
11141      * completes the SG elements that fit and halts.
11142      */
11143     if (sg_head->entry_cnt > ASC_MAX_SG_LIST)
11144     {
11145          /*
11146           * Set sg_entry_cnt to be the number of SG elements that
11147           * will fit in the allocated SG queues. It is minus 1, because
11148           * the first SG element is handled above. ASC_MAX_SG_LIST is
11149           * already inflated by 1 to account for this. For example it
11150           * may be 50 which is 1 + 7 queues * 7 SG elements.
11151           */
11152          sg_entry_cnt = ASC_MAX_SG_LIST - 1;
11153
11154          /*
11155           * Keep track of remaining number of SG elements that will
11156           * need to be handled from a_isr.c.
11157           */
11158          scsiq->remain_sg_entry_cnt = sg_head->entry_cnt - ASC_MAX_SG_LIST;
11159     } else
11160     {
11161 #endif /* CC_VERY_LONG_SG_LIST */
11162          /*
11163           * Set sg_entry_cnt to be the number of SG elements that
11164           * will fit in the allocated SG queues. It is minus 1, because
11165           * the first SG element is handled above.
11166           */
11167          sg_entry_cnt = sg_head->entry_cnt - 1;
11168 #if CC_VERY_LONG_SG_LIST
11169     }
11170 #endif /* CC_VERY_LONG_SG_LIST */
11171     if (sg_entry_cnt != 0) {
11172         scsiq->q1.cntl |= QC_SG_HEAD;
11173         q_addr = ASC_QNO_TO_QADDR(q_no);
11174         sg_index = 1;
11175         scsiq->q1.sg_queue_cnt = sg_head->queue_cnt;
11176         scsi_sg_q.sg_head_qp = q_no;
11177         scsi_sg_q.cntl = QCSG_SG_XFER_LIST;
11178         for (i = 0; i < sg_head->queue_cnt; i++) {
11179             scsi_sg_q.seq_no = i + 1;
11180             if (sg_entry_cnt > ASC_SG_LIST_PER_Q) {
11181                 sg_list_dwords = (uchar) (ASC_SG_LIST_PER_Q * 2);
11182                 sg_entry_cnt -= ASC_SG_LIST_PER_Q;
11183                 if (i == 0) {
11184                     scsi_sg_q.sg_list_cnt = ASC_SG_LIST_PER_Q;
11185                     scsi_sg_q.sg_cur_list_cnt = ASC_SG_LIST_PER_Q;
11186                 } else {
11187                     scsi_sg_q.sg_list_cnt = ASC_SG_LIST_PER_Q - 1;
11188                     scsi_sg_q.sg_cur_list_cnt = ASC_SG_LIST_PER_Q - 1;
11189                 }
11190             } else {
11191 #if CC_VERY_LONG_SG_LIST
11192                 /*
11193                  * This is the last SG queue in the list of
11194                  * allocated SG queues. If there are more
11195                  * SG elements than will fit in the allocated
11196                  * queues, then set the QCSG_SG_XFER_MORE flag.
11197                  */
11198                 if (sg_head->entry_cnt > ASC_MAX_SG_LIST)
11199                 {
11200                     scsi_sg_q.cntl |= QCSG_SG_XFER_MORE;
11201                 } else
11202                 {
11203 #endif /* CC_VERY_LONG_SG_LIST */
11204                     scsi_sg_q.cntl |= QCSG_SG_XFER_END;
11205 #if CC_VERY_LONG_SG_LIST
11206                 }
11207 #endif /* CC_VERY_LONG_SG_LIST */
11208                 sg_list_dwords = sg_entry_cnt << 1;
11209                 if (i == 0) {
11210                     scsi_sg_q.sg_list_cnt = sg_entry_cnt;
11211                     scsi_sg_q.sg_cur_list_cnt = sg_entry_cnt;
11212                 } else {
11213                     scsi_sg_q.sg_list_cnt = sg_entry_cnt - 1;
11214                     scsi_sg_q.sg_cur_list_cnt = sg_entry_cnt - 1;
11215                 }
11216                 sg_entry_cnt = 0;
11217             }
11218             next_qp = AscReadLramByte(iop_base,
11219                                       (ushort) (q_addr + ASC_SCSIQ_B_FWD));
11220             scsi_sg_q.q_no = next_qp;
11221             q_addr = ASC_QNO_TO_QADDR(next_qp);
11222             AscMemWordCopyPtrToLram(iop_base,
11223                                 q_addr + ASC_SCSIQ_SGHD_CPY_BEG,
11224                                 (uchar *) &scsi_sg_q,
11225                                 sizeof(ASC_SG_LIST_Q) >> 1);
11226             AscMemDWordCopyPtrToLram(iop_base,
11227                                 q_addr + ASC_SGQ_LIST_BEG,
11228                                 (uchar *) &sg_head->sg_list[sg_index],
11229                                 sg_list_dwords);
11230             sg_index += ASC_SG_LIST_PER_Q;
11231             scsiq->next_sg_index = sg_index;
11232         }
11233     } else {
11234         scsiq->q1.cntl &= ~QC_SG_HEAD;
11235     }
11236     sta = AscPutReadyQueue(asc_dvc, scsiq, q_no);
11237     scsiq->q1.data_addr = saved_data_addr;
11238     scsiq->q1.data_cnt = saved_data_cnt;
11239     return (sta);
11240 }
11241
11242 STATIC int
11243 AscSetRunChipSynRegAtID(
11244                            PortAddr iop_base,
11245                            uchar tid_no,
11246                            uchar sdtr_data
11247 )
11248 {
11249     int                 sta = FALSE;
11250
11251     if (AscHostReqRiscHalt(iop_base)) {
11252         sta = AscSetChipSynRegAtID(iop_base, tid_no, sdtr_data);
11253         AscStartChip(iop_base);
11254         return (sta);
11255     }
11256     return (sta);
11257 }
11258
11259 STATIC int
11260 AscSetChipSynRegAtID(
11261                         PortAddr iop_base,
11262                         uchar id,
11263                         uchar sdtr_data
11264 )
11265 {
11266     ASC_SCSI_BIT_ID_TYPE org_id;
11267     int                 i;
11268     int                 sta = TRUE;
11269
11270     AscSetBank(iop_base, 1);
11271     org_id = AscReadChipDvcID(iop_base);
11272     for (i = 0; i <= ASC_MAX_TID; i++) {
11273         if (org_id == (0x01 << i))
11274             break;
11275     }
11276     org_id = (ASC_SCSI_BIT_ID_TYPE) i;
11277     AscWriteChipDvcID(iop_base, id);
11278     if (AscReadChipDvcID(iop_base) == (0x01 << id)) {
11279         AscSetBank(iop_base, 0);
11280         AscSetChipSyn(iop_base, sdtr_data);
11281         if (AscGetChipSyn(iop_base) != sdtr_data) {
11282             sta = FALSE;
11283         }
11284     } else {
11285         sta = FALSE;
11286     }
11287     AscSetBank(iop_base, 1);
11288     AscWriteChipDvcID(iop_base, org_id);
11289     AscSetBank(iop_base, 0);
11290     return (sta);
11291 }
11292
11293 STATIC ushort
11294 AscInitLram(
11295                ASC_DVC_VAR *asc_dvc
11296 )
11297 {
11298     uchar               i;
11299     ushort              s_addr;
11300     PortAddr            iop_base;
11301     ushort              warn_code;
11302
11303     iop_base = asc_dvc->iop_base;
11304     warn_code = 0;
11305     AscMemWordSetLram(iop_base, ASC_QADR_BEG, 0,
11306                (ushort) (((int) (asc_dvc->max_total_qng + 2 + 1) * 64) >> 1)
11307 );
11308     i = ASC_MIN_ACTIVE_QNO;
11309     s_addr = ASC_QADR_BEG + ASC_QBLK_SIZE;
11310     AscWriteLramByte(iop_base, (ushort) (s_addr + ASC_SCSIQ_B_FWD),
11311                      (uchar) (i + 1));
11312     AscWriteLramByte(iop_base, (ushort) (s_addr + ASC_SCSIQ_B_BWD),
11313                      (uchar) (asc_dvc->max_total_qng));
11314     AscWriteLramByte(iop_base, (ushort) (s_addr + ASC_SCSIQ_B_QNO),
11315                      (uchar) i);
11316     i++;
11317     s_addr += ASC_QBLK_SIZE;
11318     for (; i < asc_dvc->max_total_qng; i++, s_addr += ASC_QBLK_SIZE) {
11319         AscWriteLramByte(iop_base, (ushort) (s_addr + ASC_SCSIQ_B_FWD),
11320                          (uchar) (i + 1));
11321         AscWriteLramByte(iop_base, (ushort) (s_addr + ASC_SCSIQ_B_BWD),
11322                          (uchar) (i - 1));
11323         AscWriteLramByte(iop_base, (ushort) (s_addr + ASC_SCSIQ_B_QNO),
11324                          (uchar) i);
11325     }
11326     AscWriteLramByte(iop_base, (ushort) (s_addr + ASC_SCSIQ_B_FWD),
11327                      (uchar) ASC_QLINK_END);
11328     AscWriteLramByte(iop_base, (ushort) (s_addr + ASC_SCSIQ_B_BWD),
11329                      (uchar) (asc_dvc->max_total_qng - 1));
11330     AscWriteLramByte(iop_base, (ushort) (s_addr + ASC_SCSIQ_B_QNO),
11331                      (uchar) asc_dvc->max_total_qng);
11332     i++;
11333     s_addr += ASC_QBLK_SIZE;
11334     for (; i <= (uchar) (asc_dvc->max_total_qng + 3);
11335          i++, s_addr += ASC_QBLK_SIZE) {
11336         AscWriteLramByte(iop_base,
11337                          (ushort) (s_addr + (ushort) ASC_SCSIQ_B_FWD), i);
11338         AscWriteLramByte(iop_base,
11339                          (ushort) (s_addr + (ushort) ASC_SCSIQ_B_BWD), i);
11340         AscWriteLramByte(iop_base,
11341                          (ushort) (s_addr + (ushort) ASC_SCSIQ_B_QNO), i);
11342     }
11343     return (warn_code);
11344 }
11345
11346 STATIC ushort
11347 AscInitQLinkVar(
11348                    ASC_DVC_VAR *asc_dvc
11349 )
11350 {
11351     PortAddr            iop_base;
11352     int                 i;
11353     ushort              lram_addr;
11354
11355     iop_base = asc_dvc->iop_base;
11356     AscPutRiscVarFreeQHead(iop_base, 1);
11357     AscPutRiscVarDoneQTail(iop_base, asc_dvc->max_total_qng);
11358     AscPutVarFreeQHead(iop_base, 1);
11359     AscPutVarDoneQTail(iop_base, asc_dvc->max_total_qng);
11360     AscWriteLramByte(iop_base, ASCV_BUSY_QHEAD_B,
11361                      (uchar) ((int) asc_dvc->max_total_qng + 1));
11362     AscWriteLramByte(iop_base, ASCV_DISC1_QHEAD_B,
11363                      (uchar) ((int) asc_dvc->max_total_qng + 2));
11364     AscWriteLramByte(iop_base, (ushort) ASCV_TOTAL_READY_Q_B,
11365                      asc_dvc->max_total_qng);
11366     AscWriteLramWord(iop_base, ASCV_ASCDVC_ERR_CODE_W, 0);
11367     AscWriteLramWord(iop_base, ASCV_HALTCODE_W, 0);
11368     AscWriteLramByte(iop_base, ASCV_STOP_CODE_B, 0);
11369     AscWriteLramByte(iop_base, ASCV_SCSIBUSY_B, 0);
11370     AscWriteLramByte(iop_base, ASCV_WTM_FLAG_B, 0);
11371     AscPutQDoneInProgress(iop_base, 0);
11372     lram_addr = ASC_QADR_BEG;
11373     for (i = 0; i < 32; i++, lram_addr += 2) {
11374         AscWriteLramWord(iop_base, lram_addr, 0);
11375     }
11376     return (0);
11377 }
11378
11379 STATIC int
11380 AscSetLibErrorCode(
11381                       ASC_DVC_VAR *asc_dvc,
11382                       ushort err_code
11383 )
11384 {
11385     if (asc_dvc->err_code == 0) {
11386         asc_dvc->err_code = err_code;
11387         AscWriteLramWord(asc_dvc->iop_base, ASCV_ASCDVC_ERR_CODE_W,
11388                          err_code);
11389     }
11390     return (err_code);
11391 }
11392
11393
11394 STATIC uchar
11395 AscMsgOutSDTR(
11396                  ASC_DVC_VAR *asc_dvc,
11397                  uchar sdtr_period,
11398                  uchar sdtr_offset
11399 )
11400 {
11401     EXT_MSG             sdtr_buf;
11402     uchar               sdtr_period_index;
11403     PortAddr            iop_base;
11404
11405     iop_base = asc_dvc->iop_base;
11406     sdtr_buf.msg_type = MS_EXTEND;
11407     sdtr_buf.msg_len = MS_SDTR_LEN;
11408     sdtr_buf.msg_req = MS_SDTR_CODE;
11409     sdtr_buf.xfer_period = sdtr_period;
11410     sdtr_offset &= ASC_SYN_MAX_OFFSET;
11411     sdtr_buf.req_ack_offset = sdtr_offset;
11412     if ((sdtr_period_index =
11413          AscGetSynPeriodIndex(asc_dvc, sdtr_period)) <=
11414         asc_dvc->max_sdtr_index) {
11415         AscMemWordCopyPtrToLram(iop_base,
11416                              ASCV_MSGOUT_BEG,
11417                              (uchar *) &sdtr_buf,
11418                              sizeof (EXT_MSG) >> 1);
11419         return ((sdtr_period_index << 4) | sdtr_offset);
11420     } else {
11421
11422         sdtr_buf.req_ack_offset = 0;
11423         AscMemWordCopyPtrToLram(iop_base,
11424                              ASCV_MSGOUT_BEG,
11425                              (uchar *) &sdtr_buf,
11426                              sizeof (EXT_MSG) >> 1);
11427         return (0);
11428     }
11429 }
11430
11431 STATIC uchar
11432 AscCalSDTRData(
11433                   ASC_DVC_VAR *asc_dvc,
11434                   uchar sdtr_period,
11435                   uchar syn_offset
11436 )
11437 {
11438     uchar               byte;
11439     uchar               sdtr_period_ix;
11440
11441     sdtr_period_ix = AscGetSynPeriodIndex(asc_dvc, sdtr_period);
11442     if (
11443            (sdtr_period_ix > asc_dvc->max_sdtr_index)
11444 ) {
11445         return (0xFF);
11446     }
11447     byte = (sdtr_period_ix << 4) | (syn_offset & ASC_SYN_MAX_OFFSET);
11448     return (byte);
11449 }
11450
11451 STATIC void
11452 AscSetChipSDTR(
11453                   PortAddr iop_base,
11454                   uchar sdtr_data,
11455                   uchar tid_no
11456 )
11457 {
11458     AscSetChipSynRegAtID(iop_base, tid_no, sdtr_data);
11459     AscPutMCodeSDTRDoneAtID(iop_base, tid_no, sdtr_data);
11460     return;
11461 }
11462
11463 STATIC uchar
11464 AscGetSynPeriodIndex(
11465                         ASC_DVC_VAR *asc_dvc,
11466                         uchar syn_time
11467 )
11468 {
11469     uchar             *period_table;
11470     int                 max_index;
11471     int                 min_index;
11472     int                 i;
11473
11474     period_table = asc_dvc->sdtr_period_tbl;
11475     max_index = (int) asc_dvc->max_sdtr_index;
11476     min_index = (int)asc_dvc->host_init_sdtr_index;
11477     if ((syn_time <= period_table[max_index])) {
11478         for (i = min_index; i < (max_index - 1); i++) {
11479             if (syn_time <= period_table[i]) {
11480                 return ((uchar) i);
11481             }
11482         }
11483         return ((uchar) max_index);
11484     } else {
11485         return ((uchar) (max_index + 1));
11486     }
11487 }
11488
11489 STATIC uchar
11490 AscAllocFreeQueue(
11491                      PortAddr iop_base,
11492                      uchar free_q_head
11493 )
11494 {
11495     ushort              q_addr;
11496     uchar               next_qp;
11497     uchar               q_status;
11498
11499     q_addr = ASC_QNO_TO_QADDR(free_q_head);
11500     q_status = (uchar) AscReadLramByte(iop_base,
11501                                     (ushort) (q_addr + ASC_SCSIQ_B_STATUS));
11502     next_qp = AscReadLramByte(iop_base,
11503                               (ushort) (q_addr + ASC_SCSIQ_B_FWD));
11504     if (((q_status & QS_READY) == 0) && (next_qp != ASC_QLINK_END)) {
11505         return (next_qp);
11506     }
11507     return (ASC_QLINK_END);
11508 }
11509
11510 STATIC uchar
11511 AscAllocMultipleFreeQueue(
11512                              PortAddr iop_base,
11513                              uchar free_q_head,
11514                              uchar n_free_q
11515 )
11516 {
11517     uchar               i;
11518
11519     for (i = 0; i < n_free_q; i++) {
11520         if ((free_q_head = AscAllocFreeQueue(iop_base, free_q_head))
11521             == ASC_QLINK_END) {
11522             return (ASC_QLINK_END);
11523         }
11524     }
11525     return (free_q_head);
11526 }
11527
11528 STATIC int
11529 AscHostReqRiscHalt(
11530                       PortAddr iop_base
11531 )
11532 {
11533     int                 count = 0;
11534     int                 sta = 0;
11535     uchar               saved_stop_code;
11536
11537     if (AscIsChipHalted(iop_base))
11538         return (1);
11539     saved_stop_code = AscReadLramByte(iop_base, ASCV_STOP_CODE_B);
11540     AscWriteLramByte(iop_base, ASCV_STOP_CODE_B,
11541                      ASC_STOP_HOST_REQ_RISC_HALT | ASC_STOP_REQ_RISC_STOP
11542 );
11543     do {
11544         if (AscIsChipHalted(iop_base)) {
11545             sta = 1;
11546             break;
11547         }
11548         DvcSleepMilliSecond(100);
11549     } while (count++ < 20);
11550     AscWriteLramByte(iop_base, ASCV_STOP_CODE_B, saved_stop_code);
11551     return (sta);
11552 }
11553
11554 STATIC int
11555 AscStopQueueExe(
11556                    PortAddr iop_base
11557 )
11558 {
11559     int                 count = 0;
11560
11561     if (AscReadLramByte(iop_base, ASCV_STOP_CODE_B) == 0) {
11562         AscWriteLramByte(iop_base, ASCV_STOP_CODE_B,
11563                          ASC_STOP_REQ_RISC_STOP);
11564         do {
11565             if (
11566                    AscReadLramByte(iop_base, ASCV_STOP_CODE_B) &
11567                    ASC_STOP_ACK_RISC_STOP) {
11568                 return (1);
11569             }
11570             DvcSleepMilliSecond(100);
11571         } while (count++ < 20);
11572     }
11573     return (0);
11574 }
11575
11576 STATIC void
11577 DvcDelayMicroSecond(ADV_DVC_VAR *asc_dvc, ushort micro_sec)
11578 {
11579     udelay(micro_sec);
11580 }
11581
11582 STATIC void
11583 DvcDelayNanoSecond(ASC_DVC_VAR *asc_dvc, ASC_DCNT nano_sec)
11584 {
11585     udelay((nano_sec + 999)/1000);
11586 }
11587
11588 #ifdef CONFIG_ISA
11589 STATIC ASC_DCNT __init
11590 AscGetEisaProductID(
11591                        PortAddr iop_base)
11592 {
11593     PortAddr            eisa_iop;
11594     ushort              product_id_high, product_id_low;
11595     ASC_DCNT            product_id;
11596
11597     eisa_iop = ASC_GET_EISA_SLOT(iop_base) | ASC_EISA_PID_IOP_MASK;
11598     product_id_low = inpw(eisa_iop);
11599     product_id_high = inpw(eisa_iop + 2);
11600     product_id = ((ASC_DCNT) product_id_high << 16) |
11601         (ASC_DCNT) product_id_low;
11602     return (product_id);
11603 }
11604
11605 STATIC PortAddr __init
11606 AscSearchIOPortAddrEISA(
11607                            PortAddr iop_base)
11608 {
11609     ASC_DCNT            eisa_product_id;
11610
11611     if (iop_base == 0) {
11612         iop_base = ASC_EISA_MIN_IOP_ADDR;
11613     } else {
11614         if (iop_base == ASC_EISA_MAX_IOP_ADDR)
11615             return (0);
11616         if ((iop_base & 0x0050) == 0x0050) {
11617             iop_base += ASC_EISA_BIG_IOP_GAP;
11618         } else {
11619             iop_base += ASC_EISA_SMALL_IOP_GAP;
11620         }
11621     }
11622     while (iop_base <= ASC_EISA_MAX_IOP_ADDR) {
11623         eisa_product_id = AscGetEisaProductID(iop_base);
11624         if ((eisa_product_id == ASC_EISA_ID_740) ||
11625             (eisa_product_id == ASC_EISA_ID_750)) {
11626             if (AscFindSignature(iop_base)) {
11627                 inpw(iop_base + 4);
11628                 return (iop_base);
11629             }
11630         }
11631         if (iop_base == ASC_EISA_MAX_IOP_ADDR)
11632             return (0);
11633         if ((iop_base & 0x0050) == 0x0050) {
11634             iop_base += ASC_EISA_BIG_IOP_GAP;
11635         } else {
11636             iop_base += ASC_EISA_SMALL_IOP_GAP;
11637         }
11638     }
11639     return (0);
11640 }
11641 #endif /* CONFIG_ISA */
11642
11643 STATIC int
11644 AscStartChip(
11645                 PortAddr iop_base
11646 )
11647 {
11648     AscSetChipControl(iop_base, 0);
11649     if ((AscGetChipStatus(iop_base) & CSW_HALTED) != 0) {
11650         return (0);
11651     }
11652     return (1);
11653 }
11654
11655 STATIC int
11656 AscStopChip(
11657                PortAddr iop_base
11658 )
11659 {
11660     uchar               cc_val;
11661
11662     cc_val = AscGetChipControl(iop_base) & (~(CC_SINGLE_STEP | CC_TEST | CC_DIAG));
11663     AscSetChipControl(iop_base, (uchar) (cc_val | CC_HALT));
11664     AscSetChipIH(iop_base, INS_HALT);
11665     AscSetChipIH(iop_base, INS_RFLAG_WTM);
11666     if ((AscGetChipStatus(iop_base) & CSW_HALTED) == 0) {
11667         return (0);
11668     }
11669     return (1);
11670 }
11671
11672 STATIC int
11673 AscIsChipHalted(
11674                    PortAddr iop_base
11675 )
11676 {
11677     if ((AscGetChipStatus(iop_base) & CSW_HALTED) != 0) {
11678         if ((AscGetChipControl(iop_base) & CC_HALT) != 0) {
11679             return (1);
11680         }
11681     }
11682     return (0);
11683 }
11684
11685 STATIC void
11686 AscSetChipIH(
11687                 PortAddr iop_base,
11688                 ushort ins_code
11689 )
11690 {
11691     AscSetBank(iop_base, 1);
11692     AscWriteChipIH(iop_base, ins_code);
11693     AscSetBank(iop_base, 0);
11694     return;
11695 }
11696
11697 STATIC void
11698 AscAckInterrupt(
11699                    PortAddr iop_base
11700 )
11701 {
11702     uchar               host_flag;
11703     uchar               risc_flag;
11704     ushort              loop;
11705
11706     loop = 0;
11707     do {
11708         risc_flag = AscReadLramByte(iop_base, ASCV_RISC_FLAG_B);
11709         if (loop++ > 0x7FFF) {
11710             break;
11711         }
11712     } while ((risc_flag & ASC_RISC_FLAG_GEN_INT) != 0);
11713     host_flag = AscReadLramByte(iop_base, ASCV_HOST_FLAG_B) & (~ASC_HOST_FLAG_ACK_INT);
11714     AscWriteLramByte(iop_base, ASCV_HOST_FLAG_B,
11715                      (uchar) (host_flag | ASC_HOST_FLAG_ACK_INT));
11716     AscSetChipStatus(iop_base, CIW_INT_ACK);
11717     loop = 0;
11718     while (AscGetChipStatus(iop_base) & CSW_INT_PENDING) {
11719         AscSetChipStatus(iop_base, CIW_INT_ACK);
11720         if (loop++ > 3) {
11721             break;
11722         }
11723     }
11724     AscWriteLramByte(iop_base, ASCV_HOST_FLAG_B, host_flag);
11725     return;
11726 }
11727
11728 STATIC void
11729 AscDisableInterrupt(
11730                        PortAddr iop_base
11731 )
11732 {
11733     ushort              cfg;
11734
11735     cfg = AscGetChipCfgLsw(iop_base);
11736     AscSetChipCfgLsw(iop_base, cfg & (~ASC_CFG0_HOST_INT_ON));
11737     return;
11738 }
11739
11740 STATIC void
11741 AscEnableInterrupt(
11742                       PortAddr iop_base
11743 )
11744 {
11745     ushort              cfg;
11746
11747     cfg = AscGetChipCfgLsw(iop_base);
11748     AscSetChipCfgLsw(iop_base, cfg | ASC_CFG0_HOST_INT_ON);
11749     return;
11750 }
11751
11752
11753
11754 STATIC void
11755 AscSetBank(
11756               PortAddr iop_base,
11757               uchar bank
11758 )
11759 {
11760     uchar               val;
11761
11762     val = AscGetChipControl(iop_base) &
11763       (~(CC_SINGLE_STEP | CC_TEST | CC_DIAG | CC_SCSI_RESET | CC_CHIP_RESET));
11764     if (bank == 1) {
11765         val |= CC_BANK_ONE;
11766     } else if (bank == 2) {
11767         val |= CC_DIAG | CC_BANK_ONE;
11768     } else {
11769         val &= ~CC_BANK_ONE;
11770     }
11771     AscSetChipControl(iop_base, val);
11772     return;
11773 }
11774
11775 STATIC int
11776 AscResetChipAndScsiBus(
11777                           ASC_DVC_VAR *asc_dvc
11778 )
11779 {
11780     PortAddr    iop_base;
11781     int         i = 10;
11782
11783     iop_base = asc_dvc->iop_base;
11784     while ((AscGetChipStatus(iop_base) & CSW_SCSI_RESET_ACTIVE) && (i-- > 0))
11785     {
11786           DvcSleepMilliSecond(100);
11787     }
11788     AscStopChip(iop_base);
11789     AscSetChipControl(iop_base, CC_CHIP_RESET | CC_SCSI_RESET | CC_HALT);
11790     DvcDelayNanoSecond(asc_dvc, 60000);
11791     AscSetChipIH(iop_base, INS_RFLAG_WTM);
11792     AscSetChipIH(iop_base, INS_HALT);
11793     AscSetChipControl(iop_base, CC_CHIP_RESET | CC_HALT);
11794     AscSetChipControl(iop_base, CC_HALT);
11795     DvcSleepMilliSecond(200);
11796     AscSetChipStatus(iop_base, CIW_CLR_SCSI_RESET_INT);
11797     AscSetChipStatus(iop_base, 0);
11798     return (AscIsChipHalted(iop_base));
11799 }
11800
11801 STATIC ASC_DCNT __init
11802 AscGetMaxDmaCount(
11803                      ushort bus_type)
11804 {
11805     if (bus_type & ASC_IS_ISA)
11806         return (ASC_MAX_ISA_DMA_COUNT);
11807     else if (bus_type & (ASC_IS_EISA | ASC_IS_VL))
11808         return (ASC_MAX_VL_DMA_COUNT);
11809     return (ASC_MAX_PCI_DMA_COUNT);
11810 }
11811
11812 #ifdef CONFIG_ISA
11813 STATIC ushort __init
11814 AscGetIsaDmaChannel(
11815                        PortAddr iop_base)
11816 {
11817     ushort              channel;
11818
11819     channel = AscGetChipCfgLsw(iop_base) & 0x0003;
11820     if (channel == 0x03)
11821         return (0);
11822     else if (channel == 0x00)
11823         return (7);
11824     return (channel + 4);
11825 }
11826
11827 STATIC ushort __init
11828 AscSetIsaDmaChannel(
11829                        PortAddr iop_base,
11830                        ushort dma_channel)
11831 {
11832     ushort              cfg_lsw;
11833     uchar               value;
11834
11835     if ((dma_channel >= 5) && (dma_channel <= 7)) {
11836         if (dma_channel == 7)
11837             value = 0x00;
11838         else
11839             value = dma_channel - 4;
11840         cfg_lsw = AscGetChipCfgLsw(iop_base) & 0xFFFC;
11841         cfg_lsw |= value;
11842         AscSetChipCfgLsw(iop_base, cfg_lsw);
11843         return (AscGetIsaDmaChannel(iop_base));
11844     }
11845     return (0);
11846 }
11847
11848 STATIC uchar __init
11849 AscSetIsaDmaSpeed(
11850                      PortAddr iop_base,
11851                      uchar speed_value)
11852 {
11853     speed_value &= 0x07;
11854     AscSetBank(iop_base, 1);
11855     AscWriteChipDmaSpeed(iop_base, speed_value);
11856     AscSetBank(iop_base, 0);
11857     return (AscGetIsaDmaSpeed(iop_base));
11858 }
11859
11860 STATIC uchar __init
11861 AscGetIsaDmaSpeed(
11862                      PortAddr iop_base
11863 )
11864 {
11865     uchar               speed_value;
11866
11867     AscSetBank(iop_base, 1);
11868     speed_value = AscReadChipDmaSpeed(iop_base);
11869     speed_value &= 0x07;
11870     AscSetBank(iop_base, 0);
11871     return (speed_value);
11872 }
11873 #endif /* CONFIG_ISA */
11874
11875 STATIC ushort __init
11876 AscReadPCIConfigWord(
11877     ASC_DVC_VAR *asc_dvc,
11878     ushort pci_config_offset)
11879 {
11880     uchar       lsb, msb;
11881
11882     lsb = DvcReadPCIConfigByte(asc_dvc, pci_config_offset);
11883     msb = DvcReadPCIConfigByte(asc_dvc, pci_config_offset + 1);
11884     return ((ushort) ((msb << 8) | lsb));
11885 }
11886
11887 STATIC ushort __init
11888 AscInitGetConfig(
11889         ASC_DVC_VAR *asc_dvc
11890 )
11891 {
11892     ushort              warn_code;
11893     PortAddr            iop_base;
11894     ushort              PCIDeviceID;
11895     ushort              PCIVendorID;
11896     uchar               PCIRevisionID;
11897     uchar               prevCmdRegBits;
11898
11899     warn_code = 0;
11900     iop_base = asc_dvc->iop_base;
11901     asc_dvc->init_state = ASC_INIT_STATE_BEG_GET_CFG;
11902     if (asc_dvc->err_code != 0) {
11903         return (UW_ERR);
11904     }
11905     if (asc_dvc->bus_type == ASC_IS_PCI) {
11906         PCIVendorID = AscReadPCIConfigWord(asc_dvc,
11907                                     AscPCIConfigVendorIDRegister);
11908
11909         PCIDeviceID = AscReadPCIConfigWord(asc_dvc,
11910                                     AscPCIConfigDeviceIDRegister);
11911
11912         PCIRevisionID = DvcReadPCIConfigByte(asc_dvc,
11913                                     AscPCIConfigRevisionIDRegister);
11914
11915         if (PCIVendorID != PCI_VENDOR_ID_ASP) {
11916             warn_code |= ASC_WARN_SET_PCI_CONFIG_SPACE;
11917         }
11918         prevCmdRegBits = DvcReadPCIConfigByte(asc_dvc,
11919                                     AscPCIConfigCommandRegister);
11920
11921         if ((prevCmdRegBits & AscPCICmdRegBits_IOMemBusMaster) !=
11922             AscPCICmdRegBits_IOMemBusMaster) {
11923             DvcWritePCIConfigByte(asc_dvc,
11924                             AscPCIConfigCommandRegister,
11925                             (prevCmdRegBits |
11926                              AscPCICmdRegBits_IOMemBusMaster));
11927
11928             if ((DvcReadPCIConfigByte(asc_dvc,
11929                                 AscPCIConfigCommandRegister)
11930                  & AscPCICmdRegBits_IOMemBusMaster)
11931                 != AscPCICmdRegBits_IOMemBusMaster) {
11932                 warn_code |= ASC_WARN_SET_PCI_CONFIG_SPACE;
11933             }
11934         }
11935         if ((PCIDeviceID == PCI_DEVICE_ID_ASP_1200A) ||
11936             (PCIDeviceID == PCI_DEVICE_ID_ASP_ABP940)) {
11937             DvcWritePCIConfigByte(asc_dvc,
11938                             AscPCIConfigLatencyTimer, 0x00);
11939             if (DvcReadPCIConfigByte(asc_dvc, AscPCIConfigLatencyTimer)
11940                 != 0x00) {
11941                 warn_code |= ASC_WARN_SET_PCI_CONFIG_SPACE;
11942             }
11943         } else if (PCIDeviceID == PCI_DEVICE_ID_ASP_ABP940U) {
11944             if (DvcReadPCIConfigByte(asc_dvc,
11945                                 AscPCIConfigLatencyTimer) < 0x20) {
11946                 DvcWritePCIConfigByte(asc_dvc,
11947                                     AscPCIConfigLatencyTimer, 0x20);
11948
11949                 if (DvcReadPCIConfigByte(asc_dvc,
11950                                     AscPCIConfigLatencyTimer) < 0x20) {
11951                     warn_code |= ASC_WARN_SET_PCI_CONFIG_SPACE;
11952                 }
11953             }
11954         }
11955     }
11956
11957     if (AscFindSignature(iop_base)) {
11958         warn_code |= AscInitAscDvcVar(asc_dvc);
11959         warn_code |= AscInitFromEEP(asc_dvc);
11960         asc_dvc->init_state |= ASC_INIT_STATE_END_GET_CFG;
11961         if (asc_dvc->scsi_reset_wait > ASC_MAX_SCSI_RESET_WAIT) {
11962             asc_dvc->scsi_reset_wait = ASC_MAX_SCSI_RESET_WAIT;
11963         }
11964     } else {
11965         asc_dvc->err_code = ASC_IERR_BAD_SIGNATURE;
11966     }
11967     return(warn_code);
11968 }
11969
11970 STATIC ushort __init
11971 AscInitSetConfig(
11972                     ASC_DVC_VAR *asc_dvc
11973 )
11974 {
11975     ushort              warn_code = 0;
11976
11977     asc_dvc->init_state |= ASC_INIT_STATE_BEG_SET_CFG;
11978     if (asc_dvc->err_code != 0)
11979         return (UW_ERR);
11980     if (AscFindSignature(asc_dvc->iop_base)) {
11981         warn_code |= AscInitFromAscDvcVar(asc_dvc);
11982         asc_dvc->init_state |= ASC_INIT_STATE_END_SET_CFG;
11983     } else {
11984         asc_dvc->err_code = ASC_IERR_BAD_SIGNATURE;
11985     }
11986     return (warn_code);
11987 }
11988
11989 STATIC ushort __init
11990 AscInitFromAscDvcVar(
11991                         ASC_DVC_VAR *asc_dvc
11992 )
11993 {
11994     PortAddr            iop_base;
11995     ushort              cfg_msw;
11996     ushort              warn_code;
11997     ushort              pci_device_id = 0;
11998
11999     iop_base = asc_dvc->iop_base;
12000 #ifdef CONFIG_PCI
12001     if (asc_dvc->cfg->dev)
12002         pci_device_id = to_pci_dev(asc_dvc->cfg->dev)->device;
12003 #endif
12004     warn_code = 0;
12005     cfg_msw = AscGetChipCfgMsw(iop_base);
12006     if ((cfg_msw & ASC_CFG_MSW_CLR_MASK) != 0) {
12007         cfg_msw &= (~(ASC_CFG_MSW_CLR_MASK));
12008         warn_code |= ASC_WARN_CFG_MSW_RECOVER;
12009         AscSetChipCfgMsw(iop_base, cfg_msw);
12010     }
12011     if ((asc_dvc->cfg->cmd_qng_enabled & asc_dvc->cfg->disc_enable) !=
12012         asc_dvc->cfg->cmd_qng_enabled) {
12013         asc_dvc->cfg->disc_enable = asc_dvc->cfg->cmd_qng_enabled;
12014         warn_code |= ASC_WARN_CMD_QNG_CONFLICT;
12015     }
12016     if (AscGetChipStatus(iop_base) & CSW_AUTO_CONFIG) {
12017         warn_code |= ASC_WARN_AUTO_CONFIG;
12018     }
12019     if ((asc_dvc->bus_type & (ASC_IS_ISA | ASC_IS_VL)) != 0) {
12020         if (AscSetChipIRQ(iop_base, asc_dvc->irq_no, asc_dvc->bus_type)
12021             != asc_dvc->irq_no) {
12022             asc_dvc->err_code |= ASC_IERR_SET_IRQ_NO;
12023         }
12024     }
12025     if (asc_dvc->bus_type & ASC_IS_PCI) {
12026         cfg_msw &= 0xFFC0;
12027         AscSetChipCfgMsw(iop_base, cfg_msw);
12028         if ((asc_dvc->bus_type & ASC_IS_PCI_ULTRA) == ASC_IS_PCI_ULTRA) {
12029         } else {
12030             if ((pci_device_id == PCI_DEVICE_ID_ASP_1200A) ||
12031                 (pci_device_id == PCI_DEVICE_ID_ASP_ABP940)) {
12032                 asc_dvc->bug_fix_cntl |= ASC_BUG_FIX_IF_NOT_DWB;
12033                 asc_dvc->bug_fix_cntl |= ASC_BUG_FIX_ASYN_USE_SYN;
12034             }
12035         }
12036     } else if (asc_dvc->bus_type == ASC_IS_ISAPNP) {
12037         if (AscGetChipVersion(iop_base, asc_dvc->bus_type)
12038             == ASC_CHIP_VER_ASYN_BUG) {
12039             asc_dvc->bug_fix_cntl |= ASC_BUG_FIX_ASYN_USE_SYN;
12040         }
12041     }
12042     if (AscSetChipScsiID(iop_base, asc_dvc->cfg->chip_scsi_id) !=
12043         asc_dvc->cfg->chip_scsi_id) {
12044         asc_dvc->err_code |= ASC_IERR_SET_SCSI_ID;
12045     }
12046 #ifdef CONFIG_ISA
12047     if (asc_dvc->bus_type & ASC_IS_ISA) {
12048         AscSetIsaDmaChannel(iop_base, asc_dvc->cfg->isa_dma_channel);
12049         AscSetIsaDmaSpeed(iop_base, asc_dvc->cfg->isa_dma_speed);
12050     }
12051 #endif /* CONFIG_ISA */
12052     return (warn_code);
12053 }
12054
12055 STATIC ushort
12056 AscInitAsc1000Driver(
12057                         ASC_DVC_VAR *asc_dvc
12058 )
12059 {
12060     ushort              warn_code;
12061     PortAddr            iop_base;
12062
12063     iop_base = asc_dvc->iop_base;
12064     warn_code = 0;
12065     if ((asc_dvc->dvc_cntl & ASC_CNTL_RESET_SCSI) &&
12066         !(asc_dvc->init_state & ASC_INIT_RESET_SCSI_DONE)) {
12067         AscResetChipAndScsiBus(asc_dvc);
12068         DvcSleepMilliSecond((ASC_DCNT)
12069             ((ushort) asc_dvc->scsi_reset_wait * 1000));
12070     }
12071     asc_dvc->init_state |= ASC_INIT_STATE_BEG_LOAD_MC;
12072     if (asc_dvc->err_code != 0)
12073         return (UW_ERR);
12074     if (!AscFindSignature(asc_dvc->iop_base)) {
12075         asc_dvc->err_code = ASC_IERR_BAD_SIGNATURE;
12076         return (warn_code);
12077     }
12078     AscDisableInterrupt(iop_base);
12079     warn_code |= AscInitLram(asc_dvc);
12080     if (asc_dvc->err_code != 0)
12081         return (UW_ERR);
12082     ASC_DBG1(1, "AscInitAsc1000Driver: _asc_mcode_chksum 0x%lx\n",
12083         (ulong) _asc_mcode_chksum);
12084     if (AscLoadMicroCode(iop_base, 0, _asc_mcode_buf,
12085                          _asc_mcode_size) != _asc_mcode_chksum) {
12086         asc_dvc->err_code |= ASC_IERR_MCODE_CHKSUM;
12087         return (warn_code);
12088     }
12089     warn_code |= AscInitMicroCodeVar(asc_dvc);
12090     asc_dvc->init_state |= ASC_INIT_STATE_END_LOAD_MC;
12091     AscEnableInterrupt(iop_base);
12092     return (warn_code);
12093 }
12094
12095 STATIC ushort __init
12096 AscInitAscDvcVar(
12097                     ASC_DVC_VAR *asc_dvc)
12098 {
12099     int                 i;
12100     PortAddr            iop_base;
12101     ushort              warn_code;
12102     uchar               chip_version;
12103
12104     iop_base = asc_dvc->iop_base;
12105     warn_code = 0;
12106     asc_dvc->err_code = 0;
12107     if ((asc_dvc->bus_type &
12108          (ASC_IS_ISA | ASC_IS_PCI | ASC_IS_EISA | ASC_IS_VL)) == 0) {
12109         asc_dvc->err_code |= ASC_IERR_NO_BUS_TYPE;
12110     }
12111     AscSetChipControl(iop_base, CC_HALT);
12112     AscSetChipStatus(iop_base, 0);
12113     asc_dvc->bug_fix_cntl = 0;
12114     asc_dvc->pci_fix_asyn_xfer = 0;
12115     asc_dvc->pci_fix_asyn_xfer_always = 0;
12116     /* asc_dvc->init_state initalized in AscInitGetConfig(). */
12117     asc_dvc->sdtr_done = 0;
12118     asc_dvc->cur_total_qng = 0;
12119     asc_dvc->is_in_int = 0;
12120     asc_dvc->in_critical_cnt = 0;
12121     asc_dvc->last_q_shortage = 0;
12122     asc_dvc->use_tagged_qng = 0;
12123     asc_dvc->no_scam = 0;
12124     asc_dvc->unit_not_ready = 0;
12125     asc_dvc->queue_full_or_busy = 0;
12126     asc_dvc->redo_scam = 0;
12127     asc_dvc->res2 = 0;
12128     asc_dvc->host_init_sdtr_index = 0;
12129     asc_dvc->cfg->can_tagged_qng = 0;
12130     asc_dvc->cfg->cmd_qng_enabled = 0;
12131     asc_dvc->dvc_cntl = ASC_DEF_DVC_CNTL;
12132     asc_dvc->init_sdtr = 0;
12133     asc_dvc->max_total_qng = ASC_DEF_MAX_TOTAL_QNG;
12134     asc_dvc->scsi_reset_wait = 3;
12135     asc_dvc->start_motor = ASC_SCSI_WIDTH_BIT_SET;
12136     asc_dvc->max_dma_count = AscGetMaxDmaCount(asc_dvc->bus_type);
12137     asc_dvc->cfg->sdtr_enable = ASC_SCSI_WIDTH_BIT_SET;
12138     asc_dvc->cfg->disc_enable = ASC_SCSI_WIDTH_BIT_SET;
12139     asc_dvc->cfg->chip_scsi_id = ASC_DEF_CHIP_SCSI_ID;
12140     asc_dvc->cfg->lib_serial_no = ASC_LIB_SERIAL_NUMBER;
12141     asc_dvc->cfg->lib_version = (ASC_LIB_VERSION_MAJOR << 8) |
12142       ASC_LIB_VERSION_MINOR;
12143     chip_version = AscGetChipVersion(iop_base, asc_dvc->bus_type);
12144     asc_dvc->cfg->chip_version = chip_version;
12145     asc_dvc->sdtr_period_tbl[0] = SYN_XFER_NS_0;
12146     asc_dvc->sdtr_period_tbl[1] = SYN_XFER_NS_1;
12147     asc_dvc->sdtr_period_tbl[2] = SYN_XFER_NS_2;
12148     asc_dvc->sdtr_period_tbl[3] = SYN_XFER_NS_3;
12149     asc_dvc->sdtr_period_tbl[4] = SYN_XFER_NS_4;
12150     asc_dvc->sdtr_period_tbl[5] = SYN_XFER_NS_5;
12151     asc_dvc->sdtr_period_tbl[6] = SYN_XFER_NS_6;
12152     asc_dvc->sdtr_period_tbl[7] = SYN_XFER_NS_7;
12153     asc_dvc->max_sdtr_index = 7;
12154     if ((asc_dvc->bus_type & ASC_IS_PCI) &&
12155         (chip_version >= ASC_CHIP_VER_PCI_ULTRA_3150)) {
12156         asc_dvc->bus_type = ASC_IS_PCI_ULTRA;
12157         asc_dvc->sdtr_period_tbl[0] = SYN_ULTRA_XFER_NS_0;
12158         asc_dvc->sdtr_period_tbl[1] = SYN_ULTRA_XFER_NS_1;
12159         asc_dvc->sdtr_period_tbl[2] = SYN_ULTRA_XFER_NS_2;
12160         asc_dvc->sdtr_period_tbl[3] = SYN_ULTRA_XFER_NS_3;
12161         asc_dvc->sdtr_period_tbl[4] = SYN_ULTRA_XFER_NS_4;
12162         asc_dvc->sdtr_period_tbl[5] = SYN_ULTRA_XFER_NS_5;
12163         asc_dvc->sdtr_period_tbl[6] = SYN_ULTRA_XFER_NS_6;
12164         asc_dvc->sdtr_period_tbl[7] = SYN_ULTRA_XFER_NS_7;
12165         asc_dvc->sdtr_period_tbl[8] = SYN_ULTRA_XFER_NS_8;
12166         asc_dvc->sdtr_period_tbl[9] = SYN_ULTRA_XFER_NS_9;
12167         asc_dvc->sdtr_period_tbl[10] = SYN_ULTRA_XFER_NS_10;
12168         asc_dvc->sdtr_period_tbl[11] = SYN_ULTRA_XFER_NS_11;
12169         asc_dvc->sdtr_period_tbl[12] = SYN_ULTRA_XFER_NS_12;
12170         asc_dvc->sdtr_period_tbl[13] = SYN_ULTRA_XFER_NS_13;
12171         asc_dvc->sdtr_period_tbl[14] = SYN_ULTRA_XFER_NS_14;
12172         asc_dvc->sdtr_period_tbl[15] = SYN_ULTRA_XFER_NS_15;
12173         asc_dvc->max_sdtr_index = 15;
12174         if (chip_version == ASC_CHIP_VER_PCI_ULTRA_3150)
12175         {
12176             AscSetExtraControl(iop_base,
12177                 (SEC_ACTIVE_NEGATE | SEC_SLEW_RATE));
12178         } else if (chip_version >= ASC_CHIP_VER_PCI_ULTRA_3050) {
12179             AscSetExtraControl(iop_base,
12180                 (SEC_ACTIVE_NEGATE | SEC_ENABLE_FILTER));
12181         }
12182     }
12183     if (asc_dvc->bus_type == ASC_IS_PCI) {
12184            AscSetExtraControl(iop_base, (SEC_ACTIVE_NEGATE | SEC_SLEW_RATE));
12185     }
12186
12187     asc_dvc->cfg->isa_dma_speed = ASC_DEF_ISA_DMA_SPEED;
12188     if (AscGetChipBusType(iop_base) == ASC_IS_ISAPNP) {
12189         AscSetChipIFC(iop_base, IFC_INIT_DEFAULT);
12190         asc_dvc->bus_type = ASC_IS_ISAPNP;
12191     }
12192 #ifdef CONFIG_ISA
12193     if ((asc_dvc->bus_type & ASC_IS_ISA) != 0) {
12194         asc_dvc->cfg->isa_dma_channel = (uchar) AscGetIsaDmaChannel(iop_base);
12195     }
12196 #endif /* CONFIG_ISA */
12197     for (i = 0; i <= ASC_MAX_TID; i++) {
12198         asc_dvc->cur_dvc_qng[i] = 0;
12199         asc_dvc->max_dvc_qng[i] = ASC_MAX_SCSI1_QNG;
12200         asc_dvc->scsiq_busy_head[i] = (ASC_SCSI_Q *) 0L;
12201         asc_dvc->scsiq_busy_tail[i] = (ASC_SCSI_Q *) 0L;
12202         asc_dvc->cfg->max_tag_qng[i] = ASC_MAX_INRAM_TAG_QNG;
12203     }
12204     return (warn_code);
12205 }
12206
12207 STATIC ushort __init
12208 AscInitFromEEP(ASC_DVC_VAR *asc_dvc)
12209 {
12210     ASCEEP_CONFIG       eep_config_buf;
12211     ASCEEP_CONFIG       *eep_config;
12212     PortAddr            iop_base;
12213     ushort              chksum;
12214     ushort              warn_code;
12215     ushort              cfg_msw, cfg_lsw;
12216     int                 i;
12217     int                 write_eep = 0;
12218
12219     iop_base = asc_dvc->iop_base;
12220     warn_code = 0;
12221     AscWriteLramWord(iop_base, ASCV_HALTCODE_W, 0x00FE);
12222     AscStopQueueExe(iop_base);
12223     if ((AscStopChip(iop_base) == FALSE) ||
12224         (AscGetChipScsiCtrl(iop_base) != 0)) {
12225         asc_dvc->init_state |= ASC_INIT_RESET_SCSI_DONE;
12226         AscResetChipAndScsiBus(asc_dvc);
12227         DvcSleepMilliSecond((ASC_DCNT)
12228             ((ushort) asc_dvc->scsi_reset_wait * 1000));
12229     }
12230     if (AscIsChipHalted(iop_base) == FALSE) {
12231         asc_dvc->err_code |= ASC_IERR_START_STOP_CHIP;
12232         return (warn_code);
12233     }
12234     AscSetPCAddr(iop_base, ASC_MCODE_START_ADDR);
12235     if (AscGetPCAddr(iop_base) != ASC_MCODE_START_ADDR) {
12236         asc_dvc->err_code |= ASC_IERR_SET_PC_ADDR;
12237         return (warn_code);
12238     }
12239     eep_config = (ASCEEP_CONFIG *) &eep_config_buf;
12240     cfg_msw = AscGetChipCfgMsw(iop_base);
12241     cfg_lsw = AscGetChipCfgLsw(iop_base);
12242     if ((cfg_msw & ASC_CFG_MSW_CLR_MASK) != 0) {
12243         cfg_msw &= (~(ASC_CFG_MSW_CLR_MASK));
12244         warn_code |= ASC_WARN_CFG_MSW_RECOVER;
12245         AscSetChipCfgMsw(iop_base, cfg_msw);
12246     }
12247     chksum = AscGetEEPConfig(iop_base, eep_config, asc_dvc->bus_type);
12248     ASC_DBG1(1, "AscInitFromEEP: chksum 0x%x\n", chksum);
12249     if (chksum == 0) {
12250         chksum = 0xaa55;
12251     }
12252     if (AscGetChipStatus(iop_base) & CSW_AUTO_CONFIG) {
12253         warn_code |= ASC_WARN_AUTO_CONFIG;
12254         if (asc_dvc->cfg->chip_version == 3) {
12255             if (eep_config->cfg_lsw != cfg_lsw) {
12256                 warn_code |= ASC_WARN_EEPROM_RECOVER;
12257                 eep_config->cfg_lsw = AscGetChipCfgLsw(iop_base);
12258             }
12259             if (eep_config->cfg_msw != cfg_msw) {
12260                 warn_code |= ASC_WARN_EEPROM_RECOVER;
12261                 eep_config->cfg_msw = AscGetChipCfgMsw(iop_base);
12262             }
12263         }
12264     }
12265     eep_config->cfg_msw &= ~ASC_CFG_MSW_CLR_MASK;
12266     eep_config->cfg_lsw |= ASC_CFG0_HOST_INT_ON;
12267     ASC_DBG1(1, "AscInitFromEEP: eep_config->chksum 0x%x\n",
12268         eep_config->chksum);
12269     if (chksum != eep_config->chksum) {
12270             if (AscGetChipVersion(iop_base, asc_dvc->bus_type) ==
12271                     ASC_CHIP_VER_PCI_ULTRA_3050 )
12272             {
12273                 ASC_DBG(1,
12274 "AscInitFromEEP: chksum error ignored; EEPROM-less board\n");
12275                 eep_config->init_sdtr = 0xFF;
12276                 eep_config->disc_enable = 0xFF;
12277                 eep_config->start_motor = 0xFF;
12278                 eep_config->use_cmd_qng = 0;
12279                 eep_config->max_total_qng = 0xF0;
12280                 eep_config->max_tag_qng = 0x20;
12281                 eep_config->cntl = 0xBFFF;
12282                 ASC_EEP_SET_CHIP_ID(eep_config, 7);
12283                 eep_config->no_scam = 0;
12284                 eep_config->adapter_info[0] = 0;
12285                 eep_config->adapter_info[1] = 0;
12286                 eep_config->adapter_info[2] = 0;
12287                 eep_config->adapter_info[3] = 0;
12288                 eep_config->adapter_info[4] = 0;
12289                 /* Indicate EEPROM-less board. */
12290                 eep_config->adapter_info[5] = 0xBB;
12291             } else {
12292                 ASC_PRINT(
12293 "AscInitFromEEP: EEPROM checksum error; Will try to re-write EEPROM.\n");
12294                 write_eep = 1;
12295                 warn_code |= ASC_WARN_EEPROM_CHKSUM;
12296             }
12297     }
12298     asc_dvc->cfg->sdtr_enable = eep_config->init_sdtr;
12299     asc_dvc->cfg->disc_enable = eep_config->disc_enable;
12300     asc_dvc->cfg->cmd_qng_enabled = eep_config->use_cmd_qng;
12301     asc_dvc->cfg->isa_dma_speed = ASC_EEP_GET_DMA_SPD(eep_config);
12302     asc_dvc->start_motor = eep_config->start_motor;
12303     asc_dvc->dvc_cntl = eep_config->cntl;
12304     asc_dvc->no_scam = eep_config->no_scam;
12305     asc_dvc->cfg->adapter_info[0] = eep_config->adapter_info[0];
12306     asc_dvc->cfg->adapter_info[1] = eep_config->adapter_info[1];
12307     asc_dvc->cfg->adapter_info[2] = eep_config->adapter_info[2];
12308     asc_dvc->cfg->adapter_info[3] = eep_config->adapter_info[3];
12309     asc_dvc->cfg->adapter_info[4] = eep_config->adapter_info[4];
12310     asc_dvc->cfg->adapter_info[5] = eep_config->adapter_info[5];
12311     if (!AscTestExternalLram(asc_dvc)) {
12312         if (((asc_dvc->bus_type & ASC_IS_PCI_ULTRA) == ASC_IS_PCI_ULTRA)) {
12313             eep_config->max_total_qng = ASC_MAX_PCI_ULTRA_INRAM_TOTAL_QNG;
12314             eep_config->max_tag_qng = ASC_MAX_PCI_ULTRA_INRAM_TAG_QNG;
12315         } else {
12316             eep_config->cfg_msw |= 0x0800;
12317             cfg_msw |= 0x0800;
12318             AscSetChipCfgMsw(iop_base, cfg_msw);
12319             eep_config->max_total_qng = ASC_MAX_PCI_INRAM_TOTAL_QNG;
12320             eep_config->max_tag_qng = ASC_MAX_INRAM_TAG_QNG;
12321         }
12322     } else {
12323     }
12324     if (eep_config->max_total_qng < ASC_MIN_TOTAL_QNG) {
12325         eep_config->max_total_qng = ASC_MIN_TOTAL_QNG;
12326     }
12327     if (eep_config->max_total_qng > ASC_MAX_TOTAL_QNG) {
12328         eep_config->max_total_qng = ASC_MAX_TOTAL_QNG;
12329     }
12330     if (eep_config->max_tag_qng > eep_config->max_total_qng) {
12331         eep_config->max_tag_qng = eep_config->max_total_qng;
12332     }
12333     if (eep_config->max_tag_qng < ASC_MIN_TAG_Q_PER_DVC) {
12334         eep_config->max_tag_qng = ASC_MIN_TAG_Q_PER_DVC;
12335     }
12336     asc_dvc->max_total_qng = eep_config->max_total_qng;
12337     if ((eep_config->use_cmd_qng & eep_config->disc_enable) !=
12338         eep_config->use_cmd_qng) {
12339         eep_config->disc_enable = eep_config->use_cmd_qng;
12340         warn_code |= ASC_WARN_CMD_QNG_CONFLICT;
12341     }
12342     if (asc_dvc->bus_type & (ASC_IS_ISA | ASC_IS_VL | ASC_IS_EISA)) {
12343         asc_dvc->irq_no = AscGetChipIRQ(iop_base, asc_dvc->bus_type);
12344     }
12345     ASC_EEP_SET_CHIP_ID(eep_config, ASC_EEP_GET_CHIP_ID(eep_config) & ASC_MAX_TID);
12346     asc_dvc->cfg->chip_scsi_id = ASC_EEP_GET_CHIP_ID(eep_config);
12347     if (((asc_dvc->bus_type & ASC_IS_PCI_ULTRA) == ASC_IS_PCI_ULTRA) &&
12348         !(asc_dvc->dvc_cntl & ASC_CNTL_SDTR_ENABLE_ULTRA)) {
12349         asc_dvc->host_init_sdtr_index = ASC_SDTR_ULTRA_PCI_10MB_INDEX;
12350     }
12351
12352     for (i = 0; i <= ASC_MAX_TID; i++) {
12353         asc_dvc->dos_int13_table[i] = eep_config->dos_int13_table[i];
12354         asc_dvc->cfg->max_tag_qng[i] = eep_config->max_tag_qng;
12355         asc_dvc->cfg->sdtr_period_offset[i] =
12356             (uchar) (ASC_DEF_SDTR_OFFSET |
12357                      (asc_dvc->host_init_sdtr_index << 4));
12358     }
12359     eep_config->cfg_msw = AscGetChipCfgMsw(iop_base);
12360     if (write_eep) {
12361         if ((i = AscSetEEPConfig(iop_base, eep_config, asc_dvc->bus_type)) !=
12362              0) {
12363                 ASC_PRINT1(
12364 "AscInitFromEEP: Failed to re-write EEPROM with %d errors.\n", i);
12365         } else {
12366                 ASC_PRINT("AscInitFromEEP: Succesfully re-wrote EEPROM.");
12367         }
12368     }
12369     return (warn_code);
12370 }
12371
12372 STATIC ushort
12373 AscInitMicroCodeVar(
12374                        ASC_DVC_VAR *asc_dvc
12375 )
12376 {
12377     int                 i;
12378     ushort              warn_code;
12379     PortAddr            iop_base;
12380     ASC_PADDR           phy_addr;
12381     ASC_DCNT            phy_size;
12382
12383     iop_base = asc_dvc->iop_base;
12384     warn_code = 0;
12385     for (i = 0; i <= ASC_MAX_TID; i++) {
12386         AscPutMCodeInitSDTRAtID(iop_base, i,
12387                                 asc_dvc->cfg->sdtr_period_offset[i]
12388 );
12389     }
12390
12391     AscInitQLinkVar(asc_dvc);
12392     AscWriteLramByte(iop_base, ASCV_DISC_ENABLE_B,
12393                      asc_dvc->cfg->disc_enable);
12394     AscWriteLramByte(iop_base, ASCV_HOSTSCSI_ID_B,
12395                      ASC_TID_TO_TARGET_ID(asc_dvc->cfg->chip_scsi_id));
12396
12397     /* Align overrun buffer on an 8 byte boundary. */
12398     phy_addr = virt_to_bus(asc_dvc->cfg->overrun_buf);
12399     phy_addr = cpu_to_le32((phy_addr + 7) & ~0x7);
12400     AscMemDWordCopyPtrToLram(iop_base, ASCV_OVERRUN_PADDR_D,
12401         (uchar *) &phy_addr, 1);
12402     phy_size = cpu_to_le32(ASC_OVERRUN_BSIZE - 8);
12403     AscMemDWordCopyPtrToLram(iop_base, ASCV_OVERRUN_BSIZE_D,
12404         (uchar *) &phy_size, 1);
12405
12406     asc_dvc->cfg->mcode_date =
12407         AscReadLramWord(iop_base, (ushort) ASCV_MC_DATE_W);
12408     asc_dvc->cfg->mcode_version =
12409         AscReadLramWord(iop_base, (ushort) ASCV_MC_VER_W);
12410
12411     AscSetPCAddr(iop_base, ASC_MCODE_START_ADDR);
12412     if (AscGetPCAddr(iop_base) != ASC_MCODE_START_ADDR) {
12413         asc_dvc->err_code |= ASC_IERR_SET_PC_ADDR;
12414         return (warn_code);
12415     }
12416     if (AscStartChip(iop_base) != 1) {
12417         asc_dvc->err_code |= ASC_IERR_START_STOP_CHIP;
12418         return (warn_code);
12419     }
12420
12421     return (warn_code);
12422 }
12423
12424 STATIC int __init
12425 AscTestExternalLram(
12426                        ASC_DVC_VAR *asc_dvc)
12427 {
12428     PortAddr            iop_base;
12429     ushort              q_addr;
12430     ushort              saved_word;
12431     int                 sta;
12432
12433     iop_base = asc_dvc->iop_base;
12434     sta = 0;
12435     q_addr = ASC_QNO_TO_QADDR(241);
12436     saved_word = AscReadLramWord(iop_base, q_addr);
12437     AscSetChipLramAddr(iop_base, q_addr);
12438     AscSetChipLramData(iop_base, 0x55AA);
12439     DvcSleepMilliSecond(10);
12440     AscSetChipLramAddr(iop_base, q_addr);
12441     if (AscGetChipLramData(iop_base) == 0x55AA) {
12442         sta = 1;
12443         AscWriteLramWord(iop_base, q_addr, saved_word);
12444     }
12445     return (sta);
12446 }
12447
12448 STATIC int __init
12449 AscWriteEEPCmdReg(
12450                      PortAddr iop_base,
12451                      uchar cmd_reg
12452 )
12453 {
12454     uchar               read_back;
12455     int                 retry;
12456
12457     retry = 0;
12458     while (TRUE) {
12459         AscSetChipEEPCmd(iop_base, cmd_reg);
12460         DvcSleepMilliSecond(1);
12461         read_back = AscGetChipEEPCmd(iop_base);
12462         if (read_back == cmd_reg) {
12463             return (1);
12464         }
12465         if (retry++ > ASC_EEP_MAX_RETRY) {
12466             return (0);
12467         }
12468     }
12469 }
12470
12471 STATIC int __init
12472 AscWriteEEPDataReg(
12473                       PortAddr iop_base,
12474                       ushort data_reg
12475 )
12476 {
12477     ushort              read_back;
12478     int                 retry;
12479
12480     retry = 0;
12481     while (TRUE) {
12482         AscSetChipEEPData(iop_base, data_reg);
12483         DvcSleepMilliSecond(1);
12484         read_back = AscGetChipEEPData(iop_base);
12485         if (read_back == data_reg) {
12486             return (1);
12487         }
12488         if (retry++ > ASC_EEP_MAX_RETRY) {
12489             return (0);
12490         }
12491     }
12492 }
12493
12494 STATIC void __init
12495 AscWaitEEPRead(void)
12496 {
12497     DvcSleepMilliSecond(1);
12498     return;
12499 }
12500
12501 STATIC void __init
12502 AscWaitEEPWrite(void)
12503 {
12504     DvcSleepMilliSecond(20);
12505     return;
12506 }
12507
12508 STATIC ushort __init
12509 AscReadEEPWord(
12510                   PortAddr iop_base,
12511                   uchar addr)
12512 {
12513     ushort              read_wval;
12514     uchar               cmd_reg;
12515
12516     AscWriteEEPCmdReg(iop_base, ASC_EEP_CMD_WRITE_DISABLE);
12517     AscWaitEEPRead();
12518     cmd_reg = addr | ASC_EEP_CMD_READ;
12519     AscWriteEEPCmdReg(iop_base, cmd_reg);
12520     AscWaitEEPRead();
12521     read_wval = AscGetChipEEPData(iop_base);
12522     AscWaitEEPRead();
12523     return (read_wval);
12524 }
12525
12526 STATIC ushort __init
12527 AscWriteEEPWord(
12528                    PortAddr iop_base,
12529                    uchar addr,
12530                    ushort word_val)
12531 {
12532     ushort              read_wval;
12533
12534     read_wval = AscReadEEPWord(iop_base, addr);
12535     if (read_wval != word_val) {
12536         AscWriteEEPCmdReg(iop_base, ASC_EEP_CMD_WRITE_ABLE);
12537         AscWaitEEPRead();
12538         AscWriteEEPDataReg(iop_base, word_val);
12539         AscWaitEEPRead();
12540         AscWriteEEPCmdReg(iop_base,
12541                           (uchar) ((uchar) ASC_EEP_CMD_WRITE | addr));
12542         AscWaitEEPWrite();
12543         AscWriteEEPCmdReg(iop_base, ASC_EEP_CMD_WRITE_DISABLE);
12544         AscWaitEEPRead();
12545         return (AscReadEEPWord(iop_base, addr));
12546     }
12547     return (read_wval);
12548 }
12549
12550 STATIC ushort __init
12551 AscGetEEPConfig(
12552                    PortAddr iop_base,
12553                    ASCEEP_CONFIG * cfg_buf, ushort bus_type)
12554 {
12555     ushort              wval;
12556     ushort              sum;
12557     ushort              *wbuf;
12558     int                 cfg_beg;
12559     int                 cfg_end;
12560     int                 uchar_end_in_config = ASC_EEP_MAX_DVC_ADDR - 2;
12561     int                 s_addr;
12562
12563     wbuf = (ushort *) cfg_buf;
12564     sum = 0;
12565     /* Read two config words; Byte-swapping done by AscReadEEPWord(). */
12566     for (s_addr = 0; s_addr < 2; s_addr++, wbuf++) {
12567         *wbuf = AscReadEEPWord(iop_base, (uchar) s_addr);
12568         sum += *wbuf;
12569     }
12570     if (bus_type & ASC_IS_VL) {
12571         cfg_beg = ASC_EEP_DVC_CFG_BEG_VL;
12572         cfg_end = ASC_EEP_MAX_DVC_ADDR_VL;
12573     } else {
12574         cfg_beg = ASC_EEP_DVC_CFG_BEG;
12575         cfg_end = ASC_EEP_MAX_DVC_ADDR;
12576     }
12577     for (s_addr = cfg_beg; s_addr <= (cfg_end - 1); s_addr++, wbuf++) {
12578         wval = AscReadEEPWord( iop_base, ( uchar )s_addr ) ;
12579         if (s_addr <= uchar_end_in_config) {
12580             /*
12581              * Swap all char fields - must unswap bytes already swapped
12582              * by AscReadEEPWord().
12583              */
12584             *wbuf = le16_to_cpu(wval);
12585         } else {
12586             /* Don't swap word field at the end - cntl field. */
12587             *wbuf = wval;
12588         }
12589         sum += wval; /* Checksum treats all EEPROM data as words. */
12590     }
12591     /*
12592      * Read the checksum word which will be compared against 'sum'
12593      * by the caller. Word field already swapped.
12594      */
12595     *wbuf = AscReadEEPWord(iop_base, (uchar) s_addr);
12596     return (sum);
12597 }
12598
12599 STATIC int __init
12600 AscSetEEPConfigOnce(
12601                        PortAddr iop_base,
12602                        ASCEEP_CONFIG * cfg_buf, ushort bus_type)
12603 {
12604     int                 n_error;
12605     ushort              *wbuf;
12606     ushort              word;
12607     ushort              sum;
12608     int                 s_addr;
12609     int                 cfg_beg;
12610     int                 cfg_end;
12611     int                 uchar_end_in_config = ASC_EEP_MAX_DVC_ADDR - 2;
12612
12613
12614     wbuf = (ushort *) cfg_buf;
12615     n_error = 0;
12616     sum = 0;
12617     /* Write two config words; AscWriteEEPWord() will swap bytes. */
12618     for (s_addr = 0; s_addr < 2; s_addr++, wbuf++) {
12619         sum += *wbuf;
12620         if (*wbuf != AscWriteEEPWord(iop_base, (uchar) s_addr, *wbuf)) {
12621             n_error++;
12622         }
12623     }
12624     if (bus_type & ASC_IS_VL) {
12625         cfg_beg = ASC_EEP_DVC_CFG_BEG_VL;
12626         cfg_end = ASC_EEP_MAX_DVC_ADDR_VL;
12627     } else {
12628         cfg_beg = ASC_EEP_DVC_CFG_BEG;
12629         cfg_end = ASC_EEP_MAX_DVC_ADDR;
12630     }
12631     for (s_addr = cfg_beg; s_addr <= (cfg_end - 1); s_addr++, wbuf++) {
12632         if (s_addr <= uchar_end_in_config) {
12633             /*
12634              * This is a char field. Swap char fields before they are
12635              * swapped again by AscWriteEEPWord().
12636              */
12637             word = cpu_to_le16(*wbuf);
12638             if (word != AscWriteEEPWord( iop_base, (uchar) s_addr, word)) {
12639                 n_error++;
12640             }
12641         } else {
12642             /* Don't swap word field at the end - cntl field. */
12643             if (*wbuf != AscWriteEEPWord(iop_base, (uchar) s_addr, *wbuf)) {
12644                 n_error++;
12645             }
12646         }
12647         sum += *wbuf; /* Checksum calculated from word values. */
12648     }
12649     /* Write checksum word. It will be swapped by AscWriteEEPWord(). */
12650     *wbuf = sum;
12651     if (sum != AscWriteEEPWord(iop_base, (uchar) s_addr, sum)) {
12652         n_error++;
12653     }
12654
12655     /* Read EEPROM back again. */
12656     wbuf = (ushort *) cfg_buf;
12657     /*
12658      * Read two config words; Byte-swapping done by AscReadEEPWord().
12659      */
12660     for (s_addr = 0; s_addr < 2; s_addr++, wbuf++) {
12661         if (*wbuf != AscReadEEPWord(iop_base, (uchar) s_addr)) {
12662             n_error++;
12663         }
12664     }
12665     if (bus_type & ASC_IS_VL) {
12666         cfg_beg = ASC_EEP_DVC_CFG_BEG_VL;
12667         cfg_end = ASC_EEP_MAX_DVC_ADDR_VL;
12668     } else {
12669         cfg_beg = ASC_EEP_DVC_CFG_BEG;
12670         cfg_end = ASC_EEP_MAX_DVC_ADDR;
12671     }
12672     for (s_addr = cfg_beg; s_addr <= (cfg_end - 1); s_addr++, wbuf++) {
12673         if (s_addr <= uchar_end_in_config) {
12674             /*
12675              * Swap all char fields. Must unswap bytes already swapped
12676              * by AscReadEEPWord().
12677              */
12678             word = le16_to_cpu(AscReadEEPWord(iop_base, (uchar) s_addr));
12679         } else {
12680             /* Don't swap word field at the end - cntl field. */
12681             word = AscReadEEPWord(iop_base, (uchar) s_addr);
12682         }
12683         if (*wbuf != word) {
12684             n_error++;
12685         }
12686     }
12687     /* Read checksum; Byte swapping not needed. */
12688     if (AscReadEEPWord(iop_base, (uchar) s_addr) != sum) {
12689         n_error++;
12690     }
12691     return (n_error);
12692 }
12693
12694 STATIC int __init
12695 AscSetEEPConfig(
12696                    PortAddr iop_base,
12697                    ASCEEP_CONFIG * cfg_buf, ushort bus_type
12698 )
12699 {
12700     int            retry;
12701     int            n_error;
12702
12703     retry = 0;
12704     while (TRUE) {
12705         if ((n_error = AscSetEEPConfigOnce(iop_base, cfg_buf,
12706                                            bus_type)) == 0) {
12707             break;
12708         }
12709         if (++retry > ASC_EEP_MAX_RETRY) {
12710             break;
12711         }
12712     }
12713     return (n_error);
12714 }
12715
12716 STATIC void
12717 AscAsyncFix(
12718                ASC_DVC_VAR *asc_dvc,
12719                uchar tid_no,
12720                ASC_SCSI_INQUIRY *inq)
12721 {
12722     uchar                       dvc_type;
12723     ASC_SCSI_BIT_ID_TYPE        tid_bits;
12724
12725     dvc_type = ASC_INQ_DVC_TYPE(inq);
12726     tid_bits = ASC_TIX_TO_TARGET_ID(tid_no);
12727
12728     if (asc_dvc->bug_fix_cntl & ASC_BUG_FIX_ASYN_USE_SYN)
12729     {
12730         if (!(asc_dvc->init_sdtr & tid_bits))
12731         {
12732             if ((dvc_type == TYPE_ROM) &&
12733                 (AscCompareString((uchar *) inq->vendor_id,
12734                     (uchar *) "HP ", 3) == 0))
12735             {
12736                 asc_dvc->pci_fix_asyn_xfer_always |= tid_bits;
12737             }
12738             asc_dvc->pci_fix_asyn_xfer |= tid_bits;
12739             if ((dvc_type == TYPE_PROCESSOR) ||
12740                 (dvc_type == TYPE_SCANNER) ||
12741                 (dvc_type == TYPE_ROM) ||
12742                 (dvc_type == TYPE_TAPE))
12743             {
12744                 asc_dvc->pci_fix_asyn_xfer &= ~tid_bits;
12745             }
12746
12747             if (asc_dvc->pci_fix_asyn_xfer & tid_bits)
12748             {
12749                 AscSetRunChipSynRegAtID(asc_dvc->iop_base, tid_no,
12750                     ASYN_SDTR_DATA_FIX_PCI_REV_AB);
12751             }
12752         }
12753     }
12754     return;
12755 }
12756
12757 STATIC int
12758 AscTagQueuingSafe(ASC_SCSI_INQUIRY *inq)
12759 {
12760     if ((inq->add_len >= 32) &&
12761         (AscCompareString((uchar *) inq->vendor_id,
12762             (uchar *) "QUANTUM XP34301", 15) == 0) &&
12763         (AscCompareString((uchar *) inq->product_rev_level,
12764             (uchar *) "1071", 4) == 0))
12765     {
12766         return 0;
12767     }
12768     return 1;
12769 }
12770
12771 STATIC void
12772 AscInquiryHandling(ASC_DVC_VAR *asc_dvc,
12773                    uchar tid_no, ASC_SCSI_INQUIRY *inq)
12774 {
12775     ASC_SCSI_BIT_ID_TYPE tid_bit = ASC_TIX_TO_TARGET_ID(tid_no);
12776     ASC_SCSI_BIT_ID_TYPE orig_init_sdtr, orig_use_tagged_qng;
12777
12778     orig_init_sdtr = asc_dvc->init_sdtr;
12779     orig_use_tagged_qng = asc_dvc->use_tagged_qng;
12780
12781     asc_dvc->init_sdtr &= ~tid_bit;
12782     asc_dvc->cfg->can_tagged_qng &= ~tid_bit;
12783     asc_dvc->use_tagged_qng &= ~tid_bit;
12784
12785     if (ASC_INQ_RESPONSE_FMT(inq) >= 2 || ASC_INQ_ANSI_VER(inq) >= 2) {
12786         if ((asc_dvc->cfg->sdtr_enable & tid_bit) && ASC_INQ_SYNC(inq)) {
12787             asc_dvc->init_sdtr |= tid_bit;
12788         }
12789         if ((asc_dvc->cfg->cmd_qng_enabled & tid_bit) &&
12790              ASC_INQ_CMD_QUEUE(inq)) {
12791             if (AscTagQueuingSafe(inq)) {
12792                 asc_dvc->use_tagged_qng |= tid_bit;
12793                 asc_dvc->cfg->can_tagged_qng |= tid_bit;
12794             }
12795         }
12796     }
12797     if (orig_use_tagged_qng != asc_dvc->use_tagged_qng) {
12798         AscWriteLramByte(asc_dvc->iop_base, ASCV_DISC_ENABLE_B,
12799                          asc_dvc->cfg->disc_enable);
12800         AscWriteLramByte(asc_dvc->iop_base, ASCV_USE_TAGGED_QNG_B,
12801                          asc_dvc->use_tagged_qng);
12802         AscWriteLramByte(asc_dvc->iop_base, ASCV_CAN_TAGGED_QNG_B,
12803                          asc_dvc->cfg->can_tagged_qng);
12804
12805         asc_dvc->max_dvc_qng[tid_no] =
12806           asc_dvc->cfg->max_tag_qng[tid_no];
12807         AscWriteLramByte(asc_dvc->iop_base,
12808                          (ushort) (ASCV_MAX_DVC_QNG_BEG + tid_no),
12809                          asc_dvc->max_dvc_qng[tid_no]);
12810     }
12811     if (orig_init_sdtr != asc_dvc->init_sdtr) {
12812         AscAsyncFix(asc_dvc, tid_no, inq);
12813     }
12814     return;
12815 }
12816
12817 STATIC int
12818 AscCompareString(
12819                     uchar *str1,
12820                     uchar *str2,
12821                     int len
12822 )
12823 {
12824     int                 i;
12825     int                 diff;
12826
12827     for (i = 0; i < len; i++) {
12828         diff = (int) (str1[i] - str2[i]);
12829         if (diff != 0)
12830             return (diff);
12831     }
12832     return (0);
12833 }
12834
12835 STATIC uchar
12836 AscReadLramByte(
12837                    PortAddr iop_base,
12838                    ushort addr
12839 )
12840 {
12841     uchar               byte_data;
12842     ushort              word_data;
12843
12844     if (isodd_word(addr)) {
12845         AscSetChipLramAddr(iop_base, addr - 1);
12846         word_data = AscGetChipLramData(iop_base);
12847         byte_data = (uchar) ((word_data >> 8) & 0xFF);
12848     } else {
12849         AscSetChipLramAddr(iop_base, addr);
12850         word_data = AscGetChipLramData(iop_base);
12851         byte_data = (uchar) (word_data & 0xFF);
12852     }
12853     return (byte_data);
12854 }
12855 STATIC ushort
12856 AscReadLramWord(
12857                    PortAddr iop_base,
12858                    ushort addr
12859 )
12860 {
12861     ushort              word_data;
12862
12863     AscSetChipLramAddr(iop_base, addr);
12864     word_data = AscGetChipLramData(iop_base);
12865     return (word_data);
12866 }
12867
12868 #if CC_VERY_LONG_SG_LIST
12869 STATIC ASC_DCNT
12870 AscReadLramDWord(
12871                     PortAddr iop_base,
12872                     ushort addr
12873 )
12874 {
12875     ushort              val_low, val_high;
12876     ASC_DCNT            dword_data;
12877
12878     AscSetChipLramAddr(iop_base, addr);
12879     val_low = AscGetChipLramData(iop_base);
12880     val_high = AscGetChipLramData(iop_base);
12881     dword_data = ((ASC_DCNT) val_high << 16) | (ASC_DCNT) val_low;
12882     return (dword_data);
12883 }
12884 #endif /* CC_VERY_LONG_SG_LIST */
12885
12886 STATIC void
12887 AscWriteLramWord(
12888                     PortAddr iop_base,
12889                     ushort addr,
12890                     ushort word_val
12891 )
12892 {
12893     AscSetChipLramAddr(iop_base, addr);
12894     AscSetChipLramData(iop_base, word_val);
12895     return;
12896 }
12897
12898 STATIC void
12899 AscWriteLramByte(
12900                     PortAddr iop_base,
12901                     ushort addr,
12902                     uchar byte_val
12903 )
12904 {
12905     ushort              word_data;
12906
12907     if (isodd_word(addr)) {
12908         addr--;
12909         word_data = AscReadLramWord(iop_base, addr);
12910         word_data &= 0x00FF;
12911         word_data |= (((ushort) byte_val << 8) & 0xFF00);
12912     } else {
12913         word_data = AscReadLramWord(iop_base, addr);
12914         word_data &= 0xFF00;
12915         word_data |= ((ushort) byte_val & 0x00FF);
12916     }
12917     AscWriteLramWord(iop_base, addr, word_data);
12918     return;
12919 }
12920
12921 /*
12922  * Copy 2 bytes to LRAM.
12923  *
12924  * The source data is assumed to be in little-endian order in memory
12925  * and is maintained in little-endian order when written to LRAM.
12926  */
12927 STATIC void
12928 AscMemWordCopyPtrToLram(
12929                         PortAddr iop_base,
12930                         ushort s_addr,
12931                         uchar *s_buffer,
12932                         int words
12933 )
12934 {
12935     int    i;
12936
12937     AscSetChipLramAddr(iop_base, s_addr);
12938     for (i = 0; i < 2 * words; i += 2) {
12939         /*
12940          * On a little-endian system the second argument below
12941          * produces a little-endian ushort which is written to
12942          * LRAM in little-endian order. On a big-endian system
12943          * the second argument produces a big-endian ushort which
12944          * is "transparently" byte-swapped by outpw() and written
12945          * in little-endian order to LRAM.
12946          */
12947         outpw(iop_base + IOP_RAM_DATA,
12948             ((ushort) s_buffer[i + 1] << 8) | s_buffer[i]);
12949     }
12950     return;
12951 }
12952
12953 /*
12954  * Copy 4 bytes to LRAM.
12955  *
12956  * The source data is assumed to be in little-endian order in memory
12957  * and is maintained in little-endian order when writen to LRAM.
12958  */
12959 STATIC void
12960 AscMemDWordCopyPtrToLram(
12961                          PortAddr iop_base,
12962                          ushort s_addr,
12963                          uchar *s_buffer,
12964                          int dwords
12965 )
12966 {
12967     int       i;
12968
12969     AscSetChipLramAddr(iop_base, s_addr);
12970     for (i = 0; i < 4 * dwords; i += 4) {
12971         outpw(iop_base + IOP_RAM_DATA,
12972             ((ushort) s_buffer[i + 1] << 8) | s_buffer[i]); /* LSW */
12973         outpw(iop_base + IOP_RAM_DATA,
12974             ((ushort) s_buffer[i + 3] << 8) | s_buffer[i + 2]); /* MSW */
12975     }
12976     return;
12977 }
12978
12979 /*
12980  * Copy 2 bytes from LRAM.
12981  *
12982  * The source data is assumed to be in little-endian order in LRAM
12983  * and is maintained in little-endian order when written to memory.
12984  */
12985 STATIC void
12986 AscMemWordCopyPtrFromLram(
12987                           PortAddr iop_base,
12988                           ushort s_addr,
12989                           uchar *d_buffer,
12990                           int words
12991 )
12992 {
12993     int i;
12994     ushort word;
12995
12996     AscSetChipLramAddr(iop_base, s_addr);
12997     for (i = 0; i < 2 * words; i += 2) {
12998         word = inpw(iop_base + IOP_RAM_DATA);
12999         d_buffer[i] = word & 0xff;
13000         d_buffer[i + 1] = (word >> 8) & 0xff;
13001     }
13002     return;
13003 }
13004
13005 STATIC ASC_DCNT
13006 AscMemSumLramWord(
13007                      PortAddr iop_base,
13008                      ushort s_addr,
13009                      int words
13010 )
13011 {
13012     ASC_DCNT         sum;
13013     int              i;
13014
13015     sum = 0L;
13016     for (i = 0; i < words; i++, s_addr += 2) {
13017         sum += AscReadLramWord(iop_base, s_addr);
13018     }
13019     return (sum);
13020 }
13021
13022 STATIC void
13023 AscMemWordSetLram(
13024                      PortAddr iop_base,
13025                      ushort s_addr,
13026                      ushort set_wval,
13027                      int words
13028 )
13029 {
13030     int             i;
13031
13032     AscSetChipLramAddr(iop_base, s_addr);
13033     for (i = 0; i < words; i++) {
13034         AscSetChipLramData(iop_base, set_wval);
13035     }
13036     return;
13037 }
13038
13039
13040 /*
13041  * --- Adv Library Functions
13042  */
13043
13044 /* a_mcode.h */
13045
13046 /* Microcode buffer is kept after initialization for error recovery. */
13047 STATIC unsigned char _adv_asc3550_buf[] = {
13048   0x00,  0x00,  0x00,  0xf2,  0x00,  0xf0,  0x00,  0x16,  0x18,  0xe4,  0x00,  0xfc,  0x01,  0x00,  0x48,  0xe4,
13049   0xbe,  0x18,  0x18,  0x80,  0x03,  0xf6,  0x02,  0x00,  0x00,  0xfa,  0xff,  0xff,  0x28,  0x0e,  0x9e,  0xe7,
13050   0xff,  0x00,  0x82,  0xe7,  0x00,  0xea,  0x00,  0xf6,  0x01,  0xe6,  0x09,  0xe7,  0x55,  0xf0,  0x01,  0xf6,
13051   0x01,  0xfa,  0x08,  0x00,  0x03,  0x00,  0x04,  0x00,  0x18,  0xf4,  0x10,  0x00,  0x00,  0xec,  0x85,  0xf0,
13052   0xbc,  0x00,  0xd5,  0xf0,  0x8e,  0x0c,  0x38,  0x54,  0x00,  0xe6,  0x1e,  0xf0,  0x86,  0xf0,  0xb4,  0x00,
13053   0x98,  0x57,  0xd0,  0x01,  0x0c,  0x1c,  0x3e,  0x1c,  0x0c,  0x00,  0xbb,  0x00,  0xaa,  0x18,  0x02,  0x80,
13054   0x32,  0xf0,  0x01,  0xfc,  0x88,  0x0c,  0xc6,  0x12,  0x02,  0x13,  0x18,  0x40,  0x00,  0x57,  0x01,  0xea,
13055   0x3c,  0x00,  0x6c,  0x01,  0x6e,  0x01,  0x04,  0x12,  0x3e,  0x57,  0x00,  0x80,  0x03,  0xe6,  0xb6,  0x00,
13056   0xc0,  0x00,  0x01,  0x01,  0x3e,  0x01,  0xda,  0x0f,  0x22,  0x10,  0x08,  0x12,  0x02,  0x4a,  0xb9,  0x54,
13057   0x03,  0x58,  0x1b,  0x80,  0x30,  0xe4,  0x4b,  0xe4,  0x20,  0x00,  0x32,  0x00,  0x3e,  0x00,  0x80,  0x00,
13058   0x24,  0x01,  0x3c,  0x01,  0x68,  0x01,  0x6a,  0x01,  0x70,  0x01,  0x72,  0x01,  0x74,  0x01,  0x76,  0x01,
13059   0x78,  0x01,  0x62,  0x0a,  0x92,  0x0c,  0x2c,  0x10,  0x2e,  0x10,  0x06,  0x13,  0x4c,  0x1c,  0xbb,  0x55,
13060   0x3c,  0x56,  0x04,  0x80,  0x4a,  0xe4,  0x02,  0xee,  0x5b,  0xf0,  0xb1,  0xf0,  0x03,  0xf7,  0x06,  0xf7,
13061   0x03,  0xfc,  0x0f,  0x00,  0x40,  0x00,  0xbe,  0x00,  0x00,  0x01,  0xb0,  0x08,  0x30,  0x13,  0x64,  0x15,
13062   0x32,  0x1c,  0x38,  0x1c,  0x4e,  0x1c,  0x10,  0x44,  0x02,  0x48,  0x00,  0x4c,  0x04,  0xea,  0x5d,  0xf0,
13063   0x04,  0xf6,  0x02,  0xfc,  0x05,  0x00,  0x34,  0x00,  0x36,  0x00,  0x98,  0x00,  0xcc,  0x00,  0x20,  0x01,
13064   0x4e,  0x01,  0x4e,  0x0b,  0x1e,  0x0e,  0x0c,  0x10,  0x0a,  0x12,  0x04,  0x13,  0x40,  0x13,  0x30,  0x1c,
13065   0x00,  0x4e,  0xbd,  0x56,  0x06,  0x83,  0x00,  0xdc,  0x05,  0xf0,  0x09,  0xf0,  0x59,  0xf0,  0xa7,  0xf0,
13066   0xb8,  0xf0,  0x0e,  0xf7,  0x06,  0x00,  0x19,  0x00,  0x33,  0x00,  0x9b,  0x00,  0xa4,  0x00,  0xb5,  0x00,
13067   0xba,  0x00,  0xd0,  0x00,  0xe1,  0x00,  0xe7,  0x00,  0xde,  0x03,  0x56,  0x0a,  0x14,  0x0e,  0x02,  0x10,
13068   0x04,  0x10,  0x0a,  0x10,  0x36,  0x10,  0x0a,  0x13,  0x12,  0x13,  0x52,  0x13,  0x10,  0x15,  0x14,  0x15,
13069   0xac,  0x16,  0x20,  0x1c,  0x34,  0x1c,  0x36,  0x1c,  0x08,  0x44,  0x38,  0x44,  0x91,  0x44,  0x0a,  0x45,
13070   0x48,  0x46,  0x01,  0x48,  0x68,  0x54,  0x83,  0x55,  0xb0,  0x57,  0x01,  0x58,  0x83,  0x59,  0x05,  0xe6,
13071   0x0b,  0xf0,  0x0c,  0xf0,  0x5c,  0xf0,  0x4b,  0xf4,  0x04,  0xf8,  0x05,  0xf8,  0x02,  0xfa,  0x03,  0xfa,
13072   0x04,  0xfc,  0x05,  0xfc,  0x07,  0x00,  0x0a,  0x00,  0x0d,  0x00,  0x1c,  0x00,  0x9e,  0x00,  0xa8,  0x00,
13073   0xaa,  0x00,  0xb9,  0x00,  0xe0,  0x00,  0x22,  0x01,  0x26,  0x01,  0x79,  0x01,  0x7a,  0x01,  0xc0,  0x01,
13074   0xc2,  0x01,  0x7c,  0x02,  0x5a,  0x03,  0xea,  0x04,  0xe8,  0x07,  0x68,  0x08,  0x69,  0x08,  0xba,  0x08,
13075   0xe9,  0x09,  0x06,  0x0b,  0x3a,  0x0e,  0x00,  0x10,  0x1a,  0x10,  0xed,  0x10,  0xf1,  0x10,  0x06,  0x12,
13076   0x0c,  0x13,  0x16,  0x13,  0x1e,  0x13,  0x82,  0x13,  0x42,  0x14,  0xd6,  0x14,  0x8a,  0x15,  0xc6,  0x17,
13077   0xd2,  0x17,  0x6b,  0x18,  0x12,  0x1c,  0x46,  0x1c,  0x9c,  0x32,  0x00,  0x40,  0x0e,  0x47,  0x48,  0x47,
13078   0x41,  0x48,  0x89,  0x48,  0x80,  0x4c,  0x00,  0x54,  0x44,  0x55,  0xe5,  0x55,  0x14,  0x56,  0x77,  0x57,
13079   0xbf,  0x57,  0x40,  0x5c,  0x06,  0x80,  0x08,  0x90,  0x03,  0xa1,  0xfe,  0x9c,  0xf0,  0x29,  0x02,  0xfe,
13080   0xb8,  0x0c,  0xff,  0x10,  0x00,  0x00,  0xd0,  0xfe,  0xcc,  0x18,  0x00,  0xcf,  0xfe,  0x80,  0x01,  0xff,
13081   0x03,  0x00,  0x00,  0xfe,  0x93,  0x15,  0xfe,  0x0f,  0x05,  0xff,  0x38,  0x00,  0x00,  0xfe,  0x57,  0x24,
13082   0x00,  0xfe,  0x48,  0x00,  0x4f,  0xff,  0x04,  0x00,  0x00,  0x10,  0xff,  0x09,  0x00,  0x00,  0xff,  0x08,
13083   0x01,  0x01,  0xff,  0x08,  0xff,  0xff,  0xff,  0x27,  0x00,  0x00,  0xff,  0x10,  0xff,  0xff,  0xff,  0x0f,
13084   0x00,  0x00,  0xfe,  0x78,  0x56,  0xfe,  0x34,  0x12,  0xff,  0x21,  0x00,  0x00,  0xfe,  0x04,  0xf7,  0xcf,
13085   0x2a,  0x67,  0x0b,  0x01,  0xfe,  0xce,  0x0e,  0xfe,  0x04,  0xf7,  0xcf,  0x67,  0x0b,  0x3c,  0x2a,  0xfe,
13086   0x3d,  0xf0,  0xfe,  0x02,  0x02,  0xfe,  0x20,  0xf0,  0x9c,  0xfe,  0x91,  0xf0,  0xfe,  0xf0,  0x01,  0xfe,
13087   0x90,  0xf0,  0xfe,  0xf0,  0x01,  0xfe,  0x8f,  0xf0,  0x9c,  0x05,  0x51,  0x3b,  0x02,  0xfe,  0xd4,  0x0c,
13088   0x01,  0xfe,  0x44,  0x0d,  0xfe,  0xdd,  0x12,  0xfe,  0xfc,  0x10,  0xfe,  0x28,  0x1c,  0x05,  0xfe,  0xa6,
13089   0x00,  0xfe,  0xd3,  0x12,  0x47,  0x18,  0xfe,  0xa6,  0x00,  0xb5,  0xfe,  0x48,  0xf0,  0xfe,  0x86,  0x02,
13090   0xfe,  0x49,  0xf0,  0xfe,  0xa0,  0x02,  0xfe,  0x4a,  0xf0,  0xfe,  0xbe,  0x02,  0xfe,  0x46,  0xf0,  0xfe,
13091   0x50,  0x02,  0xfe,  0x47,  0xf0,  0xfe,  0x56,  0x02,  0xfe,  0x43,  0xf0,  0xfe,  0x44,  0x02,  0xfe,  0x44,
13092   0xf0,  0xfe,  0x48,  0x02,  0xfe,  0x45,  0xf0,  0xfe,  0x4c,  0x02,  0x17,  0x0b,  0xa0,  0x17,  0x06,  0x18,
13093   0x96,  0x02,  0x29,  0xfe,  0x00,  0x1c,  0xde,  0xfe,  0x02,  0x1c,  0xdd,  0xfe,  0x1e,  0x1c,  0xfe,  0xe9,
13094   0x10,  0x01,  0xfe,  0x20,  0x17,  0xfe,  0xe7,  0x10,  0xfe,  0x06,  0xfc,  0xc7,  0x0a,  0x6b,  0x01,  0x9e,
13095   0x02,  0x29,  0x14,  0x4d,  0x37,  0x97,  0x01,  0xfe,  0x64,  0x0f,  0x0a,  0x6b,  0x01,  0x82,  0xfe,  0xbd,
13096   0x10,  0x0a,  0x6b,  0x01,  0x82,  0xfe,  0xad,  0x10,  0xfe,  0x16,  0x1c,  0xfe,  0x58,  0x1c,  0x17,  0x06,
13097   0x18,  0x96,  0x2a,  0x25,  0x29,  0xfe,  0x3d,  0xf0,  0xfe,  0x02,  0x02,  0x21,  0xfe,  0x94,  0x02,  0xfe,
13098   0x5a,  0x1c,  0xea,  0xfe,  0x14,  0x1c,  0x14,  0xfe,  0x30,  0x00,  0x37,  0x97,  0x01,  0xfe,  0x54,  0x0f,
13099   0x17,  0x06,  0x18,  0x96,  0x02,  0xd0,  0x1e,  0x20,  0x07,  0x10,  0x34,  0xfe,  0x69,  0x10,  0x17,  0x06,
13100   0x18,  0x96,  0xfe,  0x04,  0xec,  0x20,  0x46,  0x3d,  0x12,  0x20,  0xfe,  0x05,  0xf6,  0xc7,  0x01,  0xfe,
13101   0x52,  0x16,  0x09,  0x4a,  0x4c,  0x35,  0x11,  0x2d,  0x3c,  0x8a,  0x01,  0xe6,  0x02,  0x29,  0x0a,  0x40,
13102   0x01,  0x0e,  0x07,  0x00,  0x5d,  0x01,  0x6f,  0xfe,  0x18,  0x10,  0xfe,  0x41,  0x58,  0x0a,  0x99,  0x01,
13103   0x0e,  0xfe,  0xc8,  0x54,  0x64,  0xfe,  0x0c,  0x03,  0x01,  0xe6,  0x02,  0x29,  0x2a,  0x46,  0xfe,  0x02,
13104   0xe8,  0x27,  0xf8,  0xfe,  0x9e,  0x43,  0xf7,  0xfe,  0x27,  0xf0,  0xfe,  0xdc,  0x01,  0xfe,  0x07,  0x4b,
13105   0xfe,  0x20,  0xf0,  0x9c,  0xfe,  0x40,  0x1c,  0x25,  0xd2,  0xfe,  0x26,  0xf0,  0xfe,  0x56,  0x03,  0xfe,
13106   0xa0,  0xf0,  0xfe,  0x44,  0x03,  0xfe,  0x11,  0xf0,  0x9c,  0xfe,  0xef,  0x10,  0xfe,  0x9f,  0xf0,  0xfe,
13107   0x64,  0x03,  0xeb,  0x0f,  0xfe,  0x11,  0x00,  0x02,  0x5a,  0x2a,  0xfe,  0x48,  0x1c,  0xeb,  0x09,  0x04,
13108   0x1d,  0xfe,  0x18,  0x13,  0x23,  0x1e,  0x98,  0xac,  0x12,  0x98,  0x0a,  0x40,  0x01,  0x0e,  0xac,  0x75,
13109   0x01,  0xfe,  0xbc,  0x15,  0x11,  0xca,  0x25,  0xd2,  0xfe,  0x01,  0xf0,  0xd2,  0xfe,  0x82,  0xf0,  0xfe,
13110   0x92,  0x03,  0xec,  0x11,  0xfe,  0xe4,  0x00,  0x65,  0xfe,  0xa4,  0x03,  0x25,  0x32,  0x1f,  0xfe,  0xb4,
13111   0x03,  0x01,  0x43,  0xfe,  0x06,  0xf0,  0xfe,  0xc4,  0x03,  0x8d,  0x81,  0xfe,  0x0a,  0xf0,  0xfe,  0x7a,
13112   0x06,  0x02,  0x22,  0x05,  0x6b,  0x28,  0x16,  0xfe,  0xf6,  0x04,  0x14,  0x2c,  0x01,  0x33,  0x8f,  0xfe,
13113   0x66,  0x02,  0x02,  0xd1,  0xeb,  0x2a,  0x67,  0x1a,  0xfe,  0x67,  0x1b,  0xf8,  0xf7,  0xfe,  0x48,  0x1c,
13114   0x70,  0x01,  0x6e,  0x87,  0x0a,  0x40,  0x01,  0x0e,  0x07,  0x00,  0x16,  0xd3,  0x0a,  0xca,  0x01,  0x0e,
13115   0x74,  0x60,  0x59,  0x76,  0x27,  0x05,  0x6b,  0x28,  0xfe,  0x10,  0x12,  0x14,  0x2c,  0x01,  0x33,  0x8f,
13116   0xfe,  0x66,  0x02,  0x02,  0xd1,  0xbc,  0x7d,  0xbd,  0x7f,  0x25,  0x22,  0x65,  0xfe,  0x3c,  0x04,  0x1f,
13117   0xfe,  0x38,  0x04,  0x68,  0xfe,  0xa0,  0x00,  0xfe,  0x9b,  0x57,  0xfe,  0x4e,  0x12,  0x2b,  0xff,  0x02,
13118   0x00,  0x10,  0x01,  0x08,  0x1f,  0xfe,  0xe0,  0x04,  0x2b,  0x01,  0x08,  0x1f,  0x22,  0x30,  0x2e,  0xd5,
13119   0xfe,  0x4c,  0x44,  0xfe,  0x4c,  0x12,  0x60,  0xfe,  0x44,  0x48,  0x13,  0x2c,  0xfe,  0x4c,  0x54,  0x64,
13120   0xd3,  0x46,  0x76,  0x27,  0xfa,  0xef,  0xfe,  0x62,  0x13,  0x09,  0x04,  0x1d,  0xfe,  0x2a,  0x13,  0x2f,
13121   0x07,  0x7e,  0xa5,  0xfe,  0x20,  0x10,  0x13,  0x2c,  0xfe,  0x4c,  0x54,  0x64,  0xd3,  0xfa,  0xef,  0x86,
13122   0x09,  0x04,  0x1d,  0xfe,  0x08,  0x13,  0x2f,  0x07,  0x7e,  0x6e,  0x09,  0x04,  0x1d,  0xfe,  0x1c,  0x12,
13123   0x14,  0x92,  0x09,  0x04,  0x06,  0x3b,  0x14,  0xc4,  0x01,  0x33,  0x8f,  0xfe,  0x70,  0x0c,  0x02,  0x22,
13124   0x2b,  0x11,  0xfe,  0xe6,  0x00,  0xfe,  0x1c,  0x90,  0xf9,  0x03,  0x14,  0x92,  0x01,  0x33,  0x02,  0x29,
13125   0xfe,  0x42,  0x5b,  0x67,  0x1a,  0xfe,  0x46,  0x59,  0xf8,  0xf7,  0xfe,  0x87,  0x80,  0xfe,  0x31,  0xe4,
13126   0x4f,  0x09,  0x04,  0x0b,  0xfe,  0x78,  0x13,  0xfe,  0x20,  0x80,  0x07,  0x1a,  0xfe,  0x70,  0x12,  0x49,
13127   0x04,  0x06,  0xfe,  0x60,  0x13,  0x05,  0xfe,  0xa2,  0x00,  0x28,  0x16,  0xfe,  0x80,  0x05,  0xfe,  0x31,
13128   0xe4,  0x6a,  0x49,  0x04,  0x0b,  0xfe,  0x4a,  0x13,  0x05,  0xfe,  0xa0,  0x00,  0x28,  0xfe,  0x42,  0x12,
13129   0x5e,  0x01,  0x08,  0x25,  0x32,  0xf1,  0x01,  0x08,  0x26,  0xfe,  0x98,  0x05,  0x11,  0xfe,  0xe3,  0x00,
13130   0x23,  0x49,  0xfe,  0x4a,  0xf0,  0xfe,  0x6a,  0x05,  0xfe,  0x49,  0xf0,  0xfe,  0x64,  0x05,  0x83,  0x24,
13131   0xfe,  0x21,  0x00,  0xa1,  0x24,  0xfe,  0x22,  0x00,  0xa0,  0x24,  0x4c,  0xfe,  0x09,  0x48,  0x01,  0x08,
13132   0x26,  0xfe,  0x98,  0x05,  0xfe,  0xe2,  0x08,  0x49,  0x04,  0xc5,  0x3b,  0x01,  0x86,  0x24,  0x06,  0x12,
13133   0xcc,  0x37,  0xfe,  0x27,  0x01,  0x09,  0x04,  0x1d,  0xfe,  0x22,  0x12,  0x47,  0x01,  0xa7,  0x14,  0x92,
13134   0x09,  0x04,  0x06,  0x3b,  0x14,  0xc4,  0x01,  0x33,  0x8f,  0xfe,  0x70,  0x0c,  0x02,  0x22,  0x05,  0xfe,
13135   0x9c,  0x00,  0x28,  0xfe,  0x3e,  0x12,  0x05,  0x50,  0x28,  0xfe,  0x36,  0x13,  0x47,  0x01,  0xa7,  0x26,
13136   0xfe,  0x08,  0x06,  0x0a,  0x06,  0x49,  0x04,  0x19,  0xfe,  0x02,  0x12,  0x5f,  0x01,  0xfe,  0xaa,  0x14,
13137   0x1f,  0xfe,  0xfe,  0x05,  0x11,  0x9a,  0x01,  0x43,  0x11,  0xfe,  0xe5,  0x00,  0x05,  0x50,  0xb4,  0x0c,
13138   0x50,  0x05,  0xc6,  0x28,  0xfe,  0x62,  0x12,  0x05,  0x3f,  0x28,  0xfe,  0x5a,  0x13,  0x01,  0xfe,  0x14,
13139   0x18,  0x01,  0xfe,  0x66,  0x18,  0xfe,  0x43,  0x48,  0xb7,  0x19,  0x13,  0x6c,  0xff,  0x02,  0x00,  0x57,
13140   0x48,  0x8b,  0x1c,  0x3d,  0x85,  0xb7,  0x69,  0x47,  0x01,  0xa7,  0x26,  0xfe,  0x72,  0x06,  0x49,  0x04,
13141   0x1b,  0xdf,  0x89,  0x0a,  0x4d,  0x01,  0xfe,  0xd8,  0x14,  0x1f,  0xfe,  0x68,  0x06,  0x11,  0x9a,  0x01,
13142   0x43,  0x11,  0xfe,  0xe5,  0x00,  0x05,  0x3f,  0xb4,  0x0c,  0x3f,  0x17,  0x06,  0x01,  0xa7,  0xec,  0x72,
13143   0x70,  0x01,  0x6e,  0x87,  0x11,  0xfe,  0xe2,  0x00,  0x01,  0x08,  0x25,  0x32,  0xfe,  0x0a,  0xf0,  0xfe,
13144   0xa6,  0x06,  0x8c,  0xfe,  0x5c,  0x07,  0xfe,  0x06,  0xf0,  0xfe,  0x64,  0x07,  0x8d,  0x81,  0x02,  0x22,
13145   0x09,  0x04,  0x0b,  0xfe,  0x2e,  0x12,  0x15,  0x1a,  0x01,  0x08,  0x15,  0x00,  0x01,  0x08,  0x15,  0x00,
13146   0x01,  0x08,  0x15,  0x00,  0x01,  0x08,  0xfe,  0x99,  0xa4,  0x01,  0x08,  0x15,  0x00,  0x02,  0xfe,  0x32,
13147   0x08,  0x61,  0x04,  0x1b,  0xfe,  0x38,  0x12,  0x09,  0x04,  0x1b,  0x6e,  0x15,  0xfe,  0x1b,  0x00,  0x01,
13148   0x08,  0x15,  0x00,  0x01,  0x08,  0x15,  0x00,  0x01,  0x08,  0x15,  0x00,  0x01,  0x08,  0x15,  0x06,  0x01,
13149   0x08,  0x15,  0x00,  0x02,  0xd9,  0x66,  0x4c,  0xfe,  0x3a,  0x55,  0x5f,  0xfe,  0x9a,  0x81,  0x4b,  0x1d,
13150   0xba,  0xfe,  0x32,  0x07,  0x0a,  0x1d,  0xfe,  0x09,  0x6f,  0xaf,  0xfe,  0xca,  0x45,  0xfe,  0x32,  0x12,
13151   0x62,  0x2c,  0x85,  0x66,  0x7b,  0x01,  0x08,  0x25,  0x32,  0xfe,  0x0a,  0xf0,  0xfe,  0x32,  0x07,  0x8d,
13152   0x81,  0x8c,  0xfe,  0x5c,  0x07,  0x02,  0x22,  0x01,  0x43,  0x02,  0xfe,  0x8a,  0x06,  0x15,  0x19,  0x02,
13153   0xfe,  0x8a,  0x06,  0xfe,  0x9c,  0xf7,  0xd4,  0xfe,  0x2c,  0x90,  0xfe,  0xae,  0x90,  0x77,  0xfe,  0xca,
13154   0x07,  0x0c,  0x54,  0x18,  0x55,  0x09,  0x4a,  0x6a,  0x35,  0x1e,  0x20,  0x07,  0x10,  0xfe,  0x0e,  0x12,
13155   0x74,  0xfe,  0x80,  0x80,  0x37,  0x20,  0x63,  0x27,  0xfe,  0x06,  0x10,  0xfe,  0x83,  0xe7,  0xc4,  0xa1,
13156   0xfe,  0x03,  0x40,  0x09,  0x4a,  0x4f,  0x35,  0x01,  0xa8,  0xad,  0xfe,  0x1f,  0x40,  0x12,  0x58,  0x01,
13157   0xa5,  0xfe,  0x08,  0x50,  0xfe,  0x8a,  0x50,  0xfe,  0x44,  0x51,  0xfe,  0xc6,  0x51,  0x83,  0xfb,  0xfe,
13158   0x8a,  0x90,  0x0c,  0x52,  0x18,  0x53,  0xfe,  0x0c,  0x90,  0xfe,  0x8e,  0x90,  0xfe,  0x40,  0x50,  0xfe,
13159   0xc2,  0x50,  0x0c,  0x39,  0x18,  0x3a,  0xfe,  0x4a,  0x10,  0x09,  0x04,  0x6a,  0xfe,  0x2a,  0x12,  0xfe,
13160   0x2c,  0x90,  0xfe,  0xae,  0x90,  0x0c,  0x54,  0x18,  0x55,  0x09,  0x04,  0x4f,  0x85,  0x01,  0xa8,  0xfe,
13161   0x1f,  0x80,  0x12,  0x58,  0xfe,  0x44,  0x90,  0xfe,  0xc6,  0x90,  0x0c,  0x56,  0x18,  0x57,  0xfb,  0xfe,
13162   0x8a,  0x90,  0x0c,  0x52,  0x18,  0x53,  0xfe,  0x40,  0x90,  0xfe,  0xc2,  0x90,  0x0c,  0x39,  0x18,  0x3a,
13163   0x0c,  0x38,  0x18,  0x4e,  0x09,  0x4a,  0x19,  0x35,  0x2a,  0x13,  0xfe,  0x4e,  0x11,  0x65,  0xfe,  0x48,
13164   0x08,  0xfe,  0x9e,  0xf0,  0xfe,  0x5c,  0x08,  0xb1,  0x16,  0x32,  0x2a,  0x73,  0xdd,  0xb8,  0xfe,  0x80,
13165   0x08,  0xb9,  0xfe,  0x9e,  0x08,  0x8c,  0xfe,  0x74,  0x08,  0xfe,  0x06,  0xf0,  0xfe,  0x7a,  0x08,  0x8d,
13166   0x81,  0x02,  0x22,  0x01,  0x43,  0xfe,  0xc9,  0x10,  0x15,  0x19,  0xfe,  0xc9,  0x10,  0x61,  0x04,  0x06,
13167   0xfe,  0x10,  0x12,  0x61,  0x04,  0x0b,  0x45,  0x09,  0x04,  0x0b,  0xfe,  0x68,  0x12,  0xfe,  0x2e,  0x1c,
13168   0x02,  0xfe,  0x24,  0x0a,  0x61,  0x04,  0x06,  0x45,  0x61,  0x04,  0x0b,  0xfe,  0x52,  0x12,  0xfe,  0x2c,
13169   0x1c,  0xfe,  0xaa,  0xf0,  0xfe,  0x1e,  0x09,  0xfe,  0xac,  0xf0,  0xfe,  0xbe,  0x08,  0xfe,  0x8a,  0x10,
13170   0xaa,  0xfe,  0xf3,  0x10,  0xfe,  0xad,  0xf0,  0xfe,  0xca,  0x08,  0x02,  0xfe,  0x24,  0x0a,  0xab,  0xfe,
13171   0xe7,  0x10,  0xfe,  0x2b,  0xf0,  0x9d,  0xe9,  0x1c,  0xfe,  0x00,  0xfe,  0xfe,  0x1c,  0x12,  0xb5,  0xfe,
13172   0xd2,  0xf0,  0x9d,  0xfe,  0x76,  0x18,  0x1c,  0x1a,  0x16,  0x9d,  0x05,  0xcb,  0x1c,  0x06,  0x16,  0x9d,
13173   0xb8,  0x6d,  0xb9,  0x6d,  0xaa,  0xab,  0xfe,  0xb1,  0x10,  0x70,  0x5e,  0x2b,  0x14,  0x92,  0x01,  0x33,
13174   0x0f,  0xfe,  0x35,  0x00,  0xfe,  0x01,  0xf0,  0x5a,  0x0f,  0x7c,  0x02,  0x5a,  0xfe,  0x74,  0x18,  0x1c,
13175   0xfe,  0x00,  0xf8,  0x16,  0x6d,  0x67,  0x1b,  0x01,  0xfe,  0x44,  0x0d,  0x3b,  0x01,  0xe6,  0x1e,  0x27,
13176   0x74,  0x67,  0x1a,  0x02,  0x6d,  0x09,  0x04,  0x0b,  0x21,  0xfe,  0x06,  0x0a,  0x09,  0x04,  0x6a,  0xfe,
13177   0x82,  0x12,  0x09,  0x04,  0x19,  0xfe,  0x66,  0x13,  0x1e,  0x58,  0xac,  0xfc,  0xfe,  0x83,  0x80,  0xfe,
13178   0xc8,  0x44,  0xfe,  0x2e,  0x13,  0xfe,  0x04,  0x91,  0xfe,  0x86,  0x91,  0x63,  0x27,  0xfe,  0x40,  0x59,
13179   0xfe,  0xc1,  0x59,  0x77,  0xd7,  0x05,  0x54,  0x31,  0x55,  0x0c,  0x7b,  0x18,  0x7c,  0xbe,  0x54,  0xbf,
13180   0x55,  0x01,  0xa8,  0xad,  0x63,  0x27,  0x12,  0x58,  0xc0,  0x38,  0xc1,  0x4e,  0x79,  0x56,  0x68,  0x57,
13181   0xf4,  0xf5,  0xfe,  0x04,  0xfa,  0x38,  0xfe,  0x05,  0xfa,  0x4e,  0x01,  0xa5,  0xa2,  0x23,  0x0c,  0x7b,
13182   0x0c,  0x7c,  0x79,  0x56,  0x68,  0x57,  0xfe,  0x12,  0x10,  0x09,  0x04,  0x19,  0x16,  0xd7,  0x79,  0x39,
13183   0x68,  0x3a,  0x09,  0x04,  0xfe,  0xf7,  0x00,  0x35,  0x05,  0x52,  0x31,  0x53,  0xfe,  0x10,  0x58,  0xfe,
13184   0x91,  0x58,  0xfe,  0x14,  0x59,  0xfe,  0x95,  0x59,  0x02,  0x6d,  0x09,  0x04,  0x19,  0x16,  0xd7,  0x09,
13185   0x04,  0xfe,  0xf7,  0x00,  0x35,  0xfe,  0x3a,  0x55,  0xfe,  0x19,  0x81,  0x5f,  0xfe,  0x10,  0x90,  0xfe,
13186   0x92,  0x90,  0xfe,  0xd7,  0x10,  0x2f,  0x07,  0x9b,  0x16,  0xfe,  0xc6,  0x08,  0x11,  0x9b,  0x09,  0x04,
13187   0x0b,  0xfe,  0x14,  0x13,  0x05,  0x39,  0x31,  0x3a,  0x77,  0xfe,  0xc6,  0x08,  0xfe,  0x0c,  0x58,  0xfe,
13188   0x8d,  0x58,  0x02,  0x6d,  0x23,  0x47,  0xfe,  0x19,  0x80,  0xde,  0x09,  0x04,  0x0b,  0xfe,  0x1a,  0x12,
13189   0xfe,  0x6c,  0x19,  0xfe,  0x19,  0x41,  0xe9,  0xb5,  0xfe,  0xd1,  0xf0,  0xd9,  0x14,  0x7a,  0x01,  0x33,
13190   0x0f,  0xfe,  0x44,  0x00,  0xfe,  0x8e,  0x10,  0xfe,  0x6c,  0x19,  0xbe,  0x39,  0xfe,  0xed,  0x19,  0xbf,
13191   0x3a,  0xfe,  0x0c,  0x51,  0xfe,  0x8e,  0x51,  0xe9,  0x1c,  0xfe,  0x00,  0xff,  0x34,  0xfe,  0x74,  0x10,
13192   0xb5,  0xfe,  0xd2,  0xf0,  0xfe,  0xb2,  0x0a,  0xfe,  0x76,  0x18,  0x1c,  0x1a,  0x84,  0x05,  0xcb,  0x1c,
13193   0x06,  0xfe,  0x08,  0x13,  0x0f,  0xfe,  0x16,  0x00,  0x02,  0x5a,  0xfe,  0xd1,  0xf0,  0xfe,  0xc4,  0x0a,
13194   0x14,  0x7a,  0x01,  0x33,  0x0f,  0xfe,  0x17,  0x00,  0xfe,  0x42,  0x10,  0xfe,  0xce,  0xf0,  0xfe,  0xca,
13195   0x0a,  0xfe,  0x3c,  0x10,  0xfe,  0xcd,  0xf0,  0xfe,  0xd6,  0x0a,  0x0f,  0xfe,  0x22,  0x00,  0x02,  0x5a,
13196   0xfe,  0xcb,  0xf0,  0xfe,  0xe2,  0x0a,  0x0f,  0xfe,  0x24,  0x00,  0x02,  0x5a,  0xfe,  0xd0,  0xf0,  0xfe,
13197   0xec,  0x0a,  0x0f,  0x93,  0xdc,  0xfe,  0xcf,  0xf0,  0xfe,  0xf6,  0x0a,  0x0f,  0x4c,  0xfe,  0x10,  0x10,
13198   0xfe,  0xcc,  0xf0,  0xd9,  0x61,  0x04,  0x19,  0x3b,  0x0f,  0xfe,  0x12,  0x00,  0x2a,  0x13,  0xfe,  0x4e,
13199   0x11,  0x65,  0xfe,  0x0c,  0x0b,  0xfe,  0x9e,  0xf0,  0xfe,  0x20,  0x0b,  0xb1,  0x16,  0x32,  0x2a,  0x73,
13200   0xdd,  0xb8,  0x22,  0xb9,  0x22,  0x2a,  0xec,  0x65,  0xfe,  0x2c,  0x0b,  0x25,  0x32,  0x8c,  0xfe,  0x48,
13201   0x0b,  0x8d,  0x81,  0xb8,  0xd4,  0xb9,  0xd4,  0x02,  0x22,  0x01,  0x43,  0xfe,  0xdb,  0x10,  0x11,  0xfe,
13202   0xe8,  0x00,  0xaa,  0xab,  0x70,  0xbc,  0x7d,  0xbd,  0x7f,  0xfe,  0x89,  0xf0,  0x22,  0x30,  0x2e,  0xd8,
13203   0xbc,  0x7d,  0xbd,  0x7f,  0x01,  0x08,  0x1f,  0x22,  0x30,  0x2e,  0xd6,  0xb1,  0x45,  0x0f,  0xfe,  0x42,
13204   0x00,  0x02,  0x5a,  0x78,  0x06,  0xfe,  0x81,  0x49,  0x16,  0xfe,  0x38,  0x0c,  0x09,  0x04,  0x0b,  0xfe,
13205   0x44,  0x13,  0x0f,  0x00,  0x4b,  0x0b,  0xfe,  0x54,  0x12,  0x4b,  0xfe,  0x28,  0x00,  0x21,  0xfe,  0xa6,
13206   0x0c,  0x0a,  0x40,  0x01,  0x0e,  0x07,  0x00,  0x5d,  0x3e,  0xfe,  0x28,  0x00,  0xfe,  0xe2,  0x10,  0x01,
13207   0xe7,  0x01,  0xe8,  0x0a,  0x99,  0x01,  0xfe,  0x32,  0x0e,  0x59,  0x11,  0x2d,  0x01,  0x6f,  0x02,  0x29,
13208   0x0f,  0xfe,  0x44,  0x00,  0x4b,  0x0b,  0xdf,  0x3e,  0x0b,  0xfe,  0xb4,  0x10,  0x01,  0x86,  0x3e,  0x0b,
13209   0xfe,  0xaa,  0x10,  0x01,  0x86,  0xfe,  0x19,  0x82,  0xfe,  0x34,  0x46,  0xa3,  0x3e,  0x0b,  0x0f,  0xfe,
13210   0x43,  0x00,  0xfe,  0x96,  0x10,  0x09,  0x4a,  0x0b,  0x35,  0x01,  0xe7,  0x01,  0xe8,  0x59,  0x11,  0x2d,
13211   0x01,  0x6f,  0x67,  0x0b,  0x59,  0x3c,  0x8a,  0x02,  0xfe,  0x2a,  0x03,  0x09,  0x04,  0x0b,  0x84,  0x3e,
13212   0x0b,  0x0f,  0x00,  0xfe,  0x5c,  0x10,  0x61,  0x04,  0x1b,  0xfe,  0x58,  0x12,  0x09,  0x04,  0x1b,  0xfe,
13213   0x50,  0x13,  0xfe,  0x1c,  0x1c,  0xfe,  0x9d,  0xf0,  0xfe,  0x5c,  0x0c,  0xfe,  0x1c,  0x1c,  0xfe,  0x9d,
13214   0xf0,  0xfe,  0x62,  0x0c,  0x09,  0x4a,  0x1b,  0x35,  0xfe,  0xa9,  0x10,  0x0f,  0xfe,  0x15,  0x00,  0xfe,
13215   0x04,  0xe6,  0x0b,  0x5f,  0x5c,  0x0f,  0xfe,  0x13,  0x00,  0xfe,  0x10,  0x10,  0x0f,  0xfe,  0x47,  0x00,
13216   0xa1,  0x0f,  0xfe,  0x41,  0x00,  0xa0,  0x0f,  0xfe,  0x24,  0x00,  0x87,  0xaa,  0xab,  0x70,  0x05,  0x6b,
13217   0x28,  0x21,  0xd1,  0x5f,  0xfe,  0x04,  0xe6,  0x1b,  0xfe,  0x9d,  0x41,  0xfe,  0x1c,  0x42,  0x59,  0x01,
13218   0xda,  0x02,  0x29,  0xea,  0x14,  0x0b,  0x37,  0x95,  0xa9,  0x14,  0xfe,  0x31,  0x00,  0x37,  0x97,  0x01,
13219   0xfe,  0x54,  0x0f,  0x02,  0xd0,  0x3c,  0xfe,  0x06,  0xec,  0xc9,  0xee,  0x3e,  0x1d,  0xfe,  0xce,  0x45,
13220   0x34,  0x3c,  0xfe,  0x06,  0xea,  0xc9,  0xfe,  0x47,  0x4b,  0x89,  0xfe,  0x75,  0x57,  0x05,  0x51,  0xfe,
13221   0x98,  0x56,  0xfe,  0x38,  0x12,  0x0a,  0x42,  0x01,  0x0e,  0xfe,  0x44,  0x48,  0x46,  0x09,  0x04,  0x1d,
13222   0xfe,  0x1a,  0x13,  0x0a,  0x40,  0x01,  0x0e,  0x47,  0xfe,  0x41,  0x58,  0x0a,  0x99,  0x01,  0x0e,  0xfe,
13223   0x49,  0x54,  0x8e,  0xfe,  0x2a,  0x0d,  0x02,  0xfe,  0x2a,  0x03,  0x0a,  0x51,  0xfe,  0xee,  0x14,  0xee,
13224   0x3e,  0x1d,  0xfe,  0xce,  0x45,  0x34,  0x3c,  0xfe,  0xce,  0x47,  0xfe,  0xad,  0x13,  0x02,  0x29,  0x1e,
13225   0x20,  0x07,  0x10,  0xfe,  0x9e,  0x12,  0x23,  0x12,  0x4d,  0x12,  0x94,  0x12,  0xce,  0x1e,  0x2d,  0x47,
13226   0x37,  0x2d,  0xb1,  0xe0,  0xfe,  0xbc,  0xf0,  0xfe,  0xec,  0x0d,  0x13,  0x06,  0x12,  0x4d,  0x01,  0xfe,
13227   0xe2,  0x15,  0x05,  0xfe,  0x38,  0x01,  0x31,  0xfe,  0x3a,  0x01,  0x77,  0xfe,  0xf0,  0x0d,  0xfe,  0x02,
13228   0xec,  0xce,  0x62,  0x00,  0x5d,  0xfe,  0x04,  0xec,  0x20,  0x46,  0xfe,  0x05,  0xf6,  0xfe,  0x34,  0x01,
13229   0x01,  0xfe,  0x52,  0x16,  0xfb,  0xfe,  0x48,  0xf4,  0x0d,  0xfe,  0x18,  0x13,  0xaf,  0xfe,  0x02,  0xea,
13230   0xce,  0x62,  0x7a,  0xfe,  0xc5,  0x13,  0x14,  0x1b,  0x37,  0x95,  0xa9,  0x5c,  0x05,  0xfe,  0x38,  0x01,
13231   0x1c,  0xfe,  0xf0,  0xff,  0x0c,  0xfe,  0x60,  0x01,  0x05,  0xfe,  0x3a,  0x01,  0x0c,  0xfe,  0x62,  0x01,
13232   0x3d,  0x12,  0x20,  0x24,  0x06,  0x12,  0x2d,  0x11,  0x2d,  0x8a,  0x13,  0x06,  0x03,  0x23,  0x03,  0x1e,
13233   0x4d,  0xfe,  0xf7,  0x12,  0x1e,  0x94,  0xac,  0x12,  0x94,  0x07,  0x7a,  0xfe,  0x71,  0x13,  0xfe,  0x24,
13234   0x1c,  0x14,  0x1a,  0x37,  0x95,  0xa9,  0xfe,  0xd9,  0x10,  0xb6,  0xfe,  0x03,  0xdc,  0xfe,  0x73,  0x57,
13235   0xfe,  0x80,  0x5d,  0x03,  0xb6,  0xfe,  0x03,  0xdc,  0xfe,  0x5b,  0x57,  0xfe,  0x80,  0x5d,  0x03,  0xfe,
13236   0x03,  0x57,  0xb6,  0x23,  0xfe,  0x00,  0xcc,  0x03,  0xfe,  0x03,  0x57,  0xb6,  0x75,  0x03,  0x09,  0x04,
13237   0x4c,  0xfe,  0x22,  0x13,  0xfe,  0x1c,  0x80,  0x07,  0x06,  0xfe,  0x1a,  0x13,  0xfe,  0x1e,  0x80,  0xe1,
13238   0xfe,  0x1d,  0x80,  0xa4,  0xfe,  0x0c,  0x90,  0xfe,  0x0e,  0x13,  0xfe,  0x0e,  0x90,  0xa3,  0xfe,  0x3c,
13239   0x90,  0xfe,  0x30,  0xf4,  0x0b,  0xfe,  0x3c,  0x50,  0xa0,  0x01,  0xfe,  0x82,  0x16,  0x2f,  0x07,  0x2d,
13240   0xe0,  0x01,  0xfe,  0xbc,  0x15,  0x09,  0x04,  0x1d,  0x45,  0x01,  0xe7,  0x01,  0xe8,  0x11,  0xfe,  0xe9,
13241   0x00,  0x09,  0x04,  0x4c,  0xfe,  0x2c,  0x13,  0x01,  0xfe,  0x14,  0x16,  0xfe,  0x1e,  0x1c,  0xfe,  0x14,
13242   0x90,  0xfe,  0x96,  0x90,  0x0c,  0xfe,  0x64,  0x01,  0x18,  0xfe,  0x66,  0x01,  0x09,  0x04,  0x4f,  0xfe,
13243   0x12,  0x12,  0xfe,  0x03,  0x80,  0x74,  0xfe,  0x01,  0xec,  0x20,  0xfe,  0x80,  0x40,  0x12,  0x20,  0x63,
13244   0x27,  0x11,  0xc8,  0x59,  0x1e,  0x20,  0xed,  0x76,  0x20,  0x03,  0xfe,  0x08,  0x1c,  0x05,  0xfe,  0xac,
13245   0x00,  0xfe,  0x06,  0x58,  0x05,  0xfe,  0xae,  0x00,  0xfe,  0x07,  0x58,  0x05,  0xfe,  0xb0,  0x00,  0xfe,
13246   0x08,  0x58,  0x05,  0xfe,  0xb2,  0x00,  0xfe,  0x09,  0x58,  0xfe,  0x0a,  0x1c,  0x24,  0x69,  0x12,  0xc9,
13247   0x23,  0x0c,  0x50,  0x0c,  0x3f,  0x13,  0x40,  0x48,  0x5f,  0x17,  0x1d,  0xfe,  0x90,  0x4d,  0xfe,  0x91,
13248   0x54,  0x21,  0xfe,  0x08,  0x0f,  0x3e,  0x10,  0x13,  0x42,  0x48,  0x17,  0x4c,  0xfe,  0x90,  0x4d,  0xfe,
13249   0x91,  0x54,  0x21,  0xfe,  0x1e,  0x0f,  0x24,  0x10,  0x12,  0x20,  0x78,  0x2c,  0x46,  0x1e,  0x20,  0xed,
13250   0x76,  0x20,  0x11,  0xc8,  0xf6,  0xfe,  0xd6,  0xf0,  0xfe,  0x32,  0x0f,  0xea,  0x70,  0xfe,  0x14,  0x1c,
13251   0xfe,  0x10,  0x1c,  0xfe,  0x18,  0x1c,  0x03,  0x3c,  0xfe,  0x0c,  0x14,  0xee,  0xfe,  0x07,  0xe6,  0x1d,
13252   0xfe,  0xce,  0x47,  0xfe,  0xf5,  0x13,  0x03,  0x01,  0x86,  0x78,  0x2c,  0x46,  0xfa,  0xef,  0xfe,  0x42,
13253   0x13,  0x2f,  0x07,  0x2d,  0xfe,  0x34,  0x13,  0x0a,  0x42,  0x01,  0x0e,  0xb0,  0xfe,  0x36,  0x12,  0xf0,
13254   0xfe,  0x45,  0x48,  0x01,  0xe3,  0xfe,  0x00,  0xcc,  0xb0,  0xfe,  0xf3,  0x13,  0x3d,  0x75,  0x07,  0x10,
13255   0xa3,  0x0a,  0x80,  0x01,  0x0e,  0xfe,  0x80,  0x5c,  0x01,  0x6f,  0xfe,  0x0e,  0x10,  0x07,  0x7e,  0x45,
13256   0xf6,  0xfe,  0xd6,  0xf0,  0xfe,  0x6c,  0x0f,  0x03,  0xfe,  0x44,  0x58,  0x74,  0xfe,  0x01,  0xec,  0x97,
13257   0xfe,  0x9e,  0x40,  0xfe,  0x9d,  0xe7,  0x00,  0xfe,  0x9c,  0xe7,  0x1b,  0x76,  0x27,  0x01,  0xda,  0xfe,
13258   0xdd,  0x10,  0x2a,  0xbc,  0x7d,  0xbd,  0x7f,  0x30,  0x2e,  0xd5,  0x07,  0x1b,  0xfe,  0x48,  0x12,  0x07,
13259   0x0b,  0xfe,  0x56,  0x12,  0x07,  0x1a,  0xfe,  0x30,  0x12,  0x07,  0xc2,  0x16,  0xfe,  0x3e,  0x11,  0x07,
13260   0xfe,  0x23,  0x00,  0x16,  0xfe,  0x4a,  0x11,  0x07,  0x06,  0x16,  0xfe,  0xa8,  0x11,  0x07,  0x19,  0xfe,
13261   0x12,  0x12,  0x07,  0x00,  0x16,  0x22,  0x14,  0xc2,  0x01,  0x33,  0x9f,  0x2b,  0x01,  0x08,  0x8c,  0x43,
13262   0x03,  0x2b,  0xfe,  0x62,  0x08,  0x0a,  0xca,  0x01,  0xfe,  0x32,  0x0e,  0x11,  0x7e,  0x02,  0x29,  0x2b,
13263   0x2f,  0x07,  0x9b,  0xfe,  0xd9,  0x13,  0x79,  0x39,  0x68,  0x3a,  0x77,  0xfe,  0xfc,  0x10,  0x09,  0x04,
13264   0x6a,  0xfe,  0x72,  0x12,  0xc0,  0x38,  0xc1,  0x4e,  0xf4,  0xf5,  0x8e,  0xfe,  0xc6,  0x10,  0x1e,  0x58,
13265   0xfe,  0x26,  0x13,  0x05,  0x7b,  0x31,  0x7c,  0x77,  0xfe,  0x82,  0x0c,  0x0c,  0x54,  0x18,  0x55,  0x23,
13266   0x0c,  0x7b,  0x0c,  0x7c,  0x01,  0xa8,  0x24,  0x69,  0x73,  0x12,  0x58,  0x01,  0xa5,  0xc0,  0x38,  0xc1,
13267   0x4e,  0xfe,  0x04,  0x55,  0xfe,  0xa5,  0x55,  0xfe,  0x04,  0xfa,  0x38,  0xfe,  0x05,  0xfa,  0x4e,  0xfe,
13268   0x91,  0x10,  0x05,  0x56,  0x31,  0x57,  0xfe,  0x40,  0x56,  0xfe,  0xe1,  0x56,  0x0c,  0x56,  0x18,  0x57,
13269   0x83,  0xc0,  0x38,  0xc1,  0x4e,  0xf4,  0xf5,  0x05,  0x52,  0x31,  0x53,  0xfe,  0x00,  0x56,  0xfe,  0xa1,
13270   0x56,  0x0c,  0x52,  0x18,  0x53,  0x09,  0x04,  0x6a,  0xfe,  0x1e,  0x12,  0x1e,  0x58,  0xfe,  0x1f,  0x40,
13271   0x05,  0x54,  0x31,  0x55,  0xfe,  0x2c,  0x50,  0xfe,  0xae,  0x50,  0x05,  0x56,  0x31,  0x57,  0xfe,  0x44,
13272   0x50,  0xfe,  0xc6,  0x50,  0x05,  0x52,  0x31,  0x53,  0xfe,  0x08,  0x50,  0xfe,  0x8a,  0x50,  0x05,  0x39,
13273   0x31,  0x3a,  0xfe,  0x40,  0x50,  0xfe,  0xc2,  0x50,  0x02,  0x5c,  0x24,  0x06,  0x12,  0xcd,  0x02,  0x5b,
13274   0x2b,  0x01,  0x08,  0x1f,  0x44,  0x30,  0x2e,  0xd5,  0x07,  0x06,  0x21,  0x44,  0x2f,  0x07,  0x9b,  0x21,
13275   0x5b,  0x01,  0x6e,  0x1c,  0x3d,  0x16,  0x44,  0x09,  0x04,  0x0b,  0xe2,  0x79,  0x39,  0x68,  0x3a,  0xfe,
13276   0x0a,  0x55,  0x34,  0xfe,  0x8b,  0x55,  0xbe,  0x39,  0xbf,  0x3a,  0xfe,  0x0c,  0x51,  0xfe,  0x8e,  0x51,
13277   0x02,  0x5b,  0xfe,  0x19,  0x81,  0xaf,  0xfe,  0x19,  0x41,  0x02,  0x5b,  0x2b,  0x01,  0x08,  0x25,  0x32,
13278   0x1f,  0xa2,  0x30,  0x2e,  0xd8,  0x4b,  0x1a,  0xfe,  0xa6,  0x12,  0x4b,  0x0b,  0x3b,  0x02,  0x44,  0x01,
13279   0x08,  0x25,  0x32,  0x1f,  0xa2,  0x30,  0x2e,  0xd6,  0x07,  0x1a,  0x21,  0x44,  0x01,  0x08,  0x1f,  0xa2,
13280   0x30,  0x2e,  0xfe,  0xe8,  0x09,  0xfe,  0xc2,  0x49,  0x60,  0x05,  0xfe,  0x9c,  0x00,  0x28,  0x84,  0x49,
13281   0x04,  0x19,  0x34,  0x9f,  0xfe,  0xbb,  0x45,  0x4b,  0x00,  0x45,  0x3e,  0x06,  0x78,  0x3d,  0xfe,  0xda,
13282   0x14,  0x01,  0x6e,  0x87,  0xfe,  0x4b,  0x45,  0xe2,  0x2f,  0x07,  0x9a,  0xe1,  0x05,  0xc6,  0x28,  0x84,
13283   0x05,  0x3f,  0x28,  0x34,  0x5e,  0x02,  0x5b,  0xfe,  0xc0,  0x5d,  0xfe,  0xf8,  0x14,  0xfe,  0x03,  0x17,
13284   0x05,  0x50,  0xb4,  0x0c,  0x50,  0x5e,  0x2b,  0x01,  0x08,  0x26,  0x5c,  0x01,  0xfe,  0xaa,  0x14,  0x02,
13285   0x5c,  0x01,  0x08,  0x25,  0x32,  0x1f,  0x44,  0x30,  0x2e,  0xd6,  0x07,  0x06,  0x21,  0x44,  0x01,  0xfe,
13286   0x8e,  0x13,  0xfe,  0x42,  0x58,  0xfe,  0x82,  0x14,  0xfe,  0xa4,  0x14,  0x87,  0xfe,  0x4a,  0xf4,  0x0b,
13287   0x16,  0x44,  0xfe,  0x4a,  0xf4,  0x06,  0xfe,  0x0c,  0x12,  0x2f,  0x07,  0x9a,  0x85,  0x02,  0x5b,  0x05,
13288   0x3f,  0xb4,  0x0c,  0x3f,  0x5e,  0x2b,  0x01,  0x08,  0x26,  0x5c,  0x01,  0xfe,  0xd8,  0x14,  0x02,  0x5c,
13289   0x13,  0x06,  0x65,  0xfe,  0xca,  0x12,  0x26,  0xfe,  0xe0,  0x12,  0x72,  0xf1,  0x01,  0x08,  0x23,  0x72,
13290   0x03,  0x8f,  0xfe,  0xdc,  0x12,  0x25,  0xfe,  0xdc,  0x12,  0x1f,  0xfe,  0xca,  0x12,  0x5e,  0x2b,  0x01,
13291   0x08,  0xfe,  0xd5,  0x10,  0x13,  0x6c,  0xff,  0x02,  0x00,  0x57,  0x48,  0x8b,  0x1c,  0xfe,  0xff,  0x7f,
13292   0xfe,  0x30,  0x56,  0xfe,  0x00,  0x5c,  0x03,  0x13,  0x6c,  0xff,  0x02,  0x00,  0x57,  0x48,  0x8b,  0x1c,
13293   0x3d,  0xfe,  0x30,  0x56,  0xfe,  0x00,  0x5c,  0x03,  0x13,  0x6c,  0xff,  0x02,  0x00,  0x57,  0x48,  0x8b,
13294   0x03,  0x13,  0x6c,  0xff,  0x02,  0x00,  0x57,  0x48,  0x8b,  0xfe,  0x0b,  0x58,  0x03,  0x0a,  0x50,  0x01,
13295   0x82,  0x0a,  0x3f,  0x01,  0x82,  0x03,  0xfc,  0x1c,  0x10,  0xff,  0x03,  0x00,  0x54,  0xfe,  0x00,  0xf4,
13296   0x19,  0x48,  0xfe,  0x00,  0x7d,  0xfe,  0x01,  0x7d,  0xfe,  0x02,  0x7d,  0xfe,  0x03,  0x7c,  0x63,  0x27,
13297   0x0c,  0x52,  0x18,  0x53,  0xbe,  0x56,  0xbf,  0x57,  0x03,  0xfe,  0x62,  0x08,  0xfe,  0x82,  0x4a,  0xfe,
13298   0xe1,  0x1a,  0xfe,  0x83,  0x5a,  0x74,  0x03,  0x01,  0xfe,  0x14,  0x18,  0xfe,  0x42,  0x48,  0x5f,  0x60,
13299   0x89,  0x01,  0x08,  0x1f,  0xfe,  0xa2,  0x14,  0x30,  0x2e,  0xd8,  0x01,  0x08,  0x1f,  0xfe,  0xa2,  0x14,
13300   0x30,  0x2e,  0xfe,  0xe8,  0x0a,  0xfe,  0xc1,  0x59,  0x05,  0xc6,  0x28,  0xfe,  0xcc,  0x12,  0x49,  0x04,
13301   0x1b,  0xfe,  0xc4,  0x13,  0x23,  0x62,  0x1b,  0xe2,  0x4b,  0xc3,  0x64,  0xfe,  0xe8,  0x13,  0x3b,  0x13,
13302   0x06,  0x17,  0xc3,  0x78,  0xdb,  0xfe,  0x78,  0x10,  0xff,  0x02,  0x83,  0x55,  0xa1,  0xff,  0x02,  0x83,
13303   0x55,  0x62,  0x1a,  0xa4,  0xbb,  0xfe,  0x30,  0x00,  0x8e,  0xe4,  0x17,  0x2c,  0x13,  0x06,  0xfe,  0x56,
13304   0x10,  0x62,  0x0b,  0xe1,  0xbb,  0xfe,  0x64,  0x00,  0x8e,  0xe4,  0x0a,  0xfe,  0x64,  0x00,  0x17,  0x93,
13305   0x13,  0x06,  0xfe,  0x28,  0x10,  0x62,  0x06,  0xfe,  0x60,  0x13,  0xbb,  0xfe,  0xc8,  0x00,  0x8e,  0xe4,
13306   0x0a,  0xfe,  0xc8,  0x00,  0x17,  0x4d,  0x13,  0x06,  0x83,  0xbb,  0xfe,  0x90,  0x01,  0xba,  0xfe,  0x4e,
13307   0x14,  0x89,  0xfe,  0x12,  0x10,  0xfe,  0x43,  0xf4,  0x94,  0xfe,  0x56,  0xf0,  0xfe,  0x60,  0x14,  0xfe,
13308   0x04,  0xf4,  0x6c,  0xfe,  0x43,  0xf4,  0x93,  0xfe,  0xf3,  0x10,  0xf9,  0x01,  0xfe,  0x22,  0x13,  0x1c,
13309   0x3d,  0xfe,  0x10,  0x13,  0xfe,  0x00,  0x17,  0xfe,  0x4d,  0xe4,  0x69,  0xba,  0xfe,  0x9c,  0x14,  0xb7,
13310   0x69,  0xfe,  0x1c,  0x10,  0xfe,  0x00,  0x17,  0xfe,  0x4d,  0xe4,  0x19,  0xba,  0xfe,  0x9c,  0x14,  0xb7,
13311   0x19,  0x83,  0x60,  0x23,  0xfe,  0x4d,  0xf4,  0x00,  0xdf,  0x89,  0x13,  0x06,  0xfe,  0xb4,  0x56,  0xfe,
13312   0xc3,  0x58,  0x03,  0x60,  0x13,  0x0b,  0x03,  0x15,  0x06,  0x01,  0x08,  0x26,  0xe5,  0x15,  0x0b,  0x01,
13313   0x08,  0x26,  0xe5,  0x15,  0x1a,  0x01,  0x08,  0x26,  0xe5,  0x72,  0xfe,  0x89,  0x49,  0x01,  0x08,  0x03,
13314   0x15,  0x06,  0x01,  0x08,  0x26,  0xa6,  0x15,  0x1a,  0x01,  0x08,  0x26,  0xa6,  0x15,  0x06,  0x01,  0x08,
13315   0x26,  0xa6,  0xfe,  0x89,  0x49,  0x01,  0x08,  0x26,  0xa6,  0x72,  0xfe,  0x89,  0x4a,  0x01,  0x08,  0x03,
13316   0x60,  0x03,  0x1e,  0xcc,  0x07,  0x06,  0xfe,  0x44,  0x13,  0xad,  0x12,  0xcc,  0xfe,  0x49,  0xf4,  0x00,
13317   0x3b,  0x72,  0x9f,  0x5e,  0xfe,  0x01,  0xec,  0xfe,  0x27,  0x01,  0xf1,  0x01,  0x08,  0x2f,  0x07,  0xfe,
13318   0xe3,  0x00,  0xfe,  0x20,  0x13,  0x1f,  0xfe,  0x5a,  0x15,  0x23,  0x12,  0xcd,  0x01,  0x43,  0x1e,  0xcd,
13319   0x07,  0x06,  0x45,  0x09,  0x4a,  0x06,  0x35,  0x03,  0x0a,  0x42,  0x01,  0x0e,  0xed,  0x88,  0x07,  0x10,
13320   0xa4,  0x0a,  0x80,  0x01,  0x0e,  0x88,  0x0a,  0x51,  0x01,  0x9e,  0x03,  0x0a,  0x80,  0x01,  0x0e,  0x88,
13321   0xfe,  0x80,  0xe7,  0x10,  0x07,  0x10,  0x84,  0xfe,  0x45,  0x58,  0x01,  0xe3,  0x88,  0x03,  0x0a,  0x42,
13322   0x01,  0x0e,  0x88,  0x0a,  0x51,  0x01,  0x9e,  0x03,  0x0a,  0x42,  0x01,  0x0e,  0xfe,  0x80,  0x80,  0xf2,
13323   0xfe,  0x49,  0xe4,  0x10,  0xa4,  0x0a,  0x80,  0x01,  0x0e,  0xf2,  0x0a,  0x51,  0x01,  0x82,  0x03,  0x17,
13324   0x10,  0x71,  0x66,  0xfe,  0x60,  0x01,  0xfe,  0x18,  0xdf,  0xfe,  0x19,  0xde,  0xfe,  0x24,  0x1c,  0xfe,
13325   0x1d,  0xf7,  0x1d,  0x90,  0xfe,  0xf6,  0x15,  0x01,  0xfe,  0xfc,  0x16,  0xe0,  0x91,  0x1d,  0x66,  0xfe,
13326   0x2c,  0x01,  0xfe,  0x2f,  0x19,  0x03,  0xae,  0x21,  0xfe,  0xe6,  0x15,  0xfe,  0xda,  0x10,  0x17,  0x10,
13327   0x71,  0x05,  0xfe,  0x64,  0x01,  0xfe,  0x00,  0xf4,  0x19,  0xfe,  0x18,  0x58,  0x05,  0xfe,  0x66,  0x01,
13328   0xfe,  0x19,  0x58,  0x91,  0x19,  0xfe,  0x3c,  0x90,  0xfe,  0x30,  0xf4,  0x06,  0xfe,  0x3c,  0x50,  0x66,
13329   0xfe,  0x38,  0x00,  0xfe,  0x0f,  0x79,  0xfe,  0x1c,  0xf7,  0x19,  0x90,  0xfe,  0x40,  0x16,  0xfe,  0xb6,
13330   0x14,  0x34,  0x03,  0xae,  0x21,  0xfe,  0x18,  0x16,  0xfe,  0x9c,  0x10,  0x17,  0x10,  0x71,  0xfe,  0x83,
13331   0x5a,  0xfe,  0x18,  0xdf,  0xfe,  0x19,  0xde,  0xfe,  0x1d,  0xf7,  0x38,  0x90,  0xfe,  0x62,  0x16,  0xfe,
13332   0x94,  0x14,  0xfe,  0x10,  0x13,  0x91,  0x38,  0x66,  0x1b,  0xfe,  0xaf,  0x19,  0xfe,  0x98,  0xe7,  0x00,
13333   0x03,  0xae,  0x21,  0xfe,  0x56,  0x16,  0xfe,  0x6c,  0x10,  0x17,  0x10,  0x71,  0xfe,  0x30,  0xbc,  0xfe,
13334   0xb2,  0xbc,  0x91,  0xc5,  0x66,  0x1b,  0xfe,  0x0f,  0x79,  0xfe,  0x1c,  0xf7,  0xc5,  0x90,  0xfe,  0x9a,
13335   0x16,  0xfe,  0x5c,  0x14,  0x34,  0x03,  0xae,  0x21,  0xfe,  0x86,  0x16,  0xfe,  0x42,  0x10,  0xfe,  0x02,
13336   0xf6,  0x10,  0x71,  0xfe,  0x18,  0xfe,  0x54,  0xfe,  0x19,  0xfe,  0x55,  0xfc,  0xfe,  0x1d,  0xf7,  0x4f,
13337   0x90,  0xfe,  0xc0,  0x16,  0xfe,  0x36,  0x14,  0xfe,  0x1c,  0x13,  0x91,  0x4f,  0x47,  0xfe,  0x83,  0x58,
13338   0xfe,  0xaf,  0x19,  0xfe,  0x80,  0xe7,  0x10,  0xfe,  0x81,  0xe7,  0x10,  0x11,  0xfe,  0xdd,  0x00,  0x63,
13339   0x27,  0x03,  0x63,  0x27,  0xfe,  0x12,  0x45,  0x21,  0xfe,  0xb0,  0x16,  0x14,  0x06,  0x37,  0x95,  0xa9,
13340   0x02,  0x29,  0xfe,  0x39,  0xf0,  0xfe,  0x04,  0x17,  0x23,  0x03,  0xfe,  0x7e,  0x18,  0x1c,  0x1a,  0x5d,
13341   0x13,  0x0d,  0x03,  0x71,  0x05,  0xcb,  0x1c,  0x06,  0xfe,  0xef,  0x12,  0xfe,  0xe1,  0x10,  0x78,  0x2c,
13342   0x46,  0x2f,  0x07,  0x2d,  0xfe,  0x3c,  0x13,  0xfe,  0x82,  0x14,  0xfe,  0x42,  0x13,  0x3c,  0x8a,  0x0a,
13343   0x42,  0x01,  0x0e,  0xb0,  0xfe,  0x3e,  0x12,  0xf0,  0xfe,  0x45,  0x48,  0x01,  0xe3,  0xfe,  0x00,  0xcc,
13344   0xb0,  0xfe,  0xf3,  0x13,  0x3d,  0x75,  0x07,  0x10,  0xa3,  0x0a,  0x80,  0x01,  0x0e,  0xf2,  0x01,  0x6f,
13345   0xfe,  0x16,  0x10,  0x07,  0x7e,  0x85,  0xfe,  0x40,  0x14,  0xfe,  0x24,  0x12,  0xf6,  0xfe,  0xd6,  0xf0,
13346   0xfe,  0x24,  0x17,  0x17,  0x0b,  0x03,  0xfe,  0x9c,  0xe7,  0x0b,  0x0f,  0xfe,  0x15,  0x00,  0x59,  0x76,
13347   0x27,  0x01,  0xda,  0x17,  0x06,  0x03,  0x3c,  0x8a,  0x09,  0x4a,  0x1d,  0x35,  0x11,  0x2d,  0x01,  0x6f,
13348   0x17,  0x06,  0x03,  0xfe,  0x38,  0x90,  0xfe,  0xba,  0x90,  0x79,  0xc7,  0x68,  0xc8,  0xfe,  0x48,  0x55,
13349   0x34,  0xfe,  0xc9,  0x55,  0x03,  0x1e,  0x98,  0x73,  0x12,  0x98,  0x03,  0x0a,  0x99,  0x01,  0x0e,  0xf0,
13350   0x0a,  0x40,  0x01,  0x0e,  0xfe,  0x49,  0x44,  0x16,  0xfe,  0xf0,  0x17,  0x73,  0x75,  0x03,  0x0a,  0x42,
13351   0x01,  0x0e,  0x07,  0x10,  0x45,  0x0a,  0x51,  0x01,  0x9e,  0x0a,  0x40,  0x01,  0x0e,  0x73,  0x75,  0x03,
13352   0xfe,  0x4e,  0xe4,  0x1a,  0x64,  0xfe,  0x24,  0x18,  0x05,  0xfe,  0x90,  0x00,  0xfe,  0x3a,  0x45,  0x5b,
13353   0xfe,  0x4e,  0xe4,  0xc2,  0x64,  0xfe,  0x36,  0x18,  0x05,  0xfe,  0x92,  0x00,  0xfe,  0x02,  0xe6,  0x1b,
13354   0xdc,  0xfe,  0x4e,  0xe4,  0xfe,  0x0b,  0x00,  0x64,  0xfe,  0x48,  0x18,  0x05,  0xfe,  0x94,  0x00,  0xfe,
13355   0x02,  0xe6,  0x19,  0xfe,  0x08,  0x10,  0x05,  0xfe,  0x96,  0x00,  0xfe,  0x02,  0xe6,  0x2c,  0xfe,  0x4e,
13356   0x45,  0xfe,  0x0c,  0x12,  0xaf,  0xff,  0x04,  0x68,  0x54,  0xde,  0x1c,  0x69,  0x03,  0x07,  0x7a,  0xfe,
13357   0x5a,  0xf0,  0xfe,  0x74,  0x18,  0x24,  0xfe,  0x09,  0x00,  0xfe,  0x34,  0x10,  0x07,  0x1b,  0xfe,  0x5a,
13358   0xf0,  0xfe,  0x82,  0x18,  0x24,  0xc3,  0xfe,  0x26,  0x10,  0x07,  0x1a,  0x5d,  0x24,  0x2c,  0xdc,  0x07,
13359   0x0b,  0x5d,  0x24,  0x93,  0xfe,  0x0e,  0x10,  0x07,  0x06,  0x5d,  0x24,  0x4d,  0x9f,  0xad,  0x03,  0x14,
13360   0xfe,  0x09,  0x00,  0x01,  0x33,  0xfe,  0x04,  0xfe,  0x7d,  0x05,  0x7f,  0xf9,  0x03,  0x25,  0xfe,  0xca,
13361   0x18,  0xfe,  0x14,  0xf0,  0x08,  0x65,  0xfe,  0xc6,  0x18,  0x03,  0xff,  0x1a,  0x00,  0x00,
13362 };
13363
13364 STATIC unsigned short _adv_asc3550_size =
13365         sizeof(_adv_asc3550_buf); /* 0x13AD */
13366 STATIC ADV_DCNT _adv_asc3550_chksum =
13367         0x04D52DDDUL; /* Expanded little-endian checksum. */
13368
13369 /* Microcode buffer is kept after initialization for error recovery. */
13370 STATIC unsigned char _adv_asc38C0800_buf[] = {
13371   0x00,  0x00,  0x00,  0xf2,  0x00,  0xf0,  0x00,  0xfc,  0x00,  0x16,  0x18,  0xe4,  0x01,  0x00,  0x48,  0xe4,
13372   0x18,  0x80,  0x03,  0xf6,  0x02,  0x00,  0xce,  0x19,  0x00,  0xfa,  0xff,  0xff,  0x1c,  0x0f,  0x00,  0xf6,
13373   0x9e,  0xe7,  0xff,  0x00,  0x82,  0xe7,  0x00,  0xea,  0x01,  0xfa,  0x01,  0xe6,  0x09,  0xe7,  0x55,  0xf0,
13374   0x01,  0xf6,  0x03,  0x00,  0x04,  0x00,  0x10,  0x00,  0x1e,  0xf0,  0x85,  0xf0,  0x18,  0xf4,  0x08,  0x00,
13375   0xbc,  0x00,  0x38,  0x54,  0x00,  0xec,  0xd5,  0xf0,  0x82,  0x0d,  0x00,  0xe6,  0x86,  0xf0,  0xb1,  0xf0,
13376   0x98,  0x57,  0x01,  0xfc,  0xb4,  0x00,  0xd4,  0x01,  0x0c,  0x1c,  0x3e,  0x1c,  0x3c,  0x00,  0xbb,  0x00,
13377   0x00,  0x10,  0xba,  0x19,  0x02,  0x80,  0x32,  0xf0,  0x7c,  0x0d,  0x02,  0x13,  0xba,  0x13,  0x18,  0x40,
13378   0x00,  0x57,  0x01,  0xea,  0x02,  0xfc,  0x03,  0xfc,  0x3e,  0x00,  0x6c,  0x01,  0x6e,  0x01,  0x74,  0x01,
13379   0x76,  0x01,  0xb9,  0x54,  0x3e,  0x57,  0x00,  0x80,  0x03,  0xe6,  0xb6,  0x00,  0xc0,  0x00,  0x01,  0x01,
13380   0x3e,  0x01,  0x7a,  0x01,  0xca,  0x08,  0xce,  0x10,  0x16,  0x11,  0x04,  0x12,  0x08,  0x12,  0x02,  0x4a,
13381   0xbb,  0x55,  0x3c,  0x56,  0x03,  0x58,  0x1b,  0x80,  0x30,  0xe4,  0x4b,  0xe4,  0x5d,  0xf0,  0x02,  0xfa,
13382   0x20,  0x00,  0x32,  0x00,  0x40,  0x00,  0x80,  0x00,  0x24,  0x01,  0x3c,  0x01,  0x68,  0x01,  0x6a,  0x01,
13383   0x70,  0x01,  0x72,  0x01,  0x78,  0x01,  0x7c,  0x01,  0x62,  0x0a,  0x86,  0x0d,  0x06,  0x13,  0x4c,  0x1c,
13384   0x04,  0x80,  0x4a,  0xe4,  0x02,  0xee,  0x5b,  0xf0,  0x03,  0xf7,  0x0c,  0x00,  0x0f,  0x00,  0x47,  0x00,
13385   0xbe,  0x00,  0x00,  0x01,  0x20,  0x11,  0x5c,  0x16,  0x32,  0x1c,  0x38,  0x1c,  0x4e,  0x1c,  0x10,  0x44,
13386   0x00,  0x4c,  0x04,  0xea,  0x5c,  0xf0,  0xa7,  0xf0,  0x04,  0xf6,  0x03,  0xfa,  0x05,  0x00,  0x34,  0x00,
13387   0x36,  0x00,  0x98,  0x00,  0xcc,  0x00,  0x20,  0x01,  0x4e,  0x01,  0x4a,  0x0b,  0x42,  0x0c,  0x12,  0x0f,
13388   0x0c,  0x10,  0x22,  0x11,  0x0a,  0x12,  0x04,  0x13,  0x30,  0x1c,  0x02,  0x48,  0x00,  0x4e,  0x42,  0x54,
13389   0x44,  0x55,  0xbd,  0x56,  0x06,  0x83,  0x00,  0xdc,  0x05,  0xf0,  0x09,  0xf0,  0x59,  0xf0,  0xb8,  0xf0,
13390   0x4b,  0xf4,  0x06,  0xf7,  0x0e,  0xf7,  0x04,  0xfc,  0x05,  0xfc,  0x06,  0x00,  0x19,  0x00,  0x33,  0x00,
13391   0x9b,  0x00,  0xa4,  0x00,  0xb5,  0x00,  0xba,  0x00,  0xd0,  0x00,  0xe1,  0x00,  0xe7,  0x00,  0xe2,  0x03,
13392   0x08,  0x0f,  0x02,  0x10,  0x04,  0x10,  0x0a,  0x10,  0x0a,  0x13,  0x0c,  0x13,  0x12,  0x13,  0x24,  0x14,
13393   0x34,  0x14,  0x04,  0x16,  0x08,  0x16,  0xa4,  0x17,  0x20,  0x1c,  0x34,  0x1c,  0x36,  0x1c,  0x08,  0x44,
13394   0x38,  0x44,  0x91,  0x44,  0x0a,  0x45,  0x48,  0x46,  0x01,  0x48,  0x68,  0x54,  0x3a,  0x55,  0x83,  0x55,
13395   0xe5,  0x55,  0xb0,  0x57,  0x01,  0x58,  0x83,  0x59,  0x05,  0xe6,  0x0b,  0xf0,  0x0c,  0xf0,  0x04,  0xf8,
13396   0x05,  0xf8,  0x07,  0x00,  0x0a,  0x00,  0x1c,  0x00,  0x1e,  0x00,  0x9e,  0x00,  0xa8,  0x00,  0xaa,  0x00,
13397   0xb9,  0x00,  0xe0,  0x00,  0x22,  0x01,  0x26,  0x01,  0x79,  0x01,  0x7e,  0x01,  0xc4,  0x01,  0xc6,  0x01,
13398   0x80,  0x02,  0x5e,  0x03,  0xee,  0x04,  0x9a,  0x06,  0xf8,  0x07,  0x62,  0x08,  0x68,  0x08,  0x69,  0x08,
13399   0xd6,  0x08,  0xe9,  0x09,  0xfa,  0x0b,  0x2e,  0x0f,  0x12,  0x10,  0x1a,  0x10,  0xed,  0x10,  0xf1,  0x10,
13400   0x2a,  0x11,  0x06,  0x12,  0x0c,  0x12,  0x3e,  0x12,  0x10,  0x13,  0x16,  0x13,  0x1e,  0x13,  0x46,  0x14,
13401   0x76,  0x14,  0x82,  0x14,  0x36,  0x15,  0xca,  0x15,  0x6b,  0x18,  0xbe,  0x18,  0xca,  0x18,  0xe6,  0x19,
13402   0x12,  0x1c,  0x46,  0x1c,  0x9c,  0x32,  0x00,  0x40,  0x0e,  0x47,  0xfe,  0x9c,  0xf0,  0x2b,  0x02,  0xfe,
13403   0xac,  0x0d,  0xff,  0x10,  0x00,  0x00,  0xd7,  0xfe,  0xe8,  0x19,  0x00,  0xd6,  0xfe,  0x84,  0x01,  0xff,
13404   0x03,  0x00,  0x00,  0xfe,  0x93,  0x15,  0xfe,  0x0f,  0x05,  0xff,  0x38,  0x00,  0x00,  0xfe,  0x57,  0x24,
13405   0x00,  0xfe,  0x4c,  0x00,  0x5b,  0xff,  0x04,  0x00,  0x00,  0x11,  0xff,  0x09,  0x00,  0x00,  0xff,  0x08,
13406   0x01,  0x01,  0xff,  0x08,  0xff,  0xff,  0xff,  0x27,  0x00,  0x00,  0xff,  0x10,  0xff,  0xff,  0xff,  0x11,
13407   0x00,  0x00,  0xfe,  0x78,  0x56,  0xfe,  0x34,  0x12,  0xff,  0x21,  0x00,  0x00,  0xfe,  0x04,  0xf7,  0xd6,
13408   0x2c,  0x99,  0x0a,  0x01,  0xfe,  0xc2,  0x0f,  0xfe,  0x04,  0xf7,  0xd6,  0x99,  0x0a,  0x42,  0x2c,  0xfe,
13409   0x3d,  0xf0,  0xfe,  0x06,  0x02,  0xfe,  0x20,  0xf0,  0xa7,  0xfe,  0x91,  0xf0,  0xfe,  0xf4,  0x01,  0xfe,
13410   0x90,  0xf0,  0xfe,  0xf4,  0x01,  0xfe,  0x8f,  0xf0,  0xa7,  0x03,  0x5d,  0x4d,  0x02,  0xfe,  0xc8,  0x0d,
13411   0x01,  0xfe,  0x38,  0x0e,  0xfe,  0xdd,  0x12,  0xfe,  0xfc,  0x10,  0xfe,  0x28,  0x1c,  0x03,  0xfe,  0xa6,
13412   0x00,  0xfe,  0xd3,  0x12,  0x41,  0x14,  0xfe,  0xa6,  0x00,  0xc2,  0xfe,  0x48,  0xf0,  0xfe,  0x8a,  0x02,
13413   0xfe,  0x49,  0xf0,  0xfe,  0xa4,  0x02,  0xfe,  0x4a,  0xf0,  0xfe,  0xc2,  0x02,  0xfe,  0x46,  0xf0,  0xfe,
13414   0x54,  0x02,  0xfe,  0x47,  0xf0,  0xfe,  0x5a,  0x02,  0xfe,  0x43,  0xf0,  0xfe,  0x48,  0x02,  0xfe,  0x44,
13415   0xf0,  0xfe,  0x4c,  0x02,  0xfe,  0x45,  0xf0,  0xfe,  0x50,  0x02,  0x18,  0x0a,  0xaa,  0x18,  0x06,  0x14,
13416   0xa1,  0x02,  0x2b,  0xfe,  0x00,  0x1c,  0xe7,  0xfe,  0x02,  0x1c,  0xe6,  0xfe,  0x1e,  0x1c,  0xfe,  0xe9,
13417   0x10,  0x01,  0xfe,  0x18,  0x18,  0xfe,  0xe7,  0x10,  0xfe,  0x06,  0xfc,  0xce,  0x09,  0x70,  0x01,  0xa8,
13418   0x02,  0x2b,  0x15,  0x59,  0x39,  0xa2,  0x01,  0xfe,  0x58,  0x10,  0x09,  0x70,  0x01,  0x87,  0xfe,  0xbd,
13419   0x10,  0x09,  0x70,  0x01,  0x87,  0xfe,  0xad,  0x10,  0xfe,  0x16,  0x1c,  0xfe,  0x58,  0x1c,  0x18,  0x06,
13420   0x14,  0xa1,  0x2c,  0x1c,  0x2b,  0xfe,  0x3d,  0xf0,  0xfe,  0x06,  0x02,  0x23,  0xfe,  0x98,  0x02,  0xfe,
13421   0x5a,  0x1c,  0xf8,  0xfe,  0x14,  0x1c,  0x15,  0xfe,  0x30,  0x00,  0x39,  0xa2,  0x01,  0xfe,  0x48,  0x10,
13422   0x18,  0x06,  0x14,  0xa1,  0x02,  0xd7,  0x22,  0x20,  0x07,  0x11,  0x35,  0xfe,  0x69,  0x10,  0x18,  0x06,
13423   0x14,  0xa1,  0xfe,  0x04,  0xec,  0x20,  0x4f,  0x43,  0x13,  0x20,  0xfe,  0x05,  0xf6,  0xce,  0x01,  0xfe,
13424   0x4a,  0x17,  0x08,  0x54,  0x58,  0x37,  0x12,  0x2f,  0x42,  0x92,  0x01,  0xfe,  0x82,  0x16,  0x02,  0x2b,
13425   0x09,  0x46,  0x01,  0x0e,  0x07,  0x00,  0x66,  0x01,  0x73,  0xfe,  0x18,  0x10,  0xfe,  0x41,  0x58,  0x09,
13426   0xa4,  0x01,  0x0e,  0xfe,  0xc8,  0x54,  0x6b,  0xfe,  0x10,  0x03,  0x01,  0xfe,  0x82,  0x16,  0x02,  0x2b,
13427   0x2c,  0x4f,  0xfe,  0x02,  0xe8,  0x2a,  0xfe,  0xbf,  0x57,  0xfe,  0x9e,  0x43,  0xfe,  0x77,  0x57,  0xfe,
13428   0x27,  0xf0,  0xfe,  0xe0,  0x01,  0xfe,  0x07,  0x4b,  0xfe,  0x20,  0xf0,  0xa7,  0xfe,  0x40,  0x1c,  0x1c,
13429   0xd9,  0xfe,  0x26,  0xf0,  0xfe,  0x5a,  0x03,  0xfe,  0xa0,  0xf0,  0xfe,  0x48,  0x03,  0xfe,  0x11,  0xf0,
13430   0xa7,  0xfe,  0xef,  0x10,  0xfe,  0x9f,  0xf0,  0xfe,  0x68,  0x03,  0xf9,  0x10,  0xfe,  0x11,  0x00,  0x02,
13431   0x65,  0x2c,  0xfe,  0x48,  0x1c,  0xf9,  0x08,  0x05,  0x1b,  0xfe,  0x18,  0x13,  0x21,  0x22,  0xa3,  0xb7,
13432   0x13,  0xa3,  0x09,  0x46,  0x01,  0x0e,  0xb7,  0x78,  0x01,  0xfe,  0xb4,  0x16,  0x12,  0xd1,  0x1c,  0xd9,
13433   0xfe,  0x01,  0xf0,  0xd9,  0xfe,  0x82,  0xf0,  0xfe,  0x96,  0x03,  0xfa,  0x12,  0xfe,  0xe4,  0x00,  0x27,
13434   0xfe,  0xa8,  0x03,  0x1c,  0x34,  0x1d,  0xfe,  0xb8,  0x03,  0x01,  0x4b,  0xfe,  0x06,  0xf0,  0xfe,  0xc8,
13435   0x03,  0x95,  0x86,  0xfe,  0x0a,  0xf0,  0xfe,  0x8a,  0x06,  0x02,  0x24,  0x03,  0x70,  0x28,  0x17,  0xfe,
13436   0xfa,  0x04,  0x15,  0x6d,  0x01,  0x36,  0x7b,  0xfe,  0x6a,  0x02,  0x02,  0xd8,  0xf9,  0x2c,  0x99,  0x19,
13437   0xfe,  0x67,  0x1b,  0xfe,  0xbf,  0x57,  0xfe,  0x77,  0x57,  0xfe,  0x48,  0x1c,  0x74,  0x01,  0xaf,  0x8c,
13438   0x09,  0x46,  0x01,  0x0e,  0x07,  0x00,  0x17,  0xda,  0x09,  0xd1,  0x01,  0x0e,  0x8d,  0x51,  0x64,  0x79,
13439   0x2a,  0x03,  0x70,  0x28,  0xfe,  0x10,  0x12,  0x15,  0x6d,  0x01,  0x36,  0x7b,  0xfe,  0x6a,  0x02,  0x02,
13440   0xd8,  0xc7,  0x81,  0xc8,  0x83,  0x1c,  0x24,  0x27,  0xfe,  0x40,  0x04,  0x1d,  0xfe,  0x3c,  0x04,  0x3b,
13441   0xfe,  0xa0,  0x00,  0xfe,  0x9b,  0x57,  0xfe,  0x4e,  0x12,  0x2d,  0xff,  0x02,  0x00,  0x10,  0x01,  0x0b,
13442   0x1d,  0xfe,  0xe4,  0x04,  0x2d,  0x01,  0x0b,  0x1d,  0x24,  0x33,  0x31,  0xde,  0xfe,  0x4c,  0x44,  0xfe,
13443   0x4c,  0x12,  0x51,  0xfe,  0x44,  0x48,  0x0f,  0x6f,  0xfe,  0x4c,  0x54,  0x6b,  0xda,  0x4f,  0x79,  0x2a,
13444   0xfe,  0x06,  0x80,  0xfe,  0x48,  0x47,  0xfe,  0x62,  0x13,  0x08,  0x05,  0x1b,  0xfe,  0x2a,  0x13,  0x32,
13445   0x07,  0x82,  0xfe,  0x52,  0x13,  0xfe,  0x20,  0x10,  0x0f,  0x6f,  0xfe,  0x4c,  0x54,  0x6b,  0xda,  0xfe,
13446   0x06,  0x80,  0xfe,  0x48,  0x47,  0xfe,  0x40,  0x13,  0x08,  0x05,  0x1b,  0xfe,  0x08,  0x13,  0x32,  0x07,
13447   0x82,  0xfe,  0x30,  0x13,  0x08,  0x05,  0x1b,  0xfe,  0x1c,  0x12,  0x15,  0x9d,  0x08,  0x05,  0x06,  0x4d,
13448   0x15,  0xfe,  0x0d,  0x00,  0x01,  0x36,  0x7b,  0xfe,  0x64,  0x0d,  0x02,  0x24,  0x2d,  0x12,  0xfe,  0xe6,
13449   0x00,  0xfe,  0x1c,  0x90,  0xfe,  0x40,  0x5c,  0x04,  0x15,  0x9d,  0x01,  0x36,  0x02,  0x2b,  0xfe,  0x42,
13450   0x5b,  0x99,  0x19,  0xfe,  0x46,  0x59,  0xfe,  0xbf,  0x57,  0xfe,  0x77,  0x57,  0xfe,  0x87,  0x80,  0xfe,
13451   0x31,  0xe4,  0x5b,  0x08,  0x05,  0x0a,  0xfe,  0x84,  0x13,  0xfe,  0x20,  0x80,  0x07,  0x19,  0xfe,  0x7c,
13452   0x12,  0x53,  0x05,  0x06,  0xfe,  0x6c,  0x13,  0x03,  0xfe,  0xa2,  0x00,  0x28,  0x17,  0xfe,  0x90,  0x05,
13453   0xfe,  0x31,  0xe4,  0x5a,  0x53,  0x05,  0x0a,  0xfe,  0x56,  0x13,  0x03,  0xfe,  0xa0,  0x00,  0x28,  0xfe,
13454   0x4e,  0x12,  0x67,  0xff,  0x02,  0x00,  0x10,  0x27,  0xfe,  0x48,  0x05,  0x1c,  0x34,  0xfe,  0x89,  0x48,
13455   0xff,  0x02,  0x00,  0x10,  0x27,  0xfe,  0x56,  0x05,  0x26,  0xfe,  0xa8,  0x05,  0x12,  0xfe,  0xe3,  0x00,
13456   0x21,  0x53,  0xfe,  0x4a,  0xf0,  0xfe,  0x76,  0x05,  0xfe,  0x49,  0xf0,  0xfe,  0x70,  0x05,  0x88,  0x25,
13457   0xfe,  0x21,  0x00,  0xab,  0x25,  0xfe,  0x22,  0x00,  0xaa,  0x25,  0x58,  0xfe,  0x09,  0x48,  0xff,  0x02,
13458   0x00,  0x10,  0x27,  0xfe,  0x86,  0x05,  0x26,  0xfe,  0xa8,  0x05,  0xfe,  0xe2,  0x08,  0x53,  0x05,  0xcb,
13459   0x4d,  0x01,  0xb0,  0x25,  0x06,  0x13,  0xd3,  0x39,  0xfe,  0x27,  0x01,  0x08,  0x05,  0x1b,  0xfe,  0x22,
13460   0x12,  0x41,  0x01,  0xb2,  0x15,  0x9d,  0x08,  0x05,  0x06,  0x4d,  0x15,  0xfe,  0x0d,  0x00,  0x01,  0x36,
13461   0x7b,  0xfe,  0x64,  0x0d,  0x02,  0x24,  0x03,  0xfe,  0x9c,  0x00,  0x28,  0xeb,  0x03,  0x5c,  0x28,  0xfe,
13462   0x36,  0x13,  0x41,  0x01,  0xb2,  0x26,  0xfe,  0x18,  0x06,  0x09,  0x06,  0x53,  0x05,  0x1f,  0xfe,  0x02,
13463   0x12,  0x50,  0x01,  0xfe,  0x9e,  0x15,  0x1d,  0xfe,  0x0e,  0x06,  0x12,  0xa5,  0x01,  0x4b,  0x12,  0xfe,
13464   0xe5,  0x00,  0x03,  0x5c,  0xc1,  0x0c,  0x5c,  0x03,  0xcd,  0x28,  0xfe,  0x62,  0x12,  0x03,  0x45,  0x28,
13465   0xfe,  0x5a,  0x13,  0x01,  0xfe,  0x0c,  0x19,  0x01,  0xfe,  0x76,  0x19,  0xfe,  0x43,  0x48,  0xc4,  0xcc,
13466   0x0f,  0x71,  0xff,  0x02,  0x00,  0x57,  0x52,  0x93,  0x1e,  0x43,  0x8b,  0xc4,  0x6e,  0x41,  0x01,  0xb2,
13467   0x26,  0xfe,  0x82,  0x06,  0x53,  0x05,  0x1a,  0xe9,  0x91,  0x09,  0x59,  0x01,  0xfe,  0xcc,  0x15,  0x1d,
13468   0xfe,  0x78,  0x06,  0x12,  0xa5,  0x01,  0x4b,  0x12,  0xfe,  0xe5,  0x00,  0x03,  0x45,  0xc1,  0x0c,  0x45,
13469   0x18,  0x06,  0x01,  0xb2,  0xfa,  0x76,  0x74,  0x01,  0xaf,  0x8c,  0x12,  0xfe,  0xe2,  0x00,  0x27,  0xdb,
13470   0x1c,  0x34,  0xfe,  0x0a,  0xf0,  0xfe,  0xb6,  0x06,  0x94,  0xfe,  0x6c,  0x07,  0xfe,  0x06,  0xf0,  0xfe,
13471   0x74,  0x07,  0x95,  0x86,  0x02,  0x24,  0x08,  0x05,  0x0a,  0xfe,  0x2e,  0x12,  0x16,  0x19,  0x01,  0x0b,
13472   0x16,  0x00,  0x01,  0x0b,  0x16,  0x00,  0x01,  0x0b,  0x16,  0x00,  0x01,  0x0b,  0xfe,  0x99,  0xa4,  0x01,
13473   0x0b,  0x16,  0x00,  0x02,  0xfe,  0x42,  0x08,  0x68,  0x05,  0x1a,  0xfe,  0x38,  0x12,  0x08,  0x05,  0x1a,
13474   0xfe,  0x30,  0x13,  0x16,  0xfe,  0x1b,  0x00,  0x01,  0x0b,  0x16,  0x00,  0x01,  0x0b,  0x16,  0x00,  0x01,
13475   0x0b,  0x16,  0x00,  0x01,  0x0b,  0x16,  0x06,  0x01,  0x0b,  0x16,  0x00,  0x02,  0xe2,  0x6c,  0x58,  0xbe,
13476   0x50,  0xfe,  0x9a,  0x81,  0x55,  0x1b,  0x7a,  0xfe,  0x42,  0x07,  0x09,  0x1b,  0xfe,  0x09,  0x6f,  0xba,
13477   0xfe,  0xca,  0x45,  0xfe,  0x32,  0x12,  0x69,  0x6d,  0x8b,  0x6c,  0x7f,  0x27,  0xfe,  0x54,  0x07,  0x1c,
13478   0x34,  0xfe,  0x0a,  0xf0,  0xfe,  0x42,  0x07,  0x95,  0x86,  0x94,  0xfe,  0x6c,  0x07,  0x02,  0x24,  0x01,
13479   0x4b,  0x02,  0xdb,  0x16,  0x1f,  0x02,  0xdb,  0xfe,  0x9c,  0xf7,  0xdc,  0xfe,  0x2c,  0x90,  0xfe,  0xae,
13480   0x90,  0x56,  0xfe,  0xda,  0x07,  0x0c,  0x60,  0x14,  0x61,  0x08,  0x54,  0x5a,  0x37,  0x22,  0x20,  0x07,
13481   0x11,  0xfe,  0x0e,  0x12,  0x8d,  0xfe,  0x80,  0x80,  0x39,  0x20,  0x6a,  0x2a,  0xfe,  0x06,  0x10,  0xfe,
13482   0x83,  0xe7,  0xfe,  0x48,  0x00,  0xab,  0xfe,  0x03,  0x40,  0x08,  0x54,  0x5b,  0x37,  0x01,  0xb3,  0xb8,
13483   0xfe,  0x1f,  0x40,  0x13,  0x62,  0x01,  0xef,  0xfe,  0x08,  0x50,  0xfe,  0x8a,  0x50,  0xfe,  0x44,  0x51,
13484   0xfe,  0xc6,  0x51,  0x88,  0xfe,  0x08,  0x90,  0xfe,  0x8a,  0x90,  0x0c,  0x5e,  0x14,  0x5f,  0xfe,  0x0c,
13485   0x90,  0xfe,  0x8e,  0x90,  0xfe,  0x40,  0x50,  0xfe,  0xc2,  0x50,  0x0c,  0x3d,  0x14,  0x3e,  0xfe,  0x4a,
13486   0x10,  0x08,  0x05,  0x5a,  0xfe,  0x2a,  0x12,  0xfe,  0x2c,  0x90,  0xfe,  0xae,  0x90,  0x0c,  0x60,  0x14,
13487   0x61,  0x08,  0x05,  0x5b,  0x8b,  0x01,  0xb3,  0xfe,  0x1f,  0x80,  0x13,  0x62,  0xfe,  0x44,  0x90,  0xfe,
13488   0xc6,  0x90,  0x0c,  0x3f,  0x14,  0x40,  0xfe,  0x08,  0x90,  0xfe,  0x8a,  0x90,  0x0c,  0x5e,  0x14,  0x5f,
13489   0xfe,  0x40,  0x90,  0xfe,  0xc2,  0x90,  0x0c,  0x3d,  0x14,  0x3e,  0x0c,  0x2e,  0x14,  0x3c,  0x21,  0x0c,
13490   0x49,  0x0c,  0x63,  0x08,  0x54,  0x1f,  0x37,  0x2c,  0x0f,  0xfe,  0x4e,  0x11,  0x27,  0xdd,  0xfe,  0x9e,
13491   0xf0,  0xfe,  0x76,  0x08,  0xbc,  0x17,  0x34,  0x2c,  0x77,  0xe6,  0xc5,  0xfe,  0x9a,  0x08,  0xc6,  0xfe,
13492   0xb8,  0x08,  0x94,  0xfe,  0x8e,  0x08,  0xfe,  0x06,  0xf0,  0xfe,  0x94,  0x08,  0x95,  0x86,  0x02,  0x24,
13493   0x01,  0x4b,  0xfe,  0xc9,  0x10,  0x16,  0x1f,  0xfe,  0xc9,  0x10,  0x68,  0x05,  0x06,  0xfe,  0x10,  0x12,
13494   0x68,  0x05,  0x0a,  0x4e,  0x08,  0x05,  0x0a,  0xfe,  0x90,  0x12,  0xfe,  0x2e,  0x1c,  0x02,  0xfe,  0x18,
13495   0x0b,  0x68,  0x05,  0x06,  0x4e,  0x68,  0x05,  0x0a,  0xfe,  0x7a,  0x12,  0xfe,  0x2c,  0x1c,  0xfe,  0xaa,
13496   0xf0,  0xfe,  0xd2,  0x09,  0xfe,  0xac,  0xf0,  0xfe,  0x00,  0x09,  0x02,  0xfe,  0xde,  0x09,  0xfe,  0xb7,
13497   0xf0,  0xfe,  0xfc,  0x08,  0xfe,  0x02,  0xf6,  0x1a,  0x50,  0xfe,  0x70,  0x18,  0xfe,  0xf1,  0x18,  0xfe,
13498   0x40,  0x55,  0xfe,  0xe1,  0x55,  0xfe,  0x10,  0x58,  0xfe,  0x91,  0x58,  0xfe,  0x14,  0x59,  0xfe,  0x95,
13499   0x59,  0x1c,  0x85,  0xfe,  0x8c,  0xf0,  0xfe,  0xfc,  0x08,  0xfe,  0xac,  0xf0,  0xfe,  0xf0,  0x08,  0xb5,
13500   0xfe,  0xcb,  0x10,  0xfe,  0xad,  0xf0,  0xfe,  0x0c,  0x09,  0x02,  0xfe,  0x18,  0x0b,  0xb6,  0xfe,  0xbf,
13501   0x10,  0xfe,  0x2b,  0xf0,  0x85,  0xf4,  0x1e,  0xfe,  0x00,  0xfe,  0xfe,  0x1c,  0x12,  0xc2,  0xfe,  0xd2,
13502   0xf0,  0x85,  0xfe,  0x76,  0x18,  0x1e,  0x19,  0x17,  0x85,  0x03,  0xd2,  0x1e,  0x06,  0x17,  0x85,  0xc5,
13503   0x4a,  0xc6,  0x4a,  0xb5,  0xb6,  0xfe,  0x89,  0x10,  0x74,  0x67,  0x2d,  0x15,  0x9d,  0x01,  0x36,  0x10,
13504   0xfe,  0x35,  0x00,  0xfe,  0x01,  0xf0,  0x65,  0x10,  0x80,  0x02,  0x65,  0xfe,  0x98,  0x80,  0xfe,  0x19,
13505   0xe4,  0x0a,  0xfe,  0x1a,  0x12,  0x51,  0xfe,  0x19,  0x82,  0xfe,  0x6c,  0x18,  0xfe,  0x44,  0x54,  0xbe,
13506   0xfe,  0x19,  0x81,  0xfe,  0x74,  0x18,  0x8f,  0x90,  0x17,  0xfe,  0xce,  0x08,  0x02,  0x4a,  0x08,  0x05,
13507   0x5a,  0xec,  0x03,  0x2e,  0x29,  0x3c,  0x0c,  0x3f,  0x14,  0x40,  0x9b,  0x2e,  0x9c,  0x3c,  0xfe,  0x6c,
13508   0x18,  0xfe,  0xed,  0x18,  0xfe,  0x44,  0x54,  0xfe,  0xe5,  0x54,  0x3a,  0x3f,  0x3b,  0x40,  0x03,  0x49,
13509   0x29,  0x63,  0x8f,  0xfe,  0xe3,  0x54,  0xfe,  0x74,  0x18,  0xfe,  0xf5,  0x18,  0x8f,  0xfe,  0xe3,  0x54,
13510   0x90,  0xc0,  0x56,  0xfe,  0xce,  0x08,  0x02,  0x4a,  0xfe,  0x37,  0xf0,  0xfe,  0xda,  0x09,  0xfe,  0x8b,
13511   0xf0,  0xfe,  0x60,  0x09,  0x02,  0x4a,  0x08,  0x05,  0x0a,  0x23,  0xfe,  0xfa,  0x0a,  0x3a,  0x49,  0x3b,
13512   0x63,  0x56,  0xfe,  0x3e,  0x0a,  0x0f,  0xfe,  0xc0,  0x07,  0x41,  0x98,  0x00,  0xad,  0xfe,  0x01,  0x59,
13513   0xfe,  0x52,  0xf0,  0xfe,  0x0c,  0x0a,  0x8f,  0x7a,  0xfe,  0x24,  0x0a,  0x3a,  0x49,  0x8f,  0xfe,  0xe3,
13514   0x54,  0x57,  0x49,  0x7d,  0x63,  0xfe,  0x14,  0x58,  0xfe,  0x95,  0x58,  0x02,  0x4a,  0x3a,  0x49,  0x3b,
13515   0x63,  0xfe,  0x14,  0x59,  0xfe,  0x95,  0x59,  0xbe,  0x57,  0x49,  0x57,  0x63,  0x02,  0x4a,  0x08,  0x05,
13516   0x5a,  0xfe,  0x82,  0x12,  0x08,  0x05,  0x1f,  0xfe,  0x66,  0x13,  0x22,  0x62,  0xb7,  0xfe,  0x03,  0xa1,
13517   0xfe,  0x83,  0x80,  0xfe,  0xc8,  0x44,  0xfe,  0x2e,  0x13,  0xfe,  0x04,  0x91,  0xfe,  0x86,  0x91,  0x6a,
13518   0x2a,  0xfe,  0x40,  0x59,  0xfe,  0xc1,  0x59,  0x56,  0xe0,  0x03,  0x60,  0x29,  0x61,  0x0c,  0x7f,  0x14,
13519   0x80,  0x57,  0x60,  0x7d,  0x61,  0x01,  0xb3,  0xb8,  0x6a,  0x2a,  0x13,  0x62,  0x9b,  0x2e,  0x9c,  0x3c,
13520   0x3a,  0x3f,  0x3b,  0x40,  0x90,  0xc0,  0xfe,  0x04,  0xfa,  0x2e,  0xfe,  0x05,  0xfa,  0x3c,  0x01,  0xef,
13521   0xfe,  0x36,  0x10,  0x21,  0x0c,  0x7f,  0x0c,  0x80,  0x3a,  0x3f,  0x3b,  0x40,  0xe4,  0x08,  0x05,  0x1f,
13522   0x17,  0xe0,  0x3a,  0x3d,  0x3b,  0x3e,  0x08,  0x05,  0xfe,  0xf7,  0x00,  0x37,  0x03,  0x5e,  0x29,  0x5f,
13523   0xfe,  0x10,  0x58,  0xfe,  0x91,  0x58,  0x57,  0x49,  0x7d,  0x63,  0x02,  0xfe,  0xf4,  0x09,  0x08,  0x05,
13524   0x1f,  0x17,  0xe0,  0x08,  0x05,  0xfe,  0xf7,  0x00,  0x37,  0xbe,  0xfe,  0x19,  0x81,  0x50,  0xfe,  0x10,
13525   0x90,  0xfe,  0x92,  0x90,  0xfe,  0xd3,  0x10,  0x32,  0x07,  0xa6,  0x17,  0xfe,  0x08,  0x09,  0x12,  0xa6,
13526   0x08,  0x05,  0x0a,  0xfe,  0x14,  0x13,  0x03,  0x3d,  0x29,  0x3e,  0x56,  0xfe,  0x08,  0x09,  0xfe,  0x0c,
13527   0x58,  0xfe,  0x8d,  0x58,  0x02,  0x4a,  0x21,  0x41,  0xfe,  0x19,  0x80,  0xe7,  0x08,  0x05,  0x0a,  0xfe,
13528   0x1a,  0x12,  0xfe,  0x6c,  0x19,  0xfe,  0x19,  0x41,  0xf4,  0xc2,  0xfe,  0xd1,  0xf0,  0xe2,  0x15,  0x7e,
13529   0x01,  0x36,  0x10,  0xfe,  0x44,  0x00,  0xfe,  0x8e,  0x10,  0xfe,  0x6c,  0x19,  0x57,  0x3d,  0xfe,  0xed,
13530   0x19,  0x7d,  0x3e,  0xfe,  0x0c,  0x51,  0xfe,  0x8e,  0x51,  0xf4,  0x1e,  0xfe,  0x00,  0xff,  0x35,  0xfe,
13531   0x74,  0x10,  0xc2,  0xfe,  0xd2,  0xf0,  0xfe,  0xa6,  0x0b,  0xfe,  0x76,  0x18,  0x1e,  0x19,  0x8a,  0x03,
13532   0xd2,  0x1e,  0x06,  0xfe,  0x08,  0x13,  0x10,  0xfe,  0x16,  0x00,  0x02,  0x65,  0xfe,  0xd1,  0xf0,  0xfe,
13533   0xb8,  0x0b,  0x15,  0x7e,  0x01,  0x36,  0x10,  0xfe,  0x17,  0x00,  0xfe,  0x42,  0x10,  0xfe,  0xce,  0xf0,
13534   0xfe,  0xbe,  0x0b,  0xfe,  0x3c,  0x10,  0xfe,  0xcd,  0xf0,  0xfe,  0xca,  0x0b,  0x10,  0xfe,  0x22,  0x00,
13535   0x02,  0x65,  0xfe,  0xcb,  0xf0,  0xfe,  0xd6,  0x0b,  0x10,  0xfe,  0x24,  0x00,  0x02,  0x65,  0xfe,  0xd0,
13536   0xf0,  0xfe,  0xe0,  0x0b,  0x10,  0x9e,  0xe5,  0xfe,  0xcf,  0xf0,  0xfe,  0xea,  0x0b,  0x10,  0x58,  0xfe,
13537   0x10,  0x10,  0xfe,  0xcc,  0xf0,  0xe2,  0x68,  0x05,  0x1f,  0x4d,  0x10,  0xfe,  0x12,  0x00,  0x2c,  0x0f,
13538   0xfe,  0x4e,  0x11,  0x27,  0xfe,  0x00,  0x0c,  0xfe,  0x9e,  0xf0,  0xfe,  0x14,  0x0c,  0xbc,  0x17,  0x34,
13539   0x2c,  0x77,  0xe6,  0xc5,  0x24,  0xc6,  0x24,  0x2c,  0xfa,  0x27,  0xfe,  0x20,  0x0c,  0x1c,  0x34,  0x94,
13540   0xfe,  0x3c,  0x0c,  0x95,  0x86,  0xc5,  0xdc,  0xc6,  0xdc,  0x02,  0x24,  0x01,  0x4b,  0xfe,  0xdb,  0x10,
13541   0x12,  0xfe,  0xe8,  0x00,  0xb5,  0xb6,  0x74,  0xc7,  0x81,  0xc8,  0x83,  0xfe,  0x89,  0xf0,  0x24,  0x33,
13542   0x31,  0xe1,  0xc7,  0x81,  0xc8,  0x83,  0x27,  0xfe,  0x66,  0x0c,  0x1d,  0x24,  0x33,  0x31,  0xdf,  0xbc,
13543   0x4e,  0x10,  0xfe,  0x42,  0x00,  0x02,  0x65,  0x7c,  0x06,  0xfe,  0x81,  0x49,  0x17,  0xfe,  0x2c,  0x0d,
13544   0x08,  0x05,  0x0a,  0xfe,  0x44,  0x13,  0x10,  0x00,  0x55,  0x0a,  0xfe,  0x54,  0x12,  0x55,  0xfe,  0x28,
13545   0x00,  0x23,  0xfe,  0x9a,  0x0d,  0x09,  0x46,  0x01,  0x0e,  0x07,  0x00,  0x66,  0x44,  0xfe,  0x28,  0x00,
13546   0xfe,  0xe2,  0x10,  0x01,  0xf5,  0x01,  0xf6,  0x09,  0xa4,  0x01,  0xfe,  0x26,  0x0f,  0x64,  0x12,  0x2f,
13547   0x01,  0x73,  0x02,  0x2b,  0x10,  0xfe,  0x44,  0x00,  0x55,  0x0a,  0xe9,  0x44,  0x0a,  0xfe,  0xb4,  0x10,
13548   0x01,  0xb0,  0x44,  0x0a,  0xfe,  0xaa,  0x10,  0x01,  0xb0,  0xfe,  0x19,  0x82,  0xfe,  0x34,  0x46,  0xac,
13549   0x44,  0x0a,  0x10,  0xfe,  0x43,  0x00,  0xfe,  0x96,  0x10,  0x08,  0x54,  0x0a,  0x37,  0x01,  0xf5,  0x01,
13550   0xf6,  0x64,  0x12,  0x2f,  0x01,  0x73,  0x99,  0x0a,  0x64,  0x42,  0x92,  0x02,  0xfe,  0x2e,  0x03,  0x08,
13551   0x05,  0x0a,  0x8a,  0x44,  0x0a,  0x10,  0x00,  0xfe,  0x5c,  0x10,  0x68,  0x05,  0x1a,  0xfe,  0x58,  0x12,
13552   0x08,  0x05,  0x1a,  0xfe,  0x50,  0x13,  0xfe,  0x1c,  0x1c,  0xfe,  0x9d,  0xf0,  0xfe,  0x50,  0x0d,  0xfe,
13553   0x1c,  0x1c,  0xfe,  0x9d,  0xf0,  0xfe,  0x56,  0x0d,  0x08,  0x54,  0x1a,  0x37,  0xfe,  0xa9,  0x10,  0x10,
13554   0xfe,  0x15,  0x00,  0xfe,  0x04,  0xe6,  0x0a,  0x50,  0xfe,  0x2e,  0x10,  0x10,  0xfe,  0x13,  0x00,  0xfe,
13555   0x10,  0x10,  0x10,  0x6f,  0xab,  0x10,  0xfe,  0x41,  0x00,  0xaa,  0x10,  0xfe,  0x24,  0x00,  0x8c,  0xb5,
13556   0xb6,  0x74,  0x03,  0x70,  0x28,  0x23,  0xd8,  0x50,  0xfe,  0x04,  0xe6,  0x1a,  0xfe,  0x9d,  0x41,  0xfe,
13557   0x1c,  0x42,  0x64,  0x01,  0xe3,  0x02,  0x2b,  0xf8,  0x15,  0x0a,  0x39,  0xa0,  0xb4,  0x15,  0xfe,  0x31,
13558   0x00,  0x39,  0xa2,  0x01,  0xfe,  0x48,  0x10,  0x02,  0xd7,  0x42,  0xfe,  0x06,  0xec,  0xd0,  0xfc,  0x44,
13559   0x1b,  0xfe,  0xce,  0x45,  0x35,  0x42,  0xfe,  0x06,  0xea,  0xd0,  0xfe,  0x47,  0x4b,  0x91,  0xfe,  0x75,
13560   0x57,  0x03,  0x5d,  0xfe,  0x98,  0x56,  0xfe,  0x38,  0x12,  0x09,  0x48,  0x01,  0x0e,  0xfe,  0x44,  0x48,
13561   0x4f,  0x08,  0x05,  0x1b,  0xfe,  0x1a,  0x13,  0x09,  0x46,  0x01,  0x0e,  0x41,  0xfe,  0x41,  0x58,  0x09,
13562   0xa4,  0x01,  0x0e,  0xfe,  0x49,  0x54,  0x96,  0xfe,  0x1e,  0x0e,  0x02,  0xfe,  0x2e,  0x03,  0x09,  0x5d,
13563   0xfe,  0xee,  0x14,  0xfc,  0x44,  0x1b,  0xfe,  0xce,  0x45,  0x35,  0x42,  0xfe,  0xce,  0x47,  0xfe,  0xad,
13564   0x13,  0x02,  0x2b,  0x22,  0x20,  0x07,  0x11,  0xfe,  0x9e,  0x12,  0x21,  0x13,  0x59,  0x13,  0x9f,  0x13,
13565   0xd5,  0x22,  0x2f,  0x41,  0x39,  0x2f,  0xbc,  0xad,  0xfe,  0xbc,  0xf0,  0xfe,  0xe0,  0x0e,  0x0f,  0x06,
13566   0x13,  0x59,  0x01,  0xfe,  0xda,  0x16,  0x03,  0xfe,  0x38,  0x01,  0x29,  0xfe,  0x3a,  0x01,  0x56,  0xfe,
13567   0xe4,  0x0e,  0xfe,  0x02,  0xec,  0xd5,  0x69,  0x00,  0x66,  0xfe,  0x04,  0xec,  0x20,  0x4f,  0xfe,  0x05,
13568   0xf6,  0xfe,  0x34,  0x01,  0x01,  0xfe,  0x4a,  0x17,  0xfe,  0x08,  0x90,  0xfe,  0x48,  0xf4,  0x0d,  0xfe,
13569   0x18,  0x13,  0xba,  0xfe,  0x02,  0xea,  0xd5,  0x69,  0x7e,  0xfe,  0xc5,  0x13,  0x15,  0x1a,  0x39,  0xa0,
13570   0xb4,  0xfe,  0x2e,  0x10,  0x03,  0xfe,  0x38,  0x01,  0x1e,  0xfe,  0xf0,  0xff,  0x0c,  0xfe,  0x60,  0x01,
13571   0x03,  0xfe,  0x3a,  0x01,  0x0c,  0xfe,  0x62,  0x01,  0x43,  0x13,  0x20,  0x25,  0x06,  0x13,  0x2f,  0x12,
13572   0x2f,  0x92,  0x0f,  0x06,  0x04,  0x21,  0x04,  0x22,  0x59,  0xfe,  0xf7,  0x12,  0x22,  0x9f,  0xb7,  0x13,
13573   0x9f,  0x07,  0x7e,  0xfe,  0x71,  0x13,  0xfe,  0x24,  0x1c,  0x15,  0x19,  0x39,  0xa0,  0xb4,  0xfe,  0xd9,
13574   0x10,  0xc3,  0xfe,  0x03,  0xdc,  0xfe,  0x73,  0x57,  0xfe,  0x80,  0x5d,  0x04,  0xc3,  0xfe,  0x03,  0xdc,
13575   0xfe,  0x5b,  0x57,  0xfe,  0x80,  0x5d,  0x04,  0xfe,  0x03,  0x57,  0xc3,  0x21,  0xfe,  0x00,  0xcc,  0x04,
13576   0xfe,  0x03,  0x57,  0xc3,  0x78,  0x04,  0x08,  0x05,  0x58,  0xfe,  0x22,  0x13,  0xfe,  0x1c,  0x80,  0x07,
13577   0x06,  0xfe,  0x1a,  0x13,  0xfe,  0x1e,  0x80,  0xed,  0xfe,  0x1d,  0x80,  0xae,  0xfe,  0x0c,  0x90,  0xfe,
13578   0x0e,  0x13,  0xfe,  0x0e,  0x90,  0xac,  0xfe,  0x3c,  0x90,  0xfe,  0x30,  0xf4,  0x0a,  0xfe,  0x3c,  0x50,
13579   0xaa,  0x01,  0xfe,  0x7a,  0x17,  0x32,  0x07,  0x2f,  0xad,  0x01,  0xfe,  0xb4,  0x16,  0x08,  0x05,  0x1b,
13580   0x4e,  0x01,  0xf5,  0x01,  0xf6,  0x12,  0xfe,  0xe9,  0x00,  0x08,  0x05,  0x58,  0xfe,  0x2c,  0x13,  0x01,
13581   0xfe,  0x0c,  0x17,  0xfe,  0x1e,  0x1c,  0xfe,  0x14,  0x90,  0xfe,  0x96,  0x90,  0x0c,  0xfe,  0x64,  0x01,
13582   0x14,  0xfe,  0x66,  0x01,  0x08,  0x05,  0x5b,  0xfe,  0x12,  0x12,  0xfe,  0x03,  0x80,  0x8d,  0xfe,  0x01,
13583   0xec,  0x20,  0xfe,  0x80,  0x40,  0x13,  0x20,  0x6a,  0x2a,  0x12,  0xcf,  0x64,  0x22,  0x20,  0xfb,  0x79,
13584   0x20,  0x04,  0xfe,  0x08,  0x1c,  0x03,  0xfe,  0xac,  0x00,  0xfe,  0x06,  0x58,  0x03,  0xfe,  0xae,  0x00,
13585
13586   0xfe,  0x07,  0x58,  0x03,  0xfe,  0xb0,  0x00,  0xfe,  0x08,  0x58,  0x03,  0xfe,  0xb2,  0x00,  0xfe,  0x09,
13587   0x58,  0xfe,  0x0a,  0x1c,  0x25,  0x6e,  0x13,  0xd0,  0x21,  0x0c,  0x5c,  0x0c,  0x45,  0x0f,  0x46,  0x52,
13588   0x50,  0x18,  0x1b,  0xfe,  0x90,  0x4d,  0xfe,  0x91,  0x54,  0x23,  0xfe,  0xfc,  0x0f,  0x44,  0x11,  0x0f,
13589   0x48,  0x52,  0x18,  0x58,  0xfe,  0x90,  0x4d,  0xfe,  0x91,  0x54,  0x23,  0xe4,  0x25,  0x11,  0x13,  0x20,
13590   0x7c,  0x6f,  0x4f,  0x22,  0x20,  0xfb,  0x79,  0x20,  0x12,  0xcf,  0xfe,  0x14,  0x56,  0xfe,  0xd6,  0xf0,
13591   0xfe,  0x26,  0x10,  0xf8,  0x74,  0xfe,  0x14,  0x1c,  0xfe,  0x10,  0x1c,  0xfe,  0x18,  0x1c,  0x04,  0x42,
13592   0xfe,  0x0c,  0x14,  0xfc,  0xfe,  0x07,  0xe6,  0x1b,  0xfe,  0xce,  0x47,  0xfe,  0xf5,  0x13,  0x04,  0x01,
13593   0xb0,  0x7c,  0x6f,  0x4f,  0xfe,  0x06,  0x80,  0xfe,  0x48,  0x47,  0xfe,  0x42,  0x13,  0x32,  0x07,  0x2f,
13594   0xfe,  0x34,  0x13,  0x09,  0x48,  0x01,  0x0e,  0xbb,  0xfe,  0x36,  0x12,  0xfe,  0x41,  0x48,  0xfe,  0x45,
13595   0x48,  0x01,  0xf0,  0xfe,  0x00,  0xcc,  0xbb,  0xfe,  0xf3,  0x13,  0x43,  0x78,  0x07,  0x11,  0xac,  0x09,
13596   0x84,  0x01,  0x0e,  0xfe,  0x80,  0x5c,  0x01,  0x73,  0xfe,  0x0e,  0x10,  0x07,  0x82,  0x4e,  0xfe,  0x14,
13597   0x56,  0xfe,  0xd6,  0xf0,  0xfe,  0x60,  0x10,  0x04,  0xfe,  0x44,  0x58,  0x8d,  0xfe,  0x01,  0xec,  0xa2,
13598   0xfe,  0x9e,  0x40,  0xfe,  0x9d,  0xe7,  0x00,  0xfe,  0x9c,  0xe7,  0x1a,  0x79,  0x2a,  0x01,  0xe3,  0xfe,
13599   0xdd,  0x10,  0x2c,  0xc7,  0x81,  0xc8,  0x83,  0x33,  0x31,  0xde,  0x07,  0x1a,  0xfe,  0x48,  0x12,  0x07,
13600   0x0a,  0xfe,  0x56,  0x12,  0x07,  0x19,  0xfe,  0x30,  0x12,  0x07,  0xc9,  0x17,  0xfe,  0x32,  0x12,  0x07,
13601   0xfe,  0x23,  0x00,  0x17,  0xeb,  0x07,  0x06,  0x17,  0xfe,  0x9c,  0x12,  0x07,  0x1f,  0xfe,  0x12,  0x12,
13602   0x07,  0x00,  0x17,  0x24,  0x15,  0xc9,  0x01,  0x36,  0xa9,  0x2d,  0x01,  0x0b,  0x94,  0x4b,  0x04,  0x2d,
13603   0xdd,  0x09,  0xd1,  0x01,  0xfe,  0x26,  0x0f,  0x12,  0x82,  0x02,  0x2b,  0x2d,  0x32,  0x07,  0xa6,  0xfe,
13604   0xd9,  0x13,  0x3a,  0x3d,  0x3b,  0x3e,  0x56,  0xfe,  0xf0,  0x11,  0x08,  0x05,  0x5a,  0xfe,  0x72,  0x12,
13605   0x9b,  0x2e,  0x9c,  0x3c,  0x90,  0xc0,  0x96,  0xfe,  0xba,  0x11,  0x22,  0x62,  0xfe,  0x26,  0x13,  0x03,
13606   0x7f,  0x29,  0x80,  0x56,  0xfe,  0x76,  0x0d,  0x0c,  0x60,  0x14,  0x61,  0x21,  0x0c,  0x7f,  0x0c,  0x80,
13607   0x01,  0xb3,  0x25,  0x6e,  0x77,  0x13,  0x62,  0x01,  0xef,  0x9b,  0x2e,  0x9c,  0x3c,  0xfe,  0x04,  0x55,
13608   0xfe,  0xa5,  0x55,  0xfe,  0x04,  0xfa,  0x2e,  0xfe,  0x05,  0xfa,  0x3c,  0xfe,  0x91,  0x10,  0x03,  0x3f,
13609   0x29,  0x40,  0xfe,  0x40,  0x56,  0xfe,  0xe1,  0x56,  0x0c,  0x3f,  0x14,  0x40,  0x88,  0x9b,  0x2e,  0x9c,
13610   0x3c,  0x90,  0xc0,  0x03,  0x5e,  0x29,  0x5f,  0xfe,  0x00,  0x56,  0xfe,  0xa1,  0x56,  0x0c,  0x5e,  0x14,
13611   0x5f,  0x08,  0x05,  0x5a,  0xfe,  0x1e,  0x12,  0x22,  0x62,  0xfe,  0x1f,  0x40,  0x03,  0x60,  0x29,  0x61,
13612   0xfe,  0x2c,  0x50,  0xfe,  0xae,  0x50,  0x03,  0x3f,  0x29,  0x40,  0xfe,  0x44,  0x50,  0xfe,  0xc6,  0x50,
13613   0x03,  0x5e,  0x29,  0x5f,  0xfe,  0x08,  0x50,  0xfe,  0x8a,  0x50,  0x03,  0x3d,  0x29,  0x3e,  0xfe,  0x40,
13614   0x50,  0xfe,  0xc2,  0x50,  0x02,  0x89,  0x25,  0x06,  0x13,  0xd4,  0x02,  0x72,  0x2d,  0x01,  0x0b,  0x1d,
13615   0x4c,  0x33,  0x31,  0xde,  0x07,  0x06,  0x23,  0x4c,  0x32,  0x07,  0xa6,  0x23,  0x72,  0x01,  0xaf,  0x1e,
13616   0x43,  0x17,  0x4c,  0x08,  0x05,  0x0a,  0xee,  0x3a,  0x3d,  0x3b,  0x3e,  0xfe,  0x0a,  0x55,  0x35,  0xfe,
13617   0x8b,  0x55,  0x57,  0x3d,  0x7d,  0x3e,  0xfe,  0x0c,  0x51,  0xfe,  0x8e,  0x51,  0x02,  0x72,  0xfe,  0x19,
13618   0x81,  0xba,  0xfe,  0x19,  0x41,  0x02,  0x72,  0x2d,  0x01,  0x0b,  0x1c,  0x34,  0x1d,  0xe8,  0x33,  0x31,
13619   0xe1,  0x55,  0x19,  0xfe,  0xa6,  0x12,  0x55,  0x0a,  0x4d,  0x02,  0x4c,  0x01,  0x0b,  0x1c,  0x34,  0x1d,
13620   0xe8,  0x33,  0x31,  0xdf,  0x07,  0x19,  0x23,  0x4c,  0x01,  0x0b,  0x1d,  0xe8,  0x33,  0x31,  0xfe,  0xe8,
13621   0x09,  0xfe,  0xc2,  0x49,  0x51,  0x03,  0xfe,  0x9c,  0x00,  0x28,  0x8a,  0x53,  0x05,  0x1f,  0x35,  0xa9,
13622   0xfe,  0xbb,  0x45,  0x55,  0x00,  0x4e,  0x44,  0x06,  0x7c,  0x43,  0xfe,  0xda,  0x14,  0x01,  0xaf,  0x8c,
13623   0xfe,  0x4b,  0x45,  0xee,  0x32,  0x07,  0xa5,  0xed,  0x03,  0xcd,  0x28,  0x8a,  0x03,  0x45,  0x28,  0x35,
13624   0x67,  0x02,  0x72,  0xfe,  0xc0,  0x5d,  0xfe,  0xf8,  0x14,  0xfe,  0x03,  0x17,  0x03,  0x5c,  0xc1,  0x0c,
13625   0x5c,  0x67,  0x2d,  0x01,  0x0b,  0x26,  0x89,  0x01,  0xfe,  0x9e,  0x15,  0x02,  0x89,  0x01,  0x0b,  0x1c,
13626   0x34,  0x1d,  0x4c,  0x33,  0x31,  0xdf,  0x07,  0x06,  0x23,  0x4c,  0x01,  0xf1,  0xfe,  0x42,  0x58,  0xf1,
13627   0xfe,  0xa4,  0x14,  0x8c,  0xfe,  0x4a,  0xf4,  0x0a,  0x17,  0x4c,  0xfe,  0x4a,  0xf4,  0x06,  0xea,  0x32,
13628   0x07,  0xa5,  0x8b,  0x02,  0x72,  0x03,  0x45,  0xc1,  0x0c,  0x45,  0x67,  0x2d,  0x01,  0x0b,  0x26,  0x89,
13629   0x01,  0xfe,  0xcc,  0x15,  0x02,  0x89,  0x0f,  0x06,  0x27,  0xfe,  0xbe,  0x13,  0x26,  0xfe,  0xd4,  0x13,
13630   0x76,  0xfe,  0x89,  0x48,  0x01,  0x0b,  0x21,  0x76,  0x04,  0x7b,  0xfe,  0xd0,  0x13,  0x1c,  0xfe,  0xd0,
13631   0x13,  0x1d,  0xfe,  0xbe,  0x13,  0x67,  0x2d,  0x01,  0x0b,  0xfe,  0xd5,  0x10,  0x0f,  0x71,  0xff,  0x02,
13632   0x00,  0x57,  0x52,  0x93,  0x1e,  0xfe,  0xff,  0x7f,  0xfe,  0x30,  0x56,  0xfe,  0x00,  0x5c,  0x04,  0x0f,
13633   0x71,  0xff,  0x02,  0x00,  0x57,  0x52,  0x93,  0x1e,  0x43,  0xfe,  0x30,  0x56,  0xfe,  0x00,  0x5c,  0x04,
13634   0x0f,  0x71,  0xff,  0x02,  0x00,  0x57,  0x52,  0x93,  0x04,  0x0f,  0x71,  0xff,  0x02,  0x00,  0x57,  0x52,
13635   0x93,  0xfe,  0x0b,  0x58,  0x04,  0x09,  0x5c,  0x01,  0x87,  0x09,  0x45,  0x01,  0x87,  0x04,  0xfe,  0x03,
13636   0xa1,  0x1e,  0x11,  0xff,  0x03,  0x00,  0x54,  0xfe,  0x00,  0xf4,  0x1f,  0x52,  0xfe,  0x00,  0x7d,  0xfe,
13637   0x01,  0x7d,  0xfe,  0x02,  0x7d,  0xfe,  0x03,  0x7c,  0x6a,  0x2a,  0x0c,  0x5e,  0x14,  0x5f,  0x57,  0x3f,
13638   0x7d,  0x40,  0x04,  0xdd,  0xfe,  0x82,  0x4a,  0xfe,  0xe1,  0x1a,  0xfe,  0x83,  0x5a,  0x8d,  0x04,  0x01,
13639   0xfe,  0x0c,  0x19,  0xfe,  0x42,  0x48,  0x50,  0x51,  0x91,  0x01,  0x0b,  0x1d,  0xfe,  0x96,  0x15,  0x33,
13640   0x31,  0xe1,  0x01,  0x0b,  0x1d,  0xfe,  0x96,  0x15,  0x33,  0x31,  0xfe,  0xe8,  0x0a,  0xfe,  0xc1,  0x59,
13641   0x03,  0xcd,  0x28,  0xfe,  0xcc,  0x12,  0x53,  0x05,  0x1a,  0xfe,  0xc4,  0x13,  0x21,  0x69,  0x1a,  0xee,
13642   0x55,  0xca,  0x6b,  0xfe,  0xdc,  0x14,  0x4d,  0x0f,  0x06,  0x18,  0xca,  0x7c,  0x30,  0xfe,  0x78,  0x10,
13643   0xff,  0x02,  0x83,  0x55,  0xab,  0xff,  0x02,  0x83,  0x55,  0x69,  0x19,  0xae,  0x98,  0xfe,  0x30,  0x00,
13644   0x96,  0xf2,  0x18,  0x6d,  0x0f,  0x06,  0xfe,  0x56,  0x10,  0x69,  0x0a,  0xed,  0x98,  0xfe,  0x64,  0x00,
13645   0x96,  0xf2,  0x09,  0xfe,  0x64,  0x00,  0x18,  0x9e,  0x0f,  0x06,  0xfe,  0x28,  0x10,  0x69,  0x06,  0xfe,
13646   0x60,  0x13,  0x98,  0xfe,  0xc8,  0x00,  0x96,  0xf2,  0x09,  0xfe,  0xc8,  0x00,  0x18,  0x59,  0x0f,  0x06,
13647   0x88,  0x98,  0xfe,  0x90,  0x01,  0x7a,  0xfe,  0x42,  0x15,  0x91,  0xe4,  0xfe,  0x43,  0xf4,  0x9f,  0xfe,
13648   0x56,  0xf0,  0xfe,  0x54,  0x15,  0xfe,  0x04,  0xf4,  0x71,  0xfe,  0x43,  0xf4,  0x9e,  0xfe,  0xf3,  0x10,
13649   0xfe,  0x40,  0x5c,  0x01,  0xfe,  0x16,  0x14,  0x1e,  0x43,  0xec,  0xfe,  0x00,  0x17,  0xfe,  0x4d,  0xe4,
13650   0x6e,  0x7a,  0xfe,  0x90,  0x15,  0xc4,  0x6e,  0xfe,  0x1c,  0x10,  0xfe,  0x00,  0x17,  0xfe,  0x4d,  0xe4,
13651   0xcc,  0x7a,  0xfe,  0x90,  0x15,  0xc4,  0xcc,  0x88,  0x51,  0x21,  0xfe,  0x4d,  0xf4,  0x00,  0xe9,  0x91,
13652   0x0f,  0x06,  0xfe,  0xb4,  0x56,  0xfe,  0xc3,  0x58,  0x04,  0x51,  0x0f,  0x0a,  0x04,  0x16,  0x06,  0x01,
13653   0x0b,  0x26,  0xf3,  0x16,  0x0a,  0x01,  0x0b,  0x26,  0xf3,  0x16,  0x19,  0x01,  0x0b,  0x26,  0xf3,  0x76,
13654   0xfe,  0x89,  0x49,  0x01,  0x0b,  0x04,  0x16,  0x06,  0x01,  0x0b,  0x26,  0xb1,  0x16,  0x19,  0x01,  0x0b,
13655   0x26,  0xb1,  0x16,  0x06,  0x01,  0x0b,  0x26,  0xb1,  0xfe,  0x89,  0x49,  0x01,  0x0b,  0x26,  0xb1,  0x76,
13656   0xfe,  0x89,  0x4a,  0x01,  0x0b,  0x04,  0x51,  0x04,  0x22,  0xd3,  0x07,  0x06,  0xfe,  0x48,  0x13,  0xb8,
13657   0x13,  0xd3,  0xfe,  0x49,  0xf4,  0x00,  0x4d,  0x76,  0xa9,  0x67,  0xfe,  0x01,  0xec,  0xfe,  0x27,  0x01,
13658   0xfe,  0x89,  0x48,  0xff,  0x02,  0x00,  0x10,  0x27,  0xfe,  0x2e,  0x16,  0x32,  0x07,  0xfe,  0xe3,  0x00,
13659   0xfe,  0x20,  0x13,  0x1d,  0xfe,  0x52,  0x16,  0x21,  0x13,  0xd4,  0x01,  0x4b,  0x22,  0xd4,  0x07,  0x06,
13660   0x4e,  0x08,  0x54,  0x06,  0x37,  0x04,  0x09,  0x48,  0x01,  0x0e,  0xfb,  0x8e,  0x07,  0x11,  0xae,  0x09,
13661   0x84,  0x01,  0x0e,  0x8e,  0x09,  0x5d,  0x01,  0xa8,  0x04,  0x09,  0x84,  0x01,  0x0e,  0x8e,  0xfe,  0x80,
13662   0xe7,  0x11,  0x07,  0x11,  0x8a,  0xfe,  0x45,  0x58,  0x01,  0xf0,  0x8e,  0x04,  0x09,  0x48,  0x01,  0x0e,
13663   0x8e,  0x09,  0x5d,  0x01,  0xa8,  0x04,  0x09,  0x48,  0x01,  0x0e,  0xfe,  0x80,  0x80,  0xfe,  0x80,  0x4c,
13664   0xfe,  0x49,  0xe4,  0x11,  0xae,  0x09,  0x84,  0x01,  0x0e,  0xfe,  0x80,  0x4c,  0x09,  0x5d,  0x01,  0x87,
13665   0x04,  0x18,  0x11,  0x75,  0x6c,  0xfe,  0x60,  0x01,  0xfe,  0x18,  0xdf,  0xfe,  0x19,  0xde,  0xfe,  0x24,
13666   0x1c,  0xfe,  0x1d,  0xf7,  0x1b,  0x97,  0xfe,  0xee,  0x16,  0x01,  0xfe,  0xf4,  0x17,  0xad,  0x9a,  0x1b,
13667   0x6c,  0xfe,  0x2c,  0x01,  0xfe,  0x2f,  0x19,  0x04,  0xb9,  0x23,  0xfe,  0xde,  0x16,  0xfe,  0xda,  0x10,
13668   0x18,  0x11,  0x75,  0x03,  0xfe,  0x64,  0x01,  0xfe,  0x00,  0xf4,  0x1f,  0xfe,  0x18,  0x58,  0x03,  0xfe,
13669   0x66,  0x01,  0xfe,  0x19,  0x58,  0x9a,  0x1f,  0xfe,  0x3c,  0x90,  0xfe,  0x30,  0xf4,  0x06,  0xfe,  0x3c,
13670   0x50,  0x6c,  0xfe,  0x38,  0x00,  0xfe,  0x0f,  0x79,  0xfe,  0x1c,  0xf7,  0x1f,  0x97,  0xfe,  0x38,  0x17,
13671   0xfe,  0xb6,  0x14,  0x35,  0x04,  0xb9,  0x23,  0xfe,  0x10,  0x17,  0xfe,  0x9c,  0x10,  0x18,  0x11,  0x75,
13672   0xfe,  0x83,  0x5a,  0xfe,  0x18,  0xdf,  0xfe,  0x19,  0xde,  0xfe,  0x1d,  0xf7,  0x2e,  0x97,  0xfe,  0x5a,
13673   0x17,  0xfe,  0x94,  0x14,  0xec,  0x9a,  0x2e,  0x6c,  0x1a,  0xfe,  0xaf,  0x19,  0xfe,  0x98,  0xe7,  0x00,
13674   0x04,  0xb9,  0x23,  0xfe,  0x4e,  0x17,  0xfe,  0x6c,  0x10,  0x18,  0x11,  0x75,  0xfe,  0x30,  0xbc,  0xfe,
13675   0xb2,  0xbc,  0x9a,  0xcb,  0x6c,  0x1a,  0xfe,  0x0f,  0x79,  0xfe,  0x1c,  0xf7,  0xcb,  0x97,  0xfe,  0x92,
13676   0x17,  0xfe,  0x5c,  0x14,  0x35,  0x04,  0xb9,  0x23,  0xfe,  0x7e,  0x17,  0xfe,  0x42,  0x10,  0xfe,  0x02,
13677   0xf6,  0x11,  0x75,  0xfe,  0x18,  0xfe,  0x60,  0xfe,  0x19,  0xfe,  0x61,  0xfe,  0x03,  0xa1,  0xfe,  0x1d,
13678   0xf7,  0x5b,  0x97,  0xfe,  0xb8,  0x17,  0xfe,  0x36,  0x14,  0xfe,  0x1c,  0x13,  0x9a,  0x5b,  0x41,  0xfe,
13679   0x83,  0x58,  0xfe,  0xaf,  0x19,  0xfe,  0x80,  0xe7,  0x11,  0xfe,  0x81,  0xe7,  0x11,  0x12,  0xfe,  0xdd,
13680   0x00,  0x6a,  0x2a,  0x04,  0x6a,  0x2a,  0xfe,  0x12,  0x45,  0x23,  0xfe,  0xa8,  0x17,  0x15,  0x06,  0x39,
13681   0xa0,  0xb4,  0x02,  0x2b,  0xfe,  0x39,  0xf0,  0xfe,  0xfc,  0x17,  0x21,  0x04,  0xfe,  0x7e,  0x18,  0x1e,
13682   0x19,  0x66,  0x0f,  0x0d,  0x04,  0x75,  0x03,  0xd2,  0x1e,  0x06,  0xfe,  0xef,  0x12,  0xfe,  0xe1,  0x10,
13683   0x7c,  0x6f,  0x4f,  0x32,  0x07,  0x2f,  0xfe,  0x3c,  0x13,  0xf1,  0xfe,  0x42,  0x13,  0x42,  0x92,  0x09,
13684   0x48,  0x01,  0x0e,  0xbb,  0xeb,  0xfe,  0x41,  0x48,  0xfe,  0x45,  0x48,  0x01,  0xf0,  0xfe,  0x00,  0xcc,
13685   0xbb,  0xfe,  0xf3,  0x13,  0x43,  0x78,  0x07,  0x11,  0xac,  0x09,  0x84,  0x01,  0x0e,  0xfe,  0x80,  0x4c,
13686   0x01,  0x73,  0xfe,  0x16,  0x10,  0x07,  0x82,  0x8b,  0xfe,  0x40,  0x14,  0xfe,  0x24,  0x12,  0xfe,  0x14,
13687   0x56,  0xfe,  0xd6,  0xf0,  0xfe,  0x1c,  0x18,  0x18,  0x0a,  0x04,  0xfe,  0x9c,  0xe7,  0x0a,  0x10,  0xfe,
13688   0x15,  0x00,  0x64,  0x79,  0x2a,  0x01,  0xe3,  0x18,  0x06,  0x04,  0x42,  0x92,  0x08,  0x54,  0x1b,  0x37,
13689   0x12,  0x2f,  0x01,  0x73,  0x18,  0x06,  0x04,  0xfe,  0x38,  0x90,  0xfe,  0xba,  0x90,  0x3a,  0xce,  0x3b,
13690   0xcf,  0xfe,  0x48,  0x55,  0x35,  0xfe,  0xc9,  0x55,  0x04,  0x22,  0xa3,  0x77,  0x13,  0xa3,  0x04,  0x09,
13691   0xa4,  0x01,  0x0e,  0xfe,  0x41,  0x48,  0x09,  0x46,  0x01,  0x0e,  0xfe,  0x49,  0x44,  0x17,  0xfe,  0xe8,
13692   0x18,  0x77,  0x78,  0x04,  0x09,  0x48,  0x01,  0x0e,  0x07,  0x11,  0x4e,  0x09,  0x5d,  0x01,  0xa8,  0x09,
13693   0x46,  0x01,  0x0e,  0x77,  0x78,  0x04,  0xfe,  0x4e,  0xe4,  0x19,  0x6b,  0xfe,  0x1c,  0x19,  0x03,  0xfe,
13694   0x90,  0x00,  0xfe,  0x3a,  0x45,  0xfe,  0x2c,  0x10,  0xfe,  0x4e,  0xe4,  0xc9,  0x6b,  0xfe,  0x2e,  0x19,
13695   0x03,  0xfe,  0x92,  0x00,  0xfe,  0x02,  0xe6,  0x1a,  0xe5,  0xfe,  0x4e,  0xe4,  0xfe,  0x0b,  0x00,  0x6b,
13696   0xfe,  0x40,  0x19,  0x03,  0xfe,  0x94,  0x00,  0xfe,  0x02,  0xe6,  0x1f,  0xfe,  0x08,  0x10,  0x03,  0xfe,
13697   0x96,  0x00,  0xfe,  0x02,  0xe6,  0x6d,  0xfe,  0x4e,  0x45,  0xea,  0xba,  0xff,  0x04,  0x68,  0x54,  0xe7,
13698   0x1e,  0x6e,  0xfe,  0x08,  0x1c,  0xfe,  0x67,  0x19,  0xfe,  0x0a,  0x1c,  0xfe,  0x1a,  0xf4,  0xfe,  0x00,
13699   0x04,  0xea,  0xfe,  0x48,  0xf4,  0x19,  0x7a,  0xfe,  0x74,  0x19,  0x0f,  0x19,  0x04,  0x07,  0x7e,  0xfe,
13700   0x5a,  0xf0,  0xfe,  0x84,  0x19,  0x25,  0xfe,  0x09,  0x00,  0xfe,  0x34,  0x10,  0x07,  0x1a,  0xfe,  0x5a,
13701   0xf0,  0xfe,  0x92,  0x19,  0x25,  0xca,  0xfe,  0x26,  0x10,  0x07,  0x19,  0x66,  0x25,  0x6d,  0xe5,  0x07,
13702   0x0a,  0x66,  0x25,  0x9e,  0xfe,  0x0e,  0x10,  0x07,  0x06,  0x66,  0x25,  0x59,  0xa9,  0xb8,  0x04,  0x15,
13703   0xfe,  0x09,  0x00,  0x01,  0x36,  0xfe,  0x04,  0xfe,  0x81,  0x03,  0x83,  0xfe,  0x40,  0x5c,  0x04,  0x1c,
13704   0xf7,  0xfe,  0x14,  0xf0,  0x0b,  0x27,  0xfe,  0xd6,  0x19,  0x1c,  0xf7,  0x7b,  0xf7,  0xfe,  0x82,  0xf0,
13705   0xfe,  0xda,  0x19,  0x04,  0xff,  0xcc,  0x00,  0x00,
13706 };
13707
13708 STATIC unsigned short _adv_asc38C0800_size =
13709         sizeof(_adv_asc38C0800_buf); /* 0x14E1 */
13710 STATIC ADV_DCNT _adv_asc38C0800_chksum =
13711         0x050D3FD8UL; /* Expanded little-endian checksum. */
13712
13713 /* Microcode buffer is kept after initialization for error recovery. */
13714 STATIC unsigned char _adv_asc38C1600_buf[] = {
13715   0x00,  0x00,  0x00,  0xf2,  0x00,  0x16,  0x00,  0xfc,  0x00,  0x10,  0x00,  0xf0,  0x18,  0xe4,  0x01,  0x00,
13716   0x04,  0x1e,  0x48,  0xe4,  0x03,  0xf6,  0xf7,  0x13,  0x2e,  0x1e,  0x02,  0x00,  0x07,  0x17,  0xc0,  0x5f,
13717   0x00,  0xfa,  0xff,  0xff,  0x04,  0x00,  0x00,  0xf6,  0x09,  0xe7,  0x82,  0xe7,  0x85,  0xf0,  0x86,  0xf0,
13718   0x4e,  0x10,  0x9e,  0xe7,  0xff,  0x00,  0x55,  0xf0,  0x01,  0xf6,  0x03,  0x00,  0x98,  0x57,  0x01,  0xe6,
13719   0x00,  0xea,  0x00,  0xec,  0x01,  0xfa,  0x18,  0xf4,  0x08,  0x00,  0xf0,  0x1d,  0x38,  0x54,  0x32,  0xf0,
13720   0x10,  0x00,  0xc2,  0x0e,  0x1e,  0xf0,  0xd5,  0xf0,  0xbc,  0x00,  0x4b,  0xe4,  0x00,  0xe6,  0xb1,  0xf0,
13721   0xb4,  0x00,  0x02,  0x13,  0x3e,  0x1c,  0xc8,  0x47,  0x3e,  0x00,  0xd8,  0x01,  0x06,  0x13,  0x0c,  0x1c,
13722   0x5e,  0x1e,  0x00,  0x57,  0xc8,  0x57,  0x01,  0xfc,  0xbc,  0x0e,  0xa2,  0x12,  0xb9,  0x54,  0x00,  0x80,
13723   0x62,  0x0a,  0x5a,  0x12,  0xc8,  0x15,  0x3e,  0x1e,  0x18,  0x40,  0xbd,  0x56,  0x03,  0xe6,  0x01,  0xea,
13724   0x5c,  0xf0,  0x0f,  0x00,  0x20,  0x00,  0x6c,  0x01,  0x6e,  0x01,  0x04,  0x12,  0x04,  0x13,  0xbb,  0x55,
13725   0x3c,  0x56,  0x3e,  0x57,  0x03,  0x58,  0x4a,  0xe4,  0x40,  0x00,  0xb6,  0x00,  0xbb,  0x00,  0xc0,  0x00,
13726   0x00,  0x01,  0x01,  0x01,  0x3e,  0x01,  0x58,  0x0a,  0x44,  0x10,  0x0a,  0x12,  0x4c,  0x1c,  0x4e,  0x1c,
13727   0x02,  0x4a,  0x30,  0xe4,  0x05,  0xe6,  0x0c,  0x00,  0x3c,  0x00,  0x80,  0x00,  0x24,  0x01,  0x3c,  0x01,
13728   0x68,  0x01,  0x6a,  0x01,  0x70,  0x01,  0x72,  0x01,  0x74,  0x01,  0x76,  0x01,  0x78,  0x01,  0x7c,  0x01,
13729   0xc6,  0x0e,  0x0c,  0x10,  0xac,  0x12,  0xae,  0x12,  0x16,  0x1a,  0x32,  0x1c,  0x6e,  0x1e,  0x02,  0x48,
13730   0x3a,  0x55,  0xc9,  0x57,  0x02,  0xee,  0x5b,  0xf0,  0x03,  0xf7,  0x06,  0xf7,  0x03,  0xfc,  0x06,  0x00,
13731   0x1e,  0x00,  0xbe,  0x00,  0xe1,  0x00,  0x0c,  0x12,  0x18,  0x1a,  0x70,  0x1a,  0x30,  0x1c,  0x38,  0x1c,
13732   0x10,  0x44,  0x00,  0x4c,  0xb0,  0x57,  0x40,  0x5c,  0x4d,  0xe4,  0x04,  0xea,  0x5d,  0xf0,  0xa7,  0xf0,
13733   0x04,  0xf6,  0x02,  0xfc,  0x05,  0x00,  0x09,  0x00,  0x19,  0x00,  0x32,  0x00,  0x33,  0x00,  0x34,  0x00,
13734   0x36,  0x00,  0x98,  0x00,  0x9e,  0x00,  0xcc,  0x00,  0x20,  0x01,  0x4e,  0x01,  0x79,  0x01,  0x3c,  0x09,
13735   0x68,  0x0d,  0x02,  0x10,  0x04,  0x10,  0x3a,  0x10,  0x08,  0x12,  0x0a,  0x13,  0x40,  0x16,  0x50,  0x16,
13736   0x00,  0x17,  0x4a,  0x19,  0x00,  0x4e,  0x00,  0x54,  0x01,  0x58,  0x00,  0xdc,  0x05,  0xf0,  0x09,  0xf0,
13737   0x59,  0xf0,  0xb8,  0xf0,  0x48,  0xf4,  0x0e,  0xf7,  0x0a,  0x00,  0x9b,  0x00,  0x9c,  0x00,  0xa4,  0x00,
13738   0xb5,  0x00,  0xba,  0x00,  0xd0,  0x00,  0xe7,  0x00,  0xf0,  0x03,  0x69,  0x08,  0xe9,  0x09,  0x5c,  0x0c,
13739   0xb6,  0x12,  0xbc,  0x19,  0xd8,  0x1b,  0x20,  0x1c,  0x34,  0x1c,  0x36,  0x1c,  0x42,  0x1d,  0x08,  0x44,
13740   0x38,  0x44,  0x91,  0x44,  0x0a,  0x45,  0x48,  0x46,  0x89,  0x48,  0x68,  0x54,  0x83,  0x55,  0x83,  0x59,
13741   0x31,  0xe4,  0x02,  0xe6,  0x07,  0xf0,  0x08,  0xf0,  0x0b,  0xf0,  0x0c,  0xf0,  0x4b,  0xf4,  0x04,  0xf8,
13742   0x05,  0xf8,  0x02,  0xfa,  0x03,  0xfa,  0x04,  0xfc,  0x05,  0xfc,  0x07,  0x00,  0xa8,  0x00,  0xaa,  0x00,
13743   0xb9,  0x00,  0xe0,  0x00,  0xe5,  0x00,  0x22,  0x01,  0x26,  0x01,  0x60,  0x01,  0x7a,  0x01,  0x82,  0x01,
13744   0xc8,  0x01,  0xca,  0x01,  0x86,  0x02,  0x6a,  0x03,  0x18,  0x05,  0xb2,  0x07,  0x68,  0x08,  0x10,  0x0d,
13745   0x06,  0x10,  0x0a,  0x10,  0x0e,  0x10,  0x12,  0x10,  0x60,  0x10,  0xed,  0x10,  0xf3,  0x10,  0x06,  0x12,
13746   0x10,  0x12,  0x1e,  0x12,  0x0c,  0x13,  0x0e,  0x13,  0x10,  0x13,  0xfe,  0x9c,  0xf0,  0x35,  0x05,  0xfe,
13747   0xec,  0x0e,  0xff,  0x10,  0x00,  0x00,  0xe9,  0xfe,  0x34,  0x1f,  0x00,  0xe8,  0xfe,  0x88,  0x01,  0xff,
13748   0x03,  0x00,  0x00,  0xfe,  0x93,  0x15,  0xfe,  0x0f,  0x05,  0xff,  0x38,  0x00,  0x00,  0xfe,  0x57,  0x24,
13749   0x00,  0xfe,  0x4c,  0x00,  0x65,  0xff,  0x04,  0x00,  0x00,  0x1a,  0xff,  0x09,  0x00,  0x00,  0xff,  0x08,
13750   0x01,  0x01,  0xff,  0x08,  0xff,  0xff,  0xff,  0x27,  0x00,  0x00,  0xff,  0x10,  0xff,  0xff,  0xff,  0x13,
13751   0x00,  0x00,  0xfe,  0x78,  0x56,  0xfe,  0x34,  0x12,  0xff,  0x21,  0x00,  0x00,  0xfe,  0x04,  0xf7,  0xe8,
13752   0x37,  0x7d,  0x0d,  0x01,  0xfe,  0x4a,  0x11,  0xfe,  0x04,  0xf7,  0xe8,  0x7d,  0x0d,  0x51,  0x37,  0xfe,
13753   0x3d,  0xf0,  0xfe,  0x0c,  0x02,  0xfe,  0x20,  0xf0,  0xbc,  0xfe,  0x91,  0xf0,  0xfe,  0xf8,  0x01,  0xfe,
13754   0x90,  0xf0,  0xfe,  0xf8,  0x01,  0xfe,  0x8f,  0xf0,  0xbc,  0x03,  0x67,  0x4d,  0x05,  0xfe,  0x08,  0x0f,
13755   0x01,  0xfe,  0x78,  0x0f,  0xfe,  0xdd,  0x12,  0x05,  0xfe,  0x0e,  0x03,  0xfe,  0x28,  0x1c,  0x03,  0xfe,
13756   0xa6,  0x00,  0xfe,  0xd1,  0x12,  0x3e,  0x22,  0xfe,  0xa6,  0x00,  0xac,  0xfe,  0x48,  0xf0,  0xfe,  0x90,
13757   0x02,  0xfe,  0x49,  0xf0,  0xfe,  0xaa,  0x02,  0xfe,  0x4a,  0xf0,  0xfe,  0xc8,  0x02,  0xfe,  0x46,  0xf0,
13758   0xfe,  0x5a,  0x02,  0xfe,  0x47,  0xf0,  0xfe,  0x60,  0x02,  0xfe,  0x43,  0xf0,  0xfe,  0x4e,  0x02,  0xfe,
13759   0x44,  0xf0,  0xfe,  0x52,  0x02,  0xfe,  0x45,  0xf0,  0xfe,  0x56,  0x02,  0x1c,  0x0d,  0xa2,  0x1c,  0x07,
13760   0x22,  0xb7,  0x05,  0x35,  0xfe,  0x00,  0x1c,  0xfe,  0xf1,  0x10,  0xfe,  0x02,  0x1c,  0xf5,  0xfe,  0x1e,
13761   0x1c,  0xfe,  0xe9,  0x10,  0x01,  0x5f,  0xfe,  0xe7,  0x10,  0xfe,  0x06,  0xfc,  0xde,  0x0a,  0x81,  0x01,
13762   0xa3,  0x05,  0x35,  0x1f,  0x95,  0x47,  0xb8,  0x01,  0xfe,  0xe4,  0x11,  0x0a,  0x81,  0x01,  0x5c,  0xfe,
13763   0xbd,  0x10,  0x0a,  0x81,  0x01,  0x5c,  0xfe,  0xad,  0x10,  0xfe,  0x16,  0x1c,  0xfe,  0x58,  0x1c,  0x1c,
13764   0x07,  0x22,  0xb7,  0x37,  0x2a,  0x35,  0xfe,  0x3d,  0xf0,  0xfe,  0x0c,  0x02,  0x2b,  0xfe,  0x9e,  0x02,
13765   0xfe,  0x5a,  0x1c,  0xfe,  0x12,  0x1c,  0xfe,  0x14,  0x1c,  0x1f,  0xfe,  0x30,  0x00,  0x47,  0xb8,  0x01,
13766   0xfe,  0xd4,  0x11,  0x1c,  0x07,  0x22,  0xb7,  0x05,  0xe9,  0x21,  0x2c,  0x09,  0x1a,  0x31,  0xfe,  0x69,
13767   0x10,  0x1c,  0x07,  0x22,  0xb7,  0xfe,  0x04,  0xec,  0x2c,  0x60,  0x01,  0xfe,  0x1e,  0x1e,  0x20,  0x2c,
13768   0xfe,  0x05,  0xf6,  0xde,  0x01,  0xfe,  0x62,  0x1b,  0x01,  0x0c,  0x61,  0x4a,  0x44,  0x15,  0x56,  0x51,
13769   0x01,  0xfe,  0x9e,  0x1e,  0x01,  0xfe,  0x96,  0x1a,  0x05,  0x35,  0x0a,  0x57,  0x01,  0x18,  0x09,  0x00,
13770   0x36,  0x01,  0x85,  0xfe,  0x18,  0x10,  0xfe,  0x41,  0x58,  0x0a,  0xba,  0x01,  0x18,  0xfe,  0xc8,  0x54,
13771   0x7b,  0xfe,  0x1c,  0x03,  0x01,  0xfe,  0x96,  0x1a,  0x05,  0x35,  0x37,  0x60,  0xfe,  0x02,  0xe8,  0x30,
13772   0xfe,  0xbf,  0x57,  0xfe,  0x9e,  0x43,  0xfe,  0x77,  0x57,  0xfe,  0x27,  0xf0,  0xfe,  0xe4,  0x01,  0xfe,
13773   0x07,  0x4b,  0xfe,  0x20,  0xf0,  0xbc,  0xfe,  0x40,  0x1c,  0x2a,  0xeb,  0xfe,  0x26,  0xf0,  0xfe,  0x66,
13774   0x03,  0xfe,  0xa0,  0xf0,  0xfe,  0x54,  0x03,  0xfe,  0x11,  0xf0,  0xbc,  0xfe,  0xef,  0x10,  0xfe,  0x9f,
13775   0xf0,  0xfe,  0x74,  0x03,  0xfe,  0x46,  0x1c,  0x19,  0xfe,  0x11,  0x00,  0x05,  0x70,  0x37,  0xfe,  0x48,
13776   0x1c,  0xfe,  0x46,  0x1c,  0x01,  0x0c,  0x06,  0x28,  0xfe,  0x18,  0x13,  0x26,  0x21,  0xb9,  0xc7,  0x20,
13777   0xb9,  0x0a,  0x57,  0x01,  0x18,  0xc7,  0x89,  0x01,  0xfe,  0xc8,  0x1a,  0x15,  0xe1,  0x2a,  0xeb,  0xfe,
13778   0x01,  0xf0,  0xeb,  0xfe,  0x82,  0xf0,  0xfe,  0xa4,  0x03,  0xfe,  0x9c,  0x32,  0x15,  0xfe,  0xe4,  0x00,
13779   0x2f,  0xfe,  0xb6,  0x03,  0x2a,  0x3c,  0x16,  0xfe,  0xc6,  0x03,  0x01,  0x41,  0xfe,  0x06,  0xf0,  0xfe,
13780   0xd6,  0x03,  0xaf,  0xa0,  0xfe,  0x0a,  0xf0,  0xfe,  0xa2,  0x07,  0x05,  0x29,  0x03,  0x81,  0x1e,  0x1b,
13781   0xfe,  0x24,  0x05,  0x1f,  0x63,  0x01,  0x42,  0x8f,  0xfe,  0x70,  0x02,  0x05,  0xea,  0xfe,  0x46,  0x1c,
13782   0x37,  0x7d,  0x1d,  0xfe,  0x67,  0x1b,  0xfe,  0xbf,  0x57,  0xfe,  0x77,  0x57,  0xfe,  0x48,  0x1c,  0x75,
13783   0x01,  0xa6,  0x86,  0x0a,  0x57,  0x01,  0x18,  0x09,  0x00,  0x1b,  0xec,  0x0a,  0xe1,  0x01,  0x18,  0x77,
13784   0x50,  0x40,  0x8d,  0x30,  0x03,  0x81,  0x1e,  0xf8,  0x1f,  0x63,  0x01,  0x42,  0x8f,  0xfe,  0x70,  0x02,
13785   0x05,  0xea,  0xd7,  0x99,  0xd8,  0x9c,  0x2a,  0x29,  0x2f,  0xfe,  0x4e,  0x04,  0x16,  0xfe,  0x4a,  0x04,
13786   0x7e,  0xfe,  0xa0,  0x00,  0xfe,  0x9b,  0x57,  0xfe,  0x54,  0x12,  0x32,  0xff,  0x02,  0x00,  0x10,  0x01,
13787   0x08,  0x16,  0xfe,  0x02,  0x05,  0x32,  0x01,  0x08,  0x16,  0x29,  0x27,  0x25,  0xee,  0xfe,  0x4c,  0x44,
13788   0xfe,  0x58,  0x12,  0x50,  0xfe,  0x44,  0x48,  0x13,  0x34,  0xfe,  0x4c,  0x54,  0x7b,  0xec,  0x60,  0x8d,
13789   0x30,  0x01,  0xfe,  0x4e,  0x1e,  0xfe,  0x48,  0x47,  0xfe,  0x7c,  0x13,  0x01,  0x0c,  0x06,  0x28,  0xfe,
13790   0x32,  0x13,  0x01,  0x43,  0x09,  0x9b,  0xfe,  0x68,  0x13,  0xfe,  0x26,  0x10,  0x13,  0x34,  0xfe,  0x4c,
13791   0x54,  0x7b,  0xec,  0x01,  0xfe,  0x4e,  0x1e,  0xfe,  0x48,  0x47,  0xfe,  0x54,  0x13,  0x01,  0x0c,  0x06,
13792   0x28,  0xa5,  0x01,  0x43,  0x09,  0x9b,  0xfe,  0x40,  0x13,  0x01,  0x0c,  0x06,  0x28,  0xf9,  0x1f,  0x7f,
13793   0x01,  0x0c,  0x06,  0x07,  0x4d,  0x1f,  0xfe,  0x0d,  0x00,  0x01,  0x42,  0x8f,  0xfe,  0xa4,  0x0e,  0x05,
13794   0x29,  0x32,  0x15,  0xfe,  0xe6,  0x00,  0x0f,  0xfe,  0x1c,  0x90,  0x04,  0xfe,  0x9c,  0x93,  0x3a,  0x0b,
13795   0x0e,  0x8b,  0x02,  0x1f,  0x7f,  0x01,  0x42,  0x05,  0x35,  0xfe,  0x42,  0x5b,  0x7d,  0x1d,  0xfe,  0x46,
13796   0x59,  0xfe,  0xbf,  0x57,  0xfe,  0x77,  0x57,  0x0f,  0xfe,  0x87,  0x80,  0x04,  0xfe,  0x87,  0x83,  0xfe,
13797   0xc9,  0x47,  0x0b,  0x0e,  0xd0,  0x65,  0x01,  0x0c,  0x06,  0x0d,  0xfe,  0x98,  0x13,  0x0f,  0xfe,  0x20,
13798   0x80,  0x04,  0xfe,  0xa0,  0x83,  0x33,  0x0b,  0x0e,  0x09,  0x1d,  0xfe,  0x84,  0x12,  0x01,  0x38,  0x06,
13799   0x07,  0xfe,  0x70,  0x13,  0x03,  0xfe,  0xa2,  0x00,  0x1e,  0x1b,  0xfe,  0xda,  0x05,  0xd0,  0x54,  0x01,
13800   0x38,  0x06,  0x0d,  0xfe,  0x58,  0x13,  0x03,  0xfe,  0xa0,  0x00,  0x1e,  0xfe,  0x50,  0x12,  0x5e,  0xff,
13801   0x02,  0x00,  0x10,  0x2f,  0xfe,  0x90,  0x05,  0x2a,  0x3c,  0xcc,  0xff,  0x02,  0x00,  0x10,  0x2f,  0xfe,
13802   0x9e,  0x05,  0x17,  0xfe,  0xf4,  0x05,  0x15,  0xfe,  0xe3,  0x00,  0x26,  0x01,  0x38,  0xfe,  0x4a,  0xf0,
13803   0xfe,  0xc0,  0x05,  0xfe,  0x49,  0xf0,  0xfe,  0xba,  0x05,  0x71,  0x2e,  0xfe,  0x21,  0x00,  0xf1,  0x2e,
13804   0xfe,  0x22,  0x00,  0xa2,  0x2e,  0x4a,  0xfe,  0x09,  0x48,  0xff,  0x02,  0x00,  0x10,  0x2f,  0xfe,  0xd0,
13805   0x05,  0x17,  0xfe,  0xf4,  0x05,  0xfe,  0xe2,  0x08,  0x01,  0x38,  0x06,  0xfe,  0x1c,  0x00,  0x4d,  0x01,
13806   0xa7,  0x2e,  0x07,  0x20,  0xe4,  0x47,  0xfe,  0x27,  0x01,  0x01,  0x0c,  0x06,  0x28,  0xfe,  0x24,  0x12,
13807   0x3e,  0x01,  0x84,  0x1f,  0x7f,  0x01,  0x0c,  0x06,  0x07,  0x4d,  0x1f,  0xfe,  0x0d,  0x00,  0x01,  0x42,
13808   0x8f,  0xfe,  0xa4,  0x0e,  0x05,  0x29,  0x03,  0xe6,  0x1e,  0xfe,  0xca,  0x13,  0x03,  0xb6,  0x1e,  0xfe,
13809   0x40,  0x12,  0x03,  0x66,  0x1e,  0xfe,  0x38,  0x13,  0x3e,  0x01,  0x84,  0x17,  0xfe,  0x72,  0x06,  0x0a,
13810   0x07,  0x01,  0x38,  0x06,  0x24,  0xfe,  0x02,  0x12,  0x4f,  0x01,  0xfe,  0x56,  0x19,  0x16,  0xfe,  0x68,
13811   0x06,  0x15,  0x82,  0x01,  0x41,  0x15,  0xe2,  0x03,  0x66,  0x8a,  0x10,  0x66,  0x03,  0x9a,  0x1e,  0xfe,
13812   0x70,  0x12,  0x03,  0x55,  0x1e,  0xfe,  0x68,  0x13,  0x01,  0xc6,  0x09,  0x12,  0x48,  0xfe,  0x92,  0x06,
13813   0x2e,  0x12,  0x01,  0xfe,  0xac,  0x1d,  0xfe,  0x43,  0x48,  0x62,  0x80,  0x13,  0x58,  0xff,  0x02,  0x00,
13814   0x57,  0x52,  0xad,  0x23,  0x3f,  0x4e,  0x62,  0x49,  0x3e,  0x01,  0x84,  0x17,  0xfe,  0xea,  0x06,  0x01,
13815   0x38,  0x06,  0x12,  0xf7,  0x45,  0x0a,  0x95,  0x01,  0xfe,  0x84,  0x19,  0x16,  0xfe,  0xe0,  0x06,  0x15,
13816   0x82,  0x01,  0x41,  0x15,  0xe2,  0x03,  0x55,  0x8a,  0x10,  0x55,  0x1c,  0x07,  0x01,  0x84,  0xfe,  0xae,
13817   0x10,  0x03,  0x6f,  0x1e,  0xfe,  0x9e,  0x13,  0x3e,  0x01,  0x84,  0x03,  0x9a,  0x1e,  0xfe,  0x1a,  0x12,
13818   0x01,  0x38,  0x06,  0x12,  0xfc,  0x01,  0xc6,  0x01,  0xfe,  0xac,  0x1d,  0xfe,  0x43,  0x48,  0x62,  0x80,
13819   0xf0,  0x45,  0x0a,  0x95,  0x03,  0xb6,  0x1e,  0xf8,  0x01,  0x38,  0x06,  0x24,  0x36,  0xfe,  0x02,  0xf6,
13820   0x07,  0x71,  0x78,  0x8c,  0x00,  0x4d,  0x62,  0x49,  0x3e,  0x2d,  0x93,  0x4e,  0xd0,  0x0d,  0x17,  0xfe,
13821   0x9a,  0x07,  0x01,  0xfe,  0xc0,  0x19,  0x16,  0xfe,  0x90,  0x07,  0x26,  0x20,  0x9e,  0x15,  0x82,  0x01,
13822   0x41,  0x15,  0xe2,  0x21,  0x9e,  0x09,  0x07,  0xfb,  0x03,  0xe6,  0xfe,  0x58,  0x57,  0x10,  0xe6,  0x05,
13823   0xfe,  0x2a,  0x06,  0x03,  0x6f,  0x8a,  0x10,  0x6f,  0x1c,  0x07,  0x01,  0x84,  0xfe,  0x9c,  0x32,  0x5f,
13824   0x75,  0x01,  0xa6,  0x86,  0x15,  0xfe,  0xe2,  0x00,  0x2f,  0xed,  0x2a,  0x3c,  0xfe,  0x0a,  0xf0,  0xfe,
13825   0xce,  0x07,  0xae,  0xfe,  0x96,  0x08,  0xfe,  0x06,  0xf0,  0xfe,  0x9e,  0x08,  0xaf,  0xa0,  0x05,  0x29,
13826   0x01,  0x0c,  0x06,  0x0d,  0xfe,  0x2e,  0x12,  0x14,  0x1d,  0x01,  0x08,  0x14,  0x00,  0x01,  0x08,  0x14,
13827   0x00,  0x01,  0x08,  0x14,  0x00,  0x01,  0x08,  0xfe,  0x99,  0xa4,  0x01,  0x08,  0x14,  0x00,  0x05,  0xfe,
13828   0xc6,  0x09,  0x01,  0x76,  0x06,  0x12,  0xfe,  0x3a,  0x12,  0x01,  0x0c,  0x06,  0x12,  0xfe,  0x30,  0x13,
13829   0x14,  0xfe,  0x1b,  0x00,  0x01,  0x08,  0x14,  0x00,  0x01,  0x08,  0x14,  0x00,  0x01,  0x08,  0x14,  0x00,
13830   0x01,  0x08,  0x14,  0x07,  0x01,  0x08,  0x14,  0x00,  0x05,  0xef,  0x7c,  0x4a,  0x78,  0x4f,  0x0f,  0xfe,
13831   0x9a,  0x81,  0x04,  0xfe,  0x9a,  0x83,  0xfe,  0xcb,  0x47,  0x0b,  0x0e,  0x2d,  0x28,  0x48,  0xfe,  0x6c,
13832   0x08,  0x0a,  0x28,  0xfe,  0x09,  0x6f,  0xca,  0xfe,  0xca,  0x45,  0xfe,  0x32,  0x12,  0x53,  0x63,  0x4e,
13833   0x7c,  0x97,  0x2f,  0xfe,  0x7e,  0x08,  0x2a,  0x3c,  0xfe,  0x0a,  0xf0,  0xfe,  0x6c,  0x08,  0xaf,  0xa0,
13834   0xae,  0xfe,  0x96,  0x08,  0x05,  0x29,  0x01,  0x41,  0x05,  0xed,  0x14,  0x24,  0x05,  0xed,  0xfe,  0x9c,
13835   0xf7,  0x9f,  0x01,  0xfe,  0xae,  0x1e,  0xfe,  0x18,  0x58,  0x01,  0xfe,  0xbe,  0x1e,  0xfe,  0x99,  0x58,
13836   0xfe,  0x78,  0x18,  0xfe,  0xf9,  0x18,  0x8e,  0xfe,  0x16,  0x09,  0x10,  0x6a,  0x22,  0x6b,  0x01,  0x0c,
13837   0x61,  0x54,  0x44,  0x21,  0x2c,  0x09,  0x1a,  0xf8,  0x77,  0x01,  0xfe,  0x7e,  0x1e,  0x47,  0x2c,  0x7a,
13838   0x30,  0xf0,  0xfe,  0x83,  0xe7,  0xfe,  0x3f,  0x00,  0x71,  0xfe,  0x03,  0x40,  0x01,  0x0c,  0x61,  0x65,
13839   0x44,  0x01,  0xc2,  0xc8,  0xfe,  0x1f,  0x40,  0x20,  0x6e,  0x01,  0xfe,  0x6a,  0x16,  0xfe,  0x08,  0x50,
13840   0xfe,  0x8a,  0x50,  0xfe,  0x44,  0x51,  0xfe,  0xc6,  0x51,  0xfe,  0x10,  0x10,  0x01,  0xfe,  0xce,  0x1e,
13841   0x01,  0xfe,  0xde,  0x1e,  0x10,  0x68,  0x22,  0x69,  0x01,  0xfe,  0xee,  0x1e,  0x01,  0xfe,  0xfe,  0x1e,
13842   0xfe,  0x40,  0x50,  0xfe,  0xc2,  0x50,  0x10,  0x4b,  0x22,  0x4c,  0xfe,  0x8a,  0x10,  0x01,  0x0c,  0x06,
13843   0x54,  0xfe,  0x50,  0x12,  0x01,  0xfe,  0xae,  0x1e,  0x01,  0xfe,  0xbe,  0x1e,  0x10,  0x6a,  0x22,  0x6b,
13844   0x01,  0x0c,  0x06,  0x65,  0x4e,  0x01,  0xc2,  0x0f,  0xfe,  0x1f,  0x80,  0x04,  0xfe,  0x9f,  0x83,  0x33,
13845   0x0b,  0x0e,  0x20,  0x6e,  0x0f,  0xfe,  0x44,  0x90,  0x04,  0xfe,  0xc4,  0x93,  0x3a,  0x0b,  0xfe,  0xc6,
13846   0x90,  0x04,  0xfe,  0xc6,  0x93,  0x79,  0x0b,  0x0e,  0x10,  0x6c,  0x22,  0x6d,  0x01,  0xfe,  0xce,  0x1e,
13847   0x01,  0xfe,  0xde,  0x1e,  0x10,  0x68,  0x22,  0x69,  0x0f,  0xfe,  0x40,  0x90,  0x04,  0xfe,  0xc0,  0x93,
13848   0x3a,  0x0b,  0xfe,  0xc2,  0x90,  0x04,  0xfe,  0xc2,  0x93,  0x79,  0x0b,  0x0e,  0x10,  0x4b,  0x22,  0x4c,
13849   0x10,  0x64,  0x22,  0x34,  0x01,  0x0c,  0x61,  0x24,  0x44,  0x37,  0x13,  0xfe,  0x4e,  0x11,  0x2f,  0xfe,
13850   0xde,  0x09,  0xfe,  0x9e,  0xf0,  0xfe,  0xf2,  0x09,  0xfe,  0x01,  0x48,  0x1b,  0x3c,  0x37,  0x88,  0xf5,
13851   0xd4,  0xfe,  0x1e,  0x0a,  0xd5,  0xfe,  0x42,  0x0a,  0xd2,  0xfe,  0x1e,  0x0a,  0xd3,  0xfe,  0x42,  0x0a,
13852   0xae,  0xfe,  0x12,  0x0a,  0xfe,  0x06,  0xf0,  0xfe,  0x18,  0x0a,  0xaf,  0xa0,  0x05,  0x29,  0x01,  0x41,
13853   0xfe,  0xc1,  0x10,  0x14,  0x24,  0xfe,  0xc1,  0x10,  0x01,  0x76,  0x06,  0x07,  0xfe,  0x14,  0x12,  0x01,
13854   0x76,  0x06,  0x0d,  0x5d,  0x01,  0x0c,  0x06,  0x0d,  0xfe,  0x74,  0x12,  0xfe,  0x2e,  0x1c,  0x05,  0xfe,
13855   0x1a,  0x0c,  0x01,  0x76,  0x06,  0x07,  0x5d,  0x01,  0x76,  0x06,  0x0d,  0x41,  0xfe,  0x2c,  0x1c,  0xfe,
13856   0xaa,  0xf0,  0xfe,  0xce,  0x0a,  0xfe,  0xac,  0xf0,  0xfe,  0x66,  0x0a,  0xfe,  0x92,  0x10,  0xc4,  0xf6,
13857   0xfe,  0xad,  0xf0,  0xfe,  0x72,  0x0a,  0x05,  0xfe,  0x1a,  0x0c,  0xc5,  0xfe,  0xe7,  0x10,  0xfe,  0x2b,
13858   0xf0,  0xbf,  0xfe,  0x6b,  0x18,  0x23,  0xfe,  0x00,  0xfe,  0xfe,  0x1c,  0x12,  0xac,  0xfe,  0xd2,  0xf0,
13859   0xbf,  0xfe,  0x76,  0x18,  0x23,  0x1d,  0x1b,  0xbf,  0x03,  0xe3,  0x23,  0x07,  0x1b,  0xbf,  0xd4,  0x5b,
13860   0xd5,  0x5b,  0xd2,  0x5b,  0xd3,  0x5b,  0xc4,  0xc5,  0xfe,  0xa9,  0x10,  0x75,  0x5e,  0x32,  0x1f,  0x7f,
13861   0x01,  0x42,  0x19,  0xfe,  0x35,  0x00,  0xfe,  0x01,  0xf0,  0x70,  0x19,  0x98,  0x05,  0x70,  0xfe,  0x74,
13862   0x18,  0x23,  0xfe,  0x00,  0xf8,  0x1b,  0x5b,  0x7d,  0x12,  0x01,  0xfe,  0x78,  0x0f,  0x4d,  0x01,  0xfe,
13863   0x96,  0x1a,  0x21,  0x30,  0x77,  0x7d,  0x1d,  0x05,  0x5b,  0x01,  0x0c,  0x06,  0x0d,  0x2b,  0xfe,  0xe2,
13864   0x0b,  0x01,  0x0c,  0x06,  0x54,  0xfe,  0xa6,  0x12,  0x01,  0x0c,  0x06,  0x24,  0xfe,  0x88,  0x13,  0x21,
13865   0x6e,  0xc7,  0x01,  0xfe,  0x1e,  0x1f,  0x0f,  0xfe,  0x83,  0x80,  0x04,  0xfe,  0x83,  0x83,  0xfe,  0xc9,
13866   0x47,  0x0b,  0x0e,  0xfe,  0xc8,  0x44,  0xfe,  0x42,  0x13,  0x0f,  0xfe,  0x04,  0x91,  0x04,  0xfe,  0x84,
13867   0x93,  0xfe,  0xca,  0x57,  0x0b,  0xfe,  0x86,  0x91,  0x04,  0xfe,  0x86,  0x93,  0xfe,  0xcb,  0x57,  0x0b,
13868   0x0e,  0x7a,  0x30,  0xfe,  0x40,  0x59,  0xfe,  0xc1,  0x59,  0x8e,  0x40,  0x03,  0x6a,  0x3b,  0x6b,  0x10,
13869   0x97,  0x22,  0x98,  0xd9,  0x6a,  0xda,  0x6b,  0x01,  0xc2,  0xc8,  0x7a,  0x30,  0x20,  0x6e,  0xdb,  0x64,
13870   0xdc,  0x34,  0x91,  0x6c,  0x7e,  0x6d,  0xfe,  0x44,  0x55,  0xfe,  0xe5,  0x55,  0xfe,  0x04,  0xfa,  0x64,
13871   0xfe,  0x05,  0xfa,  0x34,  0x01,  0xfe,  0x6a,  0x16,  0xa3,  0x26,  0x10,  0x97,  0x10,  0x98,  0x91,  0x6c,
13872   0x7e,  0x6d,  0xfe,  0x14,  0x10,  0x01,  0x0c,  0x06,  0x24,  0x1b,  0x40,  0x91,  0x4b,  0x7e,  0x4c,  0x01,
13873   0x0c,  0x06,  0xfe,  0xf7,  0x00,  0x44,  0x03,  0x68,  0x3b,  0x69,  0xfe,  0x10,  0x58,  0xfe,  0x91,  0x58,
13874   0xfe,  0x14,  0x59,  0xfe,  0x95,  0x59,  0x05,  0x5b,  0x01,  0x0c,  0x06,  0x24,  0x1b,  0x40,  0x01,  0x0c,
13875   0x06,  0xfe,  0xf7,  0x00,  0x44,  0x78,  0x01,  0xfe,  0x8e,  0x1e,  0x4f,  0x0f,  0xfe,  0x10,  0x90,  0x04,
13876   0xfe,  0x90,  0x93,  0x3a,  0x0b,  0xfe,  0x92,  0x90,  0x04,  0xfe,  0x92,  0x93,  0x79,  0x0b,  0x0e,  0xfe,
13877   0xbd,  0x10,  0x01,  0x43,  0x09,  0xbb,  0x1b,  0xfe,  0x6e,  0x0a,  0x15,  0xbb,  0x01,  0x0c,  0x06,  0x0d,
13878   0xfe,  0x14,  0x13,  0x03,  0x4b,  0x3b,  0x4c,  0x8e,  0xfe,  0x6e,  0x0a,  0xfe,  0x0c,  0x58,  0xfe,  0x8d,
13879   0x58,  0x05,  0x5b,  0x26,  0x3e,  0x0f,  0xfe,  0x19,  0x80,  0x04,  0xfe,  0x99,  0x83,  0x33,  0x0b,  0x0e,
13880   0xfe,  0xe5,  0x10,  0x01,  0x0c,  0x06,  0x0d,  0xfe,  0x1a,  0x12,  0xfe,  0x6c,  0x19,  0xfe,  0x19,  0x41,
13881   0xfe,  0x6b,  0x18,  0xac,  0xfe,  0xd1,  0xf0,  0xef,  0x1f,  0x92,  0x01,  0x42,  0x19,  0xfe,  0x44,  0x00,
13882   0xfe,  0x90,  0x10,  0xfe,  0x6c,  0x19,  0xd9,  0x4b,  0xfe,  0xed,  0x19,  0xda,  0x4c,  0xfe,  0x0c,  0x51,
13883   0xfe,  0x8e,  0x51,  0xfe,  0x6b,  0x18,  0x23,  0xfe,  0x00,  0xff,  0x31,  0xfe,  0x76,  0x10,  0xac,  0xfe,
13884   0xd2,  0xf0,  0xfe,  0xba,  0x0c,  0xfe,  0x76,  0x18,  0x23,  0x1d,  0x5d,  0x03,  0xe3,  0x23,  0x07,  0xfe,
13885   0x08,  0x13,  0x19,  0xfe,  0x16,  0x00,  0x05,  0x70,  0xfe,  0xd1,  0xf0,  0xfe,  0xcc,  0x0c,  0x1f,  0x92,
13886   0x01,  0x42,  0x19,  0xfe,  0x17,  0x00,  0x5c,  0xfe,  0xce,  0xf0,  0xfe,  0xd2,  0x0c,  0xfe,  0x3e,  0x10,
13887   0xfe,  0xcd,  0xf0,  0xfe,  0xde,  0x0c,  0x19,  0xfe,  0x22,  0x00,  0x05,  0x70,  0xfe,  0xcb,  0xf0,  0xfe,
13888   0xea,  0x0c,  0x19,  0xfe,  0x24,  0x00,  0x05,  0x70,  0xfe,  0xd0,  0xf0,  0xfe,  0xf4,  0x0c,  0x19,  0x94,
13889   0xfe,  0x1c,  0x10,  0xfe,  0xcf,  0xf0,  0xfe,  0xfe,  0x0c,  0x19,  0x4a,  0xf3,  0xfe,  0xcc,  0xf0,  0xef,
13890   0x01,  0x76,  0x06,  0x24,  0x4d,  0x19,  0xfe,  0x12,  0x00,  0x37,  0x13,  0xfe,  0x4e,  0x11,  0x2f,  0xfe,
13891   0x16,  0x0d,  0xfe,  0x9e,  0xf0,  0xfe,  0x2a,  0x0d,  0xfe,  0x01,  0x48,  0x1b,  0x3c,  0x37,  0x88,  0xf5,
13892   0xd4,  0x29,  0xd5,  0x29,  0xd2,  0x29,  0xd3,  0x29,  0x37,  0xfe,  0x9c,  0x32,  0x2f,  0xfe,  0x3e,  0x0d,
13893   0x2a,  0x3c,  0xae,  0xfe,  0x62,  0x0d,  0xaf,  0xa0,  0xd4,  0x9f,  0xd5,  0x9f,  0xd2,  0x9f,  0xd3,  0x9f,
13894   0x05,  0x29,  0x01,  0x41,  0xfe,  0xd3,  0x10,  0x15,  0xfe,  0xe8,  0x00,  0xc4,  0xc5,  0x75,  0xd7,  0x99,
13895   0xd8,  0x9c,  0xfe,  0x89,  0xf0,  0x29,  0x27,  0x25,  0xbe,  0xd7,  0x99,  0xd8,  0x9c,  0x2f,  0xfe,  0x8c,
13896   0x0d,  0x16,  0x29,  0x27,  0x25,  0xbd,  0xfe,  0x01,  0x48,  0xa4,  0x19,  0xfe,  0x42,  0x00,  0x05,  0x70,
13897   0x90,  0x07,  0xfe,  0x81,  0x49,  0x1b,  0xfe,  0x64,  0x0e,  0x01,  0x0c,  0x06,  0x0d,  0xfe,  0x44,  0x13,
13898   0x19,  0x00,  0x2d,  0x0d,  0xfe,  0x54,  0x12,  0x2d,  0xfe,  0x28,  0x00,  0x2b,  0xfe,  0xda,  0x0e,  0x0a,
13899   0x57,  0x01,  0x18,  0x09,  0x00,  0x36,  0x46,  0xfe,  0x28,  0x00,  0xfe,  0xfa,  0x10,  0x01,  0xfe,  0xf4,
13900   0x1c,  0x01,  0xfe,  0x00,  0x1d,  0x0a,  0xba,  0x01,  0xfe,  0x58,  0x10,  0x40,  0x15,  0x56,  0x01,  0x85,
13901   0x05,  0x35,  0x19,  0xfe,  0x44,  0x00,  0x2d,  0x0d,  0xf7,  0x46,  0x0d,  0xfe,  0xcc,  0x10,  0x01,  0xa7,
13902   0x46,  0x0d,  0xfe,  0xc2,  0x10,  0x01,  0xa7,  0x0f,  0xfe,  0x19,  0x82,  0x04,  0xfe,  0x99,  0x83,  0xfe,
13903   0xcc,  0x47,  0x0b,  0x0e,  0xfe,  0x34,  0x46,  0xa5,  0x46,  0x0d,  0x19,  0xfe,  0x43,  0x00,  0xfe,  0xa2,
13904   0x10,  0x01,  0x0c,  0x61,  0x0d,  0x44,  0x01,  0xfe,  0xf4,  0x1c,  0x01,  0xfe,  0x00,  0x1d,  0x40,  0x15,
13905   0x56,  0x01,  0x85,  0x7d,  0x0d,  0x40,  0x51,  0x01,  0xfe,  0x9e,  0x1e,  0x05,  0xfe,  0x3a,  0x03,  0x01,
13906   0x0c,  0x06,  0x0d,  0x5d,  0x46,  0x0d,  0x19,  0x00,  0xfe,  0x62,  0x10,  0x01,  0x76,  0x06,  0x12,  0xfe,
13907   0x5c,  0x12,  0x01,  0x0c,  0x06,  0x12,  0xfe,  0x52,  0x13,  0xfe,  0x1c,  0x1c,  0xfe,  0x9d,  0xf0,  0xfe,
13908   0x8e,  0x0e,  0xfe,  0x1c,  0x1c,  0xfe,  0x9d,  0xf0,  0xfe,  0x94,  0x0e,  0x01,  0x0c,  0x61,  0x12,  0x44,
13909   0xfe,  0x9f,  0x10,  0x19,  0xfe,  0x15,  0x00,  0xfe,  0x04,  0xe6,  0x0d,  0x4f,  0xfe,  0x2e,  0x10,  0x19,
13910   0xfe,  0x13,  0x00,  0xfe,  0x10,  0x10,  0x19,  0xfe,  0x47,  0x00,  0xf1,  0x19,  0xfe,  0x41,  0x00,  0xa2,
13911   0x19,  0xfe,  0x24,  0x00,  0x86,  0xc4,  0xc5,  0x75,  0x03,  0x81,  0x1e,  0x2b,  0xea,  0x4f,  0xfe,  0x04,
13912   0xe6,  0x12,  0xfe,  0x9d,  0x41,  0xfe,  0x1c,  0x42,  0x40,  0x01,  0xf4,  0x05,  0x35,  0xfe,  0x12,  0x1c,
13913   0x1f,  0x0d,  0x47,  0xb5,  0xc3,  0x1f,  0xfe,  0x31,  0x00,  0x47,  0xb8,  0x01,  0xfe,  0xd4,  0x11,  0x05,
13914   0xe9,  0x51,  0xfe,  0x06,  0xec,  0xe0,  0xfe,  0x0e,  0x47,  0x46,  0x28,  0xfe,  0xce,  0x45,  0x31,  0x51,
13915   0xfe,  0x06,  0xea,  0xe0,  0xfe,  0x47,  0x4b,  0x45,  0xfe,  0x75,  0x57,  0x03,  0x67,  0xfe,  0x98,  0x56,
13916   0xfe,  0x38,  0x12,  0x0a,  0x5a,  0x01,  0x18,  0xfe,  0x44,  0x48,  0x60,  0x01,  0x0c,  0x06,  0x28,  0xfe,
13917   0x18,  0x13,  0x0a,  0x57,  0x01,  0x18,  0x3e,  0xfe,  0x41,  0x58,  0x0a,  0xba,  0xfe,  0xfa,  0x14,  0xfe,
13918   0x49,  0x54,  0xb0,  0xfe,  0x5e,  0x0f,  0x05,  0xfe,  0x3a,  0x03,  0x0a,  0x67,  0xfe,  0xe0,  0x14,  0xfe,
13919   0x0e,  0x47,  0x46,  0x28,  0xfe,  0xce,  0x45,  0x31,  0x51,  0xfe,  0xce,  0x47,  0xfe,  0xad,  0x13,  0x05,
13920   0x35,  0x21,  0x2c,  0x09,  0x1a,  0xfe,  0x98,  0x12,  0x26,  0x20,  0x96,  0x20,  0xe7,  0xfe,  0x08,  0x1c,
13921   0xfe,  0x7c,  0x19,  0xfe,  0xfd,  0x19,  0xfe,  0x0a,  0x1c,  0x03,  0xe5,  0xfe,  0x48,  0x55,  0xa5,  0x3b,
13922   0xfe,  0x62,  0x01,  0xfe,  0xc9,  0x55,  0x31,  0xfe,  0x74,  0x10,  0x01,  0xfe,  0xf0,  0x1a,  0x03,  0xfe,
13923   0x38,  0x01,  0x3b,  0xfe,  0x3a,  0x01,  0x8e,  0xfe,  0x1e,  0x10,  0xfe,  0x02,  0xec,  0xe7,  0x53,  0x00,
13924   0x36,  0xfe,  0x04,  0xec,  0x2c,  0x60,  0xfe,  0x05,  0xf6,  0xfe,  0x34,  0x01,  0x01,  0xfe,  0x62,  0x1b,
13925   0x01,  0xfe,  0xce,  0x1e,  0xb2,  0x11,  0xfe,  0x18,  0x13,  0xca,  0xfe,  0x02,  0xea,  0xe7,  0x53,  0x92,
13926   0xfe,  0xc3,  0x13,  0x1f,  0x12,  0x47,  0xb5,  0xc3,  0xfe,  0x2a,  0x10,  0x03,  0xfe,  0x38,  0x01,  0x23,
13927   0xfe,  0xf0,  0xff,  0x10,  0xe5,  0x03,  0xfe,  0x3a,  0x01,  0x10,  0xfe,  0x62,  0x01,  0x01,  0xfe,  0x1e,
13928   0x1e,  0x20,  0x2c,  0x15,  0x56,  0x01,  0xfe,  0x9e,  0x1e,  0x13,  0x07,  0x02,  0x26,  0x02,  0x21,  0x96,
13929   0xc7,  0x20,  0x96,  0x09,  0x92,  0xfe,  0x79,  0x13,  0x1f,  0x1d,  0x47,  0xb5,  0xc3,  0xfe,  0xe1,  0x10,
13930   0xcf,  0xfe,  0x03,  0xdc,  0xfe,  0x73,  0x57,  0xfe,  0x80,  0x5d,  0x02,  0xcf,  0xfe,  0x03,  0xdc,  0xfe,
13931   0x5b,  0x57,  0xfe,  0x80,  0x5d,  0x02,  0xfe,  0x03,  0x57,  0xcf,  0x26,  0xfe,  0x00,  0xcc,  0x02,  0xfe,
13932   0x03,  0x57,  0xcf,  0x89,  0x02,  0x01,  0x0c,  0x06,  0x4a,  0xfe,  0x4e,  0x13,  0x0f,  0xfe,  0x1c,  0x80,
13933   0x04,  0xfe,  0x9c,  0x83,  0x33,  0x0b,  0x0e,  0x09,  0x07,  0xfe,  0x3a,  0x13,  0x0f,  0xfe,  0x1e,  0x80,
13934   0x04,  0xfe,  0x9e,  0x83,  0x33,  0x0b,  0x0e,  0xfe,  0x2a,  0x13,  0x0f,  0xfe,  0x1d,  0x80,  0x04,  0xfe,
13935   0x9d,  0x83,  0xfe,  0xf9,  0x13,  0x0e,  0xfe,  0x1c,  0x13,  0x01,  0xfe,  0xee,  0x1e,  0xac,  0xfe,  0x14,
13936   0x13,  0x01,  0xfe,  0xfe,  0x1e,  0xfe,  0x81,  0x58,  0xfa,  0x01,  0xfe,  0x0e,  0x1f,  0xfe,  0x30,  0xf4,
13937   0x0d,  0xfe,  0x3c,  0x50,  0xa2,  0x01,  0xfe,  0x92,  0x1b,  0x01,  0x43,  0x09,  0x56,  0xfb,  0x01,  0xfe,
13938   0xc8,  0x1a,  0x01,  0x0c,  0x06,  0x28,  0xa4,  0x01,  0xfe,  0xf4,  0x1c,  0x01,  0xfe,  0x00,  0x1d,  0x15,
13939   0xfe,  0xe9,  0x00,  0x01,  0x0c,  0x06,  0x4a,  0xfe,  0x4e,  0x13,  0x01,  0xfe,  0x22,  0x1b,  0xfe,  0x1e,
13940   0x1c,  0x0f,  0xfe,  0x14,  0x90,  0x04,  0xfe,  0x94,  0x93,  0x3a,  0x0b,  0xfe,  0x96,  0x90,  0x04,  0xfe,
13941   0x96,  0x93,  0x79,  0x0b,  0x0e,  0x10,  0xfe,  0x64,  0x01,  0x22,  0xfe,  0x66,  0x01,  0x01,  0x0c,  0x06,
13942   0x65,  0xf9,  0x0f,  0xfe,  0x03,  0x80,  0x04,  0xfe,  0x83,  0x83,  0x33,  0x0b,  0x0e,  0x77,  0xfe,  0x01,
13943   0xec,  0x2c,  0xfe,  0x80,  0x40,  0x20,  0x2c,  0x7a,  0x30,  0x15,  0xdf,  0x40,  0x21,  0x2c,  0xfe,  0x00,
13944   0x40,  0x8d,  0x2c,  0x02,  0xfe,  0x08,  0x1c,  0x03,  0xfe,  0xac,  0x00,  0xfe,  0x06,  0x58,  0x03,  0xfe,
13945   0xae,  0x00,  0xfe,  0x07,  0x58,  0x03,  0xfe,  0xb0,  0x00,  0xfe,  0x08,  0x58,  0x03,  0xfe,  0xb2,  0x00,
13946   0xfe,  0x09,  0x58,  0xfe,  0x0a,  0x1c,  0x2e,  0x49,  0x20,  0xe0,  0x26,  0x10,  0x66,  0x10,  0x55,  0x10,
13947   0x6f,  0x13,  0x57,  0x52,  0x4f,  0x1c,  0x28,  0xfe,  0x90,  0x4d,  0xfe,  0x91,  0x54,  0x2b,  0xfe,  0x88,
13948   0x11,  0x46,  0x1a,  0x13,  0x5a,  0x52,  0x1c,  0x4a,  0xfe,  0x90,  0x4d,  0xfe,  0x91,  0x54,  0x2b,  0xfe,
13949   0x9e,  0x11,  0x2e,  0x1a,  0x20,  0x2c,  0x90,  0x34,  0x60,  0x21,  0x2c,  0xfe,  0x00,  0x40,  0x8d,  0x2c,
13950   0x15,  0xdf,  0xfe,  0x14,  0x56,  0xfe,  0xd6,  0xf0,  0xfe,  0xb2,  0x11,  0xfe,  0x12,  0x1c,  0x75,  0xfe,
13951   0x14,  0x1c,  0xfe,  0x10,  0x1c,  0xfe,  0x18,  0x1c,  0x02,  0x51,  0xfe,  0x0c,  0x14,  0xfe,  0x0e,  0x47,
13952   0xfe,  0x07,  0xe6,  0x28,  0xfe,  0xce,  0x47,  0xfe,  0xf5,  0x13,  0x02,  0x01,  0xa7,  0x90,  0x34,  0x60,
13953   0xfe,  0x06,  0x80,  0xfe,  0x48,  0x47,  0xfe,  0x42,  0x13,  0xfe,  0x02,  0x80,  0x09,  0x56,  0xfe,  0x34,
13954   0x13,  0x0a,  0x5a,  0x01,  0x18,  0xcb,  0xfe,  0x36,  0x12,  0xfe,  0x41,  0x48,  0xfe,  0x45,  0x48,  0x01,
13955   0xfe,  0xb2,  0x16,  0xfe,  0x00,  0xcc,  0xcb,  0xfe,  0xf3,  0x13,  0x3f,  0x89,  0x09,  0x1a,  0xa5,  0x0a,
13956   0x9d,  0x01,  0x18,  0xfe,  0x80,  0x5c,  0x01,  0x85,  0xf2,  0x09,  0x9b,  0xa4,  0xfe,  0x14,  0x56,  0xfe,
13957   0xd6,  0xf0,  0xfe,  0xec,  0x11,  0x02,  0xfe,  0x44,  0x58,  0x77,  0xfe,  0x01,  0xec,  0xb8,  0xfe,  0x9e,
13958   0x40,  0xfe,  0x9d,  0xe7,  0x00,  0xfe,  0x9c,  0xe7,  0x12,  0x8d,  0x30,  0x01,  0xf4,  0xfe,  0xdd,  0x10,
13959   0x37,  0xd7,  0x99,  0xd8,  0x9c,  0x27,  0x25,  0xee,  0x09,  0x12,  0xfe,  0x48,  0x12,  0x09,  0x0d,  0xfe,
13960   0x56,  0x12,  0x09,  0x1d,  0xfe,  0x30,  0x12,  0x09,  0xdd,  0x1b,  0xfe,  0xc4,  0x13,  0x09,  0xfe,  0x23,
13961   0x00,  0x1b,  0xfe,  0xd0,  0x13,  0x09,  0x07,  0x1b,  0xfe,  0x34,  0x14,  0x09,  0x24,  0xfe,  0x12,  0x12,
13962   0x09,  0x00,  0x1b,  0x29,  0x1f,  0xdd,  0x01,  0x42,  0xa1,  0x32,  0x01,  0x08,  0xae,  0x41,  0x02,  0x32,
13963   0xfe,  0x62,  0x08,  0x0a,  0xe1,  0x01,  0xfe,  0x58,  0x10,  0x15,  0x9b,  0x05,  0x35,  0x32,  0x01,  0x43,
13964   0x09,  0xbb,  0xfe,  0xd7,  0x13,  0x91,  0x4b,  0x7e,  0x4c,  0x8e,  0xfe,  0x80,  0x13,  0x01,  0x0c,  0x06,
13965   0x54,  0xfe,  0x72,  0x12,  0xdb,  0x64,  0xdc,  0x34,  0xfe,  0x44,  0x55,  0xfe,  0xe5,  0x55,  0xb0,  0xfe,
13966   0x4a,  0x13,  0x21,  0x6e,  0xfe,  0x26,  0x13,  0x03,  0x97,  0x3b,  0x98,  0x8e,  0xfe,  0xb6,  0x0e,  0x10,
13967   0x6a,  0x22,  0x6b,  0x26,  0x10,  0x97,  0x10,  0x98,  0x01,  0xc2,  0x2e,  0x49,  0x88,  0x20,  0x6e,  0x01,
13968   0xfe,  0x6a,  0x16,  0xdb,  0x64,  0xdc,  0x34,  0xfe,  0x04,  0x55,  0xfe,  0xa5,  0x55,  0xfe,  0x04,  0xfa,
13969   0x64,  0xfe,  0x05,  0xfa,  0x34,  0xfe,  0x8f,  0x10,  0x03,  0x6c,  0x3b,  0x6d,  0xfe,  0x40,  0x56,  0xfe,
13970   0xe1,  0x56,  0x10,  0x6c,  0x22,  0x6d,  0x71,  0xdb,  0x64,  0xdc,  0x34,  0xfe,  0x44,  0x55,  0xfe,  0xe5,
13971   0x55,  0x03,  0x68,  0x3b,  0x69,  0xfe,  0x00,  0x56,  0xfe,  0xa1,  0x56,  0x10,  0x68,  0x22,  0x69,  0x01,
13972   0x0c,  0x06,  0x54,  0xf9,  0x21,  0x6e,  0xfe,  0x1f,  0x40,  0x03,  0x6a,  0x3b,  0x6b,  0xfe,  0x2c,  0x50,
13973   0xfe,  0xae,  0x50,  0x03,  0x6c,  0x3b,  0x6d,  0xfe,  0x44,  0x50,  0xfe,  0xc6,  0x50,  0x03,  0x68,  0x3b,
13974   0x69,  0xfe,  0x08,  0x50,  0xfe,  0x8a,  0x50,  0x03,  0x4b,  0x3b,  0x4c,  0xfe,  0x40,  0x50,  0xfe,  0xc2,
13975   0x50,  0x05,  0x73,  0x2e,  0x07,  0x20,  0x9e,  0x05,  0x72,  0x32,  0x01,  0x08,  0x16,  0x3d,  0x27,  0x25,
13976   0xee,  0x09,  0x07,  0x2b,  0x3d,  0x01,  0x43,  0x09,  0xbb,  0x2b,  0x72,  0x01,  0xa6,  0x23,  0x3f,  0x1b,
13977   0x3d,  0x01,  0x0c,  0x06,  0x0d,  0xfe,  0x1e,  0x13,  0x91,  0x4b,  0x7e,  0x4c,  0xfe,  0x0a,  0x55,  0x31,
13978   0xfe,  0x8b,  0x55,  0xd9,  0x4b,  0xda,  0x4c,  0xfe,  0x0c,  0x51,  0xfe,  0x8e,  0x51,  0x05,  0x72,  0x01,
13979   0xfe,  0x8e,  0x1e,  0xca,  0xfe,  0x19,  0x41,  0x05,  0x72,  0x32,  0x01,  0x08,  0x2a,  0x3c,  0x16,  0xc0,
13980   0x27,  0x25,  0xbe,  0x2d,  0x1d,  0xc0,  0x2d,  0x0d,  0x83,  0x2d,  0x7f,  0x1b,  0xfe,  0x66,  0x15,  0x05,
13981   0x3d,  0x01,  0x08,  0x2a,  0x3c,  0x16,  0xc0,  0x27,  0x25,  0xbd,  0x09,  0x1d,  0x2b,  0x3d,  0x01,  0x08,
13982   0x16,  0xc0,  0x27,  0x25,  0xfe,  0xe8,  0x09,  0xfe,  0xc2,  0x49,  0x50,  0x03,  0xb6,  0x1e,  0x83,  0x01,
13983   0x38,  0x06,  0x24,  0x31,  0xa1,  0xfe,  0xbb,  0x45,  0x2d,  0x00,  0xa4,  0x46,  0x07,  0x90,  0x3f,  0x01,
13984   0xfe,  0xf8,  0x15,  0x01,  0xa6,  0x86,  0xfe,  0x4b,  0x45,  0xfe,  0x20,  0x13,  0x01,  0x43,  0x09,  0x82,
13985   0xfe,  0x16,  0x13,  0x03,  0x9a,  0x1e,  0x5d,  0x03,  0x55,  0x1e,  0x31,  0x5e,  0x05,  0x72,  0xfe,  0xc0,
13986   0x5d,  0x01,  0xa7,  0xfe,  0x03,  0x17,  0x03,  0x66,  0x8a,  0x10,  0x66,  0x5e,  0x32,  0x01,  0x08,  0x17,
13987   0x73,  0x01,  0xfe,  0x56,  0x19,  0x05,  0x73,  0x01,  0x08,  0x2a,  0x3c,  0x16,  0x3d,  0x27,  0x25,  0xbd,
13988   0x09,  0x07,  0x2b,  0x3d,  0x01,  0xfe,  0xbe,  0x16,  0xfe,  0x42,  0x58,  0xfe,  0xe8,  0x14,  0x01,  0xa6,
13989   0x86,  0xfe,  0x4a,  0xf4,  0x0d,  0x1b,  0x3d,  0xfe,  0x4a,  0xf4,  0x07,  0xfe,  0x0e,  0x12,  0x01,  0x43,
13990   0x09,  0x82,  0x4e,  0x05,  0x72,  0x03,  0x55,  0x8a,  0x10,  0x55,  0x5e,  0x32,  0x01,  0x08,  0x17,  0x73,
13991   0x01,  0xfe,  0x84,  0x19,  0x05,  0x73,  0x01,  0x08,  0x2a,  0x3c,  0x16,  0x3d,  0x27,  0x25,  0xbd,  0x09,
13992   0x12,  0x2b,  0x3d,  0x01,  0xfe,  0xe8,  0x17,  0x8b,  0xfe,  0xaa,  0x14,  0xfe,  0xb6,  0x14,  0x86,  0xa8,
13993   0xb2,  0x0d,  0x1b,  0x3d,  0xb2,  0x07,  0xfe,  0x0e,  0x12,  0x01,  0x43,  0x09,  0x82,  0x4e,  0x05,  0x72,
13994   0x03,  0x6f,  0x8a,  0x10,  0x6f,  0x5e,  0x32,  0x01,  0x08,  0x17,  0x73,  0x01,  0xfe,  0xc0,  0x19,  0x05,
13995   0x73,  0x13,  0x07,  0x2f,  0xfe,  0xcc,  0x15,  0x17,  0xfe,  0xe2,  0x15,  0x5f,  0xcc,  0x01,  0x08,  0x26,
13996   0x5f,  0x02,  0x8f,  0xfe,  0xde,  0x15,  0x2a,  0xfe,  0xde,  0x15,  0x16,  0xfe,  0xcc,  0x15,  0x5e,  0x32,
13997   0x01,  0x08,  0xfe,  0xd5,  0x10,  0x13,  0x58,  0xff,  0x02,  0x00,  0x57,  0x52,  0xad,  0x23,  0xfe,  0xff,
13998   0x7f,  0xfe,  0x30,  0x56,  0xfe,  0x00,  0x5c,  0x02,  0x13,  0x58,  0xff,  0x02,  0x00,  0x57,  0x52,  0xad,
13999   0x23,  0x3f,  0xfe,  0x30,  0x56,  0xfe,  0x00,  0x5c,  0x02,  0x13,  0x58,  0xff,  0x02,  0x00,  0x57,  0x52,
14000   0xad,  0x02,  0x13,  0x58,  0xff,  0x02,  0x00,  0x57,  0x52,  0xfe,  0x00,  0x5e,  0x02,  0x13,  0x58,  0xff,
14001   0x02,  0x00,  0x57,  0x52,  0xad,  0xfe,  0x0b,  0x58,  0x02,  0x0a,  0x66,  0x01,  0x5c,  0x0a,  0x55,  0x01,
14002   0x5c,  0x0a,  0x6f,  0x01,  0x5c,  0x02,  0x01,  0xfe,  0x1e,  0x1f,  0x23,  0x1a,  0xff,  0x03,  0x00,  0x54,
14003   0xfe,  0x00,  0xf4,  0x24,  0x52,  0x0f,  0xfe,  0x00,  0x7c,  0x04,  0xfe,  0x07,  0x7c,  0x3a,  0x0b,  0x0e,
14004   0xfe,  0x00,  0x71,  0xfe,  0xf9,  0x18,  0xfe,  0x7a,  0x19,  0xfe,  0xfb,  0x19,  0xfe,  0x1a,  0xf7,  0x00,
14005   0xfe,  0x1b,  0xf7,  0x00,  0x7a,  0x30,  0x10,  0x68,  0x22,  0x69,  0xd9,  0x6c,  0xda,  0x6d,  0x02,  0xfe,
14006   0x62,  0x08,  0xfe,  0x82,  0x4a,  0xfe,  0xe1,  0x1a,  0xfe,  0x83,  0x5a,  0x77,  0x02,  0x01,  0xc6,  0xfe,
14007   0x42,  0x48,  0x4f,  0x50,  0x45,  0x01,  0x08,  0x16,  0xfe,  0xe0,  0x17,  0x27,  0x25,  0xbe,  0x01,  0x08,
14008   0x16,  0xfe,  0xe0,  0x17,  0x27,  0x25,  0xfe,  0xe8,  0x0a,  0xfe,  0xc1,  0x59,  0x03,  0x9a,  0x1e,  0xfe,
14009   0xda,  0x12,  0x01,  0x38,  0x06,  0x12,  0xfe,  0xd0,  0x13,  0x26,  0x53,  0x12,  0x48,  0xfe,  0x08,  0x17,
14010   0xd1,  0x12,  0x53,  0x12,  0xfe,  0x1e,  0x13,  0x2d,  0xb4,  0x7b,  0xfe,  0x26,  0x17,  0x4d,  0x13,  0x07,
14011   0x1c,  0xb4,  0x90,  0x04,  0xfe,  0x78,  0x10,  0xff,  0x02,  0x83,  0x55,  0xf1,  0xff,  0x02,  0x83,  0x55,
14012   0x53,  0x1d,  0xfe,  0x12,  0x13,  0xd6,  0xfe,  0x30,  0x00,  0xb0,  0xfe,  0x80,  0x17,  0x1c,  0x63,  0x13,
14013   0x07,  0xfe,  0x56,  0x10,  0x53,  0x0d,  0xfe,  0x16,  0x13,  0xd6,  0xfe,  0x64,  0x00,  0xb0,  0xfe,  0x80,
14014   0x17,  0x0a,  0xfe,  0x64,  0x00,  0x1c,  0x94,  0x13,  0x07,  0xfe,  0x28,  0x10,  0x53,  0x07,  0xfe,  0x60,
14015   0x13,  0xd6,  0xfe,  0xc8,  0x00,  0xb0,  0xfe,  0x80,  0x17,  0x0a,  0xfe,  0xc8,  0x00,  0x1c,  0x95,  0x13,
14016   0x07,  0x71,  0xd6,  0xfe,  0x90,  0x01,  0x48,  0xfe,  0x8c,  0x17,  0x45,  0xf3,  0xfe,  0x43,  0xf4,  0x96,
14017   0xfe,  0x56,  0xf0,  0xfe,  0x9e,  0x17,  0xfe,  0x04,  0xf4,  0x58,  0xfe,  0x43,  0xf4,  0x94,  0xf6,  0x8b,
14018   0x01,  0xfe,  0x24,  0x16,  0x23,  0x3f,  0xfc,  0xa8,  0x8c,  0x49,  0x48,  0xfe,  0xda,  0x17,  0x62,  0x49,
14019   0xfe,  0x1c,  0x10,  0xa8,  0x8c,  0x80,  0x48,  0xfe,  0xda,  0x17,  0x62,  0x80,  0x71,  0x50,  0x26,  0xfe,
14020   0x4d,  0xf4,  0x00,  0xf7,  0x45,  0x13,  0x07,  0xfe,  0xb4,  0x56,  0xfe,  0xc3,  0x58,  0x02,  0x50,  0x13,
14021   0x0d,  0x02,  0x50,  0x3e,  0x78,  0x4f,  0x45,  0x01,  0x08,  0x16,  0xa9,  0x27,  0x25,  0xbe,  0xfe,  0x03,
14022   0xea,  0xfe,  0x7e,  0x01,  0x01,  0x08,  0x16,  0xa9,  0x27,  0x25,  0xfe,  0xe9,  0x0a,  0x01,  0x08,  0x16,
14023   0xa9,  0x27,  0x25,  0xfe,  0xe9,  0x0a,  0xfe,  0x05,  0xea,  0xfe,  0x7f,  0x01,  0x01,  0x08,  0x16,  0xa9,
14024   0x27,  0x25,  0xfe,  0x69,  0x09,  0xfe,  0x02,  0xea,  0xfe,  0x80,  0x01,  0x01,  0x08,  0x16,  0xa9,  0x27,
14025   0x25,  0xfe,  0xe8,  0x08,  0x47,  0xfe,  0x81,  0x01,  0x03,  0xb6,  0x1e,  0x83,  0x01,  0x38,  0x06,  0x24,
14026   0x31,  0xa2,  0x78,  0xf2,  0x53,  0x07,  0x36,  0xfe,  0x34,  0xf4,  0x3f,  0xa1,  0x78,  0x03,  0x9a,  0x1e,
14027   0x83,  0x01,  0x38,  0x06,  0x12,  0x31,  0xf0,  0x4f,  0x45,  0xfe,  0x90,  0x10,  0xfe,  0x40,  0x5a,  0x23,
14028   0x3f,  0xfb,  0x8c,  0x49,  0x48,  0xfe,  0xaa,  0x18,  0x62,  0x49,  0x71,  0x8c,  0x80,  0x48,  0xfe,  0xaa,
14029   0x18,  0x62,  0x80,  0xfe,  0xb4,  0x56,  0xfe,  0x40,  0x5d,  0x01,  0xc6,  0x01,  0xfe,  0xac,  0x1d,  0xfe,
14030   0x02,  0x17,  0xfe,  0xc8,  0x45,  0xfe,  0x5a,  0xf0,  0xfe,  0xc0,  0x18,  0xfe,  0x43,  0x48,  0x2d,  0x93,
14031   0x36,  0xfe,  0x34,  0xf4,  0xfe,  0x00,  0x11,  0xfe,  0x40,  0x10,  0x2d,  0xb4,  0x36,  0xfe,  0x34,  0xf4,
14032   0x04,  0xfe,  0x34,  0x10,  0x2d,  0xfe,  0x0b,  0x00,  0x36,  0x46,  0x63,  0xfe,  0x28,  0x10,  0xfe,  0xc0,
14033   0x49,  0xff,  0x02,  0x00,  0x54,  0xb2,  0xfe,  0x90,  0x01,  0x48,  0xfe,  0xfa,  0x18,  0x45,  0xfe,  0x1c,
14034   0xf4,  0x3f,  0xf3,  0xfe,  0x40,  0xf4,  0x96,  0xfe,  0x56,  0xf0,  0xfe,  0x0c,  0x19,  0xfe,  0x04,  0xf4,
14035   0x58,  0xfe,  0x40,  0xf4,  0x94,  0xf6,  0x3e,  0x2d,  0x93,  0x4e,  0xd0,  0x0d,  0x21,  0xfe,  0x7f,  0x01,
14036   0xfe,  0xc8,  0x46,  0xfe,  0x24,  0x13,  0x8c,  0x00,  0x5d,  0x26,  0x21,  0xfe,  0x7e,  0x01,  0xfe,  0xc8,
14037   0x45,  0xfe,  0x14,  0x13,  0x21,  0xfe,  0x80,  0x01,  0xfe,  0x48,  0x45,  0xfa,  0x21,  0xfe,  0x81,  0x01,
14038   0xfe,  0xc8,  0x44,  0x4e,  0x26,  0x02,  0x13,  0x07,  0x02,  0x78,  0x45,  0x50,  0x13,  0x0d,  0x02,  0x14,
14039   0x07,  0x01,  0x08,  0x17,  0xfe,  0x82,  0x19,  0x14,  0x0d,  0x01,  0x08,  0x17,  0xfe,  0x82,  0x19,  0x14,
14040   0x1d,  0x01,  0x08,  0x17,  0xfe,  0x82,  0x19,  0x5f,  0xfe,  0x89,  0x49,  0x01,  0x08,  0x02,  0x14,  0x07,
14041   0x01,  0x08,  0x17,  0xc1,  0x14,  0x1d,  0x01,  0x08,  0x17,  0xc1,  0x14,  0x07,  0x01,  0x08,  0x17,  0xc1,
14042   0xfe,  0x89,  0x49,  0x01,  0x08,  0x17,  0xc1,  0x5f,  0xfe,  0x89,  0x4a,  0x01,  0x08,  0x02,  0x50,  0x02,
14043   0x14,  0x07,  0x01,  0x08,  0x17,  0x74,  0x14,  0x7f,  0x01,  0x08,  0x17,  0x74,  0x14,  0x12,  0x01,  0x08,
14044   0x17,  0x74,  0xfe,  0x89,  0x49,  0x01,  0x08,  0x17,  0x74,  0x14,  0x00,  0x01,  0x08,  0x17,  0x74,  0xfe,
14045   0x89,  0x4a,  0x01,  0x08,  0x17,  0x74,  0xfe,  0x09,  0x49,  0x01,  0x08,  0x17,  0x74,  0x5f,  0xcc,  0x01,
14046   0x08,  0x02,  0x21,  0xe4,  0x09,  0x07,  0xfe,  0x4c,  0x13,  0xc8,  0x20,  0xe4,  0xfe,  0x49,  0xf4,  0x00,
14047   0x4d,  0x5f,  0xa1,  0x5e,  0xfe,  0x01,  0xec,  0xfe,  0x27,  0x01,  0xcc,  0xff,  0x02,  0x00,  0x10,  0x2f,
14048   0xfe,  0x3e,  0x1a,  0x01,  0x43,  0x09,  0xfe,  0xe3,  0x00,  0xfe,  0x22,  0x13,  0x16,  0xfe,  0x64,  0x1a,
14049   0x26,  0x20,  0x9e,  0x01,  0x41,  0x21,  0x9e,  0x09,  0x07,  0x5d,  0x01,  0x0c,  0x61,  0x07,  0x44,  0x02,
14050   0x0a,  0x5a,  0x01,  0x18,  0xfe,  0x00,  0x40,  0xaa,  0x09,  0x1a,  0xfe,  0x12,  0x13,  0x0a,  0x9d,  0x01,
14051   0x18,  0xaa,  0x0a,  0x67,  0x01,  0xa3,  0x02,  0x0a,  0x9d,  0x01,  0x18,  0xaa,  0xfe,  0x80,  0xe7,  0x1a,
14052   0x09,  0x1a,  0x5d,  0xfe,  0x45,  0x58,  0x01,  0xfe,  0xb2,  0x16,  0xaa,  0x02,  0x0a,  0x5a,  0x01,  0x18,
14053   0xaa,  0x0a,  0x67,  0x01,  0xa3,  0x02,  0x0a,  0x5a,  0x01,  0x18,  0x01,  0xfe,  0x7e,  0x1e,  0xfe,  0x80,
14054   0x4c,  0xfe,  0x49,  0xe4,  0x1a,  0xfe,  0x12,  0x13,  0x0a,  0x9d,  0x01,  0x18,  0xfe,  0x80,  0x4c,  0x0a,
14055   0x67,  0x01,  0x5c,  0x02,  0x1c,  0x1a,  0x87,  0x7c,  0xe5,  0xfe,  0x18,  0xdf,  0xfe,  0x19,  0xde,  0xfe,
14056   0x24,  0x1c,  0xfe,  0x1d,  0xf7,  0x28,  0xb1,  0xfe,  0x04,  0x1b,  0x01,  0xfe,  0x2a,  0x1c,  0xfa,  0xb3,
14057   0x28,  0x7c,  0xfe,  0x2c,  0x01,  0xfe,  0x2f,  0x19,  0x02,  0xc9,  0x2b,  0xfe,  0xf4,  0x1a,  0xfe,  0xfa,
14058   0x10,  0x1c,  0x1a,  0x87,  0x03,  0xfe,  0x64,  0x01,  0xfe,  0x00,  0xf4,  0x24,  0xfe,  0x18,  0x58,  0x03,
14059   0xfe,  0x66,  0x01,  0xfe,  0x19,  0x58,  0xb3,  0x24,  0x01,  0xfe,  0x0e,  0x1f,  0xfe,  0x30,  0xf4,  0x07,
14060   0xfe,  0x3c,  0x50,  0x7c,  0xfe,  0x38,  0x00,  0xfe,  0x0f,  0x79,  0xfe,  0x1c,  0xf7,  0x24,  0xb1,  0xfe,
14061   0x50,  0x1b,  0xfe,  0xd4,  0x14,  0x31,  0x02,  0xc9,  0x2b,  0xfe,  0x26,  0x1b,  0xfe,  0xba,  0x10,  0x1c,
14062   0x1a,  0x87,  0xfe,  0x83,  0x5a,  0xfe,  0x18,  0xdf,  0xfe,  0x19,  0xde,  0xfe,  0x1d,  0xf7,  0x54,  0xb1,
14063   0xfe,  0x72,  0x1b,  0xfe,  0xb2,  0x14,  0xfc,  0xb3,  0x54,  0x7c,  0x12,  0xfe,  0xaf,  0x19,  0xfe,  0x98,
14064   0xe7,  0x00,  0x02,  0xc9,  0x2b,  0xfe,  0x66,  0x1b,  0xfe,  0x8a,  0x10,  0x1c,  0x1a,  0x87,  0x8b,  0x0f,
14065   0xfe,  0x30,  0x90,  0x04,  0xfe,  0xb0,  0x93,  0x3a,  0x0b,  0xfe,  0x18,  0x58,  0xfe,  0x32,  0x90,  0x04,
14066   0xfe,  0xb2,  0x93,  0x3a,  0x0b,  0xfe,  0x19,  0x58,  0x0e,  0xa8,  0xb3,  0x4a,  0x7c,  0x12,  0xfe,  0x0f,
14067   0x79,  0xfe,  0x1c,  0xf7,  0x4a,  0xb1,  0xfe,  0xc6,  0x1b,  0xfe,  0x5e,  0x14,  0x31,  0x02,  0xc9,  0x2b,
14068   0xfe,  0x96,  0x1b,  0x5c,  0xfe,  0x02,  0xf6,  0x1a,  0x87,  0xfe,  0x18,  0xfe,  0x6a,  0xfe,  0x19,  0xfe,
14069   0x6b,  0x01,  0xfe,  0x1e,  0x1f,  0xfe,  0x1d,  0xf7,  0x65,  0xb1,  0xfe,  0xee,  0x1b,  0xfe,  0x36,  0x14,
14070   0xfe,  0x1c,  0x13,  0xb3,  0x65,  0x3e,  0xfe,  0x83,  0x58,  0xfe,  0xaf,  0x19,  0xfe,  0x80,  0xe7,  0x1a,
14071   0xfe,  0x81,  0xe7,  0x1a,  0x15,  0xfe,  0xdd,  0x00,  0x7a,  0x30,  0x02,  0x7a,  0x30,  0xfe,  0x12,  0x45,
14072   0x2b,  0xfe,  0xdc,  0x1b,  0x1f,  0x07,  0x47,  0xb5,  0xc3,  0x05,  0x35,  0xfe,  0x39,  0xf0,  0x75,  0x26,
14073   0x02,  0xfe,  0x7e,  0x18,  0x23,  0x1d,  0x36,  0x13,  0x11,  0x02,  0x87,  0x03,  0xe3,  0x23,  0x07,  0xfe,
14074   0xef,  0x12,  0xfe,  0xe1,  0x10,  0x90,  0x34,  0x60,  0xfe,  0x02,  0x80,  0x09,  0x56,  0xfe,  0x3c,  0x13,
14075   0xfe,  0x82,  0x14,  0xfe,  0x42,  0x13,  0x51,  0xfe,  0x06,  0x83,  0x0a,  0x5a,  0x01,  0x18,  0xcb,  0xfe,
14076   0x3e,  0x12,  0xfe,  0x41,  0x48,  0xfe,  0x45,  0x48,  0x01,  0xfe,  0xb2,  0x16,  0xfe,  0x00,  0xcc,  0xcb,
14077   0xfe,  0xf3,  0x13,  0x3f,  0x89,  0x09,  0x1a,  0xa5,  0x0a,  0x9d,  0x01,  0x18,  0xfe,  0x80,  0x4c,  0x01,
14078   0x85,  0xfe,  0x16,  0x10,  0x09,  0x9b,  0x4e,  0xfe,  0x40,  0x14,  0xfe,  0x24,  0x12,  0xfe,  0x14,  0x56,
14079   0xfe,  0xd6,  0xf0,  0xfe,  0x52,  0x1c,  0x1c,  0x0d,  0x02,  0xfe,  0x9c,  0xe7,  0x0d,  0x19,  0xfe,  0x15,
14080   0x00,  0x40,  0x8d,  0x30,  0x01,  0xf4,  0x1c,  0x07,  0x02,  0x51,  0xfe,  0x06,  0x83,  0xfe,  0x18,  0x80,
14081   0x61,  0x28,  0x44,  0x15,  0x56,  0x01,  0x85,  0x1c,  0x07,  0x02,  0xfe,  0x38,  0x90,  0xfe,  0xba,  0x90,
14082   0x91,  0xde,  0x7e,  0xdf,  0xfe,  0x48,  0x55,  0x31,  0xfe,  0xc9,  0x55,  0x02,  0x21,  0xb9,  0x88,  0x20,
14083   0xb9,  0x02,  0x0a,  0xba,  0x01,  0x18,  0xfe,  0x41,  0x48,  0x0a,  0x57,  0x01,  0x18,  0xfe,  0x49,  0x44,
14084   0x1b,  0xfe,  0x1e,  0x1d,  0x88,  0x89,  0x02,  0x0a,  0x5a,  0x01,  0x18,  0x09,  0x1a,  0xa4,  0x0a,  0x67,
14085   0x01,  0xa3,  0x0a,  0x57,  0x01,  0x18,  0x88,  0x89,  0x02,  0xfe,  0x4e,  0xe4,  0x1d,  0x7b,  0xfe,  0x52,
14086   0x1d,  0x03,  0xfe,  0x90,  0x00,  0xfe,  0x3a,  0x45,  0xfe,  0x2c,  0x10,  0xfe,  0x4e,  0xe4,  0xdd,  0x7b,
14087   0xfe,  0x64,  0x1d,  0x03,  0xfe,  0x92,  0x00,  0xd1,  0x12,  0xfe,  0x1a,  0x10,  0xfe,  0x4e,  0xe4,  0xfe,
14088   0x0b,  0x00,  0x7b,  0xfe,  0x76,  0x1d,  0x03,  0xfe,  0x94,  0x00,  0xd1,  0x24,  0xfe,  0x08,  0x10,  0x03,
14089   0xfe,  0x96,  0x00,  0xd1,  0x63,  0xfe,  0x4e,  0x45,  0x83,  0xca,  0xff,  0x04,  0x68,  0x54,  0xfe,  0xf1,
14090   0x10,  0x23,  0x49,  0xfe,  0x08,  0x1c,  0xfe,  0x67,  0x19,  0xfe,  0x0a,  0x1c,  0xfe,  0x1a,  0xf4,  0xfe,
14091   0x00,  0x04,  0x83,  0xb2,  0x1d,  0x48,  0xfe,  0xaa,  0x1d,  0x13,  0x1d,  0x02,  0x09,  0x92,  0xfe,  0x5a,
14092   0xf0,  0xfe,  0xba,  0x1d,  0x2e,  0x93,  0xfe,  0x34,  0x10,  0x09,  0x12,  0xfe,  0x5a,  0xf0,  0xfe,  0xc8,
14093   0x1d,  0x2e,  0xb4,  0xfe,  0x26,  0x10,  0x09,  0x1d,  0x36,  0x2e,  0x63,  0xfe,  0x1a,  0x10,  0x09,  0x0d,
14094   0x36,  0x2e,  0x94,  0xf2,  0x09,  0x07,  0x36,  0x2e,  0x95,  0xa1,  0xc8,  0x02,  0x1f,  0x93,  0x01,  0x42,
14095   0xfe,  0x04,  0xfe,  0x99,  0x03,  0x9c,  0x8b,  0x02,  0x2a,  0xfe,  0x1c,  0x1e,  0xfe,  0x14,  0xf0,  0x08,
14096   0x2f,  0xfe,  0x0c,  0x1e,  0x2a,  0xfe,  0x1c,  0x1e,  0x8f,  0xfe,  0x1c,  0x1e,  0xfe,  0x82,  0xf0,  0xfe,
14097   0x10,  0x1e,  0x02,  0x0f,  0x3f,  0x04,  0xfe,  0x80,  0x83,  0x33,  0x0b,  0x0e,  0x02,  0x0f,  0xfe,  0x18,
14098   0x80,  0x04,  0xfe,  0x98,  0x83,  0x33,  0x0b,  0x0e,  0x02,  0x0f,  0xfe,  0x02,  0x80,  0x04,  0xfe,  0x82,
14099   0x83,  0x33,  0x0b,  0x0e,  0x02,  0x0f,  0xfe,  0x06,  0x80,  0x04,  0xfe,  0x86,  0x83,  0x33,  0x0b,  0x0e,
14100   0x02,  0x0f,  0xfe,  0x1b,  0x80,  0x04,  0xfe,  0x9b,  0x83,  0x33,  0x0b,  0x0e,  0x02,  0x0f,  0xfe,  0x04,
14101   0x80,  0x04,  0xfe,  0x84,  0x83,  0x33,  0x0b,  0x0e,  0x02,  0x0f,  0xfe,  0x80,  0x80,  0x04,  0xfe,  0x80,
14102   0x83,  0xfe,  0xc9,  0x47,  0x0b,  0x0e,  0x02,  0x0f,  0xfe,  0x19,  0x81,  0x04,  0xfe,  0x99,  0x83,  0xfe,
14103   0xca,  0x47,  0x0b,  0x0e,  0x02,  0x0f,  0xfe,  0x06,  0x83,  0x04,  0xfe,  0x86,  0x83,  0xfe,  0xce,  0x47,
14104   0x0b,  0x0e,  0x02,  0x0f,  0xfe,  0x2c,  0x90,  0x04,  0xfe,  0xac,  0x93,  0x3a,  0x0b,  0x0e,  0x02,  0x0f,
14105   0xfe,  0xae,  0x90,  0x04,  0xfe,  0xae,  0x93,  0x79,  0x0b,  0x0e,  0x02,  0x0f,  0xfe,  0x08,  0x90,  0x04,
14106   0xfe,  0x88,  0x93,  0x3a,  0x0b,  0x0e,  0x02,  0x0f,  0xfe,  0x8a,  0x90,  0x04,  0xfe,  0x8a,  0x93,  0x79,
14107   0x0b,  0x0e,  0x02,  0x0f,  0xfe,  0x0c,  0x90,  0x04,  0xfe,  0x8c,  0x93,  0x3a,  0x0b,  0x0e,  0x02,  0x0f,
14108   0xfe,  0x8e,  0x90,  0x04,  0xfe,  0x8e,  0x93,  0x79,  0x0b,  0x0e,  0x02,  0x0f,  0xfe,  0x3c,  0x90,  0x04,
14109   0xfe,  0xbc,  0x93,  0x3a,  0x0b,  0x0e,  0x02,  0x8b,  0x0f,  0xfe,  0x03,  0x80,  0x04,  0xfe,  0x83,  0x83,
14110   0x33,  0x0b,  0x77,  0x0e,  0xa8,  0x02,  0xff,  0x66,  0x00,  0x00,
14111 };
14112
14113 STATIC unsigned short _adv_asc38C1600_size =
14114         sizeof(_adv_asc38C1600_buf); /* 0x1673 */
14115 STATIC ADV_DCNT _adv_asc38C1600_chksum =
14116         0x0604EF77UL; /* Expanded little-endian checksum. */
14117
14118 /* a_init.c */
14119 /*
14120  * EEPROM Configuration.
14121  *
14122  * All drivers should use this structure to set the default EEPROM
14123  * configuration. The BIOS now uses this structure when it is built.
14124  * Additional structure information can be found in a_condor.h where
14125  * the structure is defined.
14126  *
14127  * The *_Field_IsChar structs are needed to correct for endianness.
14128  * These values are read from the board 16 bits at a time directly
14129  * into the structs. Because some fields are char, the values will be
14130  * in the wrong order. The *_Field_IsChar tells when to flip the
14131  * bytes. Data read and written to PCI memory is automatically swapped
14132  * on big-endian platforms so char fields read as words are actually being
14133  * unswapped on big-endian platforms.
14134  */
14135 STATIC ADVEEP_3550_CONFIG
14136 Default_3550_EEPROM_Config __initdata = {
14137     ADV_EEPROM_BIOS_ENABLE,     /* cfg_lsw */
14138     0x0000,                     /* cfg_msw */
14139     0xFFFF,                     /* disc_enable */
14140     0xFFFF,                     /* wdtr_able */
14141     0xFFFF,                     /* sdtr_able */
14142     0xFFFF,                     /* start_motor */
14143     0xFFFF,                     /* tagqng_able */
14144     0xFFFF,                     /* bios_scan */
14145     0,                          /* scam_tolerant */
14146     7,                          /* adapter_scsi_id */
14147     0,                          /* bios_boot_delay */
14148     3,                          /* scsi_reset_delay */
14149     0,                          /* bios_id_lun */
14150     0,                          /* termination */
14151     0,                          /* reserved1 */
14152     0xFFE7,                     /* bios_ctrl */
14153     0xFFFF,                     /* ultra_able */
14154     0,                          /* reserved2 */
14155     ASC_DEF_MAX_HOST_QNG,       /* max_host_qng */
14156     ASC_DEF_MAX_DVC_QNG,        /* max_dvc_qng */
14157     0,                          /* dvc_cntl */
14158     0,                          /* bug_fix */
14159     0,                          /* serial_number_word1 */
14160     0,                          /* serial_number_word2 */
14161     0,                          /* serial_number_word3 */
14162     0,                          /* check_sum */
14163     { 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 }, /* oem_name[16] */
14164     0,                          /* dvc_err_code */
14165     0,                          /* adv_err_code */
14166     0,                          /* adv_err_addr */
14167     0,                          /* saved_dvc_err_code */
14168     0,                          /* saved_adv_err_code */
14169     0,                          /* saved_adv_err_addr */
14170     0                           /* num_of_err */
14171 };
14172
14173 STATIC ADVEEP_3550_CONFIG
14174 ADVEEP_3550_Config_Field_IsChar __initdata = {
14175     0,                          /* cfg_lsw */
14176     0,                          /* cfg_msw */
14177     0,                          /* -disc_enable */
14178     0,                          /* wdtr_able */
14179     0,                          /* sdtr_able */
14180     0,                          /* start_motor */
14181     0,                          /* tagqng_able */
14182     0,                          /* bios_scan */
14183     0,                          /* scam_tolerant */
14184     1,                          /* adapter_scsi_id */
14185     1,                          /* bios_boot_delay */
14186     1,                          /* scsi_reset_delay */
14187     1,                          /* bios_id_lun */
14188     1,                          /* termination */
14189     1,                          /* reserved1 */
14190     0,                          /* bios_ctrl */
14191     0,                          /* ultra_able */
14192     0,                          /* reserved2 */
14193     1,                          /* max_host_qng */
14194     1,                          /* max_dvc_qng */
14195     0,                          /* dvc_cntl */
14196     0,                          /* bug_fix */
14197     0,                          /* serial_number_word1 */
14198     0,                          /* serial_number_word2 */
14199     0,                          /* serial_number_word3 */
14200     0,                          /* check_sum */
14201     { 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1 }, /* oem_name[16] */
14202     0,                          /* dvc_err_code */
14203     0,                          /* adv_err_code */
14204     0,                          /* adv_err_addr */
14205     0,                          /* saved_dvc_err_code */
14206     0,                          /* saved_adv_err_code */
14207     0,                          /* saved_adv_err_addr */
14208     0                           /* num_of_err */
14209 };
14210
14211 STATIC ADVEEP_38C0800_CONFIG
14212 Default_38C0800_EEPROM_Config __initdata = {
14213     ADV_EEPROM_BIOS_ENABLE,     /* 00 cfg_lsw */
14214     0x0000,                     /* 01 cfg_msw */
14215     0xFFFF,                     /* 02 disc_enable */
14216     0xFFFF,                     /* 03 wdtr_able */
14217     0x4444,                     /* 04 sdtr_speed1 */
14218     0xFFFF,                     /* 05 start_motor */
14219     0xFFFF,                     /* 06 tagqng_able */
14220     0xFFFF,                     /* 07 bios_scan */
14221     0,                          /* 08 scam_tolerant */
14222     7,                          /* 09 adapter_scsi_id */
14223     0,                          /*    bios_boot_delay */
14224     3,                          /* 10 scsi_reset_delay */
14225     0,                          /*    bios_id_lun */
14226     0,                          /* 11 termination_se */
14227     0,                          /*    termination_lvd */
14228     0xFFE7,                     /* 12 bios_ctrl */
14229     0x4444,                     /* 13 sdtr_speed2 */
14230     0x4444,                     /* 14 sdtr_speed3 */
14231     ASC_DEF_MAX_HOST_QNG,       /* 15 max_host_qng */
14232     ASC_DEF_MAX_DVC_QNG,        /*    max_dvc_qng */
14233     0,                          /* 16 dvc_cntl */
14234     0x4444,                     /* 17 sdtr_speed4 */
14235     0,                          /* 18 serial_number_word1 */
14236     0,                          /* 19 serial_number_word2 */
14237     0,                          /* 20 serial_number_word3 */
14238     0,                          /* 21 check_sum */
14239     { 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 }, /* 22-29 oem_name[16] */
14240     0,                          /* 30 dvc_err_code */
14241     0,                          /* 31 adv_err_code */
14242     0,                          /* 32 adv_err_addr */
14243     0,                          /* 33 saved_dvc_err_code */
14244     0,                          /* 34 saved_adv_err_code */
14245     0,                          /* 35 saved_adv_err_addr */
14246     0,                          /* 36 reserved */
14247     0,                          /* 37 reserved */
14248     0,                          /* 38 reserved */
14249     0,                          /* 39 reserved */
14250     0,                          /* 40 reserved */
14251     0,                          /* 41 reserved */
14252     0,                          /* 42 reserved */
14253     0,                          /* 43 reserved */
14254     0,                          /* 44 reserved */
14255     0,                          /* 45 reserved */
14256     0,                          /* 46 reserved */
14257     0,                          /* 47 reserved */
14258     0,                          /* 48 reserved */
14259     0,                          /* 49 reserved */
14260     0,                          /* 50 reserved */
14261     0,                          /* 51 reserved */
14262     0,                          /* 52 reserved */
14263     0,                          /* 53 reserved */
14264     0,                          /* 54 reserved */
14265     0,                          /* 55 reserved */
14266     0,                          /* 56 cisptr_lsw */
14267     0,                          /* 57 cisprt_msw */
14268     PCI_VENDOR_ID_ASP,          /* 58 subsysvid */
14269     PCI_DEVICE_ID_38C0800_REV1, /* 59 subsysid */
14270     0,                          /* 60 reserved */
14271     0,                          /* 61 reserved */
14272     0,                          /* 62 reserved */
14273     0                           /* 63 reserved */
14274 };
14275
14276 STATIC ADVEEP_38C0800_CONFIG
14277 ADVEEP_38C0800_Config_Field_IsChar __initdata = {
14278     0,                          /* 00 cfg_lsw */
14279     0,                          /* 01 cfg_msw */
14280     0,                          /* 02 disc_enable */
14281     0,                          /* 03 wdtr_able */
14282     0,                          /* 04 sdtr_speed1 */
14283     0,                          /* 05 start_motor */
14284     0,                          /* 06 tagqng_able */
14285     0,                          /* 07 bios_scan */
14286     0,                          /* 08 scam_tolerant */
14287     1,                          /* 09 adapter_scsi_id */
14288     1,                          /*    bios_boot_delay */
14289     1,                          /* 10 scsi_reset_delay */
14290     1,                          /*    bios_id_lun */
14291     1,                          /* 11 termination_se */
14292     1,                          /*    termination_lvd */
14293     0,                          /* 12 bios_ctrl */
14294     0,                          /* 13 sdtr_speed2 */
14295     0,                          /* 14 sdtr_speed3 */
14296     1,                          /* 15 max_host_qng */
14297     1,                          /*    max_dvc_qng */
14298     0,                          /* 16 dvc_cntl */
14299     0,                          /* 17 sdtr_speed4 */
14300     0,                          /* 18 serial_number_word1 */
14301     0,                          /* 19 serial_number_word2 */
14302     0,                          /* 20 serial_number_word3 */
14303     0,                          /* 21 check_sum */
14304     { 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1 }, /* 22-29 oem_name[16] */
14305     0,                          /* 30 dvc_err_code */
14306     0,                          /* 31 adv_err_code */
14307     0,                          /* 32 adv_err_addr */
14308     0,                          /* 33 saved_dvc_err_code */
14309     0,                          /* 34 saved_adv_err_code */
14310     0,                          /* 35 saved_adv_err_addr */
14311     0,                          /* 36 reserved */
14312     0,                          /* 37 reserved */
14313     0,                          /* 38 reserved */
14314     0,                          /* 39 reserved */
14315     0,                          /* 40 reserved */
14316     0,                          /* 41 reserved */
14317     0,                          /* 42 reserved */
14318     0,                          /* 43 reserved */
14319     0,                          /* 44 reserved */
14320     0,                          /* 45 reserved */
14321     0,                          /* 46 reserved */
14322     0,                          /* 47 reserved */
14323     0,                          /* 48 reserved */
14324     0,                          /* 49 reserved */
14325     0,                          /* 50 reserved */
14326     0,                          /* 51 reserved */
14327     0,                          /* 52 reserved */
14328     0,                          /* 53 reserved */
14329     0,                          /* 54 reserved */
14330     0,                          /* 55 reserved */
14331     0,                          /* 56 cisptr_lsw */
14332     0,                          /* 57 cisprt_msw */
14333     0,                          /* 58 subsysvid */
14334     0,                          /* 59 subsysid */
14335     0,                          /* 60 reserved */
14336     0,                          /* 61 reserved */
14337     0,                          /* 62 reserved */
14338     0                           /* 63 reserved */
14339 };
14340
14341 STATIC ADVEEP_38C1600_CONFIG
14342 Default_38C1600_EEPROM_Config __initdata = {
14343     ADV_EEPROM_BIOS_ENABLE,     /* 00 cfg_lsw */
14344     0x0000,                     /* 01 cfg_msw */
14345     0xFFFF,                     /* 02 disc_enable */
14346     0xFFFF,                     /* 03 wdtr_able */
14347     0x5555,                     /* 04 sdtr_speed1 */
14348     0xFFFF,                     /* 05 start_motor */
14349     0xFFFF,                     /* 06 tagqng_able */
14350     0xFFFF,                     /* 07 bios_scan */
14351     0,                          /* 08 scam_tolerant */
14352     7,                          /* 09 adapter_scsi_id */
14353     0,                          /*    bios_boot_delay */
14354     3,                          /* 10 scsi_reset_delay */
14355     0,                          /*    bios_id_lun */
14356     0,                          /* 11 termination_se */
14357     0,                          /*    termination_lvd */
14358     0xFFE7,                     /* 12 bios_ctrl */
14359     0x5555,                     /* 13 sdtr_speed2 */
14360     0x5555,                     /* 14 sdtr_speed3 */
14361     ASC_DEF_MAX_HOST_QNG,       /* 15 max_host_qng */
14362     ASC_DEF_MAX_DVC_QNG,        /*    max_dvc_qng */
14363     0,                          /* 16 dvc_cntl */
14364     0x5555,                     /* 17 sdtr_speed4 */
14365     0,                          /* 18 serial_number_word1 */
14366     0,                          /* 19 serial_number_word2 */
14367     0,                          /* 20 serial_number_word3 */
14368     0,                          /* 21 check_sum */
14369     { 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 }, /* 22-29 oem_name[16] */
14370     0,                          /* 30 dvc_err_code */
14371     0,                          /* 31 adv_err_code */
14372     0,                          /* 32 adv_err_addr */
14373     0,                          /* 33 saved_dvc_err_code */
14374     0,                          /* 34 saved_adv_err_code */
14375     0,                          /* 35 saved_adv_err_addr */
14376     0,                          /* 36 reserved */
14377     0,                          /* 37 reserved */
14378     0,                          /* 38 reserved */
14379     0,                          /* 39 reserved */
14380     0,                          /* 40 reserved */
14381     0,                          /* 41 reserved */
14382     0,                          /* 42 reserved */
14383     0,                          /* 43 reserved */
14384     0,                          /* 44 reserved */
14385     0,                          /* 45 reserved */
14386     0,                          /* 46 reserved */
14387     0,                          /* 47 reserved */
14388     0,                          /* 48 reserved */
14389     0,                          /* 49 reserved */
14390     0,                          /* 50 reserved */
14391     0,                          /* 51 reserved */
14392     0,                          /* 52 reserved */
14393     0,                          /* 53 reserved */
14394     0,                          /* 54 reserved */
14395     0,                          /* 55 reserved */
14396     0,                          /* 56 cisptr_lsw */
14397     0,                          /* 57 cisprt_msw */
14398     PCI_VENDOR_ID_ASP,          /* 58 subsysvid */
14399     PCI_DEVICE_ID_38C1600_REV1, /* 59 subsysid */
14400     0,                          /* 60 reserved */
14401     0,                          /* 61 reserved */
14402     0,                          /* 62 reserved */
14403     0                           /* 63 reserved */
14404 };
14405
14406 STATIC ADVEEP_38C1600_CONFIG
14407 ADVEEP_38C1600_Config_Field_IsChar __initdata = {
14408     0,                          /* 00 cfg_lsw */
14409     0,                          /* 01 cfg_msw */
14410     0,                          /* 02 disc_enable */
14411     0,                          /* 03 wdtr_able */
14412     0,                          /* 04 sdtr_speed1 */
14413     0,                          /* 05 start_motor */
14414     0,                          /* 06 tagqng_able */
14415     0,                          /* 07 bios_scan */
14416     0,                          /* 08 scam_tolerant */
14417     1,                          /* 09 adapter_scsi_id */
14418     1,                          /*    bios_boot_delay */
14419     1,                          /* 10 scsi_reset_delay */
14420     1,                          /*    bios_id_lun */
14421     1,                          /* 11 termination_se */
14422     1,                          /*    termination_lvd */
14423     0,                          /* 12 bios_ctrl */
14424     0,                          /* 13 sdtr_speed2 */
14425     0,                          /* 14 sdtr_speed3 */
14426     1,                          /* 15 max_host_qng */
14427     1,                          /*    max_dvc_qng */
14428     0,                          /* 16 dvc_cntl */
14429     0,                          /* 17 sdtr_speed4 */
14430     0,                          /* 18 serial_number_word1 */
14431     0,                          /* 19 serial_number_word2 */
14432     0,                          /* 20 serial_number_word3 */
14433     0,                          /* 21 check_sum */
14434     { 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1 }, /* 22-29 oem_name[16] */
14435     0,                          /* 30 dvc_err_code */
14436     0,                          /* 31 adv_err_code */
14437     0,                          /* 32 adv_err_addr */
14438     0,                          /* 33 saved_dvc_err_code */
14439     0,                          /* 34 saved_adv_err_code */
14440     0,                          /* 35 saved_adv_err_addr */
14441     0,                          /* 36 reserved */
14442     0,                          /* 37 reserved */
14443     0,                          /* 38 reserved */
14444     0,                          /* 39 reserved */
14445     0,                          /* 40 reserved */
14446     0,                          /* 41 reserved */
14447     0,                          /* 42 reserved */
14448     0,                          /* 43 reserved */
14449     0,                          /* 44 reserved */
14450     0,                          /* 45 reserved */
14451     0,                          /* 46 reserved */
14452     0,                          /* 47 reserved */
14453     0,                          /* 48 reserved */
14454     0,                          /* 49 reserved */
14455     0,                          /* 50 reserved */
14456     0,                          /* 51 reserved */
14457     0,                          /* 52 reserved */
14458     0,                          /* 53 reserved */
14459     0,                          /* 54 reserved */
14460     0,                          /* 55 reserved */
14461     0,                          /* 56 cisptr_lsw */
14462     0,                          /* 57 cisprt_msw */
14463     0,                          /* 58 subsysvid */
14464     0,                          /* 59 subsysid */
14465     0,                          /* 60 reserved */
14466     0,                          /* 61 reserved */
14467     0,                          /* 62 reserved */
14468     0                           /* 63 reserved */
14469 };
14470
14471 /*
14472  * Initialize the ADV_DVC_VAR structure.
14473  *
14474  * On failure set the ADV_DVC_VAR field 'err_code' and return ADV_ERROR.
14475  *
14476  * For a non-fatal error return a warning code. If there are no warnings
14477  * then 0 is returned.
14478  */
14479 STATIC int __init
14480 AdvInitGetConfig(ADV_DVC_VAR *asc_dvc)
14481 {
14482     ushort      warn_code;
14483     AdvPortAddr iop_base;
14484     uchar       pci_cmd_reg;
14485     int         status;
14486
14487     warn_code = 0;
14488     asc_dvc->err_code = 0;
14489     iop_base = asc_dvc->iop_base;
14490
14491     /*
14492      * PCI Command Register
14493      *
14494      * Note: AscPCICmdRegBits_BusMastering definition (0x0007) includes
14495      * I/O Space Control, Memory Space Control and Bus Master Control bits.
14496      */
14497
14498     if (((pci_cmd_reg = DvcAdvReadPCIConfigByte(asc_dvc,
14499                             AscPCIConfigCommandRegister))
14500          & AscPCICmdRegBits_BusMastering)
14501         != AscPCICmdRegBits_BusMastering)
14502     {
14503         pci_cmd_reg |= AscPCICmdRegBits_BusMastering;
14504
14505         DvcAdvWritePCIConfigByte(asc_dvc,
14506                 AscPCIConfigCommandRegister, pci_cmd_reg);
14507
14508         if (((DvcAdvReadPCIConfigByte(asc_dvc, AscPCIConfigCommandRegister))
14509              & AscPCICmdRegBits_BusMastering)
14510             != AscPCICmdRegBits_BusMastering)
14511         {
14512             warn_code |= ASC_WARN_SET_PCI_CONFIG_SPACE;
14513         }
14514     }
14515
14516     /*
14517      * PCI Latency Timer
14518      *
14519      * If the "latency timer" register is 0x20 or above, then we don't need
14520      * to change it.  Otherwise, set it to 0x20 (i.e. set it to 0x20 if it
14521      * comes up less than 0x20).
14522      */
14523     if (DvcAdvReadPCIConfigByte(asc_dvc, AscPCIConfigLatencyTimer) < 0x20) {
14524         DvcAdvWritePCIConfigByte(asc_dvc, AscPCIConfigLatencyTimer, 0x20);
14525         if (DvcAdvReadPCIConfigByte(asc_dvc, AscPCIConfigLatencyTimer) < 0x20)
14526         {
14527             warn_code |= ASC_WARN_SET_PCI_CONFIG_SPACE;
14528         }
14529     }
14530
14531     /*
14532      * Save the state of the PCI Configuration Command Register
14533      * "Parity Error Response Control" Bit. If the bit is clear (0),
14534      * in AdvInitAsc3550/38C0800Driver() tell the microcode to ignore
14535      * DMA parity errors.
14536      */
14537     asc_dvc->cfg->control_flag = 0;
14538     if (((DvcAdvReadPCIConfigByte(asc_dvc, AscPCIConfigCommandRegister)
14539          & AscPCICmdRegBits_ParErrRespCtrl)) == 0)
14540     {
14541         asc_dvc->cfg->control_flag |= CONTROL_FLAG_IGNORE_PERR;
14542     }
14543
14544     asc_dvc->cfg->lib_version = (ADV_LIB_VERSION_MAJOR << 8) |
14545       ADV_LIB_VERSION_MINOR;
14546     asc_dvc->cfg->chip_version =
14547       AdvGetChipVersion(iop_base, asc_dvc->bus_type);
14548
14549     ASC_DBG2(1, "AdvInitGetConfig: iopb_chip_id_1: 0x%x 0x%x\n",
14550         (ushort) AdvReadByteRegister(iop_base, IOPB_CHIP_ID_1),
14551         (ushort) ADV_CHIP_ID_BYTE);
14552
14553     ASC_DBG2(1, "AdvInitGetConfig: iopw_chip_id_0: 0x%x 0x%x\n",
14554         (ushort) AdvReadWordRegister(iop_base, IOPW_CHIP_ID_0),
14555         (ushort) ADV_CHIP_ID_WORD);
14556
14557     /*
14558      * Reset the chip to start and allow register writes.
14559      */
14560     if (AdvFindSignature(iop_base) == 0)
14561     {
14562         asc_dvc->err_code = ASC_IERR_BAD_SIGNATURE;
14563         return ADV_ERROR;
14564     }
14565     else {
14566         /*
14567          * The caller must set 'chip_type' to a valid setting.
14568          */
14569         if (asc_dvc->chip_type != ADV_CHIP_ASC3550 &&
14570             asc_dvc->chip_type != ADV_CHIP_ASC38C0800 &&
14571             asc_dvc->chip_type != ADV_CHIP_ASC38C1600)
14572         {
14573             asc_dvc->err_code |= ASC_IERR_BAD_CHIPTYPE;
14574             return ADV_ERROR;
14575         }
14576
14577         /*
14578          * Reset Chip.
14579          */
14580         AdvWriteWordRegister(iop_base, IOPW_CTRL_REG,
14581             ADV_CTRL_REG_CMD_RESET);
14582         DvcSleepMilliSecond(100);
14583         AdvWriteWordRegister(iop_base, IOPW_CTRL_REG,
14584             ADV_CTRL_REG_CMD_WR_IO_REG);
14585
14586         if (asc_dvc->chip_type == ADV_CHIP_ASC38C1600)
14587         {
14588             if ((status = AdvInitFrom38C1600EEP(asc_dvc)) == ADV_ERROR)
14589             {
14590                 return ADV_ERROR;
14591             }
14592         } else if (asc_dvc->chip_type == ADV_CHIP_ASC38C0800)
14593         {
14594             if ((status = AdvInitFrom38C0800EEP(asc_dvc)) == ADV_ERROR)
14595             {
14596                 return ADV_ERROR;
14597             }
14598         } else
14599         {
14600             if ((status = AdvInitFrom3550EEP(asc_dvc)) == ADV_ERROR)
14601             {
14602                 return ADV_ERROR;
14603             }
14604         }
14605         warn_code |= status;
14606     }
14607
14608     return warn_code;
14609 }
14610
14611 /*
14612  * Initialize the ASC-3550.
14613  *
14614  * On failure set the ADV_DVC_VAR field 'err_code' and return ADV_ERROR.
14615  *
14616  * For a non-fatal error return a warning code. If there are no warnings
14617  * then 0 is returned.
14618  *
14619  * Needed after initialization for error recovery.
14620  */
14621 STATIC int
14622 AdvInitAsc3550Driver(ADV_DVC_VAR *asc_dvc)
14623 {
14624     AdvPortAddr iop_base;
14625     ushort      warn_code;
14626     ADV_DCNT    sum;
14627     int         begin_addr;
14628     int         end_addr;
14629     ushort      code_sum;
14630     int         word;
14631     int         j;
14632     int         adv_asc3550_expanded_size;
14633     ADV_CARR_T  *carrp;
14634     ADV_DCNT    contig_len;
14635     ADV_SDCNT   buf_size;
14636     ADV_PADDR   carr_paddr;
14637     int         i;
14638     ushort      scsi_cfg1;
14639     uchar       tid;
14640     ushort      bios_mem[ASC_MC_BIOSLEN/2]; /* BIOS RISC Memory 0x40-0x8F. */
14641     ushort      wdtr_able = 0, sdtr_able, tagqng_able;
14642     uchar       max_cmd[ADV_MAX_TID + 1];
14643
14644     /* If there is already an error, don't continue. */
14645     if (asc_dvc->err_code != 0)
14646     {
14647         return ADV_ERROR;
14648     }
14649
14650     /*
14651      * The caller must set 'chip_type' to ADV_CHIP_ASC3550.
14652      */
14653     if (asc_dvc->chip_type != ADV_CHIP_ASC3550)
14654     {
14655         asc_dvc->err_code |= ASC_IERR_BAD_CHIPTYPE;
14656         return ADV_ERROR;
14657     }
14658
14659     warn_code = 0;
14660     iop_base = asc_dvc->iop_base;
14661
14662     /*
14663      * Save the RISC memory BIOS region before writing the microcode.
14664      * The BIOS may already be loaded and using its RISC LRAM region
14665      * so its region must be saved and restored.
14666      *
14667      * Note: This code makes the assumption, which is currently true,
14668      * that a chip reset does not clear RISC LRAM.
14669      */
14670     for (i = 0; i < ASC_MC_BIOSLEN/2; i++)
14671     {
14672         AdvReadWordLram(iop_base, ASC_MC_BIOSMEM + (2 * i), bios_mem[i]);
14673     }
14674
14675     /*
14676      * Save current per TID negotiated values.
14677      */
14678     if (bios_mem[(ASC_MC_BIOS_SIGNATURE - ASC_MC_BIOSMEM)/2] == 0x55AA)
14679     {
14680         ushort  bios_version, major, minor;
14681
14682         bios_version = bios_mem[(ASC_MC_BIOS_VERSION - ASC_MC_BIOSMEM)/2];
14683         major = (bios_version  >> 12) & 0xF;
14684         minor = (bios_version  >> 8) & 0xF;
14685         if (major < 3 || (major == 3 && minor == 1))
14686         {
14687             /* BIOS 3.1 and earlier location of 'wdtr_able' variable. */
14688             AdvReadWordLram(iop_base, 0x120, wdtr_able);
14689         } else
14690         {
14691             AdvReadWordLram(iop_base, ASC_MC_WDTR_ABLE, wdtr_able);
14692         }
14693     }
14694     AdvReadWordLram(iop_base, ASC_MC_SDTR_ABLE, sdtr_able);
14695     AdvReadWordLram(iop_base, ASC_MC_TAGQNG_ABLE, tagqng_able);
14696     for (tid = 0; tid <= ADV_MAX_TID; tid++)
14697     {
14698         AdvReadByteLram(iop_base, ASC_MC_NUMBER_OF_MAX_CMD + tid,
14699             max_cmd[tid]);
14700     }
14701
14702     /*
14703      * Load the Microcode
14704      *
14705      * Write the microcode image to RISC memory starting at address 0.
14706      */
14707     AdvWriteWordRegister(iop_base, IOPW_RAM_ADDR, 0);
14708     /* Assume the following compressed format of the microcode buffer:
14709      *
14710      *  254 word (508 byte) table indexed by byte code followed
14711      *  by the following byte codes:
14712      *
14713      *    1-Byte Code:
14714      *      00: Emit word 0 in table.
14715      *      01: Emit word 1 in table.
14716      *      .
14717      *      FD: Emit word 253 in table.
14718      *
14719      *    Multi-Byte Code:
14720      *      FE WW WW: (3 byte code) Word to emit is the next word WW WW.
14721      *      FF BB WW WW: (4 byte code) Emit BB count times next word WW WW.
14722      */
14723     word = 0;
14724     for (i = 253 * 2; i < _adv_asc3550_size; i++)
14725     {
14726         if (_adv_asc3550_buf[i] == 0xff)
14727         {
14728             for (j = 0; j < _adv_asc3550_buf[i + 1]; j++)
14729             {
14730                 AdvWriteWordAutoIncLram(iop_base, (((ushort)
14731                     _adv_asc3550_buf[i + 3] << 8) |
14732                 _adv_asc3550_buf[i + 2]));
14733                 word++;
14734             }
14735             i += 3;
14736         } else if (_adv_asc3550_buf[i] == 0xfe)
14737         {
14738             AdvWriteWordAutoIncLram(iop_base, (((ushort)
14739                 _adv_asc3550_buf[i + 2] << 8) |
14740                 _adv_asc3550_buf[i + 1]));
14741             i += 2;
14742             word++;
14743         } else
14744         {
14745             AdvWriteWordAutoIncLram(iop_base, (((ushort)
14746                 _adv_asc3550_buf[(_adv_asc3550_buf[i] * 2) + 1] << 8) |
14747                 _adv_asc3550_buf[_adv_asc3550_buf[i] * 2]));
14748             word++;
14749         }
14750     }
14751
14752     /*
14753      * Set 'word' for later use to clear the rest of memory and save
14754      * the expanded mcode size.
14755      */
14756     word *= 2;
14757     adv_asc3550_expanded_size = word;
14758
14759     /*
14760      * Clear the rest of ASC-3550 Internal RAM (8KB).
14761      */
14762     for (; word < ADV_3550_MEMSIZE; word += 2)
14763     {
14764         AdvWriteWordAutoIncLram(iop_base, 0);
14765     }
14766
14767     /*
14768      * Verify the microcode checksum.
14769      */
14770     sum = 0;
14771     AdvWriteWordRegister(iop_base, IOPW_RAM_ADDR, 0);
14772
14773     for (word = 0; word < adv_asc3550_expanded_size; word += 2)
14774     {
14775         sum += AdvReadWordAutoIncLram(iop_base);
14776     }
14777
14778     if (sum != _adv_asc3550_chksum)
14779     {
14780         asc_dvc->err_code |= ASC_IERR_MCODE_CHKSUM;
14781         return ADV_ERROR;
14782     }
14783
14784     /*
14785      * Restore the RISC memory BIOS region.
14786      */
14787     for (i = 0; i < ASC_MC_BIOSLEN/2; i++)
14788     {
14789         AdvWriteWordLram(iop_base, ASC_MC_BIOSMEM + (2 * i), bios_mem[i]);
14790     }
14791
14792     /*
14793      * Calculate and write the microcode code checksum to the microcode
14794      * code checksum location ASC_MC_CODE_CHK_SUM (0x2C).
14795      */
14796     AdvReadWordLram(iop_base, ASC_MC_CODE_BEGIN_ADDR, begin_addr);
14797     AdvReadWordLram(iop_base, ASC_MC_CODE_END_ADDR, end_addr);
14798     code_sum = 0;
14799     AdvWriteWordRegister(iop_base, IOPW_RAM_ADDR, begin_addr);
14800     for (word = begin_addr; word < end_addr; word += 2)
14801     {
14802         code_sum += AdvReadWordAutoIncLram(iop_base);
14803     }
14804     AdvWriteWordLram(iop_base, ASC_MC_CODE_CHK_SUM, code_sum);
14805
14806     /*
14807      * Read and save microcode version and date.
14808      */
14809     AdvReadWordLram(iop_base, ASC_MC_VERSION_DATE, asc_dvc->cfg->mcode_date);
14810     AdvReadWordLram(iop_base, ASC_MC_VERSION_NUM, asc_dvc->cfg->mcode_version);
14811
14812     /*
14813      * Set the chip type to indicate the ASC3550.
14814      */
14815     AdvWriteWordLram(iop_base, ASC_MC_CHIP_TYPE, ADV_CHIP_ASC3550);
14816
14817     /*
14818      * If the PCI Configuration Command Register "Parity Error Response
14819      * Control" Bit was clear (0), then set the microcode variable
14820      * 'control_flag' CONTROL_FLAG_IGNORE_PERR flag to tell the microcode
14821      * to ignore DMA parity errors.
14822      */
14823     if (asc_dvc->cfg->control_flag & CONTROL_FLAG_IGNORE_PERR)
14824     {
14825         AdvReadWordLram(iop_base, ASC_MC_CONTROL_FLAG, word);
14826         word |= CONTROL_FLAG_IGNORE_PERR;
14827         AdvWriteWordLram(iop_base, ASC_MC_CONTROL_FLAG, word);
14828     }
14829
14830     /*
14831      * For ASC-3550, setting the START_CTL_EMFU [3:2] bits sets a FIFO
14832      * threshold of 128 bytes. This register is only accessible to the host.
14833      */
14834     AdvWriteByteRegister(iop_base, IOPB_DMA_CFG0,
14835         START_CTL_EMFU | READ_CMD_MRM);
14836
14837     /*
14838      * Microcode operating variables for WDTR, SDTR, and command tag
14839      * queuing will be set in AdvInquiryHandling() based on what a
14840      * device reports it is capable of in Inquiry byte 7.
14841      *
14842      * If SCSI Bus Resets have been disabled, then directly set
14843      * SDTR and WDTR from the EEPROM configuration. This will allow
14844      * the BIOS and warm boot to work without a SCSI bus hang on
14845      * the Inquiry caused by host and target mismatched DTR values.
14846      * Without the SCSI Bus Reset, before an Inquiry a device can't
14847      * be assumed to be in Asynchronous, Narrow mode.
14848      */
14849     if ((asc_dvc->bios_ctrl & BIOS_CTRL_RESET_SCSI_BUS) == 0)
14850     {
14851         AdvWriteWordLram(iop_base, ASC_MC_WDTR_ABLE, asc_dvc->wdtr_able);
14852         AdvWriteWordLram(iop_base, ASC_MC_SDTR_ABLE, asc_dvc->sdtr_able);
14853     }
14854
14855     /*
14856      * Set microcode operating variables for SDTR_SPEED1, SDTR_SPEED2,
14857      * SDTR_SPEED3, and SDTR_SPEED4 based on the ULTRA EEPROM per TID
14858      * bitmask. These values determine the maximum SDTR speed negotiated
14859      * with a device.
14860      *
14861      * The SDTR per TID bitmask overrides the SDTR_SPEED1, SDTR_SPEED2,
14862      * SDTR_SPEED3, and SDTR_SPEED4 values so it is safe to set them
14863      * without determining here whether the device supports SDTR.
14864      *
14865      * 4-bit speed  SDTR speed name
14866      * ===========  ===============
14867      * 0000b (0x0)  SDTR disabled
14868      * 0001b (0x1)  5 Mhz
14869      * 0010b (0x2)  10 Mhz
14870      * 0011b (0x3)  20 Mhz (Ultra)
14871      * 0100b (0x4)  40 Mhz (LVD/Ultra2)
14872      * 0101b (0x5)  80 Mhz (LVD2/Ultra3)
14873      * 0110b (0x6)  Undefined
14874      * .
14875      * 1111b (0xF)  Undefined
14876      */
14877     word = 0;
14878     for (tid = 0; tid <= ADV_MAX_TID; tid++)
14879     {
14880         if (ADV_TID_TO_TIDMASK(tid) & asc_dvc->ultra_able)
14881         {
14882             /* Set Ultra speed for TID 'tid'. */
14883             word |= (0x3 << (4 * (tid % 4)));
14884         } else
14885         {
14886             /* Set Fast speed for TID 'tid'. */
14887             word |= (0x2 << (4 * (tid % 4)));
14888         }
14889         if (tid == 3) /* Check if done with sdtr_speed1. */
14890         {
14891             AdvWriteWordLram(iop_base, ASC_MC_SDTR_SPEED1, word);
14892             word = 0;
14893         } else if (tid == 7) /* Check if done with sdtr_speed2. */
14894         {
14895             AdvWriteWordLram(iop_base, ASC_MC_SDTR_SPEED2, word);
14896             word = 0;
14897         } else if (tid == 11) /* Check if done with sdtr_speed3. */
14898         {
14899             AdvWriteWordLram(iop_base, ASC_MC_SDTR_SPEED3, word);
14900             word = 0;
14901         } else if (tid == 15) /* Check if done with sdtr_speed4. */
14902         {
14903             AdvWriteWordLram(iop_base, ASC_MC_SDTR_SPEED4, word);
14904             /* End of loop. */
14905         }
14906     }
14907
14908     /*
14909      * Set microcode operating variable for the disconnect per TID bitmask.
14910      */
14911     AdvWriteWordLram(iop_base, ASC_MC_DISC_ENABLE, asc_dvc->cfg->disc_enable);
14912
14913     /*
14914      * Set SCSI_CFG0 Microcode Default Value.
14915      *
14916      * The microcode will set the SCSI_CFG0 register using this value
14917      * after it is started below.
14918      */
14919     AdvWriteWordLram(iop_base, ASC_MC_DEFAULT_SCSI_CFG0,
14920         PARITY_EN | QUEUE_128 | SEL_TMO_LONG | OUR_ID_EN |
14921         asc_dvc->chip_scsi_id);
14922
14923     /*
14924      * Determine SCSI_CFG1 Microcode Default Value.
14925      *
14926      * The microcode will set the SCSI_CFG1 register using this value
14927      * after it is started below.
14928      */
14929
14930     /* Read current SCSI_CFG1 Register value. */
14931     scsi_cfg1 = AdvReadWordRegister(iop_base, IOPW_SCSI_CFG1);
14932
14933     /*
14934      * If all three connectors are in use, return an error.
14935      */
14936     if ((scsi_cfg1 & CABLE_ILLEGAL_A) == 0 ||
14937         (scsi_cfg1 & CABLE_ILLEGAL_B) == 0)
14938     {
14939             asc_dvc->err_code |= ASC_IERR_ILLEGAL_CONNECTION;
14940             return ADV_ERROR;
14941     }
14942
14943     /*
14944      * If the internal narrow cable is reversed all of the SCSI_CTRL
14945      * register signals will be set. Check for and return an error if
14946      * this condition is found.
14947      */
14948     if ((AdvReadWordRegister(iop_base, IOPW_SCSI_CTRL) & 0x3F07) == 0x3F07)
14949     {
14950         asc_dvc->err_code |= ASC_IERR_REVERSED_CABLE;
14951         return ADV_ERROR;
14952     }
14953
14954     /*
14955      * If this is a differential board and a single-ended device
14956      * is attached to one of the connectors, return an error.
14957      */
14958     if ((scsi_cfg1 & DIFF_MODE) && (scsi_cfg1 & DIFF_SENSE) == 0)
14959     {
14960         asc_dvc->err_code |= ASC_IERR_SINGLE_END_DEVICE;
14961         return ADV_ERROR;
14962     }
14963
14964     /*
14965      * If automatic termination control is enabled, then set the
14966      * termination value based on a table listed in a_condor.h.
14967      *
14968      * If manual termination was specified with an EEPROM setting
14969      * then 'termination' was set-up in AdvInitFrom3550EEPROM() and
14970      * is ready to be 'ored' into SCSI_CFG1.
14971      */
14972     if (asc_dvc->cfg->termination == 0)
14973     {
14974         /*
14975          * The software always controls termination by setting TERM_CTL_SEL.
14976          * If TERM_CTL_SEL were set to 0, the hardware would set termination.
14977          */
14978         asc_dvc->cfg->termination |= TERM_CTL_SEL;
14979
14980         switch(scsi_cfg1 & CABLE_DETECT)
14981         {
14982             /* TERM_CTL_H: on, TERM_CTL_L: on */
14983             case 0x3: case 0x7: case 0xB: case 0xD: case 0xE: case 0xF:
14984                 asc_dvc->cfg->termination |= (TERM_CTL_H | TERM_CTL_L);
14985                 break;
14986
14987             /* TERM_CTL_H: on, TERM_CTL_L: off */
14988             case 0x1: case 0x5: case 0x9: case 0xA: case 0xC:
14989                 asc_dvc->cfg->termination |= TERM_CTL_H;
14990                 break;
14991
14992             /* TERM_CTL_H: off, TERM_CTL_L: off */
14993             case 0x2: case 0x6:
14994                 break;
14995         }
14996     }
14997
14998     /*
14999      * Clear any set TERM_CTL_H and TERM_CTL_L bits.
15000      */
15001     scsi_cfg1 &= ~TERM_CTL;
15002
15003     /*
15004      * Invert the TERM_CTL_H and TERM_CTL_L bits and then
15005      * set 'scsi_cfg1'. The TERM_POL bit does not need to be
15006      * referenced, because the hardware internally inverts
15007      * the Termination High and Low bits if TERM_POL is set.
15008      */
15009     scsi_cfg1 |= (TERM_CTL_SEL | (~asc_dvc->cfg->termination & TERM_CTL));
15010
15011     /*
15012      * Set SCSI_CFG1 Microcode Default Value
15013      *
15014      * Set filter value and possibly modified termination control
15015      * bits in the Microcode SCSI_CFG1 Register Value.
15016      *
15017      * The microcode will set the SCSI_CFG1 register using this value
15018      * after it is started below.
15019      */
15020     AdvWriteWordLram(iop_base, ASC_MC_DEFAULT_SCSI_CFG1,
15021         FLTR_DISABLE | scsi_cfg1);
15022
15023     /*
15024      * Set MEM_CFG Microcode Default Value
15025      *
15026      * The microcode will set the MEM_CFG register using this value
15027      * after it is started below.
15028      *
15029      * MEM_CFG may be accessed as a word or byte, but only bits 0-7
15030      * are defined.
15031      *
15032      * ASC-3550 has 8KB internal memory.
15033      */
15034     AdvWriteWordLram(iop_base, ASC_MC_DEFAULT_MEM_CFG,
15035         BIOS_EN | RAM_SZ_8KB);
15036
15037     /*
15038      * Set SEL_MASK Microcode Default Value
15039      *
15040      * The microcode will set the SEL_MASK register using this value
15041      * after it is started below.
15042      */
15043     AdvWriteWordLram(iop_base, ASC_MC_DEFAULT_SEL_MASK,
15044         ADV_TID_TO_TIDMASK(asc_dvc->chip_scsi_id));
15045
15046     /*
15047      * Build carrier freelist.
15048      *
15049      * Driver must have already allocated memory and set 'carrier_buf'.
15050      */
15051     ASC_ASSERT(asc_dvc->carrier_buf != NULL);
15052
15053     carrp = (ADV_CARR_T *) ADV_16BALIGN(asc_dvc->carrier_buf);
15054     asc_dvc->carr_freelist = NULL;
15055     if (carrp == (ADV_CARR_T *) asc_dvc->carrier_buf)
15056     {
15057         buf_size = ADV_CARRIER_BUFSIZE;
15058     } else
15059     {
15060         buf_size = ADV_CARRIER_BUFSIZE - sizeof(ADV_CARR_T);
15061     }
15062
15063     do {
15064         /*
15065          * Get physical address of the carrier 'carrp'.
15066          */
15067         contig_len = sizeof(ADV_CARR_T);
15068         carr_paddr = cpu_to_le32(DvcGetPhyAddr(asc_dvc, NULL, (uchar *) carrp,
15069             (ADV_SDCNT *) &contig_len, ADV_IS_CARRIER_FLAG));
15070
15071         buf_size -= sizeof(ADV_CARR_T);
15072
15073         /*
15074          * If the current carrier is not physically contiguous, then
15075          * maybe there was a page crossing. Try the next carrier aligned
15076          * start address.
15077          */
15078         if (contig_len < sizeof(ADV_CARR_T))
15079         {
15080             carrp++;
15081             continue;
15082         }
15083
15084         carrp->carr_pa = carr_paddr;
15085         carrp->carr_va = cpu_to_le32(ADV_VADDR_TO_U32(carrp));
15086
15087         /*
15088          * Insert the carrier at the beginning of the freelist.
15089          */
15090         carrp->next_vpa = cpu_to_le32(ADV_VADDR_TO_U32(asc_dvc->carr_freelist));
15091         asc_dvc->carr_freelist = carrp;
15092
15093         carrp++;
15094     }
15095     while (buf_size > 0);
15096
15097     /*
15098      * Set-up the Host->RISC Initiator Command Queue (ICQ).
15099      */
15100
15101     if ((asc_dvc->icq_sp = asc_dvc->carr_freelist) == NULL)
15102     {
15103         asc_dvc->err_code |= ASC_IERR_NO_CARRIER;
15104         return ADV_ERROR;
15105     }
15106     asc_dvc->carr_freelist = (ADV_CARR_T *)
15107         ADV_U32_TO_VADDR(le32_to_cpu(asc_dvc->icq_sp->next_vpa));
15108
15109     /*
15110      * The first command issued will be placed in the stopper carrier.
15111      */
15112     asc_dvc->icq_sp->next_vpa = cpu_to_le32(ASC_CQ_STOPPER);
15113
15114     /*
15115      * Set RISC ICQ physical address start value.
15116      */
15117     AdvWriteDWordLramNoSwap(iop_base, ASC_MC_ICQ, asc_dvc->icq_sp->carr_pa);
15118
15119     /*
15120      * Set-up the RISC->Host Initiator Response Queue (IRQ).
15121      */
15122     if ((asc_dvc->irq_sp = asc_dvc->carr_freelist) == NULL)
15123     {
15124         asc_dvc->err_code |= ASC_IERR_NO_CARRIER;
15125         return ADV_ERROR;
15126     }
15127     asc_dvc->carr_freelist = (ADV_CARR_T *)
15128          ADV_U32_TO_VADDR(le32_to_cpu(asc_dvc->irq_sp->next_vpa));
15129
15130     /*
15131      * The first command completed by the RISC will be placed in
15132      * the stopper.
15133      *
15134      * Note: Set 'next_vpa' to ASC_CQ_STOPPER. When the request is
15135      * completed the RISC will set the ASC_RQ_STOPPER bit.
15136      */
15137     asc_dvc->irq_sp->next_vpa = cpu_to_le32(ASC_CQ_STOPPER);
15138
15139     /*
15140      * Set RISC IRQ physical address start value.
15141      */
15142     AdvWriteDWordLramNoSwap(iop_base, ASC_MC_IRQ, asc_dvc->irq_sp->carr_pa);
15143     asc_dvc->carr_pending_cnt = 0;
15144
15145     AdvWriteByteRegister(iop_base, IOPB_INTR_ENABLES,
15146         (ADV_INTR_ENABLE_HOST_INTR | ADV_INTR_ENABLE_GLOBAL_INTR));
15147
15148     AdvReadWordLram(iop_base, ASC_MC_CODE_BEGIN_ADDR, word);
15149     AdvWriteWordRegister(iop_base, IOPW_PC, word);
15150
15151     /* finally, finally, gentlemen, start your engine */
15152     AdvWriteWordRegister(iop_base, IOPW_RISC_CSR, ADV_RISC_CSR_RUN);
15153
15154     /*
15155      * Reset the SCSI Bus if the EEPROM indicates that SCSI Bus
15156      * Resets should be performed. The RISC has to be running
15157      * to issue a SCSI Bus Reset.
15158      */
15159     if (asc_dvc->bios_ctrl & BIOS_CTRL_RESET_SCSI_BUS)
15160     {
15161         /*
15162          * If the BIOS Signature is present in memory, restore the
15163          * BIOS Handshake Configuration Table and do not perform
15164          * a SCSI Bus Reset.
15165          */
15166         if (bios_mem[(ASC_MC_BIOS_SIGNATURE - ASC_MC_BIOSMEM)/2] == 0x55AA)
15167         {
15168             /*
15169              * Restore per TID negotiated values.
15170              */
15171             AdvWriteWordLram(iop_base, ASC_MC_WDTR_ABLE, wdtr_able);
15172             AdvWriteWordLram(iop_base, ASC_MC_SDTR_ABLE, sdtr_able);
15173             AdvWriteWordLram(iop_base, ASC_MC_TAGQNG_ABLE, tagqng_able);
15174             for (tid = 0; tid <= ADV_MAX_TID; tid++)
15175             {
15176                 AdvWriteByteLram(iop_base, ASC_MC_NUMBER_OF_MAX_CMD + tid,
15177                     max_cmd[tid]);
15178             }
15179         } else
15180         {
15181             if (AdvResetSB(asc_dvc) != ADV_TRUE)
15182             {
15183                 warn_code = ASC_WARN_BUSRESET_ERROR;
15184             }
15185         }
15186     }
15187
15188     return warn_code;
15189 }
15190
15191 /*
15192  * Initialize the ASC-38C0800.
15193  *
15194  * On failure set the ADV_DVC_VAR field 'err_code' and return ADV_ERROR.
15195  *
15196  * For a non-fatal error return a warning code. If there are no warnings
15197  * then 0 is returned.
15198  *
15199  * Needed after initialization for error recovery.
15200  */
15201 STATIC int
15202 AdvInitAsc38C0800Driver(ADV_DVC_VAR *asc_dvc)
15203 {
15204     AdvPortAddr iop_base;
15205     ushort      warn_code;
15206     ADV_DCNT    sum;
15207     int         begin_addr;
15208     int         end_addr;
15209     ushort      code_sum;
15210     int         word;
15211     int         j;
15212     int         adv_asc38C0800_expanded_size;
15213     ADV_CARR_T  *carrp;
15214     ADV_DCNT    contig_len;
15215     ADV_SDCNT   buf_size;
15216     ADV_PADDR   carr_paddr;
15217     int         i;
15218     ushort      scsi_cfg1;
15219     uchar       byte;
15220     uchar       tid;
15221     ushort      bios_mem[ASC_MC_BIOSLEN/2]; /* BIOS RISC Memory 0x40-0x8F. */
15222     ushort      wdtr_able, sdtr_able, tagqng_able;
15223     uchar       max_cmd[ADV_MAX_TID + 1];
15224
15225     /* If there is already an error, don't continue. */
15226     if (asc_dvc->err_code != 0)
15227     {
15228         return ADV_ERROR;
15229     }
15230
15231     /*
15232      * The caller must set 'chip_type' to ADV_CHIP_ASC38C0800.
15233      */
15234     if (asc_dvc->chip_type != ADV_CHIP_ASC38C0800)
15235     {
15236         asc_dvc->err_code = ASC_IERR_BAD_CHIPTYPE;
15237         return ADV_ERROR;
15238     }
15239
15240     warn_code = 0;
15241     iop_base = asc_dvc->iop_base;
15242
15243     /*
15244      * Save the RISC memory BIOS region before writing the microcode.
15245      * The BIOS may already be loaded and using its RISC LRAM region
15246      * so its region must be saved and restored.
15247      *
15248      * Note: This code makes the assumption, which is currently true,
15249      * that a chip reset does not clear RISC LRAM.
15250      */
15251     for (i = 0; i < ASC_MC_BIOSLEN/2; i++)
15252     {
15253         AdvReadWordLram(iop_base, ASC_MC_BIOSMEM + (2 * i), bios_mem[i]);
15254     }
15255
15256     /*
15257      * Save current per TID negotiated values.
15258      */
15259     AdvReadWordLram(iop_base, ASC_MC_WDTR_ABLE, wdtr_able);
15260     AdvReadWordLram(iop_base, ASC_MC_SDTR_ABLE, sdtr_able);
15261     AdvReadWordLram(iop_base, ASC_MC_TAGQNG_ABLE, tagqng_able);
15262     for (tid = 0; tid <= ADV_MAX_TID; tid++)
15263     {
15264         AdvReadByteLram(iop_base, ASC_MC_NUMBER_OF_MAX_CMD + tid,
15265             max_cmd[tid]);
15266     }
15267
15268     /*
15269      * RAM BIST (RAM Built-In Self Test)
15270      *
15271      * Address : I/O base + offset 0x38h register (byte).
15272      * Function: Bit 7-6(RW) : RAM mode
15273      *                          Normal Mode   : 0x00
15274      *                          Pre-test Mode : 0x40
15275      *                          RAM Test Mode : 0x80
15276      *           Bit 5       : unused
15277      *           Bit 4(RO)   : Done bit
15278      *           Bit 3-0(RO) : Status
15279      *                          Host Error    : 0x08
15280      *                          Int_RAM Error : 0x04
15281      *                          RISC Error    : 0x02
15282      *                          SCSI Error    : 0x01
15283      *                          No Error      : 0x00
15284      *
15285      * Note: RAM BIST code should be put right here, before loading the
15286      * microcode and after saving the RISC memory BIOS region.
15287      */
15288
15289     /*
15290      * LRAM Pre-test
15291      *
15292      * Write PRE_TEST_MODE (0x40) to register and wait for 10 milliseconds.
15293      * If Done bit not set or low nibble not PRE_TEST_VALUE (0x05), return
15294      * an error. Reset to NORMAL_MODE (0x00) and do again. If cannot reset
15295      * to NORMAL_MODE, return an error too.
15296      */
15297     for (i = 0; i < 2; i++)
15298     {
15299         AdvWriteByteRegister(iop_base, IOPB_RAM_BIST, PRE_TEST_MODE);
15300         DvcSleepMilliSecond(10);  /* Wait for 10ms before reading back. */
15301         byte = AdvReadByteRegister(iop_base, IOPB_RAM_BIST);
15302         if ((byte & RAM_TEST_DONE) == 0 || (byte & 0x0F) != PRE_TEST_VALUE)
15303         {
15304             asc_dvc->err_code |= ASC_IERR_BIST_PRE_TEST;
15305             return ADV_ERROR;
15306         }
15307
15308         AdvWriteByteRegister(iop_base, IOPB_RAM_BIST, NORMAL_MODE);
15309         DvcSleepMilliSecond(10);  /* Wait for 10ms before reading back. */
15310         if (AdvReadByteRegister(iop_base, IOPB_RAM_BIST)
15311             != NORMAL_VALUE)
15312         {
15313             asc_dvc->err_code |= ASC_IERR_BIST_PRE_TEST;
15314             return ADV_ERROR;
15315         }
15316     }
15317
15318     /*
15319      * LRAM Test - It takes about 1.5 ms to run through the test.
15320      *
15321      * Write RAM_TEST_MODE (0x80) to register and wait for 10 milliseconds.
15322      * If Done bit not set or Status not 0, save register byte, set the
15323      * err_code, and return an error.
15324      */
15325     AdvWriteByteRegister(iop_base, IOPB_RAM_BIST, RAM_TEST_MODE);
15326     DvcSleepMilliSecond(10);  /* Wait for 10ms before checking status. */
15327
15328     byte = AdvReadByteRegister(iop_base, IOPB_RAM_BIST);
15329     if ((byte & RAM_TEST_DONE) == 0 || (byte & RAM_TEST_STATUS) != 0)
15330     {
15331         /* Get here if Done bit not set or Status not 0. */
15332         asc_dvc->bist_err_code = byte;  /* for BIOS display message */
15333         asc_dvc->err_code |= ASC_IERR_BIST_RAM_TEST;
15334         return ADV_ERROR;
15335     }
15336
15337     /* We need to reset back to normal mode after LRAM test passes. */
15338     AdvWriteByteRegister(iop_base, IOPB_RAM_BIST, NORMAL_MODE);
15339
15340     /*
15341      * Load the Microcode
15342      *
15343      * Write the microcode image to RISC memory starting at address 0.
15344      *
15345      */
15346     AdvWriteWordRegister(iop_base, IOPW_RAM_ADDR, 0);
15347
15348     /* Assume the following compressed format of the microcode buffer:
15349      *
15350      *  254 word (508 byte) table indexed by byte code followed
15351      *  by the following byte codes:
15352      *
15353      *    1-Byte Code:
15354      *      00: Emit word 0 in table.
15355      *      01: Emit word 1 in table.
15356      *      .
15357      *      FD: Emit word 253 in table.
15358      *
15359      *    Multi-Byte Code:
15360      *      FE WW WW: (3 byte code) Word to emit is the next word WW WW.
15361      *      FF BB WW WW: (4 byte code) Emit BB count times next word WW WW.
15362      */
15363     word = 0;
15364     for (i = 253 * 2; i < _adv_asc38C0800_size; i++)
15365     {
15366         if (_adv_asc38C0800_buf[i] == 0xff)
15367         {
15368             for (j = 0; j < _adv_asc38C0800_buf[i + 1]; j++)
15369             {
15370                 AdvWriteWordAutoIncLram(iop_base, (((ushort)
15371                     _adv_asc38C0800_buf[i + 3] << 8) |
15372                     _adv_asc38C0800_buf[i + 2]));
15373                 word++;
15374             }
15375             i += 3;
15376         } else if (_adv_asc38C0800_buf[i] == 0xfe)
15377         {
15378             AdvWriteWordAutoIncLram(iop_base, (((ushort)
15379                 _adv_asc38C0800_buf[i + 2] << 8) |
15380                 _adv_asc38C0800_buf[i + 1]));
15381             i += 2;
15382             word++;
15383         } else
15384         {
15385             AdvWriteWordAutoIncLram(iop_base, (((ushort)
15386                 _adv_asc38C0800_buf[(_adv_asc38C0800_buf[i] * 2) + 1] << 8) |
15387                 _adv_asc38C0800_buf[_adv_asc38C0800_buf[i] * 2]));
15388             word++;
15389         }
15390     }
15391
15392     /*
15393      * Set 'word' for later use to clear the rest of memory and save
15394      * the expanded mcode size.
15395      */
15396     word *= 2;
15397     adv_asc38C0800_expanded_size = word;
15398
15399     /*
15400      * Clear the rest of ASC-38C0800 Internal RAM (16KB).
15401      */
15402     for (; word < ADV_38C0800_MEMSIZE; word += 2)
15403     {
15404         AdvWriteWordAutoIncLram(iop_base, 0);
15405     }
15406
15407     /*
15408      * Verify the microcode checksum.
15409      */
15410     sum = 0;
15411     AdvWriteWordRegister(iop_base, IOPW_RAM_ADDR, 0);
15412
15413     for (word = 0; word < adv_asc38C0800_expanded_size; word += 2)
15414     {
15415         sum += AdvReadWordAutoIncLram(iop_base);
15416     }
15417     ASC_DBG2(1, "AdvInitAsc38C0800Driver: word %d, i %d\n", word, i);
15418
15419     ASC_DBG2(1,
15420         "AdvInitAsc38C0800Driver: sum 0x%lx, _adv_asc38C0800_chksum 0x%lx\n",
15421         (ulong) sum, (ulong) _adv_asc38C0800_chksum);
15422
15423     if (sum != _adv_asc38C0800_chksum)
15424     {
15425         asc_dvc->err_code |= ASC_IERR_MCODE_CHKSUM;
15426         return ADV_ERROR;
15427     }
15428
15429     /*
15430      * Restore the RISC memory BIOS region.
15431      */
15432     for (i = 0; i < ASC_MC_BIOSLEN/2; i++)
15433     {
15434         AdvWriteWordLram(iop_base, ASC_MC_BIOSMEM + (2 * i), bios_mem[i]);
15435     }
15436
15437     /*
15438      * Calculate and write the microcode code checksum to the microcode
15439      * code checksum location ASC_MC_CODE_CHK_SUM (0x2C).
15440      */
15441     AdvReadWordLram(iop_base, ASC_MC_CODE_BEGIN_ADDR, begin_addr);
15442     AdvReadWordLram(iop_base, ASC_MC_CODE_END_ADDR, end_addr);
15443     code_sum = 0;
15444     AdvWriteWordRegister(iop_base, IOPW_RAM_ADDR, begin_addr);
15445     for (word = begin_addr; word < end_addr; word += 2)
15446     {
15447         code_sum += AdvReadWordAutoIncLram(iop_base);
15448     }
15449     AdvWriteWordLram(iop_base, ASC_MC_CODE_CHK_SUM, code_sum);
15450
15451     /*
15452      * Read microcode version and date.
15453      */
15454     AdvReadWordLram(iop_base, ASC_MC_VERSION_DATE, asc_dvc->cfg->mcode_date);
15455     AdvReadWordLram(iop_base, ASC_MC_VERSION_NUM, asc_dvc->cfg->mcode_version);
15456
15457     /*
15458      * Set the chip type to indicate the ASC38C0800.
15459      */
15460     AdvWriteWordLram(iop_base, ASC_MC_CHIP_TYPE, ADV_CHIP_ASC38C0800);
15461
15462     /*
15463      * Write 1 to bit 14 'DIS_TERM_DRV' in the SCSI_CFG1 register.
15464      * When DIS_TERM_DRV set to 1, C_DET[3:0] will reflect current
15465      * cable detection and then we are able to read C_DET[3:0].
15466      *
15467      * Note: We will reset DIS_TERM_DRV to 0 in the 'Set SCSI_CFG1
15468      * Microcode Default Value' section below.
15469      */
15470     scsi_cfg1 = AdvReadWordRegister(iop_base, IOPW_SCSI_CFG1);
15471     AdvWriteWordRegister(iop_base, IOPW_SCSI_CFG1, scsi_cfg1 | DIS_TERM_DRV);
15472
15473     /*
15474      * If the PCI Configuration Command Register "Parity Error Response
15475      * Control" Bit was clear (0), then set the microcode variable
15476      * 'control_flag' CONTROL_FLAG_IGNORE_PERR flag to tell the microcode
15477      * to ignore DMA parity errors.
15478      */
15479     if (asc_dvc->cfg->control_flag & CONTROL_FLAG_IGNORE_PERR)
15480     {
15481         AdvReadWordLram(iop_base, ASC_MC_CONTROL_FLAG, word);
15482         word |= CONTROL_FLAG_IGNORE_PERR;
15483         AdvWriteWordLram(iop_base, ASC_MC_CONTROL_FLAG, word);
15484     }
15485
15486     /*
15487      * For ASC-38C0800, set FIFO_THRESH_80B [6:4] bits and START_CTL_TH [3:2]
15488      * bits for the default FIFO threshold.
15489      *
15490      * Note: ASC-38C0800 FIFO threshold has been changed to 256 bytes.
15491      *
15492      * For DMA Errata #4 set the BC_THRESH_ENB bit.
15493      */
15494     AdvWriteByteRegister(iop_base, IOPB_DMA_CFG0,
15495         BC_THRESH_ENB | FIFO_THRESH_80B | START_CTL_TH | READ_CMD_MRM);
15496
15497     /*
15498      * Microcode operating variables for WDTR, SDTR, and command tag
15499      * queuing will be set in AdvInquiryHandling() based on what a
15500      * device reports it is capable of in Inquiry byte 7.
15501      *
15502      * If SCSI Bus Resets have been disabled, then directly set
15503      * SDTR and WDTR from the EEPROM configuration. This will allow
15504      * the BIOS and warm boot to work without a SCSI bus hang on
15505      * the Inquiry caused by host and target mismatched DTR values.
15506      * Without the SCSI Bus Reset, before an Inquiry a device can't
15507      * be assumed to be in Asynchronous, Narrow mode.
15508      */
15509     if ((asc_dvc->bios_ctrl & BIOS_CTRL_RESET_SCSI_BUS) == 0)
15510     {
15511         AdvWriteWordLram(iop_base, ASC_MC_WDTR_ABLE, asc_dvc->wdtr_able);
15512         AdvWriteWordLram(iop_base, ASC_MC_SDTR_ABLE, asc_dvc->sdtr_able);
15513     }
15514
15515     /*
15516      * Set microcode operating variables for DISC and SDTR_SPEED1,
15517      * SDTR_SPEED2, SDTR_SPEED3, and SDTR_SPEED4 based on the EEPROM
15518      * configuration values.
15519      *
15520      * The SDTR per TID bitmask overrides the SDTR_SPEED1, SDTR_SPEED2,
15521      * SDTR_SPEED3, and SDTR_SPEED4 values so it is safe to set them
15522      * without determining here whether the device supports SDTR.
15523      */
15524     AdvWriteWordLram(iop_base, ASC_MC_DISC_ENABLE, asc_dvc->cfg->disc_enable);
15525     AdvWriteWordLram(iop_base, ASC_MC_SDTR_SPEED1, asc_dvc->sdtr_speed1);
15526     AdvWriteWordLram(iop_base, ASC_MC_SDTR_SPEED2, asc_dvc->sdtr_speed2);
15527     AdvWriteWordLram(iop_base, ASC_MC_SDTR_SPEED3, asc_dvc->sdtr_speed3);
15528     AdvWriteWordLram(iop_base, ASC_MC_SDTR_SPEED4, asc_dvc->sdtr_speed4);
15529
15530     /*
15531      * Set SCSI_CFG0 Microcode Default Value.
15532      *
15533      * The microcode will set the SCSI_CFG0 register using this value
15534      * after it is started below.
15535      */
15536     AdvWriteWordLram(iop_base, ASC_MC_DEFAULT_SCSI_CFG0,
15537         PARITY_EN | QUEUE_128 | SEL_TMO_LONG | OUR_ID_EN |
15538         asc_dvc->chip_scsi_id);
15539
15540     /*
15541      * Determine SCSI_CFG1 Microcode Default Value.
15542      *
15543      * The microcode will set the SCSI_CFG1 register using this value
15544      * after it is started below.
15545      */
15546
15547     /* Read current SCSI_CFG1 Register value. */
15548     scsi_cfg1 = AdvReadWordRegister(iop_base, IOPW_SCSI_CFG1);
15549
15550     /*
15551      * If the internal narrow cable is reversed all of the SCSI_CTRL
15552      * register signals will be set. Check for and return an error if
15553      * this condition is found.
15554      */
15555     if ((AdvReadWordRegister(iop_base, IOPW_SCSI_CTRL) & 0x3F07) == 0x3F07)
15556     {
15557         asc_dvc->err_code |= ASC_IERR_REVERSED_CABLE;
15558         return ADV_ERROR;
15559     }
15560
15561     /*
15562      * All kind of combinations of devices attached to one of four connectors
15563      * are acceptable except HVD device attached. For example, LVD device can
15564      * be attached to SE connector while SE device attached to LVD connector.
15565      * If LVD device attached to SE connector, it only runs up to Ultra speed.
15566      *
15567      * If an HVD device is attached to one of LVD connectors, return an error.
15568      * However, there is no way to detect HVD device attached to SE connectors.
15569      */
15570     if (scsi_cfg1 & HVD)
15571     {
15572         asc_dvc->err_code |= ASC_IERR_HVD_DEVICE;
15573         return ADV_ERROR;
15574     }
15575
15576     /*
15577      * If either SE or LVD automatic termination control is enabled, then
15578      * set the termination value based on a table listed in a_condor.h.
15579      *
15580      * If manual termination was specified with an EEPROM setting then
15581      * 'termination' was set-up in AdvInitFrom38C0800EEPROM() and is ready to
15582      * be 'ored' into SCSI_CFG1.
15583      */
15584     if ((asc_dvc->cfg->termination & TERM_SE) == 0)
15585     {
15586         /* SE automatic termination control is enabled. */
15587         switch(scsi_cfg1 & C_DET_SE)
15588         {
15589             /* TERM_SE_HI: on, TERM_SE_LO: on */
15590             case 0x1: case 0x2: case 0x3:
15591                 asc_dvc->cfg->termination |= TERM_SE;
15592                 break;
15593
15594             /* TERM_SE_HI: on, TERM_SE_LO: off */
15595             case 0x0:
15596                 asc_dvc->cfg->termination |= TERM_SE_HI;
15597                 break;
15598         }
15599     }
15600
15601     if ((asc_dvc->cfg->termination & TERM_LVD) == 0)
15602     {
15603         /* LVD automatic termination control is enabled. */
15604         switch(scsi_cfg1 & C_DET_LVD)
15605         {
15606             /* TERM_LVD_HI: on, TERM_LVD_LO: on */
15607             case 0x4: case 0x8: case 0xC:
15608                 asc_dvc->cfg->termination |= TERM_LVD;
15609                 break;
15610
15611             /* TERM_LVD_HI: off, TERM_LVD_LO: off */
15612             case 0x0:
15613                 break;
15614         }
15615     }
15616
15617     /*
15618      * Clear any set TERM_SE and TERM_LVD bits.
15619      */
15620     scsi_cfg1 &= (~TERM_SE & ~TERM_LVD);
15621
15622     /*
15623      * Invert the TERM_SE and TERM_LVD bits and then set 'scsi_cfg1'.
15624      */
15625     scsi_cfg1 |= (~asc_dvc->cfg->termination & 0xF0);
15626
15627     /*
15628      * Clear BIG_ENDIAN, DIS_TERM_DRV, Terminator Polarity and HVD/LVD/SE bits
15629      * and set possibly modified termination control bits in the Microcode
15630      * SCSI_CFG1 Register Value.
15631      */
15632     scsi_cfg1 &= (~BIG_ENDIAN & ~DIS_TERM_DRV & ~TERM_POL & ~HVD_LVD_SE);
15633
15634     /*
15635      * Set SCSI_CFG1 Microcode Default Value
15636      *
15637      * Set possibly modified termination control and reset DIS_TERM_DRV
15638      * bits in the Microcode SCSI_CFG1 Register Value.
15639      *
15640      * The microcode will set the SCSI_CFG1 register using this value
15641      * after it is started below.
15642      */
15643     AdvWriteWordLram(iop_base, ASC_MC_DEFAULT_SCSI_CFG1, scsi_cfg1);
15644
15645     /*
15646      * Set MEM_CFG Microcode Default Value
15647      *
15648      * The microcode will set the MEM_CFG register using this value
15649      * after it is started below.
15650      *
15651      * MEM_CFG may be accessed as a word or byte, but only bits 0-7
15652      * are defined.
15653      *
15654      * ASC-38C0800 has 16KB internal memory.
15655      */
15656     AdvWriteWordLram(iop_base, ASC_MC_DEFAULT_MEM_CFG,
15657         BIOS_EN | RAM_SZ_16KB);
15658
15659     /*
15660      * Set SEL_MASK Microcode Default Value
15661      *
15662      * The microcode will set the SEL_MASK register using this value
15663      * after it is started below.
15664      */
15665     AdvWriteWordLram(iop_base, ASC_MC_DEFAULT_SEL_MASK,
15666         ADV_TID_TO_TIDMASK(asc_dvc->chip_scsi_id));
15667
15668     /*
15669      * Build the carrier freelist.
15670      *
15671      * Driver must have already allocated memory and set 'carrier_buf'.
15672      */
15673     ASC_ASSERT(asc_dvc->carrier_buf != NULL);
15674
15675     carrp = (ADV_CARR_T *) ADV_16BALIGN(asc_dvc->carrier_buf);
15676     asc_dvc->carr_freelist = NULL;
15677     if (carrp == (ADV_CARR_T *) asc_dvc->carrier_buf)
15678     {
15679         buf_size = ADV_CARRIER_BUFSIZE;
15680     } else
15681     {
15682         buf_size = ADV_CARRIER_BUFSIZE - sizeof(ADV_CARR_T);
15683     }
15684
15685     do {
15686         /*
15687          * Get physical address for the carrier 'carrp'.
15688          */
15689         contig_len = sizeof(ADV_CARR_T);
15690         carr_paddr = cpu_to_le32(DvcGetPhyAddr(asc_dvc, NULL, (uchar *) carrp,
15691             (ADV_SDCNT *) &contig_len, ADV_IS_CARRIER_FLAG));
15692
15693         buf_size -= sizeof(ADV_CARR_T);
15694
15695         /*
15696          * If the current carrier is not physically contiguous, then
15697          * maybe there was a page crossing. Try the next carrier aligned
15698          * start address.
15699          */
15700         if (contig_len < sizeof(ADV_CARR_T))
15701         {
15702             carrp++;
15703             continue;
15704         }
15705
15706         carrp->carr_pa = carr_paddr;
15707         carrp->carr_va = cpu_to_le32(ADV_VADDR_TO_U32(carrp));
15708
15709         /*
15710          * Insert the carrier at the beginning of the freelist.
15711          */
15712         carrp->next_vpa = cpu_to_le32(ADV_VADDR_TO_U32(asc_dvc->carr_freelist));
15713         asc_dvc->carr_freelist = carrp;
15714
15715         carrp++;
15716     }
15717     while (buf_size > 0);
15718
15719     /*
15720      * Set-up the Host->RISC Initiator Command Queue (ICQ).
15721      */
15722
15723     if ((asc_dvc->icq_sp = asc_dvc->carr_freelist) == NULL)
15724     {
15725         asc_dvc->err_code |= ASC_IERR_NO_CARRIER;
15726         return ADV_ERROR;
15727     }
15728     asc_dvc->carr_freelist = (ADV_CARR_T *)
15729         ADV_U32_TO_VADDR(le32_to_cpu(asc_dvc->icq_sp->next_vpa));
15730
15731     /*
15732      * The first command issued will be placed in the stopper carrier.
15733      */
15734     asc_dvc->icq_sp->next_vpa = cpu_to_le32(ASC_CQ_STOPPER);
15735
15736     /*
15737      * Set RISC ICQ physical address start value.
15738      * carr_pa is LE, must be native before write
15739      */
15740     AdvWriteDWordLramNoSwap(iop_base, ASC_MC_ICQ, asc_dvc->icq_sp->carr_pa);
15741
15742     /*
15743      * Set-up the RISC->Host Initiator Response Queue (IRQ).
15744      */
15745     if ((asc_dvc->irq_sp = asc_dvc->carr_freelist) == NULL)
15746     {
15747         asc_dvc->err_code |= ASC_IERR_NO_CARRIER;
15748         return ADV_ERROR;
15749     }
15750     asc_dvc->carr_freelist = (ADV_CARR_T *)
15751         ADV_U32_TO_VADDR(le32_to_cpu(asc_dvc->irq_sp->next_vpa));
15752
15753     /*
15754      * The first command completed by the RISC will be placed in
15755      * the stopper.
15756      *
15757      * Note: Set 'next_vpa' to ASC_CQ_STOPPER. When the request is
15758      * completed the RISC will set the ASC_RQ_STOPPER bit.
15759      */
15760     asc_dvc->irq_sp->next_vpa = cpu_to_le32(ASC_CQ_STOPPER);
15761
15762     /*
15763      * Set RISC IRQ physical address start value.
15764      *
15765      * carr_pa is LE, must be native before write *
15766      */
15767     AdvWriteDWordLramNoSwap(iop_base, ASC_MC_IRQ, asc_dvc->irq_sp->carr_pa);
15768     asc_dvc->carr_pending_cnt = 0;
15769
15770     AdvWriteByteRegister(iop_base, IOPB_INTR_ENABLES,
15771         (ADV_INTR_ENABLE_HOST_INTR | ADV_INTR_ENABLE_GLOBAL_INTR));
15772
15773     AdvReadWordLram(iop_base, ASC_MC_CODE_BEGIN_ADDR, word);
15774     AdvWriteWordRegister(iop_base, IOPW_PC, word);
15775
15776     /* finally, finally, gentlemen, start your engine */
15777     AdvWriteWordRegister(iop_base, IOPW_RISC_CSR, ADV_RISC_CSR_RUN);
15778
15779     /*
15780      * Reset the SCSI Bus if the EEPROM indicates that SCSI Bus
15781      * Resets should be performed. The RISC has to be running
15782      * to issue a SCSI Bus Reset.
15783      */
15784     if (asc_dvc->bios_ctrl & BIOS_CTRL_RESET_SCSI_BUS)
15785     {
15786         /*
15787          * If the BIOS Signature is present in memory, restore the
15788          * BIOS Handshake Configuration Table and do not perform
15789          * a SCSI Bus Reset.
15790          */
15791         if (bios_mem[(ASC_MC_BIOS_SIGNATURE - ASC_MC_BIOSMEM)/2] == 0x55AA)
15792         {
15793             /*
15794              * Restore per TID negotiated values.
15795              */
15796             AdvWriteWordLram(iop_base, ASC_MC_WDTR_ABLE, wdtr_able);
15797             AdvWriteWordLram(iop_base, ASC_MC_SDTR_ABLE, sdtr_able);
15798             AdvWriteWordLram(iop_base, ASC_MC_TAGQNG_ABLE, tagqng_able);
15799             for (tid = 0; tid <= ADV_MAX_TID; tid++)
15800             {
15801                 AdvWriteByteLram(iop_base, ASC_MC_NUMBER_OF_MAX_CMD + tid,
15802                     max_cmd[tid]);
15803             }
15804         } else
15805         {
15806             if (AdvResetSB(asc_dvc) != ADV_TRUE)
15807             {
15808                 warn_code = ASC_WARN_BUSRESET_ERROR;
15809             }
15810         }
15811     }
15812
15813     return warn_code;
15814 }
15815
15816 /*
15817  * Initialize the ASC-38C1600.
15818  *
15819  * On failure set the ASC_DVC_VAR field 'err_code' and return ADV_ERROR.
15820  *
15821  * For a non-fatal error return a warning code. If there are no warnings
15822  * then 0 is returned.
15823  *
15824  * Needed after initialization for error recovery.
15825  */
15826 STATIC int
15827 AdvInitAsc38C1600Driver(ADV_DVC_VAR *asc_dvc)
15828 {
15829     AdvPortAddr iop_base;
15830     ushort      warn_code;
15831     ADV_DCNT    sum;
15832     int         begin_addr;
15833     int         end_addr;
15834     ushort      code_sum;
15835     long        word;
15836     int         j;
15837     int         adv_asc38C1600_expanded_size;
15838     ADV_CARR_T  *carrp;
15839     ADV_DCNT    contig_len;
15840     ADV_SDCNT   buf_size;
15841     ADV_PADDR   carr_paddr;
15842     int         i;
15843     ushort      scsi_cfg1;
15844     uchar       byte;
15845     uchar       tid;
15846     ushort      bios_mem[ASC_MC_BIOSLEN/2]; /* BIOS RISC Memory 0x40-0x8F. */
15847     ushort      wdtr_able, sdtr_able, ppr_able, tagqng_able;
15848     uchar       max_cmd[ASC_MAX_TID + 1];
15849
15850     /* If there is already an error, don't continue. */
15851     if (asc_dvc->err_code != 0)
15852     {
15853         return ADV_ERROR;
15854     }
15855
15856     /*
15857      * The caller must set 'chip_type' to ADV_CHIP_ASC38C1600.
15858      */
15859     if (asc_dvc->chip_type != ADV_CHIP_ASC38C1600)
15860     {
15861         asc_dvc->err_code = ASC_IERR_BAD_CHIPTYPE;
15862         return ADV_ERROR;
15863     }
15864
15865     warn_code = 0;
15866     iop_base = asc_dvc->iop_base;
15867
15868     /*
15869      * Save the RISC memory BIOS region before writing the microcode.
15870      * The BIOS may already be loaded and using its RISC LRAM region
15871      * so its region must be saved and restored.
15872      *
15873      * Note: This code makes the assumption, which is currently true,
15874      * that a chip reset does not clear RISC LRAM.
15875      */
15876     for (i = 0; i < ASC_MC_BIOSLEN/2; i++)
15877     {
15878         AdvReadWordLram(iop_base, ASC_MC_BIOSMEM + (2 * i), bios_mem[i]);
15879     }
15880
15881     /*
15882      * Save current per TID negotiated values.
15883      */
15884     AdvReadWordLram(iop_base, ASC_MC_WDTR_ABLE, wdtr_able);
15885     AdvReadWordLram(iop_base, ASC_MC_SDTR_ABLE, sdtr_able);
15886     AdvReadWordLram(iop_base, ASC_MC_PPR_ABLE, ppr_able);
15887     AdvReadWordLram(iop_base, ASC_MC_TAGQNG_ABLE, tagqng_able);
15888     for (tid = 0; tid <= ASC_MAX_TID; tid++)
15889     {
15890         AdvReadByteLram(iop_base, ASC_MC_NUMBER_OF_MAX_CMD + tid,
15891             max_cmd[tid]);
15892     }
15893
15894     /*
15895      * RAM BIST (Built-In Self Test)
15896      *
15897      * Address : I/O base + offset 0x38h register (byte).
15898      * Function: Bit 7-6(RW) : RAM mode
15899      *                          Normal Mode   : 0x00
15900      *                          Pre-test Mode : 0x40
15901      *                          RAM Test Mode : 0x80
15902      *           Bit 5       : unused
15903      *           Bit 4(RO)   : Done bit
15904      *           Bit 3-0(RO) : Status
15905      *                          Host Error    : 0x08
15906      *                          Int_RAM Error : 0x04
15907      *                          RISC Error    : 0x02
15908      *                          SCSI Error    : 0x01
15909      *                          No Error      : 0x00
15910      *
15911      * Note: RAM BIST code should be put right here, before loading the
15912      * microcode and after saving the RISC memory BIOS region.
15913      */
15914
15915     /*
15916      * LRAM Pre-test
15917      *
15918      * Write PRE_TEST_MODE (0x40) to register and wait for 10 milliseconds.
15919      * If Done bit not set or low nibble not PRE_TEST_VALUE (0x05), return
15920      * an error. Reset to NORMAL_MODE (0x00) and do again. If cannot reset
15921      * to NORMAL_MODE, return an error too.
15922      */
15923     for (i = 0; i < 2; i++)
15924     {
15925         AdvWriteByteRegister(iop_base, IOPB_RAM_BIST, PRE_TEST_MODE);
15926         DvcSleepMilliSecond(10);  /* Wait for 10ms before reading back. */
15927         byte = AdvReadByteRegister(iop_base, IOPB_RAM_BIST);
15928         if ((byte & RAM_TEST_DONE) == 0 || (byte & 0x0F) != PRE_TEST_VALUE)
15929         {
15930             asc_dvc->err_code |= ASC_IERR_BIST_PRE_TEST;
15931             return ADV_ERROR;
15932         }
15933
15934         AdvWriteByteRegister(iop_base, IOPB_RAM_BIST, NORMAL_MODE);
15935         DvcSleepMilliSecond(10);  /* Wait for 10ms before reading back. */
15936         if (AdvReadByteRegister(iop_base, IOPB_RAM_BIST)
15937             != NORMAL_VALUE)
15938         {
15939             asc_dvc->err_code |= ASC_IERR_BIST_PRE_TEST;
15940             return ADV_ERROR;
15941         }
15942     }
15943
15944     /*
15945      * LRAM Test - It takes about 1.5 ms to run through the test.
15946      *
15947      * Write RAM_TEST_MODE (0x80) to register and wait for 10 milliseconds.
15948      * If Done bit not set or Status not 0, save register byte, set the
15949      * err_code, and return an error.
15950      */
15951     AdvWriteByteRegister(iop_base, IOPB_RAM_BIST, RAM_TEST_MODE);
15952     DvcSleepMilliSecond(10);  /* Wait for 10ms before checking status. */
15953
15954     byte = AdvReadByteRegister(iop_base, IOPB_RAM_BIST);
15955     if ((byte & RAM_TEST_DONE) == 0 || (byte & RAM_TEST_STATUS) != 0)
15956     {
15957         /* Get here if Done bit not set or Status not 0. */
15958         asc_dvc->bist_err_code = byte;  /* for BIOS display message */
15959         asc_dvc->err_code |= ASC_IERR_BIST_RAM_TEST;
15960         return ADV_ERROR;
15961     }
15962
15963     /* We need to reset back to normal mode after LRAM test passes. */
15964     AdvWriteByteRegister(iop_base, IOPB_RAM_BIST, NORMAL_MODE);
15965
15966     /*
15967      * Load the Microcode
15968      *
15969      * Write the microcode image to RISC memory starting at address 0.
15970      *
15971      */
15972     AdvWriteWordRegister(iop_base, IOPW_RAM_ADDR, 0);
15973
15974     /*
15975      * Assume the following compressed format of the microcode buffer:
15976      *
15977      *  254 word (508 byte) table indexed by byte code followed
15978      *  by the following byte codes:
15979      *
15980      *    1-Byte Code:
15981      *      00: Emit word 0 in table.
15982      *      01: Emit word 1 in table.
15983      *      .
15984      *      FD: Emit word 253 in table.
15985      *
15986      *    Multi-Byte Code:
15987      *      FE WW WW: (3 byte code) Word to emit is the next word WW WW.
15988      *      FF BB WW WW: (4 byte code) Emit BB count times next word WW WW.
15989      */
15990     word = 0;
15991     for (i = 253 * 2; i < _adv_asc38C1600_size; i++)
15992     {
15993         if (_adv_asc38C1600_buf[i] == 0xff)
15994         {
15995             for (j = 0; j < _adv_asc38C1600_buf[i + 1]; j++)
15996             {
15997                 AdvWriteWordAutoIncLram(iop_base, (((ushort)
15998                      _adv_asc38C1600_buf[i + 3] << 8) |
15999                      _adv_asc38C1600_buf[i + 2]));
16000                 word++;
16001             }
16002            i += 3;
16003         } else if (_adv_asc38C1600_buf[i] == 0xfe)
16004         {
16005                 AdvWriteWordAutoIncLram(iop_base, (((ushort)
16006                      _adv_asc38C1600_buf[i + 2] << 8) |
16007                      _adv_asc38C1600_buf[i + 1]));
16008             i += 2;
16009             word++;
16010         } else
16011         {
16012             AdvWriteWordAutoIncLram(iop_base, (((ushort)
16013                  _adv_asc38C1600_buf[(_adv_asc38C1600_buf[i] * 2) + 1] << 8) |
16014                  _adv_asc38C1600_buf[_adv_asc38C1600_buf[i] * 2]));
16015             word++;
16016         }
16017     }
16018
16019     /*
16020      * Set 'word' for later use to clear the rest of memory and save
16021      * the expanded mcode size.
16022      */
16023     word *= 2;
16024     adv_asc38C1600_expanded_size = word;
16025
16026     /*
16027      * Clear the rest of ASC-38C1600 Internal RAM (32KB).
16028      */
16029     for (; word < ADV_38C1600_MEMSIZE; word += 2)
16030     {
16031         AdvWriteWordAutoIncLram(iop_base, 0);
16032     }
16033
16034     /*
16035      * Verify the microcode checksum.
16036      */
16037     sum = 0;
16038     AdvWriteWordRegister(iop_base, IOPW_RAM_ADDR, 0);
16039
16040     for (word = 0; word < adv_asc38C1600_expanded_size; word += 2)
16041     {
16042         sum += AdvReadWordAutoIncLram(iop_base);
16043     }
16044
16045     if (sum != _adv_asc38C1600_chksum)
16046     {
16047         asc_dvc->err_code |= ASC_IERR_MCODE_CHKSUM;
16048         return ADV_ERROR;
16049     }
16050
16051     /*
16052      * Restore the RISC memory BIOS region.
16053      */
16054     for (i = 0; i < ASC_MC_BIOSLEN/2; i++)
16055     {
16056         AdvWriteWordLram(iop_base, ASC_MC_BIOSMEM + (2 * i), bios_mem[i]);
16057     }
16058
16059     /*
16060      * Calculate and write the microcode code checksum to the microcode
16061      * code checksum location ASC_MC_CODE_CHK_SUM (0x2C).
16062      */
16063     AdvReadWordLram(iop_base, ASC_MC_CODE_BEGIN_ADDR, begin_addr);
16064     AdvReadWordLram(iop_base, ASC_MC_CODE_END_ADDR, end_addr);
16065     code_sum = 0;
16066     AdvWriteWordRegister(iop_base, IOPW_RAM_ADDR, begin_addr);
16067     for (word = begin_addr; word < end_addr; word += 2)
16068     {
16069         code_sum += AdvReadWordAutoIncLram(iop_base);
16070     }
16071     AdvWriteWordLram(iop_base, ASC_MC_CODE_CHK_SUM, code_sum);
16072
16073     /*
16074      * Read microcode version and date.
16075      */
16076     AdvReadWordLram(iop_base, ASC_MC_VERSION_DATE, asc_dvc->cfg->mcode_date);
16077     AdvReadWordLram(iop_base, ASC_MC_VERSION_NUM, asc_dvc->cfg->mcode_version);
16078
16079     /*
16080      * Set the chip type to indicate the ASC38C1600.
16081      */
16082     AdvWriteWordLram(iop_base, ASC_MC_CHIP_TYPE, ADV_CHIP_ASC38C1600);
16083
16084     /*
16085      * Write 1 to bit 14 'DIS_TERM_DRV' in the SCSI_CFG1 register.
16086      * When DIS_TERM_DRV set to 1, C_DET[3:0] will reflect current
16087      * cable detection and then we are able to read C_DET[3:0].
16088      *
16089      * Note: We will reset DIS_TERM_DRV to 0 in the 'Set SCSI_CFG1
16090      * Microcode Default Value' section below.
16091      */
16092     scsi_cfg1 = AdvReadWordRegister(iop_base, IOPW_SCSI_CFG1);
16093     AdvWriteWordRegister(iop_base, IOPW_SCSI_CFG1, scsi_cfg1 | DIS_TERM_DRV);
16094
16095     /*
16096      * If the PCI Configuration Command Register "Parity Error Response
16097      * Control" Bit was clear (0), then set the microcode variable
16098      * 'control_flag' CONTROL_FLAG_IGNORE_PERR flag to tell the microcode
16099      * to ignore DMA parity errors.
16100      */
16101     if (asc_dvc->cfg->control_flag & CONTROL_FLAG_IGNORE_PERR)
16102     {
16103         AdvReadWordLram(iop_base, ASC_MC_CONTROL_FLAG, word);
16104         word |= CONTROL_FLAG_IGNORE_PERR;
16105         AdvWriteWordLram(iop_base, ASC_MC_CONTROL_FLAG, word);
16106     }
16107
16108     /*
16109      * If the BIOS control flag AIPP (Asynchronous Information
16110      * Phase Protection) disable bit is not set, then set the firmware
16111      * 'control_flag' CONTROL_FLAG_ENABLE_AIPP bit to enable
16112      * AIPP checking and encoding.
16113      */
16114     if ((asc_dvc->bios_ctrl & BIOS_CTRL_AIPP_DIS) == 0)
16115     {
16116         AdvReadWordLram(iop_base, ASC_MC_CONTROL_FLAG, word);
16117         word |= CONTROL_FLAG_ENABLE_AIPP;
16118         AdvWriteWordLram(iop_base, ASC_MC_CONTROL_FLAG, word);
16119     }
16120
16121     /*
16122      * For ASC-38C1600 use DMA_CFG0 default values: FIFO_THRESH_80B [6:4],
16123      * and START_CTL_TH [3:2].
16124      */
16125     AdvWriteByteRegister(iop_base, IOPB_DMA_CFG0,
16126         FIFO_THRESH_80B | START_CTL_TH | READ_CMD_MRM);
16127
16128     /*
16129      * Microcode operating variables for WDTR, SDTR, and command tag
16130      * queuing will be set in AdvInquiryHandling() based on what a
16131      * device reports it is capable of in Inquiry byte 7.
16132      *
16133      * If SCSI Bus Resets have been disabled, then directly set
16134      * SDTR and WDTR from the EEPROM configuration. This will allow
16135      * the BIOS and warm boot to work without a SCSI bus hang on
16136      * the Inquiry caused by host and target mismatched DTR values.
16137      * Without the SCSI Bus Reset, before an Inquiry a device can't
16138      * be assumed to be in Asynchronous, Narrow mode.
16139      */
16140     if ((asc_dvc->bios_ctrl & BIOS_CTRL_RESET_SCSI_BUS) == 0)
16141     {
16142         AdvWriteWordLram(iop_base, ASC_MC_WDTR_ABLE, asc_dvc->wdtr_able);
16143         AdvWriteWordLram(iop_base, ASC_MC_SDTR_ABLE, asc_dvc->sdtr_able);
16144     }
16145
16146     /*
16147      * Set microcode operating variables for DISC and SDTR_SPEED1,
16148      * SDTR_SPEED2, SDTR_SPEED3, and SDTR_SPEED4 based on the EEPROM
16149      * configuration values.
16150      *
16151      * The SDTR per TID bitmask overrides the SDTR_SPEED1, SDTR_SPEED2,
16152      * SDTR_SPEED3, and SDTR_SPEED4 values so it is safe to set them
16153      * without determining here whether the device supports SDTR.
16154      */
16155     AdvWriteWordLram(iop_base, ASC_MC_DISC_ENABLE, asc_dvc->cfg->disc_enable);
16156     AdvWriteWordLram(iop_base, ASC_MC_SDTR_SPEED1, asc_dvc->sdtr_speed1);
16157     AdvWriteWordLram(iop_base, ASC_MC_SDTR_SPEED2, asc_dvc->sdtr_speed2);
16158     AdvWriteWordLram(iop_base, ASC_MC_SDTR_SPEED3, asc_dvc->sdtr_speed3);
16159     AdvWriteWordLram(iop_base, ASC_MC_SDTR_SPEED4, asc_dvc->sdtr_speed4);
16160
16161     /*
16162      * Set SCSI_CFG0 Microcode Default Value.
16163      *
16164      * The microcode will set the SCSI_CFG0 register using this value
16165      * after it is started below.
16166      */
16167     AdvWriteWordLram(iop_base, ASC_MC_DEFAULT_SCSI_CFG0,
16168         PARITY_EN | QUEUE_128 | SEL_TMO_LONG | OUR_ID_EN |
16169         asc_dvc->chip_scsi_id);
16170
16171     /*
16172      * Calculate SCSI_CFG1 Microcode Default Value.
16173      *
16174      * The microcode will set the SCSI_CFG1 register using this value
16175      * after it is started below.
16176      *
16177      * Each ASC-38C1600 function has only two cable detect bits.
16178      * The bus mode override bits are in IOPB_SOFT_OVER_WR.
16179      */
16180     scsi_cfg1 = AdvReadWordRegister(iop_base, IOPW_SCSI_CFG1);
16181
16182     /*
16183      * If the cable is reversed all of the SCSI_CTRL register signals
16184      * will be set. Check for and return an error if this condition is
16185      * found.
16186      */
16187     if ((AdvReadWordRegister(iop_base, IOPW_SCSI_CTRL) & 0x3F07) == 0x3F07)
16188     {
16189         asc_dvc->err_code |= ASC_IERR_REVERSED_CABLE;
16190         return ADV_ERROR;
16191     }
16192
16193     /*
16194      * Each ASC-38C1600 function has two connectors. Only an HVD device
16195      * can not be connected to either connector. An LVD device or SE device
16196      * may be connected to either connecor. If an SE device is connected,
16197      * then at most Ultra speed (20 Mhz) can be used on both connectors.
16198      *
16199      * If an HVD device is attached, return an error.
16200      */
16201     if (scsi_cfg1 & HVD)
16202     {
16203         asc_dvc->err_code |= ASC_IERR_HVD_DEVICE;
16204         return ADV_ERROR;
16205     }
16206
16207     /*
16208      * Each function in the ASC-38C1600 uses only the SE cable detect and
16209      * termination because there are two connectors for each function. Each
16210      * function may use either LVD or SE mode. Corresponding the SE automatic
16211      * termination control EEPROM bits are used for each function. Each
16212      * function has its own EEPROM. If SE automatic control is enabled for
16213      * the function, then set the termination value based on a table listed
16214      * in a_condor.h.
16215      *
16216      * If manual termination is specified in the EEPROM for the function,
16217      * then 'termination' was set-up in AscInitFrom38C1600EEPROM() and is
16218      * ready to be 'ored' into SCSI_CFG1.
16219      */
16220     if ((asc_dvc->cfg->termination & TERM_SE) == 0)
16221     {
16222         /* SE automatic termination control is enabled. */
16223         switch(scsi_cfg1 & C_DET_SE)
16224         {
16225             /* TERM_SE_HI: on, TERM_SE_LO: on */
16226             case 0x1: case 0x2: case 0x3:
16227                 asc_dvc->cfg->termination |= TERM_SE;
16228                 break;
16229
16230             case 0x0:
16231                 if (ASC_PCI_ID2FUNC(asc_dvc->cfg->pci_slot_info) == 0)
16232                 {
16233                     /* Function 0 - TERM_SE_HI: off, TERM_SE_LO: off */
16234                 }
16235                 else
16236                 {
16237                     /* Function 1 - TERM_SE_HI: on, TERM_SE_LO: off */
16238                     asc_dvc->cfg->termination |= TERM_SE_HI;
16239                 }
16240                 break;
16241         }
16242     }
16243
16244     /*
16245      * Clear any set TERM_SE bits.
16246      */
16247     scsi_cfg1 &= ~TERM_SE;
16248
16249     /*
16250      * Invert the TERM_SE bits and then set 'scsi_cfg1'.
16251      */
16252     scsi_cfg1 |= (~asc_dvc->cfg->termination & TERM_SE);
16253
16254     /*
16255      * Clear Big Endian and Terminator Polarity bits and set possibly
16256      * modified termination control bits in the Microcode SCSI_CFG1
16257      * Register Value.
16258      *
16259      * Big Endian bit is not used even on big endian machines.
16260      */
16261     scsi_cfg1 &= (~BIG_ENDIAN & ~DIS_TERM_DRV & ~TERM_POL);
16262
16263     /*
16264      * Set SCSI_CFG1 Microcode Default Value
16265      *
16266      * Set possibly modified termination control bits in the Microcode
16267      * SCSI_CFG1 Register Value.
16268      *
16269      * The microcode will set the SCSI_CFG1 register using this value
16270      * after it is started below.
16271      */
16272     AdvWriteWordLram(iop_base, ASC_MC_DEFAULT_SCSI_CFG1, scsi_cfg1);
16273
16274     /*
16275      * Set MEM_CFG Microcode Default Value
16276      *
16277      * The microcode will set the MEM_CFG register using this value
16278      * after it is started below.
16279      *
16280      * MEM_CFG may be accessed as a word or byte, but only bits 0-7
16281      * are defined.
16282      *
16283      * ASC-38C1600 has 32KB internal memory.
16284      *
16285      * XXX - Since ASC38C1600 Rev.3 has a Local RAM failure issue, we come
16286      * out a special 16K Adv Library and Microcode version. After the issue
16287      * resolved, we should turn back to the 32K support. Both a_condor.h and
16288      * mcode.sas files also need to be updated.
16289      *
16290      * AdvWriteWordLram(iop_base, ASC_MC_DEFAULT_MEM_CFG,
16291      *  BIOS_EN | RAM_SZ_32KB);
16292      */
16293      AdvWriteWordLram(iop_base, ASC_MC_DEFAULT_MEM_CFG, BIOS_EN | RAM_SZ_16KB);
16294
16295     /*
16296      * Set SEL_MASK Microcode Default Value
16297      *
16298      * The microcode will set the SEL_MASK register using this value
16299      * after it is started below.
16300      */
16301     AdvWriteWordLram(iop_base, ASC_MC_DEFAULT_SEL_MASK,
16302         ADV_TID_TO_TIDMASK(asc_dvc->chip_scsi_id));
16303
16304     /*
16305      * Build the carrier freelist.
16306      *
16307      * Driver must have already allocated memory and set 'carrier_buf'.
16308      */
16309
16310     ASC_ASSERT(asc_dvc->carrier_buf != NULL);
16311
16312     carrp = (ADV_CARR_T *) ADV_16BALIGN(asc_dvc->carrier_buf);
16313     asc_dvc->carr_freelist = NULL;
16314     if (carrp == (ADV_CARR_T *) asc_dvc->carrier_buf)
16315     {
16316         buf_size = ADV_CARRIER_BUFSIZE;
16317     } else
16318     {
16319         buf_size = ADV_CARRIER_BUFSIZE - sizeof(ADV_CARR_T);
16320     }
16321
16322     do {
16323         /*
16324          * Get physical address for the carrier 'carrp'.
16325          */
16326         contig_len = sizeof(ADV_CARR_T);
16327         carr_paddr = cpu_to_le32(DvcGetPhyAddr(asc_dvc, NULL, (uchar *) carrp,
16328             (ADV_SDCNT *) &contig_len, ADV_IS_CARRIER_FLAG));
16329
16330         buf_size -= sizeof(ADV_CARR_T);
16331
16332         /*
16333          * If the current carrier is not physically contiguous, then
16334          * maybe there was a page crossing. Try the next carrier aligned
16335          * start address.
16336          */
16337         if (contig_len < sizeof(ADV_CARR_T))
16338         {
16339             carrp++;
16340             continue;
16341         }
16342
16343         carrp->carr_pa = carr_paddr;
16344         carrp->carr_va = cpu_to_le32(ADV_VADDR_TO_U32(carrp));
16345
16346         /*
16347          * Insert the carrier at the beginning of the freelist.
16348          */
16349         carrp->next_vpa = cpu_to_le32(ADV_VADDR_TO_U32(asc_dvc->carr_freelist));
16350         asc_dvc->carr_freelist = carrp;
16351
16352         carrp++;
16353     }
16354     while (buf_size > 0);
16355
16356     /*
16357      * Set-up the Host->RISC Initiator Command Queue (ICQ).
16358      */
16359     if ((asc_dvc->icq_sp = asc_dvc->carr_freelist) == NULL)
16360     {
16361         asc_dvc->err_code |= ASC_IERR_NO_CARRIER;
16362         return ADV_ERROR;
16363     }
16364     asc_dvc->carr_freelist = (ADV_CARR_T *)
16365         ADV_U32_TO_VADDR(le32_to_cpu(asc_dvc->icq_sp->next_vpa));
16366
16367     /*
16368      * The first command issued will be placed in the stopper carrier.
16369      */
16370     asc_dvc->icq_sp->next_vpa = cpu_to_le32(ASC_CQ_STOPPER);
16371
16372     /*
16373      * Set RISC ICQ physical address start value. Initialize the
16374      * COMMA register to the same value otherwise the RISC will
16375      * prematurely detect a command is available.
16376      */
16377     AdvWriteDWordLramNoSwap(iop_base, ASC_MC_ICQ, asc_dvc->icq_sp->carr_pa);
16378     AdvWriteDWordRegister(iop_base, IOPDW_COMMA,
16379         le32_to_cpu(asc_dvc->icq_sp->carr_pa));
16380
16381     /*
16382      * Set-up the RISC->Host Initiator Response Queue (IRQ).
16383      */
16384     if ((asc_dvc->irq_sp = asc_dvc->carr_freelist) == NULL)
16385     {
16386         asc_dvc->err_code |= ASC_IERR_NO_CARRIER;
16387         return ADV_ERROR;
16388     }
16389     asc_dvc->carr_freelist = (ADV_CARR_T *)
16390         ADV_U32_TO_VADDR(le32_to_cpu(asc_dvc->irq_sp->next_vpa));
16391
16392     /*
16393      * The first command completed by the RISC will be placed in
16394      * the stopper.
16395      *
16396      * Note: Set 'next_vpa' to ASC_CQ_STOPPER. When the request is
16397      * completed the RISC will set the ASC_RQ_STOPPER bit.
16398      */
16399     asc_dvc->irq_sp->next_vpa = cpu_to_le32(ASC_CQ_STOPPER);
16400
16401     /*
16402      * Set RISC IRQ physical address start value.
16403      */
16404     AdvWriteDWordLramNoSwap(iop_base, ASC_MC_IRQ, asc_dvc->irq_sp->carr_pa);
16405     asc_dvc->carr_pending_cnt = 0;
16406
16407     AdvWriteByteRegister(iop_base, IOPB_INTR_ENABLES,
16408         (ADV_INTR_ENABLE_HOST_INTR | ADV_INTR_ENABLE_GLOBAL_INTR));
16409     AdvReadWordLram(iop_base, ASC_MC_CODE_BEGIN_ADDR, word);
16410     AdvWriteWordRegister(iop_base, IOPW_PC, word);
16411
16412     /* finally, finally, gentlemen, start your engine */
16413     AdvWriteWordRegister(iop_base, IOPW_RISC_CSR, ADV_RISC_CSR_RUN);
16414
16415     /*
16416      * Reset the SCSI Bus if the EEPROM indicates that SCSI Bus
16417      * Resets should be performed. The RISC has to be running
16418      * to issue a SCSI Bus Reset.
16419      */
16420     if (asc_dvc->bios_ctrl & BIOS_CTRL_RESET_SCSI_BUS)
16421     {
16422         /*
16423          * If the BIOS Signature is present in memory, restore the
16424          * per TID microcode operating variables.
16425          */
16426         if (bios_mem[(ASC_MC_BIOS_SIGNATURE - ASC_MC_BIOSMEM)/2] == 0x55AA)
16427         {
16428             /*
16429              * Restore per TID negotiated values.
16430              */
16431             AdvWriteWordLram(iop_base, ASC_MC_WDTR_ABLE, wdtr_able);
16432             AdvWriteWordLram(iop_base, ASC_MC_SDTR_ABLE, sdtr_able);
16433             AdvWriteWordLram(iop_base, ASC_MC_PPR_ABLE, ppr_able);
16434             AdvWriteWordLram(iop_base, ASC_MC_TAGQNG_ABLE, tagqng_able);
16435             for (tid = 0; tid <= ASC_MAX_TID; tid++)
16436             {
16437                 AdvWriteByteLram(iop_base, ASC_MC_NUMBER_OF_MAX_CMD + tid,
16438                     max_cmd[tid]);
16439             }
16440         } else
16441         {
16442             if (AdvResetSB(asc_dvc) != ADV_TRUE)
16443             {
16444                 warn_code = ASC_WARN_BUSRESET_ERROR;
16445             }
16446         }
16447     }
16448
16449     return warn_code;
16450 }
16451
16452 /*
16453  * Read the board's EEPROM configuration. Set fields in ADV_DVC_VAR and
16454  * ADV_DVC_CFG based on the EEPROM settings. The chip is stopped while
16455  * all of this is done.
16456  *
16457  * On failure set the ADV_DVC_VAR field 'err_code' and return ADV_ERROR.
16458  *
16459  * For a non-fatal error return a warning code. If there are no warnings
16460  * then 0 is returned.
16461  *
16462  * Note: Chip is stopped on entry.
16463  */
16464 STATIC int __init
16465 AdvInitFrom3550EEP(ADV_DVC_VAR *asc_dvc)
16466 {
16467     AdvPortAddr         iop_base;
16468     ushort              warn_code;
16469     ADVEEP_3550_CONFIG  eep_config;
16470     int                 i;
16471
16472     iop_base = asc_dvc->iop_base;
16473
16474     warn_code = 0;
16475
16476     /*
16477      * Read the board's EEPROM configuration.
16478      *
16479      * Set default values if a bad checksum is found.
16480      */
16481     if (AdvGet3550EEPConfig(iop_base, &eep_config) != eep_config.check_sum)
16482     {
16483         warn_code |= ASC_WARN_EEPROM_CHKSUM;
16484
16485         /*
16486          * Set EEPROM default values.
16487          */
16488         for (i = 0; i < sizeof(ADVEEP_3550_CONFIG); i++)
16489         {
16490             *((uchar *) &eep_config + i) =
16491                 *((uchar *) &Default_3550_EEPROM_Config + i);
16492         }
16493
16494         /*
16495          * Assume the 6 byte board serial number that was read
16496          * from EEPROM is correct even if the EEPROM checksum
16497          * failed.
16498          */
16499         eep_config.serial_number_word3 =
16500             AdvReadEEPWord(iop_base, ADV_EEP_DVC_CFG_END - 1);
16501
16502         eep_config.serial_number_word2 =
16503             AdvReadEEPWord(iop_base, ADV_EEP_DVC_CFG_END - 2);
16504
16505         eep_config.serial_number_word1 =
16506             AdvReadEEPWord(iop_base, ADV_EEP_DVC_CFG_END - 3);
16507
16508         AdvSet3550EEPConfig(iop_base, &eep_config);
16509     }
16510     /*
16511      * Set ASC_DVC_VAR and ASC_DVC_CFG variables from the
16512      * EEPROM configuration that was read.
16513      *
16514      * This is the mapping of EEPROM fields to Adv Library fields.
16515      */
16516     asc_dvc->wdtr_able = eep_config.wdtr_able;
16517     asc_dvc->sdtr_able = eep_config.sdtr_able;
16518     asc_dvc->ultra_able = eep_config.ultra_able;
16519     asc_dvc->tagqng_able = eep_config.tagqng_able;
16520     asc_dvc->cfg->disc_enable = eep_config.disc_enable;
16521     asc_dvc->max_host_qng = eep_config.max_host_qng;
16522     asc_dvc->max_dvc_qng = eep_config.max_dvc_qng;
16523     asc_dvc->chip_scsi_id = (eep_config.adapter_scsi_id & ADV_MAX_TID);
16524     asc_dvc->start_motor = eep_config.start_motor;
16525     asc_dvc->scsi_reset_wait = eep_config.scsi_reset_delay;
16526     asc_dvc->bios_ctrl = eep_config.bios_ctrl;
16527     asc_dvc->no_scam = eep_config.scam_tolerant;
16528     asc_dvc->cfg->serial1 = eep_config.serial_number_word1;
16529     asc_dvc->cfg->serial2 = eep_config.serial_number_word2;
16530     asc_dvc->cfg->serial3 = eep_config.serial_number_word3;
16531
16532     /*
16533      * Set the host maximum queuing (max. 253, min. 16) and the per device
16534      * maximum queuing (max. 63, min. 4).
16535      */
16536     if (eep_config.max_host_qng > ASC_DEF_MAX_HOST_QNG)
16537     {
16538         eep_config.max_host_qng = ASC_DEF_MAX_HOST_QNG;
16539     } else if (eep_config.max_host_qng < ASC_DEF_MIN_HOST_QNG)
16540     {
16541         /* If the value is zero, assume it is uninitialized. */
16542         if (eep_config.max_host_qng == 0)
16543         {
16544             eep_config.max_host_qng = ASC_DEF_MAX_HOST_QNG;
16545         } else
16546         {
16547             eep_config.max_host_qng = ASC_DEF_MIN_HOST_QNG;
16548         }
16549     }
16550
16551     if (eep_config.max_dvc_qng > ASC_DEF_MAX_DVC_QNG)
16552     {
16553         eep_config.max_dvc_qng = ASC_DEF_MAX_DVC_QNG;
16554     } else if (eep_config.max_dvc_qng < ASC_DEF_MIN_DVC_QNG)
16555     {
16556         /* If the value is zero, assume it is uninitialized. */
16557         if (eep_config.max_dvc_qng == 0)
16558         {
16559             eep_config.max_dvc_qng = ASC_DEF_MAX_DVC_QNG;
16560         } else
16561         {
16562             eep_config.max_dvc_qng = ASC_DEF_MIN_DVC_QNG;
16563         }
16564     }
16565
16566     /*
16567      * If 'max_dvc_qng' is greater than 'max_host_qng', then
16568      * set 'max_dvc_qng' to 'max_host_qng'.
16569      */
16570     if (eep_config.max_dvc_qng > eep_config.max_host_qng)
16571     {
16572         eep_config.max_dvc_qng = eep_config.max_host_qng;
16573     }
16574
16575     /*
16576      * Set ADV_DVC_VAR 'max_host_qng' and ADV_DVC_VAR 'max_dvc_qng'
16577      * values based on possibly adjusted EEPROM values.
16578      */
16579     asc_dvc->max_host_qng = eep_config.max_host_qng;
16580     asc_dvc->max_dvc_qng = eep_config.max_dvc_qng;
16581
16582
16583     /*
16584      * If the EEPROM 'termination' field is set to automatic (0), then set
16585      * the ADV_DVC_CFG 'termination' field to automatic also.
16586      *
16587      * If the termination is specified with a non-zero 'termination'
16588      * value check that a legal value is set and set the ADV_DVC_CFG
16589      * 'termination' field appropriately.
16590      */
16591     if (eep_config.termination == 0)
16592     {
16593         asc_dvc->cfg->termination = 0;    /* auto termination */
16594     } else
16595     {
16596         /* Enable manual control with low off / high off. */
16597         if (eep_config.termination == 1)
16598         {
16599             asc_dvc->cfg->termination = TERM_CTL_SEL;
16600
16601         /* Enable manual control with low off / high on. */
16602         } else if (eep_config.termination == 2)
16603         {
16604             asc_dvc->cfg->termination = TERM_CTL_SEL | TERM_CTL_H;
16605
16606         /* Enable manual control with low on / high on. */
16607         } else if (eep_config.termination == 3)
16608         {
16609             asc_dvc->cfg->termination = TERM_CTL_SEL | TERM_CTL_H | TERM_CTL_L;
16610         } else
16611         {
16612             /*
16613              * The EEPROM 'termination' field contains a bad value. Use
16614              * automatic termination instead.
16615              */
16616             asc_dvc->cfg->termination = 0;
16617             warn_code |= ASC_WARN_EEPROM_TERMINATION;
16618         }
16619     }
16620
16621     return warn_code;
16622 }
16623
16624 /*
16625  * Read the board's EEPROM configuration. Set fields in ADV_DVC_VAR and
16626  * ADV_DVC_CFG based on the EEPROM settings. The chip is stopped while
16627  * all of this is done.
16628  *
16629  * On failure set the ADV_DVC_VAR field 'err_code' and return ADV_ERROR.
16630  *
16631  * For a non-fatal error return a warning code. If there are no warnings
16632  * then 0 is returned.
16633  *
16634  * Note: Chip is stopped on entry.
16635  */
16636 STATIC int __init
16637 AdvInitFrom38C0800EEP(ADV_DVC_VAR *asc_dvc)
16638 {
16639     AdvPortAddr              iop_base;
16640     ushort                   warn_code;
16641     ADVEEP_38C0800_CONFIG    eep_config;
16642     int                      i;
16643     uchar                    tid, termination;
16644     ushort                   sdtr_speed = 0;
16645
16646     iop_base = asc_dvc->iop_base;
16647
16648     warn_code = 0;
16649
16650     /*
16651      * Read the board's EEPROM configuration.
16652      *
16653      * Set default values if a bad checksum is found.
16654      */
16655     if (AdvGet38C0800EEPConfig(iop_base, &eep_config) != eep_config.check_sum)
16656     {
16657         warn_code |= ASC_WARN_EEPROM_CHKSUM;
16658
16659         /*
16660          * Set EEPROM default values.
16661          */
16662         for (i = 0; i < sizeof(ADVEEP_38C0800_CONFIG); i++)
16663         {
16664             *((uchar *) &eep_config + i) =
16665                 *((uchar *) &Default_38C0800_EEPROM_Config + i);
16666         }
16667
16668         /*
16669          * Assume the 6 byte board serial number that was read
16670          * from EEPROM is correct even if the EEPROM checksum
16671          * failed.
16672          */
16673         eep_config.serial_number_word3 =
16674             AdvReadEEPWord(iop_base, ADV_EEP_DVC_CFG_END - 1);
16675
16676         eep_config.serial_number_word2 =
16677             AdvReadEEPWord(iop_base, ADV_EEP_DVC_CFG_END - 2);
16678
16679         eep_config.serial_number_word1 =
16680             AdvReadEEPWord(iop_base, ADV_EEP_DVC_CFG_END - 3);
16681
16682         AdvSet38C0800EEPConfig(iop_base, &eep_config);
16683     }
16684     /*
16685      * Set ADV_DVC_VAR and ADV_DVC_CFG variables from the
16686      * EEPROM configuration that was read.
16687      *
16688      * This is the mapping of EEPROM fields to Adv Library fields.
16689      */
16690     asc_dvc->wdtr_able = eep_config.wdtr_able;
16691     asc_dvc->sdtr_speed1 = eep_config.sdtr_speed1;
16692     asc_dvc->sdtr_speed2 = eep_config.sdtr_speed2;
16693     asc_dvc->sdtr_speed3 = eep_config.sdtr_speed3;
16694     asc_dvc->sdtr_speed4 = eep_config.sdtr_speed4;
16695     asc_dvc->tagqng_able = eep_config.tagqng_able;
16696     asc_dvc->cfg->disc_enable = eep_config.disc_enable;
16697     asc_dvc->max_host_qng = eep_config.max_host_qng;
16698     asc_dvc->max_dvc_qng = eep_config.max_dvc_qng;
16699     asc_dvc->chip_scsi_id = (eep_config.adapter_scsi_id & ADV_MAX_TID);
16700     asc_dvc->start_motor = eep_config.start_motor;
16701     asc_dvc->scsi_reset_wait = eep_config.scsi_reset_delay;
16702     asc_dvc->bios_ctrl = eep_config.bios_ctrl;
16703     asc_dvc->no_scam = eep_config.scam_tolerant;
16704     asc_dvc->cfg->serial1 = eep_config.serial_number_word1;
16705     asc_dvc->cfg->serial2 = eep_config.serial_number_word2;
16706     asc_dvc->cfg->serial3 = eep_config.serial_number_word3;
16707
16708     /*
16709      * For every Target ID if any of its 'sdtr_speed[1234]' bits
16710      * are set, then set an 'sdtr_able' bit for it.
16711      */
16712     asc_dvc->sdtr_able = 0;
16713     for (tid = 0; tid <= ADV_MAX_TID; tid++)
16714     {
16715         if (tid == 0)
16716         {
16717             sdtr_speed = asc_dvc->sdtr_speed1;
16718         } else if (tid == 4)
16719         {
16720             sdtr_speed = asc_dvc->sdtr_speed2;
16721         } else if (tid == 8)
16722         {
16723             sdtr_speed = asc_dvc->sdtr_speed3;
16724         } else if (tid == 12)
16725         {
16726             sdtr_speed = asc_dvc->sdtr_speed4;
16727         }
16728         if (sdtr_speed & ADV_MAX_TID)
16729         {
16730             asc_dvc->sdtr_able |= (1 << tid);
16731         }
16732         sdtr_speed >>= 4;
16733     }
16734
16735     /*
16736      * Set the host maximum queuing (max. 253, min. 16) and the per device
16737      * maximum queuing (max. 63, min. 4).
16738      */
16739     if (eep_config.max_host_qng > ASC_DEF_MAX_HOST_QNG)
16740     {
16741         eep_config.max_host_qng = ASC_DEF_MAX_HOST_QNG;
16742     } else if (eep_config.max_host_qng < ASC_DEF_MIN_HOST_QNG)
16743     {
16744         /* If the value is zero, assume it is uninitialized. */
16745         if (eep_config.max_host_qng == 0)
16746         {
16747             eep_config.max_host_qng = ASC_DEF_MAX_HOST_QNG;
16748         } else
16749         {
16750             eep_config.max_host_qng = ASC_DEF_MIN_HOST_QNG;
16751         }
16752     }
16753
16754     if (eep_config.max_dvc_qng > ASC_DEF_MAX_DVC_QNG)
16755     {
16756         eep_config.max_dvc_qng = ASC_DEF_MAX_DVC_QNG;
16757     } else if (eep_config.max_dvc_qng < ASC_DEF_MIN_DVC_QNG)
16758     {
16759         /* If the value is zero, assume it is uninitialized. */
16760         if (eep_config.max_dvc_qng == 0)
16761         {
16762             eep_config.max_dvc_qng = ASC_DEF_MAX_DVC_QNG;
16763         } else
16764         {
16765             eep_config.max_dvc_qng = ASC_DEF_MIN_DVC_QNG;
16766         }
16767     }
16768
16769     /*
16770      * If 'max_dvc_qng' is greater than 'max_host_qng', then
16771      * set 'max_dvc_qng' to 'max_host_qng'.
16772      */
16773     if (eep_config.max_dvc_qng > eep_config.max_host_qng)
16774     {
16775         eep_config.max_dvc_qng = eep_config.max_host_qng;
16776     }
16777
16778     /*
16779      * Set ADV_DVC_VAR 'max_host_qng' and ADV_DVC_VAR 'max_dvc_qng'
16780      * values based on possibly adjusted EEPROM values.
16781      */
16782     asc_dvc->max_host_qng = eep_config.max_host_qng;
16783     asc_dvc->max_dvc_qng = eep_config.max_dvc_qng;
16784
16785     /*
16786      * If the EEPROM 'termination' field is set to automatic (0), then set
16787      * the ADV_DVC_CFG 'termination' field to automatic also.
16788      *
16789      * If the termination is specified with a non-zero 'termination'
16790      * value check that a legal value is set and set the ADV_DVC_CFG
16791      * 'termination' field appropriately.
16792      */
16793     if (eep_config.termination_se == 0)
16794     {
16795         termination = 0;                         /* auto termination for SE */
16796     } else
16797     {
16798         /* Enable manual control with low off / high off. */
16799         if (eep_config.termination_se == 1)
16800         {
16801             termination = 0;
16802
16803         /* Enable manual control with low off / high on. */
16804         } else if (eep_config.termination_se == 2)
16805         {
16806             termination = TERM_SE_HI;
16807
16808         /* Enable manual control with low on / high on. */
16809         } else if (eep_config.termination_se == 3)
16810         {
16811             termination = TERM_SE;
16812         } else
16813         {
16814             /*
16815              * The EEPROM 'termination_se' field contains a bad value.
16816              * Use automatic termination instead.
16817              */
16818             termination = 0;
16819             warn_code |= ASC_WARN_EEPROM_TERMINATION;
16820         }
16821     }
16822
16823     if (eep_config.termination_lvd == 0)
16824     {
16825         asc_dvc->cfg->termination = termination; /* auto termination for LVD */
16826     } else
16827     {
16828         /* Enable manual control with low off / high off. */
16829         if (eep_config.termination_lvd == 1)
16830         {
16831             asc_dvc->cfg->termination = termination;
16832
16833         /* Enable manual control with low off / high on. */
16834         } else if (eep_config.termination_lvd == 2)
16835         {
16836             asc_dvc->cfg->termination = termination | TERM_LVD_HI;
16837
16838         /* Enable manual control with low on / high on. */
16839         } else if (eep_config.termination_lvd == 3)
16840         {
16841             asc_dvc->cfg->termination =
16842                 termination | TERM_LVD;
16843         } else
16844         {
16845             /*
16846              * The EEPROM 'termination_lvd' field contains a bad value.
16847              * Use automatic termination instead.
16848              */
16849             asc_dvc->cfg->termination = termination;
16850             warn_code |= ASC_WARN_EEPROM_TERMINATION;
16851         }
16852     }
16853
16854     return warn_code;
16855 }
16856
16857 /*
16858  * Read the board's EEPROM configuration. Set fields in ASC_DVC_VAR and
16859  * ASC_DVC_CFG based on the EEPROM settings. The chip is stopped while
16860  * all of this is done.
16861  *
16862  * On failure set the ASC_DVC_VAR field 'err_code' and return ADV_ERROR.
16863  *
16864  * For a non-fatal error return a warning code. If there are no warnings
16865  * then 0 is returned.
16866  *
16867  * Note: Chip is stopped on entry.
16868  */
16869 STATIC int __init
16870 AdvInitFrom38C1600EEP(ADV_DVC_VAR *asc_dvc)
16871 {
16872     AdvPortAddr              iop_base;
16873     ushort                   warn_code;
16874     ADVEEP_38C1600_CONFIG    eep_config;
16875     int                      i;
16876     uchar                    tid, termination;
16877     ushort                   sdtr_speed = 0;
16878
16879     iop_base = asc_dvc->iop_base;
16880
16881     warn_code = 0;
16882
16883     /*
16884      * Read the board's EEPROM configuration.
16885      *
16886      * Set default values if a bad checksum is found.
16887      */
16888     if (AdvGet38C1600EEPConfig(iop_base, &eep_config) != eep_config.check_sum)
16889     {
16890         warn_code |= ASC_WARN_EEPROM_CHKSUM;
16891
16892         /*
16893          * Set EEPROM default values.
16894          */
16895         for (i = 0; i < sizeof(ADVEEP_38C1600_CONFIG); i++)
16896         {
16897             if (i == 1 && ASC_PCI_ID2FUNC(asc_dvc->cfg->pci_slot_info) != 0)
16898             {
16899                 /*
16900                  * Set Function 1 EEPROM Word 0 MSB
16901                  *
16902                  * Clear the BIOS_ENABLE (bit 14) and INTAB (bit 11)
16903                  * EEPROM bits.
16904                  *
16905                  * Disable Bit 14 (BIOS_ENABLE) to fix SPARC Ultra 60 and
16906                  * old Mac system booting problem. The Expansion ROM must
16907                  * be disabled in Function 1 for these systems.
16908                  *
16909                  */
16910                 *((uchar *) &eep_config + i) =
16911                 ((*((uchar *) &Default_38C1600_EEPROM_Config + i)) &
16912                     (~(((ADV_EEPROM_BIOS_ENABLE | ADV_EEPROM_INTAB) >> 8) &
16913                      0xFF)));
16914
16915                 /*
16916                  * Set the INTAB (bit 11) if the GPIO 0 input indicates
16917                  * the Function 1 interrupt line is wired to INTA.
16918                  *
16919                  * Set/Clear Bit 11 (INTAB) from the GPIO bit 0 input:
16920                  *   1 - Function 1 interrupt line wired to INT A.
16921                  *   0 - Function 1 interrupt line wired to INT B.
16922                  *
16923                  * Note: Adapter boards always have Function 0 wired to INTA.
16924                  * Put all 5 GPIO bits in input mode and then read
16925                  * their input values.
16926                  */
16927                 AdvWriteByteRegister(iop_base, IOPB_GPIO_CNTL, 0);
16928                 if (AdvReadByteRegister(iop_base, IOPB_GPIO_DATA) & 0x01)
16929                 {
16930                     /* Function 1 interrupt wired to INTA; Set EEPROM bit. */
16931                 *((uchar *) &eep_config + i) |=
16932                     ((ADV_EEPROM_INTAB >> 8) & 0xFF);
16933                 }
16934             }
16935             else
16936             {
16937                 *((uchar *) &eep_config + i) =
16938                 *((uchar *) &Default_38C1600_EEPROM_Config + i);
16939             }
16940         }
16941
16942         /*
16943          * Assume the 6 byte board serial number that was read
16944          * from EEPROM is correct even if the EEPROM checksum
16945          * failed.
16946          */
16947         eep_config.serial_number_word3 =
16948             AdvReadEEPWord(iop_base, ADV_EEP_DVC_CFG_END - 1);
16949
16950         eep_config.serial_number_word2 =
16951             AdvReadEEPWord(iop_base, ADV_EEP_DVC_CFG_END - 2);
16952
16953         eep_config.serial_number_word1 =
16954             AdvReadEEPWord(iop_base, ADV_EEP_DVC_CFG_END - 3);
16955
16956         AdvSet38C1600EEPConfig(iop_base, &eep_config);
16957     }
16958
16959     /*
16960      * Set ASC_DVC_VAR and ASC_DVC_CFG variables from the
16961      * EEPROM configuration that was read.
16962      *
16963      * This is the mapping of EEPROM fields to Adv Library fields.
16964      */
16965     asc_dvc->wdtr_able = eep_config.wdtr_able;
16966     asc_dvc->sdtr_speed1 = eep_config.sdtr_speed1;
16967     asc_dvc->sdtr_speed2 = eep_config.sdtr_speed2;
16968     asc_dvc->sdtr_speed3 = eep_config.sdtr_speed3;
16969     asc_dvc->sdtr_speed4 = eep_config.sdtr_speed4;
16970     asc_dvc->ppr_able = 0;
16971     asc_dvc->tagqng_able = eep_config.tagqng_able;
16972     asc_dvc->cfg->disc_enable = eep_config.disc_enable;
16973     asc_dvc->max_host_qng = eep_config.max_host_qng;
16974     asc_dvc->max_dvc_qng = eep_config.max_dvc_qng;
16975     asc_dvc->chip_scsi_id = (eep_config.adapter_scsi_id & ASC_MAX_TID);
16976     asc_dvc->start_motor = eep_config.start_motor;
16977     asc_dvc->scsi_reset_wait = eep_config.scsi_reset_delay;
16978     asc_dvc->bios_ctrl = eep_config.bios_ctrl;
16979     asc_dvc->no_scam = eep_config.scam_tolerant;
16980
16981     /*
16982      * For every Target ID if any of its 'sdtr_speed[1234]' bits
16983      * are set, then set an 'sdtr_able' bit for it.
16984      */
16985     asc_dvc->sdtr_able = 0;
16986     for (tid = 0; tid <= ASC_MAX_TID; tid++)
16987     {
16988         if (tid == 0)
16989         {
16990             sdtr_speed = asc_dvc->sdtr_speed1;
16991         } else if (tid == 4)
16992         {
16993             sdtr_speed = asc_dvc->sdtr_speed2;
16994         } else if (tid == 8)
16995         {
16996             sdtr_speed = asc_dvc->sdtr_speed3;
16997         } else if (tid == 12)
16998         {
16999             sdtr_speed = asc_dvc->sdtr_speed4;
17000         }
17001         if (sdtr_speed & ASC_MAX_TID)
17002         {
17003             asc_dvc->sdtr_able |= (1 << tid);
17004         }
17005         sdtr_speed >>= 4;
17006     }
17007
17008     /*
17009      * Set the host maximum queuing (max. 253, min. 16) and the per device
17010      * maximum queuing (max. 63, min. 4).
17011      */
17012     if (eep_config.max_host_qng > ASC_DEF_MAX_HOST_QNG)
17013     {
17014         eep_config.max_host_qng = ASC_DEF_MAX_HOST_QNG;
17015     } else if (eep_config.max_host_qng < ASC_DEF_MIN_HOST_QNG)
17016     {
17017         /* If the value is zero, assume it is uninitialized. */
17018         if (eep_config.max_host_qng == 0)
17019         {
17020             eep_config.max_host_qng = ASC_DEF_MAX_HOST_QNG;
17021         } else
17022         {
17023             eep_config.max_host_qng = ASC_DEF_MIN_HOST_QNG;
17024         }
17025     }
17026
17027     if (eep_config.max_dvc_qng > ASC_DEF_MAX_DVC_QNG)
17028     {
17029         eep_config.max_dvc_qng = ASC_DEF_MAX_DVC_QNG;
17030     } else if (eep_config.max_dvc_qng < ASC_DEF_MIN_DVC_QNG)
17031     {
17032         /* If the value is zero, assume it is uninitialized. */
17033         if (eep_config.max_dvc_qng == 0)
17034         {
17035             eep_config.max_dvc_qng = ASC_DEF_MAX_DVC_QNG;
17036         } else
17037         {
17038             eep_config.max_dvc_qng = ASC_DEF_MIN_DVC_QNG;
17039         }
17040     }
17041
17042     /*
17043      * If 'max_dvc_qng' is greater than 'max_host_qng', then
17044      * set 'max_dvc_qng' to 'max_host_qng'.
17045      */
17046     if (eep_config.max_dvc_qng > eep_config.max_host_qng)
17047     {
17048         eep_config.max_dvc_qng = eep_config.max_host_qng;
17049     }
17050
17051     /*
17052      * Set ASC_DVC_VAR 'max_host_qng' and ASC_DVC_VAR 'max_dvc_qng'
17053      * values based on possibly adjusted EEPROM values.
17054      */
17055     asc_dvc->max_host_qng = eep_config.max_host_qng;
17056     asc_dvc->max_dvc_qng = eep_config.max_dvc_qng;
17057
17058     /*
17059      * If the EEPROM 'termination' field is set to automatic (0), then set
17060      * the ASC_DVC_CFG 'termination' field to automatic also.
17061      *
17062      * If the termination is specified with a non-zero 'termination'
17063      * value check that a legal value is set and set the ASC_DVC_CFG
17064      * 'termination' field appropriately.
17065      */
17066     if (eep_config.termination_se == 0)
17067     {
17068         termination = 0;                         /* auto termination for SE */
17069     } else
17070     {
17071         /* Enable manual control with low off / high off. */
17072         if (eep_config.termination_se == 1)
17073         {
17074             termination = 0;
17075
17076         /* Enable manual control with low off / high on. */
17077         } else if (eep_config.termination_se == 2)
17078         {
17079             termination = TERM_SE_HI;
17080
17081         /* Enable manual control with low on / high on. */
17082         } else if (eep_config.termination_se == 3)
17083         {
17084             termination = TERM_SE;
17085         } else
17086         {
17087             /*
17088              * The EEPROM 'termination_se' field contains a bad value.
17089              * Use automatic termination instead.
17090              */
17091             termination = 0;
17092             warn_code |= ASC_WARN_EEPROM_TERMINATION;
17093         }
17094     }
17095
17096     if (eep_config.termination_lvd == 0)
17097     {
17098         asc_dvc->cfg->termination = termination; /* auto termination for LVD */
17099     } else
17100     {
17101         /* Enable manual control with low off / high off. */
17102         if (eep_config.termination_lvd == 1)
17103         {
17104             asc_dvc->cfg->termination = termination;
17105
17106         /* Enable manual control with low off / high on. */
17107         } else if (eep_config.termination_lvd == 2)
17108         {
17109             asc_dvc->cfg->termination = termination | TERM_LVD_HI;
17110
17111         /* Enable manual control with low on / high on. */
17112         } else if (eep_config.termination_lvd == 3)
17113         {
17114             asc_dvc->cfg->termination =
17115                 termination | TERM_LVD;
17116         } else
17117         {
17118             /*
17119              * The EEPROM 'termination_lvd' field contains a bad value.
17120              * Use automatic termination instead.
17121              */
17122             asc_dvc->cfg->termination = termination;
17123             warn_code |= ASC_WARN_EEPROM_TERMINATION;
17124         }
17125     }
17126
17127     return warn_code;
17128 }
17129
17130 /*
17131  * Read EEPROM configuration into the specified buffer.
17132  *
17133  * Return a checksum based on the EEPROM configuration read.
17134  */
17135 STATIC ushort __init
17136 AdvGet3550EEPConfig(AdvPortAddr iop_base, ADVEEP_3550_CONFIG *cfg_buf)
17137 {
17138     ushort              wval, chksum;
17139     ushort              *wbuf;
17140     int                 eep_addr;
17141     ushort              *charfields;
17142
17143     charfields = (ushort *) &ADVEEP_3550_Config_Field_IsChar;
17144     wbuf = (ushort *) cfg_buf;
17145     chksum = 0;
17146
17147     for (eep_addr = ADV_EEP_DVC_CFG_BEGIN;
17148          eep_addr < ADV_EEP_DVC_CFG_END;
17149          eep_addr++, wbuf++)
17150     {
17151         wval = AdvReadEEPWord(iop_base, eep_addr);
17152         chksum += wval; /* Checksum is calculated from word values. */
17153         if (*charfields++) {
17154             *wbuf = le16_to_cpu(wval);
17155         } else {
17156             *wbuf = wval;
17157         }
17158     }
17159     /* Read checksum word. */
17160     *wbuf = AdvReadEEPWord(iop_base, eep_addr);
17161     wbuf++; charfields++;
17162
17163     /* Read rest of EEPROM not covered by the checksum. */
17164     for (eep_addr = ADV_EEP_DVC_CTL_BEGIN;
17165          eep_addr < ADV_EEP_MAX_WORD_ADDR;
17166          eep_addr++, wbuf++)
17167     {
17168         *wbuf = AdvReadEEPWord(iop_base, eep_addr);
17169         if (*charfields++) {
17170             *wbuf = le16_to_cpu(*wbuf);
17171         }
17172     }
17173     return chksum;
17174 }
17175
17176 /*
17177  * Read EEPROM configuration into the specified buffer.
17178  *
17179  * Return a checksum based on the EEPROM configuration read.
17180  */
17181 STATIC ushort __init
17182 AdvGet38C0800EEPConfig(AdvPortAddr iop_base,
17183                        ADVEEP_38C0800_CONFIG *cfg_buf)
17184 {
17185     ushort              wval, chksum;
17186     ushort              *wbuf;
17187     int                 eep_addr;
17188     ushort              *charfields;
17189
17190     charfields = (ushort *) &ADVEEP_38C0800_Config_Field_IsChar;
17191     wbuf = (ushort *) cfg_buf;
17192     chksum = 0;
17193
17194     for (eep_addr = ADV_EEP_DVC_CFG_BEGIN;
17195          eep_addr < ADV_EEP_DVC_CFG_END;
17196          eep_addr++, wbuf++)
17197     {
17198         wval = AdvReadEEPWord(iop_base, eep_addr);
17199         chksum += wval; /* Checksum is calculated from word values. */
17200         if (*charfields++) {
17201             *wbuf = le16_to_cpu(wval);
17202         } else {
17203             *wbuf = wval;
17204         }
17205     }
17206     /* Read checksum word. */
17207     *wbuf = AdvReadEEPWord(iop_base, eep_addr);
17208     wbuf++; charfields++;
17209
17210     /* Read rest of EEPROM not covered by the checksum. */
17211     for (eep_addr = ADV_EEP_DVC_CTL_BEGIN;
17212          eep_addr < ADV_EEP_MAX_WORD_ADDR;
17213          eep_addr++, wbuf++)
17214     {
17215         *wbuf = AdvReadEEPWord(iop_base, eep_addr);
17216         if (*charfields++) {
17217             *wbuf = le16_to_cpu(*wbuf);
17218         }
17219     }
17220     return chksum;
17221 }
17222
17223 /*
17224  * Read EEPROM configuration into the specified buffer.
17225  *
17226  * Return a checksum based on the EEPROM configuration read.
17227  */
17228 STATIC ushort __init
17229 AdvGet38C1600EEPConfig(AdvPortAddr iop_base,
17230                        ADVEEP_38C1600_CONFIG *cfg_buf)
17231 {
17232     ushort              wval, chksum;
17233     ushort              *wbuf;
17234     int                 eep_addr;
17235     ushort              *charfields;
17236
17237     charfields = (ushort*) &ADVEEP_38C1600_Config_Field_IsChar;
17238     wbuf = (ushort *) cfg_buf;
17239     chksum = 0;
17240
17241     for (eep_addr = ADV_EEP_DVC_CFG_BEGIN;
17242          eep_addr < ADV_EEP_DVC_CFG_END;
17243          eep_addr++, wbuf++)
17244     {
17245         wval = AdvReadEEPWord(iop_base, eep_addr);
17246         chksum += wval; /* Checksum is calculated from word values. */
17247         if (*charfields++) {
17248             *wbuf = le16_to_cpu(wval);
17249         } else {
17250             *wbuf = wval;
17251         }
17252     }
17253     /* Read checksum word. */
17254     *wbuf = AdvReadEEPWord(iop_base, eep_addr);
17255     wbuf++; charfields++;
17256
17257     /* Read rest of EEPROM not covered by the checksum. */
17258     for (eep_addr = ADV_EEP_DVC_CTL_BEGIN;
17259          eep_addr < ADV_EEP_MAX_WORD_ADDR;
17260          eep_addr++, wbuf++)
17261     {
17262         *wbuf = AdvReadEEPWord(iop_base, eep_addr);
17263         if (*charfields++) {
17264             *wbuf = le16_to_cpu(*wbuf);
17265         }
17266     }
17267     return chksum;
17268 }
17269
17270 /*
17271  * Read the EEPROM from specified location
17272  */
17273 STATIC ushort __init
17274 AdvReadEEPWord(AdvPortAddr iop_base, int eep_word_addr)
17275 {
17276     AdvWriteWordRegister(iop_base, IOPW_EE_CMD,
17277         ASC_EEP_CMD_READ | eep_word_addr);
17278     AdvWaitEEPCmd(iop_base);
17279     return AdvReadWordRegister(iop_base, IOPW_EE_DATA);
17280 }
17281
17282 /*
17283  * Wait for EEPROM command to complete
17284  */
17285 STATIC void __init
17286 AdvWaitEEPCmd(AdvPortAddr iop_base)
17287 {
17288     int eep_delay_ms;
17289
17290     for (eep_delay_ms = 0; eep_delay_ms < ADV_EEP_DELAY_MS; eep_delay_ms++)
17291     {
17292         if (AdvReadWordRegister(iop_base, IOPW_EE_CMD) & ASC_EEP_CMD_DONE)
17293         {
17294             break;
17295         }
17296         DvcSleepMilliSecond(1);
17297     }
17298     if ((AdvReadWordRegister(iop_base, IOPW_EE_CMD) & ASC_EEP_CMD_DONE) == 0)
17299     {
17300         ASC_ASSERT(0);
17301     }
17302     return;
17303 }
17304
17305 /*
17306  * Write the EEPROM from 'cfg_buf'.
17307  */
17308 void __init
17309 AdvSet3550EEPConfig(AdvPortAddr iop_base, ADVEEP_3550_CONFIG *cfg_buf)
17310 {
17311     ushort *wbuf;
17312     ushort addr, chksum;
17313     ushort *charfields;
17314
17315     wbuf = (ushort *) cfg_buf;
17316     charfields = (ushort *) &ADVEEP_3550_Config_Field_IsChar;
17317     chksum = 0;
17318
17319     AdvWriteWordRegister(iop_base, IOPW_EE_CMD, ASC_EEP_CMD_WRITE_ABLE);
17320     AdvWaitEEPCmd(iop_base);
17321
17322     /*
17323      * Write EEPROM from word 0 to word 20.
17324      */
17325     for (addr = ADV_EEP_DVC_CFG_BEGIN;
17326          addr < ADV_EEP_DVC_CFG_END; addr++, wbuf++)
17327     {
17328         ushort word;
17329
17330         if (*charfields++) {
17331             word = cpu_to_le16(*wbuf);
17332         } else {
17333             word = *wbuf;
17334         }
17335         chksum += *wbuf; /* Checksum is calculated from word values. */
17336         AdvWriteWordRegister(iop_base, IOPW_EE_DATA, word);
17337         AdvWriteWordRegister(iop_base, IOPW_EE_CMD, ASC_EEP_CMD_WRITE | addr);
17338         AdvWaitEEPCmd(iop_base);
17339         DvcSleepMilliSecond(ADV_EEP_DELAY_MS);
17340     }
17341
17342     /*
17343      * Write EEPROM checksum at word 21.
17344      */
17345     AdvWriteWordRegister(iop_base, IOPW_EE_DATA, chksum);
17346     AdvWriteWordRegister(iop_base, IOPW_EE_CMD, ASC_EEP_CMD_WRITE | addr);
17347     AdvWaitEEPCmd(iop_base);
17348     wbuf++; charfields++;
17349
17350     /*
17351      * Write EEPROM OEM name at words 22 to 29.
17352      */
17353     for (addr = ADV_EEP_DVC_CTL_BEGIN;
17354          addr < ADV_EEP_MAX_WORD_ADDR; addr++, wbuf++)
17355     {
17356         ushort word;
17357
17358         if (*charfields++) {
17359             word = cpu_to_le16(*wbuf);
17360         } else {
17361             word = *wbuf;
17362         }
17363         AdvWriteWordRegister(iop_base, IOPW_EE_DATA, word);
17364         AdvWriteWordRegister(iop_base, IOPW_EE_CMD, ASC_EEP_CMD_WRITE | addr);
17365         AdvWaitEEPCmd(iop_base);
17366     }
17367     AdvWriteWordRegister(iop_base, IOPW_EE_CMD, ASC_EEP_CMD_WRITE_DISABLE);
17368     AdvWaitEEPCmd(iop_base);
17369     return;
17370 }
17371
17372 /*
17373  * Write the EEPROM from 'cfg_buf'.
17374  */
17375 void __init
17376 AdvSet38C0800EEPConfig(AdvPortAddr iop_base,
17377                        ADVEEP_38C0800_CONFIG *cfg_buf)
17378 {
17379     ushort *wbuf;
17380     ushort *charfields;
17381     ushort addr, chksum;
17382
17383     wbuf = (ushort *) cfg_buf;
17384     charfields = (ushort *) &ADVEEP_38C0800_Config_Field_IsChar;
17385     chksum = 0;
17386
17387     AdvWriteWordRegister(iop_base, IOPW_EE_CMD, ASC_EEP_CMD_WRITE_ABLE);
17388     AdvWaitEEPCmd(iop_base);
17389
17390     /*
17391      * Write EEPROM from word 0 to word 20.
17392      */
17393     for (addr = ADV_EEP_DVC_CFG_BEGIN;
17394          addr < ADV_EEP_DVC_CFG_END; addr++, wbuf++)
17395     {
17396         ushort word;
17397
17398         if (*charfields++) {
17399             word = cpu_to_le16(*wbuf);
17400         } else {
17401             word = *wbuf;
17402         }
17403         chksum += *wbuf; /* Checksum is calculated from word values. */
17404         AdvWriteWordRegister(iop_base, IOPW_EE_DATA, word);
17405         AdvWriteWordRegister(iop_base, IOPW_EE_CMD, ASC_EEP_CMD_WRITE | addr);
17406         AdvWaitEEPCmd(iop_base);
17407         DvcSleepMilliSecond(ADV_EEP_DELAY_MS);
17408     }
17409
17410     /*
17411      * Write EEPROM checksum at word 21.
17412      */
17413     AdvWriteWordRegister(iop_base, IOPW_EE_DATA, chksum);
17414     AdvWriteWordRegister(iop_base, IOPW_EE_CMD, ASC_EEP_CMD_WRITE | addr);
17415     AdvWaitEEPCmd(iop_base);
17416     wbuf++; charfields++;
17417
17418     /*
17419      * Write EEPROM OEM name at words 22 to 29.
17420      */
17421     for (addr = ADV_EEP_DVC_CTL_BEGIN;
17422          addr < ADV_EEP_MAX_WORD_ADDR; addr++, wbuf++)
17423     {
17424         ushort word;
17425
17426         if (*charfields++) {
17427             word = cpu_to_le16(*wbuf);
17428         } else {
17429             word = *wbuf;
17430         }
17431         AdvWriteWordRegister(iop_base, IOPW_EE_DATA, word);
17432         AdvWriteWordRegister(iop_base, IOPW_EE_CMD, ASC_EEP_CMD_WRITE | addr);
17433         AdvWaitEEPCmd(iop_base);
17434     }
17435     AdvWriteWordRegister(iop_base, IOPW_EE_CMD, ASC_EEP_CMD_WRITE_DISABLE);
17436     AdvWaitEEPCmd(iop_base);
17437     return;
17438 }
17439
17440 /*
17441  * Write the EEPROM from 'cfg_buf'.
17442  */
17443 void __init
17444 AdvSet38C1600EEPConfig(AdvPortAddr iop_base,
17445                        ADVEEP_38C1600_CONFIG *cfg_buf)
17446 {
17447     ushort              *wbuf;
17448     ushort              *charfields;
17449     ushort              addr, chksum;
17450
17451     wbuf = (ushort *) cfg_buf;
17452     charfields = (ushort *) &ADVEEP_38C1600_Config_Field_IsChar;
17453     chksum = 0;
17454
17455     AdvWriteWordRegister(iop_base, IOPW_EE_CMD, ASC_EEP_CMD_WRITE_ABLE);
17456     AdvWaitEEPCmd(iop_base);
17457
17458     /*
17459      * Write EEPROM from word 0 to word 20.
17460      */
17461     for (addr = ADV_EEP_DVC_CFG_BEGIN;
17462          addr < ADV_EEP_DVC_CFG_END; addr++, wbuf++)
17463     {
17464         ushort word;
17465
17466         if (*charfields++) {
17467             word = cpu_to_le16(*wbuf);
17468         } else {
17469             word = *wbuf;
17470         }
17471         chksum += *wbuf; /* Checksum is calculated from word values. */
17472         AdvWriteWordRegister(iop_base, IOPW_EE_DATA, word);
17473         AdvWriteWordRegister(iop_base, IOPW_EE_CMD, ASC_EEP_CMD_WRITE | addr);
17474         AdvWaitEEPCmd(iop_base);
17475         DvcSleepMilliSecond(ADV_EEP_DELAY_MS);
17476     }
17477
17478     /*
17479      * Write EEPROM checksum at word 21.
17480      */
17481     AdvWriteWordRegister(iop_base, IOPW_EE_DATA, chksum);
17482     AdvWriteWordRegister(iop_base, IOPW_EE_CMD, ASC_EEP_CMD_WRITE | addr);
17483     AdvWaitEEPCmd(iop_base);
17484     wbuf++; charfields++;
17485
17486     /*
17487      * Write EEPROM OEM name at words 22 to 29.
17488      */
17489     for (addr = ADV_EEP_DVC_CTL_BEGIN;
17490          addr < ADV_EEP_MAX_WORD_ADDR; addr++, wbuf++)
17491     {
17492         ushort word;
17493
17494         if (*charfields++) {
17495             word = cpu_to_le16(*wbuf);
17496         } else {
17497             word = *wbuf;
17498         }
17499         AdvWriteWordRegister(iop_base, IOPW_EE_DATA, word);
17500         AdvWriteWordRegister(iop_base, IOPW_EE_CMD, ASC_EEP_CMD_WRITE | addr);
17501         AdvWaitEEPCmd(iop_base);
17502     }
17503     AdvWriteWordRegister(iop_base, IOPW_EE_CMD, ASC_EEP_CMD_WRITE_DISABLE);
17504     AdvWaitEEPCmd(iop_base);
17505     return;
17506 }
17507
17508 /* a_advlib.c */
17509 /*
17510  * AdvExeScsiQueue() - Send a request to the RISC microcode program.
17511  *
17512  *   Allocate a carrier structure, point the carrier to the ADV_SCSI_REQ_Q,
17513  *   add the carrier to the ICQ (Initiator Command Queue), and tickle the
17514  *   RISC to notify it a new command is ready to be executed.
17515  *
17516  * If 'done_status' is not set to QD_DO_RETRY, then 'error_retry' will be
17517  * set to SCSI_MAX_RETRY.
17518  *
17519  * Multi-byte fields in the ASC_SCSI_REQ_Q that are used by the microcode
17520  * for DMA addresses or math operations are byte swapped to little-endian
17521  * order.
17522  *
17523  * Return:
17524  *      ADV_SUCCESS(1) - The request was successfully queued.
17525  *      ADV_BUSY(0) -    Resource unavailable; Retry again after pending
17526  *                       request completes.
17527  *      ADV_ERROR(-1) -  Invalid ADV_SCSI_REQ_Q request structure
17528  *                       host IC error.
17529  */
17530 STATIC int
17531 AdvExeScsiQueue(ADV_DVC_VAR *asc_dvc,
17532                 ADV_SCSI_REQ_Q *scsiq)
17533 {
17534     ulong                  last_int_level;
17535     AdvPortAddr            iop_base;
17536     ADV_DCNT               req_size;
17537     ADV_PADDR              req_paddr;
17538     ADV_CARR_T             *new_carrp;
17539
17540     ASC_ASSERT(scsiq != NULL); /* 'scsiq' should never be NULL. */
17541
17542     /*
17543      * The ADV_SCSI_REQ_Q 'target_id' field should never exceed ADV_MAX_TID.
17544      */
17545     if (scsiq->target_id > ADV_MAX_TID)
17546     {
17547         scsiq->host_status = QHSTA_M_INVALID_DEVICE;
17548         scsiq->done_status = QD_WITH_ERROR;
17549         return ADV_ERROR;
17550     }
17551
17552     iop_base = asc_dvc->iop_base;
17553
17554     last_int_level = DvcEnterCritical();
17555
17556     /*
17557      * Allocate a carrier ensuring at least one carrier always
17558      * remains on the freelist and initialize fields.
17559      */
17560     if ((new_carrp = asc_dvc->carr_freelist) == NULL)
17561     {
17562        DvcLeaveCritical(last_int_level);
17563        return ADV_BUSY;
17564     }
17565     asc_dvc->carr_freelist = (ADV_CARR_T *)
17566         ADV_U32_TO_VADDR(le32_to_cpu(new_carrp->next_vpa));
17567     asc_dvc->carr_pending_cnt++;
17568
17569     /*
17570      * Set the carrier to be a stopper by setting 'next_vpa'
17571      * to the stopper value. The current stopper will be changed
17572      * below to point to the new stopper.
17573      */
17574     new_carrp->next_vpa = cpu_to_le32(ASC_CQ_STOPPER);
17575
17576     /*
17577      * Clear the ADV_SCSI_REQ_Q done flag.
17578      */
17579     scsiq->a_flag &= ~ADV_SCSIQ_DONE;
17580
17581     req_size = sizeof(ADV_SCSI_REQ_Q);
17582     req_paddr = DvcGetPhyAddr(asc_dvc, scsiq, (uchar *) scsiq,
17583         (ADV_SDCNT *) &req_size, ADV_IS_SCSIQ_FLAG);
17584
17585     ASC_ASSERT(ADV_32BALIGN(req_paddr) == req_paddr);
17586     ASC_ASSERT(req_size >= sizeof(ADV_SCSI_REQ_Q));
17587
17588     /* Wait for assertion before making little-endian */
17589     req_paddr = cpu_to_le32(req_paddr);
17590
17591     /* Save virtual and physical address of ADV_SCSI_REQ_Q and carrier. */
17592     scsiq->scsiq_ptr = cpu_to_le32(ADV_VADDR_TO_U32(scsiq));
17593     scsiq->scsiq_rptr = req_paddr;
17594
17595     scsiq->carr_va = cpu_to_le32(ADV_VADDR_TO_U32(asc_dvc->icq_sp));
17596     /*
17597      * Every ADV_CARR_T.carr_pa is byte swapped to little-endian
17598      * order during initialization.
17599      */
17600     scsiq->carr_pa = asc_dvc->icq_sp->carr_pa;
17601
17602    /*
17603     * Use the current stopper to send the ADV_SCSI_REQ_Q command to
17604     * the microcode. The newly allocated stopper will become the new
17605     * stopper.
17606     */
17607     asc_dvc->icq_sp->areq_vpa = req_paddr;
17608
17609     /*
17610      * Set the 'next_vpa' pointer for the old stopper to be the
17611      * physical address of the new stopper. The RISC can only
17612      * follow physical addresses.
17613      */
17614     asc_dvc->icq_sp->next_vpa = new_carrp->carr_pa;
17615
17616     /*
17617      * Set the host adapter stopper pointer to point to the new carrier.
17618      */
17619     asc_dvc->icq_sp = new_carrp;
17620
17621     if (asc_dvc->chip_type == ADV_CHIP_ASC3550 ||
17622         asc_dvc->chip_type == ADV_CHIP_ASC38C0800)
17623     {
17624         /*
17625          * Tickle the RISC to tell it to read its Command Queue Head pointer.
17626          */
17627         AdvWriteByteRegister(iop_base, IOPB_TICKLE, ADV_TICKLE_A);
17628         if (asc_dvc->chip_type == ADV_CHIP_ASC3550)
17629         {
17630             /*
17631              * Clear the tickle value. In the ASC-3550 the RISC flag
17632              * command 'clr_tickle_a' does not work unless the host
17633              * value is cleared.
17634              */
17635             AdvWriteByteRegister(iop_base, IOPB_TICKLE, ADV_TICKLE_NOP);
17636         }
17637     } else if (asc_dvc->chip_type == ADV_CHIP_ASC38C1600)
17638     {
17639         /*
17640          * Notify the RISC a carrier is ready by writing the physical
17641          * address of the new carrier stopper to the COMMA register.
17642          */
17643         AdvWriteDWordRegister(iop_base, IOPDW_COMMA,
17644                 le32_to_cpu(new_carrp->carr_pa));
17645     }
17646
17647     DvcLeaveCritical(last_int_level);
17648
17649     return ADV_SUCCESS;
17650 }
17651
17652 /*
17653  * Reset SCSI Bus and purge all outstanding requests.
17654  *
17655  * Return Value:
17656  *      ADV_TRUE(1) -   All requests are purged and SCSI Bus is reset.
17657  *      ADV_FALSE(0) -  Microcode command failed.
17658  *      ADV_ERROR(-1) - Microcode command timed-out. Microcode or IC
17659  *                      may be hung which requires driver recovery.
17660  */
17661 STATIC int
17662 AdvResetSB(ADV_DVC_VAR *asc_dvc)
17663 {
17664     int         status;
17665
17666     /*
17667      * Send the SCSI Bus Reset idle start idle command which asserts
17668      * the SCSI Bus Reset signal.
17669      */
17670     status = AdvSendIdleCmd(asc_dvc, (ushort) IDLE_CMD_SCSI_RESET_START, 0L);
17671     if (status != ADV_TRUE)
17672     {
17673         return status;
17674     }
17675
17676     /*
17677      * Delay for the specified SCSI Bus Reset hold time.
17678      *
17679      * The hold time delay is done on the host because the RISC has no
17680      * microsecond accurate timer.
17681      */
17682     DvcDelayMicroSecond(asc_dvc, (ushort) ASC_SCSI_RESET_HOLD_TIME_US);
17683
17684     /*
17685      * Send the SCSI Bus Reset end idle command which de-asserts
17686      * the SCSI Bus Reset signal and purges any pending requests.
17687      */
17688     status = AdvSendIdleCmd(asc_dvc, (ushort) IDLE_CMD_SCSI_RESET_END, 0L);
17689     if (status != ADV_TRUE)
17690     {
17691         return status;
17692     }
17693
17694     DvcSleepMilliSecond((ADV_DCNT) asc_dvc->scsi_reset_wait * 1000);
17695
17696     return status;
17697 }
17698
17699 /*
17700  * Reset chip and SCSI Bus.
17701  *
17702  * Return Value:
17703  *      ADV_TRUE(1) -   Chip re-initialization and SCSI Bus Reset successful.
17704  *      ADV_FALSE(0) -  Chip re-initialization and SCSI Bus Reset failure.
17705  */
17706 STATIC int
17707 AdvResetChipAndSB(ADV_DVC_VAR *asc_dvc)
17708 {
17709     int         status;
17710     ushort      wdtr_able, sdtr_able, tagqng_able;
17711     ushort      ppr_able = 0;
17712     uchar       tid, max_cmd[ADV_MAX_TID + 1];
17713     AdvPortAddr iop_base;
17714     ushort      bios_sig;
17715
17716     iop_base = asc_dvc->iop_base;
17717
17718     /*
17719      * Save current per TID negotiated values.
17720      */
17721     AdvReadWordLram(iop_base, ASC_MC_WDTR_ABLE, wdtr_able);
17722     AdvReadWordLram(iop_base, ASC_MC_SDTR_ABLE, sdtr_able);
17723     if (asc_dvc->chip_type == ADV_CHIP_ASC38C1600)
17724     {
17725         AdvReadWordLram(iop_base, ASC_MC_PPR_ABLE, ppr_able);
17726     }
17727     AdvReadWordLram(iop_base, ASC_MC_TAGQNG_ABLE, tagqng_able);
17728     for (tid = 0; tid <= ADV_MAX_TID; tid++)
17729     {
17730         AdvReadByteLram(iop_base, ASC_MC_NUMBER_OF_MAX_CMD + tid,
17731             max_cmd[tid]);
17732     }
17733
17734     /*
17735      * Force the AdvInitAsc3550/38C0800Driver() function to
17736      * perform a SCSI Bus Reset by clearing the BIOS signature word.
17737      * The initialization functions assumes a SCSI Bus Reset is not
17738      * needed if the BIOS signature word is present.
17739      */
17740     AdvReadWordLram(iop_base, ASC_MC_BIOS_SIGNATURE, bios_sig);
17741     AdvWriteWordLram(iop_base, ASC_MC_BIOS_SIGNATURE, 0);
17742
17743     /*
17744      * Stop chip and reset it.
17745      */
17746     AdvWriteWordRegister(iop_base, IOPW_RISC_CSR, ADV_RISC_CSR_STOP);
17747     AdvWriteWordRegister(iop_base, IOPW_CTRL_REG, ADV_CTRL_REG_CMD_RESET);
17748     DvcSleepMilliSecond(100);
17749     AdvWriteWordRegister(iop_base, IOPW_CTRL_REG, ADV_CTRL_REG_CMD_WR_IO_REG);
17750
17751     /*
17752      * Reset Adv Library error code, if any, and try
17753      * re-initializing the chip.
17754      */
17755     asc_dvc->err_code = 0;
17756     if (asc_dvc->chip_type == ADV_CHIP_ASC38C1600)
17757     {
17758         status = AdvInitAsc38C1600Driver(asc_dvc);
17759     }
17760     else if (asc_dvc->chip_type == ADV_CHIP_ASC38C0800)
17761     {
17762         status = AdvInitAsc38C0800Driver(asc_dvc);
17763     } else
17764     {
17765         status = AdvInitAsc3550Driver(asc_dvc);
17766     }
17767
17768     /* Translate initialization return value to status value. */
17769     if (status == 0)
17770     {
17771         status = ADV_TRUE;
17772     } else
17773     {
17774         status = ADV_FALSE;
17775     }
17776
17777     /*
17778      * Restore the BIOS signature word.
17779      */
17780     AdvWriteWordLram(iop_base, ASC_MC_BIOS_SIGNATURE, bios_sig);
17781
17782     /*
17783      * Restore per TID negotiated values.
17784      */
17785     AdvWriteWordLram(iop_base, ASC_MC_WDTR_ABLE, wdtr_able);
17786     AdvWriteWordLram(iop_base, ASC_MC_SDTR_ABLE, sdtr_able);
17787     if (asc_dvc->chip_type == ADV_CHIP_ASC38C1600)
17788     {
17789         AdvWriteWordLram(iop_base, ASC_MC_PPR_ABLE, ppr_able);
17790     }
17791     AdvWriteWordLram(iop_base, ASC_MC_TAGQNG_ABLE, tagqng_able);
17792     for (tid = 0; tid <= ADV_MAX_TID; tid++)
17793     {
17794         AdvWriteByteLram(iop_base, ASC_MC_NUMBER_OF_MAX_CMD + tid,
17795             max_cmd[tid]);
17796     }
17797
17798     return status;
17799 }
17800
17801 /*
17802  * Adv Library Interrupt Service Routine
17803  *
17804  *  This function is called by a driver's interrupt service routine.
17805  *  The function disables and re-enables interrupts.
17806  *
17807  *  When a microcode idle command is completed, the ADV_DVC_VAR
17808  *  'idle_cmd_done' field is set to ADV_TRUE.
17809  *
17810  *  Note: AdvISR() can be called when interrupts are disabled or even
17811  *  when there is no hardware interrupt condition present. It will
17812  *  always check for completed idle commands and microcode requests.
17813  *  This is an important feature that shouldn't be changed because it
17814  *  allows commands to be completed from polling mode loops.
17815  *
17816  * Return:
17817  *   ADV_TRUE(1) - interrupt was pending
17818  *   ADV_FALSE(0) - no interrupt was pending
17819  */
17820 STATIC int
17821 AdvISR(ADV_DVC_VAR *asc_dvc)
17822 {
17823     AdvPortAddr                 iop_base;
17824     uchar                       int_stat;
17825     ushort                      target_bit;
17826     ADV_CARR_T                  *free_carrp;
17827     ADV_VADDR                   irq_next_vpa;
17828     int                         flags;
17829     ADV_SCSI_REQ_Q              *scsiq;
17830
17831     flags = DvcEnterCritical();
17832
17833     iop_base = asc_dvc->iop_base;
17834
17835     /* Reading the register clears the interrupt. */
17836     int_stat = AdvReadByteRegister(iop_base, IOPB_INTR_STATUS_REG);
17837
17838     if ((int_stat & (ADV_INTR_STATUS_INTRA | ADV_INTR_STATUS_INTRB |
17839          ADV_INTR_STATUS_INTRC)) == 0)
17840     {
17841         DvcLeaveCritical(flags);
17842         return ADV_FALSE;
17843     }
17844
17845     /*
17846      * Notify the driver of an asynchronous microcode condition by
17847      * calling the ADV_DVC_VAR.async_callback function. The function
17848      * is passed the microcode ASC_MC_INTRB_CODE byte value.
17849      */
17850     if (int_stat & ADV_INTR_STATUS_INTRB)
17851     {
17852         uchar intrb_code;
17853
17854         AdvReadByteLram(iop_base, ASC_MC_INTRB_CODE, intrb_code);
17855
17856         if (asc_dvc->chip_type == ADV_CHIP_ASC3550 ||
17857             asc_dvc->chip_type == ADV_CHIP_ASC38C0800)
17858         {
17859             if (intrb_code == ADV_ASYNC_CARRIER_READY_FAILURE &&
17860                 asc_dvc->carr_pending_cnt != 0)
17861             {
17862                 AdvWriteByteRegister(iop_base, IOPB_TICKLE, ADV_TICKLE_A);
17863                 if (asc_dvc->chip_type == ADV_CHIP_ASC3550)
17864                 {
17865                     AdvWriteByteRegister(iop_base, IOPB_TICKLE, ADV_TICKLE_NOP);
17866                 }
17867             }
17868         }
17869
17870         if (asc_dvc->async_callback != 0)
17871         {
17872             (*asc_dvc->async_callback)(asc_dvc, intrb_code);
17873         }
17874     }
17875
17876     /*
17877      * Check if the IRQ stopper carrier contains a completed request.
17878      */
17879     while (((irq_next_vpa =
17880              le32_to_cpu(asc_dvc->irq_sp->next_vpa)) & ASC_RQ_DONE) != 0)
17881     {
17882         /*
17883          * Get a pointer to the newly completed ADV_SCSI_REQ_Q structure.
17884          * The RISC will have set 'areq_vpa' to a virtual address.
17885          *
17886          * The firmware will have copied the ASC_SCSI_REQ_Q.scsiq_ptr
17887          * field to the carrier ADV_CARR_T.areq_vpa field. The conversion
17888          * below complements the conversion of ASC_SCSI_REQ_Q.scsiq_ptr'
17889          * in AdvExeScsiQueue().
17890          */
17891         scsiq = (ADV_SCSI_REQ_Q *)
17892             ADV_U32_TO_VADDR(le32_to_cpu(asc_dvc->irq_sp->areq_vpa));
17893
17894         /*
17895          * Request finished with good status and the queue was not
17896          * DMAed to host memory by the firmware. Set all status fields
17897          * to indicate good status.
17898          */
17899         if ((irq_next_vpa & ASC_RQ_GOOD) != 0)
17900         {
17901             scsiq->done_status = QD_NO_ERROR;
17902             scsiq->host_status = scsiq->scsi_status = 0;
17903             scsiq->data_cnt = 0L;
17904         }
17905
17906         /*
17907          * Advance the stopper pointer to the next carrier
17908          * ignoring the lower four bits. Free the previous
17909          * stopper carrier.
17910          */
17911         free_carrp = asc_dvc->irq_sp;
17912         asc_dvc->irq_sp = (ADV_CARR_T *)
17913             ADV_U32_TO_VADDR(ASC_GET_CARRP(irq_next_vpa));
17914
17915         free_carrp->next_vpa =
17916                 cpu_to_le32(ADV_VADDR_TO_U32(asc_dvc->carr_freelist));
17917         asc_dvc->carr_freelist = free_carrp;
17918         asc_dvc->carr_pending_cnt--;
17919
17920         ASC_ASSERT(scsiq != NULL);
17921         target_bit = ADV_TID_TO_TIDMASK(scsiq->target_id);
17922
17923         /*
17924          * Clear request microcode control flag.
17925          */
17926         scsiq->cntl = 0;
17927
17928         /*
17929          * If the command that completed was a SCSI INQUIRY and
17930          * LUN 0 was sent the command, then process the INQUIRY
17931          * command information for the device.
17932          *
17933          * Note: If data returned were either VPD or CmdDt data,
17934          * don't process the INQUIRY command information for
17935          * the device, otherwise may erroneously set *_able bits.
17936          */
17937         if (scsiq->done_status == QD_NO_ERROR &&
17938             scsiq->cdb[0] == INQUIRY &&
17939             scsiq->target_lun == 0 &&
17940             (scsiq->cdb[1] & ADV_INQ_RTN_VPD_AND_CMDDT)
17941                 == ADV_INQ_RTN_STD_INQUIRY_DATA)
17942         {
17943             AdvInquiryHandling(asc_dvc, scsiq);
17944         }
17945
17946         /*
17947          * Notify the driver of the completed request by passing
17948          * the ADV_SCSI_REQ_Q pointer to its callback function.
17949          */
17950         scsiq->a_flag |= ADV_SCSIQ_DONE;
17951         (*asc_dvc->isr_callback)(asc_dvc, scsiq);
17952         /*
17953          * Note: After the driver callback function is called, 'scsiq'
17954          * can no longer be referenced.
17955          *
17956          * Fall through and continue processing other completed
17957          * requests...
17958          */
17959
17960         /*
17961          * Disable interrupts again in case the driver inadvertently
17962          * enabled interrupts in its callback function.
17963          *
17964          * The DvcEnterCritical() return value is ignored, because
17965          * the 'flags' saved when AdvISR() was first entered will be
17966          * used to restore the interrupt flag on exit.
17967          */
17968         (void) DvcEnterCritical();
17969     }
17970     DvcLeaveCritical(flags);
17971     return ADV_TRUE;
17972 }
17973
17974 /*
17975  * Send an idle command to the chip and wait for completion.
17976  *
17977  * Command completion is polled for once per microsecond.
17978  *
17979  * The function can be called from anywhere including an interrupt handler.
17980  * But the function is not re-entrant, so it uses the DvcEnter/LeaveCritical()
17981  * functions to prevent reentrancy.
17982  *
17983  * Return Values:
17984  *   ADV_TRUE - command completed successfully
17985  *   ADV_FALSE - command failed
17986  *   ADV_ERROR - command timed out
17987  */
17988 STATIC int
17989 AdvSendIdleCmd(ADV_DVC_VAR *asc_dvc,
17990                ushort idle_cmd,
17991                ADV_DCNT idle_cmd_parameter)
17992 {
17993     ulong       last_int_level;
17994     int         result;
17995     ADV_DCNT    i, j;
17996     AdvPortAddr iop_base;
17997
17998     last_int_level = DvcEnterCritical();
17999
18000     iop_base = asc_dvc->iop_base;
18001
18002     /*
18003      * Clear the idle command status which is set by the microcode
18004      * to a non-zero value to indicate when the command is completed.
18005      * The non-zero result is one of the IDLE_CMD_STATUS_* values
18006      * defined in a_advlib.h.
18007      */
18008     AdvWriteWordLram(iop_base, ASC_MC_IDLE_CMD_STATUS, (ushort) 0);
18009
18010     /*
18011      * Write the idle command value after the idle command parameter
18012      * has been written to avoid a race condition. If the order is not
18013      * followed, the microcode may process the idle command before the
18014      * parameters have been written to LRAM.
18015      */
18016     AdvWriteDWordLramNoSwap(iop_base, ASC_MC_IDLE_CMD_PARAMETER,
18017         cpu_to_le32(idle_cmd_parameter));
18018     AdvWriteWordLram(iop_base, ASC_MC_IDLE_CMD, idle_cmd);
18019
18020     /*
18021      * Tickle the RISC to tell it to process the idle command.
18022      */
18023     AdvWriteByteRegister(iop_base, IOPB_TICKLE, ADV_TICKLE_B);
18024     if (asc_dvc->chip_type == ADV_CHIP_ASC3550)
18025     {
18026         /*
18027          * Clear the tickle value. In the ASC-3550 the RISC flag
18028          * command 'clr_tickle_b' does not work unless the host
18029          * value is cleared.
18030          */
18031         AdvWriteByteRegister(iop_base, IOPB_TICKLE, ADV_TICKLE_NOP);
18032     }
18033
18034     /* Wait for up to 100 millisecond for the idle command to timeout. */
18035     for (i = 0; i < SCSI_WAIT_100_MSEC; i++)
18036     {
18037         /* Poll once each microsecond for command completion. */
18038         for (j = 0; j < SCSI_US_PER_MSEC; j++)
18039         {
18040             AdvReadWordLram(iop_base, ASC_MC_IDLE_CMD_STATUS, result);
18041             if (result != 0)
18042             {
18043                 DvcLeaveCritical(last_int_level);
18044                 return result;
18045             }
18046             DvcDelayMicroSecond(asc_dvc, (ushort) 1);
18047         }
18048     }
18049
18050     ASC_ASSERT(0); /* The idle command should never timeout. */
18051     DvcLeaveCritical(last_int_level);
18052     return ADV_ERROR;
18053 }
18054
18055 /*
18056  * Inquiry Information Byte 7 Handling
18057  *
18058  * Handle SCSI Inquiry Command information for a device by setting
18059  * microcode operating variables that affect WDTR, SDTR, and Tag
18060  * Queuing.
18061  */
18062 STATIC void
18063 AdvInquiryHandling(
18064     ADV_DVC_VAR                 *asc_dvc,
18065     ADV_SCSI_REQ_Q              *scsiq)
18066 {
18067     AdvPortAddr                 iop_base;
18068     uchar                       tid;
18069     ADV_SCSI_INQUIRY            *inq;
18070     ushort                      tidmask;
18071     ushort                      cfg_word;
18072
18073     /*
18074      * AdvInquiryHandling() requires up to INQUIRY information Byte 7
18075      * to be available.
18076      *
18077      * If less than 8 bytes of INQUIRY information were requested or less
18078      * than 8 bytes were transferred, then return. cdb[4] is the request
18079      * length and the ADV_SCSI_REQ_Q 'data_cnt' field is set by the
18080      * microcode to the transfer residual count.
18081      */
18082
18083     if (scsiq->cdb[4] < 8 ||
18084         (scsiq->cdb[4] - le32_to_cpu(scsiq->data_cnt)) < 8)
18085     {
18086         return;
18087     }
18088
18089     iop_base = asc_dvc->iop_base;
18090     tid = scsiq->target_id;
18091
18092     inq = (ADV_SCSI_INQUIRY *) scsiq->vdata_addr;
18093
18094     /*
18095      * WDTR, SDTR, and Tag Queuing cannot be enabled for old devices.
18096      */
18097     if (ADV_INQ_RESPONSE_FMT(inq) < 2 && ADV_INQ_ANSI_VER(inq) < 2)
18098     {
18099         return;
18100     } else
18101     {
18102         /*
18103          * INQUIRY Byte 7 Handling
18104          *
18105          * Use a device's INQUIRY byte 7 to determine whether it
18106          * supports WDTR, SDTR, and Tag Queuing. If the feature
18107          * is enabled in the EEPROM and the device supports the
18108          * feature, then enable it in the microcode.
18109          */
18110
18111         tidmask = ADV_TID_TO_TIDMASK(tid);
18112
18113         /*
18114          * Wide Transfers
18115          *
18116          * If the EEPROM enabled WDTR for the device and the device
18117          * supports wide bus (16 bit) transfers, then turn on the
18118          * device's 'wdtr_able' bit and write the new value to the
18119          * microcode.
18120          */
18121         if ((asc_dvc->wdtr_able & tidmask) && ADV_INQ_WIDE16(inq))
18122         {
18123             AdvReadWordLram(iop_base, ASC_MC_WDTR_ABLE, cfg_word);
18124             if ((cfg_word & tidmask) == 0)
18125             {
18126                 cfg_word |= tidmask;
18127                 AdvWriteWordLram(iop_base, ASC_MC_WDTR_ABLE, cfg_word);
18128
18129                 /*
18130                  * Clear the microcode "SDTR negotiation" and "WDTR
18131                  * negotiation" done indicators for the target to cause
18132                  * it to negotiate with the new setting set above.
18133                  * WDTR when accepted causes the target to enter
18134                  * asynchronous mode, so SDTR must be negotiated.
18135                  */
18136                 AdvReadWordLram(iop_base, ASC_MC_SDTR_DONE, cfg_word);
18137                 cfg_word &= ~tidmask;
18138                 AdvWriteWordLram(iop_base, ASC_MC_SDTR_DONE, cfg_word);
18139                 AdvReadWordLram(iop_base, ASC_MC_WDTR_DONE, cfg_word);
18140                 cfg_word &= ~tidmask;
18141                 AdvWriteWordLram(iop_base, ASC_MC_WDTR_DONE, cfg_word);
18142             }
18143         }
18144
18145         /*
18146          * Synchronous Transfers
18147          *
18148          * If the EEPROM enabled SDTR for the device and the device
18149          * supports synchronous transfers, then turn on the device's
18150          * 'sdtr_able' bit. Write the new value to the microcode.
18151          */
18152         if ((asc_dvc->sdtr_able & tidmask) && ADV_INQ_SYNC(inq))
18153         {
18154             AdvReadWordLram(iop_base, ASC_MC_SDTR_ABLE, cfg_word);
18155             if ((cfg_word & tidmask) == 0)
18156             {
18157                 cfg_word |= tidmask;
18158                 AdvWriteWordLram(iop_base, ASC_MC_SDTR_ABLE, cfg_word);
18159
18160                 /*
18161                  * Clear the microcode "SDTR negotiation" done indicator
18162                  * for the target to cause it to negotiate with the new
18163                  * setting set above.
18164                  */
18165                 AdvReadWordLram(iop_base, ASC_MC_SDTR_DONE, cfg_word);
18166                 cfg_word &= ~tidmask;
18167                 AdvWriteWordLram(iop_base, ASC_MC_SDTR_DONE, cfg_word);
18168             }
18169         }
18170         /*
18171          * If the Inquiry data included enough space for the SPI-3
18172          * Clocking field, then check if DT mode is supported.
18173          */
18174         if (asc_dvc->chip_type == ADV_CHIP_ASC38C1600 &&
18175             (scsiq->cdb[4] >= 57 ||
18176             (scsiq->cdb[4] - le32_to_cpu(scsiq->data_cnt)) >= 57))
18177         {
18178             /*
18179              * PPR (Parallel Protocol Request) Capable
18180              *
18181              * If the device supports DT mode, then it must be PPR capable.
18182              * The PPR message will be used in place of the SDTR and WDTR
18183              * messages to negotiate synchronous speed and offset, transfer
18184              * width, and protocol options.
18185              */
18186             if (ADV_INQ_CLOCKING(inq) & ADV_INQ_CLOCKING_DT_ONLY)
18187             {
18188                 AdvReadWordLram(iop_base, ASC_MC_PPR_ABLE, asc_dvc->ppr_able);
18189                 asc_dvc->ppr_able |= tidmask;
18190                 AdvWriteWordLram(iop_base, ASC_MC_PPR_ABLE, asc_dvc->ppr_able);
18191             }
18192         }
18193
18194         /*
18195          * If the EEPROM enabled Tag Queuing for the device and the
18196          * device supports Tag Queueing, then turn on the device's
18197          * 'tagqng_enable' bit in the microcode and set the microcode
18198          * maximum command count to the ADV_DVC_VAR 'max_dvc_qng'
18199          * value.
18200          *
18201          * Tag Queuing is disabled for the BIOS which runs in polled
18202          * mode and would see no benefit from Tag Queuing. Also by
18203          * disabling Tag Queuing in the BIOS devices with Tag Queuing
18204          * bugs will at least work with the BIOS.
18205          */
18206         if ((asc_dvc->tagqng_able & tidmask) && ADV_INQ_CMD_QUEUE(inq))
18207         {
18208             AdvReadWordLram(iop_base, ASC_MC_TAGQNG_ABLE, cfg_word);
18209             cfg_word |= tidmask;
18210             AdvWriteWordLram(iop_base, ASC_MC_TAGQNG_ABLE, cfg_word);
18211
18212             AdvWriteByteLram(iop_base, ASC_MC_NUMBER_OF_MAX_CMD + tid,
18213                 asc_dvc->max_dvc_qng);
18214         }
18215     }
18216 }
18217 MODULE_LICENSE("Dual BSD/GPL");
18218
18219 /* PCI Devices supported by this driver */
18220 static struct pci_device_id advansys_pci_tbl[] __devinitdata = {
18221         { PCI_VENDOR_ID_ASP, PCI_DEVICE_ID_ASP_1200A,
18222         PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0},
18223         { PCI_VENDOR_ID_ASP, PCI_DEVICE_ID_ASP_ABP940,
18224         PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0},
18225         { PCI_VENDOR_ID_ASP, PCI_DEVICE_ID_ASP_ABP940U,
18226         PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0},
18227         { PCI_VENDOR_ID_ASP, PCI_DEVICE_ID_ASP_ABP940UW,
18228         PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0},
18229         { PCI_VENDOR_ID_ASP, PCI_DEVICE_ID_38C0800_REV1,
18230         PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0},
18231         { PCI_VENDOR_ID_ASP, PCI_DEVICE_ID_38C1600_REV1,
18232         PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0},
18233         { }
18234 };
18235 MODULE_DEVICE_TABLE(pci, advansys_pci_tbl);
18236