vserver 1.9.3
[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 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 '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 <philip.blundell@pobox.com> 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.h>
800 #include <scsi/scsi_host.h>
801 #include "advansys.h"
802 #ifdef CONFIG_PCI
803 #include <linux/pci.h>
804 #endif /* CONFIG_PCI */
805
806
807 /*
808  * --- Driver Options
809  */
810
811 /* Enable driver assertions. */
812 #define ADVANSYS_ASSERT
813
814 /* Enable driver /proc statistics. */
815 #define ADVANSYS_STATS
816
817 /* Enable driver tracing. */
818 /* #define ADVANSYS_DEBUG */
819
820
821 /*
822  * --- Debugging Header
823  */
824
825 #ifdef ADVANSYS_DEBUG
826 #define STATIC
827 #else /* ADVANSYS_DEBUG */
828 #define STATIC static
829 #endif /* ADVANSYS_DEBUG */
830
831
832 /*
833  * --- Asc Library Constants and Macros
834  */
835
836 #define ASC_LIB_VERSION_MAJOR  1
837 #define ASC_LIB_VERSION_MINOR  24
838 #define ASC_LIB_SERIAL_NUMBER  123
839
840 /*
841  * Portable Data Types
842  *
843  * Any instance where a 32-bit long or pointer type is assumed
844  * for precision or HW defined structures, the following define
845  * types must be used. In Linux the char, short, and int types
846  * are all consistent at 8, 16, and 32 bits respectively. Pointers
847  * and long types are 64 bits on Alpha and UltraSPARC.
848  */
849 #define ASC_PADDR __u32         /* Physical/Bus address data type. */
850 #define ASC_VADDR __u32         /* Virtual address data type. */
851 #define ASC_DCNT  __u32         /* Unsigned Data count type. */
852 #define ASC_SDCNT __s32         /* Signed Data count type. */
853
854 /*
855  * These macros are used to convert a virtual address to a
856  * 32-bit value. This currently can be used on Linux Alpha
857  * which uses 64-bit virtual address but a 32-bit bus address.
858  * This is likely to break in the future, but doing this now
859  * will give us time to change the HW and FW to handle 64-bit
860  * addresses.
861  */
862 #define ASC_VADDR_TO_U32   virt_to_bus
863 #define ASC_U32_TO_VADDR   bus_to_virt
864
865 typedef unsigned char uchar;
866
867 #ifndef TRUE
868 #define TRUE     (1)
869 #endif
870 #ifndef FALSE
871 #define FALSE    (0)
872 #endif
873
874 #define EOF      (-1)
875 #define ERR      (-1)
876 #define UW_ERR   (uint)(0xFFFF)
877 #define isodd_word(val)   ((((uint)val) & (uint)0x0001) != 0)
878 #define AscPCIConfigVendorIDRegister      0x0000
879 #define AscPCIConfigDeviceIDRegister      0x0002
880 #define AscPCIConfigCommandRegister       0x0004
881 #define AscPCIConfigStatusRegister        0x0006
882 #define AscPCIConfigRevisionIDRegister    0x0008
883 #define AscPCIConfigCacheSize             0x000C
884 #define AscPCIConfigLatencyTimer          0x000D
885 #define AscPCIIOBaseRegister              0x0010
886 #define AscPCICmdRegBits_IOMemBusMaster   0x0007
887 #define ASC_PCI_ID2BUS(id)    ((id) & 0xFF)
888 #define ASC_PCI_ID2DEV(id)    (((id) >> 11) & 0x1F)
889 #define ASC_PCI_ID2FUNC(id)   (((id) >> 8) & 0x7)
890 #define ASC_PCI_MKID(bus, dev, func) ((((dev) & 0x1F) << 11) | (((func) & 0x7) << 8) | ((bus) & 0xFF))
891 #define ASC_PCI_VENDORID                  0x10CD
892 #define ASC_PCI_DEVICEID_1200A            0x1100
893 #define ASC_PCI_DEVICEID_1200B            0x1200
894 #define ASC_PCI_DEVICEID_ULTRA            0x1300
895 #define ASC_PCI_REVISION_3150             0x02
896 #define ASC_PCI_REVISION_3050             0x03
897
898 #define  ASC_DVCLIB_CALL_DONE     (1)
899 #define  ASC_DVCLIB_CALL_FAILED   (0)
900 #define  ASC_DVCLIB_CALL_ERROR    (-1)
901
902 /*
903  * Enable CC_VERY_LONG_SG_LIST to support up to 64K element SG lists.
904  * The SRB structure will have to be changed and the ASC_SRB2SCSIQ()
905  * macro re-defined to be able to obtain a ASC_SCSI_Q pointer from the
906  * SRB structure.
907  */
908 #define CC_VERY_LONG_SG_LIST 0
909 #define ASC_SRB2SCSIQ(srb_ptr)  (srb_ptr)
910
911 #define PortAddr                 unsigned short    /* port address size  */
912 #define inp(port)                inb(port)
913 #define outp(port, byte)         outb((byte), (port))
914
915 #define inpw(port)               inw(port)
916 #define outpw(port, word)        outw((word), (port))
917
918 #define ASC_MAX_SG_QUEUE    7
919 #define ASC_MAX_SG_LIST     255
920
921 #define ASC_CS_TYPE  unsigned short
922
923 #define ASC_IS_ISA          (0x0001)
924 #define ASC_IS_ISAPNP       (0x0081)
925 #define ASC_IS_EISA         (0x0002)
926 #define ASC_IS_PCI          (0x0004)
927 #define ASC_IS_PCI_ULTRA    (0x0104)
928 #define ASC_IS_PCMCIA       (0x0008)
929 #define ASC_IS_MCA          (0x0020)
930 #define ASC_IS_VL           (0x0040)
931 #define ASC_ISA_PNP_PORT_ADDR  (0x279)
932 #define ASC_ISA_PNP_PORT_WRITE (ASC_ISA_PNP_PORT_ADDR+0x800)
933 #define ASC_IS_WIDESCSI_16  (0x0100)
934 #define ASC_IS_WIDESCSI_32  (0x0200)
935 #define ASC_IS_BIG_ENDIAN   (0x8000)
936 #define ASC_CHIP_MIN_VER_VL      (0x01)
937 #define ASC_CHIP_MAX_VER_VL      (0x07)
938 #define ASC_CHIP_MIN_VER_PCI     (0x09)
939 #define ASC_CHIP_MAX_VER_PCI     (0x0F)
940 #define ASC_CHIP_VER_PCI_BIT     (0x08)
941 #define ASC_CHIP_MIN_VER_ISA     (0x11)
942 #define ASC_CHIP_MIN_VER_ISA_PNP (0x21)
943 #define ASC_CHIP_MAX_VER_ISA     (0x27)
944 #define ASC_CHIP_VER_ISA_BIT     (0x30)
945 #define ASC_CHIP_VER_ISAPNP_BIT  (0x20)
946 #define ASC_CHIP_VER_ASYN_BUG    (0x21)
947 #define ASC_CHIP_VER_PCI             0x08
948 #define ASC_CHIP_VER_PCI_ULTRA_3150  (ASC_CHIP_VER_PCI | 0x02)
949 #define ASC_CHIP_VER_PCI_ULTRA_3050  (ASC_CHIP_VER_PCI | 0x03)
950 #define ASC_CHIP_MIN_VER_EISA (0x41)
951 #define ASC_CHIP_MAX_VER_EISA (0x47)
952 #define ASC_CHIP_VER_EISA_BIT (0x40)
953 #define ASC_CHIP_LATEST_VER_EISA   ((ASC_CHIP_MIN_VER_EISA - 1) + 3)
954 #define ASC_MAX_LIB_SUPPORTED_ISA_CHIP_VER   0x21
955 #define ASC_MAX_LIB_SUPPORTED_PCI_CHIP_VER   0x0A
956 #define ASC_MAX_VL_DMA_ADDR     (0x07FFFFFFL)
957 #define ASC_MAX_VL_DMA_COUNT    (0x07FFFFFFL)
958 #define ASC_MAX_PCI_DMA_ADDR    (0xFFFFFFFFL)
959 #define ASC_MAX_PCI_DMA_COUNT   (0xFFFFFFFFL)
960 #define ASC_MAX_ISA_DMA_ADDR    (0x00FFFFFFL)
961 #define ASC_MAX_ISA_DMA_COUNT   (0x00FFFFFFL)
962 #define ASC_MAX_EISA_DMA_ADDR   (0x07FFFFFFL)
963 #define ASC_MAX_EISA_DMA_COUNT  (0x07FFFFFFL)
964
965 #define ASC_SCSI_ID_BITS  3
966 #define ASC_SCSI_TIX_TYPE     uchar
967 #define ASC_ALL_DEVICE_BIT_SET  0xFF
968 #define ASC_SCSI_BIT_ID_TYPE  uchar
969 #define ASC_MAX_TID       7
970 #define ASC_MAX_LUN       7
971 #define ASC_SCSI_WIDTH_BIT_SET  0xFF
972 #define ASC_MAX_SENSE_LEN   32
973 #define ASC_MIN_SENSE_LEN   14
974 #define ASC_MAX_CDB_LEN     12
975 #define ASC_SCSI_RESET_HOLD_TIME_US  60
976
977 #define ADV_INQ_CLOCKING_ST_ONLY    0x0
978 #define ADV_INQ_CLOCKING_DT_ONLY    0x1
979 #define ADV_INQ_CLOCKING_ST_AND_DT  0x3
980
981 /*
982  * Inquiry SPC-2 SPI Byte 1 EVPD (Enable Vital Product Data)
983  * and CmdDt (Command Support Data) field bit definitions.
984  */
985 #define ADV_INQ_RTN_VPD_AND_CMDDT           0x3
986 #define ADV_INQ_RTN_CMDDT_FOR_OP_CODE       0x2
987 #define ADV_INQ_RTN_VPD_FOR_PG_CODE         0x1
988 #define ADV_INQ_RTN_STD_INQUIRY_DATA        0x0
989
990 #define ASC_SCSIDIR_NOCHK    0x00
991 #define ASC_SCSIDIR_T2H      0x08
992 #define ASC_SCSIDIR_H2T      0x10
993 #define ASC_SCSIDIR_NODATA   0x18
994 #define SCSI_ASC_NOMEDIA          0x3A
995 #define ASC_SRB_HOST(x)  ((uchar)((uchar)(x) >> 4))
996 #define ASC_SRB_TID(x)   ((uchar)((uchar)(x) & (uchar)0x0F))
997 #define ASC_SRB_LUN(x)   ((uchar)((uint)(x) >> 13))
998 #define PUT_CDB1(x)   ((uchar)((uint)(x) >> 8))
999 #define MS_CMD_DONE    0x00
1000 #define MS_EXTEND      0x01
1001 #define MS_SDTR_LEN    0x03
1002 #define MS_SDTR_CODE   0x01
1003 #define MS_WDTR_LEN    0x02
1004 #define MS_WDTR_CODE   0x03
1005 #define MS_MDP_LEN    0x05
1006 #define MS_MDP_CODE   0x00
1007
1008 /*
1009  * Inquiry data structure and bitfield macros
1010  *
1011  * Only quantities of more than 1 bit are shifted, since the others are
1012  * just tested for true or false. C bitfields aren't portable between big
1013  * and little-endian platforms so they are not used.
1014  */
1015
1016 #define ASC_INQ_DVC_TYPE(inq)       ((inq)->periph & 0x1f)
1017 #define ASC_INQ_QUALIFIER(inq)      (((inq)->periph & 0xe0) >> 5)
1018 #define ASC_INQ_DVC_TYPE_MOD(inq)   ((inq)->devtype & 0x7f)
1019 #define ASC_INQ_REMOVABLE(inq)      ((inq)->devtype & 0x80)
1020 #define ASC_INQ_ANSI_VER(inq)       ((inq)->ver & 0x07)
1021 #define ASC_INQ_ECMA_VER(inq)       (((inq)->ver & 0x38) >> 3)
1022 #define ASC_INQ_ISO_VER(inq)        (((inq)->ver & 0xc0) >> 6)
1023 #define ASC_INQ_RESPONSE_FMT(inq)   ((inq)->byte3 & 0x0f)
1024 #define ASC_INQ_TERM_IO(inq)        ((inq)->byte3 & 0x40)
1025 #define ASC_INQ_ASYNC_NOTIF(inq)    ((inq)->byte3 & 0x80)
1026 #define ASC_INQ_SOFT_RESET(inq)     ((inq)->flags & 0x01)
1027 #define ASC_INQ_CMD_QUEUE(inq)      ((inq)->flags & 0x02)
1028 #define ASC_INQ_LINK_CMD(inq)       ((inq)->flags & 0x08)
1029 #define ASC_INQ_SYNC(inq)           ((inq)->flags & 0x10)
1030 #define ASC_INQ_WIDE16(inq)         ((inq)->flags & 0x20)
1031 #define ASC_INQ_WIDE32(inq)         ((inq)->flags & 0x40)
1032 #define ASC_INQ_REL_ADDR(inq)       ((inq)->flags & 0x80)
1033 #define ASC_INQ_INFO_UNIT(inq)      ((inq)->info & 0x01)
1034 #define ASC_INQ_QUICK_ARB(inq)      ((inq)->info & 0x02)
1035 #define ASC_INQ_CLOCKING(inq)       (((inq)->info & 0x0c) >> 2)
1036
1037 typedef struct {
1038     uchar               periph;
1039     uchar               devtype;
1040     uchar               ver;
1041     uchar               byte3;
1042     uchar               add_len;
1043     uchar               res1;
1044     uchar               res2;
1045     uchar               flags;
1046     uchar               vendor_id[8];
1047     uchar               product_id[16];
1048     uchar               product_rev_level[4];
1049 } ASC_SCSI_INQUIRY;
1050
1051 #define ASC_SG_LIST_PER_Q   7
1052 #define QS_FREE        0x00
1053 #define QS_READY       0x01
1054 #define QS_DISC1       0x02
1055 #define QS_DISC2       0x04
1056 #define QS_BUSY        0x08
1057 #define QS_ABORTED     0x40
1058 #define QS_DONE        0x80
1059 #define QC_NO_CALLBACK   0x01
1060 #define QC_SG_SWAP_QUEUE 0x02
1061 #define QC_SG_HEAD       0x04
1062 #define QC_DATA_IN       0x08
1063 #define QC_DATA_OUT      0x10
1064 #define QC_URGENT        0x20
1065 #define QC_MSG_OUT       0x40
1066 #define QC_REQ_SENSE     0x80
1067 #define QCSG_SG_XFER_LIST  0x02
1068 #define QCSG_SG_XFER_MORE  0x04
1069 #define QCSG_SG_XFER_END   0x08
1070 #define QD_IN_PROGRESS       0x00
1071 #define QD_NO_ERROR          0x01
1072 #define QD_ABORTED_BY_HOST   0x02
1073 #define QD_WITH_ERROR        0x04
1074 #define QD_INVALID_REQUEST   0x80
1075 #define QD_INVALID_HOST_NUM  0x81
1076 #define QD_INVALID_DEVICE    0x82
1077 #define QD_ERR_INTERNAL      0xFF
1078 #define QHSTA_NO_ERROR               0x00
1079 #define QHSTA_M_SEL_TIMEOUT          0x11
1080 #define QHSTA_M_DATA_OVER_RUN        0x12
1081 #define QHSTA_M_DATA_UNDER_RUN       0x12
1082 #define QHSTA_M_UNEXPECTED_BUS_FREE  0x13
1083 #define QHSTA_M_BAD_BUS_PHASE_SEQ    0x14
1084 #define QHSTA_D_QDONE_SG_LIST_CORRUPTED 0x21
1085 #define QHSTA_D_ASC_DVC_ERROR_CODE_SET  0x22
1086 #define QHSTA_D_HOST_ABORT_FAILED       0x23
1087 #define QHSTA_D_EXE_SCSI_Q_FAILED       0x24
1088 #define QHSTA_D_EXE_SCSI_Q_BUSY_TIMEOUT 0x25
1089 #define QHSTA_D_ASPI_NO_BUF_POOL        0x26
1090 #define QHSTA_M_WTM_TIMEOUT         0x41
1091 #define QHSTA_M_BAD_CMPL_STATUS_IN  0x42
1092 #define QHSTA_M_NO_AUTO_REQ_SENSE   0x43
1093 #define QHSTA_M_AUTO_REQ_SENSE_FAIL 0x44
1094 #define QHSTA_M_TARGET_STATUS_BUSY  0x45
1095 #define QHSTA_M_BAD_TAG_CODE        0x46
1096 #define QHSTA_M_BAD_QUEUE_FULL_OR_BUSY  0x47
1097 #define QHSTA_M_HUNG_REQ_SCSI_BUS_RESET 0x48
1098 #define QHSTA_D_LRAM_CMP_ERROR        0x81
1099 #define QHSTA_M_MICRO_CODE_ERROR_HALT 0xA1
1100 #define ASC_FLAG_SCSIQ_REQ        0x01
1101 #define ASC_FLAG_BIOS_SCSIQ_REQ   0x02
1102 #define ASC_FLAG_BIOS_ASYNC_IO    0x04
1103 #define ASC_FLAG_SRB_LINEAR_ADDR  0x08
1104 #define ASC_FLAG_WIN16            0x10
1105 #define ASC_FLAG_WIN32            0x20
1106 #define ASC_FLAG_ISA_OVER_16MB    0x40
1107 #define ASC_FLAG_DOS_VM_CALLBACK  0x80
1108 #define ASC_TAG_FLAG_EXTRA_BYTES               0x10
1109 #define ASC_TAG_FLAG_DISABLE_DISCONNECT        0x04
1110 #define ASC_TAG_FLAG_DISABLE_ASYN_USE_SYN_FIX  0x08
1111 #define ASC_TAG_FLAG_DISABLE_CHK_COND_INT_HOST 0x40
1112 #define ASC_SCSIQ_CPY_BEG              4
1113 #define ASC_SCSIQ_SGHD_CPY_BEG         2
1114 #define ASC_SCSIQ_B_FWD                0
1115 #define ASC_SCSIQ_B_BWD                1
1116 #define ASC_SCSIQ_B_STATUS             2
1117 #define ASC_SCSIQ_B_QNO                3
1118 #define ASC_SCSIQ_B_CNTL               4
1119 #define ASC_SCSIQ_B_SG_QUEUE_CNT       5
1120 #define ASC_SCSIQ_D_DATA_ADDR          8
1121 #define ASC_SCSIQ_D_DATA_CNT          12
1122 #define ASC_SCSIQ_B_SENSE_LEN         20
1123 #define ASC_SCSIQ_DONE_INFO_BEG       22
1124 #define ASC_SCSIQ_D_SRBPTR            22
1125 #define ASC_SCSIQ_B_TARGET_IX         26
1126 #define ASC_SCSIQ_B_CDB_LEN           28
1127 #define ASC_SCSIQ_B_TAG_CODE          29
1128 #define ASC_SCSIQ_W_VM_ID             30
1129 #define ASC_SCSIQ_DONE_STATUS         32
1130 #define ASC_SCSIQ_HOST_STATUS         33
1131 #define ASC_SCSIQ_SCSI_STATUS         34
1132 #define ASC_SCSIQ_CDB_BEG             36
1133 #define ASC_SCSIQ_DW_REMAIN_XFER_ADDR 56
1134 #define ASC_SCSIQ_DW_REMAIN_XFER_CNT  60
1135 #define ASC_SCSIQ_B_FIRST_SG_WK_QP    48
1136 #define ASC_SCSIQ_B_SG_WK_QP          49
1137 #define ASC_SCSIQ_B_SG_WK_IX          50
1138 #define ASC_SCSIQ_W_ALT_DC1           52
1139 #define ASC_SCSIQ_B_LIST_CNT          6
1140 #define ASC_SCSIQ_B_CUR_LIST_CNT      7
1141 #define ASC_SGQ_B_SG_CNTL             4
1142 #define ASC_SGQ_B_SG_HEAD_QP          5
1143 #define ASC_SGQ_B_SG_LIST_CNT         6
1144 #define ASC_SGQ_B_SG_CUR_LIST_CNT     7
1145 #define ASC_SGQ_LIST_BEG              8
1146 #define ASC_DEF_SCSI1_QNG    4
1147 #define ASC_MAX_SCSI1_QNG    4
1148 #define ASC_DEF_SCSI2_QNG    16
1149 #define ASC_MAX_SCSI2_QNG    32
1150 #define ASC_TAG_CODE_MASK    0x23
1151 #define ASC_STOP_REQ_RISC_STOP      0x01
1152 #define ASC_STOP_ACK_RISC_STOP      0x03
1153 #define ASC_STOP_CLEAN_UP_BUSY_Q    0x10
1154 #define ASC_STOP_CLEAN_UP_DISC_Q    0x20
1155 #define ASC_STOP_HOST_REQ_RISC_HALT 0x40
1156 #define ASC_TIDLUN_TO_IX(tid, lun)  (ASC_SCSI_TIX_TYPE)((tid) + ((lun)<<ASC_SCSI_ID_BITS))
1157 #define ASC_TID_TO_TARGET_ID(tid)   (ASC_SCSI_BIT_ID_TYPE)(0x01 << (tid))
1158 #define ASC_TIX_TO_TARGET_ID(tix)   (0x01 << ((tix) & ASC_MAX_TID))
1159 #define ASC_TIX_TO_TID(tix)         ((tix) & ASC_MAX_TID)
1160 #define ASC_TID_TO_TIX(tid)         ((tid) & ASC_MAX_TID)
1161 #define ASC_TIX_TO_LUN(tix)         (((tix) >> ASC_SCSI_ID_BITS) & ASC_MAX_LUN)
1162 #define ASC_QNO_TO_QADDR(q_no)      ((ASC_QADR_BEG)+((int)(q_no) << 6))
1163
1164 typedef struct asc_scsiq_1 {
1165     uchar               status;
1166     uchar               q_no;
1167     uchar               cntl;
1168     uchar               sg_queue_cnt;
1169     uchar               target_id;
1170     uchar               target_lun;
1171     ASC_PADDR           data_addr;
1172     ASC_DCNT            data_cnt;
1173     ASC_PADDR           sense_addr;
1174     uchar               sense_len;
1175     uchar               extra_bytes;
1176 } ASC_SCSIQ_1;
1177
1178 typedef struct asc_scsiq_2 {
1179     ASC_VADDR           srb_ptr;
1180     uchar               target_ix;
1181     uchar               flag;
1182     uchar               cdb_len;
1183     uchar               tag_code;
1184     ushort              vm_id;
1185 } ASC_SCSIQ_2;
1186
1187 typedef struct asc_scsiq_3 {
1188     uchar               done_stat;
1189     uchar               host_stat;
1190     uchar               scsi_stat;
1191     uchar               scsi_msg;
1192 } ASC_SCSIQ_3;
1193
1194 typedef struct asc_scsiq_4 {
1195     uchar               cdb[ASC_MAX_CDB_LEN];
1196     uchar               y_first_sg_list_qp;
1197     uchar               y_working_sg_qp;
1198     uchar               y_working_sg_ix;
1199     uchar               y_res;
1200     ushort              x_req_count;
1201     ushort              x_reconnect_rtn;
1202     ASC_PADDR           x_saved_data_addr;
1203     ASC_DCNT            x_saved_data_cnt;
1204 } ASC_SCSIQ_4;
1205
1206 typedef struct asc_q_done_info {
1207     ASC_SCSIQ_2         d2;
1208     ASC_SCSIQ_3         d3;
1209     uchar               q_status;
1210     uchar               q_no;
1211     uchar               cntl;
1212     uchar               sense_len;
1213     uchar               extra_bytes;
1214     uchar               res;
1215     ASC_DCNT            remain_bytes;
1216 } ASC_QDONE_INFO;
1217
1218 typedef struct asc_sg_list {
1219     ASC_PADDR           addr;
1220     ASC_DCNT            bytes;
1221 } ASC_SG_LIST;
1222
1223 typedef struct asc_sg_head {
1224     ushort              entry_cnt;
1225     ushort              queue_cnt;
1226     ushort              entry_to_copy;
1227     ushort              res;
1228     ASC_SG_LIST         sg_list[ASC_MAX_SG_LIST];
1229 } ASC_SG_HEAD;
1230
1231 #define ASC_MIN_SG_LIST   2
1232
1233 typedef struct asc_min_sg_head {
1234     ushort              entry_cnt;
1235     ushort              queue_cnt;
1236     ushort              entry_to_copy;
1237     ushort              res;
1238     ASC_SG_LIST         sg_list[ASC_MIN_SG_LIST];
1239 } ASC_MIN_SG_HEAD;
1240
1241 #define QCX_SORT        (0x0001)
1242 #define QCX_COALEASE    (0x0002)
1243
1244 typedef struct asc_scsi_q {
1245     ASC_SCSIQ_1         q1;
1246     ASC_SCSIQ_2         q2;
1247     uchar               *cdbptr;
1248     ASC_SG_HEAD         *sg_head;
1249     ushort              remain_sg_entry_cnt;
1250     ushort              next_sg_index;
1251 } ASC_SCSI_Q;
1252
1253 typedef struct asc_scsi_req_q {
1254     ASC_SCSIQ_1         r1;
1255     ASC_SCSIQ_2         r2;
1256     uchar               *cdbptr;
1257     ASC_SG_HEAD         *sg_head;
1258     uchar               *sense_ptr;
1259     ASC_SCSIQ_3         r3;
1260     uchar               cdb[ASC_MAX_CDB_LEN];
1261     uchar               sense[ASC_MIN_SENSE_LEN];
1262 } ASC_SCSI_REQ_Q;
1263
1264 typedef struct asc_scsi_bios_req_q {
1265     ASC_SCSIQ_1         r1;
1266     ASC_SCSIQ_2         r2;
1267     uchar               *cdbptr;
1268     ASC_SG_HEAD         *sg_head;
1269     uchar               *sense_ptr;
1270     ASC_SCSIQ_3         r3;
1271     uchar               cdb[ASC_MAX_CDB_LEN];
1272     uchar               sense[ASC_MIN_SENSE_LEN];
1273 } ASC_SCSI_BIOS_REQ_Q;
1274
1275 typedef struct asc_risc_q {
1276     uchar               fwd;
1277     uchar               bwd;
1278     ASC_SCSIQ_1         i1;
1279     ASC_SCSIQ_2         i2;
1280     ASC_SCSIQ_3         i3;
1281     ASC_SCSIQ_4         i4;
1282 } ASC_RISC_Q;
1283
1284 typedef struct asc_sg_list_q {
1285     uchar               seq_no;
1286     uchar               q_no;
1287     uchar               cntl;
1288     uchar               sg_head_qp;
1289     uchar               sg_list_cnt;
1290     uchar               sg_cur_list_cnt;
1291 } ASC_SG_LIST_Q;
1292
1293 typedef struct asc_risc_sg_list_q {
1294     uchar               fwd;
1295     uchar               bwd;
1296     ASC_SG_LIST_Q       sg;
1297     ASC_SG_LIST         sg_list[7];
1298 } ASC_RISC_SG_LIST_Q;
1299
1300 #define ASC_EXE_SCSI_IO_MAX_IDLE_LOOP  0x1000000UL
1301 #define ASC_EXE_SCSI_IO_MAX_WAIT_LOOP  1024
1302 #define ASCQ_ERR_NO_ERROR             0
1303 #define ASCQ_ERR_IO_NOT_FOUND         1
1304 #define ASCQ_ERR_LOCAL_MEM            2
1305 #define ASCQ_ERR_CHKSUM               3
1306 #define ASCQ_ERR_START_CHIP           4
1307 #define ASCQ_ERR_INT_TARGET_ID        5
1308 #define ASCQ_ERR_INT_LOCAL_MEM        6
1309 #define ASCQ_ERR_HALT_RISC            7
1310 #define ASCQ_ERR_GET_ASPI_ENTRY       8
1311 #define ASCQ_ERR_CLOSE_ASPI           9
1312 #define ASCQ_ERR_HOST_INQUIRY         0x0A
1313 #define ASCQ_ERR_SAVED_SRB_BAD        0x0B
1314 #define ASCQ_ERR_QCNTL_SG_LIST        0x0C
1315 #define ASCQ_ERR_Q_STATUS             0x0D
1316 #define ASCQ_ERR_WR_SCSIQ             0x0E
1317 #define ASCQ_ERR_PC_ADDR              0x0F
1318 #define ASCQ_ERR_SYN_OFFSET           0x10
1319 #define ASCQ_ERR_SYN_XFER_TIME        0x11
1320 #define ASCQ_ERR_LOCK_DMA             0x12
1321 #define ASCQ_ERR_UNLOCK_DMA           0x13
1322 #define ASCQ_ERR_VDS_CHK_INSTALL      0x14
1323 #define ASCQ_ERR_MICRO_CODE_HALT      0x15
1324 #define ASCQ_ERR_SET_LRAM_ADDR        0x16
1325 #define ASCQ_ERR_CUR_QNG              0x17
1326 #define ASCQ_ERR_SG_Q_LINKS           0x18
1327 #define ASCQ_ERR_SCSIQ_PTR            0x19
1328 #define ASCQ_ERR_ISR_RE_ENTRY         0x1A
1329 #define ASCQ_ERR_CRITICAL_RE_ENTRY    0x1B
1330 #define ASCQ_ERR_ISR_ON_CRITICAL      0x1C
1331 #define ASCQ_ERR_SG_LIST_ODD_ADDRESS  0x1D
1332 #define ASCQ_ERR_XFER_ADDRESS_TOO_BIG 0x1E
1333 #define ASCQ_ERR_SCSIQ_NULL_PTR       0x1F
1334 #define ASCQ_ERR_SCSIQ_BAD_NEXT_PTR   0x20
1335 #define ASCQ_ERR_GET_NUM_OF_FREE_Q    0x21
1336 #define ASCQ_ERR_SEND_SCSI_Q          0x22
1337 #define ASCQ_ERR_HOST_REQ_RISC_HALT   0x23
1338 #define ASCQ_ERR_RESET_SDTR           0x24
1339
1340 /*
1341  * Warning code values are set in ASC_DVC_VAR  'warn_code'.
1342  */
1343 #define ASC_WARN_NO_ERROR             0x0000
1344 #define ASC_WARN_IO_PORT_ROTATE       0x0001
1345 #define ASC_WARN_EEPROM_CHKSUM        0x0002
1346 #define ASC_WARN_IRQ_MODIFIED         0x0004
1347 #define ASC_WARN_AUTO_CONFIG          0x0008
1348 #define ASC_WARN_CMD_QNG_CONFLICT     0x0010
1349 #define ASC_WARN_EEPROM_RECOVER       0x0020
1350 #define ASC_WARN_CFG_MSW_RECOVER      0x0040
1351 #define ASC_WARN_SET_PCI_CONFIG_SPACE 0x0080
1352
1353 /*
1354  * Error code values are set in ASC_DVC_VAR  'err_code'.
1355  */
1356 #define ASC_IERR_WRITE_EEPROM         0x0001
1357 #define ASC_IERR_MCODE_CHKSUM         0x0002
1358 #define ASC_IERR_SET_PC_ADDR          0x0004
1359 #define ASC_IERR_START_STOP_CHIP      0x0008
1360 #define ASC_IERR_IRQ_NO               0x0010
1361 #define ASC_IERR_SET_IRQ_NO           0x0020
1362 #define ASC_IERR_CHIP_VERSION         0x0040
1363 #define ASC_IERR_SET_SCSI_ID          0x0080
1364 #define ASC_IERR_GET_PHY_ADDR         0x0100
1365 #define ASC_IERR_BAD_SIGNATURE        0x0200
1366 #define ASC_IERR_NO_BUS_TYPE          0x0400
1367 #define ASC_IERR_SCAM                 0x0800
1368 #define ASC_IERR_SET_SDTR             0x1000
1369 #define ASC_IERR_RW_LRAM              0x8000
1370
1371 #define ASC_DEF_IRQ_NO  10
1372 #define ASC_MAX_IRQ_NO  15
1373 #define ASC_MIN_IRQ_NO  10
1374 #define ASC_MIN_REMAIN_Q        (0x02)
1375 #define ASC_DEF_MAX_TOTAL_QNG   (0xF0)
1376 #define ASC_MIN_TAG_Q_PER_DVC   (0x04)
1377 #define ASC_DEF_TAG_Q_PER_DVC   (0x04)
1378 #define ASC_MIN_FREE_Q        ASC_MIN_REMAIN_Q
1379 #define ASC_MIN_TOTAL_QNG     ((ASC_MAX_SG_QUEUE)+(ASC_MIN_FREE_Q))
1380 #define ASC_MAX_TOTAL_QNG 240
1381 #define ASC_MAX_PCI_ULTRA_INRAM_TOTAL_QNG 16
1382 #define ASC_MAX_PCI_ULTRA_INRAM_TAG_QNG   8
1383 #define ASC_MAX_PCI_INRAM_TOTAL_QNG  20
1384 #define ASC_MAX_INRAM_TAG_QNG   16
1385 #define ASC_IOADR_TABLE_MAX_IX  11
1386 #define ASC_IOADR_GAP   0x10
1387 #define ASC_SEARCH_IOP_GAP 0x10
1388 #define ASC_MIN_IOP_ADDR   (PortAddr)0x0100
1389 #define ASC_MAX_IOP_ADDR   (PortAddr)0x3F0
1390 #define ASC_IOADR_1     (PortAddr)0x0110
1391 #define ASC_IOADR_2     (PortAddr)0x0130
1392 #define ASC_IOADR_3     (PortAddr)0x0150
1393 #define ASC_IOADR_4     (PortAddr)0x0190
1394 #define ASC_IOADR_5     (PortAddr)0x0210
1395 #define ASC_IOADR_6     (PortAddr)0x0230
1396 #define ASC_IOADR_7     (PortAddr)0x0250
1397 #define ASC_IOADR_8     (PortAddr)0x0330
1398 #define ASC_IOADR_DEF   ASC_IOADR_8
1399 #define ASC_LIB_SCSIQ_WK_SP        256
1400 #define ASC_MAX_SYN_XFER_NO        16
1401 #define ASC_SYN_MAX_OFFSET         0x0F
1402 #define ASC_DEF_SDTR_OFFSET        0x0F
1403 #define ASC_DEF_SDTR_INDEX         0x00
1404 #define ASC_SDTR_ULTRA_PCI_10MB_INDEX  0x02
1405 #define SYN_XFER_NS_0  25
1406 #define SYN_XFER_NS_1  30
1407 #define SYN_XFER_NS_2  35
1408 #define SYN_XFER_NS_3  40
1409 #define SYN_XFER_NS_4  50
1410 #define SYN_XFER_NS_5  60
1411 #define SYN_XFER_NS_6  70
1412 #define SYN_XFER_NS_7  85
1413 #define SYN_ULTRA_XFER_NS_0    12
1414 #define SYN_ULTRA_XFER_NS_1    19
1415 #define SYN_ULTRA_XFER_NS_2    25
1416 #define SYN_ULTRA_XFER_NS_3    32
1417 #define SYN_ULTRA_XFER_NS_4    38
1418 #define SYN_ULTRA_XFER_NS_5    44
1419 #define SYN_ULTRA_XFER_NS_6    50
1420 #define SYN_ULTRA_XFER_NS_7    57
1421 #define SYN_ULTRA_XFER_NS_8    63
1422 #define SYN_ULTRA_XFER_NS_9    69
1423 #define SYN_ULTRA_XFER_NS_10   75
1424 #define SYN_ULTRA_XFER_NS_11   82
1425 #define SYN_ULTRA_XFER_NS_12   88
1426 #define SYN_ULTRA_XFER_NS_13   94
1427 #define SYN_ULTRA_XFER_NS_14  100
1428 #define SYN_ULTRA_XFER_NS_15  107
1429
1430 typedef struct ext_msg {
1431     uchar               msg_type;
1432     uchar               msg_len;
1433     uchar               msg_req;
1434     union {
1435         struct {
1436             uchar               sdtr_xfer_period;
1437             uchar               sdtr_req_ack_offset;
1438         } sdtr;
1439         struct {
1440             uchar               wdtr_width;
1441         } wdtr;
1442         struct {
1443             uchar               mdp_b3;
1444             uchar               mdp_b2;
1445             uchar               mdp_b1;
1446             uchar               mdp_b0;
1447         } mdp;
1448     } u_ext_msg;
1449     uchar               res;
1450 } EXT_MSG;
1451
1452 #define xfer_period     u_ext_msg.sdtr.sdtr_xfer_period
1453 #define req_ack_offset  u_ext_msg.sdtr.sdtr_req_ack_offset
1454 #define wdtr_width      u_ext_msg.wdtr.wdtr_width
1455 #define mdp_b3          u_ext_msg.mdp_b3
1456 #define mdp_b2          u_ext_msg.mdp_b2
1457 #define mdp_b1          u_ext_msg.mdp_b1
1458 #define mdp_b0          u_ext_msg.mdp_b0
1459
1460 typedef struct asc_dvc_cfg {
1461     ASC_SCSI_BIT_ID_TYPE can_tagged_qng;
1462     ASC_SCSI_BIT_ID_TYPE cmd_qng_enabled;
1463     ASC_SCSI_BIT_ID_TYPE disc_enable;
1464     ASC_SCSI_BIT_ID_TYPE sdtr_enable;
1465     uchar               chip_scsi_id;
1466     uchar               isa_dma_speed;
1467     uchar               isa_dma_channel;
1468     uchar               chip_version;
1469     ushort              lib_serial_no;
1470     ushort              lib_version;
1471     ushort              mcode_date;
1472     ushort              mcode_version;
1473     uchar               max_tag_qng[ASC_MAX_TID + 1];
1474     uchar               *overrun_buf;
1475     uchar               sdtr_period_offset[ASC_MAX_TID + 1];
1476     ushort              pci_slot_info;
1477     uchar               adapter_info[6];
1478     struct device       *dev;
1479 } ASC_DVC_CFG;
1480
1481 #define ASC_DEF_DVC_CNTL       0xFFFF
1482 #define ASC_DEF_CHIP_SCSI_ID   7
1483 #define ASC_DEF_ISA_DMA_SPEED  4
1484 #define ASC_INIT_STATE_NULL          0x0000
1485 #define ASC_INIT_STATE_BEG_GET_CFG   0x0001
1486 #define ASC_INIT_STATE_END_GET_CFG   0x0002
1487 #define ASC_INIT_STATE_BEG_SET_CFG   0x0004
1488 #define ASC_INIT_STATE_END_SET_CFG   0x0008
1489 #define ASC_INIT_STATE_BEG_LOAD_MC   0x0010
1490 #define ASC_INIT_STATE_END_LOAD_MC   0x0020
1491 #define ASC_INIT_STATE_BEG_INQUIRY   0x0040
1492 #define ASC_INIT_STATE_END_INQUIRY   0x0080
1493 #define ASC_INIT_RESET_SCSI_DONE     0x0100
1494 #define ASC_INIT_STATE_WITHOUT_EEP   0x8000
1495 #define ASC_PCI_DEVICE_ID_REV_A      0x1100
1496 #define ASC_PCI_DEVICE_ID_REV_B      0x1200
1497 #define ASC_BUG_FIX_IF_NOT_DWB       0x0001
1498 #define ASC_BUG_FIX_ASYN_USE_SYN     0x0002
1499 #define ASYN_SDTR_DATA_FIX_PCI_REV_AB 0x41
1500 #define ASC_MIN_TAGGED_CMD  7
1501 #define ASC_MAX_SCSI_RESET_WAIT      30
1502
1503 struct asc_dvc_var;     /* Forward Declaration. */
1504
1505 typedef void (* ASC_ISR_CALLBACK)(struct asc_dvc_var *, ASC_QDONE_INFO *);
1506 typedef int (* ASC_EXE_CALLBACK)(struct asc_dvc_var *, ASC_SCSI_Q *);
1507
1508 typedef struct asc_dvc_var {
1509     PortAddr            iop_base;
1510     ushort              err_code;
1511     ushort              dvc_cntl;
1512     ushort              bug_fix_cntl;
1513     ushort              bus_type;
1514     ASC_ISR_CALLBACK    isr_callback;
1515     ASC_EXE_CALLBACK    exe_callback;
1516     ASC_SCSI_BIT_ID_TYPE init_sdtr;
1517     ASC_SCSI_BIT_ID_TYPE sdtr_done;
1518     ASC_SCSI_BIT_ID_TYPE use_tagged_qng;
1519     ASC_SCSI_BIT_ID_TYPE unit_not_ready;
1520     ASC_SCSI_BIT_ID_TYPE queue_full_or_busy;
1521     ASC_SCSI_BIT_ID_TYPE start_motor;
1522     uchar               scsi_reset_wait;
1523     uchar               chip_no;
1524     char                is_in_int;
1525     uchar               max_total_qng;
1526     uchar               cur_total_qng;
1527     uchar               in_critical_cnt;
1528     uchar               irq_no;
1529     uchar               last_q_shortage;
1530     ushort              init_state;
1531     uchar               cur_dvc_qng[ASC_MAX_TID + 1];
1532     uchar               max_dvc_qng[ASC_MAX_TID + 1];
1533     ASC_SCSI_Q  *scsiq_busy_head[ASC_MAX_TID + 1];
1534     ASC_SCSI_Q  *scsiq_busy_tail[ASC_MAX_TID + 1];
1535     uchar               sdtr_period_tbl[ASC_MAX_SYN_XFER_NO];
1536     ASC_DVC_CFG *cfg;
1537     ASC_SCSI_BIT_ID_TYPE pci_fix_asyn_xfer_always;
1538     char                redo_scam;
1539     ushort              res2;
1540     uchar               dos_int13_table[ASC_MAX_TID + 1];
1541     ASC_DCNT            max_dma_count;
1542     ASC_SCSI_BIT_ID_TYPE no_scam;
1543     ASC_SCSI_BIT_ID_TYPE pci_fix_asyn_xfer;
1544     uchar               max_sdtr_index;
1545     uchar               host_init_sdtr_index;
1546     struct asc_board    *drv_ptr;
1547     ASC_DCNT            uc_break;
1548 } ASC_DVC_VAR;
1549
1550 typedef struct asc_dvc_inq_info {
1551     uchar               type[ASC_MAX_TID + 1][ASC_MAX_LUN + 1];
1552 } ASC_DVC_INQ_INFO;
1553
1554 typedef struct asc_cap_info {
1555     ASC_DCNT            lba;
1556     ASC_DCNT            blk_size;
1557 } ASC_CAP_INFO;
1558
1559 typedef struct asc_cap_info_array {
1560     ASC_CAP_INFO        cap_info[ASC_MAX_TID + 1][ASC_MAX_LUN + 1];
1561 } ASC_CAP_INFO_ARRAY;
1562
1563 #define ASC_MCNTL_NO_SEL_TIMEOUT  (ushort)0x0001
1564 #define ASC_MCNTL_NULL_TARGET     (ushort)0x0002
1565 #define ASC_CNTL_INITIATOR         (ushort)0x0001
1566 #define ASC_CNTL_BIOS_GT_1GB       (ushort)0x0002
1567 #define ASC_CNTL_BIOS_GT_2_DISK    (ushort)0x0004
1568 #define ASC_CNTL_BIOS_REMOVABLE    (ushort)0x0008
1569 #define ASC_CNTL_NO_SCAM           (ushort)0x0010
1570 #define ASC_CNTL_INT_MULTI_Q       (ushort)0x0080
1571 #define ASC_CNTL_NO_LUN_SUPPORT    (ushort)0x0040
1572 #define ASC_CNTL_NO_VERIFY_COPY    (ushort)0x0100
1573 #define ASC_CNTL_RESET_SCSI        (ushort)0x0200
1574 #define ASC_CNTL_INIT_INQUIRY      (ushort)0x0400
1575 #define ASC_CNTL_INIT_VERBOSE      (ushort)0x0800
1576 #define ASC_CNTL_SCSI_PARITY       (ushort)0x1000
1577 #define ASC_CNTL_BURST_MODE        (ushort)0x2000
1578 #define ASC_CNTL_SDTR_ENABLE_ULTRA (ushort)0x4000
1579 #define ASC_EEP_DVC_CFG_BEG_VL    2
1580 #define ASC_EEP_MAX_DVC_ADDR_VL   15
1581 #define ASC_EEP_DVC_CFG_BEG      32
1582 #define ASC_EEP_MAX_DVC_ADDR     45
1583 #define ASC_EEP_DEFINED_WORDS    10
1584 #define ASC_EEP_MAX_ADDR         63
1585 #define ASC_EEP_RES_WORDS         0
1586 #define ASC_EEP_MAX_RETRY        20
1587 #define ASC_MAX_INIT_BUSY_RETRY   8
1588 #define ASC_EEP_ISA_PNP_WSIZE    16
1589
1590 /*
1591  * These macros keep the chip SCSI id and ISA DMA speed
1592  * bitfields in board order. C bitfields aren't portable
1593  * between big and little-endian platforms so they are
1594  * not used.
1595  */
1596
1597 #define ASC_EEP_GET_CHIP_ID(cfg)    ((cfg)->id_speed & 0x0f)
1598 #define ASC_EEP_GET_DMA_SPD(cfg)    (((cfg)->id_speed & 0xf0) >> 4)
1599 #define ASC_EEP_SET_CHIP_ID(cfg, sid) \
1600    ((cfg)->id_speed = ((cfg)->id_speed & 0xf0) | ((sid) & ASC_MAX_TID))
1601 #define ASC_EEP_SET_DMA_SPD(cfg, spd) \
1602    ((cfg)->id_speed = ((cfg)->id_speed & 0x0f) | ((spd) & 0x0f) << 4)
1603
1604 typedef struct asceep_config {
1605     ushort              cfg_lsw;
1606     ushort              cfg_msw;
1607     uchar               init_sdtr;
1608     uchar               disc_enable;
1609     uchar               use_cmd_qng;
1610     uchar               start_motor;
1611     uchar               max_total_qng;
1612     uchar               max_tag_qng;
1613     uchar               bios_scan;
1614     uchar               power_up_wait;
1615     uchar               no_scam;
1616     uchar               id_speed; /* low order 4 bits is chip scsi id */
1617                                   /* high order 4 bits is isa dma speed */
1618     uchar               dos_int13_table[ASC_MAX_TID + 1];
1619     uchar               adapter_info[6];
1620     ushort              cntl;
1621     ushort              chksum;
1622 } ASCEEP_CONFIG;
1623
1624 #define ASC_PCI_CFG_LSW_SCSI_PARITY  0x0800
1625 #define ASC_PCI_CFG_LSW_BURST_MODE   0x0080
1626 #define ASC_PCI_CFG_LSW_INTR_ABLE    0x0020
1627
1628 #define ASC_EEP_CMD_READ          0x80
1629 #define ASC_EEP_CMD_WRITE         0x40
1630 #define ASC_EEP_CMD_WRITE_ABLE    0x30
1631 #define ASC_EEP_CMD_WRITE_DISABLE 0x00
1632 #define ASC_OVERRUN_BSIZE  0x00000048UL
1633 #define ASC_CTRL_BREAK_ONCE        0x0001
1634 #define ASC_CTRL_BREAK_STAY_IDLE   0x0002
1635 #define ASCV_MSGOUT_BEG         0x0000
1636 #define ASCV_MSGOUT_SDTR_PERIOD (ASCV_MSGOUT_BEG+3)
1637 #define ASCV_MSGOUT_SDTR_OFFSET (ASCV_MSGOUT_BEG+4)
1638 #define ASCV_BREAK_SAVED_CODE   (ushort)0x0006
1639 #define ASCV_MSGIN_BEG          (ASCV_MSGOUT_BEG+8)
1640 #define ASCV_MSGIN_SDTR_PERIOD  (ASCV_MSGIN_BEG+3)
1641 #define ASCV_MSGIN_SDTR_OFFSET  (ASCV_MSGIN_BEG+4)
1642 #define ASCV_SDTR_DATA_BEG      (ASCV_MSGIN_BEG+8)
1643 #define ASCV_SDTR_DONE_BEG      (ASCV_SDTR_DATA_BEG+8)
1644 #define ASCV_MAX_DVC_QNG_BEG    (ushort)0x0020
1645 #define ASCV_BREAK_ADDR           (ushort)0x0028
1646 #define ASCV_BREAK_NOTIFY_COUNT   (ushort)0x002A
1647 #define ASCV_BREAK_CONTROL        (ushort)0x002C
1648 #define ASCV_BREAK_HIT_COUNT      (ushort)0x002E
1649
1650 #define ASCV_ASCDVC_ERR_CODE_W  (ushort)0x0030
1651 #define ASCV_MCODE_CHKSUM_W   (ushort)0x0032
1652 #define ASCV_MCODE_SIZE_W     (ushort)0x0034
1653 #define ASCV_STOP_CODE_B      (ushort)0x0036
1654 #define ASCV_DVC_ERR_CODE_B   (ushort)0x0037
1655 #define ASCV_OVERRUN_PADDR_D  (ushort)0x0038
1656 #define ASCV_OVERRUN_BSIZE_D  (ushort)0x003C
1657 #define ASCV_HALTCODE_W       (ushort)0x0040
1658 #define ASCV_CHKSUM_W         (ushort)0x0042
1659 #define ASCV_MC_DATE_W        (ushort)0x0044
1660 #define ASCV_MC_VER_W         (ushort)0x0046
1661 #define ASCV_NEXTRDY_B        (ushort)0x0048
1662 #define ASCV_DONENEXT_B       (ushort)0x0049
1663 #define ASCV_USE_TAGGED_QNG_B (ushort)0x004A
1664 #define ASCV_SCSIBUSY_B       (ushort)0x004B
1665 #define ASCV_Q_DONE_IN_PROGRESS_B  (ushort)0x004C
1666 #define ASCV_CURCDB_B         (ushort)0x004D
1667 #define ASCV_RCLUN_B          (ushort)0x004E
1668 #define ASCV_BUSY_QHEAD_B     (ushort)0x004F
1669 #define ASCV_DISC1_QHEAD_B    (ushort)0x0050
1670 #define ASCV_DISC_ENABLE_B    (ushort)0x0052
1671 #define ASCV_CAN_TAGGED_QNG_B (ushort)0x0053
1672 #define ASCV_HOSTSCSI_ID_B    (ushort)0x0055
1673 #define ASCV_MCODE_CNTL_B     (ushort)0x0056
1674 #define ASCV_NULL_TARGET_B    (ushort)0x0057
1675 #define ASCV_FREE_Q_HEAD_W    (ushort)0x0058
1676 #define ASCV_DONE_Q_TAIL_W    (ushort)0x005A
1677 #define ASCV_FREE_Q_HEAD_B    (ushort)(ASCV_FREE_Q_HEAD_W+1)
1678 #define ASCV_DONE_Q_TAIL_B    (ushort)(ASCV_DONE_Q_TAIL_W+1)
1679 #define ASCV_HOST_FLAG_B      (ushort)0x005D
1680 #define ASCV_TOTAL_READY_Q_B  (ushort)0x0064
1681 #define ASCV_VER_SERIAL_B     (ushort)0x0065
1682 #define ASCV_HALTCODE_SAVED_W (ushort)0x0066
1683 #define ASCV_WTM_FLAG_B       (ushort)0x0068
1684 #define ASCV_RISC_FLAG_B      (ushort)0x006A
1685 #define ASCV_REQ_SG_LIST_QP   (ushort)0x006B
1686 #define ASC_HOST_FLAG_IN_ISR        0x01
1687 #define ASC_HOST_FLAG_ACK_INT       0x02
1688 #define ASC_RISC_FLAG_GEN_INT      0x01
1689 #define ASC_RISC_FLAG_REQ_SG_LIST  0x02
1690 #define IOP_CTRL         (0x0F)
1691 #define IOP_STATUS       (0x0E)
1692 #define IOP_INT_ACK      IOP_STATUS
1693 #define IOP_REG_IFC      (0x0D)
1694 #define IOP_SYN_OFFSET    (0x0B)
1695 #define IOP_EXTRA_CONTROL (0x0D)
1696 #define IOP_REG_PC        (0x0C)
1697 #define IOP_RAM_ADDR      (0x0A)
1698 #define IOP_RAM_DATA      (0x08)
1699 #define IOP_EEP_DATA      (0x06)
1700 #define IOP_EEP_CMD       (0x07)
1701 #define IOP_VERSION       (0x03)
1702 #define IOP_CONFIG_HIGH   (0x04)
1703 #define IOP_CONFIG_LOW    (0x02)
1704 #define IOP_SIG_BYTE      (0x01)
1705 #define IOP_SIG_WORD      (0x00)
1706 #define IOP_REG_DC1      (0x0E)
1707 #define IOP_REG_DC0      (0x0C)
1708 #define IOP_REG_SB       (0x0B)
1709 #define IOP_REG_DA1      (0x0A)
1710 #define IOP_REG_DA0      (0x08)
1711 #define IOP_REG_SC       (0x09)
1712 #define IOP_DMA_SPEED    (0x07)
1713 #define IOP_REG_FLAG     (0x07)
1714 #define IOP_FIFO_H       (0x06)
1715 #define IOP_FIFO_L       (0x04)
1716 #define IOP_REG_ID       (0x05)
1717 #define IOP_REG_QP       (0x03)
1718 #define IOP_REG_IH       (0x02)
1719 #define IOP_REG_IX       (0x01)
1720 #define IOP_REG_AX       (0x00)
1721 #define IFC_REG_LOCK      (0x00)
1722 #define IFC_REG_UNLOCK    (0x09)
1723 #define IFC_WR_EN_FILTER  (0x10)
1724 #define IFC_RD_NO_EEPROM  (0x10)
1725 #define IFC_SLEW_RATE     (0x20)
1726 #define IFC_ACT_NEG       (0x40)
1727 #define IFC_INP_FILTER    (0x80)
1728 #define IFC_INIT_DEFAULT  (IFC_ACT_NEG | IFC_REG_UNLOCK)
1729 #define SC_SEL   (uchar)(0x80)
1730 #define SC_BSY   (uchar)(0x40)
1731 #define SC_ACK   (uchar)(0x20)
1732 #define SC_REQ   (uchar)(0x10)
1733 #define SC_ATN   (uchar)(0x08)
1734 #define SC_IO    (uchar)(0x04)
1735 #define SC_CD    (uchar)(0x02)
1736 #define SC_MSG   (uchar)(0x01)
1737 #define SEC_SCSI_CTL         (uchar)(0x80)
1738 #define SEC_ACTIVE_NEGATE    (uchar)(0x40)
1739 #define SEC_SLEW_RATE        (uchar)(0x20)
1740 #define SEC_ENABLE_FILTER    (uchar)(0x10)
1741 #define ASC_HALT_EXTMSG_IN     (ushort)0x8000
1742 #define ASC_HALT_CHK_CONDITION (ushort)0x8100
1743 #define ASC_HALT_SS_QUEUE_FULL (ushort)0x8200
1744 #define ASC_HALT_DISABLE_ASYN_USE_SYN_FIX  (ushort)0x8300
1745 #define ASC_HALT_ENABLE_ASYN_USE_SYN_FIX   (ushort)0x8400
1746 #define ASC_HALT_SDTR_REJECTED (ushort)0x4000
1747 #define ASC_HALT_HOST_COPY_SG_LIST_TO_RISC ( ushort )0x2000
1748 #define ASC_MAX_QNO        0xF8
1749 #define ASC_DATA_SEC_BEG   (ushort)0x0080
1750 #define ASC_DATA_SEC_END   (ushort)0x0080
1751 #define ASC_CODE_SEC_BEG   (ushort)0x0080
1752 #define ASC_CODE_SEC_END   (ushort)0x0080
1753 #define ASC_QADR_BEG       (0x4000)
1754 #define ASC_QADR_USED      (ushort)(ASC_MAX_QNO * 64)
1755 #define ASC_QADR_END       (ushort)0x7FFF
1756 #define ASC_QLAST_ADR      (ushort)0x7FC0
1757 #define ASC_QBLK_SIZE      0x40
1758 #define ASC_BIOS_DATA_QBEG 0xF8
1759 #define ASC_MIN_ACTIVE_QNO 0x01
1760 #define ASC_QLINK_END      0xFF
1761 #define ASC_EEPROM_WORDS   0x10
1762 #define ASC_MAX_MGS_LEN    0x10
1763 #define ASC_BIOS_ADDR_DEF  0xDC00
1764 #define ASC_BIOS_SIZE      0x3800
1765 #define ASC_BIOS_RAM_OFF   0x3800
1766 #define ASC_BIOS_RAM_SIZE  0x800
1767 #define ASC_BIOS_MIN_ADDR  0xC000
1768 #define ASC_BIOS_MAX_ADDR  0xEC00
1769 #define ASC_BIOS_BANK_SIZE 0x0400
1770 #define ASC_MCODE_START_ADDR  0x0080
1771 #define ASC_CFG0_HOST_INT_ON    0x0020
1772 #define ASC_CFG0_BIOS_ON        0x0040
1773 #define ASC_CFG0_VERA_BURST_ON  0x0080
1774 #define ASC_CFG0_SCSI_PARITY_ON 0x0800
1775 #define ASC_CFG1_SCSI_TARGET_ON 0x0080
1776 #define ASC_CFG1_LRAM_8BITS_ON  0x0800
1777 #define ASC_CFG_MSW_CLR_MASK    0x3080
1778 #define CSW_TEST1             (ASC_CS_TYPE)0x8000
1779 #define CSW_AUTO_CONFIG       (ASC_CS_TYPE)0x4000
1780 #define CSW_RESERVED1         (ASC_CS_TYPE)0x2000
1781 #define CSW_IRQ_WRITTEN       (ASC_CS_TYPE)0x1000
1782 #define CSW_33MHZ_SELECTED    (ASC_CS_TYPE)0x0800
1783 #define CSW_TEST2             (ASC_CS_TYPE)0x0400
1784 #define CSW_TEST3             (ASC_CS_TYPE)0x0200
1785 #define CSW_RESERVED2         (ASC_CS_TYPE)0x0100
1786 #define CSW_DMA_DONE          (ASC_CS_TYPE)0x0080
1787 #define CSW_FIFO_RDY          (ASC_CS_TYPE)0x0040
1788 #define CSW_EEP_READ_DONE     (ASC_CS_TYPE)0x0020
1789 #define CSW_HALTED            (ASC_CS_TYPE)0x0010
1790 #define CSW_SCSI_RESET_ACTIVE (ASC_CS_TYPE)0x0008
1791 #define CSW_PARITY_ERR        (ASC_CS_TYPE)0x0004
1792 #define CSW_SCSI_RESET_LATCH  (ASC_CS_TYPE)0x0002
1793 #define CSW_INT_PENDING       (ASC_CS_TYPE)0x0001
1794 #define CIW_CLR_SCSI_RESET_INT (ASC_CS_TYPE)0x1000
1795 #define CIW_INT_ACK      (ASC_CS_TYPE)0x0100
1796 #define CIW_TEST1        (ASC_CS_TYPE)0x0200
1797 #define CIW_TEST2        (ASC_CS_TYPE)0x0400
1798 #define CIW_SEL_33MHZ    (ASC_CS_TYPE)0x0800
1799 #define CIW_IRQ_ACT      (ASC_CS_TYPE)0x1000
1800 #define CC_CHIP_RESET   (uchar)0x80
1801 #define CC_SCSI_RESET   (uchar)0x40
1802 #define CC_HALT         (uchar)0x20
1803 #define CC_SINGLE_STEP  (uchar)0x10
1804 #define CC_DMA_ABLE     (uchar)0x08
1805 #define CC_TEST         (uchar)0x04
1806 #define CC_BANK_ONE     (uchar)0x02
1807 #define CC_DIAG         (uchar)0x01
1808 #define ASC_1000_ID0W      0x04C1
1809 #define ASC_1000_ID0W_FIX  0x00C1
1810 #define ASC_1000_ID1B      0x25
1811 #define ASC_EISA_BIG_IOP_GAP   (0x1C30-0x0C50)
1812 #define ASC_EISA_SMALL_IOP_GAP (0x0020)
1813 #define ASC_EISA_MIN_IOP_ADDR  (0x0C30)
1814 #define ASC_EISA_MAX_IOP_ADDR  (0xFC50)
1815 #define ASC_EISA_REV_IOP_MASK  (0x0C83)
1816 #define ASC_EISA_PID_IOP_MASK  (0x0C80)
1817 #define ASC_EISA_CFG_IOP_MASK  (0x0C86)
1818 #define ASC_GET_EISA_SLOT(iop)  (PortAddr)((iop) & 0xF000)
1819 #define ASC_EISA_ID_740    0x01745004UL
1820 #define ASC_EISA_ID_750    0x01755004UL
1821 #define INS_HALTINT        (ushort)0x6281
1822 #define INS_HALT           (ushort)0x6280
1823 #define INS_SINT           (ushort)0x6200
1824 #define INS_RFLAG_WTM      (ushort)0x7380
1825 #define ASC_MC_SAVE_CODE_WSIZE  0x500
1826 #define ASC_MC_SAVE_DATA_WSIZE  0x40
1827
1828 typedef struct asc_mc_saved {
1829     ushort              data[ASC_MC_SAVE_DATA_WSIZE];
1830     ushort              code[ASC_MC_SAVE_CODE_WSIZE];
1831 } ASC_MC_SAVED;
1832
1833 #define AscGetQDoneInProgress(port)         AscReadLramByte((port), ASCV_Q_DONE_IN_PROGRESS_B)
1834 #define AscPutQDoneInProgress(port, val)    AscWriteLramByte((port), ASCV_Q_DONE_IN_PROGRESS_B, val)
1835 #define AscGetVarFreeQHead(port)            AscReadLramWord((port), ASCV_FREE_Q_HEAD_W)
1836 #define AscGetVarDoneQTail(port)            AscReadLramWord((port), ASCV_DONE_Q_TAIL_W)
1837 #define AscPutVarFreeQHead(port, val)       AscWriteLramWord((port), ASCV_FREE_Q_HEAD_W, val)
1838 #define AscPutVarDoneQTail(port, val)       AscWriteLramWord((port), ASCV_DONE_Q_TAIL_W, val)
1839 #define AscGetRiscVarFreeQHead(port)        AscReadLramByte((port), ASCV_NEXTRDY_B)
1840 #define AscGetRiscVarDoneQTail(port)        AscReadLramByte((port), ASCV_DONENEXT_B)
1841 #define AscPutRiscVarFreeQHead(port, val)   AscWriteLramByte((port), ASCV_NEXTRDY_B, val)
1842 #define AscPutRiscVarDoneQTail(port, val)   AscWriteLramByte((port), ASCV_DONENEXT_B, val)
1843 #define AscPutMCodeSDTRDoneAtID(port, id, data)  AscWriteLramByte((port), (ushort)((ushort)ASCV_SDTR_DONE_BEG+(ushort)id), (data));
1844 #define AscGetMCodeSDTRDoneAtID(port, id)        AscReadLramByte((port), (ushort)((ushort)ASCV_SDTR_DONE_BEG+(ushort)id));
1845 #define AscPutMCodeInitSDTRAtID(port, id, data)  AscWriteLramByte((port), (ushort)((ushort)ASCV_SDTR_DATA_BEG+(ushort)id), data);
1846 #define AscGetMCodeInitSDTRAtID(port, id)        AscReadLramByte((port), (ushort)((ushort)ASCV_SDTR_DATA_BEG+(ushort)id));
1847 #define AscSynIndexToPeriod(index)        (uchar)(asc_dvc->sdtr_period_tbl[ (index) ])
1848 #define AscGetChipSignatureByte(port)     (uchar)inp((port)+IOP_SIG_BYTE)
1849 #define AscGetChipSignatureWord(port)     (ushort)inpw((port)+IOP_SIG_WORD)
1850 #define AscGetChipVerNo(port)             (uchar)inp((port)+IOP_VERSION)
1851 #define AscGetChipCfgLsw(port)            (ushort)inpw((port)+IOP_CONFIG_LOW)
1852 #define AscGetChipCfgMsw(port)            (ushort)inpw((port)+IOP_CONFIG_HIGH)
1853 #define AscSetChipCfgLsw(port, data)      outpw((port)+IOP_CONFIG_LOW, data)
1854 #define AscSetChipCfgMsw(port, data)      outpw((port)+IOP_CONFIG_HIGH, data)
1855 #define AscGetChipEEPCmd(port)            (uchar)inp((port)+IOP_EEP_CMD)
1856 #define AscSetChipEEPCmd(port, data)      outp((port)+IOP_EEP_CMD, data)
1857 #define AscGetChipEEPData(port)           (ushort)inpw((port)+IOP_EEP_DATA)
1858 #define AscSetChipEEPData(port, data)     outpw((port)+IOP_EEP_DATA, data)
1859 #define AscGetChipLramAddr(port)          (ushort)inpw((PortAddr)((port)+IOP_RAM_ADDR))
1860 #define AscSetChipLramAddr(port, addr)    outpw((PortAddr)((port)+IOP_RAM_ADDR), addr)
1861 #define AscGetChipLramData(port)          (ushort)inpw((port)+IOP_RAM_DATA)
1862 #define AscSetChipLramData(port, data)    outpw((port)+IOP_RAM_DATA, data)
1863 #define AscGetChipIFC(port)               (uchar)inp((port)+IOP_REG_IFC)
1864 #define AscSetChipIFC(port, data)          outp((port)+IOP_REG_IFC, data)
1865 #define AscGetChipStatus(port)            (ASC_CS_TYPE)inpw((port)+IOP_STATUS)
1866 #define AscSetChipStatus(port, cs_val)    outpw((port)+IOP_STATUS, cs_val)
1867 #define AscGetChipControl(port)           (uchar)inp((port)+IOP_CTRL)
1868 #define AscSetChipControl(port, cc_val)   outp((port)+IOP_CTRL, cc_val)
1869 #define AscGetChipSyn(port)               (uchar)inp((port)+IOP_SYN_OFFSET)
1870 #define AscSetChipSyn(port, data)         outp((port)+IOP_SYN_OFFSET, data)
1871 #define AscSetPCAddr(port, data)          outpw((port)+IOP_REG_PC, data)
1872 #define AscGetPCAddr(port)                (ushort)inpw((port)+IOP_REG_PC)
1873 #define AscIsIntPending(port)             (AscGetChipStatus(port) & (CSW_INT_PENDING | CSW_SCSI_RESET_LATCH))
1874 #define AscGetChipScsiID(port)            ((AscGetChipCfgLsw(port) >> 8) & ASC_MAX_TID)
1875 #define AscGetExtraControl(port)          (uchar)inp((port)+IOP_EXTRA_CONTROL)
1876 #define AscSetExtraControl(port, data)    outp((port)+IOP_EXTRA_CONTROL, data)
1877 #define AscReadChipAX(port)               (ushort)inpw((port)+IOP_REG_AX)
1878 #define AscWriteChipAX(port, data)        outpw((port)+IOP_REG_AX, data)
1879 #define AscReadChipIX(port)               (uchar)inp((port)+IOP_REG_IX)
1880 #define AscWriteChipIX(port, data)        outp((port)+IOP_REG_IX, data)
1881 #define AscReadChipIH(port)               (ushort)inpw((port)+IOP_REG_IH)
1882 #define AscWriteChipIH(port, data)        outpw((port)+IOP_REG_IH, data)
1883 #define AscReadChipQP(port)               (uchar)inp((port)+IOP_REG_QP)
1884 #define AscWriteChipQP(port, data)        outp((port)+IOP_REG_QP, data)
1885 #define AscReadChipFIFO_L(port)           (ushort)inpw((port)+IOP_REG_FIFO_L)
1886 #define AscWriteChipFIFO_L(port, data)    outpw((port)+IOP_REG_FIFO_L, data)
1887 #define AscReadChipFIFO_H(port)           (ushort)inpw((port)+IOP_REG_FIFO_H)
1888 #define AscWriteChipFIFO_H(port, data)    outpw((port)+IOP_REG_FIFO_H, data)
1889 #define AscReadChipDmaSpeed(port)         (uchar)inp((port)+IOP_DMA_SPEED)
1890 #define AscWriteChipDmaSpeed(port, data)  outp((port)+IOP_DMA_SPEED, data)
1891 #define AscReadChipDA0(port)              (ushort)inpw((port)+IOP_REG_DA0)
1892 #define AscWriteChipDA0(port)             outpw((port)+IOP_REG_DA0, data)
1893 #define AscReadChipDA1(port)              (ushort)inpw((port)+IOP_REG_DA1)
1894 #define AscWriteChipDA1(port)             outpw((port)+IOP_REG_DA1, data)
1895 #define AscReadChipDC0(port)              (ushort)inpw((port)+IOP_REG_DC0)
1896 #define AscWriteChipDC0(port)             outpw((port)+IOP_REG_DC0, data)
1897 #define AscReadChipDC1(port)              (ushort)inpw((port)+IOP_REG_DC1)
1898 #define AscWriteChipDC1(port)             outpw((port)+IOP_REG_DC1, data)
1899 #define AscReadChipDvcID(port)            (uchar)inp((port)+IOP_REG_ID)
1900 #define AscWriteChipDvcID(port, data)     outp((port)+IOP_REG_ID, data)
1901
1902 STATIC int       AscWriteEEPCmdReg(PortAddr iop_base, uchar cmd_reg);
1903 STATIC int       AscWriteEEPDataReg(PortAddr iop_base, ushort data_reg);
1904 STATIC void      AscWaitEEPRead(void);
1905 STATIC void      AscWaitEEPWrite(void);
1906 STATIC ushort    AscReadEEPWord(PortAddr, uchar);
1907 STATIC ushort    AscWriteEEPWord(PortAddr, uchar, ushort);
1908 STATIC ushort    AscGetEEPConfig(PortAddr, ASCEEP_CONFIG *, ushort);
1909 STATIC int       AscSetEEPConfigOnce(PortAddr, ASCEEP_CONFIG *, ushort);
1910 STATIC int       AscSetEEPConfig(PortAddr, ASCEEP_CONFIG *, ushort);
1911 STATIC int       AscStartChip(PortAddr);
1912 STATIC int       AscStopChip(PortAddr);
1913 STATIC void      AscSetChipIH(PortAddr, ushort);
1914 STATIC int       AscIsChipHalted(PortAddr);
1915 STATIC void      AscAckInterrupt(PortAddr);
1916 STATIC void      AscDisableInterrupt(PortAddr);
1917 STATIC void      AscEnableInterrupt(PortAddr);
1918 STATIC void      AscSetBank(PortAddr, uchar);
1919 STATIC int       AscResetChipAndScsiBus(ASC_DVC_VAR *);
1920 #ifdef CONFIG_ISA
1921 STATIC ushort    AscGetIsaDmaChannel(PortAddr);
1922 STATIC ushort    AscSetIsaDmaChannel(PortAddr, ushort);
1923 STATIC uchar     AscSetIsaDmaSpeed(PortAddr, uchar);
1924 STATIC uchar     AscGetIsaDmaSpeed(PortAddr);
1925 #endif /* CONFIG_ISA */
1926 STATIC uchar     AscReadLramByte(PortAddr, ushort);
1927 STATIC ushort    AscReadLramWord(PortAddr, ushort);
1928 #if CC_VERY_LONG_SG_LIST
1929 STATIC ASC_DCNT  AscReadLramDWord(PortAddr, ushort);
1930 #endif /* CC_VERY_LONG_SG_LIST */
1931 STATIC void      AscWriteLramWord(PortAddr, ushort, ushort);
1932 STATIC void      AscWriteLramByte(PortAddr, ushort, uchar);
1933 STATIC ASC_DCNT  AscMemSumLramWord(PortAddr, ushort, int);
1934 STATIC void      AscMemWordSetLram(PortAddr, ushort, ushort, int);
1935 STATIC void      AscMemWordCopyPtrToLram(PortAddr, ushort, uchar *, int);
1936 STATIC void      AscMemDWordCopyPtrToLram(PortAddr, ushort, uchar *, int);
1937 STATIC void      AscMemWordCopyPtrFromLram(PortAddr, ushort, uchar *, int);
1938 STATIC ushort    AscInitAscDvcVar(ASC_DVC_VAR *);
1939 STATIC ushort    AscInitFromEEP(ASC_DVC_VAR *);
1940 STATIC ushort    AscInitFromAscDvcVar(ASC_DVC_VAR *);
1941 STATIC ushort    AscInitMicroCodeVar(ASC_DVC_VAR *);
1942 STATIC int       AscTestExternalLram(ASC_DVC_VAR *);
1943 STATIC uchar     AscMsgOutSDTR(ASC_DVC_VAR *, uchar, uchar);
1944 STATIC uchar     AscCalSDTRData(ASC_DVC_VAR *, uchar, uchar);
1945 STATIC void      AscSetChipSDTR(PortAddr, uchar, uchar);
1946 STATIC uchar     AscGetSynPeriodIndex(ASC_DVC_VAR *, uchar);
1947 STATIC uchar     AscAllocFreeQueue(PortAddr, uchar);
1948 STATIC uchar     AscAllocMultipleFreeQueue(PortAddr, uchar, uchar);
1949 STATIC int       AscHostReqRiscHalt(PortAddr);
1950 STATIC int       AscStopQueueExe(PortAddr);
1951 STATIC int       AscSendScsiQueue(ASC_DVC_VAR *,
1952                     ASC_SCSI_Q * scsiq,
1953                     uchar n_q_required);
1954 STATIC int       AscPutReadyQueue(ASC_DVC_VAR *,
1955                     ASC_SCSI_Q *, uchar);
1956 STATIC int       AscPutReadySgListQueue(ASC_DVC_VAR *,
1957                     ASC_SCSI_Q *, uchar);
1958 STATIC int       AscSetChipSynRegAtID(PortAddr, uchar, uchar);
1959 STATIC int       AscSetRunChipSynRegAtID(PortAddr, uchar, uchar);
1960 STATIC ushort    AscInitLram(ASC_DVC_VAR *);
1961 STATIC ushort    AscInitQLinkVar(ASC_DVC_VAR *);
1962 STATIC int       AscSetLibErrorCode(ASC_DVC_VAR *, ushort);
1963 STATIC int       AscIsrChipHalted(ASC_DVC_VAR *);
1964 STATIC uchar     _AscCopyLramScsiDoneQ(PortAddr, ushort,
1965                     ASC_QDONE_INFO *, ASC_DCNT);
1966 STATIC int       AscIsrQDone(ASC_DVC_VAR *);
1967 STATIC int       AscCompareString(uchar *, uchar *, int);
1968 #ifdef CONFIG_ISA
1969 STATIC ushort    AscGetEisaChipCfg(PortAddr);
1970 STATIC ASC_DCNT  AscGetEisaProductID(PortAddr);
1971 STATIC PortAddr  AscSearchIOPortAddrEISA(PortAddr);
1972 STATIC PortAddr  AscSearchIOPortAddr11(PortAddr);
1973 STATIC PortAddr  AscSearchIOPortAddr(PortAddr, ushort);
1974 STATIC void      AscSetISAPNPWaitForKey(void);
1975 #endif /* CONFIG_ISA */
1976 STATIC uchar     AscGetChipScsiCtrl(PortAddr);
1977 STATIC uchar     AscSetChipScsiID(PortAddr, uchar);
1978 STATIC uchar     AscGetChipVersion(PortAddr, ushort);
1979 STATIC ushort    AscGetChipBusType(PortAddr);
1980 STATIC ASC_DCNT  AscLoadMicroCode(PortAddr, ushort, uchar *, ushort);
1981 STATIC int       AscFindSignature(PortAddr);
1982 STATIC void      AscToggleIRQAct(PortAddr);
1983 STATIC uchar     AscGetChipIRQ(PortAddr, ushort);
1984 STATIC uchar     AscSetChipIRQ(PortAddr, uchar, ushort);
1985 STATIC ushort    AscGetChipBiosAddress(PortAddr, ushort);
1986 STATIC inline ulong DvcEnterCritical(void);
1987 STATIC inline void DvcLeaveCritical(ulong);
1988 #ifdef CONFIG_PCI
1989 STATIC uchar     DvcReadPCIConfigByte(ASC_DVC_VAR *, ushort);
1990 STATIC void      DvcWritePCIConfigByte(ASC_DVC_VAR *,
1991                     ushort, uchar);
1992 #endif /* CONFIG_PCI */
1993 STATIC ushort      AscGetChipBiosAddress(PortAddr, ushort);
1994 STATIC void      DvcSleepMilliSecond(ASC_DCNT);
1995 STATIC void      DvcDelayNanoSecond(ASC_DVC_VAR *, ASC_DCNT);
1996 STATIC void      DvcPutScsiQ(PortAddr, ushort, uchar *, int);
1997 STATIC void      DvcGetQinfo(PortAddr, ushort, uchar *, int);
1998 STATIC ushort    AscInitGetConfig(ASC_DVC_VAR *);
1999 STATIC ushort    AscInitSetConfig(ASC_DVC_VAR *);
2000 STATIC ushort    AscInitAsc1000Driver(ASC_DVC_VAR *);
2001 STATIC void      AscAsyncFix(ASC_DVC_VAR *, uchar,
2002                     ASC_SCSI_INQUIRY *);
2003 STATIC int       AscTagQueuingSafe(ASC_SCSI_INQUIRY *);
2004 STATIC void      AscInquiryHandling(ASC_DVC_VAR *,
2005                     uchar, ASC_SCSI_INQUIRY *);
2006 STATIC int       AscExeScsiQueue(ASC_DVC_VAR *, ASC_SCSI_Q *);
2007 STATIC int       AscISR(ASC_DVC_VAR *);
2008 STATIC uint      AscGetNumOfFreeQueue(ASC_DVC_VAR *, uchar,
2009                     uchar);
2010 STATIC int       AscSgListToQueue(int);
2011 #ifdef CONFIG_ISA
2012 STATIC void      AscEnableIsaDma(uchar);
2013 #endif /* CONFIG_ISA */
2014 STATIC ASC_DCNT  AscGetMaxDmaCount(ushort);
2015
2016
2017 /*
2018  * --- Adv Library Constants and Macros
2019  */
2020
2021 #define ADV_LIB_VERSION_MAJOR  5
2022 #define ADV_LIB_VERSION_MINOR  14
2023
2024 /*
2025  * Define Adv Library required special types.
2026  */
2027
2028 /*
2029  * Portable Data Types
2030  *
2031  * Any instance where a 32-bit long or pointer type is assumed
2032  * for precision or HW defined structures, the following define
2033  * types must be used. In Linux the char, short, and int types
2034  * are all consistent at 8, 16, and 32 bits respectively. Pointers
2035  * and long types are 64 bits on Alpha and UltraSPARC.
2036  */
2037 #define ADV_PADDR __u32         /* Physical address data type. */
2038 #define ADV_VADDR __u32         /* Virtual address data type. */
2039 #define ADV_DCNT  __u32         /* Unsigned Data count type. */
2040 #define ADV_SDCNT __s32         /* Signed Data count type. */
2041
2042 /*
2043  * These macros are used to convert a virtual address to a
2044  * 32-bit value. This currently can be used on Linux Alpha
2045  * which uses 64-bit virtual address but a 32-bit bus address.
2046  * This is likely to break in the future, but doing this now
2047  * will give us time to change the HW and FW to handle 64-bit
2048  * addresses.
2049  */
2050 #define ADV_VADDR_TO_U32   virt_to_bus
2051 #define ADV_U32_TO_VADDR   bus_to_virt
2052
2053 #define AdvPortAddr  ulong              /* Virtual memory address size */
2054
2055 /*
2056  * Define Adv Library required memory access macros.
2057  */
2058 #define ADV_MEM_READB(addr) readb(addr)
2059 #define ADV_MEM_READW(addr) readw(addr)
2060 #define ADV_MEM_WRITEB(addr, byte) writeb(byte, addr)
2061 #define ADV_MEM_WRITEW(addr, word) writew(word, addr)
2062 #define ADV_MEM_WRITEDW(addr, dword) writel(dword, addr)
2063
2064 #define ADV_CARRIER_COUNT (ASC_DEF_MAX_HOST_QNG + 15)
2065
2066 /*
2067  * For wide  boards a CDB length maximum of 16 bytes
2068  * is supported.
2069  */
2070 #define ADV_MAX_CDB_LEN     16
2071
2072 /*
2073  * Define total number of simultaneous maximum element scatter-gather
2074  * request blocks per wide adapter. ASC_DEF_MAX_HOST_QNG (253) is the
2075  * maximum number of outstanding commands per wide host adapter. Each
2076  * command uses one or more ADV_SG_BLOCK each with 15 scatter-gather
2077  * elements. Allow each command to have at least one ADV_SG_BLOCK structure.
2078  * This allows about 15 commands to have the maximum 17 ADV_SG_BLOCK
2079  * structures or 255 scatter-gather elements.
2080  *
2081  */
2082 #define ADV_TOT_SG_BLOCK        ASC_DEF_MAX_HOST_QNG
2083
2084 /*
2085  * Define Adv Library required maximum number of scatter-gather
2086  * elements per request.
2087  */
2088 #define ADV_MAX_SG_LIST         255
2089
2090 /* Number of SG blocks needed. */
2091 #define ADV_NUM_SG_BLOCK \
2092     ((ADV_MAX_SG_LIST + (NO_OF_SG_PER_BLOCK - 1))/NO_OF_SG_PER_BLOCK)
2093
2094 /* Total contiguous memory needed for SG blocks. */
2095 #define ADV_SG_TOTAL_MEM_SIZE \
2096     (sizeof(ADV_SG_BLOCK) *  ADV_NUM_SG_BLOCK)
2097
2098 #define ADV_PAGE_SIZE PAGE_SIZE
2099
2100 #define ADV_NUM_PAGE_CROSSING \
2101     ((ADV_SG_TOTAL_MEM_SIZE + (ADV_PAGE_SIZE - 1))/ADV_PAGE_SIZE)
2102
2103 /* a_condor.h */
2104 #define ADV_PCI_VENDOR_ID               0x10CD
2105 #define ADV_PCI_DEVICE_ID_REV_A         0x2300
2106 #define ADV_PCI_DEVID_38C0800_REV1      0x2500
2107 #define ADV_PCI_DEVID_38C1600_REV1      0x2700
2108
2109 #define ADV_EEP_DVC_CFG_BEGIN           (0x00)
2110 #define ADV_EEP_DVC_CFG_END             (0x15)
2111 #define ADV_EEP_DVC_CTL_BEGIN           (0x16)  /* location of OEM name */
2112 #define ADV_EEP_MAX_WORD_ADDR           (0x1E)
2113
2114 #define ADV_EEP_DELAY_MS                100
2115
2116 #define ADV_EEPROM_BIG_ENDIAN          0x8000   /* EEPROM Bit 15 */
2117 #define ADV_EEPROM_BIOS_ENABLE         0x4000   /* EEPROM Bit 14 */
2118 /*
2119  * For the ASC3550 Bit 13 is Termination Polarity control bit.
2120  * For later ICs Bit 13 controls whether the CIS (Card Information
2121  * Service Section) is loaded from EEPROM.
2122  */
2123 #define ADV_EEPROM_TERM_POL            0x2000   /* EEPROM Bit 13 */
2124 #define ADV_EEPROM_CIS_LD              0x2000   /* EEPROM Bit 13 */
2125 /*
2126  * ASC38C1600 Bit 11
2127  *
2128  * If EEPROM Bit 11 is 0 for Function 0, then Function 0 will specify
2129  * INT A in the PCI Configuration Space Int Pin field. If it is 1, then
2130  * Function 0 will specify INT B.
2131  *
2132  * If EEPROM Bit 11 is 0 for Function 1, then Function 1 will specify
2133  * INT B in the PCI Configuration Space Int Pin field. If it is 1, then
2134  * Function 1 will specify INT A.
2135  */
2136 #define ADV_EEPROM_INTAB               0x0800   /* EEPROM Bit 11 */
2137
2138 typedef struct adveep_3550_config
2139 {
2140                                 /* Word Offset, Description */
2141
2142   ushort cfg_lsw;               /* 00 power up initialization */
2143                                 /*  bit 13 set - Term Polarity Control */
2144                                 /*  bit 14 set - BIOS Enable */
2145                                 /*  bit 15 set - Big Endian Mode */
2146   ushort cfg_msw;               /* 01 unused      */
2147   ushort disc_enable;           /* 02 disconnect enable */
2148   ushort wdtr_able;             /* 03 Wide DTR able */
2149   ushort sdtr_able;             /* 04 Synchronous DTR able */
2150   ushort start_motor;           /* 05 send start up motor */
2151   ushort tagqng_able;           /* 06 tag queuing able */
2152   ushort bios_scan;             /* 07 BIOS device control */
2153   ushort scam_tolerant;         /* 08 no scam */
2154
2155   uchar  adapter_scsi_id;       /* 09 Host Adapter ID */
2156   uchar  bios_boot_delay;       /*    power up wait */
2157
2158   uchar  scsi_reset_delay;      /* 10 reset delay */
2159   uchar  bios_id_lun;           /*    first boot device scsi id & lun */
2160                                 /*    high nibble is lun */
2161                                 /*    low nibble is scsi id */
2162
2163   uchar  termination;           /* 11 0 - automatic */
2164                                 /*    1 - low off / high off */
2165                                 /*    2 - low off / high on */
2166                                 /*    3 - low on  / high on */
2167                                 /*    There is no low on  / high off */
2168
2169   uchar  reserved1;             /*    reserved byte (not used) */
2170
2171   ushort bios_ctrl;             /* 12 BIOS control bits */
2172                                 /*  bit 0  BIOS don't act as initiator. */
2173                                 /*  bit 1  BIOS > 1 GB support */
2174                                 /*  bit 2  BIOS > 2 Disk Support */
2175                                 /*  bit 3  BIOS don't support removables */
2176                                 /*  bit 4  BIOS support bootable CD */
2177                                 /*  bit 5  BIOS scan enabled */
2178                                 /*  bit 6  BIOS support multiple LUNs */
2179                                 /*  bit 7  BIOS display of message */
2180                                 /*  bit 8  SCAM disabled */
2181                                 /*  bit 9  Reset SCSI bus during init. */
2182                                 /*  bit 10 */
2183                                 /*  bit 11 No verbose initialization. */
2184                                 /*  bit 12 SCSI parity enabled */
2185                                 /*  bit 13 */
2186                                 /*  bit 14 */
2187                                 /*  bit 15 */
2188   ushort  ultra_able;           /* 13 ULTRA speed able */
2189   ushort  reserved2;            /* 14 reserved */
2190   uchar   max_host_qng;         /* 15 maximum host queuing */
2191   uchar   max_dvc_qng;          /*    maximum per device queuing */
2192   ushort  dvc_cntl;             /* 16 control bit for driver */
2193   ushort  bug_fix;              /* 17 control bit for bug fix */
2194   ushort  serial_number_word1;  /* 18 Board serial number word 1 */
2195   ushort  serial_number_word2;  /* 19 Board serial number word 2 */
2196   ushort  serial_number_word3;  /* 20 Board serial number word 3 */
2197   ushort  check_sum;            /* 21 EEP check sum */
2198   uchar   oem_name[16];         /* 22 OEM name */
2199   ushort  dvc_err_code;         /* 30 last device driver error code */
2200   ushort  adv_err_code;         /* 31 last uc and Adv Lib error code */
2201   ushort  adv_err_addr;         /* 32 last uc error address */
2202   ushort  saved_dvc_err_code;   /* 33 saved last dev. driver error code   */
2203   ushort  saved_adv_err_code;   /* 34 saved last uc and Adv Lib error code */
2204   ushort  saved_adv_err_addr;   /* 35 saved last uc error address         */
2205   ushort  num_of_err;           /* 36 number of error */
2206 } ADVEEP_3550_CONFIG;
2207
2208 typedef struct adveep_38C0800_config
2209 {
2210                                 /* Word Offset, Description */
2211
2212   ushort cfg_lsw;               /* 00 power up initialization */
2213                                 /*  bit 13 set - Load CIS */
2214                                 /*  bit 14 set - BIOS Enable */
2215                                 /*  bit 15 set - Big Endian Mode */
2216   ushort cfg_msw;               /* 01 unused      */
2217   ushort disc_enable;           /* 02 disconnect enable */
2218   ushort wdtr_able;             /* 03 Wide DTR able */
2219   ushort sdtr_speed1;           /* 04 SDTR Speed TID 0-3 */
2220   ushort start_motor;           /* 05 send start up motor */
2221   ushort tagqng_able;           /* 06 tag queuing able */
2222   ushort bios_scan;             /* 07 BIOS device control */
2223   ushort scam_tolerant;         /* 08 no scam */
2224
2225   uchar  adapter_scsi_id;       /* 09 Host Adapter ID */
2226   uchar  bios_boot_delay;       /*    power up wait */
2227
2228   uchar  scsi_reset_delay;      /* 10 reset delay */
2229   uchar  bios_id_lun;           /*    first boot device scsi id & lun */
2230                                 /*    high nibble is lun */
2231                                 /*    low nibble is scsi id */
2232
2233   uchar  termination_se;        /* 11 0 - automatic */
2234                                 /*    1 - low off / high off */
2235                                 /*    2 - low off / high on */
2236                                 /*    3 - low on  / high on */
2237                                 /*    There is no low on  / high off */
2238
2239   uchar  termination_lvd;       /* 11 0 - automatic */
2240                                 /*    1 - low off / high off */
2241                                 /*    2 - low off / high on */
2242                                 /*    3 - low on  / high on */
2243                                 /*    There is no low on  / high off */
2244
2245   ushort bios_ctrl;             /* 12 BIOS control bits */
2246                                 /*  bit 0  BIOS don't act as initiator. */
2247                                 /*  bit 1  BIOS > 1 GB support */
2248                                 /*  bit 2  BIOS > 2 Disk Support */
2249                                 /*  bit 3  BIOS don't support removables */
2250                                 /*  bit 4  BIOS support bootable CD */
2251                                 /*  bit 5  BIOS scan enabled */
2252                                 /*  bit 6  BIOS support multiple LUNs */
2253                                 /*  bit 7  BIOS display of message */
2254                                 /*  bit 8  SCAM disabled */
2255                                 /*  bit 9  Reset SCSI bus during init. */
2256                                 /*  bit 10 */
2257                                 /*  bit 11 No verbose initialization. */
2258                                 /*  bit 12 SCSI parity enabled */
2259                                 /*  bit 13 */
2260                                 /*  bit 14 */
2261                                 /*  bit 15 */
2262   ushort  sdtr_speed2;          /* 13 SDTR speed TID 4-7 */
2263   ushort  sdtr_speed3;          /* 14 SDTR speed TID 8-11 */
2264   uchar   max_host_qng;         /* 15 maximum host queueing */
2265   uchar   max_dvc_qng;          /*    maximum per device queuing */
2266   ushort  dvc_cntl;             /* 16 control bit for driver */
2267   ushort  sdtr_speed4;          /* 17 SDTR speed 4 TID 12-15 */
2268   ushort  serial_number_word1;  /* 18 Board serial number word 1 */
2269   ushort  serial_number_word2;  /* 19 Board serial number word 2 */
2270   ushort  serial_number_word3;  /* 20 Board serial number word 3 */
2271   ushort  check_sum;            /* 21 EEP check sum */
2272   uchar   oem_name[16];         /* 22 OEM name */
2273   ushort  dvc_err_code;         /* 30 last device driver error code */
2274   ushort  adv_err_code;         /* 31 last uc and Adv Lib error code */
2275   ushort  adv_err_addr;         /* 32 last uc error address */
2276   ushort  saved_dvc_err_code;   /* 33 saved last dev. driver error code   */
2277   ushort  saved_adv_err_code;   /* 34 saved last uc and Adv Lib error code */
2278   ushort  saved_adv_err_addr;   /* 35 saved last uc error address         */
2279   ushort  reserved36;           /* 36 reserved */
2280   ushort  reserved37;           /* 37 reserved */
2281   ushort  reserved38;           /* 38 reserved */
2282   ushort  reserved39;           /* 39 reserved */
2283   ushort  reserved40;           /* 40 reserved */
2284   ushort  reserved41;           /* 41 reserved */
2285   ushort  reserved42;           /* 42 reserved */
2286   ushort  reserved43;           /* 43 reserved */
2287   ushort  reserved44;           /* 44 reserved */
2288   ushort  reserved45;           /* 45 reserved */
2289   ushort  reserved46;           /* 46 reserved */
2290   ushort  reserved47;           /* 47 reserved */
2291   ushort  reserved48;           /* 48 reserved */
2292   ushort  reserved49;           /* 49 reserved */
2293   ushort  reserved50;           /* 50 reserved */
2294   ushort  reserved51;           /* 51 reserved */
2295   ushort  reserved52;           /* 52 reserved */
2296   ushort  reserved53;           /* 53 reserved */
2297   ushort  reserved54;           /* 54 reserved */
2298   ushort  reserved55;           /* 55 reserved */
2299   ushort  cisptr_lsw;           /* 56 CIS PTR LSW */
2300   ushort  cisprt_msw;           /* 57 CIS PTR MSW */
2301   ushort  subsysvid;            /* 58 SubSystem Vendor ID */
2302   ushort  subsysid;             /* 59 SubSystem ID */
2303   ushort  reserved60;           /* 60 reserved */
2304   ushort  reserved61;           /* 61 reserved */
2305   ushort  reserved62;           /* 62 reserved */
2306   ushort  reserved63;           /* 63 reserved */
2307 } ADVEEP_38C0800_CONFIG;
2308
2309 typedef struct adveep_38C1600_config
2310 {
2311                                 /* Word Offset, Description */
2312
2313   ushort cfg_lsw;               /* 00 power up initialization */
2314                                 /*  bit 11 set - Func. 0 INTB, Func. 1 INTA */
2315                                 /*       clear - Func. 0 INTA, Func. 1 INTB */
2316                                 /*  bit 13 set - Load CIS */
2317                                 /*  bit 14 set - BIOS Enable */
2318                                 /*  bit 15 set - Big Endian Mode */
2319   ushort cfg_msw;               /* 01 unused */
2320   ushort disc_enable;           /* 02 disconnect enable */
2321   ushort wdtr_able;             /* 03 Wide DTR able */
2322   ushort sdtr_speed1;           /* 04 SDTR Speed TID 0-3 */
2323   ushort start_motor;           /* 05 send start up motor */
2324   ushort tagqng_able;           /* 06 tag queuing able */
2325   ushort bios_scan;             /* 07 BIOS device control */
2326   ushort scam_tolerant;         /* 08 no scam */
2327
2328   uchar  adapter_scsi_id;       /* 09 Host Adapter ID */
2329   uchar  bios_boot_delay;       /*    power up wait */
2330
2331   uchar  scsi_reset_delay;      /* 10 reset delay */
2332   uchar  bios_id_lun;           /*    first boot device scsi id & lun */
2333                                 /*    high nibble is lun */
2334                                 /*    low nibble is scsi id */
2335
2336   uchar  termination_se;        /* 11 0 - automatic */
2337                                 /*    1 - low off / high off */
2338                                 /*    2 - low off / high on */
2339                                 /*    3 - low on  / high on */
2340                                 /*    There is no low on  / high off */
2341
2342   uchar  termination_lvd;       /* 11 0 - automatic */
2343                                 /*    1 - low off / high off */
2344                                 /*    2 - low off / high on */
2345                                 /*    3 - low on  / high on */
2346                                 /*    There is no low on  / high off */
2347
2348   ushort bios_ctrl;             /* 12 BIOS control bits */
2349                                 /*  bit 0  BIOS don't act as initiator. */
2350                                 /*  bit 1  BIOS > 1 GB support */
2351                                 /*  bit 2  BIOS > 2 Disk Support */
2352                                 /*  bit 3  BIOS don't support removables */
2353                                 /*  bit 4  BIOS support bootable CD */
2354                                 /*  bit 5  BIOS scan enabled */
2355                                 /*  bit 6  BIOS support multiple LUNs */
2356                                 /*  bit 7  BIOS display of message */
2357                                 /*  bit 8  SCAM disabled */
2358                                 /*  bit 9  Reset SCSI bus during init. */
2359                                 /*  bit 10 Basic Integrity Checking disabled */
2360                                 /*  bit 11 No verbose initialization. */
2361                                 /*  bit 12 SCSI parity enabled */
2362                                 /*  bit 13 AIPP (Asyn. Info. Ph. Prot.) dis. */
2363                                 /*  bit 14 */
2364                                 /*  bit 15 */
2365   ushort  sdtr_speed2;          /* 13 SDTR speed TID 4-7 */
2366   ushort  sdtr_speed3;          /* 14 SDTR speed TID 8-11 */
2367   uchar   max_host_qng;         /* 15 maximum host queueing */
2368   uchar   max_dvc_qng;          /*    maximum per device queuing */
2369   ushort  dvc_cntl;             /* 16 control bit for driver */
2370   ushort  sdtr_speed4;          /* 17 SDTR speed 4 TID 12-15 */
2371   ushort  serial_number_word1;  /* 18 Board serial number word 1 */
2372   ushort  serial_number_word2;  /* 19 Board serial number word 2 */
2373   ushort  serial_number_word3;  /* 20 Board serial number word 3 */
2374   ushort  check_sum;            /* 21 EEP check sum */
2375   uchar   oem_name[16];         /* 22 OEM name */
2376   ushort  dvc_err_code;         /* 30 last device driver error code */
2377   ushort  adv_err_code;         /* 31 last uc and Adv Lib error code */
2378   ushort  adv_err_addr;         /* 32 last uc error address */
2379   ushort  saved_dvc_err_code;   /* 33 saved last dev. driver error code   */
2380   ushort  saved_adv_err_code;   /* 34 saved last uc and Adv Lib error code */
2381   ushort  saved_adv_err_addr;   /* 35 saved last uc error address         */
2382   ushort  reserved36;           /* 36 reserved */
2383   ushort  reserved37;           /* 37 reserved */
2384   ushort  reserved38;           /* 38 reserved */
2385   ushort  reserved39;           /* 39 reserved */
2386   ushort  reserved40;           /* 40 reserved */
2387   ushort  reserved41;           /* 41 reserved */
2388   ushort  reserved42;           /* 42 reserved */
2389   ushort  reserved43;           /* 43 reserved */
2390   ushort  reserved44;           /* 44 reserved */
2391   ushort  reserved45;           /* 45 reserved */
2392   ushort  reserved46;           /* 46 reserved */
2393   ushort  reserved47;           /* 47 reserved */
2394   ushort  reserved48;           /* 48 reserved */
2395   ushort  reserved49;           /* 49 reserved */
2396   ushort  reserved50;           /* 50 reserved */
2397   ushort  reserved51;           /* 51 reserved */
2398   ushort  reserved52;           /* 52 reserved */
2399   ushort  reserved53;           /* 53 reserved */
2400   ushort  reserved54;           /* 54 reserved */
2401   ushort  reserved55;           /* 55 reserved */
2402   ushort  cisptr_lsw;           /* 56 CIS PTR LSW */
2403   ushort  cisprt_msw;           /* 57 CIS PTR MSW */
2404   ushort  subsysvid;            /* 58 SubSystem Vendor ID */
2405   ushort  subsysid;             /* 59 SubSystem ID */
2406   ushort  reserved60;           /* 60 reserved */
2407   ushort  reserved61;           /* 61 reserved */
2408   ushort  reserved62;           /* 62 reserved */
2409   ushort  reserved63;           /* 63 reserved */
2410 } ADVEEP_38C1600_CONFIG;
2411
2412 /*
2413  * EEPROM Commands
2414  */
2415 #define ASC_EEP_CMD_DONE             0x0200
2416 #define ASC_EEP_CMD_DONE_ERR         0x0001
2417
2418 /* cfg_word */
2419 #define EEP_CFG_WORD_BIG_ENDIAN      0x8000
2420
2421 /* bios_ctrl */
2422 #define BIOS_CTRL_BIOS               0x0001
2423 #define BIOS_CTRL_EXTENDED_XLAT      0x0002
2424 #define BIOS_CTRL_GT_2_DISK          0x0004
2425 #define BIOS_CTRL_BIOS_REMOVABLE     0x0008
2426 #define BIOS_CTRL_BOOTABLE_CD        0x0010
2427 #define BIOS_CTRL_MULTIPLE_LUN       0x0040
2428 #define BIOS_CTRL_DISPLAY_MSG        0x0080
2429 #define BIOS_CTRL_NO_SCAM            0x0100
2430 #define BIOS_CTRL_RESET_SCSI_BUS     0x0200
2431 #define BIOS_CTRL_INIT_VERBOSE       0x0800
2432 #define BIOS_CTRL_SCSI_PARITY        0x1000
2433 #define BIOS_CTRL_AIPP_DIS           0x2000
2434
2435 #define ADV_3550_MEMSIZE   0x2000       /* 8 KB Internal Memory */
2436 #define ADV_3550_IOLEN     0x40         /* I/O Port Range in bytes */
2437
2438 #define ADV_38C0800_MEMSIZE  0x4000     /* 16 KB Internal Memory */
2439 #define ADV_38C0800_IOLEN    0x100      /* I/O Port Range in bytes */
2440
2441 /*
2442  * XXX - Since ASC38C1600 Rev.3 has a local RAM failure issue, there is
2443  * a special 16K Adv Library and Microcode version. After the issue is
2444  * resolved, should restore 32K support.
2445  *
2446  * #define ADV_38C1600_MEMSIZE  0x8000L   * 32 KB Internal Memory *
2447  */
2448 #define ADV_38C1600_MEMSIZE  0x4000   /* 16 KB Internal Memory */
2449 #define ADV_38C1600_IOLEN    0x100     /* I/O Port Range 256 bytes */
2450 #define ADV_38C1600_MEMLEN   0x1000    /* Memory Range 4KB bytes */
2451
2452 /*
2453  * Byte I/O register address from base of 'iop_base'.
2454  */
2455 #define IOPB_INTR_STATUS_REG    0x00
2456 #define IOPB_CHIP_ID_1          0x01
2457 #define IOPB_INTR_ENABLES       0x02
2458 #define IOPB_CHIP_TYPE_REV      0x03
2459 #define IOPB_RES_ADDR_4         0x04
2460 #define IOPB_RES_ADDR_5         0x05
2461 #define IOPB_RAM_DATA           0x06
2462 #define IOPB_RES_ADDR_7         0x07
2463 #define IOPB_FLAG_REG           0x08
2464 #define IOPB_RES_ADDR_9         0x09
2465 #define IOPB_RISC_CSR           0x0A
2466 #define IOPB_RES_ADDR_B         0x0B
2467 #define IOPB_RES_ADDR_C         0x0C
2468 #define IOPB_RES_ADDR_D         0x0D
2469 #define IOPB_SOFT_OVER_WR       0x0E
2470 #define IOPB_RES_ADDR_F         0x0F
2471 #define IOPB_MEM_CFG            0x10
2472 #define IOPB_RES_ADDR_11        0x11
2473 #define IOPB_GPIO_DATA          0x12
2474 #define IOPB_RES_ADDR_13        0x13
2475 #define IOPB_FLASH_PAGE         0x14
2476 #define IOPB_RES_ADDR_15        0x15
2477 #define IOPB_GPIO_CNTL          0x16
2478 #define IOPB_RES_ADDR_17        0x17
2479 #define IOPB_FLASH_DATA         0x18
2480 #define IOPB_RES_ADDR_19        0x19
2481 #define IOPB_RES_ADDR_1A        0x1A
2482 #define IOPB_RES_ADDR_1B        0x1B
2483 #define IOPB_RES_ADDR_1C        0x1C
2484 #define IOPB_RES_ADDR_1D        0x1D
2485 #define IOPB_RES_ADDR_1E        0x1E
2486 #define IOPB_RES_ADDR_1F        0x1F
2487 #define IOPB_DMA_CFG0           0x20
2488 #define IOPB_DMA_CFG1           0x21
2489 #define IOPB_TICKLE             0x22
2490 #define IOPB_DMA_REG_WR         0x23
2491 #define IOPB_SDMA_STATUS        0x24
2492 #define IOPB_SCSI_BYTE_CNT      0x25
2493 #define IOPB_HOST_BYTE_CNT      0x26
2494 #define IOPB_BYTE_LEFT_TO_XFER  0x27
2495 #define IOPB_BYTE_TO_XFER_0     0x28
2496 #define IOPB_BYTE_TO_XFER_1     0x29
2497 #define IOPB_BYTE_TO_XFER_2     0x2A
2498 #define IOPB_BYTE_TO_XFER_3     0x2B
2499 #define IOPB_ACC_GRP            0x2C
2500 #define IOPB_RES_ADDR_2D        0x2D
2501 #define IOPB_DEV_ID             0x2E
2502 #define IOPB_RES_ADDR_2F        0x2F
2503 #define IOPB_SCSI_DATA          0x30
2504 #define IOPB_RES_ADDR_31        0x31
2505 #define IOPB_RES_ADDR_32        0x32
2506 #define IOPB_SCSI_DATA_HSHK     0x33
2507 #define IOPB_SCSI_CTRL          0x34
2508 #define IOPB_RES_ADDR_35        0x35
2509 #define IOPB_RES_ADDR_36        0x36
2510 #define IOPB_RES_ADDR_37        0x37
2511 #define IOPB_RAM_BIST           0x38
2512 #define IOPB_PLL_TEST           0x39
2513 #define IOPB_PCI_INT_CFG        0x3A
2514 #define IOPB_RES_ADDR_3B        0x3B
2515 #define IOPB_RFIFO_CNT          0x3C
2516 #define IOPB_RES_ADDR_3D        0x3D
2517 #define IOPB_RES_ADDR_3E        0x3E
2518 #define IOPB_RES_ADDR_3F        0x3F
2519
2520 /*
2521  * Word I/O register address from base of 'iop_base'.
2522  */
2523 #define IOPW_CHIP_ID_0          0x00  /* CID0  */
2524 #define IOPW_CTRL_REG           0x02  /* CC    */
2525 #define IOPW_RAM_ADDR           0x04  /* LA    */
2526 #define IOPW_RAM_DATA           0x06  /* LD    */
2527 #define IOPW_RES_ADDR_08        0x08
2528 #define IOPW_RISC_CSR           0x0A  /* CSR   */
2529 #define IOPW_SCSI_CFG0          0x0C  /* CFG0  */
2530 #define IOPW_SCSI_CFG1          0x0E  /* CFG1  */
2531 #define IOPW_RES_ADDR_10        0x10
2532 #define IOPW_SEL_MASK           0x12  /* SM    */
2533 #define IOPW_RES_ADDR_14        0x14
2534 #define IOPW_FLASH_ADDR         0x16  /* FA    */
2535 #define IOPW_RES_ADDR_18        0x18
2536 #define IOPW_EE_CMD             0x1A  /* EC    */
2537 #define IOPW_EE_DATA            0x1C  /* ED    */
2538 #define IOPW_SFIFO_CNT          0x1E  /* SFC   */
2539 #define IOPW_RES_ADDR_20        0x20
2540 #define IOPW_Q_BASE             0x22  /* QB    */
2541 #define IOPW_QP                 0x24  /* QP    */
2542 #define IOPW_IX                 0x26  /* IX    */
2543 #define IOPW_SP                 0x28  /* SP    */
2544 #define IOPW_PC                 0x2A  /* PC    */
2545 #define IOPW_RES_ADDR_2C        0x2C
2546 #define IOPW_RES_ADDR_2E        0x2E
2547 #define IOPW_SCSI_DATA          0x30  /* SD    */
2548 #define IOPW_SCSI_DATA_HSHK     0x32  /* SDH   */
2549 #define IOPW_SCSI_CTRL          0x34  /* SC    */
2550 #define IOPW_HSHK_CFG           0x36  /* HCFG  */
2551 #define IOPW_SXFR_STATUS        0x36  /* SXS   */
2552 #define IOPW_SXFR_CNTL          0x38  /* SXL   */
2553 #define IOPW_SXFR_CNTH          0x3A  /* SXH   */
2554 #define IOPW_RES_ADDR_3C        0x3C
2555 #define IOPW_RFIFO_DATA         0x3E  /* RFD   */
2556
2557 /*
2558  * Doubleword I/O register address from base of 'iop_base'.
2559  */
2560 #define IOPDW_RES_ADDR_0         0x00
2561 #define IOPDW_RAM_DATA           0x04
2562 #define IOPDW_RES_ADDR_8         0x08
2563 #define IOPDW_RES_ADDR_C         0x0C
2564 #define IOPDW_RES_ADDR_10        0x10
2565 #define IOPDW_COMMA              0x14
2566 #define IOPDW_COMMB              0x18
2567 #define IOPDW_RES_ADDR_1C        0x1C
2568 #define IOPDW_SDMA_ADDR0         0x20
2569 #define IOPDW_SDMA_ADDR1         0x24
2570 #define IOPDW_SDMA_COUNT         0x28
2571 #define IOPDW_SDMA_ERROR         0x2C
2572 #define IOPDW_RDMA_ADDR0         0x30
2573 #define IOPDW_RDMA_ADDR1         0x34
2574 #define IOPDW_RDMA_COUNT         0x38
2575 #define IOPDW_RDMA_ERROR         0x3C
2576
2577 #define ADV_CHIP_ID_BYTE         0x25
2578 #define ADV_CHIP_ID_WORD         0x04C1
2579
2580 #define ADV_SC_SCSI_BUS_RESET    0x2000
2581
2582 #define ADV_INTR_ENABLE_HOST_INTR                   0x01
2583 #define ADV_INTR_ENABLE_SEL_INTR                    0x02
2584 #define ADV_INTR_ENABLE_DPR_INTR                    0x04
2585 #define ADV_INTR_ENABLE_RTA_INTR                    0x08
2586 #define ADV_INTR_ENABLE_RMA_INTR                    0x10
2587 #define ADV_INTR_ENABLE_RST_INTR                    0x20
2588 #define ADV_INTR_ENABLE_DPE_INTR                    0x40
2589 #define ADV_INTR_ENABLE_GLOBAL_INTR                 0x80
2590
2591 #define ADV_INTR_STATUS_INTRA            0x01
2592 #define ADV_INTR_STATUS_INTRB            0x02
2593 #define ADV_INTR_STATUS_INTRC            0x04
2594
2595 #define ADV_RISC_CSR_STOP           (0x0000)
2596 #define ADV_RISC_TEST_COND          (0x2000)
2597 #define ADV_RISC_CSR_RUN            (0x4000)
2598 #define ADV_RISC_CSR_SINGLE_STEP    (0x8000)
2599
2600 #define ADV_CTRL_REG_HOST_INTR      0x0100
2601 #define ADV_CTRL_REG_SEL_INTR       0x0200
2602 #define ADV_CTRL_REG_DPR_INTR       0x0400
2603 #define ADV_CTRL_REG_RTA_INTR       0x0800
2604 #define ADV_CTRL_REG_RMA_INTR       0x1000
2605 #define ADV_CTRL_REG_RES_BIT14      0x2000
2606 #define ADV_CTRL_REG_DPE_INTR       0x4000
2607 #define ADV_CTRL_REG_POWER_DONE     0x8000
2608 #define ADV_CTRL_REG_ANY_INTR       0xFF00
2609
2610 #define ADV_CTRL_REG_CMD_RESET             0x00C6
2611 #define ADV_CTRL_REG_CMD_WR_IO_REG         0x00C5
2612 #define ADV_CTRL_REG_CMD_RD_IO_REG         0x00C4
2613 #define ADV_CTRL_REG_CMD_WR_PCI_CFG_SPACE  0x00C3
2614 #define ADV_CTRL_REG_CMD_RD_PCI_CFG_SPACE  0x00C2
2615
2616 #define ADV_TICKLE_NOP                      0x00
2617 #define ADV_TICKLE_A                        0x01
2618 #define ADV_TICKLE_B                        0x02
2619 #define ADV_TICKLE_C                        0x03
2620
2621 #define ADV_SCSI_CTRL_RSTOUT        0x2000
2622
2623 #define AdvIsIntPending(port) \
2624     (AdvReadWordRegister(port, IOPW_CTRL_REG) & ADV_CTRL_REG_HOST_INTR)
2625
2626 /*
2627  * SCSI_CFG0 Register bit definitions
2628  */
2629 #define TIMER_MODEAB    0xC000  /* Watchdog, Second, and Select. Timer Ctrl. */
2630 #define PARITY_EN       0x2000  /* Enable SCSI Parity Error detection */
2631 #define EVEN_PARITY     0x1000  /* Select Even Parity */
2632 #define WD_LONG         0x0800  /* Watchdog Interval, 1: 57 min, 0: 13 sec */
2633 #define QUEUE_128       0x0400  /* Queue Size, 1: 128 byte, 0: 64 byte */
2634 #define PRIM_MODE       0x0100  /* Primitive SCSI mode */
2635 #define SCAM_EN         0x0080  /* Enable SCAM selection */
2636 #define SEL_TMO_LONG    0x0040  /* Sel/Resel Timeout, 1: 400 ms, 0: 1.6 ms */
2637 #define CFRM_ID         0x0020  /* SCAM id sel. confirm., 1: fast, 0: 6.4 ms */
2638 #define OUR_ID_EN       0x0010  /* Enable OUR_ID bits */
2639 #define OUR_ID          0x000F  /* SCSI ID */
2640
2641 /*
2642  * SCSI_CFG1 Register bit definitions
2643  */
2644 #define BIG_ENDIAN      0x8000  /* Enable Big Endian Mode MIO:15, EEP:15 */
2645 #define TERM_POL        0x2000  /* Terminator Polarity Ctrl. MIO:13, EEP:13 */
2646 #define SLEW_RATE       0x1000  /* SCSI output buffer slew rate */
2647 #define FILTER_SEL      0x0C00  /* Filter Period Selection */
2648 #define  FLTR_DISABLE    0x0000  /* Input Filtering Disabled */
2649 #define  FLTR_11_TO_20NS 0x0800  /* Input Filtering 11ns to 20ns */
2650 #define  FLTR_21_TO_39NS 0x0C00  /* Input Filtering 21ns to 39ns */
2651 #define ACTIVE_DBL      0x0200  /* Disable Active Negation */
2652 #define DIFF_MODE       0x0100  /* SCSI differential Mode (Read-Only) */
2653 #define DIFF_SENSE      0x0080  /* 1: No SE cables, 0: SE cable (Read-Only) */
2654 #define TERM_CTL_SEL    0x0040  /* Enable TERM_CTL_H and TERM_CTL_L */
2655 #define TERM_CTL        0x0030  /* External SCSI Termination Bits */
2656 #define  TERM_CTL_H      0x0020  /* Enable External SCSI Upper Termination */
2657 #define  TERM_CTL_L      0x0010  /* Enable External SCSI Lower Termination */
2658 #define CABLE_DETECT    0x000F  /* External SCSI Cable Connection Status */
2659
2660 /*
2661  * Addendum for ASC-38C0800 Chip
2662  *
2663  * The ASC-38C1600 Chip uses the same definitions except that the
2664  * bus mode override bits [12:10] have been moved to byte register
2665  * offset 0xE (IOPB_SOFT_OVER_WR) bits [12:10]. The [12:10] bits in
2666  * SCSI_CFG1 are read-only and always available. Bit 14 (DIS_TERM_DRV)
2667  * is not needed. The [12:10] bits in IOPB_SOFT_OVER_WR are write-only.
2668  * Also each ASC-38C1600 function or channel uses only cable bits [5:4]
2669  * and [1:0]. Bits [14], [7:6], [3:2] are unused.
2670  */
2671 #define DIS_TERM_DRV    0x4000  /* 1: Read c_det[3:0], 0: cannot read */
2672 #define HVD_LVD_SE      0x1C00  /* Device Detect Bits */
2673 #define  HVD             0x1000  /* HVD Device Detect */
2674 #define  LVD             0x0800  /* LVD Device Detect */
2675 #define  SE              0x0400  /* SE Device Detect */
2676 #define TERM_LVD        0x00C0  /* LVD Termination Bits */
2677 #define  TERM_LVD_HI     0x0080  /* Enable LVD Upper Termination */
2678 #define  TERM_LVD_LO     0x0040  /* Enable LVD Lower Termination */
2679 #define TERM_SE         0x0030  /* SE Termination Bits */
2680 #define  TERM_SE_HI      0x0020  /* Enable SE Upper Termination */
2681 #define  TERM_SE_LO      0x0010  /* Enable SE Lower Termination */
2682 #define C_DET_LVD       0x000C  /* LVD Cable Detect Bits */
2683 #define  C_DET3          0x0008  /* Cable Detect for LVD External Wide */
2684 #define  C_DET2          0x0004  /* Cable Detect for LVD Internal Wide */
2685 #define C_DET_SE        0x0003  /* SE Cable Detect Bits */
2686 #define  C_DET1          0x0002  /* Cable Detect for SE Internal Wide */
2687 #define  C_DET0          0x0001  /* Cable Detect for SE Internal Narrow */
2688
2689
2690 #define CABLE_ILLEGAL_A 0x7
2691     /* x 0 0 0  | on  on | Illegal (all 3 connectors are used) */
2692
2693 #define CABLE_ILLEGAL_B 0xB
2694     /* 0 x 0 0  | on  on | Illegal (all 3 connectors are used) */
2695
2696 /*
2697  * MEM_CFG Register bit definitions
2698  */
2699 #define BIOS_EN         0x40    /* BIOS Enable MIO:14,EEP:14 */
2700 #define FAST_EE_CLK     0x20    /* Diagnostic Bit */
2701 #define RAM_SZ          0x1C    /* Specify size of RAM to RISC */
2702 #define  RAM_SZ_2KB      0x00    /* 2 KB */
2703 #define  RAM_SZ_4KB      0x04    /* 4 KB */
2704 #define  RAM_SZ_8KB      0x08    /* 8 KB */
2705 #define  RAM_SZ_16KB     0x0C    /* 16 KB */
2706 #define  RAM_SZ_32KB     0x10    /* 32 KB */
2707 #define  RAM_SZ_64KB     0x14    /* 64 KB */
2708
2709 /*
2710  * DMA_CFG0 Register bit definitions
2711  *
2712  * This register is only accessible to the host.
2713  */
2714 #define BC_THRESH_ENB   0x80    /* PCI DMA Start Conditions */
2715 #define FIFO_THRESH     0x70    /* PCI DMA FIFO Threshold */
2716 #define  FIFO_THRESH_16B  0x00   /* 16 bytes */
2717 #define  FIFO_THRESH_32B  0x20   /* 32 bytes */
2718 #define  FIFO_THRESH_48B  0x30   /* 48 bytes */
2719 #define  FIFO_THRESH_64B  0x40   /* 64 bytes */
2720 #define  FIFO_THRESH_80B  0x50   /* 80 bytes (default) */
2721 #define  FIFO_THRESH_96B  0x60   /* 96 bytes */
2722 #define  FIFO_THRESH_112B 0x70   /* 112 bytes */
2723 #define START_CTL       0x0C    /* DMA start conditions */
2724 #define  START_CTL_TH    0x00    /* Wait threshold level (default) */
2725 #define  START_CTL_ID    0x04    /* Wait SDMA/SBUS idle */
2726 #define  START_CTL_THID  0x08    /* Wait threshold and SDMA/SBUS idle */
2727 #define  START_CTL_EMFU  0x0C    /* Wait SDMA FIFO empty/full */
2728 #define READ_CMD        0x03    /* Memory Read Method */
2729 #define  READ_CMD_MR     0x00    /* Memory Read */
2730 #define  READ_CMD_MRL    0x02    /* Memory Read Long */
2731 #define  READ_CMD_MRM    0x03    /* Memory Read Multiple (default) */
2732
2733 /*
2734  * ASC-38C0800 RAM BIST Register bit definitions
2735  */
2736 #define RAM_TEST_MODE         0x80
2737 #define PRE_TEST_MODE         0x40
2738 #define NORMAL_MODE           0x00
2739 #define RAM_TEST_DONE         0x10
2740 #define RAM_TEST_STATUS       0x0F
2741 #define  RAM_TEST_HOST_ERROR   0x08
2742 #define  RAM_TEST_INTRAM_ERROR 0x04
2743 #define  RAM_TEST_RISC_ERROR   0x02
2744 #define  RAM_TEST_SCSI_ERROR   0x01
2745 #define  RAM_TEST_SUCCESS      0x00
2746 #define PRE_TEST_VALUE        0x05
2747 #define NORMAL_VALUE          0x00
2748
2749 /*
2750  * ASC38C1600 Definitions
2751  *
2752  * IOPB_PCI_INT_CFG Bit Field Definitions
2753  */
2754
2755 #define INTAB_LD        0x80    /* Value loaded from EEPROM Bit 11. */
2756
2757 /*
2758  * Bit 1 can be set to change the interrupt for the Function to operate in
2759  * Totem Pole mode. By default Bit 1 is 0 and the interrupt operates in
2760  * Open Drain mode. Both functions of the ASC38C1600 must be set to the same
2761  * mode, otherwise the operating mode is undefined.
2762  */
2763 #define TOTEMPOLE       0x02
2764
2765 /*
2766  * Bit 0 can be used to change the Int Pin for the Function. The value is
2767  * 0 by default for both Functions with Function 0 using INT A and Function
2768  * B using INT B. For Function 0 if set, INT B is used. For Function 1 if set,
2769  * INT A is used.
2770  *
2771  * EEPROM Word 0 Bit 11 for each Function may change the initial Int Pin
2772  * value specified in the PCI Configuration Space.
2773  */
2774 #define INTAB           0x01
2775
2776 /* a_advlib.h */
2777
2778 /*
2779  * Adv Library Status Definitions
2780  */
2781 #define ADV_TRUE        1
2782 #define ADV_FALSE       0
2783 #define ADV_NOERROR     1
2784 #define ADV_SUCCESS     1
2785 #define ADV_BUSY        0
2786 #define ADV_ERROR       (-1)
2787
2788
2789 /*
2790  * ADV_DVC_VAR 'warn_code' values
2791  */
2792 #define ASC_WARN_BUSRESET_ERROR         0x0001 /* SCSI Bus Reset error */
2793 #define ASC_WARN_EEPROM_CHKSUM          0x0002 /* EEP check sum error */
2794 #define ASC_WARN_EEPROM_TERMINATION     0x0004 /* EEP termination bad field */
2795 #define ASC_WARN_SET_PCI_CONFIG_SPACE   0x0080 /* PCI config space set error */
2796 #define ASC_WARN_ERROR                  0xFFFF /* ADV_ERROR return */
2797
2798 #define ADV_MAX_TID                     15 /* max. target identifier */
2799 #define ADV_MAX_LUN                     7  /* max. logical unit number */
2800
2801 /*
2802  * Error code values are set in ADV_DVC_VAR 'err_code'.
2803  */
2804 #define ASC_IERR_WRITE_EEPROM       0x0001 /* write EEPROM error */
2805 #define ASC_IERR_MCODE_CHKSUM       0x0002 /* micro code check sum error */
2806 #define ASC_IERR_NO_CARRIER         0x0004 /* No more carrier memory. */
2807 #define ASC_IERR_START_STOP_CHIP    0x0008 /* start/stop chip failed */
2808 #define ASC_IERR_CHIP_VERSION       0x0040 /* wrong chip version */
2809 #define ASC_IERR_SET_SCSI_ID        0x0080 /* set SCSI ID failed */
2810 #define ASC_IERR_HVD_DEVICE         0x0100 /* HVD attached to LVD connector. */
2811 #define ASC_IERR_BAD_SIGNATURE      0x0200 /* signature not found */
2812 #define ASC_IERR_ILLEGAL_CONNECTION 0x0400 /* Illegal cable connection */
2813 #define ASC_IERR_SINGLE_END_DEVICE  0x0800 /* Single-end used w/differential */
2814 #define ASC_IERR_REVERSED_CABLE     0x1000 /* Narrow flat cable reversed */
2815 #define ASC_IERR_BIST_PRE_TEST      0x2000 /* BIST pre-test error */
2816 #define ASC_IERR_BIST_RAM_TEST      0x4000 /* BIST RAM test error */
2817 #define ASC_IERR_BAD_CHIPTYPE       0x8000 /* Invalid 'chip_type' setting. */
2818
2819 /*
2820  * Fixed locations of microcode operating variables.
2821  */
2822 #define ASC_MC_CODE_BEGIN_ADDR          0x0028 /* microcode start address */
2823 #define ASC_MC_CODE_END_ADDR            0x002A /* microcode end address */
2824 #define ASC_MC_CODE_CHK_SUM             0x002C /* microcode code checksum */
2825 #define ASC_MC_VERSION_DATE             0x0038 /* microcode version */
2826 #define ASC_MC_VERSION_NUM              0x003A /* microcode number */
2827 #define ASC_MC_BIOSMEM                  0x0040 /* BIOS RISC Memory Start */
2828 #define ASC_MC_BIOSLEN                  0x0050 /* BIOS RISC Memory Length */
2829 #define ASC_MC_BIOS_SIGNATURE           0x0058 /* BIOS Signature 0x55AA */
2830 #define ASC_MC_BIOS_VERSION             0x005A /* BIOS Version (2 bytes) */
2831 #define ASC_MC_SDTR_SPEED1              0x0090 /* SDTR Speed for TID 0-3 */
2832 #define ASC_MC_SDTR_SPEED2              0x0092 /* SDTR Speed for TID 4-7 */
2833 #define ASC_MC_SDTR_SPEED3              0x0094 /* SDTR Speed for TID 8-11 */
2834 #define ASC_MC_SDTR_SPEED4              0x0096 /* SDTR Speed for TID 12-15 */
2835 #define ASC_MC_CHIP_TYPE                0x009A
2836 #define ASC_MC_INTRB_CODE               0x009B
2837 #define ASC_MC_WDTR_ABLE                0x009C
2838 #define ASC_MC_SDTR_ABLE                0x009E
2839 #define ASC_MC_TAGQNG_ABLE              0x00A0
2840 #define ASC_MC_DISC_ENABLE              0x00A2
2841 #define ASC_MC_IDLE_CMD_STATUS          0x00A4
2842 #define ASC_MC_IDLE_CMD                 0x00A6
2843 #define ASC_MC_IDLE_CMD_PARAMETER       0x00A8
2844 #define ASC_MC_DEFAULT_SCSI_CFG0        0x00AC
2845 #define ASC_MC_DEFAULT_SCSI_CFG1        0x00AE
2846 #define ASC_MC_DEFAULT_MEM_CFG          0x00B0
2847 #define ASC_MC_DEFAULT_SEL_MASK         0x00B2
2848 #define ASC_MC_SDTR_DONE                0x00B6
2849 #define ASC_MC_NUMBER_OF_QUEUED_CMD     0x00C0
2850 #define ASC_MC_NUMBER_OF_MAX_CMD        0x00D0
2851 #define ASC_MC_DEVICE_HSHK_CFG_TABLE    0x0100
2852 #define ASC_MC_CONTROL_FLAG             0x0122 /* Microcode control flag. */
2853 #define ASC_MC_WDTR_DONE                0x0124
2854 #define ASC_MC_CAM_MODE_MASK            0x015E /* CAM mode TID bitmask. */
2855 #define ASC_MC_ICQ                      0x0160
2856 #define ASC_MC_IRQ                      0x0164
2857 #define ASC_MC_PPR_ABLE                 0x017A
2858
2859 /*
2860  * BIOS LRAM variable absolute offsets.
2861  */
2862 #define BIOS_CODESEG    0x54
2863 #define BIOS_CODELEN    0x56
2864 #define BIOS_SIGNATURE  0x58
2865 #define BIOS_VERSION    0x5A
2866
2867 /*
2868  * Microcode Control Flags
2869  *
2870  * Flags set by the Adv Library in RISC variable 'control_flag' (0x122)
2871  * and handled by the microcode.
2872  */
2873 #define CONTROL_FLAG_IGNORE_PERR        0x0001 /* Ignore DMA Parity Errors */
2874 #define CONTROL_FLAG_ENABLE_AIPP        0x0002 /* Enabled AIPP checking. */
2875
2876 /*
2877  * ASC_MC_DEVICE_HSHK_CFG_TABLE microcode table or HSHK_CFG register format
2878  */
2879 #define HSHK_CFG_WIDE_XFR       0x8000
2880 #define HSHK_CFG_RATE           0x0F00
2881 #define HSHK_CFG_OFFSET         0x001F
2882
2883 #define ASC_DEF_MAX_HOST_QNG    0xFD /* Max. number of host commands (253) */
2884 #define ASC_DEF_MIN_HOST_QNG    0x10 /* Min. number of host commands (16) */
2885 #define ASC_DEF_MAX_DVC_QNG     0x3F /* Max. number commands per device (63) */
2886 #define ASC_DEF_MIN_DVC_QNG     0x04 /* Min. number commands per device (4) */
2887
2888 #define ASC_QC_DATA_CHECK  0x01 /* Require ASC_QC_DATA_OUT set or clear. */
2889 #define ASC_QC_DATA_OUT    0x02 /* Data out DMA transfer. */
2890 #define ASC_QC_START_MOTOR 0x04 /* Send auto-start motor before request. */
2891 #define ASC_QC_NO_OVERRUN  0x08 /* Don't report overrun. */
2892 #define ASC_QC_FREEZE_TIDQ 0x10 /* Freeze TID queue after request. XXX TBD */
2893
2894 #define ASC_QSC_NO_DISC     0x01 /* Don't allow disconnect for request. */
2895 #define ASC_QSC_NO_TAGMSG   0x02 /* Don't allow tag queuing for request. */
2896 #define ASC_QSC_NO_SYNC     0x04 /* Don't use Synch. transfer on request. */
2897 #define ASC_QSC_NO_WIDE     0x08 /* Don't use Wide transfer on request. */
2898 #define ASC_QSC_REDO_DTR    0x10 /* Renegotiate WDTR/SDTR before request. */
2899 /*
2900  * Note: If a Tag Message is to be sent and neither ASC_QSC_HEAD_TAG or
2901  * ASC_QSC_ORDERED_TAG is set, then a Simple Tag Message (0x20) is used.
2902  */
2903 #define ASC_QSC_HEAD_TAG    0x40 /* Use Head Tag Message (0x21). */
2904 #define ASC_QSC_ORDERED_TAG 0x80 /* Use Ordered Tag Message (0x22). */
2905
2906 /*
2907  * All fields here are accessed by the board microcode and need to be
2908  * little-endian.
2909  */
2910 typedef struct adv_carr_t
2911 {
2912     ADV_VADDR   carr_va;       /* Carrier Virtual Address */
2913     ADV_PADDR   carr_pa;       /* Carrier Physical Address */
2914     ADV_VADDR   areq_vpa;      /* ASC_SCSI_REQ_Q Virtual or Physical Address */
2915     /*
2916      * next_vpa [31:4]            Carrier Virtual or Physical Next Pointer
2917      *
2918      * next_vpa [3:1]             Reserved Bits
2919      * next_vpa [0]               Done Flag set in Response Queue.
2920      */
2921     ADV_VADDR   next_vpa;
2922 } ADV_CARR_T;
2923
2924 /*
2925  * Mask used to eliminate low 4 bits of carrier 'next_vpa' field.
2926  */
2927 #define ASC_NEXT_VPA_MASK       0xFFFFFFF0
2928
2929 #define ASC_RQ_DONE             0x00000001
2930 #define ASC_RQ_GOOD             0x00000002
2931 #define ASC_CQ_STOPPER          0x00000000
2932
2933 #define ASC_GET_CARRP(carrp) ((carrp) & ASC_NEXT_VPA_MASK)
2934
2935 #define ADV_CARRIER_NUM_PAGE_CROSSING \
2936     (((ADV_CARRIER_COUNT * sizeof(ADV_CARR_T)) + \
2937         (ADV_PAGE_SIZE - 1))/ADV_PAGE_SIZE)
2938
2939 #define ADV_CARRIER_BUFSIZE \
2940     ((ADV_CARRIER_COUNT + ADV_CARRIER_NUM_PAGE_CROSSING) * sizeof(ADV_CARR_T))
2941
2942 /*
2943  * ASC_SCSI_REQ_Q 'a_flag' definitions
2944  *
2945  * The Adv Library should limit use to the lower nibble (4 bits) of
2946  * a_flag. Drivers are free to use the upper nibble (4 bits) of a_flag.
2947  */
2948 #define ADV_POLL_REQUEST                0x01   /* poll for request completion */
2949 #define ADV_SCSIQ_DONE                  0x02   /* request done */
2950 #define ADV_DONT_RETRY                  0x08   /* don't do retry */
2951
2952 #define ADV_CHIP_ASC3550          0x01   /* Ultra-Wide IC */
2953 #define ADV_CHIP_ASC38C0800       0x02   /* Ultra2-Wide/LVD IC */
2954 #define ADV_CHIP_ASC38C1600       0x03   /* Ultra3-Wide/LVD2 IC */
2955
2956 /*
2957  * Adapter temporary configuration structure
2958  *
2959  * This structure can be discarded after initialization. Don't add
2960  * fields here needed after initialization.
2961  *
2962  * Field naming convention:
2963  *
2964  *  *_enable indicates the field enables or disables a feature. The
2965  *  value of the field is never reset.
2966  */
2967 typedef struct adv_dvc_cfg {
2968   ushort disc_enable;       /* enable disconnection */
2969   uchar  chip_version;      /* chip version */
2970   uchar  termination;       /* Term. Ctrl. bits 6-5 of SCSI_CFG1 register */
2971   ushort lib_version;       /* Adv Library version number */
2972   ushort control_flag;      /* Microcode Control Flag */
2973   ushort mcode_date;        /* Microcode date */
2974   ushort mcode_version;     /* Microcode version */
2975   ushort pci_slot_info;     /* high byte device/function number */
2976                             /* bits 7-3 device num., bits 2-0 function num. */
2977                             /* low byte bus num. */
2978   ushort serial1;           /* EEPROM serial number word 1 */
2979   ushort serial2;           /* EEPROM serial number word 2 */
2980   ushort serial3;           /* EEPROM serial number word 3 */
2981   struct device *dev;  /* pointer to the pci dev structure for this board */
2982 } ADV_DVC_CFG;
2983
2984 struct adv_dvc_var;
2985 struct adv_scsi_req_q;
2986
2987 typedef void (* ADV_ISR_CALLBACK)
2988     (struct adv_dvc_var *, struct adv_scsi_req_q *);
2989
2990 typedef void (* ADV_ASYNC_CALLBACK)
2991     (struct adv_dvc_var *, uchar);
2992
2993 /*
2994  * Adapter operation variable structure.
2995  *
2996  * One structure is required per host adapter.
2997  *
2998  * Field naming convention:
2999  *
3000  *  *_able indicates both whether a feature should be enabled or disabled
3001  *  and whether a device isi capable of the feature. At initialization
3002  *  this field may be set, but later if a device is found to be incapable
3003  *  of the feature, the field is cleared.
3004  */
3005 typedef struct adv_dvc_var {
3006   AdvPortAddr iop_base;   /* I/O port address */
3007   ushort err_code;        /* fatal error code */
3008   ushort bios_ctrl;       /* BIOS control word, EEPROM word 12 */
3009   ADV_ISR_CALLBACK isr_callback;
3010   ADV_ASYNC_CALLBACK async_callback;
3011   ushort wdtr_able;       /* try WDTR for a device */
3012   ushort sdtr_able;       /* try SDTR for a device */
3013   ushort ultra_able;      /* try SDTR Ultra speed for a device */
3014   ushort sdtr_speed1;     /* EEPROM SDTR Speed for TID 0-3   */
3015   ushort sdtr_speed2;     /* EEPROM SDTR Speed for TID 4-7   */
3016   ushort sdtr_speed3;     /* EEPROM SDTR Speed for TID 8-11  */
3017   ushort sdtr_speed4;     /* EEPROM SDTR Speed for TID 12-15 */
3018   ushort tagqng_able;     /* try tagged queuing with a device */
3019   ushort ppr_able;        /* PPR message capable per TID bitmask. */
3020   uchar  max_dvc_qng;     /* maximum number of tagged commands per device */
3021   ushort start_motor;     /* start motor command allowed */
3022   uchar  scsi_reset_wait; /* delay in seconds after scsi bus reset */
3023   uchar  chip_no;         /* should be assigned by caller */
3024   uchar  max_host_qng;    /* maximum number of Q'ed command allowed */
3025   uchar  irq_no;          /* IRQ number */
3026   ushort no_scam;         /* scam_tolerant of EEPROM */
3027   struct asc_board *drv_ptr; /* driver pointer to private structure */
3028   uchar  chip_scsi_id;    /* chip SCSI target ID */
3029   uchar  chip_type;
3030   uchar  bist_err_code;
3031   ADV_CARR_T *carrier_buf;
3032   ADV_CARR_T *carr_freelist; /* Carrier free list. */
3033   ADV_CARR_T *icq_sp;  /* Initiator command queue stopper pointer. */
3034   ADV_CARR_T *irq_sp;  /* Initiator response queue stopper pointer. */
3035   ushort carr_pending_cnt;    /* Count of pending carriers. */
3036  /*
3037   * Note: The following fields will not be used after initialization. The
3038   * driver may discard the buffer after initialization is done.
3039   */
3040   ADV_DVC_CFG *cfg; /* temporary configuration structure  */
3041 } ADV_DVC_VAR;
3042
3043 #define NO_OF_SG_PER_BLOCK              15
3044
3045 typedef struct asc_sg_block {
3046     uchar reserved1;
3047     uchar reserved2;
3048     uchar reserved3;
3049     uchar sg_cnt;                     /* Valid entries in block. */
3050     ADV_PADDR sg_ptr;                 /* Pointer to next sg block. */
3051     struct  {
3052         ADV_PADDR sg_addr;                  /* SG element address. */
3053         ADV_DCNT  sg_count;                 /* SG element count. */
3054     } sg_list[NO_OF_SG_PER_BLOCK];
3055 } ADV_SG_BLOCK;
3056
3057 /*
3058  * ADV_SCSI_REQ_Q - microcode request structure
3059  *
3060  * All fields in this structure up to byte 60 are used by the microcode.
3061  * The microcode makes assumptions about the size and ordering of fields
3062  * in this structure. Do not change the structure definition here without
3063  * coordinating the change with the microcode.
3064  *
3065  * All fields accessed by microcode must be maintained in little_endian
3066  * order.
3067  */
3068 typedef struct adv_scsi_req_q {
3069     uchar       cntl;           /* Ucode flags and state (ASC_MC_QC_*). */
3070     uchar       target_cmd;
3071     uchar       target_id;      /* Device target identifier. */
3072     uchar       target_lun;     /* Device target logical unit number. */
3073     ADV_PADDR   data_addr;      /* Data buffer physical address. */
3074     ADV_DCNT    data_cnt;       /* Data count. Ucode sets to residual. */
3075     ADV_PADDR   sense_addr;
3076     ADV_PADDR   carr_pa;
3077     uchar       mflag;
3078     uchar       sense_len;
3079     uchar       cdb_len;        /* SCSI CDB length. Must <= 16 bytes. */
3080     uchar       scsi_cntl;
3081     uchar       done_status;    /* Completion status. */
3082     uchar       scsi_status;    /* SCSI status byte. */
3083     uchar       host_status;    /* Ucode host status. */
3084     uchar       sg_working_ix;
3085     uchar       cdb[12];        /* SCSI CDB bytes 0-11. */
3086     ADV_PADDR   sg_real_addr;   /* SG list physical address. */
3087     ADV_PADDR   scsiq_rptr;
3088     uchar       cdb16[4];       /* SCSI CDB bytes 12-15. */
3089     ADV_VADDR   scsiq_ptr;
3090     ADV_VADDR   carr_va;
3091     /*
3092      * End of microcode structure - 60 bytes. The rest of the structure
3093      * is used by the Adv Library and ignored by the microcode.
3094      */
3095     ADV_VADDR   srb_ptr;
3096     ADV_SG_BLOCK *sg_list_ptr; /* SG list virtual address. */
3097     char        *vdata_addr;   /* Data buffer virtual address. */
3098     uchar       a_flag;
3099     uchar       pad[2];        /* Pad out to a word boundary. */
3100 } ADV_SCSI_REQ_Q;
3101
3102 /*
3103  * Microcode idle loop commands
3104  */
3105 #define IDLE_CMD_COMPLETED           0
3106 #define IDLE_CMD_STOP_CHIP           0x0001
3107 #define IDLE_CMD_STOP_CHIP_SEND_INT  0x0002
3108 #define IDLE_CMD_SEND_INT            0x0004
3109 #define IDLE_CMD_ABORT               0x0008
3110 #define IDLE_CMD_DEVICE_RESET        0x0010
3111 #define IDLE_CMD_SCSI_RESET_START    0x0020 /* Assert SCSI Bus Reset */
3112 #define IDLE_CMD_SCSI_RESET_END      0x0040 /* Deassert SCSI Bus Reset */
3113 #define IDLE_CMD_SCSIREQ             0x0080
3114
3115 #define IDLE_CMD_STATUS_SUCCESS      0x0001
3116 #define IDLE_CMD_STATUS_FAILURE      0x0002
3117
3118 /*
3119  * AdvSendIdleCmd() flag definitions.
3120  */
3121 #define ADV_NOWAIT     0x01
3122
3123 /*
3124  * Wait loop time out values.
3125  */
3126 #define SCSI_WAIT_10_SEC             10UL    /* 10 seconds */
3127 #define SCSI_WAIT_100_MSEC           100UL   /* 100 milliseconds */
3128 #define SCSI_US_PER_MSEC             1000    /* microseconds per millisecond */
3129 #define SCSI_MS_PER_SEC              1000UL  /* milliseconds per second */
3130 #define SCSI_MAX_RETRY               10      /* retry count */
3131
3132 #define ADV_ASYNC_RDMA_FAILURE          0x01 /* Fatal RDMA failure. */
3133 #define ADV_ASYNC_SCSI_BUS_RESET_DET    0x02 /* Detected SCSI Bus Reset. */
3134 #define ADV_ASYNC_CARRIER_READY_FAILURE 0x03 /* Carrier Ready failure. */
3135 #define ADV_RDMA_IN_CARR_AND_Q_INVALID  0x04 /* RDMAed-in data invalid. */
3136
3137
3138 #define ADV_HOST_SCSI_BUS_RESET      0x80 /* Host Initiated SCSI Bus Reset. */
3139
3140 /*
3141  * Device drivers must define the following functions.
3142  */
3143 STATIC inline ulong DvcEnterCritical(void);
3144 STATIC inline void  DvcLeaveCritical(ulong);
3145 STATIC void  DvcSleepMilliSecond(ADV_DCNT);
3146 STATIC uchar DvcAdvReadPCIConfigByte(ADV_DVC_VAR *, ushort);
3147 STATIC void  DvcAdvWritePCIConfigByte(ADV_DVC_VAR *, ushort, uchar);
3148 STATIC ADV_PADDR DvcGetPhyAddr(ADV_DVC_VAR *, ADV_SCSI_REQ_Q *,
3149                 uchar *, ASC_SDCNT *, int);
3150 STATIC void  DvcDelayMicroSecond(ADV_DVC_VAR *, ushort);
3151
3152 /*
3153  * Adv Library functions available to drivers.
3154  */
3155 STATIC int     AdvExeScsiQueue(ADV_DVC_VAR *, ADV_SCSI_REQ_Q *);
3156 STATIC int     AdvISR(ADV_DVC_VAR *);
3157 STATIC int     AdvInitGetConfig(ADV_DVC_VAR *);
3158 STATIC int     AdvInitAsc3550Driver(ADV_DVC_VAR *);
3159 STATIC int     AdvInitAsc38C0800Driver(ADV_DVC_VAR *);
3160 STATIC int     AdvInitAsc38C1600Driver(ADV_DVC_VAR *);
3161 STATIC int     AdvResetChipAndSB(ADV_DVC_VAR *);
3162 STATIC int     AdvResetSB(ADV_DVC_VAR *asc_dvc);
3163
3164 /*
3165  * Internal Adv Library functions.
3166  */
3167 STATIC int    AdvSendIdleCmd(ADV_DVC_VAR *, ushort, ADV_DCNT);
3168 STATIC void   AdvInquiryHandling(ADV_DVC_VAR *, ADV_SCSI_REQ_Q *);
3169 STATIC int    AdvInitFrom3550EEP(ADV_DVC_VAR *);
3170 STATIC int    AdvInitFrom38C0800EEP(ADV_DVC_VAR *);
3171 STATIC int    AdvInitFrom38C1600EEP(ADV_DVC_VAR *);
3172 STATIC ushort AdvGet3550EEPConfig(AdvPortAddr, ADVEEP_3550_CONFIG *);
3173 STATIC void   AdvSet3550EEPConfig(AdvPortAddr, ADVEEP_3550_CONFIG *);
3174 STATIC ushort AdvGet38C0800EEPConfig(AdvPortAddr, ADVEEP_38C0800_CONFIG *);
3175 STATIC void   AdvSet38C0800EEPConfig(AdvPortAddr, ADVEEP_38C0800_CONFIG *);
3176 STATIC ushort AdvGet38C1600EEPConfig(AdvPortAddr, ADVEEP_38C1600_CONFIG *);
3177 STATIC void   AdvSet38C1600EEPConfig(AdvPortAddr, ADVEEP_38C1600_CONFIG *);
3178 STATIC void   AdvWaitEEPCmd(AdvPortAddr);
3179 STATIC ushort AdvReadEEPWord(AdvPortAddr, int);
3180
3181 /*
3182  * PCI Bus Definitions
3183  */
3184 #define AscPCICmdRegBits_BusMastering     0x0007
3185 #define AscPCICmdRegBits_ParErrRespCtrl   0x0040
3186
3187 /* Read byte from a register. */
3188 #define AdvReadByteRegister(iop_base, reg_off) \
3189      (ADV_MEM_READB((iop_base) + (reg_off)))
3190
3191 /* Write byte to a register. */
3192 #define AdvWriteByteRegister(iop_base, reg_off, byte) \
3193      (ADV_MEM_WRITEB((iop_base) + (reg_off), (byte)))
3194
3195 /* Read word (2 bytes) from a register. */
3196 #define AdvReadWordRegister(iop_base, reg_off) \
3197      (ADV_MEM_READW((iop_base) + (reg_off)))
3198
3199 /* Write word (2 bytes) to a register. */
3200 #define AdvWriteWordRegister(iop_base, reg_off, word) \
3201      (ADV_MEM_WRITEW((iop_base) + (reg_off), (word)))
3202
3203 /* Write dword (4 bytes) to a register. */
3204 #define AdvWriteDWordRegister(iop_base, reg_off, dword) \
3205      (ADV_MEM_WRITEDW((iop_base) + (reg_off), (dword)))
3206
3207 /* Read byte from LRAM. */
3208 #define AdvReadByteLram(iop_base, addr, byte) \
3209 do { \
3210     ADV_MEM_WRITEW((iop_base) + IOPW_RAM_ADDR, (addr)); \
3211     (byte) = ADV_MEM_READB((iop_base) + IOPB_RAM_DATA); \
3212 } while (0)
3213
3214 /* Write byte to LRAM. */
3215 #define AdvWriteByteLram(iop_base, addr, byte) \
3216     (ADV_MEM_WRITEW((iop_base) + IOPW_RAM_ADDR, (addr)), \
3217      ADV_MEM_WRITEB((iop_base) + IOPB_RAM_DATA, (byte)))
3218
3219 /* Read word (2 bytes) from LRAM. */
3220 #define AdvReadWordLram(iop_base, addr, word) \
3221 do { \
3222     ADV_MEM_WRITEW((iop_base) + IOPW_RAM_ADDR, (addr)); \
3223     (word) = (ADV_MEM_READW((iop_base) + IOPW_RAM_DATA)); \
3224 } while (0)
3225
3226 /* Write word (2 bytes) to LRAM. */
3227 #define AdvWriteWordLram(iop_base, addr, word) \
3228     (ADV_MEM_WRITEW((iop_base) + IOPW_RAM_ADDR, (addr)), \
3229      ADV_MEM_WRITEW((iop_base) + IOPW_RAM_DATA, (word)))
3230
3231 /* Write little-endian double word (4 bytes) to LRAM */
3232 /* Because of unspecified C language ordering don't use auto-increment. */
3233 #define AdvWriteDWordLramNoSwap(iop_base, addr, dword) \
3234     ((ADV_MEM_WRITEW((iop_base) + IOPW_RAM_ADDR, (addr)), \
3235       ADV_MEM_WRITEW((iop_base) + IOPW_RAM_DATA, \
3236                      cpu_to_le16((ushort) ((dword) & 0xFFFF)))), \
3237      (ADV_MEM_WRITEW((iop_base) + IOPW_RAM_ADDR, (addr) + 2), \
3238       ADV_MEM_WRITEW((iop_base) + IOPW_RAM_DATA, \
3239                      cpu_to_le16((ushort) ((dword >> 16) & 0xFFFF)))))
3240
3241 /* Read word (2 bytes) from LRAM assuming that the address is already set. */
3242 #define AdvReadWordAutoIncLram(iop_base) \
3243      (ADV_MEM_READW((iop_base) + IOPW_RAM_DATA))
3244
3245 /* Write word (2 bytes) to LRAM assuming that the address is already set. */
3246 #define AdvWriteWordAutoIncLram(iop_base, word) \
3247      (ADV_MEM_WRITEW((iop_base) + IOPW_RAM_DATA, (word)))
3248
3249
3250 /*
3251  * Define macro to check for Condor signature.
3252  *
3253  * Evaluate to ADV_TRUE if a Condor chip is found the specified port
3254  * address 'iop_base'. Otherwise evalue to ADV_FALSE.
3255  */
3256 #define AdvFindSignature(iop_base) \
3257     (((AdvReadByteRegister((iop_base), IOPB_CHIP_ID_1) == \
3258     ADV_CHIP_ID_BYTE) && \
3259      (AdvReadWordRegister((iop_base), IOPW_CHIP_ID_0) == \
3260     ADV_CHIP_ID_WORD)) ?  ADV_TRUE : ADV_FALSE)
3261
3262 /*
3263  * Define macro to Return the version number of the chip at 'iop_base'.
3264  *
3265  * The second parameter 'bus_type' is currently unused.
3266  */
3267 #define AdvGetChipVersion(iop_base, bus_type) \
3268     AdvReadByteRegister((iop_base), IOPB_CHIP_TYPE_REV)
3269
3270 /*
3271  * Abort an SRB in the chip's RISC Memory. The 'srb_ptr' argument must
3272  * match the ASC_SCSI_REQ_Q 'srb_ptr' field.
3273  *
3274  * If the request has not yet been sent to the device it will simply be
3275  * aborted from RISC memory. If the request is disconnected it will be
3276  * aborted on reselection by sending an Abort Message to the target ID.
3277  *
3278  * Return value:
3279  *      ADV_TRUE(1) - Queue was successfully aborted.
3280  *      ADV_FALSE(0) - Queue was not found on the active queue list.
3281  */
3282 #define AdvAbortQueue(asc_dvc, scsiq) \
3283         AdvSendIdleCmd((asc_dvc), (ushort) IDLE_CMD_ABORT, \
3284                        (ADV_DCNT) (scsiq))
3285
3286 /*
3287  * Send a Bus Device Reset Message to the specified target ID.
3288  *
3289  * All outstanding commands will be purged if sending the
3290  * Bus Device Reset Message is successful.
3291  *
3292  * Return Value:
3293  *      ADV_TRUE(1) - All requests on the target are purged.
3294  *      ADV_FALSE(0) - Couldn't issue Bus Device Reset Message; Requests
3295  *                     are not purged.
3296  */
3297 #define AdvResetDevice(asc_dvc, target_id) \
3298         AdvSendIdleCmd((asc_dvc), (ushort) IDLE_CMD_DEVICE_RESET, \
3299                     (ADV_DCNT) (target_id))
3300
3301 /*
3302  * SCSI Wide Type definition.
3303  */
3304 #define ADV_SCSI_BIT_ID_TYPE   ushort
3305
3306 /*
3307  * AdvInitScsiTarget() 'cntl_flag' options.
3308  */
3309 #define ADV_SCAN_LUN           0x01
3310 #define ADV_CAPINFO_NOLUN      0x02
3311
3312 /*
3313  * Convert target id to target id bit mask.
3314  */
3315 #define ADV_TID_TO_TIDMASK(tid)   (0x01 << ((tid) & ADV_MAX_TID))
3316
3317 /*
3318  * ASC_SCSI_REQ_Q 'done_status' and 'host_status' return values.
3319  */
3320
3321 #define QD_NO_STATUS         0x00       /* Request not completed yet. */
3322 #define QD_NO_ERROR          0x01
3323 #define QD_ABORTED_BY_HOST   0x02
3324 #define QD_WITH_ERROR        0x04
3325
3326 #define QHSTA_NO_ERROR              0x00
3327 #define QHSTA_M_SEL_TIMEOUT         0x11
3328 #define QHSTA_M_DATA_OVER_RUN       0x12
3329 #define QHSTA_M_UNEXPECTED_BUS_FREE 0x13
3330 #define QHSTA_M_QUEUE_ABORTED       0x15
3331 #define QHSTA_M_SXFR_SDMA_ERR       0x16 /* SXFR_STATUS SCSI DMA Error */
3332 #define QHSTA_M_SXFR_SXFR_PERR      0x17 /* SXFR_STATUS SCSI Bus Parity Error */
3333 #define QHSTA_M_RDMA_PERR           0x18 /* RISC PCI DMA parity error */
3334 #define QHSTA_M_SXFR_OFF_UFLW       0x19 /* SXFR_STATUS Offset Underflow */
3335 #define QHSTA_M_SXFR_OFF_OFLW       0x20 /* SXFR_STATUS Offset Overflow */
3336 #define QHSTA_M_SXFR_WD_TMO         0x21 /* SXFR_STATUS Watchdog Timeout */
3337 #define QHSTA_M_SXFR_DESELECTED     0x22 /* SXFR_STATUS Deselected */
3338 /* Note: QHSTA_M_SXFR_XFR_OFLW is identical to QHSTA_M_DATA_OVER_RUN. */
3339 #define QHSTA_M_SXFR_XFR_OFLW       0x12 /* SXFR_STATUS Transfer Overflow */
3340 #define QHSTA_M_SXFR_XFR_PH_ERR     0x24 /* SXFR_STATUS Transfer Phase Error */
3341 #define QHSTA_M_SXFR_UNKNOWN_ERROR  0x25 /* SXFR_STATUS Unknown Error */
3342 #define QHSTA_M_SCSI_BUS_RESET      0x30 /* Request aborted from SBR */
3343 #define QHSTA_M_SCSI_BUS_RESET_UNSOL 0x31 /* Request aborted from unsol. SBR */
3344 #define QHSTA_M_BUS_DEVICE_RESET    0x32 /* Request aborted from BDR */
3345 #define QHSTA_M_DIRECTION_ERR       0x35 /* Data Phase mismatch */
3346 #define QHSTA_M_DIRECTION_ERR_HUNG  0x36 /* Data Phase mismatch and bus hang */
3347 #define QHSTA_M_WTM_TIMEOUT         0x41
3348 #define QHSTA_M_BAD_CMPL_STATUS_IN  0x42
3349 #define QHSTA_M_NO_AUTO_REQ_SENSE   0x43
3350 #define QHSTA_M_AUTO_REQ_SENSE_FAIL 0x44
3351 #define QHSTA_M_INVALID_DEVICE      0x45 /* Bad target ID */
3352 #define QHSTA_M_FROZEN_TIDQ         0x46 /* TID Queue frozen. */
3353 #define QHSTA_M_SGBACKUP_ERROR      0x47 /* Scatter-Gather backup error */
3354
3355
3356 /*
3357  * Default EEPROM Configuration structure defined in a_init.c.
3358  */
3359 static ADVEEP_3550_CONFIG Default_3550_EEPROM_Config;
3360 static ADVEEP_38C0800_CONFIG Default_38C0800_EEPROM_Config;
3361 static ADVEEP_38C1600_CONFIG Default_38C1600_EEPROM_Config;
3362
3363 /*
3364  * DvcGetPhyAddr() flag arguments
3365  */
3366 #define ADV_IS_SCSIQ_FLAG       0x01 /* 'addr' is ASC_SCSI_REQ_Q pointer */
3367 #define ADV_ASCGETSGLIST_VADDR  0x02 /* 'addr' is AscGetSGList() virtual addr */
3368 #define ADV_IS_SENSE_FLAG       0x04 /* 'addr' is sense virtual pointer */
3369 #define ADV_IS_DATA_FLAG        0x08 /* 'addr' is data virtual pointer */
3370 #define ADV_IS_SGLIST_FLAG      0x10 /* 'addr' is sglist virtual pointer */
3371 #define ADV_IS_CARRIER_FLAG     0x20 /* 'addr' is ADV_CARR_T pointer */
3372
3373 /* Return the address that is aligned at the next doubleword >= to 'addr'. */
3374 #define ADV_8BALIGN(addr)      (((ulong) (addr) + 0x7) & ~0x7)
3375 #define ADV_16BALIGN(addr)     (((ulong) (addr) + 0xF) & ~0xF)
3376 #define ADV_32BALIGN(addr)     (((ulong) (addr) + 0x1F) & ~0x1F)
3377
3378 /*
3379  * Total contiguous memory needed for driver SG blocks.
3380  *
3381  * ADV_MAX_SG_LIST must be defined by a driver. It is the maximum
3382  * number of scatter-gather elements the driver supports in a
3383  * single request.
3384  */
3385
3386 #define ADV_SG_LIST_MAX_BYTE_SIZE \
3387          (sizeof(ADV_SG_BLOCK) * \
3388           ((ADV_MAX_SG_LIST + (NO_OF_SG_PER_BLOCK - 1))/NO_OF_SG_PER_BLOCK))
3389
3390 /*
3391  * Inquiry data structure and bitfield macros
3392  *
3393  * Using bitfields to access the subchar data isn't portable across
3394  * endianness, so instead mask and shift. Only quantities of more
3395  * than 1 bit are shifted, since the others are just tested for true
3396  * or false.
3397  */
3398
3399 #define ADV_INQ_DVC_TYPE(inq)       ((inq)->periph & 0x1f)
3400 #define ADV_INQ_QUALIFIER(inq)      (((inq)->periph & 0xe0) >> 5)
3401 #define ADV_INQ_DVC_TYPE_MOD(inq)   ((inq)->devtype & 0x7f)
3402 #define ADV_INQ_REMOVABLE(inq)      ((inq)->devtype & 0x80)
3403 #define ADV_INQ_ANSI_VER(inq)       ((inq)->ver & 0x07)
3404 #define ADV_INQ_ECMA_VER(inq)       (((inq)->ver & 0x38) >> 3)
3405 #define ADV_INQ_ISO_VER(inq)        (((inq)->ver & 0xc0) >> 6)
3406 #define ADV_INQ_RESPONSE_FMT(inq)   ((inq)->byte3 & 0x0f)
3407 #define ADV_INQ_TERM_IO(inq)        ((inq)->byte3 & 0x40)
3408 #define ADV_INQ_ASYNC_NOTIF(inq)    ((inq)->byte3 & 0x80)
3409 #define ADV_INQ_SOFT_RESET(inq)     ((inq)->flags & 0x01)
3410 #define ADV_INQ_CMD_QUEUE(inq)      ((inq)->flags & 0x02)
3411 #define ADV_INQ_LINK_CMD(inq)       ((inq)->flags & 0x08)
3412 #define ADV_INQ_SYNC(inq)           ((inq)->flags & 0x10)
3413 #define ADV_INQ_WIDE16(inq)         ((inq)->flags & 0x20)
3414 #define ADV_INQ_WIDE32(inq)         ((inq)->flags & 0x40)
3415 #define ADV_INQ_REL_ADDR(inq)       ((inq)->flags & 0x80)
3416 #define ADV_INQ_INFO_UNIT(inq)      ((inq)->info & 0x01)
3417 #define ADV_INQ_QUICK_ARB(inq)      ((inq)->info & 0x02)
3418 #define ADV_INQ_CLOCKING(inq)       (((inq)->info & 0x0c) >> 2)
3419
3420 typedef struct {
3421   uchar periph;                 /* peripheral device type [0:4] */
3422                                 /* peripheral qualifier [5:7] */
3423   uchar devtype;                /* device type modifier (for SCSI I) [0:6] */
3424                                 /* RMB - removable medium bit [7] */
3425   uchar ver;                    /* ANSI approved version [0:2] */
3426                                 /* ECMA version [3:5] */
3427                                 /* ISO version [6:7] */
3428   uchar byte3;                  /* response data format [0:3] */
3429                                 /* 0 SCSI 1 */
3430                                 /* 1 CCS */
3431                                 /* 2 SCSI-2 */
3432                                 /* 3-F reserved */
3433                                 /* reserved [4:5] */
3434                                 /* terminate I/O process bit (see 5.6.22) [6] */
3435                                 /* asynch. event notification (processor) [7] */
3436   uchar add_len;                /* additional length */
3437   uchar res1;                   /* reserved */
3438   uchar res2;                   /* reserved */
3439   uchar flags;                  /* soft reset implemented [0] */
3440                                 /* command queuing [1] */
3441                                 /* reserved [2] */
3442                                 /* linked command for this logical unit [3] */
3443                                 /* synchronous data transfer [4] */
3444                                 /* wide bus 16 bit data transfer [5] */
3445                                 /* wide bus 32 bit data transfer [6] */
3446                                 /* relative addressing mode [7] */
3447   uchar vendor_id[8];           /* vendor identification */
3448   uchar product_id[16];         /* product identification */
3449   uchar product_rev_level[4];   /* product revision level */
3450   uchar vendor_specific[20];    /* vendor specific */
3451   uchar info;                   /* information unit supported [0] */
3452                                 /* quick arbitrate supported [1] */
3453                                 /* clocking field [2:3] */
3454                                 /* reserved [4:7] */
3455   uchar res3;                   /* reserved */
3456 } ADV_SCSI_INQUIRY; /* 58 bytes */
3457
3458
3459 /*
3460  * --- Driver Constants and Macros
3461  */
3462
3463 #define ASC_NUM_BOARD_SUPPORTED 16
3464 #define ASC_NUM_IOPORT_PROBE    4
3465 #define ASC_NUM_BUS             4
3466
3467 /* Reference Scsi_Host hostdata */
3468 #define ASC_BOARDP(host) ((asc_board_t *) &((host)->hostdata))
3469
3470 /* asc_board_t flags */
3471 #define ASC_HOST_IN_RESET       0x01
3472 #define ASC_IS_WIDE_BOARD       0x04    /* AdvanSys Wide Board */
3473 #define ASC_SELECT_QUEUE_DEPTHS 0x08
3474
3475 #define ASC_NARROW_BOARD(boardp) (((boardp)->flags & ASC_IS_WIDE_BOARD) == 0)
3476 #define ASC_WIDE_BOARD(boardp)   ((boardp)->flags & ASC_IS_WIDE_BOARD)
3477
3478 #define NO_ISA_DMA              0xff        /* No ISA DMA Channel Used */
3479
3480 #define ASC_INFO_SIZE           128            /* advansys_info() line size */
3481
3482 #ifdef CONFIG_PROC_FS
3483 /* /proc/scsi/advansys/[0...] related definitions */
3484 #define ASC_PRTBUF_SIZE         2048
3485 #define ASC_PRTLINE_SIZE        160
3486
3487 #define ASC_PRT_NEXT() \
3488     if (cp) { \
3489         totlen += len; \
3490         leftlen -= len; \
3491         if (leftlen == 0) { \
3492             return totlen; \
3493         } \
3494         cp += len; \
3495     }
3496 #endif /* CONFIG_PROC_FS */
3497
3498 /* Asc Library return codes */
3499 #define ASC_TRUE        1
3500 #define ASC_FALSE       0
3501 #define ASC_NOERROR     1
3502 #define ASC_BUSY        0
3503 #define ASC_ERROR       (-1)
3504
3505 /* struct scsi_cmnd function return codes */
3506 #define STATUS_BYTE(byte)   (byte)
3507 #define MSG_BYTE(byte)      ((byte) << 8)
3508 #define HOST_BYTE(byte)     ((byte) << 16)
3509 #define DRIVER_BYTE(byte)   ((byte) << 24)
3510
3511 /*
3512  * The following definitions and macros are OS independent interfaces to
3513  * the queue functions:
3514  *  REQ - SCSI request structure
3515  *  REQP - pointer to SCSI request structure
3516  *  REQPTID(reqp) - reqp's target id
3517  *  REQPNEXT(reqp) - reqp's next pointer
3518  *  REQPNEXTP(reqp) - pointer to reqp's next pointer
3519  *  REQPTIME(reqp) - reqp's time stamp value
3520  *  REQTIMESTAMP() - system time stamp value
3521  */
3522 typedef struct scsi_cmnd     REQ, *REQP;
3523 #define REQPNEXT(reqp)       ((REQP) ((reqp)->host_scribble))
3524 #define REQPNEXTP(reqp)      ((REQP *) &((reqp)->host_scribble))
3525 #define REQPTID(reqp)        ((reqp)->device->id)
3526 #define REQPTIME(reqp)       ((reqp)->SCp.this_residual)
3527 #define REQTIMESTAMP()       (jiffies)
3528
3529 #define REQTIMESTAT(function, ascq, reqp, tid) \
3530 { \
3531     /*
3532      * If the request time stamp is less than the system time stamp, then \
3533      * maybe the system time stamp wrapped. Set the request time to zero.\
3534      */ \
3535     if (REQPTIME(reqp) <= REQTIMESTAMP()) { \
3536         REQPTIME(reqp) = REQTIMESTAMP() - REQPTIME(reqp); \
3537     } else { \
3538         /* Indicate an error occurred with the assertion. */ \
3539         ASC_ASSERT(REQPTIME(reqp) <= REQTIMESTAMP()); \
3540         REQPTIME(reqp) = 0; \
3541     } \
3542     /* Handle first minimum time case without external initialization. */ \
3543     if (((ascq)->q_tot_cnt[tid] == 1) ||  \
3544         (REQPTIME(reqp) < (ascq)->q_min_tim[tid])) { \
3545             (ascq)->q_min_tim[tid] = REQPTIME(reqp); \
3546             ASC_DBG3(1, "%s: new q_min_tim[%d] %u\n", \
3547                 (function), (tid), (ascq)->q_min_tim[tid]); \
3548         } \
3549     if (REQPTIME(reqp) > (ascq)->q_max_tim[tid]) { \
3550         (ascq)->q_max_tim[tid] = REQPTIME(reqp); \
3551         ASC_DBG3(1, "%s: new q_max_tim[%d] %u\n", \
3552             (function), tid, (ascq)->q_max_tim[tid]); \
3553     } \
3554     (ascq)->q_tot_tim[tid] += REQPTIME(reqp); \
3555     /* Reset the time stamp field. */ \
3556     REQPTIME(reqp) = 0; \
3557 }
3558
3559 /* asc_enqueue() flags */
3560 #define ASC_FRONT       1
3561 #define ASC_BACK        2
3562
3563 /* asc_dequeue_list() argument */
3564 #define ASC_TID_ALL        (-1)
3565
3566 /* Return non-zero, if the queue is empty. */
3567 #define ASC_QUEUE_EMPTY(ascq)    ((ascq)->q_tidmask == 0)
3568
3569 #define PCI_MAX_SLOT            0x1F
3570 #define PCI_MAX_BUS             0xFF
3571 #define PCI_IOADDRESS_MASK      0xFFFE
3572 #define ASC_PCI_VENDORID        0x10CD
3573 #define ASC_PCI_DEVICE_ID_CNT   6       /* PCI Device ID count. */
3574 #define ASC_PCI_DEVICE_ID_1100  0x1100
3575 #define ASC_PCI_DEVICE_ID_1200  0x1200
3576 #define ASC_PCI_DEVICE_ID_1300  0x1300
3577 #define ASC_PCI_DEVICE_ID_2300  0x2300  /* ASC-3550 */
3578 #define ASC_PCI_DEVICE_ID_2500  0x2500  /* ASC-38C0800 */
3579 #define ASC_PCI_DEVICE_ID_2700  0x2700  /* ASC-38C1600 */
3580
3581 #ifndef ADVANSYS_STATS
3582 #define ASC_STATS(shp, counter)
3583 #define ASC_STATS_ADD(shp, counter, count)
3584 #else /* ADVANSYS_STATS */
3585 #define ASC_STATS(shp, counter) \
3586     (ASC_BOARDP(shp)->asc_stats.counter++)
3587
3588 #define ASC_STATS_ADD(shp, counter, count) \
3589     (ASC_BOARDP(shp)->asc_stats.counter += (count))
3590 #endif /* ADVANSYS_STATS */
3591
3592 #define ASC_CEILING(val, unit) (((val) + ((unit) - 1))/(unit))
3593
3594 /* If the result wraps when calculating tenths, return 0. */
3595 #define ASC_TENTHS(num, den) \
3596     (((10 * ((num)/(den))) > (((num) * 10)/(den))) ? \
3597     0 : ((((num) * 10)/(den)) - (10 * ((num)/(den)))))
3598
3599 /*
3600  * Display a message to the console.
3601  */
3602 #define ASC_PRINT(s) \
3603     { \
3604         printk("advansys: "); \
3605         printk(s); \
3606     }
3607
3608 #define ASC_PRINT1(s, a1) \
3609     { \
3610         printk("advansys: "); \
3611         printk((s), (a1)); \
3612     }
3613
3614 #define ASC_PRINT2(s, a1, a2) \
3615     { \
3616         printk("advansys: "); \
3617         printk((s), (a1), (a2)); \
3618     }
3619
3620 #define ASC_PRINT3(s, a1, a2, a3) \
3621     { \
3622         printk("advansys: "); \
3623         printk((s), (a1), (a2), (a3)); \
3624     }
3625
3626 #define ASC_PRINT4(s, a1, a2, a3, a4) \
3627     { \
3628         printk("advansys: "); \
3629         printk((s), (a1), (a2), (a3), (a4)); \
3630     }
3631
3632
3633 #ifndef ADVANSYS_DEBUG
3634
3635 #define ASC_DBG(lvl, s)
3636 #define ASC_DBG1(lvl, s, a1)
3637 #define ASC_DBG2(lvl, s, a1, a2)
3638 #define ASC_DBG3(lvl, s, a1, a2, a3)
3639 #define ASC_DBG4(lvl, s, a1, a2, a3, a4)
3640 #define ASC_DBG_PRT_SCSI_HOST(lvl, s)
3641 #define ASC_DBG_PRT_SCSI_CMND(lvl, s)
3642 #define ASC_DBG_PRT_ASC_SCSI_Q(lvl, scsiqp)
3643 #define ASC_DBG_PRT_ADV_SCSI_REQ_Q(lvl, scsiqp)
3644 #define ASC_DBG_PRT_ASC_QDONE_INFO(lvl, qdone)
3645 #define ADV_DBG_PRT_ADV_SCSI_REQ_Q(lvl, scsiqp)
3646 #define ASC_DBG_PRT_HEX(lvl, name, start, length)
3647 #define ASC_DBG_PRT_CDB(lvl, cdb, len)
3648 #define ASC_DBG_PRT_SENSE(lvl, sense, len)
3649 #define ASC_DBG_PRT_INQUIRY(lvl, inq, len)
3650
3651 #else /* ADVANSYS_DEBUG */
3652
3653 /*
3654  * Debugging Message Levels:
3655  * 0: Errors Only
3656  * 1: High-Level Tracing
3657  * 2-N: Verbose Tracing
3658  */
3659
3660 #define ASC_DBG(lvl, s) \
3661     { \
3662         if (asc_dbglvl >= (lvl)) { \
3663             printk(s); \
3664         } \
3665     }
3666
3667 #define ASC_DBG1(lvl, s, a1) \
3668     { \
3669         if (asc_dbglvl >= (lvl)) { \
3670             printk((s), (a1)); \
3671         } \
3672     }
3673
3674 #define ASC_DBG2(lvl, s, a1, a2) \
3675     { \
3676         if (asc_dbglvl >= (lvl)) { \
3677             printk((s), (a1), (a2)); \
3678         } \
3679     }
3680
3681 #define ASC_DBG3(lvl, s, a1, a2, a3) \
3682     { \
3683         if (asc_dbglvl >= (lvl)) { \
3684             printk((s), (a1), (a2), (a3)); \
3685         } \
3686     }
3687
3688 #define ASC_DBG4(lvl, s, a1, a2, a3, a4) \
3689     { \
3690         if (asc_dbglvl >= (lvl)) { \
3691             printk((s), (a1), (a2), (a3), (a4)); \
3692         } \
3693     }
3694
3695 #define ASC_DBG_PRT_SCSI_HOST(lvl, s) \
3696     { \
3697         if (asc_dbglvl >= (lvl)) { \
3698             asc_prt_scsi_host(s); \
3699         } \
3700     }
3701
3702 #define ASC_DBG_PRT_SCSI_CMND(lvl, s) \
3703     { \
3704         if (asc_dbglvl >= (lvl)) { \
3705             asc_prt_scsi_cmnd(s); \
3706         } \
3707     }
3708
3709 #define ASC_DBG_PRT_ASC_SCSI_Q(lvl, scsiqp) \
3710     { \
3711         if (asc_dbglvl >= (lvl)) { \
3712             asc_prt_asc_scsi_q(scsiqp); \
3713         } \
3714     }
3715
3716 #define ASC_DBG_PRT_ASC_QDONE_INFO(lvl, qdone) \
3717     { \
3718         if (asc_dbglvl >= (lvl)) { \
3719             asc_prt_asc_qdone_info(qdone); \
3720         } \
3721     }
3722
3723 #define ASC_DBG_PRT_ADV_SCSI_REQ_Q(lvl, scsiqp) \
3724     { \
3725         if (asc_dbglvl >= (lvl)) { \
3726             asc_prt_adv_scsi_req_q(scsiqp); \
3727         } \
3728     }
3729
3730 #define ASC_DBG_PRT_HEX(lvl, name, start, length) \
3731     { \
3732         if (asc_dbglvl >= (lvl)) { \
3733             asc_prt_hex((name), (start), (length)); \
3734         } \
3735     }
3736
3737 #define ASC_DBG_PRT_CDB(lvl, cdb, len) \
3738         ASC_DBG_PRT_HEX((lvl), "CDB", (uchar *) (cdb), (len));
3739
3740 #define ASC_DBG_PRT_SENSE(lvl, sense, len) \
3741         ASC_DBG_PRT_HEX((lvl), "SENSE", (uchar *) (sense), (len));
3742
3743 #define ASC_DBG_PRT_INQUIRY(lvl, inq, len) \
3744         ASC_DBG_PRT_HEX((lvl), "INQUIRY", (uchar *) (inq), (len));
3745 #endif /* ADVANSYS_DEBUG */
3746
3747 #ifndef ADVANSYS_ASSERT
3748 #define ASC_ASSERT(a)
3749 #else /* ADVANSYS_ASSERT */
3750
3751 #define ASC_ASSERT(a) \
3752     { \
3753         if (!(a)) { \
3754             printk("ASC_ASSERT() Failure: file %s, line %d\n", \
3755                 __FILE__, __LINE__); \
3756         } \
3757     }
3758
3759 #endif /* ADVANSYS_ASSERT */
3760
3761
3762 /*
3763  * --- Driver Structures
3764  */
3765
3766 #ifdef ADVANSYS_STATS
3767
3768 /* Per board statistics structure */
3769 struct asc_stats {
3770     /* Driver Entrypoint Statistics */
3771     ADV_DCNT queuecommand;    /* # calls to advansys_queuecommand() */
3772     ADV_DCNT reset;           /* # calls to advansys_eh_bus_reset() */
3773     ADV_DCNT biosparam;       /* # calls to advansys_biosparam() */
3774     ADV_DCNT interrupt;       /* # advansys_interrupt() calls */
3775     ADV_DCNT callback;        /* # calls to asc/adv_isr_callback() */
3776     ADV_DCNT done;            /* # calls to request's scsi_done function */
3777     ADV_DCNT build_error;     /* # asc/adv_build_req() ASC_ERROR returns. */
3778     ADV_DCNT adv_build_noreq; /* # adv_build_req() adv_req_t alloc. fail. */
3779     ADV_DCNT adv_build_nosg;  /* # adv_build_req() adv_sgblk_t alloc. fail. */
3780     /* AscExeScsiQueue()/AdvExeScsiQueue() Statistics */
3781     ADV_DCNT exe_noerror;     /* # ASC_NOERROR returns. */
3782     ADV_DCNT exe_busy;        /* # ASC_BUSY returns. */
3783     ADV_DCNT exe_error;       /* # ASC_ERROR returns. */
3784     ADV_DCNT exe_unknown;     /* # unknown returns. */
3785     /* Data Transfer Statistics */
3786     ADV_DCNT cont_cnt;        /* # non-scatter-gather I/O requests received */
3787     ADV_DCNT cont_xfer;       /* # contiguous transfer 512-bytes */
3788     ADV_DCNT sg_cnt;          /* # scatter-gather I/O requests received */
3789     ADV_DCNT sg_elem;         /* # scatter-gather elements */
3790     ADV_DCNT sg_xfer;         /* # scatter-gather transfer 512-bytes */
3791 };
3792 #endif /* ADVANSYS_STATS */
3793
3794 /*
3795  * Request queuing structure
3796  */
3797 typedef struct asc_queue {
3798     ADV_SCSI_BIT_ID_TYPE  q_tidmask;                /* queue mask */
3799     REQP                  q_first[ADV_MAX_TID+1];   /* first queued request */
3800     REQP                  q_last[ADV_MAX_TID+1];    /* last queued request */
3801 #ifdef ADVANSYS_STATS
3802     short                 q_cur_cnt[ADV_MAX_TID+1]; /* current queue count */
3803     short                 q_max_cnt[ADV_MAX_TID+1]; /* maximum queue count */
3804     ADV_DCNT              q_tot_cnt[ADV_MAX_TID+1]; /* total enqueue count */
3805     ADV_DCNT              q_tot_tim[ADV_MAX_TID+1]; /* total time queued */
3806     ushort                q_max_tim[ADV_MAX_TID+1]; /* maximum time queued */
3807     ushort                q_min_tim[ADV_MAX_TID+1]; /* minimum time queued */
3808 #endif /* ADVANSYS_STATS */
3809 } asc_queue_t;
3810
3811 /*
3812  * Adv Library Request Structures
3813  *
3814  * The following two structures are used to process Wide Board requests.
3815  *
3816  * The ADV_SCSI_REQ_Q structure in adv_req_t is passed to the Adv Library
3817  * and microcode with the ADV_SCSI_REQ_Q field 'srb_ptr' pointing to the
3818  * adv_req_t. The adv_req_t structure 'cmndp' field in turn points to the
3819  * Mid-Level SCSI request structure.
3820  *
3821  * Zero or more ADV_SG_BLOCK are used with each ADV_SCSI_REQ_Q. Each
3822  * ADV_SG_BLOCK structure holds 15 scatter-gather elements. Under Linux
3823  * up to 255 scatter-gather elements may be used per request or
3824  * ADV_SCSI_REQ_Q.
3825  *
3826  * Both structures must be 32 byte aligned.
3827  */
3828 typedef struct adv_sgblk {
3829     ADV_SG_BLOCK        sg_block;     /* Sgblock structure. */
3830     uchar               align[32];    /* Sgblock structure padding. */
3831     struct adv_sgblk    *next_sgblkp; /* Next scatter-gather structure. */
3832 } adv_sgblk_t;
3833
3834 typedef struct adv_req {
3835     ADV_SCSI_REQ_Q      scsi_req_q;   /* Adv Library request structure. */
3836     uchar               align[32];    /* Request structure padding. */
3837     struct scsi_cmnd    *cmndp;       /* Mid-Level SCSI command pointer. */
3838     adv_sgblk_t         *sgblkp;      /* Adv Library scatter-gather pointer. */
3839     struct adv_req      *next_reqp;   /* Next Request Structure. */
3840 } adv_req_t;
3841
3842 /*
3843  * Structure allocated for each board.
3844  *
3845  * This structure is allocated by scsi_register() at the end
3846  * of the 'Scsi_Host' structure starting at the 'hostdata'
3847  * field. It is guaranteed to be allocated from DMA-able memory.
3848  */
3849 typedef struct asc_board {
3850     int                  id;                    /* Board Id */
3851     uint                 flags;                 /* Board flags */
3852     union {
3853         ASC_DVC_VAR      asc_dvc_var;           /* Narrow board */
3854         ADV_DVC_VAR      adv_dvc_var;           /* Wide board */
3855     } dvc_var;
3856     union {
3857         ASC_DVC_CFG      asc_dvc_cfg;           /* Narrow board */
3858         ADV_DVC_CFG      adv_dvc_cfg;           /* Wide board */
3859     } dvc_cfg;
3860     ushort               asc_n_io_port;         /* Number I/O ports. */
3861     asc_queue_t          active;                /* Active command queue */
3862     asc_queue_t          waiting;               /* Waiting command queue */
3863     asc_queue_t          done;                  /* Done command queue */
3864     ADV_SCSI_BIT_ID_TYPE init_tidmask;          /* Target init./valid mask */
3865     struct scsi_device  *device[ADV_MAX_TID+1]; /* Mid-Level Scsi Device */
3866     ushort               reqcnt[ADV_MAX_TID+1]; /* Starvation request count */
3867     ADV_SCSI_BIT_ID_TYPE queue_full;            /* Queue full mask */
3868     ushort               queue_full_cnt[ADV_MAX_TID+1]; /* Queue full count */
3869     union {
3870         ASCEEP_CONFIG         asc_eep;          /* Narrow EEPROM config. */
3871         ADVEEP_3550_CONFIG    adv_3550_eep;     /* 3550 EEPROM config. */
3872         ADVEEP_38C0800_CONFIG adv_38C0800_eep;  /* 38C0800 EEPROM config. */
3873         ADVEEP_38C1600_CONFIG adv_38C1600_eep;  /* 38C1600 EEPROM config. */
3874     } eep_config;
3875     ulong                last_reset;            /* Saved last reset time */
3876     spinlock_t lock;                            /* Board spinlock */
3877 #ifdef CONFIG_PROC_FS
3878     /* /proc/scsi/advansys/[0...] */
3879     char                 *prtbuf;               /* /proc print buffer */
3880 #endif /* CONFIG_PROC_FS */
3881 #ifdef ADVANSYS_STATS
3882     struct asc_stats     asc_stats;             /* Board statistics */
3883 #endif /* ADVANSYS_STATS */
3884     /*
3885      * The following fields are used only for Narrow Boards.
3886      */
3887     /* The following three structures must be in DMA-able memory. */
3888     ASC_SCSI_REQ_Q       scsireqq;
3889     ASC_CAP_INFO         cap_info;
3890     ASC_SCSI_INQUIRY     inquiry;
3891     uchar                sdtr_data[ASC_MAX_TID+1]; /* SDTR information */
3892     /*
3893      * The following fields are used only for Wide Boards.
3894      */
3895     void                 *ioremap_addr;         /* I/O Memory remap address. */
3896     ushort               ioport;                /* I/O Port address. */
3897     ADV_CARR_T           *orig_carrp;           /* ADV_CARR_T memory block. */
3898     adv_req_t            *orig_reqp;            /* adv_req_t memory block. */
3899     adv_req_t            *adv_reqp;             /* Request structures. */
3900     adv_sgblk_t          *adv_sgblkp;           /* Scatter-gather structures. */
3901     ushort               bios_signature;        /* BIOS Signature. */
3902     ushort               bios_version;          /* BIOS Version. */
3903     ushort               bios_codeseg;          /* BIOS Code Segment. */
3904     ushort               bios_codelen;          /* BIOS Code Segment Length. */
3905 } asc_board_t;
3906
3907 /*
3908  * PCI configuration structures
3909  */
3910 typedef struct _PCI_DATA_
3911 {
3912     uchar    type;
3913     uchar    bus;
3914     uchar    slot;
3915     uchar    func;
3916     uchar    offset;
3917 } PCI_DATA;
3918
3919 typedef struct _PCI_DEVICE_
3920 {
3921     ushort   vendorID;
3922     ushort   deviceID;
3923     ushort   slotNumber;
3924     ushort   slotFound;
3925     uchar    busNumber;
3926     uchar    maxBusNumber;
3927     uchar    devFunc;
3928     ushort   startSlot;
3929     ushort   endSlot;
3930     uchar    bridge;
3931     uchar    type;
3932 } PCI_DEVICE;
3933
3934 typedef struct _PCI_CONFIG_SPACE_
3935 {
3936     ushort   vendorID;
3937     ushort   deviceID;
3938     ushort   command;
3939     ushort   status;
3940     uchar    revision;
3941     uchar    classCode[3];
3942     uchar    cacheSize;
3943     uchar    latencyTimer;
3944     uchar    headerType;
3945     uchar    bist;
3946     ADV_PADDR baseAddress[6];
3947     ushort   reserved[4];
3948     ADV_PADDR optionRomAddr;
3949     ushort   reserved2[4];
3950     uchar    irqLine;
3951     uchar    irqPin;
3952     uchar    minGnt;
3953     uchar    maxLatency;
3954 } PCI_CONFIG_SPACE;
3955
3956
3957 /*
3958  * --- Driver Data
3959  */
3960
3961 /* Note: All driver global data should be initialized. */
3962
3963 /* Number of boards detected in system. */
3964 STATIC int asc_board_count = 0;
3965 STATIC struct Scsi_Host    *asc_host[ASC_NUM_BOARD_SUPPORTED] = { 0 };
3966
3967 /* Overrun buffer used by all narrow boards. */
3968 STATIC uchar overrun_buf[ASC_OVERRUN_BSIZE] = { 0 };
3969
3970 /*
3971  * Global structures required to issue a command.
3972  */
3973 STATIC ASC_SCSI_Q asc_scsi_q = { { 0 } };
3974 STATIC ASC_SG_HEAD asc_sg_head = { 0 };
3975
3976 /* List of supported bus types. */
3977 STATIC ushort asc_bus[ASC_NUM_BUS] __initdata = {
3978     ASC_IS_ISA,
3979     ASC_IS_VL,
3980     ASC_IS_EISA,
3981     ASC_IS_PCI,
3982 };
3983
3984 /*
3985  * Used with the LILO 'advansys' option to eliminate or
3986  * limit I/O port probing at boot time, cf. advansys_setup().
3987  */
3988 STATIC int asc_iopflag = ASC_FALSE;
3989 STATIC int asc_ioport[ASC_NUM_IOPORT_PROBE] = { 0, 0, 0, 0 };
3990
3991 #ifdef ADVANSYS_DEBUG
3992 STATIC char *
3993 asc_bus_name[ASC_NUM_BUS] = {
3994     "ASC_IS_ISA",
3995     "ASC_IS_VL",
3996     "ASC_IS_EISA",
3997     "ASC_IS_PCI",
3998 };
3999
4000 STATIC int          asc_dbglvl = 3;
4001 #endif /* ADVANSYS_DEBUG */
4002
4003 /* Declaration for Asc Library internal data referenced by driver. */
4004 STATIC PortAddr     _asc_def_iop_base[];
4005
4006
4007 /*
4008  * --- Driver Function Prototypes
4009  *
4010  * advansys.h contains function prototypes for functions global to Linux.
4011  */
4012
4013 STATIC irqreturn_t advansys_interrupt(int, void *, struct pt_regs *);
4014 STATIC int        advansys_slave_configure(struct scsi_device *);
4015 STATIC void       asc_scsi_done_list(struct scsi_cmnd *);
4016 STATIC int        asc_execute_scsi_cmnd(struct scsi_cmnd *);
4017 STATIC int        asc_build_req(asc_board_t *, struct scsi_cmnd *);
4018 STATIC int        adv_build_req(asc_board_t *, struct scsi_cmnd *, ADV_SCSI_REQ_Q **);
4019 STATIC int        adv_get_sglist(asc_board_t *, adv_req_t *, struct scsi_cmnd *, int);
4020 STATIC void       asc_isr_callback(ASC_DVC_VAR *, ASC_QDONE_INFO *);
4021 STATIC void       adv_isr_callback(ADV_DVC_VAR *, ADV_SCSI_REQ_Q *);
4022 STATIC void       adv_async_callback(ADV_DVC_VAR *, uchar);
4023 STATIC void       asc_enqueue(asc_queue_t *, REQP, int);
4024 STATIC REQP       asc_dequeue(asc_queue_t *, int);
4025 STATIC REQP       asc_dequeue_list(asc_queue_t *, REQP *, int);
4026 STATIC int        asc_rmqueue(asc_queue_t *, REQP);
4027 STATIC void       asc_execute_queue(asc_queue_t *);
4028 #ifdef CONFIG_PROC_FS
4029 STATIC int        asc_proc_copy(off_t, off_t, char *, int , char *, int);
4030 STATIC int        asc_prt_board_devices(struct Scsi_Host *, char *, int);
4031 STATIC int        asc_prt_adv_bios(struct Scsi_Host *, char *, int);
4032 STATIC int        asc_get_eeprom_string(ushort *serialnum, uchar *cp);
4033 STATIC int        asc_prt_asc_board_eeprom(struct Scsi_Host *, char *, int);
4034 STATIC int        asc_prt_adv_board_eeprom(struct Scsi_Host *, char *, int);
4035 STATIC int        asc_prt_driver_conf(struct Scsi_Host *, char *, int);
4036 STATIC int        asc_prt_asc_board_info(struct Scsi_Host *, char *, int);
4037 STATIC int        asc_prt_adv_board_info(struct Scsi_Host *, char *, int);
4038 STATIC int        asc_prt_line(char *, int, char *fmt, ...);
4039 #endif /* CONFIG_PROC_FS */
4040
4041 /* Declaration for Asc Library internal functions referenced by driver. */
4042 STATIC int          AscFindSignature(PortAddr);
4043 STATIC ushort       AscGetEEPConfig(PortAddr, ASCEEP_CONFIG *, ushort);
4044
4045 /* Statistics function prototypes. */
4046 #ifdef ADVANSYS_STATS
4047 #ifdef CONFIG_PROC_FS
4048 STATIC int          asc_prt_board_stats(struct Scsi_Host *, char *, int);
4049 STATIC int          asc_prt_target_stats(struct Scsi_Host *, int, char *, int);
4050 #endif /* CONFIG_PROC_FS */
4051 #endif /* ADVANSYS_STATS */
4052
4053 /* Debug function prototypes. */
4054 #ifdef ADVANSYS_DEBUG
4055 STATIC void         asc_prt_scsi_host(struct Scsi_Host *);
4056 STATIC void         asc_prt_scsi_cmnd(struct scsi_cmnd *);
4057 STATIC void         asc_prt_asc_dvc_cfg(ASC_DVC_CFG *);
4058 STATIC void         asc_prt_asc_dvc_var(ASC_DVC_VAR *);
4059 STATIC void         asc_prt_asc_scsi_q(ASC_SCSI_Q *);
4060 STATIC void         asc_prt_asc_qdone_info(ASC_QDONE_INFO *);
4061 STATIC void         asc_prt_adv_dvc_cfg(ADV_DVC_CFG *);
4062 STATIC void         asc_prt_adv_dvc_var(ADV_DVC_VAR *);
4063 STATIC void         asc_prt_adv_scsi_req_q(ADV_SCSI_REQ_Q *);
4064 STATIC void         asc_prt_adv_sgblock(int, ADV_SG_BLOCK *);
4065 STATIC void         asc_prt_hex(char *f, uchar *, int);
4066 #endif /* ADVANSYS_DEBUG */
4067
4068
4069 /*
4070  * --- Linux 'Scsi_Host_Template' and advansys_setup() Functions
4071  */
4072
4073 #ifdef CONFIG_PROC_FS
4074 /*
4075  * advansys_proc_info() - /proc/scsi/advansys/[0-(ASC_NUM_BOARD_SUPPORTED-1)]
4076  *
4077  * *buffer: I/O buffer
4078  * **start: if inout == FALSE pointer into buffer where user read should start
4079  * offset: current offset into a /proc/scsi/advansys/[0...] file
4080  * length: length of buffer
4081  * hostno: Scsi_Host host_no
4082  * inout: TRUE - user is writing; FALSE - user is reading
4083  *
4084  * Return the number of bytes read from or written to a
4085  * /proc/scsi/advansys/[0...] file.
4086  *
4087  * Note: This function uses the per board buffer 'prtbuf' which is
4088  * allocated when the board is initialized in advansys_detect(). The
4089  * buffer is ASC_PRTBUF_SIZE bytes. The function asc_proc_copy() is
4090  * used to write to the buffer. The way asc_proc_copy() is written
4091  * if 'prtbuf' is too small it will not be overwritten. Instead the
4092  * user just won't get all the available statistics.
4093  */
4094 int
4095 advansys_proc_info(struct Scsi_Host *shost, char *buffer, char **start,
4096                 off_t offset, int length, int inout)
4097 {
4098     struct Scsi_Host    *shp;
4099     asc_board_t         *boardp;
4100     int                 i;
4101     char                *cp;
4102     int                 cplen;
4103     int                 cnt;
4104     int                 totcnt;
4105     int                 leftlen;
4106     char                *curbuf;
4107     off_t               advoffset;
4108 #ifdef ADVANSYS_STATS
4109     int                 tgt_id;
4110 #endif /* ADVANSYS_STATS */
4111
4112     ASC_DBG(1, "advansys_proc_info: begin\n");
4113
4114     /*
4115      * User write not supported.
4116      */
4117     if (inout == TRUE) {
4118         return(-ENOSYS);
4119     }
4120
4121     /*
4122      * User read of /proc/scsi/advansys/[0...] file.
4123      */
4124
4125     /* Find the specified board. */
4126     for (i = 0; i < asc_board_count; i++) {
4127         if (asc_host[i]->host_no == shost->host_no) {
4128             break;
4129         }
4130     }
4131     if (i == asc_board_count) {
4132         return(-ENOENT);
4133     }
4134
4135     shp = asc_host[i];
4136     boardp = ASC_BOARDP(shp);
4137
4138     /* Copy read data starting at the beginning of the buffer. */
4139     *start = buffer;
4140     curbuf = buffer;
4141     advoffset = 0;
4142     totcnt = 0;
4143     leftlen = length;
4144
4145     /*
4146      * Get board configuration information.
4147      *
4148      * advansys_info() returns the board string from its own static buffer.
4149      */
4150     cp = (char *) advansys_info(shp);
4151     strcat(cp, "\n");
4152     cplen = strlen(cp);
4153     /* Copy board information. */
4154     cnt = asc_proc_copy(advoffset, offset, curbuf, leftlen, cp, cplen);
4155     totcnt += cnt;
4156     leftlen -= cnt;
4157     if (leftlen == 0) {
4158         ASC_DBG1(1, "advansys_proc_info: totcnt %d\n", totcnt);
4159         return totcnt;
4160     }
4161     advoffset += cplen;
4162     curbuf += cnt;
4163
4164     /*
4165      * Display Wide Board BIOS Information.
4166      */
4167     if (ASC_WIDE_BOARD(boardp)) {
4168         cp = boardp->prtbuf;
4169         cplen = asc_prt_adv_bios(shp, cp, ASC_PRTBUF_SIZE);
4170         ASC_ASSERT(cplen < ASC_PRTBUF_SIZE);
4171         cnt = asc_proc_copy(advoffset, offset, curbuf, leftlen, cp, cplen);
4172         totcnt += cnt;
4173         leftlen -= cnt;
4174         if (leftlen == 0) {
4175             ASC_DBG1(1, "advansys_proc_info: totcnt %d\n", totcnt);
4176             return totcnt;
4177         }
4178         advoffset += cplen;
4179         curbuf += cnt;
4180     }
4181
4182     /*
4183      * Display driver information for each device attached to the board.
4184      */
4185     cp = boardp->prtbuf;
4186     cplen = asc_prt_board_devices(shp, cp, ASC_PRTBUF_SIZE);
4187     ASC_ASSERT(cplen < ASC_PRTBUF_SIZE);
4188     cnt = asc_proc_copy(advoffset, offset, curbuf, leftlen, cp, cplen);
4189     totcnt += cnt;
4190     leftlen -= cnt;
4191     if (leftlen == 0) {
4192         ASC_DBG1(1, "advansys_proc_info: totcnt %d\n", totcnt);
4193         return totcnt;
4194     }
4195     advoffset += cplen;
4196     curbuf += cnt;
4197
4198     /*
4199      * Display EEPROM configuration for the board.
4200      */
4201     cp = boardp->prtbuf;
4202     if (ASC_NARROW_BOARD(boardp)) {
4203         cplen = asc_prt_asc_board_eeprom(shp, cp, ASC_PRTBUF_SIZE);
4204     } else {
4205         cplen = asc_prt_adv_board_eeprom(shp, cp, ASC_PRTBUF_SIZE);
4206     }
4207     ASC_ASSERT(cplen < ASC_PRTBUF_SIZE);
4208     cnt = asc_proc_copy(advoffset, offset, curbuf, leftlen, cp, cplen);
4209     totcnt += cnt;
4210     leftlen -= cnt;
4211     if (leftlen == 0) {
4212         ASC_DBG1(1, "advansys_proc_info: totcnt %d\n", totcnt);
4213         return totcnt;
4214     }
4215     advoffset += cplen;
4216     curbuf += cnt;
4217
4218     /*
4219      * Display driver configuration and information for the board.
4220      */
4221     cp = boardp->prtbuf;
4222     cplen = asc_prt_driver_conf(shp, cp, ASC_PRTBUF_SIZE);
4223     ASC_ASSERT(cplen < ASC_PRTBUF_SIZE);
4224     cnt = asc_proc_copy(advoffset, offset, curbuf, leftlen, cp, cplen);
4225     totcnt += cnt;
4226     leftlen -= cnt;
4227     if (leftlen == 0) {
4228         ASC_DBG1(1, "advansys_proc_info: totcnt %d\n", totcnt);
4229         return totcnt;
4230     }
4231     advoffset += cplen;
4232     curbuf += cnt;
4233
4234 #ifdef ADVANSYS_STATS
4235     /*
4236      * Display driver statistics for the board.
4237      */
4238     cp = boardp->prtbuf;
4239     cplen = asc_prt_board_stats(shp, cp, ASC_PRTBUF_SIZE);
4240     ASC_ASSERT(cplen <= ASC_PRTBUF_SIZE);
4241     cnt = asc_proc_copy(advoffset, offset, curbuf, leftlen, cp, cplen);
4242     totcnt += cnt;
4243     leftlen -= cnt;
4244     if (leftlen == 0) {
4245         ASC_DBG1(1, "advansys_proc_info: totcnt %d\n", totcnt);
4246         return totcnt;
4247     }
4248     advoffset += cplen;
4249     curbuf += cnt;
4250
4251     /*
4252      * Display driver statistics for each target.
4253      */
4254     for (tgt_id = 0; tgt_id <= ADV_MAX_TID; tgt_id++) {
4255       cp = boardp->prtbuf;
4256       cplen = asc_prt_target_stats(shp, tgt_id, cp, ASC_PRTBUF_SIZE);
4257       ASC_ASSERT(cplen <= ASC_PRTBUF_SIZE);
4258       cnt = asc_proc_copy(advoffset, offset, curbuf, leftlen, cp, cplen);
4259       totcnt += cnt;
4260       leftlen -= cnt;
4261       if (leftlen == 0) {
4262         ASC_DBG1(1, "advansys_proc_info: totcnt %d\n", totcnt);
4263         return totcnt;
4264       }
4265       advoffset += cplen;
4266       curbuf += cnt;
4267     }
4268 #endif /* ADVANSYS_STATS */
4269
4270     /*
4271      * Display Asc Library dynamic configuration information
4272      * for the board.
4273      */
4274     cp = boardp->prtbuf;
4275     if (ASC_NARROW_BOARD(boardp)) {
4276         cplen = asc_prt_asc_board_info(shp, cp, ASC_PRTBUF_SIZE);
4277     } else {
4278         cplen = asc_prt_adv_board_info(shp, cp, ASC_PRTBUF_SIZE);
4279     }
4280     ASC_ASSERT(cplen < ASC_PRTBUF_SIZE);
4281     cnt = asc_proc_copy(advoffset, offset, curbuf, leftlen, cp, cplen);
4282     totcnt += cnt;
4283     leftlen -= cnt;
4284     if (leftlen == 0) {
4285         ASC_DBG1(1, "advansys_proc_info: totcnt %d\n", totcnt);
4286         return totcnt;
4287     }
4288     advoffset += cplen;
4289     curbuf += cnt;
4290
4291     ASC_DBG1(1, "advansys_proc_info: totcnt %d\n", totcnt);
4292
4293     return totcnt;
4294 }
4295 #endif /* CONFIG_PROC_FS */
4296
4297 /*
4298  * advansys_detect()
4299  *
4300  * Detect function for AdvanSys adapters.
4301  *
4302  * Argument is a pointer to the host driver's scsi_hosts entry.
4303  *
4304  * Return number of adapters found.
4305  *
4306  * Note: Because this function is called during system initialization
4307  * it must not call SCSI mid-level functions including scsi_malloc()
4308  * and scsi_free().
4309  */
4310 int __init
4311 advansys_detect(struct scsi_host_template *tpnt)
4312 {
4313     static int          detect_called = ASC_FALSE;
4314     int                 iop;
4315     int                 bus;
4316     struct Scsi_Host    *shp = NULL;
4317     asc_board_t         *boardp = NULL;
4318     ASC_DVC_VAR         *asc_dvc_varp = NULL;
4319     ADV_DVC_VAR         *adv_dvc_varp = NULL;
4320     adv_sgblk_t         *sgp = NULL;
4321     int                 ioport = 0;
4322     int                 share_irq = FALSE;
4323     int                 iolen = 0;
4324 #ifdef CONFIG_PCI
4325     int                 pci_init_search = 0;
4326     struct pci_dev      *pci_devicep[ASC_NUM_BOARD_SUPPORTED];
4327     int                 pci_card_cnt_max = 0;
4328     int                 pci_card_cnt = 0;
4329     struct device       *dev = NULL;
4330     struct pci_dev      *pci_devp = NULL;
4331     int                 pci_device_id_cnt = 0;
4332     unsigned int        pci_device_id[ASC_PCI_DEVICE_ID_CNT] = {
4333                                     ASC_PCI_DEVICE_ID_1100,
4334                                     ASC_PCI_DEVICE_ID_1200,
4335                                     ASC_PCI_DEVICE_ID_1300,
4336                                     ASC_PCI_DEVICE_ID_2300,
4337                                     ASC_PCI_DEVICE_ID_2500,
4338                                     ASC_PCI_DEVICE_ID_2700
4339                         };
4340     ADV_PADDR           pci_memory_address;
4341 #endif /* CONFIG_PCI */
4342     int                 warn_code, err_code;
4343     int                 ret;
4344
4345     if (detect_called == ASC_FALSE) {
4346         detect_called = ASC_TRUE;
4347     } else {
4348         printk("AdvanSys SCSI: advansys_detect() multiple calls ignored\n");
4349         return 0;
4350     }
4351
4352     ASC_DBG(1, "advansys_detect: begin\n");
4353
4354     asc_board_count = 0;
4355
4356     /*
4357      * If I/O port probing has been modified, then verify and
4358      * clean-up the 'asc_ioport' list.
4359      */
4360     if (asc_iopflag == ASC_TRUE) {
4361         for (ioport = 0; ioport < ASC_NUM_IOPORT_PROBE; ioport++) {
4362             ASC_DBG2(1, "advansys_detect: asc_ioport[%d] 0x%x\n",
4363                 ioport, asc_ioport[ioport]);
4364             if (asc_ioport[ioport] != 0) {
4365                 for (iop = 0; iop < ASC_IOADR_TABLE_MAX_IX; iop++) {
4366                     if (_asc_def_iop_base[iop] == asc_ioport[ioport]) {
4367                         break;
4368                     }
4369                 }
4370                 if (iop == ASC_IOADR_TABLE_MAX_IX) {
4371                     printk(
4372 "AdvanSys SCSI: specified I/O Port 0x%X is invalid\n",
4373                         asc_ioport[ioport]);
4374                     asc_ioport[ioport] = 0;
4375                 }
4376             }
4377         }
4378         ioport = 0;
4379     }
4380
4381     for (bus = 0; bus < ASC_NUM_BUS; bus++) {
4382
4383         ASC_DBG2(1, "advansys_detect: bus search type %d (%s)\n",
4384             bus, asc_bus_name[bus]);
4385         iop = 0;
4386
4387         while (asc_board_count < ASC_NUM_BOARD_SUPPORTED) {
4388
4389             ASC_DBG1(2, "advansys_detect: asc_board_count %d\n",
4390                 asc_board_count);
4391
4392             switch (asc_bus[bus]) {
4393             case ASC_IS_ISA:
4394             case ASC_IS_VL:
4395 #ifdef CONFIG_ISA
4396                 if (asc_iopflag == ASC_FALSE) {
4397                     iop = AscSearchIOPortAddr(iop, asc_bus[bus]);
4398                 } else {
4399                     /*
4400                      * ISA and VL I/O port scanning has either been
4401                      * eliminated or limited to selected ports on
4402                      * the LILO command line, /etc/lilo.conf, or
4403                      * by setting variables when the module was loaded.
4404                      */
4405                     ASC_DBG(1, "advansys_detect: I/O port scanning modified\n");
4406                 ioport_try_again:
4407                     iop = 0;
4408                     for (; ioport < ASC_NUM_IOPORT_PROBE; ioport++) {
4409                         if ((iop = asc_ioport[ioport]) != 0) {
4410                             break;
4411                         }
4412                     }
4413                     if (iop) {
4414                         ASC_DBG1(1,
4415                                 "advansys_detect: probing I/O port 0x%x...\n",
4416                             iop);
4417                         if (check_region(iop, ASC_IOADR_GAP) != 0) {
4418                             printk(
4419 "AdvanSys SCSI: specified I/O Port 0x%X is busy\n", iop);
4420                             /* Don't try this I/O port twice. */
4421                             asc_ioport[ioport] = 0;
4422                             goto ioport_try_again;
4423                         } else if (AscFindSignature(iop) == ASC_FALSE) {
4424                             printk(
4425 "AdvanSys SCSI: specified I/O Port 0x%X has no adapter\n", iop);
4426                             /* Don't try this I/O port twice. */
4427                             asc_ioport[ioport] = 0;
4428                             goto ioport_try_again;
4429                         } else {
4430                             /*
4431                              * If this isn't an ISA board, then it must be
4432                              * a VL board. If currently looking an ISA
4433                              * board is being looked for then try for
4434                              * another ISA board in 'asc_ioport'.
4435                              */
4436                             if (asc_bus[bus] == ASC_IS_ISA &&
4437                                 (AscGetChipVersion(iop, ASC_IS_ISA) &
4438                                  ASC_CHIP_VER_ISA_BIT) == 0) {
4439                                  /*
4440                                   * Don't clear 'asc_ioport[ioport]'. Try
4441                                   * this board again for VL. Increment
4442                                   * 'ioport' past this board.
4443                                   */
4444                                  ioport++;
4445                                  goto ioport_try_again;
4446                             }
4447                         }
4448                         /*
4449                          * This board appears good, don't try the I/O port
4450                          * again by clearing its value. Increment 'ioport'
4451                          * for the next iteration.
4452                          */
4453                         asc_ioport[ioport++] = 0;
4454                     }
4455                 }
4456 #endif /* CONFIG_ISA */
4457                 break;
4458
4459             case ASC_IS_EISA:
4460 #ifdef CONFIG_ISA
4461                 iop = AscSearchIOPortAddr(iop, asc_bus[bus]);
4462 #endif /* CONFIG_ISA */
4463                 break;
4464
4465             case ASC_IS_PCI:
4466 #ifdef CONFIG_PCI
4467                 if (pci_init_search == 0) {
4468                     int i, j;
4469
4470                     pci_init_search = 1;
4471
4472                     /* Find all PCI cards. */
4473                     while (pci_device_id_cnt < ASC_PCI_DEVICE_ID_CNT) {
4474                         if ((pci_devp = pci_find_device(ASC_PCI_VENDORID,
4475                             pci_device_id[pci_device_id_cnt], pci_devp)) ==
4476                             NULL) {
4477                             pci_device_id_cnt++;
4478                         } else {
4479                             if (pci_enable_device(pci_devp) == 0) {
4480                                 pci_devicep[pci_card_cnt_max++] = pci_devp;
4481                             }
4482                         }
4483                     }
4484
4485                     /*
4486                      * Sort PCI cards in ascending order by PCI Bus, Slot,
4487                      * and Device Number.
4488                      */
4489                     for (i = 0; i < pci_card_cnt_max - 1; i++)
4490                     {
4491                         for (j = i + 1; j < pci_card_cnt_max; j++) {
4492                             if ((pci_devicep[j]->bus->number <
4493                                  pci_devicep[i]->bus->number) ||
4494                                 ((pci_devicep[j]->bus->number ==
4495                                   pci_devicep[i]->bus->number) &&
4496                                   (pci_devicep[j]->devfn <
4497                                    pci_devicep[i]->devfn))) {
4498                                 pci_devp = pci_devicep[i];
4499                                 pci_devicep[i] = pci_devicep[j];
4500                                 pci_devicep[j] = pci_devp;
4501                             }
4502                         }
4503                     }
4504
4505                     pci_card_cnt = 0;
4506                 } else {
4507                     pci_card_cnt++;
4508                 }
4509
4510                 if (pci_card_cnt == pci_card_cnt_max) {
4511                     iop = 0;
4512                 } else {
4513                     pci_devp = pci_devicep[pci_card_cnt];
4514
4515                     ASC_DBG2(2,
4516                         "advansys_detect: devfn %d, bus number %d\n",
4517                         pci_devp->devfn, pci_devp->bus->number);
4518                     iop = pci_resource_start(pci_devp, 0);
4519                     ASC_DBG2(1,
4520                         "advansys_detect: vendorID %X, deviceID %X\n",
4521                         pci_devp->vendor, pci_devp->device);
4522                     ASC_DBG2(2, "advansys_detect: iop %X, irqLine %d\n",
4523                         iop, pci_devp->irq);
4524                 }
4525                 if(pci_devp)
4526                     dev = &pci_devp->dev;
4527
4528 #endif /* CONFIG_PCI */
4529                 break;
4530
4531             default:
4532                 ASC_PRINT1("advansys_detect: unknown bus type: %d\n",
4533                     asc_bus[bus]);
4534                 break;
4535             }
4536             ASC_DBG1(1, "advansys_detect: iop 0x%x\n", iop);
4537
4538             /*
4539              * Adapter not found, try next bus type.
4540              */
4541             if (iop == 0) {
4542                 break;
4543             }
4544
4545             /*
4546              * Adapter found.
4547              *
4548              * Register the adapter, get its configuration, and
4549              * initialize it.
4550              */
4551             ASC_DBG(2, "advansys_detect: scsi_register()\n");
4552             shp = scsi_register(tpnt, sizeof(asc_board_t));
4553
4554             if (shp == NULL) {
4555                 continue;
4556             }
4557
4558             scsi_set_device(shp, dev);
4559
4560             /* Save a pointer to the Scsi_Host of each board found. */
4561             asc_host[asc_board_count++] = shp;
4562
4563             /* Initialize private per board data */
4564             boardp = ASC_BOARDP(shp);
4565             memset(boardp, 0, sizeof(asc_board_t));
4566             boardp->id = asc_board_count - 1;
4567
4568             /* Initialize spinlock. */
4569             boardp->lock = SPIN_LOCK_UNLOCKED;
4570
4571             /*
4572              * Handle both narrow and wide boards.
4573              *
4574              * If a Wide board was detected, set the board structure
4575              * wide board flag. Set-up the board structure based on
4576              * the board type.
4577              */
4578 #ifdef CONFIG_PCI
4579             if (asc_bus[bus] == ASC_IS_PCI &&
4580                 (pci_devp->device == ASC_PCI_DEVICE_ID_2300 ||
4581                  pci_devp->device == ASC_PCI_DEVICE_ID_2500 ||
4582                  pci_devp->device == ASC_PCI_DEVICE_ID_2700))
4583             {
4584                 boardp->flags |= ASC_IS_WIDE_BOARD;
4585             }
4586 #endif /* CONFIG_PCI */
4587
4588             if (ASC_NARROW_BOARD(boardp)) {
4589                 ASC_DBG(1, "advansys_detect: narrow board\n");
4590                 asc_dvc_varp = &boardp->dvc_var.asc_dvc_var;
4591                 asc_dvc_varp->bus_type = asc_bus[bus];
4592                 asc_dvc_varp->drv_ptr = boardp;
4593                 asc_dvc_varp->cfg = &boardp->dvc_cfg.asc_dvc_cfg;
4594                 asc_dvc_varp->cfg->overrun_buf = &overrun_buf[0];
4595                 asc_dvc_varp->iop_base = iop;
4596                 asc_dvc_varp->isr_callback = asc_isr_callback;
4597             } else {
4598                 ASC_DBG(1, "advansys_detect: wide board\n");
4599                 adv_dvc_varp = &boardp->dvc_var.adv_dvc_var;
4600                 adv_dvc_varp->drv_ptr = boardp;
4601                 adv_dvc_varp->cfg = &boardp->dvc_cfg.adv_dvc_cfg;
4602                 adv_dvc_varp->isr_callback = adv_isr_callback;
4603                 adv_dvc_varp->async_callback = adv_async_callback;
4604 #ifdef CONFIG_PCI
4605                 if (pci_devp->device == ASC_PCI_DEVICE_ID_2300)
4606                 {
4607                     ASC_DBG(1, "advansys_detect: ASC-3550\n");
4608                     adv_dvc_varp->chip_type = ADV_CHIP_ASC3550;
4609                 } else if (pci_devp->device == ASC_PCI_DEVICE_ID_2500)
4610                 {
4611                     ASC_DBG(1, "advansys_detect: ASC-38C0800\n");
4612                     adv_dvc_varp->chip_type = ADV_CHIP_ASC38C0800;
4613                 } else
4614                 {
4615                     ASC_DBG(1, "advansys_detect: ASC-38C1600\n");
4616                     adv_dvc_varp->chip_type = ADV_CHIP_ASC38C1600;
4617                 }
4618 #endif /* CONFIG_PCI */
4619
4620                 /*
4621                  * Map the board's registers into virtual memory for
4622                  * PCI slave access. Only memory accesses are used to
4623                  * access the board's registers.
4624                  *
4625                  * Note: The PCI register base address is not always
4626                  * page aligned, but the address passed to ioremap()
4627                  * must be page aligned. It is guaranteed that the
4628                  * PCI register base address will not cross a page
4629                  * boundary.
4630                  */
4631                 if (adv_dvc_varp->chip_type == ADV_CHIP_ASC3550)
4632                 {
4633                     iolen = ADV_3550_IOLEN;
4634                 } else if (adv_dvc_varp->chip_type == ADV_CHIP_ASC38C0800)
4635                 {
4636                     iolen = ADV_38C0800_IOLEN;
4637                 } else
4638                 {
4639                     iolen = ADV_38C1600_IOLEN;
4640                 }
4641 #ifdef CONFIG_PCI
4642                 pci_memory_address = pci_resource_start(pci_devp, 1);
4643                 ASC_DBG1(1, "advansys_detect: pci_memory_address: 0x%lx\n",
4644                     (ulong) pci_memory_address);
4645                 if ((boardp->ioremap_addr =
4646                     ioremap(pci_memory_address & PAGE_MASK,
4647                          PAGE_SIZE)) == 0) {
4648                    ASC_PRINT3(
4649 "advansys_detect: board %d: ioremap(%x, %d) returned NULL\n",
4650                        boardp->id, pci_memory_address, iolen);
4651                    scsi_unregister(shp);
4652                    asc_board_count--;
4653                    continue;
4654                 }
4655                 ASC_DBG1(1, "advansys_detect: ioremap_addr: 0x%lx\n",
4656                     (ulong) boardp->ioremap_addr);
4657                 adv_dvc_varp->iop_base = (AdvPortAddr)
4658                     (boardp->ioremap_addr +
4659                      (pci_memory_address - (pci_memory_address & PAGE_MASK)));
4660                 ASC_DBG1(1, "advansys_detect: iop_base: 0x%lx\n",
4661                     adv_dvc_varp->iop_base);
4662 #endif /* CONFIG_PCI */
4663
4664                 /*
4665                  * Even though it isn't used to access wide boards, other
4666                  * than for the debug line below, save I/O Port address so
4667                  * that it can be reported.
4668                  */
4669                 boardp->ioport = iop;
4670
4671                 ASC_DBG2(1,
4672 "advansys_detect: iopb_chip_id_1 0x%x, iopw_chip_id_0 0x%x\n",
4673                     (ushort) inp(iop + 1), (ushort) inpw(iop));
4674             }
4675
4676 #ifdef CONFIG_PROC_FS
4677             /*
4678              * Allocate buffer for printing information from
4679              * /proc/scsi/advansys/[0...].
4680              */
4681             if ((boardp->prtbuf =
4682                 kmalloc(ASC_PRTBUF_SIZE, GFP_ATOMIC)) == NULL) {
4683                 ASC_PRINT3(
4684 "advansys_detect: board %d: kmalloc(%d, %d) returned NULL\n",
4685                     boardp->id, ASC_PRTBUF_SIZE, GFP_ATOMIC);
4686                 scsi_unregister(shp);
4687                 asc_board_count--;
4688                 continue;
4689             }
4690 #endif /* CONFIG_PROC_FS */
4691
4692             if (ASC_NARROW_BOARD(boardp)) {
4693                 asc_dvc_varp->cfg->dev = dev;
4694                 /*
4695                  * Set the board bus type and PCI IRQ before
4696                  * calling AscInitGetConfig().
4697                  */
4698                 switch (asc_dvc_varp->bus_type) {
4699 #ifdef CONFIG_ISA
4700                 case ASC_IS_ISA:
4701                     shp->unchecked_isa_dma = TRUE;
4702                     share_irq = FALSE;
4703                     break;
4704                 case ASC_IS_VL:
4705                     shp->unchecked_isa_dma = FALSE;
4706                     share_irq = FALSE;
4707                     break;
4708                 case ASC_IS_EISA:
4709                     shp->unchecked_isa_dma = FALSE;
4710                     share_irq = TRUE;
4711                     break;
4712 #endif /* CONFIG_ISA */
4713 #ifdef CONFIG_PCI
4714                 case ASC_IS_PCI:
4715                     shp->irq = asc_dvc_varp->irq_no = pci_devp->irq;
4716                     asc_dvc_varp->cfg->pci_slot_info =
4717                         ASC_PCI_MKID(pci_devp->bus->number,
4718                             PCI_SLOT(pci_devp->devfn),
4719                             PCI_FUNC(pci_devp->devfn));
4720                     shp->unchecked_isa_dma = FALSE;
4721                     share_irq = TRUE;
4722                     break;
4723 #endif /* CONFIG_PCI */
4724                 default:
4725                     ASC_PRINT2(
4726 "advansys_detect: board %d: unknown adapter type: %d\n",
4727                         boardp->id, asc_dvc_varp->bus_type);
4728                     shp->unchecked_isa_dma = TRUE;
4729                     share_irq = FALSE;
4730                     break;
4731                 }
4732             } else {
4733                 adv_dvc_varp->cfg->dev = dev;
4734                 /*
4735                  * For Wide boards set PCI information before calling
4736                  * AdvInitGetConfig().
4737                  */
4738 #ifdef CONFIG_PCI
4739                 shp->irq = adv_dvc_varp->irq_no = pci_devp->irq;
4740                 adv_dvc_varp->cfg->pci_slot_info =
4741                     ASC_PCI_MKID(pci_devp->bus->number,
4742                         PCI_SLOT(pci_devp->devfn),
4743                         PCI_FUNC(pci_devp->devfn));
4744                 shp->unchecked_isa_dma = FALSE;
4745                 share_irq = TRUE;
4746 #endif /* CONFIG_PCI */
4747             }
4748
4749             /*
4750              * Read the board configuration.
4751              */
4752             if (ASC_NARROW_BOARD(boardp)) {
4753                  /*
4754                   * NOTE: AscInitGetConfig() may change the board's
4755                   * bus_type value. The asc_bus[bus] value should no
4756                   * longer be used. If the bus_type field must be
4757                   * referenced only use the bit-wise AND operator "&".
4758                   */
4759                 ASC_DBG(2, "advansys_detect: AscInitGetConfig()\n");
4760                 switch(ret = AscInitGetConfig(asc_dvc_varp)) {
4761                 case 0:    /* No error */
4762                     break;
4763                 case ASC_WARN_IO_PORT_ROTATE:
4764                     ASC_PRINT1(
4765 "AscInitGetConfig: board %d: I/O port address modified\n",
4766                         boardp->id);
4767                     break;
4768                 case ASC_WARN_AUTO_CONFIG:
4769                     ASC_PRINT1(
4770 "AscInitGetConfig: board %d: I/O port increment switch enabled\n",
4771                         boardp->id);
4772                     break;
4773                 case ASC_WARN_EEPROM_CHKSUM:
4774                     ASC_PRINT1(
4775 "AscInitGetConfig: board %d: EEPROM checksum error\n",
4776                         boardp->id);
4777                     break;
4778                 case ASC_WARN_IRQ_MODIFIED:
4779                     ASC_PRINT1(
4780 "AscInitGetConfig: board %d: IRQ modified\n",
4781                         boardp->id);
4782                     break;
4783                 case ASC_WARN_CMD_QNG_CONFLICT:
4784                     ASC_PRINT1(
4785 "AscInitGetConfig: board %d: tag queuing enabled w/o disconnects\n",
4786                         boardp->id);
4787                     break;
4788                 default:
4789                     ASC_PRINT2(
4790 "AscInitGetConfig: board %d: unknown warning: 0x%x\n",
4791                         boardp->id, ret);
4792                     break;
4793                 }
4794                 if ((err_code = asc_dvc_varp->err_code) != 0) {
4795                     ASC_PRINT3(
4796 "AscInitGetConfig: board %d error: init_state 0x%x, err_code 0x%x\n",
4797                         boardp->id, asc_dvc_varp->init_state,
4798                         asc_dvc_varp->err_code);
4799                 }
4800             } else {
4801                 ASC_DBG(2, "advansys_detect: AdvInitGetConfig()\n");
4802                 if ((ret = AdvInitGetConfig(adv_dvc_varp)) != 0) {
4803                     ASC_PRINT2("AdvInitGetConfig: board %d: warning: 0x%x\n",
4804                         boardp->id, ret);
4805                 }
4806                 if ((err_code = adv_dvc_varp->err_code) != 0) {
4807                     ASC_PRINT2(
4808 "AdvInitGetConfig: board %d error: err_code 0x%x\n",
4809                         boardp->id, adv_dvc_varp->err_code);
4810                 }
4811             }
4812
4813             if (err_code != 0) {
4814 #ifdef CONFIG_PROC_FS
4815                 kfree(boardp->prtbuf);
4816 #endif /* CONFIG_PROC_FS */
4817                 scsi_unregister(shp);
4818                 asc_board_count--;
4819                 continue;
4820             }
4821
4822             /*
4823              * Save the EEPROM configuration so that it can be displayed
4824              * from /proc/scsi/advansys/[0...].
4825              */
4826             if (ASC_NARROW_BOARD(boardp)) {
4827
4828                 ASCEEP_CONFIG *ep;
4829
4830                 /*
4831                  * Set the adapter's target id bit in the 'init_tidmask' field.
4832                  */
4833                 boardp->init_tidmask |=
4834                     ADV_TID_TO_TIDMASK(asc_dvc_varp->cfg->chip_scsi_id);
4835
4836                 /*
4837                  * Save EEPROM settings for the board.
4838                  */
4839                 ep = &boardp->eep_config.asc_eep;
4840
4841                 ep->init_sdtr = asc_dvc_varp->cfg->sdtr_enable;
4842                 ep->disc_enable = asc_dvc_varp->cfg->disc_enable;
4843                 ep->use_cmd_qng = asc_dvc_varp->cfg->cmd_qng_enabled;
4844                 ASC_EEP_SET_DMA_SPD(ep, asc_dvc_varp->cfg->isa_dma_speed);
4845                 ep->start_motor = asc_dvc_varp->start_motor;
4846                 ep->cntl = asc_dvc_varp->dvc_cntl;
4847                 ep->no_scam = asc_dvc_varp->no_scam;
4848                 ep->max_total_qng = asc_dvc_varp->max_total_qng;
4849                 ASC_EEP_SET_CHIP_ID(ep, asc_dvc_varp->cfg->chip_scsi_id);
4850                 /* 'max_tag_qng' is set to the same value for every device. */
4851                 ep->max_tag_qng = asc_dvc_varp->cfg->max_tag_qng[0];
4852                 ep->adapter_info[0] = asc_dvc_varp->cfg->adapter_info[0];
4853                 ep->adapter_info[1] = asc_dvc_varp->cfg->adapter_info[1];
4854                 ep->adapter_info[2] = asc_dvc_varp->cfg->adapter_info[2];
4855                 ep->adapter_info[3] = asc_dvc_varp->cfg->adapter_info[3];
4856                 ep->adapter_info[4] = asc_dvc_varp->cfg->adapter_info[4];
4857                 ep->adapter_info[5] = asc_dvc_varp->cfg->adapter_info[5];
4858
4859                /*
4860                 * Modify board configuration.
4861                 */
4862                 ASC_DBG(2, "advansys_detect: AscInitSetConfig()\n");
4863                 switch (ret = AscInitSetConfig(asc_dvc_varp)) {
4864                 case 0:    /* No error. */
4865                     break;
4866                 case ASC_WARN_IO_PORT_ROTATE:
4867                     ASC_PRINT1(
4868 "AscInitSetConfig: board %d: I/O port address modified\n",
4869                         boardp->id);
4870                     break;
4871                 case ASC_WARN_AUTO_CONFIG:
4872                     ASC_PRINT1(
4873 "AscInitSetConfig: board %d: I/O port increment switch enabled\n",
4874                         boardp->id);
4875                     break;
4876                 case ASC_WARN_EEPROM_CHKSUM:
4877                     ASC_PRINT1(
4878 "AscInitSetConfig: board %d: EEPROM checksum error\n",
4879                         boardp->id);
4880                     break;
4881                 case ASC_WARN_IRQ_MODIFIED:
4882                     ASC_PRINT1(
4883 "AscInitSetConfig: board %d: IRQ modified\n",
4884                         boardp->id);
4885                     break;
4886                 case ASC_WARN_CMD_QNG_CONFLICT:
4887                     ASC_PRINT1(
4888 "AscInitSetConfig: board %d: tag queuing w/o disconnects\n",
4889                         boardp->id);
4890                     break;
4891                 default:
4892                     ASC_PRINT2(
4893 "AscInitSetConfig: board %d: unknown warning: 0x%x\n",
4894                         boardp->id, ret);
4895                     break;
4896                 }
4897                 if (asc_dvc_varp->err_code != 0) {
4898                     ASC_PRINT3(
4899 "AscInitSetConfig: board %d error: init_state 0x%x, err_code 0x%x\n",
4900                         boardp->id, asc_dvc_varp->init_state,
4901                         asc_dvc_varp->err_code);
4902 #ifdef CONFIG_PROC_FS
4903                     kfree(boardp->prtbuf);
4904 #endif /* CONFIG_PROC_FS */
4905                     scsi_unregister(shp);
4906                     asc_board_count--;
4907                     continue;
4908                 }
4909
4910                 /*
4911                  * Finish initializing the 'Scsi_Host' structure.
4912                  */
4913                 /* AscInitSetConfig() will set the IRQ for non-PCI boards. */
4914                 if ((asc_dvc_varp->bus_type & ASC_IS_PCI) == 0) {
4915                     shp->irq = asc_dvc_varp->irq_no;
4916                 }
4917             } else {
4918                 ADVEEP_3550_CONFIG      *ep_3550;
4919                 ADVEEP_38C0800_CONFIG   *ep_38C0800;
4920                 ADVEEP_38C1600_CONFIG   *ep_38C1600;
4921
4922                 /*
4923                  * Save Wide EEP Configuration Information.
4924                  */
4925                 if (adv_dvc_varp->chip_type == ADV_CHIP_ASC3550)
4926                 {
4927                     ep_3550 = &boardp->eep_config.adv_3550_eep;
4928
4929                     ep_3550->adapter_scsi_id = adv_dvc_varp->chip_scsi_id;
4930                     ep_3550->max_host_qng = adv_dvc_varp->max_host_qng;
4931                     ep_3550->max_dvc_qng = adv_dvc_varp->max_dvc_qng;
4932                     ep_3550->termination = adv_dvc_varp->cfg->termination;
4933                     ep_3550->disc_enable = adv_dvc_varp->cfg->disc_enable;
4934                     ep_3550->bios_ctrl = adv_dvc_varp->bios_ctrl;
4935                     ep_3550->wdtr_able = adv_dvc_varp->wdtr_able;
4936                     ep_3550->sdtr_able = adv_dvc_varp->sdtr_able;
4937                     ep_3550->ultra_able = adv_dvc_varp->ultra_able;
4938                     ep_3550->tagqng_able = adv_dvc_varp->tagqng_able;
4939                     ep_3550->start_motor = adv_dvc_varp->start_motor;
4940                     ep_3550->scsi_reset_delay = adv_dvc_varp->scsi_reset_wait;
4941                     ep_3550->serial_number_word1 =
4942                         adv_dvc_varp->cfg->serial1;
4943                     ep_3550->serial_number_word2 =
4944                         adv_dvc_varp->cfg->serial2;
4945                     ep_3550->serial_number_word3 =
4946                         adv_dvc_varp->cfg->serial3;
4947                 } else if (adv_dvc_varp->chip_type == ADV_CHIP_ASC38C0800)
4948                 {
4949                     ep_38C0800 = &boardp->eep_config.adv_38C0800_eep;
4950
4951                     ep_38C0800->adapter_scsi_id = adv_dvc_varp->chip_scsi_id;
4952                     ep_38C0800->max_host_qng = adv_dvc_varp->max_host_qng;
4953                     ep_38C0800->max_dvc_qng = adv_dvc_varp->max_dvc_qng;
4954                     ep_38C0800->termination_lvd =
4955                         adv_dvc_varp->cfg->termination;
4956                     ep_38C0800->disc_enable = adv_dvc_varp->cfg->disc_enable;
4957                     ep_38C0800->bios_ctrl = adv_dvc_varp->bios_ctrl;
4958                     ep_38C0800->wdtr_able = adv_dvc_varp->wdtr_able;
4959                     ep_38C0800->tagqng_able = adv_dvc_varp->tagqng_able;
4960                     ep_38C0800->sdtr_speed1 = adv_dvc_varp->sdtr_speed1;
4961                     ep_38C0800->sdtr_speed2 = adv_dvc_varp->sdtr_speed2;
4962                     ep_38C0800->sdtr_speed3 = adv_dvc_varp->sdtr_speed3;
4963                     ep_38C0800->sdtr_speed4 = adv_dvc_varp->sdtr_speed4;
4964                     ep_38C0800->tagqng_able = adv_dvc_varp->tagqng_able;
4965                     ep_38C0800->start_motor = adv_dvc_varp->start_motor;
4966                     ep_38C0800->scsi_reset_delay =
4967                         adv_dvc_varp->scsi_reset_wait;
4968                     ep_38C0800->serial_number_word1 =
4969                         adv_dvc_varp->cfg->serial1;
4970                     ep_38C0800->serial_number_word2 =
4971                         adv_dvc_varp->cfg->serial2;
4972                     ep_38C0800->serial_number_word3 =
4973                         adv_dvc_varp->cfg->serial3;
4974                 } else
4975                 {
4976                     ep_38C1600 = &boardp->eep_config.adv_38C1600_eep;
4977
4978                     ep_38C1600->adapter_scsi_id = adv_dvc_varp->chip_scsi_id;
4979                     ep_38C1600->max_host_qng = adv_dvc_varp->max_host_qng;
4980                     ep_38C1600->max_dvc_qng = adv_dvc_varp->max_dvc_qng;
4981                     ep_38C1600->termination_lvd =
4982                         adv_dvc_varp->cfg->termination;
4983                     ep_38C1600->disc_enable = adv_dvc_varp->cfg->disc_enable;
4984                     ep_38C1600->bios_ctrl = adv_dvc_varp->bios_ctrl;
4985                     ep_38C1600->wdtr_able = adv_dvc_varp->wdtr_able;
4986                     ep_38C1600->tagqng_able = adv_dvc_varp->tagqng_able;
4987                     ep_38C1600->sdtr_speed1 = adv_dvc_varp->sdtr_speed1;
4988                     ep_38C1600->sdtr_speed2 = adv_dvc_varp->sdtr_speed2;
4989                     ep_38C1600->sdtr_speed3 = adv_dvc_varp->sdtr_speed3;
4990                     ep_38C1600->sdtr_speed4 = adv_dvc_varp->sdtr_speed4;
4991                     ep_38C1600->tagqng_able = adv_dvc_varp->tagqng_able;
4992                     ep_38C1600->start_motor = adv_dvc_varp->start_motor;
4993                     ep_38C1600->scsi_reset_delay =
4994                         adv_dvc_varp->scsi_reset_wait;
4995                     ep_38C1600->serial_number_word1 =
4996                         adv_dvc_varp->cfg->serial1;
4997                     ep_38C1600->serial_number_word2 =
4998                         adv_dvc_varp->cfg->serial2;
4999                     ep_38C1600->serial_number_word3 =
5000                         adv_dvc_varp->cfg->serial3;
5001                 }
5002
5003                 /*
5004                  * Set the adapter's target id bit in the 'init_tidmask' field.
5005                  */
5006                 boardp->init_tidmask |=
5007                     ADV_TID_TO_TIDMASK(adv_dvc_varp->chip_scsi_id);
5008
5009                 /*
5010                  * Finish initializing the 'Scsi_Host' structure.
5011                  */
5012                 shp->irq = adv_dvc_varp->irq_no;
5013             }
5014
5015             /*
5016              * Channels are numbered beginning with 0. For AdvanSys one host
5017              * structure supports one channel. Multi-channel boards have a
5018              * separate host structure for each channel.
5019              */
5020             shp->max_channel = 0;
5021             if (ASC_NARROW_BOARD(boardp)) {
5022                 shp->max_id = ASC_MAX_TID + 1;
5023                 shp->max_lun = ASC_MAX_LUN + 1;
5024
5025                 shp->io_port = asc_dvc_varp->iop_base;
5026                 boardp->asc_n_io_port = ASC_IOADR_GAP;
5027                 shp->this_id = asc_dvc_varp->cfg->chip_scsi_id;
5028
5029                 /* Set maximum number of queues the adapter can handle. */
5030                 shp->can_queue = asc_dvc_varp->max_total_qng;
5031             } else {
5032                 shp->max_id = ADV_MAX_TID + 1;
5033                 shp->max_lun = ADV_MAX_LUN + 1;
5034
5035                 /*
5036                  * Save the I/O Port address and length even though
5037                  * I/O ports are not used to access Wide boards.
5038                  * Instead the Wide boards are accessed with
5039                  * PCI Memory Mapped I/O.
5040                  */
5041                 shp->io_port = iop;
5042                 boardp->asc_n_io_port = iolen;
5043
5044                 shp->this_id = adv_dvc_varp->chip_scsi_id;
5045
5046                 /* Set maximum number of queues the adapter can handle. */
5047                 shp->can_queue = adv_dvc_varp->max_host_qng;
5048             }
5049
5050             /*
5051              * 'n_io_port' currently is one byte.
5052              *
5053              * Set a value to 'n_io_port', but never referenced it because
5054              * it may be truncated.
5055              */
5056             shp->n_io_port = boardp->asc_n_io_port <= 255 ?
5057                 boardp->asc_n_io_port : 255;
5058
5059             /*
5060              * Following v1.3.89, 'cmd_per_lun' is no longer needed
5061              * and should be set to zero.
5062              *
5063              * But because of a bug introduced in v1.3.89 if the driver is
5064              * compiled as a module and 'cmd_per_lun' is zero, the Mid-Level
5065              * SCSI function 'allocate_device' will panic. To allow the driver
5066              * to work as a module in these kernels set 'cmd_per_lun' to 1.
5067              *
5068              * Note: This is wrong.  cmd_per_lun should be set to the depth
5069              * you want on untagged devices always.
5070 #ifdef MODULE
5071              */
5072             shp->cmd_per_lun = 1;
5073 /* #else
5074             shp->cmd_per_lun = 0;
5075 #endif */
5076
5077             /*
5078              * Set the maximum number of scatter-gather elements the
5079              * adapter can handle.
5080              */
5081             if (ASC_NARROW_BOARD(boardp)) {
5082                 /*
5083                  * Allow two commands with 'sg_tablesize' scatter-gather
5084                  * elements to be executed simultaneously. This value is
5085                  * the theoretical hardware limit. It may be decreased
5086                  * below.
5087                  */
5088                 shp->sg_tablesize =
5089                     (((asc_dvc_varp->max_total_qng - 2) / 2) *
5090                     ASC_SG_LIST_PER_Q) + 1;
5091             } else {
5092                 shp->sg_tablesize = ADV_MAX_SG_LIST;
5093             }
5094
5095             /*
5096              * The value of 'sg_tablesize' can not exceed the SCSI
5097              * mid-level driver definition of SG_ALL. SG_ALL also
5098              * must not be exceeded, because it is used to define the
5099              * size of the scatter-gather table in 'struct asc_sg_head'.
5100              */
5101             if (shp->sg_tablesize > SG_ALL) {
5102                 shp->sg_tablesize = SG_ALL;
5103             }
5104
5105             ASC_DBG1(1, "advansys_detect: sg_tablesize: %d\n",
5106                 shp->sg_tablesize);
5107
5108             /* BIOS start address. */
5109             if (ASC_NARROW_BOARD(boardp)) {
5110                 shp->base =
5111                         ((ulong) AscGetChipBiosAddress(
5112                             asc_dvc_varp->iop_base,
5113                             asc_dvc_varp->bus_type));
5114             } else {
5115                 /*
5116                  * Fill-in BIOS board variables. The Wide BIOS saves
5117                  * information in LRAM that is used by the driver.
5118                  */
5119                 AdvReadWordLram(adv_dvc_varp->iop_base, BIOS_SIGNATURE,
5120                     boardp->bios_signature);
5121                 AdvReadWordLram(adv_dvc_varp->iop_base, BIOS_VERSION,
5122                     boardp->bios_version);
5123                 AdvReadWordLram(adv_dvc_varp->iop_base, BIOS_CODESEG,
5124                     boardp->bios_codeseg);
5125                 AdvReadWordLram(adv_dvc_varp->iop_base, BIOS_CODELEN,
5126                     boardp->bios_codelen);
5127
5128                 ASC_DBG2(1,
5129                     "advansys_detect: bios_signature 0x%x, bios_version 0x%x\n",
5130                     boardp->bios_signature, boardp->bios_version);
5131
5132                 ASC_DBG2(1,
5133                     "advansys_detect: bios_codeseg 0x%x, bios_codelen 0x%x\n",
5134                     boardp->bios_codeseg, boardp->bios_codelen);
5135
5136                 /*
5137                  * If the BIOS saved a valid signature, then fill in
5138                  * the BIOS code segment base address.
5139                  */
5140                 if (boardp->bios_signature == 0x55AA) {
5141                     /*
5142                      * Convert x86 realmode code segment to a linear
5143                      * address by shifting left 4.
5144                      */
5145                     shp->base = ((ulong) boardp->bios_codeseg << 4);
5146                 } else {
5147                     shp->base = 0;
5148                 }
5149             }
5150
5151             /*
5152              * Register Board Resources - I/O Port, DMA, IRQ
5153              */
5154
5155             /*
5156              * Register I/O port range.
5157              *
5158              * For Wide boards the I/O ports are not used to access
5159              * the board, but request the region anyway.
5160              *
5161              * 'shp->n_io_port' is not referenced, because it may be truncated.
5162              */
5163             ASC_DBG2(2,
5164                 "advansys_detect: request_region port 0x%lx, len 0x%x\n",
5165                 (ulong) shp->io_port, boardp->asc_n_io_port);
5166             if (request_region(shp->io_port, boardp->asc_n_io_port,
5167                                "advansys") == NULL) {
5168                 ASC_PRINT3(
5169 "advansys_detect: board %d: request_region() failed, port 0x%lx, len 0x%x\n",
5170                     boardp->id, (ulong) shp->io_port, boardp->asc_n_io_port);
5171 #ifdef CONFIG_PROC_FS
5172                 kfree(boardp->prtbuf);
5173 #endif /* CONFIG_PROC_FS */
5174                 scsi_unregister(shp);
5175                 asc_board_count--;
5176                 continue;
5177             }
5178
5179             /* Register DMA Channel for Narrow boards. */
5180             shp->dma_channel = NO_ISA_DMA; /* Default to no ISA DMA. */
5181 #ifdef CONFIG_ISA
5182             if (ASC_NARROW_BOARD(boardp)) {
5183                 /* Register DMA channel for ISA bus. */
5184                 if (asc_dvc_varp->bus_type & ASC_IS_ISA) {
5185                     shp->dma_channel = asc_dvc_varp->cfg->isa_dma_channel;
5186                     if ((ret =
5187                          request_dma(shp->dma_channel, "advansys")) != 0) {
5188                         ASC_PRINT3(
5189 "advansys_detect: board %d: request_dma() %d failed %d\n",
5190                             boardp->id, shp->dma_channel, ret);
5191                         release_region(shp->io_port, boardp->asc_n_io_port);
5192 #ifdef CONFIG_PROC_FS
5193                         kfree(boardp->prtbuf);
5194 #endif /* CONFIG_PROC_FS */
5195                         scsi_unregister(shp);
5196                         asc_board_count--;
5197                         continue;
5198                     }
5199                     AscEnableIsaDma(shp->dma_channel);
5200                 }
5201             }
5202 #endif /* CONFIG_ISA */
5203
5204             /* Register IRQ Number. */
5205             ASC_DBG1(2, "advansys_detect: request_irq() %d\n", shp->irq);
5206            /*
5207             * If request_irq() fails with the SA_INTERRUPT flag set,
5208             * then try again without the SA_INTERRUPT flag set. This
5209             * allows IRQ sharing to work even with other drivers that
5210             * do not set the SA_INTERRUPT flag.
5211             *
5212             * If SA_INTERRUPT is not set, then interrupts are enabled
5213             * before the driver interrupt function is called.
5214             */
5215             if (((ret = request_irq(shp->irq, advansys_interrupt,
5216                             SA_INTERRUPT | (share_irq == TRUE ? SA_SHIRQ : 0),
5217                             "advansys", boardp)) != 0) &&
5218                 ((ret = request_irq(shp->irq, advansys_interrupt,
5219                             (share_irq == TRUE ? SA_SHIRQ : 0),
5220                             "advansys", boardp)) != 0))
5221             {
5222                 if (ret == -EBUSY) {
5223                     ASC_PRINT2(
5224 "advansys_detect: board %d: request_irq(): IRQ 0x%x already in use.\n",
5225                         boardp->id, shp->irq);
5226                 } else if (ret == -EINVAL) {
5227                     ASC_PRINT2(
5228 "advansys_detect: board %d: request_irq(): IRQ 0x%x not valid.\n",
5229                         boardp->id, shp->irq);
5230                 } else {
5231                     ASC_PRINT3(
5232 "advansys_detect: board %d: request_irq(): IRQ 0x%x failed with %d\n",
5233                         boardp->id, shp->irq, ret);
5234                 }
5235                 release_region(shp->io_port, boardp->asc_n_io_port);
5236                 iounmap(boardp->ioremap_addr);
5237                 if (shp->dma_channel != NO_ISA_DMA) {
5238                     free_dma(shp->dma_channel);
5239                 }
5240 #ifdef CONFIG_PROC_FS
5241                 kfree(boardp->prtbuf);
5242 #endif /* CONFIG_PROC_FS */
5243                 scsi_unregister(shp);
5244                 asc_board_count--;
5245                 continue;
5246             }
5247
5248             /*
5249              * Initialize board RISC chip and enable interrupts.
5250              */
5251             if (ASC_NARROW_BOARD(boardp)) {
5252                 ASC_DBG(2, "advansys_detect: AscInitAsc1000Driver()\n");
5253                 warn_code = AscInitAsc1000Driver(asc_dvc_varp);
5254                 err_code = asc_dvc_varp->err_code;
5255
5256                 if (warn_code || err_code) {
5257                     ASC_PRINT4(
5258 "advansys_detect: board %d error: init_state 0x%x, warn 0x%x, error 0x%x\n",
5259                         boardp->id, asc_dvc_varp->init_state,
5260                         warn_code, err_code);
5261                 }
5262             } else {
5263                 ADV_CARR_T      *carrp;
5264                 int             req_cnt = 0;
5265                 adv_req_t       *reqp = NULL;
5266                 int             sg_cnt = 0;
5267
5268                 /*
5269                  * Allocate buffer carrier structures. The total size
5270                  * is about 4 KB, so allocate all at once.
5271                  */
5272                 carrp =
5273                     (ADV_CARR_T *) kmalloc(ADV_CARRIER_BUFSIZE, GFP_ATOMIC);
5274                 ASC_DBG1(1, "advansys_detect: carrp 0x%lx\n", (ulong) carrp);
5275
5276                 if (carrp == NULL) {
5277                     goto kmalloc_error;
5278                 }
5279
5280                 /*
5281                  * Allocate up to 'max_host_qng' request structures for
5282                  * the Wide board. The total size is about 16 KB, so
5283                  * allocate all at once. If the allocation fails decrement
5284                  * and try again.
5285                  */
5286                 for (req_cnt = adv_dvc_varp->max_host_qng;
5287                     req_cnt > 0; req_cnt--) {
5288
5289                     reqp = (adv_req_t *)
5290                         kmalloc(sizeof(adv_req_t) * req_cnt, GFP_ATOMIC);
5291
5292                     ASC_DBG3(1,
5293                         "advansys_detect: reqp 0x%lx, req_cnt %d, bytes %lu\n",
5294                         (ulong) reqp, req_cnt,
5295                         (ulong) sizeof(adv_req_t) * req_cnt);
5296
5297                     if (reqp != NULL) {
5298                         break;
5299                     }
5300                 }
5301                 if (reqp == NULL)
5302                 {
5303                     goto kmalloc_error;
5304                 }
5305
5306                 /*
5307                  * Allocate up to ADV_TOT_SG_BLOCK request structures for
5308                  * the Wide board. Each structure is about 136 bytes.
5309                  */
5310                 boardp->adv_sgblkp = NULL;
5311                 for (sg_cnt = 0; sg_cnt < ADV_TOT_SG_BLOCK; sg_cnt++) {
5312
5313                     sgp = (adv_sgblk_t *)
5314                         kmalloc(sizeof(adv_sgblk_t), GFP_ATOMIC);
5315
5316                     if (sgp == NULL) {
5317                         break;
5318                     }
5319
5320                     sgp->next_sgblkp = boardp->adv_sgblkp;
5321                     boardp->adv_sgblkp = sgp;
5322
5323                 }
5324                 ASC_DBG3(1,
5325                     "advansys_detect: sg_cnt %d * %u = %u bytes\n",
5326                     sg_cnt, sizeof(adv_sgblk_t),
5327                     (unsigned) (sizeof(adv_sgblk_t) * sg_cnt));
5328
5329                 /*
5330                  * If no request structures or scatter-gather structures could
5331                  * be allocated, then return an error. Otherwise continue with
5332                  * initialization.
5333                  */
5334     kmalloc_error:
5335                 if (carrp == NULL)
5336                 {
5337                     ASC_PRINT1(
5338 "advansys_detect: board %d error: failed to kmalloc() carrier buffer.\n",
5339                         boardp->id);
5340                     err_code = ADV_ERROR;
5341                 } else if (reqp == NULL) {
5342                     kfree(carrp);
5343                     ASC_PRINT1(
5344 "advansys_detect: board %d error: failed to kmalloc() adv_req_t buffer.\n",
5345                         boardp->id);
5346                     err_code = ADV_ERROR;
5347                 } else if (boardp->adv_sgblkp == NULL) {
5348                     kfree(carrp);
5349                     kfree(reqp);
5350                     ASC_PRINT1(
5351 "advansys_detect: board %d error: failed to kmalloc() adv_sgblk_t buffers.\n",
5352                         boardp->id);
5353                     err_code = ADV_ERROR;
5354                 } else {
5355
5356                     /* Save carrier buffer pointer. */
5357                     boardp->orig_carrp = carrp;
5358
5359                     /*
5360                      * Save original pointer for kfree() in case the
5361                      * driver is built as a module and can be unloaded.
5362                      */
5363                     boardp->orig_reqp = reqp;
5364
5365                     adv_dvc_varp->carrier_buf = carrp;
5366
5367                     /*
5368                      * Point 'adv_reqp' to the request structures and
5369                      * link them together.
5370                      */
5371                     req_cnt--;
5372                     reqp[req_cnt].next_reqp = NULL;
5373                     for (; req_cnt > 0; req_cnt--) {
5374                         reqp[req_cnt - 1].next_reqp = &reqp[req_cnt];
5375                     }
5376                     boardp->adv_reqp = &reqp[0];
5377
5378                     if (adv_dvc_varp->chip_type == ADV_CHIP_ASC3550)
5379                     {
5380                         ASC_DBG(2,
5381                             "advansys_detect: AdvInitAsc3550Driver()\n");
5382                         warn_code = AdvInitAsc3550Driver(adv_dvc_varp);
5383                     } else if (adv_dvc_varp->chip_type == ADV_CHIP_ASC38C0800) {
5384                         ASC_DBG(2,
5385                             "advansys_detect: AdvInitAsc38C0800Driver()\n");
5386                         warn_code = AdvInitAsc38C0800Driver(adv_dvc_varp);
5387                     } else {
5388                         ASC_DBG(2,
5389                             "advansys_detect: AdvInitAsc38C1600Driver()\n");
5390                         warn_code = AdvInitAsc38C1600Driver(adv_dvc_varp);
5391                     }
5392                     err_code = adv_dvc_varp->err_code;
5393
5394                     if (warn_code || err_code) {
5395                         ASC_PRINT3(
5396 "advansys_detect: board %d error: warn 0x%x, error 0x%x\n",
5397                             boardp->id, warn_code, err_code);
5398                     }
5399                 }
5400             }
5401
5402             if (err_code != 0) {
5403                 release_region(shp->io_port, boardp->asc_n_io_port);
5404                 if (ASC_WIDE_BOARD(boardp)) {
5405                     iounmap(boardp->ioremap_addr);
5406                     if (boardp->orig_carrp) {
5407                         kfree(boardp->orig_carrp);
5408                         boardp->orig_carrp = NULL;
5409                     }
5410                     if (boardp->orig_reqp) {
5411                         kfree(boardp->orig_reqp);
5412                         boardp->orig_reqp = boardp->adv_reqp = NULL;
5413                     }
5414                     while ((sgp = boardp->adv_sgblkp) != NULL)
5415                     {
5416                         boardp->adv_sgblkp = sgp->next_sgblkp;
5417                         kfree(sgp);
5418                     }
5419                 }
5420                 if (shp->dma_channel != NO_ISA_DMA) {
5421                     free_dma(shp->dma_channel);
5422                 }
5423 #ifdef CONFIG_PROC_FS
5424                 kfree(boardp->prtbuf);
5425 #endif /* CONFIG_PROC_FS */
5426                 free_irq(shp->irq, boardp);
5427                 scsi_unregister(shp);
5428                 asc_board_count--;
5429                 continue;
5430             }
5431             ASC_DBG_PRT_SCSI_HOST(2, shp);
5432         }
5433     }
5434
5435     ASC_DBG1(1, "advansys_detect: done: asc_board_count %d\n", asc_board_count);
5436     return asc_board_count;
5437 }
5438
5439 /*
5440  * advansys_release()
5441  *
5442  * Release resources allocated for a single AdvanSys adapter.
5443  */
5444 int
5445 advansys_release(struct Scsi_Host *shp)
5446 {
5447     asc_board_t    *boardp;
5448
5449     ASC_DBG(1, "advansys_release: begin\n");
5450     boardp = ASC_BOARDP(shp);
5451     free_irq(shp->irq, boardp);
5452     if (shp->dma_channel != NO_ISA_DMA) {
5453         ASC_DBG(1, "advansys_release: free_dma()\n");
5454         free_dma(shp->dma_channel);
5455     }
5456     release_region(shp->io_port, boardp->asc_n_io_port);
5457     if (ASC_WIDE_BOARD(boardp)) {
5458         adv_sgblk_t    *sgp = NULL;
5459
5460         iounmap(boardp->ioremap_addr);
5461         if (boardp->orig_carrp) {
5462             kfree(boardp->orig_carrp);
5463             boardp->orig_carrp = NULL;
5464         }
5465         if (boardp->orig_reqp) {
5466             kfree(boardp->orig_reqp);
5467             boardp->orig_reqp = boardp->adv_reqp = NULL;
5468         }
5469         while ((sgp = boardp->adv_sgblkp) != NULL)
5470         {
5471             boardp->adv_sgblkp = sgp->next_sgblkp;
5472             kfree(sgp);
5473         }
5474     }
5475 #ifdef CONFIG_PROC_FS
5476     ASC_ASSERT(boardp->prtbuf != NULL);
5477     kfree(boardp->prtbuf);
5478 #endif /* CONFIG_PROC_FS */
5479     scsi_unregister(shp);
5480     ASC_DBG(1, "advansys_release: end\n");
5481     return 0;
5482 }
5483
5484 /*
5485  * advansys_info()
5486  *
5487  * Return suitable for printing on the console with the argument
5488  * adapter's configuration information.
5489  *
5490  * Note: The information line should not exceed ASC_INFO_SIZE bytes,
5491  * otherwise the static 'info' array will be overrun.
5492  */
5493 const char *
5494 advansys_info(struct Scsi_Host *shp)
5495 {
5496     static char     info[ASC_INFO_SIZE];
5497     asc_board_t     *boardp;
5498     ASC_DVC_VAR     *asc_dvc_varp;
5499     ADV_DVC_VAR     *adv_dvc_varp;
5500     char            *busname;
5501     int             iolen;
5502     char            *widename = NULL;
5503
5504     boardp = ASC_BOARDP(shp);
5505     if (ASC_NARROW_BOARD(boardp)) {
5506         asc_dvc_varp = &boardp->dvc_var.asc_dvc_var;
5507         ASC_DBG(1, "advansys_info: begin\n");
5508         if (asc_dvc_varp->bus_type & ASC_IS_ISA) {
5509             if ((asc_dvc_varp->bus_type & ASC_IS_ISAPNP) == ASC_IS_ISAPNP) {
5510                 busname = "ISA PnP";
5511             } else {
5512                 busname = "ISA";
5513             }
5514             /* Don't reference 'shp->n_io_port'; It may be truncated. */
5515             sprintf(info,
5516 "AdvanSys SCSI %s: %s: IO 0x%lX-0x%lX, IRQ 0x%X, DMA 0x%X",
5517                 ASC_VERSION, busname,
5518                 (ulong) shp->io_port,
5519                 (ulong) shp->io_port + boardp->asc_n_io_port - 1,
5520                 shp->irq, shp->dma_channel);
5521         } else {
5522             if (asc_dvc_varp->bus_type & ASC_IS_VL) {
5523                 busname = "VL";
5524             } else if (asc_dvc_varp->bus_type & ASC_IS_EISA) {
5525                 busname = "EISA";
5526             } else if (asc_dvc_varp->bus_type & ASC_IS_PCI) {
5527                 if ((asc_dvc_varp->bus_type & ASC_IS_PCI_ULTRA)
5528                     == ASC_IS_PCI_ULTRA) {
5529                     busname = "PCI Ultra";
5530                 } else {
5531                     busname = "PCI";
5532                 }
5533             } else {
5534                 busname = "?";
5535                 ASC_PRINT2( "advansys_info: board %d: unknown bus type %d\n",
5536                     boardp->id, asc_dvc_varp->bus_type);
5537             }
5538             /* Don't reference 'shp->n_io_port'; It may be truncated. */
5539             sprintf(info,
5540                 "AdvanSys SCSI %s: %s: IO 0x%lX-0x%lX, IRQ 0x%X",
5541                 ASC_VERSION, busname,
5542                 (ulong) shp->io_port,
5543                 (ulong) shp->io_port + boardp->asc_n_io_port - 1,
5544                 shp->irq);
5545         }
5546     } else {
5547         /*
5548          * Wide Adapter Information
5549          *
5550          * Memory-mapped I/O is used instead of I/O space to access
5551          * the adapter, but display the I/O Port range. The Memory
5552          * I/O address is displayed through the driver /proc file.
5553          */
5554         adv_dvc_varp = &boardp->dvc_var.adv_dvc_var;
5555         if (adv_dvc_varp->chip_type == ADV_CHIP_ASC3550)
5556         {
5557             iolen = ADV_3550_IOLEN;
5558             widename = "Ultra-Wide";
5559         } else if (adv_dvc_varp->chip_type == ADV_CHIP_ASC38C0800)
5560         {
5561             iolen = ADV_38C0800_IOLEN;
5562             widename = "Ultra2-Wide";
5563         } else
5564         {
5565             iolen = ADV_38C1600_IOLEN;
5566             widename = "Ultra3-Wide";
5567         }
5568         sprintf(info, "AdvanSys SCSI %s: PCI %s: PCIMEM 0x%lX-0x%lX, IRQ 0x%X",
5569             ASC_VERSION,
5570             widename,
5571             (ulong) adv_dvc_varp->iop_base,
5572             (ulong) adv_dvc_varp->iop_base + iolen - 1,
5573             shp->irq);
5574     }
5575     ASC_ASSERT(strlen(info) < ASC_INFO_SIZE);
5576     ASC_DBG(1, "advansys_info: end\n");
5577     return info;
5578 }
5579
5580 /*
5581  * advansys_queuecommand() - interrupt-driven I/O entrypoint.
5582  *
5583  * This function always returns 0. Command return status is saved
5584  * in the 'scp' result field.
5585  */
5586 int
5587 advansys_queuecommand(struct scsi_cmnd *scp, void (*done)(struct scsi_cmnd *))
5588 {
5589     struct Scsi_Host    *shp;
5590     asc_board_t         *boardp;
5591     ulong               flags;
5592     struct scsi_cmnd           *done_scp;
5593
5594     shp = scp->device->host;
5595     boardp = ASC_BOARDP(shp);
5596     ASC_STATS(shp, queuecommand);
5597
5598     /* host_lock taken by mid-level prior to call but need to protect */
5599     /* against own ISR */
5600     spin_lock_irqsave(&boardp->lock, flags);
5601
5602     /*
5603      * Block new commands while handling a reset or abort request.
5604      */
5605     if (boardp->flags & ASC_HOST_IN_RESET) {
5606         ASC_DBG1(1,
5607             "advansys_queuecommand: scp 0x%lx blocked for reset request\n",
5608             (ulong) scp);
5609         scp->result = HOST_BYTE(DID_RESET);
5610
5611         /*
5612          * Add blocked requests to the board's 'done' queue. The queued
5613          * requests will be completed at the end of the abort or reset
5614          * handling.
5615          */
5616         asc_enqueue(&boardp->done, scp, ASC_BACK);
5617         spin_unlock_irqrestore(&boardp->lock, flags);
5618         return 0;
5619     }
5620
5621     /*
5622      * Attempt to execute any waiting commands for the board.
5623      */
5624     if (!ASC_QUEUE_EMPTY(&boardp->waiting)) {
5625         ASC_DBG(1,
5626             "advansys_queuecommand: before asc_execute_queue() waiting\n");
5627         asc_execute_queue(&boardp->waiting);
5628     }
5629
5630     /*
5631      * Save the function pointer to Linux mid-level 'done' function
5632      * and attempt to execute the command.
5633      *
5634      * If ASC_NOERROR is returned the request has been added to the
5635      * board's 'active' queue and will be completed by the interrupt
5636      * handler.
5637      *
5638      * If ASC_BUSY is returned add the request to the board's per
5639      * target waiting list. This is the first time the request has
5640      * been tried. Add it to the back of the waiting list. It will be
5641      * retried later.
5642      *
5643      * If an error occurred, the request will have been placed on the
5644      * board's 'done' queue and must be completed before returning.
5645      */
5646     scp->scsi_done = done;
5647     switch (asc_execute_scsi_cmnd(scp)) {
5648     case ASC_NOERROR:
5649         break;
5650     case ASC_BUSY:
5651         asc_enqueue(&boardp->waiting, scp, ASC_BACK);
5652         break;
5653     case ASC_ERROR:
5654     default:
5655         done_scp = asc_dequeue_list(&boardp->done, NULL, ASC_TID_ALL);
5656         /* Interrupts could be enabled here. */
5657         asc_scsi_done_list(done_scp);
5658         break;
5659     }
5660     spin_unlock_irqrestore(&boardp->lock, flags);
5661
5662     return 0;
5663 }
5664
5665 /*
5666  * advansys_reset()
5667  *
5668  * Reset the bus associated with the command 'scp'.
5669  *
5670  * This function runs its own thread. Interrupts must be blocked but
5671  * sleeping is allowed and no locking other than for host structures is
5672  * required. Returns SUCCESS or FAILED.
5673  */
5674 int
5675 advansys_reset(struct scsi_cmnd *scp)
5676 {
5677     struct Scsi_Host     *shp;
5678     asc_board_t          *boardp;
5679     ASC_DVC_VAR          *asc_dvc_varp;
5680     ADV_DVC_VAR          *adv_dvc_varp;
5681     ulong                flags;
5682     struct scsi_cmnd            *done_scp = NULL, *last_scp = NULL;
5683     struct scsi_cmnd            *tscp, *new_last_scp;
5684     int                  status;
5685     int                  ret = SUCCESS;
5686
5687     ASC_DBG1(1, "advansys_reset: 0x%lx\n", (ulong) scp);
5688
5689 #ifdef ADVANSYS_STATS
5690     if (scp->device->host != NULL) {
5691         ASC_STATS(scp->device->host, reset);
5692     }
5693 #endif /* ADVANSYS_STATS */
5694
5695     if ((shp = scp->device->host) == NULL) {
5696         scp->result = HOST_BYTE(DID_ERROR);
5697         return FAILED;
5698     }
5699
5700     boardp = ASC_BOARDP(shp);
5701
5702     ASC_PRINT1("advansys_reset: board %d: SCSI bus reset started...\n",
5703         boardp->id);
5704     /*
5705      * Check for re-entrancy.
5706      */
5707     spin_lock_irqsave(&boardp->lock, flags);
5708     if (boardp->flags & ASC_HOST_IN_RESET) {
5709         spin_unlock_irqrestore(&boardp->lock, flags);
5710         return FAILED;
5711     }
5712     boardp->flags |= ASC_HOST_IN_RESET;
5713     spin_unlock_irqrestore(&boardp->lock, flags);
5714
5715     if (ASC_NARROW_BOARD(boardp)) {
5716         /*
5717          * Narrow Board
5718          */
5719         asc_dvc_varp = &boardp->dvc_var.asc_dvc_var;
5720
5721         /*
5722          * Reset the chip and SCSI bus.
5723          */
5724         ASC_DBG(1, "advansys_reset: before AscInitAsc1000Driver()\n");
5725         status = AscInitAsc1000Driver(asc_dvc_varp);
5726
5727         /* Refer to ASC_IERR_* defintions for meaning of 'err_code'. */
5728         if (asc_dvc_varp->err_code) {
5729             ASC_PRINT2(
5730                 "advansys_reset: board %d: SCSI bus reset error: 0x%x\n",
5731                 boardp->id, asc_dvc_varp->err_code);
5732             ret = FAILED;
5733         } else if (status) {
5734             ASC_PRINT2(
5735                 "advansys_reset: board %d: SCSI bus reset warning: 0x%x\n",
5736                 boardp->id, status);
5737         } else {
5738             ASC_PRINT1(
5739                 "advansys_reset: board %d: SCSI bus reset successful.\n",
5740                 boardp->id);
5741         }
5742
5743         ASC_DBG(1, "advansys_reset: after AscInitAsc1000Driver()\n");
5744         spin_lock_irqsave(&boardp->lock, flags);
5745
5746     } else {
5747         /*
5748          * Wide Board
5749          *
5750          * If the suggest reset bus flags are set, then reset the bus.
5751          * Otherwise only reset the device.
5752          */
5753         adv_dvc_varp = &boardp->dvc_var.adv_dvc_var;
5754
5755         /*
5756          * Reset the target's SCSI bus.
5757          */
5758         ASC_DBG(1, "advansys_reset: before AdvResetChipAndSB()\n");
5759         switch (AdvResetChipAndSB(adv_dvc_varp)) {
5760         case ASC_TRUE:
5761             ASC_PRINT1("advansys_reset: board %d: SCSI bus reset successful.\n",
5762                 boardp->id);
5763             break;
5764         case ASC_FALSE:
5765         default:
5766             ASC_PRINT1("advansys_reset: board %d: SCSI bus reset error.\n",
5767                 boardp->id);
5768             ret = FAILED;
5769             break;
5770         }
5771         spin_lock_irqsave(&boardp->lock, flags);
5772         (void) AdvISR(adv_dvc_varp);
5773     }
5774     /* Board lock is held. */
5775
5776     /*
5777      * Dequeue all board 'done' requests. A pointer to the last request
5778      * is returned in 'last_scp'.
5779      */
5780     done_scp = asc_dequeue_list(&boardp->done, &last_scp, ASC_TID_ALL);
5781
5782     /*
5783      * Dequeue all board 'active' requests for all devices and set
5784      * the request status to DID_RESET. A pointer to the last request
5785      * is returned in 'last_scp'.
5786      */
5787     if (done_scp == NULL) {
5788         done_scp = asc_dequeue_list(&boardp->active, &last_scp, ASC_TID_ALL);
5789         for (tscp = done_scp; tscp; tscp = REQPNEXT(tscp)) {
5790             tscp->result = HOST_BYTE(DID_RESET);
5791         }
5792     } else {
5793         /* Append to 'done_scp' at the end with 'last_scp'. */
5794         ASC_ASSERT(last_scp != NULL);
5795         last_scp->host_scribble = (unsigned char *)asc_dequeue_list(
5796                         &boardp->active, &new_last_scp, ASC_TID_ALL);
5797         if (new_last_scp != NULL) {
5798             ASC_ASSERT(REQPNEXT(last_scp) != NULL);
5799             for (tscp = REQPNEXT(last_scp); tscp; tscp = REQPNEXT(tscp)) {
5800                 tscp->result = HOST_BYTE(DID_RESET);
5801             }
5802             last_scp = new_last_scp;
5803         }
5804     }
5805
5806     /*
5807      * Dequeue all 'waiting' requests and set the request status
5808      * to DID_RESET.
5809      */
5810     if (done_scp == NULL) {
5811         done_scp = asc_dequeue_list(&boardp->waiting, &last_scp, ASC_TID_ALL);
5812         for (tscp = done_scp; tscp; tscp = REQPNEXT(tscp)) {
5813             tscp->result = HOST_BYTE(DID_RESET);
5814         }
5815     } else {
5816         /* Append to 'done_scp' at the end with 'last_scp'. */
5817         ASC_ASSERT(last_scp != NULL);
5818         last_scp->host_scribble = (unsigned char *)asc_dequeue_list(
5819                         &boardp->waiting, &new_last_scp, ASC_TID_ALL);
5820         if (new_last_scp != NULL) {
5821             ASC_ASSERT(REQPNEXT(last_scp) != NULL);
5822             for (tscp = REQPNEXT(last_scp); tscp; tscp = REQPNEXT(tscp)) {
5823                 tscp->result = HOST_BYTE(DID_RESET);
5824             }
5825             last_scp = new_last_scp;
5826         }
5827     }
5828
5829     /* Save the time of the most recently completed reset. */
5830     boardp->last_reset = jiffies;
5831
5832     /* Clear reset flag. */
5833     boardp->flags &= ~ASC_HOST_IN_RESET;
5834     spin_unlock_irqrestore(&boardp->lock, flags);
5835
5836     /*
5837      * Complete all the 'done_scp' requests.
5838      */
5839     if (done_scp != NULL) {
5840         asc_scsi_done_list(done_scp);
5841     }
5842
5843     ASC_DBG1(1, "advansys_reset: ret %d\n", ret);
5844
5845     return ret;
5846 }
5847
5848 /*
5849  * advansys_biosparam()
5850  *
5851  * Translate disk drive geometry if the "BIOS greater than 1 GB"
5852  * support is enabled for a drive.
5853  *
5854  * ip (information pointer) is an int array with the following definition:
5855  * ip[0]: heads
5856  * ip[1]: sectors
5857  * ip[2]: cylinders
5858  */
5859 int
5860 advansys_biosparam(struct scsi_device *sdev, struct block_device *bdev,
5861                 sector_t capacity, int ip[])
5862 {
5863     asc_board_t     *boardp;
5864
5865     ASC_DBG(1, "advansys_biosparam: begin\n");
5866     ASC_STATS(sdev->host, biosparam);
5867     boardp = ASC_BOARDP(sdev->host);
5868     if (ASC_NARROW_BOARD(boardp)) {
5869         if ((boardp->dvc_var.asc_dvc_var.dvc_cntl &
5870              ASC_CNTL_BIOS_GT_1GB) && capacity > 0x200000) {
5871                 ip[0] = 255;
5872                 ip[1] = 63;
5873         } else {
5874                 ip[0] = 64;
5875                 ip[1] = 32;
5876         }
5877     } else {
5878         if ((boardp->dvc_var.adv_dvc_var.bios_ctrl &
5879              BIOS_CTRL_EXTENDED_XLAT) && capacity > 0x200000) {
5880                 ip[0] = 255;
5881                 ip[1] = 63;
5882         } else {
5883                 ip[0] = 64;
5884                 ip[1] = 32;
5885         }
5886     }
5887     ip[2] = (unsigned long)capacity / (ip[0] * ip[1]);
5888     ASC_DBG(1, "advansys_biosparam: end\n");
5889     return 0;
5890 }
5891
5892 /*
5893  * advansys_setup()
5894  *
5895  * This function is called from init/main.c at boot time.
5896  * It it passed LILO parameters that can be set from the
5897  * LILO command line or in /etc/lilo.conf.
5898  *
5899  * It is used by the AdvanSys driver to either disable I/O
5900  * port scanning or to limit scanning to 1 - 4 I/O ports.
5901  * Regardless of the option setting EISA and PCI boards
5902  * will still be searched for and detected. This option
5903  * only affects searching for ISA and VL boards.
5904  *
5905  * If ADVANSYS_DEBUG is defined the driver debug level may
5906  * be set using the 5th (ASC_NUM_IOPORT_PROBE + 1) I/O Port.
5907  *
5908  * Examples:
5909  * 1. Eliminate I/O port scanning:
5910  *         boot: linux advansys=
5911  *       or
5912  *         boot: linux advansys=0x0
5913  * 2. Limit I/O port scanning to one I/O port:
5914  *        boot: linux advansys=0x110
5915  * 3. Limit I/O port scanning to four I/O ports:
5916  *        boot: linux advansys=0x110,0x210,0x230,0x330
5917  * 4. If ADVANSYS_DEBUG, limit I/O port scanning to four I/O ports and
5918  *    set the driver debug level to 2.
5919  *        boot: linux advansys=0x110,0x210,0x230,0x330,0xdeb2
5920  *
5921  * ints[0] - number of arguments
5922  * ints[1] - first argument
5923  * ints[2] - second argument
5924  * ...
5925  */
5926 void __init
5927 advansys_setup(char *str, int *ints)
5928 {
5929     int    i;
5930
5931     if (asc_iopflag == ASC_TRUE) {
5932         printk("AdvanSys SCSI: 'advansys' LILO option may appear only once\n");
5933         return;
5934     }
5935
5936     asc_iopflag = ASC_TRUE;
5937
5938     if (ints[0] > ASC_NUM_IOPORT_PROBE) {
5939 #ifdef ADVANSYS_DEBUG
5940         if ((ints[0] == ASC_NUM_IOPORT_PROBE + 1) &&
5941             (ints[ASC_NUM_IOPORT_PROBE + 1] >> 4 == 0xdeb)) {
5942             asc_dbglvl = ints[ASC_NUM_IOPORT_PROBE + 1] & 0xf;
5943         } else {
5944 #endif /* ADVANSYS_DEBUG */
5945             printk("AdvanSys SCSI: only %d I/O ports accepted\n",
5946                 ASC_NUM_IOPORT_PROBE);
5947 #ifdef ADVANSYS_DEBUG
5948         }
5949 #endif /* ADVANSYS_DEBUG */
5950     }
5951
5952 #ifdef ADVANSYS_DEBUG
5953     ASC_DBG1(1, "advansys_setup: ints[0] %d\n", ints[0]);
5954     for (i = 1; i < ints[0]; i++) {
5955         ASC_DBG2(1, " ints[%d] 0x%x", i, ints[i]);
5956     }
5957     ASC_DBG(1, "\n");
5958 #endif /* ADVANSYS_DEBUG */
5959
5960     for (i = 1; i <= ints[0] && i <= ASC_NUM_IOPORT_PROBE; i++) {
5961         asc_ioport[i-1] = ints[i];
5962         ASC_DBG2(1, "advansys_setup: asc_ioport[%d] 0x%x\n",
5963             i - 1, asc_ioport[i-1]);
5964     }
5965 }
5966
5967
5968 /*
5969  * --- Loadable Driver Support
5970  */
5971
5972 static struct scsi_host_template driver_template = {
5973     .proc_name                  = "advansys",
5974 #ifdef CONFIG_PROC_FS
5975     .proc_info                  = advansys_proc_info,
5976 #endif
5977     .name                       = "advansys",
5978     .detect                     = advansys_detect, 
5979     .release                    = advansys_release,
5980     .info                       = advansys_info,
5981     .queuecommand               = advansys_queuecommand,
5982     .eh_bus_reset_handler       = advansys_reset,
5983     .bios_param                 = advansys_biosparam,
5984     .slave_configure            = advansys_slave_configure,
5985     /*
5986      * Because the driver may control an ISA adapter 'unchecked_isa_dma'
5987      * must be set. The flag will be cleared in advansys_detect for non-ISA
5988      * adapters. Refer to the comment in scsi_module.c for more information.
5989      */
5990     .unchecked_isa_dma          = 1,
5991     /*
5992      * All adapters controlled by this driver are capable of large
5993      * scatter-gather lists. According to the mid-level SCSI documentation
5994      * this obviates any performance gain provided by setting
5995      * 'use_clustering'. But empirically while CPU utilization is increased
5996      * by enabling clustering, I/O throughput increases as well.
5997      */
5998     .use_clustering             = ENABLE_CLUSTERING,
5999 };
6000 #include "scsi_module.c"
6001
6002
6003 /*
6004  * --- Miscellaneous Driver Functions
6005  */
6006
6007 /*
6008  * First-level interrupt handler.
6009  *
6010  * 'dev_id' is a pointer to the interrupting adapter's asc_board_t. Because
6011  * all boards are currently checked for interrupts on each interrupt, 'dev_id'
6012  * is not referenced. 'dev_id' could be used to identify an interrupt passed
6013  * to the AdvanSys driver which is for a device sharing an interrupt with
6014  * an AdvanSys adapter.
6015  */
6016 STATIC irqreturn_t
6017 advansys_interrupt(int irq, void *dev_id, struct pt_regs *regs)
6018 {
6019     ulong           flags;
6020     int             i;
6021     asc_board_t     *boardp;
6022     struct scsi_cmnd       *done_scp = NULL, *last_scp = NULL;
6023     struct scsi_cmnd       *new_last_scp;
6024     struct Scsi_Host *shp;
6025
6026     ASC_DBG(1, "advansys_interrupt: begin\n");
6027
6028     /*
6029      * Check for interrupts on all boards.
6030      * AscISR() will call asc_isr_callback().
6031      */
6032     for (i = 0; i < asc_board_count; i++) {
6033         shp = asc_host[i];
6034         boardp = ASC_BOARDP(shp);
6035         ASC_DBG2(2, "advansys_interrupt: i %d, boardp 0x%lx\n",
6036             i, (ulong) boardp);
6037         spin_lock_irqsave(&boardp->lock, flags);
6038         if (ASC_NARROW_BOARD(boardp)) {
6039             /*
6040              * Narrow Board
6041              */
6042             if (AscIsIntPending(shp->io_port)) {
6043                 ASC_STATS(shp, interrupt);
6044                 ASC_DBG(1, "advansys_interrupt: before AscISR()\n");
6045                 AscISR(&boardp->dvc_var.asc_dvc_var);
6046             }
6047         } else {
6048             /*
6049              * Wide Board
6050              */
6051             ASC_DBG(1, "advansys_interrupt: before AdvISR()\n");
6052             if (AdvISR(&boardp->dvc_var.adv_dvc_var)) {
6053                 ASC_STATS(shp, interrupt);
6054             }
6055         }
6056
6057         /*
6058          * Start waiting requests and create a list of completed requests.
6059          *
6060          * If a reset request is being performed for the board, the reset
6061          * handler will complete pending requests after it has completed.
6062          */
6063         if ((boardp->flags & ASC_HOST_IN_RESET) == 0) {
6064             ASC_DBG2(1, "advansys_interrupt: done_scp 0x%lx, last_scp 0x%lx\n",
6065                 (ulong) done_scp, (ulong) last_scp);
6066
6067             /* Start any waiting commands for the board. */
6068             if (!ASC_QUEUE_EMPTY(&boardp->waiting)) {
6069                 ASC_DBG(1, "advansys_interrupt: before asc_execute_queue()\n");
6070                 asc_execute_queue(&boardp->waiting);
6071             }
6072
6073              /*
6074               * Add to the list of requests that must be completed.
6075               *
6076               * 'done_scp' will always be NULL on the first iteration
6077               * of this loop. 'last_scp' is set at the same time as
6078               * 'done_scp'.
6079               */
6080             if (done_scp == NULL) {
6081                 done_scp = asc_dequeue_list(&boardp->done, &last_scp,
6082                     ASC_TID_ALL);
6083             } else {
6084                 ASC_ASSERT(last_scp != NULL);
6085                 last_scp->host_scribble = (unsigned char *)asc_dequeue_list(
6086                         &boardp->done, &new_last_scp, ASC_TID_ALL);
6087                 if (new_last_scp != NULL) {
6088                     ASC_ASSERT(REQPNEXT(last_scp) != NULL);
6089                     last_scp = new_last_scp;
6090                 }
6091             }
6092         }
6093         spin_unlock_irqrestore(&boardp->lock, flags);
6094     }
6095
6096     /*
6097      * If interrupts were enabled on entry, then they
6098      * are now enabled here.
6099      *
6100      * Complete all requests on the done list.
6101      */
6102
6103     asc_scsi_done_list(done_scp);
6104
6105     ASC_DBG(1, "advansys_interrupt: end\n");
6106     return IRQ_HANDLED;
6107 }
6108
6109 /*
6110  * Set the number of commands to queue per device for the
6111  * specified host adapter.
6112  */
6113 STATIC int
6114 advansys_slave_configure(struct scsi_device *device)
6115 {
6116     asc_board_t        *boardp;
6117
6118     boardp = ASC_BOARDP(device->host);
6119     boardp->flags |= ASC_SELECT_QUEUE_DEPTHS;
6120     /*
6121      * Save a pointer to the device and set its initial/maximum
6122      * queue depth.  Only save the pointer for a lun0 dev though.
6123      */
6124     if(device->lun == 0)
6125         boardp->device[device->id] = device;
6126     if(device->tagged_supported) {
6127         if (ASC_NARROW_BOARD(boardp)) {
6128             scsi_adjust_queue_depth(device, MSG_ORDERED_TAG,
6129                 boardp->dvc_var.asc_dvc_var.max_dvc_qng[device->id]);
6130         } else {
6131             scsi_adjust_queue_depth(device, MSG_ORDERED_TAG,
6132                 boardp->dvc_var.adv_dvc_var.max_dvc_qng);
6133         }
6134     } else {
6135         scsi_adjust_queue_depth(device, 0, device->host->cmd_per_lun);
6136     }
6137     ASC_DBG4(1, "advansys_slave_configure: device 0x%lx, boardp 0x%lx, id %d, depth %d\n",
6138             (ulong) device, (ulong) boardp, device->id, device->queue_depth);
6139     return 0;
6140 }
6141
6142 /*
6143  * Complete all requests on the singly linked list pointed
6144  * to by 'scp'.
6145  *
6146  * Interrupts can be enabled on entry.
6147  */
6148 STATIC void
6149 asc_scsi_done_list(struct scsi_cmnd *scp)
6150 {
6151     struct scsi_cmnd    *tscp;
6152
6153     ASC_DBG(2, "asc_scsi_done_list: begin\n");
6154     while (scp != NULL) {
6155         asc_board_t *boardp;
6156         struct device *dev;
6157
6158         ASC_DBG1(3, "asc_scsi_done_list: scp 0x%lx\n", (ulong) scp);
6159         tscp = REQPNEXT(scp);
6160         scp->host_scribble = NULL;
6161
6162         boardp = ASC_BOARDP(scp->device->host);
6163
6164         if (ASC_NARROW_BOARD(boardp))
6165             dev = boardp->dvc_cfg.asc_dvc_cfg.dev;
6166         else
6167             dev = boardp->dvc_cfg.adv_dvc_cfg.dev;
6168
6169         if (scp->use_sg)
6170             dma_unmap_sg(dev, (struct scatterlist *)scp->request_buffer,
6171                          scp->use_sg, scp->sc_data_direction);
6172         else if (scp->request_bufflen)
6173             dma_unmap_single(dev, scp->SCp.dma_handle,
6174                              scp->request_bufflen, scp->sc_data_direction);
6175
6176         ASC_STATS(scp->device->host, done);
6177         ASC_ASSERT(scp->scsi_done != NULL);
6178
6179         scp->scsi_done(scp);
6180
6181         scp = tscp;
6182     }
6183     ASC_DBG(2, "asc_scsi_done_list: done\n");
6184     return;
6185 }
6186
6187 /*
6188  * Execute a single 'Scsi_Cmnd'.
6189  *
6190  * The function 'done' is called when the request has been completed.
6191  *
6192  * Scsi_Cmnd:
6193  *
6194  *  host - board controlling device
6195  *  device - device to send command
6196  *  target - target of device
6197  *  lun - lun of device
6198  *  cmd_len - length of SCSI CDB
6199  *  cmnd - buffer for SCSI 8, 10, or 12 byte CDB
6200  *  use_sg - if non-zero indicates scatter-gather request with use_sg elements
6201  *
6202  *  if (use_sg == 0) {
6203  *    request_buffer - buffer address for request
6204  *    request_bufflen - length of request buffer
6205  *  } else {
6206  *    request_buffer - pointer to scatterlist structure
6207  *  }
6208  *
6209  *  sense_buffer - sense command buffer
6210  *
6211  *  result (4 bytes of an int):
6212  *    Byte Meaning
6213  *    0 SCSI Status Byte Code
6214  *    1 SCSI One Byte Message Code
6215  *    2 Host Error Code
6216  *    3 Mid-Level Error Code
6217  *
6218  *  host driver fields:
6219  *    SCp - Scsi_Pointer used for command processing status
6220  *    scsi_done - used to save caller's done function
6221  *    host_scribble - used for pointer to another struct scsi_cmnd
6222  *
6223  * If this function returns ASC_NOERROR the request has been enqueued
6224  * on the board's 'active' queue and will be completed from the
6225  * interrupt handler.
6226  *
6227  * If this function returns ASC_NOERROR the request has been enqueued
6228  * on the board's 'done' queue and must be completed by the caller.
6229  *
6230  * If ASC_BUSY is returned the request will be enqueued by the
6231  * caller on the target's waiting queue and re-tried later.
6232  */
6233 STATIC int
6234 asc_execute_scsi_cmnd(struct scsi_cmnd *scp)
6235 {
6236     asc_board_t        *boardp;
6237     ASC_DVC_VAR        *asc_dvc_varp;
6238     ADV_DVC_VAR        *adv_dvc_varp;
6239     ADV_SCSI_REQ_Q     *adv_scsiqp;
6240     struct scsi_device *device;
6241     int                ret;
6242
6243     ASC_DBG2(1, "asc_execute_scsi_cmnd: scp 0x%lx, done 0x%lx\n",
6244         (ulong) scp, (ulong) scp->scsi_done);
6245
6246     boardp = ASC_BOARDP(scp->device->host);
6247     device = boardp->device[scp->device->id];
6248
6249     if (ASC_NARROW_BOARD(boardp)) {
6250         /*
6251          * Build and execute Narrow Board request.
6252          */
6253
6254         asc_dvc_varp = &boardp->dvc_var.asc_dvc_var;
6255
6256         /*
6257          * Build Asc Library request structure using the
6258          * global structures 'asc_scsi_req' and 'asc_sg_head'.
6259          *
6260          * If an error is returned, then the request has been
6261          * queued on the board done queue. It will be completed
6262          * by the caller.
6263          *
6264          * asc_build_req() can not return ASC_BUSY.
6265          */
6266         if (asc_build_req(boardp, scp) == ASC_ERROR) {
6267             ASC_STATS(scp->device->host, build_error);
6268             return ASC_ERROR;
6269         }
6270
6271         /*
6272          * Execute the command. If there is no error, add the command
6273          * to the active queue.
6274          */
6275         switch (ret = AscExeScsiQueue(asc_dvc_varp, &asc_scsi_q)) {
6276         case ASC_NOERROR:
6277             ASC_STATS(scp->device->host, exe_noerror);
6278             /*
6279              * Increment monotonically increasing per device successful
6280              * request counter. Wrapping doesn't matter.
6281              */
6282             boardp->reqcnt[scp->device->id]++;
6283             asc_enqueue(&boardp->active, scp, ASC_BACK);
6284             ASC_DBG(1,
6285                 "asc_execute_scsi_cmnd: AscExeScsiQueue(), ASC_NOERROR\n");
6286             break;
6287         case ASC_BUSY:
6288             /*
6289              * Caller will enqueue request on the target's waiting queue
6290              * and retry later.
6291              */
6292             ASC_STATS(scp->device->host, exe_busy);
6293             break;
6294         case ASC_ERROR:
6295             ASC_PRINT2(
6296 "asc_execute_scsi_cmnd: board %d: AscExeScsiQueue() ASC_ERROR, err_code 0x%x\n",
6297                 boardp->id, asc_dvc_varp->err_code);
6298             ASC_STATS(scp->device->host, exe_error);
6299             scp->result = HOST_BYTE(DID_ERROR);
6300             asc_enqueue(&boardp->done, scp, ASC_BACK);
6301             break;
6302         default:
6303             ASC_PRINT2(
6304 "asc_execute_scsi_cmnd: board %d: AscExeScsiQueue() unknown, err_code 0x%x\n",
6305                 boardp->id, asc_dvc_varp->err_code);
6306             ASC_STATS(scp->device->host, exe_unknown);
6307             scp->result = HOST_BYTE(DID_ERROR);
6308             asc_enqueue(&boardp->done, scp, ASC_BACK);
6309             break;
6310         }
6311     } else {
6312         /*
6313          * Build and execute Wide Board request.
6314          */
6315         adv_dvc_varp = &boardp->dvc_var.adv_dvc_var;
6316
6317         /*
6318          * Build and get a pointer to an Adv Library request structure.
6319          *
6320          * If the request is successfully built then send it below,
6321          * otherwise return with an error.
6322          */
6323         switch (adv_build_req(boardp, scp, &adv_scsiqp)) {
6324         case ASC_NOERROR:
6325             ASC_DBG(3, "asc_execute_scsi_cmnd: adv_build_req ASC_NOERROR\n");
6326             break;
6327         case ASC_BUSY:
6328             ASC_DBG(1, "asc_execute_scsi_cmnd: adv_build_req ASC_BUSY\n");
6329             /*
6330              * If busy is returned the request has not been enqueued.
6331              * It will be enqueued by the caller on the target's waiting
6332              * queue and retried later.
6333              *
6334              * The asc_stats fields 'adv_build_noreq' and 'adv_build_nosg'
6335              * count wide board busy conditions. They are updated in
6336              * adv_build_req and adv_get_sglist, respectively.
6337              */
6338             return ASC_BUSY;
6339         case ASC_ERROR:
6340              /* 
6341               * If an error is returned, then the request has been
6342               * queued on the board done queue. It will be completed
6343               * by the caller.
6344               */
6345         default:
6346             ASC_DBG(1, "asc_execute_scsi_cmnd: adv_build_req ASC_ERROR\n");
6347             ASC_STATS(scp->device->host, build_error);
6348             return ASC_ERROR;
6349         }
6350
6351         /*
6352          * Execute the command. If there is no error, add the command
6353          * to the active queue.
6354          */
6355         switch (ret = AdvExeScsiQueue(adv_dvc_varp, adv_scsiqp)) {
6356         case ASC_NOERROR:
6357             ASC_STATS(scp->device->host, exe_noerror);
6358             /*
6359              * Increment monotonically increasing per device successful
6360              * request counter. Wrapping doesn't matter.
6361              */
6362             boardp->reqcnt[scp->device->id]++;
6363             asc_enqueue(&boardp->active, scp, ASC_BACK);
6364             ASC_DBG(1,
6365                 "asc_execute_scsi_cmnd: AdvExeScsiQueue(), ASC_NOERROR\n");
6366             break;
6367         case ASC_BUSY:
6368             /*
6369              * Caller will enqueue request on the target's waiting queue
6370              * and retry later.
6371              */
6372             ASC_STATS(scp->device->host, exe_busy);
6373             break;
6374         case ASC_ERROR:
6375             ASC_PRINT2(
6376 "asc_execute_scsi_cmnd: board %d: AdvExeScsiQueue() ASC_ERROR, err_code 0x%x\n",
6377                 boardp->id, adv_dvc_varp->err_code);
6378             ASC_STATS(scp->device->host, exe_error);
6379             scp->result = HOST_BYTE(DID_ERROR);
6380             asc_enqueue(&boardp->done, scp, ASC_BACK);
6381             break;
6382         default:
6383             ASC_PRINT2(
6384 "asc_execute_scsi_cmnd: board %d: AdvExeScsiQueue() unknown, err_code 0x%x\n",
6385                 boardp->id, adv_dvc_varp->err_code);
6386             ASC_STATS(scp->device->host, exe_unknown);
6387             scp->result = HOST_BYTE(DID_ERROR);
6388             asc_enqueue(&boardp->done, scp, ASC_BACK);
6389             break;
6390         }
6391     }
6392
6393     ASC_DBG(1, "asc_execute_scsi_cmnd: end\n");
6394     return ret;
6395 }
6396
6397 /*
6398  * Build a request structure for the Asc Library (Narrow Board).
6399  *
6400  * The global structures 'asc_scsi_q' and 'asc_sg_head' are
6401  * used to build the request.
6402  *
6403  * If an error occurs, then queue the request on the board done
6404  * queue and return ASC_ERROR.
6405  */
6406 STATIC int
6407 asc_build_req(asc_board_t *boardp, struct scsi_cmnd *scp)
6408 {
6409     struct device *dev = boardp->dvc_cfg.asc_dvc_cfg.dev;
6410
6411     /*
6412      * Mutually exclusive access is required to 'asc_scsi_q' and
6413      * 'asc_sg_head' until after the request is started.
6414      */
6415     memset(&asc_scsi_q, 0, sizeof(ASC_SCSI_Q));
6416
6417     /*
6418      * Point the ASC_SCSI_Q to the 'struct scsi_cmnd'.
6419      */
6420     asc_scsi_q.q2.srb_ptr = ASC_VADDR_TO_U32(scp);
6421
6422     /*
6423      * Build the ASC_SCSI_Q request.
6424      *
6425      * For narrow boards a CDB length maximum of 12 bytes
6426      * is supported.
6427      */
6428     if (scp->cmd_len > ASC_MAX_CDB_LEN) {
6429         ASC_PRINT3(
6430 "asc_build_req: board %d: cmd_len %d > ASC_MAX_CDB_LEN  %d\n",
6431             boardp->id, scp->cmd_len, ASC_MAX_CDB_LEN);
6432         scp->result = HOST_BYTE(DID_ERROR);
6433         asc_enqueue(&boardp->done, scp, ASC_BACK);
6434         return ASC_ERROR;
6435     }
6436     asc_scsi_q.cdbptr = &scp->cmnd[0];
6437     asc_scsi_q.q2.cdb_len = scp->cmd_len;
6438     asc_scsi_q.q1.target_id = ASC_TID_TO_TARGET_ID(scp->device->id);
6439     asc_scsi_q.q1.target_lun = scp->device->lun;
6440     asc_scsi_q.q2.target_ix = ASC_TIDLUN_TO_IX(scp->device->id, scp->device->lun);
6441     asc_scsi_q.q1.sense_addr = cpu_to_le32(virt_to_bus(&scp->sense_buffer[0]));
6442     asc_scsi_q.q1.sense_len = sizeof(scp->sense_buffer);
6443
6444     /*
6445      * If there are any outstanding requests for the current target,
6446      * then every 255th request send an ORDERED request. This heuristic
6447      * tries to retain the benefit of request sorting while preventing
6448      * request starvation. 255 is the max number of tags or pending commands
6449      * a device may have outstanding.
6450      *
6451      * The request count is incremented below for every successfully
6452      * started request.
6453      *
6454      */
6455     if ((boardp->dvc_var.asc_dvc_var.cur_dvc_qng[scp->device->id] > 0) &&
6456         (boardp->reqcnt[scp->device->id] % 255) == 0) {
6457         asc_scsi_q.q2.tag_code = MSG_ORDERED_TAG;
6458     } else {
6459         asc_scsi_q.q2.tag_code = MSG_SIMPLE_TAG;
6460     }
6461
6462     /*
6463      * Build ASC_SCSI_Q for a contiguous buffer or a scatter-gather
6464      * buffer command.
6465      */
6466     if (scp->use_sg == 0) {
6467         /*
6468          * CDB request of single contiguous buffer.
6469          */
6470         ASC_STATS(scp->device->host, cont_cnt);
6471         scp->SCp.dma_handle = scp->request_bufflen ?
6472             dma_map_single(dev, scp->request_buffer,
6473                            scp->request_bufflen, scp->sc_data_direction) : 0;
6474         asc_scsi_q.q1.data_addr = cpu_to_le32(scp->SCp.dma_handle);
6475         asc_scsi_q.q1.data_cnt = cpu_to_le32(scp->request_bufflen);
6476         ASC_STATS_ADD(scp->device->host, cont_xfer,
6477                       ASC_CEILING(scp->request_bufflen, 512));
6478         asc_scsi_q.q1.sg_queue_cnt = 0;
6479         asc_scsi_q.sg_head = NULL;
6480     } else {
6481         /*
6482          * CDB scatter-gather request list.
6483          */
6484         int                     sgcnt;
6485         int                     use_sg;
6486         struct scatterlist      *slp;
6487
6488         slp = (struct scatterlist *)scp->request_buffer;
6489         use_sg = dma_map_sg(dev, slp, scp->use_sg, scp->sc_data_direction);
6490
6491         if (use_sg > scp->device->host->sg_tablesize) {
6492             ASC_PRINT3(
6493 "asc_build_req: board %d: use_sg %d > sg_tablesize %d\n",
6494                 boardp->id, use_sg, scp->device->host->sg_tablesize);
6495             dma_unmap_sg(dev, slp, scp->use_sg, scp->sc_data_direction);
6496             scp->result = HOST_BYTE(DID_ERROR);
6497             asc_enqueue(&boardp->done, scp, ASC_BACK);
6498             return ASC_ERROR;
6499         }
6500
6501         ASC_STATS(scp->device->host, sg_cnt);
6502
6503         /*
6504          * Use global ASC_SG_HEAD structure and set the ASC_SCSI_Q
6505          * structure to point to it.
6506          */
6507         memset(&asc_sg_head, 0, sizeof(ASC_SG_HEAD));
6508
6509         asc_scsi_q.q1.cntl |= QC_SG_HEAD;
6510         asc_scsi_q.sg_head = &asc_sg_head;
6511         asc_scsi_q.q1.data_cnt = 0;
6512         asc_scsi_q.q1.data_addr = 0;
6513         /* This is a byte value, otherwise it would need to be swapped. */
6514         asc_sg_head.entry_cnt = asc_scsi_q.q1.sg_queue_cnt = use_sg;
6515         ASC_STATS_ADD(scp->device->host, sg_elem, asc_sg_head.entry_cnt);
6516
6517         /*
6518          * Convert scatter-gather list into ASC_SG_HEAD list.
6519          */
6520         for (sgcnt = 0; sgcnt < use_sg; sgcnt++, slp++) {
6521             asc_sg_head.sg_list[sgcnt].addr = cpu_to_le32(sg_dma_address(slp));
6522             asc_sg_head.sg_list[sgcnt].bytes = cpu_to_le32(sg_dma_len(slp));
6523             ASC_STATS_ADD(scp->device->host, sg_xfer, ASC_CEILING(sg_dma_len(slp), 512));
6524         }
6525     }
6526
6527     ASC_DBG_PRT_ASC_SCSI_Q(2, &asc_scsi_q);
6528     ASC_DBG_PRT_CDB(1, scp->cmnd, scp->cmd_len);
6529
6530     return ASC_NOERROR;
6531 }
6532
6533 /*
6534  * Build a request structure for the Adv Library (Wide Board).
6535  *
6536  * If an adv_req_t can not be allocated to issue the request,
6537  * then return ASC_BUSY. If an error occurs, then return ASC_ERROR.
6538  *
6539  * Multi-byte fields in the ASC_SCSI_REQ_Q that are used by the
6540  * microcode for DMA addresses or math operations are byte swapped
6541  * to little-endian order.
6542  */
6543 STATIC int
6544 adv_build_req(asc_board_t *boardp, struct scsi_cmnd *scp,
6545     ADV_SCSI_REQ_Q **adv_scsiqpp)
6546 {
6547     adv_req_t           *reqp;
6548     ADV_SCSI_REQ_Q      *scsiqp;
6549     int                 i;
6550     int                 ret;
6551     struct device       *dev = boardp->dvc_cfg.adv_dvc_cfg.dev;
6552
6553     /*
6554      * Allocate an adv_req_t structure from the board to execute
6555      * the command.
6556      */
6557     if (boardp->adv_reqp == NULL) {
6558         ASC_DBG(1, "adv_build_req: no free adv_req_t\n");
6559         ASC_STATS(scp->device->host, adv_build_noreq);
6560         return ASC_BUSY;
6561     } else {
6562         reqp = boardp->adv_reqp;
6563         boardp->adv_reqp = reqp->next_reqp;
6564         reqp->next_reqp = NULL;
6565     }
6566
6567     /*
6568      * Get 32-byte aligned ADV_SCSI_REQ_Q and ADV_SG_BLOCK pointers.
6569      */
6570     scsiqp = (ADV_SCSI_REQ_Q *) ADV_32BALIGN(&reqp->scsi_req_q);
6571
6572     /*
6573      * Initialize the structure.
6574      */
6575     scsiqp->cntl = scsiqp->scsi_cntl = scsiqp->done_status = 0;
6576
6577     /*
6578      * Set the ADV_SCSI_REQ_Q 'srb_ptr' to point to the adv_req_t structure.
6579      */
6580     scsiqp->srb_ptr = ASC_VADDR_TO_U32(reqp);
6581
6582     /*
6583      * Set the adv_req_t 'cmndp' to point to the struct scsi_cmnd structure.
6584      */
6585     reqp->cmndp = scp;
6586
6587     /*
6588      * Build the ADV_SCSI_REQ_Q request.
6589      */
6590
6591     /*
6592      * Set CDB length and copy it to the request structure.
6593      * For wide  boards a CDB length maximum of 16 bytes
6594      * is supported.
6595      */
6596     if (scp->cmd_len > ADV_MAX_CDB_LEN) {
6597         ASC_PRINT3(
6598 "adv_build_req: board %d: cmd_len %d > ADV_MAX_CDB_LEN  %d\n",
6599             boardp->id, scp->cmd_len, ADV_MAX_CDB_LEN);
6600         scp->result = HOST_BYTE(DID_ERROR);
6601         asc_enqueue(&boardp->done, scp, ASC_BACK);
6602         return ASC_ERROR;
6603     }
6604     scsiqp->cdb_len = scp->cmd_len;
6605     /* Copy first 12 CDB bytes to cdb[]. */
6606     for (i = 0; i < scp->cmd_len && i < 12; i++) {
6607         scsiqp->cdb[i] = scp->cmnd[i];
6608     }
6609     /* Copy last 4 CDB bytes, if present, to cdb16[]. */
6610     for (; i < scp->cmd_len; i++) {
6611         scsiqp->cdb16[i - 12] = scp->cmnd[i];
6612     }
6613
6614     scsiqp->target_id = scp->device->id;
6615     scsiqp->target_lun = scp->device->lun;
6616
6617     scsiqp->sense_addr = cpu_to_le32(virt_to_bus(&scp->sense_buffer[0]));
6618     scsiqp->sense_len = sizeof(scp->sense_buffer);
6619
6620     /*
6621      * Build ADV_SCSI_REQ_Q for a contiguous buffer or a scatter-gather
6622      * buffer command.
6623      */
6624
6625     scsiqp->data_cnt = cpu_to_le32(scp->request_bufflen);
6626     scsiqp->vdata_addr = scp->request_buffer;
6627     scsiqp->data_addr = cpu_to_le32(virt_to_bus(scp->request_buffer));
6628
6629     if (scp->use_sg == 0) {
6630         /*
6631          * CDB request of single contiguous buffer.
6632          */
6633         reqp->sgblkp = NULL;
6634         scsiqp->data_cnt = cpu_to_le32(scp->request_bufflen);
6635         if (scp->request_bufflen) {
6636             scsiqp->vdata_addr = scp->request_buffer;
6637             scp->SCp.dma_handle =
6638                 dma_map_single(dev, scp->request_buffer,
6639                                scp->request_bufflen, scp->sc_data_direction);
6640         } else {
6641             scsiqp->vdata_addr = 0;
6642             scp->SCp.dma_handle = 0;
6643         }
6644         scsiqp->data_addr = cpu_to_le32(scp->SCp.dma_handle);
6645         scsiqp->sg_list_ptr = NULL;
6646         scsiqp->sg_real_addr = 0;
6647         ASC_STATS(scp->device->host, cont_cnt);
6648         ASC_STATS_ADD(scp->device->host, cont_xfer,
6649                       ASC_CEILING(scp->request_bufflen, 512));
6650     } else {
6651         /*
6652          * CDB scatter-gather request list.
6653          */
6654         struct scatterlist *slp;
6655         int use_sg;
6656
6657         slp = (struct scatterlist *)scp->request_buffer;
6658         use_sg = dma_map_sg(dev, slp, scp->use_sg, scp->sc_data_direction);
6659
6660         if (use_sg > ADV_MAX_SG_LIST) {
6661             ASC_PRINT3(
6662 "adv_build_req: board %d: use_sg %d > ADV_MAX_SG_LIST %d\n",
6663                 boardp->id, use_sg, scp->device->host->sg_tablesize);
6664             dma_unmap_sg(dev, slp, scp->use_sg, scp->sc_data_direction);
6665             scp->result = HOST_BYTE(DID_ERROR);
6666             asc_enqueue(&boardp->done, scp, ASC_BACK);
6667
6668             /*
6669              * Free the 'adv_req_t' structure by adding it back to the
6670              * board free list.
6671              */
6672             reqp->next_reqp = boardp->adv_reqp;
6673             boardp->adv_reqp = reqp;
6674
6675             return ASC_ERROR;
6676         }
6677
6678         if ((ret = adv_get_sglist(boardp, reqp, scp, use_sg)) != ADV_SUCCESS) {
6679             /*
6680              * Free the adv_req_t structure by adding it back to the
6681              * board free list.
6682              */
6683             reqp->next_reqp = boardp->adv_reqp;
6684             boardp->adv_reqp = reqp;
6685
6686             return ret;
6687         }
6688
6689         ASC_STATS(scp->device->host, sg_cnt);
6690         ASC_STATS_ADD(scp->device->host, sg_elem, use_sg);
6691     }
6692
6693     ASC_DBG_PRT_ADV_SCSI_REQ_Q(2, scsiqp);
6694     ASC_DBG_PRT_CDB(1, scp->cmnd, scp->cmd_len);
6695
6696     *adv_scsiqpp = scsiqp;
6697
6698     return ASC_NOERROR;
6699 }
6700
6701 /*
6702  * Build scatter-gather list for Adv Library (Wide Board).
6703  *
6704  * Additional ADV_SG_BLOCK structures will need to be allocated
6705  * if the total number of scatter-gather elements exceeds
6706  * NO_OF_SG_PER_BLOCK (15). The ADV_SG_BLOCK structures are
6707  * assumed to be physically contiguous.
6708  *
6709  * Return:
6710  *      ADV_SUCCESS(1) - SG List successfully created
6711  *      ADV_ERROR(-1) - SG List creation failed
6712  */
6713 STATIC int
6714 adv_get_sglist(asc_board_t *boardp, adv_req_t *reqp, struct scsi_cmnd *scp, int use_sg)
6715 {
6716     adv_sgblk_t         *sgblkp;
6717     ADV_SCSI_REQ_Q      *scsiqp;
6718     struct scatterlist  *slp;
6719     int                 sg_elem_cnt;
6720     ADV_SG_BLOCK        *sg_block, *prev_sg_block;
6721     ADV_PADDR           sg_block_paddr;
6722     int                 i;
6723
6724     scsiqp = (ADV_SCSI_REQ_Q *) ADV_32BALIGN(&reqp->scsi_req_q);
6725     slp = (struct scatterlist *) scp->request_buffer;
6726     sg_elem_cnt = use_sg;
6727     prev_sg_block = NULL;
6728     reqp->sgblkp = NULL;
6729
6730     do
6731     {
6732         /*
6733          * Allocate a 'adv_sgblk_t' structure from the board free
6734          * list. One 'adv_sgblk_t' structure holds NO_OF_SG_PER_BLOCK
6735          * (15) scatter-gather elements.
6736          */
6737         if ((sgblkp = boardp->adv_sgblkp) == NULL) {
6738             ASC_DBG(1, "adv_get_sglist: no free adv_sgblk_t\n");
6739             ASC_STATS(scp->device->host, adv_build_nosg);
6740
6741             /*
6742              * Allocation failed. Free 'adv_sgblk_t' structures already
6743              * allocated for the request.
6744              */
6745             while ((sgblkp = reqp->sgblkp) != NULL)
6746             {
6747                 /* Remove 'sgblkp' from the request list. */
6748                 reqp->sgblkp = sgblkp->next_sgblkp;
6749
6750                 /* Add 'sgblkp' to the board free list. */
6751                 sgblkp->next_sgblkp = boardp->adv_sgblkp;
6752                 boardp->adv_sgblkp = sgblkp;
6753             }
6754             return ASC_BUSY;
6755         } else {
6756             /* Complete 'adv_sgblk_t' board allocation. */
6757             boardp->adv_sgblkp = sgblkp->next_sgblkp;
6758             sgblkp->next_sgblkp = NULL;
6759
6760             /*
6761              * Get 8 byte aligned virtual and physical addresses for
6762              * the allocated ADV_SG_BLOCK structure.
6763              */
6764             sg_block = (ADV_SG_BLOCK *) ADV_8BALIGN(&sgblkp->sg_block);
6765             sg_block_paddr = virt_to_bus(sg_block);
6766
6767             /*
6768              * Check if this is the first 'adv_sgblk_t' for the request.
6769              */
6770             if (reqp->sgblkp == NULL)
6771             {
6772                 /* Request's first scatter-gather block. */
6773                 reqp->sgblkp = sgblkp;
6774
6775                 /*
6776                  * Set ADV_SCSI_REQ_T ADV_SG_BLOCK virtual and physical
6777                  * address pointers.
6778                  */
6779                 scsiqp->sg_list_ptr = sg_block;
6780                 scsiqp->sg_real_addr = cpu_to_le32(sg_block_paddr);
6781             } else
6782             {
6783                 /* Request's second or later scatter-gather block. */
6784                 sgblkp->next_sgblkp = reqp->sgblkp;
6785                 reqp->sgblkp = sgblkp;
6786
6787                 /*
6788                  * Point the previous ADV_SG_BLOCK structure to
6789                  * the newly allocated ADV_SG_BLOCK structure.
6790                  */
6791                 ASC_ASSERT(prev_sg_block != NULL);
6792                 prev_sg_block->sg_ptr = cpu_to_le32(sg_block_paddr);
6793             }
6794         }
6795
6796         for (i = 0; i < NO_OF_SG_PER_BLOCK; i++)
6797         {
6798             sg_block->sg_list[i].sg_addr = cpu_to_le32(sg_dma_address(slp));
6799             sg_block->sg_list[i].sg_count = cpu_to_le32(sg_dma_len(slp));
6800             ASC_STATS_ADD(scp->device->host, sg_xfer, ASC_CEILING(sg_dma_len(slp), 512));
6801
6802             if (--sg_elem_cnt == 0)
6803             {   /* Last ADV_SG_BLOCK and scatter-gather entry. */
6804                 sg_block->sg_cnt = i + 1;
6805                 sg_block->sg_ptr = 0L;    /* Last ADV_SG_BLOCK in list. */
6806                 return ADV_SUCCESS;
6807             }
6808             slp++;
6809         }
6810         sg_block->sg_cnt = NO_OF_SG_PER_BLOCK;
6811         prev_sg_block = sg_block;
6812     }
6813     while (1);
6814     /* NOTREACHED */
6815 }
6816
6817 /*
6818  * asc_isr_callback() - Second Level Interrupt Handler called by AscISR().
6819  *
6820  * Interrupt callback function for the Narrow SCSI Asc Library.
6821  */
6822 STATIC void
6823 asc_isr_callback(ASC_DVC_VAR *asc_dvc_varp, ASC_QDONE_INFO *qdonep)
6824 {
6825     asc_board_t         *boardp;
6826     struct scsi_cmnd           *scp;
6827     struct Scsi_Host    *shp;
6828     int                 i;
6829
6830     ASC_DBG2(1, "asc_isr_callback: asc_dvc_varp 0x%lx, qdonep 0x%lx\n",
6831         (ulong) asc_dvc_varp, (ulong) qdonep);
6832     ASC_DBG_PRT_ASC_QDONE_INFO(2, qdonep);
6833
6834     /*
6835      * Get the struct scsi_cmnd structure and Scsi_Host structure for the
6836      * command that has been completed.
6837      */
6838     scp = (struct scsi_cmnd *) ASC_U32_TO_VADDR(qdonep->d2.srb_ptr);
6839     ASC_DBG1(1, "asc_isr_callback: scp 0x%lx\n", (ulong) scp);
6840
6841     if (scp == NULL) {
6842         ASC_PRINT("asc_isr_callback: scp is NULL\n");
6843         return;
6844     }
6845     ASC_DBG_PRT_CDB(2, scp->cmnd, scp->cmd_len);
6846
6847     /*
6848      * If the request's host pointer is not valid, display a
6849      * message and return.
6850      */
6851     shp = scp->device->host;
6852     for (i = 0; i < asc_board_count; i++) {
6853         if (asc_host[i] == shp) {
6854             break;
6855         }
6856     }
6857     if (i == asc_board_count) {
6858         ASC_PRINT2(
6859             "asc_isr_callback: scp 0x%lx has bad host pointer, host 0x%lx\n",
6860             (ulong) scp, (ulong) shp);
6861         return;
6862     }
6863
6864     ASC_STATS(shp, callback);
6865     ASC_DBG1(1, "asc_isr_callback: shp 0x%lx\n", (ulong) shp);
6866
6867     /*
6868      * If the request isn't found on the active queue, it may
6869      * have been removed to handle a reset request.
6870      * Display a message and return.
6871      */
6872     boardp = ASC_BOARDP(shp);
6873     ASC_ASSERT(asc_dvc_varp == &boardp->dvc_var.asc_dvc_var);
6874     if (asc_rmqueue(&boardp->active, scp) == ASC_FALSE) {
6875         ASC_PRINT2(
6876             "asc_isr_callback: board %d: scp 0x%lx not on active queue\n",
6877             boardp->id, (ulong) scp);
6878         return;
6879     }
6880
6881     /*
6882      * 'qdonep' contains the command's ending status.
6883      */
6884     switch (qdonep->d3.done_stat) {
6885     case QD_NO_ERROR:
6886         ASC_DBG(2, "asc_isr_callback: QD_NO_ERROR\n");
6887         scp->result = 0;
6888
6889         /*
6890          * If an INQUIRY command completed successfully, then call
6891          * the AscInquiryHandling() function to set-up the device.
6892          */
6893         if (scp->cmnd[0] == INQUIRY && scp->device->lun == 0 &&
6894             (scp->request_bufflen - qdonep->remain_bytes) >= 8)
6895         {
6896             AscInquiryHandling(asc_dvc_varp, scp->device->id & 0x7,
6897                 (ASC_SCSI_INQUIRY *) scp->request_buffer);
6898         }
6899
6900         /*
6901          * Check for an underrun condition.
6902          *
6903          * If there was no error and an underrun condition, then
6904          * then return the number of underrun bytes.
6905          */
6906         if (scp->request_bufflen != 0 && qdonep->remain_bytes != 0 &&
6907             qdonep->remain_bytes <= scp->request_bufflen) {
6908             ASC_DBG1(1, "asc_isr_callback: underrun condition %u bytes\n",
6909             (unsigned) qdonep->remain_bytes);
6910             scp->resid = qdonep->remain_bytes;
6911         }
6912         break;
6913
6914     case QD_WITH_ERROR:
6915         ASC_DBG(2, "asc_isr_callback: QD_WITH_ERROR\n");
6916         switch (qdonep->d3.host_stat) {
6917         case QHSTA_NO_ERROR:
6918             if (qdonep->d3.scsi_stat == SAM_STAT_CHECK_CONDITION) {
6919                 ASC_DBG(2, "asc_isr_callback: SAM_STAT_CHECK_CONDITION\n");
6920                 ASC_DBG_PRT_SENSE(2, scp->sense_buffer,
6921                     sizeof(scp->sense_buffer));
6922                 /*
6923                  * Note: The 'status_byte()' macro used by target drivers
6924                  * defined in scsi.h shifts the status byte returned by
6925                  * host drivers right by 1 bit. This is why target drivers
6926                  * also use right shifted status byte definitions. For
6927                  * instance target drivers use CHECK_CONDITION, defined to
6928                  * 0x1, instead of the SCSI defined check condition value
6929                  * of 0x2. Host drivers are supposed to return the status
6930                  * byte as it is defined by SCSI.
6931                  */
6932                 scp->result = DRIVER_BYTE(DRIVER_SENSE) |
6933                     STATUS_BYTE(qdonep->d3.scsi_stat);
6934             } else {
6935                 scp->result = STATUS_BYTE(qdonep->d3.scsi_stat);
6936             }
6937             break;
6938
6939         default:
6940             /* QHSTA error occurred */
6941             ASC_DBG1(1, "asc_isr_callback: host_stat 0x%x\n",
6942                 qdonep->d3.host_stat);
6943             scp->result = HOST_BYTE(DID_BAD_TARGET);
6944             break;
6945         }
6946         break;
6947
6948     case QD_ABORTED_BY_HOST:
6949         ASC_DBG(1, "asc_isr_callback: QD_ABORTED_BY_HOST\n");
6950         scp->result = HOST_BYTE(DID_ABORT) | MSG_BYTE(qdonep->d3.scsi_msg) |
6951                 STATUS_BYTE(qdonep->d3.scsi_stat);
6952         break;
6953
6954     default:
6955         ASC_DBG1(1, "asc_isr_callback: done_stat 0x%x\n", qdonep->d3.done_stat);
6956         scp->result = HOST_BYTE(DID_ERROR) | MSG_BYTE(qdonep->d3.scsi_msg) |
6957                 STATUS_BYTE(qdonep->d3.scsi_stat);
6958         break;
6959     }
6960
6961     /*
6962      * If the 'init_tidmask' bit isn't already set for the target and the
6963      * current request finished normally, then set the bit for the target
6964      * to indicate that a device is present.
6965      */
6966     if ((boardp->init_tidmask & ADV_TID_TO_TIDMASK(scp->device->id)) == 0 &&
6967         qdonep->d3.done_stat == QD_NO_ERROR &&
6968         qdonep->d3.host_stat == QHSTA_NO_ERROR) {
6969         boardp->init_tidmask |= ADV_TID_TO_TIDMASK(scp->device->id);
6970     }
6971
6972     /*
6973      * Because interrupts may be enabled by the 'struct scsi_cmnd' done
6974      * function, add the command to the end of the board's done queue.
6975      * The done function for the command will be called from
6976      * advansys_interrupt().
6977      */
6978     asc_enqueue(&boardp->done, scp, ASC_BACK);
6979
6980     return;
6981 }
6982
6983 /*
6984  * adv_isr_callback() - Second Level Interrupt Handler called by AdvISR().
6985  *
6986  * Callback function for the Wide SCSI Adv Library.
6987  */
6988 STATIC void
6989 adv_isr_callback(ADV_DVC_VAR *adv_dvc_varp, ADV_SCSI_REQ_Q *scsiqp)
6990 {
6991     asc_board_t         *boardp;
6992     adv_req_t           *reqp;
6993     adv_sgblk_t         *sgblkp;
6994     struct scsi_cmnd           *scp;
6995     struct Scsi_Host    *shp;
6996     int                 i;
6997     ADV_DCNT            resid_cnt;
6998
6999
7000     ASC_DBG2(1, "adv_isr_callback: adv_dvc_varp 0x%lx, scsiqp 0x%lx\n",
7001         (ulong) adv_dvc_varp, (ulong) scsiqp);
7002     ASC_DBG_PRT_ADV_SCSI_REQ_Q(2, scsiqp);
7003
7004     /*
7005      * Get the adv_req_t structure for the command that has been
7006      * completed. The adv_req_t structure actually contains the
7007      * completed ADV_SCSI_REQ_Q structure.
7008      */
7009     reqp = (adv_req_t *) ADV_U32_TO_VADDR(scsiqp->srb_ptr);
7010     ASC_DBG1(1, "adv_isr_callback: reqp 0x%lx\n", (ulong) reqp);
7011     if (reqp == NULL) {
7012         ASC_PRINT("adv_isr_callback: reqp is NULL\n");
7013         return;
7014     }
7015
7016     /*
7017      * Get the struct scsi_cmnd structure and Scsi_Host structure for the
7018      * command that has been completed.
7019      *
7020      * Note: The adv_req_t request structure and adv_sgblk_t structure,
7021      * if any, are dropped, because a board structure pointer can not be
7022      * determined.
7023      */
7024     scp = reqp->cmndp;
7025     ASC_DBG1(1, "adv_isr_callback: scp 0x%lx\n", (ulong) scp);
7026     if (scp == NULL) {
7027         ASC_PRINT("adv_isr_callback: scp is NULL; adv_req_t dropped.\n");
7028         return;
7029     }
7030     ASC_DBG_PRT_CDB(2, scp->cmnd, scp->cmd_len);
7031
7032     /*
7033      * If the request's host pointer is not valid, display a message
7034      * and return.
7035      */
7036     shp = scp->device->host;
7037     for (i = 0; i < asc_board_count; i++) {
7038         if (asc_host[i] == shp) {
7039             break;
7040         }
7041     }
7042     /*
7043      * Note: If the host structure is not found, the adv_req_t request
7044      * structure and adv_sgblk_t structure, if any, is dropped.
7045      */
7046     if (i == asc_board_count) {
7047         ASC_PRINT2(
7048             "adv_isr_callback: scp 0x%lx has bad host pointer, host 0x%lx\n",
7049             (ulong) scp, (ulong) shp);
7050         return;
7051     }
7052
7053     ASC_STATS(shp, callback);
7054     ASC_DBG1(1, "adv_isr_callback: shp 0x%lx\n", (ulong) shp);
7055
7056     /*
7057      * If the request isn't found on the active queue, it may have been
7058      * removed to handle a reset request. Display a message and return.
7059      *
7060      * Note: Because the structure may still be in use don't attempt
7061      * to free the adv_req_t and adv_sgblk_t, if any, structures.
7062      */
7063     boardp = ASC_BOARDP(shp);
7064     ASC_ASSERT(adv_dvc_varp == &boardp->dvc_var.adv_dvc_var);
7065     if (asc_rmqueue(&boardp->active, scp) == ASC_FALSE) {
7066         ASC_PRINT2(
7067             "adv_isr_callback: board %d: scp 0x%lx not on active queue\n",
7068             boardp->id, (ulong) scp);
7069         return;
7070     }
7071
7072     /*
7073      * 'done_status' contains the command's ending status.
7074      */
7075     switch (scsiqp->done_status) {
7076     case QD_NO_ERROR:
7077         ASC_DBG(2, "adv_isr_callback: QD_NO_ERROR\n");
7078         scp->result = 0;
7079
7080         /*
7081          * Check for an underrun condition.
7082          *
7083          * If there was no error and an underrun condition, then
7084          * then return the number of underrun bytes.
7085          */
7086         resid_cnt = le32_to_cpu(scsiqp->data_cnt);
7087         if (scp->request_bufflen != 0 && resid_cnt != 0 &&
7088             resid_cnt <= scp->request_bufflen) {
7089             ASC_DBG1(1, "adv_isr_callback: underrun condition %lu bytes\n",
7090                 (ulong) resid_cnt);
7091             scp->resid = resid_cnt;
7092         }
7093         break;
7094
7095     case QD_WITH_ERROR:
7096         ASC_DBG(2, "adv_isr_callback: QD_WITH_ERROR\n");
7097         switch (scsiqp->host_status) {
7098         case QHSTA_NO_ERROR:
7099             if (scsiqp->scsi_status == SAM_STAT_CHECK_CONDITION) {
7100                 ASC_DBG(2, "adv_isr_callback: SAM_STAT_CHECK_CONDITION\n");
7101                 ASC_DBG_PRT_SENSE(2, scp->sense_buffer,
7102                     sizeof(scp->sense_buffer));
7103                 /*
7104                  * Note: The 'status_byte()' macro used by target drivers
7105                  * defined in scsi.h shifts the status byte returned by
7106                  * host drivers right by 1 bit. This is why target drivers
7107                  * also use right shifted status byte definitions. For
7108                  * instance target drivers use CHECK_CONDITION, defined to
7109                  * 0x1, instead of the SCSI defined check condition value
7110                  * of 0x2. Host drivers are supposed to return the status
7111                  * byte as it is defined by SCSI.
7112                  */
7113                 scp->result = DRIVER_BYTE(DRIVER_SENSE) |
7114                     STATUS_BYTE(scsiqp->scsi_status);
7115             } else {
7116                 scp->result = STATUS_BYTE(scsiqp->scsi_status);
7117             }
7118             break;
7119
7120         default:
7121             /* Some other QHSTA error occurred. */
7122             ASC_DBG1(1, "adv_isr_callback: host_status 0x%x\n",
7123                 scsiqp->host_status);
7124             scp->result = HOST_BYTE(DID_BAD_TARGET);
7125             break;
7126         }
7127         break;
7128
7129     case QD_ABORTED_BY_HOST:
7130         ASC_DBG(1, "adv_isr_callback: QD_ABORTED_BY_HOST\n");
7131         scp->result = HOST_BYTE(DID_ABORT) | STATUS_BYTE(scsiqp->scsi_status);
7132         break;
7133
7134     default:
7135         ASC_DBG1(1, "adv_isr_callback: done_status 0x%x\n", scsiqp->done_status);
7136         scp->result = HOST_BYTE(DID_ERROR) | STATUS_BYTE(scsiqp->scsi_status);
7137         break;
7138     }
7139
7140     /*
7141      * If the 'init_tidmask' bit isn't already set for the target and the
7142      * current request finished normally, then set the bit for the target
7143      * to indicate that a device is present.
7144      */
7145     if ((boardp->init_tidmask & ADV_TID_TO_TIDMASK(scp->device->id)) == 0 &&
7146         scsiqp->done_status == QD_NO_ERROR &&
7147         scsiqp->host_status == QHSTA_NO_ERROR) {
7148         boardp->init_tidmask |= ADV_TID_TO_TIDMASK(scp->device->id);
7149     }
7150
7151     /*
7152      * Because interrupts may be enabled by the 'struct scsi_cmnd' done
7153      * function, add the command to the end of the board's done queue.
7154      * The done function for the command will be called from
7155      * advansys_interrupt().
7156      */
7157     asc_enqueue(&boardp->done, scp, ASC_BACK);
7158
7159     /*
7160      * Free all 'adv_sgblk_t' structures allocated for the request.
7161      */
7162     while ((sgblkp = reqp->sgblkp) != NULL)
7163     {
7164         /* Remove 'sgblkp' from the request list. */
7165         reqp->sgblkp = sgblkp->next_sgblkp;
7166
7167         /* Add 'sgblkp' to the board free list. */
7168         sgblkp->next_sgblkp = boardp->adv_sgblkp;
7169         boardp->adv_sgblkp = sgblkp;
7170     }
7171
7172     /*
7173      * Free the adv_req_t structure used with the command by adding
7174      * it back to the board free list.
7175      */
7176     reqp->next_reqp = boardp->adv_reqp;
7177     boardp->adv_reqp = reqp;
7178
7179     ASC_DBG(1, "adv_isr_callback: done\n");
7180
7181     return;
7182 }
7183
7184 /*
7185  * adv_async_callback() - Adv Library asynchronous event callback function.
7186  */
7187 STATIC void
7188 adv_async_callback(ADV_DVC_VAR *adv_dvc_varp, uchar code)
7189 {
7190     switch (code)
7191     {
7192     case ADV_ASYNC_SCSI_BUS_RESET_DET:
7193         /*
7194          * The firmware detected a SCSI Bus reset.
7195          */
7196         ASC_DBG(0, "adv_async_callback: ADV_ASYNC_SCSI_BUS_RESET_DET\n");
7197         break;
7198
7199     case ADV_ASYNC_RDMA_FAILURE:
7200         /*
7201          * Handle RDMA failure by resetting the SCSI Bus and
7202          * possibly the chip if it is unresponsive. Log the error
7203          * with a unique code.
7204          */
7205         ASC_DBG(0, "adv_async_callback: ADV_ASYNC_RDMA_FAILURE\n");
7206         AdvResetChipAndSB(adv_dvc_varp);
7207         break;
7208
7209     case ADV_HOST_SCSI_BUS_RESET:
7210         /*
7211          * Host generated SCSI bus reset occurred.
7212          */
7213         ASC_DBG(0, "adv_async_callback: ADV_HOST_SCSI_BUS_RESET\n");
7214         break;
7215
7216     default:
7217         ASC_DBG1(0, "DvcAsyncCallBack: unknown code 0x%x\n", code);
7218         break;
7219     }
7220 }
7221
7222 /*
7223  * Add a 'REQP' to the end of specified queue. Set 'tidmask'
7224  * to indicate a command is queued for the device.
7225  *
7226  * 'flag' may be either ASC_FRONT or ASC_BACK.
7227  *
7228  * 'REQPNEXT(reqp)' returns reqp's next pointer.
7229  */
7230 STATIC void
7231 asc_enqueue(asc_queue_t *ascq, REQP reqp, int flag)
7232 {
7233     int        tid;
7234
7235     ASC_DBG3(3, "asc_enqueue: ascq 0x%lx, reqp 0x%lx, flag %d\n",
7236         (ulong) ascq, (ulong) reqp, flag);
7237     ASC_ASSERT(reqp != NULL);
7238     ASC_ASSERT(flag == ASC_FRONT || flag == ASC_BACK);
7239     tid = REQPTID(reqp);
7240     ASC_ASSERT(tid >= 0 && tid <= ADV_MAX_TID);
7241     if (flag == ASC_FRONT) {
7242         reqp->host_scribble = (unsigned char *)ascq->q_first[tid];
7243         ascq->q_first[tid] = reqp;
7244         /* If the queue was empty, set the last pointer. */
7245         if (ascq->q_last[tid] == NULL) {
7246             ascq->q_last[tid] = reqp;
7247         }
7248     } else { /* ASC_BACK */
7249         if (ascq->q_last[tid] != NULL) {
7250             ascq->q_last[tid]->host_scribble = (unsigned char *)reqp;
7251         }
7252         ascq->q_last[tid] = reqp;
7253         reqp->host_scribble = NULL;
7254         /* If the queue was empty, set the first pointer. */
7255         if (ascq->q_first[tid] == NULL) {
7256             ascq->q_first[tid] = reqp;
7257         }
7258     }
7259     /* The queue has at least one entry, set its bit. */
7260     ascq->q_tidmask |= ADV_TID_TO_TIDMASK(tid);
7261 #ifdef ADVANSYS_STATS
7262     /* Maintain request queue statistics. */
7263     ascq->q_tot_cnt[tid]++;
7264     ascq->q_cur_cnt[tid]++;
7265     if (ascq->q_cur_cnt[tid] > ascq->q_max_cnt[tid]) {
7266         ascq->q_max_cnt[tid] = ascq->q_cur_cnt[tid];
7267         ASC_DBG2(2, "asc_enqueue: new q_max_cnt[%d] %d\n",
7268             tid, ascq->q_max_cnt[tid]);
7269     }
7270     REQPTIME(reqp) = REQTIMESTAMP();
7271 #endif /* ADVANSYS_STATS */
7272     ASC_DBG1(3, "asc_enqueue: reqp 0x%lx\n", (ulong) reqp);
7273     return;
7274 }
7275
7276 /*
7277  * Return first queued 'REQP' on the specified queue for
7278  * the specified target device. Clear the 'tidmask' bit for
7279  * the device if no more commands are left queued for it.
7280  *
7281  * 'REQPNEXT(reqp)' returns reqp's next pointer.
7282  */
7283 STATIC REQP
7284 asc_dequeue(asc_queue_t *ascq, int tid)
7285 {
7286     REQP    reqp;
7287
7288     ASC_DBG2(3, "asc_dequeue: ascq 0x%lx, tid %d\n", (ulong) ascq, tid);
7289     ASC_ASSERT(tid >= 0 && tid <= ADV_MAX_TID);
7290     if ((reqp = ascq->q_first[tid]) != NULL) {
7291         ASC_ASSERT(ascq->q_tidmask & ADV_TID_TO_TIDMASK(tid));
7292         ascq->q_first[tid] = REQPNEXT(reqp);
7293         /* If the queue is empty, clear its bit and the last pointer. */
7294         if (ascq->q_first[tid] == NULL) {
7295             ascq->q_tidmask &= ~ADV_TID_TO_TIDMASK(tid);
7296             ASC_ASSERT(ascq->q_last[tid] == reqp);
7297             ascq->q_last[tid] = NULL;
7298         }
7299 #ifdef ADVANSYS_STATS
7300         /* Maintain request queue statistics. */
7301         ascq->q_cur_cnt[tid]--;
7302         ASC_ASSERT(ascq->q_cur_cnt[tid] >= 0);
7303         REQTIMESTAT("asc_dequeue", ascq, reqp, tid);
7304 #endif /* ADVANSYS_STATS */
7305     }
7306     ASC_DBG1(3, "asc_dequeue: reqp 0x%lx\n", (ulong) reqp);
7307     return reqp;
7308 }
7309
7310 /*
7311  * Return a pointer to a singly linked list of all the requests queued
7312  * for 'tid' on the 'asc_queue_t' pointed to by 'ascq'.
7313  *
7314  * If 'lastpp' is not NULL, '*lastpp' will be set to point to the
7315  * the last request returned in the singly linked list.
7316  *
7317  * 'tid' should either be a valid target id or if it is ASC_TID_ALL,
7318  * then all queued requests are concatenated into one list and
7319  * returned.
7320  *
7321  * Note: If 'lastpp' is used to append a new list to the end of
7322  * an old list, only change the old list last pointer if '*lastpp'
7323  * (or the function return value) is not NULL, i.e. use a temporary
7324  * variable for 'lastpp' and check its value after the function return
7325  * before assigning it to the list last pointer.
7326  *
7327  * Unfortunately collecting queuing time statistics adds overhead to
7328  * the function that isn't inherent to the function's algorithm.
7329  */
7330 STATIC REQP
7331 asc_dequeue_list(asc_queue_t *ascq, REQP *lastpp, int tid)
7332 {
7333     REQP    firstp, lastp;
7334     int     i;
7335
7336     ASC_DBG2(3, "asc_dequeue_list: ascq 0x%lx, tid %d\n", (ulong) ascq, tid);
7337     ASC_ASSERT((tid == ASC_TID_ALL) || (tid >= 0 && tid <= ADV_MAX_TID));
7338
7339     /*
7340      * If 'tid' is not ASC_TID_ALL, return requests only for
7341      * the specified 'tid'. If 'tid' is ASC_TID_ALL, return all
7342      * requests for all tids.
7343      */
7344     if (tid != ASC_TID_ALL) {
7345         /* Return all requests for the specified 'tid'. */
7346         if ((ascq->q_tidmask & ADV_TID_TO_TIDMASK(tid)) == 0) {
7347             /* List is empty; Set first and last return pointers to NULL. */
7348             firstp = lastp = NULL;
7349         } else {
7350             firstp = ascq->q_first[tid];
7351             lastp = ascq->q_last[tid];
7352             ascq->q_first[tid] = ascq->q_last[tid] = NULL;
7353             ascq->q_tidmask &= ~ADV_TID_TO_TIDMASK(tid);
7354 #ifdef ADVANSYS_STATS
7355             {
7356                 REQP reqp;
7357                 ascq->q_cur_cnt[tid] = 0;
7358                 for (reqp = firstp; reqp; reqp = REQPNEXT(reqp)) {
7359                     REQTIMESTAT("asc_dequeue_list", ascq, reqp, tid);
7360                 }
7361             }
7362 #endif /* ADVANSYS_STATS */
7363         }
7364     } else {
7365         /* Return all requests for all tids. */
7366         firstp = lastp = NULL;
7367         for (i = 0; i <= ADV_MAX_TID; i++) {
7368             if (ascq->q_tidmask & ADV_TID_TO_TIDMASK(i)) {
7369                 if (firstp == NULL) {
7370                     firstp = ascq->q_first[i];
7371                     lastp = ascq->q_last[i];
7372                 } else {
7373                     ASC_ASSERT(lastp != NULL);
7374                     lastp->host_scribble = (unsigned char *)ascq->q_first[i];
7375                     lastp = ascq->q_last[i];
7376                 }
7377                 ascq->q_first[i] = ascq->q_last[i] = NULL;
7378                 ascq->q_tidmask &= ~ADV_TID_TO_TIDMASK(i);
7379 #ifdef ADVANSYS_STATS
7380                 ascq->q_cur_cnt[i] = 0;
7381 #endif /* ADVANSYS_STATS */
7382             }
7383         }
7384 #ifdef ADVANSYS_STATS
7385         {
7386             REQP reqp;
7387             for (reqp = firstp; reqp; reqp = REQPNEXT(reqp)) {
7388                 REQTIMESTAT("asc_dequeue_list", ascq, reqp, reqp->device->id);
7389             }
7390         }
7391 #endif /* ADVANSYS_STATS */
7392     }
7393     if (lastpp) {
7394         *lastpp = lastp;
7395     }
7396     ASC_DBG1(3, "asc_dequeue_list: firstp 0x%lx\n", (ulong) firstp);
7397     return firstp;
7398 }
7399
7400 /*
7401  * Remove the specified 'REQP' from the specified queue for
7402  * the specified target device. Clear the 'tidmask' bit for the
7403  * device if no more commands are left queued for it.
7404  *
7405  * 'REQPNEXT(reqp)' returns reqp's the next pointer.
7406  *
7407  * Return ASC_TRUE if the command was found and removed,
7408  * otherwise return ASC_FALSE.
7409  */
7410 STATIC int
7411 asc_rmqueue(asc_queue_t *ascq, REQP reqp)
7412 {
7413     REQP        currp, prevp;
7414     int         tid;
7415     int         ret = ASC_FALSE;
7416
7417     ASC_DBG2(3, "asc_rmqueue: ascq 0x%lx, reqp 0x%lx\n",
7418         (ulong) ascq, (ulong) reqp);
7419     ASC_ASSERT(reqp != NULL);
7420
7421     tid = REQPTID(reqp);
7422     ASC_ASSERT(tid >= 0 && tid <= ADV_MAX_TID);
7423
7424     /*
7425      * Handle the common case of 'reqp' being the first
7426      * entry on the queue.
7427      */
7428     if (reqp == ascq->q_first[tid]) {
7429         ret = ASC_TRUE;
7430         ascq->q_first[tid] = REQPNEXT(reqp);
7431         /* If the queue is now empty, clear its bit and the last pointer. */
7432         if (ascq->q_first[tid] == NULL) {
7433             ascq->q_tidmask &= ~ADV_TID_TO_TIDMASK(tid);
7434             ASC_ASSERT(ascq->q_last[tid] == reqp);
7435             ascq->q_last[tid] = NULL;
7436         }
7437     } else if (ascq->q_first[tid] != NULL) {
7438         ASC_ASSERT(ascq->q_last[tid] != NULL);
7439         /*
7440          * Because the case of 'reqp' being the first entry has been
7441          * handled above and it is known the queue is not empty, if
7442          * 'reqp' is found on the queue it is guaranteed the queue will
7443          * not become empty and that 'q_first[tid]' will not be changed.
7444          *
7445          * Set 'prevp' to the first entry, 'currp' to the second entry,
7446          * and search for 'reqp'.
7447          */
7448         for (prevp = ascq->q_first[tid], currp = REQPNEXT(prevp);
7449              currp; prevp = currp, currp = REQPNEXT(currp)) {
7450             if (currp == reqp) {
7451                 ret = ASC_TRUE;
7452                 prevp->host_scribble = (unsigned char *)REQPNEXT(currp);
7453                 reqp->host_scribble = NULL;
7454                 if (ascq->q_last[tid] == reqp) {
7455                     ascq->q_last[tid] = prevp;
7456                 }
7457                 break;
7458             }
7459         }
7460     }
7461 #ifdef ADVANSYS_STATS
7462     /* Maintain request queue statistics. */
7463     if (ret == ASC_TRUE) {
7464         ascq->q_cur_cnt[tid]--;
7465         REQTIMESTAT("asc_rmqueue", ascq, reqp, tid);
7466     }
7467     ASC_ASSERT(ascq->q_cur_cnt[tid] >= 0);
7468 #endif /* ADVANSYS_STATS */
7469     ASC_DBG2(3, "asc_rmqueue: reqp 0x%lx, ret %d\n", (ulong) reqp, ret);
7470     return ret;
7471 }
7472
7473 /*
7474  * Execute as many queued requests as possible for the specified queue.
7475  *
7476  * Calls asc_execute_scsi_cmnd() to execute a REQP/struct scsi_cmnd.
7477  */
7478 STATIC void
7479 asc_execute_queue(asc_queue_t *ascq)
7480 {
7481     ADV_SCSI_BIT_ID_TYPE    scan_tidmask;
7482     REQP                    reqp;
7483     int                     i;
7484
7485     ASC_DBG1(1, "asc_execute_queue: ascq 0x%lx\n", (ulong) ascq);
7486     /*
7487      * Execute queued commands for devices attached to
7488      * the current board in round-robin fashion.
7489      */
7490     scan_tidmask = ascq->q_tidmask;
7491     do {
7492         for (i = 0; i <= ADV_MAX_TID; i++) {
7493             if (scan_tidmask & ADV_TID_TO_TIDMASK(i)) {
7494                 if ((reqp = asc_dequeue(ascq, i)) == NULL) {
7495                     scan_tidmask &= ~ADV_TID_TO_TIDMASK(i);
7496                 } else if (asc_execute_scsi_cmnd((struct scsi_cmnd *) reqp)
7497                             == ASC_BUSY) {
7498                     scan_tidmask &= ~ADV_TID_TO_TIDMASK(i);
7499                     /*
7500                      * The request returned ASC_BUSY. Enqueue at the front of
7501                      * target's waiting list to maintain correct ordering.
7502                      */
7503                     asc_enqueue(ascq, reqp, ASC_FRONT);
7504                 }
7505             }
7506         }
7507     } while (scan_tidmask);
7508     return;
7509 }
7510
7511 #ifdef CONFIG_PROC_FS
7512 /*
7513  * asc_prt_board_devices()
7514  *
7515  * Print driver information for devices attached to the board.
7516  *
7517  * Note: no single line should be greater than ASC_PRTLINE_SIZE,
7518  * cf. asc_prt_line().
7519  *
7520  * Return the number of characters copied into 'cp'. No more than
7521  * 'cplen' characters will be copied to 'cp'.
7522  */
7523 STATIC int
7524 asc_prt_board_devices(struct Scsi_Host *shp, char *cp, int cplen)
7525 {
7526     asc_board_t        *boardp;
7527     int                leftlen;
7528     int                totlen;
7529     int                len;
7530     int                chip_scsi_id;
7531     int                i;
7532
7533     boardp = ASC_BOARDP(shp);
7534     leftlen = cplen;
7535     totlen = len = 0;
7536
7537     len = asc_prt_line(cp, leftlen,
7538 "\nDevice Information for AdvanSys SCSI Host %d:\n", shp->host_no);
7539     ASC_PRT_NEXT();
7540
7541     if (ASC_NARROW_BOARD(boardp)) {
7542         chip_scsi_id = boardp->dvc_cfg.asc_dvc_cfg.chip_scsi_id;
7543     } else {
7544         chip_scsi_id = boardp->dvc_var.adv_dvc_var.chip_scsi_id;
7545     }
7546
7547     len = asc_prt_line(cp, leftlen, "Target IDs Detected:");
7548     ASC_PRT_NEXT();
7549     for (i = 0; i <= ADV_MAX_TID; i++) {
7550         if (boardp->init_tidmask & ADV_TID_TO_TIDMASK(i)) {
7551             len = asc_prt_line(cp, leftlen, " %X,", i);
7552             ASC_PRT_NEXT();
7553         }
7554     }
7555     len = asc_prt_line(cp, leftlen, " (%X=Host Adapter)\n", chip_scsi_id);
7556     ASC_PRT_NEXT();
7557
7558     return totlen;
7559 }
7560
7561 /*
7562  * Display Wide Board BIOS Information.
7563  */
7564 STATIC int
7565 asc_prt_adv_bios(struct Scsi_Host *shp, char *cp, int cplen)
7566 {
7567     asc_board_t        *boardp;
7568     int                leftlen;
7569     int                totlen;
7570     int                len;
7571     ushort             major, minor, letter;
7572
7573     boardp = ASC_BOARDP(shp);
7574     leftlen = cplen;
7575     totlen = len = 0;
7576
7577     len = asc_prt_line(cp, leftlen, "\nROM BIOS Version: ");
7578     ASC_PRT_NEXT();
7579
7580     /*
7581      * If the BIOS saved a valid signature, then fill in
7582      * the BIOS code segment base address.
7583      */
7584     if (boardp->bios_signature != 0x55AA) {
7585         len = asc_prt_line(cp, leftlen, "Disabled or Pre-3.1\n");
7586         ASC_PRT_NEXT();
7587         len = asc_prt_line(cp, leftlen,
7588 "BIOS either disabled or Pre-3.1. If it is pre-3.1, then a newer version\n");
7589         ASC_PRT_NEXT();
7590         len = asc_prt_line(cp, leftlen,
7591 "can be found at the ConnectCom FTP site: ftp://ftp.connectcom.net/pub\n");
7592         ASC_PRT_NEXT();
7593     } else {
7594         major = (boardp->bios_version >> 12) & 0xF;
7595         minor = (boardp->bios_version >> 8) & 0xF;
7596         letter = (boardp->bios_version & 0xFF);
7597
7598         len = asc_prt_line(cp, leftlen, "%d.%d%c\n",
7599             major, minor, letter >= 26 ? '?' : letter + 'A');
7600         ASC_PRT_NEXT();
7601
7602         /*
7603          * Current available ROM BIOS release is 3.1I for UW
7604          * and 3.2I for U2W. This code doesn't differentiate
7605          * UW and U2W boards.
7606          */
7607         if (major < 3 || (major <= 3 && minor < 1) ||
7608             (major <= 3 && minor <= 1 && letter < ('I'- 'A'))) {
7609             len = asc_prt_line(cp, leftlen,
7610 "Newer version of ROM BIOS is available at the ConnectCom FTP site:\n");
7611             ASC_PRT_NEXT();
7612             len = asc_prt_line(cp, leftlen,
7613 "ftp://ftp.connectcom.net/pub\n");
7614             ASC_PRT_NEXT();
7615         }
7616     }
7617
7618     return totlen;
7619 }
7620
7621 /*
7622  * Add serial number to information bar if signature AAh
7623  * is found in at bit 15-9 (7 bits) of word 1.
7624  *
7625  * Serial Number consists fo 12 alpha-numeric digits.
7626  *
7627  *       1 - Product type (A,B,C,D..)  Word0: 15-13 (3 bits)
7628  *       2 - MFG Location (A,B,C,D..)  Word0: 12-10 (3 bits)
7629  *     3-4 - Product ID (0-99)         Word0: 9-0 (10 bits)
7630  *       5 - Product revision (A-J)    Word0:  "         "
7631  *
7632  *           Signature                 Word1: 15-9 (7 bits)
7633  *       6 - Year (0-9)                Word1: 8-6 (3 bits) & Word2: 15 (1 bit)
7634  *     7-8 - Week of the year (1-52)   Word1: 5-0 (6 bits)
7635  *
7636  *    9-12 - Serial Number (A001-Z999) Word2: 14-0 (15 bits)
7637  *
7638  * Note 1: Only production cards will have a serial number.
7639  *
7640  * Note 2: Signature is most significant 7 bits (0xFE).
7641  *
7642  * Returns ASC_TRUE if serial number found, otherwise returns ASC_FALSE.
7643  */
7644 STATIC int
7645 asc_get_eeprom_string(ushort *serialnum, uchar *cp)
7646 {
7647     ushort      w, num;
7648
7649     if ((serialnum[1] & 0xFE00) != ((ushort) 0xAA << 8)) {
7650         return ASC_FALSE;
7651     } else {
7652         /*
7653          * First word - 6 digits.
7654          */
7655         w = serialnum[0];
7656
7657         /* Product type - 1st digit. */
7658         if ((*cp = 'A' + ((w & 0xE000) >> 13)) == 'H') {
7659             /* Product type is P=Prototype */
7660             *cp += 0x8;
7661         }
7662         cp++;
7663
7664         /* Manufacturing location - 2nd digit. */
7665         *cp++ = 'A' + ((w & 0x1C00) >> 10);
7666
7667         /* Product ID - 3rd, 4th digits. */
7668         num = w & 0x3FF;
7669         *cp++ = '0' + (num / 100);
7670         num %= 100;
7671         *cp++ = '0' + (num / 10);
7672
7673         /* Product revision - 5th digit. */
7674         *cp++ = 'A' + (num % 10);
7675
7676         /*
7677          * Second word
7678          */
7679         w = serialnum[1];
7680
7681         /*
7682          * Year - 6th digit.
7683          *
7684          * If bit 15 of third word is set, then the
7685          * last digit of the year is greater than 7.
7686          */
7687         if (serialnum[2] & 0x8000) {
7688             *cp++ = '8' + ((w & 0x1C0) >> 6);
7689         } else {
7690             *cp++ = '0' + ((w & 0x1C0) >> 6);
7691         }
7692
7693         /* Week of year - 7th, 8th digits. */
7694         num = w & 0x003F;
7695         *cp++ = '0' + num / 10;
7696         num %= 10;
7697         *cp++ = '0' + num;
7698
7699         /*
7700          * Third word
7701          */
7702         w = serialnum[2] & 0x7FFF;
7703
7704         /* Serial number - 9th digit. */
7705         *cp++ = 'A' + (w / 1000);
7706
7707         /* 10th, 11th, 12th digits. */
7708         num = w % 1000;
7709         *cp++ = '0' + num / 100;
7710         num %= 100;
7711         *cp++ = '0' + num / 10;
7712         num %= 10;
7713         *cp++ = '0' + num;
7714
7715         *cp = '\0';     /* Null Terminate the string. */
7716         return ASC_TRUE;
7717     }
7718 }
7719
7720 /*
7721  * asc_prt_asc_board_eeprom()
7722  *
7723  * Print board EEPROM configuration.
7724  *
7725  * Note: no single line should be greater than ASC_PRTLINE_SIZE,
7726  * cf. asc_prt_line().
7727  *
7728  * Return the number of characters copied into 'cp'. No more than
7729  * 'cplen' characters will be copied to 'cp'.
7730  */
7731 STATIC int
7732 asc_prt_asc_board_eeprom(struct Scsi_Host *shp, char *cp, int cplen)
7733 {
7734     asc_board_t        *boardp;
7735     ASC_DVC_VAR        *asc_dvc_varp;
7736     int                leftlen;
7737     int                totlen;
7738     int                len;
7739     ASCEEP_CONFIG      *ep;
7740     int                i;
7741 #ifdef CONFIG_ISA
7742     int                isa_dma_speed[] = { 10, 8, 7, 6, 5, 4, 3, 2 };
7743 #endif /* CONFIG_ISA */
7744     uchar              serialstr[13];
7745
7746     boardp = ASC_BOARDP(shp);
7747     asc_dvc_varp = &boardp->dvc_var.asc_dvc_var;
7748     ep = &boardp->eep_config.asc_eep;
7749
7750     leftlen = cplen;
7751     totlen = len = 0;
7752
7753     len = asc_prt_line(cp, leftlen,
7754 "\nEEPROM Settings for AdvanSys SCSI Host %d:\n", shp->host_no);
7755     ASC_PRT_NEXT();
7756
7757     if (asc_get_eeprom_string((ushort *) &ep->adapter_info[0], serialstr) ==
7758         ASC_TRUE) {
7759         len = asc_prt_line(cp, leftlen, " Serial Number: %s\n", serialstr);
7760         ASC_PRT_NEXT();
7761     } else {
7762         if (ep->adapter_info[5] == 0xBB) {
7763             len = asc_prt_line(cp, leftlen,
7764                 " Default Settings Used for EEPROM-less Adapter.\n");
7765             ASC_PRT_NEXT();
7766         } else {
7767             len = asc_prt_line(cp, leftlen,
7768                 " Serial Number Signature Not Present.\n");
7769             ASC_PRT_NEXT();
7770         }
7771     }
7772
7773     len = asc_prt_line(cp, leftlen,
7774 " Host SCSI ID: %u, Host Queue Size: %u, Device Queue Size: %u\n",
7775         ASC_EEP_GET_CHIP_ID(ep), ep->max_total_qng, ep->max_tag_qng);
7776     ASC_PRT_NEXT();
7777
7778     len = asc_prt_line(cp, leftlen,
7779 " cntl 0x%x, no_scam 0x%x\n",
7780         ep->cntl, ep->no_scam);
7781     ASC_PRT_NEXT();
7782
7783     len = asc_prt_line(cp, leftlen,
7784 " Target ID:           ");
7785     ASC_PRT_NEXT();
7786     for (i = 0; i <= ASC_MAX_TID; i++) {
7787         len = asc_prt_line(cp, leftlen, " %d", i);
7788         ASC_PRT_NEXT();
7789     }
7790     len = asc_prt_line(cp, leftlen, "\n");
7791     ASC_PRT_NEXT();
7792
7793     len = asc_prt_line(cp, leftlen,
7794 " Disconnects:         ");
7795     ASC_PRT_NEXT();
7796     for (i = 0; i <= ASC_MAX_TID; i++) {
7797         len = asc_prt_line(cp, leftlen, " %c",
7798             (ep->disc_enable & ADV_TID_TO_TIDMASK(i)) ? 'Y' : 'N');
7799         ASC_PRT_NEXT();
7800     }
7801     len = asc_prt_line(cp, leftlen, "\n");
7802     ASC_PRT_NEXT();
7803
7804     len = asc_prt_line(cp, leftlen,
7805 " Command Queuing:     ");
7806     ASC_PRT_NEXT();
7807     for (i = 0; i <= ASC_MAX_TID; i++) {
7808         len = asc_prt_line(cp, leftlen, " %c",
7809             (ep->use_cmd_qng & ADV_TID_TO_TIDMASK(i)) ? 'Y' : 'N');
7810         ASC_PRT_NEXT();
7811     }
7812     len = asc_prt_line(cp, leftlen, "\n");
7813     ASC_PRT_NEXT();
7814
7815     len = asc_prt_line(cp, leftlen,
7816 " Start Motor:         ");
7817     ASC_PRT_NEXT();
7818     for (i = 0; i <= ASC_MAX_TID; i++) {
7819         len = asc_prt_line(cp, leftlen, " %c",
7820             (ep->start_motor & ADV_TID_TO_TIDMASK(i)) ? 'Y' : 'N');
7821         ASC_PRT_NEXT();
7822     }
7823     len = asc_prt_line(cp, leftlen, "\n");
7824     ASC_PRT_NEXT();
7825
7826     len = asc_prt_line(cp, leftlen,
7827 " Synchronous Transfer:");
7828     ASC_PRT_NEXT();
7829     for (i = 0; i <= ASC_MAX_TID; i++) {
7830         len = asc_prt_line(cp, leftlen, " %c",
7831             (ep->init_sdtr & ADV_TID_TO_TIDMASK(i)) ? 'Y' : 'N');
7832         ASC_PRT_NEXT();
7833     }
7834     len = asc_prt_line(cp, leftlen, "\n");
7835     ASC_PRT_NEXT();
7836
7837 #ifdef CONFIG_ISA
7838     if (asc_dvc_varp->bus_type & ASC_IS_ISA) {
7839         len = asc_prt_line(cp, leftlen,
7840 " Host ISA DMA speed:   %d MB/S\n",
7841             isa_dma_speed[ASC_EEP_GET_DMA_SPD(ep)]);
7842         ASC_PRT_NEXT();
7843     }
7844 #endif /* CONFIG_ISA */
7845
7846      return totlen;
7847 }
7848
7849 /*
7850  * asc_prt_adv_board_eeprom()
7851  *
7852  * Print board EEPROM configuration.
7853  *
7854  * Note: no single line should be greater than ASC_PRTLINE_SIZE,
7855  * cf. asc_prt_line().
7856  *
7857  * Return the number of characters copied into 'cp'. No more than
7858  * 'cplen' characters will be copied to 'cp'.
7859  */
7860 STATIC int
7861 asc_prt_adv_board_eeprom(struct Scsi_Host *shp, char *cp, int cplen)
7862 {
7863     asc_board_t                 *boardp;
7864     ADV_DVC_VAR                 *adv_dvc_varp;
7865     int                         leftlen;
7866     int                         totlen;
7867     int                         len;
7868     int                         i;
7869     char                        *termstr;
7870     uchar                       serialstr[13];
7871     ADVEEP_3550_CONFIG          *ep_3550 = NULL;
7872     ADVEEP_38C0800_CONFIG       *ep_38C0800 = NULL;
7873     ADVEEP_38C1600_CONFIG       *ep_38C1600 = NULL;
7874     ushort                      word;
7875     ushort                      *wordp;
7876     ushort                      sdtr_speed = 0;
7877
7878     boardp = ASC_BOARDP(shp);
7879     adv_dvc_varp = &boardp->dvc_var.adv_dvc_var;
7880     if (adv_dvc_varp->chip_type == ADV_CHIP_ASC3550)
7881     {
7882         ep_3550 = &boardp->eep_config.adv_3550_eep;
7883     } else if (adv_dvc_varp->chip_type == ADV_CHIP_ASC38C0800)
7884     {
7885         ep_38C0800 = &boardp->eep_config.adv_38C0800_eep;
7886     } else
7887     {
7888         ep_38C1600 = &boardp->eep_config.adv_38C1600_eep;
7889     }
7890
7891     leftlen = cplen;
7892     totlen = len = 0;
7893
7894     len = asc_prt_line(cp, leftlen,
7895 "\nEEPROM Settings for AdvanSys SCSI Host %d:\n", shp->host_no);
7896     ASC_PRT_NEXT();
7897
7898     if (adv_dvc_varp->chip_type == ADV_CHIP_ASC3550)
7899     {
7900         wordp = &ep_3550->serial_number_word1;
7901     } else if (adv_dvc_varp->chip_type == ADV_CHIP_ASC38C0800)
7902     {
7903         wordp = &ep_38C0800->serial_number_word1;
7904     } else
7905     {
7906         wordp = &ep_38C1600->serial_number_word1;
7907     }
7908
7909     if (asc_get_eeprom_string(wordp, serialstr) == ASC_TRUE) {
7910         len = asc_prt_line(cp, leftlen, " Serial Number: %s\n", serialstr);
7911         ASC_PRT_NEXT();
7912     } else {
7913         len = asc_prt_line(cp, leftlen,
7914             " Serial Number Signature Not Present.\n");
7915         ASC_PRT_NEXT();
7916     }
7917
7918     if (adv_dvc_varp->chip_type == ADV_CHIP_ASC3550)
7919     {
7920         len = asc_prt_line(cp, leftlen,
7921 " Host SCSI ID: %u, Host Queue Size: %u, Device Queue Size: %u\n",
7922             ep_3550->adapter_scsi_id, ep_3550->max_host_qng,
7923             ep_3550->max_dvc_qng);
7924         ASC_PRT_NEXT();
7925     } else if (adv_dvc_varp->chip_type == ADV_CHIP_ASC38C0800)
7926     {
7927         len = asc_prt_line(cp, leftlen,
7928 " Host SCSI ID: %u, Host Queue Size: %u, Device Queue Size: %u\n",
7929             ep_38C0800->adapter_scsi_id, ep_38C0800->max_host_qng,
7930             ep_38C0800->max_dvc_qng);
7931         ASC_PRT_NEXT();
7932     } else
7933     {
7934         len = asc_prt_line(cp, leftlen,
7935 " Host SCSI ID: %u, Host Queue Size: %u, Device Queue Size: %u\n",
7936             ep_38C1600->adapter_scsi_id, ep_38C1600->max_host_qng,
7937             ep_38C1600->max_dvc_qng);
7938         ASC_PRT_NEXT();
7939     }
7940     if (adv_dvc_varp->chip_type == ADV_CHIP_ASC3550)
7941     {
7942         word = ep_3550->termination;
7943     } else if (adv_dvc_varp->chip_type == ADV_CHIP_ASC38C0800)
7944     {
7945         word = ep_38C0800->termination_lvd;
7946     } else
7947     {
7948         word = ep_38C1600->termination_lvd;
7949     }
7950     switch (word) {
7951         case 1:
7952             termstr = "Low Off/High Off";
7953             break;
7954         case 2:
7955             termstr = "Low Off/High On";
7956             break;
7957         case 3:
7958             termstr = "Low On/High On";
7959             break;
7960         default:
7961         case 0:
7962             termstr = "Automatic";
7963             break;
7964     }
7965
7966     if (adv_dvc_varp->chip_type == ADV_CHIP_ASC3550)
7967     {
7968         len = asc_prt_line(cp, leftlen,
7969 " termination: %u (%s), bios_ctrl: 0x%x\n",
7970             ep_3550->termination, termstr, ep_3550->bios_ctrl);
7971         ASC_PRT_NEXT();
7972     } else if (adv_dvc_varp->chip_type == ADV_CHIP_ASC38C0800)
7973     {
7974         len = asc_prt_line(cp, leftlen,
7975 " termination: %u (%s), bios_ctrl: 0x%x\n",
7976             ep_38C0800->termination_lvd, termstr, ep_38C0800->bios_ctrl);
7977         ASC_PRT_NEXT();
7978     } else
7979     {
7980         len = asc_prt_line(cp, leftlen,
7981 " termination: %u (%s), bios_ctrl: 0x%x\n",
7982             ep_38C1600->termination_lvd, termstr, ep_38C1600->bios_ctrl);
7983         ASC_PRT_NEXT();
7984     }
7985
7986     len = asc_prt_line(cp, leftlen,
7987 " Target ID:           ");
7988     ASC_PRT_NEXT();
7989     for (i = 0; i <= ADV_MAX_TID; i++) {
7990         len = asc_prt_line(cp, leftlen, " %X", i);
7991         ASC_PRT_NEXT();
7992     }
7993     len = asc_prt_line(cp, leftlen, "\n");
7994     ASC_PRT_NEXT();
7995
7996     if (adv_dvc_varp->chip_type == ADV_CHIP_ASC3550)
7997     {
7998         word = ep_3550->disc_enable;
7999     } else if (adv_dvc_varp->chip_type == ADV_CHIP_ASC38C0800)
8000     {
8001         word = ep_38C0800->disc_enable;
8002     } else
8003     {
8004         word = ep_38C1600->disc_enable;
8005     }
8006     len = asc_prt_line(cp, leftlen,
8007 " Disconnects:         ");
8008     ASC_PRT_NEXT();
8009     for (i = 0; i <= ADV_MAX_TID; i++) {
8010         len = asc_prt_line(cp, leftlen, " %c",
8011             (word & ADV_TID_TO_TIDMASK(i)) ? 'Y' : 'N');
8012         ASC_PRT_NEXT();
8013     }
8014     len = asc_prt_line(cp, leftlen, "\n");
8015     ASC_PRT_NEXT();
8016
8017     if (adv_dvc_varp->chip_type == ADV_CHIP_ASC3550)
8018     {
8019         word = ep_3550->tagqng_able;
8020     } else if (adv_dvc_varp->chip_type == ADV_CHIP_ASC38C0800)
8021     {
8022         word = ep_38C0800->tagqng_able;
8023     } else
8024     {
8025         word = ep_38C1600->tagqng_able;
8026     }
8027     len = asc_prt_line(cp, leftlen,
8028 " Command Queuing:     ");
8029     ASC_PRT_NEXT();
8030     for (i = 0; i <= ADV_MAX_TID; i++) {
8031         len = asc_prt_line(cp, leftlen, " %c",
8032             (word & ADV_TID_TO_TIDMASK(i)) ? 'Y' : 'N');
8033         ASC_PRT_NEXT();
8034     }
8035     len = asc_prt_line(cp, leftlen, "\n");
8036     ASC_PRT_NEXT();
8037
8038     if (adv_dvc_varp->chip_type == ADV_CHIP_ASC3550)
8039     {
8040         word = ep_3550->start_motor;
8041     } else if (adv_dvc_varp->chip_type == ADV_CHIP_ASC38C0800)
8042     {
8043         word = ep_38C0800->start_motor;
8044     } else
8045     {
8046         word = ep_38C1600->start_motor;
8047     }
8048     len = asc_prt_line(cp, leftlen,
8049 " Start Motor:         ");
8050     ASC_PRT_NEXT();
8051     for (i = 0; i <= ADV_MAX_TID; i++) {
8052         len = asc_prt_line(cp, leftlen, " %c",
8053             (word & ADV_TID_TO_TIDMASK(i)) ? 'Y' : 'N');
8054         ASC_PRT_NEXT();
8055     }
8056     len = asc_prt_line(cp, leftlen, "\n");
8057     ASC_PRT_NEXT();
8058
8059     if (adv_dvc_varp->chip_type == ADV_CHIP_ASC3550)
8060     {
8061         len = asc_prt_line(cp, leftlen,
8062 " Synchronous Transfer:");
8063         ASC_PRT_NEXT();
8064         for (i = 0; i <= ADV_MAX_TID; i++) {
8065             len = asc_prt_line(cp, leftlen, " %c",
8066                 (ep_3550->sdtr_able & ADV_TID_TO_TIDMASK(i)) ? 'Y' : 'N');
8067             ASC_PRT_NEXT();
8068         }
8069         len = asc_prt_line(cp, leftlen, "\n");
8070         ASC_PRT_NEXT();
8071     }
8072
8073     if (adv_dvc_varp->chip_type == ADV_CHIP_ASC3550)
8074     {
8075         len = asc_prt_line(cp, leftlen,
8076 " Ultra Transfer:      ");
8077     ASC_PRT_NEXT();
8078         for (i = 0; i <= ADV_MAX_TID; i++) {
8079             len = asc_prt_line(cp, leftlen, " %c",
8080                 (ep_3550->ultra_able & ADV_TID_TO_TIDMASK(i)) ? 'Y' : 'N');
8081             ASC_PRT_NEXT();
8082         }
8083         len = asc_prt_line(cp, leftlen, "\n");
8084         ASC_PRT_NEXT();
8085     }
8086
8087     if (adv_dvc_varp->chip_type == ADV_CHIP_ASC3550)
8088     {
8089         word = ep_3550->wdtr_able;
8090     } else if (adv_dvc_varp->chip_type == ADV_CHIP_ASC38C0800)
8091     {
8092         word = ep_38C0800->wdtr_able;
8093     } else
8094     {
8095         word = ep_38C1600->wdtr_able;
8096     }
8097     len = asc_prt_line(cp, leftlen,
8098 " Wide Transfer:       ");
8099     ASC_PRT_NEXT();
8100     for (i = 0; i <= ADV_MAX_TID; i++) {
8101         len = asc_prt_line(cp, leftlen, " %c",
8102             (word & ADV_TID_TO_TIDMASK(i)) ? 'Y' : 'N');
8103         ASC_PRT_NEXT();
8104     }
8105     len = asc_prt_line(cp, leftlen, "\n");
8106     ASC_PRT_NEXT();
8107
8108     if (adv_dvc_varp->chip_type == ADV_CHIP_ASC38C0800 ||
8109         adv_dvc_varp->chip_type == ADV_CHIP_ASC38C1600)
8110     {
8111         len = asc_prt_line(cp, leftlen,
8112 " Synchronous Transfer Speed (Mhz):\n  ");
8113         ASC_PRT_NEXT();
8114         for (i = 0; i <= ADV_MAX_TID; i++) {
8115             char *speed_str;
8116
8117             if (i == 0)
8118             {
8119                 sdtr_speed = adv_dvc_varp->sdtr_speed1;
8120             } else if (i == 4)
8121             {
8122                 sdtr_speed = adv_dvc_varp->sdtr_speed2;
8123             } else if (i == 8)
8124             {
8125                 sdtr_speed = adv_dvc_varp->sdtr_speed3;
8126             } else if (i == 12)
8127             {
8128                 sdtr_speed = adv_dvc_varp->sdtr_speed4;
8129             }
8130             switch (sdtr_speed & ADV_MAX_TID)
8131             {
8132                 case 0:  speed_str = "Off"; break;
8133                 case 1:  speed_str = "  5"; break;
8134                 case 2:  speed_str = " 10"; break;
8135                 case 3:  speed_str = " 20"; break;
8136                 case 4:  speed_str = " 40"; break;
8137                 case 5:  speed_str = " 80"; break;
8138                 default: speed_str = "Unk"; break;
8139             }
8140             len = asc_prt_line(cp, leftlen, "%X:%s ", i, speed_str);
8141             ASC_PRT_NEXT();
8142             if (i == 7)
8143             {
8144                 len = asc_prt_line(cp, leftlen, "\n  ");
8145                 ASC_PRT_NEXT();
8146             }
8147             sdtr_speed >>= 4;
8148         }
8149         len = asc_prt_line(cp, leftlen, "\n");
8150         ASC_PRT_NEXT();
8151     }
8152
8153     return totlen;
8154 }
8155
8156 /*
8157  * asc_prt_driver_conf()
8158  *
8159  * Note: no single line should be greater than ASC_PRTLINE_SIZE,
8160  * cf. asc_prt_line().
8161  *
8162  * Return the number of characters copied into 'cp'. No more than
8163  * 'cplen' characters will be copied to 'cp'.
8164  */
8165 STATIC int
8166 asc_prt_driver_conf(struct Scsi_Host *shp, char *cp, int cplen)
8167 {
8168     asc_board_t            *boardp;
8169     int                    leftlen;
8170     int                    totlen;
8171     int                    len;
8172     int                    chip_scsi_id;
8173
8174     boardp = ASC_BOARDP(shp);
8175
8176     leftlen = cplen;
8177     totlen = len = 0;
8178
8179     len = asc_prt_line(cp, leftlen,
8180 "\nLinux Driver Configuration and Information for AdvanSys SCSI Host %d:\n",
8181         shp->host_no);
8182     ASC_PRT_NEXT();
8183
8184     len = asc_prt_line(cp, leftlen,
8185 " host_busy %u, last_reset %u, max_id %u, max_lun %u, max_channel %u\n",
8186         shp->host_busy, shp->last_reset, shp->max_id, shp->max_lun,
8187         shp->max_channel);
8188     ASC_PRT_NEXT();
8189
8190     len = asc_prt_line(cp, leftlen,
8191 " unique_id %d, can_queue %d, this_id %d, sg_tablesize %u, cmd_per_lun %u\n",
8192         shp->unique_id, shp->can_queue, shp->this_id, shp->sg_tablesize,
8193         shp->cmd_per_lun);
8194     ASC_PRT_NEXT();
8195
8196     len = asc_prt_line(cp, leftlen,
8197 " unchecked_isa_dma %d, use_clustering %d\n",
8198         shp->unchecked_isa_dma, shp->use_clustering);
8199     ASC_PRT_NEXT();
8200
8201     len = asc_prt_line(cp, leftlen,
8202 " flags 0x%x, last_reset 0x%x, jiffies 0x%x, asc_n_io_port 0x%x\n",
8203         boardp->flags, boardp->last_reset, jiffies, boardp->asc_n_io_port);
8204     ASC_PRT_NEXT();
8205
8206      /* 'shp->n_io_port' may be truncated because it is only one byte. */
8207     len = asc_prt_line(cp, leftlen,
8208 " io_port 0x%x, n_io_port 0x%x\n",
8209         shp->io_port, shp->n_io_port);
8210     ASC_PRT_NEXT();
8211
8212     if (ASC_NARROW_BOARD(boardp)) {
8213         chip_scsi_id = boardp->dvc_cfg.asc_dvc_cfg.chip_scsi_id;
8214     } else {
8215         chip_scsi_id = boardp->dvc_var.adv_dvc_var.chip_scsi_id;
8216     }
8217
8218     return totlen;
8219 }
8220
8221 /*
8222  * asc_prt_asc_board_info()
8223  *
8224  * Print dynamic board configuration information.
8225  *
8226  * Note: no single line should be greater than ASC_PRTLINE_SIZE,
8227  * cf. asc_prt_line().
8228  *
8229  * Return the number of characters copied into 'cp'. No more than
8230  * 'cplen' characters will be copied to 'cp'.
8231  */
8232 STATIC int
8233 asc_prt_asc_board_info(struct Scsi_Host *shp, char *cp, int cplen)
8234 {
8235     asc_board_t            *boardp;
8236     int                    chip_scsi_id;
8237     int                    leftlen;
8238     int                    totlen;
8239     int                    len;
8240     ASC_DVC_VAR            *v;
8241     ASC_DVC_CFG            *c;
8242     int                    i;
8243     int                    renegotiate = 0;
8244
8245     boardp = ASC_BOARDP(shp);
8246     v = &boardp->dvc_var.asc_dvc_var;
8247     c = &boardp->dvc_cfg.asc_dvc_cfg;
8248     chip_scsi_id = c->chip_scsi_id;
8249
8250     leftlen = cplen;
8251     totlen = len = 0;
8252
8253     len = asc_prt_line(cp, leftlen,
8254 "\nAsc Library Configuration and Statistics for AdvanSys SCSI Host %d:\n",
8255     shp->host_no);
8256     ASC_PRT_NEXT();
8257
8258     len = asc_prt_line(cp, leftlen,
8259 " chip_version %u, lib_version 0x%x, lib_serial_no %u, mcode_date 0x%x\n",
8260         c->chip_version, c->lib_version, c->lib_serial_no, c->mcode_date);
8261     ASC_PRT_NEXT();
8262
8263     len = asc_prt_line(cp, leftlen,
8264 " mcode_version 0x%x, err_code %u\n",
8265          c->mcode_version, v->err_code);
8266     ASC_PRT_NEXT();
8267
8268     /* Current number of commands waiting for the host. */
8269     len = asc_prt_line(cp, leftlen,
8270 " Total Command Pending: %d\n", v->cur_total_qng);
8271     ASC_PRT_NEXT();
8272
8273     len = asc_prt_line(cp, leftlen,
8274 " Command Queuing:");
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:%c",
8282             i, (v->use_tagged_qng & ADV_TID_TO_TIDMASK(i)) ? 'Y' : 'N');
8283         ASC_PRT_NEXT();
8284     }
8285     len = asc_prt_line(cp, leftlen, "\n");
8286     ASC_PRT_NEXT();
8287
8288     /* Current number of commands waiting for a device. */
8289     len = asc_prt_line(cp, leftlen,
8290 " Command Queue Pending:");
8291     ASC_PRT_NEXT();
8292     for (i = 0; i <= ASC_MAX_TID; i++) {
8293         if ((chip_scsi_id == i) ||
8294             ((boardp->init_tidmask & ADV_TID_TO_TIDMASK(i)) == 0)) {
8295             continue;
8296         }
8297         len = asc_prt_line(cp, leftlen, " %X:%u", i, v->cur_dvc_qng[i]);
8298         ASC_PRT_NEXT();
8299     }
8300     len = asc_prt_line(cp, leftlen, "\n");
8301     ASC_PRT_NEXT();
8302
8303     /* Current limit on number of commands that can be sent to a device. */
8304     len = asc_prt_line(cp, leftlen,
8305 " Command Queue Limit:");
8306     ASC_PRT_NEXT();
8307     for (i = 0; i <= ASC_MAX_TID; i++) {
8308         if ((chip_scsi_id == i) ||
8309             ((boardp->init_tidmask & ADV_TID_TO_TIDMASK(i)) == 0)) {
8310             continue;
8311         }
8312         len = asc_prt_line(cp, leftlen, " %X:%u", i, v->max_dvc_qng[i]);
8313         ASC_PRT_NEXT();
8314     }
8315     len = asc_prt_line(cp, leftlen, "\n");
8316     ASC_PRT_NEXT();
8317
8318     /* Indicate whether the device has returned queue full status. */
8319     len = asc_prt_line(cp, leftlen,
8320 " Command Queue Full:");
8321     ASC_PRT_NEXT();
8322     for (i = 0; i <= ASC_MAX_TID; i++) {
8323         if ((chip_scsi_id == i) ||
8324             ((boardp->init_tidmask & ADV_TID_TO_TIDMASK(i)) == 0)) {
8325             continue;
8326         }
8327         if (boardp->queue_full & ADV_TID_TO_TIDMASK(i)) {
8328             len = asc_prt_line(cp, leftlen, " %X:Y-%d",
8329                 i, boardp->queue_full_cnt[i]);
8330         } else {
8331             len = asc_prt_line(cp, leftlen, " %X:N", i);
8332         }
8333         ASC_PRT_NEXT();
8334     }
8335     len = asc_prt_line(cp, leftlen, "\n");
8336     ASC_PRT_NEXT();
8337
8338     len = asc_prt_line(cp, leftlen,
8339 " Synchronous Transfer:");
8340     ASC_PRT_NEXT();
8341     for (i = 0; i <= ASC_MAX_TID; i++) {
8342         if ((chip_scsi_id == i) ||
8343             ((boardp->init_tidmask & ADV_TID_TO_TIDMASK(i)) == 0)) {
8344             continue;
8345         }
8346         len = asc_prt_line(cp, leftlen, " %X:%c",
8347             i, (v->sdtr_done & ADV_TID_TO_TIDMASK(i)) ? 'Y' : 'N');
8348         ASC_PRT_NEXT();
8349     }
8350     len = asc_prt_line(cp, leftlen, "\n");
8351     ASC_PRT_NEXT();
8352
8353     for (i = 0; i <= ASC_MAX_TID; i++) {
8354         uchar syn_period_ix;
8355
8356         if ((chip_scsi_id == i) ||
8357             ((boardp->init_tidmask & ADV_TID_TO_TIDMASK(i)) == 0) ||
8358             ((v->init_sdtr & ADV_TID_TO_TIDMASK(i)) == 0)) {
8359             continue;
8360         }
8361
8362         len = asc_prt_line(cp, leftlen, "  %X:", i);
8363         ASC_PRT_NEXT();
8364
8365         if ((boardp->sdtr_data[i] & ASC_SYN_MAX_OFFSET) == 0)
8366         {
8367             len = asc_prt_line(cp, leftlen, " Asynchronous");
8368             ASC_PRT_NEXT();
8369         } else
8370         {
8371             syn_period_ix =
8372                 (boardp->sdtr_data[i] >> 4) & (v->max_sdtr_index - 1);
8373
8374             len = asc_prt_line(cp, leftlen,
8375                 " Transfer Period Factor: %d (%d.%d Mhz),",
8376                 v->sdtr_period_tbl[syn_period_ix],
8377                 250 / v->sdtr_period_tbl[syn_period_ix],
8378                 ASC_TENTHS(250, v->sdtr_period_tbl[syn_period_ix]));
8379             ASC_PRT_NEXT();
8380
8381             len = asc_prt_line(cp, leftlen, " REQ/ACK Offset: %d",
8382                 boardp->sdtr_data[i] & ASC_SYN_MAX_OFFSET);
8383             ASC_PRT_NEXT();
8384         }
8385
8386         if ((v->sdtr_done & ADV_TID_TO_TIDMASK(i)) == 0) {
8387             len = asc_prt_line(cp, leftlen, "*\n");
8388             renegotiate = 1;
8389         } else
8390         {
8391             len = asc_prt_line(cp, leftlen, "\n");
8392         }
8393         ASC_PRT_NEXT();
8394     }
8395
8396     if (renegotiate)
8397     {
8398         len = asc_prt_line(cp, leftlen,
8399             " * = Re-negotiation pending before next command.\n");
8400         ASC_PRT_NEXT();
8401     }
8402
8403     return totlen;
8404 }
8405
8406 /*
8407  * asc_prt_adv_board_info()
8408  *
8409  * Print dynamic board configuration information.
8410  *
8411  * Note: no single line should be greater than ASC_PRTLINE_SIZE,
8412  * cf. asc_prt_line().
8413  *
8414  * Return the number of characters copied into 'cp'. No more than
8415  * 'cplen' characters will be copied to 'cp'.
8416  */
8417 STATIC int
8418 asc_prt_adv_board_info(struct Scsi_Host *shp, char *cp, int cplen)
8419 {
8420     asc_board_t            *boardp;
8421     int                    leftlen;
8422     int                    totlen;
8423     int                    len;
8424     int                    i;
8425     ADV_DVC_VAR            *v;
8426     ADV_DVC_CFG            *c;
8427     AdvPortAddr            iop_base;
8428     ushort                 chip_scsi_id;
8429     ushort                 lramword;
8430     uchar                  lrambyte;
8431     ushort                 tagqng_able;
8432     ushort                 sdtr_able, wdtr_able;
8433     ushort                 wdtr_done, sdtr_done;
8434     ushort                 period = 0;
8435     int                    renegotiate = 0;
8436
8437     boardp = ASC_BOARDP(shp);
8438     v = &boardp->dvc_var.adv_dvc_var;
8439     c = &boardp->dvc_cfg.adv_dvc_cfg;
8440     iop_base = v->iop_base;
8441     chip_scsi_id = v->chip_scsi_id;
8442
8443     leftlen = cplen;
8444     totlen = len = 0;
8445
8446     len = asc_prt_line(cp, leftlen,
8447 "\nAdv Library Configuration and Statistics for AdvanSys SCSI Host %d:\n",
8448     shp->host_no);
8449     ASC_PRT_NEXT();
8450
8451     len = asc_prt_line(cp, leftlen,
8452 " iop_base 0x%lx, cable_detect: %X, err_code %u\n",
8453          v->iop_base,
8454          AdvReadWordRegister(iop_base, IOPW_SCSI_CFG1) & CABLE_DETECT,
8455          v->err_code);
8456     ASC_PRT_NEXT();
8457
8458     len = asc_prt_line(cp, leftlen,
8459 " chip_version %u, lib_version 0x%x, mcode_date 0x%x, mcode_version 0x%x\n",
8460         c->chip_version, c->lib_version, c->mcode_date, c->mcode_version);
8461     ASC_PRT_NEXT();
8462
8463     AdvReadWordLram(iop_base, ASC_MC_TAGQNG_ABLE, tagqng_able);
8464     len = asc_prt_line(cp, leftlen,
8465 " Queuing Enabled:");
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         len = asc_prt_line(cp, leftlen, " %X:%c",
8474             i, (tagqng_able & ADV_TID_TO_TIDMASK(i)) ? 'Y' : 'N');
8475         ASC_PRT_NEXT();
8476     }
8477     len = asc_prt_line(cp, leftlen, "\n");
8478     ASC_PRT_NEXT();
8479
8480     len = asc_prt_line(cp, leftlen,
8481 " Queue Limit:");
8482     ASC_PRT_NEXT();
8483     for (i = 0; i <= ADV_MAX_TID; i++) {
8484         if ((chip_scsi_id == i) ||
8485             ((boardp->init_tidmask & ADV_TID_TO_TIDMASK(i)) == 0)) {
8486             continue;
8487         }
8488
8489         AdvReadByteLram(iop_base, ASC_MC_NUMBER_OF_MAX_CMD + i, lrambyte);
8490
8491         len = asc_prt_line(cp, leftlen, " %X:%d", i, lrambyte);
8492         ASC_PRT_NEXT();
8493     }
8494     len = asc_prt_line(cp, leftlen, "\n");
8495     ASC_PRT_NEXT();
8496
8497     len = asc_prt_line(cp, leftlen,
8498 " Command Pending:");
8499     ASC_PRT_NEXT();
8500     for (i = 0; i <= ADV_MAX_TID; i++) {
8501         if ((chip_scsi_id == i) ||
8502             ((boardp->init_tidmask & ADV_TID_TO_TIDMASK(i)) == 0)) {
8503             continue;
8504         }
8505
8506         AdvReadByteLram(iop_base, ASC_MC_NUMBER_OF_QUEUED_CMD + i, lrambyte);
8507
8508         len = asc_prt_line(cp, leftlen, " %X:%d", i, lrambyte);
8509         ASC_PRT_NEXT();
8510     }
8511     len = asc_prt_line(cp, leftlen, "\n");
8512     ASC_PRT_NEXT();
8513
8514     AdvReadWordLram(iop_base, ASC_MC_WDTR_ABLE, wdtr_able);
8515     len = asc_prt_line(cp, leftlen,
8516 " Wide Enabled:");
8517     ASC_PRT_NEXT();
8518     for (i = 0; i <= ADV_MAX_TID; i++) {
8519         if ((chip_scsi_id == i) ||
8520             ((boardp->init_tidmask & ADV_TID_TO_TIDMASK(i)) == 0)) {
8521             continue;
8522         }
8523
8524         len = asc_prt_line(cp, leftlen, " %X:%c",
8525             i, (wdtr_able & ADV_TID_TO_TIDMASK(i)) ? 'Y' : 'N');
8526         ASC_PRT_NEXT();
8527     }
8528     len = asc_prt_line(cp, leftlen, "\n");
8529     ASC_PRT_NEXT();
8530
8531     AdvReadWordLram(iop_base, ASC_MC_WDTR_DONE, wdtr_done);
8532     len = asc_prt_line(cp, leftlen,
8533 " Transfer Bit Width:");
8534     ASC_PRT_NEXT();
8535     for (i = 0; i <= ADV_MAX_TID; i++) {
8536         if ((chip_scsi_id == i) ||
8537             ((boardp->init_tidmask & ADV_TID_TO_TIDMASK(i)) == 0)) {
8538             continue;
8539         }
8540
8541         AdvReadWordLram(iop_base, ASC_MC_DEVICE_HSHK_CFG_TABLE + (2 * i),
8542             lramword);
8543
8544         len = asc_prt_line(cp, leftlen, " %X:%d",
8545             i, (lramword & 0x8000) ? 16 : 8);
8546         ASC_PRT_NEXT();
8547
8548         if ((wdtr_able & ADV_TID_TO_TIDMASK(i)) &&
8549             (wdtr_done & ADV_TID_TO_TIDMASK(i)) == 0) {
8550             len = asc_prt_line(cp, leftlen, "*");
8551             ASC_PRT_NEXT();
8552             renegotiate = 1;
8553         }
8554     }
8555     len = asc_prt_line(cp, leftlen, "\n");
8556     ASC_PRT_NEXT();
8557
8558     AdvReadWordLram(iop_base, ASC_MC_SDTR_ABLE, sdtr_able);
8559     len = asc_prt_line(cp, leftlen,
8560 " Synchronous Enabled:");
8561     ASC_PRT_NEXT();
8562     for (i = 0; i <= ADV_MAX_TID; i++) {
8563         if ((chip_scsi_id == i) ||
8564             ((boardp->init_tidmask & ADV_TID_TO_TIDMASK(i)) == 0)) {
8565             continue;
8566         }
8567
8568         len = asc_prt_line(cp, leftlen, " %X:%c",
8569             i, (sdtr_able & ADV_TID_TO_TIDMASK(i)) ? 'Y' : 'N');
8570         ASC_PRT_NEXT();
8571     }
8572     len = asc_prt_line(cp, leftlen, "\n");
8573     ASC_PRT_NEXT();
8574
8575     AdvReadWordLram(iop_base, ASC_MC_SDTR_DONE, sdtr_done);
8576     for (i = 0; i <= ADV_MAX_TID; i++) {
8577
8578         AdvReadWordLram(iop_base, ASC_MC_DEVICE_HSHK_CFG_TABLE + (2 * i),
8579             lramword);
8580         lramword &= ~0x8000;
8581
8582         if ((chip_scsi_id == i) ||
8583             ((boardp->init_tidmask & ADV_TID_TO_TIDMASK(i)) == 0) ||
8584             ((sdtr_able & ADV_TID_TO_TIDMASK(i)) == 0)) {
8585             continue;
8586         }
8587
8588         len = asc_prt_line(cp, leftlen, "  %X:", i);
8589         ASC_PRT_NEXT();
8590
8591         if ((lramword & 0x1F) == 0) /* Check for REQ/ACK Offset 0. */
8592         {
8593             len = asc_prt_line(cp, leftlen, " Asynchronous");
8594             ASC_PRT_NEXT();
8595         } else
8596         {
8597             len = asc_prt_line(cp, leftlen, " Transfer Period Factor: ");
8598             ASC_PRT_NEXT();
8599
8600             if ((lramword & 0x1F00) == 0x1100) /* 80 Mhz */
8601             {
8602                 len = asc_prt_line(cp, leftlen, "9 (80.0 Mhz),");
8603                 ASC_PRT_NEXT();
8604             } else if ((lramword & 0x1F00) == 0x1000) /* 40 Mhz */
8605             {
8606                 len = asc_prt_line(cp, leftlen, "10 (40.0 Mhz),");
8607                 ASC_PRT_NEXT();
8608             } else /* 20 Mhz or below. */
8609             {
8610                 period = (((lramword >> 8) * 25) + 50)/4;
8611
8612                 if (period == 0) /* Should never happen. */
8613                 {
8614                     len = asc_prt_line(cp, leftlen, "%d (? Mhz), ");
8615                     ASC_PRT_NEXT();
8616                 } else
8617                 {
8618                     len = asc_prt_line(cp, leftlen,
8619                         "%d (%d.%d Mhz),",
8620                         period, 250/period, ASC_TENTHS(250, period));
8621                     ASC_PRT_NEXT();
8622                 }
8623             }
8624
8625             len = asc_prt_line(cp, leftlen, " REQ/ACK Offset: %d",
8626                 lramword & 0x1F);
8627             ASC_PRT_NEXT();
8628         }
8629
8630         if ((sdtr_done & ADV_TID_TO_TIDMASK(i)) == 0) {
8631             len = asc_prt_line(cp, leftlen, "*\n");
8632             renegotiate = 1;
8633         } else
8634         {
8635             len = asc_prt_line(cp, leftlen, "\n");
8636         }
8637         ASC_PRT_NEXT();
8638     }
8639
8640     if (renegotiate)
8641     {
8642         len = asc_prt_line(cp, leftlen,
8643             " * = Re-negotiation pending before next command.\n");
8644         ASC_PRT_NEXT();
8645     }
8646
8647     return totlen;
8648 }
8649
8650 /*
8651  * asc_proc_copy()
8652  *
8653  * Copy proc information to a read buffer taking into account the current
8654  * read offset in the file and the remaining space in the read buffer.
8655  */
8656 STATIC int
8657 asc_proc_copy(off_t advoffset, off_t offset, char *curbuf, int leftlen,
8658               char *cp, int cplen)
8659 {
8660     int cnt = 0;
8661
8662     ASC_DBG3(2, "asc_proc_copy: offset %d, advoffset %d, cplen %d\n",
8663             (unsigned) offset, (unsigned) advoffset, cplen);
8664     if (offset <= advoffset) {
8665         /* Read offset below current offset, copy everything. */
8666         cnt = min(cplen, leftlen);
8667         ASC_DBG3(2, "asc_proc_copy: curbuf 0x%lx, cp 0x%lx, cnt %d\n",
8668                 (ulong) curbuf, (ulong) cp, cnt);
8669         memcpy(curbuf, cp, cnt);
8670     } else if (offset < advoffset + cplen) {
8671         /* Read offset within current range, partial copy. */
8672         cnt = (advoffset + cplen) - offset;
8673         cp = (cp + cplen) - cnt;
8674         cnt = min(cnt, leftlen);
8675         ASC_DBG3(2, "asc_proc_copy: curbuf 0x%lx, cp 0x%lx, cnt %d\n",
8676                 (ulong) curbuf, (ulong) cp, cnt);
8677         memcpy(curbuf, cp, cnt);
8678     }
8679     return cnt;
8680 }
8681
8682 /*
8683  * asc_prt_line()
8684  *
8685  * If 'cp' is NULL print to the console, otherwise print to a buffer.
8686  *
8687  * Return 0 if printing to the console, otherwise return the number of
8688  * bytes written to the buffer.
8689  *
8690  * Note: If any single line is greater than ASC_PRTLINE_SIZE bytes the stack
8691  * will be corrupted. 's[]' is defined to be ASC_PRTLINE_SIZE bytes.
8692  */
8693 STATIC int
8694 asc_prt_line(char *buf, int buflen, char *fmt, ...)
8695 {
8696     va_list        args;
8697     int            ret;
8698     char           s[ASC_PRTLINE_SIZE];
8699
8700     va_start(args, fmt);
8701     ret = vsprintf(s, fmt, args);
8702     ASC_ASSERT(ret < ASC_PRTLINE_SIZE);
8703     if (buf == NULL) {
8704         (void) printk(s);
8705         ret = 0;
8706     } else {
8707         ret = min(buflen, ret);
8708         memcpy(buf, s, ret);
8709     }
8710     va_end(args);
8711     return ret;
8712 }
8713 #endif /* CONFIG_PROC_FS */
8714
8715
8716 /*
8717  * --- Functions Required by the Asc Library
8718  */
8719
8720 /*
8721  * Delay for 'n' milliseconds. Don't use the 'jiffies'
8722  * global variable which is incremented once every 5 ms
8723  * from a timer interrupt, because this function may be
8724  * called when interrupts are disabled.
8725  */
8726 STATIC void
8727 DvcSleepMilliSecond(ADV_DCNT n)
8728 {
8729     ASC_DBG1(4, "DvcSleepMilliSecond: %lu\n", (ulong) n);
8730     mdelay(n);
8731 }
8732
8733 /*
8734  * Currently and inline noop but leave as a placeholder.
8735  * Leave DvcEnterCritical() as a noop placeholder.
8736  */
8737 STATIC inline ulong
8738 DvcEnterCritical(void)
8739 {
8740     return 0;
8741 }
8742
8743 /*
8744  * Critical sections are all protected by the board spinlock.
8745  * Leave DvcLeaveCritical() as a noop placeholder.
8746  */
8747 STATIC inline void
8748 DvcLeaveCritical(ulong flags)
8749 {
8750     return;
8751 }
8752
8753 /*
8754  * void
8755  * DvcPutScsiQ(PortAddr iop_base, ushort s_addr, uchar *outbuf, int words)
8756  *
8757  * Calling/Exit State:
8758  *    none
8759  *
8760  * Description:
8761  *     Output an ASC_SCSI_Q structure to the chip
8762  */
8763 STATIC void
8764 DvcPutScsiQ(PortAddr iop_base, ushort s_addr, uchar *outbuf, int words)
8765 {
8766     int    i;
8767
8768     ASC_DBG_PRT_HEX(2, "DvcPutScsiQ", outbuf, 2 * words);
8769     AscSetChipLramAddr(iop_base, s_addr);
8770     for (i = 0; i < 2 * words; i += 2) {
8771         if (i == 4 || i == 20) {
8772             continue;
8773         }
8774         outpw(iop_base + IOP_RAM_DATA,
8775             ((ushort) outbuf[i + 1] << 8) | outbuf[i]);
8776     }
8777 }
8778
8779 /*
8780  * void
8781  * DvcGetQinfo(PortAddr iop_base, ushort s_addr, uchar *inbuf, int words)
8782  *
8783  * Calling/Exit State:
8784  *    none
8785  *
8786  * Description:
8787  *     Input an ASC_QDONE_INFO structure from the chip
8788  */
8789 STATIC void
8790 DvcGetQinfo(PortAddr iop_base, ushort s_addr, uchar *inbuf, int words)
8791 {
8792     int    i;
8793     ushort word;
8794
8795     AscSetChipLramAddr(iop_base, s_addr);
8796     for (i = 0; i < 2 * words; i += 2) {
8797         if (i == 10) {
8798             continue;
8799         }
8800         word = inpw(iop_base + IOP_RAM_DATA);
8801         inbuf[i] = word & 0xff;
8802         inbuf[i + 1] = (word >> 8) & 0xff;
8803     }
8804     ASC_DBG_PRT_HEX(2, "DvcGetQinfo", inbuf, 2 * words);
8805 }
8806
8807 /*
8808  * Read a PCI configuration byte.
8809  */
8810 STATIC uchar __init
8811 DvcReadPCIConfigByte(
8812         ASC_DVC_VAR *asc_dvc,
8813         ushort offset)
8814 {
8815 #ifdef CONFIG_PCI
8816     uchar byte_data;
8817     pci_read_config_byte(to_pci_dev(asc_dvc->cfg->dev), offset, &byte_data);
8818     return byte_data;
8819 #else /* !defined(CONFIG_PCI) */
8820     return 0;
8821 #endif /* !defined(CONFIG_PCI) */
8822 }
8823
8824 /*
8825  * Write a PCI configuration byte.
8826  */
8827 STATIC void __init
8828 DvcWritePCIConfigByte(
8829         ASC_DVC_VAR *asc_dvc,
8830         ushort offset,
8831         uchar  byte_data)
8832 {
8833 #ifdef CONFIG_PCI
8834     pci_write_config_byte(to_pci_dev(asc_dvc->cfg->dev), offset, byte_data);
8835 #endif /* CONFIG_PCI */
8836 }
8837
8838 /*
8839  * Return the BIOS address of the adapter at the specified
8840  * I/O port and with the specified bus type.
8841  */
8842 STATIC ushort __init
8843 AscGetChipBiosAddress(
8844         PortAddr iop_base,
8845         ushort bus_type)
8846 {
8847     ushort  cfg_lsw;
8848     ushort  bios_addr;
8849
8850     /*
8851      * The PCI BIOS is re-located by the motherboard BIOS. Because
8852      * of this the driver can not determine where a PCI BIOS is
8853      * loaded and executes.
8854      */
8855     if (bus_type & ASC_IS_PCI)
8856     {
8857         return(0);
8858     }
8859
8860 #ifdef CONFIG_ISA
8861     if((bus_type & ASC_IS_EISA) != 0)
8862     {
8863         cfg_lsw = AscGetEisaChipCfg(iop_base);
8864         cfg_lsw &= 0x000F;
8865         bios_addr = (ushort)(ASC_BIOS_MIN_ADDR  +
8866                                 (cfg_lsw * ASC_BIOS_BANK_SIZE));
8867         return(bios_addr);
8868     }/* if */
8869 #endif /* CONFIG_ISA */
8870
8871     cfg_lsw = AscGetChipCfgLsw(iop_base);
8872
8873     /*
8874     *  ISA PnP uses the top bit as the 32K BIOS flag
8875     */
8876     if (bus_type == ASC_IS_ISAPNP)
8877     {
8878         cfg_lsw &= 0x7FFF;
8879     }/* if */
8880
8881     bios_addr = (ushort)(((cfg_lsw >> 12) * ASC_BIOS_BANK_SIZE) +
8882             ASC_BIOS_MIN_ADDR);
8883     return(bios_addr);
8884 }
8885
8886
8887 /*
8888  * --- Functions Required by the Adv Library
8889  */
8890
8891 /*
8892  * DvcGetPhyAddr()
8893  *
8894  * Return the physical address of 'vaddr' and set '*lenp' to the
8895  * number of physically contiguous bytes that follow 'vaddr'.
8896  * 'flag' indicates the type of structure whose physical address
8897  * is being translated.
8898  *
8899  * Note: Because Linux currently doesn't page the kernel and all
8900  * kernel buffers are physically contiguous, leave '*lenp' unchanged.
8901  */
8902 ADV_PADDR
8903 DvcGetPhyAddr(ADV_DVC_VAR *asc_dvc, ADV_SCSI_REQ_Q *scsiq,
8904         uchar *vaddr, ADV_SDCNT *lenp, int flag)
8905 {
8906     ADV_PADDR           paddr;
8907
8908     paddr = virt_to_bus(vaddr);
8909
8910     ASC_DBG4(4,
8911         "DvcGetPhyAddr: vaddr 0x%lx, lenp 0x%lx *lenp %lu, paddr 0x%lx\n",
8912         (ulong) vaddr, (ulong) lenp, (ulong) *((ulong *) lenp), (ulong) paddr);
8913
8914     return paddr;
8915 }
8916
8917 /*
8918  * Read a PCI configuration byte.
8919  */
8920 STATIC uchar __init
8921 DvcAdvReadPCIConfigByte(
8922         ADV_DVC_VAR *asc_dvc,
8923         ushort offset)
8924 {
8925 #ifdef CONFIG_PCI
8926     uchar byte_data;
8927     pci_read_config_byte(to_pci_dev(asc_dvc->cfg->dev), offset, &byte_data);
8928     return byte_data;
8929 #else /* CONFIG_PCI */
8930     return 0;
8931 #endif /* CONFIG_PCI */
8932 }
8933
8934 /*
8935  * Write a PCI configuration byte.
8936  */
8937 STATIC void __init
8938 DvcAdvWritePCIConfigByte(
8939         ADV_DVC_VAR *asc_dvc,
8940         ushort offset,
8941         uchar  byte_data)
8942 {
8943 #ifdef CONFIG_PCI
8944     pci_write_config_byte(to_pci_dev(asc_dvc->cfg->dev), offset, byte_data);
8945 #else /* CONFIG_PCI */
8946     return 0;
8947 #endif /* CONFIG_PCI */
8948 }
8949
8950 /*
8951  * --- Tracing and Debugging Functions
8952  */
8953
8954 #ifdef ADVANSYS_STATS
8955 #ifdef CONFIG_PROC_FS
8956 /*
8957  * asc_prt_board_stats()
8958  *
8959  * Note: no single line should be greater than ASC_PRTLINE_SIZE,
8960  * cf. asc_prt_line().
8961  *
8962  * Return the number of characters copied into 'cp'. No more than
8963  * 'cplen' characters will be copied to 'cp'.
8964  */
8965 STATIC int
8966 asc_prt_board_stats(struct Scsi_Host *shp, char *cp, int cplen)
8967 {
8968     int                    leftlen;
8969     int                    totlen;
8970     int                    len;
8971     struct asc_stats       *s;
8972     asc_board_t            *boardp;
8973
8974     leftlen = cplen;
8975     totlen = len = 0;
8976
8977     boardp = ASC_BOARDP(shp);
8978     s = &boardp->asc_stats;
8979
8980     len = asc_prt_line(cp, leftlen,
8981 "\nLinux Driver Statistics for AdvanSys SCSI Host %d:\n", shp->host_no);
8982     ASC_PRT_NEXT();
8983
8984     len = asc_prt_line(cp, leftlen,
8985 " queuecommand %lu, reset %lu, biosparam %lu, interrupt %lu\n",
8986         s->queuecommand, s->reset, s->biosparam, s->interrupt);
8987     ASC_PRT_NEXT();
8988
8989     len = asc_prt_line(cp, leftlen,
8990 " callback %lu, done %lu, build_error %lu, build_noreq %lu, build_nosg %lu\n",
8991         s->callback, s->done, s->build_error, s->adv_build_noreq,
8992         s->adv_build_nosg);
8993     ASC_PRT_NEXT();
8994
8995     len = asc_prt_line(cp, leftlen,
8996 " exe_noerror %lu, exe_busy %lu, exe_error %lu, exe_unknown %lu\n",
8997         s->exe_noerror, s->exe_busy, s->exe_error, s->exe_unknown);
8998     ASC_PRT_NEXT();
8999
9000     /*
9001      * Display data transfer statistics.
9002      */
9003     if (s->cont_cnt > 0) {
9004         len = asc_prt_line(cp, leftlen, " cont_cnt %lu, ", s->cont_cnt);
9005         ASC_PRT_NEXT();
9006
9007         len = asc_prt_line(cp, leftlen, "cont_xfer %lu.%01lu kb ",
9008                     s->cont_xfer/2,
9009                     ASC_TENTHS(s->cont_xfer, 2));
9010         ASC_PRT_NEXT();
9011
9012         /* Contiguous transfer average size */
9013         len = asc_prt_line(cp, leftlen, "avg_xfer %lu.%01lu kb\n",
9014                     (s->cont_xfer/2)/s->cont_cnt,
9015                     ASC_TENTHS((s->cont_xfer/2), s->cont_cnt));
9016         ASC_PRT_NEXT();
9017     }
9018
9019     if (s->sg_cnt > 0) {
9020
9021         len = asc_prt_line(cp, leftlen, " sg_cnt %lu, sg_elem %lu, ",
9022                     s->sg_cnt, s->sg_elem);
9023         ASC_PRT_NEXT();
9024
9025         len = asc_prt_line(cp, leftlen, "sg_xfer %lu.%01lu kb\n",
9026                     s->sg_xfer/2,
9027                     ASC_TENTHS(s->sg_xfer, 2));
9028         ASC_PRT_NEXT();
9029
9030         /* Scatter gather transfer statistics */
9031         len = asc_prt_line(cp, leftlen, " avg_num_elem %lu.%01lu, ",
9032                     s->sg_elem/s->sg_cnt,
9033                     ASC_TENTHS(s->sg_elem, s->sg_cnt));
9034         ASC_PRT_NEXT();
9035
9036         len = asc_prt_line(cp, leftlen, "avg_elem_size %lu.%01lu kb, ",
9037                     (s->sg_xfer/2)/s->sg_elem,
9038                     ASC_TENTHS((s->sg_xfer/2), s->sg_elem));
9039         ASC_PRT_NEXT();
9040
9041         len = asc_prt_line(cp, leftlen, "avg_xfer_size %lu.%01lu kb\n",
9042                     (s->sg_xfer/2)/s->sg_cnt,
9043                     ASC_TENTHS((s->sg_xfer/2), s->sg_cnt));
9044         ASC_PRT_NEXT();
9045     }
9046
9047     /*
9048      * Display request queuing statistics.
9049      */
9050     len = asc_prt_line(cp, leftlen,
9051 " Active and Waiting Request Queues (Time Unit: %d HZ):\n", HZ);
9052     ASC_PRT_NEXT();
9053
9054
9055      return totlen;
9056 }
9057
9058 /*
9059  * asc_prt_target_stats()
9060  *
9061  * Note: no single line should be greater than ASC_PRTLINE_SIZE,
9062  * cf. asc_prt_line().
9063  *
9064  * This is separated from asc_prt_board_stats because a full set
9065  * of targets will overflow ASC_PRTBUF_SIZE.
9066  *
9067  * Return the number of characters copied into 'cp'. No more than
9068  * 'cplen' characters will be copied to 'cp'.
9069  */
9070 STATIC int
9071 asc_prt_target_stats(struct Scsi_Host *shp, int tgt_id, char *cp, int cplen)
9072 {
9073     int                    leftlen;
9074     int                    totlen;
9075     int                    len;
9076     struct asc_stats       *s;
9077     ushort                 chip_scsi_id;
9078     asc_board_t            *boardp;
9079     asc_queue_t            *active;
9080     asc_queue_t            *waiting;
9081
9082     leftlen = cplen;
9083     totlen = len = 0;
9084
9085     boardp = ASC_BOARDP(shp);
9086     s = &boardp->asc_stats;
9087
9088     active = &ASC_BOARDP(shp)->active;
9089     waiting = &ASC_BOARDP(shp)->waiting;
9090
9091     if (ASC_NARROW_BOARD(boardp)) {
9092         chip_scsi_id = boardp->dvc_cfg.asc_dvc_cfg.chip_scsi_id;
9093     } else {
9094         chip_scsi_id = boardp->dvc_var.adv_dvc_var.chip_scsi_id;
9095     }
9096
9097     if ((chip_scsi_id == tgt_id) ||
9098         ((boardp->init_tidmask & ADV_TID_TO_TIDMASK(tgt_id)) == 0)) {
9099         return 0;
9100     }
9101
9102     do {
9103         if (active->q_tot_cnt[tgt_id] > 0 || waiting->q_tot_cnt[tgt_id] > 0) {
9104             len = asc_prt_line(cp, leftlen, " target %d\n", tgt_id);
9105             ASC_PRT_NEXT();
9106
9107             len = asc_prt_line(cp, leftlen,
9108 "   active: cnt [cur %d, max %d, tot %u], time [min %d, max %d, avg %lu.%01lu]\n",
9109                 active->q_cur_cnt[tgt_id], active->q_max_cnt[tgt_id],
9110                 active->q_tot_cnt[tgt_id],
9111                 active->q_min_tim[tgt_id], active->q_max_tim[tgt_id],
9112                 (active->q_tot_cnt[tgt_id] == 0) ? 0 :
9113                 (active->q_tot_tim[tgt_id]/active->q_tot_cnt[tgt_id]),
9114                 (active->q_tot_cnt[tgt_id] == 0) ? 0 :
9115                 ASC_TENTHS(active->q_tot_tim[tgt_id],
9116                 active->q_tot_cnt[tgt_id]));
9117              ASC_PRT_NEXT();
9118
9119              len = asc_prt_line(cp, leftlen,
9120 "   waiting: cnt [cur %d, max %d, tot %u], time [min %u, max %u, avg %lu.%01lu]\n",
9121                 waiting->q_cur_cnt[tgt_id], waiting->q_max_cnt[tgt_id],
9122                 waiting->q_tot_cnt[tgt_id],
9123                 waiting->q_min_tim[tgt_id], waiting->q_max_tim[tgt_id],
9124                 (waiting->q_tot_cnt[tgt_id] == 0) ? 0 :
9125                 (waiting->q_tot_tim[tgt_id]/waiting->q_tot_cnt[tgt_id]),
9126                 (waiting->q_tot_cnt[tgt_id] == 0) ? 0 :
9127                 ASC_TENTHS(waiting->q_tot_tim[tgt_id],
9128                 waiting->q_tot_cnt[tgt_id]));
9129              ASC_PRT_NEXT();
9130         }
9131     } while (0);
9132
9133      return totlen;
9134 }
9135 #endif /* CONFIG_PROC_FS */
9136 #endif /* ADVANSYS_STATS */
9137
9138 #ifdef ADVANSYS_DEBUG
9139 /*
9140  * asc_prt_scsi_host()
9141  */
9142 STATIC void
9143 asc_prt_scsi_host(struct Scsi_Host *s)
9144 {
9145     asc_board_t         *boardp;
9146
9147     boardp = ASC_BOARDP(s);
9148
9149     printk("Scsi_Host at addr 0x%lx\n", (ulong) s);
9150     printk(
9151 " host_busy %u, host_no %d, last_reset %d,\n",
9152         s->host_busy, s->host_no,
9153         (unsigned) s->last_reset);
9154
9155     printk(
9156 " base 0x%lx, io_port 0x%lx, n_io_port %u, irq 0x%x,\n",
9157         (ulong) s->base, (ulong) s->io_port, s->n_io_port, s->irq);
9158
9159     printk(
9160 " dma_channel %d, this_id %d, can_queue %d,\n",
9161         s->dma_channel, s->this_id, s->can_queue);
9162
9163     printk(
9164 " cmd_per_lun %d, sg_tablesize %d, unchecked_isa_dma %d\n",
9165         s->cmd_per_lun, s->sg_tablesize, s->unchecked_isa_dma);
9166
9167     if (ASC_NARROW_BOARD(boardp)) {
9168         asc_prt_asc_dvc_var(&ASC_BOARDP(s)->dvc_var.asc_dvc_var);
9169         asc_prt_asc_dvc_cfg(&ASC_BOARDP(s)->dvc_cfg.asc_dvc_cfg);
9170     } else {
9171         asc_prt_adv_dvc_var(&ASC_BOARDP(s)->dvc_var.adv_dvc_var);
9172         asc_prt_adv_dvc_cfg(&ASC_BOARDP(s)->dvc_cfg.adv_dvc_cfg);
9173     }
9174 }
9175
9176 /*
9177  * asc_prt_scsi_cmnd()
9178  */
9179 STATIC void
9180 asc_prt_scsi_cmnd(struct scsi_cmnd *s)
9181 {
9182     printk("struct scsi_cmnd at addr 0x%lx\n", (ulong) s);
9183
9184     printk(
9185 " host 0x%lx, device 0x%lx, target %u, lun %u, channel %u,\n",
9186         (ulong) s->device->host, (ulong) s->device, s->device->id, s->device->lun,
9187         s->device->channel);
9188
9189     asc_prt_hex(" CDB", s->cmnd, s->cmd_len);
9190
9191     printk (
9192 "sc_data_direction %u, resid %d\n",
9193         s->sc_data_direction, s->resid);
9194
9195     printk(
9196 " use_sg %u, sglist_len %u, abort_reason 0x%x\n",
9197         s->use_sg, s->sglist_len, s->abort_reason);
9198
9199     printk(
9200 " serial_number 0x%x, serial_number_at_timeout 0x%x, retries %d, allowed %d\n",
9201         (unsigned) s->serial_number, (unsigned) s->serial_number_at_timeout,
9202          s->retries, s->allowed);
9203
9204     printk(
9205 " timeout_per_command %d, timeout_total %d, timeout %d\n",
9206         s->timeout_per_command, s->timeout_total, s->timeout);
9207
9208     printk(" internal_timeout %u\n", s->internal_timeout);
9209
9210     printk(
9211 " scsi_done 0x%lx, done 0x%lx, host_scribble 0x%lx, result 0x%x\n",
9212         (ulong) s->scsi_done, (ulong) s->done,
9213         (ulong) s->host_scribble, s->result);
9214
9215     printk(
9216 " tag %u, pid %u\n",
9217         (unsigned) s->tag, (unsigned) s->pid);
9218 }
9219
9220 /*
9221  * asc_prt_asc_dvc_var()
9222  */
9223 STATIC void
9224 asc_prt_asc_dvc_var(ASC_DVC_VAR *h)
9225 {
9226     printk("ASC_DVC_VAR at addr 0x%lx\n", (ulong) h);
9227
9228     printk(
9229 " iop_base 0x%x, err_code 0x%x, dvc_cntl 0x%x, bug_fix_cntl %d,\n",
9230         h->iop_base, h->err_code, h->dvc_cntl, h->bug_fix_cntl);
9231
9232     printk(
9233 " bus_type %d, isr_callback 0x%lx, exe_callback 0x%lx, init_sdtr 0x%x,\n",
9234         h->bus_type, (ulong) h->isr_callback, (ulong) h->exe_callback,
9235         (unsigned) h->init_sdtr);
9236
9237     printk(
9238 " sdtr_done 0x%x, use_tagged_qng 0x%x, unit_not_ready 0x%x, chip_no 0x%x,\n",
9239         (unsigned) h->sdtr_done, (unsigned) h->use_tagged_qng,
9240         (unsigned) h->unit_not_ready, (unsigned) h->chip_no);
9241
9242     printk(
9243 " queue_full_or_busy 0x%x, start_motor 0x%x, scsi_reset_wait %u,\n",
9244         (unsigned) h->queue_full_or_busy, (unsigned) h->start_motor,
9245         (unsigned) h->scsi_reset_wait);
9246
9247     printk(
9248 " is_in_int %u, max_total_qng %u, cur_total_qng %u, in_critical_cnt %u,\n",
9249         (unsigned) h->is_in_int, (unsigned) h->max_total_qng,
9250         (unsigned) h->cur_total_qng, (unsigned) h->in_critical_cnt);
9251
9252     printk(
9253 " last_q_shortage %u, init_state 0x%x, no_scam 0x%x, pci_fix_asyn_xfer 0x%x,\n",
9254         (unsigned) h->last_q_shortage, (unsigned) h->init_state,
9255         (unsigned) h->no_scam, (unsigned) h->pci_fix_asyn_xfer);
9256
9257     printk(
9258 " cfg 0x%lx, irq_no 0x%x\n",
9259         (ulong) h->cfg, (unsigned) h->irq_no);
9260 }
9261
9262 /*
9263  * asc_prt_asc_dvc_cfg()
9264  */
9265 STATIC void
9266 asc_prt_asc_dvc_cfg(ASC_DVC_CFG *h)
9267 {
9268     printk("ASC_DVC_CFG at addr 0x%lx\n", (ulong) h);
9269
9270     printk(
9271 " can_tagged_qng 0x%x, cmd_qng_enabled 0x%x,\n",
9272             h->can_tagged_qng, h->cmd_qng_enabled);
9273     printk(
9274 " disc_enable 0x%x, sdtr_enable 0x%x,\n",
9275             h->disc_enable, h->sdtr_enable);
9276
9277     printk(
9278 " chip_scsi_id %d, isa_dma_speed %d, isa_dma_channel %d, chip_version %d,\n",
9279              h->chip_scsi_id, h->isa_dma_speed, h->isa_dma_channel,
9280              h->chip_version);
9281
9282     printk(
9283 " pci_device_id %d, lib_serial_no %u, lib_version %u, mcode_date 0x%x,\n",
9284            to_pci_dev(h->dev)->device, h->lib_serial_no, h->lib_version,
9285            h->mcode_date);
9286
9287     printk(
9288 " mcode_version %d, overrun_buf 0x%lx\n",
9289             h->mcode_version, (ulong) h->overrun_buf);
9290 }
9291
9292 /*
9293  * asc_prt_asc_scsi_q()
9294  */
9295 STATIC void
9296 asc_prt_asc_scsi_q(ASC_SCSI_Q *q)
9297 {
9298     ASC_SG_HEAD    *sgp;
9299     int i;
9300
9301     printk("ASC_SCSI_Q at addr 0x%lx\n", (ulong) q);
9302
9303     printk(
9304 " target_ix 0x%x, target_lun %u, srb_ptr 0x%lx, tag_code 0x%x,\n",
9305             q->q2.target_ix, q->q1.target_lun,
9306             (ulong) q->q2.srb_ptr, q->q2.tag_code);
9307
9308     printk(
9309 " data_addr 0x%lx, data_cnt %lu, sense_addr 0x%lx, sense_len %u,\n",
9310             (ulong) le32_to_cpu(q->q1.data_addr),
9311             (ulong) le32_to_cpu(q->q1.data_cnt),
9312             (ulong) le32_to_cpu(q->q1.sense_addr), q->q1.sense_len);
9313
9314     printk(
9315 " cdbptr 0x%lx, cdb_len %u, sg_head 0x%lx, sg_queue_cnt %u\n",
9316             (ulong) q->cdbptr, q->q2.cdb_len,
9317             (ulong) q->sg_head, q->q1.sg_queue_cnt);
9318
9319     if (q->sg_head) {
9320         sgp = q->sg_head;
9321         printk("ASC_SG_HEAD at addr 0x%lx\n", (ulong) sgp);
9322         printk(" entry_cnt %u, queue_cnt %u\n", sgp->entry_cnt, sgp->queue_cnt);
9323         for (i = 0; i < sgp->entry_cnt; i++) {
9324             printk(" [%u]: addr 0x%lx, bytes %lu\n",
9325                 i, (ulong) le32_to_cpu(sgp->sg_list[i].addr),
9326                 (ulong) le32_to_cpu(sgp->sg_list[i].bytes));
9327         }
9328
9329     }
9330 }
9331
9332 /*
9333  * asc_prt_asc_qdone_info()
9334  */
9335 STATIC void
9336 asc_prt_asc_qdone_info(ASC_QDONE_INFO *q)
9337 {
9338     printk("ASC_QDONE_INFO at addr 0x%lx\n", (ulong) q);
9339     printk(
9340 " srb_ptr 0x%lx, target_ix %u, cdb_len %u, tag_code %u,\n",
9341             (ulong) q->d2.srb_ptr, q->d2.target_ix, q->d2.cdb_len,
9342             q->d2.tag_code);
9343     printk(
9344 " done_stat 0x%x, host_stat 0x%x, scsi_stat 0x%x, scsi_msg 0x%x\n",
9345             q->d3.done_stat, q->d3.host_stat, q->d3.scsi_stat, q->d3.scsi_msg);
9346 }
9347
9348 /*
9349  * asc_prt_adv_dvc_var()
9350  *
9351  * Display an ADV_DVC_VAR structure.
9352  */
9353 STATIC void
9354 asc_prt_adv_dvc_var(ADV_DVC_VAR *h)
9355 {
9356     printk(" ADV_DVC_VAR at addr 0x%lx\n", (ulong) h);
9357
9358     printk(
9359 "  iop_base 0x%lx, err_code 0x%x, ultra_able 0x%x\n",
9360         (ulong) h->iop_base, h->err_code, (unsigned) h->ultra_able);
9361
9362     printk(
9363 "  isr_callback 0x%lx, sdtr_able 0x%x, wdtr_able 0x%x\n",
9364         (ulong) h->isr_callback, (unsigned) h->sdtr_able,
9365         (unsigned) h->wdtr_able);
9366
9367     printk(
9368 "  start_motor 0x%x, scsi_reset_wait 0x%x, irq_no 0x%x,\n",
9369         (unsigned) h->start_motor,
9370         (unsigned) h->scsi_reset_wait, (unsigned) h->irq_no);
9371
9372     printk(
9373 "  max_host_qng %u, max_dvc_qng %u, carr_freelist 0x%lxn\n",
9374         (unsigned) h->max_host_qng, (unsigned) h->max_dvc_qng,
9375         (ulong) h->carr_freelist);
9376
9377     printk(
9378 "  icq_sp 0x%lx, irq_sp 0x%lx\n",
9379         (ulong) h->icq_sp, (ulong) h->irq_sp);
9380
9381     printk(
9382 "  no_scam 0x%x, tagqng_able 0x%x\n",
9383         (unsigned) h->no_scam, (unsigned) h->tagqng_able);
9384
9385     printk(
9386 "  chip_scsi_id 0x%x, cfg 0x%lx\n",
9387         (unsigned) h->chip_scsi_id, (ulong) h->cfg);
9388 }
9389
9390 /*
9391  * asc_prt_adv_dvc_cfg()
9392  *
9393  * Display an ADV_DVC_CFG structure.
9394  */
9395 STATIC void
9396 asc_prt_adv_dvc_cfg(ADV_DVC_CFG *h)
9397 {
9398     printk(" ADV_DVC_CFG at addr 0x%lx\n", (ulong) h);
9399
9400     printk(
9401 "  disc_enable 0x%x, termination 0x%x\n",
9402         h->disc_enable, h->termination);
9403
9404     printk(
9405 "  chip_version 0x%x, mcode_date 0x%x\n",
9406         h->chip_version, h->mcode_date);
9407
9408     printk(
9409 "  mcode_version 0x%x, pci_device_id 0x%x, lib_version %u\n",
9410        h->mcode_version, to_pci_dev(h->dev)->device, h->lib_version);
9411
9412     printk(
9413 "  control_flag 0x%x, pci_slot_info 0x%x\n",
9414        h->control_flag, h->pci_slot_info);
9415 }
9416
9417 /*
9418  * asc_prt_adv_scsi_req_q()
9419  *
9420  * Display an ADV_SCSI_REQ_Q structure.
9421  */
9422 STATIC void
9423 asc_prt_adv_scsi_req_q(ADV_SCSI_REQ_Q *q)
9424 {
9425     int                 sg_blk_cnt;
9426     struct asc_sg_block *sg_ptr;
9427
9428     printk("ADV_SCSI_REQ_Q at addr 0x%lx\n", (ulong) q);
9429
9430     printk(
9431 "  target_id %u, target_lun %u, srb_ptr 0x%lx, a_flag 0x%x\n",
9432             q->target_id, q->target_lun, (ulong) q->srb_ptr, q->a_flag);
9433
9434     printk("  cntl 0x%x, data_addr 0x%lx, vdata_addr 0x%lx\n",
9435             q->cntl, (ulong) le32_to_cpu(q->data_addr), (ulong) q->vdata_addr);
9436
9437     printk(
9438 "  data_cnt %lu, sense_addr 0x%lx, sense_len %u,\n",
9439             (ulong) le32_to_cpu(q->data_cnt),
9440             (ulong) le32_to_cpu(q->sense_addr), q->sense_len);
9441
9442     printk(
9443 "  cdb_len %u, done_status 0x%x, host_status 0x%x, scsi_status 0x%x\n",
9444             q->cdb_len, q->done_status, q->host_status, q->scsi_status);
9445
9446     printk(
9447 "  sg_working_ix 0x%x, target_cmd %u\n",
9448             q->sg_working_ix, q->target_cmd);
9449
9450     printk(
9451 "  scsiq_rptr 0x%lx, sg_real_addr 0x%lx, sg_list_ptr 0x%lx\n",
9452             (ulong) le32_to_cpu(q->scsiq_rptr),
9453             (ulong) le32_to_cpu(q->sg_real_addr), (ulong) q->sg_list_ptr);
9454
9455     /* Display the request's ADV_SG_BLOCK structures. */
9456     if (q->sg_list_ptr != NULL)
9457     {
9458         sg_blk_cnt = 0;
9459         while (1) {
9460             /*
9461              * 'sg_ptr' is a physical address. Convert it to a virtual
9462              * address by indexing 'sg_blk_cnt' into the virtual address
9463              * array 'sg_list_ptr'.
9464              *
9465              * XXX - Assumes all SG physical blocks are virtually contiguous.
9466              */
9467             sg_ptr = &(((ADV_SG_BLOCK *) (q->sg_list_ptr))[sg_blk_cnt]);
9468             asc_prt_adv_sgblock(sg_blk_cnt, sg_ptr);
9469             if (sg_ptr->sg_ptr == 0)
9470             {
9471                 break;
9472             }
9473             sg_blk_cnt++;
9474         }
9475     }
9476 }
9477
9478 /*
9479  * asc_prt_adv_sgblock()
9480  *
9481  * Display an ADV_SG_BLOCK structure.
9482  */
9483 STATIC void
9484 asc_prt_adv_sgblock(int sgblockno, ADV_SG_BLOCK *b)
9485 {
9486     int i;
9487
9488     printk(" ASC_SG_BLOCK at addr 0x%lx (sgblockno %d)\n",
9489         (ulong) b, sgblockno);
9490     printk("  sg_cnt %u, sg_ptr 0x%lx\n",
9491         b->sg_cnt, (ulong) le32_to_cpu(b->sg_ptr));
9492     ASC_ASSERT(b->sg_cnt <= NO_OF_SG_PER_BLOCK);
9493     if (b->sg_ptr != 0)
9494     {
9495         ASC_ASSERT(b->sg_cnt == NO_OF_SG_PER_BLOCK);
9496     }
9497     for (i = 0; i < b->sg_cnt; i++) {
9498         printk("  [%u]: sg_addr 0x%lx, sg_count 0x%lx\n",
9499             i, (ulong) b->sg_list[i].sg_addr, (ulong) b->sg_list[i].sg_count);
9500     }
9501 }
9502
9503 /*
9504  * asc_prt_hex()
9505  *
9506  * Print hexadecimal output in 4 byte groupings 32 bytes
9507  * or 8 double-words per line.
9508  */
9509 STATIC void
9510 asc_prt_hex(char *f, uchar *s, int l)
9511 {
9512     int            i;
9513     int            j;
9514     int            k;
9515     int            m;
9516
9517     printk("%s: (%d bytes)\n", f, l);
9518
9519     for (i = 0; i < l; i += 32) {
9520
9521         /* Display a maximum of 8 double-words per line. */
9522         if ((k = (l - i) / 4) >= 8) {
9523             k = 8;
9524             m = 0;
9525         } else {
9526             m = (l - i) % 4;
9527         }
9528
9529         for (j = 0; j < k; j++) {
9530             printk(" %2.2X%2.2X%2.2X%2.2X",
9531                 (unsigned) s[i+(j*4)], (unsigned) s[i+(j*4)+1],
9532                 (unsigned) s[i+(j*4)+2], (unsigned) s[i+(j*4)+3]);
9533         }
9534
9535         switch (m) {
9536         case 0:
9537         default:
9538             break;
9539         case 1:
9540             printk(" %2.2X",
9541                 (unsigned) s[i+(j*4)]);
9542             break;
9543         case 2:
9544             printk(" %2.2X%2.2X",
9545                 (unsigned) s[i+(j*4)],
9546                 (unsigned) s[i+(j*4)+1]);
9547             break;
9548         case 3:
9549             printk(" %2.2X%2.2X%2.2X",
9550                 (unsigned) s[i+(j*4)+1],
9551                 (unsigned) s[i+(j*4)+2],
9552                 (unsigned) s[i+(j*4)+3]);
9553             break;
9554         }
9555
9556         printk("\n");
9557     }
9558 }
9559 #endif /* ADVANSYS_DEBUG */
9560
9561 /*
9562  * --- Asc Library Functions
9563  */
9564
9565 STATIC ushort __init
9566 AscGetEisaChipCfg(
9567                      PortAddr iop_base)
9568 {
9569     PortAddr            eisa_cfg_iop;
9570
9571     eisa_cfg_iop = (PortAddr) ASC_GET_EISA_SLOT(iop_base) |
9572       (PortAddr) (ASC_EISA_CFG_IOP_MASK);
9573     return (inpw(eisa_cfg_iop));
9574 }
9575
9576 STATIC uchar __init
9577 AscSetChipScsiID(
9578                     PortAddr iop_base,
9579                     uchar new_host_id
9580 )
9581 {
9582     ushort              cfg_lsw;
9583
9584     if (AscGetChipScsiID(iop_base) == new_host_id) {
9585         return (new_host_id);
9586     }
9587     cfg_lsw = AscGetChipCfgLsw(iop_base);
9588     cfg_lsw &= 0xF8FF;
9589     cfg_lsw |= (ushort) ((new_host_id & ASC_MAX_TID) << 8);
9590     AscSetChipCfgLsw(iop_base, cfg_lsw);
9591     return (AscGetChipScsiID(iop_base));
9592 }
9593
9594 STATIC uchar __init
9595 AscGetChipScsiCtrl(
9596                 PortAddr iop_base)
9597 {
9598     uchar               sc;
9599
9600     AscSetBank(iop_base, 1);
9601     sc = inp(iop_base + IOP_REG_SC);
9602     AscSetBank(iop_base, 0);
9603     return (sc);
9604 }
9605
9606 STATIC uchar __init
9607 AscGetChipVersion(
9608                      PortAddr iop_base,
9609                      ushort bus_type
9610 )
9611 {
9612     if ((bus_type & ASC_IS_EISA) != 0) {
9613         PortAddr            eisa_iop;
9614         uchar               revision;
9615         eisa_iop = (PortAddr) ASC_GET_EISA_SLOT(iop_base) |
9616           (PortAddr) ASC_EISA_REV_IOP_MASK;
9617         revision = inp(eisa_iop);
9618         return ((uchar) ((ASC_CHIP_MIN_VER_EISA - 1) + revision));
9619     }
9620     return (AscGetChipVerNo(iop_base));
9621 }
9622
9623 STATIC ushort __init
9624 AscGetChipBusType(
9625                      PortAddr iop_base)
9626 {
9627     ushort              chip_ver;
9628
9629     chip_ver = AscGetChipVerNo(iop_base);
9630     if (
9631            (chip_ver >= ASC_CHIP_MIN_VER_VL)
9632            && (chip_ver <= ASC_CHIP_MAX_VER_VL)
9633 ) {
9634         if (
9635                ((iop_base & 0x0C30) == 0x0C30)
9636                || ((iop_base & 0x0C50) == 0x0C50)
9637 ) {
9638             return (ASC_IS_EISA);
9639         }
9640         return (ASC_IS_VL);
9641     }
9642     if ((chip_ver >= ASC_CHIP_MIN_VER_ISA) &&
9643         (chip_ver <= ASC_CHIP_MAX_VER_ISA)) {
9644         if (chip_ver >= ASC_CHIP_MIN_VER_ISA_PNP) {
9645             return (ASC_IS_ISAPNP);
9646         }
9647         return (ASC_IS_ISA);
9648     } else if ((chip_ver >= ASC_CHIP_MIN_VER_PCI) &&
9649                (chip_ver <= ASC_CHIP_MAX_VER_PCI)) {
9650         return (ASC_IS_PCI);
9651     }
9652     return (0);
9653 }
9654
9655 STATIC ASC_DCNT
9656 AscLoadMicroCode(
9657                     PortAddr iop_base,
9658                     ushort s_addr,
9659                     uchar *mcode_buf,
9660                     ushort mcode_size
9661 )
9662 {
9663     ASC_DCNT            chksum;
9664     ushort              mcode_word_size;
9665     ushort              mcode_chksum;
9666
9667     /* Write the microcode buffer starting at LRAM address 0. */
9668     mcode_word_size = (ushort) (mcode_size >> 1);
9669     AscMemWordSetLram(iop_base, s_addr, 0, mcode_word_size);
9670     AscMemWordCopyPtrToLram(iop_base, s_addr, mcode_buf, mcode_word_size);
9671
9672     chksum = AscMemSumLramWord(iop_base, s_addr, mcode_word_size);
9673     ASC_DBG1(1, "AscLoadMicroCode: chksum 0x%lx\n", (ulong) chksum);
9674     mcode_chksum = (ushort) AscMemSumLramWord(iop_base,
9675           (ushort) ASC_CODE_SEC_BEG,
9676           (ushort) ((mcode_size - s_addr - (ushort) ASC_CODE_SEC_BEG) / 2));
9677     ASC_DBG1(1, "AscLoadMicroCode: mcode_chksum 0x%lx\n",
9678         (ulong) mcode_chksum);
9679     AscWriteLramWord(iop_base, ASCV_MCODE_CHKSUM_W, mcode_chksum);
9680     AscWriteLramWord(iop_base, ASCV_MCODE_SIZE_W, mcode_size);
9681     return (chksum);
9682 }
9683
9684 STATIC int
9685 AscFindSignature(
9686                     PortAddr iop_base
9687 )
9688 {
9689     ushort              sig_word;
9690
9691     ASC_DBG2(1, "AscFindSignature: AscGetChipSignatureByte(0x%x) 0x%x\n",
9692         iop_base, AscGetChipSignatureByte(iop_base));
9693     if (AscGetChipSignatureByte(iop_base) == (uchar) ASC_1000_ID1B) {
9694         ASC_DBG2(1, "AscFindSignature: AscGetChipSignatureWord(0x%x) 0x%x\n",
9695             iop_base, AscGetChipSignatureWord(iop_base));
9696         sig_word = AscGetChipSignatureWord(iop_base);
9697         if ((sig_word == (ushort) ASC_1000_ID0W) ||
9698             (sig_word == (ushort) ASC_1000_ID0W_FIX)) {
9699             return (1);
9700         }
9701     }
9702     return (0);
9703 }
9704
9705 STATIC PortAddr _asc_def_iop_base[ASC_IOADR_TABLE_MAX_IX] __initdata =
9706 {
9707     0x100, ASC_IOADR_1, 0x120, ASC_IOADR_2, 0x140, ASC_IOADR_3, ASC_IOADR_4,
9708     ASC_IOADR_5, ASC_IOADR_6, ASC_IOADR_7, ASC_IOADR_8
9709 };
9710
9711 #ifdef CONFIG_ISA
9712 STATIC uchar _isa_pnp_inited __initdata = 0;
9713
9714 STATIC PortAddr __init
9715 AscSearchIOPortAddr(
9716                        PortAddr iop_beg,
9717                        ushort bus_type)
9718 {
9719     if (bus_type & ASC_IS_VL) {
9720         while ((iop_beg = AscSearchIOPortAddr11(iop_beg)) != 0) {
9721             if (AscGetChipVersion(iop_beg, bus_type) <= ASC_CHIP_MAX_VER_VL) {
9722                 return (iop_beg);
9723             }
9724         }
9725         return (0);
9726     }
9727     if (bus_type & ASC_IS_ISA) {
9728         if (_isa_pnp_inited == 0) {
9729             AscSetISAPNPWaitForKey();
9730             _isa_pnp_inited++;
9731         }
9732         while ((iop_beg = AscSearchIOPortAddr11(iop_beg)) != 0) {
9733             if ((AscGetChipVersion(iop_beg, bus_type) & ASC_CHIP_VER_ISA_BIT) != 0) {
9734                 return (iop_beg);
9735             }
9736         }
9737         return (0);
9738     }
9739     if (bus_type & ASC_IS_EISA) {
9740         if ((iop_beg = AscSearchIOPortAddrEISA(iop_beg)) != 0) {
9741             return (iop_beg);
9742         }
9743         return (0);
9744     }
9745     return (0);
9746 }
9747
9748 STATIC PortAddr __init
9749 AscSearchIOPortAddr11(
9750                          PortAddr s_addr
9751 )
9752 {
9753     int                 i;
9754     PortAddr            iop_base;
9755
9756     for (i = 0; i < ASC_IOADR_TABLE_MAX_IX; i++) {
9757         if (_asc_def_iop_base[i] > s_addr) {
9758             break;
9759         }
9760     }
9761     for (; i < ASC_IOADR_TABLE_MAX_IX; i++) {
9762         iop_base = _asc_def_iop_base[i];
9763         if (check_region(iop_base, ASC_IOADR_GAP) != 0) {
9764             ASC_DBG1(1,
9765                "AscSearchIOPortAddr11: check_region() failed I/O port 0x%x\n",
9766                      iop_base);
9767             continue;
9768         }
9769         ASC_DBG1(1, "AscSearchIOPortAddr11: probing I/O port 0x%x\n", iop_base);
9770         if (AscFindSignature(iop_base)) {
9771             return (iop_base);
9772         }
9773     }
9774     return (0);
9775 }
9776
9777 STATIC void __init
9778 AscSetISAPNPWaitForKey(void)
9779 {
9780     outp(ASC_ISA_PNP_PORT_ADDR, 0x02);
9781     outp(ASC_ISA_PNP_PORT_WRITE, 0x02);
9782     return;
9783 }
9784 #endif /* CONFIG_ISA */
9785
9786 STATIC void __init
9787 AscToggleIRQAct(
9788                    PortAddr iop_base
9789 )
9790 {
9791     AscSetChipStatus(iop_base, CIW_IRQ_ACT);
9792     AscSetChipStatus(iop_base, 0);
9793     return;
9794 }
9795
9796 STATIC uchar __init
9797 AscGetChipIRQ(
9798                  PortAddr iop_base,
9799                  ushort bus_type)
9800 {
9801     ushort              cfg_lsw;
9802     uchar               chip_irq;
9803
9804     if ((bus_type & ASC_IS_EISA) != 0) {
9805         cfg_lsw = AscGetEisaChipCfg(iop_base);
9806         chip_irq = (uchar) (((cfg_lsw >> 8) & 0x07) + 10);
9807         if ((chip_irq == 13) || (chip_irq > 15)) {
9808             return (0);
9809         }
9810         return (chip_irq);
9811     }
9812     if ((bus_type & ASC_IS_VL) != 0) {
9813         cfg_lsw = AscGetChipCfgLsw(iop_base);
9814         chip_irq = (uchar) (((cfg_lsw >> 2) & 0x07));
9815         if ((chip_irq == 0) ||
9816             (chip_irq == 4) ||
9817             (chip_irq == 7)) {
9818             return (0);
9819         }
9820         return ((uchar) (chip_irq + (ASC_MIN_IRQ_NO - 1)));
9821     }
9822     cfg_lsw = AscGetChipCfgLsw(iop_base);
9823     chip_irq = (uchar) (((cfg_lsw >> 2) & 0x03));
9824     if (chip_irq == 3)
9825         chip_irq += (uchar) 2;
9826     return ((uchar) (chip_irq + ASC_MIN_IRQ_NO));
9827 }
9828
9829 STATIC uchar __init
9830 AscSetChipIRQ(
9831                  PortAddr iop_base,
9832                  uchar irq_no,
9833                  ushort bus_type)
9834 {
9835     ushort              cfg_lsw;
9836
9837     if ((bus_type & ASC_IS_VL) != 0) {
9838         if (irq_no != 0) {
9839             if ((irq_no < ASC_MIN_IRQ_NO) || (irq_no > ASC_MAX_IRQ_NO)) {
9840                 irq_no = 0;
9841             } else {
9842                 irq_no -= (uchar) ((ASC_MIN_IRQ_NO - 1));
9843             }
9844         }
9845         cfg_lsw = (ushort) (AscGetChipCfgLsw(iop_base) & 0xFFE3);
9846         cfg_lsw |= (ushort) 0x0010;
9847         AscSetChipCfgLsw(iop_base, cfg_lsw);
9848         AscToggleIRQAct(iop_base);
9849         cfg_lsw = (ushort) (AscGetChipCfgLsw(iop_base) & 0xFFE0);
9850         cfg_lsw |= (ushort) ((irq_no & 0x07) << 2);
9851         AscSetChipCfgLsw(iop_base, cfg_lsw);
9852         AscToggleIRQAct(iop_base);
9853         return (AscGetChipIRQ(iop_base, bus_type));
9854     }
9855     if ((bus_type & (ASC_IS_ISA)) != 0) {
9856         if (irq_no == 15)
9857             irq_no -= (uchar) 2;
9858         irq_no -= (uchar) ASC_MIN_IRQ_NO;
9859         cfg_lsw = (ushort) (AscGetChipCfgLsw(iop_base) & 0xFFF3);
9860         cfg_lsw |= (ushort) ((irq_no & 0x03) << 2);
9861         AscSetChipCfgLsw(iop_base, cfg_lsw);
9862         return (AscGetChipIRQ(iop_base, bus_type));
9863     }
9864     return (0);
9865 }
9866
9867 #ifdef CONFIG_ISA
9868 STATIC void __init
9869 AscEnableIsaDma(
9870                    uchar dma_channel)
9871 {
9872     if (dma_channel < 4) {
9873         outp(0x000B, (ushort) (0xC0 | dma_channel));
9874         outp(0x000A, dma_channel);
9875     } else if (dma_channel < 8) {
9876         outp(0x00D6, (ushort) (0xC0 | (dma_channel - 4)));
9877         outp(0x00D4, (ushort) (dma_channel - 4));
9878     }
9879     return;
9880 }
9881 #endif /* CONFIG_ISA */
9882
9883 STATIC int
9884 AscIsrChipHalted(
9885                     ASC_DVC_VAR *asc_dvc
9886 )
9887 {
9888     EXT_MSG             ext_msg;
9889     EXT_MSG             out_msg;
9890     ushort              halt_q_addr;
9891     int                 sdtr_accept;
9892     ushort              int_halt_code;
9893     ASC_SCSI_BIT_ID_TYPE scsi_busy;
9894     ASC_SCSI_BIT_ID_TYPE target_id;
9895     PortAddr            iop_base;
9896     uchar               tag_code;
9897     uchar               q_status;
9898     uchar               halt_qp;
9899     uchar               sdtr_data;
9900     uchar               target_ix;
9901     uchar               q_cntl, tid_no;
9902     uchar               cur_dvc_qng;
9903     uchar               asyn_sdtr;
9904     uchar               scsi_status;
9905     asc_board_t         *boardp;
9906
9907     ASC_ASSERT(asc_dvc->drv_ptr != NULL);
9908     boardp = asc_dvc->drv_ptr;
9909
9910     iop_base = asc_dvc->iop_base;
9911     int_halt_code = AscReadLramWord(iop_base, ASCV_HALTCODE_W);
9912
9913     halt_qp = AscReadLramByte(iop_base, ASCV_CURCDB_B);
9914     halt_q_addr = ASC_QNO_TO_QADDR(halt_qp);
9915     target_ix = AscReadLramByte(iop_base,
9916                    (ushort) (halt_q_addr + (ushort) ASC_SCSIQ_B_TARGET_IX));
9917     q_cntl = AscReadLramByte(iop_base,
9918                         (ushort) (halt_q_addr + (ushort) ASC_SCSIQ_B_CNTL));
9919     tid_no = ASC_TIX_TO_TID(target_ix);
9920     target_id = (uchar) ASC_TID_TO_TARGET_ID(tid_no);
9921     if (asc_dvc->pci_fix_asyn_xfer & target_id) {
9922         asyn_sdtr = ASYN_SDTR_DATA_FIX_PCI_REV_AB;
9923     } else {
9924         asyn_sdtr = 0;
9925     }
9926     if (int_halt_code == ASC_HALT_DISABLE_ASYN_USE_SYN_FIX) {
9927         if (asc_dvc->pci_fix_asyn_xfer & target_id) {
9928             AscSetChipSDTR(iop_base, 0, tid_no);
9929             boardp->sdtr_data[tid_no] = 0;
9930         }
9931         AscWriteLramWord(iop_base, ASCV_HALTCODE_W, 0);
9932         return (0);
9933     } else if (int_halt_code == ASC_HALT_ENABLE_ASYN_USE_SYN_FIX) {
9934         if (asc_dvc->pci_fix_asyn_xfer & target_id) {
9935             AscSetChipSDTR(iop_base, asyn_sdtr, tid_no);
9936             boardp->sdtr_data[tid_no] = asyn_sdtr;
9937         }
9938         AscWriteLramWord(iop_base, ASCV_HALTCODE_W, 0);
9939         return (0);
9940     } else if (int_halt_code == ASC_HALT_EXTMSG_IN) {
9941
9942         AscMemWordCopyPtrFromLram(iop_base,
9943                                ASCV_MSGIN_BEG,
9944                                (uchar *) &ext_msg,
9945                                sizeof(EXT_MSG) >> 1);
9946
9947         if (ext_msg.msg_type == MS_EXTEND &&
9948             ext_msg.msg_req == MS_SDTR_CODE &&
9949             ext_msg.msg_len == MS_SDTR_LEN) {
9950             sdtr_accept = TRUE;
9951             if ((ext_msg.req_ack_offset > ASC_SYN_MAX_OFFSET)) {
9952
9953                 sdtr_accept = FALSE;
9954                 ext_msg.req_ack_offset = ASC_SYN_MAX_OFFSET;
9955             }
9956             if ((ext_msg.xfer_period <
9957                  asc_dvc->sdtr_period_tbl[asc_dvc->host_init_sdtr_index]) ||
9958                 (ext_msg.xfer_period >
9959                  asc_dvc->sdtr_period_tbl[asc_dvc->max_sdtr_index])) {
9960                 sdtr_accept = FALSE;
9961                 ext_msg.xfer_period =
9962                     asc_dvc->sdtr_period_tbl[asc_dvc->host_init_sdtr_index];
9963             }
9964             if (sdtr_accept) {
9965                 sdtr_data = AscCalSDTRData(asc_dvc, ext_msg.xfer_period,
9966                                            ext_msg.req_ack_offset);
9967                 if ((sdtr_data == 0xFF)) {
9968
9969                     q_cntl |= QC_MSG_OUT;
9970                     asc_dvc->init_sdtr &= ~target_id;
9971                     asc_dvc->sdtr_done &= ~target_id;
9972                     AscSetChipSDTR(iop_base, asyn_sdtr, tid_no);
9973                     boardp->sdtr_data[tid_no] = asyn_sdtr;
9974                 }
9975             }
9976             if (ext_msg.req_ack_offset == 0) {
9977
9978                 q_cntl &= ~QC_MSG_OUT;
9979                 asc_dvc->init_sdtr &= ~target_id;
9980                 asc_dvc->sdtr_done &= ~target_id;
9981                 AscSetChipSDTR(iop_base, asyn_sdtr, tid_no);
9982             } else {
9983                 if (sdtr_accept && (q_cntl & QC_MSG_OUT)) {
9984
9985                     q_cntl &= ~QC_MSG_OUT;
9986                     asc_dvc->sdtr_done |= target_id;
9987                     asc_dvc->init_sdtr |= target_id;
9988                     asc_dvc->pci_fix_asyn_xfer &= ~target_id;
9989                     sdtr_data = AscCalSDTRData(asc_dvc, ext_msg.xfer_period,
9990                                                ext_msg.req_ack_offset);
9991                     AscSetChipSDTR(iop_base, sdtr_data, tid_no);
9992                     boardp->sdtr_data[tid_no] = sdtr_data;
9993                 } else {
9994
9995                     q_cntl |= QC_MSG_OUT;
9996                     AscMsgOutSDTR(asc_dvc,
9997                                   ext_msg.xfer_period,
9998                                   ext_msg.req_ack_offset);
9999                     asc_dvc->pci_fix_asyn_xfer &= ~target_id;
10000                     sdtr_data = AscCalSDTRData(asc_dvc, ext_msg.xfer_period,
10001                                                ext_msg.req_ack_offset);
10002                     AscSetChipSDTR(iop_base, sdtr_data, tid_no);
10003                     boardp->sdtr_data[tid_no] = sdtr_data;
10004                     asc_dvc->sdtr_done |= target_id;
10005                     asc_dvc->init_sdtr |= target_id;
10006                 }
10007             }
10008
10009             AscWriteLramByte(iop_base,
10010                          (ushort) (halt_q_addr + (ushort) ASC_SCSIQ_B_CNTL),
10011                              q_cntl);
10012             AscWriteLramWord(iop_base, ASCV_HALTCODE_W, 0);
10013             return (0);
10014         } else if (ext_msg.msg_type == MS_EXTEND &&
10015                    ext_msg.msg_req == MS_WDTR_CODE &&
10016                    ext_msg.msg_len == MS_WDTR_LEN) {
10017
10018             ext_msg.wdtr_width = 0;
10019             AscMemWordCopyPtrToLram(iop_base,
10020                                  ASCV_MSGOUT_BEG,
10021                                  (uchar *) &ext_msg,
10022                                  sizeof(EXT_MSG) >> 1);
10023             q_cntl |= QC_MSG_OUT;
10024             AscWriteLramByte(iop_base,
10025                          (ushort) (halt_q_addr + (ushort) ASC_SCSIQ_B_CNTL),
10026                              q_cntl);
10027             AscWriteLramWord(iop_base, ASCV_HALTCODE_W, 0);
10028             return (0);
10029         } else {
10030
10031             ext_msg.msg_type = MESSAGE_REJECT;
10032             AscMemWordCopyPtrToLram(iop_base,
10033                                  ASCV_MSGOUT_BEG,
10034                                  (uchar *) &ext_msg,
10035                                  sizeof(EXT_MSG) >> 1);
10036             q_cntl |= QC_MSG_OUT;
10037             AscWriteLramByte(iop_base,
10038                          (ushort) (halt_q_addr + (ushort) ASC_SCSIQ_B_CNTL),
10039                              q_cntl);
10040             AscWriteLramWord(iop_base, ASCV_HALTCODE_W, 0);
10041             return (0);
10042         }
10043     } else if (int_halt_code == ASC_HALT_CHK_CONDITION) {
10044
10045         q_cntl |= QC_REQ_SENSE;
10046
10047         if ((asc_dvc->init_sdtr & target_id) != 0) {
10048
10049             asc_dvc->sdtr_done &= ~target_id;
10050
10051             sdtr_data = AscGetMCodeInitSDTRAtID(iop_base, tid_no);
10052             q_cntl |= QC_MSG_OUT;
10053             AscMsgOutSDTR(asc_dvc,
10054                           asc_dvc->sdtr_period_tbl[(sdtr_data >> 4) &
10055                            (uchar) (asc_dvc->max_sdtr_index - 1)],
10056                           (uchar) (sdtr_data & (uchar) ASC_SYN_MAX_OFFSET));
10057         }
10058
10059         AscWriteLramByte(iop_base,
10060                          (ushort) (halt_q_addr + (ushort) ASC_SCSIQ_B_CNTL),
10061                          q_cntl);
10062
10063         tag_code = AscReadLramByte(iop_base,
10064                     (ushort) (halt_q_addr + (ushort) ASC_SCSIQ_B_TAG_CODE));
10065         tag_code &= 0xDC;
10066         if (
10067                (asc_dvc->pci_fix_asyn_xfer & target_id)
10068                && !(asc_dvc->pci_fix_asyn_xfer_always & target_id)
10069 ) {
10070
10071             tag_code |= (ASC_TAG_FLAG_DISABLE_DISCONNECT
10072                          | ASC_TAG_FLAG_DISABLE_ASYN_USE_SYN_FIX);
10073
10074         }
10075         AscWriteLramByte(iop_base,
10076                      (ushort) (halt_q_addr + (ushort) ASC_SCSIQ_B_TAG_CODE),
10077                          tag_code);
10078
10079         q_status = AscReadLramByte(iop_base,
10080                       (ushort) (halt_q_addr + (ushort) ASC_SCSIQ_B_STATUS));
10081         q_status |= (QS_READY | QS_BUSY);
10082         AscWriteLramByte(iop_base,
10083                        (ushort) (halt_q_addr + (ushort) ASC_SCSIQ_B_STATUS),
10084                          q_status);
10085
10086         scsi_busy = AscReadLramByte(iop_base,
10087                                     (ushort) ASCV_SCSIBUSY_B);
10088         scsi_busy &= ~target_id;
10089         AscWriteLramByte(iop_base, (ushort) ASCV_SCSIBUSY_B, scsi_busy);
10090
10091         AscWriteLramWord(iop_base, ASCV_HALTCODE_W, 0);
10092         return (0);
10093     } else if (int_halt_code == ASC_HALT_SDTR_REJECTED) {
10094
10095         AscMemWordCopyPtrFromLram(iop_base,
10096                                ASCV_MSGOUT_BEG,
10097                                (uchar *) &out_msg,
10098                                sizeof(EXT_MSG) >> 1);
10099
10100         if ((out_msg.msg_type == MS_EXTEND) &&
10101             (out_msg.msg_len == MS_SDTR_LEN) &&
10102             (out_msg.msg_req == MS_SDTR_CODE)) {
10103
10104             asc_dvc->init_sdtr &= ~target_id;
10105             asc_dvc->sdtr_done &= ~target_id;
10106             AscSetChipSDTR(iop_base, asyn_sdtr, tid_no);
10107             boardp->sdtr_data[tid_no] = asyn_sdtr;
10108         }
10109         q_cntl &= ~QC_MSG_OUT;
10110         AscWriteLramByte(iop_base,
10111                          (ushort) (halt_q_addr + (ushort) ASC_SCSIQ_B_CNTL),
10112                          q_cntl);
10113         AscWriteLramWord(iop_base, ASCV_HALTCODE_W, 0);
10114         return (0);
10115     } else if (int_halt_code == ASC_HALT_SS_QUEUE_FULL) {
10116
10117         scsi_status = AscReadLramByte(iop_base,
10118           (ushort) ((ushort) halt_q_addr + (ushort) ASC_SCSIQ_SCSI_STATUS));
10119         cur_dvc_qng = AscReadLramByte(iop_base,
10120                      (ushort) ((ushort) ASC_QADR_BEG + (ushort) target_ix));
10121         if ((cur_dvc_qng > 0) &&
10122             (asc_dvc->cur_dvc_qng[tid_no] > 0)) {
10123
10124             scsi_busy = AscReadLramByte(iop_base,
10125                                         (ushort) ASCV_SCSIBUSY_B);
10126             scsi_busy |= target_id;
10127             AscWriteLramByte(iop_base,
10128                              (ushort) ASCV_SCSIBUSY_B, scsi_busy);
10129             asc_dvc->queue_full_or_busy |= target_id;
10130
10131             if (scsi_status == SAM_STAT_TASK_SET_FULL) {
10132                 if (cur_dvc_qng > ASC_MIN_TAGGED_CMD) {
10133                     cur_dvc_qng -= 1;
10134                     asc_dvc->max_dvc_qng[tid_no] = cur_dvc_qng;
10135
10136                     AscWriteLramByte(iop_base,
10137                           (ushort) ((ushort) ASCV_MAX_DVC_QNG_BEG +
10138                            (ushort) tid_no),
10139                           cur_dvc_qng);
10140
10141                     /*
10142                      * Set the device queue depth to the number of
10143                      * active requests when the QUEUE FULL condition
10144                      * was encountered.
10145                      */
10146                     boardp->queue_full |= target_id;
10147                     boardp->queue_full_cnt[tid_no] = cur_dvc_qng;
10148                 }
10149             }
10150         }
10151         AscWriteLramWord(iop_base, ASCV_HALTCODE_W, 0);
10152         return (0);
10153     }
10154 #if CC_VERY_LONG_SG_LIST
10155     else if (int_halt_code == ASC_HALT_HOST_COPY_SG_LIST_TO_RISC)
10156     {
10157         uchar              q_no;
10158         ushort             q_addr;
10159         uchar              sg_wk_q_no;
10160         uchar              first_sg_wk_q_no;
10161         ASC_SCSI_Q         *scsiq; /* Ptr to driver request. */
10162         ASC_SG_HEAD        *sg_head; /* Ptr to driver SG request. */
10163         ASC_SG_LIST_Q      scsi_sg_q; /* Structure written to queue. */
10164         ushort             sg_list_dwords;
10165         ushort             sg_entry_cnt;
10166         uchar              next_qp;
10167         int                i;
10168
10169         q_no = AscReadLramByte(iop_base, (ushort) ASCV_REQ_SG_LIST_QP);
10170         if (q_no == ASC_QLINK_END)
10171         {
10172             return(0);
10173         }
10174
10175         q_addr = ASC_QNO_TO_QADDR(q_no);
10176
10177         /*
10178          * Convert the request's SRB pointer to a host ASC_SCSI_REQ
10179          * structure pointer using a macro provided by the driver.
10180          * The ASC_SCSI_REQ pointer provides a pointer to the
10181          * host ASC_SG_HEAD structure.
10182          */
10183         /* Read request's SRB pointer. */
10184         scsiq = (ASC_SCSI_Q *)
10185            ASC_SRB2SCSIQ(
10186                ASC_U32_TO_VADDR(AscReadLramDWord(iop_base,
10187                (ushort) (q_addr + ASC_SCSIQ_D_SRBPTR))));
10188
10189         /*
10190          * Get request's first and working SG queue.
10191          */
10192         sg_wk_q_no = AscReadLramByte(iop_base,
10193             (ushort) (q_addr + ASC_SCSIQ_B_SG_WK_QP));
10194
10195         first_sg_wk_q_no = AscReadLramByte(iop_base,
10196             (ushort) (q_addr + ASC_SCSIQ_B_FIRST_SG_WK_QP));
10197
10198         /*
10199          * Reset request's working SG queue back to the
10200          * first SG queue.
10201          */
10202         AscWriteLramByte(iop_base,
10203             (ushort) (q_addr + (ushort) ASC_SCSIQ_B_SG_WK_QP),
10204             first_sg_wk_q_no);
10205
10206         sg_head = scsiq->sg_head;
10207
10208         /*
10209          * Set sg_entry_cnt to the number of SG elements
10210          * that will be completed on this interrupt.
10211          *
10212          * Note: The allocated SG queues contain ASC_MAX_SG_LIST - 1
10213          * SG elements. The data_cnt and data_addr fields which
10214          * add 1 to the SG element capacity are not used when
10215          * restarting SG handling after a halt.
10216          */
10217         if (scsiq->remain_sg_entry_cnt > (ASC_MAX_SG_LIST - 1))
10218         {
10219              sg_entry_cnt = ASC_MAX_SG_LIST - 1;
10220
10221              /*
10222               * Keep track of remaining number of SG elements that will
10223               * need to be handled on the next interrupt.
10224               */
10225              scsiq->remain_sg_entry_cnt -= (ASC_MAX_SG_LIST - 1);
10226         } else
10227         {
10228              sg_entry_cnt = scsiq->remain_sg_entry_cnt;
10229              scsiq->remain_sg_entry_cnt = 0;
10230         }
10231
10232         /*
10233          * Copy SG elements into the list of allocated SG queues.
10234          *
10235          * Last index completed is saved in scsiq->next_sg_index.
10236          */
10237         next_qp = first_sg_wk_q_no;
10238         q_addr = ASC_QNO_TO_QADDR(next_qp);
10239         scsi_sg_q.sg_head_qp = q_no;
10240         scsi_sg_q.cntl = QCSG_SG_XFER_LIST;
10241         for( i = 0; i < sg_head->queue_cnt; i++)
10242         {
10243              scsi_sg_q.seq_no = i + 1;
10244              if (sg_entry_cnt > ASC_SG_LIST_PER_Q)
10245              {
10246                  sg_list_dwords = (uchar) (ASC_SG_LIST_PER_Q * 2);
10247                  sg_entry_cnt -= ASC_SG_LIST_PER_Q;
10248                  /*
10249                   * After very first SG queue RISC FW uses next
10250                   * SG queue first element then checks sg_list_cnt
10251                   * against zero and then decrements, so set
10252                   * sg_list_cnt 1 less than number of SG elements
10253                   * in each SG queue.
10254                   */
10255                  scsi_sg_q.sg_list_cnt = ASC_SG_LIST_PER_Q - 1;
10256                  scsi_sg_q.sg_cur_list_cnt = ASC_SG_LIST_PER_Q - 1;
10257              } else {
10258                  /*
10259                   * This is the last SG queue in the list of
10260                   * allocated SG queues. If there are more
10261                   * SG elements than will fit in the allocated
10262                   * queues, then set the QCSG_SG_XFER_MORE flag.
10263                   */
10264                  if (scsiq->remain_sg_entry_cnt != 0)
10265                  {
10266                      scsi_sg_q.cntl |= QCSG_SG_XFER_MORE;
10267                  } else
10268                  {
10269                      scsi_sg_q.cntl |= QCSG_SG_XFER_END;
10270                  }
10271                  /* equals sg_entry_cnt * 2 */
10272                  sg_list_dwords = sg_entry_cnt << 1;
10273                  scsi_sg_q.sg_list_cnt = sg_entry_cnt - 1;
10274                  scsi_sg_q.sg_cur_list_cnt = sg_entry_cnt - 1;
10275                  sg_entry_cnt = 0;
10276              }
10277
10278              scsi_sg_q.q_no = next_qp;
10279              AscMemWordCopyPtrToLram(iop_base,
10280                           q_addr + ASC_SCSIQ_SGHD_CPY_BEG,
10281                           (uchar *) &scsi_sg_q,
10282                           sizeof(ASC_SG_LIST_Q) >> 1);
10283
10284              AscMemDWordCopyPtrToLram(iop_base,
10285                           q_addr + ASC_SGQ_LIST_BEG,
10286                           (uchar *) &sg_head->sg_list[scsiq->next_sg_index],
10287                           sg_list_dwords);
10288
10289              scsiq->next_sg_index += ASC_SG_LIST_PER_Q;
10290
10291              /*
10292               * If the just completed SG queue contained the
10293               * last SG element, then no more SG queues need
10294               * to be written.
10295               */
10296              if (scsi_sg_q.cntl & QCSG_SG_XFER_END)
10297              {
10298                  break;
10299              }
10300
10301              next_qp = AscReadLramByte( iop_base,
10302                           ( ushort )( q_addr+ASC_SCSIQ_B_FWD ) );
10303              q_addr = ASC_QNO_TO_QADDR( next_qp );
10304         }
10305
10306         /*
10307          * Clear the halt condition so the RISC will be restarted
10308          * after the return.
10309          */
10310         AscWriteLramWord(iop_base, ASCV_HALTCODE_W, 0);
10311         return(0);
10312     }
10313 #endif /* CC_VERY_LONG_SG_LIST */
10314     return (0);
10315 }
10316
10317 STATIC uchar
10318 _AscCopyLramScsiDoneQ(
10319                          PortAddr iop_base,
10320                          ushort q_addr,
10321                          ASC_QDONE_INFO * scsiq,
10322                          ASC_DCNT max_dma_count
10323 )
10324 {
10325     ushort              _val;
10326     uchar               sg_queue_cnt;
10327
10328     DvcGetQinfo(iop_base,
10329                 q_addr + ASC_SCSIQ_DONE_INFO_BEG,
10330                 (uchar *) scsiq,
10331                 (sizeof (ASC_SCSIQ_2) + sizeof (ASC_SCSIQ_3)) / 2);
10332
10333     _val = AscReadLramWord(iop_base,
10334                            (ushort) (q_addr + (ushort) ASC_SCSIQ_B_STATUS));
10335     scsiq->q_status = (uchar) _val;
10336     scsiq->q_no = (uchar) (_val >> 8);
10337     _val = AscReadLramWord(iop_base,
10338                            (ushort) (q_addr + (ushort) ASC_SCSIQ_B_CNTL));
10339     scsiq->cntl = (uchar) _val;
10340     sg_queue_cnt = (uchar) (_val >> 8);
10341     _val = AscReadLramWord(iop_base,
10342                         (ushort) (q_addr + (ushort) ASC_SCSIQ_B_SENSE_LEN));
10343     scsiq->sense_len = (uchar) _val;
10344     scsiq->extra_bytes = (uchar) (_val >> 8);
10345
10346     /*
10347      * Read high word of remain bytes from alternate location.
10348      */
10349     scsiq->remain_bytes = (((ADV_DCNT) AscReadLramWord( iop_base,
10350                       (ushort) (q_addr+ (ushort) ASC_SCSIQ_W_ALT_DC1))) << 16);
10351     /*
10352      * Read low word of remain bytes from original location.
10353      */
10354     scsiq->remain_bytes += AscReadLramWord(iop_base,
10355         (ushort) (q_addr+ (ushort) ASC_SCSIQ_DW_REMAIN_XFER_CNT));
10356
10357     scsiq->remain_bytes &= max_dma_count;
10358     return (sg_queue_cnt);
10359 }
10360
10361 STATIC int
10362 AscIsrQDone(
10363                ASC_DVC_VAR *asc_dvc
10364 )
10365 {
10366     uchar               next_qp;
10367     uchar               n_q_used;
10368     uchar               sg_list_qp;
10369     uchar               sg_queue_cnt;
10370     uchar               q_cnt;
10371     uchar               done_q_tail;
10372     uchar               tid_no;
10373     ASC_SCSI_BIT_ID_TYPE scsi_busy;
10374     ASC_SCSI_BIT_ID_TYPE target_id;
10375     PortAddr            iop_base;
10376     ushort              q_addr;
10377     ushort              sg_q_addr;
10378     uchar               cur_target_qng;
10379     ASC_QDONE_INFO      scsiq_buf;
10380     ASC_QDONE_INFO *scsiq;
10381     int                 false_overrun;
10382     ASC_ISR_CALLBACK    asc_isr_callback;
10383
10384     iop_base = asc_dvc->iop_base;
10385     asc_isr_callback = asc_dvc->isr_callback;
10386     n_q_used = 1;
10387     scsiq = (ASC_QDONE_INFO *) & scsiq_buf;
10388     done_q_tail = (uchar) AscGetVarDoneQTail(iop_base);
10389     q_addr = ASC_QNO_TO_QADDR(done_q_tail);
10390     next_qp = AscReadLramByte(iop_base,
10391                               (ushort) (q_addr + (ushort) ASC_SCSIQ_B_FWD));
10392     if (next_qp != ASC_QLINK_END) {
10393         AscPutVarDoneQTail(iop_base, next_qp);
10394         q_addr = ASC_QNO_TO_QADDR(next_qp);
10395         sg_queue_cnt = _AscCopyLramScsiDoneQ(iop_base, q_addr, scsiq,
10396             asc_dvc->max_dma_count);
10397         AscWriteLramByte(iop_base,
10398                          (ushort) (q_addr + (ushort) ASC_SCSIQ_B_STATUS),
10399              (uchar) (scsiq->q_status & (uchar) ~ (QS_READY | QS_ABORTED)));
10400         tid_no = ASC_TIX_TO_TID(scsiq->d2.target_ix);
10401         target_id = ASC_TIX_TO_TARGET_ID(scsiq->d2.target_ix);
10402         if ((scsiq->cntl & QC_SG_HEAD) != 0) {
10403             sg_q_addr = q_addr;
10404             sg_list_qp = next_qp;
10405             for (q_cnt = 0; q_cnt < sg_queue_cnt; q_cnt++) {
10406                 sg_list_qp = AscReadLramByte(iop_base,
10407                            (ushort) (sg_q_addr + (ushort) ASC_SCSIQ_B_FWD));
10408                 sg_q_addr = ASC_QNO_TO_QADDR(sg_list_qp);
10409                 if (sg_list_qp == ASC_QLINK_END) {
10410                     AscSetLibErrorCode(asc_dvc, ASCQ_ERR_SG_Q_LINKS);
10411                     scsiq->d3.done_stat = QD_WITH_ERROR;
10412                     scsiq->d3.host_stat = QHSTA_D_QDONE_SG_LIST_CORRUPTED;
10413                     goto FATAL_ERR_QDONE;
10414                 }
10415                 AscWriteLramByte(iop_base,
10416                          (ushort) (sg_q_addr + (ushort) ASC_SCSIQ_B_STATUS),
10417                                  QS_FREE);
10418             }
10419             n_q_used = sg_queue_cnt + 1;
10420             AscPutVarDoneQTail(iop_base, sg_list_qp);
10421         }
10422         if (asc_dvc->queue_full_or_busy & target_id) {
10423             cur_target_qng = AscReadLramByte(iop_base,
10424             (ushort) ((ushort) ASC_QADR_BEG + (ushort) scsiq->d2.target_ix));
10425             if (cur_target_qng < asc_dvc->max_dvc_qng[tid_no]) {
10426                 scsi_busy = AscReadLramByte(iop_base,
10427                                             (ushort) ASCV_SCSIBUSY_B);
10428                 scsi_busy &= ~target_id;
10429                 AscWriteLramByte(iop_base,
10430                                  (ushort) ASCV_SCSIBUSY_B, scsi_busy);
10431                 asc_dvc->queue_full_or_busy &= ~target_id;
10432             }
10433         }
10434         if (asc_dvc->cur_total_qng >= n_q_used) {
10435             asc_dvc->cur_total_qng -= n_q_used;
10436             if (asc_dvc->cur_dvc_qng[tid_no] != 0) {
10437                 asc_dvc->cur_dvc_qng[tid_no]--;
10438             }
10439         } else {
10440             AscSetLibErrorCode(asc_dvc, ASCQ_ERR_CUR_QNG);
10441             scsiq->d3.done_stat = QD_WITH_ERROR;
10442             goto FATAL_ERR_QDONE;
10443         }
10444         if ((scsiq->d2.srb_ptr == 0UL) ||
10445             ((scsiq->q_status & QS_ABORTED) != 0)) {
10446             return (0x11);
10447         } else if (scsiq->q_status == QS_DONE) {
10448             false_overrun = FALSE;
10449             if (scsiq->extra_bytes != 0) {
10450                 scsiq->remain_bytes += (ADV_DCNT) scsiq->extra_bytes;
10451             }
10452             if (scsiq->d3.done_stat == QD_WITH_ERROR) {
10453                 if (scsiq->d3.host_stat == QHSTA_M_DATA_OVER_RUN) {
10454                     if ((scsiq->cntl & (QC_DATA_IN | QC_DATA_OUT)) == 0) {
10455                         scsiq->d3.done_stat = QD_NO_ERROR;
10456                         scsiq->d3.host_stat = QHSTA_NO_ERROR;
10457                     } else if (false_overrun) {
10458                         scsiq->d3.done_stat = QD_NO_ERROR;
10459                         scsiq->d3.host_stat = QHSTA_NO_ERROR;
10460                     }
10461                 } else if (scsiq->d3.host_stat ==
10462                            QHSTA_M_HUNG_REQ_SCSI_BUS_RESET) {
10463                     AscStopChip(iop_base);
10464                     AscSetChipControl(iop_base,
10465                         (uchar) (CC_SCSI_RESET | CC_HALT));
10466                     DvcDelayNanoSecond(asc_dvc, 60000);
10467                     AscSetChipControl(iop_base, CC_HALT);
10468                     AscSetChipStatus(iop_base, CIW_CLR_SCSI_RESET_INT);
10469                     AscSetChipStatus(iop_base, 0);
10470                     AscSetChipControl(iop_base, 0);
10471                 }
10472             }
10473             if ((scsiq->cntl & QC_NO_CALLBACK) == 0) {
10474                 (*asc_isr_callback) (asc_dvc, scsiq);
10475             } else {
10476                 if ((AscReadLramByte(iop_base,
10477                           (ushort) (q_addr + (ushort) ASC_SCSIQ_CDB_BEG)) ==
10478                      START_STOP)) {
10479                     asc_dvc->unit_not_ready &= ~target_id;
10480                     if (scsiq->d3.done_stat != QD_NO_ERROR) {
10481                         asc_dvc->start_motor &= ~target_id;
10482                     }
10483                 }
10484             }
10485             return (1);
10486         } else {
10487             AscSetLibErrorCode(asc_dvc, ASCQ_ERR_Q_STATUS);
10488           FATAL_ERR_QDONE:
10489             if ((scsiq->cntl & QC_NO_CALLBACK) == 0) {
10490                 (*asc_isr_callback) (asc_dvc, scsiq);
10491             }
10492             return (0x80);
10493         }
10494     }
10495     return (0);
10496 }
10497
10498 STATIC int
10499 AscISR(
10500           ASC_DVC_VAR *asc_dvc
10501 )
10502 {
10503     ASC_CS_TYPE         chipstat;
10504     PortAddr            iop_base;
10505     ushort              saved_ram_addr;
10506     uchar               ctrl_reg;
10507     uchar               saved_ctrl_reg;
10508     int                 int_pending;
10509     int                 status;
10510     uchar               host_flag;
10511
10512     iop_base = asc_dvc->iop_base;
10513     int_pending = FALSE;
10514
10515     if (AscIsIntPending(iop_base) == 0)
10516     {
10517         return int_pending;
10518     }
10519
10520     if (((asc_dvc->init_state & ASC_INIT_STATE_END_LOAD_MC) == 0)
10521         || (asc_dvc->isr_callback == 0)
10522 ) {
10523         return (ERR);
10524     }
10525     if (asc_dvc->in_critical_cnt != 0) {
10526         AscSetLibErrorCode(asc_dvc, ASCQ_ERR_ISR_ON_CRITICAL);
10527         return (ERR);
10528     }
10529     if (asc_dvc->is_in_int) {
10530         AscSetLibErrorCode(asc_dvc, ASCQ_ERR_ISR_RE_ENTRY);
10531         return (ERR);
10532     }
10533     asc_dvc->is_in_int = TRUE;
10534     ctrl_reg = AscGetChipControl(iop_base);
10535     saved_ctrl_reg = ctrl_reg & (~(CC_SCSI_RESET | CC_CHIP_RESET |
10536                                    CC_SINGLE_STEP | CC_DIAG | CC_TEST));
10537     chipstat = AscGetChipStatus(iop_base);
10538     if (chipstat & CSW_SCSI_RESET_LATCH) {
10539         if (!(asc_dvc->bus_type & (ASC_IS_VL | ASC_IS_EISA))) {
10540             int i = 10;
10541             int_pending = TRUE;
10542             asc_dvc->sdtr_done = 0;
10543             saved_ctrl_reg &= (uchar) (~CC_HALT);
10544             while ((AscGetChipStatus(iop_base) & CSW_SCSI_RESET_ACTIVE) &&
10545                    (i-- > 0))
10546             {
10547                   DvcSleepMilliSecond(100);
10548             }
10549             AscSetChipControl(iop_base, (CC_CHIP_RESET | CC_HALT));
10550             AscSetChipControl(iop_base, CC_HALT);
10551             AscSetChipStatus(iop_base, CIW_CLR_SCSI_RESET_INT);
10552             AscSetChipStatus(iop_base, 0);
10553             chipstat = AscGetChipStatus(iop_base);
10554         }
10555     }
10556     saved_ram_addr = AscGetChipLramAddr(iop_base);
10557     host_flag = AscReadLramByte(iop_base,
10558         ASCV_HOST_FLAG_B) & (uchar) (~ASC_HOST_FLAG_IN_ISR);
10559     AscWriteLramByte(iop_base, ASCV_HOST_FLAG_B,
10560                      (uchar) (host_flag | (uchar) ASC_HOST_FLAG_IN_ISR));
10561     if ((chipstat & CSW_INT_PENDING)
10562         || (int_pending)
10563 ) {
10564         AscAckInterrupt(iop_base);
10565         int_pending = TRUE;
10566         if ((chipstat & CSW_HALTED) &&
10567             (ctrl_reg & CC_SINGLE_STEP)) {
10568             if (AscIsrChipHalted(asc_dvc) == ERR) {
10569                 goto ISR_REPORT_QDONE_FATAL_ERROR;
10570             } else {
10571                 saved_ctrl_reg &= (uchar) (~CC_HALT);
10572             }
10573         } else {
10574           ISR_REPORT_QDONE_FATAL_ERROR:
10575             if ((asc_dvc->dvc_cntl & ASC_CNTL_INT_MULTI_Q) != 0) {
10576                 while (((status = AscIsrQDone(asc_dvc)) & 0x01) != 0) {
10577                 }
10578             } else {
10579                 do {
10580                     if ((status = AscIsrQDone(asc_dvc)) == 1) {
10581                         break;
10582                     }
10583                 } while (status == 0x11);
10584             }
10585             if ((status & 0x80) != 0)
10586                 int_pending = ERR;
10587         }
10588     }
10589     AscWriteLramByte(iop_base, ASCV_HOST_FLAG_B, host_flag);
10590     AscSetChipLramAddr(iop_base, saved_ram_addr);
10591     AscSetChipControl(iop_base, saved_ctrl_reg);
10592     asc_dvc->is_in_int = FALSE;
10593     return (int_pending);
10594 }
10595
10596 /* Microcode buffer is kept after initialization for error recovery. */
10597 STATIC uchar _asc_mcode_buf[] =
10598 {
10599   0x01,  0x03,  0x01,  0x19,  0x0F,  0x00,  0x00,  0x00,  0x00,  0x00,  0x00,  0x00,  0x00,  0x00,  0x00,  0x00,
10600   0x0F,  0x0F,  0x0F,  0x0F,  0x0F,  0x0F,  0x0F,  0x0F,  0x00,  0x00,  0x00,  0x00,  0x00,  0x00,  0x00,  0x00,
10601   0x00,  0x00,  0x00,  0x00,  0x00,  0x00,  0x00,  0x00,  0x00,  0x00,  0x00,  0x00,  0x00,  0x00,  0x00,  0x00,
10602   0x00,  0x00,  0x00,  0x00,  0x00,  0x00,  0x00,  0x00,  0x00,  0x00,  0x00,  0x00,  0x00,  0x00,  0x00,  0x00,
10603   0x00,  0x00,  0x00,  0x00,  0xC3,  0x12,  0x0D,  0x05,  0x01,  0x00,  0x00,  0x00,  0x00,  0xFF,  0x00,  0x00,
10604   0x00,  0x00,  0x00,  0x00,  0xFF,  0x80,  0xFF,  0xFF,  0x01,  0x00,  0x00,  0x00,  0x00,  0x00,  0x00,  0x00,
10605   0x00,  0x00,  0x00,  0x23,  0x00,  0x00,  0x00,  0x00,  0x00,  0x07,  0x00,  0xFF,  0x00,  0x00,  0x00,  0x00,
10606   0xFF,  0xFF,  0xFF,  0x00,  0x00,  0x00,  0x00,  0x00,  0x00,  0x00,  0xE4,  0x88,  0x00,  0x00,  0x00,  0x00,
10607   0x80,  0x73,  0x48,  0x04,  0x36,  0x00,  0x00,  0xA2,  0xC2,  0x00,  0x80,  0x73,  0x03,  0x23,  0x36,  0x40,
10608   0xB6,  0x00,  0x36,  0x00,  0x05,  0xD6,  0x0C,  0xD2,  0x12,  0xDA,  0x00,  0xA2,  0xC2,  0x00,  0x92,  0x80,
10609   0x1E,  0x98,  0x50,  0x00,  0xF5,  0x00,  0x48,  0x98,  0xDF,  0x23,  0x36,  0x60,  0xB6,  0x00,  0x92,  0x80,
10610   0x4F,  0x00,  0xF5,  0x00,  0x48,  0x98,  0xEF,  0x23,  0x36,  0x60,  0xB6,  0x00,  0x92,  0x80,  0x80,  0x62,
10611   0x92,  0x80,  0x00,  0x46,  0x15,  0xEE,  0x13,  0xEA,  0x02,  0x01,  0x09,  0xD8,  0xCD,  0x04,  0x4D,  0x00,
10612   0x00,  0xA3,  0xD6,  0x00,  0xA6,  0x97,  0x7F,  0x23,  0x04,  0x61,  0x84,  0x01,  0xE6,  0x84,  0xD2,  0xC1,
10613   0x80,  0x73,  0xCD,  0x04,  0x4D,  0x00,  0x00,  0xA3,  0xDA,  0x01,  0xA6,  0x97,  0xC6,  0x81,  0xC2,  0x88,
10614   0x80,  0x73,  0x80,  0x77,  0x00,  0x01,  0x01,  0xA1,  0xFE,  0x00,  0x4F,  0x00,  0x84,  0x97,  0x07,  0xA6,
10615   0x08,  0x01,  0x00,  0x33,  0x03,  0x00,  0xC2,  0x88,  0x03,  0x03,  0x01,  0xDE,  0xC2,  0x88,  0xCE,  0x00,
10616   0x69,  0x60,  0xCE,  0x00,  0x02,  0x03,  0x4A,  0x60,  0x00,  0xA2,  0x78,  0x01,  0x80,  0x63,  0x07,  0xA6,
10617   0x24,  0x01,  0x78,  0x81,  0x03,  0x03,  0x80,  0x63,  0xE2,  0x00,  0x07,  0xA6,  0x34,  0x01,  0x00,  0x33,
10618   0x04,  0x00,  0xC2,  0x88,  0x03,  0x07,  0x02,  0x01,  0x04,  0xCA,  0x0D,  0x23,  0x68,  0x98,  0x4D,  0x04,
10619   0x04,  0x85,  0x05,  0xD8,  0x0D,  0x23,  0x68,  0x98,  0xCD,  0x04,  0x15,  0x23,  0xF8,  0x88,  0xFB,  0x23,
10620   0x02,  0x61,  0x82,  0x01,  0x80,  0x63,  0x02,  0x03,  0x06,  0xA3,  0x62,  0x01,  0x00,  0x33,  0x0A,  0x00,
10621   0xC2,  0x88,  0x4E,  0x00,  0x07,  0xA3,  0x6E,  0x01,  0x00,  0x33,  0x0B,  0x00,  0xC2,  0x88,  0xCD,  0x04,
10622   0x36,  0x2D,  0x00,  0x33,  0x1A,  0x00,  0xC2,  0x88,  0x50,  0x04,  0x88,  0x81,  0x06,  0xAB,  0x82,  0x01,
10623   0x88,  0x81,  0x4E,  0x00,  0x07,  0xA3,  0x92,  0x01,  0x50,  0x00,  0x00,  0xA3,  0x3C,  0x01,  0x00,  0x05,
10624   0x7C,  0x81,  0x46,  0x97,  0x02,  0x01,  0x05,  0xC6,  0x04,  0x23,  0xA0,  0x01,  0x15,  0x23,  0xA1,  0x01,
10625   0xBE,  0x81,  0xFD,  0x23,  0x02,  0x61,  0x82,  0x01,  0x0A,  0xDA,  0x4A,  0x00,  0x06,  0x61,  0x00,  0xA0,
10626   0xB4,  0x01,  0x80,  0x63,  0xCD,  0x04,  0x36,  0x2D,  0x00,  0x33,  0x1B,  0x00,  0xC2,  0x88,  0x06,  0x23,
10627   0x68,  0x98,  0xCD,  0x04,  0xE6,  0x84,  0x06,  0x01,  0x00,  0xA2,  0xD4,  0x01,  0x57,  0x60,  0x00,  0xA0,
10628   0xDA,  0x01,  0xE6,  0x84,  0x80,  0x23,  0xA0,  0x01,  0xE6,  0x84,  0x80,  0x73,  0x4B,  0x00,  0x06,  0x61,
10629   0x00,  0xA2,  0x00,  0x02,  0x04,  0x01,  0x0C,  0xDE,  0x02,  0x01,  0x03,  0xCC,  0x4F,  0x00,  0x84,  0x97,
10630   0xFC,  0x81,  0x08,  0x23,  0x02,  0x41,  0x82,  0x01,  0x4F,  0x00,  0x62,  0x97,  0x48,  0x04,  0x84,  0x80,
10631   0xF0,  0x97,  0x00,  0x46,  0x56,  0x00,  0x03,  0xC0,  0x01,  0x23,  0xE8,  0x00,  0x81,  0x73,  0x06,  0x29,
10632   0x03,  0x42,  0x06,  0xE2,  0x03,  0xEE,  0x6B,  0xEB,  0x11,  0x23,  0xF8,  0x88,  0x04,  0x98,  0xF0,  0x80,
10633   0x80,  0x73,  0x80,  0x77,  0x07,  0xA4,  0x2A,  0x02,  0x7C,  0x95,  0x06,  0xA6,  0x34,  0x02,  0x03,  0xA6,
10634   0x4C,  0x04,  0x46,  0x82,  0x04,  0x01,  0x03,  0xD8,  0xB4,  0x98,  0x6A,  0x96,  0x46,  0x82,  0xFE,  0x95,
10635   0x80,  0x67,  0x83,  0x03,  0x80,  0x63,  0xB6,  0x2D,  0x02,  0xA6,  0x6C,  0x02,  0x07,  0xA6,  0x5A,  0x02,
10636   0x06,  0xA6,  0x5E,  0x02,  0x03,  0xA6,  0x62,  0x02,  0xC2,  0x88,  0x7C,  0x95,  0x48,  0x82,  0x60,  0x96,
10637   0x48,  0x82,  0x04,  0x23,  0xA0,  0x01,  0x14,  0x23,  0xA1,  0x01,  0x3C,  0x84,  0x04,  0x01,  0x0C,  0xDC,
10638   0xE0,  0x23,  0x25,  0x61,  0xEF,  0x00,  0x14,  0x01,  0x4F,  0x04,  0xA8,  0x01,  0x6F,  0x00,  0xA5,  0x01,
10639   0x03,  0x23,  0xA4,  0x01,  0x06,  0x23,  0x9C,  0x01,  0x24,  0x2B,  0x1C,  0x01,  0x02,  0xA6,  0xAA,  0x02,
10640   0x07,  0xA6,  0x5A,  0x02,  0x06,  0xA6,  0x5E,  0x02,  0x03,  0xA6,  0x20,  0x04,  0x01,  0xA6,  0xB4,  0x02,
10641   0x00,  0xA6,  0xB4,  0x02,  0x00,  0x33,  0x12,  0x00,  0xC2,  0x88,  0x00,  0x0E,  0x80,  0x63,  0x00,  0x43,
10642   0x00,  0xA0,  0x8C,  0x02,  0x4D,  0x04,  0x04,  0x01,  0x0B,  0xDC,  0xE7,  0x23,  0x04,  0x61,  0x84,  0x01,
10643   0x10,  0x31,  0x12,  0x35,  0x14,  0x01,  0xEC,  0x00,  0x6C,  0x38,  0x00,  0x3F,  0x00,  0x00,  0xEA,  0x82,
10644   0x18,  0x23,  0x04,  0x61,  0x18,  0xA0,  0xE2,  0x02,  0x04,  0x01,  0xA2,  0xC8,  0x00,  0x33,  0x1F,  0x00,
10645   0xC2,  0x88,  0x08,  0x31,  0x0A,  0x35,  0x0C,  0x39,  0x0E,  0x3D,  0x7E,  0x98,  0xB6,  0x2D,  0x01,  0xA6,
10646   0x14,  0x03,  0x00,  0xA6,  0x14,  0x03,  0x07,  0xA6,  0x0C,  0x03,  0x06,  0xA6,  0x10,  0x03,  0x03,  0xA6,
10647   0x20,  0x04,  0x02,  0xA6,  0x6C,  0x02,  0x00,  0x33,  0x33,  0x00,  0xC2,  0x88,  0x7C,  0x95,  0xEE,  0x82,
10648   0x60,  0x96,  0xEE,  0x82,  0x82,  0x98,  0x80,  0x42,  0x7E,  0x98,  0x64,  0xE4,  0x04,  0x01,  0x2D,  0xC8,
10649   0x31,  0x05,  0x07,  0x01,  0x00,  0xA2,  0x54,  0x03,  0x00,  0x43,  0x87,  0x01,  0x05,  0x05,  0x86,  0x98,
10650   0x7E,  0x98,  0x00,  0xA6,  0x16,  0x03,  0x07,  0xA6,  0x4C,  0x03,  0x03,  0xA6,  0x3C,  0x04,  0x06,  0xA6,
10651   0x50,  0x03,  0x01,  0xA6,  0x16,  0x03,  0x00,  0x33,  0x25,  0x00,  0xC2,  0x88,  0x7C,  0x95,  0x32,  0x83,
10652   0x60,  0x96,  0x32,  0x83,  0x04,  0x01,  0x10,  0xCE,  0x07,  0xC8,  0x05,  0x05,  0xEB,  0x04,  0x00,  0x33,
10653   0x00,  0x20,  0xC0,  0x20,  0x81,  0x62,  0x72,  0x83,  0x00,  0x01,  0x05,  0x05,  0xFF,  0xA2,  0x7A,  0x03,
10654   0xB1,  0x01,  0x08,  0x23,  0xB2,  0x01,  0x2E,  0x83,  0x05,  0x05,  0x15,  0x01,  0x00,  0xA2,  0x9A,  0x03,
10655   0xEC,  0x00,  0x6E,  0x00,  0x95,  0x01,  0x6C,  0x38,  0x00,  0x3F,  0x00,  0x00,  0x01,  0xA6,  0x96,  0x03,
10656   0x00,  0xA6,  0x96,  0x03,  0x10,  0x84,  0x80,  0x42,  0x7E,  0x98,  0x01,  0xA6,  0xA4,  0x03,  0x00,  0xA6,
10657   0xBC,  0x03,  0x10,  0x84,  0xA8,  0x98,  0x80,  0x42,  0x01,  0xA6,  0xA4,  0x03,  0x07,  0xA6,  0xB2,  0x03,
10658   0xD4,  0x83,  0x7C,  0x95,  0xA8,  0x83,  0x00,  0x33,  0x2F,  0x00,  0xC2,  0x88,  0xA8,  0x98,  0x80,  0x42,
10659   0x00,  0xA6,  0xBC,  0x03,  0x07,  0xA6,  0xCA,  0x03,  0xD4,  0x83,  0x7C,  0x95,  0xC0,  0x83,  0x00,  0x33,
10660   0x26,  0x00,  0xC2,  0x88,  0x38,  0x2B,  0x80,  0x32,  0x80,  0x36,  0x04,  0x23,  0xA0,  0x01,  0x12,  0x23,
10661   0xA1,  0x01,  0x10,  0x84,  0x07,  0xF0,  0x06,  0xA4,  0xF4,  0x03,  0x80,  0x6B,  0x80,  0x67,  0x05,  0x23,
10662   0x83,  0x03,  0x80,  0x63,  0x03,  0xA6,  0x0E,  0x04,  0x07,  0xA6,  0x06,  0x04,  0x06,  0xA6,  0x0A,  0x04,
10663   0x00,  0x33,  0x17,  0x00,  0xC2,  0x88,  0x7C,  0x95,  0xF4,  0x83,  0x60,  0x96,  0xF4,  0x83,  0x20,  0x84,
10664   0x07,  0xF0,  0x06,  0xA4,  0x20,  0x04,  0x80,  0x6B,  0x80,  0x67,  0x05,  0x23,  0x83,  0x03,  0x80,  0x63,
10665   0xB6,  0x2D,  0x03,  0xA6,  0x3C,  0x04,  0x07,  0xA6,  0x34,  0x04,  0x06,  0xA6,  0x38,  0x04,  0x00,  0x33,
10666   0x30,  0x00,  0xC2,  0x88,  0x7C,  0x95,  0x20,  0x84,  0x60,  0x96,  0x20,  0x84,  0x1D,  0x01,  0x06,  0xCC,
10667   0x00,  0x33,  0x00,  0x84,  0xC0,  0x20,  0x00,  0x23,  0xEA,  0x00,  0x81,  0x62,  0xA2,  0x0D,  0x80,  0x63,
10668   0x07,  0xA6,  0x5A,  0x04,  0x00,  0x33,  0x18,  0x00,  0xC2,  0x88,  0x03,  0x03,  0x80,  0x63,  0xA3,  0x01,
10669   0x07,  0xA4,  0x64,  0x04,  0x23,  0x01,  0x00,  0xA2,  0x86,  0x04,  0x0A,  0xA0,  0x76,  0x04,  0xE0,  0x00,
10670   0x00,  0x33,  0x1D,  0x00,  0xC2,  0x88,  0x0B,  0xA0,  0x82,  0x04,  0xE0,  0x00,  0x00,  0x33,  0x1E,  0x00,
10671   0xC2,  0x88,  0x42,  0x23,  0xF8,  0x88,  0x00,  0x23,  0x22,  0xA3,  0xE6,  0x04,  0x08,  0x23,  0x22,  0xA3,
10672   0xA2,  0x04,  0x28,  0x23,  0x22,  0xA3,  0xAE,  0x04,  0x02,  0x23,  0x22,  0xA3,  0xC4,  0x04,  0x42,  0x23,
10673   0xF8,  0x88,  0x4A,  0x00,  0x06,  0x61,  0x00,  0xA0,  0xAE,  0x04,  0x45,  0x23,  0xF8,  0x88,  0x04,  0x98,
10674   0x00,  0xA2,  0xC0,  0x04,  0xB4,  0x98,  0x00,  0x33,  0x00,  0x82,  0xC0,  0x20,  0x81,  0x62,  0xE8,  0x81,
10675   0x47,  0x23,  0xF8,  0x88,  0x04,  0x01,  0x0B,  0xDE,  0x04,  0x98,  0xB4,  0x98,  0x00,  0x33,  0x00,  0x81,
10676   0xC0,  0x20,  0x81,  0x62,  0x14,  0x01,  0x00,  0xA0,  0x00,  0x02,  0x43,  0x23,  0xF8,  0x88,  0x04,  0x23,
10677   0xA0,  0x01,  0x44,  0x23,  0xA1,  0x01,  0x80,  0x73,  0x4D,  0x00,  0x03,  0xA3,  0xF4,  0x04,  0x00,  0x33,
10678   0x27,  0x00,  0xC2,  0x88,  0x04,  0x01,  0x04,  0xDC,  0x02,  0x23,  0xA2,  0x01,  0x04,  0x23,  0xA0,  0x01,
10679   0x04,  0x98,  0x26,  0x95,  0x4B,  0x00,  0xF6,  0x00,  0x4F,  0x04,  0x4F,  0x00,  0x00,  0xA3,  0x22,  0x05,
10680   0x00,  0x05,  0x76,  0x00,  0x06,  0x61,  0x00,  0xA2,  0x1C,  0x05,  0x0A,  0x85,  0x46,  0x97,  0xCD,  0x04,
10681   0x24,  0x85,  0x48,  0x04,  0x84,  0x80,  0x02,  0x01,  0x03,  0xDA,  0x80,  0x23,  0x82,  0x01,  0x34,  0x85,
10682   0x02,  0x23,  0xA0,  0x01,  0x4A,  0x00,  0x06,  0x61,  0x00,  0xA2,  0x40,  0x05,  0x1D,  0x01,  0x04,  0xD6,
10683   0xFF,  0x23,  0x86,  0x41,  0x4B,  0x60,  0xCB,  0x00,  0xFF,  0x23,  0x80,  0x01,  0x49,  0x00,  0x81,  0x01,
10684   0x04,  0x01,  0x02,  0xC8,  0x30,  0x01,  0x80,  0x01,  0xF7,  0x04,  0x03,  0x01,  0x49,  0x04,  0x80,  0x01,
10685   0xC9,  0x00,  0x00,  0x05,  0x00,  0x01,  0xFF,  0xA0,  0x60,  0x05,  0x77,  0x04,  0x01,  0x23,  0xEA,  0x00,
10686   0x5D,  0x00,  0xFE,  0xC7,  0x00,  0x62,  0x00,  0x23,  0xEA,  0x00,  0x00,  0x63,  0x07,  0xA4,  0xF8,  0x05,
10687   0x03,  0x03,  0x02,  0xA0,  0x8E,  0x05,  0xF4,  0x85,  0x00,  0x33,  0x2D,  0x00,  0xC2,  0x88,  0x04,  0xA0,
10688   0xB8,  0x05,  0x80,  0x63,  0x00,  0x23,  0xDF,  0x00,  0x4A,  0x00,  0x06,  0x61,  0x00,  0xA2,  0xA4,  0x05,
10689   0x1D,  0x01,  0x06,  0xD6,  0x02,  0x23,  0x02,  0x41,  0x82,  0x01,  0x50,  0x00,  0x62,  0x97,  0x04,  0x85,
10690   0x04,  0x23,  0x02,  0x41,  0x82,  0x01,  0x04,  0x85,  0x08,  0xA0,  0xBE,  0x05,  0xF4,  0x85,  0x03,  0xA0,
10691   0xC4,  0x05,  0xF4,  0x85,  0x01,  0xA0,  0xCE,  0x05,  0x88,  0x00,  0x80,  0x63,  0xCC,  0x86,  0x07,  0xA0,
10692   0xEE,  0x05,  0x5F,  0x00,  0x00,  0x2B,  0xDF,  0x08,  0x00,  0xA2,  0xE6,  0x05,  0x80,  0x67,  0x80,  0x63,
10693   0x01,  0xA2,  0x7A,  0x06,  0x7C,  0x85,  0x06,  0x23,  0x68,  0x98,  0x48,  0x23,  0xF8,  0x88,  0x07,  0x23,
10694   0x80,  0x00,  0x06,  0x87,  0x80,  0x63,  0x7C,  0x85,  0x00,  0x23,  0xDF,  0x00,  0x00,  0x63,  0x4A,  0x00,
10695   0x06,  0x61,  0x00,  0xA2,  0x36,  0x06,  0x1D,  0x01,  0x16,  0xD4,  0xC0,  0x23,  0x07,  0x41,  0x83,  0x03,
10696   0x80,  0x63,  0x06,  0xA6,  0x1C,  0x06,  0x00,  0x33,  0x37,  0x00,  0xC2,  0x88,  0x1D,  0x01,  0x01,  0xD6,
10697   0x20,  0x23,  0x63,  0x60,  0x83,  0x03,  0x80,  0x63,  0x02,  0x23,  0xDF,  0x00,  0x07,  0xA6,  0x7C,  0x05,
10698   0xEF,  0x04,  0x6F,  0x00,  0x00,  0x63,  0x4B,  0x00,  0x06,  0x41,  0xCB,  0x00,  0x52,  0x00,  0x06,  0x61,
10699   0x00,  0xA2,  0x4E,  0x06,  0x1D,  0x01,  0x03,  0xCA,  0xC0,  0x23,  0x07,  0x41,  0x00,  0x63,  0x1D,  0x01,
10700   0x04,  0xCC,  0x00,  0x33,  0x00,  0x83,  0xC0,  0x20,  0x81,  0x62,  0x80,  0x23,  0x07,  0x41,  0x00,  0x63,
10701   0x80,  0x67,  0x08,  0x23,  0x83,  0x03,  0x80,  0x63,  0x00,  0x63,  0x01,  0x23,  0xDF,  0x00,  0x06,  0xA6,
10702   0x84,  0x06,  0x07,  0xA6,  0x7C,  0x05,  0x80,  0x67,  0x80,  0x63,  0x00,  0x33,  0x00,  0x40,  0xC0,  0x20,
10703   0x81,  0x62,  0x00,  0x63,  0x00,  0x00,  0xFE,  0x95,  0x83,  0x03,  0x80,  0x63,  0x06,  0xA6,  0x94,  0x06,
10704   0x07,  0xA6,  0x7C,  0x05,  0x00,  0x00,  0x01,  0xA0,  0x14,  0x07,  0x00,  0x2B,  0x40,  0x0E,  0x80,  0x63,
10705   0x01,  0x00,  0x06,  0xA6,  0xAA,  0x06,  0x07,  0xA6,  0x7C,  0x05,  0x40,  0x0E,  0x80,  0x63,  0x00,  0x43,
10706   0x00,  0xA0,  0xA2,  0x06,  0x06,  0xA6,  0xBC,  0x06,  0x07,  0xA6,  0x7C,  0x05,  0x80,  0x67,  0x40,  0x0E,
10707   0x80,  0x63,  0x07,  0xA6,  0x7C,  0x05,  0x00,  0x23,  0xDF,  0x00,  0x00,  0x63,  0x07,  0xA6,  0xD6,  0x06,
10708   0x00,  0x33,  0x2A,  0x00,  0xC2,  0x88,  0x03,  0x03,  0x80,  0x63,  0x89,  0x00,  0x0A,  0x2B,  0x07,  0xA6,
10709   0xE8,  0x06,  0x00,  0x33,  0x29,  0x00,  0xC2,  0x88,  0x00,  0x43,  0x00,  0xA2,  0xF4,  0x06,  0xC0,  0x0E,
10710   0x80,  0x63,  0xDE,  0x86,  0xC0,  0x0E,  0x00,  0x33,  0x00,  0x80,  0xC0,  0x20,  0x81,  0x62,  0x04,  0x01,
10711   0x02,  0xDA,  0x80,  0x63,  0x7C,  0x85,  0x80,  0x7B,  0x80,  0x63,  0x06,  0xA6,  0x8C,  0x06,  0x00,  0x33,
10712   0x2C,  0x00,  0xC2,  0x88,  0x0C,  0xA2,  0x2E,  0x07,  0xFE,  0x95,  0x83,  0x03,  0x80,  0x63,  0x06,  0xA6,
10713   0x2C,  0x07,  0x07,  0xA6,  0x7C,  0x05,  0x00,  0x33,  0x3D,  0x00,  0xC2,  0x88,  0x00,  0x00,  0x80,  0x67,
10714   0x83,  0x03,  0x80,  0x63,  0x0C,  0xA0,  0x44,  0x07,  0x07,  0xA6,  0x7C,  0x05,  0xBF,  0x23,  0x04,  0x61,
10715   0x84,  0x01,  0xE6,  0x84,  0x00,  0x63,  0xF0,  0x04,  0x01,  0x01,  0xF1,  0x00,  0x00,  0x01,  0xF2,  0x00,
10716   0x01,  0x05,  0x80,  0x01,  0x72,  0x04,  0x71,  0x00,  0x81,  0x01,  0x70,  0x04,  0x80,  0x05,  0x81,  0x05,
10717   0x00,  0x63,  0xF0,  0x04,  0xF2,  0x00,  0x72,  0x04,  0x01,  0x01,  0xF1,  0x00,  0x70,  0x00,  0x81,  0x01,
10718   0x70,  0x04,  0x71,  0x00,  0x81,  0x01,  0x72,  0x00,  0x80,  0x01,  0x71,  0x04,  0x70,  0x00,  0x80,  0x01,
10719   0x70,  0x04,  0x00,  0x63,  0xF0,  0x04,  0xF2,  0x00,  0x72,  0x04,  0x00,  0x01,  0xF1,  0x00,  0x70,  0x00,
10720   0x80,  0x01,  0x70,  0x04,  0x71,  0x00,  0x80,  0x01,  0x72,  0x00,  0x81,  0x01,  0x71,  0x04,  0x70,  0x00,
10721   0x81,  0x01,  0x70,  0x04,  0x00,  0x63,  0x00,  0x23,  0xB3,  0x01,  0x83,  0x05,  0xA3,  0x01,  0xA2,  0x01,
10722   0xA1,  0x01,  0x01,  0x23,  0xA0,  0x01,  0x00,  0x01,  0xC8,  0x00,  0x03,  0xA1,  0xC4,  0x07,  0x00,  0x33,
10723   0x07,  0x00,  0xC2,  0x88,  0x80,  0x05,  0x81,  0x05,  0x04,  0x01,  0x11,  0xC8,  0x48,  0x00,  0xB0,  0x01,
10724   0xB1,  0x01,  0x08,  0x23,  0xB2,  0x01,  0x05,  0x01,  0x48,  0x04,  0x00,  0x43,  0x00,  0xA2,  0xE4,  0x07,
10725   0x00,  0x05,  0xDA,  0x87,  0x00,  0x01,  0xC8,  0x00,  0xFF,  0x23,  0x80,  0x01,  0x05,  0x05,  0x00,  0x63,
10726   0xF7,  0x04,  0x1A,  0x09,  0xF6,  0x08,  0x6E,  0x04,  0x00,  0x02,  0x80,  0x43,  0x76,  0x08,  0x80,  0x02,
10727   0x77,  0x04,  0x00,  0x63,  0xF7,  0x04,  0x1A,  0x09,  0xF6,  0x08,  0x6E,  0x04,  0x00,  0x02,  0x00,  0xA0,
10728   0x14,  0x08,  0x16,  0x88,  0x00,  0x43,  0x76,  0x08,  0x80,  0x02,  0x77,  0x04,  0x00,  0x63,  0xF3,  0x04,
10729   0x00,  0x23,  0xF4,  0x00,  0x74,  0x00,  0x80,  0x43,  0xF4,  0x00,  0xCF,  0x40,  0x00,  0xA2,  0x44,  0x08,
10730   0x74,  0x04,  0x02,  0x01,  0xF7,  0xC9,  0xF6,  0xD9,  0x00,  0x01,  0x01,  0xA1,  0x24,  0x08,  0x04,  0x98,
10731   0x26,  0x95,  0x24,  0x88,  0x73,  0x04,  0x00,  0x63,  0xF3,  0x04,  0x75,  0x04,  0x5A,  0x88,  0x02,  0x01,
10732   0x04,  0xD8,  0x46,  0x97,  0x04,  0x98,  0x26,  0x95,  0x4A,  0x88,  0x75,  0x00,  0x00,  0xA3,  0x64,  0x08,
10733   0x00,  0x05,  0x4E,  0x88,  0x73,  0x04,  0x00,  0x63,  0x80,  0x7B,  0x80,  0x63,  0x06,  0xA6,  0x76,  0x08,
10734   0x00,  0x33,  0x3E,  0x00,  0xC2,  0x88,  0x80,  0x67,  0x83,  0x03,  0x80,  0x63,  0x00,  0x63,  0x38,  0x2B,
10735   0x9C,  0x88,  0x38,  0x2B,  0x92,  0x88,  0x32,  0x09,  0x31,  0x05,  0x92,  0x98,  0x05,  0x05,  0xB2,  0x09,
10736   0x00,  0x63,  0x00,  0x32,  0x00,  0x36,  0x00,  0x3A,  0x00,  0x3E,  0x00,  0x63,  0x80,  0x32,  0x80,  0x36,
10737   0x80,  0x3A,  0x80,  0x3E,  0xB4,  0x3D,  0x00,  0x63,  0x38,  0x2B,  0x40,  0x32,  0x40,  0x36,  0x40,  0x3A,
10738   0x40,  0x3E,  0x00,  0x63,  0x5A,  0x20,  0xC9,  0x40,  0x00,  0xA0,  0xB4,  0x08,  0x5D,  0x00,  0xFE,  0xC3,
10739   0x00,  0x63,  0x80,  0x73,  0xE6,  0x20,  0x02,  0x23,  0xE8,  0x00,  0x82,  0x73,  0xFF,  0xFD,  0x80,  0x73,
10740   0x13,  0x23,  0xF8,  0x88,  0x66,  0x20,  0xC0,  0x20,  0x04,  0x23,  0xA0,  0x01,  0xA1,  0x23,  0xA1,  0x01,
10741   0x81,  0x62,  0xE2,  0x88,  0x80,  0x73,  0x80,  0x77,  0x68,  0x00,  0x00,  0xA2,  0x80,  0x00,  0x03,  0xC2,
10742   0xF1,  0xC7,  0x41,  0x23,  0xF8,  0x88,  0x11,  0x23,  0xA1,  0x01,  0x04,  0x23,  0xA0,  0x01,  0xE6,  0x84,
10743 };
10744
10745 STATIC ushort _asc_mcode_size = sizeof(_asc_mcode_buf);
10746 STATIC ADV_DCNT _asc_mcode_chksum = 0x012C453FUL;
10747
10748 #define ASC_SYN_OFFSET_ONE_DISABLE_LIST  16
10749 STATIC uchar _syn_offset_one_disable_cmd[ASC_SYN_OFFSET_ONE_DISABLE_LIST] =
10750 {
10751     INQUIRY,
10752     REQUEST_SENSE,
10753     READ_CAPACITY,
10754     READ_TOC,
10755     MODE_SELECT,
10756     MODE_SENSE,
10757     MODE_SELECT_10,
10758     MODE_SENSE_10,
10759     0xFF,
10760     0xFF,
10761     0xFF,
10762     0xFF,
10763     0xFF,
10764     0xFF,
10765     0xFF,
10766     0xFF
10767 };
10768
10769 STATIC int
10770 AscExeScsiQueue(
10771                    ASC_DVC_VAR *asc_dvc,
10772                    ASC_SCSI_Q *scsiq
10773 )
10774 {
10775     PortAddr            iop_base;
10776     ulong               last_int_level;
10777     int                 sta;
10778     int                 n_q_required;
10779     int                 disable_syn_offset_one_fix;
10780     int                 i;
10781     ASC_PADDR           addr;
10782     ASC_EXE_CALLBACK    asc_exe_callback;
10783     ushort              sg_entry_cnt = 0;
10784     ushort              sg_entry_cnt_minus_one = 0;
10785     uchar               target_ix;
10786     uchar               tid_no;
10787     uchar               sdtr_data;
10788     uchar               extra_bytes;
10789     uchar               scsi_cmd;
10790     uchar               disable_cmd;
10791     ASC_SG_HEAD         *sg_head;
10792     ASC_DCNT            data_cnt;
10793
10794     iop_base = asc_dvc->iop_base;
10795     sg_head = scsiq->sg_head;
10796     asc_exe_callback = asc_dvc->exe_callback;
10797     if (asc_dvc->err_code != 0)
10798         return (ERR);
10799     if (scsiq == (ASC_SCSI_Q *) 0L) {
10800         AscSetLibErrorCode(asc_dvc, ASCQ_ERR_SCSIQ_NULL_PTR);
10801         return (ERR);
10802     }
10803     scsiq->q1.q_no = 0;
10804     if ((scsiq->q2.tag_code & ASC_TAG_FLAG_EXTRA_BYTES) == 0) {
10805         scsiq->q1.extra_bytes = 0;
10806     }
10807     sta = 0;
10808     target_ix = scsiq->q2.target_ix;
10809     tid_no = ASC_TIX_TO_TID(target_ix);
10810     n_q_required = 1;
10811     if (scsiq->cdbptr[0] == REQUEST_SENSE) {
10812         if ((asc_dvc->init_sdtr & scsiq->q1.target_id) != 0) {
10813             asc_dvc->sdtr_done &= ~scsiq->q1.target_id;
10814             sdtr_data = AscGetMCodeInitSDTRAtID(iop_base, tid_no);
10815             AscMsgOutSDTR(asc_dvc,
10816                           asc_dvc->sdtr_period_tbl[(sdtr_data >> 4) &
10817                           (uchar) (asc_dvc->max_sdtr_index - 1)],
10818                           (uchar) (sdtr_data & (uchar) ASC_SYN_MAX_OFFSET));
10819             scsiq->q1.cntl |= (QC_MSG_OUT | QC_URGENT);
10820         }
10821     }
10822     last_int_level = DvcEnterCritical();
10823     if (asc_dvc->in_critical_cnt != 0) {
10824         DvcLeaveCritical(last_int_level);
10825         AscSetLibErrorCode(asc_dvc, ASCQ_ERR_CRITICAL_RE_ENTRY);
10826         return (ERR);
10827     }
10828     asc_dvc->in_critical_cnt++;
10829     if ((scsiq->q1.cntl & QC_SG_HEAD) != 0) {
10830         if ((sg_entry_cnt = sg_head->entry_cnt) == 0) {
10831             asc_dvc->in_critical_cnt--;
10832             DvcLeaveCritical(last_int_level);
10833             return (ERR);
10834         }
10835 #if !CC_VERY_LONG_SG_LIST
10836         if (sg_entry_cnt > ASC_MAX_SG_LIST)
10837         {
10838             asc_dvc->in_critical_cnt--;
10839             DvcLeaveCritical(last_int_level);
10840             return(ERR);
10841         }
10842 #endif /* !CC_VERY_LONG_SG_LIST */
10843         if (sg_entry_cnt == 1) {
10844             scsiq->q1.data_addr = (ADV_PADDR) sg_head->sg_list[0].addr;
10845             scsiq->q1.data_cnt = (ADV_DCNT) sg_head->sg_list[0].bytes;
10846             scsiq->q1.cntl &= ~(QC_SG_HEAD | QC_SG_SWAP_QUEUE);
10847         }
10848         sg_entry_cnt_minus_one = sg_entry_cnt - 1;
10849     }
10850     scsi_cmd = scsiq->cdbptr[0];
10851     disable_syn_offset_one_fix = FALSE;
10852     if ((asc_dvc->pci_fix_asyn_xfer & scsiq->q1.target_id) &&
10853         !(asc_dvc->pci_fix_asyn_xfer_always & scsiq->q1.target_id)) {
10854         if (scsiq->q1.cntl & QC_SG_HEAD) {
10855             data_cnt = 0;
10856             for (i = 0; i < sg_entry_cnt; i++) {
10857                 data_cnt += (ADV_DCNT) le32_to_cpu(sg_head->sg_list[i].bytes);
10858             }
10859         } else {
10860             data_cnt = le32_to_cpu(scsiq->q1.data_cnt);
10861         }
10862         if (data_cnt != 0UL) {
10863             if (data_cnt < 512UL) {
10864                 disable_syn_offset_one_fix = TRUE;
10865             } else {
10866                 for (i = 0; i < ASC_SYN_OFFSET_ONE_DISABLE_LIST; i++) {
10867                     disable_cmd = _syn_offset_one_disable_cmd[i];
10868                     if (disable_cmd == 0xFF) {
10869                         break;
10870                     }
10871                     if (scsi_cmd == disable_cmd) {
10872                         disable_syn_offset_one_fix = TRUE;
10873                         break;
10874                     }
10875                 }
10876             }
10877         }
10878     }
10879     if (disable_syn_offset_one_fix) {
10880         scsiq->q2.tag_code &= ~MSG_SIMPLE_TAG;
10881         scsiq->q2.tag_code |= (ASC_TAG_FLAG_DISABLE_ASYN_USE_SYN_FIX |
10882                                ASC_TAG_FLAG_DISABLE_DISCONNECT);
10883     } else {
10884         scsiq->q2.tag_code &= 0x27;
10885     }
10886     if ((scsiq->q1.cntl & QC_SG_HEAD) != 0) {
10887         if (asc_dvc->bug_fix_cntl) {
10888             if (asc_dvc->bug_fix_cntl & ASC_BUG_FIX_IF_NOT_DWB) {
10889                 if ((scsi_cmd == READ_6) ||
10890                     (scsi_cmd == READ_10)) {
10891                     addr =
10892                         (ADV_PADDR) le32_to_cpu(
10893                             sg_head->sg_list[sg_entry_cnt_minus_one].addr) +
10894                         (ADV_DCNT) le32_to_cpu(
10895                             sg_head->sg_list[sg_entry_cnt_minus_one].bytes);
10896                     extra_bytes = (uchar) ((ushort) addr & 0x0003);
10897                     if ((extra_bytes != 0) &&
10898                         ((scsiq->q2.tag_code & ASC_TAG_FLAG_EXTRA_BYTES)
10899                          == 0)) {
10900                         scsiq->q2.tag_code |= ASC_TAG_FLAG_EXTRA_BYTES;
10901                         scsiq->q1.extra_bytes = extra_bytes;
10902                         data_cnt = le32_to_cpu(
10903                             sg_head->sg_list[sg_entry_cnt_minus_one].bytes);
10904                         data_cnt -= (ASC_DCNT) extra_bytes;
10905                         sg_head->sg_list[sg_entry_cnt_minus_one].bytes =
10906                             cpu_to_le32(data_cnt);
10907                     }
10908                 }
10909             }
10910         }
10911         sg_head->entry_to_copy = sg_head->entry_cnt;
10912 #if CC_VERY_LONG_SG_LIST
10913         /*
10914          * Set the sg_entry_cnt to the maximum possible. The rest of
10915          * the SG elements will be copied when the RISC completes the
10916          * SG elements that fit and halts.
10917          */
10918         if (sg_entry_cnt > ASC_MAX_SG_LIST)
10919         {
10920              sg_entry_cnt = ASC_MAX_SG_LIST;
10921         }
10922 #endif /* CC_VERY_LONG_SG_LIST */
10923         n_q_required = AscSgListToQueue(sg_entry_cnt);
10924         if ((AscGetNumOfFreeQueue(asc_dvc, target_ix, n_q_required) >=
10925             (uint) n_q_required) || ((scsiq->q1.cntl & QC_URGENT) != 0)) {
10926             if ((sta = AscSendScsiQueue(asc_dvc, scsiq,
10927                                         n_q_required)) == 1) {
10928                 asc_dvc->in_critical_cnt--;
10929                 if (asc_exe_callback != 0) {
10930                     (*asc_exe_callback) (asc_dvc, scsiq);
10931                 }
10932                 DvcLeaveCritical(last_int_level);
10933                 return (sta);
10934             }
10935         }
10936     } else {
10937         if (asc_dvc->bug_fix_cntl) {
10938             if (asc_dvc->bug_fix_cntl & ASC_BUG_FIX_IF_NOT_DWB) {
10939                 if ((scsi_cmd == READ_6) ||
10940                     (scsi_cmd == READ_10)) {
10941                     addr = le32_to_cpu(scsiq->q1.data_addr) +
10942                         le32_to_cpu(scsiq->q1.data_cnt);
10943                     extra_bytes = (uchar) ((ushort) addr & 0x0003);
10944                     if ((extra_bytes != 0) &&
10945                         ((scsiq->q2.tag_code & ASC_TAG_FLAG_EXTRA_BYTES)
10946                           == 0)) {
10947                         data_cnt = le32_to_cpu(scsiq->q1.data_cnt);
10948                         if (((ushort) data_cnt & 0x01FF) == 0) {
10949                             scsiq->q2.tag_code |= ASC_TAG_FLAG_EXTRA_BYTES;
10950                             data_cnt -= (ASC_DCNT) extra_bytes;
10951                             scsiq->q1.data_cnt = cpu_to_le32(data_cnt);
10952                             scsiq->q1.extra_bytes = extra_bytes;
10953                         }
10954                     }
10955                 }
10956             }
10957         }
10958         n_q_required = 1;
10959         if ((AscGetNumOfFreeQueue(asc_dvc, target_ix, 1) >= 1) ||
10960             ((scsiq->q1.cntl & QC_URGENT) != 0)) {
10961             if ((sta = AscSendScsiQueue(asc_dvc, scsiq,
10962                                         n_q_required)) == 1) {
10963                 asc_dvc->in_critical_cnt--;
10964                 if (asc_exe_callback != 0) {
10965                     (*asc_exe_callback) (asc_dvc, scsiq);
10966                 }
10967                 DvcLeaveCritical(last_int_level);
10968                 return (sta);
10969             }
10970         }
10971     }
10972     asc_dvc->in_critical_cnt--;
10973     DvcLeaveCritical(last_int_level);
10974     return (sta);
10975 }
10976
10977 STATIC int
10978 AscSendScsiQueue(
10979                     ASC_DVC_VAR *asc_dvc,
10980                     ASC_SCSI_Q *scsiq,
10981                     uchar n_q_required
10982 )
10983 {
10984     PortAddr            iop_base;
10985     uchar               free_q_head;
10986     uchar               next_qp;
10987     uchar               tid_no;
10988     uchar               target_ix;
10989     int                 sta;
10990
10991     iop_base = asc_dvc->iop_base;
10992     target_ix = scsiq->q2.target_ix;
10993     tid_no = ASC_TIX_TO_TID(target_ix);
10994     sta = 0;
10995     free_q_head = (uchar) AscGetVarFreeQHead(iop_base);
10996     if (n_q_required > 1) {
10997         if ((next_qp = AscAllocMultipleFreeQueue(iop_base,
10998                                        free_q_head, (uchar) (n_q_required)))
10999             != (uchar) ASC_QLINK_END) {
11000             asc_dvc->last_q_shortage = 0;
11001             scsiq->sg_head->queue_cnt = n_q_required - 1;
11002             scsiq->q1.q_no = free_q_head;
11003             if ((sta = AscPutReadySgListQueue(asc_dvc, scsiq,
11004                                               free_q_head)) == 1) {
11005                 AscPutVarFreeQHead(iop_base, next_qp);
11006                 asc_dvc->cur_total_qng += (uchar) (n_q_required);
11007                 asc_dvc->cur_dvc_qng[tid_no]++;
11008             }
11009             return (sta);
11010         }
11011     } else if (n_q_required == 1) {
11012         if ((next_qp = AscAllocFreeQueue(iop_base,
11013                                          free_q_head)) != ASC_QLINK_END) {
11014             scsiq->q1.q_no = free_q_head;
11015             if ((sta = AscPutReadyQueue(asc_dvc, scsiq,
11016                                         free_q_head)) == 1) {
11017                 AscPutVarFreeQHead(iop_base, next_qp);
11018                 asc_dvc->cur_total_qng++;
11019                 asc_dvc->cur_dvc_qng[tid_no]++;
11020             }
11021             return (sta);
11022         }
11023     }
11024     return (sta);
11025 }
11026
11027 STATIC int
11028 AscSgListToQueue(
11029                     int sg_list
11030 )
11031 {
11032     int                 n_sg_list_qs;
11033
11034     n_sg_list_qs = ((sg_list - 1) / ASC_SG_LIST_PER_Q);
11035     if (((sg_list - 1) % ASC_SG_LIST_PER_Q) != 0)
11036         n_sg_list_qs++;
11037     return (n_sg_list_qs + 1);
11038 }
11039
11040
11041 STATIC uint
11042 AscGetNumOfFreeQueue(
11043                         ASC_DVC_VAR *asc_dvc,
11044                         uchar target_ix,
11045                         uchar n_qs
11046 )
11047 {
11048     uint                cur_used_qs;
11049     uint                cur_free_qs;
11050     ASC_SCSI_BIT_ID_TYPE target_id;
11051     uchar               tid_no;
11052
11053     target_id = ASC_TIX_TO_TARGET_ID(target_ix);
11054     tid_no = ASC_TIX_TO_TID(target_ix);
11055     if ((asc_dvc->unit_not_ready & target_id) ||
11056         (asc_dvc->queue_full_or_busy & target_id)) {
11057         return (0);
11058     }
11059     if (n_qs == 1) {
11060         cur_used_qs = (uint) asc_dvc->cur_total_qng +
11061           (uint) asc_dvc->last_q_shortage +
11062           (uint) ASC_MIN_FREE_Q;
11063     } else {
11064         cur_used_qs = (uint) asc_dvc->cur_total_qng +
11065           (uint) ASC_MIN_FREE_Q;
11066     }
11067     if ((uint) (cur_used_qs + n_qs) <= (uint) asc_dvc->max_total_qng) {
11068         cur_free_qs = (uint) asc_dvc->max_total_qng - cur_used_qs;
11069         if (asc_dvc->cur_dvc_qng[tid_no] >=
11070             asc_dvc->max_dvc_qng[tid_no]) {
11071             return (0);
11072         }
11073         return (cur_free_qs);
11074     }
11075     if (n_qs > 1) {
11076         if ((n_qs > asc_dvc->last_q_shortage) && (n_qs <= (asc_dvc->max_total_qng - ASC_MIN_FREE_Q))) {
11077             asc_dvc->last_q_shortage = n_qs;
11078         }
11079     }
11080     return (0);
11081 }
11082
11083 STATIC int
11084 AscPutReadyQueue(
11085                     ASC_DVC_VAR *asc_dvc,
11086                     ASC_SCSI_Q *scsiq,
11087                     uchar q_no
11088 )
11089 {
11090     ushort              q_addr;
11091     uchar               tid_no;
11092     uchar               sdtr_data;
11093     uchar               syn_period_ix;
11094     uchar               syn_offset;
11095     PortAddr            iop_base;
11096
11097     iop_base = asc_dvc->iop_base;
11098     if (((asc_dvc->init_sdtr & scsiq->q1.target_id) != 0) &&
11099         ((asc_dvc->sdtr_done & scsiq->q1.target_id) == 0)) {
11100         tid_no = ASC_TIX_TO_TID(scsiq->q2.target_ix);
11101         sdtr_data = AscGetMCodeInitSDTRAtID(iop_base, tid_no);
11102         syn_period_ix = (sdtr_data >> 4) & (asc_dvc->max_sdtr_index - 1);
11103         syn_offset = sdtr_data & ASC_SYN_MAX_OFFSET;
11104         AscMsgOutSDTR(asc_dvc,
11105                       asc_dvc->sdtr_period_tbl[syn_period_ix],
11106                       syn_offset);
11107         scsiq->q1.cntl |= QC_MSG_OUT;
11108     }
11109     q_addr = ASC_QNO_TO_QADDR(q_no);
11110     if ((scsiq->q1.target_id & asc_dvc->use_tagged_qng) == 0) {
11111         scsiq->q2.tag_code &= ~MSG_SIMPLE_TAG ;
11112     }
11113     scsiq->q1.status = QS_FREE;
11114     AscMemWordCopyPtrToLram(iop_base,
11115                          q_addr + ASC_SCSIQ_CDB_BEG,
11116                          (uchar *) scsiq->cdbptr,
11117                          scsiq->q2.cdb_len >> 1);
11118
11119     DvcPutScsiQ(iop_base,
11120                 q_addr + ASC_SCSIQ_CPY_BEG,
11121                 (uchar *) &scsiq->q1.cntl,
11122                 ((sizeof(ASC_SCSIQ_1) + sizeof(ASC_SCSIQ_2)) / 2) - 1);
11123     AscWriteLramWord(iop_base,
11124                      (ushort) (q_addr + (ushort) ASC_SCSIQ_B_STATUS),
11125              (ushort) (((ushort) scsiq->q1.q_no << 8) | (ushort) QS_READY));
11126     return (1);
11127 }
11128
11129 STATIC int
11130 AscPutReadySgListQueue(
11131                           ASC_DVC_VAR *asc_dvc,
11132                           ASC_SCSI_Q *scsiq,
11133                           uchar q_no
11134 )
11135 {
11136     int                 sta;
11137     int                 i;
11138     ASC_SG_HEAD *sg_head;
11139     ASC_SG_LIST_Q       scsi_sg_q;
11140     ASC_DCNT            saved_data_addr;
11141     ASC_DCNT            saved_data_cnt;
11142     PortAddr            iop_base;
11143     ushort              sg_list_dwords;
11144     ushort              sg_index;
11145     ushort              sg_entry_cnt;
11146     ushort              q_addr;
11147     uchar               next_qp;
11148
11149     iop_base = asc_dvc->iop_base;
11150     sg_head = scsiq->sg_head;
11151     saved_data_addr = scsiq->q1.data_addr;
11152     saved_data_cnt = scsiq->q1.data_cnt;
11153     scsiq->q1.data_addr = (ASC_PADDR) sg_head->sg_list[0].addr;
11154     scsiq->q1.data_cnt = (ASC_DCNT) sg_head->sg_list[0].bytes;
11155 #if CC_VERY_LONG_SG_LIST
11156     /*
11157      * If sg_head->entry_cnt is greater than ASC_MAX_SG_LIST
11158      * then not all SG elements will fit in the allocated queues.
11159      * The rest of the SG elements will be copied when the RISC
11160      * completes the SG elements that fit and halts.
11161      */
11162     if (sg_head->entry_cnt > ASC_MAX_SG_LIST)
11163     {
11164          /*
11165           * Set sg_entry_cnt to be the number of SG elements that
11166           * will fit in the allocated SG queues. It is minus 1, because
11167           * the first SG element is handled above. ASC_MAX_SG_LIST is
11168           * already inflated by 1 to account for this. For example it
11169           * may be 50 which is 1 + 7 queues * 7 SG elements.
11170           */
11171          sg_entry_cnt = ASC_MAX_SG_LIST - 1;
11172
11173          /*
11174           * Keep track of remaining number of SG elements that will
11175           * need to be handled from a_isr.c.
11176           */
11177          scsiq->remain_sg_entry_cnt = sg_head->entry_cnt - ASC_MAX_SG_LIST;
11178     } else
11179     {
11180 #endif /* CC_VERY_LONG_SG_LIST */
11181          /*
11182           * Set sg_entry_cnt to be the number of SG elements that
11183           * will fit in the allocated SG queues. It is minus 1, because
11184           * the first SG element is handled above.
11185           */
11186          sg_entry_cnt = sg_head->entry_cnt - 1;
11187 #if CC_VERY_LONG_SG_LIST
11188     }
11189 #endif /* CC_VERY_LONG_SG_LIST */
11190     if (sg_entry_cnt != 0) {
11191         scsiq->q1.cntl |= QC_SG_HEAD;
11192         q_addr = ASC_QNO_TO_QADDR(q_no);
11193         sg_index = 1;
11194         scsiq->q1.sg_queue_cnt = sg_head->queue_cnt;
11195         scsi_sg_q.sg_head_qp = q_no;
11196         scsi_sg_q.cntl = QCSG_SG_XFER_LIST;
11197         for (i = 0; i < sg_head->queue_cnt; i++) {
11198             scsi_sg_q.seq_no = i + 1;
11199             if (sg_entry_cnt > ASC_SG_LIST_PER_Q) {
11200                 sg_list_dwords = (uchar) (ASC_SG_LIST_PER_Q * 2);
11201                 sg_entry_cnt -= ASC_SG_LIST_PER_Q;
11202                 if (i == 0) {
11203                     scsi_sg_q.sg_list_cnt = ASC_SG_LIST_PER_Q;
11204                     scsi_sg_q.sg_cur_list_cnt = ASC_SG_LIST_PER_Q;
11205                 } else {
11206                     scsi_sg_q.sg_list_cnt = ASC_SG_LIST_PER_Q - 1;
11207                     scsi_sg_q.sg_cur_list_cnt = ASC_SG_LIST_PER_Q - 1;
11208                 }
11209             } else {
11210 #if CC_VERY_LONG_SG_LIST
11211                 /*
11212                  * This is the last SG queue in the list of
11213                  * allocated SG queues. If there are more
11214                  * SG elements than will fit in the allocated
11215                  * queues, then set the QCSG_SG_XFER_MORE flag.
11216                  */
11217                 if (sg_head->entry_cnt > ASC_MAX_SG_LIST)
11218                 {
11219                     scsi_sg_q.cntl |= QCSG_SG_XFER_MORE;
11220                 } else
11221                 {
11222 #endif /* CC_VERY_LONG_SG_LIST */
11223                     scsi_sg_q.cntl |= QCSG_SG_XFER_END;
11224 #if CC_VERY_LONG_SG_LIST
11225                 }
11226 #endif /* CC_VERY_LONG_SG_LIST */
11227                 sg_list_dwords = sg_entry_cnt << 1;
11228                 if (i == 0) {
11229                     scsi_sg_q.sg_list_cnt = sg_entry_cnt;
11230                     scsi_sg_q.sg_cur_list_cnt = sg_entry_cnt;
11231                 } else {
11232                     scsi_sg_q.sg_list_cnt = sg_entry_cnt - 1;
11233                     scsi_sg_q.sg_cur_list_cnt = sg_entry_cnt - 1;
11234                 }
11235                 sg_entry_cnt = 0;
11236             }
11237             next_qp = AscReadLramByte(iop_base,
11238                                       (ushort) (q_addr + ASC_SCSIQ_B_FWD));
11239             scsi_sg_q.q_no = next_qp;
11240             q_addr = ASC_QNO_TO_QADDR(next_qp);
11241             AscMemWordCopyPtrToLram(iop_base,
11242                                 q_addr + ASC_SCSIQ_SGHD_CPY_BEG,
11243                                 (uchar *) &scsi_sg_q,
11244                                 sizeof(ASC_SG_LIST_Q) >> 1);
11245             AscMemDWordCopyPtrToLram(iop_base,
11246                                 q_addr + ASC_SGQ_LIST_BEG,
11247                                 (uchar *) &sg_head->sg_list[sg_index],
11248                                 sg_list_dwords);
11249             sg_index += ASC_SG_LIST_PER_Q;
11250             scsiq->next_sg_index = sg_index;
11251         }
11252     } else {
11253         scsiq->q1.cntl &= ~QC_SG_HEAD;
11254     }
11255     sta = AscPutReadyQueue(asc_dvc, scsiq, q_no);
11256     scsiq->q1.data_addr = saved_data_addr;
11257     scsiq->q1.data_cnt = saved_data_cnt;
11258     return (sta);
11259 }
11260
11261 STATIC int
11262 AscSetRunChipSynRegAtID(
11263                            PortAddr iop_base,
11264                            uchar tid_no,
11265                            uchar sdtr_data
11266 )
11267 {
11268     int                 sta = FALSE;
11269
11270     if (AscHostReqRiscHalt(iop_base)) {
11271         sta = AscSetChipSynRegAtID(iop_base, tid_no, sdtr_data);
11272         AscStartChip(iop_base);
11273         return (sta);
11274     }
11275     return (sta);
11276 }
11277
11278 STATIC int
11279 AscSetChipSynRegAtID(
11280                         PortAddr iop_base,
11281                         uchar id,
11282                         uchar sdtr_data
11283 )
11284 {
11285     ASC_SCSI_BIT_ID_TYPE org_id;
11286     int                 i;
11287     int                 sta = TRUE;
11288
11289     AscSetBank(iop_base, 1);
11290     org_id = AscReadChipDvcID(iop_base);
11291     for (i = 0; i <= ASC_MAX_TID; i++) {
11292         if (org_id == (0x01 << i))
11293             break;
11294     }
11295     org_id = (ASC_SCSI_BIT_ID_TYPE) i;
11296     AscWriteChipDvcID(iop_base, id);
11297     if (AscReadChipDvcID(iop_base) == (0x01 << id)) {
11298         AscSetBank(iop_base, 0);
11299         AscSetChipSyn(iop_base, sdtr_data);
11300         if (AscGetChipSyn(iop_base) != sdtr_data) {
11301             sta = FALSE;
11302         }
11303     } else {
11304         sta = FALSE;
11305     }
11306     AscSetBank(iop_base, 1);
11307     AscWriteChipDvcID(iop_base, org_id);
11308     AscSetBank(iop_base, 0);
11309     return (sta);
11310 }
11311
11312 STATIC ushort
11313 AscInitLram(
11314                ASC_DVC_VAR *asc_dvc
11315 )
11316 {
11317     uchar               i;
11318     ushort              s_addr;
11319     PortAddr            iop_base;
11320     ushort              warn_code;
11321
11322     iop_base = asc_dvc->iop_base;
11323     warn_code = 0;
11324     AscMemWordSetLram(iop_base, ASC_QADR_BEG, 0,
11325                (ushort) (((int) (asc_dvc->max_total_qng + 2 + 1) * 64) >> 1)
11326 );
11327     i = ASC_MIN_ACTIVE_QNO;
11328     s_addr = ASC_QADR_BEG + ASC_QBLK_SIZE;
11329     AscWriteLramByte(iop_base, (ushort) (s_addr + ASC_SCSIQ_B_FWD),
11330                      (uchar) (i + 1));
11331     AscWriteLramByte(iop_base, (ushort) (s_addr + ASC_SCSIQ_B_BWD),
11332                      (uchar) (asc_dvc->max_total_qng));
11333     AscWriteLramByte(iop_base, (ushort) (s_addr + ASC_SCSIQ_B_QNO),
11334                      (uchar) i);
11335     i++;
11336     s_addr += ASC_QBLK_SIZE;
11337     for (; i < asc_dvc->max_total_qng; i++, s_addr += ASC_QBLK_SIZE) {
11338         AscWriteLramByte(iop_base, (ushort) (s_addr + ASC_SCSIQ_B_FWD),
11339                          (uchar) (i + 1));
11340         AscWriteLramByte(iop_base, (ushort) (s_addr + ASC_SCSIQ_B_BWD),
11341                          (uchar) (i - 1));
11342         AscWriteLramByte(iop_base, (ushort) (s_addr + ASC_SCSIQ_B_QNO),
11343                          (uchar) i);
11344     }
11345     AscWriteLramByte(iop_base, (ushort) (s_addr + ASC_SCSIQ_B_FWD),
11346                      (uchar) ASC_QLINK_END);
11347     AscWriteLramByte(iop_base, (ushort) (s_addr + ASC_SCSIQ_B_BWD),
11348                      (uchar) (asc_dvc->max_total_qng - 1));
11349     AscWriteLramByte(iop_base, (ushort) (s_addr + ASC_SCSIQ_B_QNO),
11350                      (uchar) asc_dvc->max_total_qng);
11351     i++;
11352     s_addr += ASC_QBLK_SIZE;
11353     for (; i <= (uchar) (asc_dvc->max_total_qng + 3);
11354          i++, s_addr += ASC_QBLK_SIZE) {
11355         AscWriteLramByte(iop_base,
11356                          (ushort) (s_addr + (ushort) ASC_SCSIQ_B_FWD), i);
11357         AscWriteLramByte(iop_base,
11358                          (ushort) (s_addr + (ushort) ASC_SCSIQ_B_BWD), i);
11359         AscWriteLramByte(iop_base,
11360                          (ushort) (s_addr + (ushort) ASC_SCSIQ_B_QNO), i);
11361     }
11362     return (warn_code);
11363 }
11364
11365 STATIC ushort
11366 AscInitQLinkVar(
11367                    ASC_DVC_VAR *asc_dvc
11368 )
11369 {
11370     PortAddr            iop_base;
11371     int                 i;
11372     ushort              lram_addr;
11373
11374     iop_base = asc_dvc->iop_base;
11375     AscPutRiscVarFreeQHead(iop_base, 1);
11376     AscPutRiscVarDoneQTail(iop_base, asc_dvc->max_total_qng);
11377     AscPutVarFreeQHead(iop_base, 1);
11378     AscPutVarDoneQTail(iop_base, asc_dvc->max_total_qng);
11379     AscWriteLramByte(iop_base, ASCV_BUSY_QHEAD_B,
11380                      (uchar) ((int) asc_dvc->max_total_qng + 1));
11381     AscWriteLramByte(iop_base, ASCV_DISC1_QHEAD_B,
11382                      (uchar) ((int) asc_dvc->max_total_qng + 2));
11383     AscWriteLramByte(iop_base, (ushort) ASCV_TOTAL_READY_Q_B,
11384                      asc_dvc->max_total_qng);
11385     AscWriteLramWord(iop_base, ASCV_ASCDVC_ERR_CODE_W, 0);
11386     AscWriteLramWord(iop_base, ASCV_HALTCODE_W, 0);
11387     AscWriteLramByte(iop_base, ASCV_STOP_CODE_B, 0);
11388     AscWriteLramByte(iop_base, ASCV_SCSIBUSY_B, 0);
11389     AscWriteLramByte(iop_base, ASCV_WTM_FLAG_B, 0);
11390     AscPutQDoneInProgress(iop_base, 0);
11391     lram_addr = ASC_QADR_BEG;
11392     for (i = 0; i < 32; i++, lram_addr += 2) {
11393         AscWriteLramWord(iop_base, lram_addr, 0);
11394     }
11395     return (0);
11396 }
11397
11398 STATIC int
11399 AscSetLibErrorCode(
11400                       ASC_DVC_VAR *asc_dvc,
11401                       ushort err_code
11402 )
11403 {
11404     if (asc_dvc->err_code == 0) {
11405         asc_dvc->err_code = err_code;
11406         AscWriteLramWord(asc_dvc->iop_base, ASCV_ASCDVC_ERR_CODE_W,
11407                          err_code);
11408     }
11409     return (err_code);
11410 }
11411
11412
11413 STATIC uchar
11414 AscMsgOutSDTR(
11415                  ASC_DVC_VAR *asc_dvc,
11416                  uchar sdtr_period,
11417                  uchar sdtr_offset
11418 )
11419 {
11420     EXT_MSG             sdtr_buf;
11421     uchar               sdtr_period_index;
11422     PortAddr            iop_base;
11423
11424     iop_base = asc_dvc->iop_base;
11425     sdtr_buf.msg_type = MS_EXTEND;
11426     sdtr_buf.msg_len = MS_SDTR_LEN;
11427     sdtr_buf.msg_req = MS_SDTR_CODE;
11428     sdtr_buf.xfer_period = sdtr_period;
11429     sdtr_offset &= ASC_SYN_MAX_OFFSET;
11430     sdtr_buf.req_ack_offset = sdtr_offset;
11431     if ((sdtr_period_index =
11432          AscGetSynPeriodIndex(asc_dvc, sdtr_period)) <=
11433         asc_dvc->max_sdtr_index) {
11434         AscMemWordCopyPtrToLram(iop_base,
11435                              ASCV_MSGOUT_BEG,
11436                              (uchar *) &sdtr_buf,
11437                              sizeof (EXT_MSG) >> 1);
11438         return ((sdtr_period_index << 4) | sdtr_offset);
11439     } else {
11440
11441         sdtr_buf.req_ack_offset = 0;
11442         AscMemWordCopyPtrToLram(iop_base,
11443                              ASCV_MSGOUT_BEG,
11444                              (uchar *) &sdtr_buf,
11445                              sizeof (EXT_MSG) >> 1);
11446         return (0);
11447     }
11448 }
11449
11450 STATIC uchar
11451 AscCalSDTRData(
11452                   ASC_DVC_VAR *asc_dvc,
11453                   uchar sdtr_period,
11454                   uchar syn_offset
11455 )
11456 {
11457     uchar               byte;
11458     uchar               sdtr_period_ix;
11459
11460     sdtr_period_ix = AscGetSynPeriodIndex(asc_dvc, sdtr_period);
11461     if (
11462            (sdtr_period_ix > asc_dvc->max_sdtr_index)
11463 ) {
11464         return (0xFF);
11465     }
11466     byte = (sdtr_period_ix << 4) | (syn_offset & ASC_SYN_MAX_OFFSET);
11467     return (byte);
11468 }
11469
11470 STATIC void
11471 AscSetChipSDTR(
11472                   PortAddr iop_base,
11473                   uchar sdtr_data,
11474                   uchar tid_no
11475 )
11476 {
11477     AscSetChipSynRegAtID(iop_base, tid_no, sdtr_data);
11478     AscPutMCodeSDTRDoneAtID(iop_base, tid_no, sdtr_data);
11479     return;
11480 }
11481
11482 STATIC uchar
11483 AscGetSynPeriodIndex(
11484                         ASC_DVC_VAR *asc_dvc,
11485                         uchar syn_time
11486 )
11487 {
11488     uchar             *period_table;
11489     int                 max_index;
11490     int                 min_index;
11491     int                 i;
11492
11493     period_table = asc_dvc->sdtr_period_tbl;
11494     max_index = (int) asc_dvc->max_sdtr_index;
11495     min_index = (int)asc_dvc->host_init_sdtr_index;
11496     if ((syn_time <= period_table[max_index])) {
11497         for (i = min_index; i < (max_index - 1); i++) {
11498             if (syn_time <= period_table[i]) {
11499                 return ((uchar) i);
11500             }
11501         }
11502         return ((uchar) max_index);
11503     } else {
11504         return ((uchar) (max_index + 1));
11505     }
11506 }
11507
11508 STATIC uchar
11509 AscAllocFreeQueue(
11510                      PortAddr iop_base,
11511                      uchar free_q_head
11512 )
11513 {
11514     ushort              q_addr;
11515     uchar               next_qp;
11516     uchar               q_status;
11517
11518     q_addr = ASC_QNO_TO_QADDR(free_q_head);
11519     q_status = (uchar) AscReadLramByte(iop_base,
11520                                     (ushort) (q_addr + ASC_SCSIQ_B_STATUS));
11521     next_qp = AscReadLramByte(iop_base,
11522                               (ushort) (q_addr + ASC_SCSIQ_B_FWD));
11523     if (((q_status & QS_READY) == 0) && (next_qp != ASC_QLINK_END)) {
11524         return (next_qp);
11525     }
11526     return (ASC_QLINK_END);
11527 }
11528
11529 STATIC uchar
11530 AscAllocMultipleFreeQueue(
11531                              PortAddr iop_base,
11532                              uchar free_q_head,
11533                              uchar n_free_q
11534 )
11535 {
11536     uchar               i;
11537
11538     for (i = 0; i < n_free_q; i++) {
11539         if ((free_q_head = AscAllocFreeQueue(iop_base, free_q_head))
11540             == ASC_QLINK_END) {
11541             return (ASC_QLINK_END);
11542         }
11543     }
11544     return (free_q_head);
11545 }
11546
11547 STATIC int
11548 AscHostReqRiscHalt(
11549                       PortAddr iop_base
11550 )
11551 {
11552     int                 count = 0;
11553     int                 sta = 0;
11554     uchar               saved_stop_code;
11555
11556     if (AscIsChipHalted(iop_base))
11557         return (1);
11558     saved_stop_code = AscReadLramByte(iop_base, ASCV_STOP_CODE_B);
11559     AscWriteLramByte(iop_base, ASCV_STOP_CODE_B,
11560                      ASC_STOP_HOST_REQ_RISC_HALT | ASC_STOP_REQ_RISC_STOP
11561 );
11562     do {
11563         if (AscIsChipHalted(iop_base)) {
11564             sta = 1;
11565             break;
11566         }
11567         DvcSleepMilliSecond(100);
11568     } while (count++ < 20);
11569     AscWriteLramByte(iop_base, ASCV_STOP_CODE_B, saved_stop_code);
11570     return (sta);
11571 }
11572
11573 STATIC int
11574 AscStopQueueExe(
11575                    PortAddr iop_base
11576 )
11577 {
11578     int                 count = 0;
11579
11580     if (AscReadLramByte(iop_base, ASCV_STOP_CODE_B) == 0) {
11581         AscWriteLramByte(iop_base, ASCV_STOP_CODE_B,
11582                          ASC_STOP_REQ_RISC_STOP);
11583         do {
11584             if (
11585                    AscReadLramByte(iop_base, ASCV_STOP_CODE_B) &
11586                    ASC_STOP_ACK_RISC_STOP) {
11587                 return (1);
11588             }
11589             DvcSleepMilliSecond(100);
11590         } while (count++ < 20);
11591     }
11592     return (0);
11593 }
11594
11595 STATIC void
11596 DvcDelayMicroSecond(ADV_DVC_VAR *asc_dvc, ushort micro_sec)
11597 {
11598     udelay(micro_sec);
11599 }
11600
11601 STATIC void
11602 DvcDelayNanoSecond(ASC_DVC_VAR *asc_dvc, ASC_DCNT nano_sec)
11603 {
11604     udelay((nano_sec + 999)/1000);
11605 }
11606
11607 #ifdef CONFIG_ISA
11608 STATIC ASC_DCNT __init
11609 AscGetEisaProductID(
11610                        PortAddr iop_base)
11611 {
11612     PortAddr            eisa_iop;
11613     ushort              product_id_high, product_id_low;
11614     ASC_DCNT            product_id;
11615
11616     eisa_iop = ASC_GET_EISA_SLOT(iop_base) | ASC_EISA_PID_IOP_MASK;
11617     product_id_low = inpw(eisa_iop);
11618     product_id_high = inpw(eisa_iop + 2);
11619     product_id = ((ASC_DCNT) product_id_high << 16) |
11620         (ASC_DCNT) product_id_low;
11621     return (product_id);
11622 }
11623
11624 STATIC PortAddr __init
11625 AscSearchIOPortAddrEISA(
11626                            PortAddr iop_base)
11627 {
11628     ASC_DCNT            eisa_product_id;
11629
11630     if (iop_base == 0) {
11631         iop_base = ASC_EISA_MIN_IOP_ADDR;
11632     } else {
11633         if (iop_base == ASC_EISA_MAX_IOP_ADDR)
11634             return (0);
11635         if ((iop_base & 0x0050) == 0x0050) {
11636             iop_base += ASC_EISA_BIG_IOP_GAP;
11637         } else {
11638             iop_base += ASC_EISA_SMALL_IOP_GAP;
11639         }
11640     }
11641     while (iop_base <= ASC_EISA_MAX_IOP_ADDR) {
11642         eisa_product_id = AscGetEisaProductID(iop_base);
11643         if ((eisa_product_id == ASC_EISA_ID_740) ||
11644             (eisa_product_id == ASC_EISA_ID_750)) {
11645             if (AscFindSignature(iop_base)) {
11646                 inpw(iop_base + 4);
11647                 return (iop_base);
11648             }
11649         }
11650         if (iop_base == ASC_EISA_MAX_IOP_ADDR)
11651             return (0);
11652         if ((iop_base & 0x0050) == 0x0050) {
11653             iop_base += ASC_EISA_BIG_IOP_GAP;
11654         } else {
11655             iop_base += ASC_EISA_SMALL_IOP_GAP;
11656         }
11657     }
11658     return (0);
11659 }
11660 #endif /* CONFIG_ISA */
11661
11662 STATIC int
11663 AscStartChip(
11664                 PortAddr iop_base
11665 )
11666 {
11667     AscSetChipControl(iop_base, 0);
11668     if ((AscGetChipStatus(iop_base) & CSW_HALTED) != 0) {
11669         return (0);
11670     }
11671     return (1);
11672 }
11673
11674 STATIC int
11675 AscStopChip(
11676                PortAddr iop_base
11677 )
11678 {
11679     uchar               cc_val;
11680
11681     cc_val = AscGetChipControl(iop_base) & (~(CC_SINGLE_STEP | CC_TEST | CC_DIAG));
11682     AscSetChipControl(iop_base, (uchar) (cc_val | CC_HALT));
11683     AscSetChipIH(iop_base, INS_HALT);
11684     AscSetChipIH(iop_base, INS_RFLAG_WTM);
11685     if ((AscGetChipStatus(iop_base) & CSW_HALTED) == 0) {
11686         return (0);
11687     }
11688     return (1);
11689 }
11690
11691 STATIC int
11692 AscIsChipHalted(
11693                    PortAddr iop_base
11694 )
11695 {
11696     if ((AscGetChipStatus(iop_base) & CSW_HALTED) != 0) {
11697         if ((AscGetChipControl(iop_base) & CC_HALT) != 0) {
11698             return (1);
11699         }
11700     }
11701     return (0);
11702 }
11703
11704 STATIC void
11705 AscSetChipIH(
11706                 PortAddr iop_base,
11707                 ushort ins_code
11708 )
11709 {
11710     AscSetBank(iop_base, 1);
11711     AscWriteChipIH(iop_base, ins_code);
11712     AscSetBank(iop_base, 0);
11713     return;
11714 }
11715
11716 STATIC void
11717 AscAckInterrupt(
11718                    PortAddr iop_base
11719 )
11720 {
11721     uchar               host_flag;
11722     uchar               risc_flag;
11723     ushort              loop;
11724
11725     loop = 0;
11726     do {
11727         risc_flag = AscReadLramByte(iop_base, ASCV_RISC_FLAG_B);
11728         if (loop++ > 0x7FFF) {
11729             break;
11730         }
11731     } while ((risc_flag & ASC_RISC_FLAG_GEN_INT) != 0);
11732     host_flag = AscReadLramByte(iop_base, ASCV_HOST_FLAG_B) & (~ASC_HOST_FLAG_ACK_INT);
11733     AscWriteLramByte(iop_base, ASCV_HOST_FLAG_B,
11734                      (uchar) (host_flag | ASC_HOST_FLAG_ACK_INT));
11735     AscSetChipStatus(iop_base, CIW_INT_ACK);
11736     loop = 0;
11737     while (AscGetChipStatus(iop_base) & CSW_INT_PENDING) {
11738         AscSetChipStatus(iop_base, CIW_INT_ACK);
11739         if (loop++ > 3) {
11740             break;
11741         }
11742     }
11743     AscWriteLramByte(iop_base, ASCV_HOST_FLAG_B, host_flag);
11744     return;
11745 }
11746
11747 STATIC void
11748 AscDisableInterrupt(
11749                        PortAddr iop_base
11750 )
11751 {
11752     ushort              cfg;
11753
11754     cfg = AscGetChipCfgLsw(iop_base);
11755     AscSetChipCfgLsw(iop_base, cfg & (~ASC_CFG0_HOST_INT_ON));
11756     return;
11757 }
11758
11759 STATIC void
11760 AscEnableInterrupt(
11761                       PortAddr iop_base
11762 )
11763 {
11764     ushort              cfg;
11765
11766     cfg = AscGetChipCfgLsw(iop_base);
11767     AscSetChipCfgLsw(iop_base, cfg | ASC_CFG0_HOST_INT_ON);
11768     return;
11769 }
11770
11771
11772
11773 STATIC void
11774 AscSetBank(
11775               PortAddr iop_base,
11776               uchar bank
11777 )
11778 {
11779     uchar               val;
11780
11781     val = AscGetChipControl(iop_base) &
11782       (~(CC_SINGLE_STEP | CC_TEST | CC_DIAG | CC_SCSI_RESET | CC_CHIP_RESET));
11783     if (bank == 1) {
11784         val |= CC_BANK_ONE;
11785     } else if (bank == 2) {
11786         val |= CC_DIAG | CC_BANK_ONE;
11787     } else {
11788         val &= ~CC_BANK_ONE;
11789     }
11790     AscSetChipControl(iop_base, val);
11791     return;
11792 }
11793
11794 STATIC int
11795 AscResetChipAndScsiBus(
11796                           ASC_DVC_VAR *asc_dvc
11797 )
11798 {
11799     PortAddr    iop_base;
11800     int         i = 10;
11801
11802     iop_base = asc_dvc->iop_base;
11803     while ((AscGetChipStatus(iop_base) & CSW_SCSI_RESET_ACTIVE) && (i-- > 0))
11804     {
11805           DvcSleepMilliSecond(100);
11806     }
11807     AscStopChip(iop_base);
11808     AscSetChipControl(iop_base, CC_CHIP_RESET | CC_SCSI_RESET | CC_HALT);
11809     DvcDelayNanoSecond(asc_dvc, 60000);
11810     AscSetChipIH(iop_base, INS_RFLAG_WTM);
11811     AscSetChipIH(iop_base, INS_HALT);
11812     AscSetChipControl(iop_base, CC_CHIP_RESET | CC_HALT);
11813     AscSetChipControl(iop_base, CC_HALT);
11814     DvcSleepMilliSecond(200);
11815     AscSetChipStatus(iop_base, CIW_CLR_SCSI_RESET_INT);
11816     AscSetChipStatus(iop_base, 0);
11817     return (AscIsChipHalted(iop_base));
11818 }
11819
11820 STATIC ASC_DCNT __init
11821 AscGetMaxDmaCount(
11822                      ushort bus_type)
11823 {
11824     if (bus_type & ASC_IS_ISA)
11825         return (ASC_MAX_ISA_DMA_COUNT);
11826     else if (bus_type & (ASC_IS_EISA | ASC_IS_VL))
11827         return (ASC_MAX_VL_DMA_COUNT);
11828     return (ASC_MAX_PCI_DMA_COUNT);
11829 }
11830
11831 #ifdef CONFIG_ISA
11832 STATIC ushort __init
11833 AscGetIsaDmaChannel(
11834                        PortAddr iop_base)
11835 {
11836     ushort              channel;
11837
11838     channel = AscGetChipCfgLsw(iop_base) & 0x0003;
11839     if (channel == 0x03)
11840         return (0);
11841     else if (channel == 0x00)
11842         return (7);
11843     return (channel + 4);
11844 }
11845
11846 STATIC ushort __init
11847 AscSetIsaDmaChannel(
11848                        PortAddr iop_base,
11849                        ushort dma_channel)
11850 {
11851     ushort              cfg_lsw;
11852     uchar               value;
11853
11854     if ((dma_channel >= 5) && (dma_channel <= 7)) {
11855         if (dma_channel == 7)
11856             value = 0x00;
11857         else
11858             value = dma_channel - 4;
11859         cfg_lsw = AscGetChipCfgLsw(iop_base) & 0xFFFC;
11860         cfg_lsw |= value;
11861         AscSetChipCfgLsw(iop_base, cfg_lsw);
11862         return (AscGetIsaDmaChannel(iop_base));
11863     }
11864     return (0);
11865 }
11866
11867 STATIC uchar __init
11868 AscSetIsaDmaSpeed(
11869                      PortAddr iop_base,
11870                      uchar speed_value)
11871 {
11872     speed_value &= 0x07;
11873     AscSetBank(iop_base, 1);
11874     AscWriteChipDmaSpeed(iop_base, speed_value);
11875     AscSetBank(iop_base, 0);
11876     return (AscGetIsaDmaSpeed(iop_base));
11877 }
11878
11879 STATIC uchar __init
11880 AscGetIsaDmaSpeed(
11881                      PortAddr iop_base
11882 )
11883 {
11884     uchar               speed_value;
11885
11886     AscSetBank(iop_base, 1);
11887     speed_value = AscReadChipDmaSpeed(iop_base);
11888     speed_value &= 0x07;
11889     AscSetBank(iop_base, 0);
11890     return (speed_value);
11891 }
11892 #endif /* CONFIG_ISA */
11893
11894 STATIC ushort __init
11895 AscReadPCIConfigWord(
11896     ASC_DVC_VAR *asc_dvc,
11897     ushort pci_config_offset)
11898 {
11899     uchar       lsb, msb;
11900
11901     lsb = DvcReadPCIConfigByte(asc_dvc, pci_config_offset);
11902     msb = DvcReadPCIConfigByte(asc_dvc, pci_config_offset + 1);
11903     return ((ushort) ((msb << 8) | lsb));
11904 }
11905
11906 STATIC ushort __init
11907 AscInitGetConfig(
11908         ASC_DVC_VAR *asc_dvc
11909 )
11910 {
11911     ushort              warn_code;
11912     PortAddr            iop_base;
11913     ushort              PCIDeviceID;
11914     ushort              PCIVendorID;
11915     uchar               PCIRevisionID;
11916     uchar               prevCmdRegBits;
11917
11918     warn_code = 0;
11919     iop_base = asc_dvc->iop_base;
11920     asc_dvc->init_state = ASC_INIT_STATE_BEG_GET_CFG;
11921     if (asc_dvc->err_code != 0) {
11922         return (UW_ERR);
11923     }
11924     if (asc_dvc->bus_type == ASC_IS_PCI) {
11925         PCIVendorID = AscReadPCIConfigWord(asc_dvc,
11926                                     AscPCIConfigVendorIDRegister);
11927
11928         PCIDeviceID = AscReadPCIConfigWord(asc_dvc,
11929                                     AscPCIConfigDeviceIDRegister);
11930
11931         PCIRevisionID = DvcReadPCIConfigByte(asc_dvc,
11932                                     AscPCIConfigRevisionIDRegister);
11933
11934         if (PCIVendorID != ASC_PCI_VENDORID) {
11935             warn_code |= ASC_WARN_SET_PCI_CONFIG_SPACE;
11936         }
11937         prevCmdRegBits = DvcReadPCIConfigByte(asc_dvc,
11938                                     AscPCIConfigCommandRegister);
11939
11940         if ((prevCmdRegBits & AscPCICmdRegBits_IOMemBusMaster) !=
11941             AscPCICmdRegBits_IOMemBusMaster) {
11942             DvcWritePCIConfigByte(asc_dvc,
11943                             AscPCIConfigCommandRegister,
11944                             (prevCmdRegBits |
11945                              AscPCICmdRegBits_IOMemBusMaster));
11946
11947             if ((DvcReadPCIConfigByte(asc_dvc,
11948                                 AscPCIConfigCommandRegister)
11949                  & AscPCICmdRegBits_IOMemBusMaster)
11950                 != AscPCICmdRegBits_IOMemBusMaster) {
11951                 warn_code |= ASC_WARN_SET_PCI_CONFIG_SPACE;
11952             }
11953         }
11954         if ((PCIDeviceID == ASC_PCI_DEVICEID_1200A) ||
11955             (PCIDeviceID == ASC_PCI_DEVICEID_1200B)) {
11956             DvcWritePCIConfigByte(asc_dvc,
11957                             AscPCIConfigLatencyTimer, 0x00);
11958             if (DvcReadPCIConfigByte(asc_dvc, AscPCIConfigLatencyTimer)
11959                 != 0x00) {
11960                 warn_code |= ASC_WARN_SET_PCI_CONFIG_SPACE;
11961             }
11962         } else if (PCIDeviceID == ASC_PCI_DEVICEID_ULTRA) {
11963             if (DvcReadPCIConfigByte(asc_dvc,
11964                                 AscPCIConfigLatencyTimer) < 0x20) {
11965                 DvcWritePCIConfigByte(asc_dvc,
11966                                     AscPCIConfigLatencyTimer, 0x20);
11967
11968                 if (DvcReadPCIConfigByte(asc_dvc,
11969                                     AscPCIConfigLatencyTimer) < 0x20) {
11970                     warn_code |= ASC_WARN_SET_PCI_CONFIG_SPACE;
11971                 }
11972             }
11973         }
11974     }
11975
11976     if (AscFindSignature(iop_base)) {
11977         warn_code |= AscInitAscDvcVar(asc_dvc);
11978         warn_code |= AscInitFromEEP(asc_dvc);
11979         asc_dvc->init_state |= ASC_INIT_STATE_END_GET_CFG;
11980         if (asc_dvc->scsi_reset_wait > ASC_MAX_SCSI_RESET_WAIT) {
11981             asc_dvc->scsi_reset_wait = ASC_MAX_SCSI_RESET_WAIT;
11982         }
11983     } else {
11984         asc_dvc->err_code = ASC_IERR_BAD_SIGNATURE;
11985     }
11986     return(warn_code);
11987 }
11988
11989 STATIC ushort __init
11990 AscInitSetConfig(
11991                     ASC_DVC_VAR *asc_dvc
11992 )
11993 {
11994     ushort              warn_code = 0;
11995
11996     asc_dvc->init_state |= ASC_INIT_STATE_BEG_SET_CFG;
11997     if (asc_dvc->err_code != 0)
11998         return (UW_ERR);
11999     if (AscFindSignature(asc_dvc->iop_base)) {
12000         warn_code |= AscInitFromAscDvcVar(asc_dvc);
12001         asc_dvc->init_state |= ASC_INIT_STATE_END_SET_CFG;
12002     } else {
12003         asc_dvc->err_code = ASC_IERR_BAD_SIGNATURE;
12004     }
12005     return (warn_code);
12006 }
12007
12008 STATIC ushort __init
12009 AscInitFromAscDvcVar(
12010                         ASC_DVC_VAR *asc_dvc
12011 )
12012 {
12013     PortAddr            iop_base;
12014     ushort              cfg_msw;
12015     ushort              warn_code;
12016     ushort              pci_device_id;
12017
12018     iop_base = asc_dvc->iop_base;
12019     if (asc_dvc->cfg->dev)
12020         pci_device_id = to_pci_dev(asc_dvc->cfg->dev)->device;
12021     else
12022         pci_device_id = 0;
12023     warn_code = 0;
12024     cfg_msw = AscGetChipCfgMsw(iop_base);
12025     if ((cfg_msw & ASC_CFG_MSW_CLR_MASK) != 0) {
12026         cfg_msw &= (~(ASC_CFG_MSW_CLR_MASK));
12027         warn_code |= ASC_WARN_CFG_MSW_RECOVER;
12028         AscSetChipCfgMsw(iop_base, cfg_msw);
12029     }
12030     if ((asc_dvc->cfg->cmd_qng_enabled & asc_dvc->cfg->disc_enable) !=
12031         asc_dvc->cfg->cmd_qng_enabled) {
12032         asc_dvc->cfg->disc_enable = asc_dvc->cfg->cmd_qng_enabled;
12033         warn_code |= ASC_WARN_CMD_QNG_CONFLICT;
12034     }
12035     if (AscGetChipStatus(iop_base) & CSW_AUTO_CONFIG) {
12036         warn_code |= ASC_WARN_AUTO_CONFIG;
12037     }
12038     if ((asc_dvc->bus_type & (ASC_IS_ISA | ASC_IS_VL)) != 0) {
12039         if (AscSetChipIRQ(iop_base, asc_dvc->irq_no, asc_dvc->bus_type)
12040             != asc_dvc->irq_no) {
12041             asc_dvc->err_code |= ASC_IERR_SET_IRQ_NO;
12042         }
12043     }
12044     if (asc_dvc->bus_type & ASC_IS_PCI) {
12045         cfg_msw &= 0xFFC0;
12046         AscSetChipCfgMsw(iop_base, cfg_msw);
12047         if ((asc_dvc->bus_type & ASC_IS_PCI_ULTRA) == ASC_IS_PCI_ULTRA) {
12048         } else {
12049             if ((pci_device_id == ASC_PCI_DEVICE_ID_REV_A) ||
12050                 (pci_device_id == ASC_PCI_DEVICE_ID_REV_B)) {
12051                 asc_dvc->bug_fix_cntl |= ASC_BUG_FIX_IF_NOT_DWB;
12052                 asc_dvc->bug_fix_cntl |= ASC_BUG_FIX_ASYN_USE_SYN;
12053             }
12054         }
12055     } else if (asc_dvc->bus_type == ASC_IS_ISAPNP) {
12056         if (AscGetChipVersion(iop_base, asc_dvc->bus_type)
12057             == ASC_CHIP_VER_ASYN_BUG) {
12058             asc_dvc->bug_fix_cntl |= ASC_BUG_FIX_ASYN_USE_SYN;
12059         }
12060     }
12061     if (AscSetChipScsiID(iop_base, asc_dvc->cfg->chip_scsi_id) !=
12062         asc_dvc->cfg->chip_scsi_id) {
12063         asc_dvc->err_code |= ASC_IERR_SET_SCSI_ID;
12064     }
12065 #ifdef CONFIG_ISA
12066     if (asc_dvc->bus_type & ASC_IS_ISA) {
12067         AscSetIsaDmaChannel(iop_base, asc_dvc->cfg->isa_dma_channel);
12068         AscSetIsaDmaSpeed(iop_base, asc_dvc->cfg->isa_dma_speed);
12069     }
12070 #endif /* CONFIG_ISA */
12071     return (warn_code);
12072 }
12073
12074 STATIC ushort
12075 AscInitAsc1000Driver(
12076                         ASC_DVC_VAR *asc_dvc
12077 )
12078 {
12079     ushort              warn_code;
12080     PortAddr            iop_base;
12081
12082     iop_base = asc_dvc->iop_base;
12083     warn_code = 0;
12084     if ((asc_dvc->dvc_cntl & ASC_CNTL_RESET_SCSI) &&
12085         !(asc_dvc->init_state & ASC_INIT_RESET_SCSI_DONE)) {
12086         AscResetChipAndScsiBus(asc_dvc);
12087         DvcSleepMilliSecond((ASC_DCNT)
12088             ((ushort) asc_dvc->scsi_reset_wait * 1000));
12089     }
12090     asc_dvc->init_state |= ASC_INIT_STATE_BEG_LOAD_MC;
12091     if (asc_dvc->err_code != 0)
12092         return (UW_ERR);
12093     if (!AscFindSignature(asc_dvc->iop_base)) {
12094         asc_dvc->err_code = ASC_IERR_BAD_SIGNATURE;
12095         return (warn_code);
12096     }
12097     AscDisableInterrupt(iop_base);
12098     warn_code |= AscInitLram(asc_dvc);
12099     if (asc_dvc->err_code != 0)
12100         return (UW_ERR);
12101     ASC_DBG1(1, "AscInitAsc1000Driver: _asc_mcode_chksum 0x%lx\n",
12102         (ulong) _asc_mcode_chksum);
12103     if (AscLoadMicroCode(iop_base, 0, _asc_mcode_buf,
12104                          _asc_mcode_size) != _asc_mcode_chksum) {
12105         asc_dvc->err_code |= ASC_IERR_MCODE_CHKSUM;
12106         return (warn_code);
12107     }
12108     warn_code |= AscInitMicroCodeVar(asc_dvc);
12109     asc_dvc->init_state |= ASC_INIT_STATE_END_LOAD_MC;
12110     AscEnableInterrupt(iop_base);
12111     return (warn_code);
12112 }
12113
12114 STATIC ushort __init
12115 AscInitAscDvcVar(
12116                     ASC_DVC_VAR *asc_dvc)
12117 {
12118     int                 i;
12119     PortAddr            iop_base;
12120     ushort              warn_code;
12121     uchar               chip_version;
12122
12123     iop_base = asc_dvc->iop_base;
12124     warn_code = 0;
12125     asc_dvc->err_code = 0;
12126     if ((asc_dvc->bus_type &
12127          (ASC_IS_ISA | ASC_IS_PCI | ASC_IS_EISA | ASC_IS_VL)) == 0) {
12128         asc_dvc->err_code |= ASC_IERR_NO_BUS_TYPE;
12129     }
12130     AscSetChipControl(iop_base, CC_HALT);
12131     AscSetChipStatus(iop_base, 0);
12132     asc_dvc->bug_fix_cntl = 0;
12133     asc_dvc->pci_fix_asyn_xfer = 0;
12134     asc_dvc->pci_fix_asyn_xfer_always = 0;
12135     /* asc_dvc->init_state initalized in AscInitGetConfig(). */
12136     asc_dvc->sdtr_done = 0;
12137     asc_dvc->cur_total_qng = 0;
12138     asc_dvc->is_in_int = 0;
12139     asc_dvc->in_critical_cnt = 0;
12140     asc_dvc->last_q_shortage = 0;
12141     asc_dvc->use_tagged_qng = 0;
12142     asc_dvc->no_scam = 0;
12143     asc_dvc->unit_not_ready = 0;
12144     asc_dvc->queue_full_or_busy = 0;
12145     asc_dvc->redo_scam = 0;
12146     asc_dvc->res2 = 0;
12147     asc_dvc->host_init_sdtr_index = 0;
12148     asc_dvc->cfg->can_tagged_qng = 0;
12149     asc_dvc->cfg->cmd_qng_enabled = 0;
12150     asc_dvc->dvc_cntl = ASC_DEF_DVC_CNTL;
12151     asc_dvc->init_sdtr = 0;
12152     asc_dvc->max_total_qng = ASC_DEF_MAX_TOTAL_QNG;
12153     asc_dvc->scsi_reset_wait = 3;
12154     asc_dvc->start_motor = ASC_SCSI_WIDTH_BIT_SET;
12155     asc_dvc->max_dma_count = AscGetMaxDmaCount(asc_dvc->bus_type);
12156     asc_dvc->cfg->sdtr_enable = ASC_SCSI_WIDTH_BIT_SET;
12157     asc_dvc->cfg->disc_enable = ASC_SCSI_WIDTH_BIT_SET;
12158     asc_dvc->cfg->chip_scsi_id = ASC_DEF_CHIP_SCSI_ID;
12159     asc_dvc->cfg->lib_serial_no = ASC_LIB_SERIAL_NUMBER;
12160     asc_dvc->cfg->lib_version = (ASC_LIB_VERSION_MAJOR << 8) |
12161       ASC_LIB_VERSION_MINOR;
12162     chip_version = AscGetChipVersion(iop_base, asc_dvc->bus_type);
12163     asc_dvc->cfg->chip_version = chip_version;
12164     asc_dvc->sdtr_period_tbl[0] = SYN_XFER_NS_0;
12165     asc_dvc->sdtr_period_tbl[1] = SYN_XFER_NS_1;
12166     asc_dvc->sdtr_period_tbl[2] = SYN_XFER_NS_2;
12167     asc_dvc->sdtr_period_tbl[3] = SYN_XFER_NS_3;
12168     asc_dvc->sdtr_period_tbl[4] = SYN_XFER_NS_4;
12169     asc_dvc->sdtr_period_tbl[5] = SYN_XFER_NS_5;
12170     asc_dvc->sdtr_period_tbl[6] = SYN_XFER_NS_6;
12171     asc_dvc->sdtr_period_tbl[7] = SYN_XFER_NS_7;
12172     asc_dvc->max_sdtr_index = 7;
12173     if ((asc_dvc->bus_type & ASC_IS_PCI) &&
12174         (chip_version >= ASC_CHIP_VER_PCI_ULTRA_3150)) {
12175         asc_dvc->bus_type = ASC_IS_PCI_ULTRA;
12176         asc_dvc->sdtr_period_tbl[0] = SYN_ULTRA_XFER_NS_0;
12177         asc_dvc->sdtr_period_tbl[1] = SYN_ULTRA_XFER_NS_1;
12178         asc_dvc->sdtr_period_tbl[2] = SYN_ULTRA_XFER_NS_2;
12179         asc_dvc->sdtr_period_tbl[3] = SYN_ULTRA_XFER_NS_3;
12180         asc_dvc->sdtr_period_tbl[4] = SYN_ULTRA_XFER_NS_4;
12181         asc_dvc->sdtr_period_tbl[5] = SYN_ULTRA_XFER_NS_5;
12182         asc_dvc->sdtr_period_tbl[6] = SYN_ULTRA_XFER_NS_6;
12183         asc_dvc->sdtr_period_tbl[7] = SYN_ULTRA_XFER_NS_7;
12184         asc_dvc->sdtr_period_tbl[8] = SYN_ULTRA_XFER_NS_8;
12185         asc_dvc->sdtr_period_tbl[9] = SYN_ULTRA_XFER_NS_9;
12186         asc_dvc->sdtr_period_tbl[10] = SYN_ULTRA_XFER_NS_10;
12187         asc_dvc->sdtr_period_tbl[11] = SYN_ULTRA_XFER_NS_11;
12188         asc_dvc->sdtr_period_tbl[12] = SYN_ULTRA_XFER_NS_12;
12189         asc_dvc->sdtr_period_tbl[13] = SYN_ULTRA_XFER_NS_13;
12190         asc_dvc->sdtr_period_tbl[14] = SYN_ULTRA_XFER_NS_14;
12191         asc_dvc->sdtr_period_tbl[15] = SYN_ULTRA_XFER_NS_15;
12192         asc_dvc->max_sdtr_index = 15;
12193         if (chip_version == ASC_CHIP_VER_PCI_ULTRA_3150)
12194         {
12195             AscSetExtraControl(iop_base,
12196                 (SEC_ACTIVE_NEGATE | SEC_SLEW_RATE));
12197         } else if (chip_version >= ASC_CHIP_VER_PCI_ULTRA_3050) {
12198             AscSetExtraControl(iop_base,
12199                 (SEC_ACTIVE_NEGATE | SEC_ENABLE_FILTER));
12200         }
12201     }
12202     if (asc_dvc->bus_type == ASC_IS_PCI) {
12203            AscSetExtraControl(iop_base, (SEC_ACTIVE_NEGATE | SEC_SLEW_RATE));
12204     }
12205
12206     asc_dvc->cfg->isa_dma_speed = ASC_DEF_ISA_DMA_SPEED;
12207     if (AscGetChipBusType(iop_base) == ASC_IS_ISAPNP) {
12208         AscSetChipIFC(iop_base, IFC_INIT_DEFAULT);
12209         asc_dvc->bus_type = ASC_IS_ISAPNP;
12210     }
12211 #ifdef CONFIG_ISA
12212     if ((asc_dvc->bus_type & ASC_IS_ISA) != 0) {
12213         asc_dvc->cfg->isa_dma_channel = (uchar) AscGetIsaDmaChannel(iop_base);
12214     }
12215 #endif /* CONFIG_ISA */
12216     for (i = 0; i <= ASC_MAX_TID; i++) {
12217         asc_dvc->cur_dvc_qng[i] = 0;
12218         asc_dvc->max_dvc_qng[i] = ASC_MAX_SCSI1_QNG;
12219         asc_dvc->scsiq_busy_head[i] = (ASC_SCSI_Q *) 0L;
12220         asc_dvc->scsiq_busy_tail[i] = (ASC_SCSI_Q *) 0L;
12221         asc_dvc->cfg->max_tag_qng[i] = ASC_MAX_INRAM_TAG_QNG;
12222     }
12223     return (warn_code);
12224 }
12225
12226 STATIC ushort __init
12227 AscInitFromEEP(ASC_DVC_VAR *asc_dvc)
12228 {
12229     ASCEEP_CONFIG       eep_config_buf;
12230     ASCEEP_CONFIG       *eep_config;
12231     PortAddr            iop_base;
12232     ushort              chksum;
12233     ushort              warn_code;
12234     ushort              cfg_msw, cfg_lsw;
12235     int                 i;
12236     int                 write_eep = 0;
12237
12238     iop_base = asc_dvc->iop_base;
12239     warn_code = 0;
12240     AscWriteLramWord(iop_base, ASCV_HALTCODE_W, 0x00FE);
12241     AscStopQueueExe(iop_base);
12242     if ((AscStopChip(iop_base) == FALSE) ||
12243         (AscGetChipScsiCtrl(iop_base) != 0)) {
12244         asc_dvc->init_state |= ASC_INIT_RESET_SCSI_DONE;
12245         AscResetChipAndScsiBus(asc_dvc);
12246         DvcSleepMilliSecond((ASC_DCNT)
12247             ((ushort) asc_dvc->scsi_reset_wait * 1000));
12248     }
12249     if (AscIsChipHalted(iop_base) == FALSE) {
12250         asc_dvc->err_code |= ASC_IERR_START_STOP_CHIP;
12251         return (warn_code);
12252     }
12253     AscSetPCAddr(iop_base, ASC_MCODE_START_ADDR);
12254     if (AscGetPCAddr(iop_base) != ASC_MCODE_START_ADDR) {
12255         asc_dvc->err_code |= ASC_IERR_SET_PC_ADDR;
12256         return (warn_code);
12257     }
12258     eep_config = (ASCEEP_CONFIG *) &eep_config_buf;
12259     cfg_msw = AscGetChipCfgMsw(iop_base);
12260     cfg_lsw = AscGetChipCfgLsw(iop_base);
12261     if ((cfg_msw & ASC_CFG_MSW_CLR_MASK) != 0) {
12262         cfg_msw &= (~(ASC_CFG_MSW_CLR_MASK));
12263         warn_code |= ASC_WARN_CFG_MSW_RECOVER;
12264         AscSetChipCfgMsw(iop_base, cfg_msw);
12265     }
12266     chksum = AscGetEEPConfig(iop_base, eep_config, asc_dvc->bus_type);
12267     ASC_DBG1(1, "AscInitFromEEP: chksum 0x%x\n", chksum);
12268     if (chksum == 0) {
12269         chksum = 0xaa55;
12270     }
12271     if (AscGetChipStatus(iop_base) & CSW_AUTO_CONFIG) {
12272         warn_code |= ASC_WARN_AUTO_CONFIG;
12273         if (asc_dvc->cfg->chip_version == 3) {
12274             if (eep_config->cfg_lsw != cfg_lsw) {
12275                 warn_code |= ASC_WARN_EEPROM_RECOVER;
12276                 eep_config->cfg_lsw = AscGetChipCfgLsw(iop_base);
12277             }
12278             if (eep_config->cfg_msw != cfg_msw) {
12279                 warn_code |= ASC_WARN_EEPROM_RECOVER;
12280                 eep_config->cfg_msw = AscGetChipCfgMsw(iop_base);
12281             }
12282         }
12283     }
12284     eep_config->cfg_msw &= ~ASC_CFG_MSW_CLR_MASK;
12285     eep_config->cfg_lsw |= ASC_CFG0_HOST_INT_ON;
12286     ASC_DBG1(1, "AscInitFromEEP: eep_config->chksum 0x%x\n",
12287         eep_config->chksum);
12288     if (chksum != eep_config->chksum) {
12289             if (AscGetChipVersion(iop_base, asc_dvc->bus_type) ==
12290                     ASC_CHIP_VER_PCI_ULTRA_3050 )
12291             {
12292                 ASC_DBG(1,
12293 "AscInitFromEEP: chksum error ignored; EEPROM-less board\n");
12294                 eep_config->init_sdtr = 0xFF;
12295                 eep_config->disc_enable = 0xFF;
12296                 eep_config->start_motor = 0xFF;
12297                 eep_config->use_cmd_qng = 0;
12298                 eep_config->max_total_qng = 0xF0;
12299                 eep_config->max_tag_qng = 0x20;
12300                 eep_config->cntl = 0xBFFF;
12301                 ASC_EEP_SET_CHIP_ID(eep_config, 7);
12302                 eep_config->no_scam = 0;
12303                 eep_config->adapter_info[0] = 0;
12304                 eep_config->adapter_info[1] = 0;
12305                 eep_config->adapter_info[2] = 0;
12306                 eep_config->adapter_info[3] = 0;
12307                 eep_config->adapter_info[4] = 0;
12308                 /* Indicate EEPROM-less board. */
12309                 eep_config->adapter_info[5] = 0xBB;
12310             } else {
12311                 ASC_PRINT(
12312 "AscInitFromEEP: EEPROM checksum error; Will try to re-write EEPROM.\n");
12313                 write_eep = 1;
12314                 warn_code |= ASC_WARN_EEPROM_CHKSUM;
12315             }
12316     }
12317     asc_dvc->cfg->sdtr_enable = eep_config->init_sdtr;
12318     asc_dvc->cfg->disc_enable = eep_config->disc_enable;
12319     asc_dvc->cfg->cmd_qng_enabled = eep_config->use_cmd_qng;
12320     asc_dvc->cfg->isa_dma_speed = ASC_EEP_GET_DMA_SPD(eep_config);
12321     asc_dvc->start_motor = eep_config->start_motor;
12322     asc_dvc->dvc_cntl = eep_config->cntl;
12323     asc_dvc->no_scam = eep_config->no_scam;
12324     asc_dvc->cfg->adapter_info[0] = eep_config->adapter_info[0];
12325     asc_dvc->cfg->adapter_info[1] = eep_config->adapter_info[1];
12326     asc_dvc->cfg->adapter_info[2] = eep_config->adapter_info[2];
12327     asc_dvc->cfg->adapter_info[3] = eep_config->adapter_info[3];
12328     asc_dvc->cfg->adapter_info[4] = eep_config->adapter_info[4];
12329     asc_dvc->cfg->adapter_info[5] = eep_config->adapter_info[5];
12330     if (!AscTestExternalLram(asc_dvc)) {
12331         if (((asc_dvc->bus_type & ASC_IS_PCI_ULTRA) == ASC_IS_PCI_ULTRA)) {
12332             eep_config->max_total_qng = ASC_MAX_PCI_ULTRA_INRAM_TOTAL_QNG;
12333             eep_config->max_tag_qng = ASC_MAX_PCI_ULTRA_INRAM_TAG_QNG;
12334         } else {
12335             eep_config->cfg_msw |= 0x0800;
12336             cfg_msw |= 0x0800;
12337             AscSetChipCfgMsw(iop_base, cfg_msw);
12338             eep_config->max_total_qng = ASC_MAX_PCI_INRAM_TOTAL_QNG;
12339             eep_config->max_tag_qng = ASC_MAX_INRAM_TAG_QNG;
12340         }
12341     } else {
12342     }
12343     if (eep_config->max_total_qng < ASC_MIN_TOTAL_QNG) {
12344         eep_config->max_total_qng = ASC_MIN_TOTAL_QNG;
12345     }
12346     if (eep_config->max_total_qng > ASC_MAX_TOTAL_QNG) {
12347         eep_config->max_total_qng = ASC_MAX_TOTAL_QNG;
12348     }
12349     if (eep_config->max_tag_qng > eep_config->max_total_qng) {
12350         eep_config->max_tag_qng = eep_config->max_total_qng;
12351     }
12352     if (eep_config->max_tag_qng < ASC_MIN_TAG_Q_PER_DVC) {
12353         eep_config->max_tag_qng = ASC_MIN_TAG_Q_PER_DVC;
12354     }
12355     asc_dvc->max_total_qng = eep_config->max_total_qng;
12356     if ((eep_config->use_cmd_qng & eep_config->disc_enable) !=
12357         eep_config->use_cmd_qng) {
12358         eep_config->disc_enable = eep_config->use_cmd_qng;
12359         warn_code |= ASC_WARN_CMD_QNG_CONFLICT;
12360     }
12361     if (asc_dvc->bus_type & (ASC_IS_ISA | ASC_IS_VL | ASC_IS_EISA)) {
12362         asc_dvc->irq_no = AscGetChipIRQ(iop_base, asc_dvc->bus_type);
12363     }
12364     ASC_EEP_SET_CHIP_ID(eep_config, ASC_EEP_GET_CHIP_ID(eep_config) & ASC_MAX_TID);
12365     asc_dvc->cfg->chip_scsi_id = ASC_EEP_GET_CHIP_ID(eep_config);
12366     if (((asc_dvc->bus_type & ASC_IS_PCI_ULTRA) == ASC_IS_PCI_ULTRA) &&
12367         !(asc_dvc->dvc_cntl & ASC_CNTL_SDTR_ENABLE_ULTRA)) {
12368         asc_dvc->host_init_sdtr_index = ASC_SDTR_ULTRA_PCI_10MB_INDEX;
12369     }
12370
12371     for (i = 0; i <= ASC_MAX_TID; i++) {
12372         asc_dvc->dos_int13_table[i] = eep_config->dos_int13_table[i];
12373         asc_dvc->cfg->max_tag_qng[i] = eep_config->max_tag_qng;
12374         asc_dvc->cfg->sdtr_period_offset[i] =
12375             (uchar) (ASC_DEF_SDTR_OFFSET |
12376                      (asc_dvc->host_init_sdtr_index << 4));
12377     }
12378     eep_config->cfg_msw = AscGetChipCfgMsw(iop_base);
12379     if (write_eep) {
12380         if ((i = AscSetEEPConfig(iop_base, eep_config, asc_dvc->bus_type)) !=
12381              0) {
12382                 ASC_PRINT1(
12383 "AscInitFromEEP: Failed to re-write EEPROM with %d errors.\n", i);
12384         } else {
12385                 ASC_PRINT("AscInitFromEEP: Succesfully re-wrote EEPROM.");
12386         }
12387     }
12388     return (warn_code);
12389 }
12390
12391 STATIC ushort
12392 AscInitMicroCodeVar(
12393                        ASC_DVC_VAR *asc_dvc
12394 )
12395 {
12396     int                 i;
12397     ushort              warn_code;
12398     PortAddr            iop_base;
12399     ASC_PADDR           phy_addr;
12400     ASC_DCNT            phy_size;
12401
12402     iop_base = asc_dvc->iop_base;
12403     warn_code = 0;
12404     for (i = 0; i <= ASC_MAX_TID; i++) {
12405         AscPutMCodeInitSDTRAtID(iop_base, i,
12406                                 asc_dvc->cfg->sdtr_period_offset[i]
12407 );
12408     }
12409
12410     AscInitQLinkVar(asc_dvc);
12411     AscWriteLramByte(iop_base, ASCV_DISC_ENABLE_B,
12412                      asc_dvc->cfg->disc_enable);
12413     AscWriteLramByte(iop_base, ASCV_HOSTSCSI_ID_B,
12414                      ASC_TID_TO_TARGET_ID(asc_dvc->cfg->chip_scsi_id));
12415
12416     /* Align overrun buffer on an 8 byte boundary. */
12417     phy_addr = virt_to_bus(asc_dvc->cfg->overrun_buf);
12418     phy_addr = cpu_to_le32((phy_addr + 7) & ~0x7);
12419     AscMemDWordCopyPtrToLram(iop_base, ASCV_OVERRUN_PADDR_D,
12420         (uchar *) &phy_addr, 1);
12421     phy_size = cpu_to_le32(ASC_OVERRUN_BSIZE - 8);
12422     AscMemDWordCopyPtrToLram(iop_base, ASCV_OVERRUN_BSIZE_D,
12423         (uchar *) &phy_size, 1);
12424
12425     asc_dvc->cfg->mcode_date =
12426         AscReadLramWord(iop_base, (ushort) ASCV_MC_DATE_W);
12427     asc_dvc->cfg->mcode_version =
12428         AscReadLramWord(iop_base, (ushort) ASCV_MC_VER_W);
12429
12430     AscSetPCAddr(iop_base, ASC_MCODE_START_ADDR);
12431     if (AscGetPCAddr(iop_base) != ASC_MCODE_START_ADDR) {
12432         asc_dvc->err_code |= ASC_IERR_SET_PC_ADDR;
12433         return (warn_code);
12434     }
12435     if (AscStartChip(iop_base) != 1) {
12436         asc_dvc->err_code |= ASC_IERR_START_STOP_CHIP;
12437         return (warn_code);
12438     }
12439
12440     return (warn_code);
12441 }
12442
12443 STATIC int __init
12444 AscTestExternalLram(
12445                        ASC_DVC_VAR *asc_dvc)
12446 {
12447     PortAddr            iop_base;
12448     ushort              q_addr;
12449     ushort              saved_word;
12450     int                 sta;
12451
12452     iop_base = asc_dvc->iop_base;
12453     sta = 0;
12454     q_addr = ASC_QNO_TO_QADDR(241);
12455     saved_word = AscReadLramWord(iop_base, q_addr);
12456     AscSetChipLramAddr(iop_base, q_addr);
12457     AscSetChipLramData(iop_base, 0x55AA);
12458     DvcSleepMilliSecond(10);
12459     AscSetChipLramAddr(iop_base, q_addr);
12460     if (AscGetChipLramData(iop_base) == 0x55AA) {
12461         sta = 1;
12462         AscWriteLramWord(iop_base, q_addr, saved_word);
12463     }
12464     return (sta);
12465 }
12466
12467 STATIC int __init
12468 AscWriteEEPCmdReg(
12469                      PortAddr iop_base,
12470                      uchar cmd_reg
12471 )
12472 {
12473     uchar               read_back;
12474     int                 retry;
12475
12476     retry = 0;
12477     while (TRUE) {
12478         AscSetChipEEPCmd(iop_base, cmd_reg);
12479         DvcSleepMilliSecond(1);
12480         read_back = AscGetChipEEPCmd(iop_base);
12481         if (read_back == cmd_reg) {
12482             return (1);
12483         }
12484         if (retry++ > ASC_EEP_MAX_RETRY) {
12485             return (0);
12486         }
12487     }
12488 }
12489
12490 STATIC int __init
12491 AscWriteEEPDataReg(
12492                       PortAddr iop_base,
12493                       ushort data_reg
12494 )
12495 {
12496     ushort              read_back;
12497     int                 retry;
12498
12499     retry = 0;
12500     while (TRUE) {
12501         AscSetChipEEPData(iop_base, data_reg);
12502         DvcSleepMilliSecond(1);
12503         read_back = AscGetChipEEPData(iop_base);
12504         if (read_back == data_reg) {
12505             return (1);
12506         }
12507         if (retry++ > ASC_EEP_MAX_RETRY) {
12508             return (0);
12509         }
12510     }
12511 }
12512
12513 STATIC void __init
12514 AscWaitEEPRead(void)
12515 {
12516     DvcSleepMilliSecond(1);
12517     return;
12518 }
12519
12520 STATIC void __init
12521 AscWaitEEPWrite(void)
12522 {
12523     DvcSleepMilliSecond(20);
12524     return;
12525 }
12526
12527 STATIC ushort __init
12528 AscReadEEPWord(
12529                   PortAddr iop_base,
12530                   uchar addr)
12531 {
12532     ushort              read_wval;
12533     uchar               cmd_reg;
12534
12535     AscWriteEEPCmdReg(iop_base, ASC_EEP_CMD_WRITE_DISABLE);
12536     AscWaitEEPRead();
12537     cmd_reg = addr | ASC_EEP_CMD_READ;
12538     AscWriteEEPCmdReg(iop_base, cmd_reg);
12539     AscWaitEEPRead();
12540     read_wval = AscGetChipEEPData(iop_base);
12541     AscWaitEEPRead();
12542     return (read_wval);
12543 }
12544
12545 STATIC ushort __init
12546 AscWriteEEPWord(
12547                    PortAddr iop_base,
12548                    uchar addr,
12549                    ushort word_val)
12550 {
12551     ushort              read_wval;
12552
12553     read_wval = AscReadEEPWord(iop_base, addr);
12554     if (read_wval != word_val) {
12555         AscWriteEEPCmdReg(iop_base, ASC_EEP_CMD_WRITE_ABLE);
12556         AscWaitEEPRead();
12557         AscWriteEEPDataReg(iop_base, word_val);
12558         AscWaitEEPRead();
12559         AscWriteEEPCmdReg(iop_base,
12560                           (uchar) ((uchar) ASC_EEP_CMD_WRITE | addr));
12561         AscWaitEEPWrite();
12562         AscWriteEEPCmdReg(iop_base, ASC_EEP_CMD_WRITE_DISABLE);
12563         AscWaitEEPRead();
12564         return (AscReadEEPWord(iop_base, addr));
12565     }
12566     return (read_wval);
12567 }
12568
12569 STATIC ushort __init
12570 AscGetEEPConfig(
12571                    PortAddr iop_base,
12572                    ASCEEP_CONFIG * cfg_buf, ushort bus_type)
12573 {
12574     ushort              wval;
12575     ushort              sum;
12576     ushort              *wbuf;
12577     int                 cfg_beg;
12578     int                 cfg_end;
12579     int                 uchar_end_in_config = ASC_EEP_MAX_DVC_ADDR - 2;
12580     int                 s_addr;
12581
12582     wbuf = (ushort *) cfg_buf;
12583     sum = 0;
12584     /* Read two config words; Byte-swapping done by AscReadEEPWord(). */
12585     for (s_addr = 0; s_addr < 2; s_addr++, wbuf++) {
12586         *wbuf = AscReadEEPWord(iop_base, (uchar) s_addr);
12587         sum += *wbuf;
12588     }
12589     if (bus_type & ASC_IS_VL) {
12590         cfg_beg = ASC_EEP_DVC_CFG_BEG_VL;
12591         cfg_end = ASC_EEP_MAX_DVC_ADDR_VL;
12592     } else {
12593         cfg_beg = ASC_EEP_DVC_CFG_BEG;
12594         cfg_end = ASC_EEP_MAX_DVC_ADDR;
12595     }
12596     for (s_addr = cfg_beg; s_addr <= (cfg_end - 1); s_addr++, wbuf++) {
12597         wval = AscReadEEPWord( iop_base, ( uchar )s_addr ) ;
12598         if (s_addr <= uchar_end_in_config) {
12599             /*
12600              * Swap all char fields - must unswap bytes already swapped
12601              * by AscReadEEPWord().
12602              */
12603             *wbuf = le16_to_cpu(wval);
12604         } else {
12605             /* Don't swap word field at the end - cntl field. */
12606             *wbuf = wval;
12607         }
12608         sum += wval; /* Checksum treats all EEPROM data as words. */
12609     }
12610     /*
12611      * Read the checksum word which will be compared against 'sum'
12612      * by the caller. Word field already swapped.
12613      */
12614     *wbuf = AscReadEEPWord(iop_base, (uchar) s_addr);
12615     return (sum);
12616 }
12617
12618 STATIC int __init
12619 AscSetEEPConfigOnce(
12620                        PortAddr iop_base,
12621                        ASCEEP_CONFIG * cfg_buf, ushort bus_type)
12622 {
12623     int                 n_error;
12624     ushort              *wbuf;
12625     ushort              word;
12626     ushort              sum;
12627     int                 s_addr;
12628     int                 cfg_beg;
12629     int                 cfg_end;
12630     int                 uchar_end_in_config = ASC_EEP_MAX_DVC_ADDR - 2;
12631
12632
12633     wbuf = (ushort *) cfg_buf;
12634     n_error = 0;
12635     sum = 0;
12636     /* Write two config words; AscWriteEEPWord() will swap bytes. */
12637     for (s_addr = 0; s_addr < 2; s_addr++, wbuf++) {
12638         sum += *wbuf;
12639         if (*wbuf != AscWriteEEPWord(iop_base, (uchar) s_addr, *wbuf)) {
12640             n_error++;
12641         }
12642     }
12643     if (bus_type & ASC_IS_VL) {
12644         cfg_beg = ASC_EEP_DVC_CFG_BEG_VL;
12645         cfg_end = ASC_EEP_MAX_DVC_ADDR_VL;
12646     } else {
12647         cfg_beg = ASC_EEP_DVC_CFG_BEG;
12648         cfg_end = ASC_EEP_MAX_DVC_ADDR;
12649     }
12650     for (s_addr = cfg_beg; s_addr <= (cfg_end - 1); s_addr++, wbuf++) {
12651         if (s_addr <= uchar_end_in_config) {
12652             /*
12653              * This is a char field. Swap char fields before they are
12654              * swapped again by AscWriteEEPWord().
12655              */
12656             word = cpu_to_le16(*wbuf);
12657             if (word != AscWriteEEPWord( iop_base, (uchar) s_addr, word)) {
12658                 n_error++;
12659             }
12660         } else {
12661             /* Don't swap word field at the end - cntl field. */
12662             if (*wbuf != AscWriteEEPWord(iop_base, (uchar) s_addr, *wbuf)) {
12663                 n_error++;
12664             }
12665         }
12666         sum += *wbuf; /* Checksum calculated from word values. */
12667     }
12668     /* Write checksum word. It will be swapped by AscWriteEEPWord(). */
12669     *wbuf = sum;
12670     if (sum != AscWriteEEPWord(iop_base, (uchar) s_addr, sum)) {
12671         n_error++;
12672     }
12673
12674     /* Read EEPROM back again. */
12675     wbuf = (ushort *) cfg_buf;
12676     /*
12677      * Read two config words; Byte-swapping done by AscReadEEPWord().
12678      */
12679     for (s_addr = 0; s_addr < 2; s_addr++, wbuf++) {
12680         if (*wbuf != AscReadEEPWord(iop_base, (uchar) s_addr)) {
12681             n_error++;
12682         }
12683     }
12684     if (bus_type & ASC_IS_VL) {
12685         cfg_beg = ASC_EEP_DVC_CFG_BEG_VL;
12686         cfg_end = ASC_EEP_MAX_DVC_ADDR_VL;
12687     } else {
12688         cfg_beg = ASC_EEP_DVC_CFG_BEG;
12689         cfg_end = ASC_EEP_MAX_DVC_ADDR;
12690     }
12691     for (s_addr = cfg_beg; s_addr <= (cfg_end - 1); s_addr++, wbuf++) {
12692         if (s_addr <= uchar_end_in_config) {
12693             /*
12694              * Swap all char fields. Must unswap bytes already swapped
12695              * by AscReadEEPWord().
12696              */
12697             word = le16_to_cpu(AscReadEEPWord(iop_base, (uchar) s_addr));
12698         } else {
12699             /* Don't swap word field at the end - cntl field. */
12700             word = AscReadEEPWord(iop_base, (uchar) s_addr);
12701         }
12702         if (*wbuf != word) {
12703             n_error++;
12704         }
12705     }
12706     /* Read checksum; Byte swapping not needed. */
12707     if (AscReadEEPWord(iop_base, (uchar) s_addr) != sum) {
12708         n_error++;
12709     }
12710     return (n_error);
12711 }
12712
12713 STATIC int __init
12714 AscSetEEPConfig(
12715                    PortAddr iop_base,
12716                    ASCEEP_CONFIG * cfg_buf, ushort bus_type
12717 )
12718 {
12719     int            retry;
12720     int            n_error;
12721
12722     retry = 0;
12723     while (TRUE) {
12724         if ((n_error = AscSetEEPConfigOnce(iop_base, cfg_buf,
12725                                            bus_type)) == 0) {
12726             break;
12727         }
12728         if (++retry > ASC_EEP_MAX_RETRY) {
12729             break;
12730         }
12731     }
12732     return (n_error);
12733 }
12734
12735 STATIC void
12736 AscAsyncFix(
12737                ASC_DVC_VAR *asc_dvc,
12738                uchar tid_no,
12739                ASC_SCSI_INQUIRY *inq)
12740 {
12741     uchar                       dvc_type;
12742     ASC_SCSI_BIT_ID_TYPE        tid_bits;
12743
12744     dvc_type = ASC_INQ_DVC_TYPE(inq);
12745     tid_bits = ASC_TIX_TO_TARGET_ID(tid_no);
12746
12747     if (asc_dvc->bug_fix_cntl & ASC_BUG_FIX_ASYN_USE_SYN)
12748     {
12749         if (!(asc_dvc->init_sdtr & tid_bits))
12750         {
12751             if ((dvc_type == TYPE_ROM) &&
12752                 (AscCompareString((uchar *) inq->vendor_id,
12753                     (uchar *) "HP ", 3) == 0))
12754             {
12755                 asc_dvc->pci_fix_asyn_xfer_always |= tid_bits;
12756             }
12757             asc_dvc->pci_fix_asyn_xfer |= tid_bits;
12758             if ((dvc_type == TYPE_PROCESSOR) ||
12759                 (dvc_type == TYPE_SCANNER) ||
12760                 (dvc_type == TYPE_ROM) ||
12761                 (dvc_type == TYPE_TAPE))
12762             {
12763                 asc_dvc->pci_fix_asyn_xfer &= ~tid_bits;
12764             }
12765
12766             if (asc_dvc->pci_fix_asyn_xfer & tid_bits)
12767             {
12768                 AscSetRunChipSynRegAtID(asc_dvc->iop_base, tid_no,
12769                     ASYN_SDTR_DATA_FIX_PCI_REV_AB);
12770             }
12771         }
12772     }
12773     return;
12774 }
12775
12776 STATIC int
12777 AscTagQueuingSafe(ASC_SCSI_INQUIRY *inq)
12778 {
12779     if ((inq->add_len >= 32) &&
12780         (AscCompareString((uchar *) inq->vendor_id,
12781             (uchar *) "QUANTUM XP34301", 15) == 0) &&
12782         (AscCompareString((uchar *) inq->product_rev_level,
12783             (uchar *) "1071", 4) == 0))
12784     {
12785         return 0;
12786     }
12787     return 1;
12788 }
12789
12790 STATIC void
12791 AscInquiryHandling(ASC_DVC_VAR *asc_dvc,
12792                    uchar tid_no, ASC_SCSI_INQUIRY *inq)
12793 {
12794     ASC_SCSI_BIT_ID_TYPE tid_bit = ASC_TIX_TO_TARGET_ID(tid_no);
12795     ASC_SCSI_BIT_ID_TYPE orig_init_sdtr, orig_use_tagged_qng;
12796
12797     orig_init_sdtr = asc_dvc->init_sdtr;
12798     orig_use_tagged_qng = asc_dvc->use_tagged_qng;
12799
12800     asc_dvc->init_sdtr &= ~tid_bit;
12801     asc_dvc->cfg->can_tagged_qng &= ~tid_bit;
12802     asc_dvc->use_tagged_qng &= ~tid_bit;
12803
12804     if (ASC_INQ_RESPONSE_FMT(inq) >= 2 || ASC_INQ_ANSI_VER(inq) >= 2) {
12805         if ((asc_dvc->cfg->sdtr_enable & tid_bit) && ASC_INQ_SYNC(inq)) {
12806             asc_dvc->init_sdtr |= tid_bit;
12807         }
12808         if ((asc_dvc->cfg->cmd_qng_enabled & tid_bit) &&
12809              ASC_INQ_CMD_QUEUE(inq)) {
12810             if (AscTagQueuingSafe(inq)) {
12811                 asc_dvc->use_tagged_qng |= tid_bit;
12812                 asc_dvc->cfg->can_tagged_qng |= tid_bit;
12813             }
12814         }
12815     }
12816     if (orig_use_tagged_qng != asc_dvc->use_tagged_qng) {
12817         AscWriteLramByte(asc_dvc->iop_base, ASCV_DISC_ENABLE_B,
12818                          asc_dvc->cfg->disc_enable);
12819         AscWriteLramByte(asc_dvc->iop_base, ASCV_USE_TAGGED_QNG_B,
12820                          asc_dvc->use_tagged_qng);
12821         AscWriteLramByte(asc_dvc->iop_base, ASCV_CAN_TAGGED_QNG_B,
12822                          asc_dvc->cfg->can_tagged_qng);
12823
12824         asc_dvc->max_dvc_qng[tid_no] =
12825           asc_dvc->cfg->max_tag_qng[tid_no];
12826         AscWriteLramByte(asc_dvc->iop_base,
12827                          (ushort) (ASCV_MAX_DVC_QNG_BEG + tid_no),
12828                          asc_dvc->max_dvc_qng[tid_no]);
12829     }
12830     if (orig_init_sdtr != asc_dvc->init_sdtr) {
12831         AscAsyncFix(asc_dvc, tid_no, inq);
12832     }
12833     return;
12834 }
12835
12836 STATIC int
12837 AscCompareString(
12838                     uchar *str1,
12839                     uchar *str2,
12840                     int len
12841 )
12842 {
12843     int                 i;
12844     int                 diff;
12845
12846     for (i = 0; i < len; i++) {
12847         diff = (int) (str1[i] - str2[i]);
12848         if (diff != 0)
12849             return (diff);
12850     }
12851     return (0);
12852 }
12853
12854 STATIC uchar
12855 AscReadLramByte(
12856                    PortAddr iop_base,
12857                    ushort addr
12858 )
12859 {
12860     uchar               byte_data;
12861     ushort              word_data;
12862
12863     if (isodd_word(addr)) {
12864         AscSetChipLramAddr(iop_base, addr - 1);
12865         word_data = AscGetChipLramData(iop_base);
12866         byte_data = (uchar) ((word_data >> 8) & 0xFF);
12867     } else {
12868         AscSetChipLramAddr(iop_base, addr);
12869         word_data = AscGetChipLramData(iop_base);
12870         byte_data = (uchar) (word_data & 0xFF);
12871     }
12872     return (byte_data);
12873 }
12874 STATIC ushort
12875 AscReadLramWord(
12876                    PortAddr iop_base,
12877                    ushort addr
12878 )
12879 {
12880     ushort              word_data;
12881
12882     AscSetChipLramAddr(iop_base, addr);
12883     word_data = AscGetChipLramData(iop_base);
12884     return (word_data);
12885 }
12886
12887 #if CC_VERY_LONG_SG_LIST
12888 STATIC ASC_DCNT
12889 AscReadLramDWord(
12890                     PortAddr iop_base,
12891                     ushort addr
12892 )
12893 {
12894     ushort              val_low, val_high;
12895     ASC_DCNT            dword_data;
12896
12897     AscSetChipLramAddr(iop_base, addr);
12898     val_low = AscGetChipLramData(iop_base);
12899     val_high = AscGetChipLramData(iop_base);
12900     dword_data = ((ASC_DCNT) val_high << 16) | (ASC_DCNT) val_low;
12901     return (dword_data);
12902 }
12903 #endif /* CC_VERY_LONG_SG_LIST */
12904
12905 STATIC void
12906 AscWriteLramWord(
12907                     PortAddr iop_base,
12908                     ushort addr,
12909                     ushort word_val
12910 )
12911 {
12912     AscSetChipLramAddr(iop_base, addr);
12913     AscSetChipLramData(iop_base, word_val);
12914     return;
12915 }
12916
12917 STATIC void
12918 AscWriteLramByte(
12919                     PortAddr iop_base,
12920                     ushort addr,
12921                     uchar byte_val
12922 )
12923 {
12924     ushort              word_data;
12925
12926     if (isodd_word(addr)) {
12927         addr--;
12928         word_data = AscReadLramWord(iop_base, addr);
12929         word_data &= 0x00FF;
12930         word_data |= (((ushort) byte_val << 8) & 0xFF00);
12931     } else {
12932         word_data = AscReadLramWord(iop_base, addr);
12933         word_data &= 0xFF00;
12934         word_data |= ((ushort) byte_val & 0x00FF);
12935     }
12936     AscWriteLramWord(iop_base, addr, word_data);
12937     return;
12938 }
12939
12940 /*
12941  * Copy 2 bytes to LRAM.
12942  *
12943  * The source data is assumed to be in little-endian order in memory
12944  * and is maintained in little-endian order when written to LRAM.
12945  */
12946 STATIC void
12947 AscMemWordCopyPtrToLram(
12948                         PortAddr iop_base,
12949                         ushort s_addr,
12950                         uchar *s_buffer,
12951                         int words
12952 )
12953 {
12954     int    i;
12955
12956     AscSetChipLramAddr(iop_base, s_addr);
12957     for (i = 0; i < 2 * words; i += 2) {
12958         /*
12959          * On a little-endian system the second argument below
12960          * produces a little-endian ushort which is written to
12961          * LRAM in little-endian order. On a big-endian system
12962          * the second argument produces a big-endian ushort which
12963          * is "transparently" byte-swapped by outpw() and written
12964          * in little-endian order to LRAM.
12965          */
12966         outpw(iop_base + IOP_RAM_DATA,
12967             ((ushort) s_buffer[i + 1] << 8) | s_buffer[i]);
12968     }
12969     return;
12970 }
12971
12972 /*
12973  * Copy 4 bytes to LRAM.
12974  *
12975  * The source data is assumed to be in little-endian order in memory
12976  * and is maintained in little-endian order when writen to LRAM.
12977  */
12978 STATIC void
12979 AscMemDWordCopyPtrToLram(
12980                          PortAddr iop_base,
12981                          ushort s_addr,
12982                          uchar *s_buffer,
12983                          int dwords
12984 )
12985 {
12986     int       i;
12987
12988     AscSetChipLramAddr(iop_base, s_addr);
12989     for (i = 0; i < 4 * dwords; i += 4) {
12990         outpw(iop_base + IOP_RAM_DATA,
12991             ((ushort) s_buffer[i + 1] << 8) | s_buffer[i]); /* LSW */
12992         outpw(iop_base + IOP_RAM_DATA,
12993             ((ushort) s_buffer[i + 3] << 8) | s_buffer[i + 2]); /* MSW */
12994     }
12995     return;
12996 }
12997
12998 /*
12999  * Copy 2 bytes from LRAM.
13000  *
13001  * The source data is assumed to be in little-endian order in LRAM
13002  * and is maintained in little-endian order when written to memory.
13003  */
13004 STATIC void
13005 AscMemWordCopyPtrFromLram(
13006                           PortAddr iop_base,
13007                           ushort s_addr,
13008                           uchar *d_buffer,
13009                           int words
13010 )
13011 {
13012     int i;
13013     ushort word;
13014
13015     AscSetChipLramAddr(iop_base, s_addr);
13016     for (i = 0; i < 2 * words; i += 2) {
13017         word = inpw(iop_base + IOP_RAM_DATA);
13018         d_buffer[i] = word & 0xff;
13019         d_buffer[i + 1] = (word >> 8) & 0xff;
13020     }
13021     return;
13022 }
13023
13024 STATIC ASC_DCNT
13025 AscMemSumLramWord(
13026                      PortAddr iop_base,
13027                      ushort s_addr,
13028                      int words
13029 )
13030 {
13031     ASC_DCNT         sum;
13032     int              i;
13033
13034     sum = 0L;
13035     for (i = 0; i < words; i++, s_addr += 2) {
13036         sum += AscReadLramWord(iop_base, s_addr);
13037     }
13038     return (sum);
13039 }
13040
13041 STATIC void
13042 AscMemWordSetLram(
13043                      PortAddr iop_base,
13044                      ushort s_addr,
13045                      ushort set_wval,
13046                      int words
13047 )
13048 {
13049     int             i;
13050
13051     AscSetChipLramAddr(iop_base, s_addr);
13052     for (i = 0; i < words; i++) {
13053         AscSetChipLramData(iop_base, set_wval);
13054     }
13055     return;
13056 }
13057
13058
13059 /*
13060  * --- Adv Library Functions
13061  */
13062
13063 /* a_mcode.h */
13064
13065 /* Microcode buffer is kept after initialization for error recovery. */
13066 STATIC unsigned char _adv_asc3550_buf[] = {
13067   0x00,  0x00,  0x00,  0xf2,  0x00,  0xf0,  0x00,  0x16,  0x18,  0xe4,  0x00,  0xfc,  0x01,  0x00,  0x48,  0xe4,
13068   0xbe,  0x18,  0x18,  0x80,  0x03,  0xf6,  0x02,  0x00,  0x00,  0xfa,  0xff,  0xff,  0x28,  0x0e,  0x9e,  0xe7,
13069   0xff,  0x00,  0x82,  0xe7,  0x00,  0xea,  0x00,  0xf6,  0x01,  0xe6,  0x09,  0xe7,  0x55,  0xf0,  0x01,  0xf6,
13070   0x01,  0xfa,  0x08,  0x00,  0x03,  0x00,  0x04,  0x00,  0x18,  0xf4,  0x10,  0x00,  0x00,  0xec,  0x85,  0xf0,
13071   0xbc,  0x00,  0xd5,  0xf0,  0x8e,  0x0c,  0x38,  0x54,  0x00,  0xe6,  0x1e,  0xf0,  0x86,  0xf0,  0xb4,  0x00,
13072   0x98,  0x57,  0xd0,  0x01,  0x0c,  0x1c,  0x3e,  0x1c,  0x0c,  0x00,  0xbb,  0x00,  0xaa,  0x18,  0x02,  0x80,
13073   0x32,  0xf0,  0x01,  0xfc,  0x88,  0x0c,  0xc6,  0x12,  0x02,  0x13,  0x18,  0x40,  0x00,  0x57,  0x01,  0xea,
13074   0x3c,  0x00,  0x6c,  0x01,  0x6e,  0x01,  0x04,  0x12,  0x3e,  0x57,  0x00,  0x80,  0x03,  0xe6,  0xb6,  0x00,
13075   0xc0,  0x00,  0x01,  0x01,  0x3e,  0x01,  0xda,  0x0f,  0x22,  0x10,  0x08,  0x12,  0x02,  0x4a,  0xb9,  0x54,
13076   0x03,  0x58,  0x1b,  0x80,  0x30,  0xe4,  0x4b,  0xe4,  0x20,  0x00,  0x32,  0x00,  0x3e,  0x00,  0x80,  0x00,
13077   0x24,  0x01,  0x3c,  0x01,  0x68,  0x01,  0x6a,  0x01,  0x70,  0x01,  0x72,  0x01,  0x74,  0x01,  0x76,  0x01,
13078   0x78,  0x01,  0x62,  0x0a,  0x92,  0x0c,  0x2c,  0x10,  0x2e,  0x10,  0x06,  0x13,  0x4c,  0x1c,  0xbb,  0x55,
13079   0x3c,  0x56,  0x04,  0x80,  0x4a,  0xe4,  0x02,  0xee,  0x5b,  0xf0,  0xb1,  0xf0,  0x03,  0xf7,  0x06,  0xf7,
13080   0x03,  0xfc,  0x0f,  0x00,  0x40,  0x00,  0xbe,  0x00,  0x00,  0x01,  0xb0,  0x08,  0x30,  0x13,  0x64,  0x15,
13081   0x32,  0x1c,  0x38,  0x1c,  0x4e,  0x1c,  0x10,  0x44,  0x02,  0x48,  0x00,  0x4c,  0x04,  0xea,  0x5d,  0xf0,
13082   0x04,  0xf6,  0x02,  0xfc,  0x05,  0x00,  0x34,  0x00,  0x36,  0x00,  0x98,  0x00,  0xcc,  0x00,  0x20,  0x01,
13083   0x4e,  0x01,  0x4e,  0x0b,  0x1e,  0x0e,  0x0c,  0x10,  0x0a,  0x12,  0x04,  0x13,  0x40,  0x13,  0x30,  0x1c,
13084   0x00,  0x4e,  0xbd,  0x56,  0x06,  0x83,  0x00,  0xdc,  0x05,  0xf0,  0x09,  0xf0,  0x59,  0xf0,  0xa7,  0xf0,
13085   0xb8,  0xf0,  0x0e,  0xf7,  0x06,  0x00,  0x19,  0x00,  0x33,  0x00,  0x9b,  0x00,  0xa4,  0x00,  0xb5,  0x00,
13086   0xba,  0x00,  0xd0,  0x00,  0xe1,  0x00,  0xe7,  0x00,  0xde,  0x03,  0x56,  0x0a,  0x14,  0x0e,  0x02,  0x10,
13087   0x04,  0x10,  0x0a,  0x10,  0x36,  0x10,  0x0a,  0x13,  0x12,  0x13,  0x52,  0x13,  0x10,  0x15,  0x14,  0x15,
13088   0xac,  0x16,  0x20,  0x1c,  0x34,  0x1c,  0x36,  0x1c,  0x08,  0x44,  0x38,  0x44,  0x91,  0x44,  0x0a,  0x45,
13089   0x48,  0x46,  0x01,  0x48,  0x68,  0x54,  0x83,  0x55,  0xb0,  0x57,  0x01,  0x58,  0x83,  0x59,  0x05,  0xe6,
13090   0x0b,  0xf0,  0x0c,  0xf0,  0x5c,  0xf0,  0x4b,  0xf4,  0x04,  0xf8,  0x05,  0xf8,  0x02,  0xfa,  0x03,  0xfa,
13091   0x04,  0xfc,  0x05,  0xfc,  0x07,  0x00,  0x0a,  0x00,  0x0d,  0x00,  0x1c,  0x00,  0x9e,  0x00,  0xa8,  0x00,
13092   0xaa,  0x00,  0xb9,  0x00,  0xe0,  0x00,  0x22,  0x01,  0x26,  0x01,  0x79,  0x01,  0x7a,  0x01,  0xc0,  0x01,
13093   0xc2,  0x01,  0x7c,  0x02,  0x5a,  0x03,  0xea,  0x04,  0xe8,  0x07,  0x68,  0x08,  0x69,  0x08,  0xba,  0x08,
13094   0xe9,  0x09,  0x06,  0x0b,  0x3a,  0x0e,  0x00,  0x10,  0x1a,  0x10,  0xed,  0x10,  0xf1,  0x10,  0x06,  0x12,
13095   0x0c,  0x13,  0x16,  0x13,  0x1e,  0x13,  0x82,  0x13,  0x42,  0x14,  0xd6,  0x14,  0x8a,  0x15,  0xc6,  0x17,
13096   0xd2,  0x17,  0x6b,  0x18,  0x12,  0x1c,  0x46,  0x1c,  0x9c,  0x32,  0x00,  0x40,  0x0e,  0x47,  0x48,  0x47,
13097   0x41,  0x48,  0x89,  0x48,  0x80,  0x4c,  0x00,  0x54,  0x44,  0x55,  0xe5,  0x55,  0x14,  0x56,  0x77,  0x57,
13098   0xbf,  0x57,  0x40,  0x5c,  0x06,  0x80,  0x08,  0x90,  0x03,  0xa1,  0xfe,  0x9c,  0xf0,  0x29,  0x02,  0xfe,
13099   0xb8,  0x0c,  0xff,  0x10,  0x00,  0x00,  0xd0,  0xfe,  0xcc,  0x18,  0x00,  0xcf,  0xfe,  0x80,  0x01,  0xff,
13100   0x03,  0x00,  0x00,  0xfe,  0x93,  0x15,  0xfe,  0x0f,  0x05,  0xff,  0x38,  0x00,  0x00,  0xfe,  0x57,  0x24,
13101   0x00,  0xfe,  0x48,  0x00,  0x4f,  0xff,  0x04,  0x00,  0x00,  0x10,  0xff,  0x09,  0x00,  0x00,  0xff,  0x08,
13102   0x01,  0x01,  0xff,  0x08,  0xff,  0xff,  0xff,  0x27,  0x00,  0x00,  0xff,  0x10,  0xff,  0xff,  0xff,  0x0f,
13103   0x00,  0x00,  0xfe,  0x78,  0x56,  0xfe,  0x34,  0x12,  0xff,  0x21,  0x00,  0x00,  0xfe,  0x04,  0xf7,  0xcf,
13104   0x2a,  0x67,  0x0b,  0x01,  0xfe,  0xce,  0x0e,  0xfe,  0x04,  0xf7,  0xcf,  0x67,  0x0b,  0x3c,  0x2a,  0xfe,
13105   0x3d,  0xf0,  0xfe,  0x02,  0x02,  0xfe,  0x20,  0xf0,  0x9c,  0xfe,  0x91,  0xf0,  0xfe,  0xf0,  0x01,  0xfe,
13106   0x90,  0xf0,  0xfe,  0xf0,  0x01,  0xfe,  0x8f,  0xf0,  0x9c,  0x05,  0x51,  0x3b,  0x02,  0xfe,  0xd4,  0x0c,
13107   0x01,  0xfe,  0x44,  0x0d,  0xfe,  0xdd,  0x12,  0xfe,  0xfc,  0x10,  0xfe,  0x28,  0x1c,  0x05,  0xfe,  0xa6,
13108   0x00,  0xfe,  0xd3,  0x12,  0x47,  0x18,  0xfe,  0xa6,  0x00,  0xb5,  0xfe,  0x48,  0xf0,  0xfe,  0x86,  0x02,
13109   0xfe,  0x49,  0xf0,  0xfe,  0xa0,  0x02,  0xfe,  0x4a,  0xf0,  0xfe,  0xbe,  0x02,  0xfe,  0x46,  0xf0,  0xfe,
13110   0x50,  0x02,  0xfe,  0x47,  0xf0,  0xfe,  0x56,  0x02,  0xfe,  0x43,  0xf0,  0xfe,  0x44,  0x02,  0xfe,  0x44,
13111   0xf0,  0xfe,  0x48,  0x02,  0xfe,  0x45,  0xf0,  0xfe,  0x4c,  0x02,  0x17,  0x0b,  0xa0,  0x17,  0x06,  0x18,
13112   0x96,  0x02,  0x29,  0xfe,  0x00,  0x1c,  0xde,  0xfe,  0x02,  0x1c,  0xdd,  0xfe,  0x1e,  0x1c,  0xfe,  0xe9,
13113   0x10,  0x01,  0xfe,  0x20,  0x17,  0xfe,  0xe7,  0x10,  0xfe,  0x06,  0xfc,  0xc7,  0x0a,  0x6b,  0x01,  0x9e,
13114   0x02,  0x29,  0x14,  0x4d,  0x37,  0x97,  0x01,  0xfe,  0x64,  0x0f,  0x0a,  0x6b,  0x01,  0x82,  0xfe,  0xbd,
13115   0x10,  0x0a,  0x6b,  0x01,  0x82,  0xfe,  0xad,  0x10,  0xfe,  0x16,  0x1c,  0xfe,  0x58,  0x1c,  0x17,  0x06,
13116   0x18,  0x96,  0x2a,  0x25,  0x29,  0xfe,  0x3d,  0xf0,  0xfe,  0x02,  0x02,  0x21,  0xfe,  0x94,  0x02,  0xfe,
13117   0x5a,  0x1c,  0xea,  0xfe,  0x14,  0x1c,  0x14,  0xfe,  0x30,  0x00,  0x37,  0x97,  0x01,  0xfe,  0x54,  0x0f,
13118   0x17,  0x06,  0x18,  0x96,  0x02,  0xd0,  0x1e,  0x20,  0x07,  0x10,  0x34,  0xfe,  0x69,  0x10,  0x17,  0x06,
13119   0x18,  0x96,  0xfe,  0x04,  0xec,  0x20,  0x46,  0x3d,  0x12,  0x20,  0xfe,  0x05,  0xf6,  0xc7,  0x01,  0xfe,
13120   0x52,  0x16,  0x09,  0x4a,  0x4c,  0x35,  0x11,  0x2d,  0x3c,  0x8a,  0x01,  0xe6,  0x02,  0x29,  0x0a,  0x40,
13121   0x01,  0x0e,  0x07,  0x00,  0x5d,  0x01,  0x6f,  0xfe,  0x18,  0x10,  0xfe,  0x41,  0x58,  0x0a,  0x99,  0x01,
13122   0x0e,  0xfe,  0xc8,  0x54,  0x64,  0xfe,  0x0c,  0x03,  0x01,  0xe6,  0x02,  0x29,  0x2a,  0x46,  0xfe,  0x02,
13123   0xe8,  0x27,  0xf8,  0xfe,  0x9e,  0x43,  0xf7,  0xfe,  0x27,  0xf0,  0xfe,  0xdc,  0x01,  0xfe,  0x07,  0x4b,
13124   0xfe,  0x20,  0xf0,  0x9c,  0xfe,  0x40,  0x1c,  0x25,  0xd2,  0xfe,  0x26,  0xf0,  0xfe,  0x56,  0x03,  0xfe,
13125   0xa0,  0xf0,  0xfe,  0x44,  0x03,  0xfe,  0x11,  0xf0,  0x9c,  0xfe,  0xef,  0x10,  0xfe,  0x9f,  0xf0,  0xfe,
13126   0x64,  0x03,  0xeb,  0x0f,  0xfe,  0x11,  0x00,  0x02,  0x5a,  0x2a,  0xfe,  0x48,  0x1c,  0xeb,  0x09,  0x04,
13127   0x1d,  0xfe,  0x18,  0x13,  0x23,  0x1e,  0x98,  0xac,  0x12,  0x98,  0x0a,  0x40,  0x01,  0x0e,  0xac,  0x75,
13128   0x01,  0xfe,  0xbc,  0x15,  0x11,  0xca,  0x25,  0xd2,  0xfe,  0x01,  0xf0,  0xd2,  0xfe,  0x82,  0xf0,  0xfe,
13129   0x92,  0x03,  0xec,  0x11,  0xfe,  0xe4,  0x00,  0x65,  0xfe,  0xa4,  0x03,  0x25,  0x32,  0x1f,  0xfe,  0xb4,
13130   0x03,  0x01,  0x43,  0xfe,  0x06,  0xf0,  0xfe,  0xc4,  0x03,  0x8d,  0x81,  0xfe,  0x0a,  0xf0,  0xfe,  0x7a,
13131   0x06,  0x02,  0x22,  0x05,  0x6b,  0x28,  0x16,  0xfe,  0xf6,  0x04,  0x14,  0x2c,  0x01,  0x33,  0x8f,  0xfe,
13132   0x66,  0x02,  0x02,  0xd1,  0xeb,  0x2a,  0x67,  0x1a,  0xfe,  0x67,  0x1b,  0xf8,  0xf7,  0xfe,  0x48,  0x1c,
13133   0x70,  0x01,  0x6e,  0x87,  0x0a,  0x40,  0x01,  0x0e,  0x07,  0x00,  0x16,  0xd3,  0x0a,  0xca,  0x01,  0x0e,
13134   0x74,  0x60,  0x59,  0x76,  0x27,  0x05,  0x6b,  0x28,  0xfe,  0x10,  0x12,  0x14,  0x2c,  0x01,  0x33,  0x8f,
13135   0xfe,  0x66,  0x02,  0x02,  0xd1,  0xbc,  0x7d,  0xbd,  0x7f,  0x25,  0x22,  0x65,  0xfe,  0x3c,  0x04,  0x1f,
13136   0xfe,  0x38,  0x04,  0x68,  0xfe,  0xa0,  0x00,  0xfe,  0x9b,  0x57,  0xfe,  0x4e,  0x12,  0x2b,  0xff,  0x02,
13137   0x00,  0x10,  0x01,  0x08,  0x1f,  0xfe,  0xe0,  0x04,  0x2b,  0x01,  0x08,  0x1f,  0x22,  0x30,  0x2e,  0xd5,
13138   0xfe,  0x4c,  0x44,  0xfe,  0x4c,  0x12,  0x60,  0xfe,  0x44,  0x48,  0x13,  0x2c,  0xfe,  0x4c,  0x54,  0x64,
13139   0xd3,  0x46,  0x76,  0x27,  0xfa,  0xef,  0xfe,  0x62,  0x13,  0x09,  0x04,  0x1d,  0xfe,  0x2a,  0x13,  0x2f,
13140   0x07,  0x7e,  0xa5,  0xfe,  0x20,  0x10,  0x13,  0x2c,  0xfe,  0x4c,  0x54,  0x64,  0xd3,  0xfa,  0xef,  0x86,
13141   0x09,  0x04,  0x1d,  0xfe,  0x08,  0x13,  0x2f,  0x07,  0x7e,  0x6e,  0x09,  0x04,  0x1d,  0xfe,  0x1c,  0x12,
13142   0x14,  0x92,  0x09,  0x04,  0x06,  0x3b,  0x14,  0xc4,  0x01,  0x33,  0x8f,  0xfe,  0x70,  0x0c,  0x02,  0x22,
13143   0x2b,  0x11,  0xfe,  0xe6,  0x00,  0xfe,  0x1c,  0x90,  0xf9,  0x03,  0x14,  0x92,  0x01,  0x33,  0x02,  0x29,
13144   0xfe,  0x42,  0x5b,  0x67,  0x1a,  0xfe,  0x46,  0x59,  0xf8,  0xf7,  0xfe,  0x87,  0x80,  0xfe,  0x31,  0xe4,
13145   0x4f,  0x09,  0x04,  0x0b,  0xfe,  0x78,  0x13,  0xfe,  0x20,  0x80,  0x07,  0x1a,  0xfe,  0x70,  0x12,  0x49,
13146   0x04,  0x06,  0xfe,  0x60,  0x13,  0x05,  0xfe,  0xa2,  0x00,  0x28,  0x16,  0xfe,  0x80,  0x05,  0xfe,  0x31,
13147   0xe4,  0x6a,  0x49,  0x04,  0x0b,  0xfe,  0x4a,  0x13,  0x05,  0xfe,  0xa0,  0x00,  0x28,  0xfe,  0x42,  0x12,
13148   0x5e,  0x01,  0x08,  0x25,  0x32,  0xf1,  0x01,  0x08,  0x26,  0xfe,  0x98,  0x05,  0x11,  0xfe,  0xe3,  0x00,
13149   0x23,  0x49,  0xfe,  0x4a,  0xf0,  0xfe,  0x6a,  0x05,  0xfe,  0x49,  0xf0,  0xfe,  0x64,  0x05,  0x83,  0x24,
13150   0xfe,  0x21,  0x00,  0xa1,  0x24,  0xfe,  0x22,  0x00,  0xa0,  0x24,  0x4c,  0xfe,  0x09,  0x48,  0x01,  0x08,
13151   0x26,  0xfe,  0x98,  0x05,  0xfe,  0xe2,  0x08,  0x49,  0x04,  0xc5,  0x3b,  0x01,  0x86,  0x24,  0x06,  0x12,
13152   0xcc,  0x37,  0xfe,  0x27,  0x01,  0x09,  0x04,  0x1d,  0xfe,  0x22,  0x12,  0x47,  0x01,  0xa7,  0x14,  0x92,
13153   0x09,  0x04,  0x06,  0x3b,  0x14,  0xc4,  0x01,  0x33,  0x8f,  0xfe,  0x70,  0x0c,  0x02,  0x22,  0x05,  0xfe,
13154   0x9c,  0x00,  0x28,  0xfe,  0x3e,  0x12,  0x05,  0x50,  0x28,  0xfe,  0x36,  0x13,  0x47,  0x01,  0xa7,  0x26,
13155   0xfe,  0x08,  0x06,  0x0a,  0x06,  0x49,  0x04,  0x19,  0xfe,  0x02,  0x12,  0x5f,  0x01,  0xfe,  0xaa,  0x14,
13156   0x1f,  0xfe,  0xfe,  0x05,  0x11,  0x9a,  0x01,  0x43,  0x11,  0xfe,  0xe5,  0x00,  0x05,  0x50,  0xb4,  0x0c,
13157   0x50,  0x05,  0xc6,  0x28,  0xfe,  0x62,  0x12,  0x05,  0x3f,  0x28,  0xfe,  0x5a,  0x13,  0x01,  0xfe,  0x14,
13158   0x18,  0x01,  0xfe,  0x66,  0x18,  0xfe,  0x43,  0x48,  0xb7,  0x19,  0x13,  0x6c,  0xff,  0x02,  0x00,  0x57,
13159   0x48,  0x8b,  0x1c,  0x3d,  0x85,  0xb7,  0x69,  0x47,  0x01,  0xa7,  0x26,  0xfe,  0x72,  0x06,  0x49,  0x04,
13160   0x1b,  0xdf,  0x89,  0x0a,  0x4d,  0x01,  0xfe,  0xd8,  0x14,  0x1f,  0xfe,  0x68,  0x06,  0x11,  0x9a,  0x01,
13161   0x43,  0x11,  0xfe,  0xe5,  0x00,  0x05,  0x3f,  0xb4,  0x0c,  0x3f,  0x17,  0x06,  0x01,  0xa7,  0xec,  0x72,
13162   0x70,  0x01,  0x6e,  0x87,  0x11,  0xfe,  0xe2,  0x00,  0x01,  0x08,  0x25,  0x32,  0xfe,  0x0a,  0xf0,  0xfe,
13163   0xa6,  0x06,  0x8c,  0xfe,  0x5c,  0x07,  0xfe,  0x06,  0xf0,  0xfe,  0x64,  0x07,  0x8d,  0x81,  0x02,  0x22,
13164   0x09,  0x04,  0x0b,  0xfe,  0x2e,  0x12,  0x15,  0x1a,  0x01,  0x08,  0x15,  0x00,  0x01,  0x08,  0x15,  0x00,
13165   0x01,  0x08,  0x15,  0x00,  0x01,  0x08,  0xfe,  0x99,  0xa4,  0x01,  0x08,  0x15,  0x00,  0x02,  0xfe,  0x32,
13166   0x08,  0x61,  0x04,  0x1b,  0xfe,  0x38,  0x12,  0x09,  0x04,  0x1b,  0x6e,  0x15,  0xfe,  0x1b,  0x00,  0x01,
13167   0x08,  0x15,  0x00,  0x01,  0x08,  0x15,  0x00,  0x01,  0x08,  0x15,  0x00,  0x01,  0x08,  0x15,  0x06,  0x01,
13168   0x08,  0x15,  0x00,  0x02,  0xd9,  0x66,  0x4c,  0xfe,  0x3a,  0x55,  0x5f,  0xfe,  0x9a,  0x81,  0x4b,  0x1d,
13169   0xba,  0xfe,  0x32,  0x07,  0x0a,  0x1d,  0xfe,  0x09,  0x6f,  0xaf,  0xfe,  0xca,  0x45,  0xfe,  0x32,  0x12,
13170   0x62,  0x2c,  0x85,  0x66,  0x7b,  0x01,  0x08,  0x25,  0x32,  0xfe,  0x0a,  0xf0,  0xfe,  0x32,  0x07,  0x8d,
13171   0x81,  0x8c,  0xfe,  0x5c,  0x07,  0x02,  0x22,  0x01,  0x43,  0x02,  0xfe,  0x8a,  0x06,  0x15,  0x19,  0x02,
13172   0xfe,  0x8a,  0x06,  0xfe,  0x9c,  0xf7,  0xd4,  0xfe,  0x2c,  0x90,  0xfe,  0xae,  0x90,  0x77,  0xfe,  0xca,
13173   0x07,  0x0c,  0x54,  0x18,  0x55,  0x09,  0x4a,  0x6a,  0x35,  0x1e,  0x20,  0x07,  0x10,  0xfe,  0x0e,  0x12,
13174   0x74,  0xfe,  0x80,  0x80,  0x37,  0x20,  0x63,  0x27,  0xfe,  0x06,  0x10,  0xfe,  0x83,  0xe7,  0xc4,  0xa1,
13175   0xfe,  0x03,  0x40,  0x09,  0x4a,  0x4f,  0x35,  0x01,  0xa8,  0xad,  0xfe,  0x1f,  0x40,  0x12,  0x58,  0x01,
13176   0xa5,  0xfe,  0x08,  0x50,  0xfe,  0x8a,  0x50,  0xfe,  0x44,  0x51,  0xfe,  0xc6,  0x51,  0x83,  0xfb,  0xfe,
13177   0x8a,  0x90,  0x0c,  0x52,  0x18,  0x53,  0xfe,  0x0c,  0x90,  0xfe,  0x8e,  0x90,  0xfe,  0x40,  0x50,  0xfe,
13178   0xc2,  0x50,  0x0c,  0x39,  0x18,  0x3a,  0xfe,  0x4a,  0x10,  0x09,  0x04,  0x6a,  0xfe,  0x2a,  0x12,  0xfe,
13179   0x2c,  0x90,  0xfe,  0xae,  0x90,  0x0c,  0x54,  0x18,  0x55,  0x09,  0x04,  0x4f,  0x85,  0x01,  0xa8,  0xfe,
13180   0x1f,  0x80,  0x12,  0x58,  0xfe,  0x44,  0x90,  0xfe,  0xc6,  0x90,  0x0c,  0x56,  0x18,  0x57,  0xfb,  0xfe,
13181   0x8a,  0x90,  0x0c,  0x52,  0x18,  0x53,  0xfe,  0x40,  0x90,  0xfe,  0xc2,  0x90,  0x0c,  0x39,  0x18,  0x3a,
13182   0x0c,  0x38,  0x18,  0x4e,  0x09,  0x4a,  0x19,  0x35,  0x2a,  0x13,  0xfe,  0x4e,  0x11,  0x65,  0xfe,  0x48,
13183   0x08,  0xfe,  0x9e,  0xf0,  0xfe,  0x5c,  0x08,  0xb1,  0x16,  0x32,  0x2a,  0x73,  0xdd,  0xb8,  0xfe,  0x80,
13184   0x08,  0xb9,  0xfe,  0x9e,  0x08,  0x8c,  0xfe,  0x74,  0x08,  0xfe,  0x06,  0xf0,  0xfe,  0x7a,  0x08,  0x8d,
13185   0x81,  0x02,  0x22,  0x01,  0x43,  0xfe,  0xc9,  0x10,  0x15,  0x19,  0xfe,  0xc9,  0x10,  0x61,  0x04,  0x06,
13186   0xfe,  0x10,  0x12,  0x61,  0x04,  0x0b,  0x45,  0x09,  0x04,  0x0b,  0xfe,  0x68,  0x12,  0xfe,  0x2e,  0x1c,
13187   0x02,  0xfe,  0x24,  0x0a,  0x61,  0x04,  0x06,  0x45,  0x61,  0x04,  0x0b,  0xfe,  0x52,  0x12,  0xfe,  0x2c,
13188   0x1c,  0xfe,  0xaa,  0xf0,  0xfe,  0x1e,  0x09,  0xfe,  0xac,  0xf0,  0xfe,  0xbe,  0x08,  0xfe,  0x8a,  0x10,
13189   0xaa,  0xfe,  0xf3,  0x10,  0xfe,  0xad,  0xf0,  0xfe,  0xca,  0x08,  0x02,  0xfe,  0x24,  0x0a,  0xab,  0xfe,
13190   0xe7,  0x10,  0xfe,  0x2b,  0xf0,  0x9d,  0xe9,  0x1c,  0xfe,  0x00,  0xfe,  0xfe,  0x1c,  0x12,  0xb5,  0xfe,
13191   0xd2,  0xf0,  0x9d,  0xfe,  0x76,  0x18,  0x1c,  0x1a,  0x16,  0x9d,  0x05,  0xcb,  0x1c,  0x06,  0x16,  0x9d,
13192   0xb8,  0x6d,  0xb9,  0x6d,  0xaa,  0xab,  0xfe,  0xb1,  0x10,  0x70,  0x5e,  0x2b,  0x14,  0x92,  0x01,  0x33,
13193   0x0f,  0xfe,  0x35,  0x00,  0xfe,  0x01,  0xf0,  0x5a,  0x0f,  0x7c,  0x02,  0x5a,  0xfe,  0x74,  0x18,  0x1c,
13194   0xfe,  0x00,  0xf8,  0x16,  0x6d,  0x67,  0x1b,  0x01,  0xfe,  0x44,  0x0d,  0x3b,  0x01,  0xe6,  0x1e,  0x27,
13195   0x74,  0x67,  0x1a,  0x02,  0x6d,  0x09,  0x04,  0x0b,  0x21,  0xfe,  0x06,  0x0a,  0x09,  0x04,  0x6a,  0xfe,
13196   0x82,  0x12,  0x09,  0x04,  0x19,  0xfe,  0x66,  0x13,  0x1e,  0x58,  0xac,  0xfc,  0xfe,  0x83,  0x80,  0xfe,
13197   0xc8,  0x44,  0xfe,  0x2e,  0x13,  0xfe,  0x04,  0x91,  0xfe,  0x86,  0x91,  0x63,  0x27,  0xfe,  0x40,  0x59,
13198   0xfe,  0xc1,  0x59,  0x77,  0xd7,  0x05,  0x54,  0x31,  0x55,  0x0c,  0x7b,  0x18,  0x7c,  0xbe,  0x54,  0xbf,
13199   0x55,  0x01,  0xa8,  0xad,  0x63,  0x27,  0x12,  0x58,  0xc0,  0x38,  0xc1,  0x4e,  0x79,  0x56,  0x68,  0x57,
13200   0xf4,  0xf5,  0xfe,  0x04,  0xfa,  0x38,  0xfe,  0x05,  0xfa,  0x4e,  0x01,  0xa5,  0xa2,  0x23,  0x0c,  0x7b,
13201   0x0c,  0x7c,  0x79,  0x56,  0x68,  0x57,  0xfe,  0x12,  0x10,  0x09,  0x04,  0x19,  0x16,  0xd7,  0x79,  0x39,
13202   0x68,  0x3a,  0x09,  0x04,  0xfe,  0xf7,  0x00,  0x35,  0x05,  0x52,  0x31,  0x53,  0xfe,  0x10,  0x58,  0xfe,
13203   0x91,  0x58,  0xfe,  0x14,  0x59,  0xfe,  0x95,  0x59,  0x02,  0x6d,  0x09,  0x04,  0x19,  0x16,  0xd7,  0x09,
13204   0x04,  0xfe,  0xf7,  0x00,  0x35,  0xfe,  0x3a,  0x55,  0xfe,  0x19,  0x81,  0x5f,  0xfe,  0x10,  0x90,  0xfe,
13205   0x92,  0x90,  0xfe,  0xd7,  0x10,  0x2f,  0x07,  0x9b,  0x16,  0xfe,  0xc6,  0x08,  0x11,  0x9b,  0x09,  0x04,
13206   0x0b,  0xfe,  0x14,  0x13,  0x05,  0x39,  0x31,  0x3a,  0x77,  0xfe,  0xc6,  0x08,  0xfe,  0x0c,  0x58,  0xfe,
13207   0x8d,  0x58,  0x02,  0x6d,  0x23,  0x47,  0xfe,  0x19,  0x80,  0xde,  0x09,  0x04,  0x0b,  0xfe,  0x1a,  0x12,
13208   0xfe,  0x6c,  0x19,  0xfe,  0x19,  0x41,  0xe9,  0xb5,  0xfe,  0xd1,  0xf0,  0xd9,  0x14,  0x7a,  0x01,  0x33,
13209   0x0f,  0xfe,  0x44,  0x00,  0xfe,  0x8e,  0x10,  0xfe,  0x6c,  0x19,  0xbe,  0x39,  0xfe,  0xed,  0x19,  0xbf,
13210   0x3a,  0xfe,  0x0c,  0x51,  0xfe,  0x8e,  0x51,  0xe9,  0x1c,  0xfe,  0x00,  0xff,  0x34,  0xfe,  0x74,  0x10,
13211   0xb5,  0xfe,  0xd2,  0xf0,  0xfe,  0xb2,  0x0a,  0xfe,  0x76,  0x18,  0x1c,  0x1a,  0x84,  0x05,  0xcb,  0x1c,
13212   0x06,  0xfe,  0x08,  0x13,  0x0f,  0xfe,  0x16,  0x00,  0x02,  0x5a,  0xfe,  0xd1,  0xf0,  0xfe,  0xc4,  0x0a,
13213   0x14,  0x7a,  0x01,  0x33,  0x0f,  0xfe,  0x17,  0x00,  0xfe,  0x42,  0x10,  0xfe,  0xce,  0xf0,  0xfe,  0xca,
13214   0x0a,  0xfe,  0x3c,  0x10,  0xfe,  0xcd,  0xf0,  0xfe,  0xd6,  0x0a,  0x0f,  0xfe,  0x22,  0x00,  0x02,  0x5a,
13215   0xfe,  0xcb,  0xf0,  0xfe,  0xe2,  0x0a,  0x0f,  0xfe,  0x24,  0x00,  0x02,  0x5a,  0xfe,  0xd0,  0xf0,  0xfe,
13216   0xec,  0x0a,  0x0f,  0x93,  0xdc,  0xfe,  0xcf,  0xf0,  0xfe,  0xf6,  0x0a,  0x0f,  0x4c,  0xfe,  0x10,  0x10,
13217   0xfe,  0xcc,  0xf0,  0xd9,  0x61,  0x04,  0x19,  0x3b,  0x0f,  0xfe,  0x12,  0x00,  0x2a,  0x13,  0xfe,  0x4e,
13218   0x11,  0x65,  0xfe,  0x0c,  0x0b,  0xfe,  0x9e,  0xf0,  0xfe,  0x20,  0x0b,  0xb1,  0x16,  0x32,  0x2a,  0x73,
13219   0xdd,  0xb8,  0x22,  0xb9,  0x22,  0x2a,  0xec,  0x65,  0xfe,  0x2c,  0x0b,  0x25,  0x32,  0x8c,  0xfe,  0x48,
13220   0x0b,  0x8d,  0x81,  0xb8,  0xd4,  0xb9,  0xd4,  0x02,  0x22,  0x01,  0x43,  0xfe,  0xdb,  0x10,  0x11,  0xfe,
13221   0xe8,  0x00,  0xaa,  0xab,  0x70,  0xbc,  0x7d,  0xbd,  0x7f,  0xfe,  0x89,  0xf0,  0x22,  0x30,  0x2e,  0xd8,
13222   0xbc,  0x7d,  0xbd,  0x7f,  0x01,  0x08,  0x1f,  0x22,  0x30,  0x2e,  0xd6,  0xb1,  0x45,  0x0f,  0xfe,  0x42,
13223   0x00,  0x02,  0x5a,  0x78,  0x06,  0xfe,  0x81,  0x49,  0x16,  0xfe,  0x38,  0x0c,  0x09,  0x04,  0x0b,  0xfe,
13224   0x44,  0x13,  0x0f,  0x00,  0x4b,  0x0b,  0xfe,  0x54,  0x12,  0x4b,  0xfe,  0x28,  0x00,  0x21,  0xfe,  0xa6,
13225   0x0c,  0x0a,  0x40,  0x01,  0x0e,  0x07,  0x00,  0x5d,  0x3e,  0xfe,  0x28,  0x00,  0xfe,  0xe2,  0x10,  0x01,
13226   0xe7,  0x01,  0xe8,  0x0a,  0x99,  0x01,  0xfe,  0x32,  0x0e,  0x59,  0x11,  0x2d,  0x01,  0x6f,  0x02,  0x29,
13227   0x0f,  0xfe,  0x44,  0x00,  0x4b,  0x0b,  0xdf,  0x3e,  0x0b,  0xfe,  0xb4,  0x10,  0x01,  0x86,  0x3e,  0x0b,
13228   0xfe,  0xaa,  0x10,  0x01,  0x86,  0xfe,  0x19,  0x82,  0xfe,  0x34,  0x46,  0xa3,  0x3e,  0x0b,  0x0f,  0xfe,
13229   0x43,  0x00,  0xfe,  0x96,  0x10,  0x09,  0x4a,  0x0b,  0x35,  0x01,  0xe7,  0x01,  0xe8,  0x59,  0x11,  0x2d,
13230   0x01,  0x6f,  0x67,  0x0b,  0x59,  0x3c,  0x8a,  0x02,  0xfe,  0x2a,  0x03,  0x09,  0x04,  0x0b,  0x84,  0x3e,
13231   0x0b,  0x0f,  0x00,  0xfe,  0x5c,  0x10,  0x61,  0x04,  0x1b,  0xfe,  0x58,  0x12,  0x09,  0x04,  0x1b,  0xfe,
13232   0x50,  0x13,  0xfe,  0x1c,  0x1c,  0xfe,  0x9d,  0xf0,  0xfe,  0x5c,  0x0c,  0xfe,  0x1c,  0x1c,  0xfe,  0x9d,
13233   0xf0,  0xfe,  0x62,  0x0c,  0x09,  0x4a,  0x1b,  0x35,  0xfe,  0xa9,  0x10,  0x0f,  0xfe,  0x15,  0x00,  0xfe,
13234   0x04,  0xe6,  0x0b,  0x5f,  0x5c,  0x0f,  0xfe,  0x13,  0x00,  0xfe,  0x10,  0x10,  0x0f,  0xfe,  0x47,  0x00,
13235   0xa1,  0x0f,  0xfe,  0x41,  0x00,  0xa0,  0x0f,  0xfe,  0x24,  0x00,  0x87,  0xaa,  0xab,  0x70,  0x05,  0x6b,
13236   0x28,  0x21,  0xd1,  0x5f,  0xfe,  0x04,  0xe6,  0x1b,  0xfe,  0x9d,  0x41,  0xfe,  0x1c,  0x42,  0x59,  0x01,
13237   0xda,  0x02,  0x29,  0xea,  0x14,  0x0b,  0x37,  0x95,  0xa9,  0x14,  0xfe,  0x31,  0x00,  0x37,  0x97,  0x01,
13238   0xfe,  0x54,  0x0f,  0x02,  0xd0,  0x3c,  0xfe,  0x06,  0xec,  0xc9,  0xee,  0x3e,  0x1d,  0xfe,  0xce,  0x45,
13239   0x34,  0x3c,  0xfe,  0x06,  0xea,  0xc9,  0xfe,  0x47,  0x4b,  0x89,  0xfe,  0x75,  0x57,  0x05,  0x51,  0xfe,
13240   0x98,  0x56,  0xfe,  0x38,  0x12,  0x0a,  0x42,  0x01,  0x0e,  0xfe,  0x44,  0x48,  0x46,  0x09,  0x04,  0x1d,
13241   0xfe,  0x1a,  0x13,  0x0a,  0x40,  0x01,  0x0e,  0x47,  0xfe,  0x41,  0x58,  0x0a,  0x99,  0x01,  0x0e,  0xfe,
13242   0x49,  0x54,  0x8e,  0xfe,  0x2a,  0x0d,  0x02,  0xfe,  0x2a,  0x03,  0x0a,  0x51,  0xfe,  0xee,  0x14,  0xee,
13243   0x3e,  0x1d,  0xfe,  0xce,  0x45,  0x34,  0x3c,  0xfe,  0xce,  0x47,  0xfe,  0xad,  0x13,  0x02,  0x29,  0x1e,
13244   0x20,  0x07,  0x10,  0xfe,  0x9e,  0x12,  0x23,  0x12,  0x4d,  0x12,  0x94,  0x12,  0xce,  0x1e,  0x2d,  0x47,
13245   0x37,  0x2d,  0xb1,  0xe0,  0xfe,  0xbc,  0xf0,  0xfe,  0xec,  0x0d,  0x13,  0x06,  0x12,  0x4d,  0x01,  0xfe,
13246   0xe2,  0x15,  0x05,  0xfe,  0x38,  0x01,  0x31,  0xfe,  0x3a,  0x01,  0x77,  0xfe,  0xf0,  0x0d,  0xfe,  0x02,
13247   0xec,  0xce,  0x62,  0x00,  0x5d,  0xfe,  0x04,  0xec,  0x20,  0x46,  0xfe,  0x05,  0xf6,  0xfe,  0x34,  0x01,
13248   0x01,  0xfe,  0x52,  0x16,  0xfb,  0xfe,  0x48,  0xf4,  0x0d,  0xfe,  0x18,  0x13,  0xaf,  0xfe,  0x02,  0xea,
13249   0xce,  0x62,  0x7a,  0xfe,  0xc5,  0x13,  0x14,  0x1b,  0x37,  0x95,  0xa9,  0x5c,  0x05,  0xfe,  0x38,  0x01,
13250   0x1c,  0xfe,  0xf0,  0xff,  0x0c,  0xfe,  0x60,  0x01,  0x05,  0xfe,  0x3a,  0x01,  0x0c,  0xfe,  0x62,  0x01,
13251   0x3d,  0x12,  0x20,  0x24,  0x06,  0x12,  0x2d,  0x11,  0x2d,  0x8a,  0x13,  0x06,  0x03,  0x23,  0x03,  0x1e,
13252   0x4d,  0xfe,  0xf7,  0x12,  0x1e,  0x94,  0xac,  0x12,  0x94,  0x07,  0x7a,  0xfe,  0x71,  0x13,  0xfe,  0x24,
13253   0x1c,  0x14,  0x1a,  0x37,  0x95,  0xa9,  0xfe,  0xd9,  0x10,  0xb6,  0xfe,  0x03,  0xdc,  0xfe,  0x73,  0x57,
13254   0xfe,  0x80,  0x5d,  0x03,  0xb6,  0xfe,  0x03,  0xdc,  0xfe,  0x5b,  0x57,  0xfe,  0x80,  0x5d,  0x03,  0xfe,
13255   0x03,  0x57,  0xb6,  0x23,  0xfe,  0x00,  0xcc,  0x03,  0xfe,  0x03,  0x57,  0xb6,  0x75,  0x03,  0x09,  0x04,
13256   0x4c,  0xfe,  0x22,  0x13,  0xfe,  0x1c,  0x80,  0x07,  0x06,  0xfe,  0x1a,  0x13,  0xfe,  0x1e,  0x80,  0xe1,
13257   0xfe,  0x1d,  0x80,  0xa4,  0xfe,  0x0c,  0x90,  0xfe,  0x0e,  0x13,  0xfe,  0x0e,  0x90,  0xa3,  0xfe,  0x3c,
13258   0x90,  0xfe,  0x30,  0xf4,  0x0b,  0xfe,  0x3c,  0x50,  0xa0,  0x01,  0xfe,  0x82,  0x16,  0x2f,  0x07,  0x2d,
13259   0xe0,  0x01,  0xfe,  0xbc,  0x15,  0x09,  0x04,  0x1d,  0x45,  0x01,  0xe7,  0x01,  0xe8,  0x11,  0xfe,  0xe9,
13260   0x00,  0x09,  0x04,  0x4c,  0xfe,  0x2c,  0x13,  0x01,  0xfe,  0x14,  0x16,  0xfe,  0x1e,  0x1c,  0xfe,  0x14,
13261   0x90,  0xfe,  0x96,  0x90,  0x0c,  0xfe,  0x64,  0x01,  0x18,  0xfe,  0x66,  0x01,  0x09,  0x04,  0x4f,  0xfe,
13262   0x12,  0x12,  0xfe,  0x03,  0x80,  0x74,  0xfe,  0x01,  0xec,  0x20,  0xfe,  0x80,  0x40,  0x12,  0x20,  0x63,
13263   0x27,  0x11,  0xc8,  0x59,  0x1e,  0x20,  0xed,  0x76,  0x20,  0x03,  0xfe,  0x08,  0x1c,  0x05,  0xfe,  0xac,
13264   0x00,  0xfe,  0x06,  0x58,  0x05,  0xfe,  0xae,  0x00,  0xfe,  0x07,  0x58,  0x05,  0xfe,  0xb0,  0x00,  0xfe,
13265   0x08,  0x58,  0x05,  0xfe,  0xb2,  0x00,  0xfe,  0x09,  0x58,  0xfe,  0x0a,  0x1c,  0x24,  0x69,  0x12,  0xc9,
13266   0x23,  0x0c,  0x50,  0x0c,  0x3f,  0x13,  0x40,  0x48,  0x5f,  0x17,  0x1d,  0xfe,  0x90,  0x4d,  0xfe,  0x91,
13267   0x54,  0x21,  0xfe,  0x08,  0x0f,  0x3e,  0x10,  0x13,  0x42,  0x48,  0x17,  0x4c,  0xfe,  0x90,  0x4d,  0xfe,
13268   0x91,  0x54,  0x21,  0xfe,  0x1e,  0x0f,  0x24,  0x10,  0x12,  0x20,  0x78,  0x2c,  0x46,  0x1e,  0x20,  0xed,
13269   0x76,  0x20,  0x11,  0xc8,  0xf6,  0xfe,  0xd6,  0xf0,  0xfe,  0x32,  0x0f,  0xea,  0x70,  0xfe,  0x14,  0x1c,
13270   0xfe,  0x10,  0x1c,  0xfe,  0x18,  0x1c,  0x03,  0x3c,  0xfe,  0x0c,  0x14,  0xee,  0xfe,  0x07,  0xe6,  0x1d,
13271   0xfe,  0xce,  0x47,  0xfe,  0xf5,  0x13,  0x03,  0x01,  0x86,  0x78,  0x2c,  0x46,  0xfa,  0xef,  0xfe,  0x42,
13272   0x13,  0x2f,  0x07,  0x2d,  0xfe,  0x34,  0x13,  0x0a,  0x42,  0x01,  0x0e,  0xb0,  0xfe,  0x36,  0x12,  0xf0,
13273   0xfe,  0x45,  0x48,  0x01,  0xe3,  0xfe,  0x00,  0xcc,  0xb0,  0xfe,  0xf3,  0x13,  0x3d,  0x75,  0x07,  0x10,
13274   0xa3,  0x0a,  0x80,  0x01,  0x0e,  0xfe,  0x80,  0x5c,  0x01,  0x6f,  0xfe,  0x0e,  0x10,  0x07,  0x7e,  0x45,
13275   0xf6,  0xfe,  0xd6,  0xf0,  0xfe,  0x6c,  0x0f,  0x03,  0xfe,  0x44,  0x58,  0x74,  0xfe,  0x01,  0xec,  0x97,
13276   0xfe,  0x9e,  0x40,  0xfe,  0x9d,  0xe7,  0x00,  0xfe,  0x9c,  0xe7,  0x1b,  0x76,  0x27,  0x01,  0xda,  0xfe,
13277   0xdd,  0x10,  0x2a,  0xbc,  0x7d,  0xbd,  0x7f,  0x30,  0x2e,  0xd5,  0x07,  0x1b,  0xfe,  0x48,  0x12,  0x07,
13278   0x0b,  0xfe,  0x56,  0x12,  0x07,  0x1a,  0xfe,  0x30,  0x12,  0x07,  0xc2,  0x16,  0xfe,  0x3e,  0x11,  0x07,
13279   0xfe,  0x23,  0x00,  0x16,  0xfe,  0x4a,  0x11,  0x07,  0x06,  0x16,  0xfe,  0xa8,  0x11,  0x07,  0x19,  0xfe,
13280   0x12,  0x12,  0x07,  0x00,  0x16,  0x22,  0x14,  0xc2,  0x01,  0x33,  0x9f,  0x2b,  0x01,  0x08,  0x8c,  0x43,
13281   0x03,  0x2b,  0xfe,  0x62,  0x08,  0x0a,  0xca,  0x01,  0xfe,  0x32,  0x0e,  0x11,  0x7e,  0x02,  0x29,  0x2b,
13282   0x2f,  0x07,  0x9b,  0xfe,  0xd9,  0x13,  0x79,  0x39,  0x68,  0x3a,  0x77,  0xfe,  0xfc,  0x10,  0x09,  0x04,
13283   0x6a,  0xfe,  0x72,  0x12,  0xc0,  0x38,  0xc1,  0x4e,  0xf4,  0xf5,  0x8e,  0xfe,  0xc6,  0x10,  0x1e,  0x58,
13284   0xfe,  0x26,  0x13,  0x05,  0x7b,  0x31,  0x7c,  0x77,  0xfe,  0x82,  0x0c,  0x0c,  0x54,  0x18,  0x55,  0x23,
13285   0x0c,  0x7b,  0x0c,  0x7c,  0x01,  0xa8,  0x24,  0x69,  0x73,  0x12,  0x58,  0x01,  0xa5,  0xc0,  0x38,  0xc1,
13286   0x4e,  0xfe,  0x04,  0x55,  0xfe,  0xa5,  0x55,  0xfe,  0x04,  0xfa,  0x38,  0xfe,  0x05,  0xfa,  0x4e,  0xfe,
13287   0x91,  0x10,  0x05,  0x56,  0x31,  0x57,  0xfe,  0x40,  0x56,  0xfe,  0xe1,  0x56,  0x0c,  0x56,  0x18,  0x57,
13288   0x83,  0xc0,  0x38,  0xc1,  0x4e,  0xf4,  0xf5,  0x05,  0x52,  0x31,  0x53,  0xfe,  0x00,  0x56,  0xfe,  0xa1,
13289   0x56,  0x0c,  0x52,  0x18,  0x53,  0x09,  0x04,  0x6a,  0xfe,  0x1e,  0x12,  0x1e,  0x58,  0xfe,  0x1f,  0x40,
13290   0x05,  0x54,  0x31,  0x55,  0xfe,  0x2c,  0x50,  0xfe,  0xae,  0x50,  0x05,  0x56,  0x31,  0x57,  0xfe,  0x44,
13291   0x50,  0xfe,  0xc6,  0x50,  0x05,  0x52,  0x31,  0x53,  0xfe,  0x08,  0x50,  0xfe,  0x8a,  0x50,  0x05,  0x39,
13292   0x31,  0x3a,  0xfe,  0x40,  0x50,  0xfe,  0xc2,  0x50,  0x02,  0x5c,  0x24,  0x06,  0x12,  0xcd,  0x02,  0x5b,
13293   0x2b,  0x01,  0x08,  0x1f,  0x44,  0x30,  0x2e,  0xd5,  0x07,  0x06,  0x21,  0x44,  0x2f,  0x07,  0x9b,  0x21,
13294   0x5b,  0x01,  0x6e,  0x1c,  0x3d,  0x16,  0x44,  0x09,  0x04,  0x0b,  0xe2,  0x79,  0x39,  0x68,  0x3a,  0xfe,
13295   0x0a,  0x55,  0x34,  0xfe,  0x8b,  0x55,  0xbe,  0x39,  0xbf,  0x3a,  0xfe,  0x0c,  0x51,  0xfe,  0x8e,  0x51,
13296   0x02,  0x5b,  0xfe,  0x19,  0x81,  0xaf,  0xfe,  0x19,  0x41,  0x02,  0x5b,  0x2b,  0x01,  0x08,  0x25,  0x32,
13297   0x1f,  0xa2,  0x30,  0x2e,  0xd8,  0x4b,  0x1a,  0xfe,  0xa6,  0x12,  0x4b,  0x0b,  0x3b,  0x02,  0x44,  0x01,
13298   0x08,  0x25,  0x32,  0x1f,  0xa2,  0x30,  0x2e,  0xd6,  0x07,  0x1a,  0x21,  0x44,  0x01,  0x08,  0x1f,  0xa2,
13299   0x30,  0x2e,  0xfe,  0xe8,  0x09,  0xfe,  0xc2,  0x49,  0x60,  0x05,  0xfe,  0x9c,  0x00,  0x28,  0x84,  0x49,
13300   0x04,  0x19,  0x34,  0x9f,  0xfe,  0xbb,  0x45,  0x4b,  0x00,  0x45,  0x3e,  0x06,  0x78,  0x3d,  0xfe,  0xda,
13301   0x14,  0x01,  0x6e,  0x87,  0xfe,  0x4b,  0x45,  0xe2,  0x2f,  0x07,  0x9a,  0xe1,  0x05,  0xc6,  0x28,  0x84,
13302   0x05,  0x3f,  0x28,  0x34,  0x5e,  0x02,  0x5b,  0xfe,  0xc0,  0x5d,  0xfe,  0xf8,  0x14,  0xfe,  0x03,  0x17,
13303   0x05,  0x50,  0xb4,  0x0c,  0x50,  0x5e,  0x2b,  0x01,  0x08,  0x26,  0x5c,  0x01,  0xfe,  0xaa,  0x14,  0x02,
13304   0x5c,  0x01,  0x08,  0x25,  0x32,  0x1f,  0x44,  0x30,  0x2e,  0xd6,  0x07,  0x06,  0x21,  0x44,  0x01,  0xfe,
13305   0x8e,  0x13,  0xfe,  0x42,  0x58,  0xfe,  0x82,  0x14,  0xfe,  0xa4,  0x14,  0x87,  0xfe,  0x4a,  0xf4,  0x0b,
13306   0x16,  0x44,  0xfe,  0x4a,  0xf4,  0x06,  0xfe,  0x0c,  0x12,  0x2f,  0x07,  0x9a,  0x85,  0x02,  0x5b,  0x05,
13307   0x3f,  0xb4,  0x0c,  0x3f,  0x5e,  0x2b,  0x01,  0x08,  0x26,  0x5c,  0x01,  0xfe,  0xd8,  0x14,  0x02,  0x5c,
13308   0x13,  0x06,  0x65,  0xfe,  0xca,  0x12,  0x26,  0xfe,  0xe0,  0x12,  0x72,  0xf1,  0x01,  0x08,  0x23,  0x72,
13309   0x03,  0x8f,  0xfe,  0xdc,  0x12,  0x25,  0xfe,  0xdc,  0x12,  0x1f,  0xfe,  0xca,  0x12,  0x5e,  0x2b,  0x01,
13310   0x08,  0xfe,  0xd5,  0x10,  0x13,  0x6c,  0xff,  0x02,  0x00,  0x57,  0x48,  0x8b,  0x1c,  0xfe,  0xff,  0x7f,
13311   0xfe,  0x30,  0x56,  0xfe,  0x00,  0x5c,  0x03,  0x13,  0x6c,  0xff,  0x02,  0x00,  0x57,  0x48,  0x8b,  0x1c,
13312   0x3d,  0xfe,  0x30,  0x56,  0xfe,  0x00,  0x5c,  0x03,  0x13,  0x6c,  0xff,  0x02,  0x00,  0x57,  0x48,  0x8b,
13313   0x03,  0x13,  0x6c,  0xff,  0x02,  0x00,  0x57,  0x48,  0x8b,  0xfe,  0x0b,  0x58,  0x03,  0x0a,  0x50,  0x01,
13314   0x82,  0x0a,  0x3f,  0x01,  0x82,  0x03,  0xfc,  0x1c,  0x10,  0xff,  0x03,  0x00,  0x54,  0xfe,  0x00,  0xf4,
13315   0x19,  0x48,  0xfe,  0x00,  0x7d,  0xfe,  0x01,  0x7d,  0xfe,  0x02,  0x7d,  0xfe,  0x03,  0x7c,  0x63,  0x27,
13316   0x0c,  0x52,  0x18,  0x53,  0xbe,  0x56,  0xbf,  0x57,  0x03,  0xfe,  0x62,  0x08,  0xfe,  0x82,  0x4a,  0xfe,
13317   0xe1,  0x1a,  0xfe,  0x83,  0x5a,  0x74,  0x03,  0x01,  0xfe,  0x14,  0x18,  0xfe,  0x42,  0x48,  0x5f,  0x60,
13318   0x89,  0x01,  0x08,  0x1f,  0xfe,  0xa2,  0x14,  0x30,  0x2e,  0xd8,  0x01,  0x08,  0x1f,  0xfe,  0xa2,  0x14,
13319   0x30,  0x2e,  0xfe,  0xe8,  0x0a,  0xfe,  0xc1,  0x59,  0x05,  0xc6,  0x28,  0xfe,  0xcc,  0x12,  0x49,  0x04,
13320   0x1b,  0xfe,  0xc4,  0x13,  0x23,  0x62,  0x1b,  0xe2,  0x4b,  0xc3,  0x64,  0xfe,  0xe8,  0x13,  0x3b,  0x13,
13321   0x06,  0x17,  0xc3,  0x78,  0xdb,  0xfe,  0x78,  0x10,  0xff,  0x02,  0x83,  0x55,  0xa1,  0xff,  0x02,  0x83,
13322   0x55,  0x62,  0x1a,  0xa4,  0xbb,  0xfe,  0x30,  0x00,  0x8e,  0xe4,  0x17,  0x2c,  0x13,  0x06,  0xfe,  0x56,
13323   0x10,  0x62,  0x0b,  0xe1,  0xbb,  0xfe,  0x64,  0x00,  0x8e,  0xe4,  0x0a,  0xfe,  0x64,  0x00,  0x17,  0x93,
13324   0x13,  0x06,  0xfe,  0x28,  0x10,  0x62,  0x06,  0xfe,  0x60,  0x13,  0xbb,  0xfe,  0xc8,  0x00,  0x8e,  0xe4,
13325   0x0a,  0xfe,  0xc8,  0x00,  0x17,  0x4d,  0x13,  0x06,  0x83,  0xbb,  0xfe,  0x90,  0x01,  0xba,  0xfe,  0x4e,
13326   0x14,  0x89,  0xfe,  0x12,  0x10,  0xfe,  0x43,  0xf4,  0x94,  0xfe,  0x56,  0xf0,  0xfe,  0x60,  0x14,  0xfe,
13327   0x04,  0xf4,  0x6c,  0xfe,  0x43,  0xf4,  0x93,  0xfe,  0xf3,  0x10,  0xf9,  0x01,  0xfe,  0x22,  0x13,  0x1c,
13328   0x3d,  0xfe,  0x10,  0x13,  0xfe,  0x00,  0x17,  0xfe,  0x4d,  0xe4,  0x69,  0xba,  0xfe,  0x9c,  0x14,  0xb7,
13329   0x69,  0xfe,  0x1c,  0x10,  0xfe,  0x00,  0x17,  0xfe,  0x4d,  0xe4,  0x19,  0xba,  0xfe,  0x9c,  0x14,  0xb7,
13330   0x19,  0x83,  0x60,  0x23,  0xfe,  0x4d,  0xf4,  0x00,  0xdf,  0x89,  0x13,  0x06,  0xfe,  0xb4,  0x56,  0xfe,
13331   0xc3,  0x58,  0x03,  0x60,  0x13,  0x0b,  0x03,  0x15,  0x06,  0x01,  0x08,  0x26,  0xe5,  0x15,  0x0b,  0x01,
13332   0x08,  0x26,  0xe5,  0x15,  0x1a,  0x01,  0x08,  0x26,  0xe5,  0x72,  0xfe,  0x89,  0x49,  0x01,  0x08,  0x03,
13333   0x15,  0x06,  0x01,  0x08,  0x26,  0xa6,  0x15,  0x1a,  0x01,  0x08,  0x26,  0xa6,  0x15,  0x06,  0x01,  0x08,
13334   0x26,  0xa6,  0xfe,  0x89,  0x49,  0x01,  0x08,  0x26,  0xa6,  0x72,  0xfe,  0x89,  0x4a,  0x01,  0x08,  0x03,
13335   0x60,  0x03,  0x1e,  0xcc,  0x07,  0x06,  0xfe,  0x44,  0x13,  0xad,  0x12,  0xcc,  0xfe,  0x49,  0xf4,  0x00,
13336   0x3b,  0x72,  0x9f,  0x5e,  0xfe,  0x01,  0xec,  0xfe,  0x27,  0x01,  0xf1,  0x01,  0x08,  0x2f,  0x07,  0xfe,
13337   0xe3,  0x00,  0xfe,  0x20,  0x13,  0x1f,  0xfe,  0x5a,  0x15,  0x23,  0x12,  0xcd,  0x01,  0x43,  0x1e,  0xcd,
13338   0x07,  0x06,  0x45,  0x09,  0x4a,  0x06,  0x35,  0x03,  0x0a,  0x42,  0x01,  0x0e,  0xed,  0x88,  0x07,  0x10,
13339   0xa4,  0x0a,  0x80,  0x01,  0x0e,  0x88,  0x0a,  0x51,  0x01,  0x9e,  0x03,  0x0a,  0x80,  0x01,  0x0e,  0x88,
13340   0xfe,  0x80,  0xe7,  0x10,  0x07,  0x10,  0x84,  0xfe,  0x45,  0x58,  0x01,  0xe3,  0x88,  0x03,  0x0a,  0x42,
13341   0x01,  0x0e,  0x88,  0x0a,  0x51,  0x01,  0x9e,  0x03,  0x0a,  0x42,  0x01,  0x0e,  0xfe,  0x80,  0x80,  0xf2,
13342   0xfe,  0x49,  0xe4,  0x10,  0xa4,  0x0a,  0x80,  0x01,  0x0e,  0xf2,  0x0a,  0x51,  0x01,  0x82,  0x03,  0x17,
13343   0x10,  0x71,  0x66,  0xfe,  0x60,  0x01,  0xfe,  0x18,  0xdf,  0xfe,  0x19,  0xde,  0xfe,  0x24,  0x1c,  0xfe,
13344   0x1d,  0xf7,  0x1d,  0x90,  0xfe,  0xf6,  0x15,  0x01,  0xfe,  0xfc,  0x16,  0xe0,  0x91,  0x1d,  0x66,  0xfe,
13345   0x2c,  0x01,  0xfe,  0x2f,  0x19,  0x03,  0xae,  0x21,  0xfe,  0xe6,  0x15,  0xfe,  0xda,  0x10,  0x17,  0x10,
13346   0x71,  0x05,  0xfe,  0x64,  0x01,  0xfe,  0x00,  0xf4,  0x19,  0xfe,  0x18,  0x58,  0x05,  0xfe,  0x66,  0x01,
13347   0xfe,  0x19,  0x58,  0x91,  0x19,  0xfe,  0x3c,  0x90,  0xfe,  0x30,  0xf4,  0x06,  0xfe,  0x3c,  0x50,  0x66,
13348   0xfe,  0x38,  0x00,  0xfe,  0x0f,  0x79,  0xfe,  0x1c,  0xf7,  0x19,  0x90,  0xfe,  0x40,  0x16,  0xfe,  0xb6,
13349   0x14,  0x34,  0x03,  0xae,  0x21,  0xfe,  0x18,  0x16,  0xfe,  0x9c,  0x10,  0x17,  0x10,  0x71,  0xfe,  0x83,
13350   0x5a,  0xfe,  0x18,  0xdf,  0xfe,  0x19,  0xde,  0xfe,  0x1d,  0xf7,  0x38,  0x90,  0xfe,  0x62,  0x16,  0xfe,
13351   0x94,  0x14,  0xfe,  0x10,  0x13,  0x91,  0x38,  0x66,  0x1b,  0xfe,  0xaf,  0x19,  0xfe,  0x98,  0xe7,  0x00,
13352   0x03,  0xae,  0x21,  0xfe,  0x56,  0x16,  0xfe,  0x6c,  0x10,  0x17,  0x10,  0x71,  0xfe,  0x30,  0xbc,  0xfe,
13353   0xb2,  0xbc,  0x91,  0xc5,  0x66,  0x1b,  0xfe,  0x0f,  0x79,  0xfe,  0x1c,  0xf7,  0xc5,  0x90,  0xfe,  0x9a,
13354   0x16,  0xfe,  0x5c,  0x14,  0x34,  0x03,  0xae,  0x21,  0xfe,  0x86,  0x16,  0xfe,  0x42,  0x10,  0xfe,  0x02,
13355   0xf6,  0x10,  0x71,  0xfe,  0x18,  0xfe,  0x54,  0xfe,  0x19,  0xfe,  0x55,  0xfc,  0xfe,  0x1d,  0xf7,  0x4f,
13356   0x90,  0xfe,  0xc0,  0x16,  0xfe,  0x36,  0x14,  0xfe,  0x1c,  0x13,  0x91,  0x4f,  0x47,  0xfe,  0x83,  0x58,
13357   0xfe,  0xaf,  0x19,  0xfe,  0x80,  0xe7,  0x10,  0xfe,  0x81,  0xe7,  0x10,  0x11,  0xfe,  0xdd,  0x00,  0x63,
13358   0x27,  0x03,  0x63,  0x27,  0xfe,  0x12,  0x45,  0x21,  0xfe,  0xb0,  0x16,  0x14,  0x06,  0x37,  0x95,  0xa9,
13359   0x02,  0x29,  0xfe,  0x39,  0xf0,  0xfe,  0x04,  0x17,  0x23,  0x03,  0xfe,  0x7e,  0x18,  0x1c,  0x1a,  0x5d,
13360   0x13,  0x0d,  0x03,  0x71,  0x05,  0xcb,  0x1c,  0x06,  0xfe,  0xef,  0x12,  0xfe,  0xe1,  0x10,  0x78,  0x2c,
13361   0x46,  0x2f,  0x07,  0x2d,  0xfe,  0x3c,  0x13,  0xfe,  0x82,  0x14,  0xfe,  0x42,  0x13,  0x3c,  0x8a,  0x0a,
13362   0x42,  0x01,  0x0e,  0xb0,  0xfe,  0x3e,  0x12,  0xf0,  0xfe,  0x45,  0x48,  0x01,  0xe3,  0xfe,  0x00,  0xcc,
13363   0xb0,  0xfe,  0xf3,  0x13,  0x3d,  0x75,  0x07,  0x10,  0xa3,  0x0a,  0x80,  0x01,  0x0e,  0xf2,  0x01,  0x6f,
13364   0xfe,  0x16,  0x10,  0x07,  0x7e,  0x85,  0xfe,  0x40,  0x14,  0xfe,  0x24,  0x12,  0xf6,  0xfe,  0xd6,  0xf0,
13365   0xfe,  0x24,  0x17,  0x17,  0x0b,  0x03,  0xfe,  0x9c,  0xe7,  0x0b,  0x0f,  0xfe,  0x15,  0x00,  0x59,  0x76,
13366   0x27,  0x01,  0xda,  0x17,  0x06,  0x03,  0x3c,  0x8a,  0x09,  0x4a,  0x1d,  0x35,  0x11,  0x2d,  0x01,  0x6f,
13367   0x17,  0x06,  0x03,  0xfe,  0x38,  0x90,  0xfe,  0xba,  0x90,  0x79,  0xc7,  0x68,  0xc8,  0xfe,  0x48,  0x55,
13368   0x34,  0xfe,  0xc9,  0x55,  0x03,  0x1e,  0x98,  0x73,  0x12,  0x98,  0x03,  0x0a,  0x99,  0x01,  0x0e,  0xf0,
13369   0x0a,  0x40,  0x01,  0x0e,  0xfe,  0x49,  0x44,  0x16,  0xfe,  0xf0,  0x17,  0x73,  0x75,  0x03,  0x0a,  0x42,
13370   0x01,  0x0e,  0x07,  0x10,  0x45,  0x0a,  0x51,  0x01,  0x9e,  0x0a,  0x40,  0x01,  0x0e,  0x73,  0x75,  0x03,
13371   0xfe,  0x4e,  0xe4,  0x1a,  0x64,  0xfe,  0x24,  0x18,  0x05,  0xfe,  0x90,  0x00,  0xfe,  0x3a,  0x45,  0x5b,
13372   0xfe,  0x4e,  0xe4,  0xc2,  0x64,  0xfe,  0x36,  0x18,  0x05,  0xfe,  0x92,  0x00,  0xfe,  0x02,  0xe6,  0x1b,
13373   0xdc,  0xfe,  0x4e,  0xe4,  0xfe,  0x0b,  0x00,  0x64,  0xfe,  0x48,  0x18,  0x05,  0xfe,  0x94,  0x00,  0xfe,
13374   0x02,  0xe6,  0x19,  0xfe,  0x08,  0x10,  0x05,  0xfe,  0x96,  0x00,  0xfe,  0x02,  0xe6,  0x2c,  0xfe,  0x4e,
13375   0x45,  0xfe,  0x0c,  0x12,  0xaf,  0xff,  0x04,  0x68,  0x54,  0xde,  0x1c,  0x69,  0x03,  0x07,  0x7a,  0xfe,
13376   0x5a,  0xf0,  0xfe,  0x74,  0x18,  0x24,  0xfe,  0x09,  0x00,  0xfe,  0x34,  0x10,  0x07,  0x1b,  0xfe,  0x5a,
13377   0xf0,  0xfe,  0x82,  0x18,  0x24,  0xc3,  0xfe,  0x26,  0x10,  0x07,  0x1a,  0x5d,  0x24,  0x2c,  0xdc,  0x07,
13378   0x0b,  0x5d,  0x24,  0x93,  0xfe,  0x0e,  0x10,  0x07,  0x06,  0x5d,  0x24,  0x4d,  0x9f,  0xad,  0x03,  0x14,
13379   0xfe,  0x09,  0x00,  0x01,  0x33,  0xfe,  0x04,  0xfe,  0x7d,  0x05,  0x7f,  0xf9,  0x03,  0x25,  0xfe,  0xca,
13380   0x18,  0xfe,  0x14,  0xf0,  0x08,  0x65,  0xfe,  0xc6,  0x18,  0x03,  0xff,  0x1a,  0x00,  0x00,
13381 };
13382
13383 STATIC unsigned short _adv_asc3550_size =
13384         sizeof(_adv_asc3550_buf); /* 0x13AD */
13385 STATIC ADV_DCNT _adv_asc3550_chksum =
13386         0x04D52DDDUL; /* Expanded little-endian checksum. */
13387
13388 /* Microcode buffer is kept after initialization for error recovery. */
13389 STATIC unsigned char _adv_asc38C0800_buf[] = {
13390   0x00,  0x00,  0x00,  0xf2,  0x00,  0xf0,  0x00,  0xfc,  0x00,  0x16,  0x18,  0xe4,  0x01,  0x00,  0x48,  0xe4,
13391   0x18,  0x80,  0x03,  0xf6,  0x02,  0x00,  0xce,  0x19,  0x00,  0xfa,  0xff,  0xff,  0x1c,  0x0f,  0x00,  0xf6,
13392   0x9e,  0xe7,  0xff,  0x00,  0x82,  0xe7,  0x00,  0xea,  0x01,  0xfa,  0x01,  0xe6,  0x09,  0xe7,  0x55,  0xf0,
13393   0x01,  0xf6,  0x03,  0x00,  0x04,  0x00,  0x10,  0x00,  0x1e,  0xf0,  0x85,  0xf0,  0x18,  0xf4,  0x08,  0x00,
13394   0xbc,  0x00,  0x38,  0x54,  0x00,  0xec,  0xd5,  0xf0,  0x82,  0x0d,  0x00,  0xe6,  0x86,  0xf0,  0xb1,  0xf0,
13395   0x98,  0x57,  0x01,  0xfc,  0xb4,  0x00,  0xd4,  0x01,  0x0c,  0x1c,  0x3e,  0x1c,  0x3c,  0x00,  0xbb,  0x00,
13396   0x00,  0x10,  0xba,  0x19,  0x02,  0x80,  0x32,  0xf0,  0x7c,  0x0d,  0x02,  0x13,  0xba,  0x13,  0x18,  0x40,
13397   0x00,  0x57,  0x01,  0xea,  0x02,  0xfc,  0x03,  0xfc,  0x3e,  0x00,  0x6c,  0x01,  0x6e,  0x01,  0x74,  0x01,
13398   0x76,  0x01,  0xb9,  0x54,  0x3e,  0x57,  0x00,  0x80,  0x03,  0xe6,  0xb6,  0x00,  0xc0,  0x00,  0x01,  0x01,
13399   0x3e,  0x01,  0x7a,  0x01,  0xca,  0x08,  0xce,  0x10,  0x16,  0x11,  0x04,  0x12,  0x08,  0x12,  0x02,  0x4a,
13400   0xbb,  0x55,  0x3c,  0x56,  0x03,  0x58,  0x1b,  0x80,  0x30,  0xe4,  0x4b,  0xe4,  0x5d,  0xf0,  0x02,  0xfa,
13401   0x20,  0x00,  0x32,  0x00,  0x40,  0x00,  0x80,  0x00,  0x24,  0x01,  0x3c,  0x01,  0x68,  0x01,  0x6a,  0x01,
13402   0x70,  0x01,  0x72,  0x01,  0x78,  0x01,  0x7c,  0x01,  0x62,  0x0a,  0x86,  0x0d,  0x06,  0x13,  0x4c,  0x1c,
13403   0x04,  0x80,  0x4a,  0xe4,  0x02,  0xee,  0x5b,  0xf0,  0x03,  0xf7,  0x0c,  0x00,  0x0f,  0x00,  0x47,  0x00,
13404   0xbe,  0x00,  0x00,  0x01,  0x20,  0x11,  0x5c,  0x16,  0x32,  0x1c,  0x38,  0x1c,  0x4e,  0x1c,  0x10,  0x44,
13405   0x00,  0x4c,  0x04,  0xea,  0x5c,  0xf0,  0xa7,  0xf0,  0x04,  0xf6,  0x03,  0xfa,  0x05,  0x00,  0x34,  0x00,
13406   0x36,  0x00,  0x98,  0x00,  0xcc,  0x00,  0x20,  0x01,  0x4e,  0x01,  0x4a,  0x0b,  0x42,  0x0c,  0x12,  0x0f,
13407   0x0c,  0x10,  0x22,  0x11,  0x0a,  0x12,  0x04,  0x13,  0x30,  0x1c,  0x02,  0x48,  0x00,  0x4e,  0x42,  0x54,
13408   0x44,  0x55,  0xbd,  0x56,  0x06,  0x83,  0x00,  0xdc,  0x05,  0xf0,  0x09,  0xf0,  0x59,  0xf0,  0xb8,  0xf0,
13409   0x4b,  0xf4,  0x06,  0xf7,  0x0e,  0xf7,  0x04,  0xfc,  0x05,  0xfc,  0x06,  0x00,  0x19,  0x00,  0x33,  0x00,
13410   0x9b,  0x00,  0xa4,  0x00,  0xb5,  0x00,  0xba,  0x00,  0xd0,  0x00,  0xe1,  0x00,  0xe7,  0x00,  0xe2,  0x03,
13411   0x08,  0x0f,  0x02,  0x10,  0x04,  0x10,  0x0a,  0x10,  0x0a,  0x13,  0x0c,  0x13,  0x12,  0x13,  0x24,  0x14,
13412   0x34,  0x14,  0x04,  0x16,  0x08,  0x16,  0xa4,  0x17,  0x20,  0x1c,  0x34,  0x1c,  0x36,  0x1c,  0x08,  0x44,
13413   0x38,  0x44,  0x91,  0x44,  0x0a,  0x45,  0x48,  0x46,  0x01,  0x48,  0x68,  0x54,  0x3a,  0x55,  0x83,  0x55,
13414   0xe5,  0x55,  0xb0,  0x57,  0x01,  0x58,  0x83,  0x59,  0x05,  0xe6,  0x0b,  0xf0,  0x0c,  0xf0,  0x04,  0xf8,
13415   0x05,  0xf8,  0x07,  0x00,  0x0a,  0x00,  0x1c,  0x00,  0x1e,  0x00,  0x9e,  0x00,  0xa8,  0x00,  0xaa,  0x00,
13416   0xb9,  0x00,  0xe0,  0x00,  0x22,  0x01,  0x26,  0x01,  0x79,  0x01,  0x7e,  0x01,  0xc4,  0x01,  0xc6,  0x01,
13417   0x80,  0x02,  0x5e,  0x03,  0xee,  0x04,  0x9a,  0x06,  0xf8,  0x07,  0x62,  0x08,  0x68,  0x08,  0x69,  0x08,
13418   0xd6,  0x08,  0xe9,  0x09,  0xfa,  0x0b,  0x2e,  0x0f,  0x12,  0x10,  0x1a,  0x10,  0xed,  0x10,  0xf1,  0x10,
13419   0x2a,  0x11,  0x06,  0x12,  0x0c,  0x12,  0x3e,  0x12,  0x10,  0x13,  0x16,  0x13,  0x1e,  0x13,  0x46,  0x14,
13420   0x76,  0x14,  0x82,  0x14,  0x36,  0x15,  0xca,  0x15,  0x6b,  0x18,  0xbe,  0x18,  0xca,  0x18,  0xe6,  0x19,
13421   0x12,  0x1c,  0x46,  0x1c,  0x9c,  0x32,  0x00,  0x40,  0x0e,  0x47,  0xfe,  0x9c,  0xf0,  0x2b,  0x02,  0xfe,
13422   0xac,  0x0d,  0xff,  0x10,  0x00,  0x00,  0xd7,  0xfe,  0xe8,  0x19,  0x00,  0xd6,  0xfe,  0x84,  0x01,  0xff,
13423   0x03,  0x00,  0x00,  0xfe,  0x93,  0x15,  0xfe,  0x0f,  0x05,  0xff,  0x38,  0x00,  0x00,  0xfe,  0x57,  0x24,
13424   0x00,  0xfe,  0x4c,  0x00,  0x5b,  0xff,  0x04,  0x00,  0x00,  0x11,  0xff,  0x09,  0x00,  0x00,  0xff,  0x08,
13425   0x01,  0x01,  0xff,  0x08,  0xff,  0xff,  0xff,  0x27,  0x00,  0x00,  0xff,  0x10,  0xff,  0xff,  0xff,  0x11,
13426   0x00,  0x00,  0xfe,  0x78,  0x56,  0xfe,  0x34,  0x12,  0xff,  0x21,  0x00,  0x00,  0xfe,  0x04,  0xf7,  0xd6,
13427   0x2c,  0x99,  0x0a,  0x01,  0xfe,  0xc2,  0x0f,  0xfe,  0x04,  0xf7,  0xd6,  0x99,  0x0a,  0x42,  0x2c,  0xfe,
13428   0x3d,  0xf0,  0xfe,  0x06,  0x02,  0xfe,  0x20,  0xf0,  0xa7,  0xfe,  0x91,  0xf0,  0xfe,  0xf4,  0x01,  0xfe,
13429   0x90,  0xf0,  0xfe,  0xf4,  0x01,  0xfe,  0x8f,  0xf0,  0xa7,  0x03,  0x5d,  0x4d,  0x02,  0xfe,  0xc8,  0x0d,
13430   0x01,  0xfe,  0x38,  0x0e,  0xfe,  0xdd,  0x12,  0xfe,  0xfc,  0x10,  0xfe,  0x28,  0x1c,  0x03,  0xfe,  0xa6,
13431   0x00,  0xfe,  0xd3,  0x12,  0x41,  0x14,  0xfe,  0xa6,  0x00,  0xc2,  0xfe,  0x48,  0xf0,  0xfe,  0x8a,  0x02,
13432   0xfe,  0x49,  0xf0,  0xfe,  0xa4,  0x02,  0xfe,  0x4a,  0xf0,  0xfe,  0xc2,  0x02,  0xfe,  0x46,  0xf0,  0xfe,
13433   0x54,  0x02,  0xfe,  0x47,  0xf0,  0xfe,  0x5a,  0x02,  0xfe,  0x43,  0xf0,  0xfe,  0x48,  0x02,  0xfe,  0x44,
13434   0xf0,  0xfe,  0x4c,  0x02,  0xfe,  0x45,  0xf0,  0xfe,  0x50,  0x02,  0x18,  0x0a,  0xaa,  0x18,  0x06,  0x14,
13435   0xa1,  0x02,  0x2b,  0xfe,  0x00,  0x1c,  0xe7,  0xfe,  0x02,  0x1c,  0xe6,  0xfe,  0x1e,  0x1c,  0xfe,  0xe9,
13436   0x10,  0x01,  0xfe,  0x18,  0x18,  0xfe,  0xe7,  0x10,  0xfe,  0x06,  0xfc,  0xce,  0x09,  0x70,  0x01,  0xa8,
13437   0x02,  0x2b,  0x15,  0x59,  0x39,  0xa2,  0x01,  0xfe,  0x58,  0x10,  0x09,  0x70,  0x01,  0x87,  0xfe,  0xbd,
13438   0x10,  0x09,  0x70,  0x01,  0x87,  0xfe,  0xad,  0x10,  0xfe,  0x16,  0x1c,  0xfe,  0x58,  0x1c,  0x18,  0x06,
13439   0x14,  0xa1,  0x2c,  0x1c,  0x2b,  0xfe,  0x3d,  0xf0,  0xfe,  0x06,  0x02,  0x23,  0xfe,  0x98,  0x02,  0xfe,
13440   0x5a,  0x1c,  0xf8,  0xfe,  0x14,  0x1c,  0x15,  0xfe,  0x30,  0x00,  0x39,  0xa2,  0x01,  0xfe,  0x48,  0x10,
13441   0x18,  0x06,  0x14,  0xa1,  0x02,  0xd7,  0x22,  0x20,  0x07,  0x11,  0x35,  0xfe,  0x69,  0x10,  0x18,  0x06,
13442   0x14,  0xa1,  0xfe,  0x04,  0xec,  0x20,  0x4f,  0x43,  0x13,  0x20,  0xfe,  0x05,  0xf6,  0xce,  0x01,  0xfe,
13443   0x4a,  0x17,  0x08,  0x54,  0x58,  0x37,  0x12,  0x2f,  0x42,  0x92,  0x01,  0xfe,  0x82,  0x16,  0x02,  0x2b,
13444   0x09,  0x46,  0x01,  0x0e,  0x07,  0x00,  0x66,  0x01,  0x73,  0xfe,  0x18,  0x10,  0xfe,  0x41,  0x58,  0x09,
13445   0xa4,  0x01,  0x0e,  0xfe,  0xc8,  0x54,  0x6b,  0xfe,  0x10,  0x03,  0x01,  0xfe,  0x82,  0x16,  0x02,  0x2b,
13446   0x2c,  0x4f,  0xfe,  0x02,  0xe8,  0x2a,  0xfe,  0xbf,  0x57,  0xfe,  0x9e,  0x43,  0xfe,  0x77,  0x57,  0xfe,
13447   0x27,  0xf0,  0xfe,  0xe0,  0x01,  0xfe,  0x07,  0x4b,  0xfe,  0x20,  0xf0,  0xa7,  0xfe,  0x40,  0x1c,  0x1c,
13448   0xd9,  0xfe,  0x26,  0xf0,  0xfe,  0x5a,  0x03,  0xfe,  0xa0,  0xf0,  0xfe,  0x48,  0x03,  0xfe,  0x11,  0xf0,
13449   0xa7,  0xfe,  0xef,  0x10,  0xfe,  0x9f,  0xf0,  0xfe,  0x68,  0x03,  0xf9,  0x10,  0xfe,  0x11,  0x00,  0x02,
13450   0x65,  0x2c,  0xfe,  0x48,  0x1c,  0xf9,  0x08,  0x05,  0x1b,  0xfe,  0x18,  0x13,  0x21,  0x22,  0xa3,  0xb7,
13451   0x13,  0xa3,  0x09,  0x46,  0x01,  0x0e,  0xb7,  0x78,  0x01,  0xfe,  0xb4,  0x16,  0x12,  0xd1,  0x1c,  0xd9,
13452   0xfe,  0x01,  0xf0,  0xd9,  0xfe,  0x82,  0xf0,  0xfe,  0x96,  0x03,  0xfa,  0x12,  0xfe,  0xe4,  0x00,  0x27,
13453   0xfe,  0xa8,  0x03,  0x1c,  0x34,  0x1d,  0xfe,  0xb8,  0x03,  0x01,  0x4b,  0xfe,  0x06,  0xf0,  0xfe,  0xc8,
13454   0x03,  0x95,  0x86,  0xfe,  0x0a,  0xf0,  0xfe,  0x8a,  0x06,  0x02,  0x24,  0x03,  0x70,  0x28,  0x17,  0xfe,
13455   0xfa,  0x04,  0x15,  0x6d,  0x01,  0x36,  0x7b,  0xfe,  0x6a,  0x02,  0x02,  0xd8,  0xf9,  0x2c,  0x99,  0x19,
13456   0xfe,  0x67,  0x1b,  0xfe,  0xbf,  0x57,  0xfe,  0x77,  0x57,  0xfe,  0x48,  0x1c,  0x74,  0x01,  0xaf,  0x8c,
13457   0x09,  0x46,  0x01,  0x0e,  0x07,  0x00,  0x17,  0xda,  0x09,  0xd1,  0x01,  0x0e,  0x8d,  0x51,  0x64,  0x79,
13458   0x2a,  0x03,  0x70,  0x28,  0xfe,  0x10,  0x12,  0x15,  0x6d,  0x01,  0x36,  0x7b,  0xfe,  0x6a,  0x02,  0x02,
13459   0xd8,  0xc7,  0x81,  0xc8,  0x83,  0x1c,  0x24,  0x27,  0xfe,  0x40,  0x04,  0x1d,  0xfe,  0x3c,  0x04,  0x3b,
13460   0xfe,  0xa0,  0x00,  0xfe,  0x9b,  0x57,  0xfe,  0x4e,  0x12,  0x2d,  0xff,  0x02,  0x00,  0x10,  0x01,  0x0b,
13461   0x1d,  0xfe,  0xe4,  0x04,  0x2d,  0x01,  0x0b,  0x1d,  0x24,  0x33,  0x31,  0xde,  0xfe,  0x4c,  0x44,  0xfe,
13462   0x4c,  0x12,  0x51,  0xfe,  0x44,  0x48,  0x0f,  0x6f,  0xfe,  0x4c,  0x54,  0x6b,  0xda,  0x4f,  0x79,  0x2a,
13463   0xfe,  0x06,  0x80,  0xfe,  0x48,  0x47,  0xfe,  0x62,  0x13,  0x08,  0x05,  0x1b,  0xfe,  0x2a,  0x13,  0x32,
13464   0x07,  0x82,  0xfe,  0x52,  0x13,  0xfe,  0x20,  0x10,  0x0f,  0x6f,  0xfe,  0x4c,  0x54,  0x6b,  0xda,  0xfe,
13465   0x06,  0x80,  0xfe,  0x48,  0x47,  0xfe,  0x40,  0x13,  0x08,  0x05,  0x1b,  0xfe,  0x08,  0x13,  0x32,  0x07,
13466   0x82,  0xfe,  0x30,  0x13,  0x08,  0x05,  0x1b,  0xfe,  0x1c,  0x12,  0x15,  0x9d,  0x08,  0x05,  0x06,  0x4d,
13467   0x15,  0xfe,  0x0d,  0x00,  0x01,  0x36,  0x7b,  0xfe,  0x64,  0x0d,  0x02,  0x24,  0x2d,  0x12,  0xfe,  0xe6,
13468   0x00,  0xfe,  0x1c,  0x90,  0xfe,  0x40,  0x5c,  0x04,  0x15,  0x9d,  0x01,  0x36,  0x02,  0x2b,  0xfe,  0x42,
13469   0x5b,  0x99,  0x19,  0xfe,  0x46,  0x59,  0xfe,  0xbf,  0x57,  0xfe,  0x77,  0x57,  0xfe,  0x87,  0x80,  0xfe,
13470   0x31,  0xe4,  0x5b,  0x08,  0x05,  0x0a,  0xfe,  0x84,  0x13,  0xfe,  0x20,  0x80,  0x07,  0x19,  0xfe,  0x7c,
13471   0x12,  0x53,  0x05,  0x06,  0xfe,  0x6c,  0x13,  0x03,  0xfe,  0xa2,  0x00,  0x28,  0x17,  0xfe,  0x90,  0x05,
13472   0xfe,  0x31,  0xe4,  0x5a,  0x53,  0x05,  0x0a,  0xfe,  0x56,  0x13,  0x03,  0xfe,  0xa0,  0x00,  0x28,  0xfe,
13473   0x4e,  0x12,  0x67,  0xff,  0x02,  0x00,  0x10,  0x27,  0xfe,  0x48,  0x05,  0x1c,  0x34,  0xfe,  0x89,  0x48,
13474   0xff,  0x02,  0x00,  0x10,  0x27,  0xfe,  0x56,  0x05,  0x26,  0xfe,  0xa8,  0x05,  0x12,  0xfe,  0xe3,  0x00,
13475   0x21,  0x53,  0xfe,  0x4a,  0xf0,  0xfe,  0x76,  0x05,  0xfe,  0x49,  0xf0,  0xfe,  0x70,  0x05,  0x88,  0x25,
13476   0xfe,  0x21,  0x00,  0xab,  0x25,  0xfe,  0x22,  0x00,  0xaa,  0x25,  0x58,  0xfe,  0x09,  0x48,  0xff,  0x02,
13477   0x00,  0x10,  0x27,  0xfe,  0x86,  0x05,  0x26,  0xfe,  0xa8,  0x05,  0xfe,  0xe2,  0x08,  0x53,  0x05,  0xcb,
13478   0x4d,  0x01,  0xb0,  0x25,  0x06,  0x13,  0xd3,  0x39,  0xfe,  0x27,  0x01,  0x08,  0x05,  0x1b,  0xfe,  0x22,
13479   0x12,  0x41,  0x01,  0xb2,  0x15,  0x9d,  0x08,  0x05,  0x06,  0x4d,  0x15,  0xfe,  0x0d,  0x00,  0x01,  0x36,
13480   0x7b,  0xfe,  0x64,  0x0d,  0x02,  0x24,  0x03,  0xfe,  0x9c,  0x00,  0x28,  0xeb,  0x03,  0x5c,  0x28,  0xfe,
13481   0x36,  0x13,  0x41,  0x01,  0xb2,  0x26,  0xfe,  0x18,  0x06,  0x09,  0x06,  0x53,  0x05,  0x1f,  0xfe,  0x02,
13482   0x12,  0x50,  0x01,  0xfe,  0x9e,  0x15,  0x1d,  0xfe,  0x0e,  0x06,  0x12,  0xa5,  0x01,  0x4b,  0x12,  0xfe,
13483   0xe5,  0x00,  0x03,  0x5c,  0xc1,  0x0c,  0x5c,  0x03,  0xcd,  0x28,  0xfe,  0x62,  0x12,  0x03,  0x45,  0x28,
13484   0xfe,  0x5a,  0x13,  0x01,  0xfe,  0x0c,  0x19,  0x01,  0xfe,  0x76,  0x19,  0xfe,  0x43,  0x48,  0xc4,  0xcc,
13485   0x0f,  0x71,  0xff,  0x02,  0x00,  0x57,  0x52,  0x93,  0x1e,  0x43,  0x8b,  0xc4,  0x6e,  0x41,  0x01,  0xb2,
13486   0x26,  0xfe,  0x82,  0x06,  0x53,  0x05,  0x1a,  0xe9,  0x91,  0x09,  0x59,  0x01,  0xfe,  0xcc,  0x15,  0x1d,
13487   0xfe,  0x78,  0x06,  0x12,  0xa5,  0x01,  0x4b,  0x12,  0xfe,  0xe5,  0x00,  0x03,  0x45,  0xc1,  0x0c,  0x45,
13488   0x18,  0x06,  0x01,  0xb2,  0xfa,  0x76,  0x74,  0x01,  0xaf,  0x8c,  0x12,  0xfe,  0xe2,  0x00,  0x27,  0xdb,
13489   0x1c,  0x34,  0xfe,  0x0a,  0xf0,  0xfe,  0xb6,  0x06,  0x94,  0xfe,  0x6c,  0x07,  0xfe,  0x06,  0xf0,  0xfe,
13490   0x74,  0x07,  0x95,  0x86,  0x02,  0x24,  0x08,  0x05,  0x0a,  0xfe,  0x2e,  0x12,  0x16,  0x19,  0x01,  0x0b,
13491   0x16,  0x00,  0x01,  0x0b,  0x16,  0x00,  0x01,  0x0b,  0x16,  0x00,  0x01,  0x0b,  0xfe,  0x99,  0xa4,  0x01,
13492   0x0b,  0x16,  0x00,  0x02,  0xfe,  0x42,  0x08,  0x68,  0x05,  0x1a,  0xfe,  0x38,  0x12,  0x08,  0x05,  0x1a,
13493   0xfe,  0x30,  0x13,  0x16,  0xfe,  0x1b,  0x00,  0x01,  0x0b,  0x16,  0x00,  0x01,  0x0b,  0x16,  0x00,  0x01,
13494   0x0b,  0x16,  0x00,  0x01,  0x0b,  0x16,  0x06,  0x01,  0x0b,  0x16,  0x00,  0x02,  0xe2,  0x6c,  0x58,  0xbe,
13495   0x50,  0xfe,  0x9a,  0x81,  0x55,  0x1b,  0x7a,  0xfe,  0x42,  0x07,  0x09,  0x1b,  0xfe,  0x09,  0x6f,  0xba,
13496   0xfe,  0xca,  0x45,  0xfe,  0x32,  0x12,  0x69,  0x6d,  0x8b,  0x6c,  0x7f,  0x27,  0xfe,  0x54,  0x07,  0x1c,
13497   0x34,  0xfe,  0x0a,  0xf0,  0xfe,  0x42,  0x07,  0x95,  0x86,  0x94,  0xfe,  0x6c,  0x07,  0x02,  0x24,  0x01,
13498   0x4b,  0x02,  0xdb,  0x16,  0x1f,  0x02,  0xdb,  0xfe,  0x9c,  0xf7,  0xdc,  0xfe,  0x2c,  0x90,  0xfe,  0xae,
13499   0x90,  0x56,  0xfe,  0xda,  0x07,  0x0c,  0x60,  0x14,  0x61,  0x08,  0x54,  0x5a,  0x37,  0x22,  0x20,  0x07,
13500   0x11,  0xfe,  0x0e,  0x12,  0x8d,  0xfe,  0x80,  0x80,  0x39,  0x20,  0x6a,  0x2a,  0xfe,  0x06,  0x10,  0xfe,
13501   0x83,  0xe7,  0xfe,  0x48,  0x00,  0xab,  0xfe,  0x03,  0x40,  0x08,  0x54,  0x5b,  0x37,  0x01,  0xb3,  0xb8,
13502   0xfe,  0x1f,  0x40,  0x13,  0x62,  0x01,  0xef,  0xfe,  0x08,  0x50,  0xfe,  0x8a,  0x50,  0xfe,  0x44,  0x51,
13503   0xfe,  0xc6,  0x51,  0x88,  0xfe,  0x08,  0x90,  0xfe,  0x8a,  0x90,  0x0c,  0x5e,  0x14,  0x5f,  0xfe,  0x0c,
13504   0x90,  0xfe,  0x8e,  0x90,  0xfe,  0x40,  0x50,  0xfe,  0xc2,  0x50,  0x0c,  0x3d,  0x14,  0x3e,  0xfe,  0x4a,
13505   0x10,  0x08,  0x05,  0x5a,  0xfe,  0x2a,  0x12,  0xfe,  0x2c,  0x90,  0xfe,  0xae,  0x90,  0x0c,  0x60,  0x14,
13506   0x61,  0x08,  0x05,  0x5b,  0x8b,  0x01,  0xb3,  0xfe,  0x1f,  0x80,  0x13,  0x62,  0xfe,  0x44,  0x90,  0xfe,
13507   0xc6,  0x90,  0x0c,  0x3f,  0x14,  0x40,  0xfe,  0x08,  0x90,  0xfe,  0x8a,  0x90,  0x0c,  0x5e,  0x14,  0x5f,
13508   0xfe,  0x40,  0x90,  0xfe,  0xc2,  0x90,  0x0c,  0x3d,  0x14,  0x3e,  0x0c,  0x2e,  0x14,  0x3c,  0x21,  0x0c,
13509   0x49,  0x0c,  0x63,  0x08,  0x54,  0x1f,  0x37,  0x2c,  0x0f,  0xfe,  0x4e,  0x11,  0x27,  0xdd,  0xfe,  0x9e,
13510   0xf0,  0xfe,  0x76,  0x08,  0xbc,  0x17,  0x34,  0x2c,  0x77,  0xe6,  0xc5,  0xfe,  0x9a,  0x08,  0xc6,  0xfe,
13511   0xb8,  0x08,  0x94,  0xfe,  0x8e,  0x08,  0xfe,  0x06,  0xf0,  0xfe,  0x94,  0x08,  0x95,  0x86,  0x02,  0x24,
13512   0x01,  0x4b,  0xfe,  0xc9,  0x10,  0x16,  0x1f,  0xfe,  0xc9,  0x10,  0x68,  0x05,  0x06,  0xfe,  0x10,  0x12,
13513   0x68,  0x05,  0x0a,  0x4e,  0x08,  0x05,  0x0a,  0xfe,  0x90,  0x12,  0xfe,  0x2e,  0x1c,  0x02,  0xfe,  0x18,
13514   0x0b,  0x68,  0x05,  0x06,  0x4e,  0x68,  0x05,  0x0a,  0xfe,  0x7a,  0x12,  0xfe,  0x2c,  0x1c,  0xfe,  0xaa,
13515   0xf0,  0xfe,  0xd2,  0x09,  0xfe,  0xac,  0xf0,  0xfe,  0x00,  0x09,  0x02,  0xfe,  0xde,  0x09,  0xfe,  0xb7,
13516   0xf0,  0xfe,  0xfc,  0x08,  0xfe,  0x02,  0xf6,  0x1a,  0x50,  0xfe,  0x70,  0x18,  0xfe,  0xf1,  0x18,  0xfe,
13517   0x40,  0x55,  0xfe,  0xe1,  0x55,  0xfe,  0x10,  0x58,  0xfe,  0x91,  0x58,  0xfe,  0x14,  0x59,  0xfe,  0x95,
13518   0x59,  0x1c,  0x85,  0xfe,  0x8c,  0xf0,  0xfe,  0xfc,  0x08,  0xfe,  0xac,  0xf0,  0xfe,  0xf0,  0x08,  0xb5,
13519   0xfe,  0xcb,  0x10,  0xfe,  0xad,  0xf0,  0xfe,  0x0c,  0x09,  0x02,  0xfe,  0x18,  0x0b,  0xb6,  0xfe,  0xbf,
13520   0x10,  0xfe,  0x2b,  0xf0,  0x85,  0xf4,  0x1e,  0xfe,  0x00,  0xfe,  0xfe,  0x1c,  0x12,  0xc2,  0xfe,  0xd2,
13521   0xf0,  0x85,  0xfe,  0x76,  0x18,  0x1e,  0x19,  0x17,  0x85,  0x03,  0xd2,  0x1e,  0x06,  0x17,  0x85,  0xc5,
13522   0x4a,  0xc6,  0x4a,  0xb5,  0xb6,  0xfe,  0x89,  0x10,  0x74,  0x67,  0x2d,  0x15,  0x9d,  0x01,  0x36,  0x10,
13523   0xfe,  0x35,  0x00,  0xfe,  0x01,  0xf0,  0x65,  0x10,  0x80,  0x02,  0x65,  0xfe,  0x98,  0x80,  0xfe,  0x19,
13524   0xe4,  0x0a,  0xfe,  0x1a,  0x12,  0x51,  0xfe,  0x19,  0x82,  0xfe,  0x6c,  0x18,  0xfe,  0x44,  0x54,  0xbe,
13525   0xfe,  0x19,  0x81,  0xfe,  0x74,  0x18,  0x8f,  0x90,  0x17,  0xfe,  0xce,  0x08,  0x02,  0x4a,  0x08,  0x05,
13526   0x5a,  0xec,  0x03,  0x2e,  0x29,  0x3c,  0x0c,  0x3f,  0x14,  0x40,  0x9b,  0x2e,  0x9c,  0x3c,  0xfe,  0x6c,
13527   0x18,  0xfe,  0xed,  0x18,  0xfe,  0x44,  0x54,  0xfe,  0xe5,  0x54,  0x3a,  0x3f,  0x3b,  0x40,  0x03,  0x49,
13528   0x29,  0x63,  0x8f,  0xfe,  0xe3,  0x54,  0xfe,  0x74,  0x18,  0xfe,  0xf5,  0x18,  0x8f,  0xfe,  0xe3,  0x54,
13529   0x90,  0xc0,  0x56,  0xfe,  0xce,  0x08,  0x02,  0x4a,  0xfe,  0x37,  0xf0,  0xfe,  0xda,  0x09,  0xfe,  0x8b,
13530   0xf0,  0xfe,  0x60,  0x09,  0x02,  0x4a,  0x08,  0x05,  0x0a,  0x23,  0xfe,  0xfa,  0x0a,  0x3a,  0x49,  0x3b,
13531   0x63,  0x56,  0xfe,  0x3e,  0x0a,  0x0f,  0xfe,  0xc0,  0x07,  0x41,  0x98,  0x00,  0xad,  0xfe,  0x01,  0x59,
13532   0xfe,  0x52,  0xf0,  0xfe,  0x0c,  0x0a,  0x8f,  0x7a,  0xfe,  0x24,  0x0a,  0x3a,  0x49,  0x8f,  0xfe,  0xe3,
13533   0x54,  0x57,  0x49,  0x7d,  0x63,  0xfe,  0x14,  0x58,  0xfe,  0x95,  0x58,  0x02,  0x4a,  0x3a,  0x49,  0x3b,
13534   0x63,  0xfe,  0x14,  0x59,  0xfe,  0x95,  0x59,  0xbe,  0x57,  0x49,  0x57,  0x63,  0x02,  0x4a,  0x08,  0x05,
13535   0x5a,  0xfe,  0x82,  0x12,  0x08,  0x05,  0x1f,  0xfe,  0x66,  0x13,  0x22,  0x62,  0xb7,  0xfe,  0x03,  0xa1,
13536   0xfe,  0x83,  0x80,  0xfe,  0xc8,  0x44,  0xfe,  0x2e,  0x13,  0xfe,  0x04,  0x91,  0xfe,  0x86,  0x91,  0x6a,
13537   0x2a,  0xfe,  0x40,  0x59,  0xfe,  0xc1,  0x59,  0x56,  0xe0,  0x03,  0x60,  0x29,  0x61,  0x0c,  0x7f,  0x14,
13538   0x80,  0x57,  0x60,  0x7d,  0x61,  0x01,  0xb3,  0xb8,  0x6a,  0x2a,  0x13,  0x62,  0x9b,  0x2e,  0x9c,  0x3c,
13539   0x3a,  0x3f,  0x3b,  0x40,  0x90,  0xc0,  0xfe,  0x04,  0xfa,  0x2e,  0xfe,  0x05,  0xfa,  0x3c,  0x01,  0xef,
13540   0xfe,  0x36,  0x10,  0x21,  0x0c,  0x7f,  0x0c,  0x80,  0x3a,  0x3f,  0x3b,  0x40,  0xe4,  0x08,  0x05,  0x1f,
13541   0x17,  0xe0,  0x3a,  0x3d,  0x3b,  0x3e,  0x08,  0x05,  0xfe,  0xf7,  0x00,  0x37,  0x03,  0x5e,  0x29,  0x5f,
13542   0xfe,  0x10,  0x58,  0xfe,  0x91,  0x58,  0x57,  0x49,  0x7d,  0x63,  0x02,  0xfe,  0xf4,  0x09,  0x08,  0x05,
13543   0x1f,  0x17,  0xe0,  0x08,  0x05,  0xfe,  0xf7,  0x00,  0x37,  0xbe,  0xfe,  0x19,  0x81,  0x50,  0xfe,  0x10,
13544   0x90,  0xfe,  0x92,  0x90,  0xfe,  0xd3,  0x10,  0x32,  0x07,  0xa6,  0x17,  0xfe,  0x08,  0x09,  0x12,  0xa6,
13545   0x08,  0x05,  0x0a,  0xfe,  0x14,  0x13,  0x03,  0x3d,  0x29,  0x3e,  0x56,  0xfe,  0x08,  0x09,  0xfe,  0x0c,
13546   0x58,  0xfe,  0x8d,  0x58,  0x02,  0x4a,  0x21,  0x41,  0xfe,  0x19,  0x80,  0xe7,  0x08,  0x05,  0x0a,  0xfe,
13547   0x1a,  0x12,  0xfe,  0x6c,  0x19,  0xfe,  0x19,  0x41,  0xf4,  0xc2,  0xfe,  0xd1,  0xf0,  0xe2,  0x15,  0x7e,
13548   0x01,  0x36,  0x10,  0xfe,  0x44,  0x00,  0xfe,  0x8e,  0x10,  0xfe,  0x6c,  0x19,  0x57,  0x3d,  0xfe,  0xed,
13549   0x19,  0x7d,  0x3e,  0xfe,  0x0c,  0x51,  0xfe,  0x8e,  0x51,  0xf4,  0x1e,  0xfe,  0x00,  0xff,  0x35,  0xfe,
13550   0x74,  0x10,  0xc2,  0xfe,  0xd2,  0xf0,  0xfe,  0xa6,  0x0b,  0xfe,  0x76,  0x18,  0x1e,  0x19,  0x8a,  0x03,
13551   0xd2,  0x1e,  0x06,  0xfe,  0x08,  0x13,  0x10,  0xfe,  0x16,  0x00,  0x02,  0x65,  0xfe,  0xd1,  0xf0,  0xfe,
13552   0xb8,  0x0b,  0x15,  0x7e,  0x01,  0x36,  0x10,  0xfe,  0x17,  0x00,  0xfe,  0x42,  0x10,  0xfe,  0xce,  0xf0,
13553   0xfe,  0xbe,  0x0b,  0xfe,  0x3c,  0x10,  0xfe,  0xcd,  0xf0,  0xfe,  0xca,  0x0b,  0x10,  0xfe,  0x22,  0x00,
13554   0x02,  0x65,  0xfe,  0xcb,  0xf0,  0xfe,  0xd6,  0x0b,  0x10,  0xfe,  0x24,  0x00,  0x02,  0x65,  0xfe,  0xd0,
13555   0xf0,  0xfe,  0xe0,  0x0b,  0x10,  0x9e,  0xe5,  0xfe,  0xcf,  0xf0,  0xfe,  0xea,  0x0b,  0x10,  0x58,  0xfe,
13556   0x10,  0x10,  0xfe,  0xcc,  0xf0,  0xe2,  0x68,  0x05,  0x1f,  0x4d,  0x10,  0xfe,  0x12,  0x00,  0x2c,  0x0f,
13557   0xfe,  0x4e,  0x11,  0x27,  0xfe,  0x00,  0x0c,  0xfe,  0x9e,  0xf0,  0xfe,  0x14,  0x0c,  0xbc,  0x17,  0x34,
13558   0x2c,  0x77,  0xe6,  0xc5,  0x24,  0xc6,  0x24,  0x2c,  0xfa,  0x27,  0xfe,  0x20,  0x0c,  0x1c,  0x34,  0x94,
13559   0xfe,  0x3c,  0x0c,  0x95,  0x86,  0xc5,  0xdc,  0xc6,  0xdc,  0x02,  0x24,  0x01,  0x4b,  0xfe,  0xdb,  0x10,
13560   0x12,  0xfe,  0xe8,  0x00,  0xb5,  0xb6,  0x74,  0xc7,  0x81,  0xc8,  0x83,  0xfe,  0x89,  0xf0,  0x24,  0x33,
13561   0x31,  0xe1,  0xc7,  0x81,  0xc8,  0x83,  0x27,  0xfe,  0x66,  0x0c,  0x1d,  0x24,  0x33,  0x31,  0xdf,  0xbc,
13562   0x4e,  0x10,  0xfe,  0x42,  0x00,  0x02,  0x65,  0x7c,  0x06,  0xfe,  0x81,  0x49,  0x17,  0xfe,  0x2c,  0x0d,
13563   0x08,  0x05,  0x0a,  0xfe,  0x44,  0x13,  0x10,  0x00,  0x55,  0x0a,  0xfe,  0x54,  0x12,  0x55,  0xfe,  0x28,
13564   0x00,  0x23,  0xfe,  0x9a,  0x0d,  0x09,  0x46,  0x01,  0x0e,  0x07,  0x00,  0x66,  0x44,  0xfe,  0x28,  0x00,
13565   0xfe,  0xe2,  0x10,  0x01,  0xf5,  0x01,  0xf6,  0x09,  0xa4,  0x01,  0xfe,  0x26,  0x0f,  0x64,  0x12,  0x2f,
13566   0x01,  0x73,  0x02,  0x2b,  0x10,  0xfe,  0x44,  0x00,  0x55,  0x0a,  0xe9,  0x44,  0x0a,  0xfe,  0xb4,  0x10,
13567   0x01,  0xb0,  0x44,  0x0a,  0xfe,  0xaa,  0x10,  0x01,  0xb0,  0xfe,  0x19,  0x82,  0xfe,  0x34,  0x46,  0xac,
13568   0x44,  0x0a,  0x10,  0xfe,  0x43,  0x00,  0xfe,  0x96,  0x10,  0x08,  0x54,  0x0a,  0x37,  0x01,  0xf5,  0x01,
13569   0xf6,  0x64,  0x12,  0x2f,  0x01,  0x73,  0x99,  0x0a,  0x64,  0x42,  0x92,  0x02,  0xfe,  0x2e,  0x03,  0x08,
13570   0x05,  0x0a,  0x8a,  0x44,  0x0a,  0x10,  0x00,  0xfe,  0x5c,  0x10,  0x68,  0x05,  0x1a,  0xfe,  0x58,  0x12,
13571   0x08,  0x05,  0x1a,  0xfe,  0x50,  0x13,  0xfe,  0x1c,  0x1c,  0xfe,  0x9d,  0xf0,  0xfe,  0x50,  0x0d,  0xfe,
13572   0x1c,  0x1c,  0xfe,  0x9d,  0xf0,  0xfe,  0x56,  0x0d,  0x08,  0x54,  0x1a,  0x37,  0xfe,  0xa9,  0x10,  0x10,
13573   0xfe,  0x15,  0x00,  0xfe,  0x04,  0xe6,  0x0a,  0x50,  0xfe,  0x2e,  0x10,  0x10,  0xfe,  0x13,  0x00,  0xfe,
13574   0x10,  0x10,  0x10,  0x6f,  0xab,  0x10,  0xfe,  0x41,  0x00,  0xaa,  0x10,  0xfe,  0x24,  0x00,  0x8c,  0xb5,
13575   0xb6,  0x74,  0x03,  0x70,  0x28,  0x23,  0xd8,  0x50,  0xfe,  0x04,  0xe6,  0x1a,  0xfe,  0x9d,  0x41,  0xfe,
13576   0x1c,  0x42,  0x64,  0x01,  0xe3,  0x02,  0x2b,  0xf8,  0x15,  0x0a,  0x39,  0xa0,  0xb4,  0x15,  0xfe,  0x31,
13577   0x00,  0x39,  0xa2,  0x01,  0xfe,  0x48,  0x10,  0x02,  0xd7,  0x42,  0xfe,  0x06,  0xec,  0xd0,  0xfc,  0x44,
13578   0x1b,  0xfe,  0xce,  0x45,  0x35,  0x42,  0xfe,  0x06,  0xea,  0xd0,  0xfe,  0x47,  0x4b,  0x91,  0xfe,  0x75,
13579   0x57,  0x03,  0x5d,  0xfe,  0x98,  0x56,  0xfe,  0x38,  0x12,  0x09,  0x48,  0x01,  0x0e,  0xfe,  0x44,  0x48,
13580   0x4f,  0x08,  0x05,  0x1b,  0xfe,  0x1a,  0x13,  0x09,  0x46,  0x01,  0x0e,  0x41,  0xfe,  0x41,  0x58,  0x09,
13581   0xa4,  0x01,  0x0e,  0xfe,  0x49,  0x54,  0x96,  0xfe,  0x1e,  0x0e,  0x02,  0xfe,  0x2e,  0x03,  0x09,  0x5d,
13582   0xfe,  0xee,  0x14,  0xfc,  0x44,  0x1b,  0xfe,  0xce,  0x45,  0x35,  0x42,  0xfe,  0xce,  0x47,  0xfe,  0xad,
13583   0x13,  0x02,  0x2b,  0x22,  0x20,  0x07,  0x11,  0xfe,  0x9e,  0x12,  0x21,  0x13,  0x59,  0x13,  0x9f,  0x13,
13584   0xd5,  0x22,  0x2f,  0x41,  0x39,  0x2f,  0xbc,  0xad,  0xfe,  0xbc,  0xf0,  0xfe,  0xe0,  0x0e,  0x0f,  0x06,
13585   0x13,  0x59,  0x01,  0xfe,  0xda,  0x16,  0x03,  0xfe,  0x38,  0x01,  0x29,  0xfe,  0x3a,  0x01,  0x56,  0xfe,
13586   0xe4,  0x0e,  0xfe,  0x02,  0xec,  0xd5,  0x69,  0x00,  0x66,  0xfe,  0x04,  0xec,  0x20,  0x4f,  0xfe,  0x05,
13587   0xf6,  0xfe,  0x34,  0x01,  0x01,  0xfe,  0x4a,  0x17,  0xfe,  0x08,  0x90,  0xfe,  0x48,  0xf4,  0x0d,  0xfe,
13588   0x18,  0x13,  0xba,  0xfe,  0x02,  0xea,  0xd5,  0x69,  0x7e,  0xfe,  0xc5,  0x13,  0x15,  0x1a,  0x39,  0xa0,
13589   0xb4,  0xfe,  0x2e,  0x10,  0x03,  0xfe,  0x38,  0x01,  0x1e,  0xfe,  0xf0,  0xff,  0x0c,  0xfe,  0x60,  0x01,
13590   0x03,  0xfe,  0x3a,  0x01,  0x0c,  0xfe,  0x62,  0x01,  0x43,  0x13,  0x20,  0x25,  0x06,  0x13,  0x2f,  0x12,
13591   0x2f,  0x92,  0x0f,  0x06,  0x04,  0x21,  0x04,  0x22,  0x59,  0xfe,  0xf7,  0x12,  0x22,  0x9f,  0xb7,  0x13,
13592   0x9f,  0x07,  0x7e,  0xfe,  0x71,  0x13,  0xfe,  0x24,  0x1c,  0x15,  0x19,  0x39,  0xa0,  0xb4,  0xfe,  0xd9,
13593   0x10,  0xc3,  0xfe,  0x03,  0xdc,  0xfe,  0x73,  0x57,  0xfe,  0x80,  0x5d,  0x04,  0xc3,  0xfe,  0x03,  0xdc,
13594   0xfe,  0x5b,  0x57,  0xfe,  0x80,  0x5d,  0x04,  0xfe,  0x03,  0x57,  0xc3,  0x21,  0xfe,  0x00,  0xcc,  0x04,
13595   0xfe,  0x03,  0x57,  0xc3,  0x78,  0x04,  0x08,  0x05,  0x58,  0xfe,  0x22,  0x13,  0xfe,  0x1c,  0x80,  0x07,
13596   0x06,  0xfe,  0x1a,  0x13,  0xfe,  0x1e,  0x80,  0xed,  0xfe,  0x1d,  0x80,  0xae,  0xfe,  0x0c,  0x90,  0xfe,
13597   0x0e,  0x13,  0xfe,  0x0e,  0x90,  0xac,  0xfe,  0x3c,  0x90,  0xfe,  0x30,  0xf4,  0x0a,  0xfe,  0x3c,  0x50,
13598   0xaa,  0x01,  0xfe,  0x7a,  0x17,  0x32,  0x07,  0x2f,  0xad,  0x01,  0xfe,  0xb4,  0x16,  0x08,  0x05,  0x1b,
13599   0x4e,  0x01,  0xf5,  0x01,  0xf6,  0x12,  0xfe,  0xe9,  0x00,  0x08,  0x05,  0x58,  0xfe,  0x2c,  0x13,  0x01,
13600   0xfe,  0x0c,  0x17,  0xfe,  0x1e,  0x1c,  0xfe,  0x14,  0x90,  0xfe,  0x96,  0x90,  0x0c,  0xfe,  0x64,  0x01,
13601   0x14,  0xfe,  0x66,  0x01,  0x08,  0x05,  0x5b,  0xfe,  0x12,  0x12,  0xfe,  0x03,  0x80,  0x8d,  0xfe,  0x01,
13602   0xec,  0x20,  0xfe,  0x80,  0x40,  0x13,  0x20,  0x6a,  0x2a,  0x12,  0xcf,  0x64,  0x22,  0x20,  0xfb,  0x79,
13603   0x20,  0x04,  0xfe,  0x08,  0x1c,  0x03,  0xfe,  0xac,  0x00,  0xfe,  0x06,  0x58,  0x03,  0xfe,  0xae,  0x00,
13604
13605   0xfe,  0x07,  0x58,  0x03,  0xfe,  0xb0,  0x00,  0xfe,  0x08,  0x58,  0x03,  0xfe,  0xb2,  0x00,  0xfe,  0x09,
13606   0x58,  0xfe,  0x0a,  0x1c,  0x25,  0x6e,  0x13,  0xd0,  0x21,  0x0c,  0x5c,  0x0c,  0x45,  0x0f,  0x46,  0x52,
13607   0x50,  0x18,  0x1b,  0xfe,  0x90,  0x4d,  0xfe,  0x91,  0x54,  0x23,  0xfe,  0xfc,  0x0f,  0x44,  0x11,  0x0f,
13608   0x48,  0x52,  0x18,  0x58,  0xfe,  0x90,  0x4d,  0xfe,  0x91,  0x54,  0x23,  0xe4,  0x25,  0x11,  0x13,  0x20,
13609   0x7c,  0x6f,  0x4f,  0x22,  0x20,  0xfb,  0x79,  0x20,  0x12,  0xcf,  0xfe,  0x14,  0x56,  0xfe,  0xd6,  0xf0,
13610   0xfe,  0x26,  0x10,  0xf8,  0x74,  0xfe,  0x14,  0x1c,  0xfe,  0x10,  0x1c,  0xfe,  0x18,  0x1c,  0x04,  0x42,
13611   0xfe,  0x0c,  0x14,  0xfc,  0xfe,  0x07,  0xe6,  0x1b,  0xfe,  0xce,  0x47,  0xfe,  0xf5,  0x13,  0x04,  0x01,
13612   0xb0,  0x7c,  0x6f,  0x4f,  0xfe,  0x06,  0x80,  0xfe,  0x48,  0x47,  0xfe,  0x42,  0x13,  0x32,  0x07,  0x2f,
13613   0xfe,  0x34,  0x13,  0x09,  0x48,  0x01,  0x0e,  0xbb,  0xfe,  0x36,  0x12,  0xfe,  0x41,  0x48,  0xfe,  0x45,
13614   0x48,  0x01,  0xf0,  0xfe,  0x00,  0xcc,  0xbb,  0xfe,  0xf3,  0x13,  0x43,  0x78,  0x07,  0x11,  0xac,  0x09,
13615   0x84,  0x01,  0x0e,  0xfe,  0x80,  0x5c,  0x01,  0x73,  0xfe,  0x0e,  0x10,  0x07,  0x82,  0x4e,  0xfe,  0x14,
13616   0x56,  0xfe,  0xd6,  0xf0,  0xfe,  0x60,  0x10,  0x04,  0xfe,  0x44,  0x58,  0x8d,  0xfe,  0x01,  0xec,  0xa2,
13617   0xfe,  0x9e,  0x40,  0xfe,  0x9d,  0xe7,  0x00,  0xfe,  0x9c,  0xe7,  0x1a,  0x79,  0x2a,  0x01,  0xe3,  0xfe,
13618   0xdd,  0x10,  0x2c,  0xc7,  0x81,  0xc8,  0x83,  0x33,  0x31,  0xde,  0x07,  0x1a,  0xfe,  0x48,  0x12,  0x07,
13619   0x0a,  0xfe,  0x56,  0x12,  0x07,  0x19,  0xfe,  0x30,  0x12,  0x07,  0xc9,  0x17,  0xfe,  0x32,  0x12,  0x07,
13620   0xfe,  0x23,  0x00,  0x17,  0xeb,  0x07,  0x06,  0x17,  0xfe,  0x9c,  0x12,  0x07,  0x1f,  0xfe,  0x12,  0x12,
13621   0x07,  0x00,  0x17,  0x24,  0x15,  0xc9,  0x01,  0x36,  0xa9,  0x2d,  0x01,  0x0b,  0x94,  0x4b,  0x04,  0x2d,
13622   0xdd,  0x09,  0xd1,  0x01,  0xfe,  0x26,  0x0f,  0x12,  0x82,  0x02,  0x2b,  0x2d,  0x32,  0x07,  0xa6,  0xfe,
13623   0xd9,  0x13,  0x3a,  0x3d,  0x3b,  0x3e,  0x56,  0xfe,  0xf0,  0x11,  0x08,  0x05,  0x5a,  0xfe,  0x72,  0x12,
13624   0x9b,  0x2e,  0x9c,  0x3c,  0x90,  0xc0,  0x96,  0xfe,  0xba,  0x11,  0x22,  0x62,  0xfe,  0x26,  0x13,  0x03,
13625   0x7f,  0x29,  0x80,  0x56,  0xfe,  0x76,  0x0d,  0x0c,  0x60,  0x14,  0x61,  0x21,  0x0c,  0x7f,  0x0c,  0x80,
13626   0x01,  0xb3,  0x25,  0x6e,  0x77,  0x13,  0x62,  0x01,  0xef,  0x9b,  0x2e,  0x9c,  0x3c,  0xfe,  0x04,  0x55,
13627   0xfe,  0xa5,  0x55,  0xfe,  0x04,  0xfa,  0x2e,  0xfe,  0x05,  0xfa,  0x3c,  0xfe,  0x91,  0x10,  0x03,  0x3f,
13628   0x29,  0x40,  0xfe,  0x40,  0x56,  0xfe,  0xe1,  0x56,  0x0c,  0x3f,  0x14,  0x40,  0x88,  0x9b,  0x2e,  0x9c,
13629   0x3c,  0x90,  0xc0,  0x03,  0x5e,  0x29,  0x5f,  0xfe,  0x00,  0x56,  0xfe,  0xa1,  0x56,  0x0c,  0x5e,  0x14,
13630   0x5f,  0x08,  0x05,  0x5a,  0xfe,  0x1e,  0x12,  0x22,  0x62,  0xfe,  0x1f,  0x40,  0x03,  0x60,  0x29,  0x61,
13631   0xfe,  0x2c,  0x50,  0xfe,  0xae,  0x50,  0x03,  0x3f,  0x29,  0x40,  0xfe,  0x44,  0x50,  0xfe,  0xc6,  0x50,
13632   0x03,  0x5e,  0x29,  0x5f,  0xfe,  0x08,  0x50,  0xfe,  0x8a,  0x50,  0x03,  0x3d,  0x29,  0x3e,  0xfe,  0x40,
13633   0x50,  0xfe,  0xc2,  0x50,  0x02,  0x89,  0x25,  0x06,  0x13,  0xd4,  0x02,  0x72,  0x2d,  0x01,  0x0b,  0x1d,
13634   0x4c,  0x33,  0x31,  0xde,  0x07,  0x06,  0x23,  0x4c,  0x32,  0x07,  0xa6,  0x23,  0x72,  0x01,  0xaf,  0x1e,
13635   0x43,  0x17,  0x4c,  0x08,  0x05,  0x0a,  0xee,  0x3a,  0x3d,  0x3b,  0x3e,  0xfe,  0x0a,  0x55,  0x35,  0xfe,
13636   0x8b,  0x55,  0x57,  0x3d,  0x7d,  0x3e,  0xfe,  0x0c,  0x51,  0xfe,  0x8e,  0x51,  0x02,  0x72,  0xfe,  0x19,
13637   0x81,  0xba,  0xfe,  0x19,  0x41,  0x02,  0x72,  0x2d,  0x01,  0x0b,  0x1c,  0x34,  0x1d,  0xe8,  0x33,  0x31,
13638   0xe1,  0x55,  0x19,  0xfe,  0xa6,  0x12,  0x55,  0x0a,  0x4d,  0x02,  0x4c,  0x01,  0x0b,  0x1c,  0x34,  0x1d,
13639   0xe8,  0x33,  0x31,  0xdf,  0x07,  0x19,  0x23,  0x4c,  0x01,  0x0b,  0x1d,  0xe8,  0x33,  0x31,  0xfe,  0xe8,
13640   0x09,  0xfe,  0xc2,  0x49,  0x51,  0x03,  0xfe,  0x9c,  0x00,  0x28,  0x8a,  0x53,  0x05,  0x1f,  0x35,  0xa9,
13641   0xfe,  0xbb,  0x45,  0x55,  0x00,  0x4e,  0x44,  0x06,  0x7c,  0x43,  0xfe,  0xda,  0x14,  0x01,  0xaf,  0x8c,
13642   0xfe,  0x4b,  0x45,  0xee,  0x32,  0x07,  0xa5,  0xed,  0x03,  0xcd,  0x28,  0x8a,  0x03,  0x45,  0x28,  0x35,
13643   0x67,  0x02,  0x72,  0xfe,  0xc0,  0x5d,  0xfe,  0xf8,  0x14,  0xfe,  0x03,  0x17,  0x03,  0x5c,  0xc1,  0x0c,
13644   0x5c,  0x67,  0x2d,  0x01,  0x0b,  0x26,  0x89,  0x01,  0xfe,  0x9e,  0x15,  0x02,  0x89,  0x01,  0x0b,  0x1c,
13645   0x34,  0x1d,  0x4c,  0x33,  0x31,  0xdf,  0x07,  0x06,  0x23,  0x4c,  0x01,  0xf1,  0xfe,  0x42,  0x58,  0xf1,
13646   0xfe,  0xa4,  0x14,  0x8c,  0xfe,  0x4a,  0xf4,  0x0a,  0x17,  0x4c,  0xfe,  0x4a,  0xf4,  0x06,  0xea,  0x32,
13647   0x07,  0xa5,  0x8b,  0x02,  0x72,  0x03,  0x45,  0xc1,  0x0c,  0x45,  0x67,  0x2d,  0x01,  0x0b,  0x26,  0x89,
13648   0x01,  0xfe,  0xcc,  0x15,  0x02,  0x89,  0x0f,  0x06,  0x27,  0xfe,  0xbe,  0x13,  0x26,  0xfe,  0xd4,  0x13,
13649   0x76,  0xfe,  0x89,  0x48,  0x01,  0x0b,  0x21,  0x76,  0x04,  0x7b,  0xfe,  0xd0,  0x13,  0x1c,  0xfe,  0xd0,
13650   0x13,  0x1d,  0xfe,  0xbe,  0x13,  0x67,  0x2d,  0x01,  0x0b,  0xfe,  0xd5,  0x10,  0x0f,  0x71,  0xff,  0x02,
13651   0x00,  0x57,  0x52,  0x93,  0x1e,  0xfe,  0xff,  0x7f,  0xfe,  0x30,  0x56,  0xfe,  0x00,  0x5c,  0x04,  0x0f,
13652   0x71,  0xff,  0x02,  0x00,  0x57,  0x52,  0x93,  0x1e,  0x43,  0xfe,  0x30,  0x56,  0xfe,  0x00,  0x5c,  0x04,
13653   0x0f,  0x71,  0xff,  0x02,  0x00,  0x57,  0x52,  0x93,  0x04,  0x0f,  0x71,  0xff,  0x02,  0x00,  0x57,  0x52,
13654   0x93,  0xfe,  0x0b,  0x58,  0x04,  0x09,  0x5c,  0x01,  0x87,  0x09,  0x45,  0x01,  0x87,  0x04,  0xfe,  0x03,
13655   0xa1,  0x1e,  0x11,  0xff,  0x03,  0x00,  0x54,  0xfe,  0x00,  0xf4,  0x1f,  0x52,  0xfe,  0x00,  0x7d,  0xfe,
13656   0x01,  0x7d,  0xfe,  0x02,  0x7d,  0xfe,  0x03,  0x7c,  0x6a,  0x2a,  0x0c,  0x5e,  0x14,  0x5f,  0x57,  0x3f,
13657   0x7d,  0x40,  0x04,  0xdd,  0xfe,  0x82,  0x4a,  0xfe,  0xe1,  0x1a,  0xfe,  0x83,  0x5a,  0x8d,  0x04,  0x01,
13658   0xfe,  0x0c,  0x19,  0xfe,  0x42,  0x48,  0x50,  0x51,  0x91,  0x01,  0x0b,  0x1d,  0xfe,  0x96,  0x15,  0x33,
13659   0x31,  0xe1,  0x01,  0x0b,  0x1d,  0xfe,  0x96,  0x15,  0x33,  0x31,  0xfe,  0xe8,  0x0a,  0xfe,  0xc1,  0x59,
13660   0x03,  0xcd,  0x28,  0xfe,  0xcc,  0x12,  0x53,  0x05,  0x1a,  0xfe,  0xc4,  0x13,  0x21,  0x69,  0x1a,  0xee,
13661   0x55,  0xca,  0x6b,  0xfe,  0xdc,  0x14,  0x4d,  0x0f,  0x06,  0x18,  0xca,  0x7c,  0x30,  0xfe,  0x78,  0x10,
13662   0xff,  0x02,  0x83,  0x55,  0xab,  0xff,  0x02,  0x83,  0x55,  0x69,  0x19,  0xae,  0x98,  0xfe,  0x30,  0x00,
13663   0x96,  0xf2,  0x18,  0x6d,  0x0f,  0x06,  0xfe,  0x56,  0x10,  0x69,  0x0a,  0xed,  0x98,  0xfe,  0x64,  0x00,
13664   0x96,  0xf2,  0x09,  0xfe,  0x64,  0x00,  0x18,  0x9e,  0x0f,  0x06,  0xfe,  0x28,  0x10,  0x69,  0x06,  0xfe,
13665   0x60,  0x13,  0x98,  0xfe,  0xc8,  0x00,  0x96,  0xf2,  0x09,  0xfe,  0xc8,  0x00,  0x18,  0x59,  0x0f,  0x06,
13666   0x88,  0x98,  0xfe,  0x90,  0x01,  0x7a,  0xfe,  0x42,  0x15,  0x91,  0xe4,  0xfe,  0x43,  0xf4,  0x9f,  0xfe,
13667   0x56,  0xf0,  0xfe,  0x54,  0x15,  0xfe,  0x04,  0xf4,  0x71,  0xfe,  0x43,  0xf4,  0x9e,  0xfe,  0xf3,  0x10,
13668   0xfe,  0x40,  0x5c,  0x01,  0xfe,  0x16,  0x14,  0x1e,  0x43,  0xec,  0xfe,  0x00,  0x17,  0xfe,  0x4d,  0xe4,
13669   0x6e,  0x7a,  0xfe,  0x90,  0x15,  0xc4,  0x6e,  0xfe,  0x1c,  0x10,  0xfe,  0x00,  0x17,  0xfe,  0x4d,  0xe4,
13670   0xcc,  0x7a,  0xfe,  0x90,  0x15,  0xc4,  0xcc,  0x88,  0x51,  0x21,  0xfe,  0x4d,  0xf4,  0x00,  0xe9,  0x91,
13671   0x0f,  0x06,  0xfe,  0xb4,  0x56,  0xfe,  0xc3,  0x58,  0x04,  0x51,  0x0f,  0x0a,  0x04,  0x16,  0x06,  0x01,
13672   0x0b,  0x26,  0xf3,  0x16,  0x0a,  0x01,  0x0b,  0x26,  0xf3,  0x16,  0x19,  0x01,  0x0b,  0x26,  0xf3,  0x76,
13673   0xfe,  0x89,  0x49,  0x01,  0x0b,  0x04,  0x16,  0x06,  0x01,  0x0b,  0x26,  0xb1,  0x16,  0x19,  0x01,  0x0b,
13674   0x26,  0xb1,  0x16,  0x06,  0x01,  0x0b,  0x26,  0xb1,  0xfe,  0x89,  0x49,  0x01,  0x0b,  0x26,  0xb1,  0x76,
13675   0xfe,  0x89,  0x4a,  0x01,  0x0b,  0x04,  0x51,  0x04,  0x22,  0xd3,  0x07,  0x06,  0xfe,  0x48,  0x13,  0xb8,
13676   0x13,  0xd3,  0xfe,  0x49,  0xf4,  0x00,  0x4d,  0x76,  0xa9,  0x67,  0xfe,  0x01,  0xec,  0xfe,  0x27,  0x01,
13677   0xfe,  0x89,  0x48,  0xff,  0x02,  0x00,  0x10,  0x27,  0xfe,  0x2e,  0x16,  0x32,  0x07,  0xfe,  0xe3,  0x00,
13678   0xfe,  0x20,  0x13,  0x1d,  0xfe,  0x52,  0x16,  0x21,  0x13,  0xd4,  0x01,  0x4b,  0x22,  0xd4,  0x07,  0x06,
13679   0x4e,  0x08,  0x54,  0x06,  0x37,  0x04,  0x09,  0x48,  0x01,  0x0e,  0xfb,  0x8e,  0x07,  0x11,  0xae,  0x09,
13680   0x84,  0x01,  0x0e,  0x8e,  0x09,  0x5d,  0x01,  0xa8,  0x04,  0x09,  0x84,  0x01,  0x0e,  0x8e,  0xfe,  0x80,
13681   0xe7,  0x11,  0x07,  0x11,  0x8a,  0xfe,  0x45,  0x58,  0x01,  0xf0,  0x8e,  0x04,  0x09,  0x48,  0x01,  0x0e,
13682   0x8e,  0x09,  0x5d,  0x01,  0xa8,  0x04,  0x09,  0x48,  0x01,  0x0e,  0xfe,  0x80,  0x80,  0xfe,  0x80,  0x4c,
13683   0xfe,  0x49,  0xe4,  0x11,  0xae,  0x09,  0x84,  0x01,  0x0e,  0xfe,  0x80,  0x4c,  0x09,  0x5d,  0x01,  0x87,
13684   0x04,  0x18,  0x11,  0x75,  0x6c,  0xfe,  0x60,  0x01,  0xfe,  0x18,  0xdf,  0xfe,  0x19,  0xde,  0xfe,  0x24,
13685   0x1c,  0xfe,  0x1d,  0xf7,  0x1b,  0x97,  0xfe,  0xee,  0x16,  0x01,  0xfe,  0xf4,  0x17,  0xad,  0x9a,  0x1b,
13686   0x6c,  0xfe,  0x2c,  0x01,  0xfe,  0x2f,  0x19,  0x04,  0xb9,  0x23,  0xfe,  0xde,  0x16,  0xfe,  0xda,  0x10,
13687   0x18,  0x11,  0x75,  0x03,  0xfe,  0x64,  0x01,  0xfe,  0x00,  0xf4,  0x1f,  0xfe,  0x18,  0x58,  0x03,  0xfe,
13688   0x66,  0x01,  0xfe,  0x19,  0x58,  0x9a,  0x1f,  0xfe,  0x3c,  0x90,  0xfe,  0x30,  0xf4,  0x06,  0xfe,  0x3c,
13689   0x50,  0x6c,  0xfe,  0x38,  0x00,  0xfe,  0x0f,  0x79,  0xfe,  0x1c,  0xf7,  0x1f,  0x97,  0xfe,  0x38,  0x17,
13690   0xfe,  0xb6,  0x14,  0x35,  0x04,  0xb9,  0x23,  0xfe,  0x10,  0x17,  0xfe,  0x9c,  0x10,  0x18,  0x11,  0x75,
13691   0xfe,  0x83,  0x5a,  0xfe,  0x18,  0xdf,  0xfe,  0x19,  0xde,  0xfe,  0x1d,  0xf7,  0x2e,  0x97,  0xfe,  0x5a,
13692   0x17,  0xfe,  0x94,  0x14,  0xec,  0x9a,  0x2e,  0x6c,  0x1a,  0xfe,  0xaf,  0x19,  0xfe,  0x98,  0xe7,  0x00,
13693   0x04,  0xb9,  0x23,  0xfe,  0x4e,  0x17,  0xfe,  0x6c,  0x10,  0x18,  0x11,  0x75,  0xfe,  0x30,  0xbc,  0xfe,
13694   0xb2,  0xbc,  0x9a,  0xcb,  0x6c,  0x1a,  0xfe,  0x0f,  0x79,  0xfe,  0x1c,  0xf7,  0xcb,  0x97,  0xfe,  0x92,
13695   0x17,  0xfe,  0x5c,  0x14,  0x35,  0x04,  0xb9,  0x23,  0xfe,  0x7e,  0x17,  0xfe,  0x42,  0x10,  0xfe,  0x02,
13696   0xf6,  0x11,  0x75,  0xfe,  0x18,  0xfe,  0x60,  0xfe,  0x19,  0xfe,  0x61,  0xfe,  0x03,  0xa1,  0xfe,  0x1d,
13697   0xf7,  0x5b,  0x97,  0xfe,  0xb8,  0x17,  0xfe,  0x36,  0x14,  0xfe,  0x1c,  0x13,  0x9a,  0x5b,  0x41,  0xfe,
13698   0x83,  0x58,  0xfe,  0xaf,  0x19,  0xfe,  0x80,  0xe7,  0x11,  0xfe,  0x81,  0xe7,  0x11,  0x12,  0xfe,  0xdd,
13699   0x00,  0x6a,  0x2a,  0x04,  0x6a,  0x2a,  0xfe,  0x12,  0x45,  0x23,  0xfe,  0xa8,  0x17,  0x15,  0x06,  0x39,
13700   0xa0,  0xb4,  0x02,  0x2b,  0xfe,  0x39,  0xf0,  0xfe,  0xfc,  0x17,  0x21,  0x04,  0xfe,  0x7e,  0x18,  0x1e,
13701   0x19,  0x66,  0x0f,  0x0d,  0x04,  0x75,  0x03,  0xd2,  0x1e,  0x06,  0xfe,  0xef,  0x12,  0xfe,  0xe1,  0x10,
13702   0x7c,  0x6f,  0x4f,  0x32,  0x07,  0x2f,  0xfe,  0x3c,  0x13,  0xf1,  0xfe,  0x42,  0x13,  0x42,  0x92,  0x09,
13703   0x48,  0x01,  0x0e,  0xbb,  0xeb,  0xfe,  0x41,  0x48,  0xfe,  0x45,  0x48,  0x01,  0xf0,  0xfe,  0x00,  0xcc,
13704   0xbb,  0xfe,  0xf3,  0x13,  0x43,  0x78,  0x07,  0x11,  0xac,  0x09,  0x84,  0x01,  0x0e,  0xfe,  0x80,  0x4c,
13705   0x01,  0x73,  0xfe,  0x16,  0x10,  0x07,  0x82,  0x8b,  0xfe,  0x40,  0x14,  0xfe,  0x24,  0x12,  0xfe,  0x14,
13706   0x56,  0xfe,  0xd6,  0xf0,  0xfe,  0x1c,  0x18,  0x18,  0x0a,  0x04,  0xfe,  0x9c,  0xe7,  0x0a,  0x10,  0xfe,
13707   0x15,  0x00,  0x64,  0x79,  0x2a,  0x01,  0xe3,  0x18,  0x06,  0x04,  0x42,  0x92,  0x08,  0x54,  0x1b,  0x37,
13708   0x12,  0x2f,  0x01,  0x73,  0x18,  0x06,  0x04,  0xfe,  0x38,  0x90,  0xfe,  0xba,  0x90,  0x3a,  0xce,  0x3b,
13709   0xcf,  0xfe,  0x48,  0x55,  0x35,  0xfe,  0xc9,  0x55,  0x04,  0x22,  0xa3,  0x77,  0x13,  0xa3,  0x04,  0x09,
13710   0xa4,  0x01,  0x0e,  0xfe,  0x41,  0x48,  0x09,  0x46,  0x01,  0x0e,  0xfe,  0x49,  0x44,  0x17,  0xfe,  0xe8,
13711   0x18,  0x77,  0x78,  0x04,  0x09,  0x48,  0x01,  0x0e,  0x07,  0x11,  0x4e,  0x09,  0x5d,  0x01,  0xa8,  0x09,
13712   0x46,  0x01,  0x0e,  0x77,  0x78,  0x04,  0xfe,  0x4e,  0xe4,  0x19,  0x6b,  0xfe,  0x1c,  0x19,  0x03,  0xfe,
13713   0x90,  0x00,  0xfe,  0x3a,  0x45,  0xfe,  0x2c,  0x10,  0xfe,  0x4e,  0xe4,  0xc9,  0x6b,  0xfe,  0x2e,  0x19,
13714   0x03,  0xfe,  0x92,  0x00,  0xfe,  0x02,  0xe6,  0x1a,  0xe5,  0xfe,  0x4e,  0xe4,  0xfe,  0x0b,  0x00,  0x6b,
13715   0xfe,  0x40,  0x19,  0x03,  0xfe,  0x94,  0x00,  0xfe,  0x02,  0xe6,  0x1f,  0xfe,  0x08,  0x10,  0x03,  0xfe,
13716   0x96,  0x00,  0xfe,  0x02,  0xe6,  0x6d,  0xfe,  0x4e,  0x45,  0xea,  0xba,  0xff,  0x04,  0x68,  0x54,  0xe7,
13717   0x1e,  0x6e,  0xfe,  0x08,  0x1c,  0xfe,  0x67,  0x19,  0xfe,  0x0a,  0x1c,  0xfe,  0x1a,  0xf4,  0xfe,  0x00,
13718   0x04,  0xea,  0xfe,  0x48,  0xf4,  0x19,  0x7a,  0xfe,  0x74,  0x19,  0x0f,  0x19,  0x04,  0x07,  0x7e,  0xfe,
13719   0x5a,  0xf0,  0xfe,  0x84,  0x19,  0x25,  0xfe,  0x09,  0x00,  0xfe,  0x34,  0x10,  0x07,  0x1a,  0xfe,  0x5a,
13720   0xf0,  0xfe,  0x92,  0x19,  0x25,  0xca,  0xfe,  0x26,  0x10,  0x07,  0x19,  0x66,  0x25,  0x6d,  0xe5,  0x07,
13721   0x0a,  0x66,  0x25,  0x9e,  0xfe,  0x0e,  0x10,  0x07,  0x06,  0x66,  0x25,  0x59,  0xa9,  0xb8,  0x04,  0x15,
13722   0xfe,  0x09,  0x00,  0x01,  0x36,  0xfe,  0x04,  0xfe,  0x81,  0x03,  0x83,  0xfe,  0x40,  0x5c,  0x04,  0x1c,
13723   0xf7,  0xfe,  0x14,  0xf0,  0x0b,  0x27,  0xfe,  0xd6,  0x19,  0x1c,  0xf7,  0x7b,  0xf7,  0xfe,  0x82,  0xf0,
13724   0xfe,  0xda,  0x19,  0x04,  0xff,  0xcc,  0x00,  0x00,
13725 };
13726
13727 STATIC unsigned short _adv_asc38C0800_size =
13728         sizeof(_adv_asc38C0800_buf); /* 0x14E1 */
13729 STATIC ADV_DCNT _adv_asc38C0800_chksum =
13730         0x050D3FD8UL; /* Expanded little-endian checksum. */
13731
13732 /* Microcode buffer is kept after initialization for error recovery. */
13733 STATIC unsigned char _adv_asc38C1600_buf[] = {
13734   0x00,  0x00,  0x00,  0xf2,  0x00,  0x16,  0x00,  0xfc,  0x00,  0x10,  0x00,  0xf0,  0x18,  0xe4,  0x01,  0x00,
13735   0x04,  0x1e,  0x48,  0xe4,  0x03,  0xf6,  0xf7,  0x13,  0x2e,  0x1e,  0x02,  0x00,  0x07,  0x17,  0xc0,  0x5f,
13736   0x00,  0xfa,  0xff,  0xff,  0x04,  0x00,  0x00,  0xf6,  0x09,  0xe7,  0x82,  0xe7,  0x85,  0xf0,  0x86,  0xf0,
13737   0x4e,  0x10,  0x9e,  0xe7,  0xff,  0x00,  0x55,  0xf0,  0x01,  0xf6,  0x03,  0x00,  0x98,  0x57,  0x01,  0xe6,
13738   0x00,  0xea,  0x00,  0xec,  0x01,  0xfa,  0x18,  0xf4,  0x08,  0x00,  0xf0,  0x1d,  0x38,  0x54,  0x32,  0xf0,
13739   0x10,  0x00,  0xc2,  0x0e,  0x1e,  0xf0,  0xd5,  0xf0,  0xbc,  0x00,  0x4b,  0xe4,  0x00,  0xe6,  0xb1,  0xf0,
13740   0xb4,  0x00,  0x02,  0x13,  0x3e,  0x1c,  0xc8,  0x47,  0x3e,  0x00,  0xd8,  0x01,  0x06,  0x13,  0x0c,  0x1c,
13741   0x5e,  0x1e,  0x00,  0x57,  0xc8,  0x57,  0x01,  0xfc,  0xbc,  0x0e,  0xa2,  0x12,  0xb9,  0x54,  0x00,  0x80,
13742   0x62,  0x0a,  0x5a,  0x12,  0xc8,  0x15,  0x3e,  0x1e,  0x18,  0x40,  0xbd,  0x56,  0x03,  0xe6,  0x01,  0xea,
13743   0x5c,  0xf0,  0x0f,  0x00,  0x20,  0x00,  0x6c,  0x01,  0x6e,  0x01,  0x04,  0x12,  0x04,  0x13,  0xbb,  0x55,
13744   0x3c,  0x56,  0x3e,  0x57,  0x03,  0x58,  0x4a,  0xe4,  0x40,  0x00,  0xb6,  0x00,  0xbb,  0x00,  0xc0,  0x00,
13745   0x00,  0x01,  0x01,  0x01,  0x3e,  0x01,  0x58,  0x0a,  0x44,  0x10,  0x0a,  0x12,  0x4c,  0x1c,  0x4e,  0x1c,
13746   0x02,  0x4a,  0x30,  0xe4,  0x05,  0xe6,  0x0c,  0x00,  0x3c,  0x00,  0x80,  0x00,  0x24,  0x01,  0x3c,  0x01,
13747   0x68,  0x01,  0x6a,  0x01,  0x70,  0x01,  0x72,  0x01,  0x74,  0x01,  0x76,  0x01,  0x78,  0x01,  0x7c,  0x01,
13748   0xc6,  0x0e,  0x0c,  0x10,  0xac,  0x12,  0xae,  0x12,  0x16,  0x1a,  0x32,  0x1c,  0x6e,  0x1e,  0x02,  0x48,
13749   0x3a,  0x55,  0xc9,  0x57,  0x02,  0xee,  0x5b,  0xf0,  0x03,  0xf7,  0x06,  0xf7,  0x03,  0xfc,  0x06,  0x00,
13750   0x1e,  0x00,  0xbe,  0x00,  0xe1,  0x00,  0x0c,  0x12,  0x18,  0x1a,  0x70,  0x1a,  0x30,  0x1c,  0x38,  0x1c,
13751   0x10,  0x44,  0x00,  0x4c,  0xb0,  0x57,  0x40,  0x5c,  0x4d,  0xe4,  0x04,  0xea,  0x5d,  0xf0,  0xa7,  0xf0,
13752   0x04,  0xf6,  0x02,  0xfc,  0x05,  0x00,  0x09,  0x00,  0x19,  0x00,  0x32,  0x00,  0x33,  0x00,  0x34,  0x00,
13753   0x36,  0x00,  0x98,  0x00,  0x9e,  0x00,  0xcc,  0x00,  0x20,  0x01,  0x4e,  0x01,  0x79,  0x01,  0x3c,  0x09,
13754   0x68,  0x0d,  0x02,  0x10,  0x04,  0x10,  0x3a,  0x10,  0x08,  0x12,  0x0a,  0x13,  0x40,  0x16,  0x50,  0x16,
13755   0x00,  0x17,  0x4a,  0x19,  0x00,  0x4e,  0x00,  0x54,  0x01,  0x58,  0x00,  0xdc,  0x05,  0xf0,  0x09,  0xf0,
13756   0x59,  0xf0,  0xb8,  0xf0,  0x48,  0xf4,  0x0e,  0xf7,  0x0a,  0x00,  0x9b,  0x00,  0x9c,  0x00,  0xa4,  0x00,
13757   0xb5,  0x00,  0xba,  0x00,  0xd0,  0x00,  0xe7,  0x00,  0xf0,  0x03,  0x69,  0x08,  0xe9,  0x09,  0x5c,  0x0c,
13758   0xb6,  0x12,  0xbc,  0x19,  0xd8,  0x1b,  0x20,  0x1c,  0x34,  0x1c,  0x36,  0x1c,  0x42,  0x1d,  0x08,  0x44,
13759   0x38,  0x44,  0x91,  0x44,  0x0a,  0x45,  0x48,  0x46,  0x89,  0x48,  0x68,  0x54,  0x83,  0x55,  0x83,  0x59,
13760   0x31,  0xe4,  0x02,  0xe6,  0x07,  0xf0,  0x08,  0xf0,  0x0b,  0xf0,  0x0c,  0xf0,  0x4b,  0xf4,  0x04,  0xf8,
13761   0x05,  0xf8,  0x02,  0xfa,  0x03,  0xfa,  0x04,  0xfc,  0x05,  0xfc,  0x07,  0x00,  0xa8,  0x00,  0xaa,  0x00,
13762   0xb9,  0x00,  0xe0,  0x00,  0xe5,  0x00,  0x22,  0x01,  0x26,  0x01,  0x60,  0x01,  0x7a,  0x01,  0x82,  0x01,
13763   0xc8,  0x01,  0xca,  0x01,  0x86,  0x02,  0x6a,  0x03,  0x18,  0x05,  0xb2,  0x07,  0x68,  0x08,  0x10,  0x0d,
13764   0x06,  0x10,  0x0a,  0x10,  0x0e,  0x10,  0x12,  0x10,  0x60,  0x10,  0xed,  0x10,  0xf3,  0x10,  0x06,  0x12,
13765   0x10,  0x12,  0x1e,  0x12,  0x0c,  0x13,  0x0e,  0x13,  0x10,  0x13,  0xfe,  0x9c,  0xf0,  0x35,  0x05,  0xfe,
13766   0xec,  0x0e,  0xff,  0x10,  0x00,  0x00,  0xe9,  0xfe,  0x34,  0x1f,  0x00,  0xe8,  0xfe,  0x88,  0x01,  0xff,
13767   0x03,  0x00,  0x00,  0xfe,  0x93,  0x15,  0xfe,  0x0f,  0x05,  0xff,  0x38,  0x00,  0x00,  0xfe,  0x57,  0x24,
13768   0x00,  0xfe,  0x4c,  0x00,  0x65,  0xff,  0x04,  0x00,  0x00,  0x1a,  0xff,  0x09,  0x00,  0x00,  0xff,  0x08,
13769   0x01,  0x01,  0xff,  0x08,  0xff,  0xff,  0xff,  0x27,  0x00,  0x00,  0xff,  0x10,  0xff,  0xff,  0xff,  0x13,
13770   0x00,  0x00,  0xfe,  0x78,  0x56,  0xfe,  0x34,  0x12,  0xff,  0x21,  0x00,  0x00,  0xfe,  0x04,  0xf7,  0xe8,
13771   0x37,  0x7d,  0x0d,  0x01,  0xfe,  0x4a,  0x11,  0xfe,  0x04,  0xf7,  0xe8,  0x7d,  0x0d,  0x51,  0x37,  0xfe,
13772   0x3d,  0xf0,  0xfe,  0x0c,  0x02,  0xfe,  0x20,  0xf0,  0xbc,  0xfe,  0x91,  0xf0,  0xfe,  0xf8,  0x01,  0xfe,
13773   0x90,  0xf0,  0xfe,  0xf8,  0x01,  0xfe,  0x8f,  0xf0,  0xbc,  0x03,  0x67,  0x4d,  0x05,  0xfe,  0x08,  0x0f,
13774   0x01,  0xfe,  0x78,  0x0f,  0xfe,  0xdd,  0x12,  0x05,  0xfe,  0x0e,  0x03,  0xfe,  0x28,  0x1c,  0x03,  0xfe,
13775   0xa6,  0x00,  0xfe,  0xd1,  0x12,  0x3e,  0x22,  0xfe,  0xa6,  0x00,  0xac,  0xfe,  0x48,  0xf0,  0xfe,  0x90,
13776   0x02,  0xfe,  0x49,  0xf0,  0xfe,  0xaa,  0x02,  0xfe,  0x4a,  0xf0,  0xfe,  0xc8,  0x02,  0xfe,  0x46,  0xf0,
13777   0xfe,  0x5a,  0x02,  0xfe,  0x47,  0xf0,  0xfe,  0x60,  0x02,  0xfe,  0x43,  0xf0,  0xfe,  0x4e,  0x02,  0xfe,
13778   0x44,  0xf0,  0xfe,  0x52,  0x02,  0xfe,  0x45,  0xf0,  0xfe,  0x56,  0x02,  0x1c,  0x0d,  0xa2,  0x1c,  0x07,
13779   0x22,  0xb7,  0x05,  0x35,  0xfe,  0x00,  0x1c,  0xfe,  0xf1,  0x10,  0xfe,  0x02,  0x1c,  0xf5,  0xfe,  0x1e,
13780   0x1c,  0xfe,  0xe9,  0x10,  0x01,  0x5f,  0xfe,  0xe7,  0x10,  0xfe,  0x06,  0xfc,  0xde,  0x0a,  0x81,  0x01,
13781   0xa3,  0x05,  0x35,  0x1f,  0x95,  0x47,  0xb8,  0x01,  0xfe,  0xe4,  0x11,  0x0a,  0x81,  0x01,  0x5c,  0xfe,
13782   0xbd,  0x10,  0x0a,  0x81,  0x01,  0x5c,  0xfe,  0xad,  0x10,  0xfe,  0x16,  0x1c,  0xfe,  0x58,  0x1c,  0x1c,
13783   0x07,  0x22,  0xb7,  0x37,  0x2a,  0x35,  0xfe,  0x3d,  0xf0,  0xfe,  0x0c,  0x02,  0x2b,  0xfe,  0x9e,  0x02,
13784   0xfe,  0x5a,  0x1c,  0xfe,  0x12,  0x1c,  0xfe,  0x14,  0x1c,  0x1f,  0xfe,  0x30,  0x00,  0x47,  0xb8,  0x01,
13785   0xfe,  0xd4,  0x11,  0x1c,  0x07,  0x22,  0xb7,  0x05,  0xe9,  0x21,  0x2c,  0x09,  0x1a,  0x31,  0xfe,  0x69,
13786   0x10,  0x1c,  0x07,  0x22,  0xb7,  0xfe,  0x04,  0xec,  0x2c,  0x60,  0x01,  0xfe,  0x1e,  0x1e,  0x20,  0x2c,
13787   0xfe,  0x05,  0xf6,  0xde,  0x01,  0xfe,  0x62,  0x1b,  0x01,  0x0c,  0x61,  0x4a,  0x44,  0x15,  0x56,  0x51,
13788   0x01,  0xfe,  0x9e,  0x1e,  0x01,  0xfe,  0x96,  0x1a,  0x05,  0x35,  0x0a,  0x57,  0x01,  0x18,  0x09,  0x00,
13789   0x36,  0x01,  0x85,  0xfe,  0x18,  0x10,  0xfe,  0x41,  0x58,  0x0a,  0xba,  0x01,  0x18,  0xfe,  0xc8,  0x54,
13790   0x7b,  0xfe,  0x1c,  0x03,  0x01,  0xfe,  0x96,  0x1a,  0x05,  0x35,  0x37,  0x60,  0xfe,  0x02,  0xe8,  0x30,
13791   0xfe,  0xbf,  0x57,  0xfe,  0x9e,  0x43,  0xfe,  0x77,  0x57,  0xfe,  0x27,  0xf0,  0xfe,  0xe4,  0x01,  0xfe,
13792   0x07,  0x4b,  0xfe,  0x20,  0xf0,  0xbc,  0xfe,  0x40,  0x1c,  0x2a,  0xeb,  0xfe,  0x26,  0xf0,  0xfe,  0x66,
13793   0x03,  0xfe,  0xa0,  0xf0,  0xfe,  0x54,  0x03,  0xfe,  0x11,  0xf0,  0xbc,  0xfe,  0xef,  0x10,  0xfe,  0x9f,
13794   0xf0,  0xfe,  0x74,  0x03,  0xfe,  0x46,  0x1c,  0x19,  0xfe,  0x11,  0x00,  0x05,  0x70,  0x37,  0xfe,  0x48,
13795   0x1c,  0xfe,  0x46,  0x1c,  0x01,  0x0c,  0x06,  0x28,  0xfe,  0x18,  0x13,  0x26,  0x21,  0xb9,  0xc7,  0x20,
13796   0xb9,  0x0a,  0x57,  0x01,  0x18,  0xc7,  0x89,  0x01,  0xfe,  0xc8,  0x1a,  0x15,  0xe1,  0x2a,  0xeb,  0xfe,
13797   0x01,  0xf0,  0xeb,  0xfe,  0x82,  0xf0,  0xfe,  0xa4,  0x03,  0xfe,  0x9c,  0x32,  0x15,  0xfe,  0xe4,  0x00,
13798   0x2f,  0xfe,  0xb6,  0x03,  0x2a,  0x3c,  0x16,  0xfe,  0xc6,  0x03,  0x01,  0x41,  0xfe,  0x06,  0xf0,  0xfe,
13799   0xd6,  0x03,  0xaf,  0xa0,  0xfe,  0x0a,  0xf0,  0xfe,  0xa2,  0x07,  0x05,  0x29,  0x03,  0x81,  0x1e,  0x1b,
13800   0xfe,  0x24,  0x05,  0x1f,  0x63,  0x01,  0x42,  0x8f,  0xfe,  0x70,  0x02,  0x05,  0xea,  0xfe,  0x46,  0x1c,
13801   0x37,  0x7d,  0x1d,  0xfe,  0x67,  0x1b,  0xfe,  0xbf,  0x57,  0xfe,  0x77,  0x57,  0xfe,  0x48,  0x1c,  0x75,
13802   0x01,  0xa6,  0x86,  0x0a,  0x57,  0x01,  0x18,  0x09,  0x00,  0x1b,  0xec,  0x0a,  0xe1,  0x01,  0x18,  0x77,
13803   0x50,  0x40,  0x8d,  0x30,  0x03,  0x81,  0x1e,  0xf8,  0x1f,  0x63,  0x01,  0x42,  0x8f,  0xfe,  0x70,  0x02,
13804   0x05,  0xea,  0xd7,  0x99,  0xd8,  0x9c,  0x2a,  0x29,  0x2f,  0xfe,  0x4e,  0x04,  0x16,  0xfe,  0x4a,  0x04,
13805   0x7e,  0xfe,  0xa0,  0x00,  0xfe,  0x9b,  0x57,  0xfe,  0x54,  0x12,  0x32,  0xff,  0x02,  0x00,  0x10,  0x01,
13806   0x08,  0x16,  0xfe,  0x02,  0x05,  0x32,  0x01,  0x08,  0x16,  0x29,  0x27,  0x25,  0xee,  0xfe,  0x4c,  0x44,
13807   0xfe,  0x58,  0x12,  0x50,  0xfe,  0x44,  0x48,  0x13,  0x34,  0xfe,  0x4c,  0x54,  0x7b,  0xec,  0x60,  0x8d,
13808   0x30,  0x01,  0xfe,  0x4e,  0x1e,  0xfe,  0x48,  0x47,  0xfe,  0x7c,  0x13,  0x01,  0x0c,  0x06,  0x28,  0xfe,
13809   0x32,  0x13,  0x01,  0x43,  0x09,  0x9b,  0xfe,  0x68,  0x13,  0xfe,  0x26,  0x10,  0x13,  0x34,  0xfe,  0x4c,
13810   0x54,  0x7b,  0xec,  0x01,  0xfe,  0x4e,  0x1e,  0xfe,  0x48,  0x47,  0xfe,  0x54,  0x13,  0x01,  0x0c,  0x06,
13811   0x28,  0xa5,  0x01,  0x43,  0x09,  0x9b,  0xfe,  0x40,  0x13,  0x01,  0x0c,  0x06,  0x28,  0xf9,  0x1f,  0x7f,
13812   0x01,  0x0c,  0x06,  0x07,  0x4d,  0x1f,  0xfe,  0x0d,  0x00,  0x01,  0x42,  0x8f,  0xfe,  0xa4,  0x0e,  0x05,
13813   0x29,  0x32,  0x15,  0xfe,  0xe6,  0x00,  0x0f,  0xfe,  0x1c,  0x90,  0x04,  0xfe,  0x9c,  0x93,  0x3a,  0x0b,
13814   0x0e,  0x8b,  0x02,  0x1f,  0x7f,  0x01,  0x42,  0x05,  0x35,  0xfe,  0x42,  0x5b,  0x7d,  0x1d,  0xfe,  0x46,
13815   0x59,  0xfe,  0xbf,  0x57,  0xfe,  0x77,  0x57,  0x0f,  0xfe,  0x87,  0x80,  0x04,  0xfe,  0x87,  0x83,  0xfe,
13816   0xc9,  0x47,  0x0b,  0x0e,  0xd0,  0x65,  0x01,  0x0c,  0x06,  0x0d,  0xfe,  0x98,  0x13,  0x0f,  0xfe,  0x20,
13817   0x80,  0x04,  0xfe,  0xa0,  0x83,  0x33,  0x0b,  0x0e,  0x09,  0x1d,  0xfe,  0x84,  0x12,  0x01,  0x38,  0x06,
13818   0x07,  0xfe,  0x70,  0x13,  0x03,  0xfe,  0xa2,  0x00,  0x1e,  0x1b,  0xfe,  0xda,  0x05,  0xd0,  0x54,  0x01,
13819   0x38,  0x06,  0x0d,  0xfe,  0x58,  0x13,  0x03,  0xfe,  0xa0,  0x00,  0x1e,  0xfe,  0x50,  0x12,  0x5e,  0xff,
13820   0x02,  0x00,  0x10,  0x2f,  0xfe,  0x90,  0x05,  0x2a,  0x3c,  0xcc,  0xff,  0x02,  0x00,  0x10,  0x2f,  0xfe,
13821   0x9e,  0x05,  0x17,  0xfe,  0xf4,  0x05,  0x15,  0xfe,  0xe3,  0x00,  0x26,  0x01,  0x38,  0xfe,  0x4a,  0xf0,
13822   0xfe,  0xc0,  0x05,  0xfe,  0x49,  0xf0,  0xfe,  0xba,  0x05,  0x71,  0x2e,  0xfe,  0x21,  0x00,  0xf1,  0x2e,
13823   0xfe,  0x22,  0x00,  0xa2,  0x2e,  0x4a,  0xfe,  0x09,  0x48,  0xff,  0x02,  0x00,  0x10,  0x2f,  0xfe,  0xd0,
13824   0x05,  0x17,  0xfe,  0xf4,  0x05,  0xfe,  0xe2,  0x08,  0x01,  0x38,  0x06,  0xfe,  0x1c,  0x00,  0x4d,  0x01,
13825   0xa7,  0x2e,  0x07,  0x20,  0xe4,  0x47,  0xfe,  0x27,  0x01,  0x01,  0x0c,  0x06,  0x28,  0xfe,  0x24,  0x12,
13826   0x3e,  0x01,  0x84,  0x1f,  0x7f,  0x01,  0x0c,  0x06,  0x07,  0x4d,  0x1f,  0xfe,  0x0d,  0x00,  0x01,  0x42,
13827   0x8f,  0xfe,  0xa4,  0x0e,  0x05,  0x29,  0x03,  0xe6,  0x1e,  0xfe,  0xca,  0x13,  0x03,  0xb6,  0x1e,  0xfe,
13828   0x40,  0x12,  0x03,  0x66,  0x1e,  0xfe,  0x38,  0x13,  0x3e,  0x01,  0x84,  0x17,  0xfe,  0x72,  0x06,  0x0a,
13829   0x07,  0x01,  0x38,  0x06,  0x24,  0xfe,  0x02,  0x12,  0x4f,  0x01,  0xfe,  0x56,  0x19,  0x16,  0xfe,  0x68,
13830   0x06,  0x15,  0x82,  0x01,  0x41,  0x15,  0xe2,  0x03,  0x66,  0x8a,  0x10,  0x66,  0x03,  0x9a,  0x1e,  0xfe,
13831   0x70,  0x12,  0x03,  0x55,  0x1e,  0xfe,  0x68,  0x13,  0x01,  0xc6,  0x09,  0x12,  0x48,  0xfe,  0x92,  0x06,
13832   0x2e,  0x12,  0x01,  0xfe,  0xac,  0x1d,  0xfe,  0x43,  0x48,  0x62,  0x80,  0x13,  0x58,  0xff,  0x02,  0x00,
13833   0x57,  0x52,  0xad,  0x23,  0x3f,  0x4e,  0x62,  0x49,  0x3e,  0x01,  0x84,  0x17,  0xfe,  0xea,  0x06,  0x01,
13834   0x38,  0x06,  0x12,  0xf7,  0x45,  0x0a,  0x95,  0x01,  0xfe,  0x84,  0x19,  0x16,  0xfe,  0xe0,  0x06,  0x15,
13835   0x82,  0x01,  0x41,  0x15,  0xe2,  0x03,  0x55,  0x8a,  0x10,  0x55,  0x1c,  0x07,  0x01,  0x84,  0xfe,  0xae,
13836   0x10,  0x03,  0x6f,  0x1e,  0xfe,  0x9e,  0x13,  0x3e,  0x01,  0x84,  0x03,  0x9a,  0x1e,  0xfe,  0x1a,  0x12,
13837   0x01,  0x38,  0x06,  0x12,  0xfc,  0x01,  0xc6,  0x01,  0xfe,  0xac,  0x1d,  0xfe,  0x43,  0x48,  0x62,  0x80,
13838   0xf0,  0x45,  0x0a,  0x95,  0x03,  0xb6,  0x1e,  0xf8,  0x01,  0x38,  0x06,  0x24,  0x36,  0xfe,  0x02,  0xf6,
13839   0x07,  0x71,  0x78,  0x8c,  0x00,  0x4d,  0x62,  0x49,  0x3e,  0x2d,  0x93,  0x4e,  0xd0,  0x0d,  0x17,  0xfe,
13840   0x9a,  0x07,  0x01,  0xfe,  0xc0,  0x19,  0x16,  0xfe,  0x90,  0x07,  0x26,  0x20,  0x9e,  0x15,  0x82,  0x01,
13841   0x41,  0x15,  0xe2,  0x21,  0x9e,  0x09,  0x07,  0xfb,  0x03,  0xe6,  0xfe,  0x58,  0x57,  0x10,  0xe6,  0x05,
13842   0xfe,  0x2a,  0x06,  0x03,  0x6f,  0x8a,  0x10,  0x6f,  0x1c,  0x07,  0x01,  0x84,  0xfe,  0x9c,  0x32,  0x5f,
13843   0x75,  0x01,  0xa6,  0x86,  0x15,  0xfe,  0xe2,  0x00,  0x2f,  0xed,  0x2a,  0x3c,  0xfe,  0x0a,  0xf0,  0xfe,
13844   0xce,  0x07,  0xae,  0xfe,  0x96,  0x08,  0xfe,  0x06,  0xf0,  0xfe,  0x9e,  0x08,  0xaf,  0xa0,  0x05,  0x29,
13845   0x01,  0x0c,  0x06,  0x0d,  0xfe,  0x2e,  0x12,  0x14,  0x1d,  0x01,  0x08,  0x14,  0x00,  0x01,  0x08,  0x14,
13846   0x00,  0x01,  0x08,  0x14,  0x00,  0x01,  0x08,  0xfe,  0x99,  0xa4,  0x01,  0x08,  0x14,  0x00,  0x05,  0xfe,
13847   0xc6,  0x09,  0x01,  0x76,  0x06,  0x12,  0xfe,  0x3a,  0x12,  0x01,  0x0c,  0x06,  0x12,  0xfe,  0x30,  0x13,
13848   0x14,  0xfe,  0x1b,  0x00,  0x01,  0x08,  0x14,  0x00,  0x01,  0x08,  0x14,  0x00,  0x01,  0x08,  0x14,  0x00,
13849   0x01,  0x08,  0x14,  0x07,  0x01,  0x08,  0x14,  0x00,  0x05,  0xef,  0x7c,  0x4a,  0x78,  0x4f,  0x0f,  0xfe,
13850   0x9a,  0x81,  0x04,  0xfe,  0x9a,  0x83,  0xfe,  0xcb,  0x47,  0x0b,  0x0e,  0x2d,  0x28,  0x48,  0xfe,  0x6c,
13851   0x08,  0x0a,  0x28,  0xfe,  0x09,  0x6f,  0xca,  0xfe,  0xca,  0x45,  0xfe,  0x32,  0x12,  0x53,  0x63,  0x4e,
13852   0x7c,  0x97,  0x2f,  0xfe,  0x7e,  0x08,  0x2a,  0x3c,  0xfe,  0x0a,  0xf0,  0xfe,  0x6c,  0x08,  0xaf,  0xa0,
13853   0xae,  0xfe,  0x96,  0x08,  0x05,  0x29,  0x01,  0x41,  0x05,  0xed,  0x14,  0x24,  0x05,  0xed,  0xfe,  0x9c,
13854   0xf7,  0x9f,  0x01,  0xfe,  0xae,  0x1e,  0xfe,  0x18,  0x58,  0x01,  0xfe,  0xbe,  0x1e,  0xfe,  0x99,  0x58,
13855   0xfe,  0x78,  0x18,  0xfe,  0xf9,  0x18,  0x8e,  0xfe,  0x16,  0x09,  0x10,  0x6a,  0x22,  0x6b,  0x01,  0x0c,
13856   0x61,  0x54,  0x44,  0x21,  0x2c,  0x09,  0x1a,  0xf8,  0x77,  0x01,  0xfe,  0x7e,  0x1e,  0x47,  0x2c,  0x7a,
13857   0x30,  0xf0,  0xfe,  0x83,  0xe7,  0xfe,  0x3f,  0x00,  0x71,  0xfe,  0x03,  0x40,  0x01,  0x0c,  0x61,  0x65,
13858   0x44,  0x01,  0xc2,  0xc8,  0xfe,  0x1f,  0x40,  0x20,  0x6e,  0x01,  0xfe,  0x6a,  0x16,  0xfe,  0x08,  0x50,
13859   0xfe,  0x8a,  0x50,  0xfe,  0x44,  0x51,  0xfe,  0xc6,  0x51,  0xfe,  0x10,  0x10,  0x01,  0xfe,  0xce,  0x1e,
13860   0x01,  0xfe,  0xde,  0x1e,  0x10,  0x68,  0x22,  0x69,  0x01,  0xfe,  0xee,  0x1e,  0x01,  0xfe,  0xfe,  0x1e,
13861   0xfe,  0x40,  0x50,  0xfe,  0xc2,  0x50,  0x10,  0x4b,  0x22,  0x4c,  0xfe,  0x8a,  0x10,  0x01,  0x0c,  0x06,
13862   0x54,  0xfe,  0x50,  0x12,  0x01,  0xfe,  0xae,  0x1e,  0x01,  0xfe,  0xbe,  0x1e,  0x10,  0x6a,  0x22,  0x6b,
13863   0x01,  0x0c,  0x06,  0x65,  0x4e,  0x01,  0xc2,  0x0f,  0xfe,  0x1f,  0x80,  0x04,  0xfe,  0x9f,  0x83,  0x33,
13864   0x0b,  0x0e,  0x20,  0x6e,  0x0f,  0xfe,  0x44,  0x90,  0x04,  0xfe,  0xc4,  0x93,  0x3a,  0x0b,  0xfe,  0xc6,
13865   0x90,  0x04,  0xfe,  0xc6,  0x93,  0x79,  0x0b,  0x0e,  0x10,  0x6c,  0x22,  0x6d,  0x01,  0xfe,  0xce,  0x1e,
13866   0x01,  0xfe,  0xde,  0x1e,  0x10,  0x68,  0x22,  0x69,  0x0f,  0xfe,  0x40,  0x90,  0x04,  0xfe,  0xc0,  0x93,
13867   0x3a,  0x0b,  0xfe,  0xc2,  0x90,  0x04,  0xfe,  0xc2,  0x93,  0x79,  0x0b,  0x0e,  0x10,  0x4b,  0x22,  0x4c,
13868   0x10,  0x64,  0x22,  0x34,  0x01,  0x0c,  0x61,  0x24,  0x44,  0x37,  0x13,  0xfe,  0x4e,  0x11,  0x2f,  0xfe,
13869   0xde,  0x09,  0xfe,  0x9e,  0xf0,  0xfe,  0xf2,  0x09,  0xfe,  0x01,  0x48,  0x1b,  0x3c,  0x37,  0x88,  0xf5,
13870   0xd4,  0xfe,  0x1e,  0x0a,  0xd5,  0xfe,  0x42,  0x0a,  0xd2,  0xfe,  0x1e,  0x0a,  0xd3,  0xfe,  0x42,  0x0a,
13871   0xae,  0xfe,  0x12,  0x0a,  0xfe,  0x06,  0xf0,  0xfe,  0x18,  0x0a,  0xaf,  0xa0,  0x05,  0x29,  0x01,  0x41,
13872   0xfe,  0xc1,  0x10,  0x14,  0x24,  0xfe,  0xc1,  0x10,  0x01,  0x76,  0x06,  0x07,  0xfe,  0x14,  0x12,  0x01,
13873   0x76,  0x06,  0x0d,  0x5d,  0x01,  0x0c,  0x06,  0x0d,  0xfe,  0x74,  0x12,  0xfe,  0x2e,  0x1c,  0x05,  0xfe,
13874   0x1a,  0x0c,  0x01,  0x76,  0x06,  0x07,  0x5d,  0x01,  0x76,  0x06,  0x0d,  0x41,  0xfe,  0x2c,  0x1c,  0xfe,
13875   0xaa,  0xf0,  0xfe,  0xce,  0x0a,  0xfe,  0xac,  0xf0,  0xfe,  0x66,  0x0a,  0xfe,  0x92,  0x10,  0xc4,  0xf6,
13876   0xfe,  0xad,  0xf0,  0xfe,  0x72,  0x0a,  0x05,  0xfe,  0x1a,  0x0c,  0xc5,  0xfe,  0xe7,  0x10,  0xfe,  0x2b,
13877   0xf0,  0xbf,  0xfe,  0x6b,  0x18,  0x23,  0xfe,  0x00,  0xfe,  0xfe,  0x1c,  0x12,  0xac,  0xfe,  0xd2,  0xf0,
13878   0xbf,  0xfe,  0x76,  0x18,  0x23,  0x1d,  0x1b,  0xbf,  0x03,  0xe3,  0x23,  0x07,  0x1b,  0xbf,  0xd4,  0x5b,
13879   0xd5,  0x5b,  0xd2,  0x5b,  0xd3,  0x5b,  0xc4,  0xc5,  0xfe,  0xa9,  0x10,  0x75,  0x5e,  0x32,  0x1f,  0x7f,
13880   0x01,  0x42,  0x19,  0xfe,  0x35,  0x00,  0xfe,  0x01,  0xf0,  0x70,  0x19,  0x98,  0x05,  0x70,  0xfe,  0x74,
13881   0x18,  0x23,  0xfe,  0x00,  0xf8,  0x1b,  0x5b,  0x7d,  0x12,  0x01,  0xfe,  0x78,  0x0f,  0x4d,  0x01,  0xfe,
13882   0x96,  0x1a,  0x21,  0x30,  0x77,  0x7d,  0x1d,  0x05,  0x5b,  0x01,  0x0c,  0x06,  0x0d,  0x2b,  0xfe,  0xe2,
13883   0x0b,  0x01,  0x0c,  0x06,  0x54,  0xfe,  0xa6,  0x12,  0x01,  0x0c,  0x06,  0x24,  0xfe,  0x88,  0x13,  0x21,
13884   0x6e,  0xc7,  0x01,  0xfe,  0x1e,  0x1f,  0x0f,  0xfe,  0x83,  0x80,  0x04,  0xfe,  0x83,  0x83,  0xfe,  0xc9,
13885   0x47,  0x0b,  0x0e,  0xfe,  0xc8,  0x44,  0xfe,  0x42,  0x13,  0x0f,  0xfe,  0x04,  0x91,  0x04,  0xfe,  0x84,
13886   0x93,  0xfe,  0xca,  0x57,  0x0b,  0xfe,  0x86,  0x91,  0x04,  0xfe,  0x86,  0x93,  0xfe,  0xcb,  0x57,  0x0b,
13887   0x0e,  0x7a,  0x30,  0xfe,  0x40,  0x59,  0xfe,  0xc1,  0x59,  0x8e,  0x40,  0x03,  0x6a,  0x3b,  0x6b,  0x10,
13888   0x97,  0x22,  0x98,  0xd9,  0x6a,  0xda,  0x6b,  0x01,  0xc2,  0xc8,  0x7a,  0x30,  0x20,  0x6e,  0xdb,  0x64,
13889   0xdc,  0x34,  0x91,  0x6c,  0x7e,  0x6d,  0xfe,  0x44,  0x55,  0xfe,  0xe5,  0x55,  0xfe,  0x04,  0xfa,  0x64,
13890   0xfe,  0x05,  0xfa,  0x34,  0x01,  0xfe,  0x6a,  0x16,  0xa3,  0x26,  0x10,  0x97,  0x10,  0x98,  0x91,  0x6c,
13891   0x7e,  0x6d,  0xfe,  0x14,  0x10,  0x01,  0x0c,  0x06,  0x24,  0x1b,  0x40,  0x91,  0x4b,  0x7e,  0x4c,  0x01,
13892   0x0c,  0x06,  0xfe,  0xf7,  0x00,  0x44,  0x03,  0x68,  0x3b,  0x69,  0xfe,  0x10,  0x58,  0xfe,  0x91,  0x58,
13893   0xfe,  0x14,  0x59,  0xfe,  0x95,  0x59,  0x05,  0x5b,  0x01,  0x0c,  0x06,  0x24,  0x1b,  0x40,  0x01,  0x0c,
13894   0x06,  0xfe,  0xf7,  0x00,  0x44,  0x78,  0x01,  0xfe,  0x8e,  0x1e,  0x4f,  0x0f,  0xfe,  0x10,  0x90,  0x04,
13895   0xfe,  0x90,  0x93,  0x3a,  0x0b,  0xfe,  0x92,  0x90,  0x04,  0xfe,  0x92,  0x93,  0x79,  0x0b,  0x0e,  0xfe,
13896   0xbd,  0x10,  0x01,  0x43,  0x09,  0xbb,  0x1b,  0xfe,  0x6e,  0x0a,  0x15,  0xbb,  0x01,  0x0c,  0x06,  0x0d,
13897   0xfe,  0x14,  0x13,  0x03,  0x4b,  0x3b,  0x4c,  0x8e,  0xfe,  0x6e,  0x0a,  0xfe,  0x0c,  0x58,  0xfe,  0x8d,
13898   0x58,  0x05,  0x5b,  0x26,  0x3e,  0x0f,  0xfe,  0x19,  0x80,  0x04,  0xfe,  0x99,  0x83,  0x33,  0x0b,  0x0e,
13899   0xfe,  0xe5,  0x10,  0x01,  0x0c,  0x06,  0x0d,  0xfe,  0x1a,  0x12,  0xfe,  0x6c,  0x19,  0xfe,  0x19,  0x41,
13900   0xfe,  0x6b,  0x18,  0xac,  0xfe,  0xd1,  0xf0,  0xef,  0x1f,  0x92,  0x01,  0x42,  0x19,  0xfe,  0x44,  0x00,
13901   0xfe,  0x90,  0x10,  0xfe,  0x6c,  0x19,  0xd9,  0x4b,  0xfe,  0xed,  0x19,  0xda,  0x4c,  0xfe,  0x0c,  0x51,
13902   0xfe,  0x8e,  0x51,  0xfe,  0x6b,  0x18,  0x23,  0xfe,  0x00,  0xff,  0x31,  0xfe,  0x76,  0x10,  0xac,  0xfe,
13903   0xd2,  0xf0,  0xfe,  0xba,  0x0c,  0xfe,  0x76,  0x18,  0x23,  0x1d,  0x5d,  0x03,  0xe3,  0x23,  0x07,  0xfe,
13904   0x08,  0x13,  0x19,  0xfe,  0x16,  0x00,  0x05,  0x70,  0xfe,  0xd1,  0xf0,  0xfe,  0xcc,  0x0c,  0x1f,  0x92,
13905   0x01,  0x42,  0x19,  0xfe,  0x17,  0x00,  0x5c,  0xfe,  0xce,  0xf0,  0xfe,  0xd2,  0x0c,  0xfe,  0x3e,  0x10,
13906   0xfe,  0xcd,  0xf0,  0xfe,  0xde,  0x0c,  0x19,  0xfe,  0x22,  0x00,  0x05,  0x70,  0xfe,  0xcb,  0xf0,  0xfe,
13907   0xea,  0x0c,  0x19,  0xfe,  0x24,  0x00,  0x05,  0x70,  0xfe,  0xd0,  0xf0,  0xfe,  0xf4,  0x0c,  0x19,  0x94,
13908   0xfe,  0x1c,  0x10,  0xfe,  0xcf,  0xf0,  0xfe,  0xfe,  0x0c,  0x19,  0x4a,  0xf3,  0xfe,  0xcc,  0xf0,  0xef,
13909   0x01,  0x76,  0x06,  0x24,  0x4d,  0x19,  0xfe,  0x12,  0x00,  0x37,  0x13,  0xfe,  0x4e,  0x11,  0x2f,  0xfe,
13910   0x16,  0x0d,  0xfe,  0x9e,  0xf0,  0xfe,  0x2a,  0x0d,  0xfe,  0x01,  0x48,  0x1b,  0x3c,  0x37,  0x88,  0xf5,
13911   0xd4,  0x29,  0xd5,  0x29,  0xd2,  0x29,  0xd3,  0x29,  0x37,  0xfe,  0x9c,  0x32,  0x2f,  0xfe,  0x3e,  0x0d,
13912   0x2a,  0x3c,  0xae,  0xfe,  0x62,  0x0d,  0xaf,  0xa0,  0xd4,  0x9f,  0xd5,  0x9f,  0xd2,  0x9f,  0xd3,  0x9f,
13913   0x05,  0x29,  0x01,  0x41,  0xfe,  0xd3,  0x10,  0x15,  0xfe,  0xe8,  0x00,  0xc4,  0xc5,  0x75,  0xd7,  0x99,
13914   0xd8,  0x9c,  0xfe,  0x89,  0xf0,  0x29,  0x27,  0x25,  0xbe,  0xd7,  0x99,  0xd8,  0x9c,  0x2f,  0xfe,  0x8c,
13915   0x0d,  0x16,  0x29,  0x27,  0x25,  0xbd,  0xfe,  0x01,  0x48,  0xa4,  0x19,  0xfe,  0x42,  0x00,  0x05,  0x70,
13916   0x90,  0x07,  0xfe,  0x81,  0x49,  0x1b,  0xfe,  0x64,  0x0e,  0x01,  0x0c,  0x06,  0x0d,  0xfe,  0x44,  0x13,
13917   0x19,  0x00,  0x2d,  0x0d,  0xfe,  0x54,  0x12,  0x2d,  0xfe,  0x28,  0x00,  0x2b,  0xfe,  0xda,  0x0e,  0x0a,
13918   0x57,  0x01,  0x18,  0x09,  0x00,  0x36,  0x46,  0xfe,  0x28,  0x00,  0xfe,  0xfa,  0x10,  0x01,  0xfe,  0xf4,
13919   0x1c,  0x01,  0xfe,  0x00,  0x1d,  0x0a,  0xba,  0x01,  0xfe,  0x58,  0x10,  0x40,  0x15,  0x56,  0x01,  0x85,
13920   0x05,  0x35,  0x19,  0xfe,  0x44,  0x00,  0x2d,  0x0d,  0xf7,  0x46,  0x0d,  0xfe,  0xcc,  0x10,  0x01,  0xa7,
13921   0x46,  0x0d,  0xfe,  0xc2,  0x10,  0x01,  0xa7,  0x0f,  0xfe,  0x19,  0x82,  0x04,  0xfe,  0x99,  0x83,  0xfe,
13922   0xcc,  0x47,  0x0b,  0x0e,  0xfe,  0x34,  0x46,  0xa5,  0x46,  0x0d,  0x19,  0xfe,  0x43,  0x00,  0xfe,  0xa2,
13923   0x10,  0x01,  0x0c,  0x61,  0x0d,  0x44,  0x01,  0xfe,  0xf4,  0x1c,  0x01,  0xfe,  0x00,  0x1d,  0x40,  0x15,
13924   0x56,  0x01,  0x85,  0x7d,  0x0d,  0x40,  0x51,  0x01,  0xfe,  0x9e,  0x1e,  0x05,  0xfe,  0x3a,  0x03,  0x01,
13925   0x0c,  0x06,  0x0d,  0x5d,  0x46,  0x0d,  0x19,  0x00,  0xfe,  0x62,  0x10,  0x01,  0x76,  0x06,  0x12,  0xfe,
13926   0x5c,  0x12,  0x01,  0x0c,  0x06,  0x12,  0xfe,  0x52,  0x13,  0xfe,  0x1c,  0x1c,  0xfe,  0x9d,  0xf0,  0xfe,
13927   0x8e,  0x0e,  0xfe,  0x1c,  0x1c,  0xfe,  0x9d,  0xf0,  0xfe,  0x94,  0x0e,  0x01,  0x0c,  0x61,  0x12,  0x44,
13928   0xfe,  0x9f,  0x10,  0x19,  0xfe,  0x15,  0x00,  0xfe,  0x04,  0xe6,  0x0d,  0x4f,  0xfe,  0x2e,  0x10,  0x19,
13929   0xfe,  0x13,  0x00,  0xfe,  0x10,  0x10,  0x19,  0xfe,  0x47,  0x00,  0xf1,  0x19,  0xfe,  0x41,  0x00,  0xa2,
13930   0x19,  0xfe,  0x24,  0x00,  0x86,  0xc4,  0xc5,  0x75,  0x03,  0x81,  0x1e,  0x2b,  0xea,  0x4f,  0xfe,  0x04,
13931   0xe6,  0x12,  0xfe,  0x9d,  0x41,  0xfe,  0x1c,  0x42,  0x40,  0x01,  0xf4,  0x05,  0x35,  0xfe,  0x12,  0x1c,
13932   0x1f,  0x0d,  0x47,  0xb5,  0xc3,  0x1f,  0xfe,  0x31,  0x00,  0x47,  0xb8,  0x01,  0xfe,  0xd4,  0x11,  0x05,
13933   0xe9,  0x51,  0xfe,  0x06,  0xec,  0xe0,  0xfe,  0x0e,  0x47,  0x46,  0x28,  0xfe,  0xce,  0x45,  0x31,  0x51,
13934   0xfe,  0x06,  0xea,  0xe0,  0xfe,  0x47,  0x4b,  0x45,  0xfe,  0x75,  0x57,  0x03,  0x67,  0xfe,  0x98,  0x56,
13935   0xfe,  0x38,  0x12,  0x0a,  0x5a,  0x01,  0x18,  0xfe,  0x44,  0x48,  0x60,  0x01,  0x0c,  0x06,  0x28,  0xfe,
13936   0x18,  0x13,  0x0a,  0x57,  0x01,  0x18,  0x3e,  0xfe,  0x41,  0x58,  0x0a,  0xba,  0xfe,  0xfa,  0x14,  0xfe,
13937   0x49,  0x54,  0xb0,  0xfe,  0x5e,  0x0f,  0x05,  0xfe,  0x3a,  0x03,  0x0a,  0x67,  0xfe,  0xe0,  0x14,  0xfe,
13938   0x0e,  0x47,  0x46,  0x28,  0xfe,  0xce,  0x45,  0x31,  0x51,  0xfe,  0xce,  0x47,  0xfe,  0xad,  0x13,  0x05,
13939   0x35,  0x21,  0x2c,  0x09,  0x1a,  0xfe,  0x98,  0x12,  0x26,  0x20,  0x96,  0x20,  0xe7,  0xfe,  0x08,  0x1c,
13940   0xfe,  0x7c,  0x19,  0xfe,  0xfd,  0x19,  0xfe,  0x0a,  0x1c,  0x03,  0xe5,  0xfe,  0x48,  0x55,  0xa5,  0x3b,
13941   0xfe,  0x62,  0x01,  0xfe,  0xc9,  0x55,  0x31,  0xfe,  0x74,  0x10,  0x01,  0xfe,  0xf0,  0x1a,  0x03,  0xfe,
13942   0x38,  0x01,  0x3b,  0xfe,  0x3a,  0x01,  0x8e,  0xfe,  0x1e,  0x10,  0xfe,  0x02,  0xec,  0xe7,  0x53,  0x00,
13943   0x36,  0xfe,  0x04,  0xec,  0x2c,  0x60,  0xfe,  0x05,  0xf6,  0xfe,  0x34,  0x01,  0x01,  0xfe,  0x62,  0x1b,
13944   0x01,  0xfe,  0xce,  0x1e,  0xb2,  0x11,  0xfe,  0x18,  0x13,  0xca,  0xfe,  0x02,  0xea,  0xe7,  0x53,  0x92,
13945   0xfe,  0xc3,  0x13,  0x1f,  0x12,  0x47,  0xb5,  0xc3,  0xfe,  0x2a,  0x10,  0x03,  0xfe,  0x38,  0x01,  0x23,
13946   0xfe,  0xf0,  0xff,  0x10,  0xe5,  0x03,  0xfe,  0x3a,  0x01,  0x10,  0xfe,  0x62,  0x01,  0x01,  0xfe,  0x1e,
13947   0x1e,  0x20,  0x2c,  0x15,  0x56,  0x01,  0xfe,  0x9e,  0x1e,  0x13,  0x07,  0x02,  0x26,  0x02,  0x21,  0x96,
13948   0xc7,  0x20,  0x96,  0x09,  0x92,  0xfe,  0x79,  0x13,  0x1f,  0x1d,  0x47,  0xb5,  0xc3,  0xfe,  0xe1,  0x10,
13949   0xcf,  0xfe,  0x03,  0xdc,  0xfe,  0x73,  0x57,  0xfe,  0x80,  0x5d,  0x02,  0xcf,  0xfe,  0x03,  0xdc,  0xfe,
13950   0x5b,  0x57,  0xfe,  0x80,  0x5d,  0x02,  0xfe,  0x03,  0x57,  0xcf,  0x26,  0xfe,  0x00,  0xcc,  0x02,  0xfe,
13951   0x03,  0x57,  0xcf,  0x89,  0x02,  0x01,  0x0c,  0x06,  0x4a,  0xfe,  0x4e,  0x13,  0x0f,  0xfe,  0x1c,  0x80,
13952   0x04,  0xfe,  0x9c,  0x83,  0x33,  0x0b,  0x0e,  0x09,  0x07,  0xfe,  0x3a,  0x13,  0x0f,  0xfe,  0x1e,  0x80,
13953   0x04,  0xfe,  0x9e,  0x83,  0x33,  0x0b,  0x0e,  0xfe,  0x2a,  0x13,  0x0f,  0xfe,  0x1d,  0x80,  0x04,  0xfe,
13954   0x9d,  0x83,  0xfe,  0xf9,  0x13,  0x0e,  0xfe,  0x1c,  0x13,  0x01,  0xfe,  0xee,  0x1e,  0xac,  0xfe,  0x14,
13955   0x13,  0x01,  0xfe,  0xfe,  0x1e,  0xfe,  0x81,  0x58,  0xfa,  0x01,  0xfe,  0x0e,  0x1f,  0xfe,  0x30,  0xf4,
13956   0x0d,  0xfe,  0x3c,  0x50,  0xa2,  0x01,  0xfe,  0x92,  0x1b,  0x01,  0x43,  0x09,  0x56,  0xfb,  0x01,  0xfe,
13957   0xc8,  0x1a,  0x01,  0x0c,  0x06,  0x28,  0xa4,  0x01,  0xfe,  0xf4,  0x1c,  0x01,  0xfe,  0x00,  0x1d,  0x15,
13958   0xfe,  0xe9,  0x00,  0x01,  0x0c,  0x06,  0x4a,  0xfe,  0x4e,  0x13,  0x01,  0xfe,  0x22,  0x1b,  0xfe,  0x1e,
13959   0x1c,  0x0f,  0xfe,  0x14,  0x90,  0x04,  0xfe,  0x94,  0x93,  0x3a,  0x0b,  0xfe,  0x96,  0x90,  0x04,  0xfe,
13960   0x96,  0x93,  0x79,  0x0b,  0x0e,  0x10,  0xfe,  0x64,  0x01,  0x22,  0xfe,  0x66,  0x01,  0x01,  0x0c,  0x06,
13961   0x65,  0xf9,  0x0f,  0xfe,  0x03,  0x80,  0x04,  0xfe,  0x83,  0x83,  0x33,  0x0b,  0x0e,  0x77,  0xfe,  0x01,
13962   0xec,  0x2c,  0xfe,  0x80,  0x40,  0x20,  0x2c,  0x7a,  0x30,  0x15,  0xdf,  0x40,  0x21,  0x2c,  0xfe,  0x00,
13963   0x40,  0x8d,  0x2c,  0x02,  0xfe,  0x08,  0x1c,  0x03,  0xfe,  0xac,  0x00,  0xfe,  0x06,  0x58,  0x03,  0xfe,
13964   0xae,  0x00,  0xfe,  0x07,  0x58,  0x03,  0xfe,  0xb0,  0x00,  0xfe,  0x08,  0x58,  0x03,  0xfe,  0xb2,  0x00,
13965   0xfe,  0x09,  0x58,  0xfe,  0x0a,  0x1c,  0x2e,  0x49,  0x20,  0xe0,  0x26,  0x10,  0x66,  0x10,  0x55,  0x10,
13966   0x6f,  0x13,  0x57,  0x52,  0x4f,  0x1c,  0x28,  0xfe,  0x90,  0x4d,  0xfe,  0x91,  0x54,  0x2b,  0xfe,  0x88,
13967   0x11,  0x46,  0x1a,  0x13,  0x5a,  0x52,  0x1c,  0x4a,  0xfe,  0x90,  0x4d,  0xfe,  0x91,  0x54,  0x2b,  0xfe,
13968   0x9e,  0x11,  0x2e,  0x1a,  0x20,  0x2c,  0x90,  0x34,  0x60,  0x21,  0x2c,  0xfe,  0x00,  0x40,  0x8d,  0x2c,
13969   0x15,  0xdf,  0xfe,  0x14,  0x56,  0xfe,  0xd6,  0xf0,  0xfe,  0xb2,  0x11,  0xfe,  0x12,  0x1c,  0x75,  0xfe,
13970   0x14,  0x1c,  0xfe,  0x10,  0x1c,  0xfe,  0x18,  0x1c,  0x02,  0x51,  0xfe,  0x0c,  0x14,  0xfe,  0x0e,  0x47,
13971   0xfe,  0x07,  0xe6,  0x28,  0xfe,  0xce,  0x47,  0xfe,  0xf5,  0x13,  0x02,  0x01,  0xa7,  0x90,  0x34,  0x60,
13972   0xfe,  0x06,  0x80,  0xfe,  0x48,  0x47,  0xfe,  0x42,  0x13,  0xfe,  0x02,  0x80,  0x09,  0x56,  0xfe,  0x34,
13973   0x13,  0x0a,  0x5a,  0x01,  0x18,  0xcb,  0xfe,  0x36,  0x12,  0xfe,  0x41,  0x48,  0xfe,  0x45,  0x48,  0x01,
13974   0xfe,  0xb2,  0x16,  0xfe,  0x00,  0xcc,  0xcb,  0xfe,  0xf3,  0x13,  0x3f,  0x89,  0x09,  0x1a,  0xa5,  0x0a,
13975   0x9d,  0x01,  0x18,  0xfe,  0x80,  0x5c,  0x01,  0x85,  0xf2,  0x09,  0x9b,  0xa4,  0xfe,  0x14,  0x56,  0xfe,
13976   0xd6,  0xf0,  0xfe,  0xec,  0x11,  0x02,  0xfe,  0x44,  0x58,  0x77,  0xfe,  0x01,  0xec,  0xb8,  0xfe,  0x9e,
13977   0x40,  0xfe,  0x9d,  0xe7,  0x00,  0xfe,  0x9c,  0xe7,  0x12,  0x8d,  0x30,  0x01,  0xf4,  0xfe,  0xdd,  0x10,
13978   0x37,  0xd7,  0x99,  0xd8,  0x9c,  0x27,  0x25,  0xee,  0x09,  0x12,  0xfe,  0x48,  0x12,  0x09,  0x0d,  0xfe,
13979   0x56,  0x12,  0x09,  0x1d,  0xfe,  0x30,  0x12,  0x09,  0xdd,  0x1b,  0xfe,  0xc4,  0x13,  0x09,  0xfe,  0x23,
13980   0x00,  0x1b,  0xfe,  0xd0,  0x13,  0x09,  0x07,  0x1b,  0xfe,  0x34,  0x14,  0x09,  0x24,  0xfe,  0x12,  0x12,
13981   0x09,  0x00,  0x1b,  0x29,  0x1f,  0xdd,  0x01,  0x42,  0xa1,  0x32,  0x01,  0x08,  0xae,  0x41,  0x02,  0x32,
13982   0xfe,  0x62,  0x08,  0x0a,  0xe1,  0x01,  0xfe,  0x58,  0x10,  0x15,  0x9b,  0x05,  0x35,  0x32,  0x01,  0x43,
13983   0x09,  0xbb,  0xfe,  0xd7,  0x13,  0x91,  0x4b,  0x7e,  0x4c,  0x8e,  0xfe,  0x80,  0x13,  0x01,  0x0c,  0x06,
13984   0x54,  0xfe,  0x72,  0x12,  0xdb,  0x64,  0xdc,  0x34,  0xfe,  0x44,  0x55,  0xfe,  0xe5,  0x55,  0xb0,  0xfe,
13985   0x4a,  0x13,  0x21,  0x6e,  0xfe,  0x26,  0x13,  0x03,  0x97,  0x3b,  0x98,  0x8e,  0xfe,  0xb6,  0x0e,  0x10,
13986   0x6a,  0x22,  0x6b,  0x26,  0x10,  0x97,  0x10,  0x98,  0x01,  0xc2,  0x2e,  0x49,  0x88,  0x20,  0x6e,  0x01,
13987   0xfe,  0x6a,  0x16,  0xdb,  0x64,  0xdc,  0x34,  0xfe,  0x04,  0x55,  0xfe,  0xa5,  0x55,  0xfe,  0x04,  0xfa,
13988   0x64,  0xfe,  0x05,  0xfa,  0x34,  0xfe,  0x8f,  0x10,  0x03,  0x6c,  0x3b,  0x6d,  0xfe,  0x40,  0x56,  0xfe,
13989   0xe1,  0x56,  0x10,  0x6c,  0x22,  0x6d,  0x71,  0xdb,  0x64,  0xdc,  0x34,  0xfe,  0x44,  0x55,  0xfe,  0xe5,
13990   0x55,  0x03,  0x68,  0x3b,  0x69,  0xfe,  0x00,  0x56,  0xfe,  0xa1,  0x56,  0x10,  0x68,  0x22,  0x69,  0x01,
13991   0x0c,  0x06,  0x54,  0xf9,  0x21,  0x6e,  0xfe,  0x1f,  0x40,  0x03,  0x6a,  0x3b,  0x6b,  0xfe,  0x2c,  0x50,
13992   0xfe,  0xae,  0x50,  0x03,  0x6c,  0x3b,  0x6d,  0xfe,  0x44,  0x50,  0xfe,  0xc6,  0x50,  0x03,  0x68,  0x3b,
13993   0x69,  0xfe,  0x08,  0x50,  0xfe,  0x8a,  0x50,  0x03,  0x4b,  0x3b,  0x4c,  0xfe,  0x40,  0x50,  0xfe,  0xc2,
13994   0x50,  0x05,  0x73,  0x2e,  0x07,  0x20,  0x9e,  0x05,  0x72,  0x32,  0x01,  0x08,  0x16,  0x3d,  0x27,  0x25,
13995   0xee,  0x09,  0x07,  0x2b,  0x3d,  0x01,  0x43,  0x09,  0xbb,  0x2b,  0x72,  0x01,  0xa6,  0x23,  0x3f,  0x1b,
13996   0x3d,  0x01,  0x0c,  0x06,  0x0d,  0xfe,  0x1e,  0x13,  0x91,  0x4b,  0x7e,  0x4c,  0xfe,  0x0a,  0x55,  0x31,
13997   0xfe,  0x8b,  0x55,  0xd9,  0x4b,  0xda,  0x4c,  0xfe,  0x0c,  0x51,  0xfe,  0x8e,  0x51,  0x05,  0x72,  0x01,
13998   0xfe,  0x8e,  0x1e,  0xca,  0xfe,  0x19,  0x41,  0x05,  0x72,  0x32,  0x01,  0x08,  0x2a,  0x3c,  0x16,  0xc0,
13999   0x27,  0x25,  0xbe,  0x2d,  0x1d,  0xc0,  0x2d,  0x0d,  0x83,  0x2d,  0x7f,  0x1b,  0xfe,  0x66,  0x15,  0x05,
14000   0x3d,  0x01,  0x08,  0x2a,  0x3c,  0x16,  0xc0,  0x27,  0x25,  0xbd,  0x09,  0x1d,  0x2b,  0x3d,  0x01,  0x08,
14001   0x16,  0xc0,  0x27,  0x25,  0xfe,  0xe8,  0x09,  0xfe,  0xc2,  0x49,  0x50,  0x03,  0xb6,  0x1e,  0x83,  0x01,
14002   0x38,  0x06,  0x24,  0x31,  0xa1,  0xfe,  0xbb,  0x45,  0x2d,  0x00,  0xa4,  0x46,  0x07,  0x90,  0x3f,  0x01,
14003   0xfe,  0xf8,  0x15,  0x01,  0xa6,  0x86,  0xfe,  0x4b,  0x45,  0xfe,  0x20,  0x13,  0x01,  0x43,  0x09,  0x82,
14004   0xfe,  0x16,  0x13,  0x03,  0x9a,  0x1e,  0x5d,  0x03,  0x55,  0x1e,  0x31,  0x5e,  0x05,  0x72,  0xfe,  0xc0,
14005   0x5d,  0x01,  0xa7,  0xfe,  0x03,  0x17,  0x03,  0x66,  0x8a,  0x10,  0x66,  0x5e,  0x32,  0x01,  0x08,  0x17,
14006   0x73,  0x01,  0xfe,  0x56,  0x19,  0x05,  0x73,  0x01,  0x08,  0x2a,  0x3c,  0x16,  0x3d,  0x27,  0x25,  0xbd,
14007   0x09,  0x07,  0x2b,  0x3d,  0x01,  0xfe,  0xbe,  0x16,  0xfe,  0x42,  0x58,  0xfe,  0xe8,  0x14,  0x01,  0xa6,
14008   0x86,  0xfe,  0x4a,  0xf4,  0x0d,  0x1b,  0x3d,  0xfe,  0x4a,  0xf4,  0x07,  0xfe,  0x0e,  0x12,  0x01,  0x43,
14009   0x09,  0x82,  0x4e,  0x05,  0x72,  0x03,  0x55,  0x8a,  0x10,  0x55,  0x5e,  0x32,  0x01,  0x08,  0x17,  0x73,
14010   0x01,  0xfe,  0x84,  0x19,  0x05,  0x73,  0x01,  0x08,  0x2a,  0x3c,  0x16,  0x3d,  0x27,  0x25,  0xbd,  0x09,
14011   0x12,  0x2b,  0x3d,  0x01,  0xfe,  0xe8,  0x17,  0x8b,  0xfe,  0xaa,  0x14,  0xfe,  0xb6,  0x14,  0x86,  0xa8,
14012   0xb2,  0x0d,  0x1b,  0x3d,  0xb2,  0x07,  0xfe,  0x0e,  0x12,  0x01,  0x43,  0x09,  0x82,  0x4e,  0x05,  0x72,
14013   0x03,  0x6f,  0x8a,  0x10,  0x6f,  0x5e,  0x32,  0x01,  0x08,  0x17,  0x73,  0x01,  0xfe,  0xc0,  0x19,  0x05,
14014   0x73,  0x13,  0x07,  0x2f,  0xfe,  0xcc,  0x15,  0x17,  0xfe,  0xe2,  0x15,  0x5f,  0xcc,  0x01,  0x08,  0x26,
14015   0x5f,  0x02,  0x8f,  0xfe,  0xde,  0x15,  0x2a,  0xfe,  0xde,  0x15,  0x16,  0xfe,  0xcc,  0x15,  0x5e,  0x32,
14016   0x01,  0x08,  0xfe,  0xd5,  0x10,  0x13,  0x58,  0xff,  0x02,  0x00,  0x57,  0x52,  0xad,  0x23,  0xfe,  0xff,
14017   0x7f,  0xfe,  0x30,  0x56,  0xfe,  0x00,  0x5c,  0x02,  0x13,  0x58,  0xff,  0x02,  0x00,  0x57,  0x52,  0xad,
14018   0x23,  0x3f,  0xfe,  0x30,  0x56,  0xfe,  0x00,  0x5c,  0x02,  0x13,  0x58,  0xff,  0x02,  0x00,  0x57,  0x52,
14019   0xad,  0x02,  0x13,  0x58,  0xff,  0x02,  0x00,  0x57,  0x52,  0xfe,  0x00,  0x5e,  0x02,  0x13,  0x58,  0xff,
14020   0x02,  0x00,  0x57,  0x52,  0xad,  0xfe,  0x0b,  0x58,  0x02,  0x0a,  0x66,  0x01,  0x5c,  0x0a,  0x55,  0x01,
14021   0x5c,  0x0a,  0x6f,  0x01,  0x5c,  0x02,  0x01,  0xfe,  0x1e,  0x1f,  0x23,  0x1a,  0xff,  0x03,  0x00,  0x54,
14022   0xfe,  0x00,  0xf4,  0x24,  0x52,  0x0f,  0xfe,  0x00,  0x7c,  0x04,  0xfe,  0x07,  0x7c,  0x3a,  0x0b,  0x0e,
14023   0xfe,  0x00,  0x71,  0xfe,  0xf9,  0x18,  0xfe,  0x7a,  0x19,  0xfe,  0xfb,  0x19,  0xfe,  0x1a,  0xf7,  0x00,
14024   0xfe,  0x1b,  0xf7,  0x00,  0x7a,  0x30,  0x10,  0x68,  0x22,  0x69,  0xd9,  0x6c,  0xda,  0x6d,  0x02,  0xfe,
14025   0x62,  0x08,  0xfe,  0x82,  0x4a,  0xfe,  0xe1,  0x1a,  0xfe,  0x83,  0x5a,  0x77,  0x02,  0x01,  0xc6,  0xfe,
14026   0x42,  0x48,  0x4f,  0x50,  0x45,  0x01,  0x08,  0x16,  0xfe,  0xe0,  0x17,  0x27,  0x25,  0xbe,  0x01,  0x08,
14027   0x16,  0xfe,  0xe0,  0x17,  0x27,  0x25,  0xfe,  0xe8,  0x0a,  0xfe,  0xc1,  0x59,  0x03,  0x9a,  0x1e,  0xfe,
14028   0xda,  0x12,  0x01,  0x38,  0x06,  0x12,  0xfe,  0xd0,  0x13,  0x26,  0x53,  0x12,  0x48,  0xfe,  0x08,  0x17,
14029   0xd1,  0x12,  0x53,  0x12,  0xfe,  0x1e,  0x13,  0x2d,  0xb4,  0x7b,  0xfe,  0x26,  0x17,  0x4d,  0x13,  0x07,
14030   0x1c,  0xb4,  0x90,  0x04,  0xfe,  0x78,  0x10,  0xff,  0x02,  0x83,  0x55,  0xf1,  0xff,  0x02,  0x83,  0x55,
14031   0x53,  0x1d,  0xfe,  0x12,  0x13,  0xd6,  0xfe,  0x30,  0x00,  0xb0,  0xfe,  0x80,  0x17,  0x1c,  0x63,  0x13,
14032   0x07,  0xfe,  0x56,  0x10,  0x53,  0x0d,  0xfe,  0x16,  0x13,  0xd6,  0xfe,  0x64,  0x00,  0xb0,  0xfe,  0x80,
14033   0x17,  0x0a,  0xfe,  0x64,  0x00,  0x1c,  0x94,  0x13,  0x07,  0xfe,  0x28,  0x10,  0x53,  0x07,  0xfe,  0x60,
14034   0x13,  0xd6,  0xfe,  0xc8,  0x00,  0xb0,  0xfe,  0x80,  0x17,  0x0a,  0xfe,  0xc8,  0x00,  0x1c,  0x95,  0x13,
14035   0x07,  0x71,  0xd6,  0xfe,  0x90,  0x01,  0x48,  0xfe,  0x8c,  0x17,  0x45,  0xf3,  0xfe,  0x43,  0xf4,  0x96,
14036   0xfe,  0x56,  0xf0,  0xfe,  0x9e,  0x17,  0xfe,  0x04,  0xf4,  0x58,  0xfe,  0x43,  0xf4,  0x94,  0xf6,  0x8b,
14037   0x01,  0xfe,  0x24,  0x16,  0x23,  0x3f,  0xfc,  0xa8,  0x8c,  0x49,  0x48,  0xfe,  0xda,  0x17,  0x62,  0x49,
14038   0xfe,  0x1c,  0x10,  0xa8,  0x8c,  0x80,  0x48,  0xfe,  0xda,  0x17,  0x62,  0x80,  0x71,  0x50,  0x26,  0xfe,
14039   0x4d,  0xf4,  0x00,  0xf7,  0x45,  0x13,  0x07,  0xfe,  0xb4,  0x56,  0xfe,  0xc3,  0x58,  0x02,  0x50,  0x13,
14040   0x0d,  0x02,  0x50,  0x3e,  0x78,  0x4f,  0x45,  0x01,  0x08,  0x16,  0xa9,  0x27,  0x25,  0xbe,  0xfe,  0x03,
14041   0xea,  0xfe,  0x7e,  0x01,  0x01,  0x08,  0x16,  0xa9,  0x27,  0x25,  0xfe,  0xe9,  0x0a,  0x01,  0x08,  0x16,
14042   0xa9,  0x27,  0x25,  0xfe,  0xe9,  0x0a,  0xfe,  0x05,  0xea,  0xfe,  0x7f,  0x01,  0x01,  0x08,  0x16,  0xa9,
14043   0x27,  0x25,  0xfe,  0x69,  0x09,  0xfe,  0x02,  0xea,  0xfe,  0x80,  0x01,  0x01,  0x08,  0x16,  0xa9,  0x27,
14044   0x25,  0xfe,  0xe8,  0x08,  0x47,  0xfe,  0x81,  0x01,  0x03,  0xb6,  0x1e,  0x83,  0x01,  0x38,  0x06,  0x24,
14045   0x31,  0xa2,  0x78,  0xf2,  0x53,  0x07,  0x36,  0xfe,  0x34,  0xf4,  0x3f,  0xa1,  0x78,  0x03,  0x9a,  0x1e,
14046   0x83,  0x01,  0x38,  0x06,  0x12,  0x31,  0xf0,  0x4f,  0x45,  0xfe,  0x90,  0x10,  0xfe,  0x40,  0x5a,  0x23,
14047   0x3f,  0xfb,  0x8c,  0x49,  0x48,  0xfe,  0xaa,  0x18,  0x62,  0x49,  0x71,  0x8c,  0x80,  0x48,  0xfe,  0xaa,
14048   0x18,  0x62,  0x80,  0xfe,  0xb4,  0x56,  0xfe,  0x40,  0x5d,  0x01,  0xc6,  0x01,  0xfe,  0xac,  0x1d,  0xfe,
14049   0x02,  0x17,  0xfe,  0xc8,  0x45,  0xfe,  0x5a,  0xf0,  0xfe,  0xc0,  0x18,  0xfe,  0x43,  0x48,  0x2d,  0x93,
14050   0x36,  0xfe,  0x34,  0xf4,  0xfe,  0x00,  0x11,  0xfe,  0x40,  0x10,  0x2d,  0xb4,  0x36,  0xfe,  0x34,  0xf4,
14051   0x04,  0xfe,  0x34,  0x10,  0x2d,  0xfe,  0x0b,  0x00,  0x36,  0x46,  0x63,  0xfe,  0x28,  0x10,  0xfe,  0xc0,
14052   0x49,  0xff,  0x02,  0x00,  0x54,  0xb2,  0xfe,  0x90,  0x01,  0x48,  0xfe,  0xfa,  0x18,  0x45,  0xfe,  0x1c,
14053   0xf4,  0x3f,  0xf3,  0xfe,  0x40,  0xf4,  0x96,  0xfe,  0x56,  0xf0,  0xfe,  0x0c,  0x19,  0xfe,  0x04,  0xf4,
14054   0x58,  0xfe,  0x40,  0xf4,  0x94,  0xf6,  0x3e,  0x2d,  0x93,  0x4e,  0xd0,  0x0d,  0x21,  0xfe,  0x7f,  0x01,
14055   0xfe,  0xc8,  0x46,  0xfe,  0x24,  0x13,  0x8c,  0x00,  0x5d,  0x26,  0x21,  0xfe,  0x7e,  0x01,  0xfe,  0xc8,
14056   0x45,  0xfe,  0x14,  0x13,  0x21,  0xfe,  0x80,  0x01,  0xfe,  0x48,  0x45,  0xfa,  0x21,  0xfe,  0x81,  0x01,
14057   0xfe,  0xc8,  0x44,  0x4e,  0x26,  0x02,  0x13,  0x07,  0x02,  0x78,  0x45,  0x50,  0x13,  0x0d,  0x02,  0x14,
14058   0x07,  0x01,  0x08,  0x17,  0xfe,  0x82,  0x19,  0x14,  0x0d,  0x01,  0x08,  0x17,  0xfe,  0x82,  0x19,  0x14,
14059   0x1d,  0x01,  0x08,  0x17,  0xfe,  0x82,  0x19,  0x5f,  0xfe,  0x89,  0x49,  0x01,  0x08,  0x02,  0x14,  0x07,
14060   0x01,  0x08,  0x17,  0xc1,  0x14,  0x1d,  0x01,  0x08,  0x17,  0xc1,  0x14,  0x07,  0x01,  0x08,  0x17,  0xc1,
14061   0xfe,  0x89,  0x49,  0x01,  0x08,  0x17,  0xc1,  0x5f,  0xfe,  0x89,  0x4a,  0x01,  0x08,  0x02,  0x50,  0x02,
14062   0x14,  0x07,  0x01,  0x08,  0x17,  0x74,  0x14,  0x7f,  0x01,  0x08,  0x17,  0x74,  0x14,  0x12,  0x01,  0x08,
14063   0x17,  0x74,  0xfe,  0x89,  0x49,  0x01,  0x08,  0x17,  0x74,  0x14,  0x00,  0x01,  0x08,  0x17,  0x74,  0xfe,
14064   0x89,  0x4a,  0x01,  0x08,  0x17,  0x74,  0xfe,  0x09,  0x49,  0x01,  0x08,  0x17,  0x74,  0x5f,  0xcc,  0x01,
14065   0x08,  0x02,  0x21,  0xe4,  0x09,  0x07,  0xfe,  0x4c,  0x13,  0xc8,  0x20,  0xe4,  0xfe,  0x49,  0xf4,  0x00,
14066   0x4d,  0x5f,  0xa1,  0x5e,  0xfe,  0x01,  0xec,  0xfe,  0x27,  0x01,  0xcc,  0xff,  0x02,  0x00,  0x10,  0x2f,
14067   0xfe,  0x3e,  0x1a,  0x01,  0x43,  0x09,  0xfe,  0xe3,  0x00,  0xfe,  0x22,  0x13,  0x16,  0xfe,  0x64,  0x1a,
14068   0x26,  0x20,  0x9e,  0x01,  0x41,  0x21,  0x9e,  0x09,  0x07,  0x5d,  0x01,  0x0c,  0x61,  0x07,  0x44,  0x02,
14069   0x0a,  0x5a,  0x01,  0x18,  0xfe,  0x00,  0x40,  0xaa,  0x09,  0x1a,  0xfe,  0x12,  0x13,  0x0a,  0x9d,  0x01,
14070   0x18,  0xaa,  0x0a,  0x67,  0x01,  0xa3,  0x02,  0x0a,  0x9d,  0x01,  0x18,  0xaa,  0xfe,  0x80,  0xe7,  0x1a,
14071   0x09,  0x1a,  0x5d,  0xfe,  0x45,  0x58,  0x01,  0xfe,  0xb2,  0x16,  0xaa,  0x02,  0x0a,  0x5a,  0x01,  0x18,
14072   0xaa,  0x0a,  0x67,  0x01,  0xa3,  0x02,  0x0a,  0x5a,  0x01,  0x18,  0x01,  0xfe,  0x7e,  0x1e,  0xfe,  0x80,
14073   0x4c,  0xfe,  0x49,  0xe4,  0x1a,  0xfe,  0x12,  0x13,  0x0a,  0x9d,  0x01,  0x18,  0xfe,  0x80,  0x4c,  0x0a,
14074   0x67,  0x01,  0x5c,  0x02,  0x1c,  0x1a,  0x87,  0x7c,  0xe5,  0xfe,  0x18,  0xdf,  0xfe,  0x19,  0xde,  0xfe,
14075   0x24,  0x1c,  0xfe,  0x1d,  0xf7,  0x28,  0xb1,  0xfe,  0x04,  0x1b,  0x01,  0xfe,  0x2a,  0x1c,  0xfa,  0xb3,
14076   0x28,  0x7c,  0xfe,  0x2c,  0x01,  0xfe,  0x2f,  0x19,  0x02,  0xc9,  0x2b,  0xfe,  0xf4,  0x1a,  0xfe,  0xfa,
14077   0x10,  0x1c,  0x1a,  0x87,  0x03,  0xfe,  0x64,  0x01,  0xfe,  0x00,  0xf4,  0x24,  0xfe,  0x18,  0x58,  0x03,
14078   0xfe,  0x66,  0x01,  0xfe,  0x19,  0x58,  0xb3,  0x24,  0x01,  0xfe,  0x0e,  0x1f,  0xfe,  0x30,  0xf4,  0x07,
14079   0xfe,  0x3c,  0x50,  0x7c,  0xfe,  0x38,  0x00,  0xfe,  0x0f,  0x79,  0xfe,  0x1c,  0xf7,  0x24,  0xb1,  0xfe,
14080   0x50,  0x1b,  0xfe,  0xd4,  0x14,  0x31,  0x02,  0xc9,  0x2b,  0xfe,  0x26,  0x1b,  0xfe,  0xba,  0x10,  0x1c,
14081   0x1a,  0x87,  0xfe,  0x83,  0x5a,  0xfe,  0x18,  0xdf,  0xfe,  0x19,  0xde,  0xfe,  0x1d,  0xf7,  0x54,  0xb1,
14082   0xfe,  0x72,  0x1b,  0xfe,  0xb2,  0x14,  0xfc,  0xb3,  0x54,  0x7c,  0x12,  0xfe,  0xaf,  0x19,  0xfe,  0x98,
14083   0xe7,  0x00,  0x02,  0xc9,  0x2b,  0xfe,  0x66,  0x1b,  0xfe,  0x8a,  0x10,  0x1c,  0x1a,  0x87,  0x8b,  0x0f,
14084   0xfe,  0x30,  0x90,  0x04,  0xfe,  0xb0,  0x93,  0x3a,  0x0b,  0xfe,  0x18,  0x58,  0xfe,  0x32,  0x90,  0x04,
14085   0xfe,  0xb2,  0x93,  0x3a,  0x0b,  0xfe,  0x19,  0x58,  0x0e,  0xa8,  0xb3,  0x4a,  0x7c,  0x12,  0xfe,  0x0f,
14086   0x79,  0xfe,  0x1c,  0xf7,  0x4a,  0xb1,  0xfe,  0xc6,  0x1b,  0xfe,  0x5e,  0x14,  0x31,  0x02,  0xc9,  0x2b,
14087   0xfe,  0x96,  0x1b,  0x5c,  0xfe,  0x02,  0xf6,  0x1a,  0x87,  0xfe,  0x18,  0xfe,  0x6a,  0xfe,  0x19,  0xfe,
14088   0x6b,  0x01,  0xfe,  0x1e,  0x1f,  0xfe,  0x1d,  0xf7,  0x65,  0xb1,  0xfe,  0xee,  0x1b,  0xfe,  0x36,  0x14,
14089   0xfe,  0x1c,  0x13,  0xb3,  0x65,  0x3e,  0xfe,  0x83,  0x58,  0xfe,  0xaf,  0x19,  0xfe,  0x80,  0xe7,  0x1a,
14090   0xfe,  0x81,  0xe7,  0x1a,  0x15,  0xfe,  0xdd,  0x00,  0x7a,  0x30,  0x02,  0x7a,  0x30,  0xfe,  0x12,  0x45,
14091   0x2b,  0xfe,  0xdc,  0x1b,  0x1f,  0x07,  0x47,  0xb5,  0xc3,  0x05,  0x35,  0xfe,  0x39,  0xf0,  0x75,  0x26,
14092   0x02,  0xfe,  0x7e,  0x18,  0x23,  0x1d,  0x36,  0x13,  0x11,  0x02,  0x87,  0x03,  0xe3,  0x23,  0x07,  0xfe,
14093   0xef,  0x12,  0xfe,  0xe1,  0x10,  0x90,  0x34,  0x60,  0xfe,  0x02,  0x80,  0x09,  0x56,  0xfe,  0x3c,  0x13,
14094   0xfe,  0x82,  0x14,  0xfe,  0x42,  0x13,  0x51,  0xfe,  0x06,  0x83,  0x0a,  0x5a,  0x01,  0x18,  0xcb,  0xfe,
14095   0x3e,  0x12,  0xfe,  0x41,  0x48,  0xfe,  0x45,  0x48,  0x01,  0xfe,  0xb2,  0x16,  0xfe,  0x00,  0xcc,  0xcb,
14096   0xfe,  0xf3,  0x13,  0x3f,  0x89,  0x09,  0x1a,  0xa5,  0x0a,  0x9d,  0x01,  0x18,  0xfe,  0x80,  0x4c,  0x01,
14097   0x85,  0xfe,  0x16,  0x10,  0x09,  0x9b,  0x4e,  0xfe,  0x40,  0x14,  0xfe,  0x24,  0x12,  0xfe,  0x14,  0x56,
14098   0xfe,  0xd6,  0xf0,  0xfe,  0x52,  0x1c,  0x1c,  0x0d,  0x02,  0xfe,  0x9c,  0xe7,  0x0d,  0x19,  0xfe,  0x15,
14099   0x00,  0x40,  0x8d,  0x30,  0x01,  0xf4,  0x1c,  0x07,  0x02,  0x51,  0xfe,  0x06,  0x83,  0xfe,  0x18,  0x80,
14100   0x61,  0x28,  0x44,  0x15,  0x56,  0x01,  0x85,  0x1c,  0x07,  0x02,  0xfe,  0x38,  0x90,  0xfe,  0xba,  0x90,
14101   0x91,  0xde,  0x7e,  0xdf,  0xfe,  0x48,  0x55,  0x31,  0xfe,  0xc9,  0x55,  0x02,  0x21,  0xb9,  0x88,  0x20,
14102   0xb9,  0x02,  0x0a,  0xba,  0x01,  0x18,  0xfe,  0x41,  0x48,  0x0a,  0x57,  0x01,  0x18,  0xfe,  0x49,  0x44,
14103   0x1b,  0xfe,  0x1e,  0x1d,  0x88,  0x89,  0x02,  0x0a,  0x5a,  0x01,  0x18,  0x09,  0x1a,  0xa4,  0x0a,  0x67,
14104   0x01,  0xa3,  0x0a,  0x57,  0x01,  0x18,  0x88,  0x89,  0x02,  0xfe,  0x4e,  0xe4,  0x1d,  0x7b,  0xfe,  0x52,
14105   0x1d,  0x03,  0xfe,  0x90,  0x00,  0xfe,  0x3a,  0x45,  0xfe,  0x2c,  0x10,  0xfe,  0x4e,  0xe4,  0xdd,  0x7b,
14106   0xfe,  0x64,  0x1d,  0x03,  0xfe,  0x92,  0x00,  0xd1,  0x12,  0xfe,  0x1a,  0x10,  0xfe,  0x4e,  0xe4,  0xfe,
14107   0x0b,  0x00,  0x7b,  0xfe,  0x76,  0x1d,  0x03,  0xfe,  0x94,  0x00,  0xd1,  0x24,  0xfe,  0x08,  0x10,  0x03,
14108   0xfe,  0x96,  0x00,  0xd1,  0x63,  0xfe,  0x4e,  0x45,  0x83,  0xca,  0xff,  0x04,  0x68,  0x54,  0xfe,  0xf1,
14109   0x10,  0x23,  0x49,  0xfe,  0x08,  0x1c,  0xfe,  0x67,  0x19,  0xfe,  0x0a,  0x1c,  0xfe,  0x1a,  0xf4,  0xfe,
14110   0x00,  0x04,  0x83,  0xb2,  0x1d,  0x48,  0xfe,  0xaa,  0x1d,  0x13,  0x1d,  0x02,  0x09,  0x92,  0xfe,  0x5a,
14111   0xf0,  0xfe,  0xba,  0x1d,  0x2e,  0x93,  0xfe,  0x34,  0x10,  0x09,  0x12,  0xfe,  0x5a,  0xf0,  0xfe,  0xc8,
14112   0x1d,  0x2e,  0xb4,  0xfe,  0x26,  0x10,  0x09,  0x1d,  0x36,  0x2e,  0x63,  0xfe,  0x1a,  0x10,  0x09,  0x0d,
14113   0x36,  0x2e,  0x94,  0xf2,  0x09,  0x07,  0x36,  0x2e,  0x95,  0xa1,  0xc8,  0x02,  0x1f,  0x93,  0x01,  0x42,
14114   0xfe,  0x04,  0xfe,  0x99,  0x03,  0x9c,  0x8b,  0x02,  0x2a,  0xfe,  0x1c,  0x1e,  0xfe,  0x14,  0xf0,  0x08,
14115   0x2f,  0xfe,  0x0c,  0x1e,  0x2a,  0xfe,  0x1c,  0x1e,  0x8f,  0xfe,  0x1c,  0x1e,  0xfe,  0x82,  0xf0,  0xfe,
14116   0x10,  0x1e,  0x02,  0x0f,  0x3f,  0x04,  0xfe,  0x80,  0x83,  0x33,  0x0b,  0x0e,  0x02,  0x0f,  0xfe,  0x18,
14117   0x80,  0x04,  0xfe,  0x98,  0x83,  0x33,  0x0b,  0x0e,  0x02,  0x0f,  0xfe,  0x02,  0x80,  0x04,  0xfe,  0x82,
14118   0x83,  0x33,  0x0b,  0x0e,  0x02,  0x0f,  0xfe,  0x06,  0x80,  0x04,  0xfe,  0x86,  0x83,  0x33,  0x0b,  0x0e,
14119   0x02,  0x0f,  0xfe,  0x1b,  0x80,  0x04,  0xfe,  0x9b,  0x83,  0x33,  0x0b,  0x0e,  0x02,  0x0f,  0xfe,  0x04,
14120   0x80,  0x04,  0xfe,  0x84,  0x83,  0x33,  0x0b,  0x0e,  0x02,  0x0f,  0xfe,  0x80,  0x80,  0x04,  0xfe,  0x80,
14121   0x83,  0xfe,  0xc9,  0x47,  0x0b,  0x0e,  0x02,  0x0f,  0xfe,  0x19,  0x81,  0x04,  0xfe,  0x99,  0x83,  0xfe,
14122   0xca,  0x47,  0x0b,  0x0e,  0x02,  0x0f,  0xfe,  0x06,  0x83,  0x04,  0xfe,  0x86,  0x83,  0xfe,  0xce,  0x47,
14123   0x0b,  0x0e,  0x02,  0x0f,  0xfe,  0x2c,  0x90,  0x04,  0xfe,  0xac,  0x93,  0x3a,  0x0b,  0x0e,  0x02,  0x0f,
14124   0xfe,  0xae,  0x90,  0x04,  0xfe,  0xae,  0x93,  0x79,  0x0b,  0x0e,  0x02,  0x0f,  0xfe,  0x08,  0x90,  0x04,
14125   0xfe,  0x88,  0x93,  0x3a,  0x0b,  0x0e,  0x02,  0x0f,  0xfe,  0x8a,  0x90,  0x04,  0xfe,  0x8a,  0x93,  0x79,
14126   0x0b,  0x0e,  0x02,  0x0f,  0xfe,  0x0c,  0x90,  0x04,  0xfe,  0x8c,  0x93,  0x3a,  0x0b,  0x0e,  0x02,  0x0f,
14127   0xfe,  0x8e,  0x90,  0x04,  0xfe,  0x8e,  0x93,  0x79,  0x0b,  0x0e,  0x02,  0x0f,  0xfe,  0x3c,  0x90,  0x04,
14128   0xfe,  0xbc,  0x93,  0x3a,  0x0b,  0x0e,  0x02,  0x8b,  0x0f,  0xfe,  0x03,  0x80,  0x04,  0xfe,  0x83,  0x83,
14129   0x33,  0x0b,  0x77,  0x0e,  0xa8,  0x02,  0xff,  0x66,  0x00,  0x00,
14130 };
14131
14132 STATIC unsigned short _adv_asc38C1600_size =
14133         sizeof(_adv_asc38C1600_buf); /* 0x1673 */
14134 STATIC ADV_DCNT _adv_asc38C1600_chksum =
14135         0x0604EF77UL; /* Expanded little-endian checksum. */
14136
14137 /* a_init.c */
14138 /*
14139  * EEPROM Configuration.
14140  *
14141  * All drivers should use this structure to set the default EEPROM
14142  * configuration. The BIOS now uses this structure when it is built.
14143  * Additional structure information can be found in a_condor.h where
14144  * the structure is defined.
14145  *
14146  * The *_Field_IsChar structs are needed to correct for endianness.
14147  * These values are read from the board 16 bits at a time directly
14148  * into the structs. Because some fields are char, the values will be
14149  * in the wrong order. The *_Field_IsChar tells when to flip the
14150  * bytes. Data read and written to PCI memory is automatically swapped
14151  * on big-endian platforms so char fields read as words are actually being
14152  * unswapped on big-endian platforms.
14153  */
14154 STATIC ADVEEP_3550_CONFIG
14155 Default_3550_EEPROM_Config __initdata = {
14156     ADV_EEPROM_BIOS_ENABLE,     /* cfg_lsw */
14157     0x0000,                     /* cfg_msw */
14158     0xFFFF,                     /* disc_enable */
14159     0xFFFF,                     /* wdtr_able */
14160     0xFFFF,                     /* sdtr_able */
14161     0xFFFF,                     /* start_motor */
14162     0xFFFF,                     /* tagqng_able */
14163     0xFFFF,                     /* bios_scan */
14164     0,                          /* scam_tolerant */
14165     7,                          /* adapter_scsi_id */
14166     0,                          /* bios_boot_delay */
14167     3,                          /* scsi_reset_delay */
14168     0,                          /* bios_id_lun */
14169     0,                          /* termination */
14170     0,                          /* reserved1 */
14171     0xFFE7,                     /* bios_ctrl */
14172     0xFFFF,                     /* ultra_able */
14173     0,                          /* reserved2 */
14174     ASC_DEF_MAX_HOST_QNG,       /* max_host_qng */
14175     ASC_DEF_MAX_DVC_QNG,        /* max_dvc_qng */
14176     0,                          /* dvc_cntl */
14177     0,                          /* bug_fix */
14178     0,                          /* serial_number_word1 */
14179     0,                          /* serial_number_word2 */
14180     0,                          /* serial_number_word3 */
14181     0,                          /* check_sum */
14182     { 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 }, /* oem_name[16] */
14183     0,                          /* dvc_err_code */
14184     0,                          /* adv_err_code */
14185     0,                          /* adv_err_addr */
14186     0,                          /* saved_dvc_err_code */
14187     0,                          /* saved_adv_err_code */
14188     0,                          /* saved_adv_err_addr */
14189     0                           /* num_of_err */
14190 };
14191
14192 STATIC ADVEEP_3550_CONFIG
14193 ADVEEP_3550_Config_Field_IsChar __initdata = {
14194     0,                          /* cfg_lsw */
14195     0,                          /* cfg_msw */
14196     0,                          /* -disc_enable */
14197     0,                          /* wdtr_able */
14198     0,                          /* sdtr_able */
14199     0,                          /* start_motor */
14200     0,                          /* tagqng_able */
14201     0,                          /* bios_scan */
14202     0,                          /* scam_tolerant */
14203     1,                          /* adapter_scsi_id */
14204     1,                          /* bios_boot_delay */
14205     1,                          /* scsi_reset_delay */
14206     1,                          /* bios_id_lun */
14207     1,                          /* termination */
14208     1,                          /* reserved1 */
14209     0,                          /* bios_ctrl */
14210     0,                          /* ultra_able */
14211     0,                          /* reserved2 */
14212     1,                          /* max_host_qng */
14213     1,                          /* max_dvc_qng */
14214     0,                          /* dvc_cntl */
14215     0,                          /* bug_fix */
14216     0,                          /* serial_number_word1 */
14217     0,                          /* serial_number_word2 */
14218     0,                          /* serial_number_word3 */
14219     0,                          /* check_sum */
14220     { 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1 }, /* oem_name[16] */
14221     0,                          /* dvc_err_code */
14222     0,                          /* adv_err_code */
14223     0,                          /* adv_err_addr */
14224     0,                          /* saved_dvc_err_code */
14225     0,                          /* saved_adv_err_code */
14226     0,                          /* saved_adv_err_addr */
14227     0                           /* num_of_err */
14228 };
14229
14230 STATIC ADVEEP_38C0800_CONFIG
14231 Default_38C0800_EEPROM_Config __initdata = {
14232     ADV_EEPROM_BIOS_ENABLE,     /* 00 cfg_lsw */
14233     0x0000,                     /* 01 cfg_msw */
14234     0xFFFF,                     /* 02 disc_enable */
14235     0xFFFF,                     /* 03 wdtr_able */
14236     0x4444,                     /* 04 sdtr_speed1 */
14237     0xFFFF,                     /* 05 start_motor */
14238     0xFFFF,                     /* 06 tagqng_able */
14239     0xFFFF,                     /* 07 bios_scan */
14240     0,                          /* 08 scam_tolerant */
14241     7,                          /* 09 adapter_scsi_id */
14242     0,                          /*    bios_boot_delay */
14243     3,                          /* 10 scsi_reset_delay */
14244     0,                          /*    bios_id_lun */
14245     0,                          /* 11 termination_se */
14246     0,                          /*    termination_lvd */
14247     0xFFE7,                     /* 12 bios_ctrl */
14248     0x4444,                     /* 13 sdtr_speed2 */
14249     0x4444,                     /* 14 sdtr_speed3 */
14250     ASC_DEF_MAX_HOST_QNG,       /* 15 max_host_qng */
14251     ASC_DEF_MAX_DVC_QNG,        /*    max_dvc_qng */
14252     0,                          /* 16 dvc_cntl */
14253     0x4444,                     /* 17 sdtr_speed4 */
14254     0,                          /* 18 serial_number_word1 */
14255     0,                          /* 19 serial_number_word2 */
14256     0,                          /* 20 serial_number_word3 */
14257     0,                          /* 21 check_sum */
14258     { 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 }, /* 22-29 oem_name[16] */
14259     0,                          /* 30 dvc_err_code */
14260     0,                          /* 31 adv_err_code */
14261     0,                          /* 32 adv_err_addr */
14262     0,                          /* 33 saved_dvc_err_code */
14263     0,                          /* 34 saved_adv_err_code */
14264     0,                          /* 35 saved_adv_err_addr */
14265     0,                          /* 36 reserved */
14266     0,                          /* 37 reserved */
14267     0,                          /* 38 reserved */
14268     0,                          /* 39 reserved */
14269     0,                          /* 40 reserved */
14270     0,                          /* 41 reserved */
14271     0,                          /* 42 reserved */
14272     0,                          /* 43 reserved */
14273     0,                          /* 44 reserved */
14274     0,                          /* 45 reserved */
14275     0,                          /* 46 reserved */
14276     0,                          /* 47 reserved */
14277     0,                          /* 48 reserved */
14278     0,                          /* 49 reserved */
14279     0,                          /* 50 reserved */
14280     0,                          /* 51 reserved */
14281     0,                          /* 52 reserved */
14282     0,                          /* 53 reserved */
14283     0,                          /* 54 reserved */
14284     0,                          /* 55 reserved */
14285     0,                          /* 56 cisptr_lsw */
14286     0,                          /* 57 cisprt_msw */
14287     ADV_PCI_VENDOR_ID,          /* 58 subsysvid */
14288     ADV_PCI_DEVID_38C0800_REV1, /* 59 subsysid */
14289     0,                          /* 60 reserved */
14290     0,                          /* 61 reserved */
14291     0,                          /* 62 reserved */
14292     0                           /* 63 reserved */
14293 };
14294
14295 STATIC ADVEEP_38C0800_CONFIG
14296 ADVEEP_38C0800_Config_Field_IsChar __initdata = {
14297     0,                          /* 00 cfg_lsw */
14298     0,                          /* 01 cfg_msw */
14299     0,                          /* 02 disc_enable */
14300     0,                          /* 03 wdtr_able */
14301     0,                          /* 04 sdtr_speed1 */
14302     0,                          /* 05 start_motor */
14303     0,                          /* 06 tagqng_able */
14304     0,                          /* 07 bios_scan */
14305     0,                          /* 08 scam_tolerant */
14306     1,                          /* 09 adapter_scsi_id */
14307     1,                          /*    bios_boot_delay */
14308     1,                          /* 10 scsi_reset_delay */
14309     1,                          /*    bios_id_lun */
14310     1,                          /* 11 termination_se */
14311     1,                          /*    termination_lvd */
14312     0,                          /* 12 bios_ctrl */
14313     0,                          /* 13 sdtr_speed2 */
14314     0,                          /* 14 sdtr_speed3 */
14315     1,                          /* 15 max_host_qng */
14316     1,                          /*    max_dvc_qng */
14317     0,                          /* 16 dvc_cntl */
14318     0,                          /* 17 sdtr_speed4 */
14319     0,                          /* 18 serial_number_word1 */
14320     0,                          /* 19 serial_number_word2 */
14321     0,                          /* 20 serial_number_word3 */
14322     0,                          /* 21 check_sum */
14323     { 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1 }, /* 22-29 oem_name[16] */
14324     0,                          /* 30 dvc_err_code */
14325     0,                          /* 31 adv_err_code */
14326     0,                          /* 32 adv_err_addr */
14327     0,                          /* 33 saved_dvc_err_code */
14328     0,                          /* 34 saved_adv_err_code */
14329     0,                          /* 35 saved_adv_err_addr */
14330     0,                          /* 36 reserved */
14331     0,                          /* 37 reserved */
14332     0,                          /* 38 reserved */
14333     0,                          /* 39 reserved */
14334     0,                          /* 40 reserved */
14335     0,                          /* 41 reserved */
14336     0,                          /* 42 reserved */
14337     0,                          /* 43 reserved */
14338     0,                          /* 44 reserved */
14339     0,                          /* 45 reserved */
14340     0,                          /* 46 reserved */
14341     0,                          /* 47 reserved */
14342     0,                          /* 48 reserved */
14343     0,                          /* 49 reserved */
14344     0,                          /* 50 reserved */
14345     0,                          /* 51 reserved */
14346     0,                          /* 52 reserved */
14347     0,                          /* 53 reserved */
14348     0,                          /* 54 reserved */
14349     0,                          /* 55 reserved */
14350     0,                          /* 56 cisptr_lsw */
14351     0,                          /* 57 cisprt_msw */
14352     0,                          /* 58 subsysvid */
14353     0,                          /* 59 subsysid */
14354     0,                          /* 60 reserved */
14355     0,                          /* 61 reserved */
14356     0,                          /* 62 reserved */
14357     0                           /* 63 reserved */
14358 };
14359
14360 STATIC ADVEEP_38C1600_CONFIG
14361 Default_38C1600_EEPROM_Config __initdata = {
14362     ADV_EEPROM_BIOS_ENABLE,     /* 00 cfg_lsw */
14363     0x0000,                     /* 01 cfg_msw */
14364     0xFFFF,                     /* 02 disc_enable */
14365     0xFFFF,                     /* 03 wdtr_able */
14366     0x5555,                     /* 04 sdtr_speed1 */
14367     0xFFFF,                     /* 05 start_motor */
14368     0xFFFF,                     /* 06 tagqng_able */
14369     0xFFFF,                     /* 07 bios_scan */
14370     0,                          /* 08 scam_tolerant */
14371     7,                          /* 09 adapter_scsi_id */
14372     0,                          /*    bios_boot_delay */
14373     3,                          /* 10 scsi_reset_delay */
14374     0,                          /*    bios_id_lun */
14375     0,                          /* 11 termination_se */
14376     0,                          /*    termination_lvd */
14377     0xFFE7,                     /* 12 bios_ctrl */
14378     0x5555,                     /* 13 sdtr_speed2 */
14379     0x5555,                     /* 14 sdtr_speed3 */
14380     ASC_DEF_MAX_HOST_QNG,       /* 15 max_host_qng */
14381     ASC_DEF_MAX_DVC_QNG,        /*    max_dvc_qng */
14382     0,                          /* 16 dvc_cntl */
14383     0x5555,                     /* 17 sdtr_speed4 */
14384     0,                          /* 18 serial_number_word1 */
14385     0,                          /* 19 serial_number_word2 */
14386     0,                          /* 20 serial_number_word3 */
14387     0,                          /* 21 check_sum */
14388     { 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 }, /* 22-29 oem_name[16] */
14389     0,                          /* 30 dvc_err_code */
14390     0,                          /* 31 adv_err_code */
14391     0,                          /* 32 adv_err_addr */
14392     0,                          /* 33 saved_dvc_err_code */
14393     0,                          /* 34 saved_adv_err_code */
14394     0,                          /* 35 saved_adv_err_addr */
14395     0,                          /* 36 reserved */
14396     0,                          /* 37 reserved */
14397     0,                          /* 38 reserved */
14398     0,                          /* 39 reserved */
14399     0,                          /* 40 reserved */
14400     0,                          /* 41 reserved */
14401     0,                          /* 42 reserved */
14402     0,                          /* 43 reserved */
14403     0,                          /* 44 reserved */
14404     0,                          /* 45 reserved */
14405     0,                          /* 46 reserved */
14406     0,                          /* 47 reserved */
14407     0,                          /* 48 reserved */
14408     0,                          /* 49 reserved */
14409     0,                          /* 50 reserved */
14410     0,                          /* 51 reserved */
14411     0,                          /* 52 reserved */
14412     0,                          /* 53 reserved */
14413     0,                          /* 54 reserved */
14414     0,                          /* 55 reserved */
14415     0,                          /* 56 cisptr_lsw */
14416     0,                          /* 57 cisprt_msw */
14417     ADV_PCI_VENDOR_ID,          /* 58 subsysvid */
14418     ADV_PCI_DEVID_38C1600_REV1, /* 59 subsysid */
14419     0,                          /* 60 reserved */
14420     0,                          /* 61 reserved */
14421     0,                          /* 62 reserved */
14422     0                           /* 63 reserved */
14423 };
14424
14425 STATIC ADVEEP_38C1600_CONFIG
14426 ADVEEP_38C1600_Config_Field_IsChar __initdata = {
14427     0,                          /* 00 cfg_lsw */
14428     0,                          /* 01 cfg_msw */
14429     0,                          /* 02 disc_enable */
14430     0,                          /* 03 wdtr_able */
14431     0,                          /* 04 sdtr_speed1 */
14432     0,                          /* 05 start_motor */
14433     0,                          /* 06 tagqng_able */
14434     0,                          /* 07 bios_scan */
14435     0,                          /* 08 scam_tolerant */
14436     1,                          /* 09 adapter_scsi_id */
14437     1,                          /*    bios_boot_delay */
14438     1,                          /* 10 scsi_reset_delay */
14439     1,                          /*    bios_id_lun */
14440     1,                          /* 11 termination_se */
14441     1,                          /*    termination_lvd */
14442     0,                          /* 12 bios_ctrl */
14443     0,                          /* 13 sdtr_speed2 */
14444     0,                          /* 14 sdtr_speed3 */
14445     1,                          /* 15 max_host_qng */
14446     1,                          /*    max_dvc_qng */
14447     0,                          /* 16 dvc_cntl */
14448     0,                          /* 17 sdtr_speed4 */
14449     0,                          /* 18 serial_number_word1 */
14450     0,                          /* 19 serial_number_word2 */
14451     0,                          /* 20 serial_number_word3 */
14452     0,                          /* 21 check_sum */
14453     { 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1 }, /* 22-29 oem_name[16] */
14454     0,                          /* 30 dvc_err_code */
14455     0,                          /* 31 adv_err_code */
14456     0,                          /* 32 adv_err_addr */
14457     0,                          /* 33 saved_dvc_err_code */
14458     0,                          /* 34 saved_adv_err_code */
14459     0,                          /* 35 saved_adv_err_addr */
14460     0,                          /* 36 reserved */
14461     0,                          /* 37 reserved */
14462     0,                          /* 38 reserved */
14463     0,                          /* 39 reserved */
14464     0,                          /* 40 reserved */
14465     0,                          /* 41 reserved */
14466     0,                          /* 42 reserved */
14467     0,                          /* 43 reserved */
14468     0,                          /* 44 reserved */
14469     0,                          /* 45 reserved */
14470     0,                          /* 46 reserved */
14471     0,                          /* 47 reserved */
14472     0,                          /* 48 reserved */
14473     0,                          /* 49 reserved */
14474     0,                          /* 50 reserved */
14475     0,                          /* 51 reserved */
14476     0,                          /* 52 reserved */
14477     0,                          /* 53 reserved */
14478     0,                          /* 54 reserved */
14479     0,                          /* 55 reserved */
14480     0,                          /* 56 cisptr_lsw */
14481     0,                          /* 57 cisprt_msw */
14482     0,                          /* 58 subsysvid */
14483     0,                          /* 59 subsysid */
14484     0,                          /* 60 reserved */
14485     0,                          /* 61 reserved */
14486     0,                          /* 62 reserved */
14487     0                           /* 63 reserved */
14488 };
14489
14490 /*
14491  * Initialize the ADV_DVC_VAR structure.
14492  *
14493  * On failure set the ADV_DVC_VAR field 'err_code' and return ADV_ERROR.
14494  *
14495  * For a non-fatal error return a warning code. If there are no warnings
14496  * then 0 is returned.
14497  */
14498 STATIC int __init
14499 AdvInitGetConfig(ADV_DVC_VAR *asc_dvc)
14500 {
14501     ushort      warn_code;
14502     AdvPortAddr iop_base;
14503     uchar       pci_cmd_reg;
14504     int         status;
14505
14506     warn_code = 0;
14507     asc_dvc->err_code = 0;
14508     iop_base = asc_dvc->iop_base;
14509
14510     /*
14511      * PCI Command Register
14512      *
14513      * Note: AscPCICmdRegBits_BusMastering definition (0x0007) includes
14514      * I/O Space Control, Memory Space Control and Bus Master Control bits.
14515      */
14516
14517     if (((pci_cmd_reg = DvcAdvReadPCIConfigByte(asc_dvc,
14518                             AscPCIConfigCommandRegister))
14519          & AscPCICmdRegBits_BusMastering)
14520         != AscPCICmdRegBits_BusMastering)
14521     {
14522         pci_cmd_reg |= AscPCICmdRegBits_BusMastering;
14523
14524         DvcAdvWritePCIConfigByte(asc_dvc,
14525                 AscPCIConfigCommandRegister, pci_cmd_reg);
14526
14527         if (((DvcAdvReadPCIConfigByte(asc_dvc, AscPCIConfigCommandRegister))
14528              & AscPCICmdRegBits_BusMastering)
14529             != AscPCICmdRegBits_BusMastering)
14530         {
14531             warn_code |= ASC_WARN_SET_PCI_CONFIG_SPACE;
14532         }
14533     }
14534
14535     /*
14536      * PCI Latency Timer
14537      *
14538      * If the "latency timer" register is 0x20 or above, then we don't need
14539      * to change it.  Otherwise, set it to 0x20 (i.e. set it to 0x20 if it
14540      * comes up less than 0x20).
14541      */
14542     if (DvcAdvReadPCIConfigByte(asc_dvc, AscPCIConfigLatencyTimer) < 0x20) {
14543         DvcAdvWritePCIConfigByte(asc_dvc, AscPCIConfigLatencyTimer, 0x20);
14544         if (DvcAdvReadPCIConfigByte(asc_dvc, AscPCIConfigLatencyTimer) < 0x20)
14545         {
14546             warn_code |= ASC_WARN_SET_PCI_CONFIG_SPACE;
14547         }
14548     }
14549
14550     /*
14551      * Save the state of the PCI Configuration Command Register
14552      * "Parity Error Response Control" Bit. If the bit is clear (0),
14553      * in AdvInitAsc3550/38C0800Driver() tell the microcode to ignore
14554      * DMA parity errors.
14555      */
14556     asc_dvc->cfg->control_flag = 0;
14557     if (((DvcAdvReadPCIConfigByte(asc_dvc, AscPCIConfigCommandRegister)
14558          & AscPCICmdRegBits_ParErrRespCtrl)) == 0)
14559     {
14560         asc_dvc->cfg->control_flag |= CONTROL_FLAG_IGNORE_PERR;
14561     }
14562
14563     asc_dvc->cfg->lib_version = (ADV_LIB_VERSION_MAJOR << 8) |
14564       ADV_LIB_VERSION_MINOR;
14565     asc_dvc->cfg->chip_version =
14566       AdvGetChipVersion(iop_base, asc_dvc->bus_type);
14567
14568     ASC_DBG2(1, "AdvInitGetConfig: iopb_chip_id_1: 0x%x 0x%x\n",
14569         (ushort) AdvReadByteRegister(iop_base, IOPB_CHIP_ID_1),
14570         (ushort) ADV_CHIP_ID_BYTE);
14571
14572     ASC_DBG2(1, "AdvInitGetConfig: iopw_chip_id_0: 0x%x 0x%x\n",
14573         (ushort) AdvReadWordRegister(iop_base, IOPW_CHIP_ID_0),
14574         (ushort) ADV_CHIP_ID_WORD);
14575
14576     /*
14577      * Reset the chip to start and allow register writes.
14578      */
14579     if (AdvFindSignature(iop_base) == 0)
14580     {
14581         asc_dvc->err_code = ASC_IERR_BAD_SIGNATURE;
14582         return ADV_ERROR;
14583     }
14584     else {
14585         /*
14586          * The caller must set 'chip_type' to a valid setting.
14587          */
14588         if (asc_dvc->chip_type != ADV_CHIP_ASC3550 &&
14589             asc_dvc->chip_type != ADV_CHIP_ASC38C0800 &&
14590             asc_dvc->chip_type != ADV_CHIP_ASC38C1600)
14591         {
14592             asc_dvc->err_code |= ASC_IERR_BAD_CHIPTYPE;
14593             return ADV_ERROR;
14594         }
14595
14596         /*
14597          * Reset Chip.
14598          */
14599         AdvWriteWordRegister(iop_base, IOPW_CTRL_REG,
14600             ADV_CTRL_REG_CMD_RESET);
14601         DvcSleepMilliSecond(100);
14602         AdvWriteWordRegister(iop_base, IOPW_CTRL_REG,
14603             ADV_CTRL_REG_CMD_WR_IO_REG);
14604
14605         if (asc_dvc->chip_type == ADV_CHIP_ASC38C1600)
14606         {
14607             if ((status = AdvInitFrom38C1600EEP(asc_dvc)) == ADV_ERROR)
14608             {
14609                 return ADV_ERROR;
14610             }
14611         } else if (asc_dvc->chip_type == ADV_CHIP_ASC38C0800)
14612         {
14613             if ((status = AdvInitFrom38C0800EEP(asc_dvc)) == ADV_ERROR)
14614             {
14615                 return ADV_ERROR;
14616             }
14617         } else
14618         {
14619             if ((status = AdvInitFrom3550EEP(asc_dvc)) == ADV_ERROR)
14620             {
14621                 return ADV_ERROR;
14622             }
14623         }
14624         warn_code |= status;
14625     }
14626
14627     return warn_code;
14628 }
14629
14630 /*
14631  * Initialize the ASC-3550.
14632  *
14633  * On failure set the ADV_DVC_VAR field 'err_code' and return ADV_ERROR.
14634  *
14635  * For a non-fatal error return a warning code. If there are no warnings
14636  * then 0 is returned.
14637  *
14638  * Needed after initialization for error recovery.
14639  */
14640 STATIC int
14641 AdvInitAsc3550Driver(ADV_DVC_VAR *asc_dvc)
14642 {
14643     AdvPortAddr iop_base;
14644     ushort      warn_code;
14645     ADV_DCNT    sum;
14646     int         begin_addr;
14647     int         end_addr;
14648     ushort      code_sum;
14649     int         word;
14650     int         j;
14651     int         adv_asc3550_expanded_size;
14652     ADV_CARR_T  *carrp;
14653     ADV_DCNT    contig_len;
14654     ADV_SDCNT   buf_size;
14655     ADV_PADDR   carr_paddr;
14656     int         i;
14657     ushort      scsi_cfg1;
14658     uchar       tid;
14659     ushort      bios_mem[ASC_MC_BIOSLEN/2]; /* BIOS RISC Memory 0x40-0x8F. */
14660     ushort      wdtr_able = 0, sdtr_able, tagqng_able;
14661     uchar       max_cmd[ADV_MAX_TID + 1];
14662
14663     /* If there is already an error, don't continue. */
14664     if (asc_dvc->err_code != 0)
14665     {
14666         return ADV_ERROR;
14667     }
14668
14669     /*
14670      * The caller must set 'chip_type' to ADV_CHIP_ASC3550.
14671      */
14672     if (asc_dvc->chip_type != ADV_CHIP_ASC3550)
14673     {
14674         asc_dvc->err_code |= ASC_IERR_BAD_CHIPTYPE;
14675         return ADV_ERROR;
14676     }
14677
14678     warn_code = 0;
14679     iop_base = asc_dvc->iop_base;
14680
14681     /*
14682      * Save the RISC memory BIOS region before writing the microcode.
14683      * The BIOS may already be loaded and using its RISC LRAM region
14684      * so its region must be saved and restored.
14685      *
14686      * Note: This code makes the assumption, which is currently true,
14687      * that a chip reset does not clear RISC LRAM.
14688      */
14689     for (i = 0; i < ASC_MC_BIOSLEN/2; i++)
14690     {
14691         AdvReadWordLram(iop_base, ASC_MC_BIOSMEM + (2 * i), bios_mem[i]);
14692     }
14693
14694     /*
14695      * Save current per TID negotiated values.
14696      */
14697     if (bios_mem[(ASC_MC_BIOS_SIGNATURE - ASC_MC_BIOSMEM)/2] == 0x55AA)
14698     {
14699         ushort  bios_version, major, minor;
14700
14701         bios_version = bios_mem[(ASC_MC_BIOS_VERSION - ASC_MC_BIOSMEM)/2];
14702         major = (bios_version  >> 12) & 0xF;
14703         minor = (bios_version  >> 8) & 0xF;
14704         if (major < 3 || (major == 3 && minor == 1))
14705         {
14706             /* BIOS 3.1 and earlier location of 'wdtr_able' variable. */
14707             AdvReadWordLram(iop_base, 0x120, wdtr_able);
14708         } else
14709         {
14710             AdvReadWordLram(iop_base, ASC_MC_WDTR_ABLE, wdtr_able);
14711         }
14712     }
14713     AdvReadWordLram(iop_base, ASC_MC_SDTR_ABLE, sdtr_able);
14714     AdvReadWordLram(iop_base, ASC_MC_TAGQNG_ABLE, tagqng_able);
14715     for (tid = 0; tid <= ADV_MAX_TID; tid++)
14716     {
14717         AdvReadByteLram(iop_base, ASC_MC_NUMBER_OF_MAX_CMD + tid,
14718             max_cmd[tid]);
14719     }
14720
14721     /*
14722      * Load the Microcode
14723      *
14724      * Write the microcode image to RISC memory starting at address 0.
14725      */
14726     AdvWriteWordRegister(iop_base, IOPW_RAM_ADDR, 0);
14727     /* Assume the following compressed format of the microcode buffer:
14728      *
14729      *  254 word (508 byte) table indexed by byte code followed
14730      *  by the following byte codes:
14731      *
14732      *    1-Byte Code:
14733      *      00: Emit word 0 in table.
14734      *      01: Emit word 1 in table.
14735      *      .
14736      *      FD: Emit word 253 in table.
14737      *
14738      *    Multi-Byte Code:
14739      *      FE WW WW: (3 byte code) Word to emit is the next word WW WW.
14740      *      FF BB WW WW: (4 byte code) Emit BB count times next word WW WW.
14741      */
14742     word = 0;
14743     for (i = 253 * 2; i < _adv_asc3550_size; i++)
14744     {
14745         if (_adv_asc3550_buf[i] == 0xff)
14746         {
14747             for (j = 0; j < _adv_asc3550_buf[i + 1]; j++)
14748             {
14749                 AdvWriteWordAutoIncLram(iop_base, (((ushort)
14750                     _adv_asc3550_buf[i + 3] << 8) |
14751                 _adv_asc3550_buf[i + 2]));
14752                 word++;
14753             }
14754             i += 3;
14755         } else if (_adv_asc3550_buf[i] == 0xfe)
14756         {
14757             AdvWriteWordAutoIncLram(iop_base, (((ushort)
14758                 _adv_asc3550_buf[i + 2] << 8) |
14759                 _adv_asc3550_buf[i + 1]));
14760             i += 2;
14761             word++;
14762         } else
14763         {
14764             AdvWriteWordAutoIncLram(iop_base, (((ushort)
14765                 _adv_asc3550_buf[(_adv_asc3550_buf[i] * 2) + 1] << 8) |
14766                 _adv_asc3550_buf[_adv_asc3550_buf[i] * 2]));
14767             word++;
14768         }
14769     }
14770
14771     /*
14772      * Set 'word' for later use to clear the rest of memory and save
14773      * the expanded mcode size.
14774      */
14775     word *= 2;
14776     adv_asc3550_expanded_size = word;
14777
14778     /*
14779      * Clear the rest of ASC-3550 Internal RAM (8KB).
14780      */
14781     for (; word < ADV_3550_MEMSIZE; word += 2)
14782     {
14783         AdvWriteWordAutoIncLram(iop_base, 0);
14784     }
14785
14786     /*
14787      * Verify the microcode checksum.
14788      */
14789     sum = 0;
14790     AdvWriteWordRegister(iop_base, IOPW_RAM_ADDR, 0);
14791
14792     for (word = 0; word < adv_asc3550_expanded_size; word += 2)
14793     {
14794         sum += AdvReadWordAutoIncLram(iop_base);
14795     }
14796
14797     if (sum != _adv_asc3550_chksum)
14798     {
14799         asc_dvc->err_code |= ASC_IERR_MCODE_CHKSUM;
14800         return ADV_ERROR;
14801     }
14802
14803     /*
14804      * Restore the RISC memory BIOS region.
14805      */
14806     for (i = 0; i < ASC_MC_BIOSLEN/2; i++)
14807     {
14808         AdvWriteWordLram(iop_base, ASC_MC_BIOSMEM + (2 * i), bios_mem[i]);
14809     }
14810
14811     /*
14812      * Calculate and write the microcode code checksum to the microcode
14813      * code checksum location ASC_MC_CODE_CHK_SUM (0x2C).
14814      */
14815     AdvReadWordLram(iop_base, ASC_MC_CODE_BEGIN_ADDR, begin_addr);
14816     AdvReadWordLram(iop_base, ASC_MC_CODE_END_ADDR, end_addr);
14817     code_sum = 0;
14818     AdvWriteWordRegister(iop_base, IOPW_RAM_ADDR, begin_addr);
14819     for (word = begin_addr; word < end_addr; word += 2)
14820     {
14821         code_sum += AdvReadWordAutoIncLram(iop_base);
14822     }
14823     AdvWriteWordLram(iop_base, ASC_MC_CODE_CHK_SUM, code_sum);
14824
14825     /*
14826      * Read and save microcode version and date.
14827      */
14828     AdvReadWordLram(iop_base, ASC_MC_VERSION_DATE, asc_dvc->cfg->mcode_date);
14829     AdvReadWordLram(iop_base, ASC_MC_VERSION_NUM, asc_dvc->cfg->mcode_version);
14830
14831     /*
14832      * Set the chip type to indicate the ASC3550.
14833      */
14834     AdvWriteWordLram(iop_base, ASC_MC_CHIP_TYPE, ADV_CHIP_ASC3550);
14835
14836     /*
14837      * If the PCI Configuration Command Register "Parity Error Response
14838      * Control" Bit was clear (0), then set the microcode variable
14839      * 'control_flag' CONTROL_FLAG_IGNORE_PERR flag to tell the microcode
14840      * to ignore DMA parity errors.
14841      */
14842     if (asc_dvc->cfg->control_flag & CONTROL_FLAG_IGNORE_PERR)
14843     {
14844         AdvReadWordLram(iop_base, ASC_MC_CONTROL_FLAG, word);
14845         word |= CONTROL_FLAG_IGNORE_PERR;
14846         AdvWriteWordLram(iop_base, ASC_MC_CONTROL_FLAG, word);
14847     }
14848
14849     /*
14850      * For ASC-3550, setting the START_CTL_EMFU [3:2] bits sets a FIFO
14851      * threshold of 128 bytes. This register is only accessible to the host.
14852      */
14853     AdvWriteByteRegister(iop_base, IOPB_DMA_CFG0,
14854         START_CTL_EMFU | READ_CMD_MRM);
14855
14856     /*
14857      * Microcode operating variables for WDTR, SDTR, and command tag
14858      * queuing will be set in AdvInquiryHandling() based on what a
14859      * device reports it is capable of in Inquiry byte 7.
14860      *
14861      * If SCSI Bus Resets have been disabled, then directly set
14862      * SDTR and WDTR from the EEPROM configuration. This will allow
14863      * the BIOS and warm boot to work without a SCSI bus hang on
14864      * the Inquiry caused by host and target mismatched DTR values.
14865      * Without the SCSI Bus Reset, before an Inquiry a device can't
14866      * be assumed to be in Asynchronous, Narrow mode.
14867      */
14868     if ((asc_dvc->bios_ctrl & BIOS_CTRL_RESET_SCSI_BUS) == 0)
14869     {
14870         AdvWriteWordLram(iop_base, ASC_MC_WDTR_ABLE, asc_dvc->wdtr_able);
14871         AdvWriteWordLram(iop_base, ASC_MC_SDTR_ABLE, asc_dvc->sdtr_able);
14872     }
14873
14874     /*
14875      * Set microcode operating variables for SDTR_SPEED1, SDTR_SPEED2,
14876      * SDTR_SPEED3, and SDTR_SPEED4 based on the ULTRA EEPROM per TID
14877      * bitmask. These values determine the maximum SDTR speed negotiated
14878      * with a device.
14879      *
14880      * The SDTR per TID bitmask overrides the SDTR_SPEED1, SDTR_SPEED2,
14881      * SDTR_SPEED3, and SDTR_SPEED4 values so it is safe to set them
14882      * without determining here whether the device supports SDTR.
14883      *
14884      * 4-bit speed  SDTR speed name
14885      * ===========  ===============
14886      * 0000b (0x0)  SDTR disabled
14887      * 0001b (0x1)  5 Mhz
14888      * 0010b (0x2)  10 Mhz
14889      * 0011b (0x3)  20 Mhz (Ultra)
14890      * 0100b (0x4)  40 Mhz (LVD/Ultra2)
14891      * 0101b (0x5)  80 Mhz (LVD2/Ultra3)
14892      * 0110b (0x6)  Undefined
14893      * .
14894      * 1111b (0xF)  Undefined
14895      */
14896     word = 0;
14897     for (tid = 0; tid <= ADV_MAX_TID; tid++)
14898     {
14899         if (ADV_TID_TO_TIDMASK(tid) & asc_dvc->ultra_able)
14900         {
14901             /* Set Ultra speed for TID 'tid'. */
14902             word |= (0x3 << (4 * (tid % 4)));
14903         } else
14904         {
14905             /* Set Fast speed for TID 'tid'. */
14906             word |= (0x2 << (4 * (tid % 4)));
14907         }
14908         if (tid == 3) /* Check if done with sdtr_speed1. */
14909         {
14910             AdvWriteWordLram(iop_base, ASC_MC_SDTR_SPEED1, word);
14911             word = 0;
14912         } else if (tid == 7) /* Check if done with sdtr_speed2. */
14913         {
14914             AdvWriteWordLram(iop_base, ASC_MC_SDTR_SPEED2, word);
14915             word = 0;
14916         } else if (tid == 11) /* Check if done with sdtr_speed3. */
14917         {
14918             AdvWriteWordLram(iop_base, ASC_MC_SDTR_SPEED3, word);
14919             word = 0;
14920         } else if (tid == 15) /* Check if done with sdtr_speed4. */
14921         {
14922             AdvWriteWordLram(iop_base, ASC_MC_SDTR_SPEED4, word);
14923             /* End of loop. */
14924         }
14925     }
14926
14927     /*
14928      * Set microcode operating variable for the disconnect per TID bitmask.
14929      */
14930     AdvWriteWordLram(iop_base, ASC_MC_DISC_ENABLE, asc_dvc->cfg->disc_enable);
14931
14932     /*
14933      * Set SCSI_CFG0 Microcode Default Value.
14934      *
14935      * The microcode will set the SCSI_CFG0 register using this value
14936      * after it is started below.
14937      */
14938     AdvWriteWordLram(iop_base, ASC_MC_DEFAULT_SCSI_CFG0,
14939         PARITY_EN | QUEUE_128 | SEL_TMO_LONG | OUR_ID_EN |
14940         asc_dvc->chip_scsi_id);
14941
14942     /*
14943      * Determine SCSI_CFG1 Microcode Default Value.
14944      *
14945      * The microcode will set the SCSI_CFG1 register using this value
14946      * after it is started below.
14947      */
14948
14949     /* Read current SCSI_CFG1 Register value. */
14950     scsi_cfg1 = AdvReadWordRegister(iop_base, IOPW_SCSI_CFG1);
14951
14952     /*
14953      * If all three connectors are in use, return an error.
14954      */
14955     if ((scsi_cfg1 & CABLE_ILLEGAL_A) == 0 ||
14956         (scsi_cfg1 & CABLE_ILLEGAL_B) == 0)
14957     {
14958             asc_dvc->err_code |= ASC_IERR_ILLEGAL_CONNECTION;
14959             return ADV_ERROR;
14960     }
14961
14962     /*
14963      * If the internal narrow cable is reversed all of the SCSI_CTRL
14964      * register signals will be set. Check for and return an error if
14965      * this condition is found.
14966      */
14967     if ((AdvReadWordRegister(iop_base, IOPW_SCSI_CTRL) & 0x3F07) == 0x3F07)
14968     {
14969         asc_dvc->err_code |= ASC_IERR_REVERSED_CABLE;
14970         return ADV_ERROR;
14971     }
14972
14973     /*
14974      * If this is a differential board and a single-ended device
14975      * is attached to one of the connectors, return an error.
14976      */
14977     if ((scsi_cfg1 & DIFF_MODE) && (scsi_cfg1 & DIFF_SENSE) == 0)
14978     {
14979         asc_dvc->err_code |= ASC_IERR_SINGLE_END_DEVICE;
14980         return ADV_ERROR;
14981     }
14982
14983     /*
14984      * If automatic termination control is enabled, then set the
14985      * termination value based on a table listed in a_condor.h.
14986      *
14987      * If manual termination was specified with an EEPROM setting
14988      * then 'termination' was set-up in AdvInitFrom3550EEPROM() and
14989      * is ready to be 'ored' into SCSI_CFG1.
14990      */
14991     if (asc_dvc->cfg->termination == 0)
14992     {
14993         /*
14994          * The software always controls termination by setting TERM_CTL_SEL.
14995          * If TERM_CTL_SEL were set to 0, the hardware would set termination.
14996          */
14997         asc_dvc->cfg->termination |= TERM_CTL_SEL;
14998
14999         switch(scsi_cfg1 & CABLE_DETECT)
15000         {
15001             /* TERM_CTL_H: on, TERM_CTL_L: on */
15002             case 0x3: case 0x7: case 0xB: case 0xD: case 0xE: case 0xF:
15003                 asc_dvc->cfg->termination |= (TERM_CTL_H | TERM_CTL_L);
15004                 break;
15005
15006             /* TERM_CTL_H: on, TERM_CTL_L: off */
15007             case 0x1: case 0x5: case 0x9: case 0xA: case 0xC:
15008                 asc_dvc->cfg->termination |= TERM_CTL_H;
15009                 break;
15010
15011             /* TERM_CTL_H: off, TERM_CTL_L: off */
15012             case 0x2: case 0x6:
15013                 break;
15014         }
15015     }
15016
15017     /*
15018      * Clear any set TERM_CTL_H and TERM_CTL_L bits.
15019      */
15020     scsi_cfg1 &= ~TERM_CTL;
15021
15022     /*
15023      * Invert the TERM_CTL_H and TERM_CTL_L bits and then
15024      * set 'scsi_cfg1'. The TERM_POL bit does not need to be
15025      * referenced, because the hardware internally inverts
15026      * the Termination High and Low bits if TERM_POL is set.
15027      */
15028     scsi_cfg1 |= (TERM_CTL_SEL | (~asc_dvc->cfg->termination & TERM_CTL));
15029
15030     /*
15031      * Set SCSI_CFG1 Microcode Default Value
15032      *
15033      * Set filter value and possibly modified termination control
15034      * bits in the Microcode SCSI_CFG1 Register Value.
15035      *
15036      * The microcode will set the SCSI_CFG1 register using this value
15037      * after it is started below.
15038      */
15039     AdvWriteWordLram(iop_base, ASC_MC_DEFAULT_SCSI_CFG1,
15040         FLTR_DISABLE | scsi_cfg1);
15041
15042     /*
15043      * Set MEM_CFG Microcode Default Value
15044      *
15045      * The microcode will set the MEM_CFG register using this value
15046      * after it is started below.
15047      *
15048      * MEM_CFG may be accessed as a word or byte, but only bits 0-7
15049      * are defined.
15050      *
15051      * ASC-3550 has 8KB internal memory.
15052      */
15053     AdvWriteWordLram(iop_base, ASC_MC_DEFAULT_MEM_CFG,
15054         BIOS_EN | RAM_SZ_8KB);
15055
15056     /*
15057      * Set SEL_MASK Microcode Default Value
15058      *
15059      * The microcode will set the SEL_MASK register using this value
15060      * after it is started below.
15061      */
15062     AdvWriteWordLram(iop_base, ASC_MC_DEFAULT_SEL_MASK,
15063         ADV_TID_TO_TIDMASK(asc_dvc->chip_scsi_id));
15064
15065     /*
15066      * Build carrier freelist.
15067      *
15068      * Driver must have already allocated memory and set 'carrier_buf'.
15069      */
15070     ASC_ASSERT(asc_dvc->carrier_buf != NULL);
15071
15072     carrp = (ADV_CARR_T *) ADV_16BALIGN(asc_dvc->carrier_buf);
15073     asc_dvc->carr_freelist = NULL;
15074     if (carrp == (ADV_CARR_T *) asc_dvc->carrier_buf)
15075     {
15076         buf_size = ADV_CARRIER_BUFSIZE;
15077     } else
15078     {
15079         buf_size = ADV_CARRIER_BUFSIZE - sizeof(ADV_CARR_T);
15080     }
15081
15082     do {
15083         /*
15084          * Get physical address of the carrier 'carrp'.
15085          */
15086         contig_len = sizeof(ADV_CARR_T);
15087         carr_paddr = cpu_to_le32(DvcGetPhyAddr(asc_dvc, NULL, (uchar *) carrp,
15088             (ADV_SDCNT *) &contig_len, ADV_IS_CARRIER_FLAG));
15089
15090         buf_size -= sizeof(ADV_CARR_T);
15091
15092         /*
15093          * If the current carrier is not physically contiguous, then
15094          * maybe there was a page crossing. Try the next carrier aligned
15095          * start address.
15096          */
15097         if (contig_len < sizeof(ADV_CARR_T))
15098         {
15099             carrp++;
15100             continue;
15101         }
15102
15103         carrp->carr_pa = carr_paddr;
15104         carrp->carr_va = cpu_to_le32(ADV_VADDR_TO_U32(carrp));
15105
15106         /*
15107          * Insert the carrier at the beginning of the freelist.
15108          */
15109         carrp->next_vpa = cpu_to_le32(ADV_VADDR_TO_U32(asc_dvc->carr_freelist));
15110         asc_dvc->carr_freelist = carrp;
15111
15112         carrp++;
15113     }
15114     while (buf_size > 0);
15115
15116     /*
15117      * Set-up the Host->RISC Initiator Command Queue (ICQ).
15118      */
15119
15120     if ((asc_dvc->icq_sp = asc_dvc->carr_freelist) == NULL)
15121     {
15122         asc_dvc->err_code |= ASC_IERR_NO_CARRIER;
15123         return ADV_ERROR;
15124     }
15125     asc_dvc->carr_freelist = (ADV_CARR_T *)
15126         ADV_U32_TO_VADDR(le32_to_cpu(asc_dvc->icq_sp->next_vpa));
15127
15128     /*
15129      * The first command issued will be placed in the stopper carrier.
15130      */
15131     asc_dvc->icq_sp->next_vpa = cpu_to_le32(ASC_CQ_STOPPER);
15132
15133     /*
15134      * Set RISC ICQ physical address start value.
15135      */
15136     AdvWriteDWordLramNoSwap(iop_base, ASC_MC_ICQ, asc_dvc->icq_sp->carr_pa);
15137
15138     /*
15139      * Set-up the RISC->Host Initiator Response Queue (IRQ).
15140      */
15141     if ((asc_dvc->irq_sp = asc_dvc->carr_freelist) == NULL)
15142     {
15143         asc_dvc->err_code |= ASC_IERR_NO_CARRIER;
15144         return ADV_ERROR;
15145     }
15146     asc_dvc->carr_freelist = (ADV_CARR_T *)
15147          ADV_U32_TO_VADDR(le32_to_cpu(asc_dvc->irq_sp->next_vpa));
15148
15149     /*
15150      * The first command completed by the RISC will be placed in
15151      * the stopper.
15152      *
15153      * Note: Set 'next_vpa' to ASC_CQ_STOPPER. When the request is
15154      * completed the RISC will set the ASC_RQ_STOPPER bit.
15155      */
15156     asc_dvc->irq_sp->next_vpa = cpu_to_le32(ASC_CQ_STOPPER);
15157
15158     /*
15159      * Set RISC IRQ physical address start value.
15160      */
15161     AdvWriteDWordLramNoSwap(iop_base, ASC_MC_IRQ, asc_dvc->irq_sp->carr_pa);
15162     asc_dvc->carr_pending_cnt = 0;
15163
15164     AdvWriteByteRegister(iop_base, IOPB_INTR_ENABLES,
15165         (ADV_INTR_ENABLE_HOST_INTR | ADV_INTR_ENABLE_GLOBAL_INTR));
15166
15167     AdvReadWordLram(iop_base, ASC_MC_CODE_BEGIN_ADDR, word);
15168     AdvWriteWordRegister(iop_base, IOPW_PC, word);
15169
15170     /* finally, finally, gentlemen, start your engine */
15171     AdvWriteWordRegister(iop_base, IOPW_RISC_CSR, ADV_RISC_CSR_RUN);
15172
15173     /*
15174      * Reset the SCSI Bus if the EEPROM indicates that SCSI Bus
15175      * Resets should be performed. The RISC has to be running
15176      * to issue a SCSI Bus Reset.
15177      */
15178     if (asc_dvc->bios_ctrl & BIOS_CTRL_RESET_SCSI_BUS)
15179     {
15180         /*
15181          * If the BIOS Signature is present in memory, restore the
15182          * BIOS Handshake Configuration Table and do not perform
15183          * a SCSI Bus Reset.
15184          */
15185         if (bios_mem[(ASC_MC_BIOS_SIGNATURE - ASC_MC_BIOSMEM)/2] == 0x55AA)
15186         {
15187             /*
15188              * Restore per TID negotiated values.
15189              */
15190             AdvWriteWordLram(iop_base, ASC_MC_WDTR_ABLE, wdtr_able);
15191             AdvWriteWordLram(iop_base, ASC_MC_SDTR_ABLE, sdtr_able);
15192             AdvWriteWordLram(iop_base, ASC_MC_TAGQNG_ABLE, tagqng_able);
15193             for (tid = 0; tid <= ADV_MAX_TID; tid++)
15194             {
15195                 AdvWriteByteLram(iop_base, ASC_MC_NUMBER_OF_MAX_CMD + tid,
15196                     max_cmd[tid]);
15197             }
15198         } else
15199         {
15200             if (AdvResetSB(asc_dvc) != ADV_TRUE)
15201             {
15202                 warn_code = ASC_WARN_BUSRESET_ERROR;
15203             }
15204         }
15205     }
15206
15207     return warn_code;
15208 }
15209
15210 /*
15211  * Initialize the ASC-38C0800.
15212  *
15213  * On failure set the ADV_DVC_VAR field 'err_code' and return ADV_ERROR.
15214  *
15215  * For a non-fatal error return a warning code. If there are no warnings
15216  * then 0 is returned.
15217  *
15218  * Needed after initialization for error recovery.
15219  */
15220 STATIC int
15221 AdvInitAsc38C0800Driver(ADV_DVC_VAR *asc_dvc)
15222 {
15223     AdvPortAddr iop_base;
15224     ushort      warn_code;
15225     ADV_DCNT    sum;
15226     int         begin_addr;
15227     int         end_addr;
15228     ushort      code_sum;
15229     int         word;
15230     int         j;
15231     int         adv_asc38C0800_expanded_size;
15232     ADV_CARR_T  *carrp;
15233     ADV_DCNT    contig_len;
15234     ADV_SDCNT   buf_size;
15235     ADV_PADDR   carr_paddr;
15236     int         i;
15237     ushort      scsi_cfg1;
15238     uchar       byte;
15239     uchar       tid;
15240     ushort      bios_mem[ASC_MC_BIOSLEN/2]; /* BIOS RISC Memory 0x40-0x8F. */
15241     ushort      wdtr_able, sdtr_able, tagqng_able;
15242     uchar       max_cmd[ADV_MAX_TID + 1];
15243
15244     /* If there is already an error, don't continue. */
15245     if (asc_dvc->err_code != 0)
15246     {
15247         return ADV_ERROR;
15248     }
15249
15250     /*
15251      * The caller must set 'chip_type' to ADV_CHIP_ASC38C0800.
15252      */
15253     if (asc_dvc->chip_type != ADV_CHIP_ASC38C0800)
15254     {
15255         asc_dvc->err_code = ASC_IERR_BAD_CHIPTYPE;
15256         return ADV_ERROR;
15257     }
15258
15259     warn_code = 0;
15260     iop_base = asc_dvc->iop_base;
15261
15262     /*
15263      * Save the RISC memory BIOS region before writing the microcode.
15264      * The BIOS may already be loaded and using its RISC LRAM region
15265      * so its region must be saved and restored.
15266      *
15267      * Note: This code makes the assumption, which is currently true,
15268      * that a chip reset does not clear RISC LRAM.
15269      */
15270     for (i = 0; i < ASC_MC_BIOSLEN/2; i++)
15271     {
15272         AdvReadWordLram(iop_base, ASC_MC_BIOSMEM + (2 * i), bios_mem[i]);
15273     }
15274
15275     /*
15276      * Save current per TID negotiated values.
15277      */
15278     AdvReadWordLram(iop_base, ASC_MC_WDTR_ABLE, wdtr_able);
15279     AdvReadWordLram(iop_base, ASC_MC_SDTR_ABLE, sdtr_able);
15280     AdvReadWordLram(iop_base, ASC_MC_TAGQNG_ABLE, tagqng_able);
15281     for (tid = 0; tid <= ADV_MAX_TID; tid++)
15282     {
15283         AdvReadByteLram(iop_base, ASC_MC_NUMBER_OF_MAX_CMD + tid,
15284             max_cmd[tid]);
15285     }
15286
15287     /*
15288      * RAM BIST (RAM Built-In Self Test)
15289      *
15290      * Address : I/O base + offset 0x38h register (byte).
15291      * Function: Bit 7-6(RW) : RAM mode
15292      *                          Normal Mode   : 0x00
15293      *                          Pre-test Mode : 0x40
15294      *                          RAM Test Mode : 0x80
15295      *           Bit 5       : unused
15296      *           Bit 4(RO)   : Done bit
15297      *           Bit 3-0(RO) : Status
15298      *                          Host Error    : 0x08
15299      *                          Int_RAM Error : 0x04
15300      *                          RISC Error    : 0x02
15301      *                          SCSI Error    : 0x01
15302      *                          No Error      : 0x00
15303      *
15304      * Note: RAM BIST code should be put right here, before loading the
15305      * microcode and after saving the RISC memory BIOS region.
15306      */
15307
15308     /*
15309      * LRAM Pre-test
15310      *
15311      * Write PRE_TEST_MODE (0x40) to register and wait for 10 milliseconds.
15312      * If Done bit not set or low nibble not PRE_TEST_VALUE (0x05), return
15313      * an error. Reset to NORMAL_MODE (0x00) and do again. If cannot reset
15314      * to NORMAL_MODE, return an error too.
15315      */
15316     for (i = 0; i < 2; i++)
15317     {
15318         AdvWriteByteRegister(iop_base, IOPB_RAM_BIST, PRE_TEST_MODE);
15319         DvcSleepMilliSecond(10);  /* Wait for 10ms before reading back. */
15320         byte = AdvReadByteRegister(iop_base, IOPB_RAM_BIST);
15321         if ((byte & RAM_TEST_DONE) == 0 || (byte & 0x0F) != PRE_TEST_VALUE)
15322         {
15323             asc_dvc->err_code |= ASC_IERR_BIST_PRE_TEST;
15324             return ADV_ERROR;
15325         }
15326
15327         AdvWriteByteRegister(iop_base, IOPB_RAM_BIST, NORMAL_MODE);
15328         DvcSleepMilliSecond(10);  /* Wait for 10ms before reading back. */
15329         if (AdvReadByteRegister(iop_base, IOPB_RAM_BIST)
15330             != NORMAL_VALUE)
15331         {
15332             asc_dvc->err_code |= ASC_IERR_BIST_PRE_TEST;
15333             return ADV_ERROR;
15334         }
15335     }
15336
15337     /*
15338      * LRAM Test - It takes about 1.5 ms to run through the test.
15339      *
15340      * Write RAM_TEST_MODE (0x80) to register and wait for 10 milliseconds.
15341      * If Done bit not set or Status not 0, save register byte, set the
15342      * err_code, and return an error.
15343      */
15344     AdvWriteByteRegister(iop_base, IOPB_RAM_BIST, RAM_TEST_MODE);
15345     DvcSleepMilliSecond(10);  /* Wait for 10ms before checking status. */
15346
15347     byte = AdvReadByteRegister(iop_base, IOPB_RAM_BIST);
15348     if ((byte & RAM_TEST_DONE) == 0 || (byte & RAM_TEST_STATUS) != 0)
15349     {
15350         /* Get here if Done bit not set or Status not 0. */
15351         asc_dvc->bist_err_code = byte;  /* for BIOS display message */
15352         asc_dvc->err_code |= ASC_IERR_BIST_RAM_TEST;
15353         return ADV_ERROR;
15354     }
15355
15356     /* We need to reset back to normal mode after LRAM test passes. */
15357     AdvWriteByteRegister(iop_base, IOPB_RAM_BIST, NORMAL_MODE);
15358
15359     /*
15360      * Load the Microcode
15361      *
15362      * Write the microcode image to RISC memory starting at address 0.
15363      *
15364      */
15365     AdvWriteWordRegister(iop_base, IOPW_RAM_ADDR, 0);
15366
15367     /* Assume the following compressed format of the microcode buffer:
15368      *
15369      *  254 word (508 byte) table indexed by byte code followed
15370      *  by the following byte codes:
15371      *
15372      *    1-Byte Code:
15373      *      00: Emit word 0 in table.
15374      *      01: Emit word 1 in table.
15375      *      .
15376      *      FD: Emit word 253 in table.
15377      *
15378      *    Multi-Byte Code:
15379      *      FE WW WW: (3 byte code) Word to emit is the next word WW WW.
15380      *      FF BB WW WW: (4 byte code) Emit BB count times next word WW WW.
15381      */
15382     word = 0;
15383     for (i = 253 * 2; i < _adv_asc38C0800_size; i++)
15384     {
15385         if (_adv_asc38C0800_buf[i] == 0xff)
15386         {
15387             for (j = 0; j < _adv_asc38C0800_buf[i + 1]; j++)
15388             {
15389                 AdvWriteWordAutoIncLram(iop_base, (((ushort)
15390                     _adv_asc38C0800_buf[i + 3] << 8) |
15391                     _adv_asc38C0800_buf[i + 2]));
15392                 word++;
15393             }
15394             i += 3;
15395         } else if (_adv_asc38C0800_buf[i] == 0xfe)
15396         {
15397             AdvWriteWordAutoIncLram(iop_base, (((ushort)
15398                 _adv_asc38C0800_buf[i + 2] << 8) |
15399                 _adv_asc38C0800_buf[i + 1]));
15400             i += 2;
15401             word++;
15402         } else
15403         {
15404             AdvWriteWordAutoIncLram(iop_base, (((ushort)
15405                 _adv_asc38C0800_buf[(_adv_asc38C0800_buf[i] * 2) + 1] << 8) |
15406                 _adv_asc38C0800_buf[_adv_asc38C0800_buf[i] * 2]));
15407             word++;
15408         }
15409     }
15410
15411     /*
15412      * Set 'word' for later use to clear the rest of memory and save
15413      * the expanded mcode size.
15414      */
15415     word *= 2;
15416     adv_asc38C0800_expanded_size = word;
15417
15418     /*
15419      * Clear the rest of ASC-38C0800 Internal RAM (16KB).
15420      */
15421     for (; word < ADV_38C0800_MEMSIZE; word += 2)
15422     {
15423         AdvWriteWordAutoIncLram(iop_base, 0);
15424     }
15425
15426     /*
15427      * Verify the microcode checksum.
15428      */
15429     sum = 0;
15430     AdvWriteWordRegister(iop_base, IOPW_RAM_ADDR, 0);
15431
15432     for (word = 0; word < adv_asc38C0800_expanded_size; word += 2)
15433     {
15434         sum += AdvReadWordAutoIncLram(iop_base);
15435     }
15436     ASC_DBG2(1, "AdvInitAsc38C0800Driver: word %d, i %d\n", word, i);
15437
15438     ASC_DBG2(1,
15439         "AdvInitAsc38C0800Driver: sum 0x%lx, _adv_asc38C0800_chksum 0x%lx\n",
15440         (ulong) sum, (ulong) _adv_asc38C0800_chksum);
15441
15442     if (sum != _adv_asc38C0800_chksum)
15443     {
15444         asc_dvc->err_code |= ASC_IERR_MCODE_CHKSUM;
15445         return ADV_ERROR;
15446     }
15447
15448     /*
15449      * Restore the RISC memory BIOS region.
15450      */
15451     for (i = 0; i < ASC_MC_BIOSLEN/2; i++)
15452     {
15453         AdvWriteWordLram(iop_base, ASC_MC_BIOSMEM + (2 * i), bios_mem[i]);
15454     }
15455
15456     /*
15457      * Calculate and write the microcode code checksum to the microcode
15458      * code checksum location ASC_MC_CODE_CHK_SUM (0x2C).
15459      */
15460     AdvReadWordLram(iop_base, ASC_MC_CODE_BEGIN_ADDR, begin_addr);
15461     AdvReadWordLram(iop_base, ASC_MC_CODE_END_ADDR, end_addr);
15462     code_sum = 0;
15463     AdvWriteWordRegister(iop_base, IOPW_RAM_ADDR, begin_addr);
15464     for (word = begin_addr; word < end_addr; word += 2)
15465     {
15466         code_sum += AdvReadWordAutoIncLram(iop_base);
15467     }
15468     AdvWriteWordLram(iop_base, ASC_MC_CODE_CHK_SUM, code_sum);
15469
15470     /*
15471      * Read microcode version and date.
15472      */
15473     AdvReadWordLram(iop_base, ASC_MC_VERSION_DATE, asc_dvc->cfg->mcode_date);
15474     AdvReadWordLram(iop_base, ASC_MC_VERSION_NUM, asc_dvc->cfg->mcode_version);
15475
15476     /*
15477      * Set the chip type to indicate the ASC38C0800.
15478      */
15479     AdvWriteWordLram(iop_base, ASC_MC_CHIP_TYPE, ADV_CHIP_ASC38C0800);
15480
15481     /*
15482      * Write 1 to bit 14 'DIS_TERM_DRV' in the SCSI_CFG1 register.
15483      * When DIS_TERM_DRV set to 1, C_DET[3:0] will reflect current
15484      * cable detection and then we are able to read C_DET[3:0].
15485      *
15486      * Note: We will reset DIS_TERM_DRV to 0 in the 'Set SCSI_CFG1
15487      * Microcode Default Value' section below.
15488      */
15489     scsi_cfg1 = AdvReadWordRegister(iop_base, IOPW_SCSI_CFG1);
15490     AdvWriteWordRegister(iop_base, IOPW_SCSI_CFG1, scsi_cfg1 | DIS_TERM_DRV);
15491
15492     /*
15493      * If the PCI Configuration Command Register "Parity Error Response
15494      * Control" Bit was clear (0), then set the microcode variable
15495      * 'control_flag' CONTROL_FLAG_IGNORE_PERR flag to tell the microcode
15496      * to ignore DMA parity errors.
15497      */
15498     if (asc_dvc->cfg->control_flag & CONTROL_FLAG_IGNORE_PERR)
15499     {
15500         AdvReadWordLram(iop_base, ASC_MC_CONTROL_FLAG, word);
15501         word |= CONTROL_FLAG_IGNORE_PERR;
15502         AdvWriteWordLram(iop_base, ASC_MC_CONTROL_FLAG, word);
15503     }
15504
15505     /*
15506      * For ASC-38C0800, set FIFO_THRESH_80B [6:4] bits and START_CTL_TH [3:2]
15507      * bits for the default FIFO threshold.
15508      *
15509      * Note: ASC-38C0800 FIFO threshold has been changed to 256 bytes.
15510      *
15511      * For DMA Errata #4 set the BC_THRESH_ENB bit.
15512      */
15513     AdvWriteByteRegister(iop_base, IOPB_DMA_CFG0,
15514         BC_THRESH_ENB | FIFO_THRESH_80B | START_CTL_TH | READ_CMD_MRM);
15515
15516     /*
15517      * Microcode operating variables for WDTR, SDTR, and command tag
15518      * queuing will be set in AdvInquiryHandling() based on what a
15519      * device reports it is capable of in Inquiry byte 7.
15520      *
15521      * If SCSI Bus Resets have been disabled, then directly set
15522      * SDTR and WDTR from the EEPROM configuration. This will allow
15523      * the BIOS and warm boot to work without a SCSI bus hang on
15524      * the Inquiry caused by host and target mismatched DTR values.
15525      * Without the SCSI Bus Reset, before an Inquiry a device can't
15526      * be assumed to be in Asynchronous, Narrow mode.
15527      */
15528     if ((asc_dvc->bios_ctrl & BIOS_CTRL_RESET_SCSI_BUS) == 0)
15529     {
15530         AdvWriteWordLram(iop_base, ASC_MC_WDTR_ABLE, asc_dvc->wdtr_able);
15531         AdvWriteWordLram(iop_base, ASC_MC_SDTR_ABLE, asc_dvc->sdtr_able);
15532     }
15533
15534     /*
15535      * Set microcode operating variables for DISC and SDTR_SPEED1,
15536      * SDTR_SPEED2, SDTR_SPEED3, and SDTR_SPEED4 based on the EEPROM
15537      * configuration values.
15538      *
15539      * The SDTR per TID bitmask overrides the SDTR_SPEED1, SDTR_SPEED2,
15540      * SDTR_SPEED3, and SDTR_SPEED4 values so it is safe to set them
15541      * without determining here whether the device supports SDTR.
15542      */
15543     AdvWriteWordLram(iop_base, ASC_MC_DISC_ENABLE, asc_dvc->cfg->disc_enable);
15544     AdvWriteWordLram(iop_base, ASC_MC_SDTR_SPEED1, asc_dvc->sdtr_speed1);
15545     AdvWriteWordLram(iop_base, ASC_MC_SDTR_SPEED2, asc_dvc->sdtr_speed2);
15546     AdvWriteWordLram(iop_base, ASC_MC_SDTR_SPEED3, asc_dvc->sdtr_speed3);
15547     AdvWriteWordLram(iop_base, ASC_MC_SDTR_SPEED4, asc_dvc->sdtr_speed4);
15548
15549     /*
15550      * Set SCSI_CFG0 Microcode Default Value.
15551      *
15552      * The microcode will set the SCSI_CFG0 register using this value
15553      * after it is started below.
15554      */
15555     AdvWriteWordLram(iop_base, ASC_MC_DEFAULT_SCSI_CFG0,
15556         PARITY_EN | QUEUE_128 | SEL_TMO_LONG | OUR_ID_EN |
15557         asc_dvc->chip_scsi_id);
15558
15559     /*
15560      * Determine SCSI_CFG1 Microcode Default Value.
15561      *
15562      * The microcode will set the SCSI_CFG1 register using this value
15563      * after it is started below.
15564      */
15565
15566     /* Read current SCSI_CFG1 Register value. */
15567     scsi_cfg1 = AdvReadWordRegister(iop_base, IOPW_SCSI_CFG1);
15568
15569     /*
15570      * If the internal narrow cable is reversed all of the SCSI_CTRL
15571      * register signals will be set. Check for and return an error if
15572      * this condition is found.
15573      */
15574     if ((AdvReadWordRegister(iop_base, IOPW_SCSI_CTRL) & 0x3F07) == 0x3F07)
15575     {
15576         asc_dvc->err_code |= ASC_IERR_REVERSED_CABLE;
15577         return ADV_ERROR;
15578     }
15579
15580     /*
15581      * All kind of combinations of devices attached to one of four connectors
15582      * are acceptable except HVD device attached. For example, LVD device can
15583      * be attached to SE connector while SE device attached to LVD connector.
15584      * If LVD device attached to SE connector, it only runs up to Ultra speed.
15585      *
15586      * If an HVD device is attached to one of LVD connectors, return an error.
15587      * However, there is no way to detect HVD device attached to SE connectors.
15588      */
15589     if (scsi_cfg1 & HVD)
15590     {
15591         asc_dvc->err_code |= ASC_IERR_HVD_DEVICE;
15592         return ADV_ERROR;
15593     }
15594
15595     /*
15596      * If either SE or LVD automatic termination control is enabled, then
15597      * set the termination value based on a table listed in a_condor.h.
15598      *
15599      * If manual termination was specified with an EEPROM setting then
15600      * 'termination' was set-up in AdvInitFrom38C0800EEPROM() and is ready to
15601      * be 'ored' into SCSI_CFG1.
15602      */
15603     if ((asc_dvc->cfg->termination & TERM_SE) == 0)
15604     {
15605         /* SE automatic termination control is enabled. */
15606         switch(scsi_cfg1 & C_DET_SE)
15607         {
15608             /* TERM_SE_HI: on, TERM_SE_LO: on */
15609             case 0x1: case 0x2: case 0x3:
15610                 asc_dvc->cfg->termination |= TERM_SE;
15611                 break;
15612
15613             /* TERM_SE_HI: on, TERM_SE_LO: off */
15614             case 0x0:
15615                 asc_dvc->cfg->termination |= TERM_SE_HI;
15616                 break;
15617         }
15618     }
15619
15620     if ((asc_dvc->cfg->termination & TERM_LVD) == 0)
15621     {
15622         /* LVD automatic termination control is enabled. */
15623         switch(scsi_cfg1 & C_DET_LVD)
15624         {
15625             /* TERM_LVD_HI: on, TERM_LVD_LO: on */
15626             case 0x4: case 0x8: case 0xC:
15627                 asc_dvc->cfg->termination |= TERM_LVD;
15628                 break;
15629
15630             /* TERM_LVD_HI: off, TERM_LVD_LO: off */
15631             case 0x0:
15632                 break;
15633         }
15634     }
15635
15636     /*
15637      * Clear any set TERM_SE and TERM_LVD bits.
15638      */
15639     scsi_cfg1 &= (~TERM_SE & ~TERM_LVD);
15640
15641     /*
15642      * Invert the TERM_SE and TERM_LVD bits and then set 'scsi_cfg1'.
15643      */
15644     scsi_cfg1 |= (~asc_dvc->cfg->termination & 0xF0);
15645
15646     /*
15647      * Clear BIG_ENDIAN, DIS_TERM_DRV, Terminator Polarity and HVD/LVD/SE bits
15648      * and set possibly modified termination control bits in the Microcode
15649      * SCSI_CFG1 Register Value.
15650      */
15651     scsi_cfg1 &= (~BIG_ENDIAN & ~DIS_TERM_DRV & ~TERM_POL & ~HVD_LVD_SE);
15652
15653     /*
15654      * Set SCSI_CFG1 Microcode Default Value
15655      *
15656      * Set possibly modified termination control and reset DIS_TERM_DRV
15657      * bits in the Microcode SCSI_CFG1 Register Value.
15658      *
15659      * The microcode will set the SCSI_CFG1 register using this value
15660      * after it is started below.
15661      */
15662     AdvWriteWordLram(iop_base, ASC_MC_DEFAULT_SCSI_CFG1, scsi_cfg1);
15663
15664     /*
15665      * Set MEM_CFG Microcode Default Value
15666      *
15667      * The microcode will set the MEM_CFG register using this value
15668      * after it is started below.
15669      *
15670      * MEM_CFG may be accessed as a word or byte, but only bits 0-7
15671      * are defined.
15672      *
15673      * ASC-38C0800 has 16KB internal memory.
15674      */
15675     AdvWriteWordLram(iop_base, ASC_MC_DEFAULT_MEM_CFG,
15676         BIOS_EN | RAM_SZ_16KB);
15677
15678     /*
15679      * Set SEL_MASK Microcode Default Value
15680      *
15681      * The microcode will set the SEL_MASK register using this value
15682      * after it is started below.
15683      */
15684     AdvWriteWordLram(iop_base, ASC_MC_DEFAULT_SEL_MASK,
15685         ADV_TID_TO_TIDMASK(asc_dvc->chip_scsi_id));
15686
15687     /*
15688      * Build the carrier freelist.
15689      *
15690      * Driver must have already allocated memory and set 'carrier_buf'.
15691      */
15692     ASC_ASSERT(asc_dvc->carrier_buf != NULL);
15693
15694     carrp = (ADV_CARR_T *) ADV_16BALIGN(asc_dvc->carrier_buf);
15695     asc_dvc->carr_freelist = NULL;
15696     if (carrp == (ADV_CARR_T *) asc_dvc->carrier_buf)
15697     {
15698         buf_size = ADV_CARRIER_BUFSIZE;
15699     } else
15700     {
15701         buf_size = ADV_CARRIER_BUFSIZE - sizeof(ADV_CARR_T);
15702     }
15703
15704     do {
15705         /*
15706          * Get physical address for the carrier 'carrp'.
15707          */
15708         contig_len = sizeof(ADV_CARR_T);
15709         carr_paddr = cpu_to_le32(DvcGetPhyAddr(asc_dvc, NULL, (uchar *) carrp,
15710             (ADV_SDCNT *) &contig_len, ADV_IS_CARRIER_FLAG));
15711
15712         buf_size -= sizeof(ADV_CARR_T);
15713
15714         /*
15715          * If the current carrier is not physically contiguous, then
15716          * maybe there was a page crossing. Try the next carrier aligned
15717          * start address.
15718          */
15719         if (contig_len < sizeof(ADV_CARR_T))
15720         {
15721             carrp++;
15722             continue;
15723         }
15724
15725         carrp->carr_pa = carr_paddr;
15726         carrp->carr_va = cpu_to_le32(ADV_VADDR_TO_U32(carrp));
15727
15728         /*
15729          * Insert the carrier at the beginning of the freelist.
15730          */
15731         carrp->next_vpa = cpu_to_le32(ADV_VADDR_TO_U32(asc_dvc->carr_freelist));
15732         asc_dvc->carr_freelist = carrp;
15733
15734         carrp++;
15735     }
15736     while (buf_size > 0);
15737
15738     /*
15739      * Set-up the Host->RISC Initiator Command Queue (ICQ).
15740      */
15741
15742     if ((asc_dvc->icq_sp = asc_dvc->carr_freelist) == NULL)
15743     {
15744         asc_dvc->err_code |= ASC_IERR_NO_CARRIER;
15745         return ADV_ERROR;
15746     }
15747     asc_dvc->carr_freelist = (ADV_CARR_T *)
15748         ADV_U32_TO_VADDR(le32_to_cpu(asc_dvc->icq_sp->next_vpa));
15749
15750     /*
15751      * The first command issued will be placed in the stopper carrier.
15752      */
15753     asc_dvc->icq_sp->next_vpa = cpu_to_le32(ASC_CQ_STOPPER);
15754
15755     /*
15756      * Set RISC ICQ physical address start value.
15757      * carr_pa is LE, must be native before write
15758      */
15759     AdvWriteDWordLramNoSwap(iop_base, ASC_MC_ICQ, asc_dvc->icq_sp->carr_pa);
15760
15761     /*
15762      * Set-up the RISC->Host Initiator Response Queue (IRQ).
15763      */
15764     if ((asc_dvc->irq_sp = asc_dvc->carr_freelist) == NULL)
15765     {
15766         asc_dvc->err_code |= ASC_IERR_NO_CARRIER;
15767         return ADV_ERROR;
15768     }
15769     asc_dvc->carr_freelist = (ADV_CARR_T *)
15770         ADV_U32_TO_VADDR(le32_to_cpu(asc_dvc->irq_sp->next_vpa));
15771
15772     /*
15773      * The first command completed by the RISC will be placed in
15774      * the stopper.
15775      *
15776      * Note: Set 'next_vpa' to ASC_CQ_STOPPER. When the request is
15777      * completed the RISC will set the ASC_RQ_STOPPER bit.
15778      */
15779     asc_dvc->irq_sp->next_vpa = cpu_to_le32(ASC_CQ_STOPPER);
15780
15781     /*
15782      * Set RISC IRQ physical address start value.
15783      *
15784      * carr_pa is LE, must be native before write *
15785      */
15786     AdvWriteDWordLramNoSwap(iop_base, ASC_MC_IRQ, asc_dvc->irq_sp->carr_pa);
15787     asc_dvc->carr_pending_cnt = 0;
15788
15789     AdvWriteByteRegister(iop_base, IOPB_INTR_ENABLES,
15790         (ADV_INTR_ENABLE_HOST_INTR | ADV_INTR_ENABLE_GLOBAL_INTR));
15791
15792     AdvReadWordLram(iop_base, ASC_MC_CODE_BEGIN_ADDR, word);
15793     AdvWriteWordRegister(iop_base, IOPW_PC, word);
15794
15795     /* finally, finally, gentlemen, start your engine */
15796     AdvWriteWordRegister(iop_base, IOPW_RISC_CSR, ADV_RISC_CSR_RUN);
15797
15798     /*
15799      * Reset the SCSI Bus if the EEPROM indicates that SCSI Bus
15800      * Resets should be performed. The RISC has to be running
15801      * to issue a SCSI Bus Reset.
15802      */
15803     if (asc_dvc->bios_ctrl & BIOS_CTRL_RESET_SCSI_BUS)
15804     {
15805         /*
15806          * If the BIOS Signature is present in memory, restore the
15807          * BIOS Handshake Configuration Table and do not perform
15808          * a SCSI Bus Reset.
15809          */
15810         if (bios_mem[(ASC_MC_BIOS_SIGNATURE - ASC_MC_BIOSMEM)/2] == 0x55AA)
15811         {
15812             /*
15813              * Restore per TID negotiated values.
15814              */
15815             AdvWriteWordLram(iop_base, ASC_MC_WDTR_ABLE, wdtr_able);
15816             AdvWriteWordLram(iop_base, ASC_MC_SDTR_ABLE, sdtr_able);
15817             AdvWriteWordLram(iop_base, ASC_MC_TAGQNG_ABLE, tagqng_able);
15818             for (tid = 0; tid <= ADV_MAX_TID; tid++)
15819             {
15820                 AdvWriteByteLram(iop_base, ASC_MC_NUMBER_OF_MAX_CMD + tid,
15821                     max_cmd[tid]);
15822             }
15823         } else
15824         {
15825             if (AdvResetSB(asc_dvc) != ADV_TRUE)
15826             {
15827                 warn_code = ASC_WARN_BUSRESET_ERROR;
15828             }
15829         }
15830     }
15831
15832     return warn_code;
15833 }
15834
15835 /*
15836  * Initialize the ASC-38C1600.
15837  *
15838  * On failure set the ASC_DVC_VAR field 'err_code' and return ADV_ERROR.
15839  *
15840  * For a non-fatal error return a warning code. If there are no warnings
15841  * then 0 is returned.
15842  *
15843  * Needed after initialization for error recovery.
15844  */
15845 STATIC int
15846 AdvInitAsc38C1600Driver(ADV_DVC_VAR *asc_dvc)
15847 {
15848     AdvPortAddr iop_base;
15849     ushort      warn_code;
15850     ADV_DCNT    sum;
15851     int         begin_addr;
15852     int         end_addr;
15853     ushort      code_sum;
15854     long        word;
15855     int         j;
15856     int         adv_asc38C1600_expanded_size;
15857     ADV_CARR_T  *carrp;
15858     ADV_DCNT    contig_len;
15859     ADV_SDCNT   buf_size;
15860     ADV_PADDR   carr_paddr;
15861     int         i;
15862     ushort      scsi_cfg1;
15863     uchar       byte;
15864     uchar       tid;
15865     ushort      bios_mem[ASC_MC_BIOSLEN/2]; /* BIOS RISC Memory 0x40-0x8F. */
15866     ushort      wdtr_able, sdtr_able, ppr_able, tagqng_able;
15867     uchar       max_cmd[ASC_MAX_TID + 1];
15868
15869     /* If there is already an error, don't continue. */
15870     if (asc_dvc->err_code != 0)
15871     {
15872         return ADV_ERROR;
15873     }
15874
15875     /*
15876      * The caller must set 'chip_type' to ADV_CHIP_ASC38C1600.
15877      */
15878     if (asc_dvc->chip_type != ADV_CHIP_ASC38C1600)
15879     {
15880         asc_dvc->err_code = ASC_IERR_BAD_CHIPTYPE;
15881         return ADV_ERROR;
15882     }
15883
15884     warn_code = 0;
15885     iop_base = asc_dvc->iop_base;
15886
15887     /*
15888      * Save the RISC memory BIOS region before writing the microcode.
15889      * The BIOS may already be loaded and using its RISC LRAM region
15890      * so its region must be saved and restored.
15891      *
15892      * Note: This code makes the assumption, which is currently true,
15893      * that a chip reset does not clear RISC LRAM.
15894      */
15895     for (i = 0; i < ASC_MC_BIOSLEN/2; i++)
15896     {
15897         AdvReadWordLram(iop_base, ASC_MC_BIOSMEM + (2 * i), bios_mem[i]);
15898     }
15899
15900     /*
15901      * Save current per TID negotiated values.
15902      */
15903     AdvReadWordLram(iop_base, ASC_MC_WDTR_ABLE, wdtr_able);
15904     AdvReadWordLram(iop_base, ASC_MC_SDTR_ABLE, sdtr_able);
15905     AdvReadWordLram(iop_base, ASC_MC_PPR_ABLE, ppr_able);
15906     AdvReadWordLram(iop_base, ASC_MC_TAGQNG_ABLE, tagqng_able);
15907     for (tid = 0; tid <= ASC_MAX_TID; tid++)
15908     {
15909         AdvReadByteLram(iop_base, ASC_MC_NUMBER_OF_MAX_CMD + tid,
15910             max_cmd[tid]);
15911     }
15912
15913     /*
15914      * RAM BIST (Built-In Self Test)
15915      *
15916      * Address : I/O base + offset 0x38h register (byte).
15917      * Function: Bit 7-6(RW) : RAM mode
15918      *                          Normal Mode   : 0x00
15919      *                          Pre-test Mode : 0x40
15920      *                          RAM Test Mode : 0x80
15921      *           Bit 5       : unused
15922      *           Bit 4(RO)   : Done bit
15923      *           Bit 3-0(RO) : Status
15924      *                          Host Error    : 0x08
15925      *                          Int_RAM Error : 0x04
15926      *                          RISC Error    : 0x02
15927      *                          SCSI Error    : 0x01
15928      *                          No Error      : 0x00
15929      *
15930      * Note: RAM BIST code should be put right here, before loading the
15931      * microcode and after saving the RISC memory BIOS region.
15932      */
15933
15934     /*
15935      * LRAM Pre-test
15936      *
15937      * Write PRE_TEST_MODE (0x40) to register and wait for 10 milliseconds.
15938      * If Done bit not set or low nibble not PRE_TEST_VALUE (0x05), return
15939      * an error. Reset to NORMAL_MODE (0x00) and do again. If cannot reset
15940      * to NORMAL_MODE, return an error too.
15941      */
15942     for (i = 0; i < 2; i++)
15943     {
15944         AdvWriteByteRegister(iop_base, IOPB_RAM_BIST, PRE_TEST_MODE);
15945         DvcSleepMilliSecond(10);  /* Wait for 10ms before reading back. */
15946         byte = AdvReadByteRegister(iop_base, IOPB_RAM_BIST);
15947         if ((byte & RAM_TEST_DONE) == 0 || (byte & 0x0F) != PRE_TEST_VALUE)
15948         {
15949             asc_dvc->err_code |= ASC_IERR_BIST_PRE_TEST;
15950             return ADV_ERROR;
15951         }
15952
15953         AdvWriteByteRegister(iop_base, IOPB_RAM_BIST, NORMAL_MODE);
15954         DvcSleepMilliSecond(10);  /* Wait for 10ms before reading back. */
15955         if (AdvReadByteRegister(iop_base, IOPB_RAM_BIST)
15956             != NORMAL_VALUE)
15957         {
15958             asc_dvc->err_code |= ASC_IERR_BIST_PRE_TEST;
15959             return ADV_ERROR;
15960         }
15961     }
15962
15963     /*
15964      * LRAM Test - It takes about 1.5 ms to run through the test.
15965      *
15966      * Write RAM_TEST_MODE (0x80) to register and wait for 10 milliseconds.
15967      * If Done bit not set or Status not 0, save register byte, set the
15968      * err_code, and return an error.
15969      */
15970     AdvWriteByteRegister(iop_base, IOPB_RAM_BIST, RAM_TEST_MODE);
15971     DvcSleepMilliSecond(10);  /* Wait for 10ms before checking status. */
15972
15973     byte = AdvReadByteRegister(iop_base, IOPB_RAM_BIST);
15974     if ((byte & RAM_TEST_DONE) == 0 || (byte & RAM_TEST_STATUS) != 0)
15975     {
15976         /* Get here if Done bit not set or Status not 0. */
15977         asc_dvc->bist_err_code = byte;  /* for BIOS display message */
15978         asc_dvc->err_code |= ASC_IERR_BIST_RAM_TEST;
15979         return ADV_ERROR;
15980     }
15981
15982     /* We need to reset back to normal mode after LRAM test passes. */
15983     AdvWriteByteRegister(iop_base, IOPB_RAM_BIST, NORMAL_MODE);
15984
15985     /*
15986      * Load the Microcode
15987      *
15988      * Write the microcode image to RISC memory starting at address 0.
15989      *
15990      */
15991     AdvWriteWordRegister(iop_base, IOPW_RAM_ADDR, 0);
15992
15993     /*
15994      * Assume the following compressed format of the microcode buffer:
15995      *
15996      *  254 word (508 byte) table indexed by byte code followed
15997      *  by the following byte codes:
15998      *
15999      *    1-Byte Code:
16000      *      00: Emit word 0 in table.
16001      *      01: Emit word 1 in table.
16002      *      .
16003      *      FD: Emit word 253 in table.
16004      *
16005      *    Multi-Byte Code:
16006      *      FE WW WW: (3 byte code) Word to emit is the next word WW WW.
16007      *      FF BB WW WW: (4 byte code) Emit BB count times next word WW WW.
16008      */
16009     word = 0;
16010     for (i = 253 * 2; i < _adv_asc38C1600_size; i++)
16011     {
16012         if (_adv_asc38C1600_buf[i] == 0xff)
16013         {
16014             for (j = 0; j < _adv_asc38C1600_buf[i + 1]; j++)
16015             {
16016                 AdvWriteWordAutoIncLram(iop_base, (((ushort)
16017                      _adv_asc38C1600_buf[i + 3] << 8) |
16018                      _adv_asc38C1600_buf[i + 2]));
16019                 word++;
16020             }
16021            i += 3;
16022         } else if (_adv_asc38C1600_buf[i] == 0xfe)
16023         {
16024                 AdvWriteWordAutoIncLram(iop_base, (((ushort)
16025                      _adv_asc38C1600_buf[i + 2] << 8) |
16026                      _adv_asc38C1600_buf[i + 1]));
16027             i += 2;
16028             word++;
16029         } else
16030         {
16031             AdvWriteWordAutoIncLram(iop_base, (((ushort)
16032                  _adv_asc38C1600_buf[(_adv_asc38C1600_buf[i] * 2) + 1] << 8) |
16033                  _adv_asc38C1600_buf[_adv_asc38C1600_buf[i] * 2]));
16034             word++;
16035         }
16036     }
16037
16038     /*
16039      * Set 'word' for later use to clear the rest of memory and save
16040      * the expanded mcode size.
16041      */
16042     word *= 2;
16043     adv_asc38C1600_expanded_size = word;
16044
16045     /*
16046      * Clear the rest of ASC-38C1600 Internal RAM (32KB).
16047      */
16048     for (; word < ADV_38C1600_MEMSIZE; word += 2)
16049     {
16050         AdvWriteWordAutoIncLram(iop_base, 0);
16051     }
16052
16053     /*
16054      * Verify the microcode checksum.
16055      */
16056     sum = 0;
16057     AdvWriteWordRegister(iop_base, IOPW_RAM_ADDR, 0);
16058
16059     for (word = 0; word < adv_asc38C1600_expanded_size; word += 2)
16060     {
16061         sum += AdvReadWordAutoIncLram(iop_base);
16062     }
16063
16064     if (sum != _adv_asc38C1600_chksum)
16065     {
16066         asc_dvc->err_code |= ASC_IERR_MCODE_CHKSUM;
16067         return ADV_ERROR;
16068     }
16069
16070     /*
16071      * Restore the RISC memory BIOS region.
16072      */
16073     for (i = 0; i < ASC_MC_BIOSLEN/2; i++)
16074     {
16075         AdvWriteWordLram(iop_base, ASC_MC_BIOSMEM + (2 * i), bios_mem[i]);
16076     }
16077
16078     /*
16079      * Calculate and write the microcode code checksum to the microcode
16080      * code checksum location ASC_MC_CODE_CHK_SUM (0x2C).
16081      */
16082     AdvReadWordLram(iop_base, ASC_MC_CODE_BEGIN_ADDR, begin_addr);
16083     AdvReadWordLram(iop_base, ASC_MC_CODE_END_ADDR, end_addr);
16084     code_sum = 0;
16085     AdvWriteWordRegister(iop_base, IOPW_RAM_ADDR, begin_addr);
16086     for (word = begin_addr; word < end_addr; word += 2)
16087     {
16088         code_sum += AdvReadWordAutoIncLram(iop_base);
16089     }
16090     AdvWriteWordLram(iop_base, ASC_MC_CODE_CHK_SUM, code_sum);
16091
16092     /*
16093      * Read microcode version and date.
16094      */
16095     AdvReadWordLram(iop_base, ASC_MC_VERSION_DATE, asc_dvc->cfg->mcode_date);
16096     AdvReadWordLram(iop_base, ASC_MC_VERSION_NUM, asc_dvc->cfg->mcode_version);
16097
16098     /*
16099      * Set the chip type to indicate the ASC38C1600.
16100      */
16101     AdvWriteWordLram(iop_base, ASC_MC_CHIP_TYPE, ADV_CHIP_ASC38C1600);
16102
16103     /*
16104      * Write 1 to bit 14 'DIS_TERM_DRV' in the SCSI_CFG1 register.
16105      * When DIS_TERM_DRV set to 1, C_DET[3:0] will reflect current
16106      * cable detection and then we are able to read C_DET[3:0].
16107      *
16108      * Note: We will reset DIS_TERM_DRV to 0 in the 'Set SCSI_CFG1
16109      * Microcode Default Value' section below.
16110      */
16111     scsi_cfg1 = AdvReadWordRegister(iop_base, IOPW_SCSI_CFG1);
16112     AdvWriteWordRegister(iop_base, IOPW_SCSI_CFG1, scsi_cfg1 | DIS_TERM_DRV);
16113
16114     /*
16115      * If the PCI Configuration Command Register "Parity Error Response
16116      * Control" Bit was clear (0), then set the microcode variable
16117      * 'control_flag' CONTROL_FLAG_IGNORE_PERR flag to tell the microcode
16118      * to ignore DMA parity errors.
16119      */
16120     if (asc_dvc->cfg->control_flag & CONTROL_FLAG_IGNORE_PERR)
16121     {
16122         AdvReadWordLram(iop_base, ASC_MC_CONTROL_FLAG, word);
16123         word |= CONTROL_FLAG_IGNORE_PERR;
16124         AdvWriteWordLram(iop_base, ASC_MC_CONTROL_FLAG, word);
16125     }
16126
16127     /*
16128      * If the BIOS control flag AIPP (Asynchronous Information
16129      * Phase Protection) disable bit is not set, then set the firmware
16130      * 'control_flag' CONTROL_FLAG_ENABLE_AIPP bit to enable
16131      * AIPP checking and encoding.
16132      */
16133     if ((asc_dvc->bios_ctrl & BIOS_CTRL_AIPP_DIS) == 0)
16134     {
16135         AdvReadWordLram(iop_base, ASC_MC_CONTROL_FLAG, word);
16136         word |= CONTROL_FLAG_ENABLE_AIPP;
16137         AdvWriteWordLram(iop_base, ASC_MC_CONTROL_FLAG, word);
16138     }
16139
16140     /*
16141      * For ASC-38C1600 use DMA_CFG0 default values: FIFO_THRESH_80B [6:4],
16142      * and START_CTL_TH [3:2].
16143      */
16144     AdvWriteByteRegister(iop_base, IOPB_DMA_CFG0,
16145         FIFO_THRESH_80B | START_CTL_TH | READ_CMD_MRM);
16146
16147     /*
16148      * Microcode operating variables for WDTR, SDTR, and command tag
16149      * queuing will be set in AdvInquiryHandling() based on what a
16150      * device reports it is capable of in Inquiry byte 7.
16151      *
16152      * If SCSI Bus Resets have been disabled, then directly set
16153      * SDTR and WDTR from the EEPROM configuration. This will allow
16154      * the BIOS and warm boot to work without a SCSI bus hang on
16155      * the Inquiry caused by host and target mismatched DTR values.
16156      * Without the SCSI Bus Reset, before an Inquiry a device can't
16157      * be assumed to be in Asynchronous, Narrow mode.
16158      */
16159     if ((asc_dvc->bios_ctrl & BIOS_CTRL_RESET_SCSI_BUS) == 0)
16160     {
16161         AdvWriteWordLram(iop_base, ASC_MC_WDTR_ABLE, asc_dvc->wdtr_able);
16162         AdvWriteWordLram(iop_base, ASC_MC_SDTR_ABLE, asc_dvc->sdtr_able);
16163     }
16164
16165     /*
16166      * Set microcode operating variables for DISC and SDTR_SPEED1,
16167      * SDTR_SPEED2, SDTR_SPEED3, and SDTR_SPEED4 based on the EEPROM
16168      * configuration values.
16169      *
16170      * The SDTR per TID bitmask overrides the SDTR_SPEED1, SDTR_SPEED2,
16171      * SDTR_SPEED3, and SDTR_SPEED4 values so it is safe to set them
16172      * without determining here whether the device supports SDTR.
16173      */
16174     AdvWriteWordLram(iop_base, ASC_MC_DISC_ENABLE, asc_dvc->cfg->disc_enable);
16175     AdvWriteWordLram(iop_base, ASC_MC_SDTR_SPEED1, asc_dvc->sdtr_speed1);
16176     AdvWriteWordLram(iop_base, ASC_MC_SDTR_SPEED2, asc_dvc->sdtr_speed2);
16177     AdvWriteWordLram(iop_base, ASC_MC_SDTR_SPEED3, asc_dvc->sdtr_speed3);
16178     AdvWriteWordLram(iop_base, ASC_MC_SDTR_SPEED4, asc_dvc->sdtr_speed4);
16179
16180     /*
16181      * Set SCSI_CFG0 Microcode Default Value.
16182      *
16183      * The microcode will set the SCSI_CFG0 register using this value
16184      * after it is started below.
16185      */
16186     AdvWriteWordLram(iop_base, ASC_MC_DEFAULT_SCSI_CFG0,
16187         PARITY_EN | QUEUE_128 | SEL_TMO_LONG | OUR_ID_EN |
16188         asc_dvc->chip_scsi_id);
16189
16190     /*
16191      * Calculate SCSI_CFG1 Microcode Default Value.
16192      *
16193      * The microcode will set the SCSI_CFG1 register using this value
16194      * after it is started below.
16195      *
16196      * Each ASC-38C1600 function has only two cable detect bits.
16197      * The bus mode override bits are in IOPB_SOFT_OVER_WR.
16198      */
16199     scsi_cfg1 = AdvReadWordRegister(iop_base, IOPW_SCSI_CFG1);
16200
16201     /*
16202      * If the cable is reversed all of the SCSI_CTRL register signals
16203      * will be set. Check for and return an error if this condition is
16204      * found.
16205      */
16206     if ((AdvReadWordRegister(iop_base, IOPW_SCSI_CTRL) & 0x3F07) == 0x3F07)
16207     {
16208         asc_dvc->err_code |= ASC_IERR_REVERSED_CABLE;
16209         return ADV_ERROR;
16210     }
16211
16212     /*
16213      * Each ASC-38C1600 function has two connectors. Only an HVD device
16214      * can not be connected to either connector. An LVD device or SE device
16215      * may be connected to either connecor. If an SE device is connected,
16216      * then at most Ultra speed (20 Mhz) can be used on both connectors.
16217      *
16218      * If an HVD device is attached, return an error.
16219      */
16220     if (scsi_cfg1 & HVD)
16221     {
16222         asc_dvc->err_code |= ASC_IERR_HVD_DEVICE;
16223         return ADV_ERROR;
16224     }
16225
16226     /*
16227      * Each function in the ASC-38C1600 uses only the SE cable detect and
16228      * termination because there are two connectors for each function. Each
16229      * function may use either LVD or SE mode. Corresponding the SE automatic
16230      * termination control EEPROM bits are used for each function. Each
16231      * function has its own EEPROM. If SE automatic control is enabled for
16232      * the function, then set the termination value based on a table listed
16233      * in a_condor.h.
16234      *
16235      * If manual termination is specified in the EEPROM for the function,
16236      * then 'termination' was set-up in AscInitFrom38C1600EEPROM() and is
16237      * ready to be 'ored' into SCSI_CFG1.
16238      */
16239     if ((asc_dvc->cfg->termination & TERM_SE) == 0)
16240     {
16241         /* SE automatic termination control is enabled. */
16242         switch(scsi_cfg1 & C_DET_SE)
16243         {
16244             /* TERM_SE_HI: on, TERM_SE_LO: on */
16245             case 0x1: case 0x2: case 0x3:
16246                 asc_dvc->cfg->termination |= TERM_SE;
16247                 break;
16248
16249             case 0x0:
16250                 if (ASC_PCI_ID2FUNC(asc_dvc->cfg->pci_slot_info) == 0)
16251                 {
16252                     /* Function 0 - TERM_SE_HI: off, TERM_SE_LO: off */
16253                 }
16254                 else
16255                 {
16256                     /* Function 1 - TERM_SE_HI: on, TERM_SE_LO: off */
16257                     asc_dvc->cfg->termination |= TERM_SE_HI;
16258                 }
16259                 break;
16260         }
16261     }
16262
16263     /*
16264      * Clear any set TERM_SE bits.
16265      */
16266     scsi_cfg1 &= ~TERM_SE;
16267
16268     /*
16269      * Invert the TERM_SE bits and then set 'scsi_cfg1'.
16270      */
16271     scsi_cfg1 |= (~asc_dvc->cfg->termination & TERM_SE);
16272
16273     /*
16274      * Clear Big Endian and Terminator Polarity bits and set possibly
16275      * modified termination control bits in the Microcode SCSI_CFG1
16276      * Register Value.
16277      *
16278      * Big Endian bit is not used even on big endian machines.
16279      */
16280     scsi_cfg1 &= (~BIG_ENDIAN & ~DIS_TERM_DRV & ~TERM_POL);
16281
16282     /*
16283      * Set SCSI_CFG1 Microcode Default Value
16284      *
16285      * Set possibly modified termination control bits in the Microcode
16286      * SCSI_CFG1 Register Value.
16287      *
16288      * The microcode will set the SCSI_CFG1 register using this value
16289      * after it is started below.
16290      */
16291     AdvWriteWordLram(iop_base, ASC_MC_DEFAULT_SCSI_CFG1, scsi_cfg1);
16292
16293     /*
16294      * Set MEM_CFG Microcode Default Value
16295      *
16296      * The microcode will set the MEM_CFG register using this value
16297      * after it is started below.
16298      *
16299      * MEM_CFG may be accessed as a word or byte, but only bits 0-7
16300      * are defined.
16301      *
16302      * ASC-38C1600 has 32KB internal memory.
16303      *
16304      * XXX - Since ASC38C1600 Rev.3 has a Local RAM failure issue, we come
16305      * out a special 16K Adv Library and Microcode version. After the issue
16306      * resolved, we should turn back to the 32K support. Both a_condor.h and
16307      * mcode.sas files also need to be updated.
16308      *
16309      * AdvWriteWordLram(iop_base, ASC_MC_DEFAULT_MEM_CFG,
16310      *  BIOS_EN | RAM_SZ_32KB);
16311      */
16312      AdvWriteWordLram(iop_base, ASC_MC_DEFAULT_MEM_CFG, BIOS_EN | RAM_SZ_16KB);
16313
16314     /*
16315      * Set SEL_MASK Microcode Default Value
16316      *
16317      * The microcode will set the SEL_MASK register using this value
16318      * after it is started below.
16319      */
16320     AdvWriteWordLram(iop_base, ASC_MC_DEFAULT_SEL_MASK,
16321         ADV_TID_TO_TIDMASK(asc_dvc->chip_scsi_id));
16322
16323     /*
16324      * Build the carrier freelist.
16325      *
16326      * Driver must have already allocated memory and set 'carrier_buf'.
16327      */
16328
16329     ASC_ASSERT(asc_dvc->carrier_buf != NULL);
16330
16331     carrp = (ADV_CARR_T *) ADV_16BALIGN(asc_dvc->carrier_buf);
16332     asc_dvc->carr_freelist = NULL;
16333     if (carrp == (ADV_CARR_T *) asc_dvc->carrier_buf)
16334     {
16335         buf_size = ADV_CARRIER_BUFSIZE;
16336     } else
16337     {
16338         buf_size = ADV_CARRIER_BUFSIZE - sizeof(ADV_CARR_T);
16339     }
16340
16341     do {
16342         /*
16343          * Get physical address for the carrier 'carrp'.
16344          */
16345         contig_len = sizeof(ADV_CARR_T);
16346         carr_paddr = cpu_to_le32(DvcGetPhyAddr(asc_dvc, NULL, (uchar *) carrp,
16347             (ADV_SDCNT *) &contig_len, ADV_IS_CARRIER_FLAG));
16348
16349         buf_size -= sizeof(ADV_CARR_T);
16350
16351         /*
16352          * If the current carrier is not physically contiguous, then
16353          * maybe there was a page crossing. Try the next carrier aligned
16354          * start address.
16355          */
16356         if (contig_len < sizeof(ADV_CARR_T))
16357         {
16358             carrp++;
16359             continue;
16360         }
16361
16362         carrp->carr_pa = carr_paddr;
16363         carrp->carr_va = cpu_to_le32(ADV_VADDR_TO_U32(carrp));
16364
16365         /*
16366          * Insert the carrier at the beginning of the freelist.
16367          */
16368         carrp->next_vpa = cpu_to_le32(ADV_VADDR_TO_U32(asc_dvc->carr_freelist));
16369         asc_dvc->carr_freelist = carrp;
16370
16371         carrp++;
16372     }
16373     while (buf_size > 0);
16374
16375     /*
16376      * Set-up the Host->RISC Initiator Command Queue (ICQ).
16377      */
16378     if ((asc_dvc->icq_sp = asc_dvc->carr_freelist) == NULL)
16379     {
16380         asc_dvc->err_code |= ASC_IERR_NO_CARRIER;
16381         return ADV_ERROR;
16382     }
16383     asc_dvc->carr_freelist = (ADV_CARR_T *)
16384         ADV_U32_TO_VADDR(le32_to_cpu(asc_dvc->icq_sp->next_vpa));
16385
16386     /*
16387      * The first command issued will be placed in the stopper carrier.
16388      */
16389     asc_dvc->icq_sp->next_vpa = cpu_to_le32(ASC_CQ_STOPPER);
16390
16391     /*
16392      * Set RISC ICQ physical address start value. Initialize the
16393      * COMMA register to the same value otherwise the RISC will
16394      * prematurely detect a command is available.
16395      */
16396     AdvWriteDWordLramNoSwap(iop_base, ASC_MC_ICQ, asc_dvc->icq_sp->carr_pa);
16397     AdvWriteDWordRegister(iop_base, IOPDW_COMMA,
16398         le32_to_cpu(asc_dvc->icq_sp->carr_pa));
16399
16400     /*
16401      * Set-up the RISC->Host Initiator Response Queue (IRQ).
16402      */
16403     if ((asc_dvc->irq_sp = asc_dvc->carr_freelist) == NULL)
16404     {
16405         asc_dvc->err_code |= ASC_IERR_NO_CARRIER;
16406         return ADV_ERROR;
16407     }
16408     asc_dvc->carr_freelist = (ADV_CARR_T *)
16409         ADV_U32_TO_VADDR(le32_to_cpu(asc_dvc->irq_sp->next_vpa));
16410
16411     /*
16412      * The first command completed by the RISC will be placed in
16413      * the stopper.
16414      *
16415      * Note: Set 'next_vpa' to ASC_CQ_STOPPER. When the request is
16416      * completed the RISC will set the ASC_RQ_STOPPER bit.
16417      */
16418     asc_dvc->irq_sp->next_vpa = cpu_to_le32(ASC_CQ_STOPPER);
16419
16420     /*
16421      * Set RISC IRQ physical address start value.
16422      */
16423     AdvWriteDWordLramNoSwap(iop_base, ASC_MC_IRQ, asc_dvc->irq_sp->carr_pa);
16424     asc_dvc->carr_pending_cnt = 0;
16425
16426     AdvWriteByteRegister(iop_base, IOPB_INTR_ENABLES,
16427         (ADV_INTR_ENABLE_HOST_INTR | ADV_INTR_ENABLE_GLOBAL_INTR));
16428     AdvReadWordLram(iop_base, ASC_MC_CODE_BEGIN_ADDR, word);
16429     AdvWriteWordRegister(iop_base, IOPW_PC, word);
16430
16431     /* finally, finally, gentlemen, start your engine */
16432     AdvWriteWordRegister(iop_base, IOPW_RISC_CSR, ADV_RISC_CSR_RUN);
16433
16434     /*
16435      * Reset the SCSI Bus if the EEPROM indicates that SCSI Bus
16436      * Resets should be performed. The RISC has to be running
16437      * to issue a SCSI Bus Reset.
16438      */
16439     if (asc_dvc->bios_ctrl & BIOS_CTRL_RESET_SCSI_BUS)
16440     {
16441         /*
16442          * If the BIOS Signature is present in memory, restore the
16443          * per TID microcode operating variables.
16444          */
16445         if (bios_mem[(ASC_MC_BIOS_SIGNATURE - ASC_MC_BIOSMEM)/2] == 0x55AA)
16446         {
16447             /*
16448              * Restore per TID negotiated values.
16449              */
16450             AdvWriteWordLram(iop_base, ASC_MC_WDTR_ABLE, wdtr_able);
16451             AdvWriteWordLram(iop_base, ASC_MC_SDTR_ABLE, sdtr_able);
16452             AdvWriteWordLram(iop_base, ASC_MC_PPR_ABLE, ppr_able);
16453             AdvWriteWordLram(iop_base, ASC_MC_TAGQNG_ABLE, tagqng_able);
16454             for (tid = 0; tid <= ASC_MAX_TID; tid++)
16455             {
16456                 AdvWriteByteLram(iop_base, ASC_MC_NUMBER_OF_MAX_CMD + tid,
16457                     max_cmd[tid]);
16458             }
16459         } else
16460         {
16461             if (AdvResetSB(asc_dvc) != ADV_TRUE)
16462             {
16463                 warn_code = ASC_WARN_BUSRESET_ERROR;
16464             }
16465         }
16466     }
16467
16468     return warn_code;
16469 }
16470
16471 /*
16472  * Read the board's EEPROM configuration. Set fields in ADV_DVC_VAR and
16473  * ADV_DVC_CFG based on the EEPROM settings. The chip is stopped while
16474  * all of this is done.
16475  *
16476  * On failure set the ADV_DVC_VAR field 'err_code' and return ADV_ERROR.
16477  *
16478  * For a non-fatal error return a warning code. If there are no warnings
16479  * then 0 is returned.
16480  *
16481  * Note: Chip is stopped on entry.
16482  */
16483 STATIC int __init
16484 AdvInitFrom3550EEP(ADV_DVC_VAR *asc_dvc)
16485 {
16486     AdvPortAddr         iop_base;
16487     ushort              warn_code;
16488     ADVEEP_3550_CONFIG  eep_config;
16489     int                 i;
16490
16491     iop_base = asc_dvc->iop_base;
16492
16493     warn_code = 0;
16494
16495     /*
16496      * Read the board's EEPROM configuration.
16497      *
16498      * Set default values if a bad checksum is found.
16499      */
16500     if (AdvGet3550EEPConfig(iop_base, &eep_config) != eep_config.check_sum)
16501     {
16502         warn_code |= ASC_WARN_EEPROM_CHKSUM;
16503
16504         /*
16505          * Set EEPROM default values.
16506          */
16507         for (i = 0; i < sizeof(ADVEEP_3550_CONFIG); i++)
16508         {
16509             *((uchar *) &eep_config + i) =
16510                 *((uchar *) &Default_3550_EEPROM_Config + i);
16511         }
16512
16513         /*
16514          * Assume the 6 byte board serial number that was read
16515          * from EEPROM is correct even if the EEPROM checksum
16516          * failed.
16517          */
16518         eep_config.serial_number_word3 =
16519             AdvReadEEPWord(iop_base, ADV_EEP_DVC_CFG_END - 1);
16520
16521         eep_config.serial_number_word2 =
16522             AdvReadEEPWord(iop_base, ADV_EEP_DVC_CFG_END - 2);
16523
16524         eep_config.serial_number_word1 =
16525             AdvReadEEPWord(iop_base, ADV_EEP_DVC_CFG_END - 3);
16526
16527         AdvSet3550EEPConfig(iop_base, &eep_config);
16528     }
16529     /*
16530      * Set ASC_DVC_VAR and ASC_DVC_CFG variables from the
16531      * EEPROM configuration that was read.
16532      *
16533      * This is the mapping of EEPROM fields to Adv Library fields.
16534      */
16535     asc_dvc->wdtr_able = eep_config.wdtr_able;
16536     asc_dvc->sdtr_able = eep_config.sdtr_able;
16537     asc_dvc->ultra_able = eep_config.ultra_able;
16538     asc_dvc->tagqng_able = eep_config.tagqng_able;
16539     asc_dvc->cfg->disc_enable = eep_config.disc_enable;
16540     asc_dvc->max_host_qng = eep_config.max_host_qng;
16541     asc_dvc->max_dvc_qng = eep_config.max_dvc_qng;
16542     asc_dvc->chip_scsi_id = (eep_config.adapter_scsi_id & ADV_MAX_TID);
16543     asc_dvc->start_motor = eep_config.start_motor;
16544     asc_dvc->scsi_reset_wait = eep_config.scsi_reset_delay;
16545     asc_dvc->bios_ctrl = eep_config.bios_ctrl;
16546     asc_dvc->no_scam = eep_config.scam_tolerant;
16547     asc_dvc->cfg->serial1 = eep_config.serial_number_word1;
16548     asc_dvc->cfg->serial2 = eep_config.serial_number_word2;
16549     asc_dvc->cfg->serial3 = eep_config.serial_number_word3;
16550
16551     /*
16552      * Set the host maximum queuing (max. 253, min. 16) and the per device
16553      * maximum queuing (max. 63, min. 4).
16554      */
16555     if (eep_config.max_host_qng > ASC_DEF_MAX_HOST_QNG)
16556     {
16557         eep_config.max_host_qng = ASC_DEF_MAX_HOST_QNG;
16558     } else if (eep_config.max_host_qng < ASC_DEF_MIN_HOST_QNG)
16559     {
16560         /* If the value is zero, assume it is uninitialized. */
16561         if (eep_config.max_host_qng == 0)
16562         {
16563             eep_config.max_host_qng = ASC_DEF_MAX_HOST_QNG;
16564         } else
16565         {
16566             eep_config.max_host_qng = ASC_DEF_MIN_HOST_QNG;
16567         }
16568     }
16569
16570     if (eep_config.max_dvc_qng > ASC_DEF_MAX_DVC_QNG)
16571     {
16572         eep_config.max_dvc_qng = ASC_DEF_MAX_DVC_QNG;
16573     } else if (eep_config.max_dvc_qng < ASC_DEF_MIN_DVC_QNG)
16574     {
16575         /* If the value is zero, assume it is uninitialized. */
16576         if (eep_config.max_dvc_qng == 0)
16577         {
16578             eep_config.max_dvc_qng = ASC_DEF_MAX_DVC_QNG;
16579         } else
16580         {
16581             eep_config.max_dvc_qng = ASC_DEF_MIN_DVC_QNG;
16582         }
16583     }
16584
16585     /*
16586      * If 'max_dvc_qng' is greater than 'max_host_qng', then
16587      * set 'max_dvc_qng' to 'max_host_qng'.
16588      */
16589     if (eep_config.max_dvc_qng > eep_config.max_host_qng)
16590     {
16591         eep_config.max_dvc_qng = eep_config.max_host_qng;
16592     }
16593
16594     /*
16595      * Set ADV_DVC_VAR 'max_host_qng' and ADV_DVC_VAR 'max_dvc_qng'
16596      * values based on possibly adjusted EEPROM values.
16597      */
16598     asc_dvc->max_host_qng = eep_config.max_host_qng;
16599     asc_dvc->max_dvc_qng = eep_config.max_dvc_qng;
16600
16601
16602     /*
16603      * If the EEPROM 'termination' field is set to automatic (0), then set
16604      * the ADV_DVC_CFG 'termination' field to automatic also.
16605      *
16606      * If the termination is specified with a non-zero 'termination'
16607      * value check that a legal value is set and set the ADV_DVC_CFG
16608      * 'termination' field appropriately.
16609      */
16610     if (eep_config.termination == 0)
16611     {
16612         asc_dvc->cfg->termination = 0;    /* auto termination */
16613     } else
16614     {
16615         /* Enable manual control with low off / high off. */
16616         if (eep_config.termination == 1)
16617         {
16618             asc_dvc->cfg->termination = TERM_CTL_SEL;
16619
16620         /* Enable manual control with low off / high on. */
16621         } else if (eep_config.termination == 2)
16622         {
16623             asc_dvc->cfg->termination = TERM_CTL_SEL | TERM_CTL_H;
16624
16625         /* Enable manual control with low on / high on. */
16626         } else if (eep_config.termination == 3)
16627         {
16628             asc_dvc->cfg->termination = TERM_CTL_SEL | TERM_CTL_H | TERM_CTL_L;
16629         } else
16630         {
16631             /*
16632              * The EEPROM 'termination' field contains a bad value. Use
16633              * automatic termination instead.
16634              */
16635             asc_dvc->cfg->termination = 0;
16636             warn_code |= ASC_WARN_EEPROM_TERMINATION;
16637         }
16638     }
16639
16640     return warn_code;
16641 }
16642
16643 /*
16644  * Read the board's EEPROM configuration. Set fields in ADV_DVC_VAR and
16645  * ADV_DVC_CFG based on the EEPROM settings. The chip is stopped while
16646  * all of this is done.
16647  *
16648  * On failure set the ADV_DVC_VAR field 'err_code' and return ADV_ERROR.
16649  *
16650  * For a non-fatal error return a warning code. If there are no warnings
16651  * then 0 is returned.
16652  *
16653  * Note: Chip is stopped on entry.
16654  */
16655 STATIC int __init
16656 AdvInitFrom38C0800EEP(ADV_DVC_VAR *asc_dvc)
16657 {
16658     AdvPortAddr              iop_base;
16659     ushort                   warn_code;
16660     ADVEEP_38C0800_CONFIG    eep_config;
16661     int                      i;
16662     uchar                    tid, termination;
16663     ushort                   sdtr_speed = 0;
16664
16665     iop_base = asc_dvc->iop_base;
16666
16667     warn_code = 0;
16668
16669     /*
16670      * Read the board's EEPROM configuration.
16671      *
16672      * Set default values if a bad checksum is found.
16673      */
16674     if (AdvGet38C0800EEPConfig(iop_base, &eep_config) != eep_config.check_sum)
16675     {
16676         warn_code |= ASC_WARN_EEPROM_CHKSUM;
16677
16678         /*
16679          * Set EEPROM default values.
16680          */
16681         for (i = 0; i < sizeof(ADVEEP_38C0800_CONFIG); i++)
16682         {
16683             *((uchar *) &eep_config + i) =
16684                 *((uchar *) &Default_38C0800_EEPROM_Config + i);
16685         }
16686
16687         /*
16688          * Assume the 6 byte board serial number that was read
16689          * from EEPROM is correct even if the EEPROM checksum
16690          * failed.
16691          */
16692         eep_config.serial_number_word3 =
16693             AdvReadEEPWord(iop_base, ADV_EEP_DVC_CFG_END - 1);
16694
16695         eep_config.serial_number_word2 =
16696             AdvReadEEPWord(iop_base, ADV_EEP_DVC_CFG_END - 2);
16697
16698         eep_config.serial_number_word1 =
16699             AdvReadEEPWord(iop_base, ADV_EEP_DVC_CFG_END - 3);
16700
16701         AdvSet38C0800EEPConfig(iop_base, &eep_config);
16702     }
16703     /*
16704      * Set ADV_DVC_VAR and ADV_DVC_CFG variables from the
16705      * EEPROM configuration that was read.
16706      *
16707      * This is the mapping of EEPROM fields to Adv Library fields.
16708      */
16709     asc_dvc->wdtr_able = eep_config.wdtr_able;
16710     asc_dvc->sdtr_speed1 = eep_config.sdtr_speed1;
16711     asc_dvc->sdtr_speed2 = eep_config.sdtr_speed2;
16712     asc_dvc->sdtr_speed3 = eep_config.sdtr_speed3;
16713     asc_dvc->sdtr_speed4 = eep_config.sdtr_speed4;
16714     asc_dvc->tagqng_able = eep_config.tagqng_able;
16715     asc_dvc->cfg->disc_enable = eep_config.disc_enable;
16716     asc_dvc->max_host_qng = eep_config.max_host_qng;
16717     asc_dvc->max_dvc_qng = eep_config.max_dvc_qng;
16718     asc_dvc->chip_scsi_id = (eep_config.adapter_scsi_id & ADV_MAX_TID);
16719     asc_dvc->start_motor = eep_config.start_motor;
16720     asc_dvc->scsi_reset_wait = eep_config.scsi_reset_delay;
16721     asc_dvc->bios_ctrl = eep_config.bios_ctrl;
16722     asc_dvc->no_scam = eep_config.scam_tolerant;
16723     asc_dvc->cfg->serial1 = eep_config.serial_number_word1;
16724     asc_dvc->cfg->serial2 = eep_config.serial_number_word2;
16725     asc_dvc->cfg->serial3 = eep_config.serial_number_word3;
16726
16727     /*
16728      * For every Target ID if any of its 'sdtr_speed[1234]' bits
16729      * are set, then set an 'sdtr_able' bit for it.
16730      */
16731     asc_dvc->sdtr_able = 0;
16732     for (tid = 0; tid <= ADV_MAX_TID; tid++)
16733     {
16734         if (tid == 0)
16735         {
16736             sdtr_speed = asc_dvc->sdtr_speed1;
16737         } else if (tid == 4)
16738         {
16739             sdtr_speed = asc_dvc->sdtr_speed2;
16740         } else if (tid == 8)
16741         {
16742             sdtr_speed = asc_dvc->sdtr_speed3;
16743         } else if (tid == 12)
16744         {
16745             sdtr_speed = asc_dvc->sdtr_speed4;
16746         }
16747         if (sdtr_speed & ADV_MAX_TID)
16748         {
16749             asc_dvc->sdtr_able |= (1 << tid);
16750         }
16751         sdtr_speed >>= 4;
16752     }
16753
16754     /*
16755      * Set the host maximum queuing (max. 253, min. 16) and the per device
16756      * maximum queuing (max. 63, min. 4).
16757      */
16758     if (eep_config.max_host_qng > ASC_DEF_MAX_HOST_QNG)
16759     {
16760         eep_config.max_host_qng = ASC_DEF_MAX_HOST_QNG;
16761     } else if (eep_config.max_host_qng < ASC_DEF_MIN_HOST_QNG)
16762     {
16763         /* If the value is zero, assume it is uninitialized. */
16764         if (eep_config.max_host_qng == 0)
16765         {
16766             eep_config.max_host_qng = ASC_DEF_MAX_HOST_QNG;
16767         } else
16768         {
16769             eep_config.max_host_qng = ASC_DEF_MIN_HOST_QNG;
16770         }
16771     }
16772
16773     if (eep_config.max_dvc_qng > ASC_DEF_MAX_DVC_QNG)
16774     {
16775         eep_config.max_dvc_qng = ASC_DEF_MAX_DVC_QNG;
16776     } else if (eep_config.max_dvc_qng < ASC_DEF_MIN_DVC_QNG)
16777     {
16778         /* If the value is zero, assume it is uninitialized. */
16779         if (eep_config.max_dvc_qng == 0)
16780         {
16781             eep_config.max_dvc_qng = ASC_DEF_MAX_DVC_QNG;
16782         } else
16783         {
16784             eep_config.max_dvc_qng = ASC_DEF_MIN_DVC_QNG;
16785         }
16786     }
16787
16788     /*
16789      * If 'max_dvc_qng' is greater than 'max_host_qng', then
16790      * set 'max_dvc_qng' to 'max_host_qng'.
16791      */
16792     if (eep_config.max_dvc_qng > eep_config.max_host_qng)
16793     {
16794         eep_config.max_dvc_qng = eep_config.max_host_qng;
16795     }
16796
16797     /*
16798      * Set ADV_DVC_VAR 'max_host_qng' and ADV_DVC_VAR 'max_dvc_qng'
16799      * values based on possibly adjusted EEPROM values.
16800      */
16801     asc_dvc->max_host_qng = eep_config.max_host_qng;
16802     asc_dvc->max_dvc_qng = eep_config.max_dvc_qng;
16803
16804     /*
16805      * If the EEPROM 'termination' field is set to automatic (0), then set
16806      * the ADV_DVC_CFG 'termination' field to automatic also.
16807      *
16808      * If the termination is specified with a non-zero 'termination'
16809      * value check that a legal value is set and set the ADV_DVC_CFG
16810      * 'termination' field appropriately.
16811      */
16812     if (eep_config.termination_se == 0)
16813     {
16814         termination = 0;                         /* auto termination for SE */
16815     } else
16816     {
16817         /* Enable manual control with low off / high off. */
16818         if (eep_config.termination_se == 1)
16819         {
16820             termination = 0;
16821
16822         /* Enable manual control with low off / high on. */
16823         } else if (eep_config.termination_se == 2)
16824         {
16825             termination = TERM_SE_HI;
16826
16827         /* Enable manual control with low on / high on. */
16828         } else if (eep_config.termination_se == 3)
16829         {
16830             termination = TERM_SE;
16831         } else
16832         {
16833             /*
16834              * The EEPROM 'termination_se' field contains a bad value.
16835              * Use automatic termination instead.
16836              */
16837             termination = 0;
16838             warn_code |= ASC_WARN_EEPROM_TERMINATION;
16839         }
16840     }
16841
16842     if (eep_config.termination_lvd == 0)
16843     {
16844         asc_dvc->cfg->termination = termination; /* auto termination for LVD */
16845     } else
16846     {
16847         /* Enable manual control with low off / high off. */
16848         if (eep_config.termination_lvd == 1)
16849         {
16850             asc_dvc->cfg->termination = termination;
16851
16852         /* Enable manual control with low off / high on. */
16853         } else if (eep_config.termination_lvd == 2)
16854         {
16855             asc_dvc->cfg->termination = termination | TERM_LVD_HI;
16856
16857         /* Enable manual control with low on / high on. */
16858         } else if (eep_config.termination_lvd == 3)
16859         {
16860             asc_dvc->cfg->termination =
16861                 termination | TERM_LVD;
16862         } else
16863         {
16864             /*
16865              * The EEPROM 'termination_lvd' field contains a bad value.
16866              * Use automatic termination instead.
16867              */
16868             asc_dvc->cfg->termination = termination;
16869             warn_code |= ASC_WARN_EEPROM_TERMINATION;
16870         }
16871     }
16872
16873     return warn_code;
16874 }
16875
16876 /*
16877  * Read the board's EEPROM configuration. Set fields in ASC_DVC_VAR and
16878  * ASC_DVC_CFG based on the EEPROM settings. The chip is stopped while
16879  * all of this is done.
16880  *
16881  * On failure set the ASC_DVC_VAR field 'err_code' and return ADV_ERROR.
16882  *
16883  * For a non-fatal error return a warning code. If there are no warnings
16884  * then 0 is returned.
16885  *
16886  * Note: Chip is stopped on entry.
16887  */
16888 STATIC int __init
16889 AdvInitFrom38C1600EEP(ADV_DVC_VAR *asc_dvc)
16890 {
16891     AdvPortAddr              iop_base;
16892     ushort                   warn_code;
16893     ADVEEP_38C1600_CONFIG    eep_config;
16894     int                      i;
16895     uchar                    tid, termination;
16896     ushort                   sdtr_speed = 0;
16897
16898     iop_base = asc_dvc->iop_base;
16899
16900     warn_code = 0;
16901
16902     /*
16903      * Read the board's EEPROM configuration.
16904      *
16905      * Set default values if a bad checksum is found.
16906      */
16907     if (AdvGet38C1600EEPConfig(iop_base, &eep_config) != eep_config.check_sum)
16908     {
16909         warn_code |= ASC_WARN_EEPROM_CHKSUM;
16910
16911         /*
16912          * Set EEPROM default values.
16913          */
16914         for (i = 0; i < sizeof(ADVEEP_38C1600_CONFIG); i++)
16915         {
16916             if (i == 1 && ASC_PCI_ID2FUNC(asc_dvc->cfg->pci_slot_info) != 0)
16917             {
16918                 /*
16919                  * Set Function 1 EEPROM Word 0 MSB
16920                  *
16921                  * Clear the BIOS_ENABLE (bit 14) and INTAB (bit 11)
16922                  * EEPROM bits.
16923                  *
16924                  * Disable Bit 14 (BIOS_ENABLE) to fix SPARC Ultra 60 and
16925                  * old Mac system booting problem. The Expansion ROM must
16926                  * be disabled in Function 1 for these systems.
16927                  *
16928                  */
16929                 *((uchar *) &eep_config + i) =
16930                 ((*((uchar *) &Default_38C1600_EEPROM_Config + i)) &
16931                     (~(((ADV_EEPROM_BIOS_ENABLE | ADV_EEPROM_INTAB) >> 8) &
16932                      0xFF)));
16933
16934                 /*
16935                  * Set the INTAB (bit 11) if the GPIO 0 input indicates
16936                  * the Function 1 interrupt line is wired to INTA.
16937                  *
16938                  * Set/Clear Bit 11 (INTAB) from the GPIO bit 0 input:
16939                  *   1 - Function 1 interrupt line wired to INT A.
16940                  *   0 - Function 1 interrupt line wired to INT B.
16941                  *
16942                  * Note: Adapter boards always have Function 0 wired to INTA.
16943                  * Put all 5 GPIO bits in input mode and then read
16944                  * their input values.
16945                  */
16946                 AdvWriteByteRegister(iop_base, IOPB_GPIO_CNTL, 0);
16947                 if (AdvReadByteRegister(iop_base, IOPB_GPIO_DATA) & 0x01)
16948                 {
16949                     /* Function 1 interrupt wired to INTA; Set EEPROM bit. */
16950                 *((uchar *) &eep_config + i) |=
16951                     ((ADV_EEPROM_INTAB >> 8) & 0xFF);
16952                 }
16953             }
16954             else
16955             {
16956                 *((uchar *) &eep_config + i) =
16957                 *((uchar *) &Default_38C1600_EEPROM_Config + i);
16958             }
16959         }
16960
16961         /*
16962          * Assume the 6 byte board serial number that was read
16963          * from EEPROM is correct even if the EEPROM checksum
16964          * failed.
16965          */
16966         eep_config.serial_number_word3 =
16967             AdvReadEEPWord(iop_base, ADV_EEP_DVC_CFG_END - 1);
16968
16969         eep_config.serial_number_word2 =
16970             AdvReadEEPWord(iop_base, ADV_EEP_DVC_CFG_END - 2);
16971
16972         eep_config.serial_number_word1 =
16973             AdvReadEEPWord(iop_base, ADV_EEP_DVC_CFG_END - 3);
16974
16975         AdvSet38C1600EEPConfig(iop_base, &eep_config);
16976     }
16977
16978     /*
16979      * Set ASC_DVC_VAR and ASC_DVC_CFG variables from the
16980      * EEPROM configuration that was read.
16981      *
16982      * This is the mapping of EEPROM fields to Adv Library fields.
16983      */
16984     asc_dvc->wdtr_able = eep_config.wdtr_able;
16985     asc_dvc->sdtr_speed1 = eep_config.sdtr_speed1;
16986     asc_dvc->sdtr_speed2 = eep_config.sdtr_speed2;
16987     asc_dvc->sdtr_speed3 = eep_config.sdtr_speed3;
16988     asc_dvc->sdtr_speed4 = eep_config.sdtr_speed4;
16989     asc_dvc->ppr_able = 0;
16990     asc_dvc->tagqng_able = eep_config.tagqng_able;
16991     asc_dvc->cfg->disc_enable = eep_config.disc_enable;
16992     asc_dvc->max_host_qng = eep_config.max_host_qng;
16993     asc_dvc->max_dvc_qng = eep_config.max_dvc_qng;
16994     asc_dvc->chip_scsi_id = (eep_config.adapter_scsi_id & ASC_MAX_TID);
16995     asc_dvc->start_motor = eep_config.start_motor;
16996     asc_dvc->scsi_reset_wait = eep_config.scsi_reset_delay;
16997     asc_dvc->bios_ctrl = eep_config.bios_ctrl;
16998     asc_dvc->no_scam = eep_config.scam_tolerant;
16999
17000     /*
17001      * For every Target ID if any of its 'sdtr_speed[1234]' bits
17002      * are set, then set an 'sdtr_able' bit for it.
17003      */
17004     asc_dvc->sdtr_able = 0;
17005     for (tid = 0; tid <= ASC_MAX_TID; tid++)
17006     {
17007         if (tid == 0)
17008         {
17009             sdtr_speed = asc_dvc->sdtr_speed1;
17010         } else if (tid == 4)
17011         {
17012             sdtr_speed = asc_dvc->sdtr_speed2;
17013         } else if (tid == 8)
17014         {
17015             sdtr_speed = asc_dvc->sdtr_speed3;
17016         } else if (tid == 12)
17017         {
17018             sdtr_speed = asc_dvc->sdtr_speed4;
17019         }
17020         if (sdtr_speed & ASC_MAX_TID)
17021         {
17022             asc_dvc->sdtr_able |= (1 << tid);
17023         }
17024         sdtr_speed >>= 4;
17025     }
17026
17027     /*
17028      * Set the host maximum queuing (max. 253, min. 16) and the per device
17029      * maximum queuing (max. 63, min. 4).
17030      */
17031     if (eep_config.max_host_qng > ASC_DEF_MAX_HOST_QNG)
17032     {
17033         eep_config.max_host_qng = ASC_DEF_MAX_HOST_QNG;
17034     } else if (eep_config.max_host_qng < ASC_DEF_MIN_HOST_QNG)
17035     {
17036         /* If the value is zero, assume it is uninitialized. */
17037         if (eep_config.max_host_qng == 0)
17038         {
17039             eep_config.max_host_qng = ASC_DEF_MAX_HOST_QNG;
17040         } else
17041         {
17042             eep_config.max_host_qng = ASC_DEF_MIN_HOST_QNG;
17043         }
17044     }
17045
17046     if (eep_config.max_dvc_qng > ASC_DEF_MAX_DVC_QNG)
17047     {
17048         eep_config.max_dvc_qng = ASC_DEF_MAX_DVC_QNG;
17049     } else if (eep_config.max_dvc_qng < ASC_DEF_MIN_DVC_QNG)
17050     {
17051         /* If the value is zero, assume it is uninitialized. */
17052         if (eep_config.max_dvc_qng == 0)
17053         {
17054             eep_config.max_dvc_qng = ASC_DEF_MAX_DVC_QNG;
17055         } else
17056         {
17057             eep_config.max_dvc_qng = ASC_DEF_MIN_DVC_QNG;
17058         }
17059     }
17060
17061     /*
17062      * If 'max_dvc_qng' is greater than 'max_host_qng', then
17063      * set 'max_dvc_qng' to 'max_host_qng'.
17064      */
17065     if (eep_config.max_dvc_qng > eep_config.max_host_qng)
17066     {
17067         eep_config.max_dvc_qng = eep_config.max_host_qng;
17068     }
17069
17070     /*
17071      * Set ASC_DVC_VAR 'max_host_qng' and ASC_DVC_VAR 'max_dvc_qng'
17072      * values based on possibly adjusted EEPROM values.
17073      */
17074     asc_dvc->max_host_qng = eep_config.max_host_qng;
17075     asc_dvc->max_dvc_qng = eep_config.max_dvc_qng;
17076
17077     /*
17078      * If the EEPROM 'termination' field is set to automatic (0), then set
17079      * the ASC_DVC_CFG 'termination' field to automatic also.
17080      *
17081      * If the termination is specified with a non-zero 'termination'
17082      * value check that a legal value is set and set the ASC_DVC_CFG
17083      * 'termination' field appropriately.
17084      */
17085     if (eep_config.termination_se == 0)
17086     {
17087         termination = 0;                         /* auto termination for SE */
17088     } else
17089     {
17090         /* Enable manual control with low off / high off. */
17091         if (eep_config.termination_se == 1)
17092         {
17093             termination = 0;
17094
17095         /* Enable manual control with low off / high on. */
17096         } else if (eep_config.termination_se == 2)
17097         {
17098             termination = TERM_SE_HI;
17099
17100         /* Enable manual control with low on / high on. */
17101         } else if (eep_config.termination_se == 3)
17102         {
17103             termination = TERM_SE;
17104         } else
17105         {
17106             /*
17107              * The EEPROM 'termination_se' field contains a bad value.
17108              * Use automatic termination instead.
17109              */
17110             termination = 0;
17111             warn_code |= ASC_WARN_EEPROM_TERMINATION;
17112         }
17113     }
17114
17115     if (eep_config.termination_lvd == 0)
17116     {
17117         asc_dvc->cfg->termination = termination; /* auto termination for LVD */
17118     } else
17119     {
17120         /* Enable manual control with low off / high off. */
17121         if (eep_config.termination_lvd == 1)
17122         {
17123             asc_dvc->cfg->termination = termination;
17124
17125         /* Enable manual control with low off / high on. */
17126         } else if (eep_config.termination_lvd == 2)
17127         {
17128             asc_dvc->cfg->termination = termination | TERM_LVD_HI;
17129
17130         /* Enable manual control with low on / high on. */
17131         } else if (eep_config.termination_lvd == 3)
17132         {
17133             asc_dvc->cfg->termination =
17134                 termination | TERM_LVD;
17135         } else
17136         {
17137             /*
17138              * The EEPROM 'termination_lvd' field contains a bad value.
17139              * Use automatic termination instead.
17140              */
17141             asc_dvc->cfg->termination = termination;
17142             warn_code |= ASC_WARN_EEPROM_TERMINATION;
17143         }
17144     }
17145
17146     return warn_code;
17147 }
17148
17149 /*
17150  * Read EEPROM configuration into the specified buffer.
17151  *
17152  * Return a checksum based on the EEPROM configuration read.
17153  */
17154 STATIC ushort __init
17155 AdvGet3550EEPConfig(AdvPortAddr iop_base, ADVEEP_3550_CONFIG *cfg_buf)
17156 {
17157     ushort              wval, chksum;
17158     ushort              *wbuf;
17159     int                 eep_addr;
17160     ushort              *charfields;
17161
17162     charfields = (ushort *) &ADVEEP_3550_Config_Field_IsChar;
17163     wbuf = (ushort *) cfg_buf;
17164     chksum = 0;
17165
17166     for (eep_addr = ADV_EEP_DVC_CFG_BEGIN;
17167          eep_addr < ADV_EEP_DVC_CFG_END;
17168          eep_addr++, wbuf++)
17169     {
17170         wval = AdvReadEEPWord(iop_base, eep_addr);
17171         chksum += wval; /* Checksum is calculated from word values. */
17172         if (*charfields++) {
17173             *wbuf = le16_to_cpu(wval);
17174         } else {
17175             *wbuf = wval;
17176         }
17177     }
17178     /* Read checksum word. */
17179     *wbuf = AdvReadEEPWord(iop_base, eep_addr);
17180     wbuf++; charfields++;
17181
17182     /* Read rest of EEPROM not covered by the checksum. */
17183     for (eep_addr = ADV_EEP_DVC_CTL_BEGIN;
17184          eep_addr < ADV_EEP_MAX_WORD_ADDR;
17185          eep_addr++, wbuf++)
17186     {
17187         *wbuf = AdvReadEEPWord(iop_base, eep_addr);
17188         if (*charfields++) {
17189             *wbuf = le16_to_cpu(*wbuf);
17190         }
17191     }
17192     return chksum;
17193 }
17194
17195 /*
17196  * Read EEPROM configuration into the specified buffer.
17197  *
17198  * Return a checksum based on the EEPROM configuration read.
17199  */
17200 STATIC ushort __init
17201 AdvGet38C0800EEPConfig(AdvPortAddr iop_base,
17202                        ADVEEP_38C0800_CONFIG *cfg_buf)
17203 {
17204     ushort              wval, chksum;
17205     ushort              *wbuf;
17206     int                 eep_addr;
17207     ushort              *charfields;
17208
17209     charfields = (ushort *) &ADVEEP_38C0800_Config_Field_IsChar;
17210     wbuf = (ushort *) cfg_buf;
17211     chksum = 0;
17212
17213     for (eep_addr = ADV_EEP_DVC_CFG_BEGIN;
17214          eep_addr < ADV_EEP_DVC_CFG_END;
17215          eep_addr++, wbuf++)
17216     {
17217         wval = AdvReadEEPWord(iop_base, eep_addr);
17218         chksum += wval; /* Checksum is calculated from word values. */
17219         if (*charfields++) {
17220             *wbuf = le16_to_cpu(wval);
17221         } else {
17222             *wbuf = wval;
17223         }
17224     }
17225     /* Read checksum word. */
17226     *wbuf = AdvReadEEPWord(iop_base, eep_addr);
17227     wbuf++; charfields++;
17228
17229     /* Read rest of EEPROM not covered by the checksum. */
17230     for (eep_addr = ADV_EEP_DVC_CTL_BEGIN;
17231          eep_addr < ADV_EEP_MAX_WORD_ADDR;
17232          eep_addr++, wbuf++)
17233     {
17234         *wbuf = AdvReadEEPWord(iop_base, eep_addr);
17235         if (*charfields++) {
17236             *wbuf = le16_to_cpu(*wbuf);
17237         }
17238     }
17239     return chksum;
17240 }
17241
17242 /*
17243  * Read EEPROM configuration into the specified buffer.
17244  *
17245  * Return a checksum based on the EEPROM configuration read.
17246  */
17247 STATIC ushort __init
17248 AdvGet38C1600EEPConfig(AdvPortAddr iop_base,
17249                        ADVEEP_38C1600_CONFIG *cfg_buf)
17250 {
17251     ushort              wval, chksum;
17252     ushort              *wbuf;
17253     int                 eep_addr;
17254     ushort              *charfields;
17255
17256     charfields = (ushort*) &ADVEEP_38C1600_Config_Field_IsChar;
17257     wbuf = (ushort *) cfg_buf;
17258     chksum = 0;
17259
17260     for (eep_addr = ADV_EEP_DVC_CFG_BEGIN;
17261          eep_addr < ADV_EEP_DVC_CFG_END;
17262          eep_addr++, wbuf++)
17263     {
17264         wval = AdvReadEEPWord(iop_base, eep_addr);
17265         chksum += wval; /* Checksum is calculated from word values. */
17266         if (*charfields++) {
17267             *wbuf = le16_to_cpu(wval);
17268         } else {
17269             *wbuf = wval;
17270         }
17271     }
17272     /* Read checksum word. */
17273     *wbuf = AdvReadEEPWord(iop_base, eep_addr);
17274     wbuf++; charfields++;
17275
17276     /* Read rest of EEPROM not covered by the checksum. */
17277     for (eep_addr = ADV_EEP_DVC_CTL_BEGIN;
17278          eep_addr < ADV_EEP_MAX_WORD_ADDR;
17279          eep_addr++, wbuf++)
17280     {
17281         *wbuf = AdvReadEEPWord(iop_base, eep_addr);
17282         if (*charfields++) {
17283             *wbuf = le16_to_cpu(*wbuf);
17284         }
17285     }
17286     return chksum;
17287 }
17288
17289 /*
17290  * Read the EEPROM from specified location
17291  */
17292 STATIC ushort __init
17293 AdvReadEEPWord(AdvPortAddr iop_base, int eep_word_addr)
17294 {
17295     AdvWriteWordRegister(iop_base, IOPW_EE_CMD,
17296         ASC_EEP_CMD_READ | eep_word_addr);
17297     AdvWaitEEPCmd(iop_base);
17298     return AdvReadWordRegister(iop_base, IOPW_EE_DATA);
17299 }
17300
17301 /*
17302  * Wait for EEPROM command to complete
17303  */
17304 STATIC void __init
17305 AdvWaitEEPCmd(AdvPortAddr iop_base)
17306 {
17307     int eep_delay_ms;
17308
17309     for (eep_delay_ms = 0; eep_delay_ms < ADV_EEP_DELAY_MS; eep_delay_ms++)
17310     {
17311         if (AdvReadWordRegister(iop_base, IOPW_EE_CMD) & ASC_EEP_CMD_DONE)
17312         {
17313             break;
17314         }
17315         DvcSleepMilliSecond(1);
17316     }
17317     if ((AdvReadWordRegister(iop_base, IOPW_EE_CMD) & ASC_EEP_CMD_DONE) == 0)
17318     {
17319         ASC_ASSERT(0);
17320     }
17321     return;
17322 }
17323
17324 /*
17325  * Write the EEPROM from 'cfg_buf'.
17326  */
17327 void
17328 AdvSet3550EEPConfig(AdvPortAddr iop_base, ADVEEP_3550_CONFIG *cfg_buf)
17329 {
17330     ushort *wbuf;
17331     ushort addr, chksum;
17332     ushort *charfields;
17333
17334     wbuf = (ushort *) cfg_buf;
17335     charfields = (ushort *) &ADVEEP_3550_Config_Field_IsChar;
17336     chksum = 0;
17337
17338     AdvWriteWordRegister(iop_base, IOPW_EE_CMD, ASC_EEP_CMD_WRITE_ABLE);
17339     AdvWaitEEPCmd(iop_base);
17340
17341     /*
17342      * Write EEPROM from word 0 to word 20.
17343      */
17344     for (addr = ADV_EEP_DVC_CFG_BEGIN;
17345          addr < ADV_EEP_DVC_CFG_END; addr++, wbuf++)
17346     {
17347         ushort word;
17348
17349         if (*charfields++) {
17350             word = cpu_to_le16(*wbuf);
17351         } else {
17352             word = *wbuf;
17353         }
17354         chksum += *wbuf; /* Checksum is calculated from word values. */
17355         AdvWriteWordRegister(iop_base, IOPW_EE_DATA, word);
17356         AdvWriteWordRegister(iop_base, IOPW_EE_CMD, ASC_EEP_CMD_WRITE | addr);
17357         AdvWaitEEPCmd(iop_base);
17358         DvcSleepMilliSecond(ADV_EEP_DELAY_MS);
17359     }
17360
17361     /*
17362      * Write EEPROM checksum at word 21.
17363      */
17364     AdvWriteWordRegister(iop_base, IOPW_EE_DATA, chksum);
17365     AdvWriteWordRegister(iop_base, IOPW_EE_CMD, ASC_EEP_CMD_WRITE | addr);
17366     AdvWaitEEPCmd(iop_base);
17367     wbuf++; charfields++;
17368
17369     /*
17370      * Write EEPROM OEM name at words 22 to 29.
17371      */
17372     for (addr = ADV_EEP_DVC_CTL_BEGIN;
17373          addr < ADV_EEP_MAX_WORD_ADDR; addr++, wbuf++)
17374     {
17375         ushort word;
17376
17377         if (*charfields++) {
17378             word = cpu_to_le16(*wbuf);
17379         } else {
17380             word = *wbuf;
17381         }
17382         AdvWriteWordRegister(iop_base, IOPW_EE_DATA, word);
17383         AdvWriteWordRegister(iop_base, IOPW_EE_CMD, ASC_EEP_CMD_WRITE | addr);
17384         AdvWaitEEPCmd(iop_base);
17385     }
17386     AdvWriteWordRegister(iop_base, IOPW_EE_CMD, ASC_EEP_CMD_WRITE_DISABLE);
17387     AdvWaitEEPCmd(iop_base);
17388     return;
17389 }
17390
17391 /*
17392  * Write the EEPROM from 'cfg_buf'.
17393  */
17394 void
17395 AdvSet38C0800EEPConfig(AdvPortAddr iop_base,
17396                        ADVEEP_38C0800_CONFIG *cfg_buf)
17397 {
17398     ushort *wbuf;
17399     ushort *charfields;
17400     ushort addr, chksum;
17401
17402     wbuf = (ushort *) cfg_buf;
17403     charfields = (ushort *) &ADVEEP_38C0800_Config_Field_IsChar;
17404     chksum = 0;
17405
17406     AdvWriteWordRegister(iop_base, IOPW_EE_CMD, ASC_EEP_CMD_WRITE_ABLE);
17407     AdvWaitEEPCmd(iop_base);
17408
17409     /*
17410      * Write EEPROM from word 0 to word 20.
17411      */
17412     for (addr = ADV_EEP_DVC_CFG_BEGIN;
17413          addr < ADV_EEP_DVC_CFG_END; addr++, wbuf++)
17414     {
17415         ushort word;
17416
17417         if (*charfields++) {
17418             word = cpu_to_le16(*wbuf);
17419         } else {
17420             word = *wbuf;
17421         }
17422         chksum += *wbuf; /* Checksum is calculated from word values. */
17423         AdvWriteWordRegister(iop_base, IOPW_EE_DATA, word);
17424         AdvWriteWordRegister(iop_base, IOPW_EE_CMD, ASC_EEP_CMD_WRITE | addr);
17425         AdvWaitEEPCmd(iop_base);
17426         DvcSleepMilliSecond(ADV_EEP_DELAY_MS);
17427     }
17428
17429     /*
17430      * Write EEPROM checksum at word 21.
17431      */
17432     AdvWriteWordRegister(iop_base, IOPW_EE_DATA, chksum);
17433     AdvWriteWordRegister(iop_base, IOPW_EE_CMD, ASC_EEP_CMD_WRITE | addr);
17434     AdvWaitEEPCmd(iop_base);
17435     wbuf++; charfields++;
17436
17437     /*
17438      * Write EEPROM OEM name at words 22 to 29.
17439      */
17440     for (addr = ADV_EEP_DVC_CTL_BEGIN;
17441          addr < ADV_EEP_MAX_WORD_ADDR; addr++, wbuf++)
17442     {
17443         ushort word;
17444
17445         if (*charfields++) {
17446             word = cpu_to_le16(*wbuf);
17447         } else {
17448             word = *wbuf;
17449         }
17450         AdvWriteWordRegister(iop_base, IOPW_EE_DATA, word);
17451         AdvWriteWordRegister(iop_base, IOPW_EE_CMD, ASC_EEP_CMD_WRITE | addr);
17452         AdvWaitEEPCmd(iop_base);
17453     }
17454     AdvWriteWordRegister(iop_base, IOPW_EE_CMD, ASC_EEP_CMD_WRITE_DISABLE);
17455     AdvWaitEEPCmd(iop_base);
17456     return;
17457 }
17458
17459 /*
17460  * Write the EEPROM from 'cfg_buf'.
17461  */
17462 void
17463 AdvSet38C1600EEPConfig(AdvPortAddr iop_base,
17464                        ADVEEP_38C1600_CONFIG *cfg_buf)
17465 {
17466     ushort              *wbuf;
17467     ushort              *charfields;
17468     ushort              addr, chksum;
17469
17470     wbuf = (ushort *) cfg_buf;
17471     charfields = (ushort *) &ADVEEP_38C1600_Config_Field_IsChar;
17472     chksum = 0;
17473
17474     AdvWriteWordRegister(iop_base, IOPW_EE_CMD, ASC_EEP_CMD_WRITE_ABLE);
17475     AdvWaitEEPCmd(iop_base);
17476
17477     /*
17478      * Write EEPROM from word 0 to word 20.
17479      */
17480     for (addr = ADV_EEP_DVC_CFG_BEGIN;
17481          addr < ADV_EEP_DVC_CFG_END; addr++, wbuf++)
17482     {
17483         ushort word;
17484
17485         if (*charfields++) {
17486             word = cpu_to_le16(*wbuf);
17487         } else {
17488             word = *wbuf;
17489         }
17490         chksum += *wbuf; /* Checksum is calculated from word values. */
17491         AdvWriteWordRegister(iop_base, IOPW_EE_DATA, word);
17492         AdvWriteWordRegister(iop_base, IOPW_EE_CMD, ASC_EEP_CMD_WRITE | addr);
17493         AdvWaitEEPCmd(iop_base);
17494         DvcSleepMilliSecond(ADV_EEP_DELAY_MS);
17495     }
17496
17497     /*
17498      * Write EEPROM checksum at word 21.
17499      */
17500     AdvWriteWordRegister(iop_base, IOPW_EE_DATA, chksum);
17501     AdvWriteWordRegister(iop_base, IOPW_EE_CMD, ASC_EEP_CMD_WRITE | addr);
17502     AdvWaitEEPCmd(iop_base);
17503     wbuf++; charfields++;
17504
17505     /*
17506      * Write EEPROM OEM name at words 22 to 29.
17507      */
17508     for (addr = ADV_EEP_DVC_CTL_BEGIN;
17509          addr < ADV_EEP_MAX_WORD_ADDR; addr++, wbuf++)
17510     {
17511         ushort word;
17512
17513         if (*charfields++) {
17514             word = cpu_to_le16(*wbuf);
17515         } else {
17516             word = *wbuf;
17517         }
17518         AdvWriteWordRegister(iop_base, IOPW_EE_DATA, word);
17519         AdvWriteWordRegister(iop_base, IOPW_EE_CMD, ASC_EEP_CMD_WRITE | addr);
17520         AdvWaitEEPCmd(iop_base);
17521     }
17522     AdvWriteWordRegister(iop_base, IOPW_EE_CMD, ASC_EEP_CMD_WRITE_DISABLE);
17523     AdvWaitEEPCmd(iop_base);
17524     return;
17525 }
17526
17527 /* a_advlib.c */
17528 /*
17529  * AdvExeScsiQueue() - Send a request to the RISC microcode program.
17530  *
17531  *   Allocate a carrier structure, point the carrier to the ADV_SCSI_REQ_Q,
17532  *   add the carrier to the ICQ (Initiator Command Queue), and tickle the
17533  *   RISC to notify it a new command is ready to be executed.
17534  *
17535  * If 'done_status' is not set to QD_DO_RETRY, then 'error_retry' will be
17536  * set to SCSI_MAX_RETRY.
17537  *
17538  * Multi-byte fields in the ASC_SCSI_REQ_Q that are used by the microcode
17539  * for DMA addresses or math operations are byte swapped to little-endian
17540  * order.
17541  *
17542  * Return:
17543  *      ADV_SUCCESS(1) - The request was successfully queued.
17544  *      ADV_BUSY(0) -    Resource unavailable; Retry again after pending
17545  *                       request completes.
17546  *      ADV_ERROR(-1) -  Invalid ADV_SCSI_REQ_Q request structure
17547  *                       host IC error.
17548  */
17549 STATIC int
17550 AdvExeScsiQueue(ADV_DVC_VAR *asc_dvc,
17551                 ADV_SCSI_REQ_Q *scsiq)
17552 {
17553     ulong                  last_int_level;
17554     AdvPortAddr            iop_base;
17555     ADV_DCNT               req_size;
17556     ADV_PADDR              req_paddr;
17557     ADV_CARR_T             *new_carrp;
17558
17559     ASC_ASSERT(scsiq != NULL); /* 'scsiq' should never be NULL. */
17560
17561     /*
17562      * The ADV_SCSI_REQ_Q 'target_id' field should never exceed ADV_MAX_TID.
17563      */
17564     if (scsiq->target_id > ADV_MAX_TID)
17565     {
17566         scsiq->host_status = QHSTA_M_INVALID_DEVICE;
17567         scsiq->done_status = QD_WITH_ERROR;
17568         return ADV_ERROR;
17569     }
17570
17571     iop_base = asc_dvc->iop_base;
17572
17573     last_int_level = DvcEnterCritical();
17574
17575     /*
17576      * Allocate a carrier ensuring at least one carrier always
17577      * remains on the freelist and initialize fields.
17578      */
17579     if ((new_carrp = asc_dvc->carr_freelist) == NULL)
17580     {
17581        DvcLeaveCritical(last_int_level);
17582        return ADV_BUSY;
17583     }
17584     asc_dvc->carr_freelist = (ADV_CARR_T *)
17585         ADV_U32_TO_VADDR(le32_to_cpu(new_carrp->next_vpa));
17586     asc_dvc->carr_pending_cnt++;
17587
17588     /*
17589      * Set the carrier to be a stopper by setting 'next_vpa'
17590      * to the stopper value. The current stopper will be changed
17591      * below to point to the new stopper.
17592      */
17593     new_carrp->next_vpa = cpu_to_le32(ASC_CQ_STOPPER);
17594
17595     /*
17596      * Clear the ADV_SCSI_REQ_Q done flag.
17597      */
17598     scsiq->a_flag &= ~ADV_SCSIQ_DONE;
17599
17600     req_size = sizeof(ADV_SCSI_REQ_Q);
17601     req_paddr = DvcGetPhyAddr(asc_dvc, scsiq, (uchar *) scsiq,
17602         (ADV_SDCNT *) &req_size, ADV_IS_SCSIQ_FLAG);
17603
17604     ASC_ASSERT(ADV_32BALIGN(req_paddr) == req_paddr);
17605     ASC_ASSERT(req_size >= sizeof(ADV_SCSI_REQ_Q));
17606
17607     /* Wait for assertion before making little-endian */
17608     req_paddr = cpu_to_le32(req_paddr);
17609
17610     /* Save virtual and physical address of ADV_SCSI_REQ_Q and carrier. */
17611     scsiq->scsiq_ptr = cpu_to_le32(ADV_VADDR_TO_U32(scsiq));
17612     scsiq->scsiq_rptr = req_paddr;
17613
17614     scsiq->carr_va = cpu_to_le32(ADV_VADDR_TO_U32(asc_dvc->icq_sp));
17615     /*
17616      * Every ADV_CARR_T.carr_pa is byte swapped to little-endian
17617      * order during initialization.
17618      */
17619     scsiq->carr_pa = asc_dvc->icq_sp->carr_pa;
17620
17621    /*
17622     * Use the current stopper to send the ADV_SCSI_REQ_Q command to
17623     * the microcode. The newly allocated stopper will become the new
17624     * stopper.
17625     */
17626     asc_dvc->icq_sp->areq_vpa = req_paddr;
17627
17628     /*
17629      * Set the 'next_vpa' pointer for the old stopper to be the
17630      * physical address of the new stopper. The RISC can only
17631      * follow physical addresses.
17632      */
17633     asc_dvc->icq_sp->next_vpa = new_carrp->carr_pa;
17634
17635     /*
17636      * Set the host adapter stopper pointer to point to the new carrier.
17637      */
17638     asc_dvc->icq_sp = new_carrp;
17639
17640     if (asc_dvc->chip_type == ADV_CHIP_ASC3550 ||
17641         asc_dvc->chip_type == ADV_CHIP_ASC38C0800)
17642     {
17643         /*
17644          * Tickle the RISC to tell it to read its Command Queue Head pointer.
17645          */
17646         AdvWriteByteRegister(iop_base, IOPB_TICKLE, ADV_TICKLE_A);
17647         if (asc_dvc->chip_type == ADV_CHIP_ASC3550)
17648         {
17649             /*
17650              * Clear the tickle value. In the ASC-3550 the RISC flag
17651              * command 'clr_tickle_a' does not work unless the host
17652              * value is cleared.
17653              */
17654             AdvWriteByteRegister(iop_base, IOPB_TICKLE, ADV_TICKLE_NOP);
17655         }
17656     } else if (asc_dvc->chip_type == ADV_CHIP_ASC38C1600)
17657     {
17658         /*
17659          * Notify the RISC a carrier is ready by writing the physical
17660          * address of the new carrier stopper to the COMMA register.
17661          */
17662         AdvWriteDWordRegister(iop_base, IOPDW_COMMA,
17663                 le32_to_cpu(new_carrp->carr_pa));
17664     }
17665
17666     DvcLeaveCritical(last_int_level);
17667
17668     return ADV_SUCCESS;
17669 }
17670
17671 /*
17672  * Reset SCSI Bus and purge all outstanding requests.
17673  *
17674  * Return Value:
17675  *      ADV_TRUE(1) -   All requests are purged and SCSI Bus is reset.
17676  *      ADV_FALSE(0) -  Microcode command failed.
17677  *      ADV_ERROR(-1) - Microcode command timed-out. Microcode or IC
17678  *                      may be hung which requires driver recovery.
17679  */
17680 STATIC int
17681 AdvResetSB(ADV_DVC_VAR *asc_dvc)
17682 {
17683     int         status;
17684
17685     /*
17686      * Send the SCSI Bus Reset idle start idle command which asserts
17687      * the SCSI Bus Reset signal.
17688      */
17689     status = AdvSendIdleCmd(asc_dvc, (ushort) IDLE_CMD_SCSI_RESET_START, 0L);
17690     if (status != ADV_TRUE)
17691     {
17692         return status;
17693     }
17694
17695     /*
17696      * Delay for the specified SCSI Bus Reset hold time.
17697      *
17698      * The hold time delay is done on the host because the RISC has no
17699      * microsecond accurate timer.
17700      */
17701     DvcDelayMicroSecond(asc_dvc, (ushort) ASC_SCSI_RESET_HOLD_TIME_US);
17702
17703     /*
17704      * Send the SCSI Bus Reset end idle command which de-asserts
17705      * the SCSI Bus Reset signal and purges any pending requests.
17706      */
17707     status = AdvSendIdleCmd(asc_dvc, (ushort) IDLE_CMD_SCSI_RESET_END, 0L);
17708     if (status != ADV_TRUE)
17709     {
17710         return status;
17711     }
17712
17713     DvcSleepMilliSecond((ADV_DCNT) asc_dvc->scsi_reset_wait * 1000);
17714
17715     return status;
17716 }
17717
17718 /*
17719  * Reset chip and SCSI Bus.
17720  *
17721  * Return Value:
17722  *      ADV_TRUE(1) -   Chip re-initialization and SCSI Bus Reset successful.
17723  *      ADV_FALSE(0) -  Chip re-initialization and SCSI Bus Reset failure.
17724  */
17725 STATIC int
17726 AdvResetChipAndSB(ADV_DVC_VAR *asc_dvc)
17727 {
17728     int         status;
17729     ushort      wdtr_able, sdtr_able, tagqng_able;
17730     ushort      ppr_able = 0;
17731     uchar       tid, max_cmd[ADV_MAX_TID + 1];
17732     AdvPortAddr iop_base;
17733     ushort      bios_sig;
17734
17735     iop_base = asc_dvc->iop_base;
17736
17737     /*
17738      * Save current per TID negotiated values.
17739      */
17740     AdvReadWordLram(iop_base, ASC_MC_WDTR_ABLE, wdtr_able);
17741     AdvReadWordLram(iop_base, ASC_MC_SDTR_ABLE, sdtr_able);
17742     if (asc_dvc->chip_type == ADV_CHIP_ASC38C1600)
17743     {
17744         AdvReadWordLram(iop_base, ASC_MC_PPR_ABLE, ppr_able);
17745     }
17746     AdvReadWordLram(iop_base, ASC_MC_TAGQNG_ABLE, tagqng_able);
17747     for (tid = 0; tid <= ADV_MAX_TID; tid++)
17748     {
17749         AdvReadByteLram(iop_base, ASC_MC_NUMBER_OF_MAX_CMD + tid,
17750             max_cmd[tid]);
17751     }
17752
17753     /*
17754      * Force the AdvInitAsc3550/38C0800Driver() function to
17755      * perform a SCSI Bus Reset by clearing the BIOS signature word.
17756      * The initialization functions assumes a SCSI Bus Reset is not
17757      * needed if the BIOS signature word is present.
17758      */
17759     AdvReadWordLram(iop_base, ASC_MC_BIOS_SIGNATURE, bios_sig);
17760     AdvWriteWordLram(iop_base, ASC_MC_BIOS_SIGNATURE, 0);
17761
17762     /*
17763      * Stop chip and reset it.
17764      */
17765     AdvWriteWordRegister(iop_base, IOPW_RISC_CSR, ADV_RISC_CSR_STOP);
17766     AdvWriteWordRegister(iop_base, IOPW_CTRL_REG, ADV_CTRL_REG_CMD_RESET);
17767     DvcSleepMilliSecond(100);
17768     AdvWriteWordRegister(iop_base, IOPW_CTRL_REG, ADV_CTRL_REG_CMD_WR_IO_REG);
17769
17770     /*
17771      * Reset Adv Library error code, if any, and try
17772      * re-initializing the chip.
17773      */
17774     asc_dvc->err_code = 0;
17775     if (asc_dvc->chip_type == ADV_CHIP_ASC38C1600)
17776     {
17777         status = AdvInitAsc38C1600Driver(asc_dvc);
17778     }
17779     else if (asc_dvc->chip_type == ADV_CHIP_ASC38C0800)
17780     {
17781         status = AdvInitAsc38C0800Driver(asc_dvc);
17782     } else
17783     {
17784         status = AdvInitAsc3550Driver(asc_dvc);
17785     }
17786
17787     /* Translate initialization return value to status value. */
17788     if (status == 0)
17789     {
17790         status = ADV_TRUE;
17791     } else
17792     {
17793         status = ADV_FALSE;
17794     }
17795
17796     /*
17797      * Restore the BIOS signature word.
17798      */
17799     AdvWriteWordLram(iop_base, ASC_MC_BIOS_SIGNATURE, bios_sig);
17800
17801     /*
17802      * Restore per TID negotiated values.
17803      */
17804     AdvWriteWordLram(iop_base, ASC_MC_WDTR_ABLE, wdtr_able);
17805     AdvWriteWordLram(iop_base, ASC_MC_SDTR_ABLE, sdtr_able);
17806     if (asc_dvc->chip_type == ADV_CHIP_ASC38C1600)
17807     {
17808         AdvWriteWordLram(iop_base, ASC_MC_PPR_ABLE, ppr_able);
17809     }
17810     AdvWriteWordLram(iop_base, ASC_MC_TAGQNG_ABLE, tagqng_able);
17811     for (tid = 0; tid <= ADV_MAX_TID; tid++)
17812     {
17813         AdvWriteByteLram(iop_base, ASC_MC_NUMBER_OF_MAX_CMD + tid,
17814             max_cmd[tid]);
17815     }
17816
17817     return status;
17818 }
17819
17820 /*
17821  * Adv Library Interrupt Service Routine
17822  *
17823  *  This function is called by a driver's interrupt service routine.
17824  *  The function disables and re-enables interrupts.
17825  *
17826  *  When a microcode idle command is completed, the ADV_DVC_VAR
17827  *  'idle_cmd_done' field is set to ADV_TRUE.
17828  *
17829  *  Note: AdvISR() can be called when interrupts are disabled or even
17830  *  when there is no hardware interrupt condition present. It will
17831  *  always check for completed idle commands and microcode requests.
17832  *  This is an important feature that shouldn't be changed because it
17833  *  allows commands to be completed from polling mode loops.
17834  *
17835  * Return:
17836  *   ADV_TRUE(1) - interrupt was pending
17837  *   ADV_FALSE(0) - no interrupt was pending
17838  */
17839 STATIC int
17840 AdvISR(ADV_DVC_VAR *asc_dvc)
17841 {
17842     AdvPortAddr                 iop_base;
17843     uchar                       int_stat;
17844     ushort                      target_bit;
17845     ADV_CARR_T                  *free_carrp;
17846     ADV_VADDR                   irq_next_vpa;
17847     int                         flags;
17848     ADV_SCSI_REQ_Q              *scsiq;
17849
17850     flags = DvcEnterCritical();
17851
17852     iop_base = asc_dvc->iop_base;
17853
17854     /* Reading the register clears the interrupt. */
17855     int_stat = AdvReadByteRegister(iop_base, IOPB_INTR_STATUS_REG);
17856
17857     if ((int_stat & (ADV_INTR_STATUS_INTRA | ADV_INTR_STATUS_INTRB |
17858          ADV_INTR_STATUS_INTRC)) == 0)
17859     {
17860         DvcLeaveCritical(flags);
17861         return ADV_FALSE;
17862     }
17863
17864     /*
17865      * Notify the driver of an asynchronous microcode condition by
17866      * calling the ADV_DVC_VAR.async_callback function. The function
17867      * is passed the microcode ASC_MC_INTRB_CODE byte value.
17868      */
17869     if (int_stat & ADV_INTR_STATUS_INTRB)
17870     {
17871         uchar intrb_code;
17872
17873         AdvReadByteLram(iop_base, ASC_MC_INTRB_CODE, intrb_code);
17874
17875         if (asc_dvc->chip_type == ADV_CHIP_ASC3550 ||
17876             asc_dvc->chip_type == ADV_CHIP_ASC38C0800)
17877         {
17878             if (intrb_code == ADV_ASYNC_CARRIER_READY_FAILURE &&
17879                 asc_dvc->carr_pending_cnt != 0)
17880             {
17881                 AdvWriteByteRegister(iop_base, IOPB_TICKLE, ADV_TICKLE_A);
17882                 if (asc_dvc->chip_type == ADV_CHIP_ASC3550)
17883                 {
17884                     AdvWriteByteRegister(iop_base, IOPB_TICKLE, ADV_TICKLE_NOP);
17885                 }
17886             }
17887         }
17888
17889         if (asc_dvc->async_callback != 0)
17890         {
17891             (*asc_dvc->async_callback)(asc_dvc, intrb_code);
17892         }
17893     }
17894
17895     /*
17896      * Check if the IRQ stopper carrier contains a completed request.
17897      */
17898     while (((irq_next_vpa =
17899              le32_to_cpu(asc_dvc->irq_sp->next_vpa)) & ASC_RQ_DONE) != 0)
17900     {
17901         /*
17902          * Get a pointer to the newly completed ADV_SCSI_REQ_Q structure.
17903          * The RISC will have set 'areq_vpa' to a virtual address.
17904          *
17905          * The firmware will have copied the ASC_SCSI_REQ_Q.scsiq_ptr
17906          * field to the carrier ADV_CARR_T.areq_vpa field. The conversion
17907          * below complements the conversion of ASC_SCSI_REQ_Q.scsiq_ptr'
17908          * in AdvExeScsiQueue().
17909          */
17910         scsiq = (ADV_SCSI_REQ_Q *)
17911             ADV_U32_TO_VADDR(le32_to_cpu(asc_dvc->irq_sp->areq_vpa));
17912
17913         /*
17914          * Request finished with good status and the queue was not
17915          * DMAed to host memory by the firmware. Set all status fields
17916          * to indicate good status.
17917          */
17918         if ((irq_next_vpa & ASC_RQ_GOOD) != 0)
17919         {
17920             scsiq->done_status = QD_NO_ERROR;
17921             scsiq->host_status = scsiq->scsi_status = 0;
17922             scsiq->data_cnt = 0L;
17923         }
17924
17925         /*
17926          * Advance the stopper pointer to the next carrier
17927          * ignoring the lower four bits. Free the previous
17928          * stopper carrier.
17929          */
17930         free_carrp = asc_dvc->irq_sp;
17931         asc_dvc->irq_sp = (ADV_CARR_T *)
17932             ADV_U32_TO_VADDR(ASC_GET_CARRP(irq_next_vpa));
17933
17934         free_carrp->next_vpa =
17935                 cpu_to_le32(ADV_VADDR_TO_U32(asc_dvc->carr_freelist));
17936         asc_dvc->carr_freelist = free_carrp;
17937         asc_dvc->carr_pending_cnt--;
17938
17939         ASC_ASSERT(scsiq != NULL);
17940         target_bit = ADV_TID_TO_TIDMASK(scsiq->target_id);
17941
17942         /*
17943          * Clear request microcode control flag.
17944          */
17945         scsiq->cntl = 0;
17946
17947         /*
17948          * If the command that completed was a SCSI INQUIRY and
17949          * LUN 0 was sent the command, then process the INQUIRY
17950          * command information for the device.
17951          *
17952          * Note: If data returned were either VPD or CmdDt data,
17953          * don't process the INQUIRY command information for
17954          * the device, otherwise may erroneously set *_able bits.
17955          */
17956         if (scsiq->done_status == QD_NO_ERROR &&
17957             scsiq->cdb[0] == INQUIRY &&
17958             scsiq->target_lun == 0 &&
17959             (scsiq->cdb[1] & ADV_INQ_RTN_VPD_AND_CMDDT)
17960                 == ADV_INQ_RTN_STD_INQUIRY_DATA)
17961         {
17962             AdvInquiryHandling(asc_dvc, scsiq);
17963         }
17964
17965         /*
17966          * Notify the driver of the completed request by passing
17967          * the ADV_SCSI_REQ_Q pointer to its callback function.
17968          */
17969         scsiq->a_flag |= ADV_SCSIQ_DONE;
17970         (*asc_dvc->isr_callback)(asc_dvc, scsiq);
17971         /*
17972          * Note: After the driver callback function is called, 'scsiq'
17973          * can no longer be referenced.
17974          *
17975          * Fall through and continue processing other completed
17976          * requests...
17977          */
17978
17979         /*
17980          * Disable interrupts again in case the driver inadvertently
17981          * enabled interrupts in its callback function.
17982          *
17983          * The DvcEnterCritical() return value is ignored, because
17984          * the 'flags' saved when AdvISR() was first entered will be
17985          * used to restore the interrupt flag on exit.
17986          */
17987         (void) DvcEnterCritical();
17988     }
17989     DvcLeaveCritical(flags);
17990     return ADV_TRUE;
17991 }
17992
17993 /*
17994  * Send an idle command to the chip and wait for completion.
17995  *
17996  * Command completion is polled for once per microsecond.
17997  *
17998  * The function can be called from anywhere including an interrupt handler.
17999  * But the function is not re-entrant, so it uses the DvcEnter/LeaveCritical()
18000  * functions to prevent reentrancy.
18001  *
18002  * Return Values:
18003  *   ADV_TRUE - command completed successfully
18004  *   ADV_FALSE - command failed
18005  *   ADV_ERROR - command timed out
18006  */
18007 STATIC int
18008 AdvSendIdleCmd(ADV_DVC_VAR *asc_dvc,
18009                ushort idle_cmd,
18010                ADV_DCNT idle_cmd_parameter)
18011 {
18012     ulong       last_int_level;
18013     int         result;
18014     ADV_DCNT    i, j;
18015     AdvPortAddr iop_base;
18016
18017     last_int_level = DvcEnterCritical();
18018
18019     iop_base = asc_dvc->iop_base;
18020
18021     /*
18022      * Clear the idle command status which is set by the microcode
18023      * to a non-zero value to indicate when the command is completed.
18024      * The non-zero result is one of the IDLE_CMD_STATUS_* values
18025      * defined in a_advlib.h.
18026      */
18027     AdvWriteWordLram(iop_base, ASC_MC_IDLE_CMD_STATUS, (ushort) 0);
18028
18029     /*
18030      * Write the idle command value after the idle command parameter
18031      * has been written to avoid a race condition. If the order is not
18032      * followed, the microcode may process the idle command before the
18033      * parameters have been written to LRAM.
18034      */
18035     AdvWriteDWordLramNoSwap(iop_base, ASC_MC_IDLE_CMD_PARAMETER,
18036         cpu_to_le32(idle_cmd_parameter));
18037     AdvWriteWordLram(iop_base, ASC_MC_IDLE_CMD, idle_cmd);
18038
18039     /*
18040      * Tickle the RISC to tell it to process the idle command.
18041      */
18042     AdvWriteByteRegister(iop_base, IOPB_TICKLE, ADV_TICKLE_B);
18043     if (asc_dvc->chip_type == ADV_CHIP_ASC3550)
18044     {
18045         /*
18046          * Clear the tickle value. In the ASC-3550 the RISC flag
18047          * command 'clr_tickle_b' does not work unless the host
18048          * value is cleared.
18049          */
18050         AdvWriteByteRegister(iop_base, IOPB_TICKLE, ADV_TICKLE_NOP);
18051     }
18052
18053     /* Wait for up to 100 millisecond for the idle command to timeout. */
18054     for (i = 0; i < SCSI_WAIT_100_MSEC; i++)
18055     {
18056         /* Poll once each microsecond for command completion. */
18057         for (j = 0; j < SCSI_US_PER_MSEC; j++)
18058         {
18059             AdvReadWordLram(iop_base, ASC_MC_IDLE_CMD_STATUS, result);
18060             if (result != 0)
18061             {
18062                 DvcLeaveCritical(last_int_level);
18063                 return result;
18064             }
18065             DvcDelayMicroSecond(asc_dvc, (ushort) 1);
18066         }
18067     }
18068
18069     ASC_ASSERT(0); /* The idle command should never timeout. */
18070     DvcLeaveCritical(last_int_level);
18071     return ADV_ERROR;
18072 }
18073
18074 /*
18075  * Inquiry Information Byte 7 Handling
18076  *
18077  * Handle SCSI Inquiry Command information for a device by setting
18078  * microcode operating variables that affect WDTR, SDTR, and Tag
18079  * Queuing.
18080  */
18081 STATIC void
18082 AdvInquiryHandling(
18083     ADV_DVC_VAR                 *asc_dvc,
18084     ADV_SCSI_REQ_Q              *scsiq)
18085 {
18086     AdvPortAddr                 iop_base;
18087     uchar                       tid;
18088     ADV_SCSI_INQUIRY            *inq;
18089     ushort                      tidmask;
18090     ushort                      cfg_word;
18091
18092     /*
18093      * AdvInquiryHandling() requires up to INQUIRY information Byte 7
18094      * to be available.
18095      *
18096      * If less than 8 bytes of INQUIRY information were requested or less
18097      * than 8 bytes were transferred, then return. cdb[4] is the request
18098      * length and the ADV_SCSI_REQ_Q 'data_cnt' field is set by the
18099      * microcode to the transfer residual count.
18100      */
18101
18102     if (scsiq->cdb[4] < 8 ||
18103         (scsiq->cdb[4] - le32_to_cpu(scsiq->data_cnt)) < 8)
18104     {
18105         return;
18106     }
18107
18108     iop_base = asc_dvc->iop_base;
18109     tid = scsiq->target_id;
18110
18111     inq = (ADV_SCSI_INQUIRY *) scsiq->vdata_addr;
18112
18113     /*
18114      * WDTR, SDTR, and Tag Queuing cannot be enabled for old devices.
18115      */
18116     if (ADV_INQ_RESPONSE_FMT(inq) < 2 && ADV_INQ_ANSI_VER(inq) < 2)
18117     {
18118         return;
18119     } else
18120     {
18121         /*
18122          * INQUIRY Byte 7 Handling
18123          *
18124          * Use a device's INQUIRY byte 7 to determine whether it
18125          * supports WDTR, SDTR, and Tag Queuing. If the feature
18126          * is enabled in the EEPROM and the device supports the
18127          * feature, then enable it in the microcode.
18128          */
18129
18130         tidmask = ADV_TID_TO_TIDMASK(tid);
18131
18132         /*
18133          * Wide Transfers
18134          *
18135          * If the EEPROM enabled WDTR for the device and the device
18136          * supports wide bus (16 bit) transfers, then turn on the
18137          * device's 'wdtr_able' bit and write the new value to the
18138          * microcode.
18139          */
18140         if ((asc_dvc->wdtr_able & tidmask) && ADV_INQ_WIDE16(inq))
18141         {
18142             AdvReadWordLram(iop_base, ASC_MC_WDTR_ABLE, cfg_word);
18143             if ((cfg_word & tidmask) == 0)
18144             {
18145                 cfg_word |= tidmask;
18146                 AdvWriteWordLram(iop_base, ASC_MC_WDTR_ABLE, cfg_word);
18147
18148                 /*
18149                  * Clear the microcode "SDTR negotiation" and "WDTR
18150                  * negotiation" done indicators for the target to cause
18151                  * it to negotiate with the new setting set above.
18152                  * WDTR when accepted causes the target to enter
18153                  * asynchronous mode, so SDTR must be negotiated.
18154                  */
18155                 AdvReadWordLram(iop_base, ASC_MC_SDTR_DONE, cfg_word);
18156                 cfg_word &= ~tidmask;
18157                 AdvWriteWordLram(iop_base, ASC_MC_SDTR_DONE, cfg_word);
18158                 AdvReadWordLram(iop_base, ASC_MC_WDTR_DONE, cfg_word);
18159                 cfg_word &= ~tidmask;
18160                 AdvWriteWordLram(iop_base, ASC_MC_WDTR_DONE, cfg_word);
18161             }
18162         }
18163
18164         /*
18165          * Synchronous Transfers
18166          *
18167          * If the EEPROM enabled SDTR for the device and the device
18168          * supports synchronous transfers, then turn on the device's
18169          * 'sdtr_able' bit. Write the new value to the microcode.
18170          */
18171         if ((asc_dvc->sdtr_able & tidmask) && ADV_INQ_SYNC(inq))
18172         {
18173             AdvReadWordLram(iop_base, ASC_MC_SDTR_ABLE, cfg_word);
18174             if ((cfg_word & tidmask) == 0)
18175             {
18176                 cfg_word |= tidmask;
18177                 AdvWriteWordLram(iop_base, ASC_MC_SDTR_ABLE, cfg_word);
18178
18179                 /*
18180                  * Clear the microcode "SDTR negotiation" done indicator
18181                  * for the target to cause it to negotiate with the new
18182                  * setting set above.
18183                  */
18184                 AdvReadWordLram(iop_base, ASC_MC_SDTR_DONE, cfg_word);
18185                 cfg_word &= ~tidmask;
18186                 AdvWriteWordLram(iop_base, ASC_MC_SDTR_DONE, cfg_word);
18187             }
18188         }
18189         /*
18190          * If the Inquiry data included enough space for the SPI-3
18191          * Clocking field, then check if DT mode is supported.
18192          */
18193         if (asc_dvc->chip_type == ADV_CHIP_ASC38C1600 &&
18194             (scsiq->cdb[4] >= 57 ||
18195             (scsiq->cdb[4] - le32_to_cpu(scsiq->data_cnt)) >= 57))
18196         {
18197             /*
18198              * PPR (Parallel Protocol Request) Capable
18199              *
18200              * If the device supports DT mode, then it must be PPR capable.
18201              * The PPR message will be used in place of the SDTR and WDTR
18202              * messages to negotiate synchronous speed and offset, transfer
18203              * width, and protocol options.
18204              */
18205             if (ADV_INQ_CLOCKING(inq) & ADV_INQ_CLOCKING_DT_ONLY)
18206             {
18207                 AdvReadWordLram(iop_base, ASC_MC_PPR_ABLE, asc_dvc->ppr_able);
18208                 asc_dvc->ppr_able |= tidmask;
18209                 AdvWriteWordLram(iop_base, ASC_MC_PPR_ABLE, asc_dvc->ppr_able);
18210             }
18211         }
18212
18213         /*
18214          * If the EEPROM enabled Tag Queuing for the device and the
18215          * device supports Tag Queueing, then turn on the device's
18216          * 'tagqng_enable' bit in the microcode and set the microcode
18217          * maximum command count to the ADV_DVC_VAR 'max_dvc_qng'
18218          * value.
18219          *
18220          * Tag Queuing is disabled for the BIOS which runs in polled
18221          * mode and would see no benefit from Tag Queuing. Also by
18222          * disabling Tag Queuing in the BIOS devices with Tag Queuing
18223          * bugs will at least work with the BIOS.
18224          */
18225         if ((asc_dvc->tagqng_able & tidmask) && ADV_INQ_CMD_QUEUE(inq))
18226         {
18227             AdvReadWordLram(iop_base, ASC_MC_TAGQNG_ABLE, cfg_word);
18228             cfg_word |= tidmask;
18229             AdvWriteWordLram(iop_base, ASC_MC_TAGQNG_ABLE, cfg_word);
18230
18231             AdvWriteByteLram(iop_base, ASC_MC_NUMBER_OF_MAX_CMD + tid,
18232                 asc_dvc->max_dvc_qng);
18233         }
18234     }
18235 }
18236 MODULE_LICENSE("Dual BSD/GPL");